linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH RESEND 0/3] btrfs-progs: Introduce device delete by devid
@ 2015-10-10 14:30 Anand Jain
  2015-10-10 14:30 ` [PATCH RESEND V2 1/3] btrfs-progs: Create is_numerical() helper function Anand Jain
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Anand Jain @ 2015-10-10 14:30 UTC (permalink / raw)
  To: linux-btrfs; +Cc: dsterba

This is the btrfs-progs part of the kernel patch
   Btrfs: Introduce device delete by devid

1/3 and 2/3 are preparatory patches to apply 3/3 below.

Anand Jain (3):
  btrfs-progs: Create is_numerical() helper function
  btrfs-progs: Code optimize and cleanup device add
  btrfs-progs: Introduce device delete by devid

 Documentation/btrfs-device.asciidoc |  4 +--
 cmds-device.c                       | 60 ++++++++++++++++++++++++++-----------
 cmds-replace.c                      | 11 -------
 ioctl.h                             | 14 ++++++++-
 utils-lib.c                         | 11 +++++++
 utils.h                             |  1 +
 6 files changed, 70 insertions(+), 31 deletions(-)

-- 
2.4.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH RESEND V2 1/3] btrfs-progs: Create is_numerical() helper function
  2015-10-10 14:30 [PATCH RESEND 0/3] btrfs-progs: Introduce device delete by devid Anand Jain
@ 2015-10-10 14:30 ` Anand Jain
  2015-10-10 14:30 ` [PATCH 2/3] btrfs-progs: Code optimize and cleanup device add Anand Jain
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Anand Jain @ 2015-10-10 14:30 UTC (permalink / raw)
  To: linux-btrfs; +Cc: dsterba

This is done by moving existing is_numerical() to utils-lib.c

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
V2: Subject updated from
    btrfs-progs: move is_numerical to utils-lib.h and make it non static

 cmds-replace.c | 11 -----------
 utils-lib.c    | 11 +++++++++++
 utils.h        |  1 +
 3 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/cmds-replace.c b/cmds-replace.c
index 9ab8438..86162b6 100644
--- a/cmds-replace.c
+++ b/cmds-replace.c
@@ -65,17 +65,6 @@ static const char * const replace_cmd_group_usage[] = {
 	NULL
 };
 
-static int is_numerical(const char *str)
-{
-	if (!(*str >= '0' && *str <= '9'))
-		return 0;
-	while (*str >= '0' && *str <= '9')
-		str++;
-	if (*str != '\0')
-		return 0;
-	return 1;
-}
-
 static int dev_replace_cancel_fd = -1;
 static void dev_replace_sigint_handler(int signal)
 {
diff --git a/utils-lib.c b/utils-lib.c
index 79ef35e..9ac0b7b 100644
--- a/utils-lib.c
+++ b/utils-lib.c
@@ -38,3 +38,14 @@ u64 arg_strtou64(const char *str)
 	}
 	return value;
 }
+
+int is_numerical(const char *str)
+{
+	if (!(*str >= '0' && *str <= '9'))
+		return 0;
+	while (*str >= '0' && *str <= '9')
+		str++;
+	if (*str != '\0')
+		return 0;
+	return 1;
+}
diff --git a/utils.h b/utils.h
index 192f3d1..0a2130d 100644
--- a/utils.h
+++ b/utils.h
@@ -269,5 +269,6 @@ const char *get_argv0_buf(void);
 	"-t|--tbytes        show sizes in TiB, or TB with --si"
 
 unsigned int get_unit_mode_from_arg(int *argc, char *argv[], int df_mode);
+int is_numerical(const char *str);
 
 #endif
-- 
2.4.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/3] btrfs-progs: Code optimize and cleanup device add
  2015-10-10 14:30 [PATCH RESEND 0/3] btrfs-progs: Introduce device delete by devid Anand Jain
  2015-10-10 14:30 ` [PATCH RESEND V2 1/3] btrfs-progs: Create is_numerical() helper function Anand Jain
