xfs: clean up xfs_dir2_leafn_add
PATCH 1/1 xfs: clean up xfs_dir2_leafn_add
From: Darrick J. Wong <[email protected]>
Remove typedefs and consolidate local variable initialization.
--- fs/xfs/libxfs/xfs_dir2_node.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-)
fs/xfs/libxfs/xfs_dir2_node.c +8 -12
@@ -426,26 +426,22 @@ xfs_dir2_leaf_to_node(static int /* error */ xfs_dir2_leafn_add (struct xfs_buf *bp,/* leaf buffer */ -xfs_da_args_t *args,/* operation arguments */ +struct xfs_da_args *args,/* operation arguments */ int index)/* insertion pt for new entry */ { +struct xfs_dir3_icleaf_hdr leafhdr; +struct xfs_inode *dp = args->dp; +struct xfs_dir2_leaf *leaf = bp->b_addr; +struct xfs_dir2_leaf_entry *lep; +struct xfs_dir2_leaf_entry *ents;int compact;/* compacting stale leaves */ -xfs_inode_t *dp;/* incore directory inode */ -int highstale;/* next stale entry */ -xfs_dir2_leaf_t *leaf;/* leaf structure */ -xfs_dir2_leaf_entry_t *lep;/* leaf entry */ +int highstale =0 ;/* next stale entry */ int lfloghigh;/* high leaf entry logging */ int lfloglow;/* low leaf entry logging */ -int lowstale;/* previous stale entry */ -struct xfs_dir3_icleaf_hdr leafhdr; -struct xfs_dir2_leaf_entry *ents; +int lowstale =0 ;/* previous stale entry */ trace_xfs_dir2_leafn_add (args, index); - dp = args->dp; - leaf = bp->b_addr; - highstale =0 ; - lowstale =0 ; dp->d_ops->leaf_hdr_from_disk (&leafhdr, leaf); ents = dp->d_ops->leaf_ents_p (leaf);
Quoted 38 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
Remove typedefs and consolidate local variable initialization.
Signed-off-by Darrick J. Wong <[email protected]>--- fs/xfs/libxfs/xfs_dir2_node.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-)fs/xfs/libxfs/xfs_dir2_node.c +7
-8@@ -426,26 +426,22 @@ xfs_dir2_leaf_to_node(static int /* error */ xfs_dir2_leafn_add (struct xfs_buf *bp,/* leaf buffer */ -xfs_da_args_t *args,/* operation arguments */ +struct xfs_da_args *args,/* operation arguments */ int index)/* insertion pt for new entry */ { +struct xfs_dir3_icleaf_hdr leafhdr; +struct xfs_inode *dp = args->dp; +struct xfs_dir2_leaf *leaf = bp->b_addr; +struct xfs_dir2_leaf_entry *lep; +struct xfs_dir2_leaf_entry *ents;int compact;/* compacting stale leaves */ -xfs_inode_t *dp;/* incore directory inode */ -int highstale;/* next stale entry */ -xfs_dir2_leaf_t *leaf;/* leaf structure */ -xfs_dir2_leaf_entry_t *lep;/* leaf entry */ +int highstale =0 ;/* next stale entry */ int lfloghigh;/* high leaf entry logging */ int lfloglow;/* low leaf entry logging */ -int lowstale;/* previous stale entry */ -struct xfs_dir3_icleaf_hdr leafhdr; -struct xfs_dir2_leaf_entry *ents;
fs/xfs/libxfs/xfs_dir2_node.c xfs_dir2_leaf_to_node( · line 446
Quoted 10 lines
fs/xfs/libxfs/xfs_dir2_node.c +1
-4+int lowstale =0 ;/* previous stale entry */ trace_xfs_dir2_leafn_add (args, index); - dp = args->dp; - leaf = bp->b_addr; - highstale =0 ; - lowstale =0 ; dp->d_ops->leaf_hdr_from_disk (&leafhdr, leaf); ents = dp->d_ops->leaf_ents_p (leaf);
What about moving the initialization of ents above? (Or would that be over the line limit?)
In general, I like this change (I considered asking Nathan to do the consolidation of declaration and initialization as you've done). The additional part of converting from _t to struct * is less interesting (but still ok). It's better to be consistent within the function scope, but this translation unit is still a mismatch of styles. If the goal is to avoid typedefs, consider removing them from existence and the required work to consistently not use them throughout this code.
Signature · 2 lines
Thanks, ~Nick Desaulniers
Quoted 43 lines · Nick Desaulniers
Quoted 42 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
Remove typedefs and consolidate local variable initialization.
Signed-off-by Darrick J. Wong <[email protected]>--- fs/xfs/libxfs/xfs_dir2_node.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-)fs/xfs/libxfs/xfs_dir2_node.c +8
-8@@ -426,26 +426,22 @@ xfs_dir2_leaf_to_node(static int /* error */ xfs_dir2_leafn_add (struct xfs_buf *bp,/* leaf buffer */ -xfs_da_args_t *args,/* operation arguments */ +struct xfs_da_args *args,/* operation arguments */ int index)/* insertion pt for new entry */ { +struct xfs_dir3_icleaf_hdr leafhdr; +struct xfs_inode *dp = args->dp; +struct xfs_dir2_leaf *leaf = bp->b_addr; +struct xfs_dir2_leaf_entry *lep; +struct xfs_dir2_leaf_entry *ents;int compact;/* compacting stale leaves */ -xfs_inode_t *dp;/* incore directory inode */ -int highstale;/* next stale entry */ -xfs_dir2_leaf_t *leaf;/* leaf structure */ -xfs_dir2_leaf_entry_t *lep;/* leaf entry */ +int highstale =0 ;/* next stale entry */ int lfloghigh;/* high leaf entry logging */ int lfloglow;/* low leaf entry logging */ -int lowstale;/* previous stale entry */ -struct xfs_dir3_icleaf_hdr leafhdr; -struct xfs_dir2_leaf_entry *ents; +int lowstale =0 ;/* previous stale entry */ trace_xfs_dir2_leafn_add (args, index);
Quoted 9 lines
fs/xfs/libxfs/xfs_dir2_node.c xfs_dir2_leaf_to_node( · line 446
Quoted 6 lines
fs/xfs/libxfs/xfs_dir2_node.c +0
-4- dp = args->dp; - leaf = bp->b_addr; - highstale =0 ; - lowstale =0 ; dp->d_ops->leaf_hdr_from_disk (&leafhdr, leaf); ents = dp->d_ops->leaf_ents_p (leaf);What about moving the initialization of
entsabove? (Or would that be over the line limit?)
It might be over the line limit, but more importantly I prefer to have the tracepoint fire before we start interpreting the on-disk metadata. That way, ftrace data will show exactly where we were in the kernel if any corruption warnings are emitted during that interpretation.
I don't think either of those two functions do that today, but I don't want to leave a logic bomb in case they ever start doing that.
Quoted 8 lines
In general, I like this change (I considered asking Nathan to do the consolidation of declaration and initialization as you've done). The additional part of converting from _t to struct * is less interesting (but still ok). It's better to be consistent within the function scope, but this translation unit is still a mismatch of styles. If the goal is to avoid typedefs, consider removing them from existence and the required work to consistently not use them throughout this code.
Yeah, we're slowly converting away from the _t typedefs (and other IRIXisms) as parts of code get reworked, though of course there's nothing obvious to suggest that this (slow transition) is in progress nor that we're ok with the inconsistent formatting in the meantime, which is why I accepted the original patch and added this one to do the style conversions.
--D
Quoted 3 lines
Signature · 2 lines
Thanks, ~Nick Desaulniers
Nick Desaulniers
Reviewed-byQuoted 55 lines · Darrick J. Wong
Quoted 43 lines · Nick Desaulniers
Quoted 42 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
Remove typedefs and consolidate local variable initialization.
Signed-off-by Darrick J. Wong <[email protected]>--- fs/xfs/libxfs/xfs_dir2_node.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-)fs/xfs/libxfs/xfs_dir2_node.c +8
-8@@ -426,26 +426,22 @@ xfs_dir2_leaf_to_node(static int /* error */ xfs_dir2_leafn_add (struct xfs_buf *bp,/* leaf buffer */ -xfs_da_args_t *args,/* operation arguments */ +struct xfs_da_args *args,/* operation arguments */ int index)/* insertion pt for new entry */ { +struct xfs_dir3_icleaf_hdr leafhdr; +struct xfs_inode *dp = args->dp; +struct xfs_dir2_leaf *leaf = bp->b_addr; +struct xfs_dir2_leaf_entry *lep; +struct xfs_dir2_leaf_entry *ents;int compact;/* compacting stale leaves */ -xfs_inode_t *dp;/* incore directory inode */ -int highstale;/* next stale entry */ -xfs_dir2_leaf_t *leaf;/* leaf structure */ -xfs_dir2_leaf_entry_t *lep;/* leaf entry */ +int highstale =0 ;/* next stale entry */ int lfloghigh;/* high leaf entry logging */ int lfloglow;/* low leaf entry logging */ -int lowstale;/* previous stale entry */ -struct xfs_dir3_icleaf_hdr leafhdr; -struct xfs_dir2_leaf_entry *ents; +int lowstale =0 ;/* previous stale entry */ trace_xfs_dir2_leafn_add (args, index);Quoted 9 lines
fs/xfs/libxfs/xfs_dir2_node.c xfs_dir2_leaf_to_node( · line 446
Quoted 6 lines
fs/xfs/libxfs/xfs_dir2_node.c +0
-4- dp = args->dp; - leaf = bp->b_addr; - highstale =0 ; - lowstale =0 ; dp->d_ops->leaf_hdr_from_disk (&leafhdr, leaf); ents = dp->d_ops->leaf_ents_p (leaf);What about moving the initialization of
entsabove? (Or would that be over the line limit?)
Quoted 7 lines
It might be over the line limit, but more importantly I prefer to have the tracepoint fire before we start interpreting the on-disk metadata. That way, ftrace data will show exactly where we were in the kernel if any corruption warnings are emitted during that interpretation.
I don't think either of those two functions do that today, but I don't want to leave a logic bomb in case they ever start doing that.
Makes sense, ents is initialized to the results of function call. Thanks for the additional info, for accepting the earlier patch, and this additional cleanup.
Signature · 2 lines
Thanks, ~Nick Desaulniers
Quoted 61 lines · Nick Desaulniers
Quoted 60 lines · Darrick J. Wong
Quoted 43 lines · Nick Desaulniers
Quoted 42 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
Remove typedefs and consolidate local variable initialization.
Signed-off-by Darrick J. Wong <[email protected]>--- fs/xfs/libxfs/xfs_dir2_node.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-)fs/xfs/libxfs/xfs_dir2_node.c +8
-8@@ -426,26 +426,22 @@ xfs_dir2_leaf_to_node(static int /* error */ xfs_dir2_leafn_add (struct xfs_buf *bp,/* leaf buffer */ -xfs_da_args_t *args,/* operation arguments */ +struct xfs_da_args *args,/* operation arguments */ int index)/* insertion pt for new entry */ { +struct xfs_dir3_icleaf_hdr leafhdr; +struct xfs_inode *dp = args->dp; +struct xfs_dir2_leaf *leaf = bp->b_addr; +struct xfs_dir2_leaf_entry *lep; +struct xfs_dir2_leaf_entry *ents;int compact;/* compacting stale leaves */ -xfs_inode_t *dp;/* incore directory inode */ -int highstale;/* next stale entry */ -xfs_dir2_leaf_t *leaf;/* leaf structure */ -xfs_dir2_leaf_entry_t *lep;/* leaf entry */ +int highstale =0 ;/* next stale entry */ int lfloghigh;/* high leaf entry logging */ int lfloglow;/* low leaf entry logging */ -int lowstale;/* previous stale entry */ -struct xfs_dir3_icleaf_hdr leafhdr; -struct xfs_dir2_leaf_entry *ents; +int lowstale =0 ;/* previous stale entry */ trace_xfs_dir2_leafn_add (args, index);Quoted 9 lines
fs/xfs/libxfs/xfs_dir2_node.c xfs_dir2_leaf_to_node( · line 446
Quoted 6 lines
fs/xfs/libxfs/xfs_dir2_node.c +0
-4- dp = args->dp; - leaf = bp->b_addr; - highstale =0 ; - lowstale =0 ; dp->d_ops->leaf_hdr_from_disk (&leafhdr, leaf); ents = dp->d_ops->leaf_ents_p (leaf);What about moving the initialization of
entsabove? (Or would that be over the line limit?)It might be over the line limit, but more importantly I prefer to have the tracepoint fire before we start interpreting the on-disk metadata. That way, ftrace data will show exactly where we were in the kernel if any corruption warnings are emitted during that interpretation.
Quoted 7 lines
Quoted 2 lines
I don't think either of those two functions do that today, but I don't want to leave a logic bomb in case they ever start doing that.
Makes sense, ents is initialized to the results of function call. Thanks for the additional info, for accepting the earlier patch, and this additional cleanup.
Reviewed-by Nick Desaulniers <[email protected]>
Thanks for the review!
By the way, does clang complain about highstale/lowstale in xfs_dir2_leaf_addname being uninitialized too? Just wondering since smatch/sparse do...
--D
Quoted 3 lines
Signature · 2 lines
Thanks, ~Nick Desaulniers
Quoted 70 lines · Darrick J. Wong
Quoted 61 lines · Nick Desaulniers
Quoted 60 lines · Darrick J. Wong
Quoted 43 lines · Nick Desaulniers
Quoted 42 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
Remove typedefs and consolidate local variable initialization.
Signed-off-by Darrick J. Wong <[email protected]>--- fs/xfs/libxfs/xfs_dir2_node.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-)fs/xfs/libxfs/xfs_dir2_node.c +8
-8@@ -426,26 +426,22 @@ xfs_dir2_leaf_to_node(static int /* error */ xfs_dir2_leafn_add (struct xfs_buf *bp,/* leaf buffer */ -xfs_da_args_t *args,/* operation arguments */ +struct xfs_da_args *args,/* operation arguments */ int index)/* insertion pt for new entry */ { +struct xfs_dir3_icleaf_hdr leafhdr; +struct xfs_inode *dp = args->dp; +struct xfs_dir2_leaf *leaf = bp->b_addr; +struct xfs_dir2_leaf_entry *lep; +struct xfs_dir2_leaf_entry *ents;int compact;/* compacting stale leaves */ -xfs_inode_t *dp;/* incore directory inode */ -int highstale;/* next stale entry */ -xfs_dir2_leaf_t *leaf;/* leaf structure */ -xfs_dir2_leaf_entry_t *lep;/* leaf entry */ +int highstale =0 ;/* next stale entry */ int lfloghigh;/* high leaf entry logging */ int lfloglow;/* low leaf entry logging */ -int lowstale;/* previous stale entry */ -struct xfs_dir3_icleaf_hdr leafhdr; -struct xfs_dir2_leaf_entry *ents; +int lowstale =0 ;/* previous stale entry */ trace_xfs_dir2_leafn_add (args, index);Quoted 9 lines
fs/xfs/libxfs/xfs_dir2_node.c xfs_dir2_leaf_to_node( · line 446
Quoted 6 lines
fs/xfs/libxfs/xfs_dir2_node.c +0
-4- dp = args->dp; - leaf = bp->b_addr; - highstale =0 ; - lowstale =0 ; dp->d_ops->leaf_hdr_from_disk (&leafhdr, leaf); ents = dp->d_ops->leaf_ents_p (leaf);What about moving the initialization of
entsabove? (Or would that be over the line limit?)It might be over the line limit, but more importantly I prefer to have the tracepoint fire before we start interpreting the on-disk metadata. That way, ftrace data will show exactly where we were in the kernel if any corruption warnings are emitted during that interpretation.
Quoted 7 lines
Quoted 2 lines
I don't think either of those two functions do that today, but I don't want to leave a logic bomb in case they ever start doing that.
Makes sense, ents is initialized to the results of function call. Thanks for the additional info, for accepting the earlier patch, and this additional cleanup.
Reviewed-by Nick Desaulniers <[email protected]>
Quoted 6 lines
Thanks for the review!
By the way, does clang complain about highstale/lowstale in
xfs_dir2_leaf_addnamebeing uninitialized too? Just wondering since smatch/sparse do...
It does not, which is bizarre since it's the exact same pattern. Definitely something to look into...
Cheers,
Nathan
Quoted 5 lines
--D
Quoted 3 lines
Signature · 2 lines
Thanks, ~Nick Desaulniers