Skip to contentSkip to conversation

btrfs: zoned: two small style improvements for zone finishing

PATCH In review Johannes Thumshirn 3 participants 6 messages Jul 22, 2025 – Jul 24, 2025 Btrfs file system

lore
Share & tools
lore
#0 lore raw

v3 cover btrfs: zoned: two small style improvements for zone finishing

From: Johannes Thumshirn <[email protected]>

Two small improvements for zone finish calls. The frist one changes btrfs_zone_finish_endio_workfn() to directly call do_zone_finish(), as most of the work done in btrfs_zone_finish_endio() is not needed in this context.

The second one adds error propagation to btrfs_zone_finish_endio() so it's caller btrfs_finish_one_ordered() can do error handling (in case the chunk map block group lookup failes for some reason).

Changes to v2:
- Don't ASSERT() do_zone_finish()'s return value but set FS to r/o Link to v2:
https://lore.kernel.org/linux-btrfs/[email protected]

Changes to v1:
- Remove stray bg->last_eb = NULL setting
- ASSERT() do_zone_finish() returns sucessfull
- Remove stray {}
- Remove ASSERT(!block_group) after if (!block_group)

Link to v1:
https://lore.kernel.org/linux-btrfs/[email protected]

Johannes Thumshirn (2):
btrfs: directly call do_zone_finish() from
btrfs_zone_finish_endio_workfn()
btrfs: zoned: return error from btrfs_zone_finish_endio()

 fs/btrfs/inode.c |  7 ++++---
 fs/btrfs/zoned.c | 14 ++++++++++----
 fs/btrfs/zoned.h |  9 ++++++---
 3 files changed, 20 insertions(+), 10 deletions(-)
Signature · 1 line
2.50.1
#1 lore raw

PATCH v3 1/2 btrfs: zoned: directly call do_zone_finish() from btrfs_zone_finish_endio_workfn()

From: Johannes Thumshirn <[email protected]>

When btrfs_zone_finish_endio_workfn() is calling btrfs_zone_finish_endio() it already has a pointer to the block group. Furthermore btrfs_zone_finish_endio() does additional checks if the block group can be finished or not.

But in the context of btrfs_zone_finish_endio_workfn() only the actual call to do_zone_finish() is of interest, as the skipping condition when there is still room to allocate from the block group cannot be checked.

Directly call do_zone_finish() on the block group.

---
 fs/btrfs/zoned.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
fs/btrfs/zoned.c +5 -1
index 245e813ecd78..e997b236d00a 100644
@@ -2461,12 +2461,16 @@ void btrfs_zone_finish_endio(struct btrfs_fs_info *fs_info, u64 logical, u64 len
 
 static void btrfs_zone_finish_endio_workfn(struct work_struct *work)
 {
+	int ret;
 	struct btrfs_block_group *bg =
 		container_of(work, struct btrfs_block_group, zone_finish_work);
 
 	wait_on_extent_buffer_writeback(bg->last_eb);
 	free_extent_buffer(bg->last_eb);
-	btrfs_zone_finish_endio(bg->fs_info, bg->start, bg->length);
+	ret = do_zone_finish(bg, true);
+	if (ret)
+		btrfs_handle_fs_error(bg->fs_info, ret,
+				      "Failed to finish block-group's zone");
 	btrfs_put_block_group(bg);
 }
 
Signature · 1 line
2.50.1
#4 lore raw

PATCH v3 2/2 btrfs: zoned: return error from btrfs_zone_finish_endio()

In reply to Johannes Thumshirn

From: Johannes Thumshirn <[email protected]>

Now that btrfs_zone_finish_endio_workfn() is directly calling do_zone_finish() the only caller of btrfs_zone_finish_endio() is btrfs_finish_one_ordered().

btrfs_finish_one_ordered() already has error handling in-place so btrfs_zone_finish_endio() can return an error if the block group lookup fails.

Also as btrfs_zone_finish_endio() already checks for zoned filesystems and returns early, there's no need to do this in the caller.

---
 fs/btrfs/inode.c | 7 ++++---
 fs/btrfs/zoned.c | 8 +++++---
 fs/btrfs/zoned.h | 9 ++++++---
 3 files changed, 15 insertions(+), 9 deletions(-)
fs/btrfs/inode.c +4 -3
index 6d9a8d8bea4c..793b1d520e8d 100644
@@ -3109,9 +3109,10 @@ int btrfs_finish_one_ordered(struct btrfs_ordered_extent *ordered_extent)
 		goto out;
 	}
 
-	if (btrfs_is_zoned(fs_info))
-		btrfs_zone_finish_endio(fs_info, ordered_extent->disk_bytenr,
-					ordered_extent->disk_num_bytes);
+	ret = btrfs_zone_finish_endio(fs_info, ordered_extent->disk_bytenr,
+				      ordered_extent->disk_num_bytes);
+	if (ret)
+		goto out;
 
 	if (test_bit(BTRFS_ORDERED_TRUNCATED, &ordered_extent->flags)) {
 		truncated = true;
fs/btrfs/zoned.c +5 -3
index e997b236d00a..279446e98516 100644
@@ -2431,16 +2431,17 @@ bool btrfs_can_activate_zone(struct btrfs_fs_devices *fs_devices, u64 flags)
 	return ret;
 }
 
