diff options
author | Christophe Varoqui <cvaroqui@zezette.localdomain> | 2007-01-10 23:06:09 +0100 |
---|---|---|
committer | Christophe Varoqui <cvaroqui@zezette.localdomain> | 2007-01-10 23:06:09 +0100 |
commit | cbc9b2bb5b24df3338f9c7d1c80a3df9a2ae26f7 (patch) | |
tree | 69aed9b20f2efd39f936a9256df21eae02e10099 | |
parent | a01975dbcea541aca7823c251c3fb45f5000263c (diff) | |
download | multipath-tools-cbc9b2bb5b24df3338f9c7d1c80a3df9a2ae26f7.tar.gz multipath-tools-cbc9b2bb5b24df3338f9c7d1c80a3df9a2ae26f7.tar.bz2 multipath-tools-cbc9b2bb5b24df3338f9c7d1c80a3df9a2ae26f7.zip |
[libmultipath] Blacklist exception follow-ups
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.
Benjamin E. Marzinski, RedHat
-rw-r--r-- | libmultipath/blacklist.c | 23 | ||||
-rw-r--r-- | libmultipath/blacklist.h | 2 | ||||
-rw-r--r-- | libmultipath/config.c | 14 | ||||
-rw-r--r-- | libmultipath/config.h | 1 | ||||
-rw-r--r-- | libmultipath/dict.c | 41 | ||||
-rw-r--r-- | libmultipath/print.c | 33 |
6 files changed, 106 insertions, 8 deletions
diff --git a/libmultipath/blacklist.c b/libmultipath/blacklist.c index 5cd60a1..44987f6 100644 --- a/libmultipath/blacklist.c +++ b/libmultipath/blacklist.c @@ -174,11 +174,30 @@ blacklist (vector blist, vector elist, char * str) } 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, struct path * pp) 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; diff --git a/libmultipath/blacklist.h b/libmultipath/blacklist.h index 104e7fd..99c6fd1 100644 --- a/libmultipath/blacklist.h +++ b/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); diff --git a/libmultipath/config.c b/libmultipath/config.c index b2fdf16..a39af8a 100644 --- a/libmultipath/config.c +++ b/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(); diff --git a/libmultipath/config.h b/libmultipath/config.h index 90380bd..61e5adf 100644 --- a/libmultipath/config.h +++ b/libmultipath/config.h @@ -80,6 +80,7 @@ struct config { vector blist_device; vector elist_devnode; vector elist_wwid; + vector elist_device; }; struct config * conf; diff --git a/libmultipath/dict.c b/libmultipath/dict.c index e5db4ef..80447c7 100644 --- a/libmultipath/dict.c +++ b/libmultipath/dict.c @@ -242,8 +242,9 @@ blacklist_exceptions_handler(vector strvec) { conf->elist_devnode = vector_alloc(); conf->elist_wwid = vector_alloc(); + conf->elist_device = vector_alloc(); - if (!conf->elist_devnode || !conf->elist_wwid) + if (!conf->elist_devnode || !conf->elist_wwid || !conf->blist_device) return 1; return 0; @@ -308,6 +309,12 @@ ble_device_handler(vector strvec) } static int +ble_except_device_handler(vector strvec) +{ + return alloc_ble_device(conf->elist_device); +} + +static int ble_vendor_handler(vector strvec) { char * buff; @@ -321,6 +328,20 @@ ble_vendor_handler(vector strvec) } static int +ble_except_vendor_handler(vector strvec) +{ + char * buff; + int r; + + buff = set_value(strvec); + + if (!buff) + return 1; + + return set_ble_device(conf->elist_device, buff, NULL, ORIGIN_CONFIG); +} + +static int ble_product_handler(vector strvec) { char * buff; @@ -333,6 +354,19 @@ ble_product_handler(vector strvec) return set_ble_device(conf->blist_device, NULL, buff, ORIGIN_CONFIG); } +static int +ble_except_product_handler(vector strvec) +{ + char * buff; + + buff = set_value(strvec); + + if (!buff) + return 1; + + return set_ble_device(conf->elist_device, NULL, buff, ORIGIN_CONFIG); +} + /* * devices block handlers */ @@ -1377,6 +1411,11 @@ init_keywords(void) install_keyword_root("blacklist_exceptions", &blacklist_exceptions_handler); install_keyword("devnode", &ble_except_devnode_handler, &snprint_ble_simple); install_keyword("wwid", &ble_except_wwid_handler, &snprint_ble_simple); + install_keyword("device", &ble_except_device_handler, NULL); + install_sublevel(); + install_keyword("vendor", &ble_except_vendor_handler, &snprint_bled_vendor); + install_keyword("product", &ble_except_product_handler, &snprint_bled_product); + install_sublevel_end(); #if 0 __deprecated install_keyword_root("devnode_blacklist", &blacklist_handler); diff --git a/libmultipath/print.c b/libmultipath/print.c index dbad281..4a23ccb 100644 --- a/libmultipath/print.c +++ b/libmultipath/print.c @@ -946,6 +946,12 @@ snprint_blacklist_report (char * buff, int len) 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, int len) { 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, int len) 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; |