Skip to contentSkip to conversation

multipath-tools: Ceph rbd support

PATCH In review Mike Christie 2 participants 7 messages Jul 5, 2016 – Jul 8, 2016 Device mapper

lore
Share & tools
lore
#0 lore raw

cover multipath-tools: Ceph rbd support

The following patches add Ceph rbd support for handling blacklisted devices. This does not support features like multibus.

My specific use is for exporting rbd images through multiple LIO instances. In this case, we have one rbd instance that has the exclusive lock and send WRITE requests. If that host becomes unreachable, then another host will grab the lock, and blacklist the original host to prevent it from sending stale IO (when blacklisted IO will be failed by the OSD).

To recover from this, this patchset adds a repair() callout to the checker. If the path is in the PATH_DOWN state this callout can be used to fix it up. For my case, I am remapping the device to flush stale IO and cleanup the old lock, and then unblacklisting myself.

#1 lore raw

PATCH 1/4 multipath-tools: add rbd discovery detection

rbd is a block device interface for Ceph. It does not support any SCSI commands, so this patch adds bus detection and virtual vendor/product pathinfo.

---
 libmultipath/checkers.h  |  1 +
 libmultipath/discovery.c | 22 ++++++++++++++++++++++
 libmultipath/structs.h   |  1 +
 3 files changed, 24 insertions(+)
libmultipath/checkers.h +1 -0
index a935b3f..ea59c94 100644
@@ -84,6 +84,7 @@ enum path_check_state {
 #define EMC_CLARIION "emc_clariion"
 #define READSECTOR0  "readsector0"
 #define CCISS_TUR    "cciss_tur"
+#define RBD          "rbd"
 
 #define DEFAULT_CHECKER DIRECTIO
 
libmultipath/discovery.c +22 -0
index 126a54f..31bb02d 100644
@@ -1136,6 +1136,23 @@ scsi_sysfs_pathinfo (struct path * pp)
 }
 
 static int
+rbd_sysfs_pathinfo (struct path * pp)
+{
+	sprintf(pp->vendor_id, "Ceph");
+	sprintf(pp->product_id, "RBD");
+
+	condlog(3, "%s: vendor = %s product = %s", pp->dev, pp->vendor_id,
+		pp->product_id);
+	/*
+	 * set the hwe configlet pointer
+	 */
+	pp->hwe = find_hwe(conf->hwtable, pp->vendor_id, pp->product_id, NULL);
+
+	/* should we fake host / bus / target / lun so print looks nice */
+	return 0;
+}
+
+static int
 ccw_sysfs_pathinfo (struct path * pp)
 {
 	struct udev_device *parent;
@@ -1337,6 +1354,8 @@ sysfs_pathinfo(struct path * pp)
 		pp->bus = SYSFS_BUS_CCW;
 	if (!strncmp(pp->dev,"sd", 2))
 		pp->bus = SYSFS_BUS_SCSI;
+	if (!strncmp(pp->dev,"rbd", 3))
+		pp->bus = SYSFS_BUS_RBD;
 
 	if (pp->bus == SYSFS_BUS_UNDEF)
 		return 0;
@@ -1349,6 +1368,9 @@ sysfs_pathinfo(struct path * pp)
 	} else if (pp->bus == SYSFS_BUS_CCISS) {
 		if (cciss_sysfs_pathinfo(pp))
 			return 1;
+	} else if (pp->bus == SYSFS_BUS_RBD) {
+		if (rbd_sysfs_pathinfo(pp))
+			return 1;
 	}
 	return 0;
 }
