Skip to contentSkip to conversation

mutipath: handle nvme:tcp paths better

PATCH In review Benjamin Marzinski 2 participants 18 messages Oct 7, 2022 – Oct 21, 2022 Device mapper

lore
Share & tools
lore

Benjamin Marzinski

author maintainer
#0 lore raw

cover mutipath: handle nvme:tcp paths better

nvme:tcp devices set BLK_MQ_F_BLOCKING (they are the only block devices which multipath supports that do so), meaning that block_mq expects that they can block at certain points while servicing a request. However, due to the way device-mapper sets up its queue, it is not able to set BLK_MQ_F_BLOCKING when it includes paths that set this flag. Patches were written to address this issue but they were rejected upstream

https://lore.kernel.org/linux-block/YcH%[email protected]/T/#t

The proposed solution was to have multipath use the bio queue_mode for multipath devices that include nvme:tcp paths.

Multipathd currently doesn't handle queue_mode as well as it could. Once a multipath device is created, queue_mode cannot be changed, but multipath doesn't enforce this. This patchset improves multipath's handling of the queue_mode feature, and then makes sure that if a multipath device includes a nvme:tcp path, it will have queue_mode set to bio.

Benjamin Marzinski (8):
libmultipath: cleanup remove_feature
libmultipath: cleanup add_feature
multipath tests: tests for adding and removing features
libmultipath: fix queue_mode feature handling multipath tests: tests for reconcile_features_with_queue_mode
libmultipath: prepare proto_id for use by non-scsi devivces
libmultipath: get nvme path transport protocol
libmultipath: enforce queue_mode bio for nmve:tcp paths

 libmultipath/configure.c   |  28 +-
 libmultipath/discovery.c   |  31 ++-
 libmultipath/dmparser.c    |   2 +
 libmultipath/print.c       |   6 +-
 libmultipath/propsel.c     |  55 ++++
 libmultipath/structs.c     | 155 +++++------
 libmultipath/structs.h     |  44 ++-
 libmultipath/structs_vec.c |   7 +
 multipath/multipath.conf.5 |  17 +-
 multipathd/fpin_handlers.c |   2 +-
 tests/Makefile             |   4 +-
 tests/features.c           | 549 +++++++++++++++++++++++++++++++++++++
 12 files changed, 784 insertions(+), 116 deletions(-)
 create mode 100644 tests/features.c
Signature · 6 lines
2.17.2

--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel
author maintainer
#1 lore raw

PATCH 1/8 libmultipath: cleanup remove_feature

remove_feature() didn't correctly handle feature strings that used whitespace other than spaces, which the kernel allows. It also didn't check if the feature string to be removed was part of a larger feature token. Finally, it did a lot of unnecessary work. By failing if the feature string to be removed contains leading or trailing whitespace, the function can be significanly simplified.

---
 libmultipath/structs.c | 82 +++++++++++++++---------------------------
 1 file changed, 29 insertions(+), 53 deletions(-)
libmultipath/structs.c +29 -53
index 49621cb3..1f9945e0 100644
@@ -6,6 +6,7 @@
 #include <unistd.h>
 #include <libdevmapper.h>
 #include <libudev.h>
+#include <ctype.h>
 
 #include "checkers.h"
 #include "vector.h"
