This patch checks if a device added to btrfs is a zoned block device. If it
is, load zones information and the zone size for the device.

For a btrfs volume composed of multiple zoned block devices, all devices
must have the same zone size.

Signed-off-by: Naohiro Aota <naohiro.a...@wdc.com>
---
 common/device-scan.c | 10 ++++++++++
 volumes.c            | 18 ++++++++++++++++++
 volumes.h            |  6 ++++++
 3 files changed, 34 insertions(+)

diff --git a/common/device-scan.c b/common/device-scan.c
index 2c5ae225f710..5df77b9b68d7 100644
--- a/common/device-scan.c
+++ b/common/device-scan.c
@@ -135,6 +135,16 @@ int btrfs_add_to_fsid(struct btrfs_trans_handle *trans,
                goto out;
        }
 
+       ret = btrfs_get_zone_info(fd, path, fs_info->fs_devices->hmzoned,
+                                 &device->zone_info);
+       if (ret)
+               goto out;
+       if (device->zone_info.zone_size != fs_info->fs_devices->zone_size) {
+               error("Device zone size differ");
+               ret = -EINVAL;
+               goto out;
+       }
+
        disk_super = (struct btrfs_super_block *)buf;
        dev_item = &disk_super->dev_item;
 
diff --git a/volumes.c b/volumes.c
index f99fddc7cf6f..a0ebed547faa 100644
--- a/volumes.c
+++ b/volumes.c
@@ -196,6 +196,8 @@ static int device_list_add(const char *path,
        u64 found_transid = btrfs_super_generation(disk_super);
        bool metadata_uuid = (btrfs_super_incompat_flags(disk_super) &
                BTRFS_FEATURE_INCOMPAT_METADATA_UUID);
+       bool hmzoned = btrfs_super_incompat_flags(disk_super) &
+               BTRFS_FEATURE_INCOMPAT_HMZONED;
 
        if (metadata_uuid)
                fs_devices = find_fsid(disk_super->fsid,
@@ -285,6 +287,7 @@ static int device_list_add(const char *path,
        if (fs_devices->lowest_devid > devid) {
                fs_devices->lowest_devid = devid;
        }
+       fs_devices->hmzoned = hmzoned;
        *fs_devices_ret = fs_devices;
        return 0;
 }
@@ -355,6 +358,8 @@ int btrfs_open_devices(struct btrfs_fs_devices *fs_devices, 
int flags)
        struct btrfs_device *device;
        int ret;
 
+       fs_devices->zone_size = 0;
+
        list_for_each_entry(device, &fs_devices->devices, dev_list) {
                if (!device->name) {
                        printk("no name for device %llu, skip it now\n", 
device->devid);
@@ -378,6 +383,19 @@ int btrfs_open_devices(struct btrfs_fs_devices 
*fs_devices, int flags)
                device->fd = fd;
                if (flags & O_RDWR)
                        device->writeable = 1;
+
+               ret = btrfs_get_zone_info(fd, device->name, fs_devices->hmzoned,
+                                         &device->zone_info);
+               if (ret != 0)
+                       goto fail;
+               if (!fs_devices->zone_size) {
+                       fs_devices->zone_size = device->zone_info.zone_size;
+               } else if (device->zone_info.zone_size !=
+                          fs_devices->zone_size) {
+                       error("Device zone size differ");
+                       ret = -EINVAL;
+                       goto fail;
+               }
        }
        return 0;
 fail:
diff --git a/volumes.h b/volumes.h
index 586588c871ab..edbb0f36aa75 100644
--- a/volumes.h
+++ b/volumes.h
@@ -22,12 +22,15 @@
 #include "kerncompat.h"
 #include "ctree.h"
 
+#include "common/hmzoned.h"
+
 #define BTRFS_STRIPE_LEN       SZ_64K
 
 struct btrfs_device {
        struct list_head dev_list;
        struct btrfs_root *dev_root;
        struct btrfs_fs_devices *fs_devices;
+       struct btrfs_zone_info zone_info;
 
        u64 total_ios;
 
@@ -87,6 +90,9 @@ struct btrfs_fs_devices {
 
        int seeding;
        struct btrfs_fs_devices *seed;
+
+       u64 zone_size;
+       bool hmzoned;
 };
 
 struct btrfs_bio_stripe {
-- 
2.23.0

Reply via email to