Skip to content

Commit

Permalink
libmultipath: ignore nvme devices if nvme native multipath is enabled
Browse files Browse the repository at this point in the history
If the nvme native multipath driver is enabled, blacklist nvme devices
for dm-multipath by default. This is particularly useful with
"find_multipaths greedy".

Signed-off-by: Martin Wilck <[email protected]>
  • Loading branch information
mwilck committed Jul 3, 2023
1 parent 826cfe6 commit a5414a6
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 6 deletions.
35 changes: 32 additions & 3 deletions libmultipath/blacklist.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
* Copyright (c) 2004, 2005 Christophe Varoqui
*/
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <libudev.h>

#include "checkers.h"
Expand Down Expand Up @@ -191,16 +193,43 @@ find_blacklist_device (const struct _vector *blist, const char *vendor,
return 0;
}

/*
* Test if nvme native multipath is enabled. If the sysfs file can't
* be accessed, multipath is either disabled at compile time, or no
* nvme driver is loaded at all. Thus treat errors as "no".
*/
static bool nvme_multipath_enabled(void)
{
static const char fn[] = "/sys/module/nvme_core/parameters/multipath";
int fd, len;
char buf[2];

fd = open(fn, O_RDONLY);
if (fd == -1)
return false;

len = read(fd, buf, sizeof(buf));
close(fd);

return (len >= 1 && buf[0] == 'Y');
}

int
setup_default_blist (struct config * conf)
{
struct blentry * ble;
struct hwentry *hwe;
int i;

if (store_ble(conf->blist_devnode, "!^(sd[a-z]|dasd[a-z]|nvme[0-9])", ORIGIN_DEFAULT))
return 1;

if (nvme_multipath_enabled()) {
if (store_ble(conf->blist_devnode, "!^(sd[a-z]|dasd[a-z])",
ORIGIN_DEFAULT))
return 1;
} else {
if (store_ble(conf->blist_devnode, "!^(sd[a-z]|dasd[a-z]|nvme[0-9])",
ORIGIN_DEFAULT))
return 1;
}
if (store_ble(conf->elist_property, "(SCSI_IDENT_|ID_WWN)", ORIGIN_DEFAULT))
return 1;

Expand Down
1 change: 0 additions & 1 deletion tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ hwtable-test_OBJDEPS := $(multipathdir)/discovery.o $(multipathdir)/blacklist.o
$(multipathdir)/structs.o $(multipathdir)/propsel.o
hwtable-test_LIBDEPS := -ludev -lpthread -ldl
blacklist-test_TESTDEPS := test-log.o
blacklist-test_OBJDEPS := $(multipathdir)/blacklist.o
blacklist-test_LIBDEPS := -ludev
vpd-test_OBJDEPS := $(multipathdir)/discovery.o
vpd-test_LIBDEPS := -ludev -lpthread -ldl
Expand Down
13 changes: 11 additions & 2 deletions tests/blacklist.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include "test-log.h"
#include "debug.h"

#include "../libmultipath/blacklist.c"

struct udev_device {
const char *sysname;
char *property_list[];
Expand Down Expand Up @@ -224,8 +226,15 @@ static void test_devnode_default(void **state)
{
assert_int_equal(filter_devnode(blist_devnode_default, NULL, "sdaa"),
MATCH_NOTHING);
assert_int_equal(filter_devnode(blist_devnode_default, NULL, "nvme0n1"),
MATCH_NOTHING);
if (nvme_multipath_enabled()) {
expect_condlog(3, "nvme0n1: device node name blacklisted\n");
assert_int_equal(filter_devnode(blist_devnode_default, NULL,
"nvme0n1"),
MATCH_DEVNODE_BLIST);
} else
assert_int_equal(filter_devnode(blist_devnode_default, NULL,
"nvme0n1"),
MATCH_NOTHING);
assert_int_equal(filter_devnode(blist_devnode_default, NULL, "dasda"),
MATCH_NOTHING);
expect_condlog(3, "hda: device node name blacklisted\n");
Expand Down

0 comments on commit a5414a6

Please sign in to comment.