From 198598f08402394a3e47c4673d7fe5e187170f4f Mon Sep 17 00:00:00 2001 From: Martin Belanger Date: Tue, 17 Mar 2026 14:53:45 -0400 Subject: [PATCH] libnvme: enforce ABI boundary with -fvisibility=hidden Add -fvisibility=hidden to the libnvme library build and introduce a LIBNVME_PUBLIC macro (defined as __attribute__((visibility("default"))) in lib-types.h) to explicitly mark each exported function definition. With this change the compiler enforces the ABI boundary rather than relying solely on the linker version scripts (libnvme.ld, libnvmf.ld, accessors.ld). The immediate benefits are: - Any function accidentally omitted from the version script but lacking LIBNVME_PUBLIC will be hidden at compile time, making the omission visible as a link error rather than a silent symbol leak. - nm -D on the installed .so gives an authoritative, minimal symbol list suitable for CI checks and abidiff. The annotation is placed on function *definitions* in the .c files only. Installed public headers are left unannotated so that third-party code that includes them is not exposed to a build-internal attribute. The generate-accessors tool is updated to emit LIBNVME_PUBLIC on the generated function definitions in accessors.c. While auditing the version scripts, 34 stale symbol entries that had no corresponding definition in the source tree were removed from libnvme.ld and libnvmf.ld. Signed-off-by: Martin Belanger --- libnvme/src/libnvme.ld | 11 - libnvme/src/libnvmf.ld | 26 -- libnvme/src/meson.build | 1 + libnvme/src/nvme/accessors.c | 443 ++++++++++++------- libnvme/src/nvme/cmds.c | 89 ++-- libnvme/src/nvme/fabrics.c | 156 ++++--- libnvme/src/nvme/filters.c | 22 +- libnvme/src/nvme/ioctl.c | 14 +- libnvme/src/nvme/lib-types.h | 9 + libnvme/src/nvme/lib.c | 58 ++- libnvme/src/nvme/lib.h | 11 - libnvme/src/nvme/linux.c | 123 +++-- libnvme/src/nvme/log.c | 10 +- libnvme/src/nvme/mi-mctp.c | 10 +- libnvme/src/nvme/mi.c | 127 ++++-- libnvme/src/nvme/mi.h | 2 - libnvme/src/nvme/nbft.c | 8 +- libnvme/src/nvme/tree.c | 215 +++++---- libnvme/src/nvme/tree.h | 11 - libnvme/src/nvme/util.c | 25 +- libnvme/test/meson.build | 12 + libnvme/tools/check-public-symbols.py | 95 ++++ libnvme/tools/generator/generate-accessors.c | 32 +- 23 files changed, 962 insertions(+), 548 deletions(-) create mode 100644 libnvme/tools/check-public-symbols.py diff --git a/libnvme/src/libnvme.ld b/libnvme/src/libnvme.ld index 24fccbcd3c..6d5d7a0f9b 100644 --- a/libnvme/src/libnvme.ld +++ b/libnvme/src/libnvme.ld @@ -56,7 +56,6 @@ LIBNVME_3 { nvme_get_ns_attr; nvme_get_nsid; nvme_get_path_attr; - nvme_get_property; nvme_get_subsys_attr; nvme_get_telemetry_log; nvme_get_telemetry_max; @@ -89,13 +88,11 @@ LIBNVME_3 { nvme_mi_aem_get_next_event; nvme_mi_aem_process; nvme_mi_close; - nvme_mi_close_transport_handle; nvme_mi_control; nvme_mi_ctrl_id; nvme_mi_endpoint_desc; nvme_mi_ep_get_timeout; nvme_mi_ep_set_timeout; - nvme_mi_first_ctrl; nvme_mi_first_endpoint; nvme_mi_init_transport_handle; nvme_mi_mi_config_get; @@ -106,7 +103,6 @@ LIBNVME_3 { nvme_mi_mi_read_mi_data_subsys; nvme_mi_mi_subsystem_health_status_poll; nvme_mi_mi_xfer; - nvme_mi_next_ctrl; nvme_mi_next_endpoint; nvme_mi_open_mctp; nvme_mi_scan_ep; @@ -115,8 +111,6 @@ LIBNVME_3 { nvme_mi_status_to_string; nvme_mi_submit_entry; nvme_mi_submit_exit; - nvme_namespace_attach_ctrls; - nvme_namespace_detach_ctrls; nvme_filter_namespace; nvme_namespace_first_path; nvme_namespace_next_path; @@ -124,7 +118,6 @@ LIBNVME_3 { nvme_read_nbft; nvme_next_host; nvme_next_subsystem; - nvme_ns_attach; nvme_ns_compare; nvme_ns_flush; nvme_ns_get_csi; @@ -153,7 +146,6 @@ LIBNVME_3 { nvme_read_config; nvme_read_key; nvme_refresh_topology; - nvme_release_fds; nvme_rescan_ctrl; nvme_revoke_tls_key; nvme_scan_ctrl; @@ -171,9 +163,6 @@ LIBNVME_3 { nvme_set_ioctl_probing; nvme_set_keyring; nvme_set_logging_level; - nvme_set_probe_enabled; - nvme_set_property; - nvme_set_root; nvme_skip_namespaces; nvme_status_to_errno; nvme_status_to_string; diff --git a/libnvme/src/libnvmf.ld b/libnvme/src/libnvmf.ld index 976f300be5..806490b064 100644 --- a/libnvme/src/libnvmf.ld +++ b/libnvme/src/libnvmf.ld @@ -22,32 +22,6 @@ LIBNVMF_3 { nvmf_discovery; nvmf_discovery_config_file; nvmf_discovery_config_json; - nvmf_discovery_ctx_already_connected_set; - nvmf_discovery_ctx_connected_set; - nvmf_discovery_ctx_create; - nvmf_discovery_ctx_ctrlkey_set; - nvmf_discovery_ctx_decide_retry_set; - nvmf_discovery_ctx_default_fabrics_config_set; - nvmf_discovery_ctx_device_set; - nvmf_discovery_ctx_discovery_log_set; - nvmf_discovery_ctx_host_iface_set; - nvmf_discovery_ctx_host_traddr_set; - nvmf_discovery_ctx_hostid_set; - nvmf_discovery_ctx_hostkey_set; - nvmf_discovery_ctx_hostnqn_set; - nvmf_discovery_ctx_keep_alive_timeout; - nvmf_discovery_ctx_keyring_set; - nvmf_discovery_ctx_max_retries; - nvmf_discovery_ctx_parser_cleanup_set; - nvmf_discovery_ctx_parser_init_set; - nvmf_discovery_ctx_parser_next_line_set; - nvmf_discovery_ctx_persistent_set; - nvmf_discovery_ctx_subsysnqn_set; - nvmf_discovery_ctx_tls_key_identity_set; - nvmf_discovery_ctx_tls_key_set; - nvmf_discovery_ctx_traddr_set; - nvmf_discovery_ctx_transport_set; - nvmf_discovery_ctx_trsvcid_set; nvmf_discovery_nbft; nvmf_eflags_str; nvmf_exat_ptr_next; diff --git a/libnvme/src/meson.build b/libnvme/src/meson.build index 1fcd1aa533..53732077f5 100644 --- a/libnvme/src/meson.build +++ b/libnvme/src/meson.build @@ -96,6 +96,7 @@ libnvme = library( 'nvme', # produces libnvme.so sources, version: libnvme_so_version, + c_args: ['-fvisibility=hidden'], link_args: link_args, dependencies: deps, install: true, diff --git a/libnvme/src/nvme/accessors.c b/libnvme/src/nvme/accessors.c index ca22a4ce3a..1f0271155c 100644 --- a/libnvme/src/nvme/accessors.c +++ b/libnvme/src/nvme/accessors.c @@ -27,56 +27,62 @@ * Accessors for: struct nvme_path ****************************************************************************/ -void nvme_path_set_name(struct nvme_path *p, const char *name) +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC void nvme_path_set_numa_nodes( + struct nvme_path *p, + const char *numa_nodes) { free(p->numa_nodes); p->numa_nodes = numa_nodes ? strdup(numa_nodes) : NULL; } -const char *nvme_path_get_numa_nodes(const struct nvme_path *p) +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC void nvme_path_set_grpid(struct nvme_path *p, int grpid) { p->grpid = grpid; } -int nvme_path_get_grpid(const struct nvme_path *p) +LIBNVME_PUBLIC int nvme_path_get_grpid(const struct nvme_path *p) { return p->grpid; } @@ -85,84 +91,86 @@ int nvme_path_get_grpid(const struct nvme_path *p) * Accessors for: struct nvme_ns ****************************************************************************/ -void nvme_ns_set_nsid(struct nvme_ns *p, __u32 nsid) +LIBNVME_PUBLIC void nvme_ns_set_nsid(struct nvme_ns *p, __u32 nsid) { p->nsid = nsid; } -__u32 nvme_ns_get_nsid(const struct nvme_ns *p) +LIBNVME_PUBLIC __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) +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC uint64_t nvme_ns_get_lba_util(const struct nvme_ns *p) { return p->lba_util; } @@ -171,128 +179,146 @@ uint64_t nvme_ns_get_lba_util(const struct nvme_ns *p) * Accessors for: struct nvme_ctrl ****************************************************************************/ -void nvme_ctrl_set_name(struct nvme_ctrl *p, const char *name) +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC const char *nvme_ctrl_get_trsvcid(const struct nvme_ctrl *p) { return p->trsvcid; } -void nvme_ctrl_set_dhchap_host_key( +LIBNVME_PUBLIC void nvme_ctrl_set_dhchap_host_key( struct nvme_ctrl *p, const char *dhchap_host_key) { @@ -300,12 +326,13 @@ void nvme_ctrl_set_dhchap_host_key( p->dhchap_host_key = dhchap_host_key ? strdup(dhchap_host_key) : NULL; } -const char *nvme_ctrl_get_dhchap_host_key(const struct nvme_ctrl *p) +LIBNVME_PUBLIC const char *nvme_ctrl_get_dhchap_host_key( + const struct nvme_ctrl *p) { return p->dhchap_host_key; } -void nvme_ctrl_set_dhchap_ctrl_key( +LIBNVME_PUBLIC void nvme_ctrl_set_dhchap_ctrl_key( struct nvme_ctrl *p, const char *dhchap_ctrl_key) { @@ -313,23 +340,26 @@ void nvme_ctrl_set_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) +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC const char *nvme_ctrl_get_keyring(const struct nvme_ctrl *p) { return p->keyring; } -void nvme_ctrl_set_tls_key_identity( +LIBNVME_PUBLIC void nvme_ctrl_set_tls_key_identity( struct nvme_ctrl *p, const char *tls_key_identity) { @@ -338,115 +368,135 @@ void nvme_ctrl_set_tls_key_identity( tls_key_identity ? strdup(tls_key_identity) : NULL; } -const char *nvme_ctrl_get_tls_key_identity(const struct nvme_ctrl *p) +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC bool nvme_ctrl_get_discovery_ctrl(const struct nvme_ctrl *p) { return p->discovery_ctrl; } -void nvme_ctrl_set_unique_discovery_ctrl( +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC void nvme_ctrl_set_discovered( + struct nvme_ctrl *p, + bool discovered) { p->discovered = discovered; } -bool nvme_ctrl_get_discovered(const struct nvme_ctrl *p) +LIBNVME_PUBLIC bool nvme_ctrl_get_discovered(const struct nvme_ctrl *p) { return p->discovered; } -void nvme_ctrl_set_persistent(struct nvme_ctrl *p, bool persistent) +LIBNVME_PUBLIC void nvme_ctrl_set_persistent( + struct nvme_ctrl *p, + bool persistent) { p->persistent = persistent; } -bool nvme_ctrl_get_persistent(const struct nvme_ctrl *p) +LIBNVME_PUBLIC bool nvme_ctrl_get_persistent(const struct nvme_ctrl *p) { return p->persistent; } @@ -455,18 +505,21 @@ bool nvme_ctrl_get_persistent(const struct nvme_ctrl *p) * Accessors for: struct nvme_subsystem ****************************************************************************/ -void nvme_subsystem_set_name(struct nvme_subsystem *p, const char *name) +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC const char *nvme_subsystem_get_name( + const struct nvme_subsystem *p) { return p->name; } -void nvme_subsystem_set_sysfs_dir( +LIBNVME_PUBLIC void nvme_subsystem_set_sysfs_dir( struct nvme_subsystem *p, const char *sysfs_dir) { @@ -474,12 +527,13 @@ void nvme_subsystem_set_sysfs_dir( p->sysfs_dir = sysfs_dir ? strdup(sysfs_dir) : NULL; } -const char *nvme_subsystem_get_sysfs_dir(const struct nvme_subsystem *p) +LIBNVME_PUBLIC const char *nvme_subsystem_get_sysfs_dir( + const struct nvme_subsystem *p) { return p->sysfs_dir; } -void nvme_subsystem_set_subsysnqn( +LIBNVME_PUBLIC void nvme_subsystem_set_subsysnqn( struct nvme_subsystem *p, const char *subsysnqn) { @@ -487,45 +541,55 @@ void nvme_subsystem_set_subsysnqn( p->subsysnqn = subsysnqn ? strdup(subsysnqn) : NULL; } -const char *nvme_subsystem_get_subsysnqn(const struct nvme_subsystem *p) +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC const char *nvme_subsystem_get_firmware( + const struct nvme_subsystem *p) { return p->firmware; } -void nvme_subsystem_set_subsystype( +LIBNVME_PUBLIC void nvme_subsystem_set_subsystype( struct nvme_subsystem *p, const char *subsystype) { @@ -533,12 +597,13 @@ void nvme_subsystem_set_subsystype( p->subsystype = subsystype ? strdup(subsystype) : NULL; } -const char *nvme_subsystem_get_subsystype(const struct nvme_subsystem *p) +LIBNVME_PUBLIC const char *nvme_subsystem_get_subsystype( + const struct nvme_subsystem *p) { return p->subsystype; } -void nvme_subsystem_set_application( +LIBNVME_PUBLIC void nvme_subsystem_set_application( struct nvme_subsystem *p, const char *application) { @@ -546,18 +611,22 @@ void nvme_subsystem_set_application( p->application = application ? strdup(application) : NULL; } -const char *nvme_subsystem_get_application(const struct nvme_subsystem *p) +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC const char *nvme_subsystem_get_iopolicy( + const struct nvme_subsystem *p) { return p->iopolicy; } @@ -566,29 +635,33 @@ const char *nvme_subsystem_get_iopolicy(const struct nvme_subsystem *p) * Accessors for: struct nvme_host ****************************************************************************/ -void nvme_host_set_hostnqn(struct nvme_host *p, const char *hostnqn) +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC const char *nvme_host_get_hostid(const struct nvme_host *p) { return p->hostid; } -void nvme_host_set_dhchap_host_key( +LIBNVME_PUBLIC void nvme_host_set_dhchap_host_key( struct nvme_host *p, const char *dhchap_host_key) { @@ -596,30 +669,33 @@ void nvme_host_set_dhchap_host_key( p->dhchap_host_key = dhchap_host_key ? strdup(dhchap_host_key) : NULL; } -const char *nvme_host_get_dhchap_host_key(const struct nvme_host *p) +LIBNVME_PUBLIC const char *nvme_host_get_dhchap_host_key( + const struct nvme_host *p) { return p->dhchap_host_key; } -void nvme_host_set_hostsymname(struct nvme_host *p, const char *hostsymname) +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC const char *nvme_host_get_hostsymname(const struct nvme_host *p) { return p->hostsymname; } -void nvme_host_set_pdc_enabled_valid( +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC bool nvme_host_get_pdc_enabled_valid(const struct nvme_host *p) { return p->pdc_enabled_valid; } @@ -628,353 +704,392 @@ bool nvme_host_get_pdc_enabled_valid(const struct nvme_host *p) * Accessors for: struct nvme_fabric_options ****************************************************************************/ -void nvme_fabric_options_set_cntlid(struct nvme_fabric_options *p, bool cntlid) +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC bool nvme_fabric_options_get_concat( + const struct nvme_fabric_options *p) { return p->concat; } -void nvme_fabric_options_set_ctrl_loss_tmo( +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC 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( +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC 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( +LIBNVME_PUBLIC 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( +LIBNVME_PUBLIC 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( +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC bool nvme_fabric_options_get_dhchap_secret( + const struct nvme_fabric_options *p) { return p->dhchap_secret; } -void nvme_fabric_options_set_disable_sqflow( +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC bool nvme_fabric_options_get_disable_sqflow( + const struct nvme_fabric_options *p) { return p->disable_sqflow; } -void nvme_fabric_options_set_discovery( +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC bool nvme_fabric_options_get_discovery( + const struct nvme_fabric_options *p) { return p->discovery; } -void nvme_fabric_options_set_duplicate_connect( +LIBNVME_PUBLIC 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( +LIBNVME_PUBLIC 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( +LIBNVME_PUBLIC 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( +LIBNVME_PUBLIC 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( +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC bool nvme_fabric_options_get_hdr_digest( + const struct nvme_fabric_options *p) { return p->hdr_digest; } -void nvme_fabric_options_set_host_iface( +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC bool nvme_fabric_options_get_host_iface( + const struct nvme_fabric_options *p) { return p->host_iface; } -void nvme_fabric_options_set_host_traddr( +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC bool nvme_fabric_options_get_hostid( + const struct nvme_fabric_options *p) { return p->hostid; } -void nvme_fabric_options_set_hostnqn( +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC bool nvme_fabric_options_get_hostnqn( + const struct nvme_fabric_options *p) { return p->hostnqn; } -void nvme_fabric_options_set_instance( +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC bool nvme_fabric_options_get_instance( + const struct nvme_fabric_options *p) { return p->instance; } -void nvme_fabric_options_set_keep_alive_tmo( +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC 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( +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC bool nvme_fabric_options_get_nqn( + const struct nvme_fabric_options *p) { return p->nqn; } -void nvme_fabric_options_set_nr_io_queues( +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC 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( +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC 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( +LIBNVME_PUBLIC 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( +LIBNVME_PUBLIC 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( +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC bool nvme_fabric_options_get_queue_size( + const struct nvme_fabric_options *p) { return p->queue_size; } -void nvme_fabric_options_set_reconnect_delay( +LIBNVME_PUBLIC 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( +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC bool nvme_fabric_options_get_tls( + const struct nvme_fabric_options *p) { return p->tls; } -void nvme_fabric_options_set_tls_key( +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC bool nvme_fabric_options_get_traddr( + const struct nvme_fabric_options *p) { return p->traddr; } -void nvme_fabric_options_set_transport( +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC bool nvme_fabric_options_get_transport( + const struct nvme_fabric_options *p) { return p->transport; } -void nvme_fabric_options_set_trsvcid( +LIBNVME_PUBLIC 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) +LIBNVME_PUBLIC bool nvme_fabric_options_get_trsvcid( + const struct nvme_fabric_options *p) { return p->trsvcid; } diff --git a/libnvme/src/nvme/cmds.c b/libnvme/src/nvme/cmds.c index 3ef8523bfb..17caba2fca 100644 --- a/libnvme/src/nvme/cmds.c +++ b/libnvme/src/nvme/cmds.c @@ -31,8 +31,10 @@ static void nvme_init_env(void) force_4k = true; } -int nvme_get_log(struct nvme_transport_handle *hdl, - struct nvme_passthru_cmd *cmd, bool rae, +LIBNVME_PUBLIC int nvme_get_log( + struct nvme_transport_handle *hdl, + struct nvme_passthru_cmd *cmd, + bool rae, __u32 xfer_len) { __u64 offset = 0, xfer, data_len = cmd->data_len; @@ -175,8 +177,12 @@ static int try_read_ana(struct nvme_transport_handle *hdl, return 0; } -int nvme_get_ana_log_atomic(struct nvme_transport_handle *hdl, - bool rae, bool rgo, struct nvme_ana_log *log, __u32 *len, +LIBNVME_PUBLIC int nvme_get_ana_log_atomic( + struct nvme_transport_handle *hdl, + bool rae, + bool rgo, + struct nvme_ana_log *log, + __u32 *len, unsigned int retries) { const enum nvme_log_ana_lsp lsp = @@ -231,7 +237,9 @@ int nvme_get_ana_log_atomic(struct nvme_transport_handle *hdl, return -EAGAIN; } -int nvme_set_etdas(struct nvme_transport_handle *hdl, bool *changed) +LIBNVME_PUBLIC int nvme_set_etdas( + struct nvme_transport_handle *hdl, + bool *changed) { struct nvme_feat_host_behavior da4; struct nvme_passthru_cmd cmd; @@ -258,7 +266,9 @@ int nvme_set_etdas(struct nvme_transport_handle *hdl, bool *changed) return 0; } -int nvme_clear_etdas(struct nvme_transport_handle *hdl, bool *changed) +LIBNVME_PUBLIC int nvme_clear_etdas( + struct nvme_transport_handle *hdl, + bool *changed) { struct nvme_feat_host_behavior da4; struct nvme_passthru_cmd cmd; @@ -284,7 +294,8 @@ int nvme_clear_etdas(struct nvme_transport_handle *hdl, bool *changed) return 0; } -int nvme_get_uuid_list(struct nvme_transport_handle *hdl, +LIBNVME_PUBLIC int nvme_get_uuid_list( + struct nvme_transport_handle *hdl, struct nvme_id_uuid_list *uuid_list) { struct nvme_passthru_cmd cmd; @@ -309,8 +320,10 @@ int nvme_get_uuid_list(struct nvme_transport_handle *hdl, return err; } -int nvme_get_telemetry_max(struct nvme_transport_handle *hdl, - enum nvme_telemetry_da *da, size_t *data_tx) +LIBNVME_PUBLIC int nvme_get_telemetry_max( + struct nvme_transport_handle *hdl, + enum nvme_telemetry_da *da, + size_t *data_tx) { _cleanup_free_ struct nvme_id_ctrl *id_ctrl = NULL; struct nvme_passthru_cmd cmd; @@ -345,9 +358,14 @@ int nvme_get_telemetry_max(struct nvme_transport_handle *hdl, return err; } -int nvme_get_telemetry_log(struct nvme_transport_handle *hdl, bool create, - bool ctrl, bool rae, size_t max_data_tx, - enum nvme_telemetry_da da, struct nvme_telemetry_log **buf, +LIBNVME_PUBLIC int nvme_get_telemetry_log( + struct nvme_transport_handle *hdl, + bool create, + bool ctrl, + bool rae, + size_t max_data_tx, + enum nvme_telemetry_da da, + struct nvme_telemetry_log **buf, size_t *size) { static const __u32 xfer = NVME_LOG_TELEM_BLOCK_SIZE; @@ -449,25 +467,32 @@ static int nvme_check_get_telemetry_log(struct nvme_transport_handle *hdl, } -int nvme_get_ctrl_telemetry(struct nvme_transport_handle *hdl, bool rae, +LIBNVME_PUBLIC int nvme_get_ctrl_telemetry( + struct nvme_transport_handle *hdl, + bool rae, struct nvme_telemetry_log **log, - enum nvme_telemetry_da da, size_t *size) + enum nvme_telemetry_da da, + size_t *size) { return nvme_check_get_telemetry_log(hdl, false, true, rae, log, da, size); } -int nvme_get_host_telemetry(struct nvme_transport_handle *hdl, +LIBNVME_PUBLIC int nvme_get_host_telemetry( + struct nvme_transport_handle *hdl, struct nvme_telemetry_log **log, - enum nvme_telemetry_da da, size_t *size) + enum nvme_telemetry_da da, + size_t *size) { return nvme_check_get_telemetry_log(hdl, false, false, false, log, da, size); } -int nvme_get_new_host_telemetry(struct nvme_transport_handle *hdl, +LIBNVME_PUBLIC int nvme_get_new_host_telemetry( + struct nvme_transport_handle *hdl, struct nvme_telemetry_log **log, - enum nvme_telemetry_da da, size_t *size) + enum nvme_telemetry_da da, + size_t *size) { return nvme_check_get_telemetry_log(hdl, true, false, false, log, da, size); @@ -519,8 +544,9 @@ int nvme_get_lba_status_log(struct nvme_transport_handle *hdl, bool rae, return 0; } -size_t nvme_get_ana_log_len_from_id_ctrl(const struct nvme_id_ctrl *id_ctrl, - bool rgo) +LIBNVME_PUBLIC size_t nvme_get_ana_log_len_from_id_ctrl( + const struct nvme_id_ctrl *id_ctrl, + bool rgo) { __u32 nanagrpid = le32_to_cpu(id_ctrl->nanagrpid); size_t size = sizeof(struct nvme_ana_log) + @@ -529,7 +555,9 @@ size_t nvme_get_ana_log_len_from_id_ctrl(const struct nvme_id_ctrl *id_ctrl, return rgo ? size : size + le32_to_cpu(id_ctrl->mnan) * sizeof(__le32); } -int nvme_get_ana_log_len(struct nvme_transport_handle *hdl, size_t *analen) +LIBNVME_PUBLIC int nvme_get_ana_log_len( + struct nvme_transport_handle *hdl, + size_t *analen) { _cleanup_free_ struct nvme_id_ctrl *ctrl = NULL; struct nvme_passthru_cmd cmd; @@ -548,8 +576,10 @@ int nvme_get_ana_log_len(struct nvme_transport_handle *hdl, size_t *analen) return 0; } -int nvme_get_logical_block_size(struct nvme_transport_handle *hdl, - __u32 nsid, int *blksize) +LIBNVME_PUBLIC int nvme_get_logical_block_size( + struct nvme_transport_handle *hdl, + __u32 nsid, + int *blksize) { _cleanup_free_ struct nvme_id_ns *ns = NULL; struct nvme_passthru_cmd cmd; @@ -571,8 +601,11 @@ int nvme_get_logical_block_size(struct nvme_transport_handle *hdl, return 0; } -int nvme_get_feature_length(int fid, __u32 cdw11, enum nvme_data_tfr dir, - __u32 *len) +LIBNVME_PUBLIC int nvme_get_feature_length( + int fid, + __u32 cdw11, + enum nvme_data_tfr dir, + __u32 *len) { switch (fid) { case NVME_FEAT_FID_LBA_RANGE: @@ -644,8 +677,10 @@ int nvme_get_feature_length(int fid, __u32 cdw11, enum nvme_data_tfr dir, return 0; } -int nvme_get_directive_receive_length(enum nvme_directive_dtype dtype, - enum nvme_directive_receive_doper doper, __u32 *len) +LIBNVME_PUBLIC int nvme_get_directive_receive_length( + enum nvme_directive_dtype dtype, + enum nvme_directive_receive_doper doper, + __u32 *len) { switch (dtype) { case NVME_DIRECTIVE_DTYPE_IDENTIFY: diff --git a/libnvme/src/nvme/fabrics.c b/libnvme/src/nvme/fabrics.c index c659b23ff6..363113ea5c 100644 --- a/libnvme/src/nvme/fabrics.c +++ b/libnvme/src/nvme/fabrics.c @@ -68,7 +68,7 @@ const char * const trtypes[] = { [NVMF_TRTYPE_LOOP] = "loop", }; -const char *nvmf_trtype_str(__u8 trtype) +LIBNVME_PUBLIC const char *nvmf_trtype_str(__u8 trtype) { return arg_str(trtypes, ARRAY_SIZE(trtypes), trtype); } @@ -81,7 +81,7 @@ static const char * const adrfams[] = { [NVMF_ADDR_FAMILY_FC] = "fibre-channel", }; -const char *nvmf_adrfam_str(__u8 adrfam) +LIBNVME_PUBLIC const char *nvmf_adrfam_str(__u8 adrfam) { return arg_str(adrfams, ARRAY_SIZE(adrfams), adrfam); } @@ -92,7 +92,7 @@ static const char * const subtypes[] = { [NVME_NQN_CURR] = "current discovery subsystem", }; -const char *nvmf_subtype_str(__u8 subtype) +LIBNVME_PUBLIC const char *nvmf_subtype_str(__u8 subtype) { return arg_str(subtypes, ARRAY_SIZE(subtypes), subtype); } @@ -112,7 +112,7 @@ static const char * const treqs[] = { "sq flow control disable supported", }; -const char *nvmf_treq_str(__u8 treq) +LIBNVME_PUBLIC const char *nvmf_treq_str(__u8 treq) { return arg_str(treqs, ARRAY_SIZE(treqs), treq); } @@ -138,7 +138,7 @@ static const char * const eflags_strings[] = { "no cdc connectivity", }; -const char *nvmf_eflags_str(__u16 eflags) +LIBNVME_PUBLIC const char *nvmf_eflags_str(__u16 eflags) { return arg_str(eflags_strings, ARRAY_SIZE(eflags_strings), eflags); } @@ -149,7 +149,7 @@ static const char * const sectypes[] = { [NVMF_TCP_SECTYPE_TLS13] = "tls13", }; -const char *nvmf_sectype_str(__u8 sectype) +LIBNVME_PUBLIC const char *nvmf_sectype_str(__u8 sectype) { return arg_str(sectypes, ARRAY_SIZE(sectypes), sectype); } @@ -162,7 +162,7 @@ static const char * const prtypes[] = { [NVMF_RDMA_PRTYPE_IWARP] = "iwarp", }; -const char *nvmf_prtype_str(__u8 prtype) +LIBNVME_PUBLIC const char *nvmf_prtype_str(__u8 prtype) { return arg_str(prtypes, ARRAY_SIZE(prtypes), prtype); } @@ -172,7 +172,7 @@ static const char * const qptypes[] = { [NVMF_RDMA_QPTYPE_DATAGRAM] = "datagram", }; -const char *nvmf_qptype_str(__u8 qptype) +LIBNVME_PUBLIC const char *nvmf_qptype_str(__u8 qptype) { return arg_str(qptypes, ARRAY_SIZE(qptypes), qptype); } @@ -181,12 +181,13 @@ static const char * const cms[] = { [NVMF_RDMA_CMS_RDMA_CM] = "rdma-cm", }; -const char *nvmf_cms_str(__u8 cm) +LIBNVME_PUBLIC const char *nvmf_cms_str(__u8 cm) { return arg_str(cms, ARRAY_SIZE(cms), cm); } -int nvmf_context_create(struct nvme_global_ctx *ctx, +LIBNVME_PUBLIC int nvmf_context_create( + struct nvme_global_ctx *ctx, bool (*decide_retry)(struct nvmf_context *fctx, int err, void *user_data), void (*connected)(struct nvmf_context *fctx, @@ -195,7 +196,8 @@ int nvmf_context_create(struct nvme_global_ctx *ctx, struct nvme_host *host, const char *subsysnqn, const char *transport, const char *traddr, const char *trsvcid, void *user_data), - void *user_data, struct nvmf_context **fctxp) + void *user_data, + struct nvmf_context **fctxp) { struct nvmf_context *fctx; @@ -213,7 +215,8 @@ int nvmf_context_create(struct nvme_global_ctx *ctx, return 0; } -int nvmf_context_set_discovery_cbs(struct nvmf_context *fctx, +LIBNVME_PUBLIC int nvmf_context_set_discovery_cbs( + struct nvmf_context *fctx, void (*discovery_log)(struct nvmf_context *fctx, bool connect, struct nvmf_discovery_log *log, @@ -233,8 +236,10 @@ int nvmf_context_set_discovery_cbs(struct nvmf_context *fctx, return 0; } -int nvmf_context_set_discovery_defaults(struct nvmf_context *fctx, - int max_discovery_retries, int keep_alive_timeout) +LIBNVME_PUBLIC int nvmf_context_set_discovery_defaults( + struct nvmf_context *fctx, + int max_discovery_retries, + int keep_alive_timeout) { fctx->default_max_discovery_retries = max_discovery_retries; fctx->default_keep_alive_timeout = keep_alive_timeout; @@ -242,7 +247,8 @@ int nvmf_context_set_discovery_defaults(struct nvmf_context *fctx, return 0; } -int nvmf_context_set_fabrics_config(struct nvmf_context *fctx, +LIBNVME_PUBLIC int nvmf_context_set_fabrics_config( + struct nvmf_context *fctx, struct nvme_fabrics_config *cfg) { fctx->cfg = cfg; @@ -250,10 +256,14 @@ int nvmf_context_set_fabrics_config(struct nvmf_context *fctx, return 0; } -int nvmf_context_set_connection(struct nvmf_context *fctx, - const char *subsysnqn, const char *transport, - const char *traddr, const char *trsvcid, - const char *host_traddr, const char *host_iface) +LIBNVME_PUBLIC int nvmf_context_set_connection( + struct nvmf_context *fctx, + const char *subsysnqn, + const char *transport, + const char *traddr, + const char *trsvcid, + const char *host_traddr, + const char *host_iface) { fctx->subsysnqn = subsysnqn; fctx->transport = transport; @@ -265,8 +275,10 @@ int nvmf_context_set_connection(struct nvmf_context *fctx, return 0; } -int nvmf_context_set_hostnqn(struct nvmf_context *fctx, - const char *hostnqn, const char *hostid) +LIBNVME_PUBLIC int nvmf_context_set_hostnqn( + struct nvmf_context *fctx, + const char *hostnqn, + const char *hostid) { fctx->hostnqn = hostnqn; fctx->hostid = hostid; @@ -274,9 +286,12 @@ int nvmf_context_set_hostnqn(struct nvmf_context *fctx, return 0; } -int nvmf_context_set_crypto(struct nvmf_context *fctx, - const char *hostkey, const char *ctrlkey, - const char *keyring, const char *tls_key, +LIBNVME_PUBLIC int nvmf_context_set_crypto( + struct nvmf_context *fctx, + const char *hostkey, + const char *ctrlkey, + const char *keyring, + const char *tls_key, const char *tls_key_identity) { fctx->hostkey = hostkey; @@ -288,14 +303,18 @@ int nvmf_context_set_crypto(struct nvmf_context *fctx, return 0; } -int nvmf_context_set_persistent(struct nvmf_context *fctx, bool persistent) +LIBNVME_PUBLIC int nvmf_context_set_persistent( + struct nvmf_context *fctx, + bool persistent) { fctx->persistent = persistent; return 0; } -int nvmf_context_set_device(struct nvmf_context *fctx, const char *device) +LIBNVME_PUBLIC int nvmf_context_set_device( + struct nvmf_context *fctx, + const char *device) { fctx->device = device; @@ -364,7 +383,9 @@ static struct nvme_fabrics_config *merge_config(nvme_ctrl_t c, #define UPDATE_CFG_OPTION(c, n, o, d) \ if ((n)->o != d) (c)->o = (n)->o -void nvmf_update_config(nvme_ctrl_t c, const struct nvme_fabrics_config *cfg) +LIBNVME_PUBLIC void nvmf_update_config( + nvme_ctrl_t c, + const struct nvme_fabrics_config *cfg) { struct nvme_fabrics_config *ctrl_cfg = nvme_ctrl_get_config(c); @@ -986,8 +1007,10 @@ static const char *lookup_context(struct nvme_global_ctx *ctx, nvme_ctrl_t c) return NULL; } -int nvmf_add_ctrl(nvme_host_t h, nvme_ctrl_t c, - const struct nvme_fabrics_config *cfg) +LIBNVME_PUBLIC int nvmf_add_ctrl( + nvme_host_t h, + nvme_ctrl_t c, + const struct nvme_fabrics_config *cfg) { nvme_subsystem_t s; const char *root_app, *app; @@ -1080,7 +1103,7 @@ int nvmf_add_ctrl(nvme_host_t h, nvme_ctrl_t c, return nvme_init_ctrl(h, c, ret); } -int nvmf_connect_ctrl(nvme_ctrl_t c) +LIBNVME_PUBLIC int nvmf_connect_ctrl(nvme_ctrl_t c) { _cleanup_free_ char *argstr = NULL; int ret; @@ -1349,8 +1372,10 @@ static void sanitize_discovery_log_entry(struct nvmf_disc_log_entry *e) } } -int nvmf_get_discovery_log(nvme_ctrl_t c, struct nvmf_discovery_log **logp, - int max_retries) +LIBNVME_PUBLIC int nvmf_get_discovery_log( + nvme_ctrl_t c, + struct nvmf_discovery_log **logp, + int max_retries) { struct nvme_get_discovery_args args = { .c = c, @@ -1363,8 +1388,9 @@ int nvmf_get_discovery_log(nvme_ctrl_t c, struct nvmf_discovery_log **logp, return nvmf_get_discovery_wargs(&args, logp); } -int nvmf_get_discovery_wargs(struct nvme_get_discovery_args *args, - struct nvmf_discovery_log **logp) +LIBNVME_PUBLIC int nvmf_get_discovery_wargs( + struct nvme_get_discovery_args *args, + struct nvmf_discovery_log **logp) { struct nvmf_discovery_log *log; int err; @@ -1645,7 +1671,7 @@ static int nvme_fetch_cntrltype_dctype_from_id(nvme_ctrl_t c) return 0; } -bool nvmf_is_registration_supported(nvme_ctrl_t c) +LIBNVME_PUBLIC bool nvmf_is_registration_supported(nvme_ctrl_t c) { if (!c->cntrltype || !c->dctype) if (nvme_fetch_cntrltype_dctype_from_id(c)) @@ -1654,7 +1680,10 @@ bool nvmf_is_registration_supported(nvme_ctrl_t c) return !strcmp(c->dctype, "ddc") || !strcmp(c->dctype, "cdc"); } -int nvmf_register_ctrl(nvme_ctrl_t c, enum nvmf_dim_tas tas, __u32 *result) +LIBNVME_PUBLIC int nvmf_register_ctrl( + nvme_ctrl_t c, + enum nvmf_dim_tas tas, + __u32 *result) { if (!nvmf_is_registration_supported(c)) return -ENOTSUP; @@ -1695,7 +1724,9 @@ static char *unescape_uri(const char *str, int len) return dst; } -int nvme_parse_uri(const char *str, struct nvme_fabrics_uri **urip) +LIBNVME_PUBLIC int nvme_parse_uri( + const char *str, + struct nvme_fabrics_uri **urip) { struct nvme_fabrics_uri *uri; _cleanup_free_ char *scheme = NULL; @@ -1792,7 +1823,7 @@ int nvme_parse_uri(const char *str, struct nvme_fabrics_uri **urip) return 0; } -void nvmf_free_uri(struct nvme_fabrics_uri *uri) +LIBNVME_PUBLIC void nvmf_free_uri(struct nvme_fabrics_uri *uri) { char **s; @@ -2028,7 +2059,8 @@ static int _nvmf_discovery(struct nvme_global_ctx *ctx, return 0; } -const char *nvmf_get_default_trsvcid(const char *transport, +LIBNVME_PUBLIC const char *nvmf_get_default_trsvcid( + const char *transport, bool discovery_ctrl) { if (!transport) @@ -2255,8 +2287,11 @@ int _discovery_config_json(struct nvme_global_ctx *ctx, return ret; } -int nvmf_discovery_config_json(struct nvme_global_ctx *ctx, - struct nvmf_context *fctx, bool connect, bool force) +LIBNVME_PUBLIC int nvmf_discovery_config_json( + struct nvme_global_ctx *ctx, + struct nvmf_context *fctx, + bool connect, + bool force) { const char *hnqn, *hid; struct nvme_subsystem *s; @@ -2303,7 +2338,8 @@ int nvmf_discovery_config_json(struct nvme_global_ctx *ctx, return ret; } -int nvmf_connect_config_json(struct nvme_global_ctx *ctx, +LIBNVME_PUBLIC int nvmf_connect_config_json( + struct nvme_global_ctx *ctx, struct nvmf_context *fctx) { const char *hnqn, *hid; @@ -2362,8 +2398,11 @@ int nvmf_connect_config_json(struct nvme_global_ctx *ctx, return ret; } -int nvmf_discovery_config_file(struct nvme_global_ctx *ctx, - struct nvmf_context *fctx, bool connect, bool force) +LIBNVME_PUBLIC int nvmf_discovery_config_file( + struct nvme_global_ctx *ctx, + struct nvmf_context *fctx, + bool connect, + bool force) { struct nvme_host *h; struct nvme_ctrl *c; @@ -2422,7 +2461,8 @@ int nvmf_discovery_config_file(struct nvme_global_ctx *ctx, return 0; } -int nvmf_config_modify(struct nvme_global_ctx *ctx, +LIBNVME_PUBLIC int nvmf_config_modify( + struct nvme_global_ctx *ctx, struct nvmf_context *fctx) { _cleanup_free_ char *hnqn = NULL; @@ -2479,7 +2519,9 @@ static int nbft_filter(const struct dirent *dent) return !fnmatch(NBFT_SYSFS_FILENAME, dent->d_name, FNM_PATHNAME); } -int nvmf_nbft_read_files(struct nvme_global_ctx *ctx, char *path, +LIBNVME_PUBLIC int nvmf_nbft_read_files( + struct nvme_global_ctx *ctx, + char *path, struct nbft_file_entry **head) { struct nbft_file_entry *entry = NULL; @@ -2518,7 +2560,9 @@ int nvmf_nbft_read_files(struct nvme_global_ctx *ctx, char *path, return 0; } -void nvmf_nbft_free(struct nvme_global_ctx *ctx, struct nbft_file_entry *head) +LIBNVME_PUBLIC void nvmf_nbft_free( + struct nvme_global_ctx *ctx, + struct nbft_file_entry *head) { while (head) { struct nbft_file_entry *next = head->next; @@ -2725,8 +2769,11 @@ static int nbft_discovery(struct nvme_global_ctx *ctx, return 0; } -int nvmf_discovery_nbft(struct nvme_global_ctx *ctx, - struct nvmf_context *fctx, bool connect, char *nbft_path) +LIBNVME_PUBLIC int nvmf_discovery_nbft( + struct nvme_global_ctx *ctx, + struct nvmf_context *fctx, + bool connect, + char *nbft_path) { const char *hostnqn = NULL, *hostid = NULL, *host_traddr = NULL; char uuid[NVME_UUID_LEN_STRING]; @@ -2943,8 +2990,11 @@ int nvmf_discovery_nbft(struct nvme_global_ctx *ctx, return ret; } -int nvmf_discovery(struct nvme_global_ctx *ctx, struct nvmf_context *fctx, - bool connect, bool force) +LIBNVME_PUBLIC int nvmf_discovery( + struct nvme_global_ctx *ctx, + struct nvmf_context *fctx, + bool connect, + bool force) { struct nvme_ctrl *c = NULL; struct nvme_host *h; @@ -3051,7 +3101,9 @@ int nvmf_discovery(struct nvme_global_ctx *ctx, struct nvmf_context *fctx, return ret; } -int nvmf_connect(struct nvme_global_ctx *ctx, struct nvmf_context *fctx) +LIBNVME_PUBLIC int nvmf_connect( + struct nvme_global_ctx *ctx, + struct nvmf_context *fctx) { struct nvme_host *h; struct nvme_ctrl *c; diff --git a/libnvme/src/nvme/filters.c b/libnvme/src/nvme/filters.c index a3fb4cbfc6..6be4d352ee 100644 --- a/libnvme/src/nvme/filters.c +++ b/libnvme/src/nvme/filters.c @@ -14,7 +14,7 @@ #include "private.h" -int nvme_filter_namespace(const struct dirent *d) +LIBNVME_PUBLIC int nvme_filter_namespace(const struct dirent *d) { int i, n; @@ -28,7 +28,7 @@ int nvme_filter_namespace(const struct dirent *d) return 0; } -int nvme_filter_paths(const struct dirent *d) +LIBNVME_PUBLIC int nvme_filter_paths(const struct dirent *d) { int i, c, n; @@ -42,7 +42,7 @@ int nvme_filter_paths(const struct dirent *d) return 0; } -int nvme_filter_ctrls(const struct dirent *d) +LIBNVME_PUBLIC int nvme_filter_ctrls(const struct dirent *d) { int i, c, n; @@ -61,7 +61,7 @@ int nvme_filter_ctrls(const struct dirent *d) return 0; } -int nvme_filter_subsys(const struct dirent *d) +LIBNVME_PUBLIC int nvme_filter_subsys(const struct dirent *d) { int i; @@ -75,7 +75,7 @@ int nvme_filter_subsys(const struct dirent *d) return 0; } -int nvme_scan_subsystems(struct dirent ***subsys) +LIBNVME_PUBLIC int nvme_scan_subsystems(struct dirent ***subsys) { const char *dir = nvme_subsys_sysfs_dir(); int ret; @@ -87,7 +87,9 @@ int nvme_scan_subsystems(struct dirent ***subsys) return ret; } -int nvme_scan_subsystem_namespaces(nvme_subsystem_t s, struct dirent ***ns) +LIBNVME_PUBLIC int nvme_scan_subsystem_namespaces( + nvme_subsystem_t s, + struct dirent ***ns) { int ret; @@ -99,7 +101,7 @@ int nvme_scan_subsystem_namespaces(nvme_subsystem_t s, struct dirent ***ns) return ret; } -int nvme_scan_ctrls(struct dirent ***ctrls) +LIBNVME_PUBLIC int nvme_scan_ctrls(struct dirent ***ctrls) { const char *dir = nvme_ctrl_sysfs_dir(); int ret; @@ -111,7 +113,9 @@ int nvme_scan_ctrls(struct dirent ***ctrls) return ret; } -int nvme_scan_ctrl_namespace_paths(nvme_ctrl_t c, struct dirent ***paths) +LIBNVME_PUBLIC int nvme_scan_ctrl_namespace_paths( + nvme_ctrl_t c, + struct dirent ***paths) { int ret; @@ -123,7 +127,7 @@ int nvme_scan_ctrl_namespace_paths(nvme_ctrl_t c, struct dirent ***paths) return ret; } -int nvme_scan_ctrl_namespaces(nvme_ctrl_t c, struct dirent ***ns) +LIBNVME_PUBLIC int nvme_scan_ctrl_namespaces(nvme_ctrl_t c, struct dirent ***ns) { int ret; diff --git a/libnvme/src/nvme/ioctl.c b/libnvme/src/nvme/ioctl.c index a742cd6304..5f425b4c9a 100644 --- a/libnvme/src/nvme/ioctl.c +++ b/libnvme/src/nvme/ioctl.c @@ -37,7 +37,7 @@ static int nvme_verify_chr(struct nvme_transport_handle *hdl) return 0; } -int nvme_reset_subsystem(struct nvme_transport_handle *hdl) +LIBNVME_PUBLIC int nvme_reset_subsystem(struct nvme_transport_handle *hdl) { int ret; @@ -51,7 +51,7 @@ int nvme_reset_subsystem(struct nvme_transport_handle *hdl) return ret; } -int nvme_reset_ctrl(struct nvme_transport_handle *hdl) +LIBNVME_PUBLIC int nvme_reset_ctrl(struct nvme_transport_handle *hdl) { int ret; @@ -65,7 +65,7 @@ int nvme_reset_ctrl(struct nvme_transport_handle *hdl) return ret; } -int nvme_rescan_ns(struct nvme_transport_handle *hdl) +LIBNVME_PUBLIC int nvme_rescan_ns(struct nvme_transport_handle *hdl) { int ret; @@ -79,7 +79,7 @@ int nvme_rescan_ns(struct nvme_transport_handle *hdl) return ret; } -int nvme_get_nsid(struct nvme_transport_handle *hdl, __u32 *nsid) +LIBNVME_PUBLIC int nvme_get_nsid(struct nvme_transport_handle *hdl, __u32 *nsid) { __u32 tmp; @@ -170,7 +170,8 @@ static int nvme_submit_passthru64(struct nvme_transport_handle *hdl, return err; } -int nvme_submit_io_passthru(struct nvme_transport_handle *hdl, +LIBNVME_PUBLIC int nvme_submit_io_passthru( + struct nvme_transport_handle *hdl, struct nvme_passthru_cmd *cmd) { if (hdl->ioctl_io64) @@ -178,7 +179,8 @@ int nvme_submit_io_passthru(struct nvme_transport_handle *hdl, return nvme_submit_passthru32(hdl, NVME_IOCTL_IO_CMD, cmd); } -int nvme_submit_admin_passthru(struct nvme_transport_handle *hdl, +LIBNVME_PUBLIC int nvme_submit_admin_passthru( + struct nvme_transport_handle *hdl, struct nvme_passthru_cmd *cmd) { switch (hdl->type) { diff --git a/libnvme/src/nvme/lib-types.h b/libnvme/src/nvme/lib-types.h index 43eab2ddac..1ea4b010d3 100644 --- a/libnvme/src/nvme/lib-types.h +++ b/libnvme/src/nvme/lib-types.h @@ -10,6 +10,15 @@ #include +/** + * LIBNVME_PUBLIC - mark a symbol as part of the public API. + * + * When the library is built with -fvisibility=hidden all symbols are hidden + * by default. Annotating a function with LIBNVME_PUBLIC overrides that and + * makes the symbol visible in the shared library ABI. + */ +#define LIBNVME_PUBLIC __attribute__((visibility("default"))) + struct nvme_global_ctx; struct nvme_transport_handle; diff --git a/libnvme/src/nvme/lib.c b/libnvme/src/nvme/lib.c index c9fdd2db64..5d6ac27239 100644 --- a/libnvme/src/nvme/lib.c +++ b/libnvme/src/nvme/lib.c @@ -32,7 +32,9 @@ static bool nvme_mi_probe_enabled_default(void) } -struct nvme_global_ctx *nvme_create_global_ctx(FILE *fp, int log_level) +LIBNVME_PUBLIC struct nvme_global_ctx *nvme_create_global_ctx( + FILE *fp, + int log_level) { struct nvme_global_ctx *ctx; int fd; @@ -62,7 +64,7 @@ struct nvme_global_ctx *nvme_create_global_ctx(FILE *fp, int log_level) return ctx; } -void nvme_free_global_ctx(struct nvme_global_ctx *ctx) +LIBNVME_PUBLIC void nvme_free_global_ctx(struct nvme_global_ctx *ctx) { struct nvme_host *h, *_h; nvme_mi_ep_t ep, tmp; @@ -84,18 +86,22 @@ void nvme_free_global_ctx(struct nvme_global_ctx *ctx) free(ctx); } -void nvme_set_dry_run(struct nvme_global_ctx *ctx, bool enable) +LIBNVME_PUBLIC void nvme_set_dry_run(struct nvme_global_ctx *ctx, bool enable) { ctx->dry_run = enable; } -void nvme_set_ioctl_probing(struct nvme_global_ctx *ctx, bool enable) +LIBNVME_PUBLIC void nvme_set_ioctl_probing( + struct nvme_global_ctx *ctx, + bool enable) { ctx->ioctl_probing = enable; } -void nvme_transport_handle_set_submit_entry(struct nvme_transport_handle *hdl, - void *(*submit_entry)(struct nvme_transport_handle *hdl, +LIBNVME_PUBLIC void nvme_transport_handle_set_submit_entry( + struct nvme_transport_handle *hdl, + void *(*submit_entry)( + struct nvme_transport_handle *hdl, struct nvme_passthru_cmd *cmd)) { hdl->submit_entry = submit_entry; @@ -103,19 +109,25 @@ void nvme_transport_handle_set_submit_entry(struct nvme_transport_handle *hdl, hdl->submit_exit = __nvme_submit_exit; } -void nvme_transport_handle_set_submit_exit(struct nvme_transport_handle *hdl, - void (*submit_exit)(struct nvme_transport_handle *hdl, +LIBNVME_PUBLIC void nvme_transport_handle_set_submit_exit( + struct nvme_transport_handle *hdl, + void (*submit_exit)( + struct nvme_transport_handle *hdl, struct nvme_passthru_cmd *cmd, - int err, void *user_data)) + int err, + void *user_data)) { hdl->submit_exit = submit_exit; if (!hdl->submit_exit) hdl->submit_exit = __nvme_submit_exit; } -void nvme_transport_handle_set_decide_retry(struct nvme_transport_handle *hdl, - bool (*decide_retry)(struct nvme_transport_handle *hdl, - struct nvme_passthru_cmd *cmd, int err)) +LIBNVME_PUBLIC void nvme_transport_handle_set_decide_retry( + struct nvme_transport_handle *hdl, + bool (*decide_retry)( + struct nvme_transport_handle *hdl, + struct nvme_passthru_cmd *cmd, + int err)) { hdl->decide_retry = decide_retry; if (!hdl->decide_retry) @@ -201,7 +213,7 @@ struct nvme_transport_handle *__nvme_create_transport_handle( return hdl; } -int nvme_open(struct nvme_global_ctx *ctx, const char *name, +LIBNVME_PUBLIC int nvme_open(struct nvme_global_ctx *ctx, const char *name, struct nvme_transport_handle **hdlp) { struct nvme_transport_handle *hdl; @@ -243,7 +255,7 @@ int nvme_open(struct nvme_global_ctx *ctx, const char *name, return 0; } -void nvme_close(struct nvme_transport_handle *hdl) +LIBNVME_PUBLIC void nvme_close(struct nvme_transport_handle *hdl) { if (!hdl) return; @@ -263,32 +275,38 @@ void nvme_close(struct nvme_transport_handle *hdl) } } -int nvme_transport_handle_get_fd(struct nvme_transport_handle *hdl) +LIBNVME_PUBLIC int nvme_transport_handle_get_fd( + struct nvme_transport_handle *hdl) { return hdl->fd; } -const char *nvme_transport_handle_get_name(struct nvme_transport_handle *hdl) +LIBNVME_PUBLIC const char *nvme_transport_handle_get_name( + struct nvme_transport_handle *hdl) { return basename(hdl->name); } -bool nvme_transport_handle_is_blkdev(struct nvme_transport_handle *hdl) +LIBNVME_PUBLIC bool nvme_transport_handle_is_blkdev( + struct nvme_transport_handle *hdl) { return S_ISBLK(hdl->stat.st_mode); } -bool nvme_transport_handle_is_chardev(struct nvme_transport_handle *hdl) +LIBNVME_PUBLIC bool nvme_transport_handle_is_chardev( + struct nvme_transport_handle *hdl) { return S_ISCHR(hdl->stat.st_mode); } -bool nvme_transport_handle_is_direct(struct nvme_transport_handle *hdl) +LIBNVME_PUBLIC bool nvme_transport_handle_is_direct( + struct nvme_transport_handle *hdl) { return hdl->type == NVME_TRANSPORT_HANDLE_TYPE_DIRECT; } -bool nvme_transport_handle_is_mi(struct nvme_transport_handle *hdl) +LIBNVME_PUBLIC bool nvme_transport_handle_is_mi( + struct nvme_transport_handle *hdl) { return hdl->type == NVME_TRANSPORT_HANDLE_TYPE_MI; } diff --git a/libnvme/src/nvme/lib.h b/libnvme/src/nvme/lib.h index 6efc245d9b..0142a42187 100644 --- a/libnvme/src/nvme/lib.h +++ b/libnvme/src/nvme/lib.h @@ -204,17 +204,6 @@ void nvme_transport_handle_set_decide_retry(struct nvme_transport_handle *hdl, bool (*decide_retry)(struct nvme_transport_handle *hdl, struct nvme_passthru_cmd *cmd, int err)); -/** - * nvme_set_probe_enabled() - enable/disable the probe for new MI endpoints - * @ctx: &struct nvme_global_ctx object - * @enabled: whether to probe new endpoints - * - * Controls whether newly-created endpoints are probed for quirks on creation. - * Defaults to enabled, which results in some initial messaging with the - * endpoint to determine model-specific details. - */ -void nvme_set_probe_enabled(struct nvme_global_ctx *ctx, bool enabled); - /** * nvme_set_dry_run() - Set global dry run state * @ctx: struct nvme_global_ctx object diff --git a/libnvme/src/nvme/linux.c b/libnvme/src/nvme/linux.c index 6f58507af9..62920b9845 100644 --- a/libnvme/src/nvme/linux.c +++ b/libnvme/src/nvme/linux.c @@ -109,7 +109,7 @@ static char *__nvme_get_attr(const char *path) return strlen(value) ? strdup(value) : NULL; } -char *nvme_get_attr(const char *dir, const char *attr) +LIBNVME_PUBLIC char *nvme_get_attr(const char *dir, const char *attr) { _cleanup_free_ char *path = NULL; int ret; @@ -121,22 +121,22 @@ char *nvme_get_attr(const char *dir, const char *attr) return __nvme_get_attr(path); } -char *nvme_get_subsys_attr(nvme_subsystem_t s, const char *attr) +LIBNVME_PUBLIC char *nvme_get_subsys_attr(nvme_subsystem_t s, const char *attr) { return nvme_get_attr(nvme_subsystem_get_sysfs_dir(s), attr); } -char *nvme_get_ctrl_attr(nvme_ctrl_t c, const char *attr) +LIBNVME_PUBLIC char *nvme_get_ctrl_attr(nvme_ctrl_t c, const char *attr) { return nvme_get_attr(nvme_ctrl_get_sysfs_dir(c), attr); } -char *nvme_get_ns_attr(nvme_ns_t n, const char *attr) +LIBNVME_PUBLIC char *nvme_get_ns_attr(nvme_ns_t n, const char *attr) { return nvme_get_attr(nvme_ns_get_sysfs_dir(n), attr); } -char *nvme_get_path_attr(nvme_path_t p, const char *attr) +LIBNVME_PUBLIC char *nvme_get_path_attr(nvme_path_t p, const char *attr) { return nvme_get_attr(nvme_path_get_sysfs_dir(p), attr); } @@ -147,7 +147,7 @@ static unsigned char default_hmac(size_t key_len) return NVME_HMAC_ALG_NONE; } -int nvme_gen_dhchap_key(struct nvme_global_ctx *ctx, +LIBNVME_PUBLIC int nvme_gen_dhchap_key(struct nvme_global_ctx *ctx, char *hostnqn, enum nvme_hmac_alg hmac, unsigned int key_len, unsigned char *secret, unsigned char *key) @@ -592,7 +592,7 @@ static DEFINE_CLEANUP_FUNC(cleanup_evp_mac_ctx, EVP_MAC_CTX *, EVP_MAC_CTX_free) static DEFINE_CLEANUP_FUNC(cleanup_evp_mac, EVP_MAC *, EVP_MAC_free) #define _cleanup_evp_mac_ __cleanup__(cleanup_evp_mac) -int nvme_gen_dhchap_key(struct nvme_global_ctx *ctx, +LIBNVME_PUBLIC int nvme_gen_dhchap_key(struct nvme_global_ctx *ctx, char *hostnqn, enum nvme_hmac_alg hmac, unsigned int key_len, unsigned char *secret, unsigned char *key) @@ -840,7 +840,7 @@ static ssize_t nvme_identity_len(int hmac, int version, const char *hostnqn, return len; } -int nvme_generate_tls_key_identity(struct nvme_global_ctx *ctx, +LIBNVME_PUBLIC int nvme_generate_tls_key_identity(struct nvme_global_ctx *ctx, const char *hostnqn, const char *subsysnqn, int version, int hmac, unsigned char *configured_key, int key_len, @@ -878,10 +878,15 @@ int nvme_generate_tls_key_identity(struct nvme_global_ctx *ctx, return 0; } -int nvme_generate_tls_key_identity_compat(struct nvme_global_ctx *ctx, - const char *hostnqn, const char *subsysnqn, - int version, int hmac, unsigned char *configured_key, - int key_len, char **ident) +LIBNVME_PUBLIC int nvme_generate_tls_key_identity_compat( + struct nvme_global_ctx *ctx, + const char *hostnqn, + const char *subsysnqn, + int version, + int hmac, + unsigned char *configured_key, + int key_len, + char **ident) { _cleanup_free_ unsigned char *psk = NULL; _cleanup_free_ char *identity = NULL; @@ -916,7 +921,9 @@ int nvme_generate_tls_key_identity_compat(struct nvme_global_ctx *ctx, } #ifdef CONFIG_KEYUTILS -int nvme_lookup_keyring(struct nvme_global_ctx *ctx, const char *keyring, +LIBNVME_PUBLIC int nvme_lookup_keyring( + struct nvme_global_ctx *ctx, + const char *keyring, long *key) { key_serial_t keyring_id; @@ -931,7 +938,9 @@ int nvme_lookup_keyring(struct nvme_global_ctx *ctx, const char *keyring, return 0; } -char *nvme_describe_key_serial(struct nvme_global_ctx *ctx, long key_id) +LIBNVME_PUBLIC char *nvme_describe_key_serial( + struct nvme_global_ctx *ctx, + long key_id) { _cleanup_free_ char *str = NULL; char *last; @@ -950,8 +959,11 @@ char *nvme_describe_key_serial(struct nvme_global_ctx *ctx, long key_id) return strdup(last); } -int nvme_lookup_key(struct nvme_global_ctx *ctx, const char *type, - const char *identity, long *keyp) +LIBNVME_PUBLIC int nvme_lookup_key( + struct nvme_global_ctx *ctx, + const char *type, + const char *identity, + long *keyp) { key_serial_t key; @@ -961,7 +973,7 @@ int nvme_lookup_key(struct nvme_global_ctx *ctx, const char *type, return key; } -int nvme_set_keyring(struct nvme_global_ctx *ctx, long key_id) +LIBNVME_PUBLIC int nvme_set_keyring(struct nvme_global_ctx *ctx, long key_id) { long err; @@ -976,7 +988,7 @@ int nvme_set_keyring(struct nvme_global_ctx *ctx, long key_id) return 0; } -int nvme_read_key(struct nvme_global_ctx *ctx, long keyring_id, +LIBNVME_PUBLIC int nvme_read_key(struct nvme_global_ctx *ctx, long keyring_id, long key_id, int *len, unsigned char **key) { void *buffer; @@ -995,7 +1007,7 @@ int nvme_read_key(struct nvme_global_ctx *ctx, long keyring_id, return 0; } -int nvme_update_key(struct nvme_global_ctx *ctx, long keyring_id, +LIBNVME_PUBLIC int nvme_update_key(struct nvme_global_ctx *ctx, long keyring_id, const char *key_type, const char *identity, unsigned char *key_data, int key_len, long *keyp) { @@ -1055,8 +1067,11 @@ int __scan_keys_cb(key_serial_t parent, key_serial_t key, char *desc, return 1; } -int nvme_scan_tls_keys(struct nvme_global_ctx *ctx, const char *keyring, - nvme_scan_tls_keys_cb_t cb, void *data) +LIBNVME_PUBLIC int nvme_scan_tls_keys( + struct nvme_global_ctx *ctx, + const char *keyring, + nvme_scan_tls_keys_cb_t cb, + void *data) { struct __scan_keys_data d; long keyring_id; @@ -1123,7 +1138,7 @@ static int __nvme_insert_tls_key(struct nvme_global_ctx *ctx, return 0; } -int nvme_insert_tls_key_versioned(struct nvme_global_ctx *ctx, +LIBNVME_PUBLIC int nvme_insert_tls_key_versioned(struct nvme_global_ctx *ctx, const char *keyring, const char *key_type, const char *hostnqn, const char *subsysnqn, int version, int hmac, @@ -1146,7 +1161,7 @@ int nvme_insert_tls_key_versioned(struct nvme_global_ctx *ctx, configured_key, key_len, false, key); } -int nvme_insert_tls_key_compat(struct nvme_global_ctx *ctx, +LIBNVME_PUBLIC int nvme_insert_tls_key_compat(struct nvme_global_ctx *ctx, const char *keyring, const char *key_type, const char *hostnqn, const char *subsysnqn, int version, int hmac, @@ -1169,7 +1184,7 @@ int nvme_insert_tls_key_compat(struct nvme_global_ctx *ctx, configured_key, key_len, true, key); } -int nvme_revoke_tls_key(struct nvme_global_ctx *ctx, +LIBNVME_PUBLIC int nvme_revoke_tls_key(struct nvme_global_ctx *ctx, const char *keyring, const char *key_type, const char *identity) { @@ -1295,7 +1310,9 @@ int __nvme_import_keys_from_config(nvme_host_t h, nvme_ctrl_t c, return 0; } #else -int nvme_lookup_keyring(struct nvme_global_ctx *ctx, const char *keyring, +LIBNVME_PUBLIC int nvme_lookup_keyring( + struct nvme_global_ctx *ctx, + const char *keyring, long *key) { nvme_msg(ctx, LOG_ERR, "key operations not supported; " @@ -1303,29 +1320,34 @@ int nvme_lookup_keyring(struct nvme_global_ctx *ctx, const char *keyring, return -ENOTSUP; } -char *nvme_describe_key_serial(struct nvme_global_ctx *ctx, long key_id) +LIBNVME_PUBLIC char *nvme_describe_key_serial( + struct nvme_global_ctx *ctx, + long key_id) { nvme_msg(ctx, LOG_ERR, "key operations not supported; " "recompile with keyutils support.\n"); return NULL; } -int nvme_lookup_key(struct nvme_global_ctx *ctx, const char *type, - const char *identity, long *key) +LIBNVME_PUBLIC int nvme_lookup_key( + struct nvme_global_ctx *ctx, + const char *type, + const char *identity, + long *key) { nvme_msg(ctx, LOG_ERR, "key operations not supported; " "recompile with keyutils support.\n"); return -ENOTSUP; } -int nvme_set_keyring(struct nvme_global_ctx *ctx, long key_id) +LIBNVME_PUBLIC int nvme_set_keyring(struct nvme_global_ctx *ctx, long key_id) { nvme_msg(ctx, LOG_ERR, "key operations not supported; " "recompile with keyutils support.\n"); return -ENOTSUP; } -int nvme_read_key(struct nvme_global_ctx *ctx, long keyring_id, +LIBNVME_PUBLIC int nvme_read_key(struct nvme_global_ctx *ctx, long keyring_id, long key_id, int *len, unsigned char **key) { nvme_msg(ctx, LOG_ERR, "key operations not supported; " @@ -1333,7 +1355,7 @@ int nvme_read_key(struct nvme_global_ctx *ctx, long keyring_id, return -ENOTSUP; } -int nvme_update_key(struct nvme_global_ctx *ctx, long keyring_id, +LIBNVME_PUBLIC int nvme_update_key(struct nvme_global_ctx *ctx, long keyring_id, const char *key_type, const char *identity, unsigned char *key_data, int key_len, long *key) { @@ -1342,15 +1364,18 @@ int nvme_update_key(struct nvme_global_ctx *ctx, long keyring_id, return -ENOTSUP; } -int nvme_scan_tls_keys(struct nvme_global_ctx *ctx, const char *keyring, - nvme_scan_tls_keys_cb_t cb, void *data) +LIBNVME_PUBLIC int nvme_scan_tls_keys( + struct nvme_global_ctx *ctx, + const char *keyring, + nvme_scan_tls_keys_cb_t cb, + void *data) { nvme_msg(ctx, LOG_ERR, "key operations not supported; " "recompile with keyutils support.\n"); return -ENOTSUP; } -int nvme_insert_tls_key_versioned(struct nvme_global_ctx *ctx, +LIBNVME_PUBLIC int nvme_insert_tls_key_versioned(struct nvme_global_ctx *ctx, const char *keyring, const char *key_type, const char *hostnqn, const char *subsysnqn, int version, int hmac, @@ -1362,7 +1387,7 @@ int nvme_insert_tls_key_versioned(struct nvme_global_ctx *ctx, return -ENOTSUP; } -int nvme_insert_tls_key_compat(struct nvme_global_ctx *ctx, +LIBNVME_PUBLIC int nvme_insert_tls_key_compat(struct nvme_global_ctx *ctx, const char *keyring, const char *key_type, const char *hostnqn, const char *subsysnqn, int version, int hmac, @@ -1374,7 +1399,7 @@ int nvme_insert_tls_key_compat(struct nvme_global_ctx *ctx, return -ENOTSUP; } -int nvme_revoke_tls_key(struct nvme_global_ctx *ctx, +LIBNVME_PUBLIC int nvme_revoke_tls_key(struct nvme_global_ctx *ctx, const char *keyring, const char *key_type, const char *identity) { @@ -1393,7 +1418,7 @@ int __nvme_import_keys_from_config(nvme_host_t h, nvme_ctrl_t c, } #endif -int nvme_insert_tls_key(struct nvme_global_ctx *ctx, +LIBNVME_PUBLIC int nvme_insert_tls_key(struct nvme_global_ctx *ctx, const char *keyring, const char *key_type, const char *hostnqn, const char *subsysnqn, int hmac, unsigned char *configured_key, int key_len, long *key) @@ -1415,7 +1440,7 @@ int nvme_insert_tls_key(struct nvme_global_ctx *ctx, * s: 32 or 48 bytes binary followed by a CRC-32 of the configured PSK * (4 bytes) encoded as base64 */ -int nvme_export_tls_key_versioned(struct nvme_global_ctx *ctx, +LIBNVME_PUBLIC int nvme_export_tls_key_versioned(struct nvme_global_ctx *ctx, unsigned char version, unsigned char hmac, const unsigned char *key_data, size_t key_len, char **encoded_keyp) @@ -1465,7 +1490,7 @@ int nvme_export_tls_key_versioned(struct nvme_global_ctx *ctx, return 0; } -int nvme_export_tls_key(struct nvme_global_ctx *ctx, +LIBNVME_PUBLIC int nvme_export_tls_key(struct nvme_global_ctx *ctx, const unsigned char *key_data, int key_len, char **key) { unsigned char hmac; @@ -1479,7 +1504,7 @@ int nvme_export_tls_key(struct nvme_global_ctx *ctx, key_len, key); } -int nvme_import_tls_key_versioned(struct nvme_global_ctx *ctx, +LIBNVME_PUBLIC int nvme_import_tls_key_versioned(struct nvme_global_ctx *ctx, const char *encoded_key, unsigned char *version, unsigned char *hmac, size_t *key_len, unsigned char **keyp) @@ -1548,8 +1573,12 @@ int nvme_import_tls_key_versioned(struct nvme_global_ctx *ctx, return 0; } -int nvme_import_tls_key(struct nvme_global_ctx *ctx, const char *encoded_key, - int *key_len, unsigned int *hmac, unsigned char **keyp) +LIBNVME_PUBLIC int nvme_import_tls_key( + struct nvme_global_ctx *ctx, + const char *encoded_key, + int *key_len, + unsigned int *hmac, + unsigned char **keyp) { unsigned char version, _hmac; unsigned char *psk; @@ -1723,7 +1752,7 @@ static int uuid_from_dmi(char *system_uuid) return ret; } -char *nvme_generate_hostid(void) +LIBNVME_PUBLIC char *nvme_generate_hostid(void) { int ret; char uuid_str[NVME_UUID_LEN_STRING]; @@ -1741,7 +1770,7 @@ char *nvme_generate_hostid(void) return strdup(uuid_str); } -char *nvme_generate_hostnqn_from_hostid(char *hostid) +LIBNVME_PUBLIC char *nvme_generate_hostnqn_from_hostid(char *hostid) { char *hid = NULL; char *hostnqn; @@ -1756,7 +1785,7 @@ char *nvme_generate_hostnqn_from_hostid(char *hostid) return (ret < 0) ? NULL : hostnqn; } -char *nvme_generate_hostnqn(void) +LIBNVME_PUBLIC char *nvme_generate_hostnqn(void) { return nvme_generate_hostnqn_from_hostid(NULL); } @@ -1779,7 +1808,7 @@ static char *nvmf_read_file(const char *f, int len) return strndup(buf, strcspn(buf, "\n")); } -char *nvme_read_hostnqn(void) +LIBNVME_PUBLIC char *nvme_read_hostnqn(void) { char *hostnqn = getenv("LIBNVME_HOSTNQN"); @@ -1792,7 +1821,7 @@ char *nvme_read_hostnqn(void) return nvmf_read_file(NVMF_HOSTNQN_FILE, NVMF_NQN_SIZE); } -char *nvme_read_hostid(void) +LIBNVME_PUBLIC char *nvme_read_hostid(void) { char *hostid = getenv("LIBNVME_HOSTID"); diff --git a/libnvme/src/nvme/log.c b/libnvme/src/nvme/log.c index 56187574ac..06f2983b12 100644 --- a/libnvme/src/nvme/log.c +++ b/libnvme/src/nvme/log.c @@ -83,15 +83,19 @@ __nvme_msg(struct nvme_global_ctx *ctx, int level, message ? message : ""); } -void nvme_set_logging_level(struct nvme_global_ctx *ctx, int log_level, - bool log_pid, bool log_tstamp) +LIBNVME_PUBLIC void nvme_set_logging_level( + struct nvme_global_ctx *ctx, + int log_level, + bool log_pid, + bool log_tstamp) { ctx->log.level = log_level; ctx->log.pid = log_pid; ctx->log.timestamp = log_tstamp; } -int nvme_get_logging_level(struct nvme_global_ctx *ctx, +LIBNVME_PUBLIC int nvme_get_logging_level( + struct nvme_global_ctx *ctx, bool *log_pid, bool *log_tstamp) { if (log_pid) diff --git a/libnvme/src/nvme/mi-mctp.c b/libnvme/src/nvme/mi-mctp.c index b87b19c859..c784beaef2 100644 --- a/libnvme/src/nvme/mi-mctp.c +++ b/libnvme/src/nvme/mi-mctp.c @@ -674,8 +674,10 @@ int nvme_mi_aem_open(nvme_mi_ep_t ep) return 0; } -nvme_mi_ep_t nvme_mi_open_mctp(struct nvme_global_ctx *ctx, - unsigned int netid, __u8 eid) +LIBNVME_PUBLIC nvme_mi_ep_t nvme_mi_open_mctp( + struct nvme_global_ctx *ctx, + unsigned int netid, + __u8 eid) { struct nvme_mi_transport_mctp *mctp; struct nvme_mi_ep *ep; @@ -944,7 +946,7 @@ static int handle_mctp_obj(struct nvme_global_ctx *ctx, DBusMessageIter *obj) return 0; } -struct nvme_global_ctx *nvme_mi_scan_mctp(void) +LIBNVME_PUBLIC struct nvme_global_ctx *nvme_mi_scan_mctp(void) { DBusMessage *msg, *resp = NULL; DBusConnection *bus = NULL; @@ -1038,7 +1040,7 @@ struct nvme_global_ctx *nvme_mi_scan_mctp(void) #else /* CONFIG_DBUS */ -struct nvme_global_ctx *nvme_mi_scan_mctp(void) +LIBNVME_PUBLIC struct nvme_global_ctx *nvme_mi_scan_mctp(void) { return NULL; } diff --git a/libnvme/src/nvme/mi.c b/libnvme/src/nvme/mi.c index f023428e67..c2d0026725 100644 --- a/libnvme/src/nvme/mi.c +++ b/libnvme/src/nvme/mi.c @@ -296,7 +296,9 @@ struct nvme_mi_ep *nvme_mi_init_ep(struct nvme_global_ctx *ctx) return ep; } -int nvme_mi_ep_set_timeout(nvme_mi_ep_t ep, unsigned int timeout_ms) +LIBNVME_PUBLIC int nvme_mi_ep_set_timeout( + nvme_mi_ep_t ep, + unsigned int timeout_ms) { if (ep->transport->check_timeout) { int rc; @@ -314,7 +316,7 @@ void nvme_mi_ep_set_mprt_max(nvme_mi_ep_t ep, unsigned int mprt_max_ms) ep->mprt_max = mprt_max_ms; } -unsigned int nvme_mi_ep_get_timeout(nvme_mi_ep_t ep) +LIBNVME_PUBLIC unsigned int nvme_mi_ep_get_timeout(nvme_mi_ep_t ep) { return ep->timeout; } @@ -324,7 +326,9 @@ static bool nvme_mi_ep_has_quirk(nvme_mi_ep_t ep, unsigned long quirk) return ep->quirks & quirk; } -struct nvme_transport_handle *nvme_mi_init_transport_handle(nvme_mi_ep_t ep, __u16 ctrl_id) +LIBNVME_PUBLIC struct nvme_transport_handle *nvme_mi_init_transport_handle( + nvme_mi_ep_t ep, + __u16 ctrl_id) { struct nvme_transport_handle *hdl; @@ -342,12 +346,12 @@ struct nvme_transport_handle *nvme_mi_init_transport_handle(nvme_mi_ep_t ep, __u return hdl; } -__u16 nvme_mi_ctrl_id(struct nvme_transport_handle *hdl) +LIBNVME_PUBLIC __u16 nvme_mi_ctrl_id(struct nvme_transport_handle *hdl) { return hdl->id; } -int nvme_mi_scan_ep(nvme_mi_ep_t ep, bool force_rescan) +LIBNVME_PUBLIC int nvme_mi_scan_ep(nvme_mi_ep_t ep, bool force_rescan) { struct nvme_ctrl_list list; unsigned int i, n_ctrl; @@ -420,15 +424,23 @@ static int nvme_mi_verify_resp_mic(struct nvme_mi_resp *resp) return resp->mic != ~crc; } -__attribute__((weak)) void *nvme_mi_submit_entry(__u8 type, const struct nvme_mi_msg_hdr *hdr, - size_t hdr_len, const void *data, size_t data_len) +LIBNVME_PUBLIC __attribute__((weak)) void *nvme_mi_submit_entry( + __u8 type, + const struct nvme_mi_msg_hdr *hdr, + size_t hdr_len, + const void *data, + size_t data_len) { return NULL; } -__attribute__((weak)) void nvme_mi_submit_exit(__u8 type, const struct nvme_mi_msg_hdr *hdr, - size_t hdr_len, const void *data, size_t data_len, - void *user_data) { } +LIBNVME_PUBLIC __attribute__((weak)) void nvme_mi_submit_exit( + __u8 type, + const struct nvme_mi_msg_hdr *hdr, + size_t hdr_len, + const void *data, + size_t data_len, + void *user_data) { } int nvme_mi_async_read(nvme_mi_ep_t ep, struct nvme_mi_resp *resp) @@ -568,7 +580,7 @@ int nvme_mi_submit(nvme_mi_ep_t ep, struct nvme_mi_req *req, return 0; } -int nvme_mi_set_csi(nvme_mi_ep_t ep, uint8_t csi) +LIBNVME_PUBLIC int nvme_mi_set_csi(nvme_mi_ep_t ep, uint8_t csi) { uint8_t csi_bit = (csi) ? 1 : 0; @@ -721,12 +733,13 @@ static int nvme_mi_get_async_message(nvme_mi_ep_t ep, } -int nvme_mi_admin_xfer(struct nvme_transport_handle *hdl, - struct nvme_mi_admin_req_hdr *admin_req, - size_t req_data_size, - struct nvme_mi_admin_resp_hdr *admin_resp, - off_t resp_data_offset, - size_t *resp_data_size) +LIBNVME_PUBLIC int nvme_mi_admin_xfer( + struct nvme_transport_handle *hdl, + struct nvme_mi_admin_req_hdr *admin_req, + size_t req_data_size, + struct nvme_mi_admin_resp_hdr *admin_resp, + off_t resp_data_offset, + size_t *resp_data_size) { struct nvme_mi_resp resp; struct nvme_mi_req req; @@ -887,8 +900,11 @@ int nvme_mi_admin_admin_passthru(struct nvme_transport_handle *hdl, return 0; } -int nvme_mi_control(nvme_mi_ep_t ep, __u8 opcode, - __u16 cpsp, __u16 *result_cpsr) +LIBNVME_PUBLIC int nvme_mi_control( + nvme_mi_ep_t ep, + __u8 opcode, + __u16 cpsp, + __u16 *result_cpsr) { struct nvme_mi_control_resp control_resp; struct nvme_mi_control_req control_req; @@ -959,11 +975,12 @@ static int nvme_mi_read_data(nvme_mi_ep_t ep, __u32 cdw0, return 0; } -int nvme_mi_mi_xfer(nvme_mi_ep_t ep, - struct nvme_mi_mi_req_hdr *mi_req, - size_t req_data_size, - struct nvme_mi_mi_resp_hdr *mi_resp, - size_t *resp_data_size) +LIBNVME_PUBLIC int nvme_mi_mi_xfer( + nvme_mi_ep_t ep, + struct nvme_mi_mi_req_hdr *mi_req, + size_t req_data_size, + struct nvme_mi_mi_resp_hdr *mi_resp, + size_t *resp_data_size) { int rc; struct nvme_mi_req req; @@ -1009,8 +1026,9 @@ int nvme_mi_mi_xfer(nvme_mi_ep_t ep, return 0; } -int nvme_mi_mi_read_mi_data_subsys(nvme_mi_ep_t ep, - struct nvme_mi_read_nvm_ss_info *s) +LIBNVME_PUBLIC int nvme_mi_mi_read_mi_data_subsys( + nvme_mi_ep_t ep, + struct nvme_mi_read_nvm_ss_info *s) { size_t len; __u32 cdw0; @@ -1034,8 +1052,10 @@ int nvme_mi_mi_read_mi_data_subsys(nvme_mi_ep_t ep, return 0; } -int nvme_mi_mi_read_mi_data_port(nvme_mi_ep_t ep, __u8 portid, - struct nvme_mi_read_port_info *p) +LIBNVME_PUBLIC int nvme_mi_mi_read_mi_data_port( + nvme_mi_ep_t ep, + __u8 portid, + struct nvme_mi_read_port_info *p) { size_t len; __u32 cdw0; @@ -1054,8 +1074,10 @@ int nvme_mi_mi_read_mi_data_port(nvme_mi_ep_t ep, __u8 portid, return 0; } -int nvme_mi_mi_read_mi_data_ctrl_list(nvme_mi_ep_t ep, __u8 start_ctrlid, - struct nvme_ctrl_list *list) +LIBNVME_PUBLIC int nvme_mi_mi_read_mi_data_ctrl_list( + nvme_mi_ep_t ep, + __u8 start_ctrlid, + struct nvme_ctrl_list *list) { size_t len; __u32 cdw0; @@ -1071,8 +1093,10 @@ int nvme_mi_mi_read_mi_data_ctrl_list(nvme_mi_ep_t ep, __u8 start_ctrlid, return 0; } -int nvme_mi_mi_read_mi_data_ctrl(nvme_mi_ep_t ep, __u16 ctrl_id, - struct nvme_mi_read_ctrl_info *ctrl) +LIBNVME_PUBLIC int nvme_mi_mi_read_mi_data_ctrl( + nvme_mi_ep_t ep, + __u16 ctrl_id, + struct nvme_mi_read_ctrl_info *ctrl) { size_t len; __u32 cdw0; @@ -1091,8 +1115,10 @@ int nvme_mi_mi_read_mi_data_ctrl(nvme_mi_ep_t ep, __u16 ctrl_id, return 0; } -int nvme_mi_mi_subsystem_health_status_poll(nvme_mi_ep_t ep, bool clear, - struct nvme_mi_nvm_ss_health_status *sshs) +LIBNVME_PUBLIC int nvme_mi_mi_subsystem_health_status_poll( + nvme_mi_ep_t ep, + bool clear, + struct nvme_mi_nvm_ss_health_status *sshs) { struct nvme_mi_mi_resp_hdr resp_hdr; struct nvme_mi_mi_req_hdr req_hdr; @@ -1167,8 +1193,11 @@ int nvme_mi_mi_config_set_get_ex(nvme_mi_ep_t ep, __u8 opcode, __u32 dw0, return 0; } -int nvme_mi_mi_config_get(nvme_mi_ep_t ep, __u32 dw0, __u32 dw1, - __u32 *nmresp) +LIBNVME_PUBLIC int nvme_mi_mi_config_get( + nvme_mi_ep_t ep, + __u32 dw0, + __u32 dw1, + __u32 *nmresp) { size_t data_in_len = 0; @@ -1183,7 +1212,7 @@ int nvme_mi_mi_config_get(nvme_mi_ep_t ep, __u32 dw0, __u32 dw1, nmresp); } -int nvme_mi_mi_config_set(nvme_mi_ep_t ep, __u32 dw0, __u32 dw1) +LIBNVME_PUBLIC int nvme_mi_mi_config_set(nvme_mi_ep_t ep, __u32 dw0, __u32 dw1) { size_t data_in_len = 0; @@ -1267,7 +1296,7 @@ int nvme_mi_mi_config_set_async_event(nvme_mi_ep_t ep, } -void nvme_mi_close(nvme_mi_ep_t ep) +LIBNVME_PUBLIC void nvme_mi_close(nvme_mi_ep_t ep) { struct nvme_transport_handle *hdl, *tmp; @@ -1283,7 +1312,7 @@ void nvme_mi_close(nvme_mi_ep_t ep) free(ep); } -char *nvme_mi_endpoint_desc(nvme_mi_ep_t ep) +LIBNVME_PUBLIC char *nvme_mi_endpoint_desc(nvme_mi_ep_t ep) { char tsbuf[101], *s = NULL; size_t tslen; @@ -1313,12 +1342,14 @@ char *nvme_mi_endpoint_desc(nvme_mi_ep_t ep) return s; } -nvme_mi_ep_t nvme_mi_first_endpoint(struct nvme_global_ctx *ctx) +LIBNVME_PUBLIC nvme_mi_ep_t nvme_mi_first_endpoint(struct nvme_global_ctx *ctx) { return list_top(&ctx->endpoints, struct nvme_mi_ep, root_entry); } -nvme_mi_ep_t nvme_mi_next_endpoint(struct nvme_global_ctx *ctx, nvme_mi_ep_t ep) +LIBNVME_PUBLIC nvme_mi_ep_t nvme_mi_next_endpoint( + struct nvme_global_ctx *ctx, + nvme_mi_ep_t ep) { return ep ? list_next(&ctx->endpoints, ep, root_entry) : NULL; } @@ -1357,7 +1388,7 @@ static const char *const mi_status[] = { /* kept in mi.c while we have a split libnvme/libnvme-mi; consider moving * to utils.c (with nvme_status_to_string) if we ever merge. */ -const char *nvme_mi_status_to_string(int status) +LIBNVME_PUBLIC const char *nvme_mi_status_to_string(int status) { const char *s = "Unknown status"; @@ -1525,7 +1556,7 @@ static int validate_occ_list_update_ctx( return err; } -int nvme_mi_aem_get_fd(nvme_mi_ep_t ep) +LIBNVME_PUBLIC int nvme_mi_aem_get_fd(nvme_mi_ep_t ep) { if (!ep || !ep->aem_ctx || !ep->transport || !ep->transport->aem_fd) return -1; @@ -1634,7 +1665,7 @@ static int aem_disable_enabled(nvme_mi_ep_t ep) return rc; } -int nvme_mi_aem_enable(nvme_mi_ep_t ep, +LIBNVME_PUBLIC int nvme_mi_aem_enable(nvme_mi_ep_t ep, struct nvme_mi_aem_config *config, void *userdata) { @@ -1708,7 +1739,7 @@ int nvme_mi_aem_enable(nvme_mi_ep_t ep, return rc; } -int nvme_mi_aem_get_enabled(nvme_mi_ep_t ep, +LIBNVME_PUBLIC int nvme_mi_aem_get_enabled(nvme_mi_ep_t ep, struct nvme_mi_aem_enabled_map *enabled_map) { if (!ep || !enabled_map) @@ -1749,7 +1780,7 @@ int nvme_mi_aem_get_enabled(nvme_mi_ep_t ep, return rc; } -int nvme_mi_aem_disable(nvme_mi_ep_t ep) +LIBNVME_PUBLIC int nvme_mi_aem_disable(nvme_mi_ep_t ep) { if (!ep) return -1; @@ -1767,7 +1798,7 @@ int nvme_mi_aem_disable(nvme_mi_ep_t ep) *spec_info and vend_spec_info must be copied to persist as they will not be valid after *the aem_handler has returned. */ -struct nvme_mi_event *nvme_mi_aem_get_next_event(nvme_mi_ep_t ep) +LIBNVME_PUBLIC struct nvme_mi_event *nvme_mi_aem_get_next_event(nvme_mi_ep_t ep) { if (!ep || !ep->aem_ctx || !ep->aem_ctx->list_current || @@ -1804,7 +1835,7 @@ struct nvme_mi_event *nvme_mi_aem_get_next_event(nvme_mi_ep_t ep) /* POLLIN has indicated events. This function reads and processes them. * A callback will likely be invoked. */ -int nvme_mi_aem_process(nvme_mi_ep_t ep, void *userdata) +LIBNVME_PUBLIC int nvme_mi_aem_process(nvme_mi_ep_t ep, void *userdata) { int rc = 0; uint8_t response_buffer[4096]; diff --git a/libnvme/src/nvme/mi.h b/libnvme/src/nvme/mi.h index d7beda872c..02cba9476f 100644 --- a/libnvme/src/nvme/mi.h +++ b/libnvme/src/nvme/mi.h @@ -892,8 +892,6 @@ int nvme_mi_scan_ep(nvme_mi_ep_t ep, bool force_rescan); * &nvme_mi_mi_read_mi_data_ctrl_list. * * Return: New transport handle object, or NULL on failure. - * - * See &nvme_mi_close_transport_handle */ struct nvme_transport_handle *nvme_mi_init_transport_handle(nvme_mi_ep_t ep, __u16 ctrl_id); diff --git a/libnvme/src/nvme/nbft.c b/libnvme/src/nvme/nbft.c index 2baa4d4e52..23bbfcb9d9 100644 --- a/libnvme/src/nvme/nbft.c +++ b/libnvme/src/nvme/nbft.c @@ -711,7 +711,9 @@ static int parse_raw_nbft(struct nvme_global_ctx *ctx, struct nbft_info *nbft) return 0; } -void nvme_free_nbft(struct nvme_global_ctx *ctx, struct nbft_info *nbft) +LIBNVME_PUBLIC void nvme_free_nbft( + struct nvme_global_ctx *ctx, + struct nbft_info *nbft) { struct nbft_info_hfi **hfi; struct nbft_info_security **sec; @@ -737,7 +739,9 @@ void nvme_free_nbft(struct nvme_global_ctx *ctx, struct nbft_info *nbft) free(nbft); } -int nvme_read_nbft(struct nvme_global_ctx *ctx, struct nbft_info **nbft, +LIBNVME_PUBLIC int nvme_read_nbft( + struct nvme_global_ctx *ctx, + struct nbft_info **nbft, const char *filename) { __u8 *raw_nbft = NULL; diff --git a/libnvme/src/nvme/tree.c b/libnvme/src/nvme/tree.c index dcc18f9b8d..c841d92abc 100644 --- a/libnvme/src/nvme/tree.c +++ b/libnvme/src/nvme/tree.c @@ -118,9 +118,12 @@ static char *nvme_hostid_from_hostnqn(const char *hostnqn) return strdup(uuid + strlen("uuid:")); } -int nvme_host_get_ids(struct nvme_global_ctx *ctx, - const char *hostnqn_arg, const char *hostid_arg, - char **hostnqn, char **hostid) +LIBNVME_PUBLIC int nvme_host_get_ids( + struct nvme_global_ctx *ctx, + const char *hostnqn_arg, + const char *hostid_arg, + char **hostnqn, + char **hostid) { _cleanup_free_ char *nqn = NULL; _cleanup_free_ char *hid = NULL; @@ -188,8 +191,11 @@ int nvme_host_get_ids(struct nvme_global_ctx *ctx, return 0; } -int nvme_get_host(struct nvme_global_ctx *ctx, const char *hostnqn, - const char *hostid, nvme_host_t *host) +LIBNVME_PUBLIC int nvme_get_host( + struct nvme_global_ctx *ctx, + const char *hostnqn, + const char *hostid, + nvme_host_t *host) { _cleanup_free_ char *hnqn = NULL; _cleanup_free_ char *hid = NULL; @@ -272,7 +278,10 @@ static void nvme_filter_tree(struct nvme_global_ctx *ctx, nvme_scan_filter_t f, } } -int nvme_scan_topology(struct nvme_global_ctx *ctx, nvme_scan_filter_t f, void *f_args) +LIBNVME_PUBLIC int nvme_scan_topology( + struct nvme_global_ctx *ctx, + nvme_scan_filter_t f, + void *f_args) { _cleanup_dirents_ struct dirents subsys = {}, ctrls = {}; int i, ret; @@ -323,7 +332,9 @@ int nvme_scan_topology(struct nvme_global_ctx *ctx, nvme_scan_filter_t f, void * return 0; } -int nvme_read_config(struct nvme_global_ctx *ctx, const char *config_file) +LIBNVME_PUBLIC int nvme_read_config( + struct nvme_global_ctx *ctx, + const char *config_file) { int err; @@ -345,22 +356,24 @@ int nvme_read_config(struct nvme_global_ctx *ctx, const char *config_file) return err; } -int nvme_dump_config(struct nvme_global_ctx *ctx, int fd) +LIBNVME_PUBLIC int nvme_dump_config(struct nvme_global_ctx *ctx, int fd) { return json_update_config(ctx, fd); } -int nvme_dump_tree(struct nvme_global_ctx *ctx) +LIBNVME_PUBLIC int nvme_dump_tree(struct nvme_global_ctx *ctx) { return json_dump_tree(ctx); } -const char *nvme_get_application(struct nvme_global_ctx *ctx) +LIBNVME_PUBLIC const char *nvme_get_application(struct nvme_global_ctx *ctx) { return ctx->application; } -void nvme_set_application(struct nvme_global_ctx *ctx, const char *a) +LIBNVME_PUBLIC void nvme_set_application( + struct nvme_global_ctx *ctx, + const char *a) { free(ctx->application); ctx->application = NULL; @@ -369,50 +382,54 @@ void nvme_set_application(struct nvme_global_ctx *ctx, const char *a) ctx->application = strdup(a); } -void nvme_skip_namespaces(struct nvme_global_ctx *ctx) +LIBNVME_PUBLIC void nvme_skip_namespaces(struct nvme_global_ctx *ctx) { ctx->create_only = true; } -nvme_host_t nvme_first_host(struct nvme_global_ctx *ctx) +LIBNVME_PUBLIC nvme_host_t nvme_first_host(struct nvme_global_ctx *ctx) { return list_top(&ctx->hosts, struct nvme_host, entry); } -nvme_host_t nvme_next_host(struct nvme_global_ctx *ctx, nvme_host_t h) +LIBNVME_PUBLIC nvme_host_t nvme_next_host( + struct nvme_global_ctx *ctx, + nvme_host_t h) { return h ? list_next(&ctx->hosts, h, entry) : NULL; } -struct nvme_global_ctx *nvme_host_get_global_ctx(nvme_host_t h) +LIBNVME_PUBLIC struct nvme_global_ctx *nvme_host_get_global_ctx(nvme_host_t h) { return h->ctx; } -void nvme_host_set_pdc_enabled(nvme_host_t h, bool enabled) +LIBNVME_PUBLIC void nvme_host_set_pdc_enabled(nvme_host_t h, bool enabled) { h->pdc_enabled_valid = true; h->pdc_enabled = enabled; } -bool nvme_host_is_pdc_enabled(nvme_host_t h, bool fallback) +LIBNVME_PUBLIC bool nvme_host_is_pdc_enabled(nvme_host_t h, bool fallback) { if (h->pdc_enabled_valid) return h->pdc_enabled; return fallback; } -nvme_subsystem_t nvme_first_subsystem(nvme_host_t h) +LIBNVME_PUBLIC nvme_subsystem_t nvme_first_subsystem(nvme_host_t h) { return list_top(&h->subsystems, struct nvme_subsystem, entry); } -nvme_subsystem_t nvme_next_subsystem(nvme_host_t h, nvme_subsystem_t s) +LIBNVME_PUBLIC nvme_subsystem_t nvme_next_subsystem( + nvme_host_t h, + nvme_subsystem_t s) { return s ? list_next(&h->subsystems, s, entry) : NULL; } -void nvme_refresh_topology(struct nvme_global_ctx *ctx) +LIBNVME_PUBLIC void nvme_refresh_topology(struct nvme_global_ctx *ctx) { struct nvme_host *h, *_h; @@ -429,37 +446,39 @@ void nvme_root_release_fds(struct nvme_global_ctx *ctx) nvme_host_release_fds(h); } -nvme_ctrl_t nvme_subsystem_first_ctrl(nvme_subsystem_t s) +LIBNVME_PUBLIC nvme_ctrl_t nvme_subsystem_first_ctrl(nvme_subsystem_t s) { return list_top(&s->ctrls, struct nvme_ctrl, entry); } -nvme_ctrl_t nvme_subsystem_next_ctrl(nvme_subsystem_t s, nvme_ctrl_t c) +LIBNVME_PUBLIC nvme_ctrl_t nvme_subsystem_next_ctrl( + nvme_subsystem_t s, + nvme_ctrl_t c) { return c ? list_next(&s->ctrls, c, entry) : NULL; } -nvme_host_t nvme_subsystem_get_host(nvme_subsystem_t s) +LIBNVME_PUBLIC nvme_host_t nvme_subsystem_get_host(nvme_subsystem_t s) { return s->h; } -nvme_ns_t nvme_subsystem_first_ns(nvme_subsystem_t s) +LIBNVME_PUBLIC nvme_ns_t nvme_subsystem_first_ns(nvme_subsystem_t s) { return list_top(&s->namespaces, struct nvme_ns, entry); } -nvme_ns_t nvme_subsystem_next_ns(nvme_subsystem_t s, nvme_ns_t n) +LIBNVME_PUBLIC nvme_ns_t nvme_subsystem_next_ns(nvme_subsystem_t s, nvme_ns_t n) { return n ? list_next(&s->namespaces, n, entry) : NULL; } -nvme_path_t nvme_namespace_first_path(nvme_ns_t ns) +LIBNVME_PUBLIC nvme_path_t nvme_namespace_first_path(nvme_ns_t ns) { return list_top(&ns->head->paths, struct nvme_path, nentry); } -nvme_path_t nvme_namespace_next_path(nvme_ns_t ns, nvme_path_t p) +LIBNVME_PUBLIC nvme_path_t nvme_namespace_next_path(nvme_ns_t ns, nvme_path_t p) { return p ? list_next(&ns->head->paths, p, nentry) : NULL; } @@ -484,7 +503,7 @@ static void __nvme_free_ns(struct nvme_ns *n) } /* Stub for SWIG */ -void nvme_free_ns(struct nvme_ns *n) +LIBNVME_PUBLIC void nvme_free_ns(struct nvme_ns *n) { __nvme_free_ns(n); } @@ -513,7 +532,7 @@ static void __nvme_free_subsystem(struct nvme_subsystem *s) free(s); } -void nvme_subsystem_release_fds(struct nvme_subsystem *s) +LIBNVME_PUBLIC void nvme_subsystem_release_fds(struct nvme_subsystem *s) { struct nvme_ctrl *c, *_c; struct nvme_ns *n, *_n; @@ -528,7 +547,7 @@ void nvme_subsystem_release_fds(struct nvme_subsystem *s) /* * Stub for SWIG */ -void nvme_free_subsystem(nvme_subsystem_t s) +LIBNVME_PUBLIC void nvme_free_subsystem(nvme_subsystem_t s) { } @@ -577,7 +596,7 @@ struct nvme_subsystem *nvme_lookup_subsystem(struct nvme_host *h, return nvme_alloc_subsystem(h, name, subsysnqn); } -int nvme_get_subsystem(struct nvme_global_ctx *ctx, +LIBNVME_PUBLIC int nvme_get_subsystem(struct nvme_global_ctx *ctx, struct nvme_host *h, const char *name, const char *subsysnqn, struct nvme_subsystem **subsys) { @@ -606,7 +625,7 @@ void __nvme_free_host(struct nvme_host *h) free(h); } -void nvme_host_release_fds(struct nvme_host *h) +LIBNVME_PUBLIC void nvme_host_release_fds(struct nvme_host *h) { struct nvme_subsystem *s, *_s; @@ -615,7 +634,7 @@ void nvme_host_release_fds(struct nvme_host *h) } /* Stub for SWIG */ -void nvme_free_host(struct nvme_host *h) +LIBNVME_PUBLIC void nvme_free_host(struct nvme_host *h) { __nvme_free_host(h); } @@ -781,17 +800,17 @@ static int nvme_scan_subsystem(struct nvme_global_ctx *ctx, const char *name) return 0; } -nvme_ctrl_t nvme_path_get_ctrl(nvme_path_t p) +LIBNVME_PUBLIC nvme_ctrl_t nvme_path_get_ctrl(nvme_path_t p) { return p->c; } -nvme_ns_t nvme_path_get_ns(nvme_path_t p) +LIBNVME_PUBLIC nvme_ns_t nvme_path_get_ns(nvme_path_t p) { return p->n; } -int nvme_path_get_queue_depth(nvme_path_t p) +LIBNVME_PUBLIC int nvme_path_get_queue_depth(nvme_path_t p) { _cleanup_free_ char *queue_depth = NULL; @@ -861,7 +880,8 @@ static int nvme_ctrl_scan_path(struct nvme_global_ctx *ctx, struct nvme_ctrl *c, return 0; } -struct nvme_transport_handle *nvme_ctrl_get_transport_handle(nvme_ctrl_t c) +LIBNVME_PUBLIC struct nvme_transport_handle *nvme_ctrl_get_transport_handle( + nvme_ctrl_t c) { if (!c->hdl) { int err; @@ -875,7 +895,7 @@ struct nvme_transport_handle *nvme_ctrl_get_transport_handle(nvme_ctrl_t c) return c->hdl; } -void nvme_ctrl_release_transport_handle(nvme_ctrl_t c) +LIBNVME_PUBLIC void nvme_ctrl_release_transport_handle(nvme_ctrl_t c) { if (!c->hdl) return; @@ -884,18 +904,21 @@ void nvme_ctrl_release_transport_handle(nvme_ctrl_t c) c->hdl = NULL; } -nvme_subsystem_t nvme_ctrl_get_subsystem(nvme_ctrl_t c) +LIBNVME_PUBLIC nvme_subsystem_t nvme_ctrl_get_subsystem(nvme_ctrl_t c) { return c->s; } -const char *nvme_ctrl_get_subsysnqn(nvme_ctrl_t c) +LIBNVME_PUBLIC const char *nvme_ctrl_get_subsysnqn(nvme_ctrl_t c) { return c->s ? c->s->subsysnqn : c->subsysnqn; } -char *nvme_ctrl_get_src_addr(nvme_ctrl_t c, char *src_addr, size_t src_addr_len) +LIBNVME_PUBLIC char *nvme_ctrl_get_src_addr( + nvme_ctrl_t c, + char *src_addr, + size_t src_addr_len) { size_t l; char *p; @@ -921,12 +944,12 @@ char *nvme_ctrl_get_src_addr(nvme_ctrl_t c, char *src_addr, size_t src_addr_len) return src_addr; } -const char *nvme_ctrl_get_phy_slot(nvme_ctrl_t c) +LIBNVME_PUBLIC const char *nvme_ctrl_get_phy_slot(nvme_ctrl_t c) { return c->phy_slot ? c->phy_slot : ""; } -const char *nvme_ctrl_get_state(nvme_ctrl_t c) +LIBNVME_PUBLIC const char *nvme_ctrl_get_state(nvme_ctrl_t c) { char *state = c->state; @@ -935,12 +958,12 @@ const char *nvme_ctrl_get_state(nvme_ctrl_t c) return c->state; } -struct nvme_fabrics_config *nvme_ctrl_get_config(nvme_ctrl_t c) +LIBNVME_PUBLIC struct nvme_fabrics_config *nvme_ctrl_get_config(nvme_ctrl_t c) { return &c->cfg; } -int nvme_ctrl_identify(nvme_ctrl_t c, struct nvme_id_ctrl *id) +LIBNVME_PUBLIC int nvme_ctrl_identify(nvme_ctrl_t c, struct nvme_id_ctrl *id) { struct nvme_transport_handle *hdl = nvme_ctrl_get_transport_handle(c); struct nvme_passthru_cmd cmd; @@ -949,22 +972,22 @@ int nvme_ctrl_identify(nvme_ctrl_t c, struct nvme_id_ctrl *id) return nvme_submit_admin_passthru(hdl, &cmd); } -nvme_ns_t nvme_ctrl_first_ns(nvme_ctrl_t c) +LIBNVME_PUBLIC nvme_ns_t nvme_ctrl_first_ns(nvme_ctrl_t c) { return list_top(&c->namespaces, struct nvme_ns, entry); } -nvme_ns_t nvme_ctrl_next_ns(nvme_ctrl_t c, nvme_ns_t n) +LIBNVME_PUBLIC nvme_ns_t nvme_ctrl_next_ns(nvme_ctrl_t c, nvme_ns_t n) { return n ? list_next(&c->namespaces, n, entry) : NULL; } -nvme_path_t nvme_ctrl_first_path(nvme_ctrl_t c) +LIBNVME_PUBLIC nvme_path_t nvme_ctrl_first_path(nvme_ctrl_t c) { return list_top(&c->paths, struct nvme_path, entry); } -nvme_path_t nvme_ctrl_next_path(nvme_ctrl_t c, nvme_path_t p) +LIBNVME_PUBLIC nvme_path_t nvme_ctrl_next_path(nvme_ctrl_t c, nvme_path_t p) { return p ? list_next(&c->paths, p, entry) : NULL; } @@ -995,7 +1018,7 @@ void nvme_deconfigure_ctrl(nvme_ctrl_t c) FREE_CTRL_ATTR(c->phy_slot); } -int nvme_disconnect_ctrl(nvme_ctrl_t c) +LIBNVME_PUBLIC int nvme_disconnect_ctrl(nvme_ctrl_t c) { struct nvme_global_ctx *ctx = c->s && c->s->h ? c->s->h->ctx : NULL; int ret; @@ -1012,7 +1035,7 @@ int nvme_disconnect_ctrl(nvme_ctrl_t c) return 0; } -void nvme_unlink_ctrl(nvme_ctrl_t c) +LIBNVME_PUBLIC void nvme_unlink_ctrl(nvme_ctrl_t c) { list_del_init(&c->entry); c->s = NULL; @@ -1042,7 +1065,7 @@ static void __nvme_free_ctrl(nvme_ctrl_t c) free(c); } -void nvme_free_ctrl(nvme_ctrl_t c) +LIBNVME_PUBLIC void nvme_free_ctrl(nvme_ctrl_t c) { __nvme_free_ctrl(c); } @@ -1064,14 +1087,14 @@ static bool traddr_is_hostname(const char *transport, const char *traddr) return true; } -void nvmf_default_config(struct nvme_fabrics_config *cfg) +LIBNVME_PUBLIC void nvmf_default_config(struct nvme_fabrics_config *cfg) { memset(cfg, 0, sizeof(*cfg)); cfg->tos = -1; cfg->ctrl_loss_tmo = NVMF_DEF_CTRL_LOSS_TMO; } -int nvme_create_ctrl(struct nvme_global_ctx *ctx, +LIBNVME_PUBLIC int nvme_create_ctrl(struct nvme_global_ctx *ctx, const char *subsysnqn, const char *transport, const char *traddr, const char *host_traddr, const char *host_iface, const char *trsvcid, @@ -1471,10 +1494,14 @@ nvme_ctrl_t __nvme_lookup_ctrl(nvme_subsystem_t s, const char *transport, return matching_c; } -bool nvme_ctrl_match_config(struct nvme_ctrl *c, const char *transport, - const char *traddr, const char *trsvcid, - const char *subsysnqn, const char *host_traddr, - const char *host_iface) +LIBNVME_PUBLIC bool nvme_ctrl_match_config( + struct nvme_ctrl *c, + const char *transport, + const char *traddr, + const char *trsvcid, + const char *subsysnqn, + const char *host_traddr, + const char *host_iface) { struct candidate_args candidate = {}; ctrl_match_t ctrl_match; @@ -1767,7 +1794,7 @@ static int nvme_reconfigure_ctrl(struct nvme_global_ctx *ctx, nvme_ctrl_t c, con return 0; } -int nvme_init_ctrl(nvme_host_t h, nvme_ctrl_t c, int instance) +LIBNVME_PUBLIC int nvme_init_ctrl(nvme_host_t h, nvme_ctrl_t c, int instance) { _cleanup_free_ char *subsys_name = NULL, *name = NULL, *path = NULL; nvme_subsystem_t s; @@ -1908,8 +1935,10 @@ int nvme_ctrl_alloc(struct nvme_global_ctx *ctx, nvme_subsystem_t s, return 0; } -int nvme_scan_ctrl(struct nvme_global_ctx *ctx, const char *name, - nvme_ctrl_t *cp) +LIBNVME_PUBLIC int nvme_scan_ctrl( + struct nvme_global_ctx *ctx, + const char *name, + nvme_ctrl_t *cp) { _cleanup_free_ char *subsysnqn = NULL, *subsysname = NULL; _cleanup_free_ char *hostnqn = NULL, *hostid = NULL; @@ -1975,7 +2004,7 @@ int nvme_scan_ctrl(struct nvme_global_ctx *ctx, const char *name, return 0; } -void nvme_rescan_ctrl(struct nvme_ctrl *c) +LIBNVME_PUBLIC void nvme_rescan_ctrl(struct nvme_ctrl *c) { struct nvme_global_ctx *ctx = c->s && c->s->h ? c->s->h->ctx : NULL; if (!c->s) @@ -2029,12 +2058,12 @@ void nvme_ns_release_transport_handle(nvme_ns_t n) n->hdl = NULL; } -nvme_subsystem_t nvme_ns_get_subsystem(nvme_ns_t n) +LIBNVME_PUBLIC nvme_subsystem_t nvme_ns_get_subsystem(nvme_ns_t n) { return n->s; } -nvme_ctrl_t nvme_ns_get_ctrl(nvme_ns_t n) +LIBNVME_PUBLIC nvme_ctrl_t nvme_ns_get_ctrl(nvme_ns_t n) { return n->c; } @@ -2044,47 +2073,49 @@ const char *nvme_ns_head_get_sysfs_dir(nvme_ns_head_t head) return head->sysfs_dir; } -const char *nvme_ns_get_generic_name(nvme_ns_t n) +LIBNVME_PUBLIC const char *nvme_ns_get_generic_name(nvme_ns_t n) { return n->generic_name; } -const char *nvme_ns_get_model(nvme_ns_t n) +LIBNVME_PUBLIC const char *nvme_ns_get_model(nvme_ns_t n) { return n->c ? n->c->model : n->s->model; } -const char *nvme_ns_get_serial(nvme_ns_t n) +LIBNVME_PUBLIC const char *nvme_ns_get_serial(nvme_ns_t n) { return n->c ? n->c->serial : n->s->serial; } -const char *nvme_ns_get_firmware(nvme_ns_t n) +LIBNVME_PUBLIC const char *nvme_ns_get_firmware(nvme_ns_t n) { return n->c ? n->c->firmware : n->s->firmware; } -enum nvme_csi nvme_ns_get_csi(nvme_ns_t n) +LIBNVME_PUBLIC enum nvme_csi nvme_ns_get_csi(nvme_ns_t n) { return n->csi; } -const uint8_t *nvme_ns_get_eui64(nvme_ns_t n) +LIBNVME_PUBLIC const uint8_t *nvme_ns_get_eui64(nvme_ns_t n) { return n->eui64; } -const uint8_t *nvme_ns_get_nguid(nvme_ns_t n) +LIBNVME_PUBLIC const uint8_t *nvme_ns_get_nguid(nvme_ns_t n) { return n->nguid; } -void nvme_ns_get_uuid(nvme_ns_t n, unsigned char out[NVME_UUID_LEN]) +LIBNVME_PUBLIC void nvme_ns_get_uuid( + nvme_ns_t n, + unsigned char out[NVME_UUID_LEN]) { memcpy(out, n->uuid, NVME_UUID_LEN); } -int nvme_ns_identify(nvme_ns_t n, struct nvme_id_ns *ns) +LIBNVME_PUBLIC int nvme_ns_identify(nvme_ns_t n, struct nvme_id_ns *ns) { struct nvme_transport_handle *hdl; struct nvme_passthru_cmd cmd; @@ -2112,7 +2143,7 @@ int nvme_ns_identify_descs(nvme_ns_t n, struct nvme_ns_id_desc *descs) return nvme_submit_admin_passthru(hdl, &cmd); } -int nvme_ns_verify(nvme_ns_t n, off_t offset, size_t count) +LIBNVME_PUBLIC int nvme_ns_verify(nvme_ns_t n, off_t offset, size_t count) { struct nvme_transport_handle *hdl; struct nvme_passthru_cmd cmd; @@ -2133,7 +2164,10 @@ int nvme_ns_verify(nvme_ns_t n, off_t offset, size_t count) return nvme_submit_io_passthru(hdl, &cmd); } -int nvme_ns_write_uncorrectable(nvme_ns_t n, off_t offset, size_t count) +LIBNVME_PUBLIC int nvme_ns_write_uncorrectable( + nvme_ns_t n, + off_t offset, + size_t count) { struct nvme_transport_handle *hdl; struct nvme_passthru_cmd cmd; @@ -2154,7 +2188,7 @@ int nvme_ns_write_uncorrectable(nvme_ns_t n, off_t offset, size_t count) return nvme_submit_io_passthru(hdl, &cmd); } -int nvme_ns_write_zeros(nvme_ns_t n, off_t offset, size_t count) +LIBNVME_PUBLIC int nvme_ns_write_zeros(nvme_ns_t n, off_t offset, size_t count) { struct nvme_transport_handle *hdl; struct nvme_passthru_cmd cmd; @@ -2174,7 +2208,11 @@ int nvme_ns_write_zeros(nvme_ns_t n, off_t offset, size_t count) return nvme_submit_io_passthru(hdl, &cmd); } -int nvme_ns_write(nvme_ns_t n, void *buf, off_t offset, size_t count) +LIBNVME_PUBLIC int nvme_ns_write( + nvme_ns_t n, + void *buf, + off_t offset, + size_t count) { struct nvme_transport_handle *hdl; struct nvme_passthru_cmd cmd; @@ -2195,7 +2233,11 @@ int nvme_ns_write(nvme_ns_t n, void *buf, off_t offset, size_t count) return nvme_submit_io_passthru(hdl, &cmd); } -int nvme_ns_read(nvme_ns_t n, void *buf, off_t offset, size_t count) +LIBNVME_PUBLIC int nvme_ns_read( + nvme_ns_t n, + void *buf, + off_t offset, + size_t count) { struct nvme_transport_handle *hdl; struct nvme_passthru_cmd cmd; @@ -2216,7 +2258,11 @@ int nvme_ns_read(nvme_ns_t n, void *buf, off_t offset, size_t count) return nvme_submit_io_passthru(hdl, &cmd); } -int nvme_ns_compare(nvme_ns_t n, void *buf, off_t offset, size_t count) +LIBNVME_PUBLIC int nvme_ns_compare( + nvme_ns_t n, + void *buf, + off_t offset, + size_t count) { struct nvme_transport_handle *hdl; struct nvme_passthru_cmd cmd; @@ -2237,7 +2283,7 @@ int nvme_ns_compare(nvme_ns_t n, void *buf, off_t offset, size_t count) return nvme_submit_io_passthru(hdl, &cmd); } -int nvme_ns_flush(nvme_ns_t n) +LIBNVME_PUBLIC int nvme_ns_flush(nvme_ns_t n) { struct nvme_transport_handle *hdl; struct nvme_passthru_cmd cmd; @@ -2550,7 +2596,9 @@ static int __nvme_scan_namespace(struct nvme_global_ctx *ctx, return 0; } -int nvme_scan_namespace(struct nvme_global_ctx *ctx, const char *name, +LIBNVME_PUBLIC int nvme_scan_namespace( + struct nvme_global_ctx *ctx, + const char *name, nvme_ns_t *ns) { return __nvme_scan_namespace(ctx, nvme_ns_sysfs_dir(), name, ns); @@ -2675,8 +2723,9 @@ static int nvme_subsystem_scan_namespace(struct nvme_global_ctx *ctx, nvme_subsy return 0; } -struct nvme_ns *nvme_subsystem_lookup_namespace(struct nvme_subsystem *s, - __u32 nsid) +LIBNVME_PUBLIC struct nvme_ns *nvme_subsystem_lookup_namespace( + struct nvme_subsystem *s, + __u32 nsid) { struct nvme_ns *n; diff --git a/libnvme/src/nvme/tree.h b/libnvme/src/nvme/tree.h index fde0fe11bd..11d4505298 100644 --- a/libnvme/src/nvme/tree.h +++ b/libnvme/src/nvme/tree.h @@ -55,17 +55,6 @@ const char *nvme_get_application(struct nvme_global_ctx *ctx); */ void nvme_skip_namespaces(struct nvme_global_ctx *ctx); -/** - * nvme_release_fds - Close all opened file descriptors in the tree - * @ctx: struct nvme_global_ctx object - * - * Controller and Namespace objects cache the file descriptors - * of opened nvme devices. This API can be used to close and - * clear all cached fds in the tree. - * - */ -void nvme_release_fds(struct nvme_global_ctx *ctx); - /** * nvme_first_host() - Start host iterator * @ctx: struct nvme_global_ctx object diff --git a/libnvme/src/nvme/util.c b/libnvme/src/nvme/util.c index 842a52027f..c7cdbfa813 100644 --- a/libnvme/src/nvme/util.c +++ b/libnvme/src/nvme/util.c @@ -174,7 +174,7 @@ static inline __u8 nvme_fabrics_status_to_errno(__u16 status) return EIO; } -__u8 nvme_status_to_errno(int status, bool fabrics) +LIBNVME_PUBLIC __u8 nvme_status_to_errno(int status, bool fabrics) { __u16 sc; @@ -373,7 +373,7 @@ static const char *arg_str(const char * const *strings, return "unrecognized"; } -const char *nvme_status_to_string(int status, bool fabrics) +LIBNVME_PUBLIC const char *nvme_status_to_string(int status, bool fabrics) { const char *s = "Unknown status"; __u16 sc, sct; @@ -437,14 +437,14 @@ static const char * const libnvme_status[] = { [ENVME_CONNECT_NOKEY] = "pre-shared TLS key is missing" }; -const char *nvme_errno_to_string(int status) +LIBNVME_PUBLIC const char *nvme_errno_to_string(int status) { const char *s = ARGSTR(libnvme_status, status); return s; } -const char *nvme_strerror(int errnum) +LIBNVME_PUBLIC const char *nvme_strerror(int errnum) { if (errnum >= ENVME_CONNECT_RESOLVE) return nvme_errno_to_string(errnum); @@ -705,13 +705,13 @@ size_t get_entity_version(char *buffer, size_t bufsz) return num_bytes; } -struct nvmf_ext_attr *nvmf_exat_ptr_next(struct nvmf_ext_attr *p) +LIBNVME_PUBLIC struct nvmf_ext_attr *nvmf_exat_ptr_next(struct nvmf_ext_attr *p) { return (struct nvmf_ext_attr *) ((uintptr_t)p + (ptrdiff_t)nvmf_exat_size(le16_to_cpu(p->exatlen))); } -const char *nvme_get_version(enum nvme_version type) +LIBNVME_PUBLIC const char *nvme_get_version(enum nvme_version type) { switch(type) { case NVME_VERSION_PROJECT: @@ -723,7 +723,9 @@ const char *nvme_get_version(enum nvme_version type) } } -int nvme_uuid_to_string(unsigned char uuid[NVME_UUID_LEN], char *str) +LIBNVME_PUBLIC int nvme_uuid_to_string( + unsigned char uuid[NVME_UUID_LEN], + char *str) { int n; n = snprintf(str, NVME_UUID_LEN_STRING, @@ -735,7 +737,9 @@ int nvme_uuid_to_string(unsigned char uuid[NVME_UUID_LEN], char *str) return n != NVME_UUID_LEN_STRING - 1 ? -EINVAL : 0; } -int nvme_uuid_from_string(const char *str, unsigned char uuid[NVME_UUID_LEN]) +LIBNVME_PUBLIC int nvme_uuid_from_string( + const char *str, + unsigned char uuid[NVME_UUID_LEN]) { int n; @@ -749,7 +753,7 @@ int nvme_uuid_from_string(const char *str, unsigned char uuid[NVME_UUID_LEN]) } -int nvme_random_uuid(unsigned char uuid[NVME_UUID_LEN]) +LIBNVME_PUBLIC int nvme_random_uuid(unsigned char uuid[NVME_UUID_LEN]) { _cleanup_fd_ int f = -1; ssize_t n; @@ -774,7 +778,8 @@ int nvme_random_uuid(unsigned char uuid[NVME_UUID_LEN]) return 0; } -int nvme_find_uuid(struct nvme_id_uuid_list *uuid_list, +LIBNVME_PUBLIC int nvme_find_uuid( + struct nvme_id_uuid_list *uuid_list, const unsigned char uuid[NVME_UUID_LEN]) { const unsigned char uuid_end[NVME_UUID_LEN] = {0}; diff --git a/libnvme/test/meson.build b/libnvme/test/meson.build index 5f952a3509..035070a992 100644 --- a/libnvme/test/meson.build +++ b/libnvme/test/meson.build @@ -5,6 +5,18 @@ # # Authors: Martin Belanger +python3_prog = find_program('python3', required: false) +if python3_prog.found() + test( + 'libnvme - check-public-symbols', + python3_prog, + args: [ + files('../tools/check-public-symbols.py'), + meson.project_source_root() / 'libnvme', + ], + ) +endif + # These tests all require interaction with a real NVMe device, so we don't # define as meson unit-tests, and therefore get run as part of the 'test' # target. However, they're available for developer use, when hardware is diff --git a/libnvme/tools/check-public-symbols.py b/libnvme/tools/check-public-symbols.py new file mode 100644 index 0000000000..b2208bc63e --- /dev/null +++ b/libnvme/tools/check-public-symbols.py @@ -0,0 +1,95 @@ +#!/usr/bin/env python3 +# 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 +# +# Verify that LIBNVME_PUBLIC annotations and version-script entries are +# kept in sync: +# +# 1. Every function definition annotated with LIBNVME_PUBLIC in a .c +# file must appear in one of the three version scripts (libnvme.ld, +# libnvmf.ld, accessors.ld). A function that is annotated but not +# listed is visible to the compiler but silently hidden by the linker +# version script's "local: *;" catch-all — the developer's intent to +# export it would be silently ignored. +# +# 2. Every symbol listed in a version script must have a LIBNVME_PUBLIC +# annotation on its definition. Without the annotation the symbol is +# hidden at compile time (due to -fvisibility=hidden) and the build +# will either fail to link or produce a .so that is missing the symbol. +# +# Usage (standalone): +# python3 tools/check-public-symbols.py [LIBNVME-SOURCE-ROOT] +# +# The source root defaults to the parent directory of this script. + +import re +import sys +import pathlib + +ROOT = pathlib.Path(sys.argv[1]) if len(sys.argv) > 1 else \ + pathlib.Path(__file__).resolve().parent.parent + +SRC_DIR = ROOT / 'src' / 'nvme' +LD_FILES = [ + ROOT / 'src' / 'libnvme.ld', + ROOT / 'src' / 'libnvmf.ld', + ROOT / 'src' / 'accessors.ld', +] + +# --------------------------------------------------------------------------- +# Collect symbols listed in the version scripts +# --------------------------------------------------------------------------- +ld_syms = {} # symbol -> Path of the .ld file that declares it + +for ld_path in LD_FILES: + if not ld_path.exists(): + continue + for line in ld_path.read_text().splitlines(): + m = re.match(r'^\s+([a-z]\w+);', line) + if m: + ld_syms[m.group(1)] = ld_path + +# --------------------------------------------------------------------------- +# Collect function names annotated with LIBNVME_PUBLIC in .c files +# --------------------------------------------------------------------------- +# Match: LIBNVME_PUBLIC [*] function_name( +# The .*\b is greedy so it skips over the return type and any __attribute__ +# qualifiers, leaving the last identifier before '(' as the function name. +PUB_RE = re.compile(r'^LIBNVME_PUBLIC\b.*\b([a-z_]\w+)\s*\(', re.MULTILINE) + +pub_syms = {} # symbol -> Path of the .c file that defines it + +for c_path in sorted(SRC_DIR.glob('*.c')): + for m in PUB_RE.finditer(c_path.read_text()): + sym = m.group(1) + pub_syms[sym] = c_path + +# --------------------------------------------------------------------------- +# Report mismatches +# --------------------------------------------------------------------------- +errors = 0 + +# Check 1: LIBNVME_PUBLIC in .c but missing from all .ld files +for sym, c_path in sorted(pub_syms.items()): + if sym not in ld_syms: + print(f'ERROR: {sym}() is annotated LIBNVME_PUBLIC in ' + f'{c_path.name} but is not listed in any version script') + errors += 1 + +# Check 2: listed in a .ld file but no LIBNVME_PUBLIC definition found +for sym, ld_path in sorted(ld_syms.items()): + if sym not in pub_syms: + print(f'ERROR: {sym}() is listed in {ld_path.name} but has no ' + f'LIBNVME_PUBLIC definition in {SRC_DIR.name}/*.c') + errors += 1 + +if errors: + print(f'\n{errors} error(s) found.') + sys.exit(1) + +print(f'OK: {len(pub_syms)} LIBNVME_PUBLIC symbols all present in version ' + f'scripts; {len(ld_syms)} version-script entries all annotated.') diff --git a/libnvme/tools/generator/generate-accessors.c b/libnvme/tools/generator/generate-accessors.c index 149e151242..b06b2edc8d 100644 --- a/libnvme/tools/generator/generate-accessors.c +++ b/libnvme/tools/generator/generate-accessors.c @@ -1312,6 +1312,14 @@ static void struct_list_parse(StructList_t *sl, const char *text, Conf_t *conf) #define LINE_FITS_80_NTABS(n, fmt, ...) \ (snprintf(NULL, 0, fmt, ##__VA_ARGS__) + (n) * 7 <= 80) +/* + * PUB() prepends "LIBNVME_PUBLIC " to a string literal at compile time. + * Used in emit_src_*() to annotate generated function definitions. + * Header declarations (emit_hdr_*) are intentionally left unannotated so + * that installed public headers remain free of build-internal attributes. + */ +#define PUB(s) "LIBNVME_PUBLIC " s + /** * @brief Return the separator to place between a C type and a function name. * @@ -1509,14 +1517,14 @@ 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)", + if (LINE_FITS_80(PUB("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", + PUB("void %s" SET_FMT "(struct %s *p, const char *%s)") "\n", prefix, sname, mname, sname, mname); else fprintf(f, - "void %s" SET_FMT "(\n" + PUB("void %s" SET_FMT "(") "\n" "\t\tstruct %s *p,\n" "\t\tconst char *%s)\n", prefix, sname, mname, sname, mname); @@ -1551,14 +1559,14 @@ static void emit_src_setter_dynstr(FILE *f, const char *prefix, 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)", + if (LINE_FITS_80(PUB("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", + PUB("void %s" SET_FMT "(struct %s *p, const char *%s)") "\n", prefix, sname, mname, sname, mname); else fprintf(f, - "void %s" SET_FMT "(\n" + PUB("void %s" SET_FMT "(") "\n" "\t\tstruct %s *p,\n" "\t\tconst char *%s)\n", prefix, sname, mname, sname, mname); @@ -1594,10 +1602,10 @@ static void emit_src_setter_chararray(FILE *f, const char *prefix, 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)", + if (LINE_FITS_80(PUB("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" + PUB("void %s" SET_FMT "(struct %s *p, %s %s)") "\n" "{\n" "\tp->%s = %s;\n" "}\n\n", @@ -1606,7 +1614,7 @@ static void emit_src_setter_val(FILE *f, const char *prefix, mname, mname); else fprintf(f, - "void %s" SET_FMT "(\n" + PUB("void %s" SET_FMT "(") "\n" "\t\tstruct %s *p,\n" "\t\t%s %s)\n" "{\n" @@ -1631,10 +1639,10 @@ static void emit_src_setter_val(FILE *f, const char *prefix, 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)", + if (LINE_FITS_80(PUB("%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" + PUB("%s%s%s" GET_FMT "(const struct %s *p)") "\n" "{\n" "\treturn p->%s;\n" "}\n\n", @@ -1642,7 +1650,7 @@ static void emit_src_getter(FILE *f, const char *prefix, sname, mname); else fprintf(f, - "%s%s%s" GET_FMT "(\n" + PUB("%s%s%s" GET_FMT "(") "\n" "\t\tconst struct %s *p)\n" "{\n" "\treturn p->%s;\n"