libmultipath/structs.h +1 -0
index ab7dc25..84e56dc 100644
@@ -52,6 +52,7 @@ enum sysfs_buses {
 	SYSFS_BUS_IDE,
 	SYSFS_BUS_CCW,
 	SYSFS_BUS_CCISS,
+	SYSFS_BUS_RBD,
 };
 
 enum pathstates {
Signature · 1 line
2.5.5
#2 lore raw

PATCH 2/4 multipath-tools: add checker callout to repair path

In reply to Mike Christie

This patch adds a callback which can be used to repair a path if check() has determined it is in the PATH_DOWN state.

The next patch that adds rbd checker support which will use this to handle the case where a rbd device is blacklisted.

---
 libmultipath/checkers.c              | 23 +++++++++++++++++++++++
 libmultipath/checkers.h              |  4 ++++
 libmultipath/checkers/cciss_tur.c    |  5 +++++
 libmultipath/checkers/directio.c     |  5 +++++
 libmultipath/checkers/emc_clariion.c |  5 +++++
 libmultipath/checkers/hp_sw.c        |  5 +++++
 libmultipath/checkers/rdac.c         |  5 +++++
 libmultipath/checkers/readsector0.c  |  5 +++++
 libmultipath/checkers/tur.c          |  5 +++++
 multipathd/main.c                    | 14 +++++++++++++-
 10 files changed, 75 insertions(+), 1 deletion(-)
libmultipath/checkers.c +23 -0
index ef1d099..de6a973 100644
@@ -139,6 +139,14 @@ struct checker * add_checker (char * name)
 	if (!c->free)
 		goto out;
 
+	c->repair = (void (*)(struct checker *)) dlsym(c->handle,
+						       "libcheck_repair");
+	errstr = dlerror();
+	if (errstr != NULL)
+		condlog(0, "A dynamic linking error occurred: (%s)", errstr);
+	if (!c->repair)
+		goto out;
+
 	c->fd = 0;
 	c->sync = 1;
 	list_add(&c->node, &checkers);
@@ -204,6 +212,20 @@ void checker_put (struct checker * dst)
 	free_checker(src);
 }
 
+void checker_repair (struct checker * c)
+{
+	if (!c)
+		return;
+
+	c->message[0] = '\0';
+	if (c->disable) {
+		MSG(c, "checker disabled");
+		return;
+	}
+
+	c->repair(c);
+}
+
 int checker_check (struct checker * c)
 {
 	int r;
@@ -268,6 +290,7 @@ void checker_get (struct checker * dst, char * name)
 	dst->sync = src->sync;
 	strncpy(dst->name, src->name, CHECKER_NAME_LEN);
 	strncpy(dst->message, src->message, CHECKER_MSG_LEN);
+	dst->repair = src->repair;
 	dst->check = src->check;
 	dst->init = src->init;
 	dst->free = src->free;
libmultipath/checkers.h +4 -0
index ea59c94..d665736 100644
@@ -113,6 +113,9 @@ struct checker {
 						multipath-wide. Use MALLOC if
 						you want to stuff data in. */
 	int (*check)(struct checker *);
+	void (*repair)(struct checker *);     /* called if check returns
+					        PATH_DOWN to bring path into
+						usable state */
 	int (*init)(struct checker *);       /* to allocate the context */
 	void (*free)(struct checker *);      /* to free the context */
 };
@@ -132,6 +135,7 @@ void checker_set_async (struct checker *);
 void checker_set_fd (struct checker *, int);
 void checker_enable (struct checker *);
 void checker_disable (struct checker *);
+void checker_repair (struct checker *);
 int checker_check (struct checker *);
 int checker_selected (struct checker *);
 char * checker_name (struct checker *);
libmultipath/checkers/cciss_tur.c +5 -0
index 4c26901..7e4eb81 100644
@@ -63,6 +63,11 @@ void libcheck_free (struct checker * c)
 	return;
 }
 
+void libcheck_repair (struct checker * c)
+{
+	return;
+}
+
 extern int
 libcheck_check (struct checker * c)
 {
libmultipath/checkers/directio.c +5 -0
index 94bf8f7..eec12d5 100644
@@ -118,6 +118,11 @@ void libcheck_free (struct checker * c)
 	free(ct);
 }
 
+void libcheck_repair (struct checker * c)
+{
+	return;
+}
+
 static int
 check_state(int fd, struct directio_context *ct, int sync, int timeout_secs)
 {
libmultipath/checkers/emc_clariion.c +5 -0
index a797734..53db066 100644
@@ -91,6 +91,11 @@ void libcheck_free (struct checker * c)
 	free(c->context);
 }
 
