From a89d31214db3db245755c90ffff72af21a44417e Mon Sep 17 00:00:00 2001 From: Hannes Reinecke Date: Thu, 19 Mar 2026 08:54:34 +0100 Subject: [PATCH 1/5] libnvme: generate read-only accessor for 'phy_slot' No reason why it should not be auto-generated. Signed-off-by: Hannes Reinecke --- libnvme/src/accessors.ld | 1 + libnvme/src/nvme/accessors.c | 5 +++++ libnvme/src/nvme/accessors.h | 8 ++++++++ libnvme/src/nvme/private.h | 2 +- libnvme/src/nvme/tree.c | 16 +++++----------- libnvme/src/nvme/tree.h | 9 --------- 6 files changed, 20 insertions(+), 21 deletions(-) diff --git a/libnvme/src/accessors.ld b/libnvme/src/accessors.ld index 28401c804e..59804aa666 100644 --- a/libnvme/src/accessors.ld +++ b/libnvme/src/accessors.ld @@ -86,6 +86,7 @@ LIBNVME_ACCESSORS_3 { nvme_ctrl_set_discovered; nvme_ctrl_get_persistent; nvme_ctrl_set_persistent; + nvme_ctrl_get_phy_slot; nvme_subsystem_get_name; nvme_subsystem_set_name; nvme_subsystem_get_sysfs_dir; diff --git a/libnvme/src/nvme/accessors.c b/libnvme/src/nvme/accessors.c index ca22a4ce3a..3387445d4b 100644 --- a/libnvme/src/nvme/accessors.c +++ b/libnvme/src/nvme/accessors.c @@ -387,6 +387,11 @@ const char *nvme_ctrl_get_dctype(const struct nvme_ctrl *p) return p->dctype; } +const char *nvme_ctrl_get_phy_slot(const struct nvme_ctrl *p) +{ + return p->phy_slot; +} + void nvme_ctrl_set_host_traddr(struct nvme_ctrl *p, const char *host_traddr) { free(p->host_traddr); diff --git a/libnvme/src/nvme/accessors.h b/libnvme/src/nvme/accessors.h index 9611dada55..4c26667ca4 100644 --- a/libnvme/src/nvme/accessors.h +++ b/libnvme/src/nvme/accessors.h @@ -532,6 +532,14 @@ void nvme_ctrl_set_dctype(struct nvme_ctrl *p, const char *dctype); */ const char *nvme_ctrl_get_dctype(const struct nvme_ctrl *p); +/** + * nvme_ctrl_get_phy_slot() - Get phy_slot. + * @p: The &struct nvme_ctrl instance to query. + * + * Return: The value of the phy_slot field, or NULL if not set. + */ +const char *nvme_ctrl_get_phy_slot(const struct nvme_ctrl *p); + /** * nvme_ctrl_set_host_traddr() - Set host_traddr. * @p: The &struct nvme_ctrl instance to update. diff --git a/libnvme/src/nvme/private.h b/libnvme/src/nvme/private.h index 749c6c616b..82ce3af57d 100644 --- a/libnvme/src/nvme/private.h +++ b/libnvme/src/nvme/private.h @@ -206,7 +206,7 @@ struct nvme_ctrl { /*!generate-accessors*/ char *cntrltype; char *cntlid; char *dctype; - char *phy_slot; //!accessors:none + char *phy_slot; //!accessors:readonly char *host_traddr; char *host_iface; bool discovery_ctrl; diff --git a/libnvme/src/nvme/tree.c b/libnvme/src/nvme/tree.c index dcc18f9b8d..183784c20d 100644 --- a/libnvme/src/nvme/tree.c +++ b/libnvme/src/nvme/tree.c @@ -921,11 +921,6 @@ char *nvme_ctrl_get_src_addr(nvme_ctrl_t c, char *src_addr, size_t src_addr_len) return src_addr; } -const char *nvme_ctrl_get_phy_slot(nvme_ctrl_t c) -{ - return c->phy_slot ? c->phy_slot : ""; -} - const char *nvme_ctrl_get_state(nvme_ctrl_t c) { char *state = c->state; @@ -1603,8 +1598,7 @@ static int nvme_ctrl_lookup_subsystem_name(struct nvme_global_ctx *ctx, } static int nvme_ctrl_lookup_phy_slot(struct nvme_global_ctx *ctx, - const char *address, - char **slotp) + nvme_ctrl_t c) { const char *slots_sysfs_dir = nvme_slots_sysfs_dir(); _cleanup_free_ char *target_addr = NULL; @@ -1613,7 +1607,7 @@ static int nvme_ctrl_lookup_phy_slot(struct nvme_global_ctx *ctx, char *slot; int ret; - if (!address) + if (!c->address) return -EINVAL; slots_dir = opendir(slots_sysfs_dir); @@ -1623,7 +1617,7 @@ static int nvme_ctrl_lookup_phy_slot(struct nvme_global_ctx *ctx, return -errno; } - target_addr = strndup(address, 10); + target_addr = strndup(c->address, 10); while ((entry = readdir(slots_dir))) { if (entry->d_type == DT_DIR && strncmp(entry->d_name, ".", 1) != 0 && @@ -1647,7 +1641,7 @@ static int nvme_ctrl_lookup_phy_slot(struct nvme_global_ctx *ctx, if (!slot) return -ENOMEM; - *slotp = slot; + c->phy_slot = slot; return 0; } } @@ -1760,7 +1754,7 @@ static int nvme_reconfigure_ctrl(struct nvme_global_ctx *ctx, nvme_ctrl_t c, con c->cntrltype = nvme_get_ctrl_attr(c, "cntrltype"); c->cntlid = nvme_get_ctrl_attr(c, "cntlid"); c->dctype = nvme_get_ctrl_attr(c, "dctype"); - nvme_ctrl_lookup_phy_slot(ctx, c->address, &c->phy_slot); + nvme_ctrl_lookup_phy_slot(ctx, c); nvme_read_sysfs_dhchap(ctx, c); nvme_read_sysfs_tls(ctx, c); diff --git a/libnvme/src/nvme/tree.h b/libnvme/src/nvme/tree.h index fde0fe11bd..195f8301ef 100644 --- a/libnvme/src/nvme/tree.h +++ b/libnvme/src/nvme/tree.h @@ -726,15 +726,6 @@ void nvme_ctrl_release_transport_handle(nvme_ctrl_t c); */ char *nvme_ctrl_get_src_addr(nvme_ctrl_t c, char *src_addr, size_t src_addr_len); -/** - * nvme_ctrl_get_phy_slot() - PCI physical slot number of a controller - * @c: Controller instance - * - * Return: PCI physical slot number of @c or empty string if slot - * number is not present. - */ -const char *nvme_ctrl_get_phy_slot(nvme_ctrl_t c); - /** * nvme_ctrl_get_state() - Running state of a controller * @c: Controller instance From b3bf3037b830a6650a81ccc6a75e9337ed81f856 Mon Sep 17 00:00:00 2001 From: Hannes Reinecke Date: Thu, 19 Mar 2026 09:01:36 +0100 Subject: [PATCH 2/5] libnvme: read-only controller accessors Some controller attributes are fixed for the lifetime of the controller, so once established they cannot be changed. Consequently it's pointless to have a 'setter' function as this would not do what's expected. Signed-off-by: Hannes Reinecke --- libnvme/src/accessors.ld | 16 ----- libnvme/src/nvme/accessors.c | 96 ------------------------------ libnvme/src/nvme/accessors.h | 112 ----------------------------------- libnvme/src/nvme/private.h | 32 +++++----- 4 files changed, 16 insertions(+), 240 deletions(-) diff --git a/libnvme/src/accessors.ld b/libnvme/src/accessors.ld index 59804aa666..5f2c2cefe5 100644 --- a/libnvme/src/accessors.ld +++ b/libnvme/src/accessors.ld @@ -37,27 +37,16 @@ LIBNVME_ACCESSORS_3 { nvme_ns_get_lba_util; nvme_ns_set_lba_util; nvme_ctrl_get_name; - nvme_ctrl_set_name; nvme_ctrl_get_sysfs_dir; - nvme_ctrl_set_sysfs_dir; nvme_ctrl_get_firmware; - nvme_ctrl_set_firmware; nvme_ctrl_get_model; - nvme_ctrl_set_model; nvme_ctrl_get_numa_node; - nvme_ctrl_set_numa_node; nvme_ctrl_get_queue_count; - nvme_ctrl_set_queue_count; nvme_ctrl_get_serial; - nvme_ctrl_set_serial; nvme_ctrl_get_sqsize; - nvme_ctrl_set_sqsize; nvme_ctrl_get_transport; - nvme_ctrl_set_transport; nvme_ctrl_get_traddr; - nvme_ctrl_set_traddr; nvme_ctrl_get_trsvcid; - nvme_ctrl_set_trsvcid; nvme_ctrl_get_dhchap_host_key; nvme_ctrl_set_dhchap_host_key; nvme_ctrl_get_dhchap_ctrl_key; @@ -69,15 +58,10 @@ LIBNVME_ACCESSORS_3 { nvme_ctrl_get_tls_key; nvme_ctrl_set_tls_key; nvme_ctrl_get_cntrltype; - nvme_ctrl_set_cntrltype; nvme_ctrl_get_cntlid; - nvme_ctrl_set_cntlid; nvme_ctrl_get_dctype; - nvme_ctrl_set_dctype; nvme_ctrl_get_host_traddr; - nvme_ctrl_set_host_traddr; nvme_ctrl_get_host_iface; - nvme_ctrl_set_host_iface; nvme_ctrl_get_discovery_ctrl; nvme_ctrl_set_discovery_ctrl; nvme_ctrl_get_unique_discovery_ctrl; diff --git a/libnvme/src/nvme/accessors.c b/libnvme/src/nvme/accessors.c index 3387445d4b..70a6163d1f 100644 --- a/libnvme/src/nvme/accessors.c +++ b/libnvme/src/nvme/accessors.c @@ -171,122 +171,56 @@ uint64_t nvme_ns_get_lba_util(const struct nvme_ns *p) * Accessors for: struct nvme_ctrl ****************************************************************************/ -void nvme_ctrl_set_name(struct nvme_ctrl *p, const char *name) -{ - free(p->name); - p->name = name ? strdup(name) : NULL; -} - const char *nvme_ctrl_get_name(const struct nvme_ctrl *p) { return p->name; } -void nvme_ctrl_set_sysfs_dir(struct nvme_ctrl *p, const char *sysfs_dir) -{ - free(p->sysfs_dir); - p->sysfs_dir = sysfs_dir ? strdup(sysfs_dir) : NULL; -} - const char *nvme_ctrl_get_sysfs_dir(const struct nvme_ctrl *p) { return p->sysfs_dir; } -void nvme_ctrl_set_firmware(struct nvme_ctrl *p, const char *firmware) -{ - free(p->firmware); - p->firmware = firmware ? strdup(firmware) : NULL; -} - const char *nvme_ctrl_get_firmware(const struct nvme_ctrl *p) { return p->firmware; } -void nvme_ctrl_set_model(struct nvme_ctrl *p, const char *model) -{ - free(p->model); - p->model = model ? strdup(model) : NULL; -} - const char *nvme_ctrl_get_model(const struct nvme_ctrl *p) { return p->model; } -void nvme_ctrl_set_numa_node(struct nvme_ctrl *p, const char *numa_node) -{ - free(p->numa_node); - p->numa_node = numa_node ? strdup(numa_node) : NULL; -} - const char *nvme_ctrl_get_numa_node(const struct nvme_ctrl *p) { return p->numa_node; } -void nvme_ctrl_set_queue_count(struct nvme_ctrl *p, const char *queue_count) -{ - free(p->queue_count); - p->queue_count = queue_count ? strdup(queue_count) : NULL; -} - const char *nvme_ctrl_get_queue_count(const struct nvme_ctrl *p) { return p->queue_count; } -void nvme_ctrl_set_serial(struct nvme_ctrl *p, const char *serial) -{ - free(p->serial); - p->serial = serial ? strdup(serial) : NULL; -} - const char *nvme_ctrl_get_serial(const struct nvme_ctrl *p) { return p->serial; } -void nvme_ctrl_set_sqsize(struct nvme_ctrl *p, const char *sqsize) -{ - free(p->sqsize); - p->sqsize = sqsize ? strdup(sqsize) : NULL; -} - const char *nvme_ctrl_get_sqsize(const struct nvme_ctrl *p) { return p->sqsize; } -void nvme_ctrl_set_transport(struct nvme_ctrl *p, const char *transport) -{ - free(p->transport); - p->transport = transport ? strdup(transport) : NULL; -} - const char *nvme_ctrl_get_transport(const struct nvme_ctrl *p) { return p->transport; } -void nvme_ctrl_set_traddr(struct nvme_ctrl *p, const char *traddr) -{ - free(p->traddr); - p->traddr = traddr ? strdup(traddr) : NULL; -} - const char *nvme_ctrl_get_traddr(const struct nvme_ctrl *p) { return p->traddr; } -void nvme_ctrl_set_trsvcid(struct nvme_ctrl *p, const char *trsvcid) -{ - free(p->trsvcid); - p->trsvcid = trsvcid ? strdup(trsvcid) : NULL; -} - const char *nvme_ctrl_get_trsvcid(const struct nvme_ctrl *p) { return p->trsvcid; @@ -354,34 +288,16 @@ const char *nvme_ctrl_get_tls_key(const struct nvme_ctrl *p) return p->tls_key; } -void nvme_ctrl_set_cntrltype(struct nvme_ctrl *p, const char *cntrltype) -{ - free(p->cntrltype); - p->cntrltype = cntrltype ? strdup(cntrltype) : NULL; -} - const char *nvme_ctrl_get_cntrltype(const struct nvme_ctrl *p) { return p->cntrltype; } -void nvme_ctrl_set_cntlid(struct nvme_ctrl *p, const char *cntlid) -{ - free(p->cntlid); - p->cntlid = cntlid ? strdup(cntlid) : NULL; -} - const char *nvme_ctrl_get_cntlid(const struct nvme_ctrl *p) { return p->cntlid; } -void nvme_ctrl_set_dctype(struct nvme_ctrl *p, const char *dctype) -{ - free(p->dctype); - p->dctype = dctype ? strdup(dctype) : NULL; -} - const char *nvme_ctrl_get_dctype(const struct nvme_ctrl *p) { return p->dctype; @@ -392,23 +308,11 @@ const char *nvme_ctrl_get_phy_slot(const struct nvme_ctrl *p) return p->phy_slot; } -void nvme_ctrl_set_host_traddr(struct nvme_ctrl *p, const char *host_traddr) -{ - free(p->host_traddr); - p->host_traddr = host_traddr ? strdup(host_traddr) : NULL; -} - const char *nvme_ctrl_get_host_traddr(const struct nvme_ctrl *p) { return p->host_traddr; } -void nvme_ctrl_set_host_iface(struct nvme_ctrl *p, const char *host_iface) -{ - free(p->host_iface); - p->host_iface = host_iface ? strdup(host_iface) : NULL; -} - const char *nvme_ctrl_get_host_iface(const struct nvme_ctrl *p) { return p->host_iface; diff --git a/libnvme/src/nvme/accessors.h b/libnvme/src/nvme/accessors.h index 4c26667ca4..8da504c679 100644 --- a/libnvme/src/nvme/accessors.h +++ b/libnvme/src/nvme/accessors.h @@ -241,13 +241,6 @@ uint64_t nvme_ns_get_lba_util(const struct nvme_ns *p); * Accessors for: struct nvme_ctrl ****************************************************************************/ -/** - * nvme_ctrl_set_name() - Set name. - * @p: The &struct nvme_ctrl instance to update. - * @name: New string; a copy is stored. Pass NULL to clear. - */ -void nvme_ctrl_set_name(struct nvme_ctrl *p, const char *name); - /** * nvme_ctrl_get_name() - Get name. * @p: The &struct nvme_ctrl instance to query. @@ -256,13 +249,6 @@ void nvme_ctrl_set_name(struct nvme_ctrl *p, const char *name); */ const char *nvme_ctrl_get_name(const struct nvme_ctrl *p); -/** - * nvme_ctrl_set_sysfs_dir() - Set sysfs_dir. - * @p: The &struct nvme_ctrl instance to update. - * @sysfs_dir: New string; a copy is stored. Pass NULL to clear. - */ -void nvme_ctrl_set_sysfs_dir(struct nvme_ctrl *p, const char *sysfs_dir); - /** * nvme_ctrl_get_sysfs_dir() - Get sysfs_dir. * @p: The &struct nvme_ctrl instance to query. @@ -271,13 +257,6 @@ void nvme_ctrl_set_sysfs_dir(struct nvme_ctrl *p, const char *sysfs_dir); */ const char *nvme_ctrl_get_sysfs_dir(const struct nvme_ctrl *p); -/** - * nvme_ctrl_set_firmware() - Set firmware. - * @p: The &struct nvme_ctrl instance to update. - * @firmware: New string; a copy is stored. Pass NULL to clear. - */ -void nvme_ctrl_set_firmware(struct nvme_ctrl *p, const char *firmware); - /** * nvme_ctrl_get_firmware() - Get firmware. * @p: The &struct nvme_ctrl instance to query. @@ -286,13 +265,6 @@ void nvme_ctrl_set_firmware(struct nvme_ctrl *p, const char *firmware); */ const char *nvme_ctrl_get_firmware(const struct nvme_ctrl *p); -/** - * nvme_ctrl_set_model() - Set model. - * @p: The &struct nvme_ctrl instance to update. - * @model: New string; a copy is stored. Pass NULL to clear. - */ -void nvme_ctrl_set_model(struct nvme_ctrl *p, const char *model); - /** * nvme_ctrl_get_model() - Get model. * @p: The &struct nvme_ctrl instance to query. @@ -301,13 +273,6 @@ void nvme_ctrl_set_model(struct nvme_ctrl *p, const char *model); */ const char *nvme_ctrl_get_model(const struct nvme_ctrl *p); -/** - * nvme_ctrl_set_numa_node() - Set numa_node. - * @p: The &struct nvme_ctrl instance to update. - * @numa_node: New string; a copy is stored. Pass NULL to clear. - */ -void nvme_ctrl_set_numa_node(struct nvme_ctrl *p, const char *numa_node); - /** * nvme_ctrl_get_numa_node() - Get numa_node. * @p: The &struct nvme_ctrl instance to query. @@ -316,13 +281,6 @@ void nvme_ctrl_set_numa_node(struct nvme_ctrl *p, const char *numa_node); */ const char *nvme_ctrl_get_numa_node(const struct nvme_ctrl *p); -/** - * nvme_ctrl_set_queue_count() - Set queue_count. - * @p: The &struct nvme_ctrl instance to update. - * @queue_count: New string; a copy is stored. Pass NULL to clear. - */ -void nvme_ctrl_set_queue_count(struct nvme_ctrl *p, const char *queue_count); - /** * nvme_ctrl_get_queue_count() - Get queue_count. * @p: The &struct nvme_ctrl instance to query. @@ -331,13 +289,6 @@ void nvme_ctrl_set_queue_count(struct nvme_ctrl *p, const char *queue_count); */ const char *nvme_ctrl_get_queue_count(const struct nvme_ctrl *p); -/** - * nvme_ctrl_set_serial() - Set serial. - * @p: The &struct nvme_ctrl instance to update. - * @serial: New string; a copy is stored. Pass NULL to clear. - */ -void nvme_ctrl_set_serial(struct nvme_ctrl *p, const char *serial); - /** * nvme_ctrl_get_serial() - Get serial. * @p: The &struct nvme_ctrl instance to query. @@ -346,13 +297,6 @@ void nvme_ctrl_set_serial(struct nvme_ctrl *p, const char *serial); */ const char *nvme_ctrl_get_serial(const struct nvme_ctrl *p); -/** - * nvme_ctrl_set_sqsize() - Set sqsize. - * @p: The &struct nvme_ctrl instance to update. - * @sqsize: New string; a copy is stored. Pass NULL to clear. - */ -void nvme_ctrl_set_sqsize(struct nvme_ctrl *p, const char *sqsize); - /** * nvme_ctrl_get_sqsize() - Get sqsize. * @p: The &struct nvme_ctrl instance to query. @@ -361,13 +305,6 @@ void nvme_ctrl_set_sqsize(struct nvme_ctrl *p, const char *sqsize); */ const char *nvme_ctrl_get_sqsize(const struct nvme_ctrl *p); -/** - * nvme_ctrl_set_transport() - Set transport. - * @p: The &struct nvme_ctrl instance to update. - * @transport: New string; a copy is stored. Pass NULL to clear. - */ -void nvme_ctrl_set_transport(struct nvme_ctrl *p, const char *transport); - /** * nvme_ctrl_get_transport() - Get transport. * @p: The &struct nvme_ctrl instance to query. @@ -376,13 +313,6 @@ void nvme_ctrl_set_transport(struct nvme_ctrl *p, const char *transport); */ const char *nvme_ctrl_get_transport(const struct nvme_ctrl *p); -/** - * nvme_ctrl_set_traddr() - Set traddr. - * @p: The &struct nvme_ctrl instance to update. - * @traddr: New string; a copy is stored. Pass NULL to clear. - */ -void nvme_ctrl_set_traddr(struct nvme_ctrl *p, const char *traddr); - /** * nvme_ctrl_get_traddr() - Get traddr. * @p: The &struct nvme_ctrl instance to query. @@ -391,13 +321,6 @@ void nvme_ctrl_set_traddr(struct nvme_ctrl *p, const char *traddr); */ const char *nvme_ctrl_get_traddr(const struct nvme_ctrl *p); -/** - * nvme_ctrl_set_trsvcid() - Set trsvcid. - * @p: The &struct nvme_ctrl instance to update. - * @trsvcid: New string; a copy is stored. Pass NULL to clear. - */ -void nvme_ctrl_set_trsvcid(struct nvme_ctrl *p, const char *trsvcid); - /** * nvme_ctrl_get_trsvcid() - Get trsvcid. * @p: The &struct nvme_ctrl instance to query. @@ -487,13 +410,6 @@ void nvme_ctrl_set_tls_key(struct nvme_ctrl *p, const char *tls_key); */ const char *nvme_ctrl_get_tls_key(const struct nvme_ctrl *p); -/** - * nvme_ctrl_set_cntrltype() - Set cntrltype. - * @p: The &struct nvme_ctrl instance to update. - * @cntrltype: New string; a copy is stored. Pass NULL to clear. - */ -void nvme_ctrl_set_cntrltype(struct nvme_ctrl *p, const char *cntrltype); - /** * nvme_ctrl_get_cntrltype() - Get cntrltype. * @p: The &struct nvme_ctrl instance to query. @@ -502,13 +418,6 @@ void nvme_ctrl_set_cntrltype(struct nvme_ctrl *p, const char *cntrltype); */ const char *nvme_ctrl_get_cntrltype(const struct nvme_ctrl *p); -/** - * nvme_ctrl_set_cntlid() - Set cntlid. - * @p: The &struct nvme_ctrl instance to update. - * @cntlid: New string; a copy is stored. Pass NULL to clear. - */ -void nvme_ctrl_set_cntlid(struct nvme_ctrl *p, const char *cntlid); - /** * nvme_ctrl_get_cntlid() - Get cntlid. * @p: The &struct nvme_ctrl instance to query. @@ -517,13 +426,6 @@ void nvme_ctrl_set_cntlid(struct nvme_ctrl *p, const char *cntlid); */ const char *nvme_ctrl_get_cntlid(const struct nvme_ctrl *p); -/** - * nvme_ctrl_set_dctype() - Set dctype. - * @p: The &struct nvme_ctrl instance to update. - * @dctype: New string; a copy is stored. Pass NULL to clear. - */ -void nvme_ctrl_set_dctype(struct nvme_ctrl *p, const char *dctype); - /** * nvme_ctrl_get_dctype() - Get dctype. * @p: The &struct nvme_ctrl instance to query. @@ -540,13 +442,6 @@ const char *nvme_ctrl_get_dctype(const struct nvme_ctrl *p); */ const char *nvme_ctrl_get_phy_slot(const struct nvme_ctrl *p); -/** - * nvme_ctrl_set_host_traddr() - Set host_traddr. - * @p: The &struct nvme_ctrl instance to update. - * @host_traddr: New string; a copy is stored. Pass NULL to clear. - */ -void nvme_ctrl_set_host_traddr(struct nvme_ctrl *p, const char *host_traddr); - /** * nvme_ctrl_get_host_traddr() - Get host_traddr. * @p: The &struct nvme_ctrl instance to query. @@ -555,13 +450,6 @@ void nvme_ctrl_set_host_traddr(struct nvme_ctrl *p, const char *host_traddr); */ const char *nvme_ctrl_get_host_traddr(const struct nvme_ctrl *p); -/** - * nvme_ctrl_set_host_iface() - Set host_iface. - * @p: The &struct nvme_ctrl instance to update. - * @host_iface: New string; a copy is stored. Pass NULL to clear. - */ -void nvme_ctrl_set_host_iface(struct nvme_ctrl *p, const char *host_iface); - /** * nvme_ctrl_get_host_iface() - Get host_iface. * @p: The &struct nvme_ctrl instance to query. diff --git a/libnvme/src/nvme/private.h b/libnvme/src/nvme/private.h index 82ce3af57d..224ab23923 100644 --- a/libnvme/src/nvme/private.h +++ b/libnvme/src/nvme/private.h @@ -184,31 +184,31 @@ struct nvme_ctrl { /*!generate-accessors*/ struct nvme_global_ctx *ctx; struct nvme_transport_handle *hdl; - char *name; - char *sysfs_dir; + char *name; //!accessors:readonly + char *sysfs_dir; //!accessors:readonly char *address; //!accessors:none - char *firmware; - char *model; + char *firmware; //!accessors:readonly + char *model; //!accessors:readonly char *state; //!accessors:none - char *numa_node; - char *queue_count; - char *serial; - char *sqsize; - char *transport; + char *numa_node; //!accessors:readonly + char *queue_count; //!accessors:readonly + char *serial; //!accessors:readonly + char *sqsize; //!accessors:readonly + char *transport; //!accessors:readonly char *subsysnqn; //!accessors:none - char *traddr; - char *trsvcid; + char *traddr; //!accessors:readonly + char *trsvcid; //!accessors:readonly char *dhchap_host_key; char *dhchap_ctrl_key; char *keyring; char *tls_key_identity; char *tls_key; - char *cntrltype; - char *cntlid; - char *dctype; + char *cntrltype; //!accessors:readonly + char *cntlid; //!accessors:readonly + char *dctype; //!accessors:readonly char *phy_slot; //!accessors:readonly - char *host_traddr; - char *host_iface; + char *host_traddr; //!accessors:readonly + char *host_iface; //!accessors:readonly bool discovery_ctrl; bool unique_discovery_ctrl; bool discovered; From 4e8ab6da7476e3fabc16bccb674fa2bd1aae072b Mon Sep 17 00:00:00 2001 From: Hannes Reinecke Date: Thu, 19 Mar 2026 09:01:36 +0100 Subject: [PATCH 3/5] libnvme: read-only subsystem accessors Most subsystem attributes are fixed for the lifetime of the subsystem, so once established they cannot be changed. Consequently it's pointless to have a 'setter' function as this would not do what's expected. Signed-off-by: Hannes Reinecke --- libnvme/src/accessors.ld | 7 ----- libnvme/src/nvme/accessors.c | 48 ------------------------------ libnvme/src/nvme/accessors.h | 57 ------------------------------------ libnvme/src/nvme/private.h | 14 ++++----- 4 files changed, 7 insertions(+), 119 deletions(-) diff --git a/libnvme/src/accessors.ld b/libnvme/src/accessors.ld index 5f2c2cefe5..4aa72661a1 100644 --- a/libnvme/src/accessors.ld +++ b/libnvme/src/accessors.ld @@ -72,19 +72,12 @@ LIBNVME_ACCESSORS_3 { nvme_ctrl_set_persistent; nvme_ctrl_get_phy_slot; nvme_subsystem_get_name; - nvme_subsystem_set_name; nvme_subsystem_get_sysfs_dir; - nvme_subsystem_set_sysfs_dir; nvme_subsystem_get_subsysnqn; - nvme_subsystem_set_subsysnqn; nvme_subsystem_get_model; - nvme_subsystem_set_model; nvme_subsystem_get_serial; - nvme_subsystem_set_serial; nvme_subsystem_get_firmware; - nvme_subsystem_set_firmware; nvme_subsystem_get_subsystype; - nvme_subsystem_set_subsystype; nvme_subsystem_get_application; nvme_subsystem_set_application; nvme_subsystem_get_iopolicy; diff --git a/libnvme/src/nvme/accessors.c b/libnvme/src/nvme/accessors.c index 70a6163d1f..5e79c05e29 100644 --- a/libnvme/src/nvme/accessors.c +++ b/libnvme/src/nvme/accessors.c @@ -364,84 +364,36 @@ bool nvme_ctrl_get_persistent(const struct nvme_ctrl *p) * Accessors for: struct nvme_subsystem ****************************************************************************/ -void nvme_subsystem_set_name(struct nvme_subsystem *p, const char *name) -{ - free(p->name); - p->name = name ? strdup(name) : NULL; -} - const char *nvme_subsystem_get_name(const struct nvme_subsystem *p) { return p->name; } -void nvme_subsystem_set_sysfs_dir( - struct nvme_subsystem *p, - const char *sysfs_dir) -{ - free(p->sysfs_dir); - p->sysfs_dir = sysfs_dir ? strdup(sysfs_dir) : NULL; -} - const char *nvme_subsystem_get_sysfs_dir(const struct nvme_subsystem *p) { return p->sysfs_dir; } -void nvme_subsystem_set_subsysnqn( - struct nvme_subsystem *p, - const char *subsysnqn) -{ - free(p->subsysnqn); - p->subsysnqn = subsysnqn ? strdup(subsysnqn) : NULL; -} - const char *nvme_subsystem_get_subsysnqn(const struct nvme_subsystem *p) { return p->subsysnqn; } -void nvme_subsystem_set_model(struct nvme_subsystem *p, const char *model) -{ - free(p->model); - p->model = model ? strdup(model) : NULL; -} - const char *nvme_subsystem_get_model(const struct nvme_subsystem *p) { return p->model; } -void nvme_subsystem_set_serial(struct nvme_subsystem *p, const char *serial) -{ - free(p->serial); - p->serial = serial ? strdup(serial) : NULL; -} - const char *nvme_subsystem_get_serial(const struct nvme_subsystem *p) { return p->serial; } -void nvme_subsystem_set_firmware(struct nvme_subsystem *p, const char *firmware) -{ - free(p->firmware); - p->firmware = firmware ? strdup(firmware) : NULL; -} - const char *nvme_subsystem_get_firmware(const struct nvme_subsystem *p) { return p->firmware; } -void nvme_subsystem_set_subsystype( - struct nvme_subsystem *p, - const char *subsystype) -{ - free(p->subsystype); - p->subsystype = subsystype ? strdup(subsystype) : NULL; -} - const char *nvme_subsystem_get_subsystype(const struct nvme_subsystem *p) { return p->subsystype; diff --git a/libnvme/src/nvme/accessors.h b/libnvme/src/nvme/accessors.h index 8da504c679..01f0f88b0e 100644 --- a/libnvme/src/nvme/accessors.h +++ b/libnvme/src/nvme/accessors.h @@ -524,13 +524,6 @@ bool nvme_ctrl_get_persistent(const struct nvme_ctrl *p); * Accessors for: struct nvme_subsystem ****************************************************************************/ -/** - * nvme_subsystem_set_name() - Set name. - * @p: The &struct nvme_subsystem instance to update. - * @name: New string; a copy is stored. Pass NULL to clear. - */ -void nvme_subsystem_set_name(struct nvme_subsystem *p, const char *name); - /** * nvme_subsystem_get_name() - Get name. * @p: The &struct nvme_subsystem instance to query. @@ -539,15 +532,6 @@ void nvme_subsystem_set_name(struct nvme_subsystem *p, const char *name); */ const char *nvme_subsystem_get_name(const struct nvme_subsystem *p); -/** - * nvme_subsystem_set_sysfs_dir() - Set sysfs_dir. - * @p: The &struct nvme_subsystem instance to update. - * @sysfs_dir: New string; a copy is stored. Pass NULL to clear. - */ -void nvme_subsystem_set_sysfs_dir( - struct nvme_subsystem *p, - const char *sysfs_dir); - /** * nvme_subsystem_get_sysfs_dir() - Get sysfs_dir. * @p: The &struct nvme_subsystem instance to query. @@ -556,15 +540,6 @@ void nvme_subsystem_set_sysfs_dir( */ const char *nvme_subsystem_get_sysfs_dir(const struct nvme_subsystem *p); -/** - * nvme_subsystem_set_subsysnqn() - Set subsysnqn. - * @p: The &struct nvme_subsystem instance to update. - * @subsysnqn: New string; a copy is stored. Pass NULL to clear. - */ -void nvme_subsystem_set_subsysnqn( - struct nvme_subsystem *p, - const char *subsysnqn); - /** * nvme_subsystem_get_subsysnqn() - Get subsysnqn. * @p: The &struct nvme_subsystem instance to query. @@ -573,13 +548,6 @@ void nvme_subsystem_set_subsysnqn( */ const char *nvme_subsystem_get_subsysnqn(const struct nvme_subsystem *p); -/** - * nvme_subsystem_set_model() - Set model. - * @p: The &struct nvme_subsystem instance to update. - * @model: New string; a copy is stored. Pass NULL to clear. - */ -void nvme_subsystem_set_model(struct nvme_subsystem *p, const char *model); - /** * nvme_subsystem_get_model() - Get model. * @p: The &struct nvme_subsystem instance to query. @@ -588,13 +556,6 @@ void nvme_subsystem_set_model(struct nvme_subsystem *p, const char *model); */ const char *nvme_subsystem_get_model(const struct nvme_subsystem *p); -/** - * nvme_subsystem_set_serial() - Set serial. - * @p: The &struct nvme_subsystem instance to update. - * @serial: New string; a copy is stored. Pass NULL to clear. - */ -void nvme_subsystem_set_serial(struct nvme_subsystem *p, const char *serial); - /** * nvme_subsystem_get_serial() - Get serial. * @p: The &struct nvme_subsystem instance to query. @@ -603,15 +564,6 @@ void nvme_subsystem_set_serial(struct nvme_subsystem *p, const char *serial); */ const char *nvme_subsystem_get_serial(const struct nvme_subsystem *p); -/** - * nvme_subsystem_set_firmware() - Set firmware. - * @p: The &struct nvme_subsystem instance to update. - * @firmware: New string; a copy is stored. Pass NULL to clear. - */ -void nvme_subsystem_set_firmware( - struct nvme_subsystem *p, - const char *firmware); - /** * nvme_subsystem_get_firmware() - Get firmware. * @p: The &struct nvme_subsystem instance to query. @@ -620,15 +572,6 @@ void nvme_subsystem_set_firmware( */ const char *nvme_subsystem_get_firmware(const struct nvme_subsystem *p); -/** - * nvme_subsystem_set_subsystype() - Set subsystype. - * @p: The &struct nvme_subsystem instance to update. - * @subsystype: New string; a copy is stored. Pass NULL to clear. - */ -void nvme_subsystem_set_subsystype( - struct nvme_subsystem *p, - const char *subsystype); - /** * nvme_subsystem_get_subsystype() - Get subsystype. * @p: The &struct nvme_subsystem instance to query. diff --git a/libnvme/src/nvme/private.h b/libnvme/src/nvme/private.h index 224ab23923..796d737166 100644 --- a/libnvme/src/nvme/private.h +++ b/libnvme/src/nvme/private.h @@ -222,13 +222,13 @@ struct nvme_subsystem { /*!generate-accessors*/ struct list_head namespaces; struct nvme_host *h; - char *name; - char *sysfs_dir; - char *subsysnqn; - char *model; - char *serial; - char *firmware; - char *subsystype; + char *name; /*!accessors:readonly*/ + char *sysfs_dir; /*!accessors:readonly*/ + char *subsysnqn; /*!accessors:readonly*/ + char *model; /*!accessors:readonly*/ + char *serial; /*!accessors:readonly*/ + char *firmware; /*!accessors:readonly*/ + char *subsystype; /*!accessors:readonly*/ char *application; char *iopolicy; }; From 062b15e56fea98199068c5a07152e0c79df687a1 Mon Sep 17 00:00:00 2001 From: Hannes Reinecke Date: Thu, 19 Mar 2026 09:01:36 +0100 Subject: [PATCH 4/5] libnvme: read-only host accessors Some host attributes are fixed for the lifetime of the host, so once established they cannot be changed. Consequently it's pointless to have a 'setter' function as this would not do what's expected. Signed-off-by: Hannes Reinecke --- libnvme/src/accessors.ld | 2 -- libnvme/src/nvme/accessors.c | 12 ------------ libnvme/src/nvme/accessors.h | 14 -------------- libnvme/src/nvme/private.h | 4 ++-- 4 files changed, 2 insertions(+), 30 deletions(-) diff --git a/libnvme/src/accessors.ld b/libnvme/src/accessors.ld index 4aa72661a1..f618155eb6 100644 --- a/libnvme/src/accessors.ld +++ b/libnvme/src/accessors.ld @@ -83,9 +83,7 @@ LIBNVME_ACCESSORS_3 { nvme_subsystem_get_iopolicy; nvme_subsystem_set_iopolicy; nvme_host_get_hostnqn; - nvme_host_set_hostnqn; nvme_host_get_hostid; - nvme_host_set_hostid; nvme_host_get_dhchap_host_key; nvme_host_set_dhchap_host_key; nvme_host_get_hostsymname; diff --git a/libnvme/src/nvme/accessors.c b/libnvme/src/nvme/accessors.c index 5e79c05e29..016cd03c17 100644 --- a/libnvme/src/nvme/accessors.c +++ b/libnvme/src/nvme/accessors.c @@ -427,23 +427,11 @@ const char *nvme_subsystem_get_iopolicy(const struct nvme_subsystem *p) * Accessors for: struct nvme_host ****************************************************************************/ -void nvme_host_set_hostnqn(struct nvme_host *p, const char *hostnqn) -{ - free(p->hostnqn); - p->hostnqn = hostnqn ? strdup(hostnqn) : NULL; -} - const char *nvme_host_get_hostnqn(const struct nvme_host *p) { return p->hostnqn; } -void nvme_host_set_hostid(struct nvme_host *p, const char *hostid) -{ - free(p->hostid); - p->hostid = hostid ? strdup(hostid) : NULL; -} - const char *nvme_host_get_hostid(const struct nvme_host *p) { return p->hostid; diff --git a/libnvme/src/nvme/accessors.h b/libnvme/src/nvme/accessors.h index 01f0f88b0e..f1fb152fe6 100644 --- a/libnvme/src/nvme/accessors.h +++ b/libnvme/src/nvme/accessors.h @@ -618,13 +618,6 @@ const char *nvme_subsystem_get_iopolicy(const struct nvme_subsystem *p); * Accessors for: struct nvme_host ****************************************************************************/ -/** - * nvme_host_set_hostnqn() - Set hostnqn. - * @p: The &struct nvme_host instance to update. - * @hostnqn: New string; a copy is stored. Pass NULL to clear. - */ -void nvme_host_set_hostnqn(struct nvme_host *p, const char *hostnqn); - /** * nvme_host_get_hostnqn() - Get hostnqn. * @p: The &struct nvme_host instance to query. @@ -633,13 +626,6 @@ void nvme_host_set_hostnqn(struct nvme_host *p, const char *hostnqn); */ const char *nvme_host_get_hostnqn(const struct nvme_host *p); -/** - * nvme_host_set_hostid() - Set hostid. - * @p: The &struct nvme_host instance to update. - * @hostid: New string; a copy is stored. Pass NULL to clear. - */ -void nvme_host_set_hostid(struct nvme_host *p, const char *hostid); - /** * nvme_host_get_hostid() - Get hostid. * @p: The &struct nvme_host instance to query. diff --git a/libnvme/src/nvme/private.h b/libnvme/src/nvme/private.h index 796d737166..0e033ce610 100644 --- a/libnvme/src/nvme/private.h +++ b/libnvme/src/nvme/private.h @@ -238,8 +238,8 @@ struct nvme_host { /*!generate-accessors*/ struct list_head subsystems; struct nvme_global_ctx *ctx; - char *hostnqn; - char *hostid; + char *hostnqn; /*!accessors:readonly*/ + char *hostid; /*!accessors:readonly*/ char *dhchap_host_key; char *hostsymname; bool pdc_enabled; //!accessors:none From b1bd5be790528d49c8742341c60a446bda654865 Mon Sep 17 00:00:00 2001 From: Hannes Reinecke Date: Thu, 19 Mar 2026 09:17:10 +0100 Subject: [PATCH 5/5] libnvme: auto-generate 'subsysnqn' accessors No reason why it needs to be treated specially. Signed-off-by: Hannes Reinecke --- libnvme/src/accessors.ld | 1 + libnvme/src/nvme/accessors.c | 5 +++++ libnvme/src/nvme/accessors.h | 8 ++++++++ libnvme/src/nvme/private.h | 2 +- libnvme/src/nvme/tree.c | 5 ----- libnvme/src/nvme/tree.h | 8 -------- 6 files changed, 15 insertions(+), 14 deletions(-) diff --git a/libnvme/src/accessors.ld b/libnvme/src/accessors.ld index f618155eb6..3cd26f8f7d 100644 --- a/libnvme/src/accessors.ld +++ b/libnvme/src/accessors.ld @@ -45,6 +45,7 @@ LIBNVME_ACCESSORS_3 { nvme_ctrl_get_serial; nvme_ctrl_get_sqsize; nvme_ctrl_get_transport; + nvme_ctrl_get_subsysnqn; nvme_ctrl_get_traddr; nvme_ctrl_get_trsvcid; nvme_ctrl_get_dhchap_host_key; diff --git a/libnvme/src/nvme/accessors.c b/libnvme/src/nvme/accessors.c index 016cd03c17..7f529b3206 100644 --- a/libnvme/src/nvme/accessors.c +++ b/libnvme/src/nvme/accessors.c @@ -216,6 +216,11 @@ const char *nvme_ctrl_get_transport(const struct nvme_ctrl *p) return p->transport; } +const char *nvme_ctrl_get_subsysnqn(const struct nvme_ctrl *p) +{ + return p->subsysnqn; +} + const char *nvme_ctrl_get_traddr(const struct nvme_ctrl *p) { return p->traddr; diff --git a/libnvme/src/nvme/accessors.h b/libnvme/src/nvme/accessors.h index f1fb152fe6..5c594dd127 100644 --- a/libnvme/src/nvme/accessors.h +++ b/libnvme/src/nvme/accessors.h @@ -313,6 +313,14 @@ const char *nvme_ctrl_get_sqsize(const struct nvme_ctrl *p); */ const char *nvme_ctrl_get_transport(const struct nvme_ctrl *p); +/** + * nvme_ctrl_get_subsysnqn() - Get subsysnqn. + * @p: The &struct nvme_ctrl instance to query. + * + * Return: The value of the subsysnqn field, or NULL if not set. + */ +const char *nvme_ctrl_get_subsysnqn(const struct nvme_ctrl *p); + /** * nvme_ctrl_get_traddr() - Get traddr. * @p: The &struct nvme_ctrl instance to query. diff --git a/libnvme/src/nvme/private.h b/libnvme/src/nvme/private.h index 0e033ce610..78bbc42a63 100644 --- a/libnvme/src/nvme/private.h +++ b/libnvme/src/nvme/private.h @@ -195,7 +195,7 @@ struct nvme_ctrl { /*!generate-accessors*/ char *serial; //!accessors:readonly char *sqsize; //!accessors:readonly char *transport; //!accessors:readonly - char *subsysnqn; //!accessors:none + char *subsysnqn; //!accessors:readonly char *traddr; //!accessors:readonly char *trsvcid; //!accessors:readonly char *dhchap_host_key; diff --git a/libnvme/src/nvme/tree.c b/libnvme/src/nvme/tree.c index 183784c20d..d2f6728dff 100644 --- a/libnvme/src/nvme/tree.c +++ b/libnvme/src/nvme/tree.c @@ -890,11 +890,6 @@ nvme_subsystem_t nvme_ctrl_get_subsystem(nvme_ctrl_t c) } -const char *nvme_ctrl_get_subsysnqn(nvme_ctrl_t c) -{ - return c->s ? c->s->subsysnqn : c->subsysnqn; -} - char *nvme_ctrl_get_src_addr(nvme_ctrl_t c, char *src_addr, size_t src_addr_len) { size_t l; diff --git a/libnvme/src/nvme/tree.h b/libnvme/src/nvme/tree.h index 195f8301ef..07b75677cd 100644 --- a/libnvme/src/nvme/tree.h +++ b/libnvme/src/nvme/tree.h @@ -734,14 +734,6 @@ char *nvme_ctrl_get_src_addr(nvme_ctrl_t c, char *src_addr, size_t src_addr_len) */ const char *nvme_ctrl_get_state(nvme_ctrl_t c); -/** - * nvme_ctrl_get_subsysnqn() - Subsystem NQN of a controller - * @c: Controller instance - * - * Return: Subsystem NQN of @c - */ -const char *nvme_ctrl_get_subsysnqn(nvme_ctrl_t c); - /** * nvme_ctrl_get_subsystem() - Parent subsystem of a controller * @c: Controller instance