Re: [PATCH 3/5] xfs: automatic resource cleanup of for_each_perag*

From: Christoph Hellwig
Date: Mon Aug 09 2021 - 11:08:26 EST


> +# Required for for_each_perag*
> +ccflags-y += -std=gnu99

I don't think it is up to an individual subsystem to pick a specific C
dialect.

I think the most important reason why the kernel sticks with gnu89 is
to avoid the misfeature of variable declarations in the middle of
blocks, and this change would lose it.

> + xfs_agnumber_t last_agno = 0;
> int saved_error = 0;
> int error = 0;
> LIST_HEAD (buffer_list);
>
> /* update secondary superblocks. */
> - for_each_perag_from(mp, agno, pag) {
> + for_each_perag_from(mp, iter, 1) {
> struct xfs_buf *bp;
>
> + last_agno = iter.pag->pag_agno;

This is a really horrible API as it magically injects a local variable
in a macro. It also leads to worse code generation and a small but
noticable increase in .text sie:

hch@brick:~/work/xfs$ size xfs.o.*
text data bss dec hex filename
1521421 301161 1880 1824462 1bd6ce xfs.o.old
1521516 301161 1880 1824557 1bd72d xfs.o.new