Skip to content

Commit 0a05faf

Browse files
morbidrsakdave
authored andcommitted
btrfs: zoned: introduce a minimal zone size 4M and reject mount
Zoned devices are expected to have zone sizes in the range of 1-2GB for ZNS SSDs and SMR HDDs have zone sizes of 256MB, so there is no need to allow arbitrarily small zone sizes on btrfs. But for testing purposes with emulated devices it is sometimes desirable to create devices with as small as 4MB zone size to uncover errors. So use 4MB as the smallest possible zone size and reject mounts of devices with a smaller zone size. Reviewed-by: Nikolay Borisov <[email protected]> Signed-off-by: Johannes Thumshirn <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent d8101a0 commit 0a05faf

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

fs/btrfs/zoned.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,13 @@
5151
#define BTRFS_MIN_ACTIVE_ZONES (BTRFS_SUPER_MIRROR_MAX + 5)
5252

5353
/*
54-
* Maximum supported zone size. Currently, SMR disks have a zone size of
55-
* 256MiB, and we are expecting ZNS drives to be in the 1-4GiB range. We do not
56-
* expect the zone size to become larger than 8GiB in the near future.
54+
* Minimum / maximum supported zone size. Currently, SMR disks have a zone
55+
* size of 256MiB, and we are expecting ZNS drives to be in the 1-4GiB range.
56+
* We do not expect the zone size to become larger than 8GiB or smaller than
57+
* 4MiB in the near future.
5758
*/
5859
#define BTRFS_MAX_ZONE_SIZE SZ_8G
60+
#define BTRFS_MIN_ZONE_SIZE SZ_4M
5961

6062
#define SUPER_INFO_SECTORS ((u64)BTRFS_SUPER_INFO_SIZE >> SECTOR_SHIFT)
6163

@@ -402,6 +404,13 @@ int btrfs_get_dev_zone_info(struct btrfs_device *device, bool populate_cache)
402404
zone_info->zone_size, BTRFS_MAX_ZONE_SIZE);
403405
ret = -EINVAL;
404406
goto out;
407+
} else if (zone_info->zone_size < BTRFS_MIN_ZONE_SIZE) {
408+
btrfs_err_in_rcu(fs_info,
409+
"zoned: %s: zone size %llu smaller than supported minimum %u",
410+
rcu_str_deref(device->name),
411+
zone_info->zone_size, BTRFS_MIN_ZONE_SIZE);
412+
ret = -EINVAL;
413+
goto out;
405414
}
406415

407416
nr_sectors = bdev_nr_sectors(bdev);

0 commit comments

Comments
 (0)