@ 2015-10-10 14:30 ` Anand Jain
  2015-10-10 14:30 ` [PATCH V4 3/3] btrfs-progs: Introduce device delete by devid Anand Jain
  2015-10-13 12:48 ` [PATCH RESEND 0/3] " David Sterba
  3 siblings, 0 replies; 6+ messages in thread
From: Anand Jain @ 2015-10-10 14:30 UTC (permalink / raw)
  To: linux-btrfs; +Cc: dsterba

This is needed by the patch which introduces new devid option for the
btrfs device delete.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 cmds-device.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/cmds-device.c b/cmds-device.c
index 5f2b952..ee48c2e 100644
--- a/cmds-device.c
+++ b/cmds-device.c
@@ -51,8 +51,9 @@ static int cmd_device_add(int argc, char **argv)
 	char	*mntpnt;
 	int	i, fdmnt, ret=0, e;
 	DIR	*dirstream = NULL;
-	int discard = 1;
-	int force = 0;
+	int	discard = 1;
+	int	force = 0;
+	int	last_dev;
 
 	while (1) {
 		int c;
@@ -77,18 +78,17 @@ static int cmd_device_add(int argc, char **argv)
 		}
 	}
 
-	argc = argc - optind;
-
-	if (check_argc_min(argc, 2))
+	if (check_argc_min(argc - optind, 2))
 		usage(cmd_device_add_usage);
 
-	mntpnt = argv[optind + argc - 1];
+	last_dev = argc - 1;
+	mntpnt = argv[last_dev];
 
 	fdmnt = btrfs_open_dir(mntpnt, &dirstream, 1);
 	if (fdmnt < 0)
 		return 1;
 
-	for (i = optind; i < optind + argc - 1; i++){
+	for (i = optind; i < last_dev; i++){
 		struct btrfs_ioctl_vol_args ioctl_args;
 		int	devfd, res;
 		u64 dev_block_count = 0;
-- 
2.4.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH V4 3/3] btrfs-progs: Introduce device delete by devid
  2015-10-10 14:30 [PATCH RESEND 0/3] btrfs-progs: Introduce device delete by devid Anand Jain
  2015-10-10 14:30 ` [PATCH RESEND V2 1/3] btrfs-progs: Create is_numerical() helper function Anand Jain
  2015-10-10 14:30 ` [PATCH 2/3] btrfs-progs: Code optimize and cleanup device add Anand Jain
@ 2015-10-10 14:30 ` Anand Jain
  2015-10-13 12:48 ` [PATCH RESEND 0/3] " David Sterba
  3 siblings, 0 replies; 6+ messages in thread
From: Anand Jain @ 2015-10-10 14:30 UTC (permalink / raw)
  To: linux-btrfs; +Cc: dsterba

From: Anand Jain <Anand.Jain@oracle.com>

This patch introduces new option <devid> for the command

  btrfs device delete <device_path|devid>[..]  <mnt>

In a user reported issue on a 3-disk-RAID1, one disk failed with its SB
unreadable. Now with this patch user will have a choice to delete the
device using devid.

The other method we could do, is to match the input device_path to the
available device_paths with in the kernel. But that won't work in all the
cases, like what if user provided mapper path when the path within the
kernel is a non-mapper path.

This patch depends on the below kernel patch for the new feature to work,
however it will fail-back to the old interface for the kernel without the
patch

  Btrfs: Introduce device delete by devid

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
v4: Changelog formating update

v3: Enahnced btrfs_ioctl_vol_args_v2 to accept devid instead of creating
    a new structure. Thanks to David. Changed subject from
      btrfs-progs: device delete to accept devid

v2: Update missed Documentation for delete (not just remove) as well.
    Thanks to Goffredo.

 Documentation/btrfs-device.asciidoc |  4 ++--
 cmds-device.c                       | 46 +++++++++++++++++++++++++++++--------
 ioctl.h                             | 14 ++++++++++-
 3 files changed, 51 insertions(+), 13 deletions(-)

diff --git a/Documentation/btrfs-device.asciidoc b/Documentation/btrfs-device.asciidoc
index 2827598..bd878f4 100644
--- a/Documentation/btrfs-device.asciidoc
+++ b/Documentation/btrfs-device.asciidoc
@@ -74,10 +74,10 @@ do not perform discard by default
 -f|--force::::
 force overwrite of existing filesystem on the given disk(s)
 
-*remove* <dev> [<dev>...] <path>::
+*remove* <dev>|<devid> [<dev>|<devid>...] <path>::
 Remove device(s) from a filesystem identified by <path>.
 
-*delete* <dev> [<dev>...] <path>::
+*delete* <dev>|<devid> [<dev>|<devid>...] <path>::
 Alias of remove kept for backwards compatability
 
 *ready* <device>::
diff --git a/cmds-device.c b/cmds-device.c
index ee48c2e..bad3dbd 100644
--- a/cmds-device.c
+++ b/cmds-device.c
@@ -163,16 +163,35 @@ static int _cmd_device_remove(int argc, char **argv,
 		struct	btrfs_ioctl_vol_args arg;
 		int	res;
 
-		if (is_block_device(argv[i]) != 1) {
+		struct  btrfs_ioctl_vol_args_v2 argv2 = {0};
+		int     its_num = false;
+
+		if (is_numerical(argv[i])) {
+			argv2.devid = arg_strtou64(argv[i]);
+			argv2.flags = BTRFS_DEVICE_BY_ID;
+			its_num = true;
+		} else if (is_block_device(argv[i]) == 1) {
+			strncpy_null(argv2.name, argv[i]);
+		} else {
 			fprintf(stderr,
-				"ERROR: %s is not a block device\n", argv[i]);
+				"ERROR: %s is not a block device or devid\n", argv[i]);
 			ret++;
 			continue;
 		}
-		memset(&arg, 0, sizeof(arg));
-		strncpy_null(arg.name, argv[i]);
-		res = ioctl(fdmnt, BTRFS_IOC_RM_DEV, &arg);
+		res = ioctl(fdmnt, BTRFS_IOC_RM_DEV_V2, &argv2);
 		e = errno;
+		if (res && e == ENOTTY) {
+			if (its_num) {
+				fprintf(stderr,
+				"Error: Kernel does not support delete by devid\n");
+				ret = 1;
+				continue;
+			}
+			memset(&arg, 0, sizeof(arg));
+			strncpy_null(arg.name, argv[i]);
+			res = ioctl(fdmnt, BTRFS_IOC_RM_DEV, &arg);
+			e = errno;
+		}
 		if (res) {
 			const char *msg;
 
@@ -180,9 +199,16 @@ static int _cmd_device_remove(int argc, char **argv,
 				msg = btrfs_err_str(res);
 			else
 				msg = strerror(e);
-			fprintf(stderr,
-				"ERROR: error removing the device '%s' - %s\n",
-				argv[i], msg);
+
+			if (its_num)
+				fprintf(stderr,
+					"ERROR: error removing the devid '%llu' - %s\n",
+					argv2.devid, msg);
+			else
+				fprintf(stderr,
+					"ERROR: error removing the device '%s' - %s\n",
+					argv[i], msg);
+
 			ret++;
 		}
 	}
@@ -192,7 +218,7 @@ static int _cmd_device_remove(int argc, char **argv,
 }
 
 static const char * const cmd_device_remove_usage[] = {
-	"btrfs device remove <device> [<device>...] <path>",
+	"btrfs device remove <device>|<devid> [<device>|<devid>...] <path>",
 	"Remove a device from a filesystem",
 	NULL
 };
@@ -203,7 +229,7 @@ static int cmd_device_remove(int argc, char **argv)
 }
 
 static const char * const cmd_device_delete_usage[] = {
-	"btrfs device delete <device> [<device>...] <path>",
+	"btrfs device delete <device>|<devid> [<device>|<devid>...] <path>",
 	"Remove a device from a filesystem",
 	NULL
 };
diff --git a/ioctl.h b/ioctl.h
index dff015a..0d5dd52 100644
--- a/ioctl.h
+++ b/ioctl.h
@@ -45,6 +45,13 @@ struct btrfs_ioctl_vol_args {
 #define BTRFS_SUBVOL_CREATE_ASYNC	(1ULL << 0)
 #define BTRFS_SUBVOL_RDONLY		(1ULL << 1)
 #define BTRFS_SUBVOL_QGROUP_INHERIT	(1ULL << 2)
+#define BTRFS_DEVICE_BY_ID		(1ULL << 3)
+#define BTRFS_VOL_ARG_V2_FLAGS				\
+			(BTRFS_SUBVOL_CREATE_ASYNC |	\
+			BTRFS_SUBVOL_RDONLY |		\
+			BTRFS_SUBVOL_QGROUP_INHERIT |	\
+			BTRFS_DEVICE_BY_ID)
+
 #define BTRFS_FSID_SIZE 16
 #define BTRFS_UUID_SIZE 16
 
@@ -84,7 +91,10 @@ struct btrfs_ioctl_vol_args_v2 {
 		};
 		__u64 unused[4];
 	};
-	char name[BTRFS_SUBVOL_NAME_MAX + 1];
+	union {
+		char name[BTRFS_SUBVOL_NAME_MAX + 1];
+		u64 devid;
+	};
 };
 
 /*
@@ -683,6 +693,8 @@ static inline char *btrfs_err_str(enum btrfs_err_code err_code)
                                   struct btrfs_ioctl_feature_flags[2])
 #define BTRFS_IOC_GET_SUPPORTED_FEATURES _IOR(BTRFS_IOCTL_MAGIC, 57, \
                                   struct btrfs_ioctl_feature_flags[3])
+#define BTRFS_IOC_RM_DEV_V2	_IOW(BTRFS_IOCTL_MAGIC, 58, \
+				   struct btrfs_ioctl_vol_args_v2)
 #ifdef __cplusplus
 }
 #endif
-- 
2.4.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH RESEND 0/3] btrfs-progs: Introduce device delete by devid
  2015-10-10 14:30 [PATCH RESEND 0/3] btrfs-progs: Introduce device delete by devid Anand Jain
                   ` (2 preceding siblings ...)
  2015-10-10 14:30 ` [PATCH V4 3/3] btrfs-progs: Introduce device delete by devid Anand Jain
@ 2015-10-13 12:48 ` David Sterba
  2015-10-14 10:56   ` Anand Jain
  3 siblings, 1 reply; 6+ messages in thread
From: David Sterba @ 2015-10-13 12:48 UTC (permalink / raw)
  To: Anand Jain; +Cc: linux-btrfs, dsterba

On Sat, Oct 10, 2015 at 10:30:55PM +0800, Anand Jain wrote:
> This is the btrfs-progs part of the kernel patch
>    Btrfs: Introduce device delete by devid

Thanks, now in next/delete-by-id-v3, I made some changes so please have
a look. Notably, I've dropped the BTRFS_VOL_ARG_V2_FLAGS mask, this
belongs to kernel only (unless you need it userspace of course).

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH RESEND 0/3] btrfs-progs: Introduce device delete by devid
  2015-10-13 12:48 ` [PATCH RESEND 0/3] " David Sterba