-void btrfs_zone_finish_endio(struct btrfs_fs_info *fs_info, u64 logical, u64 length)
+int btrfs_zone_finish_endio(struct btrfs_fs_info *fs_info, u64 logical, u64 length)
 {
 	struct btrfs_block_group *block_group;
 	u64 min_alloc_bytes;
 
 	if (!btrfs_is_zoned(fs_info))
-		return;
+		return 0;
 
 	block_group = btrfs_lookup_block_group(fs_info, logical);
-	ASSERT(block_group);
+	if (WARN_ON_ONCE(!block_group))
+		return -ENOENT;
 
 	/* No MIXED_BG on zoned btrfs. */
 	if (block_group->flags & BTRFS_BLOCK_GROUP_DATA)
@@ -2457,6 +2458,7 @@ void btrfs_zone_finish_endio(struct btrfs_fs_info *fs_info, u64 logical, u64 len
 
 out:
 	btrfs_put_block_group(block_group);
+	return 0;
 }
 
 static void btrfs_zone_finish_endio_workfn(struct work_struct *work)
fs/btrfs/zoned.h +6 -3
index 6e11533b8e14..17c5656580dd 100644
@@ -83,7 +83,7 @@ int btrfs_sync_zone_write_pointer(struct btrfs_device *tgt_dev, u64 logical,
 bool btrfs_zone_activate(struct btrfs_block_group *block_group);
 int btrfs_zone_finish(struct btrfs_block_group *block_group);
 bool btrfs_can_activate_zone(struct btrfs_fs_devices *fs_devices, u64 flags);
-void btrfs_zone_finish_endio(struct btrfs_fs_info *fs_info, u64 logical,
+int btrfs_zone_finish_endio(struct btrfs_fs_info *fs_info, u64 logical,
 			     u64 length);
 void btrfs_schedule_zone_finish_bg(struct btrfs_block_group *bg,
 				   struct extent_buffer *eb);
@@ -234,8 +234,11 @@ static inline bool btrfs_can_activate_zone(struct btrfs_fs_devices *fs_devices,
 	return true;
 }
 
-static inline void btrfs_zone_finish_endio(struct btrfs_fs_info *fs_info,
-					   u64 logical, u64 length) { }
+static inline int btrfs_zone_finish_endio(struct btrfs_fs_info *fs_info,
+					   u64 logical, u64 length)
+{
+	return 0;
+}
 
 static inline void btrfs_schedule_zone_finish_bg(struct btrfs_block_group *bg,
 						 struct extent_buffer *eb) { }
Signature · 1 line
2.50.1
Reviewed-by on v3 1/2
#2 lore raw

Re: [PATCH v3 1/2] btrfs: zoned: directly call do_zone_finish() from btrfs_zone_finish_endio_workfn()

In reply to Johannes Thumshirn
Quoted 7 lines · Johannes Thumshirn

From: Johannes Thumshirn <[email protected]>

When btrfs_zone_finish_endio_workfn() is calling btrfs_zone_finish_endio() it already has a pointer to the block group. Furthermore btrfs_zone_finish_endio() does additional checks if the block group can be finished or not.

Quoted 7 lines

But in the context of btrfs_zone_finish_endio_workfn() only the actual call to do_zone_finish() is of interest, as the skipping condition when there is still room to allocate from the block group cannot be checked.

Directly call do_zone_finish() on the block group.

Looks OK to me.

Signature · 2 lines
Damien Le Moal
Western Digital Research
Reviewed-by on v3 2/2
#5 lore raw

Re: [PATCH v3 2/2] btrfs: zoned: return error from btrfs_zone_finish_endio()

In reply to Johannes Thumshirn
Quoted 6 lines · Johannes Thumshirn

From: Johannes Thumshirn <[email protected]>

Now that btrfs_zone_finish_endio_workfn() is directly calling do_zone_finish() the only caller of btrfs_zone_finish_endio() is btrfs_finish_one_ordered().

Quoted 8 lines

btrfs_finish_one_ordered() already has error handling in-place so btrfs_zone_finish_endio() can return an error if the block group lookup fails.

Also as btrfs_zone_finish_endio() already checks for zoned filesystems and returns early, there's no need to do this in the caller.

Looks OK.

Signature · 2 lines
Damien Le Moal
Western Digital Research
#3 lore raw

Re: [PATCH v3 1/2] btrfs: zoned: directly call do_zone_finish() from btrfs_zone_finish_endio_workfn()

In reply to Johannes Thumshirn
Quoted 27 lines · Johannes Thumshirn

From: Johannes Thumshirn <[email protected]>

When btrfs_zone_finish_endio_workfn() is calling btrfs_zone_finish_endio() it already has a pointer to the block group. Furthermore btrfs_zone_finish_endio() does additional checks if the block group can be finished or not.

But in the context of btrfs_zone_finish_endio_workfn() only the actual call to do_zone_finish() is of interest, as the skipping condition when there is still room to allocate from the block group cannot be checked.

Directly call do_zone_finish() on the block group.

---
 fs/btrfs/zoned.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
fs/btrfs/zoned.c +1 -0
index 245e813ecd78..e997b236d00a 100644
@@ -2461,12 +2461,16 @@ void btrfs_zone_finish_endio(struct btrfs_fs_info *fs_info, u64 logical, u64 len
 
 static void btrfs_zone_finish_endio_workfn(struct work_struct *work)
 {
+	int ret;

fs/btrfs/zoned.c void btrfs_zone_finish_endio(struct btrfs_fs_info *fs_info, u64 logical, u64 len · line 2473

Quoted 10 lines
fs/btrfs/zoned.c +4 -1
 	struct btrfs_block_group *bg =
 		container_of(work, struct btrfs_block_group, zone_finish_work);
 
 	wait_on_extent_buffer_writeback(bg->last_eb);
 	free_extent_buffer(bg->last_eb);
-	btrfs_zone_finish_endio(bg->fs_info, bg->start, bg->length);
+	ret = do_zone_finish(bg, true);
+	if (ret)
+		btrfs_handle_fs_error(bg->fs_info, ret,
+				      "Failed to finish block-group's zone");

The btrfs_handle_fs_error() is odd and should not be used in new code. Is there another way how you can signal a problem from the endio callback?