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@ibm.com, wenxiong@linux.ibm.com,
Nilay Shroff <nilay@linux.ibm.com>
Subject: [PATCH 7/9] libnvme: add support for namespace diagnostic counters
Date: Sat, 21 Mar 2026 20:58:06 +0530 [thread overview]
Message-ID: <20260321152823.3197870-8-nilay@linux.ibm.com> (raw)
In-Reply-To: <20260321152823.3197870-1-nilay@linux.ibm.com>
Add support for retrieving namespace diagnostic counters such as
command_retry_count and command_error_count. These counters improve
visibility 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 | 2 ++
libnvme/src/nvme/private.h | 3 +++
libnvme/src/nvme/tree.c | 22 ++++++++++++++++++++++
libnvme/src/nvme/tree.h | 17 +++++++++++++++++
4 files changed, 44 insertions(+)
diff --git a/libnvme/src/libnvme.ld b/libnvme/src/libnvme.ld
index 20dcb24f1..a767eca5e 100644
--- a/libnvme/src/libnvme.ld
+++ b/libnvme/src/libnvme.ld
@@ -141,6 +141,8 @@ LIBNVME_3 {
nvme_ns_get_write_sectors;
nvme_ns_get_inflights;
nvme_ns_get_io_ticks;
+ nvme_ns_get_command_retry_count;
+ nvme_ns_get_command_error_count;
nvme_ns_identify;
nvme_ns_read;
nvme_rescan_ns;
diff --git a/libnvme/src/nvme/private.h b/libnvme/src/nvme/private.h
index bbddb9ba0..f58b13bd7 100644
--- a/libnvme/src/nvme/private.h
+++ b/libnvme/src/nvme/private.h
@@ -206,6 +206,9 @@ struct nvme_ns { /*!generate-accessors*/
uint8_t nguid[16];
unsigned char uuid[NVME_UUID_LEN];
enum nvme_csi csi;
+
+ long command_retry_count; //!accessors:none
+ long command_error_count; //!accessors:none
};
struct nvme_ctrl { /*!generate-accessors*/
diff --git a/libnvme/src/nvme/tree.c b/libnvme/src/nvme/tree.c
index a197b7a00..f82ea4c02 100644
--- a/libnvme/src/nvme/tree.c
+++ b/libnvme/src/nvme/tree.c
@@ -2548,6 +2548,28 @@ __public void nvme_ns_get_uuid(nvme_ns_t n, unsigned char out[NVME_UUID_LEN])
memcpy(out, n->uuid, NVME_UUID_LEN);
}
+__public long nvme_ns_get_command_retry_count(nvme_ns_t n)
+{
+ _cleanup_free_ char *retry_count = NULL;
+
+ retry_count = nvme_get_ns_attr(n, "command_retry_count");
+ if (retry_count)
+ sscanf(retry_count, "%ld", &n->command_retry_count);
+
+ return n->command_retry_count;
+}
+
+__public long nvme_ns_get_command_error_count(nvme_ns_t n)
+{
+ _cleanup_free_ char *error_count = NULL;
+
+ error_count = nvme_get_ns_attr(n, "command_error_count");
+ if (error_count)
+ sscanf(error_count, "%ld", &n->command_error_count);
+
+ return n->command_error_count;
+}
+
__public int nvme_ns_identify(nvme_ns_t n, struct nvme_id_ns *ns)
{
struct nvme_transport_handle *hdl;
diff --git a/libnvme/src/nvme/tree.h b/libnvme/src/nvme/tree.h
index 3c651743d..6cff114bb 100644
--- a/libnvme/src/nvme/tree.h
+++ b/libnvme/src/nvme/tree.h
@@ -529,6 +529,23 @@ const uint8_t *nvme_ns_get_nguid(nvme_ns_t n);
*/
void nvme_ns_get_uuid(nvme_ns_t n, unsigned char out[NVME_UUID_LEN]);
+/**
+ * nvme_ns_get_command_retry_count() - Get command retry count
+ * @n: &nvme_ns_t object
+ *
+ * Return: Number of times any command issued to namespace @n has to be retried
+ */
+long nvme_ns_get_command_retry_count(nvme_ns_t n);
+
+/**
+ * nvme_ns_get_command_error_count() - Get command error count
+ * @n: &nvme_ns_t object
+ *
+ * Return: Number of times command issued to namespace @n returns non-zero
+ * status or error
+ */
+long nvme_ns_get_command_error_count(nvme_ns_t n);
+
/**
* nvme_ns_get_generic_name() - Returns name of generic namespace chardev.
* @n: Namespace instance
--
2.53.0
next prev parent reply other threads:[~2026-03-21 15:29 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-21 15:27 [PATCH 0/9] libnvme: add support for retrieving additional NVMe stat Nilay Shroff
2026-03-21 15:28 ` [PATCH 1/9] libnvme: annotate nvme_path::ana_state with !accessors:none Nilay Shroff
2026-03-24 8:55 ` Daniel Wagner
2026-03-24 13:08 ` Nilay Shroff
2026-03-21 15:28 ` [PATCH 2/9] libnvme: annotate nvme_path::numa_nodes " Nilay Shroff
2026-03-21 15:28 ` [PATCH 3/9] libnvme: annotate nvme_subsystem::iopolicy " Nilay Shroff
2026-03-21 15:28 ` [PATCH 4/9] libnvme: add support for retrieving per-path gendisk I/O statistics Nilay Shroff
2026-03-24 9:05 ` Daniel Wagner
2026-03-24 13:02 ` Nilay Shroff
2026-04-01 15:42 ` Daniel Wagner
2026-04-03 15:36 ` Nilay Shroff
2026-03-21 15:28 ` [PATCH 5/9] libnvme: add support for retrieving namespace " Nilay Shroff
2026-03-24 9:06 ` Daniel Wagner
2026-03-24 13:12 ` Nilay Shroff
2026-03-21 15:28 ` [PATCH 6/9] libnvme: add support for per-path diagnostic counters Nilay Shroff
2026-03-24 9:18 ` Daniel Wagner
2026-03-24 13:54 ` Nilay Shroff
2026-04-01 15:54 ` Daniel Wagner
2026-04-03 15:47 ` Nilay Shroff
2026-03-21 15:28 ` Nilay Shroff [this message]
2026-03-21 15:28 ` [PATCH 8/9] libnvme: add support for nshead " Nilay Shroff
2026-03-21 15:28 ` [PATCH 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=20260321152823.3197870-8-nilay@linux.ibm.com \
--to=nilay@linux.ibm.com \
--cc=dwagner@suse.de \
--cc=gjoyce@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