All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anand Jain <anand.jain@oracle.com>
To: linux-btrfs@vger.kernel.org
Cc: dsterba@suse.com
Subject: [PATCH 2/2 v2] btrfs-progs: device delete to accept devid
Date: Mon, 13 Jul 2015 10:28:08 +0800	[thread overview]
Message-ID: <1436754488-10106-1-git-send-email-anand.jain@oracle.com> (raw)
In-Reply-To: <1429525756-2727-4-git-send-email-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: device delete by devid

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
v1->v2: rebase on latest devel

 Documentation/btrfs-device.asciidoc |  2 +-
 cmds-device.c                       | 43 +++++++++++++++++++++++++++++--------
 ioctl.h                             |  8 +++++++
 3 files changed, 43 insertions(+), 10 deletions(-)

diff --git a/Documentation/btrfs-device.asciidoc b/Documentation/btrfs-device.asciidoc
index 2827598..61ede6e 100644
--- a/Documentation/btrfs-device.asciidoc
+++ b/Documentation/btrfs-device.asciidoc
@@ -74,7 +74,7 @@ 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>::
diff --git a/cmds-device.c b/cmds-device.c
index 0e60500..4c9b19a 100644
--- a/cmds-device.c
+++ b/cmds-device.c
@@ -164,16 +164,34 @@ static int _cmd_rm_dev(int argc, char **argv, const char * const *usagestr)
 		struct	btrfs_ioctl_vol_args arg;
 		int	res;
 
-		if (!is_block_device(argv[i])) {
+		struct  btrfs_ioctl_vol_args_v3 argv3 = {0};
+		int     its_num = false;
+
+		if (is_numerical(argv[i])) {
+			argv3.devid = arg_strtou64(argv[i]);
+			its_num = true;
+		} else if (is_block_device(argv[i])) {
+			strncpy_null(argv3.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, &argv3);
 		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;
 
@@ -181,9 +199,16 @@ static int _cmd_rm_dev(int argc, char **argv, const char * const *usagestr)
 				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",
+					argv3.devid, msg);
+			else
+				fprintf(stderr,
+					"ERROR: error removing the device '%s' - %s\n",
+					argv[i], msg);
+
 			ret++;
 		}
 	}
@@ -193,7 +218,7 @@ static int _cmd_rm_dev(int argc, char **argv, const char * const *usagestr)
 }
 
 static const char * const cmd_rm_dev_usage[] = {
-	"btrfs device remove <device> [<device>...] <path>",
+	"btrfs device remove <device>|<devid> [<device>|<devid>...] <path>",
 	"Remove a device from a filesystem",
 	NULL
 };
diff --git a/ioctl.h b/ioctl.h
index dff015a..6870931 100644
--- a/ioctl.h
+++ b/ioctl.h
@@ -40,6 +40,12 @@ struct btrfs_ioctl_vol_args {
 	char name[BTRFS_PATH_NAME_MAX + 1];
 };
 
+struct btrfs_ioctl_vol_args_v3 {
+	__s64 fd;
+	char name[BTRFS_PATH_NAME_MAX + 1];
+	__u64 devid;
+};
+
 #define BTRFS_DEVICE_PATH_NAME_MAX 1024
 
 #define BTRFS_SUBVOL_CREATE_ASYNC	(1ULL << 0)
@@ -683,6 +689,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_v3)
 #ifdef __cplusplus
 }
 #endif
-- 
2.4.1


      reply	other threads:[~2015-07-13  3:25 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-20 10:29 [PATCH] device delete by devid Anand Jain
2015-04-20 10:29 ` [PATCH] Btrfs: " Anand Jain
2015-04-27  7:34   ` [PATCH 0/8 v2] " Anand Jain
2015-04-27  7:34     ` [PATCH V2 1/8] Btrfs: " Anand Jain
2015-04-27  7:34     ` [PATCH 2/8] Btrfs: move check for min number of devices to a function Anand Jain
2015-04-27  7:34     ` [PATCH 3/8] Btrfs: rename btrfs_dev_replace_find_srcdev() Anand Jain
2015-04-27  7:34     ` [PATCH 4/8] Btrfs: use BTRFS_ERROR_DEV_MISSING_NOT_FOUND when missing device is not found Anand Jain
2015-04-27  7:34     ` [PATCH 5/8] Btrfs: use btrfs_find_device_by_user_input() Anand Jain
2015-04-27  7:34     ` [PATCH 6/8] Btrfs: add btrfs_read_dev_one_super() to read one specific SB Anand Jain
2015-04-27  7:34     ` [PATCH 7/8] Btrfs: fix btrfs_scratch_superblock() with fixes from device delete Anand Jain
2015-04-27  7:34     ` [PATCH 8/8] Btrfs: use btrfs_scratch_superblock() in btrfs_rm_device() Anand Jain
2015-04-20 10:29 ` [PATCH 1/2] btrfs-progs: move is_numerical to utils-lib.h and make it non static Anand Jain
2015-04-20 10:29 ` [PATCH 2/2] btrfs-progs: device delete to accept devid Anand Jain
2015-07-13  2:28   ` Anand Jain [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1436754488-10106-1-git-send-email-anand.jain@oracle.com \
    --to=anand.jain@oracle.com \
    --cc=dsterba@suse.com \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.