diff mbox series

[25/26] btrfs-progs: zoned: device-add: support ZONED device

Message ID f4c9911d1cefee8fc678b4f9be068acfb8fae641.1619416549.git.naohiro.aota@wdc.com (mailing list archive)
State New, archived
Headers show
Series btrfs-progs: zoned: zoned block device support | expand

Commit Message

Naohiro Aota April 26, 2021, 6:27 a.m. UTC
This patch 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 <naohiro.aota@wdc.com>
---
 cmds/device.c | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/cmds/device.c b/cmds/device.c
index adc21053fbc8..4cc104b788bb 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 file system '%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++;