Skip to content

Commit 6945656

Browse files
shroffniigaw
authored andcommitted
libnvme: annotate libnvme_path::numa_nodes with !accessors:none
The default accessor generation creates getters that return cached attribute values. However, for libnvme_path::numa_nodes, a real-time (non-cached) value is required. This is particularly useful for tools such as nvme-top, which rely on up-to-date information for displaying a real-time dashboard. Annotate libnvme_path::numa_nodes with "!accessors:none" to disable the auto-generated accessor, and provide a custom implementation of libnvme_path_get_numa_nodes() that returns the current value. Signed-off-by: Nilay Shroff <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Daniel Wagner <[email protected]>
1 parent 29db9f5 commit 6945656

8 files changed

Lines changed: 31 additions & 41 deletions

File tree

libnvme/libnvme/nvme-swig-accessors.i

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,12 @@
5858
#define libnvme_fabrics_config_concat_set libnvme_fabrics_config_set_concat
5959

6060
/* struct libnvme_path */
61-
#define libnvme_path_name_get libnvme_path_get_name
62-
#define libnvme_path_sysfs_dir_get libnvme_path_get_sysfs_dir
63-
#define libnvme_path_numa_nodes_get libnvme_path_get_numa_nodes
64-
#define libnvme_path_grpid_get libnvme_path_get_grpid
65-
#define libnvme_path_name_set libnvme_path_set_name
66-
#define libnvme_path_sysfs_dir_set libnvme_path_set_sysfs_dir
67-
#define libnvme_path_numa_nodes_set libnvme_path_set_numa_nodes
68-
#define libnvme_path_grpid_set libnvme_path_set_grpid
61+
#define libnvme_path_name_get libnvme_path_get_name
62+
#define libnvme_path_sysfs_dir_get libnvme_path_get_sysfs_dir
63+
#define libnvme_path_grpid_get libnvme_path_get_grpid
64+
#define libnvme_path_name_set libnvme_path_set_name
65+
#define libnvme_path_sysfs_dir_set libnvme_path_set_sysfs_dir
66+
#define libnvme_path_grpid_set libnvme_path_set_grpid
6967

7068
/* struct libnvme_ns */
7169
#define libnvme_ns_nsid_get libnvme_ns_get_nsid

libnvme/src/accessors.ld

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,9 @@ LIBNVME_ACCESSORS_3 {
168168
libnvme_ns_set_sysfs_dir;
169169
libnvme_path_get_grpid;
170170
libnvme_path_get_name;
171-
libnvme_path_get_numa_nodes;
172171
libnvme_path_get_sysfs_dir;
173172
libnvme_path_set_grpid;
174173
libnvme_path_set_name;
175-
libnvme_path_set_numa_nodes;
176174
libnvme_path_set_sysfs_dir;
177175
libnvme_subsystem_get_application;
178176
libnvme_subsystem_get_firmware;

libnvme/src/libnvme.ld

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ LIBNVME_3 {
139139
libnvme_path_get_ana_state;
140140
libnvme_path_get_ctrl;
141141
libnvme_path_get_ns;
142+
libnvme_path_get_numa_nodes;
142143
libnvme_path_get_queue_depth;
143144
libnvme_random_uuid;
144145
libnvme_read_config;

libnvme/src/nvme/accessors.c

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -291,19 +291,6 @@ __public const char *libnvme_path_get_sysfs_dir(const struct libnvme_path *p)
291291
return p->sysfs_dir;
292292
}
293293

294-
__public void libnvme_path_set_numa_nodes(
295-
struct libnvme_path *p,
296-
const char *numa_nodes)
297-
{
298-
free(p->numa_nodes);
299-
p->numa_nodes = numa_nodes ? strdup(numa_nodes) : NULL;
300-
}
301-
302-
__public const char *libnvme_path_get_numa_nodes(const struct libnvme_path *p)
303-
{
304-
return p->numa_nodes;
305-
}
306-
307294
__public void libnvme_path_set_grpid(struct libnvme_path *p, int grpid)
308295
{
309296
p->grpid = grpid;

libnvme/src/nvme/accessors.h

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -391,23 +391,6 @@ void libnvme_path_set_sysfs_dir(struct libnvme_path *p, const char *sysfs_dir);
391391
*/
392392
const char *libnvme_path_get_sysfs_dir(const struct libnvme_path *p);
393393

394-
/**
395-
* libnvme_path_set_numa_nodes() - Set numa_nodes.
396-
* @p: The &struct libnvme_path instance to update.
397-
* @numa_nodes: New string; a copy is stored. Pass NULL to clear.
398-
*/
399-
void libnvme_path_set_numa_nodes(
400-
struct libnvme_path *p,
401-
const char *numa_nodes);
402-
403-
/**
404-
* libnvme_path_get_numa_nodes() - Get numa_nodes.
405-
* @p: The &struct libnvme_path instance to query.
406-
*
407-
* Return: The value of the numa_nodes field, or NULL if not set.
408-
*/
409-
const char *libnvme_path_get_numa_nodes(const struct libnvme_path *p);
410-
411394
/**
412395
* libnvme_path_set_grpid() - Set grpid.
413396
* @p: The &struct libnvme_path instance to update.

libnvme/src/nvme/private.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ struct libnvme_path { // !generate-accessors
180180
char *name;
181181
char *sysfs_dir;
182182
char *ana_state; // !accessors:none
183-
char *numa_nodes;
183+
char *numa_nodes; // !accessors:none
184184
int grpid;
185185
int queue_depth; // !accessors:none
186186
};

libnvme/src/nvme/tree.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -854,6 +854,21 @@ __public char *libnvme_path_get_ana_state(libnvme_path_t p)
854854
return p->ana_state;
855855
}
856856

857+
__public char *libnvme_path_get_numa_nodes(libnvme_path_t p)
858+
{
859+
__cleanup_free char *numa_nodes = NULL;
860+
861+
numa_nodes = libnvme_get_path_attr(p, "numa_nodes");
862+
if (numa_nodes) {
863+
if (!p->numa_nodes || strcmp(numa_nodes, p->numa_nodes)) {
864+
free(p->numa_nodes);
865+
p->numa_nodes = strdup(numa_nodes);
866+
}
867+
}
868+
869+
return p->numa_nodes;
870+
}
871+
857872
void nvme_free_path(struct libnvme_path *p)
858873
{
859874
if (!p)

libnvme/src/nvme/tree.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,14 @@ int libnvme_path_get_queue_depth(libnvme_path_t p);
668668
*/
669669
char *libnvme_path_get_ana_state(libnvme_path_t p);
670670

671+
/**
672+
* libnvme_path_get_numa_nodes() - Numa nodes of an nvme_path_t object
673+
* @p: &libnvme_path_t object
674+
*
675+
* Return: Numa nodes of @p
676+
*/
677+
char *libnvme_path_get_numa_nodes(libnvme_path_t p);
678+
671679
/**
672680
* libnvme_path_get_ctrl() - Parent controller of an libnvme_path_t object
673681
* @p: &libnvme_path_t object

0 commit comments

Comments
 (0)