dm-devel.redhat.com archive mirror
 help / color / mirror / Atom feed
* [dm-devel] [PATCH]multipath-tools: fix "multipath -ll" bug for Native NVME Multipath devices
@ 2021-09-27  1:42 chengjike
  0 siblings, 0 replies; 4+ messages in thread
From: chengjike @ 2021-09-27  1:42 UTC (permalink / raw)
  To: dm-devel, christophe.varoqui; +Cc: sunao.sun, jiangtao62, chengjike.cheng

After "Native NVME Multipath" is configured,
the content displayed is incorrect when you run "multipath -ll" command.
Each NVME devices have the same path name. For example:

[root@localhost home]# multipath -ll
eui.710032e8fb22a86c24a52c1000000db8 [nvme]:nvme1n1 NVMe,Huawei-XSG1,1000001
size=10485760 features='n/a' hwhandler='ANA' wp=rw
|-+- policy='n/a' prio=50 status=optimized
| `- 1:4:1   nvme1c4n1 0:0 n/a   optimized live
`-+- policy='n/a' prio=50 status=optimized
  `- 1:9:1   nvme1c9n1 0:0 n/a   optimized live
eui.710032e8fb22a86b24a52c7c00000db7 [nvme]:nvme1n2 NVMe,Huawei-XSG1,1000001
size=10485760 features='n/a' hwhandler='ANA' wp=rw
|-+- policy='n/a' prio=50 status=optimized
| `- 1:4:1   nvme1c4n1 0:0 n/a   optimized live
`-+- policy='n/a' prio=50 status=optimized
  `- 1:9:1   nvme1c9n1 0:0 n/a   optimized live
[root@localhost home]#

The logical paths of "nvme1n1" and "nvme1n2" are both "nvme1c4n1" and "nvme1c9n1".
So when filtering logical paths, use "nvme_ns_head->instance" for matching.

Signed-off-by: chengjike <chengjike.cheng@huawei.com>
---
 libmultipath/foreign/nvme.c | 26 ++++++++++++++++++++------
 1 file changed, 20 insertions(+), 6 deletions(-)

