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

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