[PATCHv3 6/9] libnvme: add support for per-path diagnostic counters
Nilay Shroff
nilay at linux.ibm.com
Tue Apr 21 07:50:27 PDT 2026
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 at 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
More information about the Linux-nvme
mailing list