[PATCHv2 2/9] libnvme: annotate nvme_path::numa_nodes with !accessors:none
Nilay Shroff
nilay at linux.ibm.com
Sat Apr 4 03:14:52 PDT 2026
The default accessor generation creates getters that return cached
attribute values. However, for nvme_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 nvme_path::numa_nodes with "!accessors:none" to disable the
auto-generated accessor, and provide a custom implementation of
nvme_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 | 15 ---------------
libnvme/src/nvme/private.h | 2 +-
libnvme/src/nvme/tree.c | 15 +++++++++++++++
libnvme/src/nvme/tree.h | 8 ++++++++
7 files changed, 25 insertions(+), 31 deletions(-)
diff --git a/libnvme/src/accessors.ld b/libnvme/src/accessors.ld
index 9e5653b92..433767191 100644
--- a/libnvme/src/accessors.ld
+++ b/libnvme/src/accessors.ld
@@ -14,8 +14,6 @@ LIBNVME_ACCESSORS_3 {
nvme_path_set_name;
nvme_path_get_sysfs_dir;
nvme_path_set_sysfs_dir;
- nvme_path_get_numa_nodes;
- nvme_path_set_numa_nodes;
nvme_path_get_grpid;
nvme_path_set_grpid;
nvme_ns_get_nsid;
diff --git a/libnvme/src/libnvme.ld b/libnvme/src/libnvme.ld
index 38625cbf4..f2972f455 100644
--- a/libnvme/src/libnvme.ld
+++ b/libnvme/src/libnvme.ld
@@ -143,6 +143,7 @@ LIBNVME_3 {
nvme_path_get_ns;
nvme_path_get_queue_depth;
nvme_path_get_ana_state;
+ nvme_path_get_numa_nodes;
nvme_random_uuid;
nvme_read_config;
nvme_read_hostid;
diff --git a/libnvme/src/nvme/accessors.c b/libnvme/src/nvme/accessors.c
index 8b095ed4d..a98f26234 100644
--- a/libnvme/src/nvme/accessors.c
+++ b/libnvme/src/nvme/accessors.c
@@ -52,19 +52,6 @@ __public const char *nvme_path_get_sysfs_dir(const struct nvme_path *p)
return p->sysfs_dir;
}
-__public void nvme_path_set_numa_nodes(
- struct nvme_path *p,
- const char *numa_nodes)
-{
- free(p->numa_nodes);
- p->numa_nodes = numa_nodes ? strdup(numa_nodes) : NULL;
-}
-
-__public const char *nvme_path_get_numa_nodes(const struct nvme_path *p)
-{
- return p->numa_nodes;
-}
-
__public void nvme_path_set_grpid(struct nvme_path *p, int grpid)
{
p->grpid = grpid;
diff --git a/libnvme/src/nvme/accessors.h b/libnvme/src/nvme/accessors.h
index 3ede23cbc..f9323ad11 100644
--- a/libnvme/src/nvme/accessors.h
+++ b/libnvme/src/nvme/accessors.h
@@ -68,21 +68,6 @@ void nvme_path_set_sysfs_dir(struct nvme_path *p, const char *sysfs_dir);
*/
const char *nvme_path_get_sysfs_dir(const struct nvme_path *p);
-/**
- * nvme_path_set_numa_nodes() - Set numa_nodes.
- * @p: The &struct nvme_path instance to update.
- * @numa_nodes: New string; a copy is stored. Pass NULL to clear.
- */
-void nvme_path_set_numa_nodes(struct nvme_path *p, const char *numa_nodes);
-
-/**
- * nvme_path_get_numa_nodes() - Get numa_nodes.
- * @p: The &struct nvme_path instance to query.
- *
- * Return: The value of the numa_nodes field, or NULL if not set.
- */
-const char *nvme_path_get_numa_nodes(const struct nvme_path *p);
-
/**
* nvme_path_set_grpid() - Set grpid.
* @p: The &struct nvme_path instance to update.
diff --git a/libnvme/src/nvme/private.h b/libnvme/src/nvme/private.h
index 7631c4084..e115c4310 100644
--- a/libnvme/src/nvme/private.h
+++ b/libnvme/src/nvme/private.h
@@ -137,8 +137,8 @@ struct nvme_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 f087d7b03..93982dfd2 100644
--- a/libnvme/src/nvme/tree.c
+++ b/libnvme/src/nvme/tree.c
@@ -821,6 +821,21 @@ __public char *nvme_path_get_ana_state(nvme_path_t p)
return p->ana_state;
}
+__public char *nvme_path_get_numa_nodes(nvme_path_t p)
+{
+ _cleanup_free_ char *numa_nodes = NULL;
+
+ numa_nodes = nvme_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 nvme_path *p)
{
list_del_init(&p->entry);
diff --git a/libnvme/src/nvme/tree.h b/libnvme/src/nvme/tree.h
index ec0f4f2e6..1240f3023 100644
--- a/libnvme/src/nvme/tree.h
+++ b/libnvme/src/nvme/tree.h
@@ -687,6 +687,14 @@ int nvme_path_get_queue_depth(nvme_path_t p);
*/
char *nvme_path_get_ana_state(nvme_path_t p);
+/**
+ * nvme_path_get_numa_nodes() - Numa nodes of an nvme_path_t object
+ * @p: &nvme_path_t object
+ *
+ * Return: Numa nodes of @p
+ */
+char *nvme_path_get_numa_nodes(nvme_path_t p);
+
/**
* nvme_path_get_ctrl() - Parent controller of an nvme_path_t object
* @p: &nvme_path_t object
--
2.53.0
More information about the Linux-nvme
mailing list