public inbox for linux-nvme@lists.infradead.org
 help / color / mirror / Atom feed
From: Nilay Shroff <nilay@linux.ibm.com>
To: linux-nvme@lists.infradead.org
Cc: dwagner@suse.de, hare@suse.com, kbusch@kernel.org, hch@lst.de,
	gjoyce@linux.ibm.com, wenxiong@linux.ibm.com,
	Nilay Shroff <nilay@linux.ibm.com>
Subject: [PATCHv3 3/9] libnvme: annotate libnvme_subsystem::iopolicy with !accessors:none
Date: Tue, 21 Apr 2026 20:20:24 +0530	[thread overview]
Message-ID: <20260421145038.3458987-4-nilay@linux.ibm.com> (raw)
In-Reply-To: <20260421145038.3458987-1-nilay@linux.ibm.com>

The default accessor generation creates getters that return cached
attribute values. However, for libnvme_subsystem::iopolicy, 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_subsystem::iopolicy with "!accessors:none" to disable the
auto-generated accessor, and provide a custom implementation of
libnvme_subsystem_get_iopolicy() that returns the current value.

Signed-off-by: Nilay Shroff <nilay@linux.ibm.com>
---
 libnvme/src/accessors.ld     |  2 --
 libnvme/src/libnvme.ld       |  1 +
 libnvme/src/nvme/accessors.c | 14 --------------
 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(+), 34 deletions(-)

