All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ilya Dryomov <idryomov@gmail.com>
To: ceph-devel@vger.kernel.org
Subject: [PATCH 16/16] rbd: add force close option
Date: Wed, 24 Aug 2016 15:18:40 +0200	[thread overview]
Message-ID: <1472044720-29116-17-git-send-email-idryomov@gmail.com> (raw)
In-Reply-To: <1472044720-29116-1-git-send-email-idryomov@gmail.com>

From: Mike Christie <mchristi@redhat.com>

This adds a force close option, so we can force the unmapping
of a rbd device that is open. If a path/device is blacklisted, apps
like multipathd can map a new device and then unmap the old one.
The unmapping cleanup would then be handled by the generic hotunplug
code paths in multipahd like is done for iSCSI, FC/FCOE, SAS, etc.

Signed-off-by: Mike Christie <mchristi@redhat.com>
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
---
 Documentation/ABI/testing/sysfs-bus-rbd | 10 +++++++---
 drivers/block/rbd.c                     | 35 ++++++++++++++++++++++++---------
 2 files changed, 33 insertions(+), 12 deletions(-)

diff --git a/Documentation/ABI/testing/sysfs-bus-rbd b/Documentation/ABI/testing/sysfs-bus-rbd
index 6dccbf82fcf4..f208ac58d613 100644
--- a/Documentation/ABI/testing/sysfs-bus-rbd
+++ b/Documentation/ABI/testing/sysfs-bus-rbd
@@ -6,7 +6,7 @@ Description:
 
 Being used for adding and removing rbd block devices.
 
-Usage: <mon ip addr> <options> <pool name> <rbd image name> [snap name]
+Usage: <mon ip addr> <options> <pool name> <rbd image name> [<snap name>]
 
  $ echo "192.168.0.1 name=admin rbd foo" > /sys/bus/rbd/add
 
@@ -14,9 +14,13 @@ The snapshot name can be "-" or omitted to map the image read/write. A <dev-id>
 will be assigned for any registered block device. If snapshot is used, it will
 be mapped read-only.
 
-Removal of a device:
+Usage: <dev-id> [force]
 
-  $ echo <dev-id> > /sys/bus/rbd/remove
+ $ echo 2 > /sys/bus/rbd/remove
+
+Optional "force" argument which when passed will wait for running requests and
+then unmap the image. Requests sent to the driver after initiating the removal
+will be failed.  (August 2016, since 4.9.)
 
 What:		/sys/bus/rbd/add_single_major
 Date:		December 2013
diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
index 8ff2dc872008..35fc1da6c83d 100644
--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -6347,18 +6347,26 @@ static ssize_t do_rbd_remove(struct bus_type *bus,
 	struct rbd_device *rbd_dev = NULL;
 	struct list_head *tmp;
 	int dev_id;
-	unsigned long ul;
+	char opt_buf[6];
 	bool already = false;
+	bool force = false;
 	int ret;
 
-	ret = kstrtoul(buf, 10, &ul);
-	if (ret)
-		return ret;
-
-	/* convert to int; abort if we lost anything in the conversion */
-	dev_id = (int)ul;
-	if (dev_id != ul)
+	dev_id = -1;
+	opt_buf[0] = '\0';
+	sscanf(buf, "%d %5s", &dev_id, opt_buf);
+	if (dev_id < 0) {
+		pr_err("dev_id out of range\n");
 		return -EINVAL;
+	}
+	if (opt_buf[0] != '\0') {
+		if (!strcmp(opt_buf, "force")) {
+			force = true;
+		} else {
+			pr_err("bad remove option at '%s'\n", opt_buf);
+			return -EINVAL;
+		}
+	}
 
 	ret = -ENOENT;
 	spin_lock(&rbd_dev_list_lock);
@@ -6371,7 +6379,7 @@ static ssize_t do_rbd_remove(struct bus_type *bus,
 	}
 	if (!ret) {
 		spin_lock_irq(&rbd_dev->lock);
-		if (rbd_dev->open_count)
+		if (rbd_dev->open_count && !force)
 			ret = -EBUSY;
 		else
 			already = test_and_set_bit(RBD_DEV_FLAG_REMOVING,
@@ -6382,6 +6390,15 @@ static ssize_t do_rbd_remove(struct bus_type *bus,
 	if (ret < 0 || already)
 		return ret;
 
+	if (force) {
+		/*
+		 * Prevent new IO from being queued and wait for existing
+		 * IO to complete/fail.
+		 */
+		blk_mq_freeze_queue(rbd_dev->disk->queue);
+		blk_set_queue_dying(rbd_dev->disk->queue);
+	}
+
 	down_write(&rbd_dev->lock_rwsem);
 	if (__rbd_is_lock_owner(rbd_dev))
 		rbd_unlock(rbd_dev);
-- 
2.4.3


  parent reply	other threads:[~2016-08-24 13:19 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-24 13:18 [PATCH 00/16] rbd: support for exclusive-lock + mpath remap bits Ilya Dryomov
2016-08-24 13:18 ` [PATCH 01/16] libceph: rename ceph_entity_name_encode() -> ceph_auth_entity_name_encode() Ilya Dryomov
2016-08-24 18:49   ` Alex Elder
2016-08-24 20:15     ` Ilya Dryomov
2016-08-24 13:18 ` [PATCH 02/16] libceph: support for CEPH_OSD_OP_LIST_WATCHERS Ilya Dryomov
2016-08-24 19:29   ` Alex Elder
2016-08-24 20:43     ` Ilya Dryomov
2016-08-24 13:18 ` [PATCH 03/16] libceph: add ceph_osdc_call() single-page helper Ilya Dryomov
2016-08-24 19:37   ` Alex Elder
2016-08-24 13:18 ` [PATCH 04/16] libceph: support for advisory locking on RADOS objects Ilya Dryomov
2016-08-24 19:42   ` Alex Elder
2016-08-24 20:49     ` Ilya Dryomov
2016-08-24 13:18 ` [PATCH 05/16] libceph: support for lock.lock_info Ilya Dryomov
2016-08-24 19:56   ` Alex Elder
2016-08-24 13:18 ` [PATCH 06/16] libceph: support for blacklisting clients Ilya Dryomov
2016-08-24 19:59   ` Alex Elder
2016-08-24 13:18 ` [PATCH 07/16] libceph: rename ceph_client_id() -> ceph_client_gid() Ilya Dryomov
2016-08-24 20:00   ` Alex Elder
2016-08-24 20:56     ` Ilya Dryomov
2016-08-24 13:18 ` [PATCH 08/16] rbd: introduce a per-device ordered workqueue Ilya Dryomov
2016-08-24 13:18 ` [PATCH 09/16] rbd: retry watch re-registration periodically Ilya Dryomov
2016-08-24 13:18 ` [PATCH 10/16] rbd: support for exclusive-lock feature Ilya Dryomov
2016-08-24 13:18 ` [PATCH 11/16] rbd: print capacity in decimal and features in hex Ilya Dryomov
2016-08-24 13:18 ` [PATCH 12/16] rbd: add 'client_addr' sysfs rbd device attribute Ilya Dryomov
2016-08-24 13:18 ` [PATCH 13/16] rbd: add 'cluster_fsid' " Ilya Dryomov
2016-08-24 13:18 ` [PATCH 14/16] rbd: add 'snap_id' " Ilya Dryomov
2016-08-24 13:18 ` [PATCH 15/16] rbd: add 'config_info' " Ilya Dryomov
2016-08-24 13:18 ` Ilya Dryomov [this message]
2016-08-24 18:34 ` [PATCH 00/16] rbd: support for exclusive-lock + mpath remap bits Mike Christie

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=1472044720-29116-17-git-send-email-idryomov@gmail.com \
    --to=idryomov@gmail.com \
    --cc=ceph-devel@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.