Skip to contentSkip to conversation

add the ability to have blacklist exceptions for specific vendor:product

PATCH In review Benjamin Marzinski 2 participants 2 messages Jan 10, 2007 Device mapper

lore
Share & tools
lore

Benjamin Marzinski

author maintainer
#0 lore raw

PATCH 1/1 add the ability to have blacklist exceptions for specific vendor:product

This patch adds the ability to have blacklist exceptions for vendor:product devices. Also, the wwid and devnode exceptions weren't getting freed properly in free_config, so that is fixed as well.

-Ben

Benjamin E. Marzinski
[email protected]

libmultipath/blacklist.c +21 -2
diff -urpN mp-devel-clean/libmultipath/blacklist.c mp-devel-patched/libmultipath/blacklist.c
@@ -174,11 +174,30 @@ blacklist (vector blist, vector elist, c
 }
 
 int
-blacklist_device (vector blist, char * vendor, char * product)
+blacklist_exceptions_device(vector elist, char * vendor, char * product)
 {
 	int i;
 	struct blentry_device * ble;
 
+	vector_foreach_slot (elist, ble, i) {
+		if (!regexec(&ble->vendor_reg, vendor, 0, NULL, 0) &&
+		    !regexec(&ble->product_reg, product, 0, NULL, 0)) {
+			condlog(3, "%s:%s: exception-listed", vendor, product);
+			return 1;
+		}
+	}
+	return 0;
+}
+
+int
+blacklist_device (vector blist, vector elist, char * vendor, char * product)
+{
+	int i;
+	struct blentry_device * ble;
+
+	if (blacklist_exceptions_device(elist, vendor, product))
+		return 0;
+
 	vector_foreach_slot (blist, ble, i) {
 		if (!regexec(&ble->vendor_reg, vendor, 0, NULL, 0) &&
 		    !regexec(&ble->product_reg, product, 0, NULL, 0)) {
@@ -199,7 +218,7 @@ blacklist_path (struct config * conf, st
 		return 1;
 
 	if (pp->vendor_id && pp->product_id &&
-	    blacklist_device(conf->blist_device, pp->vendor_id, pp->product_id))
+	    blacklist_device(conf->blist_device, conf->elist_device, pp->vendor_id, pp->product_id))
 		return 1;
 
 	return 0;
libmultipath/blacklist.h +1 -1
diff -urpN mp-devel-clean/libmultipath/blacklist.h mp-devel-patched/libmultipath/blacklist.h
@@ -20,7 +20,7 @@ struct blentry_device {
 int setup_default_blist (struct config *);
 int alloc_ble_device (vector);
 int blacklist (vector, vector, char *);
-int blacklist_device (vector, char *, char *);
+int blacklist_device (vector, vector, char *, char *);
 int blacklist_path (struct config *, struct path *);
 int store_ble (vector, char *, int);
 int set_ble_device (vector, char *, char *, int);
libmultipath/config.c +10 -4
diff -urpN mp-devel-clean/libmultipath/config.c mp-devel-patched/libmultipath/config.c
@@ -334,10 +334,9 @@ free_config (struct config * conf)
 	free_blacklist(conf->blist_wwid);
 	free_blacklist_device(conf->blist_device);
 
-	if (conf->elist_devnode)
-		FREE(conf->elist_devnode);
-	if (conf->elist_wwid)
-		FREE(conf->elist_wwid);
+	free_blacklist(conf->elist_devnode);
+	free_blacklist(conf->elist_wwid);
+	free_blacklist_device(conf->elist_device);
 
 	free_mptable(conf->mptable);
 	free_hwtable(conf->hwtable);
@@ -422,6 +421,13 @@ load_config (char * file)
 			goto out;
 	}
 
+	if (conf->elist_device == NULL) {
+		conf->elist_device = vector_alloc();
+		
+		if (!conf->elist_device)
+			goto out;
+	}
+
 	if (conf->mptable == NULL) {
 		conf->mptable = vector_alloc();
 
libmultipath/config.h +1 -0
diff -urpN mp-devel-clean/libmultipath/config.h mp-devel-patched/libmultipath/config.h
@@ -80,6 +80,7 @@ struct config {
 	vector blist_device;
 	vector elist_devnode;
 	vector elist_wwid;
+	vector elist_device;
 };
 
 struct config * conf;
libmultipath/dict.c +40 -1

72 lines not on this page · raw message

libmultipath/print.c +33 -0
diff -urpN mp-devel-clean/libmultipath/print.c mp-devel-patched/libmultipath/print.c
@@ -946,6 +946,12 @@ snprint_blacklist_report (char * buff, i
 	if (snprint_blacklist_devgroup(buff, len, &fwd, &conf->blist_device) == 0)
 		return len;
 
+	if ((len - fwd - threshold) <= 0)
+		return len;
+	fwd += snprintf(buff + fwd, len - fwd, "- exceptions:\n");
+	if (snprint_blacklist_devgroup(buff, len, &fwd, &conf->elist_device) == 0)
+		return len;
+
 	if (fwd > len)
 		return len;
 	return fwd;
@@ -1024,6 +1030,7 @@ snprint_blacklist_except (char * buff, i
 {
 	int i;
 	struct blentry * ele;
+	struct blentry_device * eled;
 	int fwd = 0;
 	struct keyword *rootkw;
 	struct keyword *kw;
@@ -1054,6 +1061,32 @@ snprint_blacklist_except (char * buff, i
 		if (fwd > len)
 			return len;
 	}
+	rootkw = find_keyword(rootkw->sub, "device");
+	if (!rootkw)
+		return 0;
+
+	vector_foreach_slot (conf->elist_device, eled, i) {
+		fwd += snprintf(buff + fwd, len - fwd, "\tdevice {\n");
+		if (fwd > len)
+			return len;
+		kw = find_keyword(rootkw->sub, "vendor");
+		if (!kw)
+			return 0;
+		fwd += snprint_keyword(buff + fwd, len - fwd, "\t\t%k %v\n",
+				       kw, eled);
+		if (fwd > len)
+			return len;
+		kw = find_keyword(rootkw->sub, "product");
+		if (!kw)
+			return 0;
+		fwd += snprint_keyword(buff + fwd, len - fwd, "\t\t%k %v\n",
+				       kw, eled);
+		if (fwd > len)
+			return len;
+		fwd += snprintf(buff + fwd, len - fwd, "\t}\n");
+		if (fwd > len)
+			return len;
+	}
 	fwd += snprintf(buff + fwd, len - fwd, "}\n");
 	if (fwd > len)
 		return len;
#1 lore raw
Quoted 4 lines · Benjamin Marzinski

This patch adds the ability to have blacklist exceptions for vendor:product devices. Also, the wwid and devnode exceptions weren't getting freed properly in free_config, so that is fixed as well.

Thanks for the prompt review, and enhancement.
Applied.