Blame SOURCES/0253-RHBZ-1618549-mix-hw-handler.patch

a385ba
---
a385ba
 libmultipath/configure.c |    2 -
a385ba
 libmultipath/propsel.c   |   58 +++++++++++++++++++++++++++++++++++++++++++++++
a385ba
 2 files changed, 59 insertions(+), 1 deletion(-)
a385ba
a385ba
Index: multipath-tools-130222/libmultipath/configure.c
a385ba
===================================================================
a385ba
--- multipath-tools-130222.orig/libmultipath/configure.c
a385ba
+++ multipath-tools-130222/libmultipath/configure.c
a385ba
@@ -282,6 +282,7 @@ setup_map (struct multipath * mpp, char
a385ba
 	select_pgpolicy(mpp);
a385ba
 	select_selector(mpp);
a385ba
 	select_features(mpp);
a385ba
+	select_retain_hwhandler(mpp);
a385ba
 	select_hwhandler(mpp);
a385ba
 	select_rr_weight(mpp);
a385ba
 	select_minio(mpp);
a385ba
@@ -293,7 +294,6 @@ setup_map (struct multipath * mpp, char
a385ba
 	select_fast_io_fail(mpp);
a385ba
 	select_dev_loss(mpp);
a385ba
 	select_reservation_key(mpp);
a385ba
-	select_retain_hwhandler(mpp);
a385ba
 	select_deferred_remove(mpp);
a385ba
 	select_delay_watch_checks(mpp);
a385ba
 	select_delay_wait_checks(mpp);
a385ba
Index: multipath-tools-130222/libmultipath/propsel.c
a385ba
===================================================================
a385ba
--- multipath-tools-130222.orig/libmultipath/propsel.c
a385ba
+++ multipath-tools-130222/libmultipath/propsel.c
a385ba
@@ -19,6 +19,8 @@
a385ba
 #include "discovery.h"
a385ba
 #include "prioritizers/alua_rtpg.h"
a385ba
 #include "prkey.h"
a385ba
+#include "sysfs.h"
a385ba
+#include "util.h"
a385ba
 #include <inttypes.h>
a385ba
 #include <libudev.h>
a385ba
 #include <mpath_persist.h>
a385ba
@@ -317,9 +319,65 @@ select_features (struct multipath * mp)
a385ba
 	return 0;
a385ba
 }
a385ba
 
a385ba
+static int get_dh_state(struct path *pp, char *value, size_t value_len)
a385ba
+{
a385ba
+	int ret;
a385ba
+	struct udev_device *ud;
a385ba
+
a385ba
+	if (pp->udev == NULL)
a385ba
+		return -1;
a385ba
+
a385ba
+	ud = udev_device_get_parent_with_subsystem_devtype(pp->udev, "scsi",
a385ba
+							   "scsi_device");
a385ba
+	if (ud == NULL)
a385ba
+		return -1;
a385ba
+
a385ba
+	ret = sysfs_attr_get_value(ud, "dh_state", value, value_len);
a385ba
+	if (ret > 0)
a385ba
+		strchop(value);
a385ba
+	return ret;
a385ba
+}
a385ba
+
a385ba
+static int
a385ba
+use_attached_hwhandler(struct multipath * mp)
a385ba
+{
a385ba
+	int i;
a385ba
+	struct path *pp;
a385ba
+	int attached_hwhandler = 0;
a385ba
+	/* dh_state is no longer than "detached" */
a385ba
+	char dh_state[10];
a385ba
+
a385ba
+	vector_foreach_slot (mp->paths, pp, i) {
a385ba
+		if (get_dh_state(pp, dh_state, sizeof(dh_state)) > 0 &&
a385ba
+		    strcmp(dh_state, "detached") != 0) {
a385ba
+			if (!attached_hwhandler) {
a385ba
+				if (asprintf(&mp->hwhandler, "1 %s",
a385ba
+					     dh_state) < 0)
a385ba
+					return 0;
a385ba
+				attached_hwhandler = 1;
a385ba
+			/* if we find 2 different hardware handlers, disable
a385ba
+			 * retain_attached_hw_handler, and use the configured
a385ba
+			 * handler */
a385ba
+			} else if (strcmp(dh_state, &mp->hwhandler[2]) != 0) {
a385ba
+				FREE(mp->hwhandler);
a385ba
+				mp->hwhandler = NULL;
a385ba
+				mp->retain_hwhandler = RETAIN_HWHANDLER_OFF;
a385ba
+				condlog(0, "%s: retain_attached_hw_hander disabled (inconsistent handlers on paths)", mp->alias);
a385ba
+				return 0;
a385ba
+			}
a385ba
+		}
a385ba
+	}
a385ba
+	return attached_hwhandler;
a385ba
+}
a385ba
+
a385ba
 extern int
a385ba
 select_hwhandler (struct multipath * mp)
a385ba
 {
a385ba
+	if (mp->retain_hwhandler == RETAIN_HWHANDLER_ON &&
a385ba
+	    use_attached_hwhandler(mp)) {
a385ba
+		condlog(3, "%s: hwhandler = %s (setting: retained by kernel driver)", mp->alias, mp->hwhandler);
a385ba
+		return 0;
a385ba
+	}
a385ba
 	if (mp->hwe && mp->hwe->hwhandler) {
a385ba
 		mp->hwhandler = mp->hwe->hwhandler;
a385ba
 		condlog(3, "%s: hwhandler = %s (controller setting)",