@ 2015-10-14 10:56   ` Anand Jain
  0 siblings, 0 replies; 6+ messages in thread
From: Anand Jain @ 2015-10-14 10:56 UTC (permalink / raw)
  To: dsterba; +Cc: linux-btrfs



On 10/13/2015 08:48 PM, David Sterba wrote:
> On Sat, Oct 10, 2015 at 10:30:55PM +0800, Anand Jain wrote:
>> This is the btrfs-progs part of the kernel patch
>>     Btrfs: Introduce device delete by devid
>
> Thanks, now in next/delete-by-id-v3, I made some changes so please have
> a look. Notably, I've dropped the BTRFS_VOL_ARG_V2_FLAGS mask, this
> belongs to kernel only (unless you need it userspace of course).

  sorry that was by oversight. yep no need.

Thanks, Anand

> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2015-10-14 10:56 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-10-10 14:30 [PATCH RESEND 0/3] btrfs-progs: Introduce device delete by devid Anand Jain
2015-10-10 14:30 ` [PATCH RESEND V2 1/3] btrfs-progs: Create is_numerical() helper function Anand Jain
2015-10-10 14:30 ` [PATCH 2/3] btrfs-progs: Code optimize and cleanup device add Anand Jain
2015-10-10 14:30 ` [PATCH V4 3/3] btrfs-progs: Introduce device delete by devid Anand Jain
2015-10-13 12:48 ` [PATCH RESEND 0/3] " David Sterba
2015-10-14 10:56   ` Anand Jain

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).