Blame SOURCES/0232-RHBZ-1456955-property-blacklist.patch

4ae388
---
4ae388
 libmultipath/blacklist.c   |   79 +++++++++++++++++++++++++++++++++++++++++----
4ae388
 libmultipath/blacklist.h   |    5 ++
4ae388
 libmultipath/config.c      |   20 ++++++++++-
4ae388
 libmultipath/config.h      |    2 +
4ae388
 libmultipath/configure.c   |    8 ++++
4ae388
 libmultipath/dict.c        |   38 ++++++++++++++++++++-
4ae388
 libmultipath/discovery.c   |    2 +
4ae388
 libmultipath/print.c       |   31 +++++++++++++++++
4ae388
 multipath/multipath.conf.5 |   27 ++++++++++++++-
4ae388
 9 files changed, 200 insertions(+), 12 deletions(-)
4ae388
4ae388
Index: multipath-tools-130222/libmultipath/blacklist.c
4ae388
===================================================================
4ae388
--- multipath-tools-130222.orig/libmultipath/blacklist.c
4ae388
+++ multipath-tools-130222/libmultipath/blacklist.c
4ae388
@@ -2,6 +2,7 @@
4ae388
  * Copyright (c) 2004, 2005 Christophe Varoqui
4ae388
  */
4ae388
 #include <stdio.h>
4ae388
+#include <libudev.h>
4ae388
 
4ae388
 #include "checkers.h"
4ae388
 #include "memory.h"
4ae388
@@ -102,7 +103,7 @@ set_ble_device (vector blist, char * ven
4ae388
 }
4ae388
 
4ae388
 int
