dm-devel.redhat.com archive mirror
 help / color / mirror / Atom feed
From: Benjamin Marzinski <bmarzins@redhat.com>
To: mwilck@suse.com
Cc: dm-devel@redhat.com
Subject: Re: [dm-devel] [PATCH v2] libmultipath: ignore nvme devices if nvme native multipath is enabled
Date: Thu, 6 Jul 2023 11:06:34 -0500	[thread overview]
Message-ID: <20230706160634.GI7412@octiron.msp.redhat.com> (raw)
In-Reply-To: <20230703164021.24843-1-mwilck@suse.com>

On Mon, Jul 03, 2023 at 06:40:21PM +0200, mwilck@suse.com wrote:
> From: Martin Wilck <mwilck@suse.com>
> 
> 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 <mwilck@suse.com>
Reviewed-by: Benjamin Marzinski <bmarzins@redhat.com>
> ---
>  libmultipath/blacklist.c | 35 ++++++++++++++++++++++++++++++++---
>  tests/Makefile           |  1 -
>  tests/blacklist.c        | 13 +++++++++++--
>  3 files changed, 43 insertions(+), 6 deletions(-)
> 
> diff --git a/libmultipath/blacklist.c b/libmultipath/blacklist.c
> index 8d15d2e..75100b2 100644
> --- a/libmultipath/blacklist.c
> +++ b/libmultipath/blacklist.c
> @@ -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"
> @@ -191,6 +193,27 @@ 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)
>  {
> @@ -198,9 +221,15 @@ setup_default_blist (struct config * conf)
>  	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;
>  
> diff --git a/tests/Makefile b/tests/Makefile
> index 83edc2f..c777d07 100644
> --- a/tests/Makefile
> +++ b/tests/Makefile
> @@ -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
> diff --git a/tests/blacklist.c b/tests/blacklist.c
> index 882aa3a..ba8dfd0 100644
> --- a/tests/blacklist.c
> +++ b/tests/blacklist.c
> @@ -24,6 +24,8 @@
>  #include "test-log.h"
>  #include "debug.h"
>  
> +#include "../libmultipath/blacklist.c"
> +
>  struct udev_device {
>  	const char *sysname;
>  	char *property_list[];
> @@ -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");
> -- 
> 2.41.0
--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


      reply	other threads:[~2023-07-06 16:06 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-03 16:40 [dm-devel] [PATCH v2] libmultipath: ignore nvme devices if nvme native multipath is enabled mwilck
2023-07-06 16:06 ` Benjamin Marzinski [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230706160634.GI7412@octiron.msp.redhat.com \
    --to=bmarzins@redhat.com \
    --cc=dm-devel@redhat.com \
    --cc=mwilck@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).