+void libcheck_repair (struct checker * c)
+{
+	return;
+}
+
 int libcheck_check (struct checker * c)
 {
 	unsigned char sense_buffer[128] = { 0, };
libmultipath/checkers/hp_sw.c +5 -0
index fe5e0f9..0cc1111 100644
@@ -44,6 +44,11 @@ void libcheck_free (struct checker * c)
 	return;
 }
 
+void libcheck_repair (struct checker * c)
+{
+	return;
+}
+
 static int
 do_inq(int sg_fd, int cmddt, int evpd, unsigned int pg_op,
        void *resp, int mx_resp_len, int noisy, unsigned int timeout)
libmultipath/checkers/rdac.c +5 -0
index 00e3c44..68682c8 100644
@@ -139,6 +139,11 @@ void libcheck_free (struct checker * c)
 	return;
 }
 
+void libcheck_repair (struct checker * c)
+{
+	return;
+}
+
 static int
 do_inq(int sg_fd, unsigned int pg_op, void *resp, int mx_resp_len,
        unsigned int timeout)
libmultipath/checkers/readsector0.c +5 -0
index 0550fb6..b3ed1f3 100644
@@ -23,6 +23,11 @@ void libcheck_free (struct checker * c)
 	return;
 }
 
+void libcheck_repair (struct checker * c)
+{
+	return;
+}
+
 int libcheck_check (struct checker * c)
 {
 	unsigned char buf[4096];
libmultipath/checkers/tur.c +5 -0
index 2edc8ad..338d4a3 100644
@@ -97,6 +97,11 @@ void libcheck_free (struct checker * c)
 	return;
 }
 
+void libcheck_repair (struct checker * c)
+{
+	return;
+}
+
 #define TUR_MSG(msg, fmt, args...) snprintf(msg, CHECKER_MSG_LEN, fmt, ##args);
 
 int
multipathd/main.c +13 -1
index c0ca571..14728d5 100644
@@ -1635,6 +1635,14 @@ check_path (struct vectors * vecs, struct path * pp, int ticks)
 	return 1;
 }
 
