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
Subject: [PATCHv2 9/9] libnvme: add support for ctrl diagnostic counters
Date: Sat, 4 Apr 2026 15:44:59 +0530 [thread overview]
Message-ID: <20260404101504.44539-10-nilay@linux.ibm.com> (raw)
In-Reply-To: <20260404101504.44539-1-nilay@linux.ibm.com>
Add support for retrieving ctrl diagnostic counters such as command_
error_count, reset_count and reconnect_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 | 3 +++
libnvme/src/nvme/private.h | 3 +++
libnvme/src/nvme/tree.c | 33 +++++++++++++++++++++++++++++++++
libnvme/src/nvme/tree.h | 25 +++++++++++++++++++++++++
4 files changed, 64 insertions(+)
diff --git a/libnvme/src/libnvme.ld b/libnvme/src/libnvme.ld
index 13bd3995c..52611f38b 100644
--- a/libnvme/src/libnvme.ld
+++ b/libnvme/src/libnvme.ld
@@ -16,6 +16,9 @@ LIBNVME_3 {
nvme_ctrl_get_subsysnqn;
nvme_ctrl_get_subsystem;
nvme_ctrl_get_transport_handle;
+ nvme_ctrl_get_command_error_count;
+ nvme_ctrl_get_reset_count;
+ nvme_ctrl_get_reconnect_count;
nvme_ctrl_identify;
nvme_ctrl_match_config;
nvme_ctrl_next_ns;
diff --git a/libnvme/src/nvme/private.h b/libnvme/src/nvme/private.h
index ae0b8507e..2009ac3c0 100644
--- a/libnvme/src/nvme/private.h
+++ b/libnvme/src/nvme/private.h
@@ -255,6 +255,9 @@ struct nvme_ctrl { /*!generate-accessors*/
bool unique_discovery_ctrl;
bool discovered;
bool persistent;
+ long command_error_count; //!accessors:none
+ long reset_count; //!accessors:none
+ long reconnect_count; //!accessors:none
struct nvme_fabrics_config cfg;
};
diff --git a/libnvme/src/nvme/tree.c b/libnvme/src/nvme/tree.c
index 77aed7eee..210952785 100644
--- a/libnvme/src/nvme/tree.c
+++ b/libnvme/src/nvme/tree.c
@@ -1414,6 +1414,39 @@ __public const char *nvme_ctrl_get_state(nvme_ctrl_t c)
return c->state;
}
+__public long nvme_ctrl_get_command_error_count(nvme_ctrl_t c)
+{
+ _cleanup_free_ char *error_count = NULL;
+
+ error_count = nvme_get_ctrl_attr(c, "command_error_count");
+ if (error_count)
+ sscanf(error_count, "%ld", &c->command_error_count);
+
+ return c->command_error_count;
+}
+
+__public long nvme_ctrl_get_reset_count(nvme_ctrl_t c)
+{
+ _cleanup_free_ char *reset_count = NULL;
+
+ reset_count = nvme_get_ctrl_attr(c, "reset_count");
+ if (reset_count)
+ sscanf(reset_count, "%ld", &c->reset_count);
+
+ return c->reset_count;
+}
+
+__public long nvme_ctrl_get_reconnect_count(nvme_ctrl_t c)
+{
+ _cleanup_free_ char *reconnect_count = NULL;
+
+ reconnect_count = nvme_get_ctrl_attr(c, "reconnect_count");
+ if (reconnect_count)
+ sscanf(reconnect_count, "%ld", &c->reconnect_count);
+
+ return c->reconnect_count;
+}
+
__public struct nvme_fabrics_config *nvme_ctrl_get_config(nvme_ctrl_t c)
{
return &c->cfg;
diff --git a/libnvme/src/nvme/tree.h b/libnvme/src/nvme/tree.h
index e6a26efb1..3a86208ef 100644
--- a/libnvme/src/nvme/tree.h
+++ b/libnvme/src/nvme/tree.h
@@ -1030,6 +1030,31 @@ unsigned long long nvme_ns_get_write_sectors(nvme_ns_t n);
*/
struct nvme_fabrics_config *nvme_ctrl_get_config(nvme_ctrl_t c);
+/**
+ * nvme_ctrl_get_command_error_count() - Get admin command error count
+ * @c: Controller instance
+ *
+ * Return: Number of times admin command issued to controller @c failed or
+ * returned error status
+ */
+long nvme_ctrl_get_command_error_count(nvme_ctrl_t c);
+
+/**
+ * nvme_ctrl_get_reset_count() - Get controller reset count
+ * @c: Controller instance
+ *
+ * Return: Number of timer controller @c is reset
+ */
+long nvme_ctrl_get_reset_count(nvme_ctrl_t c);
+
+/**
+ * nvme_ctrl_get_reconnect_count() - Get controller reconnect count
+ * @c: Controller instance
+ *
+ * Return: Number of times controller has to reconnect to the target
+ */
+long nvme_ctrl_get_reconnect_count(nvme_ctrl_t c);
+
/**
* nvme_ctrl_identify() - Issues an 'identify controller' command
* @c: Controller instance
--
2.53.0
prev parent reply other threads:[~2026-04-04 10:16 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-04 10:14 [PATCHv2 0/9] libnvme: add support for retrieving additional NVMe stat Nilay Shroff
2026-04-04 10:14 ` [PATCHv2 1/9] libnvme: annotate nvme_path::ana_state with !accessors:none Nilay Shroff
2026-04-04 10:14 ` [PATCHv2 2/9] libnvme: annotate nvme_path::numa_nodes " Nilay Shroff
2026-04-04 10:14 ` [PATCHv2 3/9] libnvme: annotate nvme_subsystem::iopolicy " Nilay Shroff
2026-04-04 10:14 ` [PATCHv2 4/9] libnvme: add support for retrieving per-path gendisk I/O statistics Nilay Shroff
2026-04-04 10:14 ` [PATCHv2 5/9] libnvme: add support for retrieving namespace " Nilay Shroff
2026-04-04 10:14 ` [PATCHv2 6/9] libnvme: add support for per-path diagnostic counters Nilay Shroff
2026-04-04 10:14 ` [PATCHv2 7/9] libnvme: add support for namespace " Nilay Shroff
2026-04-04 10:14 ` [PATCHv2 8/9] libnvme: add support for nshead " Nilay Shroff
2026-04-04 10:14 ` Nilay Shroff [this message]
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=20260404101504.44539-10-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