4ae388
-_blacklist_exceptions (vector elist, char * str)
4ae388
+_blacklist_exceptions (vector elist, const char * str)
4ae388
 {
4ae388
 	int i;
4ae388
 	struct blentry * ele;
4ae388
@@ -115,7 +116,7 @@ _blacklist_exceptions (vector elist, cha
4ae388
 }
4ae388
 
4ae388
 int
4ae388
-_blacklist (vector blist, char * str)
4ae388
+_blacklist (vector blist, const char * str)
4ae388
 {
4ae388
 	int i;
4ae388
 	struct blentry * ble;
4ae388
@@ -208,11 +209,14 @@ setup_default_blist (struct config * con
4ae388
 		condlog(3, "%s: (%s:%s) %s", dev, vendor, product, (M)); \
4ae388
 	else if (wwid)							 \
4ae388
 		condlog(3, "%s: (%s) %s", dev, wwid, (M));		 \
4ae388
+	else if (env)							 \
4ae388
+		condlog(3, "%s: (%s) %s", dev, env, (M));		 \
4ae388
 	else								 \
4ae388
 		condlog(3, "%s: %s", dev, (M))
4ae388
 
4ae388
 void
4ae388
-log_filter (char *dev, char *vendor, char *product, char *wwid, int r)
4ae388
+log_filter (const char *dev, char *vendor, char *product, char *wwid,
4ae388
+	    const char *env, int r)
4ae388
 {
4ae388
 	/*
4ae388
 	 * Try to sort from most likely to least.
4ae388
@@ -229,6 +233,9 @@ log_filter (char *dev, char *vendor, cha
4ae388
 	case MATCH_DEVNODE_BLIST:
4ae388
 		LOG_BLIST("device node name blacklisted");
4ae388
 		break;
4ae388
+	case MATCH_PROPERTY_BLIST:
4ae388
+		LOG_BLIST("udev property blacklisted");
4ae388
+		break;
4ae388
 	case MATCH_DEVICE_BLIST_EXCEPT:
4ae388
 		LOG_BLIST("vendor/product whitelisted");
4ae388
 		break;
4ae388
@@ -238,6 +245,12 @@ log_filter (char *dev, char *vendor, cha
4ae388
 	case MATCH_DEVNODE_BLIST_EXCEPT:
4ae388
 		LOG_BLIST("device node name whitelisted");
4ae388
 		break;
4ae388
+	case MATCH_PROPERTY_BLIST_EXCEPT:
4ae388
+		LOG_BLIST("udev property whitelisted");
4ae388
+		break;
4ae388
+	case MATCH_PROPERTY_BLIST_MISSING:
4ae388
+		LOG_BLIST("blacklisted, udev property missing");
4ae388
+		break;
4ae388
 	}
4ae388
 }
4ae388
 
4ae388
@@ -257,7 +270,7 @@ int
4ae388
 filter_device (vector blist, vector elist, char * vendor, char * product)
4ae388
 {
4ae388
 	int r = _filter_device(blist, elist, vendor, product);
4ae388
-	log_filter(NULL, vendor, product, NULL, r);
4ae388
+	log_filter(NULL, vendor, product, NULL, NULL, r);
4ae388
 	return r;
4ae388
 }
4ae388
 
4ae388
@@ -277,7 +290,7 @@ int
4ae388
 filter_devnode (vector blist, vector elist, char * dev)
4ae388
 {
4ae388
 	int r = _filter_devnode(blist, elist, dev);
4ae388
-	log_filter(dev, NULL, NULL, NULL, r);
4ae388
+	log_filter(dev, NULL, NULL, NULL, NULL, r);
4ae388
 	return r;
4ae388
 }
4ae388
 
4ae388
@@ -297,15 +310,67 @@ int
4ae388
 filter_wwid (vector blist, vector elist, char * wwid)
4ae388
 {
4ae388
 	int r = _filter_wwid(blist, elist, wwid);
4ae388
-	log_filter(NULL, NULL, NULL, wwid, r);
4ae388
+	log_filter(NULL, NULL, NULL, wwid, NULL, r);
4ae388
 	return r;
4ae388
 }
4ae388
 
4ae388
 int
4ae388
+_filter_property (struct config *conf, const char *env)
4ae388
+{
4ae388
+	if (_blacklist_exceptions(conf->elist_property, env))
4ae388
+		return MATCH_PROPERTY_BLIST_EXCEPT;
4ae388
+	if (_blacklist(conf->blist_property, env))
4ae388
+		return MATCH_PROPERTY_BLIST;
4ae388
+
4ae388
+	return 0;
4ae388
+}
4ae388
+
4ae388
+int
4ae388
+filter_property(struct config * conf, struct udev_device * udev)
4ae388
+{
4ae388
+	const char *devname = udev_device_get_sysname(udev);
4ae388
+	struct udev_list_entry *list_entry;
4ae388
+	int r;
4ae388
+
4ae388
+	if (!udev || (!VECTOR_SIZE(conf->elist_property) &&
4ae388
+		      !VECTOR_SIZE(conf->blist_property)))
4ae388
+		return 0;
4ae388
+
4ae388
+	udev_list_entry_foreach(list_entry,
4ae388
+				udev_device_get_properties_list_entry(udev)) {
4ae388
+		const char *env;
4ae388
+
4ae388
+		env = udev_list_entry_get_name(list_entry);
4ae388
+		if (!env)
4ae388
+			continue;
4ae388
+
4ae388
+		r = _filter_property(conf, env);
4ae388
+		if (r) {
4ae388
+			log_filter(devname, NULL, NULL, NULL, env, r);
4ae388
+			return r;
4ae388
+		}
4ae388
+	}
4ae388
+
4ae388
+	/*
4ae388
+	 * This is the inverse of the 'normal' matching;
4ae388
+	 * the environment variable _has_ to match.
4ae388
+	 */
4ae388
+	if (VECTOR_SIZE(conf->elist_property)) {
4ae388
+		log_filter(devname, NULL, NULL, NULL, NULL,
4ae388
+				MATCH_PROPERTY_BLIST_MISSING);
4ae388
+		return MATCH_PROPERTY_BLIST_MISSING;
4ae388
+	}
4ae388
+	return 0;
4ae388
+}
4ae388
+
4ae388
+int
4ae388
 _filter_path (struct config * conf, struct path * pp)
4ae388
 {
4ae388
 	int r;
4ae388
 
4ae388
+	r = filter_property(conf, pp->udev);
4ae388
+	if (r > 0)
4ae388
+		return r;
4ae388
 	r = _filter_devnode(conf->blist_devnode, conf->elist_devnode,pp->dev);
4ae388
 	if (r > 0)
4ae388
 		return r;
4ae388
@@ -321,7 +386,7 @@ int
4ae388
 filter_path (struct config * conf, struct path * pp)
4ae388
 {
4ae388
 	int r=_filter_path(conf, pp);
4ae388
-	log_filter(pp->dev, pp->vendor_id, pp->product_id, pp->wwid, r);
4ae388
+	log_filter(pp->dev, pp->vendor_id, pp->product_id, pp->wwid, NULL, r);
4ae388
 	return r;
4ae388
 }
4ae388
 
4ae388
Index: multipath-tools-130222/libmultipath/blacklist.h
4ae388
===================================================================
4ae388
--- multipath-tools-130222.orig/libmultipath/blacklist.h
4ae388
+++ multipath-tools-130222/libmultipath/blacklist.h
4ae388
@@ -1,15 +1,19 @@
4ae388
 #ifndef _BLACKLIST_H
4ae388
 #define _BLACKLIST_H
4ae388
 
4ae388
+#include <libudev.h>
4ae388
 #include "regex.h"
4ae388
 
4ae388
 #define MATCH_NOTHING       0
4ae388
 #define MATCH_WWID_BLIST    1
4ae388
 #define MATCH_DEVICE_BLIST  2
4ae388
 #define MATCH_DEVNODE_BLIST 3
4ae388
+#define MATCH_PROPERTY_BLIST 4
4ae388
+#define MATCH_PROPERTY_BLIST_MISSING 5
4ae388
 #define MATCH_WWID_BLIST_EXCEPT    -MATCH_WWID_BLIST
4ae388
 #define MATCH_DEVICE_BLIST_EXCEPT  -MATCH_DEVICE_BLIST
4ae388
 #define MATCH_DEVNODE_BLIST_EXCEPT -MATCH_DEVNODE_BLIST
4ae388
+#define MATCH_PROPERTY_BLIST_EXCEPT -MATCH_PROPERTY_BLIST
4ae388
 
4ae388
 struct blentry {
4ae388
 	char * str;
4ae388
@@ -31,6 +35,7 @@ int filter_devnode (vector, vector, char
4ae388
 int filter_wwid (vector, vector, char *);
4ae388
 int filter_device (vector, vector, char *, char *);
4ae388
 int filter_path (struct config *, struct path *);
4ae388
+int filter_property(struct config *, struct udev_device *);
4ae388
 int store_ble (vector, char *, int);
4ae388
 int set_ble_device (vector, char *, char *, int);
4ae388
 void free_blacklist (vector);
4ae388
Index: multipath-tools-130222/libmultipath/config.c
4ae388
===================================================================
4ae388
--- multipath-tools-130222.orig/libmultipath/config.c
4ae388
+++ multipath-tools-130222/libmultipath/config.c
4ae388
@@ -597,10 +597,12 @@ free_config (struct config * conf)
4ae388
 
4ae388
 	free_blacklist(conf->blist_devnode);
4ae388
 	free_blacklist(conf->blist_wwid);
4ae388
+	free_blacklist(conf->blist_property);
4ae388
 	free_blacklist_device(conf->blist_device);
4ae388
 
4ae388
 	free_blacklist(conf->elist_devnode);
4ae388
 	free_blacklist(conf->elist_wwid);
4ae388
+	free_blacklist(conf->elist_property);
4ae388
 	free_blacklist_device(conf->elist_device);
4ae388
 
4ae388
 	free_mptable(conf->mptable);
4ae388
@@ -779,8 +781,12 @@ load_config (char * file, struct udev *u
4ae388
 		if (!conf->blist_device)
4ae388
 			goto out;
4ae388
 	}
4ae388
-	if (setup_default_blist(conf))
4ae388
-		goto out;
4ae388
+	if (conf->blist_property == NULL) {
4ae388
+		conf->blist_property = vector_alloc();
4ae388
+
4ae388
+		if (!conf->blist_property)
4ae388
+			goto out;
4ae388
+	}
4ae388
 
4ae388
 	if (conf->elist_devnode == NULL) {
4ae388
 		conf->elist_devnode = vector_alloc();
4ae388
@@ -802,6 +808,16 @@ load_config (char * file, struct udev *u
4ae388
 			goto out;
4ae388
 	}
4ae388
 
4ae388
+	if (conf->elist_property == NULL) {
4ae388
+		conf->elist_property = vector_alloc();
4ae388
+
4ae388
+		if (!conf->elist_property)
4ae388
+			goto out;
4ae388
+	}
4ae388
+
4ae388
+	if (setup_default_blist(conf))
4ae388
+		goto out;
4ae388
+
4ae388
 	if (conf->mptable == NULL) {
4ae388
 		conf->mptable = vector_alloc();
4ae388
 		if (!conf->mptable)
4ae388
Index: multipath-tools-130222/libmultipath/config.h
4ae388
===================================================================
4ae388
--- multipath-tools-130222.orig/libmultipath/config.h
4ae388
+++ multipath-tools-130222/libmultipath/config.h
4ae388
@@ -189,9 +189,11 @@ struct config {
4ae388
 	vector blist_devnode;
4ae388
 	vector blist_wwid;
4ae388
 	vector blist_device;
4ae388
+	vector blist_property;
4ae388
 	vector elist_devnode;
4ae388
 	vector elist_wwid;
4ae388
 	vector elist_device;
4ae388
+	vector elist_property;
4ae388
 };
4ae388
 
4ae388
 struct config * conf;
4ae388
Index: multipath-tools-130222/libmultipath/configure.c
4ae388
===================================================================
4ae388
--- multipath-tools-130222.orig/libmultipath/configure.c
4ae388
+++ multipath-tools-130222/libmultipath/configure.c
4ae388
@@ -1027,6 +1027,10 @@ get_refwwid (char * dev, enum devtypes d
4ae388
 				return ret;
4ae388
 			}
4ae388
 		}
4ae388
+		if (pp->udev && pp->uid_attribute &&
4ae388
+		    filter_property(conf, pp->udev) > 0)
4ae388
+			return 2;
4ae388
+
4ae388
 		refwwid = pp->wwid;
4ae388
 		goto out;
4ae388
 	}
4ae388
@@ -1051,6 +1055,10 @@ get_refwwid (char * dev, enum devtypes d
4ae388
 				return ret;
4ae388
 			}
4ae388
 		}
4ae388
+		if (pp->udev && pp->uid_attribute &&
4ae388
+		    filter_property(conf, pp->udev) > 0)
4ae388
+			return 2;
4ae388
+
4ae388
 		refwwid = pp->wwid;
4ae388
 		goto out;
4ae388
 	}
4ae388
Index: multipath-tools-130222/libmultipath/dict.c
4ae388
===================================================================
4ae388
--- multipath-tools-130222.orig/libmultipath/dict.c
4ae388
+++ multipath-tools-130222/libmultipath/dict.c
4ae388
@@ -1063,8 +1063,11 @@ blacklist_handler(vector strvec)
4ae388
 		conf->blist_wwid = vector_alloc();
4ae388
 	if (!conf->blist_device)
4ae388
 		conf->blist_device = vector_alloc();
4ae388
+	if (!conf->blist_property)
4ae388
+		conf->blist_property = vector_alloc();
4ae388
 
4ae388
-	if (!conf->blist_devnode || !conf->blist_wwid || !conf->blist_device)
4ae388
+	if (!conf->blist_devnode || !conf->blist_wwid ||
4ae388
+	    !conf->blist_device || !conf->blist_property)
4ae388
 		return 1;
4ae388
 
4ae388
 	return 0;
4ae388
@@ -1079,8 +1082,11 @@ blacklist_exceptions_handler(vector strv
4ae388
 		conf->elist_wwid = vector_alloc();
4ae388
 	if (!conf->elist_device)
4ae388
 		conf->elist_device = vector_alloc();
4ae388
+	if (!conf->elist_property)
4ae388
+		conf->elist_property = vector_alloc();
4ae388
 
4ae388
-	if (!conf->elist_devnode || !conf->elist_wwid || !conf->elist_device)
4ae388
+	if (!conf->elist_devnode || !conf->elist_wwid ||
4ae388
+	    !conf->elist_device || !conf->elist_property)
4ae388
 		return 1;
4ae388
 
4ae388
 	return 0;
4ae388
@@ -1139,6 +1145,32 @@ ble_except_wwid_handler(vector strvec)
4ae388
 }
4ae388
 
4ae388
 static int
4ae388
+ble_property_handler(vector strvec)
4ae388
+{
4ae388
+	char * buff;
4ae388
+
4ae388
+	buff = set_value(strvec);
4ae388
+
4ae388
+	if (!buff)
4ae388
+		return 1;
4ae388
+
4ae388
+	return store_ble(conf->blist_property, buff, ORIGIN_CONFIG);
4ae388
+}
4ae388
+
4ae388
+static int
4ae388
+ble_except_property_handler(vector strvec)
4ae388
+{
4ae388
+	char * buff;
4ae388
+
4ae388
+	buff = set_value(strvec);
4ae388
+
4ae388
+	if (!buff)
4ae388
+		return 1;
4ae388
+
4ae388
+	return store_ble(conf->elist_property, buff, ORIGIN_CONFIG);
4ae388
+}
4ae388
+
4ae388
+static int
4ae388
 ble_device_handler(vector strvec)
4ae388
 {
4ae388
 	return alloc_ble_device(conf->blist_device);
4ae388
@@ -3903,6 +3935,7 @@ init_keywords(void)
4ae388
 	install_keyword_root("blacklist", &blacklist_handler);
4ae388
 	install_keyword_multi("devnode", &ble_devnode_handler, &snprint_ble_simple);
4ae388
 	install_keyword_multi("wwid", &ble_wwid_handler, &snprint_ble_simple);
4ae388
+	install_keyword_multi("property", &ble_property_handler, &snprint_ble_simple);
4ae388
 	install_keyword_multi("device", &ble_device_handler, NULL);
4ae388
 	install_sublevel();
4ae388
 	install_keyword("vendor", &ble_vendor_handler, &snprint_bled_vendor);
4ae388
@@ -3911,6 +3944,7 @@ init_keywords(void)
4ae388
 	install_keyword_root("blacklist_exceptions", &blacklist_exceptions_handler);
4ae388
 	install_keyword_multi("devnode", &ble_except_devnode_handler, &snprint_ble_simple);
4ae388
 	install_keyword_multi("wwid", &ble_except_wwid_handler, &snprint_ble_simple);
4ae388
+	install_keyword_multi("property", &ble_except_property_handler, &snprint_ble_simple);
4ae388
 	install_keyword_multi("device", &ble_except_device_handler, NULL);
4ae388
 	install_sublevel();
4ae388
 	install_keyword("vendor", &ble_except_vendor_handler, &snprint_bled_vendor);
4ae388
Index: multipath-tools-130222/libmultipath/discovery.c
4ae388
===================================================================
4ae388
--- multipath-tools-130222.orig/libmultipath/discovery.c
4ae388
+++ multipath-tools-130222/libmultipath/discovery.c
4ae388
@@ -1332,6 +1332,8 @@ pathinfo (struct path *pp, vector hwtabl
4ae388
 	 * limited by DI_BLACKLIST and occurs before this debug
4ae388
 	 * message with the mask value.
4ae388
 	 */
4ae388
+	if (pp->udev && filter_property(conf, pp->udev) > 0)
4ae388
+		return PATHINFO_SKIPPED;
4ae388
 	if (filter_devnode(conf->blist_devnode,
4ae388
 			   conf->elist_devnode,
4ae388
 			   pp->dev) > 0)
4ae388
Index: multipath-tools-130222/libmultipath/print.c
4ae388
===================================================================
4ae388
--- multipath-tools-130222.orig/libmultipath/print.c
4ae388
+++ multipath-tools-130222/libmultipath/print.c
4ae388
@@ -1415,6 +1415,19 @@ snprint_blacklist_report (char * buff, i
4ae388
 
4ae388
 	if ((len - fwd - threshold) <= 0)
4ae388
 		return len;
4ae388
+	fwd += snprintf(buff + fwd, len - fwd, "udev property rules:\n"
4ae388
+					       "- blacklist:\n");
4ae388
+	if (!snprint_blacklist_group(buff, len, &fwd, &conf->blist_property))
4ae388
+		return len;
4ae388
+
4ae388
+	if ((len - fwd - threshold) <= 0)
4ae388
+		return len;
4ae388
+	fwd += snprintf(buff + fwd, len - fwd, "- exceptions:\n");
4ae388
+	if (snprint_blacklist_group(buff, len, &fwd, &conf->elist_property) == 0)
4ae388
+		return len;
4ae388
+
4ae388
+	if ((len - fwd - threshold) <= 0)
4ae388
+		return len;
4ae388
 	fwd += snprintf(buff + fwd, len - fwd, "wwid rules:\n"
4ae388
 					       "- blacklist:\n");
4ae388
 	if (snprint_blacklist_group(buff, len, &fwd, &conf->blist_wwid) == 0)
4ae388
@@ -1480,6 +1493,15 @@ snprint_blacklist (char * buff, int len)
4ae388
 		if (fwd > len)
4ae388
 			return len;
4ae388
 	}
4ae388
+	vector_foreach_slot (conf->blist_property, ble, i) {
4ae388
+		kw = find_keyword(rootkw->sub, "property");
4ae388
+		if (!kw)
4ae388
+			return 0;
4ae388
+		fwd += snprint_keyword(buff + fwd, len - fwd, "\t%k %v\n",
4ae388
+				       kw, ble);
4ae388
+		if (fwd > len)
4ae388
+			return len;
4ae388
+	}
4ae388
 	rootkw = find_keyword(rootkw->sub, "device");
4ae388
 	if (!rootkw)
4ae388
 		return 0;
4ae388
@@ -1544,6 +1566,15 @@ snprint_blacklist_except (char * buff, i
4ae388
 		if (!kw)
4ae388
 			return 0;
4ae388
 		fwd += snprint_keyword(buff + fwd, len - fwd, "\t%k %v\n",
4ae388
+				       kw, ele);
4ae388
+		if (fwd > len)
4ae388
+			return len;
4ae388
+	}
4ae388
+	vector_foreach_slot (conf->elist_property, ele, i) {
4ae388
+		kw = find_keyword(rootkw->sub, "property");
4ae388
+		if (!kw)
4ae388
+			return 0;
4ae388
+		fwd += snprint_keyword(buff + fwd, len - fwd, "\t%k %v\n",
4ae388
 				       kw, ele);
4ae388
 		if (fwd > len)
4ae388
 			return len;
4ae388
Index: multipath-tools-130222/multipath/multipath.conf.5
4ae388
===================================================================
4ae388
--- multipath-tools-130222.orig/multipath/multipath.conf.5
4ae388
+++ multipath-tools-130222/multipath/multipath.conf.5
4ae388
@@ -626,6 +626,9 @@ The \fIWorld Wide Identification\fR of a
4ae388
 .B devnode
4ae388
 Regular expression of the device nodes to be excluded.
4ae388
 .TP
4ae388
+.B property
4ae388
+Regular expresion of the udev property to be excluded.
4ae388
+.TP
4ae388
 .B device
4ae388
 Subsection for the device description. This subsection recognizes the
4ae388
 .I vendor
4ae388
@@ -650,8 +653,11 @@ The following keywords are recognized:
4ae388
 .B wwid
4ae388
 The \fIWorld Wide Identification\fR of a device.
4ae388
 .TP
4ae388
+.B property
4ae388
+Regular expresion of the udev property to be whitelisted.
4ae388
+.TP
4ae388
 .B devnode
4ae388
-Regular expression of the device nodes to be excluded.
4ae388
+Regular expression of the device nodes to be whitelisted.
4ae388
 .TP
4ae388
 .B device
4ae388
 Subsection for the device description. This subsection recognizes the
4ae388
@@ -661,6 +667,25 @@ and
4ae388
 keywords. For a full description of these keywords please see the
4ae388
 .I devices
4ae388
 section description.
4ae388
+.LP
4ae388
+The
4ae388
+.I property
4ae388
+blacklist and whitelist handling is different from the usual handling
4ae388
+in the sense that if the whitelist is set, it
4ae388
+.B has
4ae388
+to match, otherwise the device will be blacklisted.
4ae388
+In these cases the message
4ae388
+.I blacklisted, udev property missing
4ae388
+will be displayed. For example settting the
4ae388
+.I property
4ae388
+blacklist_exception to
4ae388
+.I (SCSI_IDENT_|ID_WWN)
4ae388
+will blacklist all devices that have no udev property whose name regex matches
4ae388
+either
4ae388
+.I SCSI_IDENT_
4ae388
+or
4ae388
+.I ID_WWN.
4ae388
+This works to exclude most non-multipathable devices.
4ae388
 .SH "multipaths section"
4ae388
 The only recognized attribute for the
4ae388
 .B multipaths