All of lore.kernel.org
 help / color / mirror / Atom feed
From: Guixin Liu <kanie@linux.alibaba.com>
To: Christoph Hellwig <hch@lst.de>, Sagi Grimberg <sagi@grimberg.me>,
	Chaitanya Kulkarni <kch@nvidia.com>,
	Hannes Reinecke <hare@suse.com>
Cc: linux-nvme@lists.infradead.org
Subject: [PATCH 2/2] nvmet: expose reservation state through debugfs
Date: Mon, 22 Jun 2026 18:44:18 +0800	[thread overview]
Message-ID: <20260622104418.2070277-3-kanie@linux.alibaba.com> (raw)
In-Reply-To: <20260622104418.2070277-1-kanie@linux.alibaba.com>

Add a 'reservation' debugfs file under each namespace directory that
shows the persistent reservation state, including enable status,
generation counter, notify mask, current holder info, and the full
registrant list with hostid and reservation key.

The output uses rcu_read_lock() for safe access to the holder and
registrant_list, consistent with other PR read paths.

Signed-off-by: Guixin Liu <kanie@linux.alibaba.com>
---
 drivers/nvme/target/debugfs.c | 54 +++++++++++++++++++++++++++++++++++
 1 file changed, 54 insertions(+)

diff --git a/drivers/nvme/target/debugfs.c b/drivers/nvme/target/debugfs.c
index e6f51eb59010..96d81d446d13 100644
--- a/drivers/nvme/target/debugfs.c
+++ b/drivers/nvme/target/debugfs.c
@@ -153,6 +153,58 @@ static int nvmet_ctrl_tls_concat_show(struct seq_file *m, void *p)
 NVMET_DEBUGFS_ATTR(nvmet_ctrl_tls_concat);
 #endif
 
+static const char *const nvmet_pr_type_names[] = {
+	[NVME_PR_WRITE_EXCLUSIVE]		= "write_exclusive",
+	[NVME_PR_EXCLUSIVE_ACCESS]		= "exclusive_access",
+	[NVME_PR_WRITE_EXCLUSIVE_REG_ONLY]	= "write_exclusive_reg_only",
+	[NVME_PR_EXCLUSIVE_ACCESS_REG_ONLY]	= "exclusive_access_reg_only",
+	[NVME_PR_WRITE_EXCLUSIVE_ALL_REGS]	= "write_exclusive_all_regs",
+	[NVME_PR_EXCLUSIVE_ACCESS_ALL_REGS]	= "exclusive_access_all_regs",
+};
+
+static const char *nvmet_pr_type_to_str(enum nvme_pr_type type)
+{
+	if (type < ARRAY_SIZE(nvmet_pr_type_names) &&
+	    nvmet_pr_type_names[type])
+		return nvmet_pr_type_names[type];
+	return "unknown";
+}
+
+static int nvmet_ns_pr_show(struct seq_file *m, void *p)
+{
+	struct nvmet_ns *ns = m->private;
+	struct nvmet_pr *pr = &ns->pr;
+	struct nvmet_pr_registrant *holder, *reg;
+
+	seq_printf(m, "enable : %d\n", pr->enable);
+	if (!pr->enable)
+		return 0;
+
+	seq_printf(m, "generation : %u\n", atomic_read(&pr->generation));
+	seq_printf(m, "notify_mask : 0x%lx\n", pr->notify_mask);
+
+	rcu_read_lock();
+	holder = rcu_dereference(pr->holder);
+	if (holder) {
+		seq_printf(m, "rtype : %s\n",
+			   nvmet_pr_type_to_str(holder->rtype));
+		seq_printf(m, "holder : hostid=%pUb, rkey=0x%llx\n",
+			   &holder->hostid, holder->rkey);
+	} else {
+		seq_puts(m, "holder : none\n");
+	}
+
+	seq_puts(m, "registrants:\n");
+	list_for_each_entry_rcu(reg, &pr->registrant_list, entry) {
+		seq_printf(m, "  hostid=%pUb, rkey=0x%llx\n",
+			   &reg->hostid, reg->rkey);
+	}
+	rcu_read_unlock();
+
+	return 0;
+}
+NVMET_DEBUGFS_ATTR(nvmet_ns_pr);
+
 void nvmet_debugfs_ns_setup(struct nvmet_ns *ns)
 {
 	char name[16];
@@ -166,6 +218,8 @@ void nvmet_debugfs_ns_setup(struct nvmet_ns *ns)
 		ns->debugfs_dir = NULL;
 		return;
 	}
+	debugfs_create_file("reservation", 0400, ns->debugfs_dir, ns,
+			    &nvmet_ns_pr_fops);
 }
 
 void nvmet_debugfs_ns_free(struct nvmet_ns *ns)
-- 
2.43.7



  parent reply	other threads:[~2026-06-22 10:44 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-22 10:44 [PATCH 0/2] nvmet: add namespace-level debugfs for reservation state Guixin Liu
2026-06-22 10:44 ` [PATCH 1/2] nvmet: add namespace-level debugfs directory Guixin Liu
2026-06-22 10:44 ` Guixin Liu [this message]
2026-06-25  7:17 ` [PATCH 0/2] nvmet: add namespace-level debugfs for reservation state Daniel Wagner
2026-06-25  9:10   ` Guixin Liu
2026-07-06  3:10     ` Guixin Liu
2026-07-06  7:59       ` Daniel Wagner
2026-07-06 10:28         ` Guixin Liu
2026-07-06 12:57           ` Shin'ichiro Kawasaki
2026-07-07  1:42             ` Guixin Liu

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=20260622104418.2070277-3-kanie@linux.alibaba.com \
    --to=kanie@linux.alibaba.com \
    --cc=hare@suse.com \
    --cc=hch@lst.de \
    --cc=kch@nvidia.com \
    --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 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.