@@ -663,7 +664,7 @@ int add_feature(char **f, const char *n)
 
 int remove_feature(char **f, const char *o)
 {
-	int c = 0, d, l;
+	int c = 0, d;
 	char *e, *p, *n;
 	const char *q;
 
@@ -674,33 +675,35 @@ int remove_feature(char **f, const char *o)
 	if (!o || *o == '\0')
 		return 0;
 
-	/* Check if not present */
-	if (!strstr(*f, o))
+	d = strlen(o);
+	if (isspace(*o) || isspace(*(o + d - 1))) {
+		condlog(0, "internal error: feature \"%s\" has leading or trailing spaces", o);
+		return 1;
+	}
+
+	/* Check if present and not part of a larger feature token*/
+	p = *f + 1; /* the size must be at the start of the features string */
+	while ((p = strstr(p, o)) != NULL) {
+		if (isspace(*(p - 1)) &&
+		    (isspace(*(p + d)) || *(p + d) == '\0'))
+			break;
+		p += d;
+	}
+	if (!p)
 		return 0;
 
 	/* Get feature count */
 	c = strtoul(*f, &e, 10);
-	if (*f == e)
-		/* parse error */
+	if (*f == e || !isspace(*e)) {
+		condlog(0, "parse error in feature string \"%s\"", *f);
 		return 1;
-
-	/* Normalize features */
-	while (*o == ' ') {
-		o++;
 	}
-	/* Just spaces, return */
-	if (*o == '\0')
-		return 0;
-	q = o + strlen(o);
-	while (*q == ' ')
-		q--;
-	d = (int)(q - o);
 
 	/* Update feature count */
 	c--;
 	q = o;
-	while (q[0] != '\0') {
-		if (q[0] == ' ' && q[1] != ' ' && q[1] != '\0')
+	while (*q != '\0') {
+		if (isspace(*q) && !isspace(*(q + 1)) && *(q + 1) != '\0')
 			c--;
 		q++;
 	}
@@ -714,15 +717,8 @@ int remove_feature(char **f, const char *o)
 		goto out;
 	}
 
-	/* Search feature to be removed */
-	e = strstr(*f, o);
-	if (!e)
-		/* Not found, return */
-		return 0;
-
 	/* Update feature count space */
-	l = strlen(*f) - d;
-	n =  malloc(l + 1);
+	n =  malloc(strlen(*f) - d + 1);
 	if (!n)
 		return 1;
 
@@ -732,36 +728,16 @@ int remove_feature(char **f, const char *o)
 	 * Copy existing features up to the feature
 	 * about to be removed
 	 */
-	p = strchr(*f, ' ');
-	if (!p) {
-		/* Internal error, feature string inconsistent */
-		free(n);
-		return 1;
-	}
-	while (*p == ' ')
-		p++;
-	p--;
-	if (e != p) {
-		do {
-			e--;
-			d++;
-		} while (*e == ' ');
-		e++; d--;
-		strncat(n, p, (size_t)(e - p));
-		p += (size_t)(e - p);
-	}
+	strncat(n, e, (size_t)(p - e));
 	/* Skip feature to be removed */
 	p += d;
-
 	/* Copy remaining features */
-	if (strlen(p)) {
-		while (*p == ' ')
-			p++;
-		if (strlen(p)) {
-			p--;
-			strcat(n, p);
-		}
-	}
+	while (isspace(*p))
+		p++;
+	if (*p != '\0')
+		strcat(n, p);
+	else
+		strchop(n);
 
 out:
 	free(*f);
Signature · 6 lines
2.17.2

--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel
Reviewed-by on v1 1/8
#2 lore raw

Re: [dm-devel] [PATCH 1/8] libmultipath: cleanup remove_feature

Quoted 9 lines · Benjamin Marzinski

remove_feature() didn't correctly handle feature strings that used whitespace other than spaces, which the kernel allows. It also didn't check if the feature string to be removed was part of a larger feature
token. Finally, it did a lot of unnecessary work. By failing if the feature string to be removed contains leading or trailing whitespace, the function can be significanly simplified.

This is part of the code that always makes me think we should clean it up more thoroughly. Therefore I've added some remarks below.

As you've started working on this, perhaps you want to follow up? If not, fine with me for now.

Martin

Quoted 18 lines

---
 libmultipath/structs.c | 82 +++++++++++++++------------------------- --

 1 file changed, 29 insertions(+), 53 deletions(-)
libmultipath/structs.c +1 -0
index 49621cb3..1f9945e0 100644
@@ -6,6 +6,7 @@
  #include <unistd.h>
  #include <libdevmapper.h>
  #include <libudev.h>
+#include <ctype.h>


 #include "checkers.h"
 #include "vector.h"

libmultipath/structs.c +0 -0
@@ -663,7 +664,7 @@ int add_feature(char **f, const char *n)
Quoted 7 lines


 int remove_feature(char **f, const char *o)
 {
-       int c = 0, d, l;
+       int c = 0, d;
        char *e, *p, *n;
        const char *q;

I see you sticked to the conventions ;-) but the variable naming in this function could be improved.

Quoted 64 lines

libmultipath/structs.c +0 -0
@@ -674,33 +675,35 @@ int remove_feature(char **f, const char *o)
         if (!o || *o == '\0')
                 return 0;


-       /* Check if not present */
-       if (!strstr(*f, o))
+       d = strlen(o);
+       if (isspace(*o) || isspace(*(o + d - 1))) {
+               condlog(0, "internal error: feature \"%s\" has leading or trailing spaces", o);
+               return 1;
+       }
+
+       /* Check if present and not part of a larger feature token*/ +       p = *f + 1; /* the size must be at the start of the features string */
+       while ((p = strstr(p, o)) != NULL) {
+               if (isspace(*(p - 1)) &&
+                   (isspace(*(p + d)) || *(p + d) == '\0')) +                       break;
+               p += d;
+       }
+       if (!p)
                return 0;

        /* Get feature count */
        c = strtoul(*f, &e, 10);
-       if (*f == e)
-               /* parse error */
+       if (*f == e || !isspace(*e)) {
+               condlog(0, "parse error in feature string \"%s\"", *f);
                return 1;
-
-       /* Normalize features */
-       while (*o == ' ') {
-               o++;
        }
-       /* Just spaces, return */
-       if (*o == '\0')
-               return 0;
-       q = o + strlen(o);
-       while (*q == ' ')
-               q--;
-       d = (int)(q - o);

        /* Update feature count */
        c--;
        q = o;
-       while (q[0] != '\0') {
-               if (q[0] == ' ' && q[1] != ' ' && q[1] != '\0') +       while (*q != '\0') {
+               if (isspace(*q) && !isspace(*(q + 1)) && *(q + 1) != '\0')
                        c--;
                q++;
        }

libmultipath/structs.c +0 -0
@@ -714,15 +717,8 @@ int remove_feature(char **f, const char *o)
                 goto out;
         }


-       /* Search feature to be removed */
-       e = strstr(*f, o);

Quoted 8 lines

-       if (!e)
-               /* Not found, return */
-               return 0;
-
        /* Update feature count space */
-       l = strlen(*f) - d;
-       n =  malloc(l + 1);
+       n =  malloc(strlen(*f) - d + 1);

Given that this function never increases the length of the feature string, we might as well implement it without the allocating a new string.

Quoted 44 lines

        if (!n)
                return 1;

libmultipath/structs.c +7 -27
@@ -732,36 +728,16 @@ int remove_feature(char **f, const char *o)
          * Copy existing features up to the feature
          * about to be removed
          */
-       p = strchr(*f, ' ');
-       if (!p) {
-               /* Internal error, feature string inconsistent */
-               free(n);
-               return 1;
-       }
-       while (*p == ' ')
-               p++;
-       p--;
-       if (e != p) {
-               do {
-                       e--;
-                       d++;
-               } while (*e == ' ');
-               e++; d--;
-               strncat(n, p, (size_t)(e - p));
-               p += (size_t)(e - p);
-       }
+       strncat(n, e, (size_t)(p - e));
         /* Skip feature to be removed */
         p += d;
-
         /* Copy remaining features */
-       if (strlen(p)) {
-               while (*p == ' ')
-                       p++;
-               if (strlen(p)) {
-                       p--;
-                       strcat(n, p);
-               }
-       }
+       while (isspace(*p))
+               p++;
+       if (*p != '\0')
+               strcat(n, p);
+       else
+               strchop(n);
Quoted 3 lines


 out:
        free(*f);

--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel

author maintainer
#3 lore raw

Re: [dm-devel] [PATCH 1/8] libmultipath: cleanup remove_feature

Quoted 41 lines · Martin Wilck
Quoted 9 lines · Benjamin Marzinski

remove_feature() didn't correctly handle feature strings that used whitespace other than spaces, which the kernel allows. It also didn't check if the feature string to be removed was part of a larger feature
token. Finally, it did a lot of unnecessary work. By failing if the feature string to be removed contains leading or trailing whitespace, the function can be significanly simplified.

This is part of the code that always makes me think we should clean it up more thoroughly. Therefore I've added some remarks below.

As you've started working on this, perhaps you want to follow up? If not, fine with me for now.

Martin

Quoted 20 lines

---
 libmultipath/structs.c | 82 +++++++++++++++------------------------- --

 1 file changed, 29 insertions(+), 53 deletions(-)
libmultipath/structs.c +1 -0
index 49621cb3..1f9945e0 100644
@@ -6,6 +6,7 @@
  #include <unistd.h>
  #include <libdevmapper.h>
  #include <libudev.h>
+#include <ctype.h>


 #include "checkers.h"
 #include "vector.h"

libmultipath/structs.c +0 -0
@@ -663,7 +664,7 @@ int add_feature(char **f, const char *n)


 int remove_feature(char **f, const char *o)

Quoted 8 lines
Quoted 5 lines

 {
-       int c = 0, d, l;
+       int c = 0, d;
        char *e, *p, *n;
        const char *q;

I see you sticked to the conventions ;-) but the variable naming in this function could be improved.

Yeah. I didn't want to while I was chaning things, and then got lazy and didn't do it in a separate patch, but these names certainly make harder to follow the logic of the function. I send a patch that cleans this up.

Quoted 68 lines
Quoted 68 lines

libmultipath/structs.c +0 -0
@@ -674,33 +675,35 @@ int remove_feature(char **f, const char *o)
         if (!o || *o == '\0')
                 return 0;


-       /* Check if not present */
-       if (!strstr(*f, o))
+       d = strlen(o);
+       if (isspace(*o) || isspace(*(o + d - 1))) {
+               condlog(0, "internal error: feature \"%s\" has leading or trailing spaces", o);
+               return 1;
+       }
+
+       /* Check if present and not part of a larger feature token*/ +       p = *f + 1; /* the size must be at the start of the features string */
+       while ((p = strstr(p, o)) != NULL) {
+               if (isspace(*(p - 1)) &&
+                   (isspace(*(p + d)) || *(p + d) == '\0')) +                       break;
+               p += d;
+       }
+       if (!p)
                return 0;

        /* Get feature count */
        c = strtoul(*f, &e, 10);
-       if (*f == e)
-               /* parse error */
+       if (*f == e || !isspace(*e)) {
+               condlog(0, "parse error in feature string \"%s\"", *f);
                return 1;
-
-       /* Normalize features */
-       while (*o == ' ') {
-               o++;
        }
-       /* Just spaces, return */
-       if (*o == '\0')
-               return 0;
-       q = o + strlen(o);
-       while (*q == ' ')
-               q--;
-       d = (int)(q - o);

        /* Update feature count */
        c--;
        q = o;
-       while (q[0] != '\0') {
-               if (q[0] == ' ' && q[1] != ' ' && q[1] != '\0') +       while (*q != '\0') {
+               if (isspace(*q) && !isspace(*(q + 1)) && *(q + 1) != '\0')
                        c--;
                q++;
        }

libmultipath/structs.c +0 -0
@@ -714,15 +717,8 @@ int remove_feature(char **f, const char *o)
                 goto out;
         }


-       /* Search feature to be removed */
-       e = strstr(*f, o);
-       if (!e)
-               /* Not found, return */
-               return 0;
-

Quoted 8 lines
Quoted 4 lines

        /* Update feature count space */
-       l = strlen(*f) - d;
-       n =  malloc(l + 1);
+       n =  malloc(strlen(*f) - d + 1);

Given that this function never increases the length of the feature string, we might as well implement it without the allocating a new string.

A reason to do the malloc is so that we could free the larger chunk of memory afterwards. But it's not like we're talking a significant difference, so I'm fine will removing it for simplicity's sake.

-Ben

Quoted 39 lines
Quoted 39 lines

        if (!n)
                return 1;

libmultipath/structs.c +2 -27
@@ -732,36 +728,16 @@ int remove_feature(char **f, const char *o)
          * Copy existing features up to the feature
          * about to be removed
          */
-       p = strchr(*f, ' ');
-       if (!p) {
-               /* Internal error, feature string inconsistent */
-               free(n);
-               return 1;
-       }
-       while (*p == ' ')
-               p++;
-       p--;
-       if (e != p) {
-               do {
-                       e--;
-                       d++;
-               } while (*e == ' ');
-               e++; d--;
-               strncat(n, p, (size_t)(e - p));
-               p += (size_t)(e - p);
-       }
+       strncat(n, e, (size_t)(p - e));
         /* Skip feature to be removed */
         p += d;
-
         /* Copy remaining features */
-       if (strlen(p)) {
-               while (*p == ' ')
-                       p++;
-               if (strlen(p)) {
-                       p--;
-                       strcat(n, p);
-               }
-       }
+       while (isspace(*p))
Quoted 10 lines
Quoted 8 lines
libmultipath/structs.c +5 -0
+               p++;
+       if (*p != '\0')
+               strcat(n, p);
+       else
+               strchop(n);


 out:
        free(*f);

--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel

author maintainer
#4 lore raw

PATCH 2/8 libmultipath: cleanup add_feature

In reply to Benjamin Marzinski

add_feature() didn't correctly handle feature strings that used whitespace other than spaces, which the kernel allows. It also didn't allow adding features with multiple tokens. When it looked to see if the feature string to be added already existed, it didn't check if the match was part of a larger token. Finally, it did unnecessary work. By using asprintf() to create the string, the function can be signifcantly simplified.

---
 libmultipath/structs.c | 49 +++++++++++++++++++++---------------------
 1 file changed, 24 insertions(+), 25 deletions(-)
libmultipath/structs.c +24 -25
index 1f9945e0..0f16c071 100644
@@ -602,23 +602,33 @@ int add_feature(char **f, const char *n)
 {
 	int c = 0, d, l;
 	char *e, *t;
+	const char *p;
 
 	if (!f)
 		return 1;
 
 	/* Nothing to do */
-	if (!n || *n == '0')
+	if (!n || *n == '\0')
 		return 0;
 
-	if (strchr(n, ' ') != NULL) {
-		condlog(0, "internal error: feature \"%s\" contains spaces", n);
+	l = strlen(n);
+	if (isspace(*n) || isspace(*(n + l - 1))) {
+		condlog(0, "internal error: feature \"%s\" has leading or trailing spaces", n);
 		return 1;
 	}
 
+	p = n;
+	d = 1;
+	while (*p != '\0') {
+		if (isspace(*p) && !isspace(*(p + 1)) && *(p + 1) != '\0')
+			d++;
+		p++;
+	}
+
 	/* default feature is null */
 	if(!*f)
 	{
-		l = asprintf(&t, "1 %s", n);
+		l = asprintf(&t, "%0d %s", d, n);
 		if(l == -1)
 			return 1;
 
@@ -627,35 +637,24 @@ int add_feature(char **f, const char *n)
 	}
 
 	/* Check if feature is already present */
-	if (strstr(*f, n))
-		return 0;
+	e = *f;
+	while ((e = strstr(e, n)) != NULL) {
+		if (isspace(*(e - 1)) &&
+		    (isspace(*(e + l)) || *(e + l) == '\0'))
+			return 0;
+		e += l;
+	}
 
 	/* Get feature count */
 	c = strtoul(*f, &e, 10);
-	if (*f == e || (*e != ' ' && *e != '\0')) {
+	if (*f == e || (!isspace(*e) && *e != '\0')) {
 		condlog(0, "parse error in feature string \"%s\"", *f);
 		return 1;
 	}
-
-	/* Add 1 digit and 1 space */
-	l = strlen(e) + strlen(n) + 2;
-
-	c++;
-	/* Check if we need more digits for feature count */
-	for (d = c; d >= 10; d /= 10)
-		l++;
-
-	t = calloc(1, l + 1);
-	if (!t)
+	c += d;
+	if (asprintf(&t, "%0d%s %s", c, e, n) < 0)
 		return 1;
 
-	/* e: old feature string with leading space, or "" */
-	if (*e == ' ')
-		while (*(e + 1) == ' ')
-			e++;
-
-	snprintf(t, l + 1, "%0d%s %s", c, e, n);
-
 	free(*f);
 	*f = t;
 
Signature · 6 lines
2.17.2

--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel
Reviewed-by on v1 2/8
#5 lore raw

Re: [dm-devel] [PATCH 2/8] libmultipath: cleanup add_feature

Quoted 11 lines · Benjamin Marzinski

add_feature() didn't correctly handle feature strings that used whitespace other than spaces, which the kernel allows. It also didn't allow adding features with multiple tokens. When it looked to see if the
feature string to be added already existed, it didn't check if the match
was part of a larger token. Finally, it did unnecessary work.  By using
asprintf() to create the string, the function can be signifcantly simplified.

Quoted 1 line

The same general remarks apply as for 01/08.

Quoted 10 lines

---
 libmultipath/structs.c | 49 +++++++++++++++++++++------------------- --

 1 file changed, 24 insertions(+), 25 deletions(-)
libmultipath/structs.c +0 -0
index 1f9945e0..0f16c071 100644

libmultipath/structs.c int add_feature(char **f, const char *n) · line 605

Quoted 4 lines
libmultipath/structs.c +1 -0
@@ -602,23 +602,33 @@ int add_feature(char **f, const char *n)
  {
         int c = 0, d, l;
         char *e, *t;
+       const char *p;

Same remark as before about the variable naming.

Quoted 7 lines


        if (!f)
                return 1;

        /* Nothing to do */

-       if (!n || *n == '0')
+       if (!n || *n == '\0')

ouch...

--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel

author maintainer
#6 lore raw

PATCH 3/8 multipath tests: tests for adding and removing features

In reply to Benjamin Marzinski
---
 tests/Makefile   |   2 +-
 tests/features.c | 319 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 320 insertions(+), 1 deletion(-)
 create mode 100644 tests/features.c
tests/Makefile +1 -1
index 109ea75b..ccdfbd15 100644
@@ -16,7 +16,7 @@ CFLAGS += $(BIN_CFLAGS) -Wno-unused-parameter $(W_MISSING_INITIALIZERS)
 LIBDEPS += -L. -L $(mpathutildir) -L$(mpathcmddir) -lmultipath -lmpathutil -lmpathcmd -lcmocka
 
 TESTS := uevent parser util dmevents hwtable blacklist unaligned vpd pgpolicy \
-	 alias directio valid devt mpathvalid strbuf sysfs
+	 alias directio valid devt mpathvalid strbuf sysfs features
 HELPERS := test-lib.o test-log.o
 
 .SILENT: $(TESTS:%=%.o)
tests/features.c new file +319 -0

319 lines not on this page · raw message

Signature · 6 lines
2.17.2

--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel
author maintainer
#7 lore raw

PATCH 4/8 libmultipath: fix queue_mode feature handling

In reply to Benjamin Marzinski

device-mapper is not able to change the queue_mode on a table reload. Make sure that when multipath sets up the map, both on regular reloads and reconfigures, it keeps the queue_mode the same.

---
 libmultipath/configure.c   |  4 +++
 libmultipath/dmparser.c    |  2 ++
 libmultipath/propsel.c     | 55 ++++++++++++++++++++++++++++++++++++++
 libmultipath/structs.h     |  7 +++++
 multipath/multipath.conf.5 |  7 +++--
 5 files changed, 73 insertions(+), 2 deletions(-)
libmultipath/configure.c +4 -0
index 8af7cd79..41641e30 100644
@@ -1075,6 +1075,7 @@ int coalesce_paths (struct vectors *vecs, vector mpvec, char *refwwid,
 	struct config *conf = NULL;
 	int allow_queueing;
 	struct bitfield *size_mismatch_seen;
+	struct multipath * cmpp;
 
 	/* ignore refwwid if it's empty */
 	if (refwwid && !strlen(refwwid))
@@ -1184,6 +1185,9 @@ int coalesce_paths (struct vectors *vecs, vector mpvec, char *refwwid,
 		}
 		verify_paths(mpp);
 
+		cmpp = find_mp_by_wwid(curmp, mpp->wwid);
+		if (cmpp)
+			mpp->queue_mode = cmpp->queue_mode;
 		if (setup_map(mpp, &params, vecs)) {
 			remove_map(mpp, vecs->pathvec, NULL);
 			continue;
libmultipath/dmparser.c +2 -0
index 50d13c08..3b37a926 100644
@@ -151,6 +151,8 @@ int disassemble_map(const struct _vector *pathvec,
 
 		free(word);
 	}
+	mpp->queue_mode = strstr(mpp->features, "queue_mode bio") ?
+			  QUEUE_MODE_BIO : QUEUE_MODE_RQ;
 
 	/*
 	 * hwhandler
libmultipath/propsel.c +55 -0

73 lines not on this page · raw message

libmultipath/structs.h +7 -0
index 5a713d46..129bdf0e 100644
@@ -170,6 +170,12 @@ enum max_sectors_kb_states {
 	MAX_SECTORS_KB_MIN = 4,  /* can't be smaller than page size */
 };
 
+enum queue_mode_states {
+	QUEUE_MODE_UNDEF = 0,
+	QUEUE_MODE_BIO,
+	QUEUE_MODE_RQ,
+};
+
 enum scsi_protocol {
 	SCSI_PROTOCOL_FCP = 0,	/* Fibre Channel */
 	SCSI_PROTOCOL_SPI = 1,	/* parallel SCSI */
@@ -396,6 +402,7 @@ struct multipath {
 	int needs_paths_uevent;
 	int ghost_delay;
 	int ghost_delay_tick;
+	int queue_mode;
 	uid_t uid;
 	gid_t gid;
 	mode_t mode;
multipath/multipath.conf.5 +5 -2
index e098d555..46a4126c 100644
@@ -459,8 +459,11 @@ precedence. See KNOWN ISSUES.
 <mode> can be \fIbio\fR, \fIrq\fR or \fImq\fR, which corresponds to
 bio-based, request-based, and block-multiqueue (blk-mq) request-based,
 respectively.
-The default depends on the kernel parameter \fBdm_mod.use_blk_mq\fR. It is
-\fImq\fR if the latter is set, and \fIrq\fR otherwise.
+Before kernel 4.20 The default depends on the kernel parameter
+\fBdm_mod.use_blk_mq\fR. It is \fImq\fR if the latter is set, and \fIrq\fR
+otherwise. Since kernel 4.20, \fIrq\fR and \fImq\fR both correspond to
+block-multiqueue. Once a multipath device has been created, its queue_mode
+cannot be changed.
 .TP
 The default is: \fB<unset>\fR
 .RE
Signature · 6 lines
2.17.2

--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel
Reviewed-by on v1 4/8
#8 lore raw

Re: [dm-devel] [PATCH 4/8] libmultipath: fix queue_mode feature handling

Quoted 6 lines · Benjamin Marzinski

device-mapper is not able to change the queue_mode on a table reload. Make sure that when multipath sets up the map, both on regular reloads
and reconfigures, it keeps the queue_mode the same.

Some remarks below.

Quoted 39 lines

---
 libmultipath/configure.c   |  4 +++
 libmultipath/dmparser.c    |  2 ++
 libmultipath/propsel.c     | 55
++++++++++++++++++++++++++++++++++++++
 libmultipath/structs.h     |  7 +++++
 multipath/multipath.conf.5 |  7 +++--

 5 files changed, 73 insertions(+), 2 deletions(-)
libmultipath/configure.c +1 -0
index 8af7cd79..41641e30 100644
@@ -1075,6 +1075,7 @@ int coalesce_paths (struct vectors *vecs,
 vector mpvec, char *refwwid,
         struct config *conf = NULL;
         int allow_queueing;
         struct bitfield *size_mismatch_seen;
+       struct multipath * cmpp;


        /* ignore refwwid if it's empty */
        if (refwwid && !strlen(refwwid))

libmultipath/configure.c +0 -0
@@ -1184,6 +1185,9 @@ int coalesce_paths (struct vectors *vecs,
 vector mpvec, char *refwwid,
                 }
                 verify_paths(mpp);


+               cmpp = find_mp_by_wwid(curmp, mpp->wwid); +               if (cmpp)
+                       mpp->queue_mode = cmpp->queue_mode; if (setup_map(mpp, &params, vecs)) { remove_map(mpp, vecs->pathvec, NULL); continue;

libmultipath/dmparser.c +0 -0
index 50d13c08..3b37a926 100644
@@ -151,6 +151,8 @@ int disassemble_map(const struct _vector
 *pathvec,
Quoted 5 lines


                free(word);
        }
+       mpp->queue_mode = strstr(mpp->features, "queue_mode bio") ? +                         QUEUE_MODE_BIO : QUEUE_MODE_RQ;

Nitpick: You have spent effort to make multipath-tools support any whitepace characters in the previous patches, but here you don't. I can see that disassemble_map() generally assumes space characters as word delimiters, but at least I see some inconsistency here.

Do you intend to generalize the whitespace handling in disassemble_map(), too? Or am I overlooking something?

Quoted 21 lines


        /*
         * hwhandler

libmultipath/propsel.c +1 -0
index 98e3aad1..d4f19897 100644
@@ -26,6 +26,7 @@
  #include "strbuf.h"
  #include <inttypes.h>
  #include <libudev.h>
+#include <ctype.h>


 pgpolicyfn *pgpolicies[] = {
        NULL,

libmultipath/propsel.c +0 -0
@@ -413,6 +414,59 @@ void reconcile_features_with_options(const char
 *id, char **features, int* no_pa
         }
  }

libmultipath/propsel.c +1 -0
+static void reconcile_features_with_queue_mode(struct multipath *mp)

libmultipath/propsel.c void reconcile_features_with_options(const char *id, char **features, int* no_pa · line 427

Quoted 10 lines
libmultipath/propsel.c +10 -0
+{
+       char *space = NULL, *val = NULL, *mode_str = NULL, *feat;
+       int features_mode = QUEUE_MODE_UNDEF;
+
+       if (!mp->features)
+               return;
+
+       pthread_cleanup_push(cleanup_free_ptr, &space);
+       pthread_cleanup_push(cleanup_free_ptr, &val);
+       pthread_cleanup_push(cleanup_free_ptr, &mode_str);

I was wondering why we need pthread_cleanup() complexity here, seeing no cancellation points in this function. I eventually realized that condlog()->dlog()->log_safe()->pthread_mutex_lock() is a cancellation point. I suppose we need to clean that up some time.

Quoted 5 lines

+
+       if (!(feat = strstr(mp->features, "queue_mode")) || +           feat == mp->features || !isspace(*(feat - 1)) || +           sscanf(feat, "queue_mode%m[ \f\n\r\t\v]%ms", &space, &val) != 2)

Nit: Given that mp->features comes from the multipath.conf, I'm pretty sure that it can't contain \n or \r as whitespace characters (read_line() would remove them()). Not sure about \f and \v; guess they are allowed but I wouldn't swear that they can be used in multipath.conf without causing trouble elsewhere.

Quoted 93 lines

+               goto sync_mode;
+       if (asprintf(&mode_str, "queue_mode%s%s", space, val) < 0) { +               condlog(1, "failed to allocate space for queue_mode feature string");
+               mode_str = NULL; /* value undefined on failure */ +               goto exit;
+       }

libmultipath/propsel.c +18 -0
+
+       if (!strcmp(val, "rq") || !strcmp(val, "mq"))
+               features_mode = QUEUE_MODE_RQ;
+       else if (!strcmp(val, "bio"))
+               features_mode = QUEUE_MODE_BIO;
+       if (features_mode == QUEUE_MODE_UNDEF) {
+               condlog(2, "%s: ignoring invalid feature '%s'",
+                       mp->alias, mode_str);
+               goto sync_mode;
+       }
+
+       if (mp->queue_mode == QUEUE_MODE_UNDEF)
+               mp->queue_mode = features_mode;
+       if (mp->queue_mode == features_mode)
+               goto exit;
+
+       condlog(2,
+               "%s: ignoring feature '%s' because queue_mode is set

to '%s'",
+               mp->alias, mode_str,
+               (mp->queue_mode == QUEUE_MODE_RQ)? "rq" : "bio");

libmultipath/propsel.c +12 -0
+
+sync_mode:
+       if (mode_str)
+               remove_feature(&mp->features, mode_str);
+       if (mp->queue_mode == QUEUE_MODE_BIO)
+               add_feature(&mp->features, "queue_mode bio");
+exit:
+       pthread_cleanup_pop(1);
+       pthread_cleanup_pop(1);
+       pthread_cleanup_pop(1);
+}
+

 int select_features(struct config *conf, struct multipath *mp) {
        const char *origin;

libmultipath/propsel.c +1 -0
@@ -428,6 +482,7 @@ out:
         reconcile_features_with_options(mp->alias, &mp->features,
                                         &mp->no_path_retry,
                                         &mp->retain_hwhandler);
+       reconcile_features_with_queue_mode(mp);

        condlog(3, "%s: features = \"%s\" %s", mp->alias, mp-

Quoted 1 line

features, origin);

        return 0;
 }

libmultipath/structs.h +0 -0
index 5a713d46..129bdf0e 100644
@@ -170,6 +170,12 @@ enum max_sectors_kb_states {

        MAX_SECTORS_KB_MIN = 4,  /* can't be smaller than page size */
 };

libmultipath/structs.h +6 -0
+enum queue_mode_states {
+       QUEUE_MODE_UNDEF = 0,
+       QUEUE_MODE_BIO,
+       QUEUE_MODE_RQ,
+};
+

 enum scsi_protocol {
        SCSI_PROTOCOL_FCP = 0,  /* Fibre Channel */ SCSI_PROTOCOL_SPI = 1,  /* parallel SCSI */

libmultipath/structs.h +1 -0
@@ -396,6 +402,7 @@ struct multipath {
         int needs_paths_uevent;
         int ghost_delay;
         int ghost_delay_tick;
+       int queue_mode;
         uid_t uid;
         gid_t gid;
         mode_t mode;
multipath/multipath.conf.5 +0 -0
index e098d555..46a4126c 100644
@@ -459,8 +459,11 @@ precedence. See KNOWN ISSUES.

 <mode> can be \fIbio\fR, \fIrq\fR or \fImq\fR, which corresponds to bio-based, request-based, and block-multiqueue (blk-mq) request- based,
 respectively.
-The default depends on the kernel parameter \fBdm_mod.use_blk_mq\fR. It is
-\fImq\fR if the latter is set, and \fIrq\fR otherwise. +Before kernel 4.20 The default depends on the kernel parameter +\fBdm_mod.use_blk_mq\fR. It is \fImq\fR if the latter is set, and \fIrq\fR

Quoted 8 lines

+otherwise. Since kernel 4.20, \fIrq\fR and \fImq\fR both correspond to
+block-multiqueue. Once a multipath device has been created, its queue_mode
+cannot be changed.
 .TP
 The default is: \fB<unset>\fR
 .RE

--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel

author maintainer
#9 lore raw

Re: [dm-devel] [PATCH 4/8] libmultipath: fix queue_mode feature handling

Quoted 62 lines · Martin Wilck
Quoted 6 lines · Benjamin Marzinski

device-mapper is not able to change the queue_mode on a table reload. Make sure that when multipath sets up the map, both on regular reloads
and reconfigures, it keeps the queue_mode the same.

Some remarks below.

Quoted 39 lines

---
 libmultipath/configure.c   |  4 +++
 libmultipath/dmparser.c    |  2 ++
 libmultipath/propsel.c     | 55
++++++++++++++++++++++++++++++++++++++
 libmultipath/structs.h     |  7 +++++
 multipath/multipath.conf.5 |  7 +++--

 5 files changed, 73 insertions(+), 2 deletions(-)
libmultipath/configure.c +1 -0
index 8af7cd79..41641e30 100644
@@ -1075,6 +1075,7 @@ int coalesce_paths (struct vectors *vecs,
 vector mpvec, char *refwwid,
         struct config *conf = NULL;
         int allow_queueing;
         struct bitfield *size_mismatch_seen;
+       struct multipath * cmpp;


        /* ignore refwwid if it's empty */
        if (refwwid && !strlen(refwwid))

libmultipath/configure.c +0 -0
@@ -1184,6 +1185,9 @@ int coalesce_paths (struct vectors *vecs,
 vector mpvec, char *refwwid,
                 }
                 verify_paths(mpp);


+               cmpp = find_mp_by_wwid(curmp, mpp->wwid); +               if (cmpp)
+                       mpp->queue_mode = cmpp->queue_mode; if (setup_map(mpp, &params, vecs)) { remove_map(mpp, vecs->pathvec, NULL); continue;

libmultipath/dmparser.c +0 -0
index 50d13c08..3b37a926 100644
@@ -151,6 +151,8 @@ int disassemble_map(const struct _vector
 *pathvec,
Quoted 5 lines


                free(word);
        }
+       mpp->queue_mode = strstr(mpp->features, "queue_mode bio") ? +                         QUEUE_MODE_BIO : QUEUE_MODE_RQ;

Nitpick: You have spent effort to make multipath-tools support any whitepace characters in the previous patches, but here you don't. I can see that disassemble_map() generally assumes space characters as word delimiters, but at least I see some inconsistency here.

Quoted 2 lines

Do you intend to generalize the whitespace handling in disassemble_map(), too? Or am I overlooking something?

The kernel will never output any whitespace characters other than space, so that seems like unnecessary complexity. We also know that the kernel will never output a feature named something like "enqueue_mode" so we don't need to check for the space before "queue_mode". But I suppose the the kernel could add feature named "<something>queue_mode" in the future. If you think it's important, I send a patch to add a space before "queue_mode", in the check to deal with that possibility, but I'm not particularly worried about this.

Quoted 28 lines
Quoted 28 lines


        /*
         * hwhandler

libmultipath/propsel.c +1 -0
index 98e3aad1..d4f19897 100644
@@ -26,6 +26,7 @@
  #include "strbuf.h"
  #include <inttypes.h>
  #include <libudev.h>
+#include <ctype.h>


 pgpolicyfn *pgpolicies[] = {
        NULL,

libmultipath/propsel.c +0 -0
@@ -413,6 +414,59 @@ void reconcile_features_with_options(const char
 *id, char **features, int* no_pa
         }
  }

libmultipath/propsel.c +8 -0
+static void reconcile_features_with_queue_mode(struct multipath *mp)
+{
+       char *space = NULL, *val = NULL, *mode_str = NULL, *feat;
+       int features_mode = QUEUE_MODE_UNDEF;
+
+       if (!mp->features)
+               return;
+
Quoted 9 lines
Quoted 3 lines

+       pthread_cleanup_push(cleanup_free_ptr, &space); +       pthread_cleanup_push(cleanup_free_ptr, &val); +       pthread_cleanup_push(cleanup_free_ptr, &mode_str);

I was wondering why we need pthread_cleanup() complexity here, seeing no cancellation points in this function. I eventually realized that condlog()->dlog()->log_safe()->pthread_mutex_lock() is a cancellation point. I suppose we need to clean that up some time.

So is fprintf(), so even as a systemd style daemon, condlog() is a cancellation point.

Quoted 11 lines
Quoted 5 lines

+
+       if (!(feat = strstr(mp->features, "queue_mode")) || +           feat == mp->features || !isspace(*(feat - 1)) || +           sscanf(feat, "queue_mode%m[ \f\n\r\t\v]%ms", &space, &val) != 2)

Nit: Given that mp->features comes from the multipath.conf, I'm pretty sure that it can't contain \n or \r as whitespace characters (read_line() would remove them()). Not sure about \f and \v; guess they are allowed but I wouldn't swear that they can be used in multipath.conf without causing trouble elsewhere.

I was matching the characters that isspace() checks for, for consistency, since we used isspace() to check that there was a space before "queue_mode".

-Ben

Quoted 93 lines
Quoted 93 lines

+               goto sync_mode;
+       if (asprintf(&mode_str, "queue_mode%s%s", space, val) < 0) { +               condlog(1, "failed to allocate space for queue_mode feature string");
+               mode_str = NULL; /* value undefined on failure */ +               goto exit;
+       }

libmultipath/propsel.c +18 -0
+
+       if (!strcmp(val, "rq") || !strcmp(val, "mq"))
+               features_mode = QUEUE_MODE_RQ;
+       else if (!strcmp(val, "bio"))
+               features_mode = QUEUE_MODE_BIO;
+       if (features_mode == QUEUE_MODE_UNDEF) {
+               condlog(2, "%s: ignoring invalid feature '%s'",
+                       mp->alias, mode_str);
+               goto sync_mode;
+       }
+
+       if (mp->queue_mode == QUEUE_MODE_UNDEF)
+               mp->queue_mode = features_mode;
+       if (mp->queue_mode == features_mode)
+               goto exit;
+
+       condlog(2,
+               "%s: ignoring feature '%s' because queue_mode is set

to '%s'",
+               mp->alias, mode_str,
+               (mp->queue_mode == QUEUE_MODE_RQ)? "rq" : "bio");

libmultipath/propsel.c +12 -0
+
+sync_mode:
+       if (mode_str)
+               remove_feature(&mp->features, mode_str);
+       if (mp->queue_mode == QUEUE_MODE_BIO)
+               add_feature(&mp->features, "queue_mode bio");
+exit:
+       pthread_cleanup_pop(1);
+       pthread_cleanup_pop(1);
+       pthread_cleanup_pop(1);
+}
+

 int select_features(struct config *conf, struct multipath *mp) {
        const char *origin;

libmultipath/propsel.c +1 -0
@@ -428,6 +482,7 @@ out:
         reconcile_features_with_options(mp->alias, &mp->features,
                                         &mp->no_path_retry,
                                         &mp->retain_hwhandler);
+       reconcile_features_with_queue_mode(mp);

        condlog(3, "%s: features = \"%s\" %s", mp->alias, mp-

Quoted 1 line

features, origin);

        return 0;
 }

libmultipath/structs.h +0 -0
index 5a713d46..129bdf0e 100644
@@ -170,6 +170,12 @@ enum max_sectors_kb_states {

        MAX_SECTORS_KB_MIN = 4,  /* can't be smaller than page size */
 };

libmultipath/structs.h +6 -0
+enum queue_mode_states {
+       QUEUE_MODE_UNDEF = 0,
+       QUEUE_MODE_BIO,
+       QUEUE_MODE_RQ,
+};
+

 enum scsi_protocol {
        SCSI_PROTOCOL_FCP = 0,  /* Fibre Channel */ SCSI_PROTOCOL_SPI = 1,  /* parallel SCSI */

libmultipath/structs.h +1 -0
@@ -396,6 +402,7 @@ struct multipath {
         int needs_paths_uevent;
         int ghost_delay;
         int ghost_delay_tick;
+       int queue_mode;
         uid_t uid;
         gid_t gid;
         mode_t mode;
multipath/multipath.conf.5 +0 -0
index e098d555..46a4126c 100644
@@ -459,8 +459,11 @@ precedence. See KNOWN ISSUES.

 <mode> can be \fIbio\fR, \fIrq\fR or \fImq\fR, which corresponds to bio-based, request-based, and block-multiqueue (blk-mq) request- based,
 respectively.
-The default depends on the kernel parameter \fBdm_mod.use_blk_mq\fR. It is
-\fImq\fR if the latter is set, and \fIrq\fR otherwise. +Before kernel 4.20 The default depends on the kernel parameter +\fBdm_mod.use_blk_mq\fR. It is \fImq\fR if the latter is set, and \fIrq\fR

Quoted 8 lines
Quoted 8 lines

+otherwise. Since kernel 4.20, \fIrq\fR and \fImq\fR both correspond to
+block-multiqueue. Once a multipath device has been created, its queue_mode
+cannot be changed.
 .TP
 The default is: \fB<unset>\fR
 .RE

--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel

#10 lore raw

Re: [dm-devel] [PATCH 4/8] libmultipath: fix queue_mode feature handling

Quoted 67 lines · Benjamin Marzinski
Quoted 66 lines · Martin Wilck
Quoted 7 lines · Benjamin Marzinski

device-mapper is not able to change the queue_mode on a table reload.
Make sure that when multipath sets up the map, both on regular reloads
and reconfigures, it keeps the queue_mode the same.

Some remarks below.

Quoted 39 lines

---
 libmultipath/configure.c   |  4 +++
 libmultipath/dmparser.c    |  2 ++
 libmultipath/propsel.c     | 55
++++++++++++++++++++++++++++++++++++++
 libmultipath/structs.h     |  7 +++++
 multipath/multipath.conf.5 |  7 +++--

 5 files changed, 73 insertions(+), 2 deletions(-)
libmultipath/configure.c +1 -0
index 8af7cd79..41641e30 100644
@@ -1075,6 +1075,7 @@ int coalesce_paths (struct vectors *vecs,
 vector mpvec, char *refwwid,
         struct config *conf = NULL;
         int allow_queueing;
         struct bitfield *size_mismatch_seen;
+       struct multipath * cmpp;


        /* ignore refwwid if it's empty */
        if (refwwid && !strlen(refwwid))

libmultipath/configure.c +0 -0
@@ -1184,6 +1185,9 @@ int coalesce_paths (struct vectors *vecs,
 vector mpvec, char *refwwid,
                 }
                 verify_paths(mpp);


+               cmpp = find_mp_by_wwid(curmp, mpp->wwid); +               if (cmpp)
+                       mpp->queue_mode = cmpp->queue_mode; if (setup_map(mpp, &params, vecs)) { remove_map(mpp, vecs->pathvec, NULL); continue;

libmultipath/dmparser.c +0 -0
index 50d13c08..3b37a926 100644
@@ -151,6 +151,8 @@ int disassemble_map(const struct _vector
 *pathvec,
Quoted 6 lines


                free(word);
        }
+       mpp->queue_mode = strstr(mpp->features, "queue_mode bio") ?
+                         QUEUE_MODE_BIO : QUEUE_MODE_RQ;

Nitpick: You have spent effort to make multipath-tools support any whitepace characters in the previous patches, but here you don't. I can
see that disassemble_map() generally assumes space characters as word
delimiters, but at least I see some inconsistency here.

Quoted 5 lines
Quoted 2 lines

Do you intend to generalize the whitespace handling in disassemble_map(), too? Or am I overlooking something?

The kernel will never output any whitespace characters other than space,

This was the part I was missing. The kernel separates args using isspace(), but of course it won't insert any weird characters when it returns the status line.

Fine, then.

Quoted 56 lines

so that seems like unnecessary complexity.  We also know that the kernel
will never output a feature named something like "enqueue_mode" so we don't need to check for the space before "queue_mode". But I suppose the
the kernel could add feature named "<something>queue_mode" in the future. If you think it's important, I send a patch to add a space before "queue_mode", in the check to deal with that possibility, but I'm
not particularly worried about this.

Quoted 32 lines
Quoted 32 lines


        /*
         * hwhandler

libmultipath/propsel.c +1 -0
index 98e3aad1..d4f19897 100644
@@ -26,6 +26,7 @@
  #include "strbuf.h"
  #include <inttypes.h>
  #include <libudev.h>
+#include <ctype.h>


 pgpolicyfn *pgpolicies[] = {
        NULL,

libmultipath/propsel.c +0 -0
@@ -413,6 +414,59 @@ void reconcile_features_with_options(const

char
*id, char **features, int* no_pa
        }
 }

+static void reconcile_features_with_queue_mode(struct multipath *mp)

libmultipath/propsel.c +9 -0
+{
+       char *space = NULL, *val = NULL, *mode_str = NULL, *feat;
+       int features_mode = QUEUE_MODE_UNDEF;
+
+       if (!mp->features)
+               return;
+
+       pthread_cleanup_push(cleanup_free_ptr, &space);
+       pthread_cleanup_push(cleanup_free_ptr, &val);
Quoted 9 lines
Quoted 1 line

+       pthread_cleanup_push(cleanup_free_ptr, &mode_str);

I was wondering why we need pthread_cleanup() complexity here, seeing
no cancellation points in this function. I eventually realized that condlog()->dlog()->log_safe()->pthread_mutex_lock() is a cancellation
point. I suppose we need to clean that up some time.

Quoted 2 lines

So is fprintf(), so even as a systemd style daemon, condlog() is a cancellation point.

Right, figured that in the meantime.

Quoted 15 lines

Quoted 6 lines
Quoted 5 lines

+
+       if (!(feat = strstr(mp->features, "queue_mode")) || +           feat == mp->features || !isspace(*(feat - 1)) || +           sscanf(feat, "queue_mode%m[ \f\n\r\t\v]%ms", &space, &val) != 2)

Quoted 7 lines

Nit: Given that mp->features comes from the multipath.conf, I'm pretty
sure that it can't contain \n or \r as whitespace characters (read_line() would remove them()). Not sure about \f and \v; guess they
are allowed but I wouldn't swear that they can be used in multipath.conf without causing trouble elsewhere.

Quoted 3 lines

I was matching the characters that isspace() checks for, for consistency, since we used isspace() to check that there was a space before "queue_mode".

Ok.

Martin

--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel

author maintainer
#11 lore raw

PATCH 5/8 multipath tests: tests for reconcile_features_with_queue_mode

In reply to Benjamin Marzinski
---
 tests/Makefile   |   2 +
 tests/features.c | 232 ++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 233 insertions(+), 1 deletion(-)
tests/Makefile +2 -0
index ccdfbd15..bc9380f8 100644
@@ -36,6 +36,7 @@ ifneq ($(DIO_TEST_DEV),)
 directio-test_FLAGS := -DDIO_TEST_DEV=\"$(DIO_TEST_DEV)\"
 endif
 mpathvalid-test_FLAGS := -I$(mpathvaliddir)
+features-test_FLAGS := -I$(multipathdir)/nvme
 
 # test-specific linker flags
 # XYZ-test_TESTDEPS: test libraries containing __wrap_xyz functions
@@ -73,6 +74,7 @@ strbuf-test_OBJDEPS := $(mpathutildir)/strbuf.o
 sysfs-test_TESTDEPS := test-log.o
 sysfs-test_OBJDEPS := $(multipathdir)/sysfs.o $(mpathutildir)/util.o
 sysfs-test_LIBDEPS := -ludev -lpthread -ldl
+features-test_LIBDEPS := -ludev -lpthread
 
 %.o: %.c
 	$(CC) $(CPPFLAGS) $(CFLAGS) $($*-test_FLAGS) -c -o $@ $<
tests/features.c +231 -1

252 lines not on this page · raw message

Signature · 6 lines
2.17.2

--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel
author maintainer
#12 lore raw

PATCH 6/8 libmultipath: prepare proto_id for use by non-scsi devivces

In reply to Benjamin Marzinski

Make sure that when we are checking for a scsi protocol, we are first checking that we are working with a scsi path.

---
 libmultipath/configure.c   |  9 +++++----
 libmultipath/discovery.c   | 13 ++++++++-----
 libmultipath/print.c       |  6 ++++--
 libmultipath/structs.c     |  2 +-
 libmultipath/structs.h     |  4 +++-
 multipathd/fpin_handlers.c |  2 +-
 6 files changed, 22 insertions(+), 14 deletions(-)
libmultipath/configure.c +5 -4
index 41641e30..7c7babd9 100644
@@ -218,10 +218,11 @@ int rr_optimize_path_order(struct pathgroup *pgp)
 
 	total_paths = VECTOR_SIZE(pgp->paths);
 	vector_foreach_slot(pgp->paths, pp, i) {
-		if (pp->sg_id.proto_id != SCSI_PROTOCOL_FCP &&
-			pp->sg_id.proto_id != SCSI_PROTOCOL_SAS &&
-			pp->sg_id.proto_id != SCSI_PROTOCOL_ISCSI &&
-			pp->sg_id.proto_id != SCSI_PROTOCOL_SRP) {
+		if (pp->bus != SYSFS_BUS_SCSI ||
+		    (pp->sg_id.proto_id != SCSI_PROTOCOL_FCP &&
+		     pp->sg_id.proto_id != SCSI_PROTOCOL_SAS &&
+		     pp->sg_id.proto_id != SCSI_PROTOCOL_ISCSI &&
+		     pp->sg_id.proto_id != SCSI_PROTOCOL_SRP)) {
 			/* return success as default path order
 			 * is maintained in path group
 			 */
libmultipath/discovery.c +8 -5
index 15560f8c..e937f090 100644
@@ -504,10 +504,11 @@ int sysfs_get_host_adapter_name(const struct path *pp, char *adapter_name)
 
 	proto_id = pp->sg_id.proto_id;
 
-	if (proto_id != SCSI_PROTOCOL_FCP &&
-	    proto_id != SCSI_PROTOCOL_SAS &&
-	    proto_id != SCSI_PROTOCOL_ISCSI &&
-	    proto_id != SCSI_PROTOCOL_SRP) {
+	if (pp->bus != SYSFS_BUS_SCSI ||
+	    (proto_id != SCSI_PROTOCOL_FCP &&
+	     proto_id != SCSI_PROTOCOL_SAS &&
+	     proto_id != SCSI_PROTOCOL_ISCSI &&
+	     proto_id != SCSI_PROTOCOL_SRP)) {
 		return 1;
 	}
 	/* iscsi doesn't have adapter info in sysfs
@@ -1810,8 +1811,10 @@ sysfs_pathinfo(struct path *pp, const struct _vector *hwtable)
 		pp->bus = SYSFS_BUS_CCISS;
 	if (!strncmp(pp->dev,"dasd", 4))
 		pp->bus = SYSFS_BUS_CCW;
-	if (!strncmp(pp->dev,"sd", 2))
+	if (!strncmp(pp->dev,"sd", 2)) {
 		pp->bus = SYSFS_BUS_SCSI;
+		pp->sg_id.proto_id = SCSI_PROTOCOL_UNSPEC;
+	}
 	if (!strncmp(pp->dev,"nvme", 4))
 		pp->bus = SYSFS_BUS_NVME;
 
libmultipath/print.c +4 -2
index 68a793e7..d7d522c8 100644
@@ -650,7 +650,8 @@ snprint_host_attr (struct strbuf *buff, const struct path * pp, char *attr)
 	const char *value = NULL;
 	int ret;
 
-	if (pp->sg_id.proto_id != SCSI_PROTOCOL_FCP)
+	if (pp->bus != SYSFS_BUS_SCSI ||
+	    pp->sg_id.proto_id != SCSI_PROTOCOL_FCP)
 		return append_strbuf_str(buff, "[undef]");
 	sprintf(host_id, "host%d", pp->sg_id.host_no);
 	host_dev = udev_device_new_from_subsystem_sysname(udev, "fc_host",
@@ -689,7 +690,8 @@ snprint_tgt_wwpn (struct strbuf *buff, const struct path * pp)
 	const char *value = NULL;
 	int ret;
 
-	if (pp->sg_id.proto_id != SCSI_PROTOCOL_FCP)
+	if (pp->bus != SYSFS_BUS_SCSI ||
+	    pp->sg_id.proto_id != SCSI_PROTOCOL_FCP)
 		return append_strbuf_str(buff, "[undef]");
 	sprintf(rport_id, "rport-%d:%d-%d",
 		pp->sg_id.host_no, pp->sg_id.channel, pp->sg_id.transport_id);
libmultipath/structs.c +1 -1
index 0f16c071..fb44cd64 100644
@@ -116,7 +116,7 @@ alloc_path (void)
 		pp->sg_id.channel = -1;
 		pp->sg_id.scsi_id = -1;
 		pp->sg_id.lun = SCSI_INVALID_LUN;
-		pp->sg_id.proto_id = SCSI_PROTOCOL_UNSPEC;
+		pp->sg_id.proto_id = PROTOCOL_UNSET;
 		pp->fd = -1;
 		pp->tpgs = TPGS_UNDEF;
 		pp->priority = PRIO_UNDEF;
libmultipath/structs.h +3 -1
index 129bdf0e..d3054662 100644
@@ -176,6 +176,8 @@ enum queue_mode_states {
 	QUEUE_MODE_RQ,
 };
 
+#define PROTOCOL_UNSET -1
+
 enum scsi_protocol {
 	SCSI_PROTOCOL_FCP = 0,	/* Fibre Channel */
 	SCSI_PROTOCOL_SPI = 1,	/* parallel SCSI */
@@ -291,7 +293,7 @@ struct sg_id {
 	uint64_t lun;
 	short h_cmd_per_lun;
 	short d_queue_depth;
-	enum scsi_protocol proto_id;
+	int proto_id;
 	int transport_id;
 };
 
multipathd/fpin_handlers.c +1 -1
index 03b2b9ad..a2de3011 100644
@@ -227,7 +227,7 @@ static int  fpin_chk_wwn_setpath_marginal(uint16_t host_num,  struct vectors *ve
 
 	vector_foreach_slot(vecs->pathvec, pp, k) {
 		/* Checks the host number and also for the SCSI FCP */
-		if (pp->sg_id.proto_id != SCSI_PROTOCOL_FCP || host_num !=  pp->sg_id.host_no)
+		if (pp->bus != SYSFS_BUS_SCSI || pp->sg_id.proto_id != SCSI_PROTOCOL_FCP || host_num !=  pp->sg_id.host_no)
 			continue;
 		sprintf(rport_id, "rport-%d:%d-%d",
 				pp->sg_id.host_no, pp->sg_id.channel, pp->sg_id.transport_id);
Signature · 6 lines
2.17.2

--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel
author maintainer
#13 lore raw

PATCH 7/8 libmultipath: get nvme path transport protocol

In reply to Benjamin Marzinski

Read the transport protocol from /sys/block/nvmeXnY/device/transport. Update protocol_name[] and bus_protocol_id() to store the nvme protocol names after the scsi protocol names.

---
 libmultipath/discovery.c   | 18 ++++++++++++++++--
 libmultipath/structs.c     | 22 +++++++++++++++++-----
 libmultipath/structs.h     | 33 +++++++++++++++++++++------------
 multipath/multipath.conf.5 |  8 ++++++--
 4 files changed, 60 insertions(+), 21 deletions(-)
libmultipath/discovery.c +16 -2
index e937f090..f3fccedd 100644
@@ -1539,6 +1539,7 @@ nvme_sysfs_pathinfo (struct path *pp, const struct _vector *hwtable)
 	struct udev_device *parent;
 	const char *attr_path = NULL;
 	const char *attr;
+	int i;
 
 	if (pp->udev)
 		attr_path = udev_device_get_sysname(pp->udev);
@@ -1561,6 +1562,18 @@ nvme_sysfs_pathinfo (struct path *pp, const struct _vector *hwtable)
 	attr = udev_device_get_sysattr_value(parent, "cntlid");
 	pp->sg_id.channel = attr ? atoi(attr) : 0;
 
+	attr = udev_device_get_sysattr_value(parent, "transport");
+	if (attr) {
+		for (i = 0; i < NVME_PROTOCOL_UNSPEC; i++){
+			if (protocol_name[SYSFS_BUS_NVME + i] &&
+			    !strcmp(attr,
+				    protocol_name[SYSFS_BUS_NVME + i] + 5)) {
+				pp->sg_id.proto_id = i;
+				break;
+			}
+		}
+	}
+
 	snprintf(pp->vendor_id, SCSI_VENDOR_SIZE, "NVME");
 	snprintf(pp->product_id, PATH_PRODUCT_SIZE, "%s",
 		 udev_device_get_sysattr_value(parent, "model"));
@@ -1815,9 +1828,10 @@ sysfs_pathinfo(struct path *pp, const struct _vector *hwtable)
 		pp->bus = SYSFS_BUS_SCSI;
 		pp->sg_id.proto_id = SCSI_PROTOCOL_UNSPEC;
 	}
-	if (!strncmp(pp->dev,"nvme", 4))
+	if (!strncmp(pp->dev,"nvme", 4)) {
 		pp->bus = SYSFS_BUS_NVME;
-
+		pp->sg_id.proto_id = NVME_PROTOCOL_UNSPEC;
+	}
 	switch (pp->bus) {
 	case SYSFS_BUS_SCSI:
 		return scsi_sysfs_pathinfo(pp, hwtable);
libmultipath/structs.c +17 -5
index fb44cd64..7a2ff589 100644
@@ -25,7 +25,6 @@ const char * const protocol_name[LAST_BUS_PROTOCOL_ID + 1] = {
 	[SYSFS_BUS_UNDEF] = "undef",
 	[SYSFS_BUS_CCW] = "ccw",
 	[SYSFS_BUS_CCISS] = "cciss",
-	[SYSFS_BUS_NVME] = "nvme",
 	[SYSFS_BUS_SCSI + SCSI_PROTOCOL_FCP] = "scsi:fcp",
 	[SYSFS_BUS_SCSI + SCSI_PROTOCOL_SPI] = "scsi:spi",
 	[SYSFS_BUS_SCSI + SCSI_PROTOCOL_SSA] = "scsi:ssa",
@@ -37,6 +36,13 @@ const char * const protocol_name[LAST_BUS_PROTOCOL_ID + 1] = {
 	[SYSFS_BUS_SCSI + SCSI_PROTOCOL_ATA] = "scsi:ata",
 	[SYSFS_BUS_SCSI + SCSI_PROTOCOL_USB] = "scsi:usb",
 	[SYSFS_BUS_SCSI + SCSI_PROTOCOL_UNSPEC] = "scsi:unspec",
+	[SYSFS_BUS_NVME + NVME_PROTOCOL_PCIE] = "nvme:pcie",
+	[SYSFS_BUS_NVME + NVME_PROTOCOL_RDMA] = "nvme:rdma",
+	[SYSFS_BUS_NVME + NVME_PROTOCOL_FC] = "nvme:fc",
+	[SYSFS_BUS_NVME + NVME_PROTOCOL_TCP] = "nvme:tcp",
+	[SYSFS_BUS_NVME + NVME_PROTOCOL_LOOP] = "nvme:loop",
+	[SYSFS_BUS_NVME + NVME_PROTOCOL_APPLE_NVME] = "nvme:apple-nvme",
+	[SYSFS_BUS_NVME + NVME_PROTOCOL_UNSPEC] = "nvme:unspec",
 };
 
 struct adapter_group *
@@ -746,11 +752,17 @@ out:
 }
 
 unsigned int bus_protocol_id(const struct path *pp) {
-	if (!pp || pp->bus < 0 || pp->bus > SYSFS_BUS_SCSI)
+	if (!pp || pp->bus < 0 || pp->bus > SYSFS_BUS_NVME)
 		return SYSFS_BUS_UNDEF;
-	if (pp->bus != SYSFS_BUS_SCSI)
+	if (pp->bus != SYSFS_BUS_SCSI && pp->bus != SYSFS_BUS_NVME)
 		return pp->bus;
-	if ((int)pp->sg_id.proto_id < 0 || pp->sg_id.proto_id > SCSI_PROTOCOL_UNSPEC)
+	if (pp->sg_id.proto_id < 0)
 		return SYSFS_BUS_UNDEF;
-	return SYSFS_BUS_SCSI + pp->sg_id.proto_id;
+	if (pp->bus == SYSFS_BUS_SCSI &&
+	    pp->sg_id.proto_id > SCSI_PROTOCOL_UNSPEC)
+		return SYSFS_BUS_UNDEF;
+	if (pp->bus == SYSFS_BUS_NVME &&
+	    pp->sg_id.proto_id > NVME_PROTOCOL_UNSPEC)
+		return SYSFS_BUS_UNDEF;
+	return pp->bus + pp->sg_id.proto_id;
 }
libmultipath/structs.h +21 -12
index d3054662..9e2c1ab0 100644
@@ -56,15 +56,6 @@ enum failback_mode {
 	FAILBACK_FOLLOWOVER
 };
 
-/* SYSFS_BUS_SCSI should be last, see bus_protocol_id() */
-enum sysfs_buses {
-	SYSFS_BUS_UNDEF,
-	SYSFS_BUS_CCW,
-	SYSFS_BUS_CCISS,
-	SYSFS_BUS_NVME,
-	SYSFS_BUS_SCSI,
-};
-
 enum pathstates {
 	PSTATE_UNDEF,
 	PSTATE_FAILED,
@@ -190,14 +181,32 @@ enum scsi_protocol {
 	SCSI_PROTOCOL_ATA = 8,
 	SCSI_PROTOCOL_USB = 9,  /* USB Attached SCSI (UAS), and others */
 	SCSI_PROTOCOL_UNSPEC = 0xa, /* No specific protocol */
+	SCSI_PROTOCOL_END = 0xb, /* offset of the next sysfs_buses entry */
+};
+
+/* values from /sys/class/nvme/nvmeX */
+enum nvme_protocol {
+	NVME_PROTOCOL_PCIE = 0,
+	NVME_PROTOCOL_RDMA = 1,
+	NVME_PROTOCOL_FC = 2,
+	NVME_PROTOCOL_TCP = 3,
+	NVME_PROTOCOL_LOOP = 4,
+	NVME_PROTOCOL_APPLE_NVME = 5,
+	NVME_PROTOCOL_UNSPEC = 6, /* unknown protocol */
+};
+
+enum sysfs_buses {
+	SYSFS_BUS_UNDEF,
+	SYSFS_BUS_CCW,
+	SYSFS_BUS_CCISS,
+	SYSFS_BUS_SCSI,
+	SYSFS_BUS_NVME = SYSFS_BUS_SCSI + SCSI_PROTOCOL_END,
 };
 
 /*
  * Linear ordering of bus/protocol
- * This assumes that SYSFS_BUS_SCSI is last in enum sysfs_buses
- * SCSI is the only bus type for which we distinguish protocols.
  */
-#define LAST_BUS_PROTOCOL_ID (SYSFS_BUS_SCSI + SCSI_PROTOCOL_UNSPEC)
+#define LAST_BUS_PROTOCOL_ID (SYSFS_BUS_NVME + NVME_PROTOCOL_UNSPEC)
 unsigned int bus_protocol_id(const struct path *pp);
 extern const char * const protocol_name[];
 
multipath/multipath.conf.5 +6 -2
index 46a4126c..07476497 100644
@@ -1377,7 +1377,9 @@ Regular expression for the protocol of a device to be excluded/included.
 The protocol strings that multipath recognizes are \fIscsi:fcp\fR,
 \fIscsi:spi\fR, \fIscsi:ssa\fR, \fIscsi:sbp\fR, \fIscsi:srp\fR,
 \fIscsi:iscsi\fR, \fIscsi:sas\fR, \fIscsi:adt\fR, \fIscsi:ata\fR,
-\fIscsi:unspec\fR, \fIccw\fR, \fIcciss\fR, \fInvme\fR, and \fIundef\fR.
+\fIscsi:unspec\fR, \fInvme:pcie\fR, \fInvme:rdma\fR, \fInvme:fc\fR,
+\fInvme:tcp\fR, \fInvme:loop\fR, \fInvme:apple-nvme\fR, \fInvme:unspec\fR,
+\fIccw\fR, \fIcciss\fR, and \fIundef\fR.
 The protocol that a path is using can be viewed by running
 \fBmultipathd show paths format "%d %P"\fR
 .RE
@@ -1773,7 +1775,9 @@ The protocol subsection recognizes the following mandatory attribute:
 The protocol string of the path device. The possible values are \fIscsi:fcp\fR,
 \fIscsi:spi\fR, \fIscsi:ssa\fR, \fIscsi:sbp\fR, \fIscsi:srp\fR,
 \fIscsi:iscsi\fR, \fIscsi:sas\fR, \fIscsi:adt\fR, \fIscsi:ata\fR,
-\fIscsi:unspec\fR, \fIccw\fR, \fIcciss\fR, \fInvme\fR, and \fIundef\fR. This is
+\fIscsi:unspec\fR, \fInvme:pcie\fR, \fInvme:rdma\fR, \fInvme:fc\fR,
+\fInvme:tcp\fR, \fInvme:loop\fR, \fInvme:apple-nvme\fR, \fInvme:unspec\fR,
+\fIccw\fR, \fIcciss\fR, and \fIundef\fR. This is
 \fBnot\fR a regular expression. the path device protocol string must match
 exactly. The protocol that a path is using can be viewed by running
 \fBmultipathd show paths format "%d %P"\fR
Signature · 6 lines
2.17.2

--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel
Reviewed-by on v1 7/8
#14 lore raw

Re: [dm-devel] [PATCH 7/8] libmultipath: get nvme path transport protocol

Quoted 6 lines · Benjamin Marzinski

Read the transport protocol from /sys/block/nvmeXnY/device/transport. Update protocol_name[] and bus_protocol_id() to store the nvme protocol
names after the scsi protocol names.

One remark below.

Regards
Martin

Quoted 73 lines

---
 libmultipath/discovery.c   | 18 ++++++++++++++++-- libmultipath/structs.c     | 22 +++++++++++++++++----- libmultipath/structs.h     | 33 +++++++++++++++++++++------------ multipath/multipath.conf.5 |  8 ++++++--

 4 files changed, 60 insertions(+), 21 deletions(-)
libmultipath/discovery.c +1 -0
index e937f090..f3fccedd 100644
@@ -1539,6 +1539,7 @@ nvme_sysfs_pathinfo (struct path *pp, const
 struct _vector *hwtable)
         struct udev_device *parent;
         const char *attr_path = NULL;
         const char *attr;
+       int i;


        if (pp->udev)
                attr_path = udev_device_get_sysname(pp->udev);

libmultipath/discovery.c +0 -0
@@ -1561,6 +1562,18 @@ nvme_sysfs_pathinfo (struct path *pp, const
 struct _vector *hwtable)
         attr = udev_device_get_sysattr_value(parent, "cntlid");
         pp->sg_id.channel = attr ? atoi(attr) : 0;


+       attr = udev_device_get_sysattr_value(parent, "transport"); +       if (attr) {
+               for (i = 0; i < NVME_PROTOCOL_UNSPEC; i++){ +                       if (protocol_name[SYSFS_BUS_NVME + i] && +                           !strcmp(attr,
+                                   protocol_name[SYSFS_BUS_NVME + i]
+ 5)) {
+                               pp->sg_id.proto_id = i;
+                               break;
+                       }
+               }
+       }
+
        snprintf(pp->vendor_id, SCSI_VENDOR_SIZE, "NVME"); snprintf(pp->product_id, PATH_PRODUCT_SIZE, "%s", udev_device_get_sysattr_value(parent, "model"));

libmultipath/discovery.c +3 -2
@@ -1815,9 +1828,10 @@ sysfs_pathinfo(struct path *pp, const struct
 _vector *hwtable)
                 pp->bus = SYSFS_BUS_SCSI;
                 pp->sg_id.proto_id = SCSI_PROTOCOL_UNSPEC;
         }
-       if (!strncmp(pp->dev,"nvme", 4))
+       if (!strncmp(pp->dev,"nvme", 4)) {
                 pp->bus = SYSFS_BUS_NVME;
-
+               pp->sg_id.proto_id = NVME_PROTOCOL_UNSPEC;
+       }
         switch (pp->bus) {

        case SYSFS_BUS_SCSI:
                return scsi_sysfs_pathinfo(pp, hwtable);

libmultipath/structs.c +0 -1
index fb44cd64..7a2ff589 100644
@@ -25,7 +25,6 @@ const char * const
 protocol_name[LAST_BUS_PROTOCOL_ID + 1] = {
         [SYSFS_BUS_UNDEF] = "undef",
         [SYSFS_BUS_CCW] = "ccw",
         [SYSFS_BUS_CCISS] = "cciss",
-       [SYSFS_BUS_NVME] = "nvme",
         [SYSFS_BUS_SCSI + SCSI_PROTOCOL_FCP] = "scsi:fcp",
         [SYSFS_BUS_SCSI + SCSI_PROTOCOL_SPI] = "scsi:spi",

        [SYSFS_BUS_SCSI + SCSI_PROTOCOL_SSA] = "scsi:ssa",

libmultipath/structs.c +0 -0
@@ -37,6 +36,13 @@ const char * const
 protocol_name[LAST_BUS_PROTOCOL_ID + 1] = {
         [SYSFS_BUS_SCSI + SCSI_PROTOCOL_ATA] = "scsi:ata",
         [SYSFS_BUS_SCSI + SCSI_PROTOCOL_USB] = "scsi:usb",

libmultipath/structs.c const char * const · line 48

Quoted 10 lines
libmultipath/structs.c +7 -0
         [SYSFS_BUS_SCSI + SCSI_PROTOCOL_UNSPEC] = "scsi:unspec",
+       [SYSFS_BUS_NVME + NVME_PROTOCOL_PCIE] = "nvme:pcie",
+       [SYSFS_BUS_NVME + NVME_PROTOCOL_RDMA] = "nvme:rdma",
+       [SYSFS_BUS_NVME + NVME_PROTOCOL_FC] = "nvme:fc",
+       [SYSFS_BUS_NVME + NVME_PROTOCOL_TCP] = "nvme:tcp",
+       [SYSFS_BUS_NVME + NVME_PROTOCOL_LOOP] = "nvme:loop",
+       [SYSFS_BUS_NVME + NVME_PROTOCOL_APPLE_NVME] = "nvme:apple-
 nvme",
+       [SYSFS_BUS_NVME + NVME_PROTOCOL_UNSPEC] = "nvme:unspec",
  };

With NVMe subprotocols being added, I wish we could separate bus and protocol more cleanly. The addition (SYSFS_BUS_SCSI + SCSI_PROTOCOL_FCP) was ok as long as only SCSI had transport protocols, but with NVMe transports being added, I'd prefer something cleaner.

I guess it's ok for the time being, but we should look into improving it.

Martin

Quoted 109 lines


 struct adapter_group *

libmultipath/structs.c +0 -0
@@ -746,11 +752,17 @@ out:
  }


 unsigned int bus_protocol_id(const struct path *pp) {

-       if (!pp || pp->bus < 0 || pp->bus > SYSFS_BUS_SCSI)
+       if (!pp || pp->bus < 0 || pp->bus > SYSFS_BUS_NVME)

                return SYSFS_BUS_UNDEF;
-       if (pp->bus != SYSFS_BUS_SCSI)
+       if (pp->bus != SYSFS_BUS_SCSI && pp->bus != SYSFS_BUS_NVME) return pp->bus;
-       if ((int)pp->sg_id.proto_id < 0 || pp->sg_id.proto_id > SCSI_PROTOCOL_UNSPEC)
+       if (pp->sg_id.proto_id < 0)
                return SYSFS_BUS_UNDEF;
-       return SYSFS_BUS_SCSI + pp->sg_id.proto_id;
+       if (pp->bus == SYSFS_BUS_SCSI &&
+           pp->sg_id.proto_id > SCSI_PROTOCOL_UNSPEC)
+               return SYSFS_BUS_UNDEF;
+       if (pp->bus == SYSFS_BUS_NVME &&
+           pp->sg_id.proto_id > NVME_PROTOCOL_UNSPEC)
+               return SYSFS_BUS_UNDEF;
+       return pp->bus + pp->sg_id.proto_id;
 }

libmultipath/structs.h +0 -0
index d3054662..9e2c1ab0 100644
@@ -56,15 +56,6 @@ enum failback_mode {

        FAILBACK_FOLLOWOVER
 };

libmultipath/structs.h +0 -9
-/* SYSFS_BUS_SCSI should be last, see bus_protocol_id() */
-enum sysfs_buses {
-       SYSFS_BUS_UNDEF,
-       SYSFS_BUS_CCW,
-       SYSFS_BUS_CCISS,
-       SYSFS_BUS_NVME,
-       SYSFS_BUS_SCSI,
-};
-

 enum pathstates {
        PSTATE_UNDEF,
        PSTATE_FAILED,

libmultipath/structs.h +0 -0
@@ -190,14 +181,32 @@ enum scsi_protocol {
         SCSI_PROTOCOL_ATA = 8,

        SCSI_PROTOCOL_USB = 9,  /* USB Attached SCSI (UAS), and others */
        SCSI_PROTOCOL_UNSPEC = 0xa, /* No specific protocol */ +       SCSI_PROTOCOL_END = 0xb, /* offset of the next sysfs_buses entry */

libmultipath/structs.h +19 -0
+};
+
+/* values from /sys/class/nvme/nvmeX */
+enum nvme_protocol {
+       NVME_PROTOCOL_PCIE = 0,
+       NVME_PROTOCOL_RDMA = 1,
+       NVME_PROTOCOL_FC = 2,
+       NVME_PROTOCOL_TCP = 3,
+       NVME_PROTOCOL_LOOP = 4,
+       NVME_PROTOCOL_APPLE_NVME = 5,
+       NVME_PROTOCOL_UNSPEC = 6, /* unknown protocol */
+};
+
+enum sysfs_buses {
+       SYSFS_BUS_UNDEF,
+       SYSFS_BUS_CCW,
+       SYSFS_BUS_CCISS,
+       SYSFS_BUS_SCSI,
+       SYSFS_BUS_NVME = SYSFS_BUS_SCSI + SCSI_PROTOCOL_END,

 };

 /*
  * Linear ordering of bus/protocol
- * This assumes that SYSFS_BUS_SCSI is last in enum sysfs_buses
- * SCSI is the only bus type for which we distinguish protocols. */

libmultipath/structs.h +1 -1
-#define LAST_BUS_PROTOCOL_ID (SYSFS_BUS_SCSI + SCSI_PROTOCOL_UNSPEC)
+#define LAST_BUS_PROTOCOL_ID (SYSFS_BUS_NVME + NVME_PROTOCOL_UNSPEC)

 unsigned int bus_protocol_id(const struct path *pp); extern const char * const protocol_name[];

multipath/multipath.conf.5 +0 -0
index 46a4126c..07476497 100644
@@ -1377,7 +1377,9 @@ Regular expression for the protocol of a device

to be excluded/included.
 The protocol strings that multipath recognizes are \fIscsi:fcp\fR, \fIscsi:spi\fR, \fIscsi:ssa\fR, \fIscsi:sbp\fR, \fIscsi:srp\fR, \fIscsi:iscsi\fR, \fIscsi:sas\fR, \fIscsi:adt\fR, \fIscsi:ata\fR, -\fIscsi:unspec\fR, \fIccw\fR, \fIcciss\fR, \fInvme\fR, and \fIundef\fR.
+\fIscsi:unspec\fR, \fInvme:pcie\fR, \fInvme:rdma\fR, \fInvme:fc\fR, +\fInvme:tcp\fR, \fInvme:loop\fR, \fInvme:apple-nvme\fR, \fInvme:unspec\fR,
+\fIccw\fR, \fIcciss\fR, and \fIundef\fR.
 The protocol that a path is using can be viewed by running \fBmultipathd show paths format "%d %P"\fR
 .RE

multipath/multipath.conf.5 +0 -0
@@ -1773,7 +1775,9 @@ The protocol subsection recognizes the

following mandatory attribute:
 The protocol string of the path device. The possible values are \fIscsi:fcp\fR,
 \fIscsi:spi\fR, \fIscsi:ssa\fR, \fIscsi:sbp\fR, \fIscsi:srp\fR, \fIscsi:iscsi\fR, \fIscsi:sas\fR, \fIscsi:adt\fR, \fIscsi:ata\fR, -\fIscsi:unspec\fR, \fIccw\fR, \fIcciss\fR, \fInvme\fR, and \fIundef\fR. This is

Quoted 8 lines

+\fIscsi:unspec\fR, \fInvme:pcie\fR, \fInvme:rdma\fR, \fInvme:fc\fR, +\fInvme:tcp\fR, \fInvme:loop\fR, \fInvme:apple-nvme\fR, \fInvme:unspec\fR,
+\fIccw\fR, \fIcciss\fR, and \fIundef\fR. This is \fBnot\fR a regular expression. the path device protocol string must match
 exactly. The protocol that a path is using can be viewed by running \fBmultipathd show paths format "%d %P"\fR

--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel

author maintainer
#15 lore raw

PATCH 8/8 libmultipath: enforce queue_mode bio for nmve:tcp paths

In reply to Benjamin Marzinski

nvme:tcp devices set BLK_MQ_F_BLOCKING (they are the only block devices which multipath supports that do so), meaning that block_mq expects that they can block at certain points while servicing a request. However, due to the way device-mapper sets up its queue, it is not able to set BLK_MQ_F_BLOCKING when it includes paths that set this flag. Patches were written to address this issue but they were rejected upstream

https://lore.kernel.org/linux-block/YcH%[email protected]/T/#t

The proposed solution was to have multipath use the bio queue_mode for multipath devices that include nvme:tcp paths.

Multipath devices now automatically add the "queue_mode bio" feature if they include nvme:tcp paths. If a multipath devices was created with "queue_mode rq", it will disallow the addition of nvme:tcp paths.

---
 libmultipath/configure.c   | 17 ++++++++++++++++-
 libmultipath/structs_vec.c |  7 +++++++
 multipath/multipath.conf.5 |  4 +++-
 3 files changed, 26 insertions(+), 2 deletions(-)
libmultipath/configure.c +16 -1
index 7c7babd9..e5249fc1 100644
@@ -260,6 +260,7 @@ int rr_optimize_path_order(struct pathgroup *pgp)
 int setup_map(struct multipath *mpp, char **params, struct vectors *vecs)
 {
 	struct pathgroup * pgp;
+	struct path *pp;
 	struct config *conf;
 	int i, marginal_pathgroups;
 	char *save_attr;
@@ -275,6 +276,14 @@ int setup_map(struct multipath *mpp, char **params, struct vectors *vecs)
 	if (mpp->disable_queueing && VECTOR_SIZE(mpp->paths) != 0)
 		mpp->disable_queueing = 0;
 
+	/* Force QUEUE_MODE_BIO for maps with nvme:tcp paths */
+	vector_foreach_slot(mpp->paths, pp, i) {
+		if (pp->bus == SYSFS_BUS_NVME &&
+		    pp->sg_id.proto_id == NVME_PROTOCOL_TCP) {
+			mpp->queue_mode = QUEUE_MODE_BIO;
+			break;
+		}
+	}
 	/*
 	 * If this map was created with add_map_without_path(),
 	 * mpp->hwe might not be set yet.
@@ -1148,6 +1157,13 @@ int coalesce_paths (struct vectors *vecs, vector mpvec, char *refwwid,
 			continue;
 		}
 
+		cmpp = find_mp_by_wwid(curmp, pp1->wwid);
+		if (cmpp && cmpp->queue_mode == QUEUE_MODE_RQ &&
+		    pp1->bus == SYSFS_BUS_NVME && pp1->sg_id.proto_id ==
+		    NVME_PROTOCOL_TCP) {
+			orphan_path(pp1, "nvme:tcp path not allowed with request queue_mode multipath device");
+			continue;
+		}
 		/*
 		 * at this point, we know we really got a new mp
 		 */
@@ -1186,7 +1202,6 @@ int coalesce_paths (struct vectors *vecs, vector mpvec, char *refwwid,
 		}
 		verify_paths(mpp);
 
-		cmpp = find_mp_by_wwid(curmp, mpp->wwid);
 		if (cmpp)
 			mpp->queue_mode = cmpp->queue_mode;
 		if (setup_map(mpp, &params, vecs)) {
libmultipath/structs_vec.c +7 -0
index 645896c6..5a618767 100644
@@ -264,6 +264,13 @@ int adopt_paths(vector pathvec, struct multipath *mpp)
 			}
 			if (pp->initialized == INIT_REMOVED)
 				continue;
+			if (mpp->queue_mode == QUEUE_MODE_RQ &&
+			    pp->bus == SYSFS_BUS_NVME &&
+			    pp->sg_id.proto_id == NVME_PROTOCOL_TCP) {
+				condlog(2, "%s: mulitpath device %s created with request queue_mode. Unable to add nvme:tcp paths",
+					pp->dev, mpp->alias);
+				continue;
+			}
 			if (!mpp->paths && !(mpp->paths = vector_alloc()))
 				goto err;
 
multipath/multipath.conf.5 +3 -1
index 07476497..1fea9d5a 100644
@@ -463,7 +463,9 @@ Before kernel 4.20 The default depends on the kernel parameter
 \fBdm_mod.use_blk_mq\fR. It is \fImq\fR if the latter is set, and \fIrq\fR
 otherwise. Since kernel 4.20, \fIrq\fR and \fImq\fR both correspond to
 block-multiqueue. Once a multipath device has been created, its queue_mode
-cannot be changed.
+cannot be changed. \fInvme:tcp\fR paths are only supported in multipath
+devices with queue_mode set to \fIbio\fR. multipath will automatically
+set this when creating a device with \fInvme:tcp\fR paths.
 .TP
 The default is: \fB<unset>\fR
 .RE
Signature · 6 lines
2.17.2

--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel
Reviewed-by on v1 8/8
#16 lore raw

Re: [dm-devel] [PATCH 8/8] libmultipath: enforce queue_mode bio for nmve:tcp paths

Quoted 15 lines · Benjamin Marzinski

nvme:tcp devices set BLK_MQ_F_BLOCKING (they are the only block devices
which multipath supports that do so), meaning that block_mq expects that
they can block at certain points while servicing a request.  However, due to the way device-mapper sets up its queue, it is not able to set BLK_MQ_F_BLOCKING when it includes paths that set this flag.  Patches were written to address this issue but they were rejected upstream

https://lore.kernel.org/linux-block/YcH%[email protected]/T/#t

The proposed solution was to have multipath use the bio queue_mode for
multipath devices that include nvme:tcp paths.

Quoted 6 lines

Multipath devices now automatically add the "queue_mode bio" feature if
they include nvme:tcp paths.  If a multipath devices was created with "queue_mode rq", it will disallow the addition of nvme:tcp paths.

Quoted 97 lines

---
 libmultipath/configure.c   | 17 ++++++++++++++++- libmultipath/structs_vec.c |  7 +++++++ multipath/multipath.conf.5 |  4 +++-

 3 files changed, 26 insertions(+), 2 deletions(-)
libmultipath/configure.c +0 -0
index 7c7babd9..e5249fc1 100644
@@ -260,6 +260,7 @@ int rr_optimize_path_order(struct pathgroup *pgp)

 int setup_map(struct multipath *mpp, char **params, struct vectors *vecs)
 {
        struct pathgroup * pgp;
+       struct path *pp;
        struct config *conf;
        int i, marginal_pathgroups;
        char *save_attr;

libmultipath/configure.c +0 -0
@@ -275,6 +276,14 @@ int setup_map(struct multipath *mpp, char
 **params, struct vectors *vecs)
         if (mpp->disable_queueing && VECTOR_SIZE(mpp->paths) != 0)
                 mpp->disable_queueing = 0;


+       /* Force QUEUE_MODE_BIO for maps with nvme:tcp paths */ +       vector_foreach_slot(mpp->paths, pp, i) {
+               if (pp->bus == SYSFS_BUS_NVME &&
+                   pp->sg_id.proto_id == NVME_PROTOCOL_TCP) { +                       mpp->queue_mode = QUEUE_MODE_BIO; +                       break;
+               }
+       }
        /*
         * If this map was created with add_map_without_path(),
         * mpp->hwe might not be set yet.

libmultipath/configure.c +0 -0
@@ -1148,6 +1157,13 @@ int coalesce_paths (struct vectors *vecs,
 vector mpvec, char *refwwid,
                         continue;
                 }


+               cmpp = find_mp_by_wwid(curmp, pp1->wwid); +               if (cmpp && cmpp->queue_mode == QUEUE_MODE_RQ && +                   pp1->bus == SYSFS_BUS_NVME && pp1->sg_id.proto_id ==
+                   NVME_PROTOCOL_TCP) {
+                       orphan_path(pp1, "nvme:tcp path not allowed with request queue_mode multipath device");
+                       continue;
+               }
                /*
                 * at this point, we know we really got a new mp */

libmultipath/configure.c +0 -0
@@ -1186,7 +1202,6 @@ int coalesce_paths (struct vectors *vecs,
 vector mpvec, char *refwwid,
                 }
                 verify_paths(mpp);


-               cmpp = find_mp_by_wwid(curmp, mpp->wwid); if (cmpp)
                        mpp->queue_mode = cmpp->queue_mode; if (setup_map(mpp, &params, vecs)) {

libmultipath/structs_vec.c +7 -0
index 645896c6..5a618767 100644
@@ -264,6 +264,13 @@ int adopt_paths(vector pathvec, struct multipath
 *mpp)
                         }
                         if (pp->initialized == INIT_REMOVED)
                                 continue;
+                       if (mpp->queue_mode == QUEUE_MODE_RQ &&
+                           pp->bus == SYSFS_BUS_NVME &&
+                           pp->sg_id.proto_id == NVME_PROTOCOL_TCP)
 {
+                               condlog(2, "%s: mulitpath device %s
 created with request queue_mode. Unable to add nvme:tcp paths",
+                                       pp->dev, mpp->alias);
+                               continue;
+                       }

                        if (!mpp->paths && !(mpp->paths = vector_alloc()))
                                goto err;

multipath/multipath.conf.5 +0 -0
index 07476497..1fea9d5a 100644
@@ -463,7 +463,9 @@ Before kernel 4.20 The default depends on the

kernel parameter
 \fBdm_mod.use_blk_mq\fR. It is \fImq\fR if the latter is set, and \fIrq\fR
 otherwise. Since kernel 4.20, \fIrq\fR and \fImq\fR both correspond to
 block-multiqueue. Once a multipath device has been created, its queue_mode

multipath/multipath.conf.5 +1 -1
-cannot be changed.
+cannot be changed. \fInvme:tcp\fR paths are only supported in
Quoted 7 lines

multipath
+devices with queue_mode set to \fIbio\fR. multipath will automatically
+set this when creating a device with \fInvme:tcp\fR paths. .TP
 The default is: \fB<unset>\fR
 .RE

--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel

Reviewed-by on the v1 series
#17 lore raw
In reply to Benjamin Marzinski
Quoted 9 lines · Benjamin Marzinski

nvme:tcp devices set BLK_MQ_F_BLOCKING (they are the only block devices
which multipath supports that do so), meaning that block_mq expects that
they can block at certain points while servicing a request.  However, due to the way device-mapper sets up its queue, it is not able to set BLK_MQ_F_BLOCKING when it includes paths that set this flag.  Patches were written to address this issue but they were rejected upstream

Quoted 5 lines

https://lore.kernel.org/linux-block/YcH%[email protected]/T/#t

The proposed solution was to have multipath use the bio queue_mode for
multipath devices that include nvme:tcp paths.

Request-based dm-multipath is superior to bio-based in multiple ways. I thought that was consensus. It's sad that we need to make this clumsy workaround in user space while a much neater kernel-side approach would be available.

Quoted 32 lines

Multipathd currently doesn't handle queue_mode as well as it could. Once
a multipath device is created, queue_mode cannot be changed, but multipath doesn't enforce this. This patchset improves multipath's handling of the queue_mode feature, and then makes sure that if a multipath device includes a nvme:tcp path, it will have queue_mode set to bio.

Benjamin Marzinski (8):
  libmultipath: cleanup remove_feature
  libmultipath: cleanup add_feature
  multipath tests: tests for adding and removing features
  libmultipath: fix queue_mode feature handling multipath tests: tests for reconcile_features_with_queue_mode
  libmultipath: prepare proto_id for use by non-scsi devivces
  libmultipath: get nvme path transport protocol
  libmultipath: enforce queue_mode bio for nmve:tcp paths

 libmultipath/configure.c   |  28 +-
 libmultipath/discovery.c   |  31 ++-
 libmultipath/dmparser.c    |   2 +
 libmultipath/print.c       |   6 +-

 libmultipath/propsel.c     |  55 ++++
 libmultipath/structs.c     | 155 +++++------
 libmultipath/structs.h     |  44 ++-
 libmultipath/structs_vec.c |   7 +
 multipath/multipath.conf.5 |  17 +-
 multipathd/fpin_handlers.c |   2 +-
 tests/Makefile             |   4 +-
 tests/features.c           | 549
+++++++++++++++++++++++++++++++++++++
 12 files changed, 784 insertions(+), 116 deletions(-)
Quoted 2 lines

 create mode 100644 tests/features.c

For the series:

I have a few remarks and suggestions for additional improvement which I'll send as replies to the individual patches.

--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel