Skip to content

Commit 14b9b0b

Browse files
shroffniigaw
authored andcommitted
libnvme: add support for namespace diagnostic counters
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> Link: https://patch.msgid.link/20260421145038.3458987-8-nilay@linux.ibm.com Signed-off-by: Daniel Wagner <wagi@kernel.org>
1 parent 247a359 commit 14b9b0b

4 files changed

Lines changed: 44 additions & 0 deletions

File tree

libnvme/src/libnvme.ld

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ LIBNVME_3 {
140140
libnvme_ns_get_write_sectors;
141141
libnvme_ns_get_inflights;
142142
libnvme_ns_get_io_ticks;
143+
libnvme_ns_get_command_retry_count;
144+
libnvme_ns_get_command_error_count;
143145
libnvme_ns_identify;
144146
libnvme_ns_read;
145147
libnvme_ns_verify;

libnvme/src/nvme/private.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,9 @@ struct libnvme_ns { // !generate-accessors
254254
uint8_t nguid[16];
255255
unsigned char uuid[NVME_UUID_LEN];
256256
enum nvme_csi csi;
257+
258+
long command_retry_count; // !accessors:none
259+
long command_error_count; // !accessors:none
257260
};
258261

259262
struct libnvme_ctrl { // !generate-accessors

libnvme/src/nvme/tree.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2611,6 +2611,28 @@ __public void libnvme_ns_get_uuid(libnvme_ns_t n,
26112611
memcpy(out, n->uuid, NVME_UUID_LEN);
26122612
}
26132613

2614+
__public long libnvme_ns_get_command_retry_count(libnvme_ns_t n)
2615+
{
2616+
__cleanup_free char *retry_count = NULL;
2617+
2618+
retry_count = libnvme_get_ns_attr(n, "command_retry_count");
2619+
if (retry_count)
2620+
sscanf(retry_count, "%ld", &n->command_retry_count);
2621+
2622+
return n->command_retry_count;
2623+
}
2624+
2625+
__public long libnvme_ns_get_command_error_count(libnvme_ns_t n)
2626+
{
2627+
__cleanup_free char *error_count = NULL;
2628+
2629+
error_count = libnvme_get_ns_attr(n, "command_error_count");
2630+
if (error_count)
2631+
sscanf(error_count, "%ld", &n->command_error_count);
2632+
2633+
return n->command_error_count;
2634+
}
2635+
26142636
__public int libnvme_ns_identify(libnvme_ns_t n, struct nvme_id_ns *ns)
26152637
{
26162638
struct libnvme_transport_handle *hdl;

libnvme/src/nvme/tree.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,23 @@ const uint8_t *libnvme_ns_get_nguid(libnvme_ns_t n);
510510
*/
511511
void libnvme_ns_get_uuid(libnvme_ns_t n, unsigned char out[NVME_UUID_LEN]);
512512

513+
/**
514+
* libnvme_ns_get_command_retry_count() - Get command retry count
515+
* @n: &libnvme_ns_t object
516+
*
517+
* Return: Number of times any command issued to namespace @n has to be retried
518+
*/
519+
long libnvme_ns_get_command_retry_count(libnvme_ns_t n);
520+
521+
/**
522+
* libnvme_ns_get_command_error_count() - Get command error count
523+
* @n: &libnvme_ns_t object
524+
*
525+
* Return: Number of times command issued to namespace @n returns non-zero
526+
* status or error
527+
*/
528+
long libnvme_ns_get_command_error_count(libnvme_ns_t n);
529+
513530
/**
514531
* libnvme_ns_get_generic_name() - Returns name of generic namespace chardev.
515532
* @n: Namespace instance

0 commit comments

Comments
 (0)