From 772bc6c028e4671cf4da851ef74394c4ab3ffb0c Mon Sep 17 00:00:00 2001 From: Martin Belanger Date: Thu, 12 Mar 2026 13:46:45 -0400 Subject: [PATCH] libnvme: commit pre-generated accessor files and simplify build The accessor functions (getters/setters for nvme_path, nvme_ns, nvme_ctrl, nvme_subsystem, nvme_host, nvme_fabric_options) were previously generated at build time by a custom_target in Meson. They are now committed to the source tree and treated as maintainer-generated source files, similar to how the Linux kernel and systemd handle infrequently-changing generated code. Changes: - Commit accessors.h, accessors.c, accessors.ld to the source tree - Remove the custom_target that ran the generator on every build; generate-accessors is no longer compiled during a normal build - Add accessors.c to the sources list and accessors.h to install_headers() alongside their sibling files in libnvme/src/meson.build - Remove accessors_dep (was only needed to forward the custom_target outputs; plain files don't require this indirection) - Enhance generate-accessors.c to emit mechanical Doxygen stubs in accessors.h, covering all three member kinds: value types, dynamic char * (with NULL/copy semantics), and fixed char arrays - Add update-accessors.sh: atomically regenerates accessors.h and accessors.c when content changes, and reports symbol additions and removals against accessors.ld without overwriting it - Add a Meson run_target and Makefile target 'update-accessors' for on-demand regeneration: make update-accessors - Keep accessors.ld manually maintained; its version section labels (e.g. LIBNVME_ACCESSORS_3_0) must be assigned by the maintainer to preserve ABI compatibility - Add .github/workflows/check-accessors.yml to fail CI when the committed accessor files drift from the generator output - Update README.md with a developer guide covering regeneration, accessors.ld maintenance, and the ABI versioning convention - Fix three stale test reference files that were missing dhchap_ctrl_key from their expected JSON output following an earlier json.c update Signed-off-by: Martin Belanger --- .github/workflows/check-accessors.yml | 48 + Makefile | 4 + README.md | 89 +- libnvme/src/libnvme.h | 1 + libnvme/src/meson.build | 6 +- libnvme/src/nvme/accessors.c | 974 ++++++++++++ libnvme/src/nvme/accessors.h | 1362 +++++++++++++++++ libnvme/src/nvme/accessors.ld | 168 ++ .../src/nvme/generate-accessors-exclude.list | 10 + ...de.txt => generate-accessors-include.list} | 0 libnvme/src/nvme/generate-accessors.c | 574 +++++-- libnvme/src/nvme/meson.build | 71 +- libnvme/src/nvme/tree.c | 277 ---- libnvme/src/nvme/tree.h | 404 ----- libnvme/src/nvme/update-accessors.sh | 113 ++ .../data/config-pcie-with-tcp-config.out | 12 +- libnvme/test/config/data/tls_key-1.out | 1 + libnvme/test/config/data/tls_key-2.out | 1 + 18 files changed, 3257 insertions(+), 858 deletions(-) create mode 100644 .github/workflows/check-accessors.yml create mode 100644 libnvme/src/nvme/accessors.c create mode 100644 libnvme/src/nvme/accessors.h create mode 100644 libnvme/src/nvme/accessors.ld create mode 100644 libnvme/src/nvme/generate-accessors-exclude.list rename libnvme/src/nvme/{structs-to-include.txt => generate-accessors-include.list} (100%) create mode 100755 libnvme/src/nvme/update-accessors.sh diff --git a/.github/workflows/check-accessors.yml b/.github/workflows/check-accessors.yml new file mode 100644 index 0000000000..9fd4ed077f --- /dev/null +++ b/.github/workflows/check-accessors.yml @@ -0,0 +1,48 @@ +--- +# SPDX-License-Identifier: GPL-2.0-or-later +# +# This file is part of nvme. +# Copyright (c) 2025 Dell Technologies Inc. or its subsidiaries. +# +# Authors: Martin Belanger +# +# Verify that the committed accessor files (accessors.h, accessors.c) are +# up to date with the generate-accessors tool and the structs in private.h. +# +# If this check fails, run the following command and commit the result: +# +# meson compile -C update-accessors + +name: Check accessors + +on: + push: + branches: [master] + pull_request: + branches: [master] + + workflow_dispatch: + +jobs: + check-accessors: + name: check generated accessor files are up to date + runs-on: ubuntu-latest + container: + image: ghcr.io/linux-nvme/debian:latest + steps: + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + - name: Mark repo as safe for git + run: git config --global --add safe.directory "$GITHUB_WORKSPACE" + - name: Configure + run: meson setup .build-ci + - name: Regenerate accessor files + run: meson compile -C .build-ci update-accessors + - name: Check for uncommitted differences + run: | + if ! git diff --exit-code libnvme/src/nvme/accessors.h \ + libnvme/src/nvme/accessors.c; then + echo "" + echo "ERROR: accessor files are out of date." + echo "Run 'meson compile -C update-accessors' and commit the result." + exit 1 + fi diff --git a/Makefile b/Makefile index 18ee7d6e63..695fa956cc 100644 --- a/Makefile +++ b/Makefile @@ -45,6 +45,10 @@ install: ${NAME} uninstall: cd ${BUILD-DIR} && meson --internal uninstall +.PHONY: update-accessors +update-accessors: ${BUILD-DIR} + meson compile -C ${BUILD-DIR} update-accessors + .PHONY: dist dist: ${NAME} meson dist -C ${BUILD-DIR} --formats gztar diff --git a/README.md b/README.md index 5640290abb..7c868c9061 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,7 @@ Note for nvme-cli the 'default' is set to nofallback. #### Installing # meson install -C .build - + ### Build with build.sh wrapper The `scripts/build.sh` is used for the CI build but can also be used for @@ -237,6 +237,93 @@ After that, you just need to implement the functions you defined in each ENTRY, then append the object file name to the meson.build "sources". +### Updating the libnvme accessor functions + +libnvme exposes a set of getter and setter functions (accessors) for its core +internal structs (`nvme_path`, `nvme_ns`, `nvme_ctrl`, `nvme_subsystem`, +`nvme_host`, `nvme_fabric_options`). These are generated from the struct +definitions in `libnvme/src/nvme/private.h` by the tool +`libnvme/src/nvme/generate-accessors.c`. + +The generated files are committed to the source tree and are **not** +regenerated during a normal build: + +``` +libnvme/src/nvme/accessors.h # public API declarations (with Doxygen stubs) +libnvme/src/nvme/accessors.c # implementations +libnvme/src/nvme/accessors.ld # linker version script (manually maintained) +``` + +#### When to regenerate + +Regeneration is needed when a struct member is added, removed, or renamed in +`private.h`, or when a struct is added to or removed from +`generate-accessors-include.list` or excluded in `generate-accessors-exclude.list`. + +#### How to regenerate + +```shell +$ make update-accessors +``` + +or equivalently: + +```shell +$ meson compile -C .build update-accessors +``` + +The script compiles the generator, runs it, and atomically updates +`accessors.h` and `accessors.c` only when their content changes. +Commit the updated files afterward: + +```shell +$ git add libnvme/src/nvme/accessors.h libnvme/src/nvme/accessors.c +$ git commit -m "libnvme: regenerate accessors following changes" +``` + +#### Maintaining accessors.ld + +`accessors.ld` is a GNU linker version script that controls which accessor +symbols are exported from `libnvme.so` and under which ABI version label they +were introduced (e.g. `LIBNVME_ACCESSORS_3_0`). + +This file is **not** updated automatically, because each symbol must be placed +in the correct version section by the maintainer. Adding a symbol to an +already-published version section would break binary compatibility for +existing users of the library. + +When `make update-accessors` detects that the symbol list has drifted from +`accessors.ld`, it prints a report like the following: + +``` +WARNING: accessors.ld needs manual attention. + + Symbols to ADD (place in a new version section, e.g. LIBNVME_ACCESSORS_X_Y): + nvme_ctrl_get_new_field + nvme_ctrl_set_new_field +``` + +New symbols must be added to a **new** version section that chains the +previous one. For example, if the current latest section is +`LIBNVME_ACCESSORS_3_0`, add a new section for the next release: + +``` +LIBNVME_ACCESSORS_3_1 { + global: + nvme_ctrl_get_new_field; + nvme_ctrl_set_new_field; +} LIBNVME_ACCESSORS_3_0; +``` + +Then commit `accessors.ld` together with the regenerated source files. + +#### CI enforcement + +A GitHub Actions workflow (`.github/workflows/check-accessors.yml`) runs on +every push and pull request. It regenerates the accessor files and fails if +the result differs from what is committed, ensuring the source tree never +drifts silently. + ## Dependency libnvme depends on the /sys/class/nvme-subsystem interface which was diff --git a/libnvme/src/libnvme.h b/libnvme/src/libnvme.h index e7ed221685..56416dcd6e 100644 --- a/libnvme/src/libnvme.h +++ b/libnvme/src/libnvme.h @@ -25,6 +25,7 @@ extern "C" { #include #include #include +#include #ifdef __cplusplus } diff --git a/libnvme/src/meson.build b/libnvme/src/meson.build index 44a848e386..86c76870d6 100644 --- a/libnvme/src/meson.build +++ b/libnvme/src/meson.build @@ -6,6 +6,7 @@ # Authors: Martin Belanger # sources = [ + 'nvme/accessors.c', 'nvme/base64.c', 'nvme/cmds.c', 'nvme/crc32.c', @@ -29,8 +30,7 @@ else sources += 'nvme/no-json.c' endif -# Generate accessors (setter/getter functions) -subdir('nvme') # declares: accessors_dep, accessors_ld_full_path +subdir('nvme') # declares: accessors_ld_full_path deps = [ config_dep, @@ -40,7 +40,6 @@ deps = [ libdbus_dep, liburing_dep, openssl_dep, - accessors_dep, ] ldfile = 'libnvme.ld' @@ -98,6 +97,7 @@ install_headers( ) install_headers( [ + 'nvme/accessors.h', 'nvme/cmds.h', 'nvme/fabrics.h', 'nvme/filters.h', diff --git a/libnvme/src/nvme/accessors.c b/libnvme/src/nvme/accessors.c new file mode 100644 index 0000000000..9521183f75 --- /dev/null +++ b/libnvme/src/nvme/accessors.c @@ -0,0 +1,974 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later + +/** + * This file is part of libnvme. + * + * Copyright (c) 2025, Dell Technologies Inc. or its subsidiaries. + * Authors: Martin Belanger + * + * ____ _ _ ____ _ + * / ___| ___ _ __ ___ _ __ __ _| |_ ___ __| | / ___|___ __| | ___ + * | | _ / _ \ '_ \ / _ \ '__/ _` | __/ _ \/ _` | | | / _ \ / _` |/ _ \ + * | |_| | __/ | | | __/ | | (_| | || __/ (_| | | |__| (_) | (_| | __/ + * \____|\___|_| |_|\___|_| \__,_|\__\___|\__,_| \____\___/ \__,_|\___| + * + * Auto-generated struct member accessors (setter/getter) + */ +#include +#include +#include "accessors.h" + +#include "private.h" + +/**************************************************************************** + * Accessors for: struct nvme_path + ****************************************************************************/ + +void nvme_path_set_name(struct nvme_path *p, const char *name) +{ + free(p->name); + p->name = name ? strdup(name) : NULL; +} + +const char *nvme_path_get_name(const struct nvme_path *p) +{ + return p->name; +} + +void nvme_path_set_sysfs_dir(struct nvme_path *p, const char *sysfs_dir) +{ + free(p->sysfs_dir); + p->sysfs_dir = sysfs_dir ? strdup(sysfs_dir) : NULL; +} + +const char *nvme_path_get_sysfs_dir(const struct nvme_path *p) +{ + return p->sysfs_dir; +} + +void nvme_path_set_ana_state(struct nvme_path *p, const char *ana_state) +{ + free(p->ana_state); + p->ana_state = ana_state ? strdup(ana_state) : NULL; +} + +const char *nvme_path_get_ana_state(const struct nvme_path *p) +{ + return p->ana_state; +} + +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; +} + +const char *nvme_path_get_numa_nodes(const struct nvme_path *p) +{ + return p->numa_nodes; +} + +void nvme_path_set_grpid(struct nvme_path *p, int grpid) +{ + p->grpid = grpid; +} + +int nvme_path_get_grpid(const struct nvme_path *p) +{ + return p->grpid; +} + +/**************************************************************************** + * Accessors for: struct nvme_ns + ****************************************************************************/ + +void nvme_ns_set_nsid(struct nvme_ns *p, __u32 nsid) +{ + p->nsid = nsid; +} + +__u32 nvme_ns_get_nsid(const struct nvme_ns *p) +{ + return p->nsid; +} + +void nvme_ns_set_name(struct nvme_ns *p, const char *name) +{ + free(p->name); + p->name = name ? strdup(name) : NULL; +} + +const char *nvme_ns_get_name(const struct nvme_ns *p) +{ + return p->name; +} + +void nvme_ns_set_sysfs_dir(struct nvme_ns *p, const char *sysfs_dir) +{ + free(p->sysfs_dir); + p->sysfs_dir = sysfs_dir ? strdup(sysfs_dir) : NULL; +} + +const char *nvme_ns_get_sysfs_dir(const struct nvme_ns *p) +{ + return p->sysfs_dir; +} + +void nvme_ns_set_lba_shift(struct nvme_ns *p, int lba_shift) +{ + p->lba_shift = lba_shift; +} + +int nvme_ns_get_lba_shift(const struct nvme_ns *p) +{ + return p->lba_shift; +} + +void nvme_ns_set_lba_size(struct nvme_ns *p, int lba_size) +{ + p->lba_size = lba_size; +} + +int nvme_ns_get_lba_size(const struct nvme_ns *p) +{ + return p->lba_size; +} + +void nvme_ns_set_meta_size(struct nvme_ns *p, int meta_size) +{ + p->meta_size = meta_size; +} + +int nvme_ns_get_meta_size(const struct nvme_ns *p) +{ + return p->meta_size; +} + +void nvme_ns_set_lba_count(struct nvme_ns *p, uint64_t lba_count) +{ + p->lba_count = lba_count; +} + +uint64_t nvme_ns_get_lba_count(const struct nvme_ns *p) +{ + return p->lba_count; +} + +void nvme_ns_set_lba_util(struct nvme_ns *p, uint64_t lba_util) +{ + p->lba_util = lba_util; +} + +uint64_t nvme_ns_get_lba_util(const struct nvme_ns *p) +{ + return p->lba_util; +} + +/**************************************************************************** + * 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; +} + +void nvme_ctrl_set_dhchap_key(struct nvme_ctrl *p, const char *dhchap_key) +{ + free(p->dhchap_key); + p->dhchap_key = dhchap_key ? strdup(dhchap_key) : NULL; +} + +const char *nvme_ctrl_get_dhchap_key(const struct nvme_ctrl *p) +{ + return p->dhchap_key; +} + +void nvme_ctrl_set_dhchap_ctrl_key( + struct nvme_ctrl *p, + const char *dhchap_ctrl_key) +{ + free(p->dhchap_ctrl_key); + p->dhchap_ctrl_key = dhchap_ctrl_key ? strdup(dhchap_ctrl_key) : NULL; +} + +const char *nvme_ctrl_get_dhchap_ctrl_key(const struct nvme_ctrl *p) +{ + return p->dhchap_ctrl_key; +} + +void nvme_ctrl_set_keyring(struct nvme_ctrl *p, const char *keyring) +{ + free(p->keyring); + p->keyring = keyring ? strdup(keyring) : NULL; +} + +const char *nvme_ctrl_get_keyring(const struct nvme_ctrl *p) +{ + return p->keyring; +} + +void nvme_ctrl_set_tls_key_identity( + struct nvme_ctrl *p, + const char *tls_key_identity) +{ + free(p->tls_key_identity); + p->tls_key_identity = + tls_key_identity ? strdup(tls_key_identity) : NULL; +} + +const char *nvme_ctrl_get_tls_key_identity(const struct nvme_ctrl *p) +{ + return p->tls_key_identity; +} + +void nvme_ctrl_set_tls_key(struct nvme_ctrl *p, const char *tls_key) +{ + free(p->tls_key); + p->tls_key = tls_key ? strdup(tls_key) : NULL; +} + +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; +} + +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; +} + +void nvme_ctrl_set_discovery_ctrl(struct nvme_ctrl *p, bool discovery_ctrl) +{ + p->discovery_ctrl = discovery_ctrl; +} + +bool nvme_ctrl_get_discovery_ctrl(const struct nvme_ctrl *p) +{ + return p->discovery_ctrl; +} + +void nvme_ctrl_set_unique_discovery_ctrl( + struct nvme_ctrl *p, + bool unique_discovery_ctrl) +{ + p->unique_discovery_ctrl = unique_discovery_ctrl; +} + +bool nvme_ctrl_get_unique_discovery_ctrl(const struct nvme_ctrl *p) +{ + return p->unique_discovery_ctrl; +} + +void nvme_ctrl_set_discovered(struct nvme_ctrl *p, bool discovered) +{ + p->discovered = discovered; +} + +bool nvme_ctrl_get_discovered(const struct nvme_ctrl *p) +{ + return p->discovered; +} + +void nvme_ctrl_set_persistent(struct nvme_ctrl *p, bool persistent) +{ + p->persistent = persistent; +} + +bool nvme_ctrl_get_persistent(const struct nvme_ctrl *p) +{ + return p->persistent; +} + +/**************************************************************************** + * 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; +} + +void nvme_subsystem_set_application( + struct nvme_subsystem *p, + const char *application) +{ + free(p->application); + p->application = application ? strdup(application) : NULL; +} + +const char *nvme_subsystem_get_application(const struct nvme_subsystem *p) +{ + return p->application; +} + +void nvme_subsystem_set_iopolicy(struct nvme_subsystem *p, const char *iopolicy) +{ + free(p->iopolicy); + p->iopolicy = iopolicy ? strdup(iopolicy) : NULL; +} + +const char *nvme_subsystem_get_iopolicy(const struct nvme_subsystem *p) +{ + return p->iopolicy; +} + +/**************************************************************************** + * 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; +} + +void nvme_host_set_dhchap_key(struct nvme_host *p, const char *dhchap_key) +{ + free(p->dhchap_key); + p->dhchap_key = dhchap_key ? strdup(dhchap_key) : NULL; +} + +const char *nvme_host_get_dhchap_key(const struct nvme_host *p) +{ + return p->dhchap_key; +} + +void nvme_host_set_hostsymname(struct nvme_host *p, const char *hostsymname) +{ + free(p->hostsymname); + p->hostsymname = hostsymname ? strdup(hostsymname) : NULL; +} + +const char *nvme_host_get_hostsymname(const struct nvme_host *p) +{ + return p->hostsymname; +} + +void nvme_host_set_pdc_enabled_valid( + struct nvme_host *p, + bool pdc_enabled_valid) +{ + p->pdc_enabled_valid = pdc_enabled_valid; +} + +bool nvme_host_get_pdc_enabled_valid(const struct nvme_host *p) +{ + return p->pdc_enabled_valid; +} + +/**************************************************************************** + * Accessors for: struct nvme_fabric_options + ****************************************************************************/ + +void nvme_fabric_options_set_cntlid(struct nvme_fabric_options *p, bool cntlid) +{ + p->cntlid = cntlid; +} + +bool nvme_fabric_options_get_cntlid(const struct nvme_fabric_options *p) +{ + return p->cntlid; +} + +void nvme_fabric_options_set_concat(struct nvme_fabric_options *p, bool concat) +{ + p->concat = concat; +} + +bool nvme_fabric_options_get_concat(const struct nvme_fabric_options *p) +{ + return p->concat; +} + +void nvme_fabric_options_set_ctrl_loss_tmo( + struct nvme_fabric_options *p, + bool ctrl_loss_tmo) +{ + p->ctrl_loss_tmo = ctrl_loss_tmo; +} + +bool nvme_fabric_options_get_ctrl_loss_tmo(const struct nvme_fabric_options *p) +{ + return p->ctrl_loss_tmo; +} + +void nvme_fabric_options_set_data_digest( + struct nvme_fabric_options *p, + bool data_digest) +{ + p->data_digest = data_digest; +} + +bool nvme_fabric_options_get_data_digest(const struct nvme_fabric_options *p) +{ + return p->data_digest; +} + +void nvme_fabric_options_set_dhchap_ctrl_secret( + struct nvme_fabric_options *p, + bool dhchap_ctrl_secret) +{ + p->dhchap_ctrl_secret = dhchap_ctrl_secret; +} + +bool nvme_fabric_options_get_dhchap_ctrl_secret( + const struct nvme_fabric_options *p) +{ + return p->dhchap_ctrl_secret; +} + +void nvme_fabric_options_set_dhchap_secret( + struct nvme_fabric_options *p, + bool dhchap_secret) +{ + p->dhchap_secret = dhchap_secret; +} + +bool nvme_fabric_options_get_dhchap_secret(const struct nvme_fabric_options *p) +{ + return p->dhchap_secret; +} + +void nvme_fabric_options_set_disable_sqflow( + struct nvme_fabric_options *p, + bool disable_sqflow) +{ + p->disable_sqflow = disable_sqflow; +} + +bool nvme_fabric_options_get_disable_sqflow(const struct nvme_fabric_options *p) +{ + return p->disable_sqflow; +} + +void nvme_fabric_options_set_discovery( + struct nvme_fabric_options *p, + bool discovery) +{ + p->discovery = discovery; +} + +bool nvme_fabric_options_get_discovery(const struct nvme_fabric_options *p) +{ + return p->discovery; +} + +void nvme_fabric_options_set_duplicate_connect( + struct nvme_fabric_options *p, + bool duplicate_connect) +{ + p->duplicate_connect = duplicate_connect; +} + +bool nvme_fabric_options_get_duplicate_connect( + const struct nvme_fabric_options *p) +{ + return p->duplicate_connect; +} + +void nvme_fabric_options_set_fast_io_fail_tmo( + struct nvme_fabric_options *p, + bool fast_io_fail_tmo) +{ + p->fast_io_fail_tmo = fast_io_fail_tmo; +} + +bool nvme_fabric_options_get_fast_io_fail_tmo( + const struct nvme_fabric_options *p) +{ + return p->fast_io_fail_tmo; +} + +void nvme_fabric_options_set_hdr_digest( + struct nvme_fabric_options *p, + bool hdr_digest) +{ + p->hdr_digest = hdr_digest; +} + +bool nvme_fabric_options_get_hdr_digest(const struct nvme_fabric_options *p) +{ + return p->hdr_digest; +} + +void nvme_fabric_options_set_host_iface( + struct nvme_fabric_options *p, + bool host_iface) +{ + p->host_iface = host_iface; +} + +bool nvme_fabric_options_get_host_iface(const struct nvme_fabric_options *p) +{ + return p->host_iface; +} + +void nvme_fabric_options_set_host_traddr( + struct nvme_fabric_options *p, + bool host_traddr) +{ + p->host_traddr = host_traddr; +} + +bool nvme_fabric_options_get_host_traddr(const struct nvme_fabric_options *p) +{ + return p->host_traddr; +} + +void nvme_fabric_options_set_hostid(struct nvme_fabric_options *p, bool hostid) +{ + p->hostid = hostid; +} + +bool nvme_fabric_options_get_hostid(const struct nvme_fabric_options *p) +{ + return p->hostid; +} + +void nvme_fabric_options_set_hostnqn( + struct nvme_fabric_options *p, + bool hostnqn) +{ + p->hostnqn = hostnqn; +} + +bool nvme_fabric_options_get_hostnqn(const struct nvme_fabric_options *p) +{ + return p->hostnqn; +} + +void nvme_fabric_options_set_instance( + struct nvme_fabric_options *p, + bool instance) +{ + p->instance = instance; +} + +bool nvme_fabric_options_get_instance(const struct nvme_fabric_options *p) +{ + return p->instance; +} + +void nvme_fabric_options_set_keep_alive_tmo( + struct nvme_fabric_options *p, + bool keep_alive_tmo) +{ + p->keep_alive_tmo = keep_alive_tmo; +} + +bool nvme_fabric_options_get_keep_alive_tmo(const struct nvme_fabric_options *p) +{ + return p->keep_alive_tmo; +} + +void nvme_fabric_options_set_keyring( + struct nvme_fabric_options *p, + bool keyring) +{ + p->keyring = keyring; +} + +bool nvme_fabric_options_get_keyring(const struct nvme_fabric_options *p) +{ + return p->keyring; +} + +void nvme_fabric_options_set_nqn(struct nvme_fabric_options *p, bool nqn) +{ + p->nqn = nqn; +} + +bool nvme_fabric_options_get_nqn(const struct nvme_fabric_options *p) +{ + return p->nqn; +} + +void nvme_fabric_options_set_nr_io_queues( + struct nvme_fabric_options *p, + bool nr_io_queues) +{ + p->nr_io_queues = nr_io_queues; +} + +bool nvme_fabric_options_get_nr_io_queues(const struct nvme_fabric_options *p) +{ + return p->nr_io_queues; +} + +void nvme_fabric_options_set_nr_poll_queues( + struct nvme_fabric_options *p, + bool nr_poll_queues) +{ + p->nr_poll_queues = nr_poll_queues; +} + +bool nvme_fabric_options_get_nr_poll_queues(const struct nvme_fabric_options *p) +{ + return p->nr_poll_queues; +} + +void nvme_fabric_options_set_nr_write_queues( + struct nvme_fabric_options *p, + bool nr_write_queues) +{ + p->nr_write_queues = nr_write_queues; +} + +bool nvme_fabric_options_get_nr_write_queues( + const struct nvme_fabric_options *p) +{ + return p->nr_write_queues; +} + +void nvme_fabric_options_set_queue_size( + struct nvme_fabric_options *p, + bool queue_size) +{ + p->queue_size = queue_size; +} + +bool nvme_fabric_options_get_queue_size(const struct nvme_fabric_options *p) +{ + return p->queue_size; +} + +void nvme_fabric_options_set_reconnect_delay( + struct nvme_fabric_options *p, + bool reconnect_delay) +{ + p->reconnect_delay = reconnect_delay; +} + +bool nvme_fabric_options_get_reconnect_delay( + const struct nvme_fabric_options *p) +{ + return p->reconnect_delay; +} + +void nvme_fabric_options_set_tls(struct nvme_fabric_options *p, bool tls) +{ + p->tls = tls; +} + +bool nvme_fabric_options_get_tls(const struct nvme_fabric_options *p) +{ + return p->tls; +} + +void nvme_fabric_options_set_tls_key( + struct nvme_fabric_options *p, + bool tls_key) +{ + p->tls_key = tls_key; +} + +bool nvme_fabric_options_get_tls_key(const struct nvme_fabric_options *p) +{ + return p->tls_key; +} + +void nvme_fabric_options_set_tos(struct nvme_fabric_options *p, bool tos) +{ + p->tos = tos; +} + +bool nvme_fabric_options_get_tos(const struct nvme_fabric_options *p) +{ + return p->tos; +} + +void nvme_fabric_options_set_traddr(struct nvme_fabric_options *p, bool traddr) +{ + p->traddr = traddr; +} + +bool nvme_fabric_options_get_traddr(const struct nvme_fabric_options *p) +{ + return p->traddr; +} + +void nvme_fabric_options_set_transport( + struct nvme_fabric_options *p, + bool transport) +{ + p->transport = transport; +} + +bool nvme_fabric_options_get_transport(const struct nvme_fabric_options *p) +{ + return p->transport; +} + +void nvme_fabric_options_set_trsvcid( + struct nvme_fabric_options *p, + bool trsvcid) +{ + p->trsvcid = trsvcid; +} + +bool nvme_fabric_options_get_trsvcid(const struct nvme_fabric_options *p) +{ + return p->trsvcid; +} + diff --git a/libnvme/src/nvme/accessors.h b/libnvme/src/nvme/accessors.h new file mode 100644 index 0000000000..716f4141ca --- /dev/null +++ b/libnvme/src/nvme/accessors.h @@ -0,0 +1,1362 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ + +/** + * This file is part of libnvme. + * + * Copyright (c) 2025, Dell Technologies Inc. or its subsidiaries. + * Authors: Martin Belanger + * + * ____ _ _ ____ _ + * / ___| ___ _ __ ___ _ __ __ _| |_ ___ __| | / ___|___ __| | ___ + * | | _ / _ \ '_ \ / _ \ '__/ _` | __/ _ \/ _` | | | / _ \ / _` |/ _ \ + * | |_| | __/ | | | __/ | | (_| | || __/ (_| | | |__| (_) | (_| | __/ + * \____|\___|_| |_|\___|_| \__,_|\__\___|\__,_| \____\___/ \__,_|\___| + * + * Auto-generated struct member accessors (setter/getter) + */ +#ifndef _ACCESSORS_H_ +#define _ACCESSORS_H_ + +#include +#include +#include +#include +#include /* __u32, __u64, etc. */ + +/* Forward declarations. These are internal (opaque) structs. */ +struct nvme_path; +struct nvme_ns; +struct nvme_ctrl; +struct nvme_subsystem; +struct nvme_host; +struct nvme_fabric_options; + +/**************************************************************************** + * Accessors for: struct nvme_path + ****************************************************************************/ + +/** + * nvme_path_set_name() - Set name. + * @p: The &struct nvme_path instance to update. + * @name: New string; a copy is stored. Pass NULL to clear. + */ +void nvme_path_set_name(struct nvme_path *p, const char *name); + +/** + * nvme_path_get_name() - Get name. + * @p: The &struct nvme_path instance to query. + * + * Return: The value of the name field, or NULL if not set. + */ +const char *nvme_path_get_name(const struct nvme_path *p); + +/** + * nvme_path_set_sysfs_dir() - Set sysfs_dir. + * @p: The &struct nvme_path instance to update. + * @sysfs_dir: New string; a copy is stored. Pass NULL to clear. + */ +void nvme_path_set_sysfs_dir(struct nvme_path *p, const char *sysfs_dir); + +/** + * nvme_path_get_sysfs_dir() - Get sysfs_dir. + * @p: The &struct nvme_path instance to query. + * + * Return: The value of the sysfs_dir field, or NULL if not set. + */ +const char *nvme_path_get_sysfs_dir(const struct nvme_path *p); + +/** + * nvme_path_set_ana_state() - Set ana_state. + * @p: The &struct nvme_path instance to update. + * @ana_state: New string; a copy is stored. Pass NULL to clear. + */ +void nvme_path_set_ana_state(struct nvme_path *p, const char *ana_state); + +/** + * nvme_path_get_ana_state() - Get ana_state. + * @p: The &struct nvme_path instance to query. + * + * Return: The value of the ana_state field, or NULL if not set. + */ +const char *nvme_path_get_ana_state(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. + * @grpid: Value to assign to the grpid field. + */ +void nvme_path_set_grpid(struct nvme_path *p, int grpid); + +/** + * nvme_path_get_grpid() - Get grpid. + * @p: The &struct nvme_path instance to query. + * + * Return: The value of the grpid field. + */ +int nvme_path_get_grpid(const struct nvme_path *p); + +/**************************************************************************** + * Accessors for: struct nvme_ns + ****************************************************************************/ + +/** + * nvme_ns_set_nsid() - Set nsid. + * @p: The &struct nvme_ns instance to update. + * @nsid: Value to assign to the nsid field. + */ +void nvme_ns_set_nsid(struct nvme_ns *p, __u32 nsid); + +/** + * nvme_ns_get_nsid() - Get nsid. + * @p: The &struct nvme_ns instance to query. + * + * Return: The value of the nsid field. + */ +__u32 nvme_ns_get_nsid(const struct nvme_ns *p); + +/** + * nvme_ns_set_name() - Set name. + * @p: The &struct nvme_ns instance to update. + * @name: New string; a copy is stored. Pass NULL to clear. + */ +void nvme_ns_set_name(struct nvme_ns *p, const char *name); + +/** + * nvme_ns_get_name() - Get name. + * @p: The &struct nvme_ns instance to query. + * + * Return: The value of the name field, or NULL if not set. + */ +const char *nvme_ns_get_name(const struct nvme_ns *p); + +/** + * nvme_ns_set_sysfs_dir() - Set sysfs_dir. + * @p: The &struct nvme_ns instance to update. + * @sysfs_dir: New string; a copy is stored. Pass NULL to clear. + */ +void nvme_ns_set_sysfs_dir(struct nvme_ns *p, const char *sysfs_dir); + +/** + * nvme_ns_get_sysfs_dir() - Get sysfs_dir. + * @p: The &struct nvme_ns instance to query. + * + * Return: The value of the sysfs_dir field, or NULL if not set. + */ +const char *nvme_ns_get_sysfs_dir(const struct nvme_ns *p); + +/** + * nvme_ns_set_lba_shift() - Set lba_shift. + * @p: The &struct nvme_ns instance to update. + * @lba_shift: Value to assign to the lba_shift field. + */ +void nvme_ns_set_lba_shift(struct nvme_ns *p, int lba_shift); + +/** + * nvme_ns_get_lba_shift() - Get lba_shift. + * @p: The &struct nvme_ns instance to query. + * + * Return: The value of the lba_shift field. + */ +int nvme_ns_get_lba_shift(const struct nvme_ns *p); + +/** + * nvme_ns_set_lba_size() - Set lba_size. + * @p: The &struct nvme_ns instance to update. + * @lba_size: Value to assign to the lba_size field. + */ +void nvme_ns_set_lba_size(struct nvme_ns *p, int lba_size); + +/** + * nvme_ns_get_lba_size() - Get lba_size. + * @p: The &struct nvme_ns instance to query. + * + * Return: The value of the lba_size field. + */ +int nvme_ns_get_lba_size(const struct nvme_ns *p); + +/** + * nvme_ns_set_meta_size() - Set meta_size. + * @p: The &struct nvme_ns instance to update. + * @meta_size: Value to assign to the meta_size field. + */ +void nvme_ns_set_meta_size(struct nvme_ns *p, int meta_size); + +/** + * nvme_ns_get_meta_size() - Get meta_size. + * @p: The &struct nvme_ns instance to query. + * + * Return: The value of the meta_size field. + */ +int nvme_ns_get_meta_size(const struct nvme_ns *p); + +/** + * nvme_ns_set_lba_count() - Set lba_count. + * @p: The &struct nvme_ns instance to update. + * @lba_count: Value to assign to the lba_count field. + */ +void nvme_ns_set_lba_count(struct nvme_ns *p, uint64_t lba_count); + +/** + * nvme_ns_get_lba_count() - Get lba_count. + * @p: The &struct nvme_ns instance to query. + * + * Return: The value of the lba_count field. + */ +uint64_t nvme_ns_get_lba_count(const struct nvme_ns *p); + +/** + * nvme_ns_set_lba_util() - Set lba_util. + * @p: The &struct nvme_ns instance to update. + * @lba_util: Value to assign to the lba_util field. + */ +void nvme_ns_set_lba_util(struct nvme_ns *p, uint64_t lba_util); + +/** + * nvme_ns_get_lba_util() - Get lba_util. + * @p: The &struct nvme_ns instance to query. + * + * Return: The value of the lba_util field. + */ +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. + * + * Return: The value of the name field, or NULL if not set. + */ +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. + * + * Return: The value of the sysfs_dir field, or NULL if not set. + */ +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. + * + * Return: The value of the firmware field, or NULL if not set. + */ +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. + * + * Return: The value of the model field, or NULL if not set. + */ +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. + * + * Return: The value of the numa_node field, or NULL if not set. + */ +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. + * + * Return: The value of the queue_count field, or NULL if not set. + */ +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. + * + * Return: The value of the serial field, or NULL if not set. + */ +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. + * + * Return: The value of the sqsize field, or NULL if not set. + */ +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. + * + * Return: The value of the transport field, or NULL if not set. + */ +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. + * + * Return: The value of the traddr field, or NULL if not set. + */ +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. + * + * Return: The value of the trsvcid field, or NULL if not set. + */ +const char *nvme_ctrl_get_trsvcid(const struct nvme_ctrl *p); + +/** + * nvme_ctrl_set_dhchap_key() - Set dhchap_key. + * @p: The &struct nvme_ctrl instance to update. + * @dhchap_key: New string; a copy is stored. Pass NULL to clear. + */ +void nvme_ctrl_set_dhchap_key(struct nvme_ctrl *p, const char *dhchap_key); + +/** + * nvme_ctrl_get_dhchap_key() - Get dhchap_key. + * @p: The &struct nvme_ctrl instance to query. + * + * Return: The value of the dhchap_key field, or NULL if not set. + */ +const char *nvme_ctrl_get_dhchap_key(const struct nvme_ctrl *p); + +/** + * nvme_ctrl_set_dhchap_ctrl_key() - Set dhchap_ctrl_key. + * @p: The &struct nvme_ctrl instance to update. + * @dhchap_ctrl_key: New string; a copy is stored. Pass NULL to clear. + */ +void nvme_ctrl_set_dhchap_ctrl_key( + struct nvme_ctrl *p, + const char *dhchap_ctrl_key); + +/** + * nvme_ctrl_get_dhchap_ctrl_key() - Get dhchap_ctrl_key. + * @p: The &struct nvme_ctrl instance to query. + * + * Return: The value of the dhchap_ctrl_key field, or NULL if not set. + */ +const char *nvme_ctrl_get_dhchap_ctrl_key(const struct nvme_ctrl *p); + +/** + * nvme_ctrl_set_keyring() - Set keyring. + * @p: The &struct nvme_ctrl instance to update. + * @keyring: New string; a copy is stored. Pass NULL to clear. + */ +void nvme_ctrl_set_keyring(struct nvme_ctrl *p, const char *keyring); + +/** + * nvme_ctrl_get_keyring() - Get keyring. + * @p: The &struct nvme_ctrl instance to query. + * + * Return: The value of the keyring field, or NULL if not set. + */ +const char *nvme_ctrl_get_keyring(const struct nvme_ctrl *p); + +/** + * nvme_ctrl_set_tls_key_identity() - Set tls_key_identity. + * @p: The &struct nvme_ctrl instance to update. + * @tls_key_identity: New string; a copy is stored. Pass NULL to clear. + */ +void nvme_ctrl_set_tls_key_identity( + struct nvme_ctrl *p, + const char *tls_key_identity); + +/** + * nvme_ctrl_get_tls_key_identity() - Get tls_key_identity. + * @p: The &struct nvme_ctrl instance to query. + * + * Return: The value of the tls_key_identity field, or NULL if not set. + */ +const char *nvme_ctrl_get_tls_key_identity(const struct nvme_ctrl *p); + +/** + * nvme_ctrl_set_tls_key() - Set tls_key. + * @p: The &struct nvme_ctrl instance to update. + * @tls_key: New string; a copy is stored. Pass NULL to clear. + */ +void nvme_ctrl_set_tls_key(struct nvme_ctrl *p, const char *tls_key); + +/** + * nvme_ctrl_get_tls_key() - Get tls_key. + * @p: The &struct nvme_ctrl instance to query. + * + * Return: The value of the tls_key field, or NULL if not set. + */ +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. + * + * Return: The value of the cntrltype field, or NULL if not set. + */ +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. + * + * Return: The value of the cntlid field, or NULL if not set. + */ +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. + * + * Return: The value of the dctype field, or NULL if not set. + */ +const char *nvme_ctrl_get_dctype(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. + * + * Return: The value of the host_traddr field, or NULL if not set. + */ +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. + * + * Return: The value of the host_iface field, or NULL if not set. + */ +const char *nvme_ctrl_get_host_iface(const struct nvme_ctrl *p); + +/** + * nvme_ctrl_set_discovery_ctrl() - Set discovery_ctrl. + * @p: The &struct nvme_ctrl instance to update. + * @discovery_ctrl: Value to assign to the discovery_ctrl field. + */ +void nvme_ctrl_set_discovery_ctrl(struct nvme_ctrl *p, bool discovery_ctrl); + +/** + * nvme_ctrl_get_discovery_ctrl() - Get discovery_ctrl. + * @p: The &struct nvme_ctrl instance to query. + * + * Return: The value of the discovery_ctrl field. + */ +bool nvme_ctrl_get_discovery_ctrl(const struct nvme_ctrl *p); + +/** + * nvme_ctrl_set_unique_discovery_ctrl() - Set unique_discovery_ctrl. + * @p: The &struct nvme_ctrl instance to update. + * @unique_discovery_ctrl: Value to assign to the unique_discovery_ctrl field. + */ +void nvme_ctrl_set_unique_discovery_ctrl( + struct nvme_ctrl *p, + bool unique_discovery_ctrl); + +/** + * nvme_ctrl_get_unique_discovery_ctrl() - Get unique_discovery_ctrl. + * @p: The &struct nvme_ctrl instance to query. + * + * Return: The value of the unique_discovery_ctrl field. + */ +bool nvme_ctrl_get_unique_discovery_ctrl(const struct nvme_ctrl *p); + +/** + * nvme_ctrl_set_discovered() - Set discovered. + * @p: The &struct nvme_ctrl instance to update. + * @discovered: Value to assign to the discovered field. + */ +void nvme_ctrl_set_discovered(struct nvme_ctrl *p, bool discovered); + +/** + * nvme_ctrl_get_discovered() - Get discovered. + * @p: The &struct nvme_ctrl instance to query. + * + * Return: The value of the discovered field. + */ +bool nvme_ctrl_get_discovered(const struct nvme_ctrl *p); + +/** + * nvme_ctrl_set_persistent() - Set persistent. + * @p: The &struct nvme_ctrl instance to update. + * @persistent: Value to assign to the persistent field. + */ +void nvme_ctrl_set_persistent(struct nvme_ctrl *p, bool persistent); + +/** + * nvme_ctrl_get_persistent() - Get persistent. + * @p: The &struct nvme_ctrl instance to query. + * + * Return: The value of the persistent field. + */ +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. + * + * Return: The value of the name field, or NULL if not set. + */ +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. + * + * Return: The value of the sysfs_dir field, or NULL if not set. + */ +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. + * + * Return: The value of the subsysnqn field, or NULL if not set. + */ +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. + * + * Return: The value of the model field, or NULL if not set. + */ +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. + * + * Return: The value of the serial field, or NULL if not set. + */ +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. + * + * Return: The value of the firmware field, or NULL if not set. + */ +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. + * + * Return: The value of the subsystype field, or NULL if not set. + */ +const char *nvme_subsystem_get_subsystype(const struct nvme_subsystem *p); + +/** + * nvme_subsystem_set_application() - Set application. + * @p: The &struct nvme_subsystem instance to update. + * @application: New string; a copy is stored. Pass NULL to clear. + */ +void nvme_subsystem_set_application( + struct nvme_subsystem *p, + const char *application); + +/** + * nvme_subsystem_get_application() - Get application. + * @p: The &struct nvme_subsystem instance to query. + * + * Return: The value of the application field, or NULL if not set. + */ +const char *nvme_subsystem_get_application(const struct nvme_subsystem *p); + +/** + * nvme_subsystem_set_iopolicy() - Set iopolicy. + * @p: The &struct nvme_subsystem instance to update. + * @iopolicy: New string; a copy is stored. Pass NULL to clear. + */ +void nvme_subsystem_set_iopolicy( + struct nvme_subsystem *p, + const char *iopolicy); + +/** + * nvme_subsystem_get_iopolicy() - Get iopolicy. + * @p: The &struct nvme_subsystem instance to query. + * + * Return: The value of the iopolicy field, or NULL if not set. + */ +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. + * + * Return: The value of the hostnqn field, or NULL if not set. + */ +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. + * + * Return: The value of the hostid field, or NULL if not set. + */ +const char *nvme_host_get_hostid(const struct nvme_host *p); + +/** + * nvme_host_set_dhchap_key() - Set dhchap_key. + * @p: The &struct nvme_host instance to update. + * @dhchap_key: New string; a copy is stored. Pass NULL to clear. + */ +void nvme_host_set_dhchap_key(struct nvme_host *p, const char *dhchap_key); + +/** + * nvme_host_get_dhchap_key() - Get dhchap_key. + * @p: The &struct nvme_host instance to query. + * + * Return: The value of the dhchap_key field, or NULL if not set. + */ +const char *nvme_host_get_dhchap_key(const struct nvme_host *p); + +/** + * nvme_host_set_hostsymname() - Set hostsymname. + * @p: The &struct nvme_host instance to update. + * @hostsymname: New string; a copy is stored. Pass NULL to clear. + */ +void nvme_host_set_hostsymname(struct nvme_host *p, const char *hostsymname); + +/** + * nvme_host_get_hostsymname() - Get hostsymname. + * @p: The &struct nvme_host instance to query. + * + * Return: The value of the hostsymname field, or NULL if not set. + */ +const char *nvme_host_get_hostsymname(const struct nvme_host *p); + +/** + * nvme_host_set_pdc_enabled_valid() - Set pdc_enabled_valid. + * @p: The &struct nvme_host instance to update. + * @pdc_enabled_valid: Value to assign to the pdc_enabled_valid field. + */ +void nvme_host_set_pdc_enabled_valid( + struct nvme_host *p, + bool pdc_enabled_valid); + +/** + * nvme_host_get_pdc_enabled_valid() - Get pdc_enabled_valid. + * @p: The &struct nvme_host instance to query. + * + * Return: The value of the pdc_enabled_valid field. + */ +bool nvme_host_get_pdc_enabled_valid(const struct nvme_host *p); + +/**************************************************************************** + * Accessors for: struct nvme_fabric_options + ****************************************************************************/ + +/** + * nvme_fabric_options_set_cntlid() - Set cntlid. + * @p: The &struct nvme_fabric_options instance to update. + * @cntlid: Value to assign to the cntlid field. + */ +void nvme_fabric_options_set_cntlid(struct nvme_fabric_options *p, bool cntlid); + +/** + * nvme_fabric_options_get_cntlid() - Get cntlid. + * @p: The &struct nvme_fabric_options instance to query. + * + * Return: The value of the cntlid field. + */ +bool nvme_fabric_options_get_cntlid(const struct nvme_fabric_options *p); + +/** + * nvme_fabric_options_set_concat() - Set concat. + * @p: The &struct nvme_fabric_options instance to update. + * @concat: Value to assign to the concat field. + */ +void nvme_fabric_options_set_concat(struct nvme_fabric_options *p, bool concat); + +/** + * nvme_fabric_options_get_concat() - Get concat. + * @p: The &struct nvme_fabric_options instance to query. + * + * Return: The value of the concat field. + */ +bool nvme_fabric_options_get_concat(const struct nvme_fabric_options *p); + +/** + * nvme_fabric_options_set_ctrl_loss_tmo() - Set ctrl_loss_tmo. + * @p: The &struct nvme_fabric_options instance to update. + * @ctrl_loss_tmo: Value to assign to the ctrl_loss_tmo field. + */ +void nvme_fabric_options_set_ctrl_loss_tmo( + struct nvme_fabric_options *p, + bool ctrl_loss_tmo); + +/** + * nvme_fabric_options_get_ctrl_loss_tmo() - Get ctrl_loss_tmo. + * @p: The &struct nvme_fabric_options instance to query. + * + * Return: The value of the ctrl_loss_tmo field. + */ +bool nvme_fabric_options_get_ctrl_loss_tmo(const struct nvme_fabric_options *p); + +/** + * nvme_fabric_options_set_data_digest() - Set data_digest. + * @p: The &struct nvme_fabric_options instance to update. + * @data_digest: Value to assign to the data_digest field. + */ +void nvme_fabric_options_set_data_digest( + struct nvme_fabric_options *p, + bool data_digest); + +/** + * nvme_fabric_options_get_data_digest() - Get data_digest. + * @p: The &struct nvme_fabric_options instance to query. + * + * Return: The value of the data_digest field. + */ +bool nvme_fabric_options_get_data_digest(const struct nvme_fabric_options *p); + +/** + * nvme_fabric_options_set_dhchap_ctrl_secret() - Set dhchap_ctrl_secret. + * @p: The &struct nvme_fabric_options instance to update. + * @dhchap_ctrl_secret: Value to assign to the dhchap_ctrl_secret field. + */ +void nvme_fabric_options_set_dhchap_ctrl_secret( + struct nvme_fabric_options *p, + bool dhchap_ctrl_secret); + +/** + * nvme_fabric_options_get_dhchap_ctrl_secret() - Get dhchap_ctrl_secret. + * @p: The &struct nvme_fabric_options instance to query. + * + * Return: The value of the dhchap_ctrl_secret field. + */ +bool nvme_fabric_options_get_dhchap_ctrl_secret( + const struct nvme_fabric_options *p); + +/** + * nvme_fabric_options_set_dhchap_secret() - Set dhchap_secret. + * @p: The &struct nvme_fabric_options instance to update. + * @dhchap_secret: Value to assign to the dhchap_secret field. + */ +void nvme_fabric_options_set_dhchap_secret( + struct nvme_fabric_options *p, + bool dhchap_secret); + +/** + * nvme_fabric_options_get_dhchap_secret() - Get dhchap_secret. + * @p: The &struct nvme_fabric_options instance to query. + * + * Return: The value of the dhchap_secret field. + */ +bool nvme_fabric_options_get_dhchap_secret(const struct nvme_fabric_options *p); + +/** + * nvme_fabric_options_set_disable_sqflow() - Set disable_sqflow. + * @p: The &struct nvme_fabric_options instance to update. + * @disable_sqflow: Value to assign to the disable_sqflow field. + */ +void nvme_fabric_options_set_disable_sqflow( + struct nvme_fabric_options *p, + bool disable_sqflow); + +/** + * nvme_fabric_options_get_disable_sqflow() - Get disable_sqflow. + * @p: The &struct nvme_fabric_options instance to query. + * + * Return: The value of the disable_sqflow field. + */ +bool nvme_fabric_options_get_disable_sqflow( + const struct nvme_fabric_options *p); + +/** + * nvme_fabric_options_set_discovery() - Set discovery. + * @p: The &struct nvme_fabric_options instance to update. + * @discovery: Value to assign to the discovery field. + */ +void nvme_fabric_options_set_discovery( + struct nvme_fabric_options *p, + bool discovery); + +/** + * nvme_fabric_options_get_discovery() - Get discovery. + * @p: The &struct nvme_fabric_options instance to query. + * + * Return: The value of the discovery field. + */ +bool nvme_fabric_options_get_discovery(const struct nvme_fabric_options *p); + +/** + * nvme_fabric_options_set_duplicate_connect() - Set duplicate_connect. + * @p: The &struct nvme_fabric_options instance to update. + * @duplicate_connect: Value to assign to the duplicate_connect field. + */ +void nvme_fabric_options_set_duplicate_connect( + struct nvme_fabric_options *p, + bool duplicate_connect); + +/** + * nvme_fabric_options_get_duplicate_connect() - Get duplicate_connect. + * @p: The &struct nvme_fabric_options instance to query. + * + * Return: The value of the duplicate_connect field. + */ +bool nvme_fabric_options_get_duplicate_connect( + const struct nvme_fabric_options *p); + +/** + * nvme_fabric_options_set_fast_io_fail_tmo() - Set fast_io_fail_tmo. + * @p: The &struct nvme_fabric_options instance to update. + * @fast_io_fail_tmo: Value to assign to the fast_io_fail_tmo field. + */ +void nvme_fabric_options_set_fast_io_fail_tmo( + struct nvme_fabric_options *p, + bool fast_io_fail_tmo); + +/** + * nvme_fabric_options_get_fast_io_fail_tmo() - Get fast_io_fail_tmo. + * @p: The &struct nvme_fabric_options instance to query. + * + * Return: The value of the fast_io_fail_tmo field. + */ +bool nvme_fabric_options_get_fast_io_fail_tmo( + const struct nvme_fabric_options *p); + +/** + * nvme_fabric_options_set_hdr_digest() - Set hdr_digest. + * @p: The &struct nvme_fabric_options instance to update. + * @hdr_digest: Value to assign to the hdr_digest field. + */ +void nvme_fabric_options_set_hdr_digest( + struct nvme_fabric_options *p, + bool hdr_digest); + +/** + * nvme_fabric_options_get_hdr_digest() - Get hdr_digest. + * @p: The &struct nvme_fabric_options instance to query. + * + * Return: The value of the hdr_digest field. + */ +bool nvme_fabric_options_get_hdr_digest(const struct nvme_fabric_options *p); + +/** + * nvme_fabric_options_set_host_iface() - Set host_iface. + * @p: The &struct nvme_fabric_options instance to update. + * @host_iface: Value to assign to the host_iface field. + */ +void nvme_fabric_options_set_host_iface( + struct nvme_fabric_options *p, + bool host_iface); + +/** + * nvme_fabric_options_get_host_iface() - Get host_iface. + * @p: The &struct nvme_fabric_options instance to query. + * + * Return: The value of the host_iface field. + */ +bool nvme_fabric_options_get_host_iface(const struct nvme_fabric_options *p); + +/** + * nvme_fabric_options_set_host_traddr() - Set host_traddr. + * @p: The &struct nvme_fabric_options instance to update. + * @host_traddr: Value to assign to the host_traddr field. + */ +void nvme_fabric_options_set_host_traddr( + struct nvme_fabric_options *p, + bool host_traddr); + +/** + * nvme_fabric_options_get_host_traddr() - Get host_traddr. + * @p: The &struct nvme_fabric_options instance to query. + * + * Return: The value of the host_traddr field. + */ +bool nvme_fabric_options_get_host_traddr(const struct nvme_fabric_options *p); + +/** + * nvme_fabric_options_set_hostid() - Set hostid. + * @p: The &struct nvme_fabric_options instance to update. + * @hostid: Value to assign to the hostid field. + */ +void nvme_fabric_options_set_hostid(struct nvme_fabric_options *p, bool hostid); + +/** + * nvme_fabric_options_get_hostid() - Get hostid. + * @p: The &struct nvme_fabric_options instance to query. + * + * Return: The value of the hostid field. + */ +bool nvme_fabric_options_get_hostid(const struct nvme_fabric_options *p); + +/** + * nvme_fabric_options_set_hostnqn() - Set hostnqn. + * @p: The &struct nvme_fabric_options instance to update. + * @hostnqn: Value to assign to the hostnqn field. + */ +void nvme_fabric_options_set_hostnqn( + struct nvme_fabric_options *p, + bool hostnqn); + +/** + * nvme_fabric_options_get_hostnqn() - Get hostnqn. + * @p: The &struct nvme_fabric_options instance to query. + * + * Return: The value of the hostnqn field. + */ +bool nvme_fabric_options_get_hostnqn(const struct nvme_fabric_options *p); + +/** + * nvme_fabric_options_set_instance() - Set instance. + * @p: The &struct nvme_fabric_options instance to update. + * @instance: Value to assign to the instance field. + */ +void nvme_fabric_options_set_instance( + struct nvme_fabric_options *p, + bool instance); + +/** + * nvme_fabric_options_get_instance() - Get instance. + * @p: The &struct nvme_fabric_options instance to query. + * + * Return: The value of the instance field. + */ +bool nvme_fabric_options_get_instance(const struct nvme_fabric_options *p); + +/** + * nvme_fabric_options_set_keep_alive_tmo() - Set keep_alive_tmo. + * @p: The &struct nvme_fabric_options instance to update. + * @keep_alive_tmo: Value to assign to the keep_alive_tmo field. + */ +void nvme_fabric_options_set_keep_alive_tmo( + struct nvme_fabric_options *p, + bool keep_alive_tmo); + +/** + * nvme_fabric_options_get_keep_alive_tmo() - Get keep_alive_tmo. + * @p: The &struct nvme_fabric_options instance to query. + * + * Return: The value of the keep_alive_tmo field. + */ +bool nvme_fabric_options_get_keep_alive_tmo( + const struct nvme_fabric_options *p); + +/** + * nvme_fabric_options_set_keyring() - Set keyring. + * @p: The &struct nvme_fabric_options instance to update. + * @keyring: Value to assign to the keyring field. + */ +void nvme_fabric_options_set_keyring( + struct nvme_fabric_options *p, + bool keyring); + +/** + * nvme_fabric_options_get_keyring() - Get keyring. + * @p: The &struct nvme_fabric_options instance to query. + * + * Return: The value of the keyring field. + */ +bool nvme_fabric_options_get_keyring(const struct nvme_fabric_options *p); + +/** + * nvme_fabric_options_set_nqn() - Set nqn. + * @p: The &struct nvme_fabric_options instance to update. + * @nqn: Value to assign to the nqn field. + */ +void nvme_fabric_options_set_nqn(struct nvme_fabric_options *p, bool nqn); + +/** + * nvme_fabric_options_get_nqn() - Get nqn. + * @p: The &struct nvme_fabric_options instance to query. + * + * Return: The value of the nqn field. + */ +bool nvme_fabric_options_get_nqn(const struct nvme_fabric_options *p); + +/** + * nvme_fabric_options_set_nr_io_queues() - Set nr_io_queues. + * @p: The &struct nvme_fabric_options instance to update. + * @nr_io_queues: Value to assign to the nr_io_queues field. + */ +void nvme_fabric_options_set_nr_io_queues( + struct nvme_fabric_options *p, + bool nr_io_queues); + +/** + * nvme_fabric_options_get_nr_io_queues() - Get nr_io_queues. + * @p: The &struct nvme_fabric_options instance to query. + * + * Return: The value of the nr_io_queues field. + */ +bool nvme_fabric_options_get_nr_io_queues(const struct nvme_fabric_options *p); + +/** + * nvme_fabric_options_set_nr_poll_queues() - Set nr_poll_queues. + * @p: The &struct nvme_fabric_options instance to update. + * @nr_poll_queues: Value to assign to the nr_poll_queues field. + */ +void nvme_fabric_options_set_nr_poll_queues( + struct nvme_fabric_options *p, + bool nr_poll_queues); + +/** + * nvme_fabric_options_get_nr_poll_queues() - Get nr_poll_queues. + * @p: The &struct nvme_fabric_options instance to query. + * + * Return: The value of the nr_poll_queues field. + */ +bool nvme_fabric_options_get_nr_poll_queues( + const struct nvme_fabric_options *p); + +/** + * nvme_fabric_options_set_nr_write_queues() - Set nr_write_queues. + * @p: The &struct nvme_fabric_options instance to update. + * @nr_write_queues: Value to assign to the nr_write_queues field. + */ +void nvme_fabric_options_set_nr_write_queues( + struct nvme_fabric_options *p, + bool nr_write_queues); + +/** + * nvme_fabric_options_get_nr_write_queues() - Get nr_write_queues. + * @p: The &struct nvme_fabric_options instance to query. + * + * Return: The value of the nr_write_queues field. + */ +bool nvme_fabric_options_get_nr_write_queues( + const struct nvme_fabric_options *p); + +/** + * nvme_fabric_options_set_queue_size() - Set queue_size. + * @p: The &struct nvme_fabric_options instance to update. + * @queue_size: Value to assign to the queue_size field. + */ +void nvme_fabric_options_set_queue_size( + struct nvme_fabric_options *p, + bool queue_size); + +/** + * nvme_fabric_options_get_queue_size() - Get queue_size. + * @p: The &struct nvme_fabric_options instance to query. + * + * Return: The value of the queue_size field. + */ +bool nvme_fabric_options_get_queue_size(const struct nvme_fabric_options *p); + +/** + * nvme_fabric_options_set_reconnect_delay() - Set reconnect_delay. + * @p: The &struct nvme_fabric_options instance to update. + * @reconnect_delay: Value to assign to the reconnect_delay field. + */ +void nvme_fabric_options_set_reconnect_delay( + struct nvme_fabric_options *p, + bool reconnect_delay); + +/** + * nvme_fabric_options_get_reconnect_delay() - Get reconnect_delay. + * @p: The &struct nvme_fabric_options instance to query. + * + * Return: The value of the reconnect_delay field. + */ +bool nvme_fabric_options_get_reconnect_delay( + const struct nvme_fabric_options *p); + +/** + * nvme_fabric_options_set_tls() - Set tls. + * @p: The &struct nvme_fabric_options instance to update. + * @tls: Value to assign to the tls field. + */ +void nvme_fabric_options_set_tls(struct nvme_fabric_options *p, bool tls); + +/** + * nvme_fabric_options_get_tls() - Get tls. + * @p: The &struct nvme_fabric_options instance to query. + * + * Return: The value of the tls field. + */ +bool nvme_fabric_options_get_tls(const struct nvme_fabric_options *p); + +/** + * nvme_fabric_options_set_tls_key() - Set tls_key. + * @p: The &struct nvme_fabric_options instance to update. + * @tls_key: Value to assign to the tls_key field. + */ +void nvme_fabric_options_set_tls_key( + struct nvme_fabric_options *p, + bool tls_key); + +/** + * nvme_fabric_options_get_tls_key() - Get tls_key. + * @p: The &struct nvme_fabric_options instance to query. + * + * Return: The value of the tls_key field. + */ +bool nvme_fabric_options_get_tls_key(const struct nvme_fabric_options *p); + +/** + * nvme_fabric_options_set_tos() - Set tos. + * @p: The &struct nvme_fabric_options instance to update. + * @tos: Value to assign to the tos field. + */ +void nvme_fabric_options_set_tos(struct nvme_fabric_options *p, bool tos); + +/** + * nvme_fabric_options_get_tos() - Get tos. + * @p: The &struct nvme_fabric_options instance to query. + * + * Return: The value of the tos field. + */ +bool nvme_fabric_options_get_tos(const struct nvme_fabric_options *p); + +/** + * nvme_fabric_options_set_traddr() - Set traddr. + * @p: The &struct nvme_fabric_options instance to update. + * @traddr: Value to assign to the traddr field. + */ +void nvme_fabric_options_set_traddr(struct nvme_fabric_options *p, bool traddr); + +/** + * nvme_fabric_options_get_traddr() - Get traddr. + * @p: The &struct nvme_fabric_options instance to query. + * + * Return: The value of the traddr field. + */ +bool nvme_fabric_options_get_traddr(const struct nvme_fabric_options *p); + +/** + * nvme_fabric_options_set_transport() - Set transport. + * @p: The &struct nvme_fabric_options instance to update. + * @transport: Value to assign to the transport field. + */ +void nvme_fabric_options_set_transport( + struct nvme_fabric_options *p, + bool transport); + +/** + * nvme_fabric_options_get_transport() - Get transport. + * @p: The &struct nvme_fabric_options instance to query. + * + * Return: The value of the transport field. + */ +bool nvme_fabric_options_get_transport(const struct nvme_fabric_options *p); + +/** + * nvme_fabric_options_set_trsvcid() - Set trsvcid. + * @p: The &struct nvme_fabric_options instance to update. + * @trsvcid: Value to assign to the trsvcid field. + */ +void nvme_fabric_options_set_trsvcid( + struct nvme_fabric_options *p, + bool trsvcid); + +/** + * nvme_fabric_options_get_trsvcid() - Get trsvcid. + * @p: The &struct nvme_fabric_options instance to query. + * + * Return: The value of the trsvcid field. + */ +bool nvme_fabric_options_get_trsvcid(const struct nvme_fabric_options *p); + +#endif /* _ACCESSORS_H_ */ diff --git a/libnvme/src/nvme/accessors.ld b/libnvme/src/nvme/accessors.ld new file mode 100644 index 0000000000..2fe00c6101 --- /dev/null +++ b/libnvme/src/nvme/accessors.ld @@ -0,0 +1,168 @@ + +LIBNVME_ACCESSORS_3_0 { + global: + nvme_path_get_name; + nvme_path_set_name; + nvme_path_get_sysfs_dir; + nvme_path_set_sysfs_dir; + nvme_path_get_ana_state; + nvme_path_set_ana_state; + nvme_path_get_numa_nodes; + nvme_path_set_numa_nodes; + nvme_path_get_grpid; + nvme_path_set_grpid; + nvme_ns_get_nsid; + nvme_ns_set_nsid; + nvme_ns_get_name; + nvme_ns_set_name; + nvme_ns_get_sysfs_dir; + nvme_ns_set_sysfs_dir; + nvme_ns_get_lba_shift; + nvme_ns_set_lba_shift; + nvme_ns_get_lba_size; + nvme_ns_set_lba_size; + nvme_ns_get_meta_size; + nvme_ns_set_meta_size; + nvme_ns_get_lba_count; + nvme_ns_set_lba_count; + 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_key; + nvme_ctrl_set_dhchap_key; + nvme_ctrl_get_dhchap_ctrl_key; + nvme_ctrl_set_dhchap_ctrl_key; + nvme_ctrl_get_keyring; + nvme_ctrl_set_keyring; + nvme_ctrl_get_tls_key_identity; + nvme_ctrl_set_tls_key_identity; + 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; + nvme_ctrl_set_unique_discovery_ctrl; + nvme_ctrl_get_discovered; + nvme_ctrl_set_discovered; + nvme_ctrl_get_persistent; + nvme_ctrl_set_persistent; + 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; + nvme_subsystem_set_iopolicy; + nvme_host_get_hostnqn; + nvme_host_set_hostnqn; + nvme_host_get_hostid; + nvme_host_set_hostid; + nvme_host_get_dhchap_key; + nvme_host_set_dhchap_key; + nvme_host_get_hostsymname; + nvme_host_set_hostsymname; + nvme_host_get_pdc_enabled_valid; + nvme_host_set_pdc_enabled_valid; + nvme_fabric_options_get_cntlid; + nvme_fabric_options_set_cntlid; + nvme_fabric_options_get_concat; + nvme_fabric_options_set_concat; + nvme_fabric_options_get_ctrl_loss_tmo; + nvme_fabric_options_set_ctrl_loss_tmo; + nvme_fabric_options_get_data_digest; + nvme_fabric_options_set_data_digest; + nvme_fabric_options_get_dhchap_ctrl_secret; + nvme_fabric_options_set_dhchap_ctrl_secret; + nvme_fabric_options_get_dhchap_secret; + nvme_fabric_options_set_dhchap_secret; + nvme_fabric_options_get_disable_sqflow; + nvme_fabric_options_set_disable_sqflow; + nvme_fabric_options_get_discovery; + nvme_fabric_options_set_discovery; + nvme_fabric_options_get_duplicate_connect; + nvme_fabric_options_set_duplicate_connect; + nvme_fabric_options_get_fast_io_fail_tmo; + nvme_fabric_options_set_fast_io_fail_tmo; + nvme_fabric_options_get_hdr_digest; + nvme_fabric_options_set_hdr_digest; + nvme_fabric_options_get_host_iface; + nvme_fabric_options_set_host_iface; + nvme_fabric_options_get_host_traddr; + nvme_fabric_options_set_host_traddr; + nvme_fabric_options_get_hostid; + nvme_fabric_options_set_hostid; + nvme_fabric_options_get_hostnqn; + nvme_fabric_options_set_hostnqn; + nvme_fabric_options_get_instance; + nvme_fabric_options_set_instance; + nvme_fabric_options_get_keep_alive_tmo; + nvme_fabric_options_set_keep_alive_tmo; + nvme_fabric_options_get_keyring; + nvme_fabric_options_set_keyring; + nvme_fabric_options_get_nqn; + nvme_fabric_options_set_nqn; + nvme_fabric_options_get_nr_io_queues; + nvme_fabric_options_set_nr_io_queues; + nvme_fabric_options_get_nr_poll_queues; + nvme_fabric_options_set_nr_poll_queues; + nvme_fabric_options_get_nr_write_queues; + nvme_fabric_options_set_nr_write_queues; + nvme_fabric_options_get_queue_size; + nvme_fabric_options_set_queue_size; + nvme_fabric_options_get_reconnect_delay; + nvme_fabric_options_set_reconnect_delay; + nvme_fabric_options_get_tls; + nvme_fabric_options_set_tls; + nvme_fabric_options_get_tls_key; + nvme_fabric_options_set_tls_key; + nvme_fabric_options_get_tos; + nvme_fabric_options_set_tos; + nvme_fabric_options_get_traddr; + nvme_fabric_options_set_traddr; + nvme_fabric_options_get_transport; + nvme_fabric_options_set_transport; + nvme_fabric_options_get_trsvcid; + nvme_fabric_options_set_trsvcid; +}; diff --git a/libnvme/src/nvme/generate-accessors-exclude.list b/libnvme/src/nvme/generate-accessors-exclude.list new file mode 100644 index 0000000000..6fbbf1228c --- /dev/null +++ b/libnvme/src/nvme/generate-accessors-exclude.list @@ -0,0 +1,10 @@ +# SPDX-License-Identifier: LGPL-2.1-or-later + +nvme_ns::generic_name +nvme_ctrl::state +nvme_ctrl::address +nvme_ctrl::phy_slot +nvme_ctrl::subsysnqn +nvme_path::queue_depth +nvme_host::pdc_enabled + diff --git a/libnvme/src/nvme/structs-to-include.txt b/libnvme/src/nvme/generate-accessors-include.list similarity index 100% rename from libnvme/src/nvme/structs-to-include.txt rename to libnvme/src/nvme/generate-accessors-include.list diff --git a/libnvme/src/nvme/generate-accessors.c b/libnvme/src/nvme/generate-accessors.c index d3ef1485ef..e6116c74bf 100644 --- a/libnvme/src/nvme/generate-accessors.c +++ b/libnvme/src/nvme/generate-accessors.c @@ -58,11 +58,27 @@ #define SPACES " \t\n\r" #define streq(a, b) (strcmp((a), (b)) == 0) +/** + * Function naming convention: + * This controls whether to generate the functions as: + * nvme_foo_get() / nvme_foo_set() + * Or: + * nvme_get_foo() / nvme_set_foo() + */ +#define SET_FMT "%s_set_%s" /* alternate name: "%s_%s_set" */ +#define GET_FMT "%s_get_%s" /* alternate name: "%s_%s_get" */ + +/* checkpatch requires C99 // SPDX in *.c and block-style SPDX in *.h */ +static const char *spdx_c = "// SPDX-License-Identifier: LGPL-2.1-or-later"; +static const char *spdx_h = "/* SPDX-License-Identifier: LGPL-2.1-or-later */"; + static const char *banner = - "// SPDX-License-Identifier: LGPL-2.1-or-later\n" "/**\n" " * This file is part of libnvme.\n" " *\n" + " * Copyright (c) 2025, Dell Technologies Inc. or its subsidiaries.\n" + " * Authors: Martin Belanger \n" + " *\n" " * ____ _ _ ____ _\n" " * / ___| ___ _ __ ___ _ __ __ _| |_ ___ __| | / ___|___ __| | ___\n" " * | | _ / _ \\ '_ \\ / _ \\ '__/ _` | __/ _ \\/ _` | | | / _ \\ / _` |/ _ \\\n" @@ -70,7 +86,7 @@ static const char *banner = " * \\____|\\___|_| |_|\\___|_| \\__,_|\\__\\___|\\__,_| \\____\\___/ \\__,_|\\___|\n" " *\n" " * Auto-generated struct member accessors (setter/getter)\n" - " */\n"; + " */"; /** * @brief Remove leading whitespace characters from string @@ -207,8 +223,8 @@ static char *to_uppercase(char *s) * Any character that violates these rules is replaced with an underscore ('_'). * The string is always modified in place; no new memory is allocated. * - * @param s Pointer to the NUL-terminated string to sanitize. - * If @p s is NULL or points to an empty string, the function does nothing. + * @param s Pointer to the NUL-terminated string to sanitize. If @s is NULL or + * points to an empty string, the function does nothing. * * @note This function does not check for C keywords or identifier length limits. * @@ -264,7 +280,7 @@ static char *safe_strdup(const char *s) if (!new_string) return NULL; /* Return NULL on allocation failure */ - memcpy(new_string, s, len); /* Copy the string including NUL-terminator */ + memcpy(new_string, s, len); /* Copy the string incl. NUL-terminator */ return new_string; } @@ -617,8 +633,9 @@ static void strlst_add(StringList_t *list, const char *string, bool steal) if (list->count == list->capacity) { /* Reallocate to double capacity */ list->capacity *= 2; - list->strings = (const char **)realloc(list->strings, - list->capacity * sizeof(char *)); + list->strings = + (const char **)realloc(list->strings, + list->capacity * sizeof(char *)); for (size_t i = list->count; i < list->capacity; i++) list->strings[i] = NULL; } @@ -680,7 +697,8 @@ static void strlst_free(StringList_t *list) #define STRLST_FOREACH(sl, s) \ for (size_t __str_next = 0; \ ({ \ - (s) = (__str_next >= (sl)->count) ? NULL : (sl)->strings[__str_next++]; \ + (s) = (__str_next >= (sl)->count) \ + ? NULL : (sl)->strings[__str_next++]; \ (s) != NULL; \ });) @@ -726,7 +744,8 @@ static void strlst_load(StringList_t *list, const char *filename) f = fopen(filename, "r"); if (!f) { - fprintf(stderr, "Warning: could not open file '%s'\n", filename); + fprintf(stderr, + "Warning: could not open file '%s'\n", filename); return; } @@ -808,15 +827,15 @@ typedef struct Conf { bool verbose; const char *c_fname; /* Generated output *.c file name */ const char *h_fname; /* Generated output *.h file name */ - const char *l_fname; /* Generated ou5tput *.ld file name */ + const char *l_fname; /* Generated output *.ld file name */ const char *prefix; /* Prefix added to each functions */ StringList_t hdr_files; /* Input header file list */ StringList_t incl_list; /* Inclusion list (read from --incl) */ StringList_t excl_list; /* Enclusion list (read from --excl) */ struct { regex_t re_struct; /* regex to match struct definitions */ - regex_t re_char_array; /* regex to match char array struct members */ - regex_t re_member; /* regex to match all other struct members */ + regex_t re_char_array; /* regex to match char array members */ + regex_t re_member; /* regex to match all other members */ } re; /* Precompiled regular expressions */ } Conf_t; @@ -867,13 +886,13 @@ typedef struct Member { typedef struct StructInfo { char *name; /* Name of the struct */ - Member_t *members; /* Array of struct members (each entry is one member) */ + Member_t *members; /* Array of members (each entry is 1 member) */ size_t count; /* Number of entries in members */ size_t capacity; /* Allocated capacity for members */ } StructInfo_t; typedef struct StructList { - StructInfo_t *items; /* Array of structs (each entry corresponds to one struct) */ + StructInfo_t *items; /* Array of structs (each entry is 1 struct) */ size_t count; /* Number of entries in items */ size_t capacity; /* Allocated capacity for items */ } StructList_t; @@ -994,7 +1013,9 @@ static Member_t *struct_info_member_add(StructInfo_t *si, if (si->count == si->capacity) { /* Reallocate to double capacity */ si->capacity *= 2; - si->members = (Member_t *)realloc(si->members, si->capacity * sizeof(Member_t)); + si->members = + (Member_t *)realloc(si->members, + si->capacity * sizeof(Member_t)); for (size_t i = si->count; i < si->capacity; i++) member_init(&si->members[i]); } @@ -1162,7 +1183,7 @@ static void struct_list_parse(StructList_t *sl, const char *text, Conf_t *conf) trimmed_line = trim(trim_inline_comments(line)); if (trimmed_line[0] == '\0' || /* empty line */ - !strchr(trimmed_line, ';') || /* skip lines without semicolon */ + !strchr(trimmed_line, ';') || /* skip lines w/o semicolon */ strstr(trimmed_line, "static") || /* skip static members */ strstr(trimmed_line, "struct")) /* skip struct members */ continue; @@ -1243,123 +1264,424 @@ static void struct_list_parse(StructList_t *sl, const char *text, Conf_t *conf) #define STRUCT_LIST_FOREACH(sl, si) \ for (size_t __si_next = 0; \ ({ \ - (si) = (__si_next >= (sl)->count) ? NULL : &(sl)->items[__si_next++]; \ + (si) = (__si_next >= (sl)->count) \ + ? NULL : &(sl)->items[__si_next++]; \ (si) != NULL; \ });) /******************************************************************************/ +/* + * The emit_hdr_*() and emit_src_*() helpers below generate the content of + * accessors.h and accessors.c respectively. The generated files are checked + * into the repository and must pass checkpatch.pl cleanly, so several + * design choices exist purely for that reason: + * + * 1. type_sep() — checkpatch requires that a '*' in a pointer return type + * is attached to the function name, not to the type keyword. For example: + * const char *nvme_ctrl_get_name(...) <- correct + * const char * nvme_ctrl_get_name(...) <- checkpatch error + * type_sep() returns "" when the type already ends with '*' so that no + * extra space is inserted between the type and the function name. + * + * 2. snprintf(NULL, 0, ...) — checkpatch warns about source lines longer + * than 80 characters. Because the length of a generated prototype depends + * on the struct and member names (which vary widely), we cannot know at + * compile time whether a declaration will fit on one line. snprintf with + * a NULL buffer and size 0 is a standard C99 idiom that returns the number + * of characters that *would* have been written, allowing us to measure the + * line length before committing to either the single-line or the wrapped + * two-line form. The LINE_FITS_80() macro below wraps this idiom into a + * readable boolean test. + */ + +/* + * True when the printf-formatted string would fit within checkpatch's + * 80-character line-length limit. Uses snprintf(NULL, 0, ...) to measure + * the output length without allocating a buffer (C99 - 7.19.6.5). + * + * LINE_FITS_80_NTABS is a tab-aware variant for body lines that begin with + * n hard tabs: checkpatch expands each tab to an 8-space tab stop, so each + * tab costs 7 extra visible columns compared to the 1 byte snprintf counts. + */ +#define LINE_FITS_80(fmt, ...) \ + (snprintf(NULL, 0, fmt, ##__VA_ARGS__) <= 80) +#define LINE_FITS_80_NTABS(n, fmt, ...) \ + (snprintf(NULL, 0, fmt, ##__VA_ARGS__) + (n) * 7 <= 80) + +/** + * @brief Return the separator to place between a C type and a function name. + * + * When @type already ends with '*' (e.g. "const char *") no additional + * space is needed before the function name; otherwise a single space is + * required to separate the type keyword from the identifier. + * + * @param type: The return-type string (e.g. "int", "const char *"). + * + * @return "" if @type ends with '*', " " otherwise. + */ +static const char *type_sep(const char *type) +{ + size_t len = strlen(type); + + return (len > 0 && type[len - 1] == '*') ? "" : " "; +} + +/** + * @brief Emit a header declaration for a string setter. + * + * Writes the Kerneldoc comment and prototype for a setter that accepts + * a "const char *" argument. Handles both dynamic strings (strdup'd) + * and fixed-size char arrays (snprintf'd). The prototype is wrapped + * onto two lines when it would exceed 80 characters. + * + * @param f: Output FILE*. + * @param prefix: Function-name prefix (e.g. "nvme"). + * @param sname: Struct name (e.g. "ctrl"). + * @param mname: Member name (e.g. "firmware"). + * @param is_dyn_str: true for dynamic "const char *", false for char array. + */ +static void emit_hdr_setter_str(FILE *f, const char *prefix, + const char *sname, const char *mname, bool is_dyn_str) +{ + fprintf(f, + "/**\n" + " * %s" SET_FMT "() - Set %s.\n" + " * @p: The &struct %s instance to update.\n", + prefix, sname, mname, + mname, + sname); + if (is_dyn_str) + fprintf(f, + " * @%s: New string; a copy is stored. Pass NULL to clear.\n", + mname); + else + fprintf(f, + " * @%s: New string; truncated to fit, always NUL-terminated.\n", + mname); + fprintf(f, " */\n"); + + if (LINE_FITS_80("void %s" SET_FMT "(struct %s *p, const char *%s);", + prefix, sname, mname, sname, mname)) + fprintf(f, + "void %s" SET_FMT "(struct %s *p, const char *%s);\n\n", + prefix, sname, mname, sname, mname); + else + fprintf(f, + "void %s" SET_FMT "(\n" + "\t\tstruct %s *p,\n" + "\t\tconst char *%s);\n\n", + prefix, sname, mname, sname, mname); +} + +/** + * @brief Emit a header declaration for a value setter. + * + * Writes the Kerneldoc comment and prototype for a setter that accepts + * a numeric or boolean argument. The prototype is wrapped onto two + * lines when it would exceed 80 characters. + * + * @param f: Output FILE*. + * @param prefix: Function-name prefix (e.g. "nvme"). + * @param sname: Struct name (e.g. "ctrl"). + * @param mname: Member name (e.g. "nsid"). + * @param mtype: Member type string (e.g. "__u32"). + */ +static void emit_hdr_setter_val(FILE *f, const char *prefix, + const char *sname, const char *mname, const char *mtype) +{ + fprintf(f, + "/**\n" + " * %s" SET_FMT "() - Set %s.\n" + " * @p: The &struct %s instance to update.\n" + " * @%s: Value to assign to the %s field.\n" + " */\n", + prefix, sname, mname, + mname, + sname, + mname, mname); + + if (LINE_FITS_80("void %s" SET_FMT "(struct %s *p, %s %s);", + prefix, sname, mname, sname, mtype, mname)) + fprintf(f, + "void %s" SET_FMT "(struct %s *p, %s %s);\n\n", + prefix, sname, mname, sname, mtype, mname); + else + fprintf(f, + "void %s" SET_FMT "(\n" + "\t\tstruct %s *p,\n" + "\t\t%s %s);\n\n", + prefix, sname, mname, sname, mtype, mname); +} + +/** + * @brief Emit a header declaration for a getter. + * + * Writes the Kerneldoc comment and prototype for a getter. The + * prototype is wrapped onto two lines when it would exceed 80 + * characters. + * + * @param f: Output FILE*. + * @param prefix: Function-name prefix (e.g. "nvme"). + * @param sname: Struct name (e.g. "ctrl"). + * @param mname: Member name (e.g. "firmware"). + * @param mtype: Return type string (e.g. "const char *"). + * @param is_dyn_str: true for dynamic strings (affects Return: doc). + */ +static void emit_hdr_getter(FILE *f, const char *prefix, + const char *sname, const char *mname, + const char *mtype, bool is_dyn_str) +{ + fprintf(f, + "/**\n" + " * %s" GET_FMT "() - Get %s.\n" + " * @p: The &struct %s instance to query.\n" + " *\n" + " * Return: The value of the %s field%s\n" + " */\n", + prefix, sname, mname, + mname, + sname, + mname, + is_dyn_str ? ", or NULL if not set." : "."); + + if (LINE_FITS_80("%s%s%s" GET_FMT "(const struct %s *p);", + mtype, type_sep(mtype), prefix, sname, mname, sname)) + fprintf(f, + "%s%s%s" GET_FMT "(const struct %s *p);\n\n", + mtype, type_sep(mtype), prefix, sname, mname, sname); + else + fprintf(f, + "%s%s%s" GET_FMT "(\n" + "\t\tconst struct %s *p);\n\n", + mtype, type_sep(mtype), prefix, sname, mname, sname); +} /** * @brief Generate header (.h) declarations for accessors of one struct. * - * Writes function prototypes for setters and getters for every member - * of @si to the provided output FILE (@generated_hdr). + * Iterates over the members of @si and calls the appropriate emit_hdr_* + * helper for each setter and getter. * * @param generated_hdr: FILE* to write header declarations to. * @param si: Pointer to StructInfo_t describing the struct and members. * @param conf: Pointer to Conf_t containing args and generation options. */ -static void generate_hdr(FILE *generated_hdr, StructInfo_t *si, Conf_t *conf) +static void generate_hdr(FILE *generated_hdr, StructInfo_t *si, Conf_t *conf) { for (size_t m = 0; m < si->count; m++) { - Member_t *members = &si->members[m]; + Member_t *members = &si->members[m]; + bool is_dyn_str = !members->is_char_array && + streq(members->type, "const char *"); - /* Setter method */ if (!members->is_const) { /* No setter on const members */ - if (members->is_char_array || streq(members->type, "const char *")) - fprintf(generated_hdr, - "void %s%s_%s_set(struct %s *p, const char *%s);\n", - conf->prefix, si->name, - members->name, si->name, members->name); + if (members->is_char_array || is_dyn_str) + emit_hdr_setter_str(generated_hdr, conf->prefix, + si->name, members->name, + is_dyn_str); else - fprintf(generated_hdr, - "void %s%s_%s_set(struct %s *p, %s %s);\n", - conf->prefix, si->name, - members->name, si->name, members->type, members->name); + emit_hdr_setter_val(generated_hdr, conf->prefix, + si->name, members->name, + members->type); } - /* Getter method */ - fprintf(generated_hdr, "%s %s%s_%s_get(const struct %s *p);\n\n", - members->type, conf->prefix, si->name, members->name, si->name); + emit_hdr_getter(generated_hdr, conf->prefix, + si->name, members->name, + members->type, is_dyn_str); } } +/** + * @brief Emit a source definition for a dynamic-string setter. + * + * Generates a setter that frees the old value and strdup's the new one. + * Passing NULL clears the field. + * + * @param f: Output FILE*. + * @param prefix: Function-name prefix (e.g. "nvme"). + * @param sname: Struct name. + * @param mname: Member name. + */ +static void emit_src_setter_dynstr(FILE *f, const char *prefix, + const char *sname, const char *mname) +{ + /* Emit function signature, wrapping if it exceeds 80 chars. */ + if (LINE_FITS_80("void %s" SET_FMT "(struct %s *p, const char *%s)", + prefix, sname, mname, sname, mname)) + fprintf(f, + "void %s" SET_FMT "(struct %s *p, const char *%s)\n", + prefix, sname, mname, sname, mname); + else + fprintf(f, + "void %s" SET_FMT "(\n" + "\t\tstruct %s *p,\n" + "\t\tconst char *%s)\n", + prefix, sname, mname, sname, mname); + + /* Emit function body; wrap the strdup line if it exceeds 80 chars. + * checkpatch expands the leading tab to 8 spaces, so use NTABS(1). + */ + fprintf(f, "{\n\tfree(p->%s);\n", mname); + if (LINE_FITS_80_NTABS(1, "\tp->%s = %s ? strdup(%s) : NULL;", + mname, mname, mname)) + fprintf(f, "\tp->%s = %s ? strdup(%s) : NULL;\n", + mname, mname, mname); + else + fprintf(f, "\tp->%s =\n\t\t%s ? strdup(%s) : NULL;\n", + mname, mname, mname); + fprintf(f, "}\n\n"); +} + +/** + * @brief Emit a source definition for a fixed char-array setter. + * + * Generates a setter that uses snprintf to copy into a fixed-size + * char array, always NUL-terminating the result. @array_size may be + * a numeric literal or a symbolic constant. + * + * @param f: Output FILE*. + * @param prefix: Function-name prefix (e.g. "nvme"). + * @param sname: Struct name. + * @param mname: Member name. + * @param array_size: Size of the char array as a string. + */ +static void emit_src_setter_chararray(FILE *f, const char *prefix, + const char *sname, const char *mname, const char *array_size) +{ + if (LINE_FITS_80("void %s" SET_FMT "(struct %s *p, const char *%s)", + prefix, sname, mname, sname, mname)) + fprintf(f, + "void %s" SET_FMT "(struct %s *p, const char *%s)\n", + prefix, sname, mname, sname, mname); + else + fprintf(f, + "void %s" SET_FMT "(\n" + "\t\tstruct %s *p,\n" + "\t\tconst char *%s)\n", + prefix, sname, mname, sname, mname); + + if (str_is_all_numbers(array_size)) { + unsigned long sz = strtoul(array_size, NULL, 10); + + fprintf(f, + "{\n" + "\tsnprintf(p->%s, %lu, \"%%s\", %s);\n" + "}\n\n", + mname, sz, mname); + } else { + fprintf(f, + "{\n" + "\tsnprintf(p->%s, %s, \"%%s\", %s);\n" + "}\n\n", + mname, array_size, mname); + } +} + +/** + * @brief Emit a source definition for a value setter. + * + * Generates a setter that directly assigns the argument to the member. + * + * @param f: Output FILE*. + * @param prefix: Function-name prefix (e.g. "nvme"). + * @param sname: Struct name. + * @param mname: Member name. + * @param mtype: Member type string (e.g. "__u32"). + */ +static void emit_src_setter_val(FILE *f, const char *prefix, + const char *sname, const char *mname, const char *mtype) +{ + if (LINE_FITS_80("void %s" SET_FMT "(struct %s *p, %s %s)", + prefix, sname, mname, sname, mtype, mname)) + fprintf(f, + "void %s" SET_FMT "(struct %s *p, %s %s)\n" + "{\n" + "\tp->%s = %s;\n" + "}\n\n", + prefix, sname, mname, + sname, mtype, mname, + mname, mname); + else + fprintf(f, + "void %s" SET_FMT "(\n" + "\t\tstruct %s *p,\n" + "\t\t%s %s)\n" + "{\n" + "\tp->%s = %s;\n" + "}\n\n", + prefix, sname, mname, + sname, mtype, mname, + mname, mname); +} + +/** + * @brief Emit a source definition for a getter. + * + * Generates a getter that returns the value of the struct member. + * + * @param f: Output FILE*. + * @param prefix: Function-name prefix (e.g. "nvme"). + * @param sname: Struct name. + * @param mname: Member name. + * @param mtype: Return type string (e.g. "const char *"). + */ +static void emit_src_getter(FILE *f, const char *prefix, + const char *sname, const char *mname, const char *mtype) +{ + if (LINE_FITS_80("%s%s%s" GET_FMT "(const struct %s *p)", + mtype, type_sep(mtype), prefix, sname, mname, sname)) + fprintf(f, + "%s%s%s" GET_FMT "(const struct %s *p)\n" + "{\n" + "\treturn p->%s;\n" + "}\n\n", + mtype, type_sep(mtype), prefix, sname, mname, + sname, mname); + else + fprintf(f, + "%s%s%s" GET_FMT "(\n" + "\t\tconst struct %s *p)\n" + "{\n" + "\treturn p->%s;\n" + "}\n\n", + mtype, type_sep(mtype), prefix, sname, mname, + sname, mname); +} + /** * @brief Generate source (.c) implementations for accessors of one struct. * - * Writes setter and getter function implementations for each member in - * @si to the provided output FILE (@generated_src). Handles special - * cases: - * - dynamic "const char *" members are strdup'd and freed on set. - * - fixed-size char arrays use strncpy and ensure NUL termination. - * - other members are assigned directly. + * Iterates over the members of @si and calls the appropriate emit_src_* + * helper for each setter and getter. * * @param generated_src: FILE* to write implementations to. * @param si: Pointer to the struct description. * @param conf: Pointer to Conf_t containing args and generation options. */ -static void generate_src(FILE *generated_src, StructInfo_t *si, Conf_t *conf) +static void generate_src(FILE *generated_src, StructInfo_t *si, Conf_t *conf) { for (size_t m = 0; m < si->count; m++) { - Member_t *member = &si->members[m]; + Member_t *member = &si->members[m]; - /* Setter method */ if (!member->is_const) { - if (!member->is_char_array && streq(member->type, "const char *")) { - /* dynamic string */ - fprintf(generated_src, - "void %s%s_%s_set(struct %s *p, const char *%s) {\n" - " free(p->%s);\n" - " p->%s = %s ? strdup(%s) : NULL;\n" - "}\n\n", - conf->prefix, si->name, member->name, - si->name, member->name, - member->name, - member->name, member->name, member->name); - } else if (member->is_char_array) { - /* fixed-size array */ - if (str_is_all_numbers(member->array_size)) { - unsigned long sz = strtoul(member->array_size, NULL, 10); - - fprintf(generated_src, - "void %s%s_%s_set(struct %s *p, const char *%s) {\n" - " strncpy(p->%s, %s, %lu);\n" - " p->%s[%lu] = '\\0';\n" - "}\n\n", - conf->prefix, si->name, member->name, - si->name, member->name, - member->name, member->name, sz, - member->name, sz - 1); - } else { - fprintf(generated_src, - "void %s%s_%s_set(struct %s *p, const char *%s) {\n" - " strncpy(p->%s, %s, %s);\n" - " p->%s[%s - 1] = '\\0';\n" - "}\n\n", - conf->prefix, si->name, member->name, - si->name, member->name, - member->name, member->name, member->array_size, - member->name, member->array_size); - } - } else { /* numeric or struct */ - fprintf(generated_src, - "void %s%s_%s_set(struct %s *p, %s %s) {\n" - " p->%s = %s;\n" - "}\n\n", - conf->prefix, si->name, member->name, si->name, - member->type, member->name, - member->name, member->name); - - } + if (!member->is_char_array && + streq(member->type, "const char *")) + emit_src_setter_dynstr(generated_src, + conf->prefix, + si->name, member->name); + else if (member->is_char_array) + emit_src_setter_chararray(generated_src, + conf->prefix, + si->name, member->name, + member->array_size); + else + emit_src_setter_val(generated_src, conf->prefix, + si->name, member->name, + member->type); } - /* Getter method */ - fprintf(generated_src, "%s %s%s_%s_get(const struct %s *p) {\n" - " return p->%s;\n" - "}\n\n", - member->type, conf->prefix, si->name, member->name, si->name, - member->name); + emit_src_getter(generated_src, conf->prefix, + si->name, member->name, member->type); } } @@ -1368,7 +1690,7 @@ static void generate_src(FILE *generated_src, StructInfo_t *si, Conf_t *conf) * one struct. * * Writes linker entries for each member in @si to the provided output - * FILE (@generated_ld). Handles special + * FILE (@generated_ld). * * @param generated_ld: FILE* to write implementations to. * @param si: Pointer to the struct description. @@ -1380,10 +1702,10 @@ static void generate_ld(FILE *generated_ld, StructInfo_t *si, Conf_t *conf) Member_t *member = &si->members[m]; fprintf(generated_ld, - "\t\t%s%s_%s_get;\n" - "\t\t%s%s_%s_set;\n", - conf->prefix, si->name, member->name, - conf->prefix, si->name, member->name); + "\t\t%s" GET_FMT ";\n" + "\t\t%s" SET_FMT ";\n", + conf->prefix, si->name, member->name, + conf->prefix, si->name, member->name); } } @@ -1404,8 +1726,8 @@ static void print_usage(const char *prog) " -c, --c-out Name of the generated *.c file. Default: %s\n" " -h, --h-out Name of the generated *.h file. Default: %s\n" " -l, --ld-out Name of the generated *.ld file. Default: %s\n" - " -e, --excl Exclusion list. Which member of a struct to exclude (struct::member per line). Default: do not exclude anything\n" - " -i, --incl Inclusion list. Which struct to include (struct name per line). Default: include every struct found\n" + " -e, --excl Exclusion list. struct::member to exclude (1 struct::member per line). Default: do not exclude anything\n" + " -i, --incl Inclusion list. structs to include (1 struct name per line). Default: include every struct found\n" " -p, --prefix Prefix for generated function names\n" " -v, --verbose Verbose output\n" " -H, --help Show this message\n", @@ -1478,12 +1800,16 @@ static void args_parse(Conf_t *conf, int argc, char *argv[]) strlst_init(&conf->hdr_files, 16); for (int i = optind; i < argc; ++i) { glob_t glob_result = { 0 }; - int ret = glob(argv[i], GLOB_TILDE|GLOB_NOCHECK, NULL, &glob_result); + int ret = glob(argv[i], GLOB_TILDE|GLOB_NOCHECK, NULL, + &glob_result); if (ret == 0) { - for (size_t j = 0; j < glob_result.gl_pathc; ++j) - strlst_add(&conf->hdr_files, - realpath(glob_result.gl_pathv[j], NULL), true); + char *rp; + + for (size_t j = 0; j < glob_result.gl_pathc; ++j) { + rp = realpath(glob_result.gl_pathv[j], NULL); + strlst_add(&conf->hdr_files, rp, true); + } } else { fprintf(stderr, "Warning: No match for %s\n", argv[i]); } @@ -1541,9 +1867,10 @@ static void conf_free(Conf_t *conf) * This function copies all data from the source file stream (`srce`) * to the destination file stream (`dest`). * - * If `NVME_HAVE_SENDFILE` is defined, the function uses the `sendfile()` system - * call for efficient data transfer between file descriptors. Otherwise, it falls - * back to a standard character-by-character copy using `fgetc()` and `fputc()`. + * If `NVME_HAVE_SENDFILE` is defined, the function uses the `sendfile()` + * system call for efficient data transfer between file descriptors. Otherwise, + * it falls back to a standard character-by-character copy using `fgetc()` and + * `fputc()`. * * The source file position is reset to the beginning before copying. * The destination file is not closed or flushed beyond the initial `fflush()` @@ -1672,18 +1999,18 @@ int main(int argc, char *argv[]) /* Generate code for the header file (*.h) */ fprintf(tmp_hdr_code, - "\n" "/****************************************************************************\n" " * Accessors for: struct %s\n" - " */\n", si->name); + " ****************************************************************************/\n" + "\n", si->name); generate_hdr(tmp_hdr_code, si, &conf); /* Generate code for the source file (*.c) */ fprintf(tmp_src_code, - "\n" "/****************************************************************************\n" " * Accessors for: struct %s\n" - " */\n", si->name); + " ****************************************************************************/\n" + "\n", si->name); generate_src(tmp_src_code, si, &conf); /* Generate entries for the linker script (*.ld) */ @@ -1693,7 +2020,7 @@ int main(int argc, char *argv[]) struct_list_free(&sl); - /* We've collected all the data we needed. Now let's generate some files. */ + /* We've collected all the data we needed. Now let's generate files. */ /*********************************************************************** * First, output the generated header file. @@ -1706,10 +2033,12 @@ int main(int argc, char *argv[]) dont_care = asprintf(&guard, "_%s_", get_filename(conf.h_fname)); sanitize_identifier(to_uppercase(guard)); - mkdir_fullpath(conf.h_fname, 0755); /* create output file's directory if needed */ + mkdir_fullpath(conf.h_fname, 0755); /* create output folder if needed */ generated_hdr = fopen(conf.h_fname, "w"); fprintf(generated_hdr, + "%s\n" + "\n" "%s\n" "#ifndef %s\n" "#define %s\n" @@ -1719,12 +2048,14 @@ int main(int argc, char *argv[]) "#include \n" "#include \n" "#include /* __u32, __u64, etc. */\n" - "\n", banner, guard, guard); + "\n", spdx_h, banner, guard, guard); - fprintf(generated_hdr, "/* Forward declarations. These are internal (opaque) structs. */\n"); + fprintf(generated_hdr, + "/* Forward declarations. These are internal (opaque) structs. */\n"); STRLST_FOREACH(&forward_declares, struct_to_declare) fprintf(generated_hdr, "struct %s;\n", struct_to_declare); strlst_free(&forward_declares); + fprintf(generated_hdr, "\n"); /* Copy temporary file to output */ append_file(generated_hdr, tmp_hdr_code); @@ -1738,18 +2069,21 @@ int main(int argc, char *argv[]) * Second, output the generated source file. */ - mkdir_fullpath(conf.c_fname, 0755); /* create output file's directory if needed */ + mkdir_fullpath(conf.c_fname, 0755); /* create output folder if needed */ generated_src = fopen(conf.c_fname, "w"); fprintf(generated_src, + "%s\n" + "\n" "%s\n" "#include \n" "#include \n" "#include \"%s\"\n" - "\n", banner, get_filename(conf.h_fname)); + "\n", spdx_c, banner, get_filename(conf.h_fname)); STRLST_FOREACH(&files_to_include, include_fname) fprintf(generated_src, "#include \"%s\"\n", include_fname); strlst_free(&files_to_include); + fprintf(generated_src, "\n"); /* Copy temporary file to output */ append_file(generated_src, tmp_src_code); @@ -1759,7 +2093,7 @@ int main(int argc, char *argv[]) /*********************************************************************** * Third, output the linker script file. */ - mkdir_fullpath(conf.l_fname, 0755); /* create output file's directory if needed */ + mkdir_fullpath(conf.l_fname, 0755); /* create output folder if needed */ generated_ld = fopen(conf.l_fname, "w"); fprintf(generated_ld, "\n" diff --git a/libnvme/src/nvme/meson.build b/libnvme/src/nvme/meson.build index 241f01a3d6..a7345f2dab 100644 --- a/libnvme/src/nvme/meson.build +++ b/libnvme/src/nvme/meson.build @@ -5,18 +5,22 @@ # # Authors: Martin Belanger # -# Run generate-accessors to generate the setter/getter functions. +# The accessor files (accessors.h, accessors.c, accessors.ld) are +# pre-generated and committed to the source tree. They are NOT +# regenerated during a normal build. +# +# To regenerate them after changing private.h or structs-to-include.txt: +# +# meson compile -C update-accessors -generated_h = 'accessors.h' -generated_c = 'accessors.c' -generated_ld = 'accessors.ld' +# --------------------------------------------------------------------------- +# Developer-only helper: build the generator and regenerate if structs change. +# NOT executed during a normal build (build_by_default: false). +# Usage: meson compile -C update-accessors +# --------------------------------------------------------------------------- -# List of header files to parse for structs -headers_to_scan = [ - '../nvme/private.h', -] +accessors_ld_full_path = meson.current_source_dir() / 'accessors.ld' -# Build the code generator tool generate_accessors = executable( 'generate-accessors', 'generate-accessors.c', @@ -25,49 +29,18 @@ generate_accessors = executable( config_dep, ], native: true, + build_by_default: false, ) -# Generate accessors code -accessors_ch_custom_tgt = custom_target( - 'accessors[.c.h.ld]', - input: files(headers_to_scan), - output: [ - generated_h, - generated_c, - generated_ld, - ], +run_target( + 'update-accessors', command: [ + meson.current_source_dir() / 'update-accessors.sh', generate_accessors, - '--h-out', '@OUTPUT0@', - '--c-out', '@OUTPUT1@', - '--ld-out', '@OUTPUT2@', - '--incl', join_paths(meson.current_source_dir(), 'structs-to-include.txt'), - '@INPUT@', + meson.current_source_dir(), + meson.current_source_dir() / 'generate-accessors-include.list', + meson.current_source_dir() / 'generate-accessors-exclude.list', + meson.current_source_dir() / 'private.h', ], - build_by_default: true, - install: true, - install_dir: [ - get_option('includedir') / 'nvme', - false, - false, - ], - install_mode: 'rw-r--r--', + depends: generate_accessors, ) - -tgt_accessors_h = accessors_ch_custom_tgt[0] -tgt_accessors_c = accessors_ch_custom_tgt[1] -tgt_accessors_ld = accessors_ch_custom_tgt[2] - -accessors_dep = declare_dependency( - sources: [ - tgt_accessors_c, - tgt_accessors_h, - ], - include_directories: '.', -) - -if meson.version().version_compare('>=1.4.0') - accessors_ld_full_path = tgt_accessors_ld.full_path() -else - accessors_ld_full_path = meson.current_build_dir() / generated_ld -endif diff --git a/libnvme/src/nvme/tree.c b/libnvme/src/nvme/tree.c index dcc540fb89..539f6350f0 100644 --- a/libnvme/src/nvme/tree.c +++ b/libnvme/src/nvme/tree.c @@ -389,44 +389,6 @@ struct nvme_global_ctx *nvme_host_get_global_ctx(nvme_host_t h) return h->ctx; } -const char *nvme_host_get_hostnqn(nvme_host_t h) -{ - return h->hostnqn; -} - -const char *nvme_host_get_hostid(nvme_host_t h) -{ - return h->hostid; -} - -const char *nvme_host_get_hostsymname(nvme_host_t h) -{ - return h->hostsymname; -} - -void nvme_host_set_hostsymname(nvme_host_t h, const char *hostsymname) -{ - free(h->hostsymname); - h->hostsymname = NULL; - - if (hostsymname) - h->hostsymname = strdup(hostsymname); -} - -const char *nvme_host_get_dhchap_key(nvme_host_t h) -{ - return h->dhchap_key; -} - -void nvme_host_set_dhchap_key(nvme_host_t h, const char *key) -{ - free(h->dhchap_key); - h->dhchap_key = NULL; - - if (key) - h->dhchap_key = strdup(key); -} - void nvme_host_set_pdc_enabled(nvme_host_t h, bool enabled) { h->pdc_enabled_valid = true; @@ -472,50 +434,11 @@ const char *nvme_subsystem_get_nqn(nvme_subsystem_t s) return s->subsysnqn; } -const char *nvme_subsystem_get_sysfs_dir(nvme_subsystem_t s) -{ - return s->sysfs_dir; -} - -const char *nvme_subsystem_get_name(nvme_subsystem_t s) -{ - return s->name; -} - const char *nvme_subsystem_get_type(nvme_subsystem_t s) { return s->subsystype; } -const char *nvme_subsystem_get_application(nvme_subsystem_t s) -{ - return s->application; -} - -void nvme_subsystem_set_application(nvme_subsystem_t s, const char *a) -{ - free(s->application); - s->application = NULL; - - if (a) - s->application = strdup(a); -} - -const char *nvme_subsystem_get_iopolicy(nvme_subsystem_t s) -{ - return s->iopolicy; -} - -const char *nvme_subsystem_get_model(nvme_subsystem_t s) -{ - return s->model; -} - -const char *nvme_subsystem_get_serial(nvme_subsystem_t s) -{ - return s->serial; -} - const char *nvme_subsystem_get_fw_rev(nvme_subsystem_t s) { return s->firmware; @@ -883,16 +806,6 @@ nvme_ns_t nvme_path_get_ns(nvme_path_t p) return p->n; } -const char *nvme_path_get_sysfs_dir(nvme_path_t p) -{ - return p->sysfs_dir; -} - -const char *nvme_path_get_name(nvme_path_t p) -{ - return p->name; -} - int nvme_path_get_queue_depth(nvme_path_t p) { _cleanup_free_ char *queue_depth = NULL; @@ -905,16 +818,6 @@ int nvme_path_get_queue_depth(nvme_path_t p) return p->queue_depth; } -const char *nvme_path_get_ana_state(nvme_path_t p) -{ - return p->ana_state; -} - -const char *nvme_path_get_numa_nodes(nvme_path_t p) -{ - return p->numa_nodes; -} - void nvme_free_path(struct nvme_path *p) { list_del_init(&p->entry); @@ -1001,15 +904,6 @@ nvme_subsystem_t nvme_ctrl_get_subsystem(nvme_ctrl_t c) return c->s; } -const char *nvme_ctrl_get_name(nvme_ctrl_t c) -{ - return c->name; -} - -const char *nvme_ctrl_get_sysfs_dir(nvme_ctrl_t c) -{ - return c->sysfs_dir; -} const char *nvme_ctrl_get_subsysnqn(nvme_ctrl_t c) { @@ -1052,16 +946,6 @@ const char *nvme_ctrl_get_phy_slot(nvme_ctrl_t c) return c->phy_slot ? c->phy_slot : ""; } -const char *nvme_ctrl_get_firmware(nvme_ctrl_t c) -{ - return c->firmware; -} - -const char *nvme_ctrl_get_model(nvme_ctrl_t c) -{ - return c->model; -} - const char *nvme_ctrl_get_state(nvme_ctrl_t c) { char *state = c->state; @@ -1071,51 +955,6 @@ const char *nvme_ctrl_get_state(nvme_ctrl_t c) return c->state; } -const char *nvme_ctrl_get_numa_node(nvme_ctrl_t c) -{ - return c->numa_node; -} - -const char *nvme_ctrl_get_queue_count(nvme_ctrl_t c) -{ - return c->queue_count; -} - -const char *nvme_ctrl_get_serial(nvme_ctrl_t c) -{ - return c->serial; -} - -const char *nvme_ctrl_get_sqsize(nvme_ctrl_t c) -{ - return c->sqsize; -} - -const char *nvme_ctrl_get_transport(nvme_ctrl_t c) -{ - return c->transport; -} - -const char *nvme_ctrl_get_traddr(nvme_ctrl_t c) -{ - return c->traddr; -} - -const char *nvme_ctrl_get_trsvcid(nvme_ctrl_t c) -{ - return c->trsvcid; -} - -const char *nvme_ctrl_get_host_traddr(nvme_ctrl_t c) -{ - return c->host_traddr; -} - -const char *nvme_ctrl_get_host_iface(nvme_ctrl_t c) -{ - return c->host_iface; -} - struct nvme_fabrics_config *nvme_ctrl_get_config(nvme_ctrl_t c) { return &c->cfg; @@ -1126,11 +965,6 @@ const char *nvme_ctrl_get_dhchap_host_key(nvme_ctrl_t c) return c->dhchap_key; } -const char *nvme_ctrl_get_cntlid(nvme_ctrl_t c) -{ - return c->cntlid; -} - void nvme_ctrl_set_dhchap_host_key(nvme_ctrl_t c, const char *key) { free(c->dhchap_key); @@ -1140,97 +974,21 @@ void nvme_ctrl_set_dhchap_host_key(nvme_ctrl_t c, const char *key) c->dhchap_key = strdup(key); } -const char *nvme_ctrl_get_dhchap_key(nvme_ctrl_t c) -{ - return c->dhchap_ctrl_key; -} - -void nvme_ctrl_set_dhchap_key(nvme_ctrl_t c, const char *key) -{ - free(c->dhchap_ctrl_key); - c->dhchap_ctrl_key = NULL; - - if (key) - c->dhchap_ctrl_key = strdup(key); -} - -const char *nvme_ctrl_get_keyring(nvme_ctrl_t c) -{ - return c->keyring; -} - -void nvme_ctrl_set_keyring(nvme_ctrl_t c, const char *keyring) -{ - free(c->keyring); - c->keyring = NULL; - - if (keyring) - c->keyring = strdup(keyring); -} - -const char *nvme_ctrl_get_tls_key_identity(nvme_ctrl_t c) -{ - return c->tls_key_identity; -} - -void nvme_ctrl_set_tls_key_identity(nvme_ctrl_t c, const char *identity) -{ - free(c->tls_key_identity); - c->tls_key_identity = NULL; - - if (identity) - c->tls_key_identity = strdup(identity); -} - -const char *nvme_ctrl_get_tls_key(nvme_ctrl_t c) -{ - return c->tls_key; -} - -void nvme_ctrl_set_tls_key(nvme_ctrl_t c, const char *key) -{ - free(c->tls_key); - c->tls_key = NULL; - - if (key) - c->tls_key = strdup(key); -} - -void nvme_ctrl_set_discovered(nvme_ctrl_t c, bool discovered) -{ - c->discovered = discovered; -} - bool nvme_ctrl_is_discovered(nvme_ctrl_t c) { return c->discovered; } -void nvme_ctrl_set_persistent(nvme_ctrl_t c, bool persistent) -{ - c->persistent = persistent; -} - bool nvme_ctrl_is_persistent(nvme_ctrl_t c) { return c->persistent; } -void nvme_ctrl_set_discovery_ctrl(nvme_ctrl_t c, bool discovery) -{ - c->discovery_ctrl = discovery; -} - bool nvme_ctrl_is_discovery_ctrl(nvme_ctrl_t c) { return c->discovery_ctrl; } -void nvme_ctrl_set_unique_discovery_ctrl(nvme_ctrl_t c, bool unique) -{ - c->unique_discovery_ctrl = unique; -} - bool nvme_ctrl_is_unique_discovery_ctrl(nvme_ctrl_t c) { return c->unique_discovery_ctrl; @@ -2328,26 +2086,11 @@ nvme_ctrl_t nvme_ns_get_ctrl(nvme_ns_t n) return n->c; } -int nvme_ns_get_nsid(nvme_ns_t n) -{ - return n->nsid; -} - -const char *nvme_ns_get_sysfs_dir(nvme_ns_t n) -{ - return n->sysfs_dir; -} - const char *nvme_ns_head_get_sysfs_dir(nvme_ns_head_t head) { return head->sysfs_dir; } -const char *nvme_ns_get_name(nvme_ns_t n) -{ - return n->name; -} - const char *nvme_ns_get_generic_name(nvme_ns_t n) { return n->generic_name; @@ -2368,26 +2111,6 @@ const char *nvme_ns_get_firmware(nvme_ns_t n) return n->c ? n->c->firmware : n->s->firmware; } -int nvme_ns_get_lba_size(nvme_ns_t n) -{ - return n->lba_size; -} - -int nvme_ns_get_meta_size(nvme_ns_t n) -{ - return n->meta_size; -} - -uint64_t nvme_ns_get_lba_count(nvme_ns_t n) -{ - return n->lba_count; -} - -uint64_t nvme_ns_get_lba_util(nvme_ns_t n) -{ - return n->lba_util; -} - enum nvme_csi nvme_ns_get_csi(nvme_ns_t n) { return n->csi; diff --git a/libnvme/src/nvme/tree.h b/libnvme/src/nvme/tree.h index dfc6f386ba..3ced214d1d 100644 --- a/libnvme/src/nvme/tree.h +++ b/libnvme/src/nvme/tree.h @@ -91,21 +91,6 @@ nvme_host_t nvme_next_host(struct nvme_global_ctx *ctx, nvme_host_t h); */ struct nvme_global_ctx *nvme_host_get_global_ctx(nvme_host_t h); -/** - * nvme_host_get_dhchap_key() - Return host key - * @h: Host for which the key should be returned - * - * Return: DH-HMAC-CHAP host key or NULL if not set - */ -const char *nvme_host_get_dhchap_key(nvme_host_t h); - -/** - * nvme_host_set_dhchap_key() - set host key - * @h: Host for which the key should be set - * @key: DH-HMAC-CHAP Key to set or NULL to clear existing key - */ -void nvme_host_set_dhchap_key(nvme_host_t h, const char *key); - /** * nvme_host_set_pdc_enabled() - Set Persistent Discovery Controller flag * @h: Host for which the falg should be set @@ -502,46 +487,6 @@ nvme_ns_t nvme_subsystem_next_ns(nvme_subsystem_t s, nvme_ns_t n); for (p = nvme_namespace_first_path(n); p != NULL; \ p = nvme_namespace_next_path(n, p)) -/** - * nvme_ns_get_nsid() - NSID of a namespace - * @n: Namespace instance - * - * Return: NSID of @n - */ -int nvme_ns_get_nsid(nvme_ns_t n); - -/** - * nvme_ns_get_lba_size() - LBA size of a namespace - * @n: Namespace instance - * - * Return: LBA size of @n - */ -int nvme_ns_get_lba_size(nvme_ns_t n); - -/** - * nvme_ns_get_meta_size() - Metadata size of a namespace - * @n: Namespace instance - * - * Return: Metadata size of @n - */ -int nvme_ns_get_meta_size(nvme_ns_t n); - -/** - * nvme_ns_get_lba_count() - LBA count of a namespace - * @n: Namespace instance - * - * Return: LBA count of @n - */ -uint64_t nvme_ns_get_lba_count(nvme_ns_t n); - -/** - * nvme_ns_get_lba_util() - LBA utilization of a namespace - * @n: Namespace instance - * - * Return: LBA utilization of @n - */ -uint64_t nvme_ns_get_lba_util(nvme_ns_t n); - /** * nvme_ns_get_csi() - Command set identifier of a namespace * @n: Namespace instance @@ -575,22 +520,6 @@ const uint8_t *nvme_ns_get_nguid(nvme_ns_t n); */ void nvme_ns_get_uuid(nvme_ns_t n, unsigned char out[NVME_UUID_LEN]); -/** - * nvme_ns_get_sysfs_dir() - sysfs directory of a namespace - * @n: Namespace instance - * - * Return: sysfs directory name of @n - */ -const char *nvme_ns_get_sysfs_dir(nvme_ns_t n); - -/** - * nvme_ns_get_name() - sysfs name of a namespace - * @n: Namespace instance - * - * Return: sysfs name of @n - */ -const char *nvme_ns_get_name(nvme_ns_t n); - /** * nvme_ns_get_generic_name() - Returns name of generic namespace chardev. * @n: Namespace instance @@ -742,38 +671,6 @@ int nvme_ns_identify(nvme_ns_t n, struct nvme_id_ns *ns); */ int nvme_ns_identify_descs(nvme_ns_t n, struct nvme_ns_id_desc *descs); -/** - * nvme_path_get_name() - sysfs name of an &nvme_path_t object - * @p: &nvme_path_t object - * - * Return: sysfs name of @p - */ -const char *nvme_path_get_name(nvme_path_t p); - -/** - * nvme_path_get_sysfs_dir() - sysfs directory of an nvme_path_t object - * @p: &nvme_path_t object - * - * Return: sysfs directory of @p - */ -const char *nvme_path_get_sysfs_dir(nvme_path_t p); - -/** - * nvme_path_get_ana_state() - ANA state of an nvme_path_t object - * @p: &nvme_path_t object - * - * Return: ANA (Asynchronous Namespace Access) state of @p - */ -const 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 associated to @p - */ -const char *nvme_path_get_numa_nodes(nvme_path_t p); - /** * nvme_path_get_queue_depth() - Queue depth of an nvme_path_t object * @p: &nvme_path_t object @@ -819,22 +716,6 @@ struct nvme_transport_handle *nvme_ctrl_get_transport_handle(nvme_ctrl_t c); */ void nvme_ctrl_release_transport_handle(nvme_ctrl_t c); -/** - * nvme_ctrl_get_name() - sysfs name of a controller - * @c: Controller instance - * - * Return: sysfs name of @c - */ -const char *nvme_ctrl_get_name(nvme_ctrl_t c); - -/** - * nvme_ctrl_get_sysfs_dir() - sysfs directory of a controller - * @c: Controller instance - * - * Return: sysfs directory name of @c - */ -const char *nvme_ctrl_get_sysfs_dir(nvme_ctrl_t c); - /** * nvme_ctrl_get_address() - Address string of a controller * @c: Controller instance @@ -863,22 +744,6 @@ char *nvme_ctrl_get_src_addr(nvme_ctrl_t c, char *src_addr, size_t src_addr_len) */ const char *nvme_ctrl_get_phy_slot(nvme_ctrl_t c); -/** - * nvme_ctrl_get_firmware() - Firmware string of a controller - * @c: Controller instance - * - * Return: Firmware string of @c - */ -const char *nvme_ctrl_get_firmware(nvme_ctrl_t c); - -/** - * nvme_ctrl_get_model() - Model of a controller - * @c: Controller instance - * - * Return: Model string of @c - */ -const char *nvme_ctrl_get_model(nvme_ctrl_t c); - /** * nvme_ctrl_get_state() - Running state of a controller * @c: Controller instance @@ -887,46 +752,6 @@ const char *nvme_ctrl_get_model(nvme_ctrl_t c); */ const char *nvme_ctrl_get_state(nvme_ctrl_t c); -/** - * nvme_ctrl_get_numa_node() - NUMA node of a controller - * @c: Controller instance - * - * Return: String indicating the NUMA node - */ -const char *nvme_ctrl_get_numa_node(nvme_ctrl_t c); - -/** - * nvme_ctrl_get_queue_count() - Queue count of a controller - * @c: Controller instance - * - * Return: Queue count of @c - */ -const char *nvme_ctrl_get_queue_count(nvme_ctrl_t c); - -/** - * nvme_ctrl_get_serial() - Serial number of a controller - * @c: Controller instance - * - * Return: Serial number string of @c - */ -const char *nvme_ctrl_get_serial(nvme_ctrl_t c); - -/** - * nvme_ctrl_get_sqsize() - SQ size of a controller - * @c: Controller instance - * - * Return: SQ size (as string) of @c - */ -const char *nvme_ctrl_get_sqsize(nvme_ctrl_t c); - -/** - * nvme_ctrl_get_transport() - Transport type of a controller - * @c: Controller instance - * - * Return: Transport type of @c - */ -const char *nvme_ctrl_get_transport(nvme_ctrl_t c); - /** * nvme_ctrl_get_subsysnqn() - Subsystem NQN of a controller * @c: Controller instance @@ -943,38 +768,6 @@ const char *nvme_ctrl_get_subsysnqn(nvme_ctrl_t c); */ nvme_subsystem_t nvme_ctrl_get_subsystem(nvme_ctrl_t c); -/** - * nvme_ctrl_get_traddr() - Transport address of a controller - * @c: Controller instance - * - * Return: Transport address of @c - */ -const char *nvme_ctrl_get_traddr(nvme_ctrl_t c); - -/** - * nvme_ctrl_get_trsvcid() - Transport service identifier of a controller - * @c: Controller instance - * - * Return: Transport service identifier of @c (if present) - */ -const char *nvme_ctrl_get_trsvcid(nvme_ctrl_t c); - -/** - * nvme_ctrl_get_host_traddr() - Host transport address of a controller - * @c: Controller instance - * - * Return: Host transport address of @c (if present) - */ -const char *nvme_ctrl_get_host_traddr(nvme_ctrl_t c); - -/** - * nvme_ctrl_get_host_iface() - Host interface name of a controller - * @c: Controller instance - * - * Return: Host interface name of @c (if present) - */ -const char *nvme_ctrl_get_host_iface(nvme_ctrl_t c); - /** * nvme_ctrl_get_dhchap_host_key() - Return host key * @c: Controller to be checked @@ -983,14 +776,6 @@ const char *nvme_ctrl_get_host_iface(nvme_ctrl_t c); */ const char *nvme_ctrl_get_dhchap_host_key(nvme_ctrl_t c); -/** - * nvme_ctrl_get_cntlid() - Controller id - * @c: Controller to be checked - * - * Return : Controller id of @c - */ -const char *nvme_ctrl_get_cntlid(nvme_ctrl_t c); - /** * nvme_ctrl_set_dhchap_host_key() - Set host key * @c: Host for which the key should be set @@ -998,14 +783,6 @@ const char *nvme_ctrl_get_cntlid(nvme_ctrl_t c); */ void nvme_ctrl_set_dhchap_host_key(nvme_ctrl_t c, const char *key); -/** - * nvme_ctrl_get_dhchap_key() - Return controller key - * @c: Controller for which the key should be set - * - * Return: DH-HMAC-CHAP controller key or NULL if not set - */ -const char *nvme_ctrl_get_dhchap_key(nvme_ctrl_t c); - /** * nvme_ns_head_get_sysfs_dir() - sysfs dir of namespave head * @head: namespace head instance @@ -1014,58 +791,6 @@ const char *nvme_ctrl_get_dhchap_key(nvme_ctrl_t c); */ const char *nvme_ns_head_get_sysfs_dir(nvme_ns_head_t head); -/** - * nvme_ctrl_set_dhchap_key() - Set controller key - * @c: Controller for which the key should be set - * @key: DH-HMAC-CHAP Key to set or NULL to clear existing key - */ -void nvme_ctrl_set_dhchap_key(nvme_ctrl_t c, const char *key); - -/** - * nvme_ctrl_get_keyring() - Return keyring - * @c: Controller to be used for the lookup - * - * Return: Keyring or NULL if not set - */ -const char *nvme_ctrl_get_keyring(nvme_ctrl_t c); - -/** - * nvme_ctrl_set_keyring() - Set keyring - * @c: Controller for which the keyring should be set - * @keyring: Keyring name - */ -void nvme_ctrl_set_keyring(nvme_ctrl_t c, const char *keyring); - -/** - * nvme_ctrl_get_tls_key_identity() - Return Derive TLS Identity - * @c: Controller to be used for the lookup - * - * Return: Derive TLS Identity or NULL if not set - */ -const char *nvme_ctrl_get_tls_key_identity(nvme_ctrl_t c); - -/** - * nvme_ctrl_set_tls_key_identity() - Set Derive TLS Identity - * @c: Controller for which the key should be set - * @identity: Derive TLS identity or NULL to clear existing key - */ -void nvme_ctrl_set_tls_key_identity(nvme_ctrl_t c, const char *identity); - -/** - * nvme_ctrl_get_tls_key() - Return Derive TLS PSK - * @c: Controller to be used for the lookup - * - * Return: Key in PSK interchange format or NULL if not set - */ -const char *nvme_ctrl_get_tls_key(nvme_ctrl_t c); - -/** - * nvme_ctrl_set_tls_key() - Set Derive TLS PSK - * @c: Controller for which the key should be set - * @key: Key in interchange format or NULL to clear existing key - */ -void nvme_ctrl_set_tls_key(nvme_ctrl_t c, const char *key); - /** * nvme_ctrl_get_config() - Fabrics configuration of a controller * @c: Controller instance @@ -1074,15 +799,6 @@ void nvme_ctrl_set_tls_key(nvme_ctrl_t c, const char *key); */ struct nvme_fabrics_config *nvme_ctrl_get_config(nvme_ctrl_t c); -/** - * nvme_ctrl_set_discovered() - Set the 'discovered' flag - * @c: nvme_ctrl_t object - * @discovered: Value of the 'discovered' flag - * - * Set the 'discovered' flag of @c to @discovered - */ -void nvme_ctrl_set_discovered(nvme_ctrl_t c, bool discovered); - /** * nvme_ctrl_is_discovered() - Returns the value of the 'discovered' flag * @c: Controller instance @@ -1091,15 +807,6 @@ void nvme_ctrl_set_discovered(nvme_ctrl_t c, bool discovered); */ bool nvme_ctrl_is_discovered(nvme_ctrl_t c); -/** - * nvme_ctrl_set_persistent() - Set the 'persistent' flag - * @c: Controller instance - * @persistent: value of the 'persistent' flag - * - * Set the 'persistent' flag of @c to @persistent - */ -void nvme_ctrl_set_persistent(nvme_ctrl_t c, bool persistent); - /** * nvme_ctrl_is_persistent() - Returns the value of the 'persistent' flag * @c: Controller instance @@ -1108,17 +815,6 @@ void nvme_ctrl_set_persistent(nvme_ctrl_t c, bool persistent); */ bool nvme_ctrl_is_persistent(nvme_ctrl_t c); -/** - * nvme_ctrl_set_discovery_ctrl() - Set the 'discovery_ctrl' flag - * @c: Controller to be modified - * @discovery: value of the discovery_ctrl flag - * - * Sets the 'discovery_ctrl' flag in @c to specify whether - * @c connects to a discovery subsystem. - * - */ -void nvme_ctrl_set_discovery_ctrl(nvme_ctrl_t c, bool discovery); - /** * nvme_ctrl_is_discovery_ctrl() - Check the 'discovery_ctrl' flag * @c: Controller to be checked @@ -1130,17 +826,6 @@ void nvme_ctrl_set_discovery_ctrl(nvme_ctrl_t c, bool discovery); */ bool nvme_ctrl_is_discovery_ctrl(nvme_ctrl_t c); -/** - * nvme_ctrl_set_unique_discovery_ctrl() - Set the 'unique_discovery_ctrl' flag - * @c: Controller to be modified - * @unique: value of the unique_disc_ctrl flag - * - * Sets the 'unique_discovery_ctrl' flag in @c to specify wheter - * @c is a unique discovery controller - * - */ -void nvme_ctrl_set_unique_discovery_ctrl(nvme_ctrl_t c, bool unique); - /** * nvme_ctrl_is_unique_discovery_ctrl() - Check the 'unique_discovery_ctrl' flag * @c: Controller to be checked @@ -1219,22 +904,6 @@ void nvme_unlink_ctrl(struct nvme_ctrl *c); */ const char *nvme_subsystem_get_nqn(nvme_subsystem_t s); -/** - * nvme_subsystem_get_sysfs_dir() - sysfs directory of an nvme_subsystem_t object - * @s: nvme_subsystem_t object - * - * Return: sysfs directory name of @s - */ -const char *nvme_subsystem_get_sysfs_dir(nvme_subsystem_t s); - -/** - * nvme_subsystem_get_name() - sysfs name of an nvme_subsystem_t object - * @s: nvme_subsystem_t object - * - * Return: sysfs name of @s - */ -const char *nvme_subsystem_get_name(nvme_subsystem_t s); - /** * nvme_subsystem_get_type() - Returns the type of a subsystem * @s: nvme_subsystem_t object @@ -1245,47 +914,6 @@ const char *nvme_subsystem_get_name(nvme_subsystem_t s); */ const char *nvme_subsystem_get_type(nvme_subsystem_t s); -/** - * nvme_subsystem_get_application() - Return the application string - * @s: nvme_subsystem_t object - * - * Return: Managing application string or NULL if not set. - */ -const char *nvme_subsystem_get_application(nvme_subsystem_t s); - -/** - * nvme_subsystem_set_application() - Set the application string - * @s: nvme_subsystem_t object - * @a: application string - * - * Sets the managing application string for @s. - */ -void nvme_subsystem_set_application(nvme_subsystem_t s, const char *a); - -/** - * nvme_subsystem_get_iopolicy() - Return the IO policy of subsytem - * @s: nvme_subsystem_t object - * - * Return: IO policy used by current subsystem - */ -const char *nvme_subsystem_get_iopolicy(nvme_subsystem_t s); - -/** - * nvme_subsystem_get_model() - Return the model of subsystem - * @s: nvme_subsystem_t object - * - * Return: Model of the current subsystem - */ -const char *nvme_subsystem_get_model(nvme_subsystem_t s); - -/** - * nvme_subsystem_get_serial() - Return the serial number of subsystem - * @s: nvme_subsystem_t object - * - * Return: Serial number of the current subsystem - */ -const char *nvme_subsystem_get_serial(nvme_subsystem_t s); - /** * nvme_subsystem_get_fw_rev() - Return the firmware rev of subsystem * @s: nvme_subsystem_t object @@ -1307,22 +935,6 @@ const char *nvme_subsystem_get_fw_rev(nvme_subsystem_t s); */ int nvme_scan_topology(struct nvme_global_ctx *ctx, nvme_scan_filter_t f, void *f_args); -/** - * nvme_host_get_hostnqn() - Host NQN of an nvme_host_t object - * @h: nvme_host_t object - * - * Return: Host NQN of @h - */ -const char *nvme_host_get_hostnqn(nvme_host_t h); - -/** - * nvme_host_get_hostid() - Host ID of an nvme_host_t object - * @h: nvme_host_t object - * - * Return: Host ID of @h - */ -const char *nvme_host_get_hostid(nvme_host_t h); - /** * nvme_host_release_fds() - Close all opened file descriptors under host * @h: nvme_host_t object @@ -1464,19 +1076,3 @@ char *nvme_get_path_attr(nvme_path_t p, const char *attr); */ int nvme_scan_namespace(struct nvme_global_ctx *ctx, const char *name, nvme_ns_t *ns); - -/** - * nvme_host_get_hostsymname() - Get the host's symbolic name - * @h: Host for which the symbolic name should be returned. - * - * Return: The symbolic name or NULL if a symbolic name hasn't been - * configure. - */ -const char *nvme_host_get_hostsymname(nvme_host_t h); - -/** - * nvme_host_set_hostsymname() - Set the host's symbolic name - * @h: Host for which the symbolic name should be set. - * @hostsymname: Symbolic name - */ -void nvme_host_set_hostsymname(nvme_host_t h, const char *hostsymname); diff --git a/libnvme/src/nvme/update-accessors.sh b/libnvme/src/nvme/update-accessors.sh new file mode 100755 index 0000000000..77287c21c6 --- /dev/null +++ b/libnvme/src/nvme/update-accessors.sh @@ -0,0 +1,113 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: LGPL-2.1-or-later +# +# update-accessors.sh - Regenerate accessor files only when they change. +# +# This file is part of libnvme. +# Copyright (c) 2025, Dell Technologies Inc. or its subsidiaries. +# Authors: Martin Belanger +# +# This script is invoked via: meson compile -C update-accessors +# It is NOT run during a normal build. +# +# accessors.h and accessors.c are updated automatically when the generator +# produces different output. +# +# accessors.ld is NOT updated automatically because its version section labels +# (e.g. LIBNVME_ACCESSORS_3_0) must be assigned by the maintainer. Instead, +# this script reports which symbols have been added or removed so the maintainer +# knows exactly what to change in accessors.ld. +# +# Arguments (supplied by the Meson run_target): +# $1 path to the compiled generate-accessors binary +# $2 source directory (where to write the files back) +# $3 path to generate-accessors-include.list +# $4 path to generate-accessors-exclude.list +# $5 ... one or more input headers (wildcards are accepted) + +set -euo pipefail + +GENERATOR="${1:?missing generator binary}" +SRCDIR="${2:?missing source directory}" +INCL_FILE="${3:?missing file generate-accessors-include.list}" +EXCL_FILE="${4:?missing file generate-accessors-exclude.list}" +shift 4 +INPUT_HEADERS=("$@") +[ ${#INPUT_HEADERS[@]} -gt 0 ] || { echo "error: no input headers specified" >&2; exit 1; } + +TMPDIR=$(mktemp -d) +trap 'rm -rf "$TMPDIR"' EXIT + +echo "Regenerating accessor files..." + +"$GENERATOR" \ + --h-out "$TMPDIR/accessors.h" \ + --c-out "$TMPDIR/accessors.c" \ + --ld-out "$TMPDIR/accessors.ld" \ + --incl "$INCL_FILE" \ + --excl "$EXCL_FILE" \ + "${INPUT_HEADERS[@]}" + +# --------------------------------------------------------------------------- +# Update accessors.h and accessors.c atomically when content changes. +# --------------------------------------------------------------------------- +changed=0 +for f in accessors.h accessors.c; do + dest="$SRCDIR/$f" + if [ -f "$dest" ] && cmp -s "$TMPDIR/$f" "$dest"; then + printf " unchanged: %s\n" "$f" + else + # Write to a sibling temp file then rename for atomicity + tmp_dest=$(mktemp "$SRCDIR/.${f}.XXXXXX") + cp "$TMPDIR/$f" "$tmp_dest" + mv -f "$tmp_dest" "$dest" + printf " updated: %s\n" "$f" + changed=$((changed + 1)) + fi +done + +echo "" +if [ "$changed" -gt 0 ]; then + printf "%d file(s) updated in %s\n" "$changed" "$SRCDIR" + echo "Don't forget to commit the updated files." +else + echo "All accessor source files are up to date." +fi + +# --------------------------------------------------------------------------- +# Compare symbol lists to detect accessors.ld drift. +# +# accessors.ld is manually maintained because its version section labels +# (e.g. LIBNVME_ACCESSORS_3_0) must be assigned by a human. We therefore +# only report what has changed; we never overwrite the file. +# +# Symbol lines in an ld version script look like: +# symbol_name ; +# --------------------------------------------------------------------------- +extract_syms() { + grep -E '^\s+[a-zA-Z_][a-zA-Z0-9_]*;' "$1" \ + | sed 's/[[:space:]]//g; s/;//' \ + | sort +} + +extract_syms "$TMPDIR/accessors.ld" > "$TMPDIR/syms_new.txt" +extract_syms "$SRCDIR/accessors.ld" > "$TMPDIR/syms_old.txt" + +added=$(comm -23 "$TMPDIR/syms_new.txt" "$TMPDIR/syms_old.txt") +removed=$(comm -13 "$TMPDIR/syms_new.txt" "$TMPDIR/syms_old.txt") + +if [ -z "$added" ] && [ -z "$removed" ]; then + echo "accessors.ld: symbol list is up to date." +else + echo "WARNING: accessors.ld needs manual attention." + echo "" + if [ -n "$added" ]; then + echo " Symbols to ADD (place in a new version section, e.g. LIBNVME_ACCESSORS_X_Y):" + printf '%s\n' "$added" | sed 's/^/ /' + fi + if [ -n "$removed" ]; then + echo "" + echo " Symbols to REMOVE from accessors.ld:" + printf '%s\n' "$removed" | sed 's/^/ /' + fi +fi diff --git a/libnvme/test/config/data/config-pcie-with-tcp-config.out b/libnvme/test/config/data/config-pcie-with-tcp-config.out index 6810f75462..981bd77c6a 100644 --- a/libnvme/test/config/data/config-pcie-with-tcp-config.out +++ b/libnvme/test/config/data/config-pcie-with-tcp-config.out @@ -10,13 +10,15 @@ "transport":"tcp", "traddr":"192.168.154.144", "trsvcid":"4420", - "dhchap_key":"none" + "dhchap_key":"none", + "dhchap_ctrl_key":"none" }, { "transport":"tcp", "traddr":"192.168.154.144", "trsvcid":"4421", - "dhchap_key":"none" + "dhchap_key":"none", + "dhchap_ctrl_key":"none" } ] } @@ -33,13 +35,15 @@ "transport":"tcp", "traddr":"192.168.154.144", "trsvcid":"4420", - "dhchap_key":"none" + "dhchap_key":"none", + "dhchap_ctrl_key":"none" }, { "transport":"tcp", "traddr":"192.168.154.144", "trsvcid":"4421", - "dhchap_key":"none" + "dhchap_key":"none", + "dhchap_ctrl_key":"none" } ] } diff --git a/libnvme/test/config/data/tls_key-1.out b/libnvme/test/config/data/tls_key-1.out index 5bba948d97..3edd1730e8 100644 --- a/libnvme/test/config/data/tls_key-1.out +++ b/libnvme/test/config/data/tls_key-1.out @@ -11,6 +11,7 @@ "traddr":"192.168.154.148", "trsvcid":"4420", "dhchap_key":"none", + "dhchap_ctrl_key":"none", "tls":true, "tls_key":"NVMeTLSkey-1:01:Hhc5sFjwSZ6w5hPY19tqprajYtuYci3tN+Z2wGViDk3rpSR+:" } diff --git a/libnvme/test/config/data/tls_key-2.out b/libnvme/test/config/data/tls_key-2.out index 5bba948d97..3edd1730e8 100644 --- a/libnvme/test/config/data/tls_key-2.out +++ b/libnvme/test/config/data/tls_key-2.out @@ -11,6 +11,7 @@ "traddr":"192.168.154.148", "trsvcid":"4420", "dhchap_key":"none", + "dhchap_ctrl_key":"none", "tls":true, "tls_key":"NVMeTLSkey-1:01:Hhc5sFjwSZ6w5hPY19tqprajYtuYci3tN+Z2wGViDk3rpSR+:" }