Skip to contentSkip to conversation

btrfs_map_block tidyups

PATCH In review Christoph Hellwig 4 participants 8 messages Jun 27, 2023 – Jun 29, 2023 Btrfs file system

lore
Share & tools
lore
#0 lore raw

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(-)
#1 lore raw

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.

Fixes 03793cbbc80f ("btrfs: add fast path for single device io in __btrfs_map_block")
---
 fs/btrfs/volumes.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/btrfs/volumes.c +2 -1
index a536d0e0e05566..0d386ed44279ce 100644
@@ -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
Reviewed-by on v1 1/2
#2 lore raw

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_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.

Fixes 03793cbbc80f ("btrfs: add fast path for single device io in __btrfs_map_block")

Thanks,
Qu

Quoted 18 lines
---
  fs/btrfs/volumes.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
fs/btrfs/volumes.c +2 -1
index a536d0e0e05566..0d386ed44279ce 100644
@@ -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;
#4 lore raw

PATCH 2/2 btrfs: simplify the no-bioc fast path condition in btrfs_map_block

In reply to Christoph Hellwig

nr_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
index 0d386ed44279ce..4907ed9809109d 100644
@@ -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
Reviewed-by on v1 2/2
#5 lore raw

Re: [PATCH 2/2] btrfs: simplify the no-bioc fast path condition in btrfs_map_block

Quoted 5 lines · Christoph Hellwig

nr_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.

Thanks,
Qu

Quoted 19 lines
---
  fs/btrfs/volumes.c | 4 +---
  1 file changed, 1 insertion(+), 3 deletions(-)
fs/btrfs/volumes.c +1 -3
index 0d386ed44279ce..4907ed9809109d 100644
@@ -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;
#7 lore raw
In reply to Christoph Hellwig
Quoted 5 lines · Christoph Hellwig

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.

Added to misc-next, thanks.