From 568f9ed26f7187dae6166b42667788beafc5f940 Mon Sep 17 00:00:00 2001 From: Naohiro Aota Date: Mon, 26 Apr 2021 15:27:41 +0900 Subject: [PATCH] btrfs-progs: device add: support adding zoned device Check if the target file system is flagged as ZONED. If it is, the device to be added is flagged PREP_DEVICE_ZONED. Also add checks to prevent mixing non-zoned devices and zoned devices. Signed-off-by: Naohiro Aota Signed-off-by: David Sterba --- cmds/device.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/cmds/device.c b/cmds/device.c index adc21053..99e6b4f6 100644 --- a/cmds/device.c +++ b/cmds/device.c @@ -29,6 +29,7 @@ #include "ioctl.h" #include "common/utils.h" #include "kernel-shared/volumes.h" +#include "kernel-shared/zoned.h" #include "cmds/filesystem-usage.h" #include "cmds/commands.h" @@ -65,6 +66,8 @@ static int cmd_device_add(const struct cmd_struct *cmd, int force = 0; int last_dev; bool enqueue = false; + int zoned; + struct btrfs_ioctl_feature_flags feature_flags; optind = 0; while (1) { @@ -113,12 +116,27 @@ static int cmd_device_add(const struct cmd_struct *cmd, return 1; } + ret = ioctl(fdmnt, BTRFS_IOC_GET_FEATURES, &feature_flags); + if (ret) { + error("error getting feature flags '%s': %m", mntpnt); + return 1; + } + zoned = (feature_flags.incompat_flags & BTRFS_FEATURE_INCOMPAT_ZONED); + for (i = optind; i < last_dev; i++){ struct btrfs_ioctl_vol_args ioctl_args; int devfd, res; u64 dev_block_count = 0; char *path; + if (!zoned && zoned_model(argv[i]) == ZONED_HOST_MANAGED) { + error( +"zoned: cannot add host-managed zoned device to non-zoned filesystem '%s'", + argv[i]); + ret++; + continue; + } + res = test_dev_for_mkfs(argv[i], force); if (res) { ret++; @@ -134,7 +152,8 @@ static int cmd_device_add(const struct cmd_struct *cmd, res = btrfs_prepare_device(devfd, argv[i], &dev_block_count, 0, PREP_DEVICE_ZERO_END | PREP_DEVICE_VERBOSE | - (discard ? PREP_DEVICE_DISCARD : 0)); + (discard ? PREP_DEVICE_DISCARD : 0) | + (zoned ? PREP_DEVICE_ZONED : 0)); close(devfd); if (res) { ret++;