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 9/9] libnvme: add support for ctrl diagnostic counters
Date: Tue, 21 Apr 2026 20:20:30 +0530 [thread overview]
Message-ID: <20260421145038.3458987-10-nilay@linux.ibm.com> (raw)
In-Reply-To: <20260421145038.3458987-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 c9841e45c..68df5e2b6 100644
--- a/libnvme/src/libnvme.ld
+++ b/libnvme/src/libnvme.ld
@@ -14,6 +14,9 @@ LIBNVME_3 {
libnvme_ctrl_get_subsysnqn;
libnvme_ctrl_get_subsystem;
libnvme_ctrl_get_transport_handle;
+ libnvme_ctrl_get_command_error_count;
+ libnvme_ctrl_get_reset_count;
+ libnvme_ctrl_get_reconnect_count;
libnvme_ctrl_identify;
libnvme_ctrl_match_config;
libnvme_ctrl_next_ns;
diff --git a/libnvme/src/nvme/private.h b/libnvme/src/nvme/private.h
index 170445927..f7612c06d 100644
--- a/libnvme/src/nvme/private.h
+++ b/libnvme/src/nvme/private.h
@@ -295,6 +295,9 @@ struct libnvme_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 libnvme_fabrics_config cfg;
};
diff --git a/libnvme/src/nvme/tree.c b/libnvme/src/nvme/tree.c
index 085d79558..f87a6d0c3 100644
--- a/libnvme/src/nvme/tree.c
+++ b/libnvme/src/nvme/tree.c
@@ -1458,6 +1458,39 @@ __public const char *libnvme_ctrl_get_state(libnvme_ctrl_t c)
return c->state;
}
+__public long libnvme_ctrl_get_command_error_count(libnvme_ctrl_t c)
+{
+ __cleanup_free char *error_count = NULL;
+
+ error_count = libnvme_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 libnvme_ctrl_get_reset_count(libnvme_ctrl_t c)
+{
+ __cleanup_free char *reset_count = NULL;
+
+ reset_count = libnvme_get_ctrl_attr(c, "reset_count");
+ if (reset_count)
+ sscanf(reset_count, "%ld", &c->reset_count);
+
+ return c->reset_count;
+}
+
+__public long libnvme_ctrl_get_reconnect_count(libnvme_ctrl_t c)
+{
+ __cleanup_free char *reconnect_count = NULL;
+
+ reconnect_count = libnvme_get_ctrl_attr(c, "reconnect_count");
+ if (reconnect_count)
+ sscanf(reconnect_count, "%ld", &c->reconnect_count);
+
+ return c->reconnect_count;
+}
+
__public int libnvme_ctrl_identify(libnvme_ctrl_t c, struct nvme_id_ctrl *id)
{
struct libnvme_transport_handle *hdl =
diff --git a/libnvme/src/nvme/tree.h b/libnvme/src/nvme/tree.h
index 6bfc8cf98..48f1beb49 100644
--- a/libnvme/src/nvme/tree.h
+++ b/libnvme/src/nvme/tree.h
@@ -1007,6 +1007,31 @@ unsigned long long libnvme_ns_get_read_sectors(libnvme_ns_t n);
*/
unsigned long long libnvme_ns_get_write_sectors(libnvme_ns_t n);
+/**
+ * libnvme_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 libnvme_ctrl_get_command_error_count(libnvme_ctrl_t c);
+
+/**
+ * libnvme_ctrl_get_reset_count() - Get controller reset count
+ * @c: Controller instance
+ *
+ * Return: Number of timer controller @c is reset
+ */
+long libnvme_ctrl_get_reset_count(libnvme_ctrl_t c);
+
+/**
+ * libnvme_ctrl_get_reconnect_count() - Get controller reconnect count
+ * @c: Controller instance
+ *
+ * Return: Number of times controller has to reconnect to the target
+ */
+long libnvme_ctrl_get_reconnect_count(libnvme_ctrl_t c);
+
/**
* libnvme_ctrl_identify() - Issues an 'identify controller' command
* @c: Controller instance
--
2.53.0
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 ` [PATCHv3 6/9] libnvme: add support for per-path diagnostic counters Nilay Shroff
2026-04-21 14:50 ` [PATCHv3 7/9] libnvme: add support for namespace " Nilay Shroff
2026-04-21 14:50 ` [PATCHv3 8/9] libnvme: add support for nshead " Nilay Shroff
2026-04-21 14:50 ` 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=20260421145038.3458987-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