btrfs_map_block tidyups
Hi all,
Dan reported a static type checker complained about the num_mirror_ret output argument in btrfs_map_block, so the first patch cleans that up. The second one simplifies a conditional right next to it.
Diffstat:
volumes.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
PATCH 1/2 btrfs: be a bit more careful when setting mirror_num_ret in btrfs_map_block
The mirror_num_ret is allowed to be NULL, although it has to be set when smap is set. Unfortunately that is not a well enough specifiable invariant for static type checkers, so add a NULL check to make sure they are fine.
--- fs/btrfs/volumes.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/btrfs/volumes.c +2 -1
@@ -6406,7 +6406,8 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, (op == BTRFS_MAP_READ || !dev_replace_is_ongoing || !dev_replace->tgtdev)) {set_io_stripe (smap, map, stripe_index, stripe_offset, stripe_nr); - *mirror_num_ret = mirror_num; +if (mirror_num_ret) + *mirror_num_ret = mirror_num; *bioc_ret =NULL ; ret =0 ; goto out;
Signature · 1 line
2.39.2
Re: [PATCH 1/2] btrfs: be a bit more careful when setting mirror_num_ret in btrfs_map_block
Quoted 8 lines · Christoph Hellwig
The
mirror_num_retis allowed to be NULL, although it has to be set when smap is set. Unfortunately that is not a well enough specifiable invariant for static type checkers, so add a NULL check to make sure they are fine.Fixes 03793cbbc80f ("btrfs: add fast path for single device io in __btrfs_map_block")Reported-by Dan Carpenter <[email protected]>Signed-off-by Christoph Hellwig <[email protected]>
Thanks,
Qu
Quoted 18 lines
--- fs/btrfs/volumes.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)fs/btrfs/volumes.c +2
-1@@ -6406,7 +6406,8 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, (op == BTRFS_MAP_READ || !dev_replace_is_ongoing || !dev_replace->tgtdev)) {set_io_stripe (smap, map, stripe_index, stripe_offset, stripe_nr); - *mirror_num_ret = mirror_num; +if (mirror_num_ret) + *mirror_num_ret = mirror_num; *bioc_ret =NULL ; ret =0 ; goto out;
Re: [PATCH 1/2] btrfs: be a bit more careful when setting mirror_num_ret in btrfs_map_block
In reply to Christoph HellwigLooks good,
PATCH 2/2 btrfs: simplify the no-bioc fast path condition in btrfs_map_block
In reply to Christoph Hellwignr_alloc_stripes can't be one if we are writing to a replacement device, as it is incremented for that case right above. Remove the duplicate checks.
--- fs/btrfs/volumes.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
fs/btrfs/volumes.c +1 -3
@@ -6402,9 +6402,7 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op,* I/O context structure. */ if (smap && num_alloc_stripes ==1 && - !((map->type &BTRFS_BLOCK_GROUP_RAID56_MASK ) && mirror_num >1 ) && - (op ==BTRFS_MAP_READ || !dev_replace_is_ongoing || - !dev_replace->tgtdev)) { + !((map->type &BTRFS_BLOCK_GROUP_RAID56_MASK ) && mirror_num >1 )) {set_io_stripe (smap, map, stripe_index, stripe_offset, stripe_nr);if (mirror_num_ret) *mirror_num_ret = mirror_num;
Signature · 1 line
2.39.2
Re: [PATCH 2/2] btrfs: simplify the no-bioc fast path condition in btrfs_map_block
Quoted 5 lines · Christoph Hellwig
nr_alloc_stripescan't be one if we are writing to a replacement device, as it is incremented for that case right above. Remove the duplicate checks.Signed-off-by Christoph Hellwig <[email protected]>
Thanks,
Qu
Quoted 19 lines
--- fs/btrfs/volumes.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)fs/btrfs/volumes.c +1
-3@@ -6402,9 +6402,7 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op,* I/O context structure. */ if (smap && num_alloc_stripes ==1 && - !((map->type &BTRFS_BLOCK_GROUP_RAID56_MASK ) && mirror_num >1 ) && - (op ==BTRFS_MAP_READ || !dev_replace_is_ongoing || - !dev_replace->tgtdev)) { + !((map->type &BTRFS_BLOCK_GROUP_RAID56_MASK ) && mirror_num >1 )) {set_io_stripe (smap, map, stripe_index, stripe_offset, stripe_nr);if (mirror_num_ret) *mirror_num_ret = mirror_num;
Re: [PATCH 2/2] btrfs: simplify the no-bioc fast path condition in btrfs_map_block
In reply to Christoph HellwigLooks good,
Quoted 5 lines · Christoph Hellwig
Hi all,
Dan reported a static type checker complained about the
num_mirror_retoutput argument inbtrfs_map_block, so the first patch cleans that up. The second one simplifies a conditional right next to it.
Added to misc-next, thanks.