[PATCHv3 2/9] libnvme: annotate libnvme_path::numa_nodes with !accessors:none
Nilay Shroff
nilay at linux.ibm.com
Tue Apr 21 07:50:23 PDT 2026
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 <nilay at linux.ibm.com>
---
libnvme/src/accessors.ld | 2 --
libnvme/src/libnvme.ld | 1 +
libnvme/src/nvme/accessors.c | 13 -------------
libnvme/src/nvme/accessors.h | 17 -----------------
libnvme/src/nvme/private.h | 2 +-
libnvme/src/nvme/tree.c | 15 +++++++++++++++
libnvme/src/nvme/tree.h | 8 ++++++++
7 files changed, 25 insertions(+), 33 deletions(-)
diff --git a/libnvme/src/accessors.ld b/libnvme/src/accessors.ld
index 73b238ee9..4ccba1a6e 100644
--- a/libnvme/src/accessors.ld
+++ b/libnvme/src/accessors.ld
@@ -168,11 +168,9 @@ LIBNVME_ACCESSORS_3 {
libnvme_ns_set_sysfs_dir;
libnvme_path_get_grpid;
libnvme_path_get_name;
- libnvme_path_get_numa_nodes;
libnvme_path_get_sysfs_dir;
libnvme_path_set_grpid;
libnvme_path_set_name;
- libnvme_path_set_numa_nodes;
libnvme_path_set_sysfs_dir;
libnvme_subsystem_get_application;
libnvme_subsystem_get_firmware;
diff --git a/libnvme/src/libnvme.ld b/libnvme/src/libnvme.ld
index 19a7910cb..9b26de5cd 100644
--- a/libnvme/src/libnvme.ld
+++ b/libnvme/src/libnvme.ld
@@ -140,6 +140,7 @@ LIBNVME_3 {
libnvme_path_get_ns;
libnvme_path_get_queue_depth;
libnvme_path_get_ana_state;
+ libnvme_path_get_numa_nodes;
libnvme_random_uuid;
libnvme_read_config;
libnvme_read_hostid;
diff --git a/libnvme/src/nvme/accessors.c b/libnvme/src/nvme/accessors.c
index 675bb7d02..bcae8d578 100644
--- a/libnvme/src/nvme/accessors.c
+++ b/libnvme/src/nvme/accessors.c
@@ -291,19 +291,6 @@ __public const char *libnvme_path_get_sysfs_dir(const struct libnvme_path *p)
return p->sysfs_dir;
}
-__public void libnvme_path_set_numa_nodes(
- struct libnvme_path *p,
- const char *numa_nodes)
-{
- free(p->numa_nodes);
- p->numa_nodes = numa_nodes ? strdup(numa_nodes) : NULL;
-}
-
-__public const char *libnvme_path_get_numa_nodes(const struct libnvme_path *p)
-{
- return p->numa_nodes;
-}
-
__public void libnvme_path_set_grpid(struct libnvme_path *p, int grpid)
{
p->grpid = grpid;
diff --git a/libnvme/src/nvme/accessors.h b/libnvme/src/nvme/accessors.h
index 7ff0a274f..7ade91794 100644
--- a/libnvme/src/nvme/accessors.h
+++ b/libnvme/src/nvme/accessors.h
@@ -391,23 +391,6 @@ void libnvme_path_set_sysfs_dir(struct libnvme_path *p, const char *sysfs_dir);
*/
const char *libnvme_path_get_sysfs_dir(const struct libnvme_path *p);
-/**
- * libnvme_path_set_numa_nodes() - Set numa_nodes.
- * @p: The &struct libnvme_path instance to update.
- * @numa_nodes: New string; a copy is stored. Pass NULL to clear.
- */
-void libnvme_path_set_numa_nodes(
- struct libnvme_path *p,
- const char *numa_nodes);
-
-/**
- * libnvme_path_get_numa_nodes() - Get numa_nodes.
- * @p: The &struct libnvme_path instance to query.
- *
- * Return: The value of the numa_nodes field, or NULL if not set.
- */
-const char *libnvme_path_get_numa_nodes(const struct libnvme_path *p);
-
/**
* libnvme_path_set_grpid() - Set grpid.
* @p: The &struct libnvme_path instance to update.
diff --git a/libnvme/src/nvme/private.h b/libnvme/src/nvme/private.h
index 9d25373ed..2471495ad 100644
--- a/libnvme/src/nvme/private.h
+++ b/libnvme/src/nvme/private.h
@@ -176,8 +176,8 @@ struct libnvme_path { // !generate-accessors
char *name;
char *sysfs_dir;
- char *numa_nodes;
char *ana_state; //!accessors:none
+ char *numa_nodes; //!accessors:none
int grpid;
int queue_depth; // !accessors:none
};
diff --git a/libnvme/src/nvme/tree.c b/libnvme/src/nvme/tree.c
index 46e72ebc4..c2c959871 100644
--- a/libnvme/src/nvme/tree.c
+++ b/libnvme/src/nvme/tree.c
@@ -854,6 +854,21 @@ __public char *libnvme_path_get_ana_state(libnvme_path_t p)
return p->ana_state;
}
+__public char *libnvme_path_get_numa_nodes(libnvme_path_t p)
+{
+ __cleanup_free char *numa_nodes = NULL;
+
+ numa_nodes = libnvme_get_path_attr(p, "numa_nodes");
+ if (numa_nodes) {
+ if (!p->numa_nodes || strcmp(numa_nodes, p->numa_nodes)) {
+ free(p->numa_nodes);
+ p->numa_nodes = strdup(numa_nodes);
+ }
+ }
+
+ return p->numa_nodes;
+}
+
void nvme_free_path(struct libnvme_path *p)
{
if (!p)
diff --git a/libnvme/src/nvme/tree.h b/libnvme/src/nvme/tree.h
index aa983b862..7cd90c620 100644
--- a/libnvme/src/nvme/tree.h
+++ b/libnvme/src/nvme/tree.h
@@ -668,6 +668,14 @@ int libnvme_path_get_queue_depth(libnvme_path_t p);
*/
char *libnvme_path_get_ana_state(libnvme_path_t p);
+/**
+ * libnvme_path_get_numa_nodes() - Numa nodes of an nvme_path_t object
+ * @p: &libnvme_path_t object
+ *
+ * Return: Numa nodes of @p
+ */
+char *libnvme_path_get_numa_nodes(libnvme_path_t p);
+
/**
* libnvme_path_get_ctrl() - Parent controller of an libnvme_path_t object
* @p: &libnvme_path_t object
--
2.53.0
More information about the Linux-nvme
mailing list