+void repair_path(struct vectors * vecs, struct path * pp)
+{
+	if (pp->state != PATH_DOWN)
+		return;
+
+	checker_repair(&pp->checker);
+}
+
 static void *
 checkerloop (void *ap)
 {
@@ -1665,6 +1673,7 @@ checkerloop (void *ap)
 	while (1) {
 		struct timeval diff_time, start_time, end_time;
 		int num_paths = 0, ticks = 0, signo, strict_timing, rc = 0;
+		int checked;
 		sigset_t mask;
 
 		if (gettimeofday(&start_time, NULL) != 0)
@@ -1695,7 +1704,10 @@ checkerloop (void *ap)
 			lock(vecs->lock);
 			pthread_testcancel();
 			vector_foreach_slot (vecs->pathvec, pp, i) {
-				num_paths += check_path(vecs, pp, ticks);
+				checked = check_path(vecs, pp, ticks);
+				if (checked)
+					repair_path(vecs, pp);
+				num_paths += checked;
 			}
 			lock_cleanup_pop(vecs->lock);
 		}
Signature · 1 line
2.5.5
#3 lore raw

PATCH 3/4 multipath-tools: Add rbd checker.

In reply to Mike Christie

This checker currently only handles the case where a path is failed due to it being blacklisted by the ceph cluster. The specific use case for me is when LIO exports rbd images through multiple LIO instances.

The problem it handles is when rbd instance1 has the exclusive lock, but becomes unreachable. Another host in the cluster will take over and blacklist the instance1. This prevents it from sending stale IO and corrupting date.

Later, when the host is reachable, we will want to failback to it. To this, the checker will detect we were blacklisted, unmap the old image which will make sure old IO is failed, and then remap the image and unblacklist the host. multipathd will then handle this like a path being removed and re-added.

---
 libmultipath/checkers/Makefile |   6 +-
 libmultipath/checkers/rbd.c    | 612 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 617 insertions(+), 1 deletion(-)
 create mode 100644 libmultipath/checkers/rbd.c
libmultipath/checkers/Makefile +5 -1
index 4b1a108..1538eb8 100644
@@ -11,12 +11,16 @@ LIBS= \
 	libcheckdirectio.so \
 	libcheckemc_clariion.so \
 	libcheckhp_sw.so \
-	libcheckrdac.so
+	libcheckrdac.so \
+	libcheckrbd.so
 
 CFLAGS += -I..
 
 all: $(LIBS)
 
+libcheckrbd.so: rbd.o
+	$(CC) $(LDFLAGS) $(SHARED_FLAGS) -o $@ $^ -lrados -ludev
+
 libcheckdirectio.so: libsg.o directio.o
 	$(CC) $(LDFLAGS) $(SHARED_FLAGS) -o $@ $^ -laio
 
libmultipath/checkers/rbd.c new file +612 -0

612 lines not on this page · raw message

Signature · 1 line
2.5.5
#4 lore raw

PATCH 4/4 multipath-tools: Add rbd to the hwtable

In reply to Mike Christie

Add rbd to hwtable. These defaults are for the HA type of setup supported by the checker. We do no support features like multibus at the dm-multipath level yet.

---
 libmultipath/hwtable.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
libmultipath/hwtable.c +15 -0
index 6116124..27a6ff1 100644
@@ -1206,6 +1206,21 @@ static struct hwentry default_hw[] = {
 		.pgfailback    = 30,
 		.minio         = 128,
 	},
+	{
+		.vendor        = "Ceph",
+		.product       = "RBD",
+		.features      = DEFAULT_FEATURES,
+		.hwhandler     = DEFAULT_HWHANDLER,
+		.pgpolicy      = FAILOVER,
+		.pgfailback    = -FAILBACK_IMMEDIATE,
+		.no_path_retry = NO_PATH_RETRY_FAIL,
+		.checker_name  = RBD,
+		.user_friendly_names = USER_FRIENDLY_NAMES_ON,
+		.uid_attribute = "ID_UID",
+		.prio_name     = PRIO_CONST,
+		.deferred_remove = DEFERRED_REMOVE_ON,
+	},
+
 	/*
 	 * EOL
 	 */
Signature · 1 line
2.5.5
#5 lore raw
In reply to Mike Christie

Hi Mike,

this patchset was broken by the resync with hannes rcu v2 branch. Can you rebase it in the light of the changes to the conf pointer access applied in dbd9ad6f0e555707335ec71e1c5bec1723e02f79 ?

Thanks.

Quoted 19 lines · Mike Christie

The following patches add Ceph rbd support for handling blacklisted devices. This does not support features like multibus.

My specific use is for exporting rbd images through multiple LIO instances. In this case, we have one rbd instance that has the exclusive lock and send WRITE requests. If that host becomes unreachable, then another host will grab the lock, and blacklist the original host to prevent it from sending stale IO (when blacklisted IO will be failed by the OSD).

To recover from this, this patchset adds a repair() callout to the checker. If the path is in the PATH_DOWN state this callout can be used to fix it up. For my case, I am remapping the device to flush stale IO and cleanup the old lock, and then unblacklisting myself.

#6 lore raw
Quoted 6 lines · Christophe Varoqui

Hi Mike,

this patchset was broken by the resync with hannes rcu v2 branch. Can you rebase it in the light of the changes to the conf pointer access applied in dbd9ad6f0e555707335ec71e1c5bec1723e02f79 ?

Yeah, no problem.

Quoted 31 lines

Thanks.

On Tue, Jul 5, 2016 at 10:12 AM, Mike Christie <[email protected] <mailto:[email protected]>> wrote:

The following patches add Ceph rbd support for handling blacklisted devices. This does not support features like multibus.

My specific use is for exporting rbd images through multiple LIO instances. In this case, we have one rbd instance that has the exclusive lock and send WRITE requests. If that host becomes unreachable, then another host will grab the lock, and blacklist the original host to prevent it from sending stale IO (when blacklisted IO will be failed by the OSD).

To recover from this, this patchset adds a repair() callout to the checker. If the path is in the PATH_DOWN state this callout can be used to fix it up. For my case, I am remapping the device to flush stale IO and cleanup the old lock, and then unblacklisting myself.

--
dm-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/dm-devel