All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] nvme: add namespace paths links
@ 2023-09-08  6:57 Hannes Reinecke
  2023-09-12 11:43 ` Sagi Grimberg
  0 siblings, 1 reply; 18+ messages in thread
From: Hannes Reinecke @ 2023-09-08  6:57 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: Sagi Grimberg, Keith Busch, linux-nvme, Hannes Reinecke

It is really annoying to always have to loop through the entire
/sys/block directory just to find the namespace path links for
a single namespace in libnvme/nvme-cli.
So provide links to the namespace paths for efficient lookup.

Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 drivers/nvme/host/core.c      |  3 +++
 drivers/nvme/host/multipath.c | 10 ++++++++++
 2 files changed, 13 insertions(+)

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 37b6fa746662..88933838e067 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -3681,6 +3681,9 @@ static void nvme_ns_remove(struct nvme_ns *ns)
 
 	if (!nvme_ns_head_multipath(ns->head))
 		nvme_cdev_del(&ns->cdev, &ns->cdev_device);
+	else
+		sysfs_remove_link(&disk_to_dev(ns->head->disk)->kobj,
+				  ns->disk->disk_name);
 	del_gendisk(ns->disk);
 
 	down_write(&ns->ctrl->namespaces_rwsem);
diff --git a/drivers/nvme/host/multipath.c b/drivers/nvme/host/multipath.c
index 0a88d7bdc5e3..9dd0be645dad 100644
--- a/drivers/nvme/host/multipath.c
+++ b/drivers/nvme/host/multipath.c
@@ -875,6 +875,16 @@ void nvme_mpath_add_disk(struct nvme_ns *ns, __le32 anagrpid)
 	if (blk_queue_is_zoned(ns->queue) && ns->head->disk)
 		ns->head->disk->nr_zones = ns->disk->nr_zones;
 #endif
+	if (ns->head->disk) {
+		int ret;
+
+		ret = sysfs_create_link(&disk_to_dev(ns->head->disk)->kobj,
+					&disk_to_dev(ns->disk)->kobj,
+					ns->disk->disk_name);
+		if (ret)
+			dev_warn(ns->ctrl->device,
+				 "failed to create namespace path link\n");
+	}
 }
 
 void nvme_mpath_shutdown_disk(struct nvme_ns_head *head)
-- 
2.35.3



^ permalink raw reply related	[flat|nested] 18+ messages in thread
* [PATCH] nvme: add namespace paths links
@ 2022-04-01  9:28 Hannes Reinecke
  2022-04-05  5:42 ` Christoph Hellwig
  0 siblings, 1 reply; 18+ messages in thread
From: Hannes Reinecke @ 2022-04-01  9:28 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: Sagi Grimberg, Keith Busch, linux-nvme, Hannes Reinecke

It is really annoying to always have to loop through the entire
/sys/block directory just to find the namespace path links for
a single namespace in libnvme/nvme-cli.
So provide links to the namespace paths for efficient lookup.

Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 drivers/nvme/host/core.c      | 3 +++
 drivers/nvme/host/multipath.c | 8 ++++++++
 2 files changed, 11 insertions(+)

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index f204c6f78b5b..df4d89aa061f 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -4054,6 +4054,9 @@ static void nvme_ns_remove(struct nvme_ns *ns)
 
 	if (!nvme_ns_head_multipath(ns->head))
 		nvme_cdev_del(&ns->cdev, &ns->cdev_device);
+	else
+		sysfs_remove_link(&disk_to_dev(ns->head->disk)->kobj,
+				  ns->disk->disk_name);
 	del_gendisk(ns->disk);
 	blk_cleanup_queue(ns->queue);
 
diff --git a/drivers/nvme/host/multipath.c b/drivers/nvme/host/multipath.c
index 7fc58e1f6b09..dc9a4018f90d 100644
--- a/drivers/nvme/host/multipath.c
+++ b/drivers/nvme/host/multipath.c
@@ -801,6 +801,8 @@ static int nvme_lookup_ana_group_desc(struct nvme_ctrl *ctrl,
 
 void nvme_mpath_add_disk(struct nvme_ns *ns, struct nvme_id_ns *id)
 {
+	int ret;
+
 	if (nvme_ctrl_use_ana(ns->ctrl)) {
 		struct nvme_ana_group_desc desc = {
 			.grpid = id->anagrpid,
@@ -831,6 +833,12 @@ void nvme_mpath_add_disk(struct nvme_ns *ns, struct nvme_id_ns *id)
 	if (blk_queue_is_zoned(ns->queue) && ns->head->disk)
 		ns->head->disk->queue->nr_zones = ns->queue->nr_zones;
 #endif
+	ret = sysfs_create_link(&disk_to_dev(ns->head->disk)->kobj,
+				&disk_to_dev(ns->disk)->kobj,
+				ns->disk->disk_name);
+	if (ret)
+		dev_warn(ns->ctrl->device,
+			 "failed to create namespace path link\n");
 }
 
 void nvme_mpath_shutdown_disk(struct nvme_ns_head *head)
-- 
2.29.2



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

end of thread, other threads:[~2023-12-08 15:35 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-08  6:57 [PATCH] nvme: add namespace paths links Hannes Reinecke
2023-09-12 11:43 ` Sagi Grimberg
2023-09-12 11:51   ` Hannes Reinecke
2023-09-12 12:55     ` Sagi Grimberg
2023-09-12 14:04       ` Hannes Reinecke
2023-12-04 10:25         ` Sagi Grimberg
2023-12-04 11:19           ` Hannes Reinecke
2023-12-04 11:58             ` Sagi Grimberg
2023-12-08 15:34               ` Daniel Wagner
  -- strict thread matches above, loose matches on Subject: below --
2022-04-01  9:28 Hannes Reinecke
2022-04-05  5:42 ` Christoph Hellwig
2022-04-05  5:46   ` Hannes Reinecke
2022-04-05  5:48     ` Christoph Hellwig
2022-04-05  8:34       ` Sagi Grimberg
2022-04-05  9:51         ` Hannes Reinecke
2022-04-05 10:22           ` Sagi Grimberg
2022-04-25 13:54       ` Karel Zak
2022-07-29 11:43         ` Hannes Reinecke

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.