@@ -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;
}
/**
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(-)