diff --git a/libnvme/src/accessors.ld b/libnvme/src/accessors.ld
index 4ccba1a6e..e23d9d7a2 100644
--- a/libnvme/src/accessors.ld
+++ b/libnvme/src/accessors.ld
@@ -174,7 +174,6 @@ LIBNVME_ACCESSORS_3 {
 		libnvme_path_set_sysfs_dir;
 		libnvme_subsystem_get_application;
 		libnvme_subsystem_get_firmware;
-		libnvme_subsystem_get_iopolicy;
 		libnvme_subsystem_get_model;
 		libnvme_subsystem_get_name;
 		libnvme_subsystem_get_serial;
@@ -182,5 +181,4 @@ LIBNVME_ACCESSORS_3 {
 		libnvme_subsystem_get_subsystype;
 		libnvme_subsystem_get_sysfs_dir;
 		libnvme_subsystem_set_application;
-		libnvme_subsystem_set_iopolicy;
 };
diff --git a/libnvme/src/libnvme.ld b/libnvme/src/libnvme.ld
index 9b26de5cd..1ad02034a 100644
--- a/libnvme/src/libnvme.ld
+++ b/libnvme/src/libnvme.ld
@@ -177,6 +177,7 @@ LIBNVME_3 {
 		libnvme_subsystem_first_ctrl;
 		libnvme_subsystem_first_ns;
 		libnvme_subsystem_get_host;
+		libnvme_subsystem_get_iopolicy;
 		libnvme_subsystem_lookup_namespace;
 		libnvme_subsystem_next_ctrl;
 		libnvme_subsystem_next_ns;
diff --git a/libnvme/src/nvme/accessors.c b/libnvme/src/nvme/accessors.c
index bcae8d578..a2729014d 100644
--- a/libnvme/src/nvme/accessors.c
+++ b/libnvme/src/nvme/accessors.c
@@ -661,20 +661,6 @@ __public const char *libnvme_subsystem_get_application(
 	return p->application;
 }
 
-__public void libnvme_subsystem_set_iopolicy(
-		struct libnvme_subsystem *p,
-		const char *iopolicy)
-{
-	free(p->iopolicy);
-	p->iopolicy = iopolicy ? strdup(iopolicy) : NULL;
-}
-
-__public const char *libnvme_subsystem_get_iopolicy(
-		const struct libnvme_subsystem *p)
-{
-	return p->iopolicy;
-}
-
 /****************************************************************************
  * Accessors for: struct libnvme_host
  ****************************************************************************/
diff --git a/libnvme/src/nvme/accessors.h b/libnvme/src/nvme/accessors.h
index 7ade91794..33484c723 100644
--- a/libnvme/src/nvme/accessors.h
+++ b/libnvme/src/nvme/accessors.h
@@ -901,23 +901,6 @@ void libnvme_subsystem_set_application(
 const char *libnvme_subsystem_get_application(
 		const struct libnvme_subsystem *p);
 
-/**
- * libnvme_subsystem_set_iopolicy() - Set iopolicy.
- * @p: The &struct libnvme_subsystem instance to update.
- * @iopolicy: New string; a copy is stored. Pass NULL to clear.
- */
-void libnvme_subsystem_set_iopolicy(
-		struct libnvme_subsystem *p,
-		const char *iopolicy);
-
-/**
- * libnvme_subsystem_get_iopolicy() - Get iopolicy.
- * @p: The &struct libnvme_subsystem instance to query.
- *
- * Return: The value of the iopolicy field, or NULL if not set.
- */
-const char *libnvme_subsystem_get_iopolicy(const struct libnvme_subsystem *p);
-
 /****************************************************************************
  * Accessors for: struct libnvme_host
  ****************************************************************************/
diff --git a/libnvme/src/nvme/private.h b/libnvme/src/nvme/private.h
index 2471495ad..037cde7e2 100644
--- a/libnvme/src/nvme/private.h
+++ b/libnvme/src/nvme/private.h
@@ -269,7 +269,7 @@ struct libnvme_subsystem { // !generate-accessors
 	char *firmware; // !accessors:readonly
 	char *subsystype; // !accessors:readonly
 	char *application;
-	char *iopolicy;
+	char *iopolicy; //!accessors:none
 };
 
 struct libnvme_host { // !generate-accessors
diff --git a/libnvme/src/nvme/tree.c b/libnvme/src/nvme/tree.c
index c2c959871..9e8c18da4 100644
--- a/libnvme/src/nvme/tree.c
+++ b/libnvme/src/nvme/tree.c
@@ -464,6 +464,21 @@ __public libnvme_host_t libnvme_subsystem_get_host(libnvme_subsystem_t s)
 	return s->h;
 }
 
+__public char *libnvme_subsystem_get_iopolicy(libnvme_subsystem_t s)
+{
+	__cleanup_free char *iopolicy = NULL;
+
+	iopolicy = libnvme_get_subsys_attr(s, "iopolicy");
+	if (iopolicy) {
+		if (!s->iopolicy || strcmp(iopolicy, s->iopolicy)) {
+			free(s->iopolicy);
+			s->iopolicy = strdup(iopolicy);
+		}
+	}
+
+	return s->iopolicy;
+}
+
 __public libnvme_ns_t libnvme_subsystem_first_ns(libnvme_subsystem_t s)
 {
 	return list_top(&s->namespaces, struct libnvme_ns, entry);
diff --git a/libnvme/src/nvme/tree.h b/libnvme/src/nvme/tree.h
index 7cd90c620..93140fcb0 100644
--- a/libnvme/src/nvme/tree.h
+++ b/libnvme/src/nvme/tree.h
@@ -214,6 +214,14 @@ void libnvme_free_subsystem(struct libnvme_subsystem *s);
  */
 libnvme_host_t libnvme_subsystem_get_host(libnvme_subsystem_t s);
 
+/**
+ * libnvme_subsystem_get_iopolicy() - Get subsystem iopolicy name
+ * @s:	subsystem
+ *
+ * Return: The iopolicy configured in subsystem @s
+ */
+char *libnvme_subsystem_get_iopolicy(libnvme_subsystem_t s);
+
 /**
  * libnvme_ctrl_first_ns() - Start namespace iterator
  * @c:	Controller instance
-- 
2.53.0



  parent reply	other threads:[~2026-04-21 14:51 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-21 14:50 [PATCHv3 0/9] libnvme: add support for retrieving additional NVMe stat Nilay Shroff
2026-04-21 14:50 ` [PATCHv3 1/9] libnvme: annotate libnvme_path::ana_state with !accessors:none Nilay Shroff
2026-04-21 14:50 ` [PATCHv3 2/9] libnvme: annotate libnvme_path::numa_nodes " Nilay Shroff
2026-04-21 14:50 ` Nilay Shroff [this message]
2026-04-21 14:50 ` [PATCHv3 4/9] libnvme: add support for retrieving per-path gendisk I/O statistics Nilay Shroff
2026-04-21 14:50 ` [PATCHv3 5/9] libnvme: add support for retrieving namespace " Nilay Shroff
2026-04-21 14:50 ` [PATCHv3 6/9] libnvme: add support for per-path diagnostic counters Nilay Shroff
2026-04-21 14:50 ` [PATCHv3 7/9] libnvme: add support for namespace " Nilay Shroff
2026-04-21 14:50 ` [PATCHv3 8/9] libnvme: add support for nshead " Nilay Shroff
2026-04-21 14:50 ` [PATCHv3 9/9] libnvme: add support for ctrl " Nilay Shroff

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260421145038.3458987-4-nilay@linux.ibm.com \
    --to=nilay@linux.ibm.com \
    --cc=dwagner@suse.de \
    --cc=gjoyce@linux.ibm.com \
    --cc=hare@suse.com \
    --cc=hch@lst.de \
    --cc=kbusch@kernel.org \
    --cc=linux-nvme@lists.infradead.org \
    --cc=wenxiong@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox