diff mbox series

[4/4] btrfs-progs: zoned: fix and simplify dev_extent_hole_check_zoned()

Message ID 20220406014313.993961-5-naohiro.aota@wdc.com (mailing list archive)
State New, archived
Headers show
Series btrfs-progs: zoned: fix mkfs failure on various zone size | expand

Commit Message

Naohiro Aota April 6, 2022, 1:43 a.m. UTC
The previous patch revealed a bug in dev_extent_hole_check_zoned(). If the
given hole is OK to use as is, it should have just returned the hole. But
on the contrary, it shifts the hole start position by one zone. That
results in refusing any hole.

We don't use btrfs_ensure_empty_zones() in the btrfs-progs version of
dev_extent_hole_check_zoned() unlike the kernel side, because
btrfs_find_allocatable_zones() itself is doing the necessary checks. So, we
can just "return changed" if the "pos" is unchanged. That also makes the
loop and "changed" variable unnecessary.

So, fix and simplify the code in one shot.

Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
---
 kernel-shared/volumes.c | 29 +++++++++--------------------
 1 file changed, 9 insertions(+), 20 deletions(-)
diff mbox series

Patch

diff --git a/kernel-shared/volumes.c b/kernel-shared/volumes.c
index 0199bc26a8b4..598ac553442c 100644
--- a/kernel-shared/volumes.c
+++ b/kernel-shared/volumes.c
@@ -583,30 +583,19 @@  static bool dev_extent_hole_check_zoned(struct btrfs_device *device,
 					u64 *hole_start, u64 *hole_size,
 					u64 num_bytes)
 {
-	u64 zone_size = device->zone_info->zone_size;
 	u64 pos;
-	bool changed = false;
-
-	ASSERT(IS_ALIGNED(*hole_start, zone_size));
-
-	while (*hole_size > 0) {
-		pos = btrfs_find_allocatable_zones(device, *hole_start,
-						   *hole_start + *hole_size,
-						   num_bytes);
-		if (pos != *hole_start) {
-			*hole_size = *hole_start + *hole_size - pos;
-			*hole_start = pos;
-			changed = true;
-			if (*hole_size < num_bytes)
-				break;
-		}
 
-		*hole_start += zone_size;
-		*hole_size -= zone_size;
-		changed = true;
+	ASSERT(IS_ALIGNED(*hole_start, device->zone_info->zone_size));
+
+	pos = btrfs_find_allocatable_zones(device, *hole_start,
+					   *hole_start + *hole_size, num_bytes);
+	if (pos != *hole_start) {
+		*hole_size = *hole_start + *hole_size - pos;
+		*hole_start = pos;
+		return true;
 	}
 
-	return changed;
+	return false;
 }
 
 /**