From f4a1c73a323683813e09030afb78ba8e7173241b Mon Sep 17 00:00:00 2001 From: Daniel Wagner Date: Mon, 7 Jul 2025 21:37:07 +0200 Subject: [PATCH 01/66] api-types: move nvme_root_t to new place Signed-off-by: Daniel Wagner --- examples/discover-loop.c | 2 +- examples/display-tree.c | 2 +- examples/telemetry-listen.c | 2 +- libnvme/nvme.i | 2 +- src/libnvme.map | 2 +- src/nvme/api-types.h | 21 +++++++++++++++++++++ src/nvme/log.h | 2 +- src/nvme/tree.c | 2 +- src/nvme/tree.h | 20 +------------------- test/config/config-dump.c | 2 +- test/config/hostnqn-order.c | 6 +++--- test/config/psk-json.c | 2 +- test/cpp.cc | 2 +- test/sysfs/tree-dump.c | 2 +- test/test.c | 4 ++-- test/tree.c | 8 ++++---- test/zns.c | 2 +- 17 files changed, 43 insertions(+), 40 deletions(-) diff --git a/examples/discover-loop.c b/examples/discover-loop.c index 752806713..4f445e21e 100644 --- a/examples/discover-loop.c +++ b/examples/discover-loop.c @@ -86,7 +86,7 @@ int main() else print_discover_log(log); - nvme_free_tree(r); + nvme_free_root(r); free(log); return 0; } diff --git a/examples/display-tree.c b/examples/display-tree.c index b9ea75f89..bf523f4c4 100644 --- a/examples/display-tree.c +++ b/examples/display-tree.c @@ -67,6 +67,6 @@ int main() } } } - nvme_free_tree(r); + nvme_free_root(r); return 0; } diff --git a/examples/telemetry-listen.c b/examples/telemetry-listen.c index e38a8adf9..eb0b040d0 100644 --- a/examples/telemetry-listen.c +++ b/examples/telemetry-listen.c @@ -162,7 +162,7 @@ int main() } wait_events(&fds, e, i); - nvme_free_tree(r); + nvme_free_root(r); free(e); return EXIT_SUCCESS; diff --git a/libnvme/nvme.i b/libnvme/nvme.i index 4ede50e74..47d722186 100644 --- a/libnvme/nvme.i +++ b/libnvme/nvme.i @@ -451,7 +451,7 @@ struct nvme_ns { return nvme_scan(config_file); } ~nvme_root() { - nvme_free_tree($self); + nvme_free_root($self); } void log_level(const char *level) { int log_level = DEFAULT_LOGLEVEL; diff --git a/src/libnvme.map b/src/libnvme.map index ba5c8d569..dc2b3e8f7 100644 --- a/src/libnvme.map +++ b/src/libnvme.map @@ -78,8 +78,8 @@ LIBNVME_2_0 { nvme_free_ctrl; nvme_free_host; nvme_free_ns; + nvme_free_root; nvme_free_subsystem; - nvme_free_tree; nvme_free_uri; nvme_fw_commit; nvme_fw_download; diff --git a/src/nvme/api-types.h b/src/nvme/api-types.h index 149ba22c7..d213962c9 100644 --- a/src/nvme/api-types.h +++ b/src/nvme/api-types.h @@ -13,10 +13,31 @@ #ifndef _LIBNVME_API_TYPES_H #define _LIBNVME_API_TYPES_H +#include #include #include +struct nvme_root; +typedef struct nvme_root *nvme_root_t; + +/** + * nvme_create_root() - Initialize root object + * @fp: File descriptor for logging messages + * @log_level: Logging level to use + * + * Return: Initialized &nvme_root_t object + */ +nvme_root_t nvme_create_root(FILE *fp, int log_level); + +/** + * nvme_free_root() - Free root object + * @r: &nvme_root_t object + * + * Free an &nvme_root_t object and all attached objects + */ +void nvme_free_root(nvme_root_t r); + /* * _args struct definitions. These are used by both the ioctl-based and * MI-based interfaces, as the call interface for (admin/io/etc) NVMe commands, diff --git a/src/nvme/log.h b/src/nvme/log.h index 5a2f81c1b..cd0d5f8de 100644 --- a/src/nvme/log.h +++ b/src/nvme/log.h @@ -69,7 +69,7 @@ int nvme_get_logging_level(nvme_root_t r, bool *log_pid, bool *log_tstamp); * via the arguments use the the default one which can be set via this call. * When creating a new root object with @nvme_create_root the global root object * will be set as well. This means the global root object is always pointing to - * the latest created root object. Note the first @nvme_free_tree call will reset + * the latest created root object. Note the first @nvme_free_root call will reset * the global root object. * * This function is deprecated. Use nvme_init_default_logging or/and diff --git a/src/nvme/tree.c b/src/nvme/tree.c index 9aaaa1b50..875fd6f18 100644 --- a/src/nvme/tree.c +++ b/src/nvme/tree.c @@ -518,7 +518,7 @@ void nvme_refresh_topology(nvme_root_t r) nvme_scan_topology(r, NULL, NULL); } -void nvme_free_tree(nvme_root_t r) +void nvme_free_root(nvme_root_t r) { struct nvme_host *h, *_h; diff --git a/src/nvme/tree.h b/src/nvme/tree.h index e0377b231..10267ccfe 100644 --- a/src/nvme/tree.h +++ b/src/nvme/tree.h @@ -10,7 +10,6 @@ #ifndef _LIBNVME_TREE_H #define _LIBNVME_TREE_H -#include #include #include @@ -19,6 +18,7 @@ #include #include +#include /** * DOC: tree.h @@ -32,20 +32,10 @@ typedef struct nvme_path *nvme_path_t; typedef struct nvme_ctrl *nvme_ctrl_t; typedef struct nvme_subsystem *nvme_subsystem_t; typedef struct nvme_host *nvme_host_t; -typedef struct nvme_root *nvme_root_t; typedef bool (*nvme_scan_filter_t)(nvme_subsystem_t, nvme_ctrl_t, nvme_ns_t, void *); -/** - * nvme_create_root() - Initialize root object - * @fp: File descriptor for logging messages - * @log_level: Logging level to use - * - * Return: Initialized &nvme_root_t object - */ -nvme_root_t nvme_create_root(FILE *fp, int log_level); - /** * nvme_root_set_application - Specify managing application * @r: &nvme_root_t object @@ -82,14 +72,6 @@ void nvme_root_skip_namespaces(nvme_root_t r); */ void nvme_root_release_fds(nvme_root_t r); -/** - * nvme_free_tree() - Free root object - * @r: &nvme_root_t object - * - * Free an &nvme_root_t object and all attached objects - */ -void nvme_free_tree(nvme_root_t r); - /** * nvme_first_host() - Start host iterator * @r: &nvme_root_t object diff --git a/test/config/config-dump.c b/test/config/config-dump.c index c0c8e7313..bc781fb76 100644 --- a/test/config/config-dump.c +++ b/test/config/config-dump.c @@ -38,7 +38,7 @@ static bool config_dump(const char *file) pass = true; out: - nvme_free_tree(r); + nvme_free_root(r); return pass; } diff --git a/test/config/hostnqn-order.c b/test/config/hostnqn-order.c index 22fc2278e..b7df61ece 100644 --- a/test/config/hostnqn-order.c +++ b/test/config/hostnqn-order.c @@ -50,7 +50,7 @@ static bool command_line(void) pass = true; out: - nvme_free_tree(r); + nvme_free_root(r); return pass; } @@ -101,7 +101,7 @@ static bool json_config(char *file) pass = true; out: - nvme_free_tree(r); + nvme_free_root(r); return pass; } @@ -147,7 +147,7 @@ static bool from_file(void) pass = true; out: - nvme_free_tree(r); + nvme_free_root(r); return pass; } diff --git a/test/config/psk-json.c b/test/config/psk-json.c index a96ebf1b8..5d0c8bbff 100644 --- a/test/config/psk-json.c +++ b/test/config/psk-json.c @@ -74,7 +74,7 @@ static bool psk_json_test(char *file) pass = true; out: - nvme_free_tree(r); + nvme_free_root(r); return pass; } diff --git a/test/cpp.cc b/test/cpp.cc index a6bbf42fd..07d4522ad 100644 --- a/test/cpp.cc +++ b/test/cpp.cc @@ -61,7 +61,7 @@ int main() } } std::cout << "\n"; - nvme_free_tree(r); + nvme_free_root(r); return 0; } diff --git a/test/sysfs/tree-dump.c b/test/sysfs/tree-dump.c index bcf871b36..3cee349f7 100644 --- a/test/sysfs/tree-dump.c +++ b/test/sysfs/tree-dump.c @@ -34,7 +34,7 @@ static bool tree_dump(void) pass = true; out: - nvme_free_tree(r); + nvme_free_root(r); return pass; } diff --git a/test/test.c b/test/test.c index 6655083ea..15d17d4cb 100644 --- a/test/test.c +++ b/test/test.c @@ -358,7 +358,7 @@ int main(int argc, char **argv) nvme_free_ctrl(c); } printf("\n"); - nvme_free_tree(r); + nvme_free_root(r); r = nvme_scan(NULL); if (!r) @@ -426,7 +426,7 @@ int main(int argc, char **argv) } } } - nvme_free_tree(r); + nvme_free_root(r); return 0; } diff --git a/test/tree.c b/test/tree.c index c9370f971..6c6b144f8 100644 --- a/test/tree.c +++ b/test/tree.c @@ -261,7 +261,7 @@ static bool test_lookup(void) pass = count_entries(r) == ARRAY_SIZE(test_data); pass &= ctrl_lookups(r); - nvme_free_tree(r); + nvme_free_root(r); return pass; } @@ -407,7 +407,7 @@ static bool test_src_addr() c->address = NULL; /* Needed to avoid freeing non-malloced memory (see above) */ - nvme_free_tree(r); + nvme_free_root(r); return pass; } @@ -524,7 +524,7 @@ static bool ctrl_match(const char *tag, reference_ctrl->name = NULL; reference_ctrl->address = NULL; - nvme_free_tree(r); + nvme_free_root(r); return true; } @@ -1111,7 +1111,7 @@ static bool ctrl_config_match(const char *tag, reference_ctrl->name = NULL; reference_ctrl->address = NULL; - nvme_free_tree(r); + nvme_free_root(r); return true; } diff --git a/test/zns.c b/test/zns.c index 6d06d7257..c2a22afd3 100644 --- a/test/zns.c +++ b/test/zns.c @@ -86,5 +86,5 @@ int main() } } } - nvme_free_tree(r); + nvme_free_root(r); } From 0fefaee111801242188ccfe2dfe35dd52e8176c1 Mon Sep 17 00:00:00 2001 From: Daniel Wagner Date: Mon, 26 May 2025 17:44:38 +0200 Subject: [PATCH 02/66] src: introduce link handle Abstract the file descriptor handle to a more abstract type so it's possible to use different 'backends' to send/receive commands, e.g. via MI instead direct. The name 'link' was choosen because this name is not in use and thus we avoid overloading existing names, such ctrl. The specification is using 'link' to describe the connection on a PCI bus which is kind of matching how the handle is used in the library. It is the means to talk to a controller. Signed-off-by: Daniel Wagner --- examples/telemetry-listen.c | 2 +- libnvme/nvme.i | 2 +- src/libnvme.map | 9 +- src/nvme/api-types.h | 4 +- src/nvme/fabrics.c | 32 +- src/nvme/ioctl.c | 531 +++++++++--------- src/nvme/ioctl.h | 1042 +++++++++++++++++------------------ src/nvme/linux.c | 114 ++-- src/nvme/linux.h | 64 ++- src/nvme/private.h | 27 +- src/nvme/tree.c | 88 ++- src/nvme/tree.h | 39 +- src/nvme/util.c | 6 +- test/ioctl/ana.c | 33 +- test/ioctl/discovery.c | 10 +- test/ioctl/features.c | 152 ++--- test/ioctl/identify.c | 62 ++- test/ioctl/logs.c | 94 ++-- test/ioctl/misc.c | 143 ++--- test/ioctl/zns.c | 18 +- test/test.c | 84 +-- test/zns.c | 6 +- 22 files changed, 1290 insertions(+), 1272 deletions(-) diff --git a/examples/telemetry-listen.c b/examples/telemetry-listen.c index eb0b040d0..886e9c74d 100644 --- a/examples/telemetry-listen.c +++ b/examples/telemetry-listen.c @@ -45,7 +45,7 @@ static void save_telemetry(nvme_ctrl_t c) time_t s; /* Clear the log (rae == false) at the end to see new telemetry events later */ - ret = nvme_get_ctrl_telemetry(nvme_ctrl_get_fd(c), false, &log, NVME_TELEMETRY_DA_3, &log_size); + ret = nvme_get_ctrl_telemetry(nvme_ctrl_get_link(c), false, &log, NVME_TELEMETRY_DA_3, &log_size); if (ret) return; diff --git a/libnvme/nvme.i b/libnvme/nvme.i index 47d722186..d8585ce2c 100644 --- a/libnvme/nvme.i +++ b/libnvme/nvme.i @@ -773,7 +773,7 @@ struct nvme_ns { int ret = 0; Py_BEGIN_ALLOW_THREADS /* Release Python GIL */ - ret = nvme_get_log_supported_log_pages(nvme_ctrl_get_fd($self), rae, &log); + ret = nvme_get_log_supported_log_pages(nvme_ctrl_get_link($self), rae, &log); Py_END_ALLOW_THREADS /* Reacquire Python GIL */ if (ret < 0) { diff --git a/src/libnvme.map b/src/libnvme.map index dc2b3e8f7..6d52da677 100644 --- a/src/libnvme.map +++ b/src/libnvme.map @@ -7,6 +7,7 @@ LIBNVME_2_0 { nvme_admin_passthru64; nvme_admin_passthru; nvme_capacity_mgmt; + nvme_close; nvme_copy; nvme_create_ctrl; nvme_create_root; @@ -19,11 +20,11 @@ LIBNVME_2_0 { nvme_ctrl_get_config; nvme_ctrl_get_dhchap_host_key; nvme_ctrl_get_dhchap_key; - nvme_ctrl_get_fd; nvme_ctrl_get_firmware; nvme_ctrl_get_host_iface; nvme_ctrl_get_host_traddr; nvme_ctrl_get_keyring; + nvme_ctrl_get_link; nvme_ctrl_get_model; nvme_ctrl_get_name; nvme_ctrl_get_numa_node; @@ -47,7 +48,7 @@ LIBNVME_2_0 { nvme_ctrl_is_unique_discovery_ctrl; nvme_ctrl_next_ns; nvme_ctrl_next_path; - nvme_ctrl_release_fd; + nvme_ctrl_release_link; nvme_ctrl_reset; nvme_ctrl_set_dhchap_host_key; nvme_ctrl_set_dhchap_key; @@ -254,12 +255,12 @@ LIBNVME_2_0 { nvme_ns_get_csi; nvme_ns_get_ctrl; nvme_ns_get_eui64; - nvme_ns_get_fd; nvme_ns_get_firmware; nvme_ns_get_generic_name; nvme_ns_get_lba_count; nvme_ns_get_lba_size; nvme_ns_get_lba_util; + nvme_ns_get_link; nvme_ns_get_meta_size; nvme_ns_get_model; nvme_ns_get_name; @@ -272,7 +273,7 @@ LIBNVME_2_0 { nvme_ns_identify; nvme_ns_mgmt; nvme_ns_read; - nvme_ns_release_fd; + nvme_ns_release_link; nvme_ns_rescan; nvme_ns_verify; nvme_ns_write; diff --git a/src/nvme/api-types.h b/src/nvme/api-types.h index d213962c9..68d49801d 100644 --- a/src/nvme/api-types.h +++ b/src/nvme/api-types.h @@ -20,6 +20,8 @@ struct nvme_root; typedef struct nvme_root *nvme_root_t; +struct nvme_link; +typedef struct nvme_link *nvme_link_t; /** * nvme_create_root() - Initialize root object @@ -279,7 +281,6 @@ struct nvme_fw_download_args { /** * struct nvme_fw_commit_args - Arguments for the NVMe Firmware Commit command * @args_size: Size of &struct nvme_fw_commit_args - * @fd: File descriptor of nvme device * @action: Action to use for the firmware image, see &enum nvme_fw_commit_ca * @timeout: Timeout in ms * @result: The command completion result from CQE dword0 @@ -289,7 +290,6 @@ struct nvme_fw_download_args { struct nvme_fw_commit_args { __u32 *result; int args_size; - int fd; __u32 timeout; enum nvme_fw_commit_ca action; __u8 slot; diff --git a/src/nvme/fabrics.c b/src/nvme/fabrics.c index 6aa62eea5..3c011f2bf 100644 --- a/src/nvme/fabrics.c +++ b/src/nvme/fabrics.c @@ -1131,12 +1131,11 @@ nvme_ctrl_t nvmf_connect_disc_entry(nvme_host_t h, static struct nvmf_discovery_log *nvme_discovery_log( const struct nvme_get_discovery_args *args) { - nvme_root_t r = root_from_ctrl(args->c); struct nvmf_discovery_log *log; int retries = 0; const char *name = nvme_ctrl_get_name(args->c); uint64_t genctr, numrec; - int fd = nvme_ctrl_get_fd(args->c); + nvme_link_t l = nvme_ctrl_get_link(args->c); struct nvme_get_log_args log_args = { .result = args->result, .args_size = sizeof(log_args), @@ -1151,18 +1150,18 @@ static struct nvmf_discovery_log *nvme_discovery_log( log = __nvme_alloc(sizeof(*log)); if (!log) { - nvme_msg(r, LOG_ERR, + nvme_msg(l->root, LOG_ERR, "could not allocate memory for discovery log header\n"); errno = ENOMEM; return NULL; } - nvme_msg(r, LOG_DEBUG, "%s: get header (try %d/%d)\n", + nvme_msg(l->root, LOG_DEBUG, "%s: get header (try %d/%d)\n", name, retries, args->max_retries); log_args.log = log; log_args.len = DISCOVERY_HEADER_LEN; - if (nvme_get_log_page(fd, NVME_LOG_PAGE_PDU_SIZE, &log_args)) { - nvme_msg(r, LOG_INFO, + if (nvme_get_log_page(l, NVME_LOG_PAGE_PDU_SIZE, &log_args)) { + nvme_msg(l->root, LOG_INFO, "%s: discover try %d/%d failed, error %d\n", name, retries, args->max_retries, errno); goto out_free_log; @@ -1181,21 +1180,21 @@ static struct nvmf_discovery_log *nvme_discovery_log( entries_size = sizeof(*log->entries) * numrec; log = __nvme_alloc(sizeof(*log) + entries_size); if (!log) { - nvme_msg(r, LOG_ERR, + nvme_msg(l->root, LOG_ERR, "could not alloc memory for discovery log page\n"); errno = ENOMEM; return NULL; } - nvme_msg(r, LOG_DEBUG, + nvme_msg(l->root, LOG_DEBUG, "%s: get %" PRIu64 " records (genctr %" PRIu64 ")\n", name, numrec, genctr); log_args.lpo = sizeof(*log); log_args.log = log->entries; log_args.len = entries_size; - if (nvme_get_log_page(fd, NVME_LOG_PAGE_PDU_SIZE, &log_args)) { - nvme_msg(r, LOG_INFO, + if (nvme_get_log_page(l, NVME_LOG_PAGE_PDU_SIZE, &log_args)) { + nvme_msg(l->root, LOG_INFO, "%s: discover try %d/%d failed, error %d\n", name, retries, args->max_retries, errno); goto out_free_log; @@ -1205,13 +1204,13 @@ static struct nvmf_discovery_log *nvme_discovery_log( * If the log page was read with multiple Get Log Page commands, * genctr must be checked afterwards to ensure atomicity */ - nvme_msg(r, LOG_DEBUG, "%s: get header again\n", name); + nvme_msg(l->root, LOG_DEBUG, "%s: get header again\n", name); log_args.lpo = 0; log_args.log = log; log_args.len = DISCOVERY_HEADER_LEN; - if (nvme_get_log_page(fd, NVME_LOG_PAGE_PDU_SIZE, &log_args)) { - nvme_msg(r, LOG_INFO, + if (nvme_get_log_page(l, NVME_LOG_PAGE_PDU_SIZE, &log_args)) { + nvme_msg(l->root, LOG_INFO, "%s: discover try %d/%d failed, error %d\n", name, retries, args->max_retries, errno); goto out_free_log; @@ -1220,10 +1219,10 @@ static struct nvmf_discovery_log *nvme_discovery_log( ++retries < args->max_retries); if (genctr != le64_to_cpu(log->genctr)) { - nvme_msg(r, LOG_INFO, "%s: discover genctr mismatch\n", name); + nvme_msg(l->root, LOG_INFO, "%s: discover genctr mismatch\n", name); errno = EAGAIN; } else if (numrec != le64_to_cpu(log->numrec)) { - nvme_msg(r, LOG_INFO, + nvme_msg(l->root, LOG_INFO, "%s: numrec changed unexpectedly " "from %" PRIu64 " to %" PRIu64 "\n", name, numrec, le64_to_cpu(log->numrec)); @@ -1624,7 +1623,6 @@ static int nvmf_dim(nvme_ctrl_t c, enum nvmf_dim_tas tas, __u8 trtype, struct nvme_dim_args args = { .args_size = sizeof(args), - .fd = nvme_ctrl_get_fd(c), .result = result, .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, .tas = tas @@ -1703,7 +1701,7 @@ static int nvmf_dim(nvme_ctrl_t c, enum nvmf_dim_tas tas, __u8 trtype, args.data_len = tdl; args.data = dim; - return nvme_dim_send(&args); + return nvme_dim_send(nvme_ctrl_get_link(c), &args); } /** diff --git a/src/nvme/ioctl.c b/src/nvme/ioctl.c index 567358916..7bc646bd3 100644 --- a/src/nvme/ioctl.c +++ b/src/nvme/ioctl.c @@ -29,11 +29,12 @@ #include "ioctl.h" #include "util.h" #include "log.h" +#include "private.h" -static int nvme_verify_chr(int fd) +static int nvme_verify_chr(nvme_link_t l) { static struct stat nvme_stat; - int err = fstat(fd, &nvme_stat); + int err = fstat(l->fd, &nvme_stat); if (err < 0) return errno; @@ -45,49 +46,49 @@ static int nvme_verify_chr(int fd) return 0; } -int nvme_subsystem_reset(int fd) +int nvme_subsystem_reset(nvme_link_t l) { int ret; - ret = nvme_verify_chr(fd); + ret = nvme_verify_chr(l); if (ret) return ret; - return ioctl(fd, NVME_IOCTL_SUBSYS_RESET); + return ioctl(l->fd, NVME_IOCTL_SUBSYS_RESET); } -int nvme_ctrl_reset(int fd) +int nvme_ctrl_reset(nvme_link_t l) { int ret; - ret = nvme_verify_chr(fd); + ret = nvme_verify_chr(l); if (ret) return ret; - return ioctl(fd, NVME_IOCTL_RESET); + return ioctl(l->fd, NVME_IOCTL_RESET); } -int nvme_ns_rescan(int fd) +int nvme_ns_rescan(nvme_link_t l) { int ret; - ret = nvme_verify_chr(fd); + ret = nvme_verify_chr(l); if (ret) return ret; - return ioctl(fd, NVME_IOCTL_RESCAN); + return ioctl(l->fd, NVME_IOCTL_RESCAN); } -int nvme_get_nsid(int fd, __u32 *nsid) +int nvme_get_nsid(nvme_link_t l, __u32 *nsid) { errno = 0; - *nsid = ioctl(fd, NVME_IOCTL_ID); + *nsid = ioctl(l->fd, NVME_IOCTL_ID); return -1 * (errno != 0); } __attribute__((weak)) -int nvme_submit_passthru64(int fd, unsigned long ioctl_cmd, +int nvme_submit_passthru64(nvme_link_t l, unsigned long ioctl_cmd, struct nvme_passthru_cmd64 *cmd, __u64 *result) { - int err = ioctl(fd, ioctl_cmd, cmd); + int err = ioctl(l->fd, ioctl_cmd, cmd); if (err >= 0 && result) *result = cmd->result; @@ -95,17 +96,17 @@ int nvme_submit_passthru64(int fd, unsigned long ioctl_cmd, } __attribute__((weak)) -int nvme_submit_passthru(int fd, unsigned long ioctl_cmd, +int nvme_submit_passthru(nvme_link_t l, unsigned long ioctl_cmd, struct nvme_passthru_cmd *cmd, __u32 *result) { - int err = ioctl(fd, ioctl_cmd, cmd); + int err = ioctl(l->fd, ioctl_cmd, cmd); if (err >= 0 && result) *result = cmd->result; return err; } -static int nvme_passthru64(int fd, unsigned long ioctl_cmd, __u8 opcode, +static int nvme_passthru64(nvme_link_t l, unsigned long ioctl_cmd, __u8 opcode, __u8 flags, __u16 rsvd, __u32 nsid, __u32 cdw2, __u32 cdw3, __u32 cdw10, __u32 cdw11, __u32 cdw12, __u32 cdw13, __u32 cdw14, __u32 cdw15, @@ -132,10 +133,10 @@ static int nvme_passthru64(int fd, unsigned long ioctl_cmd, __u8 opcode, .timeout_ms = timeout_ms, }; - return nvme_submit_passthru64(fd, ioctl_cmd, &cmd, result); + return nvme_submit_passthru64(l, ioctl_cmd, &cmd, result); } -static int nvme_passthru(int fd, unsigned long ioctl_cmd, __u8 opcode, +static int nvme_passthru(nvme_link_t l, unsigned long ioctl_cmd, __u8 opcode, __u8 flags, __u16 rsvd, __u32 nsid, __u32 cdw2, __u32 cdw3, __u32 cdw10, __u32 cdw11, __u32 cdw12, __u32 cdw13, __u32 cdw14, __u32 cdw15, __u32 data_len, @@ -162,41 +163,41 @@ static int nvme_passthru(int fd, unsigned long ioctl_cmd, __u8 opcode, .timeout_ms = timeout_ms, }; - return nvme_submit_passthru(fd, ioctl_cmd, &cmd, result); + return nvme_submit_passthru(l, ioctl_cmd, &cmd, result); } -int nvme_submit_admin_passthru64(int fd, struct nvme_passthru_cmd64 *cmd, +int nvme_submit_admin_passthru64(nvme_link_t l, struct nvme_passthru_cmd64 *cmd, __u64 *result) { - return nvme_submit_passthru64(fd, NVME_IOCTL_ADMIN64_CMD, cmd, result); + return nvme_submit_passthru64(l, NVME_IOCTL_ADMIN64_CMD, cmd, result); } -int nvme_admin_passthru64(int fd, __u8 opcode, __u8 flags, __u16 rsvd, +int nvme_admin_passthru64(nvme_link_t l, __u8 opcode, __u8 flags, __u16 rsvd, __u32 nsid, __u32 cdw2, __u32 cdw3, __u32 cdw10, __u32 cdw11, __u32 cdw12, __u32 cdw13, __u32 cdw14, __u32 cdw15, __u32 data_len, void *data, __u32 metadata_len, void *metadata, __u32 timeout_ms, __u64 *result) { - return nvme_passthru64(fd, NVME_IOCTL_ADMIN64_CMD, opcode, flags, rsvd, + return nvme_passthru64(l, NVME_IOCTL_ADMIN64_CMD, opcode, flags, rsvd, nsid, cdw2, cdw3, cdw10, cdw11, cdw12, cdw13, cdw14, cdw15, data_len, data, metadata_len, metadata, timeout_ms, result); } -int nvme_submit_admin_passthru(int fd, struct nvme_passthru_cmd *cmd, __u32 *result) +int nvme_submit_admin_passthru(nvme_link_t l, struct nvme_passthru_cmd *cmd, __u32 *result) { - return nvme_submit_passthru(fd, NVME_IOCTL_ADMIN_CMD, cmd, result); + return nvme_submit_passthru(l, NVME_IOCTL_ADMIN_CMD, cmd, result); } -int nvme_admin_passthru(int fd, __u8 opcode, __u8 flags, __u16 rsvd, +int nvme_admin_passthru(nvme_link_t l, __u8 opcode, __u8 flags, __u16 rsvd, __u32 nsid, __u32 cdw2, __u32 cdw3, __u32 cdw10, __u32 cdw11, __u32 cdw12, __u32 cdw13, __u32 cdw14, __u32 cdw15, __u32 data_len, void *data, __u32 metadata_len, void *metadata, __u32 timeout_ms, __u32 *result) { - return nvme_passthru(fd, NVME_IOCTL_ADMIN_CMD, opcode, flags, rsvd, + return nvme_passthru(l, NVME_IOCTL_ADMIN_CMD, opcode, flags, rsvd, nsid, cdw2, cdw3, cdw10, cdw11, cdw12, cdw13, cdw14, cdw15, data_len, data, metadata_len, metadata, timeout_ms, result); @@ -257,7 +258,7 @@ enum features { NVME_FEATURES_IOCSP_IOCSCI_MASK = 0xff, }; -int nvme_identify(struct nvme_identify_args *args) +int nvme_identify(nvme_link_t l, struct nvme_identify_args *args) { __u32 cdw10 = NVME_SET(args->cntid, IDENTIFY_CDW10_CNTID) | NVME_SET(args->cns, IDENTIFY_CDW10_CNS); @@ -280,10 +281,10 @@ int nvme_identify(struct nvme_identify_args *args) errno = EINVAL; return -1; } - return nvme_submit_admin_passthru(args->fd, &cmd, args->result); + return nvme_submit_admin_passthru(l, &cmd, args->result); } -int nvme_get_log(struct nvme_get_log_args *args) +int nvme_get_log(nvme_link_t l, struct nvme_get_log_args *args) { __u32 numd = (args->len >> 2) - 1; __u16 numdu = numd >> 16, numdl = numd & 0xffff; @@ -317,7 +318,7 @@ int nvme_get_log(struct nvme_get_log_args *args) errno = EINVAL; return -1; } - return nvme_submit_admin_passthru(args->fd, &cmd, args->result); + return nvme_submit_admin_passthru(l, &cmd, args->result); } static bool force_4k; @@ -371,7 +372,8 @@ static void nvme_uring_cmd_exit(struct io_uring *ring) io_uring_queue_exit(ring); } -static int nvme_uring_cmd_admin_passthru_async(struct io_uring *ring, struct nvme_get_log_args *args) +static int nvme_uring_cmd_admin_passthru_async(nvme_link_t l, struct io_uring *ring, + struct nvme_get_log_args *args) { struct io_uring_sqe *sqe; struct nvme_uring_cmd *cmd; @@ -413,7 +415,7 @@ static int nvme_uring_cmd_admin_passthru_async(struct io_uring *ring, struct nvm cmd->cdw14 = cdw14, cmd->timeout_ms = args->timeout, - sqe->fd = args->fd; + sqe->fd = l->fd; sqe->opcode = IORING_OP_URING_CMD; sqe->cmd_op = NVME_URING_CMD_ADMIN; sqe->user_data = (__u64)(uintptr_t)args; @@ -455,7 +457,7 @@ static int nvme_uring_cmd_wait_complete(struct io_uring *ring, int n) } #endif -int nvme_get_log_page(int fd, __u32 xfer_len, struct nvme_get_log_args *args) +int nvme_get_log_page(nvme_link_t l, __u32 xfer_len, struct nvme_get_log_args *args) { __u64 offset = 0, xfer, data_len = args->len; __u64 start = args->lpo; @@ -463,8 +465,6 @@ int nvme_get_log_page(int fd, __u32 xfer_len, struct nvme_get_log_args *args) void *ptr = args->log; int ret; - args->fd = fd; - if (force_4k) xfer_len = NVME_LOG_PAGE_PDU_SIZE; @@ -475,7 +475,7 @@ int nvme_get_log_page(int fd, __u32 xfer_len, struct nvme_get_log_args *args) bool use_uring = false; if (io_uring_kernel_support == IO_URING_AVAILABLE) { - if (fstat(fd, &st) == 0 && S_ISCHR(st.st_mode)) { + if (fstat(l->fd, &st) == 0 && S_ISCHR(st.st_mode)) { use_uring = true; if (nvme_uring_cmd_setup(&ring)) @@ -512,13 +512,13 @@ int nvme_get_log_page(int fd, __u32 xfer_len, struct nvme_get_log_args *args) n = 0; } n += 1; - ret = nvme_uring_cmd_admin_passthru_async(&ring, args); + ret = nvme_uring_cmd_admin_passthru_async(l, &ring, args); if (ret) nvme_uring_cmd_exit(&ring); } else #endif - ret = nvme_get_log(args); + ret = nvme_get_log(l, args); if (ret) return ret; @@ -537,7 +537,7 @@ int nvme_get_log_page(int fd, __u32 xfer_len, struct nvme_get_log_args *args) return 0; } -static int read_ana_chunk(int fd, enum nvme_log_ana_lsp lsp, bool rae, +static int read_ana_chunk(nvme_link_t l, enum nvme_log_ana_lsp lsp, bool rae, __u8 *log, __u8 **read, __u8 *to_read, __u8 *log_end) { if (to_read > log_end) { @@ -549,7 +549,7 @@ static int read_ana_chunk(int fd, enum nvme_log_ana_lsp lsp, bool rae, __u32 len = min_t(__u32, log_end - *read, NVME_LOG_PAGE_PDU_SIZE); int ret; - ret = nvme_get_log_ana(fd, lsp, rae, *read - log, len, *read); + ret = nvme_get_log_ana(l, lsp, rae, *read - log, len, *read); if (ret) return ret; @@ -558,7 +558,7 @@ static int read_ana_chunk(int fd, enum nvme_log_ana_lsp lsp, bool rae, return 0; } -static int try_read_ana(int fd, enum nvme_log_ana_lsp lsp, bool rae, +static int try_read_ana(nvme_link_t l, enum nvme_log_ana_lsp lsp, bool rae, struct nvme_ana_log *log, __u8 *log_end, __u8 *read, __u8 **to_read, bool *may_retry) { @@ -570,7 +570,7 @@ static int try_read_ana(int fd, enum nvme_log_ana_lsp lsp, bool rae, __le32 nnsids; *to_read += sizeof(*log->descs); - ret = read_ana_chunk(fd, lsp, rae, + ret = read_ana_chunk(l, lsp, rae, (__u8 *)log, &read, *to_read, log_end); if (ret) { /* @@ -592,7 +592,7 @@ static int try_read_ana(int fd, enum nvme_log_ana_lsp lsp, bool rae, group + offsetof(struct nvme_ana_group_desc, nnsids), sizeof(nnsids)); *to_read += le32_to_cpu(nnsids) * sizeof(__le32); - ret = read_ana_chunk(fd, lsp, rae, + ret = read_ana_chunk(l, lsp, rae, (__u8 *)log, &read, *to_read, log_end); if (ret) { *may_retry = errno == ENOSPC; @@ -604,7 +604,7 @@ static int try_read_ana(int fd, enum nvme_log_ana_lsp lsp, bool rae, return 0; } -int nvme_get_ana_log_atomic(int fd, bool rgo, bool rae, unsigned int retries, +int nvme_get_ana_log_atomic(nvme_link_t l, bool rgo, bool rae, unsigned int retries, struct nvme_ana_log *log, __u32 *len) { const enum nvme_log_ana_lsp lsp = @@ -621,7 +621,7 @@ int nvme_get_ana_log_atomic(int fd, bool rgo, bool rae, unsigned int retries, } to_read = (__u8 *)log->descs; - ret = read_ana_chunk(fd, lsp, rae, + ret = read_ana_chunk(l, lsp, rae, (__u8 *)log, &read, to_read, log_end); if (ret) return ret; @@ -632,7 +632,7 @@ int nvme_get_ana_log_atomic(int fd, bool rgo, bool rae, unsigned int retries, int saved_errno; __le64 chgcnt; - saved_ret = try_read_ana(fd, lsp, rae, log, log_end, + saved_ret = try_read_ana(l, lsp, rae, log, log_end, read, &to_read, &may_retry); /* * If the log page was read with multiple Get Log Page commands, @@ -646,7 +646,7 @@ int nvme_get_ana_log_atomic(int fd, bool rgo, bool rae, unsigned int retries, chgcnt = log->chgcnt; read = (__u8 *)log; to_read = (__u8 *)log->descs; - ret = read_ana_chunk(fd, lsp, rae, + ret = read_ana_chunk(l, lsp, rae, (__u8 *)log, &read, to_read, log_end); if (ret) return ret; @@ -662,7 +662,7 @@ int nvme_get_ana_log_atomic(int fd, bool rgo, bool rae, unsigned int retries, return -1; } -int nvme_set_features(struct nvme_set_features_args *args) +int nvme_set_features(nvme_link_t l, struct nvme_set_features_args *args) { __u32 cdw10 = NVME_SET(args->fid, FEATURES_CDW10_FID) | NVME_SET(!!args->save, SET_FEATURES_CDW10_SAVE); @@ -685,15 +685,14 @@ int nvme_set_features(struct nvme_set_features_args *args) errno = EINVAL; return -1; } - return nvme_submit_admin_passthru(args->fd, &cmd, args->result); + return nvme_submit_admin_passthru(l, &cmd, args->result); } -static int __nvme_set_features(int fd, __u8 fid, __u32 cdw11, bool save, +static int __nvme_set_features(nvme_link_t l, __u8 fid, __u32 cdw11, bool save, __u32 *result) { struct nvme_set_features_args args = { .args_size = sizeof(args), - .fd = fd, .fid = fid, .nsid = NVME_NSID_NONE, .cdw11 = cdw11, @@ -706,10 +705,10 @@ static int __nvme_set_features(int fd, __u8 fid, __u32 cdw11, bool save, .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, .result = result, }; - return nvme_set_features(&args); + return nvme_set_features(l, &args); } -int nvme_set_features_arbitration(int fd, __u8 ab, __u8 lpw, __u8 mpw, +int nvme_set_features_arbitration(nvme_link_t l, __u8 ab, __u8 lpw, __u8 mpw, __u8 hpw, bool save, __u32 *result) { __u32 value = NVME_SET(ab, FEAT_ARBITRATION_BURST) | @@ -717,29 +716,29 @@ int nvme_set_features_arbitration(int fd, __u8 ab, __u8 lpw, __u8 mpw, NVME_SET(mpw, FEAT_ARBITRATION_MPW) | NVME_SET(hpw, FEAT_ARBITRATION_HPW); - return __nvme_set_features(fd, NVME_FEAT_FID_ARBITRATION, value, save, + return __nvme_set_features(l, NVME_FEAT_FID_ARBITRATION, value, save, result); } -int nvme_set_features_power_mgmt(int fd, __u8 ps, __u8 wh, bool save, +int nvme_set_features_power_mgmt(nvme_link_t l, __u8 ps, __u8 wh, bool save, __u32 *result) { __u32 value = NVME_SET(ps, FEAT_PWRMGMT_PS) | NVME_SET(wh, FEAT_PWRMGMT_WH); - return __nvme_set_features(fd, NVME_FEAT_FID_POWER_MGMT, value, save, + return __nvme_set_features(l, NVME_FEAT_FID_POWER_MGMT, value, save, result); } -int nvme_set_features_lba_range(int fd, __u32 nsid, __u8 nr_ranges, bool save, +int nvme_set_features_lba_range(nvme_link_t l, __u32 nsid, __u8 nr_ranges, bool save, struct nvme_lba_range_type *data, __u32 *result) { return nvme_set_features_data( - fd, NVME_FEAT_FID_LBA_RANGE, nsid, nr_ranges - 1, save, + l, NVME_FEAT_FID_LBA_RANGE, nsid, nr_ranges - 1, save, sizeof(*data), data, result); } -int nvme_set_features_temp_thresh(int fd, __u16 tmpth, __u8 tmpsel, +int nvme_set_features_temp_thresh(nvme_link_t l, __u16 tmpth, __u8 tmpsel, enum nvme_feat_tmpthresh_thsel thsel, __u8 tmpthh, bool save, __u32 *result) { @@ -748,105 +747,104 @@ int nvme_set_features_temp_thresh(int fd, __u16 tmpth, __u8 tmpsel, NVME_SET(thsel, FEAT_TT_THSEL) | NVME_SET(tmpthh, FEAT_TT_TMPTHH); - return __nvme_set_features(fd, NVME_FEAT_FID_TEMP_THRESH, value, save, + return __nvme_set_features(l, NVME_FEAT_FID_TEMP_THRESH, value, save, result); } -int nvme_set_features_err_recovery(int fd, __u32 nsid, __u16 tler, bool dulbe, +int nvme_set_features_err_recovery(nvme_link_t l, __u32 nsid, __u16 tler, bool dulbe, bool save, __u32 *result) { __u32 value = NVME_SET(tler, FEAT_ERROR_RECOVERY_TLER) | NVME_SET(!!dulbe, FEAT_ERROR_RECOVERY_DULBE); return nvme_set_features_simple( - fd, NVME_FEAT_FID_ERR_RECOVERY, nsid, value, save, result); + l, NVME_FEAT_FID_ERR_RECOVERY, nsid, value, save, result); } -int nvme_set_features_volatile_wc(int fd, bool wce, bool save, __u32 *result) +int nvme_set_features_volatile_wc(nvme_link_t l, bool wce, bool save, __u32 *result) { __u32 value = NVME_SET(!!wce, FEAT_VWC_WCE); - return __nvme_set_features(fd, NVME_FEAT_FID_VOLATILE_WC, value, save, + return __nvme_set_features(l, NVME_FEAT_FID_VOLATILE_WC, value, save, result); } -int nvme_set_features_irq_coalesce(int fd, __u8 thr, __u8 time, bool save, +int nvme_set_features_irq_coalesce(nvme_link_t l, __u8 thr, __u8 time, bool save, __u32 *result) { __u32 value = NVME_SET(thr, FEAT_IRQC_THR) | NVME_SET(time, FEAT_IRQC_TIME); - return __nvme_set_features(fd, NVME_FEAT_FID_IRQ_COALESCE, value, save, + return __nvme_set_features(l, NVME_FEAT_FID_IRQ_COALESCE, value, save, result); } -int nvme_set_features_irq_config(int fd, __u16 iv, bool cd, bool save, +int nvme_set_features_irq_config(nvme_link_t l, __u16 iv, bool cd, bool save, __u32 *result) { __u32 value = NVME_SET(iv, FEAT_ICFG_IV) | NVME_SET(!!cd, FEAT_ICFG_CD); - return __nvme_set_features(fd, NVME_FEAT_FID_IRQ_CONFIG, value, save, + return __nvme_set_features(l, NVME_FEAT_FID_IRQ_CONFIG, value, save, result); } -int nvme_set_features_write_atomic(int fd, bool dn, bool save, __u32 *result) +int nvme_set_features_write_atomic(nvme_link_t l, bool dn, bool save, __u32 *result) { __u32 value = NVME_SET(!!dn, FEAT_WA_DN); - return __nvme_set_features(fd, NVME_FEAT_FID_WRITE_ATOMIC, value, save, + return __nvme_set_features(l, NVME_FEAT_FID_WRITE_ATOMIC, value, save, result); } -int nvme_set_features_async_event(int fd, __u32 events, +int nvme_set_features_async_event(nvme_link_t l, __u32 events, bool save, __u32 *result) { - return __nvme_set_features(fd, NVME_FEAT_FID_ASYNC_EVENT, events, save, + return __nvme_set_features(l, NVME_FEAT_FID_ASYNC_EVENT, events, save, result); } -int nvme_set_features_auto_pst(int fd, bool apste, bool save, +int nvme_set_features_auto_pst(nvme_link_t l, bool apste, bool save, struct nvme_feat_auto_pst *apst, __u32 *result) { - return nvme_set_features_data(fd, NVME_FEAT_FID_AUTO_PST, + return nvme_set_features_data(l, NVME_FEAT_FID_AUTO_PST, NVME_NSID_NONE, NVME_SET(!!apste, FEAT_APST_APSTE), save, sizeof(*apst), apst, result); } -int nvme_set_features_timestamp(int fd, bool save, __u64 timestamp) +int nvme_set_features_timestamp(nvme_link_t l, bool save, __u64 timestamp) { __le64 t = cpu_to_le64(timestamp); struct nvme_timestamp ts = {}; memcpy(ts.timestamp, &t, sizeof(ts.timestamp)); - return nvme_set_features_data(fd, NVME_FEAT_FID_TIMESTAMP, + return nvme_set_features_data(l, NVME_FEAT_FID_TIMESTAMP, NVME_NSID_NONE, 0, save, sizeof(ts), &ts, NULL); } -int nvme_set_features_hctm(int fd, __u16 tmt2, __u16 tmt1, +int nvme_set_features_hctm(nvme_link_t l, __u16 tmt2, __u16 tmt1, bool save, __u32 *result) { __u32 value = NVME_SET(tmt2, FEAT_HCTM_TMT2) | NVME_SET(tmt1, FEAT_HCTM_TMT1); - return __nvme_set_features(fd, NVME_FEAT_FID_HCTM, value, save, + return __nvme_set_features(l, NVME_FEAT_FID_HCTM, value, save, result); } -int nvme_set_features_nopsc(int fd, bool noppme, bool save, __u32 *result) +int nvme_set_features_nopsc(nvme_link_t l, bool noppme, bool save, __u32 *result) { __u32 value = NVME_SET(noppme, FEAT_NOPS_NOPPME); - return __nvme_set_features(fd, NVME_FEAT_FID_NOPSC, value, save, + return __nvme_set_features(l, NVME_FEAT_FID_NOPSC, value, save, result); } -int nvme_set_features_rrl(int fd, __u8 rrl, __u16 nvmsetid, +int nvme_set_features_rrl(nvme_link_t l, __u8 rrl, __u16 nvmsetid, bool save, __u32 *result) { struct nvme_set_features_args args = { .args_size = sizeof(args), - .fd = fd, .fid = NVME_FEAT_FID_RRL, .nsid = NVME_NSID_NONE, .cdw11 = nvmsetid, @@ -860,15 +858,14 @@ int nvme_set_features_rrl(int fd, __u8 rrl, __u16 nvmsetid, .result = result, }; - return nvme_set_features(&args); + return nvme_set_features(l, &args); } -int nvme_set_features_plm_config(int fd, bool plm, __u16 nvmsetid, bool save, +int nvme_set_features_plm_config(nvme_link_t l, bool plm, __u16 nvmsetid, bool save, struct nvme_plm_config *data, __u32 *result) { struct nvme_set_features_args args = { .args_size = sizeof(args), - .fd = fd, .fid = NVME_FEAT_FID_PLM_CONFIG, .nsid = NVME_NSID_NONE, .cdw11 = nvmsetid, @@ -882,16 +879,15 @@ int nvme_set_features_plm_config(int fd, bool plm, __u16 nvmsetid, bool save, .result = result, }; - return nvme_set_features(&args); + return nvme_set_features(l, &args); } -int nvme_set_features_plm_window(int fd, enum nvme_feat_plm_window_select sel, +int nvme_set_features_plm_window(nvme_link_t l, enum nvme_feat_plm_window_select sel, __u16 nvmsetid, bool save, __u32 *result) { __u32 cdw12 = NVME_SET(sel, FEAT_PLMW_WS); struct nvme_set_features_args args = { .args_size = sizeof(args), - .fd = fd, .fid = NVME_FEAT_FID_PLM_WINDOW, .nsid = NVME_NSID_NONE, .cdw11 = nvmsetid, @@ -905,88 +901,88 @@ int nvme_set_features_plm_window(int fd, enum nvme_feat_plm_window_select sel, .result = result, }; - return nvme_set_features(&args); + return nvme_set_features(l, &args); } -int nvme_set_features_lba_sts_interval(int fd, __u16 lsiri, __u16 lsipi, +int nvme_set_features_lba_sts_interval(nvme_link_t l, __u16 lsiri, __u16 lsipi, bool save, __u32 *result) { __u32 value = NVME_SET(lsiri, FEAT_LBAS_LSIRI) | NVME_SET(lsipi, FEAT_LBAS_LSIPI); - return __nvme_set_features(fd, NVME_FEAT_FID_LBA_STS_INTERVAL, value, + return __nvme_set_features(l, NVME_FEAT_FID_LBA_STS_INTERVAL, value, save, result); } -int nvme_set_features_host_behavior(int fd, bool save, +int nvme_set_features_host_behavior(nvme_link_t l, bool save, struct nvme_feat_host_behavior *data) { - return nvme_set_features_data(fd, NVME_FEAT_FID_HOST_BEHAVIOR, + return nvme_set_features_data(l, NVME_FEAT_FID_HOST_BEHAVIOR, NVME_NSID_NONE, 0, false, sizeof(*data), data, NULL); } -int nvme_set_features_sanitize(int fd, bool nodrm, bool save, __u32 *result) +int nvme_set_features_sanitize(nvme_link_t l, bool nodrm, bool save, __u32 *result) { - return __nvme_set_features(fd, NVME_FEAT_FID_SANITIZE, !!nodrm, save, + return __nvme_set_features(l, NVME_FEAT_FID_SANITIZE, !!nodrm, save, result); } -int nvme_set_features_endurance_evt_cfg(int fd, __u16 endgid, __u8 egwarn, +int nvme_set_features_endurance_evt_cfg(nvme_link_t l, __u16 endgid, __u8 egwarn, bool save, __u32 *result) { __u32 value = endgid | egwarn << 16; - return __nvme_set_features(fd, NVME_FEAT_FID_ENDURANCE_EVT_CFG, value, + return __nvme_set_features(l, NVME_FEAT_FID_ENDURANCE_EVT_CFG, value, save, result); } -int nvme_set_features_sw_progress(int fd, __u8 pbslc, bool save, +int nvme_set_features_sw_progress(nvme_link_t l, __u8 pbslc, bool save, __u32 *result) { - return __nvme_set_features(fd, NVME_FEAT_FID_SW_PROGRESS, pbslc, save, + return __nvme_set_features(l, NVME_FEAT_FID_SW_PROGRESS, pbslc, save, result); } -int nvme_set_features_host_id(int fd, bool exhid, bool save, __u8 *hostid) +int nvme_set_features_host_id(nvme_link_t l, bool exhid, bool save, __u8 *hostid) { __u32 len = exhid ? 16 : 8; __u32 value = !!exhid; - return nvme_set_features_data(fd, NVME_FEAT_FID_HOST_ID, + return nvme_set_features_data(l, NVME_FEAT_FID_HOST_ID, NVME_NSID_NONE, value, save, len, hostid, NULL); } -int nvme_set_features_resv_mask(int fd, __u32 nsid, __u32 mask, bool save, +int nvme_set_features_resv_mask(nvme_link_t l, __u32 nsid, __u32 mask, bool save, __u32 *result) { return nvme_set_features_simple( - fd, NVME_FEAT_FID_RESV_MASK, nsid, mask, save, result); + l, NVME_FEAT_FID_RESV_MASK, nsid, mask, save, result); } -int nvme_set_features_resv_persist(int fd, __u32 nsid, bool ptpl, bool save, +int nvme_set_features_resv_persist(nvme_link_t l, __u32 nsid, bool ptpl, bool save, __u32 *result) { return nvme_set_features_simple( - fd, NVME_FEAT_FID_RESV_PERSIST, nsid, !!ptpl, save, result); + l, NVME_FEAT_FID_RESV_PERSIST, nsid, !!ptpl, save, result); } -int nvme_set_features_write_protect(int fd, __u32 nsid, +int nvme_set_features_write_protect(nvme_link_t l, __u32 nsid, enum nvme_feat_nswpcfg_state state, bool save, __u32 *result) { return nvme_set_features_simple( - fd, NVME_FEAT_FID_WRITE_PROTECT, nsid, state, false, result); + l, NVME_FEAT_FID_WRITE_PROTECT, nsid, state, false, result); } -int nvme_set_features_iocs_profile(int fd, __u16 iocsi, bool save) +int nvme_set_features_iocs_profile(nvme_link_t l, __u16 iocsi, bool save) { __u32 value = NVME_SET(iocsi, FEAT_IOCSP_IOCSCI); - return __nvme_set_features(fd, NVME_FEAT_FID_IOCS_PROFILE, value, + return __nvme_set_features(l, NVME_FEAT_FID_IOCS_PROFILE, value, save, NULL); } -int nvme_get_features(struct nvme_get_features_args *args) +int nvme_get_features(nvme_link_t l, struct nvme_get_features_args *args) { __u32 cdw10 = NVME_SET(args->fid, FEATURES_CDW10_FID) | NVME_SET(args->sel, GET_FEATURES_CDW10_SEL); @@ -1007,15 +1003,14 @@ int nvme_get_features(struct nvme_get_features_args *args) errno = EINVAL; return -1; } - return nvme_submit_admin_passthru(args->fd, &cmd, args->result); + return nvme_submit_admin_passthru(l, &cmd, args->result); } -static int __nvme_get_features(int fd, enum nvme_features_id fid, +static int __nvme_get_features(nvme_link_t l, enum nvme_features_id fid, enum nvme_get_features_sel sel, __u32 *result) { struct nvme_get_features_args args = { .args_size = sizeof(args), - .fd = fd, .fid = fid, .nsid = NVME_NSID_NONE, .sel = sel, @@ -1027,28 +1022,27 @@ static int __nvme_get_features(int fd, enum nvme_features_id fid, .result = result, }; - return nvme_get_features(&args); + return nvme_get_features(l, &args); } -int nvme_get_features_arbitration(int fd, enum nvme_get_features_sel sel, +int nvme_get_features_arbitration(nvme_link_t l, enum nvme_get_features_sel sel, __u32 *result) { - return __nvme_get_features(fd, NVME_FEAT_FID_ARBITRATION, sel, result); + return __nvme_get_features(l, NVME_FEAT_FID_ARBITRATION, sel, result); } -int nvme_get_features_power_mgmt(int fd, enum nvme_get_features_sel sel, +int nvme_get_features_power_mgmt(nvme_link_t l, enum nvme_get_features_sel sel, __u32 *result) { - return __nvme_get_features(fd, NVME_FEAT_FID_POWER_MGMT, sel, result); + return __nvme_get_features(l, NVME_FEAT_FID_POWER_MGMT, sel, result); } -int nvme_get_features_lba_range(int fd, enum nvme_get_features_sel sel, +int nvme_get_features_lba_range(nvme_link_t l, enum nvme_get_features_sel sel, __u32 nsid, struct nvme_lba_range_type *data, __u32 *result) { struct nvme_get_features_args args = { .args_size = sizeof(args), - .fd = fd, .fid = NVME_FEAT_FID_LBA_RANGE, .nsid = nsid, .sel = sel, @@ -1059,15 +1053,14 @@ int nvme_get_features_lba_range(int fd, enum nvme_get_features_sel sel, .result = result, }; - return nvme_get_features(&args); + return nvme_get_features(l, &args); } -int nvme_get_features_temp_thresh(int fd, enum nvme_get_features_sel sel, __u8 tmpsel, +int nvme_get_features_temp_thresh(nvme_link_t l, enum nvme_get_features_sel sel, __u8 tmpsel, enum nvme_feat_tmpthresh_thsel thsel, __u32 *result) { struct nvme_get_features_args args = { .args_size = sizeof(args), - .fd = fd, .fid = NVME_FEAT_FID_TEMP_THRESH, .nsid = NVME_NSID_NONE, .sel = sel, @@ -1079,16 +1072,15 @@ int nvme_get_features_temp_thresh(int fd, enum nvme_get_features_sel sel, __u8 t .result = result, }; - return nvme_get_features(&args); + return nvme_get_features(l, &args); } -int nvme_get_features_err_recovery(int fd, enum nvme_get_features_sel sel, +int nvme_get_features_err_recovery(nvme_link_t l, enum nvme_get_features_sel sel, __u32 nsid, __u32 *result) { struct nvme_get_features_args args = { .args_size = sizeof(args), - .fd = fd, .fid = NVME_FEAT_FID_ERR_RECOVERY, .nsid = nsid, .sel = sel, @@ -1097,34 +1089,33 @@ int nvme_get_features_err_recovery(int fd, enum nvme_get_features_sel sel, .result = result, }; - return nvme_get_features(&args); + return nvme_get_features(l, &args); } -int nvme_get_features_volatile_wc(int fd, enum nvme_get_features_sel sel, +int nvme_get_features_volatile_wc(nvme_link_t l, enum nvme_get_features_sel sel, __u32 *result) { - return __nvme_get_features(fd, NVME_FEAT_FID_VOLATILE_WC, sel, result); + return __nvme_get_features(l, NVME_FEAT_FID_VOLATILE_WC, sel, result); } -int nvme_get_features_num_queues(int fd, enum nvme_get_features_sel sel, +int nvme_get_features_num_queues(nvme_link_t l, enum nvme_get_features_sel sel, __u32 *result) { - return __nvme_get_features(fd, NVME_FEAT_FID_NUM_QUEUES, sel, result); + return __nvme_get_features(l, NVME_FEAT_FID_NUM_QUEUES, sel, result); } -int nvme_get_features_irq_coalesce(int fd, enum nvme_get_features_sel sel, +int nvme_get_features_irq_coalesce(nvme_link_t l, enum nvme_get_features_sel sel, __u32 *result) { - return __nvme_get_features(fd, NVME_FEAT_FID_IRQ_COALESCE, sel, + return __nvme_get_features(l, NVME_FEAT_FID_IRQ_COALESCE, sel, result); } -int nvme_get_features_irq_config(int fd, enum nvme_get_features_sel sel, +int nvme_get_features_irq_config(nvme_link_t l, enum nvme_get_features_sel sel, __u16 iv, __u32 *result) { struct nvme_get_features_args args = { .args_size = sizeof(args), - .fd = fd, .fid = NVME_FEAT_FID_IRQ_CONFIG, .nsid = NVME_NSID_NONE, .sel = sel, @@ -1136,28 +1127,27 @@ int nvme_get_features_irq_config(int fd, enum nvme_get_features_sel sel, .result = result, }; - return nvme_get_features(&args); + return nvme_get_features(l, &args); } -int nvme_get_features_write_atomic(int fd, enum nvme_get_features_sel sel, +int nvme_get_features_write_atomic(nvme_link_t l, enum nvme_get_features_sel sel, __u32 *result) { - return __nvme_get_features(fd, NVME_FEAT_FID_WRITE_ATOMIC, sel, + return __nvme_get_features(l, NVME_FEAT_FID_WRITE_ATOMIC, sel, result); } -int nvme_get_features_async_event(int fd, enum nvme_get_features_sel sel, +int nvme_get_features_async_event(nvme_link_t l, enum nvme_get_features_sel sel, __u32 *result) { - return __nvme_get_features(fd, NVME_FEAT_FID_ASYNC_EVENT, sel, result); + return __nvme_get_features(l, NVME_FEAT_FID_ASYNC_EVENT, sel, result); } -int nvme_get_features_auto_pst(int fd, enum nvme_get_features_sel sel, +int nvme_get_features_auto_pst(nvme_link_t l, enum nvme_get_features_sel sel, struct nvme_feat_auto_pst *apst, __u32 *result) { struct nvme_get_features_args args = { .args_size = sizeof(args), - .fd = fd, .fid = NVME_FEAT_FID_AUTO_PST, .nsid = NVME_NSID_NONE, .sel = sel, @@ -1169,16 +1159,15 @@ int nvme_get_features_auto_pst(int fd, enum nvme_get_features_sel sel, .result = result, }; - return nvme_get_features(&args); + return nvme_get_features(l, &args); } -int nvme_get_features_host_mem_buf(int fd, enum nvme_get_features_sel sel, +int nvme_get_features_host_mem_buf(nvme_link_t l, enum nvme_get_features_sel sel, struct nvme_host_mem_buf_attrs *attrs, __u32 *result) { struct nvme_get_features_args args = { .args_size = sizeof(args), - .fd = fd, .fid = NVME_FEAT_FID_HOST_MEM_BUF, .nsid = NVME_NSID_NONE, .sel = sel, @@ -1189,15 +1178,14 @@ int nvme_get_features_host_mem_buf(int fd, enum nvme_get_features_sel sel, .result = result, }; - return nvme_get_features(&args); + return nvme_get_features(l, &args); } -int nvme_get_features_timestamp(int fd, enum nvme_get_features_sel sel, +int nvme_get_features_timestamp(nvme_link_t l, enum nvme_get_features_sel sel, struct nvme_timestamp *ts) { struct nvme_get_features_args args = { .args_size = sizeof(args), - .fd = fd, .fid = NVME_FEAT_FID_TIMESTAMP, .nsid = NVME_NSID_NONE, .sel = sel, @@ -1209,36 +1197,35 @@ int nvme_get_features_timestamp(int fd, enum nvme_get_features_sel sel, .result = NULL, }; - return nvme_get_features(&args); + return nvme_get_features(l, &args); } -int nvme_get_features_kato(int fd, enum nvme_get_features_sel sel, __u32 *result) +int nvme_get_features_kato(nvme_link_t l, enum nvme_get_features_sel sel, __u32 *result) { - return __nvme_get_features(fd, NVME_FEAT_FID_KATO, sel, result); + return __nvme_get_features(l, NVME_FEAT_FID_KATO, sel, result); } -int nvme_get_features_hctm(int fd, enum nvme_get_features_sel sel, __u32 *result) +int nvme_get_features_hctm(nvme_link_t l, enum nvme_get_features_sel sel, __u32 *result) { - return __nvme_get_features(fd, NVME_FEAT_FID_HCTM, sel, result); + return __nvme_get_features(l, NVME_FEAT_FID_HCTM, sel, result); } -int nvme_get_features_nopsc(int fd, enum nvme_get_features_sel sel, __u32 *result) +int nvme_get_features_nopsc(nvme_link_t l, enum nvme_get_features_sel sel, __u32 *result) { - return __nvme_get_features(fd, NVME_FEAT_FID_NOPSC, sel, result); + return __nvme_get_features(l, NVME_FEAT_FID_NOPSC, sel, result); } -int nvme_get_features_rrl(int fd, enum nvme_get_features_sel sel, __u32 *result) +int nvme_get_features_rrl(nvme_link_t l, enum nvme_get_features_sel sel, __u32 *result) { - return __nvme_get_features(fd, NVME_FEAT_FID_RRL, sel, result); + return __nvme_get_features(l, NVME_FEAT_FID_RRL, sel, result); } -int nvme_get_features_plm_config(int fd, enum nvme_get_features_sel sel, +int nvme_get_features_plm_config(nvme_link_t l, enum nvme_get_features_sel sel, __u16 nvmsetid, struct nvme_plm_config *data, __u32 *result) { struct nvme_get_features_args args = { .args_size = sizeof(args), - .fd = fd, .fid = NVME_FEAT_FID_PLM_CONFIG, .nsid = NVME_NSID_NONE, .sel = sel, @@ -1250,15 +1237,14 @@ int nvme_get_features_plm_config(int fd, enum nvme_get_features_sel sel, .result = result, }; - return nvme_get_features(&args); + return nvme_get_features(l, &args); } -int nvme_get_features_plm_window(int fd, enum nvme_get_features_sel sel, +int nvme_get_features_plm_window(nvme_link_t l, enum nvme_get_features_sel sel, __u16 nvmsetid, __u32 *result) { struct nvme_get_features_args args = { .args_size = sizeof(args), - .fd = fd, .fid = NVME_FEAT_FID_PLM_WINDOW, .nsid = NVME_NSID_NONE, .sel = sel, @@ -1270,23 +1256,22 @@ int nvme_get_features_plm_window(int fd, enum nvme_get_features_sel sel, .result = result, }; - return nvme_get_features(&args); + return nvme_get_features(l, &args); } -int nvme_get_features_lba_sts_interval(int fd, enum nvme_get_features_sel sel, +int nvme_get_features_lba_sts_interval(nvme_link_t l, enum nvme_get_features_sel sel, __u32 *result) { - return __nvme_get_features(fd, NVME_FEAT_FID_LBA_STS_INTERVAL, sel, + return __nvme_get_features(l, NVME_FEAT_FID_LBA_STS_INTERVAL, sel, result); } -int nvme_get_features_host_behavior(int fd, enum nvme_get_features_sel sel, +int nvme_get_features_host_behavior(nvme_link_t l, enum nvme_get_features_sel sel, struct nvme_feat_host_behavior *data, __u32 *result) { struct nvme_get_features_args args = { .args_size = sizeof(args), - .fd = fd, .fid = NVME_FEAT_FID_HOST_BEHAVIOR, .nsid = NVME_NSID_NONE, .sel = sel, @@ -1298,21 +1283,20 @@ int nvme_get_features_host_behavior(int fd, enum nvme_get_features_sel sel, .result = result, }; - return nvme_get_features(&args); + return nvme_get_features(l, &args); } -int nvme_get_features_sanitize(int fd, enum nvme_get_features_sel sel, +int nvme_get_features_sanitize(nvme_link_t l, enum nvme_get_features_sel sel, __u32 *result) { - return __nvme_get_features(fd, NVME_FEAT_FID_SANITIZE, sel, result); + return __nvme_get_features(l, NVME_FEAT_FID_SANITIZE, sel, result); } -int nvme_get_features_endurance_event_cfg(int fd, enum nvme_get_features_sel sel, +int nvme_get_features_endurance_event_cfg(nvme_link_t l, enum nvme_get_features_sel sel, __u16 endgid, __u32 *result) { struct nvme_get_features_args args = { .args_size = sizeof(args), - .fd = fd, .fid = NVME_FEAT_FID_ENDURANCE_EVT_CFG, .nsid = NVME_NSID_NONE, .sel = sel, @@ -1324,21 +1308,20 @@ int nvme_get_features_endurance_event_cfg(int fd, enum nvme_get_features_sel sel .result = result, }; - return nvme_get_features(&args); + return nvme_get_features(l, &args); } -int nvme_get_features_sw_progress(int fd, enum nvme_get_features_sel sel, +int nvme_get_features_sw_progress(nvme_link_t l, enum nvme_get_features_sel sel, __u32 *result) { - return __nvme_get_features(fd, NVME_FEAT_FID_SW_PROGRESS, sel, result); + return __nvme_get_features(l, NVME_FEAT_FID_SW_PROGRESS, sel, result); } -int nvme_get_features_host_id(int fd, enum nvme_get_features_sel sel, +int nvme_get_features_host_id(nvme_link_t l, enum nvme_get_features_sel sel, bool exhid, __u32 len, __u8 *hostid) { struct nvme_get_features_args args = { .args_size = sizeof(args), - .fd = fd, .fid = NVME_FEAT_FID_HOST_ID, .nsid = NVME_NSID_NONE, .sel = sel, @@ -1350,15 +1333,14 @@ int nvme_get_features_host_id(int fd, enum nvme_get_features_sel sel, .result = NULL, }; - return nvme_get_features(&args); + return nvme_get_features(l, &args); } -int nvme_get_features_resv_mask(int fd, enum nvme_get_features_sel sel, +int nvme_get_features_resv_mask(nvme_link_t l, enum nvme_get_features_sel sel, __u32 nsid, __u32 *result) { struct nvme_get_features_args args = { .args_size = sizeof(args), - .fd = fd, .fid = NVME_FEAT_FID_RESV_MASK, .nsid = nsid, .sel = sel, @@ -1367,15 +1349,14 @@ int nvme_get_features_resv_mask(int fd, enum nvme_get_features_sel sel, .result = result, }; - return nvme_get_features(&args); + return nvme_get_features(l, &args); } -int nvme_get_features_resv_persist(int fd, enum nvme_get_features_sel sel, +int nvme_get_features_resv_persist(nvme_link_t l, enum nvme_get_features_sel sel, __u32 nsid, __u32 *result) { struct nvme_get_features_args args = { .args_size = sizeof(args), - .fd = fd, .fid = NVME_FEAT_FID_RESV_PERSIST, .nsid = nsid, .sel = sel, @@ -1384,16 +1365,15 @@ int nvme_get_features_resv_persist(int fd, enum nvme_get_features_sel sel, .result = result, }; - return nvme_get_features(&args); + return nvme_get_features(l, &args); } -int nvme_get_features_write_protect(int fd, __u32 nsid, +int nvme_get_features_write_protect(nvme_link_t l, __u32 nsid, enum nvme_get_features_sel sel, __u32 *result) { struct nvme_get_features_args args = { .args_size = sizeof(args), - .fd = fd, .fid = NVME_FEAT_FID_WRITE_PROTECT, .nsid = nsid, .sel = sel, @@ -1405,16 +1385,16 @@ int nvme_get_features_write_protect(int fd, __u32 nsid, .result = result, }; - return nvme_get_features(&args); + return nvme_get_features(l, &args); } -int nvme_get_features_iocs_profile(int fd, enum nvme_get_features_sel sel, +int nvme_get_features_iocs_profile(nvme_link_t l, enum nvme_get_features_sel sel, __u32 *result) { - return __nvme_get_features(fd, NVME_FEAT_FID_IOCS_PROFILE, sel, result); + return __nvme_get_features(l, NVME_FEAT_FID_IOCS_PROFILE, sel, result); } -int nvme_format_nvm(struct nvme_format_nvm_args *args) +int nvme_format_nvm(nvme_link_t l, struct nvme_format_nvm_args *args) { const size_t size_v1 = sizeof_args(struct nvme_format_nvm_args, lbaf, __u64); const size_t size_v2 = sizeof_args(struct nvme_format_nvm_args, lbafu, __u64); @@ -1443,10 +1423,10 @@ int nvme_format_nvm(struct nvme_format_nvm_args *args) .timeout_ms = args->timeout, }; - return nvme_submit_admin_passthru(args->fd, &cmd, args->result); + return nvme_submit_admin_passthru(l, &cmd, args->result); } -int nvme_ns_mgmt(struct nvme_ns_mgmt_args *args) +int nvme_ns_mgmt(nvme_link_t l, struct nvme_ns_mgmt_args *args) { const size_t size_v1 = sizeof_args(struct nvme_ns_mgmt_args, csi, __u64); const size_t size_v2 = sizeof_args(struct nvme_ns_mgmt_args, data, __u64); @@ -1478,10 +1458,10 @@ int nvme_ns_mgmt(struct nvme_ns_mgmt_args *args) cmd.addr = (__u64)(uintptr_t)args->ns; } } - return nvme_submit_admin_passthru(args->fd, &cmd, args->result); + return nvme_submit_admin_passthru(l, &cmd, args->result); } -int nvme_ns_attach(struct nvme_ns_attach_args *args) +int nvme_ns_attach(nvme_link_t l, struct nvme_ns_attach_args *args) { __u32 cdw10 = NVME_SET(args->sel, NAMESPACE_ATTACH_CDW10_SEL); @@ -1498,10 +1478,10 @@ int nvme_ns_attach(struct nvme_ns_attach_args *args) errno = EINVAL; return -1; } - return nvme_submit_admin_passthru(args->fd, &cmd, args->result); + return nvme_submit_admin_passthru(l, &cmd, args->result); } -int nvme_fw_download(struct nvme_fw_download_args *args) +int nvme_fw_download(nvme_link_t l, struct nvme_fw_download_args *args) { __u32 cdw10 = (args->data_len >> 2) - 1; __u32 cdw11 = args->offset >> 2; @@ -1519,10 +1499,10 @@ int nvme_fw_download(struct nvme_fw_download_args *args) errno = EINVAL; return -1; } - return nvme_submit_admin_passthru(args->fd, &cmd, args->result); + return nvme_submit_admin_passthru(l, &cmd, args->result); } -int nvme_fw_commit(struct nvme_fw_commit_args *args) +int nvme_fw_commit(nvme_link_t l, struct nvme_fw_commit_args *args) { __u32 cdw10 = NVME_SET(args->slot, FW_COMMIT_CDW10_FS) | NVME_SET(args->action, FW_COMMIT_CDW10_CA) | @@ -1538,10 +1518,10 @@ int nvme_fw_commit(struct nvme_fw_commit_args *args) errno = EINVAL; return -1; } - return nvme_submit_admin_passthru(args->fd, &cmd, args->result); + return nvme_submit_admin_passthru(l, &cmd, args->result); } -int nvme_security_send(struct nvme_security_send_args *args) +int nvme_security_send(nvme_link_t l, struct nvme_security_send_args *args) { __u32 cdw10 = NVME_SET(args->secp, SECURITY_SECP) | NVME_SET(args->spsp0, SECURITY_SPSP0) | @@ -1563,10 +1543,10 @@ int nvme_security_send(struct nvme_security_send_args *args) errno = EINVAL; return -1; } - return nvme_submit_admin_passthru(args->fd, &cmd, args->result); + return nvme_submit_admin_passthru(l, &cmd, args->result); } -int nvme_security_receive(struct nvme_security_receive_args *args) +int nvme_security_receive(nvme_link_t l, struct nvme_security_receive_args *args) { __u32 cdw10 = NVME_SET(args->secp, SECURITY_SECP) | NVME_SET(args->spsp0, SECURITY_SPSP0) | @@ -1588,10 +1568,10 @@ int nvme_security_receive(struct nvme_security_receive_args *args) errno = EINVAL; return -1; } - return nvme_submit_admin_passthru(args->fd, &cmd, args->result); + return nvme_submit_admin_passthru(l, &cmd, args->result); } -int nvme_get_lba_status(struct nvme_get_lba_status_args *args) +int nvme_get_lba_status(nvme_link_t l, struct nvme_get_lba_status_args *args) { __u32 cdw10 = args->slba & 0xffffffff; __u32 cdw11 = args->slba >> 32; @@ -1615,10 +1595,10 @@ int nvme_get_lba_status(struct nvme_get_lba_status_args *args) errno = EINVAL; return -1; } - return nvme_submit_admin_passthru(args->fd, &cmd, args->result); + return nvme_submit_admin_passthru(l, &cmd, args->result); } -int nvme_directive_send(struct nvme_directive_send_args *args) +int nvme_directive_send(nvme_link_t l, struct nvme_directive_send_args *args) { __u32 cdw10 = args->data_len ? (args->data_len >> 2) - 1 : 0; __u32 cdw11 = NVME_SET(args->doper, DIRECTIVE_CDW11_DOPER) | @@ -1640,10 +1620,10 @@ int nvme_directive_send(struct nvme_directive_send_args *args) errno = EINVAL; return -1; } - return nvme_submit_admin_passthru(args->fd, &cmd, args->result); + return nvme_submit_admin_passthru(l, &cmd, args->result); } -int nvme_directive_send_id_endir(int fd, __u32 nsid, bool endir, +int nvme_directive_send_id_endir(nvme_link_t l, __u32 nsid, bool endir, enum nvme_directive_dtype dtype, struct nvme_id_directives *id) { @@ -1651,7 +1631,6 @@ int nvme_directive_send_id_endir(int fd, __u32 nsid, bool endir, NVME_SET(endir, DIRECTIVE_SEND_IDENTIFY_CDW12_ENDIR); struct nvme_directive_send_args args = { .args_size = sizeof(args), - .fd = fd, .nsid = nsid, .dspec = 0, .dtype = NVME_DIRECTIVE_DTYPE_IDENTIFY, @@ -1663,10 +1642,10 @@ int nvme_directive_send_id_endir(int fd, __u32 nsid, bool endir, .result = NULL, }; - return nvme_directive_send(&args); + return nvme_directive_send(l, &args); } -int nvme_directive_recv(struct nvme_directive_recv_args *args) +int nvme_directive_recv(nvme_link_t l, struct nvme_directive_recv_args *args) { __u32 cdw10 = args->data_len ? (args->data_len >> 2) - 1 : 0; __u32 cdw11 = NVME_SET(args->doper, DIRECTIVE_CDW11_DOPER) | @@ -1688,10 +1667,10 @@ int nvme_directive_recv(struct nvme_directive_recv_args *args) errno = EINVAL; return -1; } - return nvme_submit_admin_passthru(args->fd, &cmd, args->result); + return nvme_submit_admin_passthru(l, &cmd, args->result); } -int nvme_capacity_mgmt(struct nvme_capacity_mgmt_args *args) +int nvme_capacity_mgmt(nvme_link_t l, struct nvme_capacity_mgmt_args *args) { __u32 cdw10 = args->op | args->element_id << 16; @@ -1707,10 +1686,10 @@ int nvme_capacity_mgmt(struct nvme_capacity_mgmt_args *args) errno = EINVAL; return -1; } - return nvme_submit_admin_passthru(args->fd, &cmd, args->result); + return nvme_submit_admin_passthru(l, &cmd, args->result); } -int nvme_lockdown(struct nvme_lockdown_args *args) +int nvme_lockdown(nvme_link_t l, struct nvme_lockdown_args *args) { __u32 cdw10 = args->ofi << 8 | (args->ifc & 0x3) << 5 | @@ -1728,10 +1707,10 @@ int nvme_lockdown(struct nvme_lockdown_args *args) errno = EINVAL; return -1; } - return nvme_submit_admin_passthru(args->fd, &cmd, args->result); + return nvme_submit_admin_passthru(l, &cmd, args->result); } -int nvme_set_property(struct nvme_set_property_args *args) +int nvme_set_property(nvme_link_t l, struct nvme_set_property_args *args) { __u32 cdw10 = nvme_is_64bit_reg(args->offset); @@ -1749,10 +1728,10 @@ int nvme_set_property(struct nvme_set_property_args *args) errno = EINVAL; return -1; } - return nvme_submit_admin_passthru(args->fd, &cmd, args->result); + return nvme_submit_admin_passthru(l, &cmd, args->result); } -int nvme_get_property(struct nvme_get_property_args *args) +int nvme_get_property(nvme_link_t l, struct nvme_get_property_args *args) { __u32 cdw10 = nvme_is_64bit_reg(args->offset); @@ -1768,10 +1747,10 @@ int nvme_get_property(struct nvme_get_property_args *args) errno = EINVAL; return -1; } - return nvme_submit_admin_passthru64(args->fd, &cmd, args->value); + return nvme_submit_admin_passthru64(l, &cmd, args->value); } -int nvme_sanitize_nvm(struct nvme_sanitize_nvm_args *args) +int nvme_sanitize_nvm(nvme_link_t l, struct nvme_sanitize_nvm_args *args) { const size_t size_v1 = sizeof_args(struct nvme_sanitize_nvm_args, nodas, __u64); const size_t size_v2 = sizeof_args(struct nvme_sanitize_nvm_args, emvs, __u64); @@ -1800,10 +1779,10 @@ int nvme_sanitize_nvm(struct nvme_sanitize_nvm_args *args) .timeout_ms = args->timeout, }; - return nvme_submit_admin_passthru(args->fd, &cmd, args->result); + return nvme_submit_admin_passthru(l, &cmd, args->result); } -int nvme_dev_self_test(struct nvme_dev_self_test_args *args) +int nvme_dev_self_test(nvme_link_t l, struct nvme_dev_self_test_args *args) { __u32 cdw10 = NVME_SET(args->stc, DEVICE_SELF_TEST_CDW10_STC); @@ -1818,10 +1797,10 @@ int nvme_dev_self_test(struct nvme_dev_self_test_args *args) errno = EINVAL; return -1; } - return nvme_submit_admin_passthru(args->fd, &cmd, args->result); + return nvme_submit_admin_passthru(l, &cmd, args->result); } -int nvme_virtual_mgmt(struct nvme_virtual_mgmt_args *args) +int nvme_virtual_mgmt(nvme_link_t l, struct nvme_virtual_mgmt_args *args) { __u32 cdw10 = NVME_SET(args->act, VIRT_MGMT_CDW10_ACT) | NVME_SET(args->rt, VIRT_MGMT_CDW10_RT) | @@ -1839,39 +1818,39 @@ int nvme_virtual_mgmt(struct nvme_virtual_mgmt_args *args) errno = EINVAL; return -1; } - return nvme_submit_admin_passthru(args->fd, &cmd, args->result); + return nvme_submit_admin_passthru(l, &cmd, args->result); } -int nvme_submit_io_passthru64(int fd, struct nvme_passthru_cmd64 *cmd, +int nvme_submit_io_passthru64(nvme_link_t l, struct nvme_passthru_cmd64 *cmd, __u64 *result) { - return nvme_submit_passthru64(fd, NVME_IOCTL_IO64_CMD, cmd, result); + return nvme_submit_passthru64(l, NVME_IOCTL_IO64_CMD, cmd, result); } -int nvme_io_passthru64(int fd, __u8 opcode, __u8 flags, __u16 rsvd, +int nvme_io_passthru64(nvme_link_t l, __u8 opcode, __u8 flags, __u16 rsvd, __u32 nsid, __u32 cdw2, __u32 cdw3, __u32 cdw10, __u32 cdw11, __u32 cdw12, __u32 cdw13, __u32 cdw14, __u32 cdw15, __u32 data_len, void *data, __u32 metadata_len, void *metadata, __u32 timeout_ms, __u64 *result) { - return nvme_passthru64(fd, NVME_IOCTL_IO64_CMD, opcode, flags, rsvd, + return nvme_passthru64(l, NVME_IOCTL_IO64_CMD, opcode, flags, rsvd, nsid, cdw2, cdw3, cdw10, cdw11, cdw12, cdw13, cdw14, cdw15, data_len, data, metadata_len, metadata, timeout_ms, result); } -int nvme_submit_io_passthru(int fd, struct nvme_passthru_cmd *cmd, __u32 *result) +int nvme_submit_io_passthru(nvme_link_t l, struct nvme_passthru_cmd *cmd, __u32 *result) { - return nvme_submit_passthru(fd, NVME_IOCTL_IO_CMD, cmd, result); + return nvme_submit_passthru(l, NVME_IOCTL_IO_CMD, cmd, result); } -int nvme_io_passthru(int fd, __u8 opcode, __u8 flags, __u16 rsvd, +int nvme_io_passthru(nvme_link_t l, __u8 opcode, __u8 flags, __u16 rsvd, __u32 nsid, __u32 cdw2, __u32 cdw3, __u32 cdw10, __u32 cdw11, __u32 cdw12, __u32 cdw13, __u32 cdw14, __u32 cdw15, __u32 data_len, void *data, __u32 metadata_len, void *metadata, __u32 timeout_ms, __u32 *result) { - return nvme_passthru(fd, NVME_IOCTL_IO_CMD, opcode, flags, rsvd, nsid, + return nvme_passthru(l, NVME_IOCTL_IO_CMD, opcode, flags, rsvd, nsid, cdw2, cdw3, cdw10, cdw11, cdw12, cdw13, cdw14, cdw15, data_len, data, metadata_len, metadata, timeout_ms, result); @@ -1918,7 +1897,7 @@ static int nvme_set_var_size_tags(__u32 *cmd_dw2, __u32 *cmd_dw3, __u32 *cmd_dw1 return 0; } -int nvme_io(struct nvme_io_args *args, __u8 opcode) +int nvme_io(nvme_link_t l, struct nvme_io_args *args, __u8 opcode) { const size_t size_v1 = sizeof_args(struct nvme_io_args, dsm, __u64); const size_t size_v2 = sizeof_args(struct nvme_io_args, pif, __u64); @@ -1968,10 +1947,10 @@ int nvme_io(struct nvme_io_args *args, __u8 opcode) .timeout_ms = args->timeout, }; - return nvme_submit_io_passthru(args->fd, &cmd, args->result); + return nvme_submit_io_passthru(l, &cmd, args->result); } -int nvme_dsm(struct nvme_dsm_args *args) +int nvme_dsm(nvme_link_t l, struct nvme_dsm_args *args) { struct nvme_passthru_cmd cmd = { .opcode = nvme_cmd_dsm, @@ -1987,10 +1966,10 @@ int nvme_dsm(struct nvme_dsm_args *args) errno = EINVAL; return -1; } - return nvme_submit_io_passthru(args->fd, &cmd, args->result); + return nvme_submit_io_passthru(l, &cmd, args->result); } -int nvme_copy(struct nvme_copy_args *args) +int nvme_copy(nvme_link_t l, struct nvme_copy_args *args) { const size_t size_v1 = sizeof_args(struct nvme_copy_args, format, __u64); const size_t size_v2 = sizeof_args(struct nvme_copy_args, ilbrt_u64, __u64); @@ -2038,10 +2017,10 @@ int nvme_copy(struct nvme_copy_args *args) .timeout_ms = args->timeout, }; - return nvme_submit_io_passthru(args->fd, &cmd, args->result); + return nvme_submit_io_passthru(l, &cmd, args->result); } -int nvme_resv_acquire(struct nvme_resv_acquire_args *args) +int nvme_resv_acquire(nvme_link_t l, struct nvme_resv_acquire_args *args) { __le64 payload[2] = { cpu_to_le64(args->crkey), @@ -2064,10 +2043,10 @@ int nvme_resv_acquire(struct nvme_resv_acquire_args *args) errno = EINVAL; return -1; } - return nvme_submit_io_passthru(args->fd, &cmd, args->result); + return nvme_submit_io_passthru(l, &cmd, args->result); } -int nvme_resv_register(struct nvme_resv_register_args *args) +int nvme_resv_register(nvme_link_t l, struct nvme_resv_register_args *args) { __le64 payload[2] = { cpu_to_le64(args->crkey), @@ -2090,10 +2069,10 @@ int nvme_resv_register(struct nvme_resv_register_args *args) errno = EINVAL; return -1; } - return nvme_submit_io_passthru(args->fd, &cmd, args->result); + return nvme_submit_io_passthru(l, &cmd, args->result); } -int nvme_resv_release(struct nvme_resv_release_args *args) +int nvme_resv_release(nvme_link_t l, struct nvme_resv_release_args *args) { __le64 payload[1] = { cpu_to_le64(args->crkey) }; __u32 cdw10 = (args->rrela & 0x7) | @@ -2113,10 +2092,10 @@ int nvme_resv_release(struct nvme_resv_release_args *args) errno = EINVAL; return -1; } - return nvme_submit_io_passthru(args->fd, &cmd, args->result); + return nvme_submit_io_passthru(l, &cmd, args->result); } -int nvme_resv_report(struct nvme_resv_report_args *args) +int nvme_resv_report(nvme_link_t l, struct nvme_resv_report_args *args) { struct nvme_passthru_cmd cmd = { .opcode = nvme_cmd_resv_report, @@ -2132,10 +2111,10 @@ int nvme_resv_report(struct nvme_resv_report_args *args) errno = EINVAL; return -1; } - return nvme_submit_io_passthru(args->fd, &cmd, args->result); + return nvme_submit_io_passthru(l, &cmd, args->result); } -int nvme_io_mgmt_recv(struct nvme_io_mgmt_recv_args *args) +int nvme_io_mgmt_recv(nvme_link_t l, struct nvme_io_mgmt_recv_args *args) { __u32 cdw10 = args->mo | (args->mos << 16); __u32 cdw11 = (args->data_len >> 2) - 1; @@ -2155,10 +2134,10 @@ int nvme_io_mgmt_recv(struct nvme_io_mgmt_recv_args *args) return -1; } - return nvme_submit_io_passthru(args->fd, &cmd, NULL); + return nvme_submit_io_passthru(l, &cmd, NULL); } -int nvme_io_mgmt_send(struct nvme_io_mgmt_send_args *args) +int nvme_io_mgmt_send(nvme_link_t l, struct nvme_io_mgmt_send_args *args) { __u32 cdw10 = args->mo | (args->mos << 16); @@ -2176,10 +2155,10 @@ int nvme_io_mgmt_send(struct nvme_io_mgmt_send_args *args) return -1; } - return nvme_submit_io_passthru(args->fd, &cmd, NULL); + return nvme_submit_io_passthru(l, &cmd, NULL); } -int nvme_zns_mgmt_send(struct nvme_zns_mgmt_send_args *args) +int nvme_zns_mgmt_send(nvme_link_t l, struct nvme_zns_mgmt_send_args *args) { __u32 cdw10 = args->slba & 0xffffffff; __u32 cdw11 = args->slba >> 32; @@ -2202,10 +2181,10 @@ int nvme_zns_mgmt_send(struct nvme_zns_mgmt_send_args *args) errno = EINVAL; return -1; } - return nvme_submit_io_passthru(args->fd, &cmd, args->result); + return nvme_submit_io_passthru(l, &cmd, args->result); } -int nvme_zns_mgmt_recv(struct nvme_zns_mgmt_recv_args *args) +int nvme_zns_mgmt_recv(nvme_link_t l, struct nvme_zns_mgmt_recv_args *args) { __u32 cdw10 = args->slba & 0xffffffff; __u32 cdw11 = args->slba >> 32; @@ -2230,10 +2209,10 @@ int nvme_zns_mgmt_recv(struct nvme_zns_mgmt_recv_args *args) errno = EINVAL; return -1; } - return nvme_submit_io_passthru(args->fd, &cmd, args->result); + return nvme_submit_io_passthru(l, &cmd, args->result); } -int nvme_zns_append(struct nvme_zns_append_args *args) +int nvme_zns_append(nvme_link_t l, struct nvme_zns_append_args *args) { const size_t size_v1 = sizeof_args(struct nvme_zns_append_args, lbatm, __u64); const size_t size_v2 = sizeof_args(struct nvme_zns_append_args, ilbrt_u64, __u64); @@ -2273,10 +2252,10 @@ int nvme_zns_append(struct nvme_zns_append_args *args) .timeout_ms = args->timeout, }; - return nvme_submit_io_passthru64(args->fd, &cmd, args->result); + return nvme_submit_io_passthru64(l, &cmd, args->result); } -int nvme_dim_send(struct nvme_dim_args *args) +int nvme_dim_send(nvme_link_t l, struct nvme_dim_args *args) { __u32 cdw10 = NVME_SET(args->tas, DIM_TAS); @@ -2293,11 +2272,11 @@ int nvme_dim_send(struct nvme_dim_args *args) return -1; } - return nvme_submit_admin_passthru(args->fd, &cmd, args->result); + return nvme_submit_admin_passthru(l, &cmd, args->result); } -int nvme_lm_cdq(struct nvme_lm_cdq_args *args) +int nvme_lm_cdq(nvme_link_t l, struct nvme_lm_cdq_args *args) { const size_t size_v1 = sizeof_args(struct nvme_lm_cdq_args, sz_u8, __u64); const size_t size_v2 = sizeof_args(struct nvme_lm_cdq_args, sz, __u64); @@ -2339,7 +2318,7 @@ int nvme_lm_cdq(struct nvme_lm_cdq_args *args) return -1; } - err = nvme_submit_admin_passthru(args->fd, &cmd, args->result); + err = nvme_submit_admin_passthru(l, &cmd, args->result); if (!err) args->cdqid = NVME_GET(cmd.result, LM_CREATE_CDQ_CDQID); @@ -2347,7 +2326,7 @@ int nvme_lm_cdq(struct nvme_lm_cdq_args *args) return err; } -int nvme_lm_track_send(struct nvme_lm_track_send_args *args) +int nvme_lm_track_send(nvme_link_t l, struct nvme_lm_track_send_args *args) { __u32 cdw10 = NVME_SET(args->sel, LM_TRACK_SEND_SEL) | NVME_SET(args->mos, LM_TRACK_SEND_MOS); @@ -2364,10 +2343,10 @@ int nvme_lm_track_send(struct nvme_lm_track_send_args *args) return -1; } - return nvme_submit_admin_passthru(args->fd, &cmd, args->result); + return nvme_submit_admin_passthru(l, &cmd, args->result); } -int nvme_lm_migration_send(struct nvme_lm_migration_send_args *args) +int nvme_lm_migration_send(nvme_link_t l, struct nvme_lm_migration_send_args *args) { __u32 cdw10 = NVME_SET(args->sel, LM_MIGRATION_SEND_SEL) | NVME_SET(args->mos, LM_MIGRATION_SEND_MOS); @@ -2404,10 +2383,10 @@ int nvme_lm_migration_send(struct nvme_lm_migration_send_args *args) return -1; } - return nvme_submit_admin_passthru(args->fd, &cmd, args->result); + return nvme_submit_admin_passthru(l, &cmd, args->result); } -int nvme_lm_migration_recv(struct nvme_lm_migration_recv_args *args) +int nvme_lm_migration_recv(nvme_link_t l, struct nvme_lm_migration_recv_args *args) { __u32 cdw10 = NVME_SET(args->sel, LM_MIGRATION_RECV_SEL) | NVME_SET(args->mos, LM_MIGRATION_RECV_MOS); @@ -2438,15 +2417,14 @@ int nvme_lm_migration_recv(struct nvme_lm_migration_recv_args *args) return -1; } - return nvme_submit_admin_passthru(args->fd, &cmd, args->result); + return nvme_submit_admin_passthru(l, &cmd, args->result); } -int nvme_lm_set_features_ctrl_data_queue(int fd, __u16 cdqid, __u32 hp, __u32 tpt, bool etpt, +int nvme_lm_set_features_ctrl_data_queue(nvme_link_t l, __u16 cdqid, __u32 hp, __u32 tpt, bool etpt, __u32 *result) { struct nvme_set_features_args args = { .args_size = sizeof(args), - .fd = fd, .fid = NVME_FEAT_FID_CTRL_DATA_QUEUE, .nsid = NVME_NSID_NONE, .cdw11 = cdqid | NVME_SET(etpt, LM_CTRL_DATA_QUEUE_ETPT), @@ -2457,16 +2435,15 @@ int nvme_lm_set_features_ctrl_data_queue(int fd, __u16 cdqid, __u32 hp, __u32 tp .result = result, }; - return nvme_set_features(&args); + return nvme_set_features(l, &args); } -int nvme_lm_get_features_ctrl_data_queue(int fd, __u16 cdqid, +int nvme_lm_get_features_ctrl_data_queue(nvme_link_t l, __u16 cdqid, struct nvme_lm_ctrl_data_queue_fid_data *data, __u32 *result) { struct nvme_get_features_args args = { .args_size = sizeof(args), - .fd = fd, .fid = NVME_FEAT_FID_CTRL_DATA_QUEUE, .nsid = NVME_NSID_NONE, .cdw11 = cdqid, @@ -2476,5 +2453,5 @@ int nvme_lm_get_features_ctrl_data_queue(int fd, __u16 cdqid, .result = result, }; - return nvme_get_features(&args); + return nvme_get_features(l, &args); } diff --git a/src/nvme/ioctl.h b/src/nvme/ioctl.h index c1975d965..a5b202e19 100644 --- a/src/nvme/ioctl.h +++ b/src/nvme/ioctl.h @@ -332,7 +332,7 @@ enum nvme_cmd_dword_fields { /** * nvme_submit_admin_passthru64() - Submit a 64-bit nvme passthrough admin * command - * @fd: File descriptor of nvme device + * @l: Link handle * @cmd: The nvme admin command to send * @result: Optional field to return the result from the CQE DW0-1 * @@ -341,12 +341,12 @@ enum nvme_cmd_dword_fields { * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_submit_admin_passthru64(int fd, struct nvme_passthru_cmd64 *cmd, +int nvme_submit_admin_passthru64(nvme_link_t l, struct nvme_passthru_cmd64 *cmd, __u64 *result); /** * nvme_admin_passthru64() - Submit a 64-bit nvme passthrough command - * @fd: File descriptor of nvme device + * @l: Link handle * @opcode: The nvme io command to send * @flags: NVMe command flags (not used) * @rsvd: Reserved for future use @@ -374,7 +374,7 @@ int nvme_submit_admin_passthru64(int fd, struct nvme_passthru_cmd64 *cmd, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_admin_passthru64(int fd, __u8 opcode, __u8 flags, __u16 rsvd, +int nvme_admin_passthru64(nvme_link_t l, __u8 opcode, __u8 flags, __u16 rsvd, __u32 nsid, __u32 cdw2, __u32 cdw3, __u32 cdw10, __u32 cdw11, __u32 cdw12, __u32 cdw13, __u32 cdw14, __u32 cdw15, __u32 data_len, void *data, __u32 metadata_len, void *metadata, @@ -382,7 +382,7 @@ int nvme_admin_passthru64(int fd, __u8 opcode, __u8 flags, __u16 rsvd, /** * nvme_submit_admin_passthru() - Submit an nvme passthrough admin command - * @fd: File descriptor of nvme device + * @l: Link handle * @cmd: The nvme admin command to send * @result: Optional field to return the result from the CQE DW0 * @@ -391,12 +391,12 @@ int nvme_admin_passthru64(int fd, __u8 opcode, __u8 flags, __u16 rsvd, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_submit_admin_passthru(int fd, struct nvme_passthru_cmd *cmd, +int nvme_submit_admin_passthru(nvme_link_t l, struct nvme_passthru_cmd *cmd, __u32 *result); /** * nvme_admin_passthru() - Submit an nvme passthrough command - * @fd: File descriptor of nvme device + * @l: Link handle * @opcode: The nvme io command to send * @flags: NVMe command flags (not used) * @rsvd: Reserved for future use @@ -424,7 +424,7 @@ int nvme_submit_admin_passthru(int fd, struct nvme_passthru_cmd *cmd, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_admin_passthru(int fd, __u8 opcode, __u8 flags, __u16 rsvd, +int nvme_admin_passthru(nvme_link_t l, __u8 opcode, __u8 flags, __u16 rsvd, __u32 nsid, __u32 cdw2, __u32 cdw3, __u32 cdw10, __u32 cdw11, __u32 cdw12, __u32 cdw13, __u32 cdw14, __u32 cdw15, __u32 data_len, void *data, __u32 metadata_len, void *metadata, @@ -432,7 +432,7 @@ int nvme_admin_passthru(int fd, __u8 opcode, __u8 flags, __u16 rsvd, /** * nvme_submit_io_passthru64() - Submit a 64-bit nvme passthrough command - * @fd: File descriptor of nvme device + * @l: Link handle * @cmd: The nvme io command to send * @result: Optional field to return the result from the CQE DW0-1 * @@ -441,12 +441,12 @@ int nvme_admin_passthru(int fd, __u8 opcode, __u8 flags, __u16 rsvd, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_submit_io_passthru64(int fd, struct nvme_passthru_cmd64 *cmd, +int nvme_submit_io_passthru64(nvme_link_t l, struct nvme_passthru_cmd64 *cmd, __u64 *result); /** * nvme_io_passthru64() - Submit an nvme io passthrough command - * @fd: File descriptor of nvme device + * @l: Link handle * @opcode: The nvme io command to send * @flags: NVMe command flags (not used) * @rsvd: Reserved for future use @@ -474,7 +474,7 @@ int nvme_submit_io_passthru64(int fd, struct nvme_passthru_cmd64 *cmd, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_io_passthru64(int fd, __u8 opcode, __u8 flags, __u16 rsvd, +int nvme_io_passthru64(nvme_link_t l, __u8 opcode, __u8 flags, __u16 rsvd, __u32 nsid, __u32 cdw2, __u32 cdw3, __u32 cdw10, __u32 cdw11, __u32 cdw12, __u32 cdw13, __u32 cdw14, __u32 cdw15, __u32 data_len, void *data, __u32 metadata_len, void *metadata, @@ -482,7 +482,7 @@ int nvme_io_passthru64(int fd, __u8 opcode, __u8 flags, __u16 rsvd, /** * nvme_submit_io_passthru() - Submit an nvme passthrough command - * @fd: File descriptor of nvme device + * @l: Link handle * @cmd: The nvme io command to send * @result: Optional field to return the result from the CQE dword 0 * @result: Optional field to return the result from the CQE DW0 @@ -492,12 +492,12 @@ int nvme_io_passthru64(int fd, __u8 opcode, __u8 flags, __u16 rsvd, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_submit_io_passthru(int fd, struct nvme_passthru_cmd *cmd, +int nvme_submit_io_passthru(nvme_link_t l, struct nvme_passthru_cmd *cmd, __u32 *result); /** * nvme_io_passthru() - Submit an nvme io passthrough command - * @fd: File descriptor of nvme device + * @l: Link handle * @opcode: The nvme io command to send * @flags: NVMe command flags (not used) * @rsvd: Reserved for future use @@ -525,7 +525,7 @@ int nvme_submit_io_passthru(int fd, struct nvme_passthru_cmd *cmd, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_io_passthru(int fd, __u8 opcode, __u8 flags, __u16 rsvd, +int nvme_io_passthru(nvme_link_t l, __u8 opcode, __u8 flags, __u16 rsvd, __u32 nsid, __u32 cdw2, __u32 cdw3, __u32 cdw10, __u32 cdw11, __u32 cdw12, __u32 cdw13, __u32 cdw14, __u32 cdw15, __u32 data_len, void *data, __u32 metadata_len, void *metadata, @@ -533,38 +533,38 @@ int nvme_io_passthru(int fd, __u8 opcode, __u8 flags, __u16 rsvd, /** * nvme_subsystem_reset() - Initiate a subsystem reset - * @fd: File descriptor of nvme device + * @l: Link handle * * This should only be sent to controller handles, not to namespaces. * * Return: Zero if a subsystem reset was initiated or -1 with errno set * otherwise. */ -int nvme_subsystem_reset(int fd); +int nvme_subsystem_reset(nvme_link_t l); /** * nvme_ctrl_reset() - Initiate a controller reset - * @fd: File descriptor of nvme device + * @l: Link handle * * This should only be sent to controller handles, not to namespaces. * * Return: 0 if a reset was initiated or -1 with errno set otherwise. */ -int nvme_ctrl_reset(int fd); +int nvme_ctrl_reset(nvme_link_t l); /** * nvme_ns_rescan() - Initiate a controller rescan - * @fd: File descriptor of nvme device + * @l: Link handle * * This should only be sent to controller handles, not to namespaces. * * Return: 0 if a rescan was initiated or -1 with errno set otherwise. */ -int nvme_ns_rescan(int fd); +int nvme_ns_rescan(nvme_link_t l); /** * nvme_get_nsid() - Retrieve the NSID from a namespace file descriptor - * @fd: File descriptor of nvme namespace + * @l: Link handle * @nsid: User pointer to namespace id * * This should only be sent to namespace handles, not to controllers. The @@ -574,10 +574,11 @@ int nvme_ns_rescan(int fd); * * Return: 0 if @nsid was set successfully or -1 with errno set otherwise. */ -int nvme_get_nsid(int fd, __u32 *nsid); +int nvme_get_nsid(nvme_link_t l, __u32 *nsid); /** * nvme_identify() - Send the NVMe Identify command + * @l: Link handle * @args: &struct nvme_identify_args argument structure * * The Identify command returns a data buffer that describes information about @@ -586,16 +587,15 @@ int nvme_get_nsid(int fd, __u32 *nsid); * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_identify(struct nvme_identify_args *args); +int nvme_identify(nvme_link_t l, struct nvme_identify_args *args); -static inline int nvme_identify_cns_nsid(int fd, enum nvme_identify_cns cns, +static inline int nvme_identify_cns_nsid(nvme_link_t l, enum nvme_identify_cns cns, __u32 nsid, void *data) { struct nvme_identify_args args = { .result = NULL, .data = data, .args_size = sizeof(args), - .fd = fd, .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, .cns = cns, .csi = NVME_CSI_NVM, @@ -605,12 +605,12 @@ static inline int nvme_identify_cns_nsid(int fd, enum nvme_identify_cns cns, .uuidx = NVME_UUID_NONE, }; - return nvme_identify(&args); + return nvme_identify(l, &args); } /** * nvme_identify_ctrl() - Retrieves nvme identify controller - * @fd: File descriptor of nvme device + * @l: Link handle * @id: User space destination address to transfer the data, * * Sends nvme identify with CNS value %NVME_IDENTIFY_CNS_CTRL. @@ -620,15 +620,15 @@ static inline int nvme_identify_cns_nsid(int fd, enum nvme_identify_cns cns, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_identify_ctrl(int fd, struct nvme_id_ctrl *id) +static inline int nvme_identify_ctrl(nvme_link_t l, struct nvme_id_ctrl *id) { - return nvme_identify_cns_nsid(fd, NVME_IDENTIFY_CNS_CTRL, + return nvme_identify_cns_nsid(l, NVME_IDENTIFY_CNS_CTRL, NVME_NSID_NONE, id); } /** * nvme_identify_ns() - Retrieves nvme identify namespace - * @fd: File descriptor of nvme device + * @l: Link handle * @nsid: Namespace to identify * @ns: User space destination address to transfer the data * @@ -646,31 +646,31 @@ static inline int nvme_identify_ctrl(int fd, struct nvme_id_ctrl *id) * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_identify_ns(int fd, __u32 nsid, struct nvme_id_ns *ns) +static inline int nvme_identify_ns(nvme_link_t l, __u32 nsid, struct nvme_id_ns *ns) { - return nvme_identify_cns_nsid(fd, NVME_IDENTIFY_CNS_NS, nsid, ns); + return nvme_identify_cns_nsid(l, NVME_IDENTIFY_CNS_NS, nsid, ns); } /** * nvme_identify_allocated_ns() - Same as nvme_identify_ns, but only for * allocated namespaces - * @fd: File descriptor of nvme device + * @l: Link handle * @nsid: Namespace to identify * @ns: User space destination address to transfer the data * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_identify_allocated_ns(int fd, __u32 nsid, +static inline int nvme_identify_allocated_ns(nvme_link_t l, __u32 nsid, struct nvme_id_ns *ns) { - return nvme_identify_cns_nsid(fd, NVME_IDENTIFY_CNS_ALLOCATED_NS, + return nvme_identify_cns_nsid(l, NVME_IDENTIFY_CNS_ALLOCATED_NS, nsid, ns); } /** * nvme_identify_active_ns_list() - Retrieves active namespaces id list - * @fd: File descriptor of nvme device + * @l: Link handle * @nsid: Return namespaces greater than this identifier * @list: User space destination address to transfer the data * @@ -683,16 +683,16 @@ static inline int nvme_identify_allocated_ns(int fd, __u32 nsid, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_identify_active_ns_list(int fd, __u32 nsid, +static inline int nvme_identify_active_ns_list(nvme_link_t l, __u32 nsid, struct nvme_ns_list *list) { - return nvme_identify_cns_nsid(fd, NVME_IDENTIFY_CNS_NS_ACTIVE_LIST, + return nvme_identify_cns_nsid(l, NVME_IDENTIFY_CNS_NS_ACTIVE_LIST, nsid, list); } /** * nvme_identify_allocated_ns_list() - Retrieves allocated namespace id list - * @fd: File descriptor of nvme device + * @l: Link handle * @nsid: Return namespaces greater than this identifier * @list: User space destination address to transfer the data * @@ -705,16 +705,16 @@ static inline int nvme_identify_active_ns_list(int fd, __u32 nsid, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_identify_allocated_ns_list(int fd, __u32 nsid, +static inline int nvme_identify_allocated_ns_list(nvme_link_t l, __u32 nsid, struct nvme_ns_list *list) { - return nvme_identify_cns_nsid(fd, NVME_IDENTIFY_CNS_ALLOCATED_NS_LIST, + return nvme_identify_cns_nsid(l, NVME_IDENTIFY_CNS_ALLOCATED_NS_LIST, nsid, list); } /** * nvme_identify_ctrl_list() - Retrieves identify controller list - * @fd: File descriptor of nvme device + * @l: Link handle * @cntid: Starting CNTLID to return in the list * @cntlist: User space destination address to transfer the data * @@ -727,14 +727,13 @@ static inline int nvme_identify_allocated_ns_list(int fd, __u32 nsid, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_identify_ctrl_list(int fd, __u16 cntid, +static inline int nvme_identify_ctrl_list(nvme_link_t l, __u16 cntid, struct nvme_ctrl_list *cntlist) { struct nvme_identify_args args = { .result = NULL, .data = cntlist, .args_size = sizeof(args), - .fd = fd, .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, .cns = NVME_IDENTIFY_CNS_CTRL_LIST, .csi = NVME_CSI_NVM, @@ -744,12 +743,12 @@ static inline int nvme_identify_ctrl_list(int fd, __u16 cntid, .uuidx = NVME_UUID_NONE, }; - return nvme_identify(&args); + return nvme_identify(l, &args); } /** * nvme_identify_nsid_ctrl_list() - Retrieves controller list attached to an nsid - * @fd: File descriptor of nvme device + * @l: Link handle * @nsid: Return controllers that are attached to this nsid * @cntid: Starting CNTLID to return in the list * @cntlist: User space destination address to transfer the data @@ -763,14 +762,13 @@ static inline int nvme_identify_ctrl_list(int fd, __u16 cntid, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 */ -static inline int nvme_identify_nsid_ctrl_list(int fd, __u32 nsid, __u16 cntid, +static inline int nvme_identify_nsid_ctrl_list(nvme_link_t l, __u32 nsid, __u16 cntid, struct nvme_ctrl_list *cntlist) { struct nvme_identify_args args = { .result = NULL, .data = cntlist, .args_size = sizeof(args), - .fd = fd, .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, .cns = NVME_IDENTIFY_CNS_NS_CTRL_LIST, .csi = NVME_CSI_NVM, @@ -780,12 +778,12 @@ static inline int nvme_identify_nsid_ctrl_list(int fd, __u32 nsid, __u16 cntid, .uuidx = NVME_UUID_NONE, }; - return nvme_identify(&args); + return nvme_identify(l, &args); } /** * nvme_identify_ns_descs() - Retrieves namespace descriptor list - * @fd: File descriptor of nvme device + * @l: Link handle * @nsid: The namespace id to retrieve descriptors * @descs: User space destination address to transfer the data * @@ -800,16 +798,16 @@ static inline int nvme_identify_nsid_ctrl_list(int fd, __u32 nsid, __u16 cntid, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_identify_ns_descs(int fd, __u32 nsid, +static inline int nvme_identify_ns_descs(nvme_link_t l, __u32 nsid, struct nvme_ns_id_desc *descs) { - return nvme_identify_cns_nsid(fd, NVME_IDENTIFY_CNS_NS_DESC_LIST, + return nvme_identify_cns_nsid(l, NVME_IDENTIFY_CNS_NS_DESC_LIST, nsid, descs); } /** * nvme_identify_nvmset_list() - Retrieves NVM Set List - * @fd: File descriptor of nvme device + * @l: Link handle * @nvmsetid: NVM Set Identifier * @nvmset: User space destination address to transfer the data * @@ -823,14 +821,13 @@ static inline int nvme_identify_ns_descs(int fd, __u32 nsid, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_identify_nvmset_list(int fd, __u16 nvmsetid, +static inline int nvme_identify_nvmset_list(nvme_link_t l, __u16 nvmsetid, struct nvme_id_nvmset_list *nvmset) { struct nvme_identify_args args = { .result = NULL, .data = nvmset, .args_size = sizeof(args), - .fd = fd, .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, .cns = NVME_IDENTIFY_CNS_NVMSET_LIST, .csi = NVME_CSI_NVM, @@ -840,13 +837,13 @@ static inline int nvme_identify_nvmset_list(int fd, __u16 nvmsetid, .uuidx = NVME_UUID_NONE, }; - return nvme_identify(&args); + return nvme_identify(l, &args); } /** * nvme_identify_primary_ctrl() - Retrieve NVMe Primary Controller * identification - * @fd: File descriptor of nvme device + * @l: Link handle * @cntid: Return controllers starting at this identifier * @cap: User space destination buffer address to transfer the data * @@ -855,14 +852,13 @@ static inline int nvme_identify_nvmset_list(int fd, __u16 nvmsetid, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_identify_primary_ctrl(int fd, __u16 cntid, +static inline int nvme_identify_primary_ctrl(nvme_link_t l, __u16 cntid, struct nvme_primary_ctrl_cap *cap) { struct nvme_identify_args args = { .result = NULL, .data = cap, .args_size = sizeof(args), - .fd = fd, .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, .cns = NVME_IDENTIFY_CNS_PRIMARY_CTRL_CAP, .csi = NVME_CSI_NVM, @@ -872,12 +868,12 @@ static inline int nvme_identify_primary_ctrl(int fd, __u16 cntid, .uuidx = NVME_UUID_NONE, }; - return nvme_identify(&args); + return nvme_identify(l, &args); } /** * nvme_identify_secondary_ctrl_list() - Retrieves secondary controller list - * @fd: File descriptor of nvme device + * @l: Link handle * @cntid: Return controllers starting at this identifier * @sc_list: User space destination address to transfer the data * @@ -892,14 +888,13 @@ static inline int nvme_identify_primary_ctrl(int fd, __u16 cntid, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_identify_secondary_ctrl_list(int fd, +static inline int nvme_identify_secondary_ctrl_list(nvme_link_t l, __u16 cntid, struct nvme_secondary_ctrl_list *sc_list) { struct nvme_identify_args args = { .result = NULL, .data = sc_list, .args_size = sizeof(args), - .fd = fd, .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, .cns = NVME_IDENTIFY_CNS_SECONDARY_CTRL_LIST, .csi = NVME_CSI_NVM, @@ -909,13 +904,13 @@ static inline int nvme_identify_secondary_ctrl_list(int fd, .uuidx = NVME_UUID_NONE, }; - return nvme_identify(&args); + return nvme_identify(l, &args); } /** * nvme_identify_ns_granularity() - Retrieves namespace granularity * identification - * @fd: File descriptor of nvme device + * @l: Link handle * @gr_list: User space destination address to transfer the data * * If the controller supports reporting of Namespace Granularity, then a @@ -928,16 +923,16 @@ static inline int nvme_identify_secondary_ctrl_list(int fd, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_identify_ns_granularity(int fd, +static inline int nvme_identify_ns_granularity(nvme_link_t l, struct nvme_id_ns_granularity_list *gr_list) { - return nvme_identify_cns_nsid(fd, NVME_IDENTIFY_CNS_NS_GRANULARITY, + return nvme_identify_cns_nsid(l, NVME_IDENTIFY_CNS_NS_GRANULARITY, NVME_NSID_NONE, gr_list); } /** * nvme_identify_uuid() - Retrieves device's UUIDs - * @fd: File descriptor of nvme device + * @l: Link handle * @uuid_list: User space destination address to transfer the data * * Each UUID List entry is either 0h, the NVMe Invalid UUID, or a valid UUID. @@ -948,15 +943,15 @@ static inline int nvme_identify_ns_granularity(int fd, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_identify_uuid(int fd, struct nvme_id_uuid_list *uuid_list) +static inline int nvme_identify_uuid(nvme_link_t l, struct nvme_id_uuid_list *uuid_list) { - return nvme_identify_cns_nsid(fd, NVME_IDENTIFY_CNS_UUID_LIST, + return nvme_identify_cns_nsid(l, NVME_IDENTIFY_CNS_UUID_LIST, NVME_NSID_NONE, uuid_list); } /** * nvme_identify_ns_csi() - I/O command set specific identify namespace data - * @fd: File descriptor of nvme device + * @l: Link handle * @nsid: Namespace to identify * @uuidx: UUID Index for differentiating vendor specific encoding * @csi: Command Set Identifier @@ -968,14 +963,13 @@ static inline int nvme_identify_uuid(int fd, struct nvme_id_uuid_list *uuid_list * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_identify_ns_csi(int fd, __u32 nsid, __u8 uuidx, +static inline int nvme_identify_ns_csi(nvme_link_t l, __u32 nsid, __u8 uuidx, enum nvme_csi csi, void *data) { struct nvme_identify_args args = { .result = NULL, .data = data, .args_size = sizeof(args), - .fd = fd, .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, .cns = NVME_IDENTIFY_CNS_CSI_NS, .csi = csi, @@ -985,12 +979,12 @@ static inline int nvme_identify_ns_csi(int fd, __u32 nsid, __u8 uuidx, .uuidx = uuidx, }; - return nvme_identify(&args); + return nvme_identify(l, &args); } /** * nvme_identify_ctrl_csi() - I/O command set specific Identify Controller data - * @fd: File descriptor of nvme device + * @l: Link handle * @csi: Command Set Identifier * @data: User space destination address to transfer the data * @@ -1001,13 +995,12 @@ static inline int nvme_identify_ns_csi(int fd, __u32 nsid, __u8 uuidx, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_identify_ctrl_csi(int fd, enum nvme_csi csi, void *data) +static inline int nvme_identify_ctrl_csi(nvme_link_t l, enum nvme_csi csi, void *data) { struct nvme_identify_args args = { .result = NULL, .data = data, .args_size = sizeof(args), - .fd = fd, .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, .cns = NVME_IDENTIFY_CNS_CSI_CTRL, .csi = csi, @@ -1017,12 +1010,12 @@ static inline int nvme_identify_ctrl_csi(int fd, enum nvme_csi csi, void *data) .uuidx = NVME_UUID_NONE, }; - return nvme_identify(&args); + return nvme_identify(l, &args); } /** * nvme_identify_active_ns_list_csi() - Active namespace ID list associated with a specified I/O command set - * @fd: File descriptor of nvme device + * @l: Link handle * @nsid: Return namespaces greater than this identifier * @csi: Command Set Identifier * @ns_list: User space destination address to transfer the data @@ -1037,14 +1030,13 @@ static inline int nvme_identify_ctrl_csi(int fd, enum nvme_csi csi, void *data) * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_identify_active_ns_list_csi(int fd, __u32 nsid, +static inline int nvme_identify_active_ns_list_csi(nvme_link_t l, __u32 nsid, enum nvme_csi csi, struct nvme_ns_list *ns_list) { struct nvme_identify_args args = { .result = NULL, .data = ns_list, .args_size = sizeof(args), - .fd = fd, .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, .cns = NVME_IDENTIFY_CNS_CSI_NS_ACTIVE_LIST, .csi = csi, @@ -1054,12 +1046,12 @@ static inline int nvme_identify_active_ns_list_csi(int fd, __u32 nsid, .uuidx = NVME_UUID_NONE, }; - return nvme_identify(&args); + return nvme_identify(l, &args); } /** * nvme_identify_allocated_ns_list_csi() - Allocated namespace ID list associated with a specified I/O command set - * @fd: File descriptor of nvme device + * @l: Link handle * @nsid: Return namespaces greater than this identifier * @csi: Command Set Identifier * @ns_list: User space destination address to transfer the data @@ -1074,14 +1066,13 @@ static inline int nvme_identify_active_ns_list_csi(int fd, __u32 nsid, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_identify_allocated_ns_list_csi(int fd, __u32 nsid, +static inline int nvme_identify_allocated_ns_list_csi(nvme_link_t l, __u32 nsid, enum nvme_csi csi, struct nvme_ns_list *ns_list) { struct nvme_identify_args args = { .result = NULL, .data = ns_list, .args_size = sizeof(args), - .fd = fd, .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, .cns = NVME_IDENTIFY_CNS_CSI_ALLOCATED_NS_LIST, .csi = csi, @@ -1091,12 +1082,12 @@ static inline int nvme_identify_allocated_ns_list_csi(int fd, __u32 nsid, .uuidx = NVME_UUID_NONE, }; - return nvme_identify(&args); + return nvme_identify(l, &args); } /** * nvme_identify_independent_identify_ns() - I/O command set independent Identify namespace data - * @fd: File descriptor of nvme device + * @l: Link handle * @nsid: Return namespaces greater than this identifier * @ns: I/O Command Set Independent Identify Namespace data * structure @@ -1107,16 +1098,16 @@ static inline int nvme_identify_allocated_ns_list_csi(int fd, __u32 nsid, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_identify_independent_identify_ns(int fd, __u32 nsid, +static inline int nvme_identify_independent_identify_ns(nvme_link_t l, __u32 nsid, struct nvme_id_independent_id_ns *ns) { return nvme_identify_cns_nsid( - fd, NVME_IDENTIFY_CNS_CSI_INDEPENDENT_ID_NS, nsid, ns); + l, NVME_IDENTIFY_CNS_CSI_INDEPENDENT_ID_NS, nsid, ns); } /** * nvme_identify_ns_csi_user_data_format() - Identify namespace user data format - * @fd: File descriptor of nvme device + * @l: Link handle * @user_data_format: Return namespaces capability of identifier * @uuidx: UUID selection, if supported * @csi: Command Set Identifier @@ -1128,7 +1119,7 @@ static inline int nvme_identify_independent_identify_ns(int fd, __u32 nsid, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_identify_ns_csi_user_data_format(int fd, +static inline int nvme_identify_ns_csi_user_data_format(nvme_link_t l, __u16 user_data_format, __u8 uuidx, enum nvme_csi csi, void *data) { @@ -1136,7 +1127,6 @@ static inline int nvme_identify_ns_csi_user_data_format(int fd, .result = NULL, .data = data, .args_size = sizeof(args), - .fd = fd, .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, .cns = NVME_IDENTIFY_CNS_NS_USER_DATA_FORMAT, .csi = csi, @@ -1146,12 +1136,12 @@ static inline int nvme_identify_ns_csi_user_data_format(int fd, .uuidx = uuidx, }; - return nvme_identify(&args); + return nvme_identify(l, &args); } /** * nvme_identify_iocs_ns_csi_user_data_format() - Identify I/O command set namespace data structure - * @fd: File descriptor of nvme device + * @l: Link handle * @user_data_format: Return namespaces capability of identifier * @uuidx: UUID selection, if supported * @csi: Command Set Identifier @@ -1164,7 +1154,7 @@ static inline int nvme_identify_ns_csi_user_data_format(int fd, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_identify_iocs_ns_csi_user_data_format(int fd, +static inline int nvme_identify_iocs_ns_csi_user_data_format(nvme_link_t l, __u16 user_data_format, __u8 uuidx, enum nvme_csi csi, void *data) { @@ -1172,7 +1162,6 @@ static inline int nvme_identify_iocs_ns_csi_user_data_format(int fd, .result = NULL, .data = data, .args_size = sizeof(args), - .fd = fd, .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, .cns = NVME_IDENTIFY_CNS_CSI_NS_USER_DATA_FORMAT, .csi = csi, @@ -1182,12 +1171,12 @@ static inline int nvme_identify_iocs_ns_csi_user_data_format(int fd, .uuidx = uuidx, }; - return nvme_identify(&args); + return nvme_identify(l, &args); } /** * nvme_nvm_identify_ctrl() - Identify controller data - * @fd: File descriptor of nvme device + * @l: Link handle * @id: User space destination address to transfer the data * * Return an identify controller data structure to the host of @@ -1196,14 +1185,14 @@ static inline int nvme_identify_iocs_ns_csi_user_data_format(int fd, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_nvm_identify_ctrl(int fd, struct nvme_id_ctrl_nvm *id) +static inline int nvme_nvm_identify_ctrl(nvme_link_t l, struct nvme_id_ctrl_nvm *id) { - return nvme_identify_ctrl_csi(fd, NVME_CSI_NVM, id); + return nvme_identify_ctrl_csi(l, NVME_CSI_NVM, id); } /** * nvme_identify_domain_list() - Domain list data - * @fd: File descriptor of nvme device + * @l: Link handle * @domid: Domain ID * @list: User space destination address to transfer data * @@ -1217,14 +1206,13 @@ static inline int nvme_nvm_identify_ctrl(int fd, struct nvme_id_ctrl_nvm *id) * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_identify_domain_list(int fd, __u16 domid, +static inline int nvme_identify_domain_list(nvme_link_t l, __u16 domid, struct nvme_id_domain_list *list) { struct nvme_identify_args args = { .result = NULL, .data = list, .args_size = sizeof(args), - .fd = fd, .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, .cns = NVME_IDENTIFY_CNS_DOMAIN_LIST, .csi = NVME_CSI_NVM, @@ -1234,26 +1222,25 @@ static inline int nvme_identify_domain_list(int fd, __u16 domid, .uuidx = NVME_UUID_NONE, }; - return nvme_identify(&args); + return nvme_identify(l, &args); } /** * nvme_identify_endurance_group_list() - Endurance group list data - * @fd: File descriptor of nvme device + * @l: Link handle * @endgrp_id: Endurance group identifier * @list: Array of endurance group identifiers * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_identify_endurance_group_list(int fd, __u16 endgrp_id, +static inline int nvme_identify_endurance_group_list(nvme_link_t l, __u16 endgrp_id, struct nvme_id_endurance_group_list *list) { struct nvme_identify_args args = { .result = NULL, .data = list, .args_size = sizeof(args), - .fd = fd, .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, .cns = NVME_IDENTIFY_CNS_ENDURANCE_GROUP_ID, .csi = NVME_CSI_NVM, @@ -1263,12 +1250,12 @@ static inline int nvme_identify_endurance_group_list(int fd, __u16 endgrp_id, .uuidx = NVME_UUID_NONE, }; - return nvme_identify(&args); + return nvme_identify(l, &args); } /** * nvme_identify_iocs() - I/O command set data structure - * @fd: File descriptor of nvme device + * @l: Link handle * @cntlid: Controller ID * @iocs: User space destination address to transfer the data * @@ -1278,14 +1265,13 @@ static inline int nvme_identify_endurance_group_list(int fd, __u16 endgrp_id, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_identify_iocs(int fd, __u16 cntlid, +static inline int nvme_identify_iocs(nvme_link_t l, __u16 cntlid, struct nvme_id_iocs *iocs) { struct nvme_identify_args args = { .result = NULL, .data = iocs, .args_size = sizeof(args), - .fd = fd, .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, .cns = NVME_IDENTIFY_CNS_COMMAND_SET_STRUCTURE, .csi = NVME_CSI_NVM, @@ -1295,59 +1281,60 @@ static inline int nvme_identify_iocs(int fd, __u16 cntlid, .uuidx = NVME_UUID_NONE, }; - return nvme_identify(&args); + return nvme_identify(l, &args); } /** * nvme_zns_identify_ns() - ZNS identify namespace data - * @fd: File descriptor of nvme device + * @l: Link handle * @nsid: Namespace to identify * @data: User space destination address to transfer the data * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_zns_identify_ns(int fd, __u32 nsid, +static inline int nvme_zns_identify_ns(nvme_link_t l, __u32 nsid, struct nvme_zns_id_ns *data) { return nvme_identify_ns_csi( - fd, nsid, NVME_UUID_NONE, NVME_CSI_ZNS, data); + l, nsid, NVME_UUID_NONE, NVME_CSI_ZNS, data); } /** * nvme_zns_identify_ctrl() - ZNS identify controller data - * @fd: File descriptor of nvme device + * @l: Link handle * @id: User space destination address to transfer the data * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_zns_identify_ctrl(int fd, struct nvme_zns_id_ctrl *id) +static inline int nvme_zns_identify_ctrl(nvme_link_t l, struct nvme_zns_id_ctrl *id) { - return nvme_identify_ctrl_csi(fd, NVME_CSI_ZNS, id); + return nvme_identify_ctrl_csi(l, NVME_CSI_ZNS, id); } /** * nvme_get_log() - NVMe Admin Get Log command + * @l: Link handle * @args: &struct nvme_get_log_args argument structure * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_get_log(struct nvme_get_log_args *args); +int nvme_get_log(nvme_link_t l, struct nvme_get_log_args *args); /** * nvme_get_log_page() - Get log page data - * @fd: File descriptor of nvme device + * @l: Link handle * @xfer_len: Max log transfer size per request to split the total. * @args: &struct nvme_get_log_args argument structure * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_get_log_page(int fd, __u32 xfer_len, struct nvme_get_log_args *args); +int nvme_get_log_page(nvme_link_t l, __u32 xfer_len, struct nvme_get_log_args *args); -static inline int nvme_get_nsid_log(int fd, bool rae, +static inline int nvme_get_nsid_log(nvme_link_t l, bool rae, enum nvme_cmd_get_log_lid lid, __u32 nsid, __u32 len, void *log) { @@ -1356,7 +1343,6 @@ static inline int nvme_get_nsid_log(int fd, bool rae, .result = NULL, .log = log, .args_size = sizeof(args), - .fd = fd, .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, .lid = lid, .len = len, @@ -1369,10 +1355,10 @@ static inline int nvme_get_nsid_log(int fd, bool rae, .ot = false, }; - return nvme_get_log_page(fd, NVME_LOG_PAGE_PDU_SIZE, &args); + return nvme_get_log_page(l, NVME_LOG_PAGE_PDU_SIZE, &args); } -static inline int nvme_get_endgid_log(int fd, bool rae, enum nvme_cmd_get_log_lid lid, __u16 endgid, +static inline int nvme_get_endgid_log(nvme_link_t l, bool rae, enum nvme_cmd_get_log_lid lid, __u16 endgid, __u32 len, void *log) { struct nvme_get_log_args args = { @@ -1380,7 +1366,6 @@ static inline int nvme_get_endgid_log(int fd, bool rae, enum nvme_cmd_get_log_li .result = NULL, .log = log, .args_size = sizeof(args), - .fd = fd, .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, .lid = lid, .len = len, @@ -1393,34 +1378,34 @@ static inline int nvme_get_endgid_log(int fd, bool rae, enum nvme_cmd_get_log_li .ot = false, }; - return nvme_get_log_page(fd, NVME_LOG_PAGE_PDU_SIZE, &args); + return nvme_get_log_page(l, NVME_LOG_PAGE_PDU_SIZE, &args); } -static inline int nvme_get_log_simple(int fd, enum nvme_cmd_get_log_lid lid, +static inline int nvme_get_log_simple(nvme_link_t l, enum nvme_cmd_get_log_lid lid, __u32 len, void *log) { - return nvme_get_nsid_log(fd, false, lid, NVME_NSID_ALL, len, log); + return nvme_get_nsid_log(l, false, lid, NVME_NSID_ALL, len, log); } /** * nvme_get_log_supported_log_pages() - Retrieve nmve supported log pages - * @fd: File descriptor of nvme device + * @l: Link handle * @rae: Retain asynchronous events * @log: Array of LID supported and Effects data structures * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_get_log_supported_log_pages(int fd, bool rae, +static inline int nvme_get_log_supported_log_pages(nvme_link_t l, bool rae, struct nvme_supported_log_pages *log) { - return nvme_get_nsid_log(fd, rae, NVME_LOG_LID_SUPPORTED_LOG_PAGES, + return nvme_get_nsid_log(l, rae, NVME_LOG_LID_SUPPORTED_LOG_PAGES, NVME_NSID_ALL, sizeof(*log), log); } /** * nvme_get_log_error() - Retrieve nvme error log - * @fd: File descriptor of nvme device + * @l: Link handle * @nr_entries: Number of error log entries allocated * @rae: Retain asynchronous events * @err_log: Array of error logs of size 'entries' @@ -1432,17 +1417,17 @@ static inline int nvme_get_log_supported_log_pages(int fd, bool rae, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_get_log_error(int fd, unsigned int nr_entries, bool rae, +static inline int nvme_get_log_error(nvme_link_t l, unsigned int nr_entries, bool rae, struct nvme_error_log_page *err_log) { - return nvme_get_nsid_log(fd, rae, NVME_LOG_LID_ERROR, + return nvme_get_nsid_log(l, rae, NVME_LOG_LID_ERROR, NVME_NSID_ALL, sizeof(*err_log) * nr_entries, err_log); } /** * nvme_get_log_smart() - Retrieve nvme smart log - * @fd: File descriptor of nvme device + * @l: Link handle * @nsid: Optional namespace identifier * @rae: Retain asynchronous events * @smart_log: User address to store the smart log @@ -1457,16 +1442,16 @@ static inline int nvme_get_log_error(int fd, unsigned int nr_entries, bool rae, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_get_log_smart(int fd, __u32 nsid, bool rae, +static inline int nvme_get_log_smart(nvme_link_t l, __u32 nsid, bool rae, struct nvme_smart_log *smart_log) { - return nvme_get_nsid_log(fd, rae, NVME_LOG_LID_SMART, + return nvme_get_nsid_log(l, rae, NVME_LOG_LID_SMART, nsid, sizeof(*smart_log), smart_log); } /** * nvme_get_log_fw_slot() - Retrieves the controller firmware log - * @fd: File descriptor of nvme device + * @l: Link handle * @rae: Retain asynchronous events * @fw_log: User address to store the log page * @@ -1477,16 +1462,16 @@ static inline int nvme_get_log_smart(int fd, __u32 nsid, bool rae, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_get_log_fw_slot(int fd, bool rae, +static inline int nvme_get_log_fw_slot(nvme_link_t l, bool rae, struct nvme_firmware_slot *fw_log) { - return nvme_get_nsid_log(fd, rae, NVME_LOG_LID_FW_SLOT, + return nvme_get_nsid_log(l, rae, NVME_LOG_LID_FW_SLOT, NVME_NSID_ALL, sizeof(*fw_log), fw_log); } /** * nvme_get_log_changed_ns_list() - Retrieve namespace changed list - * @fd: File descriptor of nvme device + * @l: Link handle * @rae: Retain asynchronous events * @ns_log: User address to store the log page * @@ -1497,16 +1482,16 @@ static inline int nvme_get_log_fw_slot(int fd, bool rae, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_get_log_changed_ns_list(int fd, bool rae, +static inline int nvme_get_log_changed_ns_list(nvme_link_t l, bool rae, struct nvme_ns_list *ns_log) { - return nvme_get_nsid_log(fd, rae, NVME_LOG_LID_CHANGED_NS, + return nvme_get_nsid_log(l, rae, NVME_LOG_LID_CHANGED_NS, NVME_NSID_ALL, sizeof(*ns_log), ns_log); } /** * nvme_get_log_cmd_effects() - Retrieve nvme command effects log - * @fd: File descriptor of nvme device + * @l: Link handle * @csi: Command Set Identifier * @effects_log:User address to store the effects log * @@ -1516,7 +1501,7 @@ static inline int nvme_get_log_changed_ns_list(int fd, bool rae, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_get_log_cmd_effects(int fd, enum nvme_csi csi, +static inline int nvme_get_log_cmd_effects(nvme_link_t l, enum nvme_csi csi, struct nvme_cmd_effects_log *effects_log) { struct nvme_get_log_args args = { @@ -1524,7 +1509,6 @@ static inline int nvme_get_log_cmd_effects(int fd, enum nvme_csi csi, .result = NULL, .log = effects_log, .args_size = sizeof(args), - .fd = fd, .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, .lid = NVME_LOG_LID_CMD_EFFECTS, .len = sizeof(*effects_log), @@ -1536,12 +1520,12 @@ static inline int nvme_get_log_cmd_effects(int fd, enum nvme_csi csi, .rae = false, .ot = false, }; - return nvme_get_log_page(fd, NVME_LOG_PAGE_PDU_SIZE, &args); + return nvme_get_log_page(l, NVME_LOG_PAGE_PDU_SIZE, &args); } /** * nvme_get_log_device_self_test() - Retrieve the device self test log - * @fd: File descriptor of nvme device + * @l: Link handle * @log: Userspace address of the log payload * * The log page indicates the status of an in progress self test and the @@ -1551,23 +1535,23 @@ static inline int nvme_get_log_cmd_effects(int fd, enum nvme_csi csi, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_get_log_device_self_test(int fd, +static inline int nvme_get_log_device_self_test(nvme_link_t l, struct nvme_self_test_log *log) { - return nvme_get_nsid_log(fd, false, NVME_LOG_LID_DEVICE_SELF_TEST, + return nvme_get_nsid_log(l, false, NVME_LOG_LID_DEVICE_SELF_TEST, NVME_NSID_ALL, sizeof(*log), log); } /** * nvme_get_log_create_telemetry_host_mcda() - Create host telemetry log - * @fd: File descriptor of nvme device + * @l: Link handle * @mcda: Maximum Created Data Area * @log: Userspace address of the log payload * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_get_log_create_telemetry_host_mcda(int fd, +static inline int nvme_get_log_create_telemetry_host_mcda(nvme_link_t l, enum nvme_telemetry_da mcda, struct nvme_telemetry_log *log) { @@ -1576,7 +1560,6 @@ static inline int nvme_get_log_create_telemetry_host_mcda(int fd, .result = NULL, .log = log, .args_size = sizeof(args), - .fd = fd, .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, .lid = NVME_LOG_LID_TELEMETRY_HOST, .len = sizeof(*log), @@ -1588,26 +1571,26 @@ static inline int nvme_get_log_create_telemetry_host_mcda(int fd, .rae = false, .ot = false, }; - return nvme_get_log_page(fd, NVME_LOG_PAGE_PDU_SIZE, &args); + return nvme_get_log_page(l, NVME_LOG_PAGE_PDU_SIZE, &args); } /** * nvme_get_log_create_telemetry_host() - Create host telemetry log - * @fd: File descriptor of nvme device + * @l: Link handle * @log: Userspace address of the log payload * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_get_log_create_telemetry_host(int fd, +static inline int nvme_get_log_create_telemetry_host(nvme_link_t l, struct nvme_telemetry_log *log) { - return nvme_get_log_create_telemetry_host_mcda(fd, NVME_TELEMETRY_DA_CTRL_DETERMINE, log); + return nvme_get_log_create_telemetry_host_mcda(l, NVME_TELEMETRY_DA_CTRL_DETERMINE, log); } /** * nvme_get_log_telemetry_host() - Get Telemetry Host-Initiated log page - * @fd: File descriptor of nvme device + * @l: Link handle * @offset: Offset into the telemetry data * @len: Length of provided user buffer to hold the log data in bytes * @log: User address for log page data @@ -1618,7 +1601,7 @@ static inline int nvme_get_log_create_telemetry_host(int fd, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_get_log_telemetry_host(int fd, __u64 offset, +static inline int nvme_get_log_telemetry_host(nvme_link_t l, __u64 offset, __u32 len, void *log) { struct nvme_get_log_args args = { @@ -1626,7 +1609,6 @@ static inline int nvme_get_log_telemetry_host(int fd, __u64 offset, .result = NULL, .log = log, .args_size = sizeof(args), - .fd = fd, .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, .lid = NVME_LOG_LID_TELEMETRY_HOST, .len = len, @@ -1638,12 +1620,12 @@ static inline int nvme_get_log_telemetry_host(int fd, __u64 offset, .rae = false, .ot = false, }; - return nvme_get_log_page(fd, NVME_LOG_PAGE_PDU_SIZE, &args); + return nvme_get_log_page(l, NVME_LOG_PAGE_PDU_SIZE, &args); } /** * nvme_get_log_telemetry_ctrl() - Get Telemetry Controller-Initiated log page - * @fd: File descriptor of nvme device + * @l: Link handle * @rae: Retain asynchronous events * @offset: Offset into the telemetry data * @len: Length of provided user buffer to hold the log data in bytes @@ -1655,7 +1637,7 @@ static inline int nvme_get_log_telemetry_host(int fd, __u64 offset, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_get_log_telemetry_ctrl(int fd, bool rae, +static inline int nvme_get_log_telemetry_ctrl(nvme_link_t l, bool rae, __u64 offset, __u32 len, void *log) { struct nvme_get_log_args args = { @@ -1663,7 +1645,6 @@ static inline int nvme_get_log_telemetry_ctrl(int fd, bool rae, .result = NULL, .log = log, .args_size = sizeof(args), - .fd = fd, .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, .lid = NVME_LOG_LID_TELEMETRY_CTRL, .len = len, @@ -1675,12 +1656,12 @@ static inline int nvme_get_log_telemetry_ctrl(int fd, bool rae, .rae = rae, .ot = false, }; - return nvme_get_log_page(fd, NVME_LOG_PAGE_PDU_SIZE, &args); + return nvme_get_log_page(l, NVME_LOG_PAGE_PDU_SIZE, &args); } /** * nvme_get_log_endurance_group() - Get Endurance Group log - * @fd: File descriptor of nvme device + * @l: Link handle * @endgid: Starting group identifier to return in the list * @log: User address to store the endurance log * @@ -1694,7 +1675,7 @@ static inline int nvme_get_log_telemetry_ctrl(int fd, bool rae, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_get_log_endurance_group(int fd, __u16 endgid, +static inline int nvme_get_log_endurance_group(nvme_link_t l, __u16 endgid, struct nvme_endurance_group_log *log) { struct nvme_get_log_args args = { @@ -1702,7 +1683,6 @@ static inline int nvme_get_log_endurance_group(int fd, __u16 endgid, .result = NULL, .log = log, .args_size = sizeof(args), - .fd = fd, .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, .lid = NVME_LOG_LID_ENDURANCE_GROUP, .len = sizeof(*log), @@ -1714,19 +1694,19 @@ static inline int nvme_get_log_endurance_group(int fd, __u16 endgid, .rae = false, .ot = false, }; - return nvme_get_log_page(fd, NVME_LOG_PAGE_PDU_SIZE, &args); + return nvme_get_log_page(l, NVME_LOG_PAGE_PDU_SIZE, &args); } /** * nvme_get_log_predictable_lat_nvmset() - Predictable Latency Per NVM Set - * @fd: File descriptor of nvme device + * @l: Link handle * @nvmsetid: NVM set id * @log: User address to store the predictable latency log * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_get_log_predictable_lat_nvmset(int fd, __u16 nvmsetid, +static inline int nvme_get_log_predictable_lat_nvmset(nvme_link_t l, __u16 nvmsetid, struct nvme_nvmset_predictable_lat_log *log) { struct nvme_get_log_args args = { @@ -1734,7 +1714,6 @@ static inline int nvme_get_log_predictable_lat_nvmset(int fd, __u16 nvmsetid, .result = NULL, .log = log, .args_size = sizeof(args), - .fd = fd, .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, .lid = NVME_LOG_LID_PREDICTABLE_LAT_NVMSET, .len = sizeof(*log), @@ -1746,12 +1725,12 @@ static inline int nvme_get_log_predictable_lat_nvmset(int fd, __u16 nvmsetid, .rae = false, .ot = false, }; - return nvme_get_log_page(fd, NVME_LOG_PAGE_PDU_SIZE, &args); + return nvme_get_log_page(l, NVME_LOG_PAGE_PDU_SIZE, &args); } /** * nvme_get_log_predictable_lat_event() - Retrieve Predictable Latency Event Aggregate Log Page - * @fd: File descriptor of nvme device + * @l: Link handle * @rae: Retain asynchronous events * @offset: Offset into the predictable latency event * @len: Length of provided user buffer to hold the log data in bytes @@ -1760,7 +1739,7 @@ static inline int nvme_get_log_predictable_lat_nvmset(int fd, __u16 nvmsetid, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_get_log_predictable_lat_event(int fd, bool rae, +static inline int nvme_get_log_predictable_lat_event(nvme_link_t l, bool rae, __u32 offset, __u32 len, void *log) { struct nvme_get_log_args args = { @@ -1768,7 +1747,6 @@ static inline int nvme_get_log_predictable_lat_event(int fd, bool rae, .result = NULL, .log = log, .args_size = sizeof(args), - .fd = fd, .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, .lid = NVME_LOG_LID_PREDICTABLE_LAT_AGG, .len = len, @@ -1780,18 +1758,18 @@ static inline int nvme_get_log_predictable_lat_event(int fd, bool rae, .rae = rae, .ot = false, }; - return nvme_get_log_page(fd, NVME_LOG_PAGE_PDU_SIZE, &args); + return nvme_get_log_page(l, NVME_LOG_PAGE_PDU_SIZE, &args); } /** * nvme_get_log_fdp_configurations() - Get list of Flexible Data Placement configurations - * @fd: File descriptor of nvme device + * @l: Link handle * @egid: Endurance group identifier * @offset: Offset into log page * @len: Length (in bytes) of provided user buffer to hold the log data * @log: Log page data buffer */ -static inline int nvme_get_log_fdp_configurations(int fd, __u16 egid, +static inline int nvme_get_log_fdp_configurations(nvme_link_t l, __u16 egid, __u32 offset, __u32 len, void *log) { struct nvme_get_log_args args = { @@ -1799,7 +1777,6 @@ static inline int nvme_get_log_fdp_configurations(int fd, __u16 egid, .result = NULL, .log = log, .args_size = sizeof(args), - .fd = fd, .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, .lid = NVME_LOG_LID_FDP_CONFIGS, .len = len, @@ -1810,18 +1787,18 @@ static inline int nvme_get_log_fdp_configurations(int fd, __u16 egid, .uuidx = NVME_UUID_NONE, }; - return nvme_get_log(&args); + return nvme_get_log(l, &args); } /** * nvme_get_log_reclaim_unit_handle_usage() - Get reclaim unit handle usage - * @fd: File descriptor of nvme device + * @l: Link handle * @egid: Endurance group identifier * @offset: Offset into log page * @len: Length (in bytes) of provided user buffer to hold the log data * @log: Log page data buffer */ -static inline int nvme_get_log_reclaim_unit_handle_usage(int fd, __u16 egid, +static inline int nvme_get_log_reclaim_unit_handle_usage(nvme_link_t l, __u16 egid, __u32 offset, __u32 len, void *log) { struct nvme_get_log_args args = { @@ -1829,7 +1806,6 @@ static inline int nvme_get_log_reclaim_unit_handle_usage(int fd, __u16 egid, .result = NULL, .log = log, .args_size = sizeof(args), - .fd = fd, .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, .lid = NVME_LOG_LID_FDP_RUH_USAGE, .len = len, @@ -1840,25 +1816,24 @@ static inline int nvme_get_log_reclaim_unit_handle_usage(int fd, __u16 egid, .uuidx = NVME_UUID_NONE, }; - return nvme_get_log(&args); + return nvme_get_log(l, &args); } /** * nvme_get_log_fdp_stats() - Get Flexible Data Placement statistics - * @fd: File descriptor of nvme device + * @l: Link handle * @egid: Endurance group identifier * @offset: Offset into log page * @len: Length (in bytes) of provided user buffer to hold the log data * @log: Log page data buffer */ -static inline int nvme_get_log_fdp_stats(int fd, __u16 egid, __u32 offset, __u32 len, void *log) +static inline int nvme_get_log_fdp_stats(nvme_link_t l, __u16 egid, __u32 offset, __u32 len, void *log) { struct nvme_get_log_args args = { .lpo = offset, .result = NULL, .log = log, .args_size = sizeof(args), - .fd = fd, .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, .lid = NVME_LOG_LID_FDP_STATS, .len = len, @@ -1869,19 +1844,19 @@ static inline int nvme_get_log_fdp_stats(int fd, __u16 egid, __u32 offset, __u32 .uuidx = NVME_UUID_NONE, }; - return nvme_get_log(&args); + return nvme_get_log(l, &args); } /** * nvme_get_log_fdp_events() - Get Flexible Data Placement events - * @fd: File descriptor of nvme device + * @l: Link handle * @egid: Endurance group identifier * @host_events: Whether to report host or controller events * @offset: Offset into log page * @len: Length (in bytes) of provided user buffer to hold the log data * @log: Log page data buffer */ -static inline int nvme_get_log_fdp_events(int fd, __u16 egid, bool host_events, __u32 offset, +static inline int nvme_get_log_fdp_events(nvme_link_t l, __u16 egid, bool host_events, __u32 offset, __u32 len, void *log) { struct nvme_get_log_args args = { @@ -1889,7 +1864,6 @@ static inline int nvme_get_log_fdp_events(int fd, __u16 egid, bool host_events, .result = NULL, .log = log, .args_size = sizeof(args), - .fd = fd, .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, .lid = NVME_LOG_LID_FDP_EVENTS, .len = len, @@ -1900,12 +1874,12 @@ static inline int nvme_get_log_fdp_events(int fd, __u16 egid, bool host_events, .uuidx = NVME_UUID_NONE, }; - return nvme_get_log(&args); + return nvme_get_log(l, &args); } /** * nvme_get_log_ana() - Retrieve Asymmetric Namespace Access log page - * @fd: File descriptor of nvme device + * @l: Link handle * @lsp: Log specific, see &enum nvme_get_log_ana_lsp * @rae: Retain asynchronous events * @offset: Offset to the start of the log page @@ -1921,7 +1895,7 @@ static inline int nvme_get_log_fdp_events(int fd, __u16 egid, bool host_events, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_get_log_ana(int fd, enum nvme_log_ana_lsp lsp, bool rae, +static inline int nvme_get_log_ana(nvme_link_t l, enum nvme_log_ana_lsp lsp, bool rae, __u64 offset, __u32 len, void *log) { struct nvme_get_log_args args = { @@ -1929,7 +1903,6 @@ static inline int nvme_get_log_ana(int fd, enum nvme_log_ana_lsp lsp, bool rae, .result = NULL, .log = log, .args_size = sizeof(args), - .fd = fd, .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, .lid = NVME_LOG_LID_ANA, .len = len, @@ -1941,12 +1914,12 @@ static inline int nvme_get_log_ana(int fd, enum nvme_log_ana_lsp lsp, bool rae, .rae = rae, .ot = false, }; - return nvme_get_log_page(fd, NVME_LOG_PAGE_PDU_SIZE, &args); + return nvme_get_log_page(l, NVME_LOG_PAGE_PDU_SIZE, &args); } /** * nvme_get_log_ana_groups() - Retrieve Asymmetric Namespace Access groups only log page - * @fd: File descriptor of nvme device + * @l: Link handle * @rae: Retain asynchronous events * @len: The allocated length of the log page * @log: User address to store the ana group log @@ -1956,16 +1929,16 @@ static inline int nvme_get_log_ana(int fd, enum nvme_log_ana_lsp lsp, bool rae, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_get_log_ana_groups(int fd, bool rae, __u32 len, +static inline int nvme_get_log_ana_groups(nvme_link_t l, bool rae, __u32 len, struct nvme_ana_log *log) { - return nvme_get_log_ana(fd, NVME_LOG_ANA_LSP_RGO_GROUPS_ONLY, rae, 0, + return nvme_get_log_ana(l, NVME_LOG_ANA_LSP_RGO_GROUPS_ONLY, rae, 0, len, log); } /** * nvme_get_ana_log_atomic() - Retrieve Asymmetric Namespace Access log page atomically - * @fd: File descriptor of nvme device + * @l: Link handle * @rgo: Whether to retrieve ANA groups only (no NSIDs) * @rae: Whether to retain asynchronous events * @retries: The maximum number of times to retry on log page changes @@ -1983,12 +1956,12 @@ static inline int nvme_get_log_ana_groups(int fd, bool rae, __u32 len, * because chgcnt changed during each of the retries attempts. * Sets errno = ENOSPC if the full log page does not fit in the provided buffer. */ -int nvme_get_ana_log_atomic(int fd, bool rgo, bool rae, unsigned int retries, +int nvme_get_ana_log_atomic(nvme_link_t l, bool rgo, bool rae, unsigned int retries, struct nvme_ana_log *log, __u32 *len); /** * nvme_get_log_lba_status() - Retrieve LBA Status - * @fd: File descriptor of nvme device + * @l: Link handle * @rae: Retain asynchronous events * @offset: Offset to the start of the log page * @len: The allocated length of the log page @@ -1997,7 +1970,7 @@ int nvme_get_ana_log_atomic(int fd, bool rgo, bool rae, unsigned int retries, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_get_log_lba_status(int fd, bool rae, +static inline int nvme_get_log_lba_status(nvme_link_t l, bool rae, __u64 offset, __u32 len, void *log) { struct nvme_get_log_args args = { @@ -2005,7 +1978,6 @@ static inline int nvme_get_log_lba_status(int fd, bool rae, .result = NULL, .log = log, .args_size = sizeof(args), - .fd = fd, .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, .lid = NVME_LOG_LID_LBA_STATUS, .len = len, @@ -2017,12 +1989,12 @@ static inline int nvme_get_log_lba_status(int fd, bool rae, .rae = rae, .ot = false, }; - return nvme_get_log_page(fd, NVME_LOG_PAGE_PDU_SIZE, &args); + return nvme_get_log_page(l, NVME_LOG_PAGE_PDU_SIZE, &args); } /** * nvme_get_log_endurance_grp_evt() - Retrieve Endurance Group Event Aggregate - * @fd: File descriptor of nvme device + * @l: Link handle * @rae: Retain asynchronous events * @offset: Offset to the start of the log page * @len: The allocated length of the log page @@ -2031,7 +2003,7 @@ static inline int nvme_get_log_lba_status(int fd, bool rae, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_get_log_endurance_grp_evt(int fd, bool rae, +static inline int nvme_get_log_endurance_grp_evt(nvme_link_t l, bool rae, __u32 offset, __u32 len, void *log) { struct nvme_get_log_args args = { @@ -2039,7 +2011,6 @@ static inline int nvme_get_log_endurance_grp_evt(int fd, bool rae, .result = NULL, .log = log, .args_size = sizeof(args), - .fd = fd, .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, .lid = NVME_LOG_LID_ENDURANCE_GRP_EVT, .len = len, @@ -2051,44 +2022,44 @@ static inline int nvme_get_log_endurance_grp_evt(int fd, bool rae, .rae = rae, .ot = false, }; - return nvme_get_log_page(fd, NVME_LOG_PAGE_PDU_SIZE, &args); + return nvme_get_log_page(l, NVME_LOG_PAGE_PDU_SIZE, &args); } /** * nvme_get_log_fid_supported_effects() - Retrieve Feature Identifiers Supported and Effects - * @fd: File descriptor of nvme device + * @l: Link handle * @rae: Retain asynchronous events * @log: FID Supported and Effects data structure * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise */ -static inline int nvme_get_log_fid_supported_effects(int fd, bool rae, +static inline int nvme_get_log_fid_supported_effects(nvme_link_t l, bool rae, struct nvme_fid_supported_effects_log *log) { - return nvme_get_nsid_log(fd, rae, NVME_LOG_LID_FID_SUPPORTED_EFFECTS, + return nvme_get_nsid_log(l, rae, NVME_LOG_LID_FID_SUPPORTED_EFFECTS, NVME_NSID_NONE, sizeof(*log), log); } /** * nvme_get_log_mi_cmd_supported_effects() - displays the MI Commands Supported by the controller - * @fd: File descriptor of nvme device + * @l: Link handle * @rae: Retain asynchronous events * @log: MI Command Supported and Effects data structure * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise */ -static inline int nvme_get_log_mi_cmd_supported_effects(int fd, bool rae, +static inline int nvme_get_log_mi_cmd_supported_effects(nvme_link_t l, bool rae, struct nvme_mi_cmd_supported_effects_log *log) { - return nvme_get_nsid_log(fd, rae, NVME_LOG_LID_MI_CMD_SUPPORTED_EFFECTS, + return nvme_get_nsid_log(l, rae, NVME_LOG_LID_MI_CMD_SUPPORTED_EFFECTS, NVME_NSID_NONE, sizeof(*log), log); } /** * nvme_get_log_boot_partition() - Retrieve Boot Partition - * @fd: File descriptor of nvme device + * @l: Link handle * @rae: Retain asynchronous events * @lsp: The log specified field of LID * @len: The allocated size, minimum @@ -2098,7 +2069,7 @@ static inline int nvme_get_log_mi_cmd_supported_effects(int fd, bool rae, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise */ -static inline int nvme_get_log_boot_partition(int fd, bool rae, +static inline int nvme_get_log_boot_partition(nvme_link_t l, bool rae, __u8 lsp, __u32 len, struct nvme_boot_partition *part) { struct nvme_get_log_args args = { @@ -2106,7 +2077,6 @@ static inline int nvme_get_log_boot_partition(int fd, bool rae, .result = NULL, .log = part, .args_size = sizeof(args), - .fd = fd, .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, .lid = NVME_LOG_LID_BOOT_PARTITION, .len = len, @@ -2118,12 +2088,12 @@ static inline int nvme_get_log_boot_partition(int fd, bool rae, .rae = rae, .ot = false, }; - return nvme_get_log_page(fd, NVME_LOG_PAGE_PDU_SIZE, &args); + return nvme_get_log_page(l, NVME_LOG_PAGE_PDU_SIZE, &args); } /** * nvme_get_log_rotational_media_info() - Retrieve Rotational Media Information Log - * @fd: File descriptor of nvme device + * @l: Link handle * @endgid: Endurance Group Identifier * @len: The allocated length of the log page * @log: User address to store the log page @@ -2131,16 +2101,16 @@ static inline int nvme_get_log_boot_partition(int fd, bool rae, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise */ -static inline int nvme_get_log_rotational_media_info(int fd, __u16 endgid, __u32 len, +static inline int nvme_get_log_rotational_media_info(nvme_link_t l, __u16 endgid, __u32 len, struct nvme_rotational_media_info_log *log) { - return nvme_get_endgid_log(fd, false, NVME_LOG_LID_ROTATIONAL_MEDIA_INFO, endgid, len, log); + return nvme_get_endgid_log(l, false, NVME_LOG_LID_ROTATIONAL_MEDIA_INFO, endgid, len, log); } /** * nvme_get_log_dispersed_ns_participating_nss() - Retrieve Dispersed Namespace Participating NVM * Subsystems Log - * @fd: File descriptor of nvme device + * @l: Link handle * @nsid: Namespace Identifier * @len: The allocated length of the log page * @log: User address to store the log page @@ -2148,31 +2118,31 @@ static inline int nvme_get_log_rotational_media_info(int fd, __u16 endgid, __u32 * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise */ -static inline int nvme_get_log_dispersed_ns_participating_nss(int fd, __u32 nsid, __u32 len, +static inline int nvme_get_log_dispersed_ns_participating_nss(nvme_link_t l, __u32 nsid, __u32 len, struct nvme_dispersed_ns_participating_nss_log *log) { - return nvme_get_nsid_log(fd, false, NVME_LOG_LID_DISPERSED_NS_PARTICIPATING_NSS, nsid, len, + return nvme_get_nsid_log(l, false, NVME_LOG_LID_DISPERSED_NS_PARTICIPATING_NSS, nsid, len, log); } /** * nvme_get_log_mgmt_addr_list() - Retrieve Management Address List Log - * @fd: File descriptor of nvme device + * @l: Link handle * @len: The allocated length of the log page * @log: User address to store the log page * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise */ -static inline int nvme_get_log_mgmt_addr_list(int fd, __u32 len, +static inline int nvme_get_log_mgmt_addr_list(nvme_link_t l, __u32 len, struct nvme_mgmt_addr_list_log *log) { - return nvme_get_log_simple(fd, NVME_LOG_LID_MGMT_ADDR_LIST, len, log); + return nvme_get_log_simple(l, NVME_LOG_LID_MGMT_ADDR_LIST, len, log); } /** * nvme_get_log_phy_rx_eom() - Retrieve Physical Interface Receiver Eye Opening Measurement Log - * @fd: File descriptor of nvme device + * @l: Link handle * @lsp: Log specific, controls action and measurement quality * @controller: Target controller ID * @len: The allocated size, minimum @@ -2182,7 +2152,7 @@ static inline int nvme_get_log_mgmt_addr_list(int fd, __u32 len, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise */ -static inline int nvme_get_log_phy_rx_eom(int fd, __u8 lsp, __u16 controller, +static inline int nvme_get_log_phy_rx_eom(nvme_link_t l, __u8 lsp, __u16 controller, __u32 len, struct nvme_phy_rx_eom_log *log) { struct nvme_get_log_args args = { @@ -2190,7 +2160,6 @@ static inline int nvme_get_log_phy_rx_eom(int fd, __u8 lsp, __u16 controller, .result = NULL, .log = log, .args_size = sizeof(args), - .fd = fd, .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, .lid = NVME_LOG_LID_PHY_RX_EOM, .len = len, @@ -2202,12 +2171,12 @@ static inline int nvme_get_log_phy_rx_eom(int fd, __u8 lsp, __u16 controller, .rae = false, .ot = false, }; - return nvme_get_log_page(fd, NVME_LOG_PAGE_PDU_SIZE, &args); + return nvme_get_log_page(l, NVME_LOG_PAGE_PDU_SIZE, &args); } /** * nvme_get_log_reachability_groups() - Retrieve Reachability Groups Log - * @fd: File descriptor of nvme device + * @l: Link handle * @rgo: Return groups only * @rae: Retain asynchronous events * @len: The allocated length of the log page @@ -2216,7 +2185,7 @@ static inline int nvme_get_log_phy_rx_eom(int fd, __u8 lsp, __u16 controller, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise */ -static inline int nvme_get_log_reachability_groups(int fd, bool rgo, bool rae, __u32 len, +static inline int nvme_get_log_reachability_groups(nvme_link_t l, bool rgo, bool rae, __u32 len, struct nvme_reachability_groups_log *log) { struct nvme_get_log_args args = { @@ -2224,7 +2193,6 @@ static inline int nvme_get_log_reachability_groups(int fd, bool rgo, bool rae, _ .result = NULL, .log = log, .args_size = sizeof(args), - .fd = fd, .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, .lid = NVME_LOG_LID_REACHABILITY_GROUPS, .len = len, @@ -2237,12 +2205,12 @@ static inline int nvme_get_log_reachability_groups(int fd, bool rgo, bool rae, _ .ot = false, }; - return nvme_get_log_page(fd, NVME_LOG_PAGE_PDU_SIZE, &args); + return nvme_get_log_page(l, NVME_LOG_PAGE_PDU_SIZE, &args); } /** * nvme_get_log_reachability_associations() - Retrieve Reachability Associations Log - * @fd: File descriptor of nvme device + * @l: Link handle * @rao: Return associations only * @rae: Retain asynchronous events * @len: The allocated length of the log page @@ -2251,7 +2219,7 @@ static inline int nvme_get_log_reachability_groups(int fd, bool rgo, bool rae, _ * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise */ -static inline int nvme_get_log_reachability_associations(int fd, bool rao, bool rae, __u32 len, +static inline int nvme_get_log_reachability_associations(nvme_link_t l, bool rao, bool rae, __u32 len, struct nvme_reachability_associations_log *log) { struct nvme_get_log_args args = { @@ -2259,7 +2227,6 @@ static inline int nvme_get_log_reachability_associations(int fd, bool rao, bool .result = NULL, .log = log, .args_size = sizeof(args), - .fd = fd, .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, .lid = NVME_LOG_LID_REACHABILITY_ASSOCIATIONS, .len = len, @@ -2272,12 +2239,12 @@ static inline int nvme_get_log_reachability_associations(int fd, bool rao, bool .ot = false, }; - return nvme_get_log_page(fd, NVME_LOG_PAGE_PDU_SIZE, &args); + return nvme_get_log_page(l, NVME_LOG_PAGE_PDU_SIZE, &args); } /** * nvme_get_log_changed_alloc_ns_list() - Retrieve Changed Allocated Namespace List Log - * @fd: File descriptor of nvme device + * @l: Link handle * @rae: Retain asynchronous events * @len: The allocated length of the log page * @log: User address to store the log page @@ -2285,16 +2252,16 @@ static inline int nvme_get_log_reachability_associations(int fd, bool rao, bool * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise */ -static inline int nvme_get_log_changed_alloc_ns_list(int fd, bool rae, __u32 len, +static inline int nvme_get_log_changed_alloc_ns_list(nvme_link_t l, bool rae, __u32 len, struct nvme_ns_list *log) { - return nvme_get_nsid_log(fd, rae, NVME_LOG_LID_CHANGED_ALLOC_NS_LIST, NVME_NSID_ALL, len, + return nvme_get_nsid_log(l, rae, NVME_LOG_LID_CHANGED_ALLOC_NS_LIST, NVME_NSID_ALL, len, log); } /** * nvme_get_log_discovery() - Retrieve Discovery log page - * @fd: File descriptor of nvme device + * @l: Link handle * @rae: Retain asynchronous events * @offset: Offset of this log to retrieve * @len: The allocated size for this portion of the log @@ -2306,7 +2273,7 @@ static inline int nvme_get_log_changed_alloc_ns_list(int fd, bool rae, __u32 len * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_get_log_discovery(int fd, bool rae, +static inline int nvme_get_log_discovery(nvme_link_t l, bool rae, __u32 offset, __u32 len, void *log) { struct nvme_get_log_args args = { @@ -2314,7 +2281,6 @@ static inline int nvme_get_log_discovery(int fd, bool rae, .result = NULL, .log = log, .args_size = sizeof(args), - .fd = fd, .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, .lid = NVME_LOG_LID_DISCOVER, .len = len, @@ -2326,12 +2292,12 @@ static inline int nvme_get_log_discovery(int fd, bool rae, .rae = rae, .ot = false, }; - return nvme_get_log_page(fd, NVME_LOG_PAGE_PDU_SIZE, &args); + return nvme_get_log_page(l, NVME_LOG_PAGE_PDU_SIZE, &args); } /** * nvme_get_log_host_discover() - Retrieve Host Discovery Log - * @fd: File descriptor of nvme device + * @l: Link handle * @allhoste: All host entries * @rae: Retain asynchronous events * @len: The allocated length of the log page @@ -2340,7 +2306,7 @@ static inline int nvme_get_log_discovery(int fd, bool rae, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise */ -static inline int nvme_get_log_host_discover(int fd, bool allhoste, bool rae, __u32 len, +static inline int nvme_get_log_host_discover(nvme_link_t l, bool allhoste, bool rae, __u32 len, struct nvme_host_discover_log *log) { struct nvme_get_log_args args = { @@ -2348,7 +2314,6 @@ static inline int nvme_get_log_host_discover(int fd, bool allhoste, bool rae, __ .result = NULL, .log = log, .args_size = sizeof(args), - .fd = fd, .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, .lid = NVME_LOG_LID_HOST_DISCOVER, .len = len, @@ -2361,12 +2326,12 @@ static inline int nvme_get_log_host_discover(int fd, bool allhoste, bool rae, __ .ot = false, }; - return nvme_get_log_page(fd, NVME_LOG_PAGE_PDU_SIZE, &args); + return nvme_get_log_page(l, NVME_LOG_PAGE_PDU_SIZE, &args); } /** * nvme_get_log_ave_discover() - Retrieve AVE Discovery Log - * @fd: File descriptor of nvme device + * @l: Link handle * @rae: Retain asynchronous events * @len: The allocated length of the log page * @log: User address to store the log page @@ -2374,15 +2339,15 @@ static inline int nvme_get_log_host_discover(int fd, bool allhoste, bool rae, __ * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise */ -static inline int nvme_get_log_ave_discover(int fd, bool rae, __u32 len, +static inline int nvme_get_log_ave_discover(nvme_link_t l, bool rae, __u32 len, struct nvme_ave_discover_log *log) { - return nvme_get_nsid_log(fd, rae, NVME_LOG_LID_AVE_DISCOVER, NVME_NSID_ALL, len, log); + return nvme_get_nsid_log(l, rae, NVME_LOG_LID_AVE_DISCOVER, NVME_NSID_ALL, len, log); } /** * nvme_get_log_pull_model_ddc_req() - Retrieve Pull Model DDC Request Log - * @fd: File descriptor of nvme device + * @l: Link handle * @rae: Retain asynchronous events * @len: The allocated length of the log page * @log: User address to store the log page @@ -2390,22 +2355,22 @@ static inline int nvme_get_log_ave_discover(int fd, bool rae, __u32 len, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise */ -static inline int nvme_get_log_pull_model_ddc_req(int fd, bool rae, __u32 len, +static inline int nvme_get_log_pull_model_ddc_req(nvme_link_t l, bool rae, __u32 len, struct nvme_pull_model_ddc_req_log *log) { - return nvme_get_nsid_log(fd, rae, NVME_LOG_LID_PULL_MODEL_DDC_REQ, NVME_NSID_ALL, len, log); + return nvme_get_nsid_log(l, rae, NVME_LOG_LID_PULL_MODEL_DDC_REQ, NVME_NSID_ALL, len, log); } /** * nvme_get_log_media_unit_stat() - Retrieve Media Unit Status - * @fd: File descriptor of nvme device + * @l: Link handle * @domid: Domain Identifier selection, if supported * @mus: User address to store the Media Unit statistics log * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise */ -static inline int nvme_get_log_media_unit_stat(int fd, __u16 domid, +static inline int nvme_get_log_media_unit_stat(nvme_link_t l, __u16 domid, struct nvme_media_unit_stat_log *mus) { struct nvme_get_log_args args = { @@ -2413,7 +2378,6 @@ static inline int nvme_get_log_media_unit_stat(int fd, __u16 domid, .result = NULL, .log = mus, .args_size = sizeof(args), - .fd = fd, .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, .lid = NVME_LOG_LID_MEDIA_UNIT_STATUS, .len = sizeof(*mus), @@ -2425,19 +2389,19 @@ static inline int nvme_get_log_media_unit_stat(int fd, __u16 domid, .rae = false, .ot = false, }; - return nvme_get_log_page(fd, NVME_LOG_PAGE_PDU_SIZE, &args); + return nvme_get_log_page(l, NVME_LOG_PAGE_PDU_SIZE, &args); } /** * nvme_get_log_support_cap_config_list() - Retrieve Supported Capacity Configuration List - * @fd: File descriptor of nvme device + * @l: Link handle * @domid: Domain Identifier selection, if supported * @cap: User address to store supported capabilities config list * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise */ -static inline int nvme_get_log_support_cap_config_list(int fd, __u16 domid, +static inline int nvme_get_log_support_cap_config_list(nvme_link_t l, __u16 domid, struct nvme_supported_cap_config_list_log *cap) { struct nvme_get_log_args args = { @@ -2445,7 +2409,6 @@ static inline int nvme_get_log_support_cap_config_list(int fd, __u16 domid, .result = NULL, .log = cap, .args_size = sizeof(args), - .fd = fd, .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, .lid = NVME_LOG_LID_SUPPORTED_CAP_CONFIG_LIST, .len = sizeof(*cap), @@ -2457,28 +2420,28 @@ static inline int nvme_get_log_support_cap_config_list(int fd, __u16 domid, .rae = false, .ot = false, }; - return nvme_get_log_page(fd, NVME_LOG_PAGE_PDU_SIZE, &args); + return nvme_get_log_page(l, NVME_LOG_PAGE_PDU_SIZE, &args); } /** * nvme_get_log_reservation() - Retrieve Reservation Notification - * @fd: File descriptor of nvme device + * @l: Link handle * @rae: Retain asynchronous events * @log: User address to store the reservation log * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise */ -static inline int nvme_get_log_reservation(int fd, bool rae, +static inline int nvme_get_log_reservation(nvme_link_t l, bool rae, struct nvme_resv_notification_log *log) { - return nvme_get_nsid_log(fd, rae, NVME_LOG_LID_RESERVATION, + return nvme_get_nsid_log(l, rae, NVME_LOG_LID_RESERVATION, NVME_NSID_ALL, sizeof(*log), log); } /** * nvme_get_log_sanitize() - Retrieve Sanitize Status - * @fd: File descriptor of nvme device + * @l: Link handle * @rae: Retain asynchronous events * @log: User address to store the sanitize log * @@ -2488,16 +2451,16 @@ static inline int nvme_get_log_reservation(int fd, bool rae, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_get_log_sanitize(int fd, bool rae, +static inline int nvme_get_log_sanitize(nvme_link_t l, bool rae, struct nvme_sanitize_log_page *log) { - return nvme_get_nsid_log(fd, rae, NVME_LOG_LID_SANITIZE, + return nvme_get_nsid_log(l, rae, NVME_LOG_LID_SANITIZE, NVME_NSID_ALL, sizeof(*log), log); } /** * nvme_get_log_zns_changed_zones() - Retrieve list of zones that have changed - * @fd: File descriptor of nvme device + * @l: Link handle * @nsid: Namespace ID * @rae: Retain asynchronous events * @log: User address to store the changed zone log @@ -2507,7 +2470,7 @@ static inline int nvme_get_log_sanitize(int fd, bool rae, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_get_log_zns_changed_zones(int fd, __u32 nsid, bool rae, +static inline int nvme_get_log_zns_changed_zones(nvme_link_t l, __u32 nsid, bool rae, struct nvme_zns_changed_zone_log *log) { struct nvme_get_log_args args = { @@ -2515,7 +2478,6 @@ static inline int nvme_get_log_zns_changed_zones(int fd, __u32 nsid, bool rae, .result = NULL, .log = log, .args_size = sizeof(args), - .fd = fd, .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, .lid = NVME_LOG_LID_ZNS_CHANGED_ZONES, .len = sizeof(*log), @@ -2527,12 +2489,12 @@ static inline int nvme_get_log_zns_changed_zones(int fd, __u32 nsid, bool rae, .rae = rae, .ot = false, }; - return nvme_get_log_page(fd, NVME_LOG_PAGE_PDU_SIZE, &args); + return nvme_get_log_page(l, NVME_LOG_PAGE_PDU_SIZE, &args); } /** * nvme_get_log_persistent_event() - Retrieve Persistent Event Log - * @fd: File descriptor of nvme device + * @l: Link handle * @action: Action the controller should take during processing this command * @size: Size of @pevent_log * @pevent_log: User address to store the persistent event log @@ -2540,7 +2502,7 @@ static inline int nvme_get_log_zns_changed_zones(int fd, __u32 nsid, bool rae, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_get_log_persistent_event(int fd, +static inline int nvme_get_log_persistent_event(nvme_link_t l, enum nvme_pevent_log_action action, __u32 size, void *pevent_log) { @@ -2549,7 +2511,6 @@ static inline int nvme_get_log_persistent_event(int fd, .result = NULL, .log = pevent_log, .args_size = sizeof(args), - .fd = fd, .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, .lid = NVME_LOG_LID_PERSISTENT_EVENT, .len = size, @@ -2561,19 +2522,19 @@ static inline int nvme_get_log_persistent_event(int fd, .rae = false, .ot = false, }; - return nvme_get_log_page(fd, NVME_LOG_PAGE_PDU_SIZE, &args); + return nvme_get_log_page(l, NVME_LOG_PAGE_PDU_SIZE, &args); } /** * nvme_get_log_lockdown() - Retrieve lockdown Log - * @fd: File descriptor of nvme device + * @l: Link handle * @cnscp: Contents and Scope of Command and Feature Identifier Lists * @lockdown_log: Buffer to store the lockdown log * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_get_log_lockdown(int fd, +static inline int nvme_get_log_lockdown(nvme_link_t l, __u8 cnscp, struct nvme_lockdown_log *lockdown_log) { struct nvme_get_log_args args = { @@ -2581,7 +2542,6 @@ static inline int nvme_get_log_lockdown(int fd, .result = NULL, .log = lockdown_log, .args_size = sizeof(args), - .fd = fd, .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, .lid = NVME_LOG_LID_CMD_AND_FEAT_LOCKDOWN, .len = sizeof(*lockdown_log), @@ -2593,21 +2553,22 @@ static inline int nvme_get_log_lockdown(int fd, .rae = false, .ot = false, }; - return nvme_get_log_page(fd, NVME_LOG_PAGE_PDU_SIZE, &args); + return nvme_get_log_page(l, NVME_LOG_PAGE_PDU_SIZE, &args); } /** * nvme_set_features() - Set a feature attribute + * @l: Link handle * @args: &struct nvme_set_features_args argument structure * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_set_features(struct nvme_set_features_args *args); +int nvme_set_features(nvme_link_t l, struct nvme_set_features_args *args); /** * nvme_set_features_data() - Helper function for @nvme_set_features() - * @fd: File descriptor of nvme device + * @l: Link handle * @fid: Feature identifier * @nsid: Namespace ID, if applicable * @cdw11: Value to set the feature to @@ -2619,7 +2580,7 @@ int nvme_set_features(struct nvme_set_features_args *args); * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_set_features_data(int fd, __u8 fid, __u32 nsid, +static inline int nvme_set_features_data(nvme_link_t l, __u8 fid, __u32 nsid, __u32 cdw11, bool save, __u32 data_len, void *data, __u32 *result) { @@ -2627,7 +2588,6 @@ static inline int nvme_set_features_data(int fd, __u8 fid, __u32 nsid, .result = result, .data = data, .args_size = sizeof(args), - .fd = fd, .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, .nsid = nsid, .cdw11 = cdw11, @@ -2639,12 +2599,12 @@ static inline int nvme_set_features_data(int fd, __u8 fid, __u32 nsid, .uuidx = NVME_UUID_NONE, .fid = fid, }; - return nvme_set_features(&args); + return nvme_set_features(l, &args); } /** * nvme_set_features_simple() - Helper function for @nvme_set_features() - * @fd: File descriptor of nvme device + * @l: Link handle * @fid: Feature identifier * @nsid: Namespace ID, if applicable * @cdw11: Value to set the feature to @@ -2654,16 +2614,16 @@ static inline int nvme_set_features_data(int fd, __u8 fid, __u32 nsid, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_set_features_simple(int fd, __u8 fid, __u32 nsid, +static inline int nvme_set_features_simple(nvme_link_t l, __u8 fid, __u32 nsid, __u32 cdw11, bool save, __u32 *result) { - return nvme_set_features_data(fd, fid, nsid, cdw11, save, 0, NULL, + return nvme_set_features_data(l, fid, nsid, cdw11, save, 0, NULL, result); } /** * nvme_set_features_arbitration() - Set arbitration features - * @fd: File descriptor of nvme device + * @l: Link handle * @ab: Arbitration Burst * @lpw: Low Priority Weight * @mpw: Medium Priority Weight @@ -2674,12 +2634,12 @@ static inline int nvme_set_features_simple(int fd, __u8 fid, __u32 nsid, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_set_features_arbitration(int fd, __u8 ab, __u8 lpw, __u8 mpw, +int nvme_set_features_arbitration(nvme_link_t l, __u8 ab, __u8 lpw, __u8 mpw, __u8 hpw, bool save, __u32 *result); /** * nvme_set_features_power_mgmt() - Set power management feature - * @fd: File descriptor of nvme device + * @l: Link handle * @ps: Power State * @wh: Workload Hint * @save: Save value across power states @@ -2688,12 +2648,12 @@ int nvme_set_features_arbitration(int fd, __u8 ab, __u8 lpw, __u8 mpw, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_set_features_power_mgmt(int fd, __u8 ps, __u8 wh, bool save, +int nvme_set_features_power_mgmt(nvme_link_t l, __u8 ps, __u8 wh, bool save, __u32 *result); /** * nvme_set_features_lba_range() - Set LBA range feature - * @fd: File descriptor of nvme device + * @l: Link handle * @nsid: Namespace ID * @nr_ranges: Number of ranges in @data * @save: Save value across power states @@ -2703,12 +2663,12 @@ int nvme_set_features_power_mgmt(int fd, __u8 ps, __u8 wh, bool save, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_set_features_lba_range(int fd, __u32 nsid, __u8 nr_ranges, bool save, +int nvme_set_features_lba_range(nvme_link_t l, __u32 nsid, __u8 nr_ranges, bool save, struct nvme_lba_range_type *data, __u32 *result); /** * nvme_set_features_temp_thresh() - Set temperature threshold feature - * @fd: File descriptor of nvme device + * @l: Link handle * @tmpth: Temperature Threshold * @tmpsel: Threshold Temperature Select * @thsel: Threshold Type Select @@ -2719,13 +2679,13 @@ int nvme_set_features_lba_range(int fd, __u32 nsid, __u8 nr_ranges, bool save, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_set_features_temp_thresh(int fd, __u16 tmpth, __u8 tmpsel, +int nvme_set_features_temp_thresh(nvme_link_t l, __u16 tmpth, __u8 tmpsel, enum nvme_feat_tmpthresh_thsel thsel, __u8 tmpthh, bool save, __u32 *result); /** * nvme_set_features_err_recovery() - Set error recovery feature - * @fd: File descriptor of nvme device + * @l: Link handle * @nsid: Namespace ID * @tler: Time-limited error recovery value * @dulbe: Deallocated or Unwritten Logical Block Error Enable @@ -2735,12 +2695,12 @@ int nvme_set_features_temp_thresh(int fd, __u16 tmpth, __u8 tmpsel, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_set_features_err_recovery(int fd, __u32 nsid, __u16 tler, +int nvme_set_features_err_recovery(nvme_link_t l, __u32 nsid, __u16 tler, bool dulbe, bool save, __u32 *result); /** * nvme_set_features_volatile_wc() - Set volatile write cache feature - * @fd: File descriptor of nvme device + * @l: Link handle * @wce: Write cache enable * @save: Save value across power states * @result: The command completion result from CQE dword0 @@ -2748,12 +2708,12 @@ int nvme_set_features_err_recovery(int fd, __u32 nsid, __u16 tler, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_set_features_volatile_wc(int fd, bool wce, bool save, +int nvme_set_features_volatile_wc(nvme_link_t l, bool wce, bool save, __u32 *result); /** * nvme_set_features_irq_coalesce() - Set IRQ coalesce feature - * @fd: File descriptor of nvme device + * @l: Link handle * @thr: Aggregation Threshold * @time: Aggregation Time * @save: Save value across power states @@ -2762,12 +2722,12 @@ int nvme_set_features_volatile_wc(int fd, bool wce, bool save, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_set_features_irq_coalesce(int fd, __u8 thr, __u8 time, +int nvme_set_features_irq_coalesce(nvme_link_t l, __u8 thr, __u8 time, bool save, __u32 *result); /** * nvme_set_features_irq_config() - Set IRQ config feature - * @fd: File descriptor of nvme device + * @l: Link handle * @iv: Interrupt Vector * @cd: Coalescing Disable * @save: Save value across power states @@ -2776,12 +2736,12 @@ int nvme_set_features_irq_coalesce(int fd, __u8 thr, __u8 time, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_set_features_irq_config(int fd, __u16 iv, bool cd, bool save, +int nvme_set_features_irq_config(nvme_link_t l, __u16 iv, bool cd, bool save, __u32 *result); /** * nvme_set_features_write_atomic() - Set write atomic feature - * @fd: File descriptor of nvme device + * @l: Link handle * @dn: Disable Normal * @save: Save value across power states * @result: The command completion result from CQE dword0 @@ -2789,12 +2749,12 @@ int nvme_set_features_irq_config(int fd, __u16 iv, bool cd, bool save, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_set_features_write_atomic(int fd, bool dn, bool save, +int nvme_set_features_write_atomic(nvme_link_t l, bool dn, bool save, __u32 *result); /** * nvme_set_features_async_event() - Set asynchronous event feature - * @fd: File descriptor of nvme device + * @l: Link handle * @events: Events to enable * @save: Save value across power states * @result: The command completion result from CQE dword0 @@ -2802,12 +2762,12 @@ int nvme_set_features_write_atomic(int fd, bool dn, bool save, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_set_features_async_event(int fd, __u32 events, bool save, +int nvme_set_features_async_event(nvme_link_t l, __u32 events, bool save, __u32 *result); /** * nvme_set_features_auto_pst() - Set autonomous power state feature - * @fd: File descriptor of nvme device + * @l: Link handle * @apste: Autonomous Power State Transition Enable * @apst: Autonomous Power State Transition * @save: Save value across power states @@ -2816,24 +2776,24 @@ int nvme_set_features_async_event(int fd, __u32 events, bool save, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_set_features_auto_pst(int fd, bool apste, bool save, +int nvme_set_features_auto_pst(nvme_link_t l, bool apste, bool save, struct nvme_feat_auto_pst *apst, __u32 *result); /** * nvme_set_features_timestamp() - Set timestamp feature - * @fd: File descriptor of nvme device + * @l: Link handle * @save: Save value across power states * @timestamp: The current timestamp value to assign to this feature * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_set_features_timestamp(int fd, bool save, __u64 timestamp); +int nvme_set_features_timestamp(nvme_link_t l, bool save, __u64 timestamp); /** * nvme_set_features_hctm() - Set thermal management feature - * @fd: File descriptor of nvme device + * @l: Link handle * @tmt2: Thermal Management Temperature 2 * @tmt1: Thermal Management Temperature 1 * @save: Save value across power states @@ -2842,12 +2802,12 @@ int nvme_set_features_timestamp(int fd, bool save, __u64 timestamp); * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_set_features_hctm(int fd, __u16 tmt2, __u16 tmt1, bool save, +int nvme_set_features_hctm(nvme_link_t l, __u16 tmt2, __u16 tmt1, bool save, __u32 *result); /** * nvme_set_features_nopsc() - Set non-operational power state feature - * @fd: File descriptor of nvme device + * @l: Link handle * @noppme: Non-Operational Power State Permissive Mode Enable * @save: Save value across power states * @result: The command completion result from CQE dword0 @@ -2855,11 +2815,11 @@ int nvme_set_features_hctm(int fd, __u16 tmt2, __u16 tmt1, bool save, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_set_features_nopsc(int fd, bool noppme, bool save, __u32 *result); +int nvme_set_features_nopsc(nvme_link_t l, bool noppme, bool save, __u32 *result); /** * nvme_set_features_rrl() - Set read recovery level feature - * @fd: File descriptor of nvme device + * @l: Link handle * @rrl: Read recovery level setting * @nvmsetid: NVM set id * @save: Save value across power states @@ -2868,12 +2828,12 @@ int nvme_set_features_nopsc(int fd, bool noppme, bool save, __u32 *result); * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_set_features_rrl(int fd, __u8 rrl, __u16 nvmsetid, bool save, +int nvme_set_features_rrl(nvme_link_t l, __u8 rrl, __u16 nvmsetid, bool save, __u32 *result); /** * nvme_set_features_plm_config() - Set predictable latency feature - * @fd: File descriptor of nvme device + * @l: Link handle * @enable: Predictable Latency Enable * @nvmsetid: NVM Set Identifier * @save: Save value across power states @@ -2883,13 +2843,13 @@ int nvme_set_features_rrl(int fd, __u8 rrl, __u16 nvmsetid, bool save, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_set_features_plm_config(int fd, bool enable, __u16 nvmsetid, +int nvme_set_features_plm_config(nvme_link_t l, bool enable, __u16 nvmsetid, bool save, struct nvme_plm_config *data, __u32 *result); /** * nvme_set_features_plm_window() - Set window select feature - * @fd: File descriptor of nvme device + * @l: Link handle * @sel: Window Select * @nvmsetid: NVM Set Identifier * @save: Save value across power states @@ -2898,12 +2858,12 @@ int nvme_set_features_plm_config(int fd, bool enable, __u16 nvmsetid, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_set_features_plm_window(int fd, enum nvme_feat_plm_window_select sel, +int nvme_set_features_plm_window(nvme_link_t l, enum nvme_feat_plm_window_select sel, __u16 nvmsetid, bool save, __u32 *result); /** * nvme_set_features_lba_sts_interval() - Set LBA status information feature - * @fd: File descriptor of nvme device + * @l: Link handle * @save: Save value across power states * @lsiri: LBA Status Information Report Interval * @lsipi: LBA Status Information Poll Interval @@ -2912,24 +2872,24 @@ int nvme_set_features_plm_window(int fd, enum nvme_feat_plm_window_select sel, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_set_features_lba_sts_interval(int fd, __u16 lsiri, __u16 lsipi, +int nvme_set_features_lba_sts_interval(nvme_link_t l, __u16 lsiri, __u16 lsipi, bool save, __u32 *result); /** * nvme_set_features_host_behavior() - Set host behavior feature - * @fd: File descriptor of nvme device + * @l: Link handle * @save: Save value across power states * @data: Pointer to structure nvme_feat_host_behavior * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_set_features_host_behavior(int fd, bool save, +int nvme_set_features_host_behavior(nvme_link_t l, bool save, struct nvme_feat_host_behavior *data); /** * nvme_set_features_sanitize() - Set sanitize feature - * @fd: File descriptor of nvme device + * @l: Link handle * @nodrm: No-Deallocate Response Mode * @save: Save value across power states * @result: The command completion result from CQE dword0 @@ -2937,11 +2897,11 @@ int nvme_set_features_host_behavior(int fd, bool save, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_set_features_sanitize(int fd, bool nodrm, bool save, __u32 *result); +int nvme_set_features_sanitize(nvme_link_t l, bool nodrm, bool save, __u32 *result); /** * nvme_set_features_endurance_evt_cfg() - Set endurance event config feature - * @fd: File descriptor of nvme device + * @l: Link handle * @endgid: Endurance Group Identifier * @egwarn: Flags to enable warning, see &enum nvme_eg_critical_warning_flags * @save: Save value across power states @@ -2950,12 +2910,12 @@ int nvme_set_features_sanitize(int fd, bool nodrm, bool save, __u32 *result); * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_set_features_endurance_evt_cfg(int fd, __u16 endgid, __u8 egwarn, +int nvme_set_features_endurance_evt_cfg(nvme_link_t l, __u16 endgid, __u8 egwarn, bool save, __u32 *result); /** * nvme_set_features_sw_progress() - Set pre-boot software load count feature - * @fd: File descriptor of nvme device + * @l: Link handle * @pbslc: Pre-boot Software Load Count * @save: Save value across power states * @result: The command completion result from CQE dword0 @@ -2963,12 +2923,12 @@ int nvme_set_features_endurance_evt_cfg(int fd, __u16 endgid, __u8 egwarn, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_set_features_sw_progress(int fd, __u8 pbslc, bool save, +int nvme_set_features_sw_progress(nvme_link_t l, __u8 pbslc, bool save, __u32 *result); /** * nvme_set_features_host_id() - Set enable extended host identifiers feature - * @fd: File descriptor of nvme device + * @l: Link handle * @exhid: Enable Extended Host Identifier * @save: Save value across power states * @hostid: Host ID to set @@ -2976,11 +2936,11 @@ int nvme_set_features_sw_progress(int fd, __u8 pbslc, bool save, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_set_features_host_id(int fd, bool exhid, bool save, __u8 *hostid); +int nvme_set_features_host_id(nvme_link_t l, bool exhid, bool save, __u8 *hostid); /** * nvme_set_features_resv_mask() - Set reservation notification mask feature - * @fd: File descriptor of nvme device + * @l: Link handle * @nsid: Namespace ID * @mask: Reservation Notification Mask Field * @save: Save value across power states @@ -2989,12 +2949,12 @@ int nvme_set_features_host_id(int fd, bool exhid, bool save, __u8 *hostid); * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_set_features_resv_mask(int fd, __u32 nsid, __u32 mask, bool save, +int nvme_set_features_resv_mask(nvme_link_t l, __u32 nsid, __u32 mask, bool save, __u32 *result); /** * nvme_set_features_resv_persist() - Set persist through power loss feature - * @fd: File descriptor of nvme device + * @l: Link handle * @nsid: Namespace ID * @ptpl: Persist Through Power Loss * @save: Save value across power states @@ -3003,12 +2963,12 @@ int nvme_set_features_resv_mask(int fd, __u32 nsid, __u32 mask, bool save, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_set_features_resv_persist(int fd, __u32 nsid, bool ptpl, bool save, +int nvme_set_features_resv_persist(nvme_link_t l, __u32 nsid, bool ptpl, bool save, __u32 *result); /** * nvme_set_features_write_protect() - Set write protect feature - * @fd: File descriptor of nvme device + * @l: Link handle * @nsid: Namespace ID * @state: Write Protection State * @save: Save value across power states @@ -3017,33 +2977,34 @@ int nvme_set_features_resv_persist(int fd, __u32 nsid, bool ptpl, bool save, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_set_features_write_protect(int fd, __u32 nsid, +int nvme_set_features_write_protect(nvme_link_t l, __u32 nsid, enum nvme_feat_nswpcfg_state state, bool save, __u32 *result); /** * nvme_set_features_iocs_profile() - Set I/O command set profile feature - * @fd: File descriptor of nvme device + * @l: Link handle * @iocsi: I/O Command Set Combination Index * @save: Save value across power states * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_set_features_iocs_profile(int fd, __u16 iocsi, bool save); +int nvme_set_features_iocs_profile(nvme_link_t l, __u16 iocsi, bool save); /** * nvme_get_features() - Retrieve a feature attribute + * @l: Link handle * @args: &struct nvme_get_features_args argument structure * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_get_features(struct nvme_get_features_args *args); +int nvme_get_features(nvme_link_t l, struct nvme_get_features_args *args); /** * nvme_get_features_data() - Helper function for @nvme_get_features() - * @fd: File descriptor of nvme device + * @l: Link handle * @fid: Feature identifier * @nsid: Namespace ID, if applicable * @data_len: Length of feature data, if applicable, in bytes @@ -3053,14 +3014,13 @@ int nvme_get_features(struct nvme_get_features_args *args); * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_get_features_data(int fd, enum nvme_features_id fid, +static inline int nvme_get_features_data(nvme_link_t l, enum nvme_features_id fid, __u32 nsid, __u32 data_len, void *data, __u32 *result) { struct nvme_get_features_args args = { .result = result, .data = data, .args_size = sizeof(args), - .fd = fd, .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, .nsid = nsid, .sel = NVME_GET_FEATURES_SEL_CURRENT, @@ -3070,12 +3030,12 @@ static inline int nvme_get_features_data(int fd, enum nvme_features_id fid, .uuidx = NVME_UUID_NONE, }; - return nvme_get_features(&args); + return nvme_get_features(l, &args); } /** * nvme_get_features_simple() - Helper function for @nvme_get_features() - * @fd: File descriptor of nvme device + * @l: Link handle * @fid: Feature identifier * @nsid: Namespace ID, if applicable * @result: The command completion result from CQE dword0 @@ -3083,39 +3043,39 @@ static inline int nvme_get_features_data(int fd, enum nvme_features_id fid, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_get_features_simple(int fd, enum nvme_features_id fid, +static inline int nvme_get_features_simple(nvme_link_t l, enum nvme_features_id fid, __u32 nsid, __u32 *result) { - return nvme_get_features_data(fd, fid, nsid, 0, NULL, result); + return nvme_get_features_data(l, fid, nsid, 0, NULL, result); } /** * nvme_get_features_arbitration() - Get arbitration feature - * @fd: File descriptor of nvme device + * @l: Link handle * @sel: Select which type of attribute to return, see &enum nvme_get_features_sel * @result: The command completion result from CQE dword0 * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_get_features_arbitration(int fd, enum nvme_get_features_sel sel, +int nvme_get_features_arbitration(nvme_link_t l, enum nvme_get_features_sel sel, __u32 *result); /** * nvme_get_features_power_mgmt() - Get power management feature - * @fd: File descriptor of nvme device + * @l: Link handle * @sel: Select which type of attribute to return, see &enum nvme_get_features_sel * @result: The command completion result from CQE dword0 * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_get_features_power_mgmt(int fd, enum nvme_get_features_sel sel, +int nvme_get_features_power_mgmt(nvme_link_t l, enum nvme_get_features_sel sel, __u32 *result); /** * nvme_get_features_lba_range() - Get LBA range feature - * @fd: File descriptor of nvme device + * @l: Link handle * @sel: Select which type of attribute to return, see &enum nvme_get_features_sel * @nsid: Namespace ID * @data: Buffer to receive LBA Range Type data structure @@ -3124,13 +3084,13 @@ int nvme_get_features_power_mgmt(int fd, enum nvme_get_features_sel sel, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_get_features_lba_range(int fd, enum nvme_get_features_sel sel, +int nvme_get_features_lba_range(nvme_link_t l, enum nvme_get_features_sel sel, __u32 nsid, struct nvme_lba_range_type *data, __u32 *result); /** * nvme_get_features_temp_thresh() - Get temperature threshold feature - * @fd: File descriptor of nvme device + * @l: Link handle * @sel: Select which type of attribute to return, see &enum nvme_get_features_sel * @tmpsel: Threshold Temperature Select * @thsel: Threshold Type Select @@ -3139,13 +3099,13 @@ int nvme_get_features_lba_range(int fd, enum nvme_get_features_sel sel, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_get_features_temp_thresh(int fd, enum nvme_get_features_sel sel, __u8 tmpsel, +int nvme_get_features_temp_thresh(nvme_link_t l, enum nvme_get_features_sel sel, __u8 tmpsel, enum nvme_feat_tmpthresh_thsel thsel, __u32 *result); /** * nvme_get_features_err_recovery() - Get error recovery feature - * @fd: File descriptor of nvme device + * @l: Link handle * @sel: Select which type of attribute to return, see &enum nvme_get_features_sel * @nsid: Namespace ID * @result: The command completion result from CQE dword0 @@ -3153,48 +3113,48 @@ int nvme_get_features_temp_thresh(int fd, enum nvme_get_features_sel sel, __u8 t * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_get_features_err_recovery(int fd, enum nvme_get_features_sel sel, +int nvme_get_features_err_recovery(nvme_link_t l, enum nvme_get_features_sel sel, __u32 nsid, __u32 *result); /** * nvme_get_features_volatile_wc() - Get volatile write cache feature - * @fd: File descriptor of nvme device + * @l: Link handle * @sel: Select which type of attribute to return, see &enum nvme_get_features_sel * @result: The command completion result from CQE dword0 * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_get_features_volatile_wc(int fd, enum nvme_get_features_sel sel, +int nvme_get_features_volatile_wc(nvme_link_t l, enum nvme_get_features_sel sel, __u32 *result); /** * nvme_get_features_num_queues() - Get number of queues feature - * @fd: File descriptor of nvme device + * @l: Link handle * @sel: Select which type of attribute to return, see &enum nvme_get_features_sel * @result: The command completion result from CQE dword0 * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_get_features_num_queues(int fd, enum nvme_get_features_sel sel, +int nvme_get_features_num_queues(nvme_link_t l, enum nvme_get_features_sel sel, __u32 *result); /** * nvme_get_features_irq_coalesce() - Get IRQ coalesce feature - * @fd: File descriptor of nvme device + * @l: Link handle * @sel: Select which type of attribute to return, see &enum nvme_get_features_sel * @result: The command completion result from CQE dword0 * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_get_features_irq_coalesce(int fd, enum nvme_get_features_sel sel, +int nvme_get_features_irq_coalesce(nvme_link_t l, enum nvme_get_features_sel sel, __u32 *result); /** * nvme_get_features_irq_config() - Get IRQ config feature - * @fd: File descriptor of nvme device + * @l: Link handle * @sel: Select which type of attribute to return, see &enum nvme_get_features_sel * @iv: * @result: The command completion result from CQE dword0 @@ -3202,36 +3162,36 @@ int nvme_get_features_irq_coalesce(int fd, enum nvme_get_features_sel sel, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_get_features_irq_config(int fd, enum nvme_get_features_sel sel, +int nvme_get_features_irq_config(nvme_link_t l, enum nvme_get_features_sel sel, __u16 iv, __u32 *result); /** * nvme_get_features_write_atomic() - Get write atomic feature - * @fd: File descriptor of nvme device + * @l: Link handle * @sel: Select which type of attribute to return, see &enum nvme_get_features_sel * @result: The command completion result from CQE dword0 * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_get_features_write_atomic(int fd, enum nvme_get_features_sel sel, +int nvme_get_features_write_atomic(nvme_link_t l, enum nvme_get_features_sel sel, __u32 *result); /** * nvme_get_features_async_event() - Get asynchronous event feature - * @fd: File descriptor of nvme device + * @l: Link handle * @sel: Select which type of attribute to return, see &enum nvme_get_features_sel * @result: The command completion result from CQE dword0 * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_get_features_async_event(int fd, enum nvme_get_features_sel sel, +int nvme_get_features_async_event(nvme_link_t l, enum nvme_get_features_sel sel, __u32 *result); /** * nvme_get_features_auto_pst() - Get autonomous power state feature - * @fd: File descriptor of nvme device + * @l: Link handle * @sel: Select which type of attribute to return, see &enum nvme_get_features_sel * @apst: * @result: The command completion result from CQE dword0 @@ -3239,12 +3199,12 @@ int nvme_get_features_async_event(int fd, enum nvme_get_features_sel sel, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_get_features_auto_pst(int fd, enum nvme_get_features_sel sel, +int nvme_get_features_auto_pst(nvme_link_t l, enum nvme_get_features_sel sel, struct nvme_feat_auto_pst *apst, __u32 *result); /** * nvme_get_features_host_mem_buf() - Get host memory buffer feature - * @fd: File descriptor of nvme device + * @l: Link handle * @sel: Select which type of attribute to return, see &enum nvme_get_features_sel * @attrs: Buffer for returned Host Memory Buffer Attributes * @result: The command completion result from CQE dword0 @@ -3252,69 +3212,69 @@ int nvme_get_features_auto_pst(int fd, enum nvme_get_features_sel sel, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_get_features_host_mem_buf(int fd, enum nvme_get_features_sel sel, +int nvme_get_features_host_mem_buf(nvme_link_t l, enum nvme_get_features_sel sel, struct nvme_host_mem_buf_attrs *attrs, __u32 *result); /** * nvme_get_features_timestamp() - Get timestamp feature - * @fd: File descriptor of nvme device + * @l: Link handle * @sel: Select which type of attribute to return, see &enum nvme_get_features_sel * @ts: Current timestamp * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_get_features_timestamp(int fd, enum nvme_get_features_sel sel, +int nvme_get_features_timestamp(nvme_link_t l, enum nvme_get_features_sel sel, struct nvme_timestamp *ts); /** * nvme_get_features_kato() - Get keep alive timeout feature - * @fd: File descriptor of nvme device + * @l: Link handle * @sel: Select which type of attribute to return, see &enum nvme_get_features_sel * @result: The command completion result from CQE dword0 * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_get_features_kato(int fd, enum nvme_get_features_sel sel, __u32 *result); +int nvme_get_features_kato(nvme_link_t l, enum nvme_get_features_sel sel, __u32 *result); /** * nvme_get_features_hctm() - Get thermal management feature - * @fd: File descriptor of nvme device + * @l: Link handle * @sel: Select which type of attribute to return, see &enum nvme_get_features_sel * @result: The command completion result from CQE dword0 * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_get_features_hctm(int fd, enum nvme_get_features_sel sel, __u32 *result); +int nvme_get_features_hctm(nvme_link_t l, enum nvme_get_features_sel sel, __u32 *result); /** * nvme_get_features_nopsc() - Get non-operational power state feature - * @fd: File descriptor of nvme device + * @l: Link handle * @sel: Select which type of attribute to return, see &enum nvme_get_features_sel * @result: The command completion result from CQE dword0 * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_get_features_nopsc(int fd, enum nvme_get_features_sel sel, __u32 *result); +int nvme_get_features_nopsc(nvme_link_t l, enum nvme_get_features_sel sel, __u32 *result); /** * nvme_get_features_rrl() - Get read recovery level feature - * @fd: File descriptor of nvme device + * @l: Link handle * @sel: Select which type of attribute to return, see &enum nvme_get_features_sel * @result: The command completion result from CQE dword0 * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_get_features_rrl(int fd, enum nvme_get_features_sel sel, __u32 *result); +int nvme_get_features_rrl(nvme_link_t l, enum nvme_get_features_sel sel, __u32 *result); /** * nvme_get_features_plm_config() - Get predictable latency feature - * @fd: File descriptor of nvme device + * @l: Link handle * @sel: Select which type of attribute to return, see &enum nvme_get_features_sel * @nvmsetid: NVM set id * @data: @@ -3323,13 +3283,13 @@ int nvme_get_features_rrl(int fd, enum nvme_get_features_sel sel, __u32 *result) * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_get_features_plm_config(int fd, enum nvme_get_features_sel sel, +int nvme_get_features_plm_config(nvme_link_t l, enum nvme_get_features_sel sel, __u16 nvmsetid, struct nvme_plm_config *data, __u32 *result); /** * nvme_get_features_plm_window() - Get window select feature - * @fd: File descriptor of nvme device + * @l: Link handle * @sel: Select which type of attribute to return, see &enum nvme_get_features_sel * @nvmsetid: NVM set id * @result: The command completion result from CQE dword0 @@ -3337,24 +3297,24 @@ int nvme_get_features_plm_config(int fd, enum nvme_get_features_sel sel, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_get_features_plm_window(int fd, enum nvme_get_features_sel sel, +int nvme_get_features_plm_window(nvme_link_t l, enum nvme_get_features_sel sel, __u16 nvmsetid, __u32 *result); /** * nvme_get_features_lba_sts_interval() - Get LBA status information feature - * @fd: File descriptor of nvme device + * @l: Link handle * @sel: Select which type of attribute to return, see &enum nvme_get_features_sel * @result: The command completion result from CQE dword0 * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_get_features_lba_sts_interval(int fd, enum nvme_get_features_sel sel, +int nvme_get_features_lba_sts_interval(nvme_link_t l, enum nvme_get_features_sel sel, __u32 *result); /** * nvme_get_features_host_behavior() - Get host behavior feature - * @fd: File descriptor of nvme device + * @l: Link handle * @sel: Select which type of attribute to return, see &enum nvme_get_features_sel * @data: Pointer to structure nvme_feat_host_behavior * @result: The command completion result from CQE dword0 @@ -3362,25 +3322,25 @@ int nvme_get_features_lba_sts_interval(int fd, enum nvme_get_features_sel sel, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_get_features_host_behavior(int fd, enum nvme_get_features_sel sel, +int nvme_get_features_host_behavior(nvme_link_t l, enum nvme_get_features_sel sel, struct nvme_feat_host_behavior *data, __u32 *result); /** * nvme_get_features_sanitize() - Get sanitize feature - * @fd: File descriptor of nvme device + * @l: Link handle * @sel: Select which type of attribute to return, see &enum nvme_get_features_sel * @result: The command completion result from CQE dword0 * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_get_features_sanitize(int fd, enum nvme_get_features_sel sel, +int nvme_get_features_sanitize(nvme_link_t l, enum nvme_get_features_sel sel, __u32 *result); /** * nvme_get_features_endurance_event_cfg() - Get endurance event config feature - * @fd: File descriptor of nvme device + * @l: Link handle * @sel: Select which type of attribute to return, see &enum nvme_get_features_sel * @endgid: Endurance Group Identifier * @result: The command completion result from CQE dword0 @@ -3388,24 +3348,24 @@ int nvme_get_features_sanitize(int fd, enum nvme_get_features_sel sel, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_get_features_endurance_event_cfg(int fd, enum nvme_get_features_sel sel, +int nvme_get_features_endurance_event_cfg(nvme_link_t l, enum nvme_get_features_sel sel, __u16 endgid, __u32 *result); /** * nvme_get_features_sw_progress() - Get software progress feature - * @fd: File descriptor of nvme device + * @l: Link handle * @sel: Select which type of attribute to return, see &enum nvme_get_features_sel * @result: The command completion result from CQE dword0 * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_get_features_sw_progress(int fd, enum nvme_get_features_sel sel, +int nvme_get_features_sw_progress(nvme_link_t l, enum nvme_get_features_sel sel, __u32 *result); /** * nvme_get_features_host_id() - Get host id feature - * @fd: File descriptor of nvme device + * @l: Link handle * @sel: Select which type of attribute to return, see &enum nvme_get_features_sel * @exhid: Enable Extended Host Identifier * @len: Length of @hostid @@ -3414,12 +3374,12 @@ int nvme_get_features_sw_progress(int fd, enum nvme_get_features_sel sel, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_get_features_host_id(int fd, enum nvme_get_features_sel sel, +int nvme_get_features_host_id(nvme_link_t l, enum nvme_get_features_sel sel, bool exhid, __u32 len, __u8 *hostid); /** * nvme_get_features_resv_mask() - Get reservation mask feature - * @fd: File descriptor of nvme device + * @l: Link handle * @sel: Select which type of attribute to return, see &enum nvme_get_features_sel * @nsid: Namespace ID * @result: The command completion result from CQE dword0 @@ -3427,12 +3387,12 @@ int nvme_get_features_host_id(int fd, enum nvme_get_features_sel sel, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_get_features_resv_mask(int fd, enum nvme_get_features_sel sel, +int nvme_get_features_resv_mask(nvme_link_t l, enum nvme_get_features_sel sel, __u32 nsid, __u32 *result); /** * nvme_get_features_resv_persist() - Get reservation persist feature - * @fd: File descriptor of nvme device + * @l: Link handle * @sel: Select which type of attribute to return, see &enum nvme_get_features_sel * @nsid: Namespace ID * @result: The command completion result from CQE dword0 @@ -3440,12 +3400,12 @@ int nvme_get_features_resv_mask(int fd, enum nvme_get_features_sel sel, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_get_features_resv_persist(int fd, enum nvme_get_features_sel sel, +int nvme_get_features_resv_persist(nvme_link_t l, enum nvme_get_features_sel sel, __u32 nsid, __u32 *result); /** * nvme_get_features_write_protect() - Get write protect feature - * @fd: File descriptor of nvme device + * @l: Link handle * @nsid: Namespace ID * @sel: Select which type of attribute to return, see &enum nvme_get_features_sel * @result: The command completion result from CQE dword0 @@ -3453,24 +3413,25 @@ int nvme_get_features_resv_persist(int fd, enum nvme_get_features_sel sel, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_get_features_write_protect(int fd, __u32 nsid, +int nvme_get_features_write_protect(nvme_link_t l, __u32 nsid, enum nvme_get_features_sel sel, __u32 *result); /** * nvme_get_features_iocs_profile() - Get IOCS profile feature - * @fd: File descriptor of nvme device + * @l: Link handle * @sel: Select which type of attribute to return, see &enum nvme_get_features_sel * @result: The command completion result from CQE dword0 * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_get_features_iocs_profile(int fd, enum nvme_get_features_sel sel, +int nvme_get_features_iocs_profile(nvme_link_t l, enum nvme_get_features_sel sel, __u32 *result); /** * nvme_format_nvm() - Format nvme namespace(s) + * @l: Link handle * @args: &struct nvme_format_nvme_args argument structure * * The Format NVM command low level formats the NVM media. This command is used @@ -3481,20 +3442,21 @@ int nvme_get_features_iocs_profile(int fd, enum nvme_get_features_sel sel, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_format_nvm(struct nvme_format_nvm_args *args); +int nvme_format_nvm(nvme_link_t l, struct nvme_format_nvm_args *args); /** * nvme_ns_mgmt() - Issue a Namespace management command + * @l: Link handle * @args: &struct nvme_ns_mgmt_args Argument structure * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_ns_mgmt(struct nvme_ns_mgmt_args *args); +int nvme_ns_mgmt(nvme_link_t l, struct nvme_ns_mgmt_args *args); /** * nvme_ns_mgmt_create() - Create a non attached namespace - * @fd: File descriptor of nvme device + * @l: Link handle * @ns: Namespace identification that defines ns creation parameters * @nsid: On success, set to the namespace id that was created * @timeout: Override the default timeout to this value in milliseconds; @@ -3509,7 +3471,7 @@ int nvme_ns_mgmt(struct nvme_ns_mgmt_args *args); * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_ns_mgmt_create(int fd, struct nvme_id_ns *ns, +static inline int nvme_ns_mgmt_create(nvme_link_t l, struct nvme_id_ns *ns, __u32 *nsid, __u32 timeout, __u8 csi, struct nvme_ns_mgmt_host_sw_specified *data) { @@ -3517,7 +3479,6 @@ static inline int nvme_ns_mgmt_create(int fd, struct nvme_id_ns *ns, .result = nsid, .ns = ns, .args_size = sizeof(args), - .fd = fd, .timeout = timeout, .nsid = NVME_NSID_NONE, .sel = NVME_NS_MGMT_SEL_CREATE, @@ -3527,12 +3488,12 @@ static inline int nvme_ns_mgmt_create(int fd, struct nvme_id_ns *ns, .data = data, }; - return nvme_ns_mgmt(&args); + return nvme_ns_mgmt(l, &args); } /** * nvme_ns_mgmt_delete_timeout() - Delete a non attached namespace with timeout - * @fd: File descriptor of nvme device + * @l: Link handle * @nsid: Namespace identifier to delete * @timeout: Override the default timeout to this value in milliseconds; * set to 0 to use the system default. @@ -3544,13 +3505,12 @@ static inline int nvme_ns_mgmt_create(int fd, struct nvme_id_ns *ns, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_ns_mgmt_delete_timeout(int fd, __u32 nsid, __u32 timeout) +static inline int nvme_ns_mgmt_delete_timeout(nvme_link_t l, __u32 nsid, __u32 timeout) { struct nvme_ns_mgmt_args args = { .result = NULL, .ns = NULL, .args_size = sizeof(args), - .fd = fd, .timeout = timeout, .nsid = nsid, .sel = NVME_NS_MGMT_SEL_DELETE, @@ -3560,12 +3520,12 @@ static inline int nvme_ns_mgmt_delete_timeout(int fd, __u32 nsid, __u32 timeout) .data = NULL, }; - return nvme_ns_mgmt(&args); + return nvme_ns_mgmt(l, &args); } /** * nvme_ns_mgmt_delete() - Delete a non attached namespace - * @fd: File descriptor of nvme device + * @l: Link handle * @nsid: Namespace identifier to delete * * It is recommended that a namespace being deleted is not attached to any @@ -3575,73 +3535,73 @@ static inline int nvme_ns_mgmt_delete_timeout(int fd, __u32 nsid, __u32 timeout) * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_ns_mgmt_delete(int fd, __u32 nsid) +static inline int nvme_ns_mgmt_delete(nvme_link_t l, __u32 nsid) { - return nvme_ns_mgmt_delete_timeout(fd, nsid, 0); + return nvme_ns_mgmt_delete_timeout(l, nsid, 0); } /** * nvme_ns_attach() - Attach or detach namespace to controller(s) + * @l: Link handle * @args: &struct nvme_ns_attach_args Argument structure * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_ns_attach(struct nvme_ns_attach_args *args); +int nvme_ns_attach(nvme_link_t l, struct nvme_ns_attach_args *args); /** * nvme_ns_attach_ctrls() - Attach namespace to controllers - * @fd: File descriptor of nvme device + * @l: Link handle * @nsid: Namespace ID to attach * @ctrlist: Controller list to modify attachment state of nsid * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_ns_attach_ctrls(int fd, __u32 nsid, +static inline int nvme_ns_attach_ctrls(nvme_link_t l, __u32 nsid, struct nvme_ctrl_list *ctrlist) { struct nvme_ns_attach_args args = { .result = NULL, .ctrlist = ctrlist, .args_size = sizeof(args), - .fd = fd, .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, .nsid = nsid, .sel = NVME_NS_ATTACH_SEL_CTRL_ATTACH, }; - return nvme_ns_attach(&args); + return nvme_ns_attach(l, &args); } /** * nvme_ns_detach_ctrls() - Detach namespace from controllers - * @fd: File descriptor of nvme device + * @l: Link handle * @nsid: Namespace ID to detach * @ctrlist: Controller list to modify attachment state of nsid * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_ns_detach_ctrls(int fd, __u32 nsid, +static inline int nvme_ns_detach_ctrls(nvme_link_t l, __u32 nsid, struct nvme_ctrl_list *ctrlist) { struct nvme_ns_attach_args args = { .result = NULL, .ctrlist = ctrlist, .args_size = sizeof(args), - .fd = fd, .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, .nsid = nsid, .sel = NVME_NS_ATTACH_SEL_CTRL_DEATTACH, }; - return nvme_ns_attach(&args); + return nvme_ns_attach(l, &args); } /** * nvme_fw_download() - Download part or all of a firmware image to the * controller + * @l: Link handle * @args: &struct nvme_fw_download_args argument structure * * The Firmware Image Download command downloads all or a portion of an image @@ -3660,10 +3620,11 @@ static inline int nvme_ns_detach_ctrls(int fd, __u32 nsid, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_fw_download(struct nvme_fw_download_args *args); +int nvme_fw_download(nvme_link_t l, struct nvme_fw_download_args *args); /** * nvme_fw_commit() - Commit firmware using the specified action + * @l: Link handle * @args: &struct nvme_fw_commit_args argument structure * * The Firmware Commit command modifies the firmware image or Boot Partitions. @@ -3673,10 +3634,11 @@ int nvme_fw_download(struct nvme_fw_download_args *args); * status response may specify additional reset actions required to complete * the commit process. */ -int nvme_fw_commit(struct nvme_fw_commit_args *args); +int nvme_fw_commit(nvme_link_t l, struct nvme_fw_commit_args *args); /** * nvme_security_send() - Security Send command + * @l: Link handle * @args: &struct nvme_security_send argument structure * * The Security Send command transfers security protocol data to the @@ -3691,19 +3653,21 @@ int nvme_fw_commit(struct nvme_fw_commit_args *args); * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_security_send(struct nvme_security_send_args *args); +int nvme_security_send(nvme_link_t l, struct nvme_security_send_args *args); /** * nvme_security_receive() - Security Receive command + * @l: Link handle * @args: &struct nvme_security_receive argument structure * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_security_receive(struct nvme_security_receive_args *args); +int nvme_security_receive(nvme_link_t l, struct nvme_security_receive_args *args); /** * nvme_get_lba_status() - Retrieve information on possibly unrecoverable LBAs + * @l: Link handle * @args: &struct nvme_get_lba_status_args argument structure * * The Get LBA Status command requests information about Potentially @@ -3712,10 +3676,11 @@ int nvme_security_receive(struct nvme_security_receive_args *args); * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_get_lba_status(struct nvme_get_lba_status_args *args); +int nvme_get_lba_status(nvme_link_t l, struct nvme_get_lba_status_args *args); /** * nvme_directive_send() - Send directive command + * @l: Link handle * @args: &struct nvme_directive_send_args argument structure * * Directives is a mechanism to enable host and NVM subsystem or controller @@ -3727,11 +3692,11 @@ int nvme_get_lba_status(struct nvme_get_lba_status_args *args); * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_directive_send(struct nvme_directive_send_args *args); +int nvme_directive_send(nvme_link_t l, struct nvme_directive_send_args *args); /** * nvme_directive_send_id_endir() - Directive Send Enable Directive - * @fd: File descriptor of nvme device + * @l: Link handle * @nsid: Namespace Identifier * @endir: Enable Directive * @dtype: Directive Type @@ -3740,27 +3705,26 @@ int nvme_directive_send(struct nvme_directive_send_args *args); * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_directive_send_id_endir(int fd, __u32 nsid, bool endir, +int nvme_directive_send_id_endir(nvme_link_t l, __u32 nsid, bool endir, enum nvme_directive_dtype dtype, struct nvme_id_directives *id); /** * nvme_directive_send_stream_release_identifier() - Directive Send Stream release - * @fd: File descriptor of nvme device + * @l: Link handle * @nsid: Namespace ID * @stream_id: Stream identifier * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_directive_send_stream_release_identifier(int fd, +static inline int nvme_directive_send_stream_release_identifier(nvme_link_t l, __u32 nsid, __u16 stream_id) { struct nvme_directive_send_args args = { .result = NULL, .data = NULL, .args_size = sizeof(args), - .fd = fd, .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, .nsid = nsid, .doper = NVME_DIRECTIVE_SEND_STREAMS_DOPER_RELEASE_IDENTIFIER, @@ -3770,24 +3734,23 @@ static inline int nvme_directive_send_stream_release_identifier(int fd, .dspec = stream_id, }; - return nvme_directive_send(&args); + return nvme_directive_send(l, &args); } /** * nvme_directive_send_stream_release_resource() - Directive Send Stream release resources - * @fd: File descriptor of nvme device + * @l: Link handle * @nsid: Namespace ID * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_directive_send_stream_release_resource(int fd, __u32 nsid) +static inline int nvme_directive_send_stream_release_resource(nvme_link_t l, __u32 nsid) { struct nvme_directive_send_args args = { .result = NULL, .data = NULL, .args_size = sizeof(args), - .fd = fd, .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, .nsid = nsid, .doper = NVME_DIRECTIVE_SEND_STREAMS_DOPER_RELEASE_RESOURCE, @@ -3797,35 +3760,35 @@ static inline int nvme_directive_send_stream_release_resource(int fd, __u32 nsid .dspec = 0, }; - return nvme_directive_send(&args); + return nvme_directive_send(l, &args); } /** * nvme_directive_recv() - Receive directive specific data + * @l: Link handle * @args: &struct nvme_directive_recv_args argument structure * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_directive_recv(struct nvme_directive_recv_args *args); +int nvme_directive_recv(nvme_link_t l, struct nvme_directive_recv_args *args); /** * nvme_directive_recv_identify_parameters() - Directive receive identifier parameters - * @fd: File descriptor of nvme device + * @l: Link handle * @nsid: Namespace ID * @id: Identify parameters buffer * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_directive_recv_identify_parameters(int fd, __u32 nsid, +static inline int nvme_directive_recv_identify_parameters(nvme_link_t l, __u32 nsid, struct nvme_id_directives *id) { struct nvme_directive_recv_args args = { .result = NULL, .data = id, .args_size = sizeof(args), - .fd = fd, .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, .nsid = nsid, .doper = NVME_DIRECTIVE_RECEIVE_IDENTIFY_DOPER_PARAM, @@ -3835,26 +3798,25 @@ static inline int nvme_directive_recv_identify_parameters(int fd, __u32 nsid, .dspec = 0, }; - return nvme_directive_recv(&args); + return nvme_directive_recv(l, &args); } /** * nvme_directive_recv_stream_parameters() - Directive receive stream parameters - * @fd: File descriptor of nvme device + * @l: Link handle * @nsid: Namespace ID * @parms: Streams directive parameters buffer * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_directive_recv_stream_parameters(int fd, __u32 nsid, +static inline int nvme_directive_recv_stream_parameters(nvme_link_t l, __u32 nsid, struct nvme_streams_directive_params *parms) { struct nvme_directive_recv_args args = { .result = NULL, .data = parms, .args_size = sizeof(args), - .fd = fd, .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, .nsid = nsid, .doper = NVME_DIRECTIVE_RECEIVE_STREAMS_DOPER_PARAM, @@ -3864,12 +3826,12 @@ static inline int nvme_directive_recv_stream_parameters(int fd, __u32 nsid, .dspec = 0, }; - return nvme_directive_recv(&args); + return nvme_directive_recv(l, &args); } /** * nvme_directive_recv_stream_status() - Directive receive stream status - * @fd: File descriptor of nvme device + * @l: Link handle * @nsid: Namespace ID * @nr_entries: Number of streams to receive * @id: Stream status buffer @@ -3877,7 +3839,7 @@ static inline int nvme_directive_recv_stream_parameters(int fd, __u32 nsid, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_directive_recv_stream_status(int fd, __u32 nsid, +static inline int nvme_directive_recv_stream_status(nvme_link_t l, __u32 nsid, unsigned int nr_entries, struct nvme_streams_directive_status *id) { @@ -3890,7 +3852,6 @@ static inline int nvme_directive_recv_stream_status(int fd, __u32 nsid, .result = NULL, .data = id, .args_size = sizeof(args), - .fd = fd, .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, .nsid = nsid, .doper = NVME_DIRECTIVE_RECEIVE_STREAMS_DOPER_STATUS, @@ -3900,12 +3861,12 @@ static inline int nvme_directive_recv_stream_status(int fd, __u32 nsid, .dspec = 0, }; - return nvme_directive_recv(&args); + return nvme_directive_recv(l, &args); } /** * nvme_directive_recv_stream_allocate() - Directive receive stream allocate - * @fd: File descriptor of nvme device + * @l: Link handle * @nsid: Namespace ID * @nsr: Namespace Streams Requested * @result: If successful, the CQE dword0 value @@ -3913,14 +3874,13 @@ static inline int nvme_directive_recv_stream_status(int fd, __u32 nsid, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_directive_recv_stream_allocate(int fd, __u32 nsid, +static inline int nvme_directive_recv_stream_allocate(nvme_link_t l, __u32 nsid, __u16 nsr, __u32 *result) { struct nvme_directive_recv_args args = { .result = result, .data = NULL, .args_size = sizeof(args), - .fd = fd, .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, .nsid = nsid, .doper = NVME_DIRECTIVE_RECEIVE_STREAMS_DOPER_RESOURCE, @@ -3930,29 +3890,32 @@ static inline int nvme_directive_recv_stream_allocate(int fd, __u32 nsid, .dspec = 0, }; - return nvme_directive_recv(&args); + return nvme_directive_recv(l, &args); } /** * nvme_capacity_mgmt() - Capacity management command + * @l: Link handle * @args: &struct nvme_capacity_mgmt_args argument structure * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_capacity_mgmt(struct nvme_capacity_mgmt_args *args); +int nvme_capacity_mgmt(nvme_link_t l, struct nvme_capacity_mgmt_args *args); /** * nvme_lockdown() - Issue lockdown command + * @l: Link handle * @args: &struct nvme_lockdown_args argument structure * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_lockdown(struct nvme_lockdown_args *args); +int nvme_lockdown(nvme_link_t l, struct nvme_lockdown_args *args); /** * nvme_set_property() - Set controller property + * @l: Link handle * @args: &struct nvme_set_property_args argument structure * * This is an NVMe-over-Fabrics specific command, not applicable to PCIe. These @@ -3961,10 +3924,11 @@ int nvme_lockdown(struct nvme_lockdown_args *args); * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_set_property(struct nvme_set_property_args *args); +int nvme_set_property(nvme_link_t l, struct nvme_set_property_args *args); /** * nvme_get_property() - Get a controller property + * @l: Link handle * @args: &struct nvme_get_propert_args argument structure * * This is an NVMe-over-Fabrics specific command, not applicable to PCIe. These @@ -3973,10 +3937,11 @@ int nvme_set_property(struct nvme_set_property_args *args); * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_get_property(struct nvme_get_property_args *args); +int nvme_get_property(nvme_link_t l, struct nvme_get_property_args *args); /** * nvme_sanitize_nvm() - Start a sanitize operation + * @l: Link handle * @args: &struct nvme_sanitize_nvm_args argument structure * * A sanitize operation alters all user data in the NVM subsystem such that @@ -3992,10 +3957,11 @@ int nvme_get_property(struct nvme_get_property_args *args); * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_sanitize_nvm(struct nvme_sanitize_nvm_args *args); +int nvme_sanitize_nvm(nvme_link_t l, struct nvme_sanitize_nvm_args *args); /** * nvme_dev_self_test() - Start or abort a self test + * @l: Link handle * @args: &struct nvme_dev_self_test argument structure * * The Device Self-test command starts a device self-test operation or abort a @@ -4012,10 +3978,11 @@ int nvme_sanitize_nvm(struct nvme_sanitize_nvm_args *args); * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_dev_self_test(struct nvme_dev_self_test_args *args); +int nvme_dev_self_test(nvme_link_t l, struct nvme_dev_self_test_args *args); /** * nvme_virtual_mgmt() - Virtualization resource management + * @l: Link handle * @args: &struct nvme_virtual_mgmt_args argument structure * * The Virtualization Management command is supported by primary controllers @@ -4029,11 +3996,11 @@ int nvme_dev_self_test(struct nvme_dev_self_test_args *args); * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_virtual_mgmt(struct nvme_virtual_mgmt_args *args); +int nvme_virtual_mgmt(nvme_link_t l, struct nvme_virtual_mgmt_args *args); /** * nvme_flush() - Send an nvme flush command - * @fd: File descriptor of nvme device + * @l: Link handle * @nsid: Namespace identifier * * The Flush command requests that the contents of volatile write cache be made @@ -4042,64 +4009,69 @@ int nvme_virtual_mgmt(struct nvme_virtual_mgmt_args *args); * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_flush(int fd, __u32 nsid) +static inline int nvme_flush(nvme_link_t l, __u32 nsid) { struct nvme_passthru_cmd cmd = {}; cmd.opcode = nvme_cmd_flush; cmd.nsid = nsid; - return nvme_submit_io_passthru(fd, &cmd, NULL); + return nvme_submit_io_passthru(l, &cmd, NULL); } /** * nvme_io() - Submit an nvme user I/O command + * @l: Link handle * @args: &struct nvme_io_args argument structure * @opcode: Opcode to execute * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_io(struct nvme_io_args *args, __u8 opcode); +int nvme_io(nvme_link_t l, struct nvme_io_args *args, __u8 opcode); /** * nvme_read() - Submit an nvme user read command + * @l: Link handle * @args: &struct nvme_io_args argument structure * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_read(struct nvme_io_args *args) +static inline int nvme_read(nvme_link_t l, struct nvme_io_args *args) { - return nvme_io(args, nvme_cmd_read); + return nvme_io(l, args, nvme_cmd_read); } /** * nvme_write() - Submit an nvme user write command + * @l: Link handle * @args: &struct nvme_io_args argument structure * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_write(struct nvme_io_args *args) +static inline int nvme_write(nvme_link_t l, struct nvme_io_args *args) { - return nvme_io(args, nvme_cmd_write); + return nvme_io(l, args, nvme_cmd_write); } /** * nvme_compare() - Submit an nvme user compare command + * @l: Link handle * @args: &struct nvme_io_args argument structure * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_compare(struct nvme_io_args *args) +static inline int nvme_compare(nvme_link_t l, struct nvme_io_args *args) { - return nvme_io(args, nvme_cmd_compare); + return nvme_io(l, args, nvme_cmd_compare); } /** * nvme_write_zeros() - Submit an nvme write zeroes command + * @l: Link handle * @args: &struct nvme_io_args argument structure * * The Write Zeroes command sets a range of logical blocks to zero. After @@ -4110,13 +4082,14 @@ static inline int nvme_compare(struct nvme_io_args *args) * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_write_zeros(struct nvme_io_args *args) +static inline int nvme_write_zeros(nvme_link_t l, struct nvme_io_args *args) { - return nvme_io(args, nvme_cmd_write_zeroes); + return nvme_io(l, args, nvme_cmd_write_zeroes); } /** * nvme_write_uncorrectable() - Submit an nvme write uncorrectable command + * @l: Link handle * @args: &struct nvme_io_args argument structure * * The Write Uncorrectable command marks a range of logical blocks as invalid. @@ -4127,13 +4100,14 @@ static inline int nvme_write_zeros(struct nvme_io_args *args) * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_write_uncorrectable(struct nvme_io_args *args) +static inline int nvme_write_uncorrectable(nvme_link_t l, struct nvme_io_args *args) { - return nvme_io(args, nvme_cmd_write_uncor); + return nvme_io(l, args, nvme_cmd_write_uncor); } /** * nvme_verify() - Send an nvme verify command + * @l: Link handle * @args: &struct nvme_io_args argument structure * * The Verify command verifies integrity of stored information by reading data @@ -4143,13 +4117,14 @@ static inline int nvme_write_uncorrectable(struct nvme_io_args *args) * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_verify(struct nvme_io_args *args) +static inline int nvme_verify(nvme_link_t l, struct nvme_io_args *args) { - return nvme_io(args, nvme_cmd_verify); + return nvme_io(l, args, nvme_cmd_verify); } /** * nvme_dsm() - Send an nvme data set management command + * @l: Link handle * @args: &struct nvme_dsm_args argument structure * * The Dataset Management command is used by the host to indicate attributes @@ -4161,20 +4136,21 @@ static inline int nvme_verify(struct nvme_io_args *args) * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_dsm(struct nvme_dsm_args *args); +int nvme_dsm(nvme_link_t l, struct nvme_dsm_args *args); /** * nvme_copy() - Copy command - * + * @l: Link handle * @args: &struct nvme_copy_args argument structure * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_copy(struct nvme_copy_args *args); +int nvme_copy(nvme_link_t l, struct nvme_copy_args *args); /** * nvme_resv_acquire() - Send an nvme reservation acquire + * @l: Link handle * @args: &struct nvme_resv_acquire argument structure * * The Reservation Acquire command acquires a reservation on a namespace, @@ -4184,10 +4160,11 @@ int nvme_copy(struct nvme_copy_args *args); * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_resv_acquire(struct nvme_resv_acquire_args *args); +int nvme_resv_acquire(nvme_link_t l, struct nvme_resv_acquire_args *args); /** * nvme_resv_register() - Send an nvme reservation register + * @l: Link handle * @args: &struct nvme_resv_register_args argument structure * * The Reservation Register command registers, unregisters, or replaces a @@ -4196,19 +4173,21 @@ int nvme_resv_acquire(struct nvme_resv_acquire_args *args); * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_resv_register(struct nvme_resv_register_args *args); +int nvme_resv_register(nvme_link_t l, struct nvme_resv_register_args *args); /** * nvme_resv_release() - Send an nvme reservation release + * @l: Link handle * @args: &struct nvme_resv_release_args argument structure * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_resv_release(struct nvme_resv_release_args *args); +int nvme_resv_release(nvme_link_t l, struct nvme_resv_release_args *args); /** * nvme_resv_report() - Send an nvme reservation report + * @l: Link handle * @args: struct nvme_resv_report_args argument structure * * Returns a Reservation Status data structure to memory that describes the @@ -4218,20 +4197,21 @@ int nvme_resv_release(struct nvme_resv_release_args *args); * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_resv_report(struct nvme_resv_report_args *args); +int nvme_resv_report(nvme_link_t l, struct nvme_resv_report_args *args); /** * nvme_io_mgmt_recv() - I/O Management Receive command + * @l: Link handle * @args: &struct nvme_io_mgmt_recv_args argument structure * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_io_mgmt_recv(struct nvme_io_mgmt_recv_args *args); +int nvme_io_mgmt_recv(nvme_link_t l, struct nvme_io_mgmt_recv_args *args); /** * nvme_fdp_reclaim_unit_handle_status() - Get reclaim unit handle status - * @fd: File descriptor of nvme device + * @l: Link handle * @nsid: Namespace identifier * @data_len: Length of response buffer * @data: Response buffer @@ -4239,13 +4219,12 @@ int nvme_io_mgmt_recv(struct nvme_io_mgmt_recv_args *args); * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_fdp_reclaim_unit_handle_status(int fd, __u32 nsid, +static inline int nvme_fdp_reclaim_unit_handle_status(nvme_link_t l, __u32 nsid, __u32 data_len, void *data) { struct nvme_io_mgmt_recv_args args = { .data = data, .args_size = sizeof(args), - .fd = fd, .nsid = nsid, .data_len = data_len, .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, @@ -4253,21 +4232,22 @@ static inline int nvme_fdp_reclaim_unit_handle_status(int fd, __u32 nsid, .mo = NVME_IO_MGMT_RECV_RUH_STATUS, }; - return nvme_io_mgmt_recv(&args); + return nvme_io_mgmt_recv(l, &args); } /** * nvme_io_mgmt_send() - I/O Management Send command + * @l: Link handle * @args: &struct nvme_io_mgmt_send_args argument structure * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_io_mgmt_send(struct nvme_io_mgmt_send_args *args); +int nvme_io_mgmt_send(nvme_link_t l, struct nvme_io_mgmt_send_args *args); /** * nvme_fdp_reclaim_unit_handle_update() - Update a list of reclaim unit handles - * @fd: File descriptor of nvme device + * @l: Link handle * @nsid: Namespace identifier * @npids: Number of placement identifiers * @pids: List of placement identifiers @@ -4275,13 +4255,12 @@ int nvme_io_mgmt_send(struct nvme_io_mgmt_send_args *args); * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_fdp_reclaim_unit_handle_update(int fd, __u32 nsid, +static inline int nvme_fdp_reclaim_unit_handle_update(nvme_link_t l, __u32 nsid, unsigned int npids, __u16 *pids) { struct nvme_io_mgmt_send_args args = { .data = (void *)pids, .args_size = sizeof(args), - .fd = fd, .nsid = nsid, .data_len = (__u32)(npids * sizeof(__u16)), .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, @@ -4289,31 +4268,33 @@ static inline int nvme_fdp_reclaim_unit_handle_update(int fd, __u32 nsid, .mo = NVME_IO_MGMT_SEND_RUH_UPDATE, }; - return nvme_io_mgmt_send(&args); + return nvme_io_mgmt_send(l, &args); } /** * nvme_zns_mgmt_send() - ZNS management send command + * @l: Link handle * @args: &struct nvme_zns_mgmt_send_args argument structure * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_zns_mgmt_send(struct nvme_zns_mgmt_send_args *args); +int nvme_zns_mgmt_send(nvme_link_t l, struct nvme_zns_mgmt_send_args *args); /** * nvme_zns_mgmt_recv() - ZNS management receive command + * @l: Link handle * @args: &struct nvme_zns_mgmt_recv_args argument structure * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_zns_mgmt_recv(struct nvme_zns_mgmt_recv_args *args); +int nvme_zns_mgmt_recv(nvme_link_t l, struct nvme_zns_mgmt_recv_args *args); /** * nvme_zns_report_zones() - Return the list of zones - * @fd: File descriptor of nvme device + * @l: Link handle * @nsid: Namespace ID * @slba: Starting LBA * @opts: Reporting options @@ -4327,7 +4308,7 @@ int nvme_zns_mgmt_recv(struct nvme_zns_mgmt_recv_args *args); * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_zns_report_zones(int fd, __u32 nsid, __u64 slba, +static inline int nvme_zns_report_zones(nvme_link_t l, __u32 nsid, __u64 slba, enum nvme_zns_report_options opts, bool extended, bool partial, __u32 data_len, void *data, @@ -4338,7 +4319,6 @@ static inline int nvme_zns_report_zones(int fd, __u32 nsid, __u64 slba, .result = result, .data = data, .args_size = sizeof(args), - .fd = fd, .timeout = timeout, .nsid = nsid, .zra = extended ? NVME_ZNS_ZRA_EXTENDED_REPORT_ZONES : @@ -4348,66 +4328,72 @@ static inline int nvme_zns_report_zones(int fd, __u32 nsid, __u64 slba, .zras_feat = partial, }; - return nvme_zns_mgmt_recv(&args); + return nvme_zns_mgmt_recv(l, &args); } /** * nvme_zns_append() - Append data to a zone + * @l: Link handle * @args: &struct nvme_zns_append_args argument structure * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_zns_append(struct nvme_zns_append_args *args); +int nvme_zns_append(nvme_link_t l, struct nvme_zns_append_args *args); /** * nvme_dim_send - Send a Discovery Information Management (DIM) command + * @l: Link handle * @args: &struct nvme_dim_args argument structure * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_dim_send(struct nvme_dim_args *args); +int nvme_dim_send(nvme_link_t l, struct nvme_dim_args *args); /** * nvme_lm_cdq() - Controller Data Queue - Controller Data Queue command + * @l: Link handle * @args: &struct nvme_lm_cdq_args argument structure * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise.) */ -int nvme_lm_cdq(struct nvme_lm_cdq_args *args); +int nvme_lm_cdq(nvme_link_t l, struct nvme_lm_cdq_args *args); /** * nvme_lm_track_send() - Track Send command + * @l: Link handle * @args: &struct nvme_lm_track_send_args argument structure * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_lm_track_send(struct nvme_lm_track_send_args *args); +int nvme_lm_track_send(nvme_link_t l, struct nvme_lm_track_send_args *args); /** * nvme_lm_migration_send() - Migration Send command + * @l: Link handle * @args: &struct nvme_lm_migration_send_args argument structure * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_lm_migration_send(struct nvme_lm_migration_send_args *args); +int nvme_lm_migration_send(nvme_link_t l, struct nvme_lm_migration_send_args *args); /** * nvme_lm_migration_recv - Migration Receive command + * @l: Link handle * @args: &struct nvme_lm_migration_rev_args argument structure * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_lm_migration_recv(struct nvme_lm_migration_recv_args *args); +int nvme_lm_migration_recv(nvme_link_t l, struct nvme_lm_migration_recv_args *args); /** * nvme_lm_set_features_ctrl_data_queue - Set Controller Datea Queue feature - * @fd: File descriptor of nvme device + * @l: Link handle * @cdqid: Controller Data Queue ID (CDQID) * @hp: Head Pointer * @tpt: Tail Pointer Trigger @@ -4417,12 +4403,12 @@ int nvme_lm_migration_recv(struct nvme_lm_migration_recv_args *args); * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_lm_set_features_ctrl_data_queue(int fd, __u16 cdqid, __u32 hp, __u32 tpt, bool etpt, +int nvme_lm_set_features_ctrl_data_queue(nvme_link_t l, __u16 cdqid, __u32 hp, __u32 tpt, bool etpt, __u32 *result); /** * nvme_lm_get_features_ctrl_data_queue - Get Controller Data Queue feature - * @fd: File descriptor of nvme device + * @l: Link handle * @cdqid: Controller Data Queue ID (CDQID) * @data: Get Controller Data Queue feature data * @result: The command completions result from CQE dword0 @@ -4430,7 +4416,7 @@ int nvme_lm_set_features_ctrl_data_queue(int fd, __u16 cdqid, __u32 hp, __u32 tp * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_lm_get_features_ctrl_data_queue(int fd, __u16 cdqid, +int nvme_lm_get_features_ctrl_data_queue(nvme_link_t l, __u16 cdqid, struct nvme_lm_ctrl_data_queue_fid_data *data, __u32 *result); #endif /* _LIBNVME_IOCTL_H */ diff --git a/src/nvme/linux.c b/src/nvme/linux.c index ae4aa526f..bd5bc2e38 100644 --- a/src/nvme/linux.c +++ b/src/nvme/linux.c @@ -41,7 +41,7 @@ #include "base64.h" #include "crc32.h" -static int __nvme_open(const char *name) +static int __nvme_open_dev(const char *name) { _cleanup_free_ char *path = NULL; int ret; @@ -55,24 +55,38 @@ static int __nvme_open(const char *name) return open(path, O_RDONLY); } -int nvme_open(const char *name) +nvme_link_t nvme_open(nvme_root_t r, const char *name) { - int ret, fd, id, ns; + nvme_link_t l; + int ret, id, ns; struct stat stat; bool c; + l = malloc(sizeof(*l)); + if (!l) { + errno = ENOMEM; + return NULL; + } + + l->root = r; + + if (!strcmp(name, "NVME_TEST_FD")) { + l->fd = 0xFD; + return l; + } + ret = sscanf(name, "nvme%dn%d", &id, &ns); if (ret != 1 && ret != 2) { errno = EINVAL; - return -1; + goto free_link; } c = ret == 1; - fd = __nvme_open(name); - if (fd < 0) - return fd; + l->fd = __nvme_open_dev(name); + if (l->fd < 0) + goto free_link; - ret = fstat(fd, &stat); + ret = fstat(l->fd, &stat); if (ret < 0) goto close_fd; @@ -86,20 +100,31 @@ int nvme_open(const char *name) goto close_fd; } - return fd; + return l; close_fd: - close(fd); - return -1; + close(l->fd); +free_link: + free(l); + return NULL; +} + +void nvme_close(nvme_link_t l) +{ + if (!l) + return; + + close(l->fd); + free(l->log); + free(l); } -int nvme_fw_download_seq(int fd, __u32 size, __u32 xfer, __u32 offset, +int nvme_fw_download_seq(nvme_link_t l, __u32 size, __u32 xfer, __u32 offset, void *buf) { int err = 0; struct nvme_fw_download_args args = { .args_size = sizeof(args), - .fd = fd, .offset = offset, .data_len = xfer, .data = buf, @@ -109,7 +134,7 @@ int nvme_fw_download_seq(int fd, __u32 size, __u32 xfer, __u32 offset, while (size > 0) { args.data_len = MIN(xfer, size); - err = nvme_fw_download(&args); + err = nvme_fw_download(l, &args); if (err) break; @@ -121,7 +146,7 @@ int nvme_fw_download_seq(int fd, __u32 size, __u32 xfer, __u32 offset, return err; } -int nvme_get_telemetry_max(int fd, enum nvme_telemetry_da *da, size_t *data_tx) +int nvme_get_telemetry_max(nvme_link_t l, enum nvme_telemetry_da *da, size_t *data_tx) { _cleanup_free_ struct nvme_id_ctrl *id_ctrl = NULL; int err; @@ -131,7 +156,7 @@ int nvme_get_telemetry_max(int fd, enum nvme_telemetry_da *da, size_t *data_tx) errno = ENOMEM; return -1; } - err = nvme_identify_ctrl(fd, id_ctrl); + err = nvme_identify_ctrl(l, id_ctrl); if (err) return err; @@ -154,7 +179,7 @@ int nvme_get_telemetry_max(int fd, enum nvme_telemetry_da *da, size_t *data_tx) return err; } -int nvme_get_telemetry_log(int fd, bool create, bool ctrl, bool rae, size_t max_data_tx, +int nvme_get_telemetry_log(nvme_link_t l, bool create, bool ctrl, bool rae, size_t max_data_tx, enum nvme_telemetry_da da, struct nvme_telemetry_log **buf, size_t *size) { @@ -168,7 +193,6 @@ int nvme_get_telemetry_log(int fd, bool create, bool ctrl, bool rae, size_t max_ size_t dalb; struct nvme_get_log_args args = { .args_size = sizeof(args), - .fd = fd, .nsid = NVME_NSID_NONE, .lsp = NVME_LOG_LSP_NONE, .lsi = NVME_LOG_LSI_NONE, @@ -189,14 +213,14 @@ int nvme_get_telemetry_log(int fd, bool create, bool ctrl, bool rae, size_t max_ } if (ctrl) { - err = nvme_get_log_telemetry_ctrl(fd, true, 0, xfer, log); + err = nvme_get_log_telemetry_ctrl(l, true, 0, xfer, log); lid = NVME_LOG_LID_TELEMETRY_CTRL; } else { lid = NVME_LOG_LID_TELEMETRY_HOST; if (create) - err = nvme_get_log_create_telemetry_host_mcda(fd, da, log); + err = nvme_get_log_create_telemetry_host_mcda(l, da, log); else - err = nvme_get_log_telemetry_host(fd, 0, xfer, log); + err = nvme_get_log_telemetry_host(l, 0, xfer, log); } if (err) @@ -245,7 +269,7 @@ int nvme_get_telemetry_log(int fd, bool create, bool ctrl, bool rae, size_t max_ args.lid = lid; args.log = log; args.len = *size; - err = nvme_get_log_page(fd, max_data_tx, &args); + err = nvme_get_log_page(l, max_data_tx, &args); if (err) return err; @@ -255,12 +279,12 @@ int nvme_get_telemetry_log(int fd, bool create, bool ctrl, bool rae, size_t max_ } -static int nvme_check_get_telemetry_log(int fd, bool create, bool ctrl, bool rae, +static int nvme_check_get_telemetry_log(nvme_link_t l, bool create, bool ctrl, bool rae, struct nvme_telemetry_log **log, enum nvme_telemetry_da da, size_t *size) { enum nvme_telemetry_da max_da = 0; - int err = nvme_get_telemetry_max(fd, &max_da, NULL); + int err = nvme_get_telemetry_max(l, &max_da, NULL); if (err) return err; @@ -268,29 +292,29 @@ static int nvme_check_get_telemetry_log(int fd, bool create, bool ctrl, bool rae errno = ENOENT; return -1; } - return nvme_get_telemetry_log(fd, create, ctrl, rae, 4096, da, log, size); + return nvme_get_telemetry_log(l, create, ctrl, rae, 4096, da, log, size); } -int nvme_get_ctrl_telemetry(int fd, bool rae, struct nvme_telemetry_log **log, +int nvme_get_ctrl_telemetry(nvme_link_t l, bool rae, struct nvme_telemetry_log **log, enum nvme_telemetry_da da, size_t *size) { - return nvme_check_get_telemetry_log(fd, false, true, rae, log, da, size); + return nvme_check_get_telemetry_log(l, false, true, rae, log, da, size); } -int nvme_get_host_telemetry(int fd, struct nvme_telemetry_log **log, +int nvme_get_host_telemetry(nvme_link_t l, struct nvme_telemetry_log **log, enum nvme_telemetry_da da, size_t *size) { - return nvme_check_get_telemetry_log(fd, false, false, false, log, da, size); + return nvme_check_get_telemetry_log(l, false, false, false, log, da, size); } -int nvme_get_new_host_telemetry(int fd, struct nvme_telemetry_log **log, +int nvme_get_new_host_telemetry(nvme_link_t l, struct nvme_telemetry_log **log, enum nvme_telemetry_da da, size_t *size) { - return nvme_check_get_telemetry_log(fd, true, false, false, log, da, size); + return nvme_check_get_telemetry_log(l, true, false, false, log, da, size); } -int nvme_get_lba_status_log(int fd, bool rae, struct nvme_lba_status_log **log) +int nvme_get_lba_status_log(nvme_link_t l, bool rae, struct nvme_lba_status_log **log) { _cleanup_free_ struct nvme_lba_status_log *buf = NULL; __u32 size; @@ -298,7 +322,6 @@ int nvme_get_lba_status_log(int fd, bool rae, struct nvme_lba_status_log **log) int err; struct nvme_get_log_args args = { .args_size = sizeof(args), - .fd = fd, .nsid = NVME_NSID_NONE, .lsp = NVME_LOG_LSP_NONE, .lsi = NVME_LOG_LSI_NONE, @@ -314,7 +337,7 @@ int nvme_get_lba_status_log(int fd, bool rae, struct nvme_lba_status_log **log) if (!buf) return -1; - err = nvme_get_log_lba_status(fd, true, 0, sizeof(*buf), buf); + err = nvme_get_log_lba_status(l, true, 0, sizeof(*buf), buf); if (err) { *log = NULL; return err; @@ -337,7 +360,7 @@ int nvme_get_lba_status_log(int fd, bool rae, struct nvme_lba_status_log **log) args.lid = NVME_LOG_LID_LBA_STATUS; args.log = buf; args.len = size; - err = nvme_get_log_page(fd, 4096, &args); + err = nvme_get_log_page(l, 4096, &args); if (err) { *log = NULL; return err; @@ -348,13 +371,12 @@ int nvme_get_lba_status_log(int fd, bool rae, struct nvme_lba_status_log **log) return 0; } -static int nvme_ns_attachment(int fd, __u32 nsid, __u16 num_ctrls, +static int nvme_ns_attachment(nvme_link_t l, __u32 nsid, __u16 num_ctrls, __u16 *ctrlist, bool attach, __u32 timeout) { struct nvme_ctrl_list cntlist = { 0 }; struct nvme_ns_attach_args args = { .args_size = sizeof(args), - .fd = fd, .nsid = nsid, .sel = NVME_NS_ATTACH_SEL_CTRL_DEATTACH, .ctrlist = &cntlist, @@ -365,20 +387,20 @@ static int nvme_ns_attachment(int fd, __u32 nsid, __u16 num_ctrls, args.sel = NVME_NS_ATTACH_SEL_CTRL_ATTACH; nvme_init_ctrl_list(args.ctrlist, num_ctrls, ctrlist); - return nvme_ns_attach(&args); + return nvme_ns_attach(l, &args); } -int nvme_namespace_attach_ctrls(int fd, __u32 nsid, __u16 num_ctrls, +int nvme_namespace_attach_ctrls(nvme_link_t l, __u32 nsid, __u16 num_ctrls, __u16 *ctrlist) { - return nvme_ns_attachment(fd, nsid, num_ctrls, ctrlist, true, + return nvme_ns_attachment(l, nsid, num_ctrls, ctrlist, true, NVME_DEFAULT_IOCTL_TIMEOUT); } -int nvme_namespace_detach_ctrls(int fd, __u32 nsid, __u16 num_ctrls, +int nvme_namespace_detach_ctrls(nvme_link_t l, __u32 nsid, __u16 num_ctrls, __u16 *ctrlist) { - return nvme_ns_attachment(fd, nsid, num_ctrls, ctrlist, false, + return nvme_ns_attachment(l, nsid, num_ctrls, ctrlist, false, NVME_DEFAULT_IOCTL_TIMEOUT); } @@ -392,7 +414,7 @@ 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(int fd, size_t *analen) +int nvme_get_ana_log_len(nvme_link_t l, size_t *analen) { _cleanup_free_ struct nvme_id_ctrl *ctrl = NULL; int ret; @@ -402,7 +424,7 @@ int nvme_get_ana_log_len(int fd, size_t *analen) errno = ENOMEM; return -1; } - ret = nvme_identify_ctrl(fd, ctrl); + ret = nvme_identify_ctrl(l, ctrl); if (ret) return ret; @@ -410,7 +432,7 @@ int nvme_get_ana_log_len(int fd, size_t *analen) return 0; } -int nvme_get_logical_block_size(int fd, __u32 nsid, int *blksize) +int nvme_get_logical_block_size(nvme_link_t l, __u32 nsid, int *blksize) { _cleanup_free_ struct nvme_id_ns *ns = NULL; __u8 flbas; @@ -421,7 +443,7 @@ int nvme_get_logical_block_size(int fd, __u32 nsid, int *blksize) errno = ENOMEM; return -1; } - ret = nvme_identify_ns(fd, nsid, ns); + ret = nvme_identify_ns(l, nsid, ns); if (ret) return ret; diff --git a/src/nvme/linux.h b/src/nvme/linux.h index e865a8c8a..b39dec0f7 100644 --- a/src/nvme/linux.h +++ b/src/nvme/linux.h @@ -10,6 +10,7 @@ #define _LIBNVME_LINUX_H #include +#include #include #include @@ -22,7 +23,7 @@ /** * nvme_fw_download_seq() - Firmware download sequence - * @fd: File descriptor of nvme device + * @l: Link handle * @size: Total size of the firmware image to transfer * @xfer: Maximum size to send with each partial transfer * @offset: Starting offset to send with this firmware download @@ -31,23 +32,23 @@ * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_fw_download_seq(int fd, __u32 size, __u32 xfer, __u32 offset, +int nvme_fw_download_seq(nvme_link_t l, __u32 size, __u32 xfer, __u32 offset, void *buf); /** * nvme_get_telemetry_max() - Get telemetry limits - * @fd: File descriptor of nvme device + * @l: Link handle * @da: On success return max supported data area * @max_data_tx: On success set to max transfer chunk supported by the controller * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_get_telemetry_max(int fd, enum nvme_telemetry_da *da, size_t *max_data_tx); +int nvme_get_telemetry_max(nvme_link_t l, enum nvme_telemetry_da *da, size_t *max_data_tx); /** * nvme_get_telemetry_log() - Get specified telemetry log - * @fd: File descriptor of nvme device + * @l: Link handle * @create: Generate new host initated telemetry capture * @ctrl: Get controller Initiated log * @rae: Retain asynchronous events @@ -62,12 +63,12 @@ int nvme_get_telemetry_max(int fd, enum nvme_telemetry_da *da, size_t *max_data_ * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_get_telemetry_log(int fd, bool create, bool ctrl, bool rae, size_t max_data_tx, +int nvme_get_telemetry_log(nvme_link_t l, bool create, bool ctrl, bool rae, size_t max_data_tx, enum nvme_telemetry_da da, struct nvme_telemetry_log **log, size_t *size); /** * nvme_get_ctrl_telemetry() - Get controller telemetry log - * @fd: File descriptor of nvme device + * @l: Link handle * @rae: Retain asynchronous events * @log: On success, set to the value of the allocated and retrieved log. * @da: Log page data area, valid values: &enum nvme_telemetry_da @@ -79,12 +80,12 @@ int nvme_get_telemetry_log(int fd, bool create, bool ctrl, bool rae, size_t max_ * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_get_ctrl_telemetry(int fd, bool rae, struct nvme_telemetry_log **log, +int nvme_get_ctrl_telemetry(nvme_link_t l, bool rae, struct nvme_telemetry_log **log, enum nvme_telemetry_da da, size_t *size); /** * nvme_get_host_telemetry() - Get host telemetry log - * @fd: File descriptor of nvme device + * @l: Link handle * @log: On success, set to the value of the allocated and retrieved log. * @da: Log page data area, valid values: &enum nvme_telemetry_da * @size: Ptr to the telemetry log size, so it can be returned @@ -95,12 +96,12 @@ int nvme_get_ctrl_telemetry(int fd, bool rae, struct nvme_telemetry_log **log, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_get_host_telemetry(int fd, struct nvme_telemetry_log **log, +int nvme_get_host_telemetry(nvme_link_t l, struct nvme_telemetry_log **log, enum nvme_telemetry_da da, size_t *size); /** * nvme_get_new_host_telemetry() - Get new host telemetry log - * @fd: File descriptor of nvme device + * @l: Link handle * @log: On success, set to the value of the allocated and retrieved log. * @da: Log page data area, valid values: &enum nvme_telemetry_da * @size: Ptr to the telemetry log size, so it can be returned @@ -111,7 +112,7 @@ int nvme_get_host_telemetry(int fd, struct nvme_telemetry_log **log, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_get_new_host_telemetry(int fd, struct nvme_telemetry_log **log, +int nvme_get_new_host_telemetry(nvme_link_t l, struct nvme_telemetry_log **log, enum nvme_telemetry_da da, size_t *size); /** @@ -126,39 +127,39 @@ size_t nvme_get_ana_log_len_from_id_ctrl(const struct nvme_id_ctrl *id_ctrl, /** * nvme_get_ana_log_len() - Retrieve size of the current ANA log - * @fd: File descriptor of nvme device + * @l: Link handle * @analen: Pointer to where the length will be set on success * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_get_ana_log_len(int fd, size_t *analen); +int nvme_get_ana_log_len(nvme_link_t l, size_t *analen); /** * nvme_get_logical_block_size() - Retrieve block size - * @fd: File descriptor of nvme device + * @l: Link handle * @nsid: Namespace id * @blksize: Pointer to where the block size will be set on success * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_get_logical_block_size(int fd, __u32 nsid, int *blksize); +int nvme_get_logical_block_size(nvme_link_t l, __u32 nsid, int *blksize); /** * nvme_get_lba_status_log() - Retrieve the LBA Status log page - * @fd: File descriptor of the nvme device + * @l: Link handle * @rae: Retain asynchronous events * @log: On success, set to the value of the allocated and retrieved log. * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_get_lba_status_log(int fd, bool rae, struct nvme_lba_status_log **log); +int nvme_get_lba_status_log(nvme_link_t l, bool rae, struct nvme_lba_status_log **log); /** * nvme_namespace_attach_ctrls() - Attach namespace to controller(s) - * @fd: File descriptor of nvme device + * @l: Link handle * @nsid: Namespace ID to attach * @num_ctrls: Number of controllers in ctrlist * @ctrlist: List of controller IDs to perform the attach action @@ -166,11 +167,11 @@ int nvme_get_lba_status_log(int fd, bool rae, struct nvme_lba_status_log **log); * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_namespace_attach_ctrls(int fd, __u32 nsid, __u16 num_ctrls, __u16 *ctrlist); +int nvme_namespace_attach_ctrls(nvme_link_t l, __u32 nsid, __u16 num_ctrls, __u16 *ctrlist); /** * nvme_namespace_detach_ctrls() - Detach namespace from controller(s) - * @fd: File descriptor of nvme device + * @l: Link handle * @nsid: Namespace ID to detach * @num_ctrls: Number of controllers in ctrlist * @ctrlist: List of controller IDs to perform the detach action @@ -178,19 +179,26 @@ int nvme_namespace_attach_ctrls(int fd, __u32 nsid, __u16 num_ctrls, __u16 *ctrl * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_namespace_detach_ctrls(int fd, __u32 nsid, __u16 num_ctrls, __u16 *ctrlist); +int nvme_namespace_detach_ctrls(nvme_link_t l, __u32 nsid, __u16 num_ctrls, __u16 *ctrlist); /** * nvme_open() - Open an nvme controller or namespace device + * @r: &nvme_root_t object * @name: The basename of the device to open * * This will look for the handle in /dev/ and validate the name and filetype * match linux conventions. * - * Return: A file descriptor for the device on a successful open, or -1 with + * Return: A link handle for the device on a successful open, or -1 with * errno set otherwise. */ -int nvme_open(const char *name); +nvme_link_t nvme_open(nvme_root_t r, const char *name); + +/** + * nvme_close() - Close link handle + * @l: Link handle + */ +void nvme_close(nvme_link_t l); /** * enum nvme_hmac_alg - HMAC algorithm @@ -476,7 +484,7 @@ unsigned char *nvme_import_tls_key_versioned(const char *encoded_key, size_t *key_len); /** * nvme_submit_passthru - Low level ioctl wrapper for passthru commands - * @fd: File descriptor of the nvme device + * @l: Link handle * @ioctl_cmd: IOCTL command id * @cmd: Passhtru command * @result: Optional field to return the result @@ -488,12 +496,12 @@ unsigned char *nvme_import_tls_key_versioned(const char *encoded_key, * Return: The value from the ioctl system call (see ioctl documentation) */ __attribute__((weak)) -int nvme_submit_passthru(int fd, unsigned long ioctl_cmd, +int nvme_submit_passthru(nvme_link_t l, unsigned long ioctl_cmd, struct nvme_passthru_cmd *cmd, __u32 *result); /** * nvme_submit_passthru64 - Low level ioctl wrapper for passthru commands - * @fd: File descriptor of the nvme device + * @l: Link handle * @ioctl_cmd: IOCTL command id * @cmd: Passhtru command * @result: Optional field to return the result @@ -505,7 +513,7 @@ int nvme_submit_passthru(int fd, unsigned long ioctl_cmd, * Return: The value from the ioctl system call (see ioctl documentation) */ __attribute__((weak)) -int nvme_submit_passthru64(int fd, unsigned long ioctl_cmd, +int nvme_submit_passthru64(nvme_link_t l, unsigned long ioctl_cmd, struct nvme_passthru_cmd64 *cmd, __u64 *result); diff --git a/src/nvme/private.h b/src/nvme/private.h index ac5949678..c2849ba27 100644 --- a/src/nvme/private.h +++ b/src/nvme/private.h @@ -23,6 +23,20 @@ const char *nvme_slots_sysfs_dir(void); const char *nvme_uuid_ibm_filename(void); const char *nvme_dmi_entries_dir(void); +struct nvme_log { + int fd; + int level; + bool pid; + bool timestamp; +}; + +struct nvme_link { + struct nvme_root *root; + int fd; + + struct nvme_log *log; +}; + struct nvme_path { struct list_node entry; struct list_node nentry; @@ -52,7 +66,7 @@ struct nvme_ns { struct nvme_ctrl *c; struct nvme_ns_head *head; - int fd; + struct nvme_link *l; __u32 nsid; char *name; char *generic_name; @@ -76,7 +90,7 @@ struct nvme_ctrl { struct list_head namespaces; struct nvme_subsystem *s; - int fd; + struct nvme_link *l; char *name; char *sysfs_dir; char *address; @@ -171,13 +185,6 @@ struct nvme_fabric_options { bool trsvcid; }; -struct nvme_log { - int fd; - int level; - bool pid; - bool timestamp; -}; - struct nvme_root { char *config_file; char *application; @@ -198,6 +205,8 @@ int json_update_config(nvme_root_t r, const char *config_file); int json_dump_tree(nvme_root_t r); +nvme_link_t __nvme_open(nvme_root_t r, const char *name); + nvme_ctrl_t __nvme_lookup_ctrl(nvme_subsystem_t s, const char *transport, const char *traddr, const char *host_traddr, const char *host_iface, const char *trsvcid, diff --git a/src/nvme/tree.c b/src/nvme/tree.c index 875fd6f18..e541ce0f0 100644 --- a/src/nvme/tree.c +++ b/src/nvme/tree.c @@ -633,7 +633,7 @@ nvme_path_t nvme_namespace_next_path(nvme_ns_t ns, nvme_path_t p) static void __nvme_free_ns(struct nvme_ns *n) { list_del_init(&n->entry); - nvme_ns_release_fd(n); + nvme_ns_release_link(n); free(n->generic_name); free(n->name); free(n->sysfs_dir); @@ -678,10 +678,10 @@ void nvme_subsystem_release_fds(struct nvme_subsystem *s) struct nvme_ns *n, *_n; nvme_subsystem_for_each_ctrl_safe(s, c, _c) - nvme_ctrl_release_fd(c); + nvme_ctrl_release_link(c); nvme_subsystem_for_each_ns_safe(s, n, _n) - nvme_ns_release_fd(n); + nvme_ns_release_link(n); } /* @@ -1023,25 +1023,27 @@ static int nvme_ctrl_scan_path(nvme_root_t r, struct nvme_ctrl *c, char *name) return 0; } -int nvme_ctrl_get_fd(nvme_ctrl_t c) +nvme_link_t nvme_ctrl_get_link(nvme_ctrl_t c) { - if (c->fd < 0) { - c->fd = nvme_open(c->name); - if (c->fd < 0) - nvme_msg(root_from_ctrl(c), LOG_ERR, + if (!c->l) { + nvme_root_t r = root_from_ctrl(c); + + c->l = nvme_open(r, c->name); + if (!c->l) + nvme_msg(r, LOG_ERR, "Failed to open ctrl %s, errno %d\n", c->name, errno); } - return c->fd; + return c->l; } -void nvme_ctrl_release_fd(nvme_ctrl_t c) +void nvme_ctrl_release_link(nvme_ctrl_t c) { - if (c->fd < 0) + if (!c->l) return; - close(c->fd); - c->fd = -1; + nvme_close(c->l); + c->l = NULL; } nvme_subsystem_t nvme_ctrl_get_subsystem(nvme_ctrl_t c) @@ -1286,7 +1288,7 @@ bool nvme_ctrl_is_unique_discovery_ctrl(nvme_ctrl_t c) int nvme_ctrl_identify(nvme_ctrl_t c, struct nvme_id_ctrl *id) { - return nvme_identify_ctrl(nvme_ctrl_get_fd(c), id); + return nvme_identify_ctrl(nvme_ctrl_get_link(c), id); } nvme_ns_t nvme_ctrl_first_ns(nvme_ctrl_t c) @@ -1313,7 +1315,7 @@ nvme_path_t nvme_ctrl_next_path(nvme_ctrl_t c, nvme_path_t p) do { free(a); (a) = NULL; } while (0) void nvme_deconfigure_ctrl(nvme_ctrl_t c) { - nvme_ctrl_release_fd(c); + nvme_ctrl_release_link(c); FREE_CTRL_ATTR(c->name); FREE_CTRL_ATTR(c->sysfs_dir); FREE_CTRL_ATTR(c->firmware); @@ -1433,7 +1435,7 @@ struct nvme_ctrl *nvme_create_ctrl(nvme_root_t r, errno = ENOMEM; return NULL; } - c->fd = -1; + c->l = NULL; nvmf_default_config(&c->cfg); list_head_init(&c->namespaces); list_head_init(&c->paths); @@ -2049,7 +2051,7 @@ static int nvme_reconfigure_ctrl(nvme_root_t r, nvme_ctrl_t c, const char *path, * It's necesssary to release any resources first because a ctrl * can be reused. */ - nvme_ctrl_release_fd(c); + nvme_ctrl_release_link(c); FREE_CTRL_ATTR(c->name); FREE_CTRL_ATTR(c->sysfs_dir); FREE_CTRL_ATTR(c->firmware); @@ -2073,6 +2075,7 @@ static int nvme_reconfigure_ctrl(nvme_root_t r, nvme_ctrl_t c, const char *path, } closedir(d); + c->l = NULL; c->name = strdup(name); c->sysfs_dir = strdup(path); c->firmware = nvme_get_ctrl_attr(c, "firmware_rev"); @@ -2328,26 +2331,28 @@ static int nvme_bytes_to_lba(nvme_ns_t n, off_t offset, size_t count, return 0; } -int nvme_ns_get_fd(nvme_ns_t n) +nvme_link_t nvme_ns_get_link(nvme_ns_t n) { - if (n->fd < 0) { - n->fd = nvme_open(n->name); - if (n->fd < 0) - nvme_msg(root_from_ns(n), LOG_ERR, + if (!n->l) { + nvme_root_t r = root_from_ns(n); + + n->l = nvme_open(r, n->name); + if (!n->l) + nvme_msg(r, LOG_ERR, "Failed to open ns %s, errno %d\n", n->name, errno); } - return n->fd; + return n->l; } -void nvme_ns_release_fd(nvme_ns_t n) +void nvme_ns_release_link(nvme_ns_t n) { - if (n->fd < 0) + if (!n->l) return; - close(n->fd); - n->fd = -1; + nvme_close(n->l); + n->l = NULL; } nvme_subsystem_t nvme_ns_get_subsystem(nvme_ns_t n) @@ -2442,19 +2447,18 @@ void nvme_ns_get_uuid(nvme_ns_t n, unsigned char out[NVME_UUID_LEN]) int nvme_ns_identify(nvme_ns_t n, struct nvme_id_ns *ns) { - return nvme_identify_ns(nvme_ns_get_fd(n), nvme_ns_get_nsid(n), ns); + return nvme_identify_ns(nvme_ns_get_link(n), nvme_ns_get_nsid(n), ns); } int nvme_ns_identify_descs(nvme_ns_t n, struct nvme_ns_id_desc *descs) { - return nvme_identify_ns_descs(nvme_ns_get_fd(n), nvme_ns_get_nsid(n), descs); + return nvme_identify_ns_descs(nvme_ns_get_link(n), nvme_ns_get_nsid(n), descs); } int nvme_ns_verify(nvme_ns_t n, off_t offset, size_t count) { struct nvme_io_args args = { .args_size = sizeof(args), - .fd = nvme_ns_get_fd(n), .nsid = nvme_ns_get_nsid(n), .control = 0, .dsm = 0, @@ -2474,14 +2478,13 @@ int nvme_ns_verify(nvme_ns_t n, off_t offset, size_t count) if (nvme_bytes_to_lba(n, offset, count, &args.slba, &args.nlb)) return -1; - return nvme_verify(&args); + return nvme_verify(nvme_ns_get_link(n), &args); } int nvme_ns_write_uncorrectable(nvme_ns_t n, off_t offset, size_t count) { struct nvme_io_args args = { .args_size = sizeof(args), - .fd = nvme_ns_get_fd(n), .nsid = nvme_ns_get_nsid(n), .control = 0, .dsm = 0, @@ -2501,14 +2504,13 @@ int nvme_ns_write_uncorrectable(nvme_ns_t n, off_t offset, size_t count) if (nvme_bytes_to_lba(n, offset, count, &args.slba, &args.nlb)) return -1; - return nvme_write_uncorrectable(&args); + return nvme_write_uncorrectable(nvme_ns_get_link(n), &args); } int nvme_ns_write_zeros(nvme_ns_t n, off_t offset, size_t count) { struct nvme_io_args args = { .args_size = sizeof(args), - .fd = nvme_ns_get_fd(n), .nsid = nvme_ns_get_nsid(n), .control = 0, .dsm = 0, @@ -2528,14 +2530,13 @@ int nvme_ns_write_zeros(nvme_ns_t n, off_t offset, size_t count) if (nvme_bytes_to_lba(n, offset, count, &args.slba, &args.nlb)) return -1; - return nvme_write_zeros(&args); + return nvme_write_zeros(nvme_ns_get_link(n), &args); } int nvme_ns_write(nvme_ns_t n, void *buf, off_t offset, size_t count) { struct nvme_io_args args = { .args_size = sizeof(args), - .fd = nvme_ns_get_fd(n), .nsid = nvme_ns_get_nsid(n), .control = 0, .dsm = 0, @@ -2555,14 +2556,13 @@ int nvme_ns_write(nvme_ns_t n, void *buf, off_t offset, size_t count) if (nvme_bytes_to_lba(n, offset, count, &args.slba, &args.nlb)) return -1; - return nvme_write(&args); + return nvme_write(nvme_ns_get_link(n), &args); } int nvme_ns_read(nvme_ns_t n, void *buf, off_t offset, size_t count) { struct nvme_io_args args = { .args_size = sizeof(args), - .fd = nvme_ns_get_fd(n), .nsid = nvme_ns_get_nsid(n), .control = 0, .dsm = 0, @@ -2582,14 +2582,13 @@ int nvme_ns_read(nvme_ns_t n, void *buf, off_t offset, size_t count) if (nvme_bytes_to_lba(n, offset, count, &args.slba, &args.nlb)) return -1; - return nvme_read(&args); + return nvme_read(nvme_ns_get_link(n), &args); } int nvme_ns_compare(nvme_ns_t n, void *buf, off_t offset, size_t count) { struct nvme_io_args args = { .args_size = sizeof(args), - .fd = nvme_ns_get_fd(n), .nsid = nvme_ns_get_nsid(n), .control = 0, .dsm = 0, @@ -2609,12 +2608,12 @@ int nvme_ns_compare(nvme_ns_t n, void *buf, off_t offset, size_t count) if (nvme_bytes_to_lba(n, offset, count, &args.slba, &args.nlb)) return -1; - return nvme_compare(&args); + return nvme_compare(nvme_ns_get_link(n), &args); } int nvme_ns_flush(nvme_ns_t n) { - return nvme_flush(nvme_ns_get_fd(n), nvme_ns_get_nsid(n)); + return nvme_flush(nvme_ns_get_link(n), nvme_ns_get_nsid(n)); } static int nvme_strtou64(const char *str, void *res) @@ -2839,7 +2838,7 @@ static nvme_ns_t nvme_ns_open(const char *sys_path, const char *name) head->sysfs_dir = NULL; n->head = head; - n->fd = -1; + n->l = NULL; n->name = strdup(name); nvme_ns_set_generic_name(n, name); @@ -2849,8 +2848,7 @@ static nvme_ns_t nvme_ns_open(const char *sys_path, const char *name) list_node_init(&n->entry); - nvme_ns_release_fd(n); /* Do not leak fds */ - + nvme_ns_release_link(n); return n; free_ns: diff --git a/src/nvme/tree.h b/src/nvme/tree.h index 10267ccfe..904d2c071 100644 --- a/src/nvme/tree.h +++ b/src/nvme/tree.h @@ -564,26 +564,26 @@ nvme_ns_t nvme_subsystem_next_ns(nvme_subsystem_t s, nvme_ns_t n); p = nvme_namespace_next_path(n, p)) /** - * nvme_ns_get_fd() - Get associated file descriptor + * nvme_ns_get_link() - Get associated link handle * @n: Namespace instance * * libnvme will open() the file (if not already opened) and keep - * an internal copy of the file descriptor. Following calls to - * this API retrieve the internal cached copy of the file - * descriptor. The file will remain opened and the fd will + * an internal copy of the link handle. Following calls to + * this API retrieve the internal cached copy of the link + * handle. The file will remain opened and the device handle will * remain cached until the ns object is deleted or - * nvme_ns_release_fd() is called. + * nvme_ns_release_link() is called. * - * Return: File descriptor associated with @n or -1 + * Return: Link handle with @n or NULL */ -int nvme_ns_get_fd(nvme_ns_t n); +nvme_link_t nvme_ns_get_link(nvme_ns_t n); /** - * nvme_ns_release_fd() - Close fd and clear fd from ns object + * nvme_ns_release_link() - Free link handle from ns object * @n: Namespace instance * */ -void nvme_ns_release_fd(nvme_ns_t n); +void nvme_ns_release_link(nvme_ns_t n); /** * nvme_ns_get_nsid() - NSID of a namespace @@ -882,26 +882,25 @@ nvme_ctrl_t nvme_path_get_ctrl(nvme_path_t p); nvme_ns_t nvme_path_get_ns(nvme_path_t p); /** - * nvme_ctrl_get_fd() - Get associated file descriptor + * nvme_ctrl_get_link() - Get associated link handle * @c: Controller instance * - * libnvme will open() the file (if not already opened) and keep - * an internal copy of the file descriptor. Following calls to - * this API retrieve the internal cached copy of the file - * descriptor. The file will remain opened and the fd will - * remain cached until the controller object is deleted or - * nvme_ctrl_release_fd() is called. + * libnvme will open() the device (if not already opened) and keep an + * internal copy of the link handle. Following calls to this API retrieve + * the internal cached copy of the link handle. The file will remain + * opened and the handle will remain cached until the controller object + * is deleted or nvme_ctrl_release_link() is called. * - * Return: File descriptor associated with @c or -1 + * Return: Link handle associated with @c or NULL */ -int nvme_ctrl_get_fd(nvme_ctrl_t c); +nvme_link_t nvme_ctrl_get_link(nvme_ctrl_t c); /** - * nvme_ctrl_release_fd() - Close fd and clear fd from controller object + * nvme_ctrl_release_link() - Free link handle from controller object * @c: Controller instance * */ -void nvme_ctrl_release_fd(nvme_ctrl_t c); +void nvme_ctrl_release_link(nvme_ctrl_t c); /** * nvme_ctrl_get_name() - sysfs name of a controller diff --git a/src/nvme/util.c b/src/nvme/util.c index cde9d67ea..ee9cacd57 100644 --- a/src/nvme/util.c +++ b/src/nvme/util.c @@ -646,7 +646,7 @@ const char *nvme_errno_to_string(int status) } #ifdef HAVE_NETDB -char *hostname2traddr(struct nvme_root *r, const char *traddr) +char *hostname2traddr(nvme_root_t r, const char *traddr) { struct addrinfo *host_info, hints = {.ai_family = AF_UNSPEC}; char addrstr[NVMF_TRADDR_SIZE]; @@ -690,9 +690,9 @@ char *hostname2traddr(struct nvme_root *r, const char *traddr) return ret_traddr; } #else /* HAVE_NETDB */ -char *hostname2traddr(struct nvme_root *r, const char *traddr) +char *hostname2traddr(nvme_root_t r, const char *traddr) { - nvme_msg(NULL, LOG_ERR, "No support for hostname IP address resolution; " \ + nvme_msg(r, LOG_ERR, "No support for hostname IP address resolution; " \ "recompile with libnss support.\n"); errno = -ENOTSUP; diff --git a/test/ioctl/ana.c b/test/ioctl/ana.c index 1e2cffb79..7db358939 100644 --- a/test/ioctl/ana.c +++ b/test/ioctl/ana.c @@ -11,18 +11,21 @@ #include #include "mock.h" +#include "nvme/api-types.h" #include "util.h" #define TEST_FD 0xFD #define PDU_SIZE NVME_LOG_PAGE_PDU_SIZE +static nvme_link_t test_link; + static void test_no_retries(void) { struct nvme_ana_log log; __u32 len = sizeof(log); /* max_retries = 0 is nonsensical */ - check(nvme_get_ana_log_atomic(TEST_FD, false, false, 0, &log, &len), + check(nvme_get_ana_log_atomic(test_link, false, false, 0, &log, &len), "get log page succeeded"); check(errno == EINVAL, "unexpected error: %m"); } @@ -33,7 +36,7 @@ static void test_len_too_short(void) __u32 len = sizeof(log) - 1; /* Provided buffer doesn't have enough space to read the header */ - check(nvme_get_ana_log_atomic(TEST_FD, false, false, 1, &log, &len), + check(nvme_get_ana_log_atomic(test_link, false, false, 1, &log, &len), "get log page succeeded"); check(errno == ENOSPC, "unexpected error: %m"); } @@ -56,7 +59,7 @@ static void test_no_groups(void) arbitrary(&header, sizeof(header)); header.ngrps = cpu_to_le16(0); set_mock_admin_cmds(&mock_admin_cmd, 1); - check(!nvme_get_ana_log_atomic(TEST_FD, false, false, 1, &log, &len), + check(!nvme_get_ana_log_atomic(test_link, false, false, 1, &log, &len), "get log page failed: %m"); end_mock_cmds(); cmp(&log, &header, sizeof(header), "incorrect header"); @@ -94,7 +97,7 @@ static void test_one_group_rgo(void) memcpy(log_page, &header, sizeof(header)); memcpy(log_page + sizeof(header), &group, sizeof(group)); set_mock_admin_cmds(&mock_admin_cmd, 1); - check(!nvme_get_ana_log_atomic(TEST_FD, true, false, 1, log, &len), + check(!nvme_get_ana_log_atomic(test_link, true, false, 1, log, &len), "get log page failed: %m"); end_mock_cmds(); cmp(log, log_page, sizeof(log_page), "incorrect log page"); @@ -135,7 +138,7 @@ static void test_one_group_nsids(void) memcpy(log_page + sizeof(header), &group, sizeof(group)); memcpy(log_page + sizeof(header) + sizeof(group), nsids, sizeof(nsids)); set_mock_admin_cmds(&mock_admin_cmd, 1); - check(!nvme_get_ana_log_atomic(TEST_FD, false, false, 1, log, &len), + check(!nvme_get_ana_log_atomic(test_link, false, false, 1, log, &len), "get log page failed: %m"); end_mock_cmds(); cmp(log, log_page, sizeof(log_page), "incorrect log page"); @@ -176,7 +179,7 @@ static void test_multiple_groups_rgo(void) memcpy(log_page, &header, sizeof(header)); memcpy(log_page + sizeof(header), groups, sizeof(groups)); set_mock_admin_cmds(&mock_admin_cmd, 1); - check(!nvme_get_ana_log_atomic(TEST_FD, true, true, 1, log, &len), + check(!nvme_get_ana_log_atomic(test_link, true, true, 1, log, &len), "get log page failed: %m"); end_mock_cmds(); cmp(log, log_page, sizeof(log_page), "incorrect log page"); @@ -242,7 +245,7 @@ static void test_multiple_groups_nsids(void) sizeof(group2) + sizeof(nsids2) + sizeof(group3), nsids3, sizeof(nsids3)); set_mock_admin_cmds(&mock_admin_cmd, 1); - check(!nvme_get_ana_log_atomic(TEST_FD, false, false, 1, log, &len), + check(!nvme_get_ana_log_atomic(test_link, false, false, 1, log, &len), "get log page failed: %m"); end_mock_cmds(); cmp(log, log_page, sizeof(log_page), "incorrect log page"); @@ -314,7 +317,7 @@ static void test_long_log(void) memcpy(log_page + sizeof(header), &group, sizeof(group)); memcpy(log_page + sizeof(header) + sizeof(group), nsids, sizeof(nsids)); set_mock_admin_cmds(mock_admin_cmds, ARRAY_SIZE(mock_admin_cmds)); - check(!nvme_get_ana_log_atomic(TEST_FD, false, true, 1, log, &len), + check(!nvme_get_ana_log_atomic(test_link, false, true, 1, log, &len), "get log page failed: %m"); end_mock_cmds(); cmp(log, log_page, sizeof(log_page), "incorrect log page"); @@ -390,7 +393,7 @@ static void test_chgcnt_change(void) memcpy(log_page2, &header2, sizeof(header2)); memcpy(log_page2 + sizeof(header2), &group2, sizeof(group2)); set_mock_admin_cmds(mock_admin_cmds, ARRAY_SIZE(mock_admin_cmds)); - check(!nvme_get_ana_log_atomic(TEST_FD, true, true, 2, log, &len), + check(!nvme_get_ana_log_atomic(test_link, true, true, 2, log, &len), "get log page failed: %m"); end_mock_cmds(); cmp(log, log_page2, sizeof(log_page2), "incorrect log page"); @@ -472,7 +475,7 @@ static void test_buffer_too_short_chgcnt_change(void) memcpy(log_page2 + sizeof(header2) + sizeof(group2), &nsid2, sizeof(nsid2)); set_mock_admin_cmds(mock_admin_cmds, ARRAY_SIZE(mock_admin_cmds)); - check(!nvme_get_ana_log_atomic(TEST_FD, false, false, 2, log, &len), + check(!nvme_get_ana_log_atomic(test_link, false, false, 2, log, &len), "get log page failed: %m"); end_mock_cmds(); cmp(log, log_page2, sizeof(log_page2), "incorrect log page"); @@ -568,7 +571,7 @@ static void test_chgcnt_max_retries(void) memcpy(log_page2 + sizeof(header2) + sizeof(group), nsids, sizeof(nsids)); set_mock_admin_cmds(mock_admin_cmds, ARRAY_SIZE(mock_admin_cmds)); - check(nvme_get_ana_log_atomic(TEST_FD, false, true, 2, log, &len) == -1, + check(nvme_get_ana_log_atomic(test_link, false, true, 2, log, &len) == -1, "get log page succeeded"); end_mock_cmds(); check(errno == EAGAIN, "unexpected error: %m"); @@ -609,7 +612,7 @@ static void test_buffer_too_short(void) memcpy(log_page + sizeof(header), &group, sizeof(group)); memcpy(log_page + sizeof(header) + sizeof(group), nsids, sizeof(nsids)); set_mock_admin_cmds(&mock_admin_cmd, 1); - check(nvme_get_ana_log_atomic(TEST_FD, false, true, 2, log, &len) == -1, + check(nvme_get_ana_log_atomic(test_link, false, true, 2, log, &len) == -1, "get log page succeeded"); end_mock_cmds(); check(errno == ENOSPC, "unexpected error: %m"); @@ -628,7 +631,11 @@ static void run_test(const char *test_name, void (*test_fn)(void)) int main(void) { + nvme_root_t r = nvme_create_root(stdout, DEFAULT_LOGLEVEL); + set_mock_fd(TEST_FD); + test_link = nvme_open(r, "NVME_TEST_FD"); + RUN_TEST(no_retries); RUN_TEST(len_too_short); RUN_TEST(no_groups); @@ -641,4 +648,6 @@ int main(void) RUN_TEST(buffer_too_short_chgcnt_change); RUN_TEST(chgcnt_max_retries); RUN_TEST(buffer_too_short); + + nvme_free_root(r); } diff --git a/test/ioctl/discovery.c b/test/ioctl/discovery.c index 457acb0a8..aedf48fab 100644 --- a/test/ioctl/discovery.c +++ b/test/ioctl/discovery.c @@ -16,6 +16,8 @@ #define TEST_FD 0xFD #define HEADER_LEN 20 +static nvme_link_t test_link; + static void arbitrary_ascii_string(size_t max_len, char *str, char *log_str) { size_t len; @@ -403,7 +405,7 @@ static void test_genctr_error(nvme_ctrl_t c) static void run_test(const char *test_name, void (*test_fn)(nvme_ctrl_t)) { - struct nvme_ctrl c = {.fd = TEST_FD}; + struct nvme_ctrl c = { .l = test_link }; printf("Running test %s...", test_name); fflush(stdout); @@ -417,7 +419,11 @@ static void run_test(const char *test_name, void (*test_fn)(nvme_ctrl_t)) int main(void) { + nvme_root_t r = nvme_create_root(stdout, DEFAULT_LOGLEVEL); + set_mock_fd(TEST_FD); + test_link = nvme_open(r, "NVME_TEST_FD"); + RUN_TEST(no_entries); RUN_TEST(four_entries); RUN_TEST(five_entries); @@ -426,4 +432,6 @@ int main(void) RUN_TEST(header_error); RUN_TEST(entries_error); RUN_TEST(genctr_error); + + nvme_free_root(r); } diff --git a/test/ioctl/features.c b/test/ioctl/features.c index f26982c8a..f44d50087 100644 --- a/test/ioctl/features.c +++ b/test/ioctl/features.c @@ -22,6 +22,8 @@ #define TEST_SEL NVME_GET_FEATURES_SEL_SAVED #define TEST_SC NVME_SC_INVALID_FIELD +static nvme_link_t test_link; + static void test_set_features(void) { uint32_t result = 0; @@ -30,7 +32,6 @@ static void test_set_features(void) .result = &result, .data = data, .args_size = sizeof(args), - .fd = TEST_FD, .timeout = TEST_TIMEOUT, .nsid = TEST_NSID, .cdw11 = TEST_CDW11, @@ -61,7 +62,7 @@ static void test_set_features(void) arbitrary(data, sizeof(data)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_set_features(&args); + err = nvme_set_features(test_link, &args); end_mock_cmds(); check(err == 0, "set features returned error %d, errno %m", err); check(result == TEST_RESULT, @@ -76,7 +77,6 @@ static void test_get_features(void) .result = &result, .data = get_data, .args_size = sizeof(args), - .fd = TEST_FD, .timeout = TEST_TIMEOUT, .nsid = TEST_NSID, .sel = TEST_SEL, @@ -100,7 +100,7 @@ static void test_get_features(void) arbitrary(data, sizeof(data)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_get_features(&args); + err = nvme_get_features(test_link, &args); end_mock_cmds(); check(err == 0, "get features returned error %d, errno %m", err); check(result == TEST_RESULT, @@ -126,7 +126,7 @@ static void test_set_features_data(void) arbitrary(data, sizeof(data)); set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_set_features_data( - TEST_FD, TEST_FID, TEST_NSID, TEST_CDW11, false, + test_link, TEST_FID, TEST_NSID, TEST_CDW11, false, sizeof(data), data, &result); end_mock_cmds(); check(err == 0, "set features returned error %d, errno %m", err); @@ -151,7 +151,7 @@ static void test_get_features_data(void) arbitrary(data, sizeof(data)); set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_get_features_data( - TEST_FD, TEST_FID, TEST_NSID, sizeof(data), get_data, &result); + test_link, TEST_FID, TEST_NSID, sizeof(data), get_data, &result); end_mock_cmds(); check(err == 0, "set features returned error %d, errno %m", err); check(result == TEST_RESULT, @@ -174,7 +174,7 @@ static void test_set_features_simple(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_set_features_simple( - TEST_FD, TEST_FID, TEST_NSID, TEST_CDW11, true, &result); + test_link, TEST_FID, TEST_NSID, TEST_CDW11, true, &result); end_mock_cmds(); check(err == 0, "set features returned error %d, errno %m", err); check(result == TEST_RESULT, @@ -193,7 +193,7 @@ static void test_get_features_simple(void) int err; set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_get_features_simple(TEST_FD, TEST_FID, TEST_NSID, &result); + err = nvme_get_features_simple(test_link, TEST_FID, TEST_NSID, &result); end_mock_cmds(); check(err == 0, "set features returned error %d, errno %m", err); check(result == TEST_RESULT, @@ -214,7 +214,7 @@ static void test_set_arbitration(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_set_features_arbitration( - TEST_FD, AB, LPW, MPW, HPW, false, &result); + test_link, AB, LPW, MPW, HPW, false, &result); end_mock_cmds(); check(err == 0, "set features returned error %d, errno %m", err); check(result == TEST_RESULT, @@ -232,7 +232,7 @@ static void test_get_arbitration(void) int err; set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_get_features_arbitration(TEST_FD, TEST_SEL, &result); + err = nvme_get_features_arbitration(test_link, TEST_SEL, &result); end_mock_cmds(); check(err == 0, "get features returned error %d, errno %m", err); check(result == TEST_RESULT, @@ -253,7 +253,7 @@ static void test_set_power_mgmt(void) int err; set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_set_features_power_mgmt(TEST_FD, PS, WH, true, &result); + err = nvme_set_features_power_mgmt(test_link, PS, WH, true, &result); end_mock_cmds(); check(err == 0, "set features returned error %d, errno %m", err); check(result == TEST_RESULT, @@ -271,7 +271,7 @@ static void test_get_power_mgmt(void) int err; set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_get_features_power_mgmt(TEST_FD, TEST_SEL, &result); + err = nvme_get_features_power_mgmt(test_link, TEST_SEL, &result); end_mock_cmds(); check(err == 0, "get features returned error %d, errno %m", err); check(result == TEST_RESULT, @@ -297,7 +297,7 @@ static void test_set_lba_range(void) arbitrary(&range_types, sizeof(range_types)); set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_set_features_lba_range( - TEST_FD, TEST_NSID, NUM, false, &range_types, &result); + test_link, TEST_NSID, NUM, false, &range_types, &result); end_mock_cmds(); check(err == 0, "set features returned error %d, errno %m", err); check(result == TEST_RESULT, @@ -321,7 +321,7 @@ static void test_get_lba_range(void) arbitrary(&range_types, sizeof(range_types)); set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_get_features_lba_range( - TEST_FD, TEST_SEL, TEST_NSID, &get_range_types, &result); + test_link, TEST_SEL, TEST_NSID, &get_range_types, &result); end_mock_cmds(); check(err == 0, "get features returned error %d, errno %m", err); check(result == TEST_RESULT, @@ -348,7 +348,7 @@ static void test_set_temp_thresh(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_set_features_temp_thresh( - TEST_FD, TMPTH, TMPSEL, THSEL, 0, true, &result); + test_link, TMPTH, TMPSEL, THSEL, 0, true, &result); end_mock_cmds(); check(err == 0, "set features returned error %d, errno %m", err); check(result == TEST_RESULT, @@ -371,7 +371,7 @@ static void test_get_temp_thresh(void) int err; set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_get_features_temp_thresh(TEST_FD, TEST_SEL, 0, 0, &result); + err = nvme_get_features_temp_thresh(test_link, TEST_SEL, 0, 0, &result); end_mock_cmds(); check(err == 0, "get features returned error %d, errno %m", err); check(result == TEST_RESULT, @@ -394,7 +394,7 @@ static void test_set_err_recovery(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_set_features_err_recovery( - TEST_FD, TEST_NSID, TLER, true, false, &result); + test_link, TEST_NSID, TLER, true, false, &result); end_mock_cmds(); check(err == 0, "set features returned error %d, errno %m", err); check(result == TEST_RESULT, @@ -414,7 +414,7 @@ static void test_get_err_recovery(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_get_features_err_recovery( - TEST_FD, TEST_SEL, TEST_NSID, &result); + test_link, TEST_SEL, TEST_NSID, &result); end_mock_cmds(); check(err == 0, "get features returned error %d, errno %m", err); check(result == TEST_RESULT, @@ -434,7 +434,7 @@ static void test_set_volatile_wc(void) int err; set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_set_features_volatile_wc(TEST_FD, true, true, &result); + err = nvme_set_features_volatile_wc(test_link, true, true, &result); end_mock_cmds(); check(err == 0, "set features returned error %d, errno %m", err); check(result == TEST_RESULT, @@ -453,7 +453,7 @@ static void test_get_volatile_wc(void) int err; set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_get_features_volatile_wc(TEST_FD, TEST_SEL, &result); + err = nvme_get_features_volatile_wc(test_link, TEST_SEL, &result); end_mock_cmds(); check(err == 0, "get features returned error %d, errno %m", err); check(result == TEST_RESULT, @@ -471,7 +471,7 @@ static void test_get_num_queues(void) int err; set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_get_features_num_queues(TEST_FD, TEST_SEL, &result); + err = nvme_get_features_num_queues(test_link, TEST_SEL, &result); end_mock_cmds(); check(err == 0, "get features returned error %d, errno %m", err); check(result == TEST_RESULT, @@ -492,7 +492,7 @@ static void test_set_irq_coalesce(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_set_features_irq_coalesce( - TEST_FD, THR, TIME, false, &result); + test_link, THR, TIME, false, &result); end_mock_cmds(); check(err == 0, "set features returned error %d, errno %m", err); check(result == TEST_RESULT, @@ -510,7 +510,7 @@ static void test_get_irq_coalesce(void) int err; set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_get_features_irq_coalesce(TEST_FD, TEST_SEL, &result); + err = nvme_get_features_irq_coalesce(test_link, TEST_SEL, &result); end_mock_cmds(); check(err == 0, "get features returned error %d, errno %m", err); check(result == TEST_RESULT, @@ -532,7 +532,7 @@ static void test_set_irq_config(void) int err; set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_set_features_irq_config(TEST_FD, IV, true, true, &result); + err = nvme_set_features_irq_config(test_link, IV, true, true, &result); end_mock_cmds(); check(err == 0, "set features returned error %d, errno %m", err); check(result == TEST_RESULT, @@ -552,7 +552,7 @@ static void test_get_irq_config(void) int err; set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_get_features_irq_config(TEST_FD, TEST_SEL, IV, &result); + err = nvme_get_features_irq_config(test_link, TEST_SEL, IV, &result); end_mock_cmds(); check(err == 0, "get features returned error %d, errno %m", err); check(result == TEST_RESULT, @@ -571,7 +571,7 @@ static void test_set_write_atomic(void) int err; set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_set_features_write_atomic(TEST_FD, true, false, &result); + err = nvme_set_features_write_atomic(test_link, true, false, &result); end_mock_cmds(); check(err == 0, "set features returned error %d, errno %m", err); check(result == TEST_RESULT, @@ -589,7 +589,7 @@ static void test_get_write_atomic(void) int err; set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_get_features_write_atomic(TEST_FD, TEST_SEL, &result); + err = nvme_get_features_write_atomic(test_link, TEST_SEL, &result); end_mock_cmds(); check(err == 0, "get features returned error %d, errno %m", err); check(result == TEST_RESULT, @@ -610,7 +610,7 @@ static void test_set_async_event(void) int err; set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_set_features_async_event(TEST_FD, EVENTS, true, &result); + err = nvme_set_features_async_event(test_link, EVENTS, true, &result); end_mock_cmds(); check(err == 0, "set features returned error %d, errno %m", err); check(result == TEST_RESULT, @@ -628,7 +628,7 @@ static void test_get_async_event(void) int err; set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_get_features_async_event(TEST_FD, TEST_SEL, &result); + err = nvme_get_features_async_event(test_link, TEST_SEL, &result); end_mock_cmds(); check(err == 0, "get features returned error %d, errno %m", err); check(result == TEST_RESULT, @@ -651,7 +651,7 @@ static void test_set_auto_pst(void) arbitrary(&apst, sizeof(apst)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_set_features_auto_pst(TEST_FD, true, false, &apst, &result); + err = nvme_set_features_auto_pst(test_link, true, false, &apst, &result); end_mock_cmds(); check(err == 0, "set features returned error %d, errno %m", err); check(result == TEST_RESULT, @@ -673,7 +673,7 @@ static void test_get_auto_pst(void) arbitrary(&apst, sizeof(apst)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_get_features_auto_pst(TEST_FD, TEST_SEL, &get_apst, &result); + err = nvme_get_features_auto_pst(test_link, TEST_SEL, &get_apst, &result); end_mock_cmds(); check(err == 0, "get features returned error %d, errno %m", err); check(result == TEST_RESULT, @@ -697,7 +697,7 @@ static void test_get_host_mem_buf(void) arbitrary(&attrs, sizeof(attrs)); set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_get_features_host_mem_buf( - TEST_FD, TEST_SEL, &get_attrs, &result); + test_link, TEST_SEL, &get_attrs, &result); end_mock_cmds(); check(err == 0, "get features returned error %d, errno %m", err); check(result == TEST_RESULT, @@ -724,7 +724,7 @@ static void test_set_timestamp(void) int err; set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_set_features_timestamp(TEST_FD, true, timestamp); + err = nvme_set_features_timestamp(test_link, true, timestamp); end_mock_cmds(); check(err == 0, "set features returned error %d, errno %m", err); } @@ -742,7 +742,7 @@ static void test_get_timestamp(void) arbitrary(&ts, sizeof(ts)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_get_features_timestamp(TEST_FD, TEST_SEL, &get_ts); + err = nvme_get_features_timestamp(test_link, TEST_SEL, &get_ts); end_mock_cmds(); check(err == 0, "get features returned error %d, errno %m", err); cmp(&get_ts, &ts, sizeof(ts), "incorrect timestamp"); @@ -759,7 +759,7 @@ static void test_get_kato(void) int err; set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_get_features_kato(TEST_FD, TEST_SEL, &result); + err = nvme_get_features_kato(test_link, TEST_SEL, &result); end_mock_cmds(); check(err == 0, "get features returned error %d, errno %m", err); check(result == TEST_RESULT, @@ -779,7 +779,7 @@ static void test_set_hctm(void) int err; set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_set_features_hctm(TEST_FD, TMT2, TMT1, false, &result); + err = nvme_set_features_hctm(test_link, TMT2, TMT1, false, &result); end_mock_cmds(); check(err == 0, "set features returned error %d, errno %m", err); check(result == TEST_RESULT, @@ -797,7 +797,7 @@ static void test_get_hctm(void) int err; set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_get_features_hctm(TEST_FD, TEST_SEL, &result); + err = nvme_get_features_hctm(test_link, TEST_SEL, &result); end_mock_cmds(); check(err == 0, "get features returned error %d, errno %m", err); check(result == TEST_RESULT, @@ -817,7 +817,7 @@ static void test_set_nopsc(void) int err; set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_set_features_nopsc(TEST_FD, true, true, &result); + err = nvme_set_features_nopsc(test_link, true, true, &result); end_mock_cmds(); check(err == 0, "set features returned error %d, errno %m", err); check(result == TEST_RESULT, @@ -835,7 +835,7 @@ static void test_get_nopsc(void) int err; set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_get_features_nopsc(TEST_FD, TEST_SEL, &result); + err = nvme_get_features_nopsc(test_link, TEST_SEL, &result); end_mock_cmds(); check(err == 0, "get features returned error %d, errno %m", err); check(result == TEST_RESULT, @@ -857,7 +857,7 @@ static void test_set_rrl(void) int err; set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_set_features_rrl(TEST_FD, RRL, NVMSETID, false, &result); + err = nvme_set_features_rrl(test_link, RRL, NVMSETID, false, &result); end_mock_cmds(); check(err == 0, "set features returned error %d, errno %m", err); check(result == TEST_RESULT, @@ -876,7 +876,7 @@ static void test_get_rrl(void) int err; set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_get_features_rrl(TEST_FD, TEST_SEL, &result); + err = nvme_get_features_rrl(test_link, TEST_SEL, &result); end_mock_cmds(); check(err == 0, "get features returned error %d, errno %m", err); check(result == TEST_RESULT, @@ -903,7 +903,7 @@ static void test_set_plm_config(void) arbitrary(&config, sizeof(config)); set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_set_features_plm_config( - TEST_FD, true, NVMSETID, true, &config, &result); + test_link, true, NVMSETID, true, &config, &result); end_mock_cmds(); check(err == 0, "set features returned error %d, errno %m", err); check(result == TEST_RESULT, @@ -928,7 +928,7 @@ static void test_get_plm_config(void) arbitrary(&config, sizeof(config)); set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_get_features_plm_config( - TEST_FD, TEST_SEL, NVMSETID, &get_config, &result); + test_link, TEST_SEL, NVMSETID, &get_config, &result); end_mock_cmds(); check(err == 0, "get features returned error %d, errno %m", err); check(result == TEST_RESULT, @@ -952,7 +952,7 @@ static void test_set_plm_window(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_set_features_plm_window( - TEST_FD, SEL, NVMSETID, false, &result); + test_link, SEL, NVMSETID, false, &result); end_mock_cmds(); check(err == 0, "set features returned error %d, errno %m", err); check(result == TEST_RESULT, @@ -973,7 +973,7 @@ static void test_get_plm_window(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_get_features_plm_window( - TEST_FD, TEST_SEL, NVMSETID, &result); + test_link, TEST_SEL, NVMSETID, &result); end_mock_cmds(); check(err == 0, "get features returned error %d, errno %m", err); check(result == TEST_RESULT, @@ -995,7 +995,7 @@ static void test_set_lba_sts_interval(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_set_features_lba_sts_interval( - TEST_FD, LSIRI, LSIPI, true, &result); + test_link, LSIRI, LSIPI, true, &result); end_mock_cmds(); check(err == 0, "set features returned error %d, errno %m", err); check(result == TEST_RESULT, @@ -1013,7 +1013,7 @@ static void test_get_lba_sts_interval(void) int err; set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_get_features_lba_sts_interval(TEST_FD, TEST_SEL, &result); + err = nvme_get_features_lba_sts_interval(test_link, TEST_SEL, &result); end_mock_cmds(); check(err == 0, "get features returned error %d, errno %m", err); check(result == TEST_RESULT, @@ -1034,7 +1034,7 @@ static void test_set_host_behavior(void) arbitrary(&behavior, sizeof(behavior)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_set_features_host_behavior(TEST_FD, true, &behavior); + err = nvme_set_features_host_behavior(test_link, true, &behavior); end_mock_cmds(); check(err == 0, "set features returned error %d, errno %m", err); } @@ -1055,7 +1055,7 @@ static void test_get_host_behavior(void) arbitrary(&behavior, sizeof(behavior)); set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_get_features_host_behavior( - TEST_FD, TEST_SEL, &get_behavior, &result); + test_link, TEST_SEL, &get_behavior, &result); end_mock_cmds(); check(err == 0, "get features returned error %d, errno %m", err); check(result == TEST_RESULT, @@ -1075,7 +1075,7 @@ static void test_set_sanitize(void) int err; set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_set_features_sanitize(TEST_FD, true, false, &result); + err = nvme_set_features_sanitize(test_link, true, false, &result); end_mock_cmds(); check(err == 0, "set features returned error %d, errno %m", err); check(result == TEST_RESULT, @@ -1093,7 +1093,7 @@ static void test_get_sanitize(void) int err; set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_get_features_sanitize(TEST_FD, TEST_SEL, &result); + err = nvme_get_features_sanitize(test_link, TEST_SEL, &result); end_mock_cmds(); check(err == 0, "get features returned error %d, errno %m", err); check(result == TEST_RESULT, @@ -1116,7 +1116,7 @@ static void test_set_endurance_evt_cfg(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_set_features_endurance_evt_cfg( - TEST_FD, ENDGID, EGWARN, true, &result); + test_link, ENDGID, EGWARN, true, &result); end_mock_cmds(); check(err == 0, "set features returned error %d, errno %m", err); check(result == TEST_RESULT, @@ -1137,7 +1137,7 @@ static void test_get_endurance_event_cfg(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_get_features_endurance_event_cfg( - TEST_FD, TEST_SEL, ENDGID, &result); + test_link, TEST_SEL, ENDGID, &result); end_mock_cmds(); check(err == 0, "get features returned error %d, errno %m", err); check(result == TEST_RESULT, @@ -1155,7 +1155,7 @@ static void test_set_iocs_profile(void) int err; set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_set_features_iocs_profile(TEST_FD, IOCSI, false); + err = nvme_set_features_iocs_profile(test_link, IOCSI, false); end_mock_cmds(); check(err == 0, "set features returned error %d, errno %m", err); } @@ -1171,7 +1171,7 @@ static void test_get_iocs_profile(void) int err; set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_get_features_iocs_profile(TEST_FD, TEST_SEL, &result); + err = nvme_get_features_iocs_profile(test_link, TEST_SEL, &result); end_mock_cmds(); check(err == 0, "get features returned error %d, errno %m", err); check(result == TEST_RESULT, @@ -1192,7 +1192,7 @@ static void test_set_sw_progress(void) int err; set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_set_features_sw_progress(TEST_FD, PBSLC, true, &result); + err = nvme_set_features_sw_progress(test_link, PBSLC, true, &result); end_mock_cmds(); check(err == 0, "set features returned error %d, errno %m", err); check(result == TEST_RESULT, @@ -1210,7 +1210,7 @@ static void test_get_sw_progress(void) int err; set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_get_features_sw_progress(TEST_FD, TEST_SEL, &result); + err = nvme_get_features_sw_progress(test_link, TEST_SEL, &result); end_mock_cmds(); check(err == 0, "get features returned error %d, errno %m", err); check(result == TEST_RESULT, @@ -1232,7 +1232,7 @@ static void test_set_host_id(void) arbitrary(hostid, sizeof(hostid)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_set_features_host_id(TEST_FD, false, true, hostid); + err = nvme_set_features_host_id(test_link, false, true, hostid); end_mock_cmds(); check(err == 0, "set features returned error %d, errno %m", err); } @@ -1252,7 +1252,7 @@ static void test_set_host_id_extended(void) arbitrary(hostid, sizeof(hostid)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_set_features_host_id(TEST_FD, true, false, hostid); + err = nvme_set_features_host_id(test_link, true, false, hostid); end_mock_cmds(); check(err == 0, "set features returned error %d, errno %m", err); } @@ -1272,7 +1272,7 @@ static void test_get_host_id(void) arbitrary(hostid, sizeof(hostid)); set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_get_features_host_id( - TEST_FD, TEST_SEL, false, sizeof(hostid), get_hostid); + test_link, TEST_SEL, false, sizeof(hostid), get_hostid); end_mock_cmds(); check(err == 0, "get features returned error %d, errno %m", err); cmp(get_hostid, hostid, sizeof(hostid), "incorrect host identifier"); @@ -1294,7 +1294,7 @@ static void test_get_host_id_extended(void) arbitrary(hostid, sizeof(hostid)); set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_get_features_host_id( - TEST_FD, TEST_SEL, true, sizeof(hostid), get_hostid); + test_link, TEST_SEL, true, sizeof(hostid), get_hostid); end_mock_cmds(); check(err == 0, "get features returned error %d, errno %m", err); cmp(get_hostid, hostid, sizeof(hostid), "incorrect host identifier"); @@ -1316,7 +1316,7 @@ static void test_set_resv_mask(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_set_features_resv_mask( - TEST_FD, TEST_NSID, MASK, true, &result); + test_link, TEST_NSID, MASK, true, &result); end_mock_cmds(); check(err == 0, "set features returned error %d, errno %m", err); check(result == TEST_RESULT, @@ -1336,7 +1336,7 @@ static void test_get_resv_mask(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_get_features_resv_mask( - TEST_FD, TEST_SEL, TEST_NSID, &result); + test_link, TEST_SEL, TEST_NSID, &result); end_mock_cmds(); check(err == 0, "get features returned error %d, errno %m", err); check(result == TEST_RESULT, @@ -1357,7 +1357,7 @@ static void test_set_resv_persist(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_set_features_resv_persist( - TEST_FD, TEST_NSID, true, false, &result); + test_link, TEST_NSID, true, false, &result); end_mock_cmds(); check(err == 0, "set features returned error %d, errno %m", err); check(result == TEST_RESULT, @@ -1377,7 +1377,7 @@ static void test_get_resv_persist(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_get_features_resv_persist( - TEST_FD, TEST_SEL, TEST_NSID, &result); + test_link, TEST_SEL, TEST_NSID, &result); end_mock_cmds(); check(err == 0, "get features returned error %d, errno %m", err); check(result == TEST_RESULT, @@ -1401,7 +1401,7 @@ static void test_set_write_protect(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_set_features_write_protect( - TEST_FD, TEST_NSID, STATE, true, &result); + test_link, TEST_NSID, STATE, true, &result); end_mock_cmds(); check(err == 0, "set features returned error %d, errno %m", err); check(result == TEST_RESULT, @@ -1421,7 +1421,7 @@ static void test_get_write_protect(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_get_features_write_protect( - TEST_FD, TEST_NSID, TEST_SEL, &result); + test_link, TEST_NSID, TEST_SEL, &result); end_mock_cmds(); check(err == 0, "get features returned error %d, errno %m", err); check(result == TEST_RESULT, @@ -1447,7 +1447,7 @@ static void test_set_status_code_error(void) int err; set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_set_features_async_event(TEST_FD, EVENTS, false, &result); + err = nvme_set_features_async_event(test_link, EVENTS, false, &result); end_mock_cmds(); check(err == TEST_SC, "got error %d, expected %d", err, TEST_SC); check(result == TEST_RESULT, @@ -1470,7 +1470,7 @@ static void test_set_kernel_error(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_set_features_resv_mask( - TEST_FD, TEST_NSID, MASK, false, &result); + test_link, TEST_NSID, MASK, false, &result); end_mock_cmds(); check(err == -1, "got error %d, expected -1", err); check(errno == EIO, "unexpected error %m"); @@ -1494,7 +1494,7 @@ static void test_get_status_code_error(void) int err; set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_get_features_kato(TEST_FD, TEST_SEL, &result); + err = nvme_get_features_kato(test_link, TEST_SEL, &result); end_mock_cmds(); check(err == TEST_SC, "got error %d, expected %d", err, TEST_SC); check(result == TEST_RESULT, @@ -1513,7 +1513,7 @@ static void test_get_kernel_error(void) int err; set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_get_features_num_queues(TEST_FD, TEST_SEL, &result); + err = nvme_get_features_num_queues(test_link, TEST_SEL, &result); end_mock_cmds(); check(err == -1, "got error %d, expected -1", err); check(errno == EBUSY, "unexpected error %m"); @@ -1537,7 +1537,7 @@ static void test_lm_set_features_ctrl_data_queue(void) int err; set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_lm_set_features_ctrl_data_queue(TEST_FD, TEST_CDQID, hp, tpt, + err = nvme_lm_set_features_ctrl_data_queue(test_link, TEST_CDQID, hp, tpt, etpt, &result); end_mock_cmds(); check(err == 0, "set features returned error %d, errno %m", err); @@ -1562,7 +1562,7 @@ static void test_lm_get_features_ctrl_data_queue(void) arbitrary(&expected_data, sizeof(expected_data)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_lm_get_features_ctrl_data_queue(TEST_FD, TEST_CDQID, &data, + err = nvme_lm_get_features_ctrl_data_queue(test_link, TEST_CDQID, &data, &result); end_mock_cmds(); check(err == 0, "get features returned error %d, errno %m", err); @@ -1583,7 +1583,11 @@ static void run_test(const char *test_name, void (*test_fn)(void)) int main(void) { + nvme_root_t r = nvme_create_root(stdout, DEFAULT_LOGLEVEL); + set_mock_fd(TEST_FD); + test_link = nvme_open(r, "NVME_TEST_FD"); + RUN_TEST(set_features); RUN_TEST(get_features); RUN_TEST(set_features_data); @@ -1655,4 +1659,6 @@ int main(void) RUN_TEST(get_kernel_error); RUN_TEST(lm_set_features_ctrl_data_queue); RUN_TEST(lm_get_features_ctrl_data_queue); + + nvme_free_root(r); } diff --git a/test/ioctl/identify.c b/test/ioctl/identify.c index bec2a11fe..a65845605 100644 --- a/test/ioctl/identify.c +++ b/test/ioctl/identify.c @@ -19,6 +19,8 @@ #define TEST_FIDX 0xF #define TEST_SC NVME_SC_INVALID_FIELD +static nvme_link_t test_link; + static void test_ns(void) { struct nvme_id_ns expected_id, id = {}; @@ -33,7 +35,7 @@ static void test_ns(void) arbitrary(&expected_id, sizeof(expected_id)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_identify_ns(TEST_FD, TEST_NSID, &id); + err = nvme_identify_ns(test_link, TEST_NSID, &id); end_mock_cmds(); check(err == 0, "identify returned error %d, errno %m", err); cmp(&id, &expected_id, sizeof(id), "incorrect identify data"); @@ -52,7 +54,7 @@ static void test_ctrl(void) arbitrary(&expected_id, sizeof(expected_id)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_identify_ctrl(TEST_FD, &id); + err = nvme_identify_ctrl(test_link, &id); end_mock_cmds(); check(err == 0, "identify returned error %d, errno %m", err); cmp(&id, &expected_id, sizeof(id), "incorrect identify data"); @@ -72,7 +74,7 @@ static void test_active_ns_list(void) arbitrary(&expected_id, sizeof(expected_id)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_identify_active_ns_list(TEST_FD, TEST_NSID, &id); + err = nvme_identify_active_ns_list(test_link, TEST_NSID, &id); end_mock_cmds(); check(err == 0, "identify returned error %d, errno %m", err); cmp(&id, &expected_id, sizeof(id), "incorrect identify data"); @@ -95,7 +97,7 @@ static void test_ns_descs(void) id = calloc(1, NVME_IDENTIFY_DATA_SIZE); check(id, "memory allocation failed"); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_identify_ns_descs(TEST_FD, TEST_NSID, id); + err = nvme_identify_ns_descs(test_link, TEST_NSID, id); end_mock_cmds(); check(err == 0, "identify returned error %d, errno %m", err); cmp(id, expected_id, sizeof(expected_id), "incorrect identify data"); @@ -116,7 +118,7 @@ static void test_nvmset_list(void) arbitrary(&expected_id, sizeof(expected_id)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_identify_nvmset_list(TEST_FD, TEST_NVMSETID, &id); + err = nvme_identify_nvmset_list(test_link, TEST_NVMSETID, &id); end_mock_cmds(); check(err == 0, "identify returned error %d, errno %m", err); cmp(&id, &expected_id, sizeof(id), "incorrect identify data"); @@ -139,7 +141,7 @@ static void test_ns_csi(void) arbitrary(expected_id, sizeof(expected_id)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_identify_ns_csi(TEST_FD, TEST_NSID, TEST_UUID, TEST_CSI, id); + err = nvme_identify_ns_csi(test_link, TEST_NSID, TEST_UUID, TEST_CSI, id); end_mock_cmds(); check(err == 0, "identify returned error %d, errno %m", err); cmp(id, expected_id, sizeof(id), "incorrect identify data"); @@ -160,7 +162,7 @@ static void test_zns_identify_ns(void) arbitrary(&expected_id, sizeof(expected_id)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_zns_identify_ns(TEST_FD, TEST_NSID, &id); + err = nvme_zns_identify_ns(test_link, TEST_NSID, &id); end_mock_cmds(); check(err == 0, "identify returned error %d, errno %m", err); cmp(&id, &expected_id, sizeof(id), "incorrect identify data"); @@ -180,7 +182,7 @@ static void test_nvm_identify_ctrl(void) arbitrary(&expected_id, sizeof(expected_id)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_nvm_identify_ctrl(TEST_FD, &id); + err = nvme_nvm_identify_ctrl(test_link, &id); end_mock_cmds(); check(err == 0, "identify returned error %d, errno %m", err); cmp(&id, &expected_id, sizeof(id), "incorrect identify data"); @@ -200,7 +202,7 @@ static void test_zns_identify_ctrl(void) arbitrary(&expected_id, sizeof(expected_id)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_zns_identify_ctrl(TEST_FD, &id); + err = nvme_zns_identify_ctrl(test_link, &id); end_mock_cmds(); check(err == 0, "identify returned error %d, errno %m", err); cmp(&id, &expected_id, sizeof(id), "incorrect identify data"); @@ -222,7 +224,7 @@ static void test_active_ns_list_csi(void) arbitrary(&expected_id, sizeof(expected_id)); set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_identify_active_ns_list_csi( - TEST_FD, TEST_NSID, TEST_CSI, &id); + test_link, TEST_NSID, TEST_CSI, &id); end_mock_cmds(); check(err == 0, "identify returned error %d, errno %m", err); cmp(&id, &expected_id, sizeof(id), "incorrect identify data"); @@ -243,7 +245,7 @@ static void test_independent_identify_ns(void) arbitrary(&expected_id, sizeof(expected_id)); set_mock_admin_cmds(&mock_admin_cmd, 1); /* That's a mouthful! */ - err = nvme_identify_independent_identify_ns(TEST_FD, TEST_NSID, &id); + err = nvme_identify_independent_identify_ns(test_link, TEST_NSID, &id); end_mock_cmds(); check(err == 0, "identify returned error %d, errno %m", err); cmp(&id, &expected_id, sizeof(id), "incorrect identify data"); @@ -263,7 +265,7 @@ static void test_allocated_ns_list(void) arbitrary(&expected_id, sizeof(expected_id)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_identify_allocated_ns_list(TEST_FD, TEST_NSID, &id); + err = nvme_identify_allocated_ns_list(test_link, TEST_NSID, &id); end_mock_cmds(); check(err == 0, "identify returned error %d, errno %m", err); cmp(&id, &expected_id, sizeof(id), "incorrect identify data"); @@ -283,7 +285,7 @@ static void test_allocated_ns(void) arbitrary(&expected_id, sizeof(expected_id)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_identify_allocated_ns(TEST_FD, TEST_NSID, &id); + err = nvme_identify_allocated_ns(test_link, TEST_NSID, &id); end_mock_cmds(); check(err == 0, "identify returned error %d, errno %m", err); cmp(&id, &expected_id, sizeof(id), "incorrect identify data"); @@ -304,7 +306,7 @@ static void test_nsid_ctrl_list(void) arbitrary(&expected_id, sizeof(expected_id)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_identify_nsid_ctrl_list(TEST_FD, TEST_NSID, TEST_CNTID, &id); + err = nvme_identify_nsid_ctrl_list(test_link, TEST_NSID, TEST_CNTID, &id); end_mock_cmds(); check(err == 0, "identify returned error %d, errno %m", err); cmp(&id, &expected_id, sizeof(id), "incorrect identify data"); @@ -324,7 +326,7 @@ static void test_ctrl_list(void) arbitrary(&expected_id, sizeof(expected_id)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_identify_ctrl_list(TEST_FD, TEST_CNTID, &id); + err = nvme_identify_ctrl_list(test_link, TEST_CNTID, &id); end_mock_cmds(); check(err == 0, "identify returned error %d, errno %m", err); cmp(&id, &expected_id, sizeof(id), "incorrect identify data"); @@ -344,7 +346,7 @@ static void test_primary_ctrl(void) arbitrary(&expected_id, sizeof(expected_id)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_identify_primary_ctrl(TEST_FD, TEST_CNTID, &id); + err = nvme_identify_primary_ctrl(test_link, TEST_CNTID, &id); end_mock_cmds(); check(err == 0, "identify returned error %d, errno %m", err); cmp(&id, &expected_id, sizeof(id), "incorrect identify data"); @@ -364,7 +366,7 @@ static void test_secondary_ctrl_list(void) arbitrary(&expected_id, sizeof(expected_id)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_identify_secondary_ctrl_list(TEST_FD, TEST_CNTID, &id); + err = nvme_identify_secondary_ctrl_list(test_link, TEST_CNTID, &id); end_mock_cmds(); check(err == 0, "identify returned error %d, errno %m", err); cmp(&id, &expected_id, sizeof(id), "incorrect identify data"); @@ -383,7 +385,7 @@ static void test_ns_granularity(void) arbitrary(&expected_id, sizeof(expected_id)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_identify_ns_granularity(TEST_FD, &id); + err = nvme_identify_ns_granularity(test_link, &id); end_mock_cmds(); check(err == 0, "identify returned error %d, errno %m", err); cmp(&id, &expected_id, sizeof(id), "incorrect identify data"); @@ -402,7 +404,7 @@ static void test_uuid(void) arbitrary(&expected_id, sizeof(expected_id)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_identify_uuid(TEST_FD, &id); + err = nvme_identify_uuid(test_link, &id); end_mock_cmds(); check(err == 0, "identify returned error %d, errno %m", err); cmp(&id, &expected_id, sizeof(id), "incorrect identify data"); @@ -422,7 +424,7 @@ static void test_domain_list(void) arbitrary(&expected_id, sizeof(expected_id)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_identify_domain_list(TEST_FD, TEST_DOMID, &id); + err = nvme_identify_domain_list(test_link, TEST_DOMID, &id); end_mock_cmds(); check(err == 0, "identify returned error %d, errno %m", err); cmp(&id, &expected_id, sizeof(id), "incorrect identify data"); @@ -442,7 +444,7 @@ static void test_endurance_group_list(void) arbitrary(&expected_id, sizeof(expected_id)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_identify_endurance_group_list(TEST_FD, TEST_ENDGID, &id); + err = nvme_identify_endurance_group_list(test_link, TEST_ENDGID, &id); end_mock_cmds(); check(err == 0, "identify returned error %d, errno %m", err); cmp(&id, &expected_id, sizeof(id), "incorrect identify data"); @@ -464,7 +466,7 @@ static void test_allocated_ns_list_csi(void) arbitrary(&expected_id, sizeof(expected_id)); set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_identify_allocated_ns_list_csi( - TEST_FD, TEST_NSID, TEST_CSI, &id); + test_link, TEST_NSID, TEST_CSI, &id); end_mock_cmds(); check(err == 0, "identify returned error %d, errno %m", err); cmp(&id, &expected_id, sizeof(id), "incorrect identify data"); @@ -484,7 +486,7 @@ static void test_iocs(void) arbitrary(&expected_id, sizeof(expected_id)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_identify_iocs(TEST_FD, TEST_CNTID, &id); + err = nvme_identify_iocs(test_link, TEST_CNTID, &id); end_mock_cmds(); check(err == 0, "identify returned error %d, errno %m", err); cmp(&id, &expected_id, sizeof(id), "incorrect identify data"); @@ -508,7 +510,7 @@ static void test_status_code_error(void) int err; set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_identify_nvmset_list(TEST_FD, TEST_NVMSETID, &id); + err = nvme_identify_nvmset_list(test_link, TEST_NVMSETID, &id); end_mock_cmds(); check(err == TEST_SC, "got error %d, expected %d", err, TEST_SC); } @@ -526,7 +528,7 @@ static void test_kernel_error(void) int err; set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_identify_ns(TEST_FD, TEST_NSID, &id); + err = nvme_identify_ns(test_link, TEST_NSID, &id); end_mock_cmds(); check(err == -1, "got error %d, expected -1", err); check(errno == EIO, "unexpected error %m"); @@ -550,7 +552,7 @@ static void test_identify_ns_csi_user_data_format(void) arbitrary(&expected_id, sizeof(expected_id)); set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_identify_ns_csi_user_data_format( - TEST_FD, TEST_FIDX, TEST_UUID, NVME_CSI_NVM, &id); + test_link, TEST_FIDX, TEST_UUID, NVME_CSI_NVM, &id); end_mock_cmds(); check(err == 0, "identify returned error %d, errno %m", err); cmp(&id, &expected_id, sizeof(id), "incorrect identify data"); @@ -573,7 +575,7 @@ static void test_identify_iocs_ns_csi_user_data_format(void) arbitrary(&expected_id, sizeof(expected_id)); set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_identify_iocs_ns_csi_user_data_format( - TEST_FD, TEST_FIDX, TEST_UUID, TEST_CSI, &id); + test_link, TEST_FIDX, TEST_UUID, TEST_CSI, &id); end_mock_cmds(); check(err == 0, "identify returned error %d, errno %m", err); cmp(&id, &expected_id, sizeof(id), "incorrect identify data"); @@ -591,7 +593,11 @@ static void run_test(const char *test_name, void (*test_fn)(void)) int main(void) { + nvme_root_t r = nvme_create_root(stdout, DEFAULT_LOGLEVEL); + set_mock_fd(TEST_FD); + test_link = nvme_open(r, "NVME_TEST_FD"); + RUN_TEST(ns); RUN_TEST(ctrl); RUN_TEST(active_ns_list); @@ -619,4 +625,6 @@ int main(void) RUN_TEST(kernel_error); RUN_TEST(identify_ns_csi_user_data_format); RUN_TEST(identify_iocs_ns_csi_user_data_format); + + nvme_free_root(r); } diff --git a/test/ioctl/logs.c b/test/ioctl/logs.c index c3822991a..b715fbdd0 100644 --- a/test/ioctl/logs.c +++ b/test/ioctl/logs.c @@ -23,6 +23,8 @@ #define TEST_LSP NVME_LOG_CDW10_LSP_MASK #define TEST_PEVENT NVME_PEVENT_LOG_RELEASE_CTX +static nvme_link_t test_link; + static void test_get_log_sanitize(void) { struct nvme_sanitize_log_page expected_log, log = {}; @@ -38,7 +40,7 @@ static void test_get_log_sanitize(void) arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_get_log_sanitize(TEST_FD, true, &log); + err = nvme_get_log_sanitize(test_link, true, &log); end_mock_cmds(); check(err == 0, "get log returned error %d, errno %m", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); @@ -59,7 +61,7 @@ static void test_get_log_mgmt_addr_list(void) arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_get_log_mgmt_addr_list(TEST_FD, sizeof(log), &log); + err = nvme_get_log_mgmt_addr_list(test_link, sizeof(log), &log); end_mock_cmds(); check(err == 0, "get log returned error %d, errno %m", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); @@ -81,7 +83,7 @@ static void test_get_log_supported_log_pages(void) arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_get_log_supported_log_pages(TEST_FD, !TEST_RAE, &log); + err = nvme_get_log_supported_log_pages(test_link, !TEST_RAE, &log); end_mock_cmds(); check(err == 0, "get log returned error %d, errno %m", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); @@ -102,7 +104,7 @@ static void test_get_log_error(void) arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_get_log_error(TEST_FD, 1, TEST_RAE, &log); + err = nvme_get_log_error(test_link, 1, TEST_RAE, &log); end_mock_cmds(); check(err == 0, "get log returned error %d, errno %m", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); @@ -123,7 +125,7 @@ static void test_get_log_smart(void) arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_get_log_smart(TEST_FD, TEST_NSID, TEST_RAE, &log); + err = nvme_get_log_smart(test_link, TEST_NSID, TEST_RAE, &log); end_mock_cmds(); check(err == 0, "get log returned error %d, errno %m", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); @@ -144,7 +146,7 @@ static void test_get_log_fw_slot(void) arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_get_log_fw_slot(TEST_FD, TEST_RAE, &log); + err = nvme_get_log_fw_slot(test_link, TEST_RAE, &log); end_mock_cmds(); check(err == 0, "get log returned error %d, errno %m", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); @@ -165,7 +167,7 @@ static void test_get_log_changed_ns_list(void) arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_get_log_changed_ns_list(TEST_FD, TEST_RAE, &log); + err = nvme_get_log_changed_ns_list(test_link, TEST_RAE, &log); end_mock_cmds(); check(err == 0, "get log returned error %d, errno %m", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); @@ -187,7 +189,7 @@ static void test_get_log_cmd_effects(void) arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_get_log_cmd_effects(TEST_FD, TEST_CSI, &log); + err = nvme_get_log_cmd_effects(test_link, TEST_CSI, &log); end_mock_cmds(); check(err == 0, "get log returned error %d, errno %m", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); @@ -208,7 +210,7 @@ static void test_get_log_device_self_test(void) arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_get_log_device_self_test(TEST_FD, &log); + err = nvme_get_log_device_self_test(test_link, &log); end_mock_cmds(); check(err == 0, "get log returned error %d, errno %m", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); @@ -231,7 +233,7 @@ static void test_get_log_create_telemetry_host_mcda(void) arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_get_log_create_telemetry_host_mcda(TEST_FD, TEST_MCDA, &log); + err = nvme_get_log_create_telemetry_host_mcda(test_link, TEST_MCDA, &log); end_mock_cmds(); check(err == 0, "get log returned error %d, errno %m", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); @@ -255,7 +257,7 @@ static void test_get_log_create_telemetry_host(void) arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_get_log_create_telemetry_host(TEST_FD, &log); + err = nvme_get_log_create_telemetry_host(test_link, &log); end_mock_cmds(); check(err == 0, "get log returned error %d, errno %m", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); @@ -281,7 +283,7 @@ static void test_get_log_telemetry_host(void) arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_get_log_telemetry_host(TEST_FD, TEST_OFFSET, sizeof(log), + err = nvme_get_log_telemetry_host(test_link, TEST_OFFSET, sizeof(log), &log); end_mock_cmds(); check(err == 0, "get log returned error %d, errno %m", err); @@ -309,7 +311,7 @@ static void test_get_log_telemetry_ctrl(void) arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_get_log_telemetry_ctrl(TEST_FD, TEST_RAE, TEST_OFFSET, + err = nvme_get_log_telemetry_ctrl(test_link, TEST_RAE, TEST_OFFSET, sizeof(log), &log); end_mock_cmds(); check(err == 0, "get log returned error %d, errno %m", err); @@ -332,7 +334,7 @@ static void test_get_log_endurance_group(void) arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_get_log_endurance_group(TEST_FD, TEST_ENDGID, &log); + err = nvme_get_log_endurance_group(test_link, TEST_ENDGID, &log); end_mock_cmds(); check(err == 0, "get log returned error %d, errno %m", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); @@ -354,7 +356,7 @@ static void test_get_log_predictable_lat_nvmset(void) arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_get_log_predictable_lat_nvmset(TEST_FD, TEST_NVMSETID, &log); + err = nvme_get_log_predictable_lat_nvmset(test_link, TEST_NVMSETID, &log); end_mock_cmds(); check(err == 0, "get log returned error %d, errno %m", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); @@ -378,7 +380,7 @@ static void test_get_log_predictable_lat_event(void) arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_get_log_predictable_lat_event( - TEST_FD, TEST_RAE, TEST_OFFSET_32, sizeof(log), &log); + test_link, TEST_RAE, TEST_OFFSET_32, sizeof(log), &log); end_mock_cmds(); check(err == 0, "get log returned error %d, errno %m", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); @@ -402,7 +404,7 @@ static void test_get_log_fdp_configurations(void) arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_get_log_fdp_configurations( - TEST_FD, TEST_ENDGID, TEST_OFFSET_32, sizeof(log), &log); + test_link, TEST_ENDGID, TEST_OFFSET_32, sizeof(log), &log); end_mock_cmds(); check(err == 0, "get log returned error %d, errno %m", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); @@ -426,7 +428,7 @@ static void test_get_log_reclaim_unit_handle_usage(void) arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_get_log_reclaim_unit_handle_usage( - TEST_FD, TEST_ENDGID, TEST_OFFSET_32, sizeof(log), &log); + test_link, TEST_ENDGID, TEST_OFFSET_32, sizeof(log), &log); end_mock_cmds(); check(err == 0, "get log returned error %d, errno %m", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); @@ -449,7 +451,7 @@ static void test_get_log_fdp_stats(void) arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_get_log_fdp_stats(TEST_FD, TEST_ENDGID, TEST_OFFSET_32, + err = nvme_get_log_fdp_stats(test_link, TEST_ENDGID, TEST_OFFSET_32, sizeof(log), &log); end_mock_cmds(); check(err == 0, "get log returned error %d, errno %m", err); @@ -474,7 +476,7 @@ static void test_get_log_fdp_events(void) arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_get_log_fdp_events(TEST_FD, TEST_ENDGID, TEST_EVENTS, + err = nvme_get_log_fdp_events(test_link, TEST_ENDGID, TEST_EVENTS, TEST_OFFSET_32, sizeof(log), &log); end_mock_cmds(); check(err == 0, "get log returned error %d, errno %m", err); @@ -499,7 +501,7 @@ static void test_get_log_ana(void) arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_get_log_ana(TEST_FD, TEST_ANA_LSP, TEST_RAE, TEST_OFFSET, + err = nvme_get_log_ana(test_link, TEST_ANA_LSP, TEST_RAE, TEST_OFFSET, sizeof(log), &log); end_mock_cmds(); check(err == 0, "get log returned error %d, errno %m", err); @@ -523,7 +525,7 @@ static void test_get_log_ana_groups(void) arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_get_log_ana_groups(TEST_FD, TEST_RAE, sizeof(log), &log); + err = nvme_get_log_ana_groups(test_link, TEST_RAE, sizeof(log), &log); end_mock_cmds(); check(err == 0, "get log returned error %d, errno %m", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); @@ -546,7 +548,7 @@ static void test_get_log_lba_status(void) arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_get_log_lba_status(TEST_FD, TEST_RAE, TEST_OFFSET, + err = nvme_get_log_lba_status(test_link, TEST_RAE, TEST_OFFSET, sizeof(log), &log); end_mock_cmds(); check(err == 0, "get log returned error %d, errno %m", err); @@ -570,7 +572,7 @@ static void test_get_log_endurance_grp_evt(void) arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_get_log_endurance_grp_evt(TEST_FD, TEST_RAE, TEST_OFFSET_32, + err = nvme_get_log_endurance_grp_evt(test_link, TEST_RAE, TEST_OFFSET_32, sizeof(log), &log); end_mock_cmds(); check(err == 0, "get log returned error %d, errno %m", err); @@ -593,7 +595,7 @@ static void test_get_log_fid_supported_effects(void) arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_get_log_fid_supported_effects(TEST_FD, TEST_RAE, &log); + err = nvme_get_log_fid_supported_effects(test_link, TEST_RAE, &log); end_mock_cmds(); check(err == 0, "get log returned error %d, errno %m", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); @@ -615,7 +617,7 @@ static void test_get_log_mi_cmd_supported_effects(void) arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_get_log_mi_cmd_supported_effects(TEST_FD, TEST_RAE, &log); + err = nvme_get_log_mi_cmd_supported_effects(test_link, TEST_RAE, &log); end_mock_cmds(); check(err == 0, "get log returned error %d, errno %m", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); @@ -637,7 +639,7 @@ static void test_get_log_boot_partition(void) arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_get_log_boot_partition(TEST_FD, TEST_RAE, TEST_LSP, + err = nvme_get_log_boot_partition(test_link, TEST_RAE, TEST_LSP, sizeof(log), &log); end_mock_cmds(); check(err == 0, "get log returned error %d, errno %m", err); @@ -660,7 +662,7 @@ static void test_get_log_rotational_media_info(void) arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_get_log_rotational_media_info(TEST_FD, TEST_ENDGID, + err = nvme_get_log_rotational_media_info(test_link, TEST_ENDGID, sizeof(log), &log); end_mock_cmds(); check(err == 0, "get log returned error %d, errno %m", err); @@ -682,7 +684,7 @@ static void test_get_log_dispersed_ns_participating_nss(void) arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_get_log_dispersed_ns_participating_nss(TEST_FD, TEST_NSID, + err = nvme_get_log_dispersed_ns_participating_nss(test_link, TEST_NSID, sizeof(log), &log); end_mock_cmds(); check(err == 0, "get log returned error %d, errno %m", err); @@ -705,7 +707,7 @@ static void test_get_log_phy_rx_eom(void) arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_get_log_phy_rx_eom(TEST_FD, TEST_LSP, TEST_CNTID, + err = nvme_get_log_phy_rx_eom(test_link, TEST_LSP, TEST_CNTID, sizeof(log), &log); end_mock_cmds(); check(err == 0, "get log returned error %d, errno %m", err); @@ -728,7 +730,7 @@ static void test_get_log_reachability_groups(void) arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_get_log_reachability_groups(TEST_FD, !!TEST_LSP, TEST_RAE, + err = nvme_get_log_reachability_groups(test_link, !!TEST_LSP, TEST_RAE, sizeof(log), &log); end_mock_cmds(); check(err == 0, "get log returned error %d, errno %m", err); @@ -752,7 +754,7 @@ static void test_get_log_reachability_associations(void) arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_get_log_reachability_associations( - TEST_FD, !!TEST_LSP, TEST_RAE, sizeof(log), &log); + test_link, !!TEST_LSP, TEST_RAE, sizeof(log), &log); end_mock_cmds(); check(err == 0, "get log returned error %d, errno %m", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); @@ -774,7 +776,7 @@ static void test_get_log_changed_alloc_ns_list(void) arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_get_log_changed_alloc_ns_list(TEST_FD, TEST_RAE, sizeof(log), + err = nvme_get_log_changed_alloc_ns_list(test_link, TEST_RAE, sizeof(log), &log); end_mock_cmds(); check(err == 0, "get log returned error %d, errno %m", err); @@ -797,7 +799,7 @@ static void test_get_log_discovery(void) arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_get_log_discovery(TEST_FD, TEST_RAE, TEST_OFFSET_32, + err = nvme_get_log_discovery(test_link, TEST_RAE, TEST_OFFSET_32, sizeof(log), &log); end_mock_cmds(); check(err == 0, "get log returned error %d, errno %m", err); @@ -820,7 +822,7 @@ static void test_get_log_host_discover(void) arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_get_log_host_discover(TEST_FD, !!TEST_LSP, TEST_RAE, + err = nvme_get_log_host_discover(test_link, !!TEST_LSP, TEST_RAE, sizeof(log), &log); end_mock_cmds(); check(err == 0, "get log returned error %d, errno %m", err); @@ -842,7 +844,7 @@ static void test_get_log_ave_discover(void) arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_get_log_ave_discover(TEST_FD, TEST_RAE, sizeof(log), &log); + err = nvme_get_log_ave_discover(test_link, TEST_RAE, sizeof(log), &log); end_mock_cmds(); check(err == 0, "get log returned error %d, errno %m", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); @@ -864,7 +866,7 @@ static void test_get_log_pull_model_ddc_req(void) arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_get_log_pull_model_ddc_req(TEST_FD, TEST_RAE, sizeof(log), + err = nvme_get_log_pull_model_ddc_req(test_link, TEST_RAE, sizeof(log), &log); end_mock_cmds(); check(err == 0, "get log returned error %d, errno %m", err); @@ -887,7 +889,7 @@ static void test_get_log_media_unit_stat(void) arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_get_log_media_unit_stat(TEST_FD, TEST_DOMID, &log); + err = nvme_get_log_media_unit_stat(test_link, TEST_DOMID, &log); end_mock_cmds(); check(err == 0, "get log returned error %d, errno %m", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); @@ -909,7 +911,7 @@ static void test_get_log_support_cap_config_list(void) arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_get_log_support_cap_config_list(TEST_FD, TEST_DOMID, &log); + err = nvme_get_log_support_cap_config_list(test_link, TEST_DOMID, &log); end_mock_cmds(); check(err == 0, "get log returned error %d, errno %m", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); @@ -930,7 +932,7 @@ static void test_get_log_reservation(void) arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_get_log_reservation(TEST_FD, TEST_RAE, &log); + err = nvme_get_log_reservation(test_link, TEST_RAE, &log); end_mock_cmds(); check(err == 0, "get log returned error %d, errno %m", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); @@ -953,7 +955,7 @@ static void test_get_log_zns_changed_zones(void) arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_get_log_zns_changed_zones(TEST_FD, TEST_NSID, TEST_RAE, + err = nvme_get_log_zns_changed_zones(test_link, TEST_NSID, TEST_RAE, &log); end_mock_cmds(); check(err == 0, "get log returned error %d, errno %m", err); @@ -976,7 +978,7 @@ static void test_get_log_persistent_event(void) arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_get_log_persistent_event(TEST_FD, TEST_PEVENT, sizeof(log), + err = nvme_get_log_persistent_event(test_link, TEST_PEVENT, sizeof(log), &log); end_mock_cmds(); check(err == 0, "get log returned error %d, errno %m", err); @@ -999,7 +1001,7 @@ static void test_get_log_lockdown(void) arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_get_log_lockdown(TEST_FD, TEST_LSP, &log); + err = nvme_get_log_lockdown(test_link, TEST_LSP, &log); end_mock_cmds(); check(err == 0, "get log returned error %d, errno %m", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); @@ -1017,7 +1019,11 @@ static void run_test(const char *test_name, void (*test_fn)(void)) int main(void) { + nvme_root_t r = nvme_create_root(stdout, DEFAULT_LOGLEVEL); + set_mock_fd(TEST_FD); + test_link = nvme_open(r, "NVME_TEST_FD"); + RUN_TEST(get_log_sanitize); RUN_TEST(get_log_mgmt_addr_list); RUN_TEST(get_log_supported_log_pages); @@ -1061,4 +1067,6 @@ int main(void) RUN_TEST(get_log_zns_changed_zones); RUN_TEST(get_log_persistent_event); RUN_TEST(get_log_lockdown); + + nvme_free_root(r); } diff --git a/test/ioctl/misc.c b/test/ioctl/misc.c index 755cea603..2b00e3a2c 100644 --- a/test/ioctl/misc.c +++ b/test/ioctl/misc.c @@ -13,13 +13,14 @@ #define TEST_NSID 0x12345678 #define TEST_CSI NVME_CSI_KV +static nvme_link_t test_link; + static void test_format_nvm(void) { __u32 result = 0; struct nvme_format_nvm_args args = { .result = &result, .args_size = sizeof(args), - .fd = TEST_FD, .nsid = TEST_NSID, .mset = NVME_FORMAT_MSET_EXTENDED, .pi = NVME_FORMAT_PI_TYPE2, @@ -40,7 +41,7 @@ static void test_format_nvm(void) int err; set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_format_nvm(&args); + err = nvme_format_nvm(test_link, &args); end_mock_cmds(); check(err == 0, "returned error %d, errno %m", err); check(result == 0, "returned result %u", result); @@ -54,7 +55,6 @@ static void test_ns_mgmt(void) .result = &result, .ns = NULL, .args_size = sizeof(args), - .fd = TEST_FD, .nsid = TEST_NSID, .sel = NVME_NS_MGMT_SEL_CREATE, .csi = TEST_CSI, @@ -75,7 +75,7 @@ static void test_ns_mgmt(void) arbitrary(&expected_data, sizeof(expected_data)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_ns_mgmt(&args); + err = nvme_ns_mgmt(test_link, &args); end_mock_cmds(); check(err == 0, "returned error %d, errno %m", err); check(result == 0, "returned result %u", result); @@ -100,7 +100,7 @@ static void test_ns_mgmt_create(void) arbitrary(&expected_data, sizeof(expected_data)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_ns_mgmt_create(TEST_FD, NULL, &result, 0, NVME_CSI_ZNS, + err = nvme_ns_mgmt_create(test_link, NULL, &result, 0, NVME_CSI_ZNS, &data); end_mock_cmds(); check(err == 0, "returned error %d, errno %m", err); @@ -119,7 +119,7 @@ static void test_ns_mgmt_delete(void) int err; set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_ns_mgmt_delete(TEST_FD, TEST_NSID); + err = nvme_ns_mgmt_delete(test_link, TEST_NSID); end_mock_cmds(); check(err == 0, "returned error %d, errno %m", err); } @@ -130,7 +130,6 @@ static void test_get_property(void) struct nvme_get_property_args args = { .value = &result, .args_size = sizeof(args), - .fd = TEST_FD, .offset = NVME_REG_ACQ, }; @@ -147,7 +146,7 @@ static void test_get_property(void) int err; set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_get_property(&args); + err = nvme_get_property(test_link, &args); end_mock_cmds(); check(err == 0, "returned error %d, errno %m", err); check(result == expected_result, "returned wrong result"); @@ -161,7 +160,6 @@ static void test_set_property(void) .value = value, .result = &result, .args_size = sizeof(args), - .fd = TEST_FD, .offset = NVME_REG_BPMBL, }; @@ -177,7 +175,7 @@ static void test_set_property(void) int err; set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_set_property(&args); + err = nvme_set_property(test_link, &args); end_mock_cmds(); check(err == 0, "returned error %d, errno %m", err); check(result == 0, "returned result %u", result); @@ -191,7 +189,6 @@ static void test_ns_attach(void) .result = &result, .ctrlist = &ctrlist, .args_size = sizeof(args), - .fd = TEST_FD, .nsid = TEST_NSID, .sel = NVME_NS_ATTACH_SEL_CTRL_DEATTACH, }; @@ -208,7 +205,7 @@ static void test_ns_attach(void) arbitrary(&expected_ctrlist, sizeof(expected_ctrlist)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_ns_attach(&args); + err = nvme_ns_attach(test_link, &args); end_mock_cmds(); check(err == 0, "returned error %d, errno %m", err); check(result == 0, "returned result %u", result); @@ -232,7 +229,7 @@ static void test_ns_attach_ctrls(void) arbitrary(&ctrlist, sizeof(ctrlist)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_ns_attach_ctrls(TEST_FD, TEST_NSID, &ctrlist); + err = nvme_ns_attach_ctrls(test_link, TEST_NSID, &ctrlist); end_mock_cmds(); check(err == 0, "returned error %d, errno %m", err); } @@ -253,7 +250,7 @@ static void test_ns_detach_ctrls(void) arbitrary(&ctrlist, sizeof(ctrlist)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_ns_detach_ctrls(TEST_FD, TEST_NSID, &ctrlist); + err = nvme_ns_detach_ctrls(test_link, TEST_NSID, &ctrlist); end_mock_cmds(); check(err == 0, "returned error %d, errno %m", err); } @@ -267,7 +264,6 @@ static void test_fw_download(void) .result = &result, .data = &expected_data, .args_size = sizeof(args), - .fd = TEST_FD, .offset = 123, .data_len = sizeof(expected_data), }; @@ -285,7 +281,7 @@ static void test_fw_download(void) arbitrary(&expected_data, sizeof(expected_data)); memcpy(&data, &expected_data, sizeof(expected_data)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_fw_download(&args); + err = nvme_fw_download(test_link, &args); end_mock_cmds(); check(err == 0, "returned error %d, errno %m", err); check(result == 0, "returned result %u", result); @@ -298,7 +294,6 @@ static void test_fw_commit(void) struct nvme_fw_commit_args args = { .result = &result, .args_size = sizeof(args), - .fd = TEST_FD, .action = NVME_FW_COMMIT_CA_REPLACE_AND_ACTIVATE_IMMEDIATE, .slot = 0xf, .bpid = true, @@ -312,7 +307,7 @@ static void test_fw_commit(void) int err; set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_fw_commit(&args); + err = nvme_fw_commit(test_link, &args); end_mock_cmds(); check(err == 0, "returned error %d, errno %m", err); check(result == 0, "returned result %u", result); @@ -352,7 +347,7 @@ static void test_security_send(void) arbitrary(&expected_data, sizeof(expected_data)); memcpy(&data, &expected_data, sizeof(expected_data)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_security_send(&args); + err = nvme_security_send(test_link, &args); end_mock_cmds(); check(err == 0, "returned error %d, errno %m", err); check(result == 0, "returned result %u", result); @@ -368,7 +363,6 @@ static void test_security_receive(void) .result = &result, .data = &data, .args_size = sizeof(args), - .fd = TEST_FD, .nsid = TEST_NSID, .al = 0xffff, .data_len = sizeof(data), @@ -392,7 +386,7 @@ static void test_security_receive(void) arbitrary(&expected_data, sizeof(expected_data)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_security_receive(&args); + err = nvme_security_receive(test_link, &args); end_mock_cmds(); check(err == 0, "returned error %d, errno %m", err); check(result == 0, "returned result %u", result); @@ -419,7 +413,6 @@ static void test_get_lba_status(void) .result = &result, .lbas = lbas, .args_size = sizeof(args), - .fd = TEST_FD, .nsid = TEST_NSID, .mndw = ((lba_status_size - 1) >> 2), .atype = 0x11, @@ -441,7 +434,7 @@ static void test_get_lba_status(void) arbitrary(expected_lbas, lba_status_size); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_get_lba_status(&args); + err = nvme_get_lba_status(test_link, &args); end_mock_cmds(); check(err == 0, "returned error %d, errno %m", err); check(result == 0, "returned wrong result"); @@ -457,7 +450,6 @@ static void test_directive_send(void) .result = &result, .data = &expected_data, .args_size = sizeof(args), - .fd = TEST_FD, .nsid = TEST_NSID, .doper = NVME_DIRECTIVE_SEND_STREAMS_DOPER_RELEASE_RESOURCE, .dtype = NVME_DIRECTIVE_DTYPE_STREAMS, @@ -481,7 +473,7 @@ static void test_directive_send(void) arbitrary(&expected_data, sizeof(expected_data)); memcpy(&data, &expected_data, sizeof(expected_data)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_directive_send(&args); + err = nvme_directive_send(test_link, &args); end_mock_cmds(); check(err == 0, "returned error %d, errno %m", err); check(result == 0, "returned wrong result"); @@ -508,7 +500,7 @@ static void test_directive_send_id_endir(void) arbitrary(&expected_id, sizeof(expected_id)); memcpy(&id, &expected_id, sizeof(expected_id)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_directive_send_id_endir(TEST_FD, TEST_NSID, true, + err = nvme_directive_send_id_endir(test_link, TEST_NSID, true, NVME_DIRECTIVE_DTYPE_STREAMS, &id); end_mock_cmds(); check(err == 0, "returned error %d, errno %m", err); @@ -529,7 +521,7 @@ static void test_directive_send_stream_release_identifier(void) int err; set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_directive_send_stream_release_identifier(TEST_FD, TEST_NSID, + err = nvme_directive_send_stream_release_identifier(test_link, TEST_NSID, stream_id); end_mock_cmds(); check(err == 0, "returned error %d, errno %m", err); @@ -547,7 +539,7 @@ static void test_directive_send_stream_release_resource(void) int err; set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_directive_send_stream_release_resource(TEST_FD, TEST_NSID); + err = nvme_directive_send_stream_release_resource(test_link, TEST_NSID); end_mock_cmds(); check(err == 0, "returned error %d, errno %m", err); } @@ -561,7 +553,6 @@ static void test_directive_recv(void) .result = &result, .data = &data, .args_size = sizeof(args), - .fd = TEST_FD, .nsid = TEST_NSID, .doper = NVME_DIRECTIVE_RECEIVE_STREAMS_DOPER_PARAM, .dtype = NVME_DIRECTIVE_DTYPE_STREAMS, @@ -584,7 +575,7 @@ static void test_directive_recv(void) arbitrary(&expected_data, sizeof(expected_data)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_directive_recv(&args); + err = nvme_directive_recv(test_link, &args); end_mock_cmds(); check(err == 0, "returned error %d, errno %m", err); check(result == 0, "returned wrong result"); @@ -609,7 +600,7 @@ static void test_directive_recv_identify_parameters(void) arbitrary(&expected_id, sizeof(expected_id)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_directive_recv_identify_parameters(TEST_FD, TEST_NSID, &id); + err = nvme_directive_recv_identify_parameters(test_link, TEST_NSID, &id); end_mock_cmds(); check(err == 0, "returned error %d, errno %m", err); cmp(&id, &expected_id, sizeof(id), "incorrect id"); @@ -633,7 +624,7 @@ static void test_directive_recv_stream_parameters(void) arbitrary(&expected_params, sizeof(expected_params)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_directive_recv_stream_parameters(TEST_FD, TEST_NSID, + err = nvme_directive_recv_stream_parameters(test_link, TEST_NSID, ¶ms); end_mock_cmds(); check(err == 0, "returned error %d, errno %m", err); @@ -670,7 +661,7 @@ static void test_directive_recv_stream_status(void) arbitrary(expected_status, stream_status_size); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_directive_recv_stream_status(TEST_FD, TEST_NSID, nr_entries, + err = nvme_directive_recv_stream_status(test_link, TEST_NSID, nr_entries, status); end_mock_cmds(); check(err == 0, "returned error %d, errno %m", err); @@ -694,7 +685,7 @@ static void test_directive_recv_stream_allocate(void) int err; set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_directive_recv_stream_allocate(TEST_FD, TEST_NSID, nsr, + err = nvme_directive_recv_stream_allocate(test_link, TEST_NSID, nsr, &result); end_mock_cmds(); check(err == 0, "returned error %d, errno %m", err); @@ -708,7 +699,6 @@ static void test_capacity_mgmt(void) struct nvme_capacity_mgmt_args args = { .result = &result, .args_size = sizeof(args), - .fd = TEST_FD, .cdw11 = 0x1234, .cdw12 = 0x5678, .element_id = 0x12, @@ -727,7 +717,7 @@ static void test_capacity_mgmt(void) int err; set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_capacity_mgmt(&args); + err = nvme_capacity_mgmt(test_link, &args); end_mock_cmds(); check(err == 0, "returned error %d, errno %m", err); check(result == expected_result, "wrong result"); @@ -740,7 +730,6 @@ static void test_lockdown(void) struct nvme_lockdown_args args = { .result = &result, .args_size = sizeof(args), - .fd = TEST_FD, .scp = 0x2, .prhbt = !!true, .ifc = 0x1, @@ -759,7 +748,7 @@ static void test_lockdown(void) int err; set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_lockdown(&args); + err = nvme_lockdown(test_link, &args); end_mock_cmds(); check(err == 0, "returned error %d, errno %m", err); check(result == expected_result, "wrong result"); @@ -772,7 +761,6 @@ static void test_sanitize_nvm(void) struct nvme_sanitize_nvm_args args = { .result = &result, .args_size = sizeof(args), - .fd = TEST_FD, .sanact = NVME_SANITIZE_SANACT_START_CRYPTO_ERASE, .ovrpat = 0x101010, .ause = true, @@ -793,7 +781,7 @@ static void test_sanitize_nvm(void) int err; set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_sanitize_nvm(&args); + err = nvme_sanitize_nvm(test_link, &args); end_mock_cmds(); check(err == 0, "returned error %d, errno %m", err); check(result == expected_result, "wrong result"); @@ -806,7 +794,6 @@ static void test_dev_self_test(void) struct nvme_dev_self_test_args args = { .result = &result, .args_size = sizeof(args), - .fd = TEST_FD, .nsid = TEST_NSID, .stc = NVME_DST_STC_ABORT, }; @@ -821,7 +808,7 @@ static void test_dev_self_test(void) int err; set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_dev_self_test(&args); + err = nvme_dev_self_test(test_link, &args); end_mock_cmds(); check(err == 0, "returned error %d, errno %m", err); check(result == expected_result, "wrong result"); @@ -834,7 +821,6 @@ static void test_virtual_mgmt(void) struct nvme_virtual_mgmt_args args = { .result = &result, .args_size = sizeof(args), - .fd = TEST_FD, .act = NVME_VIRT_MGMT_ACT_ASSIGN_SEC_CTRL, .rt = NVME_VIRT_MGMT_RT_VI_RESOURCE, .cntlid = 0x0, @@ -851,7 +837,7 @@ static void test_virtual_mgmt(void) int err; set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_virtual_mgmt(&args); + err = nvme_virtual_mgmt(test_link, &args); end_mock_cmds(); check(err == 0, "returned error %d, errno %m", err); check(result == expected_result, "wrong result"); @@ -867,7 +853,7 @@ static void test_flush(void) int err; set_mock_io_cmds(&mock_io_cmd, 1); - err = nvme_flush(TEST_FD, TEST_NSID); + err = nvme_flush(test_link, TEST_NSID); end_mock_cmds(); check(err == 0, "returned error %d, errno %m", err); } @@ -883,7 +869,6 @@ static void test_read(void) .result = &result, .data = &data, .args_size = sizeof(args), - .fd = TEST_FD, .nsid = TEST_NSID, .reftag = 0xab, .data_len = sizeof(data), @@ -911,7 +896,7 @@ static void test_read(void) arbitrary(&expected_data, sizeof(expected_data)); set_mock_io_cmds(&mock_io_cmd, 1); - err = nvme_read(&args); + err = nvme_read(test_link, &args); end_mock_cmds(); check(err == 0, "returned error %d, errno %m", err); check(result == 0, "returned result %u", result); @@ -928,7 +913,6 @@ static void test_write(void) .result = &result, .data = &expected_data, .args_size = sizeof(args), - .fd = TEST_FD, .nsid = TEST_NSID, .reftag = 0xef, .data_len = sizeof(expected_data), @@ -957,7 +941,7 @@ static void test_write(void) arbitrary(&expected_data, sizeof(expected_data)); memcpy(&data, &expected_data, sizeof(expected_data)); set_mock_io_cmds(&mock_io_cmd, 1); - err = nvme_write(&args); + err = nvme_write(test_link, &args); end_mock_cmds(); check(err == 0, "returned error %d, errno %m", err); check(result == 0, "returned result %u", result); @@ -974,7 +958,6 @@ static void test_compare(void) .result = &result, .data = &expected_data, .args_size = sizeof(args), - .fd = TEST_FD, .nsid = TEST_NSID, .reftag = 0xff, .data_len = sizeof(expected_data), @@ -1003,7 +986,7 @@ static void test_compare(void) arbitrary(&expected_data, sizeof(expected_data)); memcpy(&data, &expected_data, sizeof(expected_data)); set_mock_io_cmds(&mock_io_cmd, 1); - err = nvme_compare(&args); + err = nvme_compare(test_link, &args); end_mock_cmds(); check(err == 0, "returned error %d, errno %m", err); check(result == 0, "returned result %u", result); @@ -1020,7 +1003,6 @@ static void test_write_zeros(void) .result = &result, .data = &expected_data, .args_size = sizeof(args), - .fd = TEST_FD, .nsid = TEST_NSID, .reftag = 0xff, .data_len = sizeof(expected_data), @@ -1049,7 +1031,7 @@ static void test_write_zeros(void) arbitrary(&expected_data, sizeof(expected_data)); memcpy(&data, &expected_data, sizeof(expected_data)); set_mock_io_cmds(&mock_io_cmd, 1); - err = nvme_write_zeros(&args); + err = nvme_write_zeros(test_link, &args); end_mock_cmds(); check(err == 0, "returned error %d, errno %m", err); check(result == 0, "returned result %u", result); @@ -1066,7 +1048,6 @@ static void test_write_uncorrectable(void) .result = &result, .data = &expected_data, .args_size = sizeof(args), - .fd = TEST_FD, .nsid = TEST_NSID, .reftag = 0x0, .data_len = sizeof(expected_data), @@ -1095,7 +1076,7 @@ static void test_write_uncorrectable(void) arbitrary(&expected_data, sizeof(expected_data)); memcpy(&data, &expected_data, sizeof(expected_data)); set_mock_io_cmds(&mock_io_cmd, 1); - err = nvme_write_uncorrectable(&args); + err = nvme_write_uncorrectable(test_link, &args); end_mock_cmds(); check(err == 0, "returned error %d, errno %m", err); check(result == 0, "returned result %u", result); @@ -1112,7 +1093,6 @@ static void test_verify(void) .result = &result, .data = &expected_data, .args_size = sizeof(args), - .fd = TEST_FD, .nsid = TEST_NSID, .reftag = 0xffffffff, .data_len = sizeof(expected_data), @@ -1141,7 +1121,7 @@ static void test_verify(void) arbitrary(&expected_data, sizeof(expected_data)); memcpy(&data, &expected_data, sizeof(expected_data)); set_mock_io_cmds(&mock_io_cmd, 1); - err = nvme_verify(&args); + err = nvme_verify(test_link, &args); end_mock_cmds(); check(err == 0, "returned error %d, errno %m", err); check(result == 0, "returned result %u", result); @@ -1162,7 +1142,6 @@ static void test_dsm(void) .result = &result, .dsm = dsm, .args_size = sizeof(args), - .fd = TEST_FD, .nsid = TEST_NSID, .attrs = NVME_DSMGMT_AD, .nr_ranges = nr_ranges, @@ -1181,7 +1160,7 @@ static void test_dsm(void) arbitrary(dsm, dsm_size); set_mock_io_cmds(&mock_io_cmd, 1); - err = nvme_dsm(&args); + err = nvme_dsm(test_link, &args); end_mock_cmds(); check(err == 0, "returned error %d, errno %m", err); check(result == 0, "returned result %u", result); @@ -1203,7 +1182,6 @@ static void test_copy(void) .result = &result, .copy = copy, .args_size = sizeof(args), - .fd = TEST_FD, .nsid = TEST_NSID, .nr = nr, .format = 0xf, @@ -1226,7 +1204,7 @@ static void test_copy(void) int err; set_mock_io_cmds(&mock_io_cmd, 1); - err = nvme_copy(&args); + err = nvme_copy(test_link, &args); end_mock_cmds(); check(err == 0, "returned error %d, errno %m", err); check(result == 0, "returned result %u", result); @@ -1241,7 +1219,6 @@ static void test_resv_acquire(void) .nrkey = 0, .result = &result, .args_size = sizeof(args), - .fd = TEST_FD, .nsid = TEST_NSID, .rtype = NVME_RESERVATION_RTYPE_EAAR, .racqa = NVME_RESERVATION_RACQA_PREEMPT, @@ -1262,7 +1239,7 @@ static void test_resv_acquire(void) int err; set_mock_io_cmds(&mock_io_cmd, 1); - err = nvme_resv_acquire(&args); + err = nvme_resv_acquire(test_link, &args); end_mock_cmds(); check(err == 0, "returned error %d, errno %m", err); check(result == 0, "returned result %u", result); @@ -1277,7 +1254,6 @@ static void test_resv_register(void) .nrkey = 0, .result = &result, .args_size = sizeof(args), - .fd = TEST_FD, .nsid = TEST_NSID, .rrega = NVME_RESERVATION_RREGA_UNREGISTER_KEY, .cptpl = NVME_RESERVATION_CPTPL_PERSIST, @@ -1298,7 +1274,7 @@ static void test_resv_register(void) int err; set_mock_io_cmds(&mock_io_cmd, 1); - err = nvme_resv_register(&args); + err = nvme_resv_register(test_link, &args); end_mock_cmds(); check(err == 0, "returned error %d, errno %m", err); check(result == 0, "returned result %u", result); @@ -1312,7 +1288,6 @@ static void test_resv_release(void) .crkey = 0xffffffffffffffff, .result = &result, .args_size = sizeof(args), - .fd = TEST_FD, .nsid = TEST_NSID, .rtype = NVME_RESERVATION_RTYPE_WE, .rrela = NVME_RESERVATION_RRELA_RELEASE, @@ -1333,7 +1308,7 @@ static void test_resv_release(void) int err; set_mock_io_cmds(&mock_io_cmd, 1); - err = nvme_resv_release(&args); + err = nvme_resv_release(test_link, &args); end_mock_cmds(); check(err == 0, "returned error %d, errno %m", err); check(result == 0, "returned result %u", result); @@ -1349,7 +1324,6 @@ static void test_resv_report(void) .result = &result, .report = &status, .args_size = sizeof(args), - .fd = TEST_FD, .nsid = TEST_NSID, .len = sizeof(status), .eds = false, @@ -1368,7 +1342,7 @@ static void test_resv_report(void) arbitrary(&expected_status, sizeof(expected_status)); set_mock_io_cmds(&mock_io_cmd, 1); - err = nvme_resv_report(&args); + err = nvme_resv_report(test_link, &args); end_mock_cmds(); check(err == 0, "returned error %d, errno %m", err); check(result == 0, "returned result %u", result); @@ -1381,7 +1355,6 @@ static void test_io_mgmt_recv(void) struct nvme_io_mgmt_recv_args args = { .data = &data, .args_size = sizeof(args), - .fd = TEST_FD, .nsid = TEST_NSID, .data_len = sizeof(data), .mos = 0x1, @@ -1401,7 +1374,7 @@ static void test_io_mgmt_recv(void) arbitrary(&expected_data, sizeof(expected_data)); set_mock_io_cmds(&mock_io_cmd, 1); - err = nvme_io_mgmt_recv(&args); + err = nvme_io_mgmt_recv(test_link, &args); end_mock_cmds(); check(err == 0, "returned error %d, errno %m", err); cmp(&data, &expected_data, sizeof(data), "incorrect data"); @@ -1413,7 +1386,6 @@ static void test_io_mgmt_send(void) struct nvme_io_mgmt_send_args args = { .data = &expected_data, .args_size = sizeof(args), - .fd = TEST_FD, .nsid = TEST_NSID, .data_len = sizeof(expected_data), .mos = 0x1, @@ -1433,7 +1405,7 @@ static void test_io_mgmt_send(void) arbitrary(&expected_data, sizeof(expected_data)); memcpy(&data, &expected_data, sizeof(expected_data)); set_mock_io_cmds(&mock_io_cmd, 1); - err = nvme_io_mgmt_send(&args); + err = nvme_io_mgmt_send(test_link, &args); end_mock_cmds(); check(err == 0, "returned error %d, errno %m", err); cmp(&data, &expected_data, sizeof(data), "incorrect data"); @@ -1456,7 +1428,7 @@ static void test_fdp_reclaim_unit_handle_status(void) arbitrary(&expected_data, sizeof(expected_data)); set_mock_io_cmds(&mock_io_cmd, 1); - err = nvme_fdp_reclaim_unit_handle_status(TEST_FD, TEST_NSID, data_len, + err = nvme_fdp_reclaim_unit_handle_status(test_link, TEST_NSID, data_len, &data); end_mock_cmds(); check(err == 0, "returned error %d, errno %m", err); @@ -1479,7 +1451,7 @@ static void test_fdp_reclaim_unit_handle_update(void) arbitrary(&pids, sizeof(pids)); set_mock_io_cmds(&mock_io_cmd, 1); - err = nvme_fdp_reclaim_unit_handle_update(TEST_FD, TEST_NSID, npids, + err = nvme_fdp_reclaim_unit_handle_update(test_link, TEST_NSID, npids, &pids); end_mock_cmds(); check(err == 0, "returned error %d, errno %m", err); @@ -1493,7 +1465,6 @@ static void test_dim_send(void) .result = 0, .data = &data, .args_size = sizeof(args), - .fd = TEST_FD, .data_len = sizeof(data), .tas = 0xf, }; @@ -1510,7 +1481,7 @@ static void test_dim_send(void) arbitrary(&expected_data, sizeof(expected_data)); memcpy(&data, &expected_data, sizeof(expected_data)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_dim_send(&args); + err = nvme_dim_send(test_link, &args); end_mock_cmds(); check(err == 0, "returned error %d, errno %m", err); check(result == 0, "returned result %u", result); @@ -1525,7 +1496,6 @@ static void test_lm_cdq(void) .result = 0, .data = &data, .args_size = sizeof(args), - .fd = TEST_FD, .mos = 0x1, .cntlid = 0x2, .cdqid = 0x3, @@ -1547,7 +1517,7 @@ static void test_lm_cdq(void) arbitrary(&expected_data, sizeof(expected_data)); memcpy(&data, &expected_data, sizeof(expected_data)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_lm_cdq(&args); + err = nvme_lm_cdq(test_link, &args); end_mock_cmds(); check(err == 0, "returned error %d, errno %m", err); check(result == 0, "returned result %u", result); @@ -1560,7 +1530,6 @@ static void test_lm_track_send(void) struct nvme_lm_track_send_args args = { .result = 0, .args_size = sizeof(args), - .fd = TEST_FD, .mos = 0x1, .cdqid = 0x3, .sel = NVME_LM_SEL_DELETE_CDQ, @@ -1575,7 +1544,7 @@ static void test_lm_track_send(void) int err; set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_lm_track_send(&args); + err = nvme_lm_track_send(test_link, &args); end_mock_cmds(); check(err == 0, "returned error %d, errno %m", err); check(result == 0, "returned result %u", result); @@ -1590,7 +1559,6 @@ static void test_lm_migration_send(void) .result = 0, .data = &expected_data, .args_size = sizeof(args), - .fd = TEST_FD, .numd = 8 - 1, .mos = 0x1, .cntlid = 0x2, @@ -1620,7 +1588,7 @@ static void test_lm_migration_send(void) arbitrary(&expected_data, sizeof(expected_data)); memcpy(&data, &expected_data, sizeof(expected_data)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_lm_migration_send(&args); + err = nvme_lm_migration_send(test_link, &args); end_mock_cmds(); check(err == 0, "returned error %d, errno %m", err); check(result == 0, "returned result %u", result); @@ -1636,7 +1604,6 @@ static void test_lm_migration_recv(void) .result = 0, .data = &data, .args_size = sizeof(args), - .fd = TEST_FD, .numd = 8 - 1, .mos = 0x1, .cntlid = 0x2, @@ -1663,7 +1630,7 @@ static void test_lm_migration_recv(void) arbitrary(&expected_data, sizeof(expected_data)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_lm_migration_recv(&args); + err = nvme_lm_migration_recv(test_link, &args); end_mock_cmds(); check(err == 0, "returned error %d, errno %m", err); check(result == 0, "returned result %u", result); @@ -1682,7 +1649,11 @@ static void run_test(const char *test_name, void (*test_fn)(void)) int main(void) { + nvme_root_t r = nvme_create_root(stdout, DEFAULT_LOGLEVEL); + set_mock_fd(TEST_FD); + test_link = nvme_open(r, "NVME_TEST_FD"); + RUN_TEST(format_nvm); RUN_TEST(ns_mgmt); RUN_TEST(ns_mgmt_create); @@ -1733,4 +1704,6 @@ int main(void) RUN_TEST(lm_track_send); RUN_TEST(lm_migration_send); RUN_TEST(lm_migration_recv); + + nvme_free_root(r); } diff --git a/test/ioctl/zns.c b/test/ioctl/zns.c index 204093535..e8e3f4a5c 100644 --- a/test/ioctl/zns.c +++ b/test/ioctl/zns.c @@ -12,6 +12,8 @@ #define TEST_NSID 0x12345678 #define TEST_SLBA 0xffffffff12345678 +static nvme_link_t test_link; + static void test_zns_append(void) { __u8 expected_data[8], data[8] = {}; @@ -21,7 +23,6 @@ static void test_zns_append(void) .result = &result, .data = &data, .args_size = sizeof(args), - .fd = TEST_FD, .nsid = TEST_NSID, .data_len = sizeof(data), .nlb = 0xab, @@ -48,7 +49,7 @@ static void test_zns_append(void) arbitrary(&expected_data, sizeof(expected_data)); set_mock_io_cmds(&mock_io_cmd, 1); - err = nvme_zns_append(&args); + err = nvme_zns_append(test_link, &args); end_mock_cmds(); check(err == 0, "returned error %d, errno %m", err); check(result == 0, "wrong result"); @@ -81,7 +82,7 @@ static void test_zns_report_zones(void) arbitrary(&expected_data, sizeof(expected_data)); set_mock_io_cmds(&mock_io_cmd, 1); - err = nvme_zns_report_zones(TEST_FD, TEST_NSID, TEST_SLBA, opts, + err = nvme_zns_report_zones(test_link, TEST_NSID, TEST_SLBA, opts, extended, partial, sizeof(data), &data, timeout, &result); end_mock_cmds(); @@ -101,7 +102,6 @@ static void test_zns_mgmt_send(void) .result = &result, .data = data, .args_size = sizeof(args), - .fd = TEST_FD, .timeout = timeout, .nsid = TEST_NSID, .zsa = NVME_ZNS_ZSA_OPEN, @@ -126,7 +126,7 @@ static void test_zns_mgmt_send(void) arbitrary(&expected_data, sizeof(expected_data)); set_mock_io_cmds(&mock_io_cmd, 1); - err = nvme_zns_mgmt_send(&args); + err = nvme_zns_mgmt_send(test_link, &args); end_mock_cmds(); check(err == 0, "returned error %d, errno %m", err); check(result == 0, "returned result %u", result); @@ -169,7 +169,7 @@ static void test_zns_mgmt_recv(void) arbitrary(&expected_data, sizeof(expected_data)); set_mock_io_cmds(&mock_io_cmd, 1); - err = nvme_zns_mgmt_recv(&args); + err = nvme_zns_mgmt_recv(test_link, &args); end_mock_cmds(); check(err == 0, "returned error %d, errno %m", err); check(result == 0, "returned result %u", result); @@ -188,9 +188,15 @@ static void run_test(const char *test_name, void (*test_fn)(void)) int main(void) { + nvme_root_t r = nvme_create_root(stdout, DEFAULT_LOGLEVEL); + set_mock_fd(TEST_FD); + test_link = nvme_open(r, "NVME_TEST_FD"); + RUN_TEST(zns_append); RUN_TEST(zns_report_zones); RUN_TEST(zns_mgmt_send); RUN_TEST(zns_mgmt_recv); + + nvme_free_root(r); } diff --git a/test/test.c b/test/test.c index 15d17d4cb..6d9cc9fa4 100644 --- a/test/test.c +++ b/test/test.c @@ -39,8 +39,9 @@ static int test_ctrl(nvme_ctrl_t c) static __u8 buf[0x1000]; enum nvme_get_features_sel sel = NVME_GET_FEATURES_SEL_CURRENT; - int ret, temp, fd = nvme_ctrl_get_fd(c); - struct nvme_error_log_page error[64]; + nvme_link_t l = nvme_ctrl_get_link(c); + int ret, temp; + struct nvme_error_log_page error[64]; struct nvme_smart_log smart = { 0 }; struct nvme_firmware_slot fw = { 0 }; struct nvme_ns_list ns_list = { 0 }; @@ -69,7 +70,7 @@ static int test_ctrl(nvme_ctrl_t c) printf("PASSED: Identify controller\n"); } - ret = nvme_get_log_smart(fd, NVME_NSID_ALL, true, &smart); + ret = nvme_get_log_smart(l, NVME_NSID_ALL, true, &smart); if (ret) { printf("ERROR: no smart log for:%s %#x\n", nvme_ctrl_get_name(c), ret); return ret; @@ -88,42 +89,42 @@ static int test_ctrl(nvme_ctrl_t c) printf(" sn:%-.20s\n", id.sn); printf(" model:%-.40s\n", id.mn); - ret = nvme_identify_allocated_ns_list(fd, 0, &ns_list); + ret = nvme_identify_allocated_ns_list(l, 0, &ns_list); if (!ret) printf(" PASSED: Allocated NS List\n"); else printf(" ERROR: Allocated NS List:%x\n", ret); - ret = nvme_identify_active_ns_list(fd, 0, &ns_list); + ret = nvme_identify_active_ns_list(l, 0, &ns_list); if (!ret) printf(" PASSED: Active NS List\n"); else printf(" ERROR: Active NS List:%x\n", ret); - ret = nvme_identify_ctrl_list(fd, 0, &ctrlist); + ret = nvme_identify_ctrl_list(l, 0, &ctrlist); if (!ret) printf(" PASSED: Ctrl List\n"); else printf(" ERROR: CtrlList:%x\n", ret); - ret = nvme_identify_nsid_ctrl_list(fd, 1, 0, &ctrlist); + ret = nvme_identify_nsid_ctrl_list(l, 1, 0, &ctrlist); if (!ret) printf(" PASSED: NSID Ctrl List\n"); else printf(" ERROR: NSID CtrlList:%x\n", ret); - ret = nvme_identify_primary_ctrl(fd, 0, &prim); + ret = nvme_identify_primary_ctrl(l, 0, &prim); if (!ret) printf(" PASSED: Identify Primary\n"); else printf(" ERROR: Identify Primary:%x\n", ret); - ret = nvme_identify_secondary_ctrl_list(fd, 0, &sec); + ret = nvme_identify_secondary_ctrl_list(l, 0, &sec); if (!ret) printf(" PASSED: Identify Secondary\n"); else printf(" ERROR: Identify Secondary:%x\n", ret); - ret = nvme_identify_ns_granularity(fd, &gran); + ret = nvme_identify_ns_granularity(l, &gran); if (!ret) printf(" PASSED: Identify NS granularity\n"); else printf(" ERROR: Identify NS granularity:%x\n", ret); - ret = nvme_identify_uuid(fd, &uuid); + ret = nvme_identify_uuid(l, &uuid); if (!ret) printf(" PASSED: Identify UUID List\n"); else @@ -132,133 +133,133 @@ static int test_ctrl(nvme_ctrl_t c) printf("\nLogs\n"); printf(" SMART: Current temperature:%d percent used:%d%%\n", temp, smart.percent_used); - ret = nvme_get_log_sanitize(fd, true, &sanlog); + ret = nvme_get_log_sanitize(l, true, &sanlog); if (!ret) printf(" Sanitize Log:\n"); else printf(" ERROR: Sanitize Log:%x\n", ret); - ret = nvme_get_log_reservation(fd, true, &resvnotify); + ret = nvme_get_log_reservation(l, true, &resvnotify); if (!ret) printf(" Reservation Log\n"); else printf(" ERROR: Reservation Log:%x\n", ret); - ret = nvme_get_log_ana_groups(fd, true, sizeof(buf), analog); + ret = nvme_get_log_ana_groups(l, true, sizeof(buf), analog); if (!ret) printf(" ANA Groups\n"); else printf(" ERROR: ANA Groups:%x\n", ret); - ret = nvme_get_log_endurance_group(fd, 0, &eglog); + ret = nvme_get_log_endurance_group(l, 0, &eglog); if (!ret) printf(" Endurance Group\n"); else printf(" ERROR: Endurance Group:%x\n", ret); - ret = nvme_get_log_telemetry_ctrl(fd, true, 0, sizeof(buf), telem); + ret = nvme_get_log_telemetry_ctrl(l, true, 0, sizeof(buf), telem); if (!ret) printf(" Telemetry Controller\n"); else printf(" ERROR: Telemetry Controller:%x\n", ret); - ret = nvme_get_log_device_self_test(fd, &st); + ret = nvme_get_log_device_self_test(l, &st); if (!ret) printf(" Device Self Test\n"); else printf(" ERROR: Device Self Test:%x\n", ret); - ret = nvme_get_log_cmd_effects(fd, NVME_CSI_NVM, &cfx); + ret = nvme_get_log_cmd_effects(l, NVME_CSI_NVM, &cfx); if (!ret) printf(" Command Effects\n"); else printf(" ERROR: Command Effects:%x\n", ret); - ret = nvme_get_log_changed_ns_list(fd, true, &ns_list); + ret = nvme_get_log_changed_ns_list(l, true, &ns_list); if (!ret) printf(" Change NS List\n"); else printf(" ERROR: Change NS List:%x\n", ret); - ret = nvme_get_log_fw_slot(fd, true, &fw); + ret = nvme_get_log_fw_slot(l, true, &fw); if (!ret) printf(" FW Slot\n"); else printf(" ERROR: FW Slot%x\n", ret); - ret = nvme_get_log_error(fd, 64, true, error); + ret = nvme_get_log_error(l, 64, true, error); if (!ret) printf(" Error Log\n"); else printf(" ERROR: Error Log:%x\n", ret); printf("\nFeatures\n"); - ret = nvme_get_features_arbitration(fd, sel, &result); + ret = nvme_get_features_arbitration(l, sel, &result); if (!ret) printf(" Arbitration:%x\n", result); else if (ret > 0) printf(" ERROR: Arbitration:%x\n", ret); - ret = nvme_get_features_power_mgmt(fd, sel, &result); + ret = nvme_get_features_power_mgmt(l, sel, &result); if (!ret) printf(" Power Management:%x\n", result); else if (ret > 0) printf(" ERROR: Power Management:%x\n", ret); - ret = nvme_get_features_temp_thresh(fd, sel, 0, 0, &result); + ret = nvme_get_features_temp_thresh(l, sel, 0, 0, &result); if (!ret) printf(" Temperature Threshold:%x\n", result); else if (ret > 0) printf(" ERROR: Temperature Threshold:%x\n", ret); - ret = nvme_get_features_volatile_wc(fd, sel, &result); + ret = nvme_get_features_volatile_wc(l, sel, &result); if (!ret) printf(" Volatile Write Cache:%x\n", result); else if (ret > 0) printf(" ERROR: Volatile Write Cache:%x\n", ret); - ret = nvme_get_features_num_queues(fd, sel, &result); + ret = nvme_get_features_num_queues(l, sel, &result); if (!ret) printf(" Number of Queues:%x\n", result); else if (ret > 0) printf(" ERROR: Number of Queues:%x\n", ret); - ret = nvme_get_features_irq_coalesce(fd, sel, &result); + ret = nvme_get_features_irq_coalesce(l, sel, &result); if (!ret) printf(" IRQ Coalescing:%x\n", result); else if (ret > 0) printf(" ERROR: IRQ Coalescing:%x\n", ret); - ret = nvme_get_features_write_atomic(fd, sel, &result); + ret = nvme_get_features_write_atomic(l, sel, &result); if (!ret) printf(" Write Atomic:%x\n", result); else if (ret > 0) printf(" ERROR: Write Atomic:%x\n", ret); - ret = nvme_get_features_async_event(fd, sel, &result); + ret = nvme_get_features_async_event(l, sel, &result); if (!ret) printf(" Asycn Event Config:%x\n", result); else if (ret > 0) printf(" ERROR: Asycn Event Config:%x\n", ret); - ret = nvme_get_features_hctm(fd, sel, &result); + ret = nvme_get_features_hctm(l, sel, &result); if (!ret) printf(" HCTM:%x\n", result); else if (ret > 0) printf(" ERROR: HCTM:%x\n", ret); - ret = nvme_get_features_nopsc(fd, sel, &result); + ret = nvme_get_features_nopsc(l, sel, &result); if (!ret) printf(" NOP Power State Config:%x\n", result); else if (ret > 0) printf(" ERROR: NOP Power State Configrbitration:%x\n", ret); - ret = nvme_get_features_rrl(fd, sel, &result); + ret = nvme_get_features_rrl(l, sel, &result); if (!ret) printf(" Read Recover Levels:%x\n", result); else if (ret > 0) printf(" ERROR: Read Recover Levels:%x\n", ret); - ret = nvme_get_features_lba_sts_interval(fd, sel, &result); + ret = nvme_get_features_lba_sts_interval(l, sel, &result); if (!ret) printf(" LBA Status Interval:%x\n", result); else if (ret > 0) printf(" ERROR: LBA Status Interval:%x\n", ret); - ret = nvme_get_features_sanitize(fd, sel, &result); + ret = nvme_get_features_sanitize(l, sel, &result); if (!ret) printf(" Sanitize:%x\n", result); else if (ret > 0) printf(" ERROR: SW Progress Marker:%x\n", ret); - ret = nvme_get_features_sw_progress(fd, sel, &result); + ret = nvme_get_features_sw_progress(l, sel, &result); if (!ret) printf(" SW Progress Marker:%x\n", result); else if (ret > 0) printf(" ERROR: Sanitize:%x\n", ret); - ret = nvme_get_features_resv_mask(fd, sel, 0, &result); + ret = nvme_get_features_resv_mask(l, sel, 0, &result); if (!ret) printf(" Reservation Mask:%x\n", result); else if (ret > 0) printf(" ERROR: Reservation Mask:%x\n", ret); - ret = nvme_get_features_resv_persist(fd, sel, 0, &result); + ret = nvme_get_features_resv_persist(l, sel, 0, &result); if (!ret) printf(" Reservation Persistence:%x\n", result); else if (ret > 0) @@ -268,7 +269,8 @@ static int test_ctrl(nvme_ctrl_t c) static int test_namespace(nvme_ns_t n) { - int ret, nsid = nvme_ns_get_nsid(n), fd = nvme_ns_get_fd(n); + int ret, nsid = nvme_ns_get_nsid(n); + nvme_link_t l = nvme_ns_get_link(n); struct nvme_id_ns ns = { 0 }, allocated = { 0 }; struct nvme_ns_id_desc *descs; __u32 result = 0; @@ -283,7 +285,7 @@ static int test_namespace(nvme_ns_t n) nvme_ns_get_name(n), le64_to_cpu(ns.nsze), 1 << ns.lbaf[flbas].ds); - ret = nvme_identify_allocated_ns(fd, nsid, &allocated); + ret = nvme_identify_allocated_ns(l, nsid, &allocated); if (!ret) printf(" Identify allocated ns\n"); else @@ -292,13 +294,13 @@ static int test_namespace(nvme_ns_t n) if (!descs) return -1; - ret = nvme_identify_ns_descs(fd, nsid, descs); + ret = nvme_identify_ns_descs(l, nsid, descs); if (!ret) printf(" Identify NS Descriptors\n"); else printf(" ERROR: Identify NS Descriptors:%x\n", ret); free(descs); - ret = nvme_get_features_write_protect(fd, nsid, + ret = nvme_get_features_write_protect(l, nsid, NVME_GET_FEATURES_SEL_CURRENT, &result); if (!ret) printf(" Write Protect:%x\n", result); diff --git a/test/zns.c b/test/zns.c index c2a22afd3..0e4e90ef5 100644 --- a/test/zns.c +++ b/test/zns.c @@ -29,7 +29,7 @@ static void show_zns_properties(nvme_ns_t n) if (!zr) return; - if (nvme_zns_identify_ns(nvme_ns_get_fd(n), nvme_ns_get_nsid(n), + if (nvme_zns_identify_ns(nvme_ns_get_link(n), nvme_ns_get_nsid(n), &zns_ns)) { fprintf(stderr, "failed to identify zns ns\n");; } @@ -38,7 +38,7 @@ static void show_zns_properties(nvme_ns_t n) le16_to_cpu(zns_ns.ozcs), le32_to_cpu(zns_ns.mar), le32_to_cpu(zns_ns.mor)); - if (nvme_zns_identify_ctrl(nvme_ns_get_fd(n), &zns_ctrl)) { + if (nvme_zns_identify_ctrl(nvme_ns_get_link(n), &zns_ctrl)) { fprintf(stderr, "failed to identify zns ctrl\n");; free(zr); return; @@ -46,7 +46,7 @@ static void show_zns_properties(nvme_ns_t n) printf("zasl:%u\n", zns_ctrl.zasl); - if (nvme_zns_report_zones(nvme_ns_get_fd(n), nvme_ns_get_nsid(n), 0, + if (nvme_zns_report_zones(nvme_ns_get_link(n), nvme_ns_get_nsid(n), 0, NVME_ZNS_ZRAS_REPORT_ALL, false, true, 0x1000, (void *)zr, NVME_DEFAULT_IOCTL_TIMEOUT, &result)) { From 6a31e42bc7d61e34147d95f67cc6da07965a9aa8 Mon Sep 17 00:00:00 2001 From: Tokunori Ikegami Date: Wed, 3 Sep 2025 08:09:33 +0900 Subject: [PATCH 03/66] ioctl: fix get_log_partial to use uring for link type direct Since uring not supported for link type mi. Signed-off-by: Tokunori Ikegami --- src/nvme/ioctl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nvme/ioctl.c b/src/nvme/ioctl.c index 7bc646bd3..a333d6401 100644 --- a/src/nvme/ioctl.c +++ b/src/nvme/ioctl.c @@ -474,7 +474,7 @@ int nvme_get_log_page(nvme_link_t l, __u32 xfer_len, struct nvme_get_log_args *a struct stat st; bool use_uring = false; - if (io_uring_kernel_support == IO_URING_AVAILABLE) { + if (io_uring_kernel_support == IO_URING_AVAILABLE && l->type == NVME_LINK_TYPE_DIRECT) { if (fstat(l->fd, &st) == 0 && S_ISCHR(st.st_mode)) { use_uring = true; From e41691eea6e30b288b0b1237a7db3f812c05cf01 Mon Sep 17 00:00:00 2001 From: Daniel Wagner Date: Tue, 27 May 2025 08:29:10 +0200 Subject: [PATCH 04/66] api-types: remove unused fd members There is no user left for the file descriptor in the args structs, thus remove it. Signed-off-by: Daniel Wagner --- src/nvme/api-types.h | 72 -------------------------------------------- test/ioctl/misc.c | 1 - test/ioctl/zns.c | 1 - 3 files changed, 74 deletions(-) diff --git a/src/nvme/api-types.h b/src/nvme/api-types.h index 68d49801d..638de13a9 100644 --- a/src/nvme/api-types.h +++ b/src/nvme/api-types.h @@ -54,7 +54,6 @@ void nvme_free_root(nvme_root_t r); * @result: The command completion result from CQE dword0 * @data: User space destination address to transfer the data * @args_size: Size of &struct nvme_identify_args - * @fd: File descriptor of nvme device * @timeout: Timeout in ms (0 for default timeout) * @cns: The Controller or Namespace structure, see @enum nvme_identify_cns * @csi: Command Set Identifier @@ -67,7 +66,6 @@ struct nvme_identify_args { __u32 *result; void *data; int args_size; - int fd; __u32 timeout; enum nvme_identify_cns cns; enum nvme_csi csi; @@ -83,7 +81,6 @@ struct nvme_identify_args { * @result: The command completion result from CQE dword0 * @log: User space destination address to transfer the data * @args_size: Length of the structure - * @fd: File descriptor of nvme device * @timeout: Timeout in ms * @lid: Log page identifier, see &enum nvme_cmd_get_log_lid for known * values @@ -103,7 +100,6 @@ struct nvme_get_log_args { __u32 *result; void *log; int args_size; - int fd; __u32 timeout; enum nvme_cmd_get_log_lid lid; __u32 len; @@ -121,7 +117,6 @@ struct nvme_get_log_args { * @result: The command completion result from CQE dword0 * @data: User address of feature data, if applicable * @args_size: Size of &struct nvme_set_features_args - * @fd: File descriptor of nvme device * @timeout: Timeout in ms * @nsid: Namespace ID, if applicable * @cdw11: Value to set the feature to @@ -137,7 +132,6 @@ struct nvme_set_features_args { __u32 *result; void *data; int args_size; - int fd; __u32 timeout; __u32 nsid; __u32 cdw11; @@ -153,7 +147,6 @@ struct nvme_set_features_args { /** * struct nvme_get_features_args - Arguments for the NVMe Admin Get Feature command * @args_size: Size of &struct nvme_get_features_args - * @fd: File descriptor of nvme device * @result: The command completion result from CQE dword0 * @timeout: Timeout in ms * @nsid: Namespace ID, if applicable @@ -169,7 +162,6 @@ struct nvme_get_features_args { __u32 *result; void *data; int args_size; - int fd; __u32 timeout; __u32 nsid; enum nvme_get_features_sel sel; @@ -183,7 +175,6 @@ struct nvme_get_features_args { * struct nvme_format_nvm_args - Arguments for the Format Nvme Namespace command * @result: The command completion result from CQE dword0 * @args_size: Size of &struct nvme_format_nvm_args - * @fd: File descriptor of nvme device * @timeout: Set to override default timeout to this value in milliseconds; * useful for long running formats. 0 will use system default. * @nsid: Namespace ID to format @@ -198,7 +189,6 @@ struct nvme_get_features_args { struct nvme_format_nvm_args { __u32 *result; int args_size; - int fd; __u32 timeout; __u32 nsid; enum nvme_cmd_format_mset mset; @@ -215,7 +205,6 @@ struct nvme_format_nvm_args { * @result: NVMe command result * @ns: Namespace identification descriptors * @args_size: Size of &struct nvme_ns_mgmt_args - * @fd: File descriptor of nvme device * @timeout: Timeout in ms * @nsid: Namespace identifier * @sel: Type of management operation to perform @@ -228,7 +217,6 @@ struct nvme_ns_mgmt_args { __u32 *result; struct nvme_id_ns *ns; int args_size; - int fd; __u32 timeout; __u32 nsid; enum nvme_ns_mgmt_sel sel; @@ -243,7 +231,6 @@ struct nvme_ns_mgmt_args { * @result: NVMe command result * @ctrlist: Controller list to modify attachment state of nsid * @args_size: Size of &struct nvme_ns_attach_args - * @fd: File descriptor of nvme device * @timeout: Timeout in ms * @nsid: Namespace ID to execute attach selection * @sel: Attachment selection, see &enum nvme_ns_attach_sel @@ -252,7 +239,6 @@ struct nvme_ns_attach_args { __u32 *result; struct nvme_ctrl_list *ctrlist; int args_size; - int fd; __u32 timeout; __u32 nsid; enum nvme_ns_attach_sel sel; @@ -261,7 +247,6 @@ struct nvme_ns_attach_args { /** * struct nvme_fw_download_args - Arguments for the NVMe Firmware Download command * @args_size: Size of &struct nvme_fw_download_args - * @fd: File descriptor of nvme device * @result: The command completion result from CQE dword0 * @timeout: Timeout in ms * @offset: Offset in the firmware data @@ -272,7 +257,6 @@ struct nvme_fw_download_args { __u32 *result; void *data; int args_size; - int fd; __u32 timeout; __u32 offset; __u32 data_len; @@ -301,7 +285,6 @@ struct nvme_fw_commit_args { * @result: The command completion result from CQE dword0 * @data: Security data payload to send * @args_size: Size of &struct nvme_security_send_args - * @fd: File descriptor of nvme device * @timeout: Timeout in ms * @nsid: Namespace ID to issue security command on * @tl: Protocol specific transfer length @@ -315,7 +298,6 @@ struct nvme_security_send_args { __u32 *result; void *data; int args_size; - int fd; __u32 timeout; __u32 nsid; __u32 tl; @@ -331,7 +313,6 @@ struct nvme_security_send_args { * @result: The command completion result from CQE dword0 * @data: Security data payload to send * @args_size: Size of &struct nvme_security_receive_args - * @fd: File descriptor of nvme device * @timeout: Timeout in ms * @nsid: Namespace ID to issue security command on * @al: Protocol specific allocation length @@ -345,7 +326,6 @@ struct nvme_security_receive_args { __u32 *result; void *data; int args_size; - int fd; __u32 timeout; __u32 nsid; __u32 al; @@ -362,7 +342,6 @@ struct nvme_security_receive_args { * @result: The command completion result from CQE dword0 * @slba: Starting logical block address to check statuses * @args_size: Size of &struct nvme_get_lba_status_args - * @fd: File descriptor of nvme device * @timeout: Timeout in ms * @nsid: Namespace ID to retrieve LBA status * @mndw: Maximum number of dwords to return @@ -375,7 +354,6 @@ struct nvme_get_lba_status_args { __u32 *result; struct nvme_lba_status *lbas; int args_size; - int fd; __u32 timeout; __u32 nsid; __u32 mndw; @@ -388,7 +366,6 @@ struct nvme_get_lba_status_args { * @result: If successful, the CQE dword0 value * @data: Data payload to be send * @args_size: Size of &struct nvme_directive_send_args - * @fd: File descriptor of nvme device * @timeout: Timeout in ms * @nsid: Namespace ID, if applicable * @doper: Directive send operation, see &enum nvme_directive_send_doper @@ -401,7 +378,6 @@ struct nvme_directive_send_args { __u32 *result; void *data; int args_size; - int fd; __u32 timeout; __u32 nsid; enum nvme_directive_send_doper doper; @@ -416,7 +392,6 @@ struct nvme_directive_send_args { * @result: If successful, the CQE dword0 value * @data: Userspace address of data payload * @args_size: Size of &struct nvme_directive_recv_args - * @fd: File descriptor of nvme device * @timeout: Timeout in ms * @nsid: Namespace ID, if applicable * @doper: Directive send operation, see &enum nvme_directive_send_doper @@ -429,7 +404,6 @@ struct nvme_directive_recv_args { __u32 *result; void *data; int args_size; - int fd; __u32 timeout; __u32 nsid; enum nvme_directive_receive_doper doper; @@ -443,7 +417,6 @@ struct nvme_directive_recv_args { * struct nvme_capacity_mgmt_args - Arguments for the NVMe Capacity Management command * @result: If successful, the CQE dword0 value * @args_size: Size of &struct nvme_capacity_mgmt_args - * @fd: File descriptor of nvme device * @cdw11: Least significant 32 bits of the capacity in bytes of the * Endurance Group or NVM Set to be created * @cdw12: Most significant 32 bits of the capacity in bytes of the @@ -455,7 +428,6 @@ struct nvme_directive_recv_args { struct nvme_capacity_mgmt_args { __u32 *result; int args_size; - int fd; __u32 timeout; __u32 cdw11; __u32 cdw12; @@ -466,7 +438,6 @@ struct nvme_capacity_mgmt_args { /** * struct nvme_lockdown_args - Arguments for the NVME Lockdown command * @args_size: Size of &struct nvme_lockdown_args - * @fd: File descriptor of nvme device * @result: The command completion result from CQE dword0 * @timeout: Timeout in ms (0 for default timeout) * @scp: Scope of the command @@ -478,7 +449,6 @@ struct nvme_capacity_mgmt_args { struct nvme_lockdown_args { __u32 *result; int args_size; - int fd; __u32 timeout; __u8 scp; __u8 prhbt; @@ -490,7 +460,6 @@ struct nvme_lockdown_args { /** * struct nvme_set_property_args - Arguments for NVMe Set Property command * @args_size: Size of &struct nvme_set_property_args - * @fd: File descriptor of nvme device * @result: The command completion result from CQE dword0 * @timeout: Timeout in ms * @offset: Property offset from the base to set @@ -500,7 +469,6 @@ struct nvme_set_property_args { __u64 value; __u32 *result; int args_size; - int fd; __u32 timeout; int offset; }; @@ -509,14 +477,12 @@ struct nvme_set_property_args { * struct nvme_get_property_args - Arguments for NVMe Get Property command * @value: Where the property's value will be stored on success * @args_size: Size of &struct nvme_get_property_args - * @fd: File descriptor of nvme device * @offset: Property offset from the base to retrieve * @timeout: Timeout in ms */ struct nvme_get_property_args { __u64 *value; int args_size; - int fd; __u32 timeout; int offset; }; @@ -525,7 +491,6 @@ struct nvme_get_property_args { * struct nvme_sanitize_nvm_args - Arguments for the NVMe Sanitize NVM command * @result: The command completion result from CQE dword0 * @args_size: Size of &struct nvme_sanitize_nvm_args - * @fd: File descriptor of nvme device * @timeout: Timeout in ms * @ovrpat: Overwrite pattern * @sanact: Sanitize action, see &enum nvme_sanitize_sanact @@ -538,7 +503,6 @@ struct nvme_get_property_args { struct nvme_sanitize_nvm_args { __u32 *result; int args_size; - int fd; __u32 timeout; enum nvme_sanitize_sanact sanact; __u32 ovrpat; @@ -553,7 +517,6 @@ struct nvme_sanitize_nvm_args { * struct nvme_dev_self_test_args - Arguments for the NVMe Device Self Test command * @result: The command completion result from CQE dword0 * @args_size: Size of &struct nvme_dev_self_test_args - * @fd: File descriptor of nvme device * @nsid: Namespace ID to test * @stc: Self test code, see &enum nvme_dst_stc * @timeout: Timeout in ms @@ -561,7 +524,6 @@ struct nvme_sanitize_nvm_args { struct nvme_dev_self_test_args { __u32 *result; int args_size; - int fd; __u32 timeout; __u32 nsid; enum nvme_dst_stc stc; @@ -571,7 +533,6 @@ struct nvme_dev_self_test_args { * struct nvme_virtual_mgmt_args - Arguments for the NVMe Virtualization * resource management command * @args_size: Size of &struct nvme_virtual_mgmt_args - * @fd: File descriptor of nvme device * @result: If successful, the CQE dword0 * @timeout: Timeout in ms * @act: Virtual resource action, see &enum nvme_virt_mgmt_act @@ -582,7 +543,6 @@ struct nvme_dev_self_test_args { struct nvme_virtual_mgmt_args { __u32 *result; int args_size; - int fd; __u32 timeout; enum nvme_virt_mgmt_act act; enum nvme_virt_mgmt_rt rt; @@ -599,7 +559,6 @@ struct nvme_virtual_mgmt_args { * @data: Pointer to user address of the data buffer * @metadata: Pointer to user address of the metadata buffer * @args_size: Size of &struct nvme_io_args - * @fd: File descriptor of nvme device * @timeout: Timeout in ms * @nsid: Namespace ID * @data_len: Length of user buffer, @data, in bytes @@ -636,7 +595,6 @@ struct nvme_io_args { void *data; void *metadata; int args_size; - int fd; __u32 timeout; __u32 nsid; __u32 reftag; @@ -659,7 +617,6 @@ struct nvme_io_args { * @result: The command completion result from CQE dword0 * @dsm: The data set management attributes * @args_size: Size of &struct nvme_dsm_args - * @fd: File descriptor of nvme device * @timeout: Timeout in ms * @nsid: Namespace identifier * @attrs: DSM attributes, see &enum nvme_dsm_attributes @@ -669,7 +626,6 @@ struct nvme_dsm_args { __u32 *result; struct nvme_dsm_range *dsm; int args_size; - int fd; __u32 timeout; __u32 nsid; __u32 attrs; @@ -682,7 +638,6 @@ struct nvme_dsm_args { * @result: The command completion result from CQE dword0 * @copy: Range description * @args_size: Size of &struct nvme_copy_args - * @fd: File descriptor of the nvme device * @timeout: Timeout in ms * @nsid: Namespace identifier * @ilbrt: Initial logical block reference tag @@ -704,7 +659,6 @@ struct nvme_copy_args { __u32 *result; struct nvme_copy_range *copy; int args_size; - int fd; __u32 timeout; __u32 nsid; __u32 ilbrt; @@ -728,7 +682,6 @@ struct nvme_copy_args { * @iekey: Set to ignore the existing key * @result: The command completion result from CQE dword0 * @args_size: Size of &struct nvme_resv_acquire_args - * @fd: File descriptor of nvme device * @timeout: Timeout in ms * @nsid: Namespace identifier * @rtype: The type of reservation to be create, see &enum nvme_resv_rtype @@ -740,7 +693,6 @@ struct nvme_resv_acquire_args { __u64 nrkey; __u32 *result; int args_size; - int fd; __u32 timeout; __u32 nsid; enum nvme_resv_rtype rtype; @@ -755,7 +707,6 @@ struct nvme_resv_acquire_args { * replace * @result: The command completion result from CQE dword0 * @args_size: Size of &struct nvme_resv_register_args - * @fd: File descriptor of nvme device * @nsid: Namespace identifier * @rrega: The registration action, see &enum nvme_resv_rrega * @cptpl: Change persist through power loss, see &enum nvme_resv_cptpl @@ -767,7 +718,6 @@ struct nvme_resv_register_args { __u64 nrkey; __u32 *result; int args_size; - int fd; __u32 timeout; __u32 nsid; enum nvme_resv_rrega rrega; @@ -780,7 +730,6 @@ struct nvme_resv_register_args { * @crkey: The current reservation key to release * @result: The command completion result from CQE dword0 * @args_size: Size of &struct nvme_resv_release_args - * @fd: File descriptor of nvme device * @timeout: Timeout in ms * @nsid: Namespace identifier * @rtype: The type of reservation to be create, see &enum nvme_resv_rtype @@ -791,7 +740,6 @@ struct nvme_resv_release_args { __u64 crkey; __u32 *result; int args_size; - int fd; __u32 timeout; __u32 nsid; enum nvme_resv_rtype rtype; @@ -805,7 +753,6 @@ struct nvme_resv_release_args { * @report: The user space destination address to store the reservation * report * @args_size: Size of &struct nvme_resv_report_args - * @fd: File descriptor of nvme device * @timeout: Timeout in ms * @nsid: Namespace identifier * @len: Number of bytes to request transferred with this command @@ -815,7 +762,6 @@ struct nvme_resv_report_args { __u32 *result; struct nvme_resv_status *report; int args_size; - int fd; __u32 timeout; __u32 nsid; __u32 len; @@ -826,7 +772,6 @@ struct nvme_resv_report_args { * struct nvme_io_mgmt_recv_args - Arguments for the NVMe I/O Management Receive command * @data: Userspace address of the data * @args_size: Size of &struct nvme_io_mgmt_recv_args - * @fd: File descriptor of nvme device * @nsid: Namespace identifier * @data_len: Length of @data * @timeout: Timeout in ms @@ -836,7 +781,6 @@ struct nvme_resv_report_args { struct nvme_io_mgmt_recv_args { void *data; int args_size; - int fd; __u32 nsid; __u32 data_len; __u32 timeout; @@ -848,7 +792,6 @@ struct nvme_io_mgmt_recv_args { * struct nvme_io_mgmt_send_args - Arguments for the NVMe I/O Management Send command * @data: Userspace address of the data * @args_size: Size of &struct nvme_io_mgmt_send_args - * @fd: File descriptor of nvme device * @nsid: Namespace identifier * @data_len: Length of @data * @timeout: Timeout in ms @@ -858,7 +801,6 @@ struct nvme_io_mgmt_recv_args { struct nvme_io_mgmt_send_args { void *data; int args_size; - int fd; __u32 nsid; __u32 data_len; __u32 timeout; @@ -872,7 +814,6 @@ struct nvme_io_mgmt_send_args { * @result: The command completion result from CQE dword0 * @data: Userspace address of the data * @args_size: Size of &struct nvme_zns_mgmt_send_args - * @fd: File descriptor of nvme device * @timeout: timeout in ms * @nsid: Namespace ID * @zsa: Zone send action @@ -885,7 +826,6 @@ struct nvme_zns_mgmt_send_args { __u32 *result; void *data; int args_size; - int fd; __u32 timeout; __u32 nsid; enum nvme_zns_send_action zsa; @@ -900,7 +840,6 @@ struct nvme_zns_mgmt_send_args { * @result: The command completion result from CQE dword0 * @data: Userspace address of the data * @args_size: Size of &struct nvme_zns_mgmt_recv_args - * @fd: File descriptor of nvme device * @timeout: timeout in ms * @nsid: Namespace ID * @zra: zone receive action @@ -913,7 +852,6 @@ struct nvme_zns_mgmt_recv_args { __u32 *result; void *data; int args_size; - int fd; __u32 timeout; __u32 nsid; enum nvme_zns_recv_action zra; @@ -929,7 +867,6 @@ struct nvme_zns_mgmt_recv_args { * @data: Userspace address of the data * @metadata: Userspace address of the metadata * @args_size: Size of &struct nvme_zns_append_args - * @fd: File descriptor of nvme device * @timeout: Timeout in ms * @nsid: Namespace ID * @ilbrt: Initial logical block reference tag @@ -950,7 +887,6 @@ struct nvme_zns_append_args { void *data; void *metadata; int args_size; - int fd; __u32 timeout; __u32 nsid; __u32 ilbrt; @@ -969,7 +905,6 @@ struct nvme_zns_append_args { * @result: Set on completion to the command's CQE DWORD 0 controller response. * @data: Pointer to the DIM data * @args_size: Length of the structure - * @fd: File descriptor of nvme device * @timeout: Timeout in ms * @data_len: Length of @data * @tas: Task field of the Command Dword 10 (cdw10) @@ -978,7 +913,6 @@ struct nvme_dim_args { __u32 *result; void *data; int args_size; - int fd; __u32 timeout; __u32 data_len; __u8 tas; @@ -989,7 +923,6 @@ struct nvme_dim_args { * @result: Set on completion to the command's CQE DWORD 0 controller response * @data: Pointer to data * @args_size: Length of structure - * @fd: File descriptor of nvme device * @timeout: Timeout in ms * @mos: Management Operation Specific (MOS): This field is specific to the SEL type * @cntlid: Controller ID: For Create CDQ, specifies the target migratable controller @@ -1005,7 +938,6 @@ struct nvme_lm_cdq_args { __u32 *result; void *data; int args_size; - int fd; __u32 timeout; __u16 mos; __u16 cntlid; @@ -1020,7 +952,6 @@ struct nvme_lm_cdq_args { * struct nvme_lm_track_send_args - Arguments for the Track Send command * @result: Set on completion to the command's CQE DWORD 0 controller response * @args_size: Length of structure - * @fd: File descriptor of nvme device * @timeout: Timeout in ms * @mos: Management Operation Specific (MOS): This field is specific to the SEL type * @cdqid: Controller Data Queue ID (CDQID) @@ -1029,7 +960,6 @@ struct nvme_lm_cdq_args { struct nvme_lm_track_send_args { __u32 *result; int args_size; - int fd; __u32 timeout; __u16 mos; __u16 cdqid; @@ -1044,7 +974,6 @@ struct nvme_lm_track_send_args { * @result: Set on completion to the command's CQE DWORD 0 controller response * @data: Pointer to data * @args_size: Length of structure - * @fd: File descriptor of nvme device * @timeout: Timeout in ms * @numd: Number of Dwords (NUMD): This field specifies the number of dwords being transferred * @mos: Management Operation Specific (MOS): This field is specific to the SEL type @@ -1071,7 +1000,6 @@ struct nvme_lm_migration_send_args { __u32 *result; void *data; int args_size; - int fd; __u32 timeout; __u32 numd; __u16 mos; diff --git a/test/ioctl/misc.c b/test/ioctl/misc.c index 2b00e3a2c..dfb0846e2 100644 --- a/test/ioctl/misc.c +++ b/test/ioctl/misc.c @@ -322,7 +322,6 @@ static void test_security_send(void) .result = &result, .data = &expected_data, .args_size = sizeof(args), - .fd = TEST_FD, .nsid = TEST_NSID, .tl = 0xffff, .data_len = sizeof(expected_data), diff --git a/test/ioctl/zns.c b/test/ioctl/zns.c index e8e3f4a5c..5bc55b2b1 100644 --- a/test/ioctl/zns.c +++ b/test/ioctl/zns.c @@ -145,7 +145,6 @@ static void test_zns_mgmt_recv(void) .result = &result, .data = data, .args_size = sizeof(args), - .fd = TEST_FD, .timeout = timeout, .nsid = TEST_NSID, .zra = NVME_ZNS_ZRA_REPORT_ZONES, From fc14a7e9d9eb74e46c361bbf6b6d919a7c57a208 Mon Sep 17 00:00:00 2001 From: Daniel Wagner Date: Wed, 28 May 2025 09:46:49 +0200 Subject: [PATCH 05/66] linux: add nvme_link_get_fd When the user provides their own implemention of the passtrhu function, it is necessary to use the file descriptor for the ioctl call. Thus allow to retrieve the file descriptor from the link handle. Signed-off-by: Daniel Wagner --- src/libnvme.map | 1 + src/nvme/linux.c | 5 +++++ src/nvme/linux.h | 11 +++++++++++ 3 files changed, 17 insertions(+) diff --git a/src/libnvme.map b/src/libnvme.map index 6d52da677..7faa6502f 100644 --- a/src/libnvme.map +++ b/src/libnvme.map @@ -173,6 +173,7 @@ LIBNVME_2_0 { nvme_io_passthru64; nvme_io_passthru; nvme_ipaddrs_eq; + nvme_link_get_fd; nvme_lm_cdq; nvme_lm_get_features_ctrl_data_queue; nvme_lm_migration_recv; diff --git a/src/nvme/linux.c b/src/nvme/linux.c index bd5bc2e38..f4a864f57 100644 --- a/src/nvme/linux.c +++ b/src/nvme/linux.c @@ -119,6 +119,11 @@ void nvme_close(nvme_link_t l) free(l); } +int nvme_link_get_fd(nvme_link_t l) +{ + return l->fd; +} + int nvme_fw_download_seq(nvme_link_t l, __u32 size, __u32 xfer, __u32 offset, void *buf) { diff --git a/src/nvme/linux.h b/src/nvme/linux.h index b39dec0f7..a7ccd8ce4 100644 --- a/src/nvme/linux.h +++ b/src/nvme/linux.h @@ -200,6 +200,17 @@ nvme_link_t nvme_open(nvme_root_t r, const char *name); */ void nvme_close(nvme_link_t l); +/** + * nvme_link_get_fd - Return file descriptor for link handle + * @l: Link handle + * + * If the device handle is for a ioctl based device, nvme_link_get_fd + * will return a valid file descriptor. + * + * Return: File descriptor for an IOCTL based link handle, otherwise -1. + */ +int nvme_link_get_fd(nvme_link_t l); + /** * enum nvme_hmac_alg - HMAC algorithm * @NVME_HMAC_ALG_NONE: No HMAC algorithm From fa1a3f1190f84dde83290b757c5d08d7747b0a39 Mon Sep 17 00:00:00 2001 From: Daniel Wagner Date: Wed, 4 Jun 2025 11:20:42 +0200 Subject: [PATCH 06/66] linux: add nvme_link_get_name nvme-cli wants to retrieve the name of the device, add a getter for this. Signed-off-by: Daniel Wagner --- src/libnvme.map | 1 + src/nvme/linux.c | 18 ++++++++++++++++-- src/nvme/linux.h | 8 ++++++++ src/nvme/private.h | 3 +++ 4 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/libnvme.map b/src/libnvme.map index 7faa6502f..789209df6 100644 --- a/src/libnvme.map +++ b/src/libnvme.map @@ -174,6 +174,7 @@ LIBNVME_2_0 { nvme_io_passthru; nvme_ipaddrs_eq; nvme_link_get_fd; + nvme_link_get_name; nvme_lm_cdq; nvme_lm_get_features_ctrl_data_queue; nvme_lm_migration_recv; diff --git a/src/nvme/linux.c b/src/nvme/linux.c index f4a864f57..f3e6ee466 100644 --- a/src/nvme/linux.c +++ b/src/nvme/linux.c @@ -82,9 +82,15 @@ nvme_link_t nvme_open(nvme_root_t r, const char *name) } c = ret == 1; - l->fd = __nvme_open_dev(name); - if (l->fd < 0) + l->name = strdup(name); + if (!l->name) { + errno = ENOMEM; goto free_link; + } + + l->fd = __nvme_open_dev(l->name); + if (l->fd < 0) + goto free_name; ret = fstat(l->fd, &stat); if (ret < 0) @@ -104,6 +110,8 @@ nvme_link_t nvme_open(nvme_root_t r, const char *name) close_fd: close(l->fd); +free_name: + free(l->name); free_link: free(l); return NULL; @@ -115,6 +123,7 @@ void nvme_close(nvme_link_t l) return; close(l->fd); + free(l->name); free(l->log); free(l); } @@ -124,6 +133,11 @@ int nvme_link_get_fd(nvme_link_t l) return l->fd; } +const char *nvme_link_get_name(nvme_link_t l) +{ + return l->name; +} + int nvme_fw_download_seq(nvme_link_t l, __u32 size, __u32 xfer, __u32 offset, void *buf) { diff --git a/src/nvme/linux.h b/src/nvme/linux.h index a7ccd8ce4..990e1ccf4 100644 --- a/src/nvme/linux.h +++ b/src/nvme/linux.h @@ -211,6 +211,14 @@ void nvme_close(nvme_link_t l); */ int nvme_link_get_fd(nvme_link_t l); +/** + * nvme_link_get_name - Return name of the device link handle + * @l: Link handle + * + * Return: Device file name, otherwise -1. + */ +const char *nvme_link_get_name(nvme_link_t l); + /** * enum nvme_hmac_alg - HMAC algorithm * @NVME_HMAC_ALG_NONE: No HMAC algorithm diff --git a/src/nvme/private.h b/src/nvme/private.h index c2849ba27..8d0560188 100644 --- a/src/nvme/private.h +++ b/src/nvme/private.h @@ -32,6 +32,9 @@ struct nvme_log { struct nvme_link { struct nvme_root *root; + char *name; + + /* direct */ int fd; struct nvme_log *log; From e602ac8f9eeccb55e2ba02770e17435340cfc008 Mon Sep 17 00:00:00 2001 From: Daniel Wagner Date: Thu, 5 Jun 2025 17:34:11 +0200 Subject: [PATCH 07/66] linux: add nvme_link_is_{blk|char}dev Signed-off-by: Daniel Wagner --- src/libnvme.map | 2 ++ src/nvme/linux.c | 17 +++++++++++++---- src/nvme/linux.h | 16 ++++++++++++++++ src/nvme/private.h | 2 ++ 4 files changed, 33 insertions(+), 4 deletions(-) diff --git a/src/libnvme.map b/src/libnvme.map index 789209df6..c23fb9a95 100644 --- a/src/libnvme.map +++ b/src/libnvme.map @@ -175,6 +175,8 @@ LIBNVME_2_0 { nvme_ipaddrs_eq; nvme_link_get_fd; nvme_link_get_name; + nvme_link_is_blkdev; + nvme_link_is_chardev; nvme_lm_cdq; nvme_lm_get_features_ctrl_data_queue; nvme_lm_migration_recv; diff --git a/src/nvme/linux.c b/src/nvme/linux.c index f3e6ee466..9fa0c7a81 100644 --- a/src/nvme/linux.c +++ b/src/nvme/linux.c @@ -59,7 +59,6 @@ nvme_link_t nvme_open(nvme_root_t r, const char *name) { nvme_link_t l; int ret, id, ns; - struct stat stat; bool c; l = malloc(sizeof(*l)); @@ -92,16 +91,16 @@ nvme_link_t nvme_open(nvme_root_t r, const char *name) if (l->fd < 0) goto free_name; - ret = fstat(l->fd, &stat); + ret = fstat(l->fd, &l->stat); if (ret < 0) goto close_fd; if (c) { - if (!S_ISCHR(stat.st_mode)) { + if (!S_ISCHR(l->stat.st_mode)) { errno = EINVAL; goto close_fd; } - } else if (!S_ISBLK(stat.st_mode)) { + } else if (!S_ISBLK(l->stat.st_mode)) { errno = EINVAL; goto close_fd; } @@ -133,6 +132,16 @@ int nvme_link_get_fd(nvme_link_t l) return l->fd; } +bool nvme_link_is_blkdev(nvme_link_t l) +{ + return S_ISBLK(l->stat.st_mode); +} + +bool nvme_link_is_chardev(nvme_link_t l) +{ + return S_ISCHR(l->stat.st_mode); +} + const char *nvme_link_get_name(nvme_link_t l) { return l->name; diff --git a/src/nvme/linux.h b/src/nvme/linux.h index 990e1ccf4..4e4736c16 100644 --- a/src/nvme/linux.h +++ b/src/nvme/linux.h @@ -211,6 +211,22 @@ void nvme_close(nvme_link_t l); */ int nvme_link_get_fd(nvme_link_t l); +/** + * nvme_link_is_blkdev - Check if link handle is a block device + * @l: Link handle + * + * Return: Return true if link handle is a block device, otherwise false. + */ +bool nvme_link_is_blkdev(nvme_link_t l); + +/** + * nvme_link_is_chardev - Check if link handle is a char device + * @l: Link handle + * + * Return: Return true if link handle is a char device, otherwise false. + */ +bool nvme_link_is_chardev(nvme_link_t l); + /** * nvme_link_get_name - Return name of the device link handle * @l: Link handle diff --git a/src/nvme/private.h b/src/nvme/private.h index 8d0560188..6eee5a66a 100644 --- a/src/nvme/private.h +++ b/src/nvme/private.h @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -36,6 +37,7 @@ struct nvme_link { /* direct */ int fd; + struct stat stat; struct nvme_log *log; }; From bade4b1004257421250d1d56be6be0b719d64c86 Mon Sep 17 00:00:00 2001 From: Daniel Wagner Date: Mon, 7 Jul 2025 19:07:42 +0200 Subject: [PATCH 08/66] mi: replace nvme_mi_ctrl_t with nvme_link_t Signed-off-by: Daniel Wagner --- examples/mi-mctp-csi-test.c | 8 +- examples/mi-mctp.c | 34 +-- src/libnvme.map | 4 +- src/nvme/mi.c | 205 ++++++++------- src/nvme/mi.h | 510 ++++++++++++++++++------------------ src/nvme/private.h | 11 +- test/mi-mctp.c | 34 +-- test/mi.c | 266 +++++++++---------- 8 files changed, 531 insertions(+), 541 deletions(-) diff --git a/examples/mi-mctp-csi-test.c b/examples/mi-mctp-csi-test.c index 2ca7e629e..980c6a6e0 100644 --- a/examples/mi-mctp-csi-test.c +++ b/examples/mi-mctp-csi-test.c @@ -57,7 +57,7 @@ void hexdump(const unsigned char *buf, int len) int do_get_log_page(nvme_mi_ep_t ep, int argc, char **argv) { struct nvme_get_log_args args = { 0 }; - struct nvme_mi_ctrl *ctrl; + struct nvme_link *link; uint8_t buf[4096]; uint16_t ctrl_id; int rc, tmp; @@ -86,13 +86,13 @@ int do_get_log_page(nvme_mi_ep_t ep, int argc, char **argv) args.lid = 0x1; } - ctrl = nvme_mi_init_ctrl(ep, ctrl_id); - if (!ctrl) { + link = nvme_mi_init_link(ep, ctrl_id); + if (!link) { warn("can't create controller"); return -1; } - rc = nvme_mi_admin_get_log(ctrl, &args); + rc = nvme_mi_admin_get_log(link, &args); if (rc) { warn("can't perform Get Log page command"); return -1; diff --git a/examples/mi-mctp.c b/examples/mi-mctp.c index cea7ed89f..b4c21eeae 100644 --- a/examples/mi-mctp.c +++ b/examples/mi-mctp.c @@ -179,7 +179,7 @@ static const char *__copy_id_str(const void *field, size_t size, int do_identify(nvme_mi_ep_t ep, int argc, char **argv) { struct nvme_identify_args id_args = { 0 }; - struct nvme_mi_ctrl *ctrl; + struct nvme_link *link; struct nvme_id_ctrl id; uint16_t ctrl_id; char buf[41]; @@ -201,8 +201,8 @@ int do_identify(nvme_mi_ep_t ep, int argc, char **argv) partial = argc > 2 && !strcmp(argv[2], "--partial"); - ctrl = nvme_mi_init_ctrl(ep, ctrl_id); - if (!ctrl) { + link = nvme_mi_init_link(ep, ctrl_id); + if (!link) { warn("can't create controller"); return -1; } @@ -220,10 +220,10 @@ int do_identify(nvme_mi_ep_t ep, int argc, char **argv) * response. */ if (partial) { - rc = nvme_mi_admin_identify_partial(ctrl, &id_args, 0, + rc = nvme_mi_admin_identify_partial(link, &id_args, 0, offsetof(struct nvme_id_ctrl, rab)); } else { - rc = nvme_mi_admin_identify(ctrl, &id_args); + rc = nvme_mi_admin_identify(link, &id_args); } if (rc) { @@ -374,7 +374,7 @@ void hexdump(const unsigned char *buf, int len) int do_get_log_page(nvme_mi_ep_t ep, int argc, char **argv) { struct nvme_get_log_args args = { 0 }; - struct nvme_mi_ctrl *ctrl; + struct nvme_link *link; uint8_t buf[512]; uint16_t ctrl_id; int rc, tmp; @@ -403,13 +403,13 @@ int do_get_log_page(nvme_mi_ep_t ep, int argc, char **argv) args.lid = 0x1; } - ctrl = nvme_mi_init_ctrl(ep, ctrl_id); - if (!ctrl) { + link = nvme_mi_init_link(ep, ctrl_id); + if (!link) { warn("can't create controller"); return -1; } - rc = nvme_mi_admin_get_log(ctrl, &args); + rc = nvme_mi_admin_get_log(link, &args); if (rc) { warn("can't perform Get Log page command"); return -1; @@ -425,7 +425,7 @@ int do_admin_raw(nvme_mi_ep_t ep, int argc, char **argv) { struct nvme_mi_admin_req_hdr req; struct nvme_mi_admin_resp_hdr *resp; - struct nvme_mi_ctrl *ctrl; + struct nvme_link *link; size_t resp_data_len; unsigned long tmp; uint8_t buf[512]; @@ -488,15 +488,15 @@ int do_admin_raw(nvme_mi_ep_t ep, int argc, char **argv) memset(buf, 0, sizeof(buf)); resp = (void *)buf; - ctrl = nvme_mi_init_ctrl(ep, ctrl_id); - if (!ctrl) { + link = nvme_mi_init_link(ep, ctrl_id); + if (!link) { warn("can't create controller"); return -1; } resp_data_len = sizeof(buf) - sizeof(*resp); - rc = nvme_mi_admin_xfer(ctrl, &req, 0, resp, 0, &resp_data_len); + rc = nvme_mi_admin_xfer(link, &req, 0, resp, 0, &resp_data_len); if (rc) { warn("nvme_admin_xfer failed: %d", rc); return -1; @@ -543,7 +543,7 @@ static const char *sec_proto_description(uint8_t id) int do_security_info(nvme_mi_ep_t ep, int argc, char **argv) { struct nvme_security_receive_args args = { 0 }; - nvme_mi_ctrl_t ctrl; + nvme_link_t link; int i, rc, n_proto; unsigned long tmp; uint16_t ctrl_id; @@ -566,8 +566,8 @@ int do_security_info(nvme_mi_ep_t ep, int argc, char **argv) ctrl_id = tmp & 0xffff; - ctrl = nvme_mi_init_ctrl(ep, ctrl_id); - if (!ctrl) { + link = nvme_mi_init_link(ep, ctrl_id); + if (!link) { warn("can't create controller"); return -1; } @@ -577,7 +577,7 @@ int do_security_info(nvme_mi_ep_t ep, int argc, char **argv) args.data = &proto_info; args.data_len = sizeof(proto_info); - rc = nvme_mi_admin_security_recv(ctrl, &args); + rc = nvme_mi_admin_security_recv(link, &args); if (rc) { warnx("can't perform Security Receive command: rc %d", rc); return -1; diff --git a/src/libnvme.map b/src/libnvme.map index c23fb9a95..561da6a7d 100644 --- a/src/libnvme.map +++ b/src/libnvme.map @@ -215,7 +215,7 @@ LIBNVME_2_0 { nvme_mi_aem_get_next_event; nvme_mi_aem_process; nvme_mi_close; - nvme_mi_close_ctrl; + nvme_mi_close_link; nvme_mi_control; nvme_mi_create_root; nvme_mi_ctrl_id; @@ -225,7 +225,7 @@ LIBNVME_2_0 { nvme_mi_first_ctrl; nvme_mi_first_endpoint; nvme_mi_free_root; - nvme_mi_init_ctrl; + nvme_mi_init_link; nvme_mi_mi_config_get; nvme_mi_mi_config_set; nvme_mi_mi_read_mi_data_ctrl; diff --git a/src/nvme/mi.c b/src/nvme/mi.c index 14c71d75e..db77efe13 100644 --- a/src/nvme/mi.c +++ b/src/nvme/mi.c @@ -159,7 +159,7 @@ void nvme_mi_ep_probe(struct nvme_mi_ep *ep) { struct nvme_identify_args id_args = { 0 }; struct nvme_id_ctrl id = { 0 }; - struct nvme_mi_ctrl *ctrl; + struct nvme_link *link; int rc; /* Ensure the probe occurs at most once. This isn't just to mitigate doubling @@ -182,8 +182,8 @@ void nvme_mi_ep_probe(struct nvme_mi_ep *ep) /* start with no quirks, detect as we go */ ep->quirks = 0; - ctrl = nvme_mi_init_ctrl(ep, 0); - if (!ctrl) + link = nvme_mi_init_link(ep, 0); + if (!link) return; /* Do enough of an identify (assuming controller 0) to retrieve @@ -205,7 +205,7 @@ void nvme_mi_ep_probe(struct nvme_mi_ep *ep) id_args.cntid = 0; id_args.csi = NVME_CSI_NVM; - rc = nvme_mi_admin_identify_partial(ctrl, &id_args, 0, + rc = nvme_mi_admin_identify_partial(link, &id_args, 0, offsetof(struct nvme_id_ctrl, rab)); if (rc) { nvme_msg(ep->root, LOG_WARNING, @@ -238,7 +238,7 @@ void nvme_mi_ep_probe(struct nvme_mi_ep *ep) } out_close: - nvme_mi_close_ctrl(ctrl); + nvme_mi_close_link(link); } static const int nsec_per_sec = 1000 * 1000 * 1000; @@ -337,25 +337,25 @@ static bool nvme_mi_ep_has_quirk(nvme_mi_ep_t ep, unsigned long quirk) return ep->quirks & quirk; } -struct nvme_mi_ctrl *nvme_mi_init_ctrl(nvme_mi_ep_t ep, __u16 ctrl_id) +struct nvme_link *nvme_mi_init_link(nvme_mi_ep_t ep, __u16 ctrl_id) { - struct nvme_mi_ctrl *ctrl; + struct nvme_link *link; - ctrl = malloc(sizeof(*ctrl)); - if (!ctrl) + link = malloc(sizeof(*link)); + if (!link) return NULL; - ctrl->ep = ep; - ctrl->id = ctrl_id; + link->ep = ep; + link->id = ctrl_id; - list_add_tail(&ep->controllers, &ctrl->ep_entry); + list_add_tail(&ep->controllers, &link->ep_entry); - return ctrl; + return link; } -__u16 nvme_mi_ctrl_id(nvme_mi_ctrl_t ctrl) +__u16 nvme_mi_ctrl_id(nvme_link_t link) { - return ctrl->id; + return link->id; } int nvme_mi_scan_ep(nvme_mi_ep_t ep, bool force_rescan) @@ -366,9 +366,9 @@ int nvme_mi_scan_ep(nvme_mi_ep_t ep, bool force_rescan) if (ep->controllers_scanned) { if (force_rescan) { - struct nvme_mi_ctrl *ctrl, *tmp; - nvme_mi_for_each_ctrl_safe(ep, ctrl, tmp) - nvme_mi_close_ctrl(ctrl); + struct nvme_link *link, *tmp; + nvme_mi_for_each_link_safe(ep, link, tmp) + nvme_mi_close_link(link); } else { return 0; } @@ -385,13 +385,13 @@ int nvme_mi_scan_ep(nvme_mi_ep_t ep, bool force_rescan) } for (i = 0; i < n_ctrl; i++) { - struct nvme_mi_ctrl *ctrl; + struct nvme_link *link; __u16 id; id = le16_to_cpu(list.identifier[i]); - ctrl = nvme_mi_init_ctrl(ep, id); - if (!ctrl) + link = nvme_mi_init_link(ep, id); + if (!link) break; } @@ -756,7 +756,7 @@ static int nvme_mi_get_async_message(nvme_mi_ep_t ep, } -int nvme_mi_admin_xfer(nvme_mi_ctrl_t ctrl, +int nvme_mi_admin_xfer(nvme_link_t link, struct nvme_mi_admin_req_hdr *admin_req, size_t req_data_size, struct nvme_mi_admin_resp_hdr *admin_resp, @@ -807,9 +807,9 @@ int nvme_mi_admin_xfer(nvme_mi_ctrl_t ctrl, admin_req->hdr.type = NVME_MI_MSGTYPE_NVME; admin_req->hdr.nmp = (NVME_MI_ROR_REQ << 7) | (NVME_MI_MT_ADMIN << 3) | - (ctrl->ep->csi & 1); + (link->ep->csi & 1); - admin_req->ctrl_id = cpu_to_le16(ctrl->id); + admin_req->ctrl_id = cpu_to_le16(link->id); memset(&req, 0, sizeof(req)); req.hdr = &admin_req->hdr; req.hdr_len = sizeof(*admin_req); @@ -836,7 +836,7 @@ int nvme_mi_admin_xfer(nvme_mi_ctrl_t ctrl, admin_req->dlen = cpu_to_le32(dlen); admin_req->doff = cpu_to_le32(doff); - rc = nvme_mi_submit(ctrl->ep, &req, &resp); + rc = nvme_mi_submit(link->ep, &req, &resp); if (rc) return rc; @@ -845,7 +845,7 @@ int nvme_mi_admin_xfer(nvme_mi_ctrl_t ctrl, return 0; } -int nvme_mi_admin_admin_passthru(nvme_mi_ctrl_t ctrl, __u8 opcode, __u8 flags, +int nvme_mi_admin_admin_passthru(nvme_link_t link, __u8 opcode, __u8 flags, __u16 rsvd, __u32 nsid, __u32 cdw2, __u32 cdw3, __u32 cdw10, __u32 cdw11, __u32 cdw12, __u32 cdw13, __u32 cdw14, __u32 cdw15, @@ -864,14 +864,14 @@ int nvme_mi_admin_admin_passthru(nvme_mi_ctrl_t ctrl, __u8 opcode, __u8 flags, bool has_read_data = false; if (direction == NVME_DATA_TFR_BIDIRECTIONAL) { - nvme_msg(ctrl->ep->root, LOG_ERR, + nvme_msg(link->root, LOG_ERR, "nvme_mi_admin_admin_passthru doesn't support bidirectional commands\n"); errno = EINVAL; return -1; } if (data_len > 4096) { - nvme_msg(ctrl->ep->root, LOG_ERR, + nvme_msg(link->root, LOG_ERR, "nvme_mi_admin_admin_passthru doesn't support data_len over 4096 bytes.\n"); errno = EINVAL; return -1; @@ -884,7 +884,7 @@ int nvme_mi_admin_admin_passthru(nvme_mi_ctrl_t ctrl, __u8 opcode, __u8 flags, has_read_data = true; } - nvme_mi_admin_init_req(ctrl->ep, &req, &req_hdr, ctrl->id, opcode); + nvme_mi_admin_init_req(link->ep, &req, &req_hdr, link->id, opcode); req_hdr.cdw1 = cpu_to_le32(nsid); req_hdr.cdw2 = cpu_to_le32(cdw2); req_hdr.cdw3 = cpu_to_le32(cdw3); @@ -917,12 +917,12 @@ int nvme_mi_admin_admin_passthru(nvme_mi_ctrl_t ctrl, __u8 opcode, __u8 flags, * timeout and override */ if (timeout_ms != 0) { - timeout_save = nvme_mi_ep_get_timeout(ctrl->ep); - nvme_mi_ep_set_timeout(ctrl->ep, timeout_ms); + timeout_save = nvme_mi_ep_get_timeout(link->ep); + nvme_mi_ep_set_timeout(link->ep, timeout_ms); } - rc = nvme_mi_submit(ctrl->ep, &req, &resp); + rc = nvme_mi_submit(link->ep, &req, &resp); if (timeout_ms != 0) - nvme_mi_ep_set_timeout(ctrl->ep, timeout_save); + nvme_mi_ep_set_timeout(link->ep, timeout_save); if (rc) return rc; @@ -939,7 +939,7 @@ int nvme_mi_admin_admin_passthru(nvme_mi_ctrl_t ctrl, __u8 opcode, __u8 flags, return 0; } -int nvme_mi_admin_identify_partial(nvme_mi_ctrl_t ctrl, +int nvme_mi_admin_identify_partial(nvme_link_t link, struct nvme_identify_args *args, off_t offset, size_t size) { @@ -959,7 +959,7 @@ int nvme_mi_admin_identify_partial(nvme_mi_ctrl_t ctrl, return -1; } - nvme_mi_admin_init_req(ctrl->ep, &req, &req_hdr, ctrl->id, nvme_admin_identify); + nvme_mi_admin_init_req(link->ep, &req, &req_hdr, link->id, nvme_admin_identify); req_hdr.cdw1 = cpu_to_le32(args->nsid); req_hdr.cdw10 = cpu_to_le32(args->cntid << 16 | args->cns); req_hdr.cdw11 = cpu_to_le32((args->csi & 0xff) << 24 | @@ -976,7 +976,7 @@ int nvme_mi_admin_identify_partial(nvme_mi_ctrl_t ctrl, resp.data = args->data; resp.data_len = size; - rc = nvme_mi_submit(ctrl->ep, &req, &resp); + rc = nvme_mi_submit(link->ep, &req, &resp); if (rc) return rc; @@ -1026,7 +1026,7 @@ int nvme_mi_control(nvme_mi_ep_t ep, __u8 opcode, * this option seems to be supported better by devices. For more information * about this option, please check https://github.com/linux-nvme/libnvme/pull/539 * */ -static int __nvme_mi_admin_get_log(nvme_mi_ctrl_t ctrl, +static int __nvme_mi_admin_get_log(nvme_link_t link, const struct nvme_get_log_args *args, off_t offset, size_t *lenp, bool final) { @@ -1054,7 +1054,7 @@ static int __nvme_mi_admin_get_log(nvme_mi_ctrl_t ctrl, ndw = (len >> 2) - 1; - nvme_mi_admin_init_req(ctrl->ep, &req, &req_hdr, ctrl->id, + nvme_mi_admin_init_req(link->ep, &req, &req_hdr, link->id, nvme_admin_get_log_page); req_hdr.cdw1 = cpu_to_le32(args->nsid); req_hdr.cdw10 = cpu_to_le32((ndw & 0xffff) << 16 | @@ -1075,7 +1075,7 @@ static int __nvme_mi_admin_get_log(nvme_mi_ctrl_t ctrl, resp.data = args->log + offset; resp.data_len = len; - rc = nvme_mi_submit(ctrl->ep, &req, &resp); + rc = nvme_mi_submit(link->ep, &req, &resp); if (rc) return rc; @@ -1086,7 +1086,7 @@ static int __nvme_mi_admin_get_log(nvme_mi_ctrl_t ctrl, return rc; } -int nvme_mi_admin_get_log_page(nvme_mi_ctrl_t ctrl, __u32 xfer_size, +int nvme_mi_admin_get_log_page(nvme_link_t link, __u32 xfer_size, struct nvme_get_log_args *args) { const size_t max_xfer_size = xfer_size; @@ -1115,7 +1115,7 @@ int nvme_mi_admin_get_log_page(nvme_mi_ctrl_t ctrl, __u32 xfer_size, final = xfer_offset + cur_xfer_size >= args->len; /* xfered_size is used as both input and output parameter */ - rc = __nvme_mi_admin_get_log(ctrl, args, xfer_offset, + rc = __nvme_mi_admin_get_log(link, args, xfer_offset, &xfered_size, final); if (rc) break; @@ -1133,12 +1133,12 @@ int nvme_mi_admin_get_log_page(nvme_mi_ctrl_t ctrl, __u32 xfer_size, return rc; } -int nvme_mi_admin_get_log(nvme_mi_ctrl_t ctrl, struct nvme_get_log_args *args) +int nvme_mi_admin_get_log(nvme_link_t link, struct nvme_get_log_args *args) { - return nvme_mi_admin_get_log_page(ctrl, 4096, args); + return nvme_mi_admin_get_log_page(link, 4096, args); } -static int read_ana_chunk(nvme_mi_ctrl_t ctrl, enum nvme_log_ana_lsp lsp, bool rae, +static int read_ana_chunk(nvme_link_t link, enum nvme_log_ana_lsp lsp, bool rae, __u8 *log, __u8 **read, __u8 *to_read, __u8 *log_end) { if (to_read > log_end) { @@ -1150,7 +1150,7 @@ static int read_ana_chunk(nvme_mi_ctrl_t ctrl, enum nvme_log_ana_lsp lsp, bool r __u32 len = min_t(__u32, log_end - *read, NVME_LOG_PAGE_PDU_SIZE); int ret; - ret = nvme_mi_admin_get_log_ana(ctrl, lsp, rae, + ret = nvme_mi_admin_get_log_ana(link, lsp, rae, *read - log, len, *read); if (ret) return ret; @@ -1160,7 +1160,7 @@ static int read_ana_chunk(nvme_mi_ctrl_t ctrl, enum nvme_log_ana_lsp lsp, bool r return 0; } -static int try_read_ana(nvme_mi_ctrl_t ctrl, enum nvme_log_ana_lsp lsp, bool rae, +static int try_read_ana(nvme_link_t link, enum nvme_log_ana_lsp lsp, bool rae, struct nvme_ana_log *log, __u8 *log_end, __u8 *read, __u8 **to_read, bool *may_retry) { @@ -1172,7 +1172,7 @@ static int try_read_ana(nvme_mi_ctrl_t ctrl, enum nvme_log_ana_lsp lsp, bool rae __le32 nnsids; *to_read += sizeof(*log->descs); - ret = read_ana_chunk(ctrl, lsp, rae, + ret = read_ana_chunk(link, lsp, rae, (__u8 *)log, &read, *to_read, log_end); if (ret) { /* @@ -1194,7 +1194,7 @@ static int try_read_ana(nvme_mi_ctrl_t ctrl, enum nvme_log_ana_lsp lsp, bool rae group + offsetof(struct nvme_ana_group_desc, nnsids), sizeof(nnsids)); *to_read += le32_to_cpu(nnsids) * sizeof(__le32); - ret = read_ana_chunk(ctrl, lsp, rae, + ret = read_ana_chunk(link, lsp, rae, (__u8 *)log, &read, *to_read, log_end); if (ret) { *may_retry = errno == ENOSPC; @@ -1206,7 +1206,7 @@ static int try_read_ana(nvme_mi_ctrl_t ctrl, enum nvme_log_ana_lsp lsp, bool rae return 0; } -int nvme_mi_admin_get_ana_log_atomic(nvme_mi_ctrl_t ctrl, bool rgo, bool rae, +int nvme_mi_admin_get_ana_log_atomic(nvme_link_t link, bool rgo, bool rae, unsigned int retries, struct nvme_ana_log *log, __u32 *len) { @@ -1224,7 +1224,7 @@ int nvme_mi_admin_get_ana_log_atomic(nvme_mi_ctrl_t ctrl, bool rgo, bool rae, } to_read = (__u8 *)log->descs; - ret = read_ana_chunk(ctrl, lsp, rae, + ret = read_ana_chunk(link, lsp, rae, (__u8 *)log, &read, to_read, log_end); if (ret) return ret; @@ -1235,7 +1235,7 @@ int nvme_mi_admin_get_ana_log_atomic(nvme_mi_ctrl_t ctrl, bool rgo, bool rae, int saved_errno; __le64 chgcnt; - saved_ret = try_read_ana(ctrl, lsp, rae, log, log_end, + saved_ret = try_read_ana(link, lsp, rae, log, log_end, read, &to_read, &may_retry); /* * If the log page was read with multiple Get Log Page commands, @@ -1249,7 +1249,7 @@ int nvme_mi_admin_get_ana_log_atomic(nvme_mi_ctrl_t ctrl, bool rgo, bool rae, chgcnt = log->chgcnt; read = (__u8 *)log; to_read = (__u8 *)log->descs; - ret = read_ana_chunk(ctrl, lsp, rae, + ret = read_ana_chunk(link, lsp, rae, (__u8 *)log, &read, to_read, log_end); if (ret) return ret; @@ -1265,7 +1265,7 @@ int nvme_mi_admin_get_ana_log_atomic(nvme_mi_ctrl_t ctrl, bool rgo, bool rae, return -1; } -int nvme_mi_admin_security_send(nvme_mi_ctrl_t ctrl, +int nvme_mi_admin_security_send(nvme_link_t link, struct nvme_security_send_args *args) { @@ -1285,7 +1285,7 @@ int nvme_mi_admin_security_send(nvme_mi_ctrl_t ctrl, return -1; } - nvme_mi_admin_init_req(ctrl->ep, &req, &req_hdr, ctrl->id, + nvme_mi_admin_init_req(link->ep, &req, &req_hdr, link->id, nvme_admin_security_send); req_hdr.cdw10 = cpu_to_le32(args->secp << 24 | @@ -1302,14 +1302,14 @@ int nvme_mi_admin_security_send(nvme_mi_ctrl_t ctrl, nvme_mi_admin_init_resp(&resp, &resp_hdr); - rc = nvme_mi_submit(ctrl->ep, &req, &resp); + rc = nvme_mi_submit(link->ep, &req, &resp); if (rc) return rc; return nvme_mi_admin_parse_status(&resp, args->result); } -int nvme_mi_admin_security_recv(nvme_mi_ctrl_t ctrl, +int nvme_mi_admin_security_recv(nvme_link_t link, struct nvme_security_receive_args *args) { @@ -1329,7 +1329,7 @@ int nvme_mi_admin_security_recv(nvme_mi_ctrl_t ctrl, return -1; } - nvme_mi_admin_init_req(ctrl->ep, &req, &req_hdr, ctrl->id, + nvme_mi_admin_init_req(link->ep, &req, &req_hdr, link->id, nvme_admin_security_recv); req_hdr.cdw10 = cpu_to_le32(args->secp << 24 | @@ -1346,7 +1346,7 @@ int nvme_mi_admin_security_recv(nvme_mi_ctrl_t ctrl, resp.data = args->data; resp.data_len = args->data_len; - rc = nvme_mi_submit(ctrl->ep, &req, &resp); + rc = nvme_mi_submit(link->ep, &req, &resp); if (rc) return rc; @@ -1359,7 +1359,7 @@ int nvme_mi_admin_security_recv(nvme_mi_ctrl_t ctrl, return 0; } -int nvme_mi_admin_get_features(nvme_mi_ctrl_t ctrl, +int nvme_mi_admin_get_features(nvme_link_t link, struct nvme_get_features_args *args) { struct nvme_mi_admin_resp_hdr resp_hdr; @@ -1373,7 +1373,7 @@ int nvme_mi_admin_get_features(nvme_mi_ctrl_t ctrl, return -1; } - nvme_mi_admin_init_req(ctrl->ep, &req, &req_hdr, ctrl->id, + nvme_mi_admin_init_req(link->ep, &req, &req_hdr, link->id, nvme_admin_get_features); req_hdr.cdw1 = cpu_to_le32(args->nsid); @@ -1385,7 +1385,7 @@ int nvme_mi_admin_get_features(nvme_mi_ctrl_t ctrl, resp.data = args->data; resp.data_len = args->data_len; - rc = nvme_mi_submit(ctrl->ep, &req, &resp); + rc = nvme_mi_submit(link->ep, &req, &resp); if (rc) return rc; @@ -1398,7 +1398,7 @@ int nvme_mi_admin_get_features(nvme_mi_ctrl_t ctrl, return 0; } -static int __nvme_mi_admin_get_features(nvme_mi_ctrl_t ctrl, enum nvme_features_id fid, +static int __nvme_mi_admin_get_features(nvme_link_t link, enum nvme_features_id fid, enum nvme_get_features_sel sel, __u32 *result) { struct nvme_get_features_args args = { @@ -1414,22 +1414,22 @@ static int __nvme_mi_admin_get_features(nvme_mi_ctrl_t ctrl, enum nvme_features_ .result = result, }; - return nvme_mi_admin_get_features(ctrl, &args); + return nvme_mi_admin_get_features(link, &args); } -int nvme_mi_admin_get_features_arbitration(nvme_mi_ctrl_t ctrl, enum nvme_get_features_sel sel, +int nvme_mi_admin_get_features_arbitration(nvme_link_t link, enum nvme_get_features_sel sel, __u32 *result) { - return __nvme_mi_admin_get_features(ctrl, NVME_FEAT_FID_ARBITRATION, sel, result); + return __nvme_mi_admin_get_features(link, NVME_FEAT_FID_ARBITRATION, sel, result); } -int nvme_mi_admin_get_features_power_mgmt(nvme_mi_ctrl_t ctrl, enum nvme_get_features_sel sel, +int nvme_mi_admin_get_features_power_mgmt(nvme_link_t link, enum nvme_get_features_sel sel, __u32 *result) { - return __nvme_mi_admin_get_features(ctrl, NVME_FEAT_FID_POWER_MGMT, sel, result); + return __nvme_mi_admin_get_features(link, NVME_FEAT_FID_POWER_MGMT, sel, result); } -int nvme_mi_admin_set_features(nvme_mi_ctrl_t ctrl, +int nvme_mi_admin_set_features(nvme_link_t link, struct nvme_set_features_args *args) { struct nvme_mi_admin_resp_hdr resp_hdr; @@ -1443,7 +1443,7 @@ int nvme_mi_admin_set_features(nvme_mi_ctrl_t ctrl, return -1; } - nvme_mi_admin_init_req(ctrl->ep, &req, &req_hdr, ctrl->id, + nvme_mi_admin_init_req(link->ep, &req, &req_hdr, link->id, nvme_admin_set_features); req_hdr.cdw1 = cpu_to_le32(args->nsid); @@ -1460,7 +1460,7 @@ int nvme_mi_admin_set_features(nvme_mi_ctrl_t ctrl, nvme_mi_admin_init_resp(&resp, &resp_hdr); - rc = nvme_mi_submit(ctrl->ep, &req, &resp); + rc = nvme_mi_submit(link->ep, &req, &resp); if (rc) return rc; @@ -1473,7 +1473,7 @@ int nvme_mi_admin_set_features(nvme_mi_ctrl_t ctrl, return 0; } -static int __nvme_mi_admin_set_features(nvme_mi_ctrl_t ctrl, __u8 fid, __u32 cdw11, bool save, +static int __nvme_mi_admin_set_features(nvme_link_t link, __u8 fid, __u32 cdw11, bool save, __u32 *result) { struct nvme_set_features_args args = { @@ -1489,18 +1489,18 @@ static int __nvme_mi_admin_set_features(nvme_mi_ctrl_t ctrl, __u8 fid, __u32 cdw .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, .result = result, }; - return nvme_mi_admin_set_features(ctrl, &args); + return nvme_mi_admin_set_features(link, &args); } -int nvme_mi_admin_set_features_power_mgmt(nvme_mi_ctrl_t ctrl, __u8 ps, __u8 wh, bool save, +int nvme_mi_admin_set_features_power_mgmt(nvme_link_t link, __u8 ps, __u8 wh, bool save, __u32 *result) { __u32 value = NVME_SET(ps, FEAT_PWRMGMT_PS) | NVME_SET(wh, FEAT_PWRMGMT_WH); - return __nvme_mi_admin_set_features(ctrl, NVME_FEAT_FID_POWER_MGMT, value, save, result); + return __nvme_mi_admin_set_features(link, NVME_FEAT_FID_POWER_MGMT, value, save, result); } -int nvme_mi_admin_ns_mgmt(nvme_mi_ctrl_t ctrl, +int nvme_mi_admin_ns_mgmt(nvme_link_t link, struct nvme_ns_mgmt_args *args) { const size_t size_v1 = sizeof_args(struct nvme_ns_mgmt_args, csi, __u64); @@ -1517,7 +1517,7 @@ int nvme_mi_admin_ns_mgmt(nvme_mi_ctrl_t ctrl, return -1; } - nvme_mi_admin_init_req(ctrl->ep, &req, &req_hdr, ctrl->id, + nvme_mi_admin_init_req(link->ep, &req, &req_hdr, link->id, nvme_admin_ns_mgmt); req_hdr.cdw1 = cpu_to_le32(args->nsid); @@ -1545,14 +1545,14 @@ int nvme_mi_admin_ns_mgmt(nvme_mi_ctrl_t ctrl, nvme_mi_admin_init_resp(&resp, &resp_hdr); - rc = nvme_mi_submit(ctrl->ep, &req, &resp); + rc = nvme_mi_submit(link->ep, &req, &resp); if (rc) return rc; return nvme_mi_admin_parse_status(&resp, args->result); } -int nvme_mi_admin_ns_attach(nvme_mi_ctrl_t ctrl, +int nvme_mi_admin_ns_attach(nvme_link_t link, struct nvme_ns_attach_args *args) { struct nvme_mi_admin_resp_hdr resp_hdr; @@ -1566,7 +1566,7 @@ int nvme_mi_admin_ns_attach(nvme_mi_ctrl_t ctrl, return -1; } - nvme_mi_admin_init_req(ctrl->ep, &req, &req_hdr, ctrl->id, + nvme_mi_admin_init_req(link->ep, &req, &req_hdr, link->id, nvme_admin_ns_attach); req_hdr.cdw1 = cpu_to_le32(args->nsid); @@ -1578,14 +1578,14 @@ int nvme_mi_admin_ns_attach(nvme_mi_ctrl_t ctrl, nvme_mi_admin_init_resp(&resp, &resp_hdr); - rc = nvme_mi_submit(ctrl->ep, &req, &resp); + rc = nvme_mi_submit(link->ep, &req, &resp); if (rc) return rc; return nvme_mi_admin_parse_status(&resp, args->result); } -int nvme_mi_admin_fw_download(nvme_mi_ctrl_t ctrl, +int nvme_mi_admin_fw_download(nvme_link_t link, struct nvme_fw_download_args *args) { struct nvme_mi_admin_resp_hdr resp_hdr; @@ -1609,7 +1609,7 @@ int nvme_mi_admin_fw_download(nvme_mi_ctrl_t ctrl, return -1; } - nvme_mi_admin_init_req(ctrl->ep, &req, &req_hdr, ctrl->id, + nvme_mi_admin_init_req(link->ep, &req, &req_hdr, link->id, nvme_admin_fw_download); req_hdr.cdw10 = cpu_to_le32((args->data_len >> 2) - 1); @@ -1621,14 +1621,14 @@ int nvme_mi_admin_fw_download(nvme_mi_ctrl_t ctrl, nvme_mi_admin_init_resp(&resp, &resp_hdr); - rc = nvme_mi_submit(ctrl->ep, &req, &resp); + rc = nvme_mi_submit(link->ep, &req, &resp); if (rc) return rc; return nvme_mi_admin_parse_status(&resp, NULL); } -int nvme_mi_admin_fw_commit(nvme_mi_ctrl_t ctrl, +int nvme_mi_admin_fw_commit(nvme_link_t link, struct nvme_fw_commit_args *args) { struct nvme_mi_admin_resp_hdr resp_hdr; @@ -1642,7 +1642,7 @@ int nvme_mi_admin_fw_commit(nvme_mi_ctrl_t ctrl, return -1; } - nvme_mi_admin_init_req(ctrl->ep, &req, &req_hdr, ctrl->id, + nvme_mi_admin_init_req(link->ep, &req, &req_hdr, link->id, nvme_admin_fw_commit); req_hdr.cdw10 = cpu_to_le32(((__u32)(args->bpid & 0x1) << 31) | @@ -1651,14 +1651,14 @@ int nvme_mi_admin_fw_commit(nvme_mi_ctrl_t ctrl, nvme_mi_admin_init_resp(&resp, &resp_hdr); - rc = nvme_mi_submit(ctrl->ep, &req, &resp); + rc = nvme_mi_submit(link->ep, &req, &resp); if (rc) return rc; return nvme_mi_admin_parse_status(&resp, NULL); } -int nvme_mi_admin_format_nvm(nvme_mi_ctrl_t ctrl, +int nvme_mi_admin_format_nvm(nvme_link_t link, struct nvme_format_nvm_args *args) { struct nvme_mi_admin_resp_hdr resp_hdr; @@ -1672,7 +1672,7 @@ int nvme_mi_admin_format_nvm(nvme_mi_ctrl_t ctrl, return -1; } - nvme_mi_admin_init_req(ctrl->ep, &req, &req_hdr, ctrl->id, + nvme_mi_admin_init_req(link->ep, &req, &req_hdr, link->id, nvme_admin_format_nvm); req_hdr.cdw1 = cpu_to_le32(args->nsid); @@ -1685,14 +1685,14 @@ int nvme_mi_admin_format_nvm(nvme_mi_ctrl_t ctrl, nvme_mi_admin_init_resp(&resp, &resp_hdr); - rc = nvme_mi_submit(ctrl->ep, &req, &resp); + rc = nvme_mi_submit(link->ep, &req, &resp); if (rc) return rc; return nvme_mi_admin_parse_status(&resp, args->result); } -int nvme_mi_admin_sanitize_nvm(nvme_mi_ctrl_t ctrl, +int nvme_mi_admin_sanitize_nvm(nvme_link_t link, struct nvme_sanitize_nvm_args *args) { struct nvme_mi_admin_resp_hdr resp_hdr; @@ -1706,7 +1706,7 @@ int nvme_mi_admin_sanitize_nvm(nvme_mi_ctrl_t ctrl, return -1; } - nvme_mi_admin_init_req(ctrl->ep, &req, &req_hdr, ctrl->id, + nvme_mi_admin_init_req(link->ep, &req, &req_hdr, link->id, nvme_admin_sanitize_nvm); req_hdr.cdw10 = cpu_to_le32(((args->nodas ? 1 : 0) << 9) @@ -1718,7 +1718,7 @@ int nvme_mi_admin_sanitize_nvm(nvme_mi_ctrl_t ctrl, nvme_mi_admin_init_resp(&resp, &resp_hdr); - rc = nvme_mi_submit(ctrl->ep, &req, &resp); + rc = nvme_mi_submit(link->ep, &req, &resp); if (rc) return rc; @@ -2097,13 +2097,13 @@ int nvme_mi_mi_config_set_async_event(nvme_mi_ep_t ep, void nvme_mi_close(nvme_mi_ep_t ep) { - struct nvme_mi_ctrl *ctrl, *tmp; + struct nvme_link *link, *tmp; /* don't look for controllers during destruction */ ep->controllers_scanned = true; - nvme_mi_for_each_ctrl_safe(ep, ctrl, tmp) - nvme_mi_close_ctrl(ctrl); + nvme_mi_for_each_link_safe(ep, link, tmp) + nvme_mi_close_link(link); if (ep->transport && ep->transport->close) ep->transport->close(ep); @@ -2111,10 +2111,10 @@ void nvme_mi_close(nvme_mi_ep_t ep) free(ep); } -void nvme_mi_close_ctrl(nvme_mi_ctrl_t ctrl) +void nvme_mi_close_link(nvme_link_t link) { - list_del(&ctrl->ep_entry); - free(ctrl); + list_del(&link->ep_entry); + free(link); } char *nvme_mi_endpoint_desc(nvme_mi_ep_t ep) @@ -2157,17 +2157,16 @@ nvme_mi_ep_t nvme_mi_next_endpoint(nvme_root_t m, nvme_mi_ep_t ep) return ep ? list_next(&m->endpoints, ep, root_entry) : NULL; } -nvme_mi_ctrl_t nvme_mi_first_ctrl(nvme_mi_ep_t ep) +nvme_link_t nvme_mi_first_link(nvme_mi_ep_t ep) { - return list_top(&ep->controllers, struct nvme_mi_ctrl, ep_entry); + return list_top(&ep->controllers, struct nvme_link, ep_entry); } -nvme_mi_ctrl_t nvme_mi_next_ctrl(nvme_mi_ep_t ep, nvme_mi_ctrl_t c) +nvme_link_t nvme_mi_next_link(nvme_mi_ep_t ep, nvme_link_t l) { - return c ? list_next(&ep->controllers, c, ep_entry) : NULL; + return l ? list_next(&ep->controllers, l, ep_entry) : NULL; } - static const char *const mi_status[] = { [NVME_MI_RESP_MPR] = "More Processing Required: The command message is in progress and requires more time to complete processing", [NVME_MI_RESP_INTERNAL_ERR] = "Internal Error: The request message could not be processed due to a vendor-specific error", diff --git a/src/nvme/mi.h b/src/nvme/mi.h index 52190636d..3c4148326 100644 --- a/src/nvme/mi.h +++ b/src/nvme/mi.h @@ -89,6 +89,7 @@ #include #include +#include /** * NVME_MI_MSGTYPE_NVME - MCTP message type for NVMe-MI messages. @@ -791,42 +792,33 @@ void nvme_mi_ep_set_mprt_max(nvme_mi_ep_t ep, unsigned int mprt_max_ms); */ unsigned int nvme_mi_ep_get_timeout(nvme_mi_ep_t ep); -struct nvme_mi_ctrl; - -/** - * typedef nvme_mi_ctrl_t - NVMe-MI Controller object. - * - * Provides NVMe command functionality, through the MI interface. - */ -typedef struct nvme_mi_ctrl * nvme_mi_ctrl_t; - /** - * nvme_mi_first_ctrl - Start controller iterator + * nvme_mi_first_link - Start link iterator * @ep: &nvme_mi_ep_t object * - * Return: first MI controller object under this root, or NULL if no controllers - * are present. + * Return: first link to a MI controller object under this root, or NULL + * if no controllers are present. * - * See: &nvme_mi_next_ctrl, &nvme_mi_for_each_ctrl + * See: &nvme_mi_next_link, &nvme_mi_for_each_link */ -nvme_mi_ctrl_t nvme_mi_first_ctrl(nvme_mi_ep_t ep); +nvme_link_t nvme_mi_first_link(nvme_mi_ep_t ep); /** - * nvme_mi_next_ctrl - Continue ctrl iterator + * nvme_mi_next_link - Continue link iterator * @ep: &nvme_mi_ep_t object - * @c: &nvme_mi_ctrl_t current position of iterator + * @l: &nvme_mi_link_t current position of iterator * - * Return: next MI controller object after @c under this endpoint, or NULL - * if no further controllers are present. + * Return: next link to MI controller object after @c under this + * endpoint, or NULL if no further controllers are present. * - * See: &nvme_mi_first_ctrl, &nvme_mi_for_each_ctrl + * See: &nvme_mi_first_link, &nvme_mi_for_each_link */ -nvme_mi_ctrl_t nvme_mi_next_ctrl(nvme_mi_ep_t ep, nvme_mi_ctrl_t c); +nvme_link_t nvme_mi_next_link(nvme_mi_ep_t ep, nvme_link_t l); /** - * nvme_mi_for_each_ctrl - Iterator for NVMe-MI controllers. + * nvme_mi_for_each_link - Iterator for link to NVMe-MI controllers. * @ep: &nvme_mi_ep_t containing endpoints - * @c: &nvme_mi_ctrl_t object, set on each iteration + * @l: &nvme_link_t object, set on each iteration * * Allows iteration of the list of controllers behind an endpoint. Unless the * controllers have already been created explicitly, you'll probably want to @@ -834,16 +826,16 @@ nvme_mi_ctrl_t nvme_mi_next_ctrl(nvme_mi_ep_t ep, nvme_mi_ctrl_t c); * * See: &nvme_mi_scan_ep() */ -#define nvme_mi_for_each_ctrl(ep, c) \ - for (c = nvme_mi_first_ctrl(ep); c != NULL; \ - c = nvme_mi_next_ctrl(ep, c)) +#define nvme_mi_for_each_link(ep, l) \ + for (l = nvme_mi_first_link(ep); l != NULL; \ + l = nvme_mi_next_link(ep, l)) /** - * nvme_mi_for_each_ctrl_safe - Iterator for NVMe-MI controllers, allowing + * nvme_mi_for_each_link_safe - Iterator for link to NVMe-MI controllers, allowing * deletion during traversal * @ep: &nvme_mi_ep_t containing controllers - * @c: &nvme_mi_ctrl_t object, set on each iteration - * @_c: &nvme_mi_ctrl_t object used as temporary storage + * @l: &nvme_link_t object, set on each iteration + * @_l: &nvme_link_t object used as temporary storage * * Allows iteration of the list of controllers behind an endpoint, safe against * deletion during iteration. Unless the controllers have already been created @@ -852,10 +844,10 @@ nvme_mi_ctrl_t nvme_mi_next_ctrl(nvme_mi_ep_t ep, nvme_mi_ctrl_t c); * * See: &nvme_mi_scan_ep() */ -#define nvme_mi_for_each_ctrl_safe(ep, c, _c) \ - for (c = nvme_mi_first_ctrl(ep), _c = nvme_mi_next_ctrl(ep, c); \ - c != NULL; \ - c = _c, _c = nvme_mi_next_ctrl(ep, c)) +#define nvme_mi_for_each_link_safe(ep, l, _l) \ + for (l = nvme_mi_first_link(ep), _l = nvme_mi_next_link(ep, l); \ + l != NULL; \ + l = _l, _l = nvme_mi_next_link(ep, l)) /** * nvme_mi_open_mctp() - Create an endpoint using a MCTP connection. @@ -924,7 +916,7 @@ nvme_root_t nvme_mi_scan_mctp(void); int nvme_mi_scan_ep(nvme_mi_ep_t ep, bool force_rescan); /** - * nvme_mi_init_ctrl() - initialise a NVMe controller. + * nvme_mi_init_link() - initialise a link to NVMe controller. * @ep: Endpoint to create under * @ctrl_id: ID of controller to initialize. * @@ -934,28 +926,28 @@ int nvme_mi_scan_ep(nvme_mi_ep_t ep, bool force_rescan); * * Return: New controller object, or NULL on failure. * - * See &nvme_mi_close_ctrl + * See &nvme_mi_close_link */ -nvme_mi_ctrl_t nvme_mi_init_ctrl(nvme_mi_ep_t ep, __u16 ctrl_id); +nvme_link_t nvme_mi_init_link(nvme_mi_ep_t ep, __u16 ctrl_id); /** - * nvme_mi_close_ctrl() - free a controller - * @ctrl: controller to free + * nvme_mi_close_link() - free a controller + * @link: link to controller to free */ -void nvme_mi_close_ctrl(nvme_mi_ctrl_t ctrl); +void nvme_mi_close_link(nvme_link_t link); /** * nvme_mi_ctrl_id() - get the ID of a controller - * @ctrl: controller to query + * @link: link to controller to query * * Retrieve the ID of the controller, as defined by hardware, and available * in the Identify (Controller List) data. This is the value passed to - * @nvme_mi_init_ctrl, but may have been created internally via + * @nvme_mi_init_link, but may have been created internally via * @nvme_mi_scan_ep. * * Return: the (locally-stored) ID of this controller. */ -__u16 nvme_mi_ctrl_id(nvme_mi_ctrl_t ctrl); +__u16 nvme_mi_ctrl_id(nvme_link_t link); /** @@ -1342,7 +1334,7 @@ static inline int nvme_mi_aem_ack(nvme_mi_ep_t ep, /** * nvme_mi_admin_xfer() - Raw admin transfer interface. - * @ctrl: controller to send the admin command to + * @link: link to send the admin command to * @admin_req: request data * @req_data_size: size of request data payload * @admin_resp: buffer for response data @@ -1367,7 +1359,7 @@ static inline int nvme_mi_aem_ack(nvme_mi_ep_t ep, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise.. */ -int nvme_mi_admin_xfer(nvme_mi_ctrl_t ctrl, +int nvme_mi_admin_xfer(nvme_link_t link, struct nvme_mi_admin_req_hdr *admin_req, size_t req_data_size, struct nvme_mi_admin_resp_hdr *admin_resp, @@ -1376,7 +1368,7 @@ int nvme_mi_admin_xfer(nvme_mi_ctrl_t ctrl, /** * nvme_mi_admin_admin_passthru() - Submit an nvme admin passthrough command - * @ctrl: Controller to send command to + * @link: Link to send command to * @opcode: The nvme admin command to send * @flags: NVMe command flags (not used) * @rsvd: Reserved for future use @@ -1407,7 +1399,7 @@ int nvme_mi_admin_xfer(nvme_mi_ctrl_t ctrl, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_mi_admin_admin_passthru(nvme_mi_ctrl_t ctrl, __u8 opcode, __u8 flags, +int nvme_mi_admin_admin_passthru(nvme_link_t link, __u8 opcode, __u8 flags, __u16 rsvd, __u32 nsid, __u32 cdw2, __u32 cdw3, __u32 cdw10, __u32 cdw11, __u32 cdw12, __u32 cdw13, __u32 cdw14, __u32 cdw15, @@ -1417,7 +1409,7 @@ int nvme_mi_admin_admin_passthru(nvme_mi_ctrl_t ctrl, __u8 opcode, __u8 flags, /** * nvme_mi_admin_identify_partial() - Perform an Admin identify command, * and retrieve partial response data. - * @ctrl: Controller to process identify command + * @link: Link to process identify command * @args: Identify command arguments * @offset: offset of identify data to retrieve from response * @size: size of identify data to return @@ -1441,13 +1433,13 @@ int nvme_mi_admin_admin_passthru(nvme_mi_ctrl_t ctrl, __u8 opcode, __u8 flags, * * See: &struct nvme_identify_args */ -int nvme_mi_admin_identify_partial(nvme_mi_ctrl_t ctrl, +int nvme_mi_admin_identify_partial(nvme_link_t link, struct nvme_identify_args *args, off_t offset, size_t size); /** * nvme_mi_admin_identify() - Perform an Admin identify command. - * @ctrl: Controller to process identify command + * @link: Link to process identify command * @args: Identify command arguments * * Perform an Identify command, using the Identify command parameters in @args. @@ -1462,10 +1454,10 @@ int nvme_mi_admin_identify_partial(nvme_mi_ctrl_t ctrl, * * See: &struct nvme_identify_args */ -static inline int nvme_mi_admin_identify(nvme_mi_ctrl_t ctrl, +static inline int nvme_mi_admin_identify(nvme_link_t link, struct nvme_identify_args *args) { - return nvme_mi_admin_identify_partial(ctrl, args, + return nvme_mi_admin_identify_partial(link, args, 0, NVME_IDENTIFY_DATA_SIZE); } @@ -1490,7 +1482,7 @@ int nvme_mi_control(nvme_mi_ep_t ep, __u8 opcode, /** * nvme_mi_admin_identify_cns_nsid() - Perform an Admin identify command using * specific CNS/NSID parameters. - * @ctrl: Controller to process identify command + * @link: Link to process identify command * @cns: Controller or Namespace Structure, specifying identified object * @nsid: namespace ID * @data: buffer for identify data response @@ -1507,7 +1499,7 @@ int nvme_mi_control(nvme_mi_ep_t ep, __u8 opcode, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_mi_admin_identify_cns_nsid(nvme_mi_ctrl_t ctrl, +static inline int nvme_mi_admin_identify_cns_nsid(nvme_link_t link, enum nvme_identify_cns cns, __u32 nsid, void *data) { @@ -1523,13 +1515,13 @@ static inline int nvme_mi_admin_identify_cns_nsid(nvme_mi_ctrl_t ctrl, .uuidx = NVME_UUID_NONE, }; - return nvme_mi_admin_identify(ctrl, &args); + return nvme_mi_admin_identify(link, &args); } /** * nvme_mi_admin_identify_ns() - Perform an Admin identify command for a * namespace - * @ctrl: Controller to process identify command + * @link: Link to process identify command * @nsid: namespace ID * @ns: Namespace identification to populate * @@ -1539,17 +1531,17 @@ static inline int nvme_mi_admin_identify_cns_nsid(nvme_mi_ctrl_t ctrl, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_mi_admin_identify_ns(nvme_mi_ctrl_t ctrl, __u32 nsid, +static inline int nvme_mi_admin_identify_ns(nvme_link_t link, __u32 nsid, struct nvme_id_ns *ns) { - return nvme_mi_admin_identify_cns_nsid(ctrl, NVME_IDENTIFY_CNS_NS, + return nvme_mi_admin_identify_cns_nsid(link, NVME_IDENTIFY_CNS_NS, nsid, ns); } /** * nvme_mi_admin_identify_ns_descs() - Perform an Admin identify Namespace * Identification Descriptor list command for a namespace - * @ctrl: Controller to process identify command + * @link: Link to process identify command * @nsid: Namespace ID * @descs: Namespace Identification Descriptor list to populate * @@ -1559,18 +1551,18 @@ static inline int nvme_mi_admin_identify_ns(nvme_mi_ctrl_t ctrl, __u32 nsid, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_mi_admin_identify_ns_descs(nvme_mi_ctrl_t ctrl, +static inline int nvme_mi_admin_identify_ns_descs(nvme_link_t link, __u32 nsid, struct nvme_ns_id_desc *descs) { - return nvme_mi_admin_identify_cns_nsid(ctrl, NVME_IDENTIFY_CNS_NS_DESC_LIST, + return nvme_mi_admin_identify_cns_nsid(link, NVME_IDENTIFY_CNS_NS_DESC_LIST, nsid, descs); } /** * nvme_mi_admin_identify_allocated_ns() - Perform an Admin identify command * for an allocated namespace - * @ctrl: Controller to process identify command + * @link: Link to process identify command * @nsid: namespace ID * @ns: Namespace identification to populate * @@ -1580,18 +1572,18 @@ static inline int nvme_mi_admin_identify_ns_descs(nvme_mi_ctrl_t ctrl, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_mi_admin_identify_allocated_ns(nvme_mi_ctrl_t ctrl, +static inline int nvme_mi_admin_identify_allocated_ns(nvme_link_t link, __u32 nsid, struct nvme_id_ns *ns) { - return nvme_mi_admin_identify_cns_nsid(ctrl, + return nvme_mi_admin_identify_cns_nsid(link, NVME_IDENTIFY_CNS_ALLOCATED_NS, nsid, ns); } /** * nvme_mi_admin_identify_ctrl() - Perform an Admin identify for a controller - * @ctrl: Controller to process identify command + * @link: Link to process identify command * @id: Controller identify data to populate * * Perform an Identify command, for the controller specified by @ctrl, @@ -1606,17 +1598,17 @@ static inline int nvme_mi_admin_identify_allocated_ns(nvme_mi_ctrl_t ctrl, * * See: &struct nvme_id_ctrl */ -static inline int nvme_mi_admin_identify_ctrl(nvme_mi_ctrl_t ctrl, +static inline int nvme_mi_admin_identify_ctrl(nvme_link_t link, struct nvme_id_ctrl *id) { - return nvme_mi_admin_identify_cns_nsid(ctrl, NVME_IDENTIFY_CNS_CTRL, + return nvme_mi_admin_identify_cns_nsid(link, NVME_IDENTIFY_CNS_CTRL, NVME_NSID_NONE, id); } /** * nvme_mi_admin_identify_ctrl_list() - Perform an Admin identify for a * controller list. - * @ctrl: Controller to process identify command + * @link: Link to process identify command * @cntid: Controller ID to specify list start * @list: List data to populate * @@ -1632,7 +1624,7 @@ static inline int nvme_mi_admin_identify_ctrl(nvme_mi_ctrl_t ctrl, * * See: &struct nvme_ctrl_list */ -static inline int nvme_mi_admin_identify_ctrl_list(nvme_mi_ctrl_t ctrl, +static inline int nvme_mi_admin_identify_ctrl_list(nvme_link_t link, __u16 cntid, struct nvme_ctrl_list *list) { @@ -1648,13 +1640,13 @@ static inline int nvme_mi_admin_identify_ctrl_list(nvme_mi_ctrl_t ctrl, .uuidx = NVME_UUID_NONE, }; - return nvme_mi_admin_identify(ctrl, &args); + return nvme_mi_admin_identify(link, &args); } /** * nvme_mi_admin_identify_nsid_ctrl_list() - Perform an Admin identify for a * controller list with specific namespace ID - * @ctrl: Controller to process identify command + * @link: Link to process identify command * @nsid: Namespace identifier * @cntid: Controller ID to specify list start * @list: List data to populate @@ -1671,7 +1663,7 @@ static inline int nvme_mi_admin_identify_ctrl_list(nvme_mi_ctrl_t ctrl, * * See: &struct nvme_ctrl_list */ -static inline int nvme_mi_admin_identify_nsid_ctrl_list(nvme_mi_ctrl_t ctrl, +static inline int nvme_mi_admin_identify_nsid_ctrl_list(nvme_link_t link, __u32 nsid, __u16 cntid, struct nvme_ctrl_list *list) { @@ -1687,13 +1679,13 @@ static inline int nvme_mi_admin_identify_nsid_ctrl_list(nvme_mi_ctrl_t ctrl, .uuidx = NVME_UUID_NONE, }; - return nvme_mi_admin_identify(ctrl, &args); + return nvme_mi_admin_identify(link, &args); } /** * nvme_mi_admin_identify_allocated_ns_list() - Perform an Admin identify for * an allocated namespace list - * @ctrl: Controller to process identify command + * @link: Link to process identify command * @nsid: Namespace ID to specify list start * @list: List data to populate * @@ -1710,7 +1702,7 @@ static inline int nvme_mi_admin_identify_nsid_ctrl_list(nvme_mi_ctrl_t ctrl, * * See: &struct nvme_ns_list */ -static inline int nvme_mi_admin_identify_allocated_ns_list(nvme_mi_ctrl_t ctrl, +static inline int nvme_mi_admin_identify_allocated_ns_list(nvme_link_t link, __u32 nsid, struct nvme_ns_list *list) { @@ -1725,13 +1717,13 @@ static inline int nvme_mi_admin_identify_allocated_ns_list(nvme_mi_ctrl_t ctrl, .uuidx = NVME_UUID_NONE, }; - return nvme_mi_admin_identify(ctrl, &args); + return nvme_mi_admin_identify(link, &args); } /** * nvme_mi_admin_identify_active_ns_list() - Perform an Admin identify for an * active namespace list - * @ctrl: Controller to process identify command + * @link: Link to process identify command * @nsid: Namespace ID to specify list start * @list: List data to populate * @@ -1748,7 +1740,7 @@ static inline int nvme_mi_admin_identify_allocated_ns_list(nvme_mi_ctrl_t ctrl, * * See: &struct nvme_ns_list */ -static inline int nvme_mi_admin_identify_active_ns_list(nvme_mi_ctrl_t ctrl, +static inline int nvme_mi_admin_identify_active_ns_list(nvme_link_t link, __u32 nsid, struct nvme_ns_list *list) { @@ -1763,13 +1755,13 @@ static inline int nvme_mi_admin_identify_active_ns_list(nvme_mi_ctrl_t ctrl, .uuidx = NVME_UUID_NONE, }; - return nvme_mi_admin_identify(ctrl, &args); + return nvme_mi_admin_identify(link, &args); } /** * nvme_mi_admin_identify_primary_ctrl() - Perform an Admin identify for * primary controller capabilities data structure. - * @ctrl: Controller to process identify command + * @link: Link to process identify command * @cntid: Controller ID to specify * @cap: Primary Controller Capabilities data structure to populate * @@ -1784,7 +1776,7 @@ static inline int nvme_mi_admin_identify_active_ns_list(nvme_mi_ctrl_t ctrl, * * See: &struct nvme_primary_ctrl_cap */ -static inline int nvme_mi_admin_identify_primary_ctrl(nvme_mi_ctrl_t ctrl, +static inline int nvme_mi_admin_identify_primary_ctrl(nvme_link_t link, __u16 cntid, struct nvme_primary_ctrl_cap *cap) { @@ -1800,13 +1792,13 @@ static inline int nvme_mi_admin_identify_primary_ctrl(nvme_mi_ctrl_t ctrl, .uuidx = NVME_UUID_NONE, }; - return nvme_mi_admin_identify(ctrl, &args); + return nvme_mi_admin_identify(link, &args); } /** * nvme_mi_admin_identify_secondary_ctrl_list() - Perform an Admin identify for * a secondary controller list. - * @ctrl: Controller to process identify command + * @link: Link to process identify command * @cntid: Controller ID to specify list start * @list: List data to populate * @@ -1822,7 +1814,7 @@ static inline int nvme_mi_admin_identify_primary_ctrl(nvme_mi_ctrl_t ctrl, * * See: &struct nvme_secondary_ctrl_list */ -static inline int nvme_mi_admin_identify_secondary_ctrl_list(nvme_mi_ctrl_t ctrl, +static inline int nvme_mi_admin_identify_secondary_ctrl_list(nvme_link_t link, __u16 cntid, struct nvme_secondary_ctrl_list *list) { @@ -1838,12 +1830,12 @@ static inline int nvme_mi_admin_identify_secondary_ctrl_list(nvme_mi_ctrl_t ctrl .uuidx = NVME_UUID_NONE, }; - return nvme_mi_admin_identify(ctrl, &args); + return nvme_mi_admin_identify(link, &args); } /** * nvme_mi_admin_get_log_page() - Retrieve log page data from controller - * @ctrl: Controller to query + * @link: Link to query * @xfer_len: The chunk size of the read * @args: Get Log Page command arguments * @@ -1860,12 +1852,12 @@ static inline int nvme_mi_admin_identify_secondary_ctrl_list(nvme_mi_ctrl_t ctrl * * See: &struct nvme_get_log_args */ -int nvme_mi_admin_get_log_page(nvme_mi_ctrl_t ctrl, __u32 xfer_len, +int nvme_mi_admin_get_log_page(nvme_link_t link, __u32 xfer_len, struct nvme_get_log_args *args); /** * nvme_mi_admin_get_log() - Retrieve log page data from controller - * @ctrl: Controller to query + * @link: Link to query * @args: Get Log Page command arguments * * Performs a Get Log Page Admin command as specified by @args. Response data @@ -1881,11 +1873,11 @@ int nvme_mi_admin_get_log_page(nvme_mi_ctrl_t ctrl, __u32 xfer_len, * * See: &struct nvme_get_log_args */ -int nvme_mi_admin_get_log(nvme_mi_ctrl_t ctrl, struct nvme_get_log_args *args); +int nvme_mi_admin_get_log(nvme_link_t link, struct nvme_get_log_args *args); /** * nvme_mi_admin_get_nsid_log() - Helper for Get Log Page functions - * @ctrl: Controller to query + * @link: Link to query * @rae: Retain Asynchronous Events * @lid: Log identifier * @nsid: Namespace ID @@ -1900,7 +1892,7 @@ int nvme_mi_admin_get_log(nvme_mi_ctrl_t ctrl, struct nvme_get_log_args *args); * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_mi_admin_get_nsid_log(nvme_mi_ctrl_t ctrl, bool rae, +static inline int nvme_mi_admin_get_nsid_log(nvme_link_t link, bool rae, enum nvme_cmd_get_log_lid lid, __u32 nsid, __u32 len, void *log) { @@ -1920,12 +1912,12 @@ static inline int nvme_mi_admin_get_nsid_log(nvme_mi_ctrl_t ctrl, bool rae, .ot = false, }; - return nvme_mi_admin_get_log(ctrl, &args); + return nvme_mi_admin_get_log(link, &args); } /** * nvme_mi_admin_get_endgid_log() - Helper for Get Endurance Group ID Log Page functions - * @ctrl: Controller to query + * @link: Link to query * @rae: Retain Asynchronous Events * @lid: Log identifier * @endgid: Endurance Group ID @@ -1940,7 +1932,7 @@ static inline int nvme_mi_admin_get_nsid_log(nvme_mi_ctrl_t ctrl, bool rae, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_mi_admin_get_endgid_log(nvme_mi_ctrl_t ctrl, bool rae, +static inline int nvme_mi_admin_get_endgid_log(nvme_link_t link, bool rae, enum nvme_cmd_get_log_lid lid, __u16 endgid, __u32 len, void *log) { @@ -1961,13 +1953,13 @@ static inline int nvme_mi_admin_get_endgid_log(nvme_mi_ctrl_t ctrl, bool rae, .ot = false, }; - return nvme_mi_admin_get_log(ctrl, &args); + return nvme_mi_admin_get_log(link, &args); } /** * nvme_mi_admin_get_log_simple() - Helper for Get Log Page functions with no * NSID or RAE requirements - * @ctrl: Controller to query + * @link: Link to query * @lid: Log identifier * @len: length of log buffer * @log: pointer for resulting log data @@ -1978,36 +1970,36 @@ static inline int nvme_mi_admin_get_endgid_log(nvme_mi_ctrl_t ctrl, bool rae, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_mi_admin_get_log_simple(nvme_mi_ctrl_t ctrl, +static inline int nvme_mi_admin_get_log_simple(nvme_link_t link, enum nvme_cmd_get_log_lid lid, __u32 len, void *log) { - return nvme_mi_admin_get_nsid_log(ctrl, false, lid, NVME_NSID_ALL, + return nvme_mi_admin_get_nsid_log(link, false, lid, NVME_NSID_ALL, len, log); } /** * nvme_mi_admin_get_log_supported_log_pages() - Retrieve nmve supported log * pages - * @ctrl: Controller to query + * @link: Link to query * @rae: Retain asynchronous events * @log: Array of LID supported and Effects data structures * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_mi_admin_get_log_supported_log_pages(nvme_mi_ctrl_t ctrl, +static inline int nvme_mi_admin_get_log_supported_log_pages(nvme_link_t link, bool rae, struct nvme_supported_log_pages *log) { - return nvme_mi_admin_get_nsid_log(ctrl, rae, + return nvme_mi_admin_get_nsid_log(link, rae, NVME_LOG_LID_SUPPORTED_LOG_PAGES, NVME_NSID_ALL, sizeof(*log), log); } /** * nvme_mi_admin_get_log_error() - Retrieve nvme error log - * @ctrl: Controller to query + * @link: Link to query * @nr_entries: Number of error log entries allocated * @rae: Retain asynchronous events * @err_log: Array of error logs of size 'entries' @@ -2019,18 +2011,18 @@ static inline int nvme_mi_admin_get_log_supported_log_pages(nvme_mi_ctrl_t ctrl, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_mi_admin_get_log_error(nvme_mi_ctrl_t ctrl, +static inline int nvme_mi_admin_get_log_error(nvme_link_t link, unsigned int nr_entries, bool rae, struct nvme_error_log_page *err_log) { - return nvme_mi_admin_get_nsid_log(ctrl, rae, NVME_LOG_LID_ERROR, + return nvme_mi_admin_get_nsid_log(link, rae, NVME_LOG_LID_ERROR, NVME_NSID_ALL, sizeof(*err_log) * nr_entries, err_log); } /** * nvme_mi_admin_get_log_smart() - Retrieve nvme smart log - * @ctrl: Controller to query + * @link: Link to query * @nsid: Optional namespace identifier * @rae: Retain asynchronous events * @smart_log: User address to store the smart log @@ -2045,17 +2037,17 @@ static inline int nvme_mi_admin_get_log_error(nvme_mi_ctrl_t ctrl, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_mi_admin_get_log_smart(nvme_mi_ctrl_t ctrl, __u32 nsid, +static inline int nvme_mi_admin_get_log_smart(nvme_link_t link, __u32 nsid, bool rae, struct nvme_smart_log *smart_log) { - return nvme_mi_admin_get_nsid_log(ctrl, rae, NVME_LOG_LID_SMART, + return nvme_mi_admin_get_nsid_log(link, rae, NVME_LOG_LID_SMART, nsid, sizeof(*smart_log), smart_log); } /** * nvme_mi_admin_get_log_fw_slot() - Retrieves the controller firmware log - * @ctrl: Controller to query + * @link: Link to query * @rae: Retain asynchronous events * @fw_log: User address to store the log page * @@ -2066,16 +2058,16 @@ static inline int nvme_mi_admin_get_log_smart(nvme_mi_ctrl_t ctrl, __u32 nsid, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_mi_admin_get_log_fw_slot(nvme_mi_ctrl_t ctrl, bool rae, +static inline int nvme_mi_admin_get_log_fw_slot(nvme_link_t link, bool rae, struct nvme_firmware_slot *fw_log) { - return nvme_mi_admin_get_nsid_log(ctrl, rae, NVME_LOG_LID_FW_SLOT, + return nvme_mi_admin_get_nsid_log(link, rae, NVME_LOG_LID_FW_SLOT, NVME_NSID_ALL, sizeof(*fw_log), fw_log); } /** * nvme_mi_admin_get_log_changed_ns_list() - Retrieve namespace changed list - * @ctrl: Controller to query + * @link: Link to query * @rae: Retain asynchronous events * @ns_log: User address to store the log page * @@ -2086,17 +2078,17 @@ static inline int nvme_mi_admin_get_log_fw_slot(nvme_mi_ctrl_t ctrl, bool rae, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_mi_admin_get_log_changed_ns_list(nvme_mi_ctrl_t ctrl, +static inline int nvme_mi_admin_get_log_changed_ns_list(nvme_link_t link, bool rae, struct nvme_ns_list *ns_log) { - return nvme_mi_admin_get_nsid_log(ctrl, rae, NVME_LOG_LID_CHANGED_NS, + return nvme_mi_admin_get_nsid_log(link, rae, NVME_LOG_LID_CHANGED_NS, NVME_NSID_ALL, sizeof(*ns_log), ns_log); } /** * nvme_mi_admin_get_log_cmd_effects() - Retrieve nvme command effects log - * @ctrl: Controller to query + * @link: Link to query * @csi: Command Set Identifier * @effects_log: User address to store the effects log * @@ -2106,7 +2098,7 @@ static inline int nvme_mi_admin_get_log_changed_ns_list(nvme_mi_ctrl_t ctrl, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_mi_admin_get_log_cmd_effects(nvme_mi_ctrl_t ctrl, +static inline int nvme_mi_admin_get_log_cmd_effects(nvme_link_t link, enum nvme_csi csi, struct nvme_cmd_effects_log *effects_log) { @@ -2125,12 +2117,12 @@ static inline int nvme_mi_admin_get_log_cmd_effects(nvme_mi_ctrl_t ctrl, .rae = false, .ot = false, }; - return nvme_mi_admin_get_log(ctrl, &args); + return nvme_mi_admin_get_log(link, &args); } /** * nvme_mi_admin_get_log_device_self_test() - Retrieve the device self test log - * @ctrl: Controller to query + * @link: Link to query * @log: Userspace address of the log payload * * The log page indicates the status of an in progress self test and the @@ -2140,24 +2132,24 @@ static inline int nvme_mi_admin_get_log_cmd_effects(nvme_mi_ctrl_t ctrl, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_mi_admin_get_log_device_self_test(nvme_mi_ctrl_t ctrl, +static inline int nvme_mi_admin_get_log_device_self_test(nvme_link_t link, struct nvme_self_test_log *log) { - return nvme_mi_admin_get_nsid_log(ctrl, false, + return nvme_mi_admin_get_nsid_log(link, false, NVME_LOG_LID_DEVICE_SELF_TEST, NVME_NSID_ALL, sizeof(*log), log); } /** * nvme_mi_admin_get_log_create_telemetry_host_mcda() - Create host telemetry log - * @ctrl: Controller to query + * @link: Link to query * @mcda: Maximum Created Data Area * @log: Userspace address of the log payload * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_mi_admin_get_log_create_telemetry_host_mcda(nvme_mi_ctrl_t ctrl, +static inline int nvme_mi_admin_get_log_create_telemetry_host_mcda(nvme_link_t link, enum nvme_telemetry_da mcda, struct nvme_telemetry_log *log) { @@ -2176,27 +2168,27 @@ static inline int nvme_mi_admin_get_log_create_telemetry_host_mcda(nvme_mi_ctrl_ .rae = false, .ot = false, }; - return nvme_mi_admin_get_log(ctrl, &args); + return nvme_mi_admin_get_log(link, &args); } /** * nvme_mi_admin_get_log_create_telemetry_host() - Create host telemetry log - * @ctrl: Controller to query + * @link: Link to query * @log: Userspace address of the log payload * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_mi_admin_get_log_create_telemetry_host(nvme_mi_ctrl_t ctrl, +static inline int nvme_mi_admin_get_log_create_telemetry_host(nvme_link_t link, struct nvme_telemetry_log *log) { - return nvme_mi_admin_get_log_create_telemetry_host_mcda(ctrl, NVME_TELEMETRY_DA_CTRL_DETERMINE, log); + return nvme_mi_admin_get_log_create_telemetry_host_mcda(link, NVME_TELEMETRY_DA_CTRL_DETERMINE, log); } /** * nvme_mi_admin_get_log_telemetry_host() - Get Telemetry Host-Initiated log * page - * @ctrl: Controller to query + * @link: Link to query * @offset: Offset into the telemetry data * @len: Length of provided user buffer to hold the log data in bytes * @log: User address for log page data @@ -2207,7 +2199,7 @@ static inline int nvme_mi_admin_get_log_create_telemetry_host(nvme_mi_ctrl_t ctr * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_mi_admin_get_log_telemetry_host(nvme_mi_ctrl_t ctrl, +static inline int nvme_mi_admin_get_log_telemetry_host(nvme_link_t link, __u64 offset, __u32 len, void *log) { @@ -2226,13 +2218,13 @@ static inline int nvme_mi_admin_get_log_telemetry_host(nvme_mi_ctrl_t ctrl, .rae = false, .ot = false, }; - return nvme_mi_admin_get_log(ctrl, &args); + return nvme_mi_admin_get_log(link, &args); } /** * nvme_mi_admin_get_log_telemetry_ctrl() - Get Telemetry Controller-Initiated * log page - * @ctrl: Controller to query + * @link: Link to query * @rae: Retain asynchronous events * @offset: Offset into the telemetry data * @len: Length of provided user buffer to hold the log data in bytes @@ -2244,7 +2236,7 @@ static inline int nvme_mi_admin_get_log_telemetry_host(nvme_mi_ctrl_t ctrl, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_mi_admin_get_log_telemetry_ctrl(nvme_mi_ctrl_t ctrl, +static inline int nvme_mi_admin_get_log_telemetry_ctrl(nvme_link_t link, bool rae, __u64 offset, __u32 len, void *log) @@ -2264,12 +2256,12 @@ static inline int nvme_mi_admin_get_log_telemetry_ctrl(nvme_mi_ctrl_t ctrl, .rae = rae, .ot = false, }; - return nvme_mi_admin_get_log(ctrl, &args); + return nvme_mi_admin_get_log(link, &args); } /** * nvme_mi_admin_get_log_endurance_group() - Get Endurance Group log - * @ctrl: Controller to query + * @link: Link to query * @endgid: Starting group identifier to return in the list * @log: User address to store the endurance log * @@ -2283,7 +2275,7 @@ static inline int nvme_mi_admin_get_log_telemetry_ctrl(nvme_mi_ctrl_t ctrl, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_mi_admin_get_log_endurance_group(nvme_mi_ctrl_t ctrl, +static inline int nvme_mi_admin_get_log_endurance_group(nvme_link_t link, __u16 endgid, struct nvme_endurance_group_log *log) { @@ -2302,20 +2294,20 @@ static inline int nvme_mi_admin_get_log_endurance_group(nvme_mi_ctrl_t ctrl, .rae = false, .ot = false, }; - return nvme_mi_admin_get_log(ctrl, &args); + return nvme_mi_admin_get_log(link, &args); } /** * nvme_mi_admin_get_log_predictable_lat_nvmset() - Predictable Latency Per NVM * Set - * @ctrl: Controller to query + * @link: Link to query * @nvmsetid: NVM set id * @log: User address to store the predictable latency log * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_mi_admin_get_log_predictable_lat_nvmset(nvme_mi_ctrl_t ctrl, +static inline int nvme_mi_admin_get_log_predictable_lat_nvmset(nvme_link_t link, __u16 nvmsetid, struct nvme_nvmset_predictable_lat_log *log) { @@ -2334,13 +2326,13 @@ static inline int nvme_mi_admin_get_log_predictable_lat_nvmset(nvme_mi_ctrl_t ct .rae = false, .ot = false, }; - return nvme_mi_admin_get_log(ctrl, &args); + return nvme_mi_admin_get_log(link, &args); } /** * nvme_mi_admin_get_log_predictable_lat_event() - Retrieve Predictable Latency * Event Aggregate Log Page - * @ctrl: Controller to query + * @link: Link to query * @rae: Retain asynchronous events * @offset: Offset into the predictable latency event * @len: Length of provided user buffer to hold the log data in bytes @@ -2349,7 +2341,7 @@ static inline int nvme_mi_admin_get_log_predictable_lat_nvmset(nvme_mi_ctrl_t ct * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_mi_admin_get_log_predictable_lat_event(nvme_mi_ctrl_t ctrl, +static inline int nvme_mi_admin_get_log_predictable_lat_event(nvme_link_t link, bool rae, __u32 offset, __u32 len, @@ -2370,12 +2362,12 @@ static inline int nvme_mi_admin_get_log_predictable_lat_event(nvme_mi_ctrl_t ctr .rae = rae, .ot = false, }; - return nvme_mi_admin_get_log(ctrl, &args); + return nvme_mi_admin_get_log(link, &args); } /** * nvme_mi_admin_get_log_ana() - Retrieve Asymmetric Namespace Access log page - * @ctrl: Controller to query + * @link: Link to query * @lsp: Log specific, see &enum nvme_get_log_ana_lsp * @rae: Retain asynchronous events * @offset: Offset to the start of the log page @@ -2391,7 +2383,7 @@ static inline int nvme_mi_admin_get_log_predictable_lat_event(nvme_mi_ctrl_t ctr * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_mi_admin_get_log_ana(nvme_mi_ctrl_t ctrl, +static inline int nvme_mi_admin_get_log_ana(nvme_link_t link, enum nvme_log_ana_lsp lsp, bool rae, __u64 offset, __u32 len, void *log) { @@ -2410,13 +2402,13 @@ static inline int nvme_mi_admin_get_log_ana(nvme_mi_ctrl_t ctrl, .rae = rae, .ot = false, }; - return nvme_mi_admin_get_log(ctrl, &args); + return nvme_mi_admin_get_log(link, &args); } /** * nvme_mi_admin_get_log_ana_groups() - Retrieve Asymmetric Namespace Access * groups only log page - * @ctrl: Controller to query + * @link: Link to query * @rae: Retain asynchronous events * @len: The allocated length of the log page * @log: User address to store the ana group log @@ -2426,18 +2418,18 @@ static inline int nvme_mi_admin_get_log_ana(nvme_mi_ctrl_t ctrl, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_mi_admin_get_log_ana_groups(nvme_mi_ctrl_t ctrl, +static inline int nvme_mi_admin_get_log_ana_groups(nvme_link_t link, bool rae, __u32 len, struct nvme_ana_group_desc *log) { - return nvme_mi_admin_get_log_ana(ctrl, NVME_LOG_ANA_LSP_RGO_GROUPS_ONLY, rae, 0, + return nvme_mi_admin_get_log_ana(link, NVME_LOG_ANA_LSP_RGO_GROUPS_ONLY, rae, 0, len, log); } /** * nvme_mi_admin_get_ana_log_atomic() - Retrieve Asymmetric Namespace Access * log page atomically - * @ctrl: Controller to query + * @link: Link to query * @rgo: Whether to retrieve ANA groups only (no NSIDs) * @rae: Whether to retain asynchronous events * @retries: The maximum number of times to retry on log page changes @@ -2455,13 +2447,13 @@ static inline int nvme_mi_admin_get_log_ana_groups(nvme_mi_ctrl_t ctrl, * because chgcnt changed during each of the retries attempts. * Sets errno = ENOSPC if the full log page does not fit in the provided buffer. */ -int nvme_mi_admin_get_ana_log_atomic(nvme_mi_ctrl_t ctrl, bool rgo, bool rae, +int nvme_mi_admin_get_ana_log_atomic(nvme_link_t link, bool rgo, bool rae, unsigned int retries, struct nvme_ana_log *log, __u32 *len); /** * nvme_mi_admin_get_log_lba_status() - Retrieve LBA Status - * @ctrl: Controller to query + * @link: Link to query * @rae: Retain asynchronous events * @offset: Offset to the start of the log page * @len: The allocated length of the log page @@ -2470,7 +2462,7 @@ int nvme_mi_admin_get_ana_log_atomic(nvme_mi_ctrl_t ctrl, bool rgo, bool rae, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_mi_admin_get_log_lba_status(nvme_mi_ctrl_t ctrl, bool rae, +static inline int nvme_mi_admin_get_log_lba_status(nvme_link_t link, bool rae, __u64 offset, __u32 len, void *log) { @@ -2489,13 +2481,13 @@ static inline int nvme_mi_admin_get_log_lba_status(nvme_mi_ctrl_t ctrl, bool rae .rae = rae, .ot = false, }; - return nvme_mi_admin_get_log(ctrl, &args); + return nvme_mi_admin_get_log(link, &args); } /** * nvme_mi_admin_get_log_endurance_grp_evt() - Retrieve Rotational Media * Information - * @ctrl: Controller to query + * @link: Link to query * @rae: Retain asynchronous events * @offset: Offset to the start of the log page * @len: The allocated length of the log page @@ -2504,7 +2496,7 @@ static inline int nvme_mi_admin_get_log_lba_status(nvme_mi_ctrl_t ctrl, bool rae * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_mi_admin_get_log_endurance_grp_evt(nvme_mi_ctrl_t ctrl, +static inline int nvme_mi_admin_get_log_endurance_grp_evt(nvme_link_t link, bool rae, __u32 offset, __u32 len, @@ -2525,24 +2517,24 @@ static inline int nvme_mi_admin_get_log_endurance_grp_evt(nvme_mi_ctrl_t ctrl, .rae = rae, .ot = false, }; - return nvme_mi_admin_get_log(ctrl, &args); + return nvme_mi_admin_get_log(link, &args); } /** * nvme_mi_admin_get_log_fid_supported_effects() - Retrieve Feature Identifiers * Supported and Effects - * @ctrl: Controller to query + * @link: Link to query * @rae: Retain asynchronous events * @log: FID Supported and Effects data structure * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_mi_admin_get_log_fid_supported_effects(nvme_mi_ctrl_t ctrl, +static inline int nvme_mi_admin_get_log_fid_supported_effects(nvme_link_t link, bool rae, struct nvme_fid_supported_effects_log *log) { - return nvme_mi_admin_get_nsid_log(ctrl, rae, + return nvme_mi_admin_get_nsid_log(link, rae, NVME_LOG_LID_FID_SUPPORTED_EFFECTS, NVME_NSID_NONE, sizeof(*log), log); } @@ -2550,24 +2542,24 @@ static inline int nvme_mi_admin_get_log_fid_supported_effects(nvme_mi_ctrl_t ctr /** * nvme_mi_admin_get_log_mi_cmd_supported_effects() - displays the MI Commands * Supported by the controller - * @ctrl: Controller to query + * @link: Link to query * @rae: Retain asynchronous events * @log: MI Command Supported and Effects data structure * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_mi_admin_get_log_mi_cmd_supported_effects(nvme_mi_ctrl_t ctrl, +static inline int nvme_mi_admin_get_log_mi_cmd_supported_effects(nvme_link_t link, bool rae, struct nvme_mi_cmd_supported_effects_log *log) { - return nvme_mi_admin_get_nsid_log(ctrl, rae, NVME_LOG_LID_MI_CMD_SUPPORTED_EFFECTS, + return nvme_mi_admin_get_nsid_log(link, rae, NVME_LOG_LID_MI_CMD_SUPPORTED_EFFECTS, NVME_NSID_NONE, sizeof(*log), log); } /** * nvme_mi_admin_get_log_boot_partition() - Retrieve Boot Partition - * @ctrl: Controller to query + * @link: Link to query * @rae: Retain asynchronous events * @lsp: The log specified field of LID * @len: The allocated size, minimum @@ -2577,7 +2569,7 @@ static inline int nvme_mi_admin_get_log_mi_cmd_supported_effects(nvme_mi_ctrl_t * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_mi_admin_get_log_boot_partition(nvme_mi_ctrl_t ctrl, +static inline int nvme_mi_admin_get_log_boot_partition(nvme_link_t link, bool rae, __u8 lsp, __u32 len, struct nvme_boot_partition *part) @@ -2597,12 +2589,12 @@ static inline int nvme_mi_admin_get_log_boot_partition(nvme_mi_ctrl_t ctrl, .rae = rae, .ot = false, }; - return nvme_mi_admin_get_log(ctrl, &args); + return nvme_mi_admin_get_log(link, &args); } /** * nvme_mi_admin_get_log_rotational_media_info() - Retrieve Rotational Media Information Log - * @ctrl: Controller to query + * @link: Link to query * @endgid: Endurance Group Identifier * @len: The allocated length of the log page * @log: User address to store the log page @@ -2610,18 +2602,18 @@ static inline int nvme_mi_admin_get_log_boot_partition(nvme_mi_ctrl_t ctrl, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise */ -static inline int nvme_mi_admin_get_log_rotational_media_info(nvme_mi_ctrl_t ctrl, __u16 endgid, +static inline int nvme_mi_admin_get_log_rotational_media_info(nvme_link_t link, __u16 endgid, __u32 len, struct nvme_rotational_media_info_log *log) { - return nvme_mi_admin_get_endgid_log(ctrl, false, NVME_LOG_LID_ROTATIONAL_MEDIA_INFO, endgid, + return nvme_mi_admin_get_endgid_log(link, false, NVME_LOG_LID_ROTATIONAL_MEDIA_INFO, endgid, len, log); } /** * nvme_mi_admin_get_log_dispersed_ns_participating_nss() - Retrieve Dispersed Namespace * Participating NVM Subsystems Log - * @ctrl: Controller to query + * @link: Link to query * @nsid: Namespace Identifier * @len: The allocated length of the log page * @log: User address to store the log page @@ -2629,32 +2621,32 @@ static inline int nvme_mi_admin_get_log_rotational_media_info(nvme_mi_ctrl_t ctr * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise */ -static inline int nvme_mi_admin_get_log_dispersed_ns_participating_nss(nvme_mi_ctrl_t ctrl, +static inline int nvme_mi_admin_get_log_dispersed_ns_participating_nss(nvme_link_t link, __u32 nsid, __u32 len, struct nvme_dispersed_ns_participating_nss_log *log) { - return nvme_mi_admin_get_nsid_log(ctrl, false, NVME_LOG_LID_DISPERSED_NS_PARTICIPATING_NSS, + return nvme_mi_admin_get_nsid_log(link, false, NVME_LOG_LID_DISPERSED_NS_PARTICIPATING_NSS, nsid, len, log); } /** * nvme_mi_admin_get_log_mgmt_addr_list() - Retrieve Management Address List Log - * @ctrl: Controller to query + * @link: Link to query * @len: The allocated length of the log page * @log: User address to store the log page * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise */ -static inline int nvme_mi_admin_get_log_mgmt_addr_list(nvme_mi_ctrl_t ctrl, __u32 len, +static inline int nvme_mi_admin_get_log_mgmt_addr_list(nvme_link_t link, __u32 len, struct nvme_mgmt_addr_list_log *log) { - return nvme_mi_admin_get_log_simple(ctrl, NVME_LOG_LID_MGMT_ADDR_LIST, len, log); + return nvme_mi_admin_get_log_simple(link, NVME_LOG_LID_MGMT_ADDR_LIST, len, log); } /** * nvme_mi_admin_get_log_phy_rx_eom() - Retrieve Physical Interface Receiver Eye Opening Measurement Log - * @ctrl: Controller to query + * @link: Link to query * @lsp: Log specific, controls action and measurement quality * @controller: Target controller ID * @len: The allocated size, minimum @@ -2664,7 +2656,7 @@ static inline int nvme_mi_admin_get_log_mgmt_addr_list(nvme_mi_ctrl_t ctrl, __u3 * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise */ -static inline int nvme_mi_admin_get_log_phy_rx_eom(nvme_mi_ctrl_t ctrl, +static inline int nvme_mi_admin_get_log_phy_rx_eom(nvme_link_t link, __u8 lsp, __u16 controller, __u32 len, struct nvme_phy_rx_eom_log *log) @@ -2684,12 +2676,12 @@ static inline int nvme_mi_admin_get_log_phy_rx_eom(nvme_mi_ctrl_t ctrl, .rae = false, .ot = false, }; - return nvme_mi_admin_get_log(ctrl, &args); + return nvme_mi_admin_get_log(link, &args); } /** * nvme_mi_admin_get_log_reachability_groups() - Retrieve Reachability Groups Log - * @ctrl: Controller to query + * @link: Link to query * @rgo: Return groups only * @rae: Retain asynchronous events * @len: The allocated length of the log page @@ -2698,7 +2690,7 @@ static inline int nvme_mi_admin_get_log_phy_rx_eom(nvme_mi_ctrl_t ctrl, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise */ -static inline int nvme_mi_admin_get_log_reachability_groups(nvme_mi_ctrl_t ctrl, bool rgo, bool rae, +static inline int nvme_mi_admin_get_log_reachability_groups(nvme_link_t link, bool rgo, bool rae, __u32 len, struct nvme_reachability_groups_log *log) { struct nvme_get_log_args args = { @@ -2718,12 +2710,12 @@ static inline int nvme_mi_admin_get_log_reachability_groups(nvme_mi_ctrl_t ctrl, .ot = false, }; - return nvme_mi_admin_get_log_page(ctrl, NVME_LOG_PAGE_PDU_SIZE, &args); + return nvme_mi_admin_get_log_page(link, NVME_LOG_PAGE_PDU_SIZE, &args); } /** * nvme_mi_admin_get_log_reachability_associations() - Retrieve Reachability Associations Log - * @ctrl: Controller to query + * @link: Link to query * @rao: Return associations only * @rae: Retain asynchronous events * @len: The allocated length of the log page @@ -2732,7 +2724,7 @@ static inline int nvme_mi_admin_get_log_reachability_groups(nvme_mi_ctrl_t ctrl, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise */ -static inline int nvme_mi_admin_get_log_reachability_associations(nvme_mi_ctrl_t ctrl, bool rao, +static inline int nvme_mi_admin_get_log_reachability_associations(nvme_link_t link, bool rao, bool rae, __u32 len, struct nvme_reachability_associations_log *log) { @@ -2753,12 +2745,12 @@ static inline int nvme_mi_admin_get_log_reachability_associations(nvme_mi_ctrl_t .ot = false, }; - return nvme_mi_admin_get_log_page(ctrl, NVME_LOG_PAGE_PDU_SIZE, &args); + return nvme_mi_admin_get_log_page(link, NVME_LOG_PAGE_PDU_SIZE, &args); } /** * nvme_mi_admin_get_log_changed_alloc_ns_list() - Retrieve Changed Allocated Namespace List Log - * @ctrl: Controller to query + * @link: Link to query * @rae: Retain asynchronous events * @len: The allocated length of the log page * @log: User address to store the log page @@ -2766,16 +2758,16 @@ static inline int nvme_mi_admin_get_log_reachability_associations(nvme_mi_ctrl_t * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise */ -static inline int nvme_mi_admin_get_log_changed_alloc_ns_list(nvme_mi_ctrl_t ctrl, bool rae, +static inline int nvme_mi_admin_get_log_changed_alloc_ns_list(nvme_link_t link, bool rae, __u32 len, struct nvme_ns_list *log) { - return nvme_mi_admin_get_nsid_log(ctrl, rae, NVME_LOG_LID_CHANGED_ALLOC_NS_LIST, + return nvme_mi_admin_get_nsid_log(link, rae, NVME_LOG_LID_CHANGED_ALLOC_NS_LIST, NVME_NSID_ALL, len, log); } /** * nvme_mi_admin_get_log_discovery() - Retrieve Discovery log page - * @ctrl: Controller to query + * @link: Link to query * @rae: Retain asynchronous events * @offset: Offset of this log to retrieve * @len: The allocated size for this portion of the log @@ -2787,7 +2779,7 @@ static inline int nvme_mi_admin_get_log_changed_alloc_ns_list(nvme_mi_ctrl_t ctr * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_mi_admin_get_log_discovery(nvme_mi_ctrl_t ctrl, bool rae, +static inline int nvme_mi_admin_get_log_discovery(nvme_link_t link, bool rae, __u32 offset, __u32 len, void *log) { @@ -2806,12 +2798,12 @@ static inline int nvme_mi_admin_get_log_discovery(nvme_mi_ctrl_t ctrl, bool rae, .rae = rae, .ot = false, }; - return nvme_mi_admin_get_log(ctrl, &args); + return nvme_mi_admin_get_log(link, &args); } /** * nvme_mi_admin_get_log_host_discover() - Retrieve Host Discovery Log - * @ctrl: Controller to query + * @link: Link to query * @allhoste: All host entries * @rae: Retain asynchronous events * @len: The allocated length of the log page @@ -2820,7 +2812,7 @@ static inline int nvme_mi_admin_get_log_discovery(nvme_mi_ctrl_t ctrl, bool rae, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise */ -static inline int nvme_mi_admin_get_log_host_discover(nvme_mi_ctrl_t ctrl, bool allhoste, bool rae, +static inline int nvme_mi_admin_get_log_host_discover(nvme_link_t link, bool allhoste, bool rae, __u32 len, struct nvme_host_discover_log *log) { struct nvme_get_log_args args = { @@ -2840,12 +2832,12 @@ static inline int nvme_mi_admin_get_log_host_discover(nvme_mi_ctrl_t ctrl, bool .ot = false, }; - return nvme_mi_admin_get_log_page(ctrl, NVME_LOG_PAGE_PDU_SIZE, &args); + return nvme_mi_admin_get_log_page(link, NVME_LOG_PAGE_PDU_SIZE, &args); } /** * nvme_mi_admin_get_log_ave_discover() - Retrieve AVE Discovery Log - * @ctrl: Controller to query + * @link: Link to query * @rae: Retain asynchronous events * @len: The allocated length of the log page * @log: User address to store the log page @@ -2853,16 +2845,16 @@ static inline int nvme_mi_admin_get_log_host_discover(nvme_mi_ctrl_t ctrl, bool * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise */ -static inline int nvme_mi_admin_get_log_ave_discover(nvme_mi_ctrl_t ctrl, bool rae, __u32 len, +static inline int nvme_mi_admin_get_log_ave_discover(nvme_link_t link, bool rae, __u32 len, struct nvme_ave_discover_log *log) { - return nvme_mi_admin_get_nsid_log(ctrl, rae, NVME_LOG_LID_AVE_DISCOVER, NVME_NSID_ALL, len, + return nvme_mi_admin_get_nsid_log(link, rae, NVME_LOG_LID_AVE_DISCOVER, NVME_NSID_ALL, len, log); } /** * nvme_mi_admin_get_log_pull_model_ddc_req() - Retrieve Pull Model DDC Request Log - * @ctrl: Controller to query + * @link: Link to query * @rae: Retain asynchronous events * @len: The allocated length of the log page * @log: User address to store the log page @@ -2870,23 +2862,23 @@ static inline int nvme_mi_admin_get_log_ave_discover(nvme_mi_ctrl_t ctrl, bool r * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise */ -static inline int nvme_mi_admin_get_log_pull_model_ddc_req(nvme_mi_ctrl_t ctrl, bool rae, __u32 len, +static inline int nvme_mi_admin_get_log_pull_model_ddc_req(nvme_link_t link, bool rae, __u32 len, struct nvme_pull_model_ddc_req_log *log) { - return nvme_mi_admin_get_nsid_log(ctrl, rae, NVME_LOG_LID_PULL_MODEL_DDC_REQ, NVME_NSID_ALL, + return nvme_mi_admin_get_nsid_log(link, rae, NVME_LOG_LID_PULL_MODEL_DDC_REQ, NVME_NSID_ALL, len, log); } /** * nvme_mi_admin_get_log_media_unit_stat() - Retrieve Media Unit Status - * @ctrl: Controller to query + * @link: Link to query * @domid: Domain Identifier selection, if supported * @mus: User address to store the Media Unit statistics log * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_mi_admin_get_log_media_unit_stat(nvme_mi_ctrl_t ctrl, +static inline int nvme_mi_admin_get_log_media_unit_stat(nvme_link_t link, __u16 domid, struct nvme_media_unit_stat_log *mus) { @@ -2905,20 +2897,20 @@ static inline int nvme_mi_admin_get_log_media_unit_stat(nvme_mi_ctrl_t ctrl, .rae = false, .ot = false, }; - return nvme_mi_admin_get_log(ctrl, &args); + return nvme_mi_admin_get_log(link, &args); } /** * nvme_mi_admin_get_log_support_cap_config_list() - Retrieve Supported * Capacity Configuration List - * @ctrl: Controller to query + * @link: Link to query * @domid: Domain Identifier selection, if supported * @cap: User address to store supported capabilities config list * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_mi_admin_get_log_support_cap_config_list(nvme_mi_ctrl_t ctrl, +static inline int nvme_mi_admin_get_log_support_cap_config_list(nvme_link_t link, __u16 domid, struct nvme_supported_cap_config_list_log *cap) { @@ -2937,29 +2929,29 @@ static inline int nvme_mi_admin_get_log_support_cap_config_list(nvme_mi_ctrl_t c .rae = false, .ot = false, }; - return nvme_mi_admin_get_log(ctrl, &args); + return nvme_mi_admin_get_log(link, &args); } /** * nvme_mi_admin_get_log_reservation() - Retrieve Reservation Notification - * @ctrl: Controller to query + * @link: Link to query * @rae: Retain asynchronous events * @log: User address to store the reservation log * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_mi_admin_get_log_reservation(nvme_mi_ctrl_t ctrl, +static inline int nvme_mi_admin_get_log_reservation(nvme_link_t link, bool rae, struct nvme_resv_notification_log *log) { - return nvme_mi_admin_get_nsid_log(ctrl, rae, NVME_LOG_LID_RESERVATION, + return nvme_mi_admin_get_nsid_log(link, rae, NVME_LOG_LID_RESERVATION, NVME_NSID_ALL, sizeof(*log), log); } /** * nvme_mi_admin_get_log_sanitize() - Retrieve Sanitize Status - * @ctrl: Controller to query + * @link: Link to query * @rae: Retain asynchronous events * @log: User address to store the sanitize log * @@ -2969,17 +2961,17 @@ static inline int nvme_mi_admin_get_log_reservation(nvme_mi_ctrl_t ctrl, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_mi_admin_get_log_sanitize(nvme_mi_ctrl_t ctrl, bool rae, +static inline int nvme_mi_admin_get_log_sanitize(nvme_link_t link, bool rae, struct nvme_sanitize_log_page *log) { - return nvme_mi_admin_get_nsid_log(ctrl, rae, NVME_LOG_LID_SANITIZE, + return nvme_mi_admin_get_nsid_log(link, rae, NVME_LOG_LID_SANITIZE, NVME_NSID_ALL, sizeof(*log), log); } /** * nvme_mi_admin_get_log_zns_changed_zones() - Retrieve list of zones that have * changed - * @ctrl: Controller to query + * @link: Link to query * @nsid: Namespace ID * @rae: Retain asynchronous events * @log: User address to store the changed zone log @@ -2989,7 +2981,7 @@ static inline int nvme_mi_admin_get_log_sanitize(nvme_mi_ctrl_t ctrl, bool rae, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_mi_admin_get_log_zns_changed_zones(nvme_mi_ctrl_t ctrl, +static inline int nvme_mi_admin_get_log_zns_changed_zones(nvme_link_t link, __u32 nsid, bool rae, struct nvme_zns_changed_zone_log *log) { @@ -3008,12 +3000,12 @@ static inline int nvme_mi_admin_get_log_zns_changed_zones(nvme_mi_ctrl_t ctrl, .rae = rae, .ot = false, }; - return nvme_mi_admin_get_log(ctrl, &args); + return nvme_mi_admin_get_log(link, &args); } /** * nvme_mi_admin_get_log_persistent_event() - Retrieve Persistent Event Log - * @ctrl: Controller to query + * @link: Link to query * @action: Action the controller should take during processing this command * @size: Size of @pevent_log * @pevent_log: User address to store the persistent event log @@ -3021,7 +3013,7 @@ static inline int nvme_mi_admin_get_log_zns_changed_zones(nvme_mi_ctrl_t ctrl, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_mi_admin_get_log_persistent_event(nvme_mi_ctrl_t ctrl, +static inline int nvme_mi_admin_get_log_persistent_event(nvme_link_t link, enum nvme_pevent_log_action action, __u32 size, void *pevent_log) { @@ -3040,19 +3032,19 @@ static inline int nvme_mi_admin_get_log_persistent_event(nvme_mi_ctrl_t ctrl, .rae = false, .ot = false, }; - return nvme_mi_admin_get_log(ctrl, &args); + return nvme_mi_admin_get_log(link, &args); } /** * nvme_mi_admin_get_log_lockdown() - Retrieve lockdown Log - * @ctrl: Controller to query + * @link: Link to query * @cnscp: Contents and Scope of Command and Feature Identifier Lists * @lockdown_log: Buffer to store the lockdown log * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_mi_admin_get_log_lockdown(nvme_mi_ctrl_t ctrl, +static inline int nvme_mi_admin_get_log_lockdown(nvme_link_t link, __u8 cnscp, struct nvme_lockdown_log *lockdown_log) { struct nvme_get_log_args args = { @@ -3070,13 +3062,13 @@ static inline int nvme_mi_admin_get_log_lockdown(nvme_mi_ctrl_t ctrl, .rae = false, .ot = false, }; - return nvme_mi_admin_get_log(ctrl, &args); + return nvme_mi_admin_get_log(link, &args); } /** * nvme_mi_admin_security_send() - Perform a Security Send command on a * controller. - * @ctrl: Controller to send command to + * @link: Link to send command to * @args: Security Send command arguments * * Performs a Security Send Admin command as specified by @args. Response data @@ -3092,13 +3084,13 @@ static inline int nvme_mi_admin_get_log_lockdown(nvme_mi_ctrl_t ctrl, * * See: &struct nvme_get_log_args */ -int nvme_mi_admin_security_send(nvme_mi_ctrl_t ctrl, +int nvme_mi_admin_security_send(nvme_link_t link, struct nvme_security_send_args *args); /** * nvme_mi_admin_security_recv() - Perform a Security Receive command on a * controller. - * @ctrl: Controller to send command to + * @link: Link to send command to * @args: Security Receive command arguments * * Performs a Security Receive Admin command as specified by @args. Response @@ -3114,12 +3106,12 @@ int nvme_mi_admin_security_send(nvme_mi_ctrl_t ctrl, * * See: &struct nvme_get_log_args */ -int nvme_mi_admin_security_recv(nvme_mi_ctrl_t ctrl, +int nvme_mi_admin_security_recv(nvme_link_t link, struct nvme_security_receive_args *args); /** * nvme_mi_admin_get_features - Perform a Get Feature command on a controller - * @ctrl: Controller to send command to + * @link: Link to send command to * @args: Get Features command arguments * * Performs a Get Features Admin command as specified by @args. Returned @@ -3134,36 +3126,36 @@ int nvme_mi_admin_security_recv(nvme_mi_ctrl_t ctrl, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_mi_admin_get_features(nvme_mi_ctrl_t ctrl, +int nvme_mi_admin_get_features(nvme_link_t link, struct nvme_get_features_args *args); /** * nvme_mi_admin_get_features_arbitration() - Get arbitration feature - * @ctrl: Controller to send command to + * @link: Link to send command to * @sel: Select which type of attribute to return, see &enum nvme_get_features_sel * @result: The feature data is returned in this argument * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_mi_admin_get_features_arbitration(nvme_mi_ctrl_t ctrl, enum nvme_get_features_sel sel, +int nvme_mi_admin_get_features_arbitration(nvme_link_t link, enum nvme_get_features_sel sel, __u32 *result); /** * nvme_mi_admin_get_features_power_mgmt() - Get power management feature - * @ctrl: Controller to send command to + * @link: Link to send command to * @sel: Select which type of attribute to return, see &enum nvme_get_features_sel * @result: The feature data is returned in this argument * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_mi_admin_get_features_power_mgmt(nvme_mi_ctrl_t ctrl, enum nvme_get_features_sel sel, +int nvme_mi_admin_get_features_power_mgmt(nvme_link_t link, enum nvme_get_features_sel sel, __u32 *result); /** * nvme_mi_admin_get_features_data() - Helper function for &nvme_mi_admin_get_features() - * @ctrl: Controller to send command to + * @link: Link to send command to * @fid: Feature identifier * @nsid: Namespace ID, if applicable for @fid * @data_len: Length of feature data, if applicable for @fid, in bytes @@ -3176,7 +3168,7 @@ int nvme_mi_admin_get_features_power_mgmt(nvme_mi_ctrl_t ctrl, enum nvme_get_fea * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_mi_admin_get_features_data(nvme_mi_ctrl_t ctrl, +static inline int nvme_mi_admin_get_features_data(nvme_link_t link, enum nvme_features_id fid, __u32 nsid, __u32 data_len, void *data, __u32 *result) @@ -3193,28 +3185,28 @@ static inline int nvme_mi_admin_get_features_data(nvme_mi_ctrl_t ctrl, .uuidx = NVME_UUID_NONE, }; - return nvme_mi_admin_get_features(ctrl, &args); + return nvme_mi_admin_get_features(link, &args); } /** * nvme_mi_admin_get_features_simple - Get a simple feature value with no data - * @ctrl: Controller to send command to + * @link: Link to send command to * @fid: Feature identifier * @nsid: Namespace id, if required by @fid * @result: output feature data */ -static inline int nvme_mi_admin_get_features_simple(nvme_mi_ctrl_t ctrl, +static inline int nvme_mi_admin_get_features_simple(nvme_link_t link, enum nvme_features_id fid, __u32 nsid, __u32 *result) { - return nvme_mi_admin_get_features_data(ctrl, fid, nsid, + return nvme_mi_admin_get_features_data(link, fid, nsid, 0, NULL, result); } /** * nvme_mi_admin_set_features - Perform a Set Features command on a controller - * @ctrl: Controller to send command to + * @link: Link to send command to * @args: Set Features command arguments * * Performs a Set Features Admin command as specified by @args. Result @@ -3229,12 +3221,12 @@ static inline int nvme_mi_admin_get_features_simple(nvme_mi_ctrl_t ctrl, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_mi_admin_set_features(nvme_mi_ctrl_t ctrl, +int nvme_mi_admin_set_features(nvme_link_t link, struct nvme_set_features_args *args); /** * nvme_mi_admin_set_features_power_mgmt() - Set power management feature - * @ctrl: Controller to send command to + * @link: Link to send command to * @ps: Power State * @wh: Workload Hint * @save: Save value across power states @@ -3243,12 +3235,12 @@ int nvme_mi_admin_set_features(nvme_mi_ctrl_t ctrl, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_mi_admin_set_features_power_mgmt(nvme_mi_ctrl_t ctrl, __u8 ps, __u8 wh, bool save, +int nvme_mi_admin_set_features_power_mgmt(nvme_link_t link, __u8 ps, __u8 wh, bool save, __u32 *result); /** * nvme_mi_admin_ns_mgmt - Issue a Namespace Management command - * @ctrl: Controller to send command to + * @link: Link to send command to * @args: Namespace management command arguments * * Issues a Namespace Management command to @ctrl, with arguments specified @@ -3257,12 +3249,12 @@ int nvme_mi_admin_set_features_power_mgmt(nvme_mi_ctrl_t ctrl, __u8 ps, __u8 wh, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_mi_admin_ns_mgmt(nvme_mi_ctrl_t ctrl, +int nvme_mi_admin_ns_mgmt(nvme_link_t link, struct nvme_ns_mgmt_args *args); /** * nvme_mi_admin_ns_mgmt_create - Helper for Namespace Management Create command - * @ctrl: Controller to send command to + * @link: Link to send command to * @ns: New namespace parameters * @csi: Command Set Identifier for new NS * @nsid: Set to new namespace ID on create @@ -3275,7 +3267,7 @@ int nvme_mi_admin_ns_mgmt(nvme_mi_ctrl_t ctrl, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_mi_admin_ns_mgmt_create(nvme_mi_ctrl_t ctrl, +static inline int nvme_mi_admin_ns_mgmt_create(nvme_link_t link, struct nvme_id_ns *ns, __u8 csi, __u32 *nsid, struct nvme_ns_mgmt_host_sw_specified *data) { @@ -3289,12 +3281,12 @@ static inline int nvme_mi_admin_ns_mgmt_create(nvme_mi_ctrl_t ctrl, .data = data, }; - return nvme_mi_admin_ns_mgmt(ctrl, &args); + return nvme_mi_admin_ns_mgmt(link, &args); } /** * nvme_mi_admin_ns_mgmt_delete - Helper for Namespace Management Delete command - * @ctrl: Controller to send command to + * @link: Link to send command to * @nsid: Namespace ID to delete * * Issues a Namespace Management (Delete) command to @ctrl, to delete the @@ -3303,7 +3295,7 @@ static inline int nvme_mi_admin_ns_mgmt_create(nvme_mi_ctrl_t ctrl, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_mi_admin_ns_mgmt_delete(nvme_mi_ctrl_t ctrl, __u32 nsid) +static inline int nvme_mi_admin_ns_mgmt_delete(nvme_link_t link, __u32 nsid) { struct nvme_ns_mgmt_args args = { .args_size = sizeof(args), @@ -3311,30 +3303,30 @@ static inline int nvme_mi_admin_ns_mgmt_delete(nvme_mi_ctrl_t ctrl, __u32 nsid) .sel = NVME_NS_MGMT_SEL_DELETE, }; - return nvme_mi_admin_ns_mgmt(ctrl, &args); + return nvme_mi_admin_ns_mgmt(link, &args); } /** * nvme_mi_admin_ns_attach() - Attach or detach namespace to controller(s) - * @ctrl: Controller to send command to + * @link: Link to send command to * @args: Namespace Attach command arguments * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_mi_admin_ns_attach(nvme_mi_ctrl_t ctrl, +int nvme_mi_admin_ns_attach(nvme_link_t link, struct nvme_ns_attach_args *args); /** * nvme_mi_admin_ns_attach_ctrls() - Attach namespace to controllers - * @ctrl: Controller to send command to + * @link: Link to send command to * @nsid: Namespace ID to attach * @ctrlist: Controller list to modify attachment state of nsid * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_mi_admin_ns_attach_ctrls(nvme_mi_ctrl_t ctrl, __u32 nsid, +static inline int nvme_mi_admin_ns_attach_ctrls(nvme_link_t link, __u32 nsid, struct nvme_ctrl_list *ctrlist) { struct nvme_ns_attach_args args = { @@ -3345,19 +3337,19 @@ static inline int nvme_mi_admin_ns_attach_ctrls(nvme_mi_ctrl_t ctrl, __u32 nsid, .sel = NVME_NS_ATTACH_SEL_CTRL_ATTACH, }; - return nvme_mi_admin_ns_attach(ctrl, &args); + return nvme_mi_admin_ns_attach(link, &args); } /** * nvme_mi_admin_ns_detach_ctrls() - Detach namespace from controllers - * @ctrl: Controller to send command to + * @link: Link to send command to * @nsid: Namespace ID to detach * @ctrlist: Controller list to modify attachment state of nsid * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -static inline int nvme_mi_admin_ns_detach_ctrls(nvme_mi_ctrl_t ctrl, __u32 nsid, +static inline int nvme_mi_admin_ns_detach_ctrls(nvme_link_t link, __u32 nsid, struct nvme_ctrl_list *ctrlist) { struct nvme_ns_attach_args args = { @@ -3368,13 +3360,13 @@ static inline int nvme_mi_admin_ns_detach_ctrls(nvme_mi_ctrl_t ctrl, __u32 nsid, .sel = NVME_NS_ATTACH_SEL_CTRL_DEATTACH, }; - return nvme_mi_admin_ns_attach(ctrl, &args); + return nvme_mi_admin_ns_attach(link, &args); } /** * nvme_mi_admin_fw_download() - Download part or all of a firmware image to * the controller - * @ctrl: Controller to send firmware data to + * @link: Link to send firmware data to * @args: &struct nvme_fw_download_args argument structure * * The Firmware Image Download command downloads all or a portion of an image @@ -3392,24 +3384,24 @@ static inline int nvme_mi_admin_ns_detach_ctrls(nvme_mi_ctrl_t ctrl, __u32 nsid, * * Return: 0 on success, non-zero on failure */ -int nvme_mi_admin_fw_download(nvme_mi_ctrl_t ctrl, +int nvme_mi_admin_fw_download(nvme_link_t link, struct nvme_fw_download_args *args); /** * nvme_mi_admin_fw_commit() - Commit firmware using the specified action - * @ctrl: Controller to send firmware data to + * @link: Link to send firmware data to * @args: &struct nvme_fw_download_args argument structure * * The Firmware Commit command modifies the firmware image or Boot Partitions. * * Return: 0 on success, non-zero on failure */ -int nvme_mi_admin_fw_commit(nvme_mi_ctrl_t ctrl, +int nvme_mi_admin_fw_commit(nvme_link_t link, struct nvme_fw_commit_args *args); /** * nvme_mi_admin_format_nvm() - Format NVMe namespace - * @ctrl: Controller to send command to + * @link: Link to send command to * @args: Format NVM command arguments * * Perform a low-level format to set the LBA data & metadata size. May destroy @@ -3418,12 +3410,12 @@ int nvme_mi_admin_fw_commit(nvme_mi_ctrl_t ctrl, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_mi_admin_format_nvm(nvme_mi_ctrl_t ctrl, +int nvme_mi_admin_format_nvm(nvme_link_t link, struct nvme_format_nvm_args *args); /** * nvme_mi_admin_sanitize_nvm() - Start a subsystem Sanitize operation - * @ctrl: Controller to send command to + * @link: Link to send command to * @args: Sanitize command arguments * * A sanitize operation alters all user data in the NVM subsystem such that @@ -3439,7 +3431,7 @@ int nvme_mi_admin_format_nvm(nvme_mi_ctrl_t ctrl, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_mi_admin_sanitize_nvm(nvme_mi_ctrl_t ctrl, +int nvme_mi_admin_sanitize_nvm(nvme_link_t link, struct nvme_sanitize_nvm_args *args); /** diff --git a/src/nvme/private.h b/src/nvme/private.h index 6eee5a66a..a3cfa3d4e 100644 --- a/src/nvme/private.h +++ b/src/nvme/private.h @@ -39,6 +39,11 @@ struct nvme_link { int fd; struct stat stat; + /* mi */ + struct nvme_mi_ep *ep; + __u16 id; + struct list_node ep_entry; + struct nvme_log *log; }; @@ -317,12 +322,6 @@ struct nvme_mi_ep { struct nvme_mi_aem_ctx *aem_ctx; }; -struct nvme_mi_ctrl { - struct nvme_mi_ep *ep; - __u16 id; - struct list_node ep_entry; -}; - struct nvme_mi_ep *nvme_mi_init_ep(struct nvme_root *root); void nvme_mi_ep_probe(struct nvme_mi_ep *ep); diff --git a/test/mi-mctp.c b/test/mi-mctp.c index 7d1acd2c6..271502a01 100644 --- a/test/mi-mctp.c +++ b/test/mi-mctp.c @@ -405,18 +405,18 @@ static void test_mi_resp_unaligned_expected(nvme_mi_ep_t ep, static void test_admin_resp_err(nvme_mi_ep_t ep, struct test_peer *peer) { struct nvme_id_ctrl id; - nvme_mi_ctrl_t ctrl; + nvme_link_t link; int rc; - ctrl = nvme_mi_init_ctrl(ep, 1); - assert(ctrl); + link = nvme_mi_init_link(ep, 1); + assert(link); /* Simple error response, will be shorter than the expected Admin * command response header. */ peer->tx_buf[4] = 0x02; /* internal error */ peer->tx_buf_len = 8; - rc = nvme_mi_admin_identify_ctrl(ctrl, &id); + rc = nvme_mi_admin_identify_ctrl(link, &id); assert(nvme_status_get_type(rc) == NVME_STATUS_TYPE_MI); assert(nvme_status_get_value(rc) == NVME_MI_RESP_INTERNAL_ERR); } @@ -430,23 +430,23 @@ static void test_admin_resp_err(nvme_mi_ep_t ep, struct test_peer *peer) static void test_admin_resp_sizes(nvme_mi_ep_t ep, struct test_peer *peer) { struct nvme_id_ctrl id; - nvme_mi_ctrl_t ctrl; + nvme_link_t link; unsigned int i; int rc; - ctrl = nvme_mi_init_ctrl(ep, 1); - assert(ctrl); + link = nvme_mi_init_link(ep, 1); + assert(link); peer->tx_buf[4] = 0x02; /* internal error */ for (i = 8; i <= 4096 + 8; i+=4) { peer->tx_buf_len = i; - rc = nvme_mi_admin_identify_ctrl(ctrl, &id); + rc = nvme_mi_admin_identify_ctrl(link, &id); assert(nvme_status_get_type(rc) == NVME_STATUS_TYPE_MI); assert(nvme_status_get_value(rc) == NVME_MI_RESP_INTERNAL_ERR); } - nvme_mi_close_ctrl(ctrl); + nvme_mi_close_link(link); } /* test: timeout value passed to poll */ @@ -552,7 +552,7 @@ static void test_mpr_admin(nvme_mi_ep_t ep, struct test_peer *peer) { struct mpr_tx_info tx_info; struct nvme_id_ctrl id; - nvme_mi_ctrl_t ctrl; + nvme_link_t link; int rc; tx_info.msg_no = 1; @@ -562,12 +562,12 @@ static void test_mpr_admin(nvme_mi_ep_t ep, struct test_peer *peer) peer->tx_fn = tx_mpr; peer->tx_data = &tx_info; - ctrl = nvme_mi_init_ctrl(ep, 1); + link = nvme_mi_init_link(ep, 1); - rc = nvme_mi_admin_identify_ctrl(ctrl, &id); + rc = nvme_mi_admin_identify_ctrl(link, &id); assert(rc == 0); - nvme_mi_close_ctrl(ctrl); + nvme_mi_close_link(link); } /* We have seen drives that send a MPR response as a full Admin message, @@ -577,7 +577,7 @@ static void test_mpr_admin_quirked(nvme_mi_ep_t ep, struct test_peer *peer) { struct mpr_tx_info tx_info; struct nvme_id_ctrl id; - nvme_mi_ctrl_t ctrl; + nvme_link_t link; int rc; tx_info.msg_no = 1; @@ -587,12 +587,12 @@ static void test_mpr_admin_quirked(nvme_mi_ep_t ep, struct test_peer *peer) peer->tx_fn = tx_mpr; peer->tx_data = &tx_info; - ctrl = nvme_mi_init_ctrl(ep, 1); + link = nvme_mi_init_link(ep, 1); - rc = nvme_mi_admin_identify_ctrl(ctrl, &id); + rc = nvme_mi_admin_identify_ctrl(link, &id); assert(rc == 0); - nvme_mi_close_ctrl(ctrl); + nvme_mi_close_link(link); } /* helpers for the MPR + poll tests */ diff --git a/test/mi.c b/test/mi.c index f92b3b131..5fd96a1dd 100644 --- a/test/mi.c +++ b/test/mi.c @@ -168,9 +168,9 @@ static void test_endpoint_lifetime(nvme_mi_ep_t ep) unsigned int count_ep_controllers(nvme_mi_ep_t ep) { unsigned int i = 0; - nvme_mi_ctrl_t ctrl; + nvme_link_t link; - nvme_mi_for_each_ctrl(ep, ctrl) + nvme_mi_for_each_link(ep, link) i++; return i; @@ -180,7 +180,7 @@ unsigned int count_ep_controllers(nvme_mi_ep_t ep) * creation/destruction */ static void test_ctrl_lifetime(nvme_mi_ep_t ep) { - nvme_mi_ctrl_t c1, c2; + nvme_link_t l1, l2; int count; ep->controllers_scanned = true; @@ -188,19 +188,19 @@ static void test_ctrl_lifetime(nvme_mi_ep_t ep) count = count_ep_controllers(ep); assert(count == 0); - c1 = nvme_mi_init_ctrl(ep, 1); + l1 = nvme_mi_init_link(ep, 1); count = count_ep_controllers(ep); assert(count == 1); - c2 = nvme_mi_init_ctrl(ep, 2); + l2 = nvme_mi_init_link(ep, 2); count = count_ep_controllers(ep); assert(count == 2); - nvme_mi_close_ctrl(c1); + nvme_mi_close_link(l1); count = count_ep_controllers(ep); assert(count == 1); - nvme_mi_close_ctrl(c2); + nvme_mi_close_link(l2); count = count_ep_controllers(ep); assert(count == 0); } @@ -361,7 +361,7 @@ static int test_scan_ctrl_list_cb(struct nvme_mi_ep *ep, static void test_scan_ctrl_list(nvme_mi_ep_t ep) { - struct nvme_mi_ctrl *ctrl; + struct nvme_link *link; ep->controllers_scanned = false; @@ -369,20 +369,20 @@ static void test_scan_ctrl_list(nvme_mi_ep_t ep) nvme_mi_scan_ep(ep, false); - ctrl = nvme_mi_first_ctrl(ep); - assert(ctrl); - assert(ctrl->id == 1); + link = nvme_mi_first_link(ep); + assert(link); + assert(link->id == 1); - ctrl = nvme_mi_next_ctrl(ep, ctrl); - assert(ctrl); - assert(ctrl->id == 4); + link = nvme_mi_next_link(ep, link); + assert(link); + assert(link->id == 4); - ctrl = nvme_mi_next_ctrl(ep, ctrl); - assert(ctrl); - assert(ctrl->id == 5); + link = nvme_mi_next_link(ep, link); + assert(link); + assert(link->id == 5); - ctrl = nvme_mi_next_ctrl(ep, ctrl); - assert(ctrl == NULL); + link = nvme_mi_next_link(ep, link); + assert(link == NULL); } /* test: simple NVMe admin request/response */ @@ -438,15 +438,15 @@ static int test_admin_id_cb(struct nvme_mi_ep *ep, static void test_admin_id(nvme_mi_ep_t ep) { struct nvme_id_ctrl id; - nvme_mi_ctrl_t ctrl; + nvme_link_t link; int rc; test_set_transport_callback(ep, test_admin_id_cb, NULL); - ctrl = nvme_mi_init_ctrl(ep, 5); - assert(ctrl); + link = nvme_mi_init_link(ep, 5); + assert(link); - rc = nvme_mi_admin_identify_ctrl(ctrl, &id); + rc = nvme_mi_admin_identify_ctrl(link, &id); assert(rc == 0); } @@ -492,15 +492,15 @@ static int test_admin_err_mi_resp_cb(struct nvme_mi_ep *ep, static void test_admin_err_mi_resp(nvme_mi_ep_t ep) { struct nvme_id_ctrl id; - nvme_mi_ctrl_t ctrl; + nvme_link_t link ; int rc; test_set_transport_callback(ep, test_admin_err_mi_resp_cb, NULL); - ctrl = nvme_mi_init_ctrl(ep, 1); - assert(ctrl); + link = nvme_mi_init_link(ep, 1); + assert(link); - rc = nvme_mi_admin_identify_ctrl(ctrl, &id); + rc = nvme_mi_admin_identify_ctrl(link, &id); assert(rc != 0); assert(nvme_status_get_type(rc) == NVME_STATUS_TYPE_MI); assert(nvme_status_get_value(rc) == NVME_MI_RESP_INTERNAL_ERR); @@ -554,15 +554,15 @@ static int test_admin_err_nvme_resp_cb(struct nvme_mi_ep *ep, static void test_admin_err_nvme_resp(nvme_mi_ep_t ep) { struct nvme_id_ctrl id; - nvme_mi_ctrl_t ctrl; + nvme_link_t link; int rc; test_set_transport_callback(ep, test_admin_err_nvme_resp_cb, NULL); - ctrl = nvme_mi_init_ctrl(ep, 1); - assert(ctrl); + link = nvme_mi_init_link(ep, 1); + assert(link); - rc = nvme_mi_admin_identify_ctrl(ctrl, &id); + rc = nvme_mi_admin_identify_ctrl(link, &id); assert(rc != 0); assert(nvme_status_get_type(rc) == NVME_STATUS_TYPE_NVME); assert(nvme_status_get_value(rc) == @@ -588,48 +588,48 @@ static void test_admin_invalid_formats(nvme_mi_ep_t ep) uint8_t data[4]; } req = { 0 }; struct nvme_mi_admin_resp_hdr resp = { 0 }; - nvme_mi_ctrl_t ctrl; + nvme_link_t link; size_t len; int rc; test_set_transport_callback(ep, test_rejected_command_cb, NULL); - ctrl = nvme_mi_init_ctrl(ep, 1); - assert(ctrl); + link = nvme_mi_init_link(ep, 1); + assert(link); /* unaligned req size */ len = 0; - rc = nvme_mi_admin_xfer(ctrl, &req.hdr, 1, &resp, 0, &len); + rc = nvme_mi_admin_xfer(link, &req.hdr, 1, &resp, 0, &len); assert(rc != 0); /* unaligned resp size */ len = 1; - rc = nvme_mi_admin_xfer(ctrl, &req.hdr, 0, &resp, 0, &len); + rc = nvme_mi_admin_xfer(link, &req.hdr, 0, &resp, 0, &len); assert(rc != 0); /* unaligned resp offset */ len = 4; - rc = nvme_mi_admin_xfer(ctrl, &req.hdr, 0, &resp, 1, &len); + rc = nvme_mi_admin_xfer(link, &req.hdr, 0, &resp, 1, &len); assert(rc != 0); /* resp too large */ len = 4096 + 4; - rc = nvme_mi_admin_xfer(ctrl, &req.hdr, 0, &resp, 0, &len); + rc = nvme_mi_admin_xfer(link, &req.hdr, 0, &resp, 0, &len); assert(rc != 0); /* resp offset too large */ len = 4; - rc = nvme_mi_admin_xfer(ctrl, &req.hdr, 0, &resp, (off_t)1 << 32, &len); + rc = nvme_mi_admin_xfer(link, &req.hdr, 0, &resp, (off_t)1 << 32, &len); assert(rc != 0); /* resp offset with no len */ len = 0; - rc = nvme_mi_admin_xfer(ctrl, &req.hdr, 0, &resp, 4, &len); + rc = nvme_mi_admin_xfer(link, &req.hdr, 0, &resp, 4, &len); assert(rc != 0); /* req and resp payloads */ len = 4; - rc = nvme_mi_admin_xfer(ctrl, &req.hdr, 4, &resp, 0, &len); + rc = nvme_mi_admin_xfer(link, &req.hdr, 4, &resp, 0, &len); assert(rc != 0); } @@ -640,14 +640,14 @@ static void test_mi_invalid_formats(nvme_mi_ep_t ep) uint8_t data[4]; } req = { 0 }; struct nvme_mi_mi_resp_hdr resp = { 0 }; - nvme_mi_ctrl_t ctrl; + nvme_link_t link; size_t len; int rc; test_set_transport_callback(ep, test_rejected_command_cb, NULL); - ctrl = nvme_mi_init_ctrl(ep, 1); - assert(ctrl); + link = nvme_mi_init_link(ep, 1); + assert(link); /* resp too large */ len = 4096 + 4; @@ -961,21 +961,21 @@ static int test_admin_get_features_cb(struct nvme_mi_ep *ep, static void test_get_features_nodata(nvme_mi_ep_t ep) { struct nvme_get_features_args args = { 0 }; - nvme_mi_ctrl_t ctrl; + nvme_link_t link; uint32_t res; int rc; test_set_transport_callback(ep, test_admin_get_features_cb, NULL); - ctrl = nvme_mi_init_ctrl(ep, 5); - assert(ctrl); + link = nvme_mi_init_link(ep, 5); + assert(link); args.args_size = sizeof(args); args.fid = NVME_FEAT_FID_ARBITRATION; args.sel = 0; args.result = &res; - rc = nvme_mi_admin_get_features(ctrl, &args); + rc = nvme_mi_admin_get_features(link, &args); assert(rc == 0); assert(args.data_len == 0); assert(res == 0x04030201); @@ -985,15 +985,15 @@ static void test_get_features_data(nvme_mi_ep_t ep) { struct nvme_get_features_args args = { 0 }; struct nvme_timestamp tstamp; - nvme_mi_ctrl_t ctrl; + nvme_link_t link; uint8_t exp[6]; uint32_t res; int rc, i; test_set_transport_callback(ep, test_admin_get_features_cb, NULL); - ctrl = nvme_mi_init_ctrl(ep, 5); - assert(ctrl); + link = nvme_mi_init_link(ep, 5); + assert(link); args.args_size = sizeof(args); args.fid = NVME_FEAT_FID_TIMESTAMP; @@ -1006,7 +1006,7 @@ static void test_get_features_data(nvme_mi_ep_t ep) for (i = 0; i < sizeof(tstamp.timestamp); i++) exp[i] = i; - rc = nvme_mi_admin_get_features(ctrl, &args); + rc = nvme_mi_admin_get_features(link, &args); assert(rc == 0); assert(args.data_len == sizeof(tstamp)); assert(tstamp.attr == 1); @@ -1069,14 +1069,14 @@ static void test_set_features(nvme_mi_ep_t ep) { struct nvme_set_features_args args = { 0 }; struct nvme_timestamp tstamp = { 0 }; - nvme_mi_ctrl_t ctrl; + nvme_link_t link; uint32_t res; int rc, i; test_set_transport_callback(ep, test_admin_set_features_cb, NULL); - ctrl = nvme_mi_init_ctrl(ep, 5); - assert(ctrl); + link = nvme_mi_init_link(ep, 5); + assert(link); for (i = 0; i < sizeof(tstamp.timestamp); i++) tstamp.timestamp[i] = i; @@ -1088,7 +1088,7 @@ static void test_set_features(nvme_mi_ep_t ep) args.data = &tstamp; args.data_len = sizeof(tstamp); - rc = nvme_mi_admin_set_features(ctrl, &args); + rc = nvme_mi_admin_set_features(link, &args); assert(rc == 0); assert(args.data_len == 0); } @@ -1147,17 +1147,17 @@ static int test_admin_id_ns_list_cb(struct nvme_mi_ep *ep, static void test_admin_id_alloc_ns_list(struct nvme_mi_ep *ep) { struct nvme_ns_list list; - nvme_mi_ctrl_t ctrl; + nvme_link_t link; enum ns_type type; int rc; type = NS_ALLOC; test_set_transport_callback(ep, test_admin_id_ns_list_cb, &type); - ctrl = nvme_mi_init_ctrl(ep, 5); - assert(ctrl); + link = nvme_mi_init_link(ep, 5); + assert(link); - rc = nvme_mi_admin_identify_allocated_ns_list(ctrl, 1, &list); + rc = nvme_mi_admin_identify_allocated_ns_list(link, 1, &list); assert(!rc); assert(le32_to_cpu(list.ns[0]) == 2); @@ -1168,17 +1168,17 @@ static void test_admin_id_alloc_ns_list(struct nvme_mi_ep *ep) static void test_admin_id_active_ns_list(struct nvme_mi_ep *ep) { struct nvme_ns_list list; - nvme_mi_ctrl_t ctrl; + nvme_link_t link; enum ns_type type; int rc; type = NS_ACTIVE; test_set_transport_callback(ep, test_admin_id_ns_list_cb, &type); - ctrl = nvme_mi_init_ctrl(ep, 5); - assert(ctrl); + link = nvme_mi_init_link(ep, 5); + assert(link); - rc = nvme_mi_admin_identify_active_ns_list(ctrl, 1, &list); + rc = nvme_mi_admin_identify_active_ns_list(link, 1, &list); assert(!rc); assert(le32_to_cpu(list.ns[0]) == 4); @@ -1231,17 +1231,17 @@ static int test_admin_id_ns_cb(struct nvme_mi_ep *ep, static void test_admin_id_alloc_ns(struct nvme_mi_ep *ep) { struct nvme_id_ns id; - nvme_mi_ctrl_t ctrl; + nvme_link_t link; enum ns_type type; int rc; type = NS_ALLOC; test_set_transport_callback(ep, test_admin_id_ns_cb, &type); - ctrl = nvme_mi_init_ctrl(ep, 5); - assert(ctrl); + link = nvme_mi_init_link(ep, 5); + assert(link); - rc = nvme_mi_admin_identify_allocated_ns(ctrl, 1, &id); + rc = nvme_mi_admin_identify_allocated_ns(link, 1, &id); assert(!rc); assert(le64_to_cpu(id.nsze) == 1); } @@ -1249,17 +1249,17 @@ static void test_admin_id_alloc_ns(struct nvme_mi_ep *ep) static void test_admin_id_active_ns(struct nvme_mi_ep *ep) { struct nvme_id_ns id; - nvme_mi_ctrl_t ctrl; + nvme_link_t link; enum ns_type type; int rc; type = NS_ACTIVE; test_set_transport_callback(ep, test_admin_id_ns_cb, &type); - ctrl = nvme_mi_init_ctrl(ep, 5); - assert(ctrl); + link = nvme_mi_init_link(ep, 5); + assert(link); - rc = nvme_mi_admin_identify_ns(ctrl, 1, &id); + rc = nvme_mi_admin_identify_ns(link, 1, &id); assert(!rc); assert(le64_to_cpu(id.nsze) == 1); } @@ -1296,15 +1296,15 @@ static int test_admin_id_nsid_ctrl_list_cb(struct nvme_mi_ep *ep, static void test_admin_id_nsid_ctrl_list(struct nvme_mi_ep *ep) { struct nvme_ctrl_list list; - nvme_mi_ctrl_t ctrl; + nvme_link_t link; int rc; test_set_transport_callback(ep, test_admin_id_nsid_ctrl_list_cb, NULL); - ctrl = nvme_mi_init_ctrl(ep, 5); - assert(ctrl); + link = nvme_mi_init_link(ep, 5); + assert(link); - rc = nvme_mi_admin_identify_nsid_ctrl_list(ctrl, 0x01020304, 5, &list); + rc = nvme_mi_admin_identify_nsid_ctrl_list(link, 0x01020304, 5, &list); assert(!rc); } @@ -1336,16 +1336,16 @@ static int test_admin_id_secondary_ctrl_list_cb(struct nvme_mi_ep *ep, static void test_admin_id_secondary_ctrl_list(struct nvme_mi_ep *ep) { struct nvme_secondary_ctrl_list list; - nvme_mi_ctrl_t ctrl; + nvme_link_t link; int rc; test_set_transport_callback(ep, test_admin_id_secondary_ctrl_list_cb, NULL); - ctrl = nvme_mi_init_ctrl(ep, 5); - assert(ctrl); + link = nvme_mi_init_link(ep, 5); + assert(link); - rc = nvme_mi_admin_identify_secondary_ctrl_list(ctrl, 5, &list); + rc = nvme_mi_admin_identify_secondary_ctrl_list(link, 5, &list); assert(!rc); } @@ -1407,35 +1407,35 @@ static int test_admin_ns_mgmt_cb(struct nvme_mi_ep *ep, static void test_admin_ns_mgmt_create(struct nvme_mi_ep *ep) { struct nvme_ns_mgmt_host_sw_specified data = { 0 }; - nvme_mi_ctrl_t ctrl; + nvme_link_t link; __u32 ns; int rc; test_set_transport_callback(ep, test_admin_ns_mgmt_cb, NULL); - ctrl = nvme_mi_init_ctrl(ep, 5); - assert(ctrl); + link = nvme_mi_init_link(ep, 5); + assert(link); - rc = nvme_mi_admin_ns_mgmt_create(ctrl, NULL, 0, &ns, &data); + rc = nvme_mi_admin_ns_mgmt_create(link, NULL, 0, &ns, &data); assert(!rc); assert(ns == 0x01020304); data.nsze = cpu_to_le64(42); - rc = nvme_mi_admin_ns_mgmt_create(ctrl, NULL, 0, &ns, &data); + rc = nvme_mi_admin_ns_mgmt_create(link, NULL, 0, &ns, &data); assert(rc); } static void test_admin_ns_mgmt_delete(struct nvme_mi_ep *ep) { - nvme_mi_ctrl_t ctrl; + nvme_link_t link; int rc; test_set_transport_callback(ep, test_admin_ns_mgmt_cb, NULL); - ctrl = nvme_mi_init_ctrl(ep, 5); - assert(ctrl); + link = nvme_mi_init_link(ep, 5); + assert(link); - rc = nvme_mi_admin_ns_mgmt_delete(ctrl, 0x05060708); + rc = nvme_mi_admin_ns_mgmt_delete(link, 0x05060708); assert(!rc); } @@ -1487,7 +1487,7 @@ static void test_admin_ns_attach(struct nvme_mi_ep *ep) { struct nvme_ctrl_list list = { 0 }; struct attach_op aop; - nvme_mi_ctrl_t ctrl; + nvme_link_t link; int rc; list.num = cpu_to_le16(2); @@ -1499,10 +1499,10 @@ static void test_admin_ns_attach(struct nvme_mi_ep *ep) test_set_transport_callback(ep, test_admin_ns_attach_cb, &aop); - ctrl = nvme_mi_init_ctrl(ep, 5); - assert(ctrl); + link = nvme_mi_init_link(ep, 5); + assert(link); - rc = nvme_mi_admin_ns_attach_ctrls(ctrl, 0x02030405, &list); + rc = nvme_mi_admin_ns_attach_ctrls(link, 0x02030405, &list); assert(!rc); } @@ -1510,7 +1510,7 @@ static void test_admin_ns_detach(struct nvme_mi_ep *ep) { struct nvme_ctrl_list list = { 0 }; struct attach_op aop; - nvme_mi_ctrl_t ctrl; + nvme_link_t link; int rc; list.num = cpu_to_le16(2); @@ -1522,10 +1522,10 @@ static void test_admin_ns_detach(struct nvme_mi_ep *ep) test_set_transport_callback(ep, test_admin_ns_attach_cb, &aop); - ctrl = nvme_mi_init_ctrl(ep, 5); - assert(ctrl); + link = nvme_mi_init_link(ep, 5); + assert(link); - rc = nvme_mi_admin_ns_detach_ctrls(ctrl, 0x02030405, &list); + rc = nvme_mi_admin_ns_detach_ctrls(link, 0x02030405, &list); assert(!rc); } @@ -1568,7 +1568,7 @@ static void test_admin_fw_download(struct nvme_mi_ep *ep) struct nvme_fw_download_args args; struct fw_download_info info; unsigned char fw[4096]; - nvme_mi_ctrl_t ctrl; + nvme_link_t link; int rc, i; for (i = 0; i < sizeof(fw); i++) @@ -1582,43 +1582,43 @@ static void test_admin_fw_download(struct nvme_mi_ep *ep) test_set_transport_callback(ep, test_admin_fw_download_cb, &info); - ctrl = nvme_mi_init_ctrl(ep, 5); - assert(ctrl); + link = nvme_mi_init_link(ep, 5); + assert(link); /* invalid (zero) len */ args.data_len = info.len = 1; args.offset = info.offset = 0; - rc = nvme_mi_admin_fw_download(ctrl, &args); + rc = nvme_mi_admin_fw_download(link, &args); assert(rc); /* invalid (unaligned) len */ args.data_len = info.len = 1; args.offset = info.offset = 0; - rc = nvme_mi_admin_fw_download(ctrl, &args); + rc = nvme_mi_admin_fw_download(link, &args); assert(rc); /* invalid offset */ args.data_len = info.len = 4; args.offset = info.offset = 1; - rc = nvme_mi_admin_fw_download(ctrl, &args); + rc = nvme_mi_admin_fw_download(link, &args); assert(rc); /* smallest len */ args.data_len = info.len = 4; args.offset = info.offset = 0; - rc = nvme_mi_admin_fw_download(ctrl, &args); + rc = nvme_mi_admin_fw_download(link, &args); assert(!rc); /* largest len */ args.data_len = info.len = 4096; args.offset = info.offset = 0; - rc = nvme_mi_admin_fw_download(ctrl, &args); + rc = nvme_mi_admin_fw_download(link, &args); assert(!rc); /* offset value */ args.data_len = info.len = 4096; args.offset = info.offset = 4096; - rc = nvme_mi_admin_fw_download(ctrl, &args); + rc = nvme_mi_admin_fw_download(link, &args); assert(!rc); } @@ -1657,7 +1657,7 @@ static void test_admin_fw_commit(struct nvme_mi_ep *ep) { struct nvme_fw_commit_args args; struct fw_commit_info info; - nvme_mi_ctrl_t ctrl; + nvme_link_t link; int rc; args.args_size = sizeof(args); @@ -1665,28 +1665,28 @@ static void test_admin_fw_commit(struct nvme_mi_ep *ep) test_set_transport_callback(ep, test_admin_fw_commit_cb, &info); - ctrl = nvme_mi_init_ctrl(ep, 5); - assert(ctrl); + link = nvme_mi_init_link(ep, 5); + assert(link); /* all zeros */ info.bpid = args.bpid = 0; info.slot = args.slot = 0; info.action = args.action = 0; - rc = nvme_mi_admin_fw_commit(ctrl, &args); + rc = nvme_mi_admin_fw_commit(link, &args); assert(!rc); /* all ones */ info.bpid = args.bpid = 1; info.slot = args.slot = 0x7; info.action = args.action = 0x7; - rc = nvme_mi_admin_fw_commit(ctrl, &args); + rc = nvme_mi_admin_fw_commit(link, &args); assert(!rc); /* correct fields */ info.bpid = args.bpid = 1; info.slot = args.slot = 2; info.action = args.action = 3; - rc = nvme_mi_admin_fw_commit(ctrl, &args); + rc = nvme_mi_admin_fw_commit(link, &args); assert(!rc); } @@ -1737,11 +1737,11 @@ static int test_admin_format_nvm_cb(struct nvme_mi_ep *ep, static void test_admin_format_nvm(struct nvme_mi_ep *ep) { struct nvme_format_nvm_args args = { 0 }; - nvme_mi_ctrl_t ctrl; + nvme_link_t link; int rc; - ctrl = nvme_mi_init_ctrl(ep, 5); - assert(ctrl); + link = nvme_mi_init_link(ep, 5); + assert(link); test_set_transport_callback(ep, test_admin_format_nvm_cb, &args); @@ -1756,7 +1756,7 @@ static void test_admin_format_nvm(struct nvme_mi_ep *ep) args.mset = 0x1; args.lbaf = 0x0; - rc = nvme_mi_admin_format_nvm(ctrl, &args); + rc = nvme_mi_admin_format_nvm(link, &args); assert(!rc); args.nsid = ~args.nsid; @@ -1767,7 +1767,7 @@ static void test_admin_format_nvm(struct nvme_mi_ep *ep) args.mset = 0x0; args.lbaf = 0xf; - rc = nvme_mi_admin_format_nvm(ctrl, &args); + rc = nvme_mi_admin_format_nvm(link, &args); assert(!rc); } @@ -1805,11 +1805,11 @@ static int test_admin_sanitize_nvm_cb(struct nvme_mi_ep *ep, static void test_admin_sanitize_nvm(struct nvme_mi_ep *ep) { struct nvme_sanitize_nvm_args args = { 0 }; - nvme_mi_ctrl_t ctrl; + nvme_link_t link; int rc; - ctrl = nvme_mi_init_ctrl(ep, 5); - assert(ctrl); + link = nvme_mi_init_link(ep, 5); + assert(link); test_set_transport_callback(ep, test_admin_sanitize_nvm_cb, &args); @@ -1821,7 +1821,7 @@ static void test_admin_sanitize_nvm(struct nvme_mi_ep *ep) args.nodas = 0x1; args.ovrpat = ~0x04030201; - rc = nvme_mi_admin_sanitize_nvm(ctrl, &args); + rc = nvme_mi_admin_sanitize_nvm(link, &args); assert(!rc); args.sanact = 0x0; @@ -1831,7 +1831,7 @@ static void test_admin_sanitize_nvm(struct nvme_mi_ep *ep) args.nodas = 0x0; args.ovrpat = 0x04030201; - rc = nvme_mi_admin_sanitize_nvm(ctrl, &args); + rc = nvme_mi_admin_sanitize_nvm(link, &args); assert(!rc); } @@ -1901,13 +1901,13 @@ static void test_admin_get_log_split(struct nvme_mi_ep *ep) struct nvme_get_log_args args = { 0 }; unsigned char buf[4096 * 2 + 4]; struct log_data ldata; - nvme_mi_ctrl_t ctrl; + nvme_link_t link; int rc; ldata.n = 0; test_set_transport_callback(ep, test_admin_get_log_split_cb, &ldata); - ctrl = nvme_mi_init_ctrl(ep, 5); + link = nvme_mi_init_link(ep, 5); args.args_size = sizeof(args); args.lid = 1; @@ -1916,7 +1916,7 @@ static void test_admin_get_log_split(struct nvme_mi_ep *ep) args.lpo = 0; args.ot = false; - rc = nvme_mi_admin_get_log(ctrl, &args); + rc = nvme_mi_admin_get_log(link, &args); assert(!rc); @@ -2024,7 +2024,7 @@ static void test_admin_dlen_doff_req(struct nvme_mi_ep *ep) struct nvme_mi_admin_resp_hdr admin_resp = { 0 }; struct req_dlen_doff_data data = { 0 }; size_t resp_sz = 0; - nvme_mi_ctrl_t ctrl; + nvme_link_t link; int rc; data.direction = DATA_DIR_OUT; @@ -2032,10 +2032,10 @@ static void test_admin_dlen_doff_req(struct nvme_mi_ep *ep) test_set_transport_callback(ep, test_admin_dlen_doff_cb, &data); - ctrl = nvme_mi_init_ctrl(ep, 0); - assert(ctrl); + link = nvme_mi_init_link(ep, 0); + assert(link); - rc = nvme_mi_admin_xfer(ctrl, &admin_req.hdr, sizeof(admin_req.data), + rc = nvme_mi_admin_xfer(link, &admin_req.hdr, sizeof(admin_req.data), &admin_resp, 0, &resp_sz); assert(!rc); @@ -2051,7 +2051,7 @@ static void test_admin_dlen_doff_resp(struct nvme_mi_ep *ep) } admin_resp = { 0 }; struct nvme_mi_admin_req_hdr admin_req = { 0 }; struct req_dlen_doff_data data = { 0 }; - nvme_mi_ctrl_t ctrl; + nvme_link_t link; size_t resp_sz; int rc; @@ -2061,10 +2061,10 @@ static void test_admin_dlen_doff_resp(struct nvme_mi_ep *ep) test_set_transport_callback(ep, test_admin_dlen_doff_cb, &data); - ctrl = nvme_mi_init_ctrl(ep, 0); - assert(ctrl); + link = nvme_mi_init_link(ep, 0); + assert(link); - rc = nvme_mi_admin_xfer(ctrl, &admin_req, 0, &admin_resp.hdr, 0, + rc = nvme_mi_admin_xfer(link, &admin_req, 0, &admin_resp.hdr, 0, &resp_sz); assert(!rc); From f6eeac30316730abef85e717e92daf04a2edc790 Mon Sep 17 00:00:00 2001 From: Daniel Wagner Date: Tue, 8 Jul 2025 09:38:04 +0200 Subject: [PATCH 09/66] linux: add MI support to nvme_{open|close} Signed-off-by: Daniel Wagner --- src/nvme/linux.c | 116 ++++++++++++++++++++++++++++----------------- src/nvme/mi.c | 76 ++++++++++++++++++++++++----- src/nvme/mi.h | 7 --- src/nvme/private.h | 11 +++++ test/mi-mctp.c | 7 +-- test/mi.c | 5 +- 6 files changed, 154 insertions(+), 68 deletions(-) diff --git a/src/nvme/linux.c b/src/nvme/linux.c index 9fa0c7a81..382d43a4f 100644 --- a/src/nvme/linux.c +++ b/src/nvme/linux.c @@ -41,10 +41,19 @@ #include "base64.h" #include "crc32.h" -static int __nvme_open_dev(const char *name) +static int __nvme_link_open_direct(nvme_link_t l, const char *devname) { _cleanup_free_ char *path = NULL; - int ret; + char *name = basename(devname); + int ret, id, ns; + bool c; + + l->type = NVME_LINK_TYPE_DIRECT; + + ret = sscanf(name, "nvme%dn%d", &id, &ns); + if (ret != 1 && ret != 2) + return -EINVAL; + c = ret == 1; ret = asprintf(&path, "%s/%s", "/dev", name); if (ret < 0) { @@ -52,16 +61,35 @@ static int __nvme_open_dev(const char *name) return -1; } - return open(path, O_RDONLY); + l->fd = open(path, O_RDONLY); + if (l->fd < 0) + return -errno; + + ret = fstat(l->fd, &l->stat); + if (ret < 0) + return -errno; + + if (c) { + if (!S_ISCHR(l->stat.st_mode)) + return -EINVAL; + } else if (!S_ISBLK(l->stat.st_mode)) { + return -EINVAL; + } + + return 0; } -nvme_link_t nvme_open(nvme_root_t r, const char *name) +void __nvme_link_close_direct(nvme_link_t l) +{ + close(l->fd); + free(l); +} + +nvme_link_t __nvme_create_link(nvme_root_t r) { nvme_link_t l; - int ret, id, ns; - bool c; - l = malloc(sizeof(*l)); + l = calloc(1, sizeof(*l)); if (!l) { errno = ENOMEM; return NULL; @@ -69,51 +97,43 @@ nvme_link_t nvme_open(nvme_root_t r, const char *name) l->root = r; - if (!strcmp(name, "NVME_TEST_FD")) { - l->fd = 0xFD; - return l; - } + return l; +} - ret = sscanf(name, "nvme%dn%d", &id, &ns); - if (ret != 1 && ret != 2) { - errno = EINVAL; - goto free_link; - } - c = ret == 1; +nvme_link_t nvme_open(nvme_root_t r, const char *name) +{ + nvme_link_t l; + int ret; + + l = __nvme_create_link(r); + if (!l) + NULL; l->name = strdup(name); if (!l->name) { - errno = ENOMEM; - goto free_link; + free(l); + errno = -ENOMEM; + return NULL; } - l->fd = __nvme_open_dev(l->name); - if (l->fd < 0) - goto free_name; + if (!strcmp(name, "NVME_TEST_FD")) { + l->type = NVME_LINK_TYPE_DIRECT; + l->fd = 0xFD; + return l; + } - ret = fstat(l->fd, &l->stat); - if (ret < 0) - goto close_fd; + if (!strncmp(name, "mctp:", strlen("mctp:"))) + ret = __nvme_link_open_mi(l, name); + else + ret = __nvme_link_open_direct(l, name); - if (c) { - if (!S_ISCHR(l->stat.st_mode)) { - errno = EINVAL; - goto close_fd; - } - } else if (!S_ISBLK(l->stat.st_mode)) { - errno = EINVAL; - goto close_fd; + if (ret) { + nvme_close(l); + errno = -ret; + return NULL; } return l; - -close_fd: - close(l->fd); -free_name: - free(l->name); -free_link: - free(l); - return NULL; } void nvme_close(nvme_link_t l) @@ -121,10 +141,18 @@ void nvme_close(nvme_link_t l) if (!l) return; - close(l->fd); free(l->name); - free(l->log); - free(l); + + switch (l->type) { + case NVME_LINK_TYPE_DIRECT: + __nvme_link_close_direct(l); + break; + case NVME_LINK_TYPE_MI: + __nvme_link_close_mi(l); + break; + case NVME_LINK_TYPE_UNKNOWN: + free(l); + } } int nvme_link_get_fd(nvme_link_t l) diff --git a/src/nvme/mi.c b/src/nvme/mi.c index db77efe13..65ea5ba3f 100644 --- a/src/nvme/mi.c +++ b/src/nvme/mi.c @@ -19,6 +19,7 @@ #include "log.h" #include "mi.h" +#include "linux.h" #include "private.h" #define NUM_ENABLES (256u) @@ -56,6 +57,61 @@ static bool nvme_mi_probe_enabled_default(void) } +static int parse_devname(const char *dev, unsigned int *net, uint8_t *eid, + unsigned int *ctrl) +{ + int rc; + + /* ,: form */ + rc = sscanf(dev, "mctp:%u,%hhu:%u", net, eid, ctrl); + if (rc == 3) + return 0; + + /* , form, implicit ctrl-id = 0 */ + *ctrl = 0; + rc = sscanf(dev, "mctp:%u,%hhu", net, eid); + if (rc == 2) + return 0; + + return -EINVAL; +} + +int __nvme_link_init_mi(nvme_link_t l) +{ + if (l->type != NVME_LINK_TYPE_UNKNOWN) + return -EALREADY; + + l->type = NVME_LINK_TYPE_MI; + + return 0; +} + +int __nvme_link_open_mi(nvme_link_t l, const char *devname) +{ + unsigned int rc, net, ctrl_id; + unsigned char eid; + struct nvme_mi_ep *ep; + + rc = __nvme_link_init_mi(l); + if (rc) + return rc; + + rc = parse_devname(devname, &net, &eid, &ctrl_id); + return rc; + + ep = nvme_mi_open_mctp(l->root, net, eid); + if (!ep) + return -EINVAL; + + return 0; +} + +void __nvme_link_close_mi(nvme_link_t link) +{ + list_del(&link->ep_entry); + free(link); +} + /* MI-equivalent of nvme_create_root, but avoids clashing symbol names * when linking against both libnvme and libnvme-mi. */ @@ -238,7 +294,7 @@ void nvme_mi_ep_probe(struct nvme_mi_ep *ep) } out_close: - nvme_mi_close_link(link); + nvme_close(link); } static const int nsec_per_sec = 1000 * 1000 * 1000; @@ -341,9 +397,11 @@ struct nvme_link *nvme_mi_init_link(nvme_mi_ep_t ep, __u16 ctrl_id) { struct nvme_link *link; - link = malloc(sizeof(*link)); - if (!link) - return NULL; + link = __nvme_create_link(ep->root); + if (!link) + NULL; + + __nvme_link_init_mi(link); link->ep = ep; link->id = ctrl_id; @@ -368,7 +426,7 @@ int nvme_mi_scan_ep(nvme_mi_ep_t ep, bool force_rescan) if (force_rescan) { struct nvme_link *link, *tmp; nvme_mi_for_each_link_safe(ep, link, tmp) - nvme_mi_close_link(link); + nvme_close(link); } else { return 0; } @@ -2103,7 +2161,7 @@ void nvme_mi_close(nvme_mi_ep_t ep) ep->controllers_scanned = true; nvme_mi_for_each_link_safe(ep, link, tmp) - nvme_mi_close_link(link); + nvme_close(link); if (ep->transport && ep->transport->close) ep->transport->close(ep); @@ -2111,12 +2169,6 @@ void nvme_mi_close(nvme_mi_ep_t ep) free(ep); } -void nvme_mi_close_link(nvme_link_t link) -{ - list_del(&link->ep_entry); - free(link); -} - char *nvme_mi_endpoint_desc(nvme_mi_ep_t ep) { char tsbuf[101], *s = NULL; diff --git a/src/nvme/mi.h b/src/nvme/mi.h index 3c4148326..60afc326d 100644 --- a/src/nvme/mi.h +++ b/src/nvme/mi.h @@ -930,12 +930,6 @@ int nvme_mi_scan_ep(nvme_mi_ep_t ep, bool force_rescan); */ nvme_link_t nvme_mi_init_link(nvme_mi_ep_t ep, __u16 ctrl_id); -/** - * nvme_mi_close_link() - free a controller - * @link: link to controller to free - */ -void nvme_mi_close_link(nvme_link_t link); - /** * nvme_mi_ctrl_id() - get the ID of a controller * @link: link to controller to query @@ -949,7 +943,6 @@ void nvme_mi_close_link(nvme_link_t link); */ __u16 nvme_mi_ctrl_id(nvme_link_t link); - /** * nvme_mi_endpoint_desc - Get a string describing a MI endpoint. * @ep: endpoint to describe diff --git a/src/nvme/private.h b/src/nvme/private.h index a3cfa3d4e..6162aa9aa 100644 --- a/src/nvme/private.h +++ b/src/nvme/private.h @@ -31,8 +31,15 @@ struct nvme_log { bool timestamp; }; +enum nvme_link_type { + NVME_LINK_TYPE_UNKNOWN = 0, + NVME_LINK_TYPE_DIRECT, + NVME_LINK_TYPE_MI, +}; + struct nvme_link { struct nvme_root *root; + enum nvme_link_type type; char *name; /* direct */ @@ -216,6 +223,10 @@ int json_update_config(nvme_root_t r, const char *config_file); int json_dump_tree(nvme_root_t r); nvme_link_t __nvme_open(nvme_root_t r, const char *name); +nvme_link_t __nvme_create_link(nvme_root_t root); +int __nvme_link_open_mi(nvme_link_t l, const char *devname); +int __nvme_link_init_mi(nvme_link_t l); +void __nvme_link_close_mi(nvme_link_t link); nvme_ctrl_t __nvme_lookup_ctrl(nvme_subsystem_t s, const char *transport, const char *traddr, const char *host_traddr, diff --git a/test/mi-mctp.c b/test/mi-mctp.c index 271502a01..d459b2fb9 100644 --- a/test/mi-mctp.c +++ b/test/mi-mctp.c @@ -19,6 +19,7 @@ #include #include "libnvme-mi.h" +#include "nvme/linux.h" #include "nvme/private.h" #include "utils.h" @@ -446,7 +447,7 @@ static void test_admin_resp_sizes(nvme_mi_ep_t ep, struct test_peer *peer) assert(nvme_status_get_value(rc) == NVME_MI_RESP_INTERNAL_ERR); } - nvme_mi_close_link(link); + nvme_close(link); } /* test: timeout value passed to poll */ @@ -567,7 +568,7 @@ static void test_mpr_admin(nvme_mi_ep_t ep, struct test_peer *peer) rc = nvme_mi_admin_identify_ctrl(link, &id); assert(rc == 0); - nvme_mi_close_link(link); + nvme_close(link); } /* We have seen drives that send a MPR response as a full Admin message, @@ -592,7 +593,7 @@ static void test_mpr_admin_quirked(nvme_mi_ep_t ep, struct test_peer *peer) rc = nvme_mi_admin_identify_ctrl(link, &id); assert(rc == 0); - nvme_mi_close_link(link); + nvme_close(link); } /* helpers for the MPR + poll tests */ diff --git a/test/mi.c b/test/mi.c index 5fd96a1dd..8bdcb9e8d 100644 --- a/test/mi.c +++ b/test/mi.c @@ -14,6 +14,7 @@ #include /* we define a custom transport, so need the internal headers */ +#include "nvme/linux.h" #include "nvme/private.h" #include "libnvme-mi.h" @@ -196,11 +197,11 @@ static void test_ctrl_lifetime(nvme_mi_ep_t ep) count = count_ep_controllers(ep); assert(count == 2); - nvme_mi_close_link(l1); + nvme_close(l1); count = count_ep_controllers(ep); assert(count == 1); - nvme_mi_close_link(l2); + nvme_close(l2); count = count_ep_controllers(ep); assert(count == 0); } From 034a6e94628a226eb5e04b3993b5a857072a685d Mon Sep 17 00:00:00 2001 From: Daniel Wagner Date: Wed, 9 Jul 2025 10:34:01 +0200 Subject: [PATCH 10/66] linux: add nvme_link_is_{direct|mi} Signed-off-by: Daniel Wagner --- src/libnvme.map | 2 ++ src/nvme/linux.c | 10 ++++++++++ src/nvme/linux.h | 16 ++++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/src/libnvme.map b/src/libnvme.map index 561da6a7d..afa5f3d0a 100644 --- a/src/libnvme.map +++ b/src/libnvme.map @@ -177,6 +177,8 @@ LIBNVME_2_0 { nvme_link_get_name; nvme_link_is_blkdev; nvme_link_is_chardev; + nvme_link_is_direct; + nvme_link_is_mi; nvme_lm_cdq; nvme_lm_get_features_ctrl_data_queue; nvme_lm_migration_recv; diff --git a/src/nvme/linux.c b/src/nvme/linux.c index 382d43a4f..4408e15f0 100644 --- a/src/nvme/linux.c +++ b/src/nvme/linux.c @@ -170,6 +170,16 @@ bool nvme_link_is_chardev(nvme_link_t l) return S_ISCHR(l->stat.st_mode); } +bool nvme_link_is_direct(nvme_link_t l) +{ + return l->type == NVME_LINK_TYPE_DIRECT; +} + +bool nvme_link_is_mi(nvme_link_t l) +{ + return l->type == NVME_LINK_TYPE_MI; +} + const char *nvme_link_get_name(nvme_link_t l) { return l->name; diff --git a/src/nvme/linux.h b/src/nvme/linux.h index 4e4736c16..47226f22a 100644 --- a/src/nvme/linux.h +++ b/src/nvme/linux.h @@ -227,6 +227,22 @@ bool nvme_link_is_blkdev(nvme_link_t l); */ bool nvme_link_is_chardev(nvme_link_t l); +/** + * nvme_link_is_direct - Check if link handle is using IOCTL interface + * @l: Link handle + * + * Return: Return true if link handle is using IOCTL itnerface, otherwise false. + */ +bool nvme_link_is_direct(nvme_link_t l); + +/** + * nvme_link_is_mi - Check if link handle is a using MI interface + * @l: Link handle + * + * Return: Return true if link handle is using MI interface, otherwise false. + */ +bool nvme_link_is_mi(nvme_link_t l); + /** * nvme_link_get_name - Return name of the device link handle * @l: Link handle From 2deb8a8f88284f4d1ee1075995eeca9e776c548b Mon Sep 17 00:00:00 2001 From: Daniel Wagner Date: Tue, 8 Jul 2025 09:46:07 +0200 Subject: [PATCH 11/66] ioctl: add support for MI passthru Signed-off-by: Daniel Wagner --- src/nvme/ioctl.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/nvme/ioctl.c b/src/nvme/ioctl.c index a333d6401..cf92d4a3e 100644 --- a/src/nvme/ioctl.c +++ b/src/nvme/ioctl.c @@ -187,7 +187,19 @@ int nvme_admin_passthru64(nvme_link_t l, __u8 opcode, __u8 flags, __u16 rsvd, int nvme_submit_admin_passthru(nvme_link_t l, struct nvme_passthru_cmd *cmd, __u32 *result) { - return nvme_submit_passthru(l, NVME_IOCTL_ADMIN_CMD, cmd, result); + switch (l->type) { + case NVME_LINK_TYPE_DIRECT: + return nvme_submit_passthru(l, NVME_IOCTL_ADMIN_CMD, cmd, result); + case NVME_LINK_TYPE_MI: + return nvme_mi_admin_admin_passthru( + l, cmd->opcode, cmd->flags, cmd->rsvd1, + cmd->nsid, cmd->cdw2, cmd->cdw3, cmd->cdw10, cmd->cdw11, cmd->cdw12, cmd->cdw13, + cmd->cdw14, cmd->cdw15, cmd->data_len, (void*)cmd->addr, cmd->metadata_len, + (void*)cmd->metadata, cmd->timeout_ms, result); + default: + errno = ENOTSUP; + return -1; + } } int nvme_admin_passthru(nvme_link_t l, __u8 opcode, __u8 flags, __u16 rsvd, From f8ec3dc739343e3b32dbfaeafa10043c9bc75743 Mon Sep 17 00:00:00 2001 From: Daniel Wagner Date: Wed, 11 Jun 2025 09:16:02 +0200 Subject: [PATCH 12/66] ioctl: add aligment and lenght check to nvme_fw_download The MI code has the aligment and lenght check which the the direkt APIs are missing. Without these checks the download tests for MI will fail after using the generic APIs. Signed-off-by: Daniel Wagner --- src/nvme/ioctl.c | 11 +++++++++++ test/ioctl/misc.c | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/nvme/ioctl.c b/src/nvme/ioctl.c index cf92d4a3e..40a2e575f 100644 --- a/src/nvme/ioctl.c +++ b/src/nvme/ioctl.c @@ -1511,6 +1511,17 @@ int nvme_fw_download(nvme_link_t l, struct nvme_fw_download_args *args) errno = EINVAL; return -1; } + + if ((args->data_len & 0x3) || (!args->data_len)) { + errno = EINVAL; + return -1; + } + + if (args->offset & 0x3) { + errno = EINVAL; + return -1; + } + return nvme_submit_admin_passthru(l, &cmd, args->result); } diff --git a/test/ioctl/misc.c b/test/ioctl/misc.c index dfb0846e2..f3621d093 100644 --- a/test/ioctl/misc.c +++ b/test/ioctl/misc.c @@ -264,7 +264,7 @@ static void test_fw_download(void) .result = &result, .data = &expected_data, .args_size = sizeof(args), - .offset = 123, + .offset = 120, .data_len = sizeof(expected_data), }; From 3b460ae2aa19b5d4fe58f5c19c4d0e8475412979 Mon Sep 17 00:00:00 2001 From: Daniel Wagner Date: Wed, 28 May 2025 18:10:25 +0200 Subject: [PATCH 13/66] mi: replace dedicated MI API with generic one With the introduction of the link handle, it's possible to use the generic nvme API. The transport selection happens on lower levels depending on the link object type. Note, the tests rely on using the ioctl interface and not the io_uring. Signed-off-by: Daniel Wagner --- examples/mi-mctp-csi-test.c | 2 +- examples/mi-mctp.c | 4 +- src/libnvme.map | 16 - src/nvme/mi.c | 708 ------------- src/nvme/mi.h | 1955 ----------------------------------- test/mi-mctp.c | 8 +- test/mi.c | 65 +- 7 files changed, 40 insertions(+), 2718 deletions(-) diff --git a/examples/mi-mctp-csi-test.c b/examples/mi-mctp-csi-test.c index 980c6a6e0..b71d463ec 100644 --- a/examples/mi-mctp-csi-test.c +++ b/examples/mi-mctp-csi-test.c @@ -92,7 +92,7 @@ int do_get_log_page(nvme_mi_ep_t ep, int argc, char **argv) return -1; } - rc = nvme_mi_admin_get_log(link, &args); + rc = nvme_get_log(link, &args); if (rc) { warn("can't perform Get Log page command"); return -1; diff --git a/examples/mi-mctp.c b/examples/mi-mctp.c index b4c21eeae..75b156879 100644 --- a/examples/mi-mctp.c +++ b/examples/mi-mctp.c @@ -409,7 +409,7 @@ int do_get_log_page(nvme_mi_ep_t ep, int argc, char **argv) return -1; } - rc = nvme_mi_admin_get_log(link, &args); + rc = nvme_get_log(link, &args); if (rc) { warn("can't perform Get Log page command"); return -1; @@ -577,7 +577,7 @@ int do_security_info(nvme_mi_ep_t ep, int argc, char **argv) args.data = &proto_info; args.data_len = sizeof(proto_info); - rc = nvme_mi_admin_security_recv(link, &args); + rc = nvme_security_receive(link, &args); if (rc) { warnx("can't perform Security Receive command: rc %d", rc); return -1; diff --git a/src/libnvme.map b/src/libnvme.map index afa5f3d0a..f2f8d010b 100644 --- a/src/libnvme.map +++ b/src/libnvme.map @@ -192,23 +192,7 @@ LIBNVME_2_0 { nvme_lookup_keyring; nvme_lookup_subsystem; nvme_mi_admin_admin_passthru; - nvme_mi_admin_format_nvm; - nvme_mi_admin_fw_commit; - nvme_mi_admin_fw_download; - nvme_mi_admin_get_ana_log_atomic; - nvme_mi_admin_get_features; - nvme_mi_admin_get_features_arbitration; - nvme_mi_admin_get_features_power_mgmt; - nvme_mi_admin_get_log; - nvme_mi_admin_get_log_page; nvme_mi_admin_identify_partial; - nvme_mi_admin_ns_attach; - nvme_mi_admin_ns_mgmt; - nvme_mi_admin_sanitize_nvm; - nvme_mi_admin_security_recv; - nvme_mi_admin_security_send; - nvme_mi_admin_set_features; - nvme_mi_admin_set_features_power_mgmt; nvme_mi_admin_xfer; nvme_mi_aem_disable; nvme_mi_aem_enable; diff --git a/src/nvme/mi.c b/src/nvme/mi.c index 65ea5ba3f..eb1f61fe8 100644 --- a/src/nvme/mi.c +++ b/src/nvme/mi.c @@ -1075,714 +1075,6 @@ int nvme_mi_control(nvme_mi_ep_t ep, __u8 opcode, return 0; } -/* retrieves a MCTP-messsage-sized chunk of log page data. offset and len are - * specified within the args->data area. The `offset` parameter is a relative - * offset to the args->lpo ! - * - * What's more, we change the LPO of original command to chunk the request - * message into proper size which is allowed by MI interface. One reason is that - * this option seems to be supported better by devices. For more information - * about this option, please check https://github.com/linux-nvme/libnvme/pull/539 - * */ -static int __nvme_mi_admin_get_log(nvme_link_t link, - const struct nvme_get_log_args *args, - off_t offset, size_t *lenp, bool final) -{ - __u64 log_page_offset = args->lpo + offset; - struct nvme_mi_admin_resp_hdr resp_hdr; - struct nvme_mi_admin_req_hdr req_hdr; - struct nvme_mi_resp resp; - struct nvme_mi_req req; - size_t len; - __u32 ndw; - int rc; - - /* MI spec requires that the data length field is less than or equal - * to 4096 */ - len = *lenp; - if (!len || len > 4096 || len < 4) { - errno = EINVAL; - return -1; - } - - if (offset < 0 || offset >= args->len || offset + len > args->len) { - errno = EINVAL; - return -1; - } - - ndw = (len >> 2) - 1; - - nvme_mi_admin_init_req(link->ep, &req, &req_hdr, link->id, - nvme_admin_get_log_page); - req_hdr.cdw1 = cpu_to_le32(args->nsid); - req_hdr.cdw10 = cpu_to_le32((ndw & 0xffff) << 16 | - ((!final || args->rae) ? 1 : 0) << 15 | - args->lsp << 8 | - (args->lid & 0xff)); - req_hdr.cdw11 = cpu_to_le32(args->lsi << 16 | - ndw >> 16); - req_hdr.cdw12 = cpu_to_le32(log_page_offset & 0xffffffff); - req_hdr.cdw13 = cpu_to_le32(log_page_offset >> 32); - req_hdr.cdw14 = cpu_to_le32(args->csi << 24 | - (args->ot ? 1 : 0) << 23 | - args->uuidx); - req_hdr.flags = 0x1; - req_hdr.dlen = cpu_to_le32(len & 0xffffffff); - - nvme_mi_admin_init_resp(&resp, &resp_hdr); - resp.data = args->log + offset; - resp.data_len = len; - - rc = nvme_mi_submit(link->ep, &req, &resp); - if (rc) - return rc; - - rc = nvme_mi_admin_parse_status(&resp, args->result); - if (!rc) - *lenp = resp.data_len; - - return rc; -} - -int nvme_mi_admin_get_log_page(nvme_link_t link, __u32 xfer_size, - struct nvme_get_log_args *args) -{ - const size_t max_xfer_size = xfer_size; - off_t xfer_offset; - int rc = 0; - - if (args->args_size < sizeof(*args)) { - errno = EINVAL; - return -1; - } - - if (args->ot && (args->len > max_xfer_size)) { - errno = EINVAL; - return -1; - } - - for (xfer_offset = 0; xfer_offset < args->len;) { - size_t xfered_size, cur_xfer_size = max_xfer_size; - bool final; - - if (xfer_offset + cur_xfer_size > args->len) - cur_xfer_size = args->len - xfer_offset; - - xfered_size = cur_xfer_size; - - final = xfer_offset + cur_xfer_size >= args->len; - - /* xfered_size is used as both input and output parameter */ - rc = __nvme_mi_admin_get_log(link, args, xfer_offset, - &xfered_size, final); - if (rc) - break; - - xfer_offset += xfered_size; - /* if we returned less data than expected, consider that - * the end of the log page */ - if (xfered_size != cur_xfer_size) - break; - } - - if (!rc) - args->len = xfer_offset; - - return rc; -} - -int nvme_mi_admin_get_log(nvme_link_t link, struct nvme_get_log_args *args) -{ - return nvme_mi_admin_get_log_page(link, 4096, args); -} - -static int read_ana_chunk(nvme_link_t link, enum nvme_log_ana_lsp lsp, bool rae, - __u8 *log, __u8 **read, __u8 *to_read, __u8 *log_end) -{ - if (to_read > log_end) { - errno = ENOSPC; - return -1; - } - - while (*read < to_read) { - __u32 len = min_t(__u32, log_end - *read, NVME_LOG_PAGE_PDU_SIZE); - int ret; - - ret = nvme_mi_admin_get_log_ana(link, lsp, rae, - *read - log, len, *read); - if (ret) - return ret; - - *read += len; - } - return 0; -} - -static int try_read_ana(nvme_link_t link, enum nvme_log_ana_lsp lsp, bool rae, - struct nvme_ana_log *log, __u8 *log_end, - __u8 *read, __u8 **to_read, bool *may_retry) -{ - __u16 ngrps = le16_to_cpu(log->ngrps); - - while (ngrps--) { - __u8 *group = *to_read; - int ret; - __le32 nnsids; - - *to_read += sizeof(*log->descs); - ret = read_ana_chunk(link, lsp, rae, - (__u8 *)log, &read, *to_read, log_end); - if (ret) { - /* - * If the provided buffer isn't long enough, - * the log page may have changed while reading it - * and the computed length was inaccurate. - * Have the caller check chgcnt and retry. - */ - *may_retry = errno == ENOSPC; - return ret; - } - - /* - * struct nvme_ana_group_desc has 8-byte alignment - * but the group pointer is only 4-byte aligned. - * Don't dereference the misaligned pointer. - */ - memcpy(&nnsids, - group + offsetof(struct nvme_ana_group_desc, nnsids), - sizeof(nnsids)); - *to_read += le32_to_cpu(nnsids) * sizeof(__le32); - ret = read_ana_chunk(link, lsp, rae, - (__u8 *)log, &read, *to_read, log_end); - if (ret) { - *may_retry = errno == ENOSPC; - return ret; - } - } - - *may_retry = true; - return 0; -} - -int nvme_mi_admin_get_ana_log_atomic(nvme_link_t link, bool rgo, bool rae, - unsigned int retries, - struct nvme_ana_log *log, __u32 *len) -{ - const enum nvme_log_ana_lsp lsp = - rgo ? NVME_LOG_ANA_LSP_RGO_GROUPS_ONLY : 0; - /* Get Log Page can only fetch multiples of dwords */ - __u8 * const log_end = (__u8 *)log + (*len & -4); - __u8 *read = (__u8 *)log; - __u8 *to_read; - int ret; - - if (!retries) { - errno = EINVAL; - return -1; - } - - to_read = (__u8 *)log->descs; - ret = read_ana_chunk(link, lsp, rae, - (__u8 *)log, &read, to_read, log_end); - if (ret) - return ret; - - do { - bool may_retry = false; - int saved_ret; - int saved_errno; - __le64 chgcnt; - - saved_ret = try_read_ana(link, lsp, rae, log, log_end, - read, &to_read, &may_retry); - /* - * If the log page was read with multiple Get Log Page commands, - * chgcnt must be checked afterwards to ensure atomicity - */ - *len = to_read - (__u8 *)log; - if (*len <= NVME_LOG_PAGE_PDU_SIZE || !may_retry) - return saved_ret; - - saved_errno = errno; - chgcnt = log->chgcnt; - read = (__u8 *)log; - to_read = (__u8 *)log->descs; - ret = read_ana_chunk(link, lsp, rae, - (__u8 *)log, &read, to_read, log_end); - if (ret) - return ret; - - if (log->chgcnt == chgcnt) { - /* Log hasn't changed; return try_read_ana() result */ - errno = saved_errno; - return saved_ret; - } - } while (--retries); - - errno = EAGAIN; - return -1; -} - -int nvme_mi_admin_security_send(nvme_link_t link, - struct nvme_security_send_args *args) -{ - - struct nvme_mi_admin_resp_hdr resp_hdr; - struct nvme_mi_admin_req_hdr req_hdr; - struct nvme_mi_resp resp; - struct nvme_mi_req req; - int rc; - - if (args->args_size < sizeof(*args)) { - errno = EINVAL; - return -1; - } - - if (args->data_len > 4096) { - errno = EINVAL; - return -1; - } - - nvme_mi_admin_init_req(link->ep, &req, &req_hdr, link->id, - nvme_admin_security_send); - - req_hdr.cdw10 = cpu_to_le32(args->secp << 24 | - args->spsp1 << 16 | - args->spsp0 << 8 | - args->nssf); - - req_hdr.cdw11 = cpu_to_le32(args->data_len & 0xffffffff); - - req_hdr.flags = 0x1; - req_hdr.dlen = cpu_to_le32(args->data_len & 0xffffffff); - req.data = args->data; - req.data_len = args->data_len; - - nvme_mi_admin_init_resp(&resp, &resp_hdr); - - rc = nvme_mi_submit(link->ep, &req, &resp); - if (rc) - return rc; - - return nvme_mi_admin_parse_status(&resp, args->result); -} - -int nvme_mi_admin_security_recv(nvme_link_t link, - struct nvme_security_receive_args *args) -{ - - struct nvme_mi_admin_resp_hdr resp_hdr; - struct nvme_mi_admin_req_hdr req_hdr; - struct nvme_mi_resp resp; - struct nvme_mi_req req; - int rc; - - if (args->args_size < sizeof(*args)) { - errno = EINVAL; - return -1; - } - - if (args->data_len > 4096) { - errno = EINVAL; - return -1; - } - - nvme_mi_admin_init_req(link->ep, &req, &req_hdr, link->id, - nvme_admin_security_recv); - - req_hdr.cdw10 = cpu_to_le32(args->secp << 24 | - args->spsp1 << 16 | - args->spsp0 << 8 | - args->nssf); - - req_hdr.cdw11 = cpu_to_le32(args->data_len & 0xffffffff); - - req_hdr.flags = 0x1; - req_hdr.dlen = cpu_to_le32(args->data_len & 0xffffffff); - - nvme_mi_admin_init_resp(&resp, &resp_hdr); - resp.data = args->data; - resp.data_len = args->data_len; - - rc = nvme_mi_submit(link->ep, &req, &resp); - if (rc) - return rc; - - rc = nvme_mi_admin_parse_status(&resp, args->result); - if (rc) - return rc; - - args->data_len = resp.data_len; - - return 0; -} - -int nvme_mi_admin_get_features(nvme_link_t link, - struct nvme_get_features_args *args) -{ - struct nvme_mi_admin_resp_hdr resp_hdr; - struct nvme_mi_admin_req_hdr req_hdr; - struct nvme_mi_resp resp; - struct nvme_mi_req req; - int rc; - - if (args->args_size < sizeof(*args)) { - errno = EINVAL; - return -1; - } - - nvme_mi_admin_init_req(link->ep, &req, &req_hdr, link->id, - nvme_admin_get_features); - - req_hdr.cdw1 = cpu_to_le32(args->nsid); - req_hdr.cdw10 = cpu_to_le32((args->sel & 0x7) << 8 | args->fid); - req_hdr.cdw14 = cpu_to_le32(args->uuidx & 0x7f); - req_hdr.cdw11 = cpu_to_le32(args->cdw11); - - nvme_mi_admin_init_resp(&resp, &resp_hdr); - resp.data = args->data; - resp.data_len = args->data_len; - - rc = nvme_mi_submit(link->ep, &req, &resp); - if (rc) - return rc; - - rc = nvme_mi_admin_parse_status(&resp, args->result); - if (rc) - return rc; - - args->data_len = resp.data_len; - - return 0; -} - -static int __nvme_mi_admin_get_features(nvme_link_t link, enum nvme_features_id fid, - enum nvme_get_features_sel sel, __u32 *result) -{ - struct nvme_get_features_args args = { - .args_size = sizeof(args), - .fid = fid, - .nsid = NVME_NSID_NONE, - .sel = sel, - .cdw11 = 0, - .uuidx = NVME_UUID_NONE, - .data_len = 0, - .data = NULL, - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .result = result, - }; - - return nvme_mi_admin_get_features(link, &args); -} - -int nvme_mi_admin_get_features_arbitration(nvme_link_t link, enum nvme_get_features_sel sel, - __u32 *result) -{ - return __nvme_mi_admin_get_features(link, NVME_FEAT_FID_ARBITRATION, sel, result); -} - -int nvme_mi_admin_get_features_power_mgmt(nvme_link_t link, enum nvme_get_features_sel sel, - __u32 *result) -{ - return __nvme_mi_admin_get_features(link, NVME_FEAT_FID_POWER_MGMT, sel, result); -} - -int nvme_mi_admin_set_features(nvme_link_t link, - struct nvme_set_features_args *args) -{ - struct nvme_mi_admin_resp_hdr resp_hdr; - struct nvme_mi_admin_req_hdr req_hdr; - struct nvme_mi_resp resp; - struct nvme_mi_req req; - int rc; - - if (args->args_size < sizeof(*args)) { - errno = EINVAL; - return -1; - } - - nvme_mi_admin_init_req(link->ep, &req, &req_hdr, link->id, - nvme_admin_set_features); - - req_hdr.cdw1 = cpu_to_le32(args->nsid); - req_hdr.cdw10 = cpu_to_le32((__u32)!!args->save << 31 | - (args->fid & 0xff)); - req_hdr.cdw14 = cpu_to_le32(args->uuidx & 0x7f); - req_hdr.cdw11 = cpu_to_le32(args->cdw11); - req_hdr.cdw12 = cpu_to_le32(args->cdw12); - req_hdr.cdw13 = cpu_to_le32(args->cdw13); - req_hdr.cdw15 = cpu_to_le32(args->cdw15); - - req.data_len = args->data_len; - req.data = args->data; - - nvme_mi_admin_init_resp(&resp, &resp_hdr); - - rc = nvme_mi_submit(link->ep, &req, &resp); - if (rc) - return rc; - - rc = nvme_mi_admin_parse_status(&resp, args->result); - if (rc) - return rc; - - args->data_len = resp.data_len; - - return 0; -} - -static int __nvme_mi_admin_set_features(nvme_link_t link, __u8 fid, __u32 cdw11, bool save, - __u32 *result) -{ - struct nvme_set_features_args args = { - .args_size = sizeof(args), - .nsid = NVME_NSID_NONE, - .cdw11 = cdw11, - .cdw12 = 0, - .save = save, - .uuidx = NVME_UUID_NONE, - .cdw15 = 0, - .data_len = 0, - .data = NULL, - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .result = result, - }; - return nvme_mi_admin_set_features(link, &args); -} - -int nvme_mi_admin_set_features_power_mgmt(nvme_link_t link, __u8 ps, __u8 wh, bool save, - __u32 *result) -{ - __u32 value = NVME_SET(ps, FEAT_PWRMGMT_PS) | NVME_SET(wh, FEAT_PWRMGMT_WH); - - return __nvme_mi_admin_set_features(link, NVME_FEAT_FID_POWER_MGMT, value, save, result); -} - -int nvme_mi_admin_ns_mgmt(nvme_link_t link, - struct nvme_ns_mgmt_args *args) -{ - const size_t size_v1 = sizeof_args(struct nvme_ns_mgmt_args, csi, __u64); - const size_t size_v2 = sizeof_args(struct nvme_ns_mgmt_args, data, __u64); - struct nvme_mi_admin_resp_hdr resp_hdr; - struct nvme_mi_admin_req_hdr req_hdr; - struct nvme_mi_resp resp; - struct nvme_mi_req req; - int rc; - size_t data_len; - - if (args->args_size < size_v1 || args->args_size > size_v2) { - errno = EINVAL; - return -1; - } - - nvme_mi_admin_init_req(link->ep, &req, &req_hdr, link->id, - nvme_admin_ns_mgmt); - - req_hdr.cdw1 = cpu_to_le32(args->nsid); - req_hdr.cdw10 = cpu_to_le32(args->sel & 0xf); - req_hdr.cdw11 = cpu_to_le32(args->csi << 24); - - if (args->args_size == size_v2) { - if (args->data) { - req.data = args->data; - data_len = sizeof(*args->data); - } - } - else { - if (args->ns) { - req.data = args->ns; - data_len = sizeof(*args->ns); - } - } - - if (req.data) { - req.data_len = data_len; - req_hdr.dlen = cpu_to_le32(data_len); - req_hdr.flags = 0x1; - } - - nvme_mi_admin_init_resp(&resp, &resp_hdr); - - rc = nvme_mi_submit(link->ep, &req, &resp); - if (rc) - return rc; - - return nvme_mi_admin_parse_status(&resp, args->result); -} - -int nvme_mi_admin_ns_attach(nvme_link_t link, - struct nvme_ns_attach_args *args) -{ - struct nvme_mi_admin_resp_hdr resp_hdr; - struct nvme_mi_admin_req_hdr req_hdr; - struct nvme_mi_resp resp; - struct nvme_mi_req req; - int rc; - - if (args->args_size < sizeof(*args)) { - errno = EINVAL; - return -1; - } - - nvme_mi_admin_init_req(link->ep, &req, &req_hdr, link->id, - nvme_admin_ns_attach); - - req_hdr.cdw1 = cpu_to_le32(args->nsid); - req_hdr.cdw10 = cpu_to_le32(args->sel & 0xf); - req.data = args->ctrlist; - req.data_len = sizeof(*args->ctrlist); - req_hdr.dlen = cpu_to_le32(sizeof(*args->ctrlist)); - req_hdr.flags = 0x1; - - nvme_mi_admin_init_resp(&resp, &resp_hdr); - - rc = nvme_mi_submit(link->ep, &req, &resp); - if (rc) - return rc; - - return nvme_mi_admin_parse_status(&resp, args->result); -} - -int nvme_mi_admin_fw_download(nvme_link_t link, - struct nvme_fw_download_args *args) -{ - struct nvme_mi_admin_resp_hdr resp_hdr; - struct nvme_mi_admin_req_hdr req_hdr; - struct nvme_mi_resp resp; - struct nvme_mi_req req; - int rc; - - if (args->args_size < sizeof(*args)) { - errno = EINVAL; - return -1; - } - - if ((args->data_len & 0x3) || (!args->data_len)) { - errno = EINVAL; - return -1; - } - - if (args->offset & 0x3) { - errno = EINVAL; - return -1; - } - - nvme_mi_admin_init_req(link->ep, &req, &req_hdr, link->id, - nvme_admin_fw_download); - - req_hdr.cdw10 = cpu_to_le32((args->data_len >> 2) - 1); - req_hdr.cdw11 = cpu_to_le32(args->offset >> 2); - req.data = args->data; - req.data_len = args->data_len; - req_hdr.dlen = cpu_to_le32(args->data_len); - req_hdr.flags = 0x1; - - nvme_mi_admin_init_resp(&resp, &resp_hdr); - - rc = nvme_mi_submit(link->ep, &req, &resp); - if (rc) - return rc; - - return nvme_mi_admin_parse_status(&resp, NULL); -} - -int nvme_mi_admin_fw_commit(nvme_link_t link, - struct nvme_fw_commit_args *args) -{ - struct nvme_mi_admin_resp_hdr resp_hdr; - struct nvme_mi_admin_req_hdr req_hdr; - struct nvme_mi_resp resp; - struct nvme_mi_req req; - int rc; - - if (args->args_size < sizeof(*args)) { - errno = EINVAL; - return -1; - } - - nvme_mi_admin_init_req(link->ep, &req, &req_hdr, link->id, - nvme_admin_fw_commit); - - req_hdr.cdw10 = cpu_to_le32(((__u32)(args->bpid & 0x1) << 31) | - ((args->action & 0x7) << 3) | - ((args->slot & 0x7) << 0)); - - nvme_mi_admin_init_resp(&resp, &resp_hdr); - - rc = nvme_mi_submit(link->ep, &req, &resp); - if (rc) - return rc; - - return nvme_mi_admin_parse_status(&resp, NULL); -} - -int nvme_mi_admin_format_nvm(nvme_link_t link, - struct nvme_format_nvm_args *args) -{ - struct nvme_mi_admin_resp_hdr resp_hdr; - struct nvme_mi_admin_req_hdr req_hdr; - struct nvme_mi_resp resp; - struct nvme_mi_req req; - int rc; - - if (args->args_size < sizeof(*args)) { - errno = EINVAL; - return -1; - } - - nvme_mi_admin_init_req(link->ep, &req, &req_hdr, link->id, - nvme_admin_format_nvm); - - req_hdr.cdw1 = cpu_to_le32(args->nsid); - req_hdr.cdw10 = cpu_to_le32(((args->lbafu & 0x3) << 12) - | ((args->ses & 0x7) << 9) - | ((args->pil & 0x1) << 8) - | ((args->pi & 0x7) << 5) - | ((args->mset & 0x1) << 4) - | ((args->lbaf & 0xf) << 0)); - - nvme_mi_admin_init_resp(&resp, &resp_hdr); - - rc = nvme_mi_submit(link->ep, &req, &resp); - if (rc) - return rc; - - return nvme_mi_admin_parse_status(&resp, args->result); -} - -int nvme_mi_admin_sanitize_nvm(nvme_link_t link, - struct nvme_sanitize_nvm_args *args) -{ - struct nvme_mi_admin_resp_hdr resp_hdr; - struct nvme_mi_admin_req_hdr req_hdr; - struct nvme_mi_resp resp; - struct nvme_mi_req req; - int rc; - - if (args->args_size < sizeof(*args)) { - errno = EINVAL; - return -1; - } - - nvme_mi_admin_init_req(link->ep, &req, &req_hdr, link->id, - nvme_admin_sanitize_nvm); - - req_hdr.cdw10 = cpu_to_le32(((args->nodas ? 1 : 0) << 9) - | ((args->oipbp ? 1 : 0) << 8) - | ((args->owpass & 0xf) << 4) - | ((args->ause ? 1 : 0) << 3) - | ((args->sanact & 0x7) << 0)); - req_hdr.cdw11 = cpu_to_le32(args->ovrpat); - - nvme_mi_admin_init_resp(&resp, &resp_hdr); - - rc = nvme_mi_submit(link->ep, &req, &resp); - if (rc) - return rc; - - return nvme_mi_admin_parse_status(&resp, args->result); -} - static void nvme_mi_mi_init_req(nvme_mi_ep_t ep, struct nvme_mi_req *req, struct nvme_mi_mi_req_hdr *hdr, diff --git a/src/nvme/mi.h b/src/nvme/mi.h index 60afc326d..ae92e053b 100644 --- a/src/nvme/mi.h +++ b/src/nvme/mi.h @@ -1472,1961 +1472,6 @@ static inline int nvme_mi_admin_identify(nvme_link_t link, int nvme_mi_control(nvme_mi_ep_t ep, __u8 opcode, __u16 cpsp, __u16 *result_cpsr); -/** - * nvme_mi_admin_identify_cns_nsid() - Perform an Admin identify command using - * specific CNS/NSID parameters. - * @link: Link to process identify command - * @cns: Controller or Namespace Structure, specifying identified object - * @nsid: namespace ID - * @data: buffer for identify data response - * - * Perform an Identify command, using the CNS specifier @cns, and the - * namespace ID @nsid if required by the CNS type. - * - * Stores the identify data in @data, which is expected to be a buffer of - * &NVME_IDENTIFY_DATA_SIZE bytes. - * - * Will return an error if the length of the response data (from the - * controller) is not a full &NVME_IDENTIFY_DATA_SIZE. - * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. - */ -static inline int nvme_mi_admin_identify_cns_nsid(nvme_link_t link, - enum nvme_identify_cns cns, - __u32 nsid, void *data) -{ - struct nvme_identify_args args = { - .result = NULL, - .data = data, - .args_size = sizeof(args), - .cns = cns, - .csi = NVME_CSI_NVM, - .nsid = nsid, - .cntid = NVME_CNTLID_NONE, - .cns_specific_id = NVME_CNSSPECID_NONE, - .uuidx = NVME_UUID_NONE, - }; - - return nvme_mi_admin_identify(link, &args); -} - -/** - * nvme_mi_admin_identify_ns() - Perform an Admin identify command for a - * namespace - * @link: Link to process identify command - * @nsid: namespace ID - * @ns: Namespace identification to populate - * - * Perform an Identify (namespace) command, setting the namespace id data - * in @ns. The namespace is expected to active and allocated. - * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. - */ -static inline int nvme_mi_admin_identify_ns(nvme_link_t link, __u32 nsid, - struct nvme_id_ns *ns) -{ - return nvme_mi_admin_identify_cns_nsid(link, NVME_IDENTIFY_CNS_NS, - nsid, ns); -} - -/** - * nvme_mi_admin_identify_ns_descs() - Perform an Admin identify Namespace - * Identification Descriptor list command for a namespace - * @link: Link to process identify command - * @nsid: Namespace ID - * @descs: Namespace Identification Descriptor list to populate - * - * Perform an Identify namespace identification description list command, - * setting the namespace identification description list in @descs - * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. - */ -static inline int nvme_mi_admin_identify_ns_descs(nvme_link_t link, - __u32 nsid, - struct nvme_ns_id_desc *descs) -{ - return nvme_mi_admin_identify_cns_nsid(link, NVME_IDENTIFY_CNS_NS_DESC_LIST, - nsid, descs); -} - -/** - * nvme_mi_admin_identify_allocated_ns() - Perform an Admin identify command - * for an allocated namespace - * @link: Link to process identify command - * @nsid: namespace ID - * @ns: Namespace identification to populate - * - * Perform an Identify (namespace) command, setting the namespace id data - * in @ns. - * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. - */ -static inline int nvme_mi_admin_identify_allocated_ns(nvme_link_t link, - __u32 nsid, - struct nvme_id_ns *ns) -{ - return nvme_mi_admin_identify_cns_nsid(link, - NVME_IDENTIFY_CNS_ALLOCATED_NS, - nsid, ns); -} - -/** - * nvme_mi_admin_identify_ctrl() - Perform an Admin identify for a controller - * @link: Link to process identify command - * @id: Controller identify data to populate - * - * Perform an Identify command, for the controller specified by @ctrl, - * writing identify data to @id. - * - * Will return an error if the length of the response data (from the - * controller) is not a full &NVME_IDENTIFY_DATA_SIZE, so @id will be - * fully populated on success. - * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. - * - * See: &struct nvme_id_ctrl - */ -static inline int nvme_mi_admin_identify_ctrl(nvme_link_t link, - struct nvme_id_ctrl *id) -{ - return nvme_mi_admin_identify_cns_nsid(link, NVME_IDENTIFY_CNS_CTRL, - NVME_NSID_NONE, id); -} - -/** - * nvme_mi_admin_identify_ctrl_list() - Perform an Admin identify for a - * controller list. - * @link: Link to process identify command - * @cntid: Controller ID to specify list start - * @list: List data to populate - * - * Perform an Identify command, for the controller list starting with - * IDs greater than or equal to @cntid. - * - * Will return an error if the length of the response data (from the - * controller) is not a full &NVME_IDENTIFY_DATA_SIZE, so @id will be - * fully populated on success. - * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. - * - * See: &struct nvme_ctrl_list - */ -static inline int nvme_mi_admin_identify_ctrl_list(nvme_link_t link, - __u16 cntid, - struct nvme_ctrl_list *list) -{ - struct nvme_identify_args args = { - .result = NULL, - .data = list, - .args_size = sizeof(args), - .cns = NVME_IDENTIFY_CNS_CTRL_LIST, - .csi = NVME_CSI_NVM, - .nsid = NVME_NSID_NONE, - .cntid = cntid, - .cns_specific_id = NVME_CNSSPECID_NONE, - .uuidx = NVME_UUID_NONE, - }; - - return nvme_mi_admin_identify(link, &args); -} - -/** - * nvme_mi_admin_identify_nsid_ctrl_list() - Perform an Admin identify for a - * controller list with specific namespace ID - * @link: Link to process identify command - * @nsid: Namespace identifier - * @cntid: Controller ID to specify list start - * @list: List data to populate - * - * Perform an Identify command, for the controller list for @nsid, starting - * with IDs greater than or equal to @cntid. - * - * Will return an error if the length of the response data (from the - * controller) is not a full &NVME_IDENTIFY_DATA_SIZE, so @id will be - * fully populated on success. - * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. - * - * See: &struct nvme_ctrl_list - */ -static inline int nvme_mi_admin_identify_nsid_ctrl_list(nvme_link_t link, - __u32 nsid, __u16 cntid, - struct nvme_ctrl_list *list) -{ - struct nvme_identify_args args = { - .result = NULL, - .data = list, - .args_size = sizeof(args), - .cns = NVME_IDENTIFY_CNS_NS_CTRL_LIST, - .csi = NVME_CSI_NVM, - .nsid = nsid, - .cntid = cntid, - .cns_specific_id = NVME_CNSSPECID_NONE, - .uuidx = NVME_UUID_NONE, - }; - - return nvme_mi_admin_identify(link, &args); -} - -/** - * nvme_mi_admin_identify_allocated_ns_list() - Perform an Admin identify for - * an allocated namespace list - * @link: Link to process identify command - * @nsid: Namespace ID to specify list start - * @list: List data to populate - * - * Perform an Identify command, for the allocated namespace list starting with - * IDs greater than or equal to @nsid. Specify &NVME_NSID_NONE for the start - * of the list. - * - * Will return an error if the length of the response data (from the - * controller) is not a full &NVME_IDENTIFY_DATA_SIZE, so @list will be - * be fully populated on success. - * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. - * - * See: &struct nvme_ns_list - */ -static inline int nvme_mi_admin_identify_allocated_ns_list(nvme_link_t link, - __u32 nsid, - struct nvme_ns_list *list) -{ - struct nvme_identify_args args = { - .result = NULL, - .data = list, - .args_size = sizeof(args), - .cns = NVME_IDENTIFY_CNS_ALLOCATED_NS_LIST, - .csi = NVME_CSI_NVM, - .nsid = nsid, - .cns_specific_id = NVME_CNSSPECID_NONE, - .uuidx = NVME_UUID_NONE, - }; - - return nvme_mi_admin_identify(link, &args); -} - -/** - * nvme_mi_admin_identify_active_ns_list() - Perform an Admin identify for an - * active namespace list - * @link: Link to process identify command - * @nsid: Namespace ID to specify list start - * @list: List data to populate - * - * Perform an Identify command, for the active namespace list starting with - * IDs greater than or equal to @nsid. Specify &NVME_NSID_NONE for the start - * of the list. - * - * Will return an error if the length of the response data (from the - * controller) is not a full &NVME_IDENTIFY_DATA_SIZE, so @list will be - * be fully populated on success. - * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. - * - * See: &struct nvme_ns_list - */ -static inline int nvme_mi_admin_identify_active_ns_list(nvme_link_t link, - __u32 nsid, - struct nvme_ns_list *list) -{ - struct nvme_identify_args args = { - .result = NULL, - .data = list, - .args_size = sizeof(args), - .cns = NVME_IDENTIFY_CNS_NS_ACTIVE_LIST, - .csi = NVME_CSI_NVM, - .nsid = nsid, - .cns_specific_id = NVME_CNSSPECID_NONE, - .uuidx = NVME_UUID_NONE, - }; - - return nvme_mi_admin_identify(link, &args); -} - -/** - * nvme_mi_admin_identify_primary_ctrl() - Perform an Admin identify for - * primary controller capabilities data structure. - * @link: Link to process identify command - * @cntid: Controller ID to specify - * @cap: Primary Controller Capabilities data structure to populate - * - * Perform an Identify command to get the Primary Controller Capabilities data - * for the controller specified by @cntid - * - * Will return an error if the length of the response data (from the - * controller) is not a full &NVME_IDENTIFY_DATA_SIZE, so @cap will be - * be fully populated on success. - * - * Return: 0 on success, non-zero on failure - * - * See: &struct nvme_primary_ctrl_cap - */ -static inline int nvme_mi_admin_identify_primary_ctrl(nvme_link_t link, - __u16 cntid, - struct nvme_primary_ctrl_cap *cap) -{ - struct nvme_identify_args args = { - .result = NULL, - .data = cap, - .args_size = sizeof(args), - .cns = NVME_IDENTIFY_CNS_PRIMARY_CTRL_CAP, - .csi = NVME_CSI_NVM, - .nsid = NVME_NSID_NONE, - .cntid = cntid, - .cns_specific_id = NVME_CNSSPECID_NONE, - .uuidx = NVME_UUID_NONE, - }; - - return nvme_mi_admin_identify(link, &args); -} - -/** - * nvme_mi_admin_identify_secondary_ctrl_list() - Perform an Admin identify for - * a secondary controller list. - * @link: Link to process identify command - * @cntid: Controller ID to specify list start - * @list: List data to populate - * - * Perform an Identify command, for the secondary controllers associated with - * the current primary controller. Only entries with IDs greater than or - * equal to @cntid are returned. - * - * Will return an error if the length of the response data (from the - * controller) is not a full &NVME_IDENTIFY_DATA_SIZE, so @list will be - * be fully populated on success. - * - * Return: 0 on success, non-zero on failure - * - * See: &struct nvme_secondary_ctrl_list - */ -static inline int nvme_mi_admin_identify_secondary_ctrl_list(nvme_link_t link, - __u16 cntid, - struct nvme_secondary_ctrl_list *list) -{ - struct nvme_identify_args args = { - .result = NULL, - .data = list, - .args_size = sizeof(args), - .cns = NVME_IDENTIFY_CNS_SECONDARY_CTRL_LIST, - .csi = NVME_CSI_NVM, - .nsid = NVME_NSID_NONE, - .cntid = cntid, - .cns_specific_id = NVME_CNSSPECID_NONE, - .uuidx = NVME_UUID_NONE, - }; - - return nvme_mi_admin_identify(link, &args); -} - -/** - * nvme_mi_admin_get_log_page() - Retrieve log page data from controller - * @link: Link to query - * @xfer_len: The chunk size of the read - * @args: Get Log Page command arguments - * - * Performs a Get Log Page Admin command as specified by @args. Response data - * is stored in @args->data, which should be a buffer of @args->data_len bytes. - * Resulting data length is stored in @args->data_len on successful - * command completion. - * - * This request may be implemented as multiple log page commands, in order - * to fit within MI message-size limits. - * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. - * - * See: &struct nvme_get_log_args - */ -int nvme_mi_admin_get_log_page(nvme_link_t link, __u32 xfer_len, - struct nvme_get_log_args *args); - -/** - * nvme_mi_admin_get_log() - Retrieve log page data from controller - * @link: Link to query - * @args: Get Log Page command arguments - * - * Performs a Get Log Page Admin command as specified by @args. Response data - * is stored in @args->data, which should be a buffer of @args->data_len bytes. - * Resulting data length is stored in @args->data_len on successful - * command completion. - * - * This request may be implemented as multiple log page commands, in order - * to fit within MI message-size limits. - * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. - * - * See: &struct nvme_get_log_args - */ -int nvme_mi_admin_get_log(nvme_link_t link, struct nvme_get_log_args *args); - -/** - * nvme_mi_admin_get_nsid_log() - Helper for Get Log Page functions - * @link: Link to query - * @rae: Retain Asynchronous Events - * @lid: Log identifier - * @nsid: Namespace ID - * @len: length of log buffer - * @log: pointer for resulting log data - * - * Performs a Get Log Page Admin command for a specific log ID @lid and - * namespace ID @nsid. Log data is expected to be @len bytes, and is stored - * in @log on success. The @rae flag is passed as-is to the Get Log Page - * command, and is specific to the Log Page requested. - * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. - */ -static inline int nvme_mi_admin_get_nsid_log(nvme_link_t link, bool rae, - enum nvme_cmd_get_log_lid lid, - __u32 nsid, __u32 len, void *log) -{ - struct nvme_get_log_args args = { - .lpo = 0, - .result = NULL, - .log = log, - .args_size = sizeof(args), - .lid = lid, - .len = len, - .nsid = nsid, - .csi = NVME_CSI_NVM, - .lsi = NVME_LOG_LSI_NONE, - .lsp = NVME_LOG_LSP_NONE, - .uuidx = NVME_UUID_NONE, - .rae = rae, - .ot = false, - }; - - return nvme_mi_admin_get_log(link, &args); -} - -/** - * nvme_mi_admin_get_endgid_log() - Helper for Get Endurance Group ID Log Page functions - * @link: Link to query - * @rae: Retain Asynchronous Events - * @lid: Log identifier - * @endgid: Endurance Group ID - * @len: length of log buffer - * @log: pointer for resulting log data - * - * Performs a Get Log Page Admin command for a specific log ID @lid and - * endurance group ID @endgid. Log data is expected to be @len bytes, and is stored - * in @log on success. The @rae flag is passed as-is to the Get Log Page - * command, and is specific to the Log Page requested. - * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. - */ -static inline int nvme_mi_admin_get_endgid_log(nvme_link_t link, bool rae, - enum nvme_cmd_get_log_lid lid, __u16 endgid, - __u32 len, void *log) -{ - struct nvme_get_log_args args = { - .lpo = 0, - .result = NULL, - .log = log, - .args_size = sizeof(args), - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .lid = lid, - .len = len, - .nsid = NVME_NSID_NONE, - .csi = NVME_CSI_NVM, - .lsi = endgid, - .lsp = NVME_LOG_LSP_NONE, - .uuidx = NVME_LOG_LSP_NONE, - .rae = rae, - .ot = false, - }; - - return nvme_mi_admin_get_log(link, &args); -} - -/** - * nvme_mi_admin_get_log_simple() - Helper for Get Log Page functions with no - * NSID or RAE requirements - * @link: Link to query - * @lid: Log identifier - * @len: length of log buffer - * @log: pointer for resulting log data - * - * Performs a Get Log Page Admin command for a specific log ID @lid, using - * NVME_NSID_ALL for the namespace identifier, and rae set to false. - * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. - */ -static inline int nvme_mi_admin_get_log_simple(nvme_link_t link, - enum nvme_cmd_get_log_lid lid, - __u32 len, void *log) -{ - return nvme_mi_admin_get_nsid_log(link, false, lid, NVME_NSID_ALL, - len, log); -} - -/** - * nvme_mi_admin_get_log_supported_log_pages() - Retrieve nmve supported log - * pages - * @link: Link to query - * @rae: Retain asynchronous events - * @log: Array of LID supported and Effects data structures - * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. - */ -static inline int nvme_mi_admin_get_log_supported_log_pages(nvme_link_t link, - bool rae, - struct nvme_supported_log_pages *log) -{ - return nvme_mi_admin_get_nsid_log(link, rae, - NVME_LOG_LID_SUPPORTED_LOG_PAGES, - NVME_NSID_ALL, sizeof(*log), log); -} - -/** - * nvme_mi_admin_get_log_error() - Retrieve nvme error log - * @link: Link to query - * @nr_entries: Number of error log entries allocated - * @rae: Retain asynchronous events - * @err_log: Array of error logs of size 'entries' - * - * This log page describes extended error information for a command that - * completed with error, or may report an error that is not specific to a - * particular command. - * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. - */ -static inline int nvme_mi_admin_get_log_error(nvme_link_t link, - unsigned int nr_entries, bool rae, - struct nvme_error_log_page *err_log) -{ - return nvme_mi_admin_get_nsid_log(link, rae, NVME_LOG_LID_ERROR, - NVME_NSID_ALL, sizeof(*err_log) * nr_entries, - err_log); -} - -/** - * nvme_mi_admin_get_log_smart() - Retrieve nvme smart log - * @link: Link to query - * @nsid: Optional namespace identifier - * @rae: Retain asynchronous events - * @smart_log: User address to store the smart log - * - * This log page provides SMART and general health information. The information - * provided is over the life of the controller and is retained across power - * cycles. To request the controller log page, the namespace identifier - * specified is FFFFFFFFh. The controller may also support requesting the log - * page on a per namespace basis, as indicated by bit 0 of the LPA field in the - * Identify Controller data structure. - * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. - */ -static inline int nvme_mi_admin_get_log_smart(nvme_link_t link, __u32 nsid, - bool rae, - struct nvme_smart_log *smart_log) -{ - return nvme_mi_admin_get_nsid_log(link, rae, NVME_LOG_LID_SMART, - nsid, sizeof(*smart_log), smart_log); -} - -/** - * nvme_mi_admin_get_log_fw_slot() - Retrieves the controller firmware log - * @link: Link to query - * @rae: Retain asynchronous events - * @fw_log: User address to store the log page - * - * This log page describes the firmware revision stored in each firmware slot - * supported. The firmware revision is indicated as an ASCII string. The log - * page also indicates the active slot number. - * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. - */ -static inline int nvme_mi_admin_get_log_fw_slot(nvme_link_t link, bool rae, - struct nvme_firmware_slot *fw_log) -{ - return nvme_mi_admin_get_nsid_log(link, rae, NVME_LOG_LID_FW_SLOT, - NVME_NSID_ALL, sizeof(*fw_log), fw_log); -} - -/** - * nvme_mi_admin_get_log_changed_ns_list() - Retrieve namespace changed list - * @link: Link to query - * @rae: Retain asynchronous events - * @ns_log: User address to store the log page - * - * This log page describes namespaces attached to this controller that have - * changed since the last time the namespace was identified, been added, or - * deleted. - * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. - */ -static inline int nvme_mi_admin_get_log_changed_ns_list(nvme_link_t link, - bool rae, - struct nvme_ns_list *ns_log) -{ - return nvme_mi_admin_get_nsid_log(link, rae, NVME_LOG_LID_CHANGED_NS, - NVME_NSID_ALL, sizeof(*ns_log), ns_log); -} - -/** - * nvme_mi_admin_get_log_cmd_effects() - Retrieve nvme command effects log - * @link: Link to query - * @csi: Command Set Identifier - * @effects_log: User address to store the effects log - * - * This log page describes the commands that the controller supports and the - * effects of those commands on the state of the NVM subsystem. - * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. - */ -static inline int nvme_mi_admin_get_log_cmd_effects(nvme_link_t link, - enum nvme_csi csi, - struct nvme_cmd_effects_log *effects_log) -{ - struct nvme_get_log_args args = { - .lpo = 0, - .result = NULL, - .log = effects_log, - .args_size = sizeof(args), - .lid = NVME_LOG_LID_CMD_EFFECTS, - .len = sizeof(*effects_log), - .nsid = NVME_NSID_ALL, - .csi = csi, - .lsi = NVME_LOG_LSI_NONE, - .lsp = NVME_LOG_LSP_NONE, - .uuidx = NVME_UUID_NONE, - .rae = false, - .ot = false, - }; - return nvme_mi_admin_get_log(link, &args); -} - -/** - * nvme_mi_admin_get_log_device_self_test() - Retrieve the device self test log - * @link: Link to query - * @log: Userspace address of the log payload - * - * The log page indicates the status of an in progress self test and the - * percent complete of that operation, and the results of the previous 20 - * self-test operations. - * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. - */ -static inline int nvme_mi_admin_get_log_device_self_test(nvme_link_t link, - struct nvme_self_test_log *log) -{ - return nvme_mi_admin_get_nsid_log(link, false, - NVME_LOG_LID_DEVICE_SELF_TEST, - NVME_NSID_ALL, sizeof(*log), log); -} - -/** - * nvme_mi_admin_get_log_create_telemetry_host_mcda() - Create host telemetry log - * @link: Link to query - * @mcda: Maximum Created Data Area - * @log: Userspace address of the log payload - * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. - */ -static inline int nvme_mi_admin_get_log_create_telemetry_host_mcda(nvme_link_t link, - enum nvme_telemetry_da mcda, - struct nvme_telemetry_log *log) -{ - struct nvme_get_log_args args = { - .lpo = 0, - .result = NULL, - .log = log, - .args_size = sizeof(args), - .lid = NVME_LOG_LID_TELEMETRY_HOST, - .len = sizeof(*log), - .nsid = NVME_NSID_NONE, - .csi = NVME_CSI_NVM, - .lsi = NVME_LOG_LSI_NONE, - .lsp = (__u8)((mcda << 1) | NVME_LOG_TELEM_HOST_LSP_CREATE), - .uuidx = NVME_UUID_NONE, - .rae = false, - .ot = false, - }; - return nvme_mi_admin_get_log(link, &args); -} - -/** - * nvme_mi_admin_get_log_create_telemetry_host() - Create host telemetry log - * @link: Link to query - * @log: Userspace address of the log payload - * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. - */ -static inline int nvme_mi_admin_get_log_create_telemetry_host(nvme_link_t link, - struct nvme_telemetry_log *log) -{ - return nvme_mi_admin_get_log_create_telemetry_host_mcda(link, NVME_TELEMETRY_DA_CTRL_DETERMINE, log); -} - -/** - * nvme_mi_admin_get_log_telemetry_host() - Get Telemetry Host-Initiated log - * page - * @link: Link to query - * @offset: Offset into the telemetry data - * @len: Length of provided user buffer to hold the log data in bytes - * @log: User address for log page data - * - * Retrieves the Telemetry Host-Initiated log page at the requested offset - * using the previously existing capture. - * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. - */ -static inline int nvme_mi_admin_get_log_telemetry_host(nvme_link_t link, - __u64 offset, __u32 len, - void *log) -{ - struct nvme_get_log_args args = { - .lpo = offset, - .result = NULL, - .log = log, - .args_size = sizeof(args), - .lid = NVME_LOG_LID_TELEMETRY_HOST, - .len = len, - .nsid = NVME_NSID_NONE, - .csi = NVME_CSI_NVM, - .lsi = NVME_LOG_LSI_NONE, - .lsp = NVME_LOG_TELEM_HOST_LSP_RETAIN, - .uuidx = NVME_UUID_NONE, - .rae = false, - .ot = false, - }; - return nvme_mi_admin_get_log(link, &args); -} - -/** - * nvme_mi_admin_get_log_telemetry_ctrl() - Get Telemetry Controller-Initiated - * log page - * @link: Link to query - * @rae: Retain asynchronous events - * @offset: Offset into the telemetry data - * @len: Length of provided user buffer to hold the log data in bytes - * @log: User address for log page data - * - * Retrieves the Telemetry Controller-Initiated log page at the requested offset - * using the previously existing capture. - * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. - */ -static inline int nvme_mi_admin_get_log_telemetry_ctrl(nvme_link_t link, - bool rae, - __u64 offset, __u32 len, - void *log) -{ - struct nvme_get_log_args args = { - .lpo = offset, - .result = NULL, - .log = log, - .args_size = sizeof(args), - .lid = NVME_LOG_LID_TELEMETRY_CTRL, - .len = len, - .nsid = NVME_NSID_NONE, - .csi = NVME_CSI_NVM, - .lsi = NVME_LOG_LSI_NONE, - .lsp = NVME_LOG_LSP_NONE, - .uuidx = NVME_UUID_NONE, - .rae = rae, - .ot = false, - }; - return nvme_mi_admin_get_log(link, &args); -} - -/** - * nvme_mi_admin_get_log_endurance_group() - Get Endurance Group log - * @link: Link to query - * @endgid: Starting group identifier to return in the list - * @log: User address to store the endurance log - * - * This log page indicates if an Endurance Group Event has occurred for a - * particular Endurance Group. If an Endurance Group Event has occurred, the - * details of the particular event are included in the Endurance Group - * Information log page for that Endurance Group. An asynchronous event is - * generated when an entry for an Endurance Group is newly added to this log - * page. - * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. - */ -static inline int nvme_mi_admin_get_log_endurance_group(nvme_link_t link, - __u16 endgid, - struct nvme_endurance_group_log *log) -{ - struct nvme_get_log_args args = { - .lpo = 0, - .result = NULL, - .log = log, - .args_size = sizeof(args), - .lid = NVME_LOG_LID_ENDURANCE_GROUP, - .len = sizeof(*log), - .nsid = NVME_NSID_NONE, - .csi = NVME_CSI_NVM, - .lsi = endgid, - .lsp = NVME_LOG_LSP_NONE, - .uuidx = NVME_UUID_NONE, - .rae = false, - .ot = false, - }; - return nvme_mi_admin_get_log(link, &args); -} - -/** - * nvme_mi_admin_get_log_predictable_lat_nvmset() - Predictable Latency Per NVM - * Set - * @link: Link to query - * @nvmsetid: NVM set id - * @log: User address to store the predictable latency log - * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. - */ -static inline int nvme_mi_admin_get_log_predictable_lat_nvmset(nvme_link_t link, - __u16 nvmsetid, - struct nvme_nvmset_predictable_lat_log *log) -{ - struct nvme_get_log_args args = { - .lpo = 0, - .result = NULL, - .log = log, - .args_size = sizeof(args), - .lid = NVME_LOG_LID_PREDICTABLE_LAT_NVMSET, - .len = sizeof(*log), - .nsid = NVME_NSID_NONE, - .csi = NVME_CSI_NVM, - .lsi = nvmsetid, - .lsp = NVME_LOG_LSP_NONE, - .uuidx = NVME_UUID_NONE, - .rae = false, - .ot = false, - }; - return nvme_mi_admin_get_log(link, &args); -} - -/** - * nvme_mi_admin_get_log_predictable_lat_event() - Retrieve Predictable Latency - * Event Aggregate Log Page - * @link: Link to query - * @rae: Retain asynchronous events - * @offset: Offset into the predictable latency event - * @len: Length of provided user buffer to hold the log data in bytes - * @log: User address for log page data - * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. - */ -static inline int nvme_mi_admin_get_log_predictable_lat_event(nvme_link_t link, - bool rae, - __u32 offset, - __u32 len, - void *log) -{ - struct nvme_get_log_args args = { - .lpo = offset, - .result = NULL, - .log = log, - .args_size = sizeof(args), - .lid = NVME_LOG_LID_PREDICTABLE_LAT_AGG, - .len = len, - .nsid = NVME_NSID_NONE, - .csi = NVME_CSI_NVM, - .lsi = NVME_LOG_LSI_NONE, - .lsp = NVME_LOG_LSP_NONE, - .uuidx = NVME_UUID_NONE, - .rae = rae, - .ot = false, - }; - return nvme_mi_admin_get_log(link, &args); -} - -/** - * nvme_mi_admin_get_log_ana() - Retrieve Asymmetric Namespace Access log page - * @link: Link to query - * @lsp: Log specific, see &enum nvme_get_log_ana_lsp - * @rae: Retain asynchronous events - * @offset: Offset to the start of the log page - * @len: The allocated length of the log page - * @log: User address to store the ana log - * - * This log consists of a header describing the log and descriptors containing - * the asymmetric namespace access information for ANA Groups that contain - * namespaces that are attached to the controller processing the command. - * - * See &struct nvme_ana_log for the definition of the returned structure. - * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. - */ -static inline int nvme_mi_admin_get_log_ana(nvme_link_t link, - enum nvme_log_ana_lsp lsp, bool rae, - __u64 offset, __u32 len, void *log) -{ - struct nvme_get_log_args args = { - .lpo = offset, - .result = NULL, - .log = log, - .args_size = sizeof(args), - .lid = NVME_LOG_LID_ANA, - .len = len, - .nsid = NVME_NSID_NONE, - .csi = NVME_CSI_NVM, - .lsi = NVME_LOG_LSI_NONE, - .lsp = (__u8)lsp, - .uuidx = NVME_UUID_NONE, - .rae = rae, - .ot = false, - }; - return nvme_mi_admin_get_log(link, &args); -} - -/** - * nvme_mi_admin_get_log_ana_groups() - Retrieve Asymmetric Namespace Access - * groups only log page - * @link: Link to query - * @rae: Retain asynchronous events - * @len: The allocated length of the log page - * @log: User address to store the ana group log - * - * See &struct nvme_ana_group_desc for the definition of the returned structure. - * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. - */ -static inline int nvme_mi_admin_get_log_ana_groups(nvme_link_t link, - bool rae, __u32 len, - struct nvme_ana_group_desc *log) -{ - return nvme_mi_admin_get_log_ana(link, NVME_LOG_ANA_LSP_RGO_GROUPS_ONLY, rae, 0, - len, log); -} - -/** - * nvme_mi_admin_get_ana_log_atomic() - Retrieve Asymmetric Namespace Access - * log page atomically - * @link: Link to query - * @rgo: Whether to retrieve ANA groups only (no NSIDs) - * @rae: Whether to retain asynchronous events - * @retries: The maximum number of times to retry on log page changes - * @log: Pointer to a buffer to receive the ANA log page - * @len: Input: the length of the log page buffer. - * Output: the actual length of the ANA log page. - * - * See &struct nvme_ana_log for the definition of the returned structure. - * - * Return: If successful, returns 0 and sets *len to the actual log page length. - * If unsuccessful, returns the nvme command status if a response was received - * (see &enum nvme_status_field) or -1 with errno set otherwise. - * Sets errno = EINVAL if retries == 0. - * Sets errno = EAGAIN if unable to read the log page atomically - * because chgcnt changed during each of the retries attempts. - * Sets errno = ENOSPC if the full log page does not fit in the provided buffer. - */ -int nvme_mi_admin_get_ana_log_atomic(nvme_link_t link, bool rgo, bool rae, - unsigned int retries, - struct nvme_ana_log *log, __u32 *len); - -/** - * nvme_mi_admin_get_log_lba_status() - Retrieve LBA Status - * @link: Link to query - * @rae: Retain asynchronous events - * @offset: Offset to the start of the log page - * @len: The allocated length of the log page - * @log: User address to store the log page - * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. - */ -static inline int nvme_mi_admin_get_log_lba_status(nvme_link_t link, bool rae, - __u64 offset, __u32 len, - void *log) -{ - struct nvme_get_log_args args = { - .lpo = offset, - .result = NULL, - .log = log, - .args_size = sizeof(args), - .lid = NVME_LOG_LID_LBA_STATUS, - .len = len, - .nsid = NVME_NSID_NONE, - .csi = NVME_CSI_NVM, - .lsi = NVME_LOG_LSI_NONE, - .lsp = NVME_LOG_LSP_NONE, - .uuidx = NVME_UUID_NONE, - .rae = rae, - .ot = false, - }; - return nvme_mi_admin_get_log(link, &args); -} - -/** - * nvme_mi_admin_get_log_endurance_grp_evt() - Retrieve Rotational Media - * Information - * @link: Link to query - * @rae: Retain asynchronous events - * @offset: Offset to the start of the log page - * @len: The allocated length of the log page - * @log: User address to store the log page - * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. - */ -static inline int nvme_mi_admin_get_log_endurance_grp_evt(nvme_link_t link, - bool rae, - __u32 offset, - __u32 len, - void *log) -{ - struct nvme_get_log_args args = { - .lpo = offset, - .result = NULL, - .log = log, - .args_size = sizeof(args), - .lid = NVME_LOG_LID_ENDURANCE_GRP_EVT, - .len = len, - .nsid = NVME_NSID_NONE, - .csi = NVME_CSI_NVM, - .lsi = NVME_LOG_LSI_NONE, - .lsp = NVME_LOG_LSP_NONE, - .uuidx = NVME_UUID_NONE, - .rae = rae, - .ot = false, - }; - return nvme_mi_admin_get_log(link, &args); -} - -/** - * nvme_mi_admin_get_log_fid_supported_effects() - Retrieve Feature Identifiers - * Supported and Effects - * @link: Link to query - * @rae: Retain asynchronous events - * @log: FID Supported and Effects data structure - * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. - */ -static inline int nvme_mi_admin_get_log_fid_supported_effects(nvme_link_t link, - bool rae, - struct nvme_fid_supported_effects_log *log) -{ - return nvme_mi_admin_get_nsid_log(link, rae, - NVME_LOG_LID_FID_SUPPORTED_EFFECTS, - NVME_NSID_NONE, sizeof(*log), log); -} - -/** - * nvme_mi_admin_get_log_mi_cmd_supported_effects() - displays the MI Commands - * Supported by the controller - * @link: Link to query - * @rae: Retain asynchronous events - * @log: MI Command Supported and Effects data structure - * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. - */ -static inline int nvme_mi_admin_get_log_mi_cmd_supported_effects(nvme_link_t link, - bool rae, - struct nvme_mi_cmd_supported_effects_log *log) -{ - return nvme_mi_admin_get_nsid_log(link, rae, NVME_LOG_LID_MI_CMD_SUPPORTED_EFFECTS, - NVME_NSID_NONE, sizeof(*log), log); -} - -/** - * nvme_mi_admin_get_log_boot_partition() - Retrieve Boot Partition - * @link: Link to query - * @rae: Retain asynchronous events - * @lsp: The log specified field of LID - * @len: The allocated size, minimum - * struct nvme_boot_partition - * @part: User address to store the log page - * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. - */ -static inline int nvme_mi_admin_get_log_boot_partition(nvme_link_t link, - bool rae, __u8 lsp, - __u32 len, - struct nvme_boot_partition *part) -{ - struct nvme_get_log_args args = { - .lpo = 0, - .result = NULL, - .log = part, - .args_size = sizeof(args), - .lid = NVME_LOG_LID_BOOT_PARTITION, - .len = len, - .nsid = NVME_NSID_NONE, - .csi = NVME_CSI_NVM, - .lsi = NVME_LOG_LSI_NONE, - .lsp = NVME_LOG_LSP_NONE, - .uuidx = NVME_UUID_NONE, - .rae = rae, - .ot = false, - }; - return nvme_mi_admin_get_log(link, &args); -} - -/** - * nvme_mi_admin_get_log_rotational_media_info() - Retrieve Rotational Media Information Log - * @link: Link to query - * @endgid: Endurance Group Identifier - * @len: The allocated length of the log page - * @log: User address to store the log page - * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise - */ -static inline int nvme_mi_admin_get_log_rotational_media_info(nvme_link_t link, __u16 endgid, - __u32 len, - struct nvme_rotational_media_info_log *log) -{ - return nvme_mi_admin_get_endgid_log(link, false, NVME_LOG_LID_ROTATIONAL_MEDIA_INFO, endgid, - len, log); -} - -/** - * nvme_mi_admin_get_log_dispersed_ns_participating_nss() - Retrieve Dispersed Namespace - * Participating NVM Subsystems Log - * @link: Link to query - * @nsid: Namespace Identifier - * @len: The allocated length of the log page - * @log: User address to store the log page - * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise - */ -static inline int nvme_mi_admin_get_log_dispersed_ns_participating_nss(nvme_link_t link, - __u32 nsid, __u32 len, - struct nvme_dispersed_ns_participating_nss_log *log) -{ - return nvme_mi_admin_get_nsid_log(link, false, NVME_LOG_LID_DISPERSED_NS_PARTICIPATING_NSS, - nsid, len, log); -} - -/** - * nvme_mi_admin_get_log_mgmt_addr_list() - Retrieve Management Address List Log - * @link: Link to query - * @len: The allocated length of the log page - * @log: User address to store the log page - * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise - */ -static inline int nvme_mi_admin_get_log_mgmt_addr_list(nvme_link_t link, __u32 len, - struct nvme_mgmt_addr_list_log *log) -{ - return nvme_mi_admin_get_log_simple(link, NVME_LOG_LID_MGMT_ADDR_LIST, len, log); -} - -/** - * nvme_mi_admin_get_log_phy_rx_eom() - Retrieve Physical Interface Receiver Eye Opening Measurement Log - * @link: Link to query - * @lsp: Log specific, controls action and measurement quality - * @controller: Target controller ID - * @len: The allocated size, minimum - * struct nvme_phy_rx_eom_log - * @log: User address to store the log page - * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise - */ -static inline int nvme_mi_admin_get_log_phy_rx_eom(nvme_link_t link, - __u8 lsp, __u16 controller, - __u32 len, - struct nvme_phy_rx_eom_log *log) -{ - struct nvme_get_log_args args = { - .lpo = 0, - .result = NULL, - .log = log, - .args_size = sizeof(args), - .lid = NVME_LOG_LID_PHY_RX_EOM, - .len = len, - .nsid = NVME_NSID_NONE, - .csi = NVME_CSI_NVM, - .lsi = controller, - .lsp = lsp, - .uuidx = NVME_UUID_NONE, - .rae = false, - .ot = false, - }; - return nvme_mi_admin_get_log(link, &args); -} - -/** - * nvme_mi_admin_get_log_reachability_groups() - Retrieve Reachability Groups Log - * @link: Link to query - * @rgo: Return groups only - * @rae: Retain asynchronous events - * @len: The allocated length of the log page - * @log: User address to store the log page - * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise - */ -static inline int nvme_mi_admin_get_log_reachability_groups(nvme_link_t link, bool rgo, bool rae, - __u32 len, struct nvme_reachability_groups_log *log) -{ - struct nvme_get_log_args args = { - .lpo = 0, - .result = NULL, - .log = log, - .args_size = sizeof(args), - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .lid = NVME_LOG_LID_REACHABILITY_GROUPS, - .len = len, - .nsid = NVME_NSID_ALL, - .csi = NVME_CSI_NVM, - .lsi = NVME_LOG_LSI_NONE, - .lsp = rgo, - .uuidx = NVME_LOG_LSP_NONE, - .rae = rae, - .ot = false, - }; - - return nvme_mi_admin_get_log_page(link, NVME_LOG_PAGE_PDU_SIZE, &args); -} - -/** - * nvme_mi_admin_get_log_reachability_associations() - Retrieve Reachability Associations Log - * @link: Link to query - * @rao: Return associations only - * @rae: Retain asynchronous events - * @len: The allocated length of the log page - * @log: User address to store the log page - * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise - */ -static inline int nvme_mi_admin_get_log_reachability_associations(nvme_link_t link, bool rao, - bool rae, __u32 len, - struct nvme_reachability_associations_log *log) -{ - struct nvme_get_log_args args = { - .lpo = 0, - .result = NULL, - .log = log, - .args_size = sizeof(args), - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .lid = NVME_LOG_LID_REACHABILITY_ASSOCIATIONS, - .len = len, - .nsid = NVME_NSID_ALL, - .csi = NVME_CSI_NVM, - .lsi = NVME_LOG_LSI_NONE, - .lsp = rao, - .uuidx = NVME_LOG_LSP_NONE, - .rae = rae, - .ot = false, - }; - - return nvme_mi_admin_get_log_page(link, NVME_LOG_PAGE_PDU_SIZE, &args); -} - -/** - * nvme_mi_admin_get_log_changed_alloc_ns_list() - Retrieve Changed Allocated Namespace List Log - * @link: Link to query - * @rae: Retain asynchronous events - * @len: The allocated length of the log page - * @log: User address to store the log page - * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise - */ -static inline int nvme_mi_admin_get_log_changed_alloc_ns_list(nvme_link_t link, bool rae, - __u32 len, struct nvme_ns_list *log) -{ - return nvme_mi_admin_get_nsid_log(link, rae, NVME_LOG_LID_CHANGED_ALLOC_NS_LIST, - NVME_NSID_ALL, len, log); -} - -/** - * nvme_mi_admin_get_log_discovery() - Retrieve Discovery log page - * @link: Link to query - * @rae: Retain asynchronous events - * @offset: Offset of this log to retrieve - * @len: The allocated size for this portion of the log - * @log: User address to store the discovery log - * - * Supported only by fabrics discovery controllers, returning discovery - * records. - * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. - */ -static inline int nvme_mi_admin_get_log_discovery(nvme_link_t link, bool rae, - __u32 offset, __u32 len, - void *log) -{ - struct nvme_get_log_args args = { - .lpo = offset, - .result = NULL, - .log = log, - .args_size = sizeof(args), - .lid = NVME_LOG_LID_DISCOVER, - .len = len, - .nsid = NVME_NSID_NONE, - .csi = NVME_CSI_NVM, - .lsi = NVME_LOG_LSI_NONE, - .lsp = NVME_LOG_LSP_NONE, - .uuidx = NVME_UUID_NONE, - .rae = rae, - .ot = false, - }; - return nvme_mi_admin_get_log(link, &args); -} - -/** - * nvme_mi_admin_get_log_host_discover() - Retrieve Host Discovery Log - * @link: Link to query - * @allhoste: All host entries - * @rae: Retain asynchronous events - * @len: The allocated length of the log page - * @log: User address to store the log page - * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise - */ -static inline int nvme_mi_admin_get_log_host_discover(nvme_link_t link, bool allhoste, bool rae, - __u32 len, struct nvme_host_discover_log *log) -{ - struct nvme_get_log_args args = { - .lpo = 0, - .result = NULL, - .log = log, - .args_size = sizeof(args), - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .lid = NVME_LOG_LID_HOST_DISCOVER, - .len = len, - .nsid = NVME_NSID_ALL, - .csi = NVME_CSI_NVM, - .lsi = NVME_LOG_LSI_NONE, - .lsp = allhoste, - .uuidx = NVME_LOG_LSP_NONE, - .rae = rae, - .ot = false, - }; - - return nvme_mi_admin_get_log_page(link, NVME_LOG_PAGE_PDU_SIZE, &args); -} - -/** - * nvme_mi_admin_get_log_ave_discover() - Retrieve AVE Discovery Log - * @link: Link to query - * @rae: Retain asynchronous events - * @len: The allocated length of the log page - * @log: User address to store the log page - * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise - */ -static inline int nvme_mi_admin_get_log_ave_discover(nvme_link_t link, bool rae, __u32 len, - struct nvme_ave_discover_log *log) -{ - return nvme_mi_admin_get_nsid_log(link, rae, NVME_LOG_LID_AVE_DISCOVER, NVME_NSID_ALL, len, - log); -} - -/** - * nvme_mi_admin_get_log_pull_model_ddc_req() - Retrieve Pull Model DDC Request Log - * @link: Link to query - * @rae: Retain asynchronous events - * @len: The allocated length of the log page - * @log: User address to store the log page - * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise - */ -static inline int nvme_mi_admin_get_log_pull_model_ddc_req(nvme_link_t link, bool rae, __u32 len, - struct nvme_pull_model_ddc_req_log *log) -{ - return nvme_mi_admin_get_nsid_log(link, rae, NVME_LOG_LID_PULL_MODEL_DDC_REQ, NVME_NSID_ALL, - len, log); -} - -/** - * nvme_mi_admin_get_log_media_unit_stat() - Retrieve Media Unit Status - * @link: Link to query - * @domid: Domain Identifier selection, if supported - * @mus: User address to store the Media Unit statistics log - * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. - */ -static inline int nvme_mi_admin_get_log_media_unit_stat(nvme_link_t link, - __u16 domid, - struct nvme_media_unit_stat_log *mus) -{ - struct nvme_get_log_args args = { - .lpo = 0, - .result = NULL, - .log = mus, - .args_size = sizeof(args), - .lid = NVME_LOG_LID_MEDIA_UNIT_STATUS, - .len = sizeof(*mus), - .nsid = NVME_NSID_NONE, - .csi = NVME_CSI_NVM, - .lsi = domid, - .lsp = NVME_LOG_LSP_NONE, - .uuidx = NVME_UUID_NONE, - .rae = false, - .ot = false, - }; - return nvme_mi_admin_get_log(link, &args); -} - -/** - * nvme_mi_admin_get_log_support_cap_config_list() - Retrieve Supported - * Capacity Configuration List - * @link: Link to query - * @domid: Domain Identifier selection, if supported - * @cap: User address to store supported capabilities config list - * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. - */ -static inline int nvme_mi_admin_get_log_support_cap_config_list(nvme_link_t link, - __u16 domid, - struct nvme_supported_cap_config_list_log *cap) -{ - struct nvme_get_log_args args = { - .lpo = 0, - .result = NULL, - .log = cap, - .args_size = sizeof(args), - .lid = NVME_LOG_LID_SUPPORTED_CAP_CONFIG_LIST, - .len = sizeof(*cap), - .nsid = NVME_NSID_NONE, - .csi = NVME_CSI_NVM, - .lsi = domid, - .lsp = NVME_LOG_LSP_NONE, - .uuidx = NVME_UUID_NONE, - .rae = false, - .ot = false, - }; - return nvme_mi_admin_get_log(link, &args); -} - -/** - * nvme_mi_admin_get_log_reservation() - Retrieve Reservation Notification - * @link: Link to query - * @rae: Retain asynchronous events - * @log: User address to store the reservation log - * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. - */ -static inline int nvme_mi_admin_get_log_reservation(nvme_link_t link, - bool rae, - struct nvme_resv_notification_log *log) -{ - return nvme_mi_admin_get_nsid_log(link, rae, NVME_LOG_LID_RESERVATION, - NVME_NSID_ALL, sizeof(*log), log); -} - -/** - * nvme_mi_admin_get_log_sanitize() - Retrieve Sanitize Status - * @link: Link to query - * @rae: Retain asynchronous events - * @log: User address to store the sanitize log - * - * The Sanitize Status log page reports sanitize operation time estimates and - * information about the most recent sanitize operation. - * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. - */ -static inline int nvme_mi_admin_get_log_sanitize(nvme_link_t link, bool rae, - struct nvme_sanitize_log_page *log) -{ - return nvme_mi_admin_get_nsid_log(link, rae, NVME_LOG_LID_SANITIZE, - NVME_NSID_ALL, sizeof(*log), log); -} - -/** - * nvme_mi_admin_get_log_zns_changed_zones() - Retrieve list of zones that have - * changed - * @link: Link to query - * @nsid: Namespace ID - * @rae: Retain asynchronous events - * @log: User address to store the changed zone log - * - * The list of zones that have changed state due to an exceptional event. - * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. - */ -static inline int nvme_mi_admin_get_log_zns_changed_zones(nvme_link_t link, - __u32 nsid, bool rae, - struct nvme_zns_changed_zone_log *log) -{ - struct nvme_get_log_args args = { - .lpo = 0, - .result = NULL, - .log = log, - .args_size = sizeof(args), - .lid = NVME_LOG_LID_ZNS_CHANGED_ZONES, - .len = sizeof(*log), - .nsid = nsid, - .csi = NVME_CSI_ZNS, - .lsi = NVME_LOG_LSI_NONE, - .lsp = NVME_LOG_LSP_NONE, - .uuidx = NVME_UUID_NONE, - .rae = rae, - .ot = false, - }; - return nvme_mi_admin_get_log(link, &args); -} - -/** - * nvme_mi_admin_get_log_persistent_event() - Retrieve Persistent Event Log - * @link: Link to query - * @action: Action the controller should take during processing this command - * @size: Size of @pevent_log - * @pevent_log: User address to store the persistent event log - * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. - */ -static inline int nvme_mi_admin_get_log_persistent_event(nvme_link_t link, - enum nvme_pevent_log_action action, - __u32 size, void *pevent_log) -{ - struct nvme_get_log_args args = { - .lpo = 0, - .result = NULL, - .log = pevent_log, - .args_size = sizeof(args), - .lid = NVME_LOG_LID_PERSISTENT_EVENT, - .len = size, - .nsid = NVME_NSID_ALL, - .csi = NVME_CSI_NVM, - .lsi = NVME_LOG_LSI_NONE, - .lsp = (__u8)action, - .uuidx = NVME_UUID_NONE, - .rae = false, - .ot = false, - }; - return nvme_mi_admin_get_log(link, &args); -} - -/** - * nvme_mi_admin_get_log_lockdown() - Retrieve lockdown Log - * @link: Link to query - * @cnscp: Contents and Scope of Command and Feature Identifier Lists - * @lockdown_log: Buffer to store the lockdown log - * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. - */ -static inline int nvme_mi_admin_get_log_lockdown(nvme_link_t link, - __u8 cnscp, struct nvme_lockdown_log *lockdown_log) -{ - struct nvme_get_log_args args = { - .lpo = 0, - .result = NULL, - .log = lockdown_log, - .args_size = sizeof(args), - .lid = NVME_LOG_LID_CMD_AND_FEAT_LOCKDOWN, - .len = sizeof(*lockdown_log), - .nsid = NVME_NSID_ALL, - .csi = NVME_CSI_NVM, - .lsi = NVME_LOG_LSI_NONE, - .lsp = cnscp, - .uuidx = NVME_UUID_NONE, - .rae = false, - .ot = false, - }; - return nvme_mi_admin_get_log(link, &args); -} - -/** - * nvme_mi_admin_security_send() - Perform a Security Send command on a - * controller. - * @link: Link to send command to - * @args: Security Send command arguments - * - * Performs a Security Send Admin command as specified by @args. Response data - * is stored in @args->data, which should be a buffer of @args->data_len bytes. - * Resulting data length is stored in @args->data_len on successful - * command completion. - * - * Security Send data length should not be greater than 4096 bytes to - * comply with specification limits. - * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. - * - * See: &struct nvme_get_log_args - */ -int nvme_mi_admin_security_send(nvme_link_t link, - struct nvme_security_send_args *args); - -/** - * nvme_mi_admin_security_recv() - Perform a Security Receive command on a - * controller. - * @link: Link to send command to - * @args: Security Receive command arguments - * - * Performs a Security Receive Admin command as specified by @args. Response - * data is stored in @args->data, which should be a buffer of @args->data_len - * bytes. Resulting data length is stored in @args->data_len on successful - * command completion. - * - * Security Receive data length should not be greater than 4096 bytes to - * comply with specification limits. - * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. - * - * See: &struct nvme_get_log_args - */ -int nvme_mi_admin_security_recv(nvme_link_t link, - struct nvme_security_receive_args *args); - -/** - * nvme_mi_admin_get_features - Perform a Get Feature command on a controller - * @link: Link to send command to - * @args: Get Features command arguments - * - * Performs a Get Features Admin command as specified by @args. Returned - * feature data will be stored in @args->result and @args->data, depending - * on the specification of the feature itself; most features do not return - * additional data. See section 5.27.1 of the NVMe spec (v2.0b) for - * feature-specific information. - * - * On success, @args->data_len will be updated with the actual data length - * received. - * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. - */ -int nvme_mi_admin_get_features(nvme_link_t link, - struct nvme_get_features_args *args); - -/** - * nvme_mi_admin_get_features_arbitration() - Get arbitration feature - * @link: Link to send command to - * @sel: Select which type of attribute to return, see &enum nvme_get_features_sel - * @result: The feature data is returned in this argument - * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. - */ -int nvme_mi_admin_get_features_arbitration(nvme_link_t link, enum nvme_get_features_sel sel, - __u32 *result); - -/** - * nvme_mi_admin_get_features_power_mgmt() - Get power management feature - * @link: Link to send command to - * @sel: Select which type of attribute to return, see &enum nvme_get_features_sel - * @result: The feature data is returned in this argument - * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. - */ -int nvme_mi_admin_get_features_power_mgmt(nvme_link_t link, enum nvme_get_features_sel sel, - __u32 *result); - -/** - * nvme_mi_admin_get_features_data() - Helper function for &nvme_mi_admin_get_features() - * @link: Link to send command to - * @fid: Feature identifier - * @nsid: Namespace ID, if applicable for @fid - * @data_len: Length of feature data, if applicable for @fid, in bytes - * @data: User address of feature data, if applicable - * @result: The command completion result from CQE dword0 - * - * Helper for optionally features that optionally return data, using the - * SEL_CURRENT selector value. - * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. - */ -static inline int nvme_mi_admin_get_features_data(nvme_link_t link, - enum nvme_features_id fid, - __u32 nsid, __u32 data_len, - void *data, __u32 *result) -{ - struct nvme_get_features_args args = { - .result = result, - .data = data, - .args_size = sizeof(args), - .nsid = nsid, - .sel = NVME_GET_FEATURES_SEL_CURRENT, - .cdw11 = 0, - .data_len = data_len, - .fid = (__u8)fid, - .uuidx = NVME_UUID_NONE, - }; - - return nvme_mi_admin_get_features(link, &args); -} - -/** - * nvme_mi_admin_get_features_simple - Get a simple feature value with no data - * @link: Link to send command to - * @fid: Feature identifier - * @nsid: Namespace id, if required by @fid - * @result: output feature data - */ -static inline int nvme_mi_admin_get_features_simple(nvme_link_t link, - enum nvme_features_id fid, - __u32 nsid, - __u32 *result) -{ - return nvme_mi_admin_get_features_data(link, fid, nsid, - 0, NULL, result); -} - -/** - * nvme_mi_admin_set_features - Perform a Set Features command on a controller - * @link: Link to send command to - * @args: Set Features command arguments - * - * Performs a Set Features Admin command as specified by @args. Result - * data will be stored in @args->result. - * on the specification of the feature itself; most features do not return - * additional data. See section 5.27.1 of the NVMe spec (v2.0b) for - * feature-specific information. - * - * On success, @args->data_len will be updated with the actual data length - * received. - * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. - */ -int nvme_mi_admin_set_features(nvme_link_t link, - struct nvme_set_features_args *args); - -/** - * nvme_mi_admin_set_features_power_mgmt() - Set power management feature - * @link: Link to send command to - * @ps: Power State - * @wh: Workload Hint - * @save: Save value across power states - * @result: The feature data is returned in this argument - * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. - */ -int nvme_mi_admin_set_features_power_mgmt(nvme_link_t link, __u8 ps, __u8 wh, bool save, - __u32 *result); - -/** - * nvme_mi_admin_ns_mgmt - Issue a Namespace Management command - * @link: Link to send command to - * @args: Namespace management command arguments - * - * Issues a Namespace Management command to @ctrl, with arguments specified - * from @args. - * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. - */ -int nvme_mi_admin_ns_mgmt(nvme_link_t link, - struct nvme_ns_mgmt_args *args); - -/** - * nvme_mi_admin_ns_mgmt_create - Helper for Namespace Management Create command - * @link: Link to send command to - * @ns: New namespace parameters - * @csi: Command Set Identifier for new NS - * @nsid: Set to new namespace ID on create - * @data: Host Software Specified Fields that defines ns creation parameters - * - * Issues a Namespace Management (Create) command to @ctrl, to create a - * new namespace specified by @ns, using command set @csi. On success, - * the new namespace ID will be written to @nsid. - * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. - */ -static inline int nvme_mi_admin_ns_mgmt_create(nvme_link_t link, - struct nvme_id_ns *ns, __u8 csi, __u32 *nsid, - struct nvme_ns_mgmt_host_sw_specified *data) -{ - struct nvme_ns_mgmt_args args = { - .result = nsid, - .ns = ns, - .args_size = sizeof(args), - .nsid = NVME_NSID_NONE, - .sel = NVME_NS_MGMT_SEL_CREATE, - .csi = csi, - .data = data, - }; - - return nvme_mi_admin_ns_mgmt(link, &args); -} - -/** - * nvme_mi_admin_ns_mgmt_delete - Helper for Namespace Management Delete command - * @link: Link to send command to - * @nsid: Namespace ID to delete - * - * Issues a Namespace Management (Delete) command to @ctrl, to delete the - * namespace with id @nsid. - * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. - */ -static inline int nvme_mi_admin_ns_mgmt_delete(nvme_link_t link, __u32 nsid) -{ - struct nvme_ns_mgmt_args args = { - .args_size = sizeof(args), - .nsid = nsid, - .sel = NVME_NS_MGMT_SEL_DELETE, - }; - - return nvme_mi_admin_ns_mgmt(link, &args); -} - -/** - * nvme_mi_admin_ns_attach() - Attach or detach namespace to controller(s) - * @link: Link to send command to - * @args: Namespace Attach command arguments - * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. - */ -int nvme_mi_admin_ns_attach(nvme_link_t link, - struct nvme_ns_attach_args *args); - -/** - * nvme_mi_admin_ns_attach_ctrls() - Attach namespace to controllers - * @link: Link to send command to - * @nsid: Namespace ID to attach - * @ctrlist: Controller list to modify attachment state of nsid - * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. - */ -static inline int nvme_mi_admin_ns_attach_ctrls(nvme_link_t link, __u32 nsid, - struct nvme_ctrl_list *ctrlist) -{ - struct nvme_ns_attach_args args = { - .result = NULL, - .ctrlist = ctrlist, - .args_size = sizeof(args), - .nsid = nsid, - .sel = NVME_NS_ATTACH_SEL_CTRL_ATTACH, - }; - - return nvme_mi_admin_ns_attach(link, &args); -} - -/** - * nvme_mi_admin_ns_detach_ctrls() - Detach namespace from controllers - * @link: Link to send command to - * @nsid: Namespace ID to detach - * @ctrlist: Controller list to modify attachment state of nsid - * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. - */ -static inline int nvme_mi_admin_ns_detach_ctrls(nvme_link_t link, __u32 nsid, - struct nvme_ctrl_list *ctrlist) -{ - struct nvme_ns_attach_args args = { - .result = NULL, - .ctrlist = ctrlist, - .args_size = sizeof(args), - .nsid = nsid, - .sel = NVME_NS_ATTACH_SEL_CTRL_DEATTACH, - }; - - return nvme_mi_admin_ns_attach(link, &args); -} - -/** - * nvme_mi_admin_fw_download() - Download part or all of a firmware image to - * the controller - * @link: Link to send firmware data to - * @args: &struct nvme_fw_download_args argument structure - * - * The Firmware Image Download command downloads all or a portion of an image - * for a future update to the controller. The Firmware Image Download command - * downloads a new image (in whole or in part) to the controller. - * - * The image may be constructed of multiple pieces that are individually - * downloaded with separate Firmware Image Download commands. Each Firmware - * Image Download command includes a Dword Offset and Number of Dwords that - * specify a dword range. - * - * The new firmware image is not activated as part of the Firmware Image - * Download command. Use the nvme_mi_admin_fw_commit() to activate a newly - * downloaded image. - * - * Return: 0 on success, non-zero on failure - */ -int nvme_mi_admin_fw_download(nvme_link_t link, - struct nvme_fw_download_args *args); - -/** - * nvme_mi_admin_fw_commit() - Commit firmware using the specified action - * @link: Link to send firmware data to - * @args: &struct nvme_fw_download_args argument structure - * - * The Firmware Commit command modifies the firmware image or Boot Partitions. - * - * Return: 0 on success, non-zero on failure - */ -int nvme_mi_admin_fw_commit(nvme_link_t link, - struct nvme_fw_commit_args *args); - -/** - * nvme_mi_admin_format_nvm() - Format NVMe namespace - * @link: Link to send command to - * @args: Format NVM command arguments - * - * Perform a low-level format to set the LBA data & metadata size. May destroy - * data & metadata on the specified namespaces - * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. - */ -int nvme_mi_admin_format_nvm(nvme_link_t link, - struct nvme_format_nvm_args *args); - -/** - * nvme_mi_admin_sanitize_nvm() - Start a subsystem Sanitize operation - * @link: Link to send command to - * @args: Sanitize command arguments - * - * A sanitize operation alters all user data in the NVM subsystem such that - * recovery of any previous user data from any cache, the non-volatile media, - * or any Controller Memory Buffer is not possible. - * - * The Sanitize command starts a sanitize operation or to recover from a - * previously failed sanitize operation. The sanitize operation types that may - * be supported are Block Erase, Crypto Erase, and Overwrite. All sanitize - * operations are processed in the background, i.e., completion of the sanitize - * command does not indicate completion of the sanitize operation. - * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. - */ -int nvme_mi_admin_sanitize_nvm(nvme_link_t link, - struct nvme_sanitize_nvm_args *args); - /** * enum nvme_mi_aem_handler_next_action - Next action for the AEM state machine handler * @NVME_MI_AEM_HNA_ACK: Send an ack for the AEM diff --git a/test/mi-mctp.c b/test/mi-mctp.c index d459b2fb9..5daa6fe94 100644 --- a/test/mi-mctp.c +++ b/test/mi-mctp.c @@ -417,7 +417,7 @@ static void test_admin_resp_err(nvme_mi_ep_t ep, struct test_peer *peer) peer->tx_buf[4] = 0x02; /* internal error */ peer->tx_buf_len = 8; - rc = nvme_mi_admin_identify_ctrl(link, &id); + rc = nvme_identify_ctrl(link, &id); assert(nvme_status_get_type(rc) == NVME_STATUS_TYPE_MI); assert(nvme_status_get_value(rc) == NVME_MI_RESP_INTERNAL_ERR); } @@ -442,7 +442,7 @@ static void test_admin_resp_sizes(nvme_mi_ep_t ep, struct test_peer *peer) for (i = 8; i <= 4096 + 8; i+=4) { peer->tx_buf_len = i; - rc = nvme_mi_admin_identify_ctrl(link, &id); + rc = nvme_identify_ctrl(link, &id); assert(nvme_status_get_type(rc) == NVME_STATUS_TYPE_MI); assert(nvme_status_get_value(rc) == NVME_MI_RESP_INTERNAL_ERR); } @@ -565,7 +565,7 @@ static void test_mpr_admin(nvme_mi_ep_t ep, struct test_peer *peer) link = nvme_mi_init_link(ep, 1); - rc = nvme_mi_admin_identify_ctrl(link, &id); + rc = nvme_identify_ctrl(link, &id); assert(rc == 0); nvme_close(link); @@ -590,7 +590,7 @@ static void test_mpr_admin_quirked(nvme_mi_ep_t ep, struct test_peer *peer) link = nvme_mi_init_link(ep, 1); - rc = nvme_mi_admin_identify_ctrl(link, &id); + rc = nvme_identify_ctrl(link, &id); assert(rc == 0); nvme_close(link); diff --git a/test/mi.c b/test/mi.c index 8bdcb9e8d..e990ca983 100644 --- a/test/mi.c +++ b/test/mi.c @@ -4,6 +4,7 @@ * Copyright (c) 2022 Code Construct */ +#include "nvme/types.h" #undef NDEBUG #include #include @@ -447,7 +448,7 @@ static void test_admin_id(nvme_mi_ep_t ep) link = nvme_mi_init_link(ep, 5); assert(link); - rc = nvme_mi_admin_identify_ctrl(link, &id); + rc = nvme_identify_ctrl(link, &id); assert(rc == 0); } @@ -501,7 +502,7 @@ static void test_admin_err_mi_resp(nvme_mi_ep_t ep) link = nvme_mi_init_link(ep, 1); assert(link); - rc = nvme_mi_admin_identify_ctrl(link, &id); + rc = nvme_identify_ctrl(link, &id); assert(rc != 0); assert(nvme_status_get_type(rc) == NVME_STATUS_TYPE_MI); assert(nvme_status_get_value(rc) == NVME_MI_RESP_INTERNAL_ERR); @@ -563,7 +564,7 @@ static void test_admin_err_nvme_resp(nvme_mi_ep_t ep) link = nvme_mi_init_link(ep, 1); assert(link); - rc = nvme_mi_admin_identify_ctrl(link, &id); + rc = nvme_identify_ctrl(link, &id); assert(rc != 0); assert(nvme_status_get_type(rc) == NVME_STATUS_TYPE_NVME); assert(nvme_status_get_value(rc) == @@ -976,7 +977,7 @@ static void test_get_features_nodata(nvme_mi_ep_t ep) args.sel = 0; args.result = &res; - rc = nvme_mi_admin_get_features(link, &args); + rc = nvme_get_features(link, &args); assert(rc == 0); assert(args.data_len == 0); assert(res == 0x04030201); @@ -1007,7 +1008,7 @@ static void test_get_features_data(nvme_mi_ep_t ep) for (i = 0; i < sizeof(tstamp.timestamp); i++) exp[i] = i; - rc = nvme_mi_admin_get_features(link, &args); + rc = nvme_get_features(link, &args); assert(rc == 0); assert(args.data_len == sizeof(tstamp)); assert(tstamp.attr == 1); @@ -1089,9 +1090,9 @@ static void test_set_features(nvme_mi_ep_t ep) args.data = &tstamp; args.data_len = sizeof(tstamp); - rc = nvme_mi_admin_set_features(link, &args); + rc = nvme_set_features(link, &args); assert(rc == 0); - assert(args.data_len == 0); + assert(args.data_len == 8); } enum ns_type { @@ -1158,7 +1159,7 @@ static void test_admin_id_alloc_ns_list(struct nvme_mi_ep *ep) link = nvme_mi_init_link(ep, 5); assert(link); - rc = nvme_mi_admin_identify_allocated_ns_list(link, 1, &list); + rc = nvme_identify_allocated_ns_list(link, 1, &list); assert(!rc); assert(le32_to_cpu(list.ns[0]) == 2); @@ -1179,7 +1180,7 @@ static void test_admin_id_active_ns_list(struct nvme_mi_ep *ep) link = nvme_mi_init_link(ep, 5); assert(link); - rc = nvme_mi_admin_identify_active_ns_list(link, 1, &list); + rc = nvme_identify_active_ns_list(link, 1, &list); assert(!rc); assert(le32_to_cpu(list.ns[0]) == 4); @@ -1242,7 +1243,7 @@ static void test_admin_id_alloc_ns(struct nvme_mi_ep *ep) link = nvme_mi_init_link(ep, 5); assert(link); - rc = nvme_mi_admin_identify_allocated_ns(link, 1, &id); + rc = nvme_identify_allocated_ns(link, 1, &id); assert(!rc); assert(le64_to_cpu(id.nsze) == 1); } @@ -1260,7 +1261,7 @@ static void test_admin_id_active_ns(struct nvme_mi_ep *ep) link = nvme_mi_init_link(ep, 5); assert(link); - rc = nvme_mi_admin_identify_ns(link, 1, &id); + rc = nvme_identify_ns(link, 1, &id); assert(!rc); assert(le64_to_cpu(id.nsze) == 1); } @@ -1305,7 +1306,7 @@ static void test_admin_id_nsid_ctrl_list(struct nvme_mi_ep *ep) link = nvme_mi_init_link(ep, 5); assert(link); - rc = nvme_mi_admin_identify_nsid_ctrl_list(link, 0x01020304, 5, &list); + rc = nvme_identify_nsid_ctrl_list(link, 0x01020304, 5, &list); assert(!rc); } @@ -1346,7 +1347,7 @@ static void test_admin_id_secondary_ctrl_list(struct nvme_mi_ep *ep) link = nvme_mi_init_link(ep, 5); assert(link); - rc = nvme_mi_admin_identify_secondary_ctrl_list(link, 5, &list); + rc = nvme_identify_secondary_ctrl_list(link, 5, &list); assert(!rc); } @@ -1417,12 +1418,12 @@ static void test_admin_ns_mgmt_create(struct nvme_mi_ep *ep) link = nvme_mi_init_link(ep, 5); assert(link); - rc = nvme_mi_admin_ns_mgmt_create(link, NULL, 0, &ns, &data); + rc = nvme_ns_mgmt_create(link, NULL, &ns, 0, NVME_CSI_NVM, &data); assert(!rc); assert(ns == 0x01020304); data.nsze = cpu_to_le64(42); - rc = nvme_mi_admin_ns_mgmt_create(link, NULL, 0, &ns, &data); + rc = nvme_ns_mgmt_create(link, NULL, &ns, 0, NVME_CSI_NVM, &data); assert(rc); } @@ -1436,7 +1437,7 @@ static void test_admin_ns_mgmt_delete(struct nvme_mi_ep *ep) link = nvme_mi_init_link(ep, 5); assert(link); - rc = nvme_mi_admin_ns_mgmt_delete(link, 0x05060708); + rc = nvme_ns_mgmt_delete(link, 0x05060708); assert(!rc); } @@ -1503,7 +1504,7 @@ static void test_admin_ns_attach(struct nvme_mi_ep *ep) link = nvme_mi_init_link(ep, 5); assert(link); - rc = nvme_mi_admin_ns_attach_ctrls(link, 0x02030405, &list); + rc = nvme_ns_attach_ctrls(link, 0x02030405, &list); assert(!rc); } @@ -1526,7 +1527,7 @@ static void test_admin_ns_detach(struct nvme_mi_ep *ep) link = nvme_mi_init_link(ep, 5); assert(link); - rc = nvme_mi_admin_ns_detach_ctrls(link, 0x02030405, &list); + rc = nvme_ns_detach_ctrls(link, 0x02030405, &list); assert(!rc); } @@ -1589,37 +1590,37 @@ static void test_admin_fw_download(struct nvme_mi_ep *ep) /* invalid (zero) len */ args.data_len = info.len = 1; args.offset = info.offset = 0; - rc = nvme_mi_admin_fw_download(link, &args); + rc = nvme_fw_download(link, &args); assert(rc); /* invalid (unaligned) len */ args.data_len = info.len = 1; args.offset = info.offset = 0; - rc = nvme_mi_admin_fw_download(link, &args); + rc = nvme_fw_download(link, &args); assert(rc); /* invalid offset */ args.data_len = info.len = 4; args.offset = info.offset = 1; - rc = nvme_mi_admin_fw_download(link, &args); + rc = nvme_fw_download(link, &args); assert(rc); /* smallest len */ args.data_len = info.len = 4; args.offset = info.offset = 0; - rc = nvme_mi_admin_fw_download(link, &args); + rc = nvme_fw_download(link, &args); assert(!rc); /* largest len */ args.data_len = info.len = 4096; args.offset = info.offset = 0; - rc = nvme_mi_admin_fw_download(link, &args); + rc = nvme_fw_download(link, &args); assert(!rc); /* offset value */ args.data_len = info.len = 4096; args.offset = info.offset = 4096; - rc = nvme_mi_admin_fw_download(link, &args); + rc = nvme_fw_download(link, &args); assert(!rc); } @@ -1673,21 +1674,21 @@ static void test_admin_fw_commit(struct nvme_mi_ep *ep) info.bpid = args.bpid = 0; info.slot = args.slot = 0; info.action = args.action = 0; - rc = nvme_mi_admin_fw_commit(link, &args); + rc = nvme_fw_commit(link, &args); assert(!rc); /* all ones */ info.bpid = args.bpid = 1; info.slot = args.slot = 0x7; info.action = args.action = 0x7; - rc = nvme_mi_admin_fw_commit(link, &args); + rc = nvme_fw_commit(link, &args); assert(!rc); /* correct fields */ info.bpid = args.bpid = 1; info.slot = args.slot = 2; info.action = args.action = 3; - rc = nvme_mi_admin_fw_commit(link, &args); + rc = nvme_fw_commit(link, &args); assert(!rc); } @@ -1757,7 +1758,7 @@ static void test_admin_format_nvm(struct nvme_mi_ep *ep) args.mset = 0x1; args.lbaf = 0x0; - rc = nvme_mi_admin_format_nvm(link, &args); + rc = nvme_format_nvm(link, &args); assert(!rc); args.nsid = ~args.nsid; @@ -1768,7 +1769,7 @@ static void test_admin_format_nvm(struct nvme_mi_ep *ep) args.mset = 0x0; args.lbaf = 0xf; - rc = nvme_mi_admin_format_nvm(link, &args); + rc = nvme_format_nvm(link, &args); assert(!rc); } @@ -1822,7 +1823,7 @@ static void test_admin_sanitize_nvm(struct nvme_mi_ep *ep) args.nodas = 0x1; args.ovrpat = ~0x04030201; - rc = nvme_mi_admin_sanitize_nvm(link, &args); + rc = nvme_sanitize_nvm(link, &args); assert(!rc); args.sanact = 0x0; @@ -1832,7 +1833,7 @@ static void test_admin_sanitize_nvm(struct nvme_mi_ep *ep) args.nodas = 0x0; args.ovrpat = 0x04030201; - rc = nvme_mi_admin_sanitize_nvm(link, &args); + rc = nvme_sanitize_nvm(link, &args); assert(!rc); } @@ -1917,7 +1918,7 @@ static void test_admin_get_log_split(struct nvme_mi_ep *ep) args.lpo = 0; args.ot = false; - rc = nvme_mi_admin_get_log(link, &args); + rc = nvme_get_log_page(link, NVME_LOG_PAGE_PDU_SIZE, &args); assert(!rc); From 45928459db7f72f82c289075d7303f281da00c8b Mon Sep 17 00:00:00 2001 From: Daniel Wagner Date: Fri, 11 Jul 2025 10:57:28 +0200 Subject: [PATCH 14/66] src: return error codes directly The v1 design used the POSIX way to return errors, return -1 with errno set. Replace this design by returning directly the error code. That means non trivial function have to return any data via a pointer so the function is able to return proper error codes. Signed-off-by: Daniel Wagner --- examples/discover-loop.c | 20 +- examples/display-columnar.c | 3 +- examples/display-tree.c | 3 +- examples/mi-mctp-ae.c | 2 +- examples/telemetry-listen.c | 3 +- libnvme/nvme.i | 22 +- src/nvme/cleanup.h | 6 + src/nvme/fabrics.c | 199 ++++----- src/nvme/fabrics.h | 31 +- src/nvme/ioctl.c | 361 +++++++-------- src/nvme/ioctl.h | 712 +++++++++++++++--------------- src/nvme/json.c | 15 +- src/nvme/linux.c | 845 ++++++++++++++++-------------------- src/nvme/linux.h | 199 +++++---- src/nvme/mi.c | 217 ++++----- src/nvme/nbft.c | 18 +- src/nvme/tree.c | 462 ++++++++++---------- src/nvme/tree.h | 58 +-- src/nvme/util.c | 50 +-- src/nvme/util.h | 2 +- test/config/config-dump.c | 9 +- test/config/hostnqn-order.c | 18 +- test/config/psk-json.c | 16 +- test/cpp.cc | 3 +- test/ioctl/ana.c | 32 +- test/ioctl/discovery.c | 23 +- test/ioctl/features.c | 138 +++--- test/ioctl/identify.c | 51 ++- test/ioctl/logs.c | 86 ++-- test/ioctl/misc.c | 102 ++--- test/ioctl/zns.c | 10 +- test/mi-mctp.c | 6 +- test/psk.c | 32 +- test/sysfs/tree-dump.c | 6 +- test/test.c | 6 +- test/tree.c | 8 +- test/uriparser.c | 7 +- test/zns.c | 3 +- 38 files changed, 1777 insertions(+), 2007 deletions(-) diff --git a/examples/discover-loop.c b/examples/discover-loop.c index 4f445e21e..e6eeb387b 100644 --- a/examples/discover-loop.c +++ b/examples/discover-loop.c @@ -59,22 +59,24 @@ int main() nvmf_default_config(&cfg); - r = nvme_scan(NULL); - h = nvme_default_host(r); - if (!h) { + ret = nvme_scan(NULL, &r); + if (ret) + return ret; + ret = nvme_default_host(r, &h); + if (ret) { fprintf(stderr, "Failed to allocated memory\n"); - return ENOMEM; + return ret; } - c = nvme_create_ctrl(r, NVME_DISC_SUBSYS_NAME, "loop", - NULL, NULL, NULL, NULL); - if (!c) { + ret = nvme_create_ctrl(r, NVME_DISC_SUBSYS_NAME, "loop", + NULL, NULL, NULL, NULL, &c); + if (ret) { fprintf(stderr, "Failed to allocate memory\n"); return ENOMEM; } ret = nvmf_add_ctrl(h, c, &cfg); - if (ret < 0) { + if (ret) { fprintf(stderr, "no controller found\n"); - return errno; + return ret; } ret = nvmf_get_discovery_log(c, &log, 4); diff --git a/examples/display-columnar.c b/examples/display-columnar.c index db98bdfec..baf67fedc 100644 --- a/examples/display-columnar.c +++ b/examples/display-columnar.c @@ -24,8 +24,7 @@ int main() nvme_path_t p; nvme_ns_t n; - r = nvme_scan(NULL); - if (!r) + if (nvme_scan(NULL, &r)) return -1; diff --git a/examples/display-tree.c b/examples/display-tree.c index bf523f4c4..74bb9ff58 100644 --- a/examples/display-tree.c +++ b/examples/display-tree.c @@ -23,8 +23,7 @@ int main() nvme_path_t p, _p; nvme_ns_t n, _n; - r = nvme_scan(NULL); - if (!r) + if (nvme_scan(NULL, &r)) return -1; printf(".\n"); diff --git a/examples/mi-mctp-ae.c b/examples/mi-mctp-ae.c index d73a35987..89e1e3172 100644 --- a/examples/mi-mctp-ae.c +++ b/examples/mi-mctp-ae.c @@ -131,7 +131,7 @@ int main(int argc, char **argv) } rc = nvme_mi_aem_enable(ep, &aem_config, &data); - if (rc && errno == EOPNOTSUPP) + if (rc == EOPNOTSUPP) errx(EXIT_FAILURE, "MCTP Peer-Bind is required for AEM"); else if (rc) err(EXIT_FAILURE, "Can't enable aem:%d", rc); diff --git a/examples/telemetry-listen.c b/examples/telemetry-listen.c index 886e9c74d..2f892c9aa 100644 --- a/examples/telemetry-listen.c +++ b/examples/telemetry-listen.c @@ -133,8 +133,7 @@ int main() nvme_host_t h; nvme_root_t r; - r = nvme_scan(NULL); - if (!r) + if (nvme_scan(NULL, &r)) return EXIT_FAILURE; nvme_for_each_host(r, h) diff --git a/libnvme/nvme.i b/libnvme/nvme.i index d8585ce2c..44f683a33 100644 --- a/libnvme/nvme.i +++ b/libnvme/nvme.i @@ -448,7 +448,10 @@ struct nvme_ns { %extend nvme_root { nvme_root(const char *config_file = NULL) { - return nvme_scan(config_file); + struct nvme_root *r; + if (nvme_scan(config_file, &r)) + return NULL; + return r; } ~nvme_root() { nvme_free_root($self); @@ -516,7 +519,11 @@ struct nvme_ns { const char *hostid = NULL, const char *hostkey = NULL, const char *hostsymname = NULL) { - nvme_host_t h = hostnqn ? nvme_lookup_host(r, hostnqn, hostid) : nvme_default_host(r); + nvme_host_t h; + if (hostnqn) + h = nvme_lookup_host(r, hostnqn, hostid); + if (nvme_default_host(r, &h)) + return NULL; if (hostsymname) nvme_host_set_hostsymname(h, hostsymname); if (hostkey) @@ -663,8 +670,11 @@ struct nvme_ns { const char *host_traddr = NULL, const char *host_iface = NULL, const char *trsvcid = NULL) { - return nvme_create_ctrl(r, subsysnqn, transport, traddr, - host_traddr, host_iface, trsvcid); + struct nvme_ctrl *c; + if (nvme_create_ctrl(r, subsysnqn, transport, traddr, + host_traddr, host_iface, trsvcid, &c)) + return NULL; + return c; } ~nvme_ctrl() { nvme_free_ctrl($self); @@ -748,7 +758,7 @@ struct nvme_ns { %newobject discover; struct nvmf_discovery_log *discover(int lsp = 0, int max_retries = 6) { - struct nvmf_discovery_log *logp; + struct nvmf_discovery_log *logp = NULL; struct nvme_get_discovery_args args = { .c = $self, .args_size = sizeof(args), @@ -759,7 +769,7 @@ struct nvme_ns { }; Py_BEGIN_ALLOW_THREADS /* Release Python GIL */ - logp = nvmf_get_discovery_wargs(&args); + nvmf_get_discovery_wargs(&args, &logp); Py_END_ALLOW_THREADS /* Reacquire Python GIL */ if (logp == NULL) discover_err = 1; diff --git a/src/nvme/cleanup.h b/src/nvme/cleanup.h index 432760046..4c275398d 100644 --- a/src/nvme/cleanup.h +++ b/src/nvme/cleanup.h @@ -6,6 +6,9 @@ #include #include #include +#include +#include +#include #define __cleanup__(fn) __attribute__((cleanup(fn))) @@ -38,4 +41,7 @@ static inline void cleanup_fd(int *fd) } #define _cleanup_fd_ __cleanup__(cleanup_fd) +static inline DEFINE_CLEANUP_FUNC(cleanup_addrinfo, struct addrinfo *, freeaddrinfo) +#define _cleanup_addrinfo_ __cleanup__(cleanup_addrinfo) + #endif diff --git a/src/nvme/fabrics.c b/src/nvme/fabrics.c index 3c011f2bf..c310e019a 100644 --- a/src/nvme/fabrics.c +++ b/src/nvme/fabrics.c @@ -300,8 +300,7 @@ static int __add_bool_argument(char **argstr, char *tok, bool arg) if (!arg) return 0; if (asprintf(&nstr, "%s,%s", *argstr, tok) < 0) { - errno = ENOMEM; - return -1; + return -ENOMEM; } free(*argstr); *argstr = nstr; @@ -316,8 +315,7 @@ static int __add_hex_argument(char **argstr, char *tok, int arg, bool allow_zero if (arg < 0 || (!arg && !allow_zero)) return 0; if (asprintf(&nstr, "%s,%s=0x%08x", *argstr, tok, arg) < 0) { - errno = ENOMEM; - return -1; + return -ENOMEM; } free(*argstr); *argstr = nstr; @@ -332,8 +330,7 @@ static int __add_int_argument(char **argstr, char *tok, int arg, bool allow_zero if (arg < 0 || (!arg && !allow_zero)) return 0; if (asprintf(&nstr, "%s,%s=%d", *argstr, tok, arg) < 0) { - errno = ENOMEM; - return -1; + return -ENOMEM; } free(*argstr); *argstr = nstr; @@ -348,8 +345,7 @@ static int __add_int_or_minus_one_argument(char **argstr, char *tok, int arg) if (arg < -1) return 0; if (asprintf(&nstr, "%s,%s=%d", *argstr, tok, arg) < 0) { - errno = ENOMEM; - return -1; + return -ENOMEM; } free(*argstr); *argstr = nstr; @@ -364,8 +360,7 @@ static int __add_argument(char **argstr, const char *tok, const char *arg) if (!arg || arg[0] == '\0' || !strcmp(arg, "none")) return 0; if (asprintf(&nstr, "%s,%s=%s", *argstr, tok, arg) < 0) { - errno = ENOMEM; - return -1; + return -ENOMEM; } free(*argstr); *argstr = nstr; @@ -591,23 +586,20 @@ static int build_options(nvme_host_t h, nvme_ctrl_t c, char **argstr) if (!transport) { nvme_msg(h->r, LOG_ERR, "need a transport (-t) argument\n"); - errno = ENVME_CONNECT_TARG; - return -1; + return -ENVME_CONNECT_TARG; } if (strncmp(transport, "loop", 4)) { if (!nvme_ctrl_get_traddr(c)) { nvme_msg(h->r, LOG_ERR, "need a address (-a) argument\n"); - errno = ENVME_CONNECT_AARG; - return -1; + return -ENVME_CONNECT_AARG; } } /* always specify nqn as first arg - this will init the string */ if (asprintf(argstr, "nqn=%s", nvme_ctrl_get_subsysnqn(c)) < 0) { - errno = ENOMEM; - return -1; + return -ENOMEM; } if (!strcmp(nvme_ctrl_get_subsysnqn(c), NVME_DISC_SUBSYS_NAME)) { @@ -629,10 +621,8 @@ static int build_options(nvme_host_t h, nvme_ctrl_t c, char **argstr) if (cfg->tls) { ret = __nvme_import_keys_from_config(h, c, &keyring_id, &key_id); - if (ret) { - errno = -ret; - return -1; - } + if (ret) + return ret; if (key_id == 0) { if (cfg->tls_configured_key) @@ -950,8 +940,7 @@ int nvmf_add_ctrl(nvme_host_t h, nvme_ctrl_t c, if (app && strcmp(app, root_app)) { nvme_msg(h->r, LOG_INFO, "skip %s, not managed by %s\n", nvme_subsystem_get_nqn(s), root_app); - errno = ENVME_CONNECT_IGNORED; - return -1; + return -ENVME_CONNECT_IGNORED; } } @@ -959,11 +948,9 @@ int nvmf_add_ctrl(nvme_host_t h, nvme_ctrl_t c, if (traddr_is_hostname(h->r, c)) { char *traddr = c->traddr; - c->traddr = hostname2traddr(h->r, traddr); - if (!c->traddr) { + if (hostname2traddr(h->r, traddr, &c->traddr)) { c->traddr = traddr; - errno = ENVME_CONNECT_TRADDR; - return -1; + return -ENVME_CONNECT_TRADDR; } free(traddr); } @@ -973,10 +960,8 @@ int nvmf_add_ctrl(nvme_host_t h, nvme_ctrl_t c, return ret; ret = __nvmf_add_ctrl(h->r, argstr); - if (ret < 0) { - errno = -ret; - return -1; - } + if (ret < 0) + return ret; nvme_msg(h->r, LOG_INFO, "nvme%d: %s connected\n", ret, nvme_ctrl_get_subsysnqn(c)); @@ -993,18 +978,17 @@ int nvmf_connect_ctrl(nvme_ctrl_t c) return ret; ret = __nvmf_add_ctrl(c->s->h->r, argstr); - if (ret < 0) { - errno = -ret; - return -1; - } + if (ret < 0) + return ret; return 0; } -nvme_ctrl_t nvmf_connect_disc_entry(nvme_host_t h, - struct nvmf_disc_log_entry *e, - const struct nvme_fabrics_config *cfg, - bool *discover) +int nvmf_connect_disc_entry(nvme_host_t h, + struct nvmf_disc_log_entry *e, + const struct nvme_fabrics_config *cfg, + bool *discover, + nvme_ctrl_t *cp) { const char *transport; char *traddr = NULL, *trsvcid = NULL; @@ -1024,8 +1008,7 @@ nvme_ctrl_t nvmf_connect_disc_entry(nvme_host_t h, nvme_msg(h->r, LOG_ERR, "skipping unsupported adrfam %d\n", e->adrfam); - errno = EINVAL; - return NULL; + return -EINVAL; } break; case NVMF_TRTYPE_FC: @@ -1037,8 +1020,7 @@ nvme_ctrl_t nvmf_connect_disc_entry(nvme_host_t h, nvme_msg(h->r, LOG_ERR, "skipping unsupported adrfam %d\n", e->adrfam); - errno = EINVAL; - return NULL; + return -EINVAL; } break; case NVMF_TRTYPE_LOOP: @@ -1047,8 +1029,7 @@ nvme_ctrl_t nvmf_connect_disc_entry(nvme_host_t h, default: nvme_msg(h->r, LOG_ERR, "skipping unsupported transport %d\n", e->trtype); - errno = EINVAL; - return NULL; + return -EINVAL; } transport = nvmf_trtype_str(e->trtype); @@ -1056,14 +1037,13 @@ nvme_ctrl_t nvmf_connect_disc_entry(nvme_host_t h, nvme_msg(h->r, LOG_DEBUG, "lookup ctrl " "(transport: %s, traddr: %s, trsvcid %s)\n", transport, traddr, trsvcid); - c = nvme_create_ctrl(h->r, e->subnqn, transport, traddr, - cfg->host_traddr, cfg->host_iface, trsvcid); - if (!c) { + ret = nvme_create_ctrl(h->r, e->subnqn, transport, traddr, + cfg->host_traddr, cfg->host_iface, trsvcid, &c); + if (!ret) { nvme_msg(h->r, LOG_DEBUG, "skipping discovery entry, " "failed to allocate %s controller with traddr %s\n", transport, traddr); - errno = ENOMEM; - return NULL; + return ret; } switch (e->subtype) { @@ -1091,8 +1071,7 @@ nvme_ctrl_t nvmf_connect_disc_entry(nvme_host_t h, if (nvme_ctrl_is_discovered(c)) { nvme_free_ctrl(c); - errno = EAGAIN; - return NULL; + return -EAGAIN; } if (e->treq & NVMF_TREQ_DISABLE_SQFLOW && @@ -1104,21 +1083,24 @@ nvme_ctrl_t nvmf_connect_disc_entry(nvme_host_t h, c->cfg.tls = true; ret = nvmf_add_ctrl(h, c, cfg); - if (!ret) - return c; + if (!ret) { + *cp = c; + return 0; + } - if (errno == EINVAL && c->cfg.disable_sqflow) { - errno = 0; + if (ret == EINVAL && c->cfg.disable_sqflow) { /* disable_sqflow is unrecognized option on older kernels */ nvme_msg(h->r, LOG_INFO, "failed to connect controller, " "retry with disabling SQ flow control\n"); c->cfg.disable_sqflow = false; ret = nvmf_add_ctrl(h, c, cfg); - if (!ret) - return c; + if (!ret) { + *cp = c; + return 0; + } } nvme_free_ctrl(c); - return NULL; + return -ENOENT; } /* @@ -1128,11 +1110,11 @@ nvme_ctrl_t nvmf_connect_disc_entry(nvme_host_t h, */ #define DISCOVERY_HEADER_LEN 20 -static struct nvmf_discovery_log *nvme_discovery_log( - const struct nvme_get_discovery_args *args) +static int nvme_discovery_log(const struct nvme_get_discovery_args *args, + struct nvmf_discovery_log **logp) { struct nvmf_discovery_log *log; - int retries = 0; + int retries = 0, err; const char *name = nvme_ctrl_get_name(args->c); uint64_t genctr, numrec; nvme_link_t l = nvme_ctrl_get_link(args->c); @@ -1152,18 +1134,18 @@ static struct nvmf_discovery_log *nvme_discovery_log( if (!log) { nvme_msg(l->root, LOG_ERR, "could not allocate memory for discovery log header\n"); - errno = ENOMEM; - return NULL; + return -ENOMEM; } nvme_msg(l->root, LOG_DEBUG, "%s: get header (try %d/%d)\n", name, retries, args->max_retries); log_args.log = log; log_args.len = DISCOVERY_HEADER_LEN; - if (nvme_get_log_page(l, NVME_LOG_PAGE_PDU_SIZE, &log_args)) { + err = nvme_get_log_page(l, NVME_LOG_PAGE_PDU_SIZE, &log_args); + if (err) { nvme_msg(l->root, LOG_INFO, "%s: discover try %d/%d failed, error %d\n", - name, retries, args->max_retries, errno); + name, retries, args->max_retries, err); goto out_free_log; } @@ -1182,8 +1164,7 @@ static struct nvmf_discovery_log *nvme_discovery_log( if (!log) { nvme_msg(l->root, LOG_ERR, "could not alloc memory for discovery log page\n"); - errno = ENOMEM; - return NULL; + return -ENOMEM; } nvme_msg(l->root, LOG_DEBUG, @@ -1193,10 +1174,11 @@ static struct nvmf_discovery_log *nvme_discovery_log( log_args.lpo = sizeof(*log); log_args.log = log->entries; log_args.len = entries_size; - if (nvme_get_log_page(l, NVME_LOG_PAGE_PDU_SIZE, &log_args)) { + err = nvme_get_log_page(l, NVME_LOG_PAGE_PDU_SIZE, &log_args); + if (err) { nvme_msg(l->root, LOG_INFO, "%s: discover try %d/%d failed, error %d\n", - name, retries, args->max_retries, errno); + name, retries, args->max_retries, err); goto out_free_log; } @@ -1209,10 +1191,11 @@ static struct nvmf_discovery_log *nvme_discovery_log( log_args.lpo = 0; log_args.log = log; log_args.len = DISCOVERY_HEADER_LEN; - if (nvme_get_log_page(l, NVME_LOG_PAGE_PDU_SIZE, &log_args)) { + err = nvme_get_log_page(l, NVME_LOG_PAGE_PDU_SIZE, &log_args); + if (err) { nvme_msg(l->root, LOG_INFO, "%s: discover try %d/%d failed, error %d\n", - name, retries, args->max_retries, errno); + name, retries, args->max_retries, err); goto out_free_log; } } while (genctr != le64_to_cpu(log->genctr) && @@ -1220,20 +1203,21 @@ static struct nvmf_discovery_log *nvme_discovery_log( if (genctr != le64_to_cpu(log->genctr)) { nvme_msg(l->root, LOG_INFO, "%s: discover genctr mismatch\n", name); - errno = EAGAIN; + err = -EAGAIN; } else if (numrec != le64_to_cpu(log->numrec)) { nvme_msg(l->root, LOG_INFO, "%s: numrec changed unexpectedly " "from %" PRIu64 " to %" PRIu64 "\n", name, numrec, le64_to_cpu(log->numrec)); - errno = EBADSLT; + err = -EBADSLT; } else { - return log; + *logp = log; + return 0; } out_free_log: free(log); - return NULL; + return err; } static void sanitize_discovery_log_entry(struct nvmf_disc_log_entry *e) @@ -1252,22 +1236,25 @@ int nvmf_get_discovery_log(nvme_ctrl_t c, struct nvmf_discovery_log **logp, .lsp = NVMF_LOG_DISC_LSP_NONE, }; - *logp = nvmf_get_discovery_wargs(&args); - return *logp ? 0 : -1; + + return nvmf_get_discovery_wargs(&args, logp); } -struct nvmf_discovery_log *nvmf_get_discovery_wargs(struct nvme_get_discovery_args *args) +int nvmf_get_discovery_wargs(struct nvme_get_discovery_args *args, + struct nvmf_discovery_log **logp) { struct nvmf_discovery_log *log; + int err; - log = nvme_discovery_log(args); - if (!log) - return NULL; + err = nvme_discovery_log(args, &log); + if (err) + return err; for (int i = 0; i < le64_to_cpu(log->numrec); i++) sanitize_discovery_log_entry(&log->entries[i]); - return log; + *logp = log; + return 0; } static int uuid_from_device_tree(char *system_uuid) @@ -1632,40 +1619,35 @@ static int nvmf_dim(nvme_ctrl_t c, enum nvmf_dim_tas tas, __u8 trtype, nvme_msg(r, LOG_ERR, "%s: failed to perform DIM. subsystem undefined.\n", c->name); - errno = EINVAL; - return -1; + return -EINVAL; } if (!c->s->h) { nvme_msg(r, LOG_ERR, "%s: failed to perform DIM. host undefined.\n", c->name); - errno = EINVAL; - return -1; + return -EINVAL; } if (!c->s->h->hostid) { nvme_msg(r, LOG_ERR, "%s: failed to perform DIM. hostid undefined.\n", c->name); - errno = EINVAL; - return -1; + return -EINVAL; } if (!c->s->h->hostnqn) { nvme_msg(r, LOG_ERR, "%s: failed to perform DIM. hostnqn undefined.\n", c->name); - errno = EINVAL; - return -1; + return -EINVAL; } if (strcmp(c->transport, "tcp")) { nvme_msg(r, LOG_ERR, "%s: DIM only supported for TCP connections.\n", c->name); - errno = EINVAL; - return -1; + return -EINVAL; } /* Register one Discovery Information Entry (DIE) of size TEL */ @@ -1674,8 +1656,7 @@ static int nvmf_dim(nvme_ctrl_t c, enum nvmf_dim_tas tas, __u8 trtype, dim = (struct nvmf_dim_data *)calloc(1, tdl); if (!dim) { - errno = ENOMEM; - return -1; + return -ENOMEM; } dim->tdl = cpu_to_le32(tdl); @@ -1690,7 +1671,7 @@ static int nvmf_dim(nvme_ctrl_t c, enum nvmf_dim_tas tas, __u8 trtype, ret = get_entity_name(dim->ename, sizeof(dim->ename)); if (ret <= 0) nvme_msg(r, LOG_INFO, "%s: Failed to retrieve ENAME. %s.\n", - c->name, strerror(errno)); + c->name, strerror(ret)); ret = get_entity_version(dim->ever, sizeof(dim->ever)); if (ret <= 0) @@ -1759,10 +1740,8 @@ static int nvme_fetch_cntrltype_dctype_from_id(nvme_ctrl_t c) int ret; id = __nvme_alloc(sizeof(*id)); - if (!id) { - errno = ENOMEM; - return -1; - } + if (!id) + return -ENOMEM; ret = nvme_ctrl_identify(c, id); if (ret) @@ -1795,10 +1774,8 @@ bool nvmf_is_registration_supported(nvme_ctrl_t c) int nvmf_register_ctrl(nvme_ctrl_t c, enum nvmf_dim_tas tas, __u32 *result) { - if (!nvmf_is_registration_supported(c)) { - errno = ENOTSUP; - return -1; - } + if (!nvmf_is_registration_supported(c)) + return -ENOTSUP; /* We're registering our source address with the DC. To do * that, we can simply send an empty string. This tells the DC @@ -1836,7 +1813,7 @@ static char *unescape_uri(const char *str, int len) return dst; } -struct nvme_fabrics_uri *nvme_parse_uri(const char *str) +int nvme_parse_uri(const char *str, struct nvme_fabrics_uri **urip) { struct nvme_fabrics_uri *uri; _cleanup_free_ char *scheme = NULL; @@ -1861,20 +1838,18 @@ struct nvme_fabrics_uri *nvme_parse_uri(const char *str) uri = calloc(1, sizeof(struct nvme_fabrics_uri)); if (!uri) - return NULL; + return -ENOMEM; if (sscanf(str, "%m[^:/]://%m[^/?#]%ms", &scheme, &authority, &path) < 2) { nvme_free_uri(uri); - errno = EINVAL; - return NULL; + return -EINVAL; } if (sscanf(scheme, "%m[^+]+%ms", &uri->scheme, &uri->protocol) < 1) { nvme_free_uri(uri); - errno = EINVAL; - return NULL; + return -EINVAL; } /* split userinfo */ @@ -1892,8 +1867,7 @@ struct nvme_fabrics_uri *nvme_parse_uri(const char *str) if (sscanf(host, "%m[^:]:%d", &h, &uri->port) < 1) { nvme_free_uri(uri); - errno = EINVAL; - return NULL; + return -EINVAL; } uri->host = unescape_uri(h, 0); } @@ -1932,7 +1906,8 @@ struct nvme_fabrics_uri *nvme_parse_uri(const char *str) } } - return uri; + *urip = uri; + return 0; } void nvme_free_uri(struct nvme_fabrics_uri *uri) diff --git a/src/nvme/fabrics.h b/src/nvme/fabrics.h index 4c84bd32f..01d3db6bd 100644 --- a/src/nvme/fabrics.h +++ b/src/nvme/fabrics.h @@ -219,7 +219,7 @@ void nvmf_update_config(nvme_ctrl_t c, const struct nvme_fabrics_config *cfg); * into the topology using @h as parent. * @c must be initialized and not connected to the topology. * - * Return: 0 on success; on failure errno is set and -1 is returned. + * Return: 0 on success, or an error code on failure. */ int nvmf_add_ctrl(nvme_host_t h, nvme_ctrl_t c, const struct nvme_fabrics_config *cfg); @@ -231,14 +231,14 @@ int nvmf_add_ctrl(nvme_host_t h, nvme_ctrl_t c, * Issues a 'connect' command to the NVMe-oF controller. * @c must be initialized and not connected to the topology. * - * Return: 0 on success; on failure errno is set and -1 is returned. + * Return: 0 on success, or an error code on failure. */ int nvmf_connect_ctrl(nvme_ctrl_t c); /** * nvmf_get_discovery_log() - Return the discovery log page * @c: Discovery controller to use - * @logp: Pointer to the log page to be returned + * @logp: Log page object to return * @max_retries: Number of retries in case of failure * * The memory allocated for the log page and returned in @logp @@ -246,7 +246,7 @@ int nvmf_connect_ctrl(nvme_ctrl_t c); * * Note: Consider using nvmf_get_discovery_wargs() instead. * - * Return: 0 on success; on failure -1 is returned and errno is set + * Return: 0 on success, or an error code on failure. */ int nvmf_get_discovery_log(nvme_ctrl_t c, struct nvmf_discovery_log **logp, int max_retries); @@ -272,6 +272,7 @@ struct nvme_get_discovery_args { /** * nvmf_get_discovery_wargs() - Get the discovery log page with args * @args: Argument structure + * @log: Discovery log page object to return * * This function is similar to nvmf_get_discovery_log(), but * takes an extensible @args parameter. @args provides more @@ -281,10 +282,10 @@ struct nvme_get_discovery_args { * and returns the DLP. The memory allocated for the returned * DLP must be freed by the caller using free(). * - * Return: Pointer to the discovery log page (to be freed). NULL - * on failure and errno is set. + * Return: 0 on success, or an error code on failure. */ -struct nvmf_discovery_log *nvmf_get_discovery_wargs(struct nvme_get_discovery_args *args); +int nvmf_get_discovery_wargs(struct nvme_get_discovery_args *args, + struct nvmf_discovery_log **log); /** * nvmf_hostnqn_generate() - Generate a machine specific host nqn @@ -343,12 +344,15 @@ char *nvmf_hostid_from_file(); * @e: Discovery log page entry * @defcfg: Default configuration to be used for the new controller * @discover: Set to 'true' if the new controller is a discovery controller + * @c: crtl object to return * - * Return: Pointer to the new controller + * Return: 0 on success, or an error code on failure. */ -nvme_ctrl_t nvmf_connect_disc_entry(nvme_host_t h, - struct nvmf_disc_log_entry *e, - const struct nvme_fabrics_config *defcfg, bool *discover); +int nvmf_connect_disc_entry(nvme_host_t h, + struct nvmf_disc_log_entry *e, + const struct nvme_fabrics_config *defcfg, + bool *discover, + nvme_ctrl_t *c); /** * nvmf_is_registration_supported - check whether registration can be performed. @@ -376,13 +380,14 @@ bool nvmf_is_registration_supported(nvme_ctrl_t c); * Perform registration task with a Discovery Controller (DC). Three * tasks are supported: register, deregister, and registration update. * - * Return: 0 on success; on failure -1 is returned and errno is set + * Return: 0 on success, or an error code on failure. */ int nvmf_register_ctrl(nvme_ctrl_t c, enum nvmf_dim_tas tas, __u32 *result); /** * nvme_parse_uri() - Parse the URI string * @str: URI string + * @uri: URI object to return * * Parse the URI string as defined in the NVM Express Boot Specification. * Supported URI elements looks as follows: @@ -392,7 +397,7 @@ int nvmf_register_ctrl(nvme_ctrl_t c, enum nvmf_dim_tas tas, __u32 *result); * Return: &nvme_fabrics_uri structure on success; NULL on failure with errno * set. */ -struct nvme_fabrics_uri *nvme_parse_uri(const char *str); +int nvme_parse_uri(const char *str, struct nvme_fabrics_uri **uri); /** * nvme_free_uri() - Free the URI structure diff --git a/src/nvme/ioctl.c b/src/nvme/ioctl.c index 40a2e575f..63afaab05 100644 --- a/src/nvme/ioctl.c +++ b/src/nvme/ioctl.c @@ -37,12 +37,10 @@ static int nvme_verify_chr(nvme_link_t l) int err = fstat(l->fd, &nvme_stat); if (err < 0) - return errno; + return -errno; - if (!S_ISCHR(nvme_stat.st_mode)) { - errno = ENOTBLK; - return -1; - } + if (!S_ISCHR(nvme_stat.st_mode)) + return -ENOTBLK; return 0; } @@ -53,7 +51,10 @@ int nvme_subsystem_reset(nvme_link_t l) ret = nvme_verify_chr(l); if (ret) return ret; - return ioctl(l->fd, NVME_IOCTL_SUBSYS_RESET); + ret = ioctl(l->fd, NVME_IOCTL_SUBSYS_RESET); + if (ret < 0) + return -errno; + return ret; } int nvme_ctrl_reset(nvme_link_t l) @@ -63,7 +64,10 @@ int nvme_ctrl_reset(nvme_link_t l) ret = nvme_verify_chr(l); if (ret) return ret; - return ioctl(l->fd, NVME_IOCTL_RESET); + ret = ioctl(l->fd, NVME_IOCTL_RESET); + if (ret < 0) + return -errno; + return ret; } int nvme_ns_rescan(nvme_link_t l) @@ -73,14 +77,19 @@ int nvme_ns_rescan(nvme_link_t l) ret = nvme_verify_chr(l); if (ret) return ret; - return ioctl(l->fd, NVME_IOCTL_RESCAN); + ret = ioctl(l->fd, NVME_IOCTL_RESCAN); + if (ret < 0) + return -errno; + return ret; } int nvme_get_nsid(nvme_link_t l, __u32 *nsid) { errno = 0; *nsid = ioctl(l->fd, NVME_IOCTL_ID); - return -1 * (errno != 0); + if (errno) + return -errno; + return 0; } __attribute__((weak)) @@ -92,6 +101,8 @@ int nvme_submit_passthru64(nvme_link_t l, unsigned long ioctl_cmd, if (err >= 0 && result) *result = cmd->result; + if (err < 0) + return -errno; return err; } @@ -103,6 +114,8 @@ int nvme_submit_passthru(nvme_link_t l, unsigned long ioctl_cmd, if (err >= 0 && result) *result = cmd->result; + if (err < 0) + return -errno; return err; } @@ -197,8 +210,7 @@ int nvme_submit_admin_passthru(nvme_link_t l, struct nvme_passthru_cmd *cmd, __u cmd->cdw14, cmd->cdw15, cmd->data_len, (void*)cmd->addr, cmd->metadata_len, (void*)cmd->metadata, cmd->timeout_ms, result); default: - errno = ENOTSUP; - return -1; + return -ENOTSUP; } } @@ -289,10 +301,9 @@ int nvme_identify(nvme_link_t l, struct nvme_identify_args *args) .timeout_ms = args->timeout, }; - if (args->args_size < sizeof(*args)) { - errno = EINVAL; - return -1; - } + if (args->args_size < sizeof(*args)) + return -EINVAL; + return nvme_submit_admin_passthru(l, &cmd, args->result); } @@ -326,10 +337,9 @@ int nvme_get_log(nvme_link_t l, struct nvme_get_log_args *args) .timeout_ms = args->timeout, }; - if (args->args_size < sizeof(struct nvme_get_log_args)) { - errno = EINVAL; - return -1; - } + if (args->args_size < sizeof(struct nvme_get_log_args)) + return -EINVAL; + return nvme_submit_admin_passthru(l, &cmd, args->result); } @@ -375,8 +385,10 @@ static void nvme_uring_cmd_probe() static int nvme_uring_cmd_setup(struct io_uring *ring) { - return io_uring_queue_init(NVME_URING_ENTRIES, ring, - IORING_SETUP_SQE128 | IORING_SETUP_CQE32); + if (io_uring_queue_init(NVME_URING_ENTRIES, ring, + IORING_SETUP_SQE128 | IORING_SETUP_CQE32)) + return -errno; + return 0; } static void nvme_uring_cmd_exit(struct io_uring *ring) @@ -406,10 +418,8 @@ static int nvme_uring_cmd_admin_passthru_async(nvme_link_t l, struct io_uring *r NVME_SET(!!args->ot, LOG_CDW14_OT) | NVME_SET(args->csi, LOG_CDW14_CSI); - if (args->args_size < sizeof(struct nvme_get_log_args)) { - errno = EINVAL; - return -1; - } + if (args->args_size < sizeof(struct nvme_get_log_args)) + return -EINVAL; sqe = io_uring_get_sqe(ring); if (!sqe) @@ -433,10 +443,8 @@ static int nvme_uring_cmd_admin_passthru_async(nvme_link_t l, struct io_uring *r sqe->user_data = (__u64)(uintptr_t)args; ret = io_uring_submit(ring); - if (ret < 0) { - errno = -ret; - return -1; - } + if (ret < 0) + return -errno; return 0; } @@ -449,10 +457,8 @@ static int nvme_uring_cmd_wait_complete(struct io_uring *ring, int n) for (i = 0; i < n; i++) { ret = io_uring_wait_cqe(ring, &cqe); - if (ret) { - errno = -ret; + if (ret) return -1; - } if (cqe->res) { args = (struct nvme_get_log_args *)cqe->user_data; @@ -490,8 +496,9 @@ int nvme_get_log_page(nvme_link_t l, __u32 xfer_len, struct nvme_get_log_args *a if (fstat(l->fd, &st) == 0 && S_ISCHR(st.st_mode)) { use_uring = true; - if (nvme_uring_cmd_setup(&ring)) - return -1; + ret = nvme_uring_cmd_setup(&ring); + if (ret) + return ret; } } #endif @@ -552,10 +559,8 @@ int nvme_get_log_page(nvme_link_t l, __u32 xfer_len, struct nvme_get_log_args *a static int read_ana_chunk(nvme_link_t l, enum nvme_log_ana_lsp lsp, bool rae, __u8 *log, __u8 **read, __u8 *to_read, __u8 *log_end) { - if (to_read > log_end) { - errno = ENOSPC; - return -1; - } + if (to_read > log_end) + return -ENOSPC; while (*read < to_read) { __u32 len = min_t(__u32, log_end - *read, NVME_LOG_PAGE_PDU_SIZE); @@ -591,7 +596,7 @@ static int try_read_ana(nvme_link_t l, enum nvme_log_ana_lsp lsp, bool rae, * and the computed length was inaccurate. * Have the caller check chgcnt and retry. */ - *may_retry = errno == ENOSPC; + *may_retry = ret == -ENOSPC; return ret; } @@ -607,7 +612,7 @@ static int try_read_ana(nvme_link_t l, enum nvme_log_ana_lsp lsp, bool rae, ret = read_ana_chunk(l, lsp, rae, (__u8 *)log, &read, *to_read, log_end); if (ret) { - *may_retry = errno == ENOSPC; + *may_retry = ret == -ENOSPC; return ret; } } @@ -627,10 +632,8 @@ int nvme_get_ana_log_atomic(nvme_link_t l, bool rgo, bool rae, unsigned int retr __u8 *to_read; int ret; - if (!retries) { - errno = EINVAL; - return -1; - } + if (!retries) + return -EINVAL; to_read = (__u8 *)log->descs; ret = read_ana_chunk(l, lsp, rae, @@ -670,8 +673,7 @@ int nvme_get_ana_log_atomic(nvme_link_t l, bool rgo, bool rae, unsigned int retr } } while (--retries); - errno = EAGAIN; - return -1; + return -EAGAIN; } int nvme_set_features(nvme_link_t l, struct nvme_set_features_args *args) @@ -693,10 +695,9 @@ int nvme_set_features(nvme_link_t l, struct nvme_set_features_args *args) .cdw15 = args->cdw15, .timeout_ms = args->timeout, }; - if (args->args_size < sizeof(*args)) { - errno = EINVAL; - return -1; - } + if (args->args_size < sizeof(*args)) + return -EINVAL; + return nvme_submit_admin_passthru(l, &cmd, args->result); } @@ -1011,10 +1012,9 @@ int nvme_get_features(nvme_link_t l, struct nvme_get_features_args *args) .timeout_ms = args->timeout, }; - if (args->args_size < sizeof(*args)) { - errno = EINVAL; - return -1; - } + if (args->args_size < sizeof(*args)) + return -EINVAL; + return nvme_submit_admin_passthru(l, &cmd, args->result); } @@ -1412,10 +1412,8 @@ int nvme_format_nvm(nvme_link_t l, struct nvme_format_nvm_args *args) const size_t size_v2 = sizeof_args(struct nvme_format_nvm_args, lbafu, __u64); __u32 cdw10; - if (args->args_size < size_v1 || args->args_size > size_v2) { - errno = EINVAL; - return -1; - } + if (args->args_size < size_v1 || args->args_size > size_v2) + return -EINVAL; cdw10 = NVME_SET(args->lbaf, FORMAT_CDW10_LBAF) | NVME_SET(args->mset, FORMAT_CDW10_MSET) | @@ -1445,10 +1443,8 @@ int nvme_ns_mgmt(nvme_link_t l, struct nvme_ns_mgmt_args *args) __u32 cdw10 = NVME_SET(args->sel, NAMESPACE_MGMT_CDW10_SEL); __u32 cdw11 = NVME_SET(args->csi, NAMESPACE_MGMT_CDW11_CSI); - if (args->args_size < size_v1 || args->args_size > size_v2) { - errno = EINVAL; - return -1; - } + if (args->args_size < size_v1 || args->args_size > size_v2) + return -EINVAL; struct nvme_passthru_cmd cmd = { .nsid = args->nsid, @@ -1486,10 +1482,9 @@ int nvme_ns_attach(nvme_link_t l, struct nvme_ns_attach_args *args) .timeout_ms = args->timeout, }; - if (args->args_size < sizeof(*args)) { - errno = EINVAL; - return -1; - } + if (args->args_size < sizeof(*args)) + return -EINVAL; + return nvme_submit_admin_passthru(l, &cmd, args->result); } @@ -1507,20 +1502,14 @@ int nvme_fw_download(nvme_link_t l, struct nvme_fw_download_args *args) .timeout_ms = args->timeout, }; - if (args->args_size < sizeof(*args)) { - errno = EINVAL; - return -1; - } + if (args->args_size < sizeof(*args)) + return -EINVAL; - if ((args->data_len & 0x3) || (!args->data_len)) { - errno = EINVAL; - return -1; - } + if ((args->data_len & 0x3) || (!args->data_len)) + return -EINVAL; - if (args->offset & 0x3) { - errno = EINVAL; - return -1; - } + if (args->offset & 0x3) + return -EINVAL; return nvme_submit_admin_passthru(l, &cmd, args->result); } @@ -1537,10 +1526,9 @@ int nvme_fw_commit(nvme_link_t l, struct nvme_fw_commit_args *args) .timeout_ms = args->timeout, }; - if (args->args_size < sizeof(*args)) { - errno = EINVAL; - return -1; - } + if (args->args_size < sizeof(*args)) + return -EINVAL; + return nvme_submit_admin_passthru(l, &cmd, args->result); } @@ -1562,10 +1550,9 @@ int nvme_security_send(nvme_link_t l, struct nvme_security_send_args *args) .timeout_ms = args->timeout, }; - if (args->args_size < sizeof(*args)) { - errno = EINVAL; - return -1; - } + if (args->args_size < sizeof(*args)) + return -EINVAL; + return nvme_submit_admin_passthru(l, &cmd, args->result); } @@ -1587,10 +1574,9 @@ int nvme_security_receive(nvme_link_t l, struct nvme_security_receive_args *args .timeout_ms = args->timeout, }; - if (args->args_size < sizeof(*args)) { - errno = EINVAL; - return -1; - } + if (args->args_size < sizeof(*args)) + return -EINVAL; + return nvme_submit_admin_passthru(l, &cmd, args->result); } @@ -1614,10 +1600,9 @@ int nvme_get_lba_status(nvme_link_t l, struct nvme_get_lba_status_args *args) .timeout_ms = args->timeout, }; - if (args->args_size < sizeof(*args)) { - errno = EINVAL; - return -1; - } + if (args->args_size < sizeof(*args)) + return -EINVAL; + return nvme_submit_admin_passthru(l, &cmd, args->result); } @@ -1639,11 +1624,10 @@ int nvme_directive_send(nvme_link_t l, struct nvme_directive_send_args *args) .timeout_ms = args->timeout, }; - if (args->args_size < sizeof(*args)) { - errno = EINVAL; - return -1; - } - return nvme_submit_admin_passthru(l, &cmd, args->result); + if (args->args_size < sizeof(*args)) + return -EINVAL; + + return nvme_submit_admin_passthru(l, &cmd, args->result); } int nvme_directive_send_id_endir(nvme_link_t l, __u32 nsid, bool endir, @@ -1686,10 +1670,9 @@ int nvme_directive_recv(nvme_link_t l, struct nvme_directive_recv_args *args) .timeout_ms = args->timeout, }; - if (args->args_size < sizeof(*args)) { - errno = EINVAL; - return -1; - } + if (args->args_size < sizeof(*args)) + return -EINVAL; + return nvme_submit_admin_passthru(l, &cmd, args->result); } @@ -1705,10 +1688,9 @@ int nvme_capacity_mgmt(nvme_link_t l, struct nvme_capacity_mgmt_args *args) .timeout_ms = args->timeout, }; - if (args->args_size < sizeof(*args)) { - errno = EINVAL; - return -1; - } + if (args->args_size < sizeof(*args)) + return -EINVAL; + return nvme_submit_admin_passthru(l, &cmd, args->result); } @@ -1726,10 +1708,9 @@ int nvme_lockdown(nvme_link_t l, struct nvme_lockdown_args *args) .timeout_ms = args->timeout, }; - if (args->args_size < sizeof(*args)) { - errno = EINVAL; - return -1; - } + if (args->args_size < sizeof(*args)) + return -EINVAL; + return nvme_submit_admin_passthru(l, &cmd, args->result); } @@ -1747,10 +1728,9 @@ int nvme_set_property(nvme_link_t l, struct nvme_set_property_args *args) .timeout_ms = args->timeout, }; - if (args->args_size < sizeof(*args)) { - errno = EINVAL; - return -1; - } + if (args->args_size < sizeof(*args)) + return -EINVAL; + return nvme_submit_admin_passthru(l, &cmd, args->result); } @@ -1766,10 +1746,9 @@ int nvme_get_property(nvme_link_t l, struct nvme_get_property_args *args) .timeout_ms = args->timeout, }; - if (args->args_size < sizeof(*args)) { - errno = EINVAL; - return -1; - } + if (args->args_size < sizeof(*args)) + return -EINVAL; + return nvme_submit_admin_passthru64(l, &cmd, args->value); } @@ -1779,10 +1758,8 @@ int nvme_sanitize_nvm(nvme_link_t l, struct nvme_sanitize_nvm_args *args) const size_t size_v2 = sizeof_args(struct nvme_sanitize_nvm_args, emvs, __u64); __u32 cdw10, cdw11; - if (args->args_size < size_v1 || args->args_size > size_v2) { - errno = EINVAL; - return -1; - } + if (args->args_size < size_v1 || args->args_size > size_v2) + return -EINVAL; cdw10 = NVME_SET(args->sanact, SANITIZE_CDW10_SANACT) | NVME_SET(!!args->ause, SANITIZE_CDW10_AUSE) | @@ -1816,10 +1793,9 @@ int nvme_dev_self_test(nvme_link_t l, struct nvme_dev_self_test_args *args) .timeout_ms = args->timeout, }; - if (args->args_size < sizeof(*args)) { - errno = EINVAL; - return -1; - } + if (args->args_size < sizeof(*args)) + return -EINVAL; + return nvme_submit_admin_passthru(l, &cmd, args->result); } @@ -1837,10 +1813,9 @@ int nvme_virtual_mgmt(nvme_link_t l, struct nvme_virtual_mgmt_args *args) .timeout_ms = args->timeout, }; - if (args->args_size < sizeof(*args)) { - errno = EINVAL; - return -1; - } + if (args->args_size < sizeof(*args)) + return -EINVAL; + return nvme_submit_admin_passthru(l, &cmd, args->result); } @@ -1910,8 +1885,7 @@ static int nvme_set_var_size_tags(__u32 *cmd_dw2, __u32 *cmd_dw3, __u32 *cmd_dw1 break; default: perror("Unsupported Protection Information Format"); - errno = EINVAL; - return -1; + return -EINVAL; } *cmd_dw2 = cdw2; @@ -1926,10 +1900,8 @@ int nvme_io(nvme_link_t l, struct nvme_io_args *args, __u8 opcode) const size_t size_v2 = sizeof_args(struct nvme_io_args, pif, __u64); __u32 cdw2, cdw3, cdw10, cdw11, cdw12, cdw13, cdw14, cdw15; - if (args->args_size < size_v1 || args->args_size > size_v2) { - errno = EINVAL; - return -1; - } + if (args->args_size < size_v1 || args->args_size > size_v2) + return -EINVAL; cdw10 = args->slba & 0xffffffff; cdw11 = args->slba >> 32; @@ -1946,10 +1918,8 @@ int nvme_io(nvme_link_t l, struct nvme_io_args *args, __u8 opcode) args->pif, args->sts, args->reftag_u64, - args->storage_tag)) { - errno = EINVAL; - return -1; - } + args->storage_tag)) + return -EINVAL; } struct nvme_passthru_cmd cmd = { @@ -1985,10 +1955,9 @@ int nvme_dsm(nvme_link_t l, struct nvme_dsm_args *args) .timeout_ms = args->timeout, }; - if (args->args_size < sizeof(*args)) { - errno = EINVAL; - return -1; - } + if (args->args_size < sizeof(*args)) + return -EINVAL; + return nvme_submit_io_passthru(l, &cmd, args->result); } @@ -1998,10 +1967,8 @@ int nvme_copy(nvme_link_t l, struct nvme_copy_args *args) const size_t size_v2 = sizeof_args(struct nvme_copy_args, ilbrt_u64, __u64); __u32 cdw3, cdw12, cdw14, data_len; - if (args->args_size < size_v1 || args->args_size > size_v2) { - errno = EINVAL; - return -1; - } + if (args->args_size < size_v1 || args->args_size > size_v2) + return -EINVAL; cdw12 = ((args->nr - 1) & 0xff) | ((args->format & 0xf) << 8) | ((args->prinfor & 0xf) << 12) | ((args->dtype & 0xf) << 20) | @@ -2062,10 +2029,9 @@ int nvme_resv_acquire(nvme_link_t l, struct nvme_resv_acquire_args *args) .timeout_ms = args->timeout, }; - if (args->args_size < sizeof(*args)) { - errno = EINVAL; - return -1; - } + if (args->args_size < sizeof(*args)) + return -EINVAL; + return nvme_submit_io_passthru(l, &cmd, args->result); } @@ -2088,10 +2054,9 @@ int nvme_resv_register(nvme_link_t l, struct nvme_resv_register_args *args) .timeout_ms = args->timeout, }; - if (args->args_size < sizeof(*args)) { - errno = EINVAL; - return -1; - } + if (args->args_size < sizeof(*args)) + return -EINVAL; + return nvme_submit_io_passthru(l, &cmd, args->result); } @@ -2111,10 +2076,9 @@ int nvme_resv_release(nvme_link_t l, struct nvme_resv_release_args *args) .timeout_ms = args->timeout, }; - if (args->args_size < sizeof(*args)) { - errno = EINVAL; - return -1; - } + if (args->args_size < sizeof(*args)) + return -EINVAL; + return nvme_submit_io_passthru(l, &cmd, args->result); } @@ -2130,10 +2094,9 @@ int nvme_resv_report(nvme_link_t l, struct nvme_resv_report_args *args) .timeout_ms = args->timeout, }; - if (args->args_size < sizeof(*args)) { - errno = EINVAL; - return -1; - } + if (args->args_size < sizeof(*args)) + return -EINVAL; + return nvme_submit_io_passthru(l, &cmd, args->result); } @@ -2152,10 +2115,8 @@ int nvme_io_mgmt_recv(nvme_link_t l, struct nvme_io_mgmt_recv_args *args) .timeout_ms = args->timeout, }; - if (args->args_size < sizeof(*args)) { - errno = EINVAL; - return -1; - } + if (args->args_size < sizeof(*args)) + return -EINVAL; return nvme_submit_io_passthru(l, &cmd, NULL); } @@ -2173,10 +2134,8 @@ int nvme_io_mgmt_send(nvme_link_t l, struct nvme_io_mgmt_send_args *args) .timeout_ms = args->timeout, }; - if (args->args_size < sizeof(*args)) { - errno = EINVAL; - return -1; - } + if (args->args_size < sizeof(*args)) + return -EINVAL; return nvme_submit_io_passthru(l, &cmd, NULL); } @@ -2200,10 +2159,9 @@ int nvme_zns_mgmt_send(nvme_link_t l, struct nvme_zns_mgmt_send_args *args) .timeout_ms = args->timeout, }; - if (args->args_size < sizeof(*args)) { - errno = EINVAL; - return -1; - } + if (args->args_size < sizeof(*args)) + return -EINVAL; + return nvme_submit_io_passthru(l, &cmd, args->result); } @@ -2228,10 +2186,9 @@ int nvme_zns_mgmt_recv(nvme_link_t l, struct nvme_zns_mgmt_recv_args *args) .timeout_ms = args->timeout, }; - if (args->args_size < sizeof(*args)) { - errno = EINVAL; - return -1; - } + if (args->args_size < sizeof(*args)) + return -EINVAL; + return nvme_submit_io_passthru(l, &cmd, args->result); } @@ -2241,10 +2198,8 @@ int nvme_zns_append(nvme_link_t l, struct nvme_zns_append_args *args) const size_t size_v2 = sizeof_args(struct nvme_zns_append_args, ilbrt_u64, __u64); __u32 cdw3, cdw10, cdw11, cdw12, cdw14, cdw15; - if (args->args_size < size_v1 || args->args_size > size_v2) { - errno = EINVAL; - return -1; - } + if (args->args_size < size_v1 || args->args_size > size_v2) + return -EINVAL; cdw10 = args->zslba & 0xffffffff; cdw11 = args->zslba >> 32; @@ -2290,10 +2245,8 @@ int nvme_dim_send(nvme_link_t l, struct nvme_dim_args *args) .timeout_ms = args->timeout, }; - if (args->args_size < sizeof(*args)) { - errno = EINVAL; - return -1; - } + if (args->args_size < sizeof(*args)) + return -EINVAL; return nvme_submit_admin_passthru(l, &cmd, args->result); } @@ -2308,10 +2261,8 @@ int nvme_lm_cdq(nvme_link_t l, struct nvme_lm_cdq_args *args) __u32 cdw11 = 0, data_len = 0, sz = 0; int err; - if (args->args_size < size_v1 || args->args_size > size_v2) { - errno = EINVAL; - return -1; - } + if (args->args_size < size_v1 || args->args_size > size_v2) + return -EINVAL; if (args->args_size == size_v1) sz = args->sz_u8; @@ -2336,10 +2287,8 @@ int nvme_lm_cdq(nvme_link_t l, struct nvme_lm_cdq_args *args) .timeout_ms = args->timeout, }; - if (args->args_size < sizeof(*args)) { - errno = EINVAL; - return -1; - } + if (args->args_size < sizeof(*args)) + return -EINVAL; err = nvme_submit_admin_passthru(l, &cmd, args->result); @@ -2361,10 +2310,8 @@ int nvme_lm_track_send(nvme_link_t l, struct nvme_lm_track_send_args *args) .timeout_ms = args->timeout, }; - if (args->args_size < sizeof(*args)) { - errno = EINVAL; - return -1; - } + if (args->args_size < sizeof(*args)) + return -EINVAL; return nvme_submit_admin_passthru(l, &cmd, args->result); } @@ -2401,10 +2348,8 @@ int nvme_lm_migration_send(nvme_link_t l, struct nvme_lm_migration_send_args *ar .timeout_ms = args->timeout, }; - if (args->args_size < sizeof(*args)) { - errno = EINVAL; - return -1; - } + if (args->args_size < sizeof(*args)) + return -EINVAL; return nvme_submit_admin_passthru(l, &cmd, args->result); } @@ -2435,10 +2380,8 @@ int nvme_lm_migration_recv(nvme_link_t l, struct nvme_lm_migration_recv_args *ar .timeout_ms = args->timeout, }; - if (args->args_size < sizeof(*args)) { - errno = EINVAL; - return -1; - } + if (args->args_size < sizeof(*args)) + return -EINVAL; return nvme_submit_admin_passthru(l, &cmd, args->result); } diff --git a/src/nvme/ioctl.h b/src/nvme/ioctl.h index a5b202e19..2518b5288 100644 --- a/src/nvme/ioctl.h +++ b/src/nvme/ioctl.h @@ -338,8 +338,8 @@ enum nvme_cmd_dword_fields { * * Uses NVME_IOCTL_ADMIN64_CMD for the ioctl request. * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_submit_admin_passthru64(nvme_link_t l, struct nvme_passthru_cmd64 *cmd, __u64 *result); @@ -371,8 +371,8 @@ int nvme_submit_admin_passthru64(nvme_link_t l, struct nvme_passthru_cmd64 *cmd, * * Known values for @opcode are defined in &enum nvme_admin_opcode. * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_admin_passthru64(nvme_link_t l, __u8 opcode, __u8 flags, __u16 rsvd, __u32 nsid, __u32 cdw2, __u32 cdw3, __u32 cdw10, __u32 cdw11, @@ -388,8 +388,8 @@ int nvme_admin_passthru64(nvme_link_t l, __u8 opcode, __u8 flags, __u16 rsvd, * * Uses NVME_IOCTL_ADMIN_CMD for the ioctl request. * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_submit_admin_passthru(nvme_link_t l, struct nvme_passthru_cmd *cmd, __u32 *result); @@ -421,8 +421,8 @@ int nvme_submit_admin_passthru(nvme_link_t l, struct nvme_passthru_cmd *cmd, * * Known values for @opcode are defined in &enum nvme_admin_opcode. * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_admin_passthru(nvme_link_t l, __u8 opcode, __u8 flags, __u16 rsvd, __u32 nsid, __u32 cdw2, __u32 cdw3, __u32 cdw10, __u32 cdw11, @@ -438,8 +438,8 @@ int nvme_admin_passthru(nvme_link_t l, __u8 opcode, __u8 flags, __u16 rsvd, * * Uses NVME_IOCTL_IO64_CMD for the ioctl request. * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_submit_io_passthru64(nvme_link_t l, struct nvme_passthru_cmd64 *cmd, __u64 *result); @@ -471,8 +471,8 @@ int nvme_submit_io_passthru64(nvme_link_t l, struct nvme_passthru_cmd64 *cmd, * * Known values for @opcode are defined in &enum nvme_io_opcode. * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_io_passthru64(nvme_link_t l, __u8 opcode, __u8 flags, __u16 rsvd, __u32 nsid, __u32 cdw2, __u32 cdw3, __u32 cdw10, __u32 cdw11, @@ -489,8 +489,8 @@ int nvme_io_passthru64(nvme_link_t l, __u8 opcode, __u8 flags, __u16 rsvd, * * Uses NVME_IOCTL_IO_CMD for the ioctl request. * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_submit_io_passthru(nvme_link_t l, struct nvme_passthru_cmd *cmd, __u32 *result); @@ -522,8 +522,8 @@ int nvme_submit_io_passthru(nvme_link_t l, struct nvme_passthru_cmd *cmd, * * Known values for @opcode are defined in &enum nvme_io_opcode. * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_io_passthru(nvme_link_t l, __u8 opcode, __u8 flags, __u16 rsvd, __u32 nsid, __u32 cdw2, __u32 cdw3, __u32 cdw10, __u32 cdw11, @@ -584,8 +584,8 @@ int nvme_get_nsid(nvme_link_t l, __u32 *nsid); * The Identify command returns a data buffer that describes information about * the NVM subsystem, the controller or the namespace(s). * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_identify(nvme_link_t l, struct nvme_identify_args *args); @@ -617,8 +617,8 @@ static inline int nvme_identify_cns_nsid(nvme_link_t l, enum nvme_identify_cns c * * See &struct nvme_id_ctrl for details on the data returned. * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline int nvme_identify_ctrl(nvme_link_t l, struct nvme_id_ctrl *id) { @@ -643,8 +643,8 @@ static inline int nvme_identify_ctrl(nvme_link_t l, struct nvme_id_ctrl *id) * * See &struct nvme_id_ns for details on the structure returned. * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline int nvme_identify_ns(nvme_link_t l, __u32 nsid, struct nvme_id_ns *ns) { @@ -658,8 +658,8 @@ static inline int nvme_identify_ns(nvme_link_t l, __u32 nsid, struct nvme_id_ns * @nsid: Namespace to identify * @ns: User space destination address to transfer the data * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline int nvme_identify_allocated_ns(nvme_link_t l, __u32 nsid, struct nvme_id_ns *ns) @@ -680,8 +680,8 @@ static inline int nvme_identify_allocated_ns(nvme_link_t l, __u32 nsid, * * See &struct nvme_ns_list for the definition of the returned structure. * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline int nvme_identify_active_ns_list(nvme_link_t l, __u32 nsid, struct nvme_ns_list *list) @@ -702,8 +702,8 @@ static inline int nvme_identify_active_ns_list(nvme_link_t l, __u32 nsid, * * See &struct nvme_ns_list for the definition of the returned structure. * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline int nvme_identify_allocated_ns_list(nvme_link_t l, __u32 nsid, struct nvme_ns_list *list) @@ -724,8 +724,8 @@ static inline int nvme_identify_allocated_ns_list(nvme_link_t l, __u32 nsid, * * See &struct nvme_ctrl_list for a definition of the structure returned. * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline int nvme_identify_ctrl_list(nvme_link_t l, __u16 cntid, struct nvme_ctrl_list *cntlist) @@ -795,8 +795,8 @@ static inline int nvme_identify_nsid_ctrl_list(nvme_link_t l, __u32 nsid, __u16 * * See &struct nvme_ns_id_desc for the definition of the returned structure. * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline int nvme_identify_ns_descs(nvme_link_t l, __u32 nsid, struct nvme_ns_id_desc *descs) @@ -818,8 +818,8 @@ static inline int nvme_identify_ns_descs(nvme_link_t l, __u32 nsid, * * See &struct nvme_id_nvmset_list for the definition of the returned structure. * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline int nvme_identify_nvmset_list(nvme_link_t l, __u16 nvmsetid, struct nvme_id_nvmset_list *nvmset) @@ -849,8 +849,8 @@ static inline int nvme_identify_nvmset_list(nvme_link_t l, __u16 nvmsetid, * * See &struct nvme_primary_ctrl_cap for the definition of the returned structure, @cap. * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline int nvme_identify_primary_ctrl(nvme_link_t l, __u16 cntid, struct nvme_primary_ctrl_cap *cap) @@ -885,8 +885,8 @@ static inline int nvme_identify_primary_ctrl(nvme_link_t l, __u16 cntid, * See &struct nvme_secondary_ctrls_list for a definition of the returned * structure. * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline int nvme_identify_secondary_ctrl_list(nvme_link_t l, __u16 cntid, struct nvme_secondary_ctrl_list *sc_list) @@ -920,8 +920,8 @@ static inline int nvme_identify_secondary_ctrl_list(nvme_link_t l, * See &struct nvme_id_ns_granularity_list for the definition of the returned * structure. * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline int nvme_identify_ns_granularity(nvme_link_t l, struct nvme_id_ns_granularity_list *gr_list) @@ -940,8 +940,8 @@ static inline int nvme_identify_ns_granularity(nvme_link_t l, * * See &struct nvme_id_uuid_list for the definition of the returned structure. * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline int nvme_identify_uuid(nvme_link_t l, struct nvme_id_uuid_list *uuid_list) { @@ -960,8 +960,8 @@ static inline int nvme_identify_uuid(nvme_link_t l, struct nvme_id_uuid_list *uu * An I/O Command Set specific Identify Namespace data structure is returned * for the namespace specified in @nsid. * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline int nvme_identify_ns_csi(nvme_link_t l, __u32 nsid, __u8 uuidx, enum nvme_csi csi, void *data) @@ -992,8 +992,8 @@ static inline int nvme_identify_ns_csi(nvme_link_t l, __u32 nsid, __u8 uuidx, * to the host for the controller processing the command. The specific Identify * Controller data structure to be returned is specified by @csi. * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline int nvme_identify_ctrl_csi(nvme_link_t l, enum nvme_csi csi, void *data) { @@ -1027,8 +1027,8 @@ static inline int nvme_identify_ctrl_csi(nvme_link_t l, enum nvme_csi csi, void * * See &struct nvme_ns_list for the definition of the returned structure. * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline int nvme_identify_active_ns_list_csi(nvme_link_t l, __u32 nsid, enum nvme_csi csi, struct nvme_ns_list *ns_list) @@ -1063,8 +1063,8 @@ static inline int nvme_identify_active_ns_list_csi(nvme_link_t l, __u32 nsid, * * See &struct nvme_ns_list for the definition of the returned structure. * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline int nvme_identify_allocated_ns_list_csi(nvme_link_t l, __u32 nsid, enum nvme_csi csi, struct nvme_ns_list *ns_list) @@ -1095,8 +1095,8 @@ static inline int nvme_identify_allocated_ns_list_csi(nvme_link_t l, __u32 nsid, * The I/O command set independent Identify namespace data structure for * the namespace identified with @ns is returned to the host. * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline int nvme_identify_independent_identify_ns(nvme_link_t l, __u32 nsid, struct nvme_id_independent_id_ns *ns) @@ -1116,8 +1116,8 @@ static inline int nvme_identify_independent_identify_ns(nvme_link_t l, __u32 nsi * Identify Namespace data structure for the specified User Data Format * index containing the namespace capabilities for the NVM Command Set. * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline int nvme_identify_ns_csi_user_data_format(nvme_link_t l, __u16 user_data_format, __u8 uuidx, @@ -1151,8 +1151,8 @@ static inline int nvme_identify_ns_csi_user_data_format(nvme_link_t l, * the specified User Data Format index containing the namespace * capabilities for the I/O Command Set specified in the CSI field. * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline int nvme_identify_iocs_ns_csi_user_data_format(nvme_link_t l, __u16 user_data_format, __u8 uuidx, @@ -1182,8 +1182,8 @@ static inline int nvme_identify_iocs_ns_csi_user_data_format(nvme_link_t l, * Return an identify controller data structure to the host of * processing controller. * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline int nvme_nvm_identify_ctrl(nvme_link_t l, struct nvme_id_ctrl_nvm *id) { @@ -1203,8 +1203,8 @@ static inline int nvme_nvm_identify_ctrl(nvme_link_t l, struct nvme_id_ctrl_nvm * See &struct nvme_identify_domain_attr for the definition of the * returned structure. * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline int nvme_identify_domain_list(nvme_link_t l, __u16 domid, struct nvme_id_domain_list *list) @@ -1231,8 +1231,8 @@ static inline int nvme_identify_domain_list(nvme_link_t l, __u16 domid, * @endgrp_id: Endurance group identifier * @list: Array of endurance group identifiers * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline int nvme_identify_endurance_group_list(nvme_link_t l, __u16 endgrp_id, struct nvme_id_endurance_group_list *list) @@ -1262,8 +1262,8 @@ static inline int nvme_identify_endurance_group_list(nvme_link_t l, __u16 endgrp * Retrieves list of the controller's supported io command set vectors. See * &struct nvme_id_iocs. * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline int nvme_identify_iocs(nvme_link_t l, __u16 cntlid, struct nvme_id_iocs *iocs) @@ -1290,8 +1290,8 @@ static inline int nvme_identify_iocs(nvme_link_t l, __u16 cntlid, * @nsid: Namespace to identify * @data: User space destination address to transfer the data * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline int nvme_zns_identify_ns(nvme_link_t l, __u32 nsid, struct nvme_zns_id_ns *data) @@ -1305,8 +1305,8 @@ static inline int nvme_zns_identify_ns(nvme_link_t l, __u32 nsid, * @l: Link handle * @id: User space destination address to transfer the data * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline int nvme_zns_identify_ctrl(nvme_link_t l, struct nvme_zns_id_ctrl *id) { @@ -1318,8 +1318,8 @@ static inline int nvme_zns_identify_ctrl(nvme_link_t l, struct nvme_zns_id_ctrl * @l: Link handle * @args: &struct nvme_get_log_args argument structure * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_get_log(nvme_link_t l, struct nvme_get_log_args *args); @@ -1329,8 +1329,8 @@ int nvme_get_log(nvme_link_t l, struct nvme_get_log_args *args); * @xfer_len: Max log transfer size per request to split the total. * @args: &struct nvme_get_log_args argument structure * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_get_log_page(nvme_link_t l, __u32 xfer_len, struct nvme_get_log_args *args); @@ -1393,8 +1393,8 @@ static inline int nvme_get_log_simple(nvme_link_t l, enum nvme_cmd_get_log_lid l * @rae: Retain asynchronous events * @log: Array of LID supported and Effects data structures * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline int nvme_get_log_supported_log_pages(nvme_link_t l, bool rae, struct nvme_supported_log_pages *log) @@ -1414,8 +1414,8 @@ static inline int nvme_get_log_supported_log_pages(nvme_link_t l, bool rae, * completed with error, or may report an error that is not specific to a * particular command. * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline int nvme_get_log_error(nvme_link_t l, unsigned int nr_entries, bool rae, struct nvme_error_log_page *err_log) @@ -1439,8 +1439,8 @@ static inline int nvme_get_log_error(nvme_link_t l, unsigned int nr_entries, boo * page on a per namespace basis, as indicated by bit 0 of the LPA field in the * Identify Controller data structure. * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline int nvme_get_log_smart(nvme_link_t l, __u32 nsid, bool rae, struct nvme_smart_log *smart_log) @@ -1459,8 +1459,8 @@ static inline int nvme_get_log_smart(nvme_link_t l, __u32 nsid, bool rae, * supported. The firmware revision is indicated as an ASCII string. The log * page also indicates the active slot number. * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline int nvme_get_log_fw_slot(nvme_link_t l, bool rae, struct nvme_firmware_slot *fw_log) @@ -1479,8 +1479,8 @@ static inline int nvme_get_log_fw_slot(nvme_link_t l, bool rae, * changed since the last time the namespace was identified, been added, or * deleted. * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline int nvme_get_log_changed_ns_list(nvme_link_t l, bool rae, struct nvme_ns_list *ns_log) @@ -1498,8 +1498,8 @@ static inline int nvme_get_log_changed_ns_list(nvme_link_t l, bool rae, * This log page describes the commands that the controller supports and the * effects of those commands on the state of the NVM subsystem. * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline int nvme_get_log_cmd_effects(nvme_link_t l, enum nvme_csi csi, struct nvme_cmd_effects_log *effects_log) @@ -1532,8 +1532,8 @@ static inline int nvme_get_log_cmd_effects(nvme_link_t l, enum nvme_csi csi, * percent complete of that operation, and the results of the previous 20 * self-test operations. * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline int nvme_get_log_device_self_test(nvme_link_t l, struct nvme_self_test_log *log) @@ -1548,8 +1548,8 @@ static inline int nvme_get_log_device_self_test(nvme_link_t l, * @mcda: Maximum Created Data Area * @log: Userspace address of the log payload * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline int nvme_get_log_create_telemetry_host_mcda(nvme_link_t l, enum nvme_telemetry_da mcda, @@ -1579,8 +1579,8 @@ static inline int nvme_get_log_create_telemetry_host_mcda(nvme_link_t l, * @l: Link handle * @log: Userspace address of the log payload * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline int nvme_get_log_create_telemetry_host(nvme_link_t l, struct nvme_telemetry_log *log) @@ -1598,8 +1598,8 @@ static inline int nvme_get_log_create_telemetry_host(nvme_link_t l, * Retrieves the Telemetry Host-Initiated log page at the requested offset * using the previously existing capture. * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline int nvme_get_log_telemetry_host(nvme_link_t l, __u64 offset, __u32 len, void *log) @@ -1634,8 +1634,8 @@ static inline int nvme_get_log_telemetry_host(nvme_link_t l, __u64 offset, * Retrieves the Telemetry Controller-Initiated log page at the requested offset * using the previously existing capture. * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline int nvme_get_log_telemetry_ctrl(nvme_link_t l, bool rae, __u64 offset, __u32 len, void *log) @@ -1672,8 +1672,8 @@ static inline int nvme_get_log_telemetry_ctrl(nvme_link_t l, bool rae, * generated when an entry for an Endurance Group is newly added to this log * page. * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline int nvme_get_log_endurance_group(nvme_link_t l, __u16 endgid, struct nvme_endurance_group_log *log) @@ -1703,8 +1703,8 @@ static inline int nvme_get_log_endurance_group(nvme_link_t l, __u16 endgid, * @nvmsetid: NVM set id * @log: User address to store the predictable latency log * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline int nvme_get_log_predictable_lat_nvmset(nvme_link_t l, __u16 nvmsetid, struct nvme_nvmset_predictable_lat_log *log) @@ -1736,8 +1736,8 @@ static inline int nvme_get_log_predictable_lat_nvmset(nvme_link_t l, __u16 nvmse * @len: Length of provided user buffer to hold the log data in bytes * @log: User address for log page data * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline int nvme_get_log_predictable_lat_event(nvme_link_t l, bool rae, __u32 offset, __u32 len, void *log) @@ -1892,8 +1892,8 @@ static inline int nvme_get_log_fdp_events(nvme_link_t l, __u16 egid, bool host_e * * See &struct nvme_ana_log for the definition of the returned structure. * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline int nvme_get_log_ana(nvme_link_t l, enum nvme_log_ana_lsp lsp, bool rae, __u64 offset, __u32 len, void *log) @@ -1926,8 +1926,8 @@ static inline int nvme_get_log_ana(nvme_link_t l, enum nvme_log_ana_lsp lsp, boo * * See &struct nvme_ana_log for the definition of the returned structure. * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline int nvme_get_log_ana_groups(nvme_link_t l, bool rae, __u32 len, struct nvme_ana_log *log) @@ -1967,8 +1967,8 @@ int nvme_get_ana_log_atomic(nvme_link_t l, bool rgo, bool rae, unsigned int retr * @len: The allocated length of the log page * @log: User address to store the log page * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline int nvme_get_log_lba_status(nvme_link_t l, bool rae, __u64 offset, __u32 len, void *log) @@ -2000,8 +2000,8 @@ static inline int nvme_get_log_lba_status(nvme_link_t l, bool rae, * @len: The allocated length of the log page * @log: User address to store the log page * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline int nvme_get_log_endurance_grp_evt(nvme_link_t l, bool rae, __u32 offset, __u32 len, void *log) @@ -2270,8 +2270,8 @@ static inline int nvme_get_log_changed_alloc_ns_list(nvme_link_t l, bool rae, __ * Supported only by fabrics discovery controllers, returning discovery * records. * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline int nvme_get_log_discovery(nvme_link_t l, bool rae, __u32 offset, __u32 len, void *log) @@ -2448,8 +2448,8 @@ static inline int nvme_get_log_reservation(nvme_link_t l, bool rae, * The Sanitize Status log page reports sanitize operation time estimates and * information about the most recent sanitize operation. * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline int nvme_get_log_sanitize(nvme_link_t l, bool rae, struct nvme_sanitize_log_page *log) @@ -2467,8 +2467,8 @@ static inline int nvme_get_log_sanitize(nvme_link_t l, bool rae, * * The list of zones that have changed state due to an exceptional event. * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline int nvme_get_log_zns_changed_zones(nvme_link_t l, __u32 nsid, bool rae, struct nvme_zns_changed_zone_log *log) @@ -2499,8 +2499,8 @@ static inline int nvme_get_log_zns_changed_zones(nvme_link_t l, __u32 nsid, bool * @size: Size of @pevent_log * @pevent_log: User address to store the persistent event log * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline int nvme_get_log_persistent_event(nvme_link_t l, enum nvme_pevent_log_action action, @@ -2531,8 +2531,8 @@ static inline int nvme_get_log_persistent_event(nvme_link_t l, * @cnscp: Contents and Scope of Command and Feature Identifier Lists * @lockdown_log: Buffer to store the lockdown log * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline int nvme_get_log_lockdown(nvme_link_t l, __u8 cnscp, struct nvme_lockdown_log *lockdown_log) @@ -2561,8 +2561,8 @@ static inline int nvme_get_log_lockdown(nvme_link_t l, * @l: Link handle * @args: &struct nvme_set_features_args argument structure * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_set_features(nvme_link_t l, struct nvme_set_features_args *args); @@ -2577,8 +2577,8 @@ int nvme_set_features(nvme_link_t l, struct nvme_set_features_args *args); * @data: User address of feature data, if applicable * @result: The command completion result from CQE dword0 * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline int nvme_set_features_data(nvme_link_t l, __u8 fid, __u32 nsid, __u32 cdw11, bool save, __u32 data_len, void *data, @@ -2611,8 +2611,8 @@ static inline int nvme_set_features_data(nvme_link_t l, __u8 fid, __u32 nsid, * @save: Save value across power states * @result: The command completion result from CQE dword0 * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline int nvme_set_features_simple(nvme_link_t l, __u8 fid, __u32 nsid, __u32 cdw11, bool save, __u32 *result) @@ -2631,8 +2631,8 @@ static inline int nvme_set_features_simple(nvme_link_t l, __u8 fid, __u32 nsid, * @save: Save value across power states * @result: The command completion result from CQE dword0 * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_set_features_arbitration(nvme_link_t l, __u8 ab, __u8 lpw, __u8 mpw, __u8 hpw, bool save, __u32 *result); @@ -2645,8 +2645,8 @@ int nvme_set_features_arbitration(nvme_link_t l, __u8 ab, __u8 lpw, __u8 mpw, * @save: Save value across power states * @result: The command completion result from CQE dword0 * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_set_features_power_mgmt(nvme_link_t l, __u8 ps, __u8 wh, bool save, __u32 *result); @@ -2660,8 +2660,8 @@ int nvme_set_features_power_mgmt(nvme_link_t l, __u8 ps, __u8 wh, bool save, * @data: User address of feature data * @result: The command completion result from CQE dword0 * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_set_features_lba_range(nvme_link_t l, __u32 nsid, __u8 nr_ranges, bool save, struct nvme_lba_range_type *data, __u32 *result); @@ -2676,8 +2676,8 @@ int nvme_set_features_lba_range(nvme_link_t l, __u32 nsid, __u8 nr_ranges, bool * @save: Save value across power states * @result: The command completion result from CQE dword0 * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_set_features_temp_thresh(nvme_link_t l, __u16 tmpth, __u8 tmpsel, enum nvme_feat_tmpthresh_thsel thsel, __u8 tmpthh, @@ -2692,8 +2692,8 @@ int nvme_set_features_temp_thresh(nvme_link_t l, __u16 tmpth, __u8 tmpsel, * @save: Save value across power states * @result: The command completion result from CQE dword0 * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_set_features_err_recovery(nvme_link_t l, __u32 nsid, __u16 tler, bool dulbe, bool save, __u32 *result); @@ -2705,8 +2705,8 @@ int nvme_set_features_err_recovery(nvme_link_t l, __u32 nsid, __u16 tler, * @save: Save value across power states * @result: The command completion result from CQE dword0 * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_set_features_volatile_wc(nvme_link_t l, bool wce, bool save, __u32 *result); @@ -2719,8 +2719,8 @@ int nvme_set_features_volatile_wc(nvme_link_t l, bool wce, bool save, * @save: Save value across power states * @result: The command completion result from CQE dword0 * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_set_features_irq_coalesce(nvme_link_t l, __u8 thr, __u8 time, bool save, __u32 *result); @@ -2733,8 +2733,8 @@ int nvme_set_features_irq_coalesce(nvme_link_t l, __u8 thr, __u8 time, * @save: Save value across power states * @result: The command completion result from CQE dword0 * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_set_features_irq_config(nvme_link_t l, __u16 iv, bool cd, bool save, __u32 *result); @@ -2746,8 +2746,8 @@ int nvme_set_features_irq_config(nvme_link_t l, __u16 iv, bool cd, bool save, * @save: Save value across power states * @result: The command completion result from CQE dword0 * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_set_features_write_atomic(nvme_link_t l, bool dn, bool save, __u32 *result); @@ -2759,8 +2759,8 @@ int nvme_set_features_write_atomic(nvme_link_t l, bool dn, bool save, * @save: Save value across power states * @result: The command completion result from CQE dword0 * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_set_features_async_event(nvme_link_t l, __u32 events, bool save, __u32 *result); @@ -2773,8 +2773,8 @@ int nvme_set_features_async_event(nvme_link_t l, __u32 events, bool save, * @save: Save value across power states * @result: The command completion result from CQE dword0 * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_set_features_auto_pst(nvme_link_t l, bool apste, bool save, struct nvme_feat_auto_pst *apst, @@ -2786,8 +2786,8 @@ int nvme_set_features_auto_pst(nvme_link_t l, bool apste, bool save, * @save: Save value across power states * @timestamp: The current timestamp value to assign to this feature * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_set_features_timestamp(nvme_link_t l, bool save, __u64 timestamp); @@ -2799,8 +2799,8 @@ int nvme_set_features_timestamp(nvme_link_t l, bool save, __u64 timestamp); * @save: Save value across power states * @result: The command completion result from CQE dword0 * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_set_features_hctm(nvme_link_t l, __u16 tmt2, __u16 tmt1, bool save, __u32 *result); @@ -2812,8 +2812,8 @@ int nvme_set_features_hctm(nvme_link_t l, __u16 tmt2, __u16 tmt1, bool save, * @save: Save value across power states * @result: The command completion result from CQE dword0 * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_set_features_nopsc(nvme_link_t l, bool noppme, bool save, __u32 *result); @@ -2825,8 +2825,8 @@ int nvme_set_features_nopsc(nvme_link_t l, bool noppme, bool save, __u32 *result * @save: Save value across power states * @result: The command completion result from CQE dword0 * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_set_features_rrl(nvme_link_t l, __u8 rrl, __u16 nvmsetid, bool save, __u32 *result); @@ -2840,8 +2840,8 @@ int nvme_set_features_rrl(nvme_link_t l, __u8 rrl, __u16 nvmsetid, bool save, * @data: Pointer to structure nvme_plm_config * @result: The command completion result from CQE dword0 * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_set_features_plm_config(nvme_link_t l, bool enable, __u16 nvmsetid, bool save, struct nvme_plm_config *data, @@ -2855,8 +2855,8 @@ int nvme_set_features_plm_config(nvme_link_t l, bool enable, __u16 nvmsetid, * @save: Save value across power states * @result: The command completion result from CQE dword0 * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_set_features_plm_window(nvme_link_t l, enum nvme_feat_plm_window_select sel, __u16 nvmsetid, bool save, __u32 *result); @@ -2869,8 +2869,8 @@ int nvme_set_features_plm_window(nvme_link_t l, enum nvme_feat_plm_window_select * @lsipi: LBA Status Information Poll Interval * @result: The command completion result from CQE dword0 * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_set_features_lba_sts_interval(nvme_link_t l, __u16 lsiri, __u16 lsipi, bool save, __u32 *result); @@ -2881,8 +2881,8 @@ int nvme_set_features_lba_sts_interval(nvme_link_t l, __u16 lsiri, __u16 lsipi, * @save: Save value across power states * @data: Pointer to structure nvme_feat_host_behavior * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_set_features_host_behavior(nvme_link_t l, bool save, struct nvme_feat_host_behavior *data); @@ -2894,8 +2894,8 @@ int nvme_set_features_host_behavior(nvme_link_t l, bool save, * @save: Save value across power states * @result: The command completion result from CQE dword0 * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_set_features_sanitize(nvme_link_t l, bool nodrm, bool save, __u32 *result); @@ -2907,8 +2907,8 @@ int nvme_set_features_sanitize(nvme_link_t l, bool nodrm, bool save, __u32 *resu * @save: Save value across power states * @result: The command completion result from CQE dword0 * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_set_features_endurance_evt_cfg(nvme_link_t l, __u16 endgid, __u8 egwarn, bool save, __u32 *result); @@ -2920,8 +2920,8 @@ int nvme_set_features_endurance_evt_cfg(nvme_link_t l, __u16 endgid, __u8 egwarn * @save: Save value across power states * @result: The command completion result from CQE dword0 * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_set_features_sw_progress(nvme_link_t l, __u8 pbslc, bool save, __u32 *result); @@ -2933,8 +2933,8 @@ int nvme_set_features_sw_progress(nvme_link_t l, __u8 pbslc, bool save, * @save: Save value across power states * @hostid: Host ID to set * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_set_features_host_id(nvme_link_t l, bool exhid, bool save, __u8 *hostid); @@ -2946,8 +2946,8 @@ int nvme_set_features_host_id(nvme_link_t l, bool exhid, bool save, __u8 *hostid * @save: Save value across power states * @result: The command completion result from CQE dword0 * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_set_features_resv_mask(nvme_link_t l, __u32 nsid, __u32 mask, bool save, __u32 *result); @@ -2960,8 +2960,8 @@ int nvme_set_features_resv_mask(nvme_link_t l, __u32 nsid, __u32 mask, bool save * @save: Save value across power states * @result: The command completion result from CQE dword0 * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_set_features_resv_persist(nvme_link_t l, __u32 nsid, bool ptpl, bool save, __u32 *result); @@ -2974,8 +2974,8 @@ int nvme_set_features_resv_persist(nvme_link_t l, __u32 nsid, bool ptpl, bool sa * @save: Save value across power states * @result: The command completion result from CQE dword0 * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_set_features_write_protect(nvme_link_t l, __u32 nsid, enum nvme_feat_nswpcfg_state state, @@ -2987,8 +2987,8 @@ int nvme_set_features_write_protect(nvme_link_t l, __u32 nsid, * @iocsi: I/O Command Set Combination Index * @save: Save value across power states * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_set_features_iocs_profile(nvme_link_t l, __u16 iocsi, bool save); @@ -2997,8 +2997,8 @@ int nvme_set_features_iocs_profile(nvme_link_t l, __u16 iocsi, bool save); * @l: Link handle * @args: &struct nvme_get_features_args argument structure * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_get_features(nvme_link_t l, struct nvme_get_features_args *args); @@ -3011,8 +3011,8 @@ int nvme_get_features(nvme_link_t l, struct nvme_get_features_args *args); * @data: User address of feature data, if applicable * @result: The command completion result from CQE dword0 * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline int nvme_get_features_data(nvme_link_t l, enum nvme_features_id fid, __u32 nsid, __u32 data_len, void *data, __u32 *result) @@ -3040,8 +3040,8 @@ static inline int nvme_get_features_data(nvme_link_t l, enum nvme_features_id fi * @nsid: Namespace ID, if applicable * @result: The command completion result from CQE dword0 * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline int nvme_get_features_simple(nvme_link_t l, enum nvme_features_id fid, __u32 nsid, __u32 *result) @@ -3055,8 +3055,8 @@ static inline int nvme_get_features_simple(nvme_link_t l, enum nvme_features_id * @sel: Select which type of attribute to return, see &enum nvme_get_features_sel * @result: The command completion result from CQE dword0 * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_get_features_arbitration(nvme_link_t l, enum nvme_get_features_sel sel, __u32 *result); @@ -3067,8 +3067,8 @@ int nvme_get_features_arbitration(nvme_link_t l, enum nvme_get_features_sel sel, * @sel: Select which type of attribute to return, see &enum nvme_get_features_sel * @result: The command completion result from CQE dword0 * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_get_features_power_mgmt(nvme_link_t l, enum nvme_get_features_sel sel, __u32 *result); @@ -3081,8 +3081,8 @@ int nvme_get_features_power_mgmt(nvme_link_t l, enum nvme_get_features_sel sel, * @data: Buffer to receive LBA Range Type data structure * @result: The command completion result from CQE dword0 * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_get_features_lba_range(nvme_link_t l, enum nvme_get_features_sel sel, __u32 nsid, struct nvme_lba_range_type *data, @@ -3096,8 +3096,8 @@ int nvme_get_features_lba_range(nvme_link_t l, enum nvme_get_features_sel sel, * @thsel: Threshold Type Select * @result: The command completion result from CQE dword0 * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_get_features_temp_thresh(nvme_link_t l, enum nvme_get_features_sel sel, __u8 tmpsel, enum nvme_feat_tmpthresh_thsel thsel, __u32 *result); @@ -3110,8 +3110,8 @@ int nvme_get_features_temp_thresh(nvme_link_t l, enum nvme_get_features_sel sel, * @nsid: Namespace ID * @result: The command completion result from CQE dword0 * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_get_features_err_recovery(nvme_link_t l, enum nvme_get_features_sel sel, __u32 nsid, __u32 *result); @@ -3122,8 +3122,8 @@ int nvme_get_features_err_recovery(nvme_link_t l, enum nvme_get_features_sel sel * @sel: Select which type of attribute to return, see &enum nvme_get_features_sel * @result: The command completion result from CQE dword0 * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_get_features_volatile_wc(nvme_link_t l, enum nvme_get_features_sel sel, __u32 *result); @@ -3134,8 +3134,8 @@ int nvme_get_features_volatile_wc(nvme_link_t l, enum nvme_get_features_sel sel, * @sel: Select which type of attribute to return, see &enum nvme_get_features_sel * @result: The command completion result from CQE dword0 * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_get_features_num_queues(nvme_link_t l, enum nvme_get_features_sel sel, __u32 *result); @@ -3146,8 +3146,8 @@ int nvme_get_features_num_queues(nvme_link_t l, enum nvme_get_features_sel sel, * @sel: Select which type of attribute to return, see &enum nvme_get_features_sel * @result: The command completion result from CQE dword0 * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_get_features_irq_coalesce(nvme_link_t l, enum nvme_get_features_sel sel, __u32 *result); @@ -3159,8 +3159,8 @@ int nvme_get_features_irq_coalesce(nvme_link_t l, enum nvme_get_features_sel sel * @iv: * @result: The command completion result from CQE dword0 * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_get_features_irq_config(nvme_link_t l, enum nvme_get_features_sel sel, __u16 iv, __u32 *result); @@ -3171,8 +3171,8 @@ int nvme_get_features_irq_config(nvme_link_t l, enum nvme_get_features_sel sel, * @sel: Select which type of attribute to return, see &enum nvme_get_features_sel * @result: The command completion result from CQE dword0 * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_get_features_write_atomic(nvme_link_t l, enum nvme_get_features_sel sel, __u32 *result); @@ -3183,8 +3183,8 @@ int nvme_get_features_write_atomic(nvme_link_t l, enum nvme_get_features_sel sel * @sel: Select which type of attribute to return, see &enum nvme_get_features_sel * @result: The command completion result from CQE dword0 * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_get_features_async_event(nvme_link_t l, enum nvme_get_features_sel sel, __u32 *result); @@ -3196,8 +3196,8 @@ int nvme_get_features_async_event(nvme_link_t l, enum nvme_get_features_sel sel, * @apst: * @result: The command completion result from CQE dword0 * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_get_features_auto_pst(nvme_link_t l, enum nvme_get_features_sel sel, struct nvme_feat_auto_pst *apst, __u32 *result); @@ -3209,8 +3209,8 @@ int nvme_get_features_auto_pst(nvme_link_t l, enum nvme_get_features_sel sel, * @attrs: Buffer for returned Host Memory Buffer Attributes * @result: The command completion result from CQE dword0 * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_get_features_host_mem_buf(nvme_link_t l, enum nvme_get_features_sel sel, struct nvme_host_mem_buf_attrs *attrs, @@ -3222,8 +3222,8 @@ int nvme_get_features_host_mem_buf(nvme_link_t l, enum nvme_get_features_sel sel * @sel: Select which type of attribute to return, see &enum nvme_get_features_sel * @ts: Current timestamp * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_get_features_timestamp(nvme_link_t l, enum nvme_get_features_sel sel, struct nvme_timestamp *ts); @@ -3234,8 +3234,8 @@ int nvme_get_features_timestamp(nvme_link_t l, enum nvme_get_features_sel sel, * @sel: Select which type of attribute to return, see &enum nvme_get_features_sel * @result: The command completion result from CQE dword0 * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_get_features_kato(nvme_link_t l, enum nvme_get_features_sel sel, __u32 *result); @@ -3245,8 +3245,8 @@ int nvme_get_features_kato(nvme_link_t l, enum nvme_get_features_sel sel, __u32 * @sel: Select which type of attribute to return, see &enum nvme_get_features_sel * @result: The command completion result from CQE dword0 * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_get_features_hctm(nvme_link_t l, enum nvme_get_features_sel sel, __u32 *result); @@ -3256,8 +3256,8 @@ int nvme_get_features_hctm(nvme_link_t l, enum nvme_get_features_sel sel, __u32 * @sel: Select which type of attribute to return, see &enum nvme_get_features_sel * @result: The command completion result from CQE dword0 * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_get_features_nopsc(nvme_link_t l, enum nvme_get_features_sel sel, __u32 *result); @@ -3267,8 +3267,8 @@ int nvme_get_features_nopsc(nvme_link_t l, enum nvme_get_features_sel sel, __u32 * @sel: Select which type of attribute to return, see &enum nvme_get_features_sel * @result: The command completion result from CQE dword0 * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_get_features_rrl(nvme_link_t l, enum nvme_get_features_sel sel, __u32 *result); @@ -3280,8 +3280,8 @@ int nvme_get_features_rrl(nvme_link_t l, enum nvme_get_features_sel sel, __u32 * * @data: * @result: The command completion result from CQE dword0 * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_get_features_plm_config(nvme_link_t l, enum nvme_get_features_sel sel, __u16 nvmsetid, struct nvme_plm_config *data, @@ -3294,8 +3294,8 @@ int nvme_get_features_plm_config(nvme_link_t l, enum nvme_get_features_sel sel, * @nvmsetid: NVM set id * @result: The command completion result from CQE dword0 * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_get_features_plm_window(nvme_link_t l, enum nvme_get_features_sel sel, __u16 nvmsetid, __u32 *result); @@ -3306,8 +3306,8 @@ int nvme_get_features_plm_window(nvme_link_t l, enum nvme_get_features_sel sel, * @sel: Select which type of attribute to return, see &enum nvme_get_features_sel * @result: The command completion result from CQE dword0 * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_get_features_lba_sts_interval(nvme_link_t l, enum nvme_get_features_sel sel, __u32 *result); @@ -3319,8 +3319,8 @@ int nvme_get_features_lba_sts_interval(nvme_link_t l, enum nvme_get_features_sel * @data: Pointer to structure nvme_feat_host_behavior * @result: The command completion result from CQE dword0 * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_get_features_host_behavior(nvme_link_t l, enum nvme_get_features_sel sel, struct nvme_feat_host_behavior *data, @@ -3332,8 +3332,8 @@ int nvme_get_features_host_behavior(nvme_link_t l, enum nvme_get_features_sel se * @sel: Select which type of attribute to return, see &enum nvme_get_features_sel * @result: The command completion result from CQE dword0 * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_get_features_sanitize(nvme_link_t l, enum nvme_get_features_sel sel, __u32 *result); @@ -3345,8 +3345,8 @@ int nvme_get_features_sanitize(nvme_link_t l, enum nvme_get_features_sel sel, * @endgid: Endurance Group Identifier * @result: The command completion result from CQE dword0 * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_get_features_endurance_event_cfg(nvme_link_t l, enum nvme_get_features_sel sel, __u16 endgid, __u32 *result); @@ -3357,8 +3357,8 @@ int nvme_get_features_endurance_event_cfg(nvme_link_t l, enum nvme_get_features_ * @sel: Select which type of attribute to return, see &enum nvme_get_features_sel * @result: The command completion result from CQE dword0 * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_get_features_sw_progress(nvme_link_t l, enum nvme_get_features_sel sel, __u32 *result); @@ -3371,8 +3371,8 @@ int nvme_get_features_sw_progress(nvme_link_t l, enum nvme_get_features_sel sel, * @len: Length of @hostid * @hostid: Buffer for returned host ID * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_get_features_host_id(nvme_link_t l, enum nvme_get_features_sel sel, bool exhid, __u32 len, __u8 *hostid); @@ -3384,8 +3384,8 @@ int nvme_get_features_host_id(nvme_link_t l, enum nvme_get_features_sel sel, * @nsid: Namespace ID * @result: The command completion result from CQE dword0 * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_get_features_resv_mask(nvme_link_t l, enum nvme_get_features_sel sel, __u32 nsid, __u32 *result); @@ -3397,8 +3397,8 @@ int nvme_get_features_resv_mask(nvme_link_t l, enum nvme_get_features_sel sel, * @nsid: Namespace ID * @result: The command completion result from CQE dword0 * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_get_features_resv_persist(nvme_link_t l, enum nvme_get_features_sel sel, __u32 nsid, __u32 *result); @@ -3410,8 +3410,8 @@ int nvme_get_features_resv_persist(nvme_link_t l, enum nvme_get_features_sel sel * @sel: Select which type of attribute to return, see &enum nvme_get_features_sel * @result: The command completion result from CQE dword0 * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_get_features_write_protect(nvme_link_t l, __u32 nsid, enum nvme_get_features_sel sel, @@ -3423,8 +3423,8 @@ int nvme_get_features_write_protect(nvme_link_t l, __u32 nsid, * @sel: Select which type of attribute to return, see &enum nvme_get_features_sel * @result: The command completion result from CQE dword0 * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_get_features_iocs_profile(nvme_link_t l, enum nvme_get_features_sel sel, __u32 *result); @@ -3439,8 +3439,8 @@ int nvme_get_features_iocs_profile(nvme_link_t l, enum nvme_get_features_sel sel * format may destroy all data and metadata associated with all namespaces or * only the specific namespace associated with the command * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_format_nvm(nvme_link_t l, struct nvme_format_nvm_args *args); @@ -3449,8 +3449,8 @@ int nvme_format_nvm(nvme_link_t l, struct nvme_format_nvm_args *args); * @l: Link handle * @args: &struct nvme_ns_mgmt_args Argument structure * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_ns_mgmt(nvme_link_t l, struct nvme_ns_mgmt_args *args); @@ -3468,8 +3468,8 @@ int nvme_ns_mgmt(nvme_link_t l, struct nvme_ns_mgmt_args *args); * attached to any controller. Use the nvme_ns_attach_ctrls() to assign the * namespace to one or more controllers. * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline int nvme_ns_mgmt_create(nvme_link_t l, struct nvme_id_ns *ns, __u32 *nsid, __u32 timeout, __u8 csi, @@ -3502,8 +3502,8 @@ static inline int nvme_ns_mgmt_create(nvme_link_t l, struct nvme_id_ns *ns, * controller. Use the nvme_ns_detach_ctrls() first if the namespace is still * attached. * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline int nvme_ns_mgmt_delete_timeout(nvme_link_t l, __u32 nsid, __u32 timeout) { @@ -3532,8 +3532,8 @@ static inline int nvme_ns_mgmt_delete_timeout(nvme_link_t l, __u32 nsid, __u32 t * controller. Use the nvme_ns_detach_ctrls() first if the namespace is still * attached. * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline int nvme_ns_mgmt_delete(nvme_link_t l, __u32 nsid) { @@ -3545,8 +3545,8 @@ static inline int nvme_ns_mgmt_delete(nvme_link_t l, __u32 nsid) * @l: Link handle * @args: &struct nvme_ns_attach_args Argument structure * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_ns_attach(nvme_link_t l, struct nvme_ns_attach_args *args); @@ -3556,8 +3556,8 @@ int nvme_ns_attach(nvme_link_t l, struct nvme_ns_attach_args *args); * @nsid: Namespace ID to attach * @ctrlist: Controller list to modify attachment state of nsid * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline int nvme_ns_attach_ctrls(nvme_link_t l, __u32 nsid, struct nvme_ctrl_list *ctrlist) @@ -3580,8 +3580,8 @@ static inline int nvme_ns_attach_ctrls(nvme_link_t l, __u32 nsid, * @nsid: Namespace ID to detach * @ctrlist: Controller list to modify attachment state of nsid * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline int nvme_ns_detach_ctrls(nvme_link_t l, __u32 nsid, struct nvme_ctrl_list *ctrlist) @@ -3617,8 +3617,8 @@ static inline int nvme_ns_detach_ctrls(nvme_link_t l, __u32 nsid, * Download command. Use the nvme_fw_commit() to activate a newly downloaded * image. * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_fw_download(nvme_link_t l, struct nvme_fw_download_args *args); @@ -3650,8 +3650,8 @@ int nvme_fw_commit(nvme_link_t l, struct nvme_fw_commit_args *args); * The security data is protocol specific and is not defined by the NVMe * specification. * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_security_send(nvme_link_t l, struct nvme_security_send_args *args); @@ -3660,8 +3660,8 @@ int nvme_security_send(nvme_link_t l, struct nvme_security_send_args *args); * @l: Link handle * @args: &struct nvme_security_receive argument structure * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_security_receive(nvme_link_t l, struct nvme_security_receive_args *args); @@ -3673,8 +3673,8 @@ int nvme_security_receive(nvme_link_t l, struct nvme_security_receive_args *args * The Get LBA Status command requests information about Potentially * Unrecoverable LBAs. Refer to the specification for action type descriptions. * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_get_lba_status(nvme_link_t l, struct nvme_get_lba_status_args *args); @@ -3689,8 +3689,8 @@ int nvme_get_lba_status(nvme_link_t l, struct nvme_get_lba_status_args *args); * * See the NVMe specification for more information. * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_directive_send(nvme_link_t l, struct nvme_directive_send_args *args); @@ -3702,8 +3702,8 @@ int nvme_directive_send(nvme_link_t l, struct nvme_directive_send_args *args); * @dtype: Directive Type * @id: Pointer to structure nvme_id_directives * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_directive_send_id_endir(nvme_link_t l, __u32 nsid, bool endir, enum nvme_directive_dtype dtype, @@ -3715,8 +3715,8 @@ int nvme_directive_send_id_endir(nvme_link_t l, __u32 nsid, bool endir, * @nsid: Namespace ID * @stream_id: Stream identifier * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline int nvme_directive_send_stream_release_identifier(nvme_link_t l, __u32 nsid, __u16 stream_id) @@ -3742,8 +3742,8 @@ static inline int nvme_directive_send_stream_release_identifier(nvme_link_t l, * @l: Link handle * @nsid: Namespace ID * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline int nvme_directive_send_stream_release_resource(nvme_link_t l, __u32 nsid) { @@ -3768,8 +3768,8 @@ static inline int nvme_directive_send_stream_release_resource(nvme_link_t l, __u * @l: Link handle * @args: &struct nvme_directive_recv_args argument structure * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_directive_recv(nvme_link_t l, struct nvme_directive_recv_args *args); @@ -3779,8 +3779,8 @@ int nvme_directive_recv(nvme_link_t l, struct nvme_directive_recv_args *args); * @nsid: Namespace ID * @id: Identify parameters buffer * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline int nvme_directive_recv_identify_parameters(nvme_link_t l, __u32 nsid, struct nvme_id_directives *id) @@ -3807,8 +3807,8 @@ static inline int nvme_directive_recv_identify_parameters(nvme_link_t l, __u32 n * @nsid: Namespace ID * @parms: Streams directive parameters buffer * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline int nvme_directive_recv_stream_parameters(nvme_link_t l, __u32 nsid, struct nvme_streams_directive_params *parms) @@ -3836,8 +3836,8 @@ static inline int nvme_directive_recv_stream_parameters(nvme_link_t l, __u32 nsi * @nr_entries: Number of streams to receive * @id: Stream status buffer * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline int nvme_directive_recv_stream_status(nvme_link_t l, __u32 nsid, unsigned int nr_entries, @@ -3871,8 +3871,8 @@ static inline int nvme_directive_recv_stream_status(nvme_link_t l, __u32 nsid, * @nsr: Namespace Streams Requested * @result: If successful, the CQE dword0 value * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline int nvme_directive_recv_stream_allocate(nvme_link_t l, __u32 nsid, __u16 nsr, __u32 *result) @@ -3898,8 +3898,8 @@ static inline int nvme_directive_recv_stream_allocate(nvme_link_t l, __u32 nsid, * @l: Link handle * @args: &struct nvme_capacity_mgmt_args argument structure * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_capacity_mgmt(nvme_link_t l, struct nvme_capacity_mgmt_args *args); @@ -3908,8 +3908,8 @@ int nvme_capacity_mgmt(nvme_link_t l, struct nvme_capacity_mgmt_args *args); * @l: Link handle * @args: &struct nvme_lockdown_args argument structure * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_lockdown(nvme_link_t l, struct nvme_lockdown_args *args); @@ -3921,8 +3921,8 @@ int nvme_lockdown(nvme_link_t l, struct nvme_lockdown_args *args); * This is an NVMe-over-Fabrics specific command, not applicable to PCIe. These * properties align to the PCI MMIO controller registers. * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_set_property(nvme_link_t l, struct nvme_set_property_args *args); @@ -3934,8 +3934,8 @@ int nvme_set_property(nvme_link_t l, struct nvme_set_property_args *args); * This is an NVMe-over-Fabrics specific command, not applicable to PCIe. These * properties align to the PCI MMIO controller registers. * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_get_property(nvme_link_t l, struct nvme_get_property_args *args); @@ -3954,8 +3954,8 @@ int nvme_get_property(nvme_link_t l, struct nvme_get_property_args *args); * operations are processed in the background, i.e., completion of the sanitize * command does not indicate completion of the sanitize operation. * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_sanitize_nvm(nvme_link_t l, struct nvme_sanitize_nvm_args *args); @@ -3975,8 +3975,8 @@ int nvme_sanitize_nvm(nvme_link_t l, struct nvme_sanitize_nvm_args *args); * 0xffffffff to test all namespaces. All other values tests a specific * namespace, if present. * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_dev_self_test(nvme_link_t l, struct nvme_dev_self_test_args *args); @@ -3993,8 +3993,8 @@ int nvme_dev_self_test(nvme_link_t l, struct nvme_dev_self_test_args *args); * - Assigning Flexible Resources for secondary controllers * - Setting the Online and Offline state for secondary controllers * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_virtual_mgmt(nvme_link_t l, struct nvme_virtual_mgmt_args *args); @@ -4006,8 +4006,8 @@ int nvme_virtual_mgmt(nvme_link_t l, struct nvme_virtual_mgmt_args *args); * The Flush command requests that the contents of volatile write cache be made * non-volatile. * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline int nvme_flush(nvme_link_t l, __u32 nsid) { @@ -4025,8 +4025,8 @@ static inline int nvme_flush(nvme_link_t l, __u32 nsid) * @args: &struct nvme_io_args argument structure * @opcode: Opcode to execute * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_io(nvme_link_t l, struct nvme_io_args *args, __u8 opcode); @@ -4035,8 +4035,8 @@ int nvme_io(nvme_link_t l, struct nvme_io_args *args, __u8 opcode); * @l: Link handle * @args: &struct nvme_io_args argument structure * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline int nvme_read(nvme_link_t l, struct nvme_io_args *args) { @@ -4048,8 +4048,8 @@ static inline int nvme_read(nvme_link_t l, struct nvme_io_args *args) * @l: Link handle * @args: &struct nvme_io_args argument structure * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline int nvme_write(nvme_link_t l, struct nvme_io_args *args) { @@ -4061,8 +4061,8 @@ static inline int nvme_write(nvme_link_t l, struct nvme_io_args *args) * @l: Link handle * @args: &struct nvme_io_args argument structure * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline int nvme_compare(nvme_link_t l, struct nvme_io_args *args) { @@ -4079,8 +4079,8 @@ static inline int nvme_compare(nvme_link_t l, struct nvme_io_args *args) * reads of logical blocks in this range shall be all bytes cleared to 0h until * a write occurs to this LBA range. * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline int nvme_write_zeros(nvme_link_t l, struct nvme_io_args *args) { @@ -4097,8 +4097,8 @@ static inline int nvme_write_zeros(nvme_link_t l, struct nvme_io_args *args) * is returned with Unrecovered Read Error status. To clear the invalid logical * block status, a write operation on those logical blocks is required. * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline int nvme_write_uncorrectable(nvme_link_t l, struct nvme_io_args *args) { @@ -4114,8 +4114,8 @@ static inline int nvme_write_uncorrectable(nvme_link_t l, struct nvme_io_args *a * and metadata, if applicable, for the LBAs indicated without transferring any * data or metadata to the host. * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline int nvme_verify(nvme_link_t l, struct nvme_io_args *args) { @@ -4133,8 +4133,8 @@ static inline int nvme_verify(nvme_link_t l, struct nvme_io_args *args) * to optimize performance and reliability, and may be used to * deallocate/unmap/trim those logical blocks. * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_dsm(nvme_link_t l, struct nvme_dsm_args *args); @@ -4143,8 +4143,8 @@ int nvme_dsm(nvme_link_t l, struct nvme_dsm_args *args); * @l: Link handle * @args: &struct nvme_copy_args argument structure * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_copy(nvme_link_t l, struct nvme_copy_args *args); @@ -4157,8 +4157,8 @@ int nvme_copy(nvme_link_t l, struct nvme_copy_args *args); * preempt a reservation held on a namespace, and abort a reservation held on a * namespace. * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_resv_acquire(nvme_link_t l, struct nvme_resv_acquire_args *args); @@ -4170,8 +4170,8 @@ int nvme_resv_acquire(nvme_link_t l, struct nvme_resv_acquire_args *args); * The Reservation Register command registers, unregisters, or replaces a * reservation key. * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_resv_register(nvme_link_t l, struct nvme_resv_register_args *args); @@ -4180,8 +4180,8 @@ int nvme_resv_register(nvme_link_t l, struct nvme_resv_register_args *args); * @l: Link handle * @args: &struct nvme_resv_release_args argument structure * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_resv_release(nvme_link_t l, struct nvme_resv_release_args *args); @@ -4194,8 +4194,8 @@ int nvme_resv_release(nvme_link_t l, struct nvme_resv_release_args *args); * registration and reservation status of a namespace. See the definition for * the returned structure, &struct nvme_reservation_status, for more details. * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_resv_report(nvme_link_t l, struct nvme_resv_report_args *args); @@ -4204,8 +4204,8 @@ int nvme_resv_report(nvme_link_t l, struct nvme_resv_report_args *args); * @l: Link handle * @args: &struct nvme_io_mgmt_recv_args argument structure * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_io_mgmt_recv(nvme_link_t l, struct nvme_io_mgmt_recv_args *args); @@ -4216,8 +4216,8 @@ int nvme_io_mgmt_recv(nvme_link_t l, struct nvme_io_mgmt_recv_args *args); * @data_len: Length of response buffer * @data: Response buffer * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline int nvme_fdp_reclaim_unit_handle_status(nvme_link_t l, __u32 nsid, __u32 data_len, void *data) @@ -4240,8 +4240,8 @@ static inline int nvme_fdp_reclaim_unit_handle_status(nvme_link_t l, __u32 nsid, * @l: Link handle * @args: &struct nvme_io_mgmt_send_args argument structure * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_io_mgmt_send(nvme_link_t l, struct nvme_io_mgmt_send_args *args); @@ -4252,8 +4252,8 @@ int nvme_io_mgmt_send(nvme_link_t l, struct nvme_io_mgmt_send_args *args); * @npids: Number of placement identifiers * @pids: List of placement identifiers * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline int nvme_fdp_reclaim_unit_handle_update(nvme_link_t l, __u32 nsid, unsigned int npids, __u16 *pids) @@ -4276,8 +4276,8 @@ static inline int nvme_fdp_reclaim_unit_handle_update(nvme_link_t l, __u32 nsid, * @l: Link handle * @args: &struct nvme_zns_mgmt_send_args argument structure * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_zns_mgmt_send(nvme_link_t l, struct nvme_zns_mgmt_send_args *args); @@ -4287,8 +4287,8 @@ int nvme_zns_mgmt_send(nvme_link_t l, struct nvme_zns_mgmt_send_args *args); * @l: Link handle * @args: &struct nvme_zns_mgmt_recv_args argument structure * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_zns_mgmt_recv(nvme_link_t l, struct nvme_zns_mgmt_recv_args *args); @@ -4305,8 +4305,8 @@ int nvme_zns_mgmt_recv(nvme_link_t l, struct nvme_zns_mgmt_recv_args *args); * @timeout: timeout in ms * @result: The command completion result from CQE dword0 * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline int nvme_zns_report_zones(nvme_link_t l, __u32 nsid, __u64 slba, enum nvme_zns_report_options opts, @@ -4336,8 +4336,8 @@ static inline int nvme_zns_report_zones(nvme_link_t l, __u32 nsid, __u64 slba, * @l: Link handle * @args: &struct nvme_zns_append_args argument structure * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_zns_append(nvme_link_t l, struct nvme_zns_append_args *args); @@ -4346,8 +4346,8 @@ int nvme_zns_append(nvme_link_t l, struct nvme_zns_append_args *args); * @l: Link handle * @args: &struct nvme_dim_args argument structure * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_dim_send(nvme_link_t l, struct nvme_dim_args *args); @@ -4366,8 +4366,8 @@ int nvme_lm_cdq(nvme_link_t l, struct nvme_lm_cdq_args *args); * @l: Link handle * @args: &struct nvme_lm_track_send_args argument structure * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_lm_track_send(nvme_link_t l, struct nvme_lm_track_send_args *args); @@ -4376,8 +4376,8 @@ int nvme_lm_track_send(nvme_link_t l, struct nvme_lm_track_send_args *args); * @l: Link handle * @args: &struct nvme_lm_migration_send_args argument structure * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_lm_migration_send(nvme_link_t l, struct nvme_lm_migration_send_args *args); @@ -4386,8 +4386,8 @@ int nvme_lm_migration_send(nvme_link_t l, struct nvme_lm_migration_send_args *ar * @l: Link handle * @args: &struct nvme_lm_migration_rev_args argument structure * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_lm_migration_recv(nvme_link_t l, struct nvme_lm_migration_recv_args *args); @@ -4400,8 +4400,8 @@ int nvme_lm_migration_recv(nvme_link_t l, struct nvme_lm_migration_recv_args *ar * @etpt: Enable Tail Pointer Trigger * @result: The command completions result from CQE dword0 * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_lm_set_features_ctrl_data_queue(nvme_link_t l, __u16 cdqid, __u32 hp, __u32 tpt, bool etpt, __u32 *result); @@ -4413,8 +4413,8 @@ int nvme_lm_set_features_ctrl_data_queue(nvme_link_t l, __u16 cdqid, __u32 hp, _ * @data: Get Controller Data Queue feature data * @result: The command completions result from CQE dword0 * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_lm_get_features_ctrl_data_queue(nvme_link_t l, __u16 cdqid, struct nvme_lm_ctrl_data_queue_fid_data *data, diff --git a/src/nvme/json.c b/src/nvme/json.c index 992a54373..8a611d8f2 100644 --- a/src/nvme/json.c +++ b/src/nvme/json.c @@ -248,15 +248,12 @@ int json_read_config(nvme_root_t r, const char *config_file) } json_root = parse_json(r, fd); close(fd); - if (!json_root) { - errno = EPROTO; - return -1; - } + if (!json_root) + return -EPROTO; if (!json_object_is_type(json_root, json_type_array)) { nvme_msg(r, LOG_DEBUG, "Wrong format, expected array\n"); json_object_put(json_root); - errno = EPROTO; - return -1; + return -EPROTO; } for (h = 0; h < json_object_array_length(json_root); h++) { host_obj = json_object_array_get_idx(json_root, h); @@ -448,8 +445,7 @@ int json_update_config(nvme_root_t r, const char *config_file) nvme_msg(r, LOG_ERR, "Failed to write to %s, %s\n", config_file ? "stdout" : config_file, json_util_get_last_err()); - ret = -1; - errno = EIO; + ret = -EIO; } json_object_put(json_root); @@ -675,8 +671,7 @@ int json_dump_tree(nvme_root_t r) if (ret < 0) { nvme_msg(r, LOG_ERR, "Failed to write, %s\n", json_util_get_last_err()); - ret = -1; - errno = EIO; + ret = -EIO; } json_object_put(json_root); diff --git a/src/nvme/linux.c b/src/nvme/linux.c index 4408e15f0..5e890d0b8 100644 --- a/src/nvme/linux.c +++ b/src/nvme/linux.c @@ -7,6 +7,7 @@ * Chaitanya Kulkarni */ +#include "nvme/api-types.h" #include #include #include @@ -56,10 +57,8 @@ static int __nvme_link_open_direct(nvme_link_t l, const char *devname) c = ret == 1; ret = asprintf(&path, "%s/%s", "/dev", name); - if (ret < 0) { - errno = ENOMEM; - return -1; - } + if (ret < 0) + return -ENOMEM; l->fd = open(path, O_RDONLY); if (l->fd < 0) @@ -90,36 +89,34 @@ nvme_link_t __nvme_create_link(nvme_root_t r) nvme_link_t l; l = calloc(1, sizeof(*l)); - if (!l) { - errno = ENOMEM; + if (!l) return NULL; - } l->root = r; return l; } -nvme_link_t nvme_open(nvme_root_t r, const char *name) +int nvme_open(nvme_root_t r, const char *name, nvme_link_t *lp) { nvme_link_t l; int ret; l = __nvme_create_link(r); if (!l) - NULL; + return -ENOMEM; l->name = strdup(name); if (!l->name) { free(l); - errno = -ENOMEM; - return NULL; + return -ENOMEM; } if (!strcmp(name, "NVME_TEST_FD")) { l->type = NVME_LINK_TYPE_DIRECT; l->fd = 0xFD; - return l; + *lp = l; + return 0; } if (!strncmp(name, "mctp:", strlen("mctp:"))) @@ -129,11 +126,12 @@ nvme_link_t nvme_open(nvme_root_t r, const char *name) if (ret) { nvme_close(l); - errno = -ret; - return NULL; + return ret; } - return l; + *lp = l; + + return 0; } void nvme_close(nvme_link_t l) @@ -218,10 +216,9 @@ int nvme_get_telemetry_max(nvme_link_t l, enum nvme_telemetry_da *da, size_t *da int err; id_ctrl = __nvme_alloc(sizeof(*id_ctrl)); - if (!id_ctrl) { - errno = ENOMEM; - return -1; - } + if (!id_ctrl) + return -ENOMEM; + err = nvme_identify_ctrl(l, id_ctrl); if (err) return err; @@ -273,10 +270,8 @@ int nvme_get_telemetry_log(nvme_link_t l, bool create, bool ctrl, bool rae, size *size = 0; log = __nvme_alloc(xfer); - if (!log) { - errno = ENOMEM; - return -1; - } + if (!log) + return -ENOMEM; if (ctrl) { err = nvme_get_log_telemetry_ctrl(l, true, 0, xfer, log); @@ -315,21 +310,16 @@ int nvme_get_telemetry_log(nvme_link_t l, bool create, bool ctrl, bool rae, size dalb = le32_to_cpu(telem->dalb4); break; default: - errno = EINVAL; - return -1; + return -EINVAL; } - if (dalb == 0) { - errno = ENOENT; - return -1; - } + if (dalb == 0) + return -ENOENT; *size = (dalb + 1) * xfer; tmp = __nvme_realloc(log, *size); - if (!tmp) { - errno = ENOMEM; - return -1; - } + if (!tmp) + return -ENOMEM; log = tmp; args.lid = lid; @@ -354,10 +344,9 @@ static int nvme_check_get_telemetry_log(nvme_link_t l, bool create, bool ctrl, b if (err) return err; - if (da > max_da) { - errno = ENOENT; - return -1; - } + if (da > max_da) + return -ENOENT; + return nvme_get_telemetry_log(l, create, ctrl, rae, 4096, da, log, size); } @@ -401,7 +390,7 @@ int nvme_get_lba_status_log(nvme_link_t l, bool rae, struct nvme_lba_status_log buf = malloc(sizeof(*buf)); if (!buf) - return -1; + return -ENOMEM; err = nvme_get_log_lba_status(l, true, 0, sizeof(*buf), buf); if (err) { @@ -419,7 +408,7 @@ int nvme_get_lba_status_log(nvme_link_t l, bool rae, struct nvme_lba_status_log tmp = realloc(buf, size); if (!tmp) { *log = NULL; - return -1; + return -ENOMEM; } buf = tmp; @@ -486,10 +475,9 @@ int nvme_get_ana_log_len(nvme_link_t l, size_t *analen) int ret; ctrl = __nvme_alloc(sizeof(*ctrl)); - if (!ctrl) { - errno = ENOMEM; - return -1; - } + if (!ctrl) + return -ENOMEM; + ret = nvme_identify_ctrl(l, ctrl); if (ret) return ret; @@ -505,10 +493,9 @@ int nvme_get_logical_block_size(nvme_link_t l, __u32 nsid, int *blksize) int ret; ns = __nvme_alloc(sizeof(*ns)); - if (!ns) { - errno = ENOMEM; - return -1; - } + if (!ns) + return -ENOMEM; + ret = nvme_identify_ns(l, nsid, ns); if (ret) return ret; @@ -529,7 +516,7 @@ static int __nvme_set_attr(const char *path, const char *value) nvme_msg(LOG_DEBUG, "Failed to open %s: %s\n", path, strerror(errno)); #endif - return -1; + return -errno; } return write(fd, value, strlen(value)); } @@ -541,7 +528,7 @@ int nvme_set_attr(const char *dir, const char *attr, const char *value) ret = asprintf(&path, "%s/%s", dir, attr); if (ret < 0) - return -1; + return -ENOMEM; return __nvme_set_attr(path, value); } @@ -581,10 +568,8 @@ char *nvme_get_attr(const char *dir, const char *attr) int ret; ret = asprintf(&path, "%s/%s", dir, attr); - if (ret < 0) { - errno = ENOMEM; + if (ret < 0) return NULL; - } return __nvme_get_attr(path); } @@ -622,8 +607,7 @@ int nvme_gen_dhchap_key(char *hostnqn, enum nvme_hmac_alg hmac, if (hmac != NVME_HMAC_ALG_NONE) { nvme_msg(NULL, LOG_ERR, "HMAC transformation not supported; " \ "recompile with OpenSSL support.\n"); - errno = -EINVAL; - return -1; + return -EINVAL; } memcpy(key, secret, key_len); @@ -637,8 +621,7 @@ static int derive_retained_key(int hmac, const char *hostnqn, { nvme_msg(NULL, LOG_ERR, "NVMe TLS is not supported; " "recompile with OpenSSL support.\n"); - errno = ENOTSUP; - return -1; + return -ENOTSUP; } static int derive_psk_digest(const char *hostnqn, const char *subsysnqn, @@ -648,8 +631,7 @@ static int derive_psk_digest(const char *hostnqn, const char *subsysnqn, { nvme_msg(NULL, LOG_ERR, "NVMe TLS 2.0 is not supported; " "recompile with OpenSSL support.\n"); - errno = ENOTSUP; - return -1; + return -ENOTSUP; } static int derive_tls_key(int version, int cipher, const char *context, @@ -658,8 +640,7 @@ static int derive_tls_key(int version, int cipher, const char *context, { nvme_msg(NULL, LOG_ERR, "NVMe TLS is not supported; " "recompile with OpenSSL support.\n"); - errno = ENOTSUP; - return -1; + return -ENOTSUP; } #else /* CONFIG_OPENSSL */ static unsigned char default_hmac(size_t key_len) @@ -750,54 +731,40 @@ static int derive_retained_key(int hmac, const char *hostnqn, } md = select_hmac(hmac, &hmac_len); - if (!md || !hmac_len) { - errno = EINVAL; - return -1; - } + if (!md || !hmac_len) + return -EINVAL; ctx = EVP_PKEY_CTX_new_id(EVP_PKEY_HKDF, NULL); - if (!ctx) { - errno = ENOMEM; - return -1; - } + if (!ctx) + return -ENOMEM; + + if (EVP_PKEY_derive_init(ctx) <= 0) + return -ENOMEM; + + if (EVP_PKEY_CTX_set_hkdf_md(ctx, md) <= 0) + return -ENOKEY; + + if (EVP_PKEY_CTX_set1_hkdf_key(ctx, configured, key_len) <= 0) + return -ENOKEY; - if (EVP_PKEY_derive_init(ctx) <= 0) { - errno = ENOMEM; - return -1; - } - if (EVP_PKEY_CTX_set_hkdf_md(ctx, md) <= 0) { - errno = ENOKEY; - return -1; - } - if (EVP_PKEY_CTX_set1_hkdf_key(ctx, configured, key_len) <= 0) { - errno = ENOKEY; - return -1; - } if (EVP_PKEY_CTX_add1_hkdf_info(ctx, - (const unsigned char *)&length, 2) <= 0) { - errno = ENOKEY; - return -1; - } + (const unsigned char *)&length, 2) <= 0) + return -ENOKEY; + if (EVP_PKEY_CTX_add1_hkdf_info(ctx, - (const unsigned char *)"tls13 ", 6) <= 0) { - errno = ENOKEY; - return -1; - } + (const unsigned char *)"tls13 ", 6) <= 0) + return -ENOKEY; + if (EVP_PKEY_CTX_add1_hkdf_info(ctx, - (const unsigned char *)"HostNQN", 7) <= 0) { - errno = ENOKEY; - return -1; - } + (const unsigned char *)"HostNQN", 7) <= 0) + return -ENOKEY; + if (EVP_PKEY_CTX_add1_hkdf_info(ctx, - (const unsigned char *)hostnqn, strlen(hostnqn)) <= 0) { - errno = ENOKEY; - return -1; - } + (const unsigned char *)hostnqn, strlen(hostnqn)) <= 0) + return -ENOKEY; - if (EVP_PKEY_derive(ctx, retained, &key_len) <= 0) { - errno = ENOKEY; - return -1; - } + if (EVP_PKEY_derive(ctx, retained, &key_len) <= 0) + return -ENOKEY; return key_len; } @@ -834,66 +801,51 @@ static int derive_tls_key(int version, unsigned char cipher, size_t hmac_len; md = select_hmac(cipher, &hmac_len); - if (!md || !hmac_len) { - errno = EINVAL; - return -1; - } + if (!md || !hmac_len) + return -EINVAL; ctx = EVP_PKEY_CTX_new_id(EVP_PKEY_HKDF, NULL); - if (!ctx) { - errno = ENOMEM; - return -1; - } + if (!ctx) + return -ENOMEM; + + if (EVP_PKEY_derive_init(ctx) <= 0) + return -ENOMEM; + + if (EVP_PKEY_CTX_set_hkdf_md(ctx, md) <= 0) + return -ENOKEY; + + if (EVP_PKEY_CTX_set1_hkdf_key(ctx, retained, key_len) <= 0) + return -ENOKEY; - if (EVP_PKEY_derive_init(ctx) <= 0) { - errno = ENOMEM; - return -1; - } - if (EVP_PKEY_CTX_set_hkdf_md(ctx, md) <= 0) { - errno = ENOKEY; - return -1; - } - if (EVP_PKEY_CTX_set1_hkdf_key(ctx, retained, key_len) <= 0) { - errno = ENOKEY; - return -1; - } if (EVP_PKEY_CTX_add1_hkdf_info(ctx, - (const unsigned char *)&length, 2) <= 0) { - errno = ENOKEY; - return -1; - } + (const unsigned char *)&length, 2) <= 0) + return -ENOKEY; + if (EVP_PKEY_CTX_add1_hkdf_info(ctx, - (const unsigned char *)"tls13 ", 6) <= 0) { - errno = ENOKEY; - return -1; - } + (const unsigned char *)"tls13 ", 6) <= 0) + return -ENOKEY; + if (EVP_PKEY_CTX_add1_hkdf_info(ctx, - (const unsigned char *)"nvme-tls-psk", 12) <= 0) { - errno = ENOKEY; - return -1; - } + (const unsigned char *)"nvme-tls-psk", 12) <= 0) + return -ENOKEY; + if (version == 1) { char hash_str[5]; sprintf(hash_str, "%02d ", cipher); if (EVP_PKEY_CTX_add1_hkdf_info(ctx, (const unsigned char *)hash_str, - strlen(hash_str)) <= 0) { - errno = ENOKEY; - return -1; - } + strlen(hash_str)) <= 0) + return -ENOKEY; } + if (EVP_PKEY_CTX_add1_hkdf_info(ctx, (const unsigned char *)context, - strlen(context)) <= 0) { - errno = ENOKEY; - return -1; - } + strlen(context)) <= 0) + return -ENOKEY; - if (EVP_PKEY_derive(ctx, psk, &key_len) <= 0) { - errno = ENOKEY; - return -1; - } + if (EVP_PKEY_derive(ctx, psk, &key_len) <= 0) + return -ENOKEY; return key_len; } @@ -920,22 +872,16 @@ int nvme_gen_dhchap_key(char *hostnqn, enum nvme_hmac_alg hmac, size_t len; lib_ctx = OSSL_LIB_CTX_new(); - if (!lib_ctx) { - errno = ENOMEM; - return -1; - } + if (!lib_ctx) + return -ENOMEM; mac = EVP_MAC_fetch(lib_ctx, OSSL_MAC_NAME_HMAC, progq); - if (!mac) { - errno = ENOMEM; - return -1; - } + if (!mac) + return -ENOMEM; mac_ctx = EVP_MAC_CTX_new(mac); - if (!mac_ctx) { - errno = ENOMEM; - return -1; - } + if (!mac_ctx) + return -ENOMEM; switch (hmac) { case NVME_HMAC_ALG_NONE: @@ -951,40 +897,29 @@ int nvme_gen_dhchap_key(char *hostnqn, enum nvme_hmac_alg hmac, digest = OSSL_DIGEST_NAME_SHA2_512; break; default: - errno = EINVAL; - return -1; + return -EINVAL; } *p++ = OSSL_PARAM_construct_utf8_string(OSSL_MAC_PARAM_DIGEST, digest, 0); *p = OSSL_PARAM_construct_end(); - if (!EVP_MAC_init(mac_ctx, secret, key_len, params)) { - errno = ENOKEY; - return -1; - } + if (!EVP_MAC_init(mac_ctx, secret, key_len, params)) + return -ENOKEY; if (!EVP_MAC_update(mac_ctx, (unsigned char *)hostnqn, - strlen(hostnqn))) { - errno = ENOKEY; - return -1; - } + strlen(hostnqn))) + return -ENOKEY; if (!EVP_MAC_update(mac_ctx, (unsigned char *)hmac_seed, - strlen(hmac_seed))) { - errno = ENOKEY; - return -1; - } + strlen(hmac_seed))) + return -ENOKEY; - if (!EVP_MAC_final(mac_ctx, key, &len, key_len)) { - errno = ENOKEY; - return -1; - } + if (!EVP_MAC_final(mac_ctx, key, &len, key_len)) + return -ENOKEY; - if (len != key_len) { - errno = EMSGSIZE; - return -1; - } + if (len != key_len) + return -EMSGSIZE; return 0; } @@ -1006,21 +941,17 @@ static int derive_psk_digest(const char *hostnqn, const char *subsysnqn, size_t len; lib_ctx = OSSL_LIB_CTX_new(); - if (!lib_ctx) { - errno = ENOMEM; - return -1; - } + if (!lib_ctx) + return -ENOMEM; + mac = EVP_MAC_fetch(lib_ctx, OSSL_MAC_NAME_HMAC, progq); - if (!mac) { - errno = ENOMEM; - return -1; - } + if (!mac) + return -ENOMEM; mac_ctx = EVP_MAC_CTX_new(mac); - if (!mac_ctx) { - errno = ENOMEM; - return -1; - } + if (!mac_ctx) + return -ENOMEM; + switch (cipher) { case NVME_HMAC_ALG_SHA2_256: dig = OSSL_DIGEST_NAME_SHA2_256; @@ -1029,66 +960,52 @@ static int derive_psk_digest(const char *hostnqn, const char *subsysnqn, dig = OSSL_DIGEST_NAME_SHA2_384; break; default: - errno = EINVAL; - break; + return -EINVAL; } - if (!dig) - return -1; + *p++ = OSSL_PARAM_construct_utf8_string(OSSL_MAC_PARAM_DIGEST, dig, 0); *p = OSSL_PARAM_construct_end(); psk_ctx = malloc(key_len); - if (!psk_ctx) { - errno = ENOMEM; - return -1; - } + if (!psk_ctx) + return -ENOMEM; + + if (!EVP_MAC_init(mac_ctx, retained, key_len, params)) + return -ENOKEY; - if (!EVP_MAC_init(mac_ctx, retained, key_len, params)) { - errno = ENOKEY; - return -1; - } if (!EVP_MAC_update(mac_ctx, (unsigned char *)hostnqn, - strlen(hostnqn))) { - errno = ENOKEY; - return -1; - } - if (!EVP_MAC_update(mac_ctx, (unsigned char *)" ", 1)) { - errno = ENOKEY; - return -1; - } + strlen(hostnqn))) + return -ENOKEY; + + if (!EVP_MAC_update(mac_ctx, (unsigned char *)" ", 1)) + return -ENOKEY; + if (!EVP_MAC_update(mac_ctx, (unsigned char *)subsysnqn, - strlen(subsysnqn))) { - errno = ENOKEY; - return -1; - } - if (!EVP_MAC_update(mac_ctx, (unsigned char *)" ", 1)) { - errno = ENOKEY; - return -1; - } + strlen(subsysnqn))) + return -ENOKEY; + + if (!EVP_MAC_update(mac_ctx, (unsigned char *)" ", 1)) + return -ENOKEY; + if (!EVP_MAC_update(mac_ctx, (unsigned char *)hmac_seed, - strlen(hmac_seed))) { - errno = ENOKEY; - return -1; - } - if (!EVP_MAC_final(mac_ctx, psk_ctx, &hmac_len, key_len)) { - errno = ENOKEY; - return -1; - } - if (hmac_len > key_len) { - errno = EMSGSIZE; - return -1; - } - if (hmac_len * 2 > digest_len) { - errno = EINVAL; - return -1; - } + strlen(hmac_seed))) + return -ENOKEY; + + if (!EVP_MAC_final(mac_ctx, psk_ctx, &hmac_len, key_len)) + return -ENOKEY; + + if (hmac_len > key_len) + return -EMSGSIZE; + + if (hmac_len * 2 > digest_len) + return -EINVAL; + memset(digest, 0, digest_len); len = base64_encode(psk_ctx, hmac_len, digest); - if (len < 0) { - errno = ENOKEY; + if (len < 0) return len; - } + return strlen(digest); } #endif /* !CONFIG_OPENSSL */ @@ -1102,10 +1019,8 @@ static int gen_tls_identity(const char *hostnqn, const char *subsysnqn, version, cipher, hostnqn, subsysnqn); return strlen(identity); } - if (version > 1) { - errno = EINVAL; - return -1; - } + if (version > 1) + return -EINVAL; sprintf(identity, "NVMe%01dR%02d %s %s %s", version, cipher, hostnqn, subsysnqn, digest); @@ -1123,16 +1038,13 @@ static int derive_nvme_keys(const char *hostnqn, const char *subsysnqn, unsigned char cipher; int ret = -1; - if (!hostnqn || !subsysnqn || !identity || !psk) { - errno = EINVAL; - return -1; - } + if (!hostnqn || !subsysnqn || !identity || !psk) + return -EINVAL; retained = malloc(key_len); - if (!retained) { - errno = ENOMEM; - return -1; - } + if (!retained) + return -ENOMEM; + ret = derive_retained_key(hmac, hostnqn, configured, retained, key_len); if (ret < 0) return ret; @@ -1146,10 +1058,9 @@ static int derive_nvme_keys(const char *hostnqn, const char *subsysnqn, size_t digest_len = 2 * key_len; digest = malloc(digest_len); - if (!digest) { - errno = ENOMEM; - return -1; - } + if (!digest) + return -ENOMEM; + ret = derive_psk_digest(hostnqn, subsysnqn, version, cipher, retained, key_len, digest, digest_len); @@ -1170,10 +1081,8 @@ static ssize_t nvme_identity_len(int hmac, int version, const char *hostnqn, { ssize_t len; - if (!hostnqn || !subsysnqn) { - errno = EINVAL; - return -1; - } + if (!hostnqn || !subsysnqn) + return -EINVAL; len = strlen(hostnqn) + strlen(subsysnqn) + 12; if (version == 1) { @@ -1181,46 +1090,52 @@ static ssize_t nvme_identity_len(int hmac, int version, const char *hostnqn, if (hmac == NVME_HMAC_ALG_SHA2_384) len += 32; } else if (version > 1) { - errno = EINVAL; - return -1; + return -EINVAL; } + return len; } -char *nvme_generate_tls_key_identity(const char *hostnqn, const char *subsysnqn, +int nvme_generate_tls_key_identity(const char *hostnqn, const char *subsysnqn, int version, int hmac, - unsigned char *configured_key, int key_len) + unsigned char *configured_key, int key_len, + char **identityp) { _cleanup_free_ unsigned char *psk = NULL; char *identity; ssize_t identity_len; - int ret = -1; + int ret; identity_len = nvme_identity_len(hmac, version, hostnqn, subsysnqn); if (identity_len < 0) - return NULL; + return identity_len; identity = malloc(identity_len); if (!identity) - return NULL; + return -ENOMEM; psk = malloc(key_len); - if (!psk) - goto out_free_identity; + if (!psk) { + ret = -ENOMEM; + goto err; + } memset(psk, 0, key_len); ret = derive_nvme_keys(hostnqn, subsysnqn, identity, version, hmac, configured_key, psk, key_len); -out_free_identity: - if (ret < 0) { - free(identity); - identity = NULL; - } - return identity; + if (ret) + goto err; + + *identityp = identity; + return 0; + +err: + free(identity); + return -ret; } #ifdef CONFIG_KEYUTILS -long nvme_lookup_keyring(const char *keyring) +int nvme_lookup_keyring(const char *keyring, long *key) { key_serial_t keyring_id; @@ -1228,8 +1143,10 @@ long nvme_lookup_keyring(const char *keyring) keyring = NVME_TLS_DEFAULT_KEYRING; keyring_id = find_key_by_type_and_desc("keyring", keyring, 0); if (keyring_id < 0) - return 0; - return keyring_id; + return -errno; + + *key = keyring_id; + return 0; } char *nvme_describe_key_serial(long key_id) @@ -1251,13 +1168,13 @@ char *nvme_describe_key_serial(long key_id) return strdup(last); } -long nvme_lookup_key(const char *type, const char *identity) +int nvme_lookup_key(const char *type, const char *identity, long *keyp) { key_serial_t key; key = keyctl_search(KEY_SPEC_SESSION_KEYRING, type, identity, 0); if (key < 0) - return 0; + return -errno; return key; } @@ -1266,55 +1183,53 @@ int nvme_set_keyring(long key_id) long err; if (key_id == 0) { - key_id = nvme_lookup_keyring(NULL); - if (key_id == 0) { - errno = ENOKEY; - return -1; - } + if (nvme_lookup_keyring(NULL, &key_id)) + return -ENOKEY; } err = keyctl_link(key_id, KEY_SPEC_SESSION_KEYRING); if (err < 0) - return -1; + return -errno; return 0; } -unsigned char *nvme_read_key(long keyring_id, long key_id, int *len) +int nvme_read_key(long keyring_id, long key_id, int *len, + unsigned char **key) { void *buffer; int ret; ret = nvme_set_keyring(keyring_id); - if (ret < 0) { - errno = -ret; - return NULL; - } + if (ret < 0) + return ret; + ret = keyctl_read_alloc(key_id, &buffer); - if (ret < 0) { - errno = -ret; - buffer = NULL; - } else - *len = ret; + if (ret < 0) + return ret; - return buffer; + *len = ret; + *key = buffer; + return 0; } -long nvme_update_key(long keyring_id, const char *key_type, - const char *identity, unsigned char *key_data, - int key_len) +int nvme_update_key(long keyring_id, const char *key_type, + const char *identity, unsigned char *key_data, + int key_len, long *keyp) { long key; key = keyctl_search(keyring_id, key_type, identity, 0); if (key > 0) { if (keyctl_revoke(key) < 0) - return 0; + return -errno; } key = add_key(key_type, identity, key_data, key_len, keyring_id); if (key < 0) - key = 0; - return key; + return -errno; + + *keyp = key; + return 0; } struct __scan_keys_data { @@ -1360,13 +1275,16 @@ int nvme_scan_tls_keys(const char *keyring, nvme_scan_tls_keys_cb_t cb, void *data) { struct __scan_keys_data d; - key_serial_t keyring_id = nvme_lookup_keyring(keyring); + long keyring_id; int ret; - if (!keyring_id) { - errno = EINVAL; - return -1; - } + ret = nvme_lookup_keyring(keyring, &keyring_id); + if (ret) + return ret; + + if (!keyring_id) + return -EINVAL; + ret = nvme_set_keyring(keyring_id); if (ret < 0) return ret; @@ -1378,99 +1296,109 @@ int nvme_scan_tls_keys(const char *keyring, nvme_scan_tls_keys_cb_t cb, return ret; } -static long __nvme_insert_tls_key_versioned(key_serial_t keyring_id, const char *key_type, - const char *hostnqn, const char *subsysnqn, - int version, int hmac, - unsigned char *configured_key, int key_len) +static int __nvme_insert_tls_key_versioned(key_serial_t keyring_id, const char *key_type, + const char *hostnqn, const char *subsysnqn, + int version, int hmac, + unsigned char *configured_key, int key_len, + long *key) { _cleanup_free_ unsigned char *psk = NULL; _cleanup_free_ char *identity = NULL; ssize_t identity_len; - key_serial_t key; int ret; identity_len = nvme_identity_len(hmac, version, hostnqn, subsysnqn); if (identity_len < 0) - return 0; + return identity_len; identity = malloc(identity_len); - if (!identity) { - errno = ENOMEM; - return 0; - } + if (!identity) + return -ENOMEM; + memset(identity, 0, identity_len); psk = malloc(key_len); - if (!psk) { - errno = ENOMEM; - return 0; - } + if (!psk) + return -ENOMEM; + memset(psk, 0, key_len); ret = derive_nvme_keys(hostnqn, subsysnqn, identity, version, hmac, configured_key, psk, key_len); - if (ret != key_len) { - errno = ENOKEY; - return 0; - } + if (ret != key_len) + return -ENOKEY; - key = nvme_update_key(keyring_id, key_type, identity, - psk, key_len); - return key; + return nvme_update_key(keyring_id, key_type, identity, + psk, key_len, key); } -long nvme_insert_tls_key_versioned(const char *keyring, const char *key_type, - const char *hostnqn, const char *subsysnqn, - int version, int hmac, - unsigned char *configured_key, int key_len) +int nvme_insert_tls_key_versioned(const char *keyring, const char *key_type, + const char *hostnqn, const char *subsysnqn, + int version, int hmac, + unsigned char *configured_key, int key_len, + long *key) { - key_serial_t keyring_id; + long keyring_id; int ret; - keyring_id = nvme_lookup_keyring(keyring); - if (keyring_id == 0) { - errno = ENOKEY; - return 0; - } + ret = nvme_lookup_keyring(keyring, &keyring_id); + if (ret) + return ret; + + if (keyring_id == 0) + return -ENOKEY; ret = nvme_set_keyring(keyring_id); if (ret < 0) - return 0; + return ret; + return __nvme_insert_tls_key_versioned(keyring_id, key_type, hostnqn, subsysnqn, version, hmac, - configured_key, key_len); + configured_key, key_len, + key); } -long nvme_revoke_tls_key(const char *keyring, const char *key_type, - const char *identity) +int nvme_revoke_tls_key(const char *keyring, const char *key_type, + const char *identity) { - key_serial_t keyring_id; + long keyring_id; long key; + int ret; - keyring_id = nvme_lookup_keyring(keyring); - if (keyring_id == 0) { - errno = ENOKEY; - return 0; - } + ret = nvme_lookup_keyring(keyring, &keyring_id); + if (ret) + return ret; + + if (keyring_id == 0) + return -ENOKEY; key = keyctl_search(keyring_id, key_type, identity, 0); if (key < 0) - return -1; + return -errno; - return keyctl_revoke(key); + if (keyctl_revoke(key)) + return -errno; + + return 0; } -static long __nvme_insert_tls_key(long keyring_id, - const char *hostnqn, const char *subsysnqn, - const char *identity, const char *key) +static int __nvme_insert_tls_key(long keyring_id, + const char *hostnqn, const char *subsysnqn, + const char *identity, const char *key, long *keyp) { _cleanup_free_ unsigned char *key_data = NULL; unsigned char version; unsigned char hmac; size_t key_len; + long lkey; + int ret; + + ret = nvme_import_tls_key_versioned(key, &version, + &hmac, &key_len, + &key_data); + if (ret) + return ret; - key_data = nvme_import_tls_key_versioned(key, &version, - &hmac, &key_len); if (!key_data) return -EINVAL; @@ -1481,14 +1409,21 @@ static long __nvme_insert_tls_key(long keyring_id, * configured key. Derive a new key and load the newly * created key into the keystore. */ - return __nvme_insert_tls_key_versioned(keyring_id, "psk", - hostnqn, subsysnqn, - version, hmac, - key_data, key_len); + ret = __nvme_insert_tls_key_versioned(keyring_id, "psk", + hostnqn, subsysnqn, + version, hmac, + key_data, key_len, + &lkey); + } else { + ret = nvme_update_key(keyring_id, "psk", identity, + key_data, key_len, &lkey); } - return nvme_update_key(keyring_id, "psk", identity, - key_data, key_len); + if (ret) + return ret; + + *keyp = lkey; + return 0; } int __nvme_import_keys_from_config(nvme_host_t h, nvme_ctrl_t c, @@ -1498,6 +1433,7 @@ int __nvme_import_keys_from_config(nvme_host_t h, nvme_ctrl_t c, const char *subsysnqn = nvme_ctrl_get_subsysnqn(c); const char *keyring, *key, *identity; long kr_id = 0, id = 0; + int ret; if (!hostnqn || !subsysnqn) { nvme_msg(h->r, LOG_ERR, "Invalid NQNs (%s, %s)\n", @@ -1512,9 +1448,9 @@ int __nvme_import_keys_from_config(nvme_host_t h, nvme_ctrl_t c, keyring = nvme_ctrl_get_keyring(c); if (keyring) { - kr_id = nvme_lookup_keyring(keyring); - if (kr_id == 0) - return -errno; + ret = nvme_lookup_keyring(keyring, &kr_id); + if (ret) + return ret; } else kr_id = c->cfg.keyring; @@ -1524,9 +1460,9 @@ int __nvme_import_keys_from_config(nvme_host_t h, nvme_ctrl_t c, * That means we are explicitly selecting the keyring. */ if (!kr_id) { - kr_id = nvme_lookup_keyring(".nvme"); - if (kr_id == 0) - return -errno; + ret = nvme_lookup_keyring(".nvme", &kr_id); + if (ret) + return ret; } if (nvme_set_keyring(kr_id) < 0) { @@ -1536,16 +1472,16 @@ int __nvme_import_keys_from_config(nvme_host_t h, nvme_ctrl_t c, identity = nvme_ctrl_get_tls_key_identity(c); if (identity) - id = nvme_lookup_key("psk", identity); + ret = nvme_lookup_key("psk", identity, &id); if (!id) - id = __nvme_insert_tls_key(kr_id, hostnqn, - subsysnqn, identity, key); + ret = __nvme_insert_tls_key(kr_id, hostnqn, + subsysnqn, identity, key, &id); - if (id <= 0) { + if (ret) { nvme_msg(h->r, LOG_ERR, "Failed to insert TLS KEY, error %d\n", - errno); - return -errno; + ret); + return ret; } out: @@ -1555,77 +1491,70 @@ int __nvme_import_keys_from_config(nvme_host_t h, nvme_ctrl_t c, return 0; } #else -long nvme_lookup_keyring(const char *keyring) +int nvme_lookup_keyring(const char *keyring, long *key) { nvme_msg(NULL, LOG_ERR, "key operations not supported; "\ "recompile with keyutils support.\n"); - errno = ENOTSUP; - return 0; + return -ENOTSUP; } char *nvme_describe_key_serial(long key_id) { nvme_msg(NULL, LOG_ERR, "key operations not supported; "\ "recompile with keyutils support.\n"); - errno = ENOTSUP; return NULL; } -long nvme_lookup_key(const char *type, const char *identity) +int nvme_lookup_key(const char *type, const char *identity, long *key) { nvme_msg(NULL, LOG_ERR, "key operations not supported; "\ "recompile with keyutils support.\n"); - errno = ENOTSUP; - return 0; + return -ENOTSUP; } int nvme_set_keyring(long key_id) { nvme_msg(NULL, LOG_ERR, "key operations not supported; "\ "recompile with keyutils support.\n"); - errno = ENOTSUP; - return -1; + return -ENOTSUP; } -unsigned char *nvme_read_key(long keyring_id, long key_id, int *len) +int nvme_read_key(long keyring_id, long key_id, int *len, + unsigned char **key) { - errno = ENOTSUP; - return NULL; + return -ENOTSUP; } -long nvme_update_key(long keyring_id, const char *key_type, - const char *identity, unsigned char *key_data, - int key_len) +int nvme_update_key(long keyring_id, const char *key_type, + const char *identity, unsigned char *key_data, + int key_len, long *key) { - errno = ENOTSUP; - return 0; + return -ENOTSUP; } int nvme_scan_tls_keys(const char *keyring, nvme_scan_tls_keys_cb_t cb, void *data) { - errno = ENOTSUP; - return -1; + return -ENOTSUP; } -long nvme_insert_tls_key_versioned(const char *keyring, const char *key_type, - const char *hostnqn, const char *subsysnqn, - int version, int hmac, - unsigned char *configured_key, int key_len) +int nvme_insert_tls_key_versioned(const char *keyring, const char *key_type, + const char *hostnqn, const char *subsysnqn, + int version, int hmac, + unsigned char *configured_key, int key_len, + long *key) { nvme_msg(NULL, LOG_ERR, "key operations not supported; " "recompile with keyutils support.\n"); - errno = ENOTSUP; - return -1; + return -ENOTSUP; } -long nvme_revoke_tls_key(const char *keyring, const char *key_type, - const char *identity) +int nvme_revoke_tls_key(const char *keyring, const char *key_type, + const char *identity) { nvme_msg(NULL, LOG_ERR, "key operations not supported; " "recompile with keyutils support.\n"); - errno = ENOTSUP; - return -1; + return -ENOTSUP; } int __nvme_import_keys_from_config(nvme_host_t h, nvme_ctrl_t c, @@ -1638,13 +1567,13 @@ int __nvme_import_keys_from_config(nvme_host_t h, nvme_ctrl_t c, } #endif -long nvme_insert_tls_key(const char *keyring, const char *key_type, +int nvme_insert_tls_key(const char *keyring, const char *key_type, const char *hostnqn, const char *subsysnqn, int hmac, - unsigned char *configured_key, int key_len) + unsigned char *configured_key, int key_len, long *key) { return nvme_insert_tls_key_versioned(keyring, key_type, hostnqn, subsysnqn, 0, hmac, - configured_key, key_len); + configured_key, key_len, key); } /* @@ -1659,9 +1588,9 @@ long nvme_insert_tls_key(const char *keyring, const char *key_type, * s: 32 or 48 bytes binary followed by a CRC-32 of the configured PSK * (4 bytes) encoded as base64 */ -char *nvme_export_tls_key_versioned(unsigned char version, unsigned char hmac, - const unsigned char *key_data, - size_t key_len) +int nvme_export_tls_key_versioned(unsigned char version, unsigned char hmac, + const unsigned char *key_data, + size_t key_len, char **encoded_keyp) { unsigned int raw_len, encoded_len, len; unsigned long crc = crc32(0L, NULL, 0); @@ -1671,18 +1600,18 @@ char *nvme_export_tls_key_versioned(unsigned char version, unsigned char hmac, switch (hmac) { case NVME_HMAC_ALG_NONE: if (key_len != 32 && key_len != 48) - goto err_inval; + return -EINVAL; break; case NVME_HMAC_ALG_SHA2_256: if (key_len != 32) - goto err_inval; + return -EINVAL; break; case NVME_HMAC_ALG_SHA2_384: if (key_len != 48) - goto err_inval; + return -EINVAL; break; default: - goto err_inval; + return -EINVAL; } raw_len = key_len; @@ -1695,25 +1624,20 @@ char *nvme_export_tls_key_versioned(unsigned char version, unsigned char hmac, encoded_len = (raw_len * 2) + 20; encoded_key = malloc(encoded_len); - if (!encoded_key) { - errno = ENOMEM; - return NULL; - } + if (!encoded_key) + return -ENOMEM; + memset(encoded_key, 0, encoded_len); len = sprintf(encoded_key, "NVMeTLSkey-%x:%02x:", version, hmac); len += base64_encode(raw_secret, raw_len, encoded_key + len); encoded_key[len++] = ':'; encoded_key[len++] = '\0'; - return encoded_key; - -err_inval: - errno = EINVAL; - return NULL; - + *encoded_keyp = encoded_key; + return 0; } -char *nvme_export_tls_key(const unsigned char *key_data, int key_len) +int nvme_export_tls_key(const unsigned char *key_data, int key_len, char **key) { unsigned char hmac; @@ -1722,13 +1646,14 @@ char *nvme_export_tls_key(const unsigned char *key_data, int key_len) else hmac = NVME_HMAC_ALG_SHA2_384; - return nvme_export_tls_key_versioned(1, hmac, key_data, key_len); + return nvme_export_tls_key_versioned(1, hmac, key_data, key_len, key); } -unsigned char *nvme_import_tls_key_versioned(const char *encoded_key, - unsigned char *version, - unsigned char *hmac, - size_t *key_len) +int nvme_import_tls_key_versioned(const char *encoded_key, + unsigned char *version, + unsigned char *hmac, + size_t *key_len, + unsigned char **keyp) { unsigned char decoded_key[128], *key_data; unsigned int crc = crc32(0L, NULL, 0); @@ -1737,48 +1662,42 @@ unsigned char *nvme_import_tls_key_versioned(const char *encoded_key, size_t len; if (sscanf(encoded_key, "NVMeTLSkey-%d:%02x:*s", - &_version, &_hmac) != 2) { - errno = EINVAL; - return NULL; - } + &_version, &_hmac) != 2) + return -EINVAL; + + if (_version != 1) + return -EINVAL; - if (_version != 1) { - errno = EINVAL; - return NULL; - } *version = _version; len = strlen(encoded_key); switch (_hmac) { case NVME_HMAC_ALG_NONE: if (len != 65 && len != 89) - goto err_inval; + return -EINVAL; break; case NVME_HMAC_ALG_SHA2_256: if (len != 65) - goto err_inval; + return -EINVAL; break; case NVME_HMAC_ALG_SHA2_384: if (len != 89) - goto err_inval; + return -EINVAL; break; default: - errno = EINVAL; - return NULL; + return -EINVAL; } *hmac = _hmac; err = base64_decode(encoded_key + 16, len - 17, decoded_key); - if (err < 0) { - errno = ENOKEY; - return NULL; - } + if (err < 0) + return -ENOKEY; + decoded_len = err; decoded_len -= 4; - if (decoded_len != 32 && decoded_len != 48) { - errno = ENOKEY; - return NULL; - } + if (decoded_len != 32 && decoded_len != 48) + return -ENOKEY; + crc = crc32(crc, decoded_key, decoded_len); key_crc = ((uint32_t)decoded_key[decoded_len]) | ((uint32_t)decoded_key[decoded_len + 1] << 8) | @@ -1787,38 +1706,34 @@ unsigned char *nvme_import_tls_key_versioned(const char *encoded_key, if (key_crc != crc) { nvme_msg(NULL, LOG_ERR, "CRC mismatch (key %08x, crc %08x)", key_crc, crc); - errno = ENOKEY; - return NULL; + return -ENOKEY; } key_data = malloc(decoded_len); - if (!key_data) { - errno = ENOMEM; - return NULL; - } + if (!key_data) + return -ENOMEM; memcpy(key_data, decoded_key, decoded_len); *key_len = decoded_len; - return key_data; - -err_inval: - errno = EINVAL; - return NULL; + *keyp = key_data; + return 0; } -unsigned char *nvme_import_tls_key(const char *encoded_key, int *key_len, - unsigned int *hmac) +int nvme_import_tls_key(const char *encoded_key, int *key_len, + unsigned int *hmac, unsigned char **keyp) { unsigned char version, _hmac; unsigned char *psk; size_t len; + int ret; - psk = nvme_import_tls_key_versioned(encoded_key, &version, - &_hmac, &len); - if (!psk) - return NULL; + ret = nvme_import_tls_key_versioned(encoded_key, &version, + &_hmac, &len, &psk); + if (ret) + return ret; *hmac = _hmac; *key_len = len; - return psk; + *keyp = psk; + return 0; } diff --git a/src/nvme/linux.h b/src/nvme/linux.h index 47226f22a..c750cddc5 100644 --- a/src/nvme/linux.h +++ b/src/nvme/linux.h @@ -29,8 +29,8 @@ * @offset: Starting offset to send with this firmware download * @buf: Address of buffer containing all or part of the firmware image. * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_fw_download_seq(nvme_link_t l, __u32 size, __u32 xfer, __u32 offset, void *buf); @@ -41,8 +41,8 @@ int nvme_fw_download_seq(nvme_link_t l, __u32 size, __u32 xfer, __u32 offset, * @da: On success return max supported data area * @max_data_tx: On success set to max transfer chunk supported by the controller * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_get_telemetry_max(nvme_link_t l, enum nvme_telemetry_da *da, size_t *max_data_tx); @@ -60,8 +60,8 @@ int nvme_get_telemetry_max(nvme_link_t l, enum nvme_telemetry_da *da, size_t *ma * The total size allocated can be calculated as: * (nvme_telemetry_log da size + 1) * NVME_LOG_TELEM_BLOCK_SIZE. * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_get_telemetry_log(nvme_link_t l, bool create, bool ctrl, bool rae, size_t max_data_tx, enum nvme_telemetry_da da, struct nvme_telemetry_log **log, @@ -77,8 +77,8 @@ int nvme_get_telemetry_log(nvme_link_t l, bool create, bool ctrl, bool rae, size * The total size allocated can be calculated as: * (nvme_telemetry_log da size + 1) * NVME_LOG_TELEM_BLOCK_SIZE. * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_get_ctrl_telemetry(nvme_link_t l, bool rae, struct nvme_telemetry_log **log, enum nvme_telemetry_da da, size_t *size); @@ -93,8 +93,8 @@ int nvme_get_ctrl_telemetry(nvme_link_t l, bool rae, struct nvme_telemetry_log * * The total size allocated can be calculated as: * (nvme_telemetry_log da size + 1) * NVME_LOG_TELEM_BLOCK_SIZE. * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_get_host_telemetry(nvme_link_t l, struct nvme_telemetry_log **log, enum nvme_telemetry_da da, size_t *size); @@ -109,8 +109,8 @@ int nvme_get_host_telemetry(nvme_link_t l, struct nvme_telemetry_log **log, * The total size allocated can be calculated as: * (nvme_telemetry_log da size + 1) * NVME_LOG_TELEM_BLOCK_SIZE. * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_get_new_host_telemetry(nvme_link_t l, struct nvme_telemetry_log **log, enum nvme_telemetry_da da, size_t *size); @@ -130,8 +130,8 @@ size_t nvme_get_ana_log_len_from_id_ctrl(const struct nvme_id_ctrl *id_ctrl, * @l: Link handle * @analen: Pointer to where the length will be set on success * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_get_ana_log_len(nvme_link_t l, size_t *analen); @@ -141,8 +141,8 @@ int nvme_get_ana_log_len(nvme_link_t l, size_t *analen); * @nsid: Namespace id * @blksize: Pointer to where the block size will be set on success * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_get_logical_block_size(nvme_link_t l, __u32 nsid, int *blksize); @@ -152,8 +152,8 @@ int nvme_get_logical_block_size(nvme_link_t l, __u32 nsid, int *blksize); * @rae: Retain asynchronous events * @log: On success, set to the value of the allocated and retrieved log. * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_get_lba_status_log(nvme_link_t l, bool rae, struct nvme_lba_status_log **log); @@ -164,8 +164,8 @@ int nvme_get_lba_status_log(nvme_link_t l, bool rae, struct nvme_lba_status_log * @num_ctrls: Number of controllers in ctrlist * @ctrlist: List of controller IDs to perform the attach action * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_namespace_attach_ctrls(nvme_link_t l, __u32 nsid, __u16 num_ctrls, __u16 *ctrlist); @@ -176,8 +176,8 @@ int nvme_namespace_attach_ctrls(nvme_link_t l, __u32 nsid, __u16 num_ctrls, __u1 * @num_ctrls: Number of controllers in ctrlist * @ctrlist: List of controller IDs to perform the detach action * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. */ int nvme_namespace_detach_ctrls(nvme_link_t l, __u32 nsid, __u16 num_ctrls, __u16 *ctrlist); @@ -185,14 +185,14 @@ int nvme_namespace_detach_ctrls(nvme_link_t l, __u32 nsid, __u16 num_ctrls, __u1 * nvme_open() - Open an nvme controller or namespace device * @r: &nvme_root_t object * @name: The basename of the device to open + * @l: Link object to return * * This will look for the handle in /dev/ and validate the name and filetype * match linux conventions. * - * Return: A link handle for the device on a successful open, or -1 with - * errno set otherwise. + * Return: 0 on success or negative error code otherwise */ -nvme_link_t nvme_open(nvme_root_t r, const char *name); +int nvme_open(nvme_root_t r, const char *name, nvme_link_t *l); /** * nvme_close() - Close link handle @@ -274,7 +274,7 @@ enum nvme_hmac_alg { * @key: Generated DH-HMAC-CHAP key * * Return: If key generation was successful the function returns 0 or - * -1 with errno set otherwise. + * a negative error code otherwise. */ int nvme_gen_dhchap_key(char *hostnqn, enum nvme_hmac_alg hmac, unsigned int key_len, unsigned char *secret, @@ -283,13 +283,13 @@ int nvme_gen_dhchap_key(char *hostnqn, enum nvme_hmac_alg hmac, /** * nvme_lookup_keyring() - Lookup keyring serial number * @keyring: Keyring name + * @key: Key serial number to return * * Looks up the serial number of the keyring @keyring. * - * Return: The key serial number of the keyring - * or 0 with errno set otherwise. + * Return: 0 on success or negative error code otherwise */ -long nvme_lookup_keyring(const char *keyring); +int nvme_lookup_keyring(const char *keyring, long *key); /** * nvme_describe_key_serial() - Return key description @@ -305,16 +305,16 @@ char *nvme_describe_key_serial(long key_id); /** * nvme_lookup_key() - Lookup key serial number - * @type: Key type - * @identity: Key description + * @type: Key type + * @identity: Key description + * @key: Key serial number to return * * Looks up the serial number of the key @identity * with type %type in the current session keyring. * - * Return: The key serial number of the key - * or 0 with errno set otherwise. + * Return: 0 on success or negative error code otherwise */ -long nvme_lookup_key(const char *type, const char *identity); +int nvme_lookup_key(const char *type, const char *identity, long *key); /** * nvme_set_keyring() - Link keyring for lookup @@ -323,45 +323,46 @@ long nvme_lookup_key(const char *type, const char *identity); * Links @keyring_id into the session keyring such that * its keys are available for further key lookups. * - * Return: 0 on success, a negative number on error - * with errno set. + * Return: 0 on success or negative error code otherwise */ int nvme_set_keyring(long keyring_id); /** * nvme_read_key() - Read key raw data - * @keyring_id: Id of the keyring holding %key_id - * @key_id: Key id - * @len: Length of the returned data + * @keyring_id: Id of the keyring holding %key_id + * @key_id: Key id + * @len: Length of the returned data + * @key: Key serial to return * * Links the keyring specified by @keyring_id into the session * keyring and reads the payload of the key specified by @key_id. * @len holds the size of the returned buffer. * If @keyring is 0 the default keyring '.nvme' is used. * - * Return: Pointer to the payload on success, - * or NULL with errno set otherwise. + * Return: 0 on success or negative error code otherwise */ -unsigned char *nvme_read_key(long keyring_id, long key_id, int *len); +int nvme_read_key(long keyring_id, long key_id, int *len, + unsigned char **key); /** * nvme_update_key() - Update key raw data - * @keyring_id: Id of the keyring holding %key_id - * @key_type: Type of the key to insert - * @identity: Key identity string - * @key_data: Raw data of the key - * @key_len: Length of @key_data + * @keyring_id: Id of the keyring holding %key_id + * @key_type: Type of the key to insert + * @identity: Key identity string + * @key_data: Raw data of the key + * @key_len: Length of @key_data + * @key: Key serial to return * * Links the keyring specified by @keyring_id into the session * keyring and updates the key reference by @identity with @key_data. * The old key with identity @identity will be revoked to make it * inaccessible. * - * Return: Key id of the new key or 0 with errno set otherwise. + * Return: 0 on success or negative error code otherwise */ -long nvme_update_key(long keyring_id, const char *key_type, - const char *identity, unsigned char *key_data, - int key_len); +int nvme_update_key(long keyring_id, const char *key_type, + const char *identity, unsigned char *key_data, + int key_len, long *key); /** * typedef nvme_scan_tls_keys_cb_t - Callback for iterating TLS keys @@ -388,31 +389,30 @@ typedef void (*nvme_scan_tls_keys_cb_t)(long keyring, long key, * form 'NVMe<0|1>0<1|2> ', otherwise it will be skipped * during iteration. * - * Return: Number of keys for which @cb was called, or -1 with errno set - * on error. + * Return: Number of keys for which @cb was called, or negative error code */ int nvme_scan_tls_keys(const char *keyring, nvme_scan_tls_keys_cb_t cb, void *data); /** * nvme_insert_tls_key() - Derive and insert TLS key - * @keyring: Keyring to use + * @keyring: Keyring to use * @key_type: Type of the resulting key * @hostnqn: Host NVMe Qualified Name * @subsysnqn: Subsystem NVMe Qualified Name * @hmac: HMAC algorithm * @configured_key: Configured key data to derive the key from * @key_len: Length of @configured_key + * @key: Key serial to return * * Derives a 'retained' TLS key as specified in NVMe TCP 1.0a and * stores it as type @key_type in the keyring specified by @keyring. * - * Return: The key serial number if the key could be inserted into - * the keyring or 0 with errno otherwise. + * Return: 0 on success or negative error code otherwise */ -long nvme_insert_tls_key(const char *keyring, const char *key_type, +int nvme_insert_tls_key(const char *keyring, const char *key_type, const char *hostnqn, const char *subsysnqn, int hmac, - unsigned char *configured_key, int key_len); + unsigned char *configured_key, int key_len, long *key); /** * nvme_insert_tls_key_versioned() - Derive and insert TLS key @@ -424,18 +424,19 @@ long nvme_insert_tls_key(const char *keyring, const char *key_type, * @hmac: HMAC algorithm * @configured_key: Configured key data to derive the key from * @key_len: Length of @configured_key + * @key: Key serial to return * * Derives a 'retained' TLS key as specified in NVMe TCP 1.0a (if * @version s set to '0') or NVMe TP8028 (if @version is set to '1) and * stores it as type @key_type in the keyring specified by @keyring. * - * Return: The key serial number if the key could be inserted into - * the keyring or 0 with errno otherwise. + * Return: 0 on success or negative error code otherwise */ -long nvme_insert_tls_key_versioned(const char *keyring, const char *key_type, - const char *hostnqn, const char *subsysnqn, - int version, int hmac, - unsigned char *configured_key, int key_len); +int nvme_insert_tls_key_versioned(const char *keyring, const char *key_type, + const char *hostnqn, const char *subsysnqn, + int version, int hmac, + unsigned char *configured_key, int key_len, + long *key); /** * nvme_generate_tls_key_identity() - Generate the TLS key identity @@ -445,16 +446,19 @@ long nvme_insert_tls_key_versioned(const char *keyring, const char *key_type, * @hmac: HMAC algorithm * @configured_key: Configured key data to derive the key from * @key_len: Length of @configured_key + * @identity: TLS identity to return * * Derives a 'retained' TLS key as specified in NVMe TCP and * generate the corresponding TLs identity. * - * Return: The string containing the TLS identity. It is the responsibility - * of the caller to free the returned string. + * It is the responsibility of the caller to free the returned string. + * + * Return: 0 on success or negative error code otherwise */ -char *nvme_generate_tls_key_identity(const char *hostnqn, const char *subsysnqn, - int version, int hmac, - unsigned char *configured_key, int key_len); +int nvme_generate_tls_key_identity(const char *hostnqn, const char *subsysnqn, + int version, int hmac, + unsigned char *configured_key, int key_len, + char **identity); /** * nvme_revoke_tls_key() - Revoke TLS key from keyring @@ -462,24 +466,26 @@ char *nvme_generate_tls_key_identity(const char *hostnqn, const char *subsysnqn, * @key_type: Type of the key to revoke * @identity: Key identity string * - * Return: 0 on success or on failure -1 with errno set. + * Return: 0 on success or negative error code otherwise */ -long nvme_revoke_tls_key(const char *keyring, const char *key_type, - const char *identity); +int nvme_revoke_tls_key(const char *keyring, const char *key_type, + const char *identity); /** * nvme_export_tls_key() - Export a TLS key * @key_data: Raw data of the key * @key_len: Length of @key_data + * @identity: TLS identity * * Returns @key_data in the PSK Interchange format as defined in section * 3.6.1.5 of the NVMe TCP Transport specification. * - * Return: The string containing the TLS identity or NULL with errno set - * on error. It is the responsibility of the caller to free the returned + * It is the responsibility of the caller to free the returned * string. + * + * Return: 0 on success or negative error code otherwise */ -char *nvme_export_tls_key(const unsigned char *key_data, int key_len); +int nvme_export_tls_key(const unsigned char *key_data, int key_len, char **identity); /** * nvme_export_tls_key_versioned() - Export a TLS pre-shared key @@ -488,32 +494,36 @@ char *nvme_export_tls_key(const unsigned char *key_data, int key_len); * in a retained PSK * @key_data: Raw data of the key * @key_len: Length of @key_data + * @identity: TLS identity to return * * Returns @key_data in the PSK Interchange format as defined in section * 3.6.1.5 of the NVMe TCP Transport specification. * - * Return: The string containing the TLS identity or NULL with errno set - * on error. It is the responsibility of the caller to free the returned + * It is the responsibility of the caller to free the returned * string. + * + * Return: 0 on success or negative error code otherwise */ -char *nvme_export_tls_key_versioned(unsigned char version, unsigned char hmac, - const unsigned char *key_data, - size_t key_len); +int nvme_export_tls_key_versioned(unsigned char version, unsigned char hmac, + const unsigned char *key_data, + size_t key_len, char **identity); /** * nvme_import_tls_key() - Import a TLS key * @encoded_key: TLS key in PSK interchange format * @key_len: Length of the resulting key data * @hmac: HMAC algorithm + * @key: Key serial to return * * Imports @key_data in the PSK Interchange format as defined in section * 3.6.1.5 of the NVMe TCP Transport specification. * - * Return: The raw data of the PSK or NULL with errno set on error. It is - * the responsibility of the caller to free the returned string. + * It is the responsibility of the caller to free the returned string. + * + * Return: 0 on success or negative error code otherwise */ -unsigned char *nvme_import_tls_key(const char *encoded_key, int *key_len, - unsigned int *hmac); +int nvme_import_tls_key(const char *encoded_key, int *key_len, + unsigned int *hmac, unsigned char **key); /** * nvme_import_tls_key_versioned() - Import a TLS key @@ -522,17 +532,20 @@ unsigned char *nvme_import_tls_key(const char *encoded_key, int *key_len, * @hmac: HMAC algorithm used to transfor the configured * PSK in a retained PSK * @key_len: Length of the resulting key data + * @key: Key serial to return * * Imports @key_data in the PSK Interchange format as defined in section * 3.6.1.5 of the NVMe TCP Transport specification. * - * Return: The raw data of the PSK or NULL with errno set on error. It is - * the responsibility of the caller to free the returned string. + * It is the responsibility of the caller to free the returned string. + * + * Return: 0 on success or negative error code otherwise */ -unsigned char *nvme_import_tls_key_versioned(const char *encoded_key, - unsigned char *version, - unsigned char *hmac, - size_t *key_len); +int nvme_import_tls_key_versioned(const char *encoded_key, + unsigned char *version, + unsigned char *hmac, + size_t *key_len, + unsigned char **key); /** * nvme_submit_passthru - Low level ioctl wrapper for passthru commands * @l: Link handle @@ -544,7 +557,8 @@ unsigned char *nvme_import_tls_key_versioned(const char *encoded_key, * exposed as weak symbol so that the user application is able to provide their own * implementation of this function with additional debugging or logging code. * - * Return: The value from the ioctl system call (see ioctl documentation) + * Return: The value from the ioctl system call (see ioctl documentation) or + * a negative error code otherwise. */ __attribute__((weak)) int nvme_submit_passthru(nvme_link_t l, unsigned long ioctl_cmd, @@ -561,7 +575,8 @@ int nvme_submit_passthru(nvme_link_t l, unsigned long ioctl_cmd, * exposed as weak symbol so that the user application is able to provide their own * implementation of this function with additional debugging or logging code. * - * Return: The value from the ioctl system call (see ioctl documentation) + * Return: The value from the ioctl system call (see ioctl documentation) or + * a negative error code otherwise. */ __attribute__((weak)) int nvme_submit_passthru64(nvme_link_t l, unsigned long ioctl_cmd, diff --git a/src/nvme/mi.c b/src/nvme/mi.c index eb1f61fe8..58a156307 100644 --- a/src/nvme/mi.c +++ b/src/nvme/mi.c @@ -121,10 +121,8 @@ nvme_root_t nvme_mi_create_root(FILE *fp, int log_level) int fd; r = calloc(1, sizeof(*r)); - if (!r) { - errno = ENOMEM; + if (!r) return NULL; - } if (fp) { fd = fileno(fp); @@ -437,10 +435,8 @@ int nvme_mi_scan_ep(nvme_mi_ep_t ep, bool force_rescan) return rc; n_ctrl = le16_to_cpu(list.num); - if (n_ctrl > NVME_ID_CTRL_LIST_MAX) { - errno = EPROTO; - return -1; - } + if (n_ctrl > NVME_ID_CTRL_LIST_MAX) + return -EPROTO; for (i = 0; i < n_ctrl; i++) { struct nvme_link *link; @@ -508,7 +504,7 @@ int nvme_mi_async_read(nvme_mi_ep_t ep, struct nvme_mi_resp *resp) int rc = ep->transport->aem_read(ep, resp); - if (rc && errno == EWOULDBLOCK) { + if (rc == EWOULDBLOCK) { //Sometimes we might get owned tag data from the wrong endpoint. //This isn't an error, but we shouldn't process it here resp->data_len = 0;//No data to process @@ -522,8 +518,7 @@ int nvme_mi_async_read(nvme_mi_ep_t ep, struct nvme_mi_resp *resp) rc = nvme_mi_verify_resp_mic(resp); if (rc) { nvme_msg(ep->root, LOG_WARNING, "crc mismatch\n"); - errno = EBADMSG; - return -1; + return -EBADMSG; } } @@ -533,22 +528,19 @@ int nvme_mi_async_read(nvme_mi_ep_t ep, struct nvme_mi_resp *resp) if (resp->hdr_len < sizeof(struct nvme_mi_msg_hdr)) { nvme_msg(ep->root, LOG_DEBUG, "Bad response header len: %zd\n", resp->hdr_len); - errno = EPROTO; - return -1; + return -EPROTO; } if (resp->hdr->type != NVME_MI_MSGTYPE_NVME) { nvme_msg(ep->root, LOG_DEBUG, "Invalid message type 0x%02x\n", resp->hdr->type); - errno = EPROTO; - return -1; + return -EPROTO; } if (!(resp->hdr->nmp & ~(NVME_MI_ROR_REQ << 7))) { nvme_msg(ep->root, LOG_DEBUG, "ROR value in response indicates a response\n"); - errno = EIO; - return -1; + return -EIO; } if (!(resp->hdr->nmp & (NVME_MI_MT_AE << 3))) { @@ -571,25 +563,17 @@ int nvme_mi_submit(nvme_mi_ep_t ep, struct nvme_mi_req *req, user_data = nvme_mi_submit_entry(req->hdr->type, req->hdr, req->hdr_len, req->data, req->data_len); - if (req->hdr_len < sizeof(struct nvme_mi_msg_hdr)) { - errno = EINVAL; - return -1; - } + if (req->hdr_len < sizeof(struct nvme_mi_msg_hdr)) + return -EINVAL; - if (req->hdr_len & 0x3) { - errno = EINVAL; - return -1; - } + if (req->hdr_len & 0x3) + return -EINVAL; - if (resp->hdr_len < sizeof(struct nvme_mi_msg_hdr)) { - errno = EINVAL; - return -1; - } + if (resp->hdr_len < sizeof(struct nvme_mi_msg_hdr)) + return -EINVAL; - if (resp->hdr_len & 0x3) { - errno = EINVAL; - return -1; - } + if (resp->hdr_len & 0x3) + return -EINVAL; nvme_mi_ep_probe(ep); @@ -613,8 +597,7 @@ int nvme_mi_submit(nvme_mi_ep_t ep, struct nvme_mi_req *req, rc = nvme_mi_verify_resp_mic(resp); if (rc) { nvme_msg(ep->root, LOG_WARNING, "crc mismatch\n"); - errno = EBADMSG; - return -1; + return -EBADMSG; } } @@ -622,22 +605,19 @@ int nvme_mi_submit(nvme_mi_ep_t ep, struct nvme_mi_req *req, if (resp->hdr_len < sizeof(struct nvme_mi_msg_hdr)) { nvme_msg(ep->root, LOG_DEBUG, "Bad response header len: %zd\n", resp->hdr_len); - errno = EPROTO; - return -1; + return -EPROTO; } if (resp->hdr->type != NVME_MI_MSGTYPE_NVME) { nvme_msg(ep->root, LOG_DEBUG, "Invalid message type 0x%02x\n", resp->hdr->type); - errno = EPROTO; - return -1; + return -EPROTO; } if (!(resp->hdr->nmp & (NVME_MI_ROR_RSP << 7))) { nvme_msg(ep->root, LOG_DEBUG, "ROR value in response indicates a request\n"); - errno = EIO; - return -1; + return -EIO; } if ((resp->hdr->nmp & 0x1) != (req->hdr->nmp & 0x1)) { @@ -645,8 +625,7 @@ int nvme_mi_submit(nvme_mi_ep_t ep, struct nvme_mi_req *req, "Command slot mismatch: req %d, resp %d\n", req->hdr->nmp & 0x1, resp->hdr->nmp & 0x1); - errno = EIO; - return -1; + return -EIO; } nvme_mi_submit_exit(resp->hdr->type, resp->hdr, resp->hdr_len, resp->data, resp->data_len, @@ -734,10 +713,8 @@ static int nvme_mi_admin_parse_status(struct nvme_mi_resp *resp, __u32 *result) * the former two generate return values here */ - if (resp->hdr_len < sizeof(*resp_hdr)) { - errno = -EPROTO; - return -1; - } + if (resp->hdr_len < sizeof(*resp_hdr)) + return -EPROTO; resp_hdr = (struct nvme_mi_msg_resp *)resp->hdr; /* If we have a MI error, we can't be sure there's an admin header @@ -751,10 +728,8 @@ static int nvme_mi_admin_parse_status(struct nvme_mi_resp *resp, __u32 *result) /* We shouldn't hit this, as we'd have an error reported earlier. * However, for pointer safety, ensure we have a full admin header */ - if (resp->hdr_len < sizeof(*admin_hdr)) { - errno = EPROTO; - return -1; - } + if (resp->hdr_len < sizeof(*admin_hdr)) + return -EPROTO; admin_hdr = (struct nvme_mi_admin_resp_hdr *)resp->hdr; nvme_result = le32_to_cpu(admin_hdr->cdw0); @@ -776,10 +751,8 @@ static int nvme_mi_control_parse_status(struct nvme_mi_resp *resp, __u16 *cpsr) { struct nvme_mi_control_resp *control_resp; - if (resp->hdr_len < sizeof(*control_resp)) { - errno = -EPROTO; - return -1; - } + if (resp->hdr_len < sizeof(*control_resp)) + return -EPROTO; control_resp = (struct nvme_mi_control_resp *)resp->hdr; if (control_resp->status) @@ -832,35 +805,25 @@ int nvme_mi_admin_xfer(nvme_link_t link, */ /* NVMe-MI v1.2 imposes a limit of 4096 bytes on the dlen field */ - if (*resp_data_size > 4096) { - errno = EINVAL; - return -1; - } + if (*resp_data_size > 4096) + return -EINVAL; /* we only have 32 bits of offset */ - if (resp_data_offset > 0xffffffff) { - errno = EINVAL; - return -1; - } + if (resp_data_offset > 0xffffffff) + return -EINVAL; /* request and response lengths & offset must be aligned */ if ((req_data_size & 0x3) || (*resp_data_size & 0x3) || - (resp_data_offset & 0x3)) { - errno = EINVAL; - return -1; - } + (resp_data_offset & 0x3)) + return -EINVAL; /* bidirectional not permitted (see DLEN definition) */ - if (req_data_size && *resp_data_size) { - errno = EINVAL; - return -1; - } + if (req_data_size && *resp_data_size) + return -EINVAL; - if (!*resp_data_size && resp_data_offset) { - errno = EINVAL; - return -1; - } + if (!*resp_data_size && resp_data_offset) + return -EINVAL; admin_req->hdr.type = NVME_MI_MSGTYPE_NVME; admin_req->hdr.nmp = (NVME_MI_ROR_REQ << 7) | @@ -924,15 +887,13 @@ int nvme_mi_admin_admin_passthru(nvme_link_t link, __u8 opcode, __u8 flags, if (direction == NVME_DATA_TFR_BIDIRECTIONAL) { nvme_msg(link->root, LOG_ERR, "nvme_mi_admin_admin_passthru doesn't support bidirectional commands\n"); - errno = EINVAL; - return -1; + return -EINVAL; } if (data_len > 4096) { nvme_msg(link->root, LOG_ERR, "nvme_mi_admin_admin_passthru doesn't support data_len over 4096 bytes.\n"); - errno = EINVAL; - return -1; + return -EINVAL; } if (data != NULL && data_len != 0) { @@ -989,10 +950,8 @@ int nvme_mi_admin_admin_passthru(nvme_link_t link, __u8 opcode, __u8 flags, if (rc) return rc; - if (has_read_data && (resp.data_len != data_len)) { - errno = EPROTO; - return -1; - } + if (has_read_data && (resp.data_len != data_len)) + return -EPROTO; return 0; } @@ -1007,15 +966,11 @@ int nvme_mi_admin_identify_partial(nvme_link_t link, struct nvme_mi_req req; int rc; - if (args->args_size < sizeof(*args)) { - errno = EINVAL; - return -1; - } + if (args->args_size < sizeof(*args)) + return -EINVAL; - if (!size || size > 0xffffffff) { - errno = EINVAL; - return -1; - } + if (!size || size > 0xffffffff) + return -EINVAL; nvme_mi_admin_init_req(link->ep, &req, &req_hdr, link->id, nvme_admin_identify); req_hdr.cdw1 = cpu_to_le32(args->nsid); @@ -1044,10 +999,8 @@ int nvme_mi_admin_identify_partial(nvme_link_t link, /* callers will expect a full response; if the data buffer isn't * fully valid, return an error */ - if (resp.data_len != size) { - errno = EPROTO; - return -1; - } + if (resp.data_len != size) + return -EPROTO; return 0; } @@ -1145,10 +1098,8 @@ int nvme_mi_mi_xfer(nvme_mi_ep_t ep, * to the requirements of the particular command set */ - if (*resp_data_size > mi_data_xfer_size_limit) { - errno = EINVAL; - return -1; - } + if (*resp_data_size > mi_data_xfer_size_limit) + return -EINVAL; mi_req->hdr.type = NVME_MI_MSGTYPE_NVME; mi_req->hdr.nmp = (NVME_MI_ROR_REQ << 7) | @@ -1195,8 +1146,7 @@ int nvme_mi_mi_read_mi_data_subsys(nvme_mi_ep_t ep, "MI read data length mismatch: " "got %zd bytes, expected %zd\n", len, sizeof(*s)); - errno = EPROTO; - return -1; + return -EPROTO; } return 0; @@ -1216,10 +1166,8 @@ int nvme_mi_mi_read_mi_data_port(nvme_mi_ep_t ep, __u8 portid, if (rc) return rc; - if (len != sizeof(*p)) { - errno = EPROTO; - return -1; - } + if (len != sizeof(*p)) + return -EPROTO; return 0; } @@ -1255,10 +1203,8 @@ int nvme_mi_mi_read_mi_data_ctrl(nvme_mi_ep_t ep, __u16 ctrl_id, if (rc) return rc; - if (len != sizeof(*ctrl)) { - errno = EPROTO; - return -1; - } + if (len != sizeof(*ctrl)) + return -EPROTO; return 0; } @@ -1294,8 +1240,7 @@ int nvme_mi_mi_subsystem_health_status_poll(nvme_mi_ep_t ep, bool clear, "MI Subsystem Health Status length mismatch: " "got %zd bytes, expected %zd\n", resp.data_len, sizeof(*sshs)); - errno = EPROTO; - return -1; + return -EPROTO; } return 0; @@ -1416,22 +1361,17 @@ int nvme_mi_mi_config_set_async_event(nvme_mi_ep_t ep, ((__u32)aemd << 16) | ((__u16) aerd << 8) | NVME_MI_CONFIG_AE; - //Basic checks here on lengths + // Basic checks here on lengths if (enable_list_size < sizeof(struct nvme_mi_aem_enable_list) || - (sizeof(struct nvme_mi_aem_enable_list) + - enable_list->hdr.numaee * sizeof(struct nvme_mi_aem_enable_item) - > enable_list_size) - ) { - errno = EINVAL; - return -1; - } + (sizeof(struct nvme_mi_aem_enable_list) + + enable_list->hdr.numaee * sizeof(struct nvme_mi_aem_enable_item) + > enable_list_size)) + return -EINVAL; - //Some very baseic header checks + // Some very baseic header checks if (enable_list->hdr.aeelhl != sizeof(struct nvme_mi_aem_enable_list_header) || - enable_list->hdr.aeelver != 0) { - errno = EINVAL; - return -1; - } + enable_list->hdr.aeelver != 0) + return -EINVAL; return nvme_mi_mi_config_set_get_ex(ep, nvme_mi_mi_opcode_configuration_set, @@ -1616,19 +1556,14 @@ void nvme_mi_aem_aeolli_set_aeoltl(struct nvme_mi_aem_occ_list_hdr *hdr, __u32 a static int validate_enabled_list(struct nvme_mi_aem_supported_list *list, size_t len) { - if (list->hdr.aeslver != 0) { - errno = EPROTO; - return -1; - } - if (list->hdr.aeslhl != sizeof(struct nvme_mi_aem_supported_list)) { - errno = EPROTO; - return -1; - } + if (list->hdr.aeslver != 0) + return -EPROTO; + if (list->hdr.aeslhl != sizeof(struct nvme_mi_aem_supported_list)) + return -EPROTO; if (list->hdr.aest > len || list->hdr.aest != list->hdr.aeslhl + list->hdr.numaes * sizeof(struct nvme_mi_aem_supported_item)) { - errno = EPROTO; - return -1; + return -EPROTO; } return 0; } @@ -1638,18 +1573,20 @@ static int validate_occ_list_update_ctx( struct nvme_mi_aem_ctx *ctx, bool check_generation_num) { + int err; + //Make sure header fields have valid data if (len < sizeof(*occ_header)) { - errno = EPROTO; + err = -EPROTO; goto err_cleanup; } else if (occ_header->aelver != 0 || occ_header->aeolhl != sizeof(*occ_header)) { //Make sure header is the right version and length - errno = EPROTO; + err = -EPROTO; goto err_cleanup; } else if (nvme_mi_aem_aeolli_get_aeoltl(occ_header->aeolli) > len) { //Full length is bigger than the data that was received - errno = EPROTO; + err = -EPROTO; goto err_cleanup; } else if (check_generation_num && ctx->last_generation_num == @@ -1677,11 +1614,11 @@ static int validate_occ_list_update_ctx( for (int i = 0; i < occ_header->numaeo; i++) { //Validate this item if (current->aelhlen != sizeof(*current)) { - errno = EPROTO; + err = -EPROTO; goto err_cleanup; } else if (!ctx->callbacks.enabled_map.enabled[current->aeoui.aeoi]) { //This is unexpected as this AE shouldn't be enabled - errno = EPROTO; + err = -EPROTO; goto err_cleanup; } @@ -1690,7 +1627,7 @@ static int validate_occ_list_update_ctx( bytes_so_far += offset; if (bytes_so_far > nvme_mi_aem_aeolli_get_aeoltl(occ_header->aeolli)) { - errno = EPROTO; + err = -EPROTO; goto err_cleanup; } @@ -1700,7 +1637,7 @@ static int validate_occ_list_update_ctx( return 0; err_cleanup: - return -1; + return err; } int nvme_mi_aem_get_fd(nvme_mi_ep_t ep) diff --git a/src/nvme/nbft.c b/src/nvme/nbft.c index b7d0dc84d..fd94a450e 100644 --- a/src/nvme/nbft.c +++ b/src/nvme/nbft.c @@ -700,8 +700,7 @@ int nvme_nbft_read(struct nbft_info **nbft, const char *filename) if (raw_nbft_fp == NULL) { nvme_msg(NULL, LOG_ERR, "Failed to open %s: %s\n", filename, strerror(errno)); - errno = EINVAL; - return 1; + return -EINVAL; } i = fseek(raw_nbft_fp, 0L, SEEK_END); @@ -709,8 +708,7 @@ int nvme_nbft_read(struct nbft_info **nbft, const char *filename) nvme_msg(NULL, LOG_ERR, "Failed to read from %s: %s\n", filename, strerror(errno)); fclose(raw_nbft_fp); - errno = EINVAL; - return 1; + return -EINVAL; } raw_nbft_size = ftell(raw_nbft_fp); @@ -720,8 +718,7 @@ int nvme_nbft_read(struct nbft_info **nbft, const char *filename) if (!raw_nbft) { nvme_msg(NULL, LOG_ERR, "Failed to allocate memory for NBFT table"); fclose(raw_nbft_fp); - errno = ENOMEM; - return 1; + return -ENOMEM; } i = fread(raw_nbft, sizeof(*raw_nbft), raw_nbft_size, raw_nbft_fp); @@ -730,8 +727,7 @@ int nvme_nbft_read(struct nbft_info **nbft, const char *filename) filename, strerror(errno)); fclose(raw_nbft_fp); free(raw_nbft); - errno = EINVAL; - return 1; + return -EINVAL; } fclose(raw_nbft_fp); @@ -742,8 +738,7 @@ int nvme_nbft_read(struct nbft_info **nbft, const char *filename) if (!*nbft) { nvme_msg(NULL, LOG_ERR, "Could not allocate memory for NBFT\n"); free(raw_nbft); - errno = ENOMEM; - return 1; + return -ENOMEM; } (*nbft)->filename = strdup(filename); @@ -753,8 +748,7 @@ int nvme_nbft_read(struct nbft_info **nbft, const char *filename) if (parse_raw_nbft(*nbft)) { nvme_msg(NULL, LOG_ERR, "Failed to parse %s\n", filename); nvme_nbft_free(*nbft); - errno = EINVAL; - return 1; + return -EINVAL; } return 0; } diff --git a/src/nvme/tree.c b/src/nvme/tree.c index e541ce0f0..0e42d8e5b 100644 --- a/src/nvme/tree.c +++ b/src/nvme/tree.c @@ -29,6 +29,7 @@ #include "ioctl.h" #include "linux.h" #include "filters.h" +#include "nvme/api-types.h" #include "tree.h" #include "filters.h" #include "util.h" @@ -166,10 +167,8 @@ int nvme_host_get_ids(nvme_root_t r, */ if (!hid) { hid = nvmf_hostid_generate(); - if (!hid) { - errno = -ENOMEM; - return -1; - } + if (!hid) + return -ENOMEM; nvme_msg(r, LOG_DEBUG, "warning: using auto generated hostid and hostnqn\n"); @@ -178,10 +177,8 @@ int nvme_host_get_ids(nvme_root_t r, /* incomplete configuration, thus derive hostnqn from hostid */ if (!hnqn) { hnqn = nvmf_hostnqn_generate_from_hostid(hid); - if (!hnqn) { - errno = -ENOMEM; - return -1; - } + if (!hnqn) + return -ENOMEM; } /* sanity checks */ @@ -200,21 +197,24 @@ int nvme_host_get_ids(nvme_root_t r, return 0; } -nvme_host_t nvme_default_host(nvme_root_t r) +int nvme_default_host(nvme_root_t r, nvme_host_t *hp) { _cleanup_free_ char *hostnqn = NULL; _cleanup_free_ char *hostid = NULL; struct nvme_host *h; + int err; - if (nvme_host_get_ids(r, NULL, NULL, &hostnqn, &hostid)) - return NULL; + err = nvme_host_get_ids(r, NULL, NULL, &hostnqn, &hostid); + if (err) + return err; h = nvme_lookup_host(r, hostnqn, hostid); nvme_host_set_hostsymname(h, NULL); default_host = h; - return h; + *hp = h; + return 0; } static void nvme_filter_subsystem(nvme_root_t r, nvme_subsystem_t s, @@ -290,15 +290,17 @@ int nvme_scan_topology(struct nvme_root *r, nvme_scan_filter_t f, void *f_args) ctrls.num = nvme_scan_ctrls(&ctrls.ents); if (ctrls.num < 0) { nvme_msg(r, LOG_DEBUG, "failed to scan ctrls: %s\n", - strerror(errno)); + strerror(ctrls.num)); return ctrls.num; } for (i = 0; i < ctrls.num; i++) { - nvme_ctrl_t c = nvme_scan_ctrl(r, ctrls.ents[i]->d_name); - if (!c) { + nvme_ctrl_t c; + + ret = nvme_scan_ctrl(r, ctrls.ents[i]->d_name, &c); + if (!ret) { nvme_msg(r, LOG_DEBUG, "failed to scan ctrl %s: %s\n", - ctrls.ents[i]->d_name, strerror(errno)); + ctrls.ents[i]->d_name, strerror(ret)); continue; } } @@ -306,7 +308,7 @@ int nvme_scan_topology(struct nvme_root *r, nvme_scan_filter_t f, void *f_args) subsys.num = nvme_scan_subsystems(&subsys.ents); if (subsys.num < 0) { nvme_msg(r, LOG_DEBUG, "failed to scan subsystems: %s\n", - strerror(errno)); + strerror(subsys.num)); return subsys.num; } @@ -315,7 +317,7 @@ int nvme_scan_topology(struct nvme_root *r, nvme_scan_filter_t f, void *f_args) if (ret < 0) { nvme_msg(r, LOG_DEBUG, "failed to scan subsystem %s: %s\n", - subsys.ents[i]->d_name, strerror(errno)); + subsys.ents[i]->d_name, strerror(ret)); } } @@ -334,10 +336,8 @@ nvme_root_t nvme_create_root(FILE *fp, int log_level) int fd; r = calloc(1, sizeof(*r)); - if (!r) { - errno = ENOMEM; + if (!r) return NULL; - } if (fp) { fd = fileno(fp); @@ -358,42 +358,51 @@ nvme_root_t nvme_create_root(FILE *fp, int log_level) } int nvme_read_config(nvme_root_t r, const char *config_file) + { - int err = -1; - int tmp; + int err; - if (!r || !config_file) { - errno = ENODEV; - return err; - } + if (!r || !config_file) + return -ENODEV; r->config_file = strdup(config_file); - if (!r->config_file) { - errno = ENOMEM; - return err; - } + if (!r->config_file) + return -ENOMEM; - tmp = errno; err = json_read_config(r, config_file); /* * The json configuration file is optional, * so ignore errors when opening the file. */ - if (err < 0 && errno != EPROTO) { - errno = tmp; + if (err < 0 && err != -EPROTO) return 0; - } return err; } -nvme_root_t nvme_scan(const char *config_file) +int nvme_scan(const char *config_file, nvme_root_t *rp) { nvme_root_t r = nvme_create_root(NULL, DEFAULT_LOGLEVEL); + int ret; - nvme_scan_topology(r, NULL, NULL); - nvme_read_config(r, config_file); - return r; + if (!r) + return -ENOMEM; + + ret = nvme_scan_topology(r, NULL, NULL); + if (ret) + goto err; + if (config_file) { + ret = nvme_read_config(r, config_file); + if (ret) + goto err; + } + + *rp = r; + return 0; + +err: + nvme_free_root(r); + return ret; } int nvme_update_config(nvme_root_t r) @@ -811,7 +820,7 @@ static int nvme_subsystem_scan_namespaces(nvme_root_t r, nvme_subsystem_t s) if (namespaces.num < 0) { nvme_msg(r, LOG_DEBUG, "failed to scan namespaces for subsys %s: %s\n", - s->subsysnqn, strerror(errno)); + s->subsysnqn, strerror(namespaces.num)); return namespaces.num; } @@ -821,7 +830,7 @@ static int nvme_subsystem_scan_namespaces(nvme_root_t r, nvme_subsystem_t s) if (ret < 0) nvme_msg(r, LOG_DEBUG, "failed to scan namespace %s: %s\n", - namespaces.ents[i]->d_name, strerror(errno)); + namespaces.ents[i]->d_name, strerror(ret)); } return 0; @@ -865,13 +874,11 @@ static int nvme_scan_subsystem(struct nvme_root *r, const char *name) nvme_msg(r, LOG_DEBUG, "scan subsystem %s\n", name); ret = asprintf(&path, "%s/%s", nvme_subsys_sysfs_dir(), name); if (ret < 0) - return ret; + return -errno; subsysnqn = nvme_get_attr(path, "subsysnqn"); - if (!subsysnqn) { - errno = ENODEV; - return -1; - } + if (!subsysnqn) + return -ENODEV; nvme_for_each_host(r, h) { nvme_for_each_subsystem(h, _s) { /* @@ -883,10 +890,8 @@ static int nvme_scan_subsystem(struct nvme_root *r, const char *name) continue; if (strcmp(_s->name, name)) continue; - if (!nvme_subsystem_scan_namespaces(r, _s)) { - errno = EINVAL; - return -1; - } + if (!nvme_subsystem_scan_namespaces(r, _s)) + return -EINVAL; s = _s; } } @@ -898,21 +903,18 @@ static int nvme_scan_subsystem(struct nvme_root *r, const char *name) */ nvme_msg(r, LOG_DEBUG, "creating detached subsystem '%s'\n", name); - h = nvme_default_host(r); + ret = nvme_default_host(r, &h); + if (ret) + return ret; s = nvme_alloc_subsystem(h, name, subsysnqn); - if (!s) { - errno = ENOMEM; - return -1; - } - if (!nvme_subsystem_scan_namespaces(r, s)) { - errno = EINVAL; - return -1; - } + if (!s) + return -ENOMEM; + if (!nvme_subsystem_scan_namespaces(r, s)) + return -EINVAL; } else if (strcmp(s->subsysnqn, subsysnqn)) { nvme_msg(r, LOG_DEBUG, "NQN mismatch for subsystem '%s'\n", name); - errno = EINVAL; - return -1; + return -EINVAL; } return 0; @@ -979,21 +981,16 @@ static int nvme_ctrl_scan_path(nvme_root_t r, struct nvme_ctrl *c, char *name) nvme_msg(r, LOG_DEBUG, "scan controller %s path %s\n", c->name, name); - if (!c->s) { - errno = ENXIO; - return -1; - } + if (!c->s) + return -ENXIO; + ret = asprintf(&path, "%s/%s", c->sysfs_dir, name); - if (ret < 0) { - errno = ENOMEM; - return -1; - } + if (ret < 0) + return -ENOMEM; p = calloc(1, sizeof(*p)); - if (!p) { - errno = ENOMEM; - return -1; - } + if (!p) + return -ENOMEM; p->c = c; p->name = strdup(name); @@ -1027,12 +1024,13 @@ nvme_link_t nvme_ctrl_get_link(nvme_ctrl_t c) { if (!c->l) { nvme_root_t r = root_from_ctrl(c); + int err; - c->l = nvme_open(r, c->name); - if (!c->l) + err = nvme_open(r, c->name, &c->l); + if (err) nvme_msg(r, LOG_ERR, - "Failed to open ctrl %s, errno %d\n", - c->name, errno); + "Failed to open ctrl %s, error %d\n", + c->name, err); } return c->l; } @@ -1406,35 +1404,31 @@ static bool traddr_is_hostname(const char *transport, const char *traddr) return true; } -struct nvme_ctrl *nvme_create_ctrl(nvme_root_t r, - const char *subsysnqn, const char *transport, - const char *traddr, const char *host_traddr, - const char *host_iface, const char *trsvcid) +int nvme_create_ctrl(nvme_root_t r, + const char *subsysnqn, const char *transport, + const char *traddr, const char *host_traddr, + const char *host_iface, const char *trsvcid, + nvme_ctrl_t *cp) { struct nvme_ctrl *c; if (!transport) { nvme_msg(r, LOG_ERR, "No transport specified\n"); - errno = EINVAL; - return NULL; + return -EINVAL; } if (strncmp(transport, "loop", 4) && strncmp(transport, "pcie", 4) && !traddr) { nvme_msg(r, LOG_ERR, "No transport address for '%s'\n", transport); - errno = EINVAL; - return NULL; + return -EINVAL; } if (!subsysnqn) { nvme_msg(r, LOG_ERR, "No subsystem NQN specified\n"); - errno = EINVAL; - return NULL; + return -EINVAL; } c = calloc(1, sizeof(*c)); - if (!c) { - errno = ENOMEM; - return NULL; - } + if (!c) + return -ENOMEM; c->l = NULL; nvmf_default_config(&c->cfg); list_head_init(&c->namespaces); @@ -1446,7 +1440,7 @@ struct nvme_ctrl *nvme_create_ctrl(nvme_root_t r, c->traddr = strdup(traddr); if (host_traddr) { if (traddr_is_hostname(transport, host_traddr)) - c->cfg.host_traddr = hostname2traddr(r, host_traddr); + hostname2traddr(r, host_traddr, &c->cfg.host_traddr); if (!c->cfg.host_traddr) c->cfg.host_traddr = strdup(host_traddr); } @@ -1455,7 +1449,8 @@ struct nvme_ctrl *nvme_create_ctrl(nvme_root_t r, if (trsvcid) c->trsvcid = strdup(trsvcid); - return c; + *cp = c; + return 0; } /** @@ -1852,6 +1847,7 @@ nvme_ctrl_t nvme_lookup_ctrl(nvme_subsystem_t s, const char *transport, { nvme_root_t r; struct nvme_ctrl *c; + int ret; if (!s || !transport) return NULL; @@ -1862,13 +1858,15 @@ nvme_ctrl_t nvme_lookup_ctrl(nvme_subsystem_t s, const char *transport, return c; r = s->h ? s->h->r : NULL; - c = nvme_create_ctrl(r, s->subsysnqn, transport, traddr, - host_traddr, host_iface, trsvcid); - if (c) { - c->s = s; - list_add_tail(&s->ctrls, &c->entry); - s->h->r->modified = true; - } + ret = nvme_create_ctrl(r, s->subsysnqn, transport, traddr, + host_traddr, host_iface, trsvcid, &c); + if (ret) + return NULL; + + c->s = s; + list_add_tail(&s->ctrls, &c->entry); + s->h->r->modified = true; + return c; } @@ -1909,8 +1907,9 @@ static int nvme_ctrl_scan_namespaces(nvme_root_t r, struct nvme_ctrl *c) return 0; } -static char *nvme_ctrl_lookup_subsystem_name(nvme_root_t r, - const char *ctrl_name) +static int nvme_ctrl_lookup_subsystem_name(nvme_root_t r, + const char *ctrl_name, + char **name) { const char *subsys_dir = nvme_subsys_sysfs_dir(); _cleanup_dirents_ struct dirents subsys = {}; @@ -1918,26 +1917,30 @@ static char *nvme_ctrl_lookup_subsystem_name(nvme_root_t r, subsys.num = nvme_scan_subsystems(&subsys.ents); if (subsys.num < 0) - return NULL; + return subsys.num; + for (i = 0; i < subsys.num; i++) { struct stat st; _cleanup_free_ char *path = NULL; if (asprintf(&path, "%s/%s/%s", subsys_dir, - subsys.ents[i]->d_name, ctrl_name) < 0) { - errno = ENOMEM; - return NULL; - } + subsys.ents[i]->d_name, ctrl_name) < 0) + return -ENOMEM; nvme_msg(r, LOG_DEBUG, "lookup subsystem %s\n", path); if (stat(path, &st) < 0) { continue; } - return strdup(subsys.ents[i]->d_name); + + *name = strdup(subsys.ents[i]->d_name); + if (!*name) + return -ENOMEM; + + return 0; } - return NULL; + return -ENOENT; } -static char *nvme_ctrl_lookup_phy_slot(nvme_root_t r, const char *address) +static int nvme_ctrl_lookup_phy_slot(nvme_root_t r, const char *address, char **slot) { const char *slots_sysfs_dir = nvme_slots_sysfs_dir(); _cleanup_free_ char *target_addr = NULL; @@ -1946,13 +1949,13 @@ static char *nvme_ctrl_lookup_phy_slot(nvme_root_t r, const char *address) struct dirent *entry; if (!address) - return NULL; + return -EINVAL; slots_dir = opendir(slots_sysfs_dir); if (!slots_dir) { nvme_msg(r, LOG_WARNING, "failed to open slots dir %s\n", slots_sysfs_dir); - return NULL; + return -errno; } target_addr = strndup(address, 10); @@ -1965,20 +1968,24 @@ static char *nvme_ctrl_lookup_phy_slot(nvme_root_t r, const char *address) ret = asprintf(&path, "%s/%s", slots_sysfs_dir, entry->d_name); - if (ret < 0) { - errno = ENOMEM; - return NULL; - } + if (ret < 0) + return -ENOMEM; addr = nvme_get_attr(path, "address"); /* some directories don't have an address entry */ if (!addr) continue; - if (strcmp(addr, target_addr) == 0) - return strdup(entry->d_name); + if (strcmp(addr, target_addr)) + continue; + + *slot = strdup(entry->d_name); + if (*slot) + return -ENOMEM; + + return 0; } } - return NULL; + return -ENOENT; } static void nvme_read_sysfs_dhchap(nvme_root_t r, nvme_ctrl_t c) @@ -2070,8 +2077,7 @@ static int nvme_reconfigure_ctrl(nvme_root_t r, nvme_ctrl_t c, const char *path, if (!d) { nvme_msg(r, LOG_ERR, "Failed to open ctrl dir %s, error %d\n", path, errno); - errno = ENODEV; - return -1; + return -ENODEV; } closedir(d); @@ -2088,11 +2094,10 @@ static int nvme_reconfigure_ctrl(nvme_root_t r, nvme_ctrl_t c, const char *path, c->cntrltype = nvme_get_ctrl_attr(c, "cntrltype"); c->cntlid = nvme_get_ctrl_attr(c, "cntlid"); c->dctype = nvme_get_ctrl_attr(c, "dctype"); - c->phy_slot = nvme_ctrl_lookup_phy_slot(r, c->address); + nvme_ctrl_lookup_phy_slot(r, c->address, &c->phy_slot); nvme_read_sysfs_dhchap(r, c); nvme_read_sysfs_tls(r, c); - errno = 0; /* cleanup after nvme_get_ctrl_attr() */ return 0; } @@ -2103,48 +2108,45 @@ int nvme_init_ctrl(nvme_host_t h, nvme_ctrl_t c, int instance) int ret; ret = asprintf(&name, "nvme%d", instance); - if (ret < 0) { - errno = ENOMEM; - return -1; - } + if (ret < 0) + return -ENOMEM; + ret = asprintf(&path, "%s/%s", nvme_ctrl_sysfs_dir(), name); - if (ret < 0) { - errno = ENOMEM; - return ret; - } + if (ret < 0) + return -ENOMEM; ret = nvme_reconfigure_ctrl(h->r, c, path, name); if (ret < 0) return ret; c->address = nvme_get_attr(path, "address"); - if (!c->address && strcmp(c->transport, "loop")) { - errno = ENVME_CONNECT_INVAL_TR; - return -1; - } + if (!c->address && strcmp(c->transport, "loop")) + return -ENVME_CONNECT_INVAL_TR; - subsys_name = nvme_ctrl_lookup_subsystem_name(h->r, name); - if (!subsys_name) { + ret = nvme_ctrl_lookup_subsystem_name(h->r, name, &subsys_name); + if (ret) { nvme_msg(h->r, LOG_ERR, "Failed to lookup subsystem name for %s\n", c->name); - errno = ENVME_CONNECT_LOOKUP_SUBSYS_NAME; - return -1; + return ENVME_CONNECT_LOOKUP_SUBSYS_NAME; } + s = nvme_lookup_subsystem(h, subsys_name, c->subsysnqn); - if (!s) { - errno = ENVME_CONNECT_LOOKUP_SUBSYS; - return -1; - } + if (!s) + return -ENVME_CONNECT_LOOKUP_SUBSYS; + if (s->subsystype && !strcmp(s->subsystype, "discovery")) c->discovery_ctrl = true; + c->s = s; list_add_tail(&s->ctrls, &c->entry); + return ret; } -static nvme_ctrl_t nvme_ctrl_alloc(nvme_root_t r, nvme_subsystem_t s, - const char *path, const char *name) +int nvme_ctrl_alloc(nvme_root_t r, nvme_subsystem_t s, + const char *path, const char *name, + nvme_ctrl_t *cp) { _cleanup_free_ char *addr = NULL, *address = NULL, *transport = NULL; char *host_traddr = NULL, *host_iface = NULL; @@ -2154,10 +2156,9 @@ static nvme_ctrl_t nvme_ctrl_alloc(nvme_root_t r, nvme_subsystem_t s, int ret; transport = nvme_get_attr(path, "transport"); - if (!transport) { - errno = ENXIO; - return NULL; - } + if (!transport) + return -ENXIO; + /* Parse 'address' string into components */ addr = nvme_get_attr(path, "address"); if (!addr) { @@ -2169,16 +2170,12 @@ static nvme_ctrl_t nvme_ctrl_alloc(nvme_root_t r, nvme_subsystem_t s, goto skip_address; /* Older kernel don't support pcie transport addresses */ - if (strcmp(transport, "pcie")) { - errno = ENXIO; - return NULL; - } + if (strcmp(transport, "pcie")) + return -ENXIO; /* Figure out the PCI address from the attribute path */ rpath = realpath(path, NULL); - if (!rpath) { - errno = ENOMEM; - return NULL; - } + if (!rpath) + return -ENOMEM; a = strtok_r(rpath, "/", &e); while(a && strlen(a)) { if (_a) @@ -2229,18 +2226,23 @@ static nvme_ctrl_t nvme_ctrl_alloc(nvme_root_t r, nvme_subsystem_t s, c = p; if (!c && !p) { nvme_msg(r, LOG_ERR, "failed to lookup ctrl\n"); - errno = ENODEV; - return NULL; + return -ENODEV; } FREE_CTRL_ATTR(c->address); c->address = strdup(addr); if (s->subsystype && !strcmp(s->subsystype, "discovery")) c->discovery_ctrl = true; + ret = nvme_reconfigure_ctrl(r, c, path, name); - return (ret < 0) ? NULL : c; + if (ret) { + nvme_free_ctrl(c); + return ret; + } + *cp = c; + return 0; } -nvme_ctrl_t nvme_scan_ctrl(nvme_root_t r, const char *name) +int nvme_scan_ctrl(nvme_root_t r, const char *name, nvme_ctrl_t *cp) { _cleanup_free_ char *subsysnqn = NULL, *subsysname = NULL; _cleanup_free_ char *hostnqn = NULL, *hostid = NULL; @@ -2252,10 +2254,8 @@ nvme_ctrl_t nvme_scan_ctrl(nvme_root_t r, const char *name) nvme_msg(r, LOG_DEBUG, "scan controller %s\n", name); ret = asprintf(&path, "%s/%s", nvme_ctrl_sysfs_dir(), name); - if (ret < 0) { - errno = ENOMEM; - return NULL; - } + if (ret < 0) + return -ENOMEM; hostnqn = nvme_get_attr(path, "hostnqn"); hostid = nvme_get_attr(path, "hostid"); @@ -2269,40 +2269,36 @@ nvme_ctrl_t nvme_scan_ctrl(nvme_root_t r, const char *name) } } if (!h) { - h = nvme_default_host(r); - if (!h) { - errno = ENOMEM; - return NULL; - } + ret = nvme_default_host(r, &h); + if (ret) + return ret; } subsysnqn = nvme_get_attr(path, "subsysnqn"); - if (!subsysnqn) { - errno = ENXIO; - return NULL; - } - subsysname = nvme_ctrl_lookup_subsystem_name(r, name); - if (!subsysname) { + if (!subsysnqn) + return -ENXIO; + + ret = nvme_ctrl_lookup_subsystem_name(r, name, &subsysname); + if (ret) { nvme_msg(r, LOG_DEBUG, "failed to lookup subsystem for controller %s\n", name); - errno = ENXIO; - return NULL; + return ret; } - s = nvme_lookup_subsystem(h, subsysname, subsysnqn); - if (!s) { - errno = ENOMEM; - return NULL; - } + s = nvme_lookup_subsystem(h, subsysname, subsysnqn); + if (!s) + return -ENOMEM; - c = nvme_ctrl_alloc(r, s, path, name); - if (!c) - return NULL; + ret = nvme_ctrl_alloc(r, s, path, name, &c); + if (ret) + return ret; nvme_ctrl_scan_paths(r, c); nvme_ctrl_scan_namespaces(r, c); - return c; + + *cp = c; + return 0; } void nvme_rescan_ctrl(struct nvme_ctrl *c) @@ -2321,13 +2317,12 @@ static int nvme_bytes_to_lba(nvme_ns_t n, off_t offset, size_t count, int bs; bs = nvme_ns_get_lba_size(n); - if (!count || offset & (bs - 1) || count & (bs - 1)) { - errno = EINVAL; - return -1; - } + if (!count || offset & (bs - 1) || count & (bs - 1)) + return -EINVAL; *lba = offset >> n->lba_shift; *nlb = (count >> n->lba_shift) - 1; + return 0; } @@ -2335,12 +2330,13 @@ nvme_link_t nvme_ns_get_link(nvme_ns_t n) { if (!n->l) { nvme_root_t r = root_from_ns(n); + int err; - n->l = nvme_open(r, n->name); - if (!n->l) + err = nvme_open(r, n->name, &n->l); + if (err) nvme_msg(r, LOG_ERR, - "Failed to open ns %s, errno %d\n", - n->name, errno); + "Failed to open ns %s, error %d\n", + n->name, err); } return n->l; @@ -2749,7 +2745,8 @@ static int nvme_ns_init(const char *path, struct nvme_ns *ns) ns->lba_count = size >> (ns->lba_shift - SECTOR_SHIFT); if (asprintf(&attr, "%s/csi", path) < 0) - return -errno; + return -ENOMEM; + ret = stat(attr, &sb); if (ret == 0) { /* only available on kernels >= 6.8 */ @@ -2798,7 +2795,7 @@ static void nvme_ns_set_generic_name(struct nvme_ns *n, const char *name) n->generic_name = strdup(generic_name); } -static nvme_ns_t nvme_ns_open(const char *sys_path, const char *name) +int nvme_ns_open(const char *sys_path, const char *name, nvme_ns_t *ns) { int ret; struct nvme_ns *n; @@ -2807,25 +2804,21 @@ static nvme_ns_t nvme_ns_open(const char *sys_path, const char *name) _cleanup_free_ char *path = NULL; n = calloc(1, sizeof(*n)); - if (!n) { - errno = ENOMEM; - return NULL; - } + if (!n) + return -ENOMEM; head = calloc(1, sizeof(*head)); if (!head) { - errno = ENOMEM; free(n); - return NULL; + return -ENOMEM; } head->n = n; list_head_init(&head->paths); ret = asprintf(&path, "%s/%s", sys_path, "multipath"); - if (ret < 0) { - errno = ENOMEM; + if (ret < 0) goto free_ns_head; - } + /* * The sysfs-dir "multipath" is available only when nvme multipath * is configured and we're running kernel version >= 6.14. @@ -2843,13 +2836,16 @@ static nvme_ns_t nvme_ns_open(const char *sys_path, const char *name) nvme_ns_set_generic_name(n, name); - if (nvme_ns_init(sys_path, n) != 0) + ret = nvme_ns_init(sys_path, n); + if (ret) goto free_ns; list_node_init(&n->entry); nvme_ns_release_link(n); - return n; + + *ns = n; + return 0; free_ns: free(n->generic_name); @@ -2857,7 +2853,7 @@ static nvme_ns_t nvme_ns_open(const char *sys_path, const char *name) free_ns_head: free(head); free(n); - return NULL; + return ret; } static inline bool nvme_ns_is_generic(const char *name) @@ -2884,38 +2880,35 @@ static char *nvme_ns_generic_to_blkdev(const char *generic) return strdup(blkdev); } -static struct nvme_ns *__nvme_scan_namespace(const char *sysfs_dir, const char *name) +static int __nvme_scan_namespace(const char *sysfs_dir, const char *name, nvme_ns_t *ns) { - struct nvme_ns *n; + _cleanup_free_ char *blkdev = NULL; _cleanup_free_ char *path = NULL; + struct nvme_ns *n; int ret; - _cleanup_free_ char *blkdev = NULL; blkdev = nvme_ns_generic_to_blkdev(name); - if (!blkdev) { - errno = ENOMEM; - return NULL; - } + if (!blkdev) + return -ENOMEM; ret = asprintf(&path, "%s/%s", sysfs_dir, blkdev); - if (ret < 0) { - errno = ENOMEM; - return NULL; - } + if (ret < 0) + return -ENOMEM; - n = nvme_ns_open(path, blkdev); - if (!n) - return NULL; + ret = nvme_ns_open(path, blkdev, &n); + if (ret) + return ret; n->sysfs_dir = path; path = NULL; - return n; + *ns = n; + return 0; } -nvme_ns_t nvme_scan_namespace(const char *name) +int nvme_scan_namespace(const char *name, nvme_ns_t *ns) { - return __nvme_scan_namespace(nvme_ns_sysfs_dir(), name); + return __nvme_scan_namespace(nvme_ns_sysfs_dir(), name, ns); } @@ -2987,18 +2980,18 @@ static int nvme_ctrl_scan_namespace(nvme_root_t r, struct nvme_ctrl *c, char *name) { struct nvme_ns *n, *_n, *__n; + int ret; nvme_msg(r, LOG_DEBUG, "scan controller %s namespace %s\n", c->name, name); if (!c->s) { nvme_msg(r, LOG_DEBUG, "no subsystem for %s\n", name); - errno = EINVAL; - return -1; + return -EINVAL; } - n = __nvme_scan_namespace(c->sysfs_dir, name); - if (!n) { + ret = __nvme_scan_namespace(c->sysfs_dir, name, &n); + if (ret) { nvme_msg(r, LOG_DEBUG, "failed to scan namespace %s\n", name); - return -1; + return ret; } nvme_ctrl_for_each_ns_safe(c, _n, __n) { if (strcmp(n->name, _n->name)) @@ -3017,13 +3010,14 @@ static int nvme_subsystem_scan_namespace(nvme_root_t r, nvme_subsystem_t s, char *name) { struct nvme_ns *n, *_n, *__n; + int ret; nvme_msg(r, LOG_DEBUG, "scan subsystem %s namespace %s\n", s->name, name); - n = __nvme_scan_namespace(s->sysfs_dir, name); - if (!n) { + ret = __nvme_scan_namespace(s->sysfs_dir, name, &n); + if (ret) { nvme_msg(r, LOG_DEBUG, "failed to scan namespace %s\n", name); - return -1; + return ret; } nvme_subsystem_for_each_ns_safe(s, _n, __n) { struct nvme_path *p, *_p; diff --git a/src/nvme/tree.h b/src/nvme/tree.h index 904d2c071..db5c70a07 100644 --- a/src/nvme/tree.h +++ b/src/nvme/tree.h @@ -151,13 +151,14 @@ bool nvme_host_is_pdc_enabled(nvme_host_t h, bool fallback); /** * nvme_default_host() - Initializes the default host * @r: &nvme_root_t object + * @h: &nvme_host_t object to return * * Initializes the default host object based on the hostnqn/hostid * values returned by nvme_host_get_ids() and attaches it to @r. * - * Return: &nvme_host_t object + * Return: 0 on success or negative error code otherwise */ -nvme_host_t nvme_default_host(nvme_root_t r); +int nvme_default_host(nvme_root_t r, nvme_host_t *h); /** * nvme_host_get_ids - Retrieve host ids from various sources @@ -188,7 +189,7 @@ nvme_host_t nvme_default_host(nvme_root_t r); * NVMe implementation expects a 1:1 matching between the IDs. * * Return: 0 on success (@hostnqn and @hostid contain valid strings - * which the caller needs to free), -1 otherwise and errno is set. + * which the caller needs to free), or negative error code otherwise. */ int nvme_host_get_ids(nvme_root_t r, char *hostnqn_arg, char *hostid_arg, @@ -388,15 +389,17 @@ bool nvme_ctrl_config_match(struct nvme_ctrl *c, const char *transport, * @host_traddr: Host transport address * @host_iface: Host interface name * @trsvcid: Transport service ID + * @c: @nvme_ctrl_t object to return * * Creates an unconnected controller to be used for nvme_add_ctrl(). * - * Return: Controller instance + * Return: 0 on success or negative error code otherwise */ -nvme_ctrl_t nvme_create_ctrl(nvme_root_t r, - const char *subsysnqn, const char *transport, - const char *traddr, const char *host_traddr, - const char *host_iface, const char *trsvcid); +int nvme_create_ctrl(nvme_root_t r, + const char *subsysnqn, const char *transport, + const char *traddr, const char *host_traddr, + const char *host_iface, const char *trsvcid, + nvme_ctrl_t *c); /** @@ -1258,12 +1261,13 @@ int nvme_disconnect_ctrl(nvme_ctrl_t c); * nvme_scan_ctrl() - Scan on a controller * @r: nvme_root_t object * @name: Name of the controller + * @c: @nvme_ctrl_t object to return * * Scans a controller with sysfs name @name and add it to @r. * - * Return: nvme_ctrl_t object + * Return: 0 on success or negative error code otherwise */ -nvme_ctrl_t nvme_scan_ctrl(nvme_root_t r, const char *name); +int nvme_scan_ctrl(nvme_root_t r, const char *name, nvme_ctrl_t *c); /** * nvme_rescan_ctrl() - Rescan an existing controller @@ -1277,7 +1281,7 @@ void nvme_rescan_ctrl(nvme_ctrl_t c); * @c: nvme_ctrl_t object * @instance: Instance number (e.g. 1 for nvme1) * - * Return: The ioctl() return code. Typically 0 on success. + * Return: 0 on success or negative error code otherwise */ int nvme_init_ctrl(nvme_host_t h, nvme_ctrl_t c, int instance); @@ -1385,7 +1389,7 @@ const char *nvme_subsystem_get_fw_rev(nvme_subsystem_t s); * Scans the NVMe topology and filters out the resulting elements * by applying @f. * - * Returns: 0 on success, -1 on failure with errno set. + * Return: 0 on success, or negative error code otherwise. */ int nvme_scan_topology(nvme_root_t r, nvme_scan_filter_t f, void *f_args); @@ -1424,10 +1428,11 @@ void nvme_free_host(nvme_host_t h); /** * nvme_scan() - Scan NVMe topology * @config_file: Configuration file + * @r: &nvme_root_t object to return * - * Return: nvme_root_t object of found elements + * Return: 0 on success or negative error code otherwise */ -nvme_root_t nvme_scan(const char *config_file); +int nvme_scan(const char *config_file, nvme_root_t *r); /** * nvme_read_config() - Read NVMe JSON configuration file @@ -1437,7 +1442,7 @@ nvme_root_t nvme_scan(const char *config_file); * Read in the contents of @config_file and merge them with * the elements in @r. * - * Returns: 0 on success, -1 on failure with errno set. + * Return: 0 on success or negative error code otherwise */ int nvme_read_config(nvme_root_t r, const char *config_file); @@ -1466,7 +1471,7 @@ int nvme_update_config(nvme_root_t r); * Prints the current contents of the JSON configuration * file to stdout. * - * Return: 0 on success, -1 on failure. + * Return: 0 on success, or negative error code otherwise. */ int nvme_dump_config(nvme_root_t r); @@ -1477,7 +1482,7 @@ int nvme_dump_config(nvme_root_t r); * Prints the internal object tree in JSON format * to stdout. * - * Return: 0 on success, -1 on failure. + * Return: 0 on success or negative error code otherwise */ int nvme_dump_tree(nvme_root_t r); @@ -1486,8 +1491,8 @@ int nvme_dump_tree(nvme_root_t r); * @d: sysfs directory * @attr: sysfs attribute name * - * Return: String with the contents of @attr or %NULL in case of an empty value - * or in case of an error (indicated by non-zero errno code). + * Return: String with the contents of @attr or %NULL in case of an empty + * value or error. */ char *nvme_get_attr(const char *d, const char *attr); @@ -1496,8 +1501,8 @@ char *nvme_get_attr(const char *d, const char *attr); * @s: nvme_subsystem_t object * @attr: sysfs attribute name * - * Return: String with the contents of @attr or %NULL in case of an empty value - * or in case of an error (indicated by non-zero errno code). + * Return: String with the contents of @attr or %NULL in case of an empty + * value or error. */ char *nvme_get_subsys_attr(nvme_subsystem_t s, const char *attr); @@ -1507,7 +1512,7 @@ char *nvme_get_subsys_attr(nvme_subsystem_t s, const char *attr); * @attr: sysfs attribute name * * Return: String with the contents of @attr or %NULL in case of an empty value - * or in case of an error (indicated by non-zero errno code). + * or in case of an error. */ char *nvme_get_ctrl_attr(nvme_ctrl_t c, const char *attr); @@ -1517,7 +1522,7 @@ char *nvme_get_ctrl_attr(nvme_ctrl_t c, const char *attr); * @attr: sysfs attribute name * * Return: String with the contents of @attr or %NULL in case of an empty value - * or in case of an error (indicated by non-zero errno code). + * or in case of an error. */ char *nvme_get_ns_attr(nvme_ns_t n, const char *attr); @@ -1549,17 +1554,18 @@ void nvme_subsystem_release_fds(struct nvme_subsystem *s); * @attr: sysfs attribute name * * Return: String with the contents of @attr or %NULL in case of an empty value - * or in case of an error (indicated by non-zero errno code). + * or in case of an error. */ char *nvme_get_path_attr(nvme_path_t p, const char *attr); /** * nvme_scan_namespace() - scan namespace based on sysfs name * @name: sysfs name of the namespace to scan + * @ns: &nvme_ns_t object to return * - * Return: nvme_ns_t object or NULL if not found. + * Return: 0 on success or negative error code otherwise */ -nvme_ns_t nvme_scan_namespace(const char *name); +int nvme_scan_namespace(const char *name, nvme_ns_t *ns); /** * nvme_host_get_hostsymname() - Get the host's symbolic name diff --git a/src/nvme/util.c b/src/nvme/util.c index ee9cacd57..41d4d38ea 100644 --- a/src/nvme/util.c +++ b/src/nvme/util.c @@ -180,7 +180,7 @@ __u8 nvme_status_to_errno(int status, bool fabrics) if (!status) return 0; if (status < 0) - return errno; + return -status; sc = nvme_status_code(status); switch (nvme_status_code_type(status)) { @@ -378,7 +378,7 @@ const char *nvme_status_to_string(int status, bool fabrics) __u16 sc, sct; if (status < 0) - return strerror(errno); + return strerror(-status); sc = nvme_status_code(status); sct = nvme_status_code_type(status); @@ -574,8 +574,7 @@ int nvme_get_feature_length(int fid, __u32 cdw11, enum nvme_data_tfr dir, *len = NVME_FEAT_FDPE_NOET_MASK * sizeof(struct nvme_fdp_supported_event_desc); break; default: - errno = EINVAL; - return -1; + return -EINVAL; } return 0; } @@ -590,8 +589,7 @@ int nvme_get_directive_receive_length(enum nvme_directive_dtype dtype, *len = sizeof(struct nvme_id_directives); return 0; default: - errno = EINVAL; - return -1; + return -EINVAL; } case NVME_DIRECTIVE_DTYPE_STREAMS: switch (doper) { @@ -605,12 +603,10 @@ int nvme_get_directive_receive_length(enum nvme_directive_dtype dtype, *len = 0; return 0; default: - errno = EINVAL; - return -1; + return -EINVAL; } default: - errno = EINVAL; - return -1; + return -EINVAL; } } @@ -646,19 +642,19 @@ const char *nvme_errno_to_string(int status) } #ifdef HAVE_NETDB -char *hostname2traddr(nvme_root_t r, const char *traddr) +int hostname2traddr(nvme_root_t r, const char *traddr, char **hostname) { - struct addrinfo *host_info, hints = {.ai_family = AF_UNSPEC}; + _cleanup_addrinfo_ struct addrinfo *host_info = NULL; + struct addrinfo hints = {.ai_family = AF_UNSPEC}; char addrstr[NVMF_TRADDR_SIZE]; const char *p; - char *ret_traddr = NULL; int ret; ret = getaddrinfo(traddr, NULL, &hints, &host_info); if (ret) { nvme_msg(r, LOG_ERR, "failed to resolve host %s info\n", traddr); - return NULL; + return -errno; } switch (host_info->ai_family) { @@ -675,28 +671,27 @@ char *hostname2traddr(nvme_root_t r, const char *traddr) default: nvme_msg(r, LOG_ERR, "unrecognized address family (%d) %s\n", host_info->ai_family, traddr); - goto free_addrinfo; + return -EINVAL; } if (!p) { nvme_msg(r, LOG_ERR, "failed to get traddr for %s\n", traddr); - goto free_addrinfo; + return -EIO; } - ret_traddr = strdup(addrstr); + *hostname = strdup(addrstr); + if (!*hostname) + return -ENOMEM; -free_addrinfo: - freeaddrinfo(host_info); - return ret_traddr; + return 0; } #else /* HAVE_NETDB */ -char *hostname2traddr(nvme_root_t r, const char *traddr) +int hostname2traddr(nvme_root_t r, const char *traddr, char **hostname) { nvme_msg(r, LOG_ERR, "No support for hostname IP address resolution; " \ "recompile with libnss support.\n"); - errno = -ENOTSUP; - return NULL; + return -ENOTSUP; } #endif /* HAVE_NETDB */ @@ -972,10 +967,8 @@ int nvme_uuid_find(struct nvme_id_uuid_list *uuid_list, const unsigned char uuid { const unsigned char uuid_end[NVME_UUID_LEN] = {0}; - if ((!uuid_list) || (!uuid)) { - errno = EINVAL; - return -1; - } + if ((!uuid_list) || (!uuid)) + return -EINVAL; for (int i = 0; i < NVME_ID_UUID_LIST_MAX; i++) { if (memcmp(uuid, &uuid_list->entry[i].uuid, NVME_UUID_LEN) == 0) @@ -983,8 +976,7 @@ int nvme_uuid_find(struct nvme_id_uuid_list *uuid_list, const unsigned char uuid if (memcmp(uuid_end, &uuid_list->entry[i].uuid, NVME_UUID_LEN) == 0) break; } - errno = ENOENT; - return -1; + return -ENOENT; } #ifdef HAVE_NETDB diff --git a/src/nvme/util.h b/src/nvme/util.h index 47f9b6642..526a4ed1c 100644 --- a/src/nvme/util.h +++ b/src/nvme/util.h @@ -503,7 +503,7 @@ static inline void nvme_id_ns_flbas_to_lbaf_inuse(__u8 flbas, __u8 *lbaf_inuse) struct nvme_root; -char *hostname2traddr(struct nvme_root *r, const char *traddr); +int hostname2traddr(struct nvme_root *r, const char *traddr, char **hostname); /** * get_entity_name - Get Entity Name (ENAME). diff --git a/test/config/config-dump.c b/test/config/config-dump.c index bc781fb76..06eb43390 100644 --- a/test/config/config-dump.c +++ b/test/config/config-dump.c @@ -4,6 +4,7 @@ * Copyright (c) 2024 Daniel Wagner, SUSE LLC */ +#include "nvme/log.h" #include #include #include @@ -17,15 +18,13 @@ static bool config_dump(const char *file) nvme_root_t r; int err; - r = nvme_create_root(stderr, LOG_ERR); + r = nvme_create_root(stderr, DEFAULT_LOGLEVEL); if (!r) return false; err = nvme_scan_topology(r, NULL, NULL); - if (err) { - if (errno != ENOENT) - goto out; - } + if (err < 0 && err != -ENOENT) + goto out; err = nvme_read_config(r, file); if (err) diff --git a/test/config/hostnqn-order.c b/test/config/hostnqn-order.c index b7df61ece..27807ab60 100644 --- a/test/config/hostnqn-order.c +++ b/test/config/hostnqn-order.c @@ -23,10 +23,8 @@ static bool command_line(void) return false; err = nvme_scan_topology(r, NULL, NULL); - if (err) { - if (errno != ENOENT) - goto out; - } + if (err && err != ENOENT) + goto out; hostnqn = "nqn.2014-08.org.nvmexpress:uuid:ce4fee3e-c02c-11ee-8442-830d068a36c6"; hostid = "ce4fee3e-c02c-11ee-8442-830d068a36c6"; @@ -74,10 +72,8 @@ static bool json_config(char *file) goto out; err = nvme_scan_topology(r, NULL, NULL); - if (err) { - if (errno != ENOENT) - goto out; - } + if (err && err != ENOENT) + goto out; hostnqn = "nqn.2014-08.org.nvmexpress:uuid:2cd2c43b-a90a-45c1-a8cd-86b33ab273b5"; hostid = "2cd2c43b-a90a-45c1-a8cd-86b33ab273b5"; @@ -123,10 +119,8 @@ static bool from_file(void) return false; err = nvme_scan_topology(r, NULL, NULL); - if (err) { - if (errno != ENOENT) - goto out; - } + if (err && err != ENOENT) + goto out; err = nvme_host_get_ids(r, NULL, NULL, &hnqn, &hid); if (err) diff --git a/test/config/psk-json.c b/test/config/psk-json.c index 5d0c8bbff..5b65a03bc 100644 --- a/test/config/psk-json.c +++ b/test/config/psk-json.c @@ -18,21 +18,23 @@ static bool import_export_key(nvme_ctrl_t c) unsigned char version, hmac, *key; char *encoded_key; size_t len; + int ret; - key = nvme_import_tls_key_versioned(nvme_ctrl_get_tls_key(c), - &version, &hmac, &len); - if (!key) { + ret = nvme_import_tls_key_versioned(nvme_ctrl_get_tls_key(c), + &version, &hmac, &len, &key); + if (ret) { printf("ERROR: nvme_import_tls_key_versioned failed with %d\n", - errno); + ret); return false; } - encoded_key = nvme_export_tls_key_versioned(version, hmac, key, len); + ret = nvme_export_tls_key_versioned(version, hmac, key, len, + &encoded_key); free(key); - if (!encoded_key) { + if (ret) { printf("ERROR: nvme_export_tls_key_versioned failed with %d\n", - errno); + ret); return false; } diff --git a/test/cpp.cc b/test/cpp.cc index 07d4522ad..403d77aac 100644 --- a/test/cpp.cc +++ b/test/cpp.cc @@ -19,8 +19,7 @@ int main() nvme_path_t p; nvme_ns_t n; - r = nvme_scan(NULL); - if (!r) + if (nvme_scan(NULL, &r)) return -1; nvme_for_each_host(r, h) { diff --git a/test/ioctl/ana.c b/test/ioctl/ana.c index 7db358939..44ec41ae3 100644 --- a/test/ioctl/ana.c +++ b/test/ioctl/ana.c @@ -25,9 +25,9 @@ static void test_no_retries(void) __u32 len = sizeof(log); /* max_retries = 0 is nonsensical */ - check(nvme_get_ana_log_atomic(test_link, false, false, 0, &log, &len), + check(nvme_get_ana_log_atomic(test_link, false, false, + 0, &log, &len) == -EINVAL, "get log page succeeded"); - check(errno == EINVAL, "unexpected error: %m"); } static void test_len_too_short(void) @@ -36,9 +36,9 @@ static void test_len_too_short(void) __u32 len = sizeof(log) - 1; /* Provided buffer doesn't have enough space to read the header */ - check(nvme_get_ana_log_atomic(test_link, false, false, 1, &log, &len), + check(nvme_get_ana_log_atomic(test_link, false, false, + 1, &log, &len) == -ENOSPC, "get log page succeeded"); - check(errno == ENOSPC, "unexpected error: %m"); } static void test_no_groups(void) @@ -60,7 +60,7 @@ static void test_no_groups(void) header.ngrps = cpu_to_le16(0); set_mock_admin_cmds(&mock_admin_cmd, 1); check(!nvme_get_ana_log_atomic(test_link, false, false, 1, &log, &len), - "get log page failed: %m"); + "get log page failed"); end_mock_cmds(); cmp(&log, &header, sizeof(header), "incorrect header"); check(len == sizeof(header), @@ -98,7 +98,7 @@ static void test_one_group_rgo(void) memcpy(log_page + sizeof(header), &group, sizeof(group)); set_mock_admin_cmds(&mock_admin_cmd, 1); check(!nvme_get_ana_log_atomic(test_link, true, false, 1, log, &len), - "get log page failed: %m"); + "get log page failed"); end_mock_cmds(); cmp(log, log_page, sizeof(log_page), "incorrect log page"); check(len == sizeof(log_page), @@ -139,7 +139,7 @@ static void test_one_group_nsids(void) memcpy(log_page + sizeof(header) + sizeof(group), nsids, sizeof(nsids)); set_mock_admin_cmds(&mock_admin_cmd, 1); check(!nvme_get_ana_log_atomic(test_link, false, false, 1, log, &len), - "get log page failed: %m"); + "get log page failed"); end_mock_cmds(); cmp(log, log_page, sizeof(log_page), "incorrect log page"); check(len == sizeof(log_page), @@ -180,7 +180,7 @@ static void test_multiple_groups_rgo(void) memcpy(log_page + sizeof(header), groups, sizeof(groups)); set_mock_admin_cmds(&mock_admin_cmd, 1); check(!nvme_get_ana_log_atomic(test_link, true, true, 1, log, &len), - "get log page failed: %m"); + "get log page failed"); end_mock_cmds(); cmp(log, log_page, sizeof(log_page), "incorrect log page"); check(len == sizeof(log_page), @@ -246,7 +246,7 @@ static void test_multiple_groups_nsids(void) nsids3, sizeof(nsids3)); set_mock_admin_cmds(&mock_admin_cmd, 1); check(!nvme_get_ana_log_atomic(test_link, false, false, 1, log, &len), - "get log page failed: %m"); + "get log page failed"); end_mock_cmds(); cmp(log, log_page, sizeof(log_page), "incorrect log page"); check(len == sizeof(log_page), @@ -318,7 +318,7 @@ static void test_long_log(void) memcpy(log_page + sizeof(header) + sizeof(group), nsids, sizeof(nsids)); set_mock_admin_cmds(mock_admin_cmds, ARRAY_SIZE(mock_admin_cmds)); check(!nvme_get_ana_log_atomic(test_link, false, true, 1, log, &len), - "get log page failed: %m"); + "get log page failed"); end_mock_cmds(); cmp(log, log_page, sizeof(log_page), "incorrect log page"); check(len == sizeof(log_page), @@ -394,7 +394,7 @@ static void test_chgcnt_change(void) memcpy(log_page2 + sizeof(header2), &group2, sizeof(group2)); set_mock_admin_cmds(mock_admin_cmds, ARRAY_SIZE(mock_admin_cmds)); check(!nvme_get_ana_log_atomic(test_link, true, true, 2, log, &len), - "get log page failed: %m"); + "get log page failed"); end_mock_cmds(); cmp(log, log_page2, sizeof(log_page2), "incorrect log page"); check(len == sizeof(log_page2), @@ -476,7 +476,7 @@ static void test_buffer_too_short_chgcnt_change(void) &nsid2, sizeof(nsid2)); set_mock_admin_cmds(mock_admin_cmds, ARRAY_SIZE(mock_admin_cmds)); check(!nvme_get_ana_log_atomic(test_link, false, false, 2, log, &len), - "get log page failed: %m"); + "get log page failed"); end_mock_cmds(); cmp(log, log_page2, sizeof(log_page2), "incorrect log page"); check(len == sizeof(log_page2), @@ -571,10 +571,9 @@ static void test_chgcnt_max_retries(void) memcpy(log_page2 + sizeof(header2) + sizeof(group), nsids, sizeof(nsids)); set_mock_admin_cmds(mock_admin_cmds, ARRAY_SIZE(mock_admin_cmds)); - check(nvme_get_ana_log_atomic(test_link, false, true, 2, log, &len) == -1, + check(nvme_get_ana_log_atomic(test_link, false, true, 2, log, &len) == -EAGAIN, "get log page succeeded"); end_mock_cmds(); - check(errno == EAGAIN, "unexpected error: %m"); free(log); } @@ -612,10 +611,9 @@ static void test_buffer_too_short(void) memcpy(log_page + sizeof(header), &group, sizeof(group)); memcpy(log_page + sizeof(header) + sizeof(group), nsids, sizeof(nsids)); set_mock_admin_cmds(&mock_admin_cmd, 1); - check(nvme_get_ana_log_atomic(test_link, false, true, 2, log, &len) == -1, + check(nvme_get_ana_log_atomic(test_link, false, true, 2, log, &len) == -ENOSPC, "get log page succeeded"); end_mock_cmds(); - check(errno == ENOSPC, "unexpected error: %m"); free(log); } @@ -634,7 +632,7 @@ int main(void) nvme_root_t r = nvme_create_root(stdout, DEFAULT_LOGLEVEL); set_mock_fd(TEST_FD); - test_link = nvme_open(r, "NVME_TEST_FD"); + check(!nvme_open(r, "NVME_TEST_FD", &test_link), "opening test link failed"); RUN_TEST(no_retries); RUN_TEST(len_too_short); diff --git a/test/ioctl/discovery.c b/test/ioctl/discovery.c index aedf48fab..c43611f39 100644 --- a/test/ioctl/discovery.c +++ b/test/ioctl/discovery.c @@ -11,6 +11,7 @@ #include #include "mock.h" +#include "nvme/log.h" #include "util.h" #define TEST_FD 0xFD @@ -74,7 +75,7 @@ static void test_no_entries(nvme_ctrl_t c) struct nvmf_discovery_log *log = NULL; set_mock_admin_cmds(mock_admin_cmds, ARRAY_SIZE(mock_admin_cmds)); - check(nvmf_get_discovery_log(c, &log, 1) == 0, "discovery failed: %m"); + check(nvmf_get_discovery_log(c, &log, 1) == 0, "discovery failed"); end_mock_cmds(); cmp(log, &header, sizeof(header), "incorrect header"); free(log); @@ -118,7 +119,7 @@ static void test_four_entries(nvme_ctrl_t c) arbitrary_entries(num_entries, entries, log_entries); set_mock_admin_cmds(mock_admin_cmds, ARRAY_SIZE(mock_admin_cmds)); - check(nvmf_get_discovery_log(c, &log, 1) == 0, "discovery failed: %m"); + check(nvmf_get_discovery_log(c, &log, 1) == 0, "discovery failed"); end_mock_cmds(); cmp(log, &header, sizeof(header), "incorrect header"); cmp(log->entries, entries, sizeof(entries), "incorrect entries"); @@ -177,7 +178,7 @@ static void test_five_entries(nvme_ctrl_t c) arbitrary_entries(num_entries, entries, log_entries); set_mock_admin_cmds(mock_admin_cmds, ARRAY_SIZE(mock_admin_cmds)); - check(nvmf_get_discovery_log(c, &log, 1) == 0, "discovery failed: %m"); + check(nvmf_get_discovery_log(c, &log, 1) == 0, "discovery failed"); end_mock_cmds(); cmp(log, &header, sizeof(header), "incorrect header"); cmp(log->entries, entries, sizeof(entries), "incorrect entries"); @@ -245,7 +246,7 @@ static void test_genctr_change(nvme_ctrl_t c) arbitrary(entries1, sizeof(entries1)); arbitrary_entries(num_entries2, entries2, log_entries2); set_mock_admin_cmds(mock_admin_cmds, ARRAY_SIZE(mock_admin_cmds)); - check(nvmf_get_discovery_log(c, &log, 2) == 0, "discovery failed: %m"); + check(nvmf_get_discovery_log(c, &log, 2) == 0, "discovery failed"); end_mock_cmds(); cmp(log, &header2, sizeof(header2), "incorrect header"); cmp(log->entries, entries2, sizeof(entries2), "incorrect entries"); @@ -308,9 +309,8 @@ static void test_max_retries(nvme_ctrl_t c) arbitrary(&entry, sizeof(entry)); set_mock_admin_cmds(mock_admin_cmds, ARRAY_SIZE(mock_admin_cmds)); - check(nvmf_get_discovery_log(c, &log, 2) == -1, "discovery succeeded"); + check(nvmf_get_discovery_log(c, &log, 2) == -EAGAIN, "discovery succeeded"); end_mock_cmds(); - check(errno == EAGAIN, "discovery failed: %m"); check(!log, "unexpected log page returned"); } @@ -323,13 +323,13 @@ static void test_header_error(nvme_ctrl_t c) .data_len = HEADER_LEN, .cdw10 = (HEADER_LEN / 4 - 1) << 16 /* NUMDL */ | NVME_LOG_LID_DISCOVER, /* LID */ - .err = NVME_SC_INVALID_OPCODE, + .err = -EAGAIN, }, }; struct nvmf_discovery_log *log = NULL; set_mock_admin_cmds(mock_admin_cmds, ARRAY_SIZE(mock_admin_cmds)); - check(nvmf_get_discovery_log(c, &log, 1) == -1, "discovery succeeded"); + check(nvmf_get_discovery_log(c, &log, 1) == -EAGAIN, "discovery succeeded"); end_mock_cmds(); check(!log, "unexpected log page returned"); } @@ -359,9 +359,8 @@ static void test_entries_error(nvme_ctrl_t c) struct nvmf_discovery_log *log = NULL; set_mock_admin_cmds(mock_admin_cmds, ARRAY_SIZE(mock_admin_cmds)); - check(nvmf_get_discovery_log(c, &log, 1) == -1, "discovery succeeded"); + check(nvmf_get_discovery_log(c, &log, 1) == -EIO, "discovery succeeded"); end_mock_cmds(); - check(errno == EIO, "discovery failed: %m"); check(!log, "unexpected log page returned"); } @@ -398,7 +397,7 @@ static void test_genctr_error(nvme_ctrl_t c) arbitrary(&entry, sizeof(entry)); set_mock_admin_cmds(mock_admin_cmds, ARRAY_SIZE(mock_admin_cmds)); - check(nvmf_get_discovery_log(c, &log, 1) == -1, "discovery succeeded"); + check(nvmf_get_discovery_log(c, &log, 1) == NVME_SC_INTERNAL, "discovery succeeded"); end_mock_cmds(); check(!log, "unexpected log page returned"); } @@ -422,7 +421,7 @@ int main(void) nvme_root_t r = nvme_create_root(stdout, DEFAULT_LOGLEVEL); set_mock_fd(TEST_FD); - test_link = nvme_open(r, "NVME_TEST_FD"); + check(!nvme_open(r, "NVME_TEST_FD", &test_link), "opening test link failed"); RUN_TEST(no_entries); RUN_TEST(four_entries); diff --git a/test/ioctl/features.c b/test/ioctl/features.c index f44d50087..40aacc738 100644 --- a/test/ioctl/features.c +++ b/test/ioctl/features.c @@ -64,7 +64,7 @@ static void test_set_features(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_set_features(test_link, &args); end_mock_cmds(); - check(err == 0, "set features returned error %d, errno %m", err); + check(err == 0, "set features returned error %d", err); check(result == TEST_RESULT, "got result %" PRIu32 ", expected %" PRIu32, result, TEST_RESULT); } @@ -102,7 +102,7 @@ static void test_get_features(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_get_features(test_link, &args); end_mock_cmds(); - check(err == 0, "get features returned error %d, errno %m", err); + check(err == 0, "get features returned error %d", err); check(result == TEST_RESULT, "got result %" PRIu32 ", expected %" PRIu32, result, TEST_RESULT); cmp(get_data, data, sizeof(data), "incorrect data"); @@ -129,7 +129,7 @@ static void test_set_features_data(void) test_link, TEST_FID, TEST_NSID, TEST_CDW11, false, sizeof(data), data, &result); end_mock_cmds(); - check(err == 0, "set features returned error %d, errno %m", err); + check(err == 0, "set features returned error %d", err); check(result == TEST_RESULT, "got result %" PRIu32 ", expected %" PRIu32, result, TEST_RESULT); } @@ -153,7 +153,7 @@ static void test_get_features_data(void) err = nvme_get_features_data( test_link, TEST_FID, TEST_NSID, sizeof(data), get_data, &result); end_mock_cmds(); - check(err == 0, "set features returned error %d, errno %m", err); + check(err == 0, "set features returned error %d", err); check(result == TEST_RESULT, "got result %" PRIu32 ", expected %" PRIu32, result, TEST_RESULT); cmp(get_data, data, sizeof(data), "incorrect data"); @@ -176,7 +176,7 @@ static void test_set_features_simple(void) err = nvme_set_features_simple( test_link, TEST_FID, TEST_NSID, TEST_CDW11, true, &result); end_mock_cmds(); - check(err == 0, "set features returned error %d, errno %m", err); + check(err == 0, "set features returned error %d", err); check(result == TEST_RESULT, "got result %" PRIu32 ", expected %" PRIu32, result, TEST_RESULT); } @@ -195,7 +195,7 @@ static void test_get_features_simple(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_get_features_simple(test_link, TEST_FID, TEST_NSID, &result); end_mock_cmds(); - check(err == 0, "set features returned error %d, errno %m", err); + check(err == 0, "set features returned error %d", err); check(result == TEST_RESULT, "got result %" PRIu32 ", expected %" PRIu32, result, TEST_RESULT); } @@ -216,7 +216,7 @@ static void test_set_arbitration(void) err = nvme_set_features_arbitration( test_link, AB, LPW, MPW, HPW, false, &result); end_mock_cmds(); - check(err == 0, "set features returned error %d, errno %m", err); + check(err == 0, "set features returned error %d", err); check(result == TEST_RESULT, "got result %" PRIu32 ", expected %" PRIu32, result, TEST_RESULT); } @@ -234,7 +234,7 @@ static void test_get_arbitration(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_get_features_arbitration(test_link, TEST_SEL, &result); end_mock_cmds(); - check(err == 0, "get features returned error %d, errno %m", err); + check(err == 0, "get features returned error %d", err); check(result == TEST_RESULT, "got result %" PRIu32 ", expected %" PRIu32, result, TEST_RESULT); } @@ -255,7 +255,7 @@ static void test_set_power_mgmt(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_set_features_power_mgmt(test_link, PS, WH, true, &result); end_mock_cmds(); - check(err == 0, "set features returned error %d, errno %m", err); + check(err == 0, "set features returned error %d", err); check(result == TEST_RESULT, "got result %" PRIu32 ", expected %" PRIu32, result, TEST_RESULT); } @@ -273,7 +273,7 @@ static void test_get_power_mgmt(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_get_features_power_mgmt(test_link, TEST_SEL, &result); end_mock_cmds(); - check(err == 0, "get features returned error %d, errno %m", err); + check(err == 0, "get features returned error %d", err); check(result == TEST_RESULT, "got result %" PRIu32 ", expected %" PRIu32, result, TEST_RESULT); } @@ -299,7 +299,7 @@ static void test_set_lba_range(void) err = nvme_set_features_lba_range( test_link, TEST_NSID, NUM, false, &range_types, &result); end_mock_cmds(); - check(err == 0, "set features returned error %d, errno %m", err); + check(err == 0, "set features returned error %d", err); check(result == TEST_RESULT, "got result %" PRIu32 ", expected %" PRIu32, result, TEST_RESULT); } @@ -323,7 +323,7 @@ static void test_get_lba_range(void) err = nvme_get_features_lba_range( test_link, TEST_SEL, TEST_NSID, &get_range_types, &result); end_mock_cmds(); - check(err == 0, "get features returned error %d, errno %m", err); + check(err == 0, "get features returned error %d", err); check(result == TEST_RESULT, "got result %" PRIu32 ", expected %" PRIu32, result, TEST_RESULT); cmp(&get_range_types, &range_types, sizeof(range_types), @@ -350,7 +350,7 @@ static void test_set_temp_thresh(void) err = nvme_set_features_temp_thresh( test_link, TMPTH, TMPSEL, THSEL, 0, true, &result); end_mock_cmds(); - check(err == 0, "set features returned error %d, errno %m", err); + check(err == 0, "set features returned error %d", err); check(result == TEST_RESULT, "got result %" PRIu32 ", expected %" PRIu32, result, TEST_RESULT); } @@ -373,7 +373,7 @@ static void test_get_temp_thresh(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_get_features_temp_thresh(test_link, TEST_SEL, 0, 0, &result); end_mock_cmds(); - check(err == 0, "get features returned error %d, errno %m", err); + check(err == 0, "get features returned error %d", err); check(result == TEST_RESULT, "got result %" PRIu32 ", expected %" PRIu32, result, TEST_RESULT); } @@ -396,7 +396,7 @@ static void test_set_err_recovery(void) err = nvme_set_features_err_recovery( test_link, TEST_NSID, TLER, true, false, &result); end_mock_cmds(); - check(err == 0, "set features returned error %d, errno %m", err); + check(err == 0, "set features returned error %d", err); check(result == TEST_RESULT, "got result %" PRIu32 ", expected %" PRIu32, result, TEST_RESULT); } @@ -416,7 +416,7 @@ static void test_get_err_recovery(void) err = nvme_get_features_err_recovery( test_link, TEST_SEL, TEST_NSID, &result); end_mock_cmds(); - check(err == 0, "get features returned error %d, errno %m", err); + check(err == 0, "get features returned error %d", err); check(result == TEST_RESULT, "got result %" PRIu32 ", expected %" PRIu32, result, TEST_RESULT); } @@ -436,7 +436,7 @@ static void test_set_volatile_wc(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_set_features_volatile_wc(test_link, true, true, &result); end_mock_cmds(); - check(err == 0, "set features returned error %d, errno %m", err); + check(err == 0, "set features returned error %d", err); check(result == TEST_RESULT, "got result %" PRIu32 ", expected %" PRIu32, result, TEST_RESULT); } @@ -455,7 +455,7 @@ static void test_get_volatile_wc(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_get_features_volatile_wc(test_link, TEST_SEL, &result); end_mock_cmds(); - check(err == 0, "get features returned error %d, errno %m", err); + check(err == 0, "get features returned error %d", err); check(result == TEST_RESULT, "got result %" PRIu32 ", expected %" PRIu32, result, TEST_RESULT); } @@ -473,7 +473,7 @@ static void test_get_num_queues(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_get_features_num_queues(test_link, TEST_SEL, &result); end_mock_cmds(); - check(err == 0, "get features returned error %d, errno %m", err); + check(err == 0, "get features returned error %d", err); check(result == TEST_RESULT, "got result %" PRIu32 ", expected %" PRIu32, result, TEST_RESULT); } @@ -494,7 +494,7 @@ static void test_set_irq_coalesce(void) err = nvme_set_features_irq_coalesce( test_link, THR, TIME, false, &result); end_mock_cmds(); - check(err == 0, "set features returned error %d, errno %m", err); + check(err == 0, "set features returned error %d", err); check(result == TEST_RESULT, "got result %" PRIu32 ", expected %" PRIu32, result, TEST_RESULT); } @@ -512,7 +512,7 @@ static void test_get_irq_coalesce(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_get_features_irq_coalesce(test_link, TEST_SEL, &result); end_mock_cmds(); - check(err == 0, "get features returned error %d, errno %m", err); + check(err == 0, "get features returned error %d", err); check(result == TEST_RESULT, "got result %" PRIu32 ", expected %" PRIu32, result, TEST_RESULT); } @@ -534,7 +534,7 @@ static void test_set_irq_config(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_set_features_irq_config(test_link, IV, true, true, &result); end_mock_cmds(); - check(err == 0, "set features returned error %d, errno %m", err); + check(err == 0, "set features returned error %d", err); check(result == TEST_RESULT, "got result %" PRIu32 ", expected %" PRIu32, result, TEST_RESULT); } @@ -554,7 +554,7 @@ static void test_get_irq_config(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_get_features_irq_config(test_link, TEST_SEL, IV, &result); end_mock_cmds(); - check(err == 0, "get features returned error %d, errno %m", err); + check(err == 0, "get features returned error %d", err); check(result == TEST_RESULT, "got result %" PRIu32 ", expected %" PRIu32, result, TEST_RESULT); } @@ -573,7 +573,7 @@ static void test_set_write_atomic(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_set_features_write_atomic(test_link, true, false, &result); end_mock_cmds(); - check(err == 0, "set features returned error %d, errno %m", err); + check(err == 0, "set features returned error %d", err); check(result == TEST_RESULT, "got result %" PRIu32 ", expected %" PRIu32, result, TEST_RESULT); } @@ -591,7 +591,7 @@ static void test_get_write_atomic(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_get_features_write_atomic(test_link, TEST_SEL, &result); end_mock_cmds(); - check(err == 0, "get features returned error %d, errno %m", err); + check(err == 0, "get features returned error %d", err); check(result == TEST_RESULT, "got result %" PRIu32 ", expected %" PRIu32, result, TEST_RESULT); } @@ -612,7 +612,7 @@ static void test_set_async_event(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_set_features_async_event(test_link, EVENTS, true, &result); end_mock_cmds(); - check(err == 0, "set features returned error %d, errno %m", err); + check(err == 0, "set features returned error %d", err); check(result == TEST_RESULT, "got result %" PRIu32 ", expected %" PRIu32, result, TEST_RESULT); } @@ -630,7 +630,7 @@ static void test_get_async_event(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_get_features_async_event(test_link, TEST_SEL, &result); end_mock_cmds(); - check(err == 0, "get features returned error %d, errno %m", err); + check(err == 0, "get features returned error %d", err); check(result == TEST_RESULT, "got result %" PRIu32 ", expected %" PRIu32, result, TEST_RESULT); } @@ -653,7 +653,7 @@ static void test_set_auto_pst(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_set_features_auto_pst(test_link, true, false, &apst, &result); end_mock_cmds(); - check(err == 0, "set features returned error %d, errno %m", err); + check(err == 0, "set features returned error %d", err); check(result == TEST_RESULT, "got result %" PRIu32 ", expected %" PRIu32, result, TEST_RESULT); } @@ -675,7 +675,7 @@ static void test_get_auto_pst(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_get_features_auto_pst(test_link, TEST_SEL, &get_apst, &result); end_mock_cmds(); - check(err == 0, "get features returned error %d, errno %m", err); + check(err == 0, "get features returned error %d", err); check(result == TEST_RESULT, "got result %" PRIu32 ", expected %" PRIu32, result, TEST_RESULT); cmp(&get_apst, &apst, sizeof(apst), "incorrect apst"); @@ -699,7 +699,7 @@ static void test_get_host_mem_buf(void) err = nvme_get_features_host_mem_buf( test_link, TEST_SEL, &get_attrs, &result); end_mock_cmds(); - check(err == 0, "get features returned error %d, errno %m", err); + check(err == 0, "get features returned error %d", err); check(result == TEST_RESULT, "got result %" PRIu32 ", expected %" PRIu32, result, TEST_RESULT); cmp(&get_attrs, &attrs, sizeof(attrs), "incorrect attrs"); @@ -726,7 +726,7 @@ static void test_set_timestamp(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_set_features_timestamp(test_link, true, timestamp); end_mock_cmds(); - check(err == 0, "set features returned error %d, errno %m", err); + check(err == 0, "set features returned error %d", err); } static void test_get_timestamp(void) @@ -744,7 +744,7 @@ static void test_get_timestamp(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_get_features_timestamp(test_link, TEST_SEL, &get_ts); end_mock_cmds(); - check(err == 0, "get features returned error %d, errno %m", err); + check(err == 0, "get features returned error %d", err); cmp(&get_ts, &ts, sizeof(ts), "incorrect timestamp"); } @@ -761,7 +761,7 @@ static void test_get_kato(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_get_features_kato(test_link, TEST_SEL, &result); end_mock_cmds(); - check(err == 0, "get features returned error %d, errno %m", err); + check(err == 0, "get features returned error %d", err); check(result == TEST_RESULT, "got result %" PRIu32 ", expected %" PRIu32, result, TEST_RESULT); } @@ -781,7 +781,7 @@ static void test_set_hctm(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_set_features_hctm(test_link, TMT2, TMT1, false, &result); end_mock_cmds(); - check(err == 0, "set features returned error %d, errno %m", err); + check(err == 0, "set features returned error %d", err); check(result == TEST_RESULT, "got result %" PRIu32 ", expected %" PRIu32, result, TEST_RESULT); } @@ -799,7 +799,7 @@ static void test_get_hctm(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_get_features_hctm(test_link, TEST_SEL, &result); end_mock_cmds(); - check(err == 0, "get features returned error %d, errno %m", err); + check(err == 0, "get features returned error %d", err); check(result == TEST_RESULT, "got result %" PRIu32 ", expected %" PRIu32, result, TEST_RESULT); } @@ -819,7 +819,7 @@ static void test_set_nopsc(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_set_features_nopsc(test_link, true, true, &result); end_mock_cmds(); - check(err == 0, "set features returned error %d, errno %m", err); + check(err == 0, "set features returned error %d", err); check(result == TEST_RESULT, "got result %" PRIu32 ", expected %" PRIu32, result, TEST_RESULT); } @@ -837,7 +837,7 @@ static void test_get_nopsc(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_get_features_nopsc(test_link, TEST_SEL, &result); end_mock_cmds(); - check(err == 0, "get features returned error %d, errno %m", err); + check(err == 0, "get features returned error %d", err); check(result == TEST_RESULT, "got result %" PRIu32 ", expected %" PRIu32, result, TEST_RESULT); } @@ -859,7 +859,7 @@ static void test_set_rrl(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_set_features_rrl(test_link, RRL, NVMSETID, false, &result); end_mock_cmds(); - check(err == 0, "set features returned error %d, errno %m", err); + check(err == 0, "set features returned error %d", err); check(result == TEST_RESULT, "got result %" PRIu32 ", expected %" PRIu32, result, TEST_RESULT); } @@ -878,7 +878,7 @@ static void test_get_rrl(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_get_features_rrl(test_link, TEST_SEL, &result); end_mock_cmds(); - check(err == 0, "get features returned error %d, errno %m", err); + check(err == 0, "get features returned error %d", err); check(result == TEST_RESULT, "got result %" PRIu32 ", expected %" PRIu32, result, TEST_RESULT); } @@ -905,7 +905,7 @@ static void test_set_plm_config(void) err = nvme_set_features_plm_config( test_link, true, NVMSETID, true, &config, &result); end_mock_cmds(); - check(err == 0, "set features returned error %d, errno %m", err); + check(err == 0, "set features returned error %d", err); check(result == TEST_RESULT, "got result %" PRIu32 ", expected %" PRIu32, result, TEST_RESULT); } @@ -930,7 +930,7 @@ static void test_get_plm_config(void) err = nvme_get_features_plm_config( test_link, TEST_SEL, NVMSETID, &get_config, &result); end_mock_cmds(); - check(err == 0, "get features returned error %d, errno %m", err); + check(err == 0, "get features returned error %d", err); check(result == TEST_RESULT, "got result %" PRIu32 ", expected %" PRIu32, result, TEST_RESULT); cmp(&get_config, &config, sizeof(config), "incorrect PLM config"); @@ -954,7 +954,7 @@ static void test_set_plm_window(void) err = nvme_set_features_plm_window( test_link, SEL, NVMSETID, false, &result); end_mock_cmds(); - check(err == 0, "set features returned error %d, errno %m", err); + check(err == 0, "set features returned error %d", err); check(result == TEST_RESULT, "got result %" PRIu32 ", expected %" PRIu32, result, TEST_RESULT); } @@ -975,7 +975,7 @@ static void test_get_plm_window(void) err = nvme_get_features_plm_window( test_link, TEST_SEL, NVMSETID, &result); end_mock_cmds(); - check(err == 0, "get features returned error %d, errno %m", err); + check(err == 0, "get features returned error %d", err); check(result == TEST_RESULT, "got result %" PRIu32 ", expected %" PRIu32, result, TEST_RESULT); } @@ -997,7 +997,7 @@ static void test_set_lba_sts_interval(void) err = nvme_set_features_lba_sts_interval( test_link, LSIRI, LSIPI, true, &result); end_mock_cmds(); - check(err == 0, "set features returned error %d, errno %m", err); + check(err == 0, "set features returned error %d", err); check(result == TEST_RESULT, "got result %" PRIu32 ", expected %" PRIu32, result, TEST_RESULT); } @@ -1015,7 +1015,7 @@ static void test_get_lba_sts_interval(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_get_features_lba_sts_interval(test_link, TEST_SEL, &result); end_mock_cmds(); - check(err == 0, "get features returned error %d, errno %m", err); + check(err == 0, "get features returned error %d", err); check(result == TEST_RESULT, "got result %" PRIu32 ", expected %" PRIu32, result, TEST_RESULT); } @@ -1036,7 +1036,7 @@ static void test_set_host_behavior(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_set_features_host_behavior(test_link, true, &behavior); end_mock_cmds(); - check(err == 0, "set features returned error %d, errno %m", err); + check(err == 0, "set features returned error %d", err); } static void test_get_host_behavior(void) @@ -1057,7 +1057,7 @@ static void test_get_host_behavior(void) err = nvme_get_features_host_behavior( test_link, TEST_SEL, &get_behavior, &result); end_mock_cmds(); - check(err == 0, "get features returned error %d, errno %m", err); + check(err == 0, "get features returned error %d", err); check(result == TEST_RESULT, "got result %" PRIu32 ", expected %" PRIu32, result, TEST_RESULT); cmp(&get_behavior, &behavior, sizeof(behavior), "incorrect behavior"); @@ -1077,7 +1077,7 @@ static void test_set_sanitize(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_set_features_sanitize(test_link, true, false, &result); end_mock_cmds(); - check(err == 0, "set features returned error %d, errno %m", err); + check(err == 0, "set features returned error %d", err); check(result == TEST_RESULT, "got result %" PRIu32 ", expected %" PRIu32, result, TEST_RESULT); } @@ -1095,7 +1095,7 @@ static void test_get_sanitize(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_get_features_sanitize(test_link, TEST_SEL, &result); end_mock_cmds(); - check(err == 0, "get features returned error %d, errno %m", err); + check(err == 0, "get features returned error %d", err); check(result == TEST_RESULT, "got result %" PRIu32 ", expected %" PRIu32, result, TEST_RESULT); } @@ -1118,7 +1118,7 @@ static void test_set_endurance_evt_cfg(void) err = nvme_set_features_endurance_evt_cfg( test_link, ENDGID, EGWARN, true, &result); end_mock_cmds(); - check(err == 0, "set features returned error %d, errno %m", err); + check(err == 0, "set features returned error %d", err); check(result == TEST_RESULT, "got result %" PRIu32 ", expected %" PRIu32, result, TEST_RESULT); } @@ -1139,7 +1139,7 @@ static void test_get_endurance_event_cfg(void) err = nvme_get_features_endurance_event_cfg( test_link, TEST_SEL, ENDGID, &result); end_mock_cmds(); - check(err == 0, "get features returned error %d, errno %m", err); + check(err == 0, "get features returned error %d", err); check(result == TEST_RESULT, "got result %" PRIu32 ", expected %" PRIu32, result, TEST_RESULT); } @@ -1157,7 +1157,7 @@ static void test_set_iocs_profile(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_set_features_iocs_profile(test_link, IOCSI, false); end_mock_cmds(); - check(err == 0, "set features returned error %d, errno %m", err); + check(err == 0, "set features returned error %d", err); } static void test_get_iocs_profile(void) @@ -1173,7 +1173,7 @@ static void test_get_iocs_profile(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_get_features_iocs_profile(test_link, TEST_SEL, &result); end_mock_cmds(); - check(err == 0, "get features returned error %d, errno %m", err); + check(err == 0, "get features returned error %d", err); check(result == TEST_RESULT, "got result %" PRIu32 ", expected %" PRIu32, result, TEST_RESULT); } @@ -1194,7 +1194,7 @@ static void test_set_sw_progress(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_set_features_sw_progress(test_link, PBSLC, true, &result); end_mock_cmds(); - check(err == 0, "set features returned error %d, errno %m", err); + check(err == 0, "set features returned error %d", err); check(result == TEST_RESULT, "got result %" PRIu32 ", expected %" PRIu32, result, TEST_RESULT); } @@ -1212,7 +1212,7 @@ static void test_get_sw_progress(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_get_features_sw_progress(test_link, TEST_SEL, &result); end_mock_cmds(); - check(err == 0, "get features returned error %d, errno %m", err); + check(err == 0, "get features returned error %d", err); check(result == TEST_RESULT, "got result %" PRIu32 ", expected %" PRIu32, result, TEST_RESULT); } @@ -1234,7 +1234,7 @@ static void test_set_host_id(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_set_features_host_id(test_link, false, true, hostid); end_mock_cmds(); - check(err == 0, "set features returned error %d, errno %m", err); + check(err == 0, "set features returned error %d", err); } static void test_set_host_id_extended(void) @@ -1254,7 +1254,7 @@ static void test_set_host_id_extended(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_set_features_host_id(test_link, true, false, hostid); end_mock_cmds(); - check(err == 0, "set features returned error %d, errno %m", err); + check(err == 0, "set features returned error %d", err); } static void test_get_host_id(void) @@ -1274,7 +1274,7 @@ static void test_get_host_id(void) err = nvme_get_features_host_id( test_link, TEST_SEL, false, sizeof(hostid), get_hostid); end_mock_cmds(); - check(err == 0, "get features returned error %d, errno %m", err); + check(err == 0, "get features returned error %d", err); cmp(get_hostid, hostid, sizeof(hostid), "incorrect host identifier"); } @@ -1296,7 +1296,7 @@ static void test_get_host_id_extended(void) err = nvme_get_features_host_id( test_link, TEST_SEL, true, sizeof(hostid), get_hostid); end_mock_cmds(); - check(err == 0, "get features returned error %d, errno %m", err); + check(err == 0, "get features returned error %d", err); cmp(get_hostid, hostid, sizeof(hostid), "incorrect host identifier"); } @@ -1318,7 +1318,7 @@ static void test_set_resv_mask(void) err = nvme_set_features_resv_mask( test_link, TEST_NSID, MASK, true, &result); end_mock_cmds(); - check(err == 0, "set features returned error %d, errno %m", err); + check(err == 0, "set features returned error %d", err); check(result == TEST_RESULT, "got result %" PRIu32 ", expected %" PRIu32, result, TEST_RESULT); } @@ -1338,7 +1338,7 @@ static void test_get_resv_mask(void) err = nvme_get_features_resv_mask( test_link, TEST_SEL, TEST_NSID, &result); end_mock_cmds(); - check(err == 0, "get features returned error %d, errno %m", err); + check(err == 0, "get features returned error %d", err); check(result == TEST_RESULT, "got result %" PRIu32 ", expected %" PRIu32, result, TEST_RESULT); } @@ -1359,7 +1359,7 @@ static void test_set_resv_persist(void) err = nvme_set_features_resv_persist( test_link, TEST_NSID, true, false, &result); end_mock_cmds(); - check(err == 0, "set features returned error %d, errno %m", err); + check(err == 0, "set features returned error %d", err); check(result == TEST_RESULT, "got result %" PRIu32 ", expected %" PRIu32, result, TEST_RESULT); } @@ -1379,7 +1379,7 @@ static void test_get_resv_persist(void) err = nvme_get_features_resv_persist( test_link, TEST_SEL, TEST_NSID, &result); end_mock_cmds(); - check(err == 0, "get features returned error %d, errno %m", err); + check(err == 0, "get features returned error %d", err); check(result == TEST_RESULT, "got result %" PRIu32 ", expected %" PRIu32, result, TEST_RESULT); } @@ -1403,7 +1403,7 @@ static void test_set_write_protect(void) err = nvme_set_features_write_protect( test_link, TEST_NSID, STATE, true, &result); end_mock_cmds(); - check(err == 0, "set features returned error %d, errno %m", err); + check(err == 0, "set features returned error %d", err); check(result == TEST_RESULT, "got result %" PRIu32 ", expected %" PRIu32, result, TEST_RESULT); } @@ -1423,7 +1423,7 @@ static void test_get_write_protect(void) err = nvme_get_features_write_protect( test_link, TEST_NSID, TEST_SEL, &result); end_mock_cmds(); - check(err == 0, "get features returned error %d, errno %m", err); + check(err == 0, "get features returned error %d", err); check(result == TEST_RESULT, "got result %" PRIu32 ", expected %" PRIu32, result, TEST_RESULT); } @@ -1472,8 +1472,7 @@ static void test_set_kernel_error(void) err = nvme_set_features_resv_mask( test_link, TEST_NSID, MASK, false, &result); end_mock_cmds(); - check(err == -1, "got error %d, expected -1", err); - check(errno == EIO, "unexpected error %m"); + check(err == -EIO, "got error %d, expected -EIO", err); check(!result, "result unexpectedly set to %" PRIu32, result); } @@ -1515,8 +1514,7 @@ static void test_get_kernel_error(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_get_features_num_queues(test_link, TEST_SEL, &result); end_mock_cmds(); - check(err == -1, "got error %d, expected -1", err); - check(errno == EBUSY, "unexpected error %m"); + check(err == -EBUSY, "got error %d, expected -EBUSY", err); check(!result, "result unexpectedly set to %" PRIu32, result); } @@ -1586,7 +1584,7 @@ int main(void) nvme_root_t r = nvme_create_root(stdout, DEFAULT_LOGLEVEL); set_mock_fd(TEST_FD); - test_link = nvme_open(r, "NVME_TEST_FD"); + check(!nvme_open(r, "NVME_TEST_FD", &test_link), "opening test link failed"); RUN_TEST(set_features); RUN_TEST(get_features); diff --git a/test/ioctl/identify.c b/test/ioctl/identify.c index a65845605..1d93c7a33 100644 --- a/test/ioctl/identify.c +++ b/test/ioctl/identify.c @@ -56,7 +56,7 @@ static void test_ctrl(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_identify_ctrl(test_link, &id); end_mock_cmds(); - check(err == 0, "identify returned error %d, errno %m", err); + check(err == 0, "identify returned error %d", err); cmp(&id, &expected_id, sizeof(id), "incorrect identify data"); } @@ -76,7 +76,7 @@ static void test_active_ns_list(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_identify_active_ns_list(test_link, TEST_NSID, &id); end_mock_cmds(); - check(err == 0, "identify returned error %d, errno %m", err); + check(err == 0, "identify returned error %d", err); cmp(&id, &expected_id, sizeof(id), "incorrect identify data"); } @@ -99,7 +99,7 @@ static void test_ns_descs(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_identify_ns_descs(test_link, TEST_NSID, id); end_mock_cmds(); - check(err == 0, "identify returned error %d, errno %m", err); + check(err == 0, "identify returned error %d", err); cmp(id, expected_id, sizeof(expected_id), "incorrect identify data"); free(id); } @@ -120,7 +120,7 @@ static void test_nvmset_list(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_identify_nvmset_list(test_link, TEST_NVMSETID, &id); end_mock_cmds(); - check(err == 0, "identify returned error %d, errno %m", err); + check(err == 0, "identify returned error %d", err); cmp(&id, &expected_id, sizeof(id), "incorrect identify data"); } @@ -143,7 +143,7 @@ static void test_ns_csi(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_identify_ns_csi(test_link, TEST_NSID, TEST_UUID, TEST_CSI, id); end_mock_cmds(); - check(err == 0, "identify returned error %d, errno %m", err); + check(err == 0, "identify returned error %d", err); cmp(id, expected_id, sizeof(id), "incorrect identify data"); } @@ -164,7 +164,7 @@ static void test_zns_identify_ns(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_zns_identify_ns(test_link, TEST_NSID, &id); end_mock_cmds(); - check(err == 0, "identify returned error %d, errno %m", err); + check(err == 0, "identify returned error %d", err); cmp(&id, &expected_id, sizeof(id), "incorrect identify data"); } @@ -184,7 +184,7 @@ static void test_nvm_identify_ctrl(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_nvm_identify_ctrl(test_link, &id); end_mock_cmds(); - check(err == 0, "identify returned error %d, errno %m", err); + check(err == 0, "identify returned error %d", err); cmp(&id, &expected_id, sizeof(id), "incorrect identify data"); } @@ -204,7 +204,7 @@ static void test_zns_identify_ctrl(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_zns_identify_ctrl(test_link, &id); end_mock_cmds(); - check(err == 0, "identify returned error %d, errno %m", err); + check(err == 0, "identify returned error %d", err); cmp(&id, &expected_id, sizeof(id), "incorrect identify data"); } @@ -226,7 +226,7 @@ static void test_active_ns_list_csi(void) err = nvme_identify_active_ns_list_csi( test_link, TEST_NSID, TEST_CSI, &id); end_mock_cmds(); - check(err == 0, "identify returned error %d, errno %m", err); + check(err == 0, "identify returned error %d", err); cmp(&id, &expected_id, sizeof(id), "incorrect identify data"); } @@ -247,7 +247,7 @@ static void test_independent_identify_ns(void) /* That's a mouthful! */ err = nvme_identify_independent_identify_ns(test_link, TEST_NSID, &id); end_mock_cmds(); - check(err == 0, "identify returned error %d, errno %m", err); + check(err == 0, "identify returned error %d", err); cmp(&id, &expected_id, sizeof(id), "incorrect identify data"); } @@ -267,7 +267,7 @@ static void test_allocated_ns_list(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_identify_allocated_ns_list(test_link, TEST_NSID, &id); end_mock_cmds(); - check(err == 0, "identify returned error %d, errno %m", err); + check(err == 0, "identify returned error %d", err); cmp(&id, &expected_id, sizeof(id), "incorrect identify data"); } @@ -287,7 +287,7 @@ static void test_allocated_ns(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_identify_allocated_ns(test_link, TEST_NSID, &id); end_mock_cmds(); - check(err == 0, "identify returned error %d, errno %m", err); + check(err == 0, "identify returned error %d", err); cmp(&id, &expected_id, sizeof(id), "incorrect identify data"); } @@ -308,7 +308,7 @@ static void test_nsid_ctrl_list(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_identify_nsid_ctrl_list(test_link, TEST_NSID, TEST_CNTID, &id); end_mock_cmds(); - check(err == 0, "identify returned error %d, errno %m", err); + check(err == 0, "identify returned error %d", err); cmp(&id, &expected_id, sizeof(id), "incorrect identify data"); } @@ -328,7 +328,7 @@ static void test_ctrl_list(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_identify_ctrl_list(test_link, TEST_CNTID, &id); end_mock_cmds(); - check(err == 0, "identify returned error %d, errno %m", err); + check(err == 0, "identify returned error %d", err); cmp(&id, &expected_id, sizeof(id), "incorrect identify data"); } @@ -348,7 +348,7 @@ static void test_primary_ctrl(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_identify_primary_ctrl(test_link, TEST_CNTID, &id); end_mock_cmds(); - check(err == 0, "identify returned error %d, errno %m", err); + check(err == 0, "identify returned error %d", err); cmp(&id, &expected_id, sizeof(id), "incorrect identify data"); } @@ -368,7 +368,7 @@ static void test_secondary_ctrl_list(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_identify_secondary_ctrl_list(test_link, TEST_CNTID, &id); end_mock_cmds(); - check(err == 0, "identify returned error %d, errno %m", err); + check(err == 0, "identify returned error %d", err); cmp(&id, &expected_id, sizeof(id), "incorrect identify data"); } @@ -387,7 +387,7 @@ static void test_ns_granularity(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_identify_ns_granularity(test_link, &id); end_mock_cmds(); - check(err == 0, "identify returned error %d, errno %m", err); + check(err == 0, "identify returned error %d", err); cmp(&id, &expected_id, sizeof(id), "incorrect identify data"); } @@ -406,7 +406,7 @@ static void test_uuid(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_identify_uuid(test_link, &id); end_mock_cmds(); - check(err == 0, "identify returned error %d, errno %m", err); + check(err == 0, "identify returned error %d", err); cmp(&id, &expected_id, sizeof(id), "incorrect identify data"); } @@ -426,7 +426,7 @@ static void test_domain_list(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_identify_domain_list(test_link, TEST_DOMID, &id); end_mock_cmds(); - check(err == 0, "identify returned error %d, errno %m", err); + check(err == 0, "identify returned error %d", err); cmp(&id, &expected_id, sizeof(id), "incorrect identify data"); } @@ -446,7 +446,7 @@ static void test_endurance_group_list(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_identify_endurance_group_list(test_link, TEST_ENDGID, &id); end_mock_cmds(); - check(err == 0, "identify returned error %d, errno %m", err); + check(err == 0, "identify returned error %d", err); cmp(&id, &expected_id, sizeof(id), "incorrect identify data"); } @@ -468,7 +468,7 @@ static void test_allocated_ns_list_csi(void) err = nvme_identify_allocated_ns_list_csi( test_link, TEST_NSID, TEST_CSI, &id); end_mock_cmds(); - check(err == 0, "identify returned error %d, errno %m", err); + check(err == 0, "identify returned error %d", err); cmp(&id, &expected_id, sizeof(id), "incorrect identify data"); } @@ -488,7 +488,7 @@ static void test_iocs(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_identify_iocs(test_link, TEST_CNTID, &id); end_mock_cmds(); - check(err == 0, "identify returned error %d, errno %m", err); + check(err == 0, "identify returned error %d", err); cmp(&id, &expected_id, sizeof(id), "incorrect identify data"); } @@ -512,7 +512,7 @@ static void test_status_code_error(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_identify_nvmset_list(test_link, TEST_NVMSETID, &id); end_mock_cmds(); - check(err == TEST_SC, "got error %d, expected %d", err, TEST_SC); + check(err == TEST_SC, "got error %d, expected TEST_SC", err); } static void test_kernel_error(void) @@ -530,8 +530,7 @@ static void test_kernel_error(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_identify_ns(test_link, TEST_NSID, &id); end_mock_cmds(); - check(err == -1, "got error %d, expected -1", err); - check(errno == EIO, "unexpected error %m"); + check(err == -EIO, "got error %d, expected -EIO", err); } static void test_identify_ns_csi_user_data_format(void) @@ -596,7 +595,7 @@ int main(void) nvme_root_t r = nvme_create_root(stdout, DEFAULT_LOGLEVEL); set_mock_fd(TEST_FD); - test_link = nvme_open(r, "NVME_TEST_FD"); + check(!nvme_open(r, "NVME_TEST_FD", &test_link), "opening test link failed"); RUN_TEST(ns); RUN_TEST(ctrl); diff --git a/test/ioctl/logs.c b/test/ioctl/logs.c index b715fbdd0..6b4467a4c 100644 --- a/test/ioctl/logs.c +++ b/test/ioctl/logs.c @@ -63,7 +63,7 @@ static void test_get_log_mgmt_addr_list(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_get_log_mgmt_addr_list(test_link, sizeof(log), &log); end_mock_cmds(); - check(err == 0, "get log returned error %d, errno %m", err); + check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); } @@ -85,7 +85,7 @@ static void test_get_log_supported_log_pages(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_get_log_supported_log_pages(test_link, !TEST_RAE, &log); end_mock_cmds(); - check(err == 0, "get log returned error %d, errno %m", err); + check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); } @@ -106,7 +106,7 @@ static void test_get_log_error(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_get_log_error(test_link, 1, TEST_RAE, &log); end_mock_cmds(); - check(err == 0, "get log returned error %d, errno %m", err); + check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); } @@ -127,7 +127,7 @@ static void test_get_log_smart(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_get_log_smart(test_link, TEST_NSID, TEST_RAE, &log); end_mock_cmds(); - check(err == 0, "get log returned error %d, errno %m", err); + check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); } @@ -148,7 +148,7 @@ static void test_get_log_fw_slot(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_get_log_fw_slot(test_link, TEST_RAE, &log); end_mock_cmds(); - check(err == 0, "get log returned error %d, errno %m", err); + check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); } @@ -169,7 +169,7 @@ static void test_get_log_changed_ns_list(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_get_log_changed_ns_list(test_link, TEST_RAE, &log); end_mock_cmds(); - check(err == 0, "get log returned error %d, errno %m", err); + check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); } @@ -191,7 +191,7 @@ static void test_get_log_cmd_effects(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_get_log_cmd_effects(test_link, TEST_CSI, &log); end_mock_cmds(); - check(err == 0, "get log returned error %d, errno %m", err); + check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); } @@ -212,7 +212,7 @@ static void test_get_log_device_self_test(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_get_log_device_self_test(test_link, &log); end_mock_cmds(); - check(err == 0, "get log returned error %d, errno %m", err); + check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); } @@ -235,7 +235,7 @@ static void test_get_log_create_telemetry_host_mcda(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_get_log_create_telemetry_host_mcda(test_link, TEST_MCDA, &log); end_mock_cmds(); - check(err == 0, "get log returned error %d, errno %m", err); + check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); } @@ -259,7 +259,7 @@ static void test_get_log_create_telemetry_host(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_get_log_create_telemetry_host(test_link, &log); end_mock_cmds(); - check(err == 0, "get log returned error %d, errno %m", err); + check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); } @@ -286,7 +286,7 @@ static void test_get_log_telemetry_host(void) err = nvme_get_log_telemetry_host(test_link, TEST_OFFSET, sizeof(log), &log); end_mock_cmds(); - check(err == 0, "get log returned error %d, errno %m", err); + check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); } @@ -314,7 +314,7 @@ static void test_get_log_telemetry_ctrl(void) err = nvme_get_log_telemetry_ctrl(test_link, TEST_RAE, TEST_OFFSET, sizeof(log), &log); end_mock_cmds(); - check(err == 0, "get log returned error %d, errno %m", err); + check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); } @@ -336,7 +336,7 @@ static void test_get_log_endurance_group(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_get_log_endurance_group(test_link, TEST_ENDGID, &log); end_mock_cmds(); - check(err == 0, "get log returned error %d, errno %m", err); + check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); } @@ -358,7 +358,7 @@ static void test_get_log_predictable_lat_nvmset(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_get_log_predictable_lat_nvmset(test_link, TEST_NVMSETID, &log); end_mock_cmds(); - check(err == 0, "get log returned error %d, errno %m", err); + check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); } @@ -382,7 +382,7 @@ static void test_get_log_predictable_lat_event(void) err = nvme_get_log_predictable_lat_event( test_link, TEST_RAE, TEST_OFFSET_32, sizeof(log), &log); end_mock_cmds(); - check(err == 0, "get log returned error %d, errno %m", err); + check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); } @@ -406,7 +406,7 @@ static void test_get_log_fdp_configurations(void) err = nvme_get_log_fdp_configurations( test_link, TEST_ENDGID, TEST_OFFSET_32, sizeof(log), &log); end_mock_cmds(); - check(err == 0, "get log returned error %d, errno %m", err); + check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); } @@ -430,7 +430,7 @@ static void test_get_log_reclaim_unit_handle_usage(void) err = nvme_get_log_reclaim_unit_handle_usage( test_link, TEST_ENDGID, TEST_OFFSET_32, sizeof(log), &log); end_mock_cmds(); - check(err == 0, "get log returned error %d, errno %m", err); + check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); } @@ -454,7 +454,7 @@ static void test_get_log_fdp_stats(void) err = nvme_get_log_fdp_stats(test_link, TEST_ENDGID, TEST_OFFSET_32, sizeof(log), &log); end_mock_cmds(); - check(err == 0, "get log returned error %d, errno %m", err); + check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); } @@ -479,7 +479,7 @@ static void test_get_log_fdp_events(void) err = nvme_get_log_fdp_events(test_link, TEST_ENDGID, TEST_EVENTS, TEST_OFFSET_32, sizeof(log), &log); end_mock_cmds(); - check(err == 0, "get log returned error %d, errno %m", err); + check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); } @@ -504,7 +504,7 @@ static void test_get_log_ana(void) err = nvme_get_log_ana(test_link, TEST_ANA_LSP, TEST_RAE, TEST_OFFSET, sizeof(log), &log); end_mock_cmds(); - check(err == 0, "get log returned error %d, errno %m", err); + check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); } @@ -527,7 +527,7 @@ static void test_get_log_ana_groups(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_get_log_ana_groups(test_link, TEST_RAE, sizeof(log), &log); end_mock_cmds(); - check(err == 0, "get log returned error %d, errno %m", err); + check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); } @@ -551,7 +551,7 @@ static void test_get_log_lba_status(void) err = nvme_get_log_lba_status(test_link, TEST_RAE, TEST_OFFSET, sizeof(log), &log); end_mock_cmds(); - check(err == 0, "get log returned error %d, errno %m", err); + check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); } @@ -575,7 +575,7 @@ static void test_get_log_endurance_grp_evt(void) err = nvme_get_log_endurance_grp_evt(test_link, TEST_RAE, TEST_OFFSET_32, sizeof(log), &log); end_mock_cmds(); - check(err == 0, "get log returned error %d, errno %m", err); + check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); } @@ -597,7 +597,7 @@ static void test_get_log_fid_supported_effects(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_get_log_fid_supported_effects(test_link, TEST_RAE, &log); end_mock_cmds(); - check(err == 0, "get log returned error %d, errno %m", err); + check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); } @@ -619,7 +619,7 @@ static void test_get_log_mi_cmd_supported_effects(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_get_log_mi_cmd_supported_effects(test_link, TEST_RAE, &log); end_mock_cmds(); - check(err == 0, "get log returned error %d, errno %m", err); + check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); } @@ -642,7 +642,7 @@ static void test_get_log_boot_partition(void) err = nvme_get_log_boot_partition(test_link, TEST_RAE, TEST_LSP, sizeof(log), &log); end_mock_cmds(); - check(err == 0, "get log returned error %d, errno %m", err); + check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); } @@ -665,7 +665,7 @@ static void test_get_log_rotational_media_info(void) err = nvme_get_log_rotational_media_info(test_link, TEST_ENDGID, sizeof(log), &log); end_mock_cmds(); - check(err == 0, "get log returned error %d, errno %m", err); + check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); } @@ -687,7 +687,7 @@ static void test_get_log_dispersed_ns_participating_nss(void) err = nvme_get_log_dispersed_ns_participating_nss(test_link, TEST_NSID, sizeof(log), &log); end_mock_cmds(); - check(err == 0, "get log returned error %d, errno %m", err); + check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); } @@ -710,7 +710,7 @@ static void test_get_log_phy_rx_eom(void) err = nvme_get_log_phy_rx_eom(test_link, TEST_LSP, TEST_CNTID, sizeof(log), &log); end_mock_cmds(); - check(err == 0, "get log returned error %d, errno %m", err); + check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); } @@ -733,7 +733,7 @@ static void test_get_log_reachability_groups(void) err = nvme_get_log_reachability_groups(test_link, !!TEST_LSP, TEST_RAE, sizeof(log), &log); end_mock_cmds(); - check(err == 0, "get log returned error %d, errno %m", err); + check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); } @@ -756,7 +756,7 @@ static void test_get_log_reachability_associations(void) err = nvme_get_log_reachability_associations( test_link, !!TEST_LSP, TEST_RAE, sizeof(log), &log); end_mock_cmds(); - check(err == 0, "get log returned error %d, errno %m", err); + check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); } @@ -779,7 +779,7 @@ static void test_get_log_changed_alloc_ns_list(void) err = nvme_get_log_changed_alloc_ns_list(test_link, TEST_RAE, sizeof(log), &log); end_mock_cmds(); - check(err == 0, "get log returned error %d, errno %m", err); + check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); } @@ -802,7 +802,7 @@ static void test_get_log_discovery(void) err = nvme_get_log_discovery(test_link, TEST_RAE, TEST_OFFSET_32, sizeof(log), &log); end_mock_cmds(); - check(err == 0, "get log returned error %d, errno %m", err); + check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); } @@ -825,7 +825,7 @@ static void test_get_log_host_discover(void) err = nvme_get_log_host_discover(test_link, !!TEST_LSP, TEST_RAE, sizeof(log), &log); end_mock_cmds(); - check(err == 0, "get log returned error %d, errno %m", err); + check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); } @@ -846,7 +846,7 @@ static void test_get_log_ave_discover(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_get_log_ave_discover(test_link, TEST_RAE, sizeof(log), &log); end_mock_cmds(); - check(err == 0, "get log returned error %d, errno %m", err); + check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); } @@ -869,7 +869,7 @@ static void test_get_log_pull_model_ddc_req(void) err = nvme_get_log_pull_model_ddc_req(test_link, TEST_RAE, sizeof(log), &log); end_mock_cmds(); - check(err == 0, "get log returned error %d, errno %m", err); + check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); } @@ -891,7 +891,7 @@ static void test_get_log_media_unit_stat(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_get_log_media_unit_stat(test_link, TEST_DOMID, &log); end_mock_cmds(); - check(err == 0, "get log returned error %d, errno %m", err); + check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); } @@ -913,7 +913,7 @@ static void test_get_log_support_cap_config_list(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_get_log_support_cap_config_list(test_link, TEST_DOMID, &log); end_mock_cmds(); - check(err == 0, "get log returned error %d, errno %m", err); + check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); } @@ -934,7 +934,7 @@ static void test_get_log_reservation(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_get_log_reservation(test_link, TEST_RAE, &log); end_mock_cmds(); - check(err == 0, "get log returned error %d, errno %m", err); + check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); } @@ -958,7 +958,7 @@ static void test_get_log_zns_changed_zones(void) err = nvme_get_log_zns_changed_zones(test_link, TEST_NSID, TEST_RAE, &log); end_mock_cmds(); - check(err == 0, "get log returned error %d, errno %m", err); + check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); } @@ -981,7 +981,7 @@ static void test_get_log_persistent_event(void) err = nvme_get_log_persistent_event(test_link, TEST_PEVENT, sizeof(log), &log); end_mock_cmds(); - check(err == 0, "get log returned error %d, errno %m", err); + check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); } @@ -1003,7 +1003,7 @@ static void test_get_log_lockdown(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_get_log_lockdown(test_link, TEST_LSP, &log); end_mock_cmds(); - check(err == 0, "get log returned error %d, errno %m", err); + check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); } @@ -1022,7 +1022,7 @@ int main(void) nvme_root_t r = nvme_create_root(stdout, DEFAULT_LOGLEVEL); set_mock_fd(TEST_FD); - test_link = nvme_open(r, "NVME_TEST_FD"); + check(!nvme_open(r, "NVME_TEST_FD", &test_link), "opening test link failed"); RUN_TEST(get_log_sanitize); RUN_TEST(get_log_mgmt_addr_list); diff --git a/test/ioctl/misc.c b/test/ioctl/misc.c index f3621d093..1ff943d7f 100644 --- a/test/ioctl/misc.c +++ b/test/ioctl/misc.c @@ -43,7 +43,7 @@ static void test_format_nvm(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_format_nvm(test_link, &args); end_mock_cmds(); - check(err == 0, "returned error %d, errno %m", err); + check(err == 0, "returned error %d", err); check(result == 0, "returned result %u", result); } @@ -77,7 +77,7 @@ static void test_ns_mgmt(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_ns_mgmt(test_link, &args); end_mock_cmds(); - check(err == 0, "returned error %d, errno %m", err); + check(err == 0, "returned error %d", err); check(result == 0, "returned result %u", result); cmp(&data, &expected_data, sizeof(data), "incorrect data"); } @@ -103,7 +103,7 @@ static void test_ns_mgmt_create(void) err = nvme_ns_mgmt_create(test_link, NULL, &result, 0, NVME_CSI_ZNS, &data); end_mock_cmds(); - check(err == 0, "returned error %d, errno %m", err); + check(err == 0, "returned error %d", err); check(result == TEST_NSID, "returned result %u", result); cmp(&data, &expected_data, sizeof(data), "incorrect data"); } @@ -121,7 +121,7 @@ static void test_ns_mgmt_delete(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_ns_mgmt_delete(test_link, TEST_NSID); end_mock_cmds(); - check(err == 0, "returned error %d, errno %m", err); + check(err == 0, "returned error %d", err); } static void test_get_property(void) @@ -148,7 +148,7 @@ static void test_get_property(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_get_property(test_link, &args); end_mock_cmds(); - check(err == 0, "returned error %d, errno %m", err); + check(err == 0, "returned error %d", err); check(result == expected_result, "returned wrong result"); } @@ -177,7 +177,7 @@ static void test_set_property(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_set_property(test_link, &args); end_mock_cmds(); - check(err == 0, "returned error %d, errno %m", err); + check(err == 0, "returned error %d", err); check(result == 0, "returned result %u", result); } @@ -207,7 +207,7 @@ static void test_ns_attach(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_ns_attach(test_link, &args); end_mock_cmds(); - check(err == 0, "returned error %d, errno %m", err); + check(err == 0, "returned error %d", err); check(result == 0, "returned result %u", result); cmp(&expected_ctrlist, &ctrlist, sizeof(expected_ctrlist), "incorrect data"); @@ -231,7 +231,7 @@ static void test_ns_attach_ctrls(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_ns_attach_ctrls(test_link, TEST_NSID, &ctrlist); end_mock_cmds(); - check(err == 0, "returned error %d, errno %m", err); + check(err == 0, "returned error %d", err); } static void test_ns_detach_ctrls(void) @@ -252,7 +252,7 @@ static void test_ns_detach_ctrls(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_ns_detach_ctrls(test_link, TEST_NSID, &ctrlist); end_mock_cmds(); - check(err == 0, "returned error %d, errno %m", err); + check(err == 0, "returned error %d", err); } static void test_fw_download(void) @@ -283,7 +283,7 @@ static void test_fw_download(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_fw_download(test_link, &args); end_mock_cmds(); - check(err == 0, "returned error %d, errno %m", err); + check(err == 0, "returned error %d", err); check(result == 0, "returned result %u", result); } @@ -309,7 +309,7 @@ static void test_fw_commit(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_fw_commit(test_link, &args); end_mock_cmds(); - check(err == 0, "returned error %d, errno %m", err); + check(err == 0, "returned error %d", err); check(result == 0, "returned result %u", result); } @@ -348,7 +348,7 @@ static void test_security_send(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_security_send(test_link, &args); end_mock_cmds(); - check(err == 0, "returned error %d, errno %m", err); + check(err == 0, "returned error %d", err); check(result == 0, "returned result %u", result); cmp(&data, &expected_data, sizeof(data), "incorrect data"); } @@ -387,7 +387,7 @@ static void test_security_receive(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_security_receive(test_link, &args); end_mock_cmds(); - check(err == 0, "returned error %d, errno %m", err); + check(err == 0, "returned error %d", err); check(result == 0, "returned result %u", result); cmp(&data, &expected_data, sizeof(data), "incorrect data"); } @@ -435,7 +435,7 @@ static void test_get_lba_status(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_get_lba_status(test_link, &args); end_mock_cmds(); - check(err == 0, "returned error %d, errno %m", err); + check(err == 0, "returned error %d", err); check(result == 0, "returned wrong result"); cmp(lbas, expected_lbas, lba_status_size, "incorrect lbas"); } @@ -474,7 +474,7 @@ static void test_directive_send(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_directive_send(test_link, &args); end_mock_cmds(); - check(err == 0, "returned error %d, errno %m", err); + check(err == 0, "returned error %d", err); check(result == 0, "returned wrong result"); cmp(&data, &expected_data, sizeof(data), "incorrect data"); } @@ -502,7 +502,7 @@ static void test_directive_send_id_endir(void) err = nvme_directive_send_id_endir(test_link, TEST_NSID, true, NVME_DIRECTIVE_DTYPE_STREAMS, &id); end_mock_cmds(); - check(err == 0, "returned error %d, errno %m", err); + check(err == 0, "returned error %d", err); cmp(&id, &expected_id, sizeof(id), "incorrect id"); } @@ -523,7 +523,7 @@ static void test_directive_send_stream_release_identifier(void) err = nvme_directive_send_stream_release_identifier(test_link, TEST_NSID, stream_id); end_mock_cmds(); - check(err == 0, "returned error %d, errno %m", err); + check(err == 0, "returned error %d", err); } static void test_directive_send_stream_release_resource(void) @@ -540,7 +540,7 @@ static void test_directive_send_stream_release_resource(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_directive_send_stream_release_resource(test_link, TEST_NSID); end_mock_cmds(); - check(err == 0, "returned error %d, errno %m", err); + check(err == 0, "returned error %d", err); } static void test_directive_recv(void) @@ -576,7 +576,7 @@ static void test_directive_recv(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_directive_recv(test_link, &args); end_mock_cmds(); - check(err == 0, "returned error %d, errno %m", err); + check(err == 0, "returned error %d", err); check(result == 0, "returned wrong result"); cmp(&data, &expected_data, sizeof(data), "incorrect data"); } @@ -601,7 +601,7 @@ static void test_directive_recv_identify_parameters(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_directive_recv_identify_parameters(test_link, TEST_NSID, &id); end_mock_cmds(); - check(err == 0, "returned error %d, errno %m", err); + check(err == 0, "returned error %d", err); cmp(&id, &expected_id, sizeof(id), "incorrect id"); } @@ -626,7 +626,7 @@ static void test_directive_recv_stream_parameters(void) err = nvme_directive_recv_stream_parameters(test_link, TEST_NSID, ¶ms); end_mock_cmds(); - check(err == 0, "returned error %d, errno %m", err); + check(err == 0, "returned error %d", err); cmp(¶ms, &expected_params, sizeof(params), "incorrect params"); } @@ -663,7 +663,7 @@ static void test_directive_recv_stream_status(void) err = nvme_directive_recv_stream_status(test_link, TEST_NSID, nr_entries, status); end_mock_cmds(); - check(err == 0, "returned error %d, errno %m", err); + check(err == 0, "returned error %d", err); cmp(status, expected_status, stream_status_size, "incorrect status"); } @@ -687,7 +687,7 @@ static void test_directive_recv_stream_allocate(void) err = nvme_directive_recv_stream_allocate(test_link, TEST_NSID, nsr, &result); end_mock_cmds(); - check(err == 0, "returned error %d, errno %m", err); + check(err == 0, "returned error %d", err); check(result == expected_result, "wrong result"); } @@ -718,7 +718,7 @@ static void test_capacity_mgmt(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_capacity_mgmt(test_link, &args); end_mock_cmds(); - check(err == 0, "returned error %d, errno %m", err); + check(err == 0, "returned error %d", err); check(result == expected_result, "wrong result"); } @@ -749,7 +749,7 @@ static void test_lockdown(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_lockdown(test_link, &args); end_mock_cmds(); - check(err == 0, "returned error %d, errno %m", err); + check(err == 0, "returned error %d", err); check(result == expected_result, "wrong result"); } @@ -782,7 +782,7 @@ static void test_sanitize_nvm(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_sanitize_nvm(test_link, &args); end_mock_cmds(); - check(err == 0, "returned error %d, errno %m", err); + check(err == 0, "returned error %d", err); check(result == expected_result, "wrong result"); } @@ -809,7 +809,7 @@ static void test_dev_self_test(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_dev_self_test(test_link, &args); end_mock_cmds(); - check(err == 0, "returned error %d, errno %m", err); + check(err == 0, "returned error %d", err); check(result == expected_result, "wrong result"); } @@ -838,7 +838,7 @@ static void test_virtual_mgmt(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_virtual_mgmt(test_link, &args); end_mock_cmds(); - check(err == 0, "returned error %d, errno %m", err); + check(err == 0, "returned error %d", err); check(result == expected_result, "wrong result"); } @@ -854,7 +854,7 @@ static void test_flush(void) set_mock_io_cmds(&mock_io_cmd, 1); err = nvme_flush(test_link, TEST_NSID); end_mock_cmds(); - check(err == 0, "returned error %d, errno %m", err); + check(err == 0, "returned error %d", err); } static void test_read(void) @@ -897,7 +897,7 @@ static void test_read(void) set_mock_io_cmds(&mock_io_cmd, 1); err = nvme_read(test_link, &args); end_mock_cmds(); - check(err == 0, "returned error %d, errno %m", err); + check(err == 0, "returned error %d", err); check(result == 0, "returned result %u", result); } @@ -942,7 +942,7 @@ static void test_write(void) set_mock_io_cmds(&mock_io_cmd, 1); err = nvme_write(test_link, &args); end_mock_cmds(); - check(err == 0, "returned error %d, errno %m", err); + check(err == 0, "returned error %d", err); check(result == 0, "returned result %u", result); } @@ -987,7 +987,7 @@ static void test_compare(void) set_mock_io_cmds(&mock_io_cmd, 1); err = nvme_compare(test_link, &args); end_mock_cmds(); - check(err == 0, "returned error %d, errno %m", err); + check(err == 0, "returned error %d", err); check(result == 0, "returned result %u", result); } @@ -1032,7 +1032,7 @@ static void test_write_zeros(void) set_mock_io_cmds(&mock_io_cmd, 1); err = nvme_write_zeros(test_link, &args); end_mock_cmds(); - check(err == 0, "returned error %d, errno %m", err); + check(err == 0, "returned error %d", err); check(result == 0, "returned result %u", result); } @@ -1077,7 +1077,7 @@ static void test_write_uncorrectable(void) set_mock_io_cmds(&mock_io_cmd, 1); err = nvme_write_uncorrectable(test_link, &args); end_mock_cmds(); - check(err == 0, "returned error %d, errno %m", err); + check(err == 0, "returned error %d", err); check(result == 0, "returned result %u", result); } @@ -1122,7 +1122,7 @@ static void test_verify(void) set_mock_io_cmds(&mock_io_cmd, 1); err = nvme_verify(test_link, &args); end_mock_cmds(); - check(err == 0, "returned error %d, errno %m", err); + check(err == 0, "returned error %d", err); check(result == 0, "returned result %u", result); } @@ -1161,7 +1161,7 @@ static void test_dsm(void) set_mock_io_cmds(&mock_io_cmd, 1); err = nvme_dsm(test_link, &args); end_mock_cmds(); - check(err == 0, "returned error %d, errno %m", err); + check(err == 0, "returned error %d", err); check(result == 0, "returned result %u", result); } @@ -1205,7 +1205,7 @@ static void test_copy(void) set_mock_io_cmds(&mock_io_cmd, 1); err = nvme_copy(test_link, &args); end_mock_cmds(); - check(err == 0, "returned error %d, errno %m", err); + check(err == 0, "returned error %d", err); check(result == 0, "returned result %u", result); } @@ -1240,7 +1240,7 @@ static void test_resv_acquire(void) set_mock_io_cmds(&mock_io_cmd, 1); err = nvme_resv_acquire(test_link, &args); end_mock_cmds(); - check(err == 0, "returned error %d, errno %m", err); + check(err == 0, "returned error %d", err); check(result == 0, "returned result %u", result); } @@ -1275,7 +1275,7 @@ static void test_resv_register(void) set_mock_io_cmds(&mock_io_cmd, 1); err = nvme_resv_register(test_link, &args); end_mock_cmds(); - check(err == 0, "returned error %d, errno %m", err); + check(err == 0, "returned error %d", err); check(result == 0, "returned result %u", result); } @@ -1309,7 +1309,7 @@ static void test_resv_release(void) set_mock_io_cmds(&mock_io_cmd, 1); err = nvme_resv_release(test_link, &args); end_mock_cmds(); - check(err == 0, "returned error %d, errno %m", err); + check(err == 0, "returned error %d", err); check(result == 0, "returned result %u", result); } @@ -1343,7 +1343,7 @@ static void test_resv_report(void) set_mock_io_cmds(&mock_io_cmd, 1); err = nvme_resv_report(test_link, &args); end_mock_cmds(); - check(err == 0, "returned error %d, errno %m", err); + check(err == 0, "returned error %d", err); check(result == 0, "returned result %u", result); cmp(&status, &expected_status, sizeof(status), "incorrect status"); } @@ -1375,7 +1375,7 @@ static void test_io_mgmt_recv(void) set_mock_io_cmds(&mock_io_cmd, 1); err = nvme_io_mgmt_recv(test_link, &args); end_mock_cmds(); - check(err == 0, "returned error %d, errno %m", err); + check(err == 0, "returned error %d", err); cmp(&data, &expected_data, sizeof(data), "incorrect data"); } @@ -1406,7 +1406,7 @@ static void test_io_mgmt_send(void) set_mock_io_cmds(&mock_io_cmd, 1); err = nvme_io_mgmt_send(test_link, &args); end_mock_cmds(); - check(err == 0, "returned error %d, errno %m", err); + check(err == 0, "returned error %d", err); cmp(&data, &expected_data, sizeof(data), "incorrect data"); } @@ -1430,7 +1430,7 @@ static void test_fdp_reclaim_unit_handle_status(void) err = nvme_fdp_reclaim_unit_handle_status(test_link, TEST_NSID, data_len, &data); end_mock_cmds(); - check(err == 0, "returned error %d, errno %m", err); + check(err == 0, "returned error %d", err); cmp(&data, &expected_data, sizeof(data), "incorrect data"); } @@ -1453,7 +1453,7 @@ static void test_fdp_reclaim_unit_handle_update(void) err = nvme_fdp_reclaim_unit_handle_update(test_link, TEST_NSID, npids, &pids); end_mock_cmds(); - check(err == 0, "returned error %d, errno %m", err); + check(err == 0, "returned error %d", err); } static void test_dim_send(void) @@ -1482,7 +1482,7 @@ static void test_dim_send(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_dim_send(test_link, &args); end_mock_cmds(); - check(err == 0, "returned error %d, errno %m", err); + check(err == 0, "returned error %d", err); check(result == 0, "returned result %u", result); cmp(&data, &expected_data, sizeof(data), "incorrect data"); } @@ -1518,7 +1518,7 @@ static void test_lm_cdq(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_lm_cdq(test_link, &args); end_mock_cmds(); - check(err == 0, "returned error %d, errno %m", err); + check(err == 0, "returned error %d", err); check(result == 0, "returned result %u", result); cmp(&data, &expected_data, sizeof(data), "incorrect data"); } @@ -1545,7 +1545,7 @@ static void test_lm_track_send(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_lm_track_send(test_link, &args); end_mock_cmds(); - check(err == 0, "returned error %d, errno %m", err); + check(err == 0, "returned error %d", err); check(result == 0, "returned result %u", result); } @@ -1589,7 +1589,7 @@ static void test_lm_migration_send(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_lm_migration_send(test_link, &args); end_mock_cmds(); - check(err == 0, "returned error %d, errno %m", err); + check(err == 0, "returned error %d", err); check(result == 0, "returned result %u", result); cmp(&data, &expected_data, sizeof(data), "incorrect data"); } @@ -1631,7 +1631,7 @@ static void test_lm_migration_recv(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_lm_migration_recv(test_link, &args); end_mock_cmds(); - check(err == 0, "returned error %d, errno %m", err); + check(err == 0, "returned error %d", err); check(result == 0, "returned result %u", result); cmp(&data, &expected_data, sizeof(data), "incorrect data"); } @@ -1651,7 +1651,7 @@ int main(void) nvme_root_t r = nvme_create_root(stdout, DEFAULT_LOGLEVEL); set_mock_fd(TEST_FD); - test_link = nvme_open(r, "NVME_TEST_FD"); + check(!nvme_open(r, "NVME_TEST_FD", &test_link), "opening test link failed"); RUN_TEST(format_nvm); RUN_TEST(ns_mgmt); diff --git a/test/ioctl/zns.c b/test/ioctl/zns.c index 5bc55b2b1..53d69bf39 100644 --- a/test/ioctl/zns.c +++ b/test/ioctl/zns.c @@ -51,7 +51,7 @@ static void test_zns_append(void) set_mock_io_cmds(&mock_io_cmd, 1); err = nvme_zns_append(test_link, &args); end_mock_cmds(); - check(err == 0, "returned error %d, errno %m", err); + check(err == 0, "returned error %d", err); check(result == 0, "wrong result"); cmp(&data, &expected_data, sizeof(data), "incorrect data"); } @@ -86,7 +86,7 @@ static void test_zns_report_zones(void) extended, partial, sizeof(data), &data, timeout, &result); end_mock_cmds(); - check(err == 0, "returned error %d, errno %m", err); + check(err == 0, "returned error %d", err); check(result == 0, "returned result %u", result); cmp(&data, &expected_data, sizeof(data), "incorrect data"); } @@ -128,7 +128,7 @@ static void test_zns_mgmt_send(void) set_mock_io_cmds(&mock_io_cmd, 1); err = nvme_zns_mgmt_send(test_link, &args); end_mock_cmds(); - check(err == 0, "returned error %d, errno %m", err); + check(err == 0, "returned error %d", err); check(result == 0, "returned result %u", result); cmp(&data, &expected_data, sizeof(data), "incorrect data"); } @@ -170,7 +170,7 @@ static void test_zns_mgmt_recv(void) set_mock_io_cmds(&mock_io_cmd, 1); err = nvme_zns_mgmt_recv(test_link, &args); end_mock_cmds(); - check(err == 0, "returned error %d, errno %m", err); + check(err == 0, "returned error %d", err); check(result == 0, "returned result %u", result); cmp(&data, &expected_data, sizeof(data), "incorrect data"); } @@ -190,7 +190,7 @@ int main(void) nvme_root_t r = nvme_create_root(stdout, DEFAULT_LOGLEVEL); set_mock_fd(TEST_FD); - test_link = nvme_open(r, "NVME_TEST_FD"); + check(!nvme_open(r, "NVME_TEST_FD", &test_link), "opening test link failed"); RUN_TEST(zns_append); RUN_TEST(zns_report_zones); diff --git a/test/mi-mctp.c b/test/mi-mctp.c index 5daa6fe94..590243483 100644 --- a/test/mi-mctp.c +++ b/test/mi-mctp.c @@ -1168,16 +1168,14 @@ static void test_mi_aem_ep_based_failure_helper(nvme_mi_ep_t ep, case AEM_FC_BAD_OCC_RSP_TOTAL_LEN_SYNC: case AEM_FC_BAD_OCC_RSP_BUFFER_LEN_SYNC: //These all should fail before processing - assert(nvme_mi_aem_enable(ep, &config, &fn_data) == -1); - assert(errno == EPROTO); + assert(nvme_mi_aem_enable(ep, &config, &fn_data) == -EPROTO); break; case AEM_FC_BAD_OCC_RSP_HDR_LEN_AEM: case AEM_FC_BAD_OCC_RSP_TOTAL_LEN_AEM: case AEM_FC_BAD_OCC_RSP_BUFFER_LEN_AEM: //These should fail on the processing assert(nvme_mi_aem_enable(ep, &config, &fn_data) == 0); - assert(nvme_mi_aem_process(ep, &fn_data) == -1); - assert(errno == EPROTO); + assert(nvme_mi_aem_process(ep, &fn_data) == -EPROTO); break; default: assert(false);//Unexpected diff --git a/test/psk.c b/test/psk.c index 02cb6d813..6f65ce142 100644 --- a/test/psk.c +++ b/test/psk.c @@ -73,6 +73,7 @@ static void check_str(const char *exp, const char *res) static void export_test(struct test_data *test) { char *psk; + int ret; if (test->version != 1 || !(test->hmac == NVME_HMAC_ALG_SHA2_256 || @@ -82,10 +83,10 @@ static void export_test(struct test_data *test) printf("test nvme_export_tls_key hmac %d %s\n", test->hmac, test->exported_psk); - psk = nvme_export_tls_key(test->configured_psk, test->psk_length); - if (!psk) { + ret = nvme_export_tls_key(test->configured_psk, test->psk_length, &psk); + if (ret) { test_rc = 1; - printf("ERROR: nvme_export_tls_key() failed with %d\n", errno); + printf("ERROR: nvme_export_tls_key() failed with %d\n", ret); return; } check_str(test->exported_psk, psk); @@ -97,6 +98,7 @@ static void import_test(struct test_data *test) unsigned char *psk; int psk_length; unsigned int hmac; + int ret; if (test->version != 1 || !(test->hmac == NVME_HMAC_ALG_SHA2_256 || @@ -106,10 +108,10 @@ static void import_test(struct test_data *test) printf("test nvme_import_tls_key hmac %d %s\n", test->hmac, test->exported_psk); - psk = nvme_import_tls_key(test->exported_psk, &psk_length, &hmac); - if (!psk) { + ret = nvme_import_tls_key(test->exported_psk, &psk_length, &hmac, &psk); + if (ret) { test_rc = 1; - printf("ERROR: nvme_import_tls_key() failed with %d\n", errno); + printf("ERROR: nvme_import_tls_key() failed with %d\n", ret); return; } @@ -136,6 +138,7 @@ static void import_test(struct test_data *test) static void export_versioned_test(struct test_data *test) { char *psk; + int ret; if (test->version != 1) return; @@ -143,13 +146,13 @@ static void export_versioned_test(struct test_data *test) printf("test nvme_export_tls_key_versioned hmac %d %s\n", test->hmac, test->exported_psk); - psk = nvme_export_tls_key_versioned(test->version, test->hmac, + ret = nvme_export_tls_key_versioned(test->version, test->hmac, test->configured_psk, - test->psk_length); - if (!psk) { + test->psk_length, &psk); + if (ret) { test_rc = 1; printf("ERROR: nvme_export_tls_key_versioned() failed with %d\n", - errno); + ret); return; } @@ -164,6 +167,7 @@ static void import_versioned_test(struct test_data *test) unsigned char version; unsigned char hmac; size_t psk_length; + int ret; if (test->version != 1) return; @@ -171,12 +175,12 @@ static void import_versioned_test(struct test_data *test) printf("test nvme_import_tls_key_versioned hmac %d %s\n", test->hmac, test->exported_psk); - psk = nvme_import_tls_key_versioned(test->exported_psk, &version, - &hmac, &psk_length); - if (!psk) { + ret = nvme_import_tls_key_versioned(test->exported_psk, &version, + &hmac, &psk_length, &psk); + if (ret) { test_rc = 1; printf("ERROR: nvme_import_tls_key_versioned() failed with %d\n", - errno); + ret); return; } diff --git a/test/sysfs/tree-dump.c b/test/sysfs/tree-dump.c index 3cee349f7..b3555299f 100644 --- a/test/sysfs/tree-dump.c +++ b/test/sysfs/tree-dump.c @@ -22,10 +22,8 @@ static bool tree_dump(void) return false; err = nvme_scan_topology(r, NULL, NULL); - if (err) { - if (errno != ENOENT) - goto out; - } + if (err && err != ENOENT) + goto out; if (nvme_dump_tree(r)) goto out; diff --git a/test/test.c b/test/test.c index 6d9cc9fa4..8ce2f626c 100644 --- a/test/test.c +++ b/test/test.c @@ -351,8 +351,7 @@ int main(int argc, char **argv) ctrl = argv[1]; printf("Test scan specific controller\n"); - c = nvme_scan_ctrl(r, ctrl); - if (c) { + if (!nvme_scan_ctrl(r, ctrl, &c)) { printf("%s %s %s %s\n", nvme_ctrl_get_name(c), nvme_ctrl_get_transport(c), nvme_ctrl_get_address(c), @@ -362,8 +361,7 @@ int main(int argc, char **argv) printf("\n"); nvme_free_root(r); - r = nvme_scan(NULL); - if (!r) + if (nvme_scan(NULL, &r)) return -1; printf("Test walking the topology\n"); diff --git a/test/tree.c b/test/tree.c index 6c6b144f8..0eb155626 100644 --- a/test/tree.c +++ b/test/tree.c @@ -125,7 +125,7 @@ static nvme_root_t create_tree() r = nvme_create_root(stdout, LOG_DEBUG); assert(r); - h = nvme_default_host(r); + nvme_default_host(r, &h); assert(h); printf(" ctrls created:\n"); @@ -281,7 +281,7 @@ static bool test_src_addr() r = nvme_create_root(stdout, LOG_DEBUG); assert(r); - h = nvme_default_host(r); + nvme_default_host(r, &h); assert(h); s = nvme_lookup_subsystem(h, DEFAULT_SUBSYSNAME, DEFAULT_SUBSYSNQN); @@ -457,7 +457,7 @@ static bool ctrl_match(const char *tag, r = nvme_create_root(stdout, LOG_INFO); assert(r); - h = nvme_default_host(r); + nvme_default_host(r, &h); assert(h); s = nvme_lookup_subsystem(h, DEFAULT_SUBSYSNAME, reference->subsysnqn ? reference->subsysnqn : DEFAULT_SUBSYSNQN); @@ -1070,7 +1070,7 @@ static bool ctrl_config_match(const char *tag, r = nvme_create_root(stdout, LOG_INFO); assert(r); - h = nvme_default_host(r); + nvme_default_host(r, &h); assert(h); s = nvme_lookup_subsystem(h, DEFAULT_SUBSYSNAME, reference->subsysnqn ? reference->subsysnqn : DEFAULT_SUBSYSNQN); diff --git a/test/uriparser.c b/test/uriparser.c index 09b2a732b..428c5495d 100644 --- a/test/uriparser.c +++ b/test/uriparser.c @@ -159,8 +159,7 @@ static void test_uriparser(void) int i; printf(" '%s'...", d->uri); - parsed_data = nvme_parse_uri(d->uri); - assert(parsed_data); + assert(!nvme_parse_uri(d->uri, &parsed_data)); assert(strcmp(d->scheme, parsed_data->scheme) == 0); if (d->proto) { @@ -201,10 +200,10 @@ static void test_uriparser_bad(void) { printf("Testing malformed URI strings:\n"); for (int i = 0; i < ARRAY_SIZE(test_data_bad); i++) { - struct nvme_fabrics_uri *parsed_data; + struct nvme_fabrics_uri *parsed_data = NULL; printf(" '%s'...", test_data_bad[i]); - parsed_data = nvme_parse_uri(test_data_bad[i]); + assert(nvme_parse_uri(test_data_bad[i], &parsed_data)); assert(parsed_data == NULL); printf(" OK\n"); } diff --git a/test/zns.c b/test/zns.c index 0e4e90ef5..5d76555a8 100644 --- a/test/zns.c +++ b/test/zns.c @@ -68,8 +68,7 @@ int main() nvme_ctrl_t c; nvme_ns_t n; - r = nvme_scan(NULL); - if (!r) + if (nvme_scan(NULL, &r)) return -1; nvme_for_each_host(r, h) { From 443b72e348d996d24e81e9c93b7ad1db4b425bf8 Mon Sep 17 00:00:00 2001 From: Daniel Wagner Date: Thu, 31 Jul 2025 11:09:27 +0200 Subject: [PATCH 15/66] ioctl: add nvme_identify_partial MI doesn't access the complete identify data struct and thus only transfers a port of it. Add a generic version of this function. Signed-off-by: Daniel Wagner --- src/libnvme.map | 1 + src/nvme/ioctl.c | 10 ++++++++-- src/nvme/ioctl.h | 15 +++++++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/libnvme.map b/src/libnvme.map index f2f8d010b..887069068 100644 --- a/src/libnvme.map +++ b/src/libnvme.map @@ -154,6 +154,7 @@ LIBNVME_2_0 { nvme_host_set_hostsymname; nvme_host_set_pdc_enabled; nvme_identify; + nvme_identify_partial; nvme_import_tls_key; nvme_import_tls_key_versioned; nvme_init_copy_range; diff --git a/src/nvme/ioctl.c b/src/nvme/ioctl.c index 63afaab05..38e9ae974 100644 --- a/src/nvme/ioctl.c +++ b/src/nvme/ioctl.c @@ -282,7 +282,8 @@ enum features { NVME_FEATURES_IOCSP_IOCSCI_MASK = 0xff, }; -int nvme_identify(nvme_link_t l, struct nvme_identify_args *args) +int nvme_identify_partial(nvme_link_t l, __u32 xfer_len, + struct nvme_identify_args *args) { __u32 cdw10 = NVME_SET(args->cntid, IDENTIFY_CDW10_CNTID) | NVME_SET(args->cns, IDENTIFY_CDW10_CNS); @@ -294,7 +295,7 @@ int nvme_identify(nvme_link_t l, struct nvme_identify_args *args) .opcode = nvme_admin_identify, .nsid = args->nsid, .addr = (__u64)(uintptr_t)args->data, - .data_len = NVME_IDENTIFY_DATA_SIZE, + .data_len = xfer_len, .cdw10 = cdw10, .cdw11 = cdw11, .cdw14 = cdw14, @@ -307,6 +308,11 @@ int nvme_identify(nvme_link_t l, struct nvme_identify_args *args) return nvme_submit_admin_passthru(l, &cmd, args->result); } +int nvme_identify(nvme_link_t l, struct nvme_identify_args *args) +{ + return nvme_identify_partial(l, NVME_IDENTIFY_DATA_SIZE, args); +} + int nvme_get_log(nvme_link_t l, struct nvme_get_log_args *args) { __u32 numd = (args->len >> 2) - 1; diff --git a/src/nvme/ioctl.h b/src/nvme/ioctl.h index 2518b5288..0867f4a08 100644 --- a/src/nvme/ioctl.h +++ b/src/nvme/ioctl.h @@ -576,6 +576,21 @@ int nvme_ns_rescan(nvme_link_t l); */ int nvme_get_nsid(nvme_link_t l, __u32 *nsid); +/** + * nvme_identify_partial() - Send the NVMe Identify command + * @l: Link handle + * @xfer_len: Max log transfer size per request to split the total. + * @args: &struct nvme_identify_args argument structure + * + * The Identify command returns a data buffer that describes information about + * the NVM subsystem, the controller or the namespace(s). + * + * Return: 0 on success, the nvme command status if a response was + * received (see &enum nvme_status_field) or a negative error otherwise. + */ +int nvme_identify_partial(nvme_link_t l, __u32 xfer_len, + struct nvme_identify_args *args); + /** * nvme_identify() - Send the NVMe Identify command * @l: Link handle From 88bac18e7d1652cce857c6dd31d2ea884b1cf4a4 Mon Sep 17 00:00:00 2001 From: Daniel Wagner Date: Thu, 31 Jul 2025 14:21:25 +0200 Subject: [PATCH 16/66] mi: remove nvme_mi_admin_identify{_partial} Use the generic nvme_identify{_partial} interface and drop the MI specific version. Signed-off-by: Daniel Wagner --- examples/mi-mctp.c | 6 ++--- src/libnvme.map | 1 - src/nvme/mi.c | 53 ++------------------------------------------ src/nvme/mi.h | 55 ---------------------------------------------- 4 files changed, 5 insertions(+), 110 deletions(-) diff --git a/examples/mi-mctp.c b/examples/mi-mctp.c index 75b156879..61a807977 100644 --- a/examples/mi-mctp.c +++ b/examples/mi-mctp.c @@ -220,10 +220,10 @@ int do_identify(nvme_mi_ep_t ep, int argc, char **argv) * response. */ if (partial) { - rc = nvme_mi_admin_identify_partial(link, &id_args, 0, - offsetof(struct nvme_id_ctrl, rab)); + rc = nvme_identify_partial(link, offsetof(struct nvme_id_ctrl, rab), + &id_args); } else { - rc = nvme_mi_admin_identify(link, &id_args); + rc = nvme_identify(link, &id_args); } if (rc) { diff --git a/src/libnvme.map b/src/libnvme.map index 887069068..157e72b29 100644 --- a/src/libnvme.map +++ b/src/libnvme.map @@ -193,7 +193,6 @@ LIBNVME_2_0 { nvme_lookup_keyring; nvme_lookup_subsystem; nvme_mi_admin_admin_passthru; - nvme_mi_admin_identify_partial; nvme_mi_admin_xfer; nvme_mi_aem_disable; nvme_mi_aem_enable; diff --git a/src/nvme/mi.c b/src/nvme/mi.c index 58a156307..b59f0e7ec 100644 --- a/src/nvme/mi.c +++ b/src/nvme/mi.c @@ -259,8 +259,8 @@ void nvme_mi_ep_probe(struct nvme_mi_ep *ep) id_args.cntid = 0; id_args.csi = NVME_CSI_NVM; - rc = nvme_mi_admin_identify_partial(link, &id_args, 0, - offsetof(struct nvme_id_ctrl, rab)); + rc = nvme_identify_partial(link, offsetof(struct nvme_id_ctrl, rab), + &id_args); if (rc) { nvme_msg(ep->root, LOG_WARNING, "Identify Controller failed, no quirks applied\n"); @@ -956,55 +956,6 @@ int nvme_mi_admin_admin_passthru(nvme_link_t link, __u8 opcode, __u8 flags, return 0; } -int nvme_mi_admin_identify_partial(nvme_link_t link, - struct nvme_identify_args *args, - off_t offset, size_t size) -{ - struct nvme_mi_admin_resp_hdr resp_hdr; - struct nvme_mi_admin_req_hdr req_hdr; - struct nvme_mi_resp resp; - struct nvme_mi_req req; - int rc; - - if (args->args_size < sizeof(*args)) - return -EINVAL; - - if (!size || size > 0xffffffff) - return -EINVAL; - - nvme_mi_admin_init_req(link->ep, &req, &req_hdr, link->id, nvme_admin_identify); - req_hdr.cdw1 = cpu_to_le32(args->nsid); - req_hdr.cdw10 = cpu_to_le32(args->cntid << 16 | args->cns); - req_hdr.cdw11 = cpu_to_le32((args->csi & 0xff) << 24 | - args->cns_specific_id); - req_hdr.cdw14 = cpu_to_le32(args->uuidx); - req_hdr.dlen = cpu_to_le32(size & 0xffffffff); - req_hdr.flags = 0x1; - if (offset) { - req_hdr.flags |= 0x2; - req_hdr.doff = cpu_to_le32(offset); - } - - nvme_mi_admin_init_resp(&resp, &resp_hdr); - resp.data = args->data; - resp.data_len = size; - - rc = nvme_mi_submit(link->ep, &req, &resp); - if (rc) - return rc; - - rc = nvme_mi_admin_parse_status(&resp, args->result); - if (rc) - return rc; - - /* callers will expect a full response; if the data buffer isn't - * fully valid, return an error */ - if (resp.data_len != size) - return -EPROTO; - - return 0; -} - int nvme_mi_control(nvme_mi_ep_t ep, __u8 opcode, __u16 cpsp, __u16 *result_cpsr) { diff --git a/src/nvme/mi.h b/src/nvme/mi.h index ae92e053b..958296573 100644 --- a/src/nvme/mi.h +++ b/src/nvme/mi.h @@ -1399,61 +1399,6 @@ int nvme_mi_admin_admin_passthru(nvme_link_t link, __u8 opcode, __u8 flags, __u32 data_len, void *data, __u32 metadata_len, void *metadata, __u32 timeout_ms, __u32 *result); -/** - * nvme_mi_admin_identify_partial() - Perform an Admin identify command, - * and retrieve partial response data. - * @link: Link to process identify command - * @args: Identify command arguments - * @offset: offset of identify data to retrieve from response - * @size: size of identify data to return - * - * Perform an Identify command, using the Identify command parameters in @args. - * The @offset and @size arguments allow the caller to retrieve part of - * the identify response. See NVMe-MI section 6.2 for the semantics (and some - * handy diagrams) of the offset & size parameters. - * - * Will return an error if the length of the response data (from the controller) - * did not match @size. - * - * Unless you're performing a vendor-unique identify command, You'll probably - * want to use one of the identify helpers (nvme_mi_admin_identify, - * nvme_mi_admin_identify_cns_nsid, or nvme_mi_admin_identify_) instead - * of this. If the type of your identify command is standardized but not - * yet supported by libnvme-mi, please contact the maintainers. - * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. - * - * See: &struct nvme_identify_args - */ -int nvme_mi_admin_identify_partial(nvme_link_t link, - struct nvme_identify_args *args, - off_t offset, size_t size); - -/** - * nvme_mi_admin_identify() - Perform an Admin identify command. - * @link: Link to process identify command - * @args: Identify command arguments - * - * Perform an Identify command, using the Identify command parameters in @args. - * Stores the identify data in ->data, and (if set) the result from cdw0 - * into args->result. - * - * Will return an error if the length of the response data (from the - * controller) is not a full &NVME_IDENTIFY_DATA_SIZE. - * - * Return: The nvme command status if a response was received (see - * &enum nvme_status_field) or -1 with errno set otherwise. - * - * See: &struct nvme_identify_args - */ -static inline int nvme_mi_admin_identify(nvme_link_t link, - struct nvme_identify_args *args) -{ - return nvme_mi_admin_identify_partial(link, args, - 0, NVME_IDENTIFY_DATA_SIZE); -} - /** * nvme_mi_control() - Perform a Control Primitive command * @ep: endpoint for MI communication From 40bf00904285c1c5bc0ed0346d526e07518d2890 Mon Sep 17 00:00:00 2001 From: Tokunori Ikegami Date: Mon, 11 Aug 2025 15:54:49 +0900 Subject: [PATCH 17/66] fabrics: fix nvme_get_adrfam function description parameter ctrl as c Since the warning message output by kernel-doc-check. Signed-off-by: Tokunori Ikegami --- src/nvme/fabrics.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nvme/fabrics.c b/src/nvme/fabrics.c index c310e019a..e19d1ad22 100644 --- a/src/nvme/fabrics.c +++ b/src/nvme/fabrics.c @@ -1693,7 +1693,7 @@ static int nvmf_dim(nvme_ctrl_t c, enum nvmf_dim_tas tas, __u8 trtype, * address from the socket, then we'll infer the address family from the * address of the DC since the DC address has the same address family. * - * @ctrl: Host NVMe controller instance maintaining the admin queue used to + * @c: Host NVMe controller instance maintaining the admin queue used to * submit the DIM command to the DC. * * Return: The address family of the source address associated with the From 9ce13d9c7e627483ba5089fb2391b4dbd6d23413 Mon Sep 17 00:00:00 2001 From: Daniel Wagner Date: Thu, 31 Jul 2025 14:54:26 +0200 Subject: [PATCH 18/66] ioctl: nvme_identify use nvme_passthru_cmd directly Signed-off-by: Daniel Wagner --- examples/mi-mctp.c | 18 +- src/libnvme.map | 2 - src/nvme/api-types.h | 26 --- src/nvme/ioctl.c | 31 ---- src/nvme/ioctl.h | 382 +++++++++++++++--------------------------- src/nvme/mi.c | 13 +- test/ioctl/identify.c | 4 +- 7 files changed, 147 insertions(+), 329 deletions(-) diff --git a/examples/mi-mctp.c b/examples/mi-mctp.c index 61a807977..1c4ab62a3 100644 --- a/examples/mi-mctp.c +++ b/examples/mi-mctp.c @@ -178,7 +178,6 @@ static const char *__copy_id_str(const void *field, size_t size, int do_identify(nvme_mi_ep_t ep, int argc, char **argv) { - struct nvme_identify_args id_args = { 0 }; struct nvme_link *link; struct nvme_id_ctrl id; uint16_t ctrl_id; @@ -207,23 +206,20 @@ int do_identify(nvme_mi_ep_t ep, int argc, char **argv) return -1; } - id_args.data = &id; - id_args.args_size = sizeof(id_args); - id_args.cns = NVME_IDENTIFY_CNS_CTRL; - id_args.nsid = NVME_NSID_NONE; - id_args.cntid = 0; - id_args.csi = NVME_CSI_NVM; - /* for this example code, we can either do a full or partial identify; * since we're only printing the fields before the 'rab' member, * these will be equivalent, aside from the size of the MI * response. */ if (partial) { - rc = nvme_identify_partial(link, offsetof(struct nvme_id_ctrl, rab), - &id_args); + rc = nvme_identify_partial(link, NVME_NSID_NONE, 0, NVME_IDENTIFY_CNS_CTRL, + NVME_CSI_NVM, 0, 0, &id, + offsetof(struct nvme_id_ctrl, rab), + NULL); } else { - rc = nvme_identify(link, &id_args); + rc = nvme_identify(link, 0, NVME_IDENTIFY_CNS_CTRL, + NVME_CSI_NVM, 0, 0, NVME_NSID_NONE, + &id, NULL); } if (rc) { diff --git a/src/libnvme.map b/src/libnvme.map index 157e72b29..9308c1b03 100644 --- a/src/libnvme.map +++ b/src/libnvme.map @@ -153,8 +153,6 @@ LIBNVME_2_0 { nvme_host_set_dhchap_key; nvme_host_set_hostsymname; nvme_host_set_pdc_enabled; - nvme_identify; - nvme_identify_partial; nvme_import_tls_key; nvme_import_tls_key_versioned; nvme_init_copy_range; diff --git a/src/nvme/api-types.h b/src/nvme/api-types.h index 638de13a9..cec51ec7e 100644 --- a/src/nvme/api-types.h +++ b/src/nvme/api-types.h @@ -49,32 +49,6 @@ void nvme_free_root(nvme_root_t r); * be set to zero. */ -/** - * struct nvme_identify_args - Arguments for the NVMe Identify command - * @result: The command completion result from CQE dword0 - * @data: User space destination address to transfer the data - * @args_size: Size of &struct nvme_identify_args - * @timeout: Timeout in ms (0 for default timeout) - * @cns: The Controller or Namespace structure, see @enum nvme_identify_cns - * @csi: Command Set Identifier - * @nsid: Namespace identifier, if applicable - * @cntid: The Controller Identifier, if applicable - * @cns_specific_id: Identifier that is required for a particular CNS value - * @uuidx: UUID Index if controller supports this id selection method - */ -struct nvme_identify_args { - __u32 *result; - void *data; - int args_size; - __u32 timeout; - enum nvme_identify_cns cns; - enum nvme_csi csi; - __u32 nsid; - __u16 cntid; - __u16 cns_specific_id; - __u8 uuidx; -}; - /** * struct nvme_get_log_args - Arguments for the NVMe Admin Get Log command * @lpo: Log page offset for partial log transfers diff --git a/src/nvme/ioctl.c b/src/nvme/ioctl.c index 38e9ae974..e57dc55fd 100644 --- a/src/nvme/ioctl.c +++ b/src/nvme/ioctl.c @@ -282,37 +282,6 @@ enum features { NVME_FEATURES_IOCSP_IOCSCI_MASK = 0xff, }; -int nvme_identify_partial(nvme_link_t l, __u32 xfer_len, - struct nvme_identify_args *args) -{ - __u32 cdw10 = NVME_SET(args->cntid, IDENTIFY_CDW10_CNTID) | - NVME_SET(args->cns, IDENTIFY_CDW10_CNS); - __u32 cdw11 = NVME_SET(args->cns_specific_id, IDENTIFY_CDW11_CNSSPECID) | - NVME_SET(args->csi, IDENTIFY_CDW11_CSI); - __u32 cdw14 = NVME_SET(args->uuidx, IDENTIFY_CDW14_UUID); - - struct nvme_passthru_cmd cmd = { - .opcode = nvme_admin_identify, - .nsid = args->nsid, - .addr = (__u64)(uintptr_t)args->data, - .data_len = xfer_len, - .cdw10 = cdw10, - .cdw11 = cdw11, - .cdw14 = cdw14, - .timeout_ms = args->timeout, - }; - - if (args->args_size < sizeof(*args)) - return -EINVAL; - - return nvme_submit_admin_passthru(l, &cmd, args->result); -} - -int nvme_identify(nvme_link_t l, struct nvme_identify_args *args) -{ - return nvme_identify_partial(l, NVME_IDENTIFY_DATA_SIZE, args); -} - int nvme_get_log(nvme_link_t l, struct nvme_get_log_args *args) { __u32 numd = (args->len >> 2) - 1; diff --git a/src/nvme/ioctl.h b/src/nvme/ioctl.h index 0867f4a08..42b840a81 100644 --- a/src/nvme/ioctl.h +++ b/src/nvme/ioctl.h @@ -577,10 +577,17 @@ int nvme_ns_rescan(nvme_link_t l); int nvme_get_nsid(nvme_link_t l, __u32 *nsid); /** - * nvme_identify_partial() - Send the NVMe Identify command + * nvme_identify_partial() - NVMe Identify command * @l: Link handle - * @xfer_len: Max log transfer size per request to split the total. - * @args: &struct nvme_identify_args argument structure + * @nsid: Namespace identifier, if applicable + * @cntid: The Controller Identifier, if applicable + * @cns: The Controller or Namespace structure, see @enum nvme_identify_cns + * @csi: Command Set Identifier + * @cnssid: Identifier that is required for a particular CNS value + * @uidx: UUID Index if controller supports this id selection method + * @data: User space destination address to transfer the data + * @len: size of identify data to return + * @result: The command completion result from CQE dword0 * * The Identify command returns a data buffer that describes information about * the NVM subsystem, the controller or the namespace(s). @@ -588,13 +595,42 @@ int nvme_get_nsid(nvme_link_t l, __u32 *nsid); * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_identify_partial(nvme_link_t l, __u32 xfer_len, - struct nvme_identify_args *args); +static inline int nvme_identify_partial(nvme_link_t l, __u32 nsid, __u16 cntid, + enum nvme_identify_cns cns, + enum nvme_csi csi, __u16 cnssid, + __u8 uidx, void *data, __u32 len, + __u32 *result) +{ + __u32 cdw10 = NVME_SET(cntid, IDENTIFY_CDW10_CNTID) | + NVME_SET(cns, IDENTIFY_CDW10_CNS); + __u32 cdw11 = NVME_SET(cnssid, IDENTIFY_CDW11_CNSSPECID) | + NVME_SET(csi, IDENTIFY_CDW11_CSI); + __u32 cdw14 = NVME_SET(uidx, IDENTIFY_CDW14_UUID); + + struct nvme_passthru_cmd cmd = { + .opcode = nvme_admin_identify, + .nsid = nsid, + .addr = (__u64)(uintptr_t)data, + .data_len = len, + .cdw10 = cdw10, + .cdw11 = cdw11, + .cdw14 = cdw14, + }; + + return nvme_submit_admin_passthru(l, &cmd, result); +} /** - * nvme_identify() - Send the NVMe Identify command + * nvme_identify() - NVMe Identify command * @l: Link handle - * @args: &struct nvme_identify_args argument structure + * @nsid: Namespace identifier, if applicable + * @cntid: The Controller Identifier, if applicable + * @cns: The Controller or Namespace structure, see @enum nvme_identify_cns + * @csi: Command Set Identifier + * @cnssid: Identifier that is required for a particular CNS value + * @uidx: UUID Index if controller supports this id selection method + * @data: User space destination address to transfer the data + * @result: The command completion result from CQE dword0 * * The Identify command returns a data buffer that describes information about * the NVM subsystem, the controller or the namespace(s). @@ -602,25 +638,21 @@ int nvme_identify_partial(nvme_link_t l, __u32 xfer_len, * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_identify(nvme_link_t l, struct nvme_identify_args *args); - -static inline int nvme_identify_cns_nsid(nvme_link_t l, enum nvme_identify_cns cns, - __u32 nsid, void *data) +static inline int nvme_identify(nvme_link_t l, __u32 nsid, __u16 cntid, + enum nvme_identify_cns cns, enum nvme_csi csi, + __u16 cnssid, __u8 uidx, + void *data, __u32 *result) { - struct nvme_identify_args args = { - .result = NULL, - .data = data, - .args_size = sizeof(args), - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .cns = cns, - .csi = NVME_CSI_NVM, - .nsid = nsid, - .cntid = NVME_CNTLID_NONE, - .cns_specific_id = NVME_CNSSPECID_NONE, - .uuidx = NVME_UUID_NONE, - }; + return nvme_identify_partial(l, nsid, cntid, cns, csi, cnssid, uidx, + data, NVME_IDENTIFY_DATA_SIZE, result); +} - return nvme_identify(l, &args); +static inline int nvme_identify_cns_nsid(nvme_link_t l, __u32 nsid, enum nvme_identify_cns cns, + void *data) +{ + return nvme_identify(l, nsid, NVME_CNTLID_NONE, cns, NVME_CSI_NVM, + NVME_CNSSPECID_NONE, NVME_UUID_NONE, + data, NULL); } /** @@ -637,8 +669,8 @@ static inline int nvme_identify_cns_nsid(nvme_link_t l, enum nvme_identify_cns c */ static inline int nvme_identify_ctrl(nvme_link_t l, struct nvme_id_ctrl *id) { - return nvme_identify_cns_nsid(l, NVME_IDENTIFY_CNS_CTRL, - NVME_NSID_NONE, id); + return nvme_identify_cns_nsid(l, NVME_NSID_NONE, NVME_IDENTIFY_CNS_CTRL, + id); } /** @@ -663,7 +695,7 @@ static inline int nvme_identify_ctrl(nvme_link_t l, struct nvme_id_ctrl *id) */ static inline int nvme_identify_ns(nvme_link_t l, __u32 nsid, struct nvme_id_ns *ns) { - return nvme_identify_cns_nsid(l, NVME_IDENTIFY_CNS_NS, nsid, ns); + return nvme_identify_cns_nsid(l, nsid, NVME_IDENTIFY_CNS_NS, ns); } /** @@ -679,8 +711,8 @@ static inline int nvme_identify_ns(nvme_link_t l, __u32 nsid, struct nvme_id_ns static inline int nvme_identify_allocated_ns(nvme_link_t l, __u32 nsid, struct nvme_id_ns *ns) { - return nvme_identify_cns_nsid(l, NVME_IDENTIFY_CNS_ALLOCATED_NS, - nsid, ns); + return nvme_identify_cns_nsid(l, nsid, + NVME_IDENTIFY_CNS_ALLOCATED_NS, ns); } /** @@ -701,8 +733,8 @@ static inline int nvme_identify_allocated_ns(nvme_link_t l, __u32 nsid, static inline int nvme_identify_active_ns_list(nvme_link_t l, __u32 nsid, struct nvme_ns_list *list) { - return nvme_identify_cns_nsid(l, NVME_IDENTIFY_CNS_NS_ACTIVE_LIST, - nsid, list); + return nvme_identify_cns_nsid(l, nsid, + NVME_IDENTIFY_CNS_NS_ACTIVE_LIST, list); } /** @@ -723,8 +755,8 @@ static inline int nvme_identify_active_ns_list(nvme_link_t l, __u32 nsid, static inline int nvme_identify_allocated_ns_list(nvme_link_t l, __u32 nsid, struct nvme_ns_list *list) { - return nvme_identify_cns_nsid(l, NVME_IDENTIFY_CNS_ALLOCATED_NS_LIST, - nsid, list); + return nvme_identify_cns_nsid(l, nsid, NVME_IDENTIFY_CNS_ALLOCATED_NS_LIST, + list); } /** @@ -745,20 +777,9 @@ static inline int nvme_identify_allocated_ns_list(nvme_link_t l, __u32 nsid, static inline int nvme_identify_ctrl_list(nvme_link_t l, __u16 cntid, struct nvme_ctrl_list *cntlist) { - struct nvme_identify_args args = { - .result = NULL, - .data = cntlist, - .args_size = sizeof(args), - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .cns = NVME_IDENTIFY_CNS_CTRL_LIST, - .csi = NVME_CSI_NVM, - .nsid = NVME_NSID_NONE, - .cntid = cntid, - .cns_specific_id = NVME_CNSSPECID_NONE, - .uuidx = NVME_UUID_NONE, - }; - - return nvme_identify(l, &args); + return nvme_identify(l, NVME_NSID_NONE, cntid, NVME_IDENTIFY_CNS_CTRL_LIST, + NVME_CSI_NVM, NVME_CNSSPECID_NONE, NVME_UUID_NONE, + cntlist, NULL); } /** @@ -780,20 +801,9 @@ static inline int nvme_identify_ctrl_list(nvme_link_t l, __u16 cntid, static inline int nvme_identify_nsid_ctrl_list(nvme_link_t l, __u32 nsid, __u16 cntid, struct nvme_ctrl_list *cntlist) { - struct nvme_identify_args args = { - .result = NULL, - .data = cntlist, - .args_size = sizeof(args), - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .cns = NVME_IDENTIFY_CNS_NS_CTRL_LIST, - .csi = NVME_CSI_NVM, - .nsid = nsid, - .cntid = cntid, - .cns_specific_id = NVME_CNSSPECID_NONE, - .uuidx = NVME_UUID_NONE, - }; - - return nvme_identify(l, &args); + return nvme_identify(l, nsid, cntid, NVME_IDENTIFY_CNS_NS_CTRL_LIST, + NVME_CSI_NVM, NVME_CNSSPECID_NONE, NVME_UUID_NONE, + cntlist, NULL); } /** @@ -816,8 +826,8 @@ static inline int nvme_identify_nsid_ctrl_list(nvme_link_t l, __u32 nsid, __u16 static inline int nvme_identify_ns_descs(nvme_link_t l, __u32 nsid, struct nvme_ns_id_desc *descs) { - return nvme_identify_cns_nsid(l, NVME_IDENTIFY_CNS_NS_DESC_LIST, - nsid, descs); + return nvme_identify_cns_nsid(l, nsid, NVME_IDENTIFY_CNS_NS_DESC_LIST, + descs); } /** @@ -839,20 +849,10 @@ static inline int nvme_identify_ns_descs(nvme_link_t l, __u32 nsid, static inline int nvme_identify_nvmset_list(nvme_link_t l, __u16 nvmsetid, struct nvme_id_nvmset_list *nvmset) { - struct nvme_identify_args args = { - .result = NULL, - .data = nvmset, - .args_size = sizeof(args), - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .cns = NVME_IDENTIFY_CNS_NVMSET_LIST, - .csi = NVME_CSI_NVM, - .nsid = NVME_NSID_NONE, - .cntid = NVME_CNTLID_NONE, - .cns_specific_id = nvmsetid, - .uuidx = NVME_UUID_NONE, - }; - - return nvme_identify(l, &args); + return nvme_identify(l, NVME_NSID_NONE, NVME_CNTLID_NONE, + NVME_IDENTIFY_CNS_NVMSET_LIST, + NVME_CSI_NVM, nvmsetid, NVME_UUID_NONE, + nvmset, NULL); } /** @@ -870,20 +870,9 @@ static inline int nvme_identify_nvmset_list(nvme_link_t l, __u16 nvmsetid, static inline int nvme_identify_primary_ctrl(nvme_link_t l, __u16 cntid, struct nvme_primary_ctrl_cap *cap) { - struct nvme_identify_args args = { - .result = NULL, - .data = cap, - .args_size = sizeof(args), - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .cns = NVME_IDENTIFY_CNS_PRIMARY_CTRL_CAP, - .csi = NVME_CSI_NVM, - .nsid = NVME_NSID_NONE, - .cntid = cntid, - .cns_specific_id = NVME_CNSSPECID_NONE, - .uuidx = NVME_UUID_NONE, - }; - - return nvme_identify(l, &args); + return nvme_identify(l, NVME_NSID_NONE, cntid, NVME_IDENTIFY_CNS_PRIMARY_CTRL_CAP, + NVME_CSI_NVM, NVME_CNSSPECID_NONE, NVME_UUID_NONE, + cap, NULL); } /** @@ -906,20 +895,10 @@ static inline int nvme_identify_primary_ctrl(nvme_link_t l, __u16 cntid, static inline int nvme_identify_secondary_ctrl_list(nvme_link_t l, __u16 cntid, struct nvme_secondary_ctrl_list *sc_list) { - struct nvme_identify_args args = { - .result = NULL, - .data = sc_list, - .args_size = sizeof(args), - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .cns = NVME_IDENTIFY_CNS_SECONDARY_CTRL_LIST, - .csi = NVME_CSI_NVM, - .nsid = NVME_NSID_NONE, - .cntid = cntid, - .cns_specific_id = NVME_CNSSPECID_NONE, - .uuidx = NVME_UUID_NONE, - }; - - return nvme_identify(l, &args); + return nvme_identify(l, NVME_NSID_NONE, cntid, + NVME_IDENTIFY_CNS_SECONDARY_CTRL_LIST, + NVME_CSI_NVM, NVME_CNSSPECID_NONE, NVME_UUID_NONE, + sc_list, NULL); } /** @@ -941,8 +920,8 @@ static inline int nvme_identify_secondary_ctrl_list(nvme_link_t l, static inline int nvme_identify_ns_granularity(nvme_link_t l, struct nvme_id_ns_granularity_list *gr_list) { - return nvme_identify_cns_nsid(l, NVME_IDENTIFY_CNS_NS_GRANULARITY, - NVME_NSID_NONE, gr_list); + return nvme_identify_cns_nsid(l, NVME_NSID_NONE, + NVME_IDENTIFY_CNS_NS_GRANULARITY, gr_list); } /** @@ -960,16 +939,16 @@ static inline int nvme_identify_ns_granularity(nvme_link_t l, */ static inline int nvme_identify_uuid(nvme_link_t l, struct nvme_id_uuid_list *uuid_list) { - return nvme_identify_cns_nsid(l, NVME_IDENTIFY_CNS_UUID_LIST, - NVME_NSID_NONE, uuid_list); + return nvme_identify_cns_nsid(l, NVME_NSID_NONE, + NVME_IDENTIFY_CNS_UUID_LIST, uuid_list); } /** * nvme_identify_ns_csi() - I/O command set specific identify namespace data * @l: Link handle * @nsid: Namespace to identify - * @uuidx: UUID Index for differentiating vendor specific encoding * @csi: Command Set Identifier + * @uidx: UUID Index for differentiating vendor specific encoding * @data: User space destination address to transfer the data * * An I/O Command Set specific Identify Namespace data structure is returned @@ -978,23 +957,12 @@ static inline int nvme_identify_uuid(nvme_link_t l, struct nvme_id_uuid_list *uu * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -static inline int nvme_identify_ns_csi(nvme_link_t l, __u32 nsid, __u8 uuidx, - enum nvme_csi csi, void *data) +static inline int nvme_identify_ns_csi(nvme_link_t l, __u32 nsid, + enum nvme_csi csi, __u8 uidx, void *data) { - struct nvme_identify_args args = { - .result = NULL, - .data = data, - .args_size = sizeof(args), - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .cns = NVME_IDENTIFY_CNS_CSI_NS, - .csi = csi, - .nsid = nsid, - .cntid = NVME_CNTLID_NONE, - .cns_specific_id = NVME_CNSSPECID_NONE, - .uuidx = uuidx, - }; - - return nvme_identify(l, &args); + return nvme_identify(l, nsid, NVME_CNTLID_NONE, NVME_IDENTIFY_CNS_CSI_NS, + csi, NVME_CNSSPECID_NONE, uidx, + data, NULL); } /** @@ -1012,20 +980,10 @@ static inline int nvme_identify_ns_csi(nvme_link_t l, __u32 nsid, __u8 uuidx, */ static inline int nvme_identify_ctrl_csi(nvme_link_t l, enum nvme_csi csi, void *data) { - struct nvme_identify_args args = { - .result = NULL, - .data = data, - .args_size = sizeof(args), - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .cns = NVME_IDENTIFY_CNS_CSI_CTRL, - .csi = csi, - .nsid = NVME_NSID_NONE, - .cntid = NVME_CNTLID_NONE, - .cns_specific_id = NVME_CNSSPECID_NONE, - .uuidx = NVME_UUID_NONE, - }; - - return nvme_identify(l, &args); + return nvme_identify(l, NVME_NSID_NONE, NVME_CNTLID_NONE, + NVME_IDENTIFY_CNS_CSI_CTRL, + csi, NVME_CNSSPECID_NONE, NVME_UUID_NONE, + data, NULL); } /** @@ -1048,20 +1006,10 @@ static inline int nvme_identify_ctrl_csi(nvme_link_t l, enum nvme_csi csi, void static inline int nvme_identify_active_ns_list_csi(nvme_link_t l, __u32 nsid, enum nvme_csi csi, struct nvme_ns_list *ns_list) { - struct nvme_identify_args args = { - .result = NULL, - .data = ns_list, - .args_size = sizeof(args), - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .cns = NVME_IDENTIFY_CNS_CSI_NS_ACTIVE_LIST, - .csi = csi, - .nsid = nsid, - .cntid = NVME_CNTLID_NONE, - .cns_specific_id = NVME_CNSSPECID_NONE, - .uuidx = NVME_UUID_NONE, - }; - - return nvme_identify(l, &args); + return nvme_identify(l, nsid, NVME_CNTLID_NONE, + NVME_IDENTIFY_CNS_CSI_NS_ACTIVE_LIST, + csi, NVME_CNSSPECID_NONE, NVME_UUID_NONE, + ns_list, NULL); } /** @@ -1084,20 +1032,10 @@ static inline int nvme_identify_active_ns_list_csi(nvme_link_t l, __u32 nsid, static inline int nvme_identify_allocated_ns_list_csi(nvme_link_t l, __u32 nsid, enum nvme_csi csi, struct nvme_ns_list *ns_list) { - struct nvme_identify_args args = { - .result = NULL, - .data = ns_list, - .args_size = sizeof(args), - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .cns = NVME_IDENTIFY_CNS_CSI_ALLOCATED_NS_LIST, - .csi = csi, - .nsid = nsid, - .cntid = NVME_CNTLID_NONE, - .cns_specific_id = NVME_CNSSPECID_NONE, - .uuidx = NVME_UUID_NONE, - }; - - return nvme_identify(l, &args); + return nvme_identify(l, nsid, NVME_CNTLID_NONE, + NVME_IDENTIFY_CNS_CSI_ALLOCATED_NS_LIST, + csi, NVME_CNSSPECID_NONE, NVME_UUID_NONE, + ns_list, NULL); } /** @@ -1116,15 +1054,15 @@ static inline int nvme_identify_allocated_ns_list_csi(nvme_link_t l, __u32 nsid, static inline int nvme_identify_independent_identify_ns(nvme_link_t l, __u32 nsid, struct nvme_id_independent_id_ns *ns) { - return nvme_identify_cns_nsid( - l, NVME_IDENTIFY_CNS_CSI_INDEPENDENT_ID_NS, nsid, ns); + return nvme_identify_cns_nsid(l, nsid, + NVME_IDENTIFY_CNS_CSI_INDEPENDENT_ID_NS, ns); } /** * nvme_identify_ns_csi_user_data_format() - Identify namespace user data format * @l: Link handle * @user_data_format: Return namespaces capability of identifier - * @uuidx: UUID selection, if supported + * @uidx: UUID selection, if supported * @csi: Command Set Identifier * @data: User space destination address to transfer the data * @@ -1135,31 +1073,21 @@ static inline int nvme_identify_independent_identify_ns(nvme_link_t l, __u32 nsi * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline int nvme_identify_ns_csi_user_data_format(nvme_link_t l, - __u16 user_data_format, __u8 uuidx, + __u16 user_data_format, __u8 uidx, enum nvme_csi csi, void *data) { - struct nvme_identify_args args = { - .result = NULL, - .data = data, - .args_size = sizeof(args), - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .cns = NVME_IDENTIFY_CNS_NS_USER_DATA_FORMAT, - .csi = csi, - .nsid = NVME_NSID_NONE, - .cntid = NVME_CNTLID_NONE, - .cns_specific_id = user_data_format, - .uuidx = uuidx, - }; - - return nvme_identify(l, &args); + return nvme_identify(l, NVME_NSID_NONE, NVME_CNTLID_NONE, + NVME_IDENTIFY_CNS_NS_USER_DATA_FORMAT, + csi, user_data_format, uidx, + data, NULL); } /** * nvme_identify_iocs_ns_csi_user_data_format() - Identify I/O command set namespace data structure * @l: Link handle - * @user_data_format: Return namespaces capability of identifier - * @uuidx: UUID selection, if supported * @csi: Command Set Identifier + * @user_data_format: Return namespaces capability of identifier + * @uidx: UUID selection, if supported * @data: User space destination address to transfer the data * * I/O Command Set specific Identify Namespace data structure for @@ -1170,23 +1098,13 @@ static inline int nvme_identify_ns_csi_user_data_format(nvme_link_t l, * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline int nvme_identify_iocs_ns_csi_user_data_format(nvme_link_t l, - __u16 user_data_format, __u8 uuidx, - enum nvme_csi csi, void *data) + enum nvme_csi csi, __u16 user_data_format, __u8 uidx, + void *data) { - struct nvme_identify_args args = { - .result = NULL, - .data = data, - .args_size = sizeof(args), - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .cns = NVME_IDENTIFY_CNS_CSI_NS_USER_DATA_FORMAT, - .csi = csi, - .nsid = NVME_NSID_NONE, - .cntid = NVME_CNTLID_NONE, - .cns_specific_id = user_data_format, - .uuidx = uuidx, - }; - - return nvme_identify(l, &args); + return nvme_identify(l, NVME_NSID_NONE, NVME_CNTLID_NONE, + NVME_IDENTIFY_CNS_CSI_NS_USER_DATA_FORMAT, + csi, user_data_format, uidx, + data, NULL); } /** @@ -1224,20 +1142,10 @@ static inline int nvme_nvm_identify_ctrl(nvme_link_t l, struct nvme_id_ctrl_nvm static inline int nvme_identify_domain_list(nvme_link_t l, __u16 domid, struct nvme_id_domain_list *list) { - struct nvme_identify_args args = { - .result = NULL, - .data = list, - .args_size = sizeof(args), - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .cns = NVME_IDENTIFY_CNS_DOMAIN_LIST, - .csi = NVME_CSI_NVM, - .nsid = NVME_NSID_NONE, - .cntid = NVME_CNTLID_NONE, - .cns_specific_id = domid, - .uuidx = NVME_UUID_NONE, - }; - - return nvme_identify(l, &args); + return nvme_identify(l, NVME_NSID_NONE, NVME_CNTLID_NONE, + NVME_IDENTIFY_CNS_DOMAIN_LIST, + NVME_CSI_NVM, domid, NVME_UUID_NONE, + list, NULL); } /** @@ -1252,20 +1160,10 @@ static inline int nvme_identify_domain_list(nvme_link_t l, __u16 domid, static inline int nvme_identify_endurance_group_list(nvme_link_t l, __u16 endgrp_id, struct nvme_id_endurance_group_list *list) { - struct nvme_identify_args args = { - .result = NULL, - .data = list, - .args_size = sizeof(args), - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .cns = NVME_IDENTIFY_CNS_ENDURANCE_GROUP_ID, - .csi = NVME_CSI_NVM, - .nsid = NVME_NSID_NONE, - .cntid = NVME_CNTLID_NONE, - .cns_specific_id = endgrp_id, - .uuidx = NVME_UUID_NONE, - }; - - return nvme_identify(l, &args); + return nvme_identify(l, NVME_NSID_NONE, NVME_CNTLID_NONE, + NVME_IDENTIFY_CNS_ENDURANCE_GROUP_ID, + NVME_CSI_NVM, endgrp_id, NVME_UUID_NONE, + list, NULL); } /** @@ -1283,20 +1181,10 @@ static inline int nvme_identify_endurance_group_list(nvme_link_t l, __u16 endgrp static inline int nvme_identify_iocs(nvme_link_t l, __u16 cntlid, struct nvme_id_iocs *iocs) { - struct nvme_identify_args args = { - .result = NULL, - .data = iocs, - .args_size = sizeof(args), - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .cns = NVME_IDENTIFY_CNS_COMMAND_SET_STRUCTURE, - .csi = NVME_CSI_NVM, - .nsid = NVME_NSID_NONE, - .cntid = cntlid, - .cns_specific_id = NVME_CNSSPECID_NONE, - .uuidx = NVME_UUID_NONE, - }; - - return nvme_identify(l, &args); + return nvme_identify(l, NVME_NSID_NONE, cntlid, + NVME_IDENTIFY_CNS_COMMAND_SET_STRUCTURE, + NVME_CSI_NVM, NVME_CNSSPECID_NONE, NVME_UUID_NONE, + iocs, NULL); } /** @@ -1312,7 +1200,7 @@ static inline int nvme_zns_identify_ns(nvme_link_t l, __u32 nsid, struct nvme_zns_id_ns *data) { return nvme_identify_ns_csi( - l, nsid, NVME_UUID_NONE, NVME_CSI_ZNS, data); + l, nsid, NVME_CSI_ZNS, NVME_UUID_NONE, data); } /** diff --git a/src/nvme/mi.c b/src/nvme/mi.c index b59f0e7ec..43511bf5e 100644 --- a/src/nvme/mi.c +++ b/src/nvme/mi.c @@ -211,7 +211,6 @@ static void __nvme_mi_format_mn(struct nvme_id_ctrl *id, void nvme_mi_ep_probe(struct nvme_mi_ep *ep) { - struct nvme_identify_args id_args = { 0 }; struct nvme_id_ctrl id = { 0 }; struct nvme_link *link; int rc; @@ -252,15 +251,9 @@ void nvme_mi_ep_probe(struct nvme_mi_ep *ep) * * all other fields - rab and onwards - will be zero! */ - id_args.args_size = sizeof(id_args); - id_args.data = &id; - id_args.cns = NVME_IDENTIFY_CNS_CTRL; - id_args.nsid = NVME_NSID_NONE; - id_args.cntid = 0; - id_args.csi = NVME_CSI_NVM; - - rc = nvme_identify_partial(link, offsetof(struct nvme_id_ctrl, rab), - &id_args); + rc = nvme_identify_partial(link, NVME_NSID_NONE, 0, NVME_IDENTIFY_CNS_CTRL, + NVME_CSI_NVM, 0, 0, &id, + offsetof(struct nvme_id_ctrl, rab), NULL); if (rc) { nvme_msg(ep->root, LOG_WARNING, "Identify Controller failed, no quirks applied\n"); diff --git a/test/ioctl/identify.c b/test/ioctl/identify.c index 1d93c7a33..5dafca074 100644 --- a/test/ioctl/identify.c +++ b/test/ioctl/identify.c @@ -141,7 +141,7 @@ static void test_ns_csi(void) arbitrary(expected_id, sizeof(expected_id)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_identify_ns_csi(test_link, TEST_NSID, TEST_UUID, TEST_CSI, id); + err = nvme_identify_ns_csi(test_link, TEST_NSID, TEST_CSI, TEST_UUID, id); end_mock_cmds(); check(err == 0, "identify returned error %d", err); cmp(id, expected_id, sizeof(id), "incorrect identify data"); @@ -574,7 +574,7 @@ static void test_identify_iocs_ns_csi_user_data_format(void) arbitrary(&expected_id, sizeof(expected_id)); set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_identify_iocs_ns_csi_user_data_format( - test_link, TEST_FIDX, TEST_UUID, TEST_CSI, &id); + test_link, TEST_CSI, TEST_FIDX, TEST_UUID, &id); end_mock_cmds(); check(err == 0, "identify returned error %d, errno %m", err); cmp(&id, &expected_id, sizeof(id), "incorrect identify data"); From 0810fef57957b65b284883a210e6ffdc5837ad53 Mon Sep 17 00:00:00 2001 From: Daniel Wagner Date: Wed, 30 Jul 2025 09:37:22 +0200 Subject: [PATCH 19/66] ioctl: reorder nvme_get_log and nvme_get_log_page The next change will add a static inline implementation of nvme_get_log which uses nvme_get_log_page. Thus move the nvme_get_log_page function up so it can be used directly. Signed-off-by: Daniel Wagner --- src/nvme/ioctl.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/nvme/ioctl.h b/src/nvme/ioctl.h index 42b840a81..f9d8812e2 100644 --- a/src/nvme/ioctl.h +++ b/src/nvme/ioctl.h @@ -1217,25 +1217,25 @@ static inline int nvme_zns_identify_ctrl(nvme_link_t l, struct nvme_zns_id_ctrl } /** - * nvme_get_log() - NVMe Admin Get Log command + * nvme_get_log_page() - Get log page data * @l: Link handle + * @xfer_len: Max log transfer size per request to split the total. * @args: &struct nvme_get_log_args argument structure * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_get_log(nvme_link_t l, struct nvme_get_log_args *args); +int nvme_get_log_page(nvme_link_t l, __u32 xfer_len, struct nvme_get_log_args *args); /** - * nvme_get_log_page() - Get log page data + * nvme_get_log() - NVMe Admin Get Log command * @l: Link handle - * @xfer_len: Max log transfer size per request to split the total. * @args: &struct nvme_get_log_args argument structure * - * Return: 0 on success, the nvme command status if a response was - * received (see &enum nvme_status_field) or a negative error otherwise. + * Return: The nvme command status if a response was received (see + * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_get_log_page(nvme_link_t l, __u32 xfer_len, struct nvme_get_log_args *args); +int nvme_get_log(nvme_link_t l, struct nvme_get_log_args *args); static inline int nvme_get_nsid_log(nvme_link_t l, bool rae, enum nvme_cmd_get_log_lid lid, From ca10a4d50fb13e10e08d90582b1cc68f880701dd Mon Sep 17 00:00:00 2001 From: Daniel Wagner Date: Tue, 29 Jul 2025 21:17:30 +0200 Subject: [PATCH 20/66] ioctl: nvme_get_log use nvme_passthru_cmd directly Refactor nvme_get_log and nvme_get_log_page to use use struct nvme_passthru_cmd directly and drop the struct nvme_get_log_args. The struct args have are ABI thus it's hard to change it after a release. The nvme_passthru_cmd buffer is a generic buffer and it's possible to use the setters directly on the buffer in an inline function. Besides a reduced API to maintain it also generates better code and avoids one call less when issue a command. [ikegami.t: update nvme_uring_cmd_amdin_passthru_async] Signed-off-by: Tokunori Ikegami Signed-off-by: Daniel Wagner --- examples/mi-mctp-csi-test.c | 20 +- examples/mi-mctp.c | 20 +- src/libnvme.map | 3 +- src/nvme/api-types.h | 37 -- src/nvme/fabrics.c | 37 +- src/nvme/ioctl.c | 127 ++--- src/nvme/ioctl.h | 924 +++++++++++++----------------------- src/nvme/linux.c | 49 +- test/ioctl/ana.c | 28 +- test/ioctl/logs.c | 58 +-- test/mi.c | 14 +- test/test.c | 4 +- 12 files changed, 476 insertions(+), 845 deletions(-) diff --git a/examples/mi-mctp-csi-test.c b/examples/mi-mctp-csi-test.c index b71d463ec..0f4bdf092 100644 --- a/examples/mi-mctp-csi-test.c +++ b/examples/mi-mctp-csi-test.c @@ -56,7 +56,7 @@ void hexdump(const unsigned char *buf, int len) int do_get_log_page(nvme_mi_ep_t ep, int argc, char **argv) { - struct nvme_get_log_args args = { 0 }; + enum nvme_cmd_get_log_lid lid; struct nvme_link *link; uint8_t buf[4096]; uint16_t ctrl_id; @@ -75,15 +75,11 @@ int do_get_log_page(nvme_mi_ep_t ep, int argc, char **argv) ctrl_id = tmp & 0xffff; - args.args_size = sizeof(args); - args.log = buf; - args.len = sizeof(buf); - if (argc > 2) { tmp = atoi(argv[2]); - args.lid = tmp & 0xff; + lid = tmp & 0xff; } else { - args.lid = 0x1; + lid = 0x1; } link = nvme_mi_init_link(ep, ctrl_id); @@ -92,14 +88,18 @@ int do_get_log_page(nvme_mi_ep_t ep, int argc, char **argv) return -1; } - rc = nvme_get_log(link, &args); + rc = nvme_get_log(link, NVME_NSID_NONE, false, NVME_LOG_LSP_NONE, + lid, NVME_LOG_LSI_NONE, NVME_CSI_NVM, + false, NVME_UUID_NONE, + 0, buf, sizeof(buf), + sizeof(buf), NULL); if (rc) { warn("can't perform Get Log page command"); return -1; } - printf("Get log page (log id = 0x%02x) data:\n", args.lid); - hexdump(buf, args.len); + printf("Get log page (log id = 0x%02x) data:\n", lid); + hexdump(buf, sizeof(buf)); return 0; } diff --git a/examples/mi-mctp.c b/examples/mi-mctp.c index 1c4ab62a3..80f55597d 100644 --- a/examples/mi-mctp.c +++ b/examples/mi-mctp.c @@ -369,7 +369,7 @@ void hexdump(const unsigned char *buf, int len) int do_get_log_page(nvme_mi_ep_t ep, int argc, char **argv) { - struct nvme_get_log_args args = { 0 }; + enum nvme_cmd_get_log_lid lid; struct nvme_link *link; uint8_t buf[512]; uint16_t ctrl_id; @@ -388,15 +388,11 @@ int do_get_log_page(nvme_mi_ep_t ep, int argc, char **argv) ctrl_id = tmp & 0xffff; - args.args_size = sizeof(args); - args.log = buf; - args.len = sizeof(buf); - if (argc > 2) { tmp = atoi(argv[2]); - args.lid = tmp & 0xff; + lid = tmp & 0xff; } else { - args.lid = 0x1; + lid = 0x1; } link = nvme_mi_init_link(ep, ctrl_id); @@ -405,14 +401,18 @@ int do_get_log_page(nvme_mi_ep_t ep, int argc, char **argv) return -1; } - rc = nvme_get_log(link, &args); + rc = nvme_get_log(link, NVME_NSID_NONE, false, NVME_LOG_LSP_NONE, + lid, NVME_LOG_LSI_NONE, NVME_CSI_NVM, + false, NVME_UUID_NONE, + 0, buf, sizeof(buf), + sizeof(buf),NULL); if (rc) { warn("can't perform Get Log page command"); return -1; } - printf("Get log page (log id = 0x%02x) data:\n", args.lid); - hexdump(buf, args.len); + printf("Get log page (log id = 0x%02x) data:\n", lid); + hexdump(buf, sizeof(buf)); return 0; } diff --git a/src/libnvme.map b/src/libnvme.map index 9308c1b03..00b116720 100644 --- a/src/libnvme.map +++ b/src/libnvme.map @@ -129,8 +129,7 @@ LIBNVME_2_0 { nvme_get_features_write_protect; nvme_get_host_telemetry; nvme_get_lba_status; - nvme_get_log; - nvme_get_log_page; + nvme_get_log_partial; nvme_get_logging_level; nvme_get_logical_block_size; nvme_get_new_host_telemetry; diff --git a/src/nvme/api-types.h b/src/nvme/api-types.h index cec51ec7e..d1f51bf39 100644 --- a/src/nvme/api-types.h +++ b/src/nvme/api-types.h @@ -49,43 +49,6 @@ void nvme_free_root(nvme_root_t r); * be set to zero. */ -/** - * struct nvme_get_log_args - Arguments for the NVMe Admin Get Log command - * @lpo: Log page offset for partial log transfers - * @result: The command completion result from CQE dword0 - * @log: User space destination address to transfer the data - * @args_size: Length of the structure - * @timeout: Timeout in ms - * @lid: Log page identifier, see &enum nvme_cmd_get_log_lid for known - * values - * @len: Length of provided user buffer to hold the log data in bytes - * @nsid: Namespace identifier, if applicable - * @csi: Command set identifier, see &enum nvme_csi for known values - * @lsi: Log Specific Identifier - * @lsp: Log specific field - * @uuidx: UUID selection, if supported - * @rae: Retain asynchronous events - * @ot: Offset Type; if set @lpo specifies the index into the list - * of data structures, otherwise @lpo specifies the byte offset - * into the log page. - */ -struct nvme_get_log_args { - __u64 lpo; - __u32 *result; - void *log; - int args_size; - __u32 timeout; - enum nvme_cmd_get_log_lid lid; - __u32 len; - __u32 nsid; - enum nvme_csi csi; - __u16 lsi; - __u8 lsp; - __u8 uuidx; - bool rae; - bool ot; -}; - /** * struct nvme_set_features_args - Arguments for the NVMe Admin Set Feature command * @result: The command completion result from CQE dword0 diff --git a/src/nvme/fabrics.c b/src/nvme/fabrics.c index e19d1ad22..e81601495 100644 --- a/src/nvme/fabrics.c +++ b/src/nvme/fabrics.c @@ -1118,17 +1118,6 @@ static int nvme_discovery_log(const struct nvme_get_discovery_args *args, const char *name = nvme_ctrl_get_name(args->c); uint64_t genctr, numrec; nvme_link_t l = nvme_ctrl_get_link(args->c); - struct nvme_get_log_args log_args = { - .result = args->result, - .args_size = sizeof(log_args), - .timeout = args->timeout, - .lid = NVME_LOG_LID_DISCOVER, - .nsid = NVME_NSID_NONE, - .csi = NVME_CSI_NVM, - .lsi = NVME_LOG_LSI_NONE, - .lsp = args->lsp, - .uuidx = NVME_UUID_NONE, - }; log = __nvme_alloc(sizeof(*log)); if (!log) { @@ -1139,9 +1128,11 @@ static int nvme_discovery_log(const struct nvme_get_discovery_args *args, nvme_msg(l->root, LOG_DEBUG, "%s: get header (try %d/%d)\n", name, retries, args->max_retries); - log_args.log = log; - log_args.len = DISCOVERY_HEADER_LEN; - err = nvme_get_log_page(l, NVME_LOG_PAGE_PDU_SIZE, &log_args); + err = nvme_get_log(l, NVME_NSID_NONE, false, args->lsp, + NVME_LOG_LID_DISCOVER, NVME_LOG_LSI_NONE, NVME_CSI_NVM, + false, NVME_UUID_NONE, + 0, log, DISCOVERY_HEADER_LEN, + NVME_LOG_PAGE_PDU_SIZE, NULL); if (err) { nvme_msg(l->root, LOG_INFO, "%s: discover try %d/%d failed, error %d\n", @@ -1171,10 +1162,11 @@ static int nvme_discovery_log(const struct nvme_get_discovery_args *args, "%s: get %" PRIu64 " records (genctr %" PRIu64 ")\n", name, numrec, genctr); - log_args.lpo = sizeof(*log); - log_args.log = log->entries; - log_args.len = entries_size; - err = nvme_get_log_page(l, NVME_LOG_PAGE_PDU_SIZE, &log_args); + err = nvme_get_log(l, NVME_NSID_NONE, false, args->lsp, + NVME_LOG_LID_DISCOVER, NVME_LOG_LSI_NONE, NVME_CSI_NVM, + false, NVME_UUID_NONE, + sizeof(*log), log->entries, entries_size, + NVME_LOG_PAGE_PDU_SIZE, NULL); if (err) { nvme_msg(l->root, LOG_INFO, "%s: discover try %d/%d failed, error %d\n", @@ -1188,10 +1180,11 @@ static int nvme_discovery_log(const struct nvme_get_discovery_args *args, */ nvme_msg(l->root, LOG_DEBUG, "%s: get header again\n", name); - log_args.lpo = 0; - log_args.log = log; - log_args.len = DISCOVERY_HEADER_LEN; - err = nvme_get_log_page(l, NVME_LOG_PAGE_PDU_SIZE, &log_args); + err = nvme_get_log(l, NVME_NSID_NONE, false, args->lsp, + NVME_LOG_LID_DISCOVER, NVME_LOG_LSI_NONE, NVME_CSI_NVM, + false, NVME_UUID_NONE, + 0, log, DISCOVERY_HEADER_LEN, + NVME_LOG_PAGE_PDU_SIZE, NULL); if (err) { nvme_msg(l->root, LOG_INFO, "%s: discover try %d/%d failed, error %d\n", diff --git a/src/nvme/ioctl.c b/src/nvme/ioctl.c index e57dc55fd..0c159e23b 100644 --- a/src/nvme/ioctl.c +++ b/src/nvme/ioctl.c @@ -282,42 +282,6 @@ enum features { NVME_FEATURES_IOCSP_IOCSCI_MASK = 0xff, }; -int nvme_get_log(nvme_link_t l, struct nvme_get_log_args *args) -{ - __u32 numd = (args->len >> 2) - 1; - __u16 numdu = numd >> 16, numdl = numd & 0xffff; - - __u32 cdw10 = NVME_SET(args->lid, LOG_CDW10_LID) | - NVME_SET(args->lsp, LOG_CDW10_LSP) | - NVME_SET(!!args->rae, LOG_CDW10_RAE) | - NVME_SET(numdl, LOG_CDW10_NUMDL); - __u32 cdw11 = NVME_SET(numdu, LOG_CDW11_NUMDU) | - NVME_SET(args->lsi, LOG_CDW11_LSI); - __u32 cdw12 = args->lpo & 0xffffffff; - __u32 cdw13 = args->lpo >> 32; - __u32 cdw14 = NVME_SET(args->uuidx, LOG_CDW14_UUID) | - NVME_SET(!!args->ot, LOG_CDW14_OT) | - NVME_SET(args->csi, LOG_CDW14_CSI); - - struct nvme_passthru_cmd cmd = { - .opcode = nvme_admin_get_log_page, - .nsid = args->nsid, - .addr = (__u64)(uintptr_t)args->log, - .data_len = args->len, - .cdw10 = cdw10, - .cdw11 = cdw11, - .cdw12 = cdw12, - .cdw13 = cdw13, - .cdw14 = cdw14, - .timeout_ms = args->timeout, - }; - - if (args->args_size < sizeof(struct nvme_get_log_args)) - return -EINVAL; - - return nvme_submit_admin_passthru(l, &cmd, args->result); -} - static bool force_4k; __attribute__((constructor)) @@ -372,50 +336,21 @@ static void nvme_uring_cmd_exit(struct io_uring *ring) } static int nvme_uring_cmd_admin_passthru_async(nvme_link_t l, struct io_uring *ring, - struct nvme_get_log_args *args) + struct nvme_passthru_cmd *cmd, __u32 *result) { struct io_uring_sqe *sqe; - struct nvme_uring_cmd *cmd; int ret; - __u32 numd = (args->len >> 2) - 1; - __u16 numdu = numd >> 16, numdl = numd & 0xffff; - - __u32 cdw10 = NVME_SET(args->lid, LOG_CDW10_LID) | - NVME_SET(args->lsp, LOG_CDW10_LSP) | - NVME_SET(!!args->rae, LOG_CDW10_RAE) | - NVME_SET(numdl, LOG_CDW10_NUMDL); - __u32 cdw11 = NVME_SET(numdu, LOG_CDW11_NUMDU) | - NVME_SET(args->lsi, LOG_CDW11_LSI); - __u32 cdw12 = args->lpo & 0xffffffff; - __u32 cdw13 = args->lpo >> 32; - __u32 cdw14 = NVME_SET(args->uuidx, LOG_CDW14_UUID) | - NVME_SET(!!args->ot, LOG_CDW14_OT) | - NVME_SET(args->csi, LOG_CDW14_CSI); - - if (args->args_size < sizeof(struct nvme_get_log_args)) - return -EINVAL; - sqe = io_uring_get_sqe(ring); if (!sqe) return -1; - cmd = (void *)&sqe->cmd; - cmd->opcode = nvme_admin_get_log_page, - cmd->nsid = args->nsid, - cmd->addr = (__u64)(uintptr_t)args->log, - cmd->data_len = args->len, - cmd->cdw10 = cdw10, - cmd->cdw11 = cdw11, - cmd->cdw12 = cdw12, - cmd->cdw13 = cdw13, - cmd->cdw14 = cdw14, - cmd->timeout_ms = args->timeout, + memcpy(&sqe->cmd, cmd, sizeof(*cmd)); sqe->fd = l->fd; sqe->opcode = IORING_OP_URING_CMD; sqe->cmd_op = NVME_URING_CMD_ADMIN; - sqe->user_data = (__u64)(uintptr_t)args; + sqe->user_data = (__u64)(uintptr_t)result; ret = io_uring_submit(ring); if (ret < 0) @@ -426,9 +361,9 @@ static int nvme_uring_cmd_admin_passthru_async(nvme_link_t l, struct io_uring *r static int nvme_uring_cmd_wait_complete(struct io_uring *ring, int n) { - struct nvme_get_log_args *args; struct io_uring_cqe *cqe; int i, ret = 0; + __u32 *result; for (i = 0; i < n; i++) { ret = io_uring_wait_cqe(ring, &cqe); @@ -436,9 +371,9 @@ static int nvme_uring_cmd_wait_complete(struct io_uring *ring, int n) return -1; if (cqe->res) { - args = (struct nvme_get_log_args *)cqe->user_data; - if (args->result) - *args->result = cqe->res; + result = (__u32 *)cqe->user_data; + if (result) + *result = cqe->res; ret = cqe->res; break; } @@ -450,13 +385,21 @@ static int nvme_uring_cmd_wait_complete(struct io_uring *ring, int n) } #endif -int nvme_get_log_page(nvme_link_t l, __u32 xfer_len, struct nvme_get_log_args *args) +int nvme_get_log_partial(nvme_link_t l, struct nvme_passthru_cmd *cmd, + __u64 lpo, void *log, __u32 len, + __u32 xfer_len, __u32 *result) { - __u64 offset = 0, xfer, data_len = args->len; - __u64 start = args->lpo; - bool retain = args->rae; - void *ptr = args->log; + __u64 offset = 0, xfer, data_len = len; + __u64 start = lpo; + void *ptr = log; int ret; + bool rae; + __u32 numd; + __u16 numdu, numdl; + bool retain = NVME_GET(cmd->cdw10, LOG_CDW10_RAE); + __u32 cdw10 = cmd->cdw10 & (NVME_VAL(LOG_CDW10_LID) | + NVME_VAL(LOG_CDW10_LSP)); + __u32 cdw11 = cmd->cdw11 & NVME_VAL(LOG_CDW11_LSI); if (force_4k) xfer_len = NVME_LOG_PAGE_PDU_SIZE; @@ -495,10 +438,21 @@ int nvme_get_log_page(nvme_link_t l, __u32 xfer_len, struct nvme_get_log_args *a * last portion of this log page so the data remains latched * during the fetch sequence. */ - args->lpo = start + offset; - args->len = xfer; - args->log = ptr; - args->rae = offset + xfer < data_len || retain; + lpo = start + offset; + numd = (xfer >> 2) - 1; + numdu = numd >> 16; + numdl = numd & 0xffff; + rae = offset + xfer < data_len || retain; + + cmd->cdw10 = cdw10 | + NVME_SET(!!rae, LOG_CDW10_RAE) | + NVME_SET(numdl, LOG_CDW10_NUMDL); + cmd->cdw11 = cdw11 | + NVME_SET(numdu, LOG_CDW11_NUMDU); + cmd->cdw12 = lpo & 0xffffffff; + cmd->cdw13 = lpo >> 32; + cmd->data_len = xfer; + cmd->addr = (__u64)(uintptr_t)ptr; #ifdef CONFIG_LIBURING if (io_uring_kernel_support == IO_URING_AVAILABLE && use_uring) { if (n >= NVME_URING_ENTRIES) { @@ -506,13 +460,13 @@ int nvme_get_log_page(nvme_link_t l, __u32 xfer_len, struct nvme_get_log_args *a n = 0; } n += 1; - ret = nvme_uring_cmd_admin_passthru_async(l, &ring, args); + ret = nvme_uring_cmd_admin_passthru_async(l, &ring, cmd, result); if (ret) nvme_uring_cmd_exit(&ring); } else #endif - ret = nvme_get_log(l, args); + ret = nvme_submit_admin_passthru(l, cmd, result); if (ret) return ret; @@ -541,7 +495,7 @@ static int read_ana_chunk(nvme_link_t l, enum nvme_log_ana_lsp lsp, bool rae, __u32 len = min_t(__u32, log_end - *read, NVME_LOG_PAGE_PDU_SIZE); int ret; - ret = nvme_get_log_ana(l, lsp, rae, *read - log, len, *read); + ret = nvme_get_log_ana(l, rae, lsp, *read - log, *read, len); if (ret) return ret; @@ -596,8 +550,9 @@ static int try_read_ana(nvme_link_t l, enum nvme_log_ana_lsp lsp, bool rae, return 0; } -int nvme_get_ana_log_atomic(nvme_link_t l, bool rgo, bool rae, unsigned int retries, - struct nvme_ana_log *log, __u32 *len) +int nvme_get_ana_log_atomic(nvme_link_t l, bool rae, bool rgo, + struct nvme_ana_log *log, __u32 *len, + unsigned int retries) { const enum nvme_log_ana_lsp lsp = rgo ? NVME_LOG_ANA_LSP_RGO_GROUPS_ONLY : 0; diff --git a/src/nvme/ioctl.h b/src/nvme/ioctl.h index f9d8812e2..fd8836e7b 100644 --- a/src/nvme/ioctl.h +++ b/src/nvme/ioctl.h @@ -1217,77 +1217,106 @@ static inline int nvme_zns_identify_ctrl(nvme_link_t l, struct nvme_zns_id_ctrl } /** - * nvme_get_log_page() - Get log page data + * nvme_get_log_partial() - Get log page data * @l: Link handle + * @cmd: Passthru command to use + * @lpo: Log page offset for partial log transfers + * @log: User space destination address to transfer the data + * @len: Length of provided user buffer to hold the log data in bytes * @xfer_len: Max log transfer size per request to split the total. - * @args: &struct nvme_get_log_args argument structure + * @result: The command completion result from CQE dword0 * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_get_log_page(nvme_link_t l, __u32 xfer_len, struct nvme_get_log_args *args); +int nvme_get_log_partial(nvme_link_t l, struct nvme_passthru_cmd *cmd, + __u64 lpo, void *log, __u32 len, __u32 xfer_len, + __u32 *result); /** * nvme_get_log() - NVMe Admin Get Log command * @l: Link handle - * @args: &struct nvme_get_log_args argument structure + * @nsid: Namespace identifier, if applicable + * @rae: Retain asynchronous events + * @lsp: Log specific field + * @lid: Log page identifier, see &enum nvme_cmd_get_log_lid for known + * values + * @lsi: Log Specific Identifier + * @csi: Command set identifier, see &enum nvme_csi for known values + * @ot: Offset Type; if set @lpo specifies the index into the list + * of data structures, otherwise @lpo specifies the byte offset + * into the log page. + * @uidx: UUID selection, if supported + * @lpo: Log page offset for partial log transfers + * @log: User space destination address to transfer the data + * @len: Length of provided user buffer to hold the log data in bytes + * @xfer_len: Max log transfer size per request to split the total. + * @result: The command completion result from CQE dword0 * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_get_log(nvme_link_t l, struct nvme_get_log_args *args); +static inline int nvme_get_log(nvme_link_t l, + __u32 nsid, bool rae, __u8 lsp, + enum nvme_cmd_get_log_lid lid, + __u16 lsi, enum nvme_csi csi, + bool ot, __u8 uidx, + __u64 lpo, void *log, __u32 len, + __u32 xfer_len, __u32 *result) +{ + __u32 numd = (len >> 2) - 1; + __u16 numdu = numd >> 16, numdl = numd & 0xffff; + + __u32 cdw10 = NVME_SET(lid, LOG_CDW10_LID) | + NVME_SET(lsp, LOG_CDW10_LSP) | + NVME_SET(!!rae, LOG_CDW10_RAE) | + NVME_SET(numdl, LOG_CDW10_NUMDL); + __u32 cdw11 = NVME_SET(numdu, LOG_CDW11_NUMDU) | + NVME_SET(lsi, LOG_CDW11_LSI); + __u32 cdw12 = lpo & 0xffffffff; + __u32 cdw13 = lpo >> 32; + __u32 cdw14 = NVME_SET(uidx, LOG_CDW14_UUID) | + NVME_SET(!!ot, LOG_CDW14_OT) | + NVME_SET(csi, LOG_CDW14_CSI); -static inline int nvme_get_nsid_log(nvme_link_t l, bool rae, - enum nvme_cmd_get_log_lid lid, - __u32 nsid, __u32 len, void *log) -{ - struct nvme_get_log_args args = { - .lpo = 0, - .result = NULL, - .log = log, - .args_size = sizeof(args), - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .lid = lid, - .len = len, - .nsid = nsid, - .csi = NVME_CSI_NVM, - .lsi = NVME_LOG_LSI_NONE, - .lsp = NVME_LOG_LSP_NONE, - .uuidx = NVME_UUID_NONE, - .rae = rae, - .ot = false, + struct nvme_passthru_cmd cmd = { + .opcode = nvme_admin_get_log_page, + .nsid = nsid, + .addr = (__u64)(uintptr_t)log, + .data_len = len, + .cdw10 = cdw10, + .cdw11 = cdw11, + .cdw12 = cdw12, + .cdw13 = cdw13, + .cdw14 = cdw14, }; - return nvme_get_log_page(l, NVME_LOG_PAGE_PDU_SIZE, &args); + return nvme_get_log_partial(l, &cmd, lpo, log, len, xfer_len, result); } -static inline int nvme_get_endgid_log(nvme_link_t l, bool rae, enum nvme_cmd_get_log_lid lid, __u16 endgid, - __u32 len, void *log) +static inline int nvme_get_nsid_log(nvme_link_t l, __u32 nsid, bool rae, + enum nvme_cmd_get_log_lid lid, + void *log, __u32 len) { - struct nvme_get_log_args args = { - .lpo = 0, - .result = NULL, - .log = log, - .args_size = sizeof(args), - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .lid = lid, - .len = len, - .nsid = NVME_NSID_NONE, - .csi = NVME_CSI_NVM, - .lsi = endgid, - .lsp = NVME_LOG_LSP_NONE, - .uuidx = NVME_LOG_LSP_NONE, - .rae = rae, - .ot = false, - }; + return nvme_get_log(l, nsid, rae, NVME_LOG_LSP_NONE, + lid, NVME_LOG_LSI_NONE, NVME_CSI_NVM, + false, NVME_UUID_NONE, + 0, log, len, NVME_LOG_PAGE_PDU_SIZE, NULL); +} - return nvme_get_log_page(l, NVME_LOG_PAGE_PDU_SIZE, &args); +static inline int nvme_get_endgid_log(nvme_link_t l, bool rae, enum nvme_cmd_get_log_lid lid, + __u16 endgid, void *log, __u32 len) +{ + return nvme_get_log(l, NVME_NSID_NONE, rae, NVME_LOG_LSP_NONE, + lid, endgid, NVME_CSI_NVM, + false, NVME_UUID_NONE, + 0, log, len, NVME_LOG_PAGE_PDU_SIZE, NULL); } static inline int nvme_get_log_simple(nvme_link_t l, enum nvme_cmd_get_log_lid lid, - __u32 len, void *log) + void *log, __u32 len) { - return nvme_get_nsid_log(l, false, lid, NVME_NSID_ALL, len, log); + return nvme_get_nsid_log(l, NVME_NSID_ALL, false, lid, log, len); } /** @@ -1302,15 +1331,16 @@ static inline int nvme_get_log_simple(nvme_link_t l, enum nvme_cmd_get_log_lid l static inline int nvme_get_log_supported_log_pages(nvme_link_t l, bool rae, struct nvme_supported_log_pages *log) { - return nvme_get_nsid_log(l, rae, NVME_LOG_LID_SUPPORTED_LOG_PAGES, - NVME_NSID_ALL, sizeof(*log), log); + return nvme_get_nsid_log(l, NVME_NSID_ALL, rae, + NVME_LOG_LID_SUPPORTED_LOG_PAGES, + log, sizeof(*log)); } /** * nvme_get_log_error() - Retrieve nvme error log * @l: Link handle - * @nr_entries: Number of error log entries allocated * @rae: Retain asynchronous events + * @nr_entries: Number of error log entries allocated * @err_log: Array of error logs of size 'entries' * * This log page describes extended error information for a command that @@ -1320,12 +1350,11 @@ static inline int nvme_get_log_supported_log_pages(nvme_link_t l, bool rae, * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -static inline int nvme_get_log_error(nvme_link_t l, unsigned int nr_entries, bool rae, +static inline int nvme_get_log_error(nvme_link_t l, bool rae, unsigned int nr_entries, struct nvme_error_log_page *err_log) { - return nvme_get_nsid_log(l, rae, NVME_LOG_LID_ERROR, - NVME_NSID_ALL, sizeof(*err_log) * nr_entries, - err_log); + return nvme_get_nsid_log(l, NVME_NSID_ALL, rae, NVME_LOG_LID_ERROR, + err_log, sizeof(*err_log) * nr_entries); } /** @@ -1348,8 +1377,8 @@ static inline int nvme_get_log_error(nvme_link_t l, unsigned int nr_entries, boo static inline int nvme_get_log_smart(nvme_link_t l, __u32 nsid, bool rae, struct nvme_smart_log *smart_log) { - return nvme_get_nsid_log(l, rae, NVME_LOG_LID_SMART, - nsid, sizeof(*smart_log), smart_log); + return nvme_get_nsid_log(l, nsid, rae, NVME_LOG_LID_SMART, + smart_log, sizeof(*smart_log)); } /** @@ -1368,8 +1397,8 @@ static inline int nvme_get_log_smart(nvme_link_t l, __u32 nsid, bool rae, static inline int nvme_get_log_fw_slot(nvme_link_t l, bool rae, struct nvme_firmware_slot *fw_log) { - return nvme_get_nsid_log(l, rae, NVME_LOG_LID_FW_SLOT, - NVME_NSID_ALL, sizeof(*fw_log), fw_log); + return nvme_get_nsid_log(l, NVME_NSID_ALL, rae, NVME_LOG_LID_FW_SLOT, + fw_log, sizeof(*fw_log)); } /** @@ -1388,8 +1417,8 @@ static inline int nvme_get_log_fw_slot(nvme_link_t l, bool rae, static inline int nvme_get_log_changed_ns_list(nvme_link_t l, bool rae, struct nvme_ns_list *ns_log) { - return nvme_get_nsid_log(l, rae, NVME_LOG_LID_CHANGED_NS, - NVME_NSID_ALL, sizeof(*ns_log), ns_log); + return nvme_get_nsid_log(l, NVME_NSID_ALL, rae, NVME_LOG_LID_CHANGED_NS, + ns_log, sizeof(*ns_log)); } /** @@ -1407,23 +1436,11 @@ static inline int nvme_get_log_changed_ns_list(nvme_link_t l, bool rae, static inline int nvme_get_log_cmd_effects(nvme_link_t l, enum nvme_csi csi, struct nvme_cmd_effects_log *effects_log) { - struct nvme_get_log_args args = { - .lpo = 0, - .result = NULL, - .log = effects_log, - .args_size = sizeof(args), - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .lid = NVME_LOG_LID_CMD_EFFECTS, - .len = sizeof(*effects_log), - .nsid = NVME_NSID_ALL, - .csi = csi, - .lsi = NVME_LOG_LSI_NONE, - .lsp = NVME_LOG_LSP_NONE, - .uuidx = NVME_UUID_NONE, - .rae = false, - .ot = false, - }; - return nvme_get_log_page(l, NVME_LOG_PAGE_PDU_SIZE, &args); + return nvme_get_log(l, NVME_NSID_ALL, false, NVME_LOG_LSP_NONE, + NVME_LOG_LID_CMD_EFFECTS, NVME_LOG_LSI_NONE, csi, + false, NVME_UUID_NONE, + 0, effects_log, sizeof(*effects_log), + NVME_LOG_PAGE_PDU_SIZE, NULL); } /** @@ -1441,8 +1458,9 @@ static inline int nvme_get_log_cmd_effects(nvme_link_t l, enum nvme_csi csi, static inline int nvme_get_log_device_self_test(nvme_link_t l, struct nvme_self_test_log *log) { - return nvme_get_nsid_log(l, false, NVME_LOG_LID_DEVICE_SELF_TEST, - NVME_NSID_ALL, sizeof(*log), log); + return nvme_get_nsid_log(l, NVME_NSID_ALL, false, + NVME_LOG_LID_DEVICE_SELF_TEST, + log, sizeof(*log)); } /** @@ -1458,23 +1476,12 @@ static inline int nvme_get_log_create_telemetry_host_mcda(nvme_link_t l, enum nvme_telemetry_da mcda, struct nvme_telemetry_log *log) { - struct nvme_get_log_args args = { - .lpo = 0, - .result = NULL, - .log = log, - .args_size = sizeof(args), - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .lid = NVME_LOG_LID_TELEMETRY_HOST, - .len = sizeof(*log), - .nsid = NVME_NSID_NONE, - .csi = NVME_CSI_NVM, - .lsi = NVME_LOG_LSI_NONE, - .lsp = (__u8)((mcda << 1) | NVME_LOG_TELEM_HOST_LSP_CREATE), - .uuidx = NVME_UUID_NONE, - .rae = false, - .ot = false, - }; - return nvme_get_log_page(l, NVME_LOG_PAGE_PDU_SIZE, &args); + return nvme_get_log(l, NVME_NSID_NONE, false, + (__u8)((mcda << 1) | NVME_LOG_TELEM_HOST_LSP_CREATE), + NVME_LOG_LID_TELEMETRY_HOST, NVME_LOG_LSI_NONE, + NVME_CSI_NVM, false, NVME_UUID_NONE, + 0, log, sizeof(*log), + NVME_LOG_PAGE_PDU_SIZE, NULL); } /** @@ -1488,15 +1495,16 @@ static inline int nvme_get_log_create_telemetry_host_mcda(nvme_link_t l, static inline int nvme_get_log_create_telemetry_host(nvme_link_t l, struct nvme_telemetry_log *log) { - return nvme_get_log_create_telemetry_host_mcda(l, NVME_TELEMETRY_DA_CTRL_DETERMINE, log); + return nvme_get_log_create_telemetry_host_mcda(l, + NVME_TELEMETRY_DA_CTRL_DETERMINE, log); } /** * nvme_get_log_telemetry_host() - Get Telemetry Host-Initiated log page * @l: Link handle - * @offset: Offset into the telemetry data - * @len: Length of provided user buffer to hold the log data in bytes + * @lpo: Offset into the telemetry data * @log: User address for log page data + * @len: Length of provided user buffer to hold the log data in bytes * * Retrieves the Telemetry Host-Initiated log page at the requested offset * using the previously existing capture. @@ -1504,35 +1512,23 @@ static inline int nvme_get_log_create_telemetry_host(nvme_link_t l, * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -static inline int nvme_get_log_telemetry_host(nvme_link_t l, __u64 offset, - __u32 len, void *log) +static inline int nvme_get_log_telemetry_host(nvme_link_t l, __u64 lpo, + void *log, __u32 len) { - struct nvme_get_log_args args = { - .lpo = offset, - .result = NULL, - .log = log, - .args_size = sizeof(args), - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .lid = NVME_LOG_LID_TELEMETRY_HOST, - .len = len, - .nsid = NVME_NSID_NONE, - .csi = NVME_CSI_NVM, - .lsi = NVME_LOG_LSI_NONE, - .lsp = NVME_LOG_TELEM_HOST_LSP_RETAIN, - .uuidx = NVME_UUID_NONE, - .rae = false, - .ot = false, - }; - return nvme_get_log_page(l, NVME_LOG_PAGE_PDU_SIZE, &args); + return nvme_get_log(l, NVME_NSID_NONE, false, + NVME_LOG_TELEM_HOST_LSP_RETAIN, NVME_LOG_LID_TELEMETRY_HOST, + NVME_LOG_LSI_NONE, NVME_CSI_NVM, + false, NVME_UUID_NONE, + lpo, log, len, NVME_LOG_PAGE_PDU_SIZE, NULL); } /** * nvme_get_log_telemetry_ctrl() - Get Telemetry Controller-Initiated log page * @l: Link handle * @rae: Retain asynchronous events - * @offset: Offset into the telemetry data - * @len: Length of provided user buffer to hold the log data in bytes + * @lpo: Offset into the telemetry data * @log: User address for log page data + * @len: Length of provided user buffer to hold the log data in bytes * * Retrieves the Telemetry Controller-Initiated log page at the requested offset * using the previously existing capture. @@ -1541,25 +1537,12 @@ static inline int nvme_get_log_telemetry_host(nvme_link_t l, __u64 offset, * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline int nvme_get_log_telemetry_ctrl(nvme_link_t l, bool rae, - __u64 offset, __u32 len, void *log) + __u64 lpo, void *log, __u32 len) { - struct nvme_get_log_args args = { - .lpo = offset, - .result = NULL, - .log = log, - .args_size = sizeof(args), - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .lid = NVME_LOG_LID_TELEMETRY_CTRL, - .len = len, - .nsid = NVME_NSID_NONE, - .csi = NVME_CSI_NVM, - .lsi = NVME_LOG_LSI_NONE, - .lsp = NVME_LOG_LSP_NONE, - .uuidx = NVME_UUID_NONE, - .rae = rae, - .ot = false, - }; - return nvme_get_log_page(l, NVME_LOG_PAGE_PDU_SIZE, &args); + return nvme_get_log(l, NVME_NSID_NONE, rae, NVME_LOG_LSP_NONE, + NVME_LOG_LID_TELEMETRY_CTRL, NVME_LOG_LSI_NONE, + NVME_CSI_NVM, false, NVME_UUID_NONE, + lpo, log, len, NVME_LOG_PAGE_PDU_SIZE, NULL); } /** @@ -1581,23 +1564,11 @@ static inline int nvme_get_log_telemetry_ctrl(nvme_link_t l, bool rae, static inline int nvme_get_log_endurance_group(nvme_link_t l, __u16 endgid, struct nvme_endurance_group_log *log) { - struct nvme_get_log_args args = { - .lpo = 0, - .result = NULL, - .log = log, - .args_size = sizeof(args), - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .lid = NVME_LOG_LID_ENDURANCE_GROUP, - .len = sizeof(*log), - .nsid = NVME_NSID_NONE, - .csi = NVME_CSI_NVM, - .lsi = endgid, - .lsp = NVME_LOG_LSP_NONE, - .uuidx = NVME_UUID_NONE, - .rae = false, - .ot = false, - }; - return nvme_get_log_page(l, NVME_LOG_PAGE_PDU_SIZE, &args); + return nvme_get_log(l, NVME_NSID_NONE, false, NVME_LOG_LSP_NONE, + NVME_LOG_LID_ENDURANCE_GROUP, endgid, NVME_CSI_NVM, + false, NVME_UUID_NONE, + 0, log, sizeof(*log), + NVME_LOG_PAGE_PDU_SIZE, NULL); } /** @@ -1612,142 +1583,86 @@ static inline int nvme_get_log_endurance_group(nvme_link_t l, __u16 endgid, static inline int nvme_get_log_predictable_lat_nvmset(nvme_link_t l, __u16 nvmsetid, struct nvme_nvmset_predictable_lat_log *log) { - struct nvme_get_log_args args = { - .lpo = 0, - .result = NULL, - .log = log, - .args_size = sizeof(args), - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .lid = NVME_LOG_LID_PREDICTABLE_LAT_NVMSET, - .len = sizeof(*log), - .nsid = NVME_NSID_NONE, - .csi = NVME_CSI_NVM, - .lsi = nvmsetid, - .lsp = NVME_LOG_LSP_NONE, - .uuidx = NVME_UUID_NONE, - .rae = false, - .ot = false, - }; - return nvme_get_log_page(l, NVME_LOG_PAGE_PDU_SIZE, &args); + return nvme_get_log(l, NVME_NSID_NONE, false, NVME_LOG_LSP_NONE, + NVME_LOG_LID_PREDICTABLE_LAT_NVMSET, nvmsetid, NVME_CSI_NVM, + false, NVME_UUID_NONE, + 0, log, sizeof(*log), + NVME_LOG_PAGE_PDU_SIZE, NULL); } /** * nvme_get_log_predictable_lat_event() - Retrieve Predictable Latency Event Aggregate Log Page * @l: Link handle * @rae: Retain asynchronous events - * @offset: Offset into the predictable latency event - * @len: Length of provided user buffer to hold the log data in bytes + * @lpo: Offset into the predictable latency event * @log: User address for log page data + * @len: Length of provided user buffer to hold the log data in bytes * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline int nvme_get_log_predictable_lat_event(nvme_link_t l, bool rae, - __u32 offset, __u32 len, void *log) + __u64 lpo, void *log, __u32 len) { - struct nvme_get_log_args args = { - .lpo = offset, - .result = NULL, - .log = log, - .args_size = sizeof(args), - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .lid = NVME_LOG_LID_PREDICTABLE_LAT_AGG, - .len = len, - .nsid = NVME_NSID_NONE, - .csi = NVME_CSI_NVM, - .lsi = NVME_LOG_LSI_NONE, - .lsp = NVME_LOG_LSP_NONE, - .uuidx = NVME_UUID_NONE, - .rae = rae, - .ot = false, - }; - return nvme_get_log_page(l, NVME_LOG_PAGE_PDU_SIZE, &args); + return nvme_get_log(l, NVME_NSID_NONE, rae, NVME_LOG_LSP_NONE, + NVME_LOG_LID_PREDICTABLE_LAT_AGG, NVME_LOG_LSI_NONE, NVME_CSI_NVM, + false, NVME_UUID_NONE, + lpo, log, len, + NVME_LOG_PAGE_PDU_SIZE, NULL); } /** * nvme_get_log_fdp_configurations() - Get list of Flexible Data Placement configurations * @l: Link handle * @egid: Endurance group identifier - * @offset: Offset into log page + * @lpo: Offset into log page * @len: Length (in bytes) of provided user buffer to hold the log data * @log: Log page data buffer */ static inline int nvme_get_log_fdp_configurations(nvme_link_t l, __u16 egid, - __u32 offset, __u32 len, void *log) + __u64 lpo, __u32 len, void *log) { - struct nvme_get_log_args args = { - .lpo = offset, - .result = NULL, - .log = log, - .args_size = sizeof(args), - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .lid = NVME_LOG_LID_FDP_CONFIGS, - .len = len, - .nsid = NVME_NSID_NONE, - .csi = NVME_CSI_NVM, - .lsi = egid, - .lsp = NVME_LOG_LSP_NONE, - .uuidx = NVME_UUID_NONE, - }; - - return nvme_get_log(l, &args); + return nvme_get_log(l, NVME_NSID_NONE, false, NVME_LOG_LSP_NONE, + NVME_LOG_LID_FDP_CONFIGS, egid, NVME_CSI_NVM, + false, NVME_UUID_NONE, + lpo, log, len, + NVME_LOG_PAGE_PDU_SIZE, NULL); } /** * nvme_get_log_reclaim_unit_handle_usage() - Get reclaim unit handle usage * @l: Link handle * @egid: Endurance group identifier - * @offset: Offset into log page - * @len: Length (in bytes) of provided user buffer to hold the log data + * @lpo: Offset into log page * @log: Log page data buffer + * @len: Length (in bytes) of provided user buffer to hold the log data */ static inline int nvme_get_log_reclaim_unit_handle_usage(nvme_link_t l, __u16 egid, - __u32 offset, __u32 len, void *log) + __u64 lpo, void *log, __u32 len) { - struct nvme_get_log_args args = { - .lpo = offset, - .result = NULL, - .log = log, - .args_size = sizeof(args), - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .lid = NVME_LOG_LID_FDP_RUH_USAGE, - .len = len, - .nsid = NVME_NSID_NONE, - .csi = NVME_CSI_NVM, - .lsi = egid, - .lsp = NVME_LOG_LSP_NONE, - .uuidx = NVME_UUID_NONE, - }; - - return nvme_get_log(l, &args); + return nvme_get_log(l, NVME_NSID_NONE, false, NVME_LOG_LSP_NONE, + NVME_LOG_LID_FDP_RUH_USAGE, egid, NVME_CSI_NVM, + false, NVME_UUID_NONE, + lpo, log, len, + NVME_LOG_PAGE_PDU_SIZE, NULL); } /** * nvme_get_log_fdp_stats() - Get Flexible Data Placement statistics * @l: Link handle * @egid: Endurance group identifier - * @offset: Offset into log page - * @len: Length (in bytes) of provided user buffer to hold the log data + * @lpo: Offset into log page * @log: Log page data buffer + * @len: Length (in bytes) of provided user buffer to hold the log data */ -static inline int nvme_get_log_fdp_stats(nvme_link_t l, __u16 egid, __u32 offset, __u32 len, void *log) +static inline int nvme_get_log_fdp_stats(nvme_link_t l, __u16 egid, + __u64 lpo, void *log, __u32 len) { - struct nvme_get_log_args args = { - .lpo = offset, - .result = NULL, - .log = log, - .args_size = sizeof(args), - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .lid = NVME_LOG_LID_FDP_STATS, - .len = len, - .nsid = NVME_NSID_NONE, - .csi = NVME_CSI_NVM, - .lsi = egid, - .lsp = NVME_LOG_LSP_NONE, - .uuidx = NVME_UUID_NONE, - }; - - return nvme_get_log(l, &args); + return nvme_get_log(l, NVME_NSID_NONE, false, NVME_LOG_LSP_NONE, + NVME_LOG_LID_FDP_STATS, egid, NVME_CSI_NVM, + false, NVME_UUID_NONE, + lpo, log, len, + NVME_LOG_PAGE_PDU_SIZE, NULL); } /** @@ -1755,39 +1670,28 @@ static inline int nvme_get_log_fdp_stats(nvme_link_t l, __u16 egid, __u32 offset * @l: Link handle * @egid: Endurance group identifier * @host_events: Whether to report host or controller events - * @offset: Offset into log page - * @len: Length (in bytes) of provided user buffer to hold the log data + * @lpo: Offset into log page * @log: Log page data buffer + * @len: Length (in bytes) of provided user buffer to hold the log data */ -static inline int nvme_get_log_fdp_events(nvme_link_t l, __u16 egid, bool host_events, __u32 offset, - __u32 len, void *log) +static inline int nvme_get_log_fdp_events(nvme_link_t l, __u16 egid, + bool host_events, __u64 lpo, void *log, __u32 len) { - struct nvme_get_log_args args = { - .lpo = offset, - .result = NULL, - .log = log, - .args_size = sizeof(args), - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .lid = NVME_LOG_LID_FDP_EVENTS, - .len = len, - .nsid = NVME_NSID_NONE, - .csi = NVME_CSI_NVM, - .lsi = egid, - .lsp = (__u8)(host_events ? 0x1 : 0x0), - .uuidx = NVME_UUID_NONE, - }; - - return nvme_get_log(l, &args); + return nvme_get_log(l, NVME_NSID_NONE, false, (__u8)(host_events ? 0x1 : 0x0), + NVME_LOG_LID_FDP_EVENTS, egid, NVME_CSI_NVM, + false, NVME_UUID_NONE, + lpo, log, len, + NVME_LOG_PAGE_PDU_SIZE, NULL); } /** * nvme_get_log_ana() - Retrieve Asymmetric Namespace Access log page * @l: Link handle - * @lsp: Log specific, see &enum nvme_get_log_ana_lsp * @rae: Retain asynchronous events - * @offset: Offset to the start of the log page - * @len: The allocated length of the log page + * @lsp: Log specific, see &enum nvme_get_log_ana_lsp + * @lpo: Offset to the start of the log page * @log: User address to store the ana log + * @len: The allocated length of the log page * * This log consists of a header describing the log and descriptors containing * the asymmetric namespace access information for ANA Groups that contain @@ -1798,56 +1702,44 @@ static inline int nvme_get_log_fdp_events(nvme_link_t l, __u16 egid, bool host_e * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -static inline int nvme_get_log_ana(nvme_link_t l, enum nvme_log_ana_lsp lsp, bool rae, - __u64 offset, __u32 len, void *log) +static inline int nvme_get_log_ana(nvme_link_t l, bool rae, enum nvme_log_ana_lsp lsp, + __u64 lpo, void *log, __u32 len) { - struct nvme_get_log_args args = { - .lpo = offset, - .result = NULL, - .log = log, - .args_size = sizeof(args), - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .lid = NVME_LOG_LID_ANA, - .len = len, - .nsid = NVME_NSID_NONE, - .csi = NVME_CSI_NVM, - .lsi = NVME_LOG_LSI_NONE, - .lsp = (__u8)lsp, - .uuidx = NVME_UUID_NONE, - .rae = rae, - .ot = false, - }; - return nvme_get_log_page(l, NVME_LOG_PAGE_PDU_SIZE, &args); + return nvme_get_log(l, NVME_NSID_NONE, rae, (__u8)lsp, + NVME_LOG_LID_ANA, NVME_LOG_LSI_NONE, NVME_CSI_NVM, + false, NVME_UUID_NONE, + lpo, log, len, + NVME_LOG_PAGE_PDU_SIZE, NULL); } /** * nvme_get_log_ana_groups() - Retrieve Asymmetric Namespace Access groups only log page * @l: Link handle * @rae: Retain asynchronous events - * @len: The allocated length of the log page * @log: User address to store the ana group log + * @len: The allocated length of the log page * * See &struct nvme_ana_log for the definition of the returned structure. * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -static inline int nvme_get_log_ana_groups(nvme_link_t l, bool rae, __u32 len, - struct nvme_ana_log *log) +static inline int nvme_get_log_ana_groups(nvme_link_t l, bool rae, + struct nvme_ana_log *log, __u32 len) { - return nvme_get_log_ana(l, NVME_LOG_ANA_LSP_RGO_GROUPS_ONLY, rae, 0, - len, log); + return nvme_get_log_ana(l, rae, NVME_LOG_ANA_LSP_RGO_GROUPS_ONLY, + 0, log, len); } /** * nvme_get_ana_log_atomic() - Retrieve Asymmetric Namespace Access log page atomically * @l: Link handle - * @rgo: Whether to retrieve ANA groups only (no NSIDs) * @rae: Whether to retain asynchronous events - * @retries: The maximum number of times to retry on log page changes + * @rgo: Whether to retrieve ANA groups only (no NSIDs) * @log: Pointer to a buffer to receive the ANA log page * @len: Input: the length of the log page buffer. * Output: the actual length of the ANA log page. + * @retries: The maximum number of times to retry on log page changes * * See &struct nvme_ana_log for the definition of the returned structure. * @@ -1859,73 +1751,50 @@ static inline int nvme_get_log_ana_groups(nvme_link_t l, bool rae, __u32 len, * because chgcnt changed during each of the retries attempts. * Sets errno = ENOSPC if the full log page does not fit in the provided buffer. */ -int nvme_get_ana_log_atomic(nvme_link_t l, bool rgo, bool rae, unsigned int retries, - struct nvme_ana_log *log, __u32 *len); +int nvme_get_ana_log_atomic(nvme_link_t l, bool rae, bool rgo, + struct nvme_ana_log *log, __u32 *len, + unsigned int retries); /** * nvme_get_log_lba_status() - Retrieve LBA Status * @l: Link handle * @rae: Retain asynchronous events - * @offset: Offset to the start of the log page - * @len: The allocated length of the log page + * @lpo: Offset to the start of the log page * @log: User address to store the log page + * @len: The allocated length of the log page * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline int nvme_get_log_lba_status(nvme_link_t l, bool rae, - __u64 offset, __u32 len, void *log) + __u64 lpo, void *log, __u32 len) { - struct nvme_get_log_args args = { - .lpo = offset, - .result = NULL, - .log = log, - .args_size = sizeof(args), - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .lid = NVME_LOG_LID_LBA_STATUS, - .len = len, - .nsid = NVME_NSID_NONE, - .csi = NVME_CSI_NVM, - .lsi = NVME_LOG_LSI_NONE, - .lsp = NVME_LOG_LSP_NONE, - .uuidx = NVME_UUID_NONE, - .rae = rae, - .ot = false, - }; - return nvme_get_log_page(l, NVME_LOG_PAGE_PDU_SIZE, &args); + return nvme_get_log(l, NVME_NSID_NONE, rae, NVME_LOG_LSP_NONE, + NVME_LOG_LID_LBA_STATUS, NVME_LOG_LSI_NONE, NVME_CSI_NVM, + false, NVME_UUID_NONE, + lpo, log, len, + NVME_LOG_PAGE_PDU_SIZE, NULL); } /** * nvme_get_log_endurance_grp_evt() - Retrieve Endurance Group Event Aggregate * @l: Link handle * @rae: Retain asynchronous events - * @offset: Offset to the start of the log page - * @len: The allocated length of the log page + * @lpo: Offset to the start of the log page * @log: User address to store the log page + * @len: The allocated length of the log page * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline int nvme_get_log_endurance_grp_evt(nvme_link_t l, bool rae, - __u32 offset, __u32 len, void *log) + __u64 lpo, void *log, __u32 len) { - struct nvme_get_log_args args = { - .lpo = offset, - .result = NULL, - .log = log, - .args_size = sizeof(args), - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .lid = NVME_LOG_LID_ENDURANCE_GRP_EVT, - .len = len, - .nsid = NVME_NSID_NONE, - .csi = NVME_CSI_NVM, - .lsi = NVME_LOG_LSI_NONE, - .lsp = NVME_LOG_LSP_NONE, - .uuidx = NVME_UUID_NONE, - .rae = rae, - .ot = false, - }; - return nvme_get_log_page(l, NVME_LOG_PAGE_PDU_SIZE, &args); + return nvme_get_log(l, NVME_NSID_NONE, rae, NVME_LOG_LSP_NONE, + NVME_LOG_LID_ENDURANCE_GRP_EVT, NVME_LOG_LSI_NONE, NVME_CSI_NVM, + false, NVME_UUID_NONE, + lpo, log, len, + NVME_LOG_PAGE_PDU_SIZE, NULL); } /** @@ -1940,15 +1809,16 @@ static inline int nvme_get_log_endurance_grp_evt(nvme_link_t l, bool rae, static inline int nvme_get_log_fid_supported_effects(nvme_link_t l, bool rae, struct nvme_fid_supported_effects_log *log) { - return nvme_get_nsid_log(l, rae, NVME_LOG_LID_FID_SUPPORTED_EFFECTS, - NVME_NSID_NONE, sizeof(*log), log); + return nvme_get_nsid_log(l, NVME_NSID_NONE, rae, + NVME_LOG_LID_FID_SUPPORTED_EFFECTS, + log, sizeof(*log)); } /** * nvme_get_log_mi_cmd_supported_effects() - displays the MI Commands Supported by the controller * @l: Link handle - * @rae: Retain asynchronous events - * @log: MI Command Supported and Effects data structure + * @rae: Retain asynchronous events + * @log: MI Command Supported and Effects data structure * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise @@ -1956,8 +1826,9 @@ static inline int nvme_get_log_fid_supported_effects(nvme_link_t l, bool rae, static inline int nvme_get_log_mi_cmd_supported_effects(nvme_link_t l, bool rae, struct nvme_mi_cmd_supported_effects_log *log) { - return nvme_get_nsid_log(l, rae, NVME_LOG_LID_MI_CMD_SUPPORTED_EFFECTS, - NVME_NSID_NONE, sizeof(*log), log); + return nvme_get_nsid_log(l, NVME_NSID_NONE, rae, + NVME_LOG_LID_MI_CMD_SUPPORTED_EFFECTS, + log, sizeof(*log)); } /** @@ -1965,49 +1836,40 @@ static inline int nvme_get_log_mi_cmd_supported_effects(nvme_link_t l, bool rae, * @l: Link handle * @rae: Retain asynchronous events * @lsp: The log specified field of LID + * @part: User address to store the log page * @len: The allocated size, minimum * struct nvme_boot_partition - * @part: User address to store the log page * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise */ static inline int nvme_get_log_boot_partition(nvme_link_t l, bool rae, - __u8 lsp, __u32 len, struct nvme_boot_partition *part) + __u8 lsp, struct nvme_boot_partition *part, __u32 len) { - struct nvme_get_log_args args = { - .lpo = 0, - .result = NULL, - .log = part, - .args_size = sizeof(args), - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .lid = NVME_LOG_LID_BOOT_PARTITION, - .len = len, - .nsid = NVME_NSID_NONE, - .csi = NVME_CSI_NVM, - .lsi = NVME_LOG_LSI_NONE, - .lsp = lsp, - .uuidx = NVME_UUID_NONE, - .rae = rae, - .ot = false, - }; - return nvme_get_log_page(l, NVME_LOG_PAGE_PDU_SIZE, &args); + return nvme_get_log(l, NVME_NSID_NONE, rae, lsp, + NVME_LOG_LID_BOOT_PARTITION, NVME_LOG_LSI_NONE, NVME_CSI_NVM, + false, NVME_UUID_NONE, + 0, part, len, + NVME_LOG_PAGE_PDU_SIZE, NULL); } /** * nvme_get_log_rotational_media_info() - Retrieve Rotational Media Information Log * @l: Link handle * @endgid: Endurance Group Identifier - * @len: The allocated length of the log page * @log: User address to store the log page + * @len: The allocated length of the log page * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise */ -static inline int nvme_get_log_rotational_media_info(nvme_link_t l, __u16 endgid, __u32 len, - struct nvme_rotational_media_info_log *log) +static inline int nvme_get_log_rotational_media_info(nvme_link_t l, __u16 endgid, + struct nvme_rotational_media_info_log *log, + __u32 len) { - return nvme_get_endgid_log(l, false, NVME_LOG_LID_ROTATIONAL_MEDIA_INFO, endgid, len, log); + return nvme_get_endgid_log(l, false, + NVME_LOG_LID_ROTATIONAL_MEDIA_INFO, + endgid, log, len); } /** @@ -2015,32 +1877,34 @@ static inline int nvme_get_log_rotational_media_info(nvme_link_t l, __u16 endgid * Subsystems Log * @l: Link handle * @nsid: Namespace Identifier - * @len: The allocated length of the log page * @log: User address to store the log page + * @len: The allocated length of the log page * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise */ -static inline int nvme_get_log_dispersed_ns_participating_nss(nvme_link_t l, __u32 nsid, __u32 len, - struct nvme_dispersed_ns_participating_nss_log *log) +static inline int nvme_get_log_dispersed_ns_participating_nss(nvme_link_t l, __u32 nsid, + struct nvme_dispersed_ns_participating_nss_log *log, + __u32 len) { - return nvme_get_nsid_log(l, false, NVME_LOG_LID_DISPERSED_NS_PARTICIPATING_NSS, nsid, len, - log); + return nvme_get_nsid_log(l, nsid, false, + NVME_LOG_LID_DISPERSED_NS_PARTICIPATING_NSS, + log, len); } /** * nvme_get_log_mgmt_addr_list() - Retrieve Management Address List Log * @l: Link handle - * @len: The allocated length of the log page * @log: User address to store the log page + * @len: The allocated length of the log page * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise */ -static inline int nvme_get_log_mgmt_addr_list(nvme_link_t l, __u32 len, - struct nvme_mgmt_addr_list_log *log) +static inline int nvme_get_log_mgmt_addr_list(nvme_link_t l, + struct nvme_mgmt_addr_list_log *log, __u32 len) { - return nvme_get_log_simple(l, NVME_LOG_LID_MGMT_ADDR_LIST, len, log); + return nvme_get_log_simple(l, NVME_LOG_LID_MGMT_ADDR_LIST, log, len); } /** @@ -2048,127 +1912,90 @@ static inline int nvme_get_log_mgmt_addr_list(nvme_link_t l, __u32 len, * @l: Link handle * @lsp: Log specific, controls action and measurement quality * @controller: Target controller ID + * @log: User address to store the log page * @len: The allocated size, minimum * struct nvme_phy_rx_eom_log - * @log: User address to store the log page * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise */ -static inline int nvme_get_log_phy_rx_eom(nvme_link_t l, __u8 lsp, __u16 controller, - __u32 len, struct nvme_phy_rx_eom_log *log) +static inline int nvme_get_log_phy_rx_eom(nvme_link_t l, __u8 lsp, + __u16 controller, struct nvme_phy_rx_eom_log *log, + __u32 len) { - struct nvme_get_log_args args = { - .lpo = 0, - .result = NULL, - .log = log, - .args_size = sizeof(args), - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .lid = NVME_LOG_LID_PHY_RX_EOM, - .len = len, - .nsid = NVME_NSID_NONE, - .csi = NVME_CSI_NVM, - .lsi = controller, - .lsp = lsp, - .uuidx = NVME_UUID_NONE, - .rae = false, - .ot = false, - }; - return nvme_get_log_page(l, NVME_LOG_PAGE_PDU_SIZE, &args); + return nvme_get_log(l, NVME_NSID_NONE, false, lsp, + NVME_LOG_LID_PHY_RX_EOM, controller, NVME_CSI_NVM, + false, NVME_UUID_NONE, + 0, log, len, + NVME_LOG_PAGE_PDU_SIZE, NULL); } /** * nvme_get_log_reachability_groups() - Retrieve Reachability Groups Log * @l: Link handle - * @rgo: Return groups only * @rae: Retain asynchronous events - * @len: The allocated length of the log page + * @rgo: Return groups only * @log: User address to store the log page + * @len: The allocated length of the log page * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise */ -static inline int nvme_get_log_reachability_groups(nvme_link_t l, bool rgo, bool rae, __u32 len, - struct nvme_reachability_groups_log *log) +static inline int nvme_get_log_reachability_groups(nvme_link_t l, bool rae, bool rgo, + struct nvme_reachability_groups_log *log, __u32 len) { - struct nvme_get_log_args args = { - .lpo = 0, - .result = NULL, - .log = log, - .args_size = sizeof(args), - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .lid = NVME_LOG_LID_REACHABILITY_GROUPS, - .len = len, - .nsid = NVME_NSID_ALL, - .csi = NVME_CSI_NVM, - .lsi = NVME_LOG_LSI_NONE, - .lsp = rgo, - .uuidx = NVME_LOG_LSP_NONE, - .rae = rae, - .ot = false, - }; - - return nvme_get_log_page(l, NVME_LOG_PAGE_PDU_SIZE, &args); + return nvme_get_log(l, NVME_NSID_ALL, rae, (__u8)rgo, + NVME_LOG_LID_REACHABILITY_GROUPS, NVME_LOG_LSI_NONE, NVME_CSI_NVM, + false, NVME_UUID_NONE, + 0, log, len, + NVME_LOG_PAGE_PDU_SIZE, NULL); } /** * nvme_get_log_reachability_associations() - Retrieve Reachability Associations Log * @l: Link handle - * @rao: Return associations only * @rae: Retain asynchronous events - * @len: The allocated length of the log page + * @rao: Return associations only * @log: User address to store the log page + * @len: The allocated length of the log page * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise */ -static inline int nvme_get_log_reachability_associations(nvme_link_t l, bool rao, bool rae, __u32 len, - struct nvme_reachability_associations_log *log) +static inline int nvme_get_log_reachability_associations(nvme_link_t l, bool rae, bool rao, + struct nvme_reachability_associations_log *log, __u32 len) { - struct nvme_get_log_args args = { - .lpo = 0, - .result = NULL, - .log = log, - .args_size = sizeof(args), - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .lid = NVME_LOG_LID_REACHABILITY_ASSOCIATIONS, - .len = len, - .nsid = NVME_NSID_ALL, - .csi = NVME_CSI_NVM, - .lsi = NVME_LOG_LSI_NONE, - .lsp = rao, - .uuidx = NVME_LOG_LSP_NONE, - .rae = rae, - .ot = false, - }; - - return nvme_get_log_page(l, NVME_LOG_PAGE_PDU_SIZE, &args); + return nvme_get_log(l, NVME_NSID_ALL, rae, (__u8)rao, + NVME_LOG_LID_REACHABILITY_ASSOCIATIONS, NVME_LOG_LSI_NONE, NVME_CSI_NVM, + false, NVME_UUID_NONE, + 0, log, len, + NVME_LOG_PAGE_PDU_SIZE, NULL); } /** * nvme_get_log_changed_alloc_ns_list() - Retrieve Changed Allocated Namespace List Log * @l: Link handle * @rae: Retain asynchronous events - * @len: The allocated length of the log page * @log: User address to store the log page + * @len: The allocated length of the log page * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise */ -static inline int nvme_get_log_changed_alloc_ns_list(nvme_link_t l, bool rae, __u32 len, - struct nvme_ns_list *log) +static inline int nvme_get_log_changed_alloc_ns_list(nvme_link_t l, bool rae, + struct nvme_ns_list *log, __u32 len) { - return nvme_get_nsid_log(l, rae, NVME_LOG_LID_CHANGED_ALLOC_NS_LIST, NVME_NSID_ALL, len, - log); + return nvme_get_nsid_log(l, NVME_NSID_ALL, rae, + NVME_LOG_LID_CHANGED_ALLOC_NS_LIST, log, len); } /** * nvme_get_log_discovery() - Retrieve Discovery log page * @l: Link handle * @rae: Retain asynchronous events - * @offset: Offset of this log to retrieve - * @len: The allocated size for this portion of the log + * @lpo: Offset of this log to retrieve * @log: User address to store the discovery log + * @len: The allocated size for this portion of the log * * Supported only by fabrics discovery controllers, returning discovery * records. @@ -2177,91 +2004,68 @@ static inline int nvme_get_log_changed_alloc_ns_list(nvme_link_t l, bool rae, __ * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline int nvme_get_log_discovery(nvme_link_t l, bool rae, - __u32 offset, __u32 len, void *log) + __u64 lpo, __u32 len, void *log) { - struct nvme_get_log_args args = { - .lpo = offset, - .result = NULL, - .log = log, - .args_size = sizeof(args), - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .lid = NVME_LOG_LID_DISCOVER, - .len = len, - .nsid = NVME_NSID_NONE, - .csi = NVME_CSI_NVM, - .lsi = NVME_LOG_LSI_NONE, - .lsp = NVME_LOG_LSP_NONE, - .uuidx = NVME_UUID_NONE, - .rae = rae, - .ot = false, - }; - return nvme_get_log_page(l, NVME_LOG_PAGE_PDU_SIZE, &args); + return nvme_get_log(l, NVME_NSID_NONE, rae, NVME_LOG_LSP_NONE, + NVME_LOG_LID_DISCOVER, NVME_LOG_LSI_NONE, NVME_CSI_NVM, + false, NVME_UUID_NONE, + lpo, log, len, + NVME_LOG_PAGE_PDU_SIZE, NULL); } /** * nvme_get_log_host_discover() - Retrieve Host Discovery Log * @l: Link handle - * @allhoste: All host entries * @rae: Retain asynchronous events - * @len: The allocated length of the log page + * @allhoste: All host entries * @log: User address to store the log page + * @len: The allocated length of the log page * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise */ -static inline int nvme_get_log_host_discover(nvme_link_t l, bool allhoste, bool rae, __u32 len, - struct nvme_host_discover_log *log) +static inline int nvme_get_log_host_discover(nvme_link_t l, bool rae, bool allhoste, + struct nvme_host_discover_log *log, __u32 len) { - struct nvme_get_log_args args = { - .lpo = 0, - .result = NULL, - .log = log, - .args_size = sizeof(args), - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .lid = NVME_LOG_LID_HOST_DISCOVER, - .len = len, - .nsid = NVME_NSID_ALL, - .csi = NVME_CSI_NVM, - .lsi = NVME_LOG_LSI_NONE, - .lsp = allhoste, - .uuidx = NVME_LOG_LSP_NONE, - .rae = rae, - .ot = false, - }; - - return nvme_get_log_page(l, NVME_LOG_PAGE_PDU_SIZE, &args); + return nvme_get_log(l, NVME_NSID_ALL, rae, (__u8)allhoste, + NVME_LOG_LID_HOST_DISCOVER, NVME_LOG_LSI_NONE, NVME_CSI_NVM, + false, NVME_UUID_NONE, + 0, log, len, + NVME_LOG_PAGE_PDU_SIZE, NULL); } /** * nvme_get_log_ave_discover() - Retrieve AVE Discovery Log * @l: Link handle * @rae: Retain asynchronous events - * @len: The allocated length of the log page * @log: User address to store the log page + * @len: The allocated length of the log page * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise */ -static inline int nvme_get_log_ave_discover(nvme_link_t l, bool rae, __u32 len, - struct nvme_ave_discover_log *log) +static inline int nvme_get_log_ave_discover(nvme_link_t l, bool rae, + struct nvme_ave_discover_log *log, __u32 len) { - return nvme_get_nsid_log(l, rae, NVME_LOG_LID_AVE_DISCOVER, NVME_NSID_ALL, len, log); + return nvme_get_nsid_log(l, NVME_NSID_ALL, rae, + NVME_LOG_LID_AVE_DISCOVER, log, len); } /** * nvme_get_log_pull_model_ddc_req() - Retrieve Pull Model DDC Request Log * @l: Link handle * @rae: Retain asynchronous events - * @len: The allocated length of the log page * @log: User address to store the log page + * @len: The allocated length of the log page * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise */ -static inline int nvme_get_log_pull_model_ddc_req(nvme_link_t l, bool rae, __u32 len, - struct nvme_pull_model_ddc_req_log *log) +static inline int nvme_get_log_pull_model_ddc_req(nvme_link_t l, bool rae, + struct nvme_pull_model_ddc_req_log *log, __u32 len) { - return nvme_get_nsid_log(l, rae, NVME_LOG_LID_PULL_MODEL_DDC_REQ, NVME_NSID_ALL, len, log); + return nvme_get_nsid_log(l, NVME_NSID_ALL, rae, + NVME_LOG_LID_PULL_MODEL_DDC_REQ, log, len); } /** @@ -2276,23 +2080,11 @@ static inline int nvme_get_log_pull_model_ddc_req(nvme_link_t l, bool rae, __u32 static inline int nvme_get_log_media_unit_stat(nvme_link_t l, __u16 domid, struct nvme_media_unit_stat_log *mus) { - struct nvme_get_log_args args = { - .lpo = 0, - .result = NULL, - .log = mus, - .args_size = sizeof(args), - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .lid = NVME_LOG_LID_MEDIA_UNIT_STATUS, - .len = sizeof(*mus), - .nsid = NVME_NSID_NONE, - .csi = NVME_CSI_NVM, - .lsi = domid, - .lsp = NVME_LOG_LSP_NONE, - .uuidx = NVME_UUID_NONE, - .rae = false, - .ot = false, - }; - return nvme_get_log_page(l, NVME_LOG_PAGE_PDU_SIZE, &args); + return nvme_get_log(l, NVME_NSID_NONE, false, NVME_LOG_LSP_NONE, + NVME_LOG_LID_MEDIA_UNIT_STATUS, domid, NVME_CSI_NVM, + false, NVME_UUID_NONE, + 0, mus, sizeof(*mus), + NVME_LOG_PAGE_PDU_SIZE, NULL); } /** @@ -2307,23 +2099,11 @@ static inline int nvme_get_log_media_unit_stat(nvme_link_t l, __u16 domid, static inline int nvme_get_log_support_cap_config_list(nvme_link_t l, __u16 domid, struct nvme_supported_cap_config_list_log *cap) { - struct nvme_get_log_args args = { - .lpo = 0, - .result = NULL, - .log = cap, - .args_size = sizeof(args), - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .lid = NVME_LOG_LID_SUPPORTED_CAP_CONFIG_LIST, - .len = sizeof(*cap), - .nsid = NVME_NSID_NONE, - .csi = NVME_CSI_NVM, - .lsi = domid, - .lsp = NVME_LOG_LSP_NONE, - .uuidx = NVME_UUID_NONE, - .rae = false, - .ot = false, - }; - return nvme_get_log_page(l, NVME_LOG_PAGE_PDU_SIZE, &args); + return nvme_get_log(l, NVME_NSID_NONE, false, NVME_LOG_LSP_NONE, + NVME_LOG_LID_SUPPORTED_CAP_CONFIG_LIST, domid, NVME_CSI_NVM, + false, NVME_UUID_NONE, + 0, cap, sizeof(*cap), + NVME_LOG_PAGE_PDU_SIZE, NULL); } /** @@ -2338,8 +2118,9 @@ static inline int nvme_get_log_support_cap_config_list(nvme_link_t l, __u16 domi static inline int nvme_get_log_reservation(nvme_link_t l, bool rae, struct nvme_resv_notification_log *log) { - return nvme_get_nsid_log(l, rae, NVME_LOG_LID_RESERVATION, - NVME_NSID_ALL, sizeof(*log), log); + return nvme_get_nsid_log(l, NVME_NSID_ALL, rae, + NVME_LOG_LID_RESERVATION, + log, sizeof(*log)); } /** @@ -2357,8 +2138,9 @@ static inline int nvme_get_log_reservation(nvme_link_t l, bool rae, static inline int nvme_get_log_sanitize(nvme_link_t l, bool rae, struct nvme_sanitize_log_page *log) { - return nvme_get_nsid_log(l, rae, NVME_LOG_LID_SANITIZE, - NVME_NSID_ALL, sizeof(*log), log); + return nvme_get_nsid_log(l, NVME_NSID_ALL, rae, + NVME_LOG_LID_SANITIZE, + log, sizeof(*log)); } /** @@ -2373,64 +2155,40 @@ static inline int nvme_get_log_sanitize(nvme_link_t l, bool rae, * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -static inline int nvme_get_log_zns_changed_zones(nvme_link_t l, __u32 nsid, bool rae, - struct nvme_zns_changed_zone_log *log) +static inline int nvme_get_log_zns_changed_zones(nvme_link_t l, __u32 nsid, + bool rae, struct nvme_zns_changed_zone_log *log) { - struct nvme_get_log_args args = { - .lpo = 0, - .result = NULL, - .log = log, - .args_size = sizeof(args), - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .lid = NVME_LOG_LID_ZNS_CHANGED_ZONES, - .len = sizeof(*log), - .nsid = nsid, - .csi = NVME_CSI_ZNS, - .lsi = NVME_LOG_LSI_NONE, - .lsp = NVME_LOG_LSP_NONE, - .uuidx = NVME_UUID_NONE, - .rae = rae, - .ot = false, - }; - return nvme_get_log_page(l, NVME_LOG_PAGE_PDU_SIZE, &args); + return nvme_get_log(l, nsid, rae, NVME_LOG_LSP_NONE, + NVME_LOG_LID_ZNS_CHANGED_ZONES, NVME_LOG_LSI_NONE, NVME_CSI_ZNS, + false, NVME_UUID_NONE, + 0, log, sizeof(*log), + NVME_LOG_PAGE_PDU_SIZE, NULL); } /** * nvme_get_log_persistent_event() - Retrieve Persistent Event Log * @l: Link handle * @action: Action the controller should take during processing this command - * @size: Size of @pevent_log * @pevent_log: User address to store the persistent event log + * @len: Size of @pevent_log * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline int nvme_get_log_persistent_event(nvme_link_t l, enum nvme_pevent_log_action action, - __u32 size, void *pevent_log) + void *pevent_log, __u32 len) { - struct nvme_get_log_args args = { - .lpo = 0, - .result = NULL, - .log = pevent_log, - .args_size = sizeof(args), - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .lid = NVME_LOG_LID_PERSISTENT_EVENT, - .len = size, - .nsid = NVME_NSID_ALL, - .csi = NVME_CSI_NVM, - .lsi = NVME_LOG_LSI_NONE, - .lsp = (__u8)action, - .uuidx = NVME_UUID_NONE, - .rae = false, - .ot = false, - }; - return nvme_get_log_page(l, NVME_LOG_PAGE_PDU_SIZE, &args); + return nvme_get_log(l, NVME_NSID_ALL, false, (__u8)action, + NVME_LOG_LID_PERSISTENT_EVENT, NVME_LOG_LSI_NONE, NVME_CSI_NVM, + false, NVME_UUID_NONE, + 0, pevent_log, len, + NVME_LOG_PAGE_PDU_SIZE, NULL); } /** * nvme_get_log_lockdown() - Retrieve lockdown Log - * @l: Link handle + * @l: Link handle * @cnscp: Contents and Scope of Command and Feature Identifier Lists * @lockdown_log: Buffer to store the lockdown log * @@ -2440,23 +2198,11 @@ static inline int nvme_get_log_persistent_event(nvme_link_t l, static inline int nvme_get_log_lockdown(nvme_link_t l, __u8 cnscp, struct nvme_lockdown_log *lockdown_log) { - struct nvme_get_log_args args = { - .lpo = 0, - .result = NULL, - .log = lockdown_log, - .args_size = sizeof(args), - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .lid = NVME_LOG_LID_CMD_AND_FEAT_LOCKDOWN, - .len = sizeof(*lockdown_log), - .nsid = NVME_NSID_ALL, - .csi = NVME_CSI_NVM, - .lsi = NVME_LOG_LSI_NONE, - .lsp = cnscp, - .uuidx = NVME_UUID_NONE, - .rae = false, - .ot = false, - }; - return nvme_get_log_page(l, NVME_LOG_PAGE_PDU_SIZE, &args); + return nvme_get_log(l, NVME_NSID_ALL, false, cnscp, + NVME_LOG_LID_CMD_AND_FEAT_LOCKDOWN, NVME_LOG_LSI_NONE, NVME_CSI_NVM, + false, NVME_UUID_NONE, + 0, lockdown_log, sizeof(*lockdown_log), + NVME_LOG_PAGE_PDU_SIZE, NULL); } /** diff --git a/src/nvme/linux.c b/src/nvme/linux.c index 5e890d0b8..3d058617e 100644 --- a/src/nvme/linux.c +++ b/src/nvme/linux.c @@ -8,6 +8,7 @@ */ #include "nvme/api-types.h" +#include "nvme/types.h" #include #include #include @@ -254,18 +255,6 @@ int nvme_get_telemetry_log(nvme_link_t l, bool create, bool ctrl, bool rae, size void *tmp; int err; size_t dalb; - struct nvme_get_log_args args = { - .args_size = sizeof(args), - .nsid = NVME_NSID_NONE, - .lsp = NVME_LOG_LSP_NONE, - .lsi = NVME_LOG_LSI_NONE, - .uuidx = NVME_UUID_NONE, - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .result = NULL, - .csi = NVME_CSI_NVM, - .rae = rae, - .ot = false, - }; *size = 0; @@ -274,14 +263,14 @@ int nvme_get_telemetry_log(nvme_link_t l, bool create, bool ctrl, bool rae, size return -ENOMEM; if (ctrl) { - err = nvme_get_log_telemetry_ctrl(l, true, 0, xfer, log); + err = nvme_get_log_telemetry_ctrl(l, true, 0, log, xfer); lid = NVME_LOG_LID_TELEMETRY_CTRL; } else { lid = NVME_LOG_LID_TELEMETRY_HOST; if (create) err = nvme_get_log_create_telemetry_host_mcda(l, da, log); else - err = nvme_get_log_telemetry_host(l, 0, xfer, log); + err = nvme_get_log_telemetry_host(l, 0, log, xfer); } if (err) @@ -322,10 +311,11 @@ int nvme_get_telemetry_log(nvme_link_t l, bool create, bool ctrl, bool rae, size return -ENOMEM; log = tmp; - args.lid = lid; - args.log = log; - args.len = *size; - err = nvme_get_log_page(l, max_data_tx, &args); + err = nvme_get_log(l, NVME_NSID_NONE, rae, NVME_LOG_LSP_NONE, + lid, NVME_LOG_LSI_NONE, NVME_CSI_NVM, + false, NVME_UUID_NONE, + 0, log, *size, + max_data_tx, NULL); if (err) return err; @@ -375,24 +365,12 @@ int nvme_get_lba_status_log(nvme_link_t l, bool rae, struct nvme_lba_status_log __u32 size; void *tmp; int err; - struct nvme_get_log_args args = { - .args_size = sizeof(args), - .nsid = NVME_NSID_NONE, - .lsp = NVME_LOG_LSP_NONE, - .lsi = NVME_LOG_LSI_NONE, - .uuidx = NVME_UUID_NONE, - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .result = NULL, - .csi = NVME_CSI_NVM, - .rae = rae, - .ot = false, - }; buf = malloc(sizeof(*buf)); if (!buf) return -ENOMEM; - err = nvme_get_log_lba_status(l, true, 0, sizeof(*buf), buf); + err = nvme_get_log_lba_status(l, true, 0, buf, sizeof(*buf)); if (err) { *log = NULL; return err; @@ -412,10 +390,11 @@ int nvme_get_lba_status_log(nvme_link_t l, bool rae, struct nvme_lba_status_log } buf = tmp; - args.lid = NVME_LOG_LID_LBA_STATUS; - args.log = buf; - args.len = size; - err = nvme_get_log_page(l, 4096, &args); + err = nvme_get_log(l, NVME_NSID_NONE, rae, NVME_LOG_LSP_NONE, + NVME_LOG_LID_LBA_STATUS, NVME_LOG_LSI_NONE, NVME_CSI_NVM, + false, NVME_UUID_NONE, + 0, buf, size, + NVME_LOG_PAGE_PDU_SIZE, NULL); if (err) { *log = NULL; return err; diff --git a/test/ioctl/ana.c b/test/ioctl/ana.c index 44ec41ae3..ccd195655 100644 --- a/test/ioctl/ana.c +++ b/test/ioctl/ana.c @@ -26,7 +26,7 @@ static void test_no_retries(void) /* max_retries = 0 is nonsensical */ check(nvme_get_ana_log_atomic(test_link, false, false, - 0, &log, &len) == -EINVAL, + &log, &len, 0) == -EINVAL, "get log page succeeded"); } @@ -37,7 +37,7 @@ static void test_len_too_short(void) /* Provided buffer doesn't have enough space to read the header */ check(nvme_get_ana_log_atomic(test_link, false, false, - 1, &log, &len) == -ENOSPC, + &log, &len, 1) == -ENOSPC, "get log page succeeded"); } @@ -59,7 +59,7 @@ static void test_no_groups(void) arbitrary(&header, sizeof(header)); header.ngrps = cpu_to_le16(0); set_mock_admin_cmds(&mock_admin_cmd, 1); - check(!nvme_get_ana_log_atomic(test_link, false, false, 1, &log, &len), + check(!nvme_get_ana_log_atomic(test_link, false, false, &log, &len, 1), "get log page failed"); end_mock_cmds(); cmp(&log, &header, sizeof(header), "incorrect header"); @@ -79,10 +79,10 @@ static void test_one_group_rgo(void) * Since only one command was issued, chgcnt doesn't need to be checked. */ struct mock_cmd mock_admin_cmd = { - .opcode = nvme_admin_get_log_page, + .opcode= nvme_admin_get_log_page, .data_len = len_dwords * 4, .cdw10 = (len_dwords - 1) << 16 /* NUMDL */ - | NVME_LOG_ANA_LSP_RGO_GROUPS_ONLY << 8 /* LSP */ + | NVME_LOG_ANA_LSP_RGO_GROUPS_ONLY << 8 /* LSP */ | NVME_LOG_LID_ANA, /* LID */ .out_data = log_page, .out_data_len = sizeof(log_page), @@ -97,7 +97,7 @@ static void test_one_group_rgo(void) memcpy(log_page, &header, sizeof(header)); memcpy(log_page + sizeof(header), &group, sizeof(group)); set_mock_admin_cmds(&mock_admin_cmd, 1); - check(!nvme_get_ana_log_atomic(test_link, true, false, 1, log, &len), + check(!nvme_get_ana_log_atomic(test_link, false, true, log, &len, 1), "get log page failed"); end_mock_cmds(); cmp(log, log_page, sizeof(log_page), "incorrect log page"); @@ -138,7 +138,7 @@ static void test_one_group_nsids(void) memcpy(log_page + sizeof(header), &group, sizeof(group)); memcpy(log_page + sizeof(header) + sizeof(group), nsids, sizeof(nsids)); set_mock_admin_cmds(&mock_admin_cmd, 1); - check(!nvme_get_ana_log_atomic(test_link, false, false, 1, log, &len), + check(!nvme_get_ana_log_atomic(test_link, false, false, log, &len, 1), "get log page failed"); end_mock_cmds(); cmp(log, log_page, sizeof(log_page), "incorrect log page"); @@ -179,7 +179,7 @@ static void test_multiple_groups_rgo(void) memcpy(log_page, &header, sizeof(header)); memcpy(log_page + sizeof(header), groups, sizeof(groups)); set_mock_admin_cmds(&mock_admin_cmd, 1); - check(!nvme_get_ana_log_atomic(test_link, true, true, 1, log, &len), + check(!nvme_get_ana_log_atomic(test_link, true, true, log, &len, 1), "get log page failed"); end_mock_cmds(); cmp(log, log_page, sizeof(log_page), "incorrect log page"); @@ -245,7 +245,7 @@ static void test_multiple_groups_nsids(void) sizeof(group2) + sizeof(nsids2) + sizeof(group3), nsids3, sizeof(nsids3)); set_mock_admin_cmds(&mock_admin_cmd, 1); - check(!nvme_get_ana_log_atomic(test_link, false, false, 1, log, &len), + check(!nvme_get_ana_log_atomic(test_link, false, false, log, &len, 1), "get log page failed"); end_mock_cmds(); cmp(log, log_page, sizeof(log_page), "incorrect log page"); @@ -317,7 +317,7 @@ static void test_long_log(void) memcpy(log_page + sizeof(header), &group, sizeof(group)); memcpy(log_page + sizeof(header) + sizeof(group), nsids, sizeof(nsids)); set_mock_admin_cmds(mock_admin_cmds, ARRAY_SIZE(mock_admin_cmds)); - check(!nvme_get_ana_log_atomic(test_link, false, true, 1, log, &len), + check(!nvme_get_ana_log_atomic(test_link, true, false, log, &len, 1), "get log page failed"); end_mock_cmds(); cmp(log, log_page, sizeof(log_page), "incorrect log page"); @@ -393,7 +393,7 @@ static void test_chgcnt_change(void) memcpy(log_page2, &header2, sizeof(header2)); memcpy(log_page2 + sizeof(header2), &group2, sizeof(group2)); set_mock_admin_cmds(mock_admin_cmds, ARRAY_SIZE(mock_admin_cmds)); - check(!nvme_get_ana_log_atomic(test_link, true, true, 2, log, &len), + check(!nvme_get_ana_log_atomic(test_link, true, true, log, &len, 2), "get log page failed"); end_mock_cmds(); cmp(log, log_page2, sizeof(log_page2), "incorrect log page"); @@ -475,7 +475,7 @@ static void test_buffer_too_short_chgcnt_change(void) memcpy(log_page2 + sizeof(header2) + sizeof(group2), &nsid2, sizeof(nsid2)); set_mock_admin_cmds(mock_admin_cmds, ARRAY_SIZE(mock_admin_cmds)); - check(!nvme_get_ana_log_atomic(test_link, false, false, 2, log, &len), + check(!nvme_get_ana_log_atomic(test_link, false, false, log, &len, 2), "get log page failed"); end_mock_cmds(); cmp(log, log_page2, sizeof(log_page2), "incorrect log page"); @@ -571,7 +571,7 @@ static void test_chgcnt_max_retries(void) memcpy(log_page2 + sizeof(header2) + sizeof(group), nsids, sizeof(nsids)); set_mock_admin_cmds(mock_admin_cmds, ARRAY_SIZE(mock_admin_cmds)); - check(nvme_get_ana_log_atomic(test_link, false, true, 2, log, &len) == -EAGAIN, + check(nvme_get_ana_log_atomic(test_link, true, false, log, &len, 2) == -EAGAIN, "get log page succeeded"); end_mock_cmds(); free(log); @@ -611,7 +611,7 @@ static void test_buffer_too_short(void) memcpy(log_page + sizeof(header), &group, sizeof(group)); memcpy(log_page + sizeof(header) + sizeof(group), nsids, sizeof(nsids)); set_mock_admin_cmds(&mock_admin_cmd, 1); - check(nvme_get_ana_log_atomic(test_link, false, true, 2, log, &len) == -ENOSPC, + check(nvme_get_ana_log_atomic(test_link, true, false, log, &len, 2) == -ENOSPC, "get log page succeeded"); end_mock_cmds(); free(log); diff --git a/test/ioctl/logs.c b/test/ioctl/logs.c index 6b4467a4c..a76413057 100644 --- a/test/ioctl/logs.c +++ b/test/ioctl/logs.c @@ -61,7 +61,7 @@ static void test_get_log_mgmt_addr_list(void) arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_get_log_mgmt_addr_list(test_link, sizeof(log), &log); + err = nvme_get_log_mgmt_addr_list(test_link, &log, sizeof(log)); end_mock_cmds(); check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); @@ -283,8 +283,8 @@ static void test_get_log_telemetry_host(void) arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_get_log_telemetry_host(test_link, TEST_OFFSET, sizeof(log), - &log); + err = nvme_get_log_telemetry_host(test_link, TEST_OFFSET, + &log, sizeof(log)); end_mock_cmds(); check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); @@ -312,7 +312,7 @@ static void test_get_log_telemetry_ctrl(void) arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_get_log_telemetry_ctrl(test_link, TEST_RAE, TEST_OFFSET, - sizeof(log), &log); + &log, sizeof(log)); end_mock_cmds(); check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); @@ -380,7 +380,7 @@ static void test_get_log_predictable_lat_event(void) arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_get_log_predictable_lat_event( - test_link, TEST_RAE, TEST_OFFSET_32, sizeof(log), &log); + test_link, TEST_RAE, TEST_OFFSET_32, &log, sizeof(log)); end_mock_cmds(); check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); @@ -428,7 +428,7 @@ static void test_get_log_reclaim_unit_handle_usage(void) arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_get_log_reclaim_unit_handle_usage( - test_link, TEST_ENDGID, TEST_OFFSET_32, sizeof(log), &log); + test_link, TEST_ENDGID, TEST_OFFSET_32, &log, sizeof(log)); end_mock_cmds(); check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); @@ -452,7 +452,7 @@ static void test_get_log_fdp_stats(void) arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_get_log_fdp_stats(test_link, TEST_ENDGID, TEST_OFFSET_32, - sizeof(log), &log); + &log, sizeof(log)); end_mock_cmds(); check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); @@ -477,7 +477,7 @@ static void test_get_log_fdp_events(void) arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_get_log_fdp_events(test_link, TEST_ENDGID, TEST_EVENTS, - TEST_OFFSET_32, sizeof(log), &log); + TEST_OFFSET_32, &log, sizeof(log)); end_mock_cmds(); check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); @@ -501,8 +501,8 @@ static void test_get_log_ana(void) arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_get_log_ana(test_link, TEST_ANA_LSP, TEST_RAE, TEST_OFFSET, - sizeof(log), &log); + err = nvme_get_log_ana(test_link, TEST_RAE, TEST_ANA_LSP, TEST_OFFSET, + &log, sizeof(log)); end_mock_cmds(); check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); @@ -525,7 +525,7 @@ static void test_get_log_ana_groups(void) arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_get_log_ana_groups(test_link, TEST_RAE, sizeof(log), &log); + err = nvme_get_log_ana_groups(test_link, TEST_RAE, &log, sizeof(log)); end_mock_cmds(); check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); @@ -549,7 +549,7 @@ static void test_get_log_lba_status(void) arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_get_log_lba_status(test_link, TEST_RAE, TEST_OFFSET, - sizeof(log), &log); + &log, sizeof(log)); end_mock_cmds(); check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); @@ -573,7 +573,7 @@ static void test_get_log_endurance_grp_evt(void) arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_get_log_endurance_grp_evt(test_link, TEST_RAE, TEST_OFFSET_32, - sizeof(log), &log); + &log, sizeof(log)); end_mock_cmds(); check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); @@ -640,7 +640,7 @@ static void test_get_log_boot_partition(void) arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_get_log_boot_partition(test_link, TEST_RAE, TEST_LSP, - sizeof(log), &log); + &log, sizeof(log)); end_mock_cmds(); check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); @@ -663,7 +663,7 @@ static void test_get_log_rotational_media_info(void) arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_get_log_rotational_media_info(test_link, TEST_ENDGID, - sizeof(log), &log); + &log, sizeof(log)); end_mock_cmds(); check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); @@ -685,7 +685,7 @@ static void test_get_log_dispersed_ns_participating_nss(void) arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_get_log_dispersed_ns_participating_nss(test_link, TEST_NSID, - sizeof(log), &log); + &log, sizeof(log)); end_mock_cmds(); check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); @@ -708,7 +708,7 @@ static void test_get_log_phy_rx_eom(void) arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_get_log_phy_rx_eom(test_link, TEST_LSP, TEST_CNTID, - sizeof(log), &log); + &log, sizeof(log)); end_mock_cmds(); check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); @@ -730,8 +730,8 @@ static void test_get_log_reachability_groups(void) arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_get_log_reachability_groups(test_link, !!TEST_LSP, TEST_RAE, - sizeof(log), &log); + err = nvme_get_log_reachability_groups(test_link, TEST_RAE, !!TEST_LSP, + &log, sizeof(log)); end_mock_cmds(); check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); @@ -754,7 +754,7 @@ static void test_get_log_reachability_associations(void) arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_get_log_reachability_associations( - test_link, !!TEST_LSP, TEST_RAE, sizeof(log), &log); + test_link, !!TEST_LSP, TEST_RAE, &log, sizeof(log)); end_mock_cmds(); check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); @@ -776,8 +776,8 @@ static void test_get_log_changed_alloc_ns_list(void) arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_get_log_changed_alloc_ns_list(test_link, TEST_RAE, sizeof(log), - &log); + err = nvme_get_log_changed_alloc_ns_list(test_link, TEST_RAE, + &log, sizeof(log)); end_mock_cmds(); check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); @@ -822,8 +822,8 @@ static void test_get_log_host_discover(void) arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_get_log_host_discover(test_link, !!TEST_LSP, TEST_RAE, - sizeof(log), &log); + err = nvme_get_log_host_discover(test_link, TEST_RAE, !!TEST_LSP, + &log, sizeof(log)); end_mock_cmds(); check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); @@ -844,7 +844,7 @@ static void test_get_log_ave_discover(void) arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_get_log_ave_discover(test_link, TEST_RAE, sizeof(log), &log); + err = nvme_get_log_ave_discover(test_link, TEST_RAE, &log, sizeof(log)); end_mock_cmds(); check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); @@ -866,8 +866,8 @@ static void test_get_log_pull_model_ddc_req(void) arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_get_log_pull_model_ddc_req(test_link, TEST_RAE, sizeof(log), - &log); + err = nvme_get_log_pull_model_ddc_req(test_link, TEST_RAE, + &log, sizeof(log)); end_mock_cmds(); check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); @@ -978,8 +978,8 @@ static void test_get_log_persistent_event(void) arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_get_log_persistent_event(test_link, TEST_PEVENT, sizeof(log), - &log); + err = nvme_get_log_persistent_event(test_link, TEST_PEVENT, + &log, sizeof(log)); end_mock_cmds(); check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); diff --git a/test/mi.c b/test/mi.c index e990ca983..7a2a2038d 100644 --- a/test/mi.c +++ b/test/mi.c @@ -1900,7 +1900,6 @@ static int test_admin_get_log_split_cb(struct nvme_mi_ep *ep, static void test_admin_get_log_split(struct nvme_mi_ep *ep) { - struct nvme_get_log_args args = { 0 }; unsigned char buf[4096 * 2 + 4]; struct log_data ldata; nvme_link_t link; @@ -1911,14 +1910,11 @@ static void test_admin_get_log_split(struct nvme_mi_ep *ep) link = nvme_mi_init_link(ep, 5); - args.args_size = sizeof(args); - args.lid = 1; - args.log = buf; - args.len = sizeof(buf); - args.lpo = 0; - args.ot = false; - - rc = nvme_get_log_page(link, NVME_LOG_PAGE_PDU_SIZE, &args); + rc = nvme_get_log(link, NVME_NSID_NONE, false, NVME_LOG_LSP_NONE, + NVME_LOG_LID_ERROR, NVME_LOG_LSI_NONE, NVME_CSI_NVM, + false, NVME_UUID_NONE, + 0, buf, sizeof(buf), + NVME_LOG_PAGE_PDU_SIZE, NULL); assert(!rc); diff --git a/test/test.c b/test/test.c index 8ce2f626c..9729f0705 100644 --- a/test/test.c +++ b/test/test.c @@ -143,7 +143,7 @@ static int test_ctrl(nvme_ctrl_t c) printf(" Reservation Log\n"); else printf(" ERROR: Reservation Log:%x\n", ret); - ret = nvme_get_log_ana_groups(l, true, sizeof(buf), analog); + ret = nvme_get_log_ana_groups(l, true, analog, sizeof(buf)); if (!ret) printf(" ANA Groups\n"); else @@ -153,7 +153,7 @@ static int test_ctrl(nvme_ctrl_t c) printf(" Endurance Group\n"); else printf(" ERROR: Endurance Group:%x\n", ret); - ret = nvme_get_log_telemetry_ctrl(l, true, 0, sizeof(buf), telem); + ret = nvme_get_log_telemetry_ctrl(l, true, 0, telem, sizeof(buf)); if (!ret) printf(" Telemetry Controller\n"); else From 8a4329979815873b3731110e57a1dc4dc5809eee Mon Sep 17 00:00:00 2001 From: Daniel Wagner Date: Fri, 8 Aug 2025 16:15:08 +0200 Subject: [PATCH 21/66] test: fix rae and lsp handling in log page tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The compiler warns with ../test/ioctl/logs.c: In function ‘test_get_log_reachability_groups’: ../test/ioctl/logs.c:725:28: warning: enum constant in boolean context [-Wint-in-bool-context] 725 | (!!TEST_LSP << 8) | (!!TEST_RAE << 15) | | ^ ../test/ioctl/logs.c:733:70: warning: enum constant in boolean context [-Wint-in-bool-context] 733 | err = nvme_get_log_reachability_groups(test_link, TEST_RAE, !!TEST_LSP, | ^ Update the tests so the types are correctly handled. It also addresses the problem with the wrong lsp value testing. Signed-off-by: Daniel Wagner --- test/ioctl/logs.c | 52 +++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/test/ioctl/logs.c b/test/ioctl/logs.c index a76413057..27d5864ed 100644 --- a/test/ioctl/logs.c +++ b/test/ioctl/logs.c @@ -14,7 +14,7 @@ #define TEST_CNTID 0x4321 #define TEST_DOMID 0xFEDC #define TEST_ENDGID 0x0123 -#define TEST_RAE true +#define TEST_RAE 0x1 #define TEST_MCDA NVME_TELEMETRY_DA_3 #define TEST_OFFSET 0xFFFFFFFF1 #define TEST_OFFSET_32 0xFFFFFFFF @@ -32,7 +32,7 @@ static void test_get_log_sanitize(void) .opcode = nvme_admin_get_log_page, .nsid = NVME_NSID_ALL, .data_len = sizeof(expected_log), - .cdw10 = (NVME_LOG_LID_SANITIZE << 0) | (!!TEST_RAE << 15) | + .cdw10 = (NVME_LOG_LID_SANITIZE << 0) | (TEST_RAE << 15) | (((sizeof(expected_log) >> 2) - 1) << 16), .out_data = &expected_log, }; @@ -96,7 +96,7 @@ static void test_get_log_error(void) .opcode = nvme_admin_get_log_page, .nsid = NVME_NSID_ALL, .data_len = sizeof(expected_log), - .cdw10 = (NVME_LOG_LID_ERROR << 0) | (!!TEST_RAE << 15) | + .cdw10 = (NVME_LOG_LID_ERROR << 0) | (TEST_RAE << 15) | (((sizeof(expected_log) >> 2) - 1) << 16), .out_data = &expected_log, }; @@ -117,7 +117,7 @@ static void test_get_log_smart(void) .opcode = nvme_admin_get_log_page, .nsid = TEST_NSID, .data_len = sizeof(expected_log), - .cdw10 = (NVME_LOG_LID_SMART << 0) | (!!TEST_RAE << 15) | + .cdw10 = (NVME_LOG_LID_SMART << 0) | (TEST_RAE << 15) | (((sizeof(expected_log) >> 2) - 1) << 16), .out_data = &expected_log, }; @@ -138,7 +138,7 @@ static void test_get_log_fw_slot(void) .opcode = nvme_admin_get_log_page, .nsid = NVME_NSID_ALL, .data_len = sizeof(expected_log), - .cdw10 = (NVME_LOG_LID_FW_SLOT << 0) | (!!TEST_RAE << 15) | + .cdw10 = (NVME_LOG_LID_FW_SLOT << 0) | (TEST_RAE << 15) | (((sizeof(expected_log) >> 2) - 1) << 16), .out_data = &expected_log, }; @@ -301,7 +301,7 @@ static void test_get_log_telemetry_ctrl(void) (((NVME_TELEMETRY_DA_CTRL_DETERMINE << 1) | NVME_LOG_TELEM_HOST_LSP_RETAIN) << 8) | - (!!TEST_RAE << 15) | + (TEST_RAE << 15) | (((sizeof(expected_log) >> 2) - 1) << 16), .cdw12 = TEST_OFFSET & 0xffffffff, .cdw13 = TEST_OFFSET >> 32, @@ -370,7 +370,7 @@ static void test_get_log_predictable_lat_event(void) .nsid = NVME_NSID_NONE, .data_len = sizeof(expected_log), .cdw10 = (NVME_LOG_LID_PREDICTABLE_LAT_AGG << 0) | - (!!TEST_RAE << 15) | + (TEST_RAE << 15) | (((sizeof(expected_log) >> 2) - 1) << 16), .cdw12 = TEST_OFFSET_32, .out_data = &expected_log, @@ -517,7 +517,7 @@ static void test_get_log_ana_groups(void) .data_len = sizeof(expected_log), .cdw10 = (NVME_LOG_LID_ANA << 0) | (NVME_LOG_ANA_LSP_RGO_GROUPS_ONLY << 8) | - (!!TEST_RAE << 15) | + (TEST_RAE << 15) | (((sizeof(expected_log) >> 2) - 1) << 16), .out_data = &expected_log, }; @@ -538,7 +538,7 @@ static void test_get_log_lba_status(void) .opcode = nvme_admin_get_log_page, .nsid = NVME_NSID_NONE, .data_len = sizeof(expected_log), - .cdw10 = (NVME_LOG_LID_LBA_STATUS << 0) | (!!TEST_RAE << 15) | + .cdw10 = (NVME_LOG_LID_LBA_STATUS << 0) | (TEST_RAE << 15) | (((sizeof(expected_log) >> 2) - 1) << 16), .cdw12 = TEST_OFFSET & 0xffffffff, .cdw13 = TEST_OFFSET >> 32, @@ -563,7 +563,7 @@ static void test_get_log_endurance_grp_evt(void) .nsid = NVME_NSID_NONE, .data_len = sizeof(expected_log), .cdw10 = (NVME_LOG_LID_ENDURANCE_GRP_EVT << 0) | - (!!TEST_RAE << 15) | + (TEST_RAE << 15) | (((sizeof(expected_log) >> 2) - 1) << 16), .cdw12 = TEST_OFFSET_32, .out_data = &expected_log, @@ -587,7 +587,7 @@ static void test_get_log_fid_supported_effects(void) .nsid = NVME_NSID_NONE, .data_len = sizeof(expected_log), .cdw10 = (NVME_LOG_LID_FID_SUPPORTED_EFFECTS << 0) | - (!!TEST_RAE << 15) | + (TEST_RAE << 15) | (((sizeof(expected_log) >> 2) - 1) << 16), .out_data = &expected_log, }; @@ -609,7 +609,7 @@ static void test_get_log_mi_cmd_supported_effects(void) .nsid = NVME_NSID_NONE, .data_len = sizeof(expected_log), .cdw10 = (NVME_LOG_LID_MI_CMD_SUPPORTED_EFFECTS << 0) | - (!!TEST_RAE << 15) | + (TEST_RAE << 15) | (((sizeof(expected_log) >> 2) - 1) << 16), .out_data = &expected_log, }; @@ -631,7 +631,7 @@ static void test_get_log_boot_partition(void) .nsid = NVME_NSID_NONE, .data_len = sizeof(expected_log), .cdw10 = (NVME_LOG_LID_BOOT_PARTITION << 0) | (TEST_LSP << 8) | - (!!TEST_RAE << 15) | + (TEST_RAE << 15) | (((sizeof(expected_log) >> 2) - 1) << 16), .out_data = &expected_log, }; @@ -722,7 +722,7 @@ static void test_get_log_reachability_groups(void) .nsid = NVME_NSID_ALL, .data_len = sizeof(expected_log), .cdw10 = (NVME_LOG_LID_REACHABILITY_GROUPS << 0) | - (!!TEST_LSP << 8) | (!!TEST_RAE << 15) | + (0x1 << 8) | (TEST_RAE << 15) | (((sizeof(expected_log) >> 2) - 1) << 16), .out_data = &expected_log, }; @@ -730,7 +730,7 @@ static void test_get_log_reachability_groups(void) arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_get_log_reachability_groups(test_link, TEST_RAE, !!TEST_LSP, + err = nvme_get_log_reachability_groups(test_link, !!TEST_RAE, true, &log, sizeof(log)); end_mock_cmds(); check(err == 0, "get log returned error %d", err); @@ -745,7 +745,7 @@ static void test_get_log_reachability_associations(void) .nsid = NVME_NSID_ALL, .data_len = sizeof(expected_log), .cdw10 = (NVME_LOG_LID_REACHABILITY_ASSOCIATIONS << 0) | - (!!TEST_LSP << 8) | (!!TEST_RAE << 15) | + (0x1 << 8) | (TEST_RAE << 15) | (((sizeof(expected_log) >> 2) - 1) << 16), .out_data = &expected_log, }; @@ -754,7 +754,7 @@ static void test_get_log_reachability_associations(void) arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_get_log_reachability_associations( - test_link, !!TEST_LSP, TEST_RAE, &log, sizeof(log)); + test_link, !!TEST_RAE, true, &log, sizeof(log)); end_mock_cmds(); check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); @@ -768,7 +768,7 @@ static void test_get_log_changed_alloc_ns_list(void) .nsid = NVME_NSID_ALL, .data_len = sizeof(expected_log), .cdw10 = (NVME_LOG_LID_CHANGED_ALLOC_NS_LIST << 0) | - (!!TEST_RAE << 15) | + (TEST_RAE << 15) | (((sizeof(expected_log) >> 2) - 1) << 16), .out_data = &expected_log, }; @@ -790,7 +790,7 @@ static void test_get_log_discovery(void) .opcode = nvme_admin_get_log_page, .nsid = NVME_NSID_NONE, .data_len = sizeof(expected_log), - .cdw10 = (NVME_LOG_LID_DISCOVER << 0) | (!!TEST_RAE << 15) | + .cdw10 = (NVME_LOG_LID_DISCOVER << 0) | (TEST_RAE << 15) | (((sizeof(expected_log) >> 2) - 1) << 16), .cdw12 = TEST_OFFSET_32, .out_data = &expected_log, @@ -813,8 +813,8 @@ static void test_get_log_host_discover(void) .opcode = nvme_admin_get_log_page, .nsid = NVME_NSID_ALL, .data_len = sizeof(expected_log), - .cdw10 = (NVME_LOG_LID_HOST_DISCOVER << 0) | (!!TEST_LSP << 8) | - (!!TEST_RAE << 15) | + .cdw10 = (NVME_LOG_LID_HOST_DISCOVER << 0) | (0x1 << 8) | + (TEST_RAE << 15) | (((sizeof(expected_log) >> 2) - 1) << 16), .out_data = &expected_log, }; @@ -822,7 +822,7 @@ static void test_get_log_host_discover(void) arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_get_log_host_discover(test_link, TEST_RAE, !!TEST_LSP, + err = nvme_get_log_host_discover(test_link, !!TEST_RAE, true, &log, sizeof(log)); end_mock_cmds(); check(err == 0, "get log returned error %d", err); @@ -836,7 +836,7 @@ static void test_get_log_ave_discover(void) .opcode = nvme_admin_get_log_page, .nsid = NVME_NSID_ALL, .data_len = sizeof(expected_log), - .cdw10 = (NVME_LOG_LID_AVE_DISCOVER << 0) | (!!TEST_RAE << 15) | + .cdw10 = (NVME_LOG_LID_AVE_DISCOVER << 0) | (TEST_RAE << 15) | (((sizeof(expected_log) >> 2) - 1) << 16), .out_data = &expected_log, }; @@ -858,7 +858,7 @@ static void test_get_log_pull_model_ddc_req(void) .nsid = NVME_NSID_ALL, .data_len = sizeof(expected_log), .cdw10 = (NVME_LOG_LID_PULL_MODEL_DDC_REQ << 0) | - (!!TEST_RAE << 15) | + (TEST_RAE << 15) | (((sizeof(expected_log) >> 2) - 1) << 16), .out_data = &expected_log, }; @@ -924,7 +924,7 @@ static void test_get_log_reservation(void) .opcode = nvme_admin_get_log_page, .nsid = NVME_NSID_ALL, .data_len = sizeof(expected_log), - .cdw10 = (NVME_LOG_LID_RESERVATION << 0) | (!!TEST_RAE << 15) | + .cdw10 = (NVME_LOG_LID_RESERVATION << 0) | (TEST_RAE << 15) | (((sizeof(expected_log) >> 2) - 1) << 16), .out_data = &expected_log, }; @@ -946,7 +946,7 @@ static void test_get_log_zns_changed_zones(void) .nsid = TEST_NSID, .data_len = sizeof(expected_log), .cdw10 = (NVME_LOG_LID_ZNS_CHANGED_ZONES << 0) | - (!!TEST_RAE << 15) | + (TEST_RAE << 15) | (((sizeof(expected_log) >> 2) - 1) << 16), .cdw14 = NVME_CSI_ZNS << 24, .out_data = &expected_log, From e7e91436996e6fa3bd74103321c034ff1056dd77 Mon Sep 17 00:00:00 2001 From: Daniel Wagner Date: Fri, 1 Aug 2025 10:40:10 +0200 Subject: [PATCH 22/66] ioctl: nvme_format_nvm use nvme_passthru_cmd directly Drop struct nvme_format_nvm_args. [dennis: merge lbafl and lbafu into one argument] Signed-off-by: Dennis Maisenbacher Signed-off-by: Daniel Wagner --- src/libnvme.map | 1 - src/nvme/api-types.h | 29 ----------------------------- src/nvme/ioctl.c | 30 ------------------------------ src/nvme/ioctl.h | 35 +++++++++++++++++++++++++++++++---- test/ioctl/misc.c | 26 +++++++++++--------------- test/mi.c | 24 +++++++++++------------- 6 files changed, 53 insertions(+), 92 deletions(-) diff --git a/src/libnvme.map b/src/libnvme.map index 00b116720..955ec358c 100644 --- a/src/libnvme.map +++ b/src/libnvme.map @@ -75,7 +75,6 @@ LIBNVME_2_0 { nvme_export_tls_key_versioned; nvme_first_host; nvme_first_subsystem; - nvme_format_nvm; nvme_free_ctrl; nvme_free_host; nvme_free_ns; diff --git a/src/nvme/api-types.h b/src/nvme/api-types.h index d1f51bf39..0967ce7c0 100644 --- a/src/nvme/api-types.h +++ b/src/nvme/api-types.h @@ -108,35 +108,6 @@ struct nvme_get_features_args { __u8 uuidx; }; -/** - * struct nvme_format_nvm_args - Arguments for the Format Nvme Namespace command - * @result: The command completion result from CQE dword0 - * @args_size: Size of &struct nvme_format_nvm_args - * @timeout: Set to override default timeout to this value in milliseconds; - * useful for long running formats. 0 will use system default. - * @nsid: Namespace ID to format - * @mset: Metadata settings (extended or separated), true if extended - * @pi: Protection information type - * @pil: Protection information location (beginning or end), true if end - * @ses: Secure erase settings - * @lbaf: Logical block address format least significant 4 bits - * @rsvd1: Reserved - * @lbafu: Logical block address format most significant 2 bits - */ -struct nvme_format_nvm_args { - __u32 *result; - int args_size; - __u32 timeout; - __u32 nsid; - enum nvme_cmd_format_mset mset; - enum nvme_cmd_format_pi pi; - enum nvme_cmd_format_pil pil; - enum nvme_cmd_format_ses ses; - __u8 lbaf; - __u8 rsvd1[7]; - __u8 lbafu; -}; - /** * struct nvme_ns_mgmt_args - Arguments for NVMe Namespace Management command * @result: NVMe command result diff --git a/src/nvme/ioctl.c b/src/nvme/ioctl.c index 0c159e23b..e57724a67 100644 --- a/src/nvme/ioctl.c +++ b/src/nvme/ioctl.c @@ -1336,36 +1336,6 @@ int nvme_get_features_iocs_profile(nvme_link_t l, enum nvme_get_features_sel sel return __nvme_get_features(l, NVME_FEAT_FID_IOCS_PROFILE, sel, result); } -int nvme_format_nvm(nvme_link_t l, struct nvme_format_nvm_args *args) -{ - const size_t size_v1 = sizeof_args(struct nvme_format_nvm_args, lbaf, __u64); - const size_t size_v2 = sizeof_args(struct nvme_format_nvm_args, lbafu, __u64); - __u32 cdw10; - - if (args->args_size < size_v1 || args->args_size > size_v2) - return -EINVAL; - - cdw10 = NVME_SET(args->lbaf, FORMAT_CDW10_LBAF) | - NVME_SET(args->mset, FORMAT_CDW10_MSET) | - NVME_SET(args->pi, FORMAT_CDW10_PI) | - NVME_SET(args->pil, FORMAT_CDW10_PIL) | - NVME_SET(args->ses, FORMAT_CDW10_SES); - - if (args->args_size == size_v2) { - /* set lbafu extension */ - cdw10 |= NVME_SET(args->lbafu, FORMAT_CDW10_LBAFU); - } - - struct nvme_passthru_cmd cmd = { - .opcode = nvme_admin_format_nvm, - .nsid = args->nsid, - .cdw10 = cdw10, - .timeout_ms = args->timeout, - }; - - return nvme_submit_admin_passthru(l, &cmd, args->result); -} - int nvme_ns_mgmt(nvme_link_t l, struct nvme_ns_mgmt_args *args) { const size_t size_v1 = sizeof_args(struct nvme_ns_mgmt_args, csi, __u64); diff --git a/src/nvme/ioctl.h b/src/nvme/ioctl.h index fd8836e7b..7ca6d1e17 100644 --- a/src/nvme/ioctl.h +++ b/src/nvme/ioctl.h @@ -277,13 +277,13 @@ enum nvme_cmd_dword_fields { NVME_VIRT_MGMT_CDW10_RT_MASK = 0x7, NVME_VIRT_MGMT_CDW10_CNTLID_MASK = 0xffff, NVME_VIRT_MGMT_CDW11_NR_MASK = 0xffff, - NVME_FORMAT_CDW10_LBAF_SHIFT = 0, + NVME_FORMAT_CDW10_LBAFL_SHIFT = 0, NVME_FORMAT_CDW10_MSET_SHIFT = 4, NVME_FORMAT_CDW10_PI_SHIFT = 5, NVME_FORMAT_CDW10_PIL_SHIFT = 8, NVME_FORMAT_CDW10_SES_SHIFT = 9, NVME_FORMAT_CDW10_LBAFU_SHIFT = 12, - NVME_FORMAT_CDW10_LBAF_MASK = 0xf, + NVME_FORMAT_CDW10_LBAFL_MASK = 0xf, NVME_FORMAT_CDW10_MSET_MASK = 0x1, NVME_FORMAT_CDW10_PI_MASK = 0x7, NVME_FORMAT_CDW10_PIL_MASK = 0x1, @@ -3081,7 +3081,13 @@ int nvme_get_features_iocs_profile(nvme_link_t l, enum nvme_get_features_sel sel /** * nvme_format_nvm() - Format nvme namespace(s) * @l: Link handle - * @args: &struct nvme_format_nvme_args argument structure + * @nsid: Namespace ID to format + * @lbaf: Logical block address format + * @mset: Metadata settings (extended or separated), true if extended + * @pi: Protection information type + * @pil: Protection information location (beginning or end), true if end + * @ses: Secure erase settings + * @result: The command completion result from CQE dword0 * * The Format NVM command low level formats the NVM media. This command is used * by the host to change the LBA data size and/or metadata size. A low level @@ -3091,7 +3097,28 @@ int nvme_get_features_iocs_profile(nvme_link_t l, enum nvme_get_features_sel sel * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_format_nvm(nvme_link_t l, struct nvme_format_nvm_args *args); +static inline int nvme_format_nvm(nvme_link_t l, __u32 nsid, __u8 lbaf, + enum nvme_cmd_format_mset mset, + enum nvme_cmd_format_pi pi, + enum nvme_cmd_format_pil pil, + enum nvme_cmd_format_ses ses, + __u32 *result) +{ + __u32 cdw10 = NVME_SET(lbaf, FORMAT_CDW10_LBAFL) | + NVME_SET(mset, FORMAT_CDW10_MSET) | + NVME_SET(pi, FORMAT_CDW10_PI) | + NVME_SET(pil, FORMAT_CDW10_PIL) | + NVME_SET(ses, FORMAT_CDW10_SES) | + NVME_SET((lbaf >> 4), FORMAT_CDW10_LBAFU); + + struct nvme_passthru_cmd cmd = { + .opcode = nvme_admin_format_nvm, + .nsid = nsid, + .cdw10 = cdw10, + }; + + return nvme_submit_admin_passthru(l, &cmd, result); +} /** * nvme_ns_mgmt() - Issue a Namespace management command diff --git a/test/ioctl/misc.c b/test/ioctl/misc.c index 1ff943d7f..a399b674b 100644 --- a/test/ioctl/misc.c +++ b/test/ioctl/misc.c @@ -17,31 +17,27 @@ static nvme_link_t test_link; static void test_format_nvm(void) { + enum nvme_cmd_format_mset mset = NVME_FORMAT_MSET_EXTENDED; + enum nvme_cmd_format_pi pi = NVME_FORMAT_PI_TYPE2; + enum nvme_cmd_format_pil pil = NVME_FORMAT_PIL_FIRST; + enum nvme_cmd_format_ses ses = NVME_FORMAT_SES_USER_DATA_ERASE; + __u32 nsid = TEST_NSID; + __u8 lbaf = 0x1F; __u32 result = 0; - struct nvme_format_nvm_args args = { - .result = &result, - .args_size = sizeof(args), - .nsid = TEST_NSID, - .mset = NVME_FORMAT_MSET_EXTENDED, - .pi = NVME_FORMAT_PI_TYPE2, - .pil = NVME_FORMAT_PIL_FIRST, - .ses = NVME_FORMAT_SES_USER_DATA_ERASE, - .lbaf = 0xF, - .lbafu = 0x1, - }; struct mock_cmd mock_admin_cmd = { .opcode = nvme_admin_format_nvm, - .nsid = TEST_NSID, - .cdw10 = args.lbaf | (args.mset << 4) | (args.pi << 5) | - (args.pil << 8) | (args.ses << 9) | (args.lbafu << 12), + .nsid = nsid, + .cdw10 = lbaf | (mset << 4) | (pi << 5) | + (pil << 8) | (ses << 9) | ((lbaf >> 4) << 12), .result = 0, }; int err; set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_format_nvm(test_link, &args); + err = nvme_format_nvm(test_link, nsid, lbaf, mset, pi, pil, + ses, &result); end_mock_cmds(); check(err == 0, "returned error %d", err); check(result == 0, "returned result %u", result); diff --git a/test/mi.c b/test/mi.c index 7a2a2038d..44c92d84c 100644 --- a/test/mi.c +++ b/test/mi.c @@ -1694,12 +1694,11 @@ static void test_admin_fw_commit(struct nvme_mi_ep *ep) struct format_data { __u32 nsid; - __u8 lbafu; __u8 ses; __u8 pil; __u8 pi; __u8 mset; - __u8 lbafl; + __u8 lbaf; }; static int test_admin_format_nvm_cb(struct nvme_mi_ep *ep, @@ -1707,7 +1706,7 @@ static int test_admin_format_nvm_cb(struct nvme_mi_ep *ep, struct nvme_mi_resp *resp, void *data) { - struct nvme_format_nvm_args *args = data; + struct format_data *args = data; __u8 *rq_hdr; __u32 nsid; @@ -1723,13 +1722,13 @@ static int test_admin_format_nvm_cb(struct nvme_mi_ep *ep, | rq_hdr[8]; assert(nsid == args->nsid); - assert(((rq_hdr[44] >> 0) & 0xf) == args->lbaf); + assert(((rq_hdr[44] >> 0) & 0xf) == (args->lbaf & 0xf)); assert(((rq_hdr[44] >> 4) & 0x1) == args->mset); assert(((rq_hdr[44] >> 5) & 0x7) == args->pi); assert(((rq_hdr[45] >> 0) & 0x1) == args->pil); assert(((rq_hdr[45] >> 1) & 0x7) == args->ses); - assert(((rq_hdr[45] >> 4) & 0x3) == args->lbafu); + assert(((rq_hdr[45] >> 4) & 0x3) == (args->lbaf >> 4)); test_transport_resp_calc_mic(resp); @@ -1738,7 +1737,7 @@ static int test_admin_format_nvm_cb(struct nvme_mi_ep *ep, static void test_admin_format_nvm(struct nvme_mi_ep *ep) { - struct nvme_format_nvm_args args = { 0 }; + struct format_data args = { 0 }; nvme_link_t link; int rc; @@ -1749,27 +1748,26 @@ static void test_admin_format_nvm(struct nvme_mi_ep *ep) /* ensure we have the cdw0 bit field encoding correct, by testing twice * with inverted bit values */ - args.args_size = sizeof(args); args.nsid = 0x04030201; - args.lbafu = 0x3; args.ses = 0x0; args.pil = 0x1; args.pi = 0x0; args.mset = 0x1; - args.lbaf = 0x0; + args.lbaf = 0x30; - rc = nvme_format_nvm(link, &args); + rc = nvme_format_nvm(link, args.nsid, args.lbaf, args.mset, + args.pi, args.pil, args.ses, NULL); assert(!rc); args.nsid = ~args.nsid; - args.lbafu = 0; args.ses = 0x7; args.pil = 0x0; args.pi = 0x7; args.mset = 0x0; - args.lbaf = 0xf; + args.lbaf = 0x0f; - rc = nvme_format_nvm(link, &args); + rc = nvme_format_nvm(link, args.nsid, args.lbaf, args.mset, + args.pi, args.pil, args.ses, NULL); assert(!rc); } From 139eb6de0ddf623d05e623ff704836ae39a84631 Mon Sep 17 00:00:00 2001 From: Daniel Wagner Date: Fri, 1 Aug 2025 15:03:49 +0200 Subject: [PATCH 23/66] ioctl: nvme_ns_mgmt use nvme_passthru_cmd directly Drop struct nvme_ns_mgmt_args. Signed-off-by: Daniel Wagner --- src/libnvme.map | 1 - src/nvme/api-types.h | 26 ------------- src/nvme/ioctl.c | 33 ---------------- src/nvme/ioctl.h | 93 +++++++++++++++++--------------------------- test/ioctl/misc.c | 33 +++++++--------- test/mi.c | 4 +- 6 files changed, 53 insertions(+), 137 deletions(-) diff --git a/src/libnvme.map b/src/libnvme.map index 955ec358c..65bd8942e 100644 --- a/src/libnvme.map +++ b/src/libnvme.map @@ -257,7 +257,6 @@ LIBNVME_2_0 { nvme_ns_get_sysfs_dir; nvme_ns_get_uuid; nvme_ns_identify; - nvme_ns_mgmt; nvme_ns_read; nvme_ns_release_link; nvme_ns_rescan; diff --git a/src/nvme/api-types.h b/src/nvme/api-types.h index 0967ce7c0..46295a24e 100644 --- a/src/nvme/api-types.h +++ b/src/nvme/api-types.h @@ -108,32 +108,6 @@ struct nvme_get_features_args { __u8 uuidx; }; -/** - * struct nvme_ns_mgmt_args - Arguments for NVMe Namespace Management command - * @result: NVMe command result - * @ns: Namespace identification descriptors - * @args_size: Size of &struct nvme_ns_mgmt_args - * @timeout: Timeout in ms - * @nsid: Namespace identifier - * @sel: Type of management operation to perform - * @csi: Command Set Identifier - * @rsvd1: Reserved - * @rsvd2: Reserved - * @data: Host Software Specified Fields - */ -struct nvme_ns_mgmt_args { - __u32 *result; - struct nvme_id_ns *ns; - int args_size; - __u32 timeout; - __u32 nsid; - enum nvme_ns_mgmt_sel sel; - __u8 csi; - __u8 rsvd1[3]; - void *rsvd2; - struct nvme_ns_mgmt_host_sw_specified *data; -}; - /** * struct nvme_ns_attach_args - Arguments for Nvme Namespace Management command * @result: NVMe command result diff --git a/src/nvme/ioctl.c b/src/nvme/ioctl.c index e57724a67..6aef35d1c 100644 --- a/src/nvme/ioctl.c +++ b/src/nvme/ioctl.c @@ -1336,39 +1336,6 @@ int nvme_get_features_iocs_profile(nvme_link_t l, enum nvme_get_features_sel sel return __nvme_get_features(l, NVME_FEAT_FID_IOCS_PROFILE, sel, result); } -int nvme_ns_mgmt(nvme_link_t l, struct nvme_ns_mgmt_args *args) -{ - const size_t size_v1 = sizeof_args(struct nvme_ns_mgmt_args, csi, __u64); - const size_t size_v2 = sizeof_args(struct nvme_ns_mgmt_args, data, __u64); - __u32 cdw10 = NVME_SET(args->sel, NAMESPACE_MGMT_CDW10_SEL); - __u32 cdw11 = NVME_SET(args->csi, NAMESPACE_MGMT_CDW11_CSI); - - if (args->args_size < size_v1 || args->args_size > size_v2) - return -EINVAL; - - struct nvme_passthru_cmd cmd = { - .nsid = args->nsid, - .opcode = nvme_admin_ns_mgmt, - .cdw10 = cdw10, - .cdw11 = cdw11, - .timeout_ms = args->timeout, - }; - - if (args->args_size == size_v2) { - if (args->data) { - cmd.data_len = sizeof(*args->data); - cmd.addr = (__u64)(uintptr_t)args->data; - } - } - else { - if (args->ns) { - cmd.data_len = sizeof(*args->ns); - cmd.addr = (__u64)(uintptr_t)args->ns; - } - } - return nvme_submit_admin_passthru(l, &cmd, args->result); -} - int nvme_ns_attach(nvme_link_t l, struct nvme_ns_attach_args *args) { __u32 cdw10 = NVME_SET(args->sel, NAMESPACE_ATTACH_CDW10_SEL); diff --git a/src/nvme/ioctl.h b/src/nvme/ioctl.h index 7ca6d1e17..6a9e569da 100644 --- a/src/nvme/ioctl.h +++ b/src/nvme/ioctl.h @@ -3123,22 +3123,45 @@ static inline int nvme_format_nvm(nvme_link_t l, __u32 nsid, __u8 lbaf, /** * nvme_ns_mgmt() - Issue a Namespace management command * @l: Link handle - * @args: &struct nvme_ns_mgmt_args Argument structure + * @nsid: Namespace identifier + * @sel: Type of management operation to perform + * @csi: Command Set Identifier + * @data: Host Software Specified Fields + * @result: NVMe command result * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_ns_mgmt(nvme_link_t l, struct nvme_ns_mgmt_args *args); +static inline int nvme_ns_mgmt(nvme_link_t l, __u32 nsid, + enum nvme_ns_mgmt_sel sel, __u8 csi, + struct nvme_ns_mgmt_host_sw_specified *data, + __u32 *result) +{ + __u32 cdw10 = NVME_SET(sel, NAMESPACE_MGMT_CDW10_SEL); + __u32 cdw11 = NVME_SET(csi, NAMESPACE_MGMT_CDW11_CSI); + __u32 len = 0; + + if (data) + len = sizeof(*data); + + struct nvme_passthru_cmd cmd = { + .opcode = nvme_admin_ns_mgmt, + .nsid = nsid, + .addr = (__u64)(uintptr_t)data, + .data_len = len, + .cdw10 = cdw10, + .cdw11 = cdw11, + }; + + return nvme_submit_admin_passthru(l, &cmd, result); +} /** * nvme_ns_mgmt_create() - Create a non attached namespace * @l: Link handle - * @ns: Namespace identification that defines ns creation parameters - * @nsid: On success, set to the namespace id that was created - * @timeout: Override the default timeout to this value in milliseconds; - * set to 0 to use the system default. - * @csi: Command Set Identifier + * @csi: Command Set Identifier * @data: Host Software Specified Fields that defines ns creation parameters + * @nsid: On success, set to the namespace id that was created * * On successful creation, the namespace exists in the subsystem, but is not * attached to any controller. Use the nvme_ns_attach_ctrls() to assign the @@ -3147,56 +3170,12 @@ int nvme_ns_mgmt(nvme_link_t l, struct nvme_ns_mgmt_args *args); * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -static inline int nvme_ns_mgmt_create(nvme_link_t l, struct nvme_id_ns *ns, - __u32 *nsid, __u32 timeout, __u8 csi, - struct nvme_ns_mgmt_host_sw_specified *data) +static inline int nvme_ns_mgmt_create(nvme_link_t l, __u8 csi, + struct nvme_ns_mgmt_host_sw_specified *data, + __u32 *nsid) { - struct nvme_ns_mgmt_args args = { - .result = nsid, - .ns = ns, - .args_size = sizeof(args), - .timeout = timeout, - .nsid = NVME_NSID_NONE, - .sel = NVME_NS_MGMT_SEL_CREATE, - .csi = csi, - .rsvd1 = { 0, }, - .rsvd2 = NULL, - .data = data, - }; - - return nvme_ns_mgmt(l, &args); -} - -/** - * nvme_ns_mgmt_delete_timeout() - Delete a non attached namespace with timeout - * @l: Link handle - * @nsid: Namespace identifier to delete - * @timeout: Override the default timeout to this value in milliseconds; - * set to 0 to use the system default. - * - * It is recommended that a namespace being deleted is not attached to any - * controller. Use the nvme_ns_detach_ctrls() first if the namespace is still - * attached. - * - * Return: 0 on success, the nvme command status if a response was - * received (see &enum nvme_status_field) or a negative error otherwise. - */ -static inline int nvme_ns_mgmt_delete_timeout(nvme_link_t l, __u32 nsid, __u32 timeout) -{ - struct nvme_ns_mgmt_args args = { - .result = NULL, - .ns = NULL, - .args_size = sizeof(args), - .timeout = timeout, - .nsid = nsid, - .sel = NVME_NS_MGMT_SEL_DELETE, - .csi = 0, - .rsvd1 = { 0, }, - .rsvd2 = NULL, - .data = NULL, - }; - - return nvme_ns_mgmt(l, &args); + return nvme_ns_mgmt(l, NVME_NSID_NONE, NVME_NS_MGMT_SEL_CREATE, + csi, data, nsid); } /** @@ -3213,7 +3192,7 @@ static inline int nvme_ns_mgmt_delete_timeout(nvme_link_t l, __u32 nsid, __u32 t */ static inline int nvme_ns_mgmt_delete(nvme_link_t l, __u32 nsid) { - return nvme_ns_mgmt_delete_timeout(l, nsid, 0); + return nvme_ns_mgmt(l, nsid, NVME_NS_MGMT_SEL_DELETE, 0, NULL, NULL); } /** diff --git a/test/ioctl/misc.c b/test/ioctl/misc.c index a399b674b..87314722f 100644 --- a/test/ioctl/misc.c +++ b/test/ioctl/misc.c @@ -46,22 +46,16 @@ static void test_format_nvm(void) static void test_ns_mgmt(void) { struct nvme_ns_mgmt_host_sw_specified expected_data, data = {}; + enum nvme_ns_mgmt_sel sel = NVME_NS_MGMT_SEL_CREATE; + __u32 nsid = TEST_NSID; + __u8 csi = TEST_CSI; __u32 result = 0; - struct nvme_ns_mgmt_args args = { - .result = &result, - .ns = NULL, - .args_size = sizeof(args), - .nsid = TEST_NSID, - .sel = NVME_NS_MGMT_SEL_CREATE, - .csi = TEST_CSI, - .data = &data, - }; struct mock_cmd mock_admin_cmd = { .opcode = nvme_admin_ns_mgmt, - .nsid = TEST_NSID, - .cdw10 = args.sel, - .cdw11 = args.csi << 24, + .nsid = nsid, + .cdw10 = sel, + .cdw11 = csi << 24, .result = 0, .data_len = sizeof(expected_data), .out_data = &expected_data, @@ -71,7 +65,8 @@ static void test_ns_mgmt(void) arbitrary(&expected_data, sizeof(expected_data)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_ns_mgmt(test_link, &args); + err = nvme_ns_mgmt(test_link, TEST_NSID, NVME_NS_MGMT_SEL_CREATE, + TEST_CSI, &data, &result); end_mock_cmds(); check(err == 0, "returned error %d", err); check(result == 0, "returned result %u", result); @@ -81,12 +76,15 @@ static void test_ns_mgmt(void) static void test_ns_mgmt_create(void) { struct nvme_ns_mgmt_host_sw_specified expected_data, data = {}; + enum nvme_ns_mgmt_sel sel = NVME_NS_MGMT_SEL_CREATE; + __u32 nsid = NVME_NSID_NONE; + __u8 csi = NVME_CSI_ZNS; __u32 result = 0; struct mock_cmd mock_admin_cmd = { .opcode = nvme_admin_ns_mgmt, - .nsid = NVME_NSID_NONE, - .cdw10 = NVME_NS_MGMT_SEL_CREATE, - .cdw11 = NVME_CSI_ZNS << 24, + .nsid = nsid, + .cdw10 = sel, + .cdw11 = csi << 24, .result = TEST_NSID, .data_len = sizeof(expected_data), .out_data = &expected_data, @@ -96,8 +94,7 @@ static void test_ns_mgmt_create(void) arbitrary(&expected_data, sizeof(expected_data)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_ns_mgmt_create(test_link, NULL, &result, 0, NVME_CSI_ZNS, - &data); + err = nvme_ns_mgmt_create(test_link, csi, &data, &result); end_mock_cmds(); check(err == 0, "returned error %d", err); check(result == TEST_NSID, "returned result %u", result); diff --git a/test/mi.c b/test/mi.c index 44c92d84c..e0d3e788b 100644 --- a/test/mi.c +++ b/test/mi.c @@ -1418,12 +1418,12 @@ static void test_admin_ns_mgmt_create(struct nvme_mi_ep *ep) link = nvme_mi_init_link(ep, 5); assert(link); - rc = nvme_ns_mgmt_create(link, NULL, &ns, 0, NVME_CSI_NVM, &data); + rc = nvme_ns_mgmt_create(link, NVME_CSI_NVM, &data, &ns); assert(!rc); assert(ns == 0x01020304); data.nsze = cpu_to_le64(42); - rc = nvme_ns_mgmt_create(link, NULL, &ns, 0, NVME_CSI_NVM, &data); + rc = nvme_ns_mgmt_create(link, NVME_CSI_NVM, &data, &ns); assert(rc); } From ba80d268c1a00c64d9e5175e0c1afa39717511ef Mon Sep 17 00:00:00 2001 From: Daniel Wagner Date: Fri, 1 Aug 2025 15:22:24 +0200 Subject: [PATCH 24/66] ioctl: nvme_ns_attach use nvme_passthru_cmd directly Drop struct nvme_ns_attach_args. Signed-off-by: Daniel Wagner --- src/nvme/api-types.h | 18 ----------------- src/nvme/ioctl.c | 19 ------------------ src/nvme/ioctl.h | 47 +++++++++++++++++++++++--------------------- src/nvme/linux.c | 22 +++++++-------------- test/ioctl/misc.c | 17 ++++++---------- 5 files changed, 38 insertions(+), 85 deletions(-) diff --git a/src/nvme/api-types.h b/src/nvme/api-types.h index 46295a24e..4cb23c4e3 100644 --- a/src/nvme/api-types.h +++ b/src/nvme/api-types.h @@ -108,24 +108,6 @@ struct nvme_get_features_args { __u8 uuidx; }; -/** - * struct nvme_ns_attach_args - Arguments for Nvme Namespace Management command - * @result: NVMe command result - * @ctrlist: Controller list to modify attachment state of nsid - * @args_size: Size of &struct nvme_ns_attach_args - * @timeout: Timeout in ms - * @nsid: Namespace ID to execute attach selection - * @sel: Attachment selection, see &enum nvme_ns_attach_sel - */ -struct nvme_ns_attach_args { - __u32 *result; - struct nvme_ctrl_list *ctrlist; - int args_size; - __u32 timeout; - __u32 nsid; - enum nvme_ns_attach_sel sel; -}; - /** * struct nvme_fw_download_args - Arguments for the NVMe Firmware Download command * @args_size: Size of &struct nvme_fw_download_args diff --git a/src/nvme/ioctl.c b/src/nvme/ioctl.c index 6aef35d1c..936166536 100644 --- a/src/nvme/ioctl.c +++ b/src/nvme/ioctl.c @@ -1336,25 +1336,6 @@ int nvme_get_features_iocs_profile(nvme_link_t l, enum nvme_get_features_sel sel return __nvme_get_features(l, NVME_FEAT_FID_IOCS_PROFILE, sel, result); } -int nvme_ns_attach(nvme_link_t l, struct nvme_ns_attach_args *args) -{ - __u32 cdw10 = NVME_SET(args->sel, NAMESPACE_ATTACH_CDW10_SEL); - - struct nvme_passthru_cmd cmd = { - .opcode = nvme_admin_ns_attach, - .nsid = args->nsid, - .cdw10 = cdw10, - .data_len = sizeof(*args->ctrlist), - .addr = (__u64)(uintptr_t)args->ctrlist, - .timeout_ms = args->timeout, - }; - - if (args->args_size < sizeof(*args)) - return -EINVAL; - - return nvme_submit_admin_passthru(l, &cmd, args->result); -} - int nvme_fw_download(nvme_link_t l, struct nvme_fw_download_args *args) { __u32 cdw10 = (args->data_len >> 2) - 1; diff --git a/src/nvme/ioctl.h b/src/nvme/ioctl.h index 6a9e569da..8fa5acd4f 100644 --- a/src/nvme/ioctl.h +++ b/src/nvme/ioctl.h @@ -3198,12 +3198,31 @@ static inline int nvme_ns_mgmt_delete(nvme_link_t l, __u32 nsid) /** * nvme_ns_attach() - Attach or detach namespace to controller(s) * @l: Link handle - * @args: &struct nvme_ns_attach_args Argument structure + * @nsid: Namespace ID to execute attach selection + * @sel: Attachment selection, see &enum nvme_ns_attach_sel + * @ctrlist: Controller list to modify attachment state of nsid + * @result: NVMe command result * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_ns_attach(nvme_link_t l, struct nvme_ns_attach_args *args); +static inline int nvme_ns_attach(nvme_link_t l, __u32 nsid, + enum nvme_ns_attach_sel sel, + struct nvme_ctrl_list *ctrlist, + __u32 *result) +{ + __u32 cdw10 = NVME_SET(sel, NAMESPACE_ATTACH_CDW10_SEL); + + struct nvme_passthru_cmd cmd = { + .opcode = nvme_admin_ns_attach, + .nsid = nsid, + .addr = (__u64)(uintptr_t)ctrlist, + .data_len = sizeof(*ctrlist), + .cdw10 = cdw10, + }; + + return nvme_submit_admin_passthru(l, &cmd, result); +} /** * nvme_ns_attach_ctrls() - Attach namespace to controllers @@ -3217,16 +3236,8 @@ int nvme_ns_attach(nvme_link_t l, struct nvme_ns_attach_args *args); static inline int nvme_ns_attach_ctrls(nvme_link_t l, __u32 nsid, struct nvme_ctrl_list *ctrlist) { - struct nvme_ns_attach_args args = { - .result = NULL, - .ctrlist = ctrlist, - .args_size = sizeof(args), - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .nsid = nsid, - .sel = NVME_NS_ATTACH_SEL_CTRL_ATTACH, - }; - - return nvme_ns_attach(l, &args); + return nvme_ns_attach(l, nsid, NVME_NS_ATTACH_SEL_CTRL_ATTACH, + ctrlist, NULL); } /** @@ -3241,16 +3252,8 @@ static inline int nvme_ns_attach_ctrls(nvme_link_t l, __u32 nsid, static inline int nvme_ns_detach_ctrls(nvme_link_t l, __u32 nsid, struct nvme_ctrl_list *ctrlist) { - struct nvme_ns_attach_args args = { - .result = NULL, - .ctrlist = ctrlist, - .args_size = sizeof(args), - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .nsid = nsid, - .sel = NVME_NS_ATTACH_SEL_CTRL_DEATTACH, - }; - - return nvme_ns_attach(l, &args); + return nvme_ns_attach(l, nsid, NVME_NS_ATTACH_SEL_CTRL_DEATTACH, + ctrlist, NULL); } /** diff --git a/src/nvme/linux.c b/src/nvme/linux.c index 3d058617e..d853c6d7e 100644 --- a/src/nvme/linux.c +++ b/src/nvme/linux.c @@ -406,36 +406,28 @@ int nvme_get_lba_status_log(nvme_link_t l, bool rae, struct nvme_lba_status_log } static int nvme_ns_attachment(nvme_link_t l, __u32 nsid, __u16 num_ctrls, - __u16 *ctrlist, bool attach, __u32 timeout) + __u16 *ctrlist, bool attach) { struct nvme_ctrl_list cntlist = { 0 }; - struct nvme_ns_attach_args args = { - .args_size = sizeof(args), - .nsid = nsid, - .sel = NVME_NS_ATTACH_SEL_CTRL_DEATTACH, - .ctrlist = &cntlist, - .timeout = timeout, - }; + enum nvme_ns_attach_sel sel = NVME_NS_ATTACH_SEL_CTRL_DEATTACH; if (attach) - args.sel = NVME_NS_ATTACH_SEL_CTRL_ATTACH; + sel = NVME_NS_ATTACH_SEL_CTRL_ATTACH; - nvme_init_ctrl_list(args.ctrlist, num_ctrls, ctrlist); - return nvme_ns_attach(l, &args); + nvme_init_ctrl_list(&cntlist, num_ctrls, ctrlist); + return nvme_ns_attach(l, nsid, sel, &cntlist, NULL); } int nvme_namespace_attach_ctrls(nvme_link_t l, __u32 nsid, __u16 num_ctrls, __u16 *ctrlist) { - return nvme_ns_attachment(l, nsid, num_ctrls, ctrlist, true, - NVME_DEFAULT_IOCTL_TIMEOUT); + return nvme_ns_attachment(l, nsid, num_ctrls, ctrlist, true); } int nvme_namespace_detach_ctrls(nvme_link_t l, __u32 nsid, __u16 num_ctrls, __u16 *ctrlist) { - return nvme_ns_attachment(l, nsid, num_ctrls, ctrlist, false, - NVME_DEFAULT_IOCTL_TIMEOUT); + return nvme_ns_attachment(l, nsid, num_ctrls, ctrlist, false); } size_t nvme_get_ana_log_len_from_id_ctrl(const struct nvme_id_ctrl *id_ctrl, diff --git a/test/ioctl/misc.c b/test/ioctl/misc.c index 87314722f..b1db888ef 100644 --- a/test/ioctl/misc.c +++ b/test/ioctl/misc.c @@ -176,20 +176,15 @@ static void test_set_property(void) static void test_ns_attach(void) { - __u32 result; struct nvme_ctrl_list expected_ctrlist, ctrlist; - struct nvme_ns_attach_args args = { - .result = &result, - .ctrlist = &ctrlist, - .args_size = sizeof(args), - .nsid = TEST_NSID, - .sel = NVME_NS_ATTACH_SEL_CTRL_DEATTACH, - }; + enum nvme_ns_attach_sel sel = NVME_NS_ATTACH_SEL_CTRL_DEATTACH; + __u32 nsid = TEST_NSID; + __u32 result; struct mock_cmd mock_admin_cmd = { .opcode = nvme_admin_ns_attach, - .nsid = TEST_NSID, - .cdw10 = NVME_NS_ATTACH_SEL_CTRL_DEATTACH, + .nsid = nsid, + .cdw10 = sel, .data_len = sizeof(expected_ctrlist), .out_data = &expected_ctrlist, }; @@ -198,7 +193,7 @@ static void test_ns_attach(void) arbitrary(&expected_ctrlist, sizeof(expected_ctrlist)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_ns_attach(test_link, &args); + err = nvme_ns_attach(test_link, nsid, sel, &ctrlist, &result); end_mock_cmds(); check(err == 0, "returned error %d", err); check(result == 0, "returned result %u", result); From e58de5912b1ca15a8a855d2cf6afe28e3b2ca98d Mon Sep 17 00:00:00 2001 From: Daniel Wagner Date: Fri, 1 Aug 2025 15:47:19 +0200 Subject: [PATCH 25/66] ioctl: nvme_ns_download use nvme_passthru_cmd directly Drop struct nvme_fw_download_args. Signed-off-by: Daniel Wagner --- src/libnvme.map | 1 - src/nvme/api-types.h | 18 ------------------ src/nvme/ioctl.c | 26 -------------------------- src/nvme/ioctl.h | 28 ++++++++++++++++++++++++++-- src/nvme/linux.c | 22 +++++++--------------- test/ioctl/misc.c | 18 ++++++------------ test/mi.c | 39 ++++++++++++++++++--------------------- 7 files changed, 57 insertions(+), 95 deletions(-) diff --git a/src/libnvme.map b/src/libnvme.map index 65bd8942e..fa33d1d3c 100644 --- a/src/libnvme.map +++ b/src/libnvme.map @@ -82,7 +82,6 @@ LIBNVME_2_0 { nvme_free_subsystem; nvme_free_uri; nvme_fw_commit; - nvme_fw_download; nvme_fw_download_seq; nvme_gen_dhchap_key; nvme_generate_tls_key_identity; diff --git a/src/nvme/api-types.h b/src/nvme/api-types.h index 4cb23c4e3..97e853867 100644 --- a/src/nvme/api-types.h +++ b/src/nvme/api-types.h @@ -108,24 +108,6 @@ struct nvme_get_features_args { __u8 uuidx; }; -/** - * struct nvme_fw_download_args - Arguments for the NVMe Firmware Download command - * @args_size: Size of &struct nvme_fw_download_args - * @result: The command completion result from CQE dword0 - * @timeout: Timeout in ms - * @offset: Offset in the firmware data - * @data: Userspace address of the firmware data - * @data_len: Length of data in this command in bytes - */ -struct nvme_fw_download_args { - __u32 *result; - void *data; - int args_size; - __u32 timeout; - __u32 offset; - __u32 data_len; -}; - /** * struct nvme_fw_commit_args - Arguments for the NVMe Firmware Commit command * @args_size: Size of &struct nvme_fw_commit_args diff --git a/src/nvme/ioctl.c b/src/nvme/ioctl.c index 936166536..339c94ad9 100644 --- a/src/nvme/ioctl.c +++ b/src/nvme/ioctl.c @@ -1336,32 +1336,6 @@ int nvme_get_features_iocs_profile(nvme_link_t l, enum nvme_get_features_sel sel return __nvme_get_features(l, NVME_FEAT_FID_IOCS_PROFILE, sel, result); } -int nvme_fw_download(nvme_link_t l, struct nvme_fw_download_args *args) -{ - __u32 cdw10 = (args->data_len >> 2) - 1; - __u32 cdw11 = args->offset >> 2; - - struct nvme_passthru_cmd cmd = { - .opcode = nvme_admin_fw_download, - .cdw10 = cdw10, - .cdw11 = cdw11, - .data_len = args->data_len, - .addr = (__u64)(uintptr_t)args->data, - .timeout_ms = args->timeout, - }; - - if (args->args_size < sizeof(*args)) - return -EINVAL; - - if ((args->data_len & 0x3) || (!args->data_len)) - return -EINVAL; - - if (args->offset & 0x3) - return -EINVAL; - - return nvme_submit_admin_passthru(l, &cmd, args->result); -} - int nvme_fw_commit(nvme_link_t l, struct nvme_fw_commit_args *args) { __u32 cdw10 = NVME_SET(args->slot, FW_COMMIT_CDW10_FS) | diff --git a/src/nvme/ioctl.h b/src/nvme/ioctl.h index 8fa5acd4f..01139acf3 100644 --- a/src/nvme/ioctl.h +++ b/src/nvme/ioctl.h @@ -3260,7 +3260,10 @@ static inline int nvme_ns_detach_ctrls(nvme_link_t l, __u32 nsid, * nvme_fw_download() - Download part or all of a firmware image to the * controller * @l: Link handle - * @args: &struct nvme_fw_download_args argument structure + * @data: Userspace address of the firmware data + * @data_len: Length of data in this command in bytes + * @offset: Offset in the firmware data + * @result: The command completion result from CQE dword0 * * The Firmware Image Download command downloads all or a portion of an image * for a future update to the controller. The Firmware Image Download command @@ -3278,7 +3281,28 @@ static inline int nvme_ns_detach_ctrls(nvme_link_t l, __u32 nsid, * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_fw_download(nvme_link_t l, struct nvme_fw_download_args *args); +static inline int nvme_fw_download(nvme_link_t l, void *data, __u32 data_len, + __u32 offset, __u32 *result) +{ + __u32 cdw10 = (data_len >> 2) - 1; + __u32 cdw11 = offset >> 2; + + struct nvme_passthru_cmd cmd = { + .opcode = nvme_admin_fw_download, + .addr = (__u64)(uintptr_t)data, + .data_len = data_len, + .cdw10 = cdw10, + .cdw11 = cdw11, + }; + + if ((data_len & 0x3) || (!data_len)) + return -EINVAL; + + if (offset & 0x3) + return -EINVAL; + + return nvme_submit_admin_passthru(l, &cmd, result); +} /** * nvme_fw_commit() - Commit firmware using the specified action diff --git a/src/nvme/linux.c b/src/nvme/linux.c index d853c6d7e..f330b84d2 100644 --- a/src/nvme/linux.c +++ b/src/nvme/linux.c @@ -187,28 +187,20 @@ const char *nvme_link_get_name(nvme_link_t l) int nvme_fw_download_seq(nvme_link_t l, __u32 size, __u32 xfer, __u32 offset, void *buf) { - int err = 0; - struct nvme_fw_download_args args = { - .args_size = sizeof(args), - .offset = offset, - .data_len = xfer, - .data = buf, - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .result = NULL, - }; + int err; while (size > 0) { - args.data_len = MIN(xfer, size); - err = nvme_fw_download(l, &args); + err = nvme_fw_download(l, buf, MIN(xfer, size), + offset, NULL); if (err) - break; + return err; - args.data += xfer; + buf += xfer; size -= xfer; - args.offset += xfer; + offset += xfer; } - return err; + return 0; } int nvme_get_telemetry_max(nvme_link_t l, enum nvme_telemetry_da *da, size_t *data_tx) diff --git a/test/ioctl/misc.c b/test/ioctl/misc.c index b1db888ef..23f2db430 100644 --- a/test/ioctl/misc.c +++ b/test/ioctl/misc.c @@ -247,20 +247,14 @@ static void test_fw_download(void) { __u32 result = 0; __u8 expected_data[8], data[8]; - - struct nvme_fw_download_args args = { - .result = &result, - .data = &expected_data, - .args_size = sizeof(args), - .offset = 120, - .data_len = sizeof(expected_data), - }; + __u32 data_len = sizeof(expected_data); + __u32 offset = 120; struct mock_cmd mock_admin_cmd = { .opcode = nvme_admin_fw_download, - .cdw10 = (args.data_len >> 2) - 1, - .cdw11 = args.offset >> 2, - .data_len = args.data_len, + .cdw10 = (data_len >> 2) - 1, + .cdw11 = offset >> 2, + .data_len = data_len, .in_data = &data, }; @@ -269,7 +263,7 @@ static void test_fw_download(void) arbitrary(&expected_data, sizeof(expected_data)); memcpy(&data, &expected_data, sizeof(expected_data)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_fw_download(test_link, &args); + err = nvme_fw_download(test_link, expected_data, data_len, offset, &result); end_mock_cmds(); check(err == 0, "returned error %d", err); check(result == 0, "returned result %u", result); diff --git a/test/mi.c b/test/mi.c index e0d3e788b..b16c76d55 100644 --- a/test/mi.c +++ b/test/mi.c @@ -1567,7 +1567,6 @@ static int test_admin_fw_download_cb(struct nvme_mi_ep *ep, static void test_admin_fw_download(struct nvme_mi_ep *ep) { - struct nvme_fw_download_args args; struct fw_download_info info; unsigned char fw[4096]; nvme_link_t link; @@ -1579,8 +1578,6 @@ static void test_admin_fw_download(struct nvme_mi_ep *ep) info.offset = 0; info.len = 0; info.data = fw; - args.data = fw; - args.args_size = sizeof(args); test_set_transport_callback(ep, test_admin_fw_download_cb, &info); @@ -1588,39 +1585,39 @@ static void test_admin_fw_download(struct nvme_mi_ep *ep) assert(link); /* invalid (zero) len */ - args.data_len = info.len = 1; - args.offset = info.offset = 0; - rc = nvme_fw_download(link, &args); + info.len = 1; + info.offset = 0; + rc = nvme_fw_download(link, fw, info.len, info.offset, NULL); assert(rc); /* invalid (unaligned) len */ - args.data_len = info.len = 1; - args.offset = info.offset = 0; - rc = nvme_fw_download(link, &args); + info.len = 1; + info.offset = 0; + rc = nvme_fw_download(link, fw, info.len, info.offset, NULL); assert(rc); /* invalid offset */ - args.data_len = info.len = 4; - args.offset = info.offset = 1; - rc = nvme_fw_download(link, &args); + info.len = 4; + info.offset = 1; + rc = nvme_fw_download(link, fw, info.len, info.offset, NULL); assert(rc); /* smallest len */ - args.data_len = info.len = 4; - args.offset = info.offset = 0; - rc = nvme_fw_download(link, &args); + info.len = 4; + info.offset = 0; + rc = nvme_fw_download(link, fw, info.len, info.offset, NULL); assert(!rc); /* largest len */ - args.data_len = info.len = 4096; - args.offset = info.offset = 0; - rc = nvme_fw_download(link, &args); + info.len = 4096; + info.offset = 0; + rc = nvme_fw_download(link, fw, info.len, info.offset, NULL); assert(!rc); /* offset value */ - args.data_len = info.len = 4096; - args.offset = info.offset = 4096; - rc = nvme_fw_download(link, &args); + info.len = 4096; + info.offset = 4096; + rc = nvme_fw_download(link, fw, info.len, info.offset, NULL); assert(!rc); } From df17c258dbf50cbef5be726529400f4676fea204 Mon Sep 17 00:00:00 2001 From: Daniel Wagner Date: Fri, 1 Aug 2025 16:01:31 +0200 Subject: [PATCH 26/66] ioctl: nvme_fw_commit use nvme_passthru_cmd directly Drop struct nvme_fw_commit_args. Signed-off-by: Daniel Wagner --- src/libnvme.map | 1 - src/nvme/api-types.h | 18 ------------------ src/nvme/ioctl.c | 18 ------------------ src/nvme/ioctl.h | 20 ++++++++++++++++++-- test/ioctl/misc.c | 15 +++++---------- test/mi.c | 28 ++++++++++++---------------- 6 files changed, 35 insertions(+), 65 deletions(-) diff --git a/src/libnvme.map b/src/libnvme.map index fa33d1d3c..5a023b1b7 100644 --- a/src/libnvme.map +++ b/src/libnvme.map @@ -81,7 +81,6 @@ LIBNVME_2_0 { nvme_free_root; nvme_free_subsystem; nvme_free_uri; - nvme_fw_commit; nvme_fw_download_seq; nvme_gen_dhchap_key; nvme_generate_tls_key_identity; diff --git a/src/nvme/api-types.h b/src/nvme/api-types.h index 97e853867..c9f997622 100644 --- a/src/nvme/api-types.h +++ b/src/nvme/api-types.h @@ -108,24 +108,6 @@ struct nvme_get_features_args { __u8 uuidx; }; -/** - * struct nvme_fw_commit_args - Arguments for the NVMe Firmware Commit command - * @args_size: Size of &struct nvme_fw_commit_args - * @action: Action to use for the firmware image, see &enum nvme_fw_commit_ca - * @timeout: Timeout in ms - * @result: The command completion result from CQE dword0 - * @slot: Firmware slot to commit the downloaded image - * @bpid: Set to true to select the boot partition id - */ -struct nvme_fw_commit_args { - __u32 *result; - int args_size; - __u32 timeout; - enum nvme_fw_commit_ca action; - __u8 slot; - bool bpid; -}; - /** * struct nvme_security_send_args - Arguments for the NVMe Security Send command * @result: The command completion result from CQE dword0 diff --git a/src/nvme/ioctl.c b/src/nvme/ioctl.c index 339c94ad9..e30a7e077 100644 --- a/src/nvme/ioctl.c +++ b/src/nvme/ioctl.c @@ -1336,24 +1336,6 @@ int nvme_get_features_iocs_profile(nvme_link_t l, enum nvme_get_features_sel sel return __nvme_get_features(l, NVME_FEAT_FID_IOCS_PROFILE, sel, result); } -int nvme_fw_commit(nvme_link_t l, struct nvme_fw_commit_args *args) -{ - __u32 cdw10 = NVME_SET(args->slot, FW_COMMIT_CDW10_FS) | - NVME_SET(args->action, FW_COMMIT_CDW10_CA) | - NVME_SET(args->bpid, FW_COMMIT_CDW10_BPID); - - struct nvme_passthru_cmd cmd = { - .opcode = nvme_admin_fw_commit, - .cdw10 = cdw10, - .timeout_ms = args->timeout, - }; - - if (args->args_size < sizeof(*args)) - return -EINVAL; - - return nvme_submit_admin_passthru(l, &cmd, args->result); -} - int nvme_security_send(nvme_link_t l, struct nvme_security_send_args *args) { __u32 cdw10 = NVME_SET(args->secp, SECURITY_SECP) | diff --git a/src/nvme/ioctl.h b/src/nvme/ioctl.h index 01139acf3..236a1fd11 100644 --- a/src/nvme/ioctl.h +++ b/src/nvme/ioctl.h @@ -3307,7 +3307,10 @@ static inline int nvme_fw_download(nvme_link_t l, void *data, __u32 data_len, /** * nvme_fw_commit() - Commit firmware using the specified action * @l: Link handle - * @args: &struct nvme_fw_commit_args argument structure + * @fs: Firmware slot to commit the downloaded image + * @ca: Action to use for the firmware image, see &enum nvme_fw_commit_ca + * @bpid: Set to true to select the boot partition id + * @result: The command completion result from CQE dword0 * * The Firmware Commit command modifies the firmware image or Boot Partitions. * @@ -3316,7 +3319,20 @@ static inline int nvme_fw_download(nvme_link_t l, void *data, __u32 data_len, * status response may specify additional reset actions required to complete * the commit process. */ -int nvme_fw_commit(nvme_link_t l, struct nvme_fw_commit_args *args); +static inline int nvme_fw_commit(nvme_link_t l, __u8 fs, enum nvme_fw_commit_ca ca, + bool bpid, __u32 *result) +{ + __u32 cdw10 = NVME_SET(fs, FW_COMMIT_CDW10_FS) | + NVME_SET(ca, FW_COMMIT_CDW10_CA) | + NVME_SET(bpid, FW_COMMIT_CDW10_BPID); + + struct nvme_passthru_cmd cmd = { + .opcode = nvme_admin_fw_commit, + .cdw10 = cdw10, + }; + + return nvme_submit_admin_passthru(l, &cmd, result); +} /** * nvme_security_send() - Security Send command diff --git a/test/ioctl/misc.c b/test/ioctl/misc.c index 23f2db430..08cb359b3 100644 --- a/test/ioctl/misc.c +++ b/test/ioctl/misc.c @@ -271,25 +271,20 @@ static void test_fw_download(void) static void test_fw_commit(void) { + enum nvme_fw_commit_ca action = NVME_FW_COMMIT_CA_REPLACE_AND_ACTIVATE_IMMEDIATE; __u32 result = 0; - - struct nvme_fw_commit_args args = { - .result = &result, - .args_size = sizeof(args), - .action = NVME_FW_COMMIT_CA_REPLACE_AND_ACTIVATE_IMMEDIATE, - .slot = 0xf, - .bpid = true, - }; + __u8 slot = 0xf; + bool bpid = true; struct mock_cmd mock_admin_cmd = { .opcode = nvme_admin_fw_commit, - .cdw10 = (!!args.bpid << 31) | (args.action << 3) | args.slot, + .cdw10 = (!!bpid << 31) | (action << 3) | slot, }; int err; set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_fw_commit(test_link, &args); + err = nvme_fw_commit(test_link, slot, action, bpid, &result); end_mock_cmds(); check(err == 0, "returned error %d", err); check(result == 0, "returned result %u", result); diff --git a/test/mi.c b/test/mi.c index b16c76d55..d30139b2a 100644 --- a/test/mi.c +++ b/test/mi.c @@ -1654,38 +1654,34 @@ static int test_admin_fw_commit_cb(struct nvme_mi_ep *ep, static void test_admin_fw_commit(struct nvme_mi_ep *ep) { - struct nvme_fw_commit_args args; struct fw_commit_info info; nvme_link_t link; int rc; - args.args_size = sizeof(args); - info.bpid = args.bpid = 0; - test_set_transport_callback(ep, test_admin_fw_commit_cb, &info); link = nvme_mi_init_link(ep, 5); assert(link); /* all zeros */ - info.bpid = args.bpid = 0; - info.slot = args.slot = 0; - info.action = args.action = 0; - rc = nvme_fw_commit(link, &args); + info.bpid = 0; + info.slot = 0; + info.action = 0; + rc = nvme_fw_commit(link, info.slot, info.action, info.bpid, NULL); assert(!rc); /* all ones */ - info.bpid = args.bpid = 1; - info.slot = args.slot = 0x7; - info.action = args.action = 0x7; - rc = nvme_fw_commit(link, &args); + info.bpid = 1; + info.slot = 0x7; + info.action = 0x7; + rc = nvme_fw_commit(link, info.slot, info.action, info.bpid, NULL); assert(!rc); /* correct fields */ - info.bpid = args.bpid = 1; - info.slot = args.slot = 2; - info.action = args.action = 3; - rc = nvme_fw_commit(link, &args); + info.bpid = 1; + info.slot = 2; + info.action = 3; + rc = nvme_fw_commit(link, info.slot, info.action, info.bpid, NULL); assert(!rc); } From 67d41a28548b8ec3bca3457c7d900e63e162c573 Mon Sep 17 00:00:00 2001 From: Daniel Wagner Date: Fri, 1 Aug 2025 16:25:24 +0200 Subject: [PATCH 27/66] ioctl: nvme_security_send use nvme_passthru_cmd directly Drop struct nvme_security_send_args. [dennis: merge spsp0 and spsp1 into one argument] Signed-off-by: Dennis Maisenbacher Signed-off-by: Daniel Wagner --- src/nvme/api-types.h | 28 ---------------------------- src/nvme/ioctl.c | 24 ------------------------ src/nvme/ioctl.h | 32 ++++++++++++++++++++++++++++++-- test/ioctl/misc.c | 31 ++++++++++++------------------- 4 files changed, 42 insertions(+), 73 deletions(-) diff --git a/src/nvme/api-types.h b/src/nvme/api-types.h index c9f997622..9ae8e3b28 100644 --- a/src/nvme/api-types.h +++ b/src/nvme/api-types.h @@ -108,34 +108,6 @@ struct nvme_get_features_args { __u8 uuidx; }; -/** - * struct nvme_security_send_args - Arguments for the NVMe Security Send command - * @result: The command completion result from CQE dword0 - * @data: Security data payload to send - * @args_size: Size of &struct nvme_security_send_args - * @timeout: Timeout in ms - * @nsid: Namespace ID to issue security command on - * @tl: Protocol specific transfer length - * @data_len: Data length of the payload in bytes - * @nssf: NVMe Security Specific field - * @spsp0: Security Protocol Specific field - * @spsp1: Security Protocol Specific field - * @secp: Security Protocol - */ -struct nvme_security_send_args { - __u32 *result; - void *data; - int args_size; - __u32 timeout; - __u32 nsid; - __u32 tl; - __u32 data_len; - __u8 nssf; - __u8 spsp0; - __u8 spsp1; - __u8 secp; -}; - /** * struct nvme_security_receive_args - Arguments for the NVMe Security Receive command * @result: The command completion result from CQE dword0 diff --git a/src/nvme/ioctl.c b/src/nvme/ioctl.c index e30a7e077..ef8515c22 100644 --- a/src/nvme/ioctl.c +++ b/src/nvme/ioctl.c @@ -1336,30 +1336,6 @@ int nvme_get_features_iocs_profile(nvme_link_t l, enum nvme_get_features_sel sel return __nvme_get_features(l, NVME_FEAT_FID_IOCS_PROFILE, sel, result); } -int nvme_security_send(nvme_link_t l, struct nvme_security_send_args *args) -{ - __u32 cdw10 = NVME_SET(args->secp, SECURITY_SECP) | - NVME_SET(args->spsp0, SECURITY_SPSP0) | - NVME_SET(args->spsp1, SECURITY_SPSP1) | - NVME_SET(args->nssf, SECURITY_NSSF); - __u32 cdw11 = args->tl; - - struct nvme_passthru_cmd cmd = { - .opcode = nvme_admin_security_send, - .nsid = args->nsid, - .cdw10 = cdw10, - .cdw11 = cdw11, - .data_len = args->data_len, - .addr = (__u64)(uintptr_t)args->data, - .timeout_ms = args->timeout, - }; - - if (args->args_size < sizeof(*args)) - return -EINVAL; - - return nvme_submit_admin_passthru(l, &cmd, args->result); -} - int nvme_security_receive(nvme_link_t l, struct nvme_security_receive_args *args) { __u32 cdw10 = NVME_SET(args->secp, SECURITY_SECP) | diff --git a/src/nvme/ioctl.h b/src/nvme/ioctl.h index 236a1fd11..39e41135c 100644 --- a/src/nvme/ioctl.h +++ b/src/nvme/ioctl.h @@ -3337,7 +3337,14 @@ static inline int nvme_fw_commit(nvme_link_t l, __u8 fs, enum nvme_fw_commit_ca /** * nvme_security_send() - Security Send command * @l: Link handle - * @args: &struct nvme_security_send argument structure + * @nsid: Namespace ID to issue security command on + * @nssf: NVMe Security Specific field + * @spsp: Security Protocol Specific field + * @secp: Security Protocol + * @tl: Protocol specific transfer length + * @data: Security data payload to send + * @data_len: Data length of the payload in bytes + * @result: The command completion result from CQE dword0 * * The Security Send command transfers security protocol data to the * controller. The data structure transferred to the controller as part of this @@ -3351,7 +3358,28 @@ static inline int nvme_fw_commit(nvme_link_t l, __u8 fs, enum nvme_fw_commit_ca * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_security_send(nvme_link_t l, struct nvme_security_send_args *args); +static inline int nvme_security_send(nvme_link_t l, __u32 nsid,__u8 nssf, + __u16 spsp, __u8 secp, __u32 tl, + void *data, __u32 data_len, + __u32 *result) +{ + __u32 cdw10 = NVME_SET(secp, SECURITY_SECP) | + NVME_SET(spsp, SECURITY_SPSP0) | + NVME_SET((spsp >> 8), SECURITY_SPSP1) | + NVME_SET(nssf, SECURITY_NSSF); + __u32 cdw11 = tl; + + struct nvme_passthru_cmd cmd = { + .opcode = nvme_admin_security_send, + .nsid = nsid, + .addr = (__u64)(uintptr_t)data, + .data_len = data_len, + .cdw10 = cdw10, + .cdw11 = cdw11, + }; + + return nvme_submit_admin_passthru(l, &cmd, result); +} /** * nvme_security_receive() - Security Receive command diff --git a/test/ioctl/misc.c b/test/ioctl/misc.c index 08cb359b3..c8ca37c73 100644 --- a/test/ioctl/misc.c +++ b/test/ioctl/misc.c @@ -293,29 +293,21 @@ static void test_fw_commit(void) static void test_security_send(void) { __u8 expected_data[8], data[8]; + __u32 data_len = sizeof(expected_data); + __u32 nsid = TEST_NSID; + __u32 tl = 0xffff; __u32 result = 0; - - struct nvme_security_send_args args = { - .result = &result, - .data = &expected_data, - .args_size = sizeof(args), - .nsid = TEST_NSID, - .tl = 0xffff, - .data_len = sizeof(expected_data), - .nssf = 0x1, - .spsp0 = 0x1, - .spsp1 = 0x1, - .secp = 0xE9, - }; + __u8 nssf = 0x1; + __u16 spsp = 0x0101; + __u8 secp = 0xE9; struct mock_cmd mock_admin_cmd = { .opcode = nvme_admin_security_send, .nsid = TEST_NSID, - .cdw10 = args.nssf | (args.spsp0 << 8) | (args.spsp1 << 16) | - (args.secp << 24), - .cdw11 = args.tl, - .data_len = args.data_len, - .in_data = &data, + .cdw10 = nssf | (spsp << 8) | (secp << 24), + .cdw11 = tl, + .data_len = data_len, + .in_data = &expected_data, }; int err; @@ -323,7 +315,8 @@ static void test_security_send(void) arbitrary(&expected_data, sizeof(expected_data)); memcpy(&data, &expected_data, sizeof(expected_data)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_security_send(test_link, &args); + err = nvme_security_send(test_link, nsid, nssf, spsp, secp, tl, + &expected_data, data_len, &result); end_mock_cmds(); check(err == 0, "returned error %d", err); check(result == 0, "returned result %u", result); From 7d7d67d6fcf2985325b6b9a107a5e286182f9ae0 Mon Sep 17 00:00:00 2001 From: Dennis Maisenbacher Date: Wed, 30 Jul 2025 15:21:52 +0200 Subject: [PATCH 28/66] ioctl: nvme_set_features use nvme_passthru_cmd directly Drop struct nvme_set_features_args. Signed-off-by: Dennis Maisenbacher [wagi: remove libnvme.map entries reorder fid and sv argument] Signed-off-by: Daniel Wagner nvme_set_features: fix argument order Signed-off-by: Daniel Wagner --- src/libnvme.map | 28 --- src/nvme/api-types.h | 32 --- src/nvme/ioctl.c | 337 ----------------------------- src/nvme/ioctl.h | 475 ++++++++++++++++++++++++++++++----------- test/ioctl/features.c | 87 ++++---- test/ioctl/meson.build | 2 +- test/meson.build | 1 + test/mi.c | 13 +- 8 files changed, 398 insertions(+), 577 deletions(-) diff --git a/src/libnvme.map b/src/libnvme.map index 5a023b1b7..ac222d2f8 100644 --- a/src/libnvme.map +++ b/src/libnvme.map @@ -299,34 +299,6 @@ LIBNVME_2_0 { nvme_security_receive; nvme_security_send; nvme_set_debug; - nvme_set_features; - nvme_set_features_arbitration; - nvme_set_features_async_event; - nvme_set_features_auto_pst; - nvme_set_features_endurance_evt_cfg; - nvme_set_features_err_recovery; - nvme_set_features_hctm; - nvme_set_features_host_behavior; - nvme_set_features_host_id; - nvme_set_features_iocs_profile; - nvme_set_features_irq_coalesce; - nvme_set_features_irq_config; - nvme_set_features_lba_range; - nvme_set_features_lba_sts_interval; - nvme_set_features_nopsc; - nvme_set_features_plm_config; - nvme_set_features_plm_window; - nvme_set_features_power_mgmt; - nvme_set_features_resv_mask; - nvme_set_features_resv_persist; - nvme_set_features_rrl; - nvme_set_features_sanitize; - nvme_set_features_sw_progress; - nvme_set_features_temp_thresh; - nvme_set_features_timestamp; - nvme_set_features_volatile_wc; - nvme_set_features_write_atomic; - nvme_set_features_write_protect; nvme_set_keyring; nvme_set_property; nvme_set_root; diff --git a/src/nvme/api-types.h b/src/nvme/api-types.h index 9ae8e3b28..d5a8dc6a5 100644 --- a/src/nvme/api-types.h +++ b/src/nvme/api-types.h @@ -49,38 +49,6 @@ void nvme_free_root(nvme_root_t r); * be set to zero. */ -/** - * struct nvme_set_features_args - Arguments for the NVMe Admin Set Feature command - * @result: The command completion result from CQE dword0 - * @data: User address of feature data, if applicable - * @args_size: Size of &struct nvme_set_features_args - * @timeout: Timeout in ms - * @nsid: Namespace ID, if applicable - * @cdw11: Value to set the feature to - * @cdw12: Feature specific command dword12 field - * @cdw13: Feature specific command dword13 field - * @cdw15: Feature specific command dword15 field - * @data_len: Length of feature data, if applicable, in bytes - * @save: Save value across power states - * @uuidx: UUID Index for differentiating vendor specific encoding - * @fid: Feature identifier - */ -struct nvme_set_features_args { - __u32 *result; - void *data; - int args_size; - __u32 timeout; - __u32 nsid; - __u32 cdw11; - __u32 cdw12; - __u32 cdw13; - __u32 cdw15; - __u32 data_len; - bool save; - __u8 uuidx; - __u8 fid; -}; - /** * struct nvme_get_features_args - Arguments for the NVMe Admin Get Feature command * @args_size: Size of &struct nvme_get_features_args diff --git a/src/nvme/ioctl.c b/src/nvme/ioctl.c index ef8515c22..9795297e5 100644 --- a/src/nvme/ioctl.c +++ b/src/nvme/ioctl.c @@ -606,325 +606,6 @@ int nvme_get_ana_log_atomic(nvme_link_t l, bool rae, bool rgo, return -EAGAIN; } -int nvme_set_features(nvme_link_t l, struct nvme_set_features_args *args) -{ - __u32 cdw10 = NVME_SET(args->fid, FEATURES_CDW10_FID) | - NVME_SET(!!args->save, SET_FEATURES_CDW10_SAVE); - __u32 cdw14 = NVME_SET(args->uuidx, FEATURES_CDW14_UUID); - - struct nvme_passthru_cmd cmd = { - .opcode = nvme_admin_set_features, - .nsid = args->nsid, - .addr = (__u64)(uintptr_t)args->data, - .data_len = args->data_len, - .cdw10 = cdw10, - .cdw11 = args->cdw11, - .cdw12 = args->cdw12, - .cdw13 = args->cdw13, - .cdw14 = cdw14, - .cdw15 = args->cdw15, - .timeout_ms = args->timeout, - }; - if (args->args_size < sizeof(*args)) - return -EINVAL; - - return nvme_submit_admin_passthru(l, &cmd, args->result); -} - -static int __nvme_set_features(nvme_link_t l, __u8 fid, __u32 cdw11, bool save, - __u32 *result) -{ - struct nvme_set_features_args args = { - .args_size = sizeof(args), - .fid = fid, - .nsid = NVME_NSID_NONE, - .cdw11 = cdw11, - .cdw12 = 0, - .save = save, - .uuidx = NVME_UUID_NONE, - .cdw15 = 0, - .data_len = 0, - .data = NULL, - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .result = result, - }; - return nvme_set_features(l, &args); -} - -int nvme_set_features_arbitration(nvme_link_t l, __u8 ab, __u8 lpw, __u8 mpw, - __u8 hpw, bool save, __u32 *result) -{ - __u32 value = NVME_SET(ab, FEAT_ARBITRATION_BURST) | - NVME_SET(lpw, FEAT_ARBITRATION_LPW) | - NVME_SET(mpw, FEAT_ARBITRATION_MPW) | - NVME_SET(hpw, FEAT_ARBITRATION_HPW); - - return __nvme_set_features(l, NVME_FEAT_FID_ARBITRATION, value, save, - result); -} - -int nvme_set_features_power_mgmt(nvme_link_t l, __u8 ps, __u8 wh, bool save, - __u32 *result) -{ - __u32 value = NVME_SET(ps, FEAT_PWRMGMT_PS) | - NVME_SET(wh, FEAT_PWRMGMT_WH); - - return __nvme_set_features(l, NVME_FEAT_FID_POWER_MGMT, value, save, - result); -} - -int nvme_set_features_lba_range(nvme_link_t l, __u32 nsid, __u8 nr_ranges, bool save, - struct nvme_lba_range_type *data, __u32 *result) -{ - return nvme_set_features_data( - l, NVME_FEAT_FID_LBA_RANGE, nsid, nr_ranges - 1, save, - sizeof(*data), data, result); -} - -int nvme_set_features_temp_thresh(nvme_link_t l, __u16 tmpth, __u8 tmpsel, - enum nvme_feat_tmpthresh_thsel thsel, __u8 tmpthh, - bool save, __u32 *result) -{ - __u32 value = NVME_SET(tmpth, FEAT_TT_TMPTH) | - NVME_SET(tmpsel, FEAT_TT_TMPSEL) | - NVME_SET(thsel, FEAT_TT_THSEL) | - NVME_SET(tmpthh, FEAT_TT_TMPTHH); - - return __nvme_set_features(l, NVME_FEAT_FID_TEMP_THRESH, value, save, - result); -} - -int nvme_set_features_err_recovery(nvme_link_t l, __u32 nsid, __u16 tler, bool dulbe, - bool save, __u32 *result) -{ - __u32 value = NVME_SET(tler, FEAT_ERROR_RECOVERY_TLER) | - NVME_SET(!!dulbe, FEAT_ERROR_RECOVERY_DULBE); - - return nvme_set_features_simple( - l, NVME_FEAT_FID_ERR_RECOVERY, nsid, value, save, result); -} - -int nvme_set_features_volatile_wc(nvme_link_t l, bool wce, bool save, __u32 *result) -{ - __u32 value = NVME_SET(!!wce, FEAT_VWC_WCE); - - return __nvme_set_features(l, NVME_FEAT_FID_VOLATILE_WC, value, save, - result); -} - -int nvme_set_features_irq_coalesce(nvme_link_t l, __u8 thr, __u8 time, bool save, - __u32 *result) -{ - __u32 value = NVME_SET(thr, FEAT_IRQC_THR) | - NVME_SET(time, FEAT_IRQC_TIME); - - return __nvme_set_features(l, NVME_FEAT_FID_IRQ_COALESCE, value, save, - result); -} - -int nvme_set_features_irq_config(nvme_link_t l, __u16 iv, bool cd, bool save, - __u32 *result) -{ - __u32 value = NVME_SET(iv, FEAT_ICFG_IV) | - NVME_SET(!!cd, FEAT_ICFG_CD); - - return __nvme_set_features(l, NVME_FEAT_FID_IRQ_CONFIG, value, save, - result); -} - -int nvme_set_features_write_atomic(nvme_link_t l, bool dn, bool save, __u32 *result) -{ - __u32 value = NVME_SET(!!dn, FEAT_WA_DN); - - return __nvme_set_features(l, NVME_FEAT_FID_WRITE_ATOMIC, value, save, - result); -} - -int nvme_set_features_async_event(nvme_link_t l, __u32 events, - bool save, __u32 *result) -{ - return __nvme_set_features(l, NVME_FEAT_FID_ASYNC_EVENT, events, save, - result); -} - -int nvme_set_features_auto_pst(nvme_link_t l, bool apste, bool save, - struct nvme_feat_auto_pst *apst, __u32 *result) -{ - return nvme_set_features_data(l, NVME_FEAT_FID_AUTO_PST, - NVME_NSID_NONE, NVME_SET(!!apste, FEAT_APST_APSTE), save, - sizeof(*apst), apst, result); -} - -int nvme_set_features_timestamp(nvme_link_t l, bool save, __u64 timestamp) -{ - __le64 t = cpu_to_le64(timestamp); - struct nvme_timestamp ts = {}; - memcpy(ts.timestamp, &t, sizeof(ts.timestamp)); - - return nvme_set_features_data(l, NVME_FEAT_FID_TIMESTAMP, - NVME_NSID_NONE, 0, save, sizeof(ts), &ts, NULL); -} - -int nvme_set_features_hctm(nvme_link_t l, __u16 tmt2, __u16 tmt1, - bool save, __u32 *result) -{ - __u32 value = NVME_SET(tmt2, FEAT_HCTM_TMT2) | - NVME_SET(tmt1, FEAT_HCTM_TMT1); - - return __nvme_set_features(l, NVME_FEAT_FID_HCTM, value, save, - result); -} - -int nvme_set_features_nopsc(nvme_link_t l, bool noppme, bool save, __u32 *result) -{ - __u32 value = NVME_SET(noppme, FEAT_NOPS_NOPPME); - - return __nvme_set_features(l, NVME_FEAT_FID_NOPSC, value, save, - result); -} - -int nvme_set_features_rrl(nvme_link_t l, __u8 rrl, __u16 nvmsetid, - bool save, __u32 *result) -{ - struct nvme_set_features_args args = { - .args_size = sizeof(args), - .fid = NVME_FEAT_FID_RRL, - .nsid = NVME_NSID_NONE, - .cdw11 = nvmsetid, - .cdw12 = rrl, - .save = save, - .uuidx = NVME_UUID_NONE, - .cdw15 = 0, - .data_len = 0, - .data = NULL, - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .result = result, - }; - - return nvme_set_features(l, &args); -} - -int nvme_set_features_plm_config(nvme_link_t l, bool plm, __u16 nvmsetid, bool save, - struct nvme_plm_config *data, __u32 *result) -{ - struct nvme_set_features_args args = { - .args_size = sizeof(args), - .fid = NVME_FEAT_FID_PLM_CONFIG, - .nsid = NVME_NSID_NONE, - .cdw11 = nvmsetid, - .cdw12 = !!plm, - .save = save, - .uuidx = NVME_UUID_NONE, - .cdw15 = 0, - .data_len = sizeof(*data), - .data = data, - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .result = result, - }; - - return nvme_set_features(l, &args); -} - -int nvme_set_features_plm_window(nvme_link_t l, enum nvme_feat_plm_window_select sel, - __u16 nvmsetid, bool save, __u32 *result) -{ - __u32 cdw12 = NVME_SET(sel, FEAT_PLMW_WS); - struct nvme_set_features_args args = { - .args_size = sizeof(args), - .fid = NVME_FEAT_FID_PLM_WINDOW, - .nsid = NVME_NSID_NONE, - .cdw11 = nvmsetid, - .cdw12 = cdw12, - .save = save, - .uuidx = NVME_UUID_NONE, - .cdw15 = 0, - .data_len = 0, - .data = NULL, - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .result = result, - }; - - return nvme_set_features(l, &args); -} - -int nvme_set_features_lba_sts_interval(nvme_link_t l, __u16 lsiri, __u16 lsipi, - bool save, __u32 *result) -{ - __u32 value = NVME_SET(lsiri, FEAT_LBAS_LSIRI) | - NVME_SET(lsipi, FEAT_LBAS_LSIPI); - - return __nvme_set_features(l, NVME_FEAT_FID_LBA_STS_INTERVAL, value, - save, result); -} - -int nvme_set_features_host_behavior(nvme_link_t l, bool save, - struct nvme_feat_host_behavior *data) -{ - return nvme_set_features_data(l, NVME_FEAT_FID_HOST_BEHAVIOR, - NVME_NSID_NONE, 0, false, sizeof(*data), data, NULL); -} - -int nvme_set_features_sanitize(nvme_link_t l, bool nodrm, bool save, __u32 *result) -{ - return __nvme_set_features(l, NVME_FEAT_FID_SANITIZE, !!nodrm, save, - result); -} - -int nvme_set_features_endurance_evt_cfg(nvme_link_t l, __u16 endgid, __u8 egwarn, - bool save, __u32 *result) -{ - __u32 value = endgid | egwarn << 16; - - return __nvme_set_features(l, NVME_FEAT_FID_ENDURANCE_EVT_CFG, value, - save, result); -} - -int nvme_set_features_sw_progress(nvme_link_t l, __u8 pbslc, bool save, - __u32 *result) -{ - return __nvme_set_features(l, NVME_FEAT_FID_SW_PROGRESS, pbslc, save, - result); -} - -int nvme_set_features_host_id(nvme_link_t l, bool exhid, bool save, __u8 *hostid) -{ - __u32 len = exhid ? 16 : 8; - __u32 value = !!exhid; - - return nvme_set_features_data(l, NVME_FEAT_FID_HOST_ID, - NVME_NSID_NONE, value, save, len, hostid, NULL); -} - -int nvme_set_features_resv_mask(nvme_link_t l, __u32 nsid, __u32 mask, bool save, - __u32 *result) -{ - return nvme_set_features_simple( - l, NVME_FEAT_FID_RESV_MASK, nsid, mask, save, result); -} - -int nvme_set_features_resv_persist(nvme_link_t l, __u32 nsid, bool ptpl, bool save, - __u32 *result) -{ - return nvme_set_features_simple( - l, NVME_FEAT_FID_RESV_PERSIST, nsid, !!ptpl, save, result); -} - -int nvme_set_features_write_protect(nvme_link_t l, __u32 nsid, - enum nvme_feat_nswpcfg_state state, - bool save, __u32 *result) -{ - return nvme_set_features_simple( - l, NVME_FEAT_FID_WRITE_PROTECT, nsid, state, false, result); -} - -int nvme_set_features_iocs_profile(nvme_link_t l, __u16 iocsi, bool save) -{ - __u32 value = NVME_SET(iocsi, FEAT_IOCSP_IOCSCI); - - return __nvme_set_features(l, NVME_FEAT_FID_IOCS_PROFILE, value, - save, NULL); -} - int nvme_get_features(nvme_link_t l, struct nvme_get_features_args *args) { __u32 cdw10 = NVME_SET(args->fid, FEATURES_CDW10_FID) | @@ -2166,24 +1847,6 @@ int nvme_lm_migration_recv(nvme_link_t l, struct nvme_lm_migration_recv_args *ar return nvme_submit_admin_passthru(l, &cmd, args->result); } -int nvme_lm_set_features_ctrl_data_queue(nvme_link_t l, __u16 cdqid, __u32 hp, __u32 tpt, bool etpt, - __u32 *result) -{ - struct nvme_set_features_args args = { - .args_size = sizeof(args), - .fid = NVME_FEAT_FID_CTRL_DATA_QUEUE, - .nsid = NVME_NSID_NONE, - .cdw11 = cdqid | NVME_SET(etpt, LM_CTRL_DATA_QUEUE_ETPT), - .cdw12 = hp, - .cdw13 = tpt, - .save = false, - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .result = result, - }; - - return nvme_set_features(l, &args); -} - int nvme_lm_get_features_ctrl_data_queue(nvme_link_t l, __u16 cdqid, struct nvme_lm_ctrl_data_queue_fid_data *data, __u32 *result) diff --git a/src/nvme/ioctl.h b/src/nvme/ioctl.h index 39e41135c..9ed09a08a 100644 --- a/src/nvme/ioctl.h +++ b/src/nvme/ioctl.h @@ -10,8 +10,10 @@ #ifndef _LIBNVME_IOCTL_H #define _LIBNVME_IOCTL_H +#include #include #include +#include #include #include @@ -2208,312 +2210,478 @@ static inline int nvme_get_log_lockdown(nvme_link_t l, /** * nvme_set_features() - Set a feature attribute * @l: Link handle - * @args: &struct nvme_set_features_args argument structure + * @nsid: Namespace ID, if applicable + * @fid: Feature identifier + * @sv: Save value across power states + * @cdw11: Value to set the feature to + * @cdw12: Feature specific command dword12 field + * @cdw13: Feature specific command dword13 field + * @cdw15: Feature specific command dword15 field + * @uidx: UUID Index for differentiating vendor specific encoding + * @data: User address of feature data, if applicable + * @data_len: Length of feature data, if applicable, in bytes + * @result: The command completion result from CQE dword0 * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_set_features(nvme_link_t l, struct nvme_set_features_args *args); +static inline int nvme_set_features(nvme_link_t l, __u32 nsid, __u8 fid, + bool sv, __u32 cdw11, __u32 cdw12, + __u32 cdw13, __u32 cdw15, + __u8 uidx, void *data, + __u32 data_len, __u32 *result) +{ + __u32 cdw10 = NVME_SET(fid, FEATURES_CDW10_FID) | + NVME_SET(sv, SET_FEATURES_CDW10_SAVE); + __u32 cdw14 = NVME_SET(uidx, FEATURES_CDW14_UUID); + + struct nvme_passthru_cmd cmd = { + .opcode = nvme_admin_set_features, + .nsid = nsid, + .addr = (__u64)(uintptr_t)data, + .data_len = data_len, + .cdw10 = cdw10, + .cdw11 = cdw11, + .cdw12 = cdw12, + .cdw13 = cdw13, + .cdw14 = cdw14, + .cdw15 = cdw15, + .timeout_ms = NVME_DEFAULT_IOCTL_TIMEOUT, + }; + + return nvme_submit_admin_passthru(l, &cmd, result); +} /** - * nvme_set_features_data() - Helper function for @nvme_set_features() + * __nvme_set_features() - Internal helper function for @nvme_set_features() * @l: Link handle * @fid: Feature identifier + * @sv: Save value across power states + * @cdw11: Value to set the feature to + * @result: The command completion result from CQE dword0 + * + * Return: The nvme command status if a response was received (see + * &enum nvme_status_field) or -1 with errno set otherwise. + */ +static int __nvme_set_features(nvme_link_t l, __u8 fid, bool sv, __u32 cdw11, + __u32 *result) +{ + return nvme_set_features(l, NVME_NSID_NONE, fid, sv, cdw11, 0, 0, 0, + NVME_UUID_NONE, NULL, 0, result); +} + +/** + * nvme_set_features_data() - Helper function for @nvme_set_features() + * @l: Link handle * @nsid: Namespace ID, if applicable + * @fid: Feature identifier + * @sv: Save value across power states * @cdw11: Value to set the feature to - * @save: Save value across power states - * @data_len: Length of feature data, if applicable, in bytes * @data: User address of feature data, if applicable + * @data_len: Length of feature data, if applicable, in bytes * @result: The command completion result from CQE dword0 * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -static inline int nvme_set_features_data(nvme_link_t l, __u8 fid, __u32 nsid, - __u32 cdw11, bool save, __u32 data_len, void *data, - __u32 *result) +static inline int nvme_set_features_data(nvme_link_t l, __u32 nsid, __u8 fid, + bool sv, __u32 cdw11, void *data, + __u32 data_len, __u32 *result) { - struct nvme_set_features_args args = { - .result = result, - .data = data, - .args_size = sizeof(args), - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .nsid = nsid, - .cdw11 = cdw11, - .cdw12 = 0, - .cdw13 = 0, - .cdw15 = 0, - .data_len = data_len, - .save = save, - .uuidx = NVME_UUID_NONE, - .fid = fid, - }; - return nvme_set_features(l, &args); + return nvme_set_features(l, nsid, fid, sv, cdw11, 0, 0, 0, + NVME_UUID_NONE, data, data_len, result); } /** * nvme_set_features_simple() - Helper function for @nvme_set_features() * @l: Link handle - * @fid: Feature identifier * @nsid: Namespace ID, if applicable + * @fid: Feature identifier + * @sv: Save value across power states * @cdw11: Value to set the feature to - * @save: Save value across power states * @result: The command completion result from CQE dword0 * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -static inline int nvme_set_features_simple(nvme_link_t l, __u8 fid, __u32 nsid, - __u32 cdw11, bool save, __u32 *result) +static inline int nvme_set_features_simple(nvme_link_t l, __u32 nsid, + __u8 fid, bool sv, __u32 cdw11, + __u32 *result) { - return nvme_set_features_data(l, fid, nsid, cdw11, save, 0, NULL, - result); + return nvme_set_features_data(l, nsid, fid, sv, cdw11, NULL, 0, + result); } /** * nvme_set_features_arbitration() - Set arbitration features * @l: Link handle + * @sv: Save value across power states * @ab: Arbitration Burst * @lpw: Low Priority Weight * @mpw: Medium Priority Weight * @hpw: High Priority Weight - * @save: Save value across power states * @result: The command completion result from CQE dword0 * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_set_features_arbitration(nvme_link_t l, __u8 ab, __u8 lpw, __u8 mpw, - __u8 hpw, bool save, __u32 *result); +static inline int nvme_set_features_arbitration(nvme_link_t l, bool sv, __u8 ab, + __u8 lpw, __u8 mpw, __u8 hpw, + __u32 *result) +{ + __u32 cdw11 = NVME_SET(ab, FEAT_ARBITRATION_BURST) | + NVME_SET(lpw, FEAT_ARBITRATION_LPW) | + NVME_SET(mpw, FEAT_ARBITRATION_MPW) | + NVME_SET(hpw, FEAT_ARBITRATION_HPW); + + return __nvme_set_features(l, NVME_FEAT_FID_ARBITRATION, sv, cdw11, + result); +} /** * nvme_set_features_power_mgmt() - Set power management feature * @l: Link handle + * @sv: Save value across power states * @ps: Power State * @wh: Workload Hint - * @save: Save value across power states * @result: The command completion result from CQE dword0 * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_set_features_power_mgmt(nvme_link_t l, __u8 ps, __u8 wh, bool save, - __u32 *result); +static inline int nvme_set_features_power_mgmt(nvme_link_t l, bool sv, + __u8 ps, __u8 wh, + __u32 *result) +{ + __u32 cdw11 = NVME_SET(ps, FEAT_PWRMGMT_PS) | + NVME_SET(wh, FEAT_PWRMGMT_WH); + + return __nvme_set_features(l, NVME_FEAT_FID_POWER_MGMT, sv, cdw11, + result); +} /** * nvme_set_features_lba_range() - Set LBA range feature * @l: Link handle * @nsid: Namespace ID - * @nr_ranges: Number of ranges in @data - * @save: Save value across power states + * @sv: Save value across power states + * @num: Number of ranges in @data * @data: User address of feature data * @result: The command completion result from CQE dword0 * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_set_features_lba_range(nvme_link_t l, __u32 nsid, __u8 nr_ranges, bool save, - struct nvme_lba_range_type *data, __u32 *result); +static inline int nvme_set_features_lba_range(nvme_link_t l, __u32 nsid, + bool sv, __u8 num, + struct nvme_lba_range_type *data, + __u32 *result) +{ + return nvme_set_features_data(l, nsid, + NVME_FEAT_FID_LBA_RANGE, sv, + num - 1, data, + sizeof(*data), result); +} /** * nvme_set_features_temp_thresh() - Set temperature threshold feature * @l: Link handle + * @sv: Save value across power states * @tmpth: Temperature Threshold * @tmpsel: Threshold Temperature Select * @thsel: Threshold Type Select * @tmpthh: Temperature Threshold Hysteresis - * @save: Save value across power states * @result: The command completion result from CQE dword0 * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_set_features_temp_thresh(nvme_link_t l, __u16 tmpth, __u8 tmpsel, - enum nvme_feat_tmpthresh_thsel thsel, __u8 tmpthh, - bool save, __u32 *result); +static inline int nvme_set_features_temp_thresh(nvme_link_t l, bool sv, __u16 tmpth, + __u8 tmpsel, + enum nvme_feat_tmpthresh_thsel thsel, + __u8 tmpthh, __u32 *result) +{ + __u32 cdw11 = NVME_SET(tmpth, FEAT_TT_TMPTH) | + NVME_SET(tmpsel, FEAT_TT_TMPSEL) | + NVME_SET(thsel, FEAT_TT_THSEL) | + NVME_SET(tmpthh, FEAT_TT_TMPTHH); + + return __nvme_set_features(l, NVME_FEAT_FID_TEMP_THRESH, sv, cdw11, + result); +} /** * nvme_set_features_err_recovery() - Set error recovery feature * @l: Link handle * @nsid: Namespace ID + * @sv: Save value across power states * @tler: Time-limited error recovery value * @dulbe: Deallocated or Unwritten Logical Block Error Enable - * @save: Save value across power states * @result: The command completion result from CQE dword0 * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_set_features_err_recovery(nvme_link_t l, __u32 nsid, __u16 tler, - bool dulbe, bool save, __u32 *result); +static inline int nvme_set_features_err_recovery(nvme_link_t l, __u32 nsid, bool sv, + __u16 tler, bool dulbe, __u32 *result) +{ + __u32 cdw11 = NVME_SET(tler, FEAT_ERROR_RECOVERY_TLER) | + NVME_SET(dulbe, FEAT_ERROR_RECOVERY_DULBE); + + return nvme_set_features_simple(l, nsid, NVME_FEAT_FID_ERR_RECOVERY, sv, + cdw11, result); +} /** * nvme_set_features_volatile_wc() - Set volatile write cache feature * @l: Link handle + * @sv: Save value across power states * @wce: Write cache enable - * @save: Save value across power states * @result: The command completion result from CQE dword0 * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_set_features_volatile_wc(nvme_link_t l, bool wce, bool save, - __u32 *result); +static inline int nvme_set_features_volatile_wc(nvme_link_t l, bool sv, bool wce, + __u32 *result) +{ + __u32 cdw11 = NVME_SET(wce, FEAT_VWC_WCE); + return __nvme_set_features(l, NVME_FEAT_FID_VOLATILE_WC, sv, cdw11, + result); +} /** * nvme_set_features_irq_coalesce() - Set IRQ coalesce feature * @l: Link handle + * @sv: Save value across power states * @thr: Aggregation Threshold * @time: Aggregation Time - * @save: Save value across power states * @result: The command completion result from CQE dword0 * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_set_features_irq_coalesce(nvme_link_t l, __u8 thr, __u8 time, - bool save, __u32 *result); +static inline int nvme_set_features_irq_coalesce(nvme_link_t l, bool sv, + __u8 thr, __u8 time, + __u32 *result) +{ + __u32 cdw11 = NVME_SET(thr, FEAT_IRQC_THR) | + NVME_SET(time, FEAT_IRQC_TIME); + + return __nvme_set_features(l, NVME_FEAT_FID_IRQ_COALESCE, sv, cdw11, + result); +} /** * nvme_set_features_irq_config() - Set IRQ config feature * @l: Link handle + * @sv: Save value across power states * @iv: Interrupt Vector * @cd: Coalescing Disable - * @save: Save value across power states * @result: The command completion result from CQE dword0 * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_set_features_irq_config(nvme_link_t l, __u16 iv, bool cd, bool save, - __u32 *result); +static inline int nvme_set_features_irq_config(nvme_link_t l, bool sv, __u16 iv, + bool cd, __u32 *result) +{ + __u32 cdw11 = NVME_SET(iv, FEAT_ICFG_IV) | + NVME_SET(cd, FEAT_ICFG_CD); + + return __nvme_set_features(l, NVME_FEAT_FID_IRQ_CONFIG, sv, cdw11, + result); +} /** * nvme_set_features_write_atomic() - Set write atomic feature * @l: Link handle + * @sv: Save value across power states * @dn: Disable Normal - * @save: Save value across power states * @result: The command completion result from CQE dword0 * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_set_features_write_atomic(nvme_link_t l, bool dn, bool save, - __u32 *result); +static inline int nvme_set_features_write_atomic(nvme_link_t l, bool sv, + bool dn, __u32 *result) +{ + __u32 cdw11 = NVME_SET(dn, FEAT_WA_DN); + + return __nvme_set_features(l, NVME_FEAT_FID_WRITE_ATOMIC, sv, cdw11, + result); +} /** * nvme_set_features_async_event() - Set asynchronous event feature * @l: Link handle + * @sv: Save value across power states * @events: Events to enable - * @save: Save value across power states * @result: The command completion result from CQE dword0 * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_set_features_async_event(nvme_link_t l, __u32 events, bool save, - __u32 *result); +static inline int nvme_set_features_async_event(nvme_link_t l, bool sv, + __u32 events, __u32 *result) +{ + return __nvme_set_features(l, NVME_FEAT_FID_ASYNC_EVENT, sv, events, + result); +} /** * nvme_set_features_auto_pst() - Set autonomous power state feature * @l: Link handle + * @sv: Save value across power states * @apste: Autonomous Power State Transition Enable * @apst: Autonomous Power State Transition - * @save: Save value across power states * @result: The command completion result from CQE dword0 * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_set_features_auto_pst(nvme_link_t l, bool apste, bool save, - struct nvme_feat_auto_pst *apst, - __u32 *result); +static inline int nvme_set_features_auto_pst(nvme_link_t l, bool sv, bool apste, + struct nvme_feat_auto_pst *apst, + __u32 *result) +{ + __u32 cdw11 = NVME_SET(apste, FEAT_APST_APSTE); + + return nvme_set_features_data(l, NVME_NSID_NONE, + NVME_FEAT_FID_AUTO_PST, sv, + cdw11, apst, + sizeof(*apst), result); +} /** * nvme_set_features_timestamp() - Set timestamp feature * @l: Link handle - * @save: Save value across power states - * @timestamp: The current timestamp value to assign to this feature + * @sv: Save value across power states + * @tstmp: The current timestamp value to assign to this feature * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_set_features_timestamp(nvme_link_t l, bool save, __u64 timestamp); +static inline int nvme_set_features_timestamp(nvme_link_t l, __u64 tstmp, bool sv) +{ + __le64 t = htole64(tstmp); + struct nvme_timestamp ts = {}; + + memcpy(ts.timestamp, &t, sizeof(ts.timestamp)); + return nvme_set_features_data(l, NVME_NSID_NONE, + NVME_FEAT_FID_TIMESTAMP, sv, + 0, &ts, sizeof(ts), NULL); +} /** * nvme_set_features_hctm() - Set thermal management feature * @l: Link handle + * @sv: Save value across power states * @tmt2: Thermal Management Temperature 2 * @tmt1: Thermal Management Temperature 1 - * @save: Save value across power states * @result: The command completion result from CQE dword0 * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_set_features_hctm(nvme_link_t l, __u16 tmt2, __u16 tmt1, bool save, - __u32 *result); +static inline int nvme_set_features_hctm(nvme_link_t l, bool sv, + __u16 tmt2, __u16 tmt1, + __u32 *result) +{ + __u32 cdw11 = NVME_SET(tmt2, FEAT_HCTM_TMT2) | + NVME_SET(tmt1, FEAT_HCTM_TMT1); + + return __nvme_set_features(l, NVME_FEAT_FID_HCTM, sv, cdw11, + result); +} /** * nvme_set_features_nopsc() - Set non-operational power state feature * @l: Link handle + * @sv: Save value across power states * @noppme: Non-Operational Power State Permissive Mode Enable - * @save: Save value across power states * @result: The command completion result from CQE dword0 * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_set_features_nopsc(nvme_link_t l, bool noppme, bool save, __u32 *result); +static inline int nvme_set_features_nopsc(nvme_link_t l, bool sv, + bool noppme, __u32 *result) +{ + __u32 cdw11 = NVME_SET(noppme, FEAT_NOPS_NOPPME); + + return __nvme_set_features(l, NVME_FEAT_FID_NOPSC, sv, cdw11, + result); +} /** * nvme_set_features_rrl() - Set read recovery level feature * @l: Link handle - * @rrl: Read recovery level setting + * @sv: Save value across power states * @nvmsetid: NVM set id - * @save: Save value across power states + * @rrl: Read recovery level setting * @result: The command completion result from CQE dword0 * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_set_features_rrl(nvme_link_t l, __u8 rrl, __u16 nvmsetid, bool save, - __u32 *result); +static inline int nvme_set_features_rrl(nvme_link_t l, bool sv, __u16 nvmsetid, + __u8 rrl, __u32 *result) +{ + return nvme_set_features(l, NVME_NSID_NONE, + NVME_FEAT_FID_RRL, sv, + nvmsetid, rrl, 0, 0, + NVME_UUID_NONE, NULL, 0, + result); +} /** * nvme_set_features_plm_config() - Set predictable latency feature * @l: Link handle - * @enable: Predictable Latency Enable + * @sv: Save value across power states * @nvmsetid: NVM Set Identifier - * @save: Save value across power states + * @lpe: Predictable Latency Enable * @data: Pointer to structure nvme_plm_config * @result: The command completion result from CQE dword0 * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_set_features_plm_config(nvme_link_t l, bool enable, __u16 nvmsetid, - bool save, struct nvme_plm_config *data, - __u32 *result); +static inline int nvme_set_features_plm_config(nvme_link_t l, bool sv, __u16 nvmsetid, + bool lpe, struct nvme_plm_config *data, + __u32 *result) +{ + return nvme_set_features(l, NVME_NSID_NONE, + NVME_FEAT_FID_PLM_CONFIG, sv, + nvmsetid, lpe, 0, 0, + NVME_UUID_NONE, data, sizeof(*data), + result); +} /** * nvme_set_features_plm_window() - Set window select feature * @l: Link handle - * @sel: Window Select + * @sv: Save value across power states * @nvmsetid: NVM Set Identifier - * @save: Save value across power states + * @wsel: Window Select * @result: The command completion result from CQE dword0 * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_set_features_plm_window(nvme_link_t l, enum nvme_feat_plm_window_select sel, - __u16 nvmsetid, bool save, __u32 *result); +static inline int nvme_set_features_plm_window(nvme_link_t l, bool sv, __u16 nvmsetid, + enum nvme_feat_plm_window_select wsel, + __u32 *result) +{ + return nvme_set_features(l, NVME_NSID_NONE, + NVME_FEAT_FID_PLM_WINDOW, sv, + nvmsetid, NVME_SET(wsel, FEAT_PLMW_WS), 0, 0, + NVME_UUID_NONE, NULL, 0, result); +} /** * nvme_set_features_lba_sts_interval() - Set LBA status information feature * @l: Link handle - * @save: Save value across power states + * @sv: Save value across power states * @lsiri: LBA Status Information Report Interval * @lsipi: LBA Status Information Poll Interval * @result: The command completion result from CQE dword0 @@ -2521,125 +2689,184 @@ int nvme_set_features_plm_window(nvme_link_t l, enum nvme_feat_plm_window_select * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_set_features_lba_sts_interval(nvme_link_t l, __u16 lsiri, __u16 lsipi, - bool save, __u32 *result); +static inline int nvme_set_features_lba_sts_interval(nvme_link_t l, bool sv, + __u16 lsiri, __u16 lsipi, + __u32 *result) +{ + __u32 cdw11 = NVME_SET(lsiri, FEAT_LBAS_LSIRI) | + NVME_SET(lsipi, FEAT_LBAS_LSIPI); + + return __nvme_set_features(l, NVME_FEAT_FID_LBA_STS_INTERVAL, sv, + cdw11, result); +} /** * nvme_set_features_host_behavior() - Set host behavior feature * @l: Link handle - * @save: Save value across power states + * @sv: Save value across power states * @data: Pointer to structure nvme_feat_host_behavior * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_set_features_host_behavior(nvme_link_t l, bool save, - struct nvme_feat_host_behavior *data); +static inline int nvme_set_features_host_behavior(nvme_link_t l, bool sv, + struct nvme_feat_host_behavior *data) +{ + return nvme_set_features_data(l, NVME_NSID_NONE, + NVME_FEAT_FID_HOST_BEHAVIOR, sv, + 0, data, sizeof(*data), NULL); +} /** * nvme_set_features_sanitize() - Set sanitize feature * @l: Link handle + * @sv: Save value across power states * @nodrm: No-Deallocate Response Mode - * @save: Save value across power states * @result: The command completion result from CQE dword0 * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_set_features_sanitize(nvme_link_t l, bool nodrm, bool save, __u32 *result); +static inline int nvme_set_features_sanitize(nvme_link_t l, bool sv, bool nodrm, + __u32 *result) +{ + return __nvme_set_features(l, NVME_FEAT_FID_SANITIZE, sv, nodrm, + result); +} /** * nvme_set_features_endurance_evt_cfg() - Set endurance event config feature * @l: Link handle + * @sv: Save value across power states * @endgid: Endurance Group Identifier - * @egwarn: Flags to enable warning, see &enum nvme_eg_critical_warning_flags - * @save: Save value across power states + * @egcw: Flags to enable warning, see &enum nvme_eg_critical_warning_flags * @result: The command completion result from CQE dword0 * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_set_features_endurance_evt_cfg(nvme_link_t l, __u16 endgid, __u8 egwarn, - bool save, __u32 *result); +static inline int nvme_set_features_endurance_evt_cfg(nvme_link_t l, bool sv, + __u16 endgid, __u8 egcw, + __u32 *result) +{ + __u32 cdw11 = endgid | egcw << 16; + + return __nvme_set_features(l, NVME_FEAT_FID_ENDURANCE_EVT_CFG, sv, + cdw11, result); +} /** * nvme_set_features_sw_progress() - Set pre-boot software load count feature * @l: Link handle + * @sv: Save value across power states * @pbslc: Pre-boot Software Load Count - * @save: Save value across power states * @result: The command completion result from CQE dword0 * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_set_features_sw_progress(nvme_link_t l, __u8 pbslc, bool save, - __u32 *result); +static inline int nvme_set_features_sw_progress(nvme_link_t l, bool sv, __u8 pbslc, + __u32 *result) +{ + return __nvme_set_features(l, NVME_FEAT_FID_SW_PROGRESS, sv, pbslc, + result); +} /** * nvme_set_features_host_id() - Set enable extended host identifiers feature * @l: Link handle + * @sv: Save value across power states * @exhid: Enable Extended Host Identifier - * @save: Save value across power states * @hostid: Host ID to set * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_set_features_host_id(nvme_link_t l, bool exhid, bool save, __u8 *hostid); +static inline int nvme_set_features_host_id(nvme_link_t l, bool sv, bool exhid, + __u8 *hostid) +{ + __u32 len = exhid ? 16 : 8; + __u32 cdw11 = exhid; + + return nvme_set_features_data(l, NVME_NSID_NONE, NVME_FEAT_FID_HOST_ID, + sv, cdw11, hostid, len, NULL); +} /** * nvme_set_features_resv_mask() - Set reservation notification mask feature * @l: Link handle * @nsid: Namespace ID + * @sv: Save value across power states * @mask: Reservation Notification Mask Field - * @save: Save value across power states * @result: The command completion result from CQE dword0 * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_set_features_resv_mask(nvme_link_t l, __u32 nsid, __u32 mask, bool save, - __u32 *result); +static inline int nvme_set_features_resv_mask(nvme_link_t l, __u32 nsid, bool sv, + __u32 mask, __u32 *result) +{ + return nvme_set_features_simple(l, nsid, NVME_FEAT_FID_RESV_MASK, + sv, mask, result); +} /** * nvme_set_features_resv_persist() - Set persist through power loss feature * @l: Link handle * @nsid: Namespace ID + * @sv: Save value across power states * @ptpl: Persist Through Power Loss - * @save: Save value across power states * @result: The command completion result from CQE dword0 * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_set_features_resv_persist(nvme_link_t l, __u32 nsid, bool ptpl, bool save, - __u32 *result); +static inline int nvme_set_features_resv_persist(nvme_link_t l, __u32 nsid, bool sv, + bool ptpl, __u32 *result) +{ + return nvme_set_features_simple(l, nsid, + NVME_FEAT_FID_RESV_PERSIST, sv, + ptpl, result); +} /** * nvme_set_features_write_protect() - Set write protect feature * @l: Link handle * @nsid: Namespace ID - * @state: Write Protection State - * @save: Save value across power states + * @sv: Save value across power states + * @wps: Write Protection State * @result: The command completion result from CQE dword0 * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_set_features_write_protect(nvme_link_t l, __u32 nsid, - enum nvme_feat_nswpcfg_state state, - bool save, __u32 *result); +static inline int nvme_set_features_write_protect(nvme_link_t l, __u32 nsid, + bool sv, + enum nvme_feat_nswpcfg_state wps, + __u32 *result) +{ + return nvme_set_features_simple(l, nsid, + NVME_FEAT_FID_WRITE_PROTECT, sv, + wps, result); +} /** * nvme_set_features_iocs_profile() - Set I/O command set profile feature * @l: Link handle - * @iocsi: I/O Command Set Combination Index - * @save: Save value across power states + * @sv: Save value across power states + * @iocsci: I/O Command Set Combination Index * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_set_features_iocs_profile(nvme_link_t l, __u16 iocsi, bool save); +static inline int nvme_set_features_iocs_profile(nvme_link_t l, bool sv, + __u16 iocsci) +{ + __u32 cdw11 = NVME_SET(iocsci, FEAT_IOCSP_IOCSCI); + + return __nvme_set_features(l, NVME_FEAT_FID_IOCS_PROFILE, + sv, cdw11, NULL); +} /** * nvme_get_features() - Retrieve a feature attribute @@ -4129,8 +4356,16 @@ int nvme_lm_migration_recv(nvme_link_t l, struct nvme_lm_migration_recv_args *ar * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_lm_set_features_ctrl_data_queue(nvme_link_t l, __u16 cdqid, __u32 hp, __u32 tpt, bool etpt, - __u32 *result); +static inline int nvme_lm_set_features_ctrl_data_queue(nvme_link_t l, __u16 cdqid, __u32 hp, + __u32 tpt, bool etpt, __u32 *result) +{ + __u32 cdw11 = cdqid | NVME_SET(etpt, LM_CTRL_DATA_QUEUE_ETPT); + + return nvme_set_features(l, NVME_NSID_NONE, + NVME_FEAT_FID_CTRL_DATA_QUEUE, false, + cdw11, hp, tpt, 0, + NVME_UUID_NONE, NULL, 0, result); +} /** * nvme_lm_get_features_ctrl_data_queue - Get Controller Data Queue feature diff --git a/test/ioctl/features.c b/test/ioctl/features.c index 40aacc738..53bc053d0 100644 --- a/test/ioctl/features.c +++ b/test/ioctl/features.c @@ -7,6 +7,7 @@ #include "mock.h" #include "util.h" +#include #define TEST_FD 0xFD #define TEST_TIMEOUT 1234 @@ -28,21 +29,6 @@ static void test_set_features(void) { uint32_t result = 0; uint8_t data[256]; - struct nvme_set_features_args args = { - .result = &result, - .data = data, - .args_size = sizeof(args), - .timeout = TEST_TIMEOUT, - .nsid = TEST_NSID, - .cdw11 = TEST_CDW11, - .cdw12 = TEST_CDW12, - .cdw13 = TEST_CDW13, - .cdw15 = TEST_CDW15, - .data_len = sizeof(data), - .save = true, - .uuidx = TEST_UUIDX, - .fid = TEST_FID, - }; struct mock_cmd mock_admin_cmd = { .opcode = nvme_admin_set_features, .nsid = TEST_NSID, @@ -55,14 +41,15 @@ static void test_set_features(void) .cdw13 = TEST_CDW13, .cdw14 = TEST_UUIDX, .cdw15 = TEST_CDW15, - .timeout_ms = TEST_TIMEOUT, .result = TEST_RESULT, }; int err; arbitrary(data, sizeof(data)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_set_features(test_link, &args); + err = nvme_set_features(test_link, TEST_NSID, TEST_FID, true, TEST_CDW11, TEST_CDW12, TEST_CDW13, + TEST_CDW15, TEST_UUIDX, data, sizeof(data), + &result); end_mock_cmds(); check(err == 0, "set features returned error %d", err); check(result == TEST_RESULT, @@ -126,8 +113,8 @@ static void test_set_features_data(void) arbitrary(data, sizeof(data)); set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_set_features_data( - test_link, TEST_FID, TEST_NSID, TEST_CDW11, false, - sizeof(data), data, &result); + test_link, TEST_NSID, TEST_FID, false, TEST_CDW11, + data, sizeof(data), &result); end_mock_cmds(); check(err == 0, "set features returned error %d", err); check(result == TEST_RESULT, @@ -174,7 +161,7 @@ static void test_set_features_simple(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_set_features_simple( - test_link, TEST_FID, TEST_NSID, TEST_CDW11, true, &result); + test_link, TEST_NSID, TEST_FID, true, TEST_CDW11, &result); end_mock_cmds(); check(err == 0, "set features returned error %d", err); check(result == TEST_RESULT, @@ -214,7 +201,7 @@ static void test_set_arbitration(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_set_features_arbitration( - test_link, AB, LPW, MPW, HPW, false, &result); + test_link, false, AB, LPW, MPW, HPW, &result); end_mock_cmds(); check(err == 0, "set features returned error %d", err); check(result == TEST_RESULT, @@ -253,7 +240,7 @@ static void test_set_power_mgmt(void) int err; set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_set_features_power_mgmt(test_link, PS, WH, true, &result); + err = nvme_set_features_power_mgmt(test_link, true, PS, WH, &result); end_mock_cmds(); check(err == 0, "set features returned error %d", err); check(result == TEST_RESULT, @@ -297,7 +284,7 @@ static void test_set_lba_range(void) arbitrary(&range_types, sizeof(range_types)); set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_set_features_lba_range( - test_link, TEST_NSID, NUM, false, &range_types, &result); + test_link, TEST_NSID, false, NUM, &range_types, &result); end_mock_cmds(); check(err == 0, "set features returned error %d", err); check(result == TEST_RESULT, @@ -348,7 +335,7 @@ static void test_set_temp_thresh(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_set_features_temp_thresh( - test_link, TMPTH, TMPSEL, THSEL, 0, true, &result); + test_link, true, TMPTH, TMPSEL, THSEL, 0, &result); end_mock_cmds(); check(err == 0, "set features returned error %d", err); check(result == TEST_RESULT, @@ -394,7 +381,7 @@ static void test_set_err_recovery(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_set_features_err_recovery( - test_link, TEST_NSID, TLER, true, false, &result); + test_link, TEST_NSID, false, TLER, true, &result); end_mock_cmds(); check(err == 0, "set features returned error %d", err); check(result == TEST_RESULT, @@ -492,7 +479,7 @@ static void test_set_irq_coalesce(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_set_features_irq_coalesce( - test_link, THR, TIME, false, &result); + test_link, false, THR, TIME, &result); end_mock_cmds(); check(err == 0, "set features returned error %d", err); check(result == TEST_RESULT, @@ -532,7 +519,7 @@ static void test_set_irq_config(void) int err; set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_set_features_irq_config(test_link, IV, true, true, &result); + err = nvme_set_features_irq_config(test_link, true, IV, true, &result); end_mock_cmds(); check(err == 0, "set features returned error %d", err); check(result == TEST_RESULT, @@ -571,7 +558,7 @@ static void test_set_write_atomic(void) int err; set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_set_features_write_atomic(test_link, true, false, &result); + err = nvme_set_features_write_atomic(test_link, false, true, &result); end_mock_cmds(); check(err == 0, "set features returned error %d", err); check(result == TEST_RESULT, @@ -610,7 +597,7 @@ static void test_set_async_event(void) int err; set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_set_features_async_event(test_link, EVENTS, true, &result); + err = nvme_set_features_async_event(test_link, true, EVENTS, &result); end_mock_cmds(); check(err == 0, "set features returned error %d", err); check(result == TEST_RESULT, @@ -651,7 +638,7 @@ static void test_set_auto_pst(void) arbitrary(&apst, sizeof(apst)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_set_features_auto_pst(test_link, true, false, &apst, &result); + err = nvme_set_features_auto_pst(test_link, false, true, &apst, &result); end_mock_cmds(); check(err == 0, "set features returned error %d", err); check(result == TEST_RESULT, @@ -724,7 +711,7 @@ static void test_set_timestamp(void) int err; set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_set_features_timestamp(test_link, true, timestamp); + err = nvme_set_features_timestamp(test_link, timestamp, true); end_mock_cmds(); check(err == 0, "set features returned error %d", err); } @@ -779,7 +766,7 @@ static void test_set_hctm(void) int err; set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_set_features_hctm(test_link, TMT2, TMT1, false, &result); + err = nvme_set_features_hctm(test_link, false, TMT2, TMT1, &result); end_mock_cmds(); check(err == 0, "set features returned error %d", err); check(result == TEST_RESULT, @@ -857,7 +844,7 @@ static void test_set_rrl(void) int err; set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_set_features_rrl(test_link, RRL, NVMSETID, false, &result); + err = nvme_set_features_rrl(test_link, false, NVMSETID, RRL, &result); end_mock_cmds(); check(err == 0, "set features returned error %d", err); check(result == TEST_RESULT, @@ -952,7 +939,7 @@ static void test_set_plm_window(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_set_features_plm_window( - test_link, SEL, NVMSETID, false, &result); + test_link, false, NVMSETID, SEL, &result); end_mock_cmds(); check(err == 0, "set features returned error %d", err); check(result == TEST_RESULT, @@ -995,7 +982,7 @@ static void test_set_lba_sts_interval(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_set_features_lba_sts_interval( - test_link, LSIRI, LSIPI, true, &result); + test_link, true, LSIRI, LSIPI, &result); end_mock_cmds(); check(err == 0, "set features returned error %d", err); check(result == TEST_RESULT, @@ -1024,17 +1011,18 @@ static void test_set_host_behavior(void) { /* nvme_set_features_host_behavior() ignores SAVE */ struct nvme_feat_host_behavior behavior; + bool save = true; struct mock_cmd mock_admin_cmd = { .opcode = nvme_admin_set_features, .in_data = &behavior, .data_len = sizeof(behavior), - .cdw10 = NVME_FEAT_FID_HOST_BEHAVIOR, + .cdw10 = NVME_FEAT_FID_HOST_BEHAVIOR | (!!save << 31), }; int err; arbitrary(&behavior, sizeof(behavior)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_set_features_host_behavior(test_link, true, &behavior); + err = nvme_set_features_host_behavior(test_link, save, &behavior); end_mock_cmds(); check(err == 0, "set features returned error %d", err); } @@ -1075,7 +1063,7 @@ static void test_set_sanitize(void) int err; set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_set_features_sanitize(test_link, true, false, &result); + err = nvme_set_features_sanitize(test_link, false, true, &result); end_mock_cmds(); check(err == 0, "set features returned error %d", err); check(result == TEST_RESULT, @@ -1116,7 +1104,7 @@ static void test_set_endurance_evt_cfg(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_set_features_endurance_evt_cfg( - test_link, ENDGID, EGWARN, true, &result); + test_link, true, ENDGID, EGWARN, &result); end_mock_cmds(); check(err == 0, "set features returned error %d", err); check(result == TEST_RESULT, @@ -1155,7 +1143,7 @@ static void test_set_iocs_profile(void) int err; set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_set_features_iocs_profile(test_link, IOCSI, false); + err = nvme_set_features_iocs_profile(test_link, false, IOCSI); end_mock_cmds(); check(err == 0, "set features returned error %d", err); } @@ -1192,7 +1180,7 @@ static void test_set_sw_progress(void) int err; set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_set_features_sw_progress(test_link, PBSLC, true, &result); + err = nvme_set_features_sw_progress(test_link, true, PBSLC, &result); end_mock_cmds(); check(err == 0, "set features returned error %d", err); check(result == TEST_RESULT, @@ -1232,7 +1220,7 @@ static void test_set_host_id(void) arbitrary(hostid, sizeof(hostid)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_set_features_host_id(test_link, false, true, hostid); + err = nvme_set_features_host_id(test_link, true, false, hostid); end_mock_cmds(); check(err == 0, "set features returned error %d", err); } @@ -1252,7 +1240,7 @@ static void test_set_host_id_extended(void) arbitrary(hostid, sizeof(hostid)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_set_features_host_id(test_link, true, false, hostid); + err = nvme_set_features_host_id(test_link, false, true, hostid); end_mock_cmds(); check(err == 0, "set features returned error %d", err); } @@ -1316,7 +1304,7 @@ static void test_set_resv_mask(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_set_features_resv_mask( - test_link, TEST_NSID, MASK, true, &result); + test_link, TEST_NSID, true, MASK, &result); end_mock_cmds(); check(err == 0, "set features returned error %d", err); check(result == TEST_RESULT, @@ -1357,7 +1345,7 @@ static void test_set_resv_persist(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_set_features_resv_persist( - test_link, TEST_NSID, true, false, &result); + test_link, TEST_NSID, false, true, &result); end_mock_cmds(); check(err == 0, "set features returned error %d", err); check(result == TEST_RESULT, @@ -1389,10 +1377,11 @@ static void test_set_write_protect(void) /* nvme_set_features_write_protect() ignores SAVE */ enum nvme_feat_nswpcfg_state STATE = NVME_FEAT_NS_WRITE_PROTECT_PERMANENT; + bool save = true; struct mock_cmd mock_admin_cmd = { .opcode = nvme_admin_set_features, .nsid = TEST_NSID, - .cdw10 = NVME_FEAT_FID_WRITE_PROTECT, + .cdw10 = NVME_FEAT_FID_WRITE_PROTECT | (!!save << 31), .cdw11 = STATE, .result = TEST_RESULT, }; @@ -1401,7 +1390,7 @@ static void test_set_write_protect(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_set_features_write_protect( - test_link, TEST_NSID, STATE, true, &result); + test_link, TEST_NSID, save, STATE, &result); end_mock_cmds(); check(err == 0, "set features returned error %d", err); check(result == TEST_RESULT, @@ -1447,7 +1436,7 @@ static void test_set_status_code_error(void) int err; set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_set_features_async_event(test_link, EVENTS, false, &result); + err = nvme_set_features_async_event(test_link, false, EVENTS, &result); end_mock_cmds(); check(err == TEST_SC, "got error %d, expected %d", err, TEST_SC); check(result == TEST_RESULT, @@ -1470,7 +1459,7 @@ static void test_set_kernel_error(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_set_features_resv_mask( - test_link, TEST_NSID, MASK, false, &result); + test_link, TEST_NSID, false, MASK, &result); end_mock_cmds(); check(err == -EIO, "got error %d, expected -EIO", err); check(!result, "result unexpectedly set to %" PRIu32, result); diff --git a/test/ioctl/meson.build b/test/ioctl/meson.build index f97925fe5..e086cbf4a 100644 --- a/test/ioctl/meson.build +++ b/test/ioctl/meson.build @@ -15,7 +15,7 @@ mock_ioctl = library( 'mock-ioctl', ['mock.c', 'util.c'], include_directories: [incdir, internal_incdir], - dependencies: [dl_dep], + dependencies: [libnvme_dep, dl_dep], c_args: ['-DHAVE_GLIBC_IOCTL=' + (mock_conf.get('HAVE_GLIBC_IOCTL') ? '1' : '0')]) # Add mock-ioctl to the LD_PRELOAD path so it overrides libc. diff --git a/test/meson.build b/test/meson.build index b73e12d60..64db67e43 100644 --- a/test/meson.build +++ b/test/meson.build @@ -110,6 +110,7 @@ if conf.get('HAVE_NETDB') test_util = executable( 'test-util', ['test-util.c'], + dependencies: libnvme_dep, include_directories: [incdir, internal_incdir] ) test('util', test_util) diff --git a/test/mi.c b/test/mi.c index d30139b2a..bd1d86761 100644 --- a/test/mi.c +++ b/test/mi.c @@ -1069,7 +1069,6 @@ static int test_admin_set_features_cb(struct nvme_mi_ep *ep, static void test_set_features(nvme_mi_ep_t ep) { - struct nvme_set_features_args args = { 0 }; struct nvme_timestamp tstamp = { 0 }; nvme_link_t link; uint32_t res; @@ -1083,16 +1082,10 @@ static void test_set_features(nvme_mi_ep_t ep) for (i = 0; i < sizeof(tstamp.timestamp); i++) tstamp.timestamp[i] = i; - args.args_size = sizeof(args); - args.fid = NVME_FEAT_FID_TIMESTAMP; - args.save = 1; - args.result = &res; - args.data = &tstamp; - args.data_len = sizeof(tstamp); - - rc = nvme_set_features(link, &args); + rc = nvme_set_features(link, NVME_NSID_NONE, NVME_FEAT_FID_TIMESTAMP, true, + 0, 0, 0, 0, 0, &tstamp, sizeof(tstamp), &res); assert(rc == 0); - assert(args.data_len == 8); + assert(sizeof(tstamp) == 8); } enum ns_type { From 49b23a5fb08c51b1b7af2a8dea6c55ee5a0d70c8 Mon Sep 17 00:00:00 2001 From: Tokunori Ikegami Date: Sat, 2 Aug 2025 10:16:59 +0900 Subject: [PATCH 29/66] ioctl: nvme_dsm use nvme_passthru_cmd directly Drop struct nvme_dsm_args. Signed-off-by: Tokunori Ikegami [wagi: reorder arguments] Signed-off-by: Daniel Wagner --- src/libnvme.map | 1 - src/nvme/api-types.h | 20 -------------------- src/nvme/ioctl.c | 18 ------------------ src/nvme/ioctl.h | 33 +++++++++++++++++++++++++++++++-- test/ioctl/misc.c | 17 ++++------------- 5 files changed, 35 insertions(+), 54 deletions(-) diff --git a/src/libnvme.map b/src/libnvme.map index ac222d2f8..7a6ba674e 100644 --- a/src/libnvme.map +++ b/src/libnvme.map @@ -67,7 +67,6 @@ LIBNVME_2_0 { nvme_directive_send; nvme_directive_send_id_endir; nvme_disconnect_ctrl; - nvme_dsm; nvme_dump_config; nvme_dump_tree; nvme_errno_to_string; diff --git a/src/nvme/api-types.h b/src/nvme/api-types.h index d5a8dc6a5..e67f18378 100644 --- a/src/nvme/api-types.h +++ b/src/nvme/api-types.h @@ -380,26 +380,6 @@ struct nvme_io_args { __u8 pif; }; -/** - * struct nvme_dsm_args - Arguments for the NVMe Dataset Management command - * @result: The command completion result from CQE dword0 - * @dsm: The data set management attributes - * @args_size: Size of &struct nvme_dsm_args - * @timeout: Timeout in ms - * @nsid: Namespace identifier - * @attrs: DSM attributes, see &enum nvme_dsm_attributes - * @nr_ranges: Number of block ranges in the data set management attributes - */ -struct nvme_dsm_args { - __u32 *result; - struct nvme_dsm_range *dsm; - int args_size; - __u32 timeout; - __u32 nsid; - __u32 attrs; - __u16 nr_ranges; -}; - /** * struct nvme_copy_args - Arguments for the NVMe Copy command * @sdlba: Start destination LBA diff --git a/src/nvme/ioctl.c b/src/nvme/ioctl.c index 9795297e5..b2162f39f 100644 --- a/src/nvme/ioctl.c +++ b/src/nvme/ioctl.c @@ -1404,24 +1404,6 @@ int nvme_io(nvme_link_t l, struct nvme_io_args *args, __u8 opcode) return nvme_submit_io_passthru(l, &cmd, args->result); } -int nvme_dsm(nvme_link_t l, struct nvme_dsm_args *args) -{ - struct nvme_passthru_cmd cmd = { - .opcode = nvme_cmd_dsm, - .nsid = args->nsid, - .addr = (__u64)(uintptr_t)args->dsm, - .data_len = args->nr_ranges * sizeof(*args->dsm), - .cdw10 = args->nr_ranges - 1, - .cdw11 = args->attrs, - .timeout_ms = args->timeout, - }; - - if (args->args_size < sizeof(*args)) - return -EINVAL; - - return nvme_submit_io_passthru(l, &cmd, args->result); -} - int nvme_copy(nvme_link_t l, struct nvme_copy_args *args) { const size_t size_v1 = sizeof_args(struct nvme_copy_args, format, __u64); diff --git a/src/nvme/ioctl.h b/src/nvme/ioctl.h index 9ed09a08a..6c4c23231 100644 --- a/src/nvme/ioctl.h +++ b/src/nvme/ioctl.h @@ -329,6 +329,14 @@ enum nvme_cmd_dword_fields { NVME_ZNS_MGMT_RECV_ZRAS_FEAT_MASK = 0x1, NVME_DIM_TAS_SHIFT = 0, NVME_DIM_TAS_MASK = 0xF, + NVME_DSM_CDW10_NR_SHIFT = 0, + NVME_DSM_CDW10_NR_MASK = 0xff, + NVME_DSM_CDW11_IDR_SHIFT = 0, + NVME_DSM_CDW11_IDR_MASK = 0x1, + NVME_DSM_CDW11_IDW_SHIFT = 1, + NVME_DSM_CDW11_IDW_MASK = 0x1, + NVME_DSM_CDW11_AD_SHIFT = 2, + NVME_DSM_CDW11_AD_MASK = 0x1, }; /** @@ -4078,7 +4086,11 @@ static inline int nvme_verify(nvme_link_t l, struct nvme_io_args *args) /** * nvme_dsm() - Send an nvme data set management command * @l: Link handle - * @args: &struct nvme_dsm_args argument structure + * @nsid: Namespace identifier + * @nr_ranges: Number of block ranges in the data set management attributes + * @attrs: DSM attributes, see &enum nvme_dsm_attributes + * @dsm: The data set management attributes + * @result: The command completion result from CQE dword0 * * The Dataset Management command is used by the host to indicate attributes * for ranges of logical blocks. This includes attributes like frequency that @@ -4089,7 +4101,24 @@ static inline int nvme_verify(nvme_link_t l, struct nvme_io_args *args) * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_dsm(nvme_link_t l, struct nvme_dsm_args *args); +static inline int nvme_dsm(nvme_link_t l, __u32 nsid, __u16 nr_ranges, + __u32 attrs, struct nvme_dsm_range *dsm, + __u32 *result) +{ + __u32 cdw10 = NVME_SET(nr_ranges - 1, DSM_CDW10_NR); + __u32 cdw11 = attrs; + + struct nvme_passthru_cmd cmd = { + .opcode = nvme_cmd_dsm, + .nsid = nsid, + .addr = (__u64)(uintptr_t)dsm, + .data_len = (__u32)(nr_ranges * sizeof(*dsm)), + .cdw10 = cdw10, + .cdw11 = cdw11, + }; + + return nvme_submit_io_passthru(l, &cmd, result); +} /** * nvme_copy() - Copy command diff --git a/test/ioctl/misc.c b/test/ioctl/misc.c index c8ca37c73..f3cc833e0 100644 --- a/test/ioctl/misc.c +++ b/test/ioctl/misc.c @@ -1107,29 +1107,20 @@ static void test_dsm(void) dsm = malloc(dsm_size); check(dsm, "dsm: ENOMEM"); - struct nvme_dsm_args args = { - .result = &result, - .dsm = dsm, - .args_size = sizeof(args), - .nsid = TEST_NSID, - .attrs = NVME_DSMGMT_AD, - .nr_ranges = nr_ranges, - }; - struct mock_cmd mock_io_cmd = { .opcode = nvme_cmd_dsm, .nsid = TEST_NSID, - .cdw10 = args.nr_ranges - 1, - .cdw11 = args.attrs, + .cdw10 = nr_ranges - 1, + .cdw11 = NVME_DSMGMT_AD, .data_len = dsm_size, - .in_data = args.dsm, + .in_data = dsm, }; int err; arbitrary(dsm, dsm_size); set_mock_io_cmds(&mock_io_cmd, 1); - err = nvme_dsm(test_link, &args); + err = nvme_dsm(test_link, TEST_NSID, nr_ranges, NVME_DSMGMT_AD, dsm, &result); end_mock_cmds(); check(err == 0, "returned error %d", err); check(result == 0, "returned result %u", result); From 1b35385ede658b59821a0e246efa945063503fde Mon Sep 17 00:00:00 2001 From: Tokunori Ikegami Date: Sat, 2 Aug 2025 23:40:51 +0900 Subject: [PATCH 30/66] ioctl: nvme_io use nvme_passthru_cmd directly Drop struct nvme_io_args. Signed-off-by: Tokunori Ikegami ioctl: reorder nsid argument Also order the pointer and its length member go to the end of the list. Signed-off-by: Tokunori Ikegami --- src/libnvme.map | 1 - src/nvme/api-types.h | 62 -------- src/nvme/ioctl.c | 89 ----------- src/nvme/ioctl.h | 362 ++++++++++++++++++++++++++++++++++++++++--- src/nvme/tree.c | 144 ++++------------- test/ioctl/misc.c | 227 +++++++++++---------------- 6 files changed, 461 insertions(+), 424 deletions(-) diff --git a/src/libnvme.map b/src/libnvme.map index 7a6ba674e..5ddb5f1cb 100644 --- a/src/libnvme.map +++ b/src/libnvme.map @@ -161,7 +161,6 @@ LIBNVME_2_0 { nvme_init_logging; nvme_insert_tls_key; nvme_insert_tls_key_versioned; - nvme_io; nvme_io_mgmt_recv; nvme_io_mgmt_send; nvme_io_passthru64; diff --git a/src/nvme/api-types.h b/src/nvme/api-types.h index e67f18378..0960f8ce1 100644 --- a/src/nvme/api-types.h +++ b/src/nvme/api-types.h @@ -318,68 +318,6 @@ struct nvme_virtual_mgmt_args { __u16 nr; }; -/** - * struct nvme_io_args - Arguments for NVMe I/O commands - * @slba: Starting logical block - * @storage_tag: This filed specifies Variable Sized Expected Logical Block - * Storage Tag (ELBST) or Logical Block Storage Tag (LBST) - * @result: The command completion result from CQE dword0 - * @data: Pointer to user address of the data buffer - * @metadata: Pointer to user address of the metadata buffer - * @args_size: Size of &struct nvme_io_args - * @timeout: Timeout in ms - * @nsid: Namespace ID - * @data_len: Length of user buffer, @data, in bytes - * @metadata_len:Length of user buffer, @metadata, in bytes - * @nlb: Number of logical blocks to send (0's based value) - * @control: Command control flags, see &enum nvme_io_control_flags. - * @apptag: This field specifies the Application Tag Mask expected value. - * Used only if the namespace is formatted to use end-to-end - * protection information. - * @appmask: This field specifies the Application Tag expected value. Used - * only if the namespace is formatted to use end-to-end protection - * information. - * @reftag: This field specifies the variable sized Expected Initial - * Logical Block Reference Tag (EILBRT) or Initial Logical Block - * Reference Tag (ILBRT). Used only if the namespace is formatted - * to use end-to-end protection information. - * @dspec: Directive specific value - * @dsm: Data set management attributes, see &enum nvme_io_dsm_flags - * @rsvd1: Reserved - * @reftag_u64: This field specifies the variable sized Expected Initial - * Logical Block Reference Tag (EILBRT) or Initial Logical Block - * Reference Tag (ILBRT). It is the 8 byte version required for - * enhanced protection information. Used only if the namespace is - * formatted to use end-to-end protection information. - * @sts: Storage tag size in bits, set by namespace Extended LBA Format - * @pif: Protection information format, determines how variable sized - * storage_tag and reftag are put into dwords 2, 3, and 14. Set by - * namespace Extended LBA Format. - */ -struct nvme_io_args { - __u64 slba; - __u64 storage_tag; - __u32 *result; - void *data; - void *metadata; - int args_size; - __u32 timeout; - __u32 nsid; - __u32 reftag; - __u32 data_len; - __u32 metadata_len; - __u16 nlb; - __u16 control; - __u16 apptag; - __u16 appmask; - __u16 dspec; - __u8 dsm; - __u8 rsvd1[1]; - __u64 reftag_u64; - __u8 sts; - __u8 pif; -}; - /** * struct nvme_copy_args - Arguments for the NVMe Copy command * @sdlba: Start destination LBA diff --git a/src/nvme/ioctl.c b/src/nvme/ioctl.c index b2162f39f..b5294ad8e 100644 --- a/src/nvme/ioctl.c +++ b/src/nvme/ioctl.c @@ -1315,95 +1315,6 @@ int nvme_io_passthru(nvme_link_t l, __u8 opcode, __u8 flags, __u16 rsvd, timeout_ms, result); } -static int nvme_set_var_size_tags(__u32 *cmd_dw2, __u32 *cmd_dw3, __u32 *cmd_dw14, - __u8 pif, __u8 sts, __u64 reftag, __u64 storage_tag) -{ - __u32 cdw2 = 0, cdw3 = 0, cdw14; - - switch (pif) { - case NVME_NVM_PIF_16B_GUARD: - cdw14 = reftag & 0xffffffff; - cdw14 |= ((storage_tag << (32 - sts)) & 0xffffffff); - break; - case NVME_NVM_PIF_32B_GUARD: - cdw14 = reftag & 0xffffffff; - cdw3 = reftag >> 32; - cdw14 |= ((storage_tag << (80 - sts)) & 0xffff0000); - if (sts >= 48) - cdw3 |= ((storage_tag >> (sts - 48)) & 0xffffffff); - else - cdw3 |= ((storage_tag << (48 - sts)) & 0xffffffff); - cdw2 = (storage_tag >> (sts - 16)) & 0xffff; - break; - case NVME_NVM_PIF_64B_GUARD: - cdw14 = reftag & 0xffffffff; - cdw3 = (reftag >> 32) & 0xffff; - cdw14 |= ((storage_tag << (48 - sts)) & 0xffffffff); - if (sts >= 16) - cdw3 |= ((storage_tag >> (sts - 16)) & 0xffff); - else - cdw3 |= ((storage_tag << (16 - sts)) & 0xffff); - break; - default: - perror("Unsupported Protection Information Format"); - return -EINVAL; - } - - *cmd_dw2 = cdw2; - *cmd_dw3 = cdw3; - *cmd_dw14 = cdw14; - return 0; -} - -int nvme_io(nvme_link_t l, struct nvme_io_args *args, __u8 opcode) -{ - const size_t size_v1 = sizeof_args(struct nvme_io_args, dsm, __u64); - const size_t size_v2 = sizeof_args(struct nvme_io_args, pif, __u64); - __u32 cdw2, cdw3, cdw10, cdw11, cdw12, cdw13, cdw14, cdw15; - - if (args->args_size < size_v1 || args->args_size > size_v2) - return -EINVAL; - - cdw10 = args->slba & 0xffffffff; - cdw11 = args->slba >> 32; - cdw12 = args->nlb | (args->control << 16); - cdw13 = args->dsm | (args->dspec << 16); - cdw15 = args->apptag | (args->appmask << 16); - - if (args->args_size == size_v1) { - cdw2 = (args->storage_tag >> 32) & 0xffff; - cdw3 = args->storage_tag & 0xffffffff; - cdw14 = args->reftag; - } else { - if (nvme_set_var_size_tags(&cdw2, &cdw3, &cdw14, - args->pif, - args->sts, - args->reftag_u64, - args->storage_tag)) - return -EINVAL; - } - - struct nvme_passthru_cmd cmd = { - .opcode = opcode, - .nsid = args->nsid, - .cdw2 = cdw2, - .cdw3 = cdw3, - .cdw10 = cdw10, - .cdw11 = cdw11, - .cdw12 = cdw12, - .cdw13 = cdw13, - .cdw14 = cdw14, - .cdw15 = cdw15, - .data_len = args->data_len, - .metadata_len = args->metadata_len, - .addr = (__u64)(uintptr_t)args->data, - .metadata = (__u64)(uintptr_t)args->metadata, - .timeout_ms = args->timeout, - }; - - return nvme_submit_io_passthru(l, &cmd, args->result); -} - int nvme_copy(nvme_link_t l, struct nvme_copy_args *args) { const size_t size_v1 = sizeof_args(struct nvme_copy_args, format, __u64); diff --git a/src/nvme/ioctl.h b/src/nvme/ioctl.h index 6c4c23231..bc275141c 100644 --- a/src/nvme/ioctl.h +++ b/src/nvme/ioctl.h @@ -3980,60 +3980,302 @@ static inline int nvme_flush(nvme_link_t l, __u32 nsid) return nvme_submit_io_passthru(l, &cmd, NULL); } +static inline int nvme_set_var_size_tags(__u8 pif, __u8 sts, __u64 reftag, __u64 storage_tag, + __u32 *cmd_dw2, __u32 *cmd_dw3, __u32 *cmd_dw14) +{ + __u32 cdw2 = 0, cdw3 = 0, cdw14; + + switch (pif) { + case NVME_NVM_PIF_16B_GUARD: + cdw14 = reftag & 0xffffffff; + cdw14 |= ((storage_tag << (32 - sts)) & 0xffffffff); + break; + case NVME_NVM_PIF_32B_GUARD: + cdw14 = reftag & 0xffffffff; + cdw3 = reftag >> 32; + cdw14 |= ((storage_tag << (80 - sts)) & 0xffff0000); + if (sts >= 48) + cdw3 |= ((storage_tag >> (sts - 48)) & 0xffffffff); + else + cdw3 |= ((storage_tag << (48 - sts)) & 0xffffffff); + cdw2 = (storage_tag >> (sts - 16)) & 0xffff; + break; + case NVME_NVM_PIF_64B_GUARD: + cdw14 = reftag & 0xffffffff; + cdw3 = (reftag >> 32) & 0xffff; + cdw14 |= ((storage_tag << (48 - sts)) & 0xffffffff); + if (sts >= 16) + cdw3 |= ((storage_tag >> (sts - 16)) & 0xffff); + else + cdw3 |= ((storage_tag << (16 - sts)) & 0xffff); + break; + default: + perror("Unsupported Protection Information Format"); + return -EINVAL; + } + + *cmd_dw2 = cdw2; + *cmd_dw3 = cdw3; + *cmd_dw14 = cdw14; + return 0; +} + /** * nvme_io() - Submit an nvme user I/O command * @l: Link handle - * @args: &struct nvme_io_args argument structure * @opcode: Opcode to execute + * @nsid: Namespace ID + * @slba: Starting logical block + * @storage_tag: This filed specifies Variable Sized Expected Logical Block + * Storage Tag (ELBST) or Logical Block Storage Tag (LBST) + * @nlb: Number of logical blocks to send (0's based value) + * @control: Command control flags, see &enum nvme_io_control_flags. + * @apptag: This field specifies the Application Tag Mask expected value. + * Used only if the namespace is formatted to use end-to-end + * protection information. + * @appmask: This field specifies the Application Tag expected value. Used + * only if the namespace is formatted to use end-to-end protection + * information. + * @reftag: This field specifies the variable sized Expected Initial + * Logical Block Reference Tag (EILBRT) or Initial Logical Block + * Reference Tag (ILBRT). Used only if the namespace is formatted + * to use end-to-end protection information. + * @dspec: Directive specific value + * @dsm: Data set management attributes, see &enum nvme_io_dsm_flags + * @reftag_u64: This field specifies the variable sized Expected Initial + * Logical Block Reference Tag (EILBRT) or Initial Logical Block + * Reference Tag (ILBRT). It is the 8 byte version required for + * enhanced protection information. Used only if the namespace is + * formatted to use end-to-end protection information. + * @sts: Storage tag size in bits, set by namespace Extended LBA Format + * @pif: Protection information format, determines how variable sized + * storage_tag and reftag are put into dwords 2, 3, and 14. Set by + * namespace Extended LBA Format. + * @data: Pointer to user address of the data buffer + * @data_len: Length of user buffer, @data, in bytes + * @metadata: Pointer to user address of the metadata buffer + * @metadata_len:Length of user buffer, @metadata, in bytes + * @result: The command completion result from CQE dword0 * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_io(nvme_link_t l, struct nvme_io_args *args, __u8 opcode); +static inline int nvme_io(nvme_link_t l, __u8 opcode, __u32 nsid, __u64 slba, __u64 storage_tag, + __u32 reftag, __u16 nlb, __u16 control, __u16 apptag, __u16 appmask, + __u16 dspec, __u8 dsm, __u64 reftag_u64, __u8 sts, __u8 pif, void *data, + __u32 data_len, void *metadata, __u32 metadata_len, __u32 *result) +{ + __u32 cdw10 = slba & 0xffffffff; + __u32 cdw11 = slba >> 32; + __u32 cdw12 = nlb | (control << 16); + __u32 cdw13 = dsm | (dspec << 16); + __u32 cdw15 = apptag | (appmask << 16); + + struct nvme_passthru_cmd cmd = { + .opcode = opcode, + .nsid = nsid, + .metadata = (__u64)(uintptr_t)metadata, + .addr = (__u64)(uintptr_t)data, + .metadata_len = metadata_len, + .data_len = data_len, + .cdw10 = cdw10, + .cdw11 = cdw11, + .cdw12 = cdw12, + .cdw13 = cdw13, + .cdw15 = cdw15, + }; + + if (nvme_set_var_size_tags(pif, sts, reftag_u64, storage_tag, &cmd.cdw2, &cmd.cdw3, + &cmd.cdw14)) + return -EINVAL; + + + return nvme_submit_io_passthru(l, &cmd, result); +} /** * nvme_read() - Submit an nvme user read command * @l: Link handle - * @args: &struct nvme_io_args argument structure + * @nsid: Namespace ID + * @slba: Starting logical block + * @storage_tag: This filed specifies Variable Sized Expected Logical Block + * Storage Tag (ELBST) or Logical Block Storage Tag (LBST) + * @nlb: Number of logical blocks to send (0's based value) + * @control: Command control flags, see &enum nvme_io_control_flags. + * @apptag: This field specifies the Application Tag Mask expected value. + * Used only if the namespace is formatted to use end-to-end + * protection information. + * @appmask: This field specifies the Application Tag expected value. Used + * only if the namespace is formatted to use end-to-end protection + * information. + * @reftag: This field specifies the variable sized Expected Initial + * Logical Block Reference Tag (EILBRT) or Initial Logical Block + * Reference Tag (ILBRT). Used only if the namespace is formatted + * to use end-to-end protection information. + * @dspec: Directive specific value + * @dsm: Data set management attributes, see &enum nvme_io_dsm_flags + * @reftag_u64: This field specifies the variable sized Expected Initial + * Logical Block Reference Tag (EILBRT) or Initial Logical Block + * Reference Tag (ILBRT). It is the 8 byte version required for + * enhanced protection information. Used only if the namespace is + * formatted to use end-to-end protection information. + * @sts: Storage tag size in bits, set by namespace Extended LBA Format + * @pif: Protection information format, determines how variable sized + * storage_tag and reftag are put into dwords 2, 3, and 14. Set by + * namespace Extended LBA Format. + * @data: Pointer to user address of the data buffer + * @data_len: Length of user buffer, @data, in bytes + * @metadata: Pointer to user address of the metadata buffer + * @metadata_len:Length of user buffer, @metadata, in bytes + * @result: The command completion result from CQE dword0 * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -static inline int nvme_read(nvme_link_t l, struct nvme_io_args *args) +static inline int nvme_read(nvme_link_t l, __u32 nsid, __u64 slba, __u64 storage_tag, __u32 reftag, + __u16 nlb, __u16 control, __u16 apptag, __u16 appmask, __u16 dspec, + __u8 dsm, __u64 reftag_u64, __u8 sts, __u8 pif, void *data, + __u32 data_len, void *metadata, __u32 metadata_len, __u32 *result) { - return nvme_io(l, args, nvme_cmd_read); + return nvme_io(l, nvme_cmd_read, nsid, slba, storage_tag, reftag, nlb, control, apptag, + appmask, dspec, dsm, reftag_u64, sts, pif, data, data_len, metadata, + metadata_len, result); } /** * nvme_write() - Submit an nvme user write command * @l: Link handle - * @args: &struct nvme_io_args argument structure + * @nsid: Namespace ID + * @slba: Starting logical block + * @storage_tag: This filed specifies Variable Sized Expected Logical Block + * Storage Tag (ELBST) or Logical Block Storage Tag (LBST) + * @nlb: Number of logical blocks to send (0's based value) + * @control: Command control flags, see &enum nvme_io_control_flags. + * @apptag: This field specifies the Application Tag Mask expected value. + * Used only if the namespace is formatted to use end-to-end + * protection information. + * @appmask: This field specifies the Application Tag expected value. Used + * only if the namespace is formatted to use end-to-end protection + * information. + * @reftag: This field specifies the variable sized Expected Initial + * Logical Block Reference Tag (EILBRT) or Initial Logical Block + * Reference Tag (ILBRT). Used only if the namespace is formatted + * to use end-to-end protection information. + * @dspec: Directive specific value + * @dsm: Data set management attributes, see &enum nvme_io_dsm_flags + * @reftag_u64: This field specifies the variable sized Expected Initial + * Logical Block Reference Tag (EILBRT) or Initial Logical Block + * Reference Tag (ILBRT). It is the 8 byte version required for + * enhanced protection information. Used only if the namespace is + * formatted to use end-to-end protection information. + * @sts: Storage tag size in bits, set by namespace Extended LBA Format + * @pif: Protection information format, determines how variable sized + * storage_tag and reftag are put into dwords 2, 3, and 14. Set by + * namespace Extended LBA Format. + * @data: Pointer to user address of the data buffer + * @data_len: Length of user buffer, @data, in bytes + * @metadata: Pointer to user address of the metadata buffer + * @metadata_len:Length of user buffer, @metadata, in bytes + * @result: The command completion result from CQE dword0 * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -static inline int nvme_write(nvme_link_t l, struct nvme_io_args *args) +static inline int nvme_write(nvme_link_t l, __u32 nsid, __u64 slba, __u64 storage_tag, __u32 reftag, + __u16 nlb, __u16 control, __u16 apptag, __u16 appmask, __u16 dspec, + __u8 dsm, __u64 reftag_u64, __u8 sts, __u8 pif, void *data, + __u32 data_len, void *metadata, __u32 metadata_len, __u32 *result) { - return nvme_io(l, args, nvme_cmd_write); + return nvme_io(l, nvme_cmd_write, nsid, slba, storage_tag, reftag, nlb, control, apptag, + appmask, dspec, dsm, reftag_u64, sts, pif, data, data_len, metadata, + metadata_len, result); } /** * nvme_compare() - Submit an nvme user compare command * @l: Link handle - * @args: &struct nvme_io_args argument structure + * @nsid: Namespace ID + * @slba: Starting logical block + * @storage_tag: This filed specifies Variable Sized Expected Logical Block + * Storage Tag (ELBST) or Logical Block Storage Tag (LBST) + * @nlb: Number of logical blocks to send (0's based value) + * @control: Command control flags, see &enum nvme_io_control_flags. + * @apptag: This field specifies the Application Tag Mask expected value. + * Used only if the namespace is formatted to use end-to-end + * protection information. + * @appmask: This field specifies the Application Tag expected value. Used + * only if the namespace is formatted to use end-to-end protection + * information. + * @reftag: This field specifies the variable sized Expected Initial + * Logical Block Reference Tag (EILBRT) or Initial Logical Block + * Reference Tag (ILBRT). Used only if the namespace is formatted + * to use end-to-end protection information. + * @dspec: Directive specific value + * @dsm: Data set management attributes, see &enum nvme_io_dsm_flags + * @reftag_u64: This field specifies the variable sized Expected Initial + * Logical Block Reference Tag (EILBRT) or Initial Logical Block + * Reference Tag (ILBRT). It is the 8 byte version required for + * enhanced protection information. Used only if the namespace is + * formatted to use end-to-end protection information. + * @sts: Storage tag size in bits, set by namespace Extended LBA Format + * @pif: Protection information format, determines how variable sized + * storage_tag and reftag are put into dwords 2, 3, and 14. Set by + * namespace Extended LBA Format. + * @data: Pointer to user address of the data buffer + * @data_len: Length of user buffer, @data, in bytes + * @metadata: Pointer to user address of the metadata buffer + * @metadata_len:Length of user buffer, @metadata, in bytes + * @result: The command completion result from CQE dword0 * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -static inline int nvme_compare(nvme_link_t l, struct nvme_io_args *args) +static inline int nvme_compare(nvme_link_t l, __u32 nsid, __u64 slba, __u64 storage_tag, + __u32 reftag, __u16 nlb, __u16 control, __u16 apptag, __u16 appmask, + __u16 dspec, __u8 dsm, __u64 reftag_u64, __u8 sts, __u8 pif, + void *data, __u32 data_len, void *metadata, __u32 metadata_len, + __u32 *result) { - return nvme_io(l, args, nvme_cmd_compare); + return nvme_io(l, nvme_cmd_compare, nsid, slba, storage_tag, reftag, nlb, control, apptag, + appmask, dspec, dsm, reftag_u64, sts, pif, data, data_len, metadata, + metadata_len, result); } /** * nvme_write_zeros() - Submit an nvme write zeroes command * @l: Link handle - * @args: &struct nvme_io_args argument structure + * @nsid: Namespace ID + * @slba: Starting logical block + * @storage_tag: This filed specifies Variable Sized Expected Logical Block + * Storage Tag (ELBST) or Logical Block Storage Tag (LBST) + * @nlb: Number of logical blocks to send (0's based value) + * @control: Command control flags, see &enum nvme_io_control_flags. + * @apptag: This field specifies the Application Tag Mask expected value. + * Used only if the namespace is formatted to use end-to-end + * protection information. + * @appmask: This field specifies the Application Tag expected value. Used + * only if the namespace is formatted to use end-to-end protection + * information. + * @reftag: This field specifies the variable sized Expected Initial + * Logical Block Reference Tag (EILBRT) or Initial Logical Block + * Reference Tag (ILBRT). Used only if the namespace is formatted + * to use end-to-end protection information. + * @dspec: Directive specific value + * @dsm: Data set management attributes, see &enum nvme_io_dsm_flags + * @reftag_u64: This field specifies the variable sized Expected Initial + * Logical Block Reference Tag (EILBRT) or Initial Logical Block + * Reference Tag (ILBRT). It is the 8 byte version required for + * enhanced protection information. Used only if the namespace is + * formatted to use end-to-end protection information. + * @sts: Storage tag size in bits, set by namespace Extended LBA Format + * @pif: Protection information format, determines how variable sized + * storage_tag and reftag are put into dwords 2, 3, and 14. Set by + * namespace Extended LBA Format. + * @data: Pointer to user address of the data buffer + * @data_len: Length of user buffer, @data, in bytes + * @metadata: Pointer to user address of the metadata buffer + * @metadata_len:Length of user buffer, @metadata, in bytes + * @result: The command completion result from CQE dword0 * * The Write Zeroes command sets a range of logical blocks to zero. After * successful completion of this command, the value returned by subsequent @@ -4043,15 +4285,52 @@ static inline int nvme_compare(nvme_link_t l, struct nvme_io_args *args) * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -static inline int nvme_write_zeros(nvme_link_t l, struct nvme_io_args *args) +static inline int nvme_write_zeros(nvme_link_t l, __u32 nsid, __u64 slba, __u64 storage_tag, + __u32 reftag, __u16 nlb, __u16 control, __u16 apptag, + __u16 appmask, __u16 dspec, __u8 dsm, __u64 reftag_u64, __u8 sts, + __u8 pif, void *data, __u32 data_len, void *metadata, + __u32 metadata_len, __u32 *result) { - return nvme_io(l, args, nvme_cmd_write_zeroes); + return nvme_io(l, nvme_cmd_write_zeroes, nsid, slba, storage_tag, reftag, nlb, control, + apptag, appmask, dspec, dsm, reftag_u64, sts, pif, data, data_len, metadata, + metadata_len, result); } /** * nvme_write_uncorrectable() - Submit an nvme write uncorrectable command * @l: Link handle - * @args: &struct nvme_io_args argument structure + * @nsid: Namespace ID + * @slba: Starting logical block + * @storage_tag: This filed specifies Variable Sized Expected Logical Block + * Storage Tag (ELBST) or Logical Block Storage Tag (LBST) + * @nlb: Number of logical blocks to send (0's based value) + * @control: Command control flags, see &enum nvme_io_control_flags. + * @apptag: This field specifies the Application Tag Mask expected value. + * Used only if the namespace is formatted to use end-to-end + * protection information. + * @appmask: This field specifies the Application Tag expected value. Used + * only if the namespace is formatted to use end-to-end protection + * information. + * @reftag: This field specifies the variable sized Expected Initial + * Logical Block Reference Tag (EILBRT) or Initial Logical Block + * Reference Tag (ILBRT). Used only if the namespace is formatted + * to use end-to-end protection information. + * @dspec: Directive specific value + * @dsm: Data set management attributes, see &enum nvme_io_dsm_flags + * @reftag_u64: This field specifies the variable sized Expected Initial + * Logical Block Reference Tag (EILBRT) or Initial Logical Block + * Reference Tag (ILBRT). It is the 8 byte version required for + * enhanced protection information. Used only if the namespace is + * formatted to use end-to-end protection information. + * @sts: Storage tag size in bits, set by namespace Extended LBA Format + * @pif: Protection information format, determines how variable sized + * storage_tag and reftag are put into dwords 2, 3, and 14. Set by + * namespace Extended LBA Format. + * @data: Pointer to user address of the data buffer + * @data_len: Length of user buffer, @data, in bytes + * @metadata: Pointer to user address of the metadata buffer + * @metadata_len:Length of user buffer, @metadata, in bytes + * @result: The command completion result from CQE dword0 * * The Write Uncorrectable command marks a range of logical blocks as invalid. * When the specified logical block(s) are read after this operation, a failure @@ -4061,15 +4340,52 @@ static inline int nvme_write_zeros(nvme_link_t l, struct nvme_io_args *args) * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -static inline int nvme_write_uncorrectable(nvme_link_t l, struct nvme_io_args *args) +static inline int nvme_write_uncorrectable(nvme_link_t l, __u32 nsid, __u64 slba, __u64 storage_tag, + __u32 reftag, __u16 nlb, __u16 control, __u16 apptag, + __u16 appmask, __u16 dspec, __u8 dsm, __u64 reftag_u64, + __u8 sts, __u8 pif, void *data, __u32 data_len, + void *metadata, __u32 metadata_len, __u32 *result) { - return nvme_io(l, args, nvme_cmd_write_uncor); + return nvme_io(l, nvme_cmd_write_uncor, nsid, slba, storage_tag, reftag, nlb, control, + apptag, appmask, dspec, dsm, reftag_u64, sts, pif, data, data_len, metadata, + metadata_len, result); } /** * nvme_verify() - Send an nvme verify command * @l: Link handle - * @args: &struct nvme_io_args argument structure + * @nsid: Namespace ID + * @slba: Starting logical block + * @storage_tag: This filed specifies Variable Sized Expected Logical Block + * Storage Tag (ELBST) or Logical Block Storage Tag (LBST) + * @nlb: Number of logical blocks to send (0's based value) + * @control: Command control flags, see &enum nvme_io_control_flags. + * @apptag: This field specifies the Application Tag Mask expected value. + * Used only if the namespace is formatted to use end-to-end + * protection information. + * @appmask: This field specifies the Application Tag expected value. Used + * only if the namespace is formatted to use end-to-end protection + * information. + * @reftag: This field specifies the variable sized Expected Initial + * Logical Block Reference Tag (EILBRT) or Initial Logical Block + * Reference Tag (ILBRT). Used only if the namespace is formatted + * to use end-to-end protection information. + * @dspec: Directive specific value + * @dsm: Data set management attributes, see &enum nvme_io_dsm_flags + * @reftag_u64: This field specifies the variable sized Expected Initial + * Logical Block Reference Tag (EILBRT) or Initial Logical Block + * Reference Tag (ILBRT). It is the 8 byte version required for + * enhanced protection information. Used only if the namespace is + * formatted to use end-to-end protection information. + * @sts: Storage tag size in bits, set by namespace Extended LBA Format + * @pif: Protection information format, determines how variable sized + * storage_tag and reftag are put into dwords 2, 3, and 14. Set by + * namespace Extended LBA Format. + * @data: Pointer to user address of the data buffer + * @data_len: Length of user buffer, @data, in bytes + * @metadata: Pointer to user address of the metadata buffer + * @metadata_len:Length of user buffer, @metadata, in bytes + * @result: The command completion result from CQE dword0 * * The Verify command verifies integrity of stored information by reading data * and metadata, if applicable, for the LBAs indicated without transferring any @@ -4078,9 +4394,15 @@ static inline int nvme_write_uncorrectable(nvme_link_t l, struct nvme_io_args *a * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -static inline int nvme_verify(nvme_link_t l, struct nvme_io_args *args) +static inline int nvme_verify(nvme_link_t l, __u32 nsid, __u64 slba, __u64 storage_tag, + __u32 reftag, __u16 nlb, __u16 control, __u16 apptag, __u16 appmask, + __u16 dspec, __u8 dsm, __u64 reftag_u64, __u8 sts, __u8 pif, + void *data, __u32 data_len, void *metadata, __u32 metadata_len, + __u32 *result) { - return nvme_io(l, args, nvme_cmd_verify); + return nvme_io(l, nvme_cmd_verify, nsid, slba, storage_tag, reftag, nlb, control, apptag, + appmask, dspec, dsm, reftag_u64, sts, pif, data, data_len, metadata, + metadata_len, result); } /** diff --git a/src/nvme/tree.c b/src/nvme/tree.c index 0e42d8e5b..208c468ff 100644 --- a/src/nvme/tree.c +++ b/src/nvme/tree.c @@ -2453,158 +2453,74 @@ int nvme_ns_identify_descs(nvme_ns_t n, struct nvme_ns_id_desc *descs) int nvme_ns_verify(nvme_ns_t n, off_t offset, size_t count) { - struct nvme_io_args args = { - .args_size = sizeof(args), - .nsid = nvme_ns_get_nsid(n), - .control = 0, - .dsm = 0, - .dspec = 0, - .reftag = 0, - .apptag = 0, - .appmask = 0, - .storage_tag = 0, - .data_len = 0, - .data = NULL, - .metadata_len = 0, - .metadata = NULL, - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .result = NULL, - }; + __u64 slba; + __u16 nlb; - if (nvme_bytes_to_lba(n, offset, count, &args.slba, &args.nlb)) + if (nvme_bytes_to_lba(n, offset, count, &slba, &nlb)) return -1; - return nvme_verify(nvme_ns_get_link(n), &args); + return nvme_verify(nvme_ns_get_link(n), nvme_ns_get_nsid(n), slba, 0, 0, nlb, 0, 0, 0, 0, 0, + 0, 0, 0, NULL, 0, NULL, 0, NULL); } int nvme_ns_write_uncorrectable(nvme_ns_t n, off_t offset, size_t count) { - struct nvme_io_args args = { - .args_size = sizeof(args), - .nsid = nvme_ns_get_nsid(n), - .control = 0, - .dsm = 0, - .dspec = 0, - .reftag = 0, - .apptag = 0, - .appmask = 0, - .storage_tag = 0, - .data_len = 0, - .data = NULL, - .metadata_len = 0, - .metadata = NULL, - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .result = NULL, - }; + __u64 slba; + __u16 nlb; - if (nvme_bytes_to_lba(n, offset, count, &args.slba, &args.nlb)) + if (nvme_bytes_to_lba(n, offset, count, &slba, &nlb)) return -1; - return nvme_write_uncorrectable(nvme_ns_get_link(n), &args); + return nvme_write_uncorrectable(nvme_ns_get_link(n), nvme_ns_get_nsid(n), slba, 0, 0, nlb, + 0, 0, 0, 0, 0, 0, 0, 0, NULL, 0, NULL, 0, NULL); } int nvme_ns_write_zeros(nvme_ns_t n, off_t offset, size_t count) { - struct nvme_io_args args = { - .args_size = sizeof(args), - .nsid = nvme_ns_get_nsid(n), - .control = 0, - .dsm = 0, - .dspec = 0, - .reftag = 0, - .apptag = 0, - .appmask = 0, - .storage_tag = 0, - .data_len = 0, - .data = NULL, - .metadata_len = 0, - .metadata = NULL, - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .result = NULL, - }; + __u64 slba; + __u16 nlb; - if (nvme_bytes_to_lba(n, offset, count, &args.slba, &args.nlb)) + if (nvme_bytes_to_lba(n, offset, count, &slba, &nlb)) return -1; - return nvme_write_zeros(nvme_ns_get_link(n), &args); + return nvme_write_zeros(nvme_ns_get_link(n), nvme_ns_get_nsid(n), slba, 0, 0, nlb, 0, 0, 0, + 0, 0, 0, 0, 0, NULL, 0, NULL, 0, NULL); } int nvme_ns_write(nvme_ns_t n, void *buf, off_t offset, size_t count) { - struct nvme_io_args args = { - .args_size = sizeof(args), - .nsid = nvme_ns_get_nsid(n), - .control = 0, - .dsm = 0, - .dspec = 0, - .reftag = 0, - .apptag = 0, - .appmask = 0, - .storage_tag = 0, - .data_len = count, - .data = buf, - .metadata_len = 0, - .metadata = NULL, - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .result = NULL, - }; + __u64 slba; + __u16 nlb; - if (nvme_bytes_to_lba(n, offset, count, &args.slba, &args.nlb)) + if (nvme_bytes_to_lba(n, offset, count, &slba, &nlb)) return -1; - return nvme_write(nvme_ns_get_link(n), &args); + return nvme_write(nvme_ns_get_link(n), nvme_ns_get_nsid(n), slba, 0, 0, nlb, 0, 0, 0, 0, 0, + 0, 0, 0, NULL, 0, NULL, 0, NULL); } int nvme_ns_read(nvme_ns_t n, void *buf, off_t offset, size_t count) { - struct nvme_io_args args = { - .args_size = sizeof(args), - .nsid = nvme_ns_get_nsid(n), - .control = 0, - .dsm = 0, - .dspec = 0, - .reftag = 0, - .apptag = 0, - .appmask = 0, - .storage_tag = 0, - .data_len = count, - .data = buf, - .metadata_len = 0, - .metadata = NULL, - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .result = NULL, - }; + __u64 slba; + __u16 nlb; - if (nvme_bytes_to_lba(n, offset, count, &args.slba, &args.nlb)) + if (nvme_bytes_to_lba(n, offset, count, &slba, &nlb)) return -1; - return nvme_read(nvme_ns_get_link(n), &args); + return nvme_read(nvme_ns_get_link(n), nvme_ns_get_nsid(n), slba, 0, 0, nlb, 0, 0, 0, 0, 0, + 0, 0, 0, NULL, 0, NULL, 0, NULL); } int nvme_ns_compare(nvme_ns_t n, void *buf, off_t offset, size_t count) { - struct nvme_io_args args = { - .args_size = sizeof(args), - .nsid = nvme_ns_get_nsid(n), - .control = 0, - .dsm = 0, - .dspec = 0, - .reftag = 0, - .apptag = 0, - .appmask = 0, - .storage_tag = 0, - .data_len = count, - .data = buf, - .metadata_len = 0, - .metadata = NULL, - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .result = NULL, - }; + __u64 slba; + __u16 nlb; - if (nvme_bytes_to_lba(n, offset, count, &args.slba, &args.nlb)) + if (nvme_bytes_to_lba(n, offset, count, &slba, &nlb)) return -1; - return nvme_compare(nvme_ns_get_link(n), &args); + return nvme_compare(nvme_ns_get_link(n), nvme_ns_get_nsid(n), slba, 0, 0, nlb, 0, 0, 0, 0, + 0, 0, 0, 0, NULL, 0, NULL, 0, NULL); } int nvme_ns_flush(nvme_ns_t n) diff --git a/test/ioctl/misc.c b/test/ioctl/misc.c index f3cc833e0..f227bd04b 100644 --- a/test/ioctl/misc.c +++ b/test/ioctl/misc.c @@ -831,32 +831,22 @@ static void test_read(void) { __u8 expected_data[512], data[512] = {}; __u32 result = 0; - - struct nvme_io_args args = { - .slba = 0xffffffffff, - .storage_tag = 0xef, - .result = &result, - .data = &data, - .args_size = sizeof(args), - .nsid = TEST_NSID, - .reftag = 0xab, - .data_len = sizeof(data), - .nlb = 0x3, - .control = NVME_IO_FUA, - .apptag = 0x12, - .appmask = 0x34, - .dspec = 0x0, - .dsm = NVME_IO_DSM_LATENCY_LOW, - }; + __u64 slba = 0xffffffffff; + __u16 nlb = 0x3; + __u16 control = NVME_IO_FUA; + __u8 dsm = NVME_IO_DSM_LATENCY_LOW; + __u16 dspec = 0x0; + __u16 apptag = 0x12; + __u16 appmask = 0x34; struct mock_cmd mock_io_cmd = { .opcode = nvme_cmd_read, .nsid = TEST_NSID, - .cdw10 = args.slba & 0xffffffff, - .cdw11 = args.slba >> 32, - .cdw12 = args.nlb | (args.control << 16), - .cdw13 = args.dsm | (args.dspec << 16), - .cdw15 = args.apptag | (args.appmask << 16), + .cdw10 = slba & 0xffffffff, + .cdw11 = slba >> 32, + .cdw12 = nlb | (control << 16), + .cdw13 = dsm | (dspec << 16), + .cdw15 = apptag | (appmask << 16), .data_len = sizeof(expected_data), .out_data = &expected_data, }; @@ -865,7 +855,8 @@ static void test_read(void) arbitrary(&expected_data, sizeof(expected_data)); set_mock_io_cmds(&mock_io_cmd, 1); - err = nvme_read(test_link, &args); + err = nvme_read(test_link, TEST_NSID, slba, 0xef, 0xab, nlb, control, apptag, appmask, + dspec, dsm, 0, 0, 0, &data, sizeof(data), NULL, 0, &result); end_mock_cmds(); check(err == 0, "returned error %d", err); check(result == 0, "returned result %u", result); @@ -875,32 +866,22 @@ static void test_write(void) { __u8 expected_data[512], data[512] = {}; __u32 result = 0; - - struct nvme_io_args args = { - .slba = 0xfffffffabcde, - .storage_tag = 0xab, - .result = &result, - .data = &expected_data, - .args_size = sizeof(args), - .nsid = TEST_NSID, - .reftag = 0xef, - .data_len = sizeof(expected_data), - .nlb = 0x5, - .control = NVME_IO_FUA, - .apptag = 0x59, - .appmask = 0x94, - .dspec = 0xa, - .dsm = NVME_IO_DSM_COMPRESSED, - }; + __u64 slba = 0xfffffffabcde; + __u16 nlb = 0x5; + __u16 control = NVME_IO_FUA; + __u8 dsm = NVME_IO_DSM_COMPRESSED; + __u16 dspec = 0xa; + __u16 apptag = 0x59; + __u16 appmask = 0x94; struct mock_cmd mock_io_cmd = { .opcode = nvme_cmd_write, .nsid = TEST_NSID, - .cdw10 = args.slba & 0xffffffff, - .cdw11 = args.slba >> 32, - .cdw12 = args.nlb | (args.control << 16), - .cdw13 = args.dsm | (args.dspec << 16), - .cdw15 = args.apptag | (args.appmask << 16), + .cdw10 = slba & 0xffffffff, + .cdw11 = slba >> 32, + .cdw12 = nlb | (control << 16), + .cdw13 = dsm | (dspec << 16), + .cdw15 = apptag | (appmask << 16), .data_len = sizeof(data), .in_data = &data, }; @@ -910,7 +891,9 @@ static void test_write(void) arbitrary(&expected_data, sizeof(expected_data)); memcpy(&data, &expected_data, sizeof(expected_data)); set_mock_io_cmds(&mock_io_cmd, 1); - err = nvme_write(test_link, &args); + err = nvme_write(test_link, TEST_NSID, slba, 0xab, 0xef, nlb, control, apptag, appmask, + dspec, dsm, 0, 0, 0, &expected_data, sizeof(expected_data), NULL, 0, + &result); end_mock_cmds(); check(err == 0, "returned error %d", err); check(result == 0, "returned result %u", result); @@ -920,32 +903,22 @@ static void test_compare(void) { __u8 expected_data[512], data[512] = {}; __u32 result = 0; - - struct nvme_io_args args = { - .slba = 0xabcde, - .storage_tag = 0xab, - .result = &result, - .data = &expected_data, - .args_size = sizeof(args), - .nsid = TEST_NSID, - .reftag = 0xff, - .data_len = sizeof(expected_data), - .nlb = 0x0, - .control = NVME_IO_LR, - .apptag = 0x59, - .appmask = 0x94, - .dspec = 0xa, - .dsm = NVME_IO_DSM_COMPRESSED, - }; + __u64 slba = 0xabcde; + __u16 nlb = 0x0; + __u16 control = NVME_IO_LR; + __u8 dsm = NVME_IO_DSM_COMPRESSED; + __u16 dspec = 0xa; + __u16 apptag = 0x59; + __u16 appmask = 0x94; struct mock_cmd mock_io_cmd = { .opcode = nvme_cmd_compare, .nsid = TEST_NSID, - .cdw10 = args.slba & 0xffffffff, - .cdw11 = args.slba >> 32, - .cdw12 = args.nlb | (args.control << 16), - .cdw13 = args.dsm | (args.dspec << 16), - .cdw15 = args.apptag | (args.appmask << 16), + .cdw10 = slba & 0xffffffff, + .cdw11 = slba >> 32, + .cdw12 = nlb | (control << 16), + .cdw13 = dsm | (dspec << 16), + .cdw15 = apptag | (appmask << 16), .data_len = sizeof(data), .in_data = &data, }; @@ -955,7 +928,9 @@ static void test_compare(void) arbitrary(&expected_data, sizeof(expected_data)); memcpy(&data, &expected_data, sizeof(expected_data)); set_mock_io_cmds(&mock_io_cmd, 1); - err = nvme_compare(test_link, &args); + err = nvme_compare(test_link, TEST_NSID, slba, 0xab, 0xff, nlb, control, apptag, appmask, + dspec, dsm, 0, 0, 0, &expected_data, sizeof(expected_data), NULL, 0, + &result); end_mock_cmds(); check(err == 0, "returned error %d", err); check(result == 0, "returned result %u", result); @@ -965,32 +940,22 @@ static void test_write_zeros(void) { __u8 expected_data[512], data[512] = {}; __u32 result = 0; - - struct nvme_io_args args = { - .slba = 0x0, - .storage_tag = 0xab, - .result = &result, - .data = &expected_data, - .args_size = sizeof(args), - .nsid = TEST_NSID, - .reftag = 0xff, - .data_len = sizeof(expected_data), - .nlb = 0xffff, - .control = NVME_IO_LR, - .apptag = 0xfa, - .appmask = 0x72, - .dspec = 0xbb, - .dsm = NVME_IO_DSM_FREQ_ONCE, - }; + __u64 slba = 0x0; + __u16 nlb = 0xffff; + __u16 control = NVME_IO_LR; + __u8 dsm = NVME_IO_DSM_FREQ_ONCE; + __u16 dspec = 0xbb; + __u16 apptag = 0xfa; + __u16 appmask = 0x72; struct mock_cmd mock_io_cmd = { .opcode = nvme_cmd_write_zeroes, .nsid = TEST_NSID, - .cdw10 = args.slba & 0xffffffff, - .cdw11 = args.slba >> 32, - .cdw12 = args.nlb | (args.control << 16), - .cdw13 = args.dsm | (args.dspec << 16), - .cdw15 = args.apptag | (args.appmask << 16), + .cdw10 = slba & 0xffffffff, + .cdw11 = slba >> 32, + .cdw12 = nlb | (control << 16), + .cdw13 = dsm | (dspec << 16), + .cdw15 = apptag | (appmask << 16), .data_len = sizeof(data), .in_data = &data, }; @@ -1000,7 +965,9 @@ static void test_write_zeros(void) arbitrary(&expected_data, sizeof(expected_data)); memcpy(&data, &expected_data, sizeof(expected_data)); set_mock_io_cmds(&mock_io_cmd, 1); - err = nvme_write_zeros(test_link, &args); + err = nvme_write_zeros(test_link, TEST_NSID, slba, 0xab, 0xff, nlb, control, apptag, + appmask, dspec, dsm, 0, 0, 0, &expected_data, sizeof(expected_data), + NULL, 0, &result); end_mock_cmds(); check(err == 0, "returned error %d", err); check(result == 0, "returned result %u", result); @@ -1010,32 +977,22 @@ static void test_write_uncorrectable(void) { __u8 expected_data[512], data[512] = {}; __u32 result = 0; - - struct nvme_io_args args = { - .slba = 0x0, - .storage_tag = 0x0, - .result = &result, - .data = &expected_data, - .args_size = sizeof(args), - .nsid = TEST_NSID, - .reftag = 0x0, - .data_len = sizeof(expected_data), - .nlb = 0x0, - .control = 0x0, - .apptag = 0x0, - .appmask = 0x0, - .dspec = 0x0, - .dsm = 0x0, - }; + __u64 slba = 0x0; + __u16 nlb = 0x0; + __u16 control = 0x0; + __u8 dsm = 0x0; + __u16 dspec = 0x0; + __u16 apptag = 0x0; + __u16 appmask = 0x0; struct mock_cmd mock_io_cmd = { .opcode = nvme_cmd_write_uncor, .nsid = TEST_NSID, - .cdw10 = args.slba & 0xffffffff, - .cdw11 = args.slba >> 32, - .cdw12 = args.nlb | (args.control << 16), - .cdw13 = args.dsm | (args.dspec << 16), - .cdw15 = args.apptag | (args.appmask << 16), + .cdw10 = slba & 0xffffffff, + .cdw11 = slba >> 32, + .cdw12 = nlb | (control << 16), + .cdw13 = dsm | (dspec << 16), + .cdw15 = apptag | (appmask << 16), .data_len = sizeof(data), .in_data = &data, }; @@ -1045,7 +1002,9 @@ static void test_write_uncorrectable(void) arbitrary(&expected_data, sizeof(expected_data)); memcpy(&data, &expected_data, sizeof(expected_data)); set_mock_io_cmds(&mock_io_cmd, 1); - err = nvme_write_uncorrectable(test_link, &args); + err = nvme_write_uncorrectable(test_link, TEST_NSID, slba, 0x0, 0x0, nlb, control, apptag, + appmask, dspec, dsm, 0, 0, 0, &expected_data, + sizeof(expected_data), NULL, 0, &result); end_mock_cmds(); check(err == 0, "returned error %d", err); check(result == 0, "returned result %u", result); @@ -1055,32 +1014,22 @@ static void test_verify(void) { __u8 expected_data[512], data[512] = {}; __u32 result = 0; - - struct nvme_io_args args = { - .slba = 0xffffffffffffffff, - .storage_tag = 0xffffffffffffffff, - .result = &result, - .data = &expected_data, - .args_size = sizeof(args), - .nsid = TEST_NSID, - .reftag = 0xffffffff, - .data_len = sizeof(expected_data), - .nlb = 0xffff, - .control = 0xffff, - .apptag = 0xffff, - .appmask = 0xffff, - .dspec = 0xffff, - .dsm = 0xff, - }; + __u64 slba = 0xffffffffffffffff; + __u16 nlb = 0xffff; + __u16 control = 0xffff; + __u8 dsm = 0xff; + __u16 dspec = 0xffff; + __u16 apptag = 0xffff; + __u16 appmask = 0xffff; struct mock_cmd mock_io_cmd = { .opcode = nvme_cmd_verify, .nsid = TEST_NSID, - .cdw10 = args.slba & 0xffffffff, - .cdw11 = args.slba >> 32, - .cdw12 = args.nlb | (args.control << 16), - .cdw13 = args.dsm | (args.dspec << 16), - .cdw15 = args.apptag | (args.appmask << 16), + .cdw10 = slba & 0xffffffff, + .cdw11 = slba >> 32, + .cdw12 = nlb | (control << 16), + .cdw13 = dsm | (dspec << 16), + .cdw15 = apptag | (appmask << 16), .data_len = sizeof(data), .in_data = &data, }; @@ -1090,7 +1039,9 @@ static void test_verify(void) arbitrary(&expected_data, sizeof(expected_data)); memcpy(&data, &expected_data, sizeof(expected_data)); set_mock_io_cmds(&mock_io_cmd, 1); - err = nvme_verify(test_link, &args); + err = nvme_verify(test_link, TEST_NSID, slba, 0xffffffffffffffff, 0xffffffff, nlb, control, + apptag, appmask, dspec, dsm, 0, 0, 0, &expected_data, + sizeof(expected_data), NULL, 0, &result); end_mock_cmds(); check(err == 0, "returned error %d", err); check(result == 0, "returned result %u", result); From 543b740eac90ebe76332a3a2d71e859738b12779 Mon Sep 17 00:00:00 2001 From: Tokunori Ikegami Date: Mon, 4 Aug 2025 00:36:12 +0900 Subject: [PATCH 31/66] ioctl: add dsm and io commands dword fields To use the fields in nvme_io() and nvme_dsm() functions. Signed-off-by: Tokunori Ikegami --- src/nvme/ioctl.h | 94 +++++++++++++++++++++++++++++++++++++---------- test/ioctl/misc.c | 2 +- 2 files changed, 76 insertions(+), 20 deletions(-) diff --git a/src/nvme/ioctl.h b/src/nvme/ioctl.h index bc275141c..20d873ff9 100644 --- a/src/nvme/ioctl.h +++ b/src/nvme/ioctl.h @@ -337,6 +337,62 @@ enum nvme_cmd_dword_fields { NVME_DSM_CDW11_IDW_MASK = 0x1, NVME_DSM_CDW11_AD_SHIFT = 2, NVME_DSM_CDW11_AD_MASK = 0x1, + NVME_DSM_CDW11_ATTRS_SHIFT = NVME_DSM_CDW11_IDR_SHIFT, + NVME_DSM_CDW11_ATTRS_MASK = (NVME_VAL(DSM_CDW11_IDR) | + NVME_VAL(DSM_CDW11_IDW) | + NVME_VAL(DSM_CDW11_AD)) >> + NVME_DSM_CDW11_IDR_SHIFT, + NVME_NVM_CDW2_ELBTU_SHIFT = 0, + NVME_NVM_CDW2_ELBTU_MASK = 0xffff, + NVME_NVM_CDW3_ELBTU_SHIFT = 0, + NVME_NVM_CDW3_ELBTU_MASK = 0xffffffff, + NVME_NVM_CDW10_SLBAL_SHIFT = 0, + NVME_NVM_CDW10_SLBAL_MASK = 0xffffffff, + NVME_NVM_CDW11_SLBAU_SHIFT = 0, + NVME_NVM_CDW11_SLBAU_MASK = 0xffffffff, + NVME_NVM_CDW12_NLB_SHIFT = 0, + NVME_NVM_CDW12_NLB_MASK = 0xffff, + NVME_NVM_CDW12_CETYPE_SHIFT = 16, + NVME_NVM_CDW12_CETYPE_MASK = 0xf, + NVME_NVM_CDW12_STC_SHIFT = 24, + NVME_NVM_CDW12_STC_MASK = 0x1, + NVME_NVM_CDW12_PRINFO_SHIFT = 26, + NVME_NVM_CDW12_PRINFO_MASK = 0xf, + NVME_NVM_CDW12_FUA_SHIFT = 30, + NVME_NVM_CDW12_FUA_MASK = 0x1, + NVME_NVM_CDW12_LR_SHIFT = 31, + NVME_NVM_CDW12_LR_MASK = 0x1, + NVME_NVM_CDW12_CONTROL_SHIFT = NVME_NVM_CDW12_CETYPE_SHIFT, + NVME_NVM_CDW12_CONTROL_MASK = (NVME_VAL(NVM_CDW12_CETYPE) | + NVME_VAL(NVM_CDW12_STC) | + NVME_VAL(NVM_CDW12_PRINFO) | + NVME_VAL(NVM_CDW12_FUA) | + NVME_VAL(NVM_CDW12_LR)) >> + NVME_NVM_CDW12_CONTROL_SHIFT, + NVME_NVM_CDW13_DSM_AF_SHIFT = 0, + NVME_NVM_CDW13_DSM_AF_MASK = 0xf, + NVME_NVM_CDW13_DSM_AL_SHIFT = 4, + NVME_NVM_CDW13_DSM_AL_MASK = 0x3, + NVME_NVM_CDW13_DSM_SEQREQ_SHIFT = 6, + NVME_NVM_CDW13_DSM_SEQREQ_MASK = 0x1, + NVME_NVM_CDW13_DSM_INCPRS_SHIFT = 7, + NVME_NVM_CDW13_DSM_INCPRS_MASK = 0x1, + NVME_NVM_CDW13_DSM_SHIFT = NVME_NVM_CDW13_DSM_AF_SHIFT, + NVME_NVM_CDW13_DSM_MASK = (NVME_VAL(NVM_CDW13_DSM_AF) | + NVME_VAL(NVM_CDW13_DSM_AL) | + NVME_VAL(NVM_CDW13_DSM_SEQREQ) | + NVME_VAL(NVM_CDW13_DSM_INCPRS)) >> + NVME_NVM_CDW13_DSM_SHIFT, + NVME_NVM_CDW13_CEV_AF_SHIFT = 0, + NVME_NVM_CDW13_CEV_AF_MASK = 0xffff, + NVME_NVM_CDW13_DSPEC_SHIFT = 16, + NVME_NVM_CDW13_DSPEC_MASK = 0xffff, + NVME_NVM_CDW14_ELBTL_SHIFT = 0, + NVME_NVM_CDW14_ELBTL_MASK = 0xffffffff, + NVME_NVM_CDW15_ELBAT_SHIFT = 0, + NVME_NVM_CDW15_ELBAT_MASK = 0xffff, + NVME_NVM_CDW15_ELBATM_SHIFT = 16, + NVME_NVM_CDW15_ELBATM_MASK = 0xffff, }; /** @@ -3987,27 +4043,27 @@ static inline int nvme_set_var_size_tags(__u8 pif, __u8 sts, __u64 reftag, __u64 switch (pif) { case NVME_NVM_PIF_16B_GUARD: - cdw14 = reftag & 0xffffffff; - cdw14 |= ((storage_tag << (32 - sts)) & 0xffffffff); + cdw14 = NVME_SET(reftag, NVM_CDW14_ELBTL); + cdw14 |= NVME_SET(storage_tag << (32 - sts), NVM_CDW14_ELBTL); break; case NVME_NVM_PIF_32B_GUARD: - cdw14 = reftag & 0xffffffff; - cdw3 = reftag >> 32; - cdw14 |= ((storage_tag << (80 - sts)) & 0xffff0000); + cdw14 = NVME_SET(reftag, NVM_CDW14_ELBTL); + cdw3 = NVME_SET(reftag >> 32, NVM_CDW3_ELBTU); + cdw14 |= NVME_SET((storage_tag << (80 - sts)) & 0xffff0000, NVM_CDW14_ELBTL); if (sts >= 48) - cdw3 |= ((storage_tag >> (sts - 48)) & 0xffffffff); + cdw3 |= NVME_SET(storage_tag >> (sts - 48), NVM_CDW3_ELBTU); else - cdw3 |= ((storage_tag << (48 - sts)) & 0xffffffff); - cdw2 = (storage_tag >> (sts - 16)) & 0xffff; + cdw3 |= NVME_SET(storage_tag << (48 - sts), NVM_CDW3_ELBTU); + cdw2 = NVME_SET(storage_tag >> (sts - 16), NVM_CDW2_ELBTU); break; case NVME_NVM_PIF_64B_GUARD: - cdw14 = reftag & 0xffffffff; - cdw3 = (reftag >> 32) & 0xffff; - cdw14 |= ((storage_tag << (48 - sts)) & 0xffffffff); + cdw14 = NVME_SET(reftag, NVM_CDW14_ELBTL); + cdw3 = NVME_SET((reftag >> 32) & 0xffff, NVM_CDW3_ELBTU); + cdw14 |= NVME_SET(storage_tag << (48 - sts), NVM_CDW14_ELBTL); if (sts >= 16) - cdw3 |= ((storage_tag >> (sts - 16)) & 0xffff); + cdw3 |= NVME_SET((storage_tag >> (sts - 16)) & 0xffff, NVM_CDW3_ELBTU); else - cdw3 |= ((storage_tag << (16 - sts)) & 0xffff); + cdw3 |= NVME_SET((storage_tag << (16 - sts)) & 0xffff, NVM_CDW3_ELBTU); break; default: perror("Unsupported Protection Information Format"); @@ -4065,11 +4121,11 @@ static inline int nvme_io(nvme_link_t l, __u8 opcode, __u32 nsid, __u64 slba, __ __u16 dspec, __u8 dsm, __u64 reftag_u64, __u8 sts, __u8 pif, void *data, __u32 data_len, void *metadata, __u32 metadata_len, __u32 *result) { - __u32 cdw10 = slba & 0xffffffff; - __u32 cdw11 = slba >> 32; - __u32 cdw12 = nlb | (control << 16); - __u32 cdw13 = dsm | (dspec << 16); - __u32 cdw15 = apptag | (appmask << 16); + __u32 cdw10 = NVME_SET(slba, NVM_CDW10_SLBAL); + __u32 cdw11 = NVME_SET(slba >> 32, NVM_CDW11_SLBAU); + __u32 cdw12 = NVME_SET(nlb, NVM_CDW12_NLB) | NVME_SET(control, NVM_CDW12_CONTROL); + __u32 cdw13 = NVME_SET(dsm, NVM_CDW13_DSM) | NVME_SET(dspec, NVM_CDW13_DSPEC); + __u32 cdw15 = NVME_SET(apptag, NVM_CDW15_ELBAT) | NVME_SET(appmask, NVM_CDW15_ELBATM); struct nvme_passthru_cmd cmd = { .opcode = opcode, @@ -4428,7 +4484,7 @@ static inline int nvme_dsm(nvme_link_t l, __u32 nsid, __u16 nr_ranges, __u32 *result) { __u32 cdw10 = NVME_SET(nr_ranges - 1, DSM_CDW10_NR); - __u32 cdw11 = attrs; + __u32 cdw11 = NVME_SET(attrs, DSM_CDW11_ATTRS); struct nvme_passthru_cmd cmd = { .opcode = nvme_cmd_dsm, diff --git a/test/ioctl/misc.c b/test/ioctl/misc.c index f227bd04b..f4cffb085 100644 --- a/test/ioctl/misc.c +++ b/test/ioctl/misc.c @@ -1016,7 +1016,7 @@ static void test_verify(void) __u32 result = 0; __u64 slba = 0xffffffffffffffff; __u16 nlb = 0xffff; - __u16 control = 0xffff; + __u16 control = 0xfd0f; __u8 dsm = 0xff; __u16 dspec = 0xffff; __u16 apptag = 0xffff; From 93bacb9ea9265b878a2930cceda44a5ee2fe4e3c Mon Sep 17 00:00:00 2001 From: Tokunori Ikegami Date: Mon, 4 Aug 2025 21:11:17 +0900 Subject: [PATCH 32/66] ioctl: nvme_copy use nvme_passthru_cmd directly Drop struct nvme_copy_args. Signed-off-by: Tokunori Ikegami --- src/libnvme.map | 1 - src/nvme/api-types.h | 43 -------------------- src/nvme/ioctl.c | 49 ---------------------- src/nvme/ioctl.h | 97 ++++++++++++++++++++++++++++++++++++++++++-- test/ioctl/misc.c | 41 ++++++++----------- 5 files changed, 109 insertions(+), 122 deletions(-) diff --git a/src/libnvme.map b/src/libnvme.map index 5ddb5f1cb..af5253258 100644 --- a/src/libnvme.map +++ b/src/libnvme.map @@ -8,7 +8,6 @@ LIBNVME_2_0 { nvme_admin_passthru; nvme_capacity_mgmt; nvme_close; - nvme_copy; nvme_create_ctrl; nvme_create_root; nvme_ctrl_config_match; diff --git a/src/nvme/api-types.h b/src/nvme/api-types.h index 0960f8ce1..1a8c73394 100644 --- a/src/nvme/api-types.h +++ b/src/nvme/api-types.h @@ -318,49 +318,6 @@ struct nvme_virtual_mgmt_args { __u16 nr; }; -/** - * struct nvme_copy_args - Arguments for the NVMe Copy command - * @sdlba: Start destination LBA - * @result: The command completion result from CQE dword0 - * @copy: Range description - * @args_size: Size of &struct nvme_copy_args - * @timeout: Timeout in ms - * @nsid: Namespace identifier - * @ilbrt: Initial logical block reference tag - * @lr: Limited retry - * @fua: Force unit access - * @nr: Number of ranges - * @dspec: Directive specific value - * @lbatm: Logical block application tag mask - * @lbat: Logical block application tag - * @prinfor: Protection information field for read - * @prinfow: Protection information field for write - * @dtype: Directive type - * @format: Descriptor format - * @ilbrt_u64: Initial logical block reference tag - 8 byte - * version required for enhanced protection info - */ -struct nvme_copy_args { - __u64 sdlba; - __u32 *result; - struct nvme_copy_range *copy; - int args_size; - __u32 timeout; - __u32 nsid; - __u32 ilbrt; - int lr; - int fua; - __u16 nr; - __u16 dspec; - __u16 lbatm; - __u16 lbat; - __u8 prinfor; - __u8 prinfow; - __u8 dtype; - __u8 format; - __u64 ilbrt_u64; -}; - /** * struct nvme_resv_acquire_args - Arguments for the NVMe Reservation Acquire Command * @nrkey: The reservation key to be unregistered from the namespace if diff --git a/src/nvme/ioctl.c b/src/nvme/ioctl.c index b5294ad8e..22ff645ac 100644 --- a/src/nvme/ioctl.c +++ b/src/nvme/ioctl.c @@ -1315,55 +1315,6 @@ int nvme_io_passthru(nvme_link_t l, __u8 opcode, __u8 flags, __u16 rsvd, timeout_ms, result); } -int nvme_copy(nvme_link_t l, struct nvme_copy_args *args) -{ - const size_t size_v1 = sizeof_args(struct nvme_copy_args, format, __u64); - const size_t size_v2 = sizeof_args(struct nvme_copy_args, ilbrt_u64, __u64); - __u32 cdw3, cdw12, cdw14, data_len; - - if (args->args_size < size_v1 || args->args_size > size_v2) - return -EINVAL; - - cdw12 = ((args->nr - 1) & 0xff) | ((args->format & 0xf) << 8) | - ((args->prinfor & 0xf) << 12) | ((args->dtype & 0xf) << 20) | - ((args->prinfow & 0xf) << 26) | ((args->fua & 0x1) << 30) | - ((args->lr & 0x1) << 31); - - if (args->args_size == size_v1) { - cdw3 = 0; - cdw14 = args->ilbrt; - } else { - cdw3 = (args->ilbrt_u64 >> 32) & 0xffffffff; - cdw14 = args->ilbrt_u64 & 0xffffffff; - } - - if (args->format == 1) - data_len = args->nr * sizeof(struct nvme_copy_range_f1); - else if (args->format == 2) - data_len = args->nr * sizeof(struct nvme_copy_range_f2); - else if (args->format == 3) - data_len = args->nr * sizeof(struct nvme_copy_range_f3); - else - data_len = args->nr * sizeof(struct nvme_copy_range); - - struct nvme_passthru_cmd cmd = { - .opcode = nvme_cmd_copy, - .nsid = args->nsid, - .addr = (__u64)(uintptr_t)args->copy, - .data_len = data_len, - .cdw3 = cdw3, - .cdw10 = args->sdlba & 0xffffffff, - .cdw11 = args->sdlba >> 32, - .cdw12 = cdw12, - .cdw13 = (args->dspec & 0xffff) << 16, - .cdw14 = cdw14, - .cdw15 = (args->lbatm << 16) | args->lbat, - .timeout_ms = args->timeout, - }; - - return nvme_submit_io_passthru(l, &cmd, args->result); -} - int nvme_resv_acquire(nvme_link_t l, struct nvme_resv_acquire_args *args) { __le64 payload[2] = { diff --git a/src/nvme/ioctl.h b/src/nvme/ioctl.h index 20d873ff9..c2c0f9dea 100644 --- a/src/nvme/ioctl.h +++ b/src/nvme/ioctl.h @@ -383,8 +383,8 @@ enum nvme_cmd_dword_fields { NVME_VAL(NVM_CDW13_DSM_SEQREQ) | NVME_VAL(NVM_CDW13_DSM_INCPRS)) >> NVME_NVM_CDW13_DSM_SHIFT, - NVME_NVM_CDW13_CEV_AF_SHIFT = 0, - NVME_NVM_CDW13_CEV_AF_MASK = 0xffff, + NVME_NVM_CDW13_CEV_SHIFT = 0, + NVME_NVM_CDW13_CEV_MASK = 0xffff, NVME_NVM_CDW13_DSPEC_SHIFT = 16, NVME_NVM_CDW13_DSPEC_MASK = 0xffff, NVME_NVM_CDW14_ELBTL_SHIFT = 0, @@ -393,6 +393,38 @@ enum nvme_cmd_dword_fields { NVME_NVM_CDW15_ELBAT_MASK = 0xffff, NVME_NVM_CDW15_ELBATM_SHIFT = 16, NVME_NVM_CDW15_ELBATM_MASK = 0xffff, + NVME_COPY_CDW3_LBTU_SHIFT = 0, + NVME_COPY_CDW3_LBTU_MASK = 0xffffffff, + NVME_COPY_CDW10_SDLBAL_SHIFT = 0, + NVME_COPY_CDW10_SDLBAL_MASK = 0xffffffff, + NVME_COPY_CDW11_SDLBAU_SHIFT = 0, + NVME_COPY_CDW11_SDLBAU_MASK = 0xffffffff, + NVME_COPY_CDW12_NR_SHIFT = 0, + NVME_COPY_CDW12_NR_MASK = 0xff, + NVME_COPY_CDW12_DESFMT_SHIFT = 8, + NVME_COPY_CDW12_DESFMT_MASK = 0xf, + NVME_COPY_CDW12_PRINFOR_SHIFT = 12, + NVME_COPY_CDW12_PRINFOR_MASK = 0xf, + NVME_COPY_CDW12_CETYPE_SHIFT = 16, + NVME_COPY_CDW12_CETYPE_MASK = 0xf, + NVME_COPY_CDW12_DTYPE_SHIFT = 20, + NVME_COPY_CDW12_DTYPE_MASK = 0xf, + NVME_COPY_CDW12_STCW_SHIFT = 24, + NVME_COPY_CDW12_STCW_MASK = 0x1, + NVME_COPY_CDW12_STCR_SHIFT = 25, + NVME_COPY_CDW12_STCR_MASK = 0x1, + NVME_COPY_CDW12_PRINFOW_SHIFT = 26, + NVME_COPY_CDW12_PRINFOW_MASK = 0xf, + NVME_COPY_CDW12_FUA_SHIFT = 30, + NVME_COPY_CDW12_FUA_MASK = 0x1, + NVME_COPY_CDW12_LR_SHIFT = 31, + NVME_COPY_CDW12_LR_MASK = 0x1, + NVME_COPY_CDW14_LBTL_SHIFT = 0, + NVME_COPY_CDW14_LBTL_MASK = 0xffffffff, + NVME_COPY_CDW15_LBAT_SHIFT = 0, + NVME_COPY_CDW15_LBAT_MASK = 0xffff, + NVME_COPY_CDW15_LBATM_SHIFT = 16, + NVME_COPY_CDW15_LBATM_MASK = 0xffff, }; /** @@ -4501,12 +4533,69 @@ static inline int nvme_dsm(nvme_link_t l, __u32 nsid, __u16 nr_ranges, /** * nvme_copy() - Copy command * @l: Link handle - * @args: &struct nvme_copy_args argument structure + * @nsid: Namespace identifier + * @sdlba: Start destination LBA + * @ilbrt: Initial logical block reference tag + * @lr: Limited retry + * @fua: Force unit access + * @dspec: Directive specific value + * @lbatm: Logical block application tag mask + * @lbat: Logical block application tag + * @prinfor: Protection information field for read + * @prinfow: Protection information field for write + * @dtype: Directive type + * @format: Descriptor format + * @ilbrt_u64: Initial logical block reference tag - 8 byte + * version required for enhanced protection info + * @copy: Range description + * @nr: Number of ranges + * @result: The command completion result from CQE dword0 * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_copy(nvme_link_t l, struct nvme_copy_args *args); +static inline int nvme_copy(nvme_link_t l, __u32 nsid, __u64 sdlba, __u32 ilbrt, int lr, int fua, + __u16 dspec, __u16 lbatm, __u16 lbat, __u8 prinfor, __u8 prinfow, + __u8 dtype, __u8 format, __u64 ilbrt_u64, struct nvme_copy_range *copy, + __u16 nr, __u32 *result) +{ + __u32 cdw3 = NVME_SET(ilbrt_u64 >> 32, COPY_CDW3_LBTU); + __u32 cdw10 = NVME_SET(sdlba, COPY_CDW10_SDLBAL); + __u32 cdw11 = NVME_SET(sdlba >> 32, COPY_CDW11_SDLBAU); + __u32 cdw12 = NVME_SET(nr - 1, COPY_CDW12_NR) | NVME_SET(format, COPY_CDW12_DESFMT) | + NVME_SET(prinfor, COPY_CDW12_PRINFOR) | NVME_SET(dtype, COPY_CDW12_DTYPE) | + NVME_SET(prinfow, COPY_CDW12_PRINFOW) | NVME_SET(fua, COPY_CDW12_FUA) | + NVME_SET(lr, COPY_CDW12_LR); + __u32 cdw13 = NVME_SET(dspec, NVM_CDW13_DSPEC); + __u32 cdw14 = NVME_SET(ilbrt_u64, COPY_CDW14_LBTL); + __u32 cdw15 = NVME_SET(lbatm, COPY_CDW15_LBATM) | NVME_SET(lbat, COPY_CDW15_LBAT); + __u32 data_len; + + if (format == 1) + data_len = nr * sizeof(struct nvme_copy_range_f1); + else if (format == 2) + data_len = nr * sizeof(struct nvme_copy_range_f2); + else if (format == 3) + data_len = nr * sizeof(struct nvme_copy_range_f3); + else + data_len = nr * sizeof(struct nvme_copy_range); + + struct nvme_passthru_cmd cmd = { + .opcode = nvme_cmd_copy, + .nsid = nsid, + .cdw3 = cdw3, + .addr = (__u64)(uintptr_t)copy, + .data_len = data_len, + .cdw10 = cdw10, + .cdw11 = cdw11, + .cdw12 = cdw12, + .cdw13 = cdw13, + .cdw14 = cdw14, + .cdw15 = cdw15, + }; + + return nvme_submit_io_passthru(l, &cmd, result); +} /** * nvme_resv_acquire() - Send an nvme reservation acquire diff --git a/test/ioctl/misc.c b/test/ioctl/misc.c index f4cffb085..06883763d 100644 --- a/test/ioctl/misc.c +++ b/test/ioctl/misc.c @@ -1079,43 +1079,34 @@ static void test_dsm(void) static void test_copy(void) { - __u32 result = 0; - __u16 nr = 0x12; - int copy_size = sizeof(struct nvme_copy_range) * nr; + __u16 nr = 0x12, dspec = 0, lbatm = 0, lbat = 0; + int copy_size = sizeof(struct nvme_copy_range) * nr, lr = 0, fua = 0, err; + __u8 prinfor = 0, prinfow = 0, dtype = 0, format = 0xf; + __u64 sdlba = 0xfffff, ilbrt_u64 = 0; + __u32 result = 0, ilbrt = 0; _cleanup_free_ struct nvme_copy_range *copy = NULL; copy = malloc(copy_size); check(copy, "copy: ENOMEM"); - struct nvme_copy_args args = { - .sdlba = 0xfffff, - .result = &result, - .copy = copy, - .args_size = sizeof(args), - .nsid = TEST_NSID, - .nr = nr, - .format = 0xf, - }; - struct mock_cmd mock_io_cmd = { .opcode = nvme_cmd_copy, .nsid = TEST_NSID, - .cdw10 = args.sdlba & 0xffffffff, - .cdw11 = args.sdlba >> 32, - .cdw12 = ((args.nr - 1) & 0xff) | ((args.format & 0xf) << 8) | - ((args.prinfor & 0xf) << 12) | - ((args.dtype & 0xf) << 20) | - ((args.prinfow & 0xf) << 26) | - ((args.fua & 0x1) << 30) | ((args.lr & 0x1) << 31), - .data_len = args.nr * sizeof(struct nvme_copy_range), - .in_data = args.copy, + .cdw10 = sdlba & 0xffffffff, + .cdw11 = sdlba >> 32, + .cdw12 = ((nr - 1) & 0xff) | ((format & 0xf) << 8) | + ((prinfor & 0xf) << 12) | + ((dtype & 0xf) << 20) | + ((prinfow & 0xf) << 26) | + ((fua & 0x1) << 30) | ((lr & 0x1) << 31), + .data_len = nr * sizeof(struct nvme_copy_range), + .in_data = copy, }; - int err; - set_mock_io_cmds(&mock_io_cmd, 1); - err = nvme_copy(test_link, &args); + err = nvme_copy(test_link, TEST_NSID, sdlba, ilbrt, lr, fua, dspec, lbatm, lbat, prinfor, + prinfow, dtype, format, ilbrt_u64, copy, nr, &result); end_mock_cmds(); check(err == 0, "returned error %d", err); check(result == 0, "returned result %u", result); From 54589e33e6e8fe2993813938dcda913a03aeb7af Mon Sep 17 00:00:00 2001 From: Daniel Wagner Date: Thu, 11 Sep 2025 10:53:46 +0200 Subject: [PATCH 33/66] ioctl: update nvme_copy to latest spec Besides adding missing arguments, follow the nvme_io API for storage and app tags. Signed-off-by: Daniel Wagner --- src/nvme/ioctl.h | 91 ++++++++++++++++++++++++++++++----------------- test/ioctl/misc.c | 21 ++++++----- 2 files changed, 71 insertions(+), 41 deletions(-) diff --git a/src/nvme/ioctl.h b/src/nvme/ioctl.h index c2c0f9dea..0665d7bd5 100644 --- a/src/nvme/ioctl.h +++ b/src/nvme/ioctl.h @@ -4535,65 +4535,90 @@ static inline int nvme_dsm(nvme_link_t l, __u32 nsid, __u16 nr_ranges, * @l: Link handle * @nsid: Namespace identifier * @sdlba: Start destination LBA - * @ilbrt: Initial logical block reference tag - * @lr: Limited retry + * @nr: Number of ranges + * @desfmt: Descriptor format + * @prinfor: Protection information field for read + * @prinfow: Protection information field for write + * @cetype: Command Extension Type + * @dtype: Directive Type + * @stcw: Storage Tag Check Write + * @stcr: Storage Tag Check Read * @fua: Force unit access + * @lr: Limited retry + * @cev: Command Extension Value * @dspec: Directive specific value - * @lbatm: Logical block application tag mask + * @sts: Storage tag size in bits, set by namespace Extended LBA Format + * @pif: Protection information format, determines how variable sized + * storage_tag and reftag are put into dwords 2, 3, and 14. Set by + * namespace Extended LBA Format. + * @storage_tag: This filed specifies Variable Sized Expected Logical Block + * Storage Tag (ELBST) or Logical Block Storage Tag (LBST) + * @reftag: This field specifies the variable sized Expected Initial + * Logical Block Reference Tag (EILBRT) or Initial Logical Block + * Reference Tag (ILBRT). Used only if the namespace is formatted + * to use end-to-end protection information. * @lbat: Logical block application tag - * @prinfor: Protection information field for read - * @prinfow: Protection information field for write - * @dtype: Directive type - * @format: Descriptor format - * @ilbrt_u64: Initial logical block reference tag - 8 byte - * version required for enhanced protection info - * @copy: Range description - * @nr: Number of ranges + * @lbatm: Logical block application tag mask + * @cpydsc: Range description * @result: The command completion result from CQE dword0 * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -static inline int nvme_copy(nvme_link_t l, __u32 nsid, __u64 sdlba, __u32 ilbrt, int lr, int fua, - __u16 dspec, __u16 lbatm, __u16 lbat, __u8 prinfor, __u8 prinfow, - __u8 dtype, __u8 format, __u64 ilbrt_u64, struct nvme_copy_range *copy, - __u16 nr, __u32 *result) +static inline int nvme_copy(nvme_link_t l, __u32 nsid, __u64 sdlba, __u16 nr, __u8 desfmt, + __u8 prinfor, __u8 prinfow, __u8 cetype, __u8 dtype, bool stcw, + bool stcr, bool fua, bool lr, __u16 cev, __u16 dspec, + __u8 sts, __u8 pif, __u64 storage_tag, __u32 reftag, + __u16 lbat, __u16 lbatm, void *cpydsc, __u32 *result) { - __u32 cdw3 = NVME_SET(ilbrt_u64 >> 32, COPY_CDW3_LBTU); __u32 cdw10 = NVME_SET(sdlba, COPY_CDW10_SDLBAL); __u32 cdw11 = NVME_SET(sdlba >> 32, COPY_CDW11_SDLBAU); - __u32 cdw12 = NVME_SET(nr - 1, COPY_CDW12_NR) | NVME_SET(format, COPY_CDW12_DESFMT) | - NVME_SET(prinfor, COPY_CDW12_PRINFOR) | NVME_SET(dtype, COPY_CDW12_DTYPE) | - NVME_SET(prinfow, COPY_CDW12_PRINFOW) | NVME_SET(fua, COPY_CDW12_FUA) | + __u32 cdw12 = NVME_SET(nr - 1, COPY_CDW12_NR) | + NVME_SET(desfmt, COPY_CDW12_DESFMT) | + NVME_SET(prinfor, COPY_CDW12_PRINFOR) | + NVME_SET(cetype, COPY_CDW12_CETYPE) | + NVME_SET(dtype, COPY_CDW12_DTYPE) | + NVME_SET(stcw, COPY_CDW12_STCW) | + NVME_SET(stcr, COPY_CDW12_STCR) | + NVME_SET(prinfow, COPY_CDW12_PRINFOW) | + NVME_SET(fua, COPY_CDW12_FUA) | NVME_SET(lr, COPY_CDW12_LR); - __u32 cdw13 = NVME_SET(dspec, NVM_CDW13_DSPEC); - __u32 cdw14 = NVME_SET(ilbrt_u64, COPY_CDW14_LBTL); - __u32 cdw15 = NVME_SET(lbatm, COPY_CDW15_LBATM) | NVME_SET(lbat, COPY_CDW15_LBAT); + __u32 cdw13 = NVME_SET(cev, NVM_CDW13_CEV) | + NVME_SET(dspec, NVM_CDW13_DSPEC); + __u32 cdw15 = NVME_SET(lbat, COPY_CDW15_LBAT) | + NVME_SET(lbatm, COPY_CDW15_LBATM); __u32 data_len; - if (format == 1) - data_len = nr * sizeof(struct nvme_copy_range_f1); - else if (format == 2) - data_len = nr * sizeof(struct nvme_copy_range_f2); - else if (format == 3) - data_len = nr * sizeof(struct nvme_copy_range_f3); - else - data_len = nr * sizeof(struct nvme_copy_range); + switch (desfmt) { + case 1: + data_len = nr * sizeof(struct nvme_copy_range_f1); + break; + case 2: + data_len = nr * sizeof(struct nvme_copy_range_f2); + break; + case 3: + data_len = nr * sizeof(struct nvme_copy_range_f3); + break; + default: + data_len = nr * sizeof(struct nvme_copy_range); + } struct nvme_passthru_cmd cmd = { .opcode = nvme_cmd_copy, .nsid = nsid, - .cdw3 = cdw3, - .addr = (__u64)(uintptr_t)copy, + .addr = (__u64)(uintptr_t)cpydsc, .data_len = data_len, .cdw10 = cdw10, .cdw11 = cdw11, .cdw12 = cdw12, .cdw13 = cdw13, - .cdw14 = cdw14, .cdw15 = cdw15, }; + if (nvme_set_var_size_tags(pif, sts, reftag, storage_tag, &cmd.cdw2, &cmd.cdw3, + &cmd.cdw14)) + return -EINVAL; + return nvme_submit_io_passthru(l, &cmd, result); } diff --git a/test/ioctl/misc.c b/test/ioctl/misc.c index 06883763d..a3a2010e8 100644 --- a/test/ioctl/misc.c +++ b/test/ioctl/misc.c @@ -1079,11 +1079,13 @@ static void test_dsm(void) static void test_copy(void) { - __u16 nr = 0x12, dspec = 0, lbatm = 0, lbat = 0; - int copy_size = sizeof(struct nvme_copy_range) * nr, lr = 0, fua = 0, err; - __u8 prinfor = 0, prinfow = 0, dtype = 0, format = 0xf; - __u64 sdlba = 0xfffff, ilbrt_u64 = 0; - __u32 result = 0, ilbrt = 0; + __u16 nr = 0x12, cev = 0, dspec = 0, lbat = 0, lbatm = 0; + int copy_size = sizeof(struct nvme_copy_range) * nr, err; + bool prinfor = false, prinfow = false, stcw = false, + stcr = false, fua = false, lr = false; + __u8 cetype = 0, dtype = 0, desfmt = 0xf, sts = 0, pif = 0; + __u64 sdlba = 0xfffff, storage_tag = 0; + __u32 reftag = 0, result = 0; _cleanup_free_ struct nvme_copy_range *copy = NULL; @@ -1095,7 +1097,7 @@ static void test_copy(void) .nsid = TEST_NSID, .cdw10 = sdlba & 0xffffffff, .cdw11 = sdlba >> 32, - .cdw12 = ((nr - 1) & 0xff) | ((format & 0xf) << 8) | + .cdw12 = ((nr - 1) & 0xff) | ((desfmt & 0xf) << 8) | ((prinfor & 0xf) << 12) | ((dtype & 0xf) << 20) | ((prinfow & 0xf) << 26) | @@ -1105,8 +1107,11 @@ static void test_copy(void) }; set_mock_io_cmds(&mock_io_cmd, 1); - err = nvme_copy(test_link, TEST_NSID, sdlba, ilbrt, lr, fua, dspec, lbatm, lbat, prinfor, - prinfow, dtype, format, ilbrt_u64, copy, nr, &result); + err = nvme_copy(test_link, TEST_NSID, sdlba, nr, desfmt, + prinfor, prinfow, cetype, dtype, stcw, stcr, + fua, lr, cev, dspec, + sts, pif, storage_tag, reftag, lbat, lbatm, + (void *)copy, &result); end_mock_cmds(); check(err == 0, "returned error %d", err); check(result == 0, "returned result %u", result); From 7a8dfef056c4e1d69f08a8dfbe56912a5d2496a7 Mon Sep 17 00:00:00 2001 From: Tokunori Ikegami Date: Sun, 10 Aug 2025 21:16:38 +0900 Subject: [PATCH 34/66] ioctl: nvme_resv_acquire use nvme_passthru_cmd directly Drop struct nvme_resv_acquire_args. Signed-off-by: Tokunori Ikegami [wagi: reorder and missing arguments] Signed-off-by: Daniel Wagner --- src/libnvme.map | 1 - src/nvme/api-types.h | 25 ------------------------- src/nvme/ioctl.c | 25 ------------------------- src/nvme/ioctl.h | 34 ++++++++++++++++++++++++++++++++-- test/ioctl/misc.c | 26 ++++++++------------------ 5 files changed, 40 insertions(+), 71 deletions(-) diff --git a/src/libnvme.map b/src/libnvme.map index af5253258..5d9f2211b 100644 --- a/src/libnvme.map +++ b/src/libnvme.map @@ -273,7 +273,6 @@ LIBNVME_2_0 { nvme_read_key; nvme_refresh_topology; nvme_rescan_ctrl; - nvme_resv_acquire; nvme_resv_register; nvme_resv_release; nvme_resv_report; diff --git a/src/nvme/api-types.h b/src/nvme/api-types.h index 1a8c73394..285531c84 100644 --- a/src/nvme/api-types.h +++ b/src/nvme/api-types.h @@ -318,31 +318,6 @@ struct nvme_virtual_mgmt_args { __u16 nr; }; -/** - * struct nvme_resv_acquire_args - Arguments for the NVMe Reservation Acquire Command - * @nrkey: The reservation key to be unregistered from the namespace if - * the action is preempt - * @iekey: Set to ignore the existing key - * @result: The command completion result from CQE dword0 - * @args_size: Size of &struct nvme_resv_acquire_args - * @timeout: Timeout in ms - * @nsid: Namespace identifier - * @rtype: The type of reservation to be create, see &enum nvme_resv_rtype - * @racqa: The action that is performed by the command, see &enum nvme_resv_racqa - * @crkey: The current reservation key associated with the host - */ -struct nvme_resv_acquire_args { - __u64 crkey; - __u64 nrkey; - __u32 *result; - int args_size; - __u32 timeout; - __u32 nsid; - enum nvme_resv_rtype rtype; - enum nvme_resv_racqa racqa; - bool iekey; -}; - /** * struct nvme_resv_register_args - Arguments for the NVMe Reservation Register command * @crkey: The current reservation key associated with the host diff --git a/src/nvme/ioctl.c b/src/nvme/ioctl.c index 22ff645ac..f158ff688 100644 --- a/src/nvme/ioctl.c +++ b/src/nvme/ioctl.c @@ -1315,31 +1315,6 @@ int nvme_io_passthru(nvme_link_t l, __u8 opcode, __u8 flags, __u16 rsvd, timeout_ms, result); } -int nvme_resv_acquire(nvme_link_t l, struct nvme_resv_acquire_args *args) -{ - __le64 payload[2] = { - cpu_to_le64(args->crkey), - cpu_to_le64(args->nrkey) - }; - __u32 cdw10 = (args->racqa & 0x7) | - (args->iekey ? 1 << 3 : 0) | - (args->rtype << 8); - - struct nvme_passthru_cmd cmd = { - .opcode = nvme_cmd_resv_acquire, - .nsid = args->nsid, - .cdw10 = cdw10, - .data_len = sizeof(payload), - .addr = (__u64)(uintptr_t)(payload), - .timeout_ms = args->timeout, - }; - - if (args->args_size < sizeof(*args)) - return -EINVAL; - - return nvme_submit_io_passthru(l, &cmd, args->result); -} - int nvme_resv_register(nvme_link_t l, struct nvme_resv_register_args *args) { __le64 payload[2] = { diff --git a/src/nvme/ioctl.h b/src/nvme/ioctl.h index 0665d7bd5..15524a81b 100644 --- a/src/nvme/ioctl.h +++ b/src/nvme/ioctl.h @@ -4625,7 +4625,16 @@ static inline int nvme_copy(nvme_link_t l, __u32 nsid, __u64 sdlba, __u16 nr, __ /** * nvme_resv_acquire() - Send an nvme reservation acquire * @l: Link handle - * @args: &struct nvme_resv_acquire argument structure + * @nsid: Namespace identifier + * @racqa: The action that is performed by the command, see &enum nvme_resv_racqa + * @iekey: Set to ignore the existing key + * @disnsrs: Disperse Namespace Reservation Support + * @rtype: The type of reservation to be create, see &enum nvme_resv_rtype + * @crkey: The current reservation key associated with the host + * @prkey: Preempt Reserveration Key + * @nrkey: The reservation key to be unregistered from the namespace if + * the action is preempt + * @result: The command completion result from CQE dword0 * * The Reservation Acquire command acquires a reservation on a namespace, * preempt a reservation held on a namespace, and abort a reservation held on a @@ -4634,7 +4643,28 @@ static inline int nvme_copy(nvme_link_t l, __u32 nsid, __u64 sdlba, __u16 nr, __ * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_resv_acquire(nvme_link_t l, struct nvme_resv_acquire_args *args); +static inline int nvme_resv_acquire(nvme_link_t l, __u32 nsid, enum nvme_resv_racqa racqa, + bool iekey, bool disnsrs, enum nvme_resv_rtype rtype, + __u16 prkey, __u64 crkey, __u64 nrkey, + __u32 *result) + +{ + __le64 payload[2] = { + htole64(crkey), + htole64(nrkey) + }; + __u32 cdw10 = (racqa & 0x7) | (iekey ? 1 << 3 : 0) | (rtype << 8); + + struct nvme_passthru_cmd cmd = { + .opcode = nvme_cmd_resv_acquire, + .nsid = nsid, + .addr = (__u64)(uintptr_t)(payload), + .data_len = sizeof(payload), + .cdw10 = cdw10, + }; + + return nvme_submit_io_passthru(l, &cmd, result); +} /** * nvme_resv_register() - Send an nvme reservation register diff --git a/test/ioctl/misc.c b/test/ioctl/misc.c index a3a2010e8..4bc4f7e9a 100644 --- a/test/ioctl/misc.c +++ b/test/ioctl/misc.c @@ -1119,34 +1119,24 @@ static void test_copy(void) static void test_resv_acquire(void) { - __u32 result = 0; - - struct nvme_resv_acquire_args args = { - .crkey = 0, - .nrkey = 0, - .result = &result, - .args_size = sizeof(args), - .nsid = TEST_NSID, - .rtype = NVME_RESERVATION_RTYPE_EAAR, - .racqa = NVME_RESERVATION_RACQA_PREEMPT, - .iekey = true, - }; - + enum nvme_resv_rtype rtype = NVME_RESERVATION_RTYPE_EAAR; + enum nvme_resv_racqa racqa = NVME_RESERVATION_RACQA_PREEMPT; __le64 payload[2] = { 0 }; + bool iekey = true; + __u32 result = 0; + int err; struct mock_cmd mock_io_cmd = { .opcode = nvme_cmd_resv_acquire, .nsid = TEST_NSID, - .cdw10 = (args.racqa & 0x7) | (args.iekey ? 1 << 3 : 0) | - (args.rtype << 8), + .cdw10 = (racqa & 0x7) | (iekey ? 1 << 3 : 0) | (rtype << 8), .data_len = sizeof(payload), .in_data = payload, }; - int err; - set_mock_io_cmds(&mock_io_cmd, 1); - err = nvme_resv_acquire(test_link, &args); + err = nvme_resv_acquire(test_link, TEST_NSID, racqa, iekey, + false, rtype, 0, 0, 0, &result); end_mock_cmds(); check(err == 0, "returned error %d", err); check(result == 0, "returned result %u", result); From 4d92dba5e089755a14a93ad749a4d1cb672bbbf6 Mon Sep 17 00:00:00 2001 From: Tokunori Ikegami Date: Sun, 10 Aug 2025 22:45:42 +0900 Subject: [PATCH 35/66] ioctl: nvme_resv_register use nvme_passthru_cmd directly Drop struct nvme_resv_register_args. Signed-off-by: Tokunori Ikegami [wagi: reorder and added missing arguments] Signed-off-by: Daniel Wagner --- src/libnvme.map | 1 - src/nvme/api-types.h | 25 ------------------------- src/nvme/ioctl.c | 25 ------------------------- src/nvme/ioctl.h | 31 +++++++++++++++++++++++++++++-- test/ioctl/misc.c | 26 ++++++++------------------ 5 files changed, 37 insertions(+), 71 deletions(-) diff --git a/src/libnvme.map b/src/libnvme.map index 5d9f2211b..8433ab88c 100644 --- a/src/libnvme.map +++ b/src/libnvme.map @@ -273,7 +273,6 @@ LIBNVME_2_0 { nvme_read_key; nvme_refresh_topology; nvme_rescan_ctrl; - nvme_resv_register; nvme_resv_release; nvme_resv_report; nvme_revoke_tls_key; diff --git a/src/nvme/api-types.h b/src/nvme/api-types.h index 285531c84..002c19797 100644 --- a/src/nvme/api-types.h +++ b/src/nvme/api-types.h @@ -318,31 +318,6 @@ struct nvme_virtual_mgmt_args { __u16 nr; }; -/** - * struct nvme_resv_register_args - Arguments for the NVMe Reservation Register command - * @crkey: The current reservation key associated with the host - * @nrkey: The new reservation key to be register if action is register or - * replace - * @result: The command completion result from CQE dword0 - * @args_size: Size of &struct nvme_resv_register_args - * @nsid: Namespace identifier - * @rrega: The registration action, see &enum nvme_resv_rrega - * @cptpl: Change persist through power loss, see &enum nvme_resv_cptpl - * @iekey: Set to ignore the existing key - * @timeout: Timeout in ms - */ -struct nvme_resv_register_args { - __u64 crkey; - __u64 nrkey; - __u32 *result; - int args_size; - __u32 timeout; - __u32 nsid; - enum nvme_resv_rrega rrega; - enum nvme_resv_cptpl cptpl; - bool iekey; -}; - /** * struct nvme_resv_release_args - Arguments for the NVMe Reservation Release Command * @crkey: The current reservation key to release diff --git a/src/nvme/ioctl.c b/src/nvme/ioctl.c index f158ff688..6e9f1ccce 100644 --- a/src/nvme/ioctl.c +++ b/src/nvme/ioctl.c @@ -1315,31 +1315,6 @@ int nvme_io_passthru(nvme_link_t l, __u8 opcode, __u8 flags, __u16 rsvd, timeout_ms, result); } -int nvme_resv_register(nvme_link_t l, struct nvme_resv_register_args *args) -{ - __le64 payload[2] = { - cpu_to_le64(args->crkey), - cpu_to_le64(args->nrkey) - }; - __u32 cdw10 = (args->rrega & 0x7) | - (args->iekey ? 1 << 3 : 0) | - (args->cptpl << 30); - - struct nvme_passthru_cmd cmd = { - .opcode = nvme_cmd_resv_register, - .nsid = args->nsid, - .cdw10 = cdw10, - .data_len = sizeof(payload), - .addr = (__u64)(uintptr_t)(payload), - .timeout_ms = args->timeout, - }; - - if (args->args_size < sizeof(*args)) - return -EINVAL; - - return nvme_submit_io_passthru(l, &cmd, args->result); -} - int nvme_resv_release(nvme_link_t l, struct nvme_resv_release_args *args) { __le64 payload[1] = { cpu_to_le64(args->crkey) }; diff --git a/src/nvme/ioctl.h b/src/nvme/ioctl.h index 15524a81b..96abc8836 100644 --- a/src/nvme/ioctl.h +++ b/src/nvme/ioctl.h @@ -4669,7 +4669,15 @@ static inline int nvme_resv_acquire(nvme_link_t l, __u32 nsid, enum nvme_resv_ra /** * nvme_resv_register() - Send an nvme reservation register * @l: Link handle - * @args: &struct nvme_resv_register_args argument structure + * @nsid: Namespace identifier + * @rrega: The registration action, see &enum nvme_resv_rrega + * @iekey: Set to ignore the existing key + * @disnsrs: Disperse Namespace Reservation Support + * @cptpl: Change persist through power loss, see &enum nvme_resv_cptpl + * @crkey: The current reservation key associated with the host + * @nrkey: The new reservation key to be register if action is register or + * replace + * @result: The command completion result from CQE dword0 * * The Reservation Register command registers, unregisters, or replaces a * reservation key. @@ -4677,7 +4685,26 @@ static inline int nvme_resv_acquire(nvme_link_t l, __u32 nsid, enum nvme_resv_ra * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_resv_register(nvme_link_t l, struct nvme_resv_register_args *args); +static inline int nvme_resv_register(nvme_link_t l, __u32 nsid, enum nvme_resv_rrega rrega, + bool iekey, bool disnsrs, enum nvme_resv_cptpl cptpl, + __u64 crkey, __u64 nrkey, __u32 *result) +{ + __le64 payload[2] = { + htole64(crkey), + htole64(nrkey) + }; + __u32 cdw10 = (rrega & 0x7) | (iekey ? 1 << 3 : 0) | (cptpl << 30); + + struct nvme_passthru_cmd cmd = { + .opcode = nvme_cmd_resv_register, + .nsid = nsid, + .addr = (__u64)(uintptr_t)(payload), + .data_len = sizeof(payload), + .cdw10 = cdw10, + }; + + return nvme_submit_io_passthru(l, &cmd, result); +} /** * nvme_resv_release() - Send an nvme reservation release diff --git a/test/ioctl/misc.c b/test/ioctl/misc.c index 4bc4f7e9a..85603893b 100644 --- a/test/ioctl/misc.c +++ b/test/ioctl/misc.c @@ -1144,34 +1144,24 @@ static void test_resv_acquire(void) static void test_resv_register(void) { - __u32 result = 0; - - struct nvme_resv_register_args args = { - .crkey = 0xffffffffffffffff, - .nrkey = 0, - .result = &result, - .args_size = sizeof(args), - .nsid = TEST_NSID, - .rrega = NVME_RESERVATION_RREGA_UNREGISTER_KEY, - .cptpl = NVME_RESERVATION_CPTPL_PERSIST, - .iekey = true, - }; - + enum nvme_resv_rrega rrega = NVME_RESERVATION_RREGA_UNREGISTER_KEY; + enum nvme_resv_cptpl cptpl = NVME_RESERVATION_CPTPL_PERSIST; __le64 payload[2] = { 0xffffffffffffffff, 0 }; + bool iekey = true; + __u32 result = 0; + int err; struct mock_cmd mock_io_cmd = { .opcode = nvme_cmd_resv_register, .nsid = TEST_NSID, - .cdw10 = (args.rrega & 0x7) | (args.iekey ? 1 << 3 : 0) | - (args.cptpl << 30), + .cdw10 = (rrega & 0x7) | (iekey ? 1 << 3 : 0) | (cptpl << 30), .data_len = sizeof(payload), .in_data = payload, }; - int err; - set_mock_io_cmds(&mock_io_cmd, 1); - err = nvme_resv_register(test_link, &args); + err = nvme_resv_register(test_link, TEST_NSID, rrega, iekey, false, cptpl, + 0xffffffffffffffff, 0, &result); end_mock_cmds(); check(err == 0, "returned error %d", err); check(result == 0, "returned result %u", result); From bac81870b86522143744cc5c32a602c7765ff3a8 Mon Sep 17 00:00:00 2001 From: Tokunori Ikegami Date: Sun, 10 Aug 2025 23:12:26 +0900 Subject: [PATCH 36/66] ioctl: nvme_resv_release use nvme_passthru_cmd directly Drop struct nvme_resv_release_args. Signed-off-by: Tokunori Ikegami --- src/libnvme.map | 1 - src/nvme/api-types.h | 22 ---------------------- src/nvme/ioctl.c | 22 ---------------------- src/nvme/ioctl.h | 25 +++++++++++++++++++++++-- test/ioctl/misc.c | 24 ++++++++---------------- 5 files changed, 31 insertions(+), 63 deletions(-) diff --git a/src/libnvme.map b/src/libnvme.map index 8433ab88c..c57ff1910 100644 --- a/src/libnvme.map +++ b/src/libnvme.map @@ -273,7 +273,6 @@ LIBNVME_2_0 { nvme_read_key; nvme_refresh_topology; nvme_rescan_ctrl; - nvme_resv_release; nvme_resv_report; nvme_revoke_tls_key; nvme_root_get_application; diff --git a/src/nvme/api-types.h b/src/nvme/api-types.h index 002c19797..cb446e7a2 100644 --- a/src/nvme/api-types.h +++ b/src/nvme/api-types.h @@ -318,28 +318,6 @@ struct nvme_virtual_mgmt_args { __u16 nr; }; -/** - * struct nvme_resv_release_args - Arguments for the NVMe Reservation Release Command - * @crkey: The current reservation key to release - * @result: The command completion result from CQE dword0 - * @args_size: Size of &struct nvme_resv_release_args - * @timeout: Timeout in ms - * @nsid: Namespace identifier - * @rtype: The type of reservation to be create, see &enum nvme_resv_rtype - * @rrela: Reservation release action, see &enum nvme_resv_rrela - * @iekey: Set to ignore the existing key - */ -struct nvme_resv_release_args { - __u64 crkey; - __u32 *result; - int args_size; - __u32 timeout; - __u32 nsid; - enum nvme_resv_rtype rtype; - enum nvme_resv_rrela rrela; - bool iekey; -}; - /** * struct nvme_resv_report_args - Arguments for the NVMe Reservation Report command * @result: The command completion result from CQE dword0 diff --git a/src/nvme/ioctl.c b/src/nvme/ioctl.c index 6e9f1ccce..1c8f59dbe 100644 --- a/src/nvme/ioctl.c +++ b/src/nvme/ioctl.c @@ -1315,28 +1315,6 @@ int nvme_io_passthru(nvme_link_t l, __u8 opcode, __u8 flags, __u16 rsvd, timeout_ms, result); } -int nvme_resv_release(nvme_link_t l, struct nvme_resv_release_args *args) -{ - __le64 payload[1] = { cpu_to_le64(args->crkey) }; - __u32 cdw10 = (args->rrela & 0x7) | - (args->iekey ? 1 << 3 : 0) | - (args->rtype << 8); - - struct nvme_passthru_cmd cmd = { - .opcode = nvme_cmd_resv_release, - .nsid = args->nsid, - .cdw10 = cdw10, - .addr = (__u64)(uintptr_t)(payload), - .data_len = sizeof(payload), - .timeout_ms = args->timeout, - }; - - if (args->args_size < sizeof(*args)) - return -EINVAL; - - return nvme_submit_io_passthru(l, &cmd, args->result); -} - int nvme_resv_report(nvme_link_t l, struct nvme_resv_report_args *args) { struct nvme_passthru_cmd cmd = { diff --git a/src/nvme/ioctl.h b/src/nvme/ioctl.h index 96abc8836..8d5ccc430 100644 --- a/src/nvme/ioctl.h +++ b/src/nvme/ioctl.h @@ -4709,12 +4709,33 @@ static inline int nvme_resv_register(nvme_link_t l, __u32 nsid, enum nvme_resv_r /** * nvme_resv_release() - Send an nvme reservation release * @l: Link handle - * @args: &struct nvme_resv_release_args argument structure + * @nsid: Namespace identifier + * @crkey: The current reservation key to release + * @rtype: The type of reservation to be create, see &enum nvme_resv_rtype + * @rrela: Reservation release action, see &enum nvme_resv_rrela + * @iekey: Set to ignore the existing key + * @result: The command completion result from CQE dword0 * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_resv_release(nvme_link_t l, struct nvme_resv_release_args *args); +static inline int nvme_resv_release(nvme_link_t l, __u32 nsid, __u64 crkey, + enum nvme_resv_rtype rtype, enum nvme_resv_rrela rrela, + bool iekey, __u32 *result) +{ + __le64 payload[1] = { htole64(crkey) }; + __u32 cdw10 = (rrela & 0x7) | (iekey ? 1 << 3 : 0) | (rtype << 8); + + struct nvme_passthru_cmd cmd = { + .opcode = nvme_cmd_resv_release, + .nsid = nsid, + .addr = (__u64)(uintptr_t)(payload), + .data_len = sizeof(payload), + .cdw10 = cdw10, + }; + + return nvme_submit_io_passthru(l, &cmd, result); +} /** * nvme_resv_report() - Send an nvme reservation report diff --git a/test/ioctl/misc.c b/test/ioctl/misc.c index 85603893b..fe318042e 100644 --- a/test/ioctl/misc.c +++ b/test/ioctl/misc.c @@ -1169,33 +1169,25 @@ static void test_resv_register(void) static void test_resv_release(void) { - __u32 result = 0; - - struct nvme_resv_release_args args = { - .crkey = 0xffffffffffffffff, - .result = &result, - .args_size = sizeof(args), - .nsid = TEST_NSID, - .rtype = NVME_RESERVATION_RTYPE_WE, - .rrela = NVME_RESERVATION_RRELA_RELEASE, - .iekey = true, - }; - + enum nvme_resv_rtype rtype = NVME_RESERVATION_RTYPE_WE; + enum nvme_resv_rrela rrela = NVME_RESERVATION_RRELA_RELEASE; __le64 payload[1] = { 0xffffffffffffffff }; + bool iekey = true; + __u32 result = 0; + int err; struct mock_cmd mock_io_cmd = { .opcode = nvme_cmd_resv_release, .nsid = TEST_NSID, - .cdw10 = (args.rrela & 0x7) | (args.iekey ? 1 << 3 : 0) | - (args.rtype << 8), + .cdw10 = (rrela & 0x7) | (iekey ? 1 << 3 : 0) | (rtype << 8), .data_len = sizeof(payload), .in_data = payload, }; - int err; set_mock_io_cmds(&mock_io_cmd, 1); - err = nvme_resv_release(test_link, &args); + err = nvme_resv_release(test_link, TEST_NSID, 0xffffffffffffffff, rtype, rrela, + iekey, &result); end_mock_cmds(); check(err == 0, "returned error %d", err); check(result == 0, "returned result %u", result); From 157f10a24f3e0e46c2fa7936a690443ed9f7008c Mon Sep 17 00:00:00 2001 From: Tokunori Ikegami Date: Sun, 10 Aug 2025 23:23:05 +0900 Subject: [PATCH 37/66] ioctl: nvme_resv_report use nvme_passthru_cmd directly Drop struct nvme_resv_report_args. Signed-off-by: Tokunori Ikegami [wagi: reorder and added missing arguments] Signed-off-by: Daniel Wagner --- src/libnvme.map | 1 - src/nvme/api-types.h | 21 --------------------- src/nvme/ioctl.c | 18 ------------------ src/nvme/ioctl.h | 33 ++++++++++++++++++++++++++------- test/ioctl/misc.c | 29 ++++++++++------------------- 5 files changed, 36 insertions(+), 66 deletions(-) diff --git a/src/libnvme.map b/src/libnvme.map index c57ff1910..9efb82ab7 100644 --- a/src/libnvme.map +++ b/src/libnvme.map @@ -273,7 +273,6 @@ LIBNVME_2_0 { nvme_read_key; nvme_refresh_topology; nvme_rescan_ctrl; - nvme_resv_report; nvme_revoke_tls_key; nvme_root_get_application; nvme_root_release_fds; diff --git a/src/nvme/api-types.h b/src/nvme/api-types.h index cb446e7a2..60b1a3af9 100644 --- a/src/nvme/api-types.h +++ b/src/nvme/api-types.h @@ -318,27 +318,6 @@ struct nvme_virtual_mgmt_args { __u16 nr; }; -/** - * struct nvme_resv_report_args - Arguments for the NVMe Reservation Report command - * @result: The command completion result from CQE dword0 - * @report: The user space destination address to store the reservation - * report - * @args_size: Size of &struct nvme_resv_report_args - * @timeout: Timeout in ms - * @nsid: Namespace identifier - * @len: Number of bytes to request transferred with this command - * @eds: Request extended Data Structure - */ -struct nvme_resv_report_args { - __u32 *result; - struct nvme_resv_status *report; - int args_size; - __u32 timeout; - __u32 nsid; - __u32 len; - bool eds; -}; - /** * struct nvme_io_mgmt_recv_args - Arguments for the NVMe I/O Management Receive command * @data: Userspace address of the data diff --git a/src/nvme/ioctl.c b/src/nvme/ioctl.c index 1c8f59dbe..5071f1a51 100644 --- a/src/nvme/ioctl.c +++ b/src/nvme/ioctl.c @@ -1315,24 +1315,6 @@ int nvme_io_passthru(nvme_link_t l, __u8 opcode, __u8 flags, __u16 rsvd, timeout_ms, result); } -int nvme_resv_report(nvme_link_t l, struct nvme_resv_report_args *args) -{ - struct nvme_passthru_cmd cmd = { - .opcode = nvme_cmd_resv_report, - .nsid = args->nsid, - .cdw10 = (args->len >> 2) - 1, - .cdw11 = args->eds ? 1 : 0, - .addr = (__u64)(uintptr_t)args->report, - .data_len = args->len, - .timeout_ms = args->timeout, - }; - - if (args->args_size < sizeof(*args)) - return -EINVAL; - - return nvme_submit_io_passthru(l, &cmd, args->result); -} - int nvme_io_mgmt_recv(nvme_link_t l, struct nvme_io_mgmt_recv_args *args) { __u32 cdw10 = args->mo | (args->mos << 16); diff --git a/src/nvme/ioctl.h b/src/nvme/ioctl.h index 8d5ccc430..b86876adb 100644 --- a/src/nvme/ioctl.h +++ b/src/nvme/ioctl.h @@ -4710,18 +4710,19 @@ static inline int nvme_resv_register(nvme_link_t l, __u32 nsid, enum nvme_resv_r * nvme_resv_release() - Send an nvme reservation release * @l: Link handle * @nsid: Namespace identifier - * @crkey: The current reservation key to release - * @rtype: The type of reservation to be create, see &enum nvme_resv_rtype * @rrela: Reservation release action, see &enum nvme_resv_rrela + * @crkey: The current reservation key to release * @iekey: Set to ignore the existing key + * @disnsrs: Disperse Namespace Reservation Support + * @rtype: The type of reservation to be create, see &enum nvme_resv_rtype * @result: The command completion result from CQE dword0 * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -static inline int nvme_resv_release(nvme_link_t l, __u32 nsid, __u64 crkey, - enum nvme_resv_rtype rtype, enum nvme_resv_rrela rrela, - bool iekey, __u32 *result) +static inline int nvme_resv_release(nvme_link_t l, __u32 nsid, enum nvme_resv_rrela rrela, + __u64 crkey, bool iekey, bool disnsrs, + enum nvme_resv_rtype rtype, __u32 *result) { __le64 payload[1] = { htole64(crkey) }; __u32 cdw10 = (rrela & 0x7) | (iekey ? 1 << 3 : 0) | (rtype << 8); @@ -4740,7 +4741,12 @@ static inline int nvme_resv_release(nvme_link_t l, __u32 nsid, __u64 crkey, /** * nvme_resv_report() - Send an nvme reservation report * @l: Link handle - * @args: struct nvme_resv_report_args argument structure + * @nsid: Namespace identifier + * @eds: Request extended Data Structure + * @report: The user space destination address to store the reservation + * report + * @len: Number of bytes to request transferred with this command + * @result: The command completion result from CQE dword0 * * Returns a Reservation Status data structure to memory that describes the * registration and reservation status of a namespace. See the definition for @@ -4749,7 +4755,20 @@ static inline int nvme_resv_release(nvme_link_t l, __u32 nsid, __u64 crkey, * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_resv_report(nvme_link_t l, struct nvme_resv_report_args *args); +static inline int nvme_resv_report(nvme_link_t l, __u32 nsid, bool eds, + struct nvme_resv_status *report, __u32 len, __u32 *result) +{ + struct nvme_passthru_cmd cmd = { + .opcode = nvme_cmd_resv_report, + .nsid = nsid, + .addr = (__u64)(uintptr_t)report, + .data_len = len, + .cdw10 = (len >> 2) - 1, + .cdw11 = (__u32)(eds ? 1 : 0), + }; + + return nvme_submit_io_passthru(l, &cmd, result); +} /** * nvme_io_mgmt_recv() - I/O Management Receive command diff --git a/test/ioctl/misc.c b/test/ioctl/misc.c index fe318042e..954c4ccd4 100644 --- a/test/ioctl/misc.c +++ b/test/ioctl/misc.c @@ -1186,8 +1186,8 @@ static void test_resv_release(void) set_mock_io_cmds(&mock_io_cmd, 1); - err = nvme_resv_release(test_link, TEST_NSID, 0xffffffffffffffff, rtype, rrela, - iekey, &result); + err = nvme_resv_release(test_link, TEST_NSID, rrela, 0xffffffffffffffff, + iekey, false, rtype, &result); end_mock_cmds(); check(err == 0, "returned error %d", err); check(result == 0, "returned result %u", result); @@ -1195,33 +1195,24 @@ static void test_resv_release(void) static void test_resv_report(void) { - __u32 result = 0; - struct nvme_resv_status expected_status, status = {}; - - struct nvme_resv_report_args args = { - .result = &result, - .report = &status, - .args_size = sizeof(args), - .nsid = TEST_NSID, - .len = sizeof(status), - .eds = false, - }; + __u32 len = sizeof(status); + __u32 result = 0; + bool eds = false; + int err; struct mock_cmd mock_io_cmd = { .opcode = nvme_cmd_resv_report, .nsid = TEST_NSID, - .cdw10 = (args.len >> 2) - 1, - .cdw11 = args.eds ? 1 : 0, - .data_len = args.len, + .cdw10 = (len >> 2) - 1, + .cdw11 = eds ? 1 : 0, + .data_len = len, .out_data = &expected_status, }; - int err; - arbitrary(&expected_status, sizeof(expected_status)); set_mock_io_cmds(&mock_io_cmd, 1); - err = nvme_resv_report(test_link, &args); + err = nvme_resv_report(test_link, TEST_NSID, eds, &status, len, &result); end_mock_cmds(); check(err == 0, "returned error %d", err); check(result == 0, "returned result %u", result); From 3bad7e6815c8cf725e9c2b753475e7635a26481b Mon Sep 17 00:00:00 2001 From: Tokunori Ikegami Date: Mon, 11 Aug 2025 11:07:00 +0900 Subject: [PATCH 38/66] ioctl: nvme_io_mgmt_recv use nvme_passthru_cmd directly Drop struct nvme_io_mgmt_recv_args. Signed-off-by: Tokunori Ikegami [wagi: reorder arguments] Signed-off-by: Daniel Wagner --- src/libnvme.map | 1 - src/nvme/api-types.h | 20 -------------------- src/nvme/ioctl.c | 21 --------------------- src/nvme/ioctl.h | 37 ++++++++++++++++++++++++------------- test/ioctl/misc.c | 22 ++++++++-------------- 5 files changed, 32 insertions(+), 69 deletions(-) diff --git a/src/libnvme.map b/src/libnvme.map index 9efb82ab7..f418004ea 100644 --- a/src/libnvme.map +++ b/src/libnvme.map @@ -160,7 +160,6 @@ LIBNVME_2_0 { nvme_init_logging; nvme_insert_tls_key; nvme_insert_tls_key_versioned; - nvme_io_mgmt_recv; nvme_io_mgmt_send; nvme_io_passthru64; nvme_io_passthru; diff --git a/src/nvme/api-types.h b/src/nvme/api-types.h index 60b1a3af9..6e520f131 100644 --- a/src/nvme/api-types.h +++ b/src/nvme/api-types.h @@ -318,26 +318,6 @@ struct nvme_virtual_mgmt_args { __u16 nr; }; -/** - * struct nvme_io_mgmt_recv_args - Arguments for the NVMe I/O Management Receive command - * @data: Userspace address of the data - * @args_size: Size of &struct nvme_io_mgmt_recv_args - * @nsid: Namespace identifier - * @data_len: Length of @data - * @timeout: Timeout in ms - * @mos: Management Operation Specific - * @mo: Management Operation - */ -struct nvme_io_mgmt_recv_args { - void *data; - int args_size; - __u32 nsid; - __u32 data_len; - __u32 timeout; - __u16 mos; - __u8 mo; -}; - /** * struct nvme_io_mgmt_send_args - Arguments for the NVMe I/O Management Send command * @data: Userspace address of the data diff --git a/src/nvme/ioctl.c b/src/nvme/ioctl.c index 5071f1a51..04165c87b 100644 --- a/src/nvme/ioctl.c +++ b/src/nvme/ioctl.c @@ -1315,27 +1315,6 @@ int nvme_io_passthru(nvme_link_t l, __u8 opcode, __u8 flags, __u16 rsvd, timeout_ms, result); } -int nvme_io_mgmt_recv(nvme_link_t l, struct nvme_io_mgmt_recv_args *args) -{ - __u32 cdw10 = args->mo | (args->mos << 16); - __u32 cdw11 = (args->data_len >> 2) - 1; - - struct nvme_passthru_cmd cmd = { - .opcode = nvme_cmd_io_mgmt_recv, - .nsid = args->nsid, - .cdw10 = cdw10, - .cdw11 = cdw11, - .addr = (__u64)(uintptr_t)args->data, - .data_len = args->data_len, - .timeout_ms = args->timeout, - }; - - if (args->args_size < sizeof(*args)) - return -EINVAL; - - return nvme_submit_io_passthru(l, &cmd, NULL); -} - int nvme_io_mgmt_send(nvme_link_t l, struct nvme_io_mgmt_send_args *args) { __u32 cdw10 = args->mo | (args->mos << 16); diff --git a/src/nvme/ioctl.h b/src/nvme/ioctl.h index b86876adb..100d4a5c5 100644 --- a/src/nvme/ioctl.h +++ b/src/nvme/ioctl.h @@ -4773,12 +4773,32 @@ static inline int nvme_resv_report(nvme_link_t l, __u32 nsid, bool eds, /** * nvme_io_mgmt_recv() - I/O Management Receive command * @l: Link handle - * @args: &struct nvme_io_mgmt_recv_args argument structure + * @nsid: Namespace identifier + * @mo: Management Operation + * @mos: Management Operation Specific + * @data: Userspace address of the data + * @data_len: Length of @data * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_io_mgmt_recv(nvme_link_t l, struct nvme_io_mgmt_recv_args *args); +static inline int nvme_io_mgmt_recv(nvme_link_t l, __u32 nsid, __u8 mo, + __u16 mos, void *data, __u32 data_len) +{ + __u32 cdw10 = mo | (mos << 16); + __u32 cdw11 = (data_len >> 2) - 1; + + struct nvme_passthru_cmd cmd = { + .opcode = nvme_cmd_io_mgmt_recv, + .nsid = nsid, + .addr = (__u64)(uintptr_t)data, + .data_len = data_len, + .cdw10 = cdw10, + .cdw11 = cdw11, + }; + + return nvme_submit_io_passthru(l, &cmd, NULL); +} /** * nvme_fdp_reclaim_unit_handle_status() - Get reclaim unit handle status @@ -4793,17 +4813,8 @@ int nvme_io_mgmt_recv(nvme_link_t l, struct nvme_io_mgmt_recv_args *args); static inline int nvme_fdp_reclaim_unit_handle_status(nvme_link_t l, __u32 nsid, __u32 data_len, void *data) { - struct nvme_io_mgmt_recv_args args = { - .data = data, - .args_size = sizeof(args), - .nsid = nsid, - .data_len = data_len, - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .mos = 0, - .mo = NVME_IO_MGMT_RECV_RUH_STATUS, - }; - - return nvme_io_mgmt_recv(l, &args); + return nvme_io_mgmt_recv(l, nsid, NVME_IO_MGMT_RECV_RUH_STATUS, 0, + data, data_len); } /** diff --git a/test/ioctl/misc.c b/test/ioctl/misc.c index 954c4ccd4..a21760896 100644 --- a/test/ioctl/misc.c +++ b/test/ioctl/misc.c @@ -1222,29 +1222,23 @@ static void test_resv_report(void) static void test_io_mgmt_recv(void) { __u8 expected_data[8], data[8] = {}; - struct nvme_io_mgmt_recv_args args = { - .data = &data, - .args_size = sizeof(args), - .nsid = TEST_NSID, - .data_len = sizeof(data), - .mos = 0x1, - .mo = 0x2, - }; + __u32 data_len = sizeof(data); + __u16 mos = 0x1; + __u8 mo = 0x2; + int err; struct mock_cmd mock_io_cmd = { .opcode = nvme_cmd_io_mgmt_recv, .nsid = TEST_NSID, - .cdw10 = args.mo | (args.mos << 16), - .cdw11 = (args.data_len >> 2) - 1, - .data_len = args.data_len, + .cdw10 = mo | (mos << 16), + .cdw11 = (data_len >> 2) - 1, + .data_len = data_len, .out_data = &expected_data, }; - int err; - arbitrary(&expected_data, sizeof(expected_data)); set_mock_io_cmds(&mock_io_cmd, 1); - err = nvme_io_mgmt_recv(test_link, &args); + err = nvme_io_mgmt_recv(test_link, TEST_NSID, mo, mos, &data, data_len); end_mock_cmds(); check(err == 0, "returned error %d", err); cmp(&data, &expected_data, sizeof(data), "incorrect data"); From b3047910463a72b5c83c1a02f4f861225623261d Mon Sep 17 00:00:00 2001 From: Tokunori Ikegami Date: Mon, 11 Aug 2025 12:47:38 +0900 Subject: [PATCH 39/66] ioctl: nvme_io_mgmt_send use nvme_passthru_cmd directly Drop struct nvme_io_mgmt_send_args. Signed-off-by: Tokunori Ikegami [wagi: reorder arguments] Signed-off-by: Daniel Wagner --- src/libnvme.map | 1 - src/nvme/api-types.h | 20 -------------------- src/nvme/ioctl.c | 19 ------------------- src/nvme/ioctl.h | 37 ++++++++++++++++++++++++------------- test/ioctl/misc.c | 21 ++++++++------------- 5 files changed, 32 insertions(+), 66 deletions(-) diff --git a/src/libnvme.map b/src/libnvme.map index f418004ea..03d92ebae 100644 --- a/src/libnvme.map +++ b/src/libnvme.map @@ -160,7 +160,6 @@ LIBNVME_2_0 { nvme_init_logging; nvme_insert_tls_key; nvme_insert_tls_key_versioned; - nvme_io_mgmt_send; nvme_io_passthru64; nvme_io_passthru; nvme_ipaddrs_eq; diff --git a/src/nvme/api-types.h b/src/nvme/api-types.h index 6e520f131..56d8b08dc 100644 --- a/src/nvme/api-types.h +++ b/src/nvme/api-types.h @@ -318,26 +318,6 @@ struct nvme_virtual_mgmt_args { __u16 nr; }; -/** - * struct nvme_io_mgmt_send_args - Arguments for the NVMe I/O Management Send command - * @data: Userspace address of the data - * @args_size: Size of &struct nvme_io_mgmt_send_args - * @nsid: Namespace identifier - * @data_len: Length of @data - * @timeout: Timeout in ms - * @mos: Management Operation Specific - * @mo: Management Operation - */ -struct nvme_io_mgmt_send_args { - void *data; - int args_size; - __u32 nsid; - __u32 data_len; - __u32 timeout; - __u16 mos; - __u8 mo; -}; - /** * struct nvme_zns_mgmt_send_args - Arguments for the NVMe ZNS Management Send command * @slba: Starting logical block address diff --git a/src/nvme/ioctl.c b/src/nvme/ioctl.c index 04165c87b..b40916808 100644 --- a/src/nvme/ioctl.c +++ b/src/nvme/ioctl.c @@ -1315,25 +1315,6 @@ int nvme_io_passthru(nvme_link_t l, __u8 opcode, __u8 flags, __u16 rsvd, timeout_ms, result); } -int nvme_io_mgmt_send(nvme_link_t l, struct nvme_io_mgmt_send_args *args) -{ - __u32 cdw10 = args->mo | (args->mos << 16); - - struct nvme_passthru_cmd cmd = { - .opcode = nvme_cmd_io_mgmt_send, - .nsid = args->nsid, - .cdw10 = cdw10, - .addr = (__u64)(uintptr_t)args->data, - .data_len = args->data_len, - .timeout_ms = args->timeout, - }; - - if (args->args_size < sizeof(*args)) - return -EINVAL; - - return nvme_submit_io_passthru(l, &cmd, NULL); -} - int nvme_zns_mgmt_send(nvme_link_t l, struct nvme_zns_mgmt_send_args *args) { __u32 cdw10 = args->slba & 0xffffffff; diff --git a/src/nvme/ioctl.h b/src/nvme/ioctl.h index 100d4a5c5..d8dcb0b9d 100644 --- a/src/nvme/ioctl.h +++ b/src/nvme/ioctl.h @@ -4820,12 +4820,30 @@ static inline int nvme_fdp_reclaim_unit_handle_status(nvme_link_t l, __u32 nsid, /** * nvme_io_mgmt_send() - I/O Management Send command * @l: Link handle - * @args: &struct nvme_io_mgmt_send_args argument structure + * @nsid: Namespace identifier + * @mo: Management Operation + * @mos: Management Operation Specific + * @data: Userspace address of the data + * @data_len: Length of @data * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_io_mgmt_send(nvme_link_t l, struct nvme_io_mgmt_send_args *args); +static inline int nvme_io_mgmt_send(nvme_link_t l, __u32 nsid, __u8 mo, __u16 mos, + void *data, __u32 data_len) +{ + __u32 cdw10 = mo | (mos << 16); + + struct nvme_passthru_cmd cmd = { + .opcode = nvme_cmd_io_mgmt_send, + .nsid = nsid, + .addr = (__u64)(uintptr_t)data, + .data_len = data_len, + .cdw10 = cdw10, + }; + + return nvme_submit_io_passthru(l, &cmd, NULL); +} /** * nvme_fdp_reclaim_unit_handle_update() - Update a list of reclaim unit handles @@ -4840,17 +4858,10 @@ int nvme_io_mgmt_send(nvme_link_t l, struct nvme_io_mgmt_send_args *args); static inline int nvme_fdp_reclaim_unit_handle_update(nvme_link_t l, __u32 nsid, unsigned int npids, __u16 *pids) { - struct nvme_io_mgmt_send_args args = { - .data = (void *)pids, - .args_size = sizeof(args), - .nsid = nsid, - .data_len = (__u32)(npids * sizeof(__u16)), - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .mos = (__u16)(npids - 1), - .mo = NVME_IO_MGMT_SEND_RUH_UPDATE, - }; - - return nvme_io_mgmt_send(l, &args); + return nvme_io_mgmt_send(l, nsid, NVME_IO_MGMT_SEND_RUH_UPDATE, + (__u16)(npids - 1), + (void *)pids, + (__u32)(npids * sizeof(__u16))); } /** diff --git a/test/ioctl/misc.c b/test/ioctl/misc.c index a21760896..6a94d35a5 100644 --- a/test/ioctl/misc.c +++ b/test/ioctl/misc.c @@ -1247,29 +1247,24 @@ static void test_io_mgmt_recv(void) static void test_io_mgmt_send(void) { __u8 expected_data[8], data[8] = {}; - struct nvme_io_mgmt_send_args args = { - .data = &expected_data, - .args_size = sizeof(args), - .nsid = TEST_NSID, - .data_len = sizeof(expected_data), - .mos = 0x1, - .mo = 0x2, - }; + __u32 data_len = sizeof(expected_data); + __u16 mos = 0x1; + __u8 mo = 0x2; + int err; struct mock_cmd mock_io_cmd = { .opcode = nvme_cmd_io_mgmt_send, .nsid = TEST_NSID, - .cdw10 = args.mo | (args.mos << 16), - .data_len = args.data_len, + .cdw10 = mo | (mos << 16), + .data_len = data_len, .in_data = &data, }; - int err; - arbitrary(&expected_data, sizeof(expected_data)); memcpy(&data, &expected_data, sizeof(expected_data)); set_mock_io_cmds(&mock_io_cmd, 1); - err = nvme_io_mgmt_send(test_link, &args); + err = nvme_io_mgmt_send(test_link, TEST_NSID, mo, mos, + &expected_data, data_len); end_mock_cmds(); check(err == 0, "returned error %d", err); cmp(&data, &expected_data, sizeof(data), "incorrect data"); From 9f1d7861b1f83d611cb2ce01dbb1bd48b84a554d Mon Sep 17 00:00:00 2001 From: Tokunori Ikegami Date: Mon, 11 Aug 2025 13:14:14 +0900 Subject: [PATCH 40/66] ioctl: nvme_zns_mgmt_send use nvme_passthru_cmd directly Drop struct nvme_zns_mgmt_send_args. Signed-off-by: Tokunori Ikegami [wagi: reorderd and added missing arguments] Signed-off-by: Daniel Wagner --- src/libnvme.map | 1 - src/nvme/api-types.h | 26 -------------------------- src/nvme/ioctl.c | 25 ------------------------- src/nvme/ioctl.h | 33 +++++++++++++++++++++++++++++++-- test/ioctl/zns.c | 33 +++++++++++---------------------- 5 files changed, 42 insertions(+), 76 deletions(-) diff --git a/src/libnvme.map b/src/libnvme.map index 03d92ebae..58bf41a7d 100644 --- a/src/libnvme.map +++ b/src/libnvme.map @@ -330,7 +330,6 @@ LIBNVME_2_0 { nvme_virtual_mgmt; nvme_zns_append; nvme_zns_mgmt_recv; - nvme_zns_mgmt_send; nvmf_add_ctrl; nvmf_adrfam_str; nvmf_cms_str; diff --git a/src/nvme/api-types.h b/src/nvme/api-types.h index 56d8b08dc..8426b4283 100644 --- a/src/nvme/api-types.h +++ b/src/nvme/api-types.h @@ -318,32 +318,6 @@ struct nvme_virtual_mgmt_args { __u16 nr; }; -/** - * struct nvme_zns_mgmt_send_args - Arguments for the NVMe ZNS Management Send command - * @slba: Starting logical block address - * @result: The command completion result from CQE dword0 - * @data: Userspace address of the data - * @args_size: Size of &struct nvme_zns_mgmt_send_args - * @timeout: timeout in ms - * @nsid: Namespace ID - * @zsa: Zone send action - * @data_len: Length of @data - * @select_all: Select all flag - * @zsaso: Zone Send Action Specific Option - */ -struct nvme_zns_mgmt_send_args { - __u64 slba; - __u32 *result; - void *data; - int args_size; - __u32 timeout; - __u32 nsid; - enum nvme_zns_send_action zsa; - __u32 data_len; - bool select_all; - __u8 zsaso; -}; - /** * struct nvme_zns_mgmt_recv_args - Arguments for the NVMe ZNS Management Receive command * @slba: Starting logical block address diff --git a/src/nvme/ioctl.c b/src/nvme/ioctl.c index b40916808..d1cf4927c 100644 --- a/src/nvme/ioctl.c +++ b/src/nvme/ioctl.c @@ -1315,31 +1315,6 @@ int nvme_io_passthru(nvme_link_t l, __u8 opcode, __u8 flags, __u16 rsvd, timeout_ms, result); } -int nvme_zns_mgmt_send(nvme_link_t l, struct nvme_zns_mgmt_send_args *args) -{ - __u32 cdw10 = args->slba & 0xffffffff; - __u32 cdw11 = args->slba >> 32; - __u32 cdw13 = NVME_SET(args->zsaso, ZNS_MGMT_SEND_ZSASO) | - NVME_SET(!!args->select_all, ZNS_MGMT_SEND_SEL) | - NVME_SET(args->zsa, ZNS_MGMT_SEND_ZSA); - - struct nvme_passthru_cmd cmd = { - .opcode = nvme_zns_cmd_mgmt_send, - .nsid = args->nsid, - .cdw10 = cdw10, - .cdw11 = cdw11, - .cdw13 = cdw13, - .addr = (__u64)(uintptr_t)args->data, - .data_len = args->data_len, - .timeout_ms = args->timeout, - }; - - if (args->args_size < sizeof(*args)) - return -EINVAL; - - return nvme_submit_io_passthru(l, &cmd, args->result); -} - int nvme_zns_mgmt_recv(nvme_link_t l, struct nvme_zns_mgmt_recv_args *args) { __u32 cdw10 = args->slba & 0xffffffff; diff --git a/src/nvme/ioctl.h b/src/nvme/ioctl.h index d8dcb0b9d..cf7a5f467 100644 --- a/src/nvme/ioctl.h +++ b/src/nvme/ioctl.h @@ -4867,13 +4867,42 @@ static inline int nvme_fdp_reclaim_unit_handle_update(nvme_link_t l, __u32 nsid, /** * nvme_zns_mgmt_send() - ZNS management send command * @l: Link handle - * @args: &struct nvme_zns_mgmt_send_args argument structure + * @nsid: Namespace ID + * @slba: Starting logical block address + * @zsa: Zone send action + * @selall: Select all flag + * @zsaso: Zone Send Action Specific Option + * @zm: Zone Management + * @data: Userspace address of the data + * @data_len: Length of @data + * @result: The command completion result from CQE dword0 * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_zns_mgmt_send(nvme_link_t l, struct nvme_zns_mgmt_send_args *args); +static inline int nvme_zns_mgmt_send(nvme_link_t l, __u32 nsid, __u64 slba, + enum nvme_zns_send_action zsa, bool selall, + __u8 zsaso, __u8 zm, void *data, __u32 data_len, + __u32 *result) +{ + __u32 cdw10 = slba & 0xffffffff; + __u32 cdw11 = slba >> 32; + __u32 cdw13 = NVME_SET(zsa, ZNS_MGMT_SEND_ZSA) | + NVME_SET(selall, ZNS_MGMT_SEND_SEL) | + NVME_SET(zsaso, ZNS_MGMT_SEND_ZSASO); + struct nvme_passthru_cmd cmd = { + .opcode = nvme_zns_cmd_mgmt_send, + .nsid = nsid, + .addr = (__u64)(uintptr_t)data, + .data_len = data_len, + .cdw10 = cdw10, + .cdw11 = cdw11, + .cdw13 = cdw13, + }; + + return nvme_submit_io_passthru(l, &cmd, result); +} /** * nvme_zns_mgmt_recv() - ZNS management receive command diff --git a/test/ioctl/zns.c b/test/ioctl/zns.c index 53d69bf39..2fada9162 100644 --- a/test/ioctl/zns.c +++ b/test/ioctl/zns.c @@ -93,40 +93,29 @@ static void test_zns_report_zones(void) static void test_zns_mgmt_send(void) { + enum nvme_zns_send_action zsa = NVME_ZNS_ZSA_OPEN; __u8 expected_data[8], data[8] = {}; + __u64 slba = TEST_SLBA; + bool select_all = true; + __u8 zsaso = !!true; __u32 result = 0; - uint32_t timeout = 1234; - - struct nvme_zns_mgmt_send_args args = { - .slba = TEST_SLBA, - .result = &result, - .data = data, - .args_size = sizeof(args), - .timeout = timeout, - .nsid = TEST_NSID, - .zsa = NVME_ZNS_ZSA_OPEN, - .data_len = sizeof(data), - .select_all = true, - .zsaso = !!true, - }; + int err; struct mock_cmd mock_io_cmd = { .opcode = nvme_zns_cmd_mgmt_send, .nsid = TEST_NSID, - .cdw10 = args.slba & 0xffffffff, - .cdw11 = args.slba >> 32, - .cdw13 = (args.zsaso << 9) | (!!args.select_all << 8) | - (args.zsa << 0), + .cdw10 = slba & 0xffffffff, + .cdw11 = slba >> 32, + .cdw13 = (zsaso << 9) | (!!select_all << 8) | (zsa << 0), .data_len = sizeof(expected_data), .out_data = &expected_data, - .timeout_ms = timeout, }; - int err; - arbitrary(&expected_data, sizeof(expected_data)); set_mock_io_cmds(&mock_io_cmd, 1); - err = nvme_zns_mgmt_send(test_link, &args); + err = nvme_zns_mgmt_send(test_link, TEST_NSID, slba, zsa, select_all, + zsaso, 0, data, + sizeof(data), &result); end_mock_cmds(); check(err == 0, "returned error %d", err); check(result == 0, "returned result %u", result); From b34092f03606aac9e1ce8b11197e2175a702177f Mon Sep 17 00:00:00 2001 From: Tokunori Ikegami Date: Mon, 11 Aug 2025 13:46:23 +0900 Subject: [PATCH 41/66] ioctl: nvme_zns_mgmt_recv use nvme_passthru_cmd directly Drop struct nvme_zns_mgmt_recv_args. Signed-off-by: Tokunori Ikegami [wagi: renamed arguments] Signed-off-by: Daniel Wagner --- src/libnvme.map | 1 - src/nvme/api-types.h | 26 ----------------- src/nvme/ioctl.c | 27 ------------------ src/nvme/ioctl.h | 68 +++++++++++++++++++++++++++----------------- test/ioctl/zns.c | 42 ++++++++------------------- test/zns.c | 5 ++-- 6 files changed, 56 insertions(+), 113 deletions(-) diff --git a/src/libnvme.map b/src/libnvme.map index 58bf41a7d..02b6f8aa3 100644 --- a/src/libnvme.map +++ b/src/libnvme.map @@ -329,7 +329,6 @@ LIBNVME_2_0 { nvme_uuid_to_string; nvme_virtual_mgmt; nvme_zns_append; - nvme_zns_mgmt_recv; nvmf_add_ctrl; nvmf_adrfam_str; nvmf_cms_str; diff --git a/src/nvme/api-types.h b/src/nvme/api-types.h index 8426b4283..f5099a56d 100644 --- a/src/nvme/api-types.h +++ b/src/nvme/api-types.h @@ -318,32 +318,6 @@ struct nvme_virtual_mgmt_args { __u16 nr; }; -/** - * struct nvme_zns_mgmt_recv_args - Arguments for the NVMe ZNS Management Receive command - * @slba: Starting logical block address - * @result: The command completion result from CQE dword0 - * @data: Userspace address of the data - * @args_size: Size of &struct nvme_zns_mgmt_recv_args - * @timeout: timeout in ms - * @nsid: Namespace ID - * @zra: zone receive action - * @data_len: Length of @data - * @zrasf: Zone receive action specific field - * @zras_feat: Zone receive action specific features - */ -struct nvme_zns_mgmt_recv_args { - __u64 slba; - __u32 *result; - void *data; - int args_size; - __u32 timeout; - __u32 nsid; - enum nvme_zns_recv_action zra; - __u32 data_len; - __u16 zrasf; - bool zras_feat; -}; - /** * struct nvme_zns_append_args - Arguments for the NVMe ZNS Append command * @zslba: Zone start logical block address diff --git a/src/nvme/ioctl.c b/src/nvme/ioctl.c index d1cf4927c..78b75b701 100644 --- a/src/nvme/ioctl.c +++ b/src/nvme/ioctl.c @@ -1315,33 +1315,6 @@ int nvme_io_passthru(nvme_link_t l, __u8 opcode, __u8 flags, __u16 rsvd, timeout_ms, result); } -int nvme_zns_mgmt_recv(nvme_link_t l, struct nvme_zns_mgmt_recv_args *args) -{ - __u32 cdw10 = args->slba & 0xffffffff; - __u32 cdw11 = args->slba >> 32; - __u32 cdw12 = (args->data_len >> 2) - 1; - __u32 cdw13 = NVME_SET(args->zra, ZNS_MGMT_RECV_ZRA) | - NVME_SET(args->zrasf, ZNS_MGMT_RECV_ZRASF) | - NVME_SET(args->zras_feat, ZNS_MGMT_RECV_ZRAS_FEAT); - - struct nvme_passthru_cmd cmd = { - .opcode = nvme_zns_cmd_mgmt_recv, - .nsid = args->nsid, - .cdw10 = cdw10, - .cdw11 = cdw11, - .cdw12 = cdw12, - .cdw13 = cdw13, - .addr = (__u64)(uintptr_t)args->data, - .data_len = args->data_len, - .timeout_ms = args->timeout, - }; - - if (args->args_size < sizeof(*args)) - return -EINVAL; - - return nvme_submit_io_passthru(l, &cmd, args->result); -} - int nvme_zns_append(nvme_link_t l, struct nvme_zns_append_args *args) { const size_t size_v1 = sizeof_args(struct nvme_zns_append_args, lbatm, __u64); diff --git a/src/nvme/ioctl.h b/src/nvme/ioctl.h index cf7a5f467..c3b6196a6 100644 --- a/src/nvme/ioctl.h +++ b/src/nvme/ioctl.h @@ -323,10 +323,10 @@ enum nvme_cmd_dword_fields { NVME_ZNS_MGMT_SEND_ZSA_MASK = 0xff, NVME_ZNS_MGMT_RECV_ZRA_SHIFT = 0, NVME_ZNS_MGMT_RECV_ZRA_MASK = 0xff, - NVME_ZNS_MGMT_RECV_ZRASF_SHIFT = 8, - NVME_ZNS_MGMT_RECV_ZRASF_MASK = 0xff, - NVME_ZNS_MGMT_RECV_ZRAS_FEAT_SHIFT = 16, - NVME_ZNS_MGMT_RECV_ZRAS_FEAT_MASK = 0x1, + NVME_ZNS_MGMT_RECV_ZRAS_SHIFT = 8, + NVME_ZNS_MGMT_RECV_ZRAS_MASK = 0xff, + NVME_ZNS_MGMT_RECV_ZRASPF_SHIFT = 16, + NVME_ZNS_MGMT_RECV_ZRASPF_MASK = 0x1, NVME_DIM_TAS_SHIFT = 0, NVME_DIM_TAS_MASK = 0xF, NVME_DSM_CDW10_NR_SHIFT = 0, @@ -4907,12 +4907,43 @@ static inline int nvme_zns_mgmt_send(nvme_link_t l, __u32 nsid, __u64 slba, /** * nvme_zns_mgmt_recv() - ZNS management receive command * @l: Link handle - * @args: &struct nvme_zns_mgmt_recv_args argument structure + * @nsid: Namespace ID + * @slba: Starting logical block address + * @zra: zone receive action + * @zras: Zone receive action specific field + * @zraspf: Zone receive action specific features + * @data: Userspace address of the data + * @data_len: Length of @data + * @result: The command completion result from CQE dword0 * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_zns_mgmt_recv(nvme_link_t l, struct nvme_zns_mgmt_recv_args *args); +static inline int nvme_zns_mgmt_recv(nvme_link_t l, __u32 nsid, __u64 slba, + enum nvme_zns_recv_action zra, __u16 zras, + bool zraspf, void *data, __u32 data_len, + __u32 *result) +{ + __u32 cdw10 = slba & 0xffffffff; + __u32 cdw11 = slba >> 32; + __u32 cdw12 = (data_len >> 2) - 1; + __u32 cdw13 = NVME_SET(zra, ZNS_MGMT_RECV_ZRA) | + NVME_SET(zras, ZNS_MGMT_RECV_ZRAS) | + NVME_SET(zraspf, ZNS_MGMT_RECV_ZRASPF); + + struct nvme_passthru_cmd cmd = { + .opcode = nvme_zns_cmd_mgmt_recv, + .nsid = nsid, + .addr = (__u64)(uintptr_t)data, + .data_len = data_len, + .cdw10 = cdw10, + .cdw11 = cdw11, + .cdw12 = cdw12, + .cdw13 = cdw13, + }; + + return nvme_submit_io_passthru(l, &cmd, result); +} /** * nvme_zns_report_zones() - Return the list of zones @@ -4924,33 +4955,18 @@ int nvme_zns_mgmt_recv(nvme_link_t l, struct nvme_zns_mgmt_recv_args *args); * @partial: Partial report requested * @data_len: Length of the data buffer * @data: Userspace address of the report zones data - * @timeout: timeout in ms * @result: The command completion result from CQE dword0 * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline int nvme_zns_report_zones(nvme_link_t l, __u32 nsid, __u64 slba, - enum nvme_zns_report_options opts, - bool extended, bool partial, - __u32 data_len, void *data, - __u32 timeout, __u32 *result) + enum nvme_zns_report_options opts, bool extended, + bool partial, __u32 data_len, void *data, __u32 *result) { - struct nvme_zns_mgmt_recv_args args = { - .slba = slba, - .result = result, - .data = data, - .args_size = sizeof(args), - .timeout = timeout, - .nsid = nsid, - .zra = extended ? NVME_ZNS_ZRA_EXTENDED_REPORT_ZONES : - NVME_ZNS_ZRA_REPORT_ZONES, - .data_len = data_len, - .zrasf = (__u16)opts, - .zras_feat = partial, - }; - - return nvme_zns_mgmt_recv(l, &args); + return nvme_zns_mgmt_recv(l, nsid, slba, extended ? NVME_ZNS_ZRA_EXTENDED_REPORT_ZONES : + NVME_ZNS_ZRA_REPORT_ZONES, (__u16)opts, partial, data, data_len, + result); } /** diff --git a/test/ioctl/zns.c b/test/ioctl/zns.c index 2fada9162..6ba76c813 100644 --- a/test/ioctl/zns.c +++ b/test/ioctl/zns.c @@ -58,12 +58,12 @@ static void test_zns_append(void) static void test_zns_report_zones(void) { + enum nvme_zns_report_options opts = NVME_ZNS_ZRAS_REPORT_CLOSED; __u8 expected_data[8], data[8] = {}; - __u32 result = 0; - uint32_t timeout = 1234; bool extended = true; bool partial = true; - enum nvme_zns_report_options opts = NVME_ZNS_ZRAS_REPORT_CLOSED; + __u32 result = 0; + int err; struct mock_cmd mock_io_cmd = { .opcode = nvme_zns_cmd_mgmt_recv, @@ -75,16 +75,12 @@ static void test_zns_report_zones(void) (!!partial << 16), .data_len = sizeof(expected_data), .out_data = &expected_data, - .timeout_ms = timeout, }; - int err; - arbitrary(&expected_data, sizeof(expected_data)); set_mock_io_cmds(&mock_io_cmd, 1); - err = nvme_zns_report_zones(test_link, TEST_NSID, TEST_SLBA, opts, - extended, partial, sizeof(data), &data, - timeout, &result); + err = nvme_zns_report_zones(test_link, TEST_NSID, TEST_SLBA, opts, extended, partial, + sizeof(data), &data, &result); end_mock_cmds(); check(err == 0, "returned error %d", err); check(result == 0, "returned result %u", result); @@ -124,40 +120,26 @@ static void test_zns_mgmt_send(void) static void test_zns_mgmt_recv(void) { + enum nvme_zns_recv_action zra = NVME_ZNS_ZRA_REPORT_ZONES; __u8 expected_data[8], data[8] = {}; + __u16 zrasf = (__u16)NVME_ZNS_ZRAS_REPORT_ALL; + bool zras_feat = false; __u32 result = 0; - uint32_t timeout = 1234; - bool partial = false; - - struct nvme_zns_mgmt_recv_args args = { - .slba = 0, - .result = &result, - .data = data, - .args_size = sizeof(args), - .timeout = timeout, - .nsid = TEST_NSID, - .zra = NVME_ZNS_ZRA_REPORT_ZONES, - .data_len = sizeof(data), - .zrasf = (__u16)NVME_ZNS_ZRAS_REPORT_ALL, - .zras_feat = partial, - }; + int err; struct mock_cmd mock_io_cmd = { .opcode = nvme_zns_cmd_mgmt_recv, .nsid = TEST_NSID, .cdw12 = (sizeof(expected_data) >> 2) - 1, - .cdw13 = (!!args.zra << 0) | ((__u16)args.zrasf << 8) | - (!!args.zras_feat << 16), + .cdw13 = (!!zra << 0) | ((__u16)zrasf << 8) | (!!zras_feat << 16), .data_len = sizeof(expected_data), .out_data = &expected_data, - .timeout_ms = timeout, }; - int err; - arbitrary(&expected_data, sizeof(expected_data)); set_mock_io_cmds(&mock_io_cmd, 1); - err = nvme_zns_mgmt_recv(test_link, &args); + err = nvme_zns_mgmt_recv(test_link, TEST_NSID, 0, zra, zrasf, zras_feat, data, sizeof(data), + &result); end_mock_cmds(); check(err == 0, "returned error %d", err); check(result == 0, "returned result %u", result); diff --git a/test/zns.c b/test/zns.c index 5d76555a8..46e73294e 100644 --- a/test/zns.c +++ b/test/zns.c @@ -47,9 +47,8 @@ static void show_zns_properties(nvme_ns_t n) printf("zasl:%u\n", zns_ctrl.zasl); if (nvme_zns_report_zones(nvme_ns_get_link(n), nvme_ns_get_nsid(n), 0, - NVME_ZNS_ZRAS_REPORT_ALL, false, - true, 0x1000, (void *)zr, - NVME_DEFAULT_IOCTL_TIMEOUT, &result)) { + NVME_ZNS_ZRAS_REPORT_ALL, false, true, 0x1000, (void *)zr, + &result)) { fprintf(stderr, "failed to report zones, result %x\n", le32_to_cpu(result)); free(zr); From f0b9aa773206a83435faff64004a98c576cb3115 Mon Sep 17 00:00:00 2001 From: Tokunori Ikegami Date: Mon, 11 Aug 2025 15:15:19 +0900 Subject: [PATCH 42/66] ioctl: nvme_zns_append use nvme_passthru_cmd directly Drop struct nvme_zns_append_args. Signed-off-by: Tokunori Ikegami [wagi: reorder and added missing arguments] Signed-off-by: Daniel Wagner --- src/libnvme.map | 1 - src/nvme/api-types.h | 40 ------------------------------------- src/nvme/ioctl.c | 41 -------------------------------------- src/nvme/ioctl.h | 47 ++++++++++++++++++++++++++++++++++++++++++-- test/ioctl/zns.c | 40 +++++++++++++++++-------------------- 5 files changed, 63 insertions(+), 106 deletions(-) diff --git a/src/libnvme.map b/src/libnvme.map index 02b6f8aa3..937c0b204 100644 --- a/src/libnvme.map +++ b/src/libnvme.map @@ -328,7 +328,6 @@ LIBNVME_2_0 { nvme_uuid_random; nvme_uuid_to_string; nvme_virtual_mgmt; - nvme_zns_append; nvmf_add_ctrl; nvmf_adrfam_str; nvmf_cms_str; diff --git a/src/nvme/api-types.h b/src/nvme/api-types.h index f5099a56d..c95978266 100644 --- a/src/nvme/api-types.h +++ b/src/nvme/api-types.h @@ -318,46 +318,6 @@ struct nvme_virtual_mgmt_args { __u16 nr; }; -/** - * struct nvme_zns_append_args - Arguments for the NVMe ZNS Append command - * @zslba: Zone start logical block address - * @result: The command completion result from CQE dword0 - * @data: Userspace address of the data - * @metadata: Userspace address of the metadata - * @args_size: Size of &struct nvme_zns_append_args - * @timeout: Timeout in ms - * @nsid: Namespace ID - * @ilbrt: Initial logical block reference tag - * @data_len: Length of @data - * @metadata_len: Length of @metadata - * @nlb: Number of logical blocks - * @control: - * @lbat: Logical block application tag - * @lbatm: Logical block application tag mask - * @rsvd1: Reserved - * @ilbrt_u64: Initial logical block reference tag - 8 byte - * version required for enhanced protection info - * - */ -struct nvme_zns_append_args { - __u64 zslba; - __u64 *result; - void *data; - void *metadata; - int args_size; - __u32 timeout; - __u32 nsid; - __u32 ilbrt; - __u32 data_len; - __u32 metadata_len; - __u16 nlb; - __u16 control; - __u16 lbat; - __u16 lbatm; - __u8 rsvd1[4]; - __u64 ilbrt_u64; -}; - /** * struct nvme_dim_args - Arguments for the Discovery Information Management (DIM) command * @result: Set on completion to the command's CQE DWORD 0 controller response. diff --git a/src/nvme/ioctl.c b/src/nvme/ioctl.c index 78b75b701..eb624e326 100644 --- a/src/nvme/ioctl.c +++ b/src/nvme/ioctl.c @@ -1315,47 +1315,6 @@ int nvme_io_passthru(nvme_link_t l, __u8 opcode, __u8 flags, __u16 rsvd, timeout_ms, result); } -int nvme_zns_append(nvme_link_t l, struct nvme_zns_append_args *args) -{ - const size_t size_v1 = sizeof_args(struct nvme_zns_append_args, lbatm, __u64); - const size_t size_v2 = sizeof_args(struct nvme_zns_append_args, ilbrt_u64, __u64); - __u32 cdw3, cdw10, cdw11, cdw12, cdw14, cdw15; - - if (args->args_size < size_v1 || args->args_size > size_v2) - return -EINVAL; - - cdw10 = args->zslba & 0xffffffff; - cdw11 = args->zslba >> 32; - cdw12 = args->nlb | (args->control << 16); - cdw15 = args->lbat | (args->lbatm << 16); - - if (args->args_size == size_v1) { - cdw3 = 0; - cdw14 = args->ilbrt; - } else { - cdw3 = (args->ilbrt_u64 >> 32) & 0xffffffff; - cdw14 = args->ilbrt_u64 & 0xffffffff; - } - - struct nvme_passthru_cmd64 cmd = { - .opcode = nvme_zns_cmd_append, - .nsid = args->nsid, - .cdw3 = cdw3, - .cdw10 = cdw10, - .cdw11 = cdw11, - .cdw12 = cdw12, - .cdw14 = cdw14, - .cdw15 = cdw15, - .data_len = args->data_len, - .addr = (__u64)(uintptr_t)args->data, - .metadata_len = args->metadata_len, - .metadata = (__u64)(uintptr_t)args->metadata, - .timeout_ms = args->timeout, - }; - - return nvme_submit_io_passthru64(l, &cmd, args->result); -} - int nvme_dim_send(nvme_link_t l, struct nvme_dim_args *args) { __u32 cdw10 = NVME_SET(args->tas, DIM_TAS); diff --git a/src/nvme/ioctl.h b/src/nvme/ioctl.h index c3b6196a6..cb7ff0d36 100644 --- a/src/nvme/ioctl.h +++ b/src/nvme/ioctl.h @@ -4972,12 +4972,55 @@ static inline int nvme_zns_report_zones(nvme_link_t l, __u32 nsid, __u64 slba, /** * nvme_zns_append() - Append data to a zone * @l: Link handle - * @args: &struct nvme_zns_append_args argument structure + * @nsid: Namespace ID + * @zslba: Zone start logical block address + * @nlb: Number of logical blocks + * @control: Upper 16 bits of cdw12 + * @cev: Command Extension Value + * @dspec: Directive Specific + * @lbatm: Logical block application tag mask + * @lbat: Logical block application tag + * @ilbrt_u64: Initial logical block reference tag - 8 byte + * version required for enhanced protection info + * @metadata: Userspace address of the metadata + * @metadata_len: Length of @metadata + * @data: Userspace address of the data + * @data_len: Length of @data + * @result: The command completion result from CQE dword0 * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_zns_append(nvme_link_t l, struct nvme_zns_append_args *args); +static inline int nvme_zns_append(nvme_link_t l, __u32 nsid, __u64 zslba, __u16 nlb, + __u16 control, __u16 cev, __u16 dspec, + __u16 lbat, __u16 lbatm, __u64 ilbrt_u64, + void *metadata, __u32 metadata_len, + void *data, __u32 data_len, __u64 *result) +{ + __u32 cdw3 = (ilbrt_u64 >> 32) & 0xffffffff; + __u32 cdw10 = zslba & 0xffffffff; + __u32 cdw11 = zslba >> 32; + __u32 cdw12 = nlb | (control << 16); + __u32 cdw14 = ilbrt_u64 & 0xffffffff; + __u32 cdw15 = lbat | (lbatm << 16); + + struct nvme_passthru_cmd64 cmd = { + .opcode = nvme_zns_cmd_append, + .nsid = nsid, + .cdw3 = cdw3, + .metadata = (__u64)(uintptr_t)metadata, + .addr = (__u64)(uintptr_t)data, + .metadata_len = metadata_len, + .data_len = data_len, + .cdw10 = cdw10, + .cdw11 = cdw11, + .cdw12 = cdw12, + .cdw14 = cdw14, + .cdw15 = cdw15, + }; + + return nvme_submit_io_passthru64(l, &cmd, result); +} /** * nvme_dim_send - Send a Discovery Information Management (DIM) command diff --git a/test/ioctl/zns.c b/test/ioctl/zns.c index 6ba76c813..3e2d16766 100644 --- a/test/ioctl/zns.c +++ b/test/ioctl/zns.c @@ -17,39 +17,35 @@ static nvme_link_t test_link; static void test_zns_append(void) { __u8 expected_data[8], data[8] = {}; + __u64 zslba = TEST_SLBA; + __u64 ilbrt_u64 = 0x76; + __u16 control = 0xcd; + __u16 cev = 0; + __u16 dspec = 0; + __u16 lbatm = 0x98; + __u16 lbat = 0xef; + __u16 nlb = 0xab; __u64 result = 0; - struct nvme_zns_append_args args = { - .zslba = TEST_SLBA, - .result = &result, - .data = &data, - .args_size = sizeof(args), - .nsid = TEST_NSID, - .data_len = sizeof(data), - .nlb = 0xab, - .control = 0xcd, - .lbat = 0xef, - .lbatm = 0x98, - .ilbrt_u64 = 0x76, - }; + int err; struct mock_cmd mock_io_cmd = { .opcode = nvme_zns_cmd_append, .nsid = TEST_NSID, - .cdw3 = (args.ilbrt_u64 >> 32) & 0xffffffff, - .cdw10 = args.zslba & 0xffffffff, - .cdw11 = args.zslba >> 32, - .cdw12 = args.nlb | (args.control << 16), - .cdw14 = args.ilbrt_u64 & 0xffffffff, - .cdw15 = args.lbat | (args.lbatm << 16), + .cdw3 = (ilbrt_u64 >> 32) & 0xffffffff, + .cdw10 = zslba & 0xffffffff, + .cdw11 = zslba >> 32, + .cdw12 = nlb | (control << 16), + .cdw14 = ilbrt_u64 & 0xffffffff, + .cdw15 = lbat | (lbatm << 16), .data_len = sizeof(expected_data), .out_data = &expected_data, }; - int err; - arbitrary(&expected_data, sizeof(expected_data)); set_mock_io_cmds(&mock_io_cmd, 1); - err = nvme_zns_append(test_link, &args); + err = nvme_zns_append(test_link, TEST_NSID, zslba, nlb, control, + cev, dspec, lbat, lbatm, ilbrt_u64, + NULL, 0, &data, sizeof(data), &result); end_mock_cmds(); check(err == 0, "returned error %d", err); check(result == 0, "wrong result"); From f83b1b26f7d197f95e330352622ec534dde8253f Mon Sep 17 00:00:00 2001 From: Tokunori Ikegami Date: Mon, 11 Aug 2025 15:48:13 +0900 Subject: [PATCH 43/66] ioctl: nvme_dim_send use nvme_passthru_cmd directly Drop struct nvme_dim_args. Signed-off-by: Tokunori Ikegami --- src/libnvme.map | 1 - src/nvme/api-types.h | 18 ------------------ src/nvme/fabrics.c | 11 +---------- src/nvme/ioctl.c | 19 ------------------- src/nvme/ioctl.h | 20 ++++++++++++++++++-- test/ioctl/misc.c | 20 +++++++------------- 6 files changed, 26 insertions(+), 63 deletions(-) diff --git a/src/libnvme.map b/src/libnvme.map index 937c0b204..951216d20 100644 --- a/src/libnvme.map +++ b/src/libnvme.map @@ -61,7 +61,6 @@ LIBNVME_2_0 { nvme_default_host; nvme_describe_key_serial; nvme_dev_self_test; - nvme_dim_send; nvme_directive_recv; nvme_directive_send; nvme_directive_send_id_endir; diff --git a/src/nvme/api-types.h b/src/nvme/api-types.h index c95978266..7069694d6 100644 --- a/src/nvme/api-types.h +++ b/src/nvme/api-types.h @@ -318,24 +318,6 @@ struct nvme_virtual_mgmt_args { __u16 nr; }; -/** - * struct nvme_dim_args - Arguments for the Discovery Information Management (DIM) command - * @result: Set on completion to the command's CQE DWORD 0 controller response. - * @data: Pointer to the DIM data - * @args_size: Length of the structure - * @timeout: Timeout in ms - * @data_len: Length of @data - * @tas: Task field of the Command Dword 10 (cdw10) - */ -struct nvme_dim_args { - __u32 *result; - void *data; - int args_size; - __u32 timeout; - __u32 data_len; - __u8 tas; -}; - /** * struct nvme_lm_cdq_args - Arguments for Controller Data Queue (CDQ) command * @result: Set on completion to the command's CQE DWORD 0 controller response diff --git a/src/nvme/fabrics.c b/src/nvme/fabrics.c index e81601495..1b424dfc2 100644 --- a/src/nvme/fabrics.c +++ b/src/nvme/fabrics.c @@ -1601,13 +1601,6 @@ static int nvmf_dim(nvme_ctrl_t c, enum nvmf_dim_tas tas, __u8 trtype, __u32 tel; int ret; - struct nvme_dim_args args = { - .args_size = sizeof(args), - .result = result, - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .tas = tas - }; - if (!c->s) { nvme_msg(r, LOG_ERR, "%s: failed to perform DIM. subsystem undefined.\n", @@ -1673,9 +1666,7 @@ static int nvmf_dim(nvme_ctrl_t c, enum nvmf_dim_tas tas, __u8 trtype, die = &dim->die->extended; nvmf_fill_die(die, c->s->h, tel, trtype, adrfam, reg_addr, tsas); - args.data_len = tdl; - args.data = dim; - return nvme_dim_send(nvme_ctrl_get_link(c), &args); + return nvme_dim_send(nvme_ctrl_get_link(c), tas, dim, tdl, result); } /** diff --git a/src/nvme/ioctl.c b/src/nvme/ioctl.c index eb624e326..1e7f75a01 100644 --- a/src/nvme/ioctl.c +++ b/src/nvme/ioctl.c @@ -1315,25 +1315,6 @@ int nvme_io_passthru(nvme_link_t l, __u8 opcode, __u8 flags, __u16 rsvd, timeout_ms, result); } -int nvme_dim_send(nvme_link_t l, struct nvme_dim_args *args) -{ - __u32 cdw10 = NVME_SET(args->tas, DIM_TAS); - - struct nvme_passthru_cmd cmd = { - .opcode = nvme_admin_discovery_info_mgmt, - .cdw10 = cdw10, - .addr = (__u64)(uintptr_t)args->data, - .data_len = args->data_len, - .timeout_ms = args->timeout, - }; - - if (args->args_size < sizeof(*args)) - return -EINVAL; - - return nvme_submit_admin_passthru(l, &cmd, args->result); -} - - int nvme_lm_cdq(nvme_link_t l, struct nvme_lm_cdq_args *args) { const size_t size_v1 = sizeof_args(struct nvme_lm_cdq_args, sz_u8, __u64); diff --git a/src/nvme/ioctl.h b/src/nvme/ioctl.h index cb7ff0d36..34eb950c6 100644 --- a/src/nvme/ioctl.h +++ b/src/nvme/ioctl.h @@ -5025,12 +5025,28 @@ static inline int nvme_zns_append(nvme_link_t l, __u32 nsid, __u64 zslba, __u16 /** * nvme_dim_send - Send a Discovery Information Management (DIM) command * @l: Link handle - * @args: &struct nvme_dim_args argument structure + * @tas: Task field of the Command Dword 10 (cdw10) + * @data: Pointer to the DIM data + * @data_len: Length of @data + * @result: Set on completion to the command's CQE DWORD 0 controller response. * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_dim_send(nvme_link_t l, struct nvme_dim_args *args); +static inline int nvme_dim_send(nvme_link_t l, __u8 tas, void *data, + __u32 data_len, __u32 *result) +{ + __u32 cdw10 = NVME_SET(tas, DIM_TAS); + + struct nvme_passthru_cmd cmd = { + .opcode = nvme_admin_discovery_info_mgmt, + .addr = (__u64)(uintptr_t)data, + .data_len = data_len, + .cdw10 = cdw10, + }; + + return nvme_submit_admin_passthru(l, &cmd, result); +} /** * nvme_lm_cdq() - Controller Data Queue - Controller Data Queue command diff --git a/test/ioctl/misc.c b/test/ioctl/misc.c index 6a94d35a5..e10cbf573 100644 --- a/test/ioctl/misc.c +++ b/test/ioctl/misc.c @@ -1318,29 +1318,23 @@ static void test_fdp_reclaim_unit_handle_update(void) static void test_dim_send(void) { - __u32 result = 0; __u8 expected_data[8], data[8] = {}; - struct nvme_dim_args args = { - .result = 0, - .data = &data, - .args_size = sizeof(args), - .data_len = sizeof(data), - .tas = 0xf, - }; + __u32 data_len = sizeof(data); + __u32 result = 0; + __u8 tas = 0xf; + int err; struct mock_cmd mock_admin_cmd = { .opcode = nvme_admin_discovery_info_mgmt, - .cdw10 = args.tas, - .data_len = args.data_len, + .cdw10 = tas, + .data_len = data_len, .in_data = &expected_data, }; - int err; - arbitrary(&expected_data, sizeof(expected_data)); memcpy(&data, &expected_data, sizeof(expected_data)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_dim_send(test_link, &args); + err = nvme_dim_send(test_link, tas, &data, data_len, NULL); end_mock_cmds(); check(err == 0, "returned error %d", err); check(result == 0, "returned result %u", result); From cc71ada5315d5f3bcbb54108419b1355ced70468 Mon Sep 17 00:00:00 2001 From: Tokunori Ikegami Date: Mon, 11 Aug 2025 22:18:12 +0900 Subject: [PATCH 44/66] ioctl: nvme_lm_cdq use nvme_passthru_cmd directly Drop struct nvme_lm_cdq_args. Signed-off-by: Tokunori Ikegami [wagi: reorder arguments] Signed-off-by: Daniel Wagner --- src/libnvme.map | 1 - src/nvme/api-types.h | 30 ----------------------------- src/nvme/ioctl.c | 46 -------------------------------------------- src/nvme/ioctl.h | 43 +++++++++++++++++++++++++++++++++++++++-- test/ioctl/misc.c | 22 ++++++++------------- 5 files changed, 49 insertions(+), 93 deletions(-) diff --git a/src/libnvme.map b/src/libnvme.map index 951216d20..74cfc8867 100644 --- a/src/libnvme.map +++ b/src/libnvme.map @@ -168,7 +168,6 @@ LIBNVME_2_0 { nvme_link_is_chardev; nvme_link_is_direct; nvme_link_is_mi; - nvme_lm_cdq; nvme_lm_get_features_ctrl_data_queue; nvme_lm_migration_recv; nvme_lm_migration_send; diff --git a/src/nvme/api-types.h b/src/nvme/api-types.h index 7069694d6..7ea8fb685 100644 --- a/src/nvme/api-types.h +++ b/src/nvme/api-types.h @@ -318,36 +318,6 @@ struct nvme_virtual_mgmt_args { __u16 nr; }; -/** - * struct nvme_lm_cdq_args - Arguments for Controller Data Queue (CDQ) command - * @result: Set on completion to the command's CQE DWORD 0 controller response - * @data: Pointer to data - * @args_size: Length of structure - * @timeout: Timeout in ms - * @mos: Management Operation Specific (MOS): This field is specific to the SEL type - * @cntlid: Controller ID: For Create CDQ, specifies the target migratable controller - * @cdqid: Controller Data Queue ID (CDQID): For Create CDQ, this field is the CDQID created - * by the controller if no error is present. For Delete CDQ, this field is the CDQID - * to delete. - * @sel: Select (SEL): This field specifies the type of management operation to perform. - * @sz_u8: For Create CDQ, specifies the size of CDQ, in dwords - 1 byte - * @rsvd1: Reserved - * @sz: For Create CDQ, specifies the size of CDQ, in dwords - 4 byte - */ -struct nvme_lm_cdq_args { - __u32 *result; - void *data; - int args_size; - __u32 timeout; - __u16 mos; - __u16 cntlid; - __u16 cdqid; - __u8 sel; - __u8 sz_u8; - __u8 rsvd1[4]; - __u32 sz; -}; - /** * struct nvme_lm_track_send_args - Arguments for the Track Send command * @result: Set on completion to the command's CQE DWORD 0 controller response diff --git a/src/nvme/ioctl.c b/src/nvme/ioctl.c index 1e7f75a01..8398e3538 100644 --- a/src/nvme/ioctl.c +++ b/src/nvme/ioctl.c @@ -1315,52 +1315,6 @@ int nvme_io_passthru(nvme_link_t l, __u8 opcode, __u8 flags, __u16 rsvd, timeout_ms, result); } -int nvme_lm_cdq(nvme_link_t l, struct nvme_lm_cdq_args *args) -{ - const size_t size_v1 = sizeof_args(struct nvme_lm_cdq_args, sz_u8, __u64); - const size_t size_v2 = sizeof_args(struct nvme_lm_cdq_args, sz, __u64); - __u32 cdw10 = NVME_SET(args->sel, LM_CDQ_SEL) | - NVME_SET(args->mos, LM_CDQ_MOS); - __u32 cdw11 = 0, data_len = 0, sz = 0; - int err; - - if (args->args_size < size_v1 || args->args_size > size_v2) - return -EINVAL; - - if (args->args_size == size_v1) - sz = args->sz_u8; - else - sz = args->sz; - - if (args->sel == NVME_LM_SEL_CREATE_CDQ) { - cdw11 = NVME_SET(NVME_SET(args->cntlid, LM_CREATE_CDQ_CNTLID), LM_CQS) | - NVME_LM_CREATE_CDQ_PC; - data_len = sz << 2; - } else if (args->sel == NVME_LM_SEL_DELETE_CDQ) { - cdw11 = NVME_SET(args->cdqid, LM_DELETE_CDQ_CDQID); - } - - struct nvme_passthru_cmd cmd = { - .opcode = nvme_admin_ctrl_data_queue, - .cdw10 = cdw10, - .cdw11 = cdw11, - .cdw12 = sz, - .addr = (__u64)(uintptr_t)args->data, - .data_len = data_len, - .timeout_ms = args->timeout, - }; - - if (args->args_size < sizeof(*args)) - return -EINVAL; - - err = nvme_submit_admin_passthru(l, &cmd, args->result); - - if (!err) - args->cdqid = NVME_GET(cmd.result, LM_CREATE_CDQ_CDQID); - - return err; -} - int nvme_lm_track_send(nvme_link_t l, struct nvme_lm_track_send_args *args) { __u32 cdw10 = NVME_SET(args->sel, LM_TRACK_SEND_SEL) | diff --git a/src/nvme/ioctl.h b/src/nvme/ioctl.h index 34eb950c6..395ba1327 100644 --- a/src/nvme/ioctl.h +++ b/src/nvme/ioctl.h @@ -5051,12 +5051,51 @@ static inline int nvme_dim_send(nvme_link_t l, __u8 tas, void *data, /** * nvme_lm_cdq() - Controller Data Queue - Controller Data Queue command * @l: Link handle - * @args: &struct nvme_lm_cdq_args argument structure + * @sel: Select (SEL): This field specifies the type of management operation to perform. + * @mos: Management Operation Specific (MOS): This field is specific to the SEL type + * @cntlid: Controller ID: For Create CDQ, specifies the target migratable controller + * @sz: For Create CDQ, specifies the size of CDQ, in dwords - 4 byte + * @data: Pointer to data + * @cdqid: Controller Data Queue ID (CDQID): For Create CDQ, this field is the CDQID created + * by the controller if no error is present. For Delete CDQ, this field is the CDQID + * to delete. + * @result: Set on completion to the command's CQE DWORD 0 controller response * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise.) */ -int nvme_lm_cdq(nvme_link_t l, struct nvme_lm_cdq_args *args); +static inline int nvme_lm_cdq(nvme_link_t l, __u8 sel, __u16 mos, __u16 cntlid, + __u32 sz, void *data, __u16 *cdqid, __u32 *result) +{ + __u32 cdw10 = NVME_SET(sel, LM_CDQ_SEL) | + NVME_SET(mos, LM_CDQ_MOS); + __u32 cdw11 = 0, data_len = 0; + int err; + + if (sel == NVME_LM_SEL_CREATE_CDQ) { + cdw11 = NVME_SET(NVME_SET(cntlid, LM_CREATE_CDQ_CNTLID), LM_CQS) | + NVME_LM_CREATE_CDQ_PC; + data_len = sz << 2; + } else if (sel == NVME_LM_SEL_DELETE_CDQ) { + cdw11 = NVME_SET(*cdqid, LM_DELETE_CDQ_CDQID); + } + + struct nvme_passthru_cmd cmd = { + .opcode = nvme_admin_ctrl_data_queue, + .addr = (__u64)(uintptr_t)data, + .data_len = data_len, + .cdw10 = cdw10, + .cdw11 = cdw11, + .cdw12 = sz, + }; + + err = nvme_submit_admin_passthru(l, &cmd, result); + + if (!err) + *cdqid = NVME_GET(cmd.result, LM_CREATE_CDQ_CDQID); + + return err; +} /** * nvme_lm_track_send() - Track Send command diff --git a/test/ioctl/misc.c b/test/ioctl/misc.c index e10cbf573..1e6d6d76b 100644 --- a/test/ioctl/misc.c +++ b/test/ioctl/misc.c @@ -1345,22 +1345,16 @@ static void test_lm_cdq(void) { __u32 result = 0; __u8 expected_data[8], data[8] = {}; - struct nvme_lm_cdq_args args = { - .result = 0, - .data = &data, - .args_size = sizeof(args), - .mos = 0x1, - .cntlid = 0x2, - .cdqid = 0x3, - .sel = NVME_LM_SEL_DELETE_CDQ, - .sz = 0x4, - }; + __u16 mos = 0x1; + __u16 cdqid = 0x3; + __u8 sel = NVME_LM_SEL_DELETE_CDQ; + __u32 sz = 0x4; struct mock_cmd mock_admin_cmd = { .opcode = nvme_admin_ctrl_data_queue, - .cdw10 = args.sel | (args.mos << 16), - .cdw11 = args.cdqid, - .cdw12 = args.sz, + .cdw10 = sel | (mos << 16), + .cdw11 = cdqid, + .cdw12 = sz, .data_len = 0, .in_data = &expected_data, }; @@ -1370,7 +1364,7 @@ static void test_lm_cdq(void) arbitrary(&expected_data, sizeof(expected_data)); memcpy(&data, &expected_data, sizeof(expected_data)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_lm_cdq(test_link, &args); + err = nvme_lm_cdq(test_link, sel, mos, 0x2, sz, &data, &cdqid, NULL); end_mock_cmds(); check(err == 0, "returned error %d", err); check(result == 0, "returned result %u", result); From 6194feb8d5fb9d75259319393f64de6144ec830c Mon Sep 17 00:00:00 2001 From: Tokunori Ikegami Date: Mon, 11 Aug 2025 22:58:06 +0900 Subject: [PATCH 45/66] ioctl: nvme_lm_track_send use nvme_passthru_cmd directly Drop struct nvme_lm_track_send_args. Signed-off-by: Tokunori Ikegami [wagi: reordered arguments] Signed-off-by: Daniel Wagner --- src/libnvme.map | 1 - src/nvme/api-types.h | 18 ------------------ src/nvme/ioctl.c | 18 ------------------ src/nvme/ioctl.h | 24 ++++++++++++++++++++++-- test/ioctl/misc.c | 19 +++++++------------ 5 files changed, 29 insertions(+), 51 deletions(-) diff --git a/src/libnvme.map b/src/libnvme.map index 74cfc8867..718640ba9 100644 --- a/src/libnvme.map +++ b/src/libnvme.map @@ -172,7 +172,6 @@ LIBNVME_2_0 { nvme_lm_migration_recv; nvme_lm_migration_send; nvme_lm_set_features_ctrl_data_queue; - nvme_lm_track_send; nvme_lockdown; nvme_lookup_ctrl; nvme_lookup_host; diff --git a/src/nvme/api-types.h b/src/nvme/api-types.h index 7ea8fb685..fc18d0014 100644 --- a/src/nvme/api-types.h +++ b/src/nvme/api-types.h @@ -318,24 +318,6 @@ struct nvme_virtual_mgmt_args { __u16 nr; }; -/** - * struct nvme_lm_track_send_args - Arguments for the Track Send command - * @result: Set on completion to the command's CQE DWORD 0 controller response - * @args_size: Length of structure - * @timeout: Timeout in ms - * @mos: Management Operation Specific (MOS): This field is specific to the SEL type - * @cdqid: Controller Data Queue ID (CDQID) - * @sel: Select (SEL): This field specifies the type of management operation to perform - */ -struct nvme_lm_track_send_args { - __u32 *result; - int args_size; - __u32 timeout; - __u16 mos; - __u16 cdqid; - __u8 sel; -}; - /** * struct nvme_lm_migration_send_args - Arguments for the Migration Send command * @offset: Offset: This field specifies the offset, in bytes, within the data available to be diff --git a/src/nvme/ioctl.c b/src/nvme/ioctl.c index 8398e3538..09c3c2bb1 100644 --- a/src/nvme/ioctl.c +++ b/src/nvme/ioctl.c @@ -1315,24 +1315,6 @@ int nvme_io_passthru(nvme_link_t l, __u8 opcode, __u8 flags, __u16 rsvd, timeout_ms, result); } -int nvme_lm_track_send(nvme_link_t l, struct nvme_lm_track_send_args *args) -{ - __u32 cdw10 = NVME_SET(args->sel, LM_TRACK_SEND_SEL) | - NVME_SET(args->mos, LM_TRACK_SEND_MOS); - - struct nvme_passthru_cmd cmd = { - .opcode = nvme_admin_track_send, - .cdw10 = cdw10, - .cdw11 = args->cdqid, - .timeout_ms = args->timeout, - }; - - if (args->args_size < sizeof(*args)) - return -EINVAL; - - return nvme_submit_admin_passthru(l, &cmd, args->result); -} - int nvme_lm_migration_send(nvme_link_t l, struct nvme_lm_migration_send_args *args) { __u32 cdw10 = NVME_SET(args->sel, LM_MIGRATION_SEND_SEL) | diff --git a/src/nvme/ioctl.h b/src/nvme/ioctl.h index 395ba1327..caeb0f075 100644 --- a/src/nvme/ioctl.h +++ b/src/nvme/ioctl.h @@ -5100,12 +5100,32 @@ static inline int nvme_lm_cdq(nvme_link_t l, __u8 sel, __u16 mos, __u16 cntlid, /** * nvme_lm_track_send() - Track Send command * @l: Link handle - * @args: &struct nvme_lm_track_send_args argument structure + * @sel: Select (SEL): This field specifies the type of + * management operation to perform + * @mos: Management Operation Specific (MOS): This field + * is specific to the SEL type + * @cdqid: Controller Data Queue ID (CDQID) + * @result: Set on completion to the command's CQE DWORD 0 + * controller response * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_lm_track_send(nvme_link_t l, struct nvme_lm_track_send_args *args); +static inline int nvme_lm_track_send(nvme_link_t l, __u8 sel, __u16 mos, + __u16 cdqid, __u32 *result) + +{ + __u32 cdw10 = NVME_SET(sel, LM_TRACK_SEND_SEL) | + NVME_SET(mos, LM_TRACK_SEND_MOS); + + struct nvme_passthru_cmd cmd = { + .opcode = nvme_admin_track_send, + .cdw10 = cdw10, + .cdw11 = cdqid, + }; + + return nvme_submit_admin_passthru(l, &cmd, result); +} /** * nvme_lm_migration_send() - Migration Send command diff --git a/test/ioctl/misc.c b/test/ioctl/misc.c index 1e6d6d76b..ff23ebd8a 100644 --- a/test/ioctl/misc.c +++ b/test/ioctl/misc.c @@ -1373,25 +1373,20 @@ static void test_lm_cdq(void) static void test_lm_track_send(void) { + __u8 sel = NVME_LM_SEL_DELETE_CDQ; + __u16 cdqid = 0x3; __u32 result = 0; - struct nvme_lm_track_send_args args = { - .result = 0, - .args_size = sizeof(args), - .mos = 0x1, - .cdqid = 0x3, - .sel = NVME_LM_SEL_DELETE_CDQ, - }; + __u16 mos = 0x1; + int err; struct mock_cmd mock_admin_cmd = { .opcode = nvme_admin_track_send, - .cdw10 = args.sel | (args.mos << 16), - .cdw11 = args.cdqid, + .cdw10 = sel | (mos << 16), + .cdw11 = cdqid, }; - int err; - set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_lm_track_send(test_link, &args); + err = nvme_lm_track_send(test_link, sel, mos, cdqid, NULL); end_mock_cmds(); check(err == 0, "returned error %d", err); check(result == 0, "returned result %u", result); From e88499e687a6cd969649c8eac0199c2d989ceadb Mon Sep 17 00:00:00 2001 From: Tokunori Ikegami Date: Mon, 11 Aug 2025 23:37:43 +0900 Subject: [PATCH 46/66] ioctl: nvme_lm_migration_send use nvme_passthru_cmd directly Drop struct nvme_lm_migration_send_args. Signed-off-by: Tokunori Ikegami [wagi: reordered arguments] Signed-off-by: Daniel Wagner --- src/libnvme.map | 1 - src/nvme/api-types.h | 47 ------------------------------- src/nvme/ioctl.c | 38 ------------------------- src/nvme/ioctl.h | 67 ++++++++++++++++++++++++++++++++++++++++++-- test/ioctl/misc.c | 50 +++++++++++++++------------------ 5 files changed, 88 insertions(+), 115 deletions(-) diff --git a/src/libnvme.map b/src/libnvme.map index 718640ba9..8f4d77c22 100644 --- a/src/libnvme.map +++ b/src/libnvme.map @@ -170,7 +170,6 @@ LIBNVME_2_0 { nvme_link_is_mi; nvme_lm_get_features_ctrl_data_queue; nvme_lm_migration_recv; - nvme_lm_migration_send; nvme_lm_set_features_ctrl_data_queue; nvme_lockdown; nvme_lookup_ctrl; diff --git a/src/nvme/api-types.h b/src/nvme/api-types.h index fc18d0014..1728531fa 100644 --- a/src/nvme/api-types.h +++ b/src/nvme/api-types.h @@ -318,53 +318,6 @@ struct nvme_virtual_mgmt_args { __u16 nr; }; -/** - * struct nvme_lm_migration_send_args - Arguments for the Migration Send command - * @offset: Offset: This field specifies the offset, in bytes, within the data available to be - * returned and specifies the starting point for that data for what is actually - * returned to the host. - * @result: Set on completion to the command's CQE DWORD 0 controller response - * @data: Pointer to data - * @args_size: Length of structure - * @timeout: Timeout in ms - * @numd: Number of Dwords (NUMD): This field specifies the number of dwords being transferred - * @mos: Management Operation Specific (MOS): This field is specific to the SEL type - * @cntlid: Controller ID: This field specifies the identifier of the controller to which the - * operation is performed. - * @csuuidi: Controller State UUID Index (CSUUIDI): A non-zero value in this field specifies the - * index to a specific entry in the Vendor Specific Controller State UUID Supported. - * list of the Supported Controller State Formats data structure. - * @sel: Select (SEL): This field specifies the type of management operation to perform. - * @uidx: UUID Index (UIDX): If this field is set to a non-zero value, then the value of this - * field is the index of a UUID in the UUID List (refer to Figure 320) that is used by - * the command. - * @stype: Suspend Type (STYPE): This field specifies the type of suspend. - * @seqind: Sequence Identifier (SEQIND): This field identified the sequences of this Migration - * Send command in relation to other Migration Send commands. - * @csvi: Controller State Version Index (CSVI): A non-zero value in this field specifies the - * index to a specific entry in the NVMe Controller State Version list of the Supported - * Controller State Formats data structure. - * @dudmq: Delete User Data Migration Queue (DUDMQ): If set, the migration queue is deleted - * is deleted as part of the Suspend operation. If cleared, it is retained. - */ -struct nvme_lm_migration_send_args { - __u64 offset; - __u32 *result; - void *data; - int args_size; - __u32 timeout; - __u32 numd; - __u16 mos; - __u16 cntlid; - __u16 csuuidi; - __u8 sel; - __u8 uidx; - __u8 stype; - __u8 seqind; - __u8 csvi; - bool dudmq; -}; - /** * struct nvme_lm_migration_recv_args - Arguments for the Migration Receive command * @offset: Offset: This field specifies the offset, in bytes, within the data available to be diff --git a/src/nvme/ioctl.c b/src/nvme/ioctl.c index 09c3c2bb1..8861a0e84 100644 --- a/src/nvme/ioctl.c +++ b/src/nvme/ioctl.c @@ -1315,44 +1315,6 @@ int nvme_io_passthru(nvme_link_t l, __u8 opcode, __u8 flags, __u16 rsvd, timeout_ms, result); } -int nvme_lm_migration_send(nvme_link_t l, struct nvme_lm_migration_send_args *args) -{ - __u32 cdw10 = NVME_SET(args->sel, LM_MIGRATION_SEND_SEL) | - NVME_SET(args->mos, LM_MIGRATION_SEND_MOS); - __u32 cdw11 = 0; - - if (args->sel == NVME_LM_SEL_SUSPEND) { - cdw11 = NVME_SET(args->stype, LM_STYPE) | - NVME_SET(args->cntlid, LM_SUSPEND_CNTLID); - if (args->dudmq) - cdw11 |= NVME_LM_DUDMQ; - } else if (args->sel == NVME_LM_SEL_RESUME) { - cdw11 = NVME_SET(args->cntlid, LM_RESUME_CNTLID); - } else if (args->sel == NVME_LM_SEL_SET_CONTROLLER_STATE) { - cdw11 = NVME_SET(args->csuuidi, LM_SET_CONTROLLER_STATE_CSUUIDI) | - NVME_SET(args->csvi, LM_SET_CONTROLLER_STATE_CSVI) | - NVME_SET(args->cntlid, LM_SET_CONTROLLER_STATE_CNTLID); - } - - struct nvme_passthru_cmd cmd = { - .opcode = nvme_admin_migration_send, - .cdw10 = cdw10, - .cdw11 = cdw11, - .cdw12 = (__u32)args->offset, - .cdw13 = (__u32)(args->offset >> 32), - .cdw14 = NVME_SET(args->uidx, LM_MIGRATION_SEND_UIDX), - .cdw15 = args->numd, - .addr = (__u64)(uintptr_t)args->data, - .data_len = args->numd << 2, - .timeout_ms = args->timeout, - }; - - if (args->args_size < sizeof(*args)) - return -EINVAL; - - return nvme_submit_admin_passthru(l, &cmd, args->result); -} - int nvme_lm_migration_recv(nvme_link_t l, struct nvme_lm_migration_recv_args *args) { __u32 cdw10 = NVME_SET(args->sel, LM_MIGRATION_RECV_SEL) | diff --git a/src/nvme/ioctl.h b/src/nvme/ioctl.h index caeb0f075..c9b538a26 100644 --- a/src/nvme/ioctl.h +++ b/src/nvme/ioctl.h @@ -5130,12 +5130,75 @@ static inline int nvme_lm_track_send(nvme_link_t l, __u8 sel, __u16 mos, /** * nvme_lm_migration_send() - Migration Send command * @l: Link handle - * @args: &struct nvme_lm_migration_send_args argument structure + * @sel: Select (SEL): This field specifies the type of management + * operation to perform. + * @mos: Management Operation Specific (MOS): This field is specific + * to the SEL type + * @cntlid: Controller ID: This field specifies the identifier of the + * controller to which the operation is performed. + * @stype: Suspend Type (STYPE): This field specifies the type of suspend. + * @dudmq: Delete User Data Migration Queue (DUDMQ): If set, the migration + * queue is deleted is deleted as part of the Suspend operation. + * If cleared, it is retained. + * @csvi: Controller State Version Index (CSVI): A non-zero value in this + * field specifies the index to a specific entry in the NVMe + * Controller State Version list of the Supported Controller State + * Formats data structure. + * @csuuidi: Controller State UUID Index (CSUUIDI): A non-zero value in this + * field specifies the index to a specific entry in the + * Vendor Specific Controller State UUID Supported. + * list of the Supported Controller State Formats data structure. + * @cso: Offset: This field specifies the offset, in bytes, within + * the data available to be returned and specifies the starting + * point for that data for what is actually returned to the host. + * @uidx: UUID Index (UIDX): If this field is set to a non-zero value, + * then the value of this field is the index of a UUID in the + * UUID List (refer to Figure 320) that is used by the command. + * @data: Pointer to data + * @data_len: Length of @data + * @result: Set on completion to the command's CQE DWORD 0 controller response * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_lm_migration_send(nvme_link_t l, struct nvme_lm_migration_send_args *args); +static inline int nvme_lm_migration_send(nvme_link_t l, __u16 sel, __u16 mos, + __u16 cntlid, __u8 stype, bool dudmq, + __u8 csvi, __u16 csuuidi, __u64 cso, + __u8 uidx, void *data, __u32 data_len, + __u32 *result) +{ + __u32 cdw10 = NVME_SET(sel, LM_MIGRATION_SEND_SEL) | + NVME_SET(mos, LM_MIGRATION_SEND_MOS); + __u32 cdw11 = 0; + __u32 cdw14 = NVME_SET(uidx, LM_MIGRATION_SEND_UIDX); + + if (sel == NVME_LM_SEL_SUSPEND) { + cdw11 = NVME_SET(stype, LM_STYPE) | + NVME_SET(cntlid, LM_SUSPEND_CNTLID); + if (dudmq) + cdw11 |= NVME_LM_DUDMQ; + } else if (sel == NVME_LM_SEL_RESUME) { + cdw11 = NVME_SET(cntlid, LM_RESUME_CNTLID); + } else if (sel == NVME_LM_SEL_SET_CONTROLLER_STATE) { + cdw11 = NVME_SET(csuuidi, LM_SET_CONTROLLER_STATE_CSUUIDI) | + NVME_SET(csvi, LM_SET_CONTROLLER_STATE_CSVI) | + NVME_SET(cntlid, LM_SET_CONTROLLER_STATE_CNTLID); + } + + struct nvme_passthru_cmd cmd = { + .opcode = nvme_admin_migration_send, + .addr = (__u64)(uintptr_t)data, + .data_len = data_len, + .cdw10 = cdw10, + .cdw11 = cdw11, + .cdw12 = (__u32)cso, + .cdw13 = (__u32)(cso >> 32), + .cdw14 = cdw14, + .cdw15 = (__u32)(data_len / sizeof(__u32)), + }; + + return nvme_submit_admin_passthru(l, &cmd, result); +} /** * nvme_lm_migration_recv - Migration Receive command diff --git a/test/ioctl/misc.c b/test/ioctl/misc.c index ff23ebd8a..23dfb3fa8 100644 --- a/test/ioctl/misc.c +++ b/test/ioctl/misc.c @@ -1394,43 +1394,39 @@ static void test_lm_track_send(void) static void test_lm_migration_send(void) { - __u32 result = 0; __u32 expected_data[8], data[8] = {}; - struct nvme_lm_migration_send_args args = { - .offset = 0xffffffffff, - .result = 0, - .data = &expected_data, - .args_size = sizeof(args), - .numd = 8 - 1, - .mos = 0x1, - .cntlid = 0x2, - .csuuidi = 0x3, - .sel = NVME_LM_SEL_RESUME, - .uidx = 0x4, - .stype = 0x5, - .seqind = 0x6, - .csvi = 0x7, - .dudmq = true, - }; + __u8 sel = NVME_LM_SEL_RESUME; + __u64 offset = 0xffffffffff; + __u32 numd = 8; + __u16 cntlid = 0x2; + __u32 result = 0; + __u16 mos = 0x1; + __u8 uidx = 0x4; + __u8 stype = 0x1; + __u8 csvi = 0x2; + __u16 csuuidi = 0x13; + bool dudmq = false; + int err; struct mock_cmd mock_admin_cmd = { .opcode = nvme_admin_migration_send, - .cdw10 = args.sel | (args.mos << 16), - .cdw11 = args.cntlid, - .cdw12 = (__u32)args.offset, - .cdw13 = (__u32)(args.offset >> 32), - .cdw14 = args.uidx, - .cdw15 = args.numd, - .data_len = args.numd << 2, + .cdw10 = sel | (mos << 16), + .cdw11 = cntlid, + .cdw12 = (__u32)offset, + .cdw13 = (__u32)(offset >> 32), + .cdw14 = uidx, + .cdw15 = numd, + .data_len = numd << 2, .in_data = &data, }; - int err; - arbitrary(&expected_data, sizeof(expected_data)); memcpy(&data, &expected_data, sizeof(expected_data)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_lm_migration_send(test_link, &args); + err = nvme_lm_migration_send(test_link, sel, mos, + cntlid, stype, dudmq, csvi, csuuidi, + offset, uidx, &expected_data, + sizeof(expected_data), NULL); end_mock_cmds(); check(err == 0, "returned error %d", err); check(result == 0, "returned result %u", result); From 7dbc090d0ad195b2b3905af6294af2decec26f29 Mon Sep 17 00:00:00 2001 From: Tokunori Ikegami Date: Mon, 11 Aug 2025 23:52:58 +0900 Subject: [PATCH 47/66] ioctl: nvme_lm_migration_recv use nvme_passthru_cmd directly Drop struct nvme_lm_migration_recv_args. Signed-off-by: Tokunori Ikegami --- src/libnvme.map | 1 - src/nvme/api-types.h | 41 -------------------------------------- src/nvme/ioctl.c | 32 ------------------------------ src/nvme/ioctl.h | 47 ++++++++++++++++++++++++++++++++++++++++++-- test/ioctl/misc.c | 45 +++++++++++++++++++----------------------- 5 files changed, 65 insertions(+), 101 deletions(-) diff --git a/src/libnvme.map b/src/libnvme.map index 8f4d77c22..bd969e0a1 100644 --- a/src/libnvme.map +++ b/src/libnvme.map @@ -169,7 +169,6 @@ LIBNVME_2_0 { nvme_link_is_direct; nvme_link_is_mi; nvme_lm_get_features_ctrl_data_queue; - nvme_lm_migration_recv; nvme_lm_set_features_ctrl_data_queue; nvme_lockdown; nvme_lookup_ctrl; diff --git a/src/nvme/api-types.h b/src/nvme/api-types.h index 1728531fa..068394b67 100644 --- a/src/nvme/api-types.h +++ b/src/nvme/api-types.h @@ -317,45 +317,4 @@ struct nvme_virtual_mgmt_args { __u16 cntlid; __u16 nr; }; - -/** - * struct nvme_lm_migration_recv_args - Arguments for the Migration Receive command - * @offset: Offset: This field specifies the offset, in bytes, within the data available to be - * returned and specifies the starting point for that data for what is actually - * returned to the host. - * @result: Set on completion to the command's CQE DWORD 0 controller response - * @data: Pointer to data - * @args_size: Length of structure - * @fd: File descriptor of nvme device - * @timeout: Timeout in ms - * @numd: Number of Dwords (NUMD): This field specifies the number of dwords to return. This - * is a 0's based value. - * @mos: Management Operation Specific (MOS): This field is specific to the SEL type - * @cntlid: Controller ID: This field specifies the identifier of the controller to which the - * operation is performed. - * @csuuidi: Controller State UUID Index (CSUUIDI): A non-zero value in this field specifies the - * index to a specific entry in the Vendor Specific Controller State UUID Supported. - * list of the Supported Controller State Formats data structure. - * @sel: Select (SEL): This field specifies the type of management operation to perform - * @uidx: UUID Index (UIDX): If this field is set to a non-zero value, then the value of this - * field is the index of a UUID in the UUID List (refer to Figure 320) that is used by - * the command. - * @csuidxp: Controller State UUID Index Parameter (CSUIDXP): This field is vendor specific. - */ -struct nvme_lm_migration_recv_args { - __u64 offset; - __u32 *result; - void *data; - int args_size; - int fd; - __u32 timeout; - __u32 numd; - __u16 mos; - __u16 cntlid; - __u16 csuuidi; - __u8 sel; - __u8 uidx; - __u8 csuidxp; -}; - #endif /* _LIBNVME_API_TYPES_H */ diff --git a/src/nvme/ioctl.c b/src/nvme/ioctl.c index 8861a0e84..2830f1b27 100644 --- a/src/nvme/ioctl.c +++ b/src/nvme/ioctl.c @@ -1315,38 +1315,6 @@ int nvme_io_passthru(nvme_link_t l, __u8 opcode, __u8 flags, __u16 rsvd, timeout_ms, result); } -int nvme_lm_migration_recv(nvme_link_t l, struct nvme_lm_migration_recv_args *args) -{ - __u32 cdw10 = NVME_SET(args->sel, LM_MIGRATION_RECV_SEL) | - NVME_SET(args->mos, LM_MIGRATION_RECV_MOS); - __u32 cdw11 = 0, data_len = 0; - - if (args->sel == NVME_LM_SEL_GET_CONTROLLER_STATE) { - cdw11 = NVME_SET(args->csuidxp, LM_GET_CONTROLLER_STATE_CSUIDXP) | - NVME_SET(args->csuuidi, LM_GET_CONTROLLER_STATE_CSUUIDI) | - NVME_SET(args->cntlid, LM_GET_CONTROLLER_STATE_CNTLID); - data_len = (args->numd + 1 /*0's based*/) << 2; - } - - struct nvme_passthru_cmd cmd = { - .opcode = nvme_admin_migration_receive, - .cdw10 = cdw10, - .cdw11 = cdw11, - .cdw12 = (__u32)args->offset, - .cdw13 = (__u32)(args->offset >> 32), - .cdw14 = NVME_SET(args->uidx, LM_MIGRATION_RECV_UIDX), - .cdw15 = args->numd, - .addr = (__u64)(uintptr_t)args->data, - .data_len = data_len, - .timeout_ms = args->timeout, - }; - - if (args->args_size < sizeof(*args)) - return -EINVAL; - - return nvme_submit_admin_passthru(l, &cmd, args->result); -} - int nvme_lm_get_features_ctrl_data_queue(nvme_link_t l, __u16 cdqid, struct nvme_lm_ctrl_data_queue_fid_data *data, __u32 *result) diff --git a/src/nvme/ioctl.h b/src/nvme/ioctl.h index c9b538a26..155aaefa1 100644 --- a/src/nvme/ioctl.h +++ b/src/nvme/ioctl.h @@ -5203,12 +5203,55 @@ static inline int nvme_lm_migration_send(nvme_link_t l, __u16 sel, __u16 mos, /** * nvme_lm_migration_recv - Migration Receive command * @l: Link handle - * @args: &struct nvme_lm_migration_rev_args argument structure + * @offset: Offset: This field specifies the offset, in bytes, within the data available to be + * returned and specifies the starting point for that data for what is actually + * returned to the host. + * @mos: Management Operation Specific (MOS): This field is specific to the SEL type + * @cntlid: Controller ID: This field specifies the identifier of the controller to which the + * operation is performed. + * @csuuidi: Controller State UUID Index (CSUUIDI): A non-zero value in this field specifies the + * index to a specific entry in the Vendor Specific Controller State UUID Supported. + * list of the Supported Controller State Formats data structure. + * @sel: Select (SEL): This field specifies the type of management operation to perform + * @uidx: UUID Index (UIDX): If this field is set to a non-zero value, then the value of this + * field is the index of a UUID in the UUID List (refer to Figure 320) that is used by + * the command. + * @csuidxp: Controller State UUID Index Parameter (CSUIDXP): This field is vendor specific. + * @data: Pointer to data + * @len: Length of @data + * @result: Set on completion to the command's CQE DWORD 0 controller response * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_lm_migration_recv(nvme_link_t l, struct nvme_lm_migration_recv_args *args); +static inline int nvme_lm_migration_recv(nvme_link_t l, __u64 offset, __u16 mos, __u16 cntlid, + __u16 csuuidi, __u8 sel, __u8 uidx, __u8 csuidxp, + void *data, __u32 len, __u32 *result) +{ + __u32 cdw10 = NVME_SET(sel, LM_MIGRATION_RECV_SEL) | NVME_SET(mos, LM_MIGRATION_RECV_MOS); + __u32 cdw11 = 0, data_len = 0; + + if (sel == NVME_LM_SEL_GET_CONTROLLER_STATE) { + cdw11 = NVME_SET(csuidxp, LM_GET_CONTROLLER_STATE_CSUIDXP) | + NVME_SET(csuuidi, LM_GET_CONTROLLER_STATE_CSUUIDI) | + NVME_SET(cntlid, LM_GET_CONTROLLER_STATE_CNTLID); + data_len = len; + } + + struct nvme_passthru_cmd cmd = { + .opcode = nvme_admin_migration_receive, + .addr = (__u64)(uintptr_t)data, + .data_len = data_len, + .cdw10 = cdw10, + .cdw11 = cdw11, + .cdw12 = (__u32)offset, + .cdw13 = (__u32)(offset >> 32), + .cdw14 = NVME_SET(uidx, LM_MIGRATION_RECV_UIDX), + .cdw15 = len ? (__u32)((len - 1) / sizeof(__u32)) : 0, /* 0's based */ + }; + + return nvme_submit_admin_passthru(l, &cmd, result); +} /** * nvme_lm_set_features_ctrl_data_queue - Set Controller Datea Queue feature diff --git a/test/ioctl/misc.c b/test/ioctl/misc.c index 23dfb3fa8..b8aaddeee 100644 --- a/test/ioctl/misc.c +++ b/test/ioctl/misc.c @@ -1435,40 +1435,35 @@ static void test_lm_migration_send(void) static void test_lm_migration_recv(void) { - __u32 result = 0; + __u8 sel = NVME_LM_SEL_GET_CONTROLLER_STATE; __u32 expected_data[8], data[8] = {}; - struct nvme_lm_migration_recv_args args = { - .offset = 0xffffffffff, - .result = 0, - .data = &data, - .args_size = sizeof(args), - .numd = 8 - 1, - .mos = 0x1, - .cntlid = 0x2, - .csuuidi = 0x3, - .sel = NVME_LM_SEL_GET_CONTROLLER_STATE, - .uidx = 0x4, - .csuidxp = 0x5, - }; + __u64 offset = 0xffffffffff; + __u16 csuuidi = 0x3; + __u32 numd = 8 - 1; + __u16 cntlid = 0x2; + __u8 csuidxp = 0x5; + __u32 result = 0; + __u16 mos = 0x1; + __u8 uidx = 0x4; + int err; struct mock_cmd mock_admin_cmd = { .opcode = nvme_admin_migration_receive, - .cdw10 = args.sel | (args.mos << 16), - .cdw11 = args.cntlid | (args.csuuidi << 16) | - (args.csuidxp << 24), - .cdw12 = (__u32)args.offset, - .cdw13 = (__u32)(args.offset >> 32), - .cdw14 = args.uidx, - .cdw15 = args.numd, - .data_len = (args.numd + 1) << 2, + .cdw10 = sel | (mos << 16), + .cdw11 = cntlid | (csuuidi << 16) | + (csuidxp << 24), + .cdw12 = (__u32)offset, + .cdw13 = (__u32)(offset >> 32), + .cdw14 = uidx, + .cdw15 = numd, + .data_len = (numd + 1) << 2, .out_data = &expected_data, }; - int err; - arbitrary(&expected_data, sizeof(expected_data)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_lm_migration_recv(test_link, &args); + err = nvme_lm_migration_recv(test_link, offset, mos, cntlid, csuuidi, sel, uidx, csuidxp, + &data, sizeof(data), NULL); end_mock_cmds(); check(err == 0, "returned error %d", err); check(result == 0, "returned result %u", result); From bdc195264ec173cd24e499ac8f11fde7be3ddec1 Mon Sep 17 00:00:00 2001 From: Tokunori Ikegami Date: Tue, 26 Aug 2025 01:26:24 +0900 Subject: [PATCH 48/66] ioctl: nvme_security_receive use nvme_passthru_cmd directly Drop struct nvme_security_receive_args. Signed-off-by: Tokunori Ikegami [wagi: reordered arguments] Signed-off-by: Daniel Wagner --- examples/mi-mctp.c | 22 +++++++++------------- src/libnvme.map | 2 -- src/nvme/api-types.h | 28 ---------------------------- src/nvme/ioctl.c | 24 ------------------------ src/nvme/ioctl.h | 35 +++++++++++++++++++++++++++++++++-- test/ioctl/misc.c | 31 +++++++++++-------------------- 6 files changed, 53 insertions(+), 89 deletions(-) diff --git a/examples/mi-mctp.c b/examples/mi-mctp.c index 80f55597d..c12f892b5 100644 --- a/examples/mi-mctp.c +++ b/examples/mi-mctp.c @@ -538,7 +538,6 @@ static const char *sec_proto_description(uint8_t id) int do_security_info(nvme_mi_ep_t ep, int argc, char **argv) { - struct nvme_security_receive_args args = { 0 }; nvme_link_t link; int i, rc, n_proto; unsigned long tmp; @@ -548,6 +547,9 @@ int do_security_info(nvme_mi_ep_t ep, int argc, char **argv) uint16_t len; uint8_t protocols[256]; } proto_info; + /* protocol 0x00, spsp 0x0000: retrieve supported protocols */ + void *data = &proto_info; + __u32 data_len = sizeof(proto_info); if (argc != 2) { fprintf(stderr, "no controller ID specified\n"); @@ -568,27 +570,21 @@ int do_security_info(nvme_mi_ep_t ep, int argc, char **argv) return -1; } - /* protocol 0x00, spsp 0x0000: retrieve supported protocols */ - args.args_size = sizeof(args); - args.data = &proto_info; - args.data_len = sizeof(proto_info); - - rc = nvme_security_receive(link, &args); + rc = nvme_security_receive(link, 0, 0, 0, 0, 0, 0, data, data_len, NULL); if (rc) { warnx("can't perform Security Receive command: rc %d", rc); return -1; } - if (args.data_len < 6) { - warnx("Short response in security receive command (%d bytes)", - args.data_len); + if (data_len < 6) { + warnx("Short response in security receive command (%d bytes)", data_len); return -1; } n_proto = be16_to_cpu(proto_info.len); - if (args.data_len < 6 + n_proto) { - warnx("Short response in security receive command (%d bytes), " - "for %d protocols", args.data_len, n_proto); + if (data_len < 6 + n_proto) { + warnx("Short response in security receive command (%d bytes), for %d protocols", + data_len, n_proto); return -1; } diff --git a/src/libnvme.map b/src/libnvme.map index bd969e0a1..2412d8144 100644 --- a/src/libnvme.map +++ b/src/libnvme.map @@ -282,8 +282,6 @@ LIBNVME_2_0 { nvme_scan_subsystems; nvme_scan_tls_keys; nvme_scan_topology; - nvme_security_receive; - nvme_security_send; nvme_set_debug; nvme_set_keyring; nvme_set_property; diff --git a/src/nvme/api-types.h b/src/nvme/api-types.h index 068394b67..5e9a73873 100644 --- a/src/nvme/api-types.h +++ b/src/nvme/api-types.h @@ -76,34 +76,6 @@ struct nvme_get_features_args { __u8 uuidx; }; -/** - * struct nvme_security_receive_args - Arguments for the NVMe Security Receive command - * @result: The command completion result from CQE dword0 - * @data: Security data payload to send - * @args_size: Size of &struct nvme_security_receive_args - * @timeout: Timeout in ms - * @nsid: Namespace ID to issue security command on - * @al: Protocol specific allocation length - * @data_len: Data length of the payload in bytes - * @nssf: NVMe Security Specific field - * @spsp0: Security Protocol Specific field - * @spsp1: Security Protocol Specific field - * @secp: Security Protocol - */ -struct nvme_security_receive_args { - __u32 *result; - void *data; - int args_size; - __u32 timeout; - __u32 nsid; - __u32 al; - __u32 data_len; - __u8 nssf; - __u8 spsp0; - __u8 spsp1; - __u8 secp; -}; - /** * struct nvme_get_lba_status_args - Arguments for the NVMe Get LBA Status command * @lbas: Data payload to return status descriptors diff --git a/src/nvme/ioctl.c b/src/nvme/ioctl.c index 2830f1b27..243ed292c 100644 --- a/src/nvme/ioctl.c +++ b/src/nvme/ioctl.c @@ -1017,30 +1017,6 @@ int nvme_get_features_iocs_profile(nvme_link_t l, enum nvme_get_features_sel sel return __nvme_get_features(l, NVME_FEAT_FID_IOCS_PROFILE, sel, result); } -int nvme_security_receive(nvme_link_t l, struct nvme_security_receive_args *args) -{ - __u32 cdw10 = NVME_SET(args->secp, SECURITY_SECP) | - NVME_SET(args->spsp0, SECURITY_SPSP0) | - NVME_SET(args->spsp1, SECURITY_SPSP1) | - NVME_SET(args->nssf, SECURITY_NSSF); - __u32 cdw11 = args->al; - - struct nvme_passthru_cmd cmd = { - .opcode = nvme_admin_security_recv, - .nsid = args->nsid, - .cdw10 = cdw10, - .cdw11 = cdw11, - .data_len = args->data_len, - .addr = (__u64)(uintptr_t)args->data, - .timeout_ms = args->timeout, - }; - - if (args->args_size < sizeof(*args)) - return -EINVAL; - - return nvme_submit_admin_passthru(l, &cmd, args->result); -} - int nvme_get_lba_status(nvme_link_t l, struct nvme_get_lba_status_args *args) { __u32 cdw10 = args->slba & 0xffffffff; diff --git a/src/nvme/ioctl.h b/src/nvme/ioctl.h index 155aaefa1..15a3e5a35 100644 --- a/src/nvme/ioctl.h +++ b/src/nvme/ioctl.h @@ -3707,12 +3707,43 @@ static inline int nvme_security_send(nvme_link_t l, __u32 nsid,__u8 nssf, /** * nvme_security_receive() - Security Receive command * @l: Link handle - * @args: &struct nvme_security_receive argument structure + * @nsid: Namespace ID to issue security command on + * @nssf: NVMe Security Specific field + * @spsp0: Security Protocol Specific field + * @spsp1: Security Protocol Specific field + * @secp: Security Protocol + * @al: Protocol specific allocation length + * @data: Security data payload to send + * @data_len: Data length of the payload in bytes + * @result: The command completion result from CQE dword0 * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_security_receive(nvme_link_t l, struct nvme_security_receive_args *args); +static inline int nvme_security_receive(nvme_link_t l, __u32 nsid, + __u8 nssf, __u8 spsp0, + __u8 spsp1, __u8 secp, + __u32 al, void *data, + __u32 data_len, __u32 *result) +{ + __u32 cdw10 = NVME_SET(secp, SECURITY_SECP) | + NVME_SET(spsp0, SECURITY_SPSP0) | + NVME_SET(spsp1, SECURITY_SPSP1) | + NVME_SET(nssf, SECURITY_NSSF); + __u32 cdw11 = al; + + struct nvme_passthru_cmd cmd = { + .opcode = nvme_admin_security_recv, + .nsid = nsid, + .addr = (__u64)(uintptr_t)data, + .data_len = data_len, + .cdw10 = cdw10, + .cdw11 = cdw11, + }; + + return nvme_submit_admin_passthru(l, &cmd, result); +} + /** * nvme_get_lba_status() - Retrieve information on possibly unrecoverable LBAs diff --git a/test/ioctl/misc.c b/test/ioctl/misc.c index b8aaddeee..389cb89ad 100644 --- a/test/ioctl/misc.c +++ b/test/ioctl/misc.c @@ -327,35 +327,26 @@ static void test_security_receive(void) { __u8 expected_data[8], data[8]; __u32 result = 0; - - struct nvme_security_receive_args args = { - .result = &result, - .data = &data, - .args_size = sizeof(args), - .nsid = TEST_NSID, - .al = 0xffff, - .data_len = sizeof(data), - .nssf = 0x1, - .spsp0 = 0x1, - .spsp1 = 0x1, - .secp = 0xE9, - }; + __u32 al = 0xffff; + __u8 spsp0 = 0x1; + __u8 spsp1 = 0x1; + __u8 secp = 0xE9; + __u8 nssf = 0x1; + int err; struct mock_cmd mock_admin_cmd = { .opcode = nvme_admin_security_recv, .nsid = TEST_NSID, - .cdw10 = args.nssf | (args.spsp0 << 8) | (args.spsp1 << 16) | - (args.secp << 24), - .cdw11 = args.al, - .data_len = args.data_len, + .cdw10 = nssf | (spsp0 << 8) | (spsp1 << 16) | (secp << 24), + .cdw11 = al, + .data_len = sizeof(expected_data), .out_data = &expected_data, }; - int err; - arbitrary(&expected_data, sizeof(expected_data)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_security_receive(test_link, &args); + err = nvme_security_receive(test_link, TEST_NSID, nssf, spsp0, spsp1, + secp, al, &data, sizeof(data), &result); end_mock_cmds(); check(err == 0, "returned error %d", err); check(result == 0, "returned result %u", result); From 219c26b64a9c49e75633f7a3d6f011ea94c6e2d8 Mon Sep 17 00:00:00 2001 From: Tokunori Ikegami Date: Sun, 31 Aug 2025 15:41:23 +0900 Subject: [PATCH 49/66] ioctl: nvme_get_lba_status use nvme_passthru_cmd directly Drop struct nvme_get_lba_status_args. Signed-off-by: Tokunori Ikegami [wagi: reordering arguments] Signed-off-by: Daniel Wagner --- src/libnvme.map | 1 - src/nvme/api-types.h | 25 ------------------------- src/nvme/ioctl.c | 26 -------------------------- src/nvme/ioctl.h | 35 +++++++++++++++++++++++++++++++++-- test/ioctl/misc.c | 33 +++++++++++++-------------------- 5 files changed, 46 insertions(+), 74 deletions(-) diff --git a/src/libnvme.map b/src/libnvme.map index 2412d8144..de8c73fd1 100644 --- a/src/libnvme.map +++ b/src/libnvme.map @@ -122,7 +122,6 @@ LIBNVME_2_0 { nvme_get_features_write_atomic; nvme_get_features_write_protect; nvme_get_host_telemetry; - nvme_get_lba_status; nvme_get_log_partial; nvme_get_logging_level; nvme_get_logical_block_size; diff --git a/src/nvme/api-types.h b/src/nvme/api-types.h index 5e9a73873..060c14298 100644 --- a/src/nvme/api-types.h +++ b/src/nvme/api-types.h @@ -76,31 +76,6 @@ struct nvme_get_features_args { __u8 uuidx; }; -/** - * struct nvme_get_lba_status_args - Arguments for the NVMe Get LBA Status command - * @lbas: Data payload to return status descriptors - * @result: The command completion result from CQE dword0 - * @slba: Starting logical block address to check statuses - * @args_size: Size of &struct nvme_get_lba_status_args - * @timeout: Timeout in ms - * @nsid: Namespace ID to retrieve LBA status - * @mndw: Maximum number of dwords to return - * @atype: Action type mechanism to determine LBA status descriptors to - * return, see &enum nvme_lba_status_atype - * @rl: Range length from slba to perform the action - */ -struct nvme_get_lba_status_args { - __u64 slba; - __u32 *result; - struct nvme_lba_status *lbas; - int args_size; - __u32 timeout; - __u32 nsid; - __u32 mndw; - enum nvme_lba_status_atype atype; - __u16 rl; -}; - /** * struct nvme_directive_send_args - Arguments for the NVMe Directive Send command * @result: If successful, the CQE dword0 value diff --git a/src/nvme/ioctl.c b/src/nvme/ioctl.c index 243ed292c..3dbd5248d 100644 --- a/src/nvme/ioctl.c +++ b/src/nvme/ioctl.c @@ -1017,32 +1017,6 @@ int nvme_get_features_iocs_profile(nvme_link_t l, enum nvme_get_features_sel sel return __nvme_get_features(l, NVME_FEAT_FID_IOCS_PROFILE, sel, result); } -int nvme_get_lba_status(nvme_link_t l, struct nvme_get_lba_status_args *args) -{ - __u32 cdw10 = args->slba & 0xffffffff; - __u32 cdw11 = args->slba >> 32; - __u32 cdw12 = args->mndw; - __u32 cdw13 = NVME_SET(args->rl, GET_LBA_STATUS_CDW13_RL) | - NVME_SET(args->atype, GET_LBA_STATUS_CDW13_ATYPE); - - struct nvme_passthru_cmd cmd = { - .opcode = nvme_admin_get_lba_status, - .nsid = args->nsid, - .addr = (__u64)(uintptr_t)args->lbas, - .data_len = (args->mndw + 1) << 2, - .cdw10 = cdw10, - .cdw11 = cdw11, - .cdw12 = cdw12, - .cdw13 = cdw13, - .timeout_ms = args->timeout, - }; - - if (args->args_size < sizeof(*args)) - return -EINVAL; - - return nvme_submit_admin_passthru(l, &cmd, args->result); -} - int nvme_directive_send(nvme_link_t l, struct nvme_directive_send_args *args) { __u32 cdw10 = args->data_len ? (args->data_len >> 2) - 1 : 0; diff --git a/src/nvme/ioctl.h b/src/nvme/ioctl.h index 15a3e5a35..aa00e4003 100644 --- a/src/nvme/ioctl.h +++ b/src/nvme/ioctl.h @@ -3748,7 +3748,14 @@ static inline int nvme_security_receive(nvme_link_t l, __u32 nsid, /** * nvme_get_lba_status() - Retrieve information on possibly unrecoverable LBAs * @l: Link handle - * @args: &struct nvme_get_lba_status_args argument structure + * @nsid: Namespace ID to retrieve LBA status + * @slba: Starting logical block address to check statuses + * @mndw: Maximum number of dwords to return + * @atype: Action type mechanism to determine LBA status descriptors to + * return, see &enum nvme_lba_status_atype + * @rl: Range length from slba to perform the action + * @lbas: Data payload to return status descriptors + * @result: The command completion result from CQE dword0 * * The Get LBA Status command requests information about Potentially * Unrecoverable LBAs. Refer to the specification for action type descriptions. @@ -3756,7 +3763,31 @@ static inline int nvme_security_receive(nvme_link_t l, __u32 nsid, * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_get_lba_status(nvme_link_t l, struct nvme_get_lba_status_args *args); +static inline int nvme_get_lba_status(nvme_link_t l, __u32 nsid, __u64 slba, + __u32 mndw, + enum nvme_lba_status_atype atype, __u16 rl, + struct nvme_lba_status *lbas, + __u32 *result) +{ + __u32 cdw10 = slba & 0xffffffff; + __u32 cdw11 = slba >> 32; + __u32 cdw12 = mndw; + __u32 cdw13 = NVME_SET(rl, GET_LBA_STATUS_CDW13_RL) | + NVME_SET(atype, GET_LBA_STATUS_CDW13_ATYPE); + + struct nvme_passthru_cmd cmd = { + .opcode = nvme_admin_get_lba_status, + .nsid = nsid, + .addr = (__u64)(uintptr_t)lbas, + .data_len = (mndw + 1) << 2, + .cdw10 = cdw10, + .cdw11 = cdw11, + .cdw12 = cdw12, + .cdw13 = cdw13, + }; + + return nvme_submit_admin_passthru(l, &cmd, result); +} /** * nvme_directive_send() - Send directive command diff --git a/test/ioctl/misc.c b/test/ioctl/misc.c index 389cb89ad..22330f068 100644 --- a/test/ioctl/misc.c +++ b/test/ioctl/misc.c @@ -355,10 +355,15 @@ static void test_security_receive(void) static void test_get_lba_status(void) { - __u32 result = 0; __u8 nlsd = 3; int lba_status_size = sizeof(struct nvme_lba_status) + nlsd * sizeof(struct nvme_lba_status_desc); + enum nvme_lba_status_atype atype = 0x11; + __u32 mndw = (lba_status_size - 1) >> 2; + __u64 slba = 0x123456789; + __u32 result = 0; + __u16 rl = 0x42; + int err; _cleanup_free_ struct nvme_lba_status *lbas = NULL; _cleanup_free_ struct nvme_lba_status *expected_lbas = NULL; @@ -368,33 +373,21 @@ static void test_get_lba_status(void) expected_lbas = malloc(lba_status_size); check(expected_lbas, "expected_lbas: ENOMEM"); - struct nvme_get_lba_status_args args = { - .slba = 0x123456789, - .result = &result, - .lbas = lbas, - .args_size = sizeof(args), - .nsid = TEST_NSID, - .mndw = ((lba_status_size - 1) >> 2), - .atype = 0x11, - .rl = 0x42, - }; - struct mock_cmd mock_admin_cmd = { .opcode = nvme_admin_get_lba_status, .nsid = TEST_NSID, - .cdw10 = args.slba & 0xffffffff, - .cdw11 = args.slba >> 32, - .cdw12 = args.mndw, - .cdw13 = args.rl | (args.atype << 24), - .data_len = (args.mndw + 1) << 2, + .cdw10 = slba & 0xffffffff, + .cdw11 = slba >> 32, + .cdw12 = mndw, + .cdw13 = rl | (atype << 24), + .data_len = (mndw + 1) << 2, .out_data = expected_lbas, }; - int err; - arbitrary(expected_lbas, lba_status_size); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_get_lba_status(test_link, &args); + err = nvme_get_lba_status(test_link, TEST_NSID, slba, mndw, atype, + rl, lbas, &result); end_mock_cmds(); check(err == 0, "returned error %d", err); check(result == 0, "returned wrong result"); From 3e8e5daa687536e021d7fb5375c7c6f785a0a61a Mon Sep 17 00:00:00 2001 From: Tokunori Ikegami Date: Sun, 31 Aug 2025 16:12:17 +0900 Subject: [PATCH 50/66] ioctl: nvme_directive_send use nvme_passthru_cmd directly Drop struct nvme_directive_send_args. Signed-off-by: Tokunori Ikegami [wagi: updated nvme_directive_send_id_endir reordered arguments] Signed-off-by: Daniel Wagner --- src/libnvme.map | 2 - src/nvme/api-types.h | 26 ------------- src/nvme/ioctl.c | 46 ---------------------- src/nvme/ioctl.h | 90 +++++++++++++++++++++++++++----------------- test/ioctl/misc.c | 32 +++++++--------- 5 files changed, 68 insertions(+), 128 deletions(-) diff --git a/src/libnvme.map b/src/libnvme.map index de8c73fd1..d10068814 100644 --- a/src/libnvme.map +++ b/src/libnvme.map @@ -62,8 +62,6 @@ LIBNVME_2_0 { nvme_describe_key_serial; nvme_dev_self_test; nvme_directive_recv; - nvme_directive_send; - nvme_directive_send_id_endir; nvme_disconnect_ctrl; nvme_dump_config; nvme_dump_tree; diff --git a/src/nvme/api-types.h b/src/nvme/api-types.h index 060c14298..ce08d9c61 100644 --- a/src/nvme/api-types.h +++ b/src/nvme/api-types.h @@ -76,32 +76,6 @@ struct nvme_get_features_args { __u8 uuidx; }; -/** - * struct nvme_directive_send_args - Arguments for the NVMe Directive Send command - * @result: If successful, the CQE dword0 value - * @data: Data payload to be send - * @args_size: Size of &struct nvme_directive_send_args - * @timeout: Timeout in ms - * @nsid: Namespace ID, if applicable - * @doper: Directive send operation, see &enum nvme_directive_send_doper - * @dtype: Directive type, see &enum nvme_directive_dtype - * @cdw12: Directive specific command dword12 - * @data_len: Length of data payload in bytes - * @dspec: Directive specific field - */ -struct nvme_directive_send_args { - __u32 *result; - void *data; - int args_size; - __u32 timeout; - __u32 nsid; - enum nvme_directive_send_doper doper; - enum nvme_directive_dtype dtype; - __u32 cdw12; - __u32 data_len; - __u16 dspec; -}; - /** * struct nvme_directive_recv_args - Arguments for the NVMe Directive Receive command * @result: If successful, the CQE dword0 value diff --git a/src/nvme/ioctl.c b/src/nvme/ioctl.c index 3dbd5248d..a6fb71c2f 100644 --- a/src/nvme/ioctl.c +++ b/src/nvme/ioctl.c @@ -1017,52 +1017,6 @@ int nvme_get_features_iocs_profile(nvme_link_t l, enum nvme_get_features_sel sel return __nvme_get_features(l, NVME_FEAT_FID_IOCS_PROFILE, sel, result); } -int nvme_directive_send(nvme_link_t l, struct nvme_directive_send_args *args) -{ - __u32 cdw10 = args->data_len ? (args->data_len >> 2) - 1 : 0; - __u32 cdw11 = NVME_SET(args->doper, DIRECTIVE_CDW11_DOPER) | - NVME_SET(args->dtype, DIRECTIVE_CDW11_DTYPE) | - NVME_SET(args->dspec, DIRECTIVE_CDW11_DPSEC); - - struct nvme_passthru_cmd cmd = { - .opcode = nvme_admin_directive_send, - .nsid = args->nsid, - .cdw10 = cdw10, - .cdw11 = cdw11, - .cdw12 = args->cdw12, - .data_len = args->data_len, - .addr = (__u64)(uintptr_t)args->data, - .timeout_ms = args->timeout, - }; - - if (args->args_size < sizeof(*args)) - return -EINVAL; - - return nvme_submit_admin_passthru(l, &cmd, args->result); -} - -int nvme_directive_send_id_endir(nvme_link_t l, __u32 nsid, bool endir, - enum nvme_directive_dtype dtype, - struct nvme_id_directives *id) -{ - __u32 cdw12 = NVME_SET(dtype, DIRECTIVE_SEND_IDENTIFY_CDW12_DTYPE) | - NVME_SET(endir, DIRECTIVE_SEND_IDENTIFY_CDW12_ENDIR); - struct nvme_directive_send_args args = { - .args_size = sizeof(args), - .nsid = nsid, - .dspec = 0, - .dtype = NVME_DIRECTIVE_DTYPE_IDENTIFY, - .doper = NVME_DIRECTIVE_SEND_IDENTIFY_DOPER_ENDIR, - .cdw12 = cdw12, - .data_len = sizeof(*id), - .data = id, - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .result = NULL, - }; - - return nvme_directive_send(l, &args); -} - int nvme_directive_recv(nvme_link_t l, struct nvme_directive_recv_args *args) { __u32 cdw10 = args->data_len ? (args->data_len >> 2) - 1 : 0; diff --git a/src/nvme/ioctl.h b/src/nvme/ioctl.h index aa00e4003..230f918d7 100644 --- a/src/nvme/ioctl.h +++ b/src/nvme/ioctl.h @@ -3792,7 +3792,14 @@ static inline int nvme_get_lba_status(nvme_link_t l, __u32 nsid, __u64 slba, /** * nvme_directive_send() - Send directive command * @l: Link handle - * @args: &struct nvme_directive_send_args argument structure + * @nsid: Namespace ID, if applicable + * @doper: Directive send operation, see &enum nvme_directive_send_doper + * @dtype: Directive type, see &enum nvme_directive_dtype + * @dspec: Directive specific field + * @cdw12: Directive specific command dword12 + * @data: Data payload to be send + * @data_len: Length of data payload in bytes + * @result: If successful, the CQE dword0 value * * Directives is a mechanism to enable host and NVM subsystem or controller * information exchange. The Directive Send command transfers data related to a @@ -3803,7 +3810,29 @@ static inline int nvme_get_lba_status(nvme_link_t l, __u32 nsid, __u64 slba, * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_directive_send(nvme_link_t l, struct nvme_directive_send_args *args); +static inline int nvme_directive_send(nvme_link_t l, __u32 nsid, + enum nvme_directive_send_doper doper, + enum nvme_directive_dtype dtype, + __u16 dspec, __u32 cdw12, + void *data, __u32 data_len, __u32 *result) +{ + __u32 cdw10 = data_len ? (data_len >> 2) - 1 : 0; + __u32 cdw11 = NVME_SET(doper, DIRECTIVE_CDW11_DOPER) | + NVME_SET(dtype, DIRECTIVE_CDW11_DTYPE) | + NVME_SET(dspec, DIRECTIVE_CDW11_DPSEC); + + struct nvme_passthru_cmd cmd = { + .opcode = nvme_admin_directive_send, + .nsid = nsid, + .addr = (__u64)(uintptr_t)data, + .data_len = data_len, + .cdw10 = cdw10, + .cdw11 = cdw11, + .cdw12 = cdw12, + }; + + return nvme_submit_admin_passthru(l, &cmd, result); +} /** * nvme_directive_send_id_endir() - Directive Send Enable Directive @@ -3816,9 +3845,18 @@ int nvme_directive_send(nvme_link_t l, struct nvme_directive_send_args *args); * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_directive_send_id_endir(nvme_link_t l, __u32 nsid, bool endir, - enum nvme_directive_dtype dtype, - struct nvme_id_directives *id); +static inline int nvme_directive_send_id_endir(nvme_link_t l, __u32 nsid, bool endir, + enum nvme_directive_dtype dtype, + struct nvme_id_directives *id) +{ + __u32 cdw12 = NVME_SET(dtype, DIRECTIVE_SEND_IDENTIFY_CDW12_DTYPE) | + NVME_SET(endir, DIRECTIVE_SEND_IDENTIFY_CDW12_ENDIR); + + return nvme_directive_send(l, nsid, + NVME_DIRECTIVE_SEND_IDENTIFY_DOPER_ENDIR, + NVME_DIRECTIVE_DTYPE_IDENTIFY, 0, cdw12, + id, sizeof(*id), NULL); +} /** * nvme_directive_send_stream_release_identifier() - Directive Send Stream release @@ -3830,22 +3868,13 @@ int nvme_directive_send_id_endir(nvme_link_t l, __u32 nsid, bool endir, * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline int nvme_directive_send_stream_release_identifier(nvme_link_t l, - __u32 nsid, __u16 stream_id) + __u32 nsid, + __u16 stream_id) { - struct nvme_directive_send_args args = { - .result = NULL, - .data = NULL, - .args_size = sizeof(args), - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .nsid = nsid, - .doper = NVME_DIRECTIVE_SEND_STREAMS_DOPER_RELEASE_IDENTIFIER, - .dtype = NVME_DIRECTIVE_DTYPE_STREAMS, - .cdw12 = 0, - .data_len = 0, - .dspec = stream_id, - }; - - return nvme_directive_send(l, &args); + return nvme_directive_send(l, nsid, + NVME_DIRECTIVE_SEND_STREAMS_DOPER_RELEASE_IDENTIFIER, + NVME_DIRECTIVE_DTYPE_STREAMS, stream_id, + 0, NULL, 0, NULL); } /** @@ -3856,22 +3885,13 @@ static inline int nvme_directive_send_stream_release_identifier(nvme_link_t l, * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -static inline int nvme_directive_send_stream_release_resource(nvme_link_t l, __u32 nsid) +static inline int nvme_directive_send_stream_release_resource(nvme_link_t l, + __u32 nsid) { - struct nvme_directive_send_args args = { - .result = NULL, - .data = NULL, - .args_size = sizeof(args), - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .nsid = nsid, - .doper = NVME_DIRECTIVE_SEND_STREAMS_DOPER_RELEASE_RESOURCE, - .dtype = NVME_DIRECTIVE_DTYPE_STREAMS, - .cdw12 = 0, - .data_len = 0, - .dspec = 0, - }; - - return nvme_directive_send(l, &args); + return nvme_directive_send(l, nsid, + NVME_DIRECTIVE_SEND_STREAMS_DOPER_RELEASE_RESOURCE, + NVME_DIRECTIVE_DTYPE_STREAMS, + 0, 0, NULL, 0, NULL); } /** diff --git a/test/ioctl/misc.c b/test/ioctl/misc.c index 22330f068..a0f2c6622 100644 --- a/test/ioctl/misc.c +++ b/test/ioctl/misc.c @@ -396,37 +396,31 @@ static void test_get_lba_status(void) static void test_directive_send(void) { + enum nvme_directive_send_doper doper = NVME_DIRECTIVE_SEND_STREAMS_DOPER_RELEASE_RESOURCE; + enum nvme_directive_dtype dtype = NVME_DIRECTIVE_DTYPE_STREAMS; __u8 expected_data[8], data[8]; + __u32 cdw12 = 0xffff; + __u16 dspec = 0x0; __u32 result = 0; - - struct nvme_directive_send_args args = { - .result = &result, - .data = &expected_data, - .args_size = sizeof(args), - .nsid = TEST_NSID, - .doper = NVME_DIRECTIVE_SEND_STREAMS_DOPER_RELEASE_RESOURCE, - .dtype = NVME_DIRECTIVE_DTYPE_STREAMS, - .cdw12 = 0xffff, - .data_len = sizeof(expected_data), - .dspec = 0x0, - }; + __u32 data_len = sizeof(expected_data); + int err; struct mock_cmd mock_admin_cmd = { .opcode = nvme_admin_directive_send, .nsid = TEST_NSID, - .cdw10 = args.data_len ? (args.data_len >> 2) - 1 : 0, - .cdw11 = args.doper | (args.dtype << 8) | (args.dspec << 16), - .cdw12 = args.cdw12, - .data_len = args.data_len, + .cdw10 = data_len ? (data_len >> 2) - 1 : 0, + .cdw11 = doper | (dtype << 8) | (dspec << 16), + .cdw12 = cdw12, + .data_len = data_len, .in_data = &data, }; - int err; - arbitrary(&expected_data, sizeof(expected_data)); memcpy(&data, &expected_data, sizeof(expected_data)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_directive_send(test_link, &args); + err = nvme_directive_send(test_link, TEST_NSID, doper, dtype, dspec, + cdw12, &expected_data, + data_len, &result); end_mock_cmds(); check(err == 0, "returned error %d", err); check(result == 0, "returned wrong result"); From e16123b8c5c79cb2b0a148059c3eeb06c02c0655 Mon Sep 17 00:00:00 2001 From: Tokunori Ikegami Date: Sun, 31 Aug 2025 20:45:36 +0900 Subject: [PATCH 51/66] ioctl: nvme_directive_recv use nvme_passthru_cmd directly Drop struct nvme_directive_recv_args. Signed-off-by: Tokunori Ikegami [wagi: removed libnvme.map entry reordered arguments] Signed-off-by: Daniel Wagner --- src/libnvme.map | 1 - src/nvme/api-types.h | 26 --------- src/nvme/ioctl.c | 24 --------- src/nvme/ioctl.h | 123 ++++++++++++++++++++----------------------- test/ioctl/misc.c | 30 +++++------ 5 files changed, 70 insertions(+), 134 deletions(-) diff --git a/src/libnvme.map b/src/libnvme.map index d10068814..89686a1a2 100644 --- a/src/libnvme.map +++ b/src/libnvme.map @@ -61,7 +61,6 @@ LIBNVME_2_0 { nvme_default_host; nvme_describe_key_serial; nvme_dev_self_test; - nvme_directive_recv; nvme_disconnect_ctrl; nvme_dump_config; nvme_dump_tree; diff --git a/src/nvme/api-types.h b/src/nvme/api-types.h index ce08d9c61..af033ff58 100644 --- a/src/nvme/api-types.h +++ b/src/nvme/api-types.h @@ -76,32 +76,6 @@ struct nvme_get_features_args { __u8 uuidx; }; -/** - * struct nvme_directive_recv_args - Arguments for the NVMe Directive Receive command - * @result: If successful, the CQE dword0 value - * @data: Userspace address of data payload - * @args_size: Size of &struct nvme_directive_recv_args - * @timeout: Timeout in ms - * @nsid: Namespace ID, if applicable - * @doper: Directive send operation, see &enum nvme_directive_send_doper - * @dtype: Directive type, see &enum nvme_directive_dtype - * @cdw12: Directive specific command dword12 - * @data_len: Length of data payload in bytes - * @dspec: Directive specific field - */ -struct nvme_directive_recv_args { - __u32 *result; - void *data; - int args_size; - __u32 timeout; - __u32 nsid; - enum nvme_directive_receive_doper doper; - enum nvme_directive_dtype dtype; - __u32 cdw12; - __u32 data_len; - __u16 dspec; -}; - /** * struct nvme_capacity_mgmt_args - Arguments for the NVMe Capacity Management command * @result: If successful, the CQE dword0 value diff --git a/src/nvme/ioctl.c b/src/nvme/ioctl.c index a6fb71c2f..ddb5bf28a 100644 --- a/src/nvme/ioctl.c +++ b/src/nvme/ioctl.c @@ -1017,30 +1017,6 @@ int nvme_get_features_iocs_profile(nvme_link_t l, enum nvme_get_features_sel sel return __nvme_get_features(l, NVME_FEAT_FID_IOCS_PROFILE, sel, result); } -int nvme_directive_recv(nvme_link_t l, struct nvme_directive_recv_args *args) -{ - __u32 cdw10 = args->data_len ? (args->data_len >> 2) - 1 : 0; - __u32 cdw11 = NVME_SET(args->doper, DIRECTIVE_CDW11_DOPER) | - NVME_SET(args->dtype, DIRECTIVE_CDW11_DTYPE) | - NVME_SET(args->dspec, DIRECTIVE_CDW11_DPSEC); - - struct nvme_passthru_cmd cmd = { - .opcode = nvme_admin_directive_recv, - .nsid = args->nsid, - .cdw10 = cdw10, - .cdw11 = cdw11, - .cdw12 = args->cdw12, - .data_len = args->data_len, - .addr = (__u64)(uintptr_t)args->data, - .timeout_ms = args->timeout, - }; - - if (args->args_size < sizeof(*args)) - return -EINVAL; - - return nvme_submit_admin_passthru(l, &cmd, args->result); -} - int nvme_capacity_mgmt(nvme_link_t l, struct nvme_capacity_mgmt_args *args) { __u32 cdw10 = args->op | args->element_id << 16; diff --git a/src/nvme/ioctl.h b/src/nvme/ioctl.h index 230f918d7..3fc9e5c7e 100644 --- a/src/nvme/ioctl.h +++ b/src/nvme/ioctl.h @@ -3897,12 +3897,41 @@ static inline int nvme_directive_send_stream_release_resource(nvme_link_t l, /** * nvme_directive_recv() - Receive directive specific data * @l: Link handle - * @args: &struct nvme_directive_recv_args argument structure + * @nsid: Namespace ID, if applicable + * @doper: Directive send operation, see &enum nvme_directive_send_doper + * @dtype: Directive type, see &enum nvme_directive_dtype + * @dspec: Directive specific field + * @cdw12: Directive specific command dword12 + * @data: Userspace address of data payload + * @data_len: Length of data payload in bytes + * @result: If successful, the CQE dword0 value * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_directive_recv(nvme_link_t l, struct nvme_directive_recv_args *args); +static inline int nvme_directive_recv(nvme_link_t l, __u32 nsid, + enum nvme_directive_receive_doper doper, + enum nvme_directive_dtype dtype, + __u16 dspec, __u32 cdw12, + void *data, __u32 data_len, __u32 *result) +{ + __u32 cdw10 = data_len ? (data_len >> 2) - 1 : 0; + __u32 cdw11 = NVME_SET(doper, DIRECTIVE_CDW11_DOPER) | + NVME_SET(dtype, DIRECTIVE_CDW11_DTYPE) | + NVME_SET(dspec, DIRECTIVE_CDW11_DPSEC); + + struct nvme_passthru_cmd cmd = { + .opcode = nvme_admin_directive_recv, + .nsid = nsid, + .addr = (__u64)(uintptr_t)data, + .data_len = data_len, + .cdw10 = cdw10, + .cdw11 = cdw11, + .cdw12 = cdw12, + }; + + return nvme_submit_admin_passthru(l, &cmd, result); +} /** * nvme_directive_recv_identify_parameters() - Directive receive identifier parameters @@ -3913,23 +3942,14 @@ int nvme_directive_recv(nvme_link_t l, struct nvme_directive_recv_args *args); * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -static inline int nvme_directive_recv_identify_parameters(nvme_link_t l, __u32 nsid, - struct nvme_id_directives *id) +static inline int nvme_directive_recv_identify_parameters(nvme_link_t l, + __u32 nsid, + struct nvme_id_directives *id) { - struct nvme_directive_recv_args args = { - .result = NULL, - .data = id, - .args_size = sizeof(args), - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .nsid = nsid, - .doper = NVME_DIRECTIVE_RECEIVE_IDENTIFY_DOPER_PARAM, - .dtype = NVME_DIRECTIVE_DTYPE_IDENTIFY, - .cdw12 = 0, - .data_len = sizeof(*id), - .dspec = 0, - }; - - return nvme_directive_recv(l, &args); + return nvme_directive_recv(l, nsid, + NVME_DIRECTIVE_RECEIVE_IDENTIFY_DOPER_PARAM, + NVME_DIRECTIVE_DTYPE_IDENTIFY, + 0, 0, id, sizeof(*id), NULL); } /** @@ -3941,23 +3961,14 @@ static inline int nvme_directive_recv_identify_parameters(nvme_link_t l, __u32 n * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -static inline int nvme_directive_recv_stream_parameters(nvme_link_t l, __u32 nsid, - struct nvme_streams_directive_params *parms) +static inline int nvme_directive_recv_stream_parameters(nvme_link_t l, + __u32 nsid, + struct nvme_streams_directive_params *parms) { - struct nvme_directive_recv_args args = { - .result = NULL, - .data = parms, - .args_size = sizeof(args), - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .nsid = nsid, - .doper = NVME_DIRECTIVE_RECEIVE_STREAMS_DOPER_PARAM, - .dtype = NVME_DIRECTIVE_DTYPE_STREAMS, - .cdw12 = 0, - .data_len = sizeof(*parms), - .dspec = 0, - }; - - return nvme_directive_recv(l, &args); + return nvme_directive_recv(l, nsid, + NVME_DIRECTIVE_RECEIVE_STREAMS_DOPER_PARAM, + NVME_DIRECTIVE_DTYPE_STREAMS, + 0, 0, parms, sizeof(*parms), NULL); } /** @@ -3971,28 +3982,19 @@ static inline int nvme_directive_recv_stream_parameters(nvme_link_t l, __u32 nsi * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline int nvme_directive_recv_stream_status(nvme_link_t l, __u32 nsid, - unsigned int nr_entries, - struct nvme_streams_directive_status *id) + unsigned int nr_entries, + struct nvme_streams_directive_status *id) { if (nr_entries > NVME_STREAM_ID_MAX) { errno = EINVAL; return -1; } - struct nvme_directive_recv_args args = { - .result = NULL, - .data = id, - .args_size = sizeof(args), - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .nsid = nsid, - .doper = NVME_DIRECTIVE_RECEIVE_STREAMS_DOPER_STATUS, - .dtype = NVME_DIRECTIVE_DTYPE_STREAMS, - .cdw12 = 0, - .data_len = (__u32)(sizeof(*id) + nr_entries * sizeof(__le16)), - .dspec = 0, - }; - - return nvme_directive_recv(l, &args); + return nvme_directive_recv(l, nsid, + NVME_DIRECTIVE_RECEIVE_STREAMS_DOPER_STATUS, + NVME_DIRECTIVE_DTYPE_STREAMS, 0, 0, id, + (__u32)(sizeof(*id) + nr_entries * sizeof(__le16)), + NULL); } /** @@ -4006,22 +4008,13 @@ static inline int nvme_directive_recv_stream_status(nvme_link_t l, __u32 nsid, * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline int nvme_directive_recv_stream_allocate(nvme_link_t l, __u32 nsid, - __u16 nsr, __u32 *result) + __u16 nsr, + __u32 *result) { - struct nvme_directive_recv_args args = { - .result = result, - .data = NULL, - .args_size = sizeof(args), - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .nsid = nsid, - .doper = NVME_DIRECTIVE_RECEIVE_STREAMS_DOPER_RESOURCE, - .dtype = NVME_DIRECTIVE_DTYPE_STREAMS, - .cdw12 = nsr, - .data_len = 0, - .dspec = 0, - }; - - return nvme_directive_recv(l, &args); + return nvme_directive_recv(l, nsid, + NVME_DIRECTIVE_RECEIVE_STREAMS_DOPER_RESOURCE, + NVME_DIRECTIVE_DTYPE_STREAMS, + 0, nsr, NULL, 0, result); } /** diff --git a/test/ioctl/misc.c b/test/ioctl/misc.c index a0f2c6622..d2e55eaca 100644 --- a/test/ioctl/misc.c +++ b/test/ioctl/misc.c @@ -493,36 +493,30 @@ static void test_directive_send_stream_release_resource(void) static void test_directive_recv(void) { + enum nvme_directive_receive_doper doper = NVME_DIRECTIVE_RECEIVE_STREAMS_DOPER_PARAM; + enum nvme_directive_dtype dtype = NVME_DIRECTIVE_DTYPE_STREAMS; __u8 expected_data[8], data[8]; + __u32 data_len = sizeof(data); + __u32 cdw12 = 0xffff; + __u16 dspec = 0x0; __u32 result = 0; - - struct nvme_directive_recv_args args = { - .result = &result, - .data = &data, - .args_size = sizeof(args), - .nsid = TEST_NSID, - .doper = NVME_DIRECTIVE_RECEIVE_STREAMS_DOPER_PARAM, - .dtype = NVME_DIRECTIVE_DTYPE_STREAMS, - .cdw12 = 0xffff, - .data_len = sizeof(data), - .dspec = 0x0, - }; + int err; struct mock_cmd mock_admin_cmd = { .opcode = nvme_admin_directive_recv, .nsid = TEST_NSID, - .cdw10 = args.data_len ? (args.data_len >> 2) - 1 : 0, - .cdw11 = args.doper | (args.dtype << 8) | (args.dspec << 16), - .cdw12 = args.cdw12, + .cdw10 = data_len ? (data_len >> 2) - 1 : 0, + .cdw11 = doper | (dtype << 8) | (dspec << 16), + .cdw12 = cdw12, .data_len = sizeof(expected_data), .out_data = &expected_data, }; - int err; - arbitrary(&expected_data, sizeof(expected_data)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_directive_recv(test_link, &args); + err = nvme_directive_recv(test_link, TEST_NSID, doper, dtype, + dspec, cdw12, &data, data_len, + &result); end_mock_cmds(); check(err == 0, "returned error %d", err); check(result == 0, "returned wrong result"); From 02a60de556f59602a5a35dcd7344bc7806f1e7c1 Mon Sep 17 00:00:00 2001 From: Tokunori Ikegami Date: Sun, 31 Aug 2025 21:01:29 +0900 Subject: [PATCH 52/66] ioctl: nvme_virtual_mgmt use nvme_passthru_cmd directly Drop struct nvme_virtual_mgmt_args. Signed-off-by: Tokunori Ikegami [wagi: remove libnvme.map entry] Signed-off-by: Daniel Wagner --- src/libnvme.map | 1 - src/nvme/api-types.h | 21 --------------------- src/nvme/ioctl.c | 20 -------------------- src/nvme/ioctl.h | 24 ++++++++++++++++++++++-- test/ioctl/misc.c | 22 ++++++++-------------- 5 files changed, 30 insertions(+), 58 deletions(-) diff --git a/src/libnvme.map b/src/libnvme.map index 89686a1a2..0786b999b 100644 --- a/src/libnvme.map +++ b/src/libnvme.map @@ -316,7 +316,6 @@ LIBNVME_2_0 { nvme_uuid_from_string; nvme_uuid_random; nvme_uuid_to_string; - nvme_virtual_mgmt; nvmf_add_ctrl; nvmf_adrfam_str; nvmf_cms_str; diff --git a/src/nvme/api-types.h b/src/nvme/api-types.h index af033ff58..0bbd58e9a 100644 --- a/src/nvme/api-types.h +++ b/src/nvme/api-types.h @@ -191,25 +191,4 @@ struct nvme_dev_self_test_args { __u32 nsid; enum nvme_dst_stc stc; }; - -/** - * struct nvme_virtual_mgmt_args - Arguments for the NVMe Virtualization - * resource management command - * @args_size: Size of &struct nvme_virtual_mgmt_args - * @result: If successful, the CQE dword0 - * @timeout: Timeout in ms - * @act: Virtual resource action, see &enum nvme_virt_mgmt_act - * @rt: Resource type to modify, see &enum nvme_virt_mgmt_rt - * @cntlid: Controller id for which resources are bing modified - * @nr: Number of resources being allocated or assigned - */ -struct nvme_virtual_mgmt_args { - __u32 *result; - int args_size; - __u32 timeout; - enum nvme_virt_mgmt_act act; - enum nvme_virt_mgmt_rt rt; - __u16 cntlid; - __u16 nr; -}; #endif /* _LIBNVME_API_TYPES_H */ diff --git a/src/nvme/ioctl.c b/src/nvme/ioctl.c index ddb5bf28a..aa7b3cd96 100644 --- a/src/nvme/ioctl.c +++ b/src/nvme/ioctl.c @@ -1140,26 +1140,6 @@ int nvme_dev_self_test(nvme_link_t l, struct nvme_dev_self_test_args *args) return nvme_submit_admin_passthru(l, &cmd, args->result); } -int nvme_virtual_mgmt(nvme_link_t l, struct nvme_virtual_mgmt_args *args) -{ - __u32 cdw10 = NVME_SET(args->act, VIRT_MGMT_CDW10_ACT) | - NVME_SET(args->rt, VIRT_MGMT_CDW10_RT) | - NVME_SET(args->cntlid, VIRT_MGMT_CDW10_CNTLID); - __u32 cdw11 = NVME_SET(args->nr, VIRT_MGMT_CDW11_NR); - - struct nvme_passthru_cmd cmd = { - .opcode = nvme_admin_virtual_mgmt, - .cdw10 = cdw10, - .cdw11 = cdw11, - .timeout_ms = args->timeout, - }; - - if (args->args_size < sizeof(*args)) - return -EINVAL; - - return nvme_submit_admin_passthru(l, &cmd, args->result); -} - int nvme_submit_io_passthru64(nvme_link_t l, struct nvme_passthru_cmd64 *cmd, __u64 *result) { diff --git a/src/nvme/ioctl.h b/src/nvme/ioctl.h index 3fc9e5c7e..cf9126aed 100644 --- a/src/nvme/ioctl.h +++ b/src/nvme/ioctl.h @@ -4107,7 +4107,11 @@ int nvme_dev_self_test(nvme_link_t l, struct nvme_dev_self_test_args *args); /** * nvme_virtual_mgmt() - Virtualization resource management * @l: Link handle - * @args: &struct nvme_virtual_mgmt_args argument structure + * @act: Virtual resource action, see &enum nvme_virt_mgmt_act + * @rt: Resource type to modify, see &enum nvme_virt_mgmt_rt + * @cntlid: Controller id for which resources are bing modified + * @nr: Number of resources being allocated or assigned + * @result: If successful, the CQE dword0 * * The Virtualization Management command is supported by primary controllers * that support the Virtualization Enhancements capability. This command is @@ -4120,7 +4124,23 @@ int nvme_dev_self_test(nvme_link_t l, struct nvme_dev_self_test_args *args); * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_virtual_mgmt(nvme_link_t l, struct nvme_virtual_mgmt_args *args); +static inline int nvme_virtual_mgmt(nvme_link_t l, enum nvme_virt_mgmt_act act, + enum nvme_virt_mgmt_rt rt, __u16 cntlid, + __u16 nr, __u32 *result) +{ + __u32 cdw10 = NVME_SET(act, VIRT_MGMT_CDW10_ACT) | + NVME_SET(rt, VIRT_MGMT_CDW10_RT) | + NVME_SET(cntlid, VIRT_MGMT_CDW10_CNTLID); + __u32 cdw11 = NVME_SET(nr, VIRT_MGMT_CDW11_NR); + + struct nvme_passthru_cmd cmd = { + .opcode = nvme_admin_virtual_mgmt, + .cdw10 = cdw10, + .cdw11 = cdw11, + }; + + return nvme_submit_admin_passthru(l, &cmd, result); +} /** * nvme_flush() - Send an nvme flush command diff --git a/test/ioctl/misc.c b/test/ioctl/misc.c index d2e55eaca..a533490c3 100644 --- a/test/ioctl/misc.c +++ b/test/ioctl/misc.c @@ -757,28 +757,22 @@ static void test_dev_self_test(void) static void test_virtual_mgmt(void) { + enum nvme_virt_mgmt_act act = NVME_VIRT_MGMT_ACT_ASSIGN_SEC_CTRL; + enum nvme_virt_mgmt_rt rt = NVME_VIRT_MGMT_RT_VI_RESOURCE; __u32 expected_result = 0x45, result = 0; - - struct nvme_virtual_mgmt_args args = { - .result = &result, - .args_size = sizeof(args), - .act = NVME_VIRT_MGMT_ACT_ASSIGN_SEC_CTRL, - .rt = NVME_VIRT_MGMT_RT_VI_RESOURCE, - .cntlid = 0x0, - .nr = 0xff, - }; + __u16 cntlid = 0x0; + __u16 nr = 0xff; + int err; struct mock_cmd mock_admin_cmd = { .opcode = nvme_admin_virtual_mgmt, - .cdw10 = args.act | (args.rt << 8) | (args.cntlid << 16), - .cdw11 = args.nr, + .cdw10 = act | (rt << 8) | (cntlid << 16), + .cdw11 = nr, .result = expected_result, }; - int err; - set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_virtual_mgmt(test_link, &args); + err = nvme_virtual_mgmt(test_link, act, rt, cntlid, nr, &result); end_mock_cmds(); check(err == 0, "returned error %d", err); check(result == expected_result, "wrong result"); From 5bdac348d33b8837ac26e6b995a35e68e5713e66 Mon Sep 17 00:00:00 2001 From: Tokunori Ikegami Date: Sun, 31 Aug 2025 21:09:46 +0900 Subject: [PATCH 53/66] ioctl: nvme_dev_self_test use nvme_passthru_cmd directly Drop struct nvme_dev_self_test_args. Signed-off-by: Tokunori Ikegami [wagi: removed libnvme.map entry] Signed-off-by: Daniel Wagner --- src/libnvme.map | 1 - src/nvme/api-types.h | 16 ---------------- src/nvme/ioctl.c | 17 ----------------- src/nvme/ioctl.h | 19 +++++++++++++++++-- test/ioctl/misc.c | 18 ++++++------------ 5 files changed, 23 insertions(+), 48 deletions(-) diff --git a/src/libnvme.map b/src/libnvme.map index 0786b999b..6ad38e9a4 100644 --- a/src/libnvme.map +++ b/src/libnvme.map @@ -60,7 +60,6 @@ LIBNVME_2_0 { nvme_ctrls_filter; nvme_default_host; nvme_describe_key_serial; - nvme_dev_self_test; nvme_disconnect_ctrl; nvme_dump_config; nvme_dump_tree; diff --git a/src/nvme/api-types.h b/src/nvme/api-types.h index 0bbd58e9a..b8ce60d99 100644 --- a/src/nvme/api-types.h +++ b/src/nvme/api-types.h @@ -175,20 +175,4 @@ struct nvme_sanitize_nvm_args { bool nodas; bool emvs; }; - -/** - * struct nvme_dev_self_test_args - Arguments for the NVMe Device Self Test command - * @result: The command completion result from CQE dword0 - * @args_size: Size of &struct nvme_dev_self_test_args - * @nsid: Namespace ID to test - * @stc: Self test code, see &enum nvme_dst_stc - * @timeout: Timeout in ms - */ -struct nvme_dev_self_test_args { - __u32 *result; - int args_size; - __u32 timeout; - __u32 nsid; - enum nvme_dst_stc stc; -}; #endif /* _LIBNVME_API_TYPES_H */ diff --git a/src/nvme/ioctl.c b/src/nvme/ioctl.c index aa7b3cd96..1cac85dbc 100644 --- a/src/nvme/ioctl.c +++ b/src/nvme/ioctl.c @@ -1123,23 +1123,6 @@ int nvme_sanitize_nvm(nvme_link_t l, struct nvme_sanitize_nvm_args *args) return nvme_submit_admin_passthru(l, &cmd, args->result); } -int nvme_dev_self_test(nvme_link_t l, struct nvme_dev_self_test_args *args) -{ - __u32 cdw10 = NVME_SET(args->stc, DEVICE_SELF_TEST_CDW10_STC); - - struct nvme_passthru_cmd cmd = { - .opcode = nvme_admin_dev_self_test, - .nsid = args->nsid, - .cdw10 = cdw10, - .timeout_ms = args->timeout, - }; - - if (args->args_size < sizeof(*args)) - return -EINVAL; - - return nvme_submit_admin_passthru(l, &cmd, args->result); -} - int nvme_submit_io_passthru64(nvme_link_t l, struct nvme_passthru_cmd64 *cmd, __u64 *result) { diff --git a/src/nvme/ioctl.h b/src/nvme/ioctl.h index cf9126aed..358be8d2c 100644 --- a/src/nvme/ioctl.h +++ b/src/nvme/ioctl.h @@ -4086,7 +4086,9 @@ int nvme_sanitize_nvm(nvme_link_t l, struct nvme_sanitize_nvm_args *args); /** * nvme_dev_self_test() - Start or abort a self test * @l: Link handle - * @args: &struct nvme_dev_self_test argument structure + * @nsid: Namespace ID to test + * @stc: Self test code, see &enum nvme_dst_stc + * @result: The command completion result from CQE dword0 * * The Device Self-test command starts a device self-test operation or abort a * device self-test operation. A device self-test operation is a diagnostic @@ -4102,7 +4104,20 @@ int nvme_sanitize_nvm(nvme_link_t l, struct nvme_sanitize_nvm_args *args); * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_dev_self_test(nvme_link_t l, struct nvme_dev_self_test_args *args); +static inline int nvme_dev_self_test(nvme_link_t l, __u32 nsid, + enum nvme_dst_stc stc, + __u32 *result) +{ + __u32 cdw10 = NVME_SET(stc, DEVICE_SELF_TEST_CDW10_STC); + + struct nvme_passthru_cmd cmd = { + .opcode = nvme_admin_dev_self_test, + .nsid = nsid, + .cdw10 = cdw10, + }; + + return nvme_submit_admin_passthru(l, &cmd, result); +} /** * nvme_virtual_mgmt() - Virtualization resource management diff --git a/test/ioctl/misc.c b/test/ioctl/misc.c index a533490c3..5246d8ce0 100644 --- a/test/ioctl/misc.c +++ b/test/ioctl/misc.c @@ -730,26 +730,20 @@ static void test_sanitize_nvm(void) static void test_dev_self_test(void) { + enum nvme_dst_stc stc = NVME_DST_STC_ABORT; __u32 expected_result = 0x45, result = 0; - - struct nvme_dev_self_test_args args = { - .result = &result, - .args_size = sizeof(args), - .nsid = TEST_NSID, - .stc = NVME_DST_STC_ABORT, - }; + __u32 nsid = TEST_NSID; + int err; struct mock_cmd mock_admin_cmd = { .opcode = nvme_admin_dev_self_test, - .nsid = args.nsid, - .cdw10 = args.stc, + .nsid = nsid, + .cdw10 = stc, .result = expected_result, }; - int err; - set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_dev_self_test(test_link, &args); + err = nvme_dev_self_test(test_link, nsid, stc, &result); end_mock_cmds(); check(err == 0, "returned error %d", err); check(result == expected_result, "wrong result"); From 2312b441c1c99dca8215c14902dc06563842c5c9 Mon Sep 17 00:00:00 2001 From: Tokunori Ikegami Date: Sun, 31 Aug 2025 21:38:26 +0900 Subject: [PATCH 54/66] ioctl: nvme_sanitize_nvm use nvme_passthru_cmd directly Drop struct nvme_sanitize_nvm_args. Signed-off-by: Tokunori Ikegami [wagi: remove libnvme.map entry reorder and rename arguments] Signed-off-by: Daniel Wagner --- src/libnvme.map | 1 - src/nvme/api-types.h | 26 --------------- src/nvme/ioctl.c | 30 ----------------- src/nvme/ioctl.h | 36 +++++++++++++++++--- test/ioctl/misc.c | 31 ++++++++---------- test/mi.c | 78 ++++++++++++++++++++++++-------------------- 6 files changed, 88 insertions(+), 114 deletions(-) diff --git a/src/libnvme.map b/src/libnvme.map index 6ad38e9a4..1e016f65e 100644 --- a/src/libnvme.map +++ b/src/libnvme.map @@ -266,7 +266,6 @@ LIBNVME_2_0 { nvme_root_release_fds; nvme_root_set_application; nvme_root_skip_namespaces; - nvme_sanitize_nvm; nvme_scan; nvme_scan_ctrl; nvme_scan_ctrl_namespace_paths; diff --git a/src/nvme/api-types.h b/src/nvme/api-types.h index b8ce60d99..3d997369d 100644 --- a/src/nvme/api-types.h +++ b/src/nvme/api-types.h @@ -149,30 +149,4 @@ struct nvme_get_property_args { __u32 timeout; int offset; }; - -/** - * struct nvme_sanitize_nvm_args - Arguments for the NVMe Sanitize NVM command - * @result: The command completion result from CQE dword0 - * @args_size: Size of &struct nvme_sanitize_nvm_args - * @timeout: Timeout in ms - * @ovrpat: Overwrite pattern - * @sanact: Sanitize action, see &enum nvme_sanitize_sanact - * @ause: Set to allow unrestricted sanitize exit - * @owpass: Overwrite pass count - * @oipbp: Set to overwrite invert pattern between passes - * @nodas: Set to not deallocate blocks after sanitizing - * @emvs: Set to enter media verification state - */ -struct nvme_sanitize_nvm_args { - __u32 *result; - int args_size; - __u32 timeout; - enum nvme_sanitize_sanact sanact; - __u32 ovrpat; - bool ause; - __u8 owpass; - bool oipbp; - bool nodas; - bool emvs; -}; #endif /* _LIBNVME_API_TYPES_H */ diff --git a/src/nvme/ioctl.c b/src/nvme/ioctl.c index 1cac85dbc..efa98d2ec 100644 --- a/src/nvme/ioctl.c +++ b/src/nvme/ioctl.c @@ -1093,36 +1093,6 @@ int nvme_get_property(nvme_link_t l, struct nvme_get_property_args *args) return nvme_submit_admin_passthru64(l, &cmd, args->value); } -int nvme_sanitize_nvm(nvme_link_t l, struct nvme_sanitize_nvm_args *args) -{ - const size_t size_v1 = sizeof_args(struct nvme_sanitize_nvm_args, nodas, __u64); - const size_t size_v2 = sizeof_args(struct nvme_sanitize_nvm_args, emvs, __u64); - __u32 cdw10, cdw11; - - if (args->args_size < size_v1 || args->args_size > size_v2) - return -EINVAL; - - cdw10 = NVME_SET(args->sanact, SANITIZE_CDW10_SANACT) | - NVME_SET(!!args->ause, SANITIZE_CDW10_AUSE) | - NVME_SET(args->owpass, SANITIZE_CDW10_OWPASS) | - NVME_SET(!!args->oipbp, SANITIZE_CDW10_OIPBP) | - NVME_SET(!!args->nodas, SANITIZE_CDW10_NODAS); - - if (args->args_size == size_v2) - cdw10 |= NVME_SET(!!args->emvs, SANITIZE_CDW10_EMVS); - - cdw11 = args->ovrpat; - - struct nvme_passthru_cmd cmd = { - .opcode = nvme_admin_sanitize_nvm, - .cdw10 = cdw10, - .cdw11 = cdw11, - .timeout_ms = args->timeout, - }; - - return nvme_submit_admin_passthru(l, &cmd, args->result); -} - int nvme_submit_io_passthru64(nvme_link_t l, struct nvme_passthru_cmd64 *cmd, __u64 *result) { diff --git a/src/nvme/ioctl.h b/src/nvme/ioctl.h index 358be8d2c..7a9bf989e 100644 --- a/src/nvme/ioctl.h +++ b/src/nvme/ioctl.h @@ -295,13 +295,13 @@ enum nvme_cmd_dword_fields { NVME_SANITIZE_CDW10_AUSE_SHIFT = 3, NVME_SANITIZE_CDW10_OWPASS_SHIFT = 4, NVME_SANITIZE_CDW10_OIPBP_SHIFT = 8, - NVME_SANITIZE_CDW10_NODAS_SHIFT = 9, + NVME_SANITIZE_CDW10_NDAS_SHIFT = 9, NVME_SANITIZE_CDW10_EMVS_SHIFT = 10, NVME_SANITIZE_CDW10_SANACT_MASK = 0x7, NVME_SANITIZE_CDW10_AUSE_MASK = 0x1, NVME_SANITIZE_CDW10_OWPASS_MASK = 0xf, NVME_SANITIZE_CDW10_OIPBP_MASK = 0x1, - NVME_SANITIZE_CDW10_NODAS_MASK = 0x1, + NVME_SANITIZE_CDW10_NDAS_MASK = 0x1, NVME_SANITIZE_CDW10_EMVS_MASK = 0x1, NVME_SECURITY_NSSF_SHIFT = 0, NVME_SECURITY_SPSP0_SHIFT = 8, @@ -4066,7 +4066,14 @@ int nvme_get_property(nvme_link_t l, struct nvme_get_property_args *args); /** * nvme_sanitize_nvm() - Start a sanitize operation * @l: Link handle - * @args: &struct nvme_sanitize_nvm_args argument structure + * @sanact: Sanitize action, see &enum nvme_sanitize_sanact + * @ause: Set to allow unrestricted sanitize exit + * @owpass: Overwrite pass count + * @oipbp: Set to overwrite invert pattern between passes + * @ndas: Set to not deallocate blocks after sanitizing + * @emvs: Set to enter media verification state + * @ovrpat: Overwrite pattern + * @result: The command completion result from CQE dword0 * * A sanitize operation alters all user data in the NVM subsystem such that * recovery of any previous user data from any cache, the non-volatile media, @@ -4081,7 +4088,28 @@ int nvme_get_property(nvme_link_t l, struct nvme_get_property_args *args); * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_sanitize_nvm(nvme_link_t l, struct nvme_sanitize_nvm_args *args); +static inline int nvme_sanitize_nvm(nvme_link_t l, + enum nvme_sanitize_sanact sanact, + bool ause, __u8 owpass, bool oipbp, + bool ndas, bool emvs, __u32 ovrpat, + __u32 *result) +{ + __u32 cdw10 = NVME_SET(sanact, SANITIZE_CDW10_SANACT) | + NVME_SET(ause, SANITIZE_CDW10_AUSE) | + NVME_SET(owpass, SANITIZE_CDW10_OWPASS) | + NVME_SET(oipbp, SANITIZE_CDW10_OIPBP) | + NVME_SET(ndas, SANITIZE_CDW10_NDAS) | + NVME_SET(emvs, SANITIZE_CDW10_EMVS); + __u32 cdw11 = ovrpat; + + struct nvme_passthru_cmd cmd = { + .opcode = nvme_admin_sanitize_nvm, + .cdw10 = cdw10, + .cdw11 = cdw11, + }; + + return nvme_submit_admin_passthru(l, &cmd, result); +} /** * nvme_dev_self_test() - Start or abort a self test diff --git a/test/ioctl/misc.c b/test/ioctl/misc.c index 5246d8ce0..bb0a8f3f7 100644 --- a/test/ioctl/misc.c +++ b/test/ioctl/misc.c @@ -697,32 +697,27 @@ static void test_lockdown(void) static void test_sanitize_nvm(void) { + enum nvme_sanitize_sanact sanact = NVME_SANITIZE_SANACT_START_CRYPTO_ERASE; __u32 expected_result = 0x45, result = 0; - - struct nvme_sanitize_nvm_args args = { - .result = &result, - .args_size = sizeof(args), - .sanact = NVME_SANITIZE_SANACT_START_CRYPTO_ERASE, - .ovrpat = 0x101010, - .ause = true, - .owpass = 0x2, - .oipbp = false, - .nodas = true, - .emvs = false, - }; + __u32 ovrpat = 0x101010; + bool oipbp = false; + __u8 owpass = 0x2; + bool nodas = true; + bool emvs = false; + bool ause = true; + int err; struct mock_cmd mock_admin_cmd = { .opcode = nvme_admin_sanitize_nvm, - .cdw10 = args.sanact | (!!args.ause << 3) | (args.owpass << 4) | - (!!args.oipbp << 8) | (!!args.nodas << 9), - .cdw11 = args.ovrpat, + .cdw10 = sanact | (ause << 3) | (owpass << 4) | (oipbp << 8) | (nodas << 9), + .cdw11 = ovrpat, .result = expected_result, }; - int err; - set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_sanitize_nvm(test_link, &args); + err = nvme_sanitize_nvm(test_link, sanact, ause, + owpass, oipbp, nodas, emvs, + ovrpat, &result); end_mock_cmds(); check(err == 0, "returned error %d", err); check(result == expected_result, "wrong result"); diff --git a/test/mi.c b/test/mi.c index bd1d86761..98dbe5f63 100644 --- a/test/mi.c +++ b/test/mi.c @@ -1757,31 +1757,36 @@ static void test_admin_format_nvm(struct nvme_mi_ep *ep) assert(!rc); } -static int test_admin_sanitize_nvm_cb(struct nvme_mi_ep *ep, - struct nvme_mi_req *req, - struct nvme_mi_resp *resp, - void *data) -{ - struct nvme_sanitize_nvm_args *args = data; - __u8 *rq_hdr; +struct sanitize_nvm_info { + enum nvme_sanitize_sanact sanact; + bool ause; + __u8 owpass; + bool oipbp; + bool ndas; + bool emvs; __u32 ovrpat; +}; - assert(req->data_len == 0); +static int test_admin_sanitize_nvm_cb(struct nvme_mi_ep *ep, struct nvme_mi_req *req, + struct nvme_mi_resp *resp, void *data) +{ + struct sanitize_nvm_info *info = data; + __u8 *rq_hdr = (__u8 *)req->hdr; + __u32 ovrpat; - rq_hdr = (__u8 *)req->hdr; + assert(!req->data_len); assert(rq_hdr[4] == nvme_admin_sanitize_nvm); - assert(((rq_hdr[44] >> 0) & 0x7) == args->sanact); - assert(((rq_hdr[44] >> 3) & 0x1) == args->ause); - assert(((rq_hdr[44] >> 4) & 0xf) == args->owpass); + assert(((rq_hdr[44] >> 0) & 0x7) == info->sanact); + assert(((rq_hdr[44] >> 3) & 0x1) == info->ause); + assert(((rq_hdr[44] >> 4) & 0xf) == info->owpass); - assert(((rq_hdr[45] >> 0) & 0x1) == args->oipbp); - assert(((rq_hdr[45] >> 1) & 0x1) == args->nodas); + assert(((rq_hdr[45] >> 0) & 0x1) == info->oipbp); + assert(((rq_hdr[45] >> 1) & 0x1) == info->ndas); - ovrpat = (__u32)rq_hdr[51] << 24 | rq_hdr[50] << 16 | - rq_hdr[49] << 8 | rq_hdr[48]; - assert(ovrpat == args->ovrpat); + ovrpat = (__u32)rq_hdr[51] << 24 | rq_hdr[50] << 16 | rq_hdr[49] << 8 | rq_hdr[48]; + assert(ovrpat == info->ovrpat); test_transport_resp_calc_mic(resp); @@ -1790,34 +1795,37 @@ static int test_admin_sanitize_nvm_cb(struct nvme_mi_ep *ep, static void test_admin_sanitize_nvm(struct nvme_mi_ep *ep) { - struct nvme_sanitize_nvm_args args = { 0 }; + struct sanitize_nvm_info info; nvme_link_t link; int rc; link = nvme_mi_init_link(ep, 5); assert(link); - test_set_transport_callback(ep, test_admin_sanitize_nvm_cb, &args); + test_set_transport_callback(ep, test_admin_sanitize_nvm_cb, &info); - args.args_size = sizeof(args); - args.sanact = 0x7; - args.ause = 0x0; - args.owpass = 0xf; - args.oipbp = 0x0; - args.nodas = 0x1; - args.ovrpat = ~0x04030201; - - rc = nvme_sanitize_nvm(link, &args); + info.sanact = 0x7; + info.ause = 0x0; + info.owpass = 0xf; + info.oipbp = 0x0; + info.ndas = 0x1; + info.ovrpat = ~0x04030201; + + rc = nvme_sanitize_nvm(link, info.sanact, info.ause, info.owpass, + info.oipbp, info.ndas, info.emvs, + info.ovrpat, NULL); assert(!rc); - args.sanact = 0x0; - args.ause = 0x1; - args.owpass = 0x0; - args.oipbp = 0x1; - args.nodas = 0x0; - args.ovrpat = 0x04030201; + info.sanact = 0x0; + info.ause = 0x1; + info.owpass = 0x0; + info.oipbp = 0x1; + info.ndas = 0x0; + info.ovrpat = 0x04030201; - rc = nvme_sanitize_nvm(link, &args); + rc = nvme_sanitize_nvm(link, info.sanact, info.ause, info.owpass, + info.oipbp, info.ndas, info.emvs, + info.ovrpat, NULL); assert(!rc); } From 7107c2d3d316fed5889fef4662eb8b928ab57e4e Mon Sep 17 00:00:00 2001 From: Tokunori Ikegami Date: Sun, 31 Aug 2025 21:53:55 +0900 Subject: [PATCH 55/66] ioctl: nvme_get_property use nvme_passthru_cmd directly Drop struct nvme_get_property_args. Signed-off-by: Tokunori Ikegami [wagi: remove libnvme.map entry] Signed-off-by: Daniel Wagner --- src/libnvme.map | 1 - src/nvme/api-types.h | 14 -------------- src/nvme/ioctl.c | 18 ------------------ src/nvme/ioctl.h | 17 +++++++++++++++-- test/ioctl/misc.c | 10 ++-------- 5 files changed, 17 insertions(+), 43 deletions(-) diff --git a/src/libnvme.map b/src/libnvme.map index 1e016f65e..d0a014a03 100644 --- a/src/libnvme.map +++ b/src/libnvme.map @@ -125,7 +125,6 @@ LIBNVME_2_0 { 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; diff --git a/src/nvme/api-types.h b/src/nvme/api-types.h index 3d997369d..7d54f3b4e 100644 --- a/src/nvme/api-types.h +++ b/src/nvme/api-types.h @@ -135,18 +135,4 @@ struct nvme_set_property_args { __u32 timeout; int offset; }; - -/** - * struct nvme_get_property_args - Arguments for NVMe Get Property command - * @value: Where the property's value will be stored on success - * @args_size: Size of &struct nvme_get_property_args - * @offset: Property offset from the base to retrieve - * @timeout: Timeout in ms - */ -struct nvme_get_property_args { - __u64 *value; - int args_size; - __u32 timeout; - int offset; -}; #endif /* _LIBNVME_API_TYPES_H */ diff --git a/src/nvme/ioctl.c b/src/nvme/ioctl.c index efa98d2ec..f4245b1f6 100644 --- a/src/nvme/ioctl.c +++ b/src/nvme/ioctl.c @@ -1075,24 +1075,6 @@ int nvme_set_property(nvme_link_t l, struct nvme_set_property_args *args) return nvme_submit_admin_passthru(l, &cmd, args->result); } -int nvme_get_property(nvme_link_t l, struct nvme_get_property_args *args) -{ - __u32 cdw10 = nvme_is_64bit_reg(args->offset); - - struct nvme_passthru_cmd64 cmd = { - .opcode = nvme_admin_fabrics, - .nsid = nvme_fabrics_type_property_get, - .cdw10 = cdw10, - .cdw11 = args->offset, - .timeout_ms = args->timeout, - }; - - if (args->args_size < sizeof(*args)) - return -EINVAL; - - return nvme_submit_admin_passthru64(l, &cmd, args->value); -} - int nvme_submit_io_passthru64(nvme_link_t l, struct nvme_passthru_cmd64 *cmd, __u64 *result) { diff --git a/src/nvme/ioctl.h b/src/nvme/ioctl.h index 7a9bf989e..ef0b75b65 100644 --- a/src/nvme/ioctl.h +++ b/src/nvme/ioctl.h @@ -4053,7 +4053,8 @@ int nvme_set_property(nvme_link_t l, struct nvme_set_property_args *args); /** * nvme_get_property() - Get a controller property * @l: Link handle - * @args: &struct nvme_get_propert_args argument structure + * @offset: Property offset from the base to retrieve + * @value: Where the property's value will be stored on success * * This is an NVMe-over-Fabrics specific command, not applicable to PCIe. These * properties align to the PCI MMIO controller registers. @@ -4061,7 +4062,19 @@ int nvme_set_property(nvme_link_t l, struct nvme_set_property_args *args); * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_get_property(nvme_link_t l, struct nvme_get_property_args *args); +static inline int nvme_get_property(nvme_link_t l, int offset, __u64 *value) +{ + __u32 cdw10 = nvme_is_64bit_reg(offset); + + struct nvme_passthru_cmd64 cmd = { + .opcode = nvme_admin_fabrics, + .nsid = nvme_fabrics_type_property_get, + .cdw10 = cdw10, + .cdw11 = (__u32)offset, + }; + + return nvme_submit_admin_passthru64(l, &cmd, value); +} /** * nvme_sanitize_nvm() - Start a sanitize operation diff --git a/test/ioctl/misc.c b/test/ioctl/misc.c index bb0a8f3f7..62ad5d9ba 100644 --- a/test/ioctl/misc.c +++ b/test/ioctl/misc.c @@ -120,11 +120,7 @@ static void test_ns_mgmt_delete(void) static void test_get_property(void) { __u64 expected_result, result; - struct nvme_get_property_args args = { - .value = &result, - .args_size = sizeof(args), - .offset = NVME_REG_ACQ, - }; + int err; arbitrary(&expected_result, sizeof(expected_result)); @@ -136,10 +132,8 @@ static void test_get_property(void) .result = expected_result, }; - int err; - set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_get_property(test_link, &args); + err = nvme_get_property(test_link, NVME_REG_ACQ, &result); end_mock_cmds(); check(err == 0, "returned error %d", err); check(result == expected_result, "returned wrong result"); From db6e7e4818382fc51677e144d3483dc108c42a82 Mon Sep 17 00:00:00 2001 From: Tokunori Ikegami Date: Sun, 31 Aug 2025 22:06:07 +0900 Subject: [PATCH 56/66] ioctl: nvme_set_property use nvme_passthru_cmd directly Drop struct nvme_set_property_args. Signed-off-by: Tokunori Ikegami [wagi: remove libnvme.map entry] Signed-off-by: Daniel Wagner --- src/libnvme.map | 1 - src/nvme/api-types.h | 16 ---------------- src/nvme/ioctl.c | 20 -------------------- src/nvme/ioctl.h | 20 ++++++++++++++++++-- test/ioctl/misc.c | 11 ++--------- 5 files changed, 20 insertions(+), 48 deletions(-) diff --git a/src/libnvme.map b/src/libnvme.map index d0a014a03..0a09721f1 100644 --- a/src/libnvme.map +++ b/src/libnvme.map @@ -277,7 +277,6 @@ LIBNVME_2_0 { nvme_scan_topology; nvme_set_debug; nvme_set_keyring; - nvme_set_property; nvme_set_root; nvme_status_to_errno; nvme_status_to_string; diff --git a/src/nvme/api-types.h b/src/nvme/api-types.h index 7d54f3b4e..99df7672f 100644 --- a/src/nvme/api-types.h +++ b/src/nvme/api-types.h @@ -119,20 +119,4 @@ struct nvme_lockdown_args { __u8 ofi; __u8 uuidx; }; - -/** - * struct nvme_set_property_args - Arguments for NVMe Set Property command - * @args_size: Size of &struct nvme_set_property_args - * @result: The command completion result from CQE dword0 - * @timeout: Timeout in ms - * @offset: Property offset from the base to set - * @value: The value to set the property - */ -struct nvme_set_property_args { - __u64 value; - __u32 *result; - int args_size; - __u32 timeout; - int offset; -}; #endif /* _LIBNVME_API_TYPES_H */ diff --git a/src/nvme/ioctl.c b/src/nvme/ioctl.c index f4245b1f6..f340c49c2 100644 --- a/src/nvme/ioctl.c +++ b/src/nvme/ioctl.c @@ -1055,26 +1055,6 @@ int nvme_lockdown(nvme_link_t l, struct nvme_lockdown_args *args) return nvme_submit_admin_passthru(l, &cmd, args->result); } -int nvme_set_property(nvme_link_t l, struct nvme_set_property_args *args) -{ - __u32 cdw10 = nvme_is_64bit_reg(args->offset); - - struct nvme_passthru_cmd cmd = { - .opcode = nvme_admin_fabrics, - .nsid = nvme_fabrics_type_property_set, - .cdw10 = cdw10, - .cdw11 = args->offset, - .cdw12 = args->value & 0xffffffff, - .cdw13 = args->value >> 32, - .timeout_ms = args->timeout, - }; - - if (args->args_size < sizeof(*args)) - return -EINVAL; - - return nvme_submit_admin_passthru(l, &cmd, args->result); -} - int nvme_submit_io_passthru64(nvme_link_t l, struct nvme_passthru_cmd64 *cmd, __u64 *result) { diff --git a/src/nvme/ioctl.h b/src/nvme/ioctl.h index ef0b75b65..a82d73fb7 100644 --- a/src/nvme/ioctl.h +++ b/src/nvme/ioctl.h @@ -4040,7 +4040,9 @@ int nvme_lockdown(nvme_link_t l, struct nvme_lockdown_args *args); /** * nvme_set_property() - Set controller property * @l: Link handle - * @args: &struct nvme_set_property_args argument structure + * @offset: Property offset from the base to set + * @value: The value to set the property + * @result: The command completion result from CQE dword0 * * This is an NVMe-over-Fabrics specific command, not applicable to PCIe. These * properties align to the PCI MMIO controller registers. @@ -4048,7 +4050,21 @@ int nvme_lockdown(nvme_link_t l, struct nvme_lockdown_args *args); * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_set_property(nvme_link_t l, struct nvme_set_property_args *args); +static inline int nvme_set_property(nvme_link_t l, int offset, __u64 value, __u32 *result) +{ + __u32 cdw10 = nvme_is_64bit_reg(offset); + + struct nvme_passthru_cmd cmd = { + .opcode = nvme_admin_fabrics, + .nsid = nvme_fabrics_type_property_set, + .cdw10 = cdw10, + .cdw11 = (__u32)offset, + .cdw12 = (__u32)(value & 0xffffffff), + .cdw13 = (__u32)(value >> 32), + }; + + return nvme_submit_admin_passthru(l, &cmd, result); +} /** * nvme_get_property() - Get a controller property diff --git a/test/ioctl/misc.c b/test/ioctl/misc.c index 62ad5d9ba..819a73e96 100644 --- a/test/ioctl/misc.c +++ b/test/ioctl/misc.c @@ -143,12 +143,7 @@ static void test_set_property(void) { __u64 value = 0xffffffff; __u32 result; - struct nvme_set_property_args args = { - .value = value, - .result = &result, - .args_size = sizeof(args), - .offset = NVME_REG_BPMBL, - }; + int err; struct mock_cmd mock_admin_cmd = { .opcode = nvme_admin_fabrics, @@ -159,10 +154,8 @@ static void test_set_property(void) .cdw13 = value >> 32, }; - int err; - set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_set_property(test_link, &args); + err = nvme_set_property(test_link, NVME_REG_BPMBL, value, &result); end_mock_cmds(); check(err == 0, "returned error %d", err); check(result == 0, "returned result %u", result); From 6afd7c93e9938e09c782522c1a18da0391ed37d8 Mon Sep 17 00:00:00 2001 From: Tokunori Ikegami Date: Sun, 31 Aug 2025 22:07:51 +0900 Subject: [PATCH 57/66] ioctl: nvme_lockdown use nvme_passthru_cmd directly Drop struct nvme_lockdown_args. Signed-off-by: Tokunori Ikegami [wagi: remove libnvme.map entry] Signed-off-by: Daniel Wagner --- src/libnvme.map | 1 - src/nvme/api-types.h | 21 --------------------- src/nvme/ioctl.c | 20 -------------------- src/nvme/ioctl.h | 22 ++++++++++++++++++++-- test/ioctl/misc.c | 25 +++++++++---------------- 5 files changed, 29 insertions(+), 60 deletions(-) diff --git a/src/libnvme.map b/src/libnvme.map index 0a09721f1..b3fdf043f 100644 --- a/src/libnvme.map +++ b/src/libnvme.map @@ -164,7 +164,6 @@ LIBNVME_2_0 { nvme_link_is_mi; nvme_lm_get_features_ctrl_data_queue; nvme_lm_set_features_ctrl_data_queue; - nvme_lockdown; nvme_lookup_ctrl; nvme_lookup_host; nvme_lookup_key; diff --git a/src/nvme/api-types.h b/src/nvme/api-types.h index 99df7672f..884c876c9 100644 --- a/src/nvme/api-types.h +++ b/src/nvme/api-types.h @@ -98,25 +98,4 @@ struct nvme_capacity_mgmt_args { __u8 op; }; -/** - * struct nvme_lockdown_args - Arguments for the NVME Lockdown command - * @args_size: Size of &struct nvme_lockdown_args - * @result: The command completion result from CQE dword0 - * @timeout: Timeout in ms (0 for default timeout) - * @scp: Scope of the command - * @prhbt: Prohibit or allow the command opcode or Set Features command - * @ifc: Affected interface - * @ofi: Opcode or Feature Identifier - * @uuidx: UUID Index if controller supports this id selection method - */ -struct nvme_lockdown_args { - __u32 *result; - int args_size; - __u32 timeout; - __u8 scp; - __u8 prhbt; - __u8 ifc; - __u8 ofi; - __u8 uuidx; -}; #endif /* _LIBNVME_API_TYPES_H */ diff --git a/src/nvme/ioctl.c b/src/nvme/ioctl.c index f340c49c2..6e74eb4b7 100644 --- a/src/nvme/ioctl.c +++ b/src/nvme/ioctl.c @@ -1035,26 +1035,6 @@ int nvme_capacity_mgmt(nvme_link_t l, struct nvme_capacity_mgmt_args *args) return nvme_submit_admin_passthru(l, &cmd, args->result); } -int nvme_lockdown(nvme_link_t l, struct nvme_lockdown_args *args) -{ - __u32 cdw10 = args->ofi << 8 | - (args->ifc & 0x3) << 5 | - (args->prhbt & 0x1) << 4 | - (args->scp & 0xF); - - struct nvme_passthru_cmd cmd = { - .opcode = nvme_admin_lockdown, - .cdw10 = cdw10, - .cdw14 = args->uuidx & 0x3F, - .timeout_ms = args->timeout, - }; - - if (args->args_size < sizeof(*args)) - return -EINVAL; - - return nvme_submit_admin_passthru(l, &cmd, args->result); -} - int nvme_submit_io_passthru64(nvme_link_t l, struct nvme_passthru_cmd64 *cmd, __u64 *result) { diff --git a/src/nvme/ioctl.h b/src/nvme/ioctl.h index a82d73fb7..93cfa2bba 100644 --- a/src/nvme/ioctl.h +++ b/src/nvme/ioctl.h @@ -4030,12 +4030,30 @@ int nvme_capacity_mgmt(nvme_link_t l, struct nvme_capacity_mgmt_args *args); /** * nvme_lockdown() - Issue lockdown command * @l: Link handle - * @args: &struct nvme_lockdown_args argument structure + * @scp: Scope of the command + * @prhbt: Prohibit or allow the command opcode or Set Features command + * @ifc: Affected interface + * @ofi: Opcode or Feature Identifier + * @uuidx: UUID Index if controller supports this id selection method + * @result: The command completion result from CQE dword0 * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_lockdown(nvme_link_t l, struct nvme_lockdown_args *args); +static inline int nvme_lockdown(nvme_link_t l, __u8 scp, __u8 prhbt, + __u8 ifc, __u8 ofi, __u8 uuidx, + __u32 *result) +{ + __u32 cdw10 = ofi << 8 | (ifc & 0x3) << 5 | (prhbt & 0x1) << 4 | (scp & 0xF); + + struct nvme_passthru_cmd cmd = { + .opcode = nvme_admin_lockdown, + .cdw10 = cdw10, + .cdw14 = (__u32)(uuidx & 0x3F), + }; + + return nvme_submit_admin_passthru(l, &cmd, result); +} /** * nvme_set_property() - Set controller property diff --git a/test/ioctl/misc.c b/test/ioctl/misc.c index 819a73e96..9fb145a4a 100644 --- a/test/ioctl/misc.c +++ b/test/ioctl/misc.c @@ -654,29 +654,22 @@ static void test_capacity_mgmt(void) static void test_lockdown(void) { __u32 expected_result = 0x45, result = 0; - - struct nvme_lockdown_args args = { - .result = &result, - .args_size = sizeof(args), - .scp = 0x2, - .prhbt = !!true, - .ifc = 0x1, - .ofi = 0x12, - .uuidx = 0x34, - }; + __u8 prhbt = !!true; + __u8 uuidx = 0x34; + __u8 ofi = 0x12; + __u8 scp = 0x2; + __u8 ifc = 0x1; + int err; struct mock_cmd mock_admin_cmd = { .opcode = nvme_admin_lockdown, - .cdw10 = args.ofi << 8 | (args.ifc & 0x3) << 5 | - (args.prhbt & 0x1) << 4 | (args.scp & 0xF), - .cdw14 = args.uuidx & 0x3F, + .cdw10 = ofi << 8 | (ifc & 0x3) << 5 | (prhbt & 0x1) << 4 | (scp & 0xF), + .cdw14 = (__u32)(uuidx & 0x3F), .result = expected_result, }; - int err; - set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_lockdown(test_link, &args); + err = nvme_lockdown(test_link, scp, prhbt, ifc, ofi, uuidx, &result); end_mock_cmds(); check(err == 0, "returned error %d", err); check(result == expected_result, "wrong result"); From 932ba271321eea442f334c511c18b28750900a7e Mon Sep 17 00:00:00 2001 From: Tokunori Ikegami Date: Fri, 5 Sep 2025 20:12:53 +0200 Subject: [PATCH 58/66] ioctl: nvme_capacity_mgmt use nvme_passthru_cmd directly Drop struct nvme_capacity_mgmt_args. Signed-off-by: Tokunori Ikegami [wagi: remove libnvme.map entry reordered/renamed arguments] Signed-off-by: Daniel Wagner --- src/libnvme.map | 1 - src/nvme/api-types.h | 22 ---------------------- src/nvme/ioctl.c | 18 ------------------ src/nvme/ioctl.h | 23 +++++++++++++++++++++-- test/ioctl/misc.c | 24 +++++++++--------------- 5 files changed, 30 insertions(+), 58 deletions(-) diff --git a/src/libnvme.map b/src/libnvme.map index b3fdf043f..c41c53252 100644 --- a/src/libnvme.map +++ b/src/libnvme.map @@ -6,7 +6,6 @@ LIBNVME_2_0 { global: nvme_admin_passthru64; nvme_admin_passthru; - nvme_capacity_mgmt; nvme_close; nvme_create_ctrl; nvme_create_root; diff --git a/src/nvme/api-types.h b/src/nvme/api-types.h index 884c876c9..1b8ee4694 100644 --- a/src/nvme/api-types.h +++ b/src/nvme/api-types.h @@ -76,26 +76,4 @@ struct nvme_get_features_args { __u8 uuidx; }; -/** - * struct nvme_capacity_mgmt_args - Arguments for the NVMe Capacity Management command - * @result: If successful, the CQE dword0 value - * @args_size: Size of &struct nvme_capacity_mgmt_args - * @cdw11: Least significant 32 bits of the capacity in bytes of the - * Endurance Group or NVM Set to be created - * @cdw12: Most significant 32 bits of the capacity in bytes of the - * Endurance Group or NVM Set to be created - * @timeout: Timeout in ms - * @element_id: Value specific to the value of the Operation field - * @op: Operation to be performed by the controller - */ -struct nvme_capacity_mgmt_args { - __u32 *result; - int args_size; - __u32 timeout; - __u32 cdw11; - __u32 cdw12; - __u16 element_id; - __u8 op; -}; - #endif /* _LIBNVME_API_TYPES_H */ diff --git a/src/nvme/ioctl.c b/src/nvme/ioctl.c index 6e74eb4b7..537ec316b 100644 --- a/src/nvme/ioctl.c +++ b/src/nvme/ioctl.c @@ -1017,24 +1017,6 @@ int nvme_get_features_iocs_profile(nvme_link_t l, enum nvme_get_features_sel sel return __nvme_get_features(l, NVME_FEAT_FID_IOCS_PROFILE, sel, result); } -int nvme_capacity_mgmt(nvme_link_t l, struct nvme_capacity_mgmt_args *args) -{ - __u32 cdw10 = args->op | args->element_id << 16; - - struct nvme_passthru_cmd cmd = { - .opcode = nvme_admin_capacity_mgmt, - .cdw10 = cdw10, - .cdw11 = args->cdw11, - .cdw12 = args->cdw12, - .timeout_ms = args->timeout, - }; - - if (args->args_size < sizeof(*args)) - return -EINVAL; - - return nvme_submit_admin_passthru(l, &cmd, args->result); -} - int nvme_submit_io_passthru64(nvme_link_t l, struct nvme_passthru_cmd64 *cmd, __u64 *result) { diff --git a/src/nvme/ioctl.h b/src/nvme/ioctl.h index 93cfa2bba..c2d6c46fa 100644 --- a/src/nvme/ioctl.h +++ b/src/nvme/ioctl.h @@ -4020,12 +4020,31 @@ static inline int nvme_directive_recv_stream_allocate(nvme_link_t l, __u32 nsid, /** * nvme_capacity_mgmt() - Capacity management command * @l: Link handle - * @args: &struct nvme_capacity_mgmt_args argument structure + * @op: Operation to be performed by the controller + * @elid: Value specific to the value of the Operation field + * @cdw11: Least significant 32 bits of the capacity in bytes of the + * Endurance Group or NVM Set to be created + * @cdw12: Most significant 32 bits of the capacity in bytes of the + * Endurance Group or NVM Set to be created + * @result: If successful, the CQE dword0 value * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_capacity_mgmt(nvme_link_t l, struct nvme_capacity_mgmt_args *args); +static inline int nvme_capacity_mgmt(nvme_link_t l, __u8 op, __u16 elid, + __u32 cdw11, __u32 cdw12, __u32 *result) +{ + __u32 cdw10 = op | elid << 16; + + struct nvme_passthru_cmd cmd = { + .opcode = nvme_admin_capacity_mgmt, + .cdw10 = cdw10, + .cdw11 = cdw11, + .cdw12 = cdw12, + }; + + return nvme_submit_admin_passthru(l, &cmd, result); +} /** * nvme_lockdown() - Issue lockdown command diff --git a/test/ioctl/misc.c b/test/ioctl/misc.c index 9fb145a4a..9b5d2c4e8 100644 --- a/test/ioctl/misc.c +++ b/test/ioctl/misc.c @@ -623,29 +623,23 @@ static void test_directive_recv_stream_allocate(void) static void test_capacity_mgmt(void) { __u32 expected_result = 0x45, result = 0; - - struct nvme_capacity_mgmt_args args = { - .result = &result, - .args_size = sizeof(args), - .cdw11 = 0x1234, - .cdw12 = 0x5678, - .element_id = 0x12, - .op = 0x3, - }; + __u16 elid = 0x12; + __u32 cdw11 = 0x1234; + __u32 cdw12 = 0x5678; + __u8 op = 0x3; + int err; struct mock_cmd mock_admin_cmd = { .opcode = nvme_admin_capacity_mgmt, .nsid = NVME_NSID_NONE, - .cdw10 = args.op | args.element_id << 16, - .cdw11 = args.cdw11, - .cdw12 = args.cdw12, + .cdw10 = op | elid << 16, + .cdw11 = cdw11, + .cdw12 = cdw12, .result = expected_result, }; - int err; - set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_capacity_mgmt(test_link, &args); + err = nvme_capacity_mgmt(test_link, op, elid, cdw11, cdw12, &result); end_mock_cmds(); check(err == 0, "returned error %d", err); check(result == expected_result, "wrong result"); From b62c63facee6c8692ca1212003c31b11cacc6543 Mon Sep 17 00:00:00 2001 From: Dennis Maisenbacher Date: Mon, 11 Aug 2025 13:49:37 +0200 Subject: [PATCH 59/66] ioctl: nvme_get_features use nvme_passthru_cmd directly Drop struct nvme_get_features_args. Signed-off-by: Dennis Maisenbacher [wagi: reordered/renamed arguments] Signed-off-by: Daniel Wagner --- src/libnvme.map | 32 --- src/nvme/api-types.h | 36 ---- src/nvme/ioctl.c | 429 ------------------------------------- src/nvme/ioctl.h | 477 +++++++++++++++++++++++++++++++----------- test/ioctl/features.c | 39 ++-- test/mi.c | 22 +- 6 files changed, 371 insertions(+), 664 deletions(-) diff --git a/src/libnvme.map b/src/libnvme.map index c41c53252..60210684e 100644 --- a/src/libnvme.map +++ b/src/libnvme.map @@ -84,38 +84,6 @@ LIBNVME_2_0 { nvme_get_ctrl_telemetry; nvme_get_debug; nvme_get_directive_receive_length; - nvme_get_feature_length; - nvme_get_features; - nvme_get_features_arbitration; - nvme_get_features_async_event; - nvme_get_features_auto_pst; - nvme_get_features_endurance_event_cfg; - nvme_get_features_err_recovery; - nvme_get_features_hctm; - nvme_get_features_host_behavior; - nvme_get_features_host_id; - nvme_get_features_host_mem_buf; - nvme_get_features_iocs_profile; - nvme_get_features_irq_coalesce; - nvme_get_features_irq_config; - nvme_get_features_kato; - nvme_get_features_lba_range; - nvme_get_features_lba_sts_interval; - nvme_get_features_nopsc; - nvme_get_features_num_queues; - nvme_get_features_plm_config; - nvme_get_features_plm_window; - nvme_get_features_power_mgmt; - nvme_get_features_resv_mask; - nvme_get_features_resv_persist; - nvme_get_features_rrl; - nvme_get_features_sanitize; - nvme_get_features_sw_progress; - nvme_get_features_temp_thresh; - nvme_get_features_timestamp; - nvme_get_features_volatile_wc; - nvme_get_features_write_atomic; - nvme_get_features_write_protect; nvme_get_host_telemetry; nvme_get_log_partial; nvme_get_logging_level; diff --git a/src/nvme/api-types.h b/src/nvme/api-types.h index 1b8ee4694..60ebc324e 100644 --- a/src/nvme/api-types.h +++ b/src/nvme/api-types.h @@ -40,40 +40,4 @@ nvme_root_t nvme_create_root(FILE *fp, int log_level); */ void nvme_free_root(nvme_root_t r); -/* - * _args struct definitions. These are used by both the ioctl-based and - * MI-based interfaces, as the call interface for (admin/io/etc) NVMe commands, - * passed to the nvme_*() and nvme_mi_*() functions. - * - * On MI-based interfaces, the fd and timeout members are unused, and should - * be set to zero. - */ - -/** - * struct nvme_get_features_args - Arguments for the NVMe Admin Get Feature command - * @args_size: Size of &struct nvme_get_features_args - * @result: The command completion result from CQE dword0 - * @timeout: Timeout in ms - * @nsid: Namespace ID, if applicable - * @sel: Select which type of attribute to return, - * see &enum nvme_get_features_sel - * @cdw11: Feature specific command dword11 field - * @data_len: Length of feature data, if applicable, in bytes - * @data: User address of feature data, if applicable - * @fid: Feature identifier, see &enum nvme_features_id - * @uuidx: UUID Index for differentiating vendor specific encoding - */ -struct nvme_get_features_args { - __u32 *result; - void *data; - int args_size; - __u32 timeout; - __u32 nsid; - enum nvme_get_features_sel sel; - __u32 cdw11; - __u32 data_len; - __u8 fid; - __u8 uuidx; -}; - #endif /* _LIBNVME_API_TYPES_H */ diff --git a/src/nvme/ioctl.c b/src/nvme/ioctl.c index 537ec316b..bb559c0b9 100644 --- a/src/nvme/ioctl.c +++ b/src/nvme/ioctl.c @@ -606,417 +606,6 @@ int nvme_get_ana_log_atomic(nvme_link_t l, bool rae, bool rgo, return -EAGAIN; } -int nvme_get_features(nvme_link_t l, struct nvme_get_features_args *args) -{ - __u32 cdw10 = NVME_SET(args->fid, FEATURES_CDW10_FID) | - NVME_SET(args->sel, GET_FEATURES_CDW10_SEL); - __u32 cdw14 = NVME_SET(args->uuidx, FEATURES_CDW14_UUID); - - struct nvme_passthru_cmd cmd = { - .opcode = nvme_admin_get_features, - .nsid = args->nsid, - .addr = (__u64)(uintptr_t)args->data, - .data_len = args->data_len, - .cdw10 = cdw10, - .cdw11 = args->cdw11, - .cdw14 = cdw14, - .timeout_ms = args->timeout, - }; - - if (args->args_size < sizeof(*args)) - return -EINVAL; - - return nvme_submit_admin_passthru(l, &cmd, args->result); -} - -static int __nvme_get_features(nvme_link_t l, enum nvme_features_id fid, - enum nvme_get_features_sel sel, __u32 *result) -{ - struct nvme_get_features_args args = { - .args_size = sizeof(args), - .fid = fid, - .nsid = NVME_NSID_NONE, - .sel = sel, - .cdw11 = 0, - .uuidx = NVME_UUID_NONE, - .data_len = 0, - .data = NULL, - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .result = result, - }; - - return nvme_get_features(l, &args); -} - -int nvme_get_features_arbitration(nvme_link_t l, enum nvme_get_features_sel sel, - __u32 *result) -{ - return __nvme_get_features(l, NVME_FEAT_FID_ARBITRATION, sel, result); -} - -int nvme_get_features_power_mgmt(nvme_link_t l, enum nvme_get_features_sel sel, - __u32 *result) -{ - return __nvme_get_features(l, NVME_FEAT_FID_POWER_MGMT, sel, result); -} - -int nvme_get_features_lba_range(nvme_link_t l, enum nvme_get_features_sel sel, - __u32 nsid, struct nvme_lba_range_type *data, - __u32 *result) -{ - struct nvme_get_features_args args = { - .args_size = sizeof(args), - .fid = NVME_FEAT_FID_LBA_RANGE, - .nsid = nsid, - .sel = sel, - .uuidx = NVME_UUID_NONE, - .data = data, - .data_len = sizeof(*data), - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .result = result, - }; - - return nvme_get_features(l, &args); -} - -int nvme_get_features_temp_thresh(nvme_link_t l, enum nvme_get_features_sel sel, __u8 tmpsel, - enum nvme_feat_tmpthresh_thsel thsel, __u32 *result) -{ - struct nvme_get_features_args args = { - .args_size = sizeof(args), - .fid = NVME_FEAT_FID_TEMP_THRESH, - .nsid = NVME_NSID_NONE, - .sel = sel, - .cdw11 = NVME_SET(tmpsel, FEAT_TT_TMPSEL) | NVME_SET(thsel, FEAT_TT_THSEL), - .uuidx = NVME_UUID_NONE, - .data_len = 0, - .data = NULL, - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .result = result, - }; - - return nvme_get_features(l, &args); -} - -int nvme_get_features_err_recovery(nvme_link_t l, enum nvme_get_features_sel sel, - __u32 nsid, __u32 *result) -{ - - struct nvme_get_features_args args = { - .args_size = sizeof(args), - .fid = NVME_FEAT_FID_ERR_RECOVERY, - .nsid = nsid, - .sel = sel, - .uuidx = NVME_UUID_NONE, - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .result = result, - }; - - return nvme_get_features(l, &args); -} - -int nvme_get_features_volatile_wc(nvme_link_t l, enum nvme_get_features_sel sel, - __u32 *result) -{ - return __nvme_get_features(l, NVME_FEAT_FID_VOLATILE_WC, sel, result); -} - -int nvme_get_features_num_queues(nvme_link_t l, enum nvme_get_features_sel sel, - __u32 *result) -{ - return __nvme_get_features(l, NVME_FEAT_FID_NUM_QUEUES, sel, result); -} - -int nvme_get_features_irq_coalesce(nvme_link_t l, enum nvme_get_features_sel sel, - __u32 *result) -{ - return __nvme_get_features(l, NVME_FEAT_FID_IRQ_COALESCE, sel, - result); -} - -int nvme_get_features_irq_config(nvme_link_t l, enum nvme_get_features_sel sel, - __u16 iv, __u32 *result) -{ - struct nvme_get_features_args args = { - .args_size = sizeof(args), - .fid = NVME_FEAT_FID_IRQ_CONFIG, - .nsid = NVME_NSID_NONE, - .sel = sel, - .cdw11 = iv, - .uuidx = NVME_UUID_NONE, - .data_len = 0, - .data = NULL, - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .result = result, - }; - - return nvme_get_features(l, &args); -} - -int nvme_get_features_write_atomic(nvme_link_t l, enum nvme_get_features_sel sel, - __u32 *result) -{ - return __nvme_get_features(l, NVME_FEAT_FID_WRITE_ATOMIC, sel, - result); -} - -int nvme_get_features_async_event(nvme_link_t l, enum nvme_get_features_sel sel, - __u32 *result) -{ - return __nvme_get_features(l, NVME_FEAT_FID_ASYNC_EVENT, sel, result); -} - -int nvme_get_features_auto_pst(nvme_link_t l, enum nvme_get_features_sel sel, - struct nvme_feat_auto_pst *apst, __u32 *result) -{ - struct nvme_get_features_args args = { - .args_size = sizeof(args), - .fid = NVME_FEAT_FID_AUTO_PST, - .nsid = NVME_NSID_NONE, - .sel = sel, - .cdw11 = 0, - .uuidx = NVME_UUID_NONE, - .data_len = sizeof(*apst), - .data = apst, - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .result = result, - }; - - return nvme_get_features(l, &args); -} - -int nvme_get_features_host_mem_buf(nvme_link_t l, enum nvme_get_features_sel sel, - struct nvme_host_mem_buf_attrs *attrs, - __u32 *result) -{ - struct nvme_get_features_args args = { - .args_size = sizeof(args), - .fid = NVME_FEAT_FID_HOST_MEM_BUF, - .nsid = NVME_NSID_NONE, - .sel = sel, - .uuidx = NVME_UUID_NONE, - .data = attrs, - .data_len = sizeof(*attrs), - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .result = result, - }; - - return nvme_get_features(l, &args); -} - -int nvme_get_features_timestamp(nvme_link_t l, enum nvme_get_features_sel sel, - struct nvme_timestamp *ts) -{ - struct nvme_get_features_args args = { - .args_size = sizeof(args), - .fid = NVME_FEAT_FID_TIMESTAMP, - .nsid = NVME_NSID_NONE, - .sel = sel, - .cdw11 = 0, - .uuidx = NVME_UUID_NONE, - .data_len = sizeof(*ts), - .data = ts, - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .result = NULL, - }; - - return nvme_get_features(l, &args); -} - -int nvme_get_features_kato(nvme_link_t l, enum nvme_get_features_sel sel, __u32 *result) -{ - return __nvme_get_features(l, NVME_FEAT_FID_KATO, sel, result); -} - -int nvme_get_features_hctm(nvme_link_t l, enum nvme_get_features_sel sel, __u32 *result) -{ - return __nvme_get_features(l, NVME_FEAT_FID_HCTM, sel, result); -} - -int nvme_get_features_nopsc(nvme_link_t l, enum nvme_get_features_sel sel, __u32 *result) -{ - return __nvme_get_features(l, NVME_FEAT_FID_NOPSC, sel, result); -} - -int nvme_get_features_rrl(nvme_link_t l, enum nvme_get_features_sel sel, __u32 *result) -{ - return __nvme_get_features(l, NVME_FEAT_FID_RRL, sel, result); -} - -int nvme_get_features_plm_config(nvme_link_t l, enum nvme_get_features_sel sel, - __u16 nvmsetid, struct nvme_plm_config *data, - __u32 *result) -{ - struct nvme_get_features_args args = { - .args_size = sizeof(args), - .fid = NVME_FEAT_FID_PLM_CONFIG, - .nsid = NVME_NSID_NONE, - .sel = sel, - .cdw11 = nvmsetid, - .uuidx = NVME_UUID_NONE, - .data_len = sizeof(*data), - .data = data, - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .result = result, - }; - - return nvme_get_features(l, &args); -} - -int nvme_get_features_plm_window(nvme_link_t l, enum nvme_get_features_sel sel, - __u16 nvmsetid, __u32 *result) -{ - struct nvme_get_features_args args = { - .args_size = sizeof(args), - .fid = NVME_FEAT_FID_PLM_WINDOW, - .nsid = NVME_NSID_NONE, - .sel = sel, - .cdw11 = nvmsetid, - .uuidx = NVME_UUID_NONE, - .data_len = 0, - .data = NULL, - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .result = result, - }; - - return nvme_get_features(l, &args); -} - -int nvme_get_features_lba_sts_interval(nvme_link_t l, enum nvme_get_features_sel sel, - __u32 *result) -{ - return __nvme_get_features(l, NVME_FEAT_FID_LBA_STS_INTERVAL, sel, - result); -} - -int nvme_get_features_host_behavior(nvme_link_t l, enum nvme_get_features_sel sel, - struct nvme_feat_host_behavior *data, - __u32 *result) -{ - struct nvme_get_features_args args = { - .args_size = sizeof(args), - .fid = NVME_FEAT_FID_HOST_BEHAVIOR, - .nsid = NVME_NSID_NONE, - .sel = sel, - .cdw11 = 0, - .uuidx = NVME_UUID_NONE, - .data_len = sizeof(*data), - .data = data, - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .result = result, - }; - - return nvme_get_features(l, &args); -} - -int nvme_get_features_sanitize(nvme_link_t l, enum nvme_get_features_sel sel, - __u32 *result) -{ - return __nvme_get_features(l, NVME_FEAT_FID_SANITIZE, sel, result); -} - -int nvme_get_features_endurance_event_cfg(nvme_link_t l, enum nvme_get_features_sel sel, - __u16 endgid, __u32 *result) -{ - struct nvme_get_features_args args = { - .args_size = sizeof(args), - .fid = NVME_FEAT_FID_ENDURANCE_EVT_CFG, - .nsid = NVME_NSID_NONE, - .sel = sel, - .cdw11 = endgid, - .uuidx = NVME_UUID_NONE, - .data_len = 0, - .data = NULL, - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .result = result, - }; - - return nvme_get_features(l, &args); -} - -int nvme_get_features_sw_progress(nvme_link_t l, enum nvme_get_features_sel sel, - __u32 *result) -{ - return __nvme_get_features(l, NVME_FEAT_FID_SW_PROGRESS, sel, result); -} - -int nvme_get_features_host_id(nvme_link_t l, enum nvme_get_features_sel sel, - bool exhid, __u32 len, __u8 *hostid) -{ - struct nvme_get_features_args args = { - .args_size = sizeof(args), - .fid = NVME_FEAT_FID_HOST_ID, - .nsid = NVME_NSID_NONE, - .sel = sel, - .cdw11 = !!exhid, - .uuidx = NVME_UUID_NONE, - .data_len = len, - .data = hostid, - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .result = NULL, - }; - - return nvme_get_features(l, &args); -} - -int nvme_get_features_resv_mask(nvme_link_t l, enum nvme_get_features_sel sel, - __u32 nsid, __u32 *result) -{ - struct nvme_get_features_args args = { - .args_size = sizeof(args), - .fid = NVME_FEAT_FID_RESV_MASK, - .nsid = nsid, - .sel = sel, - .uuidx = NVME_UUID_NONE, - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .result = result, - }; - - return nvme_get_features(l, &args); -} - -int nvme_get_features_resv_persist(nvme_link_t l, enum nvme_get_features_sel sel, - __u32 nsid, __u32 *result) -{ - struct nvme_get_features_args args = { - .args_size = sizeof(args), - .fid = NVME_FEAT_FID_RESV_PERSIST, - .nsid = nsid, - .sel = sel, - .uuidx = NVME_UUID_NONE, - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .result = result, - }; - - return nvme_get_features(l, &args); -} - -int nvme_get_features_write_protect(nvme_link_t l, __u32 nsid, - enum nvme_get_features_sel sel, - __u32 *result) -{ - struct nvme_get_features_args args = { - .args_size = sizeof(args), - .fid = NVME_FEAT_FID_WRITE_PROTECT, - .nsid = nsid, - .sel = sel, - .cdw11 = 0, - .uuidx = NVME_UUID_NONE, - .data_len = 0, - .data = NULL, - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .result = result, - }; - - return nvme_get_features(l, &args); -} - -int nvme_get_features_iocs_profile(nvme_link_t l, enum nvme_get_features_sel sel, - __u32 *result) -{ - return __nvme_get_features(l, NVME_FEAT_FID_IOCS_PROFILE, sel, result); -} - int nvme_submit_io_passthru64(nvme_link_t l, struct nvme_passthru_cmd64 *cmd, __u64 *result) { @@ -1051,21 +640,3 @@ int nvme_io_passthru(nvme_link_t l, __u8 opcode, __u8 flags, __u16 rsvd, cdw15, data_len, data, metadata_len, metadata, timeout_ms, result); } - -int nvme_lm_get_features_ctrl_data_queue(nvme_link_t l, __u16 cdqid, - struct nvme_lm_ctrl_data_queue_fid_data *data, - __u32 *result) -{ - struct nvme_get_features_args args = { - .args_size = sizeof(args), - .fid = NVME_FEAT_FID_CTRL_DATA_QUEUE, - .nsid = NVME_NSID_NONE, - .cdw11 = cdqid, - .data = data, - .data_len = sizeof(*data), - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .result = result, - }; - - return nvme_get_features(l, &args); -} diff --git a/src/nvme/ioctl.h b/src/nvme/ioctl.h index c2d6c46fa..3d573ac15 100644 --- a/src/nvme/ioctl.h +++ b/src/nvme/ioctl.h @@ -2967,103 +2967,158 @@ static inline int nvme_set_features_iocs_profile(nvme_link_t l, bool sv, /** * nvme_get_features() - Retrieve a feature attribute * @l: Link handle - * @args: &struct nvme_get_features_args argument structure + * @nsid: Namespace ID, if applicable + * @fid: Feature identifier, see &enum nvme_features_id + * @sel: Select which type of attribute to return, + * see &enum nvme_get_features_sel + * @cdw11: Feature specific command dword11 field + * @uidx: UUID Index for differentiating vendor specific encoding + * @data: User address of feature data, if applicable + * @data_len: Length of feature data, if applicable, in bytes + * @result: The command completion result from CQE dword0 * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_get_features(nvme_link_t l, struct nvme_get_features_args *args); +static inline int nvme_get_features(nvme_link_t l, __u32 nsid, __u8 fid, + enum nvme_get_features_sel sel, __u32 cdw11, + __u8 uidx, void *data, __u32 data_len, + __u32 *result) +{ + __u32 cdw10 = NVME_SET(fid, FEATURES_CDW10_FID) | + NVME_SET(sel, GET_FEATURES_CDW10_SEL); + __u32 cdw14 = NVME_SET(uidx, FEATURES_CDW14_UUID); + + struct nvme_passthru_cmd cmd = { + .opcode = nvme_admin_get_features, + .nsid = nsid, + .addr = (__u64)(uintptr_t)data, + .data_len = data_len, + .cdw10 = cdw10, + .cdw11 = cdw11, + .cdw14 = cdw14, + .timeout_ms = NVME_DEFAULT_IOCTL_TIMEOUT, + }; + + return nvme_submit_admin_passthru(l, &cmd, result); +} + +/** + * __nvme_get_features() - Internal helper function for @nvme_get_features() + * @l: Link handle + * @fid: Feature identifier, see &enum nvme_features_id + * @sel: Select which type of attribute to return, + * see &enum nvme_get_features_sel + * @result: The command completion result from CQE dword0 + * + * Return: The nvme command status if a response was received (see + * &enum nvme_status_field) or -1 with errno set otherwise. + */ +static inline int __nvme_get_features(nvme_link_t l, enum nvme_features_id fid, + enum nvme_get_features_sel sel, __u32 *result) +{ + return nvme_get_features(l, NVME_NSID_NONE, fid, sel, 0, NVME_UUID_NONE, + NULL, 0, result); +} /** * nvme_get_features_data() - Helper function for @nvme_get_features() * @l: Link handle - * @fid: Feature identifier * @nsid: Namespace ID, if applicable - * @data_len: Length of feature data, if applicable, in bytes + * @fid: Feature identifier * @data: User address of feature data, if applicable + * @data_len: Length of feature data, if applicable, in bytes * @result: The command completion result from CQE dword0 * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -static inline int nvme_get_features_data(nvme_link_t l, enum nvme_features_id fid, - __u32 nsid, __u32 data_len, void *data, __u32 *result) +static inline int nvme_get_features_data(nvme_link_t l, __u32 nsid, + enum nvme_features_id fid, + void *data, __u32 data_len, + __u32 *result) { - struct nvme_get_features_args args = { - .result = result, - .data = data, - .args_size = sizeof(args), - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .nsid = nsid, - .sel = NVME_GET_FEATURES_SEL_CURRENT, - .cdw11 = 0, - .data_len = data_len, - .fid = (__u8)fid, - .uuidx = NVME_UUID_NONE, - }; - - return nvme_get_features(l, &args); + return nvme_get_features(l, nsid, fid, NVME_GET_FEATURES_SEL_CURRENT, 0, + NVME_UUID_NONE, data, data_len, result); } /** * nvme_get_features_simple() - Helper function for @nvme_get_features() * @l: Link handle - * @fid: Feature identifier * @nsid: Namespace ID, if applicable + * @fid: Feature identifier * @result: The command completion result from CQE dword0 * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -static inline int nvme_get_features_simple(nvme_link_t l, enum nvme_features_id fid, - __u32 nsid, __u32 *result) +static inline int nvme_get_features_simple(nvme_link_t l, __u32 nsid, + enum nvme_features_id fid, + __u32 *result) { - return nvme_get_features_data(l, fid, nsid, 0, NULL, result); + return nvme_get_features_data(l, nsid, fid, NULL, 0, result); } /** * nvme_get_features_arbitration() - Get arbitration feature * @l: Link handle - * @sel: Select which type of attribute to return, see &enum nvme_get_features_sel + * @sel: Select which type of attribute to return, + * see &enum nvme_get_features_sel * @result: The command completion result from CQE dword0 * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_get_features_arbitration(nvme_link_t l, enum nvme_get_features_sel sel, - __u32 *result); +static inline int nvme_get_features_arbitration(nvme_link_t l, + enum nvme_get_features_sel sel, + __u32 *result) +{ + return __nvme_get_features(l, NVME_FEAT_FID_ARBITRATION, sel, result); +} /** * nvme_get_features_power_mgmt() - Get power management feature * @l: Link handle - * @sel: Select which type of attribute to return, see &enum nvme_get_features_sel + * @sel: Select which type of attribute to return, + * see &enum nvme_get_features_sel * @result: The command completion result from CQE dword0 * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_get_features_power_mgmt(nvme_link_t l, enum nvme_get_features_sel sel, - __u32 *result); +static inline int nvme_get_features_power_mgmt(nvme_link_t l, + enum nvme_get_features_sel sel, + __u32 *result) +{ + return __nvme_get_features(l, NVME_FEAT_FID_POWER_MGMT, sel, result); +} /** * nvme_get_features_lba_range() - Get LBA range feature * @l: Link handle - * @sel: Select which type of attribute to return, see &enum nvme_get_features_sel * @nsid: Namespace ID - * @data: Buffer to receive LBA Range Type data structure + * @sel: Select which type of attribute to return, + * see &enum nvme_get_features_sel + * @lrt: Buffer to receive LBA Range Type data structure * @result: The command completion result from CQE dword0 * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_get_features_lba_range(nvme_link_t l, enum nvme_get_features_sel sel, - __u32 nsid, struct nvme_lba_range_type *data, - __u32 *result); +static inline int nvme_get_features_lba_range(nvme_link_t l, __u32 nsid, + enum nvme_get_features_sel sel, + struct nvme_lba_range_type *lrt, + __u32 *result) +{ + return nvme_get_features(l, nsid, NVME_FEAT_FID_LBA_RANGE, sel, 0, + NVME_UUID_NONE, lrt, sizeof(*lrt), result); +} /** * nvme_get_features_temp_thresh() - Get temperature threshold feature * @l: Link handle - * @sel: Select which type of attribute to return, see &enum nvme_get_features_sel + * @sel: Select which type of attribute to return, + * see &enum nvme_get_features_sel * @tmpsel: Threshold Temperature Select * @thsel: Threshold Type Select * @result: The command completion result from CQE dword0 @@ -3071,274 +3126,413 @@ int nvme_get_features_lba_range(nvme_link_t l, enum nvme_get_features_sel sel, * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_get_features_temp_thresh(nvme_link_t l, enum nvme_get_features_sel sel, __u8 tmpsel, - enum nvme_feat_tmpthresh_thsel thsel, __u32 *result); +static inline int nvme_get_features_temp_thresh(nvme_link_t l, + enum nvme_get_features_sel sel, + __u8 tmpsel, + enum nvme_feat_tmpthresh_thsel thsel, + __u32 *result) +{ + __u32 cdw11 = NVME_SET(tmpsel, FEAT_TT_TMPSEL) | + NVME_SET(thsel, FEAT_TT_THSEL); + + return nvme_get_features(l, NVME_NSID_NONE, NVME_FEAT_FID_TEMP_THRESH, + sel, cdw11, NVME_UUID_NONE, NULL, 0, result); +} /** * nvme_get_features_err_recovery() - Get error recovery feature * @l: Link handle - * @sel: Select which type of attribute to return, see &enum nvme_get_features_sel * @nsid: Namespace ID + * @sel: Select which type of attribute to return, + * see &enum nvme_get_features_sel * @result: The command completion result from CQE dword0 * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_get_features_err_recovery(nvme_link_t l, enum nvme_get_features_sel sel, - __u32 nsid, __u32 *result); +static inline int nvme_get_features_err_recovery(nvme_link_t l, __u32 nsid, + enum nvme_get_features_sel sel, + __u32 *result) +{ + return nvme_get_features(l, nsid, NVME_FEAT_FID_ERR_RECOVERY, sel, 0, + NVME_UUID_NONE, NULL, 0, result); +} /** * nvme_get_features_volatile_wc() - Get volatile write cache feature * @l: Link handle - * @sel: Select which type of attribute to return, see &enum nvme_get_features_sel + * @sel: Select which type of attribute to return, + * see &enum nvme_get_features_sel * @result: The command completion result from CQE dword0 * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_get_features_volatile_wc(nvme_link_t l, enum nvme_get_features_sel sel, - __u32 *result); +static inline int nvme_get_features_volatile_wc(nvme_link_t l, + enum nvme_get_features_sel sel, + __u32 *result) +{ + return __nvme_get_features(l, NVME_FEAT_FID_VOLATILE_WC, sel, result); +} /** * nvme_get_features_num_queues() - Get number of queues feature * @l: Link handle - * @sel: Select which type of attribute to return, see &enum nvme_get_features_sel + * @sel: Select which type of attribute to return, + * see &enum nvme_get_features_sel * @result: The command completion result from CQE dword0 * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_get_features_num_queues(nvme_link_t l, enum nvme_get_features_sel sel, - __u32 *result); +static inline int nvme_get_features_num_queues(nvme_link_t l, + enum nvme_get_features_sel sel, + __u32 *result) +{ + return __nvme_get_features(l, NVME_FEAT_FID_NUM_QUEUES, sel, result); +} /** * nvme_get_features_irq_coalesce() - Get IRQ coalesce feature * @l: Link handle - * @sel: Select which type of attribute to return, see &enum nvme_get_features_sel + * @sel: Select which type of attribute to return, + * see &enum nvme_get_features_sel * @result: The command completion result from CQE dword0 * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_get_features_irq_coalesce(nvme_link_t l, enum nvme_get_features_sel sel, - __u32 *result); +static inline int nvme_get_features_irq_coalesce(nvme_link_t l, + enum nvme_get_features_sel sel, + __u32 *result) +{ + return __nvme_get_features(l, NVME_FEAT_FID_IRQ_COALESCE, sel, result); +} /** * nvme_get_features_irq_config() - Get IRQ config feature * @l: Link handle - * @sel: Select which type of attribute to return, see &enum nvme_get_features_sel - * @iv: + * @sel: Select which type of attribute to return, + * see &enum nvme_get_features_sel + * @iv: Interrupt Vector + * @cd: Coalescing Disable * @result: The command completion result from CQE dword0 * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_get_features_irq_config(nvme_link_t l, enum nvme_get_features_sel sel, - __u16 iv, __u32 *result); +static inline int nvme_get_features_irq_config(nvme_link_t l, + enum nvme_get_features_sel sel, + __u16 iv, bool cd, __u32 *result) +{ + __u32 cdw11 = NVME_SET(iv, FEAT_ICFG_IV) | + NVME_SET(cd, FEAT_ICFG_CD); + + return nvme_get_features(l, NVME_NSID_NONE, NVME_FEAT_FID_IRQ_CONFIG, + sel, cdw11, NVME_UUID_NONE, NULL, 0, result); +} /** * nvme_get_features_write_atomic() - Get write atomic feature * @l: Link handle - * @sel: Select which type of attribute to return, see &enum nvme_get_features_sel + * @sel: Select which type of attribute to return, + * see &enum nvme_get_features_sel * @result: The command completion result from CQE dword0 * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_get_features_write_atomic(nvme_link_t l, enum nvme_get_features_sel sel, - __u32 *result); +static inline int nvme_get_features_write_atomic(nvme_link_t l, + enum nvme_get_features_sel sel, + __u32 *result) +{ + return __nvme_get_features(l, NVME_FEAT_FID_WRITE_ATOMIC, sel, result); +} /** * nvme_get_features_async_event() - Get asynchronous event feature * @l: Link handle - * @sel: Select which type of attribute to return, see &enum nvme_get_features_sel + * @sel: Select which type of attribute to return, + * see &enum nvme_get_features_sel * @result: The command completion result from CQE dword0 * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_get_features_async_event(nvme_link_t l, enum nvme_get_features_sel sel, - __u32 *result); +static inline int nvme_get_features_async_event(nvme_link_t l, + enum nvme_get_features_sel sel, + __u32 *result) +{ + return __nvme_get_features(l, NVME_FEAT_FID_ASYNC_EVENT, sel, result); +} /** * nvme_get_features_auto_pst() - Get autonomous power state feature * @l: Link handle - * @sel: Select which type of attribute to return, see &enum nvme_get_features_sel - * @apst: + * @sel: Select which type of attribute to return, + * see &enum nvme_get_features_sel + * @apst: Autonomous Power State Transition * @result: The command completion result from CQE dword0 * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_get_features_auto_pst(nvme_link_t l, enum nvme_get_features_sel sel, - struct nvme_feat_auto_pst *apst, __u32 *result); +static inline int nvme_get_features_auto_pst(nvme_link_t l, + enum nvme_get_features_sel sel, + struct nvme_feat_auto_pst *apst, + __u32 *result) +{ + return nvme_get_features(l, NVME_NSID_NONE, NVME_FEAT_FID_AUTO_PST, sel, + 0, NVME_UUID_NONE, apst, sizeof(*apst), result); +} /** * nvme_get_features_host_mem_buf() - Get host memory buffer feature * @l: Link handle - * @sel: Select which type of attribute to return, see &enum nvme_get_features_sel + * @sel: Select which type of attribute to return, + * see &enum nvme_get_features_sel * @attrs: Buffer for returned Host Memory Buffer Attributes * @result: The command completion result from CQE dword0 * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_get_features_host_mem_buf(nvme_link_t l, enum nvme_get_features_sel sel, - struct nvme_host_mem_buf_attrs *attrs, - __u32 *result); +static inline int nvme_get_features_host_mem_buf(nvme_link_t l, + enum nvme_get_features_sel sel, + struct nvme_host_mem_buf_attrs *attrs, + __u32 *result) +{ + return nvme_get_features(l, NVME_NSID_NONE, NVME_FEAT_FID_HOST_MEM_BUF, + sel, 0, NVME_UUID_NONE, + attrs, sizeof(*attrs), result); +} /** * nvme_get_features_timestamp() - Get timestamp feature * @l: Link handle - * @sel: Select which type of attribute to return, see &enum nvme_get_features_sel + * @sel: Select which type of attribute to return, + * see &enum nvme_get_features_sel * @ts: Current timestamp * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_get_features_timestamp(nvme_link_t l, enum nvme_get_features_sel sel, - struct nvme_timestamp *ts); +static inline int nvme_get_features_timestamp(nvme_link_t l, + enum nvme_get_features_sel sel, + struct nvme_timestamp *ts) +{ + return nvme_get_features(l, NVME_NSID_NONE, NVME_FEAT_FID_TIMESTAMP, + sel, 0, NVME_UUID_NONE, ts, sizeof(*ts), NULL); +} /** * nvme_get_features_kato() - Get keep alive timeout feature * @l: Link handle - * @sel: Select which type of attribute to return, see &enum nvme_get_features_sel + * @sel: Select which type of attribute to return, + * see &enum nvme_get_features_sel * @result: The command completion result from CQE dword0 * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_get_features_kato(nvme_link_t l, enum nvme_get_features_sel sel, __u32 *result); +static inline int nvme_get_features_kato(nvme_link_t l, + enum nvme_get_features_sel sel, + __u32 *result) +{ + return __nvme_get_features(l, NVME_FEAT_FID_KATO, sel, result); +} /** * nvme_get_features_hctm() - Get thermal management feature * @l: Link handle - * @sel: Select which type of attribute to return, see &enum nvme_get_features_sel + * @sel: Select which type of attribute to return, + * see &enum nvme_get_features_sel * @result: The command completion result from CQE dword0 * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_get_features_hctm(nvme_link_t l, enum nvme_get_features_sel sel, __u32 *result); +static inline int nvme_get_features_hctm(nvme_link_t l, + enum nvme_get_features_sel sel, + __u32 *result) +{ + return __nvme_get_features(l, NVME_FEAT_FID_HCTM, sel, result); +} /** * nvme_get_features_nopsc() - Get non-operational power state feature * @l: Link handle - * @sel: Select which type of attribute to return, see &enum nvme_get_features_sel + * @sel: Select which type of attribute to return, + * see &enum nvme_get_features_sel * @result: The command completion result from CQE dword0 * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_get_features_nopsc(nvme_link_t l, enum nvme_get_features_sel sel, __u32 *result); +static inline int nvme_get_features_nopsc(nvme_link_t l, + enum nvme_get_features_sel sel, + __u32 *result) +{ + return __nvme_get_features(l, NVME_FEAT_FID_NOPSC, sel, result); +} /** * nvme_get_features_rrl() - Get read recovery level feature * @l: Link handle - * @sel: Select which type of attribute to return, see &enum nvme_get_features_sel + * @sel: Select which type of attribute to return, + * see &enum nvme_get_features_sel * @result: The command completion result from CQE dword0 * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_get_features_rrl(nvme_link_t l, enum nvme_get_features_sel sel, __u32 *result); +static inline int nvme_get_features_rrl(nvme_link_t l, + enum nvme_get_features_sel sel, + __u32 *result) +{ + return __nvme_get_features(l, NVME_FEAT_FID_RRL, sel, result); +} /** * nvme_get_features_plm_config() - Get predictable latency feature * @l: Link handle - * @sel: Select which type of attribute to return, see &enum nvme_get_features_sel + * @sel: Select which type of attribute to return, + * see &enum nvme_get_features_sel * @nvmsetid: NVM set id - * @data: + * @plmc: Buffer for returned Predictable Latency Mode Config * @result: The command completion result from CQE dword0 * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_get_features_plm_config(nvme_link_t l, enum nvme_get_features_sel sel, - __u16 nvmsetid, struct nvme_plm_config *data, - __u32 *result); +static inline int nvme_get_features_plm_config(nvme_link_t l, + enum nvme_get_features_sel sel, + __u16 nvmsetid, + struct nvme_plm_config *plmc, + __u32 *result) +{ + return nvme_get_features(l, NVME_NSID_NONE, NVME_FEAT_FID_PLM_CONFIG, + sel, nvmsetid, NVME_UUID_NONE, + plmc, sizeof(*plmc), result); +} /** * nvme_get_features_plm_window() - Get window select feature * @l: Link handle - * @sel: Select which type of attribute to return, see &enum nvme_get_features_sel + * @sel: Select which type of attribute to return, + * see &enum nvme_get_features_sel * @nvmsetid: NVM set id * @result: The command completion result from CQE dword0 * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_get_features_plm_window(nvme_link_t l, enum nvme_get_features_sel sel, - __u16 nvmsetid, __u32 *result); +static inline int nvme_get_features_plm_window(nvme_link_t l, + enum nvme_get_features_sel sel, + __u16 nvmsetid, __u32 *result) +{ + return nvme_get_features(l, NVME_NSID_NONE, NVME_FEAT_FID_PLM_WINDOW, + sel, nvmsetid, NVME_UUID_NONE, + NULL, 0, result); +} /** * nvme_get_features_lba_sts_interval() - Get LBA status information feature * @l: Link handle - * @sel: Select which type of attribute to return, see &enum nvme_get_features_sel + * @sel: Select which type of attribute to return, + * see &enum nvme_get_features_sel * @result: The command completion result from CQE dword0 * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_get_features_lba_sts_interval(nvme_link_t l, enum nvme_get_features_sel sel, - __u32 *result); +static inline int nvme_get_features_lba_sts_interval(nvme_link_t l, + enum nvme_get_features_sel sel, + __u32 *result) +{ + return __nvme_get_features(l, NVME_FEAT_FID_LBA_STS_INTERVAL, sel, result); +} /** * nvme_get_features_host_behavior() - Get host behavior feature * @l: Link handle - * @sel: Select which type of attribute to return, see &enum nvme_get_features_sel - * @data: Pointer to structure nvme_feat_host_behavior + * @sel: Select which type of attribute to return, + * see &enum nvme_get_features_sel + * @fhb: Pointer to structure nvme_feat_host_behavior * @result: The command completion result from CQE dword0 * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_get_features_host_behavior(nvme_link_t l, enum nvme_get_features_sel sel, - struct nvme_feat_host_behavior *data, - __u32 *result); +static inline int nvme_get_features_host_behavior(nvme_link_t l, + enum nvme_get_features_sel sel, + struct nvme_feat_host_behavior *fhb, + __u32 *result) +{ + return nvme_get_features(l, NVME_NSID_NONE, NVME_FEAT_FID_HOST_BEHAVIOR, + sel, 0, NVME_UUID_NONE, + fhb, sizeof(*fhb), result); +} /** * nvme_get_features_sanitize() - Get sanitize feature * @l: Link handle - * @sel: Select which type of attribute to return, see &enum nvme_get_features_sel + * @sel: Select which type of attribute to return, + * see &enum nvme_get_features_sel * @result: The command completion result from CQE dword0 * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_get_features_sanitize(nvme_link_t l, enum nvme_get_features_sel sel, - __u32 *result); +static inline int nvme_get_features_sanitize(nvme_link_t l, + enum nvme_get_features_sel sel, + __u32 *result) +{ + return __nvme_get_features(l, NVME_FEAT_FID_SANITIZE, sel, result); +} /** * nvme_get_features_endurance_event_cfg() - Get endurance event config feature * @l: Link handle - * @sel: Select which type of attribute to return, see &enum nvme_get_features_sel + * @sel: Select which type of attribute to return, + * see &enum nvme_get_features_sel * @endgid: Endurance Group Identifier * @result: The command completion result from CQE dword0 * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_get_features_endurance_event_cfg(nvme_link_t l, enum nvme_get_features_sel sel, - __u16 endgid, __u32 *result); +static inline int nvme_get_features_endurance_event_cfg(nvme_link_t l, + enum nvme_get_features_sel sel, + __u16 endgid, __u32 *result) +{ + return nvme_get_features(l, NVME_NSID_NONE, NVME_FEAT_FID_ENDURANCE_EVT_CFG, + sel, endgid, NVME_UUID_NONE, NULL, 0, result); +} /** * nvme_get_features_sw_progress() - Get software progress feature * @l: Link handle - * @sel: Select which type of attribute to return, see &enum nvme_get_features_sel + * @sel: Select which type of attribute to return, + * see &enum nvme_get_features_sel * @result: The command completion result from CQE dword0 * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_get_features_sw_progress(nvme_link_t l, enum nvme_get_features_sel sel, - __u32 *result); +static inline int nvme_get_features_sw_progress(nvme_link_t l, + enum nvme_get_features_sel sel, + __u32 *result) +{ + return __nvme_get_features(l, NVME_FEAT_FID_SW_PROGRESS, sel, result); +} /** * nvme_get_features_host_id() - Get host id feature * @l: Link handle - * @sel: Select which type of attribute to return, see &enum nvme_get_features_sel + * @sel: Select which type of attribute to return, + * see &enum nvme_get_features_sel * @exhid: Enable Extended Host Identifier * @len: Length of @hostid * @hostid: Buffer for returned host ID @@ -3346,60 +3540,86 @@ int nvme_get_features_sw_progress(nvme_link_t l, enum nvme_get_features_sel sel, * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_get_features_host_id(nvme_link_t l, enum nvme_get_features_sel sel, - bool exhid, __u32 len, __u8 *hostid); +static inline int nvme_get_features_host_id(nvme_link_t l, enum nvme_get_features_sel sel, + bool exhid, __u32 len, __u8 *hostid) +{ + return nvme_get_features(l, NVME_NSID_NONE, NVME_FEAT_FID_HOST_ID, + sel, exhid, NVME_UUID_NONE, hostid, len, NULL); +} /** * nvme_get_features_resv_mask() - Get reservation mask feature * @l: Link handle - * @sel: Select which type of attribute to return, see &enum nvme_get_features_sel * @nsid: Namespace ID + * @sel: Select which type of attribute to return, + * see &enum nvme_get_features_sel * @result: The command completion result from CQE dword0 * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_get_features_resv_mask(nvme_link_t l, enum nvme_get_features_sel sel, - __u32 nsid, __u32 *result); +static inline int nvme_get_features_resv_mask(nvme_link_t l, __u32 nsid, + enum nvme_get_features_sel sel, + __u32 *result) +{ + return nvme_get_features(l, nsid, NVME_FEAT_FID_RESV_MASK, + sel, 0, NVME_UUID_NONE, NULL, 0, result); +} /** * nvme_get_features_resv_persist() - Get reservation persist feature * @l: Link handle - * @sel: Select which type of attribute to return, see &enum nvme_get_features_sel * @nsid: Namespace ID + * @sel: Select which type of attribute to return, + * see &enum nvme_get_features_sel * @result: The command completion result from CQE dword0 * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_get_features_resv_persist(nvme_link_t l, enum nvme_get_features_sel sel, - __u32 nsid, __u32 *result); +static inline int nvme_get_features_resv_persist(nvme_link_t l, __u32 nsid, + enum nvme_get_features_sel sel, + __u32 *result) +{ + return nvme_get_features(l, nsid, NVME_FEAT_FID_RESV_PERSIST, + sel, 0, NVME_UUID_NONE, NULL, 0, result); +} /** * nvme_get_features_write_protect() - Get write protect feature * @l: Link handle * @nsid: Namespace ID - * @sel: Select which type of attribute to return, see &enum nvme_get_features_sel + * @sel: Select which type of attribute to return, + * see &enum nvme_get_features_sel * @result: The command completion result from CQE dword0 * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_get_features_write_protect(nvme_link_t l, __u32 nsid, - enum nvme_get_features_sel sel, - __u32 *result); +static inline int nvme_get_features_write_protect(nvme_link_t l, __u32 nsid, + enum nvme_get_features_sel sel, + __u32 *result) +{ + return nvme_get_features(l, nsid, NVME_FEAT_FID_WRITE_PROTECT, + sel, 0, NVME_UUID_NONE, NULL, 0, result); +} /** * nvme_get_features_iocs_profile() - Get IOCS profile feature * @l: Link handle - * @sel: Select which type of attribute to return, see &enum nvme_get_features_sel + * @sel: Select which type of attribute to return, + * see &enum nvme_get_features_sel * @result: The command completion result from CQE dword0 * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_get_features_iocs_profile(nvme_link_t l, enum nvme_get_features_sel sel, - __u32 *result); +static inline int nvme_get_features_iocs_profile(nvme_link_t l, + enum nvme_get_features_sel sel, + __u32 *result) +{ + return __nvme_get_features(l, NVME_FEAT_FID_IOCS_PROFILE, sel, result); +} /** * nvme_format_nvm() - Format nvme namespace(s) @@ -5483,14 +5703,23 @@ static inline int nvme_lm_set_features_ctrl_data_queue(nvme_link_t l, __u16 cdqi /** * nvme_lm_get_features_ctrl_data_queue - Get Controller Data Queue feature * @l: Link handle + * @sel: Select which type of attribute to return, + * see &enum nvme_get_features_sel * @cdqid: Controller Data Queue ID (CDQID) - * @data: Get Controller Data Queue feature data + * @qfd: Get Controller Data Queue feature data * @result: The command completions result from CQE dword0 * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ -int nvme_lm_get_features_ctrl_data_queue(nvme_link_t l, __u16 cdqid, - struct nvme_lm_ctrl_data_queue_fid_data *data, - __u32 *result); +static inline int nvme_lm_get_features_ctrl_data_queue(nvme_link_t l, + enum nvme_get_features_sel sel, + __u16 cdqid, + struct nvme_lm_ctrl_data_queue_fid_data *qfd, + __u32 *result) +{ + return nvme_get_features(l, NVME_NSID_NONE, NVME_FEAT_FID_CTRL_DATA_QUEUE, + sel, cdqid, NVME_UUID_NONE, + qfd, sizeof(*qfd), result); +} #endif /* _LIBNVME_IOCTL_H */ diff --git a/test/ioctl/features.c b/test/ioctl/features.c index 53bc053d0..a98e315fd 100644 --- a/test/ioctl/features.c +++ b/test/ioctl/features.c @@ -60,18 +60,6 @@ static void test_get_features(void) { uint32_t result = 0; uint8_t data[256], get_data[sizeof(data)] = {}; - struct nvme_get_features_args args = { - .result = &result, - .data = get_data, - .args_size = sizeof(args), - .timeout = TEST_TIMEOUT, - .nsid = TEST_NSID, - .sel = TEST_SEL, - .cdw11 = TEST_CDW11, - .data_len = sizeof(data), - .fid = TEST_FID, - .uuidx = TEST_UUIDX, - }; struct mock_cmd mock_admin_cmd = { .opcode = nvme_admin_get_features, .nsid = TEST_NSID, @@ -79,7 +67,6 @@ static void test_get_features(void) .cdw10 = TEST_SEL << 8 | TEST_FID, .cdw11 = TEST_CDW11, .cdw14 = TEST_UUIDX, - .timeout_ms = TEST_TIMEOUT, .out_data = data, .result = TEST_RESULT, }; @@ -87,7 +74,8 @@ static void test_get_features(void) arbitrary(data, sizeof(data)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_get_features(test_link, &args); + err = nvme_get_features(test_link, TEST_NSID, TEST_FID, TEST_SEL, TEST_CDW11, + TEST_UUIDX, get_data, sizeof(data), &result); end_mock_cmds(); check(err == 0, "get features returned error %d", err); check(result == TEST_RESULT, @@ -138,7 +126,7 @@ static void test_get_features_data(void) arbitrary(data, sizeof(data)); set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_get_features_data( - test_link, TEST_FID, TEST_NSID, sizeof(data), get_data, &result); + test_link, TEST_NSID, TEST_FID, get_data, sizeof(data), &result); end_mock_cmds(); check(err == 0, "set features returned error %d", err); check(result == TEST_RESULT, @@ -180,7 +168,7 @@ static void test_get_features_simple(void) int err; set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_get_features_simple(test_link, TEST_FID, TEST_NSID, &result); + err = nvme_get_features_simple(test_link, TEST_NSID, TEST_FID, &result); end_mock_cmds(); check(err == 0, "set features returned error %d", err); check(result == TEST_RESULT, @@ -308,7 +296,7 @@ static void test_get_lba_range(void) arbitrary(&range_types, sizeof(range_types)); set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_get_features_lba_range( - test_link, TEST_SEL, TEST_NSID, &get_range_types, &result); + test_link, TEST_NSID, TEST_SEL, &get_range_types, &result); end_mock_cmds(); check(err == 0, "get features returned error %d", err); check(result == TEST_RESULT, @@ -401,7 +389,7 @@ static void test_get_err_recovery(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_get_features_err_recovery( - test_link, TEST_SEL, TEST_NSID, &result); + test_link, TEST_NSID, TEST_SEL, &result); end_mock_cmds(); check(err == 0, "get features returned error %d", err); check(result == TEST_RESULT, @@ -529,17 +517,18 @@ static void test_set_irq_config(void) static void test_get_irq_config(void) { uint16_t IV = 0x5678; + bool CD = true; struct mock_cmd mock_admin_cmd = { .opcode = nvme_admin_get_features, .cdw10 = TEST_SEL << 8 | NVME_FEAT_FID_IRQ_CONFIG, - .cdw11 = IV, + .cdw11 = IV | (!!CD << 16), .result = TEST_RESULT, }; uint32_t result = 0; int err; set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_get_features_irq_config(test_link, TEST_SEL, IV, &result); + err = nvme_get_features_irq_config(test_link, TEST_SEL, IV, CD, &result); end_mock_cmds(); check(err == 0, "get features returned error %d", err); check(result == TEST_RESULT, @@ -1324,7 +1313,7 @@ static void test_get_resv_mask(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_get_features_resv_mask( - test_link, TEST_SEL, TEST_NSID, &result); + test_link, TEST_NSID, TEST_SEL, &result); end_mock_cmds(); check(err == 0, "get features returned error %d", err); check(result == TEST_RESULT, @@ -1365,7 +1354,7 @@ static void test_get_resv_persist(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_get_features_resv_persist( - test_link, TEST_SEL, TEST_NSID, &result); + test_link, TEST_NSID, TEST_SEL, &result); end_mock_cmds(); check(err == 0, "get features returned error %d", err); check(result == TEST_RESULT, @@ -1538,7 +1527,7 @@ static void test_lm_get_features_ctrl_data_queue(void) struct mock_cmd mock_admin_cmd = { .opcode = nvme_admin_get_features, .nsid = NVME_NSID_NONE, - .cdw10 = NVME_FEAT_FID_CTRL_DATA_QUEUE, + .cdw10 = TEST_SEL << 8 | NVME_FEAT_FID_CTRL_DATA_QUEUE, .cdw11 = TEST_CDQID, .data_len = sizeof(expected_data), .out_data = &expected_data, @@ -1549,8 +1538,8 @@ static void test_lm_get_features_ctrl_data_queue(void) arbitrary(&expected_data, sizeof(expected_data)); set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_lm_get_features_ctrl_data_queue(test_link, TEST_CDQID, &data, - &result); + err = nvme_lm_get_features_ctrl_data_queue(test_link, TEST_SEL, TEST_CDQID, + &data, &result); end_mock_cmds(); check(err == 0, "get features returned error %d, errno %m", err); check(result == TEST_RESULT, diff --git a/test/mi.c b/test/mi.c index 98dbe5f63..24904432c 100644 --- a/test/mi.c +++ b/test/mi.c @@ -962,7 +962,6 @@ static int test_admin_get_features_cb(struct nvme_mi_ep *ep, static void test_get_features_nodata(nvme_mi_ep_t ep) { - struct nvme_get_features_args args = { 0 }; nvme_link_t link; uint32_t res; int rc; @@ -972,20 +971,14 @@ static void test_get_features_nodata(nvme_mi_ep_t ep) link = nvme_mi_init_link(ep, 5); assert(link); - args.args_size = sizeof(args); - args.fid = NVME_FEAT_FID_ARBITRATION; - args.sel = 0; - args.result = &res; - - rc = nvme_get_features(link, &args); + rc = nvme_get_features(link, NVME_NSID_NONE, NVME_FEAT_FID_ARBITRATION, + 0, 0, NVME_UUID_NONE, NULL, 0, &res); assert(rc == 0); - assert(args.data_len == 0); assert(res == 0x04030201); } static void test_get_features_data(nvme_mi_ep_t ep) { - struct nvme_get_features_args args = { 0 }; struct nvme_timestamp tstamp; nvme_link_t link; uint8_t exp[6]; @@ -997,20 +990,13 @@ static void test_get_features_data(nvme_mi_ep_t ep) link = nvme_mi_init_link(ep, 5); assert(link); - args.args_size = sizeof(args); - args.fid = NVME_FEAT_FID_TIMESTAMP; - args.sel = 0; - args.result = &res; - args.data = &tstamp; - args.data_len = sizeof(tstamp); - /* expected timestamp value */ for (i = 0; i < sizeof(tstamp.timestamp); i++) exp[i] = i; - rc = nvme_get_features(link, &args); + rc = nvme_get_features(link, NVME_NSID_NONE, NVME_FEAT_FID_TIMESTAMP, + 0, 0, NVME_UUID_NONE, &tstamp, sizeof(tstamp), &res); assert(rc == 0); - assert(args.data_len == sizeof(tstamp)); assert(tstamp.attr == 1); assert(!memcmp(tstamp.timestamp, exp, sizeof(tstamp.timestamp))); } From 3c347af22a15cc8edcdbe13ba34f537c34bf5525 Mon Sep 17 00:00:00 2001 From: Daniel Wagner Date: Fri, 5 Sep 2025 20:34:02 +0200 Subject: [PATCH 60/66] ioctl: remove unused enum features There is no user left of this type in ioctl.c. Remove it. Signed-off-by: Daniel Wagner --- src/nvme/ioctl.c | 55 ------------------------------------------------ 1 file changed, 55 deletions(-) diff --git a/src/nvme/ioctl.c b/src/nvme/ioctl.c index bb559c0b9..80ec86330 100644 --- a/src/nvme/ioctl.c +++ b/src/nvme/ioctl.c @@ -227,61 +227,6 @@ int nvme_admin_passthru(nvme_link_t l, __u8 opcode, __u8 flags, __u16 rsvd, metadata, timeout_ms, result); } -enum features { - NVME_FEATURES_ARBITRATION_BURST_SHIFT = 0, - NVME_FEATURES_ARBITRATION_LPW_SHIFT = 8, - NVME_FEATURES_ARBITRATION_MPW_SHIFT = 16, - NVME_FEATURES_ARBITRATION_HPW_SHIFT = 24, - NVME_FEATURES_ARBITRATION_BURST_MASK = 0x7, - NVME_FEATURES_ARBITRATION_LPW_MASK = 0xff, - NVME_FEATURES_ARBITRATION_MPW_MASK = 0xff, - NVME_FEATURES_ARBITRATION_HPW_MASK = 0xff, - NVME_FEATURES_PWRMGMT_PS_SHIFT = 0, - NVME_FEATURES_PWRMGMT_WH_SHIFT = 5, - NVME_FEATURES_PWRMGMT_PS_MASK = 0x1f, - NVME_FEATURES_PWRMGMT_WH_MASK = 0x7, - NVME_FEATURES_TMPTH_SHIFT = 0, - NVME_FEATURES_TMPSEL_SHIFT = 16, - NVME_FEATURES_THSEL_SHIFT = 20, - NVME_FEATURES_TMPTH_MASK = 0xff, - NVME_FEATURES_TMPSEL_MASK = 0xf, - NVME_FEATURES_THSEL_MASK = 0x3, - NVME_FEATURES_ERROR_RECOVERY_TLER_SHIFT = 0, - NVME_FEATURES_ERROR_RECOVERY_DULBE_SHIFT = 16, - NVME_FEATURES_ERROR_RECOVERY_TLER_MASK = 0xff, - NVME_FEATURES_ERROR_RECOVERY_DULBE_MASK = 0x1, - NVME_FEATURES_VWC_WCE_SHIFT = 0, - NVME_FEATURES_VWC_WCE_MASK = 0x1, - NVME_FEATURES_IRQC_THR_SHIFT = 0, - NVME_FEATURES_IRQC_TIME_SHIFT = 8, - NVME_FEATURES_IRQC_THR_MASK = 0xff, - NVME_FEATURES_IRQC_TIME_MASK = 0xff, - NVME_FEATURES_IVC_IV_SHIFT = 0, - NVME_FEATURES_IVC_CD_SHIFT = 16, - NVME_FEATURES_IVC_IV_MASK = 0xffff, - NVME_FEATURES_IVC_CD_MASK = 0x1, - NVME_FEATURES_WAN_DN_SHIFT = 0, - NVME_FEATURES_WAN_DN_MASK = 0x1, - NVME_FEATURES_APST_APSTE_SHIFT = 0, - NVME_FEATURES_APST_APSTE_MASK = 0x1, - NVME_FEATURES_HCTM_TMT2_SHIFT = 0, - NVME_FEATURES_HCTM_TMT1_SHIFT = 16, - NVME_FEATURES_HCTM_TMT2_MASK = 0xffff, - NVME_FEATURES_HCTM_TMT1_MASK = 0xffff, - NVME_FEATURES_NOPS_NOPPME_SHIFT = 0, - NVME_FEATURES_NOPS_NOPPME_MASK = 0x1, - NVME_FEATURES_PLM_PLE_SHIFT = 0, - NVME_FEATURES_PLM_PLE_MASK = 0x1, - NVME_FEATURES_PLM_WINDOW_SELECT_SHIFT = 0, - NVME_FEATURES_PLM_WINDOW_SELECT_MASK = 0xf, - NVME_FEATURES_LBAS_LSIRI_SHIFT = 0, - NVME_FEATURES_LBAS_LSIPI_SHIFT = 16, - NVME_FEATURES_LBAS_LSIRI_MASK = 0xffff, - NVME_FEATURES_LBAS_LSIPI_MASK = 0xffff, - NVME_FEATURES_IOCSP_IOCSCI_SHIFT = 0, - NVME_FEATURES_IOCSP_IOCSCI_MASK = 0xff, -}; - static bool force_4k; __attribute__((constructor)) From 861d7b26ae36d157a53fb400dd3ce659a07d5264 Mon Sep 17 00:00:00 2001 From: Tokunori Ikegami Date: Thu, 4 Sep 2025 08:18:23 +0900 Subject: [PATCH 61/66] ioctl: refactor nvme_get_log_partial uring This is to maintain nvme_get_log_partial easily. Signed-off-by: Tokunori Ikegami --- src/nvme/ioctl.c | 62 +++++++++++++++++++++++++++++------------------- 1 file changed, 38 insertions(+), 24 deletions(-) diff --git a/src/nvme/ioctl.c b/src/nvme/ioctl.c index 80ec86330..da506c11c 100644 --- a/src/nvme/ioctl.c +++ b/src/nvme/ioctl.c @@ -328,7 +328,18 @@ static int nvme_uring_cmd_wait_complete(struct io_uring *ring, int n) return ret; } -#endif + +static bool nvme_uring_is_usable(nvme_link_t l) +{ + struct stat st; + + if (io_uring_kernel_support != IO_URING_AVAILABLE || l->type != NVME_LINK_TYPE_DIRECT || + fstat(l->fd, &st) || !S_ISCHR(st.st_mode)) + return false; + + return true; +} +#endif /* CONFIG_LIBURING */ int nvme_get_log_partial(nvme_link_t l, struct nvme_passthru_cmd *cmd, __u64 lpo, void *log, __u32 len, @@ -345,26 +356,21 @@ int nvme_get_log_partial(nvme_link_t l, struct nvme_passthru_cmd *cmd, __u32 cdw10 = cmd->cdw10 & (NVME_VAL(LOG_CDW10_LID) | NVME_VAL(LOG_CDW10_LSP)); __u32 cdw11 = cmd->cdw11 & NVME_VAL(LOG_CDW11_LSI); - - if (force_4k) - xfer_len = NVME_LOG_PAGE_PDU_SIZE; - #ifdef CONFIG_LIBURING - int n = 0; + bool use_uring = nvme_uring_is_usable(l); struct io_uring ring; - struct stat st; - bool use_uring = false; - - if (io_uring_kernel_support == IO_URING_AVAILABLE && l->type == NVME_LINK_TYPE_DIRECT) { - if (fstat(l->fd, &st) == 0 && S_ISCHR(st.st_mode)) { - use_uring = true; + int n = 0; - ret = nvme_uring_cmd_setup(&ring); - if (ret) - return ret; - } + if (use_uring) { + ret = nvme_uring_cmd_setup(&ring); + if (ret) + return ret; } -#endif +#endif /* CONFIG_LIBURING */ + + if (force_4k) + xfer_len = NVME_LOG_PAGE_PDU_SIZE; + /* * 4k is the smallest possible transfer unit, so restricting to 4k * avoids having to check the MDTS value of the controller. @@ -398,10 +404,11 @@ int nvme_get_log_partial(nvme_link_t l, struct nvme_passthru_cmd *cmd, cmd->cdw13 = lpo >> 32; cmd->data_len = xfer; cmd->addr = (__u64)(uintptr_t)ptr; + #ifdef CONFIG_LIBURING - if (io_uring_kernel_support == IO_URING_AVAILABLE && use_uring) { + if (use_uring) { if (n >= NVME_URING_ENTRIES) { - ret = nvme_uring_cmd_wait_complete(&ring, n); + nvme_uring_cmd_wait_complete(&ring, n); n = 0; } n += 1; @@ -409,9 +416,15 @@ int nvme_get_log_partial(nvme_link_t l, struct nvme_passthru_cmd *cmd, if (ret) nvme_uring_cmd_exit(&ring); - } else -#endif + } else { + ret = nvme_submit_admin_passthru(l, cmd, result); + if (ret) + return ret; + } +#else /* CONFIG_LIBURING */ ret = nvme_submit_admin_passthru(l, cmd, result); +#endif /* CONFIG_LIBURING */ + if (ret) return ret; @@ -420,13 +433,14 @@ int nvme_get_log_partial(nvme_link_t l, struct nvme_passthru_cmd *cmd, } while (offset < data_len); #ifdef CONFIG_LIBURING - if (io_uring_kernel_support == IO_URING_AVAILABLE && use_uring) { - ret = nvme_uring_cmd_wait_complete(&ring, n); + if (use_uring) { + nvme_uring_cmd_wait_complete(&ring, n); nvme_uring_cmd_exit(&ring); if (ret) return ret; } -#endif +#endif /* CONFIG_LIBURING */ + return 0; } From 4a44ef65c67b1c62b589046085778849d67dd3b8 Mon Sep 17 00:00:00 2001 From: Tokunori Ikegami Date: Wed, 20 Aug 2025 00:29:09 +0900 Subject: [PATCH 62/66] test/zns: fix kernel-doc-check warnings Since the following warnings output. $ ./scripts/kernel-doc-check test/zns.c test/zns.c:3: warning: This comment starts with '/**', but isn't a kernel-doc comment. Refer Documentation/doc-guide/kernel-doc.rst test/zns.c:10: warning: This comment starts with '/**', but isn't a kernel-doc comment. Refer Documentation/doc-guide/kernel-doc.rst Signed-off-by: Tokunori Ikegami --- test/zns.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/zns.c b/test/zns.c index 46e73294e..742a7297d 100644 --- a/test/zns.c +++ b/test/zns.c @@ -1,12 +1,12 @@ // SPDX-License-Identifier: LGPL-2.1-or-later -/** +/* * This file is part of libnvme. * Copyright (c) 2020 Western Digital Corporation or its affiliates. * * Authors: Keith Busch */ -/** +/* * Search out for ZNS type namespaces, and if found, report their properties. */ #include From ec2a1bc49f27acbcbfb56221728a3887de3bcce3 Mon Sep 17 00:00:00 2001 From: Tokunori Ikegami Date: Tue, 26 Aug 2025 01:50:31 +0900 Subject: [PATCH 63/66] examples: fix mi-mctp.c kernel-doc-check warning examples/mi-mctp.c:3: warning: This comment starts with '/**', but isn't a kernel-doc comment. Refer Documentation/doc-guide/kernel-doc.rst Signed-off-by: Tokunori Ikegami --- examples/mi-mctp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/mi-mctp.c b/examples/mi-mctp.c index c12f892b5..107592234 100644 --- a/examples/mi-mctp.c +++ b/examples/mi-mctp.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: LGPL-2.1-or-later -/** +/* * This file is part of libnvme. * Copyright (c) 2021 Code Construct Pty Ltd. * From 490db9c4878df1a1e0f46f193ae0d7fd045a31a1 Mon Sep 17 00:00:00 2001 From: Tokunori Ikegami Date: Tue, 2 Sep 2025 23:46:42 +0900 Subject: [PATCH 64/66] examples: do not use "/**" opening comment mark Since checked by kernel-doc-check then the warning message output. Signed-off-by: Tokunori Ikegami --- examples/discover-loop.c | 4 ++-- examples/display-columnar.c | 4 ++-- examples/display-tree.c | 4 ++-- examples/mi-conf.c | 4 ++-- examples/mi-mctp-ae.c | 4 ++-- examples/mi-mctp-csi-test.c | 4 ++-- examples/mi-mctp.c | 2 +- examples/telemetry-listen.c | 4 ++-- 8 files changed, 15 insertions(+), 15 deletions(-) diff --git a/examples/discover-loop.c b/examples/discover-loop.c index e6eeb387b..658a9ecbe 100644 --- a/examples/discover-loop.c +++ b/examples/discover-loop.c @@ -1,12 +1,12 @@ // SPDX-License-Identifier: LGPL-2.1-or-later -/** +/* * This file is part of libnvme. * Copyright (c) 2020 Western Digital Corporation or its affiliates. * * Authors: Keith Busch */ -/** +/* * discover-loop: Use fabrics commands to discover any loop targets and print * those records. You must have at least one configured nvme loop target on the * system (no existing connection required). The output will look more diff --git a/examples/display-columnar.c b/examples/display-columnar.c index baf67fedc..1c356bf48 100644 --- a/examples/display-columnar.c +++ b/examples/display-columnar.c @@ -1,12 +1,12 @@ // SPDX-License-Identifier: LGPL-2.1-or-later -/** +/* * This file is part of libnvme. * Copyright (c) 2020 Western Digital Corporation or its affiliates. * * Authors: Keith Busch */ -/** +/* * display-columnar: Scans the nvme topology, prints each record type in a * column format for easy visual scanning. */ diff --git a/examples/display-tree.c b/examples/display-tree.c index 74bb9ff58..4cab82e5c 100644 --- a/examples/display-tree.c +++ b/examples/display-tree.c @@ -1,12 +1,12 @@ // SPDX-License-Identifier: LGPL-2.1-or-later -/** +/* * This file is part of libnvme. * Copyright (c) 2020 Western Digital Corporation or its affiliates. * * Authors: Keith Busch */ -/** +/* * display-tree: Scans the nvme topology, prints as an ascii tree with some * selected attributes for each component. */ diff --git a/examples/mi-conf.c b/examples/mi-conf.c index e47d281f3..c9311e77a 100644 --- a/examples/mi-conf.c +++ b/examples/mi-conf.c @@ -1,12 +1,12 @@ // SPDX-License-Identifier: LGPL-2.1-or-later -/** +/* * This file is part of libnvme. * Copyright (c) 2022 Code Construct Pty Ltd. * * Authors: Jeremy Kerr */ -/** +/* * mi-conf: query a device for optimal MTU and set for both the local MCTP * route (through dbus to mctpd) and the device itself (through NVMe-MI * configuration commands) diff --git a/examples/mi-mctp-ae.c b/examples/mi-mctp-ae.c index 89e1e3172..b1ecc554a 100644 --- a/examples/mi-mctp-ae.c +++ b/examples/mi-mctp-ae.c @@ -1,9 +1,9 @@ // SPDX-License-Identifier: LGPL-2.1-or-later -/** +/* * This file is part of libnvme. */ -/** +/* * mi-mctp-ae: open a MI connection over MCTP, supporting asynchronous event messages */ diff --git a/examples/mi-mctp-csi-test.c b/examples/mi-mctp-csi-test.c index 0f4bdf092..d18b9b1ee 100644 --- a/examples/mi-mctp-csi-test.c +++ b/examples/mi-mctp-csi-test.c @@ -1,9 +1,9 @@ // SPDX-License-Identifier: LGPL-2.1-or-later -/** +/* * This file is part of libnvme. */ -/** +/* * mi-mctp-csi-test: open a MI connection over MCTP, and send two commands * in parallel with different CSI buffers */ diff --git a/examples/mi-mctp.c b/examples/mi-mctp.c index 107592234..1342b80b3 100644 --- a/examples/mi-mctp.c +++ b/examples/mi-mctp.c @@ -6,7 +6,7 @@ * Authors: Jeremy Kerr */ -/** +/* * mi-mctp: open a MI connection over MCTP, and query controller info */ diff --git a/examples/telemetry-listen.c b/examples/telemetry-listen.c index 2f892c9aa..15904cd4a 100644 --- a/examples/telemetry-listen.c +++ b/examples/telemetry-listen.c @@ -1,12 +1,12 @@ // SPDX-License-Identifier: LGPL-2.1-or-later -/** +/* * This file is part of libnvme. * Copyright (c) 2020 Western Digital Corporation or its affiliates. * * Authors: Keith Busch */ -/** +/* * Open all nvme controller's uevent and listen for changes. If NVME_AEN event * is observed with controller telemetry data, read the log and save it to a * file in /var/log/ with the device's unique name and epoch timestamp. From b911a1a7f10bdb59f729a39595ba4adb582e3c40 Mon Sep 17 00:00:00 2001 From: Tokunori Ikegami Date: Sun, 31 Aug 2025 21:42:55 +0900 Subject: [PATCH 65/66] test: fix mi.c kernel-doc-check warning To fix the warning message below. test/mi.c:3: warning: This comment starts with '/**', but isn't a kernel-doc comment. Refer Documentation/doc-guide/kernel-doc.rst Signed-off-by: Tokunori Ikegami --- test/mi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/mi.c b/test/mi.c index 24904432c..18f430532 100644 --- a/test/mi.c +++ b/test/mi.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: LGPL-2.1-or-later -/** +/* * This file is part of libnvme. * Copyright (c) 2022 Code Construct */ From f6436ae0a5aa645efc6cea15f4b4e1e9b172db1e Mon Sep 17 00:00:00 2001 From: Dennis Maisenbacher Date: Tue, 16 Sep 2025 15:16:27 +0200 Subject: [PATCH 66/66] ioctl: add return value for nvme_set_features_iocs_profile The spec specifies that this command returns the currently selected IOCSCI upon successful completion. Signed-off-by: Dennis Maisenbacher --- src/nvme/ioctl.h | 5 +++-- test/ioctl/features.c | 6 +++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/nvme/ioctl.h b/src/nvme/ioctl.h index 3d573ac15..5a6dceb5e 100644 --- a/src/nvme/ioctl.h +++ b/src/nvme/ioctl.h @@ -2951,17 +2951,18 @@ static inline int nvme_set_features_write_protect(nvme_link_t l, __u32 nsid, * @l: Link handle * @sv: Save value across power states * @iocsci: I/O Command Set Combination Index + * @result: The command completions result from CQE dword0 * * Return: 0 on success, the nvme command status if a response was * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline int nvme_set_features_iocs_profile(nvme_link_t l, bool sv, - __u16 iocsci) + __u16 iocsci, __u32 *result) { __u32 cdw11 = NVME_SET(iocsci, FEAT_IOCSP_IOCSCI); return __nvme_set_features(l, NVME_FEAT_FID_IOCS_PROFILE, - sv, cdw11, NULL); + sv, cdw11, result); } /** diff --git a/test/ioctl/features.c b/test/ioctl/features.c index a98e315fd..c8d741441 100644 --- a/test/ioctl/features.c +++ b/test/ioctl/features.c @@ -1128,13 +1128,17 @@ static void test_set_iocs_profile(void) .opcode = nvme_admin_set_features, .cdw10 = NVME_FEAT_FID_IOCS_PROFILE, .cdw11 = IOCSI, + .result = TEST_RESULT, }; + uint32_t result = 0; int err; set_mock_admin_cmds(&mock_admin_cmd, 1); - err = nvme_set_features_iocs_profile(test_link, false, IOCSI); + err = nvme_set_features_iocs_profile(test_link, false, IOCSI, &result); end_mock_cmds(); check(err == 0, "set features returned error %d", err); + check(result == TEST_RESULT, + "got result %" PRIu32 ", expected %" PRIu32, result, TEST_RESULT); } static void test_get_iocs_profile(void)