linux-nvme.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Hannes Reinecke <hare@suse.de>
To: Christoph Hellwig <hch@lst.de>
Cc: Sagi Grimberg <sagi@grimberg.me>, Keith Busch <kbusch@kernel.org>,
	linux-nvme@lists.infradead.org, Hannes Reinecke <hare@suse.de>
Subject: [PATCH] nvme: add namespace paths links
Date: Fri,  8 Sep 2023 08:57:17 +0200	[thread overview]
Message-ID: <20230908065717.92207-1-hare@suse.de> (raw)

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



             reply	other threads:[~2023-09-08  6:57 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-08  6:57 Hannes Reinecke [this message]
2023-09-12 11:43 ` [PATCH] nvme: add namespace paths links 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

Reply instructions:

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

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

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

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

  git send-email \
    --in-reply-to=20230908065717.92207-1-hare@suse.de \
    --to=hare@suse.de \
    --cc=hch@lst.de \
    --cc=kbusch@kernel.org \
    --cc=linux-nvme@lists.infradead.org \
    --cc=sagi@grimberg.me \
    /path/to/YOUR_REPLY

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

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