Skip to content

Commit 247a359

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

4 files changed

Lines changed: 66 additions & 0 deletions

File tree

libnvme/src/libnvme.ld

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,9 @@ LIBNVME_3 {
163163
libnvme_path_get_write_ticks;
164164
libnvme_path_reset_stat;
165165
libnvme_path_update_stat;
166+
libnvme_path_get_command_retry_count;
167+
libnvme_path_get_command_error_count;
168+
libnvme_path_get_multipath_failover_count;
166169
libnvme_random_uuid;
167170
libnvme_read_config;
168171
libnvme_read_hostid;

libnvme/src/nvme/private.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,9 @@ struct libnvme_path { // !generate-accessors
213213
char *numa_nodes; // !accessors:none
214214
int grpid;
215215
int queue_depth; // !accessors:none
216+
long multipath_failover_count; // !accessors:none
217+
long command_retry_count; // !accessors:none
218+
long command_error_count; // !accessors:none
216219
};
217220

218221
struct libnvme_ns_head {

libnvme/src/nvme/tree.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,39 @@ __public char *libnvme_path_get_numa_nodes(libnvme_path_t p)
885885
return p->numa_nodes;
886886
}
887887

888+
__public long libnvme_path_get_multipath_failover_count(libnvme_path_t p)
889+
{
890+
__cleanup_free char *failover_count = NULL;
891+
892+
failover_count = libnvme_get_path_attr(p, "multipath_failover_count");
893+
if (failover_count)
894+
sscanf(failover_count, "%ld", &p->multipath_failover_count);
895+
896+
return p->multipath_failover_count;
897+
}
898+
899+
__public long libnvme_path_get_command_retry_count(libnvme_path_t p)
900+
{
901+
__cleanup_free char *retry_count = NULL;
902+
903+
retry_count = libnvme_get_path_attr(p, "command_retry_count");
904+
if (retry_count)
905+
sscanf(retry_count, "%ld", &p->command_retry_count);
906+
907+
return p->command_retry_count;
908+
}
909+
910+
__public long libnvme_path_get_command_error_count(libnvme_path_t p)
911+
{
912+
__cleanup_free char *error_count = NULL;
913+
914+
error_count = libnvme_get_path_attr(p, "command_error_count");
915+
if (error_count)
916+
sscanf(error_count, "%ld", &p->command_error_count);
917+
918+
return p->command_error_count;
919+
}
920+
888921
static libnvme_stat_t libnvme_path_get_stat(libnvme_path_t p, unsigned int idx)
889922
{
890923
if (idx > 1)

libnvme/src/nvme/tree.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,33 @@ char *libnvme_path_get_ana_state(libnvme_path_t p);
685685
*/
686686
char *libnvme_path_get_numa_nodes(libnvme_path_t p);
687687

688+
/**
689+
* libnvme_path_get_multipath_failover_count() - Get multipath failover count
690+
* @p: &libnvme_path_t object
691+
*
692+
* Return: Number of times I/Os have to be failed over to another active path
693+
* from path @p maybe due to any transient error observed on path @p
694+
*/
695+
long libnvme_path_get_multipath_failover_count(libnvme_path_t p);
696+
697+
/**
698+
* libnvme_path_get_command_retry_count() - Get command retry count
699+
* @p: &libnvme_path_t object
700+
*
701+
* Return: Number of times any command issued to the namespace represented by
702+
* path @p has to be retried
703+
*/
704+
long libnvme_path_get_command_retry_count(libnvme_path_t p);
705+
706+
/**
707+
* libnvme_path_get_command_error_count() - Get command error count
708+
* @p: &libnvme_path_t object
709+
*
710+
* Return: Number of times command issued to the namespace represented by path
711+
* @p returns non-zero status or error
712+
*/
713+
long libnvme_path_get_command_error_count(libnvme_path_t p);
714+
688715
/**
689716
* libnvme_path_get_ctrl() - Parent controller of an libnvme_path_t object
690717
* @p: &libnvme_path_t object

0 commit comments

Comments
 (0)