Blame SOURCES/0178-libmultipath-add-rbd-discovery.patch

f20720
From 2fc494b81157059e0be66022f6a2110f1ce179c3 Mon Sep 17 00:00:00 2001
f20720
From: Mike Christie <mchristi@redhat.com>
f20720
Date: Tue, 9 Aug 2016 13:44:10 -0500
f20720
Subject: [PATCH 02/11] libmultipath: add rbd discovery
f20720
f20720
For BZ 1348372 from upstream commit:
f20720
f20720
Commit 152f3f803ee922075e8b25027eb9dc5699f1aefa
f20720
Author: Mike Christie <mchristi@redhat.com>
f20720
Date:   Mon Aug 8 07:01:47 2016 -0500
f20720
f20720
    libmultipath: add rbd discovery
f20720
f20720
    rbd is a block device interface for Ceph. It does not support
f20720
    any SCSI commands, so this patch adds bus detection and virtual
f20720
    vendor/product pathinfo.
f20720
f20720
--------
f20720
f20720
Porting notes:
f20720
f20720
get_uid() chunk does not match upstream due to rhel not having
f20720
the get uid callout code and sysfs uid detection code.
f20720
f20720
Signed-off-by: Mike Christie <mchristi@redhat.com>
f20720
---
f20720
 libmultipath/checkers.h  |   1 +
f20720
 libmultipath/discovery.c | 116 ++++++++++++++++++++++++++++++++++++++++-------
f20720
 libmultipath/structs.h   |   1 +
f20720
 3 files changed, 101 insertions(+), 17 deletions(-)
f20720
f20720
diff --git a/libmultipath/checkers.h b/libmultipath/checkers.h
f20720
index f6fe326..735bb25 100644
f20720
--- a/libmultipath/checkers.h
f20720
+++ b/libmultipath/checkers.h
f20720
@@ -75,6 +75,7 @@ enum path_check_state {
f20720
 #define EMC_CLARIION "emc_clariion"
f20720
 #define READSECTOR0  "readsector0"
f20720
 #define CCISS_TUR    "cciss_tur"
f20720
+#define RBD          "rbd"
f20720
 
f20720
 #define DEFAULT_CHECKER DIRECTIO
f20720
 
f20720
diff --git a/libmultipath/discovery.c b/libmultipath/discovery.c
f20720
index 7a8282b..1b9f390 100644
f20720
--- a/libmultipath/discovery.c
f20720
+++ b/libmultipath/discovery.c
f20720
@@ -781,6 +781,21 @@ scsi_sysfs_pathinfo (struct path * pp)
f20720
 }
f20720
 
f20720
 static int
f20720
+rbd_sysfs_pathinfo (struct path * pp)
f20720
+{
f20720
+	sprintf(pp->vendor_id, "Ceph");
f20720
+	sprintf(pp->product_id, "RBD");
f20720
+
f20720
+	condlog(3, "%s: vendor = %s product = %s", pp->dev, pp->vendor_id,
f20720
+		pp->product_id);
f20720
+	/*
f20720
+	 * set the hwe configlet pointer
f20720
+	 */
f20720
+	pp->hwe = find_hwe(conf->hwtable, pp->vendor_id, pp->product_id, NULL);
f20720
+	return 0;
f20720
+}
f20720
+
f20720
+static int
f20720
 ccw_sysfs_pathinfo (struct path * pp)
f20720
 {
f20720
 	struct udev_device *parent;
f20720
@@ -974,6 +989,8 @@ sysfs_pathinfo(struct path * pp)
f20720
 		pp->bus = SYSFS_BUS_CCW;
f20720
 	if (!strncmp(pp->dev,"sd", 2))
f20720
 		pp->bus = SYSFS_BUS_SCSI;
f20720
+	if (!strncmp(pp->dev,"rbd", 3))
f20720
+		pp->bus = SYSFS_BUS_RBD;
f20720
 
f20720
 	if (pp->bus == SYSFS_BUS_UNDEF)
f20720
 		return 0;
f20720
@@ -986,6 +1003,9 @@ sysfs_pathinfo(struct path * pp)
f20720
 	} else if (pp->bus == SYSFS_BUS_CCISS) {
f20720
 		if (cciss_sysfs_pathinfo(pp))
f20720
 			return 1;
f20720
+	} else if (pp->bus == SYSFS_BUS_RBD) {
f20720
+		if (rbd_sysfs_pathinfo(pp))
f20720
+			return 1;
f20720
 	}
f20720
 	return 0;
f20720
 }
f20720
@@ -1087,10 +1107,60 @@ get_prio (struct path * pp)
f20720
 }
f20720
 
f20720
 static int
