From: Nilay Shroff <nilay@linux.ibm.com>
To: linux-nvme@lists.infradead.org
Cc: dwagner@suse.de, hare@suse.com, kbusch@kernel.org, hch@lst.de,
gjoyce@linux.ibm.com, wenxiong@linux.ibm.com,
Nilay Shroff <nilay@linux.ibm.com>
Subject: [PATCHv3 6/9] libnvme: add support for per-path diagnostic counters
Date: Tue, 21 Apr 2026 20:20:27 +0530 [thread overview]
Message-ID: <20260421145038.3458987-7-nilay@linux.ibm.com> (raw)
In-Reply-To: <20260421145038.3458987-1-nilay@linux.ibm.com>
Add support for retrieving per-path diagnostic counters such as
command_retry_count, command_error_count, and multipath_failover_count.
These counters improve visibility into NVMe native multipath behavior
and can be useful for tools such as nvme-top to display real-time
statistics.
Unlike other sysfs attributes, these counters can change dynamically.
Annotate them with "!accessors:none" and provide custom implementations
to always retrieve the latest (non-cached) values.
Signed-off-by: Nilay Shroff <nilay@linux.ibm.com>
---
libnvme/src/libnvme.ld | 3 +++
libnvme/src/nvme/private.h | 5 ++++-
libnvme/src/nvme/tree.c | 33 +++++++++++++++++++++++++++++++++
libnvme/src/nvme/tree.h | 27 +++++++++++++++++++++++++++
4 files changed, 67 insertions(+), 1 deletion(-)
diff --git a/libnvme/src/libnvme.ld b/libnvme/src/libnvme.ld
index ce85c960e..85ff00e55 100644
--- a/libnvme/src/libnvme.ld
+++ b/libnvme/src/libnvme.ld
@@ -163,6 +163,9 @@ LIBNVME_3 {
libnvme_path_get_write_sectors;
libnvme_path_reset_stat;
libnvme_path_update_stat;
+ libnvme_path_get_command_retry_count;
+ libnvme_path_get_command_error_count;
+ libnvme_path_get_multipath_failover_count;
libnvme_random_uuid;
libnvme_read_config;
libnvme_read_hostid;
diff --git a/libnvme/src/nvme/private.h b/libnvme/src/nvme/private.h
index 08b35e002..7f01f8a7d 100644
--- a/libnvme/src/nvme/private.h
+++ b/libnvme/src/nvme/private.h
@@ -209,7 +209,10 @@ struct libnvme_path { // !generate-accessors
char *ana_state; //!accessors:none
char *numa_nodes; //!accessors:none
int grpid;
- int queue_depth; // !accessors:none
+ int queue_depth; //!accessors:none
+ long multipath_failover_count; //!accessors:none
+ long command_retry_count; //!accessors:none
+ long command_error_count; //!accessors:none
};
struct libnvme_ns_head {
diff --git a/libnvme/src/nvme/tree.c b/libnvme/src/nvme/tree.c
index ca716bde7..a603c2fde 100644
--- a/libnvme/src/nvme/tree.c
+++ b/libnvme/src/nvme/tree.c
@@ -885,6 +885,39 @@ __public char *libnvme_path_get_numa_nodes(libnvme_path_t p)
return p->numa_nodes;
}
+__public long libnvme_path_get_multipath_failover_count(libnvme_path_t p)
+{
+ __cleanup_free char *failover_count = NULL;
+
+ failover_count = libnvme_get_path_attr(p, "multipath_failover_count");
+ if (failover_count)
+ sscanf(failover_count, "%ld", &p->multipath_failover_count);
+
+ return p->multipath_failover_count;
+}
+
+__public long libnvme_path_get_command_retry_count(libnvme_path_t p)
+{
+ __cleanup_free char *retry_count = NULL;
+
+ retry_count = libnvme_get_path_attr(p, "command_retry_count");
+ if (retry_count)
+ sscanf(retry_count, "%ld", &p->command_retry_count);
+
+ return p->command_retry_count;
+}
+
+__public long libnvme_path_get_command_error_count(libnvme_path_t p)
+{
+ __cleanup_free char *error_count = NULL;
+
+ error_count = libnvme_get_path_attr(p, "command_error_count");
+ if (error_count)
+ sscanf(error_count, "%ld", &p->command_error_count);
+
+ return p->command_error_count;
+}
+
static libnvme_stat_t libnvme_path_get_stat(libnvme_path_t p, unsigned int idx)
{
if (idx > 1)
diff --git a/libnvme/src/nvme/tree.h b/libnvme/src/nvme/tree.h
index a166d9df6..2eb4cea0e 100644
--- a/libnvme/src/nvme/tree.h
+++ b/libnvme/src/nvme/tree.h
@@ -685,6 +685,33 @@ char *libnvme_path_get_ana_state(libnvme_path_t p);
*/
char *libnvme_path_get_numa_nodes(libnvme_path_t p);
+/**
+ * libnvme_path_get_multipath_failover_count() - Get multipath failover count
+ * @p: &libnvme_path_t object
+ *
+ * Return: Number of times I/Os have to be failed over to another active path
+ * from path @p maybe due to any transient error observed on path @p
+ */
+long libnvme_path_get_multipath_failover_count(libnvme_path_t p);
+
+/**
+ * libnvme_path_get_command_retry_count() - Get command retry count
+ * @p: &libnvme_path_t object
+ *
+ * Return: Number of times any command issued to the namespace represented by
+ * path @p has to be retried
+ */
+long libnvme_path_get_command_retry_count(libnvme_path_t p);
+
+/**
+ * libnvme_path_get_command_error_count() - Get command error count
+ * @p: &libnvme_path_t object
+ *
+ * Return: Number of times command issued to the namespace represented by path
+ * @p returns non-zero status or error
+ */
+long libnvme_path_get_command_error_count(libnvme_path_t p);
+
/**
* libnvme_path_get_ctrl() - Parent controller of an libnvme_path_t object
* @p: &libnvme_path_t object
--
2.53.0
next prev parent reply other threads:[~2026-04-21 14:51 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-21 14:50 [PATCHv3 0/9] libnvme: add support for retrieving additional NVMe stat Nilay Shroff
2026-04-21 14:50 ` [PATCHv3 1/9] libnvme: annotate libnvme_path::ana_state with !accessors:none Nilay Shroff
2026-04-21 14:50 ` [PATCHv3 2/9] libnvme: annotate libnvme_path::numa_nodes " Nilay Shroff
2026-04-21 14:50 ` [PATCHv3 3/9] libnvme: annotate libnvme_subsystem::iopolicy " Nilay Shroff
2026-04-21 14:50 ` [PATCHv3 4/9] libnvme: add support for retrieving per-path gendisk I/O statistics Nilay Shroff
2026-04-21 14:50 ` [PATCHv3 5/9] libnvme: add support for retrieving namespace " Nilay Shroff
2026-04-21 14:50 ` Nilay Shroff [this message]
2026-04-21 14:50 ` [PATCHv3 7/9] libnvme: add support for namespace diagnostic counters Nilay Shroff
2026-04-21 14:50 ` [PATCHv3 8/9] libnvme: add support for nshead " Nilay Shroff
2026-04-21 14:50 ` [PATCHv3 9/9] libnvme: add support for ctrl " Nilay Shroff
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=20260421145038.3458987-7-nilay@linux.ibm.com \
--to=nilay@linux.ibm.com \
--cc=dwagner@suse.de \
--cc=gjoyce@linux.ibm.com \
--cc=hare@suse.com \
--cc=hch@lst.de \
--cc=kbusch@kernel.org \
--cc=linux-nvme@lists.infradead.org \
--cc=wenxiong@linux.ibm.com \
/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