diff mbox series

[26/26] btrfs-progs: zoned: introduce zoned support for device replace

Message ID 63e64f41e87756562d34322f19c78e5e5b4ec068.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 checks 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/replace.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/cmds/replace.c b/cmds/replace.c
index 53af8ca61898..1de4a6d3ca9f 100644
--- a/cmds/replace.c
+++ b/cmds/replace.c
@@ -122,12 +122,14 @@  static const char *const cmd_replace_start_usage[] = {
 static int cmd_replace_start(const struct cmd_struct *cmd,
 			     int argc, char **argv)
 {
+	struct btrfs_ioctl_feature_flags feature_flags;
 	struct btrfs_ioctl_dev_replace_args start_args = {0};
 	struct btrfs_ioctl_dev_replace_args status_args = {0};
 	int ret;
 	int i;
 	int fdmnt = -1;
 	int fddstdev = -1;
+	int zoned;
 	char *path;
 	char *srcdev;
 	char *dstdev = NULL;
@@ -182,6 +184,14 @@  static int cmd_replace_start(const struct cmd_struct *cmd,
 	if (fdmnt < 0)
 		goto leave_with_error;
 
+	ret = ioctl(fdmnt, BTRFS_IOC_GET_FEATURES, &feature_flags);
+	if (ret) {
+		error("zoned: ioctl(GET_FEATURES) on '%s' returns error: %m",
+		      path);
+		goto leave_with_error;
+	}
+	zoned = feature_flags.incompat_flags & BTRFS_FEATURE_INCOMPAT_ZONED;
+
 	/* check for possible errors before backgrounding */
 	status_args.cmd = BTRFS_IOCTL_DEV_REPLACE_CMD_STATUS;
 	status_args.result = BTRFS_IOCTL_DEV_REPLACE_RESULT_NO_RESULT;
@@ -286,7 +296,8 @@  static int cmd_replace_start(const struct cmd_struct *cmd,
 	strncpy((char *)start_args.start.tgtdev_name, dstdev,
 		BTRFS_DEVICE_PATH_NAME_MAX);
 	ret = btrfs_prepare_device(fddstdev, dstdev, &dstdev_block_count, 0,
-			PREP_DEVICE_ZERO_END | PREP_DEVICE_VERBOSE);
+			PREP_DEVICE_ZERO_END | PREP_DEVICE_VERBOSE |
+			(zoned ? PREP_DEVICE_ZONED : 0));
 	if (ret)
 		goto leave_with_error;