linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Anand Jain <anand.jain@oracle.com>
To: linux-btrfs@vger.kernel.org
Cc: dsterba@suse.cz, m_btrfs@ml1.co.uk
Subject: [PATCH 2/2] btrfs-progs: device delete to accept devid
Date: Mon, 20 Apr 2015 18:29:16 +0800	[thread overview]
Message-ID: <1429525756-2727-4-git-send-email-anand.jain@oracle.com> (raw)
In-Reply-To: <1429525756-2727-1-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>
---
 Documentation/btrfs-device.txt |  2 +-
 cmds-device.c                  | 47 ++++++++++++++++++++++++++++++++----------
 ioctl.h                        |  8 +++++++
 3 files changed, 45 insertions(+), 12 deletions(-)

diff --git a/Documentation/btrfs-device.txt b/Documentation/btrfs-device.txt
index 66be6b3..4bb5ea5 100644
--- a/Documentation/btrfs-device.txt
+++ b/Documentation/btrfs-device.txt
@@ -74,7 +74,7 @@ do not perform discard by default
 -f|--force::::
 force overwrite of existing filesystem on the given disk(s)
 
-*delete* <dev> [<dev>...] <path>::
+*delete* <dev>|<devid> [<dev>|<devid>...] <path>::
 Remove device(s) from a filesystem identified by <path>.
 
 *ready* <device>::
diff --git a/cmds-device.c b/cmds-device.c
index 1c32771..69e79d4 100644
--- a/cmds-device.c
+++ b/cmds-device.c
@@ -145,7 +145,7 @@ error_out:
 }
 
 static const char * const cmd_rm_dev_usage[] = {
-	"btrfs device delete <device> [<device>...] <path>",
+	"btrfs device delete <device>|<devid> [<device>|<devid>...] <path>",
 	"Remove a device from a filesystem",
 	NULL
 };
@@ -169,26 +169,51 @@ static int cmd_rm_dev(int argc, char **argv)
 
 	for(i=1 ; i < argc - 1; i++ ){
 		struct	btrfs_ioctl_vol_args arg;
+		struct	btrfs_ioctl_vol_args_v3 argv3 = {0};
 		int	res;
+		int 	its_num = false;
 
-		if (!is_block_device(argv[i])) {
+		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;
 		}
-		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");
+				continue;
+			}
+			strncpy_null(arg.name, argv[i]);
+			res = ioctl(fdmnt, BTRFS_IOC_RM_DEV, &arg);
+			e = errno;
+		}
 		if (res > 0) {
-			fprintf(stderr,
-				"ERROR: error removing the device '%s' - %s\n",
-				argv[i], btrfs_err_str(res));
+			if (its_num)
+				fprintf(stderr,
+					"ERROR: removing the devid '%llu' - %s\n",
+					argv3.devid, btrfs_err_str(res));
+			else
+				fprintf(stderr,
+					"ERROR: removing the device '%s' - %s\n",
+					argv[i], btrfs_err_str(res));
 			ret++;
 		} else if (res < 0) {
-			fprintf(stderr,
-				"ERROR: ioctl error removing the device '%s' - %s\n",
-				argv[i], strerror(e));
+			if (its_num)
+				fprintf(stderr,
+					"ERROR: ioctl removing the devid '%llu' - %s\n",
+					argv3.devid, strerror(e));
+			else
+				fprintf(stderr,
+					"ERROR: ioctl removing the device '%s' - %s\n",
+					argv[i], strerror(e));
 			ret++;
 		}
 	}
diff --git a/ioctl.h b/ioctl.h
index d550ca6..4354c37 100644
--- a/ioctl.h
+++ b/ioctl.h
@@ -37,6 +37,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)
@@ -621,6 +627,8 @@ struct btrfs_ioctl_clone_range_args {
                                   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.0.0.153.g79dcccc


  parent reply	other threads:[~2015-04-20  8:19 UTC|newest]

Thread overview: 21+ 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 ` Anand Jain [this message]
2015-07-13  2:28   ` [PATCH 2/2 v2] btrfs-progs: device delete to accept devid Anand Jain
  -- strict thread matches above, loose matches on Subject: below --
2015-08-14 10:36 [PATCH 0/2] Btrfs-progs: " Anand Jain
2015-08-14 10:36 ` [PATCH 2/2] btrfs-progs: " Anand Jain
2015-08-17  7:00   ` Goffredo Baroncelli
2015-08-17 11:17     ` Anand Jain
2015-08-20 11:29   ` Goffredo Baroncelli
2015-08-28 14:17     ` Anand Jain
2015-08-28 16:56       ` Goffredo Baroncelli
2015-08-28 16:57       ` Goffredo Baroncelli

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=1429525756-2727-4-git-send-email-anand.jain@oracle.com \
    --to=anand.jain@oracle.com \
    --cc=dsterba@suse.cz \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=m_btrfs@ml1.co.uk \
    /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 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).