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

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