f20720
+get_rbd_uid(struct path * pp)
f20720
+{
f20720
+	struct udev_device *rbd_bus_dev;
f20720
+	int ret, rbd_bus_id;
f20720
+	const char *pool, *image, *snap;
f20720
+	char sysfs_path[PATH_SIZE];
f20720
+	uint64_t snap_id, max_snap_id = -3;
f20720
+
f20720
+	ret = sscanf(pp->dev, "rbd%d", &rbd_bus_id);
f20720
+	if (ret != 1)
f20720
+		return -EINVAL;
f20720
+
f20720
+	snprintf(sysfs_path, sizeof(sysfs_path), "/sys/bus/rbd/devices/%d",
f20720
+		 rbd_bus_id);
f20720
+	rbd_bus_dev = udev_device_new_from_syspath(conf->udev, sysfs_path);
f20720
+	if (!rbd_bus_dev)
f20720
+		return -ENODEV;
f20720
+
f20720
+	ret = -EINVAL;
f20720
+	pool = udev_device_get_sysattr_value(rbd_bus_dev, "pool_id");
f20720
+	if (!pool)
f20720
+		goto free_dev;
f20720
+
f20720
+	image = udev_device_get_sysattr_value(rbd_bus_dev, "image_id");
f20720
+	if (!image)
f20720
+		goto free_dev;
f20720
+
f20720
+	snap = udev_device_get_sysattr_value(rbd_bus_dev, "snap_id");
f20720
+	if (!snap)
f20720
+		goto free_dev;
f20720
+	snap_id = strtoull(snap, NULL, 19);
f20720
+	if (snap_id >= max_snap_id)
f20720
+		ret = snprintf(pp->wwid, WWID_SIZE, "%s-%s", pool, image);
f20720
+	else
f20720
+		ret = snprintf(pp->wwid, WWID_SIZE, "%s-%s-%s", pool,
f20720
+			       image, snap);
f20720
+	if (ret < WWID_SIZE) {
f20720
+		ret = 0;
f20720
+	} else {
f20720
+		condlog(0, "%s: wwid overflow", pp->dev);
f20720
+		ret = -EOVERFLOW;
f20720
+	}
f20720
+
f20720
+free_dev:
f20720
+	udev_device_unref(rbd_bus_dev);	
f20720
+	return ret;
f20720
+}
f20720
+
f20720
+static int
f20720
 get_uid (struct path * pp)
f20720
 {
f20720
 	char *c;
f20720
 	const char *value;
f20720
+	int ret;
f20720
 
f20720
 	if (!pp->uid_attribute)
f20720
 		select_getuid(pp);
f20720
@@ -1101,25 +1171,37 @@ get_uid (struct path * pp)
f20720
 	}
f20720
 
f20720
 	memset(pp->wwid, 0, WWID_SIZE);
f20720
-	value = udev_device_get_property_value(pp->udev, pp->uid_attribute);
f20720
-	if ((!value || strlen(value) == 0) && conf->cmd == CMD_VALID_PATH)
f20720
-		value = getenv(pp->uid_attribute);
f20720
-	if (value && strlen(value)) {
f20720
-		size_t len = WWID_SIZE;
f20720
-
f20720
-		if (strlen(value) + 1 > WWID_SIZE) {
f20720
-			condlog(0, "%s: wwid overflow", pp->dev);
f20720
-		} else {
f20720
-			len = strlen(value);
f20720
+	if (pp->bus == SYSFS_BUS_RBD) {
f20720
+		ret = get_rbd_uid(pp);
f20720
+		if (ret) {
f20720
+			condlog(1, "%s: failed to get sysfs uid: %s",
f20720
+				pp->dev, strerror(-ret));
f20720
+			pp->missing_udev_info = INFO_MISSING;
f20720
+			pp->tick = conf->retrigger_delay;
f20720
 		}
f20720
-		strncpy(pp->wwid, value, len);
f20720
-		pp->missing_udev_info = INFO_OK;
f20720
-		pp->tick = 0;
f20720
 	} else {
f20720
-		condlog(3, "%s: no %s attribute", pp->dev,
f20720
-			pp->uid_attribute);
f20720
-		pp->missing_udev_info = INFO_MISSING;
f20720
-		pp->tick = conf->retrigger_delay;
f20720
+		value = udev_device_get_property_value(pp->udev,
f20720
+						       pp->uid_attribute);
f20720
+		if ((!value || strlen(value) == 0) &&
f20720
+		     conf->cmd == CMD_VALID_PATH)
f20720
+			value = getenv(pp->uid_attribute);
f20720
+		if (value && strlen(value)) {
f20720
+			size_t len = WWID_SIZE;
f20720
+
f20720
+			if (strlen(value) + 1 > WWID_SIZE) {
f20720
+				condlog(0, "%s: wwid overflow", pp->dev);
f20720
+			} else {
f20720
+				len = strlen(value);
f20720
+			}
f20720
+			strncpy(pp->wwid, value, len);
f20720
+			pp->missing_udev_info = INFO_OK;
f20720
+			pp->tick = 0;
f20720
+		} else {
f20720
+			condlog(3, "%s: no %s attribute", pp->dev,
f20720
+				pp->uid_attribute);
f20720
+			pp->missing_udev_info = INFO_MISSING;
f20720
+			pp->tick = conf->retrigger_delay;
f20720
+		}
f20720
 	}
f20720
 
f20720
 	/* Strip any trailing blanks */
f20720
diff --git a/libmultipath/structs.h b/libmultipath/structs.h
f20720
index b5b4567..e566462 100644
f20720
--- a/libmultipath/structs.h
f20720
+++ b/libmultipath/structs.h
f20720
@@ -52,6 +52,7 @@ enum sysfs_buses {
f20720
 	SYSFS_BUS_IDE,
f20720
 	SYSFS_BUS_CCW,
f20720
 	SYSFS_BUS_CCISS,
f20720
+	SYSFS_BUS_RBD,
f20720
 };
f20720
 
f20720
 enum pathstates {
f20720
-- 
f20720
1.8.3.1
f20720