|
|
96a22b |
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
96a22b |
From: Benjamin Marzinski <bmarzins@redhat.com>
|
|
|
96a22b |
Date: Mon, 8 Jun 2020 13:40:16 -0500
|
|
|
96a22b |
Subject: [PATCH] libmultipath: invert regexes that start with exclamation
|
|
|
96a22b |
point
|
|
|
96a22b |
|
|
|
96a22b |
The number of devices that multipath needs to blacklist keeps growing,
|
|
|
96a22b |
and the udev rules already have
|
|
|
96a22b |
|
|
|
96a22b |
KERNEL!="sd*|dasd*|nvme*", GOTO="end_mpath"
|
|
|
96a22b |
|
|
|
96a22b |
so they only work correctly with these device types. Instead of
|
|
|
96a22b |
individually blacklisting every type of device that can't be
|
|
|
96a22b |
multipathed, multipath's default blacklist should work like the udev
|
|
|
96a22b |
rule, and blacklist all devices that aren't scsi, dasd, or nvme.
|
|
|
96a22b |
Unfortunately, the c regex library doesn't support negative lookahead.
|
|
|
96a22b |
Instead, multipath should treat "!" at the beginning of
|
|
|
96a22b |
blacklist/exceptions regexes as inverse matching the rest of the regex.
|
|
|
96a22b |
If users need to match a literal '!' as the first character of their
|
|
|
96a22b |
regex, they can use "\!" instead. This allows multipath to change the
|
|
|
96a22b |
default devnode blacklist regex to "!^(sd[a-z]|dasd[a-z]|nvme[0-9])".
|
|
|
96a22b |
|
|
|
96a22b |
Extra tests have been added to the blacklist unit tests to verify the
|
|
|
96a22b |
inverse matching code and the new default blacklist.
|
|
|
96a22b |
|
|
|
96a22b |
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
|
|
|
96a22b |
---
|
|
|
96a22b |
libmultipath/blacklist.c | 41 +++++++++-----
|
|
|
96a22b |
libmultipath/blacklist.h | 3 +
|
|
|
96a22b |
multipath/multipath.conf.5 | 17 ++++--
|
|
|
96a22b |
tests/blacklist.c | 110 +++++++++++++++++++++++++++++++++++++
|
|
|
96a22b |
tests/test-lib.c | 2 +-
|
|
|
96a22b |
5 files changed, 155 insertions(+), 18 deletions(-)
|
|
|
96a22b |
|
|
|
96a22b |
diff --git a/libmultipath/blacklist.c b/libmultipath/blacklist.c
|
|
|
96a22b |
index 04d3adb9..0c58aa32 100644
|
|
|
96a22b |
--- a/libmultipath/blacklist.c
|
|
|
96a22b |
+++ b/libmultipath/blacklist.c
|
|
|
96a22b |
@@ -15,9 +15,24 @@
|
|
|
96a22b |
#include "structs_vec.h"
|
|
|
96a22b |
#include "print.h"
|
|
|
96a22b |
|
|
|
96a22b |
+char *check_invert(char *str, bool *invert)
|
|
|
96a22b |
+{
|
|
|
96a22b |
+ if (str[0] == '!') {
|
|
|
96a22b |
+ *invert = true;
|
|
|
96a22b |
+ return str + 1;
|
|
|
96a22b |
+ }
|
|
|
96a22b |
+ if (str[0] == '\\' && str[1] == '!') {
|
|
|
96a22b |
+ *invert = false;
|
|
|
96a22b |
+ return str + 1;
|
|
|
96a22b |
+ }
|
|
|
96a22b |
+ *invert = false;
|
|
|
96a22b |
+ return str;
|
|
|
96a22b |
+}
|
|
|
96a22b |
+
|
|
|
96a22b |
int store_ble(vector blist, char * str, int origin)
|
|
|
96a22b |
{
|
|
|
96a22b |
struct blentry * ble;
|
|
|
96a22b |
+ char *regex_str;
|
|
|
96a22b |
|
|
|
96a22b |
if (!str)
|
|
|
96a22b |
return 0;
|
|
|
96a22b |
@@ -30,7 +45,8 @@ int store_ble(vector blist, char * str, int origin)
|
|
|
96a22b |
if (!ble)
|
|
|
96a22b |
goto out;
|
|
|
96a22b |
|
|
|
96a22b |
- if (regcomp(&ble->regex, str, REG_EXTENDED|REG_NOSUB))
|
|
|
96a22b |
+ regex_str = check_invert(str, &ble->invert);
|
|
|
96a22b |
+ if (regcomp(&ble->regex, regex_str, REG_EXTENDED|REG_NOSUB))
|
|
|
96a22b |
goto out1;
|
|
|
96a22b |
|
|
|
96a22b |
if (!vector_alloc_slot(blist))
|
|
|
96a22b |
@@ -66,6 +82,7 @@ int alloc_ble_device(vector blist)
|
|
|
96a22b |
int set_ble_device(vector blist, char * vendor, char * product, int origin)
|
|
|
96a22b |
{
|
|
|
96a22b |
struct blentry_device * ble;
|
|
|
96a22b |
+ char *regex_str;
|
|
|
96a22b |
|
|
|
96a22b |
if (!blist)
|
|
|
96a22b |
return 1;
|
|
|
96a22b |
@@ -76,7 +93,8 @@ int set_ble_device(vector blist, char * vendor, char * product, int origin)
|
|
|
96a22b |
return 1;
|
|
|
96a22b |
|
|
|
96a22b |
if (vendor) {
|
|
|
96a22b |
- if (regcomp(&ble->vendor_reg, vendor,
|
|
|
96a22b |
+ regex_str = check_invert(vendor, &ble->vendor_invert);
|
|
|
96a22b |
+ if (regcomp(&ble->vendor_reg, regex_str,
|
|
|
96a22b |
REG_EXTENDED|REG_NOSUB)) {
|
|
|
96a22b |
FREE(vendor);
|
|
|
96a22b |
if (product)
|
|
|
96a22b |
@@ -86,7 +104,8 @@ int set_ble_device(vector blist, char * vendor, char * product, int origin)
|
|
|
96a22b |
ble->vendor = vendor;
|
|
|
96a22b |
}
|
|
|
96a22b |
if (product) {
|
|
|
96a22b |
- if (regcomp(&ble->product_reg, product,
|
|
|
96a22b |
+ regex_str = check_invert(product, &ble->product_invert);
|
|
|
96a22b |
+ if (regcomp(&ble->product_reg, regex_str,
|
|
|
96a22b |
REG_EXTENDED|REG_NOSUB)) {
|
|
|
96a22b |
FREE(product);
|
|
|
96a22b |
if (vendor) {
|
|
|
96a22b |
@@ -108,7 +127,7 @@ match_reglist (vector blist, const char * str)
|
|
|
96a22b |
struct blentry * ble;
|
|
|
96a22b |
|
|
|
96a22b |
vector_foreach_slot (blist, ble, i) {
|
|
|
96a22b |
- if (!regexec(&ble->regex, str, 0, NULL, 0))
|
|
|
96a22b |
+ if (!!regexec(&ble->regex, str, 0, NULL, 0) == ble->invert)
|
|
|
96a22b |
return 1;
|
|
|
96a22b |
}
|
|
|
96a22b |
return 0;
|
|
|
96a22b |
@@ -125,9 +144,11 @@ match_reglist_device (const struct _vector *blist, const char * vendor,
|
|
|
96a22b |
if (!ble->vendor && !ble->product)
|
|
|
96a22b |
continue;
|
|
|
96a22b |
if ((!ble->vendor ||
|
|
|
96a22b |
- !regexec(&ble->vendor_reg, vendor, 0, NULL, 0)) &&
|
|
|
96a22b |
+ !!regexec(&ble->vendor_reg, vendor, 0, NULL, 0) ==
|
|
|
96a22b |
+ ble->vendor_invert) &&
|
|
|
96a22b |
(!ble->product ||
|
|
|
96a22b |
- !regexec(&ble->product_reg, product, 0, NULL, 0)))
|
|
|
96a22b |
+ !!regexec(&ble->product_reg, product, 0, NULL, 0) ==
|
|
|
96a22b |
+ ble->product_invert))
|
|
|
96a22b |
return 1;
|
|
|
96a22b |
}
|
|
|
96a22b |
return 0;
|
|
|
96a22b |
@@ -160,13 +181,7 @@ setup_default_blist (struct config * conf)
|
|
|
96a22b |
char * str;
|
|
|
96a22b |
int i;
|
|
|
96a22b |
|
|
|
96a22b |
- str = STRDUP("^(ram|zram|raw|loop|fd|md|dm-|sr|scd|st|dcssblk)[0-9]");
|
|
|
96a22b |
- if (!str)
|
|
|
96a22b |
- return 1;
|
|
|
96a22b |
- if (store_ble(conf->blist_devnode, str, ORIGIN_DEFAULT))
|
|
|
96a22b |
- return 1;
|
|
|
96a22b |
-
|
|
|
96a22b |
- str = STRDUP("^(td|hd|vd)[a-z]");
|
|
|
96a22b |
+ str = STRDUP("!^(sd[a-z]|dasd[a-z]|nvme[0-9])");
|
|
|
96a22b |
if (!str)
|
|
|
96a22b |
return 1;
|
|
|
96a22b |
if (store_ble(conf->blist_devnode, str, ORIGIN_DEFAULT))
|
|
|
96a22b |
diff --git a/libmultipath/blacklist.h b/libmultipath/blacklist.h
|
|
|
96a22b |
index 2d721f60..4305857d 100644
|
|
|
96a22b |
--- a/libmultipath/blacklist.h
|
|
|
96a22b |
+++ b/libmultipath/blacklist.h
|
|
|
96a22b |
@@ -20,6 +20,7 @@
|
|
|
96a22b |
struct blentry {
|
|
|
96a22b |
char * str;
|
|
|
96a22b |
regex_t regex;
|
|
|
96a22b |
+ bool invert;
|
|
|
96a22b |
int origin;
|
|
|
96a22b |
};
|
|
|
96a22b |
|
|
|
96a22b |
@@ -28,6 +29,8 @@ struct blentry_device {
|
|
|
96a22b |
char * product;
|
|
|
96a22b |
regex_t vendor_reg;
|
|
|
96a22b |
regex_t product_reg;
|
|
|
96a22b |
+ bool vendor_invert;
|
|
|
96a22b |
+ bool product_invert;
|
|
|
96a22b |
int origin;
|
|
|
96a22b |
};
|
|
|
96a22b |
|
|
|
96a22b |
diff --git a/multipath/multipath.conf.5 b/multipath/multipath.conf.5
|
|
|
96a22b |
index 3455b1cc..6dc26f10 100644
|
|
|
96a22b |
--- a/multipath/multipath.conf.5
|
|
|
96a22b |
+++ b/multipath/multipath.conf.5
|
|
|
96a22b |
@@ -1248,6 +1248,16 @@ being handled by multipath-tools.
|
|
|
96a22b |
.LP
|
|
|
96a22b |
.
|
|
|
96a22b |
.
|
|
|
96a22b |
+In the \fIblacklist\fR and \fIblacklist_exceptions\fR sections, starting a
|
|
|
96a22b |
+quoted value with an exclamation mark \fB"!"\fR will invert the matching
|
|
|
96a22b |
+of the rest of the regular expression. For instance, \fB"!^sd[a-z]"\fR will
|
|
|
96a22b |
+match all values that do not start with \fB"sd[a-z]"\fR. The exclamation mark
|
|
|
96a22b |
+can be escaped \fB"\\!"\fR to match a literal \fB!\fR at the start of a
|
|
|
96a22b |
+regular expression. \fBNote:\fR The exclamation mark must be inside quotes,
|
|
|
96a22b |
+otherwise it will be treated as starting a comment.
|
|
|
96a22b |
+.LP
|
|
|
96a22b |
+.
|
|
|
96a22b |
+.
|
|
|
96a22b |
The \fIblacklist_exceptions\fR section is used to revert the actions of the
|
|
|
96a22b |
\fIblacklist\fR section. This allows one to selectively include ("whitelist") devices which
|
|
|
96a22b |
would normally be excluded via the \fIblacklist\fR section. A common usage is
|
|
|
96a22b |
@@ -1264,10 +1274,9 @@ unless explicitly stated.
|
|
|
96a22b |
Regular expression matching the device nodes to be excluded/included.
|
|
|
96a22b |
.RS
|
|
|
96a22b |
.PP
|
|
|
96a22b |
-The default \fIblacklist\fR consists of the regular expressions
|
|
|
96a22b |
-"^(ram|zram|raw|loop|fd|md|dm-|sr|scd|st|dcssblk)[0-9]" and
|
|
|
96a22b |
-"^(td|hd|vd)[a-z]". This causes virtual devices, non-disk devices, and some other
|
|
|
96a22b |
-device types to be excluded from multipath handling by default.
|
|
|
96a22b |
+The default \fIblacklist\fR consists of the regular expression
|
|
|
96a22b |
+\fB"!^(sd[a-z]|dasd[a-z]|nvme[0-9])"\fR. This causes all device types other
|
|
|
96a22b |
+than scsi, dasd, and nvme to be excluded from multipath handling by default.
|
|
|
96a22b |
.RE
|
|
|
96a22b |
.TP
|
|
|
96a22b |
.B wwid
|
|
|
96a22b |
diff --git a/tests/blacklist.c b/tests/blacklist.c
|
|
|
96a22b |
index cc8a9a4a..d20e97af 100644
|
|
|
96a22b |
--- a/tests/blacklist.c
|
|
|
96a22b |
+++ b/tests/blacklist.c
|
|
|
96a22b |
@@ -60,20 +60,46 @@ __wrap_udev_list_entry_get_name(struct udev_list_entry *list_entry)
|
|
|
96a22b |
return *(const char **)list_entry;
|
|
|
96a22b |
}
|
|
|
96a22b |
|
|
|
96a22b |
+vector elist_property_default;
|
|
|
96a22b |
+vector blist_devnode_default;
|
|
|
96a22b |
vector blist_devnode_sdb;
|
|
|
96a22b |
+vector blist_devnode_sdb_inv;
|
|
|
96a22b |
vector blist_all;
|
|
|
96a22b |
vector blist_device_foo_bar;
|
|
|
96a22b |
+vector blist_device_foo_inv_bar;
|
|
|
96a22b |
+vector blist_device_foo_bar_inv;
|
|
|
96a22b |
vector blist_device_all;
|
|
|
96a22b |
vector blist_wwid_xyzzy;
|
|
|
96a22b |
+vector blist_wwid_xyzzy_inv;
|
|
|
96a22b |
vector blist_protocol_fcp;
|
|
|
96a22b |
+vector blist_protocol_fcp_inv;
|
|
|
96a22b |
vector blist_property_wwn;
|
|
|
96a22b |
+vector blist_property_wwn_inv;
|
|
|
96a22b |
|
|
|
96a22b |
static int setup(void **state)
|
|
|
96a22b |
{
|
|
|
96a22b |
+ struct config conf;
|
|
|
96a22b |
+
|
|
|
96a22b |
+ memset(&conf, 0, sizeof(conf));
|
|
|
96a22b |
+ conf.blist_devnode = vector_alloc();
|
|
|
96a22b |
+ if (!conf.blist_devnode)
|
|
|
96a22b |
+ return -1;
|
|
|
96a22b |
+ conf.elist_property = vector_alloc();
|
|
|
96a22b |
+ if (!conf.elist_property)
|
|
|
96a22b |
+ return -1;
|
|
|
96a22b |
+ if (setup_default_blist(&conf) != 0)
|
|
|
96a22b |
+ return -1;
|
|
|
96a22b |
+ elist_property_default = conf.elist_property;
|
|
|
96a22b |
+ blist_devnode_default = conf.blist_devnode;
|
|
|
96a22b |
+
|
|
|
96a22b |
blist_devnode_sdb = vector_alloc();
|
|
|
96a22b |
if (!blist_devnode_sdb ||
|
|
|
96a22b |
store_ble(blist_devnode_sdb, strdup("sdb"), ORIGIN_CONFIG))
|
|
|
96a22b |
return -1;
|
|
|
96a22b |
+ blist_devnode_sdb_inv = vector_alloc();
|
|
|
96a22b |
+ if (!blist_devnode_sdb_inv ||
|
|
|
96a22b |
+ store_ble(blist_devnode_sdb_inv, strdup("!sdb"), ORIGIN_CONFIG))
|
|
|
96a22b |
+ return -1;
|
|
|
96a22b |
|
|
|
96a22b |
blist_all = vector_alloc();
|
|
|
96a22b |
if (!blist_all || store_ble(blist_all, strdup(".*"), ORIGIN_CONFIG))
|
|
|
96a22b |
@@ -84,6 +110,18 @@ static int setup(void **state)
|
|
|
96a22b |
set_ble_device(blist_device_foo_bar, strdup("foo"), strdup("bar"),
|
|
|
96a22b |
ORIGIN_CONFIG))
|
|
|
96a22b |
return -1;
|
|
|
96a22b |
+ blist_device_foo_inv_bar = vector_alloc();
|
|
|
96a22b |
+ if (!blist_device_foo_inv_bar ||
|
|
|
96a22b |
+ alloc_ble_device(blist_device_foo_inv_bar) ||
|
|
|
96a22b |
+ set_ble_device(blist_device_foo_inv_bar, strdup("!foo"),
|
|
|
96a22b |
+ strdup("bar"), ORIGIN_CONFIG))
|
|
|
96a22b |
+ return -1;
|
|
|
96a22b |
+ blist_device_foo_bar_inv = vector_alloc();
|
|
|
96a22b |
+ if (!blist_device_foo_bar_inv ||
|
|
|
96a22b |
+ alloc_ble_device(blist_device_foo_bar_inv) ||
|
|
|
96a22b |
+ set_ble_device(blist_device_foo_bar_inv, strdup("foo"),
|
|
|
96a22b |
+ strdup("!bar"), ORIGIN_CONFIG))
|
|
|
96a22b |
+ return -1;
|
|
|
96a22b |
|
|
|
96a22b |
blist_device_all = vector_alloc();
|
|
|
96a22b |
if (!blist_device_all || alloc_ble_device(blist_device_all) ||
|
|
|
96a22b |
@@ -95,29 +133,50 @@ static int setup(void **state)
|
|
|
96a22b |
if (!blist_wwid_xyzzy ||
|
|
|
96a22b |
store_ble(blist_wwid_xyzzy, strdup("xyzzy"), ORIGIN_CONFIG))
|
|
|
96a22b |
return -1;
|
|
|
96a22b |
+ blist_wwid_xyzzy_inv = vector_alloc();
|
|
|
96a22b |
+ if (!blist_wwid_xyzzy_inv ||
|
|
|
96a22b |
+ store_ble(blist_wwid_xyzzy_inv, strdup("!xyzzy"), ORIGIN_CONFIG))
|
|
|
96a22b |
+ return -1;
|
|
|
96a22b |
|
|
|
96a22b |
blist_protocol_fcp = vector_alloc();
|
|
|
96a22b |
if (!blist_protocol_fcp ||
|
|
|
96a22b |
store_ble(blist_protocol_fcp, strdup("scsi:fcp"), ORIGIN_CONFIG))
|
|
|
96a22b |
return -1;
|
|
|
96a22b |
+ blist_protocol_fcp_inv = vector_alloc();
|
|
|
96a22b |
+ if (!blist_protocol_fcp_inv ||
|
|
|
96a22b |
+ store_ble(blist_protocol_fcp_inv, strdup("!scsi:fcp"),
|
|
|
96a22b |
+ ORIGIN_CONFIG))
|
|
|
96a22b |
+ return -1;
|
|
|
96a22b |
|
|
|
96a22b |
blist_property_wwn = vector_alloc();
|
|
|
96a22b |
if (!blist_property_wwn ||
|
|
|
96a22b |
store_ble(blist_property_wwn, strdup("ID_WWN"), ORIGIN_CONFIG))
|
|
|
96a22b |
return -1;
|
|
|
96a22b |
+ blist_property_wwn_inv = vector_alloc();
|
|
|
96a22b |
+ if (!blist_property_wwn_inv ||
|
|
|
96a22b |
+ store_ble(blist_property_wwn_inv, strdup("!ID_WWN"), ORIGIN_CONFIG))
|
|
|
96a22b |
+ return -1;
|
|
|
96a22b |
|
|
|
96a22b |
return 0;
|
|
|
96a22b |
}
|
|
|
96a22b |
|
|
|
96a22b |
static int teardown(void **state)
|
|
|
96a22b |
{
|
|
|
96a22b |
+ free_blacklist(elist_property_default);
|
|
|
96a22b |
+ free_blacklist(blist_devnode_default);
|
|
|
96a22b |
free_blacklist(blist_devnode_sdb);
|
|
|
96a22b |
+ free_blacklist(blist_devnode_sdb_inv);
|
|
|
96a22b |
free_blacklist(blist_all);
|
|
|
96a22b |
free_blacklist_device(blist_device_foo_bar);
|
|
|
96a22b |
+ free_blacklist_device(blist_device_foo_inv_bar);
|
|
|
96a22b |
+ free_blacklist_device(blist_device_foo_bar_inv);
|
|
|
96a22b |
free_blacklist_device(blist_device_all);
|
|
|
96a22b |
free_blacklist(blist_wwid_xyzzy);
|
|
|
96a22b |
+ free_blacklist(blist_wwid_xyzzy_inv);
|
|
|
96a22b |
free_blacklist(blist_protocol_fcp);
|
|
|
96a22b |
+ free_blacklist(blist_protocol_fcp_inv);
|
|
|
96a22b |
free_blacklist(blist_property_wwn);
|
|
|
96a22b |
+ free_blacklist(blist_property_wwn_inv);
|
|
|
96a22b |
return 0;
|
|
|
96a22b |
}
|
|
|
96a22b |
|
|
|
96a22b |
@@ -141,6 +200,11 @@ static void test_devnode_blacklist(void **state)
|
|
|
96a22b |
expect_condlog(3, "sdb: device node name blacklisted\n");
|
|
|
96a22b |
assert_int_equal(filter_devnode(blist_devnode_sdb, NULL, "sdb"),
|
|
|
96a22b |
MATCH_DEVNODE_BLIST);
|
|
|
96a22b |
+ assert_int_equal(filter_devnode(blist_devnode_sdb_inv, NULL, "sdb"),
|
|
|
96a22b |
+ MATCH_NOTHING);
|
|
|
96a22b |
+ expect_condlog(3, "sdc: device node name blacklisted\n");
|
|
|
96a22b |
+ assert_int_equal(filter_devnode(blist_devnode_sdb_inv, NULL, "sdc"),
|
|
|
96a22b |
+ MATCH_DEVNODE_BLIST);
|
|
|
96a22b |
}
|
|
|
96a22b |
|
|
|
96a22b |
static void test_devnode_whitelist(void **state)
|
|
|
96a22b |
@@ -159,12 +223,39 @@ static void test_devnode_missing(void **state)
|
|
|
96a22b |
MATCH_NOTHING);
|
|
|
96a22b |
}
|
|
|
96a22b |
|
|
|
96a22b |
+static void test_devnode_default(void **state)
|
|
|
96a22b |
+{
|
|
|
96a22b |
+ assert_int_equal(filter_devnode(blist_devnode_default, NULL, "sdaa"),
|
|
|
96a22b |
+ MATCH_NOTHING);
|
|
|
96a22b |
+ assert_int_equal(filter_devnode(blist_devnode_default, NULL, "nvme0n1"),
|
|
|
96a22b |
+ MATCH_NOTHING);
|
|
|
96a22b |
+ assert_int_equal(filter_devnode(blist_devnode_default, NULL, "dasda"),
|
|
|
96a22b |
+ MATCH_NOTHING);
|
|
|
96a22b |
+ expect_condlog(3, "hda: device node name blacklisted\n");
|
|
|
96a22b |
+ assert_int_equal(filter_devnode(blist_devnode_default, NULL, "hda"),
|
|
|
96a22b |
+ MATCH_DEVNODE_BLIST);
|
|
|
96a22b |
+}
|
|
|
96a22b |
+
|
|
|
96a22b |
static void test_device_blacklist(void **state)
|
|
|
96a22b |
{
|
|
|
96a22b |
expect_condlog(3, "sdb: (foo:bar) vendor/product blacklisted\n");
|
|
|
96a22b |
assert_int_equal(filter_device(blist_device_foo_bar, NULL, "foo",
|
|
|
96a22b |
"bar", "sdb"),
|
|
|
96a22b |
MATCH_DEVICE_BLIST);
|
|
|
96a22b |
+ assert_int_equal(filter_device(blist_device_foo_inv_bar, NULL, "foo",
|
|
|
96a22b |
+ "bar", "sdb"),
|
|
|
96a22b |
+ MATCH_NOTHING);
|
|
|
96a22b |
+ assert_int_equal(filter_device(blist_device_foo_bar_inv, NULL, "foo",
|
|
|
96a22b |
+ "bar", "sdb"),
|
|
|
96a22b |
+ MATCH_NOTHING);
|
|
|
96a22b |
+ expect_condlog(3, "sdb: (baz:bar) vendor/product blacklisted\n");
|
|
|
96a22b |
+ assert_int_equal(filter_device(blist_device_foo_inv_bar, NULL, "baz",
|
|
|
96a22b |
+ "bar", "sdb"),
|
|
|
96a22b |
+ MATCH_DEVICE_BLIST);
|
|
|
96a22b |
+ expect_condlog(3, "sdb: (foo:baz) vendor/product blacklisted\n");
|
|
|
96a22b |
+ assert_int_equal(filter_device(blist_device_foo_bar_inv, NULL, "foo",
|
|
|
96a22b |
+ "baz", "sdb"),
|
|
|
96a22b |
+ MATCH_DEVICE_BLIST);
|
|
|
96a22b |
}
|
|
|
96a22b |
|
|
|
96a22b |
static void test_device_whitelist(void **state)
|
|
|
96a22b |
@@ -191,6 +282,11 @@ static void test_wwid_blacklist(void **state)
|
|
|
96a22b |
expect_condlog(3, "sdb: wwid xyzzy blacklisted\n");
|
|
|
96a22b |
assert_int_equal(filter_wwid(blist_wwid_xyzzy, NULL, "xyzzy", "sdb"),
|
|
|
96a22b |
MATCH_WWID_BLIST);
|
|
|
96a22b |
+ assert_int_equal(filter_wwid(blist_wwid_xyzzy_inv, NULL, "xyzzy",
|
|
|
96a22b |
+ "sdb"), MATCH_NOTHING);
|
|
|
96a22b |
+ expect_condlog(3, "sdb: wwid plugh blacklisted\n");
|
|
|
96a22b |
+ assert_int_equal(filter_wwid(blist_wwid_xyzzy_inv, NULL, "plugh",
|
|
|
96a22b |
+ "sdb"), MATCH_WWID_BLIST);
|
|
|
96a22b |
}
|
|
|
96a22b |
|
|
|
96a22b |
static void test_wwid_whitelist(void **state)
|
|
|
96a22b |
@@ -218,6 +314,12 @@ static void test_protocol_blacklist(void **state)
|
|
|
96a22b |
expect_condlog(3, "sdb: protocol scsi:fcp blacklisted\n");
|
|
|
96a22b |
assert_int_equal(filter_protocol(blist_protocol_fcp, NULL, &pp),
|
|
|
96a22b |
MATCH_PROTOCOL_BLIST);
|
|
|
96a22b |
+ assert_int_equal(filter_protocol(blist_protocol_fcp_inv, NULL, &pp),
|
|
|
96a22b |
+ MATCH_NOTHING);
|
|
|
96a22b |
+ pp.sg_id.proto_id = SCSI_PROTOCOL_ATA;
|
|
|
96a22b |
+ expect_condlog(3, "sdb: protocol scsi:ata blacklisted\n");
|
|
|
96a22b |
+ assert_int_equal(filter_protocol(blist_protocol_fcp_inv, NULL, &pp),
|
|
|
96a22b |
+ MATCH_PROTOCOL_BLIST);
|
|
|
96a22b |
}
|
|
|
96a22b |
|
|
|
96a22b |
static void test_protocol_whitelist(void **state)
|
|
|
96a22b |
@@ -245,10 +347,17 @@ static void test_protocol_missing(void **state)
|
|
|
96a22b |
static void test_property_blacklist(void **state)
|
|
|
96a22b |
{
|
|
|
96a22b |
static struct udev_device udev = { "sdb", { "ID_FOO", "ID_WWN", "ID_BAR", NULL } };
|
|
|
96a22b |
+ static struct udev_device udev_inv = { "sdb", { "ID_WWN", NULL } };
|
|
|
96a22b |
conf.blist_property = blist_property_wwn;
|
|
|
96a22b |
expect_condlog(3, "sdb: udev property ID_WWN blacklisted\n");
|
|
|
96a22b |
assert_int_equal(filter_property(&conf, &udev, 3, "ID_SERIAL"),
|
|
|
96a22b |
MATCH_PROPERTY_BLIST);
|
|
|
96a22b |
+ conf.blist_property = blist_property_wwn_inv;
|
|
|
96a22b |
+ expect_condlog(3, "sdb: udev property ID_FOO blacklisted\n");
|
|
|
96a22b |
+ assert_int_equal(filter_property(&conf, &udev, 3, "ID_SERIAL"),
|
|
|
96a22b |
+ MATCH_PROPERTY_BLIST);
|
|
|
96a22b |
+ assert_int_equal(filter_property(&conf, &udev_inv, 3, "ID_SERIAL"),
|
|
|
96a22b |
+ MATCH_NOTHING);
|
|
|
96a22b |
}
|
|
|
96a22b |
|
|
|
96a22b |
/* the property check works different in that you check all the property
|
|
|
96a22b |
@@ -482,6 +591,7 @@ int test_blacklist(void)
|
|
|
96a22b |
cmocka_unit_test(test_devnode_blacklist),
|
|
|
96a22b |
cmocka_unit_test(test_devnode_whitelist),
|
|
|
96a22b |
cmocka_unit_test(test_devnode_missing),
|
|
|
96a22b |
+ cmocka_unit_test(test_devnode_default),
|
|
|
96a22b |
cmocka_unit_test(test_device_blacklist),
|
|
|
96a22b |
cmocka_unit_test(test_device_whitelist),
|
|
|
96a22b |
cmocka_unit_test(test_device_missing),
|
|
|
96a22b |
diff --git a/tests/test-lib.c b/tests/test-lib.c
|
|
|
96a22b |
index 59275163..08ff2d8d 100644
|
|
|
96a22b |
--- a/tests/test-lib.c
|
|
|
96a22b |
+++ b/tests/test-lib.c
|
|
|
96a22b |
@@ -15,7 +15,7 @@
|
|
|
96a22b |
#include "test-lib.h"
|
|
|
96a22b |
|
|
|
96a22b |
const int default_mask = (DI_SYSFS|DI_BLACKLIST|DI_WWID|DI_CHECKER|DI_PRIO);
|
|
|
96a22b |
-const char default_devnode[] = "sdTEST";
|
|
|
96a22b |
+const char default_devnode[] = "sdxTEST";
|
|
|
96a22b |
const char default_wwid[] = "TEST-WWID";
|
|
|
96a22b |
/* default_wwid should be a substring of default_wwid_1! */
|
|
|
96a22b |
const char default_wwid_1[] = "TEST-WWID-1";
|
|
|
96a22b |
--
|
|
|
96a22b |
2.17.2
|
|
|
96a22b |
|