diff mbox series

btrfs-progs: zoned: add upper and lower zone size boundarys

Message ID 20220210134900.184638-1-johannes.thumshirn@wdc.com (mailing list archive)
State New, archived
Headers show
Series btrfs-progs: zoned: add upper and lower zone size boundarys | expand

Commit Message

Johannes Thumshirn Feb. 10, 2022, 1:49 p.m. UTC
As we're not supporting arbitrarily big or small zone sizes in the kernel,
reject devices that don't fit in progs as well.

Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
---
 kernel-shared/zoned.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

Comments

David Sterba May 27, 2022, 3:02 p.m. UTC | #1
On Thu, Feb 10, 2022 at 05:49:00AM -0800, Johannes Thumshirn wrote:
> As we're not supporting arbitrarily big or small zone sizes in the kernel,
> reject devices that don't fit in progs as well.
> 
> Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>

I've updated the lower limit to 4M so it matches the recent update in
kernel and added patch to devel, thanks.
diff mbox series

Patch

diff --git a/kernel-shared/zoned.c b/kernel-shared/zoned.c
index 2a11a1d723aa..2665861f23c4 100644
--- a/kernel-shared/zoned.c
+++ b/kernel-shared/zoned.c
@@ -47,6 +47,9 @@ 
 #define BTRFS_SB_LOG_FIRST_SHIFT	const_ilog2(BTRFS_SB_LOG_FIRST_OFFSET)
 #define BTRFS_SB_LOG_SECOND_SHIFT	const_ilog2(BTRFS_SB_LOG_SECOND_OFFSET)
 
+#define BTRFS_MAX_ZONE_SIZE		(8ULL * SZ_1G)
+#define BTRFS_MIN_ZONE_SIZE		SZ_64M
+
 #define EMULATED_ZONE_SIZE		SZ_256M
 
 static int btrfs_get_dev_zone_info(struct btrfs_device *device);
@@ -307,6 +310,17 @@  static int report_zones(int fd, const char *file,
 	/* Allocate the zone information array */
 	zinfo->zone_size = zone_bytes;
 	zinfo->nr_zones = device_size / zone_bytes;
+
+	if (zinfo->zone_size > BTRFS_MAX_ZONE_SIZE) {
+		error("zoned: zone size %llu larger than supported maximum %llu",
+		      zinfo->zone_size, BTRFS_MAX_ZONE_SIZE);
+		exit(1);
+	} else if (zinfo->zone_size < BTRFS_MIN_ZONE_SIZE) {
+		error("zoned: zone size %llu smaller than supported minimum %u",
+		      zinfo->zone_size, BTRFS_MIN_ZONE_SIZE);
+		exit(1);
+	}
+
 	if (device_size & (zone_bytes - 1))
 		zinfo->nr_zones++;