diff --git a/libmultipath/foreign/nvme.c b/libmultipath/foreign/nvme.c
index d40c0869..38580880 100644
--- a/libmultipath/foreign/nvme.c
+++ b/libmultipath/foreign/nvme.c
@@ -530,14 +530,18 @@ static int _dirent_controller(const struct dirent *di)
 
 /* Find the block device for a given nvme controller */
 struct udev_device *get_ctrl_blkdev(const struct context *ctx,
-				    struct udev_device *ctrl)
+				    struct udev_device *ctrl, const char *ctrl_name)
 {
+	int ctrl_num, ns_num; 
 	struct udev_list_entry *item;
 	struct udev_device *blkdev = NULL;
 	struct udev_enumerate *enm = udev_enumerate_new(ctx->udev);
 	const char *devtype;
 
-	if (enm == NULL)
+	if (enm == NULL || ctrl_name == NULL)
+		return NULL;
+
+	if (sscanf(ctrl_name, "nvme%dn%d", &ctrl_num, &ns_num) != 2)
 		return NULL;
 
 	pthread_cleanup_push(_udev_enumerate_unref, enm);
@@ -555,6 +559,8 @@ struct udev_device *get_ctrl_blkdev(const struct context *ctx,
 	     item != NULL;
 	     item = udev_list_entry_get_next(item)) {
 		struct udev_device *tmp;
+		const char *name = NULL ;
+		int m, n, l;
 
 		tmp = udev_device_new_from_syspath(ctx->udev,
 					   udev_list_entry_get_name(item));
@@ -562,11 +568,19 @@ struct udev_device *get_ctrl_blkdev(const struct context *ctx,
 			continue;
 
 		devtype = udev_device_get_devtype(tmp);
-		if (devtype && !strcmp(devtype, "disk")) {
+		if (devtype == NULL || strcmp(devtype, "disk")) {
+			udev_device_unref(tmp);
+			continue;
+		}
+
+		name = udev_device_get_sysname(tmp);
+		if (name != NULL && 
+			sscanf(name, "nvme%dc%dn%d", &m, &n, &l) == 3 &&
+			l == ns_num) {
 			blkdev = tmp;
 			break;
-		} else
-			udev_device_unref(tmp);
+		}
+		udev_device_unref(tmp);
 	}
 
 	if (blkdev == NULL)
@@ -679,7 +693,7 @@ static void _find_controllers(struct context *ctx, struct nvme_map *map)
 		}
 
 		pthread_cleanup_push(_udev_device_unref, ctrl);
-		udev = get_ctrl_blkdev(ctx, ctrl);
+		udev = get_ctrl_blkdev(ctx, ctrl, udev_device_get_sysname(map->udev));
 		/*
 		 * We give up the reference to the nvme device here and get
 		 * it back from the child below.
-- 
2.21.0.windows.1


--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [dm-devel] [PATCH]multipath-tools: fix "multipath -ll" bug for Native NVME Multipath devices
  2021-10-08 12:24 chengjike
  2021-10-20 16:03 ` Martin Wilck
@ 2022-06-17 14:33 ` Martin Wilck
  1 sibling, 0 replies; 4+ messages in thread
From: Martin Wilck @ 2022-06-17 14:33 UTC (permalink / raw)
  To: chengjike, dm-devel, christophe.varoqui, xose.vazquez
  Cc: sunao.sun, jiangtao62

On Fri, 2021-10-08 at 20:24 +0800, chengjike wrote:
> After "Native NVME Multipath" is configured,
> the content displayed is incorrect when you run "multipath -ll"
> command.
> Each NVME devices have the same path name. For example:
> 
> [root@localhost home]# multipath -ll
> eui.710032e8fb22a86c24a52c1000000db8 [nvme]:nvme1n1 NVMe,Huawei-
> XSG1,1000001
> size=10485760 features='n/a' hwhandler='ANA' wp=rw
> > -+- policy='n/a' prio=50 status=optimized
> > `- 1:4:1   nvme1c4n1 0:0 n/a   optimized live
> `-+- policy='n/a' prio=50 status=optimized
>   `- 1:9:1   nvme1c9n1 0:0 n/a   optimized live
> eui.710032e8fb22a86b24a52c7c00000db7 [nvme]:nvme1n2 NVMe,Huawei-
> XSG1,1000001
> size=10485760 features='n/a' hwhandler='ANA' wp=rw
> > -+- policy='n/a' prio=50 status=optimized
> > `- 1:4:1   nvme1c4n1 0:0 n/a   optimized live
> `-+- policy='n/a' prio=50 status=optimized
>   `- 1:9:1   nvme1c9n1 0:0 n/a   optimized live
> [root@localhost home]#
> 
> The logical paths of "nvme1n1" and "nvme1n2" are both "nvme1c4n1" and
> "nvme1c9n1".
> So when multipath-tools aggregates disks, use "nvme_ns_head-
> >instance" for matching.
> such as ,Use "b" in "nvmeanb" string to match "z" in
> "nvmexcynz"(a,b,x,y,z can be any number),
> and if "b" and "z" are the same, they are related.
> 
> Signed-off-by: chengjike <chengjike.cheng@huawei.com>

Reviewed-by: Martin Wilck <mwilck@suse.com>

Thanks a lot, and sorry for the late reply. This somehow got lost in my
inbox.

Regards,
Martin

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [dm-devel] [PATCH]multipath-tools: fix "multipath -ll" bug for Native NVME Multipath devices
  2021-10-08 12:24 chengjike
@ 2021-10-20 16:03 ` Martin Wilck
  2022-06-17 14:33 ` Martin Wilck
  1 sibling, 0 replies; 4+ messages in thread
From: Martin Wilck @ 2021-10-20 16:03 UTC (permalink / raw)
  To: chengjike, dm-devel, christophe.varoqui, xose.vazquez
  Cc: sunao.sun, jiangtao62

On Fri, 2021-10-08 at 20:24 +0800, chengjike wrote:
> After "Native NVME Multipath" is configured,
> the content displayed is incorrect when you run "multipath -ll"
> command.
> Each NVME devices have the same path name. For example:
> 
> [root@localhost home]# multipath -ll
> eui.710032e8fb22a86c24a52c1000000db8 [nvme]:nvme1n1 NVMe,Huawei-
> XSG1,1000001
> size=10485760 features='n/a' hwhandler='ANA' wp=rw
> > -+- policy='n/a' prio=50 status=optimized
> > `- 1:4:1   nvme1c4n1 0:0 n/a   optimized live
> `-+- policy='n/a' prio=50 status=optimized
>   `- 1:9:1   nvme1c9n1 0:0 n/a   optimized live
> eui.710032e8fb22a86b24a52c7c00000db7 [nvme]:nvme1n2 NVMe,Huawei-
> XSG1,1000001
> size=10485760 features='n/a' hwhandler='ANA' wp=rw
> > -+- policy='n/a' prio=50 status=optimized
> > `- 1:4:1   nvme1c4n1 0:0 n/a   optimized live
> `-+- policy='n/a' prio=50 status=optimized
>   `- 1:9:1   nvme1c9n1 0:0 n/a   optimized live
> [root@localhost home]#
> 
> The logical paths of "nvme1n1" and "nvme1n2" are both "nvme1c4n1" and
> "nvme1c9n1".
> So when multipath-tools aggregates disks, use "nvme_ns_head-
> >instance" for matching.
> such as ,Use "b" in "nvmeanb" string to match "z" in
> "nvmexcynz"(a,b,x,y,z can be any number),
> and if "b" and "z" are the same, they are related.
> 
> Signed-off-by: chengjike <chengjike.cheng@huawei.com>

Reviewed-by: Martin Wilck <mwilck@suse.com>

Thanks!!


--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [dm-devel] [PATCH]multipath-tools: fix "multipath -ll" bug for Native NVME Multipath devices
@ 2021-10-08 12:24 chengjike
  2021-10-20 16:03 ` Martin Wilck
  2022-06-17 14:33 ` Martin Wilck
  0 siblings, 2 replies; 4+ messages in thread
From: chengjike @ 2021-10-08 12:24 UTC (permalink / raw)
  To: dm-devel, christophe.varoqui, mwilck, xose.vazquez
  Cc: sunao.sun, jiangtao62, chengjike.cheng

After "Native NVME Multipath" is configured,
the content displayed is incorrect when you run "multipath -ll" command.
Each NVME devices have the same path name. For example:

[root@localhost home]# multipath -ll
eui.710032e8fb22a86c24a52c1000000db8 [nvme]:nvme1n1 NVMe,Huawei-XSG1,1000001
size=10485760 features='n/a' hwhandler='ANA' wp=rw
|-+- policy='n/a' prio=50 status=optimized
| `- 1:4:1   nvme1c4n1 0:0 n/a   optimized live
`-+- policy='n/a' prio=50 status=optimized
  `- 1:9:1   nvme1c9n1 0:0 n/a   optimized live
eui.710032e8fb22a86b24a52c7c00000db7 [nvme]:nvme1n2 NVMe,Huawei-XSG1,1000001
size=10485760 features='n/a' hwhandler='ANA' wp=rw
|-+- policy='n/a' prio=50 status=optimized
| `- 1:4:1   nvme1c4n1 0:0 n/a   optimized live
`-+- policy='n/a' prio=50 status=optimized
  `- 1:9:1   nvme1c9n1 0:0 n/a   optimized live
[root@localhost home]#

The logical paths of "nvme1n1" and "nvme1n2" are both "nvme1c4n1" and "nvme1c9n1".
So when multipath-tools aggregates disks, use "nvme_ns_head->instance" for matching.
such as ,Use "b" in "nvmeanb" string to match "z" in "nvmexcynz"(a,b,x,y,z can be any number),
and if "b" and "z" are the same, they are related.

Signed-off-by: chengjike <chengjike.cheng@huawei.com>
---
 libmultipath/foreign/nvme.c | 26 ++++++++++++++++++++------
 1 file changed, 20 insertions(+), 6 deletions(-)

diff --git a/libmultipath/foreign/nvme.c b/libmultipath/foreign/nvme.c
index d40c0869..38580880 100644
--- a/libmultipath/foreign/nvme.c
+++ b/libmultipath/foreign/nvme.c
@@ -530,14 +530,18 @@ static int _dirent_controller(const struct dirent *di)
 
 /* Find the block device for a given nvme controller */
 struct udev_device *get_ctrl_blkdev(const struct context *ctx,
-				    struct udev_device *ctrl)
+				    struct udev_device *ctrl, const char *ctrl_name)
 {
+	int ctrl_num, ns_num; 
 	struct udev_list_entry *item;
 	struct udev_device *blkdev = NULL;
 	struct udev_enumerate *enm = udev_enumerate_new(ctx->udev);
 	const char *devtype;
 
-	if (enm == NULL)
+	if (enm == NULL || ctrl_name == NULL)
+		return NULL;
+
+	if (sscanf(ctrl_name, "nvme%dn%d", &ctrl_num, &ns_num) != 2)
 		return NULL;
 
 	pthread_cleanup_push(_udev_enumerate_unref, enm);
@@ -555,6 +559,8 @@ struct udev_device *get_ctrl_blkdev(const struct context *ctx,
 	     item != NULL;
 	     item = udev_list_entry_get_next(item)) {
 		struct udev_device *tmp;
+		const char *name = NULL ;
+		int m, n, l;
 
 		tmp = udev_device_new_from_syspath(ctx->udev,
 					   udev_list_entry_get_name(item));
@@ -562,11 +568,19 @@ struct udev_device *get_ctrl_blkdev(const struct context *ctx,
 			continue;
 
 		devtype = udev_device_get_devtype(tmp);
-		if (devtype && !strcmp(devtype, "disk")) {
+		if (devtype == NULL || strcmp(devtype, "disk")) {
+			udev_device_unref(tmp);
+			continue;
+		}
+
+		name = udev_device_get_sysname(tmp);
+		if (name != NULL && 
+			sscanf(name, "nvme%dc%dn%d", &m, &n, &l) == 3 &&
+			l == ns_num) {
 			blkdev = tmp;
 			break;
-		} else
-			udev_device_unref(tmp);
+		}
+		udev_device_unref(tmp);
 	}
 
 	if (blkdev == NULL)
@@ -679,7 +693,7 @@ static void _find_controllers(struct context *ctx, struct nvme_map *map)
 		}
 
 		pthread_cleanup_push(_udev_device_unref, ctrl);
-		udev = get_ctrl_blkdev(ctx, ctrl);
+		udev = get_ctrl_blkdev(ctx, ctrl, udev_device_get_sysname(map->udev));
 		/*
 		 * We give up the reference to the nvme device here and get
 		 * it back from the child below.
-- 
2.21.0.windows.1


--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-06-17 14:34 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-27  1:42 [dm-devel] [PATCH]multipath-tools: fix "multipath -ll" bug for Native NVME Multipath devices chengjike
2021-10-08 12:24 chengjike
2021-10-20 16:03 ` Martin Wilck
2022-06-17 14:33 ` Martin Wilck

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).