diff --git a/fabrics.c b/fabrics.c index a7bbd5a743..34a71a30cd 100644 --- a/fabrics.c +++ b/fabrics.c @@ -153,7 +153,7 @@ static void save_discovery_log(char *raw, struct nvmf_discovery_log *log) fd = open(raw, O_CREAT | O_RDWR | O_TRUNC, 0600); if (fd < 0) { - fprintf(stderr, "failed to open %s: %s\n", raw, nvme_strerror(errno)); + fprintf(stderr, "failed to open %s: %s\n", raw, libnvme_strerror(errno)); return; } @@ -162,7 +162,7 @@ static void save_discovery_log(char *raw, struct nvmf_discovery_log *log) ret = write(fd, log, len); if (ret < 0) fprintf(stderr, "failed to write to %s: %s\n", - raw, nvme_strerror(errno)); + raw, libnvme_strerror(errno)); else printf("Discovery log is saved to %s\n", raw); @@ -173,7 +173,7 @@ static int setup_common_context(struct nvmf_context *fctx, struct nvmf_args *fa); struct cb_fabrics_data { - struct nvme_fabrics_config *cfg; + struct libnvme_fabrics_config *cfg; nvme_print_flags_t flags; bool quiet; char *raw; @@ -185,7 +185,7 @@ static bool cb_decide_retry(struct nvmf_context *fctx, int err, void *user_data) { if (err == -EAGAIN || (err == -EINTR && !nvme_sigint_received)) { - print_debug("nvmf_add_ctrl returned '%s'\n", nvme_strerror(-err)); + print_debug("nvmf_add_ctrl returned '%s'\n", libnvme_strerror(-err)); return true; } @@ -193,7 +193,7 @@ static bool cb_decide_retry(struct nvmf_context *fctx, int err, } static void cb_connected(struct nvmf_context *fctx, - struct nvme_ctrl *c, void *user_data) + struct libnvme_ctrl *c, void *user_data) { struct cb_fabrics_data *cfd = user_data; @@ -201,7 +201,7 @@ static void cb_connected(struct nvmf_context *fctx, return; if (cfd->flags == NORMAL) { - printf("connecting to device: %s\n", nvme_ctrl_get_name(c)); + printf("connecting to device: %s\n", libnvme_ctrl_get_name(c)); return; } @@ -212,7 +212,7 @@ static void cb_connected(struct nvmf_context *fctx, root = json_create_object(); json_object_add_value_string(root, "device", - nvme_ctrl_get_name(c)); + libnvme_ctrl_get_name(c)); json_print_object(root, NULL); printf("\n"); @@ -222,7 +222,7 @@ static void cb_connected(struct nvmf_context *fctx, } static void cb_already_connected(struct nvmf_context *fctx, - struct nvme_host *host, const char *subsysnqn, + struct libnvme_host *host, const char *subsysnqn, const char *transport, const char *traddr, const char *trsvcid, void *user_data) { @@ -230,7 +230,7 @@ static void cb_already_connected(struct nvmf_context *fctx, return; fprintf(stderr, "already connected to hostnqn=%s,nqn=%s,transport=%s,traddr=%s,trsvcid=%s\n", - nvme_host_get_hostnqn(host), subsysnqn, + libnvme_host_get_hostnqn(host), subsysnqn, transport, traddr, trsvcid); } @@ -276,7 +276,7 @@ static void cb_parser_cleanup(struct nvmf_context *fctx, void *user_data) static int cb_parser_next_line(struct nvmf_context *fctx, void *user_data) { struct cb_fabrics_data *cfd = user_data; - struct nvme_fabrics_config cfg; + struct libnvme_fabrics_config cfg; struct nvmf_args fa = {}; char *ptr, *p, line[4096]; int argc, ret = 0; @@ -348,9 +348,9 @@ static int setup_common_context(struct nvmf_context *fctx, return 0; } -static int create_common_context(struct nvme_global_ctx *ctx, +static int create_common_context(struct libnvme_global_ctx *ctx, bool persistent, struct nvmf_args *fa, - struct nvme_fabrics_config *cfg, + struct libnvme_fabrics_config *cfg, void *user_data, struct nvmf_context **fctxp) { struct nvmf_context *fctx; @@ -393,10 +393,10 @@ static int create_common_context(struct nvme_global_ctx *ctx, return err; } -static int create_discovery_context(struct nvme_global_ctx *ctx, +static int create_discovery_context(struct libnvme_global_ctx *ctx, bool persistent, const char *device, struct nvmf_args *fa, - struct nvme_fabrics_config *cfg, + struct libnvme_fabrics_config *cfg, void *user_data, struct nvmf_context **fctxp) { struct nvmf_context *fctx; @@ -429,7 +429,7 @@ static int create_discovery_context(struct nvme_global_ctx *ctx, return err; } -static int nvme_read_volatile_config(struct nvme_global_ctx *ctx) +static int nvme_read_volatile_config(struct libnvme_global_ctx *ctx) { char *filename, *ext; struct dirent *dir; @@ -453,7 +453,7 @@ static int nvme_read_volatile_config(struct nvme_global_ctx *ctx) break; } - if (nvme_read_config(ctx, filename)) + if (libnvme_read_config(ctx, filename)) ret = 0; free(filename); @@ -463,13 +463,13 @@ static int nvme_read_volatile_config(struct nvme_global_ctx *ctx) return ret; } -static int nvme_read_config_checked(struct nvme_global_ctx *ctx, +static int nvme_read_config_checked(struct libnvme_global_ctx *ctx, const char *filename) { if (access(filename, F_OK)) return -errno; - return nvme_read_config(ctx, filename); + return libnvme_read_config(ctx, filename); } #define NBFT_SYSFS_PATH "/sys/firmware/acpi/tables" @@ -479,10 +479,10 @@ int fabrics_discovery(const char *desc, int argc, char **argv, bool connect) char *config_file = PATH_NVMF_CONFIG; char *context = NULL; nvme_print_flags_t flags; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; _cleanup_nvmf_context_ struct nvmf_context *fctx = NULL; int ret; - struct nvme_fabrics_config cfg; + struct libnvme_fabrics_config cfg; struct nvmf_args fa = { .subsysnqn = NVME_DISC_SUBSYS_NAME }; char *device = NULL; bool force = false; @@ -520,25 +520,25 @@ int fabrics_discovery(const char *desc, int argc, char **argv, bool connect) log_level = map_log_level(nvme_args.verbose, quiet); - ctx = nvme_create_global_ctx(stderr, log_level); + ctx = libnvme_create_global_ctx(stderr, log_level); if (!ctx) { fprintf(stderr, "Failed to create topology root: %s\n", - nvme_strerror(errno)); + libnvme_strerror(errno)); return -ENOMEM; } if (context) - nvme_set_application(ctx, context); + libnvme_set_application(ctx, context); if (!nvme_read_config_checked(ctx, config_file)) json_config = true; if (!nvme_read_volatile_config(ctx)) json_config = true; - nvme_skip_namespaces(ctx); - ret = nvme_scan_topology(ctx, NULL, NULL); + libnvme_skip_namespaces(ctx); + ret = libnvme_scan_topology(ctx, NULL, NULL); if (ret < 0) { fprintf(stderr, "Failed to scan topology: %s\n", - nvme_strerror(-ret)); + libnvme_strerror(-ret)); return ret; } @@ -580,7 +580,7 @@ int fabrics_discovery(const char *desc, int argc, char **argv, bool connect) out_free: if (dump_config) - nvme_dump_config(ctx, STDOUT_FILENO); + libnvme_dump_config(ctx, STDOUT_FILENO); return ret; } @@ -591,12 +591,12 @@ int fabrics_connect(const char *desc, int argc, char **argv) _cleanup_free_ char *hid = NULL; char *config_file = NULL; char *context = NULL; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; _cleanup_nvmf_context_ struct nvmf_context *fctx = NULL; - _cleanup_nvme_ctrl_ nvme_ctrl_t c = NULL; + _cleanup_nvme_ctrl_ libnvme_ctrl_t c = NULL; int ret; nvme_print_flags_t flags; - struct nvme_fabrics_config cfg = { 0 }; + struct libnvme_fabrics_config cfg = { 0 }; struct nvmf_args fa = { 0 }; NVMF_ARGS(opts, fa, cfg, @@ -643,23 +643,23 @@ int fabrics_connect(const char *desc, int argc, char **argv) do_connect: log_level = map_log_level(nvme_args.verbose, quiet); - ctx = nvme_create_global_ctx(stderr, log_level); + ctx = libnvme_create_global_ctx(stderr, log_level); if (!ctx) { fprintf(stderr, "Failed to create topology root: %s\n", - nvme_strerror(errno)); + libnvme_strerror(errno)); return -ENOMEM; } if (context) - nvme_set_application(ctx, context); + libnvme_set_application(ctx, context); - nvme_read_config(ctx, config_file); + libnvme_read_config(ctx, config_file); nvme_read_volatile_config(ctx); - nvme_skip_namespaces(ctx); - ret = nvme_scan_topology(ctx, NULL, NULL); + libnvme_skip_namespaces(ctx); + ret = libnvme_scan_topology(ctx, NULL, NULL); if (ret < 0) { fprintf(stderr, "Failed to scan topology: %s\n", - nvme_strerror(-ret)); + libnvme_strerror(-ret)); return ret; } @@ -679,27 +679,27 @@ int fabrics_connect(const char *desc, int argc, char **argv) ret = nvmf_connect(ctx, fctx); if (ret) { fprintf(stderr, "failed to connect: %s\n", - nvme_strerror(-ret)); + libnvme_strerror(-ret)); return ret; } if (dump_config) - nvme_dump_config(ctx, STDOUT_FILENO); + libnvme_dump_config(ctx, STDOUT_FILENO); return 0; } -static nvme_ctrl_t lookup_nvme_ctrl(struct nvme_global_ctx *ctx, +static libnvme_ctrl_t lookup_nvme_ctrl(struct libnvme_global_ctx *ctx, const char *name) { - nvme_host_t h; - nvme_subsystem_t s; - nvme_ctrl_t c; - - nvme_for_each_host(ctx, h) { - nvme_for_each_subsystem(h, s) { - nvme_subsystem_for_each_ctrl(s, c) { - if (!strcmp(nvme_ctrl_get_name(c), name)) + libnvme_host_t h; + libnvme_subsystem_t s; + libnvme_ctrl_t c; + + libnvme_for_each_host(ctx, h) { + libnvme_for_each_subsystem(h, s) { + libnvme_subsystem_for_each_ctrl(s, c) { + if (!strcmp(libnvme_ctrl_get_name(c), name)) return c; } } @@ -707,24 +707,24 @@ static nvme_ctrl_t lookup_nvme_ctrl(struct nvme_global_ctx *ctx, return NULL; } -static void nvmf_disconnect_nqn(struct nvme_global_ctx *ctx, char *nqn) +static void nvmf_disconnect_nqn(struct libnvme_global_ctx *ctx, char *nqn) { int i = 0; char *n = nqn; char *p; - nvme_host_t h; - nvme_subsystem_t s; - nvme_ctrl_t c; + libnvme_host_t h; + libnvme_subsystem_t s; + libnvme_ctrl_t c; while ((p = strsep(&n, ",")) != NULL) { if (!strlen(p)) continue; - nvme_for_each_host(ctx, h) { - nvme_for_each_subsystem(h, s) { - if (strcmp(nvme_subsystem_get_subsysnqn(s), p)) + libnvme_for_each_host(ctx, h) { + libnvme_for_each_subsystem(h, s) { + if (strcmp(libnvme_subsystem_get_subsysnqn(s), p)) continue; - nvme_subsystem_for_each_ctrl(s, c) { - if (!nvme_disconnect_ctrl(c)) + libnvme_subsystem_for_each_ctrl(s, c) { + if (!libnvme_disconnect_ctrl(c)) i++; } } @@ -736,8 +736,8 @@ static void nvmf_disconnect_nqn(struct nvme_global_ctx *ctx, char *nqn) int fabrics_disconnect(const char *desc, int argc, char **argv) { const char *device = "nvme device handle"; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - nvme_ctrl_t c; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + libnvme_ctrl_t c; char *p; int ret; @@ -769,14 +769,14 @@ int fabrics_disconnect(const char *desc, int argc, char **argv) log_level = map_log_level(nvme_args.verbose, false); - ctx = nvme_create_global_ctx(stderr, log_level); + ctx = libnvme_create_global_ctx(stderr, log_level); if (!ctx) { fprintf(stderr, "Failed to create topology root: %s\n", - nvme_strerror(errno)); + libnvme_strerror(errno)); return -ENOMEM; } - nvme_skip_namespaces(ctx); - ret = nvme_scan_topology(ctx, NULL, NULL); + libnvme_skip_namespaces(ctx); + ret = libnvme_scan_topology(ctx, NULL, NULL); if (ret < 0) { /* * Do not report an error when the modules are not @@ -787,7 +787,7 @@ int fabrics_disconnect(const char *desc, int argc, char **argv) return 0; fprintf(stderr, "Failed to scan topology: %s\n", - nvme_strerror(-ret)); + libnvme_strerror(-ret)); return ret; } @@ -807,11 +807,11 @@ int fabrics_disconnect(const char *desc, int argc, char **argv) "Did not find device %s\n", p); return -ENODEV; } - ret = nvme_disconnect_ctrl(c); + ret = libnvme_disconnect_ctrl(c); if (ret) fprintf(stderr, "Failed to disconnect %s: %s\n", - p, nvme_strerror(-ret)); + p, libnvme_strerror(-ret)); } } @@ -820,10 +820,10 @@ int fabrics_disconnect(const char *desc, int argc, char **argv) int fabrics_disconnect_all(const char *desc, int argc, char **argv) { - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - nvme_host_t h; - nvme_subsystem_t s; - nvme_ctrl_t c; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + libnvme_host_t h; + libnvme_subsystem_t s; + libnvme_ctrl_t c; int ret; struct config { @@ -841,14 +841,14 @@ int fabrics_disconnect_all(const char *desc, int argc, char **argv) log_level = map_log_level(nvme_args.verbose, false); - ctx = nvme_create_global_ctx(stderr, log_level); + ctx = libnvme_create_global_ctx(stderr, log_level); if (!ctx) { fprintf(stderr, "Failed to create topology root: %s\n", - nvme_strerror(errno)); + libnvme_strerror(errno)); return -ENOMEM; } - nvme_skip_namespaces(ctx); - ret = nvme_scan_topology(ctx, NULL, NULL); + libnvme_skip_namespaces(ctx); + ret = libnvme_scan_topology(ctx, NULL, NULL); if (ret < 0) { /* * Do not report an error when the modules are not @@ -859,24 +859,24 @@ int fabrics_disconnect_all(const char *desc, int argc, char **argv) return 0; fprintf(stderr, "Failed to scan topology: %s\n", - nvme_strerror(-ret)); + libnvme_strerror(-ret)); return ret; } - nvme_for_each_host(ctx, h) { - nvme_for_each_subsystem(h, s) { - nvme_subsystem_for_each_ctrl(s, c) { + libnvme_for_each_host(ctx, h) { + libnvme_for_each_subsystem(h, s) { + libnvme_subsystem_for_each_ctrl(s, c) { if (cfg.transport && strcmp(cfg.transport, - nvme_ctrl_get_transport(c))) + libnvme_ctrl_get_transport(c))) continue; - else if (!strcmp(nvme_ctrl_get_transport(c), + else if (!strcmp(libnvme_ctrl_get_transport(c), "pcie")) continue; - if (nvme_disconnect_ctrl(c)) + if (libnvme_disconnect_ctrl(c)) fprintf(stderr, "failed to disconnect %s\n", - nvme_ctrl_get_name(c)); + libnvme_ctrl_get_name(c)); } } } @@ -887,9 +887,9 @@ int fabrics_disconnect_all(const char *desc, int argc, char **argv) int fabrics_config(const char *desc, int argc, char **argv) { bool scan_tree = false, modify_config = false, update_config = false; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; char *config_file = PATH_NVMF_CONFIG; - struct nvme_fabrics_config cfg; + struct libnvme_fabrics_config cfg; struct nvmf_args fa = { }; int ret; @@ -911,21 +911,21 @@ int fabrics_config(const char *desc, int argc, char **argv) log_level = map_log_level(nvme_args.verbose, quiet); - ctx = nvme_create_global_ctx(stderr, log_level); + ctx = libnvme_create_global_ctx(stderr, log_level); if (!ctx) { fprintf(stderr, "Failed to create topology root: %s\n", - nvme_strerror(errno)); + libnvme_strerror(errno)); return -ENOMEM; } - nvme_read_config(ctx, config_file); + libnvme_read_config(ctx, config_file); if (scan_tree) { - nvme_skip_namespaces(ctx); - ret = nvme_scan_topology(ctx, NULL, NULL); + libnvme_skip_namespaces(ctx); + ret = libnvme_scan_topology(ctx, NULL, NULL); if (ret < 0) { fprintf(stderr, "Failed to scan topology: %s\n", - nvme_strerror(-ret)); + libnvme_strerror(-ret)); return -ret; } } @@ -962,16 +962,16 @@ int fabrics_config(const char *desc, int argc, char **argv) fd = open(config_file, O_RDONLY, 0); if (fd != -1) - nvme_dump_config(ctx, fd); + libnvme_dump_config(ctx, fd); } if (dump_config) - nvme_dump_config(ctx, STDOUT_FILENO); + libnvme_dump_config(ctx, STDOUT_FILENO); return 0; } -static int dim_operation(nvme_ctrl_t c, enum nvmf_dim_tas tas, const char *name) +static int dim_operation(libnvme_ctrl_t c, enum nvmf_dim_tas tas, const char *name) { static const char * const task[] = { [NVMF_DIM_TAS_REGISTER] = "register", @@ -987,20 +987,20 @@ static int dim_operation(nvme_ctrl_t c, enum nvmf_dim_tas tas, const char *name) printf("%s DIM %s command success\n", name, t); } else if (status < NVME_SC_SUCCESS) { fprintf(stderr, "%s DIM %s command error. Status:0x%04x - %s\n", - name, t, status, nvme_status_to_string(status, false)); + name, t, status, libnvme_status_to_string(status, false)); } else { fprintf(stderr, "%s DIM %s command error. Result:0x%04x, Status:0x%04x - %s\n", - name, t, result, status, nvme_status_to_string(status, false)); + name, t, result, status, libnvme_status_to_string(status, false)); } - return nvme_status_to_errno(status, true); + return libnvme_status_to_errno(status, true); } int fabrics_dim(const char *desc, int argc, char **argv) { - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; enum nvmf_dim_tas tas; - nvme_ctrl_t c; + libnvme_ctrl_t c; char *p; int ret; @@ -1043,33 +1043,33 @@ int fabrics_dim(const char *desc, int argc, char **argv) log_level = map_log_level(nvme_args.verbose, false); - ctx = nvme_create_global_ctx(stderr, log_level); + ctx = libnvme_create_global_ctx(stderr, log_level); if (!ctx) { fprintf(stderr, "Failed to create topology root: %s\n", - nvme_strerror(errno)); + libnvme_strerror(errno)); return -ENODEV; } - nvme_skip_namespaces(ctx); - ret = nvme_scan_topology(ctx, NULL, NULL); + libnvme_skip_namespaces(ctx); + ret = libnvme_scan_topology(ctx, NULL, NULL); if (ret < 0) { fprintf(stderr, "Failed to scan topology: %s\n", - nvme_strerror(-ret)); + libnvme_strerror(-ret)); return ret; } if (cfg.nqn) { - nvme_host_t h; - nvme_subsystem_t s; + libnvme_host_t h; + libnvme_subsystem_t s; char *n = cfg.nqn; while ((p = strsep(&n, ",")) != NULL) { if (!strlen(p)) continue; - nvme_for_each_host(ctx, h) { - nvme_for_each_subsystem(h, s) { - if (strcmp(nvme_subsystem_get_subsysnqn(s), p)) + libnvme_for_each_host(ctx, h) { + libnvme_for_each_subsystem(h, s) { + if (strcmp(libnvme_subsystem_get_subsysnqn(s), p)) continue; - nvme_subsystem_for_each_ctrl(s, c) + libnvme_subsystem_for_each_ctrl(s, c) ret = dim_operation(c, tas, p); } } @@ -1082,11 +1082,11 @@ int fabrics_dim(const char *desc, int argc, char **argv) while ((p = strsep(&d, ",")) != NULL) { if (!strncmp(p, "/dev/", 5)) p += 5; - ret = nvme_scan_ctrl(ctx, p, &c); + ret = libnvme_scan_ctrl(ctx, p, &c); if (ret) { fprintf(stderr, "Did not find device %s: %s\n", - p, nvme_strerror(ret)); + p, libnvme_strerror(ret)); return ret; } ret = dim_operation(c, tas, p); diff --git a/libnvme/examples/discover-loop.c b/libnvme/examples/discover-loop.c index f1369e8a0d..1083e427bb 100644 --- a/libnvme/examples/discover-loop.c +++ b/libnvme/examples/discover-loop.c @@ -52,29 +52,29 @@ static void print_discover_log(struct nvmf_discovery_log *log) int main() { struct nvmf_discovery_log *log; - struct nvme_global_ctx *ctx; - nvme_host_t h; - nvme_ctrl_t c; + struct libnvme_global_ctx *ctx; + libnvme_host_t h; + libnvme_ctrl_t c; int ret; - struct nvme_fabrics_config cfg; + struct libnvme_fabrics_config cfg; nvmf_default_config(&cfg); - ctx = nvme_create_global_ctx(stdout, DEFAULT_LOGLEVEL); + ctx = libnvme_create_global_ctx(stdout, DEFAULT_LOGLEVEL); if (!ctx) return 1; - ret = nvme_scan_topology(ctx, NULL, NULL); + ret = libnvme_scan_topology(ctx, NULL, NULL); if (ret) { - nvme_free_global_ctx(ctx); + libnvme_free_global_ctx(ctx); return 1; } - ret = nvme_get_host(ctx, NULL, NULL, &h); + ret = libnvme_get_host(ctx, NULL, NULL, &h); if (ret) { fprintf(stderr, "Failed to allocated memory\n"); return 1; } - ret = nvme_create_ctrl(ctx, NVME_DISC_SUBSYS_NAME, "loop", + ret = libnvme_create_ctrl(ctx, NVME_DISC_SUBSYS_NAME, "loop", NULL, NULL, NULL, NULL, &c); if (ret) { fprintf(stderr, "Failed to allocate memory\n"); @@ -87,15 +87,15 @@ int main() } ret = nvmf_get_discovery_log(c, &log, 4); - nvme_disconnect_ctrl(c); - nvme_free_ctrl(c); + libnvme_disconnect_ctrl(c); + libnvme_free_ctrl(c); if (ret) fprintf(stderr, "nvmf-discover-log:%x\n", ret); else print_discover_log(log); - nvme_free_global_ctx(ctx); + libnvme_free_global_ctx(ctx); free(log); return 0; } diff --git a/libnvme/examples/display-columnar.c b/libnvme/examples/display-columnar.c index ab6d9e672f..c6753eee40 100644 --- a/libnvme/examples/display-columnar.c +++ b/libnvme/examples/display-columnar.c @@ -17,36 +17,36 @@ static const char dash[101] = {[0 ... 99] = '-'}; int main() { - struct nvme_global_ctx *ctx; - nvme_host_t h; - nvme_subsystem_t s; - nvme_ctrl_t c; - nvme_path_t p; - nvme_ns_t n; + struct libnvme_global_ctx *ctx; + libnvme_host_t h; + libnvme_subsystem_t s; + libnvme_ctrl_t c; + libnvme_path_t p; + libnvme_ns_t n; int err; - ctx = nvme_create_global_ctx(stdout, DEFAULT_LOGLEVEL); + ctx = libnvme_create_global_ctx(stdout, DEFAULT_LOGLEVEL); if (!ctx) return 1; - err = nvme_scan_topology(ctx, NULL, NULL); + err = libnvme_scan_topology(ctx, NULL, NULL); if (err) { - nvme_free_global_ctx(ctx); + libnvme_free_global_ctx(ctx); return 1; } printf("%-16s %-96s %-.16s\n", "Subsystem", "Subsystem-NQN", "Controllers"); printf("%-.16s %-.96s %-.16s\n", dash, dash, dash); - nvme_for_each_host(ctx, h) { - nvme_for_each_subsystem(h, s) { + libnvme_for_each_host(ctx, h) { + libnvme_for_each_subsystem(h, s) { bool first = true; - printf("%-16s %-96s ", nvme_subsystem_get_name(s), - nvme_subsystem_get_subsysnqn(s)); + printf("%-16s %-96s ", libnvme_subsystem_get_name(s), + libnvme_subsystem_get_subsysnqn(s)); - nvme_subsystem_for_each_ctrl(s, c) { + libnvme_subsystem_for_each_ctrl(s, c) { printf("%s%s", first ? "": ", ", - nvme_ctrl_get_name(c)); + libnvme_ctrl_get_name(c)); first = false; } printf("\n"); @@ -59,29 +59,29 @@ int main() printf("%-.8s %-.20s %-.40s %-.8s %-.6s %-.14s %-.12s %-.16s\n", dash, dash, dash, dash, dash, dash, dash, dash); - nvme_for_each_host(ctx, h) { - nvme_for_each_subsystem(h, s) { - nvme_subsystem_for_each_ctrl(s, c) { + libnvme_for_each_host(ctx, h) { + libnvme_for_each_subsystem(h, s) { + libnvme_subsystem_for_each_ctrl(s, c) { bool first = true; printf("%-8s %-20s %-40s %-8s %-6s %-14s %-12s ", - nvme_ctrl_get_name(c), - nvme_ctrl_get_serial(c), - nvme_ctrl_get_model(c), - nvme_ctrl_get_firmware(c), - nvme_ctrl_get_transport(c), - nvme_ctrl_get_traddr(c), - nvme_subsystem_get_name(s)); - - nvme_ctrl_for_each_ns(c, n) { + libnvme_ctrl_get_name(c), + libnvme_ctrl_get_serial(c), + libnvme_ctrl_get_model(c), + libnvme_ctrl_get_firmware(c), + libnvme_ctrl_get_transport(c), + libnvme_ctrl_get_traddr(c), + libnvme_subsystem_get_name(s)); + + libnvme_ctrl_for_each_ns(c, n) { printf("%s%s", first ? "": ", ", - nvme_ns_get_name(n)); + libnvme_ns_get_name(n)); first = false; } - nvme_ctrl_for_each_path(c, p) { + libnvme_ctrl_for_each_path(c, p) { printf("%s%s", first ? "": ", ", - nvme_ns_get_name(nvme_path_get_ns(p))); + libnvme_ns_get_name(libnvme_path_get_ns(p))); first = false; } printf("\n"); @@ -93,29 +93,29 @@ int main() printf("%-12s %-8s %-16s %-8s %-16s\n", "Device", "NSID", "Sectors", "Format", "Controllers"); printf("%-.12s %-.8s %-.16s %-.8s %-.16s\n", dash, dash, dash, dash, dash); - nvme_for_each_host(ctx, h) { - nvme_for_each_subsystem(h, s) { - nvme_subsystem_for_each_ctrl(s, c) { - nvme_ctrl_for_each_ns(c, n) + libnvme_for_each_host(ctx, h) { + libnvme_for_each_subsystem(h, s) { + libnvme_subsystem_for_each_ctrl(s, c) { + libnvme_ctrl_for_each_ns(c, n) printf("%-12s %-8d %-16" PRIu64 " %-8d %s\n", - nvme_ns_get_name(n), - nvme_ns_get_nsid(n), - nvme_ns_get_lba_count(n), - nvme_ns_get_lba_size(n), - nvme_ctrl_get_name(c)); + libnvme_ns_get_name(n), + libnvme_ns_get_nsid(n), + libnvme_ns_get_lba_count(n), + libnvme_ns_get_lba_size(n), + libnvme_ctrl_get_name(c)); } - nvme_subsystem_for_each_ns(s, n) { + libnvme_subsystem_for_each_ns(s, n) { bool first = true; printf("%-12s %-8d %-16" PRIu64 " %-8d ", - nvme_ns_get_name(n), - nvme_ns_get_nsid(n), - nvme_ns_get_lba_count(n), - nvme_ns_get_lba_size(n)); - nvme_subsystem_for_each_ctrl(s, c) { + libnvme_ns_get_name(n), + libnvme_ns_get_nsid(n), + libnvme_ns_get_lba_count(n), + libnvme_ns_get_lba_size(n)); + libnvme_subsystem_for_each_ctrl(s, c) { printf("%s%s", first ? "" : ", ", - nvme_ctrl_get_name(c)); + libnvme_ctrl_get_name(c)); first = false; } printf("\n"); diff --git a/libnvme/examples/display-tree.c b/libnvme/examples/display-tree.c index 91f67676d8..7ea623d607 100644 --- a/libnvme/examples/display-tree.c +++ b/libnvme/examples/display-tree.c @@ -16,64 +16,64 @@ int main() { - struct nvme_global_ctx *ctx; - nvme_host_t h; - nvme_subsystem_t s, _s; - nvme_ctrl_t c, _c; - nvme_path_t p, _p; - nvme_ns_t n, _n; + struct libnvme_global_ctx *ctx; + libnvme_host_t h; + libnvme_subsystem_t s, _s; + libnvme_ctrl_t c, _c; + libnvme_path_t p, _p; + libnvme_ns_t n, _n; int err; - ctx = nvme_create_global_ctx(stdout, DEFAULT_LOGLEVEL); + ctx = libnvme_create_global_ctx(stdout, DEFAULT_LOGLEVEL); if (!ctx) return 1; - err = nvme_scan_topology(ctx, NULL, NULL); + err = libnvme_scan_topology(ctx, NULL, NULL); if (err) { - nvme_free_global_ctx(ctx); + libnvme_free_global_ctx(ctx); return 1; } printf(".\n"); - nvme_for_each_host(ctx, h) { - nvme_for_each_subsystem_safe(h, s, _s) { + libnvme_for_each_host(ctx, h) { + libnvme_for_each_subsystem_safe(h, s, _s) { printf("%c-- %s - NQN=%s\n", _s ? '|' : '`', - nvme_subsystem_get_name(s), - nvme_subsystem_get_subsysnqn(s)); + libnvme_subsystem_get_name(s), + libnvme_subsystem_get_subsysnqn(s)); - nvme_subsystem_for_each_ns_safe(s, n, _n) { + libnvme_subsystem_for_each_ns_safe(s, n, _n) { printf("%c |-- %s lba size:%d lba max:%" PRIu64 "\n", _s ? '|' : ' ', - nvme_ns_get_name(n), - nvme_ns_get_lba_size(n), - nvme_ns_get_lba_count(n)); + libnvme_ns_get_name(n), + libnvme_ns_get_lba_size(n), + libnvme_ns_get_lba_count(n)); } - nvme_subsystem_for_each_ctrl_safe(s, c, _c) { + libnvme_subsystem_for_each_ctrl_safe(s, c, _c) { printf("%c %c-- %s %s %s %s\n", _s ? '|' : ' ', _c ? '|' : '`', - nvme_ctrl_get_name(c), - nvme_ctrl_get_transport(c), - nvme_ctrl_get_traddr(c), - nvme_ctrl_get_state(c)); + libnvme_ctrl_get_name(c), + libnvme_ctrl_get_transport(c), + libnvme_ctrl_get_traddr(c), + libnvme_ctrl_get_state(c)); - nvme_ctrl_for_each_ns_safe(c, n, _n) + libnvme_ctrl_for_each_ns_safe(c, n, _n) printf("%c %c %c-- %s lba size:%d lba max:%" PRIu64 "\n", _s ? '|' : ' ', _c ? '|' : ' ', _n ? '|' : '`', - nvme_ns_get_name(n), - nvme_ns_get_lba_size(n), - nvme_ns_get_lba_count(n)); + libnvme_ns_get_name(n), + libnvme_ns_get_lba_size(n), + libnvme_ns_get_lba_count(n)); - nvme_ctrl_for_each_path_safe(c, p, _p) + libnvme_ctrl_for_each_path_safe(c, p, _p) printf("%c %c %c-- %s %s\n", _s ? '|' : ' ', _c ? '|' : ' ', _p ? '|' : '`', - nvme_path_get_name(p), - nvme_path_get_ana_state(p)); + libnvme_path_get_name(p), + libnvme_path_get_ana_state(p)); } } } - nvme_free_global_ctx(ctx); + libnvme_free_global_ctx(ctx); return 0; } diff --git a/libnvme/examples/mi-conf.c b/libnvme/examples/mi-conf.c index 03b74639d7..5a8abd993b 100644 --- a/libnvme/examples/mi-conf.c +++ b/libnvme/examples/mi-conf.c @@ -40,7 +40,7 @@ static int parse_mctp(const char *devstr, unsigned int *net, uint8_t *eid) return 0; } -int find_port(nvme_mi_ep_t ep, uint8_t *portp, uint16_t *mtup) +int find_port(libnvme_mi_ep_t ep, uint8_t *portp, uint16_t *mtup) { struct nvme_mi_read_nvm_ss_info ss_info; struct nvme_mi_read_port_info port_info; @@ -49,7 +49,7 @@ int find_port(nvme_mi_ep_t ep, uint8_t *portp, uint16_t *mtup) int rc; /* query number of ports */ - rc = nvme_mi_mi_read_mi_data_subsys(ep, &ss_info); + rc = libnvme_mi_mi_read_mi_data_subsys(ep, &ss_info); if (rc) { warn("Failed reading subsystem info"); return -1; @@ -57,7 +57,7 @@ int find_port(nvme_mi_ep_t ep, uint8_t *portp, uint16_t *mtup) found = false; for (port = 0; port <= ss_info.nump; port++) { - rc = nvme_mi_mi_read_mi_data_port(ep, port, &port_info); + rc = libnvme_mi_mi_read_mi_data_port(ep, port, &port_info); if (rc) { warn("Failed reading port info for port %ud", port); return -1; @@ -137,13 +137,13 @@ int set_local_mtu(DBusConnection *bus, unsigned int net, uint8_t eid, int main(int argc, char **argv) { - struct nvme_global_ctx *ctx; + struct libnvme_global_ctx *ctx; uint16_t cur_mtu, mtu; DBusConnection *bus; const char *devstr; uint8_t eid, port; unsigned int net; - nvme_mi_ep_t ep; + libnvme_mi_ep_t ep; DBusError berr; int rc; @@ -157,11 +157,11 @@ int main(int argc, char **argv) if (rc) errx(EXIT_FAILURE, "can't parse MI device string '%s'", devstr); - ctx = nvme_create_global_ctx(stderr, DEFAULT_LOGLEVEL); + ctx = libnvme_create_global_ctx(stderr, DEFAULT_LOGLEVEL); if (!ctx) err(EXIT_FAILURE, "can't create global context"); - ep = nvme_mi_open_mctp(ctx, net, eid); + ep = libnvme_mi_open_mctp(ctx, net, eid); if (!ep) { warnx("can't open MCTP endpoint %d:%d", net, eid); goto out_free_ctx; @@ -182,7 +182,7 @@ int main(int argc, char **argv) goto out_close_bus; } - rc = nvme_mi_mi_config_get_mctp_mtu(ep, port, &cur_mtu); + rc = libnvme_mi_mi_config_get_mctp_mtu(ep, port, &cur_mtu); if (rc) { cur_mtu = 0; warn("Can't query current MTU; no way to revert on failure"); @@ -193,7 +193,7 @@ int main(int argc, char **argv) goto out_close_bus; } - rc = nvme_mi_mi_config_set_mctp_mtu(ep, port, mtu); + rc = libnvme_mi_mi_config_set_mctp_mtu(ep, port, mtu); if (rc) { warn("Can't set MCTP MTU"); goto out_close_bus; @@ -203,7 +203,7 @@ int main(int argc, char **argv) if (rc) { /* revert if we have an old setting */ if (cur_mtu) { - rc = nvme_mi_mi_config_set_mctp_mtu(ep, port, cur_mtu); + rc = libnvme_mi_mi_config_set_mctp_mtu(ep, port, cur_mtu); if (rc) warn("Failed to restore previous MTU!"); rc = -1; @@ -217,9 +217,9 @@ int main(int argc, char **argv) dbus_connection_unref(bus); out_close_ep: dbus_error_free(&berr); - nvme_mi_close(ep); + libnvme_mi_close(ep); out_free_ctx: - nvme_free_global_ctx(ctx); + libnvme_free_global_ctx(ctx); return rc ? EXIT_FAILURE : EXIT_SUCCESS; } diff --git a/libnvme/examples/mi-mctp-ae.c b/libnvme/examples/mi-mctp-ae.c index e35ffebc75..c77839844d 100644 --- a/libnvme/examples/mi-mctp-ae.c +++ b/libnvme/examples/mi-mctp-ae.c @@ -38,7 +38,7 @@ static void print_byte_array(void *data, size_t len) printf("\n"); } -static void print_event_info(struct nvme_mi_event *event) +static void print_event_info(struct libnvme_mi_event *event) { printf("aeoi: %02X\n", event->aeoi); printf("aeocidi: %04X\n", event->aeocidi); @@ -55,7 +55,7 @@ static void print_event_info(struct nvme_mi_event *event) } } -enum nvme_mi_aem_handler_next_action aem_handler(nvme_mi_ep_t ep, size_t num_events, void *userdata) +enum libnvme_mi_aem_handler_next_action aem_handler(libnvme_mi_ep_t ep, size_t num_events, void *userdata) { struct app_userdata *data = (struct app_userdata *) userdata; @@ -63,7 +63,7 @@ enum nvme_mi_aem_handler_next_action aem_handler(nvme_mi_ep_t ep, size_t num_eve printf("Received notification #%d with %zu events:\n", data->count, num_events); for (int i = 0; i < num_events; i++) { - struct nvme_mi_event *event = nvme_mi_aem_get_next_event(ep); + struct libnvme_mi_event *event = libnvme_mi_aem_get_next_event(ep); if (event == NULL) printf("Unexpected NULL event\n"); @@ -79,12 +79,12 @@ enum nvme_mi_aem_handler_next_action aem_handler(nvme_mi_ep_t ep, size_t num_eve int main(int argc, char **argv) { - struct nvme_global_ctx *ctx; - nvme_mi_ep_t ep; + struct libnvme_global_ctx *ctx; + libnvme_mi_ep_t ep; uint8_t eid = 0; int rc = 0, net = 0; - struct nvme_mi_aem_config aem_config = {0}; - struct nvme_mi_aem_enabled_map enabled_map = {0}; + struct libnvme_mi_aem_config aem_config = {0}; + struct libnvme_mi_aem_enabled_map enabled_map = {0}; struct app_userdata data = {0}; const uint8_t AEM_FD_INDEX = 0; @@ -110,11 +110,11 @@ int main(int argc, char **argv) return EXIT_FAILURE; } - ctx = nvme_create_global_ctx(stderr, DEFAULT_LOGLEVEL); + ctx = libnvme_create_global_ctx(stderr, DEFAULT_LOGLEVEL); if (!ctx) err(EXIT_FAILURE, "can't create NVMe root"); - ep = nvme_mi_open_mctp(ctx, net, eid); + ep = libnvme_mi_open_mctp(ctx, net, eid); if (!ep) err(EXIT_FAILURE, "can't open MCTP endpoint %d:%d", net, eid); @@ -122,7 +122,7 @@ int main(int argc, char **argv) aem_config.aemd = 1; aem_config.aerd = 100; - rc = nvme_mi_aem_get_enabled(ep, &enabled_map); + rc = libnvme_mi_aem_get_enabled(ep, &enabled_map); if (rc) err(EXIT_FAILURE, "Can't query enabled aems:%d", rc); printf("The following events were previously enabled:\n"); @@ -131,19 +131,19 @@ int main(int argc, char **argv) printf("Event: %d\n", i); } - rc = nvme_mi_aem_enable(ep, &aem_config, &data); + rc = libnvme_mi_aem_enable(ep, &aem_config, &data); 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); - rc = nvme_mi_aem_get_enabled(ep, &enabled_map); + rc = libnvme_mi_aem_get_enabled(ep, &enabled_map); if (rc) err(EXIT_FAILURE, "Can't query enabled aems:%d", rc); struct pollfd fds[2]; - fds[AEM_FD_INDEX].fd = nvme_mi_aem_get_fd(ep); + fds[AEM_FD_INDEX].fd = libnvme_mi_aem_get_fd(ep); if (fds[AEM_FD_INDEX].fd < 0) errx(EXIT_FAILURE, "Can't get aem fd"); @@ -162,19 +162,19 @@ int main(int argc, char **argv) } //Time to do the work if (fds[AEM_FD_INDEX].revents & POLLIN) { - rc = nvme_mi_aem_process(ep, &data); + rc = libnvme_mi_aem_process(ep, &data); if (rc) err(EXIT_FAILURE, - "nvme_mi_aem_process failed with:%d", rc); + "libnvme_mi_aem_process failed with:%d", rc); } if (fds[STD_IN_FD_INDEX].revents & POLLIN) break;//we are done } //Cleanup - nvme_mi_aem_disable(ep); - nvme_mi_close(ep); - nvme_free_global_ctx(ctx); + libnvme_mi_aem_disable(ep); + libnvme_mi_close(ep); + libnvme_free_global_ctx(ctx); return rc ? EXIT_FAILURE : EXIT_SUCCESS; } diff --git a/libnvme/examples/mi-mctp-csi-test.c b/libnvme/examples/mi-mctp-csi-test.c index 57602fe049..8bf04051f8 100644 --- a/libnvme/examples/mi-mctp-csi-test.c +++ b/libnvme/examples/mi-mctp-csi-test.c @@ -54,11 +54,11 @@ void hexdump(const unsigned char *buf, int len) fhexdump(stdout, buf, len); } -int do_get_log_page(nvme_mi_ep_t ep, int argc, char **argv) +int do_get_log_page(libnvme_mi_ep_t ep, int argc, char **argv) { - struct nvme_transport_handle *hdl; + struct libnvme_transport_handle *hdl; enum nvme_cmd_get_log_lid lid; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; uint8_t buf[4096]; uint16_t ctrl_id; int rc, tmp; @@ -83,7 +83,7 @@ int do_get_log_page(nvme_mi_ep_t ep, int argc, char **argv) lid = 0x1; } - hdl = nvme_mi_init_transport_handle(ep, ctrl_id); + hdl = libnvme_mi_init_transport_handle(ep, ctrl_id); if (!hdl) { warn("can't create controller"); return -1; @@ -91,7 +91,7 @@ int do_get_log_page(nvme_mi_ep_t ep, int argc, char **argv) nvme_init_get_log(&cmd, NVME_NSID_NONE, lid, NVME_CSI_NVM, buf, sizeof(buf)); - rc = nvme_get_log(hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); + rc = libnvme_get_log(hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); if (rc) { warn("can't perform Get Log page command"); return -1; @@ -104,7 +104,7 @@ int do_get_log_page(nvme_mi_ep_t ep, int argc, char **argv) } struct thread_struct { - nvme_mi_ep_t ep; + libnvme_mi_ep_t ep; int argc; char **argv; int rc; @@ -122,23 +122,23 @@ enum action { ACTION_CSI_TEST, }; -int do_csi_test(struct nvme_global_ctx *ctx, int net, __u8 eid, +int do_csi_test(struct libnvme_global_ctx *ctx, int net, __u8 eid, int argc, char **argv) { int rc = 0; - nvme_mi_ep_t ep1, ep2; + libnvme_mi_ep_t ep1, ep2; - ep1 = nvme_mi_open_mctp(ctx, net, eid); + ep1 = libnvme_mi_open_mctp(ctx, net, eid); if (!ep1) errx(EXIT_FAILURE, "can't open MCTP endpoint %d:%d", net, eid); - ep2 = nvme_mi_open_mctp(ctx, net, eid); + ep2 = libnvme_mi_open_mctp(ctx, net, eid); if (!ep2) errx(EXIT_FAILURE, "can't open MCTP endpoint %d:%d", net, eid); pthread_t thread; - nvme_mi_set_csi(ep1, 0);//Not necessary, but to be explicit - nvme_mi_set_csi(ep2, 1); + libnvme_mi_set_csi(ep1, 0);//Not necessary, but to be explicit + libnvme_mi_set_csi(ep2, 1); struct thread_struct s; s.ep = ep2; @@ -164,8 +164,8 @@ int do_csi_test(struct nvme_global_ctx *ctx, int net, __u8 eid, printf("Second thread finished with rc=%d\n", s.rc); - nvme_mi_close(ep1); - nvme_mi_close(ep2); + libnvme_mi_close(ep1); + libnvme_mi_close(ep2); if (rc) return rc; @@ -175,7 +175,7 @@ int do_csi_test(struct nvme_global_ctx *ctx, int net, __u8 eid, } static int do_action_endpoint(enum action action, - struct nvme_global_ctx *ctx, + struct libnvme_global_ctx *ctx, int net, uint8_t eid, int argc, @@ -200,7 +200,7 @@ static int do_action_endpoint(enum action action, int main(int argc, char **argv) { - struct nvme_global_ctx *ctx; + struct libnvme_global_ctx *ctx; enum action action; bool usage = true; uint8_t eid = 0; @@ -237,12 +237,12 @@ int main(int argc, char **argv) return EXIT_FAILURE; } - ctx = nvme_create_global_ctx(stderr, DEFAULT_LOGLEVEL); + ctx = libnvme_create_global_ctx(stderr, DEFAULT_LOGLEVEL); if (!ctx) err(EXIT_FAILURE, "can't create NVMe root"); rc = do_action_endpoint(action, ctx, net, eid, argc, argv); - nvme_free_global_ctx(ctx); + libnvme_free_global_ctx(ctx); return rc ? EXIT_FAILURE : EXIT_SUCCESS; } diff --git a/libnvme/examples/mi-mctp.c b/libnvme/examples/mi-mctp.c index 5aa4831095..169983dba9 100644 --- a/libnvme/examples/mi-mctp.c +++ b/libnvme/examples/mi-mctp.c @@ -53,14 +53,14 @@ static struct { { 0x02, "SMBus", show_port_smbus }, }; -static int show_port(nvme_mi_ep_t ep, int portid) +static int show_port(libnvme_mi_ep_t ep, int portid) { void (*show_fn)(struct nvme_mi_read_port_info *); struct nvme_mi_read_port_info port; const char *typestr; int rc; - rc = nvme_mi_mi_read_mi_data_port(ep, portid, &port); + rc = libnvme_mi_mi_read_mi_data_port(ep, portid, &port); if (rc) return rc; @@ -83,13 +83,13 @@ static int show_port(nvme_mi_ep_t ep, int portid) return 0; } -int do_info(nvme_mi_ep_t ep) +int do_info(libnvme_mi_ep_t ep) { struct nvme_mi_nvm_ss_health_status ss_health; struct nvme_mi_read_nvm_ss_info ss_info; int i, rc; - rc = nvme_mi_mi_read_mi_data_subsys(ep, &ss_info); + rc = libnvme_mi_mi_read_mi_data_subsys(ep, &ss_info); if (rc) { warn("can't perform Read MI Data operation"); return -1; @@ -104,7 +104,7 @@ int do_info(nvme_mi_ep_t ep) for (i = 0; i <= ss_info.nump; i++) show_port(ep, i); - rc = nvme_mi_mi_subsystem_health_status_poll(ep, true, &ss_health); + rc = libnvme_mi_mi_subsystem_health_status_poll(ep, true, &ss_health); if (rc) err(EXIT_FAILURE, "can't perform Health Status Poll operation"); @@ -118,12 +118,12 @@ int do_info(nvme_mi_ep_t ep) return 0; } -static int show_ctrl(nvme_mi_ep_t ep, uint16_t ctrl_id) +static int show_ctrl(libnvme_mi_ep_t ep, uint16_t ctrl_id) { struct nvme_mi_read_ctrl_info ctrl; int rc; - rc = nvme_mi_mi_read_mi_data_ctrl(ep, ctrl_id, &ctrl); + rc = libnvme_mi_mi_read_mi_data_ctrl(ep, ctrl_id, &ctrl); if (rc) return rc; @@ -146,12 +146,12 @@ static int show_ctrl(nvme_mi_ep_t ep, uint16_t ctrl_id) return 0; } -static int do_controllers(nvme_mi_ep_t ep) +static int do_controllers(libnvme_mi_ep_t ep) { struct nvme_ctrl_list ctrl_list; int rc, i; - rc = nvme_mi_mi_read_mi_data_ctrl_list(ep, 0, &ctrl_list); + rc = libnvme_mi_mi_read_mi_data_ctrl_list(ep, 0, &ctrl_list); if (rc) { warnx("Can't perform Controller List operation"); return rc; @@ -176,10 +176,10 @@ static const char *__copy_id_str(const void *field, size_t size, #define copy_id_str(f,b) __copy_id_str(f, sizeof(f), b, sizeof(b)) -int do_identify(nvme_mi_ep_t ep, int argc, char **argv) +int do_identify(libnvme_mi_ep_t ep, int argc, char **argv) { - struct nvme_transport_handle *hdl; - struct nvme_passthru_cmd cmd; + struct libnvme_transport_handle *hdl; + struct libnvme_passthru_cmd cmd; struct nvme_id_ctrl id; uint16_t ctrl_id; char buf[41]; @@ -201,7 +201,7 @@ int do_identify(nvme_mi_ep_t ep, int argc, char **argv) partial = argc > 2 && !strcmp(argv[2], "--partial"); - hdl = nvme_mi_init_transport_handle(ep, ctrl_id); + hdl = libnvme_mi_init_transport_handle(ep, ctrl_id); if (!hdl) { warn("can't create controller"); return -1; @@ -216,7 +216,7 @@ int do_identify(nvme_mi_ep_t ep, int argc, char **argv) if (partial) cmd.data_len = offsetof(struct nvme_id_ctrl, rab); - rc = nvme_submit_admin_passthru(hdl, &cmd); + rc = libnvme_submit_admin_passthru(hdl, &cmd); if (rc) { warn("can't perform Admin Identify command"); return -1; @@ -232,7 +232,7 @@ int do_identify(nvme_mi_ep_t ep, int argc, char **argv) return 0; } -int do_control_primitive(nvme_mi_ep_t ep, int argc, char **argv) +int do_control_primitive(libnvme_mi_ep_t ep, int argc, char **argv) { int rc = 0; char *action = NULL; @@ -283,7 +283,7 @@ int do_control_primitive(nvme_mi_ep_t ep, int argc, char **argv) return -1; } - rc = nvme_mi_control(ep, opcode, 0, &cpsr); /* cpsp reserved in example */ + rc = libnvme_mi_control(ep, opcode, 0, &cpsr); /* cpsp reserved in example */ if (rc) { warn("can't perform primitive control command"); return -1; @@ -362,11 +362,11 @@ void hexdump(const unsigned char *buf, int len) fhexdump(stdout, buf, len); } -int do_get_log_page(nvme_mi_ep_t ep, int argc, char **argv) +int do_get_log_page(libnvme_mi_ep_t ep, int argc, char **argv) { - struct nvme_transport_handle *hdl; + struct libnvme_transport_handle *hdl; enum nvme_cmd_get_log_lid lid; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; uint8_t buf[512]; uint16_t ctrl_id; int rc, tmp; @@ -391,7 +391,7 @@ int do_get_log_page(nvme_mi_ep_t ep, int argc, char **argv) lid = 0x1; } - hdl = nvme_mi_init_transport_handle(ep, ctrl_id); + hdl = libnvme_mi_init_transport_handle(ep, ctrl_id); if (!hdl) { warn("can't create controller"); return -1; @@ -399,7 +399,7 @@ int do_get_log_page(nvme_mi_ep_t ep, int argc, char **argv) nvme_init_get_log(&cmd, NVME_NSID_NONE, lid, NVME_CSI_NVM, buf, sizeof(buf)); - rc = nvme_get_log(hdl, &cmd, true, NVME_LOG_PAGE_PDU_SIZE); + rc = libnvme_get_log(hdl, &cmd, true, NVME_LOG_PAGE_PDU_SIZE); if (rc) { warn("can't perform Get Log page command"); return -1; @@ -411,11 +411,11 @@ int do_get_log_page(nvme_mi_ep_t ep, int argc, char **argv) return 0; } -int do_admin_raw(nvme_mi_ep_t ep, int argc, char **argv) +int do_admin_raw(libnvme_mi_ep_t ep, int argc, char **argv) { struct nvme_mi_admin_req_hdr req; struct nvme_mi_admin_resp_hdr *resp; - struct nvme_transport_handle *hdl; + struct libnvme_transport_handle *hdl; size_t resp_data_len; unsigned long tmp; uint8_t buf[512]; @@ -478,7 +478,7 @@ int do_admin_raw(nvme_mi_ep_t ep, int argc, char **argv) memset(buf, 0, sizeof(buf)); resp = (void *)buf; - hdl = nvme_mi_init_transport_handle(ep, ctrl_id); + hdl = libnvme_mi_init_transport_handle(ep, ctrl_id); if (!hdl) { warn("can't create controller"); return -1; @@ -486,7 +486,7 @@ int do_admin_raw(nvme_mi_ep_t ep, int argc, char **argv) resp_data_len = sizeof(buf) - sizeof(*resp); - rc = nvme_mi_admin_xfer(hdl, &req, 0, resp, 0, &resp_data_len); + rc = libnvme_mi_admin_xfer(hdl, &req, 0, resp, 0, &resp_data_len); if (rc) { warn("nvme_admin_xfer failed: %d", rc); return -1; @@ -530,10 +530,10 @@ static const char *sec_proto_description(uint8_t id) return "unknown"; } -int do_security_info(nvme_mi_ep_t ep, int argc, char **argv) +int do_security_info(libnvme_mi_ep_t ep, int argc, char **argv) { - struct nvme_transport_handle *hdl; - struct nvme_passthru_cmd cmd; + struct libnvme_transport_handle *hdl; + struct libnvme_passthru_cmd cmd; int i, rc, n_proto; unsigned long tmp; uint16_t ctrl_id; @@ -559,14 +559,14 @@ int do_security_info(nvme_mi_ep_t ep, int argc, char **argv) ctrl_id = tmp & 0xffff; - hdl = nvme_mi_init_transport_handle(ep, ctrl_id); + hdl = libnvme_mi_init_transport_handle(ep, ctrl_id); if (!hdl) { warn("can't create controller"); return -1; } nvme_init_security_receive(&cmd, 0, 0, 0, 0, 0, data, data_len); - rc = nvme_submit_admin_passthru(hdl, &cmd); + rc = libnvme_submit_admin_passthru(hdl, &cmd); if (rc) { warnx("can't perform Security Receive command: rc %d", rc); return -1; @@ -623,7 +623,7 @@ static int smbus_freq_val(const char *str, enum nvme_mi_config_smbus_freq *freq) return -1; } -int do_config_get(nvme_mi_ep_t ep, int argc, char **argv) +int do_config_get(libnvme_mi_ep_t ep, int argc, char **argv) { enum nvme_mi_config_smbus_freq freq; uint16_t mtu; @@ -635,7 +635,7 @@ int do_config_get(nvme_mi_ep_t ep, int argc, char **argv) else port = 0; - rc = nvme_mi_mi_config_get_smbus_freq(ep, port, &freq); + rc = libnvme_mi_mi_config_get_smbus_freq(ep, port, &freq); if (rc) { warn("can't query SMBus freq for port %d\n", port); } else { @@ -644,7 +644,7 @@ int do_config_get(nvme_mi_ep_t ep, int argc, char **argv) fstr ?: "unknown", freq); } - rc = nvme_mi_mi_config_get_mctp_mtu(ep, port, &mtu); + rc = libnvme_mi_mi_config_get_mctp_mtu(ep, port, &mtu); if (rc) warn("can't query MCTP MTU for port %d\n", port); else @@ -653,7 +653,7 @@ int do_config_get(nvme_mi_ep_t ep, int argc, char **argv) return 0; } -int do_config_set(nvme_mi_ep_t ep, int argc, char **argv) +int do_config_set(libnvme_mi_ep_t ep, int argc, char **argv) { const char *name, *val; uint8_t port; @@ -676,7 +676,7 @@ int do_config_set(nvme_mi_ep_t ep, int argc, char **argv) "Try 100k, 400k or 1M\n", val); return -1; } - rc = nvme_mi_mi_config_set_smbus_freq(ep, port, freq); + rc = libnvme_mi_mi_config_set_smbus_freq(ep, port, freq); } else if (!strcmp(name, "mtu")) { uint16_t mtu; @@ -688,7 +688,7 @@ int do_config_set(nvme_mi_ep_t ep, int argc, char **argv) fprintf(stderr, "MTU value too small\n"); return -1; } - rc = nvme_mi_mi_config_set_mctp_mtu(ep, port, mtu); + rc = libnvme_mi_mi_config_set_mctp_mtu(ep, port, mtu); } else { fprintf(stderr, "Invalid configuration '%s', " @@ -714,7 +714,7 @@ enum action { ACTION_CONTROL_PRIMITIVE, }; -static int do_action_endpoint(enum action action, nvme_mi_ep_t ep, int argc, char** argv) +static int do_action_endpoint(enum action action, libnvme_mi_ep_t ep, int argc, char** argv) { int rc; @@ -758,9 +758,9 @@ static int do_action_endpoint(enum action action, nvme_mi_ep_t ep, int argc, cha int main(int argc, char **argv) { - struct nvme_global_ctx *ctx; + struct libnvme_global_ctx *ctx; enum action action; - nvme_mi_ep_t ep; + libnvme_mi_ep_t ep; bool dbus = false, usage = true; uint8_t eid = 0; int rc = 0, net = 0; @@ -830,34 +830,34 @@ int main(int argc, char **argv) } } if (dbus) { - struct nvme_global_ctx *ctx; + struct libnvme_global_ctx *ctx; int i = 0; - ctx = nvme_mi_scan_mctp(); + ctx = libnvme_mi_scan_mctp(); if (!ctx) errx(EXIT_FAILURE, "can't scan D-Bus entries"); - nvme_mi_for_each_endpoint(ctx, ep) i++; + libnvme_mi_for_each_endpoint(ctx, ep) i++; printf("Found %d endpoints in D-Bus:\n", i); - nvme_mi_for_each_endpoint(ctx, ep) { - char *desc = nvme_mi_endpoint_desc(ep); + libnvme_mi_for_each_endpoint(ctx, ep) { + char *desc = libnvme_mi_endpoint_desc(ep); printf("%s\n", desc); rc = do_action_endpoint(action, ep, argc, argv); printf("---\n"); free(desc); } - nvme_free_global_ctx(ctx); + libnvme_free_global_ctx(ctx); } else { - ctx = nvme_create_global_ctx(stderr, DEFAULT_LOGLEVEL); + ctx = libnvme_create_global_ctx(stderr, DEFAULT_LOGLEVEL); if (!ctx) err(EXIT_FAILURE, "can't create NVMe root"); - ep = nvme_mi_open_mctp(ctx, net, eid); + ep = libnvme_mi_open_mctp(ctx, net, eid); if (!ep) errx(EXIT_FAILURE, "can't open MCTP endpoint %d:%d", net, eid); rc = do_action_endpoint(action, ep, argc, argv); - nvme_mi_close(ep); - nvme_free_global_ctx(ctx); + libnvme_mi_close(ep); + libnvme_free_global_ctx(ctx); } return rc ? EXIT_FAILURE : EXIT_SUCCESS; diff --git a/libnvme/examples/telemetry-listen.c b/libnvme/examples/telemetry-listen.c index 7fb8f2b15b..113108e913 100644 --- a/libnvme/examples/telemetry-listen.c +++ b/libnvme/examples/telemetry-listen.c @@ -29,19 +29,19 @@ #include "nvme/tree.h" struct events { - nvme_ctrl_t c; + libnvme_ctrl_t c; int uevent_fd; }; -static int open_uevent(nvme_ctrl_t c) +static int open_uevent(libnvme_ctrl_t c) { char buf[0x1000]; - if (snprintf(buf, sizeof(buf), "%s/uevent", nvme_ctrl_get_sysfs_dir(c)) < 0) + if (snprintf(buf, sizeof(buf), "%s/uevent", libnvme_ctrl_get_sysfs_dir(c)) < 0) return -1; return open(buf, O_RDONLY); } -static void save_telemetry(nvme_ctrl_t c) +static void save_telemetry(libnvme_ctrl_t c) { char buf[0x1000]; size_t log_size; @@ -50,14 +50,14 @@ 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_transport_handle(c), false, &log, + ret = libnvme_get_ctrl_telemetry(libnvme_ctrl_get_transport_handle(c), false, &log, NVME_TELEMETRY_DA_3, &log_size); if (ret) return; s = time(NULL); ret = snprintf(buf, sizeof(buf), "/var/log/%s-telemetry-%llu", - nvme_ctrl_get_subsysnqn(c), (unsigned long long)s); + libnvme_ctrl_get_subsysnqn(c), (unsigned long long)s); if (ret < 0) { free(log); return; @@ -79,7 +79,7 @@ static void save_telemetry(nvme_ctrl_t c) free(log); } -static void check_telemetry(nvme_ctrl_t c, int ufd) +static void check_telemetry(libnvme_ctrl_t c, int ufd) { char buf[0x1000] = { 0 }; char *p, *ptr; @@ -101,7 +101,7 @@ static void check_telemetry(nvme_ctrl_t c, int ufd) lid = (aen >> 16) & 0xff; printf("%s: aen type:%x info:%x lid:%d\n", - nvme_ctrl_get_name(c), type, info, lid); + libnvme_ctrl_get_name(c), type, info, lid); if (type == NVME_AER_NOTICE && info == NVME_AER_NOTICE_TELEMETRY) save_telemetry(c); @@ -134,32 +134,32 @@ int main() fd_set fds; int i = 0; - struct nvme_global_ctx *ctx; - nvme_subsystem_t s; - nvme_ctrl_t c; - nvme_host_t h; + struct libnvme_global_ctx *ctx; + libnvme_subsystem_t s; + libnvme_ctrl_t c; + libnvme_host_t h; - ctx = nvme_create_global_ctx(stdout, DEFAULT_LOGLEVEL); + ctx = libnvme_create_global_ctx(stdout, DEFAULT_LOGLEVEL); if (!ctx) return 1; - if (nvme_scan_topology(ctx, NULL, NULL)) { - nvme_free_global_ctx(ctx); + if (libnvme_scan_topology(ctx, NULL, NULL)) { + libnvme_free_global_ctx(ctx); return EXIT_FAILURE; } - nvme_for_each_host(ctx, h) - nvme_for_each_subsystem(h, s) - nvme_subsystem_for_each_ctrl(s, c) + libnvme_for_each_host(ctx, h) + libnvme_for_each_subsystem(h, s) + libnvme_subsystem_for_each_ctrl(s, c) i++; e = calloc(i, sizeof(struct events)); FD_ZERO(&fds); i = 0; - nvme_for_each_host(ctx, h) { - nvme_for_each_subsystem(h, s) { - nvme_subsystem_for_each_ctrl(s, c) { + libnvme_for_each_host(ctx, h) { + libnvme_for_each_subsystem(h, s) { + libnvme_subsystem_for_each_ctrl(s, c) { int fd = open_uevent(c); if (fd < 0) @@ -173,7 +173,7 @@ int main() } wait_events(&fds, e, i); - nvme_free_global_ctx(ctx); + libnvme_free_global_ctx(ctx); free(e); return EXIT_SUCCESS; diff --git a/libnvme/libnvme/nvme.i b/libnvme/libnvme/nvme.i index 3669936f7e..d71de88e81 100644 --- a/libnvme/libnvme/nvme.i +++ b/libnvme/libnvme/nvme.i @@ -19,11 +19,11 @@ %allowexception; -%rename(global_ctx) nvme_global_ctx; -%rename(host) nvme_host; -%rename(ctrl) nvme_ctrl; -%rename(subsystem) nvme_subsystem; -%rename(ns) nvme_ns; +%rename(global_ctx) libnvme_global_ctx; +%rename(host) libnvme_host; +%rename(ctrl) libnvme_ctrl; +%rename(subsystem) libnvme_subsystem; +%rename(ns) libnvme_ns; %{ #include @@ -39,13 +39,13 @@ Py_XDECREF(val); /* .. therefore decrement ref. count. */ } PyObject *read_hostnqn() { - char * val = nvme_read_hostnqn(); + char * val = libnvme_read_hostnqn(); PyObject * obj = val ? PyUnicode_FromString(val) : Py_NewRef(Py_None); free(val); return obj; } PyObject *read_hostid() { - char * val = nvme_read_hostid(); + char * val = libnvme_read_hostid(); PyObject * obj = val ? PyUnicode_FromString(val) : Py_NewRef(Py_None); free(val); return obj; @@ -54,11 +54,11 @@ PyObject *read_hostnqn(); PyObject *read_hostid(); -%exception nvme_ctrl::connect { +%exception libnvme_ctrl::connect { connect_err = 0; $action /* $action sets connect_err to non-zero value on failure */ if (connect_err) { - const char *errstr = nvme_errno_to_string(-connect_err); + const char *errstr = libnvme_errno_to_string(-connect_err); if (errstr) { SWIG_exception(SWIG_RuntimeError, errstr); } else { @@ -67,14 +67,14 @@ PyObject *read_hostid(); } } -%exception nvme_ctrl::disconnect { +%exception libnvme_ctrl::disconnect { connect_err = 0; errno = 0; $action /* $action sets connect_err to non-zero value on failure */ if (connect_err == 1) { SWIG_exception(SWIG_AttributeError, "No controller connection"); } else if (connect_err) { - const char *errstr = nvme_errno_to_string(-connect_err); + const char *errstr = libnvme_errno_to_string(-connect_err); if (errstr) { SWIG_exception(SWIG_RuntimeError, errstr); } else { @@ -83,13 +83,13 @@ PyObject *read_hostid(); } } -%exception nvme_ctrl::discover { +%exception libnvme_ctrl::discover { discover_err = 0; $action /* $action sets discover_err to non-zero value on failure */ if (discover_err == 1) { SWIG_exception(SWIG_AttributeError, "No controller connection"); } else if (discover_err) { - const char *errstr = nvme_errno_to_string(-discover_err); + const char *errstr = libnvme_errno_to_string(-discover_err); if (errstr) { SWIG_exception(SWIG_RuntimeError, errstr); } else { @@ -98,7 +98,7 @@ PyObject *read_hostid(); } } -%typemap(in) struct nvme_fabrics_config *($*1_type temp){ +%typemap(in) struct libnvme_fabrics_config *($*1_type temp){ Py_ssize_t pos = 0; PyObject * key,*value; memset(&temp, 0, sizeof(temp)); @@ -343,25 +343,25 @@ PyObject *read_hostid(); #include "fabrics.h" #define STR_OR_NONE(str) (!(str) ? "None" : str) -struct nvme_host * nvme_first_host(struct nvme_global_ctx * ctx); -struct nvme_host * nvme_next_host(struct nvme_global_ctx *ctx, struct nvme_host * h); -struct nvme_subsystem * nvme_first_subsystem(struct nvme_host * h); -struct nvme_subsystem * nvme_next_subsystem(struct nvme_host * h, struct nvme_subsystem * s); -struct nvme_ctrl * nvme_subsystem_first_ctrl(struct nvme_subsystem * s); -struct nvme_ctrl * nvme_subsystem_next_ctrl(struct nvme_subsystem * s, struct nvme_ctrl * c); -struct nvme_ns * nvme_subsystem_first_ns(struct nvme_subsystem * s); -struct nvme_ns * nvme_subsystem_next_ns(struct nvme_subsystem * s, struct nvme_ns * n); -struct nvme_ns * nvme_ctrl_first_ns(struct nvme_ctrl * c); -struct nvme_ns * nvme_ctrl_next_ns(struct nvme_ctrl * c, struct nvme_ns * n); - -struct nvme_global_ctx { +struct libnvme_host * libnvme_first_host(struct libnvme_global_ctx * ctx); +struct libnvme_host * libnvme_next_host(struct libnvme_global_ctx *ctx, struct libnvme_host * h); +struct libnvme_subsystem * libnvme_first_subsystem(struct libnvme_host * h); +struct libnvme_subsystem * libnvme_next_subsystem(struct libnvme_host * h, struct libnvme_subsystem * s); +struct libnvme_ctrl * libnvme_subsystem_first_ctrl(struct libnvme_subsystem * s); +struct libnvme_ctrl * libnvme_subsystem_next_ctrl(struct libnvme_subsystem * s, struct libnvme_ctrl * c); +struct libnvme_ns * libnvme_subsystem_first_ns(struct libnvme_subsystem * s); +struct libnvme_ns * libnvme_subsystem_next_ns(struct libnvme_subsystem * s, struct libnvme_ns * n); +struct libnvme_ns * libnvme_ctrl_first_ns(struct libnvme_ctrl * c); +struct libnvme_ns * libnvme_ctrl_next_ns(struct libnvme_ctrl * c, struct libnvme_ns * n); + +struct libnvme_global_ctx { %immutable config_file; %immutable application; char *config_file; char *application; }; -struct nvme_host { +struct libnvme_host { %immutable hostnqn; %immutable hostid; %immutable hostsymname; @@ -373,7 +373,7 @@ struct nvme_host { } }; -struct nvme_subsystem { +struct libnvme_subsystem { %immutable sysfs_dir; %immutable subsysnqn; %immutable model; @@ -394,7 +394,7 @@ struct nvme_subsystem { } }; -struct nvme_ctrl { +struct libnvme_ctrl { %immutable name; %immutable subsystem; %immutable state; @@ -427,7 +427,7 @@ struct nvme_ctrl { * accessing the members directly. * * For example, SWIG will generate code like this: - * name = nvme_ctrl_name_get(ctrl) + * name = libnvme_ctrl_name_get(ctrl) * * instead of that: * name = ctrl->name @@ -462,18 +462,18 @@ struct nvme_ctrl { /** * We are remapping the following member(s) of the C code's - * nvme_ctrl_t to different name(s) in Python. Here's the + * libnvme_ctrl_t to different name(s) in Python. Here's the * mapping: * * C code Python (SWIG) * ===================== ===================== * ctrl->s ctrl->subsystem */ - struct nvme_subsystem *subsystem; // Maps to "s" in the C code + struct libnvme_subsystem *subsystem; // Maps to "s" in the C code } }; -struct nvme_ns { +struct libnvme_ns { %immutable nsid; %immutable eui64; %immutable nguid; @@ -484,26 +484,26 @@ struct nvme_ns { uint8_t uuid[16]; }; -%extend nvme_global_ctx { - nvme_global_ctx(const char *config_file = NULL) { - struct nvme_global_ctx *ctx; +%extend libnvme_global_ctx { + libnvme_global_ctx(const char *config_file = NULL) { + struct libnvme_global_ctx *ctx; - ctx = nvme_create_global_ctx(stdout, DEFAULT_LOGLEVEL); + ctx = libnvme_create_global_ctx(stdout, DEFAULT_LOGLEVEL); if (!ctx) return NULL; - nvme_scan_topology(ctx, NULL, NULL); - nvme_read_config(ctx, config_file); + libnvme_scan_topology(ctx, NULL, NULL); + libnvme_read_config(ctx, config_file); return ctx; } - ~nvme_global_ctx() { - nvme_free_global_ctx($self); + ~libnvme_global_ctx() { + libnvme_free_global_ctx($self); } - struct nvme_global_ctx* __enter__() { + struct libnvme_global_ctx* __enter__() { return $self; } - struct nvme_global_ctx* __exit__(PyObject *type, PyObject *value, PyObject *traceback) { + struct libnvme_global_ctx* __exit__(PyObject *type, PyObject *value, PyObject *traceback) { return $self; } void log_level(const char *level) { @@ -516,21 +516,21 @@ struct nvme_ns { else if (!strcmp(level, "crit")) log_level = LOG_CRIT; else if (!strcmp(level, "alert")) log_level = LOG_ALERT; else if (!strcmp(level, "emerg")) log_level = LOG_EMERG; - nvme_set_logging_level($self, log_level, false, false); + libnvme_set_logging_level($self, log_level, false, false); } %pythoncode %{ def hosts(self): """Iterator over all host objects""" - h = nvme_first_host(self) + h = libnvme_first_host(self) while h: yield h - h = nvme_next_host(self, h) + h = libnvme_next_host(self, h) %} void refresh_topology() { - nvme_refresh_topology($self); + libnvme_refresh_topology($self); } void dump_config() { - nvme_dump_config($self, STDERR_FILENO); + libnvme_dump_config($self, STDERR_FILENO); } } @@ -544,39 +544,39 @@ struct nvme_ns { @return: None" %enddef -%pythonappend nvme_host::nvme_host(struct nvme_global_ctx *ctx, +%pythonappend libnvme_host::libnvme_host(struct libnvme_global_ctx *ctx, const char *hostnqn, const char *hostid, const char *hostkey, const char *hostsymname) { self.__parent = ctx # Keep a reference to parent to ensure garbage collection happens in the right order} -%extend nvme_host { - nvme_host(struct nvme_global_ctx *ctx, +%extend libnvme_host { + libnvme_host(struct libnvme_global_ctx *ctx, const char *hostnqn = NULL, const char *hostid = NULL, const char *hostkey = NULL, const char *hostsymname = NULL) { - nvme_host_t h; - if (nvme_get_host(ctx, hostnqn, hostid, &h)) + libnvme_host_t h; + if (libnvme_get_host(ctx, hostnqn, hostid, &h)) return NULL; if (hostsymname) - nvme_host_set_hostsymname(h, hostsymname); + libnvme_host_set_hostsymname(h, hostsymname); if (hostkey) - nvme_host_set_dhchap_host_key(h, hostkey); + libnvme_host_set_dhchap_host_key(h, hostkey); return h; } - ~nvme_host() { - nvme_free_host($self); + ~libnvme_host() { + libnvme_free_host($self); } - struct nvme_host* __enter__() { + struct libnvme_host* __enter__() { return $self; } - struct nvme_host* __exit__(PyObject *type, PyObject *value, PyObject *traceback) { + struct libnvme_host* __exit__(PyObject *type, PyObject *value, PyObject *traceback) { return $self; } %feature("autodoc", SET_SYMNAME_DOCSTRING) set_symname; void set_symname(const char *hostsymname) { - nvme_host_set_hostsymname($self, hostsymname); + libnvme_host_set_hostsymname($self, hostsymname); } PyObject* __str__() { @@ -585,46 +585,46 @@ struct nvme_ns { %pythoncode %{ def subsystems(self): """Iterator over all subsystem objects""" - s = nvme_first_subsystem(self) + s = libnvme_first_subsystem(self) while s: yield s - s = nvme_next_subsystem(self, s) + s = libnvme_next_subsystem(self, s) %} } %{ - const char *nvme_host_dhchap_host_key_get(struct nvme_host *h) { - return nvme_host_get_dhchap_host_key(h); + const char *libnvme_host_dhchap_host_key_get(struct libnvme_host *h) { + return libnvme_host_get_dhchap_host_key(h); } - void nvme_host_dhchap_host_key_set(struct nvme_host *h, char *key) { - nvme_host_set_dhchap_host_key(h, key); + void libnvme_host_dhchap_host_key_set(struct libnvme_host *h, char *key) { + libnvme_host_set_dhchap_host_key(h, key); } %}; -%pythonappend nvme_subsystem::nvme_subsystem(struct nvme_global_ctx *ctx, - struct nvme_host *host, +%pythonappend libnvme_subsystem::libnvme_subsystem(struct libnvme_global_ctx *ctx, + struct libnvme_host *host, const char *subsysnqn, const char *name) { self.__parent = host # Keep a reference to parent to ensure garbage collection happens in the right order} -%extend nvme_subsystem { - nvme_subsystem(struct nvme_global_ctx *ctx, - struct nvme_host *host, +%extend libnvme_subsystem { + libnvme_subsystem(struct libnvme_global_ctx *ctx, + struct libnvme_host *host, const char *subsysnqn, const char *name = NULL) { - struct nvme_subsystem *s; + struct libnvme_subsystem *s; - if (nvme_get_subsystem(ctx, host, name, subsysnqn, &s)) + if (libnvme_get_subsystem(ctx, host, name, subsysnqn, &s)) return NULL; return s; } - ~nvme_subsystem() { - nvme_free_subsystem($self); + ~libnvme_subsystem() { + libnvme_free_subsystem($self); } - struct nvme_subsystem* __enter__() { + struct libnvme_subsystem* __enter__() { return $self; } - struct nvme_subsystem* __exit__(PyObject *type, PyObject *value, PyObject *traceback) { + struct libnvme_subsystem* __exit__(PyObject *type, PyObject *value, PyObject *traceback) { return $self; } PyObject *__str__() { @@ -633,87 +633,87 @@ struct nvme_ns { %pythoncode %{ def controllers(self): """Iterator over all controller objects""" - c = nvme_subsystem_first_ctrl(self) + c = libnvme_subsystem_first_ctrl(self) while c: yield c - c = nvme_subsystem_next_ctrl(self, c) + c = libnvme_subsystem_next_ctrl(self, c) %} %pythoncode %{ def namespaces(self): """Iterator over all namespace objects""" - ns = nvme_subsystem_first_ns(self) + ns = libnvme_subsystem_first_ns(self) while ns: yield ns - ns = nvme_subsystem_next_ns(self, ns) + ns = libnvme_subsystem_next_ns(self, ns) %} %immutable name; const char *name; %immutable host; - struct nvme_host *host; + struct libnvme_host *host; } %{ - const char *nvme_subsystem_name_get(struct nvme_subsystem *s) { - return nvme_subsystem_get_name(s); + const char *libnvme_subsystem_name_get(struct libnvme_subsystem *s) { + return libnvme_subsystem_get_name(s); } - struct nvme_host *nvme_subsystem_host_get(struct nvme_subsystem *s) { - return nvme_subsystem_get_host(s); + struct libnvme_host *libnvme_subsystem_host_get(struct libnvme_subsystem *s) { + return libnvme_subsystem_get_host(s); } - const char *nvme_subsystem_sysfs_dir_get(struct nvme_subsystem *s) { - return nvme_subsystem_get_sysfs_dir(s); + const char *libnvme_subsystem_sysfs_dir_get(struct libnvme_subsystem *s) { + return libnvme_subsystem_get_sysfs_dir(s); } - const char *nvme_subsystem_iopolicy_get(struct nvme_subsystem *s) { - return nvme_subsystem_get_iopolicy(s); + const char *libnvme_subsystem_iopolicy_get(struct libnvme_subsystem *s) { + return libnvme_subsystem_get_iopolicy(s); } - const char *nvme_subsystem_application_get(struct nvme_subsystem *s) { - return nvme_subsystem_get_application(s); + const char *libnvme_subsystem_application_get(struct libnvme_subsystem *s) { + return libnvme_subsystem_get_application(s); } - void nvme_subsystem_application_set(struct nvme_subsystem *s, const char *a) { - nvme_subsystem_set_application(s, a); + void libnvme_subsystem_application_set(struct libnvme_subsystem *s, const char *a) { + libnvme_subsystem_set_application(s, a); } %}; -%pythonappend nvme_ctrl::connect(struct nvme_host *h, - struct nvme_fabrics_config *cfg) { +%pythonappend libnvme_ctrl::connect(struct libnvme_host *h, + struct libnvme_fabrics_config *cfg) { self.__host = h # Keep a reference to parent to ensure ctrl obj gets GCed before host} -%pythonappend nvme_ctrl::init(struct nvme_host *h, int instance) { +%pythonappend libnvme_ctrl::init(struct libnvme_host *h, int instance) { self.__host = h # Keep a reference to parent to ensure ctrl obj gets GCed before host} -%extend nvme_ctrl { - nvme_ctrl(struct nvme_global_ctx *ctx, +%extend libnvme_ctrl { + libnvme_ctrl(struct libnvme_global_ctx *ctx, const char *subsysnqn, const char *transport, const char *traddr = NULL, const char *host_traddr = NULL, const char *host_iface = NULL, const char *trsvcid = NULL) { - struct nvme_ctrl *c; - if (nvme_create_ctrl(ctx, subsysnqn, transport, traddr, + struct libnvme_ctrl *c; + if (libnvme_create_ctrl(ctx, subsysnqn, transport, traddr, host_traddr, host_iface, trsvcid, &c)) return NULL; return c; } - ~nvme_ctrl() { - nvme_free_ctrl($self); + ~libnvme_ctrl() { + libnvme_free_ctrl($self); } - struct nvme_ctrl* __enter__() { + struct libnvme_ctrl* __enter__() { return $self; } - struct nvme_ctrl* __exit__(PyObject *type, PyObject *value, PyObject *traceback) { - if (nvme_ctrl_get_name($self)) - nvme_disconnect_ctrl($self); + struct libnvme_ctrl* __exit__(PyObject *type, PyObject *value, PyObject *traceback) { + if (libnvme_ctrl_get_name($self)) + libnvme_disconnect_ctrl($self); return $self; } - bool init(struct nvme_host *h, int instance) { - return nvme_init_ctrl(h, $self, instance) == 0; + bool init(struct libnvme_host *h, int instance) { + return libnvme_init_ctrl(h, $self, instance) == 0; } - void connect(struct nvme_host *h, - struct nvme_fabrics_config *cfg = NULL) { + void connect(struct libnvme_host *h, + struct libnvme_fabrics_config *cfg = NULL) { int ret; const char *dev; - dev = nvme_ctrl_get_name($self); + dev = libnvme_ctrl_get_name($self); if (dev && !cfg->duplicate_connect) { connect_err = -ENVME_CONNECT_ALREADY; return; @@ -729,22 +729,22 @@ struct nvme_ns { } } bool connected() { - return nvme_ctrl_get_name($self) != NULL; + return libnvme_ctrl_get_name($self) != NULL; } void rescan() { - nvme_rescan_ctrl($self); + libnvme_rescan_ctrl($self); } void disconnect() { int ret; const char *dev; - dev = nvme_ctrl_get_name($self); + dev = libnvme_ctrl_get_name($self); if (!dev) { connect_err = 1; return; } Py_BEGIN_ALLOW_THREADS /* Release Python GIL */ - ret = nvme_disconnect_ctrl($self); + ret = libnvme_disconnect_ctrl($self); Py_END_ALLOW_THREADS /* Reacquire Python GIL */ if (ret < 0) connect_err = 2; @@ -767,8 +767,8 @@ struct nvme_ns { if (status != NVME_SC_SUCCESS) { /* On error, return an error message */ return (status < 0) ? - PyUnicode_FromFormat("Status:0x%04x - %s", status, nvme_status_to_string(status, false)) : - PyUnicode_FromFormat("Result:0x%04x, Status:0x%04x - %s", result, status, nvme_status_to_string(status, false)); + PyUnicode_FromFormat("Status:0x%04x - %s", status, libnvme_status_to_string(status, false)) : + PyUnicode_FromFormat("Result:0x%04x, Status:0x%04x - %s", result, status, libnvme_status_to_string(status, false)); } /* On success, return None */ @@ -779,7 +779,7 @@ struct nvme_ns { struct nvmf_discovery_log *discover(int lsp = 0, int max_retries = 6) { const char *dev; struct nvmf_discovery_log *logp = NULL; - struct nvme_get_discovery_args args = { + struct libnvme_get_discovery_args args = { .c = $self, .args_size = sizeof(args), .max_retries = max_retries, @@ -788,7 +788,7 @@ struct nvme_ns { .lsp = lsp, }; - dev = nvme_ctrl_get_name($self); + dev = libnvme_ctrl_get_name($self); if (!dev) { discover_err = 1; return NULL; @@ -804,13 +804,13 @@ struct nvme_ns { %feature("autodoc", "@return: List of supported log pages") supported_log_pages; PyObject *supported_log_pages(bool rae = true) { struct nvme_supported_log_pages log; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; PyObject *obj = NULL; int ret = 0; Py_BEGIN_ALLOW_THREADS /* Release Python GIL */ nvme_init_get_log_supported_log_pages(&cmd, NVME_CSI_NVM, &log); - ret = nvme_get_log(nvme_ctrl_get_transport_handle($self), &cmd, rae, NVME_LOG_PAGE_PDU_SIZE); + ret = libnvme_get_log(libnvme_ctrl_get_transport_handle($self), &cmd, rae, NVME_LOG_PAGE_PDU_SIZE); Py_END_ALLOW_THREADS /* Reacquire Python GIL */ if (ret) { @@ -828,17 +828,17 @@ struct nvme_ns { PyObject* __str__() { return $self->address ? - PyUnicode_FromFormat("nvme_ctrl(transport=%s,%s)", STR_OR_NONE($self->transport), STR_OR_NONE($self->address)) : - PyUnicode_FromFormat("nvme_ctrl(transport=%s)", STR_OR_NONE($self->transport)); + PyUnicode_FromFormat("libnvme_ctrl(transport=%s,%s)", STR_OR_NONE($self->transport), STR_OR_NONE($self->address)) : + PyUnicode_FromFormat("libnvme_ctrl(transport=%s)", STR_OR_NONE($self->transport)); } %pythoncode %{ def namespaces(self): """Iterator over all namespace objects""" - ns = nvme_ctrl_first_ns(self) + ns = libnvme_ctrl_first_ns(self) while ns: yield ns - ns = nvme_ctrl_next_ns(self, ns) + ns = libnvme_ctrl_next_ns(self, ns) %} } @@ -851,147 +851,147 @@ struct nvme_ns { * * SWIG libnvme.map * ====================== ======================= - * nvme_ctrl_[member]_get -> nvme_ctrl_get_[member] - * nvme_ctrl_[member]_set -> nvme_ctrl_set_[member] + * libnvme_ctrl_[member]_get -> libnvme_ctrl_get_[member] + * libnvme_ctrl_[member]_set -> libnvme_ctrl_set_[member] * */ - const char *nvme_ctrl_name_get(struct nvme_ctrl *c) { - return nvme_ctrl_get_name(c); + const char *libnvme_ctrl_name_get(struct libnvme_ctrl *c) { + return libnvme_ctrl_get_name(c); } - struct nvme_subsystem *nvme_ctrl_subsystem_get(struct nvme_ctrl *c) { - return nvme_ctrl_get_subsystem(c); + struct libnvme_subsystem *libnvme_ctrl_subsystem_get(struct libnvme_ctrl *c) { + return libnvme_ctrl_get_subsystem(c); } - const char *nvme_ctrl_state_get(struct nvme_ctrl *c) { - return nvme_ctrl_get_state(c); + const char *libnvme_ctrl_state_get(struct libnvme_ctrl *c) { + return libnvme_ctrl_get_state(c); } - const char *nvme_ctrl_dhchap_ctrl_key_get(struct nvme_ctrl *c) { - return nvme_ctrl_get_dhchap_ctrl_key(c); + const char *libnvme_ctrl_dhchap_ctrl_key_get(struct libnvme_ctrl *c) { + return libnvme_ctrl_get_dhchap_ctrl_key(c); } - void nvme_ctrl_dhchap_ctrl_key_set(struct nvme_ctrl *c, const char *key) { - nvme_ctrl_set_dhchap_ctrl_key(c, key); + void libnvme_ctrl_dhchap_ctrl_key_set(struct libnvme_ctrl *c, const char *key) { + libnvme_ctrl_set_dhchap_ctrl_key(c, key); } - const char *nvme_ctrl_dhchap_host_key_get(struct nvme_ctrl *c) { - return nvme_ctrl_get_dhchap_host_key(c); + const char *libnvme_ctrl_dhchap_host_key_get(struct libnvme_ctrl *c) { + return libnvme_ctrl_get_dhchap_host_key(c); } - void nvme_ctrl_dhchap_host_key_set(struct nvme_ctrl *c, const char *key) { - nvme_ctrl_set_dhchap_host_key(c, key); + void libnvme_ctrl_dhchap_host_key_set(struct libnvme_ctrl *c, const char *key) { + libnvme_ctrl_set_dhchap_host_key(c, key); } - const char *nvme_ctrl_cntlid_get(nvme_ctrl_t c) { - return nvme_ctrl_get_cntlid(c); + const char *libnvme_ctrl_cntlid_get(libnvme_ctrl_t c) { + return libnvme_ctrl_get_cntlid(c); } - bool nvme_ctrl_persistent_get(struct nvme_ctrl *c) { - return nvme_ctrl_get_persistent(c); + bool libnvme_ctrl_persistent_get(struct libnvme_ctrl *c) { + return libnvme_ctrl_get_persistent(c); } - void nvme_ctrl_persistent_set(struct nvme_ctrl *c, bool persistent) { - nvme_ctrl_set_persistent(c, persistent); + void libnvme_ctrl_persistent_set(struct libnvme_ctrl *c, bool persistent) { + libnvme_ctrl_set_persistent(c, persistent); } - const char *nvme_ctrl_phy_slot_get(nvme_ctrl_t c) { - return nvme_ctrl_get_phy_slot(c); + const char *libnvme_ctrl_phy_slot_get(libnvme_ctrl_t c) { + return libnvme_ctrl_get_phy_slot(c); } - const char *nvme_ctrl_trsvcid_get(nvme_ctrl_t c) { - return nvme_ctrl_get_trsvcid(c); + const char *libnvme_ctrl_trsvcid_get(libnvme_ctrl_t c) { + return libnvme_ctrl_get_trsvcid(c); } - const char *nvme_ctrl_traddr_get(nvme_ctrl_t c) { - return nvme_ctrl_get_traddr(c); + const char *libnvme_ctrl_traddr_get(libnvme_ctrl_t c) { + return libnvme_ctrl_get_traddr(c); } - const char *nvme_ctrl_subsysnqn_get(nvme_ctrl_t c) { - return nvme_ctrl_get_subsysnqn(c); + const char *libnvme_ctrl_subsysnqn_get(libnvme_ctrl_t c) { + return libnvme_ctrl_get_subsysnqn(c); } - const char *nvme_ctrl_transport_get(nvme_ctrl_t c) { - return nvme_ctrl_get_transport(c); + const char *libnvme_ctrl_transport_get(libnvme_ctrl_t c) { + return libnvme_ctrl_get_transport(c); } - const char *nvme_ctrl_sqsize_get(nvme_ctrl_t c) { - return nvme_ctrl_get_sqsize(c); + const char *libnvme_ctrl_sqsize_get(libnvme_ctrl_t c) { + return libnvme_ctrl_get_sqsize(c); } - const char *nvme_ctrl_serial_get(nvme_ctrl_t c) { - return nvme_ctrl_get_serial(c); + const char *libnvme_ctrl_serial_get(libnvme_ctrl_t c) { + return libnvme_ctrl_get_serial(c); } - const char *nvme_ctrl_queue_count_get(nvme_ctrl_t c) { - return nvme_ctrl_get_queue_count(c); + const char *libnvme_ctrl_queue_count_get(libnvme_ctrl_t c) { + return libnvme_ctrl_get_queue_count(c); } - const char *nvme_ctrl_numa_node_get(nvme_ctrl_t c) { - return nvme_ctrl_get_numa_node(c); + const char *libnvme_ctrl_numa_node_get(libnvme_ctrl_t c) { + return libnvme_ctrl_get_numa_node(c); } - const char *nvme_ctrl_model_get(nvme_ctrl_t c) { - return nvme_ctrl_get_model(c); + const char *libnvme_ctrl_model_get(libnvme_ctrl_t c) { + return libnvme_ctrl_get_model(c); } - const char *nvme_ctrl_firmware_get(nvme_ctrl_t c) { - return nvme_ctrl_get_firmware(c); + const char *libnvme_ctrl_firmware_get(libnvme_ctrl_t c) { + return libnvme_ctrl_get_firmware(c); } - const char *nvme_ctrl_address_get(nvme_ctrl_t c) { - return nvme_ctrl_get_traddr(c); + const char *libnvme_ctrl_address_get(libnvme_ctrl_t c) { + return libnvme_ctrl_get_traddr(c); } - const char *nvme_ctrl_sysfs_dir_get(nvme_ctrl_t c) { - return nvme_ctrl_get_sysfs_dir(c); + const char *libnvme_ctrl_sysfs_dir_get(libnvme_ctrl_t c) { + return libnvme_ctrl_get_sysfs_dir(c); } - bool nvme_ctrl_discovery_ctrl_get(struct nvme_ctrl *c) { - return nvme_ctrl_get_discovery_ctrl(c); + bool libnvme_ctrl_discovery_ctrl_get(struct libnvme_ctrl *c) { + return libnvme_ctrl_get_discovery_ctrl(c); } - void nvme_ctrl_discovery_ctrl_set(struct nvme_ctrl *c, bool discovery) { - nvme_ctrl_set_discovery_ctrl(c, discovery); + void libnvme_ctrl_discovery_ctrl_set(struct libnvme_ctrl *c, bool discovery) { + libnvme_ctrl_set_discovery_ctrl(c, discovery); } - bool nvme_ctrl_unique_discovery_ctrl_get(nvme_ctrl_t c) { - return nvme_ctrl_get_unique_discovery_ctrl(c); + bool libnvme_ctrl_unique_discovery_ctrl_get(libnvme_ctrl_t c) { + return libnvme_ctrl_get_unique_discovery_ctrl(c); } - void nvme_ctrl_unique_discovery_ctrl_set(nvme_ctrl_t c, bool unique) { - nvme_ctrl_set_unique_discovery_ctrl(c, unique); + void libnvme_ctrl_unique_discovery_ctrl_set(libnvme_ctrl_t c, bool unique) { + libnvme_ctrl_set_unique_discovery_ctrl(c, unique); } - const char *nvme_ctrl_keyring_get(nvme_ctrl_t c) { - return nvme_ctrl_get_keyring(c); + const char *libnvme_ctrl_keyring_get(libnvme_ctrl_t c) { + return libnvme_ctrl_get_keyring(c); } - void nvme_ctrl_keyring_set(nvme_ctrl_t c, const char *keyring) { - nvme_ctrl_set_keyring(c, keyring); + void libnvme_ctrl_keyring_set(libnvme_ctrl_t c, const char *keyring) { + libnvme_ctrl_set_keyring(c, keyring); } - const char *nvme_ctrl_tls_key_identity_get(nvme_ctrl_t c) { - return nvme_ctrl_get_tls_key_identity(c); + const char *libnvme_ctrl_tls_key_identity_get(libnvme_ctrl_t c) { + return libnvme_ctrl_get_tls_key_identity(c); } - void nvme_ctrl_tls_key_identity_set(nvme_ctrl_t c, const char *identity) { - nvme_ctrl_set_tls_key_identity(c, identity); + void libnvme_ctrl_tls_key_identity_set(libnvme_ctrl_t c, const char *identity) { + libnvme_ctrl_set_tls_key_identity(c, identity); } - const char *nvme_ctrl_tls_key_get(nvme_ctrl_t c) { - return nvme_ctrl_get_tls_key(c); + const char *libnvme_ctrl_tls_key_get(libnvme_ctrl_t c) { + return libnvme_ctrl_get_tls_key(c); } - void nvme_ctrl_tls_key_set(nvme_ctrl_t c, const char *key) { - nvme_ctrl_set_tls_key(c, key); + void libnvme_ctrl_tls_key_set(libnvme_ctrl_t c, const char *key) { + libnvme_ctrl_set_tls_key(c, key); } %} -%pythonappend nvme_ns::nvme_ns(struct nvme_subsystem *s, +%pythonappend libnvme_ns::libnvme_ns(struct libnvme_subsystem *s, unsigned int nsid) { self.__parent = s # Keep a reference to parent to ensure garbage collection happens in the right order} -%extend nvme_ns { - nvme_ns(struct nvme_subsystem *s, +%extend libnvme_ns { + libnvme_ns(struct libnvme_subsystem *s, unsigned int nsid) { - return nvme_subsystem_lookup_namespace(s, nsid); + return libnvme_subsystem_lookup_namespace(s, nsid); } - ~nvme_ns() { - nvme_free_ns($self); + ~libnvme_ns() { + libnvme_free_ns($self); } - struct nvme_ns* __enter__() { + struct libnvme_ns* __enter__() { return $self; } - struct nvme_ns* __exit__(PyObject *type, PyObject *value, PyObject *traceback) { + struct libnvme_ns* __exit__(PyObject *type, PyObject *value, PyObject *traceback) { return $self; } PyObject *__str__() { @@ -1002,8 +1002,8 @@ struct nvme_ns { } %{ - const char *nvme_ns_name_get(struct nvme_ns *n) { - return nvme_ns_get_name(n); + const char *libnvme_ns_name_get(struct libnvme_ns *n) { + return libnvme_ns_get_name(n); } %}; @@ -1051,7 +1051,7 @@ struct nvme_ns { { char uuid_str[NVME_UUID_LEN_STRING]; PyDict_SetItemStringDecRef(output, "nid_type", PyUnicode_FromString("uuid")); - nvme_uuid_to_string(ss->nid, uuid_str); + libnvme_uuid_to_string(ss->nid, uuid_str); nid = PyUnicode_FromString(uuid_str); break; } @@ -1150,7 +1150,7 @@ struct nvme_ns { PyDict_SetItemStringDecRef(host, "nqn", PyUnicode_FromString(nbft->host.nqn)); if (nbft->host.id) { char uuid_str[NVME_UUID_LEN_STRING]; - nvme_uuid_to_string((unsigned char *)nbft->host.id, uuid_str); + libnvme_uuid_to_string((unsigned char *)nbft->host.id, uuid_str); PyDict_SetItemStringDecRef(host, "id", PyUnicode_FromString(uuid_str)); } @@ -1224,26 +1224,26 @@ struct nvme_ns { return output; } - PyObject *nbft_get(struct nvme_global_ctx *ctx, const char * filename) + PyObject *nbft_get(struct libnvme_global_ctx *ctx, const char * filename) { struct nbft_info *nbft; PyObject *output; int ret; - ret = nvme_read_nbft(ctx, &nbft, filename); + ret = libnvme_read_nbft(ctx, &nbft, filename); if (ret) { Py_RETURN_NONE; } output = nbft_to_pydict(nbft); - nvme_free_nbft(ctx, nbft); + libnvme_free_nbft(ctx, nbft); return output; } %}; %feature("autodoc", "@return an NBFT table as a dict on success, None otherwise.\n" "@param filename: file to read") nbft_get; -PyObject *nbft_get(struct nvme_global_ctx *ctx, const char * filename); +PyObject *nbft_get(struct libnvme_global_ctx *ctx, const char * filename); // We want to swig all the #define and enum from types.h, but none of the structs. #pragma SWIG nowarn=503 // Supress warnings about unnamed struct diff --git a/libnvme/src/accessors.ld b/libnvme/src/accessors.ld index 3cd26f8f7d..58aa702356 100644 --- a/libnvme/src/accessors.ld +++ b/libnvme/src/accessors.ld @@ -10,145 +10,145 @@ LIBNVME_ACCESSORS_3 { global: - nvme_path_get_name; - nvme_path_set_name; - nvme_path_get_sysfs_dir; - nvme_path_set_sysfs_dir; - nvme_path_get_ana_state; - nvme_path_set_ana_state; - nvme_path_get_numa_nodes; - nvme_path_set_numa_nodes; - nvme_path_get_grpid; - nvme_path_set_grpid; - nvme_ns_get_nsid; - nvme_ns_set_nsid; - nvme_ns_get_name; - nvme_ns_set_name; - nvme_ns_get_sysfs_dir; - nvme_ns_set_sysfs_dir; - nvme_ns_get_lba_shift; - nvme_ns_set_lba_shift; - nvme_ns_get_lba_size; - nvme_ns_set_lba_size; - nvme_ns_get_meta_size; - nvme_ns_set_meta_size; - nvme_ns_get_lba_count; - nvme_ns_set_lba_count; - nvme_ns_get_lba_util; - nvme_ns_set_lba_util; - nvme_ctrl_get_name; - nvme_ctrl_get_sysfs_dir; - nvme_ctrl_get_firmware; - nvme_ctrl_get_model; - nvme_ctrl_get_numa_node; - nvme_ctrl_get_queue_count; - nvme_ctrl_get_serial; - nvme_ctrl_get_sqsize; - nvme_ctrl_get_transport; - nvme_ctrl_get_subsysnqn; - nvme_ctrl_get_traddr; - nvme_ctrl_get_trsvcid; - nvme_ctrl_get_dhchap_host_key; - nvme_ctrl_set_dhchap_host_key; - nvme_ctrl_get_dhchap_ctrl_key; - nvme_ctrl_set_dhchap_ctrl_key; - nvme_ctrl_get_keyring; - nvme_ctrl_set_keyring; - nvme_ctrl_get_tls_key_identity; - nvme_ctrl_set_tls_key_identity; - nvme_ctrl_get_tls_key; - nvme_ctrl_set_tls_key; - nvme_ctrl_get_cntrltype; - nvme_ctrl_get_cntlid; - nvme_ctrl_get_dctype; - nvme_ctrl_get_host_traddr; - nvme_ctrl_get_host_iface; - nvme_ctrl_get_discovery_ctrl; - nvme_ctrl_set_discovery_ctrl; - nvme_ctrl_get_unique_discovery_ctrl; - nvme_ctrl_set_unique_discovery_ctrl; - nvme_ctrl_get_discovered; - nvme_ctrl_set_discovered; - nvme_ctrl_get_persistent; - nvme_ctrl_set_persistent; - nvme_ctrl_get_phy_slot; - nvme_subsystem_get_name; - nvme_subsystem_get_sysfs_dir; - nvme_subsystem_get_subsysnqn; - nvme_subsystem_get_model; - nvme_subsystem_get_serial; - nvme_subsystem_get_firmware; - nvme_subsystem_get_subsystype; - nvme_subsystem_get_application; - nvme_subsystem_set_application; - nvme_subsystem_get_iopolicy; - nvme_subsystem_set_iopolicy; - nvme_host_get_hostnqn; - nvme_host_get_hostid; - nvme_host_get_dhchap_host_key; - nvme_host_set_dhchap_host_key; - nvme_host_get_hostsymname; - nvme_host_set_hostsymname; - nvme_host_get_pdc_enabled_valid; - nvme_host_set_pdc_enabled_valid; - nvme_fabric_options_get_cntlid; - nvme_fabric_options_set_cntlid; - nvme_fabric_options_get_concat; - nvme_fabric_options_set_concat; - nvme_fabric_options_get_ctrl_loss_tmo; - nvme_fabric_options_set_ctrl_loss_tmo; - nvme_fabric_options_get_data_digest; - nvme_fabric_options_set_data_digest; - nvme_fabric_options_get_dhchap_ctrl_secret; - nvme_fabric_options_set_dhchap_ctrl_secret; - nvme_fabric_options_get_dhchap_secret; - nvme_fabric_options_set_dhchap_secret; - nvme_fabric_options_get_disable_sqflow; - nvme_fabric_options_set_disable_sqflow; - nvme_fabric_options_get_discovery; - nvme_fabric_options_set_discovery; - nvme_fabric_options_get_duplicate_connect; - nvme_fabric_options_set_duplicate_connect; - nvme_fabric_options_get_fast_io_fail_tmo; - nvme_fabric_options_set_fast_io_fail_tmo; - nvme_fabric_options_get_hdr_digest; - nvme_fabric_options_set_hdr_digest; - nvme_fabric_options_get_host_iface; - nvme_fabric_options_set_host_iface; - nvme_fabric_options_get_host_traddr; - nvme_fabric_options_set_host_traddr; - nvme_fabric_options_get_hostid; - nvme_fabric_options_set_hostid; - nvme_fabric_options_get_hostnqn; - nvme_fabric_options_set_hostnqn; - nvme_fabric_options_get_instance; - nvme_fabric_options_set_instance; - nvme_fabric_options_get_keep_alive_tmo; - nvme_fabric_options_set_keep_alive_tmo; - nvme_fabric_options_get_keyring; - nvme_fabric_options_set_keyring; - nvme_fabric_options_get_nqn; - nvme_fabric_options_set_nqn; - nvme_fabric_options_get_nr_io_queues; - nvme_fabric_options_set_nr_io_queues; - nvme_fabric_options_get_nr_poll_queues; - nvme_fabric_options_set_nr_poll_queues; - nvme_fabric_options_get_nr_write_queues; - nvme_fabric_options_set_nr_write_queues; - nvme_fabric_options_get_queue_size; - nvme_fabric_options_set_queue_size; - nvme_fabric_options_get_reconnect_delay; - nvme_fabric_options_set_reconnect_delay; - nvme_fabric_options_get_tls; - nvme_fabric_options_set_tls; - nvme_fabric_options_get_tls_key; - nvme_fabric_options_set_tls_key; - nvme_fabric_options_get_tos; - nvme_fabric_options_set_tos; - nvme_fabric_options_get_traddr; - nvme_fabric_options_set_traddr; - nvme_fabric_options_get_transport; - nvme_fabric_options_set_transport; - nvme_fabric_options_get_trsvcid; - nvme_fabric_options_set_trsvcid; + libnvme_path_get_name; + libnvme_path_set_name; + libnvme_path_get_sysfs_dir; + libnvme_path_set_sysfs_dir; + libnvme_path_get_ana_state; + libnvme_path_set_ana_state; + libnvme_path_get_numa_nodes; + libnvme_path_set_numa_nodes; + libnvme_path_get_grpid; + libnvme_path_set_grpid; + libnvme_ns_get_nsid; + libnvme_ns_set_nsid; + libnvme_ns_get_name; + libnvme_ns_set_name; + libnvme_ns_get_sysfs_dir; + libnvme_ns_set_sysfs_dir; + libnvme_ns_get_lba_shift; + libnvme_ns_set_lba_shift; + libnvme_ns_get_lba_size; + libnvme_ns_set_lba_size; + libnvme_ns_get_meta_size; + libnvme_ns_set_meta_size; + libnvme_ns_get_lba_count; + libnvme_ns_set_lba_count; + libnvme_ns_get_lba_util; + libnvme_ns_set_lba_util; + libnvme_ctrl_get_name; + libnvme_ctrl_get_sysfs_dir; + libnvme_ctrl_get_firmware; + libnvme_ctrl_get_model; + libnvme_ctrl_get_numa_node; + libnvme_ctrl_get_queue_count; + libnvme_ctrl_get_serial; + libnvme_ctrl_get_sqsize; + libnvme_ctrl_get_transport; + libnvme_ctrl_get_subsysnqn; + libnvme_ctrl_get_traddr; + libnvme_ctrl_get_trsvcid; + libnvme_ctrl_get_dhchap_host_key; + libnvme_ctrl_set_dhchap_host_key; + libnvme_ctrl_get_dhchap_ctrl_key; + libnvme_ctrl_set_dhchap_ctrl_key; + libnvme_ctrl_get_keyring; + libnvme_ctrl_set_keyring; + libnvme_ctrl_get_tls_key_identity; + libnvme_ctrl_set_tls_key_identity; + libnvme_ctrl_get_tls_key; + libnvme_ctrl_set_tls_key; + libnvme_ctrl_get_cntrltype; + libnvme_ctrl_get_cntlid; + libnvme_ctrl_get_dctype; + libnvme_ctrl_get_host_traddr; + libnvme_ctrl_get_host_iface; + libnvme_ctrl_get_discovery_ctrl; + libnvme_ctrl_set_discovery_ctrl; + libnvme_ctrl_get_unique_discovery_ctrl; + libnvme_ctrl_set_unique_discovery_ctrl; + libnvme_ctrl_get_discovered; + libnvme_ctrl_set_discovered; + libnvme_ctrl_get_persistent; + libnvme_ctrl_set_persistent; + libnvme_ctrl_get_phy_slot; + libnvme_subsystem_get_name; + libnvme_subsystem_get_sysfs_dir; + libnvme_subsystem_get_subsysnqn; + libnvme_subsystem_get_model; + libnvme_subsystem_get_serial; + libnvme_subsystem_get_firmware; + libnvme_subsystem_get_subsystype; + libnvme_subsystem_get_application; + libnvme_subsystem_set_application; + libnvme_subsystem_get_iopolicy; + libnvme_subsystem_set_iopolicy; + libnvme_host_get_hostnqn; + libnvme_host_get_hostid; + libnvme_host_get_dhchap_host_key; + libnvme_host_set_dhchap_host_key; + libnvme_host_get_hostsymname; + libnvme_host_set_hostsymname; + libnvme_host_get_pdc_enabled_valid; + libnvme_host_set_pdc_enabled_valid; + libnvme_fabric_options_get_cntlid; + libnvme_fabric_options_set_cntlid; + libnvme_fabric_options_get_concat; + libnvme_fabric_options_set_concat; + libnvme_fabric_options_get_ctrl_loss_tmo; + libnvme_fabric_options_set_ctrl_loss_tmo; + libnvme_fabric_options_get_data_digest; + libnvme_fabric_options_set_data_digest; + libnvme_fabric_options_get_dhchap_ctrl_secret; + libnvme_fabric_options_set_dhchap_ctrl_secret; + libnvme_fabric_options_get_dhchap_secret; + libnvme_fabric_options_set_dhchap_secret; + libnvme_fabric_options_get_disable_sqflow; + libnvme_fabric_options_set_disable_sqflow; + libnvme_fabric_options_get_discovery; + libnvme_fabric_options_set_discovery; + libnvme_fabric_options_get_duplicate_connect; + libnvme_fabric_options_set_duplicate_connect; + libnvme_fabric_options_get_fast_io_fail_tmo; + libnvme_fabric_options_set_fast_io_fail_tmo; + libnvme_fabric_options_get_hdr_digest; + libnvme_fabric_options_set_hdr_digest; + libnvme_fabric_options_get_host_iface; + libnvme_fabric_options_set_host_iface; + libnvme_fabric_options_get_host_traddr; + libnvme_fabric_options_set_host_traddr; + libnvme_fabric_options_get_hostid; + libnvme_fabric_options_set_hostid; + libnvme_fabric_options_get_hostnqn; + libnvme_fabric_options_set_hostnqn; + libnvme_fabric_options_get_instance; + libnvme_fabric_options_set_instance; + libnvme_fabric_options_get_keep_alive_tmo; + libnvme_fabric_options_set_keep_alive_tmo; + libnvme_fabric_options_get_keyring; + libnvme_fabric_options_set_keyring; + libnvme_fabric_options_get_nqn; + libnvme_fabric_options_set_nqn; + libnvme_fabric_options_get_nr_io_queues; + libnvme_fabric_options_set_nr_io_queues; + libnvme_fabric_options_get_nr_poll_queues; + libnvme_fabric_options_set_nr_poll_queues; + libnvme_fabric_options_get_nr_write_queues; + libnvme_fabric_options_set_nr_write_queues; + libnvme_fabric_options_get_queue_size; + libnvme_fabric_options_set_queue_size; + libnvme_fabric_options_get_reconnect_delay; + libnvme_fabric_options_set_reconnect_delay; + libnvme_fabric_options_get_tls; + libnvme_fabric_options_set_tls; + libnvme_fabric_options_get_tls_key; + libnvme_fabric_options_set_tls_key; + libnvme_fabric_options_get_tos; + libnvme_fabric_options_set_tos; + libnvme_fabric_options_get_traddr; + libnvme_fabric_options_set_traddr; + libnvme_fabric_options_get_transport; + libnvme_fabric_options_set_transport; + libnvme_fabric_options_get_trsvcid; + libnvme_fabric_options_set_trsvcid; }; diff --git a/libnvme/src/libnvme.ld b/libnvme/src/libnvme.ld index 2a34886af2..59f5232c51 100644 --- a/libnvme/src/libnvme.ld +++ b/libnvme/src/libnvme.ld @@ -2,199 +2,200 @@ LIBNVME_3 { global: - nvme_clear_etdas; - nvme_close; - nvme_create_ctrl; - nvme_create_global_ctx; - nvme_create_raw_secret; - nvme_ctrl_first_ns; - nvme_ctrl_first_path; - nvme_ctrl_get_config; - nvme_ctrl_get_phy_slot; - nvme_ctrl_get_src_addr; - nvme_ctrl_get_state; - nvme_ctrl_get_subsysnqn; - nvme_ctrl_get_subsystem; - nvme_ctrl_get_transport_handle; - nvme_ctrl_identify; - nvme_ctrl_match_config; - nvme_ctrl_next_ns; - nvme_ctrl_next_path; - nvme_ctrl_release_transport_handle; - nvme_describe_key_serial; - nvme_disconnect_ctrl; - nvme_dump_config; - nvme_dump_tree; - nvme_errno_to_string; - nvme_export_tls_key; - nvme_export_tls_key_versioned; - nvme_filter_ctrls; - nvme_filter_namespace; - nvme_filter_paths; - nvme_filter_subsys; - nvme_find_uuid; - nvme_first_host; - nvme_first_subsystem; - nvme_free_ctrl; - nvme_free_global_ctx; - nvme_free_host; - nvme_free_nbft; - nvme_free_ns; - nvme_free_subsystem; - nvme_gen_dhchap_key; - nvme_generate_hostid; - nvme_generate_hostnqn; - nvme_generate_hostnqn_from_hostid; - nvme_generate_tls_key_identity; - nvme_generate_tls_key_identity_compat; - nvme_get_ana_log_atomic; - nvme_get_ana_log_len; - nvme_get_ana_log_len_from_id_ctrl; - nvme_get_application; - nvme_get_attr; - nvme_get_ctrl_attr; - nvme_get_ctrl_telemetry; - nvme_get_directive_receive_length; - nvme_get_feature_length; - nvme_get_host; - nvme_get_host_telemetry; - nvme_get_log; - nvme_get_logging_level; - nvme_get_logical_block_size; - nvme_get_new_host_telemetry; - nvme_get_ns_attr; - nvme_get_nsid; - nvme_get_path_attr; - nvme_get_subsys_attr; - nvme_get_subsystem; - nvme_get_telemetry_log; - nvme_get_telemetry_max; - nvme_get_uuid_list; - nvme_get_version; - nvme_host_get_global_ctx; - nvme_host_get_ids; - nvme_host_is_pdc_enabled; - nvme_host_release_fds; - nvme_host_set_pdc_enabled; - nvme_import_tls_key; - nvme_import_tls_key_versioned; - nvme_init_ctrl; - nvme_insert_tls_key; - nvme_insert_tls_key_compat; - nvme_insert_tls_key_versioned; - nvme_lookup_key; - nvme_lookup_keyring; - nvme_mi_admin_xfer; - nvme_mi_aem_disable; - nvme_mi_aem_enable; - nvme_mi_aem_get_enabled; - nvme_mi_aem_get_fd; - nvme_mi_aem_get_next_event; - nvme_mi_aem_process; - nvme_mi_close; - nvme_mi_control; - nvme_mi_ctrl_id; - nvme_mi_endpoint_desc; - nvme_mi_ep_get_timeout; - nvme_mi_ep_set_timeout; - nvme_mi_first_endpoint; - nvme_mi_init_transport_handle; - nvme_mi_mi_config_get; - nvme_mi_mi_config_set; - nvme_mi_mi_read_mi_data_ctrl; - nvme_mi_mi_read_mi_data_ctrl_list; - nvme_mi_mi_read_mi_data_port; - nvme_mi_mi_read_mi_data_subsys; - nvme_mi_mi_subsystem_health_status_poll; - nvme_mi_mi_xfer; - nvme_mi_next_endpoint; - nvme_mi_open_mctp; - nvme_mi_scan_ep; - nvme_mi_scan_mctp; - nvme_mi_set_csi; - nvme_mi_status_to_string; - nvme_mi_submit_entry; - nvme_mi_submit_exit; - nvme_namespace_first_path; - nvme_namespace_next_path; - nvme_next_host; - nvme_next_subsystem; - nvme_ns_compare; - nvme_ns_flush; - nvme_ns_get_csi; - nvme_ns_get_ctrl; - nvme_ns_get_eui64; - nvme_ns_get_firmware; - nvme_ns_get_generic_name; - nvme_ns_get_model; - nvme_ns_get_nguid; - nvme_ns_get_serial; - nvme_ns_get_subsystem; - nvme_ns_get_uuid; - nvme_ns_identify; - nvme_ns_read; - nvme_ns_verify; - nvme_ns_write; - nvme_ns_write_uncorrectable; - nvme_ns_write_zeros; - nvme_open; - nvme_parse_uri; - nvme_path_get_ctrl; - nvme_path_get_ns; - nvme_path_get_queue_depth; - nvme_random_uuid; - nvme_read_config; - nvme_read_hostid; - nvme_read_hostnqn; - nvme_read_key; - nvme_read_nbft; - nvme_refresh_topology; - nvme_rescan_ctrl; - nvme_rescan_ns; - nvme_reset_ctrl; - nvme_reset_subsystem; - nvme_revoke_tls_key; - nvme_scan_ctrl; - nvme_scan_ctrl_namespace_paths; - nvme_scan_ctrl_namespaces; - nvme_scan_ctrls; - nvme_scan_namespace; - nvme_scan_subsystem_namespaces; - nvme_scan_subsystems; - nvme_scan_tls_keys; - nvme_scan_topology; - nvme_set_application; - nvme_set_dry_run; - nvme_set_etdas; - nvme_set_ioctl_probing; - nvme_set_keyring; - nvme_set_logging_level; - nvme_skip_namespaces; - nvme_status_to_errno; - nvme_status_to_string; - nvme_strerror; - nvme_submit_admin_passthru; - nvme_submit_io_passthru; - nvme_subsystem_first_ctrl; - nvme_subsystem_first_ns; - nvme_subsystem_get_host; - nvme_subsystem_lookup_namespace; - nvme_subsystem_next_ctrl; - nvme_subsystem_next_ns; - nvme_subsystem_release_fds; - nvme_transport_handle_get_fd; - nvme_transport_handle_get_name; - nvme_transport_handle_is_blkdev; - nvme_transport_handle_is_chardev; - nvme_transport_handle_is_direct; - nvme_transport_handle_is_mi; - nvme_transport_handle_set_decide_retry; - nvme_transport_handle_set_submit_entry; - nvme_transport_handle_set_submit_exit; - nvme_unlink_ctrl; - nvme_update_key; - nvme_uuid_from_string; - nvme_uuid_to_string; + libnvme_clear_etdas; + libnvme_close; + libnvme_create_ctrl; + libnvme_create_global_ctx; + libnvme_create_raw_secret; + libnvme_ctrl_first_ns; + libnvme_ctrl_first_path; + libnvme_ctrl_get_config; + libnvme_ctrl_get_phy_slot; + libnvme_ctrl_get_src_addr; + libnvme_ctrl_get_state; + libnvme_ctrl_get_subsysnqn; + libnvme_ctrl_get_subsystem; + libnvme_ctrl_get_transport_handle; + libnvme_ctrl_identify; + libnvme_ctrl_match_config; + libnvme_ctrl_next_ns; + libnvme_ctrl_next_path; + libnvme_ctrl_release_transport_handle; + libnvme_describe_key_serial; + libnvme_disconnect_ctrl; + libnvme_dump_config; + libnvme_dump_tree; + libnvme_errno_to_string; + libnvme_export_tls_key; + libnvme_export_tls_key_versioned; + libnvme_filter_ctrls; + libnvme_filter_namespace; + libnvme_filter_paths; + libnvme_filter_subsys; + libnvme_find_uuid; + libnvme_first_host; + libnvme_first_subsystem; + libnvme_free_ctrl; + libnvme_free_global_ctx; + libnvme_free_host; + libnvme_free_nbft; + libnvme_free_ns; + libnvme_free_subsystem; + libnvme_gen_dhchap_key; + libnvme_generate_hostid; + libnvme_generate_hostnqn; + libnvme_generate_hostnqn_from_hostid; + libnvme_generate_tls_key_identity; + libnvme_generate_tls_key_identity_compat; + libnvme_get_ana_log_atomic; + libnvme_get_ana_log_len; + libnvme_get_ana_log_len_from_id_ctrl; + libnvme_get_application; + libnvme_get_attr; + libnvme_get_ctrl_attr; + libnvme_get_ctrl_telemetry; + libnvme_get_directive_receive_length; + libnvme_get_feature_length; + libnvme_get_host; + libnvme_get_host_telemetry; + libnvme_get_log; + libnvme_get_logging_level; + libnvme_get_logical_block_size; + libnvme_get_new_host_telemetry; + libnvme_get_ns_attr; + libnvme_get_nsid; + libnvme_get_path_attr; + libnvme_get_subsys_attr; + libnvme_get_subsystem; + libnvme_get_telemetry_log; + libnvme_get_telemetry_max; + libnvme_get_uuid_list; + libnvme_get_version; + libnvme_host_get_global_ctx; + libnvme_host_get_ids; + libnvme_host_is_pdc_enabled; + libnvme_host_release_fds; + libnvme_host_set_pdc_enabled; + libnvme_import_tls_key; + libnvme_import_tls_key_versioned; + libnvme_init_ctrl; + libnvme_insert_tls_key; + libnvme_insert_tls_key_compat; + libnvme_insert_tls_key_versioned; + libnvme_lookup_key; + libnvme_lookup_keyring; + libnvme_scan_ns_head_paths; + libnvme_mi_admin_xfer; + libnvme_mi_aem_disable; + libnvme_mi_aem_enable; + libnvme_mi_aem_get_enabled; + libnvme_mi_aem_get_fd; + libnvme_mi_aem_get_next_event; + libnvme_mi_aem_process; + libnvme_mi_close; + libnvme_mi_control; + libnvme_mi_ctrl_id; + libnvme_mi_endpoint_desc; + libnvme_mi_ep_get_timeout; + libnvme_mi_ep_set_timeout; + libnvme_mi_first_endpoint; + libnvme_mi_init_transport_handle; + libnvme_mi_mi_config_get; + libnvme_mi_mi_config_set; + libnvme_mi_mi_read_mi_data_ctrl; + libnvme_mi_mi_read_mi_data_ctrl_list; + libnvme_mi_mi_read_mi_data_port; + libnvme_mi_mi_read_mi_data_subsys; + libnvme_mi_mi_subsystem_health_status_poll; + libnvme_mi_mi_xfer; + libnvme_mi_next_endpoint; + libnvme_mi_open_mctp; + libnvme_mi_scan_ep; + libnvme_mi_scan_mctp; + libnvme_mi_set_csi; + libnvme_mi_status_to_string; + libnvme_mi_submit_entry; + libnvme_mi_submit_exit; + libnvme_namespace_first_path; + libnvme_namespace_next_path; + libnvme_next_host; + libnvme_next_subsystem; + libnvme_ns_compare; + libnvme_ns_flush; + libnvme_ns_get_csi; + libnvme_ns_get_ctrl; + libnvme_ns_get_eui64; + libnvme_ns_get_firmware; + libnvme_ns_get_generic_name; + libnvme_ns_get_model; + libnvme_ns_get_nguid; + libnvme_ns_get_serial; + libnvme_ns_get_subsystem; + libnvme_ns_get_uuid; + libnvme_ns_identify; + libnvme_ns_read; + libnvme_ns_verify; + libnvme_ns_write; + libnvme_ns_write_uncorrectable; + libnvme_ns_write_zeros; + libnvme_open; + libnvme_parse_uri; + libnvme_path_get_ctrl; + libnvme_path_get_ns; + libnvme_path_get_queue_depth; + libnvme_random_uuid; + libnvme_read_config; + libnvme_read_hostid; + libnvme_read_hostnqn; + libnvme_read_key; + libnvme_read_nbft; + libnvme_refresh_topology; + libnvme_rescan_ctrl; + libnvme_rescan_ns; + libnvme_reset_ctrl; + libnvme_reset_subsystem; + libnvme_revoke_tls_key; + libnvme_scan_ctrl; + libnvme_scan_ctrl_namespace_paths; + libnvme_scan_ctrl_namespaces; + libnvme_scan_ctrls; + libnvme_scan_namespace; + libnvme_scan_subsystem_namespaces; + libnvme_scan_subsystems; + libnvme_scan_tls_keys; + libnvme_scan_topology; + libnvme_set_application; + libnvme_set_dry_run; + libnvme_set_etdas; + libnvme_set_ioctl_probing; + libnvme_set_keyring; + libnvme_set_logging_level; + libnvme_skip_namespaces; + libnvme_status_to_errno; + libnvme_status_to_string; + libnvme_strerror; + libnvme_submit_admin_passthru; + libnvme_submit_io_passthru; + libnvme_subsystem_first_ctrl; + libnvme_subsystem_first_ns; + libnvme_subsystem_get_host; + libnvme_subsystem_lookup_namespace; + libnvme_subsystem_next_ctrl; + libnvme_subsystem_next_ns; + libnvme_subsystem_release_fds; + libnvme_transport_handle_get_fd; + libnvme_transport_handle_get_name; + libnvme_transport_handle_is_blkdev; + libnvme_transport_handle_is_chardev; + libnvme_transport_handle_is_direct; + libnvme_transport_handle_is_mi; + libnvme_transport_handle_set_decide_retry; + libnvme_transport_handle_set_submit_entry; + libnvme_transport_handle_set_submit_exit; + libnvme_unlink_ctrl; + libnvme_update_key; + libnvme_uuid_from_string; + libnvme_uuid_to_string; local: *; }; diff --git a/libnvme/src/meson.build b/libnvme/src/meson.build index 15f08f1a84..4fa1214167 100644 --- a/libnvme/src/meson.build +++ b/libnvme/src/meson.build @@ -34,6 +34,7 @@ headers = [ 'nvme/lib-types.h', 'nvme/lib.h', 'nvme/linux.h', + 'nvme/mi-types.h', 'nvme/mi.h', 'nvme/tree.h', 'nvme/types.h', diff --git a/libnvme/src/nvme/accessors.c b/libnvme/src/nvme/accessors.c index d3c507d7ed..d844e72b4a 100644 --- a/libnvme/src/nvme/accessors.c +++ b/libnvme/src/nvme/accessors.c @@ -25,258 +25,264 @@ #include "compiler_attributes.h" /**************************************************************************** - * Accessors for: struct nvme_path + * Accessors for: struct libnvme_path ****************************************************************************/ -__public void nvme_path_set_name(struct nvme_path *p, const char *name) +__public void libnvme_path_set_name(struct libnvme_path *p, const char *name) { free(p->name); p->name = name ? strdup(name) : NULL; } -__public const char *nvme_path_get_name(const struct nvme_path *p) +__public const char *libnvme_path_get_name(const struct libnvme_path *p) { return p->name; } -__public void nvme_path_set_sysfs_dir( - struct nvme_path *p, +__public void libnvme_path_set_sysfs_dir( + struct libnvme_path *p, const char *sysfs_dir) { free(p->sysfs_dir); p->sysfs_dir = sysfs_dir ? strdup(sysfs_dir) : NULL; } -__public const char *nvme_path_get_sysfs_dir(const struct nvme_path *p) +__public const char *libnvme_path_get_sysfs_dir(const struct libnvme_path *p) { return p->sysfs_dir; } -__public void nvme_path_set_ana_state( - struct nvme_path *p, +__public void libnvme_path_set_ana_state( + struct libnvme_path *p, const char *ana_state) { free(p->ana_state); p->ana_state = ana_state ? strdup(ana_state) : NULL; } -__public const char *nvme_path_get_ana_state(const struct nvme_path *p) +__public const char *libnvme_path_get_ana_state(const struct libnvme_path *p) { return p->ana_state; } -__public void nvme_path_set_numa_nodes( - struct nvme_path *p, +__public void libnvme_path_set_numa_nodes( + struct libnvme_path *p, const char *numa_nodes) { free(p->numa_nodes); p->numa_nodes = numa_nodes ? strdup(numa_nodes) : NULL; } -__public const char *nvme_path_get_numa_nodes(const struct nvme_path *p) +__public const char *libnvme_path_get_numa_nodes(const struct libnvme_path *p) { return p->numa_nodes; } -__public void nvme_path_set_grpid(struct nvme_path *p, int grpid) +__public void libnvme_path_set_grpid(struct libnvme_path *p, int grpid) { p->grpid = grpid; } -__public int nvme_path_get_grpid(const struct nvme_path *p) +__public int libnvme_path_get_grpid(const struct libnvme_path *p) { return p->grpid; } /**************************************************************************** - * Accessors for: struct nvme_ns + * Accessors for: struct libnvme_ns ****************************************************************************/ -__public void nvme_ns_set_nsid(struct nvme_ns *p, __u32 nsid) +__public void libnvme_ns_set_nsid(struct libnvme_ns *p, __u32 nsid) { p->nsid = nsid; } -__public __u32 nvme_ns_get_nsid(const struct nvme_ns *p) +__public __u32 libnvme_ns_get_nsid(const struct libnvme_ns *p) { return p->nsid; } -__public void nvme_ns_set_name(struct nvme_ns *p, const char *name) +__public void libnvme_ns_set_name(struct libnvme_ns *p, const char *name) { free(p->name); p->name = name ? strdup(name) : NULL; } -__public const char *nvme_ns_get_name(const struct nvme_ns *p) +__public const char *libnvme_ns_get_name(const struct libnvme_ns *p) { return p->name; } -__public void nvme_ns_set_sysfs_dir(struct nvme_ns *p, const char *sysfs_dir) +__public void libnvme_ns_set_sysfs_dir( + struct libnvme_ns *p, + const char *sysfs_dir) { free(p->sysfs_dir); p->sysfs_dir = sysfs_dir ? strdup(sysfs_dir) : NULL; } -__public const char *nvme_ns_get_sysfs_dir(const struct nvme_ns *p) +__public const char *libnvme_ns_get_sysfs_dir(const struct libnvme_ns *p) { return p->sysfs_dir; } -__public void nvme_ns_set_lba_shift(struct nvme_ns *p, int lba_shift) +__public void libnvme_ns_set_lba_shift(struct libnvme_ns *p, int lba_shift) { p->lba_shift = lba_shift; } -__public int nvme_ns_get_lba_shift(const struct nvme_ns *p) +__public int libnvme_ns_get_lba_shift(const struct libnvme_ns *p) { return p->lba_shift; } -__public void nvme_ns_set_lba_size(struct nvme_ns *p, int lba_size) +__public void libnvme_ns_set_lba_size(struct libnvme_ns *p, int lba_size) { p->lba_size = lba_size; } -__public int nvme_ns_get_lba_size(const struct nvme_ns *p) +__public int libnvme_ns_get_lba_size(const struct libnvme_ns *p) { return p->lba_size; } -__public void nvme_ns_set_meta_size(struct nvme_ns *p, int meta_size) +__public void libnvme_ns_set_meta_size(struct libnvme_ns *p, int meta_size) { p->meta_size = meta_size; } -__public int nvme_ns_get_meta_size(const struct nvme_ns *p) +__public int libnvme_ns_get_meta_size(const struct libnvme_ns *p) { return p->meta_size; } -__public void nvme_ns_set_lba_count(struct nvme_ns *p, uint64_t lba_count) +__public void libnvme_ns_set_lba_count(struct libnvme_ns *p, uint64_t lba_count) { p->lba_count = lba_count; } -__public uint64_t nvme_ns_get_lba_count(const struct nvme_ns *p) +__public uint64_t libnvme_ns_get_lba_count(const struct libnvme_ns *p) { return p->lba_count; } -__public void nvme_ns_set_lba_util(struct nvme_ns *p, uint64_t lba_util) +__public void libnvme_ns_set_lba_util(struct libnvme_ns *p, uint64_t lba_util) { p->lba_util = lba_util; } -__public uint64_t nvme_ns_get_lba_util(const struct nvme_ns *p) +__public uint64_t libnvme_ns_get_lba_util(const struct libnvme_ns *p) { return p->lba_util; } /**************************************************************************** - * Accessors for: struct nvme_ctrl + * Accessors for: struct libnvme_ctrl ****************************************************************************/ -__public const char *nvme_ctrl_get_name(const struct nvme_ctrl *p) +__public const char *libnvme_ctrl_get_name(const struct libnvme_ctrl *p) { return p->name; } -__public const char *nvme_ctrl_get_sysfs_dir(const struct nvme_ctrl *p) +__public const char *libnvme_ctrl_get_sysfs_dir(const struct libnvme_ctrl *p) { return p->sysfs_dir; } -__public const char *nvme_ctrl_get_firmware(const struct nvme_ctrl *p) +__public const char *libnvme_ctrl_get_firmware(const struct libnvme_ctrl *p) { return p->firmware; } -__public const char *nvme_ctrl_get_model(const struct nvme_ctrl *p) +__public const char *libnvme_ctrl_get_model(const struct libnvme_ctrl *p) { return p->model; } -__public const char *nvme_ctrl_get_numa_node(const struct nvme_ctrl *p) +__public const char *libnvme_ctrl_get_numa_node(const struct libnvme_ctrl *p) { return p->numa_node; } -__public const char *nvme_ctrl_get_queue_count(const struct nvme_ctrl *p) +__public const char *libnvme_ctrl_get_queue_count(const struct libnvme_ctrl *p) { return p->queue_count; } -__public const char *nvme_ctrl_get_serial(const struct nvme_ctrl *p) +__public const char *libnvme_ctrl_get_serial(const struct libnvme_ctrl *p) { return p->serial; } -__public const char *nvme_ctrl_get_sqsize(const struct nvme_ctrl *p) +__public const char *libnvme_ctrl_get_sqsize(const struct libnvme_ctrl *p) { return p->sqsize; } -__public const char *nvme_ctrl_get_transport(const struct nvme_ctrl *p) +__public const char *libnvme_ctrl_get_transport(const struct libnvme_ctrl *p) { return p->transport; } -__public const char *nvme_ctrl_get_subsysnqn(const struct nvme_ctrl *p) +__public const char *libnvme_ctrl_get_subsysnqn(const struct libnvme_ctrl *p) { return p->subsysnqn; } -__public const char *nvme_ctrl_get_traddr(const struct nvme_ctrl *p) +__public const char *libnvme_ctrl_get_traddr(const struct libnvme_ctrl *p) { return p->traddr; } -__public const char *nvme_ctrl_get_trsvcid(const struct nvme_ctrl *p) +__public const char *libnvme_ctrl_get_trsvcid(const struct libnvme_ctrl *p) { return p->trsvcid; } -__public void nvme_ctrl_set_dhchap_host_key( - struct nvme_ctrl *p, +__public void libnvme_ctrl_set_dhchap_host_key( + struct libnvme_ctrl *p, const char *dhchap_host_key) { free(p->dhchap_host_key); p->dhchap_host_key = dhchap_host_key ? strdup(dhchap_host_key) : NULL; } -__public const char *nvme_ctrl_get_dhchap_host_key(const struct nvme_ctrl *p) +__public const char *libnvme_ctrl_get_dhchap_host_key( + const struct libnvme_ctrl *p) { return p->dhchap_host_key; } -__public void nvme_ctrl_set_dhchap_ctrl_key( - struct nvme_ctrl *p, +__public void libnvme_ctrl_set_dhchap_ctrl_key( + struct libnvme_ctrl *p, const char *dhchap_ctrl_key) { free(p->dhchap_ctrl_key); p->dhchap_ctrl_key = dhchap_ctrl_key ? strdup(dhchap_ctrl_key) : NULL; } -__public const char *nvme_ctrl_get_dhchap_ctrl_key(const struct nvme_ctrl *p) +__public const char *libnvme_ctrl_get_dhchap_ctrl_key( + const struct libnvme_ctrl *p) { return p->dhchap_ctrl_key; } -__public void nvme_ctrl_set_keyring(struct nvme_ctrl *p, const char *keyring) +__public void libnvme_ctrl_set_keyring( + struct libnvme_ctrl *p, + const char *keyring) { free(p->keyring); p->keyring = keyring ? strdup(keyring) : NULL; } -__public const char *nvme_ctrl_get_keyring(const struct nvme_ctrl *p) +__public const char *libnvme_ctrl_get_keyring(const struct libnvme_ctrl *p) { return p->keyring; } -__public void nvme_ctrl_set_tls_key_identity( - struct nvme_ctrl *p, +__public void libnvme_ctrl_set_tls_key_identity( + struct libnvme_ctrl *p, const char *tls_key_identity) { free(p->tls_key_identity); @@ -284,604 +290,621 @@ __public void nvme_ctrl_set_tls_key_identity( tls_key_identity ? strdup(tls_key_identity) : NULL; } -__public const char *nvme_ctrl_get_tls_key_identity(const struct nvme_ctrl *p) +__public const char *libnvme_ctrl_get_tls_key_identity( + const struct libnvme_ctrl *p) { return p->tls_key_identity; } -__public void nvme_ctrl_set_tls_key(struct nvme_ctrl *p, const char *tls_key) +__public void libnvme_ctrl_set_tls_key( + struct libnvme_ctrl *p, + const char *tls_key) { free(p->tls_key); p->tls_key = tls_key ? strdup(tls_key) : NULL; } -__public const char *nvme_ctrl_get_tls_key(const struct nvme_ctrl *p) +__public const char *libnvme_ctrl_get_tls_key(const struct libnvme_ctrl *p) { return p->tls_key; } -__public const char *nvme_ctrl_get_cntrltype(const struct nvme_ctrl *p) +__public const char *libnvme_ctrl_get_cntrltype(const struct libnvme_ctrl *p) { return p->cntrltype; } -__public const char *nvme_ctrl_get_cntlid(const struct nvme_ctrl *p) +__public const char *libnvme_ctrl_get_cntlid(const struct libnvme_ctrl *p) { return p->cntlid; } -__public const char *nvme_ctrl_get_dctype(const struct nvme_ctrl *p) +__public const char *libnvme_ctrl_get_dctype(const struct libnvme_ctrl *p) { return p->dctype; } -__public const char *nvme_ctrl_get_phy_slot(const struct nvme_ctrl *p) +__public const char *libnvme_ctrl_get_phy_slot(const struct libnvme_ctrl *p) { return p->phy_slot; } -__public const char *nvme_ctrl_get_host_traddr(const struct nvme_ctrl *p) +__public const char *libnvme_ctrl_get_host_traddr(const struct libnvme_ctrl *p) { return p->host_traddr; } -__public const char *nvme_ctrl_get_host_iface(const struct nvme_ctrl *p) +__public const char *libnvme_ctrl_get_host_iface(const struct libnvme_ctrl *p) { return p->host_iface; } -__public void nvme_ctrl_set_discovery_ctrl( - struct nvme_ctrl *p, +__public void libnvme_ctrl_set_discovery_ctrl( + struct libnvme_ctrl *p, bool discovery_ctrl) { p->discovery_ctrl = discovery_ctrl; } -__public bool nvme_ctrl_get_discovery_ctrl(const struct nvme_ctrl *p) +__public bool libnvme_ctrl_get_discovery_ctrl(const struct libnvme_ctrl *p) { return p->discovery_ctrl; } -__public void nvme_ctrl_set_unique_discovery_ctrl( - struct nvme_ctrl *p, +__public void libnvme_ctrl_set_unique_discovery_ctrl( + struct libnvme_ctrl *p, bool unique_discovery_ctrl) { p->unique_discovery_ctrl = unique_discovery_ctrl; } -__public bool nvme_ctrl_get_unique_discovery_ctrl(const struct nvme_ctrl *p) +__public bool libnvme_ctrl_get_unique_discovery_ctrl( + const struct libnvme_ctrl *p) { return p->unique_discovery_ctrl; } -__public void nvme_ctrl_set_discovered(struct nvme_ctrl *p, bool discovered) +__public void libnvme_ctrl_set_discovered( + struct libnvme_ctrl *p, + bool discovered) { p->discovered = discovered; } -__public bool nvme_ctrl_get_discovered(const struct nvme_ctrl *p) +__public bool libnvme_ctrl_get_discovered(const struct libnvme_ctrl *p) { return p->discovered; } -__public void nvme_ctrl_set_persistent(struct nvme_ctrl *p, bool persistent) +__public void libnvme_ctrl_set_persistent( + struct libnvme_ctrl *p, + bool persistent) { p->persistent = persistent; } -__public bool nvme_ctrl_get_persistent(const struct nvme_ctrl *p) +__public bool libnvme_ctrl_get_persistent(const struct libnvme_ctrl *p) { return p->persistent; } /**************************************************************************** - * Accessors for: struct nvme_subsystem + * Accessors for: struct libnvme_subsystem ****************************************************************************/ -__public const char *nvme_subsystem_get_name(const struct nvme_subsystem *p) +__public const char *libnvme_subsystem_get_name( + const struct libnvme_subsystem *p) { return p->name; } -__public const char *nvme_subsystem_get_sysfs_dir( - const struct nvme_subsystem *p) +__public const char *libnvme_subsystem_get_sysfs_dir( + const struct libnvme_subsystem *p) { return p->sysfs_dir; } -__public const char *nvme_subsystem_get_subsysnqn( - const struct nvme_subsystem *p) +__public const char *libnvme_subsystem_get_subsysnqn( + const struct libnvme_subsystem *p) { return p->subsysnqn; } -__public const char *nvme_subsystem_get_model(const struct nvme_subsystem *p) +__public const char *libnvme_subsystem_get_model( + const struct libnvme_subsystem *p) { return p->model; } -__public const char *nvme_subsystem_get_serial(const struct nvme_subsystem *p) +__public const char *libnvme_subsystem_get_serial( + const struct libnvme_subsystem *p) { return p->serial; } -__public const char *nvme_subsystem_get_firmware(const struct nvme_subsystem *p) +__public const char *libnvme_subsystem_get_firmware( + const struct libnvme_subsystem *p) { return p->firmware; } -__public const char *nvme_subsystem_get_subsystype( - const struct nvme_subsystem *p) +__public const char *libnvme_subsystem_get_subsystype( + const struct libnvme_subsystem *p) { return p->subsystype; } -__public void nvme_subsystem_set_application( - struct nvme_subsystem *p, +__public void libnvme_subsystem_set_application( + struct libnvme_subsystem *p, const char *application) { free(p->application); p->application = application ? strdup(application) : NULL; } -__public const char *nvme_subsystem_get_application( - const struct nvme_subsystem *p) +__public const char *libnvme_subsystem_get_application( + const struct libnvme_subsystem *p) { return p->application; } -__public void nvme_subsystem_set_iopolicy( - struct nvme_subsystem *p, +__public void libnvme_subsystem_set_iopolicy( + struct libnvme_subsystem *p, const char *iopolicy) { free(p->iopolicy); p->iopolicy = iopolicy ? strdup(iopolicy) : NULL; } -__public const char *nvme_subsystem_get_iopolicy(const struct nvme_subsystem *p) +__public const char *libnvme_subsystem_get_iopolicy( + const struct libnvme_subsystem *p) { return p->iopolicy; } /**************************************************************************** - * Accessors for: struct nvme_host + * Accessors for: struct libnvme_host ****************************************************************************/ -__public const char *nvme_host_get_hostnqn(const struct nvme_host *p) +__public const char *libnvme_host_get_hostnqn(const struct libnvme_host *p) { return p->hostnqn; } -__public const char *nvme_host_get_hostid(const struct nvme_host *p) +__public const char *libnvme_host_get_hostid(const struct libnvme_host *p) { return p->hostid; } -__public void nvme_host_set_dhchap_host_key( - struct nvme_host *p, +__public void libnvme_host_set_dhchap_host_key( + struct libnvme_host *p, const char *dhchap_host_key) { free(p->dhchap_host_key); p->dhchap_host_key = dhchap_host_key ? strdup(dhchap_host_key) : NULL; } -__public const char *nvme_host_get_dhchap_host_key(const struct nvme_host *p) +__public const char *libnvme_host_get_dhchap_host_key( + const struct libnvme_host *p) { return p->dhchap_host_key; } -__public void nvme_host_set_hostsymname( - struct nvme_host *p, +__public void libnvme_host_set_hostsymname( + struct libnvme_host *p, const char *hostsymname) { free(p->hostsymname); p->hostsymname = hostsymname ? strdup(hostsymname) : NULL; } -__public const char *nvme_host_get_hostsymname(const struct nvme_host *p) +__public const char *libnvme_host_get_hostsymname(const struct libnvme_host *p) { return p->hostsymname; } -__public void nvme_host_set_pdc_enabled_valid( - struct nvme_host *p, +__public void libnvme_host_set_pdc_enabled_valid( + struct libnvme_host *p, bool pdc_enabled_valid) { p->pdc_enabled_valid = pdc_enabled_valid; } -__public bool nvme_host_get_pdc_enabled_valid(const struct nvme_host *p) +__public bool libnvme_host_get_pdc_enabled_valid(const struct libnvme_host *p) { return p->pdc_enabled_valid; } /**************************************************************************** - * Accessors for: struct nvme_fabric_options + * Accessors for: struct libnvme_fabric_options ****************************************************************************/ -__public void nvme_fabric_options_set_cntlid( - struct nvme_fabric_options *p, +__public void libnvme_fabric_options_set_cntlid( + struct libnvme_fabric_options *p, bool cntlid) { p->cntlid = cntlid; } -__public bool nvme_fabric_options_get_cntlid( - const struct nvme_fabric_options *p) +__public bool libnvme_fabric_options_get_cntlid( + const struct libnvme_fabric_options *p) { return p->cntlid; } -__public void nvme_fabric_options_set_concat( - struct nvme_fabric_options *p, +__public void libnvme_fabric_options_set_concat( + struct libnvme_fabric_options *p, bool concat) { p->concat = concat; } -__public bool nvme_fabric_options_get_concat( - const struct nvme_fabric_options *p) +__public bool libnvme_fabric_options_get_concat( + const struct libnvme_fabric_options *p) { return p->concat; } -__public void nvme_fabric_options_set_ctrl_loss_tmo( - struct nvme_fabric_options *p, +__public void libnvme_fabric_options_set_ctrl_loss_tmo( + struct libnvme_fabric_options *p, bool ctrl_loss_tmo) { p->ctrl_loss_tmo = ctrl_loss_tmo; } -__public bool nvme_fabric_options_get_ctrl_loss_tmo( - const struct nvme_fabric_options *p) +__public bool libnvme_fabric_options_get_ctrl_loss_tmo( + const struct libnvme_fabric_options *p) { return p->ctrl_loss_tmo; } -__public void nvme_fabric_options_set_data_digest( - struct nvme_fabric_options *p, +__public void libnvme_fabric_options_set_data_digest( + struct libnvme_fabric_options *p, bool data_digest) { p->data_digest = data_digest; } -__public bool nvme_fabric_options_get_data_digest( - const struct nvme_fabric_options *p) +__public bool libnvme_fabric_options_get_data_digest( + const struct libnvme_fabric_options *p) { return p->data_digest; } -__public void nvme_fabric_options_set_dhchap_ctrl_secret( - struct nvme_fabric_options *p, +__public void libnvme_fabric_options_set_dhchap_ctrl_secret( + struct libnvme_fabric_options *p, bool dhchap_ctrl_secret) { p->dhchap_ctrl_secret = dhchap_ctrl_secret; } -__public bool nvme_fabric_options_get_dhchap_ctrl_secret( - const struct nvme_fabric_options *p) +__public bool libnvme_fabric_options_get_dhchap_ctrl_secret( + const struct libnvme_fabric_options *p) { return p->dhchap_ctrl_secret; } -__public void nvme_fabric_options_set_dhchap_secret( - struct nvme_fabric_options *p, +__public void libnvme_fabric_options_set_dhchap_secret( + struct libnvme_fabric_options *p, bool dhchap_secret) { p->dhchap_secret = dhchap_secret; } -__public bool nvme_fabric_options_get_dhchap_secret( - const struct nvme_fabric_options *p) +__public bool libnvme_fabric_options_get_dhchap_secret( + const struct libnvme_fabric_options *p) { return p->dhchap_secret; } -__public void nvme_fabric_options_set_disable_sqflow( - struct nvme_fabric_options *p, +__public void libnvme_fabric_options_set_disable_sqflow( + struct libnvme_fabric_options *p, bool disable_sqflow) { p->disable_sqflow = disable_sqflow; } -__public bool nvme_fabric_options_get_disable_sqflow( - const struct nvme_fabric_options *p) +__public bool libnvme_fabric_options_get_disable_sqflow( + const struct libnvme_fabric_options *p) { return p->disable_sqflow; } -__public void nvme_fabric_options_set_discovery( - struct nvme_fabric_options *p, +__public void libnvme_fabric_options_set_discovery( + struct libnvme_fabric_options *p, bool discovery) { p->discovery = discovery; } -__public bool nvme_fabric_options_get_discovery( - const struct nvme_fabric_options *p) +__public bool libnvme_fabric_options_get_discovery( + const struct libnvme_fabric_options *p) { return p->discovery; } -__public void nvme_fabric_options_set_duplicate_connect( - struct nvme_fabric_options *p, +__public void libnvme_fabric_options_set_duplicate_connect( + struct libnvme_fabric_options *p, bool duplicate_connect) { p->duplicate_connect = duplicate_connect; } -__public bool nvme_fabric_options_get_duplicate_connect( - const struct nvme_fabric_options *p) +__public bool libnvme_fabric_options_get_duplicate_connect( + const struct libnvme_fabric_options *p) { return p->duplicate_connect; } -__public void nvme_fabric_options_set_fast_io_fail_tmo( - struct nvme_fabric_options *p, +__public void libnvme_fabric_options_set_fast_io_fail_tmo( + struct libnvme_fabric_options *p, bool fast_io_fail_tmo) { p->fast_io_fail_tmo = fast_io_fail_tmo; } -__public bool nvme_fabric_options_get_fast_io_fail_tmo( - const struct nvme_fabric_options *p) +__public bool libnvme_fabric_options_get_fast_io_fail_tmo( + const struct libnvme_fabric_options *p) { return p->fast_io_fail_tmo; } -__public void nvme_fabric_options_set_hdr_digest( - struct nvme_fabric_options *p, +__public void libnvme_fabric_options_set_hdr_digest( + struct libnvme_fabric_options *p, bool hdr_digest) { p->hdr_digest = hdr_digest; } -__public bool nvme_fabric_options_get_hdr_digest( - const struct nvme_fabric_options *p) +__public bool libnvme_fabric_options_get_hdr_digest( + const struct libnvme_fabric_options *p) { return p->hdr_digest; } -__public void nvme_fabric_options_set_host_iface( - struct nvme_fabric_options *p, +__public void libnvme_fabric_options_set_host_iface( + struct libnvme_fabric_options *p, bool host_iface) { p->host_iface = host_iface; } -__public bool nvme_fabric_options_get_host_iface( - const struct nvme_fabric_options *p) +__public bool libnvme_fabric_options_get_host_iface( + const struct libnvme_fabric_options *p) { return p->host_iface; } -__public void nvme_fabric_options_set_host_traddr( - struct nvme_fabric_options *p, +__public void libnvme_fabric_options_set_host_traddr( + struct libnvme_fabric_options *p, bool host_traddr) { p->host_traddr = host_traddr; } -__public bool nvme_fabric_options_get_host_traddr( - const struct nvme_fabric_options *p) +__public bool libnvme_fabric_options_get_host_traddr( + const struct libnvme_fabric_options *p) { return p->host_traddr; } -__public void nvme_fabric_options_set_hostid( - struct nvme_fabric_options *p, +__public void libnvme_fabric_options_set_hostid( + struct libnvme_fabric_options *p, bool hostid) { p->hostid = hostid; } -__public bool nvme_fabric_options_get_hostid( - const struct nvme_fabric_options *p) +__public bool libnvme_fabric_options_get_hostid( + const struct libnvme_fabric_options *p) { return p->hostid; } -__public void nvme_fabric_options_set_hostnqn( - struct nvme_fabric_options *p, +__public void libnvme_fabric_options_set_hostnqn( + struct libnvme_fabric_options *p, bool hostnqn) { p->hostnqn = hostnqn; } -__public bool nvme_fabric_options_get_hostnqn( - const struct nvme_fabric_options *p) +__public bool libnvme_fabric_options_get_hostnqn( + const struct libnvme_fabric_options *p) { return p->hostnqn; } -__public void nvme_fabric_options_set_instance( - struct nvme_fabric_options *p, +__public void libnvme_fabric_options_set_instance( + struct libnvme_fabric_options *p, bool instance) { p->instance = instance; } -__public bool nvme_fabric_options_get_instance( - const struct nvme_fabric_options *p) +__public bool libnvme_fabric_options_get_instance( + const struct libnvme_fabric_options *p) { return p->instance; } -__public void nvme_fabric_options_set_keep_alive_tmo( - struct nvme_fabric_options *p, +__public void libnvme_fabric_options_set_keep_alive_tmo( + struct libnvme_fabric_options *p, bool keep_alive_tmo) { p->keep_alive_tmo = keep_alive_tmo; } -__public bool nvme_fabric_options_get_keep_alive_tmo( - const struct nvme_fabric_options *p) +__public bool libnvme_fabric_options_get_keep_alive_tmo( + const struct libnvme_fabric_options *p) { return p->keep_alive_tmo; } -__public void nvme_fabric_options_set_keyring( - struct nvme_fabric_options *p, +__public void libnvme_fabric_options_set_keyring( + struct libnvme_fabric_options *p, bool keyring) { p->keyring = keyring; } -__public bool nvme_fabric_options_get_keyring( - const struct nvme_fabric_options *p) +__public bool libnvme_fabric_options_get_keyring( + const struct libnvme_fabric_options *p) { return p->keyring; } -__public void nvme_fabric_options_set_nqn( - struct nvme_fabric_options *p, +__public void libnvme_fabric_options_set_nqn( + struct libnvme_fabric_options *p, bool nqn) { p->nqn = nqn; } -__public bool nvme_fabric_options_get_nqn(const struct nvme_fabric_options *p) +__public bool libnvme_fabric_options_get_nqn( + const struct libnvme_fabric_options *p) { return p->nqn; } -__public void nvme_fabric_options_set_nr_io_queues( - struct nvme_fabric_options *p, +__public void libnvme_fabric_options_set_nr_io_queues( + struct libnvme_fabric_options *p, bool nr_io_queues) { p->nr_io_queues = nr_io_queues; } -__public bool nvme_fabric_options_get_nr_io_queues( - const struct nvme_fabric_options *p) +__public bool libnvme_fabric_options_get_nr_io_queues( + const struct libnvme_fabric_options *p) { return p->nr_io_queues; } -__public void nvme_fabric_options_set_nr_poll_queues( - struct nvme_fabric_options *p, +__public void libnvme_fabric_options_set_nr_poll_queues( + struct libnvme_fabric_options *p, bool nr_poll_queues) { p->nr_poll_queues = nr_poll_queues; } -__public bool nvme_fabric_options_get_nr_poll_queues( - const struct nvme_fabric_options *p) +__public bool libnvme_fabric_options_get_nr_poll_queues( + const struct libnvme_fabric_options *p) { return p->nr_poll_queues; } -__public void nvme_fabric_options_set_nr_write_queues( - struct nvme_fabric_options *p, +__public void libnvme_fabric_options_set_nr_write_queues( + struct libnvme_fabric_options *p, bool nr_write_queues) { p->nr_write_queues = nr_write_queues; } -__public bool nvme_fabric_options_get_nr_write_queues( - const struct nvme_fabric_options *p) +__public bool libnvme_fabric_options_get_nr_write_queues( + const struct libnvme_fabric_options *p) { return p->nr_write_queues; } -__public void nvme_fabric_options_set_queue_size( - struct nvme_fabric_options *p, +__public void libnvme_fabric_options_set_queue_size( + struct libnvme_fabric_options *p, bool queue_size) { p->queue_size = queue_size; } -__public bool nvme_fabric_options_get_queue_size( - const struct nvme_fabric_options *p) +__public bool libnvme_fabric_options_get_queue_size( + const struct libnvme_fabric_options *p) { return p->queue_size; } -__public void nvme_fabric_options_set_reconnect_delay( - struct nvme_fabric_options *p, +__public void libnvme_fabric_options_set_reconnect_delay( + struct libnvme_fabric_options *p, bool reconnect_delay) { p->reconnect_delay = reconnect_delay; } -__public bool nvme_fabric_options_get_reconnect_delay( - const struct nvme_fabric_options *p) +__public bool libnvme_fabric_options_get_reconnect_delay( + const struct libnvme_fabric_options *p) { return p->reconnect_delay; } -__public void nvme_fabric_options_set_tls( - struct nvme_fabric_options *p, +__public void libnvme_fabric_options_set_tls( + struct libnvme_fabric_options *p, bool tls) { p->tls = tls; } -__public bool nvme_fabric_options_get_tls(const struct nvme_fabric_options *p) +__public bool libnvme_fabric_options_get_tls( + const struct libnvme_fabric_options *p) { return p->tls; } -__public void nvme_fabric_options_set_tls_key( - struct nvme_fabric_options *p, +__public void libnvme_fabric_options_set_tls_key( + struct libnvme_fabric_options *p, bool tls_key) { p->tls_key = tls_key; } -__public bool nvme_fabric_options_get_tls_key( - const struct nvme_fabric_options *p) +__public bool libnvme_fabric_options_get_tls_key( + const struct libnvme_fabric_options *p) { return p->tls_key; } -__public void nvme_fabric_options_set_tos( - struct nvme_fabric_options *p, +__public void libnvme_fabric_options_set_tos( + struct libnvme_fabric_options *p, bool tos) { p->tos = tos; } -__public bool nvme_fabric_options_get_tos(const struct nvme_fabric_options *p) +__public bool libnvme_fabric_options_get_tos( + const struct libnvme_fabric_options *p) { return p->tos; } -__public void nvme_fabric_options_set_traddr( - struct nvme_fabric_options *p, +__public void libnvme_fabric_options_set_traddr( + struct libnvme_fabric_options *p, bool traddr) { p->traddr = traddr; } -__public bool nvme_fabric_options_get_traddr( - const struct nvme_fabric_options *p) +__public bool libnvme_fabric_options_get_traddr( + const struct libnvme_fabric_options *p) { return p->traddr; } -__public void nvme_fabric_options_set_transport( - struct nvme_fabric_options *p, +__public void libnvme_fabric_options_set_transport( + struct libnvme_fabric_options *p, bool transport) { p->transport = transport; } -__public bool nvme_fabric_options_get_transport( - const struct nvme_fabric_options *p) +__public bool libnvme_fabric_options_get_transport( + const struct libnvme_fabric_options *p) { return p->transport; } -__public void nvme_fabric_options_set_trsvcid( - struct nvme_fabric_options *p, +__public void libnvme_fabric_options_set_trsvcid( + struct libnvme_fabric_options *p, bool trsvcid) { p->trsvcid = trsvcid; } -__public bool nvme_fabric_options_get_trsvcid( - const struct nvme_fabric_options *p) +__public bool libnvme_fabric_options_get_trsvcid( + const struct libnvme_fabric_options *p) { return p->trsvcid; } diff --git a/libnvme/src/nvme/accessors.h b/libnvme/src/nvme/accessors.h index 5c594dd127..e15e450825 100644 --- a/libnvme/src/nvme/accessors.h +++ b/libnvme/src/nvme/accessors.h @@ -27,1176 +27,1202 @@ #include /* __u32, __u64, etc. */ /* Forward declarations. These are internal (opaque) structs. */ -struct nvme_path; -struct nvme_ns; -struct nvme_ctrl; -struct nvme_subsystem; -struct nvme_host; -struct nvme_fabric_options; +struct libnvme_path; +struct libnvme_ns; +struct libnvme_ctrl; +struct libnvme_subsystem; +struct libnvme_host; +struct libnvme_fabric_options; /**************************************************************************** - * Accessors for: struct nvme_path + * Accessors for: struct libnvme_path ****************************************************************************/ /** - * nvme_path_set_name() - Set name. - * @p: The &struct nvme_path instance to update. + * libnvme_path_set_name() - Set name. + * @p: The &struct libnvme_path instance to update. * @name: New string; a copy is stored. Pass NULL to clear. */ -void nvme_path_set_name(struct nvme_path *p, const char *name); +void libnvme_path_set_name(struct libnvme_path *p, const char *name); /** - * nvme_path_get_name() - Get name. - * @p: The &struct nvme_path instance to query. + * libnvme_path_get_name() - Get name. + * @p: The &struct libnvme_path instance to query. * * Return: The value of the name field, or NULL if not set. */ -const char *nvme_path_get_name(const struct nvme_path *p); +const char *libnvme_path_get_name(const struct libnvme_path *p); /** - * nvme_path_set_sysfs_dir() - Set sysfs_dir. - * @p: The &struct nvme_path instance to update. + * libnvme_path_set_sysfs_dir() - Set sysfs_dir. + * @p: The &struct libnvme_path instance to update. * @sysfs_dir: New string; a copy is stored. Pass NULL to clear. */ -void nvme_path_set_sysfs_dir(struct nvme_path *p, const char *sysfs_dir); +void libnvme_path_set_sysfs_dir(struct libnvme_path *p, const char *sysfs_dir); /** - * nvme_path_get_sysfs_dir() - Get sysfs_dir. - * @p: The &struct nvme_path instance to query. + * libnvme_path_get_sysfs_dir() - Get sysfs_dir. + * @p: The &struct libnvme_path instance to query. * * Return: The value of the sysfs_dir field, or NULL if not set. */ -const char *nvme_path_get_sysfs_dir(const struct nvme_path *p); +const char *libnvme_path_get_sysfs_dir(const struct libnvme_path *p); /** - * nvme_path_set_ana_state() - Set ana_state. - * @p: The &struct nvme_path instance to update. + * libnvme_path_set_ana_state() - Set ana_state. + * @p: The &struct libnvme_path instance to update. * @ana_state: New string; a copy is stored. Pass NULL to clear. */ -void nvme_path_set_ana_state(struct nvme_path *p, const char *ana_state); +void libnvme_path_set_ana_state(struct libnvme_path *p, const char *ana_state); /** - * nvme_path_get_ana_state() - Get ana_state. - * @p: The &struct nvme_path instance to query. + * libnvme_path_get_ana_state() - Get ana_state. + * @p: The &struct libnvme_path instance to query. * * Return: The value of the ana_state field, or NULL if not set. */ -const char *nvme_path_get_ana_state(const struct nvme_path *p); +const char *libnvme_path_get_ana_state(const struct libnvme_path *p); /** - * nvme_path_set_numa_nodes() - Set numa_nodes. - * @p: The &struct nvme_path instance to update. + * libnvme_path_set_numa_nodes() - Set numa_nodes. + * @p: The &struct libnvme_path instance to update. * @numa_nodes: New string; a copy is stored. Pass NULL to clear. */ -void nvme_path_set_numa_nodes(struct nvme_path *p, const char *numa_nodes); +void libnvme_path_set_numa_nodes( + struct libnvme_path *p, + const char *numa_nodes); /** - * nvme_path_get_numa_nodes() - Get numa_nodes. - * @p: The &struct nvme_path instance to query. + * libnvme_path_get_numa_nodes() - Get numa_nodes. + * @p: The &struct libnvme_path instance to query. * * Return: The value of the numa_nodes field, or NULL if not set. */ -const char *nvme_path_get_numa_nodes(const struct nvme_path *p); +const char *libnvme_path_get_numa_nodes(const struct libnvme_path *p); /** - * nvme_path_set_grpid() - Set grpid. - * @p: The &struct nvme_path instance to update. + * libnvme_path_set_grpid() - Set grpid. + * @p: The &struct libnvme_path instance to update. * @grpid: Value to assign to the grpid field. */ -void nvme_path_set_grpid(struct nvme_path *p, int grpid); +void libnvme_path_set_grpid(struct libnvme_path *p, int grpid); /** - * nvme_path_get_grpid() - Get grpid. - * @p: The &struct nvme_path instance to query. + * libnvme_path_get_grpid() - Get grpid. + * @p: The &struct libnvme_path instance to query. * * Return: The value of the grpid field. */ -int nvme_path_get_grpid(const struct nvme_path *p); +int libnvme_path_get_grpid(const struct libnvme_path *p); /**************************************************************************** - * Accessors for: struct nvme_ns + * Accessors for: struct libnvme_ns ****************************************************************************/ /** - * nvme_ns_set_nsid() - Set nsid. - * @p: The &struct nvme_ns instance to update. + * libnvme_ns_set_nsid() - Set nsid. + * @p: The &struct libnvme_ns instance to update. * @nsid: Value to assign to the nsid field. */ -void nvme_ns_set_nsid(struct nvme_ns *p, __u32 nsid); +void libnvme_ns_set_nsid(struct libnvme_ns *p, __u32 nsid); /** - * nvme_ns_get_nsid() - Get nsid. - * @p: The &struct nvme_ns instance to query. + * libnvme_ns_get_nsid() - Get nsid. + * @p: The &struct libnvme_ns instance to query. * * Return: The value of the nsid field. */ -__u32 nvme_ns_get_nsid(const struct nvme_ns *p); +__u32 libnvme_ns_get_nsid(const struct libnvme_ns *p); /** - * nvme_ns_set_name() - Set name. - * @p: The &struct nvme_ns instance to update. + * libnvme_ns_set_name() - Set name. + * @p: The &struct libnvme_ns instance to update. * @name: New string; a copy is stored. Pass NULL to clear. */ -void nvme_ns_set_name(struct nvme_ns *p, const char *name); +void libnvme_ns_set_name(struct libnvme_ns *p, const char *name); /** - * nvme_ns_get_name() - Get name. - * @p: The &struct nvme_ns instance to query. + * libnvme_ns_get_name() - Get name. + * @p: The &struct libnvme_ns instance to query. * * Return: The value of the name field, or NULL if not set. */ -const char *nvme_ns_get_name(const struct nvme_ns *p); +const char *libnvme_ns_get_name(const struct libnvme_ns *p); /** - * nvme_ns_set_sysfs_dir() - Set sysfs_dir. - * @p: The &struct nvme_ns instance to update. + * libnvme_ns_set_sysfs_dir() - Set sysfs_dir. + * @p: The &struct libnvme_ns instance to update. * @sysfs_dir: New string; a copy is stored. Pass NULL to clear. */ -void nvme_ns_set_sysfs_dir(struct nvme_ns *p, const char *sysfs_dir); +void libnvme_ns_set_sysfs_dir(struct libnvme_ns *p, const char *sysfs_dir); /** - * nvme_ns_get_sysfs_dir() - Get sysfs_dir. - * @p: The &struct nvme_ns instance to query. + * libnvme_ns_get_sysfs_dir() - Get sysfs_dir. + * @p: The &struct libnvme_ns instance to query. * * Return: The value of the sysfs_dir field, or NULL if not set. */ -const char *nvme_ns_get_sysfs_dir(const struct nvme_ns *p); +const char *libnvme_ns_get_sysfs_dir(const struct libnvme_ns *p); /** - * nvme_ns_set_lba_shift() - Set lba_shift. - * @p: The &struct nvme_ns instance to update. + * libnvme_ns_set_lba_shift() - Set lba_shift. + * @p: The &struct libnvme_ns instance to update. * @lba_shift: Value to assign to the lba_shift field. */ -void nvme_ns_set_lba_shift(struct nvme_ns *p, int lba_shift); +void libnvme_ns_set_lba_shift(struct libnvme_ns *p, int lba_shift); /** - * nvme_ns_get_lba_shift() - Get lba_shift. - * @p: The &struct nvme_ns instance to query. + * libnvme_ns_get_lba_shift() - Get lba_shift. + * @p: The &struct libnvme_ns instance to query. * * Return: The value of the lba_shift field. */ -int nvme_ns_get_lba_shift(const struct nvme_ns *p); +int libnvme_ns_get_lba_shift(const struct libnvme_ns *p); /** - * nvme_ns_set_lba_size() - Set lba_size. - * @p: The &struct nvme_ns instance to update. + * libnvme_ns_set_lba_size() - Set lba_size. + * @p: The &struct libnvme_ns instance to update. * @lba_size: Value to assign to the lba_size field. */ -void nvme_ns_set_lba_size(struct nvme_ns *p, int lba_size); +void libnvme_ns_set_lba_size(struct libnvme_ns *p, int lba_size); /** - * nvme_ns_get_lba_size() - Get lba_size. - * @p: The &struct nvme_ns instance to query. + * libnvme_ns_get_lba_size() - Get lba_size. + * @p: The &struct libnvme_ns instance to query. * * Return: The value of the lba_size field. */ -int nvme_ns_get_lba_size(const struct nvme_ns *p); +int libnvme_ns_get_lba_size(const struct libnvme_ns *p); /** - * nvme_ns_set_meta_size() - Set meta_size. - * @p: The &struct nvme_ns instance to update. + * libnvme_ns_set_meta_size() - Set meta_size. + * @p: The &struct libnvme_ns instance to update. * @meta_size: Value to assign to the meta_size field. */ -void nvme_ns_set_meta_size(struct nvme_ns *p, int meta_size); +void libnvme_ns_set_meta_size(struct libnvme_ns *p, int meta_size); /** - * nvme_ns_get_meta_size() - Get meta_size. - * @p: The &struct nvme_ns instance to query. + * libnvme_ns_get_meta_size() - Get meta_size. + * @p: The &struct libnvme_ns instance to query. * * Return: The value of the meta_size field. */ -int nvme_ns_get_meta_size(const struct nvme_ns *p); +int libnvme_ns_get_meta_size(const struct libnvme_ns *p); /** - * nvme_ns_set_lba_count() - Set lba_count. - * @p: The &struct nvme_ns instance to update. + * libnvme_ns_set_lba_count() - Set lba_count. + * @p: The &struct libnvme_ns instance to update. * @lba_count: Value to assign to the lba_count field. */ -void nvme_ns_set_lba_count(struct nvme_ns *p, uint64_t lba_count); +void libnvme_ns_set_lba_count(struct libnvme_ns *p, uint64_t lba_count); /** - * nvme_ns_get_lba_count() - Get lba_count. - * @p: The &struct nvme_ns instance to query. + * libnvme_ns_get_lba_count() - Get lba_count. + * @p: The &struct libnvme_ns instance to query. * * Return: The value of the lba_count field. */ -uint64_t nvme_ns_get_lba_count(const struct nvme_ns *p); +uint64_t libnvme_ns_get_lba_count(const struct libnvme_ns *p); /** - * nvme_ns_set_lba_util() - Set lba_util. - * @p: The &struct nvme_ns instance to update. + * libnvme_ns_set_lba_util() - Set lba_util. + * @p: The &struct libnvme_ns instance to update. * @lba_util: Value to assign to the lba_util field. */ -void nvme_ns_set_lba_util(struct nvme_ns *p, uint64_t lba_util); +void libnvme_ns_set_lba_util(struct libnvme_ns *p, uint64_t lba_util); /** - * nvme_ns_get_lba_util() - Get lba_util. - * @p: The &struct nvme_ns instance to query. + * libnvme_ns_get_lba_util() - Get lba_util. + * @p: The &struct libnvme_ns instance to query. * * Return: The value of the lba_util field. */ -uint64_t nvme_ns_get_lba_util(const struct nvme_ns *p); +uint64_t libnvme_ns_get_lba_util(const struct libnvme_ns *p); /**************************************************************************** - * Accessors for: struct nvme_ctrl + * Accessors for: struct libnvme_ctrl ****************************************************************************/ /** - * nvme_ctrl_get_name() - Get name. - * @p: The &struct nvme_ctrl instance to query. + * libnvme_ctrl_get_name() - Get name. + * @p: The &struct libnvme_ctrl instance to query. * * Return: The value of the name field, or NULL if not set. */ -const char *nvme_ctrl_get_name(const struct nvme_ctrl *p); +const char *libnvme_ctrl_get_name(const struct libnvme_ctrl *p); /** - * nvme_ctrl_get_sysfs_dir() - Get sysfs_dir. - * @p: The &struct nvme_ctrl instance to query. + * libnvme_ctrl_get_sysfs_dir() - Get sysfs_dir. + * @p: The &struct libnvme_ctrl instance to query. * * Return: The value of the sysfs_dir field, or NULL if not set. */ -const char *nvme_ctrl_get_sysfs_dir(const struct nvme_ctrl *p); +const char *libnvme_ctrl_get_sysfs_dir(const struct libnvme_ctrl *p); /** - * nvme_ctrl_get_firmware() - Get firmware. - * @p: The &struct nvme_ctrl instance to query. + * libnvme_ctrl_get_firmware() - Get firmware. + * @p: The &struct libnvme_ctrl instance to query. * * Return: The value of the firmware field, or NULL if not set. */ -const char *nvme_ctrl_get_firmware(const struct nvme_ctrl *p); +const char *libnvme_ctrl_get_firmware(const struct libnvme_ctrl *p); /** - * nvme_ctrl_get_model() - Get model. - * @p: The &struct nvme_ctrl instance to query. + * libnvme_ctrl_get_model() - Get model. + * @p: The &struct libnvme_ctrl instance to query. * * Return: The value of the model field, or NULL if not set. */ -const char *nvme_ctrl_get_model(const struct nvme_ctrl *p); +const char *libnvme_ctrl_get_model(const struct libnvme_ctrl *p); /** - * nvme_ctrl_get_numa_node() - Get numa_node. - * @p: The &struct nvme_ctrl instance to query. + * libnvme_ctrl_get_numa_node() - Get numa_node. + * @p: The &struct libnvme_ctrl instance to query. * * Return: The value of the numa_node field, or NULL if not set. */ -const char *nvme_ctrl_get_numa_node(const struct nvme_ctrl *p); +const char *libnvme_ctrl_get_numa_node(const struct libnvme_ctrl *p); /** - * nvme_ctrl_get_queue_count() - Get queue_count. - * @p: The &struct nvme_ctrl instance to query. + * libnvme_ctrl_get_queue_count() - Get queue_count. + * @p: The &struct libnvme_ctrl instance to query. * * Return: The value of the queue_count field, or NULL if not set. */ -const char *nvme_ctrl_get_queue_count(const struct nvme_ctrl *p); +const char *libnvme_ctrl_get_queue_count(const struct libnvme_ctrl *p); /** - * nvme_ctrl_get_serial() - Get serial. - * @p: The &struct nvme_ctrl instance to query. + * libnvme_ctrl_get_serial() - Get serial. + * @p: The &struct libnvme_ctrl instance to query. * * Return: The value of the serial field, or NULL if not set. */ -const char *nvme_ctrl_get_serial(const struct nvme_ctrl *p); +const char *libnvme_ctrl_get_serial(const struct libnvme_ctrl *p); /** - * nvme_ctrl_get_sqsize() - Get sqsize. - * @p: The &struct nvme_ctrl instance to query. + * libnvme_ctrl_get_sqsize() - Get sqsize. + * @p: The &struct libnvme_ctrl instance to query. * * Return: The value of the sqsize field, or NULL if not set. */ -const char *nvme_ctrl_get_sqsize(const struct nvme_ctrl *p); +const char *libnvme_ctrl_get_sqsize(const struct libnvme_ctrl *p); /** - * nvme_ctrl_get_transport() - Get transport. - * @p: The &struct nvme_ctrl instance to query. + * libnvme_ctrl_get_transport() - Get transport. + * @p: The &struct libnvme_ctrl instance to query. * * Return: The value of the transport field, or NULL if not set. */ -const char *nvme_ctrl_get_transport(const struct nvme_ctrl *p); +const char *libnvme_ctrl_get_transport(const struct libnvme_ctrl *p); /** - * nvme_ctrl_get_subsysnqn() - Get subsysnqn. - * @p: The &struct nvme_ctrl instance to query. + * libnvme_ctrl_get_subsysnqn() - Get subsysnqn. + * @p: The &struct libnvme_ctrl instance to query. * * Return: The value of the subsysnqn field, or NULL if not set. */ -const char *nvme_ctrl_get_subsysnqn(const struct nvme_ctrl *p); +const char *libnvme_ctrl_get_subsysnqn(const struct libnvme_ctrl *p); /** - * nvme_ctrl_get_traddr() - Get traddr. - * @p: The &struct nvme_ctrl instance to query. + * libnvme_ctrl_get_traddr() - Get traddr. + * @p: The &struct libnvme_ctrl instance to query. * * Return: The value of the traddr field, or NULL if not set. */ -const char *nvme_ctrl_get_traddr(const struct nvme_ctrl *p); +const char *libnvme_ctrl_get_traddr(const struct libnvme_ctrl *p); /** - * nvme_ctrl_get_trsvcid() - Get trsvcid. - * @p: The &struct nvme_ctrl instance to query. + * libnvme_ctrl_get_trsvcid() - Get trsvcid. + * @p: The &struct libnvme_ctrl instance to query. * * Return: The value of the trsvcid field, or NULL if not set. */ -const char *nvme_ctrl_get_trsvcid(const struct nvme_ctrl *p); +const char *libnvme_ctrl_get_trsvcid(const struct libnvme_ctrl *p); /** - * nvme_ctrl_set_dhchap_host_key() - Set dhchap_host_key. - * @p: The &struct nvme_ctrl instance to update. + * libnvme_ctrl_set_dhchap_host_key() - Set dhchap_host_key. + * @p: The &struct libnvme_ctrl instance to update. * @dhchap_host_key: New string; a copy is stored. Pass NULL to clear. */ -void nvme_ctrl_set_dhchap_host_key( - struct nvme_ctrl *p, +void libnvme_ctrl_set_dhchap_host_key( + struct libnvme_ctrl *p, const char *dhchap_host_key); /** - * nvme_ctrl_get_dhchap_host_key() - Get dhchap_host_key. - * @p: The &struct nvme_ctrl instance to query. + * libnvme_ctrl_get_dhchap_host_key() - Get dhchap_host_key. + * @p: The &struct libnvme_ctrl instance to query. * * Return: The value of the dhchap_host_key field, or NULL if not set. */ -const char *nvme_ctrl_get_dhchap_host_key(const struct nvme_ctrl *p); +const char *libnvme_ctrl_get_dhchap_host_key(const struct libnvme_ctrl *p); /** - * nvme_ctrl_set_dhchap_ctrl_key() - Set dhchap_ctrl_key. - * @p: The &struct nvme_ctrl instance to update. + * libnvme_ctrl_set_dhchap_ctrl_key() - Set dhchap_ctrl_key. + * @p: The &struct libnvme_ctrl instance to update. * @dhchap_ctrl_key: New string; a copy is stored. Pass NULL to clear. */ -void nvme_ctrl_set_dhchap_ctrl_key( - struct nvme_ctrl *p, +void libnvme_ctrl_set_dhchap_ctrl_key( + struct libnvme_ctrl *p, const char *dhchap_ctrl_key); /** - * nvme_ctrl_get_dhchap_ctrl_key() - Get dhchap_ctrl_key. - * @p: The &struct nvme_ctrl instance to query. + * libnvme_ctrl_get_dhchap_ctrl_key() - Get dhchap_ctrl_key. + * @p: The &struct libnvme_ctrl instance to query. * * Return: The value of the dhchap_ctrl_key field, or NULL if not set. */ -const char *nvme_ctrl_get_dhchap_ctrl_key(const struct nvme_ctrl *p); +const char *libnvme_ctrl_get_dhchap_ctrl_key(const struct libnvme_ctrl *p); /** - * nvme_ctrl_set_keyring() - Set keyring. - * @p: The &struct nvme_ctrl instance to update. + * libnvme_ctrl_set_keyring() - Set keyring. + * @p: The &struct libnvme_ctrl instance to update. * @keyring: New string; a copy is stored. Pass NULL to clear. */ -void nvme_ctrl_set_keyring(struct nvme_ctrl *p, const char *keyring); +void libnvme_ctrl_set_keyring(struct libnvme_ctrl *p, const char *keyring); /** - * nvme_ctrl_get_keyring() - Get keyring. - * @p: The &struct nvme_ctrl instance to query. + * libnvme_ctrl_get_keyring() - Get keyring. + * @p: The &struct libnvme_ctrl instance to query. * * Return: The value of the keyring field, or NULL if not set. */ -const char *nvme_ctrl_get_keyring(const struct nvme_ctrl *p); +const char *libnvme_ctrl_get_keyring(const struct libnvme_ctrl *p); /** - * nvme_ctrl_set_tls_key_identity() - Set tls_key_identity. - * @p: The &struct nvme_ctrl instance to update. + * libnvme_ctrl_set_tls_key_identity() - Set tls_key_identity. + * @p: The &struct libnvme_ctrl instance to update. * @tls_key_identity: New string; a copy is stored. Pass NULL to clear. */ -void nvme_ctrl_set_tls_key_identity( - struct nvme_ctrl *p, +void libnvme_ctrl_set_tls_key_identity( + struct libnvme_ctrl *p, const char *tls_key_identity); /** - * nvme_ctrl_get_tls_key_identity() - Get tls_key_identity. - * @p: The &struct nvme_ctrl instance to query. + * libnvme_ctrl_get_tls_key_identity() - Get tls_key_identity. + * @p: The &struct libnvme_ctrl instance to query. * * Return: The value of the tls_key_identity field, or NULL if not set. */ -const char *nvme_ctrl_get_tls_key_identity(const struct nvme_ctrl *p); +const char *libnvme_ctrl_get_tls_key_identity(const struct libnvme_ctrl *p); /** - * nvme_ctrl_set_tls_key() - Set tls_key. - * @p: The &struct nvme_ctrl instance to update. + * libnvme_ctrl_set_tls_key() - Set tls_key. + * @p: The &struct libnvme_ctrl instance to update. * @tls_key: New string; a copy is stored. Pass NULL to clear. */ -void nvme_ctrl_set_tls_key(struct nvme_ctrl *p, const char *tls_key); +void libnvme_ctrl_set_tls_key(struct libnvme_ctrl *p, const char *tls_key); /** - * nvme_ctrl_get_tls_key() - Get tls_key. - * @p: The &struct nvme_ctrl instance to query. + * libnvme_ctrl_get_tls_key() - Get tls_key. + * @p: The &struct libnvme_ctrl instance to query. * * Return: The value of the tls_key field, or NULL if not set. */ -const char *nvme_ctrl_get_tls_key(const struct nvme_ctrl *p); +const char *libnvme_ctrl_get_tls_key(const struct libnvme_ctrl *p); /** - * nvme_ctrl_get_cntrltype() - Get cntrltype. - * @p: The &struct nvme_ctrl instance to query. + * libnvme_ctrl_get_cntrltype() - Get cntrltype. + * @p: The &struct libnvme_ctrl instance to query. * * Return: The value of the cntrltype field, or NULL if not set. */ -const char *nvme_ctrl_get_cntrltype(const struct nvme_ctrl *p); +const char *libnvme_ctrl_get_cntrltype(const struct libnvme_ctrl *p); /** - * nvme_ctrl_get_cntlid() - Get cntlid. - * @p: The &struct nvme_ctrl instance to query. + * libnvme_ctrl_get_cntlid() - Get cntlid. + * @p: The &struct libnvme_ctrl instance to query. * * Return: The value of the cntlid field, or NULL if not set. */ -const char *nvme_ctrl_get_cntlid(const struct nvme_ctrl *p); +const char *libnvme_ctrl_get_cntlid(const struct libnvme_ctrl *p); /** - * nvme_ctrl_get_dctype() - Get dctype. - * @p: The &struct nvme_ctrl instance to query. + * libnvme_ctrl_get_dctype() - Get dctype. + * @p: The &struct libnvme_ctrl instance to query. * * Return: The value of the dctype field, or NULL if not set. */ -const char *nvme_ctrl_get_dctype(const struct nvme_ctrl *p); +const char *libnvme_ctrl_get_dctype(const struct libnvme_ctrl *p); /** - * nvme_ctrl_get_phy_slot() - Get phy_slot. - * @p: The &struct nvme_ctrl instance to query. + * libnvme_ctrl_get_phy_slot() - Get phy_slot. + * @p: The &struct libnvme_ctrl instance to query. * * Return: The value of the phy_slot field, or NULL if not set. */ -const char *nvme_ctrl_get_phy_slot(const struct nvme_ctrl *p); +const char *libnvme_ctrl_get_phy_slot(const struct libnvme_ctrl *p); /** - * nvme_ctrl_get_host_traddr() - Get host_traddr. - * @p: The &struct nvme_ctrl instance to query. + * libnvme_ctrl_get_host_traddr() - Get host_traddr. + * @p: The &struct libnvme_ctrl instance to query. * * Return: The value of the host_traddr field, or NULL if not set. */ -const char *nvme_ctrl_get_host_traddr(const struct nvme_ctrl *p); +const char *libnvme_ctrl_get_host_traddr(const struct libnvme_ctrl *p); /** - * nvme_ctrl_get_host_iface() - Get host_iface. - * @p: The &struct nvme_ctrl instance to query. + * libnvme_ctrl_get_host_iface() - Get host_iface. + * @p: The &struct libnvme_ctrl instance to query. * * Return: The value of the host_iface field, or NULL if not set. */ -const char *nvme_ctrl_get_host_iface(const struct nvme_ctrl *p); +const char *libnvme_ctrl_get_host_iface(const struct libnvme_ctrl *p); /** - * nvme_ctrl_set_discovery_ctrl() - Set discovery_ctrl. - * @p: The &struct nvme_ctrl instance to update. + * libnvme_ctrl_set_discovery_ctrl() - Set discovery_ctrl. + * @p: The &struct libnvme_ctrl instance to update. * @discovery_ctrl: Value to assign to the discovery_ctrl field. */ -void nvme_ctrl_set_discovery_ctrl(struct nvme_ctrl *p, bool discovery_ctrl); +void libnvme_ctrl_set_discovery_ctrl( + struct libnvme_ctrl *p, + bool discovery_ctrl); /** - * nvme_ctrl_get_discovery_ctrl() - Get discovery_ctrl. - * @p: The &struct nvme_ctrl instance to query. + * libnvme_ctrl_get_discovery_ctrl() - Get discovery_ctrl. + * @p: The &struct libnvme_ctrl instance to query. * * Return: The value of the discovery_ctrl field. */ -bool nvme_ctrl_get_discovery_ctrl(const struct nvme_ctrl *p); +bool libnvme_ctrl_get_discovery_ctrl(const struct libnvme_ctrl *p); /** - * nvme_ctrl_set_unique_discovery_ctrl() - Set unique_discovery_ctrl. - * @p: The &struct nvme_ctrl instance to update. + * libnvme_ctrl_set_unique_discovery_ctrl() - Set unique_discovery_ctrl. + * @p: The &struct libnvme_ctrl instance to update. * @unique_discovery_ctrl: Value to assign to the unique_discovery_ctrl field. */ -void nvme_ctrl_set_unique_discovery_ctrl( - struct nvme_ctrl *p, +void libnvme_ctrl_set_unique_discovery_ctrl( + struct libnvme_ctrl *p, bool unique_discovery_ctrl); /** - * nvme_ctrl_get_unique_discovery_ctrl() - Get unique_discovery_ctrl. - * @p: The &struct nvme_ctrl instance to query. + * libnvme_ctrl_get_unique_discovery_ctrl() - Get unique_discovery_ctrl. + * @p: The &struct libnvme_ctrl instance to query. * * Return: The value of the unique_discovery_ctrl field. */ -bool nvme_ctrl_get_unique_discovery_ctrl(const struct nvme_ctrl *p); +bool libnvme_ctrl_get_unique_discovery_ctrl(const struct libnvme_ctrl *p); /** - * nvme_ctrl_set_discovered() - Set discovered. - * @p: The &struct nvme_ctrl instance to update. + * libnvme_ctrl_set_discovered() - Set discovered. + * @p: The &struct libnvme_ctrl instance to update. * @discovered: Value to assign to the discovered field. */ -void nvme_ctrl_set_discovered(struct nvme_ctrl *p, bool discovered); +void libnvme_ctrl_set_discovered(struct libnvme_ctrl *p, bool discovered); /** - * nvme_ctrl_get_discovered() - Get discovered. - * @p: The &struct nvme_ctrl instance to query. + * libnvme_ctrl_get_discovered() - Get discovered. + * @p: The &struct libnvme_ctrl instance to query. * * Return: The value of the discovered field. */ -bool nvme_ctrl_get_discovered(const struct nvme_ctrl *p); +bool libnvme_ctrl_get_discovered(const struct libnvme_ctrl *p); /** - * nvme_ctrl_set_persistent() - Set persistent. - * @p: The &struct nvme_ctrl instance to update. + * libnvme_ctrl_set_persistent() - Set persistent. + * @p: The &struct libnvme_ctrl instance to update. * @persistent: Value to assign to the persistent field. */ -void nvme_ctrl_set_persistent(struct nvme_ctrl *p, bool persistent); +void libnvme_ctrl_set_persistent(struct libnvme_ctrl *p, bool persistent); /** - * nvme_ctrl_get_persistent() - Get persistent. - * @p: The &struct nvme_ctrl instance to query. + * libnvme_ctrl_get_persistent() - Get persistent. + * @p: The &struct libnvme_ctrl instance to query. * * Return: The value of the persistent field. */ -bool nvme_ctrl_get_persistent(const struct nvme_ctrl *p); +bool libnvme_ctrl_get_persistent(const struct libnvme_ctrl *p); /**************************************************************************** - * Accessors for: struct nvme_subsystem + * Accessors for: struct libnvme_subsystem ****************************************************************************/ /** - * nvme_subsystem_get_name() - Get name. - * @p: The &struct nvme_subsystem instance to query. + * libnvme_subsystem_get_name() - Get name. + * @p: The &struct libnvme_subsystem instance to query. * * Return: The value of the name field, or NULL if not set. */ -const char *nvme_subsystem_get_name(const struct nvme_subsystem *p); +const char *libnvme_subsystem_get_name(const struct libnvme_subsystem *p); /** - * nvme_subsystem_get_sysfs_dir() - Get sysfs_dir. - * @p: The &struct nvme_subsystem instance to query. + * libnvme_subsystem_get_sysfs_dir() - Get sysfs_dir. + * @p: The &struct libnvme_subsystem instance to query. * * Return: The value of the sysfs_dir field, or NULL if not set. */ -const char *nvme_subsystem_get_sysfs_dir(const struct nvme_subsystem *p); +const char *libnvme_subsystem_get_sysfs_dir(const struct libnvme_subsystem *p); /** - * nvme_subsystem_get_subsysnqn() - Get subsysnqn. - * @p: The &struct nvme_subsystem instance to query. + * libnvme_subsystem_get_subsysnqn() - Get subsysnqn. + * @p: The &struct libnvme_subsystem instance to query. * * Return: The value of the subsysnqn field, or NULL if not set. */ -const char *nvme_subsystem_get_subsysnqn(const struct nvme_subsystem *p); +const char *libnvme_subsystem_get_subsysnqn(const struct libnvme_subsystem *p); /** - * nvme_subsystem_get_model() - Get model. - * @p: The &struct nvme_subsystem instance to query. + * libnvme_subsystem_get_model() - Get model. + * @p: The &struct libnvme_subsystem instance to query. * * Return: The value of the model field, or NULL if not set. */ -const char *nvme_subsystem_get_model(const struct nvme_subsystem *p); +const char *libnvme_subsystem_get_model(const struct libnvme_subsystem *p); /** - * nvme_subsystem_get_serial() - Get serial. - * @p: The &struct nvme_subsystem instance to query. + * libnvme_subsystem_get_serial() - Get serial. + * @p: The &struct libnvme_subsystem instance to query. * * Return: The value of the serial field, or NULL if not set. */ -const char *nvme_subsystem_get_serial(const struct nvme_subsystem *p); +const char *libnvme_subsystem_get_serial(const struct libnvme_subsystem *p); /** - * nvme_subsystem_get_firmware() - Get firmware. - * @p: The &struct nvme_subsystem instance to query. + * libnvme_subsystem_get_firmware() - Get firmware. + * @p: The &struct libnvme_subsystem instance to query. * * Return: The value of the firmware field, or NULL if not set. */ -const char *nvme_subsystem_get_firmware(const struct nvme_subsystem *p); +const char *libnvme_subsystem_get_firmware(const struct libnvme_subsystem *p); /** - * nvme_subsystem_get_subsystype() - Get subsystype. - * @p: The &struct nvme_subsystem instance to query. + * libnvme_subsystem_get_subsystype() - Get subsystype. + * @p: The &struct libnvme_subsystem instance to query. * * Return: The value of the subsystype field, or NULL if not set. */ -const char *nvme_subsystem_get_subsystype(const struct nvme_subsystem *p); +const char *libnvme_subsystem_get_subsystype(const struct libnvme_subsystem *p); /** - * nvme_subsystem_set_application() - Set application. - * @p: The &struct nvme_subsystem instance to update. + * libnvme_subsystem_set_application() - Set application. + * @p: The &struct libnvme_subsystem instance to update. * @application: New string; a copy is stored. Pass NULL to clear. */ -void nvme_subsystem_set_application( - struct nvme_subsystem *p, +void libnvme_subsystem_set_application( + struct libnvme_subsystem *p, const char *application); /** - * nvme_subsystem_get_application() - Get application. - * @p: The &struct nvme_subsystem instance to query. + * libnvme_subsystem_get_application() - Get application. + * @p: The &struct libnvme_subsystem instance to query. * * Return: The value of the application field, or NULL if not set. */ -const char *nvme_subsystem_get_application(const struct nvme_subsystem *p); +const char *libnvme_subsystem_get_application( + const struct libnvme_subsystem *p); /** - * nvme_subsystem_set_iopolicy() - Set iopolicy. - * @p: The &struct nvme_subsystem instance to update. + * libnvme_subsystem_set_iopolicy() - Set iopolicy. + * @p: The &struct libnvme_subsystem instance to update. * @iopolicy: New string; a copy is stored. Pass NULL to clear. */ -void nvme_subsystem_set_iopolicy( - struct nvme_subsystem *p, +void libnvme_subsystem_set_iopolicy( + struct libnvme_subsystem *p, const char *iopolicy); /** - * nvme_subsystem_get_iopolicy() - Get iopolicy. - * @p: The &struct nvme_subsystem instance to query. + * libnvme_subsystem_get_iopolicy() - Get iopolicy. + * @p: The &struct libnvme_subsystem instance to query. * * Return: The value of the iopolicy field, or NULL if not set. */ -const char *nvme_subsystem_get_iopolicy(const struct nvme_subsystem *p); +const char *libnvme_subsystem_get_iopolicy(const struct libnvme_subsystem *p); /**************************************************************************** - * Accessors for: struct nvme_host + * Accessors for: struct libnvme_host ****************************************************************************/ /** - * nvme_host_get_hostnqn() - Get hostnqn. - * @p: The &struct nvme_host instance to query. + * libnvme_host_get_hostnqn() - Get hostnqn. + * @p: The &struct libnvme_host instance to query. * * Return: The value of the hostnqn field, or NULL if not set. */ -const char *nvme_host_get_hostnqn(const struct nvme_host *p); +const char *libnvme_host_get_hostnqn(const struct libnvme_host *p); /** - * nvme_host_get_hostid() - Get hostid. - * @p: The &struct nvme_host instance to query. + * libnvme_host_get_hostid() - Get hostid. + * @p: The &struct libnvme_host instance to query. * * Return: The value of the hostid field, or NULL if not set. */ -const char *nvme_host_get_hostid(const struct nvme_host *p); +const char *libnvme_host_get_hostid(const struct libnvme_host *p); /** - * nvme_host_set_dhchap_host_key() - Set dhchap_host_key. - * @p: The &struct nvme_host instance to update. + * libnvme_host_set_dhchap_host_key() - Set dhchap_host_key. + * @p: The &struct libnvme_host instance to update. * @dhchap_host_key: New string; a copy is stored. Pass NULL to clear. */ -void nvme_host_set_dhchap_host_key( - struct nvme_host *p, +void libnvme_host_set_dhchap_host_key( + struct libnvme_host *p, const char *dhchap_host_key); /** - * nvme_host_get_dhchap_host_key() - Get dhchap_host_key. - * @p: The &struct nvme_host instance to query. + * libnvme_host_get_dhchap_host_key() - Get dhchap_host_key. + * @p: The &struct libnvme_host instance to query. * * Return: The value of the dhchap_host_key field, or NULL if not set. */ -const char *nvme_host_get_dhchap_host_key(const struct nvme_host *p); +const char *libnvme_host_get_dhchap_host_key(const struct libnvme_host *p); /** - * nvme_host_set_hostsymname() - Set hostsymname. - * @p: The &struct nvme_host instance to update. + * libnvme_host_set_hostsymname() - Set hostsymname. + * @p: The &struct libnvme_host instance to update. * @hostsymname: New string; a copy is stored. Pass NULL to clear. */ -void nvme_host_set_hostsymname(struct nvme_host *p, const char *hostsymname); +void libnvme_host_set_hostsymname( + struct libnvme_host *p, + const char *hostsymname); /** - * nvme_host_get_hostsymname() - Get hostsymname. - * @p: The &struct nvme_host instance to query. + * libnvme_host_get_hostsymname() - Get hostsymname. + * @p: The &struct libnvme_host instance to query. * * Return: The value of the hostsymname field, or NULL if not set. */ -const char *nvme_host_get_hostsymname(const struct nvme_host *p); +const char *libnvme_host_get_hostsymname(const struct libnvme_host *p); /** - * nvme_host_set_pdc_enabled_valid() - Set pdc_enabled_valid. - * @p: The &struct nvme_host instance to update. + * libnvme_host_set_pdc_enabled_valid() - Set pdc_enabled_valid. + * @p: The &struct libnvme_host instance to update. * @pdc_enabled_valid: Value to assign to the pdc_enabled_valid field. */ -void nvme_host_set_pdc_enabled_valid( - struct nvme_host *p, +void libnvme_host_set_pdc_enabled_valid( + struct libnvme_host *p, bool pdc_enabled_valid); /** - * nvme_host_get_pdc_enabled_valid() - Get pdc_enabled_valid. - * @p: The &struct nvme_host instance to query. + * libnvme_host_get_pdc_enabled_valid() - Get pdc_enabled_valid. + * @p: The &struct libnvme_host instance to query. * * Return: The value of the pdc_enabled_valid field. */ -bool nvme_host_get_pdc_enabled_valid(const struct nvme_host *p); +bool libnvme_host_get_pdc_enabled_valid(const struct libnvme_host *p); /**************************************************************************** - * Accessors for: struct nvme_fabric_options + * Accessors for: struct libnvme_fabric_options ****************************************************************************/ /** - * nvme_fabric_options_set_cntlid() - Set cntlid. - * @p: The &struct nvme_fabric_options instance to update. + * libnvme_fabric_options_set_cntlid() - Set cntlid. + * @p: The &struct libnvme_fabric_options instance to update. * @cntlid: Value to assign to the cntlid field. */ -void nvme_fabric_options_set_cntlid(struct nvme_fabric_options *p, bool cntlid); +void libnvme_fabric_options_set_cntlid( + struct libnvme_fabric_options *p, + bool cntlid); /** - * nvme_fabric_options_get_cntlid() - Get cntlid. - * @p: The &struct nvme_fabric_options instance to query. + * libnvme_fabric_options_get_cntlid() - Get cntlid. + * @p: The &struct libnvme_fabric_options instance to query. * * Return: The value of the cntlid field. */ -bool nvme_fabric_options_get_cntlid(const struct nvme_fabric_options *p); +bool libnvme_fabric_options_get_cntlid(const struct libnvme_fabric_options *p); /** - * nvme_fabric_options_set_concat() - Set concat. - * @p: The &struct nvme_fabric_options instance to update. + * libnvme_fabric_options_set_concat() - Set concat. + * @p: The &struct libnvme_fabric_options instance to update. * @concat: Value to assign to the concat field. */ -void nvme_fabric_options_set_concat(struct nvme_fabric_options *p, bool concat); +void libnvme_fabric_options_set_concat( + struct libnvme_fabric_options *p, + bool concat); /** - * nvme_fabric_options_get_concat() - Get concat. - * @p: The &struct nvme_fabric_options instance to query. + * libnvme_fabric_options_get_concat() - Get concat. + * @p: The &struct libnvme_fabric_options instance to query. * * Return: The value of the concat field. */ -bool nvme_fabric_options_get_concat(const struct nvme_fabric_options *p); +bool libnvme_fabric_options_get_concat(const struct libnvme_fabric_options *p); /** - * nvme_fabric_options_set_ctrl_loss_tmo() - Set ctrl_loss_tmo. - * @p: The &struct nvme_fabric_options instance to update. + * libnvme_fabric_options_set_ctrl_loss_tmo() - Set ctrl_loss_tmo. + * @p: The &struct libnvme_fabric_options instance to update. * @ctrl_loss_tmo: Value to assign to the ctrl_loss_tmo field. */ -void nvme_fabric_options_set_ctrl_loss_tmo( - struct nvme_fabric_options *p, +void libnvme_fabric_options_set_ctrl_loss_tmo( + struct libnvme_fabric_options *p, bool ctrl_loss_tmo); /** - * nvme_fabric_options_get_ctrl_loss_tmo() - Get ctrl_loss_tmo. - * @p: The &struct nvme_fabric_options instance to query. + * libnvme_fabric_options_get_ctrl_loss_tmo() - Get ctrl_loss_tmo. + * @p: The &struct libnvme_fabric_options instance to query. * * Return: The value of the ctrl_loss_tmo field. */ -bool nvme_fabric_options_get_ctrl_loss_tmo(const struct nvme_fabric_options *p); +bool libnvme_fabric_options_get_ctrl_loss_tmo( + const struct libnvme_fabric_options *p); /** - * nvme_fabric_options_set_data_digest() - Set data_digest. - * @p: The &struct nvme_fabric_options instance to update. + * libnvme_fabric_options_set_data_digest() - Set data_digest. + * @p: The &struct libnvme_fabric_options instance to update. * @data_digest: Value to assign to the data_digest field. */ -void nvme_fabric_options_set_data_digest( - struct nvme_fabric_options *p, +void libnvme_fabric_options_set_data_digest( + struct libnvme_fabric_options *p, bool data_digest); /** - * nvme_fabric_options_get_data_digest() - Get data_digest. - * @p: The &struct nvme_fabric_options instance to query. + * libnvme_fabric_options_get_data_digest() - Get data_digest. + * @p: The &struct libnvme_fabric_options instance to query. * * Return: The value of the data_digest field. */ -bool nvme_fabric_options_get_data_digest(const struct nvme_fabric_options *p); +bool libnvme_fabric_options_get_data_digest( + const struct libnvme_fabric_options *p); /** - * nvme_fabric_options_set_dhchap_ctrl_secret() - Set dhchap_ctrl_secret. - * @p: The &struct nvme_fabric_options instance to update. + * libnvme_fabric_options_set_dhchap_ctrl_secret() - Set dhchap_ctrl_secret. + * @p: The &struct libnvme_fabric_options instance to update. * @dhchap_ctrl_secret: Value to assign to the dhchap_ctrl_secret field. */ -void nvme_fabric_options_set_dhchap_ctrl_secret( - struct nvme_fabric_options *p, +void libnvme_fabric_options_set_dhchap_ctrl_secret( + struct libnvme_fabric_options *p, bool dhchap_ctrl_secret); /** - * nvme_fabric_options_get_dhchap_ctrl_secret() - Get dhchap_ctrl_secret. - * @p: The &struct nvme_fabric_options instance to query. + * libnvme_fabric_options_get_dhchap_ctrl_secret() - Get dhchap_ctrl_secret. + * @p: The &struct libnvme_fabric_options instance to query. * * Return: The value of the dhchap_ctrl_secret field. */ -bool nvme_fabric_options_get_dhchap_ctrl_secret( - const struct nvme_fabric_options *p); +bool libnvme_fabric_options_get_dhchap_ctrl_secret( + const struct libnvme_fabric_options *p); /** - * nvme_fabric_options_set_dhchap_secret() - Set dhchap_secret. - * @p: The &struct nvme_fabric_options instance to update. + * libnvme_fabric_options_set_dhchap_secret() - Set dhchap_secret. + * @p: The &struct libnvme_fabric_options instance to update. * @dhchap_secret: Value to assign to the dhchap_secret field. */ -void nvme_fabric_options_set_dhchap_secret( - struct nvme_fabric_options *p, +void libnvme_fabric_options_set_dhchap_secret( + struct libnvme_fabric_options *p, bool dhchap_secret); /** - * nvme_fabric_options_get_dhchap_secret() - Get dhchap_secret. - * @p: The &struct nvme_fabric_options instance to query. + * libnvme_fabric_options_get_dhchap_secret() - Get dhchap_secret. + * @p: The &struct libnvme_fabric_options instance to query. * * Return: The value of the dhchap_secret field. */ -bool nvme_fabric_options_get_dhchap_secret(const struct nvme_fabric_options *p); +bool libnvme_fabric_options_get_dhchap_secret( + const struct libnvme_fabric_options *p); /** - * nvme_fabric_options_set_disable_sqflow() - Set disable_sqflow. - * @p: The &struct nvme_fabric_options instance to update. + * libnvme_fabric_options_set_disable_sqflow() - Set disable_sqflow. + * @p: The &struct libnvme_fabric_options instance to update. * @disable_sqflow: Value to assign to the disable_sqflow field. */ -void nvme_fabric_options_set_disable_sqflow( - struct nvme_fabric_options *p, +void libnvme_fabric_options_set_disable_sqflow( + struct libnvme_fabric_options *p, bool disable_sqflow); /** - * nvme_fabric_options_get_disable_sqflow() - Get disable_sqflow. - * @p: The &struct nvme_fabric_options instance to query. + * libnvme_fabric_options_get_disable_sqflow() - Get disable_sqflow. + * @p: The &struct libnvme_fabric_options instance to query. * * Return: The value of the disable_sqflow field. */ -bool nvme_fabric_options_get_disable_sqflow( - const struct nvme_fabric_options *p); +bool libnvme_fabric_options_get_disable_sqflow( + const struct libnvme_fabric_options *p); /** - * nvme_fabric_options_set_discovery() - Set discovery. - * @p: The &struct nvme_fabric_options instance to update. + * libnvme_fabric_options_set_discovery() - Set discovery. + * @p: The &struct libnvme_fabric_options instance to update. * @discovery: Value to assign to the discovery field. */ -void nvme_fabric_options_set_discovery( - struct nvme_fabric_options *p, +void libnvme_fabric_options_set_discovery( + struct libnvme_fabric_options *p, bool discovery); /** - * nvme_fabric_options_get_discovery() - Get discovery. - * @p: The &struct nvme_fabric_options instance to query. + * libnvme_fabric_options_get_discovery() - Get discovery. + * @p: The &struct libnvme_fabric_options instance to query. * * Return: The value of the discovery field. */ -bool nvme_fabric_options_get_discovery(const struct nvme_fabric_options *p); +bool libnvme_fabric_options_get_discovery( + const struct libnvme_fabric_options *p); /** - * nvme_fabric_options_set_duplicate_connect() - Set duplicate_connect. - * @p: The &struct nvme_fabric_options instance to update. + * libnvme_fabric_options_set_duplicate_connect() - Set duplicate_connect. + * @p: The &struct libnvme_fabric_options instance to update. * @duplicate_connect: Value to assign to the duplicate_connect field. */ -void nvme_fabric_options_set_duplicate_connect( - struct nvme_fabric_options *p, +void libnvme_fabric_options_set_duplicate_connect( + struct libnvme_fabric_options *p, bool duplicate_connect); /** - * nvme_fabric_options_get_duplicate_connect() - Get duplicate_connect. - * @p: The &struct nvme_fabric_options instance to query. + * libnvme_fabric_options_get_duplicate_connect() - Get duplicate_connect. + * @p: The &struct libnvme_fabric_options instance to query. * * Return: The value of the duplicate_connect field. */ -bool nvme_fabric_options_get_duplicate_connect( - const struct nvme_fabric_options *p); +bool libnvme_fabric_options_get_duplicate_connect( + const struct libnvme_fabric_options *p); /** - * nvme_fabric_options_set_fast_io_fail_tmo() - Set fast_io_fail_tmo. - * @p: The &struct nvme_fabric_options instance to update. + * libnvme_fabric_options_set_fast_io_fail_tmo() - Set fast_io_fail_tmo. + * @p: The &struct libnvme_fabric_options instance to update. * @fast_io_fail_tmo: Value to assign to the fast_io_fail_tmo field. */ -void nvme_fabric_options_set_fast_io_fail_tmo( - struct nvme_fabric_options *p, +void libnvme_fabric_options_set_fast_io_fail_tmo( + struct libnvme_fabric_options *p, bool fast_io_fail_tmo); /** - * nvme_fabric_options_get_fast_io_fail_tmo() - Get fast_io_fail_tmo. - * @p: The &struct nvme_fabric_options instance to query. + * libnvme_fabric_options_get_fast_io_fail_tmo() - Get fast_io_fail_tmo. + * @p: The &struct libnvme_fabric_options instance to query. * * Return: The value of the fast_io_fail_tmo field. */ -bool nvme_fabric_options_get_fast_io_fail_tmo( - const struct nvme_fabric_options *p); +bool libnvme_fabric_options_get_fast_io_fail_tmo( + const struct libnvme_fabric_options *p); /** - * nvme_fabric_options_set_hdr_digest() - Set hdr_digest. - * @p: The &struct nvme_fabric_options instance to update. + * libnvme_fabric_options_set_hdr_digest() - Set hdr_digest. + * @p: The &struct libnvme_fabric_options instance to update. * @hdr_digest: Value to assign to the hdr_digest field. */ -void nvme_fabric_options_set_hdr_digest( - struct nvme_fabric_options *p, +void libnvme_fabric_options_set_hdr_digest( + struct libnvme_fabric_options *p, bool hdr_digest); /** - * nvme_fabric_options_get_hdr_digest() - Get hdr_digest. - * @p: The &struct nvme_fabric_options instance to query. + * libnvme_fabric_options_get_hdr_digest() - Get hdr_digest. + * @p: The &struct libnvme_fabric_options instance to query. * * Return: The value of the hdr_digest field. */ -bool nvme_fabric_options_get_hdr_digest(const struct nvme_fabric_options *p); +bool libnvme_fabric_options_get_hdr_digest( + const struct libnvme_fabric_options *p); /** - * nvme_fabric_options_set_host_iface() - Set host_iface. - * @p: The &struct nvme_fabric_options instance to update. + * libnvme_fabric_options_set_host_iface() - Set host_iface. + * @p: The &struct libnvme_fabric_options instance to update. * @host_iface: Value to assign to the host_iface field. */ -void nvme_fabric_options_set_host_iface( - struct nvme_fabric_options *p, +void libnvme_fabric_options_set_host_iface( + struct libnvme_fabric_options *p, bool host_iface); /** - * nvme_fabric_options_get_host_iface() - Get host_iface. - * @p: The &struct nvme_fabric_options instance to query. + * libnvme_fabric_options_get_host_iface() - Get host_iface. + * @p: The &struct libnvme_fabric_options instance to query. * * Return: The value of the host_iface field. */ -bool nvme_fabric_options_get_host_iface(const struct nvme_fabric_options *p); +bool libnvme_fabric_options_get_host_iface( + const struct libnvme_fabric_options *p); /** - * nvme_fabric_options_set_host_traddr() - Set host_traddr. - * @p: The &struct nvme_fabric_options instance to update. + * libnvme_fabric_options_set_host_traddr() - Set host_traddr. + * @p: The &struct libnvme_fabric_options instance to update. * @host_traddr: Value to assign to the host_traddr field. */ -void nvme_fabric_options_set_host_traddr( - struct nvme_fabric_options *p, +void libnvme_fabric_options_set_host_traddr( + struct libnvme_fabric_options *p, bool host_traddr); /** - * nvme_fabric_options_get_host_traddr() - Get host_traddr. - * @p: The &struct nvme_fabric_options instance to query. + * libnvme_fabric_options_get_host_traddr() - Get host_traddr. + * @p: The &struct libnvme_fabric_options instance to query. * * Return: The value of the host_traddr field. */ -bool nvme_fabric_options_get_host_traddr(const struct nvme_fabric_options *p); +bool libnvme_fabric_options_get_host_traddr( + const struct libnvme_fabric_options *p); /** - * nvme_fabric_options_set_hostid() - Set hostid. - * @p: The &struct nvme_fabric_options instance to update. + * libnvme_fabric_options_set_hostid() - Set hostid. + * @p: The &struct libnvme_fabric_options instance to update. * @hostid: Value to assign to the hostid field. */ -void nvme_fabric_options_set_hostid(struct nvme_fabric_options *p, bool hostid); +void libnvme_fabric_options_set_hostid( + struct libnvme_fabric_options *p, + bool hostid); /** - * nvme_fabric_options_get_hostid() - Get hostid. - * @p: The &struct nvme_fabric_options instance to query. + * libnvme_fabric_options_get_hostid() - Get hostid. + * @p: The &struct libnvme_fabric_options instance to query. * * Return: The value of the hostid field. */ -bool nvme_fabric_options_get_hostid(const struct nvme_fabric_options *p); +bool libnvme_fabric_options_get_hostid(const struct libnvme_fabric_options *p); /** - * nvme_fabric_options_set_hostnqn() - Set hostnqn. - * @p: The &struct nvme_fabric_options instance to update. + * libnvme_fabric_options_set_hostnqn() - Set hostnqn. + * @p: The &struct libnvme_fabric_options instance to update. * @hostnqn: Value to assign to the hostnqn field. */ -void nvme_fabric_options_set_hostnqn( - struct nvme_fabric_options *p, +void libnvme_fabric_options_set_hostnqn( + struct libnvme_fabric_options *p, bool hostnqn); /** - * nvme_fabric_options_get_hostnqn() - Get hostnqn. - * @p: The &struct nvme_fabric_options instance to query. + * libnvme_fabric_options_get_hostnqn() - Get hostnqn. + * @p: The &struct libnvme_fabric_options instance to query. * * Return: The value of the hostnqn field. */ -bool nvme_fabric_options_get_hostnqn(const struct nvme_fabric_options *p); +bool libnvme_fabric_options_get_hostnqn(const struct libnvme_fabric_options *p); /** - * nvme_fabric_options_set_instance() - Set instance. - * @p: The &struct nvme_fabric_options instance to update. + * libnvme_fabric_options_set_instance() - Set instance. + * @p: The &struct libnvme_fabric_options instance to update. * @instance: Value to assign to the instance field. */ -void nvme_fabric_options_set_instance( - struct nvme_fabric_options *p, +void libnvme_fabric_options_set_instance( + struct libnvme_fabric_options *p, bool instance); /** - * nvme_fabric_options_get_instance() - Get instance. - * @p: The &struct nvme_fabric_options instance to query. + * libnvme_fabric_options_get_instance() - Get instance. + * @p: The &struct libnvme_fabric_options instance to query. * * Return: The value of the instance field. */ -bool nvme_fabric_options_get_instance(const struct nvme_fabric_options *p); +bool libnvme_fabric_options_get_instance( + const struct libnvme_fabric_options *p); /** - * nvme_fabric_options_set_keep_alive_tmo() - Set keep_alive_tmo. - * @p: The &struct nvme_fabric_options instance to update. + * libnvme_fabric_options_set_keep_alive_tmo() - Set keep_alive_tmo. + * @p: The &struct libnvme_fabric_options instance to update. * @keep_alive_tmo: Value to assign to the keep_alive_tmo field. */ -void nvme_fabric_options_set_keep_alive_tmo( - struct nvme_fabric_options *p, +void libnvme_fabric_options_set_keep_alive_tmo( + struct libnvme_fabric_options *p, bool keep_alive_tmo); /** - * nvme_fabric_options_get_keep_alive_tmo() - Get keep_alive_tmo. - * @p: The &struct nvme_fabric_options instance to query. + * libnvme_fabric_options_get_keep_alive_tmo() - Get keep_alive_tmo. + * @p: The &struct libnvme_fabric_options instance to query. * * Return: The value of the keep_alive_tmo field. */ -bool nvme_fabric_options_get_keep_alive_tmo( - const struct nvme_fabric_options *p); +bool libnvme_fabric_options_get_keep_alive_tmo( + const struct libnvme_fabric_options *p); /** - * nvme_fabric_options_set_keyring() - Set keyring. - * @p: The &struct nvme_fabric_options instance to update. + * libnvme_fabric_options_set_keyring() - Set keyring. + * @p: The &struct libnvme_fabric_options instance to update. * @keyring: Value to assign to the keyring field. */ -void nvme_fabric_options_set_keyring( - struct nvme_fabric_options *p, +void libnvme_fabric_options_set_keyring( + struct libnvme_fabric_options *p, bool keyring); /** - * nvme_fabric_options_get_keyring() - Get keyring. - * @p: The &struct nvme_fabric_options instance to query. + * libnvme_fabric_options_get_keyring() - Get keyring. + * @p: The &struct libnvme_fabric_options instance to query. * * Return: The value of the keyring field. */ -bool nvme_fabric_options_get_keyring(const struct nvme_fabric_options *p); +bool libnvme_fabric_options_get_keyring(const struct libnvme_fabric_options *p); /** - * nvme_fabric_options_set_nqn() - Set nqn. - * @p: The &struct nvme_fabric_options instance to update. + * libnvme_fabric_options_set_nqn() - Set nqn. + * @p: The &struct libnvme_fabric_options instance to update. * @nqn: Value to assign to the nqn field. */ -void nvme_fabric_options_set_nqn(struct nvme_fabric_options *p, bool nqn); +void libnvme_fabric_options_set_nqn(struct libnvme_fabric_options *p, bool nqn); /** - * nvme_fabric_options_get_nqn() - Get nqn. - * @p: The &struct nvme_fabric_options instance to query. + * libnvme_fabric_options_get_nqn() - Get nqn. + * @p: The &struct libnvme_fabric_options instance to query. * * Return: The value of the nqn field. */ -bool nvme_fabric_options_get_nqn(const struct nvme_fabric_options *p); +bool libnvme_fabric_options_get_nqn(const struct libnvme_fabric_options *p); /** - * nvme_fabric_options_set_nr_io_queues() - Set nr_io_queues. - * @p: The &struct nvme_fabric_options instance to update. + * libnvme_fabric_options_set_nr_io_queues() - Set nr_io_queues. + * @p: The &struct libnvme_fabric_options instance to update. * @nr_io_queues: Value to assign to the nr_io_queues field. */ -void nvme_fabric_options_set_nr_io_queues( - struct nvme_fabric_options *p, +void libnvme_fabric_options_set_nr_io_queues( + struct libnvme_fabric_options *p, bool nr_io_queues); /** - * nvme_fabric_options_get_nr_io_queues() - Get nr_io_queues. - * @p: The &struct nvme_fabric_options instance to query. + * libnvme_fabric_options_get_nr_io_queues() - Get nr_io_queues. + * @p: The &struct libnvme_fabric_options instance to query. * * Return: The value of the nr_io_queues field. */ -bool nvme_fabric_options_get_nr_io_queues(const struct nvme_fabric_options *p); +bool libnvme_fabric_options_get_nr_io_queues( + const struct libnvme_fabric_options *p); /** - * nvme_fabric_options_set_nr_poll_queues() - Set nr_poll_queues. - * @p: The &struct nvme_fabric_options instance to update. + * libnvme_fabric_options_set_nr_poll_queues() - Set nr_poll_queues. + * @p: The &struct libnvme_fabric_options instance to update. * @nr_poll_queues: Value to assign to the nr_poll_queues field. */ -void nvme_fabric_options_set_nr_poll_queues( - struct nvme_fabric_options *p, +void libnvme_fabric_options_set_nr_poll_queues( + struct libnvme_fabric_options *p, bool nr_poll_queues); /** - * nvme_fabric_options_get_nr_poll_queues() - Get nr_poll_queues. - * @p: The &struct nvme_fabric_options instance to query. + * libnvme_fabric_options_get_nr_poll_queues() - Get nr_poll_queues. + * @p: The &struct libnvme_fabric_options instance to query. * * Return: The value of the nr_poll_queues field. */ -bool nvme_fabric_options_get_nr_poll_queues( - const struct nvme_fabric_options *p); +bool libnvme_fabric_options_get_nr_poll_queues( + const struct libnvme_fabric_options *p); /** - * nvme_fabric_options_set_nr_write_queues() - Set nr_write_queues. - * @p: The &struct nvme_fabric_options instance to update. + * libnvme_fabric_options_set_nr_write_queues() - Set nr_write_queues. + * @p: The &struct libnvme_fabric_options instance to update. * @nr_write_queues: Value to assign to the nr_write_queues field. */ -void nvme_fabric_options_set_nr_write_queues( - struct nvme_fabric_options *p, +void libnvme_fabric_options_set_nr_write_queues( + struct libnvme_fabric_options *p, bool nr_write_queues); /** - * nvme_fabric_options_get_nr_write_queues() - Get nr_write_queues. - * @p: The &struct nvme_fabric_options instance to query. + * libnvme_fabric_options_get_nr_write_queues() - Get nr_write_queues. + * @p: The &struct libnvme_fabric_options instance to query. * * Return: The value of the nr_write_queues field. */ -bool nvme_fabric_options_get_nr_write_queues( - const struct nvme_fabric_options *p); +bool libnvme_fabric_options_get_nr_write_queues( + const struct libnvme_fabric_options *p); /** - * nvme_fabric_options_set_queue_size() - Set queue_size. - * @p: The &struct nvme_fabric_options instance to update. + * libnvme_fabric_options_set_queue_size() - Set queue_size. + * @p: The &struct libnvme_fabric_options instance to update. * @queue_size: Value to assign to the queue_size field. */ -void nvme_fabric_options_set_queue_size( - struct nvme_fabric_options *p, +void libnvme_fabric_options_set_queue_size( + struct libnvme_fabric_options *p, bool queue_size); /** - * nvme_fabric_options_get_queue_size() - Get queue_size. - * @p: The &struct nvme_fabric_options instance to query. + * libnvme_fabric_options_get_queue_size() - Get queue_size. + * @p: The &struct libnvme_fabric_options instance to query. * * Return: The value of the queue_size field. */ -bool nvme_fabric_options_get_queue_size(const struct nvme_fabric_options *p); +bool libnvme_fabric_options_get_queue_size( + const struct libnvme_fabric_options *p); /** - * nvme_fabric_options_set_reconnect_delay() - Set reconnect_delay. - * @p: The &struct nvme_fabric_options instance to update. + * libnvme_fabric_options_set_reconnect_delay() - Set reconnect_delay. + * @p: The &struct libnvme_fabric_options instance to update. * @reconnect_delay: Value to assign to the reconnect_delay field. */ -void nvme_fabric_options_set_reconnect_delay( - struct nvme_fabric_options *p, +void libnvme_fabric_options_set_reconnect_delay( + struct libnvme_fabric_options *p, bool reconnect_delay); /** - * nvme_fabric_options_get_reconnect_delay() - Get reconnect_delay. - * @p: The &struct nvme_fabric_options instance to query. + * libnvme_fabric_options_get_reconnect_delay() - Get reconnect_delay. + * @p: The &struct libnvme_fabric_options instance to query. * * Return: The value of the reconnect_delay field. */ -bool nvme_fabric_options_get_reconnect_delay( - const struct nvme_fabric_options *p); +bool libnvme_fabric_options_get_reconnect_delay( + const struct libnvme_fabric_options *p); /** - * nvme_fabric_options_set_tls() - Set tls. - * @p: The &struct nvme_fabric_options instance to update. + * libnvme_fabric_options_set_tls() - Set tls. + * @p: The &struct libnvme_fabric_options instance to update. * @tls: Value to assign to the tls field. */ -void nvme_fabric_options_set_tls(struct nvme_fabric_options *p, bool tls); +void libnvme_fabric_options_set_tls(struct libnvme_fabric_options *p, bool tls); /** - * nvme_fabric_options_get_tls() - Get tls. - * @p: The &struct nvme_fabric_options instance to query. + * libnvme_fabric_options_get_tls() - Get tls. + * @p: The &struct libnvme_fabric_options instance to query. * * Return: The value of the tls field. */ -bool nvme_fabric_options_get_tls(const struct nvme_fabric_options *p); +bool libnvme_fabric_options_get_tls(const struct libnvme_fabric_options *p); /** - * nvme_fabric_options_set_tls_key() - Set tls_key. - * @p: The &struct nvme_fabric_options instance to update. + * libnvme_fabric_options_set_tls_key() - Set tls_key. + * @p: The &struct libnvme_fabric_options instance to update. * @tls_key: Value to assign to the tls_key field. */ -void nvme_fabric_options_set_tls_key( - struct nvme_fabric_options *p, +void libnvme_fabric_options_set_tls_key( + struct libnvme_fabric_options *p, bool tls_key); /** - * nvme_fabric_options_get_tls_key() - Get tls_key. - * @p: The &struct nvme_fabric_options instance to query. + * libnvme_fabric_options_get_tls_key() - Get tls_key. + * @p: The &struct libnvme_fabric_options instance to query. * * Return: The value of the tls_key field. */ -bool nvme_fabric_options_get_tls_key(const struct nvme_fabric_options *p); +bool libnvme_fabric_options_get_tls_key(const struct libnvme_fabric_options *p); /** - * nvme_fabric_options_set_tos() - Set tos. - * @p: The &struct nvme_fabric_options instance to update. + * libnvme_fabric_options_set_tos() - Set tos. + * @p: The &struct libnvme_fabric_options instance to update. * @tos: Value to assign to the tos field. */ -void nvme_fabric_options_set_tos(struct nvme_fabric_options *p, bool tos); +void libnvme_fabric_options_set_tos(struct libnvme_fabric_options *p, bool tos); /** - * nvme_fabric_options_get_tos() - Get tos. - * @p: The &struct nvme_fabric_options instance to query. + * libnvme_fabric_options_get_tos() - Get tos. + * @p: The &struct libnvme_fabric_options instance to query. * * Return: The value of the tos field. */ -bool nvme_fabric_options_get_tos(const struct nvme_fabric_options *p); +bool libnvme_fabric_options_get_tos(const struct libnvme_fabric_options *p); /** - * nvme_fabric_options_set_traddr() - Set traddr. - * @p: The &struct nvme_fabric_options instance to update. + * libnvme_fabric_options_set_traddr() - Set traddr. + * @p: The &struct libnvme_fabric_options instance to update. * @traddr: Value to assign to the traddr field. */ -void nvme_fabric_options_set_traddr(struct nvme_fabric_options *p, bool traddr); +void libnvme_fabric_options_set_traddr( + struct libnvme_fabric_options *p, + bool traddr); /** - * nvme_fabric_options_get_traddr() - Get traddr. - * @p: The &struct nvme_fabric_options instance to query. + * libnvme_fabric_options_get_traddr() - Get traddr. + * @p: The &struct libnvme_fabric_options instance to query. * * Return: The value of the traddr field. */ -bool nvme_fabric_options_get_traddr(const struct nvme_fabric_options *p); +bool libnvme_fabric_options_get_traddr(const struct libnvme_fabric_options *p); /** - * nvme_fabric_options_set_transport() - Set transport. - * @p: The &struct nvme_fabric_options instance to update. + * libnvme_fabric_options_set_transport() - Set transport. + * @p: The &struct libnvme_fabric_options instance to update. * @transport: Value to assign to the transport field. */ -void nvme_fabric_options_set_transport( - struct nvme_fabric_options *p, +void libnvme_fabric_options_set_transport( + struct libnvme_fabric_options *p, bool transport); /** - * nvme_fabric_options_get_transport() - Get transport. - * @p: The &struct nvme_fabric_options instance to query. + * libnvme_fabric_options_get_transport() - Get transport. + * @p: The &struct libnvme_fabric_options instance to query. * * Return: The value of the transport field. */ -bool nvme_fabric_options_get_transport(const struct nvme_fabric_options *p); +bool libnvme_fabric_options_get_transport( + const struct libnvme_fabric_options *p); /** - * nvme_fabric_options_set_trsvcid() - Set trsvcid. - * @p: The &struct nvme_fabric_options instance to update. + * libnvme_fabric_options_set_trsvcid() - Set trsvcid. + * @p: The &struct libnvme_fabric_options instance to update. * @trsvcid: Value to assign to the trsvcid field. */ -void nvme_fabric_options_set_trsvcid( - struct nvme_fabric_options *p, +void libnvme_fabric_options_set_trsvcid( + struct libnvme_fabric_options *p, bool trsvcid); /** - * nvme_fabric_options_get_trsvcid() - Get trsvcid. - * @p: The &struct nvme_fabric_options instance to query. + * libnvme_fabric_options_get_trsvcid() - Get trsvcid. + * @p: The &struct libnvme_fabric_options instance to query. * * Return: The value of the trsvcid field. */ -bool nvme_fabric_options_get_trsvcid(const struct nvme_fabric_options *p); +bool libnvme_fabric_options_get_trsvcid(const struct libnvme_fabric_options *p); #endif /* _ACCESSORS_H_ */ diff --git a/libnvme/src/nvme/cleanup.h b/libnvme/src/nvme/cleanup.h index ac3461c655..d4ee5705ba 100644 --- a/libnvme/src/nvme/cleanup.h +++ b/libnvme/src/nvme/cleanup.h @@ -47,7 +47,7 @@ static inline void cleanup_fd(int *fd) static inline DEFINE_CLEANUP_FUNC(cleanup_addrinfo, struct addrinfo *, freeaddrinfo) #define _cleanup_addrinfo_ __cleanup__(cleanup_addrinfo) -static inline void free_uri(struct nvme_fabrics_uri **uri) +static inline void free_uri(struct libnvme_fabrics_uri **uri) { if (*uri) nvmf_free_uri(*uri); diff --git a/libnvme/src/nvme/cmds.c b/libnvme/src/nvme/cmds.c index d5de75ca5d..143c89c5e6 100644 --- a/libnvme/src/nvme/cmds.c +++ b/libnvme/src/nvme/cmds.c @@ -32,8 +32,8 @@ static void nvme_init_env(void) force_4k = true; } -__public int nvme_get_log(struct nvme_transport_handle *hdl, - struct nvme_passthru_cmd *cmd, bool rae, +__public int libnvme_get_log(struct libnvme_transport_handle *hdl, + struct libnvme_passthru_cmd *cmd, bool rae, __u32 xfer_len) { __u64 offset = 0, xfer, data_len = cmd->data_len; @@ -86,9 +86,9 @@ __public int nvme_get_log(struct nvme_transport_handle *hdl, cmd->addr = (__u64)(uintptr_t)ptr; if (hdl->uring_enabled) - ret = nvme_submit_admin_passthru_async(hdl, cmd); + ret = libnvme_submit_admin_passthru_async(hdl, cmd); else - ret = nvme_submit_admin_passthru(hdl, cmd); + ret = libnvme_submit_admin_passthru(hdl, cmd); if (ret) return ret; @@ -97,7 +97,7 @@ __public int nvme_get_log(struct nvme_transport_handle *hdl, } while (offset < data_len); if (hdl->uring_enabled) { - ret = nvme_wait_complete_passthru(hdl); + ret = libnvme_wait_complete_passthru(hdl); if (ret) return ret; } @@ -105,11 +105,11 @@ __public int nvme_get_log(struct nvme_transport_handle *hdl, return 0; } -static int read_ana_chunk(struct nvme_transport_handle *hdl, +static int read_ana_chunk(struct libnvme_transport_handle *hdl, enum nvme_log_ana_lsp lsp, bool rae, __u8 *log, __u8 **read, __u8 *to_read, __u8 *log_end) { - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; if (to_read > log_end) return -ENOSPC; @@ -120,7 +120,7 @@ static int read_ana_chunk(struct nvme_transport_handle *hdl, int ret; nvme_init_get_log_ana(&cmd, lsp, *read - log, *read, len); - ret = nvme_get_log(hdl, &cmd, rae, NVME_LOG_PAGE_PDU_SIZE); + ret = libnvme_get_log(hdl, &cmd, rae, NVME_LOG_PAGE_PDU_SIZE); if (ret) return ret; @@ -129,7 +129,7 @@ static int read_ana_chunk(struct nvme_transport_handle *hdl, return 0; } -static int try_read_ana(struct nvme_transport_handle *hdl, +static int try_read_ana(struct libnvme_transport_handle *hdl, enum nvme_log_ana_lsp lsp, bool rae, struct nvme_ana_log *log, __u8 *log_end, __u8 *read, __u8 **to_read, bool *may_retry) @@ -176,7 +176,7 @@ static int try_read_ana(struct nvme_transport_handle *hdl, return 0; } -__public int nvme_get_ana_log_atomic(struct nvme_transport_handle *hdl, +__public int libnvme_get_ana_log_atomic(struct libnvme_transport_handle *hdl, bool rae, bool rgo, struct nvme_ana_log *log, __u32 *len, unsigned int retries) { @@ -232,14 +232,14 @@ __public int nvme_get_ana_log_atomic(struct nvme_transport_handle *hdl, return -EAGAIN; } -__public int nvme_set_etdas(struct nvme_transport_handle *hdl, bool *changed) +__public int libnvme_set_etdas(struct libnvme_transport_handle *hdl, bool *changed) { struct nvme_feat_host_behavior da4; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; nvme_init_get_features_host_behavior(&cmd, 0, &da4); - err = nvme_submit_admin_passthru(hdl, &cmd); + err = libnvme_submit_admin_passthru(hdl, &cmd); if (err) return err; @@ -251,7 +251,7 @@ __public int nvme_set_etdas(struct nvme_transport_handle *hdl, bool *changed) da4.etdas = 1; nvme_init_set_features_host_behavior(&cmd, false, &da4); - err = nvme_submit_admin_passthru(hdl, &cmd); + err = libnvme_submit_admin_passthru(hdl, &cmd); if (err) return err; @@ -259,14 +259,14 @@ __public int nvme_set_etdas(struct nvme_transport_handle *hdl, bool *changed) return 0; } -__public int nvme_clear_etdas(struct nvme_transport_handle *hdl, bool *changed) +__public int libnvme_clear_etdas(struct libnvme_transport_handle *hdl, bool *changed) { struct nvme_feat_host_behavior da4; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; nvme_init_get_features_host_behavior(&cmd, 0, &da4); - err = nvme_submit_admin_passthru(hdl, &cmd); + err = libnvme_submit_admin_passthru(hdl, &cmd); if (err) return err; @@ -277,7 +277,7 @@ __public int nvme_clear_etdas(struct nvme_transport_handle *hdl, bool *changed) da4.etdas = 0; nvme_init_set_features_host_behavior(&cmd, false, &da4); - err = nvme_submit_admin_passthru(hdl, &cmd); + err = libnvme_submit_admin_passthru(hdl, &cmd); if (err) return err; @@ -285,18 +285,18 @@ __public int nvme_clear_etdas(struct nvme_transport_handle *hdl, bool *changed) return 0; } -__public int nvme_get_uuid_list(struct nvme_transport_handle *hdl, +__public int libnvme_get_uuid_list(struct libnvme_transport_handle *hdl, struct nvme_id_uuid_list *uuid_list) { - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; struct nvme_id_ctrl ctrl; int err; memset(&ctrl, 0, sizeof(struct nvme_id_ctrl)); nvme_init_identify_ctrl(&cmd, &ctrl); - err = nvme_submit_admin_passthru(hdl, &cmd); + err = libnvme_submit_admin_passthru(hdl, &cmd); if (err) { - nvme_msg(hdl->ctx, LOG_ERR, + libnvme_msg(hdl->ctx, LOG_ERR, "ERROR: nvme_identify_ctrl() failed 0x%x\n", err); return err; } @@ -304,25 +304,25 @@ __public int nvme_get_uuid_list(struct nvme_transport_handle *hdl, if ((ctrl.ctratt & NVME_CTRL_CTRATT_UUID_LIST) == NVME_CTRL_CTRATT_UUID_LIST) { nvme_init_identify_uuid_list(&cmd, uuid_list); - err = nvme_submit_admin_passthru(hdl, &cmd); + err = libnvme_submit_admin_passthru(hdl, &cmd); } return err; } -__public int nvme_get_telemetry_max(struct nvme_transport_handle *hdl, +__public int libnvme_get_telemetry_max(struct libnvme_transport_handle *hdl, enum nvme_telemetry_da *da, size_t *data_tx) { _cleanup_free_ struct nvme_id_ctrl *id_ctrl = NULL; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; - id_ctrl = __nvme_alloc(sizeof(*id_ctrl)); + id_ctrl = __libnvme_alloc(sizeof(*id_ctrl)); if (!id_ctrl) return -ENOMEM; nvme_init_identify_ctrl(&cmd, id_ctrl); - err = nvme_submit_admin_passthru(hdl, &cmd); + err = libnvme_submit_admin_passthru(hdl, &cmd); if (err) return err; @@ -346,14 +346,14 @@ __public int nvme_get_telemetry_max(struct nvme_transport_handle *hdl, return err; } -__public int nvme_get_telemetry_log(struct nvme_transport_handle *hdl, bool create, +__public int libnvme_get_telemetry_log(struct libnvme_transport_handle *hdl, bool create, bool ctrl, bool rae, size_t max_data_tx, enum nvme_telemetry_da da, struct nvme_telemetry_log **buf, size_t *size) { static const __u32 xfer = NVME_LOG_TELEM_BLOCK_SIZE; struct nvme_telemetry_log *telem; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; _cleanup_free_ void *log = NULL; void *tmp; int err; @@ -361,21 +361,21 @@ __public int nvme_get_telemetry_log(struct nvme_transport_handle *hdl, bool crea *size = 0; - log = __nvme_alloc(xfer); + log = __libnvme_alloc(xfer); if (!log) return -ENOMEM; if (ctrl) { nvme_init_get_log_telemetry_ctrl(&cmd, 0, log, xfer); - err = nvme_get_log(hdl, &cmd, true, xfer); + err = libnvme_get_log(hdl, &cmd, true, xfer); } else { if (create) { nvme_init_get_log_create_telemetry_host_mcda(&cmd, da, log); - err = nvme_get_log(hdl, &cmd, false, xfer); + err = libnvme_get_log(hdl, &cmd, false, xfer); } else { nvme_init_get_log_telemetry_host(&cmd, 0, log, xfer); - err = nvme_get_log(hdl, &cmd, false, xfer); + err = libnvme_get_log(hdl, &cmd, false, xfer); } } @@ -412,7 +412,7 @@ __public int nvme_get_telemetry_log(struct nvme_transport_handle *hdl, bool crea return -ENOENT; *size = (dalb + 1) * xfer; - tmp = __nvme_realloc(log, *size); + tmp = __libnvme_realloc(log, *size); if (!tmp) return -ENOMEM; log = tmp; @@ -421,7 +421,7 @@ __public int nvme_get_telemetry_log(struct nvme_transport_handle *hdl, bool crea nvme_init_get_log_telemetry_ctrl(&cmd, 0, log, *size); else nvme_init_get_log_telemetry_host(&cmd, 0, log, *size); - err = nvme_get_log(hdl, &cmd, rae, max_data_tx); + err = libnvme_get_log(hdl, &cmd, rae, max_data_tx); if (err) return err; @@ -430,7 +430,7 @@ __public int nvme_get_telemetry_log(struct nvme_transport_handle *hdl, bool crea return 0; } -static int nvme_check_get_telemetry_log(struct nvme_transport_handle *hdl, +static int nvme_check_get_telemetry_log(struct libnvme_transport_handle *hdl, bool create, bool ctrl, bool rae, struct nvme_telemetry_log **log, enum nvme_telemetry_da da, size_t *size) @@ -438,19 +438,19 @@ static int nvme_check_get_telemetry_log(struct nvme_transport_handle *hdl, enum nvme_telemetry_da max_da = 0; int err; - err = nvme_get_telemetry_max(hdl, &max_da, NULL); + err = libnvme_get_telemetry_max(hdl, &max_da, NULL); if (err) return err; if (da > max_da) return -ENOENT; - return nvme_get_telemetry_log(hdl, create, ctrl, rae, 4096, da, + return libnvme_get_telemetry_log(hdl, create, ctrl, rae, 4096, da, log, size); } -__public int nvme_get_ctrl_telemetry(struct nvme_transport_handle *hdl, bool rae, +__public int libnvme_get_ctrl_telemetry(struct libnvme_transport_handle *hdl, bool rae, struct nvme_telemetry_log **log, enum nvme_telemetry_da da, size_t *size) { @@ -458,7 +458,7 @@ __public int nvme_get_ctrl_telemetry(struct nvme_transport_handle *hdl, bool rae da, size); } -__public int nvme_get_host_telemetry(struct nvme_transport_handle *hdl, +__public int libnvme_get_host_telemetry(struct libnvme_transport_handle *hdl, struct nvme_telemetry_log **log, enum nvme_telemetry_da da, size_t *size) { @@ -466,7 +466,7 @@ __public int nvme_get_host_telemetry(struct nvme_transport_handle *hdl, da, size); } -__public int nvme_get_new_host_telemetry(struct nvme_transport_handle *hdl, +__public int libnvme_get_new_host_telemetry(struct libnvme_transport_handle *hdl, struct nvme_telemetry_log **log, enum nvme_telemetry_da da, size_t *size) { @@ -474,11 +474,11 @@ __public int nvme_get_new_host_telemetry(struct nvme_transport_handle *hdl, da, size); } -int nvme_get_lba_status_log(struct nvme_transport_handle *hdl, bool rae, +int libnvme_get_lba_status_log(struct libnvme_transport_handle *hdl, bool rae, struct nvme_lba_status_log **log) { _cleanup_free_ struct nvme_lba_status_log *buf = NULL; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; __u32 size; void *tmp; int err; @@ -488,7 +488,7 @@ int nvme_get_lba_status_log(struct nvme_transport_handle *hdl, bool rae, return -ENOMEM; nvme_init_get_log_lba_status(&cmd, 0, log, sizeof(*buf)); - err = nvme_get_log(hdl, &cmd, true, sizeof(*buf)); + err = libnvme_get_log(hdl, &cmd, true, sizeof(*buf)); if (err) { *log = NULL; return err; @@ -509,7 +509,7 @@ int nvme_get_lba_status_log(struct nvme_transport_handle *hdl, bool rae, buf = tmp; nvme_init_get_log_lba_status(&cmd, 0, buf, size); - err = nvme_get_log(hdl, &cmd, rae, NVME_LOG_PAGE_PDU_SIZE); + err = libnvme_get_log(hdl, &cmd, rae, NVME_LOG_PAGE_PDU_SIZE); if (err) { *log = NULL; return err; @@ -520,7 +520,7 @@ int nvme_get_lba_status_log(struct nvme_transport_handle *hdl, bool rae, return 0; } -__public size_t nvme_get_ana_log_len_from_id_ctrl(const struct nvme_id_ctrl *id_ctrl, +__public size_t libnvme_get_ana_log_len_from_id_ctrl(const struct nvme_id_ctrl *id_ctrl, bool rgo) { __u32 nanagrpid = le32_to_cpu(id_ctrl->nanagrpid); @@ -530,39 +530,39 @@ __public size_t nvme_get_ana_log_len_from_id_ctrl(const struct nvme_id_ctrl *id_ return rgo ? size : size + le32_to_cpu(id_ctrl->mnan) * sizeof(__le32); } -__public int nvme_get_ana_log_len(struct nvme_transport_handle *hdl, size_t *analen) +__public int libnvme_get_ana_log_len(struct libnvme_transport_handle *hdl, size_t *analen) { _cleanup_free_ struct nvme_id_ctrl *ctrl = NULL; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int ret; - ctrl = __nvme_alloc(sizeof(*ctrl)); + ctrl = __libnvme_alloc(sizeof(*ctrl)); if (!ctrl) return -ENOMEM; nvme_init_identify_ctrl(&cmd, ctrl); - ret = nvme_submit_admin_passthru(hdl, &cmd); + ret = libnvme_submit_admin_passthru(hdl, &cmd); if (ret) return ret; - *analen = nvme_get_ana_log_len_from_id_ctrl(ctrl, false); + *analen = libnvme_get_ana_log_len_from_id_ctrl(ctrl, false); return 0; } -__public int nvme_get_logical_block_size(struct nvme_transport_handle *hdl, +__public int libnvme_get_logical_block_size(struct libnvme_transport_handle *hdl, __u32 nsid, int *blksize) { _cleanup_free_ struct nvme_id_ns *ns = NULL; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; __u8 flbas; int ret; - ns = __nvme_alloc(sizeof(*ns)); + ns = __libnvme_alloc(sizeof(*ns)); if (!ns) return -ENOMEM; nvme_init_identify_ns(&cmd, nsid, ns); - ret = nvme_submit_admin_passthru(hdl, &cmd); + ret = libnvme_submit_admin_passthru(hdl, &cmd); if (ret) return ret; @@ -572,7 +572,7 @@ __public int nvme_get_logical_block_size(struct nvme_transport_handle *hdl, return 0; } -__public int nvme_get_feature_length(int fid, __u32 cdw11, enum nvme_data_tfr dir, +__public int libnvme_get_feature_length(int fid, __u32 cdw11, enum nvme_data_tfr dir, __u32 *len) { switch (fid) { @@ -645,7 +645,7 @@ __public int nvme_get_feature_length(int fid, __u32 cdw11, enum nvme_data_tfr di return 0; } -__public int nvme_get_directive_receive_length(enum nvme_directive_dtype dtype, +__public int libnvme_get_directive_receive_length(enum nvme_directive_dtype dtype, enum nvme_directive_receive_doper doper, __u32 *len) { switch (dtype) { diff --git a/libnvme/src/nvme/cmds.h b/libnvme/src/nvme/cmds.h index 47ea8ea55c..97ba590fed 100644 --- a/libnvme/src/nvme/cmds.h +++ b/libnvme/src/nvme/cmds.h @@ -331,7 +331,7 @@ enum nvme_cmd_dword_fields { * Prepare the @cmd data structure for the NVMe Identify command. */ static inline void -nvme_init_identify(struct nvme_passthru_cmd *cmd, +nvme_init_identify(struct libnvme_passthru_cmd *cmd, __u32 nsid, enum nvme_csi csi, enum nvme_identify_cns cns, void *data, __u32 len) { @@ -363,7 +363,7 @@ nvme_init_identify(struct nvme_passthru_cmd *cmd, * CNS value %NVME_IDENTIFY_CNS_NS. */ static inline void -nvme_init_identify_ns(struct nvme_passthru_cmd *cmd, +nvme_init_identify_ns(struct libnvme_passthru_cmd *cmd, __u32 nsid, struct nvme_id_ns *id) { nvme_init_identify(cmd, nsid, NVME_CSI_NVM, @@ -381,7 +381,8 @@ nvme_init_identify_ns(struct nvme_passthru_cmd *cmd, * CNS value %NVME_IDENTIFY_CNS_CTRL. */ static inline void -nvme_init_identify_ctrl(struct nvme_passthru_cmd *cmd, struct nvme_id_ctrl *id) +nvme_init_identify_ctrl(struct libnvme_passthru_cmd *cmd, + struct nvme_id_ctrl *id) { nvme_init_identify(cmd, NVME_NSID_NONE, NVME_CSI_NVM, NVME_IDENTIFY_CNS_CTRL, @@ -399,7 +400,7 @@ nvme_init_identify_ctrl(struct nvme_passthru_cmd *cmd, struct nvme_id_ctrl *id) * CNS value %NVME_IDENTIFY_CNS_NS_ACTIVE_LIST. */ static inline void -nvme_init_identify_active_ns_list(struct nvme_passthru_cmd *cmd, +nvme_init_identify_active_ns_list(struct libnvme_passthru_cmd *cmd, __u32 nsid, struct nvme_ns_list *list) { nvme_init_identify(cmd, nsid, NVME_CSI_NVM, @@ -418,7 +419,7 @@ nvme_init_identify_active_ns_list(struct nvme_passthru_cmd *cmd, * CNS value %NVME_IDENTIFY_CNS_NS_DESC_LIST. */ static inline void -nvme_init_identify_ns_descs_list(struct nvme_passthru_cmd *cmd, +nvme_init_identify_ns_descs_list(struct libnvme_passthru_cmd *cmd, __u32 nsid, struct nvme_ns_id_desc *descs) { nvme_init_identify(cmd, nsid, NVME_CSI_NVM, @@ -438,7 +439,7 @@ nvme_init_identify_ns_descs_list(struct nvme_passthru_cmd *cmd, * CNS value %NVME_IDENTIFY_CNS_NS_ACTIVE_LIST. */ static inline void -nvme_init_identify_nvmset_list(struct nvme_passthru_cmd *cmd, +nvme_init_identify_nvmset_list(struct libnvme_passthru_cmd *cmd, __u32 nsid, __u16 nvmsetid, struct nvme_id_nvmset_list *nvmset) { nvme_init_identify(cmd, nsid, NVME_CSI_NVM, @@ -462,7 +463,7 @@ nvme_init_identify_nvmset_list(struct nvme_passthru_cmd *cmd, * CNS value %NVME_IDENTIFY_CNS_CSI_NS. */ static inline void -nvme_init_identify_csi_ns(struct nvme_passthru_cmd *cmd, +nvme_init_identify_csi_ns(struct libnvme_passthru_cmd *cmd, __u32 nsid, enum nvme_csi csi, __u8 uidx, void *data) { nvme_init_identify(cmd, nsid, csi, @@ -484,7 +485,7 @@ nvme_init_identify_csi_ns(struct nvme_passthru_cmd *cmd, * CNS value %NVME_IDENTIFY_CNS_CSI_CTRL. */ static inline void -nvme_init_identify_csi_ctrl(struct nvme_passthru_cmd *cmd, +nvme_init_identify_csi_ctrl(struct libnvme_passthru_cmd *cmd, enum nvme_csi csi, void *data) { nvme_init_identify(cmd, NVME_NSID_NONE, csi, @@ -504,7 +505,7 @@ nvme_init_identify_csi_ctrl(struct nvme_passthru_cmd *cmd, * CNS value %NVME_IDENTIFY_CNS_CSI_NS_ACTIVE_LIST. */ static inline void -nvme_init_identify_csi_active_ns_list(struct nvme_passthru_cmd *cmd, +nvme_init_identify_csi_active_ns_list(struct libnvme_passthru_cmd *cmd, __u32 nsid, enum nvme_csi csi, struct nvme_ns_list *ns_list) { nvme_init_identify(cmd, nsid, csi, @@ -524,7 +525,8 @@ nvme_init_identify_csi_active_ns_list(struct nvme_passthru_cmd *cmd, * CNS value %NVME_IDENTIFY_CNS_CSI_INDEPENDENT_ID_NS. */ static inline void -nvme_init_identify_csi_independent_identify_id_ns(struct nvme_passthru_cmd *cmd, +nvme_init_identify_csi_independent_identify_id_ns( + struct libnvme_passthru_cmd *cmd, __u32 nsid, struct nvme_id_independent_id_ns *ns) { nvme_init_identify(cmd, nsid, NVME_CSI_NVM, @@ -545,7 +547,7 @@ nvme_init_identify_csi_independent_identify_id_ns(struct nvme_passthru_cmd *cmd, * CNS value %NVME_IDENTIFY_CNS_NS_USER_DATA_FORMAT. */ static inline void -nvme_init_identify_ns_user_data_format(struct nvme_passthru_cmd *cmd, +nvme_init_identify_ns_user_data_format(struct libnvme_passthru_cmd *cmd, enum nvme_csi csi, __u16 fidx, __u8 uidx, void *data) { nvme_init_identify(cmd, NVME_NSID_NONE, csi, @@ -572,7 +574,7 @@ nvme_init_identify_ns_user_data_format(struct nvme_passthru_cmd *cmd, * CNS value %NVME_IDENTIFY_CNS_CSI_NS_USER_DATA_FORMAT. */ static inline void -nvme_init_identify_csi_ns_user_data_format(struct nvme_passthru_cmd *cmd, +nvme_init_identify_csi_ns_user_data_format(struct libnvme_passthru_cmd *cmd, enum nvme_csi csi, __u16 fidx, __u8 uidx, void *data) { nvme_init_identify(cmd, NVME_NSID_NONE, csi, @@ -597,7 +599,7 @@ nvme_init_identify_csi_ns_user_data_format(struct nvme_passthru_cmd *cmd, * CNS value %NVME_IDENTIFY_CNS_ALLOCATED_NS_LIST. */ static inline void -nvme_init_identify_allocated_ns_list(struct nvme_passthru_cmd *cmd, +nvme_init_identify_allocated_ns_list(struct libnvme_passthru_cmd *cmd, __u32 nsid, struct nvme_ns_list *ns_list) { nvme_init_identify(cmd, nsid, NVME_CSI_NVM, @@ -616,7 +618,7 @@ nvme_init_identify_allocated_ns_list(struct nvme_passthru_cmd *cmd, * CNS value %NVME_IDENTIFY_CNS_ALLOCATED_NS. */ static inline void -nvme_init_identify_allocated_ns(struct nvme_passthru_cmd *cmd, +nvme_init_identify_allocated_ns(struct libnvme_passthru_cmd *cmd, __u32 nsid, struct nvme_id_ns *ns) { nvme_init_identify(cmd, nsid, NVME_CSI_NVM, @@ -636,7 +638,7 @@ nvme_init_identify_allocated_ns(struct nvme_passthru_cmd *cmd, * CNS value %NVME_IDENTIFY_CNS_NS_CTRL_LIST. */ static inline void -nvme_init_identify_ns_ctrl_list(struct nvme_passthru_cmd *cmd, +nvme_init_identify_ns_ctrl_list(struct libnvme_passthru_cmd *cmd, __u32 nsid, __u16 cntid, struct nvme_ctrl_list *cntlist) { nvme_init_identify(cmd, nsid, NVME_CSI_NVM, @@ -658,7 +660,7 @@ nvme_init_identify_ns_ctrl_list(struct nvme_passthru_cmd *cmd, * CNS value %NVME_IDENTIFY_CNS_CTRL_LIST. */ static inline void -nvme_init_identify_ctrl_list(struct nvme_passthru_cmd *cmd, +nvme_init_identify_ctrl_list(struct libnvme_passthru_cmd *cmd, __u16 cntid, struct nvme_ctrl_list *cntlist) { nvme_init_identify(cmd, NVME_NSID_NONE, NVME_CSI_NVM, @@ -680,7 +682,7 @@ nvme_init_identify_ctrl_list(struct nvme_passthru_cmd *cmd, * CNS value %NVME_IDENTIFY_CNS_PRIMARY_CTRL_CAP. */ static inline void -nvme_init_identify_primary_ctrl_cap(struct nvme_passthru_cmd *cmd, +nvme_init_identify_primary_ctrl_cap(struct libnvme_passthru_cmd *cmd, __u16 cntid, struct nvme_primary_ctrl_cap *cap) { nvme_init_identify(cmd, NVME_NSID_NONE, NVME_CSI_NVM, @@ -702,7 +704,7 @@ nvme_init_identify_primary_ctrl_cap(struct nvme_passthru_cmd *cmd, * CNS value %NVME_IDENTIFY_CNS_SECONDARY_CTRL_LIST. */ static inline void -nvme_init_identify_secondary_ctrl_list(struct nvme_passthru_cmd *cmd, +nvme_init_identify_secondary_ctrl_list(struct libnvme_passthru_cmd *cmd, __u16 cntid, struct nvme_secondary_ctrl_list *sc_list) { nvme_init_identify(cmd, NVME_NSID_NONE, NVME_CSI_NVM, @@ -724,7 +726,7 @@ nvme_init_identify_secondary_ctrl_list(struct nvme_passthru_cmd *cmd, * CNS value %NVME_IDENTIFY_CNS_SECONDARY_CTRL_LIST. */ static inline void -nvme_init_identify_ns_granularity(struct nvme_passthru_cmd *cmd, +nvme_init_identify_ns_granularity(struct libnvme_passthru_cmd *cmd, struct nvme_id_ns_granularity_list *gr_list) { nvme_init_identify(cmd, NVME_NSID_NONE, NVME_CSI_NVM, @@ -742,7 +744,7 @@ nvme_init_identify_ns_granularity(struct nvme_passthru_cmd *cmd, * CNS value %NVME_IDENTIFY_CNS_UUID_LIST. */ static inline void -nvme_init_identify_uuid_list(struct nvme_passthru_cmd *cmd, +nvme_init_identify_uuid_list(struct libnvme_passthru_cmd *cmd, struct nvme_id_uuid_list *uuid_list) { nvme_init_identify(cmd, NVME_UUID_NONE, NVME_CSI_NVM, @@ -761,7 +763,7 @@ nvme_init_identify_uuid_list(struct nvme_passthru_cmd *cmd, * CNS value %NVME_IDENTIFY_CNS_DOMAIN_LIST. */ static inline void -nvme_init_identify_domain_list(struct nvme_passthru_cmd *cmd, +nvme_init_identify_domain_list(struct libnvme_passthru_cmd *cmd, __u16 domid, struct nvme_id_domain_list *list) { nvme_init_identify(cmd, NVME_NSID_NONE, NVME_CSI_NVM, @@ -783,7 +785,7 @@ nvme_init_identify_domain_list(struct nvme_passthru_cmd *cmd, * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline void -nvme_init_identify_endurance_group_id(struct nvme_passthru_cmd *cmd, +nvme_init_identify_endurance_group_id(struct libnvme_passthru_cmd *cmd, __u16 enggid, struct nvme_id_endurance_group_list *list) { nvme_init_identify(cmd, NVME_NSID_NONE, NVME_CSI_NVM, @@ -806,7 +808,7 @@ nvme_init_identify_endurance_group_id(struct nvme_passthru_cmd *cmd, * CNS value %NVME_IDENTIFY_CNS_CSI_ALLOCATED_NS_LIST. */ static inline void -nvme_init_identify_csi_allocated_ns_list(struct nvme_passthru_cmd *cmd, +nvme_init_identify_csi_allocated_ns_list(struct libnvme_passthru_cmd *cmd, __u32 nsid, enum nvme_csi csi, struct nvme_ns_list *ns_list) { nvme_init_identify(cmd, nsid, csi, @@ -826,7 +828,7 @@ nvme_init_identify_csi_allocated_ns_list(struct nvme_passthru_cmd *cmd, * CNS value %NVME_IDENTIFY_CNS_CSI_ID_NS_DATA_STRUCTURE. */ static inline void -nvme_init_identify_csi_id_ns_data_structure(struct nvme_passthru_cmd *cmd, +nvme_init_identify_csi_id_ns_data_structure(struct libnvme_passthru_cmd *cmd, __u32 nsid, enum nvme_csi csi, void *data) { nvme_init_identify(cmd, nsid, csi, @@ -848,7 +850,7 @@ nvme_init_identify_csi_id_ns_data_structure(struct nvme_passthru_cmd *cmd, * received (see &enum nvme_status_field) or a negative error otherwise. */ static inline void -nvme_init_identify_command_set_structure(struct nvme_passthru_cmd *cmd, +nvme_init_identify_command_set_structure(struct libnvme_passthru_cmd *cmd, __u16 cntid, struct nvme_id_iocs *iocs) { nvme_init_identify(cmd, NVME_NSID_NONE, NVME_CSI_NVM, @@ -867,7 +869,7 @@ nvme_init_identify_command_set_structure(struct nvme_passthru_cmd *cmd, * @data: User space destination address to transfer the data */ static inline void -nvme_init_zns_identify_ns(struct nvme_passthru_cmd *cmd, +nvme_init_zns_identify_ns(struct libnvme_passthru_cmd *cmd, __u32 nsid, struct nvme_zns_id_ns *data) { nvme_init_identify(cmd, nsid, NVME_CSI_ZNS, @@ -882,7 +884,7 @@ nvme_init_zns_identify_ns(struct nvme_passthru_cmd *cmd, * @id: User space destination address to transfer the data */ static inline void -nvme_init_zns_identify_ctrl(struct nvme_passthru_cmd *cmd, +nvme_init_zns_identify_ctrl(struct libnvme_passthru_cmd *cmd, struct nvme_zns_id_ctrl *id) { nvme_init_identify(cmd, NVME_NSID_NONE, NVME_CSI_ZNS, @@ -897,7 +899,7 @@ nvme_init_zns_identify_ctrl(struct nvme_passthru_cmd *cmd, * @lpo: Log Page Offset to set */ static inline void -nvme_init_get_log_lpo(struct nvme_passthru_cmd *cmd, __u64 lpo) +nvme_init_get_log_lpo(struct libnvme_passthru_cmd *cmd, __u64 lpo) { cmd->cdw12 = lpo & 0xffffffff; cmd->cdw13 = lpo >> 32; @@ -914,7 +916,7 @@ nvme_init_get_log_lpo(struct nvme_passthru_cmd *cmd, __u64 lpo) * @len: Length of provided user buffer to hold the log data in bytes */ static inline void -nvme_init_get_log(struct nvme_passthru_cmd *cmd, __u32 nsid, +nvme_init_get_log(struct libnvme_passthru_cmd *cmd, __u32 nsid, enum nvme_cmd_get_log_lid lid, enum nvme_csi csi, void *data, __u32 len) { @@ -956,7 +958,7 @@ nvme_init_get_log(struct nvme_passthru_cmd *cmd, __u32 nsid, * LID value %NVME_LOG_LID_SUPPORTED_LOG_PAGES. */ static inline void -nvme_init_get_log_supported_log_pages(struct nvme_passthru_cmd *cmd, +nvme_init_get_log_supported_log_pages(struct libnvme_passthru_cmd *cmd, enum nvme_csi csi, struct nvme_supported_log_pages *log) { nvme_init_get_log(cmd, NVME_NSID_ALL, NVME_LOG_LID_SUPPORTED_LOG_PAGES, @@ -973,8 +975,8 @@ nvme_init_get_log_supported_log_pages(struct nvme_passthru_cmd *cmd, * LID value %NVME_LOG_LID_ERROR. */ static inline void -nvme_init_get_log_error(struct nvme_passthru_cmd *cmd, unsigned int nr_entries, - struct nvme_error_log_page *err_log) +nvme_init_get_log_error(struct libnvme_passthru_cmd *cmd, + unsigned int nr_entries, struct nvme_error_log_page *err_log) { nvme_init_get_log(cmd, NVME_NSID_ALL, NVME_LOG_LID_ERROR, NVME_CSI_NVM, err_log, sizeof(*err_log) * nr_entries); @@ -991,7 +993,7 @@ nvme_init_get_log_error(struct nvme_passthru_cmd *cmd, unsigned int nr_entries, * LID value %NVME_LOG_LID_SMART. */ static inline void -nvme_init_get_log_smart(struct nvme_passthru_cmd *cmd, __u32 nsid, +nvme_init_get_log_smart(struct libnvme_passthru_cmd *cmd, __u32 nsid, struct nvme_smart_log *smart_log) { nvme_init_get_log(cmd, nsid, NVME_LOG_LID_SMART, NVME_CSI_NVM, @@ -1008,7 +1010,7 @@ nvme_init_get_log_smart(struct nvme_passthru_cmd *cmd, __u32 nsid, * LID value %NVME_LOG_LID_SMART. */ static inline void -nvme_init_get_log_fw_slot(struct nvme_passthru_cmd *cmd, +nvme_init_get_log_fw_slot(struct libnvme_passthru_cmd *cmd, struct nvme_firmware_slot *fw_log) { nvme_init_get_log(cmd, NVME_NSID_ALL, NVME_LOG_LID_FW_SLOT, @@ -1025,7 +1027,7 @@ nvme_init_get_log_fw_slot(struct nvme_passthru_cmd *cmd, * LID value %NVME_LOG_LID_CHANGED_NS. */ static inline void -nvme_init_get_log_changed_ns(struct nvme_passthru_cmd *cmd, +nvme_init_get_log_changed_ns(struct libnvme_passthru_cmd *cmd, struct nvme_ns_list *ns_log) { nvme_init_get_log(cmd, NVME_NSID_ALL, NVME_LOG_LID_CHANGED_NS, @@ -1044,7 +1046,7 @@ nvme_init_get_log_changed_ns(struct nvme_passthru_cmd *cmd, * LID value %NVME_LOG_LID_CMD_EFFECTS. */ static inline void -nvme_init_get_log_cmd_effects(struct nvme_passthru_cmd *cmd, +nvme_init_get_log_cmd_effects(struct libnvme_passthru_cmd *cmd, enum nvme_csi csi, struct nvme_cmd_effects_log *effects_log) { nvme_init_get_log(cmd, NVME_NSID_ALL, NVME_LOG_LID_CMD_EFFECTS, csi, @@ -1061,7 +1063,7 @@ nvme_init_get_log_cmd_effects(struct nvme_passthru_cmd *cmd, * LID value %NVME_LOG_LID_DEVICE_SELF_TEST. */ static inline void -nvme_init_get_log_device_self_test(struct nvme_passthru_cmd *cmd, +nvme_init_get_log_device_self_test(struct libnvme_passthru_cmd *cmd, struct nvme_self_test_log *log) { nvme_init_get_log(cmd, NVME_NSID_ALL, NVME_LOG_LID_DEVICE_SELF_TEST, @@ -1080,7 +1082,7 @@ nvme_init_get_log_device_self_test(struct nvme_passthru_cmd *cmd, * LID value %NVME_LOG_LID_TELEMETRY_HOST. */ static inline void -nvme_init_get_log_telemetry_host(struct nvme_passthru_cmd *cmd, __u64 lpo, +nvme_init_get_log_telemetry_host(struct libnvme_passthru_cmd *cmd, __u64 lpo, void *log, __u32 len) { nvme_init_get_log(cmd, NVME_NSID_NONE, NVME_LOG_LID_TELEMETRY_HOST, @@ -1103,7 +1105,7 @@ nvme_init_get_log_telemetry_host(struct nvme_passthru_cmd *cmd, __u64 lpo, * LSP value %NVME_LOG_TELEM_HOST_LSP_CREATE. */ static inline void -nvme_init_get_log_create_telemetry_host_mcda(struct nvme_passthru_cmd *cmd, +nvme_init_get_log_create_telemetry_host_mcda(struct libnvme_passthru_cmd *cmd, enum nvme_telemetry_da mcda, struct nvme_telemetry_log *log) { nvme_init_get_log(cmd, NVME_NSID_NONE, NVME_LOG_LID_TELEMETRY_HOST, @@ -1125,7 +1127,7 @@ nvme_init_get_log_create_telemetry_host_mcda(struct nvme_passthru_cmd *cmd, * LSP value %NVME_LOG_TELEM_HOST_LSP_CREATE. */ static inline void -nvme_init_get_log_create_telemetry_host(struct nvme_passthru_cmd *cmd, +nvme_init_get_log_create_telemetry_host(struct libnvme_passthru_cmd *cmd, struct nvme_telemetry_log *log) { nvme_init_get_log_create_telemetry_host_mcda(cmd, @@ -1144,7 +1146,7 @@ nvme_init_get_log_create_telemetry_host(struct nvme_passthru_cmd *cmd, * LID value %NVME_LOG_LID_TELEMETRY_CTRL. */ static inline void -nvme_init_get_log_telemetry_ctrl(struct nvme_passthru_cmd *cmd, +nvme_init_get_log_telemetry_ctrl(struct libnvme_passthru_cmd *cmd, __u64 lpo, void *log, __u32 len) { nvme_init_get_log(cmd, NVME_NSID_NONE, NVME_LOG_LID_TELEMETRY_CTRL, @@ -1163,8 +1165,8 @@ nvme_init_get_log_telemetry_ctrl(struct nvme_passthru_cmd *cmd, * LID value %NVME_LOG_LID_ENDURANCE_GROUP. */ static inline void -nvme_init_get_log_endurance_group(struct nvme_passthru_cmd *cmd, __u16 endgid, - struct nvme_endurance_group_log *log) +nvme_init_get_log_endurance_group(struct libnvme_passthru_cmd *cmd, + __u16 endgid, struct nvme_endurance_group_log *log) { nvme_init_get_log(cmd, NVME_NSID_NONE, NVME_LOG_LID_ENDURANCE_GROUP, NVME_CSI_NVM, log, sizeof(*log)); @@ -1184,7 +1186,7 @@ nvme_init_get_log_endurance_group(struct nvme_passthru_cmd *cmd, __u16 endgid, * LID value %NVME_LOG_LID_PREDICTABLE_LAT_NVMSET. */ static inline void -nvme_init_get_log_predictable_lat_nvmset(struct nvme_passthru_cmd *cmd, +nvme_init_get_log_predictable_lat_nvmset(struct libnvme_passthru_cmd *cmd, __u16 nvmsetid, struct nvme_nvmset_predictable_lat_log *log) { nvme_init_get_log(cmd, NVME_NSID_NONE, @@ -1207,7 +1209,7 @@ nvme_init_get_log_predictable_lat_nvmset(struct nvme_passthru_cmd *cmd, * LID value %NVME_LOG_LID_PREDICTABLE_LAT_AGG. */ static inline void -nvme_init_get_log_predictable_lat_event(struct nvme_passthru_cmd *cmd, +nvme_init_get_log_predictable_lat_event(struct libnvme_passthru_cmd *cmd, __u64 lpo, void *log, __u32 len) { nvme_init_get_log(cmd, NVME_NSID_NONE, @@ -1230,7 +1232,7 @@ nvme_init_get_log_predictable_lat_event(struct nvme_passthru_cmd *cmd, * LID value %NVME_LOG_LID_ANA. */ static inline void -nvme_init_get_log_ana(struct nvme_passthru_cmd *cmd, +nvme_init_get_log_ana(struct libnvme_passthru_cmd *cmd, enum nvme_log_ana_lsp lsp, __u64 lpo, void *log, __u32 len) { nvme_init_get_log(cmd, NVME_NSID_NONE, @@ -1254,7 +1256,7 @@ nvme_init_get_log_ana(struct nvme_passthru_cmd *cmd, * LID value %NVME_LOG_LID_ANA and LSP value %NVME_LOG_ANA_LSP_RGO_GROUPS_ONLY */ static inline void -nvme_init_get_log_ana_groups(struct nvme_passthru_cmd *cmd, +nvme_init_get_log_ana_groups(struct libnvme_passthru_cmd *cmd, struct nvme_ana_log *log, __u32 len) { nvme_init_get_log_ana(cmd, NVME_LOG_ANA_LSP_RGO_GROUPS_ONLY, @@ -1273,7 +1275,7 @@ nvme_init_get_log_ana_groups(struct nvme_passthru_cmd *cmd, * LID value %NVME_LOG_PERSISTENT_EVENT */ static inline void -nvme_init_get_log_persistent_event(struct nvme_passthru_cmd *cmd, +nvme_init_get_log_persistent_event(struct libnvme_passthru_cmd *cmd, enum nvme_pevent_log_action action, void *pevent_log, __u32 len) { @@ -1297,7 +1299,7 @@ nvme_init_get_log_persistent_event(struct nvme_passthru_cmd *cmd, * LID value %NVME_LOG_LID_LBA_STATUS */ static inline void -nvme_init_get_log_lba_status(struct nvme_passthru_cmd *cmd, +nvme_init_get_log_lba_status(struct libnvme_passthru_cmd *cmd, __u64 lpo, void *log, __u32 len) { nvme_init_get_log(cmd, NVME_NSID_NONE, @@ -1319,7 +1321,7 @@ nvme_init_get_log_lba_status(struct nvme_passthru_cmd *cmd, * LID value %NVME_LOG_LID_ENDURANCE_GRP_EVT */ static inline void -nvme_init_get_log_endurance_grp_evt(struct nvme_passthru_cmd *cmd, +nvme_init_get_log_endurance_grp_evt(struct libnvme_passthru_cmd *cmd, __u64 lpo, void *log, __u32 len) { nvme_init_get_log(cmd, NVME_NSID_NONE, @@ -1339,7 +1341,7 @@ nvme_init_get_log_endurance_grp_evt(struct nvme_passthru_cmd *cmd, * LID value %NVME_LOG_LID_MEDIA_UNIT_STATUS */ static inline void -nvme_init_get_log_media_unit_stat(struct nvme_passthru_cmd *cmd, +nvme_init_get_log_media_unit_stat(struct libnvme_passthru_cmd *cmd, __u16 domid, struct nvme_media_unit_stat_log *mus) { nvme_init_get_log(cmd, NVME_NSID_NONE, @@ -1361,7 +1363,7 @@ nvme_init_get_log_media_unit_stat(struct nvme_passthru_cmd *cmd, * LID value %NVME_LOG_LID_SUPPORTED_CAP_CONFIG_LIST */ static inline void -nvme_init_get_log_support_cap_config_list(struct nvme_passthru_cmd *cmd, +nvme_init_get_log_support_cap_config_list(struct libnvme_passthru_cmd *cmd, __u16 domid, struct nvme_supported_cap_config_list_log *cap) { nvme_init_get_log(cmd, NVME_NSID_NONE, @@ -1383,7 +1385,7 @@ nvme_init_get_log_support_cap_config_list(struct nvme_passthru_cmd *cmd, * LID value %NVME_LOG_LID_FID_SUPPORTED_EFFECTS */ static inline void -nvme_init_get_log_fid_supported_effects(struct nvme_passthru_cmd *cmd, +nvme_init_get_log_fid_supported_effects(struct libnvme_passthru_cmd *cmd, enum nvme_csi csi, struct nvme_fid_supported_effects_log *log) { nvme_init_get_log(cmd, NVME_NSID_NONE, @@ -1401,7 +1403,7 @@ nvme_init_get_log_fid_supported_effects(struct nvme_passthru_cmd *cmd, * LID value %NVME_LOG_LID_MI_CMD_SUPPORTED_EFFECTS */ static inline void -nvme_init_get_log_mi_cmd_supported_effects(struct nvme_passthru_cmd *cmd, +nvme_init_get_log_mi_cmd_supported_effects(struct libnvme_passthru_cmd *cmd, struct nvme_mi_cmd_supported_effects_log *log) { nvme_init_get_log(cmd, NVME_NSID_NONE, @@ -1421,7 +1423,7 @@ nvme_init_get_log_mi_cmd_supported_effects(struct nvme_passthru_cmd *cmd, * LID value %NVME_LOG_LID_CMD_AND_FEAT_LOCKDOWN */ static inline void -nvme_init_get_log_lockdown(struct nvme_passthru_cmd *cmd, +nvme_init_get_log_lockdown(struct libnvme_passthru_cmd *cmd, __u8 cnscp, struct nvme_lockdown_log *lockdown_log) { nvme_init_get_log(cmd, NVME_NSID_ALL, @@ -1445,7 +1447,7 @@ nvme_init_get_log_lockdown(struct nvme_passthru_cmd *cmd, * LID value %NVME_LOG_LID_BOOT_PARTITION */ static inline void -nvme_init_get_log_boot_partition(struct nvme_passthru_cmd *cmd, +nvme_init_get_log_boot_partition(struct libnvme_passthru_cmd *cmd, __u8 lsp, struct nvme_boot_partition *part, __u32 len) { nvme_init_get_log(cmd, NVME_NSID_NONE, @@ -1468,7 +1470,7 @@ nvme_init_get_log_boot_partition(struct nvme_passthru_cmd *cmd, * LID value %NVME_LOG_LID_ROTATIONAL_MEDIA_INFO */ static inline void -nvme_init_get_log_rotational_media_info(struct nvme_passthru_cmd *cmd, +nvme_init_get_log_rotational_media_info(struct libnvme_passthru_cmd *cmd, __u16 endgid, struct nvme_rotational_media_info_log *log, __u32 len) { @@ -1492,9 +1494,9 @@ nvme_init_get_log_rotational_media_info(struct nvme_passthru_cmd *cmd, * LID value %NVME_LOG_LID_DISPERSED_NS_PARTICIPATING_NSS */ static inline void -nvme_init_get_log_dispersed_ns_participating_nss(struct nvme_passthru_cmd *cmd, - __u32 nsid, struct nvme_dispersed_ns_participating_nss_log *log, - __u32 len) +nvme_init_get_log_dispersed_ns_participating_nss( + struct libnvme_passthru_cmd *cmd, __u32 nsid, + struct nvme_dispersed_ns_participating_nss_log *log, __u32 len) { nvme_init_get_log(cmd, nsid, NVME_LOG_LID_DISPERSED_NS_PARTICIPATING_NSS, NVME_CSI_NVM, @@ -1512,7 +1514,7 @@ nvme_init_get_log_dispersed_ns_participating_nss(struct nvme_passthru_cmd *cmd, * LID value %NVME_LOG_LID_MGMT_ADDR_LIST */ static inline void -nvme_init_get_log_mgmt_addr_list(struct nvme_passthru_cmd *cmd, +nvme_init_get_log_mgmt_addr_list(struct libnvme_passthru_cmd *cmd, struct nvme_mgmt_addr_list_log *log, __u32 len) { nvme_init_get_log(cmd, NVME_NSID_ALL, @@ -1531,7 +1533,7 @@ nvme_init_get_log_mgmt_addr_list(struct nvme_passthru_cmd *cmd, * LID value %NVME_LOG_LID_POWER_MEASUREMENT */ static inline void -nvme_init_get_log_power_measurement(struct nvme_passthru_cmd *cmd, +nvme_init_get_log_power_measurement(struct libnvme_passthru_cmd *cmd, struct nvme_power_meas_log *log, __u32 len) { nvme_init_get_log(cmd, NVME_NSID_ALL, @@ -1553,7 +1555,7 @@ nvme_init_get_log_power_measurement(struct nvme_passthru_cmd *cmd, * LID value %NVME_LOG_LID_PHY_RX_EOM */ static inline void -nvme_init_get_log_phy_rx_eom(struct nvme_passthru_cmd *cmd, +nvme_init_get_log_phy_rx_eom(struct libnvme_passthru_cmd *cmd, __u8 lsp, __u16 controller, struct nvme_phy_rx_eom_log *log, __u32 len) { @@ -1580,7 +1582,7 @@ nvme_init_get_log_phy_rx_eom(struct nvme_passthru_cmd *cmd, * LID value %NVME_LOG_LID_REACHABILITY_GROUPS */ static inline void -nvme_init_get_log_reachability_groups(struct nvme_passthru_cmd *cmd, +nvme_init_get_log_reachability_groups(struct libnvme_passthru_cmd *cmd, bool rgo, struct nvme_reachability_groups_log *log, __u32 len) { nvme_init_get_log(cmd, NVME_NSID_ALL, @@ -1603,7 +1605,7 @@ nvme_init_get_log_reachability_groups(struct nvme_passthru_cmd *cmd, * LID value %NVME_LOG_LID_REACHABILITY_ASSOCIATIONS */ static inline void -nvme_init_get_log_reachability_associations(struct nvme_passthru_cmd *cmd, +nvme_init_get_log_reachability_associations(struct libnvme_passthru_cmd *cmd, bool rao, struct nvme_reachability_associations_log *log, __u32 len) { @@ -1626,7 +1628,7 @@ nvme_init_get_log_reachability_associations(struct nvme_passthru_cmd *cmd, * LID value %NVME_LOG_LID_CHANGED_ALLOC_NS */ static inline void -nvme_init_get_log_changed_alloc_ns(struct nvme_passthru_cmd *cmd, +nvme_init_get_log_changed_alloc_ns(struct libnvme_passthru_cmd *cmd, struct nvme_ns_list *log, __u32 len) { nvme_init_get_log(cmd, NVME_NSID_ALL, @@ -1647,7 +1649,7 @@ nvme_init_get_log_changed_alloc_ns(struct nvme_passthru_cmd *cmd, * LID value %NVME_LOG_LID_FDP_CONFIGS */ static inline void -nvme_init_get_log_fdp_configurations(struct nvme_passthru_cmd *cmd, +nvme_init_get_log_fdp_configurations(struct libnvme_passthru_cmd *cmd, __u16 egid, __u64 lpo, void *log, __u32 len) { nvme_init_get_log(cmd, NVME_NSID_NONE, @@ -1672,7 +1674,7 @@ nvme_init_get_log_fdp_configurations(struct nvme_passthru_cmd *cmd, * LID value %NVME_LOG_LID_RUH_USAGE */ static inline void -nvme_init_get_log_reclaim_unit_handle_usage(struct nvme_passthru_cmd *cmd, +nvme_init_get_log_reclaim_unit_handle_usage(struct libnvme_passthru_cmd *cmd, __u16 egid, __u64 lpo, void *log, __u32 len) { nvme_init_get_log(cmd, NVME_NSID_NONE, @@ -1697,7 +1699,7 @@ nvme_init_get_log_reclaim_unit_handle_usage(struct nvme_passthru_cmd *cmd, * LID value %NVME_LOG_LID_FDP_STATS */ static inline -void nvme_init_get_log_fdp_stats(struct nvme_passthru_cmd *cmd, +void nvme_init_get_log_fdp_stats(struct libnvme_passthru_cmd *cmd, __u16 egid, __u64 lpo, void *log, __u32 len) { nvme_init_get_log(cmd, NVME_NSID_NONE, @@ -1724,7 +1726,7 @@ void nvme_init_get_log_fdp_stats(struct nvme_passthru_cmd *cmd, * LID value %NVME_LOG_LID_FDP_EVENTS */ static inline void -nvme_init_get_log_fdp_events(struct nvme_passthru_cmd *cmd, +nvme_init_get_log_fdp_events(struct libnvme_passthru_cmd *cmd, bool host_events, __u16 egid, __u64 lpo, void *log, __u32 len) { nvme_init_get_log(cmd, NVME_NSID_NONE, @@ -1751,7 +1753,7 @@ nvme_init_get_log_fdp_events(struct nvme_passthru_cmd *cmd, * LID value %NVME_LOG_LID_DISCOVERY */ static inline void -nvme_init_get_log_discovery(struct nvme_passthru_cmd *cmd, +nvme_init_get_log_discovery(struct libnvme_passthru_cmd *cmd, __u64 lpo, void *log, __u32 len) { nvme_init_get_log(cmd, NVME_NSID_NONE, @@ -1772,7 +1774,7 @@ nvme_init_get_log_discovery(struct nvme_passthru_cmd *cmd, * LID value %NVME_LOG_LID_HOST_DISCOVERY */ static inline void -nvme_init_get_log_host_discovery(struct nvme_passthru_cmd *cmd, +nvme_init_get_log_host_discovery(struct libnvme_passthru_cmd *cmd, bool allhoste, struct nvme_host_discover_log *log, __u32 len) { nvme_init_get_log(cmd, NVME_NSID_ALL, @@ -1794,7 +1796,7 @@ nvme_init_get_log_host_discovery(struct nvme_passthru_cmd *cmd, * LID value %NVME_LOG_LID_AVE_DISCOVERY */ static inline void -nvme_init_get_log_ave_discovery(struct nvme_passthru_cmd *cmd, +nvme_init_get_log_ave_discovery(struct libnvme_passthru_cmd *cmd, struct nvme_ave_discover_log *log, __u32 len) { nvme_init_get_log(cmd, NVME_NSID_ALL, @@ -1813,7 +1815,7 @@ nvme_init_get_log_ave_discovery(struct nvme_passthru_cmd *cmd, * LID value %NVME_LOG_LID_PULL_MODEL_DDC_REQ */ static inline void -nvme_init_get_log_pull_model_ddc_req(struct nvme_passthru_cmd *cmd, +nvme_init_get_log_pull_model_ddc_req(struct libnvme_passthru_cmd *cmd, struct nvme_pull_model_ddc_req_log *log, __u32 len) { nvme_init_get_log(cmd, NVME_NSID_ALL, @@ -1831,7 +1833,7 @@ nvme_init_get_log_pull_model_ddc_req(struct nvme_passthru_cmd *cmd, * LID value %NVME_LOG_LID_RESERVATION */ static inline void -nvme_init_get_log_reservation(struct nvme_passthru_cmd *cmd, +nvme_init_get_log_reservation(struct libnvme_passthru_cmd *cmd, struct nvme_resv_notification_log *log) { nvme_init_get_log(cmd, NVME_NSID_ALL, @@ -1849,7 +1851,7 @@ nvme_init_get_log_reservation(struct nvme_passthru_cmd *cmd, * LID value %NVME_LOG_LID_SANITIZE */ static inline void -nvme_init_get_log_sanitize(struct nvme_passthru_cmd *cmd, +nvme_init_get_log_sanitize(struct libnvme_passthru_cmd *cmd, struct nvme_sanitize_log_page *log) { nvme_init_get_log(cmd, NVME_NSID_ALL, @@ -1868,7 +1870,7 @@ nvme_init_get_log_sanitize(struct nvme_passthru_cmd *cmd, * LID value %NVME_LOG_LID_ZNS_CHANGED_ZONES */ static inline void -nvme_init_get_log_zns_changed_zones(struct nvme_passthru_cmd *cmd, +nvme_init_get_log_zns_changed_zones(struct libnvme_passthru_cmd *cmd, __u32 nsid, struct nvme_zns_changed_zone_log *log) { nvme_init_get_log(cmd, nsid, @@ -1884,7 +1886,7 @@ nvme_init_get_log_zns_changed_zones(struct nvme_passthru_cmd *cmd, * @sv: Save value across power states */ static inline void -nvme_init_set_features(struct nvme_passthru_cmd *cmd, __u8 fid, bool sv) +nvme_init_set_features(struct libnvme_passthru_cmd *cmd, __u8 fid, bool sv) { __u32 cdw10 = NVME_FIELD_ENCODE(fid, NVME_SET_FEATURES_CDW10_FID_SHIFT, @@ -1913,7 +1915,7 @@ nvme_init_set_features(struct nvme_passthru_cmd *cmd, __u8 fid, bool sv) * FID value %NVME_FEAT_FID_ARBRITARTION */ static inline void -nvme_init_set_features_arbitration(struct nvme_passthru_cmd *cmd, +nvme_init_set_features_arbitration(struct libnvme_passthru_cmd *cmd, bool sv, __u8 ab, __u8 lpw, __u8 mpw, __u8 hpw) { nvme_init_set_features(cmd, NVME_FEAT_FID_ARBITRATION, sv); @@ -1943,7 +1945,7 @@ nvme_init_set_features_arbitration(struct nvme_passthru_cmd *cmd, * FID value %NVME_FEAT_FID_PWRMGMT_PS */ static inline void -nvme_init_set_features_power_mgmt(struct nvme_passthru_cmd *cmd, +nvme_init_set_features_power_mgmt(struct libnvme_passthru_cmd *cmd, bool sv, __u8 ps, __u8 wh) { @@ -1969,7 +1971,7 @@ nvme_init_set_features_power_mgmt(struct nvme_passthru_cmd *cmd, * FID value %NVME_FEAT_FID_LBA_RANGE */ static inline void -nvme_init_set_features_lba_range(struct nvme_passthru_cmd *cmd, +nvme_init_set_features_lba_range(struct libnvme_passthru_cmd *cmd, __u32 nsid, bool sv, __u8 num, struct nvme_lba_range_type *data) { @@ -1996,7 +1998,7 @@ nvme_init_set_features_lba_range(struct nvme_passthru_cmd *cmd, * FID value %NVME_FEAT_FID_TEMP_THRESH */ static inline void -nvme_init_set_features_temp_thresh(struct nvme_passthru_cmd *cmd, +nvme_init_set_features_temp_thresh(struct libnvme_passthru_cmd *cmd, bool sv, __u16 tmpth, __u8 tmpsel, enum nvme_feat_tmpthresh_thsel thsel, __u8 tmpthh) { @@ -2029,7 +2031,7 @@ nvme_init_set_features_temp_thresh(struct nvme_passthru_cmd *cmd, * FID value %NVME_FEAT_FID_ERR_RECOVERY */ static inline void -nvme_init_set_features_err_recovery(struct nvme_passthru_cmd *cmd, +nvme_init_set_features_err_recovery(struct libnvme_passthru_cmd *cmd, __u32 nsid, bool sv, __u16 tler, bool dulbe) { nvme_init_set_features(cmd, NVME_FEAT_FID_ERR_RECOVERY, sv); @@ -2053,7 +2055,7 @@ nvme_init_set_features_err_recovery(struct nvme_passthru_cmd *cmd, * FID value %NVME_FEAT_FID_VOLATILE_WC */ static inline void -nvme_init_set_features_volatile_wc(struct nvme_passthru_cmd *cmd, +nvme_init_set_features_volatile_wc(struct libnvme_passthru_cmd *cmd, bool sv, bool wce) { nvme_init_set_features(cmd, NVME_FEAT_FID_VOLATILE_WC, sv); @@ -2074,7 +2076,7 @@ nvme_init_set_features_volatile_wc(struct nvme_passthru_cmd *cmd, * FID value %NVME_FEAT_FID_IRQ_COALESCE */ static inline void -nvme_init_set_features_irq_coalesce(struct nvme_passthru_cmd *cmd, +nvme_init_set_features_irq_coalesce(struct libnvme_passthru_cmd *cmd, bool sv, __u8 thr, __u8 time) { nvme_init_set_features(cmd, NVME_FEAT_FID_IRQ_COALESCE, sv); @@ -2098,7 +2100,7 @@ nvme_init_set_features_irq_coalesce(struct nvme_passthru_cmd *cmd, * FID value %NVME_FEAT_FID_IRQ_CONFIG */ static inline void -nvme_init_set_features_irq_config(struct nvme_passthru_cmd *cmd, +nvme_init_set_features_irq_config(struct libnvme_passthru_cmd *cmd, bool sv, __u16 iv, bool cd) { nvme_init_set_features(cmd, NVME_FEAT_FID_IRQ_CONFIG, sv); @@ -2121,7 +2123,7 @@ nvme_init_set_features_irq_config(struct nvme_passthru_cmd *cmd, * FID value %NVME_FEAT_FID_WRITE_ATOMIC */ static inline void -nvme_init_set_features_write_atomic(struct nvme_passthru_cmd *cmd, +nvme_init_set_features_write_atomic(struct libnvme_passthru_cmd *cmd, bool sv, bool dn) { nvme_init_set_features(cmd, NVME_FEAT_FID_WRITE_ATOMIC, sv); @@ -2141,7 +2143,7 @@ nvme_init_set_features_write_atomic(struct nvme_passthru_cmd *cmd, * FID value %NVME_FEAT_FID_ASYNC_EVENT */ static inline void -nvme_init_set_features_async_event(struct nvme_passthru_cmd *cmd, +nvme_init_set_features_async_event(struct libnvme_passthru_cmd *cmd, bool sv, __u32 events) { nvme_init_set_features(cmd, NVME_FEAT_FID_ASYNC_EVENT, sv); @@ -2160,7 +2162,7 @@ nvme_init_set_features_async_event(struct nvme_passthru_cmd *cmd, * FID value %NVME_FEAT_FID_AUTO_PST */ static inline void -nvme_init_set_features_auto_pst(struct nvme_passthru_cmd *cmd, +nvme_init_set_features_auto_pst(struct libnvme_passthru_cmd *cmd, bool sv, bool apste, struct nvme_feat_auto_pst *apst) { nvme_init_set_features(cmd, NVME_FEAT_FID_AUTO_PST, sv); @@ -2184,7 +2186,7 @@ nvme_init_set_features_auto_pst(struct nvme_passthru_cmd *cmd, * buffer via @ts, which this function will populate. */ static inline void -nvme_init_set_features_timestamp(struct nvme_passthru_cmd *cmd, +nvme_init_set_features_timestamp(struct libnvme_passthru_cmd *cmd, bool sv, __u64 tstmp, struct nvme_timestamp *ts) { __le64 t = htole64(tstmp); @@ -2208,7 +2210,7 @@ nvme_init_set_features_timestamp(struct nvme_passthru_cmd *cmd, * FID value %NVME_FEAT_FID_HCTM */ static inline void -nvme_init_set_features_hctm(struct nvme_passthru_cmd *cmd, +nvme_init_set_features_hctm(struct libnvme_passthru_cmd *cmd, bool sv, __u16 tmt2, __u16 tmt1) { nvme_init_set_features(cmd, NVME_FEAT_FID_HCTM, sv); @@ -2231,7 +2233,7 @@ nvme_init_set_features_hctm(struct nvme_passthru_cmd *cmd, * FID value %NVME_FEAT_FID_NOPSC */ static inline void -nvme_init_set_features_nopsc(struct nvme_passthru_cmd *cmd, +nvme_init_set_features_nopsc(struct libnvme_passthru_cmd *cmd, bool sv, bool noppme) { nvme_init_set_features(cmd, NVME_FEAT_FID_NOPSC, sv); @@ -2252,7 +2254,7 @@ nvme_init_set_features_nopsc(struct nvme_passthru_cmd *cmd, * FID value %NVME_FEAT_FID_RRL */ static inline void -nvme_init_set_features_rrl(struct nvme_passthru_cmd *cmd, +nvme_init_set_features_rrl(struct libnvme_passthru_cmd *cmd, bool sv, __u16 nvmsetid, __u8 rrl) { nvme_init_set_features(cmd, NVME_FEAT_FID_RRL, sv); @@ -2277,7 +2279,7 @@ nvme_init_set_features_rrl(struct nvme_passthru_cmd *cmd, * FID value %NVME_FEAT_FID_PLM_CONFIG */ static inline void -nvme_init_set_features_plm_config(struct nvme_passthru_cmd *cmd, +nvme_init_set_features_plm_config(struct libnvme_passthru_cmd *cmd, bool sv, __u16 nvmsetid, bool lpe, struct nvme_plm_config *data) { nvme_init_set_features(cmd, NVME_FEAT_FID_PLM_CONFIG, sv); @@ -2303,7 +2305,7 @@ nvme_init_set_features_plm_config(struct nvme_passthru_cmd *cmd, * FID value %NVME_FEAT_FID_PLM_WINDOW */ static inline void -nvme_init_set_features_plm_window(struct nvme_passthru_cmd *cmd, +nvme_init_set_features_plm_window(struct libnvme_passthru_cmd *cmd, bool sv, __u16 nvmsetid, enum nvme_feat_plm_window_select wsel) { @@ -2328,7 +2330,7 @@ nvme_init_set_features_plm_window(struct nvme_passthru_cmd *cmd, * FID value %NVME_FEAT_FID_LBA_STS_INTERVAL */ static inline void -nvme_init_set_features_lba_sts_interval(struct nvme_passthru_cmd *cmd, +nvme_init_set_features_lba_sts_interval(struct libnvme_passthru_cmd *cmd, bool sv, __u16 lsiri, __u16 lsipi) { nvme_init_set_features(cmd, NVME_FEAT_FID_LBA_STS_INTERVAL, sv); @@ -2351,7 +2353,7 @@ nvme_init_set_features_lba_sts_interval(struct nvme_passthru_cmd *cmd, * FID value %NVME_FEAT_FID_HOST_BEHAVIOR */ static inline void -nvme_init_set_features_host_behavior(struct nvme_passthru_cmd *cmd, +nvme_init_set_features_host_behavior(struct libnvme_passthru_cmd *cmd, bool sv, struct nvme_feat_host_behavior *data) { nvme_init_set_features(cmd, NVME_FEAT_FID_HOST_BEHAVIOR, sv); @@ -2370,7 +2372,7 @@ nvme_init_set_features_host_behavior(struct nvme_passthru_cmd *cmd, * FID value %NVME_FEAT_FID_SANITIZE */ static inline void -nvme_init_set_features_sanitize(struct nvme_passthru_cmd *cmd, +nvme_init_set_features_sanitize(struct libnvme_passthru_cmd *cmd, bool sv, bool nodrm) { nvme_init_set_features(cmd, NVME_FEAT_FID_SANITIZE, sv); @@ -2392,7 +2394,7 @@ nvme_init_set_features_sanitize(struct nvme_passthru_cmd *cmd, * FID value %NVME_FEAT_FID_ENDURANCE_EVT_CFG */ static inline void -nvme_init_set_features_endurance_evt_cfg(struct nvme_passthru_cmd *cmd, +nvme_init_set_features_endurance_evt_cfg(struct libnvme_passthru_cmd *cmd, bool sv, __u16 endgid, __u8 egcw) { nvme_init_set_features(cmd, NVME_FEAT_FID_ENDURANCE_EVT_CFG, sv); @@ -2415,7 +2417,7 @@ nvme_init_set_features_endurance_evt_cfg(struct nvme_passthru_cmd *cmd, * FID value %NVME_FEAT_FID_SW_PROGRESS */ static inline void -nvme_init_set_features_sw_progress(struct nvme_passthru_cmd *cmd, +nvme_init_set_features_sw_progress(struct libnvme_passthru_cmd *cmd, bool sv, __u8 pbslc) { nvme_init_set_features(cmd, NVME_FEAT_FID_SW_PROGRESS, sv); @@ -2436,7 +2438,7 @@ nvme_init_set_features_sw_progress(struct nvme_passthru_cmd *cmd, * FID value %NVME_FEAT_FID_HOST_ID. */ static inline void -nvme_init_set_features_host_id(struct nvme_passthru_cmd *cmd, +nvme_init_set_features_host_id(struct libnvme_passthru_cmd *cmd, bool sv, bool exhid, __u8 *hostid) { nvme_init_set_features(cmd, NVME_FEAT_FID_HOST_ID, sv); @@ -2459,7 +2461,7 @@ nvme_init_set_features_host_id(struct nvme_passthru_cmd *cmd, * FID value %NVME_FEAT_FID_RESV_MASK */ static inline void -nvme_init_set_features_resv_mask(struct nvme_passthru_cmd *cmd, __u32 nsid, +nvme_init_set_features_resv_mask(struct libnvme_passthru_cmd *cmd, __u32 nsid, bool sv, __u32 mask) { nvme_init_set_features(cmd, NVME_FEAT_FID_RESV_MASK, sv); @@ -2479,7 +2481,7 @@ nvme_init_set_features_resv_mask(struct nvme_passthru_cmd *cmd, __u32 nsid, * FID value %NVME_FEAT_FID_RESV_PERSIST */ static inline void -nvme_init_set_features_resv_persist(struct nvme_passthru_cmd *cmd, __u32 nsid, +nvme_init_set_features_resv_persist(struct libnvme_passthru_cmd *cmd, __u32 nsid, bool sv, bool ptpl) { nvme_init_set_features(cmd, NVME_FEAT_FID_RESV_PERSIST, sv); @@ -2501,8 +2503,8 @@ nvme_init_set_features_resv_persist(struct nvme_passthru_cmd *cmd, __u32 nsid, * FID value %NVME_FEAT_FID_WRITE_PROTECT */ static inline void -nvme_init_set_features_write_protect(struct nvme_passthru_cmd *cmd, __u32 nsid, - bool sv, enum nvme_feat_nswpcfg_state wps) +nvme_init_set_features_write_protect(struct libnvme_passthru_cmd *cmd, + __u32 nsid, bool sv, enum nvme_feat_nswpcfg_state wps) { nvme_init_set_features(cmd, NVME_FEAT_FID_WRITE_PROTECT, sv); cmd->nsid = nsid; @@ -2522,7 +2524,7 @@ nvme_init_set_features_write_protect(struct nvme_passthru_cmd *cmd, __u32 nsid, * FID value %NVME_FEAT_FID_IOCS_PROFILE */ static inline void -nvme_init_set_features_iocs_profile(struct nvme_passthru_cmd *cmd, +nvme_init_set_features_iocs_profile(struct libnvme_passthru_cmd *cmd, bool sv, __u16 iocsci) { nvme_init_set_features(cmd, NVME_FEAT_FID_IOCS_PROFILE, sv); @@ -2540,7 +2542,7 @@ nvme_init_set_features_iocs_profile(struct nvme_passthru_cmd *cmd, * see &enum nvme_get_features_sel */ static inline void -nvme_init_get_features(struct nvme_passthru_cmd *cmd, __u8 fid, +nvme_init_get_features(struct libnvme_passthru_cmd *cmd, __u8 fid, enum nvme_get_features_sel sel) { __u32 cdw10 = NVME_FIELD_ENCODE(fid, @@ -2567,7 +2569,7 @@ nvme_init_get_features(struct nvme_passthru_cmd *cmd, __u8 fid, * FID value %NVME_FEAT_FID_ARBITRATION */ static inline void -nvme_init_get_features_arbitration(struct nvme_passthru_cmd *cmd, +nvme_init_get_features_arbitration(struct libnvme_passthru_cmd *cmd, enum nvme_get_features_sel sel) { nvme_init_get_features(cmd, NVME_FEAT_FID_ARBITRATION, sel); @@ -2584,7 +2586,7 @@ nvme_init_get_features_arbitration(struct nvme_passthru_cmd *cmd, * FID value %NVME_FEAT_FID_POWER_MGMT */ static inline void -nvme_init_get_features_power_mgmt(struct nvme_passthru_cmd *cmd, +nvme_init_get_features_power_mgmt(struct libnvme_passthru_cmd *cmd, enum nvme_get_features_sel sel) { nvme_init_get_features(cmd, NVME_FEAT_FID_POWER_MGMT, sel); @@ -2603,7 +2605,7 @@ nvme_init_get_features_power_mgmt(struct nvme_passthru_cmd *cmd, * FID value %NVME_FEAT_FID_LBA_RANGE */ static inline void -nvme_init_get_features_lba_range(struct nvme_passthru_cmd *cmd, __u32 nsid, +nvme_init_get_features_lba_range(struct libnvme_passthru_cmd *cmd, __u32 nsid, enum nvme_get_features_sel sel, struct nvme_lba_range_type *lrt) { nvme_init_get_features(cmd, NVME_FEAT_FID_LBA_RANGE, sel); @@ -2625,7 +2627,7 @@ nvme_init_get_features_lba_range(struct nvme_passthru_cmd *cmd, __u32 nsid, * FID value %NVME_FEAT_FID_TEMP_THRESH */ static inline void -nvme_init_get_features_temp_thresh(struct nvme_passthru_cmd *cmd, +nvme_init_get_features_temp_thresh(struct libnvme_passthru_cmd *cmd, enum nvme_get_features_sel sel, __u8 tmpsel, enum nvme_feat_tmpthresh_thsel thsel) { @@ -2651,8 +2653,8 @@ nvme_init_get_features_temp_thresh(struct nvme_passthru_cmd *cmd, * FID value %NVME_FEAT_FID_ERR_RECOVERY */ static inline void -nvme_init_get_features_err_recovery(struct nvme_passthru_cmd *cmd, __u32 nsid, - enum nvme_get_features_sel sel) +nvme_init_get_features_err_recovery(struct libnvme_passthru_cmd *cmd, + __u32 nsid, enum nvme_get_features_sel sel) { nvme_init_get_features(cmd, NVME_FEAT_FID_ERR_RECOVERY, sel); cmd->nsid = nsid; @@ -2669,7 +2671,7 @@ nvme_init_get_features_err_recovery(struct nvme_passthru_cmd *cmd, __u32 nsid, * FID value %NVME_FEAT_FID_VOLATILE_WC */ static inline void -nvme_init_get_features_volatile_wc(struct nvme_passthru_cmd *cmd, +nvme_init_get_features_volatile_wc(struct libnvme_passthru_cmd *cmd, enum nvme_get_features_sel sel) { nvme_init_get_features(cmd, NVME_FEAT_FID_VOLATILE_WC, sel); @@ -2686,7 +2688,7 @@ nvme_init_get_features_volatile_wc(struct nvme_passthru_cmd *cmd, * FID value %NVME_FEAT_FID_NUM_QUEUES */ static inline void -nvme_init_get_features_num_queues(struct nvme_passthru_cmd *cmd, +nvme_init_get_features_num_queues(struct libnvme_passthru_cmd *cmd, enum nvme_get_features_sel sel) { nvme_init_get_features(cmd, NVME_FEAT_FID_NUM_QUEUES, sel); @@ -2703,7 +2705,7 @@ nvme_init_get_features_num_queues(struct nvme_passthru_cmd *cmd, * FID value %NVME_FEAT_FID_IRQ_COALESCE */ static inline void -nvme_init_get_features_irq_coalesce(struct nvme_passthru_cmd *cmd, +nvme_init_get_features_irq_coalesce(struct libnvme_passthru_cmd *cmd, enum nvme_get_features_sel sel) { nvme_init_get_features(cmd, NVME_FEAT_FID_IRQ_COALESCE, sel); @@ -2722,9 +2724,8 @@ nvme_init_get_features_irq_coalesce(struct nvme_passthru_cmd *cmd, * FID value %NVME_FEAT_FID_IRQ_CONFIG */ static inline void -nvme_init_get_features_irq_config(struct nvme_passthru_cmd *cmd, - enum nvme_get_features_sel sel, - __u16 iv, bool cd) +nvme_init_get_features_irq_config(struct libnvme_passthru_cmd *cmd, + enum nvme_get_features_sel sel, __u16 iv, bool cd) { __u32 cdw11 = NVME_FIELD_ENCODE(iv, NVME_FEAT_ICFG_IV_SHIFT, @@ -2748,7 +2749,7 @@ nvme_init_get_features_irq_config(struct nvme_passthru_cmd *cmd, * FID value %NVME_FEAT_FID_WRITE_ATOMIC */ static inline void -nvme_init_get_features_write_atomic(struct nvme_passthru_cmd *cmd, +nvme_init_get_features_write_atomic(struct libnvme_passthru_cmd *cmd, enum nvme_get_features_sel sel) { nvme_init_get_features(cmd, NVME_FEAT_FID_WRITE_ATOMIC, sel); @@ -2765,7 +2766,7 @@ nvme_init_get_features_write_atomic(struct nvme_passthru_cmd *cmd, * FID value %NVME_FEAT_FID_ASYNC_EVENT */ static inline void -nvme_init_get_features_async_event(struct nvme_passthru_cmd *cmd, +nvme_init_get_features_async_event(struct libnvme_passthru_cmd *cmd, enum nvme_get_features_sel sel) { nvme_init_get_features(cmd, NVME_FEAT_FID_ASYNC_EVENT, sel); @@ -2783,7 +2784,7 @@ nvme_init_get_features_async_event(struct nvme_passthru_cmd *cmd, * FID value %NVME_FEAT_FID_AUTO_PST */ static inline void -nvme_init_get_features_auto_pst(struct nvme_passthru_cmd *cmd, +nvme_init_get_features_auto_pst(struct libnvme_passthru_cmd *cmd, enum nvme_get_features_sel sel, struct nvme_feat_auto_pst *apst) { nvme_init_get_features(cmd, NVME_FEAT_FID_AUTO_PST, sel); @@ -2803,7 +2804,7 @@ nvme_init_get_features_auto_pst(struct nvme_passthru_cmd *cmd, * FID value %NVME_FEAT_FID_HOST_MEM_BUF */ static inline void -nvme_init_get_features_host_mem_buf(struct nvme_passthru_cmd *cmd, +nvme_init_get_features_host_mem_buf(struct libnvme_passthru_cmd *cmd, enum nvme_get_features_sel sel, struct nvme_host_mem_buf_attrs *attrs) { @@ -2824,7 +2825,7 @@ nvme_init_get_features_host_mem_buf(struct nvme_passthru_cmd *cmd, * FID value %NVME_FEAT_FID_TIMESTAMP */ static inline void -nvme_init_get_features_timestamp(struct nvme_passthru_cmd *cmd, +nvme_init_get_features_timestamp(struct libnvme_passthru_cmd *cmd, enum nvme_get_features_sel sel, struct nvme_timestamp *ts) { nvme_init_get_features(cmd, NVME_FEAT_FID_TIMESTAMP, sel); @@ -2843,7 +2844,7 @@ nvme_init_get_features_timestamp(struct nvme_passthru_cmd *cmd, * FID value %NVME_FEAT_FID_KATO */ static inline void -nvme_init_get_features_kato(struct nvme_passthru_cmd *cmd, +nvme_init_get_features_kato(struct libnvme_passthru_cmd *cmd, enum nvme_get_features_sel sel) { nvme_init_get_features(cmd, NVME_FEAT_FID_KATO, sel); @@ -2860,7 +2861,7 @@ nvme_init_get_features_kato(struct nvme_passthru_cmd *cmd, * FID value %NVME_FEAT_FID_HCTM */ static inline void -nvme_init_get_features_hctm(struct nvme_passthru_cmd *cmd, +nvme_init_get_features_hctm(struct libnvme_passthru_cmd *cmd, enum nvme_get_features_sel sel) { nvme_init_get_features(cmd, NVME_FEAT_FID_HCTM, sel); @@ -2877,7 +2878,7 @@ nvme_init_get_features_hctm(struct nvme_passthru_cmd *cmd, * FID value %NVME_FEAT_FID_NOPSC */ static inline void -nvme_init_get_features_nopsc(struct nvme_passthru_cmd *cmd, +nvme_init_get_features_nopsc(struct libnvme_passthru_cmd *cmd, enum nvme_get_features_sel sel) { nvme_init_get_features(cmd, NVME_FEAT_FID_NOPSC, sel); @@ -2894,7 +2895,7 @@ nvme_init_get_features_nopsc(struct nvme_passthru_cmd *cmd, * FID value %NVME_FEAT_FID_RRL */ static inline void -nvme_init_get_features_rrl(struct nvme_passthru_cmd *cmd, +nvme_init_get_features_rrl(struct libnvme_passthru_cmd *cmd, enum nvme_get_features_sel sel) { nvme_init_get_features(cmd, NVME_FEAT_FID_RRL, sel); @@ -2913,7 +2914,7 @@ nvme_init_get_features_rrl(struct nvme_passthru_cmd *cmd, * FID value %NVME_FEAT_FID_PLM_CONFIG */ static inline void -nvme_init_get_features_plm_config(struct nvme_passthru_cmd *cmd, +nvme_init_get_features_plm_config(struct libnvme_passthru_cmd *cmd, enum nvme_get_features_sel sel, __u16 nvmsetid, struct nvme_plm_config *plmc) { @@ -2937,7 +2938,7 @@ nvme_init_get_features_plm_config(struct nvme_passthru_cmd *cmd, * FID value %NVME_FEAT_FID_PLM_WINDOW */ static inline void -nvme_init_get_features_plm_window(struct nvme_passthru_cmd *cmd, +nvme_init_get_features_plm_window(struct libnvme_passthru_cmd *cmd, enum nvme_get_features_sel sel, __u16 nvmsetid) { nvme_init_get_features(cmd, NVME_FEAT_FID_PLM_WINDOW, sel); @@ -2957,7 +2958,7 @@ nvme_init_get_features_plm_window(struct nvme_passthru_cmd *cmd, * FID value %NVME_FEAT_FID_LBA_STS_INTERVAL */ static inline void -nvme_init_get_features_lba_sts_interval(struct nvme_passthru_cmd *cmd, +nvme_init_get_features_lba_sts_interval(struct libnvme_passthru_cmd *cmd, enum nvme_get_features_sel sel) { nvme_init_get_features(cmd, NVME_FEAT_FID_LBA_STS_INTERVAL, sel); @@ -2975,7 +2976,7 @@ nvme_init_get_features_lba_sts_interval(struct nvme_passthru_cmd *cmd, * FID value %NVME_FEAT_FID_HOST_BEHAVIOR */ static inline void -nvme_init_get_features_host_behavior(struct nvme_passthru_cmd *cmd, +nvme_init_get_features_host_behavior(struct libnvme_passthru_cmd *cmd, enum nvme_get_features_sel sel, struct nvme_feat_host_behavior *fhb) { @@ -2995,7 +2996,7 @@ nvme_init_get_features_host_behavior(struct nvme_passthru_cmd *cmd, * FID value %NVME_FEAT_FID_SANITIZE */ static inline void -nvme_init_get_features_sanitize(struct nvme_passthru_cmd *cmd, +nvme_init_get_features_sanitize(struct libnvme_passthru_cmd *cmd, enum nvme_get_features_sel sel) { nvme_init_get_features(cmd, NVME_FEAT_FID_SANITIZE, sel); @@ -3013,7 +3014,7 @@ nvme_init_get_features_sanitize(struct nvme_passthru_cmd *cmd, * FID value %NVME_FEAT_FID_ENDURANCE_EVT_CFG */ static inline void -nvme_init_get_features_endurance_event_cfg(struct nvme_passthru_cmd *cmd, +nvme_init_get_features_endurance_event_cfg(struct libnvme_passthru_cmd *cmd, enum nvme_get_features_sel sel, __u16 endgid) { nvme_init_get_features(cmd, NVME_FEAT_FID_ENDURANCE_EVT_CFG, sel); @@ -3033,7 +3034,7 @@ nvme_init_get_features_endurance_event_cfg(struct nvme_passthru_cmd *cmd, * FID value %NVME_FEAT_FID_SW_PROGRESS */ static inline void -nvme_init_get_features_sw_progress(struct nvme_passthru_cmd *cmd, +nvme_init_get_features_sw_progress(struct libnvme_passthru_cmd *cmd, enum nvme_get_features_sel sel) { nvme_init_get_features(cmd, NVME_FEAT_FID_SW_PROGRESS, sel); @@ -3053,7 +3054,7 @@ nvme_init_get_features_sw_progress(struct nvme_passthru_cmd *cmd, * FID value %NVME_FEAT_FID_HOST_ID */ static inline void -nvme_init_get_features_host_id(struct nvme_passthru_cmd *cmd, +nvme_init_get_features_host_id(struct libnvme_passthru_cmd *cmd, enum nvme_get_features_sel sel, bool exhid, void *hostid, __u32 len) { @@ -3077,7 +3078,7 @@ nvme_init_get_features_host_id(struct nvme_passthru_cmd *cmd, * FID value %NVME_FEAT_FID_RESV_MASK */ static inline void -nvme_init_get_features_resv_mask(struct nvme_passthru_cmd *cmd, __u32 nsid, +nvme_init_get_features_resv_mask(struct libnvme_passthru_cmd *cmd, __u32 nsid, enum nvme_get_features_sel sel) { nvme_init_get_features(cmd, NVME_FEAT_FID_RESV_MASK, sel); @@ -3096,8 +3097,8 @@ nvme_init_get_features_resv_mask(struct nvme_passthru_cmd *cmd, __u32 nsid, * FID value %NVME_FEAT_FID_RESV_PERSIST */ static inline void -nvme_init_get_features_resv_persist(struct nvme_passthru_cmd *cmd, __u32 nsid, - enum nvme_get_features_sel sel) +nvme_init_get_features_resv_persist(struct libnvme_passthru_cmd *cmd, + __u32 nsid, enum nvme_get_features_sel sel) { nvme_init_get_features(cmd, NVME_FEAT_FID_RESV_PERSIST, sel); cmd->nsid = nsid; @@ -3115,8 +3116,8 @@ nvme_init_get_features_resv_persist(struct nvme_passthru_cmd *cmd, __u32 nsid, * FID value %NVME_FEAT_FID_WRITE_PROTECT */ static inline void -nvme_init_get_features_write_protect(struct nvme_passthru_cmd *cmd, __u32 nsid, - enum nvme_get_features_sel sel) +nvme_init_get_features_write_protect(struct libnvme_passthru_cmd *cmd, + __u32 nsid, enum nvme_get_features_sel sel) { nvme_init_get_features(cmd, NVME_FEAT_FID_WRITE_PROTECT, sel); cmd->nsid = nsid; @@ -3133,7 +3134,7 @@ nvme_init_get_features_write_protect(struct nvme_passthru_cmd *cmd, __u32 nsid, * FID value %NVME_FEAT_FID_IOCS_PROFILE */ static inline void -nvme_init_get_features_iocs_profile(struct nvme_passthru_cmd *cmd, +nvme_init_get_features_iocs_profile(struct libnvme_passthru_cmd *cmd, enum nvme_get_features_sel sel) { nvme_init_get_features(cmd, NVME_FEAT_FID_IOCS_PROFILE, sel); @@ -3152,7 +3153,7 @@ nvme_init_get_features_iocs_profile(struct nvme_passthru_cmd *cmd, * Initializes the passthru command buffer for the Format NVM command. */ static inline void -nvme_init_format_nvm(struct nvme_passthru_cmd *cmd, __u32 nsid, __u8 lbaf, +nvme_init_format_nvm(struct libnvme_passthru_cmd *cmd, __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) { @@ -3191,7 +3192,7 @@ nvme_init_format_nvm(struct nvme_passthru_cmd *cmd, __u32 nsid, __u8 lbaf, * Initializes the passthru command buffer for the Namespace Management command. */ static inline void -nvme_init_ns_mgmt(struct nvme_passthru_cmd *cmd, __u32 nsid, +nvme_init_ns_mgmt(struct libnvme_passthru_cmd *cmd, __u32 nsid, enum nvme_ns_mgmt_sel sel, __u8 csi, struct nvme_ns_mgmt_host_sw_specified *data) { @@ -3221,7 +3222,7 @@ nvme_init_ns_mgmt(struct nvme_passthru_cmd *cmd, __u32 nsid, * command. The command uses NVME_NSID_NONE as the target NSID. */ static inline void -nvme_init_ns_mgmt_create(struct nvme_passthru_cmd *cmd, __u8 csi, +nvme_init_ns_mgmt_create(struct libnvme_passthru_cmd *cmd, __u8 csi, struct nvme_ns_mgmt_host_sw_specified *data) { nvme_init_ns_mgmt(cmd, NVME_NSID_NONE, NVME_NS_MGMT_SEL_CREATE, @@ -3239,7 +3240,7 @@ nvme_init_ns_mgmt_create(struct nvme_passthru_cmd *cmd, __u8 csi, * the target NSID. */ static inline void -nvme_init_ns_mgmt_delete(struct nvme_passthru_cmd *cmd, __u32 nsid) +nvme_init_ns_mgmt_delete(struct libnvme_passthru_cmd *cmd, __u32 nsid) { nvme_init_ns_mgmt(cmd, nsid, NVME_NS_MGMT_SEL_DELETE, NVME_CSI_NVM, NULL); @@ -3257,7 +3258,7 @@ nvme_init_ns_mgmt_delete(struct nvme_passthru_cmd *cmd, __u32 nsid) * command. */ static inline void -nvme_init_ns_attach(struct nvme_passthru_cmd *cmd, __u32 nsid, +nvme_init_ns_attach(struct libnvme_passthru_cmd *cmd, __u32 nsid, enum nvme_ns_attach_sel sel, struct nvme_ctrl_list *ctrlist) { memset(cmd, 0, sizeof(*cmd)); @@ -3282,7 +3283,7 @@ nvme_init_ns_attach(struct nvme_passthru_cmd *cmd, __u32 nsid, * (NVME_NS_ATTACH_SEL_CTRL_ATTACH). */ static inline void -nvme_init_ns_attach_ctrls(struct nvme_passthru_cmd *cmd, __u32 nsid, +nvme_init_ns_attach_ctrls(struct libnvme_passthru_cmd *cmd, __u32 nsid, struct nvme_ctrl_list *ctrlist) { nvme_init_ns_attach(cmd, nsid, NVME_NS_ATTACH_SEL_CTRL_ATTACH, @@ -3300,7 +3301,7 @@ nvme_init_ns_attach_ctrls(struct nvme_passthru_cmd *cmd, __u32 nsid, * (NVME_NS_ATTACH_SEL_CTRL_DEATTACH). */ static inline void -nvme_init_ns_detach_ctrls(struct nvme_passthru_cmd *cmd, __u32 nsid, +nvme_init_ns_detach_ctrls(struct libnvme_passthru_cmd *cmd, __u32 nsid, struct nvme_ctrl_list *ctrlist) { nvme_init_ns_attach(cmd, nsid, NVME_NS_ATTACH_SEL_CTRL_DEATTACH, @@ -3323,7 +3324,7 @@ nvme_init_ns_detach_ctrls(struct nvme_passthru_cmd *cmd, __u32 nsid, * Returns: 0 on success, or error code if arguments are invalid. */ static inline int -nvme_init_fw_download(struct nvme_passthru_cmd *cmd, void *data, +nvme_init_fw_download(struct libnvme_passthru_cmd *cmd, void *data, __u32 len, __u32 offset) { if (len & 0x3 || !len) @@ -3355,7 +3356,7 @@ nvme_init_fw_download(struct nvme_passthru_cmd *cmd, void *data, * Initializes the passthru command buffer for the Firmware Commit command. */ static inline void -nvme_init_fw_commit(struct nvme_passthru_cmd *cmd, __u8 fs, +nvme_init_fw_commit(struct libnvme_passthru_cmd *cmd, __u8 fs, enum nvme_fw_commit_ca ca, bool bpid) { memset(cmd, 0, sizeof(*cmd)); @@ -3386,7 +3387,7 @@ nvme_init_fw_commit(struct nvme_passthru_cmd *cmd, __u8 fs, * Initializes the passthru command buffer for the Security Send command. */ static inline void -nvme_init_security_send(struct nvme_passthru_cmd *cmd, __u32 nsid, __u8 nssf, +nvme_init_security_send(struct libnvme_passthru_cmd *cmd, __u32 nsid, __u8 nssf, __u16 spsp, __u8 secp, __u32 tl, void *data, __u32 len) { memset(cmd, 0, sizeof(*cmd)); @@ -3425,8 +3426,9 @@ nvme_init_security_send(struct nvme_passthru_cmd *cmd, __u32 nsid, __u8 nssf, * Initializes the passthru command buffer for the Security Receive command. */ static inline void -nvme_init_security_receive(struct nvme_passthru_cmd *cmd, __u32 nsid, __u8 nssf, - __u16 spsp, __u8 secp, __u32 al, void *data, __u32 len) +nvme_init_security_receive(struct libnvme_passthru_cmd *cmd, __u32 nsid, + __u8 nssf, __u16 spsp, __u8 secp, __u32 al, void *data, + __u32 len) { memset(cmd, 0, sizeof(*cmd)); @@ -3464,9 +3466,9 @@ nvme_init_security_receive(struct nvme_passthru_cmd *cmd, __u32 nsid, __u8 nssf, * Initializes the passthru command buffer for the Get LBA Status command. */ static inline void -nvme_init_get_lba_status(struct nvme_passthru_cmd *cmd, __u32 nsid, __u64 slba, - __u32 mndw, enum nvme_lba_status_atype atype, __u16 rl, - struct nvme_lba_status *lbas) +nvme_init_get_lba_status(struct libnvme_passthru_cmd *cmd, __u32 nsid, + __u64 slba, __u32 mndw, enum nvme_lba_status_atype atype, + __u16 rl, struct nvme_lba_status *lbas) { memset(cmd, 0, sizeof(*cmd)); @@ -3498,7 +3500,7 @@ nvme_init_get_lba_status(struct nvme_passthru_cmd *cmd, __u32 nsid, __u64 slba, * Initializes the passthru command buffer for the Directive Send command. */ static inline void -nvme_init_directive_send(struct nvme_passthru_cmd *cmd, __u32 nsid, +nvme_init_directive_send(struct libnvme_passthru_cmd *cmd, __u32 nsid, enum nvme_directive_send_doper doper, enum nvme_directive_dtype dtype, __u16 dspec, void *data, __u32 len) @@ -3535,7 +3537,7 @@ nvme_init_directive_send(struct nvme_passthru_cmd *cmd, __u32 nsid, * (Enable Directive) command. */ static inline void -nvme_init_directive_send_id_endir(struct nvme_passthru_cmd *cmd, __u32 nsid, +nvme_init_directive_send_id_endir(struct libnvme_passthru_cmd *cmd, __u32 nsid, bool endir, enum nvme_directive_dtype dtype, struct nvme_id_directives *id) { @@ -3562,7 +3564,7 @@ nvme_init_directive_send_id_endir(struct nvme_passthru_cmd *cmd, __u32 nsid, */ static inline void nvme_init_directive_send_stream_release_identifier( - struct nvme_passthru_cmd *cmd, + struct libnvme_passthru_cmd *cmd, __u32 nsid, __u16 stream_id) { nvme_init_directive_send(cmd, nsid, @@ -3580,8 +3582,8 @@ nvme_init_directive_send_stream_release_identifier( * Release Resource command. */ static inline void -nvme_init_directive_send_stream_release_resource(struct nvme_passthru_cmd *cmd, - __u32 nsid) +nvme_init_directive_send_stream_release_resource( + struct libnvme_passthru_cmd *cmd, __u32 nsid) { nvme_init_directive_send(cmd, nsid, NVME_DIRECTIVE_SEND_STREAMS_DOPER_RELEASE_RESOURCE, @@ -3603,7 +3605,7 @@ nvme_init_directive_send_stream_release_resource(struct nvme_passthru_cmd *cmd, * Initializes the passthru command buffer for the Directive Receive command. */ static inline void -nvme_init_directive_recv(struct nvme_passthru_cmd *cmd, __u32 nsid, +nvme_init_directive_recv(struct libnvme_passthru_cmd *cmd, __u32 nsid, enum nvme_directive_receive_doper doper, enum nvme_directive_dtype dtype, __u16 dspec, void *data, __u32 len) @@ -3638,7 +3640,7 @@ nvme_init_directive_recv(struct nvme_passthru_cmd *cmd, __u32 nsid, * Parameters command. */ static inline void -nvme_init_directive_recv_identify_parameters(struct nvme_passthru_cmd *cmd, +nvme_init_directive_recv_identify_parameters(struct libnvme_passthru_cmd *cmd, __u32 nsid, struct nvme_id_directives *id) { nvme_init_directive_recv(cmd, nsid, @@ -3657,7 +3659,7 @@ nvme_init_directive_recv_identify_parameters(struct nvme_passthru_cmd *cmd, * Parameters command. */ static inline void -nvme_init_directive_recv_stream_parameters(struct nvme_passthru_cmd *cmd, +nvme_init_directive_recv_stream_parameters(struct libnvme_passthru_cmd *cmd, __u32 nsid, struct nvme_streams_directive_params *parms) { nvme_init_directive_recv(cmd, nsid, @@ -3679,7 +3681,7 @@ nvme_init_directive_recv_stream_parameters(struct nvme_passthru_cmd *cmd, * Return: 0 on success, or error code if arguments are invalid. */ static inline int -nvme_init_directive_recv_stream_status(struct nvme_passthru_cmd *cmd, +nvme_init_directive_recv_stream_status(struct libnvme_passthru_cmd *cmd, __u32 nsid, unsigned int nr_entries, struct nvme_streams_directive_status *id) { @@ -3705,7 +3707,7 @@ nvme_init_directive_recv_stream_status(struct nvme_passthru_cmd *cmd, * Allocate command. */ static inline void -nvme_init_directive_recv_stream_allocate(struct nvme_passthru_cmd *cmd, +nvme_init_directive_recv_stream_allocate(struct libnvme_passthru_cmd *cmd, __u32 nsid, __u16 nsr) { nvme_init_directive_recv(cmd, nsid, @@ -3726,7 +3728,7 @@ nvme_init_directive_recv_stream_allocate(struct nvme_passthru_cmd *cmd, * Initializes the passthru command buffer for the Capacity Management command. */ static inline void -nvme_init_capacity_mgmt(struct nvme_passthru_cmd *cmd, +nvme_init_capacity_mgmt(struct libnvme_passthru_cmd *cmd, __u8 oper, __u16 elid, __u64 cap) { memset(cmd, 0, sizeof(*cmd)); @@ -3758,7 +3760,7 @@ nvme_init_capacity_mgmt(struct nvme_passthru_cmd *cmd, * Initializes the passthru command buffer for the Lockdown command. */ static inline void -nvme_init_lockdown(struct nvme_passthru_cmd *cmd, __u8 scp, __u8 prhbt, +nvme_init_lockdown(struct libnvme_passthru_cmd *cmd, __u8 scp, __u8 prhbt, __u8 ifc, __u8 ofi, __u8 uidx) { memset(cmd, 0, sizeof(*cmd)); @@ -3792,7 +3794,8 @@ nvme_init_lockdown(struct nvme_passthru_cmd *cmd, __u8 scp, __u8 prhbt, * This is an NVMe-over-Fabrics specific command. */ static inline void -nvme_init_set_property(struct nvme_passthru_cmd *cmd, __u32 offset, __u64 value) +nvme_init_set_property(struct libnvme_passthru_cmd *cmd, __u32 offset, + __u64 value) { memset(cmd, 0, sizeof(*cmd)); @@ -3814,7 +3817,7 @@ nvme_init_set_property(struct nvme_passthru_cmd *cmd, __u32 offset, __u64 value) * This is an NVMe-over-Fabrics specific command. */ static inline void -nvme_init_get_property(struct nvme_passthru_cmd *cmd, __u32 offset) +nvme_init_get_property(struct libnvme_passthru_cmd *cmd, __u32 offset) { memset(cmd, 0, sizeof(*cmd)); @@ -3840,7 +3843,7 @@ nvme_init_get_property(struct nvme_passthru_cmd *cmd, __u32 offset) * Initializes the passthru command buffer for the Sanitize NVM command. */ static inline void -nvme_init_sanitize_nvm(struct nvme_passthru_cmd *cmd, +nvme_init_sanitize_nvm(struct libnvme_passthru_cmd *cmd, enum nvme_sanitize_sanact sanact, bool ause, __u8 owpass, bool oipbp, bool ndas, bool emvs, __u32 ovrpat) { @@ -3879,7 +3882,7 @@ nvme_init_sanitize_nvm(struct nvme_passthru_cmd *cmd, * Initializes the passthru command buffer for the Sanitize namespace command. */ static inline void -nvme_init_sanitize_ns(struct nvme_passthru_cmd *cmd, +nvme_init_sanitize_ns(struct libnvme_passthru_cmd *cmd, enum nvme_sanitize_sanact sanact, bool ause, bool emvs) { memset(cmd, 0, sizeof(*cmd)); @@ -3906,7 +3909,7 @@ nvme_init_sanitize_ns(struct nvme_passthru_cmd *cmd, * Initializes the passthru command buffer for the Device Self-test command. */ static inline void -nvme_init_dev_self_test(struct nvme_passthru_cmd *cmd, __u32 nsid, +nvme_init_dev_self_test(struct libnvme_passthru_cmd *cmd, __u32 nsid, enum nvme_dst_stc stc) { memset(cmd, 0, sizeof(*cmd)); @@ -3931,7 +3934,7 @@ nvme_init_dev_self_test(struct nvme_passthru_cmd *cmd, __u32 nsid, * Management command. */ static inline void -nvme_init_virtual_mgmt(struct nvme_passthru_cmd *cmd, +nvme_init_virtual_mgmt(struct libnvme_passthru_cmd *cmd, enum nvme_virt_mgmt_act act, enum nvme_virt_mgmt_rt rt, __u16 cntlid, __u16 nr) { @@ -3962,7 +3965,7 @@ nvme_init_virtual_mgmt(struct nvme_passthru_cmd *cmd, * Initializes the passthru command buffer for the Flush command. */ static inline void -nvme_init_flush(struct nvme_passthru_cmd *cmd, __u32 nsid) +nvme_init_flush(struct libnvme_passthru_cmd *cmd, __u32 nsid) { memset(cmd, 0, sizeof(*cmd)); cmd->opcode = nvme_cmd_flush; @@ -3982,7 +3985,7 @@ nvme_init_flush(struct nvme_passthru_cmd *cmd, __u32 nsid) * @len: Length of provided user buffer to hold the log data in bytes */ static inline void -nvme_init_dsm(struct nvme_passthru_cmd *cmd, +nvme_init_dsm(struct libnvme_passthru_cmd *cmd, __u32 nsid, __u16 nr, __u8 idr, __u8 idw, __u8 ad, void *data, __u32 len) { @@ -4020,7 +4023,7 @@ nvme_init_dsm(struct nvme_passthru_cmd *cmd, * the command-specific init function (like nvme_init_zns_append). */ static inline int -nvme_init_var_size_tags(struct nvme_passthru_cmd *cmd, +nvme_init_var_size_tags(struct libnvme_passthru_cmd *cmd, __u8 pif, __u8 sts, __u64 reftag, __u64 storage_tag) { __u32 cdw2 = 0, cdw3 = 0, cdw14 = 0; @@ -4097,7 +4100,7 @@ nvme_init_var_size_tags(struct nvme_passthru_cmd *cmd, * @lbatm: Logical block application tag mask */ static inline void -nvme_init_app_tag(struct nvme_passthru_cmd *cmd, +nvme_init_app_tag(struct libnvme_passthru_cmd *cmd, __u16 lbat, __u16 lbatm) { cmd->cdw15 = NVME_FIELD_ENCODE(lbat, @@ -4125,7 +4128,8 @@ nvme_init_app_tag(struct nvme_passthru_cmd *cmd, * that function is checked for error. */ static inline void -nvme_init_io(struct nvme_passthru_cmd *cmd, __u8 opcode, __u32 nsid, __u64 slba, +nvme_init_io(struct libnvme_passthru_cmd *cmd, __u8 opcode, + __u32 nsid, __u64 slba, void *data, __u32 data_len, void *metadata, __u32 metadata_len) { memset(cmd, 0, sizeof(*cmd)); @@ -4165,7 +4169,8 @@ nvme_init_io(struct nvme_passthru_cmd *cmd, __u8 opcode, __u32 nsid, __u64 slba, * the parameters are used for a generic nvme_init_io wrapper. */ static inline void -nvme_init_read(struct nvme_passthru_cmd *cmd, __u32 nsid, __u64 slba, +nvme_init_read(struct libnvme_passthru_cmd *cmd, + __u32 nsid, __u64 slba, __u16 nlb, __u16 control, __u8 dsm, __u16 cev, void *data, __u32 data_len, void *metadata, __u32 metadata_len) { @@ -4204,7 +4209,8 @@ nvme_init_read(struct nvme_passthru_cmd *cmd, __u32 nsid, __u64 slba, * Initializes the passthru command buffer for the Write command. */ static inline void -nvme_init_write(struct nvme_passthru_cmd *cmd, __u32 nsid, __u64 slba, +nvme_init_write(struct libnvme_passthru_cmd *cmd, + __u32 nsid, __u64 slba, __u16 nlb, __u16 control, __u16 dspec, __u8 dsm, __u8 cev, void *data, __u32 data_len, void *metadata, __u32 metadata_len) { @@ -4242,9 +4248,10 @@ nvme_init_write(struct nvme_passthru_cmd *cmd, __u32 nsid, __u64 slba, * Initializes the passthru command buffer for the Compare command. */ static inline void -nvme_init_compare(struct nvme_passthru_cmd *cmd, __u32 nsid, __u64 slba, - __u16 nlb, __u16 control, __u8 cev, void *data, __u32 data_len, - void *metadata, __u32 metadata_len) +nvme_init_compare(struct libnvme_passthru_cmd *cmd, + __u32 nsid, __u64 slba, + __u16 nlb, __u16 control, __u8 cev, + void *data, __u32 data_len, void *metadata, __u32 metadata_len) { nvme_init_io(cmd, nvme_cmd_compare, nsid, slba, data, data_len, metadata, metadata_len); @@ -4276,7 +4283,8 @@ nvme_init_compare(struct nvme_passthru_cmd *cmd, __u32 nsid, __u64 slba, * Note: Write Zeroes command does not transfer data or metadata. */ static inline void -nvme_init_write_zeros(struct nvme_passthru_cmd *cmd, __u32 nsid, __u64 slba, +nvme_init_write_zeros(struct libnvme_passthru_cmd *cmd, + __u32 nsid, __u64 slba, __u16 nlb, __u16 control, __u16 dspec, __u8 dsm, __u8 cev) { nvme_init_io(cmd, nvme_cmd_write_zeroes, nsid, slba, NULL, 0, NULL, 0); @@ -4311,8 +4319,8 @@ nvme_init_write_zeros(struct nvme_passthru_cmd *cmd, __u32 nsid, __u64 slba, * Note: This command transfers no data or metadata. */ static inline void -nvme_init_write_uncorrectable(struct nvme_passthru_cmd *cmd, __u32 nsid, - __u64 slba, __u16 nlb, __u16 control, __u16 dspec) +nvme_init_write_uncorrectable(struct libnvme_passthru_cmd *cmd, + __u32 nsid, __u64 slba, __u16 nlb, __u16 control, __u16 dspec) { nvme_init_io(cmd, nvme_cmd_write_uncor, nsid, slba, NULL, 0, NULL, 0); cmd->cdw12 = NVME_FIELD_ENCODE(nlb, @@ -4344,9 +4352,10 @@ nvme_init_write_uncorrectable(struct nvme_passthru_cmd *cmd, __u32 nsid, * the verification but not back to the host. */ static inline void -nvme_init_verify(struct nvme_passthru_cmd *cmd, __u32 nsid, __u64 slba, - __u16 nlb, __u16 control, __u8 cev, void *data, __u32 data_len, - void *metadata, __u32 metadata_len) +nvme_init_verify(struct libnvme_passthru_cmd *cmd, + __u32 nsid, __u64 slba, + __u16 nlb, __u16 control, __u8 cev, + void *data, __u32 data_len, void *metadata, __u32 metadata_len) { nvme_init_io(cmd, nvme_cmd_verify, nsid, slba, data, data_len, metadata, metadata_len); @@ -4384,7 +4393,7 @@ nvme_init_verify(struct nvme_passthru_cmd *cmd, __u32 nsid, __u64 slba, * the data length and calling the generic I/O initializer. */ static inline void -nvme_init_copy(struct nvme_passthru_cmd *cmd, __u32 nsid, __u64 sdlba, +nvme_init_copy(struct libnvme_passthru_cmd *cmd, __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, void *cpydsc) @@ -4463,7 +4472,7 @@ nvme_init_copy(struct nvme_passthru_cmd *cmd, __u32 nsid, __u64 sdlba, * Initializes the passthru command buffer for the Reservation Acquire command. */ static inline void -nvme_init_resv_acquire(struct nvme_passthru_cmd *cmd, __u32 nsid, +nvme_init_resv_acquire(struct libnvme_passthru_cmd *cmd, __u32 nsid, enum nvme_resv_racqa racqa, bool iekey, bool disnsrs, enum nvme_resv_rtype rtype, __u64 crkey, __u64 prkey, __le64 *payload) @@ -4508,7 +4517,7 @@ nvme_init_resv_acquire(struct nvme_passthru_cmd *cmd, __u32 nsid, * Initializes the passthru command buffer for the Reservation Register command. */ static inline void -nvme_init_resv_register(struct nvme_passthru_cmd *cmd, __u32 nsid, +nvme_init_resv_register(struct libnvme_passthru_cmd *cmd, __u32 nsid, enum nvme_resv_rrega rrega, bool iekey, bool disnsrs, enum nvme_resv_cptpl cptpl, __u64 crkey, __u64 nrkey, __le64 *payload) @@ -4551,7 +4560,7 @@ nvme_init_resv_register(struct nvme_passthru_cmd *cmd, __u32 nsid, * Initializes the passthru command buffer for the Reservation Release command. */ static inline void -nvme_init_resv_release(struct nvme_passthru_cmd *cmd, __u32 nsid, +nvme_init_resv_release(struct libnvme_passthru_cmd *cmd, __u32 nsid, enum nvme_resv_rrela rrela, bool iekey, bool disnsrs, enum nvme_resv_rtype rtype, __u64 crkey, __le64 *payload) { @@ -4591,7 +4600,7 @@ nvme_init_resv_release(struct nvme_passthru_cmd *cmd, __u32 nsid, * Initializes the passthru command buffer for the Reservation Report command. */ static inline void -nvme_init_resv_report(struct nvme_passthru_cmd *cmd, __u32 nsid, +nvme_init_resv_report(struct libnvme_passthru_cmd *cmd, __u32 nsid, bool eds, bool disnsrs, struct nvme_resv_status *report, __u32 len) { @@ -4624,7 +4633,7 @@ nvme_init_resv_report(struct nvme_passthru_cmd *cmd, __u32 nsid, * Receive command. */ static inline void -nvme_init_io_mgmt_recv(struct nvme_passthru_cmd *cmd, __u32 nsid, +nvme_init_io_mgmt_recv(struct libnvme_passthru_cmd *cmd, __u32 nsid, __u8 mo, __u16 mos, void *data, __u32 len) { memset(cmd, 0, sizeof(*cmd)); @@ -4654,7 +4663,7 @@ nvme_init_io_mgmt_recv(struct nvme_passthru_cmd *cmd, __u32 nsid, * Reclaim Unit Handle Status command. */ static inline void -nvme_init_fdp_reclaim_unit_handle_status(struct nvme_passthru_cmd *cmd, +nvme_init_fdp_reclaim_unit_handle_status(struct libnvme_passthru_cmd *cmd, __u32 nsid, void *data, __u32 len) { nvme_init_io_mgmt_recv(cmd, nsid, NVME_IO_MGMT_RECV_RUH_STATUS, 0, @@ -4674,7 +4683,7 @@ nvme_init_fdp_reclaim_unit_handle_status(struct nvme_passthru_cmd *cmd, * Initializes the passthru command buffer for the I/O Management Send command. */ static inline void -nvme_init_io_mgmt_send(struct nvme_passthru_cmd *cmd, __u32 nsid, +nvme_init_io_mgmt_send(struct libnvme_passthru_cmd *cmd, __u32 nsid, __u8 mo, __u16 mos, void *data, __u32 len) { memset(cmd, 0, sizeof(*cmd)); @@ -4703,7 +4712,7 @@ nvme_init_io_mgmt_send(struct nvme_passthru_cmd *cmd, __u32 nsid, * Reclaim Unit Handle Update command. */ static inline void -nvme_init_fdp_reclaim_unit_handle_update(struct nvme_passthru_cmd *cmd, +nvme_init_fdp_reclaim_unit_handle_update(struct libnvme_passthru_cmd *cmd, __u32 nsid, void *pids, unsigned int npids) { __u16 mos = npids - 1; /* MOS = NPI - 1 */ @@ -4729,7 +4738,7 @@ nvme_init_fdp_reclaim_unit_handle_update(struct nvme_passthru_cmd *cmd, * Initializes the passthru command buffer for the ZNS Management Send command. */ static inline void -nvme_init_zns_mgmt_send(struct nvme_passthru_cmd *cmd, __u32 nsid, +nvme_init_zns_mgmt_send(struct libnvme_passthru_cmd *cmd, __u32 nsid, __u64 slba, enum nvme_zns_send_action zsa, bool selall, __u8 zsaso, __u8 zm, void *data, __u32 len) { @@ -4771,7 +4780,7 @@ nvme_init_zns_mgmt_send(struct nvme_passthru_cmd *cmd, __u32 nsid, * Receive command. */ static inline void -nvme_init_zns_mgmt_recv(struct nvme_passthru_cmd *cmd, __u32 nsid, +nvme_init_zns_mgmt_recv(struct libnvme_passthru_cmd *cmd, __u32 nsid, __u64 slba, enum nvme_zns_recv_action zra, __u16 zras, bool zraspf, void *data, __u32 len) { @@ -4811,7 +4820,7 @@ nvme_init_zns_mgmt_recv(struct nvme_passthru_cmd *cmd, __u32 nsid, * Report Zones command. */ static inline void -nvme_init_zns_report_zones(struct nvme_passthru_cmd *cmd, __u32 nsid, +nvme_init_zns_report_zones(struct libnvme_passthru_cmd *cmd, __u32 nsid, __u64 slba, enum nvme_zns_report_options opts, bool extended, bool partial, void *data, __u32 len) @@ -4841,7 +4850,7 @@ nvme_init_zns_report_zones(struct nvme_passthru_cmd *cmd, __u32 nsid, * Initializes the passthru command buffer for the ZNS Append command. */ static inline void -nvme_init_zns_append(struct nvme_passthru_cmd *cmd, __u32 nsid, +nvme_init_zns_append(struct libnvme_passthru_cmd *cmd, __u32 nsid, __u64 zslba, __u16 nlb, __u16 control, __u16 cev, __u16 dspec, void *data, __u32 data_len, void *metadata, __u32 metadata_len) { @@ -4886,7 +4895,7 @@ nvme_init_zns_append(struct nvme_passthru_cmd *cmd, __u32 nsid, * Management Send command. */ static inline void -nvme_init_dim_send(struct nvme_passthru_cmd *cmd, +nvme_init_dim_send(struct libnvme_passthru_cmd *cmd, __u8 tas, void *data, __u32 len) { memset(cmd, 0, sizeof(*cmd)); @@ -4916,7 +4925,7 @@ nvme_init_dim_send(struct nvme_passthru_cmd *cmd, * submission function must handle. */ static inline void -nvme_init_lm_cdq_create(struct nvme_passthru_cmd *cmd, +nvme_init_lm_cdq_create(struct libnvme_passthru_cmd *cmd, __u16 mos, __u16 cntlid, __u32 cdqsize, void *data) { __u16 cqs; @@ -4958,7 +4967,7 @@ nvme_init_lm_cdq_create(struct nvme_passthru_cmd *cmd, * command. */ static inline void -nvme_init_lm_cdq_delete(struct nvme_passthru_cmd *cmd, +nvme_init_lm_cdq_delete(struct libnvme_passthru_cmd *cmd, __u16 mos, __u16 cdqid) { memset(cmd, 0, sizeof(*cmd)); @@ -4988,7 +4997,7 @@ nvme_init_lm_cdq_delete(struct nvme_passthru_cmd *cmd, * Initializes the passthru command buffer for the Track Send command. */ static inline void -nvme_init_lm_track_send(struct nvme_passthru_cmd *cmd, +nvme_init_lm_track_send(struct libnvme_passthru_cmd *cmd, __u8 sel, __u16 mos, __u16 cdqid) { @@ -5028,7 +5037,7 @@ nvme_init_lm_track_send(struct nvme_passthru_cmd *cmd, * Initializes the passthru command buffer for the Migration Send command. */ static inline void -nvme_init_lm_migration_send(struct nvme_passthru_cmd *cmd, +nvme_init_lm_migration_send(struct libnvme_passthru_cmd *cmd, __u16 sel, __u16 mos, __u16 cntlid, __u8 stype, bool dudmq, __u8 csvi, __u16 csuuidi, __u64 cso, __u8 uidx, void *data, __u32 len) @@ -5104,7 +5113,7 @@ nvme_init_lm_migration_send(struct nvme_passthru_cmd *cmd, * Initializes the passthru command buffer for the Migration Receive command. */ static inline void -nvme_init_lm_migration_recv(struct nvme_passthru_cmd *cmd, +nvme_init_lm_migration_recv(struct libnvme_passthru_cmd *cmd, __u64 offset, __u16 mos, __u16 cntlid, __u16 csuuidi, __u8 sel, __u8 uidx, __u8 csuidxp, void *data, __u32 len) { @@ -5157,7 +5166,7 @@ nvme_init_lm_migration_recv(struct nvme_passthru_cmd *cmd, * FID value %NVME_FEAT_FID_CTRL_DATA_QUEUE. */ static inline void -nvme_init_lm_set_features_ctrl_data_queue(struct nvme_passthru_cmd *cmd, +nvme_init_lm_set_features_ctrl_data_queue(struct libnvme_passthru_cmd *cmd, __u16 cdqid, __u32 hp, __u32 tpt, bool etpt) { nvme_init_set_features(cmd, NVME_FEAT_FID_CTRL_DATA_QUEUE, false); @@ -5182,7 +5191,7 @@ nvme_init_lm_set_features_ctrl_data_queue(struct nvme_passthru_cmd *cmd, * FID value %NVME_FEAT_FID_CTRL_DATA_QUEUE. */ static inline void -nvme_init_lm_get_features_ctrl_data_queue(struct nvme_passthru_cmd *cmd, +nvme_init_lm_get_features_ctrl_data_queue(struct libnvme_passthru_cmd *cmd, enum nvme_get_features_sel sel, __u16 cdqid, struct nvme_lm_ctrl_data_queue_fid_data *qfd) { @@ -5200,7 +5209,7 @@ nvme_init_lm_get_features_ctrl_data_queue(struct nvme_passthru_cmd *cmd, * Initializes the passthru command flags */ static inline void -nvme_init_mi_cmd_flags(struct nvme_passthru_cmd *cmd, bool ish) +nvme_init_mi_cmd_flags(struct libnvme_passthru_cmd *cmd, bool ish) { cmd->flags = NVME_FIELD_ENCODE(ish, NVME_MI_ADMIN_CFLAGS_ISH_SHIFT, @@ -5373,7 +5382,7 @@ nvme_init_copy_range_f3(struct nvme_copy_range_f3 *copy, __u32 *snsids, } /** - * nvme_get_log() - Get log page data + * libnvme_get_log() - Get log page data * @hdl: Transport handle * @cmd: Passthru command * @rae: Retain asynchronous events @@ -5382,12 +5391,12 @@ nvme_init_copy_range_f3(struct nvme_copy_range_f3 *copy, __u32 *snsids, * 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(struct nvme_transport_handle *hdl, - struct nvme_passthru_cmd *cmd, bool rae, +int libnvme_get_log(struct libnvme_transport_handle *hdl, + struct libnvme_passthru_cmd *cmd, bool rae, __u32 xfer_len); /** - * nvme_set_etdas() - Set the Extended Telemetry Data Area 4 Supported bit + * libnvme_set_etdas() - Set the Extended Telemetry Data Area 4 Supported bit * @hdl: Transport handle * @changed: boolean to indicate whether or not the host * behavior support feature had been changed @@ -5395,10 +5404,11 @@ int nvme_get_log(struct nvme_transport_handle *hdl, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_set_etdas(struct nvme_transport_handle *hdl, bool *changed); +int libnvme_set_etdas(struct libnvme_transport_handle *hdl, bool *changed); /** - * nvme_clear_etdas() - Clear the Extended Telemetry Data Area 4 Supported bit + * libnvme_clear_etdas() - Clear the Extended Telemetry Data Area 4 + * Supported bit * @hdl: Transport handle * @changed: boolean to indicate whether or not the host * behavior support feature had been changed @@ -5406,21 +5416,21 @@ int nvme_set_etdas(struct nvme_transport_handle *hdl, bool *changed); * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_clear_etdas(struct nvme_transport_handle *hdl, bool *changed); +int libnvme_clear_etdas(struct libnvme_transport_handle *hdl, bool *changed); /** - * nvme_get_uuid_list - Returns the uuid list (if supported) + * libnvme_get_uuid_list - Returns the uuid list (if supported) * @hdl: Transport handle * @uuid_list: UUID list returned by identify UUID * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_get_uuid_list(struct nvme_transport_handle *hdl, +int libnvme_get_uuid_list(struct libnvme_transport_handle *hdl, struct nvme_id_uuid_list *uuid_list); /** - * nvme_get_telemetry_max() - Get telemetry limits + * libnvme_get_telemetry_max() - Get telemetry limits * @hdl: Transport handle * @da: On success return max supported data area * @max_data_tx: On success set to max transfer chunk supported by @@ -5429,11 +5439,11 @@ int nvme_get_uuid_list(struct nvme_transport_handle *hdl, * 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(struct nvme_transport_handle *hdl, +int libnvme_get_telemetry_max(struct libnvme_transport_handle *hdl, enum nvme_telemetry_da *da, size_t *max_data_tx); /** - * nvme_get_telemetry_log() - Get specified telemetry log + * libnvme_get_telemetry_log() - Get specified telemetry log * @hdl: Transport handle * @create: Generate new host initated telemetry capture * @ctrl: Get controller Initiated log @@ -5449,13 +5459,13 @@ int nvme_get_telemetry_max(struct nvme_transport_handle *hdl, * 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(struct nvme_transport_handle *hdl, bool create, +int libnvme_get_telemetry_log(struct libnvme_transport_handle *hdl, 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 + * libnvme_get_ctrl_telemetry() - Get controller telemetry log * @hdl: Transport handle * @rae: Retain asynchronous events * @log: On success, set to the value of the allocated and retrieved log. @@ -5468,12 +5478,12 @@ int nvme_get_telemetry_log(struct nvme_transport_handle *hdl, bool create, * 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(struct nvme_transport_handle *hdl, bool rae, +int libnvme_get_ctrl_telemetry(struct libnvme_transport_handle *hdl, bool rae, struct nvme_telemetry_log **log, enum nvme_telemetry_da da, size_t *size); /** - * nvme_get_host_telemetry() - Get host telemetry log + * libnvme_get_host_telemetry() - Get host telemetry log * @hdl: Transport 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 @@ -5485,12 +5495,12 @@ int nvme_get_ctrl_telemetry(struct nvme_transport_handle *hdl, 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. */ -int nvme_get_host_telemetry(struct nvme_transport_handle *hdl, +int libnvme_get_host_telemetry(struct libnvme_transport_handle *hdl, struct nvme_telemetry_log **log, enum nvme_telemetry_da da, size_t *size); /** - * nvme_get_new_host_telemetry() - Get new host telemetry log + * libnvme_get_new_host_telemetry() - Get new host telemetry log * @hdl: Transport 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 @@ -5502,22 +5512,23 @@ int nvme_get_host_telemetry(struct nvme_transport_handle *hdl, * 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(struct nvme_transport_handle *hdl, +int libnvme_get_new_host_telemetry(struct libnvme_transport_handle *hdl, struct nvme_telemetry_log **log, enum nvme_telemetry_da da, size_t *size); /** - * nvme_get_ana_log_len_from_id_ctrl() - Retrieve maximum possible ANA log size + * libnvme_get_ana_log_len_from_id_ctrl() - Retrieve maximum possible + * ANA log size * @id_ctrl: Controller identify data * @rgo: If true, return maximum log page size without NSIDs * * Return: A byte limit on the size of the controller's ANA log page */ -size_t nvme_get_ana_log_len_from_id_ctrl(const struct nvme_id_ctrl *id_ctrl, +size_t libnvme_get_ana_log_len_from_id_ctrl(const struct nvme_id_ctrl *id_ctrl, bool rgo); /** - * nvme_get_ana_log_atomic() - Retrieve Asymmetric Namespace Access + * libnvme_get_ana_log_atomic() - Retrieve Asymmetric Namespace Access * log page atomically * @hdl: Transport handle * @rae: Whether to retain asynchronous events @@ -5538,21 +5549,23 @@ size_t nvme_get_ana_log_len_from_id_ctrl(const struct nvme_id_ctrl *id_ctrl, * Sets errno = ENOSPC if the full log page does not fit in the provided buffer. */ int -nvme_get_ana_log_atomic(struct nvme_transport_handle *hdl, bool rae, bool rgo, - struct nvme_ana_log *log, __u32 *len, unsigned int retries); +libnvme_get_ana_log_atomic(struct libnvme_transport_handle *hdl, bool rae, + bool rgo, struct nvme_ana_log *log, __u32 *len, + unsigned int retries); /** - * nvme_get_ana_log_len() - Retrieve size of the current ANA log + * libnvme_get_ana_log_len() - Retrieve size of the current ANA log * @hdl: Transport handle * @analen: Pointer to where the length will be set on success * * 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(struct nvme_transport_handle *hdl, size_t *analen); +int libnvme_get_ana_log_len(struct libnvme_transport_handle *hdl, + size_t *analen); /** - * nvme_get_logical_block_size() - Retrieve block size + * libnvme_get_logical_block_size() - Retrieve block size * @hdl: Transport handle * @nsid: Namespace id * @blksize: Pointer to where the block size will be set on success @@ -5560,11 +5573,11 @@ int nvme_get_ana_log_len(struct nvme_transport_handle *hdl, size_t *analen); * 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(struct nvme_transport_handle *hdl, __u32 nsid, - int *blksize); +int libnvme_get_logical_block_size(struct libnvme_transport_handle *hdl, + __u32 nsid, int *blksize); /** - * nvme_get_lba_status_log() - Retrieve the LBA Status log page + * libnvme_get_lba_status_log() - Retrieve the LBA Status log page * @hdl: Transport handle * @rae: Retain asynchronous events * @log: On success, set to the value of the allocated and retrieved log. @@ -5572,11 +5585,11 @@ int nvme_get_logical_block_size(struct nvme_transport_handle *hdl, __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_log(struct nvme_transport_handle *hdl, bool rae, +int libnvme_get_lba_status_log(struct libnvme_transport_handle *hdl, bool rae, struct nvme_lba_status_log **log); /** - * nvme_get_feature_length() - Retrieve the command payload length for a + * libnvme_get_feature_length() - Retrieve the command payload length for a * specific feature identifier * @fid: Feature identifier, see &enum nvme_features_id. * @cdw11: The cdw11 value may affect the transfer (only known fid is @@ -5589,11 +5602,11 @@ int nvme_get_lba_status_log(struct nvme_transport_handle *hdl, bool rae, * Return: 0 on success, -1 with errno set to EINVAL if the function did not * recognize &fid. */ -int nvme_get_feature_length(int fid, __u32 cdw11, enum nvme_data_tfr dir, +int libnvme_get_feature_length(int fid, __u32 cdw11, enum nvme_data_tfr dir, __u32 *len); /** - * nvme_get_directive_receive_length() - Get directive receive length + * libnvme_get_directive_receive_length() - Get directive receive length * @dtype: Directive type, see &enum nvme_directive_dtype * @doper: Directive receive operation, see &enum nvme_directive_receive_doper * @len: On success, set to this directives payload length in bytes. @@ -5601,5 +5614,5 @@ int nvme_get_feature_length(int fid, __u32 cdw11, enum nvme_data_tfr dir, * Return: 0 on success, -1 with errno set to EINVAL if the function did not * recognize &dtype or &doper. */ -int nvme_get_directive_receive_length(enum nvme_directive_dtype dtype, +int libnvme_get_directive_receive_length(enum nvme_directive_dtype dtype, enum nvme_directive_receive_doper doper, __u32 *len); diff --git a/libnvme/src/nvme/fabrics.c b/libnvme/src/nvme/fabrics.c index a856f6a18f..7fd73306dd 100644 --- a/libnvme/src/nvme/fabrics.c +++ b/libnvme/src/nvme/fabrics.c @@ -187,13 +187,13 @@ __public const char *nvmf_cms_str(__u8 cm) return arg_str(cms, ARRAY_SIZE(cms), cm); } -__public int nvmf_context_create(struct nvme_global_ctx *ctx, +__public int nvmf_context_create(struct libnvme_global_ctx *ctx, bool (*decide_retry)(struct nvmf_context *fctx, int err, void *user_data), void (*connected)(struct nvmf_context *fctx, - struct nvme_ctrl *c, void *user_data), + struct libnvme_ctrl *c, void *user_data), void (*already_connected)(struct nvmf_context *fctx, - struct nvme_host *host, const char *subsysnqn, + struct libnvme_host *host, const char *subsysnqn, const char *transport, const char *traddr, const char *trsvcid, void *user_data), void *user_data, struct nvmf_context **fctxp) @@ -252,7 +252,7 @@ __public int nvmf_context_set_discovery_defaults(struct nvmf_context *fctx, } __public int nvmf_context_set_fabrics_config(struct nvmf_context *fctx, - struct nvme_fabrics_config *cfg) + struct libnvme_fabrics_config *cfg) { fctx->cfg = cfg; @@ -319,12 +319,12 @@ __public int nvmf_context_set_crypto(struct nvmf_context *fctx, _cleanup_free_ char *encoded_key = NULL; int key_len = 32; - err = nvme_create_raw_secret(fctx->ctx, tls_key, + err = libnvme_create_raw_secret(fctx->ctx, tls_key, key_len, &raw_secret); if (err) return err; - err = nvme_export_tls_key(fctx->ctx, raw_secret, + err = libnvme_export_tls_key(fctx->ctx, raw_secret, key_len, &encoded_key); if (err) return err; @@ -358,7 +358,7 @@ __public int nvmf_context_set_device(struct nvmf_context *fctx, const char *devi * Not all of these options may actually be supported, * but we retain the old behavior of passing all that might be. */ -static const struct nvme_fabric_options default_supported_options = { +static const struct libnvme_fabric_options default_supported_options = { .ctrl_loss_tmo = true, .data_digest = true, .disable_sqflow = true, @@ -385,10 +385,10 @@ static const struct nvme_fabric_options default_supported_options = { #define MERGE_CFG_OPTION(c, n, o, d) \ if ((c)->o == d) (c)->o = (n)->o -static struct nvme_fabrics_config *merge_config(nvme_ctrl_t c, - const struct nvme_fabrics_config *cfg) +static struct libnvme_fabrics_config *merge_config(libnvme_ctrl_t c, + const struct libnvme_fabrics_config *cfg) { - struct nvme_fabrics_config *ctrl_cfg = nvme_ctrl_get_config(c); + struct libnvme_fabrics_config *ctrl_cfg = libnvme_ctrl_get_config(c); MERGE_CFG_OPTION(ctrl_cfg, cfg, nr_io_queues, 0); MERGE_CFG_OPTION(ctrl_cfg, cfg, nr_write_queues, 0); @@ -414,9 +414,9 @@ static struct nvme_fabrics_config *merge_config(nvme_ctrl_t c, #define UPDATE_CFG_OPTION(c, n, o, d) \ if ((n)->o != d) (c)->o = (n)->o -__public void nvmf_update_config(nvme_ctrl_t c, const struct nvme_fabrics_config *cfg) +__public void nvmf_update_config(libnvme_ctrl_t c, const struct libnvme_fabrics_config *cfg) { - struct nvme_fabrics_config *ctrl_cfg = nvme_ctrl_get_config(c); + struct libnvme_fabrics_config *ctrl_cfg = libnvme_ctrl_get_config(c); UPDATE_CFG_OPTION(ctrl_cfg, cfg, nr_io_queues, 0); UPDATE_CFG_OPTION(ctrl_cfg, cfg, nr_write_queues, 0); @@ -513,7 +513,7 @@ static int __add_argument(char **argstr, const char *tok, const char *arg) return 0; } -static int __nvmf_supported_options(struct nvme_global_ctx *ctx); +static int __nvmf_supported_options(struct libnvme_global_ctx *ctx); #define nvmf_check_option(ctx, tok) \ ({ \ !__nvmf_supported_options(ctx) && ctx->options->tok; \ @@ -527,7 +527,7 @@ static int __nvmf_supported_options(struct nvme_global_ctx *ctx); stringify(tok), \ arg); \ } else { \ - nvme_msg(ctx, LOG_DEBUG, \ + libnvme_msg(ctx, LOG_DEBUG, \ "option \"%s\" ignored\n", \ stringify(tok)); \ ret = 0; \ @@ -544,7 +544,7 @@ static int __nvmf_supported_options(struct nvme_global_ctx *ctx); arg, \ allow_zero); \ } else { \ - nvme_msg(ctx, LOG_DEBUG, \ + libnvme_msg(ctx, LOG_DEBUG, \ "option \"%s\" ignored\n", \ stringify(tok)); \ ret = 0; \ @@ -561,7 +561,7 @@ static int __nvmf_supported_options(struct nvme_global_ctx *ctx); arg, \ allow_zero); \ } else { \ - nvme_msg(ctx, LOG_DEBUG, \ + libnvme_msg(ctx, LOG_DEBUG, \ "option \"%s\" ignored\n", \ stringify(tok)); \ ret = 0; \ @@ -577,7 +577,7 @@ static int __nvmf_supported_options(struct nvme_global_ctx *ctx); stringify(tok), \ arg); \ } else { \ - nvme_msg(ctx, LOG_DEBUG, \ + libnvme_msg(ctx, LOG_DEBUG, \ "option \"%s\" ignored\n", \ stringify(tok)); \ ret = 0; \ @@ -593,7 +593,7 @@ static int __nvmf_supported_options(struct nvme_global_ctx *ctx); stringify(tok), \ arg); \ } else { \ - nvme_msg(ctx, LOG_NOTICE, \ + libnvme_msg(ctx, LOG_NOTICE, \ "option \"%s\" ignored\n", \ stringify(tok)); \ ret = 0; \ @@ -618,7 +618,7 @@ static int inet4_pton(const char *src, uint16_t port, return 0; } -static int inet6_pton(struct nvme_global_ctx *ctx, const char *src, uint16_t port, +static int inet6_pton(struct libnvme_global_ctx *ctx, const char *src, uint16_t port, struct sockaddr_storage *addr) { struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)addr; @@ -630,7 +630,7 @@ static int inet6_pton(struct nvme_global_ctx *ctx, const char *src, uint16_t por _cleanup_free_ char *tmp = strdup(src); if (!tmp) { - nvme_msg(ctx, LOG_ERR, "cannot copy: %s\n", src); + libnvme_msg(ctx, LOG_ERR, "cannot copy: %s\n", src); return -ENOMEM; } @@ -646,7 +646,7 @@ static int inet6_pton(struct nvme_global_ctx *ctx, const char *src, uint16_t por if (IN6_IS_ADDR_LINKLOCAL(&addr6->sin6_addr) && scope) { addr6->sin6_scope_id = if_nametoindex(scope); if (addr6->sin6_scope_id == 0) { - nvme_msg(ctx, LOG_ERR, + libnvme_msg(ctx, LOG_ERR, "can't find iface index for: %s (%m)\n", scope); return -EINVAL; } @@ -667,7 +667,7 @@ static int inet6_pton(struct nvme_global_ctx *ctx, const char *src, uint16_t por * * Return 0 on success, errno otherwise. */ -static int inet_pton_with_scope(struct nvme_global_ctx *ctx, int af, +static int inet_pton_with_scope(struct libnvme_global_ctx *ctx, int af, const char *src, const char * trsvcid, struct sockaddr_storage *addr) { @@ -678,7 +678,7 @@ static int inet_pton_with_scope(struct nvme_global_ctx *ctx, int af, unsigned long long tmp = strtoull(trsvcid, NULL, 0); port = (uint16_t)tmp; if (tmp != port) { - nvme_msg(ctx, LOG_ERR, "trsvcid out of range: %s\n", + libnvme_msg(ctx, LOG_ERR, "trsvcid out of range: %s\n", trsvcid); return -ERANGE; } @@ -699,13 +699,13 @@ static int inet_pton_with_scope(struct nvme_global_ctx *ctx, int af, ret = inet6_pton(ctx, src, port, addr); break; default: - nvme_msg(ctx, LOG_ERR, "unexpected address family %d\n", af); + libnvme_msg(ctx, LOG_ERR, "unexpected address family %d\n", af); } return ret; } -static bool traddr_is_hostname(struct nvme_global_ctx *ctx, nvme_ctrl_t c) +static bool traddr_is_hostname(struct libnvme_global_ctx *ctx, libnvme_ctrl_t c) { struct sockaddr_storage addr; @@ -718,65 +718,65 @@ static bool traddr_is_hostname(struct nvme_global_ctx *ctx, nvme_ctrl_t c) return true; } -static int build_options(nvme_host_t h, nvme_ctrl_t c, char **argstr) +static int build_options(libnvme_host_t h, libnvme_ctrl_t c, char **argstr) { - struct nvme_fabrics_config *cfg = nvme_ctrl_get_config(c); - const char *transport = nvme_ctrl_get_transport(c); + struct libnvme_fabrics_config *cfg = libnvme_ctrl_get_config(c); + const char *transport = libnvme_ctrl_get_transport(c); const char *hostnqn, *hostid, *hostkey, *ctrlkey = NULL; bool discover = false, discovery_nqn = false; - struct nvme_global_ctx *ctx = h->ctx; + struct libnvme_global_ctx *ctx = h->ctx; long keyring_id = 0; long key_id = 0; int ret; if (!transport) { - nvme_msg(ctx, LOG_ERR, "need a transport (-t) argument\n"); + libnvme_msg(ctx, LOG_ERR, "need a transport (-t) argument\n"); return -ENVME_CONNECT_TARG; } if (strncmp(transport, "loop", 4)) { - if (!nvme_ctrl_get_traddr(c)) { - nvme_msg(h->ctx, LOG_ERR, "need a address (-a) argument\n"); + if (!libnvme_ctrl_get_traddr(c)) { + libnvme_msg(h->ctx, LOG_ERR, "need a address (-a) argument\n"); 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) { + libnvme_ctrl_get_subsysnqn(c)) < 0) { return -ENOMEM; } - if (!strcmp(nvme_ctrl_get_subsysnqn(c), NVME_DISC_SUBSYS_NAME)) { - nvme_ctrl_set_discovery_ctrl(c, true); - nvme_ctrl_set_unique_discovery_ctrl(c, false); + if (!strcmp(libnvme_ctrl_get_subsysnqn(c), NVME_DISC_SUBSYS_NAME)) { + libnvme_ctrl_set_discovery_ctrl(c, true); + libnvme_ctrl_set_unique_discovery_ctrl(c, false); discovery_nqn = true; } - if (nvme_ctrl_get_discovery_ctrl(c)) + if (libnvme_ctrl_get_discovery_ctrl(c)) discover = true; - hostnqn = nvme_host_get_hostnqn(h); - hostid = nvme_host_get_hostid(h); - hostkey = nvme_host_get_dhchap_host_key(h); + hostnqn = libnvme_host_get_hostnqn(h); + hostid = libnvme_host_get_hostid(h); + hostkey = libnvme_host_get_dhchap_host_key(h); if (!hostkey) - hostkey = nvme_ctrl_get_dhchap_host_key(c); + hostkey = libnvme_ctrl_get_dhchap_host_key(c); if (hostkey) - ctrlkey = nvme_ctrl_get_dhchap_ctrl_key(c); + ctrlkey = libnvme_ctrl_get_dhchap_ctrl_key(c); if (cfg->tls && cfg->concat) { - nvme_msg(h->ctx, LOG_ERR, "cannot specify --tls and --concat together\n"); + libnvme_msg(h->ctx, LOG_ERR, "cannot specify --tls and --concat together\n"); return -ENVME_CONNECT_INVAL; } if (cfg->concat && !hostkey) { - nvme_msg(h->ctx, LOG_ERR, "required argument [--dhchap-secret | -S] not specified with --concat\n"); + libnvme_msg(h->ctx, LOG_ERR, "required argument [--dhchap-secret | -S] not specified with --concat\n"); return -ENVME_CONNECT_INVAL; } if (cfg->tls) { - ret = __nvme_import_keys_from_config(h, c, + ret = __libnvme_import_keys_from_config(h, c, &keyring_id, &key_id); if (ret) return ret; @@ -791,13 +791,13 @@ static int build_options(nvme_host_t h, nvme_ctrl_t c, char **argstr) if (add_argument(ctx, argstr, transport, transport) || add_argument(ctx, argstr, traddr, - nvme_ctrl_get_traddr(c)) || + libnvme_ctrl_get_traddr(c)) || add_argument(ctx, argstr, host_traddr, - nvme_ctrl_get_host_traddr(c)) || + libnvme_ctrl_get_host_traddr(c)) || add_argument(ctx, argstr, host_iface, - nvme_ctrl_get_host_iface(c)) || + libnvme_ctrl_get_host_iface(c)) || add_argument(ctx, argstr, trsvcid, - nvme_ctrl_get_trsvcid(c)) || + libnvme_ctrl_get_trsvcid(c)) || (hostnqn && add_argument(ctx, argstr, hostnqn, hostnqn)) || (hostid && add_argument(ctx, argstr, hostid, hostid)) || (discover && !discovery_nqn && @@ -858,7 +858,7 @@ static int build_options(nvme_host_t h, nvme_ctrl_t c, char **argstr) continue; \ } -static int __nvmf_supported_options(struct nvme_global_ctx *ctx) +static int __nvmf_supported_options(struct libnvme_global_ctx *ctx) { char buf[0x1000], *options, *p, *v; _cleanup_fd_ int fd = -1; @@ -873,8 +873,8 @@ static int __nvmf_supported_options(struct nvme_global_ctx *ctx) fd = open(nvmf_dev, O_RDONLY); if (fd < 0) { - nvme_msg(ctx, LOG_ERR, "Failed to open %s: %s\n", - nvmf_dev, nvme_strerror(errno)); + libnvme_msg(ctx, LOG_ERR, "Failed to open %s: %s\n", + nvmf_dev, libnvme_strerror(errno)); return -ENVME_CONNECT_OPEN; } @@ -886,22 +886,22 @@ static int __nvmf_supported_options(struct nvme_global_ctx *ctx) * Older Linux kernels don't allow reading from nvmf_dev * to get supported options, so use a default set */ - nvme_msg(ctx, LOG_DEBUG, + libnvme_msg(ctx, LOG_DEBUG, "Cannot read %s, using default options\n", nvmf_dev); *ctx->options = default_supported_options; return 0; } - nvme_msg(ctx, LOG_ERR, "Failed to read from %s: %s\n", - nvmf_dev, nvme_strerror(errno)); + libnvme_msg(ctx, LOG_ERR, "Failed to read from %s: %s\n", + nvmf_dev, libnvme_strerror(errno)); return -ENVME_CONNECT_READ; } buf[len] = '\0'; options = buf; - nvme_msg(ctx, LOG_DEBUG, "kernel supports: "); + libnvme_msg(ctx, LOG_DEBUG, "kernel supports: "); while ((p = strsep(&options, ",\n")) != NULL) { if (!*p) @@ -909,7 +909,7 @@ static int __nvmf_supported_options(struct nvme_global_ctx *ctx) v = strsep(&p, "= "); if (!v) continue; - nvme_msg(ctx, LOG_DEBUG, "%s ", v); + libnvme_msg(ctx, LOG_DEBUG, "%s ", v); parse_option(ctx, v, cntlid); parse_option(ctx, v, concat); @@ -942,11 +942,11 @@ static int __nvmf_supported_options(struct nvme_global_ctx *ctx) parse_option(ctx, v, transport); parse_option(ctx, v, trsvcid); } - nvme_msg(ctx, LOG_DEBUG, "\n"); + libnvme_msg(ctx, LOG_DEBUG, "\n"); return 0; } -static int __nvmf_add_ctrl(struct nvme_global_ctx *ctx, const char *argstr) +static int __nvmf_add_ctrl(struct libnvme_global_ctx *ctx, const char *argstr) { _cleanup_fd_ int fd = -1; int ret, len = strlen(argstr); @@ -954,17 +954,17 @@ static int __nvmf_add_ctrl(struct nvme_global_ctx *ctx, const char *argstr) fd = open(nvmf_dev, O_RDWR); if (fd < 0) { - nvme_msg(ctx, LOG_ERR, "Failed to open %s: %s\n", - nvmf_dev, nvme_strerror(errno)); + libnvme_msg(ctx, LOG_ERR, "Failed to open %s: %s\n", + nvmf_dev, libnvme_strerror(errno)); return -ENVME_CONNECT_OPEN; } - nvme_msg(ctx, LOG_DEBUG, "connect ctrl, '%.*s'\n", + libnvme_msg(ctx, LOG_DEBUG, "connect ctrl, '%.*s'\n", (int)strcspn(argstr,"\n"), argstr); ret = write(fd, argstr, len); if (ret != len) { - nvme_msg(ctx, LOG_INFO, "Failed to write to %s: %s\n", - nvmf_dev, nvme_strerror(errno)); + libnvme_msg(ctx, LOG_INFO, "Failed to write to %s: %s\n", + nvmf_dev, libnvme_strerror(errno)); switch (errno) { case EALREADY: return -ENVME_CONNECT_ALREADY; @@ -990,11 +990,11 @@ static int __nvmf_add_ctrl(struct nvme_global_ctx *ctx, const char *argstr) memset(buf, 0x0, sizeof(buf)); len = read(fd, buf, sizeof(buf) - 1); if (len < 0) { - nvme_msg(ctx, LOG_ERR, "Failed to read from %s: %s\n", - nvmf_dev, nvme_strerror(errno)); + libnvme_msg(ctx, LOG_ERR, "Failed to read from %s: %s\n", + nvmf_dev, libnvme_strerror(errno)); return -ENVME_CONNECT_READ; } - nvme_msg(ctx, LOG_DEBUG, "connect ctrl, response '%.*s'\n", + libnvme_msg(ctx, LOG_DEBUG, "connect ctrl, response '%.*s'\n", (int)strcspn(buf, "\n"), buf); buf[len] = '\0'; options = buf; @@ -1005,38 +1005,38 @@ static int __nvmf_add_ctrl(struct nvme_global_ctx *ctx, const char *argstr) return ret; } - nvme_msg(ctx, LOG_ERR, "Failed to parse ctrl info for \"%s\"\n", argstr); + libnvme_msg(ctx, LOG_ERR, "Failed to parse ctrl info for \"%s\"\n", argstr); return -ENVME_CONNECT_PARSE; } -static const char *lookup_context(struct nvme_global_ctx *ctx, nvme_ctrl_t c) +static const char *lookup_context(struct libnvme_global_ctx *ctx, libnvme_ctrl_t c) { - nvme_host_t h; - nvme_subsystem_t s; + libnvme_host_t h; + libnvme_subsystem_t s; - nvme_for_each_host(ctx, h) { - nvme_for_each_subsystem(h, s) { + libnvme_for_each_host(ctx, h) { + libnvme_for_each_subsystem(h, s) { struct nvmf_context fctx = { - .transport = nvme_ctrl_get_transport(c), - .traddr = nvme_ctrl_get_traddr(c), + .transport = libnvme_ctrl_get_transport(c), + .traddr = libnvme_ctrl_get_traddr(c), .host_traddr = NULL, .host_iface = NULL, - .trsvcid = nvme_ctrl_get_trsvcid(c), + .trsvcid = libnvme_ctrl_get_trsvcid(c), .subsysnqn = NULL, }; - if (nvme_ctrl_find(s, &fctx)) - return nvme_subsystem_get_application(s); + if (libnvme_ctrl_find(s, &fctx)) + return libnvme_subsystem_get_application(s); } } return NULL; } -__public int nvmf_add_ctrl(nvme_host_t h, nvme_ctrl_t c, - const struct nvme_fabrics_config *cfg) +__public int nvmf_add_ctrl(libnvme_host_t h, libnvme_ctrl_t c, + const struct libnvme_fabrics_config *cfg) { - nvme_subsystem_t s; + libnvme_subsystem_t s; const char *root_app, *app; _cleanup_free_ char *argstr = NULL; int ret; @@ -1045,51 +1045,51 @@ __public int nvmf_add_ctrl(nvme_host_t h, nvme_ctrl_t c, cfg = merge_config(c, cfg); /* apply configuration from config file (JSON) */ - s = nvme_lookup_subsystem(h, NULL, nvme_ctrl_get_subsysnqn(c)); + s = libnvme_lookup_subsystem(h, NULL, libnvme_ctrl_get_subsysnqn(c)); if (s) { - nvme_ctrl_t fc; + libnvme_ctrl_t fc; struct nvmf_context fctx = { - .transport = nvme_ctrl_get_transport(c), - .traddr = nvme_ctrl_get_traddr(c), - .host_traddr = nvme_ctrl_get_host_traddr(c), - .host_iface = nvme_ctrl_get_trsvcid(c), - .trsvcid = nvme_ctrl_get_trsvcid(c), + .transport = libnvme_ctrl_get_transport(c), + .traddr = libnvme_ctrl_get_traddr(c), + .host_traddr = libnvme_ctrl_get_host_traddr(c), + .host_iface = libnvme_ctrl_get_trsvcid(c), + .trsvcid = libnvme_ctrl_get_trsvcid(c), .subsysnqn = NULL, }; - fc = nvme_ctrl_find(s, &fctx); + fc = libnvme_ctrl_find(s, &fctx); if (fc) { const char *key; - cfg = merge_config(c, nvme_ctrl_get_config(fc)); + cfg = merge_config(c, libnvme_ctrl_get_config(fc)); /* * An authentication key might already been set * in @cfg, so ensure to update @c with the correct * controller key. */ - key = nvme_ctrl_get_dhchap_host_key(fc); + key = libnvme_ctrl_get_dhchap_host_key(fc); if (key) - nvme_ctrl_set_dhchap_host_key(c, key); - key = nvme_ctrl_get_dhchap_ctrl_key(fc); + libnvme_ctrl_set_dhchap_host_key(c, key); + key = libnvme_ctrl_get_dhchap_ctrl_key(fc); if (key) - nvme_ctrl_set_dhchap_ctrl_key(c, key); - key = nvme_ctrl_get_keyring(fc); + libnvme_ctrl_set_dhchap_ctrl_key(c, key); + key = libnvme_ctrl_get_keyring(fc); if (key) - nvme_ctrl_set_keyring(c, key); - key = nvme_ctrl_get_tls_key_identity(fc); + libnvme_ctrl_set_keyring(c, key); + key = libnvme_ctrl_get_tls_key_identity(fc); if (key) - nvme_ctrl_set_tls_key_identity(c, key); - key = nvme_ctrl_get_tls_key(fc); + libnvme_ctrl_set_tls_key_identity(c, key); + key = libnvme_ctrl_get_tls_key(fc); if (key) - nvme_ctrl_set_tls_key(c, key); + libnvme_ctrl_set_tls_key(c, key); } } - root_app = nvme_get_application(h->ctx); + root_app = libnvme_get_application(h->ctx); if (root_app) { - app = nvme_subsystem_get_application(s); - if (!app && nvme_ctrl_get_discovery_ctrl(c)) + app = libnvme_subsystem_get_application(s); + if (!app && libnvme_ctrl_get_discovery_ctrl(c)) app = lookup_context(h->ctx, c); /* @@ -1099,13 +1099,13 @@ __public int nvmf_add_ctrl(nvme_host_t h, nvme_ctrl_t c, * application string. */ if (app && strcmp(app, root_app)) { - nvme_msg(h->ctx, LOG_INFO, "skip %s, not managed by %s\n", - nvme_subsystem_get_subsysnqn(s), root_app); + libnvme_msg(h->ctx, LOG_INFO, "skip %s, not managed by %s\n", + libnvme_subsystem_get_subsysnqn(s), root_app); return -ENVME_CONNECT_IGNORED; } } - nvme_ctrl_set_discovered(c, true); + libnvme_ctrl_set_discovered(c, true); if (traddr_is_hostname(h->ctx, c)) { char *traddr = c->traddr; @@ -1124,12 +1124,12 @@ __public int nvmf_add_ctrl(nvme_host_t h, nvme_ctrl_t c, if (ret < 0) return ret; - nvme_msg(h->ctx, LOG_INFO, "nvme%d: %s connected\n", ret, - nvme_ctrl_get_subsysnqn(c)); - return nvme_init_ctrl(h, c, ret); + libnvme_msg(h->ctx, LOG_INFO, "nvme%d: %s connected\n", ret, + libnvme_ctrl_get_subsysnqn(c)); + return libnvme_init_ctrl(h, c, ret); } -__public int nvmf_connect_ctrl(nvme_ctrl_t c) +__public int nvmf_connect_ctrl(libnvme_ctrl_t c) { _cleanup_free_ char *argstr = NULL; int ret; @@ -1146,14 +1146,14 @@ __public int nvmf_connect_ctrl(nvme_ctrl_t c) } static void nvmf_update_tls_concat(struct nvmf_disc_log_entry *e, - nvme_ctrl_t c, nvme_host_t h) + libnvme_ctrl_t c, libnvme_host_t h) { if (e->trtype != NVMF_TRTYPE_TCP || e->tsas.tcp.sectype == NVMF_TCP_SECTYPE_NONE) return; if (e->treq & NVMF_TREQ_REQUIRED) { - nvme_msg(h->ctx, LOG_DEBUG, + libnvme_msg(h->ctx, LOG_DEBUG, "setting --tls due to treq %s and sectype %s\n", nvmf_treq_str(e->treq), nvmf_sectype_str(e->tsas.tcp.sectype)); @@ -1163,7 +1163,7 @@ static void nvmf_update_tls_concat(struct nvmf_disc_log_entry *e, } if (e->treq & NVMF_TREQ_NOT_REQUIRED) { - nvme_msg(h->ctx, LOG_DEBUG, + libnvme_msg(h->ctx, LOG_DEBUG, "setting --concat due to treq %s and sectype %s\n", nvmf_treq_str(e->treq), nvmf_sectype_str(e->tsas.tcp.sectype)); @@ -1173,13 +1173,13 @@ static void nvmf_update_tls_concat(struct nvmf_disc_log_entry *e, } } -static int nvmf_connect_disc_entry(nvme_host_t h, +static int nvmf_connect_disc_entry(libnvme_host_t h, struct nvmf_disc_log_entry *e, struct nvmf_context *fctx, - const struct nvme_fabrics_config *cfg, - bool *discover, nvme_ctrl_t *cp) + const struct libnvme_fabrics_config *cfg, + bool *discover, libnvme_ctrl_t *cp) { - nvme_ctrl_t c; + libnvme_ctrl_t c; int ret; switch (e->trtype) { @@ -1192,7 +1192,7 @@ static int nvmf_connect_disc_entry(nvme_host_t h, fctx->trsvcid = e->trsvcid; break; default: - nvme_msg(h->ctx, LOG_ERR, + libnvme_msg(h->ctx, LOG_ERR, "skipping unsupported adrfam %d\n", e->adrfam); return -EINVAL; @@ -1204,7 +1204,7 @@ static int nvmf_connect_disc_entry(nvme_host_t h, fctx->traddr = e->traddr; break; default: - nvme_msg(h->ctx, LOG_ERR, + libnvme_msg(h->ctx, LOG_ERR, "skipping unsupported adrfam %d\n", e->adrfam); return -EINVAL; @@ -1214,7 +1214,7 @@ static int nvmf_connect_disc_entry(nvme_host_t h, fctx->traddr = strlen(e->traddr) ? e->traddr : NULL; break; default: - nvme_msg(h->ctx, LOG_ERR, "skipping unsupported transport %d\n", + libnvme_msg(h->ctx, LOG_ERR, "skipping unsupported transport %d\n", e->trtype); return -EINVAL; } @@ -1222,13 +1222,13 @@ static int nvmf_connect_disc_entry(nvme_host_t h, fctx->transport = nvmf_trtype_str(e->trtype); fctx->subsysnqn = e->subnqn; - nvme_msg(h->ctx, LOG_DEBUG, "lookup ctrl " + libnvme_msg(h->ctx, LOG_DEBUG, "lookup ctrl " "(transport: %s, traddr: %s, trsvcid %s)\n", fctx->transport, fctx->traddr, fctx->trsvcid); - ret = _nvme_create_ctrl(h->ctx, fctx, &c); + ret = _libnvme_create_ctrl(h->ctx, fctx, &c); if (ret) { - nvme_msg(h->ctx, LOG_DEBUG, "skipping discovery entry, " + libnvme_msg(h->ctx, LOG_DEBUG, "skipping discovery entry, " "failed to allocate %s controller with traddr %s\n", fctx->transport, fctx->traddr); return ret; @@ -1236,29 +1236,29 @@ static int nvmf_connect_disc_entry(nvme_host_t h, switch (e->subtype) { case NVME_NQN_CURR: - nvme_ctrl_set_discovered(c, true); - nvme_ctrl_set_unique_discovery_ctrl(c, + libnvme_ctrl_set_discovered(c, true); + libnvme_ctrl_set_unique_discovery_ctrl(c, strcmp(e->subnqn, NVME_DISC_SUBSYS_NAME)); break; case NVME_NQN_DISC: if (discover) *discover = true; - nvme_ctrl_set_discovery_ctrl(c, true); - nvme_ctrl_set_unique_discovery_ctrl(c, + libnvme_ctrl_set_discovery_ctrl(c, true); + libnvme_ctrl_set_unique_discovery_ctrl(c, strcmp(e->subnqn, NVME_DISC_SUBSYS_NAME)); break; default: - nvme_msg(h->ctx, LOG_ERR, "unsupported subtype %d\n", + libnvme_msg(h->ctx, LOG_ERR, "unsupported subtype %d\n", e->subtype); fallthrough; case NVME_NQN_NVME: - nvme_ctrl_set_discovery_ctrl(c, false); - nvme_ctrl_set_unique_discovery_ctrl(c, false); + libnvme_ctrl_set_discovery_ctrl(c, false); + libnvme_ctrl_set_unique_discovery_ctrl(c, false); break; } - if (nvme_ctrl_get_discovered(c)) { - nvme_free_ctrl(c); + if (libnvme_ctrl_get_discovered(c)) { + libnvme_free_ctrl(c); return -EAGAIN; } @@ -1277,7 +1277,7 @@ static int nvmf_connect_disc_entry(nvme_host_t h, if (ret == EINVAL && c->cfg.disable_sqflow) { /* disable_sqflow is unrecognized option on older kernels */ - nvme_msg(h->ctx, LOG_INFO, "failed to connect controller, " + libnvme_msg(h->ctx, 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); @@ -1286,7 +1286,7 @@ static int nvmf_connect_disc_entry(nvme_host_t h, return 0; } } - nvme_free_ctrl(c); + libnvme_free_ctrl(c); return -ENOENT; } @@ -1297,31 +1297,31 @@ static int nvmf_connect_disc_entry(nvme_host_t h, */ #define DISCOVERY_HEADER_LEN 20 -static int nvme_discovery_log(const struct nvme_get_discovery_args *args, +static int nvme_discovery_log(const struct libnvme_get_discovery_args *args, struct nvmf_discovery_log **logp) { - struct nvme_global_ctx *ctx = args->c->ctx; + struct libnvme_global_ctx *ctx = args->c->ctx; struct nvmf_discovery_log *log; int retries = 0; int err; - const char *name = nvme_ctrl_get_name(args->c); + const char *name = libnvme_ctrl_get_name(args->c); uint64_t genctr, numrec; - struct nvme_transport_handle *hdl = nvme_ctrl_get_transport_handle(args->c); - struct nvme_passthru_cmd cmd; + struct libnvme_transport_handle *hdl = libnvme_ctrl_get_transport_handle(args->c); + struct libnvme_passthru_cmd cmd; - log = __nvme_alloc(sizeof(*log)); + log = __libnvme_alloc(sizeof(*log)); if (!log) { - nvme_msg(ctx, LOG_ERR, + libnvme_msg(ctx, LOG_ERR, "could not allocate memory for discovery log header\n"); return -ENOMEM; } - nvme_msg(ctx, LOG_DEBUG, "%s: get header (try %d/%d)\n", + libnvme_msg(ctx, LOG_DEBUG, "%s: get header (try %d/%d)\n", name, retries, args->max_retries); nvme_init_get_log_discovery(&cmd, 0, log, DISCOVERY_HEADER_LEN); - err = nvme_get_log(hdl, &cmd, false, DISCOVERY_HEADER_LEN); + err = libnvme_get_log(hdl, &cmd, false, DISCOVERY_HEADER_LEN); if (err) { - nvme_msg(ctx, LOG_INFO, + libnvme_msg(ctx, LOG_INFO, "%s: discover try %d/%d failed, errno %d status 0x%x\n", name, retries, args->max_retries, errno, err); goto out_free_log; @@ -1338,14 +1338,14 @@ static int nvme_discovery_log(const struct nvme_get_discovery_args *args, free(log); entries_size = sizeof(*log->entries) * numrec; - log = __nvme_alloc(sizeof(*log) + entries_size); + log = __libnvme_alloc(sizeof(*log) + entries_size); if (!log) { - nvme_msg(ctx, LOG_ERR, + libnvme_msg(ctx, LOG_ERR, "could not alloc memory for discovery log page\n"); return -ENOMEM; } - nvme_msg(ctx, LOG_DEBUG, + libnvme_msg(ctx, LOG_DEBUG, "%s: get %" PRIu64 " records (genctr %" PRIu64 ")\n", name, numrec, genctr); @@ -1353,9 +1353,9 @@ static int nvme_discovery_log(const struct nvme_get_discovery_args *args, cmd.cdw10 |= NVME_FIELD_ENCODE(args->lsp, NVME_LOG_CDW10_LSP_SHIFT, NVME_LOG_CDW10_LSP_MASK); - err = nvme_get_log(hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); + err = libnvme_get_log(hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); if (err) { - nvme_msg(ctx, LOG_INFO, + libnvme_msg(ctx, LOG_INFO, "%s: discover try %d/%d failed, errno %d status 0x%x\n", name, retries, args->max_retries, errno, err); goto out_free_log; @@ -1365,12 +1365,12 @@ static int nvme_discovery_log(const struct nvme_get_discovery_args *args, * If the log page was read with multiple Get Log Page commands, * genctr must be checked afterwards to ensure atomicity */ - nvme_msg(ctx, LOG_DEBUG, "%s: get header again\n", name); + libnvme_msg(ctx, LOG_DEBUG, "%s: get header again\n", name); nvme_init_get_log_discovery(&cmd, 0, log, DISCOVERY_HEADER_LEN); - err = nvme_get_log(hdl, &cmd, false, DISCOVERY_HEADER_LEN); + err = libnvme_get_log(hdl, &cmd, false, DISCOVERY_HEADER_LEN); if (err) { - nvme_msg(ctx, LOG_INFO, + libnvme_msg(ctx, LOG_INFO, "%s: discover try %d/%d failed, errno %d status 0x%x\n", name, retries, args->max_retries, errno, err); goto out_free_log; @@ -1379,10 +1379,10 @@ static int nvme_discovery_log(const struct nvme_get_discovery_args *args, ++retries < args->max_retries); if (genctr != le64_to_cpu(log->genctr)) { - nvme_msg(ctx, LOG_INFO, "%s: discover genctr mismatch\n", name); + libnvme_msg(ctx, LOG_INFO, "%s: discover genctr mismatch\n", name); err = -EAGAIN; } else if (numrec != le64_to_cpu(log->numrec)) { - nvme_msg(ctx, LOG_INFO, + libnvme_msg(ctx, LOG_INFO, "%s: numrec changed unexpectedly " "from %" PRIu64 " to %" PRIu64 "\n", name, numrec, le64_to_cpu(log->numrec)); @@ -1414,10 +1414,10 @@ static void sanitize_discovery_log_entry(struct nvmf_disc_log_entry *e) } } -__public int nvmf_get_discovery_log(nvme_ctrl_t c, struct nvmf_discovery_log **logp, +__public int nvmf_get_discovery_log(libnvme_ctrl_t c, struct nvmf_discovery_log **logp, int max_retries) { - struct nvme_get_discovery_args args = { + struct libnvme_get_discovery_args args = { .c = c, .max_retries = max_retries, .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, @@ -1428,7 +1428,7 @@ __public int nvmf_get_discovery_log(nvme_ctrl_t c, struct nvmf_discovery_log **l return nvmf_get_discovery_wargs(&args, logp); } -__public int nvmf_get_discovery_wargs(struct nvme_get_discovery_args *args, +__public int nvmf_get_discovery_wargs(struct libnvme_get_discovery_args *args, struct nvmf_discovery_log **logp) { struct nvmf_discovery_log *log; @@ -1483,7 +1483,7 @@ static __u32 nvmf_get_tel(const char *hostsymname) * @tsas: Transport Specific Address Subtype for the address being * registered. */ -static void nvmf_fill_die(struct nvmf_ext_die *die, struct nvme_host *h, +static void nvmf_fill_die(struct nvmf_ext_die *die, struct libnvme_host *h, __u32 tel, __u8 trtype, __u8 adrfam, const char *reg_addr, union nvmf_tsas *tsas) { @@ -1506,7 +1506,7 @@ static void nvmf_fill_die(struct nvmf_ext_die *die, struct nvme_host *h, exat = die->exat; exat->exattype = cpu_to_le16(NVMF_EXATTYPE_HOSTID); exat->exatlen = cpu_to_le16(nvmf_exat_len(NVME_UUID_LEN)); - nvme_uuid_from_string(h->hostid, exat->exatval); + libnvme_uuid_from_string(h->hostid, exat->exatval); /* Extended Attribute for the Symbolic Name (optional) */ symname_len = h->hostsymname ? strlen(h->hostsymname) : 0; @@ -1547,49 +1547,49 @@ static void nvmf_fill_die(struct nvmf_ext_die *die, struct nvme_host *h, * * Return: 0 on success; on failure -1 is returned and errno is set */ -static int nvmf_dim(nvme_ctrl_t c, enum nvmf_dim_tas tas, __u8 trtype, +static int nvmf_dim(libnvme_ctrl_t c, enum nvmf_dim_tas tas, __u8 trtype, __u8 adrfam, const char *reg_addr, union nvmf_tsas *tsas, __u32 *result) { - struct nvme_global_ctx *ctx = c->s && c->s->h ? c->s->h->ctx : NULL; + struct libnvme_global_ctx *ctx = c->s && c->s->h ? c->s->h->ctx : NULL; _cleanup_free_ struct nvmf_dim_data *dim = NULL; - struct nvme_transport_handle *hdl = nvme_ctrl_get_transport_handle(c); - struct nvme_passthru_cmd cmd; + struct libnvme_transport_handle *hdl = libnvme_ctrl_get_transport_handle(c); + struct libnvme_passthru_cmd cmd; struct nvmf_ext_die *die; __u32 tdl; __u32 tel; int ret; if (!c->s) { - nvme_msg(ctx, LOG_ERR, + libnvme_msg(ctx, LOG_ERR, "%s: failed to perform DIM. subsystem undefined.\n", c->name); return -EINVAL; } if (!c->s->h) { - nvme_msg(ctx, LOG_ERR, + libnvme_msg(ctx, LOG_ERR, "%s: failed to perform DIM. host undefined.\n", c->name); return -EINVAL; } if (!c->s->h->hostid) { - nvme_msg(ctx, LOG_ERR, + libnvme_msg(ctx, LOG_ERR, "%s: failed to perform DIM. hostid undefined.\n", c->name); return -EINVAL; } if (!c->s->h->hostnqn) { - nvme_msg(ctx, LOG_ERR, + libnvme_msg(ctx, LOG_ERR, "%s: failed to perform DIM. hostnqn undefined.\n", c->name); return -EINVAL; } if (strcmp(c->transport, "tcp")) { - nvme_msg(ctx, LOG_ERR, + libnvme_msg(ctx, LOG_ERR, "%s: DIM only supported for TCP connections.\n", c->name); return -EINVAL; @@ -1615,21 +1615,21 @@ 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(ctx, LOG_INFO, "%s: Failed to retrieve ENAME. %s.\n", - c->name, nvme_strerror(-ret)); + libnvme_msg(ctx, LOG_INFO, "%s: Failed to retrieve ENAME. %s.\n", + c->name, libnvme_strerror(-ret)); else if (ret == 0) - nvme_msg(ctx, LOG_INFO, "%s: Failed to retrieve ENAME.\n", + libnvme_msg(ctx, LOG_INFO, "%s: Failed to retrieve ENAME.\n", c->name); ret = get_entity_version(dim->ever, sizeof(dim->ever)); if (ret <= 0) - nvme_msg(ctx, LOG_INFO, "%s: Failed to retrieve EVER.\n", c->name); + libnvme_msg(ctx, LOG_INFO, "%s: Failed to retrieve EVER.\n", c->name); die = &dim->die->extended; nvmf_fill_die(die, c->s->h, tel, trtype, adrfam, reg_addr, tsas); nvme_init_dim_send(&cmd, tas, dim, tdl); - return nvme_submit_admin_passthru(hdl, &cmd); + return libnvme_submit_admin_passthru(hdl, &cmd); } /** @@ -1646,11 +1646,11 @@ static int nvmf_dim(nvme_ctrl_t c, enum nvmf_dim_tas tas, __u8 trtype, * Return: The address family of the source address associated with the * socket connected to the DC. */ -static __u8 nvme_get_adrfam(nvme_ctrl_t c) +static __u8 nvme_get_adrfam(libnvme_ctrl_t c) { struct sockaddr_storage addr; __u8 adrfam = NVMF_ADDR_FAMILY_IP4; - struct nvme_global_ctx *ctx = c->s && c->s->h ? c->s->h->ctx : NULL; + struct libnvme_global_ctx *ctx = c->s && c->s->h ? c->s->h->ctx : NULL; if (!inet_pton_with_scope(ctx, AF_UNSPEC, c->traddr, c->trsvcid, &addr)) { if (addr.ss_family == AF_INET6) @@ -1681,16 +1681,16 @@ static const char *dctype_str[] = { * sysfs. We must get them directly from the controller by performing an * identify command. */ -static int nvme_fetch_cntrltype_dctype_from_id(nvme_ctrl_t c) +static int nvme_fetch_cntrltype_dctype_from_id(libnvme_ctrl_t c) { _cleanup_free_ struct nvme_id_ctrl *id = NULL; int ret; - id = __nvme_alloc(sizeof(*id)); + id = __libnvme_alloc(sizeof(*id)); if (!id) return -ENOMEM; - ret = nvme_ctrl_identify(c, id); + ret = libnvme_ctrl_identify(c, id); if (ret) return ret; @@ -1710,7 +1710,7 @@ static int nvme_fetch_cntrltype_dctype_from_id(nvme_ctrl_t c) return 0; } -__public bool nvmf_is_registration_supported(nvme_ctrl_t c) +__public bool nvmf_is_registration_supported(libnvme_ctrl_t c) { if (!c->cntrltype || !c->dctype) if (nvme_fetch_cntrltype_dctype_from_id(c)) @@ -1719,7 +1719,7 @@ __public bool nvmf_is_registration_supported(nvme_ctrl_t c) return !strcmp(c->dctype, "ddc") || !strcmp(c->dctype, "cdc"); } -__public int nvmf_register_ctrl(nvme_ctrl_t c, enum nvmf_dim_tas tas, __u32 *result) +__public int nvmf_register_ctrl(libnvme_ctrl_t c, enum nvmf_dim_tas tas, __u32 *result) { if (!nvmf_is_registration_supported(c)) return -ENOTSUP; @@ -1760,9 +1760,9 @@ static char *unescape_uri(const char *str, int len) return dst; } -__public int nvme_parse_uri(const char *str, struct nvme_fabrics_uri **urip) +__public int libnvme_parse_uri(const char *str, struct libnvme_fabrics_uri **urip) { - struct nvme_fabrics_uri *uri; + struct libnvme_fabrics_uri *uri; _cleanup_free_ char *scheme = NULL; _cleanup_free_ char *authority = NULL; _cleanup_free_ char *path = NULL; @@ -1783,7 +1783,7 @@ __public int nvme_parse_uri(const char *str, struct nvme_fabrics_uri **urip) * -CONTROLLER PORT]/NQN.2014-08.ORG.NVMEXPRESS.DISCOVERY/ */ - uri = calloc(1, sizeof(struct nvme_fabrics_uri)); + uri = calloc(1, sizeof(struct libnvme_fabrics_uri)); if (!uri) return -ENOMEM; @@ -1857,7 +1857,7 @@ __public int nvme_parse_uri(const char *str, struct nvme_fabrics_uri **urip) return 0; } -__public void nvmf_free_uri(struct nvme_fabrics_uri *uri) +__public void nvmf_free_uri(struct libnvme_fabrics_uri *uri) { char **s; @@ -1875,13 +1875,13 @@ __public void nvmf_free_uri(struct nvme_fabrics_uri *uri) free(uri); } -static nvme_ctrl_t lookup_ctrl(nvme_host_t h, struct nvmf_context *fctx) +static libnvme_ctrl_t lookup_ctrl(libnvme_host_t h, struct nvmf_context *fctx) { - nvme_subsystem_t s; - nvme_ctrl_t c; + libnvme_subsystem_t s; + libnvme_ctrl_t c; - nvme_for_each_subsystem(h, s) { - c = nvme_ctrl_find(s, fctx); + libnvme_for_each_subsystem(h, s) { + c = libnvme_ctrl_find(s, fctx); if (c) return c; } @@ -1889,19 +1889,19 @@ static nvme_ctrl_t lookup_ctrl(nvme_host_t h, struct nvmf_context *fctx) return NULL; } -static int lookup_host(struct nvme_global_ctx *ctx, - struct nvmf_context *fctx, struct nvme_host **host) +static int lookup_host(struct libnvme_global_ctx *ctx, + struct nvmf_context *fctx, struct libnvme_host **host) { _cleanup_free_ char *hnqn = NULL; _cleanup_free_ char *hid = NULL; - struct nvme_host *h; + struct libnvme_host *h; int err; - err = nvme_host_get_ids(ctx, fctx->hostnqn, fctx->hostid, &hnqn, &hid); + err = libnvme_host_get_ids(ctx, fctx->hostnqn, fctx->hostid, &hnqn, &hid); if (err < 0) return err; - h = nvme_lookup_host(ctx, hnqn, hid); + h = libnvme_lookup_host(ctx, hnqn, hid); if (!h) return -ENOMEM; @@ -1910,11 +1910,11 @@ static int lookup_host(struct nvme_global_ctx *ctx, return 0; } -static int setup_connection(struct nvmf_context *fctx, struct nvme_host *h, +static int setup_connection(struct nvmf_context *fctx, struct libnvme_host *h, bool discovery) { if (fctx->hostkey) - nvme_host_set_dhchap_host_key(h, fctx->hostkey); + libnvme_host_set_dhchap_host_key(h, fctx->hostkey); if (!fctx->trsvcid) fctx->trsvcid = nvmf_get_default_trsvcid(fctx->transport, @@ -1925,7 +1925,7 @@ static int setup_connection(struct nvmf_context *fctx, struct nvme_host *h, static int set_discovery_kato(struct nvmf_context *fctx, - struct nvme_fabrics_config *cfg) + struct libnvme_fabrics_config *cfg) { int tmo = cfg->keep_alive_tmo; @@ -1941,7 +1941,7 @@ static int set_discovery_kato(struct nvmf_context *fctx, static void nvme_parse_tls_args(const char *keyring, const char *tls_key, const char *tls_key_identity, - struct nvme_fabrics_config *cfg, nvme_ctrl_t c) + struct libnvme_fabrics_config *cfg, libnvme_ctrl_t c) { if (keyring) { char *endptr; @@ -1950,11 +1950,11 @@ static void nvme_parse_tls_args(const char *keyring, const char *tls_key, if (endptr != keyring) cfg->keyring = id; else - nvme_ctrl_set_keyring(c, keyring); + libnvme_ctrl_set_keyring(c, keyring); } if (tls_key_identity) - nvme_ctrl_set_tls_key_identity(c, tls_key_identity); + libnvme_ctrl_set_tls_key_identity(c, tls_key_identity); if (tls_key) { char *endptr; @@ -1963,22 +1963,22 @@ static void nvme_parse_tls_args(const char *keyring, const char *tls_key, if (endptr != tls_key) cfg->tls_key = id; else - nvme_ctrl_set_tls_key(c, tls_key); + libnvme_ctrl_set_tls_key(c, tls_key); } } -static int _nvmf_discovery(struct nvme_global_ctx *ctx, +static int _nvmf_discovery(struct libnvme_global_ctx *ctx, struct nvmf_context *fctx, bool connect, - struct nvme_ctrl *c) + struct libnvme_ctrl *c) { _cleanup_free_ struct nvmf_discovery_log *log = NULL; - nvme_subsystem_t s = nvme_ctrl_get_subsystem(c); - nvme_host_t h = nvme_subsystem_get_host(s); + libnvme_subsystem_t s = libnvme_ctrl_get_subsystem(c); + libnvme_host_t h = libnvme_subsystem_get_host(s); uint64_t numrec; int err; - struct nvme_get_discovery_args args = { + struct libnvme_get_discovery_args args = { .c = c, .args_size = sizeof(args), .max_retries = fctx->default_max_discovery_retries, @@ -1988,8 +1988,8 @@ static int _nvmf_discovery(struct nvme_global_ctx *ctx, err = nvmf_get_discovery_wargs(&args, &log); if (err) { - nvme_msg(ctx, LOG_ERR, "failed to get discovery log: %s\n", - nvme_strerror(err)); + libnvme_msg(ctx, LOG_ERR, "failed to get discovery log: %s\n", + libnvme_strerror(err)); return err; } @@ -2003,10 +2003,10 @@ static int _nvmf_discovery(struct nvme_global_ctx *ctx, for (int i = 0; i < numrec; i++) { struct nvmf_disc_log_entry *e = &log->entries[i]; - nvme_ctrl_t cl; + libnvme_ctrl_t cl; bool discover = false; bool disconnect; - nvme_ctrl_t child = { 0 }; + libnvme_ctrl_t child = { 0 }; int tmo = fctx->cfg->keep_alive_tmo; struct nvmf_context nfctx = *fctx; @@ -2018,11 +2018,11 @@ static int _nvmf_discovery(struct nvme_global_ctx *ctx, /* Already connected ? */ cl = lookup_ctrl(h, &nfctx); - if (cl && nvme_ctrl_get_name(cl)) + if (cl && libnvme_ctrl_get_name(cl)) continue; /* Skip connect if the transport types don't match */ - if (strcmp(nvme_ctrl_get_transport(c), + if (strcmp(libnvme_ctrl_get_transport(c), nfctx.transport)) continue; @@ -2069,8 +2069,8 @@ static int _nvmf_discovery(struct nvme_global_ctx *ctx, _nvmf_discovery(ctx, &nfctx, true, child); if (child && disconnect) { - nvme_disconnect_ctrl(child); - nvme_free_ctrl(child); + libnvme_disconnect_ctrl(child); + libnvme_free_ctrl(child); } } else if (err == -ENVME_CONNECT_ALREADY) { struct nvmf_disc_log_entry *e = &log->entries[i]; @@ -2103,17 +2103,17 @@ __public const char *nvmf_get_default_trsvcid(const char *transport, return NULL; } -static bool is_persistent_discovery_ctrl(nvme_host_t h, nvme_ctrl_t c) +static bool is_persistent_discovery_ctrl(libnvme_host_t h, libnvme_ctrl_t c) { - if (nvme_host_is_pdc_enabled(h, DEFAULT_PDC_ENABLED)) - return nvme_ctrl_get_unique_discovery_ctrl(c); + if (libnvme_host_is_pdc_enabled(h, DEFAULT_PDC_ENABLED)) + return libnvme_ctrl_get_unique_discovery_ctrl(c); return false; } -static int nvme_add_ctrl(struct nvmf_context *fctx, - struct nvme_host *h, struct nvme_ctrl *c, - struct nvme_fabrics_config *cfg) +static int libnvme_add_ctrl(struct nvmf_context *fctx, + struct libnvme_host *h, struct libnvme_ctrl *c, + struct libnvme_fabrics_config *cfg) { int err; @@ -2127,32 +2127,32 @@ static int nvme_add_ctrl(struct nvmf_context *fctx, return err; } -static int __create_discovery_ctrl(struct nvme_global_ctx *ctx, - struct nvmf_context *fctx, nvme_host_t h, - struct nvme_fabrics_config *cfg, struct nvme_ctrl **ctrl) +static int __create_discovery_ctrl(struct libnvme_global_ctx *ctx, + struct nvmf_context *fctx, libnvme_host_t h, + struct libnvme_fabrics_config *cfg, struct libnvme_ctrl **ctrl) { - nvme_ctrl_t c; + libnvme_ctrl_t c; int tmo, ret; - ret = _nvme_create_ctrl(ctx, fctx, &c); + ret = _libnvme_create_ctrl(ctx, fctx, &c); if (ret) return ret; - nvme_ctrl_set_discovery_ctrl(c, true); - nvme_ctrl_set_unique_discovery_ctrl(c, + libnvme_ctrl_set_discovery_ctrl(c, true); + libnvme_ctrl_set_unique_discovery_ctrl(c, strcmp(fctx->subsysnqn, NVME_DISC_SUBSYS_NAME)); tmo = set_discovery_kato(fctx, cfg); - if (nvme_ctrl_get_unique_discovery_ctrl(c) && fctx->hostkey) { - nvme_ctrl_set_dhchap_host_key(c, fctx->hostkey); + if (libnvme_ctrl_get_unique_discovery_ctrl(c) && fctx->hostkey) { + libnvme_ctrl_set_dhchap_host_key(c, fctx->hostkey); if (fctx->ctrlkey) - nvme_ctrl_set_dhchap_ctrl_key(c, fctx->ctrlkey); + libnvme_ctrl_set_dhchap_ctrl_key(c, fctx->ctrlkey); } - ret = nvme_add_ctrl(fctx, h, c, cfg); + ret = libnvme_add_ctrl(fctx, h, c, cfg); cfg->keep_alive_tmo = tmo; if (ret) { - nvme_free_ctrl(c); + libnvme_free_ctrl(c); return ret; } @@ -2160,44 +2160,44 @@ static int __create_discovery_ctrl(struct nvme_global_ctx *ctx, return 0; } -static int nvmf_create_discovery_ctrl(struct nvme_global_ctx *ctx, - struct nvmf_context *fctx, nvme_host_t h, - struct nvme_fabrics_config *cfg, - struct nvme_ctrl **ctrl) +static int nvmf_create_discovery_ctrl(struct libnvme_global_ctx *ctx, + struct nvmf_context *fctx, libnvme_host_t h, + struct libnvme_fabrics_config *cfg, + struct libnvme_ctrl **ctrl) { _cleanup_free_ struct nvme_id_ctrl *id = NULL; - struct nvme_ctrl *c; + struct libnvme_ctrl *c; int ret; ret = __create_discovery_ctrl(ctx, fctx, h, cfg, &c); if (ret) return ret; - if (nvme_ctrl_get_unique_discovery_ctrl(c)) { + if (libnvme_ctrl_get_unique_discovery_ctrl(c)) { *ctrl = c; return 0; } - id = __nvme_alloc(sizeof(*id)); + id = __libnvme_alloc(sizeof(*id)); if (!id) { - nvme_free_ctrl(c); + libnvme_free_ctrl(c); return -ENOMEM; } - ret = nvme_open(ctx, c->name, &c->hdl); + ret = libnvme_open(ctx, c->name, &c->hdl); if (ret) { - nvme_msg(ctx, LOG_ERR, "failed to open %s\n", c->name); + libnvme_msg(ctx, LOG_ERR, "failed to open %s\n", c->name); return ret; } /* Find out the name of discovery controller */ - ret = nvme_ctrl_identify(c, id); + ret = libnvme_ctrl_identify(c, id); if (ret) { - nvme_msg(ctx, LOG_ERR, + libnvme_msg(ctx, LOG_ERR, "failed to identify controller, error %s\n", - nvme_strerror(-ret)); - nvme_disconnect_ctrl(c); - nvme_free_ctrl(c); + libnvme_strerror(-ret)); + libnvme_disconnect_ctrl(c); + libnvme_free_ctrl(c); return ret; } @@ -2210,8 +2210,8 @@ static int nvmf_create_discovery_ctrl(struct nvme_global_ctx *ctx, * The subsysnqn is not the well-known name. Prefer the unique * subsysnqn over the well-known one. */ - nvme_disconnect_ctrl(c); - nvme_free_ctrl(c); + libnvme_disconnect_ctrl(c); + libnvme_free_ctrl(c); fctx->subsysnqn = id->subnqn; ret = __create_discovery_ctrl(ctx, fctx, h, cfg, &c); @@ -2222,19 +2222,19 @@ static int nvmf_create_discovery_ctrl(struct nvme_global_ctx *ctx, return 0; } -int _discovery_config_json(struct nvme_global_ctx *ctx, - struct nvmf_context *fctx, nvme_host_t h, nvme_ctrl_t c, +int _discovery_config_json(struct libnvme_global_ctx *ctx, + struct nvmf_context *fctx, libnvme_host_t h, libnvme_ctrl_t c, bool connect, bool force) { struct nvmf_context nfctx = *fctx; - struct nvme_fabrics_config cfg; - nvme_ctrl_t cn; + struct libnvme_fabrics_config cfg; + libnvme_ctrl_t cn; int ret = 0; - nfctx.transport = nvme_ctrl_get_transport(c); - nfctx.traddr = nvme_ctrl_get_traddr(c); - nfctx.host_traddr = nvme_ctrl_get_host_traddr(c); - nfctx.host_iface = nvme_ctrl_get_host_iface(c); + nfctx.transport = libnvme_ctrl_get_transport(c); + nfctx.traddr = libnvme_ctrl_get_traddr(c); + nfctx.host_traddr = libnvme_ctrl_get_host_traddr(c); + nfctx.host_iface = libnvme_ctrl_get_host_iface(c); if (!nfctx.transport && !nfctx.traddr) return 0; @@ -2248,7 +2248,7 @@ int _discovery_config_json(struct nvme_global_ctx *ctx, /* ignore if no host_traddr for fc */ if (!strcmp(nfctx.transport, "fc")) { if (!nfctx.host_traddr) { - nvme_msg(ctx, LOG_ERR, + libnvme_msg(ctx, LOG_ERR, "host_traddr required for fc\n"); return 0; } @@ -2258,23 +2258,23 @@ int _discovery_config_json(struct nvme_global_ctx *ctx, if (!strcmp(nfctx.transport, "rdma") || !strcmp(nfctx.transport, "fc")) { if (nfctx.host_iface) { - nvme_msg(ctx, LOG_ERR, + libnvme_msg(ctx, LOG_ERR, "host_iface not permitted for rdma or fc\n"); return 0; } } - nfctx.trsvcid = nvme_ctrl_get_trsvcid(c); + nfctx.trsvcid = libnvme_ctrl_get_trsvcid(c); if (!nfctx.trsvcid || !strcmp(nfctx.trsvcid, "")) nfctx.trsvcid = nvmf_get_default_trsvcid(nfctx.transport, true); if (force) - nfctx.subsysnqn = nvme_ctrl_get_subsysnqn(c); + nfctx.subsysnqn = libnvme_ctrl_get_subsysnqn(c); else nfctx.subsysnqn = NVME_DISC_SUBSYS_NAME; - if (nvme_ctrl_get_persistent(c)) + if (libnvme_ctrl_get_persistent(c)) nfctx.persistent = true; memcpy(&cfg, fctx->cfg, sizeof(cfg)); @@ -2294,19 +2294,19 @@ int _discovery_config_json(struct nvme_global_ctx *ctx, _nvmf_discovery(ctx, &nfctx, connect, cn); if (!(fctx->persistent || is_persistent_discovery_ctrl(h, cn))) - ret = nvme_disconnect_ctrl(cn); - nvme_free_ctrl(cn); + ret = libnvme_disconnect_ctrl(cn); + libnvme_free_ctrl(cn); return ret; } -__public int nvmf_discovery_config_json(struct nvme_global_ctx *ctx, +__public int nvmf_discovery_config_json(struct libnvme_global_ctx *ctx, struct nvmf_context *fctx, bool connect, bool force) { const char *hnqn, *hid; - struct nvme_subsystem *s; - struct nvme_host *h; - struct nvme_ctrl *c; + struct libnvme_subsystem *s; + struct libnvme_host *h; + struct libnvme_ctrl *c; int ret = 0, err; err = lookup_host(ctx, fctx, &h); @@ -2317,26 +2317,26 @@ __public int nvmf_discovery_config_json(struct nvme_global_ctx *ctx, if (err) return err; - nvme_for_each_host(ctx, h) { - nvme_for_each_subsystem(h, s) { - hnqn = nvme_host_get_hostnqn(h); + libnvme_for_each_host(ctx, h) { + libnvme_for_each_subsystem(h, s) { + hnqn = libnvme_host_get_hostnqn(h); if (fctx->hostnqn && hnqn && strcmp(fctx->hostnqn, hnqn)) continue; - hid = nvme_host_get_hostid(h); + hid = libnvme_host_get_hostid(h); if (fctx->hostid && hid && strcmp(fctx->hostid, hid)) continue; - nvme_subsystem_for_each_ctrl(s, c) { + libnvme_subsystem_for_each_ctrl(s, c) { err = _discovery_config_json(ctx, fctx, h, c, connect, force); if (err) { - nvme_msg(ctx, LOG_ERR, + libnvme_msg(ctx, LOG_ERR, "failed to connect to hostnqn=%s,nqn=%s,%s\n", - nvme_host_get_hostnqn(h), - nvme_subsystem_get_name(s), - nvme_ctrl_get_traddr(c)); + libnvme_host_get_hostnqn(h), + libnvme_subsystem_get_name(s), + libnvme_ctrl_get_traddr(c)); if (!ret) ret = err; @@ -2348,14 +2348,14 @@ __public int nvmf_discovery_config_json(struct nvme_global_ctx *ctx, return ret; } -__public int nvmf_connect_config_json(struct nvme_global_ctx *ctx, +__public int nvmf_connect_config_json(struct libnvme_global_ctx *ctx, struct nvmf_context *fctx) { const char *hnqn, *hid; const char *transport; - nvme_host_t h; - nvme_subsystem_t s; - nvme_ctrl_t c, _c; + libnvme_host_t h; + libnvme_subsystem_t s; + libnvme_ctrl_t c, _c; int ret = 0, err; err = lookup_host(ctx, fctx, &h); @@ -2366,19 +2366,19 @@ __public int nvmf_connect_config_json(struct nvme_global_ctx *ctx, if (err) return err; - nvme_for_each_host(ctx, h) { - nvme_for_each_subsystem(h, s) { - hnqn = nvme_host_get_hostnqn(h); + libnvme_for_each_host(ctx, h) { + libnvme_for_each_subsystem(h, s) { + hnqn = libnvme_host_get_hostnqn(h); if (fctx->hostnqn && hnqn && strcmp(fctx->hostnqn, hnqn)) continue; - hid = nvme_host_get_hostid(h); + hid = libnvme_host_get_hostid(h); if (fctx->hostid && hid && strcmp(fctx->hostid, hid)) continue; - nvme_subsystem_for_each_ctrl_safe(s, c, _c) { - transport = nvme_ctrl_get_transport(c); + libnvme_subsystem_for_each_ctrl_safe(s, c, _c) { + transport = libnvme_ctrl_get_transport(c); /* ignore none fabric transports */ if (strcmp(transport, "tcp") && @@ -2391,11 +2391,11 @@ __public int nvmf_connect_config_json(struct nvme_global_ctx *ctx, if (err == -ENVME_CONNECT_ALREADY) continue; - nvme_msg(ctx, LOG_ERR, + libnvme_msg(ctx, LOG_ERR, "failed to connect to hostnqn=%s,nqn=%s,%s\n", - nvme_host_get_hostnqn(h), - nvme_subsystem_get_name(s), - nvme_ctrl_get_traddr(c)); + libnvme_host_get_hostnqn(h), + libnvme_subsystem_get_name(s), + libnvme_ctrl_get_traddr(c)); if (!ret) ret = err; @@ -2407,11 +2407,11 @@ __public int nvmf_connect_config_json(struct nvme_global_ctx *ctx, return ret; } -__public int nvmf_discovery_config_file(struct nvme_global_ctx *ctx, +__public int nvmf_discovery_config_file(struct libnvme_global_ctx *ctx, struct nvmf_context *fctx, bool connect, bool force) { - struct nvme_host *h; - struct nvme_ctrl *c; + struct libnvme_host *h; + struct libnvme_ctrl *c; int err; err = lookup_host(ctx, fctx, &h); @@ -2449,8 +2449,8 @@ __public int nvmf_discovery_config_file(struct nvme_global_ctx *ctx, _nvmf_discovery(ctx, &nfctx, connect, c); if (!(nfctx.persistent || is_persistent_discovery_ctrl(h, c))) - err = nvme_disconnect_ctrl(c); - nvme_free_ctrl(c); + err = libnvme_disconnect_ctrl(c); + libnvme_free_ctrl(c); } while (!err); fctx->parser_cleanup(fctx, fctx->user_data); @@ -2461,44 +2461,44 @@ __public int nvmf_discovery_config_file(struct nvme_global_ctx *ctx, return 0; } -__public int nvmf_config_modify(struct nvme_global_ctx *ctx, +__public int nvmf_config_modify(struct libnvme_global_ctx *ctx, struct nvmf_context *fctx) { _cleanup_free_ char *hnqn = NULL; _cleanup_free_ char *hid = NULL; - struct nvme_host *h; - struct nvme_subsystem *s; - struct nvme_ctrl *c; + struct libnvme_host *h; + struct libnvme_subsystem *s; + struct libnvme_ctrl *c; if (!fctx->hostnqn) - fctx->hostnqn = hnqn = nvme_read_hostnqn(); + fctx->hostnqn = hnqn = libnvme_read_hostnqn(); if (!fctx->hostid && hnqn) - fctx->hostid = hid = nvme_read_hostid(); + fctx->hostid = hid = libnvme_read_hostid(); - h = nvme_lookup_host(ctx, fctx->hostnqn, fctx->hostid); + h = libnvme_lookup_host(ctx, fctx->hostnqn, fctx->hostid); if (!h) { - nvme_msg(ctx, LOG_ERR, "Failed to lookup host '%s'\n", + libnvme_msg(ctx, LOG_ERR, "Failed to lookup host '%s'\n", fctx->hostnqn); return -ENODEV; } if (fctx->hostkey) - nvme_host_set_dhchap_host_key(h, fctx->hostkey); + libnvme_host_set_dhchap_host_key(h, fctx->hostkey); - s = nvme_lookup_subsystem(h, NULL, fctx->subsysnqn); + s = libnvme_lookup_subsystem(h, NULL, fctx->subsysnqn); if (!s) { - nvme_msg(ctx, LOG_ERR, "Failed to lookup subsystem '%s'\n", + libnvme_msg(ctx, LOG_ERR, "Failed to lookup subsystem '%s'\n", fctx->subsysnqn); return -ENODEV; } - c = nvme_lookup_ctrl(s, fctx, NULL); + c = libnvme_lookup_ctrl(s, fctx, NULL); if (!c) { - nvme_msg(ctx, LOG_ERR, "Failed to lookup controller\n"); + libnvme_msg(ctx, LOG_ERR, "Failed to lookup controller\n"); return -ENODEV; } if (fctx->ctrlkey) - nvme_ctrl_set_dhchap_ctrl_key(c, fctx->ctrlkey); + libnvme_ctrl_set_dhchap_ctrl_key(c, fctx->ctrlkey); nvme_parse_tls_args(fctx->keyring, fctx->tls_key, fctx->tls_key_identity, fctx->cfg, c); @@ -2515,7 +2515,7 @@ static int nbft_filter(const struct dirent *dent) return !fnmatch(NBFT_SYSFS_FILENAME, dent->d_name, FNM_PATHNAME); } -__public int nvmf_nbft_read_files(struct nvme_global_ctx *ctx, char *path, +__public int nvmf_nbft_read_files(struct libnvme_global_ctx *ctx, char *path, struct nbft_file_entry **head) { struct nbft_file_entry *entry = NULL; @@ -2532,7 +2532,7 @@ __public int nvmf_nbft_read_files(struct nvme_global_ctx *ctx, char *path, snprintf(filename, sizeof(filename), "%s/%s", path, dent[i]->d_name); - ret = nvme_read_nbft(ctx, &nbft, filename); + ret = libnvme_read_nbft(ctx, &nbft, filename); if (!ret) { struct nbft_file_entry *new; @@ -2554,36 +2554,36 @@ __public int nvmf_nbft_read_files(struct nvme_global_ctx *ctx, char *path, return 0; } -__public void nvmf_nbft_free(struct nvme_global_ctx *ctx, struct nbft_file_entry *head) +__public void nvmf_nbft_free(struct libnvme_global_ctx *ctx, struct nbft_file_entry *head) { while (head) { struct nbft_file_entry *next = head->next; - nvme_free_nbft(ctx, head->nbft); + libnvme_free_nbft(ctx, head->nbft); free(head); head = next; } } -static bool validate_uri(struct nvme_global_ctx *ctx, +static bool validate_uri(struct libnvme_global_ctx *ctx, struct nbft_info_discovery *dd, - struct nvme_fabrics_uri *uri) + struct libnvme_fabrics_uri *uri) { if (!uri) { - nvme_msg(ctx, LOG_ERR, + libnvme_msg(ctx, LOG_ERR, "Discovery Descriptor %d: failed to parse URI %s\n", dd->index, dd->uri); return false; } if (strcmp(uri->scheme, "nvme") != 0) { - nvme_msg(ctx, LOG_ERR, + libnvme_msg(ctx, LOG_ERR, "Discovery Descriptor %d: unsupported scheme '%s'\n", dd->index, uri->scheme); return false; } if (!uri->protocol || strcmp(uri->protocol, "tcp") != 0) { - nvme_msg(ctx, LOG_ERR, + libnvme_msg(ctx, LOG_ERR, "Discovery Descriptor %d: unsupported transport '%s'\n", dd->index, uri->protocol); return false; @@ -2592,32 +2592,32 @@ static bool validate_uri(struct nvme_global_ctx *ctx, return true; } -static int nbft_connect(struct nvme_global_ctx *ctx, - struct nvmf_context *fctx, struct nvme_host *h, +static int nbft_connect(struct libnvme_global_ctx *ctx, + struct nvmf_context *fctx, struct libnvme_host *h, struct nvmf_disc_log_entry *e, struct nbft_info_subsystem_ns *ss, - struct nvme_fabrics_config *cfg) + struct libnvme_fabrics_config *cfg) { - nvme_ctrl_t c; + libnvme_ctrl_t c; int saved_log_level; bool saved_log_tstamp; bool saved_log_pid; int ret; - saved_log_level = nvme_get_logging_level(ctx, &saved_log_tstamp, + saved_log_level = libnvme_get_logging_level(ctx, &saved_log_tstamp, &saved_log_pid); c = lookup_ctrl(h, fctx); - if (c && nvme_ctrl_get_name(c)) + if (c && libnvme_ctrl_get_name(c)) return 0; - ret = _nvme_create_ctrl(ctx, fctx, &c); + ret = _libnvme_create_ctrl(ctx, fctx, &c); if (ret) return ret; /* Pause logging for unavailable SSNSs */ if (ss && ss->unavailable && saved_log_level < 1) - nvme_set_logging_level(ctx, -1, false, false); + libnvme_set_logging_level(ctx, -1, false, false); /* Update tls or concat */ nvmf_update_tls_concat(e, c, h); @@ -2626,19 +2626,19 @@ static int nbft_connect(struct nvme_global_ctx *ctx, /* Resume logging */ if (ss && ss->unavailable && saved_log_level < 1) - nvme_set_logging_level(ctx, + libnvme_set_logging_level(ctx, saved_log_level, saved_log_pid, saved_log_tstamp); if (ret) { - nvme_free_ctrl(c); + libnvme_free_ctrl(c); /* * In case this SSNS was marked as 'unavailable' and * our connection attempt has failed, ignore it. */ if (ss && ss->unavailable) { - nvme_msg(ctx, LOG_INFO, + libnvme_msg(ctx, LOG_INFO, "SSNS %d reported as unavailable, skipping\n", ss->index); return 0; @@ -2652,16 +2652,16 @@ static int nbft_connect(struct nvme_global_ctx *ctx, return 0; } -static int nbft_discovery(struct nvme_global_ctx *ctx, +static int nbft_discovery(struct libnvme_global_ctx *ctx, struct nvmf_context *fctx, struct nbft_info_discovery *dd, - struct nvme_host *h, struct nvme_ctrl *c, - struct nvme_fabrics_config *defcfg) + struct libnvme_host *h, struct libnvme_ctrl *c, + struct libnvme_fabrics_config *defcfg) { struct nvmf_discovery_log *log = NULL; int ret; int i; - struct nvme_get_discovery_args args = { + struct libnvme_get_discovery_args args = { .c = c, .args_size = sizeof(args), .max_retries = 10 /* MAX_DISC_RETRIES */, @@ -2672,16 +2672,16 @@ static int nbft_discovery(struct nvme_global_ctx *ctx, ret = nvmf_get_discovery_wargs(&args, &log); if (ret) { - nvme_msg(ctx, LOG_ERR, + libnvme_msg(ctx, LOG_ERR, "Discovery Descriptor %d: failed to get discovery log: %s\n", - dd->index, nvme_strerror(ret)); + dd->index, libnvme_strerror(ret)); return ret; } for (i = 0; i < le64_to_cpu(log->numrec); i++) { struct nvmf_disc_log_entry *e = &log->entries[i]; struct nvmf_context nfctx = *fctx; - nvme_ctrl_t cl; + libnvme_ctrl_t cl; int tmo = defcfg->keep_alive_tmo; nfctx.subsysnqn = e->subnqn; @@ -2694,24 +2694,24 @@ static int nbft_discovery(struct nvme_global_ctx *ctx, /* Already connected ? */ cl = lookup_ctrl(h, &nfctx); - if (cl && nvme_ctrl_get_name(cl)) + if (cl && libnvme_ctrl_get_name(cl)) continue; /* Skip connect if the transport types don't match */ - if (strcmp(nvme_ctrl_get_transport(c), + if (strcmp(libnvme_ctrl_get_transport(c), nfctx.transport)) continue; if (e->subtype == NVME_NQN_DISC) { - nvme_ctrl_t child; + libnvme_ctrl_t child; ret = nvmf_connect_disc_entry(h, e, &nfctx, defcfg, NULL, &child); if (ret) continue; nbft_discovery(ctx, &nfctx, dd, h, child, defcfg); - nvme_disconnect_ctrl(child); - nvme_free_ctrl(child); + libnvme_disconnect_ctrl(child); + libnvme_free_ctrl(child); } else { ret = nbft_connect(ctx, &nfctx, h, e, NULL, defcfg); @@ -2731,14 +2731,14 @@ static int nbft_discovery(struct nvme_global_ctx *ctx, defcfg); if (ret == 0) - nvme_msg(ctx, LOG_INFO, + libnvme_msg(ctx, LOG_INFO, "Discovery Descriptor %d: connect with host_traddr=\"%s\" failed, success after omitting host_traddr\n", dd->index, htradr); } if (ret) - nvme_msg(ctx, LOG_ERR, + libnvme_msg(ctx, LOG_ERR, "Discovery Descriptor %d: no controller found\n", dd->index); if (ret == -ENOMEM) @@ -2752,7 +2752,7 @@ static int nbft_discovery(struct nvme_global_ctx *ctx, return 0; } -__public int nvmf_discovery_nbft(struct nvme_global_ctx *ctx, +__public int nvmf_discovery_nbft(struct libnvme_global_ctx *ctx, struct nvmf_context *fctx, bool connect, char *nbft_path) { const char *hostnqn = NULL, *hostid = NULL, *host_traddr = NULL; @@ -2761,7 +2761,7 @@ __public int nvmf_discovery_nbft(struct nvme_global_ctx *ctx, struct nbft_info_subsystem_ns **ss; struct nbft_info_hfi *hfi; struct nbft_info_discovery **dd; - struct nvme_host *h; + struct libnvme_host *h; int ret, rr, i; ret = lookup_host(ctx, fctx, &h); @@ -2779,7 +2779,7 @@ __public int nvmf_discovery_nbft(struct nvme_global_ctx *ctx, ret = nvmf_nbft_read_files(ctx, nbft_path, &entry); if (ret) { if (ret != -ENOENT) - nvme_msg(ctx, LOG_ERR, + libnvme_msg(ctx, LOG_ERR, "Failed to access ACPI tables directory\n"); else ret = 0; /* nothing to connect */ @@ -2798,14 +2798,14 @@ __public int nvmf_discovery_nbft(struct nvme_global_ctx *ctx, if (fctx->hostid) hostid = fctx->hostid; else if (*entry->nbft->host.id) { - ret = nvme_uuid_to_string(entry->nbft->host.id, uuid); + ret = libnvme_uuid_to_string(entry->nbft->host.id, uuid); if (!ret) hostid = uuid; else hostid = fctx->hostid; } - h = nvme_lookup_host(ctx, hostnqn, hostid); + h = libnvme_lookup_host(ctx, hostnqn, hostid); if (!h) { ret = -ENOENT; goto out_free; @@ -2821,7 +2821,7 @@ __public int nvmf_discovery_nbft(struct nvme_global_ctx *ctx, /* Skip discovery NQN records */ if (strcmp((*ss)->subsys_nqn, NVME_DISC_SUBSYS_NAME) == 0) { - nvme_msg(ctx, LOG_INFO, + libnvme_msg(ctx, LOG_INFO, "SSNS %d points to well-known discovery NQN, skipping\n", (*ss)->index); continue; @@ -2856,14 +2856,14 @@ __public int nvmf_discovery_nbft(struct nvme_global_ctx *ctx, *ss, fctx->cfg); if (rr == 0) - nvme_msg(ctx, LOG_INFO, + libnvme_msg(ctx, LOG_INFO, "SSNS %d: connect with host_traddr=\"%s\" failed, success after omitting host_traddr\n", (*ss)->index, host_traddr); } if (rr) { - nvme_msg(ctx, LOG_ERR, + libnvme_msg(ctx, LOG_ERR, "SSNS %d: no controller found\n", (*ss)->index); /* report an error */ @@ -2876,12 +2876,12 @@ __public int nvmf_discovery_nbft(struct nvme_global_ctx *ctx, /* Discovery Descriptor List */ for (dd = entry->nbft->discovery_list; dd && *dd; dd++) { - _cleanup_uri_ struct nvme_fabrics_uri *uri = NULL; + _cleanup_uri_ struct libnvme_fabrics_uri *uri = NULL; _cleanup_free_ char *trsvcid = NULL; struct nvmf_context nfctx = *fctx; bool persistent = false; bool linked = false; - nvme_ctrl_t c; + libnvme_ctrl_t c; /* only perform discovery when no SSNS record references it */ for (ss = entry->nbft->subsystem_ns_list; @@ -2901,7 +2901,7 @@ __public int nvmf_discovery_nbft(struct nvme_global_ctx *ctx, continue; hfi = (*dd)->hfi; - ret = nvme_parse_uri((*dd)->uri, &uri); + ret = libnvme_parse_uri((*dd)->uri, &uri); if (ret) continue; if (!validate_uri(ctx, *dd, uri)) @@ -2930,7 +2930,7 @@ __public int nvmf_discovery_nbft(struct nvme_global_ctx *ctx, /* Lookup existing discovery controller */ c = lookup_ctrl(h, &nfctx); - if (c && nvme_ctrl_get_name(c)) + if (c && libnvme_ctrl_get_name(c)) persistent = true; if (!c) { @@ -2947,16 +2947,16 @@ __public int nvmf_discovery_nbft(struct nvme_global_ctx *ctx, ret = 0; if (ret) { - nvme_msg(ctx, LOG_ERR, + libnvme_msg(ctx, LOG_ERR, "Discovery Descriptor %d: failed to add discovery controller: %s\n", - (*dd)->index, nvme_strerror(-ret)); + (*dd)->index, libnvme_strerror(-ret)); goto out_free; } rr = nbft_discovery(ctx, &nfctx, *dd, h, c, fctx->cfg); if (!persistent) - nvme_disconnect_ctrl(c); - nvme_free_ctrl(c); + libnvme_disconnect_ctrl(c); + libnvme_free_ctrl(c); if (rr == -ENOMEM) { ret = rr; goto out_free; @@ -2968,11 +2968,11 @@ __public int nvmf_discovery_nbft(struct nvme_global_ctx *ctx, return ret; } -__public int nvmf_discovery(struct nvme_global_ctx *ctx, struct nvmf_context *fctx, +__public int nvmf_discovery(struct libnvme_global_ctx *ctx, struct nvmf_context *fctx, bool connect, bool force) { - struct nvme_ctrl *c = NULL; - struct nvme_host *h; + struct libnvme_ctrl *c = NULL; + struct libnvme_host *h; int ret; ret = lookup_host(ctx, fctx, &h); @@ -2984,22 +2984,22 @@ __public int nvmf_discovery(struct nvme_global_ctx *ctx, struct nvmf_context *fc return ret; if (fctx->device && !force) { - ret = nvme_scan_ctrl(ctx, fctx->device, &c); + ret = libnvme_scan_ctrl(ctx, fctx->device, &c); if (!ret) { /* Check if device matches command-line options */ - if (!_nvme_ctrl_match_config(c, fctx)) { - nvme_msg(ctx, LOG_ERR, + if (!_libnvme_ctrl_match_config(c, fctx)) { + libnvme_msg(ctx, LOG_ERR, "ctrl device %s found, ignoring non matching command-line options\n", fctx->device); } - if (!nvme_ctrl_get_discovery_ctrl(c)) { - nvme_msg( + if (!libnvme_ctrl_get_discovery_ctrl(c)) { + libnvme_msg( ctx, LOG_ERR, "ctrl device %s found, ignoring non discovery controller\n", fctx->device); - nvme_free_ctrl(c); + libnvme_free_ctrl(c); c = NULL; fctx->persistent = false; } else { @@ -3021,17 +3021,17 @@ __public int nvmf_discovery(struct nvme_global_ctx *ctx, struct nvmf_context *fc */ if (!fctx->host_traddr) fctx->host_traddr = (char *) - nvme_ctrl_get_host_traddr(c); + libnvme_ctrl_get_host_traddr(c); if (!fctx->host_iface) fctx->host_iface = (char *) - nvme_ctrl_get_host_iface(c); + libnvme_ctrl_get_host_iface(c); } } else { /* * No controller found, fall back to create one. * But that controller cannot be persistent. */ - nvme_msg(ctx, LOG_ERR, + libnvme_msg(ctx, LOG_ERR, "ctrl device %s not found%s\n", fctx->device, fctx->persistent ? ", ignoring --persistent" : ""); fctx->persistent = false; @@ -3048,25 +3048,25 @@ __public int nvmf_discovery(struct nvme_global_ctx *ctx, struct nvmf_context *fc ret = nvmf_create_discovery_ctrl(ctx, fctx, h, fctx->cfg, &c); if (ret) { if (ret != -ENVME_CONNECT_IGNORED) - nvme_msg(ctx, LOG_ERR, + libnvme_msg(ctx, LOG_ERR, "failed to add controller, error %s\n", - nvme_strerror(-ret)); + libnvme_strerror(-ret)); return ret; } } ret = _nvmf_discovery(ctx, fctx, connect, c); if (!(fctx->persistent || is_persistent_discovery_ctrl(h, c))) - nvme_disconnect_ctrl(c); - nvme_free_ctrl(c); + libnvme_disconnect_ctrl(c); + libnvme_free_ctrl(c); return ret; } -__public int nvmf_connect(struct nvme_global_ctx *ctx, struct nvmf_context *fctx) +__public int nvmf_connect(struct libnvme_global_ctx *ctx, struct nvmf_context *fctx) { - struct nvme_host *h; - struct nvme_ctrl *c; + struct libnvme_host *h; + struct libnvme_ctrl *c; int err; err = lookup_host(ctx, fctx, &h); @@ -3078,21 +3078,21 @@ __public int nvmf_connect(struct nvme_global_ctx *ctx, struct nvmf_context *fctx return err; c = lookup_ctrl(h, fctx); - if (c && nvme_ctrl_get_name(c) && !fctx->cfg->duplicate_connect) { - fctx->already_connected(fctx, h, nvme_ctrl_get_subsysnqn(c), - nvme_ctrl_get_transport(c), nvme_ctrl_get_traddr(c), - nvme_ctrl_get_trsvcid(c), fctx->user_data); + if (c && libnvme_ctrl_get_name(c) && !fctx->cfg->duplicate_connect) { + fctx->already_connected(fctx, h, libnvme_ctrl_get_subsysnqn(c), + libnvme_ctrl_get_transport(c), libnvme_ctrl_get_traddr(c), + libnvme_ctrl_get_trsvcid(c), fctx->user_data); return -EALREADY; } - err = _nvme_create_ctrl(ctx, fctx, &c); + err = _libnvme_create_ctrl(ctx, fctx, &c); if (err) return err; if (fctx->hostkey) { - nvme_ctrl_set_dhchap_host_key(c, fctx->hostkey); + libnvme_ctrl_set_dhchap_host_key(c, fctx->hostkey); if (fctx->ctrlkey) - nvme_ctrl_set_dhchap_ctrl_key(c, fctx->ctrlkey); + libnvme_ctrl_set_dhchap_ctrl_key(c, fctx->ctrlkey); } nvme_parse_tls_args(fctx->keyring, fctx->tls_key, @@ -3108,11 +3108,11 @@ __public int nvmf_connect(struct nvme_global_ctx *ctx, struct nvmf_context *fctx set_discovery_kato(fctx, fctx->cfg); } - err = nvme_add_ctrl(fctx, h, c, fctx->cfg); + err = libnvme_add_ctrl(fctx, h, c, fctx->cfg); if (err) { - nvme_msg(ctx, LOG_ERR, "could not add new controller: %s\n", - nvme_strerror(-err)); - nvme_free_ctrl(c); + libnvme_msg(ctx, LOG_ERR, "could not add new controller: %s\n", + libnvme_strerror(-err)); + libnvme_free_ctrl(c); return err; } diff --git a/libnvme/src/nvme/fabrics.h b/libnvme/src/nvme/fabrics.h index bba27ab036..1d934b2412 100644 --- a/libnvme/src/nvme/fabrics.h +++ b/libnvme/src/nvme/fabrics.h @@ -24,7 +24,7 @@ #define NVMF_DEF_CTRL_LOSS_TMO 600 /** - * struct nvme_fabrics_config - Defines all linux nvme fabrics initiator options + * struct libnvme_fabrics_config - Defines all linux nvme fabrics initiator options * @queue_size: Number of IO queue entries * @nr_io_queues: Number of controller IO queues to establish * @reconnect_delay: Time between two consecutive reconnect attempts. @@ -44,7 +44,7 @@ * @tls: Start TLS on the connection (TCP) * @concat: Enable secure concatenation (TCP) */ -struct nvme_fabrics_config { +struct libnvme_fabrics_config { int queue_size; int nr_io_queues; int reconnect_delay; @@ -67,7 +67,7 @@ struct nvme_fabrics_config { }; /** - * struct nvme_fabrics_uri - Parsed URI structure + * struct libnvme_fabrics_uri - Parsed URI structure * @scheme: Scheme name (typically 'nvme') * @protocol: Optional protocol/transport (e.g. 'tcp') * @userinfo: Optional user information component of the URI authority @@ -77,7 +77,7 @@ struct nvme_fabrics_config { * @query: Optional query string component (separated by '?') * @fragment: Optional fragment identifier component (separated by '#') */ -struct nvme_fabrics_uri { +struct libnvme_fabrics_uri { char *scheme; char *protocol; char *userinfo; @@ -193,7 +193,7 @@ const char *nvmf_cms_str(__u8 cms); * * Initializes @cfg with default values. */ -void nvmf_default_config(struct nvme_fabrics_config *cfg); +void nvmf_default_config(struct libnvme_fabrics_config *cfg); /** * nvmf_update_config() - Update fabrics configuration values @@ -203,7 +203,8 @@ void nvmf_default_config(struct nvme_fabrics_config *cfg); * Updates the values from @c with the configuration values from @cfg; * all non-default values from @cfg will overwrite the values in @c. */ -void nvmf_update_config(nvme_ctrl_t c, const struct nvme_fabrics_config *cfg); +void nvmf_update_config(libnvme_ctrl_t c, + const struct libnvme_fabrics_config *cfg); /** * nvmf_add_ctrl() - Connect a controller and update topology @@ -217,8 +218,8 @@ void nvmf_update_config(nvme_ctrl_t c, const struct nvme_fabrics_config *cfg); * * 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); +int nvmf_add_ctrl(libnvme_host_t h, libnvme_ctrl_t c, + const struct libnvme_fabrics_config *cfg); /** * nvmf_connect_ctrl() - Connect a controller @@ -229,7 +230,7 @@ int nvmf_add_ctrl(nvme_host_t h, nvme_ctrl_t c, * * Return: 0 on success, or an error code on failure. */ -int nvmf_connect_ctrl(nvme_ctrl_t c); +int nvmf_connect_ctrl(libnvme_ctrl_t c); /** * nvmf_get_discovery_log() - Return the discovery log page @@ -244,11 +245,11 @@ int nvmf_connect_ctrl(nvme_ctrl_t c); * * 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 nvmf_get_discovery_log(libnvme_ctrl_t c, struct nvmf_discovery_log **logp, int max_retries); /** - * struct nvme_get_discovery_args - Arguments for nvmf_get_discovery_wargs() + * struct libnvme_get_discovery_args - Arguments for nvmf_get_discovery_wargs() * @c: Discovery controller * @args_size: Length of the structure * @max_retries: Number of retries in case of failure @@ -256,8 +257,8 @@ int nvmf_get_discovery_log(nvme_ctrl_t c, struct nvmf_discovery_log **logp, * @timeout: Timeout in ms (default: NVME_DEFAULT_IOCTL_TIMEOUT) * @lsp: Log specific field (See enum nvmf_log_discovery_lsp) */ -struct nvme_get_discovery_args { - nvme_ctrl_t c; +struct libnvme_get_discovery_args { + libnvme_ctrl_t c; int args_size; int max_retries; __u32 *result; @@ -280,7 +281,7 @@ struct nvme_get_discovery_args { * * Return: 0 on success, or an error code on failure. */ -int nvmf_get_discovery_wargs(struct nvme_get_discovery_args *args, +int nvmf_get_discovery_wargs(struct libnvme_get_discovery_args *args, struct nvmf_discovery_log **log); /** @@ -296,7 +297,7 @@ int nvmf_get_discovery_wargs(struct nvme_get_discovery_args *args, * Return: true if controller supports explicit registration. false * otherwise. */ -bool nvmf_is_registration_supported(nvme_ctrl_t c); +bool nvmf_is_registration_supported(libnvme_ctrl_t c); /** * nvmf_register_ctrl() - Perform registration task with a DC @@ -311,10 +312,10 @@ bool nvmf_is_registration_supported(nvme_ctrl_t c); * * 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); +int nvmf_register_ctrl(libnvme_ctrl_t c, enum nvmf_dim_tas tas, __u32 *result); /** - * nvme_parse_uri() - Parse the URI string + * libnvme_parse_uri() - Parse the URI string * @str: URI string * @uri: URI object to return * @@ -323,18 +324,18 @@ int nvmf_register_ctrl(nvme_ctrl_t c, enum nvmf_dim_tas tas, __u32 *result); * * nvme+tcp://user@host:port/subsys_nqn/nid?query=val#fragment * - * Return: &nvme_fabrics_uri structure on success; NULL on failure with errno + * Return: &libnvme_fabrics_uri structure on success; NULL on failure with errno * set. */ -int nvme_parse_uri(const char *str, struct nvme_fabrics_uri **uri); +int libnvme_parse_uri(const char *str, struct libnvme_fabrics_uri **uri); /** * nvmf_free_uri() - Free the URI structure - * @uri: &nvme_fabrics_uri structure + * @uri: &libnvme_fabrics_uri structure * - * Free an &nvme_fabrics_uri structure. + * Free an &libnvme_fabrics_uri structure. */ -void nvmf_free_uri(struct nvme_fabrics_uri *uri); +void nvmf_free_uri(struct libnvme_fabrics_uri *uri); /** * nvmf_get_default_trsvcid() - Get default transport service ID @@ -370,13 +371,13 @@ struct nvmf_context; * * Return: 0 on success, or a negative error code on failure. */ -int nvmf_context_create(struct nvme_global_ctx *ctx, +int nvmf_context_create(struct libnvme_global_ctx *ctx, bool (*decide_retry)(struct nvmf_context *fctx, int err, void *user_data), void (*connected)(struct nvmf_context *fctx, - struct nvme_ctrl *c, void *user_data), + struct libnvme_ctrl *c, void *user_data), void (*already_connected)(struct nvmf_context *fctx, - struct nvme_host *host, const char *subsysnqn, + struct libnvme_host *host, const char *subsysnqn, const char *transport, const char *traddr, const char *trsvcid, void *user_data), void *user_data, struct nvmf_context **fctxp); @@ -438,7 +439,7 @@ int nvmf_context_set_discovery_defaults(struct nvmf_context *fctx, * Return: 0 on success, or a negative error code on failure. */ int nvmf_context_set_fabrics_config(struct nvmf_context *fctx, - struct nvme_fabrics_config *cfg); + struct libnvme_fabrics_config *cfg); /** * nvmf_context_set_connection() - Set connection parameters for context @@ -524,7 +525,7 @@ int nvmf_context_set_device(struct nvmf_context *fctx, const char *device); * * Return: 0 on success, or a negative error code on failure. */ -int nvmf_discovery(struct nvme_global_ctx *ctx, +int nvmf_discovery(struct libnvme_global_ctx *ctx, struct nvmf_context *fctx, bool connect, bool force); /** @@ -538,7 +539,7 @@ int nvmf_discovery(struct nvme_global_ctx *ctx, * * Return: 0 on success, or a negative error code on failure. */ -int nvmf_discovery_config_json(struct nvme_global_ctx *ctx, +int nvmf_discovery_config_json(struct libnvme_global_ctx *ctx, struct nvmf_context *fctx, bool connect, bool force); /** @@ -552,7 +553,7 @@ int nvmf_discovery_config_json(struct nvme_global_ctx *ctx, * * Return: 0 on success, or a negative error code on failure. */ -int nvmf_discovery_config_file(struct nvme_global_ctx *ctx, +int nvmf_discovery_config_file(struct libnvme_global_ctx *ctx, struct nvmf_context *fctx, bool connect, bool force); /** @@ -566,7 +567,7 @@ int nvmf_discovery_config_file(struct nvme_global_ctx *ctx, * * Return: 0 on success, or a negative error code on failure. */ -int nvmf_discovery_nbft(struct nvme_global_ctx *ctx, +int nvmf_discovery_nbft(struct libnvme_global_ctx *ctx, struct nvmf_context *fctx, bool connect, char *nbft_path); /** @@ -578,7 +579,7 @@ int nvmf_discovery_nbft(struct nvme_global_ctx *ctx, * * Return: 0 on success, or a negative error code on failure. */ -int nvmf_connect(struct nvme_global_ctx *ctx, struct nvmf_context *fctx); +int nvmf_connect(struct libnvme_global_ctx *ctx, struct nvmf_context *fctx); /** * nvmf_connect_config_json() - Connect using JSON config @@ -589,7 +590,7 @@ int nvmf_connect(struct nvme_global_ctx *ctx, struct nvmf_context *fctx); * * Return: 0 on success, or a negative error code on failure. */ -int nvmf_connect_config_json(struct nvme_global_ctx *ctx, +int nvmf_connect_config_json(struct libnvme_global_ctx *ctx, struct nvmf_context *fctx); /** @@ -602,14 +603,14 @@ int nvmf_connect_config_json(struct nvme_global_ctx *ctx, * * Return: 0 on success, or a negative error code on failure. */ -int nvmf_config_modify(struct nvme_global_ctx *ctx, +int nvmf_config_modify(struct libnvme_global_ctx *ctx, struct nvmf_context *fctx); struct nbft_file_entry; /** * nvmf_nbft_read_files() - Read NBFT files from path - * @ctx: struct nvme_global_ctx object + * @ctx: struct libnvme_global_ctx object * @path: Path to NBFT files * @head: Pointer to store linked list of NBFT file entries * @@ -617,16 +618,17 @@ struct nbft_file_entry; * * Return: 0 on success, or a negative error code on failure. */ -int nvmf_nbft_read_files(struct nvme_global_ctx *ctx, char *path, +int nvmf_nbft_read_files(struct libnvme_global_ctx *ctx, char *path, struct nbft_file_entry **head); /** * nvmf_nbft_free() - Free NBFT file entry list - * @ctx: struct nvme_global_ctx object + * @ctx: struct libnvme_global_ctx object * @head: Head of the NBFT file entry list * * Frees all memory associated with the NBFT file entry list. */ -void nvmf_nbft_free(struct nvme_global_ctx *ctx, struct nbft_file_entry *head); +void nvmf_nbft_free(struct libnvme_global_ctx *ctx, + struct nbft_file_entry *head); #endif /* _LIBNVME_FABRICS_H */ diff --git a/libnvme/src/nvme/filters.c b/libnvme/src/nvme/filters.c index e960420821..f18a6e3e1c 100644 --- a/libnvme/src/nvme/filters.c +++ b/libnvme/src/nvme/filters.c @@ -15,7 +15,7 @@ #include "private.h" #include "compiler_attributes.h" -__public int nvme_filter_namespace(const struct dirent *d) +__public int libnvme_filter_namespace(const struct dirent *d) { int i, n; @@ -29,7 +29,7 @@ __public int nvme_filter_namespace(const struct dirent *d) return 0; } -__public int nvme_filter_paths(const struct dirent *d) +__public int libnvme_filter_paths(const struct dirent *d) { int i, c, n; @@ -43,7 +43,7 @@ __public int nvme_filter_paths(const struct dirent *d) return 0; } -__public int nvme_filter_ctrls(const struct dirent *d) +__public int libnvme_filter_ctrls(const struct dirent *d) { int i, c, n; @@ -62,7 +62,7 @@ __public int nvme_filter_ctrls(const struct dirent *d) return 0; } -__public int nvme_filter_subsys(const struct dirent *d) +__public int libnvme_filter_subsys(const struct dirent *d) { int i; @@ -76,72 +76,75 @@ __public int nvme_filter_subsys(const struct dirent *d) return 0; } -__public int nvme_scan_subsystems(struct dirent ***subsys) +__public int libnvme_scan_subsystems(struct dirent ***subsys) { - const char *dir = nvme_subsys_sysfs_dir(); + const char *dir = libnvme_subsys_sysfs_dir(); int ret; - ret = scandir(dir, subsys, nvme_filter_subsys, alphasort); + ret = scandir(dir, subsys, libnvme_filter_subsys, alphasort); if (ret < 0) return -errno; return ret; } -__public int nvme_scan_subsystem_namespaces(nvme_subsystem_t s, struct dirent ***ns) +__public int libnvme_scan_subsystem_namespaces(libnvme_subsystem_t s, + struct dirent ***ns) { int ret; - ret = scandir(nvme_subsystem_get_sysfs_dir(s), ns, - nvme_filter_namespace, alphasort); + ret = scandir(libnvme_subsystem_get_sysfs_dir(s), ns, + libnvme_filter_namespace, alphasort); if (ret < 0) return -errno; return ret; } -__public int nvme_scan_ctrls(struct dirent ***ctrls) +__public int libnvme_scan_ctrls(struct dirent ***ctrls) { - const char *dir = nvme_ctrl_sysfs_dir(); + const char *dir = libnvme_ctrl_sysfs_dir(); int ret; - ret = scandir(dir, ctrls, nvme_filter_ctrls, alphasort); + ret = scandir(dir, ctrls, libnvme_filter_ctrls, alphasort); if (ret < 0) return -errno; return ret; } -__public int nvme_scan_ctrl_namespace_paths(nvme_ctrl_t c, struct dirent ***paths) +__public int libnvme_scan_ctrl_namespace_paths(libnvme_ctrl_t c, + struct dirent ***paths) { int ret; - ret = scandir(nvme_ctrl_get_sysfs_dir(c), paths, - nvme_filter_paths, alphasort); + ret = scandir(libnvme_ctrl_get_sysfs_dir(c), paths, + libnvme_filter_paths, alphasort); if (ret < 0) return -errno; return ret; } -__public int nvme_scan_ctrl_namespaces(nvme_ctrl_t c, struct dirent ***ns) +__public int libnvme_scan_ctrl_namespaces(libnvme_ctrl_t c, struct dirent ***ns) { int ret; - ret = scandir(nvme_ctrl_get_sysfs_dir(c), ns, - nvme_filter_namespace, alphasort); + ret = scandir(libnvme_ctrl_get_sysfs_dir(c), ns, + libnvme_filter_namespace, alphasort); if (ret < 0) return -errno; return ret; } -int nvme_scan_ns_head_paths(nvme_ns_head_t head, struct dirent ***paths) +__public int libnvme_scan_ns_head_paths(libnvme_ns_head_t head, + struct dirent ***paths) { int ret; - ret = scandir(nvme_ns_head_get_sysfs_dir(head), paths, - nvme_filter_paths, alphasort); + ret = scandir(libnvme_ns_head_get_sysfs_dir(head), paths, + libnvme_filter_paths, alphasort); if (ret < 0) return -errno; diff --git a/libnvme/src/nvme/filters.h b/libnvme/src/nvme/filters.h index 05fd02a6f6..f0a76a3b44 100644 --- a/libnvme/src/nvme/filters.h +++ b/libnvme/src/nvme/filters.h @@ -20,87 +20,89 @@ */ /** - * nvme_filter_namespace() - Filter for namespaces + * libnvme_filter_namespace() - Filter for namespaces * @d: dirent to check * * Return: 1 if @d matches, 0 otherwise */ -int nvme_filter_namespace(const struct dirent *d); +int libnvme_filter_namespace(const struct dirent *d); /** - * nvme_filter_paths() - Filter for paths + * libnvme_filter_paths() - Filter for paths * @d: dirent to check * * Return: 1 if @d matches, 0 otherwise */ -int nvme_filter_paths(const struct dirent *d); +int libnvme_filter_paths(const struct dirent *d); /** - * nvme_filter_ctrls() - Filter for controllers + * libnvme_filter_ctrls() - Filter for controllers * @d: dirent to check * * Return: 1 if @d matches, 0 otherwise */ -int nvme_filter_ctrls(const struct dirent *d); +int libnvme_filter_ctrls(const struct dirent *d); /** - * nvme_filter_subsys() - Filter for subsystems + * libnvme_filter_subsys() - Filter for subsystems * @d: dirent to check * * Return: 1 if @d matches, 0 otherwise */ -int nvme_filter_subsys(const struct dirent *d); +int libnvme_filter_subsys(const struct dirent *d); /** - * nvme_scan_subsystems() - Scan for subsystems + * libnvme_scan_subsystems() - Scan for subsystems * @subsys: Pointer to array of dirents * * Return: number of entries in @subsys or a negative error code */ -int nvme_scan_subsystems(struct dirent ***subsys); +int libnvme_scan_subsystems(struct dirent ***subsys); /** - * nvme_scan_subsystem_namespaces() - Scan for namespaces in a subsystem + * libnvme_scan_subsystem_namespaces() - Scan for namespaces in a subsystem * @s: Subsystem to scan * @ns: Pointer to array of dirents * * Return: number of entries in @ns or a negative error code */ -int nvme_scan_subsystem_namespaces(nvme_subsystem_t s, struct dirent ***ns); +int libnvme_scan_subsystem_namespaces(libnvme_subsystem_t s, + struct dirent ***ns); /** - * nvme_scan_ctrls() - Scan for controllers + * libnvme_scan_ctrls() - Scan for controllers * @ctrls: Pointer to array of dirents * * Return: number of entries in @ctrls or a negative error code */ -int nvme_scan_ctrls(struct dirent ***ctrls); +int libnvme_scan_ctrls(struct dirent ***ctrls); /** - * nvme_scan_ctrl_namespace_paths() - Scan for namespace paths in a controller + * libnvme_scan_ctrl_namespace_paths() - Scan for namespace paths in + * a controller * @c: Controller to scan * @paths: Pointer to array of dirents * * Return: number of entries in @paths or a negative error code */ -int nvme_scan_ctrl_namespace_paths(nvme_ctrl_t c, struct dirent ***paths); +int libnvme_scan_ctrl_namespace_paths(libnvme_ctrl_t c, struct dirent ***paths); /** - * nvme_scan_ctrl_namespaces() - Scan for namespaces in a controller + * libnvme_scan_ctrl_namespaces() - Scan for namespaces in a controller * @c: Controller to scan * @ns: Pointer to array of dirents * * Return: number of entries in @ns or a negative error code */ -int nvme_scan_ctrl_namespaces(nvme_ctrl_t c, struct dirent ***ns); +int libnvme_scan_ctrl_namespaces(libnvme_ctrl_t c, struct dirent ***ns); /** - * nvme_scan_ns_head_paths() - Scan for namespace paths + * libnvme_scan_ns_head_paths() - Scan for namespace paths * @head: Namespace head node to scan * @paths : Pointer to array of dirents * * Return: number of entries in @ents or a negative error code */ -int nvme_scan_ns_head_paths(nvme_ns_head_t head, struct dirent ***paths); +int libnvme_scan_ns_head_paths(libnvme_ns_head_t head, struct dirent ***paths); #endif /* _LIBNVME_FILTERS_H */ diff --git a/libnvme/src/nvme/ioctl.c b/libnvme/src/nvme/ioctl.c index 85f401b940..53ee19ac91 100644 --- a/libnvme/src/nvme/ioctl.c +++ b/libnvme/src/nvme/ioctl.c @@ -25,7 +25,7 @@ #include "private.h" #include "compiler_attributes.h" -static int nvme_verify_chr(struct nvme_transport_handle *hdl) +static int nvme_verify_chr(struct libnvme_transport_handle *hdl) { static struct stat nvme_stat; int err = fstat(hdl->fd, &nvme_stat); @@ -38,7 +38,7 @@ static int nvme_verify_chr(struct nvme_transport_handle *hdl) return 0; } -__public int nvme_reset_subsystem(struct nvme_transport_handle *hdl) +__public int libnvme_reset_subsystem(struct libnvme_transport_handle *hdl) { int ret; @@ -46,13 +46,13 @@ __public int nvme_reset_subsystem(struct nvme_transport_handle *hdl) if (ret) return ret; - ret = ioctl(hdl->fd, NVME_IOCTL_SUBSYS_RESET); + ret = ioctl(hdl->fd, LIBNVME_IOCTL_SUBSYS_RESET); if (ret < 0) return -errno; return ret; } -__public int nvme_reset_ctrl(struct nvme_transport_handle *hdl) +__public int libnvme_reset_ctrl(struct libnvme_transport_handle *hdl) { int ret; @@ -60,13 +60,13 @@ __public int nvme_reset_ctrl(struct nvme_transport_handle *hdl) if (ret) return ret; - ret = ioctl(hdl->fd, NVME_IOCTL_RESET); + ret = ioctl(hdl->fd, LIBNVME_IOCTL_RESET); if (ret < 0) return -errno; return ret; } -__public int nvme_rescan_ns(struct nvme_transport_handle *hdl) +__public int libnvme_rescan_ns(struct libnvme_transport_handle *hdl) { int ret; @@ -74,18 +74,18 @@ __public int nvme_rescan_ns(struct nvme_transport_handle *hdl) if (ret) return ret; - ret = ioctl(hdl->fd, NVME_IOCTL_RESCAN); + ret = ioctl(hdl->fd, LIBNVME_IOCTL_RESCAN); if (ret < 0) return -errno; return ret; } -__public int nvme_get_nsid(struct nvme_transport_handle *hdl, __u32 *nsid) +__public int libnvme_get_nsid(struct libnvme_transport_handle *hdl, __u32 *nsid) { __u32 tmp; errno = 0; - tmp = ioctl(hdl->fd, NVME_IOCTL_ID); + tmp = ioctl(hdl->fd, LIBNVME_IOCTL_ID); if (errno) return -errno; @@ -93,19 +93,19 @@ __public int nvme_get_nsid(struct nvme_transport_handle *hdl, __u32 *nsid) return 0; } -void *__nvme_submit_entry(struct nvme_transport_handle *hdl, - struct nvme_passthru_cmd *cmd) +void *__libnvme_submit_entry(struct libnvme_transport_handle *hdl, + struct libnvme_passthru_cmd *cmd) { return NULL; } -void __nvme_submit_exit(struct nvme_transport_handle *hdl, - struct nvme_passthru_cmd *cmd, int err, void *user_data) +void __libnvme_submit_exit(struct libnvme_transport_handle *hdl, + struct libnvme_passthru_cmd *cmd, int err, void *user_data) { } -bool __nvme_decide_retry(struct nvme_transport_handle *hdl, - struct nvme_passthru_cmd *cmd, int err) +bool __libnvme_decide_retry(struct libnvme_transport_handle *hdl, + struct libnvme_passthru_cmd *cmd, int err) { return false; } @@ -114,8 +114,8 @@ bool __nvme_decide_retry(struct nvme_transport_handle *hdl, * The 64 bit version is the preferred version to use, but for backwards * compatibility keep a 32 version. */ -static int nvme_submit_passthru32(struct nvme_transport_handle *hdl, - unsigned long ioctl_cmd, struct nvme_passthru_cmd *cmd) +static int libnvme_submit_passthru32(struct libnvme_transport_handle *hdl, + unsigned long ioctl_cmd, struct libnvme_passthru_cmd *cmd) { struct linux_passthru_cmd32 cmd32; void *user_data; @@ -145,8 +145,8 @@ static int nvme_submit_passthru32(struct nvme_transport_handle *hdl, * supported since kernel 5.4, see * 65e68edce0db ("nvme: allow 64-bit results in passthru commands") */ -static int nvme_submit_passthru64(struct nvme_transport_handle *hdl, - unsigned long ioctl_cmd, struct nvme_passthru_cmd *cmd) +static int libnvme_submit_passthru64(struct libnvme_transport_handle *hdl, + unsigned long ioctl_cmd, struct libnvme_passthru_cmd *cmd) { void *user_data; int err = 0; @@ -171,28 +171,29 @@ static int nvme_submit_passthru64(struct nvme_transport_handle *hdl, return err; } -__public int nvme_submit_io_passthru(struct nvme_transport_handle *hdl, - struct nvme_passthru_cmd *cmd) +__public int libnvme_submit_io_passthru(struct libnvme_transport_handle *hdl, + struct libnvme_passthru_cmd *cmd) { if (hdl->ioctl_io64) - return nvme_submit_passthru64(hdl, NVME_IOCTL_IO64_CMD, cmd); - return nvme_submit_passthru32(hdl, NVME_IOCTL_IO_CMD, cmd); + return libnvme_submit_passthru64(hdl, + LIBNVME_IOCTL_IO64_CMD, cmd); + return libnvme_submit_passthru32(hdl, LIBNVME_IOCTL_IO_CMD, cmd); } -__public int nvme_submit_admin_passthru(struct nvme_transport_handle *hdl, - struct nvme_passthru_cmd *cmd) +__public int libnvme_submit_admin_passthru(struct libnvme_transport_handle *hdl, + struct libnvme_passthru_cmd *cmd) { switch (hdl->type) { - case NVME_TRANSPORT_HANDLE_TYPE_DIRECT: + case LIBNVME_TRANSPORT_HANDLE_TYPE_DIRECT: if (hdl->ioctl_admin64) - return nvme_submit_passthru64(hdl, - NVME_IOCTL_ADMIN64_CMD, cmd); + return libnvme_submit_passthru64(hdl, + LIBNVME_IOCTL_ADMIN64_CMD, cmd); if (cmd->opcode == nvme_admin_fabrics) return -ENOTSUP; - return nvme_submit_passthru32(hdl, - NVME_IOCTL_ADMIN_CMD, cmd); - case NVME_TRANSPORT_HANDLE_TYPE_MI: - return nvme_mi_admin_admin_passthru(hdl, cmd); + return libnvme_submit_passthru32(hdl, + LIBNVME_IOCTL_ADMIN_CMD, cmd); + case LIBNVME_TRANSPORT_HANDLE_TYPE_MI: + return libnvme_mi_admin_admin_passthru(hdl, cmd); default: break; } diff --git a/libnvme/src/nvme/ioctl.h b/libnvme/src/nvme/ioctl.h index 197c94cd4b..7284ba39f8 100644 --- a/libnvme/src/nvme/ioctl.h +++ b/libnvme/src/nvme/ioctl.h @@ -27,33 +27,33 @@ #define NVME_LOG_PAGE_PDU_SIZE 4096 /** - * nvme_submit_admin_passthru() - Submit an nvme passthrough admin command + * libnvme_submit_admin_passthru() - Submit an nvme passthrough admin command * @hdl: Transport handle * @cmd: The nvme admin command to send * - * Uses NVME_IOCTL_ADMIN_CMD for the ioctl request. + * Uses LIBNVME_IOCTL_ADMIN_CMD for the ioctl request. * * 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(struct nvme_transport_handle *hdl, - struct nvme_passthru_cmd *cmd); +int libnvme_submit_admin_passthru(struct libnvme_transport_handle *hdl, + struct libnvme_passthru_cmd *cmd); /** - * nvme_submit_io_passthru() - Submit an nvme passthrough command + * libnvme_submit_io_passthru() - Submit an nvme passthrough command * @hdl: Transport handle * @cmd: The nvme io command to send * - * Uses NVME_IOCTL_IO_CMD for the ioctl request. + * Uses LIBNVME_IOCTL_IO_CMD for the ioctl request. * * 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(struct nvme_transport_handle *hdl, - struct nvme_passthru_cmd *cmd); +int libnvme_submit_io_passthru(struct libnvme_transport_handle *hdl, + struct libnvme_passthru_cmd *cmd); /** - * nvme_reset_subsystem() - Initiate a subsystem reset + * libnvme_reset_subsystem() - Initiate a subsystem reset * @hdl: Transport handle * * This should only be sent to controller handles, not to namespaces. @@ -61,30 +61,30 @@ int nvme_submit_io_passthru(struct nvme_transport_handle *hdl, * Return: Zero if a subsystem reset was initiated or -1 with errno set * otherwise. */ -int nvme_reset_subsystem(struct nvme_transport_handle *hdl); +int libnvme_reset_subsystem(struct libnvme_transport_handle *hdl); /** - * nvme_reset_ctrl() - Initiate a controller reset + * libnvme_reset_ctrl() - Initiate a controller reset * @hdl: Transport 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_reset_ctrl(struct nvme_transport_handle *hdl); +int libnvme_reset_ctrl(struct libnvme_transport_handle *hdl); /** - * nvme_rescan_ns() - Initiate a controller rescan + * libnvme_rescan_ns() - Initiate a controller rescan * @hdl: Transport 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_rescan_ns(struct nvme_transport_handle *hdl); +int libnvme_rescan_ns(struct libnvme_transport_handle *hdl); /** - * nvme_get_nsid() - Retrieve the NSID from a namespace file descriptor + * libnvme_get_nsid() - Retrieve the NSID from a namespace file descriptor * @hdl: Transport handle * @nsid: User pointer to namespace id * @@ -95,4 +95,4 @@ int nvme_rescan_ns(struct nvme_transport_handle *hdl); * * Return: 0 if @nsid was set successfully or -1 with errno set otherwise. */ -int nvme_get_nsid(struct nvme_transport_handle *hdl, __u32 *nsid); +int libnvme_get_nsid(struct libnvme_transport_handle *hdl, __u32 *nsid); diff --git a/libnvme/src/nvme/json.c b/libnvme/src/nvme/json.c index f42f3a26e2..cd81545308 100644 --- a/libnvme/src/nvme/json.c +++ b/libnvme/src/nvme/json.c @@ -22,10 +22,10 @@ #define JSON_UPDATE_BOOL_OPTION(c, k, a, o) \ if (!strcmp(# a, k ) && !c->a) c->a = json_object_get_boolean(o); -static void json_update_attributes(nvme_ctrl_t c, +static void json_update_attributes(libnvme_ctrl_t c, struct json_object *ctrl_obj) { - struct nvme_fabrics_config *cfg = nvme_ctrl_get_config(c); + struct libnvme_fabrics_config *cfg = libnvme_ctrl_get_config(c); json_object_object_foreach(ctrl_obj, key_str, val_obj) { JSON_UPDATE_INT_OPTION(cfg, key_str, @@ -60,28 +60,28 @@ static void json_update_attributes(nvme_ctrl_t c, JSON_UPDATE_BOOL_OPTION(cfg, key_str, concat, val_obj); if (!strcmp("persistent", key_str) && - !nvme_ctrl_get_persistent(c)) - nvme_ctrl_set_persistent(c, true); + !libnvme_ctrl_get_persistent(c)) + libnvme_ctrl_set_persistent(c, true); if (!strcmp("discovery", key_str) && - !nvme_ctrl_get_discovery_ctrl(c)) - nvme_ctrl_set_discovery_ctrl(c, true); + !libnvme_ctrl_get_discovery_ctrl(c)) + libnvme_ctrl_set_discovery_ctrl(c, true); if (!strcmp("keyring", key_str)) - nvme_ctrl_set_keyring(c, + libnvme_ctrl_set_keyring(c, json_object_get_string(val_obj)); if (!strcmp("tls_key_identity", key_str)) { - nvme_ctrl_set_tls_key_identity(c, + libnvme_ctrl_set_tls_key_identity(c, json_object_get_string(val_obj)); } if (!strcmp("tls_key", key_str)) { - nvme_ctrl_set_tls_key(c, + libnvme_ctrl_set_tls_key(c, json_object_get_string(val_obj)); } } } -static void json_parse_port(nvme_subsystem_t s, struct json_object *port_obj) +static void json_parse_port(libnvme_subsystem_t s, struct json_object *port_obj) { - nvme_ctrl_t c; + libnvme_ctrl_t c; struct json_object *attr_obj; struct nvmf_context fctx = {}; @@ -101,35 +101,35 @@ static void json_parse_port(nvme_subsystem_t s, struct json_object *port_obj) attr_obj = json_object_object_get(port_obj, "trsvcid"); if (attr_obj) fctx.trsvcid = json_object_get_string(attr_obj); - c = nvme_lookup_ctrl(s, &fctx, NULL); + c = libnvme_lookup_ctrl(s, &fctx, NULL); if (!c) return; json_update_attributes(c, port_obj); attr_obj = json_object_object_get(port_obj, "dhchap_key"); if (attr_obj) - nvme_ctrl_set_dhchap_host_key(c, json_object_get_string(attr_obj)); + libnvme_ctrl_set_dhchap_host_key(c, json_object_get_string(attr_obj)); attr_obj = json_object_object_get(port_obj, "dhchap_ctrl_key"); if (attr_obj) - nvme_ctrl_set_dhchap_ctrl_key(c, json_object_get_string(attr_obj)); + libnvme_ctrl_set_dhchap_ctrl_key(c, json_object_get_string(attr_obj)); attr_obj = json_object_object_get(port_obj, "keyring"); if (attr_obj) - nvme_ctrl_set_keyring(c, json_object_get_string(attr_obj)); + libnvme_ctrl_set_keyring(c, json_object_get_string(attr_obj)); attr_obj = json_object_object_get(port_obj, "tls_key_identity"); if (attr_obj) { - nvme_ctrl_set_tls_key_identity(c, + libnvme_ctrl_set_tls_key_identity(c, json_object_get_string(attr_obj)); } attr_obj = json_object_object_get(port_obj, "tls_key"); if (attr_obj) { - nvme_ctrl_set_tls_key(c, + libnvme_ctrl_set_tls_key(c, json_object_get_string(attr_obj)); } } -static void json_parse_subsys(nvme_host_t h, struct json_object *subsys_obj) +static void json_parse_subsys(libnvme_host_t h, struct json_object *subsys_obj) { struct json_object *nqn_obj, *app_obj, *port_array; - nvme_subsystem_t s; + libnvme_subsystem_t s; const char *nqn; int p; @@ -137,12 +137,12 @@ static void json_parse_subsys(nvme_host_t h, struct json_object *subsys_obj) if (!nqn_obj) return; nqn = json_object_get_string(nqn_obj); - s = nvme_lookup_subsystem(h, NULL, nqn); + s = libnvme_lookup_subsystem(h, NULL, nqn); if (!s) return; app_obj = json_object_object_get(subsys_obj, "application"); if (app_obj) - nvme_subsystem_set_application(s, json_object_get_string(app_obj)); + libnvme_subsystem_set_application(s, json_object_get_string(app_obj)); port_array = json_object_object_get(subsys_obj, "ports"); if (!port_array) @@ -156,10 +156,10 @@ static void json_parse_subsys(nvme_host_t h, struct json_object *subsys_obj) } } -static void json_parse_host(struct nvme_global_ctx *ctx, struct json_object *host_obj) +static void json_parse_host(struct libnvme_global_ctx *ctx, struct json_object *host_obj) { struct json_object *attr_obj, *subsys_array, *subsys_obj; - nvme_host_t h; + libnvme_host_t h; const char *hostnqn, *hostid = NULL; int s; @@ -170,16 +170,16 @@ static void json_parse_host(struct nvme_global_ctx *ctx, struct json_object *hos attr_obj = json_object_object_get(host_obj, "hostid"); if (attr_obj) hostid = json_object_get_string(attr_obj); - h = nvme_lookup_host(ctx, hostnqn, hostid); + h = libnvme_lookup_host(ctx, hostnqn, hostid); attr_obj = json_object_object_get(host_obj, "dhchap_key"); if (attr_obj) - nvme_host_set_dhchap_host_key(h, json_object_get_string(attr_obj)); + libnvme_host_set_dhchap_host_key(h, json_object_get_string(attr_obj)); attr_obj = json_object_object_get(host_obj, "hostsymname"); if (attr_obj) - nvme_host_set_hostsymname(h, json_object_get_string(attr_obj)); + libnvme_host_set_hostsymname(h, json_object_get_string(attr_obj)); attr_obj = json_object_object_get(host_obj, "persistent_discovery_ctrl"); if (attr_obj) - nvme_host_set_pdc_enabled(h, json_object_get_boolean(attr_obj)); + libnvme_host_set_pdc_enabled(h, json_object_get_boolean(attr_obj)); subsys_array = json_object_object_get(host_obj, "subsystems"); if (!subsys_array) return; @@ -193,7 +193,7 @@ static void json_parse_host(struct nvme_global_ctx *ctx, struct json_object *hos static DEFINE_CLEANUP_FUNC(cleanup_tokener, json_tokener *, json_tokener_free) #define _cleanup_tokener_ __cleanup__(cleanup_tokener) -static struct json_object *parse_json(struct nvme_global_ctx *ctx, int fd) +static struct json_object *parse_json(struct libnvme_global_ctx *ctx, int fd) { char buf[JSON_FILE_BUF_SIZE]; struct json_object *obj; @@ -224,21 +224,21 @@ static struct json_object *parse_json(struct nvme_global_ctx *ctx, int fd) obj = json_tokener_parse_ex(tok, str, len); if (!obj) - nvme_msg(ctx, LOG_DEBUG, "JSON parsing failed: %s\n", + libnvme_msg(ctx, LOG_DEBUG, "JSON parsing failed: %s\n", json_util_get_last_err()); return obj; } -int json_read_config(struct nvme_global_ctx *ctx, const char *config_file) +int json_read_config(struct libnvme_global_ctx *ctx, const char *config_file) { struct json_object *json_root, *host_obj; int fd, h; fd = open(config_file, O_RDONLY); if (fd < 0) { - nvme_msg(ctx, LOG_DEBUG, "Error opening %s, %s\n", - config_file, nvme_strerror(errno)); + libnvme_msg(ctx, LOG_DEBUG, "Error opening %s, %s\n", + config_file, libnvme_strerror(errno)); return fd; } json_root = parse_json(ctx, fd); @@ -246,7 +246,7 @@ int json_read_config(struct nvme_global_ctx *ctx, const char *config_file) if (!json_root) return -EPROTO; if (!json_object_is_type(json_root, json_type_array)) { - nvme_msg(ctx, LOG_DEBUG, "Wrong format, expected array\n"); + libnvme_msg(ctx, LOG_DEBUG, "Wrong format, expected array\n"); json_object_put(json_root); return -EPROTO; } @@ -272,13 +272,13 @@ int json_read_config(struct nvme_global_ctx *ctx, const char *config_file) json_object_object_add((p), # o , \ json_object_new_boolean((c)->o)) -static void json_update_port(struct json_object *ctrl_array, nvme_ctrl_t c) +static void json_update_port(struct json_object *ctrl_array, libnvme_ctrl_t c) { - struct nvme_fabrics_config *cfg = nvme_ctrl_get_config(c); + struct libnvme_fabrics_config *cfg = libnvme_ctrl_get_config(c); struct json_object *port_obj = json_object_new_object(); const char *transport, *value; - transport = nvme_ctrl_get_transport(c); + transport = libnvme_ctrl_get_transport(c); if (!strcmp(transport, "pcie")) { json_object_put(port_obj); return; @@ -286,40 +286,40 @@ static void json_update_port(struct json_object *ctrl_array, nvme_ctrl_t c) json_object_object_add(port_obj, "transport", json_object_new_string(transport)); - value = nvme_ctrl_get_traddr(c); + value = libnvme_ctrl_get_traddr(c); if (value) json_object_object_add(port_obj, "traddr", json_object_new_string(value)); - value = nvme_ctrl_get_host_traddr(c); + value = libnvme_ctrl_get_host_traddr(c); if (value) json_object_object_add(port_obj, "host_traddr", json_object_new_string(value)); - value = nvme_ctrl_get_host_iface(c); + value = libnvme_ctrl_get_host_iface(c); if (value) json_object_object_add(port_obj, "host_iface", json_object_new_string(value)); - value = nvme_ctrl_get_trsvcid(c); + value = libnvme_ctrl_get_trsvcid(c); if (value) json_object_object_add(port_obj, "trsvcid", json_object_new_string(value)); - value = nvme_ctrl_get_dhchap_host_key(c); + value = libnvme_ctrl_get_dhchap_host_key(c); if (value) json_object_object_add(port_obj, "dhchap_key", json_object_new_string(value)); - value = nvme_ctrl_get_dhchap_ctrl_key(c); + value = libnvme_ctrl_get_dhchap_ctrl_key(c); if (value) json_object_object_add(port_obj, "dhchap_ctrl_key", json_object_new_string(value)); JSON_BOOL_OPTION(cfg, port_obj, tls); - value = nvme_ctrl_get_keyring(c); + value = libnvme_ctrl_get_keyring(c); if (value) json_object_object_add(port_obj, "keyring", json_object_new_string(value)); - value = nvme_ctrl_get_tls_key_identity(c); + value = libnvme_ctrl_get_tls_key_identity(c); if (value) json_object_object_add(port_obj, "tls_key_identity", json_object_new_string(value)); - value = nvme_ctrl_get_tls_key(c); + value = libnvme_ctrl_get_tls_key(c); if (value) json_object_object_add(port_obj, "tls_key", json_object_new_string(value)); @@ -340,10 +340,10 @@ static void json_update_port(struct json_object *ctrl_array, nvme_ctrl_t c) JSON_BOOL_OPTION(cfg, port_obj, hdr_digest); JSON_BOOL_OPTION(cfg, port_obj, data_digest); JSON_BOOL_OPTION(cfg, port_obj, concat); - if (nvme_ctrl_get_persistent(c)) + if (libnvme_ctrl_get_persistent(c)) json_object_object_add(port_obj, "persistent", json_object_new_boolean(true)); - if (nvme_ctrl_get_discovery_ctrl(c)) + if (libnvme_ctrl_get_discovery_ctrl(c)) json_object_object_add(port_obj, "discovery", json_object_new_boolean(true)); @@ -351,10 +351,10 @@ static void json_update_port(struct json_object *ctrl_array, nvme_ctrl_t c) } static void json_update_subsys(struct json_object *subsys_array, - nvme_subsystem_t s) + libnvme_subsystem_t s) { - nvme_ctrl_t c; - const char *subsysnqn = nvme_subsystem_get_subsysnqn(s), *app; + libnvme_ctrl_t c; + const char *subsysnqn = libnvme_subsystem_get_subsysnqn(s), *app; struct json_object *subsys_obj = json_object_new_object(); struct json_object *port_array; @@ -364,12 +364,12 @@ static void json_update_subsys(struct json_object *subsys_array, json_object_object_add(subsys_obj, "nqn", json_object_new_string(subsysnqn)); - app = nvme_subsystem_get_application(s); + app = libnvme_subsystem_get_application(s); if (app) json_object_object_add(subsys_obj, "application", json_object_new_string(app)); port_array = json_object_new_array(); - nvme_subsystem_for_each_ctrl(s, c) { + libnvme_subsystem_for_each_ctrl(s, c) { json_update_port(port_array, c); } if (json_object_array_length(port_array)) { @@ -381,33 +381,33 @@ static void json_update_subsys(struct json_object *subsys_array, } } -int json_update_config(struct nvme_global_ctx *ctx, int fd) +int json_update_config(struct libnvme_global_ctx *ctx, int fd) { - nvme_host_t h; + libnvme_host_t h; struct json_object *json_root, *host_obj; struct json_object *subsys_array; int ret = 0; json_root = json_object_new_array(); - nvme_for_each_host(ctx, h) { - nvme_subsystem_t s; + libnvme_for_each_host(ctx, h) { + libnvme_subsystem_t s; const char *hostnqn, *hostid, *dhchap_key, *hostsymname; host_obj = json_object_new_object(); if (!host_obj) continue; - hostnqn = nvme_host_get_hostnqn(h); + hostnqn = libnvme_host_get_hostnqn(h); json_object_object_add(host_obj, "hostnqn", json_object_new_string(hostnqn)); - hostid = nvme_host_get_hostid(h); + hostid = libnvme_host_get_hostid(h); if (hostid) json_object_object_add(host_obj, "hostid", json_object_new_string(hostid)); - dhchap_key = nvme_host_get_dhchap_host_key(h); + dhchap_key = libnvme_host_get_dhchap_host_key(h); if (dhchap_key) json_object_object_add(host_obj, "dhchap_key", json_object_new_string(dhchap_key)); - hostsymname = nvme_host_get_hostsymname(h); + hostsymname = libnvme_host_get_hostsymname(h); if (hostsymname) json_object_object_add(host_obj, "hostsymname", json_object_new_string(hostsymname)); @@ -415,7 +415,7 @@ int json_update_config(struct nvme_global_ctx *ctx, int fd) json_object_object_add(host_obj, "persistent_discovery_ctrl", json_object_new_boolean(h->pdc_enabled)); subsys_array = json_object_new_array(); - nvme_for_each_subsystem(h, s) { + libnvme_for_each_subsystem(h, s) { json_update_subsys(subsys_array, s); } if (json_object_array_length(subsys_array)) { @@ -431,7 +431,7 @@ int json_update_config(struct nvme_global_ctx *ctx, int fd) JSON_C_TO_STRING_PRETTY | JSON_C_TO_STRING_NOSLASHESCAPE); if (ret < 0 || write(fd, "\n", 1) < 0) { - nvme_msg(ctx, LOG_ERR, "Failed to write JSON config file: %s\n", + libnvme_msg(ctx, LOG_ERR, "Failed to write JSON config file: %s\n", ret ? json_util_get_last_err() : strerror(errno)); ret = -EIO; } @@ -440,40 +440,40 @@ int json_update_config(struct nvme_global_ctx *ctx, int fd) return ret; } -static void json_dump_ctrl(struct json_object *ctrl_array, nvme_ctrl_t c) +static void json_dump_ctrl(struct json_object *ctrl_array, libnvme_ctrl_t c) { - struct nvme_fabrics_config *cfg = nvme_ctrl_get_config(c); + struct libnvme_fabrics_config *cfg = libnvme_ctrl_get_config(c); struct json_object *ctrl_obj = json_object_new_object(); const char *name, *transport, *value; - name = nvme_ctrl_get_name(c); + name = libnvme_ctrl_get_name(c); if (name && strlen(name)) json_object_object_add(ctrl_obj, "name", json_object_new_string(name)); - transport = nvme_ctrl_get_transport(c); + transport = libnvme_ctrl_get_transport(c); json_object_object_add(ctrl_obj, "transport", json_object_new_string(transport)); - value = nvme_ctrl_get_traddr(c); + value = libnvme_ctrl_get_traddr(c); if (value) json_object_object_add(ctrl_obj, "traddr", json_object_new_string(value)); - value = nvme_ctrl_get_host_traddr(c); + value = libnvme_ctrl_get_host_traddr(c); if (value) json_object_object_add(ctrl_obj, "host_traddr", json_object_new_string(value)); - value = nvme_ctrl_get_host_iface(c); + value = libnvme_ctrl_get_host_iface(c); if (value) json_object_object_add(ctrl_obj, "host_iface", json_object_new_string(value)); - value = nvme_ctrl_get_trsvcid(c); + value = libnvme_ctrl_get_trsvcid(c); if (value) json_object_object_add(ctrl_obj, "trsvcid", json_object_new_string(value)); - value = nvme_ctrl_get_dhchap_host_key(c); + value = libnvme_ctrl_get_dhchap_host_key(c); if (value) json_object_object_add(ctrl_obj, "dhchap_key", json_object_new_string(value)); - value = nvme_ctrl_get_dhchap_ctrl_key(c); + value = libnvme_ctrl_get_dhchap_ctrl_key(c); if (value) json_object_object_add(ctrl_obj, "dhchap_ctrl_key", json_object_new_string(value)); @@ -496,63 +496,63 @@ static void json_dump_ctrl(struct json_object *ctrl_array, nvme_ctrl_t c) if (!strcmp(transport, "tcp")) { JSON_BOOL_OPTION(cfg, ctrl_obj, tls); - value = nvme_ctrl_get_keyring(c); + value = libnvme_ctrl_get_keyring(c); if (value) json_object_object_add(ctrl_obj, "keyring", json_object_new_string(value)); - value = nvme_ctrl_get_tls_key_identity(c); + value = libnvme_ctrl_get_tls_key_identity(c); if (value) json_object_object_add(ctrl_obj, "tls_key_identity", json_object_new_string(value)); - value = nvme_ctrl_get_tls_key(c); + value = libnvme_ctrl_get_tls_key(c); if (value) json_object_object_add(ctrl_obj, "tls_key", json_object_new_string(value)); } JSON_BOOL_OPTION(cfg, ctrl_obj, concat); - if (nvme_ctrl_get_persistent(c)) + if (libnvme_ctrl_get_persistent(c)) json_object_object_add(ctrl_obj, "persistent", json_object_new_boolean(true)); - if (nvme_ctrl_get_discovery_ctrl(c)) + if (libnvme_ctrl_get_discovery_ctrl(c)) json_object_object_add(ctrl_obj, "discovery", json_object_new_boolean(true)); json_object_array_add(ctrl_array, ctrl_obj); } -static unsigned int json_dump_subsys_multipath(nvme_subsystem_t s, +static unsigned int json_dump_subsys_multipath(libnvme_subsystem_t s, struct json_object *ns_array) { - nvme_ns_t n; - nvme_path_t p; + libnvme_ns_t n; + libnvme_path_t p; unsigned int i = 0; - nvme_subsystem_for_each_ns(s, n) { + libnvme_subsystem_for_each_ns(s, n) { struct json_object *ns_obj; struct json_object *path_array; ns_obj = json_object_new_object(); json_object_object_add(ns_obj, "nsid", - json_object_new_int(nvme_ns_get_nsid(n))); + json_object_new_int(libnvme_ns_get_nsid(n))); json_object_object_add(ns_obj, "name", - json_object_new_string(nvme_ns_get_name(n))); + json_object_new_string(libnvme_ns_get_name(n))); path_array = json_object_new_array(); - nvme_namespace_for_each_path(n, p) { + libnvme_namespace_for_each_path(n, p) { struct json_object *path_obj; struct json_object *ctrl_array; - nvme_ctrl_t c; + libnvme_ctrl_t c; path_obj = json_object_new_object(); json_object_object_add(path_obj, "path", - json_object_new_string(nvme_path_get_name(p))); + json_object_new_string(libnvme_path_get_name(p))); json_object_object_add(path_obj, "ANAState", - json_object_new_string(nvme_path_get_ana_state(p))); + json_object_new_string(libnvme_path_get_ana_state(p))); json_object_object_add(path_obj, "NUMANodes", - json_object_new_string(nvme_path_get_numa_nodes(p))); + json_object_new_string(libnvme_path_get_numa_nodes(p))); json_object_object_add(path_obj, "qdepth", - json_object_new_int(nvme_path_get_queue_depth(p))); + json_object_new_int(libnvme_path_get_queue_depth(p))); - c = nvme_path_get_ctrl(p); + c = libnvme_path_get_ctrl(p); ctrl_array = json_object_new_array(); json_dump_ctrl(ctrl_array, c); json_object_object_add(path_obj, "controller", ctrl_array); @@ -565,22 +565,22 @@ static unsigned int json_dump_subsys_multipath(nvme_subsystem_t s, return i; } -static void json_dump_subsys_non_multipath(nvme_subsystem_t s, +static void json_dump_subsys_non_multipath(libnvme_subsystem_t s, struct json_object *ns_array) { - nvme_ctrl_t c; - nvme_ns_t n; + libnvme_ctrl_t c; + libnvme_ns_t n; - nvme_subsystem_for_each_ctrl(s, c) { - nvme_ctrl_for_each_ns(c, n) { + libnvme_subsystem_for_each_ctrl(s, c) { + libnvme_ctrl_for_each_ns(c, n) { struct json_object *ctrl_array; struct json_object *ns_obj; ns_obj = json_object_new_object(); json_object_object_add(ns_obj, "nsid", - json_object_new_int(nvme_ns_get_nsid(n))); + json_object_new_int(libnvme_ns_get_nsid(n))); json_object_object_add(ns_obj, "name", - json_object_new_string(nvme_ns_get_name(n))); + json_object_new_string(libnvme_ns_get_name(n))); ctrl_array = json_object_new_array(); json_dump_ctrl(ctrl_array, c); @@ -592,15 +592,15 @@ static void json_dump_subsys_non_multipath(nvme_subsystem_t s, } static void json_dump_subsys(struct json_object *subsys_array, - nvme_subsystem_t s) + libnvme_subsystem_t s) { struct json_object *subsys_obj = json_object_new_object(); struct json_object *ns_array; json_object_object_add(subsys_obj, "name", - json_object_new_string(nvme_subsystem_get_name(s))); + json_object_new_string(libnvme_subsystem_get_name(s))); json_object_object_add(subsys_obj, "nqn", - json_object_new_string(nvme_subsystem_get_subsysnqn(s))); + json_object_new_string(libnvme_subsystem_get_subsysnqn(s))); ns_array = json_object_new_array(); if (!json_dump_subsys_multipath(s, ns_array)) @@ -613,27 +613,27 @@ static void json_dump_subsys(struct json_object *subsys_array, json_object_array_add(subsys_array, subsys_obj); } -int json_dump_tree(struct nvme_global_ctx *ctx) +int json_dump_tree(struct libnvme_global_ctx *ctx) { - nvme_host_t h; + libnvme_host_t h; struct json_object *json_root, *host_obj; struct json_object *host_array, *subsys_array; int ret = 0; json_root = json_object_new_object(); host_array = json_object_new_array(); - nvme_for_each_host(ctx, h) { - nvme_subsystem_t s; + libnvme_for_each_host(ctx, h) { + libnvme_subsystem_t s; const char *hostid, *dhchap_key; host_obj = json_object_new_object(); json_object_object_add(host_obj, "hostnqn", - json_object_new_string(nvme_host_get_hostnqn(h))); - hostid = nvme_host_get_hostid(h); + json_object_new_string(libnvme_host_get_hostnqn(h))); + hostid = libnvme_host_get_hostid(h); if (hostid) json_object_object_add(host_obj, "hostid", json_object_new_string(hostid)); - dhchap_key = nvme_host_get_dhchap_host_key(h); + dhchap_key = libnvme_host_get_dhchap_host_key(h); if (dhchap_key) json_object_object_add(host_obj, "dhchap_key", json_object_new_string(dhchap_key)); @@ -641,7 +641,7 @@ int json_dump_tree(struct nvme_global_ctx *ctx) json_object_object_add(host_obj, "persistent_discovery_ctrl", json_object_new_boolean(h->pdc_enabled)); subsys_array = json_object_new_array(); - nvme_for_each_subsystem(h, s) { + libnvme_for_each_subsystem(h, s) { json_dump_subsys(subsys_array, s); } if (json_object_array_length(subsys_array)) @@ -657,7 +657,7 @@ int json_dump_tree(struct nvme_global_ctx *ctx) JSON_C_TO_STRING_PRETTY | JSON_C_TO_STRING_NOSLASHESCAPE); if (ret < 0) { - nvme_msg(ctx, LOG_ERR, "Failed to write, %s\n", + libnvme_msg(ctx, LOG_ERR, "Failed to write, %s\n", json_util_get_last_err()); ret = -EIO; } diff --git a/libnvme/src/nvme/lib-types.h b/libnvme/src/nvme/lib-types.h index 43eab2ddac..bfda16167d 100644 --- a/libnvme/src/nvme/lib-types.h +++ b/libnvme/src/nvme/lib-types.h @@ -10,13 +10,13 @@ #include -struct nvme_global_ctx; -struct nvme_transport_handle; +struct libnvme_global_ctx; +struct libnvme_transport_handle; /** - * struct nvme_passthru_cmd - nvme passthrough command structure - * @opcode: Operation code, see &enum nvme_io_opcodes and - * &enum nvme_admin_opcodes + * struct libnvme_passthru_cmd - nvme passthrough command structure + * @opcode: Operation code, see &enum libnvme_io_opcodes and + * &enum libnvme_admin_opcodes * @flags: Supported only for NVMe-MI * @rsvd1: Reserved for future use * @nsid: Namespace Identifier, or Fabrics type @@ -37,7 +37,7 @@ struct nvme_transport_handle; * @result: Set on completion to the command's CQE DWORD 0-1 * controller response */ -struct nvme_passthru_cmd { +struct libnvme_passthru_cmd { __u8 opcode; __u8 flags; __u16 rsvd1; @@ -60,9 +60,9 @@ struct nvme_passthru_cmd { }; /** - * struct nvme_uring_cmd - nvme uring command structure - * @opcode: Operation code, see &enum nvme_io_opcodes and - * &enum nvme_admin_opcodes + * struct libnvme_uring_cmd - nvme uring command structure + * @opcode: Operation code, see &enum libnvme_io_opcodes and + * &enum libnvme_admin_opcodes * @flags: Not supported: intended for command flags (eg: SGL, FUSE) * @rsvd1: Reserved for future use * @nsid: Namespace Identifier, or Fabrics type @@ -81,7 +81,7 @@ struct nvme_passthru_cmd { * @timeout_ms: If non-zero, overrides system default timeout in milliseconds * @rsvd2: Reserved for future use (and fills an implicit struct pad */ -struct nvme_uring_cmd { +struct libnvme_uring_cmd { __u8 opcode; __u8 flags; __u16 rsvd1; diff --git a/libnvme/src/nvme/lib.c b/libnvme/src/nvme/lib.c index 2dd8a26452..d5bc10a097 100644 --- a/libnvme/src/nvme/lib.c +++ b/libnvme/src/nvme/lib.c @@ -19,7 +19,7 @@ #include "private.h" #include "compiler_attributes.h" -static bool nvme_mi_probe_enabled_default(void) +static bool libnvme_mi_probe_enabled_default(void) { char *val; @@ -33,9 +33,9 @@ static bool nvme_mi_probe_enabled_default(void) } -__public struct nvme_global_ctx *nvme_create_global_ctx(FILE *fp, int log_level) +__public struct libnvme_global_ctx *libnvme_create_global_ctx(FILE *fp, int log_level) { - struct nvme_global_ctx *ctx; + struct libnvme_global_ctx *ctx; int fd; ctx = calloc(1, sizeof(*ctx)); @@ -58,15 +58,15 @@ __public struct nvme_global_ctx *nvme_create_global_ctx(FILE *fp, int log_level) list_head_init(&ctx->endpoints); ctx->ioctl_probing = true; - ctx->mi_probe_enabled = nvme_mi_probe_enabled_default(); + ctx->mi_probe_enabled = libnvme_mi_probe_enabled_default(); return ctx; } -__public void nvme_free_global_ctx(struct nvme_global_ctx *ctx) +__public void libnvme_free_global_ctx(struct libnvme_global_ctx *ctx) { - struct nvme_host *h, *_h; - nvme_mi_ep_t ep, tmp; + struct libnvme_host *h, *_h; + libnvme_mi_ep_t ep, tmp; if (!ctx) return; @@ -75,66 +75,66 @@ __public void nvme_free_global_ctx(struct nvme_global_ctx *ctx) ctx->ifaddrs_cache = NULL; free(ctx->options); - nvme_for_each_host_safe(ctx, h, _h) - __nvme_free_host(h); - nvme_mi_for_each_endpoint_safe(ctx, ep, tmp) - nvme_mi_close(ep); + libnvme_for_each_host_safe(ctx, h, _h) + __libnvme_free_host(h); + libnvme_mi_for_each_endpoint_safe(ctx, ep, tmp) + libnvme_mi_close(ep); free(ctx->config_file); free(ctx->application); - nvme_close_uring(ctx); + libnvme_close_uring(ctx); free(ctx); } -__public void nvme_set_dry_run(struct nvme_global_ctx *ctx, bool enable) +__public void libnvme_set_dry_run(struct libnvme_global_ctx *ctx, bool enable) { ctx->dry_run = enable; } -__public void nvme_set_ioctl_probing(struct nvme_global_ctx *ctx, bool enable) +__public void libnvme_set_ioctl_probing(struct libnvme_global_ctx *ctx, bool enable) { ctx->ioctl_probing = enable; } -__public void nvme_transport_handle_set_submit_entry(struct nvme_transport_handle *hdl, - void *(*submit_entry)(struct nvme_transport_handle *hdl, - struct nvme_passthru_cmd *cmd)) +__public void libnvme_transport_handle_set_submit_entry(struct libnvme_transport_handle *hdl, + void *(*submit_entry)(struct libnvme_transport_handle *hdl, + struct libnvme_passthru_cmd *cmd)) { hdl->submit_entry = submit_entry; if (!hdl->submit_exit) - hdl->submit_exit = __nvme_submit_exit; + hdl->submit_exit = __libnvme_submit_exit; } -__public void nvme_transport_handle_set_submit_exit(struct nvme_transport_handle *hdl, - void (*submit_exit)(struct nvme_transport_handle *hdl, - struct nvme_passthru_cmd *cmd, +__public void libnvme_transport_handle_set_submit_exit(struct libnvme_transport_handle *hdl, + void (*submit_exit)(struct libnvme_transport_handle *hdl, + struct libnvme_passthru_cmd *cmd, int err, void *user_data)) { hdl->submit_exit = submit_exit; if (!hdl->submit_exit) - hdl->submit_exit = __nvme_submit_exit; + hdl->submit_exit = __libnvme_submit_exit; } -__public void nvme_transport_handle_set_decide_retry(struct nvme_transport_handle *hdl, - bool (*decide_retry)(struct nvme_transport_handle *hdl, - struct nvme_passthru_cmd *cmd, int err)) +__public void libnvme_transport_handle_set_decide_retry(struct libnvme_transport_handle *hdl, + bool (*decide_retry)(struct libnvme_transport_handle *hdl, + struct libnvme_passthru_cmd *cmd, int err)) { hdl->decide_retry = decide_retry; if (!hdl->decide_retry) - hdl->decide_retry = __nvme_decide_retry; + hdl->decide_retry = __libnvme_decide_retry; } static int __nvme_transport_handle_open_direct( - struct nvme_transport_handle *hdl, const char *devname) + struct libnvme_transport_handle *hdl, const char *devname) { - struct nvme_passthru_cmd dummy = { 0 }; + struct libnvme_passthru_cmd dummy = { 0 }; _cleanup_free_ char *path = NULL; char *name; int ret, id, ns; bool c = true; - name = nvme_basename(devname); + name = libnvme_basename(devname); - hdl->type = NVME_TRANSPORT_HANDLE_TYPE_DIRECT; + hdl->type = LIBNVME_TRANSPORT_HANDLE_TYPE_DIRECT; ret = sscanf(name, "nvme%dn%d", &id, &ns); if (ret == 2) @@ -157,7 +157,7 @@ static int __nvme_transport_handle_open_direct( if (c) { if (!S_ISCHR(hdl->stat.st_mode)) return -EINVAL; - ret = __nvme_transport_handle_open_uring(hdl); + ret = __libnvme_transport_handle_open_uring(hdl); if (ret && ret != -ENOTSUP) { close(hdl->fd); return ret; @@ -167,10 +167,10 @@ static int __nvme_transport_handle_open_direct( } if (hdl->ctx->ioctl_probing) { - ret = ioctl(hdl->fd, NVME_IOCTL_ADMIN64_CMD, &dummy); + ret = ioctl(hdl->fd, LIBNVME_IOCTL_ADMIN64_CMD, &dummy); if (ret > 0) { hdl->ioctl_admin64 = true; - ret = ioctl(hdl->fd, NVME_IOCTL_IO64_CMD, &dummy); + ret = ioctl(hdl->fd, LIBNVME_IOCTL_IO64_CMD, &dummy); if (ret != -1 || errno != ENOTTY) hdl->ioctl_io64 = true; } @@ -179,36 +179,37 @@ static int __nvme_transport_handle_open_direct( return 0; } -void __nvme_transport_handle_close_direct(struct nvme_transport_handle *hdl) +void __libnvme_transport_handle_close_direct( + struct libnvme_transport_handle *hdl) { close(hdl->fd); free(hdl); } -struct nvme_transport_handle *__nvme_create_transport_handle( - struct nvme_global_ctx *ctx) +struct libnvme_transport_handle *__libnvme_create_transport_handle( + struct libnvme_global_ctx *ctx) { - struct nvme_transport_handle *hdl; + struct libnvme_transport_handle *hdl; hdl = calloc(1, sizeof(*hdl)); if (!hdl) return NULL; hdl->ctx = ctx; - hdl->submit_entry = __nvme_submit_entry; - hdl->submit_exit = __nvme_submit_exit; - hdl->decide_retry = __nvme_decide_retry; + hdl->submit_entry = __libnvme_submit_entry; + hdl->submit_exit = __libnvme_submit_exit; + hdl->decide_retry = __libnvme_decide_retry; return hdl; } -__public int nvme_open(struct nvme_global_ctx *ctx, const char *name, - struct nvme_transport_handle **hdlp) +__public int libnvme_open(struct libnvme_global_ctx *ctx, const char *name, + struct libnvme_transport_handle **hdlp) { - struct nvme_transport_handle *hdl; + struct libnvme_transport_handle *hdl; int ret; - hdl = __nvme_create_transport_handle(ctx); + hdl = __libnvme_create_transport_handle(ctx); if (!hdl) return -ENOMEM; @@ -219,7 +220,7 @@ __public int nvme_open(struct nvme_global_ctx *ctx, const char *name, } if (!strncmp(name, "NVME_TEST_FD", 12)) { - hdl->type = NVME_TRANSPORT_HANDLE_TYPE_DIRECT; + hdl->type = LIBNVME_TRANSPORT_HANDLE_TYPE_DIRECT; hdl->fd = 0xFD; if (!strcmp(name, "NVME_TEST_FD64")) @@ -230,12 +231,12 @@ __public int nvme_open(struct nvme_global_ctx *ctx, const char *name, } if (!strncmp(name, "mctp:", strlen("mctp:"))) - ret = __nvme_transport_handle_open_mi(hdl, name); + ret = __libnvme_transport_handle_open_mi(hdl, name); else ret = __nvme_transport_handle_open_direct(hdl, name); if (ret) { - nvme_close(hdl); + libnvme_close(hdl); return ret; } @@ -244,7 +245,7 @@ __public int nvme_open(struct nvme_global_ctx *ctx, const char *name, return 0; } -__public void nvme_close(struct nvme_transport_handle *hdl) +__public void libnvme_close(struct libnvme_transport_handle *hdl) { if (!hdl) return; @@ -252,45 +253,45 @@ __public void nvme_close(struct nvme_transport_handle *hdl) free(hdl->name); switch (hdl->type) { - case NVME_TRANSPORT_HANDLE_TYPE_DIRECT: - __nvme_transport_handle_close_direct(hdl); + case LIBNVME_TRANSPORT_HANDLE_TYPE_DIRECT: + __libnvme_transport_handle_close_direct(hdl); break; - case NVME_TRANSPORT_HANDLE_TYPE_MI: - __nvme_transport_handle_close_mi(hdl); + case LIBNVME_TRANSPORT_HANDLE_TYPE_MI: + __libnvme_transport_handle_close_mi(hdl); break; - case NVME_TRANSPORT_HANDLE_TYPE_UNKNOWN: + case LIBNVME_TRANSPORT_HANDLE_TYPE_UNKNOWN: free(hdl); break; } } -__public int nvme_transport_handle_get_fd(struct nvme_transport_handle *hdl) +__public int libnvme_transport_handle_get_fd(struct libnvme_transport_handle *hdl) { return hdl->fd; } -__public const char *nvme_transport_handle_get_name(struct nvme_transport_handle *hdl) +__public const char *libnvme_transport_handle_get_name(struct libnvme_transport_handle *hdl) { return basename(hdl->name); } -__public bool nvme_transport_handle_is_blkdev(struct nvme_transport_handle *hdl) +__public bool libnvme_transport_handle_is_blkdev(struct libnvme_transport_handle *hdl) { return S_ISBLK(hdl->stat.st_mode); } -__public bool nvme_transport_handle_is_chardev(struct nvme_transport_handle *hdl) +__public bool libnvme_transport_handle_is_chardev(struct libnvme_transport_handle *hdl) { return S_ISCHR(hdl->stat.st_mode); } -__public bool nvme_transport_handle_is_direct(struct nvme_transport_handle *hdl) +__public bool libnvme_transport_handle_is_direct(struct libnvme_transport_handle *hdl) { - return hdl->type == NVME_TRANSPORT_HANDLE_TYPE_DIRECT; + return hdl->type == LIBNVME_TRANSPORT_HANDLE_TYPE_DIRECT; } -__public bool nvme_transport_handle_is_mi(struct nvme_transport_handle *hdl) +__public bool libnvme_transport_handle_is_mi(struct libnvme_transport_handle *hdl) { - return hdl->type == NVME_TRANSPORT_HANDLE_TYPE_MI; + return hdl->type == LIBNVME_TRANSPORT_HANDLE_TYPE_MI; } diff --git a/libnvme/src/nvme/lib.h b/libnvme/src/nvme/lib.h index 6efc245d9b..bbce950ac2 100644 --- a/libnvme/src/nvme/lib.h +++ b/libnvme/src/nvme/lib.h @@ -22,37 +22,37 @@ #endif /** - * nvme_create_global_ctx() - Initialize global context object + * libnvme_create_global_ctx() - Initialize global context object * @fp: File descriptor for logging messages * @log_level: Logging level to use * - * Return: Initialized &struct nvme_global_ctx object + * Return: Initialized &struct libnvme_global_ctx object */ -struct nvme_global_ctx *nvme_create_global_ctx(FILE *fp, int log_level); +struct libnvme_global_ctx *libnvme_create_global_ctx(FILE *fp, int log_level); /** - * nvme_free_global_ctx() - Free global context object - * @ctx: &struct nvme_global_ctx object + * libnvme_free_global_ctx() - Free global context object + * @ctx: &struct libnvme_global_ctx object * - * Free an &struct nvme_global_ctx object and all attached objects + * Free an &struct libnvme_global_ctx object and all attached objects */ -void nvme_free_global_ctx(struct nvme_global_ctx *ctx); +void libnvme_free_global_ctx(struct libnvme_global_ctx *ctx); /** - * nvme_set_logging_level() - Set current logging level - * @ctx: struct nvme_global_ctx object + * libnvme_set_logging_level() - Set current logging level + * @ctx: struct libnvme_global_ctx object * @log_level: Logging level to set * @log_pid: Boolean to enable logging of the PID * @log_tstamp: Boolean to enable logging of the timestamp * * Sets the current logging level for the global context. */ -void nvme_set_logging_level(struct nvme_global_ctx *ctx, int log_level, +void libnvme_set_logging_level(struct libnvme_global_ctx *ctx, int log_level, bool log_pid, bool log_tstamp); /** - * nvme_get_logging_level() - Get current logging level - * @ctx: struct nvme_global_ctx object + * libnvme_get_logging_level() - Get current logging level + * @ctx: struct libnvme_global_ctx object * @log_pid: Pointer to store a current value of logging of * the PID flag at (optional). * @log_tstamp: Pointer to store a current value of logging of @@ -62,12 +62,12 @@ void nvme_set_logging_level(struct nvme_global_ctx *ctx, int log_level, * * Return: current log level value or DEFAULT_LOGLEVEL if not initialized. */ -int nvme_get_logging_level(struct nvme_global_ctx *ctx, bool *log_pid, +int libnvme_get_logging_level(struct libnvme_global_ctx *ctx, bool *log_pid, bool *log_tstamp); /** - * nvme_open() - Open an nvme controller or namespace device - * @ctx: struct nvme_global_ctx object + * libnvme_open() - Open an nvme controller or namespace device + * @ctx: struct libnvme_global_ctx object * @name: The basename of the device to open * @hdl: Transport handle to return * @@ -76,72 +76,77 @@ int nvme_get_logging_level(struct nvme_global_ctx *ctx, bool *log_pid, * * Return: 0 on success or negative error code otherwise */ -int nvme_open(struct nvme_global_ctx *ctx, const char *name, - struct nvme_transport_handle **hdl); +int libnvme_open(struct libnvme_global_ctx *ctx, const char *name, + struct libnvme_transport_handle **hdl); /** - * nvme_close() - Close transport handle + * libnvme_close() - Close transport handle * @hdl: Transport handle */ -void nvme_close(struct nvme_transport_handle *hdl); +void libnvme_close(struct libnvme_transport_handle *hdl); /** - * nvme_transport_handle_get_fd - Return file descriptor from transport handle + * libnvme_transport_handle_get_fd - Return file descriptor from + * the transport handle * @hdl: Transport handle * * If the device handle is for a ioctl based device, - * nvme_transport_handle_get_fd will return a valid file descriptor. + * libnvme_transport_handle_get_fd will return a valid file descriptor. * * Return: File descriptor for an IOCTL based transport handle, otherwise -1. */ -int nvme_transport_handle_get_fd(struct nvme_transport_handle *hdl); +int libnvme_transport_handle_get_fd(struct libnvme_transport_handle *hdl); /** - * nvme_transport_handle_get_name - Return name of the device transport handle + * libnvme_transport_handle_get_name - Return name of the device + * transport handle * @hdl: Transport handle * * Return: Device file name, otherwise -1. */ -const char *nvme_transport_handle_get_name(struct nvme_transport_handle *hdl); +const char *libnvme_transport_handle_get_name( + struct libnvme_transport_handle *hdl); /** - * nvme_transport_handle_is_blkdev - Check if transport handle is a block device + * libnvme_transport_handle_is_blkdev - Check if transport handle is a + * block device * @hdl: Transport handle * * Return: Return true if transport handle is a block device, otherwise false. */ -bool nvme_transport_handle_is_blkdev(struct nvme_transport_handle *hdl); +bool libnvme_transport_handle_is_blkdev(struct libnvme_transport_handle *hdl); /** - * nvme_transport_handle_is_chardev - Check if transport handle is a char device + * libnvme_transport_handle_is_chardev - Check if transport handle is a + * char device * @hdl: Transport handle * * Return: Return true if transport handle is a char device, otherwise false. */ -bool nvme_transport_handle_is_chardev(struct nvme_transport_handle *hdl); +bool libnvme_transport_handle_is_chardev(struct libnvme_transport_handle *hdl); /** - * nvme_transport_handle_is_direct - Check if transport handle is using IOCTL + * libnvme_transport_handle_is_direct - Check if transport handle is using IOCTL * interface * @hdl: Transport handle * * Return: Return true if transport handle is using IOCTL itnerface, * otherwise false. */ -bool nvme_transport_handle_is_direct(struct nvme_transport_handle *hdl); +bool libnvme_transport_handle_is_direct(struct libnvme_transport_handle *hdl); /** - * nvme_transport_handle_is_mi - Check if transport handle is a using MI + * libnvme_transport_handle_is_mi - Check if transport handle is a using MI * interface * @hdl: Transport handle * * Return: Return true if transport handle is using MI interface, * otherwise false. */ -bool nvme_transport_handle_is_mi(struct nvme_transport_handle *hdl); +bool libnvme_transport_handle_is_mi(struct libnvme_transport_handle *hdl); /** - * nvme_transport_handle_set_submit_entry() - Install a submit-entry callback + * libnvme_transport_handle_set_submit_entry() - Install a submit-entry callback * @hdl: Transport handle to configure * @submit_entry: Callback invoked immediately before a passthrough command is * submitted. The function receives the command about to be issued @@ -156,12 +161,13 @@ bool nvme_transport_handle_is_mi(struct nvme_transport_handle *hdl); * * Return: None. */ -void nvme_transport_handle_set_submit_entry(struct nvme_transport_handle *hdl, - void *(*submit_entry)(struct nvme_transport_handle *hdl, - struct nvme_passthru_cmd *cmd)); +void libnvme_transport_handle_set_submit_entry( + struct libnvme_transport_handle *hdl, + void *(*submit_entry)(struct libnvme_transport_handle *hdl, + struct libnvme_passthru_cmd *cmd)); /** - * nvme_transport_handle_set_submit_exit() - Install a submit-exit callback + * libnvme_transport_handle_set_submit_exit() - Install a submit-exit callback * @hdl: Transport handle to configure * @submit_exit: Callback invoked after a passthrough command completes. The * function receives the command, the completion status @err @@ -175,13 +181,15 @@ void nvme_transport_handle_set_submit_entry(struct nvme_transport_handle *hdl, * * Return: None. */ -void nvme_transport_handle_set_submit_exit(struct nvme_transport_handle *hdl, - void (*submit_exit)(struct nvme_transport_handle *hdl, - struct nvme_passthru_cmd *cmd, +void libnvme_transport_handle_set_submit_exit( + struct libnvme_transport_handle *hdl, + void (*submit_exit)(struct libnvme_transport_handle *hdl, + struct libnvme_passthru_cmd *cmd, int err, void *user_data)); /** - * nvme_transport_handle_set_decide_retry() - Install a retry-decision callback + * libnvme_transport_handle_set_decide_retry() - Install a retry-decision + * callback * @hdl: Transport handle to configure * @decide_retry: Callback used to determine whether a passthrough command * should be retried after an error. The function is called with @@ -200,34 +208,35 @@ void nvme_transport_handle_set_submit_exit(struct nvme_transport_handle *hdl, * * Return: None. */ -void nvme_transport_handle_set_decide_retry(struct nvme_transport_handle *hdl, - bool (*decide_retry)(struct nvme_transport_handle *hdl, - struct nvme_passthru_cmd *cmd, int err)); +void libnvme_transport_handle_set_decide_retry( + struct libnvme_transport_handle *hdl, + bool (*decide_retry)(struct libnvme_transport_handle *hdl, + struct libnvme_passthru_cmd *cmd, int err)); /** - * nvme_set_probe_enabled() - enable/disable the probe for new MI endpoints - * @ctx: &struct nvme_global_ctx object + * libnvme_set_probe_enabled() - enable/disable the probe for new MI endpoints + * @ctx: &struct libnvme_global_ctx object * @enabled: whether to probe new endpoints * * Controls whether newly-created endpoints are probed for quirks on creation. * Defaults to enabled, which results in some initial messaging with the * endpoint to determine model-specific details. */ -void nvme_set_probe_enabled(struct nvme_global_ctx *ctx, bool enabled); +void libnvme_set_probe_enabled(struct libnvme_global_ctx *ctx, bool enabled); /** - * nvme_set_dry_run() - Set global dry run state - * @ctx: struct nvme_global_ctx object + * libnvme_set_dry_run() - Set global dry run state + * @ctx: struct libnvme_global_ctx object * @enable: Enable/disable dry run state * * When dry_run is enabled, any IOCTL commands send via the passthru * interface won't be executed. */ -void nvme_set_dry_run(struct nvme_global_ctx *ctx, bool enable); +void libnvme_set_dry_run(struct libnvme_global_ctx *ctx, bool enable); /** - * nvme_set_ioctl_probing() - Enable/disable 64-bit IOCTL probing - * @ctx: struct nvme_global_ctx object + * libnvme_set_ioctl_probing() - Enable/disable 64-bit IOCTL probing + * @ctx: struct libnvme_global_ctx object * @enable: Enable/disable 64-bit IOCTL probing * * When IOCTL probing is enabled, a 64-bit IOCTL command is issued to @@ -235,4 +244,4 @@ void nvme_set_dry_run(struct nvme_global_ctx *ctx, bool enable); * * IOCTL probing is enabled per default. */ -void nvme_set_ioctl_probing(struct nvme_global_ctx *ctx, bool enable); +void libnvme_set_ioctl_probing(struct libnvme_global_ctx *ctx, bool enable); diff --git a/libnvme/src/nvme/linux.c b/libnvme/src/nvme/linux.c index 8189ce814a..742f5c9958 100644 --- a/libnvme/src/nvme/linux.c +++ b/libnvme/src/nvme/linux.c @@ -64,7 +64,7 @@ static int __nvme_set_attr(const char *path, const char *value) fd = open(path, O_WRONLY); if (fd < 0) { #if 0 - nvme_msg(LOG_DEBUG, "Failed to open %s: %s\n", path, + libnvme_msg(LOG_DEBUG, "Failed to open %s: %s\n", path, strerror(errno)); #endif return -errno; @@ -72,7 +72,7 @@ static int __nvme_set_attr(const char *path, const char *value) return write(fd, value, strlen(value)); } -int nvme_set_attr(const char *dir, const char *attr, const char *value) +int libnvme_set_attr(const char *dir, const char *attr, const char *value) { _cleanup_free_ char *path = NULL; int ret; @@ -113,7 +113,7 @@ static char *__nvme_get_attr(const char *path) return strlen(value) ? strdup(value) : NULL; } -__public char *nvme_get_attr(const char *dir, const char *attr) +__public char *libnvme_get_attr(const char *dir, const char *attr) { _cleanup_free_ char *path = NULL; int ret; @@ -125,39 +125,39 @@ __public char *nvme_get_attr(const char *dir, const char *attr) return __nvme_get_attr(path); } -__public char *nvme_get_subsys_attr(nvme_subsystem_t s, const char *attr) +__public char *libnvme_get_subsys_attr(libnvme_subsystem_t s, const char *attr) { - return nvme_get_attr(nvme_subsystem_get_sysfs_dir(s), attr); + return libnvme_get_attr(libnvme_subsystem_get_sysfs_dir(s), attr); } -__public char *nvme_get_ctrl_attr(nvme_ctrl_t c, const char *attr) +__public char *libnvme_get_ctrl_attr(libnvme_ctrl_t c, const char *attr) { - return nvme_get_attr(nvme_ctrl_get_sysfs_dir(c), attr); + return libnvme_get_attr(libnvme_ctrl_get_sysfs_dir(c), attr); } -__public char *nvme_get_ns_attr(nvme_ns_t n, const char *attr) +__public char *libnvme_get_ns_attr(libnvme_ns_t n, const char *attr) { - return nvme_get_attr(nvme_ns_get_sysfs_dir(n), attr); + return libnvme_get_attr(libnvme_ns_get_sysfs_dir(n), attr); } -__public char *nvme_get_path_attr(nvme_path_t p, const char *attr) +__public char *libnvme_get_path_attr(libnvme_path_t p, const char *attr) { - return nvme_get_attr(nvme_path_get_sysfs_dir(p), attr); + return libnvme_get_attr(libnvme_path_get_sysfs_dir(p), attr); } #ifndef CONFIG_OPENSSL static unsigned char default_hmac(size_t key_len) { - return NVME_HMAC_ALG_NONE; + return LIBNVME_HMAC_ALG_NONE; } -__public int nvme_gen_dhchap_key(struct nvme_global_ctx *ctx, - char *hostnqn, enum nvme_hmac_alg hmac, +__public int libnvme_gen_dhchap_key(struct libnvme_global_ctx *ctx, + char *hostnqn, enum libnvme_hmac_alg hmac, unsigned int key_len, unsigned char *secret, unsigned char *key) { - if (hmac != NVME_HMAC_ALG_NONE) { - nvme_msg(ctx, LOG_ERR, "HMAC transformation not supported; " + if (hmac != LIBNVME_HMAC_ALG_NONE) { + libnvme_msg(ctx, LOG_ERR, "HMAC transformation not supported; " "recompile with OpenSSL support.\n"); return -EINVAL; } @@ -166,74 +166,74 @@ __public int nvme_gen_dhchap_key(struct nvme_global_ctx *ctx, return 0; } -__public int nvme_create_raw_secret(struct nvme_global_ctx *ctx, +__public int libnvme_create_raw_secret(struct libnvme_global_ctx *ctx, const char *secret, size_t key_len, unsigned char **raw_secret) { - nvme_msg(ctx, LOG_ERR, "NVMe TLS 2.0 is not supported; " + libnvme_msg(ctx, LOG_ERR, "NVMe TLS 2.0 is not supported; " "recompile with OpenSSL support.\n"); return -ENOTSUP; } -static int derive_retained_key(struct nvme_global_ctx *ctx, +static int derive_retained_key(struct libnvme_global_ctx *ctx, int hmac, const char *hostnqn, unsigned char *generated, unsigned char *retained, size_t key_len) { - nvme_msg(ctx, LOG_ERR, "NVMe TLS is not supported; " + libnvme_msg(ctx, LOG_ERR, "NVMe TLS is not supported; " "recompile with OpenSSL support.\n"); return -ENOTSUP; } -static int derive_retained_key_compat(struct nvme_global_ctx *ctx, +static int derive_retained_key_compat(struct libnvme_global_ctx *ctx, int hmac, const char *hostnqn, unsigned char *generated, unsigned char *retained, size_t key_len) { - nvme_msg(ctx, LOG_ERR, "NVMe TLS is not supported; " + libnvme_msg(ctx, LOG_ERR, "NVMe TLS is not supported; " "recompile with OpenSSL support.\n"); return -ENOTSUP; } -static int derive_psk_digest(struct nvme_global_ctx *ctx, +static int derive_psk_digest(struct libnvme_global_ctx *ctx, const char *hostnqn, const char *subsysnqn, int version, int cipher, unsigned char *retained, size_t key_len, char *digest, size_t digest_len) { - nvme_msg(ctx, LOG_ERR, "NVMe TLS 2.0 is not supported; " + libnvme_msg(ctx, LOG_ERR, "NVMe TLS 2.0 is not supported; " "recompile with OpenSSL support.\n"); return -ENOTSUP; } -static int derive_tls_key(struct nvme_global_ctx *ctx, +static int derive_tls_key(struct libnvme_global_ctx *ctx, int version, unsigned char cipher, const char *context, unsigned char *retained, unsigned char *psk, size_t key_len) { - nvme_msg(ctx, LOG_ERR, "NVMe TLS is not supported; " + libnvme_msg(ctx, LOG_ERR, "NVMe TLS is not supported; " "recompile with OpenSSL support.\n"); return -ENOTSUP; } -static int derive_tls_key_compat(struct nvme_global_ctx *ctx, +static int derive_tls_key_compat(struct libnvme_global_ctx *ctx, int version, unsigned char cipher, const char *context, unsigned char *retained, unsigned char *psk, size_t key_len) { - nvme_msg(ctx, LOG_ERR, "NVMe TLS is not supported; " + libnvme_msg(ctx, LOG_ERR, "NVMe TLS is not supported; " "recompile with OpenSSL support.\n"); return -ENOTSUP; } #else /* CONFIG_OPENSSL */ static unsigned char default_hmac(size_t key_len) { - unsigned char hmac = NVME_HMAC_ALG_NONE; + unsigned char hmac = LIBNVME_HMAC_ALG_NONE; switch (key_len) { case 32: - hmac = NVME_HMAC_ALG_SHA2_256; + hmac = LIBNVME_HMAC_ALG_SHA2_256; break; case 48: - hmac = NVME_HMAC_ALG_SHA2_384; + hmac = LIBNVME_HMAC_ALG_SHA2_384; break; case 64: - hmac = NVME_HMAC_ALG_SHA2_512; + hmac = LIBNVME_HMAC_ALG_SHA2_512; break; default: break; @@ -246,11 +246,11 @@ static const EVP_MD *select_hmac(int hmac, size_t *hmac_len) const EVP_MD *md = NULL; switch (hmac) { - case NVME_HMAC_ALG_SHA2_256: + case LIBNVME_HMAC_ALG_SHA2_256: md = EVP_sha256(); *hmac_len = 32; break; - case NVME_HMAC_ALG_SHA2_384: + case LIBNVME_HMAC_ALG_SHA2_384: md = EVP_sha384(); *hmac_len = 48; break; @@ -298,7 +298,7 @@ static DEFINE_CLEANUP_FUNC( * - 1 indicates SHA-256 * - 2 indicates SHA-384 */ -static int derive_retained_key(struct nvme_global_ctx *ctx, +static int derive_retained_key(struct libnvme_global_ctx *ctx, int hmac, const char *hostnqn, unsigned char *configured, unsigned char *retained, size_t key_len) @@ -316,7 +316,7 @@ static int derive_retained_key(struct nvme_global_ctx *ctx, if (!hkdf_info) return -ENOMEM; - if (hmac == NVME_HMAC_ALG_NONE) { + if (hmac == LIBNVME_HMAC_ALG_NONE) { memcpy(retained, configured, key_len); return key_len; } @@ -368,7 +368,7 @@ static int derive_retained_key(struct nvme_global_ctx *ctx, return key_len; } -static int derive_retained_key_compat(struct nvme_global_ctx *ctx, +static int derive_retained_key_compat(struct libnvme_global_ctx *ctx, int hmac, const char *hostnqn, unsigned char *configured, unsigned char *retained, size_t key_len) { @@ -379,7 +379,7 @@ static int derive_retained_key_compat(struct nvme_global_ctx *ctx, char *pos; int ret; - if (hmac == NVME_HMAC_ALG_NONE) { + if (hmac == LIBNVME_HMAC_ALG_NONE) { memcpy(retained, configured, key_len); return key_len; } @@ -449,7 +449,7 @@ static int derive_retained_key_compat(struct nvme_global_ctx *ctx, * and the value '0' is invalid here. */ -static int derive_tls_key(struct nvme_global_ctx *ctx, +static int derive_tls_key(struct libnvme_global_ctx *ctx, int version, unsigned char cipher, const char *context, unsigned char *retained, unsigned char *psk, size_t key_len) { @@ -526,7 +526,7 @@ static int derive_tls_key(struct nvme_global_ctx *ctx, return key_len; } -static int derive_tls_key_compat(struct nvme_global_ctx *ctx, +static int derive_tls_key_compat(struct libnvme_global_ctx *ctx, int version, unsigned char cipher, const char *context, unsigned char *retained, unsigned char *psk, size_t key_len) { @@ -604,8 +604,8 @@ static DEFINE_CLEANUP_FUNC(cleanup_evp_mac_ctx, EVP_MAC_CTX *, EVP_MAC_CTX_free) static DEFINE_CLEANUP_FUNC(cleanup_evp_mac, EVP_MAC *, EVP_MAC_free) #define _cleanup_evp_mac_ __cleanup__(cleanup_evp_mac) -__public int nvme_gen_dhchap_key(struct nvme_global_ctx *ctx, - char *hostnqn, enum nvme_hmac_alg hmac, +__public int libnvme_gen_dhchap_key(struct libnvme_global_ctx *ctx, + char *hostnqn, enum libnvme_hmac_alg hmac, unsigned int key_len, unsigned char *secret, unsigned char *key) { @@ -631,16 +631,16 @@ __public int nvme_gen_dhchap_key(struct nvme_global_ctx *ctx, return -ENOMEM; switch (hmac) { - case NVME_HMAC_ALG_NONE: + case LIBNVME_HMAC_ALG_NONE: memcpy(key, secret, key_len); return 0; - case NVME_HMAC_ALG_SHA2_256: + case LIBNVME_HMAC_ALG_SHA2_256: digest = OSSL_DIGEST_NAME_SHA2_256; break; - case NVME_HMAC_ALG_SHA2_384: + case LIBNVME_HMAC_ALG_SHA2_384: digest = OSSL_DIGEST_NAME_SHA2_384; break; - case NVME_HMAC_ALG_SHA2_512: + case LIBNVME_HMAC_ALG_SHA2_512: digest = OSSL_DIGEST_NAME_SHA2_512; break; default: @@ -671,7 +671,7 @@ __public int nvme_gen_dhchap_key(struct nvme_global_ctx *ctx, return 0; } -static int derive_psk_digest(struct nvme_global_ctx *ctx, +static int derive_psk_digest(struct libnvme_global_ctx *ctx, const char *hostnqn, const char *subsysnqn, int version, int cipher, unsigned char *retained, size_t key_len, @@ -701,10 +701,10 @@ static int derive_psk_digest(struct nvme_global_ctx *ctx, return -ENOMEM; switch (cipher) { - case NVME_HMAC_ALG_SHA2_256: + case LIBNVME_HMAC_ALG_SHA2_256: dig = OSSL_DIGEST_NAME_SHA2_256; break; - case NVME_HMAC_ALG_SHA2_384: + case LIBNVME_HMAC_ALG_SHA2_384: dig = OSSL_DIGEST_NAME_SHA2_384; break; default: @@ -775,7 +775,7 @@ static ssize_t getrandom_bytes(void *buf, size_t buflen) return result; } -static ssize_t getswordfish(struct nvme_global_ctx *ctx, +static ssize_t getswordfish(struct libnvme_global_ctx *ctx, const char *seed, void *buf, size_t buflen) { unsigned char hash[EVP_MAX_MD_SIZE]; @@ -817,7 +817,7 @@ static ssize_t getswordfish(struct nvme_global_ctx *ctx, return -EIO; } -__public int nvme_create_raw_secret(struct nvme_global_ctx *ctx, +__public int libnvme_create_raw_secret(struct libnvme_global_ctx *ctx, const char *secret, size_t key_len, unsigned char **raw_secret) { _cleanup_free_ unsigned char *buf = NULL; @@ -825,7 +825,7 @@ __public int nvme_create_raw_secret(struct nvme_global_ctx *ctx, unsigned int c; if (key_len != 32 && key_len != 48 && key_len != 64) { - nvme_msg(ctx, LOG_ERR, "Invalid key length %ld", key_len); + libnvme_msg(ctx, LOG_ERR, "Invalid key length %ld", key_len); return -EINVAL; } @@ -842,7 +842,7 @@ __public int nvme_create_raw_secret(struct nvme_global_ctx *ctx, } if (strlen(secret) < 4) { - nvme_msg(ctx, LOG_ERR, "Input secret too short\n"); + libnvme_msg(ctx, LOG_ERR, "Input secret too short\n"); return -EINVAL; } @@ -856,19 +856,19 @@ __public int nvme_create_raw_secret(struct nvme_global_ctx *ctx, for (i = 0; i < strlen(secret); i += 2) { if (sscanf(&secret[i], "%02x", &c) != 1) { - nvme_msg(ctx, LOG_ERR, + libnvme_msg(ctx, LOG_ERR, "Invalid secret '%s'", secret); return -EINVAL; } if (i >= key_len * 2) { - nvme_msg(ctx, LOG_ERR, + libnvme_msg(ctx, LOG_ERR, "Skipping excess secret bytes\n"); break; } buf[secret_len++] = (unsigned char)c; } if (secret_len != key_len) { - nvme_msg(ctx, LOG_ERR, + libnvme_msg(ctx, LOG_ERR, "Invalid key length (%d bytes)\n", secret_len); return -EINVAL; } @@ -898,7 +898,7 @@ static int gen_tls_identity(const char *hostnqn, const char *subsysnqn, return strlen(identity); } -static int derive_nvme_keys(struct nvme_global_ctx *ctx, +static int derive_nvme_keys(struct libnvme_global_ctx *ctx, const char *hostnqn, const char *subsysnqn, char *identity, int version, int hmac, unsigned char *configured, @@ -926,7 +926,7 @@ static int derive_nvme_keys(struct nvme_global_ctx *ctx, if (ret < 0) return ret; - if (hmac == NVME_HMAC_ALG_NONE) + if (hmac == LIBNVME_HMAC_ALG_NONE) cipher = default_hmac(key_len); else cipher = hmac; @@ -967,7 +967,7 @@ static ssize_t nvme_identity_len(int hmac, int version, const char *hostnqn, len = strlen(hostnqn) + strlen(subsysnqn) + 12; if (version == 1) { len += 66; - if (hmac == NVME_HMAC_ALG_SHA2_384) + if (hmac == LIBNVME_HMAC_ALG_SHA2_384) len += 32; } else if (version > 1) { return -EINVAL; @@ -975,7 +975,7 @@ static ssize_t nvme_identity_len(int hmac, int version, const char *hostnqn, return len; } -__public int nvme_generate_tls_key_identity(struct nvme_global_ctx *ctx, +__public int libnvme_generate_tls_key_identity(struct libnvme_global_ctx *ctx, const char *hostnqn, const char *subsysnqn, int version, int hmac, unsigned char *configured_key, int key_len, @@ -1013,7 +1013,7 @@ __public int nvme_generate_tls_key_identity(struct nvme_global_ctx *ctx, return 0; } -__public int nvme_generate_tls_key_identity_compat(struct nvme_global_ctx *ctx, +__public int libnvme_generate_tls_key_identity_compat(struct libnvme_global_ctx *ctx, const char *hostnqn, const char *subsysnqn, int version, int hmac, unsigned char *configured_key, int key_len, char **ident) @@ -1051,7 +1051,7 @@ __public int nvme_generate_tls_key_identity_compat(struct nvme_global_ctx *ctx, } #ifdef CONFIG_KEYUTILS -__public int nvme_lookup_keyring(struct nvme_global_ctx *ctx, const char *keyring, +__public int libnvme_lookup_keyring(struct libnvme_global_ctx *ctx, const char *keyring, long *key) { key_serial_t keyring_id; @@ -1066,7 +1066,7 @@ __public int nvme_lookup_keyring(struct nvme_global_ctx *ctx, const char *keyrin return 0; } -__public char *nvme_describe_key_serial(struct nvme_global_ctx *ctx, long key_id) +__public char *libnvme_describe_key_serial(struct libnvme_global_ctx *ctx, long key_id) { _cleanup_free_ char *str = NULL; char *last; @@ -1085,7 +1085,7 @@ __public char *nvme_describe_key_serial(struct nvme_global_ctx *ctx, long key_id return strdup(last); } -__public int nvme_lookup_key(struct nvme_global_ctx *ctx, const char *type, +__public int libnvme_lookup_key(struct libnvme_global_ctx *ctx, const char *type, const char *identity, long *keyp) { key_serial_t key; @@ -1098,12 +1098,12 @@ __public int nvme_lookup_key(struct nvme_global_ctx *ctx, const char *type, return 0; } -__public int nvme_set_keyring(struct nvme_global_ctx *ctx, long key_id) +__public int libnvme_set_keyring(struct libnvme_global_ctx *ctx, long key_id) { long err; if (key_id == 0) { - if (nvme_lookup_keyring(ctx, NULL, &key_id)) + if (libnvme_lookup_keyring(ctx, NULL, &key_id)) return -ENOKEY; } @@ -1113,13 +1113,13 @@ __public int nvme_set_keyring(struct nvme_global_ctx *ctx, long key_id) return 0; } -__public int nvme_read_key(struct nvme_global_ctx *ctx, long keyring_id, +__public int libnvme_read_key(struct libnvme_global_ctx *ctx, long keyring_id, long key_id, int *len, unsigned char **key) { void *buffer; int ret; - ret = nvme_set_keyring(ctx, keyring_id); + ret = libnvme_set_keyring(ctx, keyring_id); if (ret < 0) return ret; @@ -1132,7 +1132,7 @@ __public int nvme_read_key(struct nvme_global_ctx *ctx, long keyring_id, return 0; } -__public int nvme_update_key(struct nvme_global_ctx *ctx, long keyring_id, +__public int libnvme_update_key(struct libnvme_global_ctx *ctx, long keyring_id, const char *key_type, const char *identity, unsigned char *key_data, int key_len, long *keyp) { @@ -1153,8 +1153,8 @@ __public int nvme_update_key(struct nvme_global_ctx *ctx, long keyring_id, } struct __scan_keys_data { - struct nvme_global_ctx *ctx; - nvme_scan_tls_keys_cb_t cb; + struct libnvme_global_ctx *ctx; + libnvme_scan_tls_keys_cb_t cb; key_serial_t keyring; void *data; }; @@ -1192,21 +1192,21 @@ int __scan_keys_cb(key_serial_t parent, key_serial_t key, char *desc, return 1; } -__public int nvme_scan_tls_keys(struct nvme_global_ctx *ctx, const char *keyring, - nvme_scan_tls_keys_cb_t cb, void *data) +__public int libnvme_scan_tls_keys(struct libnvme_global_ctx *ctx, const char *keyring, + libnvme_scan_tls_keys_cb_t cb, void *data) { struct __scan_keys_data d; long keyring_id; int ret; - ret = nvme_lookup_keyring(ctx, keyring, &keyring_id); + ret = libnvme_lookup_keyring(ctx, keyring, &keyring_id); if (ret) return ret; if (!keyring_id) return -EINVAL; - ret = nvme_set_keyring(ctx, keyring_id); + ret = libnvme_set_keyring(ctx, keyring_id); if (ret < 0) return ret; @@ -1218,7 +1218,7 @@ __public int nvme_scan_tls_keys(struct nvme_global_ctx *ctx, const char *keyring return ret; } -static int __nvme_insert_tls_key(struct nvme_global_ctx *ctx, +static int __nvme_insert_tls_key(struct libnvme_global_ctx *ctx, key_serial_t keyring_id, const char *key_type, const char *hostnqn, const char *subsysnqn, int version, int hmac, unsigned char *configured_key, @@ -1251,7 +1251,7 @@ static int __nvme_insert_tls_key(struct nvme_global_ctx *ctx, return -ENOKEY; } - ret = nvme_update_key(ctx, keyring_id, key_type, identity, + ret = libnvme_update_key(ctx, keyring_id, key_type, identity, psk, key_len, &key); if (ret) return ret; @@ -1260,7 +1260,7 @@ static int __nvme_insert_tls_key(struct nvme_global_ctx *ctx, return 0; } -__public int nvme_insert_tls_key_versioned(struct nvme_global_ctx *ctx, +__public int libnvme_insert_tls_key_versioned(struct libnvme_global_ctx *ctx, const char *keyring, const char *key_type, const char *hostnqn, const char *subsysnqn, int version, int hmac, @@ -1270,11 +1270,11 @@ __public int nvme_insert_tls_key_versioned(struct nvme_global_ctx *ctx, long keyring_id; int ret; - ret = nvme_lookup_keyring(ctx, keyring, &keyring_id); + ret = libnvme_lookup_keyring(ctx, keyring, &keyring_id); if (ret) return ret; - ret = nvme_set_keyring(ctx, keyring_id); + ret = libnvme_set_keyring(ctx, keyring_id); if (ret < 0) return 0; @@ -1283,7 +1283,7 @@ __public int nvme_insert_tls_key_versioned(struct nvme_global_ctx *ctx, configured_key, key_len, false, key); } -__public int nvme_insert_tls_key_compat(struct nvme_global_ctx *ctx, +__public int libnvme_insert_tls_key_compat(struct libnvme_global_ctx *ctx, const char *keyring, const char *key_type, const char *hostnqn, const char *subsysnqn, int version, int hmac, @@ -1293,11 +1293,11 @@ __public int nvme_insert_tls_key_compat(struct nvme_global_ctx *ctx, long keyring_id; int ret; - ret = nvme_lookup_keyring(ctx, keyring, &keyring_id); + ret = libnvme_lookup_keyring(ctx, keyring, &keyring_id); if (ret) return ret; - ret = nvme_set_keyring(ctx, keyring_id); + ret = libnvme_set_keyring(ctx, keyring_id); if (ret < 0) return 0; @@ -1306,14 +1306,14 @@ __public int nvme_insert_tls_key_compat(struct nvme_global_ctx *ctx, configured_key, key_len, true, key); } -__public int nvme_revoke_tls_key(struct nvme_global_ctx *ctx, +__public int libnvme_revoke_tls_key(struct libnvme_global_ctx *ctx, const char *keyring, const char *key_type, const char *identity) { long keyring_id, key; int ret; - ret = nvme_lookup_keyring(ctx, keyring, &keyring_id); + ret = libnvme_lookup_keyring(ctx, keyring, &keyring_id); if (ret) return ret; @@ -1328,7 +1328,7 @@ __public int nvme_revoke_tls_key(struct nvme_global_ctx *ctx, return 0; } -static int __nvme_import_tls_key(struct nvme_global_ctx *ctx, long keyring_id, +static int __nvme_import_tls_key(struct libnvme_global_ctx *ctx, long keyring_id, const char *hostnqn, const char *subsysnqn, const char *identity, const char *key, long *keyp) @@ -1339,12 +1339,12 @@ static int __nvme_import_tls_key(struct nvme_global_ctx *ctx, long keyring_id, size_t key_len; int ret; - ret = nvme_import_tls_key_versioned(ctx, key, &version, + ret = libnvme_import_tls_key_versioned(ctx, key, &version, &hmac, &key_len, &key_data); if (ret) return ret; - if (hmac == NVME_HMAC_ALG_NONE || !identity) { + if (hmac == LIBNVME_HMAC_ALG_NONE || !identity) { /* * This is a configured key (hmac 0) or we don't know the * identity and so the assumtion is it is also a @@ -1356,33 +1356,33 @@ static int __nvme_import_tls_key(struct nvme_global_ctx *ctx, long keyring_id, key_data, key_len, false, keyp); } - return nvme_update_key(ctx, keyring_id, "psk", identity, + return libnvme_update_key(ctx, keyring_id, "psk", identity, key_data, key_len, keyp); } -int __nvme_import_keys_from_config(nvme_host_t h, nvme_ctrl_t c, +int __libnvme_import_keys_from_config(libnvme_host_t h, libnvme_ctrl_t c, long *keyring_id, long *key_id) { - const char *hostnqn = nvme_host_get_hostnqn(h); - const char *subsysnqn = nvme_ctrl_get_subsysnqn(c); + const char *hostnqn = libnvme_host_get_hostnqn(h); + const char *subsysnqn = libnvme_ctrl_get_subsysnqn(c); const char *keyring, *key, *identity; long kr_id = 0, id = 0; int ret; if (!hostnqn || !subsysnqn) { - nvme_msg(h->ctx, LOG_ERR, "Invalid NQNs (%s, %s)\n", + libnvme_msg(h->ctx, LOG_ERR, "Invalid NQNs (%s, %s)\n", hostnqn, subsysnqn); return -EINVAL; } /* If we don't have a key avoid all keyring operations */ - key = nvme_ctrl_get_tls_key(c); + key = libnvme_ctrl_get_tls_key(c); if (!key) goto out; - keyring = nvme_ctrl_get_keyring(c); + keyring = libnvme_ctrl_get_keyring(c); if (keyring) { - ret = nvme_lookup_keyring(h->ctx, keyring, &kr_id); + ret = libnvme_lookup_keyring(h->ctx, keyring, &kr_id); if (ret) return ret; } else @@ -1394,21 +1394,21 @@ 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) { - ret = nvme_lookup_keyring(h->ctx, ".nvme", &kr_id); + ret = libnvme_lookup_keyring(h->ctx, ".nvme", &kr_id); if (ret) return ret; } - if (nvme_set_keyring(h->ctx, kr_id) < 0) { - nvme_msg(h->ctx, LOG_ERR, "Failed to set keyring\n"); + if (libnvme_set_keyring(h->ctx, kr_id) < 0) { + libnvme_msg(h->ctx, LOG_ERR, "Failed to set keyring\n"); return -errno; } - identity = nvme_ctrl_get_tls_key_identity(c); + identity = libnvme_ctrl_get_tls_key_identity(c); if (identity) { - ret = nvme_lookup_key(h->ctx, "psk", identity, &id); + ret = libnvme_lookup_key(h->ctx, "psk", identity, &id); if (ret && !(ret == -ENOKEY || ret == -EKEYREVOKED)) { - nvme_msg(h->ctx, LOG_ERR, + libnvme_msg(h->ctx, LOG_ERR, "Failed to lookup key for identity %s, error %d\n", identity, ret); return ret; @@ -1419,7 +1419,7 @@ int __nvme_import_keys_from_config(nvme_host_t h, nvme_ctrl_t c, ret = __nvme_import_tls_key(h->ctx, kr_id, hostnqn, subsysnqn, identity, key, &id); if (ret) { - nvme_msg(h->ctx, LOG_ERR, + libnvme_msg(h->ctx, LOG_ERR, "Failed to insert TLS KEY, error %d\n", ret); return ret; } @@ -1432,95 +1432,95 @@ int __nvme_import_keys_from_config(nvme_host_t h, nvme_ctrl_t c, return 0; } #else -__public int nvme_lookup_keyring(struct nvme_global_ctx *ctx, const char *keyring, +__public int libnvme_lookup_keyring(struct libnvme_global_ctx *ctx, const char *keyring, long *key) { - nvme_msg(ctx, LOG_ERR, "key operations not supported; " + libnvme_msg(ctx, LOG_ERR, "key operations not supported; " "recompile with keyutils support.\n"); return -ENOTSUP; } -__public char *nvme_describe_key_serial(struct nvme_global_ctx *ctx, long key_id) +__public char *libnvme_describe_key_serial(struct libnvme_global_ctx *ctx, long key_id) { - nvme_msg(ctx, LOG_ERR, "key operations not supported; " + libnvme_msg(ctx, LOG_ERR, "key operations not supported; " "recompile with keyutils support.\n"); return NULL; } -__public int nvme_lookup_key(struct nvme_global_ctx *ctx, const char *type, +__public int libnvme_lookup_key(struct libnvme_global_ctx *ctx, const char *type, const char *identity, long *key) { - nvme_msg(ctx, LOG_ERR, "key operations not supported; " + libnvme_msg(ctx, LOG_ERR, "key operations not supported; " "recompile with keyutils support.\n"); return -ENOTSUP; } -__public int nvme_set_keyring(struct nvme_global_ctx *ctx, long key_id) +__public int libnvme_set_keyring(struct libnvme_global_ctx *ctx, long key_id) { - nvme_msg(ctx, LOG_ERR, "key operations not supported; " + libnvme_msg(ctx, LOG_ERR, "key operations not supported; " "recompile with keyutils support.\n"); return -ENOTSUP; } -__public int nvme_read_key(struct nvme_global_ctx *ctx, long keyring_id, +__public int libnvme_read_key(struct libnvme_global_ctx *ctx, long keyring_id, long key_id, int *len, unsigned char **key) { - nvme_msg(ctx, LOG_ERR, "key operations not supported; " + libnvme_msg(ctx, LOG_ERR, "key operations not supported; " "recompile with keyutils support.\n"); return -ENOTSUP; } -__public int nvme_update_key(struct nvme_global_ctx *ctx, long keyring_id, +__public int libnvme_update_key(struct libnvme_global_ctx *ctx, long keyring_id, const char *key_type, const char *identity, unsigned char *key_data, int key_len, long *key) { - nvme_msg(ctx, LOG_ERR, "key operations not supported; " + libnvme_msg(ctx, LOG_ERR, "key operations not supported; " "recompile with keyutils support.\n"); return -ENOTSUP; } -__public int nvme_scan_tls_keys(struct nvme_global_ctx *ctx, const char *keyring, - nvme_scan_tls_keys_cb_t cb, void *data) +__public int libnvme_scan_tls_keys(struct libnvme_global_ctx *ctx, const char *keyring, + libnvme_scan_tls_keys_cb_t cb, void *data) { - nvme_msg(ctx, LOG_ERR, "key operations not supported; " + libnvme_msg(ctx, LOG_ERR, "key operations not supported; " "recompile with keyutils support.\n"); return -ENOTSUP; } -__public int nvme_insert_tls_key_versioned(struct nvme_global_ctx *ctx, +__public int libnvme_insert_tls_key_versioned(struct libnvme_global_ctx *ctx, 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 *keyp) { - nvme_msg(ctx, LOG_ERR, "key operations not supported; " + libnvme_msg(ctx, LOG_ERR, "key operations not supported; " "recompile with keyutils support.\n"); return -ENOTSUP; } -__public int nvme_insert_tls_key_compat(struct nvme_global_ctx *ctx, +__public int libnvme_insert_tls_key_compat(struct libnvme_global_ctx *ctx, 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 *keyp) { - nvme_msg(ctx, LOG_ERR, "key operations not supported; " + libnvme_msg(ctx, LOG_ERR, "key operations not supported; " "recompile with keyutils support.\n"); return -ENOTSUP; } -__public int nvme_revoke_tls_key(struct nvme_global_ctx *ctx, +__public int libnvme_revoke_tls_key(struct libnvme_global_ctx *ctx, const char *keyring, const char *key_type, const char *identity) { - nvme_msg(ctx, LOG_ERR, "key operations not supported; " + libnvme_msg(ctx, LOG_ERR, "key operations not supported; " "recompile with keyutils support.\n"); return -ENOTSUP; } -int __nvme_import_keys_from_config(nvme_host_t h, nvme_ctrl_t c, +int __libnvme_import_keys_from_config(libnvme_host_t h, libnvme_ctrl_t c, long *keyring_id, long *key_id) { *keyring_id = 0; @@ -1530,12 +1530,12 @@ int __nvme_import_keys_from_config(nvme_host_t h, nvme_ctrl_t c, } #endif -__public int nvme_insert_tls_key(struct nvme_global_ctx *ctx, +__public int libnvme_insert_tls_key(struct libnvme_global_ctx *ctx, const char *keyring, const char *key_type, const char *hostnqn, const char *subsysnqn, int hmac, unsigned char *configured_key, int key_len, long *key) { - return nvme_insert_tls_key_versioned(ctx, keyring, key_type, + return libnvme_insert_tls_key_versioned(ctx, keyring, key_type, hostnqn, subsysnqn, 0, hmac, configured_key, key_len, key); } @@ -1552,7 +1552,7 @@ __public int nvme_insert_tls_key(struct nvme_global_ctx *ctx, * s: 32 or 48 bytes binary followed by a CRC-32 of the configured PSK * (4 bytes) encoded as base64 */ -__public int nvme_export_tls_key_versioned(struct nvme_global_ctx *ctx, +__public int libnvme_export_tls_key_versioned(struct libnvme_global_ctx *ctx, unsigned char version, unsigned char hmac, const unsigned char *key_data, size_t key_len, char **encoded_keyp) @@ -1563,15 +1563,15 @@ __public int nvme_export_tls_key_versioned(struct nvme_global_ctx *ctx, char *encoded_key; switch (hmac) { - case NVME_HMAC_ALG_NONE: + case LIBNVME_HMAC_ALG_NONE: if (key_len != 32 && key_len != 48) return -EINVAL; break; - case NVME_HMAC_ALG_SHA2_256: + case LIBNVME_HMAC_ALG_SHA2_256: if (key_len != 32) return -EINVAL; break; - case NVME_HMAC_ALG_SHA2_384: + case LIBNVME_HMAC_ALG_SHA2_384: if (key_len != 48) return -EINVAL; break; @@ -1602,21 +1602,21 @@ __public int nvme_export_tls_key_versioned(struct nvme_global_ctx *ctx, return 0; } -__public int nvme_export_tls_key(struct nvme_global_ctx *ctx, +__public int libnvme_export_tls_key(struct libnvme_global_ctx *ctx, const unsigned char *key_data, int key_len, char **key) { unsigned char hmac; if (key_len == 32) - hmac = NVME_HMAC_ALG_SHA2_256; + hmac = LIBNVME_HMAC_ALG_SHA2_256; else - hmac = NVME_HMAC_ALG_SHA2_384; + hmac = LIBNVME_HMAC_ALG_SHA2_384; - return nvme_export_tls_key_versioned(ctx, 1, hmac, key_data, + return libnvme_export_tls_key_versioned(ctx, 1, hmac, key_data, key_len, key); } -__public int nvme_import_tls_key_versioned(struct nvme_global_ctx *ctx, +__public int libnvme_import_tls_key_versioned(struct libnvme_global_ctx *ctx, const char *encoded_key, unsigned char *version, unsigned char *hmac, size_t *key_len, unsigned char **keyp) @@ -1638,15 +1638,15 @@ __public int nvme_import_tls_key_versioned(struct nvme_global_ctx *ctx, len = strlen(encoded_key); switch (_hmac) { - case NVME_HMAC_ALG_NONE: + case LIBNVME_HMAC_ALG_NONE: if (len != 65 && len != 89) return -EINVAL; break; - case NVME_HMAC_ALG_SHA2_256: + case LIBNVME_HMAC_ALG_SHA2_256: if (len != 65) return -EINVAL; break; - case NVME_HMAC_ALG_SHA2_384: + case LIBNVME_HMAC_ALG_SHA2_384: if (len != 89) return -EINVAL; break; @@ -1670,7 +1670,7 @@ __public int nvme_import_tls_key_versioned(struct nvme_global_ctx *ctx, ((uint32_t)decoded_key[decoded_len + 2] << 16) | ((uint32_t)decoded_key[decoded_len + 3] << 24); if (key_crc != crc) { - nvme_msg(ctx, LOG_ERR, "CRC mismatch (key %08x, crc %08x)", + libnvme_msg(ctx, LOG_ERR, "CRC mismatch (key %08x, crc %08x)", key_crc, crc); return -ENOKEY; } @@ -1685,7 +1685,7 @@ __public int nvme_import_tls_key_versioned(struct nvme_global_ctx *ctx, return 0; } -__public int nvme_import_tls_key(struct nvme_global_ctx *ctx, const char *encoded_key, +__public int libnvme_import_tls_key(struct libnvme_global_ctx *ctx, const char *encoded_key, int *key_len, unsigned int *hmac, unsigned char **keyp) { unsigned char version, _hmac; @@ -1693,7 +1693,7 @@ __public int nvme_import_tls_key(struct nvme_global_ctx *ctx, const char *encode size_t len; int ret; - ret = nvme_import_tls_key_versioned(ctx, encoded_key, &version, + ret = libnvme_import_tls_key_versioned(ctx, encoded_key, &version, &_hmac, &len, &psk); if (ret) return ret; @@ -1709,7 +1709,7 @@ static int uuid_from_device_tree(char *system_uuid) _cleanup_fd_ int f = -1; ssize_t len; - f = open(nvme_uuid_ibm_filename(), O_RDONLY); + f = open(libnvme_uuid_ibm_filename(), O_RDONLY); if (f < 0) return -ENXIO; @@ -1749,7 +1749,7 @@ static bool is_dmi_uuid_valid(const char *buf, size_t len) static int uuid_from_dmi_entries(char *system_uuid) { _cleanup_dir_ DIR *d = NULL; - const char *entries_dir = nvme_dmi_entries_dir(); + const char *entries_dir = libnvme_dmi_entries_dir(); int f; struct dirent *de; char buf[512] = {0}; @@ -1860,7 +1860,7 @@ static int uuid_from_dmi(char *system_uuid) return ret; } -__public char *nvme_generate_hostid(void) +__public char *libnvme_generate_hostid(void) { int ret; char uuid_str[NVME_UUID_LEN_STRING]; @@ -1870,22 +1870,22 @@ __public char *nvme_generate_hostid(void) if (ret < 0) ret = uuid_from_device_tree(uuid_str); if (ret < 0) { - if (nvme_random_uuid(uuid) < 0) + if (libnvme_random_uuid(uuid) < 0) memset(uuid, 0, NVME_UUID_LEN); - nvme_uuid_to_string(uuid, uuid_str); + libnvme_uuid_to_string(uuid, uuid_str); } return strdup(uuid_str); } -__public char *nvme_generate_hostnqn_from_hostid(char *hostid) +__public char *libnvme_generate_hostnqn_from_hostid(char *hostid) { char *hid = NULL; char *hostnqn; int ret; if (!hostid) - hostid = hid = nvme_generate_hostid(); + hostid = hid = libnvme_generate_hostid(); ret = asprintf(&hostnqn, "nqn.2014-08.org.nvmexpress:uuid:%s", hostid); free(hid); @@ -1893,9 +1893,9 @@ __public char *nvme_generate_hostnqn_from_hostid(char *hostid) return (ret < 0) ? NULL : hostnqn; } -__public char *nvme_generate_hostnqn(void) +__public char *libnvme_generate_hostnqn(void) { - return nvme_generate_hostnqn_from_hostid(NULL); + return libnvme_generate_hostnqn_from_hostid(NULL); } static char *nvmf_read_file(const char *f, int len) @@ -1916,7 +1916,7 @@ static char *nvmf_read_file(const char *f, int len) return strndup(buf, strcspn(buf, "\n")); } -__public char *nvme_read_hostnqn(void) +__public char *libnvme_read_hostnqn(void) { char *hostnqn = getenv("LIBNVME_HOSTNQN"); @@ -1929,7 +1929,7 @@ __public char *nvme_read_hostnqn(void) return nvmf_read_file(NVMF_HOSTNQN_FILE, NVMF_NQN_SIZE); } -__public char *nvme_read_hostid(void) +__public char *libnvme_read_hostid(void) { char *hostid = getenv("LIBNVME_HOSTID"); diff --git a/libnvme/src/nvme/linux.h b/libnvme/src/nvme/linux.h index 91320352dc..aa0693a64b 100644 --- a/libnvme/src/nvme/linux.h +++ b/libnvme/src/nvme/linux.h @@ -19,22 +19,22 @@ * linux-specific utility functions */ /** - * enum nvme_hmac_alg - HMAC algorithm - * @NVME_HMAC_ALG_NONE: No HMAC algorithm - * @NVME_HMAC_ALG_SHA2_256: SHA2-256 - * @NVME_HMAC_ALG_SHA2_384: SHA2-384 - * @NVME_HMAC_ALG_SHA2_512: SHA2-512 + * enum libnvme_hmac_alg - HMAC algorithm + * @LIBNVME_HMAC_ALG_NONE: No HMAC algorithm + * @LIBNVME_HMAC_ALG_SHA2_256: SHA2-256 + * @LIBNVME_HMAC_ALG_SHA2_384: SHA2-384 + * @LIBNVME_HMAC_ALG_SHA2_512: SHA2-512 */ -enum nvme_hmac_alg { - NVME_HMAC_ALG_NONE = 0, - NVME_HMAC_ALG_SHA2_256 = 1, - NVME_HMAC_ALG_SHA2_384 = 2, - NVME_HMAC_ALG_SHA2_512 = 3, +enum libnvme_hmac_alg { + LIBNVME_HMAC_ALG_NONE = 0, + LIBNVME_HMAC_ALG_SHA2_256 = 1, + LIBNVME_HMAC_ALG_SHA2_384 = 2, + LIBNVME_HMAC_ALG_SHA2_512 = 3, }; /** - * nvme_gen_dhchap_key() - DH-HMAC-CHAP key generation - * @ctx: struct nvme_global_ctx object + * libnvme_gen_dhchap_key() - DH-HMAC-CHAP key generation + * @ctx: struct libnvme_global_ctx object * @hostnqn: Host NVMe Qualified Name * @hmac: HMAC algorithm * @key_len: Output key length @@ -44,14 +44,14 @@ enum nvme_hmac_alg { * Return: If key generation was successful the function returns 0 or * a negative error code otherwise. */ -int nvme_gen_dhchap_key(struct nvme_global_ctx *ctx, - char *hostnqn, enum nvme_hmac_alg hmac, +int libnvme_gen_dhchap_key(struct libnvme_global_ctx *ctx, + char *hostnqn, enum libnvme_hmac_alg hmac, unsigned int key_len, unsigned char *secret, unsigned char *key); /** - * nvme_lookup_keyring() - Lookup keyring serial number - * @ctx: struct nvme_global_ctx object + * libnvme_lookup_keyring() - Lookup keyring serial number + * @ctx: struct libnvme_global_ctx object * @keyring: Keyring name * @key: Key serial number to return * @@ -59,12 +59,12 @@ int nvme_gen_dhchap_key(struct nvme_global_ctx *ctx, * * Return: 0 on success or negative error code otherwise */ -int nvme_lookup_keyring(struct nvme_global_ctx *ctx, +int libnvme_lookup_keyring(struct libnvme_global_ctx *ctx, const char *keyring, long *key); /** - * nvme_describe_key_serial() - Return key description - * @ctx: struct nvme_global_ctx object + * libnvme_describe_key_serial() - Return key description + * @ctx: struct libnvme_global_ctx object * @key_id: Key serial number * * Fetches the description of the key or keyring identified @@ -73,12 +73,12 @@ int nvme_lookup_keyring(struct nvme_global_ctx *ctx, * Return: The description of @key_id or NULL on failure. * The returned string needs to be freed by the caller. */ -char *nvme_describe_key_serial(struct nvme_global_ctx *ctx, +char *libnvme_describe_key_serial(struct libnvme_global_ctx *ctx, long key_id); /** - * nvme_lookup_key() - Lookup key serial number - * @ctx: struct nvme_global_ctx object + * libnvme_lookup_key() - Lookup key serial number + * @ctx: struct libnvme_global_ctx object * @type: Key type * @identity: Key description * @key: Key serial number to return @@ -88,12 +88,12 @@ char *nvme_describe_key_serial(struct nvme_global_ctx *ctx, * * Return: 0 on success or negative error code otherwise */ -int nvme_lookup_key(struct nvme_global_ctx *ctx, const char *type, +int libnvme_lookup_key(struct libnvme_global_ctx *ctx, const char *type, const char *identity, long *key); /** - * nvme_set_keyring() - Link keyring for lookup - * @ctx: struct nvme_global_ctx object + * libnvme_set_keyring() - Link keyring for lookup + * @ctx: struct libnvme_global_ctx object * @keyring_id: Keyring id * * Links @keyring_id into the session keyring such that @@ -101,11 +101,11 @@ int nvme_lookup_key(struct nvme_global_ctx *ctx, const char *type, * * Return: 0 on success or negative error code otherwise */ -int nvme_set_keyring(struct nvme_global_ctx *ctx, long keyring_id); +int libnvme_set_keyring(struct libnvme_global_ctx *ctx, long keyring_id); /** - * nvme_create_raw_secret - Generate a raw secret buffer from input data - * @ctx: struct nvme_global_ctx object + * libnvme_create_raw_secret - Generate a raw secret buffer from input data + * @ctx: struct libnvme_global_ctx object * @secret: Input secret data * @key_len: The length of the raw_secret in bytes * @raw_secret: Return buffer with the generated raw secret @@ -113,17 +113,17 @@ int nvme_set_keyring(struct nvme_global_ctx *ctx, long keyring_id); * Transforms the provided @secret into a raw secret buffer suitable for * use with NVMe key management operations. * - * The generated raw secret can subsequently be passed to nvme_read_key() - * or nvme_update_key(). + * The generated raw secret can subsequently be passed to libnvme_read_key() + * or libnvme_update_key(). * * Return: 0 on success, or a negative error code on failure. */ -int nvme_create_raw_secret(struct nvme_global_ctx *ctx, +int libnvme_create_raw_secret(struct libnvme_global_ctx *ctx, const char *secret, size_t key_len, unsigned char **raw_secret); /** - * nvme_read_key() - Read key raw data - * @ctx: struct nvme_global_ctx object + * libnvme_read_key() - Read key raw data + * @ctx: struct libnvme_global_ctx object * @keyring_id: Id of the keyring holding %key_id * @key_id: Key id * @len: Length of the returned data @@ -136,12 +136,12 @@ int nvme_create_raw_secret(struct nvme_global_ctx *ctx, * * Return: 0 on success or negative error code otherwise */ -int nvme_read_key(struct nvme_global_ctx *ctx, long keyring_id, +int libnvme_read_key(struct libnvme_global_ctx *ctx, long keyring_id, long key_id, int *len, unsigned char **key); /** - * nvme_update_key() - Update key raw data - * @ctx: struct nvme_global_ctx object + * libnvme_update_key() - Update key raw data + * @ctx: struct libnvme_global_ctx object * @keyring_id: Id of the keyring holding %key_id * @key_type: Type of the key to insert * @identity: Key identity string @@ -156,13 +156,13 @@ int nvme_read_key(struct nvme_global_ctx *ctx, long keyring_id, * * Return: 0 on success or negative error code otherwise */ -int nvme_update_key(struct nvme_global_ctx *ctx, long keyring_id, +int libnvme_update_key(struct libnvme_global_ctx *ctx, 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 - * @ctx: struct nvme_global_ctx object + * typedef libnvme_scan_tls_keys_cb_t - Callback for iterating TLS keys + * @ctx: struct libnvme_global_ctx object * @keyring: Keyring which has been iterated * @key: Key for which the callback has been invoked * @desc: Description of the key @@ -171,12 +171,12 @@ int nvme_update_key(struct nvme_global_ctx *ctx, long keyring_id, * * Called for each TLS PSK in the keyring. */ -typedef void (*nvme_scan_tls_keys_cb_t)(struct nvme_global_ctx *ctx, +typedef void (*libnvme_scan_tls_keys_cb_t)(struct libnvme_global_ctx *ctx, long keyring, long key, char *desc, int desc_len, void *data); /** - * nvme_scan_tls_keys() - Iterate over TLS keys in a keyring - * @ctx: struct nvme_global_ctx object + * libnvme_scan_tls_keys() - Iterate over TLS keys in a keyring + * @ctx: struct libnvme_global_ctx object * @keyring: Keyring holding TLS keys * @cb: Callback function * @data: Pointer for data to be passed to @cb @@ -189,12 +189,12 @@ typedef void (*nvme_scan_tls_keys_cb_t)(struct nvme_global_ctx *ctx, * * Return: Number of keys for which @cb was called, or negative error code */ -int nvme_scan_tls_keys(struct nvme_global_ctx *ctx, const char *keyring, - nvme_scan_tls_keys_cb_t cb, void *data); +int libnvme_scan_tls_keys(struct libnvme_global_ctx *ctx, const char *keyring, + libnvme_scan_tls_keys_cb_t cb, void *data); /** - * nvme_insert_tls_key() - Derive and insert TLS key - * @ctx: struct nvme_global_ctx object + * libnvme_insert_tls_key() - Derive and insert TLS key + * @ctx: struct libnvme_global_ctx object * @keyring: Keyring to use * @key_type: Type of the resulting key * @hostnqn: Host NVMe Qualified Name @@ -209,14 +209,14 @@ int nvme_scan_tls_keys(struct nvme_global_ctx *ctx, const char *keyring, * * Return: 0 on success or negative error code otherwise */ -int nvme_insert_tls_key(struct nvme_global_ctx *ctx, const char *keyring, +int libnvme_insert_tls_key(struct libnvme_global_ctx *ctx, const char *keyring, const char *key_type, const char *hostnqn, const char *subsysnqn, int hmac, unsigned char *configured_key, int key_len, long *key); /** - * nvme_insert_tls_key_versioned() - Derive and insert TLS key - * @ctx: struct nvme_global_ctx object + * libnvme_insert_tls_key_versioned() - Derive and insert TLS key + * @ctx: struct libnvme_global_ctx object * @keyring: Keyring to use * @key_type: Type of the resulting key * @hostnqn: Host NVMe Qualified Name @@ -233,7 +233,7 @@ int nvme_insert_tls_key(struct nvme_global_ctx *ctx, const char *keyring, * * Return: 0 on success or negative error code otherwise */ -int nvme_insert_tls_key_versioned(struct nvme_global_ctx *ctx, +int libnvme_insert_tls_key_versioned(struct libnvme_global_ctx *ctx, const char *keyring, const char *key_type, const char *hostnqn, const char *subsysnqn, int version, int hmac, @@ -241,8 +241,8 @@ int nvme_insert_tls_key_versioned(struct nvme_global_ctx *ctx, long *key); /** - * nvme_insert_tls_key_compat() - Derive and insert TLS key - * @ctx: struct nvme_global_ctx object + * libnvme_insert_tls_key_compat() - Derive and insert TLS key + * @ctx: struct libnvme_global_ctx object * @keyring: Keyring to use * @key_type: Type of the resulting key * @hostnqn: Host NVMe Qualified Name @@ -256,14 +256,14 @@ int nvme_insert_tls_key_versioned(struct nvme_global_ctx *ctx, * 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. - * This version differs from @nvme_insert_tls_key_versioned() in that it + * This version differs from @libnvme_insert_tls_key_versioned() in that it * uses the original implementation for HKDF Expand-Label which does not * prefix the 'info' and 'label' strings with the length. * * Return: The key serial number if the key could be inserted into * the keyring or 0 with errno otherwise. */ -int nvme_insert_tls_key_compat(struct nvme_global_ctx *ctx, +int libnvme_insert_tls_key_compat(struct libnvme_global_ctx *ctx, const char *keyring, const char *key_type, const char *hostnqn, const char *subsysnqn, int version, int hmac, @@ -271,8 +271,8 @@ int nvme_insert_tls_key_compat(struct nvme_global_ctx *ctx, long *key); /** - * nvme_generate_tls_key_identity() - Generate the TLS key identity - * @ctx: struct nvme_global_ctx object + * libnvme_generate_tls_key_identity() - Generate the TLS key identity + * @ctx: struct libnvme_global_ctx object * @hostnqn: Host NVMe Qualified Name * @subsysnqn: Subsystem NVMe Qualified Name * @version: Key version to use @@ -288,15 +288,15 @@ int nvme_insert_tls_key_compat(struct nvme_global_ctx *ctx, * * Return: 0 on success or negative error code otherwise */ -int nvme_generate_tls_key_identity(struct nvme_global_ctx *ctx, +int libnvme_generate_tls_key_identity(struct libnvme_global_ctx *ctx, const char *hostnqn, const char *subsysnqn, int version, int hmac, unsigned char *configured_key, int key_len, char **identity); /** - * nvme_generate_tls_key_identity_compat() - Generate the TLS key identity - * @ctx: struct nvme_global_ctx object + * libnvme_generate_tls_key_identity_compat() - Generate the TLS key identity + * @ctx: struct libnvme_global_ctx object * @hostnqn: Host NVMe Qualified Name * @subsysnqn: Subsystem NVMe Qualified Name * @version: Key version to use @@ -307,7 +307,7 @@ int nvme_generate_tls_key_identity(struct nvme_global_ctx *ctx, * * Derives a 'retained' TLS key as specified in NVMe TCP and * generate the corresponding TLs identity. This version differs - * from @nvme_generate_tls_key_identity() in that it uses the original + * from @libnvme_generate_tls_key_identity() in that it uses the original * implementation for HKDF-Expand-Label which does not prefix the 'info' * and 'label' string with the length. * @@ -315,26 +315,26 @@ int nvme_generate_tls_key_identity(struct nvme_global_ctx *ctx, * * Return: 0 on success or negative error code otherwise */ -int nvme_generate_tls_key_identity_compat(struct nvme_global_ctx *ctx, +int libnvme_generate_tls_key_identity_compat(struct libnvme_global_ctx *ctx, 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 - * @ctx: struct nvme_global_ctx object + * libnvme_revoke_tls_key() - Revoke TLS key from keyring + * @ctx: struct libnvme_global_ctx object * @keyring: Keyring to use * @key_type: Type of the key to revoke * @identity: Key identity string * * Return: 0 on success or negative error code otherwise */ -int nvme_revoke_tls_key(struct nvme_global_ctx *ctx, const char *keyring, +int libnvme_revoke_tls_key(struct libnvme_global_ctx *ctx, const char *keyring, const char *key_type, const char *identity); /** - * nvme_export_tls_key() - Export a TLS key - * @ctx: struct nvme_global_ctx object + * libnvme_export_tls_key() - Export a TLS key + * @ctx: struct libnvme_global_ctx object * @key_data: Raw data of the key * @key_len: Length of @key_data * @identity: TLS identity @@ -347,12 +347,12 @@ int nvme_revoke_tls_key(struct nvme_global_ctx *ctx, const char *keyring, * * Return: 0 on success or negative error code otherwise */ -int nvme_export_tls_key(struct nvme_global_ctx *ctx, +int libnvme_export_tls_key(struct libnvme_global_ctx *ctx, const unsigned char *key_data, int key_len, char **identity); /** - * nvme_export_tls_key_versioned() - Export a TLS pre-shared key - * @ctx: struct nvme_global_ctx object + * libnvme_export_tls_key_versioned() - Export a TLS pre-shared key + * @ctx: struct libnvme_global_ctx object * @version: Indicated the representation of the TLS PSK * @hmac: HMAC algorithm used to transfor the configured PSK * in a retained PSK @@ -368,14 +368,14 @@ int nvme_export_tls_key(struct nvme_global_ctx *ctx, * * Return: 0 on success or negative error code otherwise */ -int nvme_export_tls_key_versioned(struct nvme_global_ctx *ctx, +int libnvme_export_tls_key_versioned(struct libnvme_global_ctx *ctx, 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 - * @ctx: struct nvme_global_ctx object + * libnvme_import_tls_key() - Import a TLS key + * @ctx: struct libnvme_global_ctx object * @encoded_key: TLS key in PSK interchange format * @key_len: Length of the resulting key data * @hmac: HMAC algorithm @@ -388,12 +388,13 @@ int nvme_export_tls_key_versioned(struct nvme_global_ctx *ctx, * * Return: 0 on success or negative error code otherwise */ -int nvme_import_tls_key(struct nvme_global_ctx *ctx, const char *encoded_key, - int *key_len, unsigned int *hmac, unsigned char **key); +int libnvme_import_tls_key(struct libnvme_global_ctx *ctx, + const char *encoded_key, int *key_len, unsigned int *hmac, + unsigned char **key); /** - * nvme_import_tls_key_versioned() - Import a TLS key - * @ctx: struct nvme_global_ctx object + * libnvme_import_tls_key_versioned() - Import a TLS key + * @ctx: struct libnvme_global_ctx object * @encoded_key: TLS key in PSK interchange format * @version: Indicated the representation of the TLS PSK * @hmac: HMAC algorithm used to transfor the configured @@ -408,19 +409,19 @@ int nvme_import_tls_key(struct nvme_global_ctx *ctx, const char *encoded_key, * * Return: 0 on success or negative error code otherwise */ -int nvme_import_tls_key_versioned(struct nvme_global_ctx *ctx, +int libnvme_import_tls_key_versioned(struct libnvme_global_ctx *ctx, const char *encoded_key, unsigned char *version, unsigned char *hmac, size_t *key_len, unsigned char **key); /** - * nvme_generate_hostnqn() - Generate a machine specific host nqn + * libnvme_generate_hostnqn() - Generate a machine specific host nqn * Returns: An nvm namespace qualified name string based on the machine * identifier, or NULL if not successful. */ -char *nvme_generate_hostnqn(void); +char *libnvme_generate_hostnqn(void); /** - * nvme_generate_hostnqn_from_hostid() - Generate a host nqn from + * libnvme_generate_hostnqn_from_hostid() - Generate a host nqn from * host identifier * @hostid: Host identifier * @@ -430,18 +431,18 @@ char *nvme_generate_hostnqn(void); * Return: On success, an NVMe Qualified Name for host identification. This * name is based on the given host identifier. On failure, NULL. */ -char *nvme_generate_hostnqn_from_hostid(char *hostid); +char *libnvme_generate_hostnqn_from_hostid(char *hostid); /** - * nvme_generate_hostid() - Generate a machine specific host identifier + * libnvme_generate_hostid() - Generate a machine specific host identifier * * Return: On success, an identifier string based on the machine identifier to * be used as NVMe Host Identifier, or NULL on failure. */ -char *nvme_generate_hostid(void); +char *libnvme_generate_hostid(void); /** - * nvme_read_hostnqn() - Reads the host nvm qualified name from the config + * libnvme_read_hostnqn() - Reads the host nvm qualified name from the config * default location * * Retrieve the qualified name from the config file located in $SYSCONFDIR/nvme. @@ -450,10 +451,10 @@ char *nvme_generate_hostid(void); * Return: The host nqn, or NULL if unsuccessful. If found, the caller * is responsible to free the string. */ -char *nvme_read_hostnqn(void); +char *libnvme_read_hostnqn(void); /** - * nvme_read_hostid() - Reads the host identifier from the config default + * libnvme_read_hostid() - Reads the host identifier from the config default * location * * Retrieve the host idenditifer from the config file located in @@ -462,4 +463,4 @@ char *nvme_read_hostnqn(void); * Return: The host identifier, or NULL if unsuccessful. If found, the caller * is responsible to free the string. */ -char *nvme_read_hostid(void); +char *libnvme_read_hostid(void); diff --git a/libnvme/src/nvme/log.c b/libnvme/src/nvme/log.c index 705217a069..186316d988 100644 --- a/libnvme/src/nvme/log.c +++ b/libnvme/src/nvme/log.c @@ -27,10 +27,10 @@ #endif void __attribute__((format(printf, 4, 5))) -__nvme_msg(struct nvme_global_ctx *ctx, int level, +__libnvme_msg(struct libnvme_global_ctx *ctx, int level, const char *func, const char *format, ...) { - struct nvme_log *l = &ctx->log; + struct libnvme_log *l = &ctx->log; va_list ap; char pidbuf[16]; char timebuf[32]; @@ -84,7 +84,7 @@ __nvme_msg(struct nvme_global_ctx *ctx, int level, message ? message : ""); } -__public void nvme_set_logging_level(struct nvme_global_ctx *ctx, int log_level, +__public void libnvme_set_logging_level(struct libnvme_global_ctx *ctx, int log_level, bool log_pid, bool log_tstamp) { ctx->log.level = log_level; @@ -92,7 +92,7 @@ __public void nvme_set_logging_level(struct nvme_global_ctx *ctx, int log_level, ctx->log.timestamp = log_tstamp; } -__public int nvme_get_logging_level(struct nvme_global_ctx *ctx, +__public int libnvme_get_logging_level(struct libnvme_global_ctx *ctx, bool *log_pid, bool *log_tstamp) { if (log_pid) diff --git a/libnvme/src/nvme/mi-mctp.c b/libnvme/src/nvme/mi-mctp.c index d8daff4620..1e1554e1cb 100644 --- a/libnvme/src/nvme/mi-mctp.c +++ b/libnvme/src/nvme/mi-mctp.c @@ -78,7 +78,7 @@ struct mctp_ioc_tag_ctl { #define MCTP_TYPE_NVME 0x04 #define MCTP_TYPE_MIC 0x80 -struct nvme_mi_transport_mctp { +struct libnvme_mi_transport_mctp { int net; __u8 eid; int sd; @@ -94,12 +94,12 @@ static int ioctl_tag(int sd, unsigned long req, struct mctp_ioc_tag_ctl *ctl) return ioctl(sd, req, ctl); } -static int nvme_mi_msg_socket(void) +static int libnvme_mi_msg_socket(void) { return socket(AF_MCTP, SOCK_DGRAM, 0); } -static int nvme_mi_aem_socket(__u8 eid, unsigned int network) +static int libnvme_mi_aem_socket(__u8 eid, unsigned int network) { struct sockaddr_mctp local_addr = {0}, remote_addr = {0}; int sd, rc; @@ -134,23 +134,23 @@ static int nvme_mi_aem_socket(__u8 eid, unsigned int network) } static struct __mi_mctp_socket_ops ops = { - nvme_mi_msg_socket, - nvme_mi_aem_socket, + libnvme_mi_msg_socket, + libnvme_mi_aem_socket, sendmsg, recvmsg, poll, ioctl_tag, }; -void __nvme_mi_mctp_set_ops(const struct __mi_mctp_socket_ops *newops) +void __libnvme_mi_mctp_set_ops(const struct __mi_mctp_socket_ops *newops) { ops = *newops; } -static const struct nvme_mi_transport nvme_mi_transport_mctp; +static const struct libnvme_mi_transport libnvme_mi_transport_mctp; -static __u8 nvme_mi_mctp_tag_alloc(struct nvme_mi_ep *ep) +static __u8 libnvme_mi_mctp_tag_alloc(struct libnvme_mi_ep *ep) { - struct nvme_mi_transport_mctp *mctp; + struct libnvme_mi_transport_mctp *mctp; struct mctp_ioc_tag_ctl ctl = { 0 }; static bool logged; int rc; @@ -165,7 +165,7 @@ static __u8 nvme_mi_mctp_tag_alloc(struct nvme_mi_ep *ep) if (!logged) { /* not necessarily fatal, just means we can't handle * "more processing required" messages */ - nvme_msg(ep->ctx, LOG_INFO, + libnvme_msg(ep->ctx, LOG_INFO, "System does not support explicit tag allocation\n"); logged = true; } @@ -175,9 +175,9 @@ static __u8 nvme_mi_mctp_tag_alloc(struct nvme_mi_ep *ep) return ctl.tag; } -static void nvme_mi_mctp_tag_drop(struct nvme_mi_ep *ep, __u8 tag) +static void libnvme_mi_mctp_tag_drop(struct libnvme_mi_ep *ep, __u8 tag) { - struct nvme_mi_transport_mctp *mctp; + struct libnvme_mi_transport_mctp *mctp; struct mctp_ioc_tag_ctl ctl = { 0 }; mctp = ep->transport_data; @@ -191,7 +191,7 @@ static void nvme_mi_mctp_tag_drop(struct nvme_mi_ep *ep, __u8 tag) ops.ioctl_tag(mctp->sd, SIOCMCTPDROPTAG, &ctl); } -struct nvme_mi_msg_resp_mpr { +struct libnvme_mi_msg_resp_mpr { struct nvme_mi_msg_hdr hdr; __u8 status; __u8 rsvd0; @@ -204,17 +204,17 @@ struct nvme_mi_msg_resp_mpr { * buf is the incoming message data, including type byte, but excluding * the MIC which has been extracted into the mic argument already. */ -static bool nvme_mi_mctp_resp_is_mpr(void *buf, size_t len, +static bool libnvme_mi_mctp_resp_is_mpr(void *buf, size_t len, __le32 mic, unsigned int *mpr_time) { - struct nvme_mi_msg_resp_mpr *msg; + struct libnvme_mi_msg_resp_mpr *msg; __u32 crc; /* We need at least the minimal header */ if (len < sizeof(*msg)) return false; - msg = (struct nvme_mi_msg_resp_mpr *)buf; + msg = (struct libnvme_mi_msg_resp_mpr *)buf; if (msg->status != NVME_MI_RESP_MPR) return false; @@ -233,7 +233,7 @@ static bool nvme_mi_mctp_resp_is_mpr(void *buf, size_t len, * header data here, and need to preserve the resp pointer & size * values, so can't use verify_resp_mic here. */ - crc = ~nvme_mi_crc32_update(0xffffffff, buf, len); + crc = ~libnvme_mi_crc32_update(0xffffffff, buf, len); if (le32_to_cpu(mic) != crc) return false; @@ -243,11 +243,11 @@ static bool nvme_mi_mctp_resp_is_mpr(void *buf, size_t len, return true; } -static int nvme_mi_mctp_aem_fd(struct nvme_mi_ep *ep) +static int libnvme_mi_mctp_aem_fd(struct libnvme_mi_ep *ep) { - struct nvme_mi_transport_mctp *mctp; + struct libnvme_mi_transport_mctp *mctp; - if (ep->transport != &nvme_mi_transport_mctp) { + if (ep->transport != &libnvme_mi_transport_mctp) { errno = EINVAL; return -1; } @@ -256,9 +256,9 @@ static int nvme_mi_mctp_aem_fd(struct nvme_mi_ep *ep) return mctp->sd_aem; } -static int nvme_mi_mctp_aem_purge(struct nvme_mi_ep *ep) +static int libnvme_mi_mctp_aem_purge(struct libnvme_mi_ep *ep) { - struct nvme_mi_transport_mctp *mctp = ep->transport_data; + struct libnvme_mi_transport_mctp *mctp = ep->transport_data; struct msghdr msg = {0}; struct iovec iov; char buffer; @@ -276,18 +276,18 @@ static int nvme_mi_mctp_aem_purge(struct nvme_mi_ep *ep) } -static int nvme_mi_mctp_aem_read(struct nvme_mi_ep *ep, - struct nvme_mi_resp *resp) +static int libnvme_mi_mctp_aem_read(struct libnvme_mi_ep *ep, + struct libnvme_mi_resp *resp) { ssize_t len, resp_len, resp_hdr_len, resp_data_len; struct sockaddr_mctp src_addr = { 0 }; - struct nvme_mi_transport_mctp *mctp; + struct libnvme_mi_transport_mctp *mctp; struct iovec resp_iov[1]; struct msghdr resp_msg; int rc, errno_save; __le32 mic; - if (ep->transport != &nvme_mi_transport_mctp) { + if (ep->transport != &libnvme_mi_transport_mctp) { errno = EINVAL; return -1; } @@ -306,7 +306,7 @@ static int nvme_mi_mctp_aem_read(struct nvme_mi_ep *ep, if (!tmp) { errno_save = errno; - nvme_msg(ep->ctx, LOG_ERR, + libnvme_msg(ep->ctx, LOG_ERR, "Failure allocating response buffer: %m\n"); errno = errno_save; rc = -1; @@ -334,7 +334,7 @@ static int nvme_mi_mctp_aem_read(struct nvme_mi_ep *ep, goto out; errno_save = errno; - nvme_msg(ep->ctx, LOG_ERR, + libnvme_msg(ep->ctx, LOG_ERR, "Failure receiving MCTP message: %m\n"); errno = errno_save; goto out; @@ -342,13 +342,13 @@ static int nvme_mi_mctp_aem_read(struct nvme_mi_ep *ep, if (len == 0) { - nvme_msg(ep->ctx, LOG_WARNING, "No data from MCTP endpoint\n"); + libnvme_msg(ep->ctx, LOG_WARNING, "No data from MCTP endpoint\n"); errno = EIO; goto out; } if (resp_msg.msg_namelen < sizeof(src_addr)) { - nvme_msg(ep->ctx, LOG_WARNING, "Unexpected src address length\n"); + libnvme_msg(ep->ctx, LOG_WARNING, "Unexpected src address length\n"); errno = EIO; goto out; } @@ -367,7 +367,7 @@ static int nvme_mi_mctp_aem_read(struct nvme_mi_ep *ep, * plus four bytes of error data (excluding MIC). Ensure we have enough. */ if (len < 8 + sizeof(mic)) { - nvme_msg(ep->ctx, LOG_ERR, + libnvme_msg(ep->ctx, LOG_ERR, "Invalid MCTP response: too short (%zd bytes, needed %zd)\n", len, 8 + sizeof(mic)); errno = EPROTO; @@ -405,12 +405,12 @@ static int nvme_mi_mctp_aem_read(struct nvme_mi_ep *ep, return rc; } -static int nvme_mi_mctp_submit(struct nvme_mi_ep *ep, - struct nvme_mi_req *req, - struct nvme_mi_resp *resp) +static int libnvme_mi_mctp_submit(struct libnvme_mi_ep *ep, + struct libnvme_mi_req *req, + struct libnvme_mi_resp *resp) { ssize_t len, resp_len, resp_hdr_len, resp_data_len; - struct nvme_mi_transport_mctp *mctp; + struct libnvme_mi_transport_mctp *mctp; struct iovec req_iov[3], resp_iov[1]; struct msghdr req_msg, resp_msg; int i, rc, errno_save, timeout; @@ -420,7 +420,7 @@ static int nvme_mi_mctp_submit(struct nvme_mi_ep *ep, __le32 mic; __u8 tag; - if (ep->transport != &nvme_mi_transport_mctp) { + if (ep->transport != &libnvme_mi_transport_mctp) { errno = EINVAL; return -1; } @@ -432,7 +432,7 @@ static int nvme_mi_mctp_submit(struct nvme_mi_ep *ep, } mctp = ep->transport_data; - tag = nvme_mi_mctp_tag_alloc(ep); + tag = libnvme_mi_mctp_tag_alloc(ep); memset(&addr, 0, sizeof(addr)); addr.smctp_family = AF_MCTP; @@ -466,7 +466,7 @@ static int nvme_mi_mctp_submit(struct nvme_mi_ep *ep, len = ops.sendmsg(mctp->sd, &req_msg, 0); if (len < 0) { errno_save = errno; - nvme_msg(ep->ctx, LOG_ERR, + libnvme_msg(ep->ctx, LOG_ERR, "Failure sending MCTP message: %m\n"); errno = errno_save; rc = -1; @@ -478,7 +478,7 @@ static int nvme_mi_mctp_submit(struct nvme_mi_ep *ep, void *tmp = realloc(mctp->resp_buf, resp_len); if (!tmp) { errno_save = errno; - nvme_msg(ep->ctx, LOG_ERR, + libnvme_msg(ep->ctx, LOG_ERR, "Failure allocating response buffer: %m\n"); errno = errno_save; rc = -1; @@ -507,14 +507,14 @@ static int nvme_mi_mctp_submit(struct nvme_mi_ep *ep, if (errno == EINTR) goto retry; errno_save = errno; - nvme_msg(ep->ctx, LOG_ERR, + libnvme_msg(ep->ctx, LOG_ERR, "Failed polling on MCTP socket: %m"); errno = errno_save; goto out; } if (rc == 0) { - nvme_msg(ep->ctx, LOG_DEBUG, "Timeout on MCTP socket"); + libnvme_msg(ep->ctx, LOG_DEBUG, "Timeout on MCTP socket"); errno = ETIMEDOUT; rc = -1; goto out; @@ -525,7 +525,7 @@ static int nvme_mi_mctp_submit(struct nvme_mi_ep *ep, if (len < 0) { errno_save = errno; - nvme_msg(ep->ctx, LOG_ERR, + libnvme_msg(ep->ctx, LOG_ERR, "Failure receiving MCTP message: %m\n"); errno = errno_save; goto out; @@ -533,7 +533,7 @@ static int nvme_mi_mctp_submit(struct nvme_mi_ep *ep, if (len == 0) { - nvme_msg(ep->ctx, LOG_WARNING, "No data from MCTP endpoint\n"); + libnvme_msg(ep->ctx, LOG_WARNING, "No data from MCTP endpoint\n"); errno = EIO; goto out; } @@ -546,7 +546,7 @@ static int nvme_mi_mctp_submit(struct nvme_mi_ep *ep, * plus four bytes of error data (excluding MIC). Ensure we have enough. */ if (len < 8 + sizeof(mic)) { - nvme_msg(ep->ctx, LOG_ERR, + libnvme_msg(ep->ctx, LOG_ERR, "Invalid MCTP response: too short (%zd bytes, needed %zd)\n", len, 8 + sizeof(mic)); errno = EPROTO; @@ -567,8 +567,8 @@ static int nvme_mi_mctp_submit(struct nvme_mi_ep *ep, * header fields. However, we need to do this in the transport in order * to keep the tag allocated and retry the recvmsg */ - if (nvme_mi_mctp_resp_is_mpr(mctp->resp_buf, len, mic, &mpr_time)) { - nvme_msg(ep->ctx, LOG_DEBUG, + if (libnvme_mi_mctp_resp_is_mpr(mctp->resp_buf, len, mic, &mpr_time)) { + libnvme_msg(ep->ctx, LOG_DEBUG, "Received More Processing Required, waiting for response\n"); /* if the controller hasn't set MPRT, fall back to our command/ @@ -604,16 +604,16 @@ static int nvme_mi_mctp_submit(struct nvme_mi_ep *ep, rc = 0; out: - nvme_mi_mctp_tag_drop(ep, tag); + libnvme_mi_mctp_tag_drop(ep, tag); return rc; } -static void nvme_mi_mctp_close(struct nvme_mi_ep *ep) +static void libnvme_mi_mctp_close(struct libnvme_mi_ep *ep) { - struct nvme_mi_transport_mctp *mctp; + struct libnvme_mi_transport_mctp *mctp; - if (ep->transport != &nvme_mi_transport_mctp) + if (ep->transport != &libnvme_mi_transport_mctp) return; mctp = ep->transport_data; @@ -625,11 +625,11 @@ static void nvme_mi_mctp_close(struct nvme_mi_ep *ep) free(ep->transport_data); } -static int nvme_mi_mctp_desc_ep(struct nvme_mi_ep *ep, char *buf, size_t len) +static int libnvme_mi_mctp_desc_ep(struct libnvme_mi_ep *ep, char *buf, size_t len) { - struct nvme_mi_transport_mctp *mctp; + struct libnvme_mi_transport_mctp *mctp; - if (ep->transport != &nvme_mi_transport_mctp) { + if (ep->transport != &libnvme_mi_transport_mctp) { errno = EINVAL; return -1; } @@ -641,22 +641,22 @@ static int nvme_mi_mctp_desc_ep(struct nvme_mi_ep *ep, char *buf, size_t len) return 0; } -static const struct nvme_mi_transport nvme_mi_transport_mctp = { +static const struct libnvme_mi_transport libnvme_mi_transport_mctp = { .name = "mctp", .mic_enabled = true, - .submit = nvme_mi_mctp_submit, - .close = nvme_mi_mctp_close, - .desc_ep = nvme_mi_mctp_desc_ep, - .aem_read = nvme_mi_mctp_aem_read, - .aem_fd = nvme_mi_mctp_aem_fd, - .aem_purge = nvme_mi_mctp_aem_purge, + .submit = libnvme_mi_mctp_submit, + .close = libnvme_mi_mctp_close, + .desc_ep = libnvme_mi_mctp_desc_ep, + .aem_read = libnvme_mi_mctp_aem_read, + .aem_fd = libnvme_mi_mctp_aem_fd, + .aem_purge = libnvme_mi_mctp_aem_purge, }; -int nvme_mi_aem_open(nvme_mi_ep_t ep) +int libnvme_mi_aem_open(libnvme_mi_ep_t ep) { - struct nvme_mi_transport_mctp *mctp; + struct libnvme_mi_transport_mctp *mctp; - if (ep->transport != &nvme_mi_transport_mctp) { + if (ep->transport != &libnvme_mi_transport_mctp) { errno = EINVAL; return -1; } @@ -675,14 +675,14 @@ int nvme_mi_aem_open(nvme_mi_ep_t ep) return 0; } -__public nvme_mi_ep_t nvme_mi_open_mctp(struct nvme_global_ctx *ctx, +__public libnvme_mi_ep_t libnvme_mi_open_mctp(struct libnvme_global_ctx *ctx, unsigned int netid, __u8 eid) { - struct nvme_mi_transport_mctp *mctp; - struct nvme_mi_ep *ep; + struct libnvme_mi_transport_mctp *mctp; + struct libnvme_mi_ep *ep; int errno_save; - ep = nvme_mi_init_ep(ctx); + ep = libnvme_mi_init_ep(ctx); if (!ep) return NULL; @@ -719,7 +719,7 @@ __public nvme_mi_ep_t nvme_mi_open_mctp(struct nvme_global_ctx *ctx, goto err_free_aem_rspbuf; } - ep->transport = &nvme_mi_transport_mctp; + ep->transport = &libnvme_mi_transport_mctp; ep->transport_data = mctp; /* Assuming an i2c transport at 100kHz, smallest MTU (64+4). Given @@ -739,30 +739,30 @@ __public nvme_mi_ep_t nvme_mi_open_mctp(struct nvme_global_ctx *ctx, free(mctp); err_close_ep: /* the ep->transport is not set yet, so this will not call back - * into nvme_mi_mctp_close() */ - nvme_mi_close(ep); + * into libnvme_mi_mctp_close() */ + libnvme_mi_close(ep); errno = errno_save; return NULL; } #ifdef CONFIG_DBUS -static int nvme_mi_mctp_add(struct nvme_global_ctx *ctx, unsigned int netid, __u8 eid) +static int libnvme_mi_mctp_add(struct libnvme_global_ctx *ctx, unsigned int netid, __u8 eid) { - nvme_mi_ep_t ep = NULL; + libnvme_mi_ep_t ep = NULL; /* ensure we don't already have an endpoint with the same net/eid. if * we do, just skip, no need to re-add. */ list_for_each(&ctx->endpoints, ep, root_entry) { - if (ep->transport != &nvme_mi_transport_mctp) { + if (ep->transport != &libnvme_mi_transport_mctp) { continue; } - const struct nvme_mi_transport_mctp *t = ep->transport_data; + const struct libnvme_mi_transport_mctp *t = ep->transport_data; if (t->eid == eid && t->net == netid) return 0; } - ep = nvme_mi_open_mctp(ctx, netid, eid); + ep = libnvme_mi_open_mctp(ctx, netid, eid); if (!ep) return -1; @@ -812,7 +812,7 @@ static bool has_message_type(DBusMessageIter *prop, uint8_t type) return false; } -static int handle_mctp_endpoint(struct nvme_global_ctx *ctx, const char* objpath, +static int handle_mctp_endpoint(struct libnvme_global_ctx *ctx, const char* objpath, DBusMessageIter *props) { bool have_eid = false, have_net = false, have_nvmemi = false; @@ -828,7 +828,7 @@ static int handle_mctp_endpoint(struct nvme_global_ctx *ctx, const char* objpath dbus_message_iter_recurse(props, &prop); if (!dbus_object_is_type(&prop, DBUS_TYPE_STRING)) { - nvme_msg(ctx, LOG_ERR, + libnvme_msg(ctx, LOG_ERR, "error unmashalling object (propname)\n"); return -1; } @@ -838,7 +838,7 @@ static int handle_mctp_endpoint(struct nvme_global_ctx *ctx, const char* objpath dbus_message_iter_next(&prop); if (!dbus_object_is_type(&prop, DBUS_TYPE_VARIANT)) { - nvme_msg(ctx, LOG_ERR, + libnvme_msg(ctx, LOG_ERR, "error unmashalling object (propval)\n"); return -1; } @@ -866,15 +866,15 @@ static int handle_mctp_endpoint(struct nvme_global_ctx *ctx, const char* objpath if (have_nvmemi) { if (!(have_eid && have_net)) { - nvme_msg(ctx, LOG_ERR, + libnvme_msg(ctx, LOG_ERR, "Missing property for %s\n", objpath); errno = ENOENT; return -1; } - rc = nvme_mi_mctp_add(ctx, net, eid); + rc = libnvme_mi_mctp_add(ctx, net, eid); if (rc < 0) { int errno_save = errno; - nvme_msg(ctx, LOG_ERR, + libnvme_msg(ctx, LOG_ERR, "Error adding net %d eid %d: %m\n", net, eid); errno = errno_save; } @@ -888,13 +888,13 @@ static int handle_mctp_endpoint(struct nvme_global_ctx *ctx, const char* objpath /* obj is an array of (object path, interfaces) dict entries - ie., dbus type * a{oa{sa{sv}}} */ -static int handle_mctp_obj(struct nvme_global_ctx *ctx, DBusMessageIter *obj) +static int handle_mctp_obj(struct libnvme_global_ctx *ctx, DBusMessageIter *obj) { const char *objpath = NULL; DBusMessageIter intfs; if (!dbus_object_is_type(obj, DBUS_TYPE_OBJECT_PATH)) { - nvme_msg(ctx, LOG_ERR, "error unmashalling object (path)\n"); + libnvme_msg(ctx, LOG_ERR, "error unmashalling object (path)\n"); return -1; } @@ -903,7 +903,7 @@ static int handle_mctp_obj(struct nvme_global_ctx *ctx, DBusMessageIter *obj) dbus_message_iter_next(obj); if (!dbus_object_is_dict(obj)) { - nvme_msg(ctx, LOG_ERR, "error unmashalling object (intfs)\n"); + libnvme_msg(ctx, LOG_ERR, "error unmashalling object (intfs)\n"); return -1; } @@ -917,7 +917,7 @@ static int handle_mctp_obj(struct nvme_global_ctx *ctx, DBusMessageIter *obj) dbus_message_iter_recurse(&intfs, &intf); if (!dbus_object_is_type(&intf, DBUS_TYPE_STRING)) { - nvme_msg(ctx, LOG_ERR, + libnvme_msg(ctx, LOG_ERR, "error unmashalling object (intf)\n"); return -1; } @@ -933,7 +933,7 @@ static int handle_mctp_obj(struct nvme_global_ctx *ctx, DBusMessageIter *obj) dbus_message_iter_next(&intf); if (!dbus_object_is_dict(&intf)) { - nvme_msg(ctx, LOG_ERR, + libnvme_msg(ctx, LOG_ERR, "error unmarshalling object (props)\n"); return -1; } @@ -945,17 +945,17 @@ static int handle_mctp_obj(struct nvme_global_ctx *ctx, DBusMessageIter *obj) return 0; } -__public struct nvme_global_ctx *nvme_mi_scan_mctp(void) +__public struct libnvme_global_ctx *libnvme_mi_scan_mctp(void) { DBusMessage *msg, *resp = NULL; DBusConnection *bus = NULL; DBusMessageIter args, objs; int errno_save, rc = -1; - struct nvme_global_ctx *ctx; + struct libnvme_global_ctx *ctx; dbus_bool_t drc; DBusError berr; - ctx = nvme_create_global_ctx(NULL, DEFAULT_LOGLEVEL); + ctx = libnvme_create_global_ctx(NULL, DEFAULT_LOGLEVEL); if (!ctx) { errno = ENOMEM; return NULL; @@ -965,7 +965,7 @@ __public struct nvme_global_ctx *nvme_mi_scan_mctp(void) bus = dbus_bus_get(DBUS_BUS_SYSTEM, &berr); if (!bus) { - nvme_msg(ctx, LOG_ERR, "Failed connecting to D-Bus: %s (%s)\n", + libnvme_msg(ctx, LOG_ERR, "Failed connecting to D-Bus: %s (%s)\n", berr.message, berr.name); goto out; } @@ -975,7 +975,7 @@ __public struct nvme_global_ctx *nvme_mi_scan_mctp(void) "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); if (!msg) { - nvme_msg(ctx, LOG_ERR, "Failed creating call message\n"); + libnvme_msg(ctx, LOG_ERR, "Failed creating call message\n"); goto out; } @@ -984,7 +984,7 @@ __public struct nvme_global_ctx *nvme_mi_scan_mctp(void) &berr); dbus_message_unref(msg); if (!resp) { - nvme_msg(ctx, LOG_ERR, "Failed querying MCTP D-Bus: %s (%s)\n", + libnvme_msg(ctx, LOG_ERR, "Failed querying MCTP D-Bus: %s (%s)\n", berr.message, berr.name); goto out; } @@ -992,12 +992,12 @@ __public struct nvme_global_ctx *nvme_mi_scan_mctp(void) /* argument container */ drc = dbus_message_iter_init(resp, &args); if (!drc) { - nvme_msg(ctx, LOG_ERR, "can't read dbus reply args\n"); + libnvme_msg(ctx, LOG_ERR, "can't read dbus reply args\n"); goto out; } if (!dbus_object_is_dict(&args)) { - nvme_msg(ctx, LOG_ERR, "error unmashalling args\n"); + libnvme_msg(ctx, LOG_ERR, "error unmashalling args\n"); goto out; } @@ -1029,7 +1029,7 @@ __public struct nvme_global_ctx *nvme_mi_scan_mctp(void) if (rc < 0) { if (ctx) { - nvme_free_global_ctx(ctx); + libnvme_free_global_ctx(ctx); } errno = errno_save; ctx = NULL; @@ -1039,7 +1039,7 @@ __public struct nvme_global_ctx *nvme_mi_scan_mctp(void) #else /* CONFIG_DBUS */ -__public struct nvme_global_ctx *nvme_mi_scan_mctp(void) +__public struct libnvme_global_ctx *libnvme_mi_scan_mctp(void) { return NULL; } diff --git a/libnvme/src/nvme/mi-types.h b/libnvme/src/nvme/mi-types.h new file mode 100644 index 0000000000..3c5f0566c5 --- /dev/null +++ b/libnvme/src/nvme/mi-types.h @@ -0,0 +1,561 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later +/* + * This file is part of libnvme. + * Copyright (c) 2021 Code Construct Pty Ltd + * + * Authors: Jeremy Kerr + */ +#pragma once + +#include +#include + +#include + +/** + * NVME_MI_MSGTYPE_NVME - MCTP message type for NVMe-MI messages. + * + * This is defined by MCTP, but is referenced as part of the NVMe-MI message + * spec. This is the MCTP NVMe message type (0x4), with the message-integrity + * bit (0x80) set. + */ +#define NVME_MI_MSGTYPE_NVME 0x84 + +/* Basic MI message definitions */ + +/** + * enum nvme_mi_message_type - NVMe-MI message type field. + * @NVME_MI_MT_CONTROL: NVME-MI Control Primitive + * @NVME_MI_MT_MI: NVMe-MI command + * @NVME_MI_MT_ADMIN: NVMe Admin command + * @NVME_MI_MT_PCIE: PCIe command + * @NVME_MI_MT_AE: Asynchronous Event + * + * Used as byte 1 of both request and response messages (NMIMT bits of NMP + * byte). Not to be confused with the MCTP message type in byte 0. + */ +enum nvme_mi_message_type { + NVME_MI_MT_CONTROL = 0, + NVME_MI_MT_MI = 1, + NVME_MI_MT_ADMIN = 2, + NVME_MI_MT_PCIE = 4, + NVME_MI_MT_AE = 5, +}; + +/** + * enum nvme_mi_ror: Request or response field. + * @NVME_MI_ROR_REQ: request message + * @NVME_MI_ROR_RSP: response message + */ +enum nvme_mi_ror { + NVME_MI_ROR_REQ = 0, + NVME_MI_ROR_RSP = 1, +}; + +/** + * enum nvme_mi_resp_status - values for the response status field + * @NVME_MI_RESP_SUCCESS: success + * @NVME_MI_RESP_MPR: More Processing Required + * @NVME_MI_RESP_INTERNAL_ERR: Internal Error + * @NVME_MI_RESP_INVALID_OPCODE: Invalid command opcode + * @NVME_MI_RESP_INVALID_PARAM: Invalid command parameter + * @NVME_MI_RESP_INVALID_CMD_SIZE: Invalid command size + * @NVME_MI_RESP_INVALID_INPUT_SIZE: Invalid command input data size + * @NVME_MI_RESP_ACCESS_DENIED: Access Denied + * @NVME_MI_RESP_VPD_UPDATES_EXCEEDED: More VPD updates than allowed + * @NVME_MI_RESP_PCIE_INACCESSIBLE: PCIe functionality currently unavailable + * @NVME_MI_RESP_MEB_SANITIZED: MEB has been cleared due to sanitize + * @NVME_MI_RESP_ENC_SERV_FAILURE: Enclosure services process failed + * @NVME_MI_RESP_ENC_SERV_XFER_FAILURE: Transfer with enclosure services failed + * @NVME_MI_RESP_ENC_FAILURE: Unreoverable enclosure failure + * @NVME_MI_RESP_ENC_XFER_REFUSED: Enclosure services transfer refused + * @NVME_MI_RESP_ENC_FUNC_UNSUP: Unsupported enclosure services function + * @NVME_MI_RESP_ENC_SERV_UNAVAIL: Enclosure services unavailable + * @NVME_MI_RESP_ENC_DEGRADED: Noncritical failure detected by enc. services + * @NVME_MI_RESP_SANITIZE_IN_PROGRESS: Command prohibited during sanitize + */ +enum nvme_mi_resp_status { + NVME_MI_RESP_SUCCESS = 0x00, + NVME_MI_RESP_MPR = 0x01, + NVME_MI_RESP_INTERNAL_ERR = 0x02, + NVME_MI_RESP_INVALID_OPCODE = 0x03, + NVME_MI_RESP_INVALID_PARAM = 0x04, + NVME_MI_RESP_INVALID_CMD_SIZE = 0x05, + NVME_MI_RESP_INVALID_INPUT_SIZE = 0x06, + NVME_MI_RESP_ACCESS_DENIED = 0x07, + /* 0x08 - 0x1f: reserved */ + NVME_MI_RESP_VPD_UPDATES_EXCEEDED = 0x20, + NVME_MI_RESP_PCIE_INACCESSIBLE = 0x21, + NVME_MI_RESP_MEB_SANITIZED = 0x22, + NVME_MI_RESP_ENC_SERV_FAILURE = 0x23, + NVME_MI_RESP_ENC_SERV_XFER_FAILURE = 0x24, + NVME_MI_RESP_ENC_FAILURE = 0x25, + NVME_MI_RESP_ENC_XFER_REFUSED = 0x26, + NVME_MI_RESP_ENC_FUNC_UNSUP = 0x27, + NVME_MI_RESP_ENC_SERV_UNAVAIL = 0x28, + NVME_MI_RESP_ENC_DEGRADED = 0x29, + NVME_MI_RESP_SANITIZE_IN_PROGRESS = 0x2a, + /* 0x2b - 0xdf: reserved */ + /* 0xe0 - 0xff: vendor specific */ +}; + +/** + * struct nvme_mi_msg_hdr - General MI message header. + * @type: MCTP message type, will always be NVME_MI_MSGTYPE_NVME + * @nmp: NVMe-MI message parameters (including MI message type) + * @meb: Management Endpoint Buffer flag; unused for libnvme-mi implementation + * @rsvd0: currently reserved + * + * Wire format shared by both request and response messages, per NVMe-MI + * section 3.1. This is used for all message types, MI and Admin. + */ +struct nvme_mi_msg_hdr { + __u8 type; + __u8 nmp; + __u8 meb; + __u8 rsvd0; +} __attribute__((packed)); + +/** + * struct nvme_mi_msg_resp - Generic response type. + * @hdr: the general request/response message header + * @status: response status value (see &enum nvme_mi_resp_status) + * @rsvd0: reserved data, may be defined by specific response + * + * Every response will start with one of these; command-specific responses + * will define parts of the reserved data, and may add further fields. + */ +struct nvme_mi_msg_resp { + struct nvme_mi_msg_hdr hdr; + __u8 status; + __u8 rsvd0[3]; +}; + +/** + * enum nvme_mi_mi_opcode - Operation code for supported NVMe-MI commands. + * @nvme_mi_mi_opcode_mi_data_read: Read NVMe-MI Data Structure + * @nvme_mi_mi_opcode_subsys_health_status_poll: Subsystem Health Status Poll + * @nvme_mi_mi_opcode_configuration_set: MI Configuration Set + * @nvme_mi_mi_opcode_configuration_get: MI Configuration Get + */ +enum nvme_mi_mi_opcode { + nvme_mi_mi_opcode_mi_data_read = 0x00, + nvme_mi_mi_opcode_subsys_health_status_poll = 0x01, + nvme_mi_mi_opcode_configuration_set = 0x03, + nvme_mi_mi_opcode_configuration_get = 0x04, +}; + +/** + * struct nvme_mi_mi_req_hdr - MI request message header. + * @hdr: generic MI message header + * @opcode: opcode (OPC) for the specific MI command + * @rsvd0: reserved bytes + * @cdw0: Management Request Doubleword 0 - command specific usage + * @cdw1: Management Request Doubleword 1 - command specific usage + * + * Wire format for MI request message headers, defined in section 5 of NVMe-MI. + */ +struct nvme_mi_mi_req_hdr { + struct nvme_mi_msg_hdr hdr; + __u8 opcode; + __u8 rsvd0[3]; + __le32 cdw0, cdw1; +}; + +/** + * struct nvme_mi_mi_resp_hdr - MI response message header. + * @hdr: generic MI message header + * @status: generic response status from command; non-zero on failure. + * @nmresp: NVMe Management Response: command-type-specific response data + * + * Wire format for MI response message header, defined in section 5 of NVMe-MI. + */ +struct nvme_mi_mi_resp_hdr { + struct nvme_mi_msg_hdr hdr; + __u8 status; + __u8 nmresp[3]; +}; + +/** + * enum nvme_mi_dtyp - Data Structure Type field. + * @nvme_mi_dtyp_subsys_info: NVM Subsystem Information + * @nvme_mi_dtyp_port_info: Port information + * @nvme_mi_dtyp_ctrl_list: Controller List + * @nvme_mi_dtyp_ctrl_info: Controller Information + * @nvme_mi_dtyp_opt_cmd_support: Optionally Supported Command List + * @nvme_mi_dtyp_meb_support: Management Endpoint Buffer Command Support List + * + * Data Structure Type field for Read NVMe-MI Data Structure command, used to + * indicate the particular structure to query from the endpoint. + */ +enum nvme_mi_dtyp { + nvme_mi_dtyp_subsys_info = 0x00, + nvme_mi_dtyp_port_info = 0x01, + nvme_mi_dtyp_ctrl_list = 0x02, + nvme_mi_dtyp_ctrl_info = 0x03, + nvme_mi_dtyp_opt_cmd_support = 0x04, + nvme_mi_dtyp_meb_support = 0x05, +}; + +/** + * enum nvme_mi_config_id - NVMe-MI Configuration identifier. + * @NVME_MI_CONFIG_SMBUS_FREQ: Current SMBus/I2C frequency + * @NVME_MI_CONFIG_HEALTH_STATUS_CHANGE: Health Status change - used to clear + * health status bits in CCS bits of + * status poll. Only for Set ops. + * @NVME_MI_CONFIG_MCTP_MTU: MCTP maximum transmission unit size of port + * specified in dw 0 + * @NVME_MI_CONFIG_AE: Asynchronous Events configuration + * Configuration parameters for the MI Get/Set Configuration commands. + * + * See &nvme_mi_mi_config_get() and &nvme_mi_config_set(). + */ +enum nvme_mi_config_id { + NVME_MI_CONFIG_SMBUS_FREQ = 0x1, + NVME_MI_CONFIG_HEALTH_STATUS_CHANGE = 0x2, + NVME_MI_CONFIG_MCTP_MTU = 0x3, + NVME_MI_CONFIG_AE = 0x4, +}; + +/** + * enum nvme_mi_config_smbus_freq - SMBus/I2C frequency values + * @NVME_MI_CONFIG_SMBUS_FREQ_100kHz: 100kHz + * @NVME_MI_CONFIG_SMBUS_FREQ_400kHz: 400kHz + * @NVME_MI_CONFIG_SMBUS_FREQ_1MHz: 1MHz + * + * Values used in the SMBus Frequency device configuration. See + * &nvme_mi_mi_config_get_smbus_freq() and &nvme_mi_mi_config_set_smbus_freq(). + */ +enum nvme_mi_config_smbus_freq { + NVME_MI_CONFIG_SMBUS_FREQ_100kHz = 0x1, + NVME_MI_CONFIG_SMBUS_FREQ_400kHz = 0x2, + NVME_MI_CONFIG_SMBUS_FREQ_1MHz = 0x3, +}; + +/* Asynchronous Event Message definitions*/ + +/** + * struct nvme_mi_aem_supported_list_header - Asynchronous Event Supported List Header. + * @numaes: Number of AE supported data structures that follow the header + * @aeslver: AE Supported List Version + * @aest: AE Supported list length (including this header) + * @aeslhl: AE Supported list header length + * + * This header preceeds a number, (&numaes), of AE supported data structures + */ +struct nvme_mi_aem_supported_list_header { + __u8 numaes; + __u8 aeslver;//Should be zero + __le16 aest; + __u8 aeslhl; //Should be 5 +} __attribute__((packed)); + +/** + * struct nvme_mi_aem_supported_item - AE Supported List Item + * @aesl: AE supported list item length + * @aesi: AE supported info + * + * Following this header should be hdr.numaes entries of + * nvme_mi_aem_supported_item structures + */ +struct nvme_mi_aem_supported_item { + __u8 aesl;//Length of this item. Set to 3 + __le16 aesi; +} __attribute__((packed)); + +/** + * nvme_mi_aem_aesi_get_aese() - return aese from aesi field + * @aesi: aesi field from @nvme_mi_aem_supported_item + * + * Returns: A bool representing the aese value + */ +bool nvme_mi_aem_aesi_get_aese(__le16 aesi); + +/** + * nvme_mi_aem_aesi_get_aesid() - return aesid from aesi field + * @aesi: aesi field from @nvme_mi_aem_supported_item + * + * Returns: aesid value + */ +__u8 nvme_mi_aem_aesi_get_aesid(__le16 aesi); + +/** + * nvme_mi_aem_aesi_set_aesid() - set aesid in the aesi field + * @item: Pointer to @nvme_mi_aem_supported_item to update the aesi field + * @aesid: aesid value to use + */ +void nvme_mi_aem_aesi_set_aesid(struct nvme_mi_aem_supported_item *item, __u8 aesid); + +/** + * nvme_mi_aem_aesi_set_aee() - set aee in the aesi field + * @item: Pointer to @nvme_mi_aem_supported_item to update the aesi field + * @enabled: aee value to use + */ +void nvme_mi_aem_aesi_set_aee(struct nvme_mi_aem_supported_item *item, bool enabled); + +/** + * struct nvme_mi_aem_supported_list - AE Supported List received with GET CONFIG Asynchronous Event + * @hdr: AE supported list header + * + * Following this header should be hdr.numaes entries of + * nvme_mi_aem_supported_item structures + */ +struct nvme_mi_aem_supported_list { + struct nvme_mi_aem_supported_list_header hdr; +} __attribute__((packed)); + +/** + * struct nvme_mi_aem_enable_item - AE Enabled item entry + * @aeel: AE Enable Length (length of this structure which is 3) + * @aeei: AE Enable Info + * + */ +struct nvme_mi_aem_enable_item { + __u8 aeel; + __le16 aeei; +} __attribute__((packed)); + +/** + * nvme_mi_aem_aeei_get_aee() - return aee from aeei field + * @aeei: aeei field from @nvme_mi_aem_enable_item + * + * Returns: aee value + */ +bool nvme_mi_aem_aeei_get_aee(__le16 aeei); + +/** + * nvme_mi_aem_aeei_get_aeeid() - return aeeid from aeei field + * @aeei: aeei field from @nvme_mi_aem_enable_item + * + * Returns: aeeid value + */ +__u8 nvme_mi_aem_aeei_get_aeeid(__le16 aeei); + +/** + * nvme_mi_aem_aeei_set_aeeid() - set aeeid in the aeei field + * @item: Pointer to @nvme_mi_aem_enable_item to update the aeei field + * @aeeid: aeeid value to use + */ +void nvme_mi_aem_aeei_set_aeeid(struct nvme_mi_aem_enable_item *item, __u8 aeeid); + +/** + * nvme_mi_aem_aeei_set_aee() - set aee in the aeei field + * @item: Pointer to @nvme_mi_aem_enable_item to update the aee field + * @enabled: aee value to use + */ +void nvme_mi_aem_aeei_set_aee(struct nvme_mi_aem_enable_item *item, bool enabled); + +/** + * struct nvme_mi_aem_enable_list_header - AE Enable list header + * @numaee: Number of AE enable items following the header + * @aeelver: Version of the AE enable list (zero) + * @aeetl: Total length of the AE enable list including header and items + * @aeelhl: Header length of this header (5) + */ +struct nvme_mi_aem_enable_list_header { + __u8 numaee; + __u8 aeelver; + __le16 aeetl; + __u8 aeelhl; +} __attribute__((packed)); + +/** + * struct nvme_mi_aem_enable_list - AE enable list sent with SET CONFIG Asyncronous Event + * @hdr: AE enable list header + * + * Following this header should be hdr.numaee entries of nvme_mi_aem_enable_item structures + */ +struct nvme_mi_aem_enable_list { + struct nvme_mi_aem_enable_list_header hdr; +} __attribute__((packed)); + +/** + * struct nvme_mi_aem_occ_data - AEM Message definition. + * @aelhlen: AE Occurrence Header Length + * @aeosil: AE Occurrence Specific Info Length + * @aeovsil: AE Occurrence Vendor Specific Info Length + * @aeoui: AE Occurrence Unique ID made up of other subfields + * + * A single entry of ae occurrence data that comes with an nvme_aem_msg. + * Following this structure is variable length AEOSI (occurrence specific + * info) and variable length AEVSI (vendor specific info). The length of + * AEOSI is specified by aeosil and the length of AEVSI is specified by + * AEVSI. Neither field is mandatory and shall be omitted if their length + * parameter is set to zero. + */ +struct nvme_mi_aem_occ_data { + __u8 aelhlen; + __u8 aeosil; + __u8 aeovsil; + struct { + __u8 aeoi; + __le32 aeocidi; + __u8 aessi; + } __attribute__((packed)) aeoui; +} __attribute__((packed)); + +/** + * struct nvme_mi_aem_occ_list_hdr - AE occurrence list header + * @numaeo: Number of AE Occurrence Data Structures + * @aelver: AE Occurrence List Version Number + * @aeolli: AE Occurrence List Length Info (AEOLLI) + * @aeolhl: AE Occurrence List Header Length (shall be set to 7) + * @aemti: AEM Transmission Info + * + * The header for the occurrence list. numaeo defines how many + * nvme_mi_aem_occ_data structures (including variable payaloads) are included. + * Following this header is each of the numaeo occurrence data structures. + */ +struct nvme_mi_aem_occ_list_hdr { + __u8 numaeo; + __u8 aelver; + __u8 aeolli[3];//24-bits + __u8 aeolhl; + __u8 aemti; +} __attribute__((packed)); + +/** + * nvme_mi_aem_aemti_get_aemgn() - return aemgn from aemti field + * @aemti: aemti field from @nvme_mi_aem_occ_list_hdr + * + * Returns: aemgn value + */ +__u8 nvme_mi_aem_aemti_get_aemgn(__u8 aemti); + +/** + * nvme_mi_aem_aeolli_get_aeoltl() - return aeoltl from aeolli field + * @aeolli: Pointer to 3 byte aeolli field from @nvme_mi_aem_occ_list_hdr + * + * Returns: aeoltl value + */ +__u32 nvme_mi_aem_aeolli_get_aeoltl(__u8 *aeolli); + +/** + * nvme_mi_aem_aeolli_set_aeoltl() - set aeoltl in the aeolli field + * @hdr:Pointer to @nvme_mi_aem_occ_list_hdr to set the aeolli field + * @aeoltl: aeoltl value to use + */ +void nvme_mi_aem_aeolli_set_aeoltl(struct nvme_mi_aem_occ_list_hdr *hdr, __u32 aeoltl); + +/** + * struct nvme_mi_aem_msg - AEM Message definition. + * @hdr: the general response message header + * @occ_list_hdr: ae occurrence list header. + * + * Every ae message will start with one of these. The occ_list_hder wil define + * information about how many ae occ data entries are included. Each entry is + * defined by the nvme_mi_aem_occ_data structure which will follow the + * occ_list_hdr. Each nvme_mi_aem_occ_data structure has a fixed length header + * but a variable length payload ude to occurrence specific and vendor specific + * info. For this reason, do not index the nvme_mi_ae_occ data structures by + * array or fixed offset. + */ +struct nvme_mi_aem_msg { + struct nvme_mi_msg_hdr hdr; + struct nvme_mi_aem_occ_list_hdr occ_list_hdr; +} __attribute__((packed)); + +/* Admin command definitions */ + +/** + * struct nvme_mi_admin_req_hdr - Admin command request header. + * @hdr: Generic MI message header + * @opcode: Admin command opcode (using enum nvme_admin_opcode) + * @flags: Command Flags, indicating dlen and doff validity; Only defined in + * NVMe-MI version 1.1, no fields defined in 1.2 (where the dlen/doff + * are always considered valid). + * @ctrl_id: Controller ID target of command + * @cdw1: Submission Queue Entry doubleword 1 + * @cdw2: Submission Queue Entry doubleword 2 + * @cdw3: Submission Queue Entry doubleword 3 + * @cdw4: Submission Queue Entry doubleword 4 + * @cdw5: Submission Queue Entry doubleword 5 + * @doff: Offset of data to return from command + * @dlen: Length of sent/returned data + * @rsvd0: Reserved + * @rsvd1: Reserved + * @cdw10: Submission Queue Entry doubleword 10 + * @cdw11: Submission Queue Entry doubleword 11 + * @cdw12: Submission Queue Entry doubleword 12 + * @cdw13: Submission Queue Entry doubleword 13 + * @cdw14: Submission Queue Entry doubleword 14 + * @cdw15: Submission Queue Entry doubleword 15 + * + * Wire format for Admin command message headers, defined in section 6 of + * NVMe-MI. + */ +struct nvme_mi_admin_req_hdr { + struct nvme_mi_msg_hdr hdr; + __u8 opcode; + __u8 flags; + __le16 ctrl_id; + __le32 cdw1, cdw2, cdw3, cdw4, cdw5; + __le32 doff; + __le32 dlen; + __le32 rsvd0, rsvd1; + __le32 cdw10, cdw11, cdw12, cdw13, cdw14, cdw15; +} __attribute((packed)); + +/** + * struct nvme_mi_admin_resp_hdr - Admin command response header. + * @hdr: Generic MI message header + * @status: Generic response code, non-zero on failure + * @rsvd0: Reserved + * @cdw0: Completion Queue Entry doubleword 0 + * @cdw1: Completion Queue Entry doubleword 1 + * @cdw3: Completion Queue Entry doubleword 3 + * + * This is the generic response format with the three doublewords of completion + * queue data, plus optional response data. + */ +struct nvme_mi_admin_resp_hdr { + struct nvme_mi_msg_hdr hdr; + __u8 status; + __u8 rsvd0[3]; + __le32 cdw0, cdw1, cdw3; +} __attribute__((packed)); + +/** + * enum nvme_mi_control_opcode - Operation code for Control Primitives. + * @nvme_mi_control_opcode_pause: Suspend response transmission/timeout + * @nvme_mi_control_opcode_resume: Resume from a paused condition + * @nvme_mi_control_opcode_abort: Re-initialize a Command Slot to the Idle state + * @nvme_mi_control_opcode_get_state: Get the state of a Command Slot + * @nvme_mi_control_opcode_replay: Retransmit the Response Message + */ +enum nvme_mi_control_opcode { + nvme_mi_control_opcode_pause = 0x00, + nvme_mi_control_opcode_resume = 0x01, + nvme_mi_control_opcode_abort = 0x02, + nvme_mi_control_opcode_get_state = 0x03, + nvme_mi_control_opcode_replay = 0x04, +}; + +/** + * struct nvme_mi_control_req - The Control Primitive request. + * @hdr: Generic MI message header + * @opcode: Control Primitive Opcodes (using &enum nvme_mi_control_opcode) + * @tag: flag - Opaque value passed from request to response + * @cpsp: Control Primitive Specific Parameter + * + */ +struct nvme_mi_control_req { + struct nvme_mi_msg_hdr hdr; + __u8 opcode; + __u8 tag; + __le16 cpsp; +} __attribute((packed)); + +/** struct nvme_mi_control_resp - The Control Primitive response. + * @hdr: Generic MI message header + * @status: Generic response code, non-zero on failure + * @tag: flag - Opaque value passed from request to response + * @cpsr: Control Primitive Specific Response + * + */ +struct nvme_mi_control_resp { + struct nvme_mi_msg_hdr hdr; + __u8 status; + __u8 tag; + __le16 cpsr; +} __attribute((packed)); diff --git a/libnvme/src/nvme/mi.c b/libnvme/src/nvme/mi.c index 9897c655aa..da8486448f 100644 --- a/libnvme/src/nvme/mi.c +++ b/libnvme/src/nvme/mi.c @@ -37,7 +37,7 @@ _Static_assert(sizeof(struct nvme_mi_aem_occ_data) == 9, _Static_assert(sizeof(struct nvme_mi_aem_occ_list_hdr) == 7, "size_of_nvme_mi_aem_occ_list_hdr_is_not_7_bytes"); -static int nvme_mi_get_async_message(nvme_mi_ep_t ep, +static int libnvme_mi_get_async_message(libnvme_mi_ep_t ep, struct nvme_mi_aem_msg *aem_msg, size_t *aem_msg_len); static const int default_timeout = 1000; /* milliseconds; endpoints may @@ -62,23 +62,23 @@ static int parse_devname(const char *dev, unsigned int *net, uint8_t *eid, return -EINVAL; } -int __nvme_transport_handle_init_mi(struct nvme_transport_handle *hdl) +int __libnvme_transport_handle_init_mi(struct libnvme_transport_handle *hdl) { - if (hdl->type != NVME_TRANSPORT_HANDLE_TYPE_UNKNOWN) + if (hdl->type != LIBNVME_TRANSPORT_HANDLE_TYPE_UNKNOWN) return -EALREADY; - hdl->type = NVME_TRANSPORT_HANDLE_TYPE_MI; + hdl->type = LIBNVME_TRANSPORT_HANDLE_TYPE_MI; return 0; } -int __nvme_transport_handle_open_mi(struct nvme_transport_handle *hdl, const char *devname) +int __libnvme_transport_handle_open_mi(struct libnvme_transport_handle *hdl, const char *devname) { unsigned int rc, net, ctrl_id; unsigned char eid; - struct nvme_mi_ep *ep; + struct libnvme_mi_ep *ep; - rc = __nvme_transport_handle_init_mi(hdl); + rc = __libnvme_transport_handle_init_mi(hdl); if (rc) return rc; @@ -86,20 +86,20 @@ int __nvme_transport_handle_open_mi(struct nvme_transport_handle *hdl, const cha if (rc) return rc; - ep = nvme_mi_open_mctp(hdl->ctx, net, eid); + ep = libnvme_mi_open_mctp(hdl->ctx, net, eid); if (!ep) return -EINVAL; return 0; } -void __nvme_transport_handle_close_mi(struct nvme_transport_handle *hdl) +void __libnvme_transport_handle_close_mi(struct libnvme_transport_handle *hdl) { list_del(&hdl->ep_entry); free(hdl); } -static void nvme_mi_record_resp_time(struct nvme_mi_ep *ep) +static void libnvme_mi_record_resp_time(struct libnvme_mi_ep *ep) { int rc; @@ -107,7 +107,7 @@ static void nvme_mi_record_resp_time(struct nvme_mi_ep *ep) ep->last_resp_time_valid = !rc; } -static bool nvme_mi_compare_vid_mn(struct nvme_mi_ep *ep, +static bool libnvme_mi_compare_vid_mn(struct libnvme_mi_ep *ep, struct nvme_id_ctrl *id, __u16 vid, const char *mn) @@ -116,7 +116,7 @@ static bool nvme_mi_compare_vid_mn(struct nvme_mi_ep *ep, len = strlen(mn); if (len >= sizeof(id->mn)) { - nvme_msg(ep->ctx, LOG_ERR, + libnvme_msg(ep->ctx, LOG_ERR, "Internal error: invalid model number for %s\n", __func__); return false; @@ -147,25 +147,25 @@ static void __nvme_mi_format_mn(struct nvme_id_ctrl *id, } } -#define nvme_mi_format_mn(id, m) __nvme_mi_format_mn(id, m, sizeof(m)) +#define libnvme_mi_format_mn(id, m) __nvme_mi_format_mn(id, m, sizeof(m)) -void nvme_mi_ep_probe(struct nvme_mi_ep *ep) +void libnvme_mi_ep_probe(struct libnvme_mi_ep *ep) { struct nvme_id_ctrl id = { 0 }; - struct nvme_transport_handle *hdl; - struct nvme_passthru_cmd cmd; + struct libnvme_transport_handle *hdl; + struct libnvme_passthru_cmd cmd; int rc; /* Ensure the probe occurs at most once. This isn't just to mitigate doubling * a linear stream of commands, it also terminates recursion via the - * nvme_mi_submit() call issued by nvme_mi_admin_identify_partial() below. + * libnvme_mi_submit() call issued by libnvme_mi_admin_identify_partial() below. */ if (ep->quirks_probed) return; /* Mark ep->quirks as valid. Note that for the purpose of quirk probing, * the quirk probe itself cannot rely on quirks, and so the fact that none are - * yet set is desirable. The request that triggered nvme_mi_submit() will have + * yet set is desirable. The request that triggered libnvme_mi_submit() will have * an initialised ep->quirks when we return from the root probe call. */ ep->quirks_probed = true; @@ -176,7 +176,7 @@ void nvme_mi_ep_probe(struct nvme_mi_ep *ep) /* start with no quirks, detect as we go */ ep->quirks = 0; - hdl = nvme_mi_init_transport_handle(ep, 0); + hdl = libnvme_mi_init_transport_handle(ep, 0); if (!hdl) return; @@ -194,9 +194,9 @@ void nvme_mi_ep_probe(struct nvme_mi_ep *ep) */ nvme_init_identify_ctrl(&cmd, &id); cmd.data_len = offsetof(struct nvme_id_ctrl, rab); - rc = nvme_submit_admin_passthru(hdl, &cmd); + rc = libnvme_submit_admin_passthru(hdl, &cmd); if (rc) { - nvme_msg(ep->ctx, LOG_WARNING, + libnvme_msg(ep->ctx, LOG_WARNING, "Identify Controller failed, no quirks applied\n"); goto out_close; } @@ -205,28 +205,28 @@ void nvme_mi_ep_probe(struct nvme_mi_ep *ep) * the previous response. Set an inter-command delay of 1.2ms for * a little extra tolerance. */ - if (nvme_mi_compare_vid_mn(ep, &id, 0x144d, "MZUL2512HCJQ")) { - ep->quirks |= NVME_QUIRK_MIN_INTER_COMMAND_TIME; + if (libnvme_mi_compare_vid_mn(ep, &id, 0x144d, "MZUL2512HCJQ")) { + ep->quirks |= LIBNVME_QUIRK_MIN_INTER_COMMAND_TIME; ep->inter_command_us = 1200; } /* If we're quirking for the inter-command time, record the last * command time now, so we don't conflict with the just-sent identify. */ - if (ep->quirks & NVME_QUIRK_MIN_INTER_COMMAND_TIME) - nvme_mi_record_resp_time(ep); + if (ep->quirks & LIBNVME_QUIRK_MIN_INTER_COMMAND_TIME) + libnvme_mi_record_resp_time(ep); if (ep->quirks) { char tmp[sizeof(id.mn) + 1]; - nvme_mi_format_mn(&id, tmp); - nvme_msg(ep->ctx, LOG_DEBUG, + libnvme_mi_format_mn(&id, tmp); + libnvme_msg(ep->ctx, LOG_DEBUG, "device %02x:%s: applying quirks 0x%08lx\n", id.vid, tmp, ep->quirks); } out_close: - nvme_close(hdl); + libnvme_close(hdl); } static const int nsec_per_sec = 1000 * 1000 * 1000; @@ -246,7 +246,7 @@ static const int nsec_per_sec = 1000 * 1000 * 1000; } \ } while (0) -static void nvme_mi_insert_delay(struct nvme_mi_ep *ep) +static void libnvme_mi_insert_delay(struct libnvme_mi_ep *ep) { struct timespec now, next, delay; int rc; @@ -276,9 +276,9 @@ static void nvme_mi_insert_delay(struct nvme_mi_ep *ep) nanosleep(&delay, NULL); } -struct nvme_mi_ep *nvme_mi_init_ep(struct nvme_global_ctx *ctx) +struct libnvme_mi_ep *libnvme_mi_init_ep(struct libnvme_global_ctx *ctx) { - struct nvme_mi_ep *ep; + struct libnvme_mi_ep *ep; ep = calloc(1, sizeof(*ep)); if (!ep) @@ -297,7 +297,7 @@ struct nvme_mi_ep *nvme_mi_init_ep(struct nvme_global_ctx *ctx) return ep; } -__public int nvme_mi_ep_set_timeout(nvme_mi_ep_t ep, unsigned int timeout_ms) +__public int libnvme_mi_ep_set_timeout(libnvme_mi_ep_t ep, unsigned int timeout_ms) { if (ep->transport->check_timeout) { int rc; @@ -310,30 +310,30 @@ __public int nvme_mi_ep_set_timeout(nvme_mi_ep_t ep, unsigned int timeout_ms) return 0; } -void nvme_mi_ep_set_mprt_max(nvme_mi_ep_t ep, unsigned int mprt_max_ms) +void libnvme_mi_ep_set_mprt_max(libnvme_mi_ep_t ep, unsigned int mprt_max_ms) { ep->mprt_max = mprt_max_ms; } -__public unsigned int nvme_mi_ep_get_timeout(nvme_mi_ep_t ep) +__public unsigned int libnvme_mi_ep_get_timeout(libnvme_mi_ep_t ep) { return ep->timeout; } -static bool nvme_mi_ep_has_quirk(nvme_mi_ep_t ep, unsigned long quirk) +static bool libnvme_mi_ep_has_quirk(libnvme_mi_ep_t ep, unsigned long quirk) { return ep->quirks & quirk; } -__public struct nvme_transport_handle *nvme_mi_init_transport_handle(nvme_mi_ep_t ep, __u16 ctrl_id) +__public struct libnvme_transport_handle *libnvme_mi_init_transport_handle(libnvme_mi_ep_t ep, __u16 ctrl_id) { - struct nvme_transport_handle *hdl; + struct libnvme_transport_handle *hdl; - hdl = __nvme_create_transport_handle(ep->ctx); + hdl = __libnvme_create_transport_handle(ep->ctx); if (!hdl) return NULL; - __nvme_transport_handle_init_mi(hdl); + __libnvme_transport_handle_init_mi(hdl); hdl->ep = ep; hdl->id = ctrl_id; @@ -343,12 +343,12 @@ __public struct nvme_transport_handle *nvme_mi_init_transport_handle(nvme_mi_ep_ return hdl; } -__public __u16 nvme_mi_ctrl_id(struct nvme_transport_handle *hdl) +__public __u16 libnvme_mi_ctrl_id(struct libnvme_transport_handle *hdl) { return hdl->id; } -__public int nvme_mi_scan_ep(nvme_mi_ep_t ep, bool force_rescan) +__public int libnvme_mi_scan_ep(libnvme_mi_ep_t ep, bool force_rescan) { struct nvme_ctrl_list list; unsigned int i, n_ctrl; @@ -356,16 +356,16 @@ __public int nvme_mi_scan_ep(nvme_mi_ep_t ep, bool force_rescan) if (ep->controllers_scanned) { if (force_rescan) { - struct nvme_transport_handle *hdl, *tmp; + struct libnvme_transport_handle *hdl, *tmp; - nvme_mi_for_each_transport_handle_safe(ep, hdl, tmp) - nvme_close(hdl); + libnvme_mi_for_each_transport_handle_safe(ep, hdl, tmp) + libnvme_close(hdl); } else { return 0; } } - rc = nvme_mi_mi_read_mi_data_ctrl_list(ep, 0, &list); + rc = libnvme_mi_mi_read_mi_data_ctrl_list(ep, 0, &list); if (rc) return rc; @@ -374,12 +374,12 @@ __public int nvme_mi_scan_ep(nvme_mi_ep_t ep, bool force_rescan) return -EPROTO; for (i = 0; i < n_ctrl; i++) { - struct nvme_transport_handle *hdl; + struct libnvme_transport_handle *hdl; __u16 id; id = le16_to_cpu(list.identifier[i]); - hdl = nvme_mi_init_transport_handle(ep, id); + hdl = libnvme_mi_init_transport_handle(ep, id); if (!hdl) break; } @@ -388,7 +388,7 @@ __public int nvme_mi_scan_ep(nvme_mi_ep_t ep, bool force_rescan) return 0; } -__u32 nvme_mi_crc32_update(__u32 crc, void *data, size_t len) +__u32 libnvme_mi_crc32_update(__u32 crc, void *data, size_t len) { int i; @@ -400,42 +400,42 @@ __u32 nvme_mi_crc32_update(__u32 crc, void *data, size_t len) return crc; } -static void nvme_mi_calc_req_mic(struct nvme_mi_req *req) +static void libnvme_mi_calc_req_mic(struct libnvme_mi_req *req) { __u32 crc = 0xffffffff; - crc = nvme_mi_crc32_update(crc, req->hdr, req->hdr_len); - crc = nvme_mi_crc32_update(crc, req->data, req->data_len); + crc = libnvme_mi_crc32_update(crc, req->hdr, req->hdr_len); + crc = libnvme_mi_crc32_update(crc, req->data, req->data_len); req->mic = ~crc; } /* returns zero on correct MIC */ -static int nvme_mi_verify_resp_mic(struct nvme_mi_resp *resp) +static int libnvme_mi_verify_resp_mic(struct libnvme_mi_resp *resp) { __u32 crc = 0xffffffff; - crc = nvme_mi_crc32_update(crc, resp->hdr, resp->hdr_len); - crc = nvme_mi_crc32_update(crc, resp->data, resp->data_len); + crc = libnvme_mi_crc32_update(crc, resp->hdr, resp->hdr_len); + crc = libnvme_mi_crc32_update(crc, resp->data, resp->data_len); return resp->mic != ~crc; } -__public __weak void *nvme_mi_submit_entry(__u8 type, const struct nvme_mi_msg_hdr *hdr, +__public __weak void *libnvme_mi_submit_entry(__u8 type, const struct nvme_mi_msg_hdr *hdr, size_t hdr_len, const void *data, size_t data_len) { return NULL; } -__public __weak void nvme_mi_submit_exit(__u8 type, const struct nvme_mi_msg_hdr *hdr, +__public __weak void libnvme_mi_submit_exit(__u8 type, const struct nvme_mi_msg_hdr *hdr, size_t hdr_len, const void *data, size_t data_len, void *user_data) { } -int nvme_mi_async_read(nvme_mi_ep_t ep, struct nvme_mi_resp *resp) +int libnvme_mi_async_read(libnvme_mi_ep_t ep, struct libnvme_mi_resp *resp) { - if (nvme_mi_ep_has_quirk(ep, NVME_QUIRK_MIN_INTER_COMMAND_TIME)) - nvme_mi_record_resp_time(ep); + if (libnvme_mi_ep_has_quirk(ep, LIBNVME_QUIRK_MIN_INTER_COMMAND_TIME)) + libnvme_mi_record_resp_time(ep); int rc = ep->transport->aem_read(ep, resp); @@ -445,41 +445,41 @@ int nvme_mi_async_read(nvme_mi_ep_t ep, struct nvme_mi_resp *resp) resp->data_len = 0;//No data to process return 0; } else if (rc) { - nvme_msg(ep->ctx, LOG_INFO, "transport failure\n"); + libnvme_msg(ep->ctx, LOG_INFO, "transport failure\n"); return rc; } if (ep->transport->mic_enabled) { - rc = nvme_mi_verify_resp_mic(resp); + rc = libnvme_mi_verify_resp_mic(resp); if (rc) { - nvme_msg(ep->ctx, LOG_WARNING, "crc mismatch\n"); + libnvme_msg(ep->ctx, LOG_WARNING, "crc mismatch\n"); return -EBADMSG; } } - //TODO: There's a bunch of overlap with the nvme_mi_submit. Maybe we make common helpers + //TODO: There's a bunch of overlap with the libnvme_mi_submit. Maybe we make common helpers /* basic response checks */ if (resp->hdr_len < sizeof(struct nvme_mi_msg_hdr)) { - nvme_msg(ep->ctx, LOG_DEBUG, + libnvme_msg(ep->ctx, LOG_DEBUG, "Bad response header len: %zd\n", resp->hdr_len); return -EPROTO; } if (resp->hdr->type != NVME_MI_MSGTYPE_NVME) { - nvme_msg(ep->ctx, LOG_DEBUG, + libnvme_msg(ep->ctx, LOG_DEBUG, "Invalid message type 0x%02x\n", resp->hdr->type); return -EPROTO; } if (!(resp->hdr->nmp & ~(NVME_MI_ROR_REQ << 7))) { - nvme_msg(ep->ctx, LOG_DEBUG, + libnvme_msg(ep->ctx, LOG_DEBUG, "ROR value in response indicates a response\n"); return -EIO; } if (!(resp->hdr->nmp & (NVME_MI_MT_AE << 3))) { - nvme_msg(ep->ctx, LOG_DEBUG, + libnvme_msg(ep->ctx, LOG_DEBUG, "NMIMT does not indicate AEM\n"); resp->data_len = 0;//No data to process return 0; @@ -489,13 +489,13 @@ int nvme_mi_async_read(nvme_mi_ep_t ep, struct nvme_mi_resp *resp) } -int nvme_mi_submit(nvme_mi_ep_t ep, struct nvme_mi_req *req, - struct nvme_mi_resp *resp) +int libnvme_mi_submit(libnvme_mi_ep_t ep, struct libnvme_mi_req *req, + struct libnvme_mi_resp *resp) { int rc; void *user_data; - user_data = nvme_mi_submit_entry(req->hdr->type, req->hdr, req->hdr_len, req->data, + user_data = libnvme_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)) @@ -510,70 +510,70 @@ int nvme_mi_submit(nvme_mi_ep_t ep, struct nvme_mi_req *req, if (resp->hdr_len & 0x3) return -EINVAL; - nvme_mi_ep_probe(ep); + libnvme_mi_ep_probe(ep); if (ep->transport->mic_enabled) - nvme_mi_calc_req_mic(req); + libnvme_mi_calc_req_mic(req); - if (nvme_mi_ep_has_quirk(ep, NVME_QUIRK_MIN_INTER_COMMAND_TIME)) - nvme_mi_insert_delay(ep); + if (libnvme_mi_ep_has_quirk(ep, LIBNVME_QUIRK_MIN_INTER_COMMAND_TIME)) + libnvme_mi_insert_delay(ep); rc = ep->transport->submit(ep, req, resp); - if (nvme_mi_ep_has_quirk(ep, NVME_QUIRK_MIN_INTER_COMMAND_TIME)) - nvme_mi_record_resp_time(ep); + if (libnvme_mi_ep_has_quirk(ep, LIBNVME_QUIRK_MIN_INTER_COMMAND_TIME)) + libnvme_mi_record_resp_time(ep); if (rc) { - nvme_msg(ep->ctx, LOG_INFO, "transport failure\n"); + libnvme_msg(ep->ctx, LOG_INFO, "transport failure\n"); return rc; } if (ep->transport->mic_enabled) { - rc = nvme_mi_verify_resp_mic(resp); + rc = libnvme_mi_verify_resp_mic(resp); if (rc) { - nvme_msg(ep->ctx, LOG_WARNING, "crc mismatch\n"); + libnvme_msg(ep->ctx, LOG_WARNING, "crc mismatch\n"); return -EBADMSG; } } /* basic response checks */ if (resp->hdr_len < sizeof(struct nvme_mi_msg_hdr)) { - nvme_msg(ep->ctx, LOG_DEBUG, + libnvme_msg(ep->ctx, LOG_DEBUG, "Bad response header len: %zd\n", resp->hdr_len); return -EPROTO; } if (resp->hdr->type != NVME_MI_MSGTYPE_NVME) { - nvme_msg(ep->ctx, LOG_DEBUG, + libnvme_msg(ep->ctx, LOG_DEBUG, "Invalid message type 0x%02x\n", resp->hdr->type); return -EPROTO; } if (!(resp->hdr->nmp & (NVME_MI_ROR_RSP << 7))) { - nvme_msg(ep->ctx, LOG_DEBUG, + libnvme_msg(ep->ctx, LOG_DEBUG, "ROR value in response indicates a request\n"); return -EIO; } if ((resp->hdr->nmp & 0x1) != (req->hdr->nmp & 0x1)) { - nvme_msg(ep->ctx, LOG_WARNING, + libnvme_msg(ep->ctx, LOG_WARNING, "Command slot mismatch: req %d, resp %d\n", req->hdr->nmp & 0x1, resp->hdr->nmp & 0x1); return -EIO; } - nvme_mi_submit_exit(resp->hdr->type, resp->hdr, resp->hdr_len, resp->data, resp->data_len, + libnvme_mi_submit_exit(resp->hdr->type, resp->hdr, resp->hdr_len, resp->data, resp->data_len, user_data); return 0; } -__public int nvme_mi_set_csi(nvme_mi_ep_t ep, uint8_t csi) +__public int libnvme_mi_set_csi(libnvme_mi_ep_t ep, uint8_t csi) { uint8_t csi_bit = (csi) ? 1 : 0; - if (nvme_mi_ep_has_quirk(ep, NVME_QUIRK_CSI_1_NOT_SUPPORTED) && csi_bit) + if (libnvme_mi_ep_has_quirk(ep, LIBNVME_QUIRK_CSI_1_NOT_SUPPORTED) && csi_bit) return -1; ep->csi = csi_bit; @@ -581,8 +581,8 @@ __public int nvme_mi_set_csi(nvme_mi_ep_t ep, uint8_t csi) return 0; } -static void nvme_mi_admin_init_req(nvme_mi_ep_t ep, - struct nvme_mi_req *req, +static void libnvme_mi_admin_init_req(libnvme_mi_ep_t ep, + struct libnvme_mi_req *req, struct nvme_mi_admin_req_hdr *hdr, __u16 ctrl_id, __u8 opcode) { @@ -600,7 +600,7 @@ static void nvme_mi_admin_init_req(nvme_mi_ep_t ep, req->hdr_len = sizeof(*hdr); } -static void nvme_mi_admin_init_resp(struct nvme_mi_resp *resp, +static void libnvme_mi_admin_init_resp(struct libnvme_mi_resp *resp, struct nvme_mi_admin_resp_hdr *hdr) { memset(resp, 0, sizeof(*resp)); @@ -608,8 +608,8 @@ static void nvme_mi_admin_init_resp(struct nvme_mi_resp *resp, resp->hdr_len = sizeof(*hdr); } -static void nvme_mi_control_init_req(nvme_mi_ep_t ep, - struct nvme_mi_req *req, +static void libnvme_mi_control_init_req(libnvme_mi_ep_t ep, + struct libnvme_mi_req *req, struct nvme_mi_control_req *control_req, __u8 opcode, __u16 cpsp) { @@ -627,7 +627,7 @@ static void nvme_mi_control_init_req(nvme_mi_ep_t ep, req->hdr_len = sizeof(*control_req); } -static void nvme_mi_control_init_resp(struct nvme_mi_resp *resp, +static void libnvme_mi_control_init_resp(struct libnvme_mi_resp *resp, struct nvme_mi_control_resp *control_resp) { memset(resp, 0, sizeof(*resp)); @@ -635,7 +635,7 @@ static void nvme_mi_control_init_resp(struct nvme_mi_resp *resp, resp->hdr_len = sizeof(*control_resp); } -static int nvme_mi_admin_parse_status(struct nvme_mi_resp *resp, __u64 *result) +static int libnvme_mi_admin_parse_status(struct libnvme_mi_resp *resp, __u64 *result) { struct nvme_mi_admin_resp_hdr *admin_hdr; struct nvme_mi_msg_resp *resp_hdr; @@ -682,7 +682,7 @@ static int nvme_mi_admin_parse_status(struct nvme_mi_resp *resp, __u64 *result) return nvme_status; } -static int nvme_mi_control_parse_status(struct nvme_mi_resp *resp, __u16 *cpsr) +static int libnvme_mi_control_parse_status(struct libnvme_mi_resp *resp, __u16 *cpsr) { struct nvme_mi_control_resp *control_resp; @@ -700,11 +700,11 @@ static int nvme_mi_control_parse_status(struct nvme_mi_resp *resp, __u16 *cpsr) return control_resp->status; } -static int nvme_mi_get_async_message(nvme_mi_ep_t ep, +static int libnvme_mi_get_async_message(libnvme_mi_ep_t ep, struct nvme_mi_aem_msg *aem_msg, size_t *aem_msg_len) { - struct nvme_mi_resp resp; + struct libnvme_mi_resp resp; memset(&resp, 0, sizeof(resp)); resp.hdr = &aem_msg->hdr; @@ -712,7 +712,7 @@ static int nvme_mi_get_async_message(nvme_mi_ep_t ep, resp.data = &aem_msg->occ_list_hdr; resp.data_len = *aem_msg_len; - int rc = nvme_mi_async_read(ep, &resp); + int rc = libnvme_mi_async_read(ep, &resp); if (rc) return rc; @@ -722,15 +722,15 @@ static int nvme_mi_get_async_message(nvme_mi_ep_t ep, } -__public int nvme_mi_admin_xfer(struct nvme_transport_handle *hdl, +__public int libnvme_mi_admin_xfer(struct libnvme_transport_handle *hdl, struct nvme_mi_admin_req_hdr *admin_req, size_t req_data_size, struct nvme_mi_admin_resp_hdr *admin_resp, off_t resp_data_offset, size_t *resp_data_size) { - struct nvme_mi_resp resp; - struct nvme_mi_req req; + struct libnvme_mi_resp resp; + struct libnvme_mi_req req; __u32 dlen, doff; int rc; @@ -792,7 +792,7 @@ __public int nvme_mi_admin_xfer(struct nvme_transport_handle *hdl, admin_req->dlen = cpu_to_le32(dlen); admin_req->doff = cpu_to_le32(doff); - rc = nvme_mi_submit(hdl->ep, &req, &resp); + rc = libnvme_mi_submit(hdl->ep, &req, &resp); if (rc) return rc; @@ -801,14 +801,14 @@ __public int nvme_mi_admin_xfer(struct nvme_transport_handle *hdl, return 0; } -int nvme_mi_admin_admin_passthru(struct nvme_transport_handle *hdl, - struct nvme_passthru_cmd *cmd) +int libnvme_mi_admin_admin_passthru(struct libnvme_transport_handle *hdl, + struct libnvme_passthru_cmd *cmd) { /* Input parameters flags, rsvd, metadata, metadata_len are not used */ 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; + struct libnvme_mi_resp resp; + struct libnvme_mi_req req; unsigned int timeout_save = 0; int rc; int direction = cmd->opcode & 0x3; @@ -816,14 +816,14 @@ int nvme_mi_admin_admin_passthru(struct nvme_transport_handle *hdl, bool has_read_data = false; if (direction == NVME_DATA_TFR_BIDIRECTIONAL) { - nvme_msg(hdl->ctx, LOG_ERR, - "nvme_mi_admin_admin_passthru doesn't support bidirectional commands\n"); + libnvme_msg(hdl->ctx, LOG_ERR, + "libnvme_mi_admin_admin_passthru doesn't support bidirectional commands\n"); return -EINVAL; } if (cmd->data_len > 4096) { - nvme_msg(hdl->ctx, LOG_ERR, - "nvme_mi_admin_admin_passthru doesn't support data_len over 4096 bytes.\n"); + libnvme_msg(hdl->ctx, LOG_ERR, + "libnvme_mi_admin_admin_passthru doesn't support data_len over 4096 bytes.\n"); return -EINVAL; } @@ -834,7 +834,7 @@ int nvme_mi_admin_admin_passthru(struct nvme_transport_handle *hdl, has_read_data = true; } - nvme_mi_admin_init_req(hdl->ep, &req, &req_hdr, hdl->id, cmd->opcode); + libnvme_mi_admin_init_req(hdl->ep, &req, &req_hdr, hdl->id, cmd->opcode); req_hdr.flags = cmd->flags; req_hdr.cdw1 = cpu_to_le32(cmd->nsid); req_hdr.cdw2 = cpu_to_le32(cmd->cdw2); @@ -857,7 +857,7 @@ int nvme_mi_admin_admin_passthru(struct nvme_transport_handle *hdl, req.data_len = cmd->data_len; } - nvme_mi_admin_init_resp(&resp, &resp_hdr); + libnvme_mi_admin_init_resp(&resp, &resp_hdr); if (has_read_data) { resp.data = (void *)(uintptr_t)cmd->addr; @@ -868,17 +868,17 @@ int nvme_mi_admin_admin_passthru(struct nvme_transport_handle *hdl, * timeout and override */ if (cmd->timeout_ms != 0) { - timeout_save = nvme_mi_ep_get_timeout(hdl->ep); - nvme_mi_ep_set_timeout(hdl->ep, cmd->timeout_ms); + timeout_save = libnvme_mi_ep_get_timeout(hdl->ep); + libnvme_mi_ep_set_timeout(hdl->ep, cmd->timeout_ms); } - rc = nvme_mi_submit(hdl->ep, &req, &resp); + rc = libnvme_mi_submit(hdl->ep, &req, &resp); if (cmd->timeout_ms != 0) - nvme_mi_ep_set_timeout(hdl->ep, timeout_save); + libnvme_mi_ep_set_timeout(hdl->ep, timeout_save); if (rc) return rc; - rc = nvme_mi_admin_parse_status(&resp, &cmd->result); + rc = libnvme_mi_admin_parse_status(&resp, &cmd->result); if (rc) return rc; @@ -888,31 +888,31 @@ int nvme_mi_admin_admin_passthru(struct nvme_transport_handle *hdl, return 0; } -__public int nvme_mi_control(nvme_mi_ep_t ep, __u8 opcode, +__public int libnvme_mi_control(libnvme_mi_ep_t ep, __u8 opcode, __u16 cpsp, __u16 *result_cpsr) { struct nvme_mi_control_resp control_resp; struct nvme_mi_control_req control_req; - struct nvme_mi_resp resp; - struct nvme_mi_req req; + struct libnvme_mi_resp resp; + struct libnvme_mi_req req; int rc = 0; - nvme_mi_control_init_req(ep, &req, &control_req, opcode, cpsp); - nvme_mi_control_init_resp(&resp, &control_resp); + libnvme_mi_control_init_req(ep, &req, &control_req, opcode, cpsp); + libnvme_mi_control_init_resp(&resp, &control_resp); - rc = nvme_mi_submit(ep, &req, &resp); + rc = libnvme_mi_submit(ep, &req, &resp); if (rc) return rc; - rc = nvme_mi_control_parse_status(&resp, result_cpsr); + rc = libnvme_mi_control_parse_status(&resp, result_cpsr); if (rc) return rc; return 0; } -static void nvme_mi_mi_init_req(nvme_mi_ep_t ep, - struct nvme_mi_req *req, +static void libnvme_mi_mi_init_req(libnvme_mi_ep_t ep, + struct libnvme_mi_req *req, struct nvme_mi_mi_req_hdr *hdr, __u32 cdw0, __u8 opcode) { @@ -930,16 +930,16 @@ static void nvme_mi_mi_init_req(nvme_mi_ep_t ep, req->hdr_len = sizeof(*hdr); } -static int nvme_mi_read_data(nvme_mi_ep_t ep, __u32 cdw0, +static int libnvme_mi_read_data(libnvme_mi_ep_t ep, __u32 cdw0, void *data, size_t *data_len) { struct nvme_mi_mi_resp_hdr resp_hdr; struct nvme_mi_mi_req_hdr req_hdr; - struct nvme_mi_resp resp; - struct nvme_mi_req req; + struct libnvme_mi_resp resp; + struct libnvme_mi_req req; int rc; - nvme_mi_mi_init_req(ep, &req, &req_hdr, cdw0, + libnvme_mi_mi_init_req(ep, &req, &req_hdr, cdw0, nvme_mi_mi_opcode_mi_data_read); memset(&resp, 0, sizeof(resp)); @@ -948,7 +948,7 @@ static int nvme_mi_read_data(nvme_mi_ep_t ep, __u32 cdw0, resp.data = data; resp.data_len = *data_len; - rc = nvme_mi_submit(ep, &req, &resp); + rc = libnvme_mi_submit(ep, &req, &resp); if (rc) return rc; @@ -960,15 +960,15 @@ static int nvme_mi_read_data(nvme_mi_ep_t ep, __u32 cdw0, return 0; } -__public int nvme_mi_mi_xfer(nvme_mi_ep_t ep, +__public int libnvme_mi_mi_xfer(libnvme_mi_ep_t ep, struct nvme_mi_mi_req_hdr *mi_req, size_t req_data_size, struct nvme_mi_mi_resp_hdr *mi_resp, size_t *resp_data_size) { int rc; - struct nvme_mi_req req; - struct nvme_mi_resp resp; + struct libnvme_mi_req req; + struct libnvme_mi_resp resp; /* There is nothing in the spec to define this limit but going with the limits * from the admin message types for DLEN seems like a reasonable starting point @@ -1001,7 +1001,7 @@ __public int nvme_mi_mi_xfer(nvme_mi_ep_t ep, resp.data = mi_resp + 1; resp.data_len = *resp_data_size; - rc = nvme_mi_submit(ep, &req, &resp); + rc = libnvme_mi_submit(ep, &req, &resp); if (rc) return rc; @@ -1010,7 +1010,7 @@ __public int nvme_mi_mi_xfer(nvme_mi_ep_t ep, return 0; } -__public int nvme_mi_mi_read_mi_data_subsys(nvme_mi_ep_t ep, +__public int libnvme_mi_mi_read_mi_data_subsys(libnvme_mi_ep_t ep, struct nvme_mi_read_nvm_ss_info *s) { size_t len; @@ -1020,12 +1020,12 @@ __public int nvme_mi_mi_read_mi_data_subsys(nvme_mi_ep_t ep, cdw0 = (__u8)nvme_mi_dtyp_subsys_info << 24; len = sizeof(*s); - rc = nvme_mi_read_data(ep, cdw0, s, &len); + rc = libnvme_mi_read_data(ep, cdw0, s, &len); if (rc) return rc; if (len != sizeof(*s)) { - nvme_msg(ep->ctx, LOG_WARNING, + libnvme_msg(ep->ctx, LOG_WARNING, "MI read data length mismatch: " "got %zd bytes, expected %zd\n", len, sizeof(*s)); @@ -1035,7 +1035,7 @@ __public int nvme_mi_mi_read_mi_data_subsys(nvme_mi_ep_t ep, return 0; } -__public int nvme_mi_mi_read_mi_data_port(nvme_mi_ep_t ep, __u8 portid, +__public int libnvme_mi_mi_read_mi_data_port(libnvme_mi_ep_t ep, __u8 portid, struct nvme_mi_read_port_info *p) { size_t len; @@ -1045,7 +1045,7 @@ __public int nvme_mi_mi_read_mi_data_port(nvme_mi_ep_t ep, __u8 portid, cdw0 = ((__u8)nvme_mi_dtyp_port_info << 24) | (portid << 16); len = sizeof(*p); - rc = nvme_mi_read_data(ep, cdw0, p, &len); + rc = libnvme_mi_read_data(ep, cdw0, p, &len); if (rc) return rc; @@ -1055,7 +1055,7 @@ __public int nvme_mi_mi_read_mi_data_port(nvme_mi_ep_t ep, __u8 portid, return 0; } -__public int nvme_mi_mi_read_mi_data_ctrl_list(nvme_mi_ep_t ep, __u8 start_ctrlid, +__public int libnvme_mi_mi_read_mi_data_ctrl_list(libnvme_mi_ep_t ep, __u8 start_ctrlid, struct nvme_ctrl_list *list) { size_t len; @@ -1065,14 +1065,14 @@ __public int nvme_mi_mi_read_mi_data_ctrl_list(nvme_mi_ep_t ep, __u8 start_ctrli cdw0 = ((__u8)nvme_mi_dtyp_ctrl_list << 24) | (start_ctrlid << 16); len = sizeof(*list); - rc = nvme_mi_read_data(ep, cdw0, list, &len); + rc = libnvme_mi_read_data(ep, cdw0, list, &len); if (rc) return rc; return 0; } -__public int nvme_mi_mi_read_mi_data_ctrl(nvme_mi_ep_t ep, __u16 ctrl_id, +__public int libnvme_mi_mi_read_mi_data_ctrl(libnvme_mi_ep_t ep, __u16 ctrl_id, struct nvme_mi_read_ctrl_info *ctrl) { size_t len; @@ -1082,7 +1082,7 @@ __public int nvme_mi_mi_read_mi_data_ctrl(nvme_mi_ep_t ep, __u16 ctrl_id, cdw0 = ((__u8)nvme_mi_dtyp_ctrl_info << 24) | cpu_to_le16(ctrl_id); len = sizeof(*ctrl); - rc = nvme_mi_read_data(ep, cdw0, ctrl, &len); + rc = libnvme_mi_read_data(ep, cdw0, ctrl, &len); if (rc) return rc; @@ -1092,16 +1092,16 @@ __public int nvme_mi_mi_read_mi_data_ctrl(nvme_mi_ep_t ep, __u16 ctrl_id, return 0; } -__public int nvme_mi_mi_subsystem_health_status_poll(nvme_mi_ep_t ep, bool clear, +__public int libnvme_mi_mi_subsystem_health_status_poll(libnvme_mi_ep_t ep, bool clear, struct nvme_mi_nvm_ss_health_status *sshs) { struct nvme_mi_mi_resp_hdr resp_hdr; struct nvme_mi_mi_req_hdr req_hdr; - struct nvme_mi_resp resp; - struct nvme_mi_req req; + struct libnvme_mi_resp resp; + struct libnvme_mi_req req; int rc; - nvme_mi_mi_init_req(ep, &req, &req_hdr, 0, + libnvme_mi_mi_init_req(ep, &req, &req_hdr, 0, nvme_mi_mi_opcode_subsys_health_status_poll); req_hdr.cdw1 = (clear ? 1 : 0) << 31; @@ -1111,7 +1111,7 @@ __public int nvme_mi_mi_subsystem_health_status_poll(nvme_mi_ep_t ep, bool clear resp.data = sshs; resp.data_len = sizeof(*sshs); - rc = nvme_mi_submit(ep, &req, &resp); + rc = libnvme_mi_submit(ep, &req, &resp); if (rc) return rc; @@ -1119,7 +1119,7 @@ __public int nvme_mi_mi_subsystem_health_status_poll(nvme_mi_ep_t ep, bool clear return resp_hdr.status; if (resp.data_len != sizeof(*sshs)) { - nvme_msg(ep->ctx, LOG_WARNING, + libnvme_msg(ep->ctx, LOG_WARNING, "MI Subsystem Health Status length mismatch: " "got %zd bytes, expected %zd\n", resp.data_len, sizeof(*sshs)); @@ -1129,17 +1129,17 @@ __public int nvme_mi_mi_subsystem_health_status_poll(nvme_mi_ep_t ep, bool clear return 0; } -int nvme_mi_mi_config_set_get_ex(nvme_mi_ep_t ep, __u8 opcode, __u32 dw0, +int libnvme_mi_mi_config_set_get_ex(libnvme_mi_ep_t ep, __u8 opcode, __u32 dw0, __u32 dw1, void *data_out, size_t data_out_len, void *data_in, size_t *data_in_len, __u32 *nmresp) { struct nvme_mi_mi_resp_hdr resp_hdr; struct nvme_mi_mi_req_hdr req_hdr; - struct nvme_mi_resp resp; - struct nvme_mi_req req; + struct libnvme_mi_resp resp; + struct libnvme_mi_req req; int rc; - nvme_mi_mi_init_req(ep, &req, &req_hdr, dw0, opcode); + libnvme_mi_mi_init_req(ep, &req, &req_hdr, dw0, opcode); req_hdr.cdw1 = cpu_to_le32(dw1); req.data = data_out; req.data_len = data_out_len; @@ -1150,7 +1150,7 @@ int nvme_mi_mi_config_set_get_ex(nvme_mi_ep_t ep, __u8 opcode, __u32 dw0, resp.data = data_in; resp.data_len = *data_in_len; - rc = nvme_mi_submit(ep, &req, &resp); + rc = libnvme_mi_submit(ep, &req, &resp); if (rc) return rc; @@ -1168,12 +1168,12 @@ int nvme_mi_mi_config_set_get_ex(nvme_mi_ep_t ep, __u8 opcode, __u32 dw0, return 0; } -__public int nvme_mi_mi_config_get(nvme_mi_ep_t ep, __u32 dw0, __u32 dw1, +__public int libnvme_mi_mi_config_get(libnvme_mi_ep_t ep, __u32 dw0, __u32 dw1, __u32 *nmresp) { size_t data_in_len = 0; - return nvme_mi_mi_config_set_get_ex(ep, + return libnvme_mi_mi_config_set_get_ex(ep, nvme_mi_mi_opcode_configuration_get, dw0, dw1, @@ -1184,11 +1184,11 @@ __public int nvme_mi_mi_config_get(nvme_mi_ep_t ep, __u32 dw0, __u32 dw1, nmresp); } -__public int nvme_mi_mi_config_set(nvme_mi_ep_t ep, __u32 dw0, __u32 dw1) +__public int libnvme_mi_mi_config_set(libnvme_mi_ep_t ep, __u32 dw0, __u32 dw1) { size_t data_in_len = 0; - return nvme_mi_mi_config_set_get_ex(ep, + return libnvme_mi_mi_config_set_get_ex(ep, nvme_mi_mi_opcode_configuration_set, dw0, dw1, @@ -1199,7 +1199,7 @@ __public int nvme_mi_mi_config_set(nvme_mi_ep_t ep, __u32 dw0, __u32 dw1) NULL); } -int nvme_mi_mi_config_get_async_event(nvme_mi_ep_t ep, +int libnvme_mi_mi_config_get_async_event(libnvme_mi_ep_t ep, __u8 *aeelver, struct nvme_mi_aem_supported_list *list, size_t *list_num_bytes) @@ -1208,7 +1208,7 @@ int nvme_mi_mi_config_get_async_event(nvme_mi_ep_t ep, __u32 dw0 = NVME_MI_CONFIG_AE; __u32 aeelvertemp = 0; - int rc = nvme_mi_mi_config_set_get_ex(ep, + int rc = libnvme_mi_mi_config_set_get_ex(ep, nvme_mi_mi_opcode_configuration_get, dw0, 0, @@ -1226,7 +1226,7 @@ int nvme_mi_mi_config_get_async_event(nvme_mi_ep_t ep, return 0; } -int nvme_mi_mi_config_set_async_event(nvme_mi_ep_t ep, +int libnvme_mi_mi_config_set_async_event(libnvme_mi_ep_t ep, bool envfa, bool empfa, bool encfa, @@ -1256,7 +1256,7 @@ int nvme_mi_mi_config_set_async_event(nvme_mi_ep_t ep, enable_list->hdr.aeelver != 0) return -EINVAL; - return nvme_mi_mi_config_set_get_ex(ep, + return libnvme_mi_mi_config_set_get_ex(ep, nvme_mi_mi_opcode_configuration_set, dw0, 0, @@ -1268,15 +1268,15 @@ int nvme_mi_mi_config_set_async_event(nvme_mi_ep_t ep, } -__public void nvme_mi_close(nvme_mi_ep_t ep) +__public void libnvme_mi_close(libnvme_mi_ep_t ep) { - struct nvme_transport_handle *hdl, *tmp; + struct libnvme_transport_handle *hdl, *tmp; /* don't look for controllers during destruction */ ep->controllers_scanned = true; - nvme_mi_for_each_transport_handle_safe(ep, hdl, tmp) - nvme_close(hdl); + libnvme_mi_for_each_transport_handle_safe(ep, hdl, tmp) + libnvme_close(hdl); if (ep->transport && ep->transport->close) ep->transport->close(ep); @@ -1284,7 +1284,7 @@ __public void nvme_mi_close(nvme_mi_ep_t ep) free(ep); } -__public char *nvme_mi_endpoint_desc(nvme_mi_ep_t ep) +__public char *libnvme_mi_endpoint_desc(libnvme_mi_ep_t ep) { char tsbuf[101], *s = NULL; size_t tslen; @@ -1314,23 +1314,23 @@ __public char *nvme_mi_endpoint_desc(nvme_mi_ep_t ep) return s; } -__public nvme_mi_ep_t nvme_mi_first_endpoint(struct nvme_global_ctx *ctx) +__public libnvme_mi_ep_t libnvme_mi_first_endpoint(struct libnvme_global_ctx *ctx) { - return list_top(&ctx->endpoints, struct nvme_mi_ep, root_entry); + return list_top(&ctx->endpoints, struct libnvme_mi_ep, root_entry); } -__public nvme_mi_ep_t nvme_mi_next_endpoint(struct nvme_global_ctx *ctx, nvme_mi_ep_t ep) +__public libnvme_mi_ep_t libnvme_mi_next_endpoint(struct libnvme_global_ctx *ctx, libnvme_mi_ep_t ep) { return ep ? list_next(&ctx->endpoints, ep, root_entry) : NULL; } -struct nvme_transport_handle *nvme_mi_first_transport_handle(nvme_mi_ep_t ep) +struct libnvme_transport_handle *libnvme_mi_first_transport_handle(libnvme_mi_ep_t ep) { - return list_top(&ep->controllers, struct nvme_transport_handle, ep_entry); + return list_top(&ep->controllers, struct libnvme_transport_handle, ep_entry); } -struct nvme_transport_handle *nvme_mi_next_transport_handle(nvme_mi_ep_t ep, - struct nvme_transport_handle *hdl) +struct libnvme_transport_handle *libnvme_mi_next_transport_handle(libnvme_mi_ep_t ep, + struct libnvme_transport_handle *hdl) { return hdl ? list_next(&ep->controllers, hdl, ep_entry) : NULL; } @@ -1357,8 +1357,8 @@ static const char *const mi_status[] = { }; /* kept in mi.c while we have a split libnvme/libnvme-mi; consider moving - * to utils.c (with nvme_status_to_string) if we ever merge. */ -__public const char *nvme_mi_status_to_string(int status) + * to utils.c (with libnvme_status_to_string) if we ever merge. */ +__public const char *libnvme_mi_status_to_string(int status) { const char *s = "Unknown status"; @@ -1456,7 +1456,7 @@ static int validate_enabled_list(struct nvme_mi_aem_supported_list *list, size_t static int validate_occ_list_update_ctx( struct nvme_mi_aem_occ_list_hdr *occ_header, size_t len, - struct nvme_mi_aem_ctx *ctx, + struct libnvme_mi_aem_ctx *ctx, bool check_generation_num) { int err; @@ -1526,7 +1526,7 @@ static int validate_occ_list_update_ctx( return err; } -__public int nvme_mi_aem_get_fd(nvme_mi_ep_t ep) +__public int libnvme_mi_aem_get_fd(libnvme_mi_ep_t ep) { if (!ep || !ep->aem_ctx || !ep->transport || !ep->transport->aem_fd) return -1; @@ -1534,7 +1534,7 @@ __public int nvme_mi_aem_get_fd(nvme_mi_ep_t ep) return ep->transport->aem_fd(ep); } -static void reset_list_info(struct nvme_mi_aem_ctx *ctx) +static void reset_list_info(struct libnvme_mi_aem_ctx *ctx) { //Reset context information ctx->list_current_index = -1; @@ -1543,7 +1543,7 @@ static void reset_list_info(struct nvme_mi_aem_ctx *ctx) ctx->occ_header = NULL; } -static int aem_sync(nvme_mi_ep_t ep, +static int aem_sync(libnvme_mi_ep_t ep, bool envfa, bool empfa, bool encfa, @@ -1579,7 +1579,7 @@ static int aem_sync(nvme_mi_ep_t ep, } //Send it - int rc = nvme_mi_mi_config_set_async_event(ep, + int rc = libnvme_mi_mi_config_set_async_event(ep, envfa, empfa, encfa, @@ -1594,9 +1594,9 @@ static int aem_sync(nvme_mi_ep_t ep, return rc; } -static int aem_disable_enabled(nvme_mi_ep_t ep) +static int aem_disable_enabled(libnvme_mi_ep_t ep) { - struct nvme_mi_aem_enabled_map already_enabled = {false}; + struct libnvme_mi_aem_enabled_map already_enabled = {false}; uint8_t response_buffer[4096] = {0}; size_t response_len = sizeof(response_buffer); struct nvme_mi_aem_occ_list_hdr *response = @@ -1604,7 +1604,7 @@ static int aem_disable_enabled(nvme_mi_ep_t ep) // First, let's figure out if anything is already enabled that we need to // disable - int rc = nvme_mi_aem_get_enabled(ep, &already_enabled); + int rc = libnvme_mi_aem_get_enabled(ep, &already_enabled); if (rc) return rc; @@ -1635,14 +1635,14 @@ static int aem_disable_enabled(nvme_mi_ep_t ep) return rc; } -__public int nvme_mi_aem_enable(nvme_mi_ep_t ep, - struct nvme_mi_aem_config *config, +__public int libnvme_mi_aem_enable(libnvme_mi_ep_t ep, + struct libnvme_mi_aem_config *config, void *userdata) { if (!ep || !config || !config->aem_handler) return -1; - int rc = nvme_mi_aem_open(ep); + int rc = libnvme_mi_aem_open(ep); if (rc < 0) return rc; @@ -1709,8 +1709,8 @@ __public int nvme_mi_aem_enable(nvme_mi_ep_t ep, return rc; } -__public int nvme_mi_aem_get_enabled(nvme_mi_ep_t ep, - struct nvme_mi_aem_enabled_map *enabled_map) +__public int libnvme_mi_aem_get_enabled(libnvme_mi_ep_t ep, + struct libnvme_mi_aem_enabled_map *enabled_map) { if (!ep || !enabled_map) return -1; @@ -1724,7 +1724,7 @@ __public int nvme_mi_aem_get_enabled(nvme_mi_ep_t ep, if (!enabled_list) return -1; - rc = nvme_mi_mi_config_get_async_event( + rc = libnvme_mi_mi_config_get_async_event( ep, &aeelver, enabled_list, &ae_list_bytes); if (rc) goto cleanup; @@ -1750,7 +1750,7 @@ __public int nvme_mi_aem_get_enabled(nvme_mi_ep_t ep, return rc; } -__public int nvme_mi_aem_disable(nvme_mi_ep_t ep) +__public int libnvme_mi_aem_disable(libnvme_mi_ep_t ep) { if (!ep) return -1; @@ -1768,7 +1768,7 @@ __public int nvme_mi_aem_disable(nvme_mi_ep_t ep) *spec_info and vend_spec_info must be copied to persist as they will not be valid after *the aem_handler has returned. */ -__public struct nvme_mi_event *nvme_mi_aem_get_next_event(nvme_mi_ep_t ep) +__public struct libnvme_mi_event *libnvme_mi_aem_get_next_event(libnvme_mi_ep_t ep) { if (!ep || !ep->aem_ctx || !ep->aem_ctx->list_current || @@ -1780,7 +1780,7 @@ __public struct nvme_mi_event *nvme_mi_aem_get_next_event(nvme_mi_ep_t ep) if (ep->aem_ctx->occ_header->numaeo <= ep->aem_ctx->list_current_index) return NULL; - struct nvme_mi_aem_ctx *aem_ctx = ep->aem_ctx; + struct libnvme_mi_aem_ctx *aem_ctx = ep->aem_ctx; struct nvme_mi_aem_occ_data *current = aem_ctx->list_current; aem_ctx->event.aeoi = current->aeoui.aeoi; @@ -1805,7 +1805,7 @@ __public struct nvme_mi_event *nvme_mi_aem_get_next_event(nvme_mi_ep_t ep) /* POLLIN has indicated events. This function reads and processes them. * A callback will likely be invoked. */ -__public int nvme_mi_aem_process(nvme_mi_ep_t ep, void *userdata) +__public int libnvme_mi_aem_process(libnvme_mi_ep_t ep, void *userdata) { int rc = 0; uint8_t response_buffer[4096]; @@ -1820,7 +1820,7 @@ __public int nvme_mi_aem_process(nvme_mi_ep_t ep, void *userdata) //Reset context information reset_list_info(ep->aem_ctx); - rc = nvme_mi_get_async_message(ep, response, &response_len); + rc = libnvme_mi_get_async_message(ep, response, &response_len); if (rc) goto cleanup; @@ -1840,7 +1840,7 @@ __public int nvme_mi_aem_process(nvme_mi_ep_t ep, void *userdata) goto cleanup; if (response->occ_list_hdr.numaeo) { - enum nvme_mi_aem_handler_next_action action = + enum libnvme_mi_aem_handler_next_action action = ep->aem_ctx->callbacks.aem_handler(ep, response->occ_list_hdr.numaeo, userdata); @@ -1850,7 +1850,7 @@ __public int nvme_mi_aem_process(nvme_mi_ep_t ep, void *userdata) if (action == NVME_MI_AEM_HNA_ACK) { response_len = sizeof(response_buffer); - rc = nvme_mi_aem_ack(ep, &response->occ_list_hdr, &response_len); + rc = libnvme_mi_aem_ack(ep, &response->occ_list_hdr, &response_len); if (rc) goto cleanup; diff --git a/libnvme/src/nvme/mi.h b/libnvme/src/nvme/mi.h index d7beda872c..d1d184c126 100644 --- a/libnvme/src/nvme/mi.h +++ b/libnvme/src/nvme/mi.h @@ -16,7 +16,7 @@ * We have a few data structures define here to reflect the topology * of a MI connection with an NVMe subsystem: * - * - &nvme_mi_ep_t: an MI endpoint - our mechanism of communication with a + * - &libnvme_mi_ep_t: an MI endpoint - our mechanism of communication with a * NVMe subsystem. For MCTP, an endpoint will be the component that * holds the MCTP address (EID), and receives our request message. * @@ -25,22 +25,22 @@ * * Each endpoint will provide access to one or more of: * - * - &nvme_mi_ctrl_t: a NVMe controller, as defined by the NVMe base spec. + * - &libnvme_mi_ctrl_t: a NVMe controller, as defined by the NVMe base spec. * The controllers are responsible for processing any NVMe standard - * commands (eg, the Admin command set). An endpoint (&nvme_mi_ep_t) + * commands (eg, the Admin command set). An endpoint (&libnvme_mi_ep_t) * may provide access to multiple controllers - so each of the controller- - * type commands will require a &nvme_mi_ctrl_t to be specified, rather than + * type commands will require a &libnvme_mi_ctrl_t to be specified, rather than * an endpoint * * A couple of conventions with the libnvme-mi API: * - * - All types and functions have the nvme_mi prefix, to distinguish from + * - All types and functions have the libnvme_mi prefix, to distinguish from * the libnvme core. * * - We currently support either MI commands and Admin commands. The * former adds a _mi prefix, the latter an _admin prefix. [This does * result in the MI functions having a double _mi, like - * &nvme_mi_mi_subsystem_health_status_poll, which is apparently amusing + * &libnvme_mi_mi_subsystem_health_status_poll, which is apparently amusing * for our German-speaking readers] * * For return values: unless specified in the per-function documentation, @@ -82,562 +82,11 @@ */ #pragma once -#include -#include - +#include #include /** - * NVME_MI_MSGTYPE_NVME - MCTP message type for NVMe-MI messages. - * - * This is defined by MCTP, but is referenced as part of the NVMe-MI message - * spec. This is the MCTP NVMe message type (0x4), with the message-integrity - * bit (0x80) set. - */ -#define NVME_MI_MSGTYPE_NVME 0x84 - -/* Basic MI message definitions */ - -/** - * enum nvme_mi_message_type - NVMe-MI message type field. - * @NVME_MI_MT_CONTROL: NVME-MI Control Primitive - * @NVME_MI_MT_MI: NVMe-MI command - * @NVME_MI_MT_ADMIN: NVMe Admin command - * @NVME_MI_MT_PCIE: PCIe command - * @NVME_MI_MT_AE: Asynchronous Event - * - * Used as byte 1 of both request and response messages (NMIMT bits of NMP - * byte). Not to be confused with the MCTP message type in byte 0. - */ -enum nvme_mi_message_type { - NVME_MI_MT_CONTROL = 0, - NVME_MI_MT_MI = 1, - NVME_MI_MT_ADMIN = 2, - NVME_MI_MT_PCIE = 4, - NVME_MI_MT_AE = 5, -}; - -/** - * enum nvme_mi_ror: Request or response field. - * @NVME_MI_ROR_REQ: request message - * @NVME_MI_ROR_RSP: response message - */ -enum nvme_mi_ror { - NVME_MI_ROR_REQ = 0, - NVME_MI_ROR_RSP = 1, -}; - -/** - * enum nvme_mi_resp_status - values for the response status field - * @NVME_MI_RESP_SUCCESS: success - * @NVME_MI_RESP_MPR: More Processing Required - * @NVME_MI_RESP_INTERNAL_ERR: Internal Error - * @NVME_MI_RESP_INVALID_OPCODE: Invalid command opcode - * @NVME_MI_RESP_INVALID_PARAM: Invalid command parameter - * @NVME_MI_RESP_INVALID_CMD_SIZE: Invalid command size - * @NVME_MI_RESP_INVALID_INPUT_SIZE: Invalid command input data size - * @NVME_MI_RESP_ACCESS_DENIED: Access Denied - * @NVME_MI_RESP_VPD_UPDATES_EXCEEDED: More VPD updates than allowed - * @NVME_MI_RESP_PCIE_INACCESSIBLE: PCIe functionality currently unavailable - * @NVME_MI_RESP_MEB_SANITIZED: MEB has been cleared due to sanitize - * @NVME_MI_RESP_ENC_SERV_FAILURE: Enclosure services process failed - * @NVME_MI_RESP_ENC_SERV_XFER_FAILURE: Transfer with enclosure services failed - * @NVME_MI_RESP_ENC_FAILURE: Unreoverable enclosure failure - * @NVME_MI_RESP_ENC_XFER_REFUSED: Enclosure services transfer refused - * @NVME_MI_RESP_ENC_FUNC_UNSUP: Unsupported enclosure services function - * @NVME_MI_RESP_ENC_SERV_UNAVAIL: Enclosure services unavailable - * @NVME_MI_RESP_ENC_DEGRADED: Noncritical failure detected by enc. services - * @NVME_MI_RESP_SANITIZE_IN_PROGRESS: Command prohibited during sanitize - */ -enum nvme_mi_resp_status { - NVME_MI_RESP_SUCCESS = 0x00, - NVME_MI_RESP_MPR = 0x01, - NVME_MI_RESP_INTERNAL_ERR = 0x02, - NVME_MI_RESP_INVALID_OPCODE = 0x03, - NVME_MI_RESP_INVALID_PARAM = 0x04, - NVME_MI_RESP_INVALID_CMD_SIZE = 0x05, - NVME_MI_RESP_INVALID_INPUT_SIZE = 0x06, - NVME_MI_RESP_ACCESS_DENIED = 0x07, - /* 0x08 - 0x1f: reserved */ - NVME_MI_RESP_VPD_UPDATES_EXCEEDED = 0x20, - NVME_MI_RESP_PCIE_INACCESSIBLE = 0x21, - NVME_MI_RESP_MEB_SANITIZED = 0x22, - NVME_MI_RESP_ENC_SERV_FAILURE = 0x23, - NVME_MI_RESP_ENC_SERV_XFER_FAILURE = 0x24, - NVME_MI_RESP_ENC_FAILURE = 0x25, - NVME_MI_RESP_ENC_XFER_REFUSED = 0x26, - NVME_MI_RESP_ENC_FUNC_UNSUP = 0x27, - NVME_MI_RESP_ENC_SERV_UNAVAIL = 0x28, - NVME_MI_RESP_ENC_DEGRADED = 0x29, - NVME_MI_RESP_SANITIZE_IN_PROGRESS = 0x2a, - /* 0x2b - 0xdf: reserved */ - /* 0xe0 - 0xff: vendor specific */ -}; - -/** - * struct nvme_mi_msg_hdr - General MI message header. - * @type: MCTP message type, will always be NVME_MI_MSGTYPE_NVME - * @nmp: NVMe-MI message parameters (including MI message type) - * @meb: Management Endpoint Buffer flag; unused for libnvme-mi implementation - * @rsvd0: currently reserved - * - * Wire format shared by both request and response messages, per NVMe-MI - * section 3.1. This is used for all message types, MI and Admin. - */ -struct nvme_mi_msg_hdr { - __u8 type; - __u8 nmp; - __u8 meb; - __u8 rsvd0; -} __attribute__((packed)); - -/** - * struct nvme_mi_msg_resp - Generic response type. - * @hdr: the general request/response message header - * @status: response status value (see &enum nvme_mi_resp_status) - * @rsvd0: reserved data, may be defined by specific response - * - * Every response will start with one of these; command-specific responses - * will define parts of the reserved data, and may add further fields. - */ -struct nvme_mi_msg_resp { - struct nvme_mi_msg_hdr hdr; - __u8 status; - __u8 rsvd0[3]; -}; - -/** - * enum nvme_mi_mi_opcode - Operation code for supported NVMe-MI commands. - * @nvme_mi_mi_opcode_mi_data_read: Read NVMe-MI Data Structure - * @nvme_mi_mi_opcode_subsys_health_status_poll: Subsystem Health Status Poll - * @nvme_mi_mi_opcode_configuration_set: MI Configuration Set - * @nvme_mi_mi_opcode_configuration_get: MI Configuration Get - */ -enum nvme_mi_mi_opcode { - nvme_mi_mi_opcode_mi_data_read = 0x00, - nvme_mi_mi_opcode_subsys_health_status_poll = 0x01, - nvme_mi_mi_opcode_configuration_set = 0x03, - nvme_mi_mi_opcode_configuration_get = 0x04, -}; - -/** - * struct nvme_mi_mi_req_hdr - MI request message header. - * @hdr: generic MI message header - * @opcode: opcode (OPC) for the specific MI command - * @rsvd0: reserved bytes - * @cdw0: Management Request Doubleword 0 - command specific usage - * @cdw1: Management Request Doubleword 1 - command specific usage - * - * Wire format for MI request message headers, defined in section 5 of NVMe-MI. - */ -struct nvme_mi_mi_req_hdr { - struct nvme_mi_msg_hdr hdr; - __u8 opcode; - __u8 rsvd0[3]; - __le32 cdw0, cdw1; -}; - -/** - * struct nvme_mi_mi_resp_hdr - MI response message header. - * @hdr: generic MI message header - * @status: generic response status from command; non-zero on failure. - * @nmresp: NVMe Management Response: command-type-specific response data - * - * Wire format for MI response message header, defined in section 5 of NVMe-MI. - */ -struct nvme_mi_mi_resp_hdr { - struct nvme_mi_msg_hdr hdr; - __u8 status; - __u8 nmresp[3]; -}; - -/** - * enum nvme_mi_dtyp - Data Structure Type field. - * @nvme_mi_dtyp_subsys_info: NVM Subsystem Information - * @nvme_mi_dtyp_port_info: Port information - * @nvme_mi_dtyp_ctrl_list: Controller List - * @nvme_mi_dtyp_ctrl_info: Controller Information - * @nvme_mi_dtyp_opt_cmd_support: Optionally Supported Command List - * @nvme_mi_dtyp_meb_support: Management Endpoint Buffer Command Support List - * - * Data Structure Type field for Read NVMe-MI Data Structure command, used to - * indicate the particular structure to query from the endpoint. - */ -enum nvme_mi_dtyp { - nvme_mi_dtyp_subsys_info = 0x00, - nvme_mi_dtyp_port_info = 0x01, - nvme_mi_dtyp_ctrl_list = 0x02, - nvme_mi_dtyp_ctrl_info = 0x03, - nvme_mi_dtyp_opt_cmd_support = 0x04, - nvme_mi_dtyp_meb_support = 0x05, -}; - -/** - * enum nvme_mi_config_id - NVMe-MI Configuration identifier. - * @NVME_MI_CONFIG_SMBUS_FREQ: Current SMBus/I2C frequency - * @NVME_MI_CONFIG_HEALTH_STATUS_CHANGE: Health Status change - used to clear - * health status bits in CCS bits of - * status poll. Only for Set ops. - * @NVME_MI_CONFIG_MCTP_MTU: MCTP maximum transmission unit size of port - * specified in dw 0 - * @NVME_MI_CONFIG_AE: Asynchronous Events configuration - * Configuration parameters for the MI Get/Set Configuration commands. - * - * See &nvme_mi_mi_config_get() and &nvme_mi_config_set(). - */ -enum nvme_mi_config_id { - NVME_MI_CONFIG_SMBUS_FREQ = 0x1, - NVME_MI_CONFIG_HEALTH_STATUS_CHANGE = 0x2, - NVME_MI_CONFIG_MCTP_MTU = 0x3, - NVME_MI_CONFIG_AE = 0x4, -}; - -/** - * enum nvme_mi_config_smbus_freq - SMBus/I2C frequency values - * @NVME_MI_CONFIG_SMBUS_FREQ_100kHz: 100kHz - * @NVME_MI_CONFIG_SMBUS_FREQ_400kHz: 400kHz - * @NVME_MI_CONFIG_SMBUS_FREQ_1MHz: 1MHz - * - * Values used in the SMBus Frequency device configuration. See - * &nvme_mi_mi_config_get_smbus_freq() and &nvme_mi_mi_config_set_smbus_freq(). - */ -enum nvme_mi_config_smbus_freq { - NVME_MI_CONFIG_SMBUS_FREQ_100kHz = 0x1, - NVME_MI_CONFIG_SMBUS_FREQ_400kHz = 0x2, - NVME_MI_CONFIG_SMBUS_FREQ_1MHz = 0x3, -}; - -/* Asynchronous Event Message definitions*/ - -/** - * struct nvme_mi_aem_supported_list_header - Asynchronous Event Supported List Header. - * @numaes: Number of AE supported data structures that follow the header - * @aeslver: AE Supported List Version - * @aest: AE Supported list length (including this header) - * @aeslhl: AE Supported list header length - * - * This header preceeds a number, (&numaes), of AE supported data structures - */ -struct nvme_mi_aem_supported_list_header { - __u8 numaes; - __u8 aeslver;//Should be zero - __le16 aest; - __u8 aeslhl; //Should be 5 -} __attribute__((packed)); - -/** - * struct nvme_mi_aem_supported_item - AE Supported List Item - * @aesl: AE supported list item length - * @aesi: AE supported info - * - * Following this header should be hdr.numaes entries of - * nvme_mi_aem_supported_item structures - */ -struct nvme_mi_aem_supported_item { - __u8 aesl;//Length of this item. Set to 3 - __le16 aesi; -} __attribute__((packed)); - -/** - * nvme_mi_aem_aesi_get_aese() - return aese from aesi field - * @aesi: aesi field from @nvme_mi_aem_supported_item - * - * Returns: A bool representing the aese value - */ -bool nvme_mi_aem_aesi_get_aese(__le16 aesi); - -/** - * nvme_mi_aem_aesi_get_aesid() - return aesid from aesi field - * @aesi: aesi field from @nvme_mi_aem_supported_item - * - * Returns: aesid value - */ -__u8 nvme_mi_aem_aesi_get_aesid(__le16 aesi); - -/** - * nvme_mi_aem_aesi_set_aesid() - set aesid in the aesi field - * @item: Pointer to @nvme_mi_aem_supported_item to update the aesi field - * @aesid: aesid value to use - */ -void nvme_mi_aem_aesi_set_aesid(struct nvme_mi_aem_supported_item *item, __u8 aesid); - -/** - * nvme_mi_aem_aesi_set_aee() - set aee in the aesi field - * @item: Pointer to @nvme_mi_aem_supported_item to update the aesi field - * @enabled: aee value to use - */ -void nvme_mi_aem_aesi_set_aee(struct nvme_mi_aem_supported_item *item, bool enabled); - -/** - * struct nvme_mi_aem_supported_list - AE Supported List received with GET CONFIG Asynchronous Event - * @hdr: AE supported list header - * - * Following this header should be hdr.numaes entries of - * nvme_mi_aem_supported_item structures - */ -struct nvme_mi_aem_supported_list { - struct nvme_mi_aem_supported_list_header hdr; -} __attribute__((packed)); - -/** - * struct nvme_mi_aem_enable_item - AE Enabled item entry - * @aeel: AE Enable Length (length of this structure which is 3) - * @aeei: AE Enable Info - * - */ -struct nvme_mi_aem_enable_item { - __u8 aeel; - __le16 aeei; -} __attribute__((packed)); - -/** - * nvme_mi_aem_aeei_get_aee() - return aee from aeei field - * @aeei: aeei field from @nvme_mi_aem_enable_item - * - * Returns: aee value - */ -bool nvme_mi_aem_aeei_get_aee(__le16 aeei); - -/** - * nvme_mi_aem_aeei_get_aeeid() - return aeeid from aeei field - * @aeei: aeei field from @nvme_mi_aem_enable_item - * - * Returns: aeeid value - */ -__u8 nvme_mi_aem_aeei_get_aeeid(__le16 aeei); - -/** - * nvme_mi_aem_aeei_set_aeeid() - set aeeid in the aeei field - * @item: Pointer to @nvme_mi_aem_enable_item to update the aeei field - * @aeeid: aeeid value to use - */ -void nvme_mi_aem_aeei_set_aeeid(struct nvme_mi_aem_enable_item *item, __u8 aeeid); - -/** - * nvme_mi_aem_aeei_set_aee() - set aee in the aeei field - * @item: Pointer to @nvme_mi_aem_enable_item to update the aee field - * @enabled: aee value to use - */ -void nvme_mi_aem_aeei_set_aee(struct nvme_mi_aem_enable_item *item, bool enabled); - -/** - * struct nvme_mi_aem_enable_list_header - AE Enable list header - * @numaee: Number of AE enable items following the header - * @aeelver: Version of the AE enable list (zero) - * @aeetl: Total length of the AE enable list including header and items - * @aeelhl: Header length of this header (5) - */ -struct nvme_mi_aem_enable_list_header { - __u8 numaee; - __u8 aeelver; - __le16 aeetl; - __u8 aeelhl; -} __attribute__((packed)); - -/** - * struct nvme_mi_aem_enable_list - AE enable list sent with SET CONFIG Asyncronous Event - * @hdr: AE enable list header - * - * Following this header should be hdr.numaee entries of nvme_mi_aem_enable_item structures - */ -struct nvme_mi_aem_enable_list { - struct nvme_mi_aem_enable_list_header hdr; -} __attribute__((packed)); - -/** - * struct nvme_mi_aem_occ_data - AEM Message definition. - * @aelhlen: AE Occurrence Header Length - * @aeosil: AE Occurrence Specific Info Length - * @aeovsil: AE Occurrence Vendor Specific Info Length - * @aeoui: AE Occurrence Unique ID made up of other subfields - * - * A single entry of ae occurrence data that comes with an nvme_aem_msg. - * Following this structure is variable length AEOSI (occurrence specific - * info) and variable length AEVSI (vendor specific info). The length of - * AEOSI is specified by aeosil and the length of AEVSI is specified by - * AEVSI. Neither field is mandatory and shall be omitted if their length - * parameter is set to zero. - */ -struct nvme_mi_aem_occ_data { - __u8 aelhlen; - __u8 aeosil; - __u8 aeovsil; - struct { - __u8 aeoi; - __le32 aeocidi; - __u8 aessi; - } __attribute__((packed)) aeoui; -} __attribute__((packed)); - -/** - * struct nvme_mi_aem_occ_list_hdr - AE occurrence list header - * @numaeo: Number of AE Occurrence Data Structures - * @aelver: AE Occurrence List Version Number - * @aeolli: AE Occurrence List Length Info (AEOLLI) - * @aeolhl: AE Occurrence List Header Length (shall be set to 7) - * @aemti: AEM Transmission Info - * - * The header for the occurrence list. numaeo defines how many - * nvme_mi_aem_occ_data structures (including variable payaloads) are included. - * Following this header is each of the numaeo occurrence data structures. - */ -struct nvme_mi_aem_occ_list_hdr { - __u8 numaeo; - __u8 aelver; - __u8 aeolli[3];//24-bits - __u8 aeolhl; - __u8 aemti; -} __attribute__((packed)); - -/** - * nvme_mi_aem_aemti_get_aemgn() - return aemgn from aemti field - * @aemti: aemti field from @nvme_mi_aem_occ_list_hdr - * - * Returns: aemgn value - */ -__u8 nvme_mi_aem_aemti_get_aemgn(__u8 aemti); - -/** - * nvme_mi_aem_aeolli_get_aeoltl() - return aeoltl from aeolli field - * @aeolli: Pointer to 3 byte aeolli field from @nvme_mi_aem_occ_list_hdr - * - * Returns: aeoltl value - */ -__u32 nvme_mi_aem_aeolli_get_aeoltl(__u8 *aeolli); - -/** - * nvme_mi_aem_aeolli_set_aeoltl() - set aeoltl in the aeolli field - * @hdr:Pointer to @nvme_mi_aem_occ_list_hdr to set the aeolli field - * @aeoltl: aeoltl value to use - */ -void nvme_mi_aem_aeolli_set_aeoltl(struct nvme_mi_aem_occ_list_hdr *hdr, __u32 aeoltl); - -/** - * struct nvme_mi_aem_msg - AEM Message definition. - * @hdr: the general response message header - * @occ_list_hdr: ae occurrence list header. - * - * Every ae message will start with one of these. The occ_list_hder wil define - * information about how many ae occ data entries are included. Each entry is - * defined by the nvme_mi_aem_occ_data structure which will follow the - * occ_list_hdr. Each nvme_mi_aem_occ_data structure has a fixed length header - * but a variable length payload ude to occurrence specific and vendor specific - * info. For this reason, do not index the nvme_mi_ae_occ data structures by - * array or fixed offset. - */ -struct nvme_mi_aem_msg { - struct nvme_mi_msg_hdr hdr; - struct nvme_mi_aem_occ_list_hdr occ_list_hdr; -} __attribute__((packed)); - -/* Admin command definitions */ - -/** - * struct nvme_mi_admin_req_hdr - Admin command request header. - * @hdr: Generic MI message header - * @opcode: Admin command opcode (using enum nvme_admin_opcode) - * @flags: Command Flags, indicating dlen and doff validity; Only defined in - * NVMe-MI version 1.1, no fields defined in 1.2 (where the dlen/doff - * are always considered valid). - * @ctrl_id: Controller ID target of command - * @cdw1: Submission Queue Entry doubleword 1 - * @cdw2: Submission Queue Entry doubleword 2 - * @cdw3: Submission Queue Entry doubleword 3 - * @cdw4: Submission Queue Entry doubleword 4 - * @cdw5: Submission Queue Entry doubleword 5 - * @doff: Offset of data to return from command - * @dlen: Length of sent/returned data - * @rsvd0: Reserved - * @rsvd1: Reserved - * @cdw10: Submission Queue Entry doubleword 10 - * @cdw11: Submission Queue Entry doubleword 11 - * @cdw12: Submission Queue Entry doubleword 12 - * @cdw13: Submission Queue Entry doubleword 13 - * @cdw14: Submission Queue Entry doubleword 14 - * @cdw15: Submission Queue Entry doubleword 15 - * - * Wire format for Admin command message headers, defined in section 6 of - * NVMe-MI. - */ -struct nvme_mi_admin_req_hdr { - struct nvme_mi_msg_hdr hdr; - __u8 opcode; - __u8 flags; - __le16 ctrl_id; - __le32 cdw1, cdw2, cdw3, cdw4, cdw5; - __le32 doff; - __le32 dlen; - __le32 rsvd0, rsvd1; - __le32 cdw10, cdw11, cdw12, cdw13, cdw14, cdw15; -} __attribute((packed)); - -/** - * struct nvme_mi_admin_resp_hdr - Admin command response header. - * @hdr: Generic MI message header - * @status: Generic response code, non-zero on failure - * @rsvd0: Reserved - * @cdw0: Completion Queue Entry doubleword 0 - * @cdw1: Completion Queue Entry doubleword 1 - * @cdw3: Completion Queue Entry doubleword 3 - * - * This is the generic response format with the three doublewords of completion - * queue data, plus optional response data. - */ -struct nvme_mi_admin_resp_hdr { - struct nvme_mi_msg_hdr hdr; - __u8 status; - __u8 rsvd0[3]; - __le32 cdw0, cdw1, cdw3; -} __attribute__((packed)); - -/** - * enum nvme_mi_control_opcode - Operation code for Control Primitives. - * @nvme_mi_control_opcode_pause: Suspend response transmission/timeout - * @nvme_mi_control_opcode_resume: Resume from a paused condition - * @nvme_mi_control_opcode_abort: Re-initialize a Command Slot to the Idle state - * @nvme_mi_control_opcode_get_state: Get the state of a Command Slot - * @nvme_mi_control_opcode_replay: Retransmit the Response Message - */ -enum nvme_mi_control_opcode { - nvme_mi_control_opcode_pause = 0x00, - nvme_mi_control_opcode_resume = 0x01, - nvme_mi_control_opcode_abort = 0x02, - nvme_mi_control_opcode_get_state = 0x03, - nvme_mi_control_opcode_replay = 0x04, -}; - -/** - * struct nvme_mi_control_req - The Control Primitive request. - * @hdr: Generic MI message header - * @opcode: Control Primitive Opcodes (using &enum nvme_mi_control_opcode) - * @tag: flag - Opaque value passed from request to response - * @cpsp: Control Primitive Specific Parameter - * - */ -struct nvme_mi_control_req { - struct nvme_mi_msg_hdr hdr; - __u8 opcode; - __u8 tag; - __le16 cpsp; -} __attribute((packed)); - -/** struct nvme_mi_control_resp - The Control Primitive response. - * @hdr: Generic MI message header - * @status: Generic response code, non-zero on failure - * @tag: flag - Opaque value passed from request to response - * @cpsr: Control Primitive Specific Response - * - */ - -struct nvme_mi_control_resp { - struct nvme_mi_msg_hdr hdr; - __u8 status; - __u8 tag; - __le16 cpsr; -} __attribute((packed)); - -/** - * nvme_mi_status_to_string() - return a string representation of the MI + * libnvme_mi_status_to_string() - return a string representation of the MI * status. * @status: MI response status * @@ -649,89 +98,89 @@ struct nvme_mi_control_resp { * * Returns: A string representing the status value */ -const char *nvme_mi_status_to_string(int status); +const char *libnvme_mi_status_to_string(int status); /* Top level management object: NVMe-MI Management Endpoint */ -struct nvme_mi_ep; +struct libnvme_mi_ep; /** - * typedef nvme_mi_ep_t - MI Endpoint object. + * typedef libnvme_mi_ep_t - MI Endpoint object. * * Represents our communication endpoint on the remote MI-capable device. * To be used for direct MI commands for the endpoint (through the - * nvme_mi_mi_* functions(), or to communicate with individual controllers - * (see &nvme_mi_init_ctrl). + * libnvme_mi_mi_* functions(), or to communicate with individual controllers + * (see &libnvme_mi_init_ctrl). * * Endpoints are created through a transport-specific constructor; currently - * only MCTP-connected endpoints are supported, through &nvme_mi_open_mctp. + * only MCTP-connected endpoints are supported, through &libnvme_mi_open_mctp. * Subsequent operations on the endpoint (and related controllers) are * transport-independent. */ -typedef struct nvme_mi_ep * nvme_mi_ep_t; +typedef struct libnvme_mi_ep * libnvme_mi_ep_t; /** - * nvme_mi_set_csi - Assign a CSI to an endpoint. + * libnvme_mi_set_csi - Assign a CSI to an endpoint. * @ep: Endpoint * @csi: value to use for CSI bit in NMP (0 or 1) for this endpoint * * Return: 0 if successful, -1 otherwise (some endpoints may not support) * */ -int nvme_mi_set_csi(nvme_mi_ep_t ep, uint8_t csi); +int libnvme_mi_set_csi(libnvme_mi_ep_t ep, uint8_t csi); /** - * nvme_mi_first_endpoint - Start endpoint iterator - * @ctx: &struct nvme_global_ctx object + * libnvme_mi_first_endpoint - Start endpoint iterator + * @ctx: &struct libnvme_global_ctx object * * Return: first MI endpoint object under this root, or NULL if no endpoints * are present. * - * See: &nvme_mi_next_endpoint, &nvme_mi_for_each_endpoint + * See: &libnvme_mi_next_endpoint, &libnvme_mi_for_each_endpoint */ -nvme_mi_ep_t nvme_mi_first_endpoint(struct nvme_global_ctx *ctx); +libnvme_mi_ep_t libnvme_mi_first_endpoint(struct libnvme_global_ctx *ctx); /** - * nvme_mi_next_endpoint - Continue endpoint iterator - * @ctx: &struct nvme_global_ctx object - * @e: &nvme_mi_ep_t current position of iterator + * libnvme_mi_next_endpoint - Continue endpoint iterator + * @ctx: &struct libnvme_global_ctx object + * @e: &libnvme_mi_ep_t current position of iterator * * Return: next endpoint MI endpoint object after @e under this root, or NULL * if no further endpoints are present. * - * See: &nvme_mi_first_endpoint, &nvme_mi_for_each_endpoint + * See: &libnvme_mi_first_endpoint, &libnvme_mi_for_each_endpoint */ -nvme_mi_ep_t nvme_mi_next_endpoint(struct nvme_global_ctx *ctx, nvme_mi_ep_t e); +libnvme_mi_ep_t libnvme_mi_next_endpoint(struct libnvme_global_ctx *ctx, libnvme_mi_ep_t e); /** - * nvme_mi_for_each_endpoint - Iterator for NVMe-MI endpoints. - * @c: &struct nvme_global_ctx object - * @e: &nvme_mi_ep_t object, set on each iteration + * libnvme_mi_for_each_endpoint - Iterator for NVMe-MI endpoints. + * @c: &struct libnvme_global_ctx object + * @e: &libnvme_mi_ep_t object, set on each iteration */ -#define nvme_mi_for_each_endpoint(c, e) \ - for (e = nvme_mi_first_endpoint(c); e != NULL; \ - e = nvme_mi_next_endpoint(c, e)) +#define libnvme_mi_for_each_endpoint(c, e) \ + for (e = libnvme_mi_first_endpoint(c); e != NULL; \ + e = libnvme_mi_next_endpoint(c, e)) /** - * nvme_mi_for_each_endpoint_safe - Iterator for NVMe-MI endpoints, allowing + * libnvme_mi_for_each_endpoint_safe - Iterator for NVMe-MI endpoints, allowing * deletion during traversal - * @c: &struct nvme_global_ctx object - * @e: &nvme_mi_ep_t object, set on each iteration - * @_e: &nvme_mi_ep_t object used as temporary storage + * @c: &struct libnvme_global_ctx object + * @e: &libnvme_mi_ep_t object, set on each iteration + * @_e: &libnvme_mi_ep_t object used as temporary storage */ -#define nvme_mi_for_each_endpoint_safe(c, e, _e) \ - for (e = nvme_mi_first_endpoint(c), _e = nvme_mi_next_endpoint(c, e); \ +#define libnvme_mi_for_each_endpoint_safe(c, e, _e) \ + for (e = libnvme_mi_first_endpoint(c), _e = libnvme_mi_next_endpoint(c, e); \ e != NULL; \ - e = _e, _e = nvme_mi_next_endpoint(c, e)) + e = _e, _e = libnvme_mi_next_endpoint(c, e)) /** - * nvme_mi_ep_set_timeout - set a timeout for NVMe-MI responses + * libnvme_mi_ep_set_timeout - set a timeout for NVMe-MI responses * @ep: MI endpoint object * @timeout_ms: Timeout for MI responses, given in milliseconds */ -int nvme_mi_ep_set_timeout(nvme_mi_ep_t ep, unsigned int timeout_ms); +int libnvme_mi_ep_set_timeout(libnvme_mi_ep_t ep, unsigned int timeout_ms); /** - * nvme_mi_ep_set_mprt_max - set the maximum wait time for a More Processing + * libnvme_mi_ep_set_mprt_max - set the maximum wait time for a More Processing * Required response * @ep: MI endpoint object * @mprt_max_ms: Maximum more processing required wait time @@ -744,80 +193,80 @@ int nvme_mi_ep_set_timeout(nvme_mi_ep_t ep, unsigned int timeout_ms); * This function provides a way to limit the maximum time we're prepared to * wait for the final response. Specify zero in @mprt_max_ms for no limit. * This should be larger than the command/response timeout set in - * &nvme_mi_ep_set_timeout(). + * &libnvme_mi_ep_set_timeout(). */ -void nvme_mi_ep_set_mprt_max(nvme_mi_ep_t ep, unsigned int mprt_max_ms); +void libnvme_mi_ep_set_mprt_max(libnvme_mi_ep_t ep, unsigned int mprt_max_ms); /** - * nvme_mi_ep_get_timeout - get the current timeout value for NVMe-MI responses + * libnvme_mi_ep_get_timeout - get the current timeout value for NVMe-MI responses * @ep: MI endpoint object * * Returns the current timeout value, in milliseconds, for this endpoint. */ -unsigned int nvme_mi_ep_get_timeout(nvme_mi_ep_t ep); +unsigned int libnvme_mi_ep_get_timeout(libnvme_mi_ep_t ep); /** - * nvme_mi_first_transport_handle - Start transport handle iterator - * @ep: &nvme_mi_ep_t object + * libnvme_mi_first_transport_handle - Start transport handle iterator + * @ep: &libnvme_mi_ep_t object * * Return: first transport handle to a MI controller object under this * root, or NULL if no controllers are present. * - * See: &nvme_mi_next_transport_handle, &nvme_mi_for_each_transport_handle + * See: &libnvme_mi_next_transport_handle, &libnvme_mi_for_each_transport_handle */ -struct nvme_transport_handle *nvme_mi_first_transport_handle(nvme_mi_ep_t ep); +struct libnvme_transport_handle *libnvme_mi_first_transport_handle(libnvme_mi_ep_t ep); /** - * nvme_mi_next_transport_handle - Continue transport handle iterator - * @ep: &nvme_mi_ep_t object + * libnvme_mi_next_transport_handle - Continue transport handle iterator + * @ep: &libnvme_mi_ep_t object * @hdl: &nvme_transport_handle current position of iterator * * Return: next transport handle to MI controller object after @c under * this endpoint, or NULL if no further controllers are present. * - * See: &nvme_mi_first_transport_handle, &nvme_mi_for_each_transport_handle + * See: &libnvme_mi_first_transport_handle, &libnvme_mi_for_each_transport_handle */ -struct nvme_transport_handle *nvme_mi_next_transport_handle(nvme_mi_ep_t ep, - struct nvme_transport_handle *hdl); +struct libnvme_transport_handle *libnvme_mi_next_transport_handle(libnvme_mi_ep_t ep, + struct libnvme_transport_handle *hdl); /** - * nvme_mi_for_each_transport_handle - Iterator for transport handle to NVMe-MI controllers. - * @ep: &nvme_mi_ep_t containing endpoints + * libnvme_mi_for_each_transport_handle - Iterator for transport handle to NVMe-MI controllers. + * @ep: &libnvme_mi_ep_t containing endpoints * @hdl: &nvme_trasnport_handle 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 - * call &nvme_mi_scan_ep() to scan for the controllers first. + * call &libnvme_mi_scan_ep() to scan for the controllers first. * - * See: &nvme_mi_scan_ep() + * See: &libnvme_mi_scan_ep() */ -#define nvme_mi_for_each_transport_handle(ep, hdl) \ - for (hdl = nvme_mi_first_transport_handle(ep); hdl != NULL; \ - hdl = nvme_mi_next_transport_handle(ep, hdl)) +#define libnvme_mi_for_each_transport_handle(ep, hdl) \ + for (hdl = libnvme_mi_first_transport_handle(ep); hdl != NULL; \ + hdl = libnvme_mi_next_transport_handle(ep, hdl)) /** - * nvme_mi_for_each_transport_handle_safe - Iterator for transport handle to NVMe-MI controllers, allowing + * libnvme_mi_for_each_transport_handle_safe - Iterator for transport handle to NVMe-MI controllers, allowing * deletion during traversal - * @ep: &nvme_mi_ep_t containing controllers + * @ep: &libnvme_mi_ep_t containing controllers * @hdl: &nvme_transport_handle object, set on each iteration * @_hdl: &nvme_transport_handle 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 * explicitly (or you're just iterating to destroy controllers) you'll probably - * want to call &nvme_mi_scan_ep() to scan for the controllers first. + * want to call &libnvme_mi_scan_ep() to scan for the controllers first. * - * See: &nvme_mi_scan_ep() + * See: &libnvme_mi_scan_ep() */ -#define nvme_mi_for_each_transport_handle_safe(ep, hdl, _hdl) \ - for (hdl = nvme_mi_first_transport_handle(ep), \ - _hdl = nvme_mi_next_transport_handle(ep, hdl); \ +#define libnvme_mi_for_each_transport_handle_safe(ep, hdl, _hdl) \ + for (hdl = libnvme_mi_first_transport_handle(ep), \ + _hdl = libnvme_mi_next_transport_handle(ep, hdl); \ hdl != NULL; \ - hdl = _hdl, _hdl = nvme_mi_next_transport_handle(ep, hdl)) + hdl = _hdl, _hdl = libnvme_mi_next_transport_handle(ep, hdl)) /** - * nvme_mi_open_mctp() - Create an endpoint using a MCTP connection. - * @ctx: &struct nvme_global_ctx object + * libnvme_mi_open_mctp() - Create an endpoint using a MCTP connection. + * @ctx: &struct libnvme_global_ctx object * @netid: MCTP network ID on this system * @eid: MCTP endpoint ID * @@ -826,29 +275,29 @@ struct nvme_transport_handle *nvme_mi_next_transport_handle(nvme_mi_ep_t ep, * * Return: New endpoint object for @netid & @eid, or NULL on failure. * - * See &nvme_mi_close + * See &libnvme_mi_close */ -nvme_mi_ep_t nvme_mi_open_mctp(struct nvme_global_ctx *ctx, +libnvme_mi_ep_t libnvme_mi_open_mctp(struct libnvme_global_ctx *ctx, unsigned int netid, uint8_t eid); /** - * nvme_mi_aem_open() - Prepare an existing endpoint to receive AEMs + * libnvme_mi_aem_open() - Prepare an existing endpoint to receive AEMs * @ep: Endpoint to configure for AEMs * * Return: 0 if success, -1 otherwise */ -int nvme_mi_aem_open(nvme_mi_ep_t ep); +int libnvme_mi_aem_open(libnvme_mi_ep_t ep); /** - * nvme_mi_close() - Close an endpoint connection and release resources, + * libnvme_mi_close() - Close an endpoint connection and release resources, * including controller objects. * * @ep: Endpoint object to close */ -void nvme_mi_close(nvme_mi_ep_t ep); +void libnvme_mi_close(libnvme_mi_ep_t ep); /** - * nvme_mi_scan_mctp - look for MCTP-connected NVMe-MI endpoints. + * libnvme_mi_scan_mctp - look for MCTP-connected NVMe-MI endpoints. * * Description: This function queries the system MCTP daemon ("mctpd") over * D-Bus, to find MCTP endpoints that report support for NVMe-MI over MCTP. @@ -856,20 +305,20 @@ void nvme_mi_close(nvme_mi_ep_t ep); * This requires libvnme-mi to be compiled with D-Bus support; if not, this * will return NULL. * - * Return: A @struct nvme_global_ctx populated with a set of + * Return: A @struct libnvme_global_ctx populated with a set of * MCTP-connected endpoints, or NULL on failure */ -struct nvme_global_ctx *nvme_mi_scan_mctp(void); +struct libnvme_global_ctx *libnvme_mi_scan_mctp(void); /** - * nvme_mi_scan_ep - query an endpoint for its NVMe controllers. + * libnvme_mi_scan_ep - query an endpoint for its NVMe controllers. * @ep: Endpoint to scan * @force_rescan: close existing controllers and rescan * * This function queries an MI endpoint for the controllers available, by * performing an MI Read MI Data Structure command (requesting the * controller list). The controllers are stored in the endpoint's internal - * list, and can be iterated with nvme_mi_for_each_ctrl. + * list, and can be iterated with libnvme_mi_for_each_ctrl. * * This will only scan the endpoint once, unless @force_rescan is set. If * so, all existing controller objects will be freed - the caller must not @@ -878,40 +327,40 @@ struct nvme_global_ctx *nvme_mi_scan_mctp(void); * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. * - * See: &nvme_mi_for_each_ctrl + * See: &libnvme_mi_for_each_ctrl */ -int nvme_mi_scan_ep(nvme_mi_ep_t ep, bool force_rescan); +int libnvme_mi_scan_ep(libnvme_mi_ep_t ep, bool force_rescan); /** - * nvme_mi_init_transport_handle() - initialise a transport handle to NVMe controller. + * libnvme_mi_init_transport_handle() - initialise a transport handle to NVMe controller. * @ep: Endpoint to create under * @ctrl_id: ID of controller to initialize. * * Create a connection to a controller behind the endpoint specified in @ep. * Controller IDs may be queried from the endpoint through - * &nvme_mi_mi_read_mi_data_ctrl_list. + * &libnvme_mi_mi_read_mi_data_ctrl_list. * * Return: New transport handle object, or NULL on failure. * - * See &nvme_mi_close_transport_handle + * See &libnvme_mi_close_transport_handle */ -struct nvme_transport_handle *nvme_mi_init_transport_handle(nvme_mi_ep_t ep, __u16 ctrl_id); +struct libnvme_transport_handle *libnvme_mi_init_transport_handle(libnvme_mi_ep_t ep, __u16 ctrl_id); /** - * nvme_mi_ctrl_id() - get the ID of a controller + * libnvme_mi_ctrl_id() - get the ID of a controller * @hdl: transport handle 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_transport_handle, but may have been created internally via - * @nvme_mi_scan_ep. + * @libnvme_mi_init_transport_handle, but may have been created internally via + * @libnvme_mi_scan_ep. * * Return: the (locally-stored) ID of this controller. */ -__u16 nvme_mi_ctrl_id(struct nvme_transport_handle *hdl); +__u16 libnvme_mi_ctrl_id(struct libnvme_transport_handle *hdl); /** - * nvme_mi_endpoint_desc - Get a string describing a MI endpoint. + * libnvme_mi_endpoint_desc - Get a string describing a MI endpoint. * @ep: endpoint to describe * * Generates a human-readable string describing the endpoint, with possibly @@ -921,12 +370,12 @@ __u16 nvme_mi_ctrl_id(struct nvme_transport_handle *hdl); * Return: a newly-allocated string containing the endpoint description, or * NULL on failure. */ -char *nvme_mi_endpoint_desc(nvme_mi_ep_t ep); +char *libnvme_mi_endpoint_desc(libnvme_mi_ep_t ep); -/* MI Command API: nvme_mi_mi_ prefix */ +/* MI Command API: libnvme_mi_mi_ prefix */ /** - * nvme_mi_mi_xfer() - Raw mi transfer interface. + * libnvme_mi_mi_xfer() - Raw mi transfer interface. * @ep: endpoint to send the MI command to * @mi_req: request data * @req_data_size: size of request data payload @@ -949,14 +398,14 @@ char *nvme_mi_endpoint_desc(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_mi_xfer(nvme_mi_ep_t ep, +int libnvme_mi_mi_xfer(libnvme_mi_ep_t ep, struct nvme_mi_mi_req_hdr *mi_req, size_t req_data_size, struct nvme_mi_mi_resp_hdr *mi_resp, size_t *resp_data_size); /** - * nvme_mi_mi_read_mi_data_subsys() - Perform a Read MI Data Structure command, + * libnvme_mi_mi_read_mi_data_subsys() - Perform a Read MI Data Structure command, * retrieving subsystem data. * @ep: endpoint for MI communication * @s: subsystem information to populate @@ -967,18 +416,18 @@ int nvme_mi_mi_xfer(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_mi_read_mi_data_subsys(nvme_mi_ep_t ep, +int libnvme_mi_mi_read_mi_data_subsys(libnvme_mi_ep_t ep, struct nvme_mi_read_nvm_ss_info *s); /** - * nvme_mi_mi_read_mi_data_port() - Perform a Read MI Data Structure command, + * libnvme_mi_mi_read_mi_data_port() - Perform a Read MI Data Structure command, * retrieving port data. * @ep: endpoint for MI communication * @portid: id of port data to retrieve * @p: port information to populate * * Retrieves the Port information, for the specified port ID. The subsystem - * data (from &nvme_mi_mi_read_mi_data_subsys) nmp field contains the allowed + * data (from &libnvme_mi_mi_read_mi_data_subsys) nmp field contains the allowed * range of port IDs. * * See &struct nvme_mi_read_port_info. @@ -986,11 +435,11 @@ int nvme_mi_mi_read_mi_data_subsys(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_mi_read_mi_data_port(nvme_mi_ep_t ep, __u8 portid, +int libnvme_mi_mi_read_mi_data_port(libnvme_mi_ep_t ep, __u8 portid, struct nvme_mi_read_port_info *p); /** - * nvme_mi_mi_read_mi_data_ctrl_list() - Perform a Read MI Data Structure + * libnvme_mi_mi_read_mi_data_ctrl_list() - Perform a Read MI Data Structure * command, retrieving the list of attached controllers. * @ep: endpoint for MI communication * @start_ctrlid: starting controller ID @@ -1004,11 +453,11 @@ int nvme_mi_mi_read_mi_data_port(nvme_mi_ep_t ep, __u8 portid, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise.. */ -int nvme_mi_mi_read_mi_data_ctrl_list(nvme_mi_ep_t ep, __u8 start_ctrlid, +int libnvme_mi_mi_read_mi_data_ctrl_list(libnvme_mi_ep_t ep, __u8 start_ctrlid, struct nvme_ctrl_list *list); /** - * nvme_mi_mi_read_mi_data_ctrl() - Perform a Read MI Data Structure command, + * libnvme_mi_mi_read_mi_data_ctrl() - Perform a Read MI Data Structure command, * retrieving controller information * @ep: endpoint for MI communication * @ctrl_id: ID of controller to query @@ -1022,11 +471,11 @@ int nvme_mi_mi_read_mi_data_ctrl_list(nvme_mi_ep_t ep, __u8 start_ctrlid, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise.. */ -int nvme_mi_mi_read_mi_data_ctrl(nvme_mi_ep_t ep, __u16 ctrl_id, +int libnvme_mi_mi_read_mi_data_ctrl(libnvme_mi_ep_t ep, __u16 ctrl_id, struct nvme_mi_read_ctrl_info *ctrl); /** - * nvme_mi_mi_subsystem_health_status_poll() - Read the Subsystem Health + * libnvme_mi_mi_subsystem_health_status_poll() - Read the Subsystem Health * Data Structure from the NVM subsystem * @ep: endpoint for MI communication * @clear: flag to clear the Composite Controller Status state @@ -1041,11 +490,11 @@ int nvme_mi_mi_read_mi_data_ctrl(nvme_mi_ep_t ep, __u16 ctrl_id, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise.. */ -int nvme_mi_mi_subsystem_health_status_poll(nvme_mi_ep_t ep, bool clear, +int libnvme_mi_mi_subsystem_health_status_poll(libnvme_mi_ep_t ep, bool clear, struct nvme_mi_nvm_ss_health_status *nshds); /** - * nvme_mi_mi_config_get - query a configuration parameter + * libnvme_mi_mi_config_get - query a configuration parameter * @ep: endpoint for MI communication * @dw0: management doubleword 0, containing configuration identifier, plus * config-specific fields @@ -1064,11 +513,11 @@ int nvme_mi_mi_subsystem_health_status_poll(nvme_mi_ep_t ep, bool clear, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise.. */ -int nvme_mi_mi_config_get(nvme_mi_ep_t ep, __u32 dw0, __u32 dw1, +int libnvme_mi_mi_config_get(libnvme_mi_ep_t ep, __u32 dw0, __u32 dw1, __u32 *nmresp); /** - * nvme_mi_mi_config_set - set a configuration parameter + * libnvme_mi_mi_config_set - set a configuration parameter * @ep: endpoint for MI communication * @dw0: management doubleword 0, containing configuration identifier, plus * config-specific fields @@ -1082,10 +531,10 @@ int nvme_mi_mi_config_get(nvme_mi_ep_t ep, __u32 dw0, __u32 dw1, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise.. */ -int nvme_mi_mi_config_set(nvme_mi_ep_t ep, __u32 dw0, __u32 dw1); +int libnvme_mi_mi_config_set(libnvme_mi_ep_t ep, __u32 dw0, __u32 dw1); /** - * nvme_mi_mi_config_get_smbus_freq - get configuration: SMBus port frequency + * libnvme_mi_mi_config_get_smbus_freq - get configuration: SMBus port frequency * @ep: endpoint for MI communication * @port: port ID to query * @freq: output value for current frequency configuration @@ -1097,7 +546,7 @@ int nvme_mi_mi_config_set(nvme_mi_ep_t ep, __u32 dw0, __u32 dw1); * 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_mi_config_get_smbus_freq(nvme_mi_ep_t ep, __u8 port, +static inline int libnvme_mi_mi_config_get_smbus_freq(libnvme_mi_ep_t ep, __u8 port, enum nvme_mi_config_smbus_freq *freq) { __u32 tmp, dw0; @@ -1105,14 +554,14 @@ static inline int nvme_mi_mi_config_get_smbus_freq(nvme_mi_ep_t ep, __u8 port, dw0 = port << 24 | NVME_MI_CONFIG_SMBUS_FREQ; - rc = nvme_mi_mi_config_get(ep, dw0, 0, &tmp); + rc = libnvme_mi_mi_config_get(ep, dw0, 0, &tmp); if (!rc) *freq = (enum nvme_mi_config_smbus_freq)(tmp & 0x3); return rc; } /** - * nvme_mi_mi_config_set_smbus_freq - set configuration: SMBus port frequency + * libnvme_mi_mi_config_set_smbus_freq - set configuration: SMBus port frequency * @ep: endpoint for MI communication * @port: port ID to set * @freq: new frequency configuration @@ -1126,18 +575,18 @@ static inline int nvme_mi_mi_config_get_smbus_freq(nvme_mi_ep_t ep, __u8 port, * 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_mi_config_set_smbus_freq(nvme_mi_ep_t ep, __u8 port, +static inline int libnvme_mi_mi_config_set_smbus_freq(libnvme_mi_ep_t ep, __u8 port, enum nvme_mi_config_smbus_freq freq) { __u32 dw0 = port << 24 | (freq & 0x3) << 8 | NVME_MI_CONFIG_SMBUS_FREQ; - return nvme_mi_mi_config_set(ep, dw0, 0); + return libnvme_mi_mi_config_set(ep, dw0, 0); } /** - * nvme_mi_mi_config_set_health_status_change - clear CCS bits in health status + * libnvme_mi_mi_config_set_health_status_change - clear CCS bits in health status * @ep: endpoint for MI communication * @mask: bitmask to clear * @@ -1146,21 +595,21 @@ static inline int nvme_mi_mi_config_set_smbus_freq(nvme_mi_ep_t ep, __u8 port, * be cleared from future health status poll data, and may be re-triggered by * a future health change event. * - * See &nvme_mi_mi_subsystem_health_status_poll(), &enum nvme_mi_ccs for + * See &libnvme_mi_mi_subsystem_health_status_poll(), &enum nvme_mi_ccs for * values in @mask. * * 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_mi_config_set_health_status_change(nvme_mi_ep_t ep, +static inline int libnvme_mi_mi_config_set_health_status_change(libnvme_mi_ep_t ep, __u32 mask) { - return nvme_mi_mi_config_set(ep, NVME_MI_CONFIG_HEALTH_STATUS_CHANGE, + return libnvme_mi_mi_config_set(ep, NVME_MI_CONFIG_HEALTH_STATUS_CHANGE, mask); } /** - * nvme_mi_mi_config_get_mctp_mtu - get configuration: MCTP MTU + * libnvme_mi_mi_config_get_mctp_mtu - get configuration: MCTP MTU * @ep: endpoint for MI communication * @port: port ID to query * @mtu: output value for current MCTP MTU configuration @@ -1177,7 +626,7 @@ static inline int nvme_mi_mi_config_set_health_status_change(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.. */ -static inline int nvme_mi_mi_config_get_mctp_mtu(nvme_mi_ep_t ep, __u8 port, +static inline int libnvme_mi_mi_config_get_mctp_mtu(libnvme_mi_ep_t ep, __u8 port, __u16 *mtu) { __u32 tmp, dw0; @@ -1185,14 +634,14 @@ static inline int nvme_mi_mi_config_get_mctp_mtu(nvme_mi_ep_t ep, __u8 port, dw0 = port << 24 | NVME_MI_CONFIG_MCTP_MTU; - rc = nvme_mi_mi_config_get(ep, dw0, 0, &tmp); + rc = libnvme_mi_mi_config_get(ep, dw0, 0, &tmp); if (!rc) *mtu = tmp & 0xffff; return rc; } /** - * nvme_mi_mi_config_set_mctp_mtu - set configuration: MCTP MTU + * libnvme_mi_mi_config_set_mctp_mtu - set configuration: MCTP MTU * @ep: endpoint for MI communication * @port: port ID to set * @mtu: new MTU configuration @@ -1208,17 +657,17 @@ static inline int nvme_mi_mi_config_get_mctp_mtu(nvme_mi_ep_t ep, __u8 port, * 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_mi_config_set_mctp_mtu(nvme_mi_ep_t ep, __u8 port, +static inline int libnvme_mi_mi_config_set_mctp_mtu(libnvme_mi_ep_t ep, __u8 port, __u16 mtu) { __u32 dw0 = port << 24 | NVME_MI_CONFIG_MCTP_MTU; - return nvme_mi_mi_config_set(ep, dw0, mtu); + return libnvme_mi_mi_config_set(ep, dw0, mtu); } /** - * nvme_mi_mi_config_get_async_event - get configuration: Asynchronous Event + * libnvme_mi_mi_config_get_async_event - get configuration: Asynchronous Event * @ep: endpoint for MI communication * @aeelver: Asynchronous Event Enable List Version Number * @list: AE Supported list header and list contents @@ -1231,20 +680,20 @@ static inline int nvme_mi_mi_config_set_mctp_mtu(nvme_mi_ep_t ep, __u8 port, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise.. */ -int nvme_mi_mi_config_get_async_event(nvme_mi_ep_t ep, +int libnvme_mi_mi_config_get_async_event(libnvme_mi_ep_t ep, __u8 *aeelver, struct nvme_mi_aem_supported_list *list, size_t *list_num_bytes); /** - * nvme_mi_mi_config_set_async_event - set configuration: Asynchronous Event + * libnvme_mi_mi_config_set_async_event - set configuration: Asynchronous Event * @ep: endpoint for MI communication * @envfa: Enable SR-IOV Virtual Functions AE * @empfa: Enable SR-IOV Physical Functions AE * @encfa: Enable PCI Functions AE. * @aemd: AEM Delay Interval (for Sync only) * @aerd: AEM Retry Delay (for Sync only; time in 100s of ms) - * @enable_list: nvme_mi_aem_enable_listucture containing header and items + * @enable_list: libnvme_mi_aem_enable_listucture containing header and items * of events to be enabled or disabled. This is taken as a delta change * from the current configuration. * @enable_list_size: Size of the enable_list including header and data. @@ -1262,7 +711,7 @@ int nvme_mi_mi_config_get_async_event(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_mi_config_set_async_event(nvme_mi_ep_t ep, +int libnvme_mi_mi_config_set_async_event(libnvme_mi_ep_t ep, bool envfa, bool empfa, bool encfa, @@ -1273,7 +722,7 @@ int nvme_mi_mi_config_set_async_event(nvme_mi_ep_t ep, struct nvme_mi_aem_occ_list_hdr *occ_list, size_t *occ_list_size); -static inline int nvme_mi_aem_ack(nvme_mi_ep_t ep, +static inline int libnvme_mi_aem_ack(libnvme_mi_ep_t ep, struct nvme_mi_aem_occ_list_hdr *occ_list, size_t *occ_list_size) { @@ -1285,7 +734,7 @@ static inline int nvme_mi_aem_ack(nvme_mi_ep_t ep, list.hdr.aeetl = sizeof(struct nvme_mi_aem_enable_list_header); list.hdr.numaee = 0; - return nvme_mi_mi_config_set_async_event(ep, false, false, false, 0, 0, + return libnvme_mi_mi_config_set_async_event(ep, false, false, false, 0, 0, &list, sizeof(list), occ_list, occ_list_size); } @@ -1293,7 +742,7 @@ static inline int nvme_mi_aem_ack(nvme_mi_ep_t ep, /* Admin channel functions */ /** - * nvme_mi_admin_xfer() - Raw admin transfer interface. + * libnvme_mi_admin_xfer() - Raw admin transfer interface. * @hdl: transport handle to send the admin command to * @admin_req: request data * @req_data_size: size of request data payload @@ -1319,7 +768,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(struct nvme_transport_handle *hdl, +int libnvme_mi_admin_xfer(struct libnvme_transport_handle *hdl, struct nvme_mi_admin_req_hdr *admin_req, size_t req_data_size, struct nvme_mi_admin_resp_hdr *admin_resp, @@ -1327,7 +776,7 @@ int nvme_mi_admin_xfer(struct nvme_transport_handle *hdl, size_t *resp_data_size); /** - * nvme_mi_control() - Perform a Control Primitive command + * libnvme_mi_control() - Perform a Control Primitive command * @ep: endpoint for MI communication * @opcode: Control Primitive opcode (using &enum nvme_mi_control_opcode) * @cpsp: Control Primitive Specific Parameter @@ -1341,23 +790,23 @@ int nvme_mi_admin_xfer(struct nvme_transport_handle *hdl, * See: &enum nvme_mi_control_opcode * */ -int nvme_mi_control(nvme_mi_ep_t ep, __u8 opcode, +int libnvme_mi_control(libnvme_mi_ep_t ep, __u8 opcode, __u16 cpsp, __u16 *result_cpsr); /** - * enum nvme_mi_aem_handler_next_action - Next action for the AEM state machine handler + * enum libnvme_mi_aem_handler_next_action - Next action for the AEM state machine handler * @NVME_MI_AEM_HNA_ACK: Send an ack for the AEM * @NVME_MI_AEM_HNA_NONE: No further action * - * Used as return value for the AE callback generated when calling nvme_mi_aem_process + * Used as return value for the AE callback generated when calling libnvme_mi_aem_process */ -enum nvme_mi_aem_handler_next_action { +enum libnvme_mi_aem_handler_next_action { NVME_MI_AEM_HNA_ACK, NVME_MI_AEM_HNA_NONE, }; /** - * struct nvme_mi_event - AE event information structure + * struct libnvme_mi_event - AE event information structure * @aeoi: Event identifier * @aessi: Event occurrence scope info * @aeocidi: Event occurrence scope ID info @@ -1366,11 +815,11 @@ enum nvme_mi_aem_handler_next_action { * @vend_spec_info: Vendor specific info buffer * @vend_spec_info_len: Length of vendor specific info buffer * - * Application callbacks for nvme_mi_aem_process will be able to call - * nvme_mi_aem_get_next_event which will return a pointer to such an identifier + * Application callbacks for libnvme_mi_aem_process will be able to call + * libnvme_mi_aem_get_next_event which will return a pointer to such an identifier * for the next event the application should parse */ -struct nvme_mi_event { +struct libnvme_mi_event { uint8_t aeoi; uint8_t aessi; uint32_t aeocidi; @@ -1381,7 +830,7 @@ struct nvme_mi_event { }; /** - * nvme_mi_aem_get_next_event() - Get details for the next event to parse + * libnvme_mi_aem_get_next_event() - Get details for the next event to parse * @ep: The endpoint with the event * * When inside a aem_handler, call this and a returned struct pointer @@ -1389,16 +838,16 @@ struct nvme_mi_event { * spec_info and vend_spec_info must be copied to persist as they will not be valid * after the handler_next_action has returned. * - * Return: Pointer no next nvme_mi_event or NULL if this is the last one + * Return: Pointer no next libnvme_mi_event or NULL if this is the last one */ -struct nvme_mi_event *nvme_mi_aem_get_next_event(nvme_mi_ep_t ep); +struct libnvme_mi_event *libnvme_mi_aem_get_next_event(libnvme_mi_ep_t ep); -struct nvme_mi_aem_enabled_map { +struct libnvme_mi_aem_enabled_map { bool enabled[256]; }; /** - * struct nvme_mi_aem_config - Provided for nvme_mi_aem_enable + * struct libnvme_mi_aem_config - Provided for libnvme_mi_aem_enable * @aem_handler: Callback function for application processing of events * @enabled_map: Map indicating which AE should be enabled on the endpoint * @envfa: Enable SR-IOV virtual functions AE @@ -1407,22 +856,22 @@ struct nvme_mi_aem_enabled_map { * @aemd: AEM Delay (time in seconds from when event happens to AEM being batched and sent) * @aerd: AEM Retry Delay (time in 100s of ms between AEM retries from the endpoint) * - * Application callbacks for nvme_mi_aem_process will be able to call - * nvme_mi_aem_get_next_event which will return a pointer to such an identifier + * Application callbacks for libnvme_mi_aem_process will be able to call + * libnvme_mi_aem_get_next_event which will return a pointer to such an identifier * for the next event the application should parse */ -struct nvme_mi_aem_config { +struct libnvme_mi_aem_config { /* - * This is called from inside nvme_mi_process when a payload has been validated and - * can be parsed. The application may call nvme_mi_aem_get_next_event from inside + * This is called from inside libnvme_mi_process when a payload has been validated and + * can be parsed. The application may call libnvme_mi_aem_get_next_event from inside * the callback to parse event data. */ - enum nvme_mi_aem_handler_next_action (*aem_handler)( - nvme_mi_ep_t ep, + enum libnvme_mi_aem_handler_next_action (*aem_handler)( + libnvme_mi_ep_t ep, size_t num_events, void *userdata); - struct nvme_mi_aem_enabled_map enabled_map; + struct libnvme_mi_aem_enabled_map enabled_map; bool envfa; bool empfa; @@ -1432,69 +881,69 @@ struct nvme_mi_aem_config { }; /** - * nvme_mi_aem_get_fd() - Returns the pollable fd for AEM data available + * libnvme_mi_aem_get_fd() - Returns the pollable fd for AEM data available * @ep: The endpoint being monitored for asynchronous data * * This populated structure can be polled from the application to understand if - * a call to nvme_mi_aem_process() is required (when a poll returns > 0). + * a call to libnvme_mi_aem_process() is required (when a poll returns > 0). * * Return: The fd value or -1 if error */ -int nvme_mi_aem_get_fd(nvme_mi_ep_t ep); +int libnvme_mi_aem_get_fd(libnvme_mi_ep_t ep); /** - * nvme_mi_aem_enable() - Enable AE on the provided endpoint + * libnvme_mi_aem_enable() - Enable AE on the provided endpoint * @ep: Endpoint to enable AEs * @config: AE configuraiton including which events are enabled and the callback function * @userdata: Application provided context pointer for callback function * * This function is called to enable AE on the endpoint. Endpoint will provide initial state * (if any) of enabled AEs and application can parse those via the aem_handler fn pointer in - * callbacks. Thes can be obtained in the callback by calling nvme_mi_aem_get_next_event(). + * callbacks. Thes can be obtained in the callback by calling libnvme_mi_aem_get_next_event(). * - * Application should poll the fd that can be obtained from nvme_mi_aem_get_fd and then call - * nvme_mi_aem_process() when poll() indicates data available. + * Application should poll the fd that can be obtained from libnvme_mi_aem_get_fd and then call + * libnvme_mi_aem_process() when poll() indicates data available. * - * A call to nvme_mi_aem_process() will grab AEM data and call the aem_handler fn pointer. - * At this point the application can call nvme_mi_aem_get_next_event() to get information for + * A call to libnvme_mi_aem_process() will grab AEM data and call the aem_handler fn pointer. + * At this point the application can call libnvme_mi_aem_get_next_event() to get information for * each triggered event. * * Return: 0 is a success, nonzero is an error and errno may be read for further details */ -int nvme_mi_aem_enable(nvme_mi_ep_t ep, - struct nvme_mi_aem_config *config, +int libnvme_mi_aem_enable(libnvme_mi_ep_t ep, + struct libnvme_mi_aem_config *config, void *userdata); /** - * nvme_mi_aem_get_enabled() - Return information on which AEs are enabled + * libnvme_mi_aem_get_enabled() - Return information on which AEs are enabled * @ep: Endpoint to check enabled status - * @enabled: nvme_mi_aem_enabled_map indexed by AE event ID of enabled state + * @enabled: libnvme_mi_aem_enabled_map indexed by AE event ID of enabled state * * Return: 0 is a success, nonzero is an error and errno may be read for further details */ -int nvme_mi_aem_get_enabled(nvme_mi_ep_t ep, - struct nvme_mi_aem_enabled_map *enabled); +int libnvme_mi_aem_get_enabled(libnvme_mi_ep_t ep, + struct libnvme_mi_aem_enabled_map *enabled); /** - * nvme_mi_aem_disable() - Disable AE on the provided endpoint + * libnvme_mi_aem_disable() - Disable AE on the provided endpoint * @ep: Endpoint to disable AEs * * Return: 0 is a success, nonzero is an error and errno may be read for further details */ -int nvme_mi_aem_disable(nvme_mi_ep_t ep); +int libnvme_mi_aem_disable(libnvme_mi_ep_t ep); /** - * nvme_mi_aem_process() - Process AEM on the provided endpoint + * libnvme_mi_aem_process() - Process AEM on the provided endpoint * @ep: Endpoint to process * @userdata: Application provided context pointer for callback function * - * Call this if poll() indicates data is available on the fd provided by nvme_mi_aem_get_fd() + * Call this if poll() indicates data is available on the fd provided by libnvme_mi_aem_get_fd() * - * This will call the fn pointer, aem_handler, provided with nvme_mi_aem_config and the - * application can call nvme_mi_aem_get_next_event() from within this callback to get + * This will call the fn pointer, aem_handler, provided with libnvme_mi_aem_config and the + * application can call libnvme_mi_aem_get_next_event() from within this callback to get * aem event data. The callback function should return NVME_MI_AEM_HNA_ACK for normal operation. * * Return: 0 is a success, nonzero is an error and errno may be read for further details */ -int nvme_mi_aem_process(nvme_mi_ep_t ep, void *userdata); +int libnvme_mi_aem_process(libnvme_mi_ep_t ep, void *userdata); diff --git a/libnvme/src/nvme/nbft.c b/libnvme/src/nvme/nbft.c index c2b96804c5..852d8c4db6 100644 --- a/libnvme/src/nvme/nbft.c +++ b/libnvme/src/nvme/nbft.c @@ -75,13 +75,13 @@ static char *trtype_to_string(__u8 transport_type) #define verify(ctx, condition, message) \ do { \ if (!(condition)) { \ - nvme_msg(ctx, LOG_DEBUG, "file %s: " message "\n", \ + libnvme_msg(ctx, LOG_DEBUG, "file %s: " message "\n", \ nbft->filename); \ return -EINVAL; \ } \ } while (0) -static int __get_heap_obj(struct nvme_global_ctx *ctx, +static int __get_heap_obj(struct libnvme_global_ctx *ctx, struct nbft_header *header, const char *filename, const char *descriptorname, const char *fieldname, struct nbft_heap_obj obj, bool is_string, @@ -91,7 +91,7 @@ static int __get_heap_obj(struct nvme_global_ctx *ctx, return -ENOENT; if (!in_heap(header, obj)) { - nvme_msg(ctx, LOG_DEBUG, + libnvme_msg(ctx, LOG_DEBUG, "file %s: field '%s' in descriptor '%s' has invalid offset or length\n", filename, fieldname, descriptorname); return -EINVAL; @@ -103,14 +103,14 @@ static int __get_heap_obj(struct nvme_global_ctx *ctx, if (is_string) { if (strnlen(*output, le16_to_cpu(obj.length) + 1) < le16_to_cpu(obj.length)) { - nvme_msg(ctx, LOG_DEBUG, + libnvme_msg(ctx, LOG_DEBUG, "file %s: string '%s' in descriptor '%s' is shorter (%zd) than specified length (%d)\n", filename, fieldname, descriptorname, strnlen(*output, le16_to_cpu(obj.length) + 1), le16_to_cpu(obj.length)); } else if (strnlen(*output, le16_to_cpu(obj.length) + 1) > le16_to_cpu(obj.length)) { - nvme_msg(ctx, LOG_DEBUG, + libnvme_msg(ctx, LOG_DEBUG, "file %s: string '%s' in descriptor '%s' is not zero terminated\n", filename, fieldname, descriptorname); return -EINVAL; @@ -161,7 +161,7 @@ static struct nbft_info_security *security_from_index(struct nbft_info *nbft, return NULL; } -static int read_ssns_exended_info(struct nvme_global_ctx *ctx, +static int read_ssns_exended_info(struct libnvme_global_ctx *ctx, struct nbft_info *nbft, struct nbft_info_subsystem_ns *ssns, struct nbft_ssns_ext_info *raw_ssns_ei) { @@ -186,7 +186,7 @@ static int read_ssns_exended_info(struct nvme_global_ctx *ctx, return 0; } -static int read_ssns(struct nvme_global_ctx *ctx, +static int read_ssns(struct libnvme_global_ctx *ctx, struct nbft_info *nbft, struct nbft_ssns *raw_ssns, struct nbft_info_subsystem_ns **s) { @@ -229,7 +229,7 @@ static int read_ssns(struct nvme_global_ctx *ctx, ssns->discovery = discovery_from_index(nbft, raw_ssns->primary_discovery_ctrl_index); if (!ssns->discovery) - nvme_msg(ctx, LOG_DEBUG, + libnvme_msg(ctx, LOG_DEBUG, "file %s: namespace %d discovery controller not found\n", nbft->filename, ssns->index); } @@ -266,7 +266,7 @@ static int read_ssns(struct nvme_global_ctx *ctx, ssns->security = security_from_index(nbft, raw_ssns->security_desc_index); if (!ssns->security) - nvme_msg(ctx, LOG_DEBUG, + libnvme_msg(ctx, LOG_DEBUG, "file %s: namespace %d security controller not found\n", nbft->filename, ssns->index); } @@ -286,7 +286,7 @@ static int read_ssns(struct nvme_global_ctx *ctx, } ssns->hfis[0] = hfi_from_index(nbft, raw_ssns->primary_hfi_desc_index); if (!ssns->hfis[0]) { - nvme_msg(ctx, LOG_DEBUG, + libnvme_msg(ctx, LOG_DEBUG, "file %s: SSNS %d: HFI %d not found\n", nbft->filename, ssns->index, raw_ssns->primary_hfi_desc_index); @@ -311,7 +311,7 @@ static int read_ssns(struct nvme_global_ctx *ctx, duplicate = true; if (duplicate) { - nvme_msg(ctx, LOG_DEBUG, + libnvme_msg(ctx, LOG_DEBUG, "file %s: SSNS %d skipping duplicate HFI index %d\n", nbft->filename, ssns->index, ss_hfi_indexes[i]); continue; @@ -319,7 +319,7 @@ static int read_ssns(struct nvme_global_ctx *ctx, ssns->hfis[i + 1] = hfi_from_index(nbft, ss_hfi_indexes[i]); if (ss_hfi_indexes[i] && !ssns->hfis[i + 1]) - nvme_msg(ctx, LOG_DEBUG, + libnvme_msg(ctx, LOG_DEBUG, "file %s: SSNS %d HFI %d not found\n", nbft->filename, ssns->index, ss_hfi_indexes[i]); else @@ -351,7 +351,7 @@ static int read_ssns(struct nvme_global_ctx *ctx, return ret; } -static int read_hfi_info_tcp(struct nvme_global_ctx *ctx, +static int read_hfi_info_tcp(struct libnvme_global_ctx *ctx, struct nbft_info *nbft, struct nbft_hfi_info_tcp *raw_hfi_info_tcp, struct nbft_info_hfi *hfi) @@ -366,7 +366,7 @@ static int read_hfi_info_tcp(struct nvme_global_ctx *ctx, verify(ctx, raw_hfi_info_tcp->version == 1, "invalid version in HFI transport descriptor"); if (le16_to_cpu(raw_hfi_info_tcp->hfi_index) != hfi->index) - nvme_msg(ctx, LOG_DEBUG, + libnvme_msg(ctx, LOG_DEBUG, "file %s: HFI descriptor index %d does not match index in HFI transport descriptor\n", nbft->filename, hfi->index); @@ -402,7 +402,7 @@ static int read_hfi_info_tcp(struct nvme_global_ctx *ctx, return 0; } -static int read_hfi(struct nvme_global_ctx *ctx, struct nbft_info *nbft, +static int read_hfi(struct libnvme_global_ctx *ctx, struct nbft_info *nbft, struct nbft_hfi *raw_hfi, struct nbft_info_hfi **h) { int ret; @@ -440,7 +440,7 @@ static int read_hfi(struct nvme_global_ctx *ctx, struct nbft_info *nbft, if (ret) goto fail; } else { - nvme_msg(ctx, LOG_DEBUG, + libnvme_msg(ctx, LOG_DEBUG, "file %s: invalid transport type %d\n", nbft->filename, raw_hfi->trtype); ret = -EINVAL; @@ -455,7 +455,7 @@ static int read_hfi(struct nvme_global_ctx *ctx, struct nbft_info *nbft, return ret; } -static int read_discovery(struct nvme_global_ctx *ctx, +static int read_discovery(struct libnvme_global_ctx *ctx, struct nbft_info *nbft, struct nbft_discovery *raw_discovery, struct nbft_info_discovery **d) @@ -488,14 +488,14 @@ static int read_discovery(struct nvme_global_ctx *ctx, discovery->hfi = hfi_from_index(nbft, raw_discovery->hfi_index); if (raw_discovery->hfi_index && !discovery->hfi) - nvme_msg(ctx, LOG_DEBUG, + libnvme_msg(ctx, LOG_DEBUG, "file %s: discovery %d HFI not found\n", nbft->filename, discovery->index); discovery->security = security_from_index(nbft, raw_discovery->sec_index); if (raw_discovery->sec_index && !discovery->security) - nvme_msg(ctx, LOG_DEBUG, + libnvme_msg(ctx, LOG_DEBUG, "file %s: discovery %d security descriptor not found\n", nbft->filename, discovery->index); @@ -508,14 +508,14 @@ static int read_discovery(struct nvme_global_ctx *ctx, return r; } -static int read_security(struct nvme_global_ctx *ctx, struct nbft_info *nbft, +static int read_security(struct libnvme_global_ctx *ctx, struct nbft_info *nbft, struct nbft_security *raw_security, struct nbft_info_security **s) { return -EINVAL; } -static void read_hfi_descriptors(struct nvme_global_ctx *ctx, +static void read_hfi_descriptors(struct libnvme_global_ctx *ctx, struct nbft_info *nbft, int num_hfi, struct nbft_hfi *raw_hfi_array, int hfi_len) { @@ -529,7 +529,7 @@ static void read_hfi_descriptors(struct nvme_global_ctx *ctx, } } -static void read_security_descriptors(struct nvme_global_ctx *ctx, +static void read_security_descriptors(struct libnvme_global_ctx *ctx, struct nbft_info *nbft, int num_sec, struct nbft_security *raw_sec_array, int sec_len) { @@ -544,7 +544,7 @@ static void read_security_descriptors(struct nvme_global_ctx *ctx, } } -static void read_discovery_descriptors(struct nvme_global_ctx *ctx, +static void read_discovery_descriptors(struct libnvme_global_ctx *ctx, struct nbft_info *nbft, int num_disc, struct nbft_discovery *raw_disc_array, int disc_len) { @@ -559,7 +559,7 @@ static void read_discovery_descriptors(struct nvme_global_ctx *ctx, } } -static void read_ssns_descriptors(struct nvme_global_ctx *ctx, +static void read_ssns_descriptors(struct libnvme_global_ctx *ctx, struct nbft_info *nbft, int num_ssns, struct nbft_ssns *raw_ssns_array, int ssns_len) { @@ -580,7 +580,7 @@ static void read_ssns_descriptors(struct nvme_global_ctx *ctx, * * Returns 0 on success, errno otherwise. */ -static int parse_raw_nbft(struct nvme_global_ctx *ctx, struct nbft_info *nbft) +static int parse_raw_nbft(struct libnvme_global_ctx *ctx, struct nbft_info *nbft) { __u8 *raw_nbft = nbft->raw_nbft; int raw_nbft_size = nbft->raw_nbft_size; @@ -712,7 +712,7 @@ static int parse_raw_nbft(struct nvme_global_ctx *ctx, struct nbft_info *nbft) return 0; } -__public void nvme_free_nbft(struct nvme_global_ctx *ctx, struct nbft_info *nbft) +__public void libnvme_free_nbft(struct libnvme_global_ctx *ctx, struct nbft_info *nbft) { struct nbft_info_hfi **hfi; struct nbft_info_security **sec; @@ -738,7 +738,7 @@ __public void nvme_free_nbft(struct nvme_global_ctx *ctx, struct nbft_info *nbft free(nbft); } -__public int nvme_read_nbft(struct nvme_global_ctx *ctx, struct nbft_info **nbft, +__public int libnvme_read_nbft(struct libnvme_global_ctx *ctx, struct nbft_info **nbft, const char *filename) { __u8 *raw_nbft = NULL; @@ -751,15 +751,15 @@ __public int nvme_read_nbft(struct nvme_global_ctx *ctx, struct nbft_info **nbft */ raw_nbft_fp = fopen(filename, "rb"); if (raw_nbft_fp == NULL) { - nvme_msg(ctx, LOG_ERR, "Failed to open %s: %s\n", - filename, nvme_strerror(errno)); + libnvme_msg(ctx, LOG_ERR, "Failed to open %s: %s\n", + filename, libnvme_strerror(errno)); return -EINVAL; } i = fseek(raw_nbft_fp, 0L, SEEK_END); if (i) { - nvme_msg(ctx, LOG_ERR, "Failed to read from %s: %s\n", - filename, nvme_strerror(errno)); + libnvme_msg(ctx, LOG_ERR, "Failed to read from %s: %s\n", + filename, libnvme_strerror(errno)); fclose(raw_nbft_fp); return -EINVAL; } @@ -769,7 +769,7 @@ __public int nvme_read_nbft(struct nvme_global_ctx *ctx, struct nbft_info **nbft raw_nbft = malloc(raw_nbft_size); if (!raw_nbft) { - nvme_msg(ctx, LOG_ERR, + libnvme_msg(ctx, LOG_ERR, "Failed to allocate memory for NBFT table"); fclose(raw_nbft_fp); return -ENOMEM; @@ -777,8 +777,8 @@ __public int nvme_read_nbft(struct nvme_global_ctx *ctx, struct nbft_info **nbft i = fread(raw_nbft, sizeof(*raw_nbft), raw_nbft_size, raw_nbft_fp); if (i != raw_nbft_size) { - nvme_msg(ctx, LOG_ERR, "Failed to read from %s: %s\n", - filename, nvme_strerror(errno)); + libnvme_msg(ctx, LOG_ERR, "Failed to read from %s: %s\n", + filename, libnvme_strerror(errno)); fclose(raw_nbft_fp); free(raw_nbft); return -EINVAL; @@ -791,7 +791,7 @@ __public int nvme_read_nbft(struct nvme_global_ctx *ctx, struct nbft_info **nbft */ *nbft = calloc(1, sizeof(struct nbft_info)); if (!*nbft) { - nvme_msg(ctx, LOG_ERR, "Could not allocate memory for NBFT\n"); + libnvme_msg(ctx, LOG_ERR, "Could not allocate memory for NBFT\n"); free(raw_nbft); return -ENOMEM; } @@ -801,8 +801,8 @@ __public int nvme_read_nbft(struct nvme_global_ctx *ctx, struct nbft_info **nbft (*nbft)->raw_nbft_size = raw_nbft_size; if (parse_raw_nbft(ctx, *nbft)) { - nvme_msg(ctx, LOG_ERR, "Failed to parse %s\n", filename); - nvme_free_nbft(ctx, *nbft); + libnvme_msg(ctx, LOG_ERR, "Failed to parse %s\n", filename); + libnvme_free_nbft(ctx, *nbft); return -EINVAL; } return 0; diff --git a/libnvme/src/nvme/nbft.h b/libnvme/src/nvme/nbft.h index 48d60ffb1b..f5e46d3bdd 100644 --- a/libnvme/src/nvme/nbft.h +++ b/libnvme/src/nvme/nbft.h @@ -1234,26 +1234,26 @@ struct nbft_info { }; /** - * nvme_read_nbft() - Read and parse contents of an ACPI NBFT table + * libnvme_read_nbft() - Read and parse contents of an ACPI NBFT table * - * @ctx: struct nvme_global_ctx object + * @ctx: struct libnvme_global_ctx object * @nbft: Parsed NBFT table data. * @filename: Filename of the raw NBFT table to read. * * Read and parse the specified NBFT file into a struct nbft_info. - * Free with nvme_free_nbft(). + * Free with libnvme_free_nbft(). * * Return: 0 on success, errno otherwise. */ -int nvme_read_nbft(struct nvme_global_ctx *ctx, struct nbft_info **nbft, +int libnvme_read_nbft(struct libnvme_global_ctx *ctx, struct nbft_info **nbft, const char *filename); /** - * nvme_free_nbft() - Free the struct nbft_info and its contents - * @ctx: struct nvme_global_ctx object + * libnvme_free_nbft() - Free the struct nbft_info and its contents + * @ctx: struct libnvme_global_ctx object * @nbft: Parsed NBFT table data. */ -void nvme_free_nbft(struct nvme_global_ctx *ctx, struct nbft_info *nbft); +void libnvme_free_nbft(struct libnvme_global_ctx *ctx, struct nbft_info *nbft); /** * struct nbft_file_entry - Linked list entry for NBFT files diff --git a/libnvme/src/nvme/no-json.c b/libnvme/src/nvme/no-json.c index 1060c071c1..8aeb217756 100644 --- a/libnvme/src/nvme/no-json.c +++ b/libnvme/src/nvme/no-json.c @@ -10,17 +10,17 @@ #include -int json_read_config(struct nvme_global_ctx *ctx, const char *config_file) +int json_read_config(struct libnvme_global_ctx *ctx, const char *config_file) { return -ENOTSUP; } -int json_update_config(struct nvme_global_ctx *ctx, int fd) +int json_update_config(struct libnvme_global_ctx *ctx, int fd) { return -ENOTSUP; } -int json_dump_tree(struct nvme_global_ctx *ctx) +int json_dump_tree(struct libnvme_global_ctx *ctx) { return -ENOTSUP; } diff --git a/libnvme/src/nvme/private.h b/libnvme/src/nvme/private.h index c3651fb958..b392c8ccd6 100644 --- a/libnvme/src/nvme/private.h +++ b/libnvme/src/nvme/private.h @@ -21,12 +21,12 @@ #include #include -const char *nvme_subsys_sysfs_dir(void); -const char *nvme_ctrl_sysfs_dir(void); -const char *nvme_ns_sysfs_dir(void); -const char *nvme_slots_sysfs_dir(void); -const char *nvme_uuid_ibm_filename(void); -const char *nvme_dmi_entries_dir(void); +const char *libnvme_subsys_sysfs_dir(void); +const char *libnvme_ctrl_sysfs_dir(void); +const char *libnvme_ns_sysfs_dir(void); +const char *libnvme_slots_sysfs_dir(void); +const char *libnvme_uuid_ibm_filename(void); +const char *libnvme_dmi_entries_dir(void); struct linux_passthru_cmd32 { __u8 opcode; @@ -71,47 +71,47 @@ struct linux_passthru_cmd64 { __u64 result; }; -#define NVME_IOCTL_ID _IO('N', 0x40) -#define NVME_IOCTL_RESET _IO('N', 0x44) -#define NVME_IOCTL_SUBSYS_RESET _IO('N', 0x45) -#define NVME_IOCTL_RESCAN _IO('N', 0x46) +#define LIBNVME_IOCTL_ID _IO('N', 0x40) +#define LIBNVME_IOCTL_RESET _IO('N', 0x44) +#define LIBNVME_IOCTL_SUBSYS_RESET _IO('N', 0x45) +#define LIBNVME_IOCTL_RESCAN _IO('N', 0x46) -#define NVME_IOCTL_ADMIN_CMD _IOWR('N', 0x41, struct linux_passthru_cmd32) -#define NVME_IOCTL_IO_CMD _IOWR('N', 0x43, struct linux_passthru_cmd32) -#define NVME_IOCTL_ADMIN64_CMD _IOWR('N', 0x47, struct linux_passthru_cmd64) -#define NVME_IOCTL_IO64_CMD _IOWR('N', 0x48, struct linux_passthru_cmd64) +#define LIBNVME_IOCTL_ADMIN_CMD _IOWR('N', 0x41, struct linux_passthru_cmd32) +#define LIBNVME_IOCTL_IO_CMD _IOWR('N', 0x43, struct linux_passthru_cmd32) +#define LIBNVME_IOCTL_ADMIN64_CMD _IOWR('N', 0x47, struct linux_passthru_cmd64) +#define LIBNVME_IOCTL_IO64_CMD _IOWR('N', 0x48, struct linux_passthru_cmd64) /* io_uring async commands: */ -#define NVME_URING_CMD_IO _IOWR('N', 0x80, struct nvme_uring_cmd) -#define NVME_URING_CMD_IO_VEC _IOWR('N', 0x81, struct nvme_uring_cmd) -#define NVME_URING_CMD_ADMIN _IOWR('N', 0x82, struct nvme_uring_cmd) -#define NVME_URING_CMD_ADMIN_VEC _IOWR('N', 0x83, struct nvme_uring_cmd) +#define LIBNVME_URING_CMD_IO _IOWR('N', 0x80, struct libnvme_uring_cmd) +#define LIBNVME_URING_CMD_IO_VEC _IOWR('N', 0x81, struct libnvme_uring_cmd) +#define LIBNVME_URING_CMD_ADMIN _IOWR('N', 0x82, struct libnvme_uring_cmd) +#define LIBNVME_URING_CMD_ADMIN_VEC _IOWR('N', 0x83, struct libnvme_uring_cmd) -struct nvme_log { +struct libnvme_log { int fd; int level; bool pid; bool timestamp; }; -enum nvme_transport_handle_type { - NVME_TRANSPORT_HANDLE_TYPE_UNKNOWN = 0, - NVME_TRANSPORT_HANDLE_TYPE_DIRECT, - NVME_TRANSPORT_HANDLE_TYPE_MI, +enum libnvme_transport_handle_type { + LIBNVME_TRANSPORT_HANDLE_TYPE_UNKNOWN = 0, + LIBNVME_TRANSPORT_HANDLE_TYPE_DIRECT, + LIBNVME_TRANSPORT_HANDLE_TYPE_MI, }; -struct nvme_transport_handle { - struct nvme_global_ctx *ctx; - enum nvme_transport_handle_type type; +struct libnvme_transport_handle { + struct libnvme_global_ctx *ctx; + enum libnvme_transport_handle_type type; char *name; - void *(*submit_entry)(struct nvme_transport_handle *hdl, - struct nvme_passthru_cmd *cmd); - void (*submit_exit)(struct nvme_transport_handle *hdl, - struct nvme_passthru_cmd *cmd, + void *(*submit_entry)(struct libnvme_transport_handle *hdl, + struct libnvme_passthru_cmd *cmd); + void (*submit_exit)(struct libnvme_transport_handle *hdl, + struct libnvme_passthru_cmd *cmd, int err, void *user_data); - bool (*decide_retry)(struct nvme_transport_handle *hdl, - struct nvme_passthru_cmd *cmd, int err); + bool (*decide_retry)(struct libnvme_transport_handle *hdl, + struct libnvme_passthru_cmd *cmd, int err); /* direct */ int fd; @@ -121,19 +121,19 @@ struct nvme_transport_handle { bool uring_enabled; /* mi */ - struct nvme_mi_ep *ep; + struct libnvme_mi_ep *ep; __u16 id; struct list_node ep_entry; - struct nvme_log *log; + struct libnvme_log *log; }; -struct nvme_path { /*!generate-accessors*/ +struct libnvme_path { /*!generate-accessors*/ struct list_node entry; struct list_node nentry; - struct nvme_ctrl *c; - struct nvme_ns *n; + struct libnvme_ctrl *c; + struct libnvme_ns *n; char *name; char *sysfs_dir; @@ -143,22 +143,22 @@ struct nvme_path { /*!generate-accessors*/ int queue_depth; //!accessors:none }; -struct nvme_ns_head { +struct libnvme_ns_head { struct list_head paths; - struct nvme_ns *n; + struct libnvme_ns *n; char *sysfs_dir; }; -struct nvme_ns { /*!generate-accessors*/ +struct libnvme_ns { /*!generate-accessors*/ struct list_node entry; - struct nvme_subsystem *s; - struct nvme_ctrl *c; - struct nvme_ns_head *head; + struct libnvme_subsystem *s; + struct libnvme_ctrl *c; + struct libnvme_ns_head *head; - struct nvme_global_ctx *ctx; - struct nvme_transport_handle *hdl; + struct libnvme_global_ctx *ctx; + struct libnvme_transport_handle *hdl; __u32 nsid; char *name; char *generic_name; //!accessors:none @@ -176,14 +176,14 @@ struct nvme_ns { /*!generate-accessors*/ enum nvme_csi csi; }; -struct nvme_ctrl { /*!generate-accessors*/ +struct libnvme_ctrl { /*!generate-accessors*/ struct list_node entry; struct list_head paths; struct list_head namespaces; - struct nvme_subsystem *s; + struct libnvme_subsystem *s; - struct nvme_global_ctx *ctx; - struct nvme_transport_handle *hdl; + struct libnvme_global_ctx *ctx; + struct libnvme_transport_handle *hdl; char *name; //!accessors:readonly char *sysfs_dir; //!accessors:readonly char *address; //!accessors:none @@ -213,14 +213,14 @@ struct nvme_ctrl { /*!generate-accessors*/ bool unique_discovery_ctrl; bool discovered; bool persistent; - struct nvme_fabrics_config cfg; + struct libnvme_fabrics_config cfg; }; -struct nvme_subsystem { /*!generate-accessors*/ +struct libnvme_subsystem { /*!generate-accessors*/ struct list_node entry; struct list_head ctrls; struct list_head namespaces; - struct nvme_host *h; + struct libnvme_host *h; char *name; /*!accessors:readonly*/ char *sysfs_dir; /*!accessors:readonly*/ @@ -233,10 +233,10 @@ struct nvme_subsystem { /*!generate-accessors*/ char *iopolicy; }; -struct nvme_host { /*!generate-accessors*/ +struct libnvme_host { /*!generate-accessors*/ struct list_node entry; struct list_head subsystems; - struct nvme_global_ctx *ctx; + struct libnvme_global_ctx *ctx; char *hostnqn; /*!accessors:readonly*/ char *hostid; /*!accessors:readonly*/ @@ -247,7 +247,7 @@ struct nvme_host { /*!generate-accessors*/ * value */ }; -struct nvme_fabric_options { /*!generate-accessors*/ +struct libnvme_fabric_options { /*!generate-accessors*/ bool cntlid; bool concat; bool ctrl_loss_tmo; @@ -280,26 +280,26 @@ struct nvme_fabric_options { /*!generate-accessors*/ bool trsvcid; }; -enum nvme_io_uring_state { - NVME_IO_URING_STATE_UNKNOWN = 0, - NVME_IO_URING_STATE_NOT_AVAILABLE, - NVME_IO_URING_STATE_AVAILABLE, +enum libnvme_io_uring_state { + LIBNVME_IO_URING_STATE_UNKNOWN = 0, + LIBNVME_IO_URING_STATE_NOT_AVAILABLE, + LIBNVME_IO_URING_STATE_AVAILABLE, }; -struct nvme_global_ctx { +struct libnvme_global_ctx { char *config_file; char *application; struct list_head endpoints; /* MI endpoints */ struct list_head hosts; - struct nvme_log log; + struct libnvme_log log; bool mi_probe_enabled; bool ioctl_probing; bool create_only; bool dry_run; - struct nvme_fabric_options *options; - struct ifaddrs *ifaddrs_cache; /* init with nvme_getifaddrs() */ + struct libnvme_fabric_options *options; + struct ifaddrs *ifaddrs_cache; /* init with libnvme_getifaddrs() */ - enum nvme_io_uring_state uring_state; + enum libnvme_io_uring_state uring_state; #ifdef CONFIG_LIBURING int ring_cmds; struct io_uring *ring; @@ -307,15 +307,15 @@ struct nvme_global_ctx { }; struct nvmf_context { - struct nvme_global_ctx *ctx; + struct libnvme_global_ctx *ctx; /* common callbacks */ bool (*decide_retry)(struct nvmf_context *fctx, int err, void *user_data); - void (*connected)(struct nvmf_context *fctx, struct nvme_ctrl *c, + void (*connected)(struct nvmf_context *fctx, struct libnvme_ctrl *c, void *user_data); void (*already_connected)(struct nvmf_context *fctx, - struct nvme_host *host, const char *subsysnqn, + struct libnvme_host *host, const char *subsysnqn, const char *transport, const char *traddr, const char *trsvcid, void *user_data); @@ -338,7 +338,7 @@ struct nvmf_context { /* common fabrics configuraiton */ const char *device; bool persistent; - struct nvme_fabrics_config *cfg; + struct libnvme_fabrics_config *cfg; /* connection configuration */ const char *subsysnqn; @@ -362,64 +362,68 @@ struct nvmf_context { void *user_data; }; -int nvme_set_attr(const char *dir, const char *attr, const char *value); +int libnvme_set_attr(const char *dir, const char *attr, const char *value); -int json_read_config(struct nvme_global_ctx *ctx, const char *config_file); +int json_read_config(struct libnvme_global_ctx *ctx, const char *config_file); -int json_update_config(struct nvme_global_ctx *ctx, int fd); +int json_update_config(struct libnvme_global_ctx *ctx, int fd); -int json_dump_tree(struct nvme_global_ctx *ctx); +int json_dump_tree(struct libnvme_global_ctx *ctx); -void *__nvme_submit_entry(struct nvme_transport_handle *hdl, - struct nvme_passthru_cmd *cmd); -void __nvme_submit_exit(struct nvme_transport_handle *hdl, - struct nvme_passthru_cmd *cmd, int err, void *user_data); -bool __nvme_decide_retry(struct nvme_transport_handle *hdl, - struct nvme_passthru_cmd *cmd, int err); +void *__libnvme_submit_entry(struct libnvme_transport_handle *hdl, + struct libnvme_passthru_cmd *cmd); +void __libnvme_submit_exit(struct libnvme_transport_handle *hdl, + struct libnvme_passthru_cmd *cmd, int err, void *user_data); +bool __libnvme_decide_retry(struct libnvme_transport_handle *hdl, + struct libnvme_passthru_cmd *cmd, int err); -struct nvme_transport_handle *__nvme_open(struct nvme_global_ctx *ctx, const char *name); -struct nvme_transport_handle *__nvme_create_transport_handle(struct nvme_global_ctx *ctx); -int __nvme_transport_handle_open_mi(struct nvme_transport_handle *hdl, const char *devname); -int __nvme_transport_handle_init_mi(struct nvme_transport_handle *hdl); -void __nvme_transport_handle_close_mi(struct nvme_transport_handle *hdl); +struct libnvme_transport_handle *__libnvme_open(struct libnvme_global_ctx *ctx, + const char *name); +struct libnvme_transport_handle *__libnvme_create_transport_handle( + struct libnvme_global_ctx *ctx); +int __libnvme_transport_handle_open_mi(struct libnvme_transport_handle *hdl, + const char *devname); +int __libnvme_transport_handle_init_mi(struct libnvme_transport_handle *hdl); +void __libnvme_transport_handle_close_mi(struct libnvme_transport_handle *hdl); -int _nvme_create_ctrl(struct nvme_global_ctx *ctx, - struct nvmf_context *fctx, - nvme_ctrl_t *cp); -bool _nvme_ctrl_match_config(struct nvme_ctrl *c, struct nvmf_context *fctx); +int _libnvme_create_ctrl(struct libnvme_global_ctx *ctx, + struct nvmf_context *fctx, + libnvme_ctrl_t *cp); +bool _libnvme_ctrl_match_config(struct libnvme_ctrl *c, + struct nvmf_context *fctx); -void *__nvme_alloc(size_t len); +void *__libnvme_alloc(size_t len); -void *__nvme_realloc(void *p, size_t len); +void *__libnvme_realloc(void *p, size_t len); -nvme_host_t nvme_lookup_host(struct nvme_global_ctx *ctx, const char *hostnqn, - const char *hostid); -nvme_subsystem_t nvme_lookup_subsystem(struct nvme_host *h, - const char *name, - const char *subsysnqn); -nvme_ctrl_t nvme_lookup_ctrl(nvme_subsystem_t s, - struct nvmf_context *fctx, - nvme_ctrl_t p); -nvme_ctrl_t nvme_ctrl_find(nvme_subsystem_t s, struct nvmf_context *fctx); +libnvme_host_t libnvme_lookup_host(struct libnvme_global_ctx *ctx, + const char *hostnqn, const char *hostid); +libnvme_subsystem_t libnvme_lookup_subsystem(struct libnvme_host *h, + const char *name, const char *subsysnqn); +libnvme_ctrl_t libnvme_lookup_ctrl(libnvme_subsystem_t s, + struct nvmf_context *fctx, libnvme_ctrl_t p); +libnvme_ctrl_t libnvme_ctrl_find(libnvme_subsystem_t s, + struct nvmf_context *fctx); -void __nvme_free_host(nvme_host_t h); +void __libnvme_free_host(libnvme_host_t h); #if (LOG_FUNCNAME == 1) -#define __nvme_log_func __func__ +#define __libnvme_log_func __func__ #else -#define __nvme_log_func NULL +#define __libnvme_log_func NULL #endif void __attribute__((format(printf, 4, 5))) -__nvme_msg(struct nvme_global_ctx *ctx, int level, const char *func, const char *format, ...); +__libnvme_msg(struct libnvme_global_ctx *ctx, int level, + const char *func, const char *format, ...); -#define nvme_msg(ctx, level, format, ...) \ - __nvme_msg(ctx, level, __nvme_log_func, format, ##__VA_ARGS__) +#define libnvme_msg(ctx, level, format, ...) \ + __libnvme_msg(ctx, level, __libnvme_log_func, format, ##__VA_ARGS__) /* mi internal headers */ /* internal transport API */ -struct nvme_mi_req { +struct libnvme_mi_req { struct nvme_mi_msg_hdr *hdr; size_t hdr_len; void *data; @@ -427,7 +431,7 @@ struct nvme_mi_req { __u32 mic; }; -struct nvme_mi_resp { +struct libnvme_mi_resp { struct nvme_mi_msg_hdr *hdr; size_t hdr_len; void *data; @@ -435,30 +439,30 @@ struct nvme_mi_resp { __u32 mic; }; -struct nvme_mi_ep; -struct nvme_mi_transport { +struct libnvme_mi_ep; +struct libnvme_mi_transport { const char *name; bool mic_enabled; - int (*submit)(struct nvme_mi_ep *ep, - struct nvme_mi_req *req, - struct nvme_mi_resp *resp); - void (*close)(struct nvme_mi_ep *ep); - int (*desc_ep)(struct nvme_mi_ep *ep, char *buf, size_t len); - int (*check_timeout)(struct nvme_mi_ep *ep, unsigned int timeout); - int (*aem_fd)(struct nvme_mi_ep *ep); - int (*aem_read)(struct nvme_mi_ep *ep, - struct nvme_mi_resp *resp); - int (*aem_purge)(struct nvme_mi_ep *ep); + int (*submit)(struct libnvme_mi_ep *ep, + struct libnvme_mi_req *req, + struct libnvme_mi_resp *resp); + void (*close)(struct libnvme_mi_ep *ep); + int (*desc_ep)(struct libnvme_mi_ep *ep, char *buf, size_t len); + int (*check_timeout)(struct libnvme_mi_ep *ep, unsigned int timeout); + int (*aem_fd)(struct libnvme_mi_ep *ep); + int (*aem_read)(struct libnvme_mi_ep *ep, + struct libnvme_mi_resp *resp); + int (*aem_purge)(struct libnvme_mi_ep *ep); }; -struct nvme_mi_aem_ctx { +struct libnvme_mi_aem_ctx { struct nvme_mi_aem_occ_list_hdr *occ_header; struct nvme_mi_aem_occ_data *list_start; struct nvme_mi_aem_occ_data *list_current; int list_current_index; - struct nvme_mi_aem_config callbacks; + struct libnvme_mi_aem_config callbacks; int last_generation_num; - struct nvme_mi_event event; + struct libnvme_mi_event event; }; /* quirks */ @@ -467,16 +471,16 @@ struct nvme_mi_aem_ctx { * sending the next request. Some devices may ignore new commands sent too soon * after the previous request, so manually insert a delay */ -#define NVME_QUIRK_MIN_INTER_COMMAND_TIME (1 << 0) +#define LIBNVME_QUIRK_MIN_INTER_COMMAND_TIME (1 << 0) /* Some devices may not support using CSI 1. Attempting to set an * endpoint to use this with these devices should return an error */ -#define NVME_QUIRK_CSI_1_NOT_SUPPORTED (1 << 1) +#define LIBNVME_QUIRK_CSI_1_NOT_SUPPORTED (1 << 1) -struct nvme_mi_ep { - struct nvme_global_ctx *ctx; - const struct nvme_mi_transport *transport; +struct libnvme_mi_ep { + struct libnvme_global_ctx *ctx; + const struct libnvme_mi_transport *transport; void *transport_data; struct list_node root_entry; struct list_head controllers; @@ -488,19 +492,19 @@ struct nvme_mi_ep { __u8 csi; - /* inter-command delay, for NVME_QUIRK_MIN_INTER_COMMAND_TIME */ + /* inter-command delay, for LIBNVME_QUIRK_MIN_INTER_COMMAND_TIME */ unsigned int inter_command_us; struct timespec last_resp_time; bool last_resp_time_valid; - struct nvme_mi_aem_ctx *aem_ctx; + struct libnvme_mi_aem_ctx *aem_ctx; }; -struct nvme_mi_ep *nvme_mi_init_ep(struct nvme_global_ctx *ctx); -void nvme_mi_ep_probe(struct nvme_mi_ep *ep); +struct libnvme_mi_ep *libnvme_mi_init_ep(struct libnvme_global_ctx *ctx); +void libnvme_mi_ep_probe(struct libnvme_mi_ep *ep); /* for tests, we need to calculate the correct MICs */ -__u32 nvme_mi_crc32_update(__u32 crc, void *data, size_t len); +__u32 libnvme_mi_crc32_update(__u32 crc, void *data, size_t len); /* we have a facility to mock MCTP socket operations in the mi-mctp transport, * using this ops type. This should only be used for test, and isn't exposed @@ -514,12 +518,12 @@ struct __mi_mctp_socket_ops { int (*poll)(struct pollfd *, nfds_t, int); int (*ioctl_tag)(int, unsigned long, struct mctp_ioc_tag_ctl *); }; -void __nvme_mi_mctp_set_ops(const struct __mi_mctp_socket_ops *newops); +void __libnvme_mi_mctp_set_ops(const struct __mi_mctp_socket_ops *newops); #define SECTOR_SIZE 512 #define SECTOR_SHIFT 9 -int __nvme_import_keys_from_config(nvme_host_t h, nvme_ctrl_t c, +int __libnvme_import_keys_from_config(libnvme_host_t h, libnvme_ctrl_t c, long *keyring_id, long *key_id); static inline char *xstrdup(const char *s) @@ -530,7 +534,7 @@ static inline char *xstrdup(const char *s) } /** - * nvme_getifaddrs - Cached wrapper around getifaddrs() + * libnvme_getifaddrs - Cached wrapper around getifaddrs() * @ctx: pointer to the global context * * On the first call, this function invokes the POSIX getifaddrs() @@ -541,19 +545,19 @@ static inline char *xstrdup(const char *s) * * Return: Pointer to I/F data, NULL on error (with errno set). */ -const struct ifaddrs *nvme_getifaddrs(struct nvme_global_ctx *ctx); +const struct ifaddrs *libnvme_getifaddrs(struct libnvme_global_ctx *ctx); /** - * nvme_ipaddrs_eq - Check if 2 IP addresses are equal. + * libnvme_ipaddrs_eq - Check if 2 IP addresses are equal. * @addr1: IP address (can be IPv4 or IPv6) * @addr2: IP address (can be IPv4 or IPv6) * * Return: true if addr1 == addr2. false otherwise. */ -bool nvme_ipaddrs_eq(const char *addr1, const char *addr2); +bool libnvme_ipaddrs_eq(const char *addr1, const char *addr2); /** - * nvme_iface_matching_addr - Get interface matching @addr + * libnvme_iface_matching_addr - Get interface matching @addr * @iface_list: Interface list returned by getifaddrs() * @addr: Address to match * @@ -563,11 +567,11 @@ bool nvme_ipaddrs_eq(const char *addr1, const char *addr2); * * Return: The name of the interface that owns @addr or NULL. */ -const char *nvme_iface_matching_addr(const struct ifaddrs *iface_list, +const char *libnvme_iface_matching_addr(const struct ifaddrs *iface_list, const char *addr); /** - * nvme_iface_primary_addr_matches - Check that interface's primary + * libnvme_iface_primary_addr_matches - Check that interface's primary * address matches * @iface_list: Interface list returned by getifaddrs() * @iface: Interface to match @@ -579,10 +583,10 @@ const char *nvme_iface_matching_addr(const struct ifaddrs *iface_list, * * Return: true if a match is found, false otherwise. */ -bool nvme_iface_primary_addr_matches(const struct ifaddrs *iface_list, +bool libnvme_iface_primary_addr_matches(const struct ifaddrs *iface_list, const char *iface, const char *addr); -int hostname2traddr(struct nvme_global_ctx *ctx, const char *traddr, +int hostname2traddr(struct libnvme_global_ctx *ctx, const char *traddr, char **hostname); /** @@ -697,7 +701,7 @@ static inline __u16 nvmf_exat_size(size_t val_len) } /** - * nvme_ns_get_transport_handle() - Get associated transport handle + * libnvme_ns_get_transport_handle() - Get associated transport handle * @n: Namespace instance * @hdl: Transport handle * @@ -706,22 +710,22 @@ static inline __u16 nvmf_exat_size(size_t val_len) * 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_transport_handle() is called. + * libnvme_ns_release_transport_handle() is called. * * Return: On success 0, else error code. */ -int nvme_ns_get_transport_handle(nvme_ns_t n, - struct nvme_transport_handle **hdl); +int libnvme_ns_get_transport_handle(libnvme_ns_t n, + struct libnvme_transport_handle **hdl); /** - * nvme_ns_release_transport_handle() - Free transport handle from ns object + * libnvme_ns_release_transport_handle() - Free transport handle from ns object * @n: Namespace instance * */ -void nvme_ns_release_transport_handle(nvme_ns_t n); +void libnvme_ns_release_transport_handle(libnvme_ns_t n); /** - * nvme_mi_admin_admin_passthru() - Submit an nvme admin passthrough command + * libnvme_mi_admin_admin_passthru() - Submit an nvme admin passthrough command * @hdl: Transport handle to send command to * @cmd: The nvme admin command to send * @@ -736,40 +740,40 @@ void nvme_ns_release_transport_handle(nvme_ns_t n); * 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(struct nvme_transport_handle *hdl, - struct nvme_passthru_cmd *cmd); +int libnvme_mi_admin_admin_passthru(struct libnvme_transport_handle *hdl, + struct libnvme_passthru_cmd *cmd); #ifdef CONFIG_LIBURING -int nvme_open_uring(struct nvme_global_ctx *ctx); -void nvme_close_uring(struct nvme_global_ctx *ctx); -int __nvme_transport_handle_open_uring(struct nvme_transport_handle *hdl); -int nvme_submit_admin_passthru_async(struct nvme_transport_handle *hdl, - struct nvme_passthru_cmd *cmd); -int nvme_wait_complete_passthru(struct nvme_transport_handle *hdl); +int libnvme_open_uring(struct libnvme_global_ctx *ctx); +void libnvme_close_uring(struct libnvme_global_ctx *ctx); +int __libnvme_transport_handle_open_uring(struct libnvme_transport_handle *hdl); +int libnvme_submit_admin_passthru_async(struct libnvme_transport_handle *hdl, + struct libnvme_passthru_cmd *cmd); +int libnvme_wait_complete_passthru(struct libnvme_transport_handle *hdl); #else static inline int -nvme_open_uring(struct nvme_global_ctx *ctx) +libnvme_open_uring(struct libnvme_global_ctx *ctx) { return -ENOTSUP; } static inline void -nvme_close_uring(struct nvme_global_ctx *ctx) +libnvme_close_uring(struct libnvme_global_ctx *ctx) { } static inline int -__nvme_transport_handle_open_uring(struct nvme_transport_handle *hdl) +__libnvme_transport_handle_open_uring(struct libnvme_transport_handle *hdl) { - hdl->ctx->uring_state = NVME_IO_URING_STATE_NOT_AVAILABLE; + hdl->ctx->uring_state = LIBNVME_IO_URING_STATE_NOT_AVAILABLE; return -ENOTSUP; } static inline int -nvme_submit_admin_passthru_async(struct nvme_transport_handle *hdl, - struct nvme_passthru_cmd *cmd) +libnvme_submit_admin_passthru_async(struct libnvme_transport_handle *hdl, + struct libnvme_passthru_cmd *cmd) { return -ENOTSUP; } static inline int -nvme_wait_complete_passthru(struct nvme_transport_handle *hdl) +libnvme_wait_complete_passthru(struct libnvme_transport_handle *hdl) { return -ENOTSUP; } diff --git a/libnvme/src/nvme/sysfs.c b/libnvme/src/nvme/sysfs.c index ea4f0e20c3..c3b9686d3c 100644 --- a/libnvme/src/nvme/sysfs.c +++ b/libnvme/src/nvme/sysfs.c @@ -25,7 +25,7 @@ static const char *make_sysfs_dir(const char *path) return str; } -const char *nvme_subsys_sysfs_dir(void) +const char *libnvme_subsys_sysfs_dir(void) { static const char *str; @@ -35,7 +35,7 @@ const char *nvme_subsys_sysfs_dir(void) return str = make_sysfs_dir(PATH_SYSFS_NVME_SUBSYSTEM); } -const char *nvme_ctrl_sysfs_dir(void) +const char *libnvme_ctrl_sysfs_dir(void) { static const char *str; @@ -45,7 +45,7 @@ const char *nvme_ctrl_sysfs_dir(void) return str = make_sysfs_dir(PATH_SYSFS_NVME); } -const char *nvme_ns_sysfs_dir(void) +const char *libnvme_ns_sysfs_dir(void) { static const char *str; @@ -55,7 +55,7 @@ const char *nvme_ns_sysfs_dir(void) return str = make_sysfs_dir(PATH_SYSFS_BLOCK); } -const char *nvme_slots_sysfs_dir(void) +const char *libnvme_slots_sysfs_dir(void) { static const char *str; @@ -65,7 +65,7 @@ const char *nvme_slots_sysfs_dir(void) return str = make_sysfs_dir(PATH_SYSFS_SLOTS); } -const char *nvme_uuid_ibm_filename(void) +const char *libnvme_uuid_ibm_filename(void) { static const char *str; @@ -75,7 +75,7 @@ const char *nvme_uuid_ibm_filename(void) return str = make_sysfs_dir(PATH_UUID_IBM); } -const char *nvme_dmi_entries_dir(void) +const char *libnvme_dmi_entries_dir(void) { static const char *str; diff --git a/libnvme/src/nvme/tree.c b/libnvme/src/nvme/tree.c index 377f6e8ead..81686d1a00 100644 --- a/libnvme/src/nvme/tree.c +++ b/libnvme/src/nvme/tree.c @@ -55,16 +55,19 @@ struct candidate_args { bool (*addreq)(const char *, const char *); bool well_known_nqn; }; -typedef bool (*ctrl_match_t)(struct nvme_ctrl *c, struct candidate_args *candidate); - -static void __nvme_free_ctrl(nvme_ctrl_t c); -static int nvme_subsystem_scan_namespace(struct nvme_global_ctx *ctx, - struct nvme_subsystem *s, char *name); -static int nvme_init_subsystem(nvme_subsystem_t s, const char *name); -static int nvme_scan_subsystem(struct nvme_global_ctx *ctx, const char *name); -static int nvme_ctrl_scan_namespace(struct nvme_global_ctx *ctx, struct nvme_ctrl *c, - char *name); -static int nvme_ctrl_scan_path(struct nvme_global_ctx *ctx, struct nvme_ctrl *c, char *name); +typedef bool (*ctrl_match_t)(struct libnvme_ctrl *c, + struct candidate_args *candidate); + +static void __libnvme_free_ctrl(libnvme_ctrl_t c); +static int libnvme_subsystem_scan_namespace(struct libnvme_global_ctx *ctx, + struct libnvme_subsystem *s, char *name); +static int libnvme_init_subsystem(libnvme_subsystem_t s, const char *name); +static int libnvme_scan_subsystem(struct libnvme_global_ctx *ctx, + const char *name); +static int libnvme_ctrl_scan_namespace(struct libnvme_global_ctx *ctx, + struct libnvme_ctrl *c, char *name); +static int libnvme_ctrl_scan_path(struct libnvme_global_ctx *ctx, + struct libnvme_ctrl *c, char *name); /** * Compare two C strings and handle NULL pointers gracefully. @@ -119,14 +122,14 @@ static char *nvme_hostid_from_hostnqn(const char *hostnqn) return strdup(uuid + strlen("uuid:")); } -__public int nvme_host_get_ids(struct nvme_global_ctx *ctx, +__public int libnvme_host_get_ids(struct libnvme_global_ctx *ctx, const char *hostnqn_arg, const char *hostid_arg, char **hostnqn, char **hostid) { _cleanup_free_ char *nqn = NULL; _cleanup_free_ char *hid = NULL; _cleanup_free_ char *hnqn = NULL; - nvme_host_t h; + libnvme_host_t h; /* command line argumments */ if (hostid_arg) @@ -135,19 +138,19 @@ __public int nvme_host_get_ids(struct nvme_global_ctx *ctx, hnqn = strdup(hostnqn_arg); /* JSON config: assume the first entry is the default host */ - h = nvme_first_host(ctx); + h = libnvme_first_host(ctx); if (h) { if (!hid) - hid = xstrdup(nvme_host_get_hostid(h)); + hid = xstrdup(libnvme_host_get_hostid(h)); if (!hnqn) - hnqn = xstrdup(nvme_host_get_hostnqn(h)); + hnqn = xstrdup(libnvme_host_get_hostnqn(h)); } /* /etc/nvme/hostid and/or /etc/nvme/hostnqn */ if (!hid) - hid = nvme_read_hostid(); + hid = libnvme_read_hostid(); if (!hnqn) - hnqn = nvme_read_hostnqn(); + hnqn = libnvme_read_hostnqn(); /* incomplete configuration, thus derive hostid from hostnqn */ if (!hid && hnqn) @@ -158,17 +161,17 @@ __public int nvme_host_get_ids(struct nvme_global_ctx *ctx, * fails generate one */ if (!hid) { - hid = nvme_generate_hostid(); + hid = libnvme_generate_hostid(); if (!hid) return -ENOMEM; - nvme_msg(ctx, LOG_DEBUG, + libnvme_msg(ctx, LOG_DEBUG, "warning: using auto generated hostid and hostnqn\n"); } /* incomplete configuration, thus derive hostnqn from hostid */ if (!hnqn) { - hnqn = nvme_generate_hostnqn_from_hostid(hid); + hnqn = libnvme_generate_hostnqn_from_hostid(hid); if (!hnqn) return -ENOMEM; } @@ -176,7 +179,7 @@ __public int nvme_host_get_ids(struct nvme_global_ctx *ctx, /* sanity checks */ nqn = nvme_hostid_from_hostnqn(hnqn); if (nqn && strcmp(nqn, hid)) { - nvme_msg(ctx, LOG_DEBUG, + libnvme_msg(ctx, LOG_DEBUG, "warning: use hostid '%s' which does not match uuid in hostnqn '%s'\n", hid, hnqn); } @@ -189,91 +192,93 @@ __public int nvme_host_get_ids(struct nvme_global_ctx *ctx, return 0; } -__public int nvme_get_host(struct nvme_global_ctx *ctx, const char *hostnqn, - const char *hostid, nvme_host_t *host) +__public int libnvme_get_host(struct libnvme_global_ctx *ctx, const char *hostnqn, + const char *hostid, libnvme_host_t *host) { _cleanup_free_ char *hnqn = NULL; _cleanup_free_ char *hid = NULL; - struct nvme_host *h; + struct libnvme_host *h; int err; - err = nvme_host_get_ids(ctx, hostnqn, hostid, &hnqn, &hid); + err = libnvme_host_get_ids(ctx, hostnqn, hostid, &hnqn, &hid); if (err) return err; - h = nvme_lookup_host(ctx, hnqn, hid); + h = libnvme_lookup_host(ctx, hnqn, hid); if (!h) return -ENOMEM; - nvme_host_set_hostsymname(h, NULL); + libnvme_host_set_hostsymname(h, NULL); *host = h; return 0; } -static void nvme_filter_subsystem(struct nvme_global_ctx *ctx, nvme_subsystem_t s, - nvme_scan_filter_t f, void *f_args) +static void libnvme_filter_subsystem(struct libnvme_global_ctx *ctx, + libnvme_subsystem_t s, libnvme_scan_filter_t f, void *f_args) { if (f(s, NULL, NULL, f_args)) return; - nvme_msg(ctx, LOG_DEBUG, "filter out subsystem %s\n", - nvme_subsystem_get_name(s)); - nvme_free_subsystem(s); + libnvme_msg(ctx, LOG_DEBUG, "filter out subsystem %s\n", + libnvme_subsystem_get_name(s)); + libnvme_free_subsystem(s); } -static void nvme_filter_ns(struct nvme_global_ctx *ctx, nvme_ns_t n, - nvme_scan_filter_t f, void *f_args) +static void libnvme_filter_ns(struct libnvme_global_ctx *ctx, libnvme_ns_t n, + libnvme_scan_filter_t f, void *f_args) { if (f(NULL, NULL, n, f_args)) return; - nvme_msg(ctx, LOG_DEBUG, "filter out namespace %s\n", - nvme_ns_get_name(n)); - nvme_free_ns(n); + libnvme_msg(ctx, LOG_DEBUG, "filter out namespace %s\n", + libnvme_ns_get_name(n)); + libnvme_free_ns(n); } -static void nvme_filter_ctrl(struct nvme_global_ctx *ctx, nvme_ctrl_t c, - nvme_scan_filter_t f, void *f_args) +static void libnvme_filter_ctrl(struct libnvme_global_ctx *ctx, + libnvme_ctrl_t c, libnvme_scan_filter_t f, void *f_args) { if (f(NULL, c, NULL, f_args)) return; - nvme_msg(ctx, LOG_DEBUG, "filter out controller %s\n", - nvme_ctrl_get_name(c)); - nvme_free_ctrl(c); + libnvme_msg(ctx, LOG_DEBUG, "filter out controller %s\n", + libnvme_ctrl_get_name(c)); + libnvme_free_ctrl(c); } -static void nvme_filter_tree(struct nvme_global_ctx *ctx, nvme_scan_filter_t f, void *f_args) +static void libnvme_filter_tree(struct libnvme_global_ctx *ctx, + libnvme_scan_filter_t f, void *f_args) { - nvme_host_t h, _h; - nvme_subsystem_t s, _s; - nvme_ns_t n, _n; - nvme_path_t p, _p; - nvme_ctrl_t c, _c; + libnvme_host_t h, _h; + libnvme_subsystem_t s, _s; + libnvme_ns_t n, _n; + libnvme_path_t p, _p; + libnvme_ctrl_t c, _c; if (!f) return; - nvme_for_each_host_safe(ctx, h, _h) { - nvme_for_each_subsystem_safe(h, s, _s) { - nvme_subsystem_for_each_ctrl_safe(s, c, _c) - nvme_filter_ctrl(ctx, c, f, f_args); + libnvme_for_each_host_safe(ctx, h, _h) { + libnvme_for_each_subsystem_safe(h, s, _s) { + libnvme_subsystem_for_each_ctrl_safe(s, c, _c) + libnvme_filter_ctrl(ctx, c, f, f_args); - nvme_subsystem_for_each_ns_safe(s, n, _n) { - nvme_namespace_for_each_path_safe(n, p, _p) { - nvme_filter_ctrl(ctx, nvme_path_get_ctrl(p), + libnvme_subsystem_for_each_ns_safe(s, n, _n) { + libnvme_namespace_for_each_path_safe(n, p, _p) { + libnvme_filter_ctrl(ctx, libnvme_path_get_ctrl(p), f, f_args); } - nvme_filter_ns(ctx, n, f, f_args); + libnvme_filter_ns(ctx, n, f, f_args); } - nvme_filter_subsystem(ctx, s, f, f_args); + libnvme_filter_subsystem(ctx, s, f, f_args); } } } -__public int nvme_scan_topology(struct nvme_global_ctx *ctx, nvme_scan_filter_t f, void *f_args) +__public int libnvme_scan_topology(struct libnvme_global_ctx *ctx, + libnvme_scan_filter_t f, void *f_args) { _cleanup_dirents_ struct dirents subsys = {}, ctrls = {}; int i, ret; @@ -281,37 +286,39 @@ __public int nvme_scan_topology(struct nvme_global_ctx *ctx, nvme_scan_filter_t if (!ctx) return 0; - ctrls.num = nvme_scan_ctrls(&ctrls.ents); + ctrls.num = libnvme_scan_ctrls(&ctrls.ents); if (ctrls.num < 0) { - nvme_msg(ctx, LOG_DEBUG, "failed to scan ctrls: %s\n", - nvme_strerror(-ctrls.num)); + libnvme_msg(ctx, LOG_DEBUG, "failed to scan ctrls: %s\n", + libnvme_strerror(-ctrls.num)); return ctrls.num; } for (i = 0; i < ctrls.num; i++) { - nvme_ctrl_t c; + libnvme_ctrl_t c; - ret = nvme_scan_ctrl(ctx, ctrls.ents[i]->d_name, &c); + ret = libnvme_scan_ctrl(ctx, ctrls.ents[i]->d_name, &c); if (ret < 0) { - nvme_msg(ctx, LOG_DEBUG, "failed to scan ctrl %s: %s\n", - ctrls.ents[i]->d_name, nvme_strerror(-ret)); + libnvme_msg(ctx, LOG_DEBUG, + "failed to scan ctrl %s: %s\n", + ctrls.ents[i]->d_name, libnvme_strerror(-ret)); continue; } } - subsys.num = nvme_scan_subsystems(&subsys.ents); + subsys.num = libnvme_scan_subsystems(&subsys.ents); if (subsys.num < 0) { - nvme_msg(ctx, LOG_DEBUG, "failed to scan subsystems: %s\n", - nvme_strerror(-subsys.num)); + libnvme_msg(ctx, LOG_DEBUG, "failed to scan subsystems: %s\n", + libnvme_strerror(-subsys.num)); return subsys.num; } for (i = 0; i < subsys.num; i++) { - ret = nvme_scan_subsystem(ctx, subsys.ents[i]->d_name); + ret = libnvme_scan_subsystem(ctx, subsys.ents[i]->d_name); if (ret < 0) { - nvme_msg(ctx, LOG_DEBUG, - "failed to scan subsystem %s: %s\n", - subsys.ents[i]->d_name, nvme_strerror(-ret)); + libnvme_msg(ctx, LOG_DEBUG, + "failed to scan subsystem %s: %s\n", + subsys.ents[i]->d_name, + libnvme_strerror(-ret)); } } @@ -319,20 +326,21 @@ __public int nvme_scan_topology(struct nvme_global_ctx *ctx, nvme_scan_filter_t * Filter the tree after it has been fully populated and * updated */ - nvme_filter_tree(ctx, f, f_args); + libnvme_filter_tree(ctx, f, f_args); return 0; } -__public int nvme_read_config(struct nvme_global_ctx *ctx, const char *config_file) +__public int libnvme_read_config(struct libnvme_global_ctx *ctx, + const char *config_file) { int err; - if (!ctx || !config_file) + if (!ctx || !config_file) return -ENODEV; ctx->config_file = strdup(config_file); - if (!ctx->config_file) + if (!ctx->config_file) return -ENOMEM; err = json_read_config(ctx, config_file); @@ -346,22 +354,23 @@ __public int nvme_read_config(struct nvme_global_ctx *ctx, const char *config_fi return err; } -__public int nvme_dump_config(struct nvme_global_ctx *ctx, int fd) +__public int libnvme_dump_config(struct libnvme_global_ctx *ctx, int fd) { return json_update_config(ctx, fd); } -__public int nvme_dump_tree(struct nvme_global_ctx *ctx) +__public int libnvme_dump_tree(struct libnvme_global_ctx *ctx) { return json_dump_tree(ctx); } -__public const char *nvme_get_application(struct nvme_global_ctx *ctx) +__public const char *libnvme_get_application(struct libnvme_global_ctx *ctx) { return ctx->application; } -__public void nvme_set_application(struct nvme_global_ctx *ctx, const char *a) +__public void libnvme_set_application(struct libnvme_global_ctx *ctx, + const char *a) { free(ctx->application); ctx->application = NULL; @@ -370,111 +379,117 @@ __public void nvme_set_application(struct nvme_global_ctx *ctx, const char *a) ctx->application = strdup(a); } -__public void nvme_skip_namespaces(struct nvme_global_ctx *ctx) +__public void libnvme_skip_namespaces(struct libnvme_global_ctx *ctx) { ctx->create_only = true; } -__public nvme_host_t nvme_first_host(struct nvme_global_ctx *ctx) +__public libnvme_host_t libnvme_first_host(struct libnvme_global_ctx *ctx) { - return list_top(&ctx->hosts, struct nvme_host, entry); + return list_top(&ctx->hosts, struct libnvme_host, entry); } -__public nvme_host_t nvme_next_host(struct nvme_global_ctx *ctx, nvme_host_t h) +__public libnvme_host_t libnvme_next_host(struct libnvme_global_ctx *ctx, + libnvme_host_t h) { return h ? list_next(&ctx->hosts, h, entry) : NULL; } -__public struct nvme_global_ctx *nvme_host_get_global_ctx(nvme_host_t h) +__public struct libnvme_global_ctx *libnvme_host_get_global_ctx( + libnvme_host_t h) { return h->ctx; } -__public void nvme_host_set_pdc_enabled(nvme_host_t h, bool enabled) +__public void libnvme_host_set_pdc_enabled(libnvme_host_t h, bool enabled) { h->pdc_enabled_valid = true; h->pdc_enabled = enabled; } -__public bool nvme_host_is_pdc_enabled(nvme_host_t h, bool fallback) +__public bool libnvme_host_is_pdc_enabled(libnvme_host_t h, bool fallback) { if (h->pdc_enabled_valid) return h->pdc_enabled; return fallback; } -__public nvme_subsystem_t nvme_first_subsystem(nvme_host_t h) +__public libnvme_subsystem_t libnvme_first_subsystem(libnvme_host_t h) { - return list_top(&h->subsystems, struct nvme_subsystem, entry); + return list_top(&h->subsystems, struct libnvme_subsystem, entry); } -__public nvme_subsystem_t nvme_next_subsystem(nvme_host_t h, nvme_subsystem_t s) +__public libnvme_subsystem_t libnvme_next_subsystem(libnvme_host_t h, + libnvme_subsystem_t s) { return s ? list_next(&h->subsystems, s, entry) : NULL; } -__public void nvme_refresh_topology(struct nvme_global_ctx *ctx) +__public void libnvme_refresh_topology(struct libnvme_global_ctx *ctx) { - struct nvme_host *h, *_h; + struct libnvme_host *h, *_h; - nvme_for_each_host_safe(ctx, h, _h) - __nvme_free_host(h); - nvme_scan_topology(ctx, NULL, NULL); + libnvme_for_each_host_safe(ctx, h, _h) + __libnvme_free_host(h); + libnvme_scan_topology(ctx, NULL, NULL); } -void nvme_root_release_fds(struct nvme_global_ctx *ctx) +void nvme_root_release_fds(struct libnvme_global_ctx *ctx) { - struct nvme_host *h, *_h; + struct libnvme_host *h, *_h; - nvme_for_each_host_safe(ctx, h, _h) - nvme_host_release_fds(h); + libnvme_for_each_host_safe(ctx, h, _h) + libnvme_host_release_fds(h); } -__public nvme_ctrl_t nvme_subsystem_first_ctrl(nvme_subsystem_t s) +__public libnvme_ctrl_t libnvme_subsystem_first_ctrl(libnvme_subsystem_t s) { - return list_top(&s->ctrls, struct nvme_ctrl, entry); + return list_top(&s->ctrls, struct libnvme_ctrl, entry); } -__public nvme_ctrl_t nvme_subsystem_next_ctrl(nvme_subsystem_t s, nvme_ctrl_t c) +__public libnvme_ctrl_t libnvme_subsystem_next_ctrl(libnvme_subsystem_t s, + libnvme_ctrl_t c) { return c ? list_next(&s->ctrls, c, entry) : NULL; } -__public nvme_host_t nvme_subsystem_get_host(nvme_subsystem_t s) +__public libnvme_host_t libnvme_subsystem_get_host(libnvme_subsystem_t s) { return s->h; } -__public nvme_ns_t nvme_subsystem_first_ns(nvme_subsystem_t s) +__public libnvme_ns_t libnvme_subsystem_first_ns(libnvme_subsystem_t s) { - return list_top(&s->namespaces, struct nvme_ns, entry); + return list_top(&s->namespaces, struct libnvme_ns, entry); } -__public nvme_ns_t nvme_subsystem_next_ns(nvme_subsystem_t s, nvme_ns_t n) +__public libnvme_ns_t libnvme_subsystem_next_ns(libnvme_subsystem_t s, + libnvme_ns_t n) { return n ? list_next(&s->namespaces, n, entry) : NULL; } -__public nvme_path_t nvme_namespace_first_path(nvme_ns_t ns) +__public libnvme_path_t libnvme_namespace_first_path(libnvme_ns_t ns) { - return list_top(&ns->head->paths, struct nvme_path, nentry); + return list_top(&ns->head->paths, struct libnvme_path, nentry); } -__public nvme_path_t nvme_namespace_next_path(nvme_ns_t ns, nvme_path_t p) +__public libnvme_path_t libnvme_namespace_next_path(libnvme_ns_t ns, + libnvme_path_t p) { return p ? list_next(&ns->head->paths, p, nentry) : NULL; } -static void __nvme_free_ns(struct nvme_ns *n) +static void __nvme_free_ns(struct libnvme_ns *n) { - struct nvme_path *p, *_p; + struct libnvme_path *p, *_p; list_del_init(&n->entry); - nvme_ns_release_transport_handle(n); + libnvme_ns_release_transport_handle(n); free(n->generic_name); free(n->name); free(n->sysfs_dir); - nvme_namespace_for_each_path_safe(n, p, _p) { + libnvme_namespace_for_each_path_safe(n, p, _p) { list_del_init(&p->nentry); p->n = NULL; } @@ -485,21 +500,21 @@ static void __nvme_free_ns(struct nvme_ns *n) } /* Stub for SWIG */ -__public void nvme_free_ns(struct nvme_ns *n) +__public void libnvme_free_ns(struct libnvme_ns *n) { __nvme_free_ns(n); } -static void __nvme_free_subsystem(struct nvme_subsystem *s) +static void __nvme_free_subsystem(struct libnvme_subsystem *s) { - struct nvme_ctrl *c, *_c; - struct nvme_ns *n, *_n; + struct libnvme_ctrl *c, *_c; + struct libnvme_ns *n, *_n; list_del_init(&s->entry); - nvme_subsystem_for_each_ctrl_safe(s, c, _c) - __nvme_free_ctrl(c); + libnvme_subsystem_for_each_ctrl_safe(s, c, _c) + __libnvme_free_ctrl(c); - nvme_subsystem_for_each_ns_safe(s, n, _n) + libnvme_subsystem_for_each_ns_safe(s, n, _n) __nvme_free_ns(n); free(s->name); @@ -514,30 +529,29 @@ static void __nvme_free_subsystem(struct nvme_subsystem *s) free(s); } -__public void nvme_subsystem_release_fds(struct nvme_subsystem *s) +__public void libnvme_subsystem_release_fds(struct libnvme_subsystem *s) { - struct nvme_ctrl *c, *_c; - struct nvme_ns *n, *_n; + struct libnvme_ctrl *c, *_c; + struct libnvme_ns *n, *_n; - nvme_subsystem_for_each_ctrl_safe(s, c, _c) - nvme_ctrl_release_transport_handle(c); + libnvme_subsystem_for_each_ctrl_safe(s, c, _c) + libnvme_ctrl_release_transport_handle(c); - nvme_subsystem_for_each_ns_safe(s, n, _n) - nvme_ns_release_transport_handle(n); + libnvme_subsystem_for_each_ns_safe(s, n, _n) + libnvme_ns_release_transport_handle(n); } /* * Stub for SWIG */ -__public void nvme_free_subsystem(nvme_subsystem_t s) +__public void libnvme_free_subsystem(libnvme_subsystem_t s) { } -struct nvme_subsystem *nvme_alloc_subsystem(struct nvme_host *h, - const char *name, - const char *subsysnqn) +struct libnvme_subsystem *nvme_alloc_subsystem(struct libnvme_host *h, + const char *name, const char *subsysnqn) { - struct nvme_subsystem *s; + struct libnvme_subsystem *s; s = calloc(1, sizeof(*s)); if (!s) @@ -546,7 +560,7 @@ struct nvme_subsystem *nvme_alloc_subsystem(struct nvme_host *h, s->h = h; s->subsysnqn = strdup(subsysnqn); if (name) - nvme_init_subsystem(s, name); + libnvme_init_subsystem(s, name); list_head_init(&s->ctrls); list_head_init(&s->namespaces); list_node_init(&s->entry); @@ -554,13 +568,12 @@ struct nvme_subsystem *nvme_alloc_subsystem(struct nvme_host *h, return s; } -struct nvme_subsystem *nvme_lookup_subsystem(struct nvme_host *h, - const char *name, - const char *subsysnqn) +struct libnvme_subsystem *libnvme_lookup_subsystem(struct libnvme_host *h, + const char *name, const char *subsysnqn) { - struct nvme_subsystem *s; + struct libnvme_subsystem *s; - nvme_for_each_subsystem(h, s) { + libnvme_for_each_subsystem(h, s) { if (subsysnqn && s->subsysnqn && strcmp(s->subsysnqn, subsysnqn)) continue; @@ -578,13 +591,13 @@ struct nvme_subsystem *nvme_lookup_subsystem(struct nvme_host *h, return nvme_alloc_subsystem(h, name, subsysnqn); } -__public int nvme_get_subsystem(struct nvme_global_ctx *ctx, - struct nvme_host *h, const char *name, - const char *subsysnqn, struct nvme_subsystem **subsys) +__public int libnvme_get_subsystem(struct libnvme_global_ctx *ctx, + struct libnvme_host *h, const char *name, + const char *subsysnqn, struct libnvme_subsystem **subsys) { - struct nvme_subsystem *s; + struct libnvme_subsystem *s; - s = nvme_lookup_subsystem(h, name, subsysnqn); + s = libnvme_lookup_subsystem(h, name, subsysnqn); if (!s) return -ENOMEM; @@ -593,38 +606,39 @@ __public int nvme_get_subsystem(struct nvme_global_ctx *ctx, return 0; } -void __nvme_free_host(struct nvme_host *h) +void __libnvme_free_host(struct libnvme_host *h) { - struct nvme_subsystem *s, *_s; + struct libnvme_subsystem *s, *_s; list_del_init(&h->entry); - nvme_for_each_subsystem_safe(h, s, _s) + libnvme_for_each_subsystem_safe(h, s, _s) __nvme_free_subsystem(s); free(h->hostnqn); free(h->hostid); free(h->dhchap_host_key); - nvme_host_set_hostsymname(h, NULL); + libnvme_host_set_hostsymname(h, NULL); free(h); } -__public void nvme_host_release_fds(struct nvme_host *h) +__public void libnvme_host_release_fds(struct libnvme_host *h) { - struct nvme_subsystem *s, *_s; + struct libnvme_subsystem *s, *_s; - nvme_for_each_subsystem_safe(h, s, _s) - nvme_subsystem_release_fds(s); + libnvme_for_each_subsystem_safe(h, s, _s) + libnvme_subsystem_release_fds(s); } /* Stub for SWIG */ -__public void nvme_free_host(struct nvme_host *h) +__public void libnvme_free_host(struct libnvme_host *h) { - __nvme_free_host(h); + __libnvme_free_host(h); } -static int nvme_create_host(struct nvme_global_ctx *ctx, const char *hostnqn, - const char *hostid, struct nvme_host **host) +static int libnvme_create_host(struct libnvme_global_ctx *ctx, + const char *hostnqn, const char *hostid, + struct libnvme_host **host) { - struct nvme_host *h; + struct libnvme_host *h; h = calloc(1, sizeof(*h)); if (!h) @@ -646,15 +660,15 @@ static int nvme_create_host(struct nvme_global_ctx *ctx, const char *hostnqn, return 0; } -struct nvme_host *nvme_lookup_host(struct nvme_global_ctx *ctx, +struct libnvme_host *libnvme_lookup_host(struct libnvme_global_ctx *ctx, const char *hostnqn, const char *hostid) { - struct nvme_host *h; + struct libnvme_host *h; if (!hostnqn) return NULL; - nvme_for_each_host(ctx, h) { + libnvme_for_each_host(ctx, h) { if (strcmp(h->hostnqn, hostnqn)) continue; if (hostid && (!h->hostid || @@ -663,56 +677,58 @@ struct nvme_host *nvme_lookup_host(struct nvme_global_ctx *ctx, return h; } - if (nvme_create_host(ctx, hostnqn, hostid, &h)) + if (libnvme_create_host(ctx, hostnqn, hostid, &h)) return NULL; return h; } -static int nvme_subsystem_scan_namespaces(struct nvme_global_ctx *ctx, nvme_subsystem_t s) +static int nvme_subsystem_scan_namespaces(struct libnvme_global_ctx *ctx, + libnvme_subsystem_t s) { _cleanup_dirents_ struct dirents namespaces = {}; int i, ret; if (ctx->create_only) { - nvme_msg(ctx, LOG_DEBUG, + libnvme_msg(ctx, LOG_DEBUG, "skipping namespace scan for subsys %s\n", s->subsysnqn); return 0; } - namespaces.num = nvme_scan_subsystem_namespaces(s, &namespaces.ents); + namespaces.num = libnvme_scan_subsystem_namespaces(s, &namespaces.ents); if (namespaces.num < 0) { - nvme_msg(ctx, LOG_DEBUG, - "failed to scan namespaces for subsys %s: %s\n", - s->subsysnqn, nvme_strerror(-namespaces.num)); + libnvme_msg(ctx, LOG_DEBUG, + "failed to scan namespaces for subsys %s: %s\n", + s->subsysnqn, libnvme_strerror(-namespaces.num)); return namespaces.num; } for (i = 0; i < namespaces.num; i++) { - ret = nvme_subsystem_scan_namespace(ctx, s, + ret = libnvme_subsystem_scan_namespace(ctx, s, namespaces.ents[i]->d_name); if (ret < 0) - nvme_msg(ctx, LOG_DEBUG, - "failed to scan namespace %s: %s\n", - namespaces.ents[i]->d_name, nvme_strerror(-ret)); + libnvme_msg(ctx, LOG_DEBUG, + "failed to scan namespace %s: %s\n", + namespaces.ents[i]->d_name, + libnvme_strerror(-ret)); } return 0; } -static int nvme_init_subsystem(nvme_subsystem_t s, const char *name) +static int libnvme_init_subsystem(libnvme_subsystem_t s, const char *name) { char *path; - if (asprintf(&path, "%s/%s", nvme_subsys_sysfs_dir(), name) < 0) + if (asprintf(&path, "%s/%s", libnvme_subsys_sysfs_dir(), name) < 0) return -ENOMEM; - s->model = nvme_get_attr(path, "model"); + s->model = libnvme_get_attr(path, "model"); if (!s->model) s->model = strdup("undefined"); - s->serial = nvme_get_attr(path, "serial"); - s->firmware = nvme_get_attr(path, "firmware_rev"); - s->subsystype = nvme_get_attr(path, "subsystype"); + s->serial = libnvme_get_attr(path, "serial"); + s->firmware = libnvme_get_attr(path, "firmware_rev"); + s->subsystype = libnvme_get_attr(path, "subsystype"); if (!s->subsystype) { if (!strcmp(s->subsysnqn, NVME_DISC_SUBSYS_NAME)) s->subsystype = strdup("discovery"); @@ -723,30 +739,31 @@ static int nvme_init_subsystem(nvme_subsystem_t s, const char *name) s->sysfs_dir = (char *)path; if (s->h->ctx->application) s->application = strdup(s->h->ctx->application); - s->iopolicy = nvme_get_attr(path, "iopolicy"); + s->iopolicy = libnvme_get_attr(path, "iopolicy"); return 0; } -static int nvme_scan_subsystem(struct nvme_global_ctx *ctx, const char *name) +static int libnvme_scan_subsystem(struct libnvme_global_ctx *ctx, + const char *name) { - struct nvme_subsystem *s = NULL, *_s; + struct libnvme_subsystem *s = NULL, *_s; _cleanup_free_ char *path = NULL, *subsysnqn = NULL; - nvme_host_t h = NULL; + libnvme_host_t h = NULL; int ret; - nvme_msg(ctx, LOG_DEBUG, "scan subsystem %s\n", name); - ret = asprintf(&path, "%s/%s", nvme_subsys_sysfs_dir(), name); + libnvme_msg(ctx, LOG_DEBUG, "scan subsystem %s\n", name); + ret = asprintf(&path, "%s/%s", libnvme_subsys_sysfs_dir(), name); if (ret < 0) return -ENOMEM; - subsysnqn = nvme_get_attr(path, "subsysnqn"); + subsysnqn = libnvme_get_attr(path, "subsysnqn"); if (!subsysnqn) return -ENODEV; - nvme_for_each_host(ctx, h) { - nvme_for_each_subsystem(h, _s) { + libnvme_for_each_host(ctx, h) { + libnvme_for_each_subsystem(h, _s) { /* - * We are always called after nvme_scan_ctrl(), + * We are always called after libnvme_scan_ctrl(), * so any subsystem we're interested at _must_ * have a name. */ @@ -765,9 +782,9 @@ static int nvme_scan_subsystem(struct nvme_global_ctx *ctx, const char *name) * Create a subsystem with the default host * and hope for the best. */ - nvme_msg(ctx, LOG_DEBUG, "creating detached subsystem '%s'\n", - name); - ret = nvme_get_host(ctx, NULL, NULL, &h); + libnvme_msg(ctx, LOG_DEBUG, + "creating detached subsystem '%s'\n", name); + ret = libnvme_get_host(ctx, NULL, NULL, &h); if (ret) return ret; s = nvme_alloc_subsystem(h, name, subsysnqn); @@ -776,7 +793,7 @@ static int nvme_scan_subsystem(struct nvme_global_ctx *ctx, const char *name) if (nvme_subsystem_scan_namespaces(ctx, s)) return -EINVAL; } else if (strcmp(s->subsysnqn, subsysnqn)) { - nvme_msg(ctx, LOG_DEBUG, "NQN mismatch for subsystem '%s'\n", + libnvme_msg(ctx, LOG_DEBUG, "NQN mismatch for subsystem '%s'\n", name); return -EINVAL; } @@ -784,21 +801,21 @@ static int nvme_scan_subsystem(struct nvme_global_ctx *ctx, const char *name) return 0; } -__public nvme_ctrl_t nvme_path_get_ctrl(nvme_path_t p) +__public libnvme_ctrl_t libnvme_path_get_ctrl(libnvme_path_t p) { return p->c; } -__public nvme_ns_t nvme_path_get_ns(nvme_path_t p) +__public libnvme_ns_t libnvme_path_get_ns(libnvme_path_t p) { return p->n; } -__public int nvme_path_get_queue_depth(nvme_path_t p) +__public int libnvme_path_get_queue_depth(libnvme_path_t p) { _cleanup_free_ char *queue_depth = NULL; - queue_depth = nvme_get_path_attr(p, "queue_depth"); + queue_depth = libnvme_get_path_attr(p, "queue_depth"); if (queue_depth) { sscanf(queue_depth, "%d", &p->queue_depth); } @@ -806,7 +823,7 @@ __public int nvme_path_get_queue_depth(nvme_path_t p) return p->queue_depth; } -void nvme_free_path(struct nvme_path *p) +void nvme_free_path(struct libnvme_path *p) { list_del_init(&p->entry); list_del_init(&p->nentry); @@ -817,13 +834,14 @@ void nvme_free_path(struct nvme_path *p) free(p); } -static int nvme_ctrl_scan_path(struct nvme_global_ctx *ctx, struct nvme_ctrl *c, char *name) +static int libnvme_ctrl_scan_path(struct libnvme_global_ctx *ctx, + struct libnvme_ctrl *c, char *name) { - struct nvme_path *p; + struct libnvme_path *p; _cleanup_free_ char *path = NULL, *grpid = NULL, *queue_depth = NULL; int ret; - nvme_msg(ctx, LOG_DEBUG, "scan controller %s path %s\n", + libnvme_msg(ctx, LOG_DEBUG, "scan controller %s path %s\n", c->name, name); if (!c->s) return -ENXIO; @@ -840,20 +858,20 @@ static int nvme_ctrl_scan_path(struct nvme_global_ctx *ctx, struct nvme_ctrl *c, p->name = strdup(name); p->sysfs_dir = path; path = NULL; - p->ana_state = nvme_get_path_attr(p, "ana_state"); + p->ana_state = libnvme_get_path_attr(p, "ana_state"); if (!p->ana_state) p->ana_state = strdup("optimized"); - p->numa_nodes = nvme_get_path_attr(p, "numa_nodes"); + p->numa_nodes = libnvme_get_path_attr(p, "numa_nodes"); if (!p->numa_nodes) p->numa_nodes = strdup("-1"); - grpid = nvme_get_path_attr(p, "ana_grpid"); + grpid = libnvme_get_path_attr(p, "ana_grpid"); if (grpid) { sscanf(grpid, "%d", &p->grpid); } - queue_depth = nvme_get_path_attr(p, "queue_depth"); + queue_depth = libnvme_get_path_attr(p, "queue_depth"); if (queue_depth) { sscanf(queue_depth, "%d", &p->queue_depth); } @@ -864,36 +882,38 @@ static int nvme_ctrl_scan_path(struct nvme_global_ctx *ctx, struct nvme_ctrl *c, return 0; } -__public struct nvme_transport_handle *nvme_ctrl_get_transport_handle(nvme_ctrl_t c) +__public struct libnvme_transport_handle *libnvme_ctrl_get_transport_handle( + libnvme_ctrl_t c) { if (!c->hdl) { int err; - err = nvme_open(c->ctx, c->name, &c->hdl); + err = libnvme_open(c->ctx, c->name, &c->hdl); if (err) - nvme_msg(c->ctx, LOG_ERR, + libnvme_msg(c->ctx, LOG_ERR, "Failed to open ctrl %s, errno %d\n", c->name, err); } return c->hdl; } -__public void nvme_ctrl_release_transport_handle(nvme_ctrl_t c) +__public void libnvme_ctrl_release_transport_handle(libnvme_ctrl_t c) { if (!c->hdl) return; - nvme_close(c->hdl); + libnvme_close(c->hdl); c->hdl = NULL; } -__public nvme_subsystem_t nvme_ctrl_get_subsystem(nvme_ctrl_t c) +__public libnvme_subsystem_t libnvme_ctrl_get_subsystem(libnvme_ctrl_t c) { return c->s; } -__public char *nvme_ctrl_get_src_addr(nvme_ctrl_t c, char *src_addr, size_t src_addr_len) +__public char *libnvme_ctrl_get_src_addr(libnvme_ctrl_t c, char *src_addr, + size_t src_addr_len) { size_t l; char *p; @@ -908,9 +928,9 @@ __public char *nvme_ctrl_get_src_addr(nvme_ctrl_t c, char *src_addr, size_t src_ p += strlen("src_addr="); l = strcspn(p, ",%"); /* % to eliminate IPv6 scope (if present) */ if (l >= src_addr_len) { - nvme_msg(c->ctx, LOG_ERR, - "Buffer for src_addr is too small (%zu must be > %zu)\n", - src_addr_len, l); + libnvme_msg(c->ctx, LOG_ERR, + "Buffer for src_addr is too small (%zu must be > %zu)\n", + src_addr_len, l); return NULL; } @@ -919,54 +939,57 @@ __public char *nvme_ctrl_get_src_addr(nvme_ctrl_t c, char *src_addr, size_t src_ return src_addr; } -__public const char *nvme_ctrl_get_state(nvme_ctrl_t c) +__public const char *libnvme_ctrl_get_state(libnvme_ctrl_t c) { char *state = c->state; - c->state = nvme_get_ctrl_attr(c, "state"); + c->state = libnvme_get_ctrl_attr(c, "state"); free(state); return c->state; } -__public struct nvme_fabrics_config *nvme_ctrl_get_config(nvme_ctrl_t c) +__public struct libnvme_fabrics_config *libnvme_ctrl_get_config( + libnvme_ctrl_t c) { return &c->cfg; } -__public int nvme_ctrl_identify(nvme_ctrl_t c, struct nvme_id_ctrl *id) +__public int libnvme_ctrl_identify(libnvme_ctrl_t c, struct nvme_id_ctrl *id) { - struct nvme_transport_handle *hdl = nvme_ctrl_get_transport_handle(c); - struct nvme_passthru_cmd cmd; + struct libnvme_transport_handle *hdl = + libnvme_ctrl_get_transport_handle(c); + struct libnvme_passthru_cmd cmd; nvme_init_identify_ctrl(&cmd, id); - return nvme_submit_admin_passthru(hdl, &cmd); + return libnvme_submit_admin_passthru(hdl, &cmd); } -__public nvme_ns_t nvme_ctrl_first_ns(nvme_ctrl_t c) +__public libnvme_ns_t libnvme_ctrl_first_ns(libnvme_ctrl_t c) { - return list_top(&c->namespaces, struct nvme_ns, entry); + return list_top(&c->namespaces, struct libnvme_ns, entry); } -__public nvme_ns_t nvme_ctrl_next_ns(nvme_ctrl_t c, nvme_ns_t n) +__public libnvme_ns_t libnvme_ctrl_next_ns(libnvme_ctrl_t c, libnvme_ns_t n) { return n ? list_next(&c->namespaces, n, entry) : NULL; } -__public nvme_path_t nvme_ctrl_first_path(nvme_ctrl_t c) +__public libnvme_path_t libnvme_ctrl_first_path(libnvme_ctrl_t c) { - return list_top(&c->paths, struct nvme_path, entry); + return list_top(&c->paths, struct libnvme_path, entry); } -__public nvme_path_t nvme_ctrl_next_path(nvme_ctrl_t c, nvme_path_t p) +__public libnvme_path_t libnvme_ctrl_next_path(libnvme_ctrl_t c, + libnvme_path_t p) { return p ? list_next(&c->paths, p, entry) : NULL; } #define FREE_CTRL_ATTR(a) \ do { free(a); (a) = NULL; } while (0) -void nvme_deconfigure_ctrl(nvme_ctrl_t c) +void nvme_deconfigure_ctrl(libnvme_ctrl_t c) { - nvme_ctrl_release_transport_handle(c); + libnvme_ctrl_release_transport_handle(c); FREE_CTRL_ATTR(c->name); FREE_CTRL_ATTR(c->sysfs_dir); FREE_CTRL_ATTR(c->firmware); @@ -988,40 +1011,41 @@ void nvme_deconfigure_ctrl(nvme_ctrl_t c) FREE_CTRL_ATTR(c->phy_slot); } -__public int nvme_disconnect_ctrl(nvme_ctrl_t c) +__public int libnvme_disconnect_ctrl(libnvme_ctrl_t c) { - struct nvme_global_ctx *ctx = c->s && c->s->h ? c->s->h->ctx : NULL; + struct libnvme_global_ctx *ctx = c->s && c->s->h ? c->s->h->ctx : NULL; int ret; - ret = nvme_set_attr(nvme_ctrl_get_sysfs_dir(c), + ret = libnvme_set_attr(libnvme_ctrl_get_sysfs_dir(c), "delete_controller", "1"); if (ret < 0) { - nvme_msg(ctx, LOG_ERR, "%s: failed to disconnect, error %d\n", - c->name, errno); + libnvme_msg(ctx, LOG_ERR, + "%s: failed to disconnect, error %d\n", c->name, errno); return ret; } - nvme_msg(ctx, LOG_INFO, "%s: %s disconnected\n", c->name, c->subsysnqn); + libnvme_msg(ctx, LOG_INFO, "%s: %s disconnected\n", + c->name, c->subsysnqn); nvme_deconfigure_ctrl(c); return 0; } -__public void nvme_unlink_ctrl(nvme_ctrl_t c) +__public void libnvme_unlink_ctrl(libnvme_ctrl_t c) { list_del_init(&c->entry); c->s = NULL; } -static void __nvme_free_ctrl(nvme_ctrl_t c) +static void __libnvme_free_ctrl(libnvme_ctrl_t c) { - struct nvme_path *p, *_p; - struct nvme_ns *n, *_n; + struct libnvme_path *p, *_p; + struct libnvme_ns *n, *_n; - nvme_unlink_ctrl(c); + libnvme_unlink_ctrl(c); - nvme_ctrl_for_each_path_safe(c, p, _p) + libnvme_ctrl_for_each_path_safe(c, p, _p) nvme_free_path(p); - nvme_ctrl_for_each_ns_safe(c, n, _n) + libnvme_ctrl_for_each_ns_safe(c, n, _n) __nvme_free_ns(n); nvme_deconfigure_ctrl(c); @@ -1035,9 +1059,9 @@ static void __nvme_free_ctrl(nvme_ctrl_t c) free(c); } -__public void nvme_free_ctrl(nvme_ctrl_t c) +__public void libnvme_free_ctrl(libnvme_ctrl_t c) { - __nvme_free_ctrl(c); + __libnvme_free_ctrl(c); } static bool traddr_is_hostname(const char *transport, const char *traddr) @@ -1057,32 +1081,31 @@ static bool traddr_is_hostname(const char *transport, const char *traddr) return true; } -__public void nvmf_default_config(struct nvme_fabrics_config *cfg) +__public void nvmf_default_config(struct libnvme_fabrics_config *cfg) { memset(cfg, 0, sizeof(*cfg)); cfg->tos = -1; cfg->ctrl_loss_tmo = NVMF_DEF_CTRL_LOSS_TMO; } -int _nvme_create_ctrl(struct nvme_global_ctx *ctx, - struct nvmf_context *fctx, - nvme_ctrl_t *cp) +int _libnvme_create_ctrl(struct libnvme_global_ctx *ctx, + struct nvmf_context *fctx, libnvme_ctrl_t *cp) { - struct nvme_ctrl *c; + struct libnvme_ctrl *c; if (!fctx->transport) { - nvme_msg(ctx, LOG_ERR, "No transport specified\n"); + libnvme_msg(ctx, LOG_ERR, "No transport specified\n"); return -EINVAL; } if (strncmp(fctx->transport, "loop", 4) && strncmp(fctx->transport, "pcie", 4) && strncmp(fctx->transport, "apple-nvme", 10) && !fctx->traddr) { - nvme_msg(ctx, LOG_ERR, "No transport address for '%s'\n", + libnvme_msg(ctx, LOG_ERR, "No transport address for '%s'\n", fctx->transport); return -EINVAL; } if (!fctx->subsysnqn) { - nvme_msg(ctx, LOG_ERR, "No subsystem NQN specified\n"); + libnvme_msg(ctx, LOG_ERR, "No subsystem NQN specified\n"); return -EINVAL; } c = calloc(1, sizeof(*c)); @@ -1115,11 +1138,11 @@ int _nvme_create_ctrl(struct nvme_global_ctx *ctx, return 0; } -__public int nvme_create_ctrl(struct nvme_global_ctx *ctx, - const char *subsysnqn, const char *transport, - const char *traddr, const char *host_traddr, - const char *host_iface, const char *trsvcid, - nvme_ctrl_t *cp) +__public int libnvme_create_ctrl(struct libnvme_global_ctx *ctx, + const char *subsysnqn, const char *transport, + const char *traddr, const char *host_traddr, + const char *host_iface, const char *trsvcid, + libnvme_ctrl_t *cp) { struct nvmf_context fctx = { .transport = transport, @@ -1130,7 +1153,7 @@ __public int nvme_create_ctrl(struct nvme_global_ctx *ctx, .subsysnqn = subsysnqn, }; - return _nvme_create_ctrl(ctx, &fctx, cp); + return _libnvme_create_ctrl(ctx, &fctx, cp); } /** @@ -1146,10 +1169,12 @@ __public int nvme_create_ctrl(struct nvme_global_ctx *ctx, * * Return: true if @c->host_traddr matches @candidate->host_traddr. false otherwise. */ -static bool _tcp_ctrl_match_host_traddr_no_src_addr(struct nvme_ctrl *c, struct candidate_args *candidate) +static bool _tcp_ctrl_match_host_traddr_no_src_addr(struct libnvme_ctrl *c, + struct candidate_args *candidate) { if (c->host_traddr) - return candidate->addreq(candidate->host_traddr, c->host_traddr); + return candidate->addreq(candidate->host_traddr, + c->host_traddr); /* If c->cfg.host_traddr is NULL, then the controller (c) * uses the interface's primary address as the source @@ -1158,18 +1183,17 @@ static bool _tcp_ctrl_match_host_traddr_no_src_addr(struct nvme_ctrl *c, struct * interface and compare that to the candidate->host_traddr. */ if (c->host_iface) - return nvme_iface_primary_addr_matches(candidate->iface_list, - c->host_iface, - candidate->host_traddr); + return libnvme_iface_primary_addr_matches(candidate->iface_list, + c->host_iface, candidate->host_traddr); /* If both c->cfg.host_traddr and c->cfg.host_iface are * NULL, we don't have enough information to make a * 100% positive match. Regardless, let's be optimistic * and assume that we have a match. */ - nvme_msg(c->ctx, LOG_DEBUG, - "Not enough data, but assume %s matches candidate's host_traddr: %s\n", - nvme_ctrl_get_name(c), candidate->host_traddr); + libnvme_msg(c->ctx, LOG_DEBUG, + "Not enough data, but assume %s matches candidate's host_traddr: %s\n", + libnvme_ctrl_get_name(c), candidate->host_traddr); return true; } @@ -1187,7 +1211,8 @@ static bool _tcp_ctrl_match_host_traddr_no_src_addr(struct nvme_ctrl *c, struct * * Return: true if @c->host_iface matches @candidate->host_iface. false otherwise. */ -static bool _tcp_ctrl_match_host_iface_no_src_addr(struct nvme_ctrl *c, struct candidate_args *candidate) +static bool _tcp_ctrl_match_host_iface_no_src_addr(struct libnvme_ctrl *c, + struct candidate_args *candidate) { if (c->host_iface) return streq0(candidate->host_iface, c->host_iface); @@ -1198,7 +1223,9 @@ static bool _tcp_ctrl_match_host_iface_no_src_addr(struct nvme_ctrl *c, struct c if (c->host_traddr) { const char *c_host_iface; - c_host_iface = nvme_iface_matching_addr(candidate->iface_list, c->host_traddr); + c_host_iface = + libnvme_iface_matching_addr(candidate->iface_list, + c->host_traddr); return streq0(candidate->host_iface, c_host_iface); } @@ -1207,15 +1234,16 @@ static bool _tcp_ctrl_match_host_iface_no_src_addr(struct nvme_ctrl *c, struct c * 100% positive match. Regardless, let's be optimistic * and assume that we have a match. */ - nvme_msg(c->ctx, LOG_DEBUG, - "Not enough data, but assume %s matches candidate's host_iface: %s\n", - nvme_ctrl_get_name(c), candidate->host_iface); + libnvme_msg(c->ctx, LOG_DEBUG, + "Not enough data, but assume %s matches candidate's host_iface: %s\n", + libnvme_ctrl_get_name(c), candidate->host_iface); return true; } /** - * _tcp_opt_params_match_no_src_addr() - Match optional host_traddr/host_iface w/o src_addr + * _tcp_opt_params_match_no_src_addr() - Match optional + * host_traddr/host_iface w/o src_addr * @c: An existing controller instance * @candidate: Candidate ctrl we're trying to match with @c. * @@ -1231,7 +1259,8 @@ static bool _tcp_ctrl_match_host_iface_no_src_addr(struct nvme_ctrl *c, struct c * * Return: true if @c matches @candidate. false otherwise. */ -static bool _tcp_opt_params_match_no_src_addr(struct nvme_ctrl *c, struct candidate_args *candidate) +static bool _tcp_opt_params_match_no_src_addr(struct libnvme_ctrl *c, + struct candidate_args *candidate) { /* Check host_traddr only if candidate is interested */ if (candidate->host_traddr) { @@ -1286,12 +1315,13 @@ static bool _tcp_opt_params_match_no_src_addr(struct nvme_ctrl *c, struct candid * * Return: true if @c matches @candidate. false otherwise. */ -static bool _tcp_opt_params_match(struct nvme_ctrl *c, struct candidate_args *candidate) +static bool _tcp_opt_params_match(struct libnvme_ctrl *c, + struct candidate_args *candidate) { char *src_addr, buffer[INET6_ADDRSTRLEN]; /* Check if src_addr is available (kernel 6.1 or later) */ - src_addr = nvme_ctrl_get_src_addr(c, buffer, sizeof(buffer)); + src_addr = libnvme_ctrl_get_src_addr(c, buffer, sizeof(buffer)); if (!src_addr) return _tcp_opt_params_match_no_src_addr(c, candidate); @@ -1303,7 +1333,7 @@ static bool _tcp_opt_params_match(struct nvme_ctrl *c, struct candidate_args *ca /* Check host_iface only if candidate is interested */ if (candidate->host_iface && !streq0(candidate->host_iface, - nvme_iface_matching_addr(candidate->iface_list, src_addr))) + libnvme_iface_matching_addr(candidate->iface_list, src_addr))) return false; return true; @@ -1327,7 +1357,8 @@ static bool _tcp_opt_params_match(struct nvme_ctrl *c, struct candidate_args *ca * * Return: true if a match is found, false otherwise. */ -static bool _tcp_match_ctrl(struct nvme_ctrl *c, struct candidate_args *candidate) +static bool _tcp_match_ctrl(struct libnvme_ctrl *c, + struct candidate_args *candidate) { if (!streq0(c->transport, candidate->transport)) return false; @@ -1338,7 +1369,7 @@ static bool _tcp_match_ctrl(struct nvme_ctrl *c, struct candidate_args *candidat if (!candidate->addreq(c->traddr, candidate->traddr)) return false; - if (candidate->well_known_nqn && !nvme_ctrl_get_discovery_ctrl(c)) + if (candidate->well_known_nqn && !libnvme_ctrl_get_discovery_ctrl(c)) return false; if (candidate->subsysnqn && !streq0(c->subsysnqn, candidate->subsysnqn)) @@ -1363,7 +1394,8 @@ static bool _tcp_match_ctrl(struct nvme_ctrl *c, struct candidate_args *candidat * * Return: true if a match is found, false otherwise. */ -static bool _match_ctrl(struct nvme_ctrl *c, struct candidate_args *candidate) +static bool _match_ctrl(struct libnvme_ctrl *c, + struct candidate_args *candidate) { if (!streq0(c->transport, candidate->transport)) return false; @@ -1384,7 +1416,7 @@ static bool _match_ctrl(struct nvme_ctrl *c, struct candidate_args *candidate) !streq0(c->trsvcid, candidate->trsvcid)) return false; - if (candidate->well_known_nqn && !nvme_ctrl_get_discovery_ctrl(c)) + if (candidate->well_known_nqn && !libnvme_ctrl_get_discovery_ctrl(c)) return false; if (candidate->subsysnqn && !streq0(c->subsysnqn, candidate->subsysnqn)) @@ -1410,9 +1442,8 @@ static bool _match_ctrl(struct nvme_ctrl *c, struct candidate_args *candidate) * Return: The matching function to use when comparing an existing * controller to the candidate controller. */ -static ctrl_match_t _candidate_init(struct nvme_global_ctx *ctx, - struct candidate_args *candidate, - struct nvmf_context *fctx) +static ctrl_match_t _candidate_init(struct libnvme_global_ctx *ctx, + struct candidate_args *candidate, struct nvmf_context *fctx) { memset(candidate, 0, sizeof(*candidate)); @@ -1438,13 +1469,13 @@ static ctrl_match_t _candidate_init(struct nvme_global_ctx *ctx, } if (streq0(fctx->transport, "tcp")) { - candidate->iface_list = nvme_getifaddrs(ctx); /* TCP only */ - candidate->addreq = nvme_ipaddrs_eq; + candidate->iface_list = libnvme_getifaddrs(ctx); /* TCP only */ + candidate->addreq = libnvme_ipaddrs_eq; return _tcp_match_ctrl; } if (streq0(fctx->transport, "rdma")) { - candidate->addreq = nvme_ipaddrs_eq; + candidate->addreq = libnvme_ipaddrs_eq; return _match_ctrl; } @@ -1453,19 +1484,18 @@ static ctrl_match_t _candidate_init(struct nvme_global_ctx *ctx, return _match_ctrl; } -static nvme_ctrl_t __nvme_ctrl_find(nvme_subsystem_t s, - struct nvmf_context *fctx, - nvme_ctrl_t p) +static libnvme_ctrl_t __nvme_ctrl_find(libnvme_subsystem_t s, + struct nvmf_context *fctx, libnvme_ctrl_t p) { struct candidate_args candidate = {}; - struct nvme_ctrl *c, *matching_c = NULL; + struct libnvme_ctrl *c, *matching_c = NULL; ctrl_match_t ctrl_match; /* Init candidate and get the matching function to use */ ctrl_match = _candidate_init(s->h->ctx, &candidate, fctx); - c = p ? nvme_subsystem_next_ctrl(s, p) : nvme_subsystem_first_ctrl(s); - for (; c != NULL; c = nvme_subsystem_next_ctrl(s, c)) { + c = p ? libnvme_subsystem_next_ctrl(s, p) : libnvme_subsystem_first_ctrl(s); + for (; c != NULL; c = libnvme_subsystem_next_ctrl(s, c)) { if (ctrl_match(c, &candidate)) { matching_c = c; break; @@ -1475,7 +1505,8 @@ static nvme_ctrl_t __nvme_ctrl_find(nvme_subsystem_t s, return matching_c; } -bool _nvme_ctrl_match_config(struct nvme_ctrl *c, struct nvmf_context *fctx) +bool _libnvme_ctrl_match_config(struct libnvme_ctrl *c, + struct nvmf_context *fctx) { struct candidate_args candidate = {}; ctrl_match_t ctrl_match; @@ -1486,10 +1517,10 @@ bool _nvme_ctrl_match_config(struct nvme_ctrl *c, struct nvmf_context *fctx) return ctrl_match(c, &candidate); } -__public bool nvme_ctrl_match_config(struct nvme_ctrl *c, const char *transport, - const char *traddr, const char *trsvcid, - const char *subsysnqn, const char *host_traddr, - const char *host_iface) +__public bool libnvme_ctrl_match_config(struct libnvme_ctrl *c, + const char *transport, const char *traddr, const char *trsvcid, + const char *subsysnqn, const char *host_traddr, + const char *host_iface) { struct nvmf_context fctx = { .transport = transport, @@ -1500,20 +1531,21 @@ __public bool nvme_ctrl_match_config(struct nvme_ctrl *c, const char *transport, .subsysnqn = subsysnqn, }; - return _nvme_ctrl_match_config(c, &fctx); + return _libnvme_ctrl_match_config(c, &fctx); } -nvme_ctrl_t nvme_ctrl_find(nvme_subsystem_t s, struct nvmf_context *fctx) +libnvme_ctrl_t libnvme_ctrl_find(libnvme_subsystem_t s, + struct nvmf_context *fctx) { return __nvme_ctrl_find(s, fctx, NULL/*p*/); } -nvme_ctrl_t nvme_lookup_ctrl(nvme_subsystem_t s, +libnvme_ctrl_t libnvme_lookup_ctrl(libnvme_subsystem_t s, struct nvmf_context *fctx, - nvme_ctrl_t p) + libnvme_ctrl_t p) { - struct nvme_global_ctx *ctx; - struct nvme_ctrl *c; + struct libnvme_global_ctx *ctx; + struct libnvme_ctrl *c; const char *subsysnqn = fctx->subsysnqn; int ret; @@ -1531,7 +1563,7 @@ nvme_ctrl_t nvme_lookup_ctrl(nvme_subsystem_t s, ctx = s->h ? s->h->ctx : NULL; /* Set the NQN to the subsystem the controller should be created in */ fctx->subsysnqn = s->subsysnqn; - ret = _nvme_create_ctrl(ctx, fctx, &c); + ret = _libnvme_create_ctrl(ctx, fctx, &c); /* And restore NQN to avoid issues with repetitive calls */ fctx->subsysnqn = subsysnqn; if (ret) @@ -1543,22 +1575,23 @@ nvme_ctrl_t nvme_lookup_ctrl(nvme_subsystem_t s, return c; } -static int nvme_ctrl_scan_paths(struct nvme_global_ctx *ctx, struct nvme_ctrl *c) +static int libnvme_ctrl_scan_paths(struct libnvme_global_ctx *ctx, + struct libnvme_ctrl *c) { _cleanup_dirents_ struct dirents paths = {}; int err, i; if (ctx->create_only) { - nvme_msg(ctx, LOG_DEBUG, + libnvme_msg(ctx, LOG_DEBUG, "skipping path scan for ctrl %s\n", c->name); return 0; } - paths.num = nvme_scan_ctrl_namespace_paths(c, &paths.ents); + paths.num = libnvme_scan_ctrl_namespace_paths(c, &paths.ents); if (paths.num < 0) return paths.num; for (i = 0; i < paths.num; i++) { - err = nvme_ctrl_scan_path(ctx, c, paths.ents[i]->d_name); + err = libnvme_ctrl_scan_path(ctx, c, paths.ents[i]->d_name); if (err) return err; } @@ -1566,19 +1599,20 @@ static int nvme_ctrl_scan_paths(struct nvme_global_ctx *ctx, struct nvme_ctrl *c return 0; } -static int nvme_ctrl_scan_namespaces(struct nvme_global_ctx *ctx, struct nvme_ctrl *c) +static int libnvme_ctrl_scan_namespaces(struct libnvme_global_ctx *ctx, + struct libnvme_ctrl *c) { _cleanup_dirents_ struct dirents namespaces = {}; int err, i; if (ctx->create_only) { - nvme_msg(ctx, LOG_DEBUG, "skipping namespace scan for ctrl %s\n", - c->name); + libnvme_msg(ctx, LOG_DEBUG, + "skipping namespace scan for ctrl %s\n", c->name); return 0; } - namespaces.num = nvme_scan_ctrl_namespaces(c, &namespaces.ents); + namespaces.num = libnvme_scan_ctrl_namespaces(c, &namespaces.ents); for (i = 0; i < namespaces.num; i++) { - err = nvme_ctrl_scan_namespace(ctx, c, + err = libnvme_ctrl_scan_namespace(ctx, c, namespaces.ents[i]->d_name); if (err) return err; @@ -1587,15 +1621,14 @@ static int nvme_ctrl_scan_namespaces(struct nvme_global_ctx *ctx, struct nvme_ct return 0; } -static int nvme_ctrl_lookup_subsystem_name(struct nvme_global_ctx *ctx, - const char *ctrl_name, - char **name) +static int libnvme_ctrl_lookup_subsystem_name(struct libnvme_global_ctx *ctx, + const char *ctrl_name, char **name) { - const char *subsys_dir = nvme_subsys_sysfs_dir(); + const char *subsys_dir = libnvme_subsys_sysfs_dir(); _cleanup_dirents_ struct dirents subsys = {}; int i; - subsys.num = nvme_scan_subsystems(&subsys.ents); + subsys.num = libnvme_scan_subsystems(&subsys.ents); if (subsys.num < 0) return subsys.num; @@ -1606,7 +1639,7 @@ static int nvme_ctrl_lookup_subsystem_name(struct nvme_global_ctx *ctx, if (asprintf(&path, "%s/%s/%s", subsys_dir, subsys.ents[i]->d_name, ctrl_name) < 0) return -ENOMEM; - nvme_msg(ctx, LOG_DEBUG, "lookup subsystem %s\n", path); + libnvme_msg(ctx, LOG_DEBUG, "lookup subsystem %s\n", path); if (stat(path, &st) < 0) { continue; } @@ -1620,10 +1653,10 @@ static int nvme_ctrl_lookup_subsystem_name(struct nvme_global_ctx *ctx, return -ENOENT; } -static int nvme_ctrl_lookup_phy_slot(struct nvme_global_ctx *ctx, - nvme_ctrl_t c) +static int libnvme_ctrl_lookup_phy_slot(struct libnvme_global_ctx *ctx, + libnvme_ctrl_t c) { - const char *slots_sysfs_dir = nvme_slots_sysfs_dir(); + const char *slots_sysfs_dir = libnvme_slots_sysfs_dir(); _cleanup_free_ char *target_addr = NULL; _cleanup_dir_ DIR *slots_dir = NULL; struct dirent *entry; @@ -1635,7 +1668,7 @@ static int nvme_ctrl_lookup_phy_slot(struct nvme_global_ctx *ctx, slots_dir = opendir(slots_sysfs_dir); if (!slots_dir) { - nvme_msg(ctx, LOG_WARNING, "failed to open slots dir %s\n", + libnvme_msg(ctx, LOG_WARNING, "failed to open slots dir %s\n", slots_sysfs_dir); return -errno; } @@ -1652,7 +1685,7 @@ static int nvme_ctrl_lookup_phy_slot(struct nvme_global_ctx *ctx, slots_sysfs_dir, entry->d_name); if (ret < 0) return -ENOMEM; - addr = nvme_get_attr(path, "address"); + addr = libnvme_get_attr(path, "address"); /* some directories don't have an address entry */ if (!addr) @@ -1671,45 +1704,47 @@ static int nvme_ctrl_lookup_phy_slot(struct nvme_global_ctx *ctx, return -ENOENT; } -static void nvme_read_sysfs_dhchap(struct nvme_global_ctx *ctx, nvme_ctrl_t c) +static void libnvme_read_sysfs_dhchap(struct libnvme_global_ctx *ctx, + libnvme_ctrl_t c) { char *host_key, *ctrl_key; - host_key = nvme_get_ctrl_attr(c, "dhchap_secret"); + host_key = libnvme_get_ctrl_attr(c, "dhchap_secret"); if (host_key && !strcmp(host_key, "none")) { free(host_key); host_key = NULL; } if (host_key) { - nvme_ctrl_set_dhchap_host_key(c, NULL); + libnvme_ctrl_set_dhchap_host_key(c, NULL); c->dhchap_host_key = host_key; } - ctrl_key = nvme_get_ctrl_attr(c, "dhchap_ctrl_secret"); + ctrl_key = libnvme_get_ctrl_attr(c, "dhchap_ctrl_secret"); if (ctrl_key && !strcmp(ctrl_key, "none")) { free(ctrl_key); ctrl_key = NULL; } if (ctrl_key) { - nvme_ctrl_set_dhchap_ctrl_key(c, NULL); + libnvme_ctrl_set_dhchap_ctrl_key(c, NULL); c->dhchap_ctrl_key = ctrl_key; } } -static void nvme_read_sysfs_tls(struct nvme_global_ctx *ctx, nvme_ctrl_t c) +static void libnvme_read_sysfs_tls(struct libnvme_global_ctx *ctx, + libnvme_ctrl_t c) { char *endptr; long key_id; char *key, *keyring; - key = nvme_get_ctrl_attr(c, "tls_key"); + key = libnvme_get_ctrl_attr(c, "tls_key"); if (!key) { /* tls_key is only present if --tls or --concat has been used */ return; } - keyring = nvme_get_ctrl_attr(c, "tls_keyring"); - nvme_ctrl_set_keyring(c, keyring); + keyring = libnvme_get_ctrl_attr(c, "tls_keyring"); + libnvme_ctrl_set_keyring(c, keyring); free(keyring); /* the sysfs entry is not prefixing the id but it's in hex */ @@ -1719,7 +1754,7 @@ static void nvme_read_sysfs_tls(struct nvme_global_ctx *ctx, nvme_ctrl_t c) free(key); - key = nvme_get_ctrl_attr(c, "tls_configured_key"); + key = libnvme_get_ctrl_attr(c, "tls_configured_key"); if (!key) return; @@ -1731,8 +1766,8 @@ static void nvme_read_sysfs_tls(struct nvme_global_ctx *ctx, nvme_ctrl_t c) free(key); } -static int nvme_reconfigure_ctrl(struct nvme_global_ctx *ctx, nvme_ctrl_t c, const char *path, - const char *name) +static int libnvme_reconfigure_ctrl(struct libnvme_global_ctx *ctx, + libnvme_ctrl_t c, const char *path, const char *name) { DIR *d; @@ -1740,7 +1775,7 @@ static int nvme_reconfigure_ctrl(struct nvme_global_ctx *ctx, nvme_ctrl_t c, con * It's necesssary to release any resources first because a ctrl * can be reused. */ - nvme_ctrl_release_transport_handle(c); + libnvme_ctrl_release_transport_handle(c); FREE_CTRL_ATTR(c->name); FREE_CTRL_ATTR(c->sysfs_dir); FREE_CTRL_ATTR(c->firmware); @@ -1757,8 +1792,8 @@ static int nvme_reconfigure_ctrl(struct nvme_global_ctx *ctx, nvme_ctrl_t c, con d = opendir(path); if (!d) { - nvme_msg(ctx, LOG_ERR, "Failed to open ctrl dir %s, error %d\n", - path, errno); + libnvme_msg(ctx, LOG_ERR, + "Failed to open ctrl dir %s, error %d\n", path, errno); return -ENODEV; } closedir(d); @@ -1766,54 +1801,54 @@ static int nvme_reconfigure_ctrl(struct nvme_global_ctx *ctx, nvme_ctrl_t c, con c->hdl = NULL; c->name = xstrdup(name); c->sysfs_dir = xstrdup(path); - c->firmware = nvme_get_ctrl_attr(c, "firmware_rev"); - c->model = nvme_get_ctrl_attr(c, "model"); - c->state = nvme_get_ctrl_attr(c, "state"); - c->numa_node = nvme_get_ctrl_attr(c, "numa_node"); - c->queue_count = nvme_get_ctrl_attr(c, "queue_count"); - c->serial = nvme_get_ctrl_attr(c, "serial"); - c->sqsize = nvme_get_ctrl_attr(c, "sqsize"); - c->cntrltype = nvme_get_ctrl_attr(c, "cntrltype"); - c->cntlid = nvme_get_ctrl_attr(c, "cntlid"); - c->dctype = nvme_get_ctrl_attr(c, "dctype"); - nvme_ctrl_lookup_phy_slot(ctx, c); - nvme_read_sysfs_dhchap(ctx, c); - nvme_read_sysfs_tls(ctx, c); + c->firmware = libnvme_get_ctrl_attr(c, "firmware_rev"); + c->model = libnvme_get_ctrl_attr(c, "model"); + c->state = libnvme_get_ctrl_attr(c, "state"); + c->numa_node = libnvme_get_ctrl_attr(c, "numa_node"); + c->queue_count = libnvme_get_ctrl_attr(c, "queue_count"); + c->serial = libnvme_get_ctrl_attr(c, "serial"); + c->sqsize = libnvme_get_ctrl_attr(c, "sqsize"); + c->cntrltype = libnvme_get_ctrl_attr(c, "cntrltype"); + c->cntlid = libnvme_get_ctrl_attr(c, "cntlid"); + c->dctype = libnvme_get_ctrl_attr(c, "dctype"); + libnvme_ctrl_lookup_phy_slot(ctx, c); + libnvme_read_sysfs_dhchap(ctx, c); + libnvme_read_sysfs_tls(ctx, c); return 0; } -__public int nvme_init_ctrl(nvme_host_t h, nvme_ctrl_t c, int instance) +__public int libnvme_init_ctrl(libnvme_host_t h, libnvme_ctrl_t c, int instance) { _cleanup_free_ char *subsys_name = NULL, *name = NULL, *path = NULL; - nvme_subsystem_t s; + libnvme_subsystem_t s; int ret; ret = asprintf(&name, "nvme%d", instance); if (ret < 0) return -ENOMEM; - ret = asprintf(&path, "%s/%s", nvme_ctrl_sysfs_dir(), name); + ret = asprintf(&path, "%s/%s", libnvme_ctrl_sysfs_dir(), name); if (ret < 0) return -ENOMEM; - ret = nvme_reconfigure_ctrl(h->ctx, c, path, name); + ret = libnvme_reconfigure_ctrl(h->ctx, c, path, name); if (ret < 0) return ret; - c->address = nvme_get_attr(path, "address"); + c->address = libnvme_get_attr(path, "address"); if (!c->address && strcmp(c->transport, "loop")) return -ENVME_CONNECT_INVAL_TR; - ret = nvme_ctrl_lookup_subsystem_name(h->ctx, name, &subsys_name); + ret = libnvme_ctrl_lookup_subsystem_name(h->ctx, name, &subsys_name); if (ret) { - nvme_msg(h->ctx, LOG_ERR, + libnvme_msg(h->ctx, LOG_ERR, "Failed to lookup subsystem name for %s\n", c->name); return ENVME_CONNECT_LOOKUP_SUBSYS_NAME; } - s = nvme_lookup_subsystem(h, subsys_name, c->subsysnqn); + s = libnvme_lookup_subsystem(h, subsys_name, c->subsysnqn); if (!s) return -ENVME_CONNECT_LOOKUP_SUBSYS; @@ -1826,23 +1861,22 @@ __public int nvme_init_ctrl(nvme_host_t h, nvme_ctrl_t c, int instance) return ret; } -int nvme_ctrl_alloc(struct nvme_global_ctx *ctx, nvme_subsystem_t s, - const char *path, const char *name, - nvme_ctrl_t *cp) +int libnvme_ctrl_alloc(struct libnvme_global_ctx *ctx, libnvme_subsystem_t s, + const char *path, const char *name, libnvme_ctrl_t *cp) { _cleanup_free_ char *addr = NULL, *address = NULL, *transport = NULL; char *host_traddr = NULL, *host_iface = NULL; char *traddr = NULL, *trsvcid = NULL; char *a = NULL, *e = NULL; - nvme_ctrl_t c, p; + libnvme_ctrl_t c, p; int ret; - transport = nvme_get_attr(path, "transport"); + transport = libnvme_get_attr(path, "transport"); if (!transport) return -ENXIO; /* Parse 'address' string into components */ - addr = nvme_get_attr(path, "address"); + addr = libnvme_get_attr(path, "address"); if (!addr) { _cleanup_free_ char *rpath = NULL; char *p = NULL, *_a = NULL; @@ -1899,30 +1933,31 @@ int nvme_ctrl_alloc(struct nvme_global_ctx *ctx, nvme_subsystem_t s, .host_iface = host_iface, .trsvcid = trsvcid, }; - c = nvme_lookup_ctrl(s, &fctx, p); + c = libnvme_lookup_ctrl(s, &fctx, p); if (c) { if (!c->name) break; if (!strcmp(c->name, name)) { - nvme_msg(ctx, LOG_DEBUG, - "found existing ctrl %s\n", c->name); + libnvme_msg(ctx, LOG_DEBUG, + "found existing ctrl %s\n", c->name); break; } - nvme_msg(ctx, LOG_DEBUG, "skipping ctrl %s\n", c->name); + libnvme_msg(ctx, LOG_DEBUG, + "skipping ctrl %s\n", c->name); p = c; } } while (c); if (!c) c = p; if (!c && !p) { - nvme_msg(ctx, LOG_ERR, "failed to lookup ctrl\n"); + libnvme_msg(ctx, LOG_ERR, "failed to lookup ctrl\n"); return -ENODEV; } FREE_CTRL_ATTR(c->address); c->address = xstrdup(addr); if (s->subsystype && !strcmp(s->subsystype, "discovery")) c->discovery_ctrl = true; - ret = nvme_reconfigure_ctrl(ctx, c, path, name); + ret = libnvme_reconfigure_ctrl(ctx, c, path, name); if (ret) return ret; @@ -1930,30 +1965,30 @@ int nvme_ctrl_alloc(struct nvme_global_ctx *ctx, nvme_subsystem_t s, return 0; } -__public int nvme_scan_ctrl(struct nvme_global_ctx *ctx, const char *name, - nvme_ctrl_t *cp) +__public int libnvme_scan_ctrl(struct libnvme_global_ctx *ctx, const char *name, + libnvme_ctrl_t *cp) { _cleanup_free_ char *subsysnqn = NULL, *subsysname = NULL; _cleanup_free_ char *hostnqn = NULL, *hostid = NULL; _cleanup_free_ char *path = NULL; char *host_key; - nvme_host_t h; - nvme_subsystem_t s; - nvme_ctrl_t c; + libnvme_host_t h; + libnvme_subsystem_t s; + libnvme_ctrl_t c; int ret; - nvme_msg(ctx, LOG_DEBUG, "scan controller %s\n", name); - ret = asprintf(&path, "%s/%s", nvme_ctrl_sysfs_dir(), name); + libnvme_msg(ctx, LOG_DEBUG, "scan controller %s\n", name); + ret = asprintf(&path, "%s/%s", libnvme_ctrl_sysfs_dir(), name); if (ret < 0) return -ENOMEM; - hostnqn = nvme_get_attr(path, "hostnqn"); - hostid = nvme_get_attr(path, "hostid"); - ret = nvme_get_host(ctx, hostnqn, hostid, &h); + hostnqn = libnvme_get_attr(path, "hostnqn"); + hostid = libnvme_get_attr(path, "hostid"); + ret = libnvme_get_host(ctx, hostnqn, hostid, &h); if (ret) return ret; - host_key = nvme_get_attr(path, "dhchap_secret"); + host_key = libnvme_get_attr(path, "dhchap_secret"); if (host_key && strcmp(host_key, "none")) { free(h->dhchap_host_key); h->dhchap_host_key = host_key; @@ -1961,35 +1996,35 @@ __public int nvme_scan_ctrl(struct nvme_global_ctx *ctx, const char *name, } free(host_key); - subsysnqn = nvme_get_attr(path, "subsysnqn"); + subsysnqn = libnvme_get_attr(path, "subsysnqn"); if (!subsysnqn) return -ENXIO; - ret = nvme_ctrl_lookup_subsystem_name(ctx, name, &subsysname); + ret = libnvme_ctrl_lookup_subsystem_name(ctx, name, &subsysname); if (ret) { - nvme_msg(ctx, LOG_DEBUG, + libnvme_msg(ctx, LOG_DEBUG, "failed to lookup subsystem for controller %s\n", name); return ret; } - s = nvme_lookup_subsystem(h, subsysname, subsysnqn); + s = libnvme_lookup_subsystem(h, subsysname, subsysnqn); if (!s) return -ENOMEM; - ret = nvme_ctrl_alloc(ctx, s, path, name, &c); + ret = libnvme_ctrl_alloc(ctx, s, path, name, &c); if (ret) return ret; - ret = nvme_ctrl_scan_paths(ctx, c); + ret = libnvme_ctrl_scan_paths(ctx, c); if (ret) { - nvme_free_ctrl(c); + libnvme_free_ctrl(c); return ret; } - ret = nvme_ctrl_scan_namespaces(ctx, c); + ret = libnvme_ctrl_scan_namespaces(ctx, c); if (ret) { - nvme_free_ctrl(c); + libnvme_free_ctrl(c); return ret; } @@ -1997,22 +2032,22 @@ __public int nvme_scan_ctrl(struct nvme_global_ctx *ctx, const char *name, return 0; } -__public void nvme_rescan_ctrl(struct nvme_ctrl *c) +__public void libnvme_rescan_ctrl(struct libnvme_ctrl *c) { - struct nvme_global_ctx *ctx = c->s && c->s->h ? c->s->h->ctx : NULL; + struct libnvme_global_ctx *ctx = c->s && c->s->h ? c->s->h->ctx : NULL; if (!c->s) return; - nvme_ctrl_scan_namespaces(ctx, c); - nvme_ctrl_scan_paths(ctx, c); + libnvme_ctrl_scan_namespaces(ctx, c); + libnvme_ctrl_scan_paths(ctx, c); nvme_subsystem_scan_namespaces(ctx, c->s); } -static int nvme_bytes_to_lba(nvme_ns_t n, off_t offset, size_t count, - __u64 *lba, __u16 *nlb) +static int libnvme_bytes_to_lba(libnvme_ns_t n, off_t offset, size_t count, + __u64 *lba, __u16 *nlb) { int bs; - bs = nvme_ns_get_lba_size(n); + bs = libnvme_ns_get_lba_size(n); if (!count || offset & (bs - 1) || count & (bs - 1)) return -EINVAL; @@ -2022,17 +2057,17 @@ static int nvme_bytes_to_lba(nvme_ns_t n, off_t offset, size_t count, return 0; } -int nvme_ns_get_transport_handle(nvme_ns_t n, - struct nvme_transport_handle **hdl) +int libnvme_ns_get_transport_handle(libnvme_ns_t n, + struct libnvme_transport_handle **hdl) { int err; if (n->hdl) goto valid; - err = nvme_open(n->ctx, n->name, &n->hdl); + err = libnvme_open(n->ctx, n->name, &n->hdl); if (err) { - nvme_msg(n->ctx, LOG_ERR, "Failed to open ns %s, error %d\n", + libnvme_msg(n->ctx, LOG_ERR, "Failed to open ns %s, error %d\n", n->name, err); return err; } @@ -2042,238 +2077,244 @@ int nvme_ns_get_transport_handle(nvme_ns_t n, return 0; } -void nvme_ns_release_transport_handle(nvme_ns_t n) +void libnvme_ns_release_transport_handle(libnvme_ns_t n) { if (!n->hdl) return; - nvme_close(n->hdl); + libnvme_close(n->hdl); n->hdl = NULL; } -__public nvme_subsystem_t nvme_ns_get_subsystem(nvme_ns_t n) +__public libnvme_subsystem_t libnvme_ns_get_subsystem(libnvme_ns_t n) { return n->s; } -__public nvme_ctrl_t nvme_ns_get_ctrl(nvme_ns_t n) +__public libnvme_ctrl_t libnvme_ns_get_ctrl(libnvme_ns_t n) { return n->c; } -const char *nvme_ns_head_get_sysfs_dir(nvme_ns_head_t head) +const char *libnvme_ns_head_get_sysfs_dir(libnvme_ns_head_t head) { return head->sysfs_dir; } -__public const char *nvme_ns_get_generic_name(nvme_ns_t n) +__public const char *libnvme_ns_get_generic_name(libnvme_ns_t n) { return n->generic_name; } -__public const char *nvme_ns_get_model(nvme_ns_t n) +__public const char *libnvme_ns_get_model(libnvme_ns_t n) { return n->c ? n->c->model : n->s->model; } -__public const char *nvme_ns_get_serial(nvme_ns_t n) +__public const char *libnvme_ns_get_serial(libnvme_ns_t n) { return n->c ? n->c->serial : n->s->serial; } -__public const char *nvme_ns_get_firmware(nvme_ns_t n) +__public const char *libnvme_ns_get_firmware(libnvme_ns_t n) { return n->c ? n->c->firmware : n->s->firmware; } -__public enum nvme_csi nvme_ns_get_csi(nvme_ns_t n) +__public enum nvme_csi libnvme_ns_get_csi(libnvme_ns_t n) { return n->csi; } -__public const uint8_t *nvme_ns_get_eui64(nvme_ns_t n) +__public const uint8_t *libnvme_ns_get_eui64(libnvme_ns_t n) { return n->eui64; } -__public const uint8_t *nvme_ns_get_nguid(nvme_ns_t n) +__public const uint8_t *libnvme_ns_get_nguid(libnvme_ns_t n) { return n->nguid; } -__public void nvme_ns_get_uuid(nvme_ns_t n, unsigned char out[NVME_UUID_LEN]) +__public void libnvme_ns_get_uuid(libnvme_ns_t n, + unsigned char out[NVME_UUID_LEN]) { memcpy(out, n->uuid, NVME_UUID_LEN); } -__public int nvme_ns_identify(nvme_ns_t n, struct nvme_id_ns *ns) +__public int libnvme_ns_identify(libnvme_ns_t n, struct nvme_id_ns *ns) { - struct nvme_transport_handle *hdl; - struct nvme_passthru_cmd cmd; + struct libnvme_transport_handle *hdl; + struct libnvme_passthru_cmd cmd; int err; - err = nvme_ns_get_transport_handle(n, &hdl); + err = libnvme_ns_get_transport_handle(n, &hdl); if (err) return err; - nvme_init_identify_ns(&cmd, nvme_ns_get_nsid(n), ns); - return nvme_submit_admin_passthru(hdl, &cmd); + nvme_init_identify_ns(&cmd, libnvme_ns_get_nsid(n), ns); + return libnvme_submit_admin_passthru(hdl, &cmd); } -int nvme_ns_identify_descs(nvme_ns_t n, struct nvme_ns_id_desc *descs) +int libnvme_ns_identify_descs(libnvme_ns_t n, struct nvme_ns_id_desc *descs) { - struct nvme_transport_handle *hdl; - struct nvme_passthru_cmd cmd; + struct libnvme_transport_handle *hdl; + struct libnvme_passthru_cmd cmd; int err; - err = nvme_ns_get_transport_handle(n, &hdl); + err = libnvme_ns_get_transport_handle(n, &hdl); if (err) return err; - nvme_init_identify_ns_descs_list(&cmd, nvme_ns_get_nsid(n), descs); - return nvme_submit_admin_passthru(hdl, &cmd); + nvme_init_identify_ns_descs_list(&cmd, libnvme_ns_get_nsid(n), descs); + return libnvme_submit_admin_passthru(hdl, &cmd); } -__public int nvme_ns_verify(nvme_ns_t n, off_t offset, size_t count) +__public int libnvme_ns_verify(libnvme_ns_t n, off_t offset, size_t count) { - struct nvme_transport_handle *hdl; - struct nvme_passthru_cmd cmd; + struct libnvme_transport_handle *hdl; + struct libnvme_passthru_cmd cmd; __u64 slba; __u16 nlb; int err; - err = nvme_ns_get_transport_handle(n, &hdl); + err = libnvme_ns_get_transport_handle(n, &hdl); if (err) return err; - if (nvme_bytes_to_lba(n, offset, count, &slba, &nlb)) + if (libnvme_bytes_to_lba(n, offset, count, &slba, &nlb)) return -1; - nvme_init_verify(&cmd, nvme_ns_get_nsid(n), slba, nlb, + nvme_init_verify(&cmd, libnvme_ns_get_nsid(n), slba, nlb, 0, 0, NULL, 0, NULL, 0); - return nvme_submit_io_passthru(hdl, &cmd); + return libnvme_submit_io_passthru(hdl, &cmd); } -__public int nvme_ns_write_uncorrectable(nvme_ns_t n, off_t offset, size_t count) +__public int libnvme_ns_write_uncorrectable(libnvme_ns_t n, off_t offset, + size_t count) { - struct nvme_transport_handle *hdl; - struct nvme_passthru_cmd cmd; + struct libnvme_transport_handle *hdl; + struct libnvme_passthru_cmd cmd; __u64 slba; __u16 nlb; int err; - err = nvme_ns_get_transport_handle(n, &hdl); + err = libnvme_ns_get_transport_handle(n, &hdl); if (err) return err; - if (nvme_bytes_to_lba(n, offset, count, &slba, &nlb)) + if (libnvme_bytes_to_lba(n, offset, count, &slba, &nlb)) return -1; - nvme_init_write_uncorrectable(&cmd, nvme_ns_get_nsid(n), slba, nlb, + nvme_init_write_uncorrectable(&cmd, libnvme_ns_get_nsid(n), slba, nlb, 0, 0); - return nvme_submit_io_passthru(hdl, &cmd); + return libnvme_submit_io_passthru(hdl, &cmd); } -__public int nvme_ns_write_zeros(nvme_ns_t n, off_t offset, size_t count) +__public int libnvme_ns_write_zeros(libnvme_ns_t n, off_t offset, size_t count) { - struct nvme_transport_handle *hdl; - struct nvme_passthru_cmd cmd; + struct libnvme_transport_handle *hdl; + struct libnvme_passthru_cmd cmd; __u64 slba; __u16 nlb; int err; - err = nvme_ns_get_transport_handle(n, &hdl); + err = libnvme_ns_get_transport_handle(n, &hdl); if (err) return err; - if (nvme_bytes_to_lba(n, offset, count, &slba, &nlb)) + if (libnvme_bytes_to_lba(n, offset, count, &slba, &nlb)) return -1; - nvme_init_write_zeros(&cmd, nvme_ns_get_nsid(n), slba, nlb, 0, 0, 0, 0); + nvme_init_write_zeros(&cmd, libnvme_ns_get_nsid(n), + slba, nlb, 0, 0, 0, 0); - return nvme_submit_io_passthru(hdl, &cmd); + return libnvme_submit_io_passthru(hdl, &cmd); } -__public int nvme_ns_write(nvme_ns_t n, void *buf, off_t offset, size_t count) +__public int libnvme_ns_write(libnvme_ns_t n, void *buf, off_t offset, + size_t count) { - struct nvme_transport_handle *hdl; - struct nvme_passthru_cmd cmd; + struct libnvme_transport_handle *hdl; + struct libnvme_passthru_cmd cmd; __u64 slba; __u16 nlb; int err; - err = nvme_ns_get_transport_handle(n, &hdl); + err = libnvme_ns_get_transport_handle(n, &hdl); if (err) return err; - if (nvme_bytes_to_lba(n, offset, count, &slba, &nlb)) + if (libnvme_bytes_to_lba(n, offset, count, &slba, &nlb)) return -1; - nvme_init_write(&cmd, nvme_ns_get_nsid(n), slba, nlb, + nvme_init_write(&cmd, libnvme_ns_get_nsid(n), slba, nlb, 0, 0, 0, 0, buf, count, NULL, 0); - return nvme_submit_io_passthru(hdl, &cmd); + return libnvme_submit_io_passthru(hdl, &cmd); } -__public int nvme_ns_read(nvme_ns_t n, void *buf, off_t offset, size_t count) +__public int libnvme_ns_read(libnvme_ns_t n, void *buf, off_t offset, + size_t count) { - struct nvme_transport_handle *hdl; - struct nvme_passthru_cmd cmd; + struct libnvme_transport_handle *hdl; + struct libnvme_passthru_cmd cmd; __u64 slba; __u16 nlb; int err; - err = nvme_ns_get_transport_handle(n, &hdl); + err = libnvme_ns_get_transport_handle(n, &hdl); if (err) return err; - if (nvme_bytes_to_lba(n, offset, count, &slba, &nlb)) + if (libnvme_bytes_to_lba(n, offset, count, &slba, &nlb)) return -1; - nvme_init_read(&cmd, nvme_ns_get_nsid(n), slba, nlb, + nvme_init_read(&cmd, libnvme_ns_get_nsid(n), slba, nlb, 0, 0, 0, buf, count, NULL, 0); - return nvme_submit_io_passthru(hdl, &cmd); + return libnvme_submit_io_passthru(hdl, &cmd); } -__public int nvme_ns_compare(nvme_ns_t n, void *buf, off_t offset, size_t count) +__public int libnvme_ns_compare(libnvme_ns_t n, void *buf, off_t offset, + size_t count) { - struct nvme_transport_handle *hdl; - struct nvme_passthru_cmd cmd; + struct libnvme_transport_handle *hdl; + struct libnvme_passthru_cmd cmd; __u64 slba; __u16 nlb; int err; - err = nvme_ns_get_transport_handle(n, &hdl); + err = libnvme_ns_get_transport_handle(n, &hdl); if (err) return err; - if (nvme_bytes_to_lba(n, offset, count, &slba, &nlb)) + if (libnvme_bytes_to_lba(n, offset, count, &slba, &nlb)) return -1; - nvme_init_compare(&cmd, nvme_ns_get_nsid(n), slba, nlb, + nvme_init_compare(&cmd, libnvme_ns_get_nsid(n), slba, nlb, 0, 0, buf, count, NULL, 0); - return nvme_submit_io_passthru(hdl, &cmd); + return libnvme_submit_io_passthru(hdl, &cmd); } -__public int nvme_ns_flush(nvme_ns_t n) +__public int libnvme_ns_flush(libnvme_ns_t n) { - struct nvme_transport_handle *hdl; - struct nvme_passthru_cmd cmd; + struct libnvme_transport_handle *hdl; + struct libnvme_passthru_cmd cmd; int err; - err = nvme_ns_get_transport_handle(n, &hdl); + err = libnvme_ns_get_transport_handle(n, &hdl); if (err) return err; - nvme_init_flush(&cmd, nvme_ns_get_nsid(n)); - return nvme_submit_io_passthru(hdl, &cmd); + nvme_init_flush(&cmd, libnvme_ns_get_nsid(n)); + return libnvme_submit_io_passthru(hdl, &cmd); } -static int nvme_strtou64(const char *str, void *res) +static int libnvme_strtou64(const char *str, void *res) { char *endptr; __u64 v; @@ -2293,7 +2334,7 @@ static int nvme_strtou64(const char *str, void *res) return 0; } -static int nvme_strtou32(const char *str, void *res) +static int libnvme_strtou32(const char *str, void *res) { char *endptr; __u32 v; @@ -2313,7 +2354,7 @@ static int nvme_strtou32(const char *str, void *res) return 0; } -static int nvme_strtoi(const char *str, void *res) +static int libnvme_strtoi(const char *str, void *res) { char *endptr; int v; @@ -2333,13 +2374,13 @@ static int nvme_strtoi(const char *str, void *res) return 0; } -static int nvme_strtoeuid(const char *str, void *res) +static int libnvme_strtoeuid(const char *str, void *res) { memcpy(res, str, 8); return 0; } -static int nvme_strtouuid(const char *str, void *res) +static int libnvme_strtouuid(const char *str, void *res) { memcpy(res, str, NVME_UUID_LEN); return 0; @@ -2363,7 +2404,7 @@ static int parse_attrs(const char *path, struct sysfs_attr_table *tbl, int size) for (i = 0; i < size; i++) { struct sysfs_attr_table *e = &tbl[i]; - str = nvme_get_attr(path, e->name); + str = libnvme_get_attr(path, e->name); if (!str) { if (!e->mandatory) continue; @@ -2378,7 +2419,7 @@ static int parse_attrs(const char *path, struct sysfs_attr_table *tbl, int size) return 0; } -static int nvme_ns_init(const char *path, struct nvme_ns *ns) +static int libnvme_ns_init(const char *path, struct libnvme_ns *ns) { _cleanup_free_ char *attr = NULL; struct stat sb; @@ -2386,12 +2427,12 @@ static int nvme_ns_init(const char *path, struct nvme_ns *ns) int ret; struct sysfs_attr_table base[] = { - { &ns->nsid, nvme_strtou32, true, "nsid" }, - { &size, nvme_strtou64, true, "size" }, - { &ns->lba_size, nvme_strtou32, true, "queue/logical_block_size" }, - { ns->eui64, nvme_strtoeuid, false, "eui" }, - { ns->nguid, nvme_strtouuid, false, "nguid" }, - { ns->uuid, nvme_strtouuid, false, "uuid" } + { &ns->nsid, libnvme_strtou32, true, "nsid" }, + { &size, libnvme_strtou64, true, "size" }, + { &ns->lba_size, libnvme_strtou32, true, "queue/logical_block_size" }, + { ns->eui64, libnvme_strtoeuid, false, "eui" }, + { ns->nguid, libnvme_strtouuid, false, "nguid" }, + { ns->uuid, libnvme_strtouuid, false, "uuid" } }; ret = parse_attrs(path, base, ARRAY_SIZE(base)); @@ -2412,9 +2453,9 @@ static int nvme_ns_init(const char *path, struct nvme_ns *ns) if (ret == 0) { /* only available on kernels >= 6.8 */ struct sysfs_attr_table ext[] = { - { &ns->csi, nvme_strtoi, true, "csi" }, - { &ns->lba_util, nvme_strtou64, true, "nuse" }, - { &ns->meta_size, nvme_strtoi, true, "metadata_bytes"}, + { &ns->csi, libnvme_strtoi, true, "csi" }, + { &ns->lba_util, libnvme_strtou64, true, "nuse" }, + { &ns->meta_size, libnvme_strtoi, true, "metadata_bytes"}, }; @@ -2425,11 +2466,11 @@ static int nvme_ns_init(const char *path, struct nvme_ns *ns) _cleanup_free_ struct nvme_id_ns *id = NULL; uint8_t flbas; - id = __nvme_alloc(sizeof(*ns)); + id = __libnvme_alloc(sizeof(*ns)); if (!id) return -ENOMEM; - ret = nvme_ns_identify(ns, id); + ret = libnvme_ns_identify(ns, id); if (ret) return ret; @@ -2442,7 +2483,7 @@ static int nvme_ns_init(const char *path, struct nvme_ns *ns) return 0; } -static void nvme_ns_set_generic_name(struct nvme_ns *n, const char *name) +static void libnvme_ns_set_generic_name(struct libnvme_ns *n, const char *name) { char generic_name[PATH_MAX]; int instance, head_instance; @@ -2456,12 +2497,12 @@ static void nvme_ns_set_generic_name(struct nvme_ns *n, const char *name) n->generic_name = strdup(generic_name); } -static int nvme_ns_open(struct nvme_global_ctx *ctx, const char *sys_path, - const char *name, nvme_ns_t *ns) +static int libnvme_ns_open(struct libnvme_global_ctx *ctx, const char *sys_path, + const char *name, libnvme_ns_t *ns) { int ret; - struct nvme_ns *n; - struct nvme_ns_head *head; + struct libnvme_ns *n; + struct libnvme_ns_head *head; struct stat arg; _cleanup_free_ char *path = NULL; @@ -2499,15 +2540,15 @@ static int nvme_ns_open(struct nvme_global_ctx *ctx, const char *sys_path, n->hdl = NULL; n->name = strdup(name); - nvme_ns_set_generic_name(n, name); + libnvme_ns_set_generic_name(n, name); - ret = nvme_ns_init(sys_path, n); + ret = libnvme_ns_init(sys_path, n); if (ret) goto free_ns; list_node_init(&n->entry); - nvme_ns_release_transport_handle(n); + libnvme_ns_release_transport_handle(n); *ns = n; return 0; @@ -2521,7 +2562,7 @@ static int nvme_ns_open(struct nvme_global_ctx *ctx, const char *sys_path, return ret; } -static inline bool nvme_ns_is_generic(const char *name) +static inline bool libnvme_ns_is_generic(const char *name) { int instance, head_instance; @@ -2530,13 +2571,13 @@ static inline bool nvme_ns_is_generic(const char *name) return true; } -static char *nvme_ns_generic_to_blkdev(const char *generic) +static char *libnvme_ns_generic_to_blkdev(const char *generic) { int instance, head_instance; char blkdev[PATH_MAX]; - if (!nvme_ns_is_generic(generic)) + if (!libnvme_ns_is_generic(generic)) return strdup(generic); sscanf(generic, "ng%dn%d", &instance, &head_instance); @@ -2545,15 +2586,15 @@ static char *nvme_ns_generic_to_blkdev(const char *generic) return strdup(blkdev); } -static int __nvme_scan_namespace(struct nvme_global_ctx *ctx, - const char *sysfs_dir, const char *name, nvme_ns_t *ns) +static int __libnvme_scan_namespace(struct libnvme_global_ctx *ctx, + const char *sysfs_dir, const char *name, libnvme_ns_t *ns) { _cleanup_free_ char *blkdev = NULL; _cleanup_free_ char *path = NULL; - struct nvme_ns *n = NULL; + struct libnvme_ns *n = NULL; int ret; - blkdev = nvme_ns_generic_to_blkdev(name); + blkdev = libnvme_ns_generic_to_blkdev(name); if (!blkdev) return -ENOMEM; @@ -2561,7 +2602,7 @@ static int __nvme_scan_namespace(struct nvme_global_ctx *ctx, if (ret < 0) return -ENOMEM; - ret = nvme_ns_open(ctx, path, blkdev, &n); + ret = libnvme_ns_open(ctx, path, blkdev, &n); if (ret) return ret; @@ -2572,21 +2613,22 @@ static int __nvme_scan_namespace(struct nvme_global_ctx *ctx, return 0; } -__public int nvme_scan_namespace(struct nvme_global_ctx *ctx, const char *name, - nvme_ns_t *ns) +__public int libnvme_scan_namespace(struct libnvme_global_ctx *ctx, + const char *name, libnvme_ns_t *ns) { - return __nvme_scan_namespace(ctx, nvme_ns_sysfs_dir(), name, ns); + return __libnvme_scan_namespace(ctx, libnvme_ns_sysfs_dir(), name, ns); } -static void nvme_ns_head_scan_path(nvme_subsystem_t s, nvme_ns_t n, char *name) +static void libnvme_ns_head_scan_path(libnvme_subsystem_t s, + libnvme_ns_t n, char *name) { - nvme_ctrl_t c; - nvme_path_t p; + libnvme_ctrl_t c; + libnvme_path_t p; - nvme_subsystem_for_each_ctrl(s, c) { - nvme_ctrl_for_each_path(c, p) { - if (!strcmp(nvme_path_get_name(p), name)) { + libnvme_subsystem_for_each_ctrl(s, c) { + libnvme_ctrl_for_each_path(c, p) { + if (!strcmp(libnvme_path_get_name(p), name)) { list_add_tail(&n->head->paths, &p->nentry); p->n = n; return; @@ -2595,11 +2637,11 @@ static void nvme_ns_head_scan_path(nvme_subsystem_t s, nvme_ns_t n, char *name) } } -static void nvme_subsystem_set_ns_path(nvme_subsystem_t s, nvme_ns_t n) +static void libnvme_subsystem_set_ns_path(libnvme_subsystem_t s, libnvme_ns_t n) { - struct nvme_ns_head *head = n->head; + struct libnvme_ns_head *head = n->head; - if (nvme_ns_head_get_sysfs_dir(head)) { + if (libnvme_ns_head_get_sysfs_dir(head)) { struct dirents paths = {}; int i; @@ -2607,29 +2649,29 @@ static void nvme_subsystem_set_ns_path(nvme_subsystem_t s, nvme_ns_t n) * When multipath is configured on kernel version >= 6.15, * we use multipath sysfs link to get each path of a namespace. */ - paths.num = nvme_scan_ns_head_paths(head, &paths.ents); + paths.num = libnvme_scan_ns_head_paths(head, &paths.ents); for (i = 0; i < paths.num; i++) - nvme_ns_head_scan_path(s, n, paths.ents[i]->d_name); + libnvme_ns_head_scan_path(s, n, paths.ents[i]->d_name); } else { - nvme_ctrl_t c; - nvme_path_t p; + libnvme_ctrl_t c; + libnvme_path_t p; int ns_ctrl, ns_nsid, ret; /* * If multipath is not configured or we're running on kernel * version < 6.15, fallback to the old way. */ - ret = sscanf(nvme_ns_get_name(n), "nvme%dn%d", + ret = sscanf(libnvme_ns_get_name(n), "nvme%dn%d", &ns_ctrl, &ns_nsid); if (ret != 2) return; - nvme_subsystem_for_each_ctrl(s, c) { - nvme_ctrl_for_each_path(c, p) { + libnvme_subsystem_for_each_ctrl(s, c) { + libnvme_ctrl_for_each_path(c, p) { int p_subsys, p_ctrl, p_nsid; - ret = sscanf(nvme_path_get_name(p), + ret = sscanf(libnvme_path_get_name(p), "nvme%dc%dn%d", &p_subsys, &p_ctrl, &p_nsid); if (ret != 3) @@ -2643,24 +2685,24 @@ static void nvme_subsystem_set_ns_path(nvme_subsystem_t s, nvme_ns_t n) } } -static int nvme_ctrl_scan_namespace(struct nvme_global_ctx *ctx, struct nvme_ctrl *c, - char *name) +static int libnvme_ctrl_scan_namespace(struct libnvme_global_ctx *ctx, + struct libnvme_ctrl *c, char *name) { - struct nvme_ns *n, *_n, *__n; + struct libnvme_ns *n, *_n, *__n; int ret; - nvme_msg(ctx, LOG_DEBUG, "scan controller %s namespace %s\n", + libnvme_msg(ctx, LOG_DEBUG, "scan controller %s namespace %s\n", c->name, name); if (!c->s) { - nvme_msg(ctx, LOG_DEBUG, "no subsystem for %s\n", name); + libnvme_msg(ctx, LOG_DEBUG, "no subsystem for %s\n", name); return -EINVAL; } - ret = __nvme_scan_namespace(ctx, c->sysfs_dir, name, &n); + ret = __libnvme_scan_namespace(ctx, c->sysfs_dir, name, &n); if (ret) { - nvme_msg(ctx, LOG_DEBUG, "failed to scan namespace %s\n", name); + libnvme_msg(ctx, LOG_DEBUG, "failed to scan namespace %s\n", name); return ret; } - nvme_ctrl_for_each_ns_safe(c, _n, __n) { + libnvme_ctrl_for_each_ns_safe(c, _n, __n) { if (strcmp(n->name, _n->name)) continue; __nvme_free_ns(_n); @@ -2668,42 +2710,42 @@ static int nvme_ctrl_scan_namespace(struct nvme_global_ctx *ctx, struct nvme_ctr n->s = c->s; n->c = c; list_add_tail(&c->namespaces, &n->entry); - nvme_subsystem_set_ns_path(c->s, n); + libnvme_subsystem_set_ns_path(c->s, n); return 0; } -static int nvme_subsystem_scan_namespace(struct nvme_global_ctx *ctx, nvme_subsystem_t s, - char *name) +static int libnvme_subsystem_scan_namespace(struct libnvme_global_ctx *ctx, + libnvme_subsystem_t s, char *name) { - struct nvme_ns *n, *_n, *__n; + struct libnvme_ns *n, *_n, *__n; int ret; - nvme_msg(ctx, LOG_DEBUG, "scan subsystem %s namespace %s\n", + libnvme_msg(ctx, LOG_DEBUG, "scan subsystem %s namespace %s\n", s->name, name); - ret = __nvme_scan_namespace(ctx, s->sysfs_dir, name, &n); + ret = __libnvme_scan_namespace(ctx, s->sysfs_dir, name, &n); if (ret) { - nvme_msg(ctx, LOG_DEBUG, "failed to scan namespace %s\n", name); + libnvme_msg(ctx, LOG_DEBUG, "failed to scan namespace %s\n", name); return ret; } - nvme_subsystem_for_each_ns_safe(s, _n, __n) { + libnvme_subsystem_for_each_ns_safe(s, _n, __n) { if (strcmp(n->name, _n->name)) continue; __nvme_free_ns(_n); } n->s = s; list_add_tail(&s->namespaces, &n->entry); - nvme_subsystem_set_ns_path(s, n); + libnvme_subsystem_set_ns_path(s, n); return 0; } -__public struct nvme_ns *nvme_subsystem_lookup_namespace(struct nvme_subsystem *s, - __u32 nsid) +__public struct libnvme_ns *libnvme_subsystem_lookup_namespace( + struct libnvme_subsystem *s, __u32 nsid) { - struct nvme_ns *n; + struct libnvme_ns *n; - nvme_subsystem_for_each_ns(s, n) { - if (nvme_ns_get_nsid(n) == nsid) + libnvme_subsystem_for_each_ns(s, n) { + if (libnvme_ns_get_nsid(n) == nsid) return n; } return NULL; diff --git a/libnvme/src/nvme/tree.h b/libnvme/src/nvme/tree.h index 07b75677cd..e59b09c052 100644 --- a/libnvme/src/nvme/tree.h +++ b/libnvme/src/nvme/tree.h @@ -20,124 +20,125 @@ * libnvme tree object interface */ -typedef struct nvme_ns *nvme_ns_t; -typedef struct nvme_ns_head *nvme_ns_head_t; -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 libnvme_ns *libnvme_ns_t; +typedef struct libnvme_ns_head *libnvme_ns_head_t; +typedef struct libnvme_path *libnvme_path_t; +typedef struct libnvme_ctrl *libnvme_ctrl_t; +typedef struct libnvme_subsystem *libnvme_subsystem_t; +typedef struct libnvme_host *libnvme_host_t; -typedef bool (*nvme_scan_filter_t)(nvme_subsystem_t, nvme_ctrl_t, - nvme_ns_t, void *); +typedef bool (*libnvme_scan_filter_t)(libnvme_subsystem_t, libnvme_ctrl_t, + libnvme_ns_t, void *); /** - * nvme_set_application - Specify managing application - * @ctx: struct nvme_global_ctx object + * libnvme_set_application - Specify managing application + * @ctx: struct libnvme_global_ctx object * @a: Application string * * Sets the managing application string for @r. */ -void nvme_set_application(struct nvme_global_ctx *ctx, const char *a); +void libnvme_set_application(struct libnvme_global_ctx *ctx, const char *a); /** - * nvme_get_application - Get managing application - * @ctx: struct nvme_global_ctx object + * libnvme_get_application - Get managing application + * @ctx: struct libnvme_global_ctx object * * Returns the managing application string for @r or NULL if not set. */ -const char *nvme_get_application(struct nvme_global_ctx *ctx); +const char *libnvme_get_application(struct libnvme_global_ctx *ctx); /** - * nvme_skip_namespaces - Skip namespace scanning - * @ctx: struct nvme_global_ctx object + * libnvme_skip_namespaces - Skip namespace scanning + * @ctx: struct libnvme_global_ctx object * * Sets a flag to skip namespaces during scanning. */ -void nvme_skip_namespaces(struct nvme_global_ctx *ctx); +void libnvme_skip_namespaces(struct libnvme_global_ctx *ctx); /** - * nvme_release_fds - Close all opened file descriptors in the tree - * @ctx: struct nvme_global_ctx object + * libnvme_release_fds - Close all opened file descriptors in the tree + * @ctx: struct libnvme_global_ctx object * * Controller and Namespace objects cache the file descriptors * of opened nvme devices. This API can be used to close and * clear all cached fds in the tree. * */ -void nvme_release_fds(struct nvme_global_ctx *ctx); +void libnvme_release_fds(struct libnvme_global_ctx *ctx); /** - * nvme_first_host() - Start host iterator - * @ctx: struct nvme_global_ctx object + * libnvme_first_host() - Start host iterator + * @ctx: struct libnvme_global_ctx object * - * Return: First &nvme_host_t object in an iterator + * Return: First &libnvme_host_t object in an iterator */ -nvme_host_t nvme_first_host(struct nvme_global_ctx *ctx); +libnvme_host_t libnvme_first_host(struct libnvme_global_ctx *ctx); /** - * nvme_next_host() - Next host iterator - * @ctx: struct nvme_global_ctx object - * @h: Previous &nvme_host_t iterator + * libnvme_next_host() - Next host iterator + * @ctx: struct libnvme_global_ctx object + * @h: Previous &libnvme_host_t iterator * - * Return: Next &nvme_host_t object in an iterator + * Return: Next &libnvme_host_t object in an iterator */ -nvme_host_t nvme_next_host(struct nvme_global_ctx *ctx, nvme_host_t h); +libnvme_host_t libnvme_next_host(struct libnvme_global_ctx *ctx, + libnvme_host_t h); /** - * nvme_host_get_global_ctx() - Returns nvme_global_ctx object - * @h: &nvme_host_t object + * libnvme_host_get_global_ctx() - Returns libnvme_global_ctx object + * @h: &libnvme_host_t object * - * Return: &struct nvme_global_ctx object from @h + * Return: &struct libnvme_global_ctx object from @h */ -struct nvme_global_ctx *nvme_host_get_global_ctx(nvme_host_t h); +struct libnvme_global_ctx *libnvme_host_get_global_ctx(libnvme_host_t h); /** - * nvme_host_set_pdc_enabled() - Set Persistent Discovery Controller flag + * libnvme_host_set_pdc_enabled() - Set Persistent Discovery Controller flag * @h: Host for which the falg should be set * @enabled: The bool to set the enabled flag * - * When nvme_host_set_pdc_enabled() is not used to set the PDC flag, - * nvme_host_is_pdc_enabled() will return the default value which was + * When libnvme_host_set_pdc_enabled() is not used to set the PDC flag, + * libnvme_host_is_pdc_enabled() will return the default value which was * passed into the function and not the undefined flag value. */ -void nvme_host_set_pdc_enabled(nvme_host_t h, bool enabled); +void libnvme_host_set_pdc_enabled(libnvme_host_t h, bool enabled); /** - * nvme_host_is_pdc_enabled() - Is Persistenct Discovery Controller enabled + * libnvme_host_is_pdc_enabled() - Is Persistenct Discovery Controller enabled * @h: Host which to check if PDC is enabled * @fallback: The fallback default value of the flag when - * @nvme_host_set_pdc_enabled has not be used + * @libnvme_host_set_pdc_enabled has not be used * to set the flag. * * Return: true if PDC is enabled for @h, else false */ -bool nvme_host_is_pdc_enabled(nvme_host_t h, bool fallback); +bool libnvme_host_is_pdc_enabled(libnvme_host_t h, bool fallback); /** - * nvme_get_host() - Returns a host object - * @ctx: struct nvme_global_ctx object + * libnvme_get_host() - Returns a host object + * @ctx: struct libnvme_global_ctx object * @hostnqn: Host NQN (optional) * @hostid: Host ID (optional) - * @h: &nvme_host_t object to return + * @h: &libnvme_host_t object to return * * Returns a host object based on the hostnqn/hostid values or the default if * hostnqn/hostid are NULL. * * Return: 0 on success or negative error code otherwise */ -int nvme_get_host(struct nvme_global_ctx *ctx, const char *hostnqn, - const char *hostid, nvme_host_t *h); +int libnvme_get_host(struct libnvme_global_ctx *ctx, const char *hostnqn, + const char *hostid, libnvme_host_t *h); /** - * nvme_host_get_ids - Retrieve host ids from various sources + * libnvme_host_get_ids - Retrieve host ids from various sources * - * @ctx: struct nvme_global_ctx object + * @ctx: struct libnvme_global_ctx object * @hostnqn_arg: Input hostnqn (command line) argument * @hostid_arg: Input hostid (command line) argument * @hostnqn: Output hostnqn * @hostid: Output hostid * - * nvme_host_get_ids figures out which hostnqn/hostid is to be used. + * libnvme_host_get_ids figures out which hostnqn/hostid is to be used. * There are several sources where this information can be retrieved. * * The order is: @@ -159,129 +160,131 @@ int nvme_get_host(struct nvme_global_ctx *ctx, const char *hostnqn, * Return: 0 on success (@hostnqn and @hostid contain valid strings * which the caller needs to free), or negative error code otherwise. */ -int nvme_host_get_ids(struct nvme_global_ctx *ctx, +int libnvme_host_get_ids(struct libnvme_global_ctx *ctx, const char *hostnqn_arg, const char *hostid_arg, char **hostnqn, char **hostid); /** - * nvme_first_subsystem() - Start subsystem iterator - * @h: &nvme_host_t object + * libnvme_first_subsystem() - Start subsystem iterator + * @h: &libnvme_host_t object * - * Return: first &nvme_subsystem_t object in an iterator + * Return: first &libnvme_subsystem_t object in an iterator */ -nvme_subsystem_t nvme_first_subsystem(nvme_host_t h); +libnvme_subsystem_t libnvme_first_subsystem(libnvme_host_t h); /** - * nvme_next_subsystem() - Next subsystem iterator - * @h: &nvme_host_t object - * @s: Previous &nvme_subsystem_t iterator + * libnvme_next_subsystem() - Next subsystem iterator + * @h: &libnvme_host_t object + * @s: Previous &libnvme_subsystem_t iterator * - * Return: next &nvme_subsystem_t object in an iterator + * Return: next &libnvme_subsystem_t object in an iterator */ -nvme_subsystem_t nvme_next_subsystem(nvme_host_t h, nvme_subsystem_t s); +libnvme_subsystem_t libnvme_next_subsystem(libnvme_host_t h, + libnvme_subsystem_t s); /** - * nvme_get_subsystem() - Returns nvme_subsystem_t object - * @ctx: struct nvme_global_ctx object - * @h: &nvme_host_t object + * libnvme_get_subsystem() - Returns libnvme_subsystem_t object + * @ctx: struct libnvme_global_ctx object + * @h: &libnvme_host_t object * @name: Name of the subsystem (may be NULL) * @subsysnqn: Subsystem NQN - * @s: nvme_subsystem_t object + * @s: libnvme_subsystem_t object * - * Returns an &nvme_subsystem_t object in @h base on @name (if present) + * Returns an &libnvme_subsystem_t object in @h base on @name (if present) * and @subsysnqn or create one if not found. * */ -int nvme_get_subsystem(struct nvme_global_ctx *ctx, - struct nvme_host *h, const char *name, - const char *subsysnqn, struct nvme_subsystem **s); +int libnvme_get_subsystem(struct libnvme_global_ctx *ctx, + struct libnvme_host *h, const char *name, + const char *subsysnqn, struct libnvme_subsystem **s); /** - * nvme_free_subsystem() - Free a subsystem + * libnvme_free_subsystem() - Free a subsystem * @s: subsystem * * Frees @s and all related objects. */ -void nvme_free_subsystem(struct nvme_subsystem *s); +void libnvme_free_subsystem(struct libnvme_subsystem *s); /** - * nvme_subsystem_get_host() - Returns nvme_host_t object + * libnvme_subsystem_get_host() - Returns libnvme_host_t object * @s: subsystem * - * Return: &nvme_host_t object from @s + * Return: &libnvme_host_t object from @s */ -nvme_host_t nvme_subsystem_get_host(nvme_subsystem_t s); +libnvme_host_t libnvme_subsystem_get_host(libnvme_subsystem_t s); /** - * nvme_ctrl_first_ns() - Start namespace iterator + * libnvme_ctrl_first_ns() - Start namespace iterator * @c: Controller instance * - * Return: First &nvme_ns_t object of an @c iterator + * Return: First &libnvme_ns_t object of an @c iterator */ -nvme_ns_t nvme_ctrl_first_ns(nvme_ctrl_t c); +libnvme_ns_t libnvme_ctrl_first_ns(libnvme_ctrl_t c); /** - * nvme_ctrl_next_ns() - Next namespace iterator + * libnvme_ctrl_next_ns() - Next namespace iterator * @c: Controller instance - * @n: Previous nvme_ns_t iterator + * @n: Previous libnvme_ns_t iterator * - * Return: Next nvme_ns_t object of an @c iterator + * Return: Next libnvme_ns_t object of an @c iterator */ -nvme_ns_t nvme_ctrl_next_ns(nvme_ctrl_t c, nvme_ns_t n); +libnvme_ns_t libnvme_ctrl_next_ns(libnvme_ctrl_t c, libnvme_ns_t n); /** - * nvme_ctrl_first_path() - Start path iterator + * libnvme_ctrl_first_path() - Start path iterator * @c: Controller instance * - * Return: First &nvme_path_t object of an @c iterator + * Return: First &libnvme_path_t object of an @c iterator */ -nvme_path_t nvme_ctrl_first_path(nvme_ctrl_t c); +libnvme_path_t libnvme_ctrl_first_path(libnvme_ctrl_t c); /** - * nvme_ctrl_next_path() - Next path iterator + * libnvme_ctrl_next_path() - Next path iterator * @c: Controller instance - * @p: Previous &nvme_path_t object of an @c iterator + * @p: Previous &libnvme_path_t object of an @c iterator * - * Return: Next &nvme_path_t object of an @c iterator + * Return: Next &libnvme_path_t object of an @c iterator */ -nvme_path_t nvme_ctrl_next_path(nvme_ctrl_t c, nvme_path_t p); +libnvme_path_t libnvme_ctrl_next_path(libnvme_ctrl_t c, libnvme_path_t p); /** - * nvme_subsystem_first_ctrl() - First ctrl iterator - * @s: &nvme_subsystem_t object + * libnvme_subsystem_first_ctrl() - First ctrl iterator + * @s: &libnvme_subsystem_t object * * Return: First controller of an @s iterator */ -nvme_ctrl_t nvme_subsystem_first_ctrl(nvme_subsystem_t s); +libnvme_ctrl_t libnvme_subsystem_first_ctrl(libnvme_subsystem_t s); /** - * nvme_subsystem_next_ctrl() - Next ctrl iterator - * @s: &nvme_subsystem_t object + * libnvme_subsystem_next_ctrl() - Next ctrl iterator + * @s: &libnvme_subsystem_t object * @c: Previous controller instance of an @s iterator * * Return: Next controller of an @s iterator */ -nvme_ctrl_t nvme_subsystem_next_ctrl(nvme_subsystem_t s, nvme_ctrl_t c); +libnvme_ctrl_t libnvme_subsystem_next_ctrl(libnvme_subsystem_t s, + libnvme_ctrl_t c); /** - * nvme_namespace_first_path() - Start path iterator + * libnvme_namespace_first_path() - Start path iterator * @ns: Namespace instance * - * Return: First &nvme_path_t object of an @ns iterator + * Return: First &libnvme_path_t object of an @ns iterator */ -nvme_path_t nvme_namespace_first_path(nvme_ns_t ns); +libnvme_path_t libnvme_namespace_first_path(libnvme_ns_t ns); /** - * nvme_namespace_next_path() - Next path iterator + * libnvme_namespace_next_path() - Next path iterator * @ns: Namespace instance - * @p: Previous &nvme_path_t object of an @ns iterator + * @p: Previous &libnvme_path_t object of an @ns iterator * - * Return: Next &nvme_path_t object of an @ns iterator + * Return: Next &libnvme_path_t object of an @ns iterator */ -nvme_path_t nvme_namespace_next_path(nvme_ns_t ns, nvme_path_t p); +libnvme_path_t libnvme_namespace_next_path(libnvme_ns_t ns, libnvme_path_t p); /** - * nvme_ctrl_match_config() - Check if ctrl @c matches config params + * libnvme_ctrl_match_config() - Check if ctrl @c matches config params * @c: An existing controller instance * @transport: Transport name * @traddr: Transport address @@ -296,288 +299,288 @@ nvme_path_t nvme_namespace_next_path(nvme_ns_t ns, nvme_path_t p); * * Return: true if there's a match, false otherwise. */ -bool nvme_ctrl_match_config(struct nvme_ctrl *c, const char *transport, +bool libnvme_ctrl_match_config(struct libnvme_ctrl *c, const char *transport, const char *traddr, const char *trsvcid, const char *subsysnqn, const char *host_traddr, const char *host_iface); /** - * nvme_create_ctrl() - Allocate an unconnected NVMe controller - * @ctx: struct nvme_global_ctx object + * libnvme_create_ctrl() - Allocate an unconnected NVMe controller + * @ctx: struct libnvme_global_ctx object * @subsysnqn: Subsystem NQN * @transport: Transport type * @traddr: Transport address * @host_traddr: Host transport address * @host_iface: Host interface name * @trsvcid: Transport service ID - * @c: @nvme_ctrl_t object to return + * @c: @libnvme_ctrl_t object to return * - * Creates an unconnected controller to be used for nvme_add_ctrl(). + * Creates an unconnected controller to be used for libnvme_add_ctrl(). * * Return: 0 on success or negative error code otherwise */ -int nvme_create_ctrl(struct nvme_global_ctx *ctx, +int libnvme_create_ctrl(struct libnvme_global_ctx *ctx, const char *subsysnqn, const char *transport, const char *traddr, const char *host_traddr, const char *host_iface, const char *trsvcid, - nvme_ctrl_t *c); + libnvme_ctrl_t *c); /** - * nvme_subsystem_first_ns() - Start namespace iterator - * @s: &nvme_subsystem_t object + * libnvme_subsystem_first_ns() - Start namespace iterator + * @s: &libnvme_subsystem_t object * - * Return: First &nvme_ns_t object of an @s iterator + * Return: First &libnvme_ns_t object of an @s iterator */ -nvme_ns_t nvme_subsystem_first_ns(nvme_subsystem_t s); +libnvme_ns_t libnvme_subsystem_first_ns(libnvme_subsystem_t s); /** - * nvme_subsystem_next_ns() - Next namespace iterator - * @s: &nvme_subsystem_t object - * @n: Previous &nvme_ns_t iterator + * libnvme_subsystem_next_ns() - Next namespace iterator + * @s: &libnvme_subsystem_t object + * @n: Previous &libnvme_ns_t iterator * - * Return: Next &nvme_ns_t object of an @s iterator + * Return: Next &libnvme_ns_t object of an @s iterator */ -nvme_ns_t nvme_subsystem_next_ns(nvme_subsystem_t s, nvme_ns_t n); +libnvme_ns_t libnvme_subsystem_next_ns(libnvme_subsystem_t s, libnvme_ns_t n); /** - * nvme_for_each_host_safe() - Traverse host list - * @r: &nvme_root_t object - * @h: &nvme_host_t object - * @_h: Temporary &nvme_host_t object + * libnvme_for_each_host_safe() - Traverse host list + * @r: &libnvme_root_t object + * @h: &libnvme_host_t object + * @_h: Temporary &libnvme_host_t object */ -#define nvme_for_each_host_safe(r, h, _h) \ - for (h = nvme_first_host(r), \ - _h = nvme_next_host(r, h); \ +#define libnvme_for_each_host_safe(r, h, _h) \ + for (h = libnvme_first_host(r), \ + _h = libnvme_next_host(r, h); \ h != NULL; \ - h = _h, _h = nvme_next_host(r, h)) + h = _h, _h = libnvme_next_host(r, h)) /** - * nvme_for_each_host() - Traverse host list - * @r: &nvme_root_t object - * @h: &nvme_host_t object + * libnvme_for_each_host() - Traverse host list + * @r: &libnvme_root_t object + * @h: &libnvme_host_t object */ -#define nvme_for_each_host(r, h) \ - for (h = nvme_first_host(r); h != NULL; \ - h = nvme_next_host(r, h)) +#define libnvme_for_each_host(r, h) \ + for (h = libnvme_first_host(r); h != NULL; \ + h = libnvme_next_host(r, h)) /** - * nvme_for_each_subsystem_safe() - Traverse subsystems - * @h: &nvme_host_t object - * @s: &nvme_subsystem_t object - * @_s: Temporary &nvme_subsystem_t object + * libnvme_for_each_subsystem_safe() - Traverse subsystems + * @h: &libnvme_host_t object + * @s: &libnvme_subsystem_t object + * @_s: Temporary &libnvme_subsystem_t object */ -#define nvme_for_each_subsystem_safe(h, s, _s) \ - for (s = nvme_first_subsystem(h), \ - _s = nvme_next_subsystem(h, s); \ +#define libnvme_for_each_subsystem_safe(h, s, _s) \ + for (s = libnvme_first_subsystem(h), \ + _s = libnvme_next_subsystem(h, s); \ s != NULL; \ - s = _s, _s = nvme_next_subsystem(h, s)) + s = _s, _s = libnvme_next_subsystem(h, s)) /** - * nvme_for_each_subsystem() - Traverse subsystems - * @h: &nvme_host_t object - * @s: &nvme_subsystem_t object + * libnvme_for_each_subsystem() - Traverse subsystems + * @h: &libnvme_host_t object + * @s: &libnvme_subsystem_t object */ -#define nvme_for_each_subsystem(h, s) \ - for (s = nvme_first_subsystem(h); s != NULL; \ - s = nvme_next_subsystem(h, s)) +#define libnvme_for_each_subsystem(h, s) \ + for (s = libnvme_first_subsystem(h); s != NULL; \ + s = libnvme_next_subsystem(h, s)) /** - * nvme_subsystem_for_each_ctrl_safe() - Traverse controllers - * @s: &nvme_subsystem_t object + * libnvme_subsystem_for_each_ctrl_safe() - Traverse controllers + * @s: &libnvme_subsystem_t object * @c: Controller instance - * @_c: A &nvme_ctrl_t_node to use as temporary storage + * @_c: A &libnvme_ctrl_t_node to use as temporary storage */ -#define nvme_subsystem_for_each_ctrl_safe(s, c, _c) \ - for (c = nvme_subsystem_first_ctrl(s), \ - _c = nvme_subsystem_next_ctrl(s, c); \ +#define libnvme_subsystem_for_each_ctrl_safe(s, c, _c) \ + for (c = libnvme_subsystem_first_ctrl(s), \ + _c = libnvme_subsystem_next_ctrl(s, c); \ c != NULL; \ - c = _c, _c = nvme_subsystem_next_ctrl(s, c)) + c = _c, _c = libnvme_subsystem_next_ctrl(s, c)) /** - * nvme_subsystem_for_each_ctrl() - Traverse controllers - * @s: &nvme_subsystem_t object + * libnvme_subsystem_for_each_ctrl() - Traverse controllers + * @s: &libnvme_subsystem_t object * @c: Controller instance */ -#define nvme_subsystem_for_each_ctrl(s, c) \ - for (c = nvme_subsystem_first_ctrl(s); c != NULL; \ - c = nvme_subsystem_next_ctrl(s, c)) +#define libnvme_subsystem_for_each_ctrl(s, c) \ + for (c = libnvme_subsystem_first_ctrl(s); c != NULL; \ + c = libnvme_subsystem_next_ctrl(s, c)) /** - * nvme_ctrl_for_each_ns_safe() - Traverse namespaces + * libnvme_ctrl_for_each_ns_safe() - Traverse namespaces * @c: Controller instance - * @n: &nvme_ns_t object - * @_n: A &nvme_ns_t_node to use as temporary storage + * @n: &libnvme_ns_t object + * @_n: A &libnvme_ns_t_node to use as temporary storage */ -#define nvme_ctrl_for_each_ns_safe(c, n, _n) \ - for (n = nvme_ctrl_first_ns(c), \ - _n = nvme_ctrl_next_ns(c, n); \ +#define libnvme_ctrl_for_each_ns_safe(c, n, _n) \ + for (n = libnvme_ctrl_first_ns(c), \ + _n = libnvme_ctrl_next_ns(c, n); \ n != NULL; \ - n = _n, _n = nvme_ctrl_next_ns(c, n)) + n = _n, _n = libnvme_ctrl_next_ns(c, n)) /** - * nvme_ctrl_for_each_ns() - Traverse namespaces + * libnvme_ctrl_for_each_ns() - Traverse namespaces * @c: Controller instance - * @n: &nvme_ns_t object + * @n: &libnvme_ns_t object */ -#define nvme_ctrl_for_each_ns(c, n) \ - for (n = nvme_ctrl_first_ns(c); n != NULL; \ - n = nvme_ctrl_next_ns(c, n)) +#define libnvme_ctrl_for_each_ns(c, n) \ + for (n = libnvme_ctrl_first_ns(c); n != NULL; \ + n = libnvme_ctrl_next_ns(c, n)) /** - * nvme_ctrl_for_each_path_safe() - Traverse paths + * libnvme_ctrl_for_each_path_safe() - Traverse paths * @c: Controller instance - * @p: &nvme_path_t object - * @_p: A &nvme_path_t_node to use as temporary storage + * @p: &libnvme_path_t object + * @_p: A &libnvme_path_t_node to use as temporary storage */ -#define nvme_ctrl_for_each_path_safe(c, p, _p) \ - for (p = nvme_ctrl_first_path(c), \ - _p = nvme_ctrl_next_path(c, p); \ +#define libnvme_ctrl_for_each_path_safe(c, p, _p) \ + for (p = libnvme_ctrl_first_path(c), \ + _p = libnvme_ctrl_next_path(c, p); \ p != NULL; \ - p = _p, _p = nvme_ctrl_next_path(c, p)) + p = _p, _p = libnvme_ctrl_next_path(c, p)) /** - * nvme_ctrl_for_each_path() - Traverse paths + * libnvme_ctrl_for_each_path() - Traverse paths * @c: Controller instance - * @p: &nvme_path_t object + * @p: &libnvme_path_t object */ -#define nvme_ctrl_for_each_path(c, p) \ - for (p = nvme_ctrl_first_path(c); p != NULL; \ - p = nvme_ctrl_next_path(c, p)) +#define libnvme_ctrl_for_each_path(c, p) \ + for (p = libnvme_ctrl_first_path(c); p != NULL; \ + p = libnvme_ctrl_next_path(c, p)) /** - * nvme_subsystem_for_each_ns_safe() - Traverse namespaces - * @s: &nvme_subsystem_t object - * @n: &nvme_ns_t object - * @_n: A &nvme_ns_t_node to use as temporary storage + * libnvme_subsystem_for_each_ns_safe() - Traverse namespaces + * @s: &libnvme_subsystem_t object + * @n: &libnvme_ns_t object + * @_n: A &libnvme_ns_t_node to use as temporary storage */ -#define nvme_subsystem_for_each_ns_safe(s, n, _n) \ - for (n = nvme_subsystem_first_ns(s), \ - _n = nvme_subsystem_next_ns(s, n); \ +#define libnvme_subsystem_for_each_ns_safe(s, n, _n) \ + for (n = libnvme_subsystem_first_ns(s), \ + _n = libnvme_subsystem_next_ns(s, n); \ n != NULL; \ - n = _n, _n = nvme_subsystem_next_ns(s, n)) + n = _n, _n = libnvme_subsystem_next_ns(s, n)) /** - * nvme_subsystem_for_each_ns() - Traverse namespaces - * @s: &nvme_subsystem_t object - * @n: &nvme_ns_t object + * libnvme_subsystem_for_each_ns() - Traverse namespaces + * @s: &libnvme_subsystem_t object + * @n: &libnvme_ns_t object */ -#define nvme_subsystem_for_each_ns(s, n) \ - for (n = nvme_subsystem_first_ns(s); n != NULL; \ - n = nvme_subsystem_next_ns(s, n)) +#define libnvme_subsystem_for_each_ns(s, n) \ + for (n = libnvme_subsystem_first_ns(s); n != NULL; \ + n = libnvme_subsystem_next_ns(s, n)) /** - * nvme_namespace_for_each_path_safe() - Traverse paths + * libnvme_namespace_for_each_path_safe() - Traverse paths * @n: Namespace instance - * @p: &nvme_path_t object - * @_p: A &nvme_path_t_node to use as temporary storage + * @p: &libnvme_path_t object + * @_p: A &libnvme_path_t_node to use as temporary storage */ -#define nvme_namespace_for_each_path_safe(n, p, _p) \ - for (p = nvme_namespace_first_path(n), \ - _p = nvme_namespace_next_path(n, p); \ +#define libnvme_namespace_for_each_path_safe(n, p, _p) \ + for (p = libnvme_namespace_first_path(n), \ + _p = libnvme_namespace_next_path(n, p); \ p != NULL; \ - p = _p, _p = nvme_namespace_next_path(n, p)) + p = _p, _p = libnvme_namespace_next_path(n, p)) /** - * nvme_namespace_for_each_path() - Traverse paths + * libnvme_namespace_for_each_path() - Traverse paths * @n: Namespace instance - * @p: &nvme_path_t object + * @p: &libnvme_path_t object */ -#define nvme_namespace_for_each_path(n, p) \ - for (p = nvme_namespace_first_path(n); p != NULL; \ - p = nvme_namespace_next_path(n, p)) +#define libnvme_namespace_for_each_path(n, p) \ + for (p = libnvme_namespace_first_path(n); p != NULL; \ + p = libnvme_namespace_next_path(n, p)) /** - * nvme_ns_get_csi() - Command set identifier of a namespace + * libnvme_ns_get_csi() - Command set identifier of a namespace * @n: Namespace instance * * Return: The namespace's command set identifier in use */ -enum nvme_csi nvme_ns_get_csi(nvme_ns_t n); +enum nvme_csi libnvme_ns_get_csi(libnvme_ns_t n); /** - * nvme_ns_get_eui64() - 64-bit eui of a namespace + * libnvme_ns_get_eui64() - 64-bit eui of a namespace * @n: Namespace instance * * Return: A pointer to the 64-bit eui */ -const uint8_t *nvme_ns_get_eui64(nvme_ns_t n); +const uint8_t *libnvme_ns_get_eui64(libnvme_ns_t n); /** - * nvme_ns_get_nguid() - 128-bit nguid of a namespace + * libnvme_ns_get_nguid() - 128-bit nguid of a namespace * @n: Namespace instance * * Return: A pointer to the 128-bit nguid */ -const uint8_t *nvme_ns_get_nguid(nvme_ns_t n); +const uint8_t *libnvme_ns_get_nguid(libnvme_ns_t n); /** - * nvme_ns_get_uuid() - UUID of a namespace + * libnvme_ns_get_uuid() - UUID of a namespace * @n: Namespace instance * @out: buffer for the UUID * * Copies the namespace's uuid into @out */ -void nvme_ns_get_uuid(nvme_ns_t n, unsigned char out[NVME_UUID_LEN]); +void libnvme_ns_get_uuid(libnvme_ns_t n, unsigned char out[NVME_UUID_LEN]); /** - * nvme_ns_get_generic_name() - Returns name of generic namespace chardev. + * libnvme_ns_get_generic_name() - Returns name of generic namespace chardev. * @n: Namespace instance * * Return: Name of generic namespace chardev */ -const char *nvme_ns_get_generic_name(nvme_ns_t n); +const char *libnvme_ns_get_generic_name(libnvme_ns_t n); /** - * nvme_ns_get_firmware() - Firmware string of a namespace + * libnvme_ns_get_firmware() - Firmware string of a namespace * @n: Namespace instance * * Return: Firmware string of @n */ -const char *nvme_ns_get_firmware(nvme_ns_t n); +const char *libnvme_ns_get_firmware(libnvme_ns_t n); /** - * nvme_ns_get_serial() - Serial number of a namespace + * libnvme_ns_get_serial() - Serial number of a namespace * @n: Namespace instance * * Return: Serial number string of @n */ -const char *nvme_ns_get_serial(nvme_ns_t n); +const char *libnvme_ns_get_serial(libnvme_ns_t n); /** - * nvme_ns_get_model() - Model of a namespace + * libnvme_ns_get_model() - Model of a namespace * @n: Namespace instance * * Return: Model string of @n */ -const char *nvme_ns_get_model(nvme_ns_t n); +const char *libnvme_ns_get_model(libnvme_ns_t n); /** - * nvme_ns_get_subsystem() - &nvme_subsystem_t of a namespace + * libnvme_ns_get_subsystem() - &libnvme_subsystem_t of a namespace * @n: Namespace instance * - * Return: nvme_subsystem_t object of @n + * Return: libnvme_subsystem_t object of @n */ -nvme_subsystem_t nvme_ns_get_subsystem(nvme_ns_t n); +libnvme_subsystem_t libnvme_ns_get_subsystem(libnvme_ns_t n); /** - * nvme_ns_get_ctrl() - &nvme_ctrl_t of a namespace + * libnvme_ns_get_ctrl() - &libnvme_ctrl_t of a namespace * @n: Namespace instance * - * nvme_ctrl_t object may be NULL for a multipathed namespace + * libnvme_ctrl_t object may be NULL for a multipathed namespace * - * Return: nvme_ctrl_t object of @n if present + * Return: libnvme_ctrl_t object of @n if present */ -nvme_ctrl_t nvme_ns_get_ctrl(nvme_ns_t n); +libnvme_ctrl_t libnvme_ns_get_ctrl(libnvme_ns_t n); /** - * nvme_free_ns() - Free a namespace object + * libnvme_free_ns() - Free a namespace object * @n: Namespace instance */ -void nvme_free_ns(struct nvme_ns *n); +void libnvme_free_ns(struct libnvme_ns *n); /** - * nvme_ns_read() - Read from a namespace + * libnvme_ns_read() - Read from a namespace * @n: Namespace instance * @buf: Buffer into which the data will be transferred * @offset: LBA offset of @n @@ -585,10 +588,10 @@ void nvme_free_ns(struct nvme_ns *n); * * Return: Number of sectors read or -1 on error. */ -int nvme_ns_read(nvme_ns_t n, void *buf, off_t offset, size_t count); +int libnvme_ns_read(libnvme_ns_t n, void *buf, off_t offset, size_t count); /** - * nvme_ns_write() - Write to a namespace + * libnvme_ns_write() - Write to a namespace * @n: Namespace instance * @buf: Buffer with data to be written * @offset: LBA offset of @n @@ -596,20 +599,20 @@ int nvme_ns_read(nvme_ns_t n, void *buf, off_t offset, size_t count); * * Return: Number of sectors written or -1 on error */ -int nvme_ns_write(nvme_ns_t n, void *buf, off_t offset, size_t count); +int libnvme_ns_write(libnvme_ns_t n, void *buf, off_t offset, size_t count); /** - * nvme_ns_verify() - Verify data on a namespace + * libnvme_ns_verify() - Verify data on a namespace * @n: Namespace instance * @offset: LBA offset of @n * @count: Number of sectors to be verified * * Return: Number of sectors verified */ -int nvme_ns_verify(nvme_ns_t n, off_t offset, size_t count); +int libnvme_ns_verify(libnvme_ns_t n, off_t offset, size_t count); /** - * nvme_ns_compare() - Compare data on a namespace + * libnvme_ns_compare() - Compare data on a namespace * @n: Namespace instance * @buf: Buffer with data to be compared * @offset: LBA offset of @n @@ -617,38 +620,38 @@ int nvme_ns_verify(nvme_ns_t n, off_t offset, size_t count); * * Return: Number of sectors compared */ -int nvme_ns_compare(nvme_ns_t n, void *buf, off_t offset, size_t count); +int libnvme_ns_compare(libnvme_ns_t n, void *buf, off_t offset, size_t count); /** - * nvme_ns_write_zeros() - Write zeros to a namespace + * libnvme_ns_write_zeros() - Write zeros to a namespace * @n: Namespace instance * @offset: LBA offset in @n * @count: Number of sectors to be written * * Return: Number of sectors written */ -int nvme_ns_write_zeros(nvme_ns_t n, off_t offset, size_t count); +int libnvme_ns_write_zeros(libnvme_ns_t n, off_t offset, size_t count); /** - * nvme_ns_write_uncorrectable() - Issus a 'write uncorrectable' command + * libnvme_ns_write_uncorrectable() - Issus a 'write uncorrectable' command * @n: Namespace instance * @offset: LBA offset in @n * @count: Number of sectors to be written * * Return: Number of sectors written */ -int nvme_ns_write_uncorrectable(nvme_ns_t n, off_t offset, size_t count); +int libnvme_ns_write_uncorrectable(libnvme_ns_t n, off_t offset, size_t count); /** - * nvme_ns_flush() - Flush data to a namespace + * libnvme_ns_flush() - Flush data to a namespace * @n: Namespace instance * * Return: 0 on success, -1 on error. */ -int nvme_ns_flush(nvme_ns_t n); +int libnvme_ns_flush(libnvme_ns_t n); /** - * nvme_ns_identify() - Issue an 'identify namespace' command + * libnvme_ns_identify() - Issue an 'identify namespace' command * @n: Namespace instance * @ns: &nvme_id_ns buffer * @@ -657,10 +660,10 @@ int nvme_ns_flush(nvme_ns_t n); * * Return: 0 on success, -1 on error. */ -int nvme_ns_identify(nvme_ns_t n, struct nvme_id_ns *ns); +int libnvme_ns_identify(libnvme_ns_t n, struct nvme_id_ns *ns); /** - * nvme_ns_identify_descs() - Issue an 'identify descriptors' command + * libnvme_ns_identify_descs() - Issue an 'identify descriptors' command * @n: Namespace instance * @descs: List of identify descriptors * @@ -669,97 +672,102 @@ int nvme_ns_identify(nvme_ns_t n, struct nvme_id_ns *ns); * * Return: 0 on success, -1 on error. */ -int nvme_ns_identify_descs(nvme_ns_t n, struct nvme_ns_id_desc *descs); +int libnvme_ns_identify_descs(libnvme_ns_t n, struct nvme_ns_id_desc *descs); /** - * nvme_path_get_queue_depth() - Queue depth of an nvme_path_t object - * @p: &nvme_path_t object + * libnvme_path_get_queue_depth() - Queue depth of an libnvme_path_t object + * @p: &libnvme_path_t object * * Return: Queue depth of @p */ -int nvme_path_get_queue_depth(nvme_path_t p); +int libnvme_path_get_queue_depth(libnvme_path_t p); /** - * nvme_path_get_ctrl() - Parent controller of an nvme_path_t object - * @p: &nvme_path_t object + * libnvme_path_get_ctrl() - Parent controller of an libnvme_path_t object + * @p: &libnvme_path_t object * * Return: Parent controller if present */ -nvme_ctrl_t nvme_path_get_ctrl(nvme_path_t p); +libnvme_ctrl_t libnvme_path_get_ctrl(libnvme_path_t p); /** - * nvme_path_get_ns() - Parent namespace of an nvme_path_t object - * @p: &nvme_path_t object + * libnvme_path_get_ns() - Parent namespace of an libnvme_path_t object + * @p: &libnvme_path_t object * * Return: Parent namespace if present */ -nvme_ns_t nvme_path_get_ns(nvme_path_t p); +libnvme_ns_t libnvme_path_get_ns(libnvme_path_t p); /** - * nvme_ctrl_get_transport_handle() - Get associated transport handle + * libnvme_ctrl_get_transport_handle() - Get associated transport handle * @c: Controller instance * * 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_transport_handle() is called. + * is deleted or libnvme_ctrl_release_transport_handle() is called. * * Return: Link handle associated with @c or NULL */ -struct nvme_transport_handle *nvme_ctrl_get_transport_handle(nvme_ctrl_t c); +struct libnvme_transport_handle * +libnvme_ctrl_get_transport_handle(libnvme_ctrl_t c); /** - * nvme_ctrl_release_transport_handle() - Free transport handle from controller object + * libnvme_ctrl_release_transport_handle() - Free transport handle + * from controller object * @c: Controller instance * */ -void nvme_ctrl_release_transport_handle(nvme_ctrl_t c); +void libnvme_ctrl_release_transport_handle(libnvme_ctrl_t c); /** - * nvme_ctrl_get_src_addr() - Extract src_addr from the c->address string + * libnvme_ctrl_get_src_addr() - Extract src_addr from the c->address string * @c: Controller instance - * @src_addr: Where to copy the src_addr. Size must be at least INET6_ADDRSTRLEN. + * @src_addr: Where to copy the src_addr. Size must be at least + * INET6_ADDRSTRLEN. * @src_addr_len: Length of the buffer @src_addr. * - * Return: Pointer to @src_addr on success. NULL on failure to extract the src_addr. + * Return: Pointer to @src_addr on success. NULL on failure to extract the + * src_addr. */ -char *nvme_ctrl_get_src_addr(nvme_ctrl_t c, char *src_addr, size_t src_addr_len); +char *libnvme_ctrl_get_src_addr(libnvme_ctrl_t c, char *src_addr, + size_t src_addr_len); /** - * nvme_ctrl_get_state() - Running state of a controller + * libnvme_ctrl_get_state() - Running state of a controller * @c: Controller instance * * Return: String indicating the running state of @c */ -const char *nvme_ctrl_get_state(nvme_ctrl_t c); +const char *libnvme_ctrl_get_state(libnvme_ctrl_t c); /** - * nvme_ctrl_get_subsystem() - Parent subsystem of a controller + * libnvme_ctrl_get_subsystem() - Parent subsystem of a controller * @c: Controller instance * - * Return: Parent nvme_subsystem_t object + * Return: Parent libnvme_subsystem_t object */ -nvme_subsystem_t nvme_ctrl_get_subsystem(nvme_ctrl_t c); +libnvme_subsystem_t libnvme_ctrl_get_subsystem(libnvme_ctrl_t c); /** - * nvme_ns_head_get_sysfs_dir() - sysfs dir of namespave head + * libnvme_ns_head_get_sysfs_dir() - sysfs dir of namespave head * @head: namespace head instance * * Returns: sysfs directory name of @head */ -const char *nvme_ns_head_get_sysfs_dir(nvme_ns_head_t head); +const char *libnvme_ns_head_get_sysfs_dir(libnvme_ns_head_t head); /** - * nvme_ctrl_get_config() - Fabrics configuration of a controller + * libnvme_ctrl_get_config() - Fabrics configuration of a controller * @c: Controller instance * * Return: Fabrics configuration of @c */ -struct nvme_fabrics_config *nvme_ctrl_get_config(nvme_ctrl_t c); +struct libnvme_fabrics_config *libnvme_ctrl_get_config(libnvme_ctrl_t c); /** - * nvme_ctrl_identify() - Issues an 'identify controller' command + * libnvme_ctrl_identify() - Issues an 'identify controller' command * @c: Controller instance * @id: Identify controller data structure * @@ -768,61 +776,63 @@ struct nvme_fabrics_config *nvme_ctrl_get_config(nvme_ctrl_t c); * * Return: 0 on success or -1 on failure. */ -int nvme_ctrl_identify(nvme_ctrl_t c, struct nvme_id_ctrl *id); +int libnvme_ctrl_identify(libnvme_ctrl_t c, struct nvme_id_ctrl *id); /** - * nvme_disconnect_ctrl() - Disconnect a controller + * libnvme_disconnect_ctrl() - Disconnect a controller * @c: Controller instance * * Issues a 'disconnect' fabrics command to @c * * Return: 0 on success, -1 on failure. */ -int nvme_disconnect_ctrl(nvme_ctrl_t c); +int libnvme_disconnect_ctrl(libnvme_ctrl_t c); /** - * nvme_scan_ctrl() - Scan on a controller - * @ctx: struct nvme_global_ctx object + * libnvme_scan_ctrl() - Scan on a controller + * @ctx: struct libnvme_global_ctx object * @name: Name of the controller - * @c: @nvme_ctrl_t object to return + * @c: @libnvme_ctrl_t object to return * * Scans a controller with sysfs name @name and add it to @r. * * Return: 0 on success or negative error code otherwise */ -int nvme_scan_ctrl(struct nvme_global_ctx *ctx, const char *name, nvme_ctrl_t *c); +int libnvme_scan_ctrl(struct libnvme_global_ctx *ctx, const char *name, + libnvme_ctrl_t *c); /** - * nvme_rescan_ctrl() - Rescan an existing controller + * libnvme_rescan_ctrl() - Rescan an existing controller * @c: Controller instance */ -void nvme_rescan_ctrl(nvme_ctrl_t c); +void libnvme_rescan_ctrl(libnvme_ctrl_t c); /** - * nvme_init_ctrl() - Initialize nvme_ctrl_t object for an existing controller. - * @h: nvme_host_t object - * @c: nvme_ctrl_t object + * libnvme_init_ctrl() - Initialize libnvme_ctrl_t object for an existing + * controller. + * @h: libnvme_host_t object + * @c: libnvme_ctrl_t object * @instance: Instance number (e.g. 1 for nvme1) * * Return: 0 on success or negative error code otherwise */ -int nvme_init_ctrl(nvme_host_t h, nvme_ctrl_t c, int instance); +int libnvme_init_ctrl(libnvme_host_t h, libnvme_ctrl_t c, int instance); /** - * nvme_free_ctrl() - Free controller + * libnvme_free_ctrl() - Free controller * @c: Controller instance */ -void nvme_free_ctrl(struct nvme_ctrl *c); +void libnvme_free_ctrl(struct libnvme_ctrl *c); /** - * nvme_unlink_ctrl() - Unlink controller + * libnvme_unlink_ctrl() - Unlink controller * @c: Controller instance */ -void nvme_unlink_ctrl(struct nvme_ctrl *c); +void libnvme_unlink_ctrl(struct libnvme_ctrl *c); /** - * nvme_scan_topology() - Scan NVMe topology and apply filter - * @ctx: struct nvme_global_ctx object + * libnvme_scan_topology() - Scan NVMe topology and apply filter + * @ctx: struct libnvme_global_ctx object * @f: filter to apply * @f_args: user-specified argument to @f * @@ -831,27 +841,28 @@ void nvme_unlink_ctrl(struct nvme_ctrl *c); * * Return: 0 on success, or negative error code otherwise. */ -int nvme_scan_topology(struct nvme_global_ctx *ctx, nvme_scan_filter_t f, void *f_args); +int libnvme_scan_topology(struct libnvme_global_ctx *ctx, + libnvme_scan_filter_t f, void *f_args); /** - * nvme_host_release_fds() - Close all opened file descriptors under host - * @h: nvme_host_t object + * libnvme_host_release_fds() - Close all opened file descriptors under host + * @h: libnvme_host_t object * * Controller and Namespace objects cache the file descriptors * of opened nvme devices. This API can be used to close and * clear all cached fds under this host. */ -void nvme_host_release_fds(struct nvme_host *h); +void libnvme_host_release_fds(struct libnvme_host *h); /** - * nvme_free_host() - Free nvme_host_t object - * @h: nvme_host_t object + * libnvme_free_host() - Free libnvme_host_t object + * @h: libnvme_host_t object */ -void nvme_free_host(nvme_host_t h); +void libnvme_free_host(libnvme_host_t h); /** - * nvme_read_config() - Read NVMe JSON configuration file - * @ctx: &struct nvme_global_ctx object + * libnvme_read_config() - Read NVMe JSON configuration file + * @ctx: &struct libnvme_global_ctx object * @config_file: JSON configuration file * * Read in the contents of @config_file and merge them with @@ -859,19 +870,20 @@ void nvme_free_host(nvme_host_t h); * * Return: 0 on success or negative error code otherwise */ -int nvme_read_config(struct nvme_global_ctx *ctx, const char *config_file); +int libnvme_read_config(struct libnvme_global_ctx *ctx, + const char *config_file); /** - * nvme_refresh_topology() - Refresh nvme_root_t object contents - * @ctx: &struct nvme_global_ctx object + * libnvme_refresh_topology() - Refresh libnvme_root_t object contents + * @ctx: &struct libnvme_global_ctx object * * Removes all elements in @r and rescans the existing topology. */ -void nvme_refresh_topology(struct nvme_global_ctx *ctx); +void libnvme_refresh_topology(struct libnvme_global_ctx *ctx); /** - * nvme_dump_config() - Print the JSON configuration - * @ctx: &struct nvme_global_ctx object + * libnvme_dump_config() - Print the JSON configuration + * @ctx: &struct libnvme_global_ctx object * @fd: File descriptor to write the JSON configuration. * * Writes the current contents of the JSON configuration @@ -879,98 +891,98 @@ void nvme_refresh_topology(struct nvme_global_ctx *ctx); * * Return: 0 on success, or negative error code otherwise. */ -int nvme_dump_config(struct nvme_global_ctx *ctx, int fd); +int libnvme_dump_config(struct libnvme_global_ctx *ctx, int fd); /** - * nvme_dump_tree() - Dump internal object tree - * @ctx: &struct nvme_global_ctx object + * libnvme_dump_tree() - Dump internal object tree + * @ctx: &struct libnvme_global_ctx object * * Prints the internal object tree in JSON format * to stdout. * * Return: 0 on success or negative error code otherwise */ -int nvme_dump_tree(struct nvme_global_ctx *ctx); +int libnvme_dump_tree(struct libnvme_global_ctx *ctx); /** - * nvme_get_attr() - Read sysfs attribute + * libnvme_get_attr() - Read sysfs attribute * @d: sysfs directory * @attr: sysfs attribute name * * 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); +char *libnvme_get_attr(const char *d, const char *attr); /** - * nvme_get_subsys_attr() - Read subsystem sysfs attribute - * @s: nvme_subsystem_t object + * libnvme_get_subsys_attr() - Read subsystem sysfs attribute + * @s: libnvme_subsystem_t object * @attr: sysfs attribute name * * 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); +char *libnvme_get_subsys_attr(libnvme_subsystem_t s, const char *attr); /** - * nvme_get_ctrl_attr() - Read controller sysfs attribute + * libnvme_get_ctrl_attr() - Read controller sysfs attribute * @c: Controller instance * @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. */ -char *nvme_get_ctrl_attr(nvme_ctrl_t c, const char *attr); +char *libnvme_get_ctrl_attr(libnvme_ctrl_t c, const char *attr); /** - * nvme_get_ns_attr() - Read namespace sysfs attribute - * @n: nvme_ns_t object + * libnvme_get_ns_attr() - Read namespace sysfs attribute + * @n: libnvme_ns_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. */ -char *nvme_get_ns_attr(nvme_ns_t n, const char *attr); +char *libnvme_get_ns_attr(libnvme_ns_t n, const char *attr); /** - * nvme_subsystem_lookup_namespace() - lookup namespace by NSID - * @s: nvme_subsystem_t object + * libnvme_subsystem_lookup_namespace() - lookup namespace by NSID + * @s: libnvme_subsystem_t object * @nsid: Namespace id * - * Return: nvme_ns_t of the namespace with id @nsid in subsystem @s + * Return: libnvme_ns_t of the namespace with id @nsid in subsystem @s */ -nvme_ns_t nvme_subsystem_lookup_namespace(struct nvme_subsystem *s, +libnvme_ns_t libnvme_subsystem_lookup_namespace(struct libnvme_subsystem *s, __u32 nsid); /** - * nvme_subsystem_release_fds() - Close all opened fds under subsystem - * @s: nvme_subsystem_t object + * libnvme_subsystem_release_fds() - Close all opened fds under subsystem + * @s: libnvme_subsystem_t object * * Controller and Namespace objects cache the file descriptors * of opened nvme devices. This API can be used to close and * clear all cached fds under this subsystem. * */ -void nvme_subsystem_release_fds(struct nvme_subsystem *s); +void libnvme_subsystem_release_fds(struct libnvme_subsystem *s); /** - * nvme_get_path_attr() - Read path sysfs attribute - * @p: nvme_path_t object + * libnvme_get_path_attr() - Read path sysfs attribute + * @p: libnvme_path_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. */ -char *nvme_get_path_attr(nvme_path_t p, const char *attr); +char *libnvme_get_path_attr(libnvme_path_t p, const char *attr); /** - * nvme_scan_namespace() - scan namespace based on sysfs name - * @ctx: &struct nvme_global_ctx object + * libnvme_scan_namespace() - scan namespace based on sysfs name + * @ctx: &struct libnvme_global_ctx object * @name: sysfs name of the namespace to scan - * @ns: &nvme_ns_t object to return + * @ns: &libnvme_ns_t object to return * * Return: 0 on success or negative error code otherwise */ -int nvme_scan_namespace(struct nvme_global_ctx *ctx, const char *name, - nvme_ns_t *ns); +int libnvme_scan_namespace(struct libnvme_global_ctx *ctx, const char *name, + libnvme_ns_t *ns); diff --git a/libnvme/src/nvme/uring.c b/libnvme/src/nvme/uring.c index 7eb4bfa2ba..ad3679daed 100644 --- a/libnvme/src/nvme/uring.c +++ b/libnvme/src/nvme/uring.c @@ -18,7 +18,7 @@ */ #define NVME_URING_ENTRIES 16 -int nvme_open_uring(struct nvme_global_ctx *ctx) +int libnvme_open_uring(struct libnvme_global_ctx *ctx) { struct io_uring_probe *probe; struct io_uring *ring; @@ -44,7 +44,7 @@ int nvme_open_uring(struct nvme_global_ctx *ctx) return 0; } -void nvme_close_uring(struct nvme_global_ctx *ctx) +void libnvme_close_uring(struct libnvme_global_ctx *ctx) { if (!ctx->ring) return; @@ -53,20 +53,20 @@ void nvme_close_uring(struct nvme_global_ctx *ctx) free(ctx->ring); } -int __nvme_transport_handle_open_uring(struct nvme_transport_handle *hdl) +int __libnvme_transport_handle_open_uring(struct libnvme_transport_handle *hdl) { int err; switch (hdl->ctx->uring_state) { - case NVME_IO_URING_STATE_NOT_AVAILABLE: + case LIBNVME_IO_URING_STATE_NOT_AVAILABLE: return -ENOTSUP; - case NVME_IO_URING_STATE_AVAILABLE: + case LIBNVME_IO_URING_STATE_AVAILABLE: goto uring_enabled; - case NVME_IO_URING_STATE_UNKNOWN: + case LIBNVME_IO_URING_STATE_UNKNOWN: break; } - err = nvme_open_uring(hdl->ctx); + err = libnvme_open_uring(hdl->ctx); if (err) return err; @@ -77,7 +77,7 @@ int __nvme_transport_handle_open_uring(struct nvme_transport_handle *hdl) } static int nvme_submit_uring_cmd(struct io_uring *ring, int fd, - struct nvme_passthru_cmd *cmd) + struct libnvme_passthru_cmd *cmd) { struct io_uring_sqe *sqe; int ret; @@ -90,7 +90,7 @@ static int nvme_submit_uring_cmd(struct io_uring *ring, int fd, sqe->fd = fd; sqe->opcode = IORING_OP_URING_CMD; - sqe->cmd_op = NVME_URING_CMD_ADMIN; + sqe->cmd_op = LIBNVME_URING_CMD_ADMIN; ret = io_uring_submit(ring); if (ret < 0) @@ -99,7 +99,7 @@ static int nvme_submit_uring_cmd(struct io_uring *ring, int fd, return 0; } -int nvme_wait_complete_passthru(struct nvme_transport_handle *hdl) +int libnvme_wait_complete_passthru(struct libnvme_transport_handle *hdl) { struct io_uring_cqe *cqe; struct io_uring *ring; @@ -118,13 +118,13 @@ int nvme_wait_complete_passthru(struct nvme_transport_handle *hdl) return 0; } -int nvme_submit_admin_passthru_async(struct nvme_transport_handle *hdl, - struct nvme_passthru_cmd *cmd) +int libnvme_submit_admin_passthru_async(struct libnvme_transport_handle *hdl, + struct libnvme_passthru_cmd *cmd) { int err; if (hdl->ctx->ring_cmds >= NVME_URING_ENTRIES) { - err = nvme_wait_complete_passthru(hdl); + err = libnvme_wait_complete_passthru(hdl); if (err) return err; } diff --git a/libnvme/src/nvme/util.c b/libnvme/src/nvme/util.c index 70916d566d..25d1847e5a 100644 --- a/libnvme/src/nvme/util.c +++ b/libnvme/src/nvme/util.c @@ -175,7 +175,7 @@ static inline __u8 nvme_fabrics_status_to_errno(__u16 status) return EIO; } -__public __u8 nvme_status_to_errno(int status, bool fabrics) +__public __u8 libnvme_status_to_errno(int status, bool fabrics) { __u16 sc; @@ -374,7 +374,7 @@ static const char *arg_str(const char * const *strings, return "unrecognized"; } -__public const char *nvme_status_to_string(int status, bool fabrics) +__public const char *libnvme_status_to_string(int status, bool fabrics) { const char *s = "Unknown status"; __u16 sc, sct; @@ -438,22 +438,22 @@ static const char * const libnvme_status[] = { [ENVME_CONNECT_NOKEY] = "pre-shared TLS key is missing" }; -__public const char *nvme_errno_to_string(int status) +__public const char *libnvme_errno_to_string(int status) { const char *s = ARGSTR(libnvme_status, status); return s; } -__public const char *nvme_strerror(int errnum) +__public const char *libnvme_strerror(int errnum) { if (errnum >= ENVME_CONNECT_RESOLVE) - return nvme_errno_to_string(errnum); + return libnvme_errno_to_string(errnum); return strerror(errnum); } #ifdef HAVE_NETDB -int hostname2traddr(struct nvme_global_ctx *ctx, const char *traddr, +int hostname2traddr(struct libnvme_global_ctx *ctx, const char *traddr, char **hostname) { _cleanup_addrinfo_ struct addrinfo *host_info = NULL; @@ -464,7 +464,7 @@ int hostname2traddr(struct nvme_global_ctx *ctx, const char *traddr, ret = getaddrinfo(traddr, NULL, &hints, &host_info); if (ret) { - nvme_msg(ctx, LOG_ERR, "failed to resolve host %s info\n", + libnvme_msg(ctx, LOG_ERR, "failed to resolve host %s info\n", traddr); return -errno; } @@ -481,13 +481,13 @@ int hostname2traddr(struct nvme_global_ctx *ctx, const char *traddr, addrstr, NVMF_TRADDR_SIZE); break; default: - nvme_msg(ctx, LOG_ERR, "unrecognized address family (%d) %s\n", + libnvme_msg(ctx, LOG_ERR, "unrecognized address family (%d) %s\n", host_info->ai_family, traddr); return -EINVAL; } if (!p) { - nvme_msg(ctx, LOG_ERR, "failed to get traddr for %s\n", + libnvme_msg(ctx, LOG_ERR, "failed to get traddr for %s\n", traddr); return -EIO; } @@ -498,9 +498,9 @@ int hostname2traddr(struct nvme_global_ctx *ctx, const char *traddr, return 0; } #else /* HAVE_NETDB */ -int hostname2traddr(struct nvme_global_ctx *ctx, const char *traddr, char **hostname) +int hostname2traddr(struct libnvme_global_ctx *ctx, const char *traddr, char **hostname) { - nvme_msg(ctx, LOG_ERR, "No support for hostname IP address resolution; " \ + libnvme_msg(ctx, LOG_ERR, "No support for hostname IP address resolution; " \ "recompile with libnss support.\n"); return -ENOTSUP; @@ -712,19 +712,19 @@ __public struct nvmf_ext_attr *nvmf_exat_ptr_next(struct nvmf_ext_attr *p) ((uintptr_t)p + (ptrdiff_t)nvmf_exat_size(le16_to_cpu(p->exatlen))); } -__public const char *nvme_get_version(enum nvme_version type) +__public const char *libnvme_get_version(enum libnvme_version type) { switch(type) { - case NVME_VERSION_PROJECT: + case LIBNVME_VERSION_PROJECT: return LIBNVME_VERSION; - case NVME_VERSION_GIT: + case LIBNVME_VERSION_GIT: return GIT_VERSION; default: return "n/a"; } } -__public int nvme_uuid_to_string(unsigned char uuid[NVME_UUID_LEN], char *str) +__public int libnvme_uuid_to_string(unsigned char uuid[NVME_UUID_LEN], char *str) { int n; n = snprintf(str, NVME_UUID_LEN_STRING, @@ -736,7 +736,7 @@ __public int nvme_uuid_to_string(unsigned char uuid[NVME_UUID_LEN], char *str) return n != NVME_UUID_LEN_STRING - 1 ? -EINVAL : 0; } -__public int nvme_uuid_from_string(const char *str, unsigned char uuid[NVME_UUID_LEN]) +__public int libnvme_uuid_from_string(const char *str, unsigned char uuid[NVME_UUID_LEN]) { int n; @@ -750,7 +750,7 @@ __public int nvme_uuid_from_string(const char *str, unsigned char uuid[NVME_UUID } -__public int nvme_random_uuid(unsigned char uuid[NVME_UUID_LEN]) +__public int libnvme_random_uuid(unsigned char uuid[NVME_UUID_LEN]) { _cleanup_fd_ int f = -1; ssize_t n; @@ -775,7 +775,7 @@ __public int nvme_random_uuid(unsigned char uuid[NVME_UUID_LEN]) return 0; } -__public int nvme_find_uuid(struct nvme_id_uuid_list *uuid_list, +__public int libnvme_find_uuid(struct nvme_id_uuid_list *uuid_list, const unsigned char uuid[NVME_UUID_LEN]) { const unsigned char uuid_end[NVME_UUID_LEN] = {0}; @@ -833,7 +833,7 @@ static bool _nvme_ipaddrs_eq(struct sockaddr *addr1, struct sockaddr *addr2) return false; } -bool nvme_ipaddrs_eq(const char *addr1, const char *addr2) +bool libnvme_ipaddrs_eq(const char *addr1, const char *addr2) { bool result = false; struct addrinfo *info1 = NULL, hint1 = { .ai_flags=AI_NUMERICHOST, .ai_family=AF_UNSPEC }; @@ -861,9 +861,9 @@ bool nvme_ipaddrs_eq(const char *addr1, const char *addr2) return result; } #else /* HAVE_NETDB */ -bool nvme_ipaddrs_eq(const char *addr1, const char *addr2) +bool libnvme_ipaddrs_eq(const char *addr1, const char *addr2) { - nvme_msg(NULL, LOG_ERR, "no support for hostname ip address resolution; " \ + libnvme_msg(NULL, LOG_ERR, "no support for hostname ip address resolution; " \ "recompile with libnss support.\n"); return false; @@ -871,7 +871,8 @@ bool nvme_ipaddrs_eq(const char *addr1, const char *addr2) #endif /* HAVE_NETDB */ #ifdef HAVE_NETDB -const char *nvme_iface_matching_addr(const struct ifaddrs *iface_list, const char *addr) +const char *libnvme_iface_matching_addr(const struct ifaddrs *iface_list, + const char *addr) { const struct ifaddrs *iface_it; struct addrinfo *info = NULL, hint = { .ai_flags = AI_NUMERICHOST, .ai_family = AF_UNSPEC }; @@ -896,7 +897,8 @@ const char *nvme_iface_matching_addr(const struct ifaddrs *iface_list, const cha return iface_name; } -bool nvme_iface_primary_addr_matches(const struct ifaddrs *iface_list, const char *iface, const char *addr) +bool libnvme_iface_primary_addr_matches(const struct ifaddrs *iface_list, + const char *iface, const char *addr) { const struct ifaddrs *iface_it; struct addrinfo *info = NULL, hint = { .ai_flags = AI_NUMERICHOST, .ai_family = AF_UNSPEC }; @@ -928,17 +930,19 @@ bool nvme_iface_primary_addr_matches(const struct ifaddrs *iface_list, const cha #else /* HAVE_NETDB */ -const char *nvme_iface_matching_addr(const struct ifaddrs *iface_list, const char *addr) +const char *libnvme_iface_matching_addr(const struct ifaddrs *iface_list, + const char *addr) { - nvme_msg(NULL, LOG_ERR, "no support for interface lookup; " + libnvme_msg(NULL, LOG_ERR, "no support for interface lookup; " "recompile with libnss support.\n"); return NULL; } -bool nvme_iface_primary_addr_matches(const struct ifaddrs *iface_list, const char *iface, const char *addr) +bool libnvme_iface_primary_addr_matches(const struct ifaddrs *iface_list, + const char *iface, const char *addr) { - nvme_msg(NULL, LOG_ERR, "no support for interface lookup; " + libnvme_msg(NULL, LOG_ERR, "no support for interface lookup; " "recompile with libnss support.\n"); return false; @@ -946,7 +950,7 @@ bool nvme_iface_primary_addr_matches(const struct ifaddrs *iface_list, const cha #endif /* HAVE_NETDB */ -void *__nvme_alloc(size_t len) +void *__libnvme_alloc(size_t len) { size_t _len = round_up(len, 0x1000); void *p; @@ -958,11 +962,11 @@ void *__nvme_alloc(size_t len) return p; } -void *__nvme_realloc(void *p, size_t len) +void *__libnvme_realloc(void *p, size_t len) { size_t old_len = malloc_usable_size(p); - void *result = __nvme_alloc(len); + void *result = __libnvme_alloc(len); if (p && result) { memcpy(result, p, min(old_len, len)); @@ -972,7 +976,7 @@ void *__nvme_realloc(void *p, size_t len) return result; } -const struct ifaddrs *nvme_getifaddrs(struct nvme_global_ctx *ctx) +const struct ifaddrs *libnvme_getifaddrs(struct libnvme_global_ctx *ctx) { if (!ctx->ifaddrs_cache) { struct ifaddrs *p; @@ -987,7 +991,7 @@ const struct ifaddrs *nvme_getifaddrs(struct nvme_global_ctx *ctx) /* This used instead of basename() due to behavioral differences between * the POSIX and the GNU version. This is the glibc implementation. * Original source: https://github.com/bminor/glibc/blob/master/string/basename.c */ -char *nvme_basename(const char *path) +char *libnvme_basename(const char *path) { char *p = (char *) strrchr(path, '/'); return p ? p + 1 : (char *) path; diff --git a/libnvme/src/nvme/util.h b/libnvme/src/nvme/util.h index 90459bb4f3..abd515171f 100644 --- a/libnvme/src/nvme/util.h +++ b/libnvme/src/nvme/util.h @@ -17,7 +17,7 @@ */ /** - * enum nvme_connect_err - nvme connect error codes + * enum libnvme_connect_err - nvme connect error codes * @ENVME_CONNECT_RESOLVE: failed to resolve host * @ENVME_CONNECT_ADDRFAM: unrecognized address family * @ENVME_CONNECT_TRADDR: failed to get traddr @@ -40,7 +40,7 @@ * @ENVME_CONNECT_IGNORED: connect attempt is ignored due to configuration * @ENVME_CONNECT_NOKEY: the TLS key is missing */ -enum nvme_connect_err { +enum libnvme_connect_err { ENVME_CONNECT_RESOLVE = 1000, ENVME_CONNECT_ADDRFAM, ENVME_CONNECT_TRADDR, @@ -65,33 +65,33 @@ enum nvme_connect_err { }; /** - * nvme_status_to_errno() - Converts nvme return status to errno + * libnvme_status_to_errno() - Converts nvme return status to errno * @status: Return status from an nvme passthrough command * @fabrics: Set to true if &status is to a fabrics target. * * Return: An errno representing the nvme status if it is an nvme status field, * or unchanged status is < 0 since errno is already set. */ -__u8 nvme_status_to_errno(int status, bool fabrics); +__u8 libnvme_status_to_errno(int status, bool fabrics); /** - * nvme_status_to_string() - Returns string describing nvme return status. + * libnvme_status_to_string() - Returns string describing nvme return status. * @status: Return status from an nvme passthrough command * @fabrics: Set to true if &status is to a fabrics target. * * Return: String representation of the nvme status if it is an nvme status field, * or a standard errno string if status is < 0. */ -const char *nvme_status_to_string(int status, bool fabrics); +const char *libnvme_status_to_string(int status, bool fabrics); /** - * nvme_sanitize_ns_status_to_string() - Returns sanitize ns status string. + * libnvme_sanitize_ns_status_to_string() - Returns sanitize ns status string. * @sc: Return status code from an sanitize ns command * * Return: The sanitize ns status string if it is a specific status code. */ static inline const char * -nvme_sanitize_ns_status_to_string(__u16 sc) +libnvme_sanitize_ns_status_to_string(__u16 sc) { switch (sc) { case NVME_SC_EXCEEDS_MAX_NS_SANITIZE: @@ -104,13 +104,13 @@ nvme_sanitize_ns_status_to_string(__u16 sc) }; /** - * nvme_set_features_status_to_string() - Returns set features status string. + * libnvme_set_features_status_to_string() - Returns set features status string. * @sc: Return status code from an set features command * * Return: The set features status string if it is a specific status code. */ static inline const char * -nvme_set_features_status_to_string(__u16 sc) +libnvme_set_features_status_to_string(__u16 sc) { switch (sc) { case NVME_SC_FEATURE_NOT_SAVEABLE: @@ -133,7 +133,7 @@ nvme_set_features_status_to_string(__u16 sc) }; /** - * nvme_opcode_status_to_string() - Returns nvme opcode status string. + * libnvme_opcode_status_to_string() - Returns nvme opcode status string. * @status: Return status from an nvme passthrough command * @admin: Set to true if an admin command * @opcode: Opcode from an nvme passthrough command @@ -142,7 +142,7 @@ nvme_set_features_status_to_string(__u16 sc) * or a standard errno string if status is < 0. */ static inline const char * -nvme_opcode_status_to_string(int status, bool admin, __u8 opcode) +libnvme_opcode_status_to_string(int status, bool admin, __u8 opcode) { __u16 sct = nvme_status_code_type(status); __u16 sc = nvme_status_code(status); @@ -152,10 +152,10 @@ nvme_opcode_status_to_string(int status, bool admin, __u8 opcode) if (admin) { switch (opcode) { case nvme_admin_sanitize_ns: - s = nvme_sanitize_ns_status_to_string(sc); + s = libnvme_sanitize_ns_status_to_string(sc); break; case nvme_admin_set_features: - s = nvme_set_features_status_to_string(sc); + s = libnvme_set_features_status_to_string(sc); break; default: break; @@ -166,25 +166,25 @@ nvme_opcode_status_to_string(int status, bool admin, __u8 opcode) if (s) return s; - return nvme_status_to_string(status, false); + return libnvme_status_to_string(status, false); } /** - * nvme_errno_to_string() - Returns string describing nvme connect failures - * @err: Returned error code from nvme_add_ctrl() + * libnvme_errno_to_string() - Returns string describing nvme connect failures + * @err: Returned error code from libnvme_add_ctrl() * * Return: String representation of the nvme connect error codes */ -const char *nvme_errno_to_string(int err); +const char *libnvme_errno_to_string(int err); /** - * nvme_strerror() - Returns string describing nvme errors and errno + * libnvme_strerror() - Returns string describing nvme errors and errno * @err: Returned error codes from all libnvme functions * * Return: String representation of either the nvme connect error codes * (positive values) or errno string (negative values) */ -const char *nvme_strerror(int err); +const char *libnvme_strerror(int err); /** * nvmf_exat_ptr_next - Increment @p to the next element in the array. @@ -201,44 +201,45 @@ const char *nvme_strerror(int err); struct nvmf_ext_attr *nvmf_exat_ptr_next(struct nvmf_ext_attr *p); /** - * enum nvme_version - Selector for version to be returned by @nvme_get_version + * enum libnvme_version - Selector for version to be returned by + * @libnvme_get_version * - * @NVME_VERSION_PROJECT: Project release version - * @NVME_VERSION_GIT: Git reference + * @LIBNVME_VERSION_PROJECT: Project release version + * @LIBNVME_VERSION_GIT: Git reference */ -enum nvme_version { - NVME_VERSION_PROJECT = 0, - NVME_VERSION_GIT = 1, +enum libnvme_version { + LIBNVME_VERSION_PROJECT = 0, + LIBNVME_VERSION_GIT = 1, }; /** - * nvme_get_version - Return version libnvme string - * @type: Selects which version type (see @struct nvme_version) + * libnvme_get_version - Return version libnvme string + * @type: Selects which version type (see @struct libnvme_version) * * Return: Returns version string for known types or else "n/a" */ -const char *nvme_get_version(enum nvme_version type); +const char *libnvme_get_version(enum libnvme_version type); /** - * nvme_uuid_to_string - Return string represenation of encoded UUID + * libnvme_uuid_to_string - Return string represenation of encoded UUID * @uuid: Binary encoded input UUID * @str: Output string represenation of UUID * * Return: Returns error code if type conversion fails. */ -int nvme_uuid_to_string(unsigned char uuid[NVME_UUID_LEN], char *str); +int libnvme_uuid_to_string(unsigned char uuid[NVME_UUID_LEN], char *str); /** - * nvme_uuid_from_string - Return encoded UUID represenation of string UUID + * libnvme_uuid_from_string - Return encoded UUID represenation of string UUID * @uuid: Binary encoded input UUID * @str: Output string represenation of UUID * * Return: Returns error code if type conversion fails. */ -int nvme_uuid_from_string(const char *str, unsigned char uuid[NVME_UUID_LEN]); +int libnvme_uuid_from_string(const char *str, unsigned char uuid[NVME_UUID_LEN]); /** - * nvme_random_uuid - Generate random UUID + * libnvme_random_uuid - Generate random UUID * @uuid: Generated random UUID * * Generate random number according @@ -246,23 +247,24 @@ int nvme_uuid_from_string(const char *str, unsigned char uuid[NVME_UUID_LEN]); * * Return: Returns error code if generating of random number fails. */ -int nvme_random_uuid(unsigned char uuid[NVME_UUID_LEN]); +int libnvme_random_uuid(unsigned char uuid[NVME_UUID_LEN]); /** - * nvme_find_uuid - Find UUID position on UUID list + * libnvme_find_uuid - Find UUID position on UUID list * @uuid_list: UUID list returned by identify UUID * @uuid: Binary encoded input UUID * * Return: The array position where given UUID is present, or -1 on failure * with errno set. */ -int nvme_find_uuid(struct nvme_id_uuid_list *uuid_list, +int libnvme_find_uuid(struct nvme_id_uuid_list *uuid_list, const unsigned char uuid[NVME_UUID_LEN]); /** - * nvme_basename - Return the final path component (the one after the last '/') + * libnvme_basename - Return the final path component (the one + * after the last '/') * @path: A string containing a filesystem path * * Return: A pointer into the original null-terminated path string. */ -char *nvme_basename(const char *path); +char *libnvme_basename(const char *path); diff --git a/libnvme/test/config/config-dump.c b/libnvme/test/config/config-dump.c index 0c68195d62..1139d1c92d 100644 --- a/libnvme/test/config/config-dump.c +++ b/libnvme/test/config/config-dump.c @@ -14,30 +14,30 @@ static bool config_dump(const char *file) { - struct nvme_global_ctx *ctx; + struct libnvme_global_ctx *ctx; bool pass = false; int err; - ctx = nvme_create_global_ctx(stderr, LOG_ERR); + ctx = libnvme_create_global_ctx(stderr, LOG_ERR); if (!ctx) return false; - err = nvme_scan_topology(ctx, NULL, NULL); + err = libnvme_scan_topology(ctx, NULL, NULL); if (err < 0 && err != -ENOENT) goto out; - err = nvme_read_config(ctx, file); + err = libnvme_read_config(ctx, file); if (err) goto out; - err = nvme_dump_config(ctx, STDOUT_FILENO); + err = libnvme_dump_config(ctx, STDOUT_FILENO); if (err) goto out; pass = true; out: - nvme_free_global_ctx(ctx); + libnvme_free_global_ctx(ctx); return pass; } diff --git a/libnvme/test/config/hostnqn-order.c b/libnvme/test/config/hostnqn-order.c index 7500b96675..bb73f503f8 100644 --- a/libnvme/test/config/hostnqn-order.c +++ b/libnvme/test/config/hostnqn-order.c @@ -13,23 +13,23 @@ static bool command_line(void) { - struct nvme_global_ctx *ctx; + struct libnvme_global_ctx *ctx; bool pass = false; int err; char *hostnqn, *hostid, *hnqn, *hid; - ctx = nvme_create_global_ctx(stderr, LOG_ERR); + ctx = libnvme_create_global_ctx(stderr, LOG_ERR); if (!ctx) return false; - err = nvme_scan_topology(ctx, NULL, NULL); + err = libnvme_scan_topology(ctx, NULL, NULL); if (err && err != ENOENT) goto out; hostnqn = "nqn.2014-08.org.nvmexpress:uuid:ce4fee3e-c02c-11ee-8442-830d068a36c6"; hostid = "ce4fee3e-c02c-11ee-8442-830d068a36c6"; - err = nvme_host_get_ids(ctx, hostnqn, hostid, &hnqn, &hid); + err = libnvme_host_get_ids(ctx, hostnqn, hostid, &hnqn, &hid); if (err) goto out; @@ -48,13 +48,13 @@ static bool command_line(void) pass = true; out: - nvme_free_global_ctx(ctx); + libnvme_free_global_ctx(ctx); return pass; } static bool json_config(char *file) { - struct nvme_global_ctx *ctx; + struct libnvme_global_ctx *ctx; bool pass = false; int err; char *hostnqn, *hostid, *hnqn, *hid; @@ -62,23 +62,23 @@ static bool json_config(char *file) setenv("LIBNVME_HOSTNQN", "", 1); setenv("LIBNVME_HOSTID", "", 1); - ctx = nvme_create_global_ctx(stderr, LOG_ERR); + ctx = libnvme_create_global_ctx(stderr, LOG_ERR); if (!ctx) return false; /* We need to read the config in before we scan */ - err = nvme_read_config(ctx, file); + err = libnvme_read_config(ctx, file); if (err) goto out; - err = nvme_scan_topology(ctx, NULL, NULL); + err = libnvme_scan_topology(ctx, NULL, NULL); if (err && err != ENOENT) goto out; hostnqn = "nqn.2014-08.org.nvmexpress:uuid:2cd2c43b-a90a-45c1-a8cd-86b33ab273b5"; hostid = "2cd2c43b-a90a-45c1-a8cd-86b33ab273b5"; - err = nvme_host_get_ids(ctx, NULL, NULL, &hnqn, &hid); + err = libnvme_host_get_ids(ctx, NULL, NULL, &hnqn, &hid); if (err) goto out; @@ -97,13 +97,13 @@ static bool json_config(char *file) pass = true; out: - nvme_free_global_ctx(ctx); + libnvme_free_global_ctx(ctx); return pass; } static bool from_file(void) { - struct nvme_global_ctx *ctx; + struct libnvme_global_ctx *ctx; bool pass = false; int err; char *hostnqn, *hostid, *hnqn, *hid; @@ -114,15 +114,15 @@ static bool from_file(void) setenv("LIBNVME_HOSTNQN", hostnqn, 1); setenv("LIBNVME_HOSTID", hostid, 1); - ctx = nvme_create_global_ctx(stderr, LOG_ERR); + ctx = libnvme_create_global_ctx(stderr, LOG_ERR); if (!ctx) return false; - err = nvme_scan_topology(ctx, NULL, NULL); + err = libnvme_scan_topology(ctx, NULL, NULL); if (err && err != ENOENT) goto out; - err = nvme_host_get_ids(ctx, NULL, NULL, &hnqn, &hid); + err = libnvme_host_get_ids(ctx, NULL, NULL, &hnqn, &hid); if (err) goto out; @@ -141,7 +141,7 @@ static bool from_file(void) pass = true; out: - nvme_free_global_ctx(ctx); + libnvme_free_global_ctx(ctx); return pass; } diff --git a/libnvme/test/config/psk-json.c b/libnvme/test/config/psk-json.c index b83ebfb32a..f2fe1905cd 100644 --- a/libnvme/test/config/psk-json.c +++ b/libnvme/test/config/psk-json.c @@ -15,32 +15,32 @@ #include "nvme/linux.h" #include "nvme/tree.h" -static bool import_export_key(struct nvme_global_ctx *ctx, nvme_ctrl_t c) +static bool import_export_key(struct libnvme_global_ctx *ctx, libnvme_ctrl_t c) { unsigned char version, hmac, *key; char *encoded_key; size_t len; int ret; - ret = nvme_import_tls_key_versioned(ctx, nvme_ctrl_get_tls_key(c), + ret = libnvme_import_tls_key_versioned(ctx, libnvme_ctrl_get_tls_key(c), &version, &hmac, &len, &key); if (ret) { - printf("ERROR: nvme_import_tls_key_versioned failed with %d\n", + printf("ERROR: libnvme_import_tls_key_versioned failed with %d\n", ret); return false; } - ret = nvme_export_tls_key_versioned(ctx, version, hmac, key, len, + ret = libnvme_export_tls_key_versioned(ctx, version, hmac, key, len, &encoded_key); free(key); if (ret) { - printf("ERROR: nvme_export_tls_key_versioned failed with %d\n", + printf("ERROR: libnvme_export_tls_key_versioned failed with %d\n", ret); return false; } - nvme_ctrl_set_tls_key(c, encoded_key); + libnvme_ctrl_set_tls_key(c, encoded_key); free(encoded_key); @@ -49,36 +49,36 @@ static bool import_export_key(struct nvme_global_ctx *ctx, nvme_ctrl_t c) static bool psk_json_test(char *file) { - struct nvme_global_ctx *ctx; + struct libnvme_global_ctx *ctx; bool pass = false; - nvme_host_t h; - nvme_subsystem_t s; - nvme_ctrl_t c; + libnvme_host_t h; + libnvme_subsystem_t s; + libnvme_ctrl_t c; int err; - ctx = nvme_create_global_ctx(stderr, LOG_ERR); + ctx = libnvme_create_global_ctx(stderr, LOG_ERR); if (!ctx) return false; - err = nvme_read_config(ctx, file); + err = libnvme_read_config(ctx, file); if (err) goto out; - nvme_for_each_host(ctx, h) - nvme_for_each_subsystem(h, s) - nvme_subsystem_for_each_ctrl(s, c) + libnvme_for_each_host(ctx, h) + libnvme_for_each_subsystem(h, s) + libnvme_subsystem_for_each_ctrl(s, c) if (!import_export_key(ctx, c)) goto out; - err = nvme_dump_config(ctx, STDOUT_FILENO); + err = libnvme_dump_config(ctx, STDOUT_FILENO); if (err) goto out; pass = true; out: - nvme_free_global_ctx(ctx); + libnvme_free_global_ctx(ctx); return pass; } diff --git a/libnvme/test/cpp.cc b/libnvme/test/cpp.cc index 6cd0778bea..f1789aa4c7 100644 --- a/libnvme/test/cpp.cc +++ b/libnvme/test/cpp.cc @@ -12,65 +12,65 @@ int main() { - struct nvme_global_ctx *ctx; - nvme_host_t h; - nvme_subsystem_t s; - nvme_ctrl_t c; - nvme_path_t p; - nvme_ns_t n; + struct libnvme_global_ctx *ctx; + libnvme_host_t h; + libnvme_subsystem_t s; + libnvme_ctrl_t c; + libnvme_path_t p; + libnvme_ns_t n; int err; - ctx = nvme_create_global_ctx(stdout, DEFAULT_LOGLEVEL); + ctx = libnvme_create_global_ctx(stdout, DEFAULT_LOGLEVEL); if (!ctx) return 1; - err = nvme_scan_topology(ctx, NULL, NULL); + err = libnvme_scan_topology(ctx, NULL, NULL); if (err && !(err == -ENOENT || err == -EACCES)) { - fprintf(stderr, "nvme_scan_topology failed %d\n", err); - nvme_free_global_ctx(ctx); + fprintf(stderr, "libnvme_scan_topology failed %d\n", err); + libnvme_free_global_ctx(ctx); return 1; } - nvme_for_each_host(ctx, h) { - nvme_for_each_subsystem(h, s) { - std::cout << nvme_subsystem_get_name(s) - << " - NQN=" << nvme_subsystem_get_subsysnqn(s) + libnvme_for_each_host(ctx, h) { + libnvme_for_each_subsystem(h, s) { + std::cout << libnvme_subsystem_get_name(s) + << " - NQN=" << libnvme_subsystem_get_subsysnqn(s) << "\n"; - nvme_subsystem_for_each_ctrl(s, c) { - std::cout << " `- " << nvme_ctrl_get_name(c) - << " " << nvme_ctrl_get_transport(c) - << " " << nvme_ctrl_get_traddr(c) - << " " << nvme_ctrl_get_state(c) + libnvme_subsystem_for_each_ctrl(s, c) { + std::cout << " `- " << libnvme_ctrl_get_name(c) + << " " << libnvme_ctrl_get_transport(c) + << " " << libnvme_ctrl_get_traddr(c) + << " " << libnvme_ctrl_get_state(c) << "\n"; - nvme_ctrl_for_each_ns(c, n) { + libnvme_ctrl_for_each_ns(c, n) { std::cout << " `- " - << nvme_ns_get_name(n) + << libnvme_ns_get_name(n) << "lba size:" - << nvme_ns_get_lba_size(n) + << libnvme_ns_get_lba_size(n) << " lba max:" - << nvme_ns_get_lba_count(n) + << libnvme_ns_get_lba_count(n) << "\n"; } - nvme_ctrl_for_each_path(c, p) { + libnvme_ctrl_for_each_path(c, p) { std::cout << " `- " - << nvme_path_get_name(p) + << libnvme_path_get_name(p) << " " - << nvme_path_get_ana_state(p) + << libnvme_path_get_ana_state(p) << "\n"; } } - nvme_subsystem_for_each_ns(s, n) { - std::cout << " `- " << nvme_ns_get_name(n) + libnvme_subsystem_for_each_ns(s, n) { + std::cout << " `- " << libnvme_ns_get_name(n) << "lba size:" - << nvme_ns_get_lba_size(n) + << libnvme_ns_get_lba_size(n) << " lba max:" - << nvme_ns_get_lba_count(n) << "\n"; + << libnvme_ns_get_lba_count(n) << "\n"; } } } std::cout << "\n"; - nvme_free_global_ctx(ctx); + libnvme_free_global_ctx(ctx); return 0; } diff --git a/libnvme/test/ioctl/ana.c b/libnvme/test/ioctl/ana.c index 411e15324c..1bb2012bb7 100644 --- a/libnvme/test/ioctl/ana.c +++ b/libnvme/test/ioctl/ana.c @@ -16,7 +16,7 @@ #define TEST_FD 0xFD #define PDU_SIZE NVME_LOG_PAGE_PDU_SIZE -static struct nvme_transport_handle *test_hdl; +static struct libnvme_transport_handle *test_hdl; static void test_no_retries(void) { @@ -24,7 +24,7 @@ static void test_no_retries(void) __u32 len = sizeof(log); /* max_retries = 0 is nonsensical */ - check(nvme_get_ana_log_atomic(test_hdl, false, false, + check(libnvme_get_ana_log_atomic(test_hdl, false, false, &log, &len, 0) == -EINVAL, "get log page succeeded"); } @@ -35,7 +35,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_hdl, false, false, + check(libnvme_get_ana_log_atomic(test_hdl, false, false, &log, &len, 1) == -ENOSPC, "get log page succeeded"); } @@ -58,7 +58,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_hdl, false, false, &log, &len, 1), + check(!libnvme_get_ana_log_atomic(test_hdl, false, false, &log, &len, 1), "get log page failed"); end_mock_cmds(); cmp(&log, &header, sizeof(header), "incorrect header"); @@ -96,7 +96,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_hdl, false, true, log, &len, 1), + check(!libnvme_get_ana_log_atomic(test_hdl, false, true, log, &len, 1), "get log page failed"); end_mock_cmds(); cmp(log, log_page, sizeof(log_page), "incorrect log page"); @@ -137,7 +137,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_hdl, false, false, log, &len, 1), + check(!libnvme_get_ana_log_atomic(test_hdl, false, false, log, &len, 1), "get log page failed"); end_mock_cmds(); cmp(log, log_page, sizeof(log_page), "incorrect log page"); @@ -178,7 +178,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_hdl, true, true, log, &len, 1), + check(!libnvme_get_ana_log_atomic(test_hdl, true, true, log, &len, 1), "get log page failed"); end_mock_cmds(); cmp(log, log_page, sizeof(log_page), "incorrect log page"); @@ -244,7 +244,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_hdl, false, false, log, &len, 1), + check(!libnvme_get_ana_log_atomic(test_hdl, false, false, log, &len, 1), "get log page failed"); end_mock_cmds(); cmp(log, log_page, sizeof(log_page), "incorrect log page"); @@ -316,7 +316,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_hdl, true, false, log, &len, 1), + check(!libnvme_get_ana_log_atomic(test_hdl, true, false, log, &len, 1), "get log page failed"); end_mock_cmds(); cmp(log, log_page, sizeof(log_page), "incorrect log page"); @@ -392,7 +392,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_hdl, true, true, log, &len, 2), + check(!libnvme_get_ana_log_atomic(test_hdl, true, true, log, &len, 2), "get log page failed"); end_mock_cmds(); cmp(log, log_page2, sizeof(log_page2), "incorrect log page"); @@ -474,7 +474,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_hdl, false, false, log, &len, 2), + check(!libnvme_get_ana_log_atomic(test_hdl, false, false, log, &len, 2), "get log page failed"); end_mock_cmds(); cmp(log, log_page2, sizeof(log_page2), "incorrect log page"); @@ -570,7 +570,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_hdl, true, false, log, &len, 2) == -EAGAIN, + check(libnvme_get_ana_log_atomic(test_hdl, true, false, log, &len, 2) == -EAGAIN, "get log page succeeded"); end_mock_cmds(); free(log); @@ -610,7 +610,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_hdl, true, false, log, &len, 2) == -ENOSPC, + check(libnvme_get_ana_log_atomic(test_hdl, true, false, log, &len, 2) == -ENOSPC, "log page succeeded"); end_mock_cmds(); free(log); @@ -628,11 +628,11 @@ static void run_test(const char *test_name, void (*test_fn)(void)) int main(void) { - struct nvme_global_ctx *ctx = - nvme_create_global_ctx(stdout, DEFAULT_LOGLEVEL); + struct libnvme_global_ctx *ctx = + libnvme_create_global_ctx(stdout, DEFAULT_LOGLEVEL); set_mock_fd(TEST_FD); - check(!nvme_open(ctx, "NVME_TEST_FD", &test_hdl), + check(!libnvme_open(ctx, "NVME_TEST_FD", &test_hdl), "opening test link failed"); RUN_TEST(no_retries); @@ -648,5 +648,5 @@ int main(void) RUN_TEST(chgcnt_max_retries); RUN_TEST(buffer_too_short); - nvme_free_global_ctx(ctx); + libnvme_free_global_ctx(ctx); } diff --git a/libnvme/test/ioctl/discovery.c b/libnvme/test/ioctl/discovery.c index a39621d8b3..a51574af97 100644 --- a/libnvme/test/ioctl/discovery.c +++ b/libnvme/test/ioctl/discovery.c @@ -16,7 +16,7 @@ #define TEST_FD 0xFD #define HEADER_LEN 20 -static struct nvme_transport_handle *test_hdl; +static struct libnvme_transport_handle *test_hdl; static void arbitrary_ascii_string(size_t max_len, char *str, char *log_str) { @@ -58,7 +58,7 @@ static void arbitrary_entries(size_t len, arbitrary_entry(&entries[i], &log_entries[i]); } -static void test_no_entries(nvme_ctrl_t c) +static void test_no_entries(libnvme_ctrl_t c) { struct nvmf_discovery_log header = {}; /* No entries to fetch after fetching the header */ @@ -80,7 +80,7 @@ static void test_no_entries(nvme_ctrl_t c) free(log); } -static void test_four_entries(nvme_ctrl_t c) +static void test_four_entries(libnvme_ctrl_t c) { size_t num_entries = 4; struct nvmf_disc_log_entry entries[num_entries]; @@ -125,7 +125,7 @@ static void test_four_entries(nvme_ctrl_t c) free(log); } -static void test_five_entries(nvme_ctrl_t c) +static void test_five_entries(libnvme_ctrl_t c) { size_t num_entries = 5; struct nvmf_disc_log_entry entries[num_entries]; @@ -184,7 +184,7 @@ static void test_five_entries(nvme_ctrl_t c) free(log); } -static void test_genctr_change(nvme_ctrl_t c) +static void test_genctr_change(libnvme_ctrl_t c) { struct nvmf_disc_log_entry entries1[1]; struct nvmf_discovery_log header1 = { @@ -252,7 +252,7 @@ static void test_genctr_change(nvme_ctrl_t c) free(log); } -static void test_max_retries(nvme_ctrl_t c) +static void test_max_retries(libnvme_ctrl_t c) { struct nvmf_disc_log_entry entry; struct nvmf_discovery_log header1 = {.numrec = cpu_to_le64(1)}; @@ -313,7 +313,7 @@ static void test_max_retries(nvme_ctrl_t c) check(!log, "unexpected log page returned"); } -static void test_header_error(nvme_ctrl_t c) +static void test_header_error(libnvme_ctrl_t c) { /* Stop after an error in fetching the header the first time */ struct mock_cmd mock_admin_cmds[] = { @@ -333,7 +333,7 @@ static void test_header_error(nvme_ctrl_t c) check(!log, "unexpected log page returned"); } -static void test_entries_error(nvme_ctrl_t c) +static void test_entries_error(libnvme_ctrl_t c) { struct nvmf_discovery_log header = {.numrec = cpu_to_le64(1)}; size_t entry_size = sizeof(struct nvmf_disc_log_entry); @@ -363,7 +363,7 @@ static void test_entries_error(nvme_ctrl_t c) check(!log, "unexpected log page returned"); } -static void test_genctr_error(nvme_ctrl_t c) +static void test_genctr_error(libnvme_ctrl_t c) { struct nvmf_disc_log_entry entry; struct nvmf_discovery_log header = {.numrec = cpu_to_le64(1)}; @@ -401,10 +401,10 @@ static void test_genctr_error(nvme_ctrl_t c) check(!log, "unexpected log page returned"); } -static void run_test(struct nvme_global_ctx *ctx, const char *test_name, - void (*test_fn)(nvme_ctrl_t)) +static void run_test(struct libnvme_global_ctx *ctx, const char *test_name, + void (*test_fn)(libnvme_ctrl_t)) { - struct nvme_ctrl c = { .ctx = ctx, .hdl = test_hdl }; + struct libnvme_ctrl c = { .ctx = ctx, .hdl = test_hdl }; printf("Running test %s...", test_name); fflush(stdout); @@ -418,11 +418,11 @@ static void run_test(struct nvme_global_ctx *ctx, const char *test_name, int main(void) { - struct nvme_global_ctx *ctx = - nvme_create_global_ctx(stdout, DEFAULT_LOGLEVEL); + struct libnvme_global_ctx *ctx = + libnvme_create_global_ctx(stdout, DEFAULT_LOGLEVEL); set_mock_fd(TEST_FD); - check(!nvme_open(ctx, "NVME_TEST_FD", &test_hdl), + check(!libnvme_open(ctx, "NVME_TEST_FD", &test_hdl), "opening test link failed"); RUN_TEST(no_entries); @@ -434,5 +434,5 @@ int main(void) RUN_TEST(entries_error); RUN_TEST(genctr_error); - nvme_free_global_ctx(ctx); + libnvme_free_global_ctx(ctx); } diff --git a/libnvme/test/ioctl/features.c b/libnvme/test/ioctl/features.c index 5c4eddcf1e..ca9839ab26 100644 --- a/libnvme/test/ioctl/features.c +++ b/libnvme/test/ioctl/features.c @@ -22,7 +22,7 @@ #define TEST_SEL NVME_GET_FEATURES_SEL_SAVED #define TEST_SC NVME_SC_INVALID_FIELD -static struct nvme_transport_handle *test_hdl; +static struct libnvme_transport_handle *test_hdl; static void test_set_features(void) { @@ -42,7 +42,7 @@ static void test_set_features(void) .timeout_ms = TEST_TIMEOUT, .result = TEST_RESULT, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(data, sizeof(data)); @@ -57,7 +57,7 @@ static void test_set_features(void) cmd.data_len = sizeof(data); cmd.addr = (__u64)(uintptr_t)data; cmd.timeout_ms = TEST_TIMEOUT; - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "set features returned error %d", err); check(cmd.result == TEST_RESULT, @@ -79,7 +79,7 @@ static void test_get_features(void) .out_data = data, .result = TEST_RESULT, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(data, sizeof(data)); @@ -91,7 +91,7 @@ static void test_get_features(void) cmd.data_len = sizeof(get_data); cmd.addr = (__u64)(uintptr_t)get_data; cmd.timeout_ms = TEST_TIMEOUT; - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "get features returned error %d", err); check(cmd.result == TEST_RESULT, @@ -111,7 +111,7 @@ static void test_get_features_data(void) .out_data = data, .result = TEST_RESULT, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(data, sizeof(data)); @@ -120,7 +120,7 @@ static void test_get_features_data(void) cmd.nsid = TEST_NSID; cmd.data_len = sizeof(get_data); cmd.addr = (__u64)(uintptr_t)get_data; - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "set features returned error %d", err); check(cmd.result == TEST_RESULT, @@ -138,12 +138,12 @@ static void test_set_arbitration(void) .cdw11 = (uint32_t)HPW << 24 | MPW << 16 | LPW << 8 | AB, .result = TEST_RESULT, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_set_features_arbitration(&cmd, false, AB, LPW, MPW, HPW); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "set features returned error %d", err); check(cmd.result == TEST_RESULT, @@ -158,12 +158,12 @@ static void test_get_arbitration(void) .cdw10 = TEST_SEL << 8 | NVME_FEAT_FID_ARBITRATION, .result = TEST_RESULT, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_get_features_arbitration(&cmd, TEST_SEL); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "get features returned error %d", err); check(cmd.result == TEST_RESULT, @@ -181,12 +181,12 @@ static void test_set_power_mgmt(void) .cdw11 = WH << 5 | PS, .result = TEST_RESULT, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_set_features_power_mgmt(&cmd, true, PS, WH); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "set features returned error %d", err); check(cmd.result == TEST_RESULT, @@ -201,12 +201,12 @@ static void test_get_power_mgmt(void) .cdw10 = TEST_SEL << 8 | NVME_FEAT_FID_POWER_MGMT, .result = TEST_RESULT, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_get_features_power_mgmt(&cmd, TEST_SEL); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "get features returned error %d", err); check(cmd.result == TEST_RESULT, @@ -227,14 +227,14 @@ static void test_set_lba_range(void) .cdw11 = NUM - 1, .result = TEST_RESULT, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&range_types, sizeof(range_types)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_set_features_lba_range(&cmd, TEST_NSID, false, NUM, &range_types); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "set features returned error %d", err); check(cmd.result == TEST_RESULT, @@ -253,14 +253,14 @@ static void test_get_lba_range(void) .out_data = &range_types, .result = TEST_RESULT, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&range_types, sizeof(range_types)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_get_features_lba_range(&cmd, TEST_NSID, TEST_SEL, &get_range_types); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "get features returned error %d", err); check(cmd.result == TEST_RESULT, @@ -283,12 +283,12 @@ static void test_set_temp_thresh(void) .cdw11 = THSEL << 20 | TMPSEL << 16 | TMPTH, .result = TEST_RESULT, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_set_features_temp_thresh(&cmd, true, TMPTH, TMPSEL, THSEL, 0); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "set features returned error %d", err); check(cmd.result == TEST_RESULT, @@ -308,12 +308,12 @@ static void test_get_temp_thresh(void) .cdw11 = NVME_FEATURE_TEMPTHRESH_THSEL_OVER << 20, .result = TEST_RESULT, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_get_features_temp_thresh(&cmd, TEST_SEL, 0, 0); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "get features returned error %d", err); check(cmd.result == TEST_RESULT, @@ -332,12 +332,12 @@ static void test_set_err_recovery(void) | TLER, .result = TEST_RESULT, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_set_features_err_recovery(&cmd, TEST_NSID, false, TLER, true); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "set features returned error %d", err); check(cmd.result == TEST_RESULT, @@ -353,12 +353,12 @@ static void test_get_err_recovery(void) .cdw10 = TEST_SEL << 8 | NVME_FEAT_FID_ERR_RECOVERY, .result = TEST_RESULT, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_get_features_err_recovery(&cmd, TEST_NSID, TEST_SEL); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "get features returned error %d", err); check(cmd.result == TEST_RESULT, @@ -375,12 +375,12 @@ static void test_set_volatile_wc(void) .cdw11 = 1 << 0, /* WCE */ .result = TEST_RESULT, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_set_features_volatile_wc(&cmd, true, true); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "set features returned error %d", err); check(cmd.result == TEST_RESULT, @@ -396,12 +396,12 @@ static void test_get_volatile_wc(void) | NVME_FEAT_FID_VOLATILE_WC, .result = TEST_RESULT, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_get_features_volatile_wc(&cmd, TEST_SEL); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "get features returned error %d", err); check(cmd.result == TEST_RESULT, @@ -416,12 +416,12 @@ static void test_get_num_queues(void) .cdw10 = TEST_SEL << 8 | NVME_FEAT_FID_NUM_QUEUES, .result = TEST_RESULT, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_get_features_num_queues(&cmd, TEST_SEL); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "get features returned error %d", err); check(cmd.result == TEST_RESULT, @@ -438,12 +438,12 @@ static void test_set_irq_coalesce(void) .cdw11 = TIME << 8 | THR, .result = TEST_RESULT, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_set_features_irq_coalesce(&cmd, false, THR, TIME); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "set features returned error %d", err); check(cmd.result == TEST_RESULT, @@ -458,12 +458,12 @@ static void test_get_irq_coalesce(void) .cdw10 = TEST_SEL << 8 | NVME_FEAT_FID_IRQ_COALESCE, .result = TEST_RESULT, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_get_features_irq_coalesce(&cmd, TEST_SEL); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "get features returned error %d", err); check(cmd.result == TEST_RESULT, @@ -482,12 +482,12 @@ static void test_set_irq_config(void) | IV, .result = TEST_RESULT, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_set_features_irq_config(&cmd, true, IV, true); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "set features returned error %d", err); check(cmd.result == TEST_RESULT, @@ -504,12 +504,12 @@ static void test_get_irq_config(void) .cdw11 = IV, .result = TEST_RESULT, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_get_features_irq_config(&cmd, TEST_SEL, IV, false); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "get features returned error %d", err); check(cmd.result == TEST_RESULT, @@ -525,12 +525,12 @@ static void test_set_write_atomic(void) .cdw11 = 1 << 0, /* DN */ .result = TEST_RESULT, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_set_features_write_atomic(&cmd, false, true); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "set features returned error %d", err); check(cmd.result == TEST_RESULT, @@ -545,12 +545,12 @@ static void test_get_write_atomic(void) .cdw10 = TEST_SEL << 8 | NVME_FEAT_FID_WRITE_ATOMIC, .result = TEST_RESULT, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_get_features_write_atomic(&cmd, TEST_SEL); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "get features returned error %d", err); check(cmd.result == TEST_RESULT, @@ -568,12 +568,12 @@ static void test_set_async_event(void) .cdw11 = EVENTS, .result = TEST_RESULT, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_set_features_async_event(&cmd, true, EVENTS); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "set features returned error %d", err); check(cmd.result == TEST_RESULT, @@ -588,12 +588,12 @@ static void test_get_async_event(void) .cdw10 = TEST_SEL << 8 | NVME_FEAT_FID_ASYNC_EVENT, .result = TEST_RESULT, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_get_features_async_event(&cmd, TEST_SEL); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "get features returned error %d", err); check(cmd.result == TEST_RESULT, @@ -612,13 +612,13 @@ static void test_set_auto_pst(void) .cdw11 = 1 << 0, /* APSTE */ .result = TEST_RESULT, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&apst, sizeof(apst)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_set_features_auto_pst(&cmd, false, true, &apst); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "set features returned error %d", err); check(cmd.result == TEST_RESULT, @@ -636,13 +636,13 @@ static void test_get_auto_pst(void) .out_data = &apst, .result = TEST_RESULT, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&apst, sizeof(apst)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_get_features_auto_pst(&cmd, TEST_SEL, &get_apst); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "get features returned error %d", err); check(cmd.result == TEST_RESULT, @@ -661,13 +661,13 @@ static void test_get_host_mem_buf(void) .out_data = &attrs, .result = TEST_RESULT, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&attrs, sizeof(attrs)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_get_features_host_mem_buf(&cmd, TEST_SEL, &get_attrs); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "get features returned error %d", err); check(cmd.result == TEST_RESULT, @@ -693,12 +693,12 @@ static void test_set_timestamp(void) .cdw10 = (uint32_t)1 << 31 /* SAVE */ | NVME_FEAT_FID_TIMESTAMP, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_set_features_timestamp(&cmd, true, timestamp, &buf); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "set features returned error %d", err); } @@ -712,13 +712,13 @@ static void test_get_timestamp(void) .cdw10 = TEST_SEL << 8 | NVME_FEAT_FID_TIMESTAMP, .out_data = &ts, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&ts, sizeof(ts)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_get_features_timestamp(&cmd, TEST_SEL, &get_ts); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "get features returned error %d", err); cmp(&get_ts, &ts, sizeof(ts), "incorrect timestamp"); @@ -731,12 +731,12 @@ static void test_get_kato(void) .cdw10 = TEST_SEL << 8 | NVME_FEAT_FID_KATO, .result = TEST_RESULT, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_get_features_kato(&cmd, TEST_SEL); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "get features returned error %d", err); check(cmd.result == TEST_RESULT, @@ -753,12 +753,12 @@ static void test_set_hctm(void) .cdw11 = (uint32_t)TMT1 << 16 | TMT2, .result = TEST_RESULT, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_set_features_hctm(&cmd, false, TMT2, TMT1); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "set features returned error %d", err); check(cmd.result == TEST_RESULT, @@ -773,12 +773,12 @@ static void test_get_hctm(void) .cdw10 = TEST_SEL << 8 | NVME_FEAT_FID_HCTM, .result = TEST_RESULT, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_get_features_hctm(&cmd, TEST_SEL); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "get features returned error %d", err); check(cmd.result == TEST_RESULT, @@ -795,12 +795,12 @@ static void test_set_nopsc(void) .cdw11 = 1 << 0 /* NOPPME */, .result = TEST_RESULT, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_set_features_nopsc(&cmd, true, true); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "set features returned error %d", err); check(cmd.result == TEST_RESULT, @@ -815,12 +815,12 @@ static void test_get_nopsc(void) .cdw10 = TEST_SEL << 8 | NVME_FEAT_FID_NOPSC, .result = TEST_RESULT, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_get_features_nopsc(&cmd, TEST_SEL); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "get features returned error %d", err); check(cmd.result == TEST_RESULT, @@ -839,12 +839,12 @@ static void test_set_rrl(void) .cdw12 = RRL, .result = TEST_RESULT, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_set_features_rrl(&cmd, false, NVMSETID, RRL); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "set features returned error %d", err); check(cmd.result == TEST_RESULT, @@ -860,12 +860,12 @@ static void test_get_rrl(void) .cdw10 = TEST_SEL << 8 | NVME_FEAT_FID_RRL, .result = TEST_RESULT, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_get_features_rrl(&cmd, TEST_SEL); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "get features returned error %d", err); check(cmd.result == TEST_RESULT, @@ -887,13 +887,13 @@ static void test_set_plm_config(void) .cdw12 = 1 << 0 /* Predictable Latency Enable */, .result = TEST_RESULT, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&config, sizeof(config)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_set_features_plm_config(&cmd, true, NVMSETID, true, &config); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "set features returned error %d", err); check(cmd.result == TEST_RESULT, @@ -913,14 +913,14 @@ static void test_get_plm_config(void) .out_data = &config, .result = TEST_RESULT, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&config, sizeof(config)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_get_features_plm_config(&cmd, TEST_SEL, NVMSETID, &get_config); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "get features returned error %d", err); check(cmd.result == TEST_RESULT, @@ -940,12 +940,12 @@ static void test_set_plm_window(void) .cdw12 = SEL, .result = TEST_RESULT, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_set_features_plm_window(&cmd, false, NVMSETID, SEL); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "set features returned error %d", err); check(cmd.result == TEST_RESULT, @@ -962,12 +962,12 @@ static void test_get_plm_window(void) .cdw11 = NVMSETID, .result = TEST_RESULT, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_get_features_plm_window(&cmd, TEST_SEL, NVMSETID); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "get features returned error %d", err); check(cmd.result == TEST_RESULT, @@ -985,12 +985,12 @@ static void test_set_lba_sts_interval(void) .cdw11 = LSIPI << 16 | LSIRI, .result = TEST_RESULT, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_set_features_lba_sts_interval(&cmd, true, LSIRI, LSIPI); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "set features returned error %d", err); check(cmd.result == TEST_RESULT, @@ -1005,12 +1005,12 @@ static void test_get_lba_sts_interval(void) .cdw10 = TEST_SEL << 8 | NVME_FEAT_FID_LBA_STS_INTERVAL, .result = TEST_RESULT, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_get_features_lba_sts_interval(&cmd, TEST_SEL); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "get features returned error %d", err); check(cmd.result == TEST_RESULT, @@ -1028,13 +1028,13 @@ static void test_set_host_behavior(void) .data_len = sizeof(behavior), .cdw10 = NVME_FEAT_FID_HOST_BEHAVIOR, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&behavior, sizeof(behavior)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_set_features_host_behavior(&cmd, false, &behavior); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "set features returned error %d", err); } @@ -1049,13 +1049,13 @@ static void test_get_host_behavior(void) .out_data = &behavior, .result = TEST_RESULT, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&behavior, sizeof(behavior)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_get_features_host_behavior(&cmd, TEST_SEL, &get_behavior); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "get features returned error %d", err); check(cmd.result == TEST_RESULT, @@ -1072,12 +1072,12 @@ static void test_set_sanitize(void) .cdw11 = 1 << 0, /* NODRM */ .result = TEST_RESULT, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_set_features_sanitize(&cmd, false, true); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "set features returned error %d", err); check(cmd.result == TEST_RESULT, @@ -1092,12 +1092,12 @@ static void test_get_sanitize(void) .cdw10 = TEST_SEL << 8 | NVME_FEAT_FID_SANITIZE, .result = TEST_RESULT, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_get_features_sanitize(&cmd, TEST_SEL); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "get features returned error %d", err); check(cmd.result == TEST_RESULT, @@ -1116,12 +1116,12 @@ static void test_set_endurance_evt_cfg(void) .cdw11 = EGWARN << 16 | ENDGID, .result = TEST_RESULT, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_set_features_endurance_evt_cfg(&cmd, true, ENDGID, EGWARN); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "set features returned error %d", err); check(cmd.result == TEST_RESULT, @@ -1138,12 +1138,12 @@ static void test_get_endurance_event_cfg(void) .cdw11 = ENDGID, .result = TEST_RESULT, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_get_features_endurance_event_cfg(&cmd, TEST_SEL, ENDGID); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "get features returned error %d", err); check(cmd.result == TEST_RESULT, @@ -1159,12 +1159,12 @@ static void test_set_iocs_profile(void) .cdw10 = NVME_FEAT_FID_IOCS_PROFILE, .cdw11 = IOCSI, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_set_features_iocs_profile(&cmd, false, IOCSI); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "set features returned error %d", err); } @@ -1176,12 +1176,12 @@ static void test_get_iocs_profile(void) .cdw10 = TEST_SEL << 8 | NVME_FEAT_FID_IOCS_PROFILE, .result = TEST_RESULT, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_get_features_iocs_profile(&cmd, TEST_SEL); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "get features returned error %d", err); check(cmd.result == TEST_RESULT, @@ -1199,12 +1199,12 @@ static void test_set_sw_progress(void) .cdw11 = PBSLC, .result = TEST_RESULT, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_set_features_sw_progress(&cmd, true, PBSLC); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "set features returned error %d", err); check(cmd.result == TEST_RESULT, @@ -1219,12 +1219,12 @@ static void test_get_sw_progress(void) .cdw10 = TEST_SEL << 8 | NVME_FEAT_FID_SW_PROGRESS, .result = TEST_RESULT, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_get_features_sw_progress(&cmd, TEST_SEL); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "get features returned error %d", err); check(cmd.result == TEST_RESULT, @@ -1243,13 +1243,13 @@ static void test_set_host_id(void) | NVME_FEAT_FID_HOST_ID, .result = TEST_RESULT, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(hostid, sizeof(hostid)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_set_features_host_id(&cmd, true, false,hostid); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "set features returned error %d", err); } @@ -1265,13 +1265,13 @@ static void test_set_host_id_extended(void) .cdw11 = 1 << 0, /* EXHID */ .result = TEST_RESULT, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(hostid, sizeof(hostid)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_set_features_host_id(&cmd, false, true, hostid); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "set features returned error %d", err); } @@ -1286,14 +1286,14 @@ static void test_get_host_id(void) .out_data = hostid, .result = TEST_RESULT, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(hostid, sizeof(hostid)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_get_features_host_id(&cmd, TEST_SEL, false, get_hostid, sizeof(hostid)); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "get features returned error %d", err); cmp(get_hostid, hostid, sizeof(hostid), "incorrect host identifier"); @@ -1310,14 +1310,14 @@ static void test_get_host_id_extended(void) .out_data = hostid, .result = TEST_RESULT, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(hostid, sizeof(hostid)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_get_features_host_id(&cmd, TEST_SEL, true, get_hostid, sizeof(hostid)); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "get features returned error %d", err); cmp(get_hostid, hostid, sizeof(hostid), "incorrect host identifier"); @@ -1334,12 +1334,12 @@ static void test_set_resv_mask(void) .cdw11 = MASK, .result = TEST_RESULT, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_set_features_resv_mask(&cmd, TEST_NSID, true, MASK); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "set features returned error %d", err); check(cmd.result == TEST_RESULT, @@ -1355,12 +1355,12 @@ static void test_get_resv_mask(void) .cdw10 = TEST_SEL << 8 | NVME_FEAT_FID_RESV_MASK, .result = TEST_RESULT, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_get_features_resv_mask(&cmd, TEST_NSID, TEST_SEL); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "get features returned error %d", err); check(cmd.result == TEST_RESULT, @@ -1377,12 +1377,12 @@ static void test_set_resv_persist(void) .cdw11 = 1 << 0, /* PTPL */ .result = TEST_RESULT, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_set_features_resv_persist(&cmd, TEST_NSID, false, true); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "set features returned error %d", err); check(cmd.result == TEST_RESULT, @@ -1398,12 +1398,12 @@ static void test_get_resv_persist(void) .cdw10 = TEST_SEL << 8 | NVME_FEAT_FID_RESV_PERSIST, .result = TEST_RESULT, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_get_features_resv_persist(&cmd, TEST_NSID, TEST_SEL); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "get features returned error %d", err); check(cmd.result == TEST_RESULT, @@ -1424,12 +1424,12 @@ static void test_set_write_protect(void) .cdw11 = STATE, .result = TEST_RESULT, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_set_features_write_protect(&cmd, TEST_NSID, true, STATE); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "set features returned error %d", err); check(cmd.result == TEST_RESULT, @@ -1445,12 +1445,12 @@ static void test_get_write_protect(void) .cdw10 = TEST_SEL << 8 | NVME_FEAT_FID_WRITE_PROTECT, .result = TEST_RESULT, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_get_features_write_protect(&cmd, TEST_NSID, TEST_SEL); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "get features returned error %d", err); check(cmd.result == TEST_RESULT, @@ -1473,12 +1473,12 @@ static void test_set_status_code_error(void) .result = TEST_RESULT, .err = TEST_SC, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_set_features_async_event(&cmd, false, EVENTS); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == TEST_SC, "got error %d, expected %d", err, TEST_SC); check(cmd.result == TEST_RESULT, @@ -1497,12 +1497,12 @@ static void test_set_kernel_error(void) .result = 0, .err = -EIO, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_set_features_resv_mask(&cmd, TEST_NSID, false, MASK); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == -EIO, "got error %d, expected -EIO", err); check(!cmd.result, @@ -1522,12 +1522,12 @@ static void test_get_status_code_error(void) .result = TEST_RESULT, .err = TEST_SC, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_get_features_kato(&cmd, TEST_SEL); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == TEST_SC, "got error %d, expected %d", err, TEST_SC); check(cmd.result == TEST_RESULT, @@ -1543,12 +1543,12 @@ static void test_get_kernel_error(void) .result = 0, .err = -EBUSY, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_get_features_num_queues(&cmd, TEST_SEL); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == -EBUSY, "got error %d, expected -EBUSY", err); check(!cmd.result, @@ -1568,13 +1568,13 @@ static void test_lm_set_features_ctrl_data_queue(void) .cdw13 = tpt, .result = TEST_RESULT, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_lm_set_features_ctrl_data_queue(&cmd, TEST_CDQID, hp, tpt, etpt); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "set features returned error %d, errno %m", err); check(cmd.result == TEST_RESULT, @@ -1594,14 +1594,14 @@ static void test_lm_get_features_ctrl_data_queue(void) .out_data = &expected_data, .result = TEST_RESULT, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_data, sizeof(expected_data)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_lm_get_features_ctrl_data_queue(&cmd, TEST_SEL, TEST_CDQID, &data); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "get features returned error %d, errno %m", err); check(cmd.result == TEST_RESULT, @@ -1622,11 +1622,11 @@ static void run_test(const char *test_name, void (*test_fn)(void)) int main(void) { - struct nvme_global_ctx *ctx = - nvme_create_global_ctx(stdout, DEFAULT_LOGLEVEL); + struct libnvme_global_ctx *ctx = + libnvme_create_global_ctx(stdout, DEFAULT_LOGLEVEL); set_mock_fd(TEST_FD); - check(!nvme_open(ctx, "NVME_TEST_FD64", &test_hdl), + check(!libnvme_open(ctx, "NVME_TEST_FD64", &test_hdl), "opening test link failed"); RUN_TEST(set_features); @@ -1698,5 +1698,5 @@ int main(void) RUN_TEST(lm_set_features_ctrl_data_queue); RUN_TEST(lm_get_features_ctrl_data_queue); - nvme_free_global_ctx(ctx); + libnvme_free_global_ctx(ctx); } diff --git a/libnvme/test/ioctl/identify.c b/libnvme/test/ioctl/identify.c index cdafd22b1e..a9b27864bb 100644 --- a/libnvme/test/ioctl/identify.c +++ b/libnvme/test/ioctl/identify.c @@ -19,7 +19,7 @@ #define TEST_FIDX 0xF #define TEST_SC NVME_SC_INVALID_FIELD -static struct nvme_transport_handle *test_hdl; +static struct libnvme_transport_handle *test_hdl; static void test_ns(void) { @@ -31,13 +31,13 @@ static void test_ns(void) .cdw10 = NVME_IDENTIFY_CNS_NS, .out_data = &expected_id, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_id, sizeof(expected_id)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_identify_ns(&cmd, TEST_NSID, &id); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "identify returned error %d, errno %m", err); cmp(&id, &expected_id, sizeof(id), "incorrect identify data"); @@ -52,13 +52,13 @@ static void test_ctrl(void) .cdw10 = NVME_IDENTIFY_CNS_CTRL, .out_data = &expected_id, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_id, sizeof(expected_id)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_identify_ctrl(&cmd, &id); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "identify returned error %d", err); cmp(&id, &expected_id, sizeof(id), "incorrect identify data"); @@ -74,13 +74,13 @@ static void test_active_ns_list(void) .cdw10 = NVME_IDENTIFY_CNS_NS_ACTIVE_LIST, .out_data = &expected_id, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_id, sizeof(expected_id)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_identify_active_ns_list(&cmd, TEST_NSID, &id); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "identify returned error %d", err); cmp(&id, &expected_id, sizeof(id), "incorrect identify data"); @@ -97,7 +97,7 @@ static void test_ns_descs(void) .cdw10 = NVME_IDENTIFY_CNS_NS_DESC_LIST, .out_data = &expected_id, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(expected_id, sizeof(expected_id)); @@ -105,7 +105,7 @@ static void test_ns_descs(void) check(id, "memory allocation failed"); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_identify_ns_descs_list(&cmd, TEST_NSID, id); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "identify returned error %d", err); cmp(id, expected_id, sizeof(expected_id), "incorrect identify data"); @@ -122,13 +122,13 @@ static void test_nvmset_list(void) .cdw11 = TEST_NVMSETID, .out_data = &expected_id, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_id, sizeof(expected_id)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_identify_nvmset_list(&cmd, NVME_NSID_NONE, TEST_NVMSETID, &id); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "identify returned error %d", err); cmp(&id, &expected_id, sizeof(id), "incorrect identify data"); @@ -147,13 +147,13 @@ static void test_ns_csi(void) .cdw14 = TEST_UUID, .out_data = expected_id, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(expected_id, sizeof(expected_id)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_identify_csi_ns(&cmd, TEST_NSID, TEST_CSI, TEST_UUID, id); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "identify returned error %d", err); cmp(id, expected_id, sizeof(id), "incorrect identify data"); @@ -170,13 +170,13 @@ static void test_zns_identify_ns(void) .cdw11 = NVME_CSI_ZNS << 24, .out_data = &expected_id, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_id, sizeof(expected_id)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_zns_identify_ns(&cmd, TEST_NSID, &id); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "identify returned error %d", err); cmp(&id, &expected_id, sizeof(id), "incorrect identify data"); @@ -192,13 +192,13 @@ static void test_nvm_identify_ctrl(void) .cdw11 = NVME_CSI_NVM << 24, .out_data = &expected_id, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_id, sizeof(expected_id)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_identify_csi_ctrl(&cmd, NVME_CSI_NVM, &id); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "identify returned error %d", err); cmp(&id, &expected_id, sizeof(id), "incorrect identify data"); @@ -214,13 +214,13 @@ static void test_zns_identify_ctrl(void) .cdw11 = NVME_CSI_ZNS << 24, .out_data = &expected_id, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_id, sizeof(expected_id)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_zns_identify_ctrl(&cmd, &id); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "identify returned error %d", err); cmp(&id, &expected_id, sizeof(id), "incorrect identify data"); @@ -237,13 +237,13 @@ static void test_active_ns_list_csi(void) .cdw11 = TEST_CSI << 24, .out_data = &expected_id, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_id, sizeof(expected_id)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_identify_csi_active_ns_list(&cmd, TEST_NSID, TEST_CSI, &id); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "identify returned error %d", err); cmp(&id, &expected_id, sizeof(id), "incorrect identify data"); @@ -259,14 +259,14 @@ static void test_independent_identify_ns(void) .cdw10 = NVME_IDENTIFY_CNS_CSI_INDEPENDENT_ID_NS, .out_data = &expected_id, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_id, sizeof(expected_id)); set_mock_admin_cmds(&mock_admin_cmd, 1); /* That's a mouthful! */ nvme_init_identify_csi_independent_identify_id_ns(&cmd, TEST_NSID, &id); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "identify returned error %d", err); cmp(&id, &expected_id, sizeof(id), "incorrect identify data"); @@ -282,13 +282,13 @@ static void test_allocated_ns_list(void) .cdw10 = NVME_IDENTIFY_CNS_ALLOCATED_NS_LIST, .out_data = &expected_id, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_id, sizeof(expected_id)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_identify_allocated_ns_list(&cmd, TEST_NSID, &id); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "identify returned error %d", err); cmp(&id, &expected_id, sizeof(id), "incorrect identify data"); @@ -304,13 +304,13 @@ static void test_allocated_ns(void) .cdw10 = NVME_IDENTIFY_CNS_ALLOCATED_NS, .out_data = &expected_id, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_id, sizeof(expected_id)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_identify_allocated_ns(&cmd, TEST_NSID, &id); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "identify returned error %d", err); cmp(&id, &expected_id, sizeof(id), "incorrect identify data"); @@ -327,13 +327,13 @@ static void test_nsid_ctrl_list(void) | NVME_IDENTIFY_CNS_NS_CTRL_LIST, .out_data = &expected_id, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_id, sizeof(expected_id)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_identify_ns_ctrl_list(&cmd, TEST_NSID, TEST_CNTID, &id); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "identify returned error %d", err); cmp(&id, &expected_id, sizeof(id), "incorrect identify data"); @@ -349,13 +349,13 @@ static void test_ctrl_list(void) | NVME_IDENTIFY_CNS_CTRL_LIST, .out_data = &expected_id, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_id, sizeof(expected_id)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_identify_ctrl_list(&cmd, TEST_CNTID, &id); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "identify returned error %d", err); cmp(&id, &expected_id, sizeof(id), "incorrect identify data"); @@ -371,13 +371,13 @@ static void test_primary_ctrl(void) | NVME_IDENTIFY_CNS_PRIMARY_CTRL_CAP, .out_data = &expected_id, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_id, sizeof(expected_id)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_identify_primary_ctrl_cap(&cmd, TEST_CNTID, &id); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "identify returned error %d", err); cmp(&id, &expected_id, sizeof(id), "incorrect identify data"); @@ -393,13 +393,13 @@ static void test_secondary_ctrl_list(void) | NVME_IDENTIFY_CNS_SECONDARY_CTRL_LIST, .out_data = &expected_id, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_id, sizeof(expected_id)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_identify_secondary_ctrl_list(&cmd, TEST_CNTID, &id); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "identify returned error %d", err); cmp(&id, &expected_id, sizeof(id), "incorrect identify data"); @@ -414,13 +414,13 @@ static void test_ns_granularity(void) .cdw10 = NVME_IDENTIFY_CNS_NS_GRANULARITY, .out_data = &expected_id, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_id, sizeof(expected_id)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_identify_ns_granularity(&cmd, &id); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "identify returned error %d", err); cmp(&id, &expected_id, sizeof(id), "incorrect identify data"); @@ -435,13 +435,13 @@ static void test_uuid(void) .cdw10 = NVME_IDENTIFY_CNS_UUID_LIST, .out_data = &expected_id, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_id, sizeof(expected_id)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_identify_uuid_list(&cmd, &id); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "identify returned error %d", err); cmp(&id, &expected_id, sizeof(id), "incorrect identify data"); @@ -457,13 +457,13 @@ static void test_domain_list(void) .cdw11 = TEST_DOMID, .out_data = &expected_id, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_id, sizeof(expected_id)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_identify_domain_list(&cmd, TEST_DOMID, &id); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "identify returned error %d", err); cmp(&id, &expected_id, sizeof(id), "incorrect identify data"); @@ -479,13 +479,13 @@ static void test_endurance_group_list(void) .cdw11 = TEST_ENDGID, .out_data = &expected_id, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_id, sizeof(expected_id)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_identify_endurance_group_id(&cmd, TEST_ENDGID, &id); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "identify returned error %d", err); cmp(&id, &expected_id, sizeof(id), "incorrect identify data"); @@ -502,13 +502,13 @@ static void test_allocated_ns_list_csi(void) .cdw11 = TEST_CSI << 24, .out_data = &expected_id, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_id, sizeof(expected_id)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_identify_csi_allocated_ns_list(&cmd, TEST_NSID, TEST_CSI, &id); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "identify returned error %d", err); cmp(&id, &expected_id, sizeof(id), "incorrect identify data"); @@ -524,13 +524,13 @@ static void test_iocs(void) | NVME_IDENTIFY_CNS_COMMAND_SET_STRUCTURE, .out_data = &expected_id, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_id, sizeof(expected_id)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_identify_command_set_structure(&cmd, TEST_CNTID, &id); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "identify returned error %d", err); cmp(&id, &expected_id, sizeof(id), "incorrect identify data"); @@ -551,12 +551,12 @@ static void test_status_code_error(void) .cdw11 = TEST_NVMSETID, .err = TEST_SC, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_identify_nvmset_list(&cmd, NVME_NSID_NONE, TEST_NVMSETID, &id); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == TEST_SC, "got error %d, expected TEST_SC", err); } @@ -571,12 +571,12 @@ static void test_kernel_error(void) .cdw10 = NVME_IDENTIFY_CNS_NS, .err = -EIO, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_identify_ns(&cmd, TEST_NSID, &id); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == -EIO, "got error %d, expected -EIO", err); } @@ -594,14 +594,14 @@ static void test_identify_ns_csi_user_data_format(void) .cdw14 = TEST_UUID, .out_data = &expected_id, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_id, sizeof(expected_id)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_identify_ns_user_data_format(&cmd, NVME_CSI_NVM, TEST_FIDX, TEST_UUID, &id); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "identify returned error %d, errno %m", err); cmp(&id, &expected_id, sizeof(id), "incorrect identify data"); @@ -619,14 +619,14 @@ static void test_identify_iocs_ns_csi_user_data_format(void) .cdw14 = TEST_UUID, .out_data = &expected_id, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_id, sizeof(expected_id)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_identify_csi_ns_user_data_format(&cmd, TEST_CSI, TEST_FIDX, TEST_UUID, &id); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "identify returned error %d, errno %m", err); cmp(&id, &expected_id, sizeof(id), "incorrect identify data"); @@ -644,11 +644,11 @@ static void run_test(const char *test_name, void (*test_fn)(void)) int main(void) { - struct nvme_global_ctx * ctx = - nvme_create_global_ctx(stdout, DEFAULT_LOGLEVEL); + struct libnvme_global_ctx * ctx = + libnvme_create_global_ctx(stdout, DEFAULT_LOGLEVEL); set_mock_fd(TEST_FD); - check(!nvme_open(ctx, "NVME_TEST_FD", &test_hdl), + check(!libnvme_open(ctx, "NVME_TEST_FD", &test_hdl), "opening test link failed"); RUN_TEST(ns); @@ -679,5 +679,5 @@ int main(void) RUN_TEST(identify_ns_csi_user_data_format); RUN_TEST(identify_iocs_ns_csi_user_data_format); - nvme_free_global_ctx(ctx); + libnvme_free_global_ctx(ctx); } diff --git a/libnvme/test/ioctl/logs.c b/libnvme/test/ioctl/logs.c index b048a3df98..d6537344dc 100644 --- a/libnvme/test/ioctl/logs.c +++ b/libnvme/test/ioctl/logs.c @@ -21,7 +21,7 @@ #define TEST_LSP NVME_LOG_CDW10_LSP_MASK #define TEST_PEVENT NVME_PEVENT_LOG_RELEASE_CTX -static struct nvme_transport_handle *test_hdl; +static struct libnvme_transport_handle *test_hdl; static void test_get_log_sanitize(void) { @@ -34,13 +34,13 @@ static void test_get_log_sanitize(void) (((sizeof(expected_log) >> 2) - 1) << 16), .out_data = &expected_log, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_get_log_sanitize(&cmd, &log); - err = nvme_get_log(test_hdl, &cmd, true, NVME_LOG_PAGE_PDU_SIZE); + err = libnvme_get_log(test_hdl, &cmd, true, NVME_LOG_PAGE_PDU_SIZE); end_mock_cmds(); check(err == 0, "get log returned error %d, errno %m", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); @@ -57,13 +57,13 @@ static void test_get_log_mgmt_addr_list(void) (((sizeof(expected_log) >> 2) - 1) << 16), .out_data = &expected_log, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_get_log_mgmt_addr_list(&cmd, &log, sizeof(log)); - err = nvme_get_log(test_hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); + err = libnvme_get_log(test_hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); end_mock_cmds(); check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); @@ -81,13 +81,13 @@ static void test_get_log_supported_log_pages(void) (((sizeof(expected_log) >> 2) - 1) << 16), .out_data = &expected_log, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_get_log_supported_log_pages(&cmd, NVME_CSI_NVM, &log); - err = nvme_get_log(test_hdl, &cmd, !TEST_RAE, + err = libnvme_get_log(test_hdl, &cmd, !TEST_RAE, NVME_LOG_PAGE_PDU_SIZE); end_mock_cmds(); check(err == 0, "get log returned error %d", err); @@ -105,13 +105,13 @@ static void test_get_log_error(void) (((sizeof(expected_log) >> 2) - 1) << 16), .out_data = &expected_log, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_get_log_error(&cmd, 1, &log); - err = nvme_get_log(test_hdl, &cmd, TEST_RAE, + err = libnvme_get_log(test_hdl, &cmd, TEST_RAE, NVME_LOG_PAGE_PDU_SIZE); end_mock_cmds(); check(err == 0, "get log returned error %d", err); @@ -129,13 +129,13 @@ static void test_get_log_smart(void) (((sizeof(expected_log) >> 2) - 1) << 16), .out_data = &expected_log, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_get_log_smart(&cmd, TEST_NSID, &log); - err = nvme_get_log(test_hdl, &cmd, TEST_RAE, + err = libnvme_get_log(test_hdl, &cmd, TEST_RAE, NVME_LOG_PAGE_PDU_SIZE); end_mock_cmds(); check(err == 0, "get log returned error %d", err); @@ -153,13 +153,13 @@ static void test_get_log_fw_slot(void) (((sizeof(expected_log) >> 2) - 1) << 16), .out_data = &expected_log, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_get_log_fw_slot(&cmd, &log); - err = nvme_get_log(test_hdl, &cmd, TEST_RAE, + err = libnvme_get_log(test_hdl, &cmd, TEST_RAE, NVME_LOG_PAGE_PDU_SIZE); end_mock_cmds(); check(err == 0, "get log returned error %d", err); @@ -177,13 +177,13 @@ static void test_get_log_changed_ns_list(void) (((sizeof(expected_log) >> 2) - 1) << 16), .out_data = &expected_log, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_get_log_changed_ns(&cmd, &log); - err = nvme_get_log(test_hdl, &cmd, TEST_RAE, NVME_LOG_PAGE_PDU_SIZE); + err = libnvme_get_log(test_hdl, &cmd, TEST_RAE, NVME_LOG_PAGE_PDU_SIZE); end_mock_cmds(); check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); @@ -201,13 +201,13 @@ static void test_get_log_cmd_effects(void) .cdw14 = (TEST_CSI << 24), .out_data = &expected_log, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_get_log_cmd_effects(&cmd, TEST_CSI, &log); - err = nvme_get_log(test_hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); + err = libnvme_get_log(test_hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); end_mock_cmds(); check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); @@ -224,13 +224,13 @@ static void test_get_log_device_self_test(void) (((sizeof(expected_log) >> 2) - 1) << 16), .out_data = &expected_log, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_get_log_device_self_test(&cmd, &log); - err = nvme_get_log(test_hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); + err = libnvme_get_log(test_hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); end_mock_cmds(); check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); @@ -249,13 +249,13 @@ static void test_get_log_create_telemetry_host_mcda(void) (((sizeof(expected_log) >> 2) - 1) << 16), .out_data = &expected_log, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_get_log_create_telemetry_host_mcda(&cmd, TEST_MCDA, &log); - err = nvme_get_log(test_hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); + err = libnvme_get_log(test_hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); end_mock_cmds(); check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); @@ -275,13 +275,13 @@ static void test_get_log_create_telemetry_host(void) (((sizeof(expected_log) >> 2) - 1) << 16), .out_data = &expected_log, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_get_log_create_telemetry_host(&cmd, &log); - err = nvme_get_log(test_hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); + err = libnvme_get_log(test_hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); end_mock_cmds(); check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); @@ -303,13 +303,13 @@ static void test_get_log_telemetry_host(void) .cdw13 = TEST_OFFSET >> 32, .out_data = &expected_log, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_get_log_telemetry_host(&cmd, TEST_OFFSET, &log, sizeof(log)); - err = nvme_get_log(test_hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); + err = libnvme_get_log(test_hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); end_mock_cmds(); check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); @@ -332,13 +332,13 @@ static void test_get_log_telemetry_ctrl(void) .cdw13 = TEST_OFFSET >> 32, .out_data = &expected_log, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_get_log_telemetry_ctrl(&cmd, TEST_OFFSET, &log, sizeof(log)); - err = nvme_get_log(test_hdl, &cmd, TEST_RAE, NVME_LOG_PAGE_PDU_SIZE); + err = libnvme_get_log(test_hdl, &cmd, TEST_RAE, NVME_LOG_PAGE_PDU_SIZE); end_mock_cmds(); check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); @@ -356,13 +356,13 @@ static void test_get_log_endurance_group(void) .cdw11 = (TEST_ENDGID << 16), .out_data = &expected_log, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_get_log_endurance_group(&cmd, TEST_ENDGID, &log); - err = nvme_get_log(test_hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); + err = libnvme_get_log(test_hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); end_mock_cmds(); check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); @@ -380,13 +380,13 @@ static void test_get_log_predictable_lat_nvmset(void) .cdw11 = (TEST_NVMSETID << 16), .out_data = &expected_log, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_get_log_predictable_lat_nvmset(&cmd, TEST_NVMSETID, &log); - err = nvme_get_log(test_hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); + err = libnvme_get_log(test_hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); end_mock_cmds(); check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); @@ -405,14 +405,14 @@ static void test_get_log_predictable_lat_event(void) .cdw12 = TEST_OFFSET_32, .out_data = &expected_log, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_get_log_predictable_lat_event(&cmd, TEST_OFFSET_32, &log, sizeof(log)); - err = nvme_get_log(test_hdl, &cmd, TEST_RAE, NVME_LOG_PAGE_PDU_SIZE); + err = libnvme_get_log(test_hdl, &cmd, TEST_RAE, NVME_LOG_PAGE_PDU_SIZE); end_mock_cmds(); check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); @@ -431,14 +431,14 @@ static void test_get_log_fdp_configurations(void) .cdw12 = TEST_OFFSET_32, .out_data = &expected_log, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_get_log_fdp_configurations(&cmd, TEST_ENDGID, TEST_OFFSET_32, &log, sizeof(log)); - err = nvme_get_log(test_hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); + err = libnvme_get_log(test_hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); end_mock_cmds(); check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); @@ -457,7 +457,7 @@ static void test_get_log_reclaim_unit_handle_usage(void) .cdw12 = TEST_OFFSET_32, .out_data = &expected_log, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_log, sizeof(expected_log)); @@ -465,7 +465,7 @@ static void test_get_log_reclaim_unit_handle_usage(void) nvme_init_get_log_reclaim_unit_handle_usage(&cmd, TEST_ENDGID, TEST_OFFSET_32, &log, sizeof(log)); - err = nvme_get_log(test_hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); + err = libnvme_get_log(test_hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); end_mock_cmds(); check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); @@ -484,14 +484,14 @@ static void test_get_log_fdp_stats(void) .cdw12 = TEST_OFFSET_32, .out_data = &expected_log, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_get_log_fdp_stats(&cmd, TEST_ENDGID, TEST_OFFSET_32, &log, sizeof(log)); - err = nvme_get_log(test_hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); + err = libnvme_get_log(test_hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); end_mock_cmds(); check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); @@ -511,14 +511,14 @@ static void test_get_log_fdp_events(void) .cdw12 = TEST_OFFSET_32, .out_data = &expected_log, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_get_log_fdp_events(&cmd, TEST_EVENTS, TEST_ENDGID, TEST_OFFSET_32, &log, sizeof(log)); - err = nvme_get_log(test_hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); + err = libnvme_get_log(test_hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); end_mock_cmds(); check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); @@ -538,14 +538,14 @@ static void test_get_log_ana(void) .cdw13 = TEST_OFFSET >> 32, .out_data = &expected_log, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_get_log_ana(&cmd, TEST_ANA_LSP, TEST_OFFSET, &log, sizeof(log)); - err = nvme_get_log(test_hdl, &cmd, TEST_RAE, NVME_LOG_PAGE_PDU_SIZE); + err = libnvme_get_log(test_hdl, &cmd, TEST_RAE, NVME_LOG_PAGE_PDU_SIZE); end_mock_cmds(); check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); @@ -564,13 +564,13 @@ static void test_get_log_ana_groups(void) (((sizeof(expected_log) >> 2) - 1) << 16), .out_data = &expected_log, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_get_log_ana_groups(&cmd, &log, sizeof(log)); - err = nvme_get_log(test_hdl, &cmd, TEST_RAE, NVME_LOG_PAGE_PDU_SIZE); + err = libnvme_get_log(test_hdl, &cmd, TEST_RAE, NVME_LOG_PAGE_PDU_SIZE); end_mock_cmds(); check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); @@ -589,13 +589,13 @@ static void test_get_log_lba_status(void) .cdw13 = TEST_OFFSET >> 32, .out_data = &expected_log, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_get_log_lba_status(&cmd, TEST_OFFSET, &log, sizeof(log)); - err = nvme_get_log(test_hdl, &cmd, TEST_RAE, NVME_LOG_PAGE_PDU_SIZE); + err = libnvme_get_log(test_hdl, &cmd, TEST_RAE, NVME_LOG_PAGE_PDU_SIZE); end_mock_cmds(); check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); @@ -614,14 +614,14 @@ static void test_get_log_endurance_grp_evt(void) .cdw12 = TEST_OFFSET_32, .out_data = &expected_log, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_get_log_endurance_grp_evt(&cmd, TEST_OFFSET_32, &log, sizeof(log)); - err = nvme_get_log(test_hdl, &cmd, TEST_RAE, NVME_LOG_PAGE_PDU_SIZE); + err = libnvme_get_log(test_hdl, &cmd, TEST_RAE, NVME_LOG_PAGE_PDU_SIZE); end_mock_cmds(); check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); @@ -639,13 +639,13 @@ static void test_get_log_fid_supported_effects(void) (((sizeof(expected_log) >> 2) - 1) << 16), .out_data = &expected_log, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_get_log_fid_supported_effects(&cmd, NVME_CSI_NVM, &log); - err = nvme_get_log(test_hdl, &cmd, TEST_RAE, NVME_LOG_PAGE_PDU_SIZE); + err = libnvme_get_log(test_hdl, &cmd, TEST_RAE, NVME_LOG_PAGE_PDU_SIZE); end_mock_cmds(); check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); @@ -663,13 +663,13 @@ static void test_get_log_mi_cmd_supported_effects(void) (((sizeof(expected_log) >> 2) - 1) << 16), .out_data = &expected_log, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_get_log_mi_cmd_supported_effects(&cmd, &log); - err = nvme_get_log(test_hdl, &cmd, TEST_RAE, NVME_LOG_PAGE_PDU_SIZE); + err = libnvme_get_log(test_hdl, &cmd, TEST_RAE, NVME_LOG_PAGE_PDU_SIZE); end_mock_cmds(); check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); @@ -687,13 +687,13 @@ static void test_get_log_boot_partition(void) (((sizeof(expected_log) >> 2) - 1) << 16), .out_data = &expected_log, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_get_log_boot_partition(&cmd, TEST_LSP, &log, sizeof(log)); - err = nvme_get_log(test_hdl, &cmd, TEST_RAE, NVME_LOG_PAGE_PDU_SIZE); + err = libnvme_get_log(test_hdl, &cmd, TEST_RAE, NVME_LOG_PAGE_PDU_SIZE); end_mock_cmds(); check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); @@ -711,14 +711,14 @@ static void test_get_log_rotational_media_info(void) .cdw11 = (TEST_ENDGID << 16), .out_data = &expected_log, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_get_log_rotational_media_info(&cmd, TEST_ENDGID, &log, sizeof(log)); - err = nvme_get_log(test_hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); + err = libnvme_get_log(test_hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); end_mock_cmds(); check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); @@ -735,14 +735,14 @@ static void test_get_log_dispersed_ns_participating_nss(void) (((sizeof(expected_log) >> 2) - 1) << 16), .out_data = &expected_log, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_get_log_dispersed_ns_participating_nss(&cmd, TEST_NSID, &log, sizeof(log)); - err = nvme_get_log(test_hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); + err = libnvme_get_log(test_hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); end_mock_cmds(); check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); @@ -760,14 +760,14 @@ static void test_get_log_phy_rx_eom(void) .cdw11 = (TEST_CNTID << 16), .out_data = &expected_log, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_get_log_phy_rx_eom(&cmd, TEST_LSP, TEST_CNTID, &log, sizeof(log)); - err = nvme_get_log(test_hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); + err = libnvme_get_log(test_hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); end_mock_cmds(); check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); @@ -785,14 +785,14 @@ static void test_get_log_reachability_groups(void) (((sizeof(expected_log) >> 2) - 1) << 16), .out_data = &expected_log, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_get_log_reachability_groups(&cmd, TEST_LSP != 0, &log, sizeof(log)); - err = nvme_get_log(test_hdl, &cmd, TEST_RAE, NVME_LOG_PAGE_PDU_SIZE); + err = libnvme_get_log(test_hdl, &cmd, TEST_RAE, NVME_LOG_PAGE_PDU_SIZE); end_mock_cmds(); check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); @@ -810,14 +810,14 @@ static void test_get_log_reachability_associations(void) (((sizeof(expected_log) >> 2) - 1) << 16), .out_data = &expected_log, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_get_log_reachability_associations(&cmd, TEST_LSP != 0, &log, sizeof(log)); - err = nvme_get_log(test_hdl, &cmd, TEST_RAE, NVME_LOG_PAGE_PDU_SIZE); + err = libnvme_get_log(test_hdl, &cmd, TEST_RAE, NVME_LOG_PAGE_PDU_SIZE); end_mock_cmds(); check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); @@ -835,13 +835,13 @@ static void test_get_log_changed_alloc_ns(void) (((sizeof(expected_log) >> 2) - 1) << 16), .out_data = &expected_log, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_get_log_changed_alloc_ns(&cmd, &log, sizeof(log)); - err = nvme_get_log(test_hdl, &cmd, TEST_RAE, NVME_LOG_PAGE_PDU_SIZE); + err = libnvme_get_log(test_hdl, &cmd, TEST_RAE, NVME_LOG_PAGE_PDU_SIZE); end_mock_cmds(); check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); @@ -859,13 +859,13 @@ static void test_get_log_discovery(void) .cdw12 = TEST_OFFSET_32, .out_data = &expected_log, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_get_log_discovery(&cmd, TEST_OFFSET_32, &log, sizeof(log)); - err = nvme_get_log(test_hdl, &cmd, TEST_RAE, NVME_LOG_PAGE_PDU_SIZE); + err = libnvme_get_log(test_hdl, &cmd, TEST_RAE, NVME_LOG_PAGE_PDU_SIZE); end_mock_cmds(); check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); @@ -884,14 +884,14 @@ static void test_get_log_host_discover(void) (((sizeof(expected_log) >> 2) - 1) << 16), .out_data = &expected_log, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_get_log_host_discovery(&cmd, TEST_LSP != 0, &log, sizeof(log)); - err = nvme_get_log(test_hdl, &cmd, TEST_RAE, NVME_LOG_PAGE_PDU_SIZE); + err = libnvme_get_log(test_hdl, &cmd, TEST_RAE, NVME_LOG_PAGE_PDU_SIZE); end_mock_cmds(); check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); @@ -909,13 +909,13 @@ static void test_get_log_ave_discover(void) (((sizeof(expected_log) >> 2) - 1) << 16), .out_data = &expected_log, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_get_log_ave_discovery(&cmd, &log, sizeof(log)); - err = nvme_get_log(test_hdl, &cmd, TEST_RAE, NVME_LOG_PAGE_PDU_SIZE); + err = libnvme_get_log(test_hdl, &cmd, TEST_RAE, NVME_LOG_PAGE_PDU_SIZE); end_mock_cmds(); check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); @@ -933,13 +933,13 @@ static void test_get_log_pull_model_ddc_req(void) (((sizeof(expected_log) >> 2) - 1) << 16), .out_data = &expected_log, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_get_log_pull_model_ddc_req(&cmd, &log, sizeof(log)); - err = nvme_get_log(test_hdl, &cmd, TEST_RAE, NVME_LOG_PAGE_PDU_SIZE); + err = libnvme_get_log(test_hdl, &cmd, TEST_RAE, NVME_LOG_PAGE_PDU_SIZE); end_mock_cmds(); check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); @@ -957,13 +957,13 @@ static void test_get_log_media_unit_stat(void) .cdw11 = (TEST_DOMID << 16), .out_data = &expected_log, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_get_log_media_unit_stat(&cmd, TEST_DOMID, &log); - err = nvme_get_log(test_hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); + err = libnvme_get_log(test_hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); end_mock_cmds(); check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); @@ -981,13 +981,13 @@ static void test_get_log_support_cap_config_list(void) .cdw11 = (TEST_DOMID << 16), .out_data = &expected_log, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_get_log_support_cap_config_list(&cmd, TEST_DOMID, &log); - err = nvme_get_log(test_hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); + err = libnvme_get_log(test_hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); end_mock_cmds(); check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); @@ -1004,13 +1004,13 @@ static void test_get_log_reservation(void) (((sizeof(expected_log) >> 2) - 1) << 16), .out_data = &expected_log, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_get_log_reservation(&cmd, &log); - err = nvme_get_log(test_hdl, &cmd, TEST_RAE, NVME_LOG_PAGE_PDU_SIZE); + err = libnvme_get_log(test_hdl, &cmd, TEST_RAE, NVME_LOG_PAGE_PDU_SIZE); end_mock_cmds(); check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); @@ -1029,13 +1029,13 @@ static void test_get_log_zns_changed_zones(void) .cdw14 = NVME_CSI_ZNS << 24, .out_data = &expected_log, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_get_log_zns_changed_zones(&cmd, TEST_NSID, &log); - err = nvme_get_log(test_hdl, &cmd, TEST_RAE, NVME_LOG_PAGE_PDU_SIZE); + err = libnvme_get_log(test_hdl, &cmd, TEST_RAE, NVME_LOG_PAGE_PDU_SIZE); end_mock_cmds(); check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); @@ -1053,14 +1053,14 @@ static void test_get_log_persistent_event(void) (((sizeof(expected_log) >> 2) - 1) << 16), .out_data = &expected_log, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_get_log_persistent_event(&cmd, TEST_PEVENT, &log, sizeof(log)); - err = nvme_get_log(test_hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); + err = libnvme_get_log(test_hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); end_mock_cmds(); check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); @@ -1078,13 +1078,13 @@ static void test_get_log_lockdown(void) (((sizeof(expected_log) >> 2) - 1) << 16), .out_data = &expected_log, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_log, sizeof(expected_log)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_get_log_lockdown(&cmd, TEST_LSP, &log); - err = nvme_get_log(test_hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); + err = libnvme_get_log(test_hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); end_mock_cmds(); check(err == 0, "get log returned error %d", err); cmp(&log, &expected_log, sizeof(log), "incorrect log data"); @@ -1102,11 +1102,11 @@ static void run_test(const char *test_name, void (*test_fn)(void)) int main(void) { - struct nvme_global_ctx * ctx = - nvme_create_global_ctx(stdout, DEFAULT_LOGLEVEL); + struct libnvme_global_ctx * ctx = + libnvme_create_global_ctx(stdout, DEFAULT_LOGLEVEL); set_mock_fd(TEST_FD); - check(!nvme_open(ctx, "NVME_TEST_FD", &test_hdl), + check(!libnvme_open(ctx, "NVME_TEST_FD", &test_hdl), "opening test link failed"); RUN_TEST(get_log_sanitize); @@ -1153,5 +1153,5 @@ int main(void) RUN_TEST(get_log_persistent_event); RUN_TEST(get_log_lockdown); - nvme_free_global_ctx(ctx); + libnvme_free_global_ctx(ctx); } diff --git a/libnvme/test/ioctl/misc.c b/libnvme/test/ioctl/misc.c index d02cf98002..9c61815c1a 100644 --- a/libnvme/test/ioctl/misc.c +++ b/libnvme/test/ioctl/misc.c @@ -13,7 +13,7 @@ #define TEST_CSI NVME_CSI_KV #define TEST_COPY_NR 0x12 -static struct nvme_transport_handle *test_hdl; +static struct libnvme_transport_handle *test_hdl; static void test_format_nvm(void) { @@ -30,12 +30,12 @@ static void test_format_nvm(void) (pil << 8) | (ses << 9) | ((lbaf >> 4) << 12), .result = 0, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_format_nvm(&cmd, nsid, lbaf, mset, pi, pil, ses); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "returned error %d", err); check(cmd.result == 0, "returned result %" PRIu64, (uint64_t)cmd.result); @@ -56,13 +56,13 @@ static void test_ns_mgmt(void) .data_len = sizeof(expected_data), .out_data = &expected_data, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_data, sizeof(expected_data)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_ns_mgmt(&cmd, nsid, sel, csi, &data); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "returned error %d", err); check(cmd.result == 0, "returned result %" PRIu64, (uint64_t)cmd.result); @@ -84,13 +84,13 @@ static void test_ns_mgmt_create(void) .data_len = sizeof(expected_data), .out_data = &expected_data, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_data, sizeof(expected_data)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_ns_mgmt_create(&cmd, NVME_CSI_ZNS, &data); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "returned error %d", err); check(cmd.result == TEST_NSID, @@ -105,12 +105,12 @@ static void test_ns_mgmt_delete(void) .nsid = TEST_NSID, .cdw10 = NVME_NS_MGMT_SEL_DELETE, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_ns_mgmt_delete(&cmd, TEST_NSID); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "returned error %d", err); } @@ -126,12 +126,12 @@ static void test_get_property(void) .cdw11 = NVME_REG_ACQ, .result = expected_result, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_get_property(&cmd, NVME_REG_ACQ); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "returned error %d", err); check(cmd.result == expected_result, "returned wrong result"); @@ -148,12 +148,12 @@ static void test_set_property(void) .cdw12 = value & 0xffffffff, .cdw13 = value >> 32, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_set_property(&cmd, NVME_REG_BPMBL, value); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "returned error %d", err); check(cmd.result == 0, "returned result %" PRIu64, (uint64_t)cmd.result); @@ -171,13 +171,13 @@ static void test_ns_attach(void) .data_len = sizeof(expected_ctrlist), .out_data = &expected_ctrlist, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_ctrlist, sizeof(expected_ctrlist)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_ns_attach(&cmd, nsid, sel, &ctrlist); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "returned error %d", err); check(cmd.result == 0, "returned result %" PRIu64, (uint64_t)cmd.result); @@ -195,13 +195,13 @@ static void test_ns_attach_ctrls(void) .data_len = sizeof(ctrlist), .out_data = &ctrlist, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&ctrlist, sizeof(ctrlist)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_ns_attach_ctrls(&cmd, TEST_NSID, &ctrlist); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "returned error %d", err); } @@ -216,13 +216,13 @@ static void test_ns_detach_ctrls(void) .data_len = sizeof(ctrlist), .out_data = &ctrlist, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&ctrlist, sizeof(ctrlist)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_ns_detach_ctrls(&cmd, TEST_NSID, &ctrlist); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "returned error %d", err); } @@ -239,7 +239,7 @@ static void test_fw_download(void) .data_len = data_len, .in_data = &data, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_data, sizeof(expected_data)); @@ -247,7 +247,7 @@ static void test_fw_download(void) set_mock_admin_cmds(&mock_admin_cmd, 1); err = nvme_init_fw_download(&cmd, data, data_len, offset); check(err == 0, "download initializing error %d", err); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "returned error %d", err); check(cmd.result == 0, "returned result %" PRIu64, (uint64_t)cmd.result); @@ -263,12 +263,12 @@ static void test_fw_commit(void) .opcode = nvme_admin_fw_commit, .cdw10 = (bpid << 31) | (action << 3) | slot, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_fw_commit(&cmd, slot, action, bpid); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "returned error %d", err); check(cmd.result == 0, "returned result %" PRIu64, (uint64_t)cmd.result); @@ -291,7 +291,7 @@ static void test_security_send(void) .data_len = data_len, .in_data = &expected_data, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_data, sizeof(expected_data)); @@ -299,7 +299,7 @@ static void test_security_send(void) set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_security_send(&cmd, nsid, nssf, spsp, secp, tl, data, data_len); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "returned error %d", err); check(cmd.result == 0, "returned result %" PRIu64, (uint64_t)cmd.result); @@ -322,13 +322,13 @@ static void test_security_receive(void) .data_len = sizeof(expected_data), .out_data = &expected_data, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; arbitrary(&expected_data, sizeof(expected_data)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_security_receive(&cmd, TEST_NSID, nssf, spsp, secp, al, data, sizeof(data)); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "returned error %d", err); check(cmd.result == 0, "returned result %" PRIu64, (uint64_t)cmd.result); @@ -364,13 +364,13 @@ static void test_get_lba_status(void) .data_len = (mndw + 1) << 2, .out_data = expected_lbas, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; arbitrary(expected_lbas, lba_status_size); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_get_lba_status(&cmd, TEST_NSID, slba, mndw, atype, rl, lbas); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "returned error %d", err); check(cmd.result == 0, "returned wrong result"); @@ -393,7 +393,7 @@ static void test_directive_send(void) .data_len = data_len, .in_data = &data, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_data, sizeof(expected_data)); @@ -401,7 +401,7 @@ static void test_directive_send(void) set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_directive_send(&cmd, TEST_NSID, doper, dtype, dspec, expected_data, data_len); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "returned error %d", err); check(cmd.result == 0, "returned wrong result"); @@ -421,7 +421,7 @@ static void test_directive_send_id_endir(void) .data_len = sizeof(id), .in_data = &id, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_id, sizeof(expected_id)); @@ -429,7 +429,7 @@ static void test_directive_send_id_endir(void) set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_directive_send_id_endir(&cmd, TEST_NSID, true, NVME_DIRECTIVE_DTYPE_STREAMS, &id); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "returned error %d", err); cmp(&id, &expected_id, sizeof(id), "incorrect id"); @@ -445,13 +445,13 @@ static void test_directive_send_stream_release_identifier(void) (NVME_DIRECTIVE_DTYPE_STREAMS << 8) | (stream_id << 16), }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_directive_send_stream_release_identifier(&cmd, TEST_NSID, stream_id); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "returned error %d", err); } @@ -464,12 +464,12 @@ static void test_directive_send_stream_release_resource(void) .cdw11 = NVME_DIRECTIVE_SEND_STREAMS_DOPER_RELEASE_RESOURCE | (NVME_DIRECTIVE_DTYPE_STREAMS << 8), }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_directive_send_stream_release_resource(&cmd, TEST_NSID); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "returned error %d", err); } @@ -489,14 +489,14 @@ static void test_directive_recv(void) .data_len = sizeof(expected_data), .out_data = &expected_data, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_data, sizeof(expected_data)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_directive_recv(&cmd, TEST_NSID, doper, dtype, dspec, data, data_len); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "returned error %d", err); check(cmd.result == 0, "returned wrong result"); @@ -515,13 +515,13 @@ static void test_directive_recv_identify_parameters(void) .data_len = sizeof(expected_id), .out_data = &expected_id, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_id, sizeof(expected_id)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_directive_recv_identify_parameters(&cmd, TEST_NSID, &id); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "returned error %d", err); cmp(&id, &expected_id, sizeof(id), "incorrect id"); @@ -539,13 +539,13 @@ static void test_directive_recv_stream_parameters(void) .data_len = sizeof(expected_params), .out_data = &expected_params, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_params, sizeof(expected_params)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_directive_recv_stream_parameters(&cmd, TEST_NSID, ¶ms); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "returned error %d", err); cmp(¶ms, &expected_params, sizeof(params), "incorrect params"); @@ -576,14 +576,14 @@ static void test_directive_recv_stream_status(void) .data_len = stream_status_size, .out_data = expected_status, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(expected_status, stream_status_size); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_directive_recv_stream_status(&cmd, TEST_NSID, nr_entries, status); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "returned error %d", err); cmp(status, expected_status, stream_status_size, "incorrect status"); @@ -601,12 +601,12 @@ static void test_directive_recv_stream_allocate(void) .cdw12 = nsr, .result = expected_result, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_directive_recv_stream_allocate(&cmd, TEST_NSID, nsr); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "returned error %d", err); check(cmd.result == expected_result, "wrong result"); @@ -626,12 +626,12 @@ void test_capacity_mgmt(void) .cdw12 = cap >> 32, .result = expected_result, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_capacity_mgmt(&cmd, op, elid, cap); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "returned error %d", err); check(cmd.result == expected_result, "wrong result"); @@ -652,12 +652,12 @@ static void test_lockdown(void) .cdw14 = uuidx & 0x3F, .result = expected_result, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_lockdown(&cmd, scp, prhbt, ifc, ofi, uuidx); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "returned error %d", err); check(cmd.result == expected_result, "wrong result"); @@ -681,13 +681,13 @@ static void test_sanitize_nvm(void) .cdw11 = ovrpat, .result = expected_result, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_sanitize_nvm(&cmd, sanact, ause, owpass, oipbp, ndas, emvs, ovrpat); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "returned error %d", err); check(cmd.result == expected_result, "wrong result"); @@ -702,12 +702,12 @@ static void test_dev_self_test(void) .cdw10 = NVME_DST_STC_ABORT, .result = expected_result, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_dev_self_test(&cmd, TEST_NSID, NVME_DST_STC_ABORT); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "returned error %d", err); check(cmd.result == expected_result, "wrong result"); @@ -726,12 +726,12 @@ static void test_virtual_mgmt(void) .cdw11 = nr, .result = expected_result, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_virtual_mgmt(&cmd, act, rt, cntlid, nr); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "returned error %d", err); check(cmd.result == expected_result, "wrong result"); @@ -743,12 +743,12 @@ static void test_flush(void) .opcode = nvme_cmd_flush, .nsid = TEST_NSID, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; set_mock_io_cmds(&mock_io_cmd, 1); nvme_init_flush(&cmd, TEST_NSID); - err = nvme_submit_io_passthru(test_hdl, &cmd); + err = libnvme_submit_io_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "returned error %d", err); } @@ -773,7 +773,7 @@ static void test_read(void) .data_len = sizeof(expected_data), .out_data = &expected_data, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_data, sizeof(expected_data)); @@ -781,7 +781,7 @@ static void test_read(void) nvme_init_read(&cmd, TEST_NSID, slba, nlb, control, dsm, 0, data, sizeof(data), NULL, 0); nvme_init_app_tag(&cmd, apptag, appmask); - err = nvme_submit_io_passthru(test_hdl, &cmd); + err = libnvme_submit_io_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "returned error %d", err); check(cmd.result == 0, "returned result %" PRIu64, (uint64_t)cmd.result); @@ -808,7 +808,7 @@ static void test_write(void) .data_len = sizeof(expected_data), .in_data = &expected_data, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_data, sizeof(expected_data)); @@ -816,7 +816,7 @@ static void test_write(void) nvme_init_write(&cmd, TEST_NSID, slba, nlb, control, dspec, dsm, 0, expected_data, sizeof(expected_data), NULL, 0); nvme_init_app_tag(&cmd, apptag, appmask); - err = nvme_submit_io_passthru(test_hdl, &cmd); + err = libnvme_submit_io_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "returned error %d", err); check(cmd.result == 0, "returned result %" PRIu64, (uint64_t)cmd.result); @@ -841,7 +841,7 @@ static void test_compare(void) .data_len = sizeof(expected_data), .in_data = &expected_data, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_data, sizeof(expected_data)); @@ -850,7 +850,7 @@ static void test_compare(void) nvme_init_compare(&cmd, TEST_NSID, slba, nlb, control, cev, data, sizeof(data), NULL, 0); nvme_init_app_tag(&cmd, apptag, appmask); - err = nvme_submit_io_passthru(test_hdl, &cmd); + err = libnvme_submit_io_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "returned error %d", err); check(cmd.result == 0, "returned result %" PRIu64, (uint64_t)cmd.result); @@ -875,14 +875,14 @@ static void test_write_zeros(void) .cdw13 = dsm | (dspec << 16), .cdw15 = apptag | (appmask << 16), }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; set_mock_io_cmds(&mock_io_cmd, 1); nvme_init_write_zeros(&cmd, TEST_NSID, slba, nlb, control, dspec, dsm, cev); nvme_init_app_tag(&cmd, apptag, appmask); - err = nvme_submit_io_passthru(test_hdl, &cmd); + err = libnvme_submit_io_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "returned error %d", err); check(cmd.result == 0, "returned result %" PRIu64, (uint64_t)cmd.result); @@ -906,14 +906,14 @@ static void test_write_uncorrectable(void) .cdw13 = dsm | (dspec << 16), .cdw15 = apptag | (appmask << 16), }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; set_mock_io_cmds(&mock_io_cmd, 1); nvme_init_write_uncorrectable(&cmd, TEST_NSID, slba, nlb, control, dspec); nvme_init_app_tag(&cmd, apptag, appmask); - err = nvme_submit_io_passthru(test_hdl, &cmd); + err = libnvme_submit_io_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "returned error %d", err); check(cmd.result == 0, "returned result %" PRIu64, (uint64_t)cmd.result); @@ -936,14 +936,14 @@ static void test_verify(void) .cdw13 = cev, .cdw15 = apptag | (appmask << 16), }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; set_mock_io_cmds(&mock_io_cmd, 1); nvme_init_verify(&cmd, TEST_NSID, slba, nlb, control, cev, NULL, 0, NULL, 0); nvme_init_app_tag(&cmd, apptag, appmask); - err = nvme_submit_io_passthru(test_hdl, &cmd); + err = libnvme_submit_io_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "returned error %d", err); check(cmd.result == 0, "returned result %" PRIu64, (uint64_t)cmd.result); @@ -951,7 +951,7 @@ static void test_verify(void) static void test_dsm(void) { - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; __u16 nr_ranges = 0xab; int dsm_size = sizeof(struct nvme_dsm_range) * nr_ranges; @@ -974,7 +974,7 @@ static void test_dsm(void) arbitrary(dsm, dsm_size); set_mock_io_cmds(&mock_io_cmd, 1); nvme_init_dsm(&cmd, TEST_NSID, nr_ranges, 0, 0, 1, dsm, dsm_size); - err = nvme_submit_io_passthru(test_hdl, &cmd); + err = libnvme_submit_io_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "returned error %d", err); check(cmd.result == 0, "returned result %" PRIu64, (uint64_t)cmd.result); @@ -1020,7 +1020,7 @@ static void test_copy(void) .data_len = nr * sizeof(struct nvme_copy_range_f0), .in_data = expected_data, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; set_mock_io_cmds(&mock_io_cmd, 1); nvme_init_copy_range_f0(copy, nlbs, slbas, short_pi, elbatms, elbats, @@ -1028,7 +1028,7 @@ static void test_copy(void) nvme_init_copy(&cmd, TEST_NSID, sdlba, nr, desfmt, prinfor, prinfow, cetype, dtype, stcw, stcr, fua, lr, cev, dspec, (void *)copy); - err = nvme_submit_io_passthru(test_hdl, &cmd); + err = libnvme_submit_io_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "returned error %d", err); check(cmd.result == 0, "returned result %" PRIu64, (uint64_t)cmd.result); @@ -1076,7 +1076,7 @@ static void test_copy_range_f1(void) .data_len = nr * sizeof(struct nvme_copy_range_f1), .in_data = expected_data, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; set_mock_io_cmds(&mock_io_cmd, 1); nvme_init_copy_range_f1(copy, nlbs, slbas, long_pi, elbatms, elbats, @@ -1084,7 +1084,7 @@ static void test_copy_range_f1(void) nvme_init_copy(&cmd, TEST_NSID, sdlba, nr, desfmt, prinfor, prinfow, cetype, dtype, stcw, stcr, fua, lr, cev, dspec, (void *)copy); - err = nvme_submit_io_passthru(test_hdl, &cmd); + err = libnvme_submit_io_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "returned error %d", err); check(cmd.result == 0, "returned result %" PRIu64, @@ -1106,13 +1106,13 @@ static void test_resv_acquire(void) .data_len = sizeof(expected_payload), .in_data = expected_payload, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; set_mock_io_cmds(&mock_io_cmd, 1); nvme_init_resv_acquire(&cmd, TEST_NSID, racqa, iekey, false, rtype, 1, 2, payload); - err = nvme_submit_io_passthru(test_hdl, &cmd); + err = libnvme_submit_io_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "returned error %d", err); check(cmd.result == 0, "returned result %" PRIu64, (uint64_t)cmd.result); @@ -1133,13 +1133,13 @@ static void test_resv_register(void) .data_len = sizeof(expected_payload), .in_data = expected_payload, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; set_mock_io_cmds(&mock_io_cmd, 1); nvme_init_resv_register(&cmd, TEST_NSID, rrega, iekey, false, cptpl, 0xffffffffffffffff, 0, payload); - err = nvme_submit_io_passthru(test_hdl, &cmd); + err = libnvme_submit_io_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "returned error %d", err); check(cmd.result == 0, "returned result %" PRIu64, (uint64_t)cmd.result); @@ -1160,13 +1160,13 @@ static void test_resv_release(void) .data_len = sizeof(expected_payload), .in_data = expected_payload, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; set_mock_io_cmds(&mock_io_cmd, 1); nvme_init_resv_release(&cmd, TEST_NSID, rrela, iekey, false, rtype, 0xffffffffffffffff, payload); - err = nvme_submit_io_passthru(test_hdl, &cmd); + err = libnvme_submit_io_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "returned error %d", err); check(cmd.result == 0, "returned result %" PRIu64, (uint64_t)cmd.result); @@ -1186,13 +1186,13 @@ static void test_resv_report(void) .data_len = len, .out_data = &expected_status, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_status, sizeof(expected_status)); set_mock_io_cmds(&mock_io_cmd, 1); nvme_init_resv_report(&cmd, TEST_NSID, eds, disnsrs, &status, len); - err = nvme_submit_io_passthru(test_hdl, &cmd); + err = libnvme_submit_io_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "returned error %d", err); check(cmd.result == 0, "returned result %" PRIu64, (uint64_t)cmd.result); @@ -1213,13 +1213,13 @@ static void test_io_mgmt_recv(void) .data_len = data_len, .out_data = &expected_data, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_data, sizeof(expected_data)); set_mock_io_cmds(&mock_io_cmd, 1); nvme_init_io_mgmt_recv(&cmd, TEST_NSID, mo, mos, data, data_len); - err = nvme_submit_io_passthru(test_hdl, &cmd); + err = libnvme_submit_io_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "returned error %d", err); cmp(&data, &expected_data, sizeof(data), "incorrect data"); @@ -1238,14 +1238,14 @@ static void test_io_mgmt_send(void) .data_len = data_len, .in_data = &expected_data, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_data, sizeof(expected_data)); memcpy(&data, &expected_data, sizeof(expected_data)); set_mock_io_cmds(&mock_io_cmd, 1); nvme_init_io_mgmt_send(&cmd, TEST_NSID, mo, mos, data, data_len); - err = nvme_submit_io_passthru(test_hdl, &cmd); + err = libnvme_submit_io_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "returned error %d", err); cmp(&data, &expected_data, sizeof(data), "incorrect data"); @@ -1263,14 +1263,14 @@ static void test_fdp_reclaim_unit_handle_status(void) .data_len = data_len, .out_data = &expected_data, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_data, sizeof(expected_data)); set_mock_io_cmds(&mock_io_cmd, 1); nvme_init_fdp_reclaim_unit_handle_status(&cmd, TEST_NSID, &data, data_len); - err = nvme_submit_io_passthru(test_hdl, &cmd); + err = libnvme_submit_io_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "returned error %d", err); cmp(&data, &expected_data, sizeof(data), "incorrect data"); @@ -1287,13 +1287,13 @@ static void test_fdp_reclaim_unit_handle_update(void) .data_len = npids * sizeof(__u16), .in_data = &pids, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&pids, sizeof(pids)); set_mock_io_cmds(&mock_io_cmd, 1); nvme_init_fdp_reclaim_unit_handle_update(&cmd, TEST_NSID, &pids, npids); - err = nvme_submit_io_passthru(test_hdl, &cmd); + err = libnvme_submit_io_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "returned error %d", err); } @@ -1309,14 +1309,14 @@ static void test_dim_send(void) .data_len =data_len, .in_data = &expected_data, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_data, sizeof(expected_data)); memcpy(&data, &expected_data, sizeof(expected_data)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_dim_send(&cmd, tas, data, data_len); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "returned error %d", err); check(cmd.result == 0, "returned result %" PRIu64, (uint64_t)cmd.result); @@ -1338,14 +1338,14 @@ static void test_lm_cdq_delete(void) .data_len = 0, .in_data = &expected_data, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_data, sizeof(expected_data)); memcpy(&data, &expected_data, sizeof(expected_data)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_lm_cdq_delete(&cmd, mos, cdqid); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "returned error %d", err); check(cmd.result == 0, "returned result %" PRIu64, (uint64_t)cmd.result); @@ -1362,12 +1362,12 @@ static void test_lm_track_send(void) .cdw10 = sel | (mos << 16), .cdw11 = cdqid, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_lm_track_send(&cmd, sel, mos, cdqid); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "returned error %d", err); check(cmd.result == 0, "returned result %" PRIu64, (uint64_t)cmd.result); @@ -1397,7 +1397,7 @@ static void test_lm_migration_send(void) .data_len = numd << 2, .in_data = &expected_data, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_data, sizeof(expected_data)); @@ -1405,7 +1405,7 @@ static void test_lm_migration_send(void) set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_lm_migration_send(&cmd, sel, mos, cntlid, stype, dudmq, csvi, csuuidi, offset, uidx, &data, sizeof(data)); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "returned error %d", err); check(cmd.result == 0, "returned result %" PRIu64, (uint64_t)cmd.result); @@ -1435,14 +1435,14 @@ static void test_lm_migration_recv(void) .data_len = (numd + 1) << 2, .out_data = &expected_data, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_data, sizeof(expected_data)); set_mock_admin_cmds(&mock_admin_cmd, 1); nvme_init_lm_migration_recv(&cmd, offset, mos, cntlid, csuuidi, sel, uidx, csuidxp, data, sizeof(data)); - err = nvme_submit_admin_passthru(test_hdl, &cmd); + err = libnvme_submit_admin_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "returned error %d", err); check(cmd.result == 0, "returned result %" PRIu64, (uint64_t)cmd.result); @@ -1461,11 +1461,11 @@ static void run_test(const char *test_name, void (*test_fn)(void)) int main(void) { - struct nvme_global_ctx *ctx = - nvme_create_global_ctx(stdout, DEFAULT_LOGLEVEL); + struct libnvme_global_ctx *ctx = + libnvme_create_global_ctx(stdout, DEFAULT_LOGLEVEL); set_mock_fd(TEST_FD); - check(!nvme_open(ctx, "NVME_TEST_FD64", &test_hdl), + check(!libnvme_open(ctx, "NVME_TEST_FD64", &test_hdl), "opening test link failed"); RUN_TEST(format_nvm); @@ -1520,5 +1520,5 @@ int main(void) RUN_TEST(lm_migration_send); RUN_TEST(lm_migration_recv); - nvme_free_global_ctx(ctx); + libnvme_free_global_ctx(ctx); } diff --git a/libnvme/test/ioctl/mock.c b/libnvme/test/ioctl/mock.c index cf03e2d28f..894968cf8f 100644 --- a/libnvme/test/ioctl/mock.c +++ b/libnvme/test/ioctl/mock.c @@ -137,19 +137,19 @@ int ioctl(int fd, int request, ...) void *cmd; switch (request) { - case NVME_IOCTL_ADMIN_CMD: + case LIBNVME_IOCTL_ADMIN_CMD: mock_cmds = &mock_admin_cmds; result64 = false; break; - case NVME_IOCTL_ADMIN64_CMD: + case LIBNVME_IOCTL_ADMIN64_CMD: mock_cmds = &mock_admin_cmds; result64 = true; break; - case NVME_IOCTL_IO_CMD: + case LIBNVME_IOCTL_IO_CMD: mock_cmds = &mock_io_cmds; result64 = false; break; - case NVME_IOCTL_IO64_CMD: + case LIBNVME_IOCTL_IO64_CMD: mock_cmds = &mock_io_cmds; result64 = true; break; diff --git a/libnvme/test/ioctl/zns.c b/libnvme/test/ioctl/zns.c index b5cf859f96..81fd939300 100644 --- a/libnvme/test/ioctl/zns.c +++ b/libnvme/test/ioctl/zns.c @@ -11,7 +11,7 @@ #define TEST_NSID 0x12345678 #define TEST_SLBA 0xffffffff12345678 -static struct nvme_transport_handle *test_hdl; +static struct libnvme_transport_handle *test_hdl; static void test_zns_append(void) { @@ -41,7 +41,7 @@ static void test_zns_append(void) .data_len = sizeof(expected_data), .out_data = &expected_data, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_data, sizeof(expected_data)); @@ -51,7 +51,7 @@ static void test_zns_append(void) if (elbas) nvme_init_var_size_tags(&cmd, pif, sts, reftag, storage_tag); nvme_init_app_tag(&cmd, lbat, lbatm); - err = nvme_submit_io_passthru(test_hdl, &cmd); + err = libnvme_submit_io_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "returned error %d", err); check(result == 0, "wrong result"); @@ -75,14 +75,14 @@ static void test_zns_report_zones(void) .data_len = sizeof(expected_data), .out_data = &expected_data, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_data, sizeof(expected_data)); set_mock_io_cmds(&mock_io_cmd, 1); nvme_init_zns_report_zones(&cmd, TEST_NSID, TEST_SLBA, opts, extended, partial, &data, sizeof(data)); - err = nvme_submit_io_passthru(test_hdl, &cmd); + err = libnvme_submit_io_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "returned error %d", err); check(result == 0, "returned result %"PRIu64, (uint64_t)result); @@ -107,14 +107,14 @@ static void test_zns_mgmt_send(void) .data_len = sizeof(expected_data), .out_data = &expected_data, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_data, sizeof(expected_data)); set_mock_io_cmds(&mock_io_cmd, 1); nvme_init_zns_mgmt_send(&cmd, TEST_NSID, slba, zsa, select_all, zsaso, false, data, sizeof(data)); - err = nvme_submit_io_passthru(test_hdl, &cmd); + err = libnvme_submit_io_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "returned error %d", err); check(result == 0, "returned result %"PRIu64, (uint64_t)result); @@ -136,14 +136,14 @@ static void test_zns_mgmt_recv(void) .data_len = sizeof(expected_data), .out_data = &expected_data, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; arbitrary(&expected_data, sizeof(expected_data)); set_mock_io_cmds(&mock_io_cmd, 1); nvme_init_zns_mgmt_recv(&cmd, TEST_NSID, 0, zra, zrasf, zras_feat, data, sizeof(data)); - err = nvme_submit_io_passthru(test_hdl, &cmd); + err = libnvme_submit_io_passthru(test_hdl, &cmd); end_mock_cmds(); check(err == 0, "returned error %d", err); check(result == 0, "returned result %"PRIu64, (uint64_t)result); @@ -162,11 +162,11 @@ static void run_test(const char *test_name, void (*test_fn)(void)) int main(void) { - struct nvme_global_ctx *ctx = - nvme_create_global_ctx(stdout, DEFAULT_LOGLEVEL); + struct libnvme_global_ctx *ctx = + libnvme_create_global_ctx(stdout, DEFAULT_LOGLEVEL); set_mock_fd(TEST_FD); - check(!nvme_open(ctx, "NVME_TEST_FD", &test_hdl), + check(!libnvme_open(ctx, "NVME_TEST_FD", &test_hdl), "opening test link failed"); RUN_TEST(zns_append); @@ -174,5 +174,5 @@ int main(void) RUN_TEST(zns_mgmt_send); RUN_TEST(zns_mgmt_recv); - nvme_free_global_ctx(ctx); + libnvme_free_global_ctx(ctx); } diff --git a/libnvme/test/mi-mctp.c b/libnvme/test/mi-mctp.c index c666b0119d..f88a7381f3 100644 --- a/libnvme/test/mi-mctp.c +++ b/libnvme/test/mi-mctp.c @@ -96,13 +96,13 @@ void reset_test_peer(void) * the new MIC */ static void test_set_tx_mic(struct test_peer *peer) { - extern __u32 nvme_mi_crc32_update(__u32 crc, void *data, size_t len); + extern __u32 libnvme_mi_crc32_update(__u32 crc, void *data, size_t len); __u32 crc = 0xffffffff; __le32 crc_le; assert(peer->tx_buf_len + sizeof(crc_le) <= MAX_BUFSIZ); - crc = nvme_mi_crc32_update(crc, peer->tx_buf, peer->tx_buf_len); + crc = libnvme_mi_crc32_update(crc, peer->tx_buf, peer->tx_buf_len); crc_le = cpu_to_le32(~crc); memcpy(peer->tx_buf + peer->tx_buf_len, &crc_le, sizeof(crc_le)); peer->tx_buf_len += sizeof(crc_le); @@ -237,14 +237,14 @@ static struct __mi_mctp_socket_ops ops = { }; /* tests */ -static void test_rx_err(nvme_mi_ep_t ep, struct test_peer *peer) +static void test_rx_err(libnvme_mi_ep_t ep, struct test_peer *peer) { struct nvme_mi_read_nvm_ss_info ss_info; int rc; peer->rx_rc = -1; - rc = nvme_mi_mi_read_mi_data_subsys(ep, &ss_info); + rc = libnvme_mi_mi_read_mi_data_subsys(ep, &ss_info); assert(rc != 0); } @@ -253,7 +253,7 @@ static int tx_none(struct test_peer *peer, void *buf, size_t len, int sd) return 0; } -static void test_tx_none(nvme_mi_ep_t ep, struct test_peer *peer) +static void test_tx_none(libnvme_mi_ep_t ep, struct test_peer *peer) { struct nvme_mi_read_nvm_ss_info ss_info; int rc; @@ -261,29 +261,29 @@ static void test_tx_none(nvme_mi_ep_t ep, struct test_peer *peer) peer->tx_buf_len = 0; peer->tx_fn = tx_none; - rc = nvme_mi_mi_read_mi_data_subsys(ep, &ss_info); + rc = libnvme_mi_mi_read_mi_data_subsys(ep, &ss_info); assert(rc != 0); } -static void test_tx_err(nvme_mi_ep_t ep, struct test_peer *peer) +static void test_tx_err(libnvme_mi_ep_t ep, struct test_peer *peer) { struct nvme_mi_read_nvm_ss_info ss_info; int rc; peer->tx_rc = -1; - rc = nvme_mi_mi_read_mi_data_subsys(ep, &ss_info); + rc = libnvme_mi_mi_read_mi_data_subsys(ep, &ss_info); assert(rc != 0); } -static void test_tx_short(nvme_mi_ep_t ep, struct test_peer *peer) +static void test_tx_short(libnvme_mi_ep_t ep, struct test_peer *peer) { struct nvme_mi_read_nvm_ss_info ss_info; int rc; peer->tx_buf_len = 11; - rc = nvme_mi_mi_read_mi_data_subsys(ep, &ss_info); + rc = libnvme_mi_mi_read_mi_data_subsys(ep, &ss_info); assert(rc != 0); } @@ -293,18 +293,18 @@ static int poll_fn_err(struct test_peer *peer, struct pollfd *fds, return -1; } -static void test_poll_err(nvme_mi_ep_t ep, struct test_peer *peer) +static void test_poll_err(libnvme_mi_ep_t ep, struct test_peer *peer) { struct nvme_mi_read_nvm_ss_info ss_info; int rc; peer->poll_fn = poll_fn_err; - rc = nvme_mi_mi_read_mi_data_subsys(ep, &ss_info); + rc = libnvme_mi_mi_read_mi_data_subsys(ep, &ss_info); assert(rc != 0); } -static void test_read_mi_data(nvme_mi_ep_t ep, struct test_peer *peer) +static void test_read_mi_data(libnvme_mi_ep_t ep, struct test_peer *peer) { struct nvme_mi_read_nvm_ss_info ss_info; int rc; @@ -312,11 +312,11 @@ static void test_read_mi_data(nvme_mi_ep_t ep, struct test_peer *peer) /* empty response data */ peer->tx_buf_len = 8 + 32; - rc = nvme_mi_mi_read_mi_data_subsys(ep, &ss_info); + rc = libnvme_mi_mi_read_mi_data_subsys(ep, &ss_info); assert(rc == 0); } -static void test_mi_resp_err(nvme_mi_ep_t ep, struct test_peer *peer) +static void test_mi_resp_err(libnvme_mi_ep_t ep, struct test_peer *peer) { struct nvme_mi_read_nvm_ss_info ss_info; int rc; @@ -325,7 +325,7 @@ static void test_mi_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_mi_read_mi_data_subsys(ep, &ss_info); + rc = libnvme_mi_mi_read_mi_data_subsys(ep, &ss_info); assert(rc == 0x2); } @@ -350,7 +350,7 @@ static void setup_unaligned_ctrl_list_resp(struct test_peer *peer) * resp->data_len is set to sizeof(list)), but the endpoint will return an * unaligned short list. */ -static void test_mi_resp_unaligned(nvme_mi_ep_t ep, struct test_peer *peer) +static void test_mi_resp_unaligned(libnvme_mi_ep_t ep, struct test_peer *peer) { struct nvme_ctrl_list list; int rc; @@ -359,7 +359,7 @@ static void test_mi_resp_unaligned(nvme_mi_ep_t ep, struct test_peer *peer) memset(&list, 0, sizeof(list)); - rc = nvme_mi_mi_read_mi_data_ctrl_list(ep, 0, &list); + rc = libnvme_mi_mi_read_mi_data_ctrl_list(ep, 0, &list); assert(rc == 0); assert(le16_to_cpu(list.num) == 2); @@ -370,17 +370,17 @@ static void test_mi_resp_unaligned(nvme_mi_ep_t ep, struct test_peer *peer) /* Will call through the xfer/submit API expecting an unaligned list, * and get a response of exactly that size. */ -static void test_mi_resp_unaligned_expected(nvme_mi_ep_t ep, +static void test_mi_resp_unaligned_expected(libnvme_mi_ep_t ep, struct test_peer *peer) { /* direct access to the raw submit() API */ - extern int nvme_mi_submit(nvme_mi_ep_t ep, struct nvme_mi_req *req, - struct nvme_mi_resp *resp); + extern int libnvme_mi_submit(libnvme_mi_ep_t ep, struct libnvme_mi_req *req, + struct libnvme_mi_resp *resp); struct nvme_mi_mi_resp_hdr resp_hdr; struct nvme_mi_mi_req_hdr req_hdr; struct nvme_ctrl_list list; - struct nvme_mi_resp resp; - struct nvme_mi_req req; + struct libnvme_mi_resp resp; + struct libnvme_mi_req req; int rc; setup_unaligned_ctrl_list_resp(peer); @@ -403,7 +403,7 @@ static void test_mi_resp_unaligned_expected(nvme_mi_ep_t ep, resp.data = &list; resp.data_len = peer->tx_buf_len; - rc = nvme_mi_submit(ep, &req, &resp); + rc = libnvme_mi_submit(ep, &req, &resp); assert(rc == 0); assert(resp.data_len == 6); /* 2-byte length, 2*2 byte controller IDs */ @@ -412,14 +412,14 @@ static void test_mi_resp_unaligned_expected(nvme_mi_ep_t ep, assert(le16_to_cpu(list.identifier[1]) == 2); } -static void test_admin_resp_err(nvme_mi_ep_t ep, struct test_peer *peer) +static void test_admin_resp_err(libnvme_mi_ep_t ep, struct test_peer *peer) { - struct nvme_transport_handle *hdl; - struct nvme_passthru_cmd cmd; + struct libnvme_transport_handle *hdl; + struct libnvme_passthru_cmd cmd; struct nvme_id_ctrl id; int rc; - hdl = nvme_mi_init_transport_handle(ep, 1); + hdl = libnvme_mi_init_transport_handle(ep, 1); assert(hdl); /* Simple error response, will be shorter than the expected Admin @@ -428,7 +428,7 @@ static void test_admin_resp_err(nvme_mi_ep_t ep, struct test_peer *peer) peer->tx_buf_len = 8; nvme_init_identify_ctrl(&cmd, &id); - rc = nvme_submit_admin_passthru(hdl, &cmd); + rc = libnvme_submit_admin_passthru(hdl, &cmd); assert(nvme_status_get_type(rc) == NVME_STATUS_TYPE_MI); assert(nvme_status_get_value(rc) == NVME_MI_RESP_INTERNAL_ERR); } @@ -439,15 +439,15 @@ static void test_admin_resp_err(nvme_mi_ep_t ep, struct test_peer *peer) * doublewords), and we need to ensure that an error response is correctly * interpreted, including having the MIC extracted from the message. */ -static void test_admin_resp_sizes(nvme_mi_ep_t ep, struct test_peer *peer) +static void test_admin_resp_sizes(libnvme_mi_ep_t ep, struct test_peer *peer) { - struct nvme_transport_handle *hdl; - struct nvme_passthru_cmd cmd; + struct libnvme_transport_handle *hdl; + struct libnvme_passthru_cmd cmd; struct nvme_id_ctrl id; unsigned int i; int rc; - hdl = nvme_mi_init_transport_handle(ep, 1); + hdl = libnvme_mi_init_transport_handle(ep, 1); assert(hdl); peer->tx_buf[4] = 0x02; /* internal error */ @@ -455,12 +455,12 @@ 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; nvme_init_identify_ctrl(&cmd, &id); - rc = nvme_submit_admin_passthru(hdl, &cmd); + rc = libnvme_submit_admin_passthru(hdl, &cmd); assert(nvme_status_get_type(rc) == NVME_STATUS_TYPE_MI); assert(nvme_status_get_value(rc) == NVME_MI_RESP_INTERNAL_ERR); } - nvme_close(hdl); + libnvme_close(hdl); } /* test: timeout value passed to poll */ @@ -471,7 +471,7 @@ static int poll_fn_timeout_value(struct test_peer *peer, struct pollfd *fds, return 1; } -static void test_poll_timeout_value(nvme_mi_ep_t ep, struct test_peer *peer) +static void test_poll_timeout_value(libnvme_mi_ep_t ep, struct test_peer *peer) { struct nvme_mi_read_nvm_ss_info ss_info; int rc; @@ -480,9 +480,9 @@ static void test_poll_timeout_value(nvme_mi_ep_t ep, struct test_peer *peer) peer->tx_buf_len = 8 + 32; peer->poll_fn = poll_fn_timeout_value; - nvme_mi_ep_set_timeout(ep, 3141); + libnvme_mi_ep_set_timeout(ep, 3141); - rc = nvme_mi_mi_read_mi_data_subsys(ep, &ss_info); + rc = libnvme_mi_mi_read_mi_data_subsys(ep, &ss_info); assert(rc == 0); } @@ -493,14 +493,14 @@ static int poll_fn_timeout(struct test_peer *peer, struct pollfd *fds, return 0; } -static void test_poll_timeout(nvme_mi_ep_t ep, struct test_peer *peer) +static void test_poll_timeout(libnvme_mi_ep_t ep, struct test_peer *peer) { struct nvme_mi_read_nvm_ss_info ss_info; int rc; peer->poll_fn = poll_fn_timeout; - rc = nvme_mi_mi_read_mi_data_subsys(ep, &ss_info); + rc = libnvme_mi_mi_read_mi_data_subsys(ep, &ss_info); assert(rc != 0); assert(errno == ETIMEDOUT); } @@ -545,7 +545,7 @@ static int tx_mpr(struct test_peer *peer, void *buf, size_t len, int sd) return 0; } -static void test_mpr_mi(nvme_mi_ep_t ep, struct test_peer *peer) +static void test_mpr_mi(libnvme_mi_ep_t ep, struct test_peer *peer) { struct nvme_mi_read_nvm_ss_info ss_info; struct mpr_tx_info tx_info; @@ -558,14 +558,14 @@ static void test_mpr_mi(nvme_mi_ep_t ep, struct test_peer *peer) peer->tx_fn = tx_mpr; peer->tx_data = &tx_info; - rc = nvme_mi_mi_read_mi_data_subsys(ep, &ss_info); + rc = libnvme_mi_mi_read_mi_data_subsys(ep, &ss_info); assert(rc == 0); } -static void test_mpr_admin(nvme_mi_ep_t ep, struct test_peer *peer) +static void test_mpr_admin(libnvme_mi_ep_t ep, struct test_peer *peer) { - struct nvme_transport_handle *hdl; - struct nvme_passthru_cmd cmd; + struct libnvme_transport_handle *hdl; + struct libnvme_passthru_cmd cmd; struct mpr_tx_info tx_info; struct nvme_id_ctrl id; int rc; @@ -577,22 +577,22 @@ static void test_mpr_admin(nvme_mi_ep_t ep, struct test_peer *peer) peer->tx_fn = tx_mpr; peer->tx_data = &tx_info; - hdl = nvme_mi_init_transport_handle(ep, 1); + hdl = libnvme_mi_init_transport_handle(ep, 1); nvme_init_identify_ctrl(&cmd, &id); - rc = nvme_submit_admin_passthru(hdl, &cmd); + rc = libnvme_submit_admin_passthru(hdl, &cmd); assert(rc == 0); - nvme_close(hdl); + libnvme_close(hdl); } /* We have seen drives that send a MPR response as a full Admin message, * rather than a MI message; these have a larger message body */ -static void test_mpr_admin_quirked(nvme_mi_ep_t ep, struct test_peer *peer) +static void test_mpr_admin_quirked(libnvme_mi_ep_t ep, struct test_peer *peer) { - struct nvme_transport_handle *hdl; - struct nvme_passthru_cmd cmd; + struct libnvme_transport_handle *hdl; + struct libnvme_passthru_cmd cmd; struct mpr_tx_info tx_info; struct nvme_id_ctrl id; int rc; @@ -604,13 +604,13 @@ 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; - hdl = nvme_mi_init_transport_handle(ep, 1); + hdl = libnvme_mi_init_transport_handle(ep, 1); nvme_init_identify_ctrl(&cmd, &id); - rc = nvme_submit_admin_passthru(hdl, &cmd); + rc = libnvme_submit_admin_passthru(hdl, &cmd); assert(rc == 0); - nvme_close(hdl); + libnvme_close(hdl); } /* helpers for the MPR + poll tests */ @@ -674,14 +674,14 @@ static int tx_fn_mpr_poll(struct test_peer *peer, void *buf, size_t len, int sd) } /* test: correct timeout value used from MPR response */ -static void test_mpr_timeouts(nvme_mi_ep_t ep, struct test_peer *peer) +static void test_mpr_timeouts(libnvme_mi_ep_t ep, struct test_peer *peer) { struct nvme_mi_read_nvm_ss_info ss_info; struct mpr_poll_info poll_info; struct mpr_tx_info tx_info; int rc; - nvme_mi_ep_set_timeout(ep, 3141); + libnvme_mi_ep_set_timeout(ep, 3141); tx_info.msg_no = 1; tx_info.final_len = sizeof(struct nvme_mi_mi_resp_hdr) + sizeof(ss_info); @@ -697,20 +697,20 @@ static void test_mpr_timeouts(nvme_mi_ep_t ep, struct test_peer *peer) peer->poll_fn = poll_fn_mpr_poll; peer->poll_data = &poll_info; - rc = nvme_mi_mi_read_mi_data_subsys(ep, &ss_info); + rc = libnvme_mi_mi_read_mi_data_subsys(ep, &ss_info); assert(rc == 0); } /* test: MPR value is limited to the max mpr */ -static void test_mpr_timeout_clamp(nvme_mi_ep_t ep, struct test_peer *peer) +static void test_mpr_timeout_clamp(libnvme_mi_ep_t ep, struct test_peer *peer) { struct nvme_mi_read_nvm_ss_info ss_info; struct mpr_poll_info poll_info; struct mpr_tx_info tx_info; int rc; - nvme_mi_ep_set_timeout(ep, 3141); - nvme_mi_ep_set_mprt_max(ep, 123400); + libnvme_mi_ep_set_timeout(ep, 3141); + libnvme_mi_ep_set_mprt_max(ep, 123400); tx_info.msg_no = 1; tx_info.final_len = sizeof(struct nvme_mi_mi_resp_hdr) + sizeof(ss_info); @@ -726,20 +726,20 @@ static void test_mpr_timeout_clamp(nvme_mi_ep_t ep, struct test_peer *peer) peer->poll_fn = poll_fn_mpr_poll; peer->poll_data = &poll_info; - rc = nvme_mi_mi_read_mi_data_subsys(ep, &ss_info); + rc = libnvme_mi_mi_read_mi_data_subsys(ep, &ss_info); assert(rc == 0); } /* test: MPR value of zero doesn't result in poll with zero timeout */ -static void test_mpr_mprt_zero(nvme_mi_ep_t ep, struct test_peer *peer) +static void test_mpr_mprt_zero(libnvme_mi_ep_t ep, struct test_peer *peer) { struct nvme_mi_read_nvm_ss_info ss_info; struct mpr_poll_info poll_info; struct mpr_tx_info tx_info; int rc; - nvme_mi_ep_set_timeout(ep, 3141); - nvme_mi_ep_set_mprt_max(ep, 123400); + libnvme_mi_ep_set_timeout(ep, 3141); + libnvme_mi_ep_set_mprt_max(ep, 123400); tx_info.msg_no = 1; tx_info.final_len = sizeof(struct nvme_mi_mi_resp_hdr) + sizeof(ss_info); @@ -755,7 +755,7 @@ static void test_mpr_mprt_zero(nvme_mi_ep_t ep, struct test_peer *peer) peer->poll_fn = poll_fn_mpr_poll; peer->poll_data = &poll_info; - rc = nvme_mi_mi_read_mi_data_subsys(ep, &ss_info); + rc = libnvme_mi_mi_read_mi_data_subsys(ep, &ss_info); assert(rc == 0); } @@ -784,16 +784,16 @@ enum aem_failure_condition { struct aem_rcv_enable_fn_data { enum aem_enable_state state; enum aem_failure_condition fc; - struct nvme_mi_aem_enabled_map ep_enabled_map; - struct nvme_mi_aem_enabled_map host_enabled_map; - struct nvme_mi_aem_enabled_map aem_during_process_map; - struct nvme_mi_aem_enabled_map ack_events_map; - struct nvme_mi_event *events[256]; + struct libnvme_mi_aem_enabled_map ep_enabled_map; + struct libnvme_mi_aem_enabled_map host_enabled_map; + struct libnvme_mi_aem_enabled_map aem_during_process_map; + struct libnvme_mi_aem_enabled_map ack_events_map; + struct libnvme_mi_event *events[256]; int callback_count; }; static void populate_tx_occ_list(bool aem_not_ack, - struct aem_rcv_enable_fn_data *fn_data, struct nvme_mi_aem_enabled_map *to_send) + struct aem_rcv_enable_fn_data *fn_data, struct libnvme_mi_aem_enabled_map *to_send) { struct nvme_mi_mi_resp_hdr *resp_hdr = (struct nvme_mi_mi_resp_hdr *)test_peer.tx_buf; @@ -826,7 +826,7 @@ static void populate_tx_occ_list(bool aem_not_ack, for (int i = 0; i < 255; i++) { if (fn_data->events[i] && to_send->enabled[i]) { - struct nvme_mi_event *event = fn_data->events[i]; + struct libnvme_mi_event *event = fn_data->events[i]; list_hdr->numaeo++; aeoltl += sizeof(struct nvme_mi_aem_occ_data); @@ -878,8 +878,8 @@ static void populate_tx_occ_list(bool aem_not_ack, test_set_tx_mic(&test_peer); } -static void check_aem_sync_message(struct nvme_mi_aem_enabled_map *expected_mask, - struct nvme_mi_aem_enabled_map *expected_state, +static void check_aem_sync_message(struct libnvme_mi_aem_enabled_map *expected_mask, + struct libnvme_mi_aem_enabled_map *expected_state, struct aem_rcv_enable_fn_data *fn_data) { //Check the RX buffer for the endpoint. We should be getting a CONFIG SET AEM @@ -992,7 +992,7 @@ static int aem_rcv_enable_fn(struct test_peer *peer, void *buf, size_t len, int { assert(sd == peer->sd[TEST_PEER_SD_COMMANDS_IDX]); - struct nvme_mi_aem_enabled_map expected = {false}; + struct libnvme_mi_aem_enabled_map expected = {false}; //The items in the ep_enabled_map should get disabled check_aem_sync_message(&fn_data->ep_enabled_map, &expected, fn_data); @@ -1052,7 +1052,7 @@ static int aem_rcv_enable_fn(struct test_peer *peer, void *buf, size_t len, int return 0; } -enum nvme_mi_aem_handler_next_action aem_handler(nvme_mi_ep_t ep, size_t num_events, void *userdata) +enum libnvme_mi_aem_handler_next_action aem_handler(libnvme_mi_ep_t ep, size_t num_events, void *userdata) { struct aem_rcv_enable_fn_data *fn_data = userdata; @@ -1065,7 +1065,7 @@ enum nvme_mi_aem_handler_next_action aem_handler(nvme_mi_ep_t ep, size_t num_eve { //This means we just sent out first OCC data int item_count = 0; - struct nvme_mi_aem_enabled_map *map; + struct libnvme_mi_aem_enabled_map *map; //Count how many events we want to act are enabled switch (fn_data->state) { @@ -1089,7 +1089,7 @@ enum nvme_mi_aem_handler_next_action aem_handler(nvme_mi_ep_t ep, size_t num_eve assert(num_events == item_count); for (int i = 0; i < num_events; i++) { - struct nvme_mi_event *e = nvme_mi_aem_get_next_event(ep); + struct libnvme_mi_event *e = libnvme_mi_aem_get_next_event(ep); uint8_t idx = e->aeoi; assert(fn_data->events[idx]); @@ -1106,7 +1106,7 @@ enum nvme_mi_aem_handler_next_action aem_handler(nvme_mi_ep_t ep, size_t num_eve e->vend_spec_info, e->vend_spec_info_len) == 0); } - assert(nvme_mi_aem_get_next_event(ep) == NULL); + assert(libnvme_mi_aem_get_next_event(ep) == NULL); break; } default: @@ -1116,8 +1116,8 @@ enum nvme_mi_aem_handler_next_action aem_handler(nvme_mi_ep_t ep, size_t num_eve return NVME_MI_AEM_HNA_ACK; } -static void aem_test_aem_api_helper(nvme_mi_ep_t ep, - struct nvme_mi_aem_config *config, int expected_event_count) +static void aem_test_aem_api_helper(libnvme_mi_ep_t ep, + struct libnvme_mi_aem_config *config, int expected_event_count) { struct aem_rcv_enable_fn_data *fn_data = (struct aem_rcv_enable_fn_data *)test_peer.tx_data; @@ -1126,45 +1126,45 @@ static void aem_test_aem_api_helper(nvme_mi_ep_t ep, test_peer.tx_fn = aem_rcv_enable_fn; //This should not work outside the handler - assert(nvme_mi_aem_get_next_event(ep) == NULL); + assert(libnvme_mi_aem_get_next_event(ep) == NULL); - rc = nvme_mi_aem_enable(ep, config, test_peer.tx_data); + rc = libnvme_mi_aem_enable(ep, config, test_peer.tx_data); assert(rc == 0); //This should not work outside the handler - assert(nvme_mi_aem_get_next_event(ep) == NULL); + assert(libnvme_mi_aem_get_next_event(ep) == NULL); - rc = nvme_mi_aem_process(ep, test_peer.tx_data); + rc = libnvme_mi_aem_process(ep, test_peer.tx_data); assert(rc == 0); //One for initial enable, one for AEM. No ACK events assert(fn_data->callback_count == expected_event_count); //This should not work outside the handler - assert(nvme_mi_aem_get_next_event(ep) == NULL); + assert(libnvme_mi_aem_get_next_event(ep) == NULL); } -static void aem_test_aem_disable_helper(nvme_mi_ep_t ep, +static void aem_test_aem_disable_helper(libnvme_mi_ep_t ep, struct aem_rcv_enable_fn_data *fn_data) { memcpy(&fn_data->ep_enabled_map, &fn_data->host_enabled_map, sizeof(fn_data->host_enabled_map)); fn_data->state = AEM_ES_GET_ENABLED;//This is the flow for disabling - assert(nvme_mi_aem_disable(ep) == 0); + assert(libnvme_mi_aem_disable(ep) == 0); } -static void test_mi_aem_ep_based_failure_helper(nvme_mi_ep_t ep, +static void test_mi_aem_ep_based_failure_helper(libnvme_mi_ep_t ep, enum aem_failure_condition fc, struct test_peer *peer) { struct aem_rcv_enable_fn_data fn_data = {0}; - struct nvme_mi_aem_config config = {0}; + struct libnvme_mi_aem_config config = {0}; config.aemd = 1; config.aerd = 2; config.enabled_map.enabled[3] = true; fn_data.aem_during_process_map.enabled[3] = true; - struct nvme_mi_event e = {0}; + struct libnvme_mi_event e = {0}; e.aeoi = 3; e.spec_info_len = 0; @@ -1185,14 +1185,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) == -EPROTO); + assert(libnvme_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) == -EPROTO); + assert(libnvme_mi_aem_enable(ep, &config, &fn_data) == 0); + assert(libnvme_mi_aem_process(ep, &fn_data) == -EPROTO); break; default: assert(false);//Unexpected @@ -1200,7 +1200,7 @@ static void test_mi_aem_ep_based_failure_helper(nvme_mi_ep_t ep, } /* test: Check validation of endpoint messages in various stages of aem handling */ -static void test_mi_aem_ep_based_failure_conditions(nvme_mi_ep_t ep, struct test_peer *peer) +static void test_mi_aem_ep_based_failure_conditions(libnvme_mi_ep_t ep, struct test_peer *peer) { test_mi_aem_ep_based_failure_helper(ep, AEM_FC_BAD_GET_CONFIG_HEADER_LEN, peer); test_mi_aem_ep_based_failure_helper(ep, AEM_FC_BAD_GET_CONFIG_TOTAL_LEN, peer); @@ -1214,9 +1214,9 @@ static void test_mi_aem_ep_based_failure_conditions(nvme_mi_ep_t ep, struct test } /* test: Check aem process logic when API used improperly */ -static void test_mi_aem_enable_invalid_usage(nvme_mi_ep_t ep, struct test_peer *peer) +static void test_mi_aem_enable_invalid_usage(libnvme_mi_ep_t ep, struct test_peer *peer) { - struct nvme_mi_aem_config config = {0}; + struct libnvme_mi_aem_config config = {0}; config.aem_handler = aem_handler; config.enabled_map.enabled[0] = false; @@ -1224,54 +1224,54 @@ static void test_mi_aem_enable_invalid_usage(nvme_mi_ep_t ep, struct test_peer * config.aerd = 2; //Call with invalid config due to nothing enabled - assert(nvme_mi_aem_enable(ep, &config, NULL) == -1); + assert(libnvme_mi_aem_enable(ep, &config, NULL) == -1); config.aem_handler = NULL; config.enabled_map.enabled[0] = true; //Call with invalid config due to no callback - assert(nvme_mi_aem_enable(ep, &config, NULL) == -1); + assert(libnvme_mi_aem_enable(ep, &config, NULL) == -1); //Call with invalid config due to being NULL - assert(nvme_mi_aem_enable(ep, NULL, NULL) == -1); + assert(libnvme_mi_aem_enable(ep, NULL, NULL) == -1); config.aem_handler = aem_handler; config.enabled_map.enabled[0] = true; //Call with invalid endpoint - assert(nvme_mi_aem_enable(NULL, &config, NULL) == -1); + assert(libnvme_mi_aem_enable(NULL, &config, NULL) == -1); } /* test: Check aem process logic when API used improperly */ -static void test_mi_aem_process_invalid_usage(nvme_mi_ep_t ep, struct test_peer *peer) +static void test_mi_aem_process_invalid_usage(libnvme_mi_ep_t ep, struct test_peer *peer) { //Without calling enable first - assert(nvme_mi_aem_process(ep, NULL) == -1); + assert(libnvme_mi_aem_process(ep, NULL) == -1); //Call with invalid ep - assert(nvme_mi_aem_process(NULL, NULL) == -1); + assert(libnvme_mi_aem_process(NULL, NULL) == -1); } /* test: Check aem disable logic when API used improperly */ -static void test_mi_aem_disable_invalid_usage(nvme_mi_ep_t ep, struct test_peer *peer) +static void test_mi_aem_disable_invalid_usage(libnvme_mi_ep_t ep, struct test_peer *peer) { - assert(nvme_mi_aem_disable(NULL) == -1); + assert(libnvme_mi_aem_disable(NULL) == -1); } -static void test_mi_aem_get_enabled_invalid_usage(nvme_mi_ep_t ep, struct test_peer *peer) +static void test_mi_aem_get_enabled_invalid_usage(libnvme_mi_ep_t ep, struct test_peer *peer) { - struct nvme_mi_aem_enabled_map map; + struct libnvme_mi_aem_enabled_map map; - assert(nvme_mi_aem_get_enabled(ep, NULL) == -1); - assert(nvme_mi_aem_get_enabled(NULL, &map) == -1); + assert(libnvme_mi_aem_get_enabled(ep, NULL) == -1); + assert(libnvme_mi_aem_get_enabled(NULL, &map) == -1); } /* test: Check aem get enabled logic*/ -static void test_mi_aem_get_enabled(nvme_mi_ep_t ep, struct test_peer *peer) +static void test_mi_aem_get_enabled(libnvme_mi_ep_t ep, struct test_peer *peer) { //When no events enabled on Endpoint struct aem_rcv_enable_fn_data fn_data = {0}; - struct nvme_mi_aem_enabled_map map; + struct libnvme_mi_aem_enabled_map map; test_peer.tx_fn = aem_rcv_enable_fn; peer->tx_data = (void *) &fn_data; @@ -1280,13 +1280,13 @@ static void test_mi_aem_get_enabled(nvme_mi_ep_t ep, struct test_peer *peer) fn_data.ep_enabled_map.enabled[51] = true; fn_data.ep_enabled_map.enabled[255] = true; - assert(nvme_mi_aem_get_enabled(ep, &map) == 0); + assert(libnvme_mi_aem_get_enabled(ep, &map) == 0); assert(memcmp(&fn_data.ep_enabled_map, &map, sizeof(map)) == 0); } /* test: Check aem disable logic when called without an enable */ -static void test_mi_aem_disable_no_enable(nvme_mi_ep_t ep, struct test_peer *peer) +static void test_mi_aem_disable_no_enable(libnvme_mi_ep_t ep, struct test_peer *peer) { //When no events enabled on Endpoint struct aem_rcv_enable_fn_data fn_data = {0}; @@ -1303,10 +1303,10 @@ static void test_mi_aem_disable_no_enable(nvme_mi_ep_t ep, struct test_peer *pee } /* test: Check aem enable logic with ack carrying events */ -static void test_mi_aem_api_w_ack_events(nvme_mi_ep_t ep, struct test_peer *peer) +static void test_mi_aem_api_w_ack_events(libnvme_mi_ep_t ep, struct test_peer *peer) { struct aem_rcv_enable_fn_data fn_data = {0}; - struct nvme_mi_aem_config config = {0}; + struct libnvme_mi_aem_config config = {0}; config.aemd = 1; config.aerd = 2; @@ -1323,13 +1323,13 @@ static void test_mi_aem_api_w_ack_events(nvme_mi_ep_t ep, struct test_peer *peer //Will have EP have nothing enabled at start (ep_enabled_map) - struct nvme_mi_event ev5 = {0}; + struct libnvme_mi_event ev5 = {0}; ev5.aeoi = 5; ev5.aeocidi = 2; ev5.aessi = 3; - struct nvme_mi_event ev15 = {0}; + struct libnvme_mi_event ev15 = {0}; uint8_t ev15_spec[] = { 45, 15}; ev15.aeoi = 15; @@ -1349,10 +1349,10 @@ static void test_mi_aem_api_w_ack_events(nvme_mi_ep_t ep, struct test_peer *peer } /* test: Check aem enable logic */ -static void test_mi_aem_api_simple(nvme_mi_ep_t ep, struct test_peer *peer) +static void test_mi_aem_api_simple(libnvme_mi_ep_t ep, struct test_peer *peer) { struct aem_rcv_enable_fn_data fn_data = {0}; - struct nvme_mi_aem_config config = {0}; + struct libnvme_mi_aem_config config = {0}; config.aemd = 1; config.aerd = 2; @@ -1371,7 +1371,7 @@ static void test_mi_aem_api_simple(nvme_mi_ep_t ep, struct test_peer *peer) fn_data.ep_enabled_map.enabled[20] = true; fn_data.ep_enabled_map.enabled[200] = true; - struct nvme_mi_event ev1 = {0}; + struct libnvme_mi_event ev1 = {0}; uint8_t ev1_spec[] = { 98, 56, 32, 12}; ev1.aeoi = 1; @@ -1380,7 +1380,7 @@ static void test_mi_aem_api_simple(nvme_mi_ep_t ep, struct test_peer *peer) ev1.spec_info = ev1_spec; ev1.spec_info_len = sizeof(ev1_spec); - struct nvme_mi_event ev3 = {0}; + struct libnvme_mi_event ev3 = {0}; uint8_t ev3_spec[] = { 45, 15}; ev3.aeoi = 3; @@ -1389,7 +1389,7 @@ static void test_mi_aem_api_simple(nvme_mi_ep_t ep, struct test_peer *peer) ev3.spec_info = ev3_spec; ev3.spec_info_len = sizeof(ev3_spec); - struct nvme_mi_event ev16 = {0}; + struct libnvme_mi_event ev16 = {0}; ev16.aeoi = 16; ev16.aeocidi = 6; @@ -1409,7 +1409,7 @@ static void test_mi_aem_api_simple(nvme_mi_ep_t ep, struct test_peer *peer) #define DEFINE_TEST(name) { #name, test_ ## name } struct test { const char *name; - void (*fn)(nvme_mi_ep_t, struct test_peer *); + void (*fn)(libnvme_mi_ep_t, struct test_peer *); } tests[] = { DEFINE_TEST(rx_err), DEFINE_TEST(tx_none), @@ -1441,7 +1441,7 @@ struct test { DEFINE_TEST(mi_aem_ep_based_failure_conditions), }; -static void run_test(struct test *test, FILE *logfd, nvme_mi_ep_t ep, +static void run_test(struct test *test, FILE *logfd, libnvme_mi_ep_t ep, struct test_peer *peer) { printf("Running test %s...", test->name); @@ -1453,19 +1453,19 @@ static void run_test(struct test *test, FILE *logfd, nvme_mi_ep_t ep, int main(void) { - struct nvme_global_ctx *ctx; - nvme_mi_ep_t ep; + struct libnvme_global_ctx *ctx; + libnvme_mi_ep_t ep; unsigned int i; FILE *fd; fd = test_setup_log(); - __nvme_mi_mctp_set_ops(&ops); + __libnvme_mi_mctp_set_ops(&ops); - ctx = nvme_create_global_ctx(fd, DEFAULT_LOGLEVEL); + ctx = libnvme_create_global_ctx(fd, DEFAULT_LOGLEVEL); assert(ctx); - ep = nvme_mi_open_mctp(ctx, 0, 0); + ep = libnvme_mi_open_mctp(ctx, 0, 0); assert(ep); for (i = 0; i < ARRAY_SIZE(tests); i++) { @@ -1473,8 +1473,8 @@ int main(void) run_test(&tests[i], fd, ep, &test_peer); } - nvme_mi_close(ep); - nvme_free_global_ctx(ctx); + libnvme_mi_close(ep); + libnvme_free_global_ctx(ctx); test_close_log(fd); diff --git a/libnvme/test/mi.c b/libnvme/test/mi.c index 3a890bc716..8d033cd590 100644 --- a/libnvme/test/mi.c +++ b/libnvme/test/mi.c @@ -21,9 +21,9 @@ #include "utils.h" -typedef int (*test_submit_cb)(struct nvme_mi_ep *ep, - struct nvme_mi_req *req, - struct nvme_mi_resp *resp, +typedef int (*test_submit_cb)(struct libnvme_mi_ep *ep, + struct libnvme_mi_req *req, + struct libnvme_mi_resp *resp, void *data); struct test_transport_data { @@ -35,9 +35,9 @@ struct test_transport_data { static const int test_transport_magic = 0x74657374; -static int test_transport_submit(struct nvme_mi_ep *ep, - struct nvme_mi_req *req, - struct nvme_mi_resp *resp) +static int test_transport_submit(struct libnvme_mi_ep *ep, + struct libnvme_mi_req *req, + struct libnvme_mi_resp *resp) { struct test_transport_data *tpd = ep->transport_data; @@ -56,14 +56,14 @@ static int test_transport_submit(struct nvme_mi_ep *ep, return 0; } -static void test_transport_close(struct nvme_mi_ep *ep) +static void test_transport_close(struct libnvme_mi_ep *ep) { struct test_transport_data *tpd = ep->transport_data; assert(tpd->magic == test_transport_magic); free(tpd); } -static int test_transport_desc_ep(struct nvme_mi_ep *ep, +static int test_transport_desc_ep(struct libnvme_mi_ep *ep, char *buf, size_t len) { struct test_transport_data *tpd = ep->transport_data; @@ -79,18 +79,18 @@ static int test_transport_desc_ep(struct nvme_mi_ep *ep, } /* internal test helper to generate correct response crc */ -static void test_transport_resp_calc_mic(struct nvme_mi_resp *resp) +static void test_transport_resp_calc_mic(struct libnvme_mi_resp *resp) { - extern __u32 nvme_mi_crc32_update(__u32 crc, void *data, size_t len); + extern __u32 libnvme_mi_crc32_update(__u32 crc, void *data, size_t len); __u32 crc = 0xffffffff; - crc = nvme_mi_crc32_update(crc, resp->hdr, resp->hdr_len); - crc = nvme_mi_crc32_update(crc, resp->data, resp->data_len); + crc = libnvme_mi_crc32_update(crc, resp->hdr, resp->hdr_len); + crc = libnvme_mi_crc32_update(crc, resp->data, resp->data_len); resp->mic = ~crc; } -static const struct nvme_mi_transport test_transport = { +static const struct libnvme_mi_transport test_transport = { .name = "test-mi", .mic_enabled = true, .submit = test_transport_submit, @@ -102,7 +102,7 @@ static const struct nvme_mi_transport test_transport = { .aem_read = NULL, }; -static void test_set_transport_callback(nvme_mi_ep_t ep, test_submit_cb cb, +static void test_set_transport_callback(libnvme_mi_ep_t ep, test_submit_cb cb, void *data) { struct test_transport_data *tpd = ep->transport_data; @@ -112,12 +112,12 @@ static void test_set_transport_callback(nvme_mi_ep_t ep, test_submit_cb cb, tpd->submit_cb_data = data; } -nvme_mi_ep_t nvme_mi_open_test(struct nvme_global_ctx *ctx) +libnvme_mi_ep_t libnvme_mi_open_test(struct libnvme_global_ctx *ctx) { struct test_transport_data *tpd; - struct nvme_mi_ep *ep; + struct libnvme_mi_ep *ep; - ep = nvme_mi_init_ep(ctx); + ep = libnvme_mi_init_ep(ctx); assert(ep); /* preempt the quirk probe to avoid clutter */ @@ -135,12 +135,12 @@ nvme_mi_ep_t nvme_mi_open_test(struct nvme_global_ctx *ctx) return ep; } -unsigned int count_root_eps(struct nvme_global_ctx *ctx) +unsigned int count_root_eps(struct libnvme_global_ctx *ctx) { unsigned int i = 0; - nvme_mi_ep_t ep; + libnvme_mi_ep_t ep; - nvme_mi_for_each_endpoint(ctx, ep) + libnvme_mi_for_each_endpoint(ctx, ep) i++; return i; @@ -148,30 +148,30 @@ unsigned int count_root_eps(struct nvme_global_ctx *ctx) /* test that the root->endpoints list is updated on endpoint * creation/destruction */ -static void test_endpoint_lifetime(nvme_mi_ep_t ep) +static void test_endpoint_lifetime(libnvme_mi_ep_t ep) { - struct nvme_global_ctx *ctx= ep->ctx; + struct libnvme_global_ctx *ctx= ep->ctx; unsigned int count; - nvme_mi_ep_t ep2; + libnvme_mi_ep_t ep2; count = count_root_eps(ctx); assert(count == 1); - ep2 = nvme_mi_open_test(ctx); + ep2 = libnvme_mi_open_test(ctx); count = count_root_eps(ctx); assert(count == 2); - nvme_mi_close(ep2); + libnvme_mi_close(ep2); count = count_root_eps(ctx); assert(count == 1); } -unsigned int count_ep_controllers(nvme_mi_ep_t ep) +unsigned int count_ep_controllers(libnvme_mi_ep_t ep) { - struct nvme_transport_handle *hdl; + struct libnvme_transport_handle *hdl; unsigned int i = 0; - nvme_mi_for_each_transport_handle(ep, hdl) + libnvme_mi_for_each_transport_handle(ep, hdl) i++; return i; @@ -179,9 +179,9 @@ unsigned int count_ep_controllers(nvme_mi_ep_t ep) /* test that the ep->controllers list is updated on controller * creation/destruction */ -static void test_ctrl_lifetime(nvme_mi_ep_t ep) +static void test_ctrl_lifetime(libnvme_mi_ep_t ep) { - struct nvme_transport_handle *hdl1, *hdl2; + struct libnvme_transport_handle *hdl1, *hdl2; int count; ep->controllers_scanned = true; @@ -189,28 +189,28 @@ static void test_ctrl_lifetime(nvme_mi_ep_t ep) count = count_ep_controllers(ep); assert(count == 0); - hdl1 = nvme_mi_init_transport_handle(ep, 1); + hdl1 = libnvme_mi_init_transport_handle(ep, 1); count = count_ep_controllers(ep); assert(count == 1); - hdl2 = nvme_mi_init_transport_handle(ep, 2); + hdl2 = libnvme_mi_init_transport_handle(ep, 2); count = count_ep_controllers(ep); assert(count == 2); - nvme_close(hdl1); + libnvme_close(hdl1); count = count_ep_controllers(ep); assert(count == 1); - nvme_close(hdl2); + libnvme_close(hdl2); count = count_ep_controllers(ep); assert(count == 0); } /* test: basic read MI datastructure command */ -static int test_read_mi_data_cb(struct nvme_mi_ep *ep, - struct nvme_mi_req *req, - struct nvme_mi_resp *resp, +static int test_read_mi_data_cb(struct libnvme_mi_ep *ep, + struct libnvme_mi_req *req, + struct libnvme_mi_resp *resp, void *data) { __u8 ror, mt, *hdr, *buf; @@ -247,37 +247,37 @@ static int test_read_mi_data_cb(struct nvme_mi_ep *ep, return 0; } -static void test_read_mi_data(nvme_mi_ep_t ep) +static void test_read_mi_data(libnvme_mi_ep_t ep) { struct nvme_mi_read_nvm_ss_info ss_info; int rc; test_set_transport_callback(ep, test_read_mi_data_cb, NULL); - rc = nvme_mi_mi_read_mi_data_subsys(ep, &ss_info); + rc = libnvme_mi_mi_read_mi_data_subsys(ep, &ss_info); assert(rc == 0); } /* test: failed transport */ -static int test_transport_fail_cb(struct nvme_mi_ep *ep, - struct nvme_mi_req *req, - struct nvme_mi_resp *resp, +static int test_transport_fail_cb(struct libnvme_mi_ep *ep, + struct libnvme_mi_req *req, + struct libnvme_mi_resp *resp, void *data) { return -1; } -static void test_transport_fail(nvme_mi_ep_t ep) +static void test_transport_fail(libnvme_mi_ep_t ep) { struct nvme_mi_read_nvm_ss_info ss_info; int rc; test_set_transport_callback(ep, test_transport_fail_cb, NULL); - rc = nvme_mi_mi_read_mi_data_subsys(ep, &ss_info); + rc = libnvme_mi_mi_read_mi_data_subsys(ep, &ss_info); assert(rc != 0); } -static void test_transport_describe(nvme_mi_ep_t ep) +static void test_transport_describe(libnvme_mi_ep_t ep) { struct test_transport_data *tpd; char *str; @@ -285,43 +285,43 @@ static void test_transport_describe(nvme_mi_ep_t ep) tpd = (struct test_transport_data *)ep->transport_data; tpd->named = false; - str = nvme_mi_endpoint_desc(ep); + str = libnvme_mi_endpoint_desc(ep); assert(str); assert(!strcmp(str, "test-mi endpoint")); free(str); tpd->named = true; - str = nvme_mi_endpoint_desc(ep); + str = libnvme_mi_endpoint_desc(ep); assert(str); assert(!strcmp(str, "test-mi: test endpoint 0x74657374")); free(str); } /* test: invalid crc */ -static int test_invalid_crc_cb(struct nvme_mi_ep *ep, - struct nvme_mi_req *req, - struct nvme_mi_resp *resp, +static int test_invalid_crc_cb(struct libnvme_mi_ep *ep, + struct libnvme_mi_req *req, + struct libnvme_mi_resp *resp, void *data) { resp->mic = 0; return 0; } -static void test_invalid_crc(nvme_mi_ep_t ep) +static void test_invalid_crc(libnvme_mi_ep_t ep) { struct nvme_mi_read_nvm_ss_info ss_info; int rc; test_set_transport_callback(ep, test_invalid_crc_cb, NULL); - rc = nvme_mi_mi_read_mi_data_subsys(ep, &ss_info); + rc = libnvme_mi_mi_read_mi_data_subsys(ep, &ss_info); assert(rc < 0); } /* test: test that the controller list populates the endpoint's list of * controllers */ -static int test_scan_ctrl_list_cb(struct nvme_mi_ep *ep, - struct nvme_mi_req *req, - struct nvme_mi_resp *resp, +static int test_scan_ctrl_list_cb(struct libnvme_mi_ep *ep, + struct libnvme_mi_req *req, + struct libnvme_mi_resp *resp, void *data) { __u8 ror, mt, *hdr, *buf; @@ -360,36 +360,36 @@ static int test_scan_ctrl_list_cb(struct nvme_mi_ep *ep, return 0; } -static void test_scan_ctrl_list(nvme_mi_ep_t ep) +static void test_scan_ctrl_list(libnvme_mi_ep_t ep) { - struct nvme_transport_handle *hdl; + struct libnvme_transport_handle *hdl; ep->controllers_scanned = false; test_set_transport_callback(ep, test_scan_ctrl_list_cb, NULL); - nvme_mi_scan_ep(ep, false); + libnvme_mi_scan_ep(ep, false); - hdl = nvme_mi_first_transport_handle(ep); + hdl = libnvme_mi_first_transport_handle(ep); assert(hdl); assert(hdl->id == 1); - hdl = nvme_mi_next_transport_handle(ep, hdl); + hdl = libnvme_mi_next_transport_handle(ep, hdl); assert(hdl); assert(hdl->id == 4); - hdl = nvme_mi_next_transport_handle(ep, hdl); + hdl = libnvme_mi_next_transport_handle(ep, hdl); assert(hdl); assert(hdl->id == 5); - hdl = nvme_mi_next_transport_handle(ep, hdl); + hdl = libnvme_mi_next_transport_handle(ep, hdl); assert(hdl == NULL); } /* test: simple NVMe admin request/response */ -static int test_admin_id_cb(struct nvme_mi_ep *ep, - struct nvme_mi_req *req, - struct nvme_mi_resp *resp, +static int test_admin_id_cb(struct libnvme_mi_ep *ep, + struct libnvme_mi_req *req, + struct libnvme_mi_resp *resp, void *data) { __u8 ror, mt, *hdr; @@ -436,27 +436,27 @@ static int test_admin_id_cb(struct nvme_mi_ep *ep, return 0; } -static void test_admin_id(nvme_mi_ep_t ep) +static void test_admin_id(libnvme_mi_ep_t ep) { - struct nvme_transport_handle *hdl; - struct nvme_passthru_cmd cmd; + struct libnvme_transport_handle *hdl; + struct libnvme_passthru_cmd cmd; struct nvme_id_ctrl id; int rc; test_set_transport_callback(ep, test_admin_id_cb, NULL); - hdl = nvme_mi_init_transport_handle(ep, 5); + hdl = libnvme_mi_init_transport_handle(ep, 5); assert(hdl); nvme_init_identify_ctrl(&cmd, &id); - rc = nvme_submit_admin_passthru(hdl, &cmd); + rc = libnvme_submit_admin_passthru(hdl, &cmd); assert(rc == 0); } /* test: simple NVMe error response, error reported in the MI header */ -static int test_admin_err_mi_resp_cb(struct nvme_mi_ep *ep, - struct nvme_mi_req *req, - struct nvme_mi_resp *resp, +static int test_admin_err_mi_resp_cb(struct libnvme_mi_ep *ep, + struct libnvme_mi_req *req, + struct libnvme_mi_resp *resp, void *data) { __u8 ror, mt, *hdr; @@ -492,29 +492,29 @@ static int test_admin_err_mi_resp_cb(struct nvme_mi_ep *ep, return 0; } -static void test_admin_err_mi_resp(nvme_mi_ep_t ep) +static void test_admin_err_mi_resp(libnvme_mi_ep_t ep) { - struct nvme_transport_handle *hdl; - struct nvme_passthru_cmd cmd; + struct libnvme_transport_handle *hdl; + struct libnvme_passthru_cmd cmd; struct nvme_id_ctrl id; int rc; test_set_transport_callback(ep, test_admin_err_mi_resp_cb, NULL); - hdl = nvme_mi_init_transport_handle(ep, 1); + hdl = libnvme_mi_init_transport_handle(ep, 1); assert(hdl); nvme_init_identify_ctrl(&cmd, &id); - rc = nvme_submit_admin_passthru(hdl, &cmd); + rc = libnvme_submit_admin_passthru(hdl, &cmd); assert(rc != 0); assert(nvme_status_get_type(rc) == NVME_STATUS_TYPE_MI); assert(nvme_status_get_value(rc) == NVME_MI_RESP_INTERNAL_ERR); } /* test: NVMe Admin error, with the error reported in the Admin response */ -static int test_admin_err_nvme_resp_cb(struct nvme_mi_ep *ep, - struct nvme_mi_req *req, - struct nvme_mi_resp *resp, +static int test_admin_err_nvme_resp_cb(struct libnvme_mi_ep *ep, + struct libnvme_mi_req *req, + struct libnvme_mi_resp *resp, void *data) { __u8 ror, mt, *hdr; @@ -556,20 +556,20 @@ static int test_admin_err_nvme_resp_cb(struct nvme_mi_ep *ep, return 0; } -static void test_admin_err_nvme_resp(nvme_mi_ep_t ep) +static void test_admin_err_nvme_resp(libnvme_mi_ep_t ep) { struct nvme_id_ctrl id; - struct nvme_transport_handle *hdl; - struct nvme_passthru_cmd cmd; + struct libnvme_transport_handle *hdl; + struct libnvme_passthru_cmd cmd; int rc; test_set_transport_callback(ep, test_admin_err_nvme_resp_cb, NULL); - hdl = nvme_mi_init_transport_handle(ep, 1); + hdl = libnvme_mi_init_transport_handle(ep, 1); assert(hdl); nvme_init_identify_ctrl(&cmd, &id); - rc = nvme_submit_admin_passthru(hdl, &cmd); + rc = libnvme_submit_admin_passthru(hdl, &cmd); assert(rc != 0); assert(nvme_status_get_type(rc) == NVME_STATUS_TYPE_NVME); assert(nvme_status_get_value(rc) == @@ -578,9 +578,9 @@ static void test_admin_err_nvme_resp(nvme_mi_ep_t ep) } /* invalid command transfers */ -static int test_rejected_command_cb(struct nvme_mi_ep *ep, - struct nvme_mi_req *req, - struct nvme_mi_resp *resp, +static int test_rejected_command_cb(struct libnvme_mi_ep *ep, + struct libnvme_mi_req *req, + struct libnvme_mi_resp *resp, void *data) { /* none of the tests should result in message transfer */ @@ -588,84 +588,84 @@ static int test_rejected_command_cb(struct nvme_mi_ep *ep, return -1; } -static void test_admin_invalid_formats(nvme_mi_ep_t ep) +static void test_admin_invalid_formats(libnvme_mi_ep_t ep) { struct { struct nvme_mi_admin_req_hdr hdr; uint8_t data[4]; } req = { 0 }; struct nvme_mi_admin_resp_hdr resp = { 0 }; - struct nvme_transport_handle *hdl; + struct libnvme_transport_handle *hdl; size_t len; int rc; test_set_transport_callback(ep, test_rejected_command_cb, NULL); - hdl = nvme_mi_init_transport_handle(ep, 1); + hdl = libnvme_mi_init_transport_handle(ep, 1); assert(hdl); /* unaligned req size */ len = 0; - rc = nvme_mi_admin_xfer(hdl, &req.hdr, 1, &resp, 0, &len); + rc = libnvme_mi_admin_xfer(hdl, &req.hdr, 1, &resp, 0, &len); assert(rc != 0); /* unaligned resp size */ len = 1; - rc = nvme_mi_admin_xfer(hdl, &req.hdr, 0, &resp, 0, &len); + rc = libnvme_mi_admin_xfer(hdl, &req.hdr, 0, &resp, 0, &len); assert(rc != 0); /* unaligned resp offset */ len = 4; - rc = nvme_mi_admin_xfer(hdl, &req.hdr, 0, &resp, 1, &len); + rc = libnvme_mi_admin_xfer(hdl, &req.hdr, 0, &resp, 1, &len); assert(rc != 0); /* resp too large */ len = 4096 + 4; - rc = nvme_mi_admin_xfer(hdl, &req.hdr, 0, &resp, 0, &len); + rc = libnvme_mi_admin_xfer(hdl, &req.hdr, 0, &resp, 0, &len); assert(rc != 0); /* resp offset too large */ len = 4; - rc = nvme_mi_admin_xfer(hdl, &req.hdr, 0, &resp, (off_t)1 << 32, &len); + rc = libnvme_mi_admin_xfer(hdl, &req.hdr, 0, &resp, (off_t)1 << 32, &len); assert(rc != 0); /* resp offset with no len */ len = 0; - rc = nvme_mi_admin_xfer(hdl, &req.hdr, 0, &resp, 4, &len); + rc = libnvme_mi_admin_xfer(hdl, &req.hdr, 0, &resp, 4, &len); assert(rc != 0); /* req and resp payloads */ len = 4; - rc = nvme_mi_admin_xfer(hdl, &req.hdr, 4, &resp, 0, &len); + rc = libnvme_mi_admin_xfer(hdl, &req.hdr, 4, &resp, 0, &len); assert(rc != 0); } -static void test_mi_invalid_formats(nvme_mi_ep_t ep) +static void test_mi_invalid_formats(libnvme_mi_ep_t ep) { struct { struct nvme_mi_mi_req_hdr hdr; uint8_t data[4]; } req = { 0 }; struct nvme_mi_mi_resp_hdr resp = { 0 }; - struct nvme_transport_handle *hdl; + struct libnvme_transport_handle *hdl; size_t len; int rc; test_set_transport_callback(ep, test_rejected_command_cb, NULL); - hdl = nvme_mi_init_transport_handle(ep, 1); + hdl = libnvme_mi_init_transport_handle(ep, 1); assert(hdl); /* resp too large */ len = 4096 + 4; - rc = nvme_mi_mi_xfer(ep, &req.hdr, 0, &resp, &len); + rc = libnvme_mi_mi_xfer(ep, &req.hdr, 0, &resp, &len); assert(rc != 0); } /* test: header length too small */ -static int test_resp_hdr_small_cb(struct nvme_mi_ep *ep, - struct nvme_mi_req *req, - struct nvme_mi_resp *resp, +static int test_resp_hdr_small_cb(struct libnvme_mi_ep *ep, + struct libnvme_mi_req *req, + struct libnvme_mi_resp *resp, void *data) { resp->hdr_len = 2; @@ -673,21 +673,21 @@ static int test_resp_hdr_small_cb(struct nvme_mi_ep *ep, return 0; } -static void test_resp_hdr_small(nvme_mi_ep_t ep) +static void test_resp_hdr_small(libnvme_mi_ep_t ep) { struct nvme_mi_read_nvm_ss_info ss_info; int rc; test_set_transport_callback(ep, test_resp_hdr_small_cb, NULL); - rc = nvme_mi_mi_read_mi_data_subsys(ep, &ss_info); + rc = libnvme_mi_mi_read_mi_data_subsys(ep, &ss_info); assert(rc != 0); } /* test: respond with a request message */ -static int test_resp_req_cb(struct nvme_mi_ep *ep, - struct nvme_mi_req *req, - struct nvme_mi_resp *resp, +static int test_resp_req_cb(struct libnvme_mi_ep *ep, + struct libnvme_mi_req *req, + struct libnvme_mi_resp *resp, void *data) { resp->hdr->nmp &= ~(NVME_MI_ROR_RSP << 7); @@ -695,21 +695,21 @@ static int test_resp_req_cb(struct nvme_mi_ep *ep, return 0; } -static void test_resp_req(nvme_mi_ep_t ep) +static void test_resp_req(libnvme_mi_ep_t ep) { struct nvme_mi_read_nvm_ss_info ss_info; int rc; test_set_transport_callback(ep, test_resp_req_cb, NULL); - rc = nvme_mi_mi_read_mi_data_subsys(ep, &ss_info); + rc = libnvme_mi_mi_read_mi_data_subsys(ep, &ss_info); assert(rc != 0); } /* test: invalid MCTP type in response */ -static int test_resp_invalid_type_cb(struct nvme_mi_ep *ep, - struct nvme_mi_req *req, - struct nvme_mi_resp *resp, +static int test_resp_invalid_type_cb(struct libnvme_mi_ep *ep, + struct libnvme_mi_req *req, + struct libnvme_mi_resp *resp, void *data) { resp->hdr->type = 0x3; @@ -717,21 +717,21 @@ static int test_resp_invalid_type_cb(struct nvme_mi_ep *ep, return 0; } -static void test_resp_invalid_type(nvme_mi_ep_t ep) +static void test_resp_invalid_type(libnvme_mi_ep_t ep) { struct nvme_mi_read_nvm_ss_info ss_info; int rc; test_set_transport_callback(ep, test_resp_invalid_type_cb, NULL); - rc = nvme_mi_mi_read_mi_data_subsys(ep, &ss_info); + rc = libnvme_mi_mi_read_mi_data_subsys(ep, &ss_info); assert(rc != 0); } /* test: response with mis-matching command slot */ -static int test_resp_csi_invert_cb(struct nvme_mi_ep *ep, - struct nvme_mi_req *req, - struct nvme_mi_resp *resp, +static int test_resp_csi_invert_cb(struct libnvme_mi_ep *ep, + struct libnvme_mi_req *req, + struct libnvme_mi_resp *resp, void *data) { resp->hdr->nmp ^= 0x1; @@ -740,9 +740,9 @@ static int test_resp_csi_invert_cb(struct nvme_mi_ep *ep, } /* test: validation of proper csi setting */ -static int test_resp_csi_check_cb(struct nvme_mi_ep *ep, - struct nvme_mi_req *req, - struct nvme_mi_resp *resp, +static int test_resp_csi_check_cb(struct libnvme_mi_ep *ep, + struct libnvme_mi_req *req, + struct libnvme_mi_resp *resp, void *data) { assert((req->hdr->nmp & 1) == (ep->csi & 1)); @@ -750,50 +750,50 @@ static int test_resp_csi_check_cb(struct nvme_mi_ep *ep, } /* test: Ensure that csi bit is set properly in the request */ -static void test_resp_csi_request(nvme_mi_ep_t ep) +static void test_resp_csi_request(libnvme_mi_ep_t ep) { struct nvme_mi_read_nvm_ss_info ss_info; int rc; test_set_transport_callback(ep, test_resp_csi_check_cb, NULL); - rc = nvme_mi_mi_read_mi_data_subsys(ep, &ss_info); + rc = libnvme_mi_mi_read_mi_data_subsys(ep, &ss_info); assert(rc != 0); - nvme_mi_set_csi(ep, 1);//Change CSI + libnvme_mi_set_csi(ep, 1);//Change CSI - rc = nvme_mi_mi_read_mi_data_subsys(ep, &ss_info); + rc = libnvme_mi_mi_read_mi_data_subsys(ep, &ss_info); assert(rc != 0); - nvme_mi_set_csi(ep, 0);//Change CSI + libnvme_mi_set_csi(ep, 0);//Change CSI } /* test: Ensure that when csi bit set wrong in response, * it results in an error */ -static void test_resp_csi_mismatch(nvme_mi_ep_t ep) +static void test_resp_csi_mismatch(libnvme_mi_ep_t ep) { struct nvme_mi_read_nvm_ss_info ss_info; int rc; test_set_transport_callback(ep, test_resp_csi_invert_cb, NULL); - rc = nvme_mi_mi_read_mi_data_subsys(ep, &ss_info); + rc = libnvme_mi_mi_read_mi_data_subsys(ep, &ss_info); assert(rc != 0); - nvme_mi_set_csi(ep, 1);//Change CSI + libnvme_mi_set_csi(ep, 1);//Change CSI - rc = nvme_mi_mi_read_mi_data_subsys(ep, &ss_info); + rc = libnvme_mi_mi_read_mi_data_subsys(ep, &ss_info); assert(rc != 0); - nvme_mi_set_csi(ep, 0);//Change CSI + libnvme_mi_set_csi(ep, 0);//Change CSI } /* test: config get MTU request & response layout, ensure we're handling * endianness in the 3-byte NMRESP field correctly */ -static int test_mi_config_get_mtu_cb(struct nvme_mi_ep *ep, - struct nvme_mi_req *req, - struct nvme_mi_resp *resp, +static int test_mi_config_get_mtu_cb(struct libnvme_mi_ep *ep, + struct libnvme_mi_req *req, + struct libnvme_mi_resp *resp, void *data) { struct nvme_mi_mi_resp_hdr *mi_resp; @@ -820,22 +820,22 @@ static int test_mi_config_get_mtu_cb(struct nvme_mi_ep *ep, return 0; } -static void test_mi_config_get_mtu(nvme_mi_ep_t ep) +static void test_mi_config_get_mtu(libnvme_mi_ep_t ep) { uint16_t mtu; int rc; test_set_transport_callback(ep, test_mi_config_get_mtu_cb, NULL); - rc = nvme_mi_mi_config_get_mctp_mtu(ep, 5, &mtu); + rc = libnvme_mi_mi_config_get_mctp_mtu(ep, 5, &mtu); assert(rc == 0); assert(mtu == 0x1234); } /* test: config set SMBus freq, both valid and invalid */ -static int test_mi_config_set_freq_cb(struct nvme_mi_ep *ep, - struct nvme_mi_req *req, - struct nvme_mi_resp *resp, +static int test_mi_config_set_freq_cb(struct libnvme_mi_ep *ep, + struct libnvme_mi_req *req, + struct libnvme_mi_resp *resp, void *data) { struct nvme_mi_mi_resp_hdr *mi_resp; @@ -871,24 +871,24 @@ static int test_mi_config_set_freq_cb(struct nvme_mi_ep *ep, return 0; } -static void test_mi_config_set_freq(nvme_mi_ep_t ep) +static void test_mi_config_set_freq(libnvme_mi_ep_t ep) { int rc; test_set_transport_callback(ep, test_mi_config_set_freq_cb, NULL); - rc = nvme_mi_mi_config_set_smbus_freq(ep, 5, + rc = libnvme_mi_mi_config_set_smbus_freq(ep, 5, NVME_MI_CONFIG_SMBUS_FREQ_100kHz); assert(rc == 0); } -static void test_mi_config_set_freq_invalid(nvme_mi_ep_t ep) +static void test_mi_config_set_freq_invalid(libnvme_mi_ep_t ep) { int rc; test_set_transport_callback(ep, test_mi_config_set_freq_cb, NULL); - rc = nvme_mi_mi_config_set_smbus_freq(ep, 5, + rc = libnvme_mi_mi_config_set_smbus_freq(ep, 5, NVME_MI_CONFIG_SMBUS_FREQ_1MHz); assert(rc == 4); } @@ -896,9 +896,9 @@ static void test_mi_config_set_freq_invalid(nvme_mi_ep_t ep) /* Get Features callback, implementing Arbitration (which doesn't return * additional data) and Timestamp (which does). */ -static int test_admin_get_features_cb(struct nvme_mi_ep *ep, - struct nvme_mi_req *req, - struct nvme_mi_resp *resp, +static int test_admin_get_features_cb(struct libnvme_mi_ep *ep, + struct libnvme_mi_req *req, + struct libnvme_mi_resp *resp, void *data) { __u8 sel, fid, ror, mt, *rq_hdr, *rs_hdr, *rs_data; @@ -965,27 +965,27 @@ static int test_admin_get_features_cb(struct nvme_mi_ep *ep, return 0; } -static void test_get_features(nvme_mi_ep_t ep) +static void test_get_features(libnvme_mi_ep_t ep) { - struct nvme_transport_handle *hdl; - struct nvme_passthru_cmd cmd; + struct libnvme_transport_handle *hdl; + struct libnvme_passthru_cmd cmd; int rc; test_set_transport_callback(ep, test_admin_get_features_cb, NULL); - hdl = nvme_mi_init_transport_handle(ep, 5); + hdl = libnvme_mi_init_transport_handle(ep, 5); assert(hdl); nvme_init_get_features(&cmd, NVME_FEAT_FID_ARBITRATION, 0); - rc = nvme_submit_admin_passthru(hdl, &cmd); + rc = libnvme_submit_admin_passthru(hdl, &cmd); assert(rc == 0); assert(cmd.result == 0x04030201); } /* Set Features callback for timestamp */ -static int test_admin_set_features_cb(struct nvme_mi_ep *ep, - struct nvme_mi_req *req, - struct nvme_mi_resp *resp, +static int test_admin_set_features_cb(struct libnvme_mi_ep *ep, + struct libnvme_mi_req *req, + struct libnvme_mi_resp *resp, void *data) { __u8 save, fid, ror, mt, *rq_hdr, *rq_data, *rs_hdr; @@ -1034,20 +1034,20 @@ static int test_admin_set_features_cb(struct nvme_mi_ep *ep, return 0; } -static void test_set_features(nvme_mi_ep_t ep) +static void test_set_features(libnvme_mi_ep_t ep) { struct nvme_timestamp tstmp = { 0 }; - struct nvme_transport_handle *hdl; - struct nvme_passthru_cmd cmd; + struct libnvme_transport_handle *hdl; + struct libnvme_passthru_cmd cmd; int rc; test_set_transport_callback(ep, test_admin_set_features_cb, NULL); - hdl = nvme_mi_init_transport_handle(ep, 5); + hdl = libnvme_mi_init_transport_handle(ep, 5); assert(hdl); nvme_init_set_features_timestamp(&cmd, true, 0x050403020100, &tstmp); - rc = nvme_submit_admin_passthru(hdl, &cmd); + rc = libnvme_submit_admin_passthru(hdl, &cmd); assert(rc == 0); } @@ -1056,9 +1056,9 @@ enum ns_type { NS_ALLOC, }; -static int test_admin_id_ns_list_cb(struct nvme_mi_ep *ep, - struct nvme_mi_req *req, - struct nvme_mi_resp *resp, +static int test_admin_id_ns_list_cb(struct libnvme_mi_ep *ep, + struct libnvme_mi_req *req, + struct libnvme_mi_resp *resp, void *data) { struct nvme_ns_list *list; @@ -1102,10 +1102,10 @@ static int test_admin_id_ns_list_cb(struct nvme_mi_ep *ep, return 0; } -static void test_admin_id_alloc_ns_list(struct nvme_mi_ep *ep) +static void test_admin_id_alloc_ns_list(struct libnvme_mi_ep *ep) { - struct nvme_transport_handle *hdl; - struct nvme_passthru_cmd cmd; + struct libnvme_transport_handle *hdl; + struct libnvme_passthru_cmd cmd; struct nvme_ns_list list; enum ns_type type; int rc; @@ -1113,11 +1113,11 @@ static void test_admin_id_alloc_ns_list(struct nvme_mi_ep *ep) type = NS_ALLOC; test_set_transport_callback(ep, test_admin_id_ns_list_cb, &type); - hdl = nvme_mi_init_transport_handle(ep, 5); + hdl = libnvme_mi_init_transport_handle(ep, 5); assert(hdl); nvme_init_identify_allocated_ns_list(&cmd, 1, &list); - rc = nvme_submit_admin_passthru(hdl, &cmd); + rc = libnvme_submit_admin_passthru(hdl, &cmd); assert(!rc); assert(le32_to_cpu(list.ns[0]) == 2); @@ -1125,10 +1125,10 @@ static void test_admin_id_alloc_ns_list(struct nvme_mi_ep *ep) assert(le32_to_cpu(list.ns[2]) == 0); } -static void test_admin_id_active_ns_list(struct nvme_mi_ep *ep) +static void test_admin_id_active_ns_list(struct libnvme_mi_ep *ep) { - struct nvme_transport_handle *hdl; - struct nvme_passthru_cmd cmd; + struct libnvme_transport_handle *hdl; + struct libnvme_passthru_cmd cmd; struct nvme_ns_list list; enum ns_type type; int rc; @@ -1136,11 +1136,11 @@ static void test_admin_id_active_ns_list(struct nvme_mi_ep *ep) type = NS_ACTIVE; test_set_transport_callback(ep, test_admin_id_ns_list_cb, &type); - hdl = nvme_mi_init_transport_handle(ep, 5); + hdl = libnvme_mi_init_transport_handle(ep, 5); assert(hdl); nvme_init_identify_active_ns_list(&cmd, 1, &list); - rc = nvme_submit_admin_passthru(hdl, &cmd); + rc = libnvme_submit_admin_passthru(hdl, &cmd); assert(!rc); assert(le32_to_cpu(list.ns[0]) == 4); @@ -1148,9 +1148,9 @@ static void test_admin_id_active_ns_list(struct nvme_mi_ep *ep) assert(le32_to_cpu(list.ns[2]) == 0); } -static int test_admin_id_ns_cb(struct nvme_mi_ep *ep, - struct nvme_mi_req *req, - struct nvme_mi_resp *resp, +static int test_admin_id_ns_cb(struct libnvme_mi_ep *ep, + struct libnvme_mi_req *req, + struct libnvme_mi_resp *resp, void *data) { struct nvme_id_ns *id; @@ -1190,10 +1190,10 @@ static int test_admin_id_ns_cb(struct nvme_mi_ep *ep, return 0; } -static void test_admin_id_alloc_ns(struct nvme_mi_ep *ep) +static void test_admin_id_alloc_ns(struct libnvme_mi_ep *ep) { - struct nvme_transport_handle *hdl; - struct nvme_passthru_cmd cmd; + struct libnvme_transport_handle *hdl; + struct libnvme_passthru_cmd cmd; struct nvme_id_ns id; enum ns_type type; int rc; @@ -1201,19 +1201,19 @@ static void test_admin_id_alloc_ns(struct nvme_mi_ep *ep) type = NS_ALLOC; test_set_transport_callback(ep, test_admin_id_ns_cb, &type); - hdl = nvme_mi_init_transport_handle(ep, 5); + hdl = libnvme_mi_init_transport_handle(ep, 5); assert(hdl); nvme_init_identify_allocated_ns(&cmd, 1, &id); - rc = nvme_submit_admin_passthru(hdl, &cmd); + rc = libnvme_submit_admin_passthru(hdl, &cmd); assert(!rc); assert(le64_to_cpu(id.nsze) == 1); } -static void test_admin_id_active_ns(struct nvme_mi_ep *ep) +static void test_admin_id_active_ns(struct libnvme_mi_ep *ep) { - struct nvme_transport_handle *hdl; - struct nvme_passthru_cmd cmd; + struct libnvme_transport_handle *hdl; + struct libnvme_passthru_cmd cmd; struct nvme_id_ns id; enum ns_type type; int rc; @@ -1221,18 +1221,18 @@ static void test_admin_id_active_ns(struct nvme_mi_ep *ep) type = NS_ACTIVE; test_set_transport_callback(ep, test_admin_id_ns_cb, &type); - hdl = nvme_mi_init_transport_handle(ep, 5); + hdl = libnvme_mi_init_transport_handle(ep, 5); assert(hdl); nvme_init_identify_ns(&cmd, 1, &id); - rc = nvme_submit_admin_passthru(hdl, &cmd); + rc = libnvme_submit_admin_passthru(hdl, &cmd); assert(!rc); assert(le64_to_cpu(id.nsze) == 1); } -static int test_admin_id_ns_ctrl_list_cb(struct nvme_mi_ep *ep, - struct nvme_mi_req *req, - struct nvme_mi_resp *resp, +static int test_admin_id_ns_ctrl_list_cb(struct libnvme_mi_ep *ep, + struct libnvme_mi_req *req, + struct libnvme_mi_resp *resp, void *data) { __u16 cns, ctrlid; @@ -1259,26 +1259,26 @@ static int test_admin_id_ns_ctrl_list_cb(struct nvme_mi_ep *ep, return 0; } -static void test_admin_id_ns_ctrl_list(struct nvme_mi_ep *ep) +static void test_admin_id_ns_ctrl_list(struct libnvme_mi_ep *ep) { - struct nvme_transport_handle *hdl; - struct nvme_passthru_cmd cmd; + struct libnvme_transport_handle *hdl; + struct libnvme_passthru_cmd cmd; struct nvme_ctrl_list list; int rc; test_set_transport_callback(ep, test_admin_id_ns_ctrl_list_cb, NULL); - hdl = nvme_mi_init_transport_handle(ep, 5); + hdl = libnvme_mi_init_transport_handle(ep, 5); assert(hdl); nvme_init_identify_ns_ctrl_list(&cmd, 0x01020304, 5, &list); - rc = nvme_submit_admin_passthru(hdl, &cmd); + rc = libnvme_submit_admin_passthru(hdl, &cmd); assert(!rc); } -static int test_admin_id_secondary_ctrl_list_cb(struct nvme_mi_ep *ep, - struct nvme_mi_req *req, - struct nvme_mi_resp *resp, +static int test_admin_id_secondary_ctrl_list_cb(struct libnvme_mi_ep *ep, + struct libnvme_mi_req *req, + struct libnvme_mi_resp *resp, void *data) { __u16 cns, ctrlid; @@ -1301,27 +1301,27 @@ static int test_admin_id_secondary_ctrl_list_cb(struct nvme_mi_ep *ep, return 0; } -static void test_admin_id_secondary_ctrl_list(struct nvme_mi_ep *ep) +static void test_admin_id_secondary_ctrl_list(struct libnvme_mi_ep *ep) { struct nvme_secondary_ctrl_list list; - struct nvme_transport_handle *hdl; - struct nvme_passthru_cmd cmd; + struct libnvme_transport_handle *hdl; + struct libnvme_passthru_cmd cmd; int rc; test_set_transport_callback(ep, test_admin_id_secondary_ctrl_list_cb, NULL); - hdl = nvme_mi_init_transport_handle(ep, 5); + hdl = libnvme_mi_init_transport_handle(ep, 5); assert(hdl); nvme_init_identify_secondary_ctrl_list(&cmd, 5, &list); - rc = nvme_submit_admin_passthru(hdl, &cmd); + rc = libnvme_submit_admin_passthru(hdl, &cmd); assert(!rc); } -static int test_admin_ns_mgmt_cb(struct nvme_mi_ep *ep, - struct nvme_mi_req *req, - struct nvme_mi_resp *resp, +static int test_admin_ns_mgmt_cb(struct libnvme_mi_ep *ep, + struct libnvme_mi_req *req, + struct libnvme_mi_resp *resp, void *data) { __u8 *rq_hdr, *rs_hdr, sel, csi; @@ -1374,44 +1374,44 @@ static int test_admin_ns_mgmt_cb(struct nvme_mi_ep *ep, return 0; } -static void test_admin_ns_mgmt_create(struct nvme_mi_ep *ep) +static void test_admin_ns_mgmt_create(struct libnvme_mi_ep *ep) { struct nvme_ns_mgmt_host_sw_specified data = { 0 }; - struct nvme_transport_handle *hdl; - struct nvme_passthru_cmd cmd; + struct libnvme_transport_handle *hdl; + struct libnvme_passthru_cmd cmd; __u64 ns; int rc; test_set_transport_callback(ep, test_admin_ns_mgmt_cb, NULL); - hdl = nvme_mi_init_transport_handle(ep, 5); + hdl = libnvme_mi_init_transport_handle(ep, 5); assert(hdl); nvme_init_ns_mgmt_create(&cmd, NVME_CSI_NVM, &data); - rc = nvme_submit_admin_passthru(hdl, &cmd); + rc = libnvme_submit_admin_passthru(hdl, &cmd); assert(!rc); ns = cmd.result; assert(ns == 0x01020304); data.nsze = cpu_to_le64(42); nvme_init_ns_mgmt_create(&cmd, NVME_CSI_NVM, &data); - rc = nvme_submit_admin_passthru(hdl, &cmd); + rc = libnvme_submit_admin_passthru(hdl, &cmd); assert(rc); } -static void test_admin_ns_mgmt_delete(struct nvme_mi_ep *ep) +static void test_admin_ns_mgmt_delete(struct libnvme_mi_ep *ep) { - struct nvme_transport_handle *hdl; - struct nvme_passthru_cmd cmd; + struct libnvme_transport_handle *hdl; + struct libnvme_passthru_cmd cmd; int rc; test_set_transport_callback(ep, test_admin_ns_mgmt_cb, NULL); - hdl = nvme_mi_init_transport_handle(ep, 5); + hdl = libnvme_mi_init_transport_handle(ep, 5); assert(hdl); nvme_init_ns_mgmt_delete(&cmd, 0x05060708); - rc = nvme_submit_admin_passthru(hdl, &cmd); + rc = libnvme_submit_admin_passthru(hdl, &cmd); assert(!rc); } @@ -1423,9 +1423,9 @@ struct attach_op { struct nvme_ctrl_list *list; }; -static int test_admin_ns_attach_cb(struct nvme_mi_ep *ep, - struct nvme_mi_req *req, - struct nvme_mi_resp *resp, +static int test_admin_ns_attach_cb(struct libnvme_mi_ep *ep, + struct libnvme_mi_req *req, + struct libnvme_mi_resp *resp, void *data) { struct attach_op *op = data; @@ -1459,12 +1459,12 @@ static int test_admin_ns_attach_cb(struct nvme_mi_ep *ep, return 0; } -static void test_admin_ns_attach(struct nvme_mi_ep *ep) +static void test_admin_ns_attach(struct libnvme_mi_ep *ep) { struct nvme_ctrl_list list = { 0 }; struct attach_op aop; - struct nvme_transport_handle *hdl; - struct nvme_passthru_cmd cmd; + struct libnvme_transport_handle *hdl; + struct libnvme_passthru_cmd cmd; int rc; list.num = cpu_to_le16(2); @@ -1476,20 +1476,20 @@ static void test_admin_ns_attach(struct nvme_mi_ep *ep) test_set_transport_callback(ep, test_admin_ns_attach_cb, &aop); - hdl = nvme_mi_init_transport_handle(ep, 5); + hdl = libnvme_mi_init_transport_handle(ep, 5); assert(hdl); nvme_init_ns_attach_ctrls(&cmd, 0x02030405, &list); - rc = nvme_submit_admin_passthru(hdl, &cmd); + rc = libnvme_submit_admin_passthru(hdl, &cmd); assert(!rc); } -static void test_admin_ns_detach(struct nvme_mi_ep *ep) +static void test_admin_ns_detach(struct libnvme_mi_ep *ep) { struct nvme_ctrl_list list = { 0 }; struct attach_op aop; - struct nvme_transport_handle *hdl; - struct nvme_passthru_cmd cmd; + struct libnvme_transport_handle *hdl; + struct libnvme_passthru_cmd cmd; int rc; list.num = cpu_to_le16(2); @@ -1501,11 +1501,11 @@ static void test_admin_ns_detach(struct nvme_mi_ep *ep) test_set_transport_callback(ep, test_admin_ns_attach_cb, &aop); - hdl = nvme_mi_init_transport_handle(ep, 5); + hdl = libnvme_mi_init_transport_handle(ep, 5); assert(hdl); nvme_init_ns_detach_ctrls(&cmd, 0x02030405, &list); - rc = nvme_submit_admin_passthru(hdl, &cmd); + rc = libnvme_submit_admin_passthru(hdl, &cmd); assert(!rc); } @@ -1515,9 +1515,9 @@ struct fw_download_info { void *data; }; -static int test_admin_fw_download_cb(struct nvme_mi_ep *ep, - struct nvme_mi_req *req, - struct nvme_mi_resp *resp, +static int test_admin_fw_download_cb(struct libnvme_mi_ep *ep, + struct libnvme_mi_req *req, + struct libnvme_mi_resp *resp, void *data) { struct fw_download_info *info = data; @@ -1543,12 +1543,12 @@ static int test_admin_fw_download_cb(struct nvme_mi_ep *ep, return 0; } -static void test_admin_fw_download(struct nvme_mi_ep *ep) +static void test_admin_fw_download(struct libnvme_mi_ep *ep) { struct fw_download_info info; unsigned char fw[4096]; - struct nvme_transport_handle *hdl; - struct nvme_passthru_cmd cmd; + struct libnvme_transport_handle *hdl; + struct libnvme_passthru_cmd cmd; int rc, i; for (i = 0; i < sizeof(fw); i++) @@ -1560,7 +1560,7 @@ static void test_admin_fw_download(struct nvme_mi_ep *ep) test_set_transport_callback(ep, test_admin_fw_download_cb, &info); - hdl = nvme_mi_init_transport_handle(ep, 5); + hdl = libnvme_mi_init_transport_handle(ep, 5); assert(hdl); /* invalid (zero) len */ @@ -1586,7 +1586,7 @@ static void test_admin_fw_download(struct nvme_mi_ep *ep) info.offset = 0; rc = nvme_init_fw_download(&cmd, fw, info.len, info.offset); assert(!rc); - rc = nvme_submit_admin_passthru(hdl, &cmd); + rc = libnvme_submit_admin_passthru(hdl, &cmd); assert(!rc); /* largest len */ @@ -1594,7 +1594,7 @@ static void test_admin_fw_download(struct nvme_mi_ep *ep) info.offset = 0; rc = nvme_init_fw_download(&cmd, fw, info.len, info.offset); assert(!rc); - rc = nvme_submit_admin_passthru(hdl, &cmd); + rc = libnvme_submit_admin_passthru(hdl, &cmd); assert(!rc); /* offset value */ @@ -1602,7 +1602,7 @@ static void test_admin_fw_download(struct nvme_mi_ep *ep) info.offset = 4096; rc = nvme_init_fw_download(&cmd, fw, info.len, info.offset); assert(!rc); - rc = nvme_submit_admin_passthru(hdl, &cmd); + rc = libnvme_submit_admin_passthru(hdl, &cmd); assert(!rc); } @@ -1612,9 +1612,9 @@ struct fw_commit_info { __u8 slot; }; -static int test_admin_fw_commit_cb(struct nvme_mi_ep *ep, - struct nvme_mi_req *req, - struct nvme_mi_resp *resp, +static int test_admin_fw_commit_cb(struct libnvme_mi_ep *ep, + struct libnvme_mi_req *req, + struct libnvme_mi_resp *resp, void *data) { struct fw_commit_info *info = data; @@ -1637,10 +1637,10 @@ static int test_admin_fw_commit_cb(struct nvme_mi_ep *ep, return 0; } -static void test_admin_fw_commit(struct nvme_mi_ep *ep) +static void test_admin_fw_commit(struct libnvme_mi_ep *ep) { - struct nvme_transport_handle *hdl; - struct nvme_passthru_cmd cmd; + struct libnvme_transport_handle *hdl; + struct libnvme_passthru_cmd cmd; struct fw_commit_info info; int rc; @@ -1648,7 +1648,7 @@ static void test_admin_fw_commit(struct nvme_mi_ep *ep) test_set_transport_callback(ep, test_admin_fw_commit_cb, &info); - hdl = nvme_mi_init_transport_handle(ep, 5); + hdl = libnvme_mi_init_transport_handle(ep, 5); assert(hdl); /* all zeros */ @@ -1656,7 +1656,7 @@ static void test_admin_fw_commit(struct nvme_mi_ep *ep) info.slot = 0; info.action = 0; nvme_init_fw_commit(&cmd, info.slot, info.action, info.bpid); - rc = nvme_submit_admin_passthru(hdl, &cmd); + rc = libnvme_submit_admin_passthru(hdl, &cmd); assert(!rc); /* all ones */ @@ -1664,7 +1664,7 @@ static void test_admin_fw_commit(struct nvme_mi_ep *ep) info.slot = 0x7; info.action = 0x7; nvme_init_fw_commit(&cmd, info.slot, info.action, info.bpid); - rc = nvme_submit_admin_passthru(hdl, &cmd); + rc = libnvme_submit_admin_passthru(hdl, &cmd); assert(!rc); /* correct fields */ @@ -1672,7 +1672,7 @@ static void test_admin_fw_commit(struct nvme_mi_ep *ep) info.slot = 2; info.action = 3; nvme_init_fw_commit(&cmd, info.slot, info.action, info.bpid); - rc = nvme_submit_admin_passthru(hdl, &cmd); + rc = libnvme_submit_admin_passthru(hdl, &cmd); assert(!rc); } @@ -1685,9 +1685,9 @@ struct format_data { __u8 lbaf; }; -static int test_admin_format_nvm_cb(struct nvme_mi_ep *ep, - struct nvme_mi_req *req, - struct nvme_mi_resp *resp, +static int test_admin_format_nvm_cb(struct libnvme_mi_ep *ep, + struct libnvme_mi_req *req, + struct libnvme_mi_resp *resp, void *data) { struct format_data *args = data; @@ -1719,14 +1719,14 @@ static int test_admin_format_nvm_cb(struct nvme_mi_ep *ep, return 0; } -static void test_admin_format_nvm(struct nvme_mi_ep *ep) +static void test_admin_format_nvm(struct libnvme_mi_ep *ep) { struct format_data args = { 0 }; - struct nvme_transport_handle *hdl; - struct nvme_passthru_cmd cmd; + struct libnvme_transport_handle *hdl; + struct libnvme_passthru_cmd cmd; int rc; - hdl = nvme_mi_init_transport_handle(ep, 5); + hdl = libnvme_mi_init_transport_handle(ep, 5); assert(hdl); test_set_transport_callback(ep, test_admin_format_nvm_cb, &args); @@ -1742,7 +1742,7 @@ static void test_admin_format_nvm(struct nvme_mi_ep *ep) nvme_init_format_nvm(&cmd, args.nsid, args.lbaf, args.mset, args.pi, args.pil, args.ses); - rc = nvme_submit_admin_passthru(hdl, &cmd); + rc = libnvme_submit_admin_passthru(hdl, &cmd); assert(!rc); args.nsid = ~args.nsid; @@ -1754,7 +1754,7 @@ static void test_admin_format_nvm(struct nvme_mi_ep *ep) nvme_init_format_nvm(&cmd, args.nsid, args.lbaf, args.mset, args.pi, args.pil, args.ses); - rc = nvme_submit_admin_passthru(hdl, &cmd); + rc = libnvme_submit_admin_passthru(hdl, &cmd); assert(!rc); } @@ -1768,9 +1768,9 @@ struct nvme_sanitize_nvm_args { bool emvs; }; -static int test_admin_sanitize_nvm_cb(struct nvme_mi_ep *ep, - struct nvme_mi_req *req, - struct nvme_mi_resp *resp, +static int test_admin_sanitize_nvm_cb(struct libnvme_mi_ep *ep, + struct libnvme_mi_req *req, + struct libnvme_mi_resp *resp, void *data) { struct nvme_sanitize_nvm_args *args = data; @@ -1799,14 +1799,14 @@ static int test_admin_sanitize_nvm_cb(struct nvme_mi_ep *ep, return 0; } -static void test_admin_sanitize_nvm(struct nvme_mi_ep *ep) +static void test_admin_sanitize_nvm(struct libnvme_mi_ep *ep) { struct nvme_sanitize_nvm_args args = { 0 }; - struct nvme_transport_handle *hdl; - struct nvme_passthru_cmd cmd; + struct libnvme_transport_handle *hdl; + struct libnvme_passthru_cmd cmd; int rc; - hdl = nvme_mi_init_transport_handle(ep, 5); + hdl = libnvme_mi_init_transport_handle(ep, 5); assert(hdl); test_set_transport_callback(ep, test_admin_sanitize_nvm_cb, &args); @@ -1820,7 +1820,7 @@ static void test_admin_sanitize_nvm(struct nvme_mi_ep *ep) nvme_init_sanitize_nvm(&cmd, args.sanact, args.ause, args.owpass, args.oipbp, args.ndas, args.emvs, args.ovrpat); - rc = nvme_submit_admin_passthru(hdl, &cmd); + rc = libnvme_submit_admin_passthru(hdl, &cmd); assert(!rc); args.sanact = 0x0; @@ -1832,7 +1832,7 @@ static void test_admin_sanitize_nvm(struct nvme_mi_ep *ep) nvme_init_sanitize_nvm(&cmd, args.sanact, args.ause, args.owpass, args.oipbp, args.ndas, args.emvs, args.ovrpat); - rc = nvme_submit_admin_passthru(hdl, &cmd); + rc = libnvme_submit_admin_passthru(hdl, &cmd); assert(!rc); } @@ -1842,9 +1842,9 @@ struct log_data { int n; }; -static int test_admin_get_log_split_cb(struct nvme_mi_ep *ep, - struct nvme_mi_req *req, - struct nvme_mi_resp *resp, +static int test_admin_get_log_split_cb(struct libnvme_mi_ep *ep, + struct libnvme_mi_req *req, + struct libnvme_mi_resp *resp, void *data) { uint32_t log_page_offset_lower; @@ -1897,39 +1897,39 @@ static int test_admin_get_log_split_cb(struct nvme_mi_ep *ep, return 0; } -static void test_admin_get_log_split(struct nvme_mi_ep *ep) +static void test_admin_get_log_split(struct libnvme_mi_ep *ep) { unsigned char buf[4096 * 2 + 4]; struct log_data ldata; - struct nvme_transport_handle *hdl; - struct nvme_passthru_cmd cmd; + struct libnvme_transport_handle *hdl; + struct libnvme_passthru_cmd cmd; int rc; ldata.n = 0; test_set_transport_callback(ep, test_admin_get_log_split_cb, &ldata); - hdl = nvme_mi_init_transport_handle(ep, 5); + hdl = libnvme_mi_init_transport_handle(ep, 5); nvme_init_get_log(&cmd, NVME_NSID_ALL, NVME_LOG_LID_ERROR, NVME_CSI_NVM, buf, sizeof(buf)); - rc = nvme_get_log(hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); + rc = libnvme_get_log(hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); assert(!rc); /* we should have sent three commands */ assert(ldata.n == 3); } -static int test_endpoint_quirk_probe_cb_stage2(struct nvme_mi_ep *ep, - struct nvme_mi_req *req, - struct nvme_mi_resp *resp, +static int test_endpoint_quirk_probe_cb_stage2(struct libnvme_mi_ep *ep, + struct libnvme_mi_req *req, + struct libnvme_mi_resp *resp, void *data) { return test_read_mi_data_cb(ep, req, resp, data); } -static int test_endpoint_quirk_probe_cb_stage1(struct nvme_mi_ep *ep, - struct nvme_mi_req *req, - struct nvme_mi_resp *resp, +static int test_endpoint_quirk_probe_cb_stage1(struct libnvme_mi_ep *ep, + struct libnvme_mi_req *req, + struct libnvme_mi_resp *resp, void *data) { struct nvme_mi_admin_req_hdr *admin_req; @@ -1954,7 +1954,7 @@ static int test_endpoint_quirk_probe_cb_stage1(struct nvme_mi_ep *ep, return 0; } -static void test_endpoint_quirk_probe(struct nvme_mi_ep *ep) +static void test_endpoint_quirk_probe(struct libnvme_mi_ep *ep) { struct nvme_mi_read_nvm_ss_info ss_info; int rc; @@ -1964,7 +1964,7 @@ static void test_endpoint_quirk_probe(struct nvme_mi_ep *ep) test_set_transport_callback(ep, test_endpoint_quirk_probe_cb_stage1, NULL); - rc = nvme_mi_mi_read_mi_data_subsys(ep, &ss_info); + rc = libnvme_mi_mi_read_mi_data_subsys(ep, &ss_info); assert(rc == 0); } @@ -1978,9 +1978,9 @@ struct req_dlen_doff_data { unsigned int exp_doff; }; -static int test_admin_dlen_doff_cb(struct nvme_mi_ep *ep, - struct nvme_mi_req *req, - struct nvme_mi_resp *resp, +static int test_admin_dlen_doff_cb(struct libnvme_mi_ep *ep, + struct libnvme_mi_req *req, + struct libnvme_mi_resp *resp, void *data) { struct req_dlen_doff_data *args = data; @@ -2010,7 +2010,7 @@ static int test_admin_dlen_doff_cb(struct nvme_mi_ep *ep, } /* Check dlen value on admin_xfer requests that include data. */ -static void test_admin_dlen_doff_req(struct nvme_mi_ep *ep) +static void test_admin_dlen_doff_req(struct libnvme_mi_ep *ep) { struct { struct nvme_mi_admin_req_hdr hdr; @@ -2019,7 +2019,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; - struct nvme_transport_handle *hdl; + struct libnvme_transport_handle *hdl; int rc; data.direction = DATA_DIR_OUT; @@ -2027,10 +2027,10 @@ static void test_admin_dlen_doff_req(struct nvme_mi_ep *ep) test_set_transport_callback(ep, test_admin_dlen_doff_cb, &data); - hdl = nvme_mi_init_transport_handle(ep, 0); + hdl = libnvme_mi_init_transport_handle(ep, 0); assert(hdl); - rc = nvme_mi_admin_xfer(hdl, &admin_req.hdr, sizeof(admin_req.data), + rc = libnvme_mi_admin_xfer(hdl, &admin_req.hdr, sizeof(admin_req.data), &admin_resp, 0, &resp_sz); assert(!rc); @@ -2038,7 +2038,7 @@ static void test_admin_dlen_doff_req(struct nvme_mi_ep *ep) /* Check dlen value on admin_xfer requests that return data in their response. */ -static void test_admin_dlen_doff_resp(struct nvme_mi_ep *ep) +static void test_admin_dlen_doff_resp(struct libnvme_mi_ep *ep) { struct { struct nvme_mi_admin_resp_hdr hdr; @@ -2046,7 +2046,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 }; - struct nvme_transport_handle *hdl; + struct libnvme_transport_handle *hdl; size_t resp_sz; int rc; @@ -2056,10 +2056,10 @@ static void test_admin_dlen_doff_resp(struct nvme_mi_ep *ep) test_set_transport_callback(ep, test_admin_dlen_doff_cb, &data); - hdl = nvme_mi_init_transport_handle(ep, 0); + hdl = libnvme_mi_init_transport_handle(ep, 0); assert(hdl); - rc = nvme_mi_admin_xfer(hdl, &admin_req, 0, &admin_resp.hdr, 0, + rc = libnvme_mi_admin_xfer(hdl, &admin_req, 0, &admin_resp.hdr, 0, &resp_sz); assert(!rc); @@ -2068,7 +2068,7 @@ static void test_admin_dlen_doff_resp(struct nvme_mi_ep *ep) #define DEFINE_TEST(name) { #name, test_ ## name } struct test { const char *name; - void (*fn)(nvme_mi_ep_t); + void (*fn)(libnvme_mi_ep_t); } tests[] = { DEFINE_TEST(endpoint_lifetime), DEFINE_TEST(ctrl_lifetime), @@ -2112,7 +2112,7 @@ struct test { DEFINE_TEST(mi_invalid_formats), }; -static void run_test(struct test *test, FILE *logfd, nvme_mi_ep_t ep) +static void run_test(struct test *test, FILE *logfd, libnvme_mi_ep_t ep) { printf("Running test %s...", test->name); fflush(stdout); @@ -2124,25 +2124,25 @@ static void run_test(struct test *test, FILE *logfd, nvme_mi_ep_t ep) int main(void) { - struct nvme_global_ctx *ctx; - nvme_mi_ep_t ep; + struct libnvme_global_ctx *ctx; + libnvme_mi_ep_t ep; unsigned int i; FILE *fd; fd = test_setup_log(); - ctx = nvme_create_global_ctx(fd, DEFAULT_LOGLEVEL); + ctx = libnvme_create_global_ctx(fd, DEFAULT_LOGLEVEL); assert(ctx); - ep = nvme_mi_open_test(ctx); + ep = libnvme_mi_open_test(ctx); assert(ep); for (i = 0; i < ARRAY_SIZE(tests); i++) { run_test(&tests[i], fd, ep); } - nvme_mi_close(ep); - nvme_free_global_ctx(ctx); + libnvme_mi_close(ep); + libnvme_free_global_ctx(ctx); test_close_log(fd); diff --git a/libnvme/test/nbft/nbft-dump.c b/libnvme/test/nbft/nbft-dump.c index 2b14bf5869..73040adb76 100644 --- a/libnvme/test/nbft/nbft-dump.c +++ b/libnvme/test/nbft/nbft-dump.c @@ -105,29 +105,29 @@ static void print_nbft(struct nbft_info *table) int main(int argc, char **argv) { struct nbft_info *table = NULL; - struct nvme_global_ctx *ctx; + struct libnvme_global_ctx *ctx; if (argc < 2) { fprintf(stderr, "Usage: %s TABLE\n", argv[0]); return 1; } - ctx = nvme_create_global_ctx(stderr, false); + ctx = libnvme_create_global_ctx(stderr, false); if (!ctx) { fprintf(stderr, "Failed to create global context"); return 1; } - if (nvme_read_nbft(ctx, &table, argv[1]) != 0) { + if (libnvme_read_nbft(ctx, &table, argv[1]) != 0) { fprintf(stderr, "Error parsing the NBFT table %s: %m\n", argv[1]); - nvme_free_global_ctx(ctx); + libnvme_free_global_ctx(ctx); return 2; } print_nbft(table); - nvme_free_nbft(ctx, table); - nvme_free_global_ctx(ctx); + libnvme_free_nbft(ctx, table); + libnvme_free_global_ctx(ctx); return 0; } diff --git a/libnvme/test/psk.c b/libnvme/test/psk.c index 7dd810f38a..4b1def3916 100644 --- a/libnvme/test/psk.c +++ b/libnvme/test/psk.c @@ -31,7 +31,7 @@ static struct test_data_psk test_data_psk[] = { 0xF4, 0x42, 0xE2, 0xDD, 0x6D, 0x8B, 0xC4, 0x87, 0x0B, 0x5D, 0x5B, 0x03}, - 32, 1, NVME_HMAC_ALG_NONE, + 32, 1, LIBNVME_HMAC_ALG_NONE, "NVMeTLSkey-1:00:VRLbtnN9AQb2WXW3c9+wEf/DRLz0QuLdbYvEhwtdWwNf9LrZ:" }, { { 0x55, 0x12, 0xDB, 0xB6, 0x73, 0x7D, 0x01, 0x06, @@ -41,7 +41,7 @@ static struct test_data_psk test_data_psk[] = { 0xF4, 0x42, 0xE2, 0xDD, 0x6D, 0x8B, 0xC4, 0x87, 0x0B, 0x5D, 0x5B, 0x03}, - 32, 1, NVME_HMAC_ALG_SHA2_256, + 32, 1, LIBNVME_HMAC_ALG_SHA2_256, "NVMeTLSkey-1:01:VRLbtnN9AQb2WXW3c9+wEf/DRLz0QuLdbYvEhwtdWwNf9LrZ:" }, { { 0x55, 0x12, 0xDB, 0xB6, 0x73, 0x7D, 0x01, 0x06, @@ -55,7 +55,7 @@ static struct test_data_psk test_data_psk[] = { 0xF4, 0x42, 0xE2, 0xDD, 0x6D, 0x8B, 0xC4, 0x87, 0x0B, 0x5D, 0x5B, 0x03}, - 48, 1, NVME_HMAC_ALG_SHA2_384, + 48, 1, LIBNVME_HMAC_ALG_SHA2_384, "NVMeTLSkey-1:02:VRLbtnN9AQb2WXW3c9+wEf/DRLz0QuLdbYvEhwtdWwP/w0S89ELi3W2LxIcLXVsDn8kXZQ==:" }, }; @@ -78,7 +78,7 @@ static struct test_data_identity test_data_identity[] = { 0xF4, 0x42, 0xE2, 0xDD, 0x6D, 0x8B, 0xC4, 0x87, 0x0B, 0x5D, 0x5B, 0x03}, - 32, 1, NVME_HMAC_ALG_SHA2_256, + 32, 1, LIBNVME_HMAC_ALG_SHA2_256, "nqn.psk-test-host", "nqn.psk-test-subsys", "NVMe1R01 nqn.psk-test-host nqn.psk-test-subsys iSbjiStwJ/1TrTvDlt2fjFmzvsytOJelidNnA+X5lEU=" }, { { 0x55, 0x12, 0xDB, 0xB6, @@ -93,7 +93,7 @@ static struct test_data_identity test_data_identity[] = { 0xF4, 0x42, 0xE2, 0xDD, 0x6D, 0x8B, 0xC4, 0x87, 0x0B, 0x5D, 0x5B, 0x03}, - 48, 1, NVME_HMAC_ALG_SHA2_384, + 48, 1, LIBNVME_HMAC_ALG_SHA2_384, "nqn.psk-test-host", "nqn.psk-test-subsys", "NVMe1R02 nqn.psk-test-host nqn.psk-test-subsys QhW2+Rp6RzHlNtCslyRxMnwJ11tKKhz8JCAQpQ+XUD8f9td1VeH5h53yz2wKJG1a" }, }; @@ -107,7 +107,7 @@ static struct test_data_identity test_data_identity_compat[] = { 0xF4, 0x42, 0xE2, 0xDD, 0x6D, 0x8B, 0xC4, 0x87, 0x0B, 0x5D, 0x5B, 0x03}, - 32, 1, NVME_HMAC_ALG_SHA2_256, + 32, 1, LIBNVME_HMAC_ALG_SHA2_256, "nqn.psk-test-host", "nqn.psk-test-subsys", "NVMe1R01 nqn.psk-test-host nqn.psk-test-subsys 66GuqV08TsAGII39teWUfwQwizjv06Jy8jOcX3NAAzM=" }, { { 0x55, 0x12, 0xDB, 0xB6, @@ -122,7 +122,7 @@ static struct test_data_identity test_data_identity_compat[] = { 0xF4, 0x42, 0xE2, 0xDD, 0x6D, 0x8B, 0xC4, 0x87, 0x0B, 0x5D, 0x5B, 0x03}, - 48, 1, NVME_HMAC_ALG_SHA2_384, + 48, 1, LIBNVME_HMAC_ALG_SHA2_384, "nqn.psk-test-host", "nqn.psk-test-subsys", "NVMe1R02 nqn.psk-test-host nqn.psk-test-subsys RsKmYJ3nAn1ApjjMloJFbAkLPivONDAX/xW327YBUsn2eGShXSjCZvBaOxscLqmz" }, }; @@ -137,32 +137,32 @@ static void check_str(const char *exp, const char *res) test_rc = 1; } -static void export_test(struct nvme_global_ctx *ctx, +static void export_test(struct libnvme_global_ctx *ctx, struct test_data_psk *test) { char *psk; int ret; if (test->version != 1 || - !(test->hmac == NVME_HMAC_ALG_SHA2_256 || - test->hmac == NVME_HMAC_ALG_SHA2_384)) + !(test->hmac == LIBNVME_HMAC_ALG_SHA2_256 || + test->hmac == LIBNVME_HMAC_ALG_SHA2_384)) return; - printf("test nvme_export_tls_key hmac %d %s\n", + printf("test libnvme_export_tls_key hmac %d %s\n", test->hmac, test->exported_psk); - ret = nvme_export_tls_key(ctx, test->configured_psk, + ret = libnvme_export_tls_key(ctx, test->configured_psk, test->psk_length, &psk); if (ret) { test_rc = 1; - printf("ERROR: nvme_export_tls_key() failed with %d\n", ret); + printf("ERROR: libnvme_export_tls_key() failed with %d\n", ret); return; } check_str(test->exported_psk, psk); free(psk); } -static void import_test(struct nvme_global_ctx *ctx, +static void import_test(struct libnvme_global_ctx *ctx, struct test_data_psk *test) { unsigned char *psk; @@ -171,18 +171,18 @@ static void import_test(struct nvme_global_ctx *ctx, int ret; if (test->version != 1 || - !(test->hmac == NVME_HMAC_ALG_SHA2_256 || - test->hmac == NVME_HMAC_ALG_SHA2_384)) + !(test->hmac == LIBNVME_HMAC_ALG_SHA2_256 || + test->hmac == LIBNVME_HMAC_ALG_SHA2_384)) return; - printf("test nvme_import_tls_key hmac %d %s\n", + printf("test libnvme_import_tls_key hmac %d %s\n", test->hmac, test->exported_psk); - ret = nvme_import_tls_key(ctx, test->exported_psk, &psk_length, + ret = libnvme_import_tls_key(ctx, test->exported_psk, &psk_length, &hmac, &psk); if (ret) { test_rc = 1; - printf("ERROR: nvme_import_tls_key() failed with %d\n", ret); + printf("ERROR: libnvme_import_tls_key() failed with %d\n", ret); return; } @@ -206,7 +206,7 @@ static void import_test(struct nvme_global_ctx *ctx, free(psk); } -static void export_versioned_test(struct nvme_global_ctx *ctx, +static void export_versioned_test(struct libnvme_global_ctx *ctx, struct test_data_psk *test) { char *psk; @@ -215,15 +215,15 @@ static void export_versioned_test(struct nvme_global_ctx *ctx, if (test->version != 1) return; - printf("test nvme_export_tls_key_versioned hmac %d %s\n", + printf("test libnvme_export_tls_key_versioned hmac %d %s\n", test->hmac, test->exported_psk); - ret = nvme_export_tls_key_versioned(ctx, test->version, test->hmac, + ret = libnvme_export_tls_key_versioned(ctx, test->version, test->hmac, test->configured_psk, test->psk_length, &psk); if (ret) { test_rc = 1; - printf("ERROR: nvme_export_tls_key_versioned() failed with %d\n", + printf("ERROR: libnvme_export_tls_key_versioned() failed with %d\n", ret); return; } @@ -233,7 +233,7 @@ static void export_versioned_test(struct nvme_global_ctx *ctx, free(psk); } -static void import_versioned_test(struct nvme_global_ctx *ctx, +static void import_versioned_test(struct libnvme_global_ctx *ctx, struct test_data_psk *test) { unsigned char *psk; @@ -245,14 +245,14 @@ static void import_versioned_test(struct nvme_global_ctx *ctx, if (test->version != 1) return; - printf("test nvme_import_tls_key_versioned hmac %d %s\n", + printf("test libnvme_import_tls_key_versioned hmac %d %s\n", test->hmac, test->exported_psk); - ret = nvme_import_tls_key_versioned(ctx, test->exported_psk, &version, + ret = libnvme_import_tls_key_versioned(ctx, test->exported_psk, &version, &hmac, &psk_length, &psk); if (ret) { test_rc = 1; - printf("ERROR: nvme_import_tls_key_versioned() failed with %d\n", + printf("ERROR: libnvme_import_tls_key_versioned() failed with %d\n", ret); return; } @@ -284,21 +284,21 @@ static void import_versioned_test(struct nvme_global_ctx *ctx, free(psk); } -static void identity_test(struct nvme_global_ctx *ctx, +static void identity_test(struct libnvme_global_ctx *ctx, struct test_data_identity *test) { char *id; int ret; if (test->version != 1 || - !(test->hmac == NVME_HMAC_ALG_SHA2_256 || - test->hmac == NVME_HMAC_ALG_SHA2_384)) + !(test->hmac == LIBNVME_HMAC_ALG_SHA2_256 || + test->hmac == LIBNVME_HMAC_ALG_SHA2_384)) return; - printf("test nvme_generate_tls_key_identity host %s subsys %s hmac %d %s\n", + printf("test libnvme_generate_tls_key_identity host %s subsys %s hmac %d %s\n", test->hostnqn, test->subsysnqn, test->hmac, test->identity); - ret = nvme_generate_tls_key_identity(ctx, test->hostnqn, + ret = libnvme_generate_tls_key_identity(ctx, test->hostnqn, test->subsysnqn, test->version, test->hmac, (unsigned char *)test->configured_psk, test->psk_length, &id); @@ -306,28 +306,28 @@ static void identity_test(struct nvme_global_ctx *ctx, if (ret == -ENOTSUP) return; test_rc = 1; - printf("ERROR: nvme_generate_tls_key_identity() failed with %d\n", ret); + printf("ERROR: libnvme_generate_tls_key_identity() failed with %d\n", ret); return; } check_str(test->identity, id); free(id); } -static void identity_test_compat(struct nvme_global_ctx *ctx, +static void identity_test_compat(struct libnvme_global_ctx *ctx, struct test_data_identity *test) { char *id; int ret; if (test->version != 1 || - !(test->hmac == NVME_HMAC_ALG_SHA2_256 || - test->hmac == NVME_HMAC_ALG_SHA2_384)) + !(test->hmac == LIBNVME_HMAC_ALG_SHA2_256 || + test->hmac == LIBNVME_HMAC_ALG_SHA2_384)) return; - printf("test nvme_generate_tls_key_identity_compat host %s subsys %s hmac %d %s\n", + printf("test libnvme_generate_tls_key_identity_compat host %s subsys %s hmac %d %s\n", test->hostnqn, test->subsysnqn, test->hmac, test->identity); - ret = nvme_generate_tls_key_identity_compat(ctx, test->hostnqn, + ret = libnvme_generate_tls_key_identity_compat(ctx, test->hostnqn, test->subsysnqn, test->version, test->hmac, (unsigned char *)test->configured_psk, test->psk_length, &id); @@ -335,7 +335,7 @@ static void identity_test_compat(struct nvme_global_ctx *ctx, if (ret == -ENOTSUP) return; test_rc = 1; - printf("ERROR: nvme_generate_tls_key_identity_compat() failed with %d\n", ret); + printf("ERROR: libnvme_generate_tls_key_identity_compat() failed with %d\n", ret); return; } check_str(test->identity, id); @@ -344,8 +344,8 @@ static void identity_test_compat(struct nvme_global_ctx *ctx, int main(void) { - struct nvme_global_ctx *ctx = - nvme_create_global_ctx(stdout, DEFAULT_LOGLEVEL); + struct libnvme_global_ctx *ctx = + libnvme_create_global_ctx(stdout, DEFAULT_LOGLEVEL); for (int i = 0; i < ARRAY_SIZE(test_data_psk); i++) export_test(ctx, &test_data_psk[i]); @@ -365,7 +365,7 @@ int main(void) for (int i = 0; i < ARRAY_SIZE(test_data_identity_compat); i++) identity_test_compat(ctx, &test_data_identity_compat[i]); - nvme_free_global_ctx(ctx); + libnvme_free_global_ctx(ctx); return test_rc ? EXIT_FAILURE : EXIT_SUCCESS; } diff --git a/libnvme/test/sysfs/tree-dump.c b/libnvme/test/sysfs/tree-dump.c index a6c9831323..607c00beca 100644 --- a/libnvme/test/sysfs/tree-dump.c +++ b/libnvme/test/sysfs/tree-dump.c @@ -13,28 +13,28 @@ static bool tree_dump(void) { - struct nvme_global_ctx *ctx; + struct libnvme_global_ctx *ctx; bool pass = false; int err; - ctx = nvme_create_global_ctx(stdout, LOG_ERR); + ctx = libnvme_create_global_ctx(stdout, LOG_ERR); if (!ctx) return false; - err = nvme_scan_topology(ctx, NULL, NULL); + err = libnvme_scan_topology(ctx, NULL, NULL); if (err && !(err == ENOENT || err == EACCES)) { - fprintf(stderr, "nvme_scan_topology failed %d\n", err); + fprintf(stderr, "libnvme_scan_topology failed %d\n", err); goto out; } - if (nvme_dump_tree(ctx)) + if (libnvme_dump_tree(ctx)) goto out; printf("\n"); pass = true; out: - nvme_free_global_ctx(ctx); + libnvme_free_global_ctx(ctx); return pass; } diff --git a/libnvme/test/test-util.c b/libnvme/test/test-util.c index 997d72d13e..2f4e67bd07 100644 --- a/libnvme/test/test-util.c +++ b/libnvme/test/test-util.c @@ -27,9 +27,9 @@ static size_t safe_strlen(const char *p) { return p ? strlen(p) : strlen("null"); } -static bool test_nvme_get_version(enum nvme_version type, const char * exp_str) { +static bool test_nvme_get_version(enum libnvme_version type, const char * exp_str) { const char * str; - str = nvme_get_version(type); + str = libnvme_get_version(type); return !strcmp(str, exp_str); } @@ -70,7 +70,7 @@ static bool test_ipaddrs_eq() { } for (i = 0; i < n; i++) { - bool result = nvme_ipaddrs_eq(addrs[i].a, addrs[i].b); + bool result = libnvme_ipaddrs_eq(addrs[i].a, addrs[i].b); bool pass = result == addrs[i].exp_result; int pad_a = longest_a - safe_strlen(addrs[i].a); int pad_b = longest_b - safe_strlen(addrs[i].b); @@ -146,26 +146,26 @@ int main(int argc, char *argv[]) { bool pass; printf("\n------------------------------------------------------------------------------\n"); - pass = test_nvme_get_version(NVME_VERSION_PROJECT, LIBNVME_VERSION); - printf("nvme_get_version(NVME_VERSION_PROJECT) %s\n", pass ? "[PASS]" : "[FAIL]"); + pass = test_nvme_get_version(LIBNVME_VERSION_PROJECT, LIBNVME_VERSION); + printf("libnvme_get_version(LIBNVME_VERSION_PROJECT) %s\n", pass ? "[PASS]" : "[FAIL]"); if (!pass) exit_val = EXIT_FAILURE; printf("\n------------------------------------------------------------------------------\n"); - pass = test_nvme_get_version(NVME_VERSION_GIT, GIT_VERSION); - printf("nvme_get_version(NVME_VERSION_GIT) %s\n", pass ? "[PASS]" : "[FAIL]"); + pass = test_nvme_get_version(LIBNVME_VERSION_GIT, GIT_VERSION); + printf("libnvme_get_version(LIBNVME_VERSION_GIT) %s\n", pass ? "[PASS]" : "[FAIL]"); if (!pass) exit_val = EXIT_FAILURE; printf("\n------------------------------------------------------------------------------\n"); pass = test_nvme_get_version(-1, "n/a"); - printf("nvme_get_version(-1) %s\n", pass ? "[PASS]" : "[FAIL]"); + printf("libnvme_get_version(-1) %s\n", pass ? "[PASS]" : "[FAIL]"); if (!pass) exit_val = EXIT_FAILURE; printf("\n------------------------------------------------------------------------------\n"); pass = test_ipaddrs_eq(); - printf("nvme_ipaddrs_eq() %s", pass ? "[PASS]" : "[FAIL]"); + printf("libnvme_ipaddrs_eq() %s", pass ? "[PASS]" : "[FAIL]"); if (!pass) exit_val = EXIT_FAILURE; diff --git a/libnvme/test/test.c b/libnvme/test/test.c index cefa97d360..4e3a865800 100644 --- a/libnvme/test/test.c +++ b/libnvme/test/test.c @@ -27,23 +27,23 @@ #include "nvme/private.h" -static bool nvme_match_subsysnqn_filter(nvme_subsystem_t s, - nvme_ctrl_t c, nvme_ns_t ns, void *f_args) +static bool nvme_match_subsysnqn_filter(libnvme_subsystem_t s, + libnvme_ctrl_t c, libnvme_ns_t ns, void *f_args) { char *nqn_match = f_args; if (s) - return strcmp(nvme_subsystem_get_subsysnqn(s), nqn_match) == 0; + return strcmp(libnvme_subsystem_get_subsysnqn(s), nqn_match) == 0; return true; } -static int test_ctrl(nvme_ctrl_t c) +static int test_ctrl(libnvme_ctrl_t c) { static __u8 buf[0x1000]; enum nvme_get_features_sel sel = NVME_GET_FEATURES_SEL_CURRENT; - struct nvme_transport_handle *hdl = nvme_ctrl_get_transport_handle(c); - struct nvme_passthru_cmd cmd; + struct libnvme_transport_handle *hdl = libnvme_ctrl_get_transport_handle(c); + struct libnvme_passthru_cmd cmd; int ret, temp; struct nvme_error_log_page error[64]; struct nvme_smart_log smart = { 0 }; @@ -64,9 +64,9 @@ static int test_ctrl(nvme_ctrl_t c) struct nvme_id_ctrl id = { 0 }; nvme_init_identify_ctrl(&cmd, &id); - ret = nvme_submit_admin_passthru(hdl, &cmd); + ret = libnvme_submit_admin_passthru(hdl, &cmd); if (ret) { - printf("ERROR: no identify for:%s\n", nvme_ctrl_get_name(c)); + printf("ERROR: no identify for:%s\n", libnvme_ctrl_get_name(c)); return ret; } else { @@ -74,9 +74,9 @@ static int test_ctrl(nvme_ctrl_t c) } nvme_init_get_log_smart(&cmd, NVME_NSID_ALL, &smart); - ret = nvme_get_log(hdl, &cmd, true, NVME_LOG_PAGE_PDU_SIZE); + ret = libnvme_get_log(hdl, &cmd, true, NVME_LOG_PAGE_PDU_SIZE); if (ret) { - printf("ERROR: no smart log for:%s %#x\n", nvme_ctrl_get_name(c), ret); + printf("ERROR: no smart log for:%s %#x\n", libnvme_ctrl_get_name(c), ret); return ret; } else { @@ -84,7 +84,7 @@ static int test_ctrl(nvme_ctrl_t c) } temp = ((smart.temperature[1] << 8) | smart.temperature[0]) - 273; - printf("Controller:%s\n", nvme_ctrl_get_name(c)); + printf("Controller:%s\n", libnvme_ctrl_get_name(c)); printf("\nIdentify:\n"); printf(" vid:%#04x\n", le16_to_cpu(id.vid)); printf(" ssvid:%#04x\n", le16_to_cpu(id.ssvid)); @@ -94,49 +94,49 @@ static int test_ctrl(nvme_ctrl_t c) printf(" model:%-.40s\n", id.mn); nvme_init_identify_allocated_ns_list(&cmd, 0, &ns_list); - ret = nvme_submit_admin_passthru(hdl, &cmd); + ret = libnvme_submit_admin_passthru(hdl, &cmd); if (!ret) printf(" PASSED: Allocated NS List\n"); else printf(" ERROR: Allocated NS List:%x\n", ret); nvme_init_identify_active_ns_list(&cmd, 0, &ns_list); - ret = nvme_submit_admin_passthru(hdl, &cmd); + ret = libnvme_submit_admin_passthru(hdl, &cmd); if (!ret) printf(" PASSED: Active NS List\n"); else printf(" ERROR: Active NS List:%x\n", ret); nvme_init_identify_ctrl_list(&cmd, 0, &ctrlist); - ret = nvme_submit_admin_passthru(hdl, &cmd); + ret = libnvme_submit_admin_passthru(hdl, &cmd); if (!ret) printf(" PASSED: Ctrl List\n"); else printf(" ERROR: CtrlList:%x\n", ret); nvme_init_identify_ctrl_list(&cmd, 1, &ctrlist); - ret = nvme_submit_admin_passthru(hdl, &cmd); + ret = libnvme_submit_admin_passthru(hdl, &cmd); if (!ret) printf(" PASSED: NSID Ctrl List\n"); else printf(" ERROR: NSID CtrlList:%x\n", ret); nvme_init_identify_primary_ctrl_cap(&cmd, 0, &prim); - ret = nvme_submit_admin_passthru(hdl, &cmd); + ret = libnvme_submit_admin_passthru(hdl, &cmd); if (!ret) printf(" PASSED: Identify Primary\n"); else printf(" ERROR: Identify Primary:%x\n", ret); nvme_init_identify_secondary_ctrl_list(&cmd, 0, &sec); - ret = nvme_submit_admin_passthru(hdl, &cmd); + ret = libnvme_submit_admin_passthru(hdl, &cmd); if (!ret) printf(" PASSED: Identify Secondary\n"); else printf(" ERROR: Identify Secondary:%x\n", ret); nvme_init_identify_ns_granularity(&cmd, &gran); - ret = nvme_submit_admin_passthru(hdl, &cmd); + ret = libnvme_submit_admin_passthru(hdl, &cmd); if (!ret) printf(" PASSED: Identify NS granularity\n"); else printf(" ERROR: Identify NS granularity:%x\n", ret); nvme_init_identify_uuid_list(&cmd, &uuid); - ret = nvme_submit_admin_passthru(hdl, &cmd); + ret = libnvme_submit_admin_passthru(hdl, &cmd); if (!ret) printf(" PASSED: Identify UUID List\n"); else @@ -146,172 +146,172 @@ static int test_ctrl(nvme_ctrl_t c) printf(" SMART: Current temperature:%d percent used:%d%%\n", temp, smart.percent_used); nvme_init_get_log_sanitize(&cmd, &sanlog); - ret = nvme_get_log(hdl, &cmd, true, NVME_LOG_PAGE_PDU_SIZE); + ret = libnvme_get_log(hdl, &cmd, true, NVME_LOG_PAGE_PDU_SIZE); if (!ret) printf(" Sanitize Log:\n"); else printf(" ERROR: Sanitize Log:%x\n", ret); nvme_init_get_log_reservation(&cmd, &resvnotify); - ret = nvme_get_log(hdl, &cmd, true, NVME_LOG_PAGE_PDU_SIZE); + ret = libnvme_get_log(hdl, &cmd, true, NVME_LOG_PAGE_PDU_SIZE); if (!ret) printf(" Reservation Log\n"); else printf(" ERROR: Reservation Log:%x\n", ret); nvme_init_get_log_ana_groups(&cmd, analog, sizeof(buf)); - ret = nvme_get_log(hdl, &cmd, true, NVME_LOG_PAGE_PDU_SIZE); + ret = libnvme_get_log(hdl, &cmd, true, NVME_LOG_PAGE_PDU_SIZE); if (!ret) printf(" ANA Groups\n"); else printf(" ERROR: ANA Groups:%x\n", ret); nvme_init_get_log_endurance_group(&cmd, 0, &eglog); - ret = nvme_get_log(hdl, &cmd, true, NVME_LOG_PAGE_PDU_SIZE); + ret = libnvme_get_log(hdl, &cmd, true, NVME_LOG_PAGE_PDU_SIZE); if (!ret) printf(" Endurance Group\n"); else printf(" ERROR: Endurance Group:%x\n", ret); nvme_init_get_log_telemetry_ctrl(&cmd, 0, telem, sizeof(buf)); - ret = nvme_get_log(hdl, &cmd, true, NVME_LOG_PAGE_PDU_SIZE); + ret = libnvme_get_log(hdl, &cmd, true, NVME_LOG_PAGE_PDU_SIZE); if (!ret) printf(" Telemetry Controller\n"); else printf(" ERROR: Telemetry Controller:%x\n", ret); nvme_init_get_log_device_self_test(&cmd, &st); - ret = nvme_get_log(hdl, &cmd, true, NVME_LOG_PAGE_PDU_SIZE); + ret = libnvme_get_log(hdl, &cmd, true, NVME_LOG_PAGE_PDU_SIZE); if (!ret) printf(" Device Self Test\n"); else printf(" ERROR: Device Self Test:%x\n", ret); nvme_init_get_log_cmd_effects(&cmd, NVME_CSI_NVM, &cfx); - ret = nvme_get_log(hdl, &cmd, true, NVME_LOG_PAGE_PDU_SIZE); + ret = libnvme_get_log(hdl, &cmd, true, NVME_LOG_PAGE_PDU_SIZE); if (!ret) printf(" Command Effects\n"); else printf(" ERROR: Command Effects:%x\n", ret); nvme_init_get_log_changed_alloc_ns(&cmd, &ns_list, sizeof(ns_list)); - ret = nvme_get_log(hdl, &cmd, true, NVME_LOG_PAGE_PDU_SIZE); + ret = libnvme_get_log(hdl, &cmd, true, NVME_LOG_PAGE_PDU_SIZE); if (!ret) printf(" Change NS List\n"); else printf(" ERROR: Change NS List:%x\n", ret); nvme_init_get_log_fw_slot(&cmd, &fw); - ret = nvme_get_log(hdl, &cmd, true, NVME_LOG_PAGE_PDU_SIZE); + ret = libnvme_get_log(hdl, &cmd, true, NVME_LOG_PAGE_PDU_SIZE); if (!ret) printf(" FW Slot\n"); else printf(" ERROR: FW Slot%x\n", ret); nvme_init_get_log_error(&cmd, 64, error); - ret = nvme_get_log(hdl, &cmd, true, NVME_LOG_PAGE_PDU_SIZE); + ret = libnvme_get_log(hdl, &cmd, true, NVME_LOG_PAGE_PDU_SIZE); if (!ret) printf(" Error Log\n"); else printf(" ERROR: Error Log:%x\n", ret); printf("\nFeatures\n"); nvme_init_get_features_arbitration(&cmd, sel); - ret = nvme_submit_admin_passthru(hdl, &cmd); + ret = libnvme_submit_admin_passthru(hdl, &cmd); if (!ret) printf(" Arbitration:%" PRIu64 "\n", (uint64_t)cmd.result); else if (ret > 0) printf(" ERROR: Arbitration:%x\n", ret); nvme_init_get_features_power_mgmt(&cmd, sel); - ret = nvme_submit_admin_passthru(hdl, &cmd); + ret = libnvme_submit_admin_passthru(hdl, &cmd); if (!ret) printf(" Power Management:%" PRIu64 "x\n", (uint64_t)cmd.result); else if (ret > 0) printf(" ERROR: Power Management:%x\n", ret); nvme_init_get_features_temp_thresh(&cmd, sel, 0, 0); - ret = nvme_submit_admin_passthru(hdl, &cmd); + ret = libnvme_submit_admin_passthru(hdl, &cmd); if (!ret) printf(" Temperature Threshold:%" PRIu64 "\n", (uint64_t)cmd.result); else if (ret > 0) printf(" ERROR: Temperature Threshold:%x\n", ret); nvme_init_get_features_volatile_wc(&cmd, sel); - ret = nvme_submit_admin_passthru(hdl, &cmd); + ret = libnvme_submit_admin_passthru(hdl, &cmd); if (!ret) printf(" Volatile Write Cache:%" PRIu64 "\n", (uint64_t)cmd.result); else if (ret > 0) printf(" ERROR: Volatile Write Cache:%x\n", ret); nvme_init_get_features_num_queues(&cmd, sel); - ret = nvme_submit_admin_passthru(hdl, &cmd); + ret = libnvme_submit_admin_passthru(hdl, &cmd); if (!ret) printf(" Number of Queues:%" PRIu64 "\n", (uint64_t)cmd.result); else if (ret > 0) printf(" ERROR: Number of Queues:%x\n", ret); nvme_init_get_features_irq_coalesce(&cmd, sel); - ret = nvme_submit_admin_passthru(hdl, &cmd); + ret = libnvme_submit_admin_passthru(hdl, &cmd); if (!ret) printf(" IRQ Coalescing:%" PRIu64 "\n", (uint64_t)cmd.result); else if (ret > 0) printf(" ERROR: IRQ Coalescing:%x\n", ret); nvme_init_get_features_write_atomic(&cmd, sel); - ret = nvme_submit_admin_passthru(hdl, &cmd); + ret = libnvme_submit_admin_passthru(hdl, &cmd); if (!ret) printf(" Write Atomic:%" PRIu64 "\n", (uint64_t)cmd.result); else if (ret > 0) printf(" ERROR: Write Atomic:%x\n", ret); nvme_init_get_features_async_event(&cmd, sel); - ret = nvme_submit_admin_passthru(hdl, &cmd); + ret = libnvme_submit_admin_passthru(hdl, &cmd); if (!ret) printf(" Asycn Event Config:%" PRIu64 "\n", (uint64_t)cmd.result); else if (ret > 0) printf(" ERROR: Asycn Event Config:%x\n", ret); nvme_init_get_features_hctm(&cmd, sel); - ret = nvme_submit_admin_passthru(hdl, &cmd); + ret = libnvme_submit_admin_passthru(hdl, &cmd); if (!ret) printf(" HCTM:%" PRIu64 "\n", (uint64_t)cmd.result); else if (ret > 0) printf(" ERROR: HCTM:%x\n", ret); nvme_init_get_features_nopsc(&cmd, sel); - ret = nvme_submit_admin_passthru(hdl, &cmd); + ret = libnvme_submit_admin_passthru(hdl, &cmd); if (!ret) printf(" NOP Power State Config:%" PRIu64 "\n", (uint64_t)cmd.result); else if (ret > 0) printf(" ERROR: NOP Power State Configrbitration:%x\n", ret); nvme_init_get_features_rrl(&cmd, sel); - ret = nvme_submit_admin_passthru(hdl, &cmd); + ret = libnvme_submit_admin_passthru(hdl, &cmd); if (!ret) printf(" Read Recover Levels:%" PRIu64 "\n", (uint64_t)cmd.result); else if (ret > 0) printf(" ERROR: Read Recover Levels:%x\n", ret); nvme_init_get_features_lba_sts_interval(&cmd, sel); - ret = nvme_submit_admin_passthru(hdl, &cmd); + ret = libnvme_submit_admin_passthru(hdl, &cmd); if (!ret) printf(" LBA Status Interval:%" PRIu64 "\n", (uint64_t)cmd.result); else if (ret > 0) printf(" ERROR: LBA Status Interval:%x\n", ret); nvme_init_get_features_sanitize(&cmd, sel); - ret = nvme_submit_admin_passthru(hdl, &cmd); + ret = libnvme_submit_admin_passthru(hdl, &cmd); if (!ret) printf(" Sanitize:%" PRIu64 "\n", (uint64_t)cmd.result); else if (ret > 0) printf(" ERROR: SW Progress Marker:%x\n", ret); nvme_init_get_features_sw_progress(&cmd, sel); - ret = nvme_submit_admin_passthru(hdl, &cmd); + ret = libnvme_submit_admin_passthru(hdl, &cmd); if (!ret) printf(" SW Progress Marker:%" PRIu64 "\n", (uint64_t)cmd.result); else if (ret > 0) printf(" ERROR: Sanitize:%x\n", ret); nvme_init_get_features_resv_mask(&cmd, 0, sel); - ret = nvme_submit_admin_passthru(hdl, &cmd); + ret = libnvme_submit_admin_passthru(hdl, &cmd); if (!ret) printf(" Reservation Mask:%" PRIu64 "\n", (uint64_t)cmd.result); else if (ret > 0) printf(" ERROR: Reservation Mask:%x\n", ret); nvme_init_get_features_resv_persist(&cmd, 0, sel); - ret = nvme_submit_admin_passthru(hdl, &cmd); + ret = libnvme_submit_admin_passthru(hdl, &cmd); if (!ret) printf(" Reservation Persistence:%" PRIu64 "\n", (uint64_t)cmd.result); @@ -320,31 +320,31 @@ static int test_ctrl(nvme_ctrl_t c) return 0; } -static int test_namespace(nvme_ns_t n) +static int test_namespace(libnvme_ns_t n) { - int ret, nsid = nvme_ns_get_nsid(n); - struct nvme_transport_handle *hdl; - struct nvme_passthru_cmd cmd; + int ret, nsid = libnvme_ns_get_nsid(n); + struct libnvme_transport_handle *hdl; + struct libnvme_passthru_cmd cmd; struct nvme_id_ns ns = { 0 }, allocated = { 0 }; struct nvme_ns_id_desc *descs; __u64 result = 0; __u8 flbas; - ret = nvme_ns_get_transport_handle(n, &hdl); + ret = libnvme_ns_get_transport_handle(n, &hdl); if (ret) return ret; - ret = nvme_ns_identify(n, &ns); + ret = libnvme_ns_identify(n, &ns); if (ret) return ret; nvme_id_ns_flbas_to_lbaf_inuse(ns.flbas, &flbas); printf("%s: nsze:%" PRIu64 " lba size:%d\n", - nvme_ns_get_name(n), le64_to_cpu(ns.nsze), + libnvme_ns_get_name(n), le64_to_cpu(ns.nsze), 1 << ns.lbaf[flbas].ds); nvme_init_identify_allocated_ns(&cmd, nsid, &allocated); - ret = nvme_submit_admin_passthru(hdl, &cmd); + ret = libnvme_submit_admin_passthru(hdl, &cmd); if (!ret) printf(" Identify allocated ns\n"); else @@ -354,7 +354,7 @@ static int test_namespace(nvme_ns_t n) return -1; nvme_init_identify_ns_descs_list(&cmd, nsid, descs); - ret = nvme_submit_admin_passthru(hdl, &cmd); + ret = libnvme_submit_admin_passthru(hdl, &cmd); if (!ret) printf(" Identify NS Descriptors\n"); else @@ -362,7 +362,7 @@ static int test_namespace(nvme_ns_t n) free(descs); nvme_init_get_features_write_protect(&cmd, nsid, NVME_GET_FEATURES_SEL_CURRENT); - ret = nvme_submit_admin_passthru(hdl, &cmd); + ret = libnvme_submit_admin_passthru(hdl, &cmd); if (!ret) printf(" Write Protect:%" PRIu64 "\n", (uint64_t)result); else if (ret > 0) @@ -380,37 +380,37 @@ static void print_hex(const uint8_t *x, int len) int main(int argc, char **argv) { - struct nvme_global_ctx *ctx; - nvme_host_t h; - nvme_subsystem_t s; - nvme_ctrl_t c; - nvme_path_t p; - nvme_ns_t n; + struct libnvme_global_ctx *ctx; + libnvme_host_t h; + libnvme_subsystem_t s; + libnvme_ctrl_t c; + libnvme_path_t p; + libnvme_ns_t n; int err; const char *ctrl = "nvme4"; const char *nqn_match = "testnqn"; printf("Test filter for common loop back target\n"); - ctx = nvme_create_global_ctx(stdout, DEFAULT_LOGLEVEL); + ctx = libnvme_create_global_ctx(stdout, DEFAULT_LOGLEVEL); if (!ctx) return 1; - err = nvme_scan_topology(ctx, nvme_match_subsysnqn_filter, + err = libnvme_scan_topology(ctx, nvme_match_subsysnqn_filter, (void *)nqn_match); if (err && !(err == ENOENT || err == EACCES)) { - nvme_free_global_ctx(ctx); + libnvme_free_global_ctx(ctx); return 1; } - nvme_for_each_host(ctx, h) { - nvme_for_each_subsystem(h, s) { - printf("%s - NQN=%s\n", nvme_subsystem_get_name(s), - nvme_subsystem_get_subsysnqn(s)); - nvme_subsystem_for_each_ctrl(s, c) { - printf(" %s %s %s %s\n", nvme_ctrl_get_name(c), - nvme_ctrl_get_transport(c), - nvme_ctrl_get_traddr(c), - nvme_ctrl_get_state(c)); + libnvme_for_each_host(ctx, h) { + libnvme_for_each_subsystem(h, s) { + printf("%s - NQN=%s\n", libnvme_subsystem_get_name(s), + libnvme_subsystem_get_subsysnqn(s)); + libnvme_subsystem_for_each_ctrl(s, c) { + printf(" %s %s %s %s\n", libnvme_ctrl_get_name(c), + libnvme_ctrl_get_transport(c), + libnvme_ctrl_get_traddr(c), + libnvme_ctrl_get_state(c)); } } } @@ -420,78 +420,78 @@ int main(int argc, char **argv) ctrl = argv[1]; printf("Test scan specific controller\n"); - if (!nvme_scan_ctrl(ctx, ctrl, &c)) { - printf("%s %s %s %s\n", nvme_ctrl_get_name(c), - nvme_ctrl_get_transport(c), - nvme_ctrl_get_traddr(c), - nvme_ctrl_get_state(c)); - nvme_free_ctrl(c); + if (!libnvme_scan_ctrl(ctx, ctrl, &c)) { + printf("%s %s %s %s\n", libnvme_ctrl_get_name(c), + libnvme_ctrl_get_transport(c), + libnvme_ctrl_get_traddr(c), + libnvme_ctrl_get_state(c)); + libnvme_free_ctrl(c); } printf("\n"); printf("Test walking the topology\n"); - nvme_for_each_host(ctx, h) { - nvme_for_each_subsystem(h, s) { - printf("%s - NQN=%s\n", nvme_subsystem_get_name(s), - nvme_subsystem_get_subsysnqn(s)); - nvme_subsystem_for_each_ctrl(s, c) { + libnvme_for_each_host(ctx, h) { + libnvme_for_each_subsystem(h, s) { + printf("%s - NQN=%s\n", libnvme_subsystem_get_name(s), + libnvme_subsystem_get_subsysnqn(s)); + libnvme_subsystem_for_each_ctrl(s, c) { printf(" `- %s %s %s %s\n", - nvme_ctrl_get_name(c), - nvme_ctrl_get_transport(c), - nvme_ctrl_get_traddr(c), - nvme_ctrl_get_state(c)); + libnvme_ctrl_get_name(c), + libnvme_ctrl_get_transport(c), + libnvme_ctrl_get_traddr(c), + libnvme_ctrl_get_state(c)); - nvme_ctrl_for_each_ns(c, n) { + libnvme_ctrl_for_each_ns(c, n) { char uuid_str[NVME_UUID_LEN_STRING]; unsigned char uuid[NVME_UUID_LEN]; printf(" `- %s lba size:%d lba max:%" PRIu64 "\n", - nvme_ns_get_name(n), - nvme_ns_get_lba_size(n), - nvme_ns_get_lba_count(n)); + libnvme_ns_get_name(n), + libnvme_ns_get_lba_size(n), + libnvme_ns_get_lba_count(n)); printf(" eui:"); - print_hex(nvme_ns_get_eui64(n), 8); + print_hex(libnvme_ns_get_eui64(n), 8); printf(" nguid:"); - print_hex(nvme_ns_get_nguid(n), 16); - nvme_ns_get_uuid(n, uuid); - nvme_uuid_to_string(uuid, uuid_str); + print_hex(libnvme_ns_get_nguid(n), 16); + libnvme_ns_get_uuid(n, uuid); + libnvme_uuid_to_string(uuid, uuid_str); printf(" uuid:%s csi:%d\n", uuid_str, - nvme_ns_get_csi(n)); + libnvme_ns_get_csi(n)); } - nvme_ctrl_for_each_path(c, p) + libnvme_ctrl_for_each_path(c, p) printf(" `- %s %s\n", - nvme_path_get_name(p), - nvme_path_get_ana_state(p)); + libnvme_path_get_name(p), + libnvme_path_get_ana_state(p)); } - nvme_subsystem_for_each_ns(s, n) { + libnvme_subsystem_for_each_ns(s, n) { printf(" `- %s lba size:%d lba max:%" PRIu64 "\n", - nvme_ns_get_name(n), - nvme_ns_get_lba_size(n), - nvme_ns_get_lba_count(n)); + libnvme_ns_get_name(n), + libnvme_ns_get_lba_size(n), + libnvme_ns_get_lba_count(n)); } } printf("\n"); } printf("Test identification, logs, and features\n"); - nvme_for_each_host(ctx, h) { - nvme_for_each_subsystem(h, s) { - nvme_subsystem_for_each_ctrl(s, c) { + libnvme_for_each_host(ctx, h) { + libnvme_for_each_subsystem(h, s) { + libnvme_subsystem_for_each_ctrl(s, c) { test_ctrl(c); printf("\n"); - nvme_ctrl_for_each_ns(c, n) { + libnvme_ctrl_for_each_ns(c, n) { test_namespace(n); printf("\n"); } } - nvme_subsystem_for_each_ns(s, n) { + libnvme_subsystem_for_each_ns(s, n) { test_namespace(n); printf("\n"); } } } - nvme_free_global_ctx(ctx); + libnvme_free_global_ctx(ctx); return 0; } diff --git a/libnvme/test/tree.c b/libnvme/test/tree.c index 6bb23a2b7b..71143bafee 100644 --- a/libnvme/test/tree.c +++ b/libnvme/test/tree.c @@ -21,8 +21,8 @@ struct test_data { const char *subsysname; /* track controller generated by input data */ - nvme_subsystem_t s; - nvme_ctrl_t c; + libnvme_subsystem_t s; + libnvme_ctrl_t c; int ctrl_id; }; @@ -57,7 +57,7 @@ struct test_data test_data[] = { }, }; -static struct test_data *find_test_data(nvme_ctrl_t c) +static struct test_data *find_test_data(libnvme_ctrl_t c) { for (int i = 0; i < ARRAY_SIZE(test_data); i++) { struct test_data *d = &test_data[i]; @@ -69,7 +69,7 @@ static struct test_data *find_test_data(nvme_ctrl_t c) return NULL; } -static void show_ctrl(nvme_ctrl_t c) +static void show_ctrl(libnvme_ctrl_t c) { struct test_data *d = find_test_data(c); @@ -80,15 +80,15 @@ static void show_ctrl(nvme_ctrl_t c) printf("0x%p: %s %s %s %s %s %s", c, - nvme_ctrl_get_subsysnqn(c), - nvme_ctrl_get_transport(c), - nvme_ctrl_get_traddr(c), - nvme_ctrl_get_host_traddr(c), - nvme_ctrl_get_host_iface(c), - nvme_ctrl_get_trsvcid(c)); + libnvme_ctrl_get_subsysnqn(c), + libnvme_ctrl_get_transport(c), + libnvme_ctrl_get_traddr(c), + libnvme_ctrl_get_host_traddr(c), + libnvme_ctrl_get_host_iface(c), + libnvme_ctrl_get_trsvcid(c)); } -static bool match_ctrl(struct test_data *d, nvme_ctrl_t c) +static bool match_ctrl(struct test_data *d, libnvme_ctrl_t c) { bool pass = true; const char *trsvid, *host_traddr, *host_iface; @@ -96,24 +96,24 @@ static bool match_ctrl(struct test_data *d, nvme_ctrl_t c) if (d->c != c) pass = false; - if (strcmp(d->f.transport, nvme_ctrl_get_transport(d->c))) + if (strcmp(d->f.transport, libnvme_ctrl_get_transport(d->c))) pass = false; - if (strcmp(d->f.traddr, nvme_ctrl_get_traddr(d->c))) + if (strcmp(d->f.traddr, libnvme_ctrl_get_traddr(d->c))) pass = false; - host_traddr = nvme_ctrl_get_host_traddr(c); + host_traddr = libnvme_ctrl_get_host_traddr(c); if (d->f.host_traddr && (!host_traddr || strcmp(d->f.host_traddr, host_traddr))) pass = false; - host_iface = nvme_ctrl_get_host_iface(c); + host_iface = libnvme_ctrl_get_host_iface(c); if (d->f.host_iface && (!host_iface || strcmp(d->f.host_iface, host_iface))) pass = false; - trsvid = nvme_ctrl_get_trsvcid(c); + trsvid = libnvme_ctrl_get_trsvcid(c); if (d->f.trsvcid && (!trsvid || strcmp(d->f.trsvcid, trsvid))) pass = false; @@ -123,24 +123,24 @@ static bool match_ctrl(struct test_data *d, nvme_ctrl_t c) return pass; } -static struct nvme_global_ctx *create_tree() +static struct libnvme_global_ctx *create_tree() { - struct nvme_global_ctx *ctx; - nvme_host_t h; + struct libnvme_global_ctx *ctx; + libnvme_host_t h; - ctx = nvme_create_global_ctx(stdout, LOG_DEBUG); + ctx = libnvme_create_global_ctx(stdout, LOG_DEBUG); assert(ctx); - nvme_get_host(ctx, DEFAULT_HOSTNQN, DEFAULT_HOSTID, &h); + libnvme_get_host(ctx, DEFAULT_HOSTNQN, DEFAULT_HOSTID, &h); assert(h); printf(" ctrls created:\n"); for (int i = 0; i < ARRAY_SIZE(test_data); i++) { struct test_data *d = &test_data[i]; - assert(!nvme_get_subsystem(ctx, h, d->subsysname, + assert(!libnvme_get_subsystem(ctx, h, d->subsysname, d->f.subsysnqn, &d->s)); assert(d->s); - d->c = nvme_lookup_ctrl(d->s, &d->f, NULL); + d->c = libnvme_lookup_ctrl(d->s, &d->f, NULL); assert(d->c); d->ctrl_id = i; @@ -154,30 +154,30 @@ static struct nvme_global_ctx *create_tree() return ctx; } -static unsigned int count_entries(struct nvme_global_ctx *ctx) +static unsigned int count_entries(struct libnvme_global_ctx *ctx) { - nvme_host_t h; - nvme_subsystem_t s; - nvme_ctrl_t c; + libnvme_host_t h; + libnvme_subsystem_t s; + libnvme_ctrl_t c; unsigned int i = 0; - nvme_for_each_host(ctx, h) - nvme_for_each_subsystem(h, s) - nvme_subsystem_for_each_ctrl(s, c) + libnvme_for_each_host(ctx, h) + libnvme_for_each_subsystem(h, s) + libnvme_subsystem_for_each_ctrl(s, c) i++; return i; } -static bool tcp_ctrl_lookup(nvme_subsystem_t s, struct test_data *d) +static bool tcp_ctrl_lookup(libnvme_subsystem_t s, struct test_data *d) { - nvme_ctrl_t c; + libnvme_ctrl_t c; bool pass = true; struct nvmf_context f = d->f; f.host_traddr = NULL; f.host_iface = NULL; - c = nvme_lookup_ctrl(s, &f, NULL); + c = libnvme_lookup_ctrl(s, &f, NULL); printf("%10s %12s %10s -> ", f.trsvcid, "", ""); show_ctrl(c); pass &= match_ctrl(d, c); @@ -186,7 +186,7 @@ static bool tcp_ctrl_lookup(nvme_subsystem_t s, struct test_data *d) if (d->f.host_traddr) { f = d->f; f.host_iface = NULL; - c = nvme_lookup_ctrl(s, &f, NULL); + c = libnvme_lookup_ctrl(s, &f, NULL); printf("%10s %12s %10s -> ", f.trsvcid, f.host_traddr, ""); show_ctrl(c); pass &= match_ctrl(d, c); @@ -196,7 +196,7 @@ static bool tcp_ctrl_lookup(nvme_subsystem_t s, struct test_data *d) if (d->f.host_iface) { f = d->f; f.host_traddr = NULL; - c = nvme_lookup_ctrl(s, &f, NULL); + c = libnvme_lookup_ctrl(s, &f, NULL); printf("%10s %12s %10s -> ", f.trsvcid, "", f.host_iface); show_ctrl(c); pass &= match_ctrl(d, c); @@ -205,7 +205,7 @@ static bool tcp_ctrl_lookup(nvme_subsystem_t s, struct test_data *d) if (d->f.host_iface && d->f.traddr) { f = d->f; - c = nvme_lookup_ctrl(s, &f, NULL); + c = libnvme_lookup_ctrl(s, &f, NULL); printf("%10s %12s %10s -> ", f.trsvcid, f.host_traddr, f.host_iface); show_ctrl(c); @@ -216,15 +216,15 @@ static bool tcp_ctrl_lookup(nvme_subsystem_t s, struct test_data *d) return pass; } -static bool default_ctrl_lookup(nvme_subsystem_t s, struct test_data *d) +static bool default_ctrl_lookup(libnvme_subsystem_t s, struct test_data *d) { - nvme_ctrl_t c; + libnvme_ctrl_t c; bool pass = true; struct nvmf_context f = d->f; f.host_iface = NULL; f.trsvcid = NULL; - c = nvme_lookup_ctrl(s, &f, NULL); + c = libnvme_lookup_ctrl(s, &f, NULL); printf("%10s %12s %10s -> ", "", "", ""); show_ctrl(c); pass &= match_ctrl(d, c); @@ -233,14 +233,14 @@ static bool default_ctrl_lookup(nvme_subsystem_t s, struct test_data *d) return pass; } -static bool ctrl_lookups(struct nvme_global_ctx *ctx) +static bool ctrl_lookups(struct libnvme_global_ctx *ctx) { - nvme_host_t h; - nvme_subsystem_t s; + libnvme_host_t h; + libnvme_subsystem_t s; bool pass = true; - h = nvme_first_host(ctx); - nvme_get_subsystem(ctx, h, DEFAULT_SUBSYSNAME, DEFAULT_SUBSYSNQN, &s); + h = libnvme_first_host(ctx); + libnvme_get_subsystem(ctx, h, DEFAULT_SUBSYSNAME, DEFAULT_SUBSYSNQN, &s); printf(" lookup controller:\n"); for (int i = 0; i < ARRAY_SIZE(test_data); i++) { @@ -263,7 +263,7 @@ static bool ctrl_lookups(struct nvme_global_ctx *ctx) static bool test_lookup(void) { - struct nvme_global_ctx *ctx; + struct libnvme_global_ctx *ctx; bool pass; printf("test_lookup:\n"); @@ -272,14 +272,14 @@ static bool test_lookup(void) pass = count_entries(ctx) == ARRAY_SIZE(test_data); pass &= ctrl_lookups(ctx); - nvme_free_global_ctx(ctx); + libnvme_free_global_ctx(ctx); return pass; } static bool test_src_addr() { - struct nvme_global_ctx *ctx; + struct libnvme_global_ctx *ctx; struct nvmf_context fctx = { .transport = "tcp", .traddr = "192.168.56.1", @@ -288,33 +288,33 @@ static bool test_src_addr() .trsvcid = "8009", }; bool pass = true; - nvme_host_t h; - nvme_ctrl_t c; - nvme_subsystem_t s; + libnvme_host_t h; + libnvme_ctrl_t c; + libnvme_subsystem_t s; char *src_addr, buffer[100]; /* big enough for IPv6 max length */ printf("\n" "test_src_addr:\n"); - ctx = nvme_create_global_ctx(stdout, LOG_DEBUG); + ctx = libnvme_create_global_ctx(stdout, LOG_DEBUG); assert(ctx); - nvme_get_host(ctx, DEFAULT_HOSTNQN, DEFAULT_HOSTID, &h); + libnvme_get_host(ctx, DEFAULT_HOSTNQN, DEFAULT_HOSTID, &h); assert(h); - nvme_get_subsystem(ctx, h, DEFAULT_SUBSYSNAME, DEFAULT_SUBSYSNQN, &s); + libnvme_get_subsystem(ctx, h, DEFAULT_SUBSYSNAME, DEFAULT_SUBSYSNQN, &s); assert(s); - c = nvme_lookup_ctrl(s, &fctx, NULL); + c = libnvme_lookup_ctrl(s, &fctx, NULL); assert(c); c->address = NULL; printf(" - Test c->address = NULL : src_addr = NULL "); - src_addr = nvme_ctrl_get_src_addr(c, buffer, sizeof(buffer)); + src_addr = libnvme_ctrl_get_src_addr(c, buffer, sizeof(buffer)); if (src_addr != NULL) { printf("[FAIL]\n"); fprintf(stderr, - "nvme_ctrl_get_src_addr() c->address=NULL should return src_addr=NULL\n"); + "libnvme_ctrl_get_src_addr() c->address=NULL should return src_addr=NULL\n"); pass = false; } else { printf("[PASS]\n"); @@ -322,11 +322,11 @@ static bool test_src_addr() c->address = ""; printf(" - Test c->address = \"\" : src_addr = NULL "); - src_addr = nvme_ctrl_get_src_addr(c, buffer, sizeof(buffer)); + src_addr = libnvme_ctrl_get_src_addr(c, buffer, sizeof(buffer)); if (src_addr != NULL) { printf("[FAIL]\n"); fprintf(stderr, - "nvme_ctrl_get_src_addr() c->address="" should return src_addr=NULL\n"); + "libnvme_ctrl_get_src_addr() c->address="" should return src_addr=NULL\n"); pass = false; } else { printf("[PASS]\n"); @@ -334,11 +334,11 @@ static bool test_src_addr() c->address = "traddr=192.168.56.1,trsvcid=8009"; printf(" - Test c->address = \"%s\" : src_addr = NULL ", c->address); - src_addr = nvme_ctrl_get_src_addr(c, buffer, sizeof(buffer)); + src_addr = libnvme_ctrl_get_src_addr(c, buffer, sizeof(buffer)); if (src_addr != NULL) { printf("[FAIL]\n"); fprintf(stderr, - "nvme_ctrl_get_src_addr() c->address=%s should return src_addr=NULL\n", + "libnvme_ctrl_get_src_addr() c->address=%s should return src_addr=NULL\n", c->address); pass = false; } else { @@ -347,11 +347,11 @@ static bool test_src_addr() c->address = "traddr=192.168.56.1,trsvcid=8009,src_addr=" SRC_ADDR4; printf(" - Test c->address = \"%s\" : src_addr = \"" SRC_ADDR4 "\" ", c->address); - src_addr = nvme_ctrl_get_src_addr(c, buffer, sizeof(buffer)); + src_addr = libnvme_ctrl_get_src_addr(c, buffer, sizeof(buffer)); if (!src_addr || strcmp(src_addr, SRC_ADDR4)) { printf("[FAIL]\n"); fprintf(stderr, - "nvme_ctrl_get_src_addr() c->address=%s should return src_addr=" SRC_ADDR4 "\n", + "libnvme_ctrl_get_src_addr() c->address=%s should return src_addr=" SRC_ADDR4 "\n", c->address); pass = false; } else { @@ -360,11 +360,11 @@ static bool test_src_addr() c->address = "traddr=192.168.56.1,src_addr=" SRC_ADDR4 ",trsvcid=8009"; printf(" - Test c->address = \"%s\" : src_addr = \"" SRC_ADDR4 "\" ", c->address); - src_addr = nvme_ctrl_get_src_addr(c, buffer, sizeof(buffer)); + src_addr = libnvme_ctrl_get_src_addr(c, buffer, sizeof(buffer)); if (!src_addr || strcmp(src_addr, SRC_ADDR4)) { printf("[FAIL]\n"); fprintf(stderr, - "nvme_ctrl_get_src_addr() c->address=%s should return src_addr=" SRC_ADDR4 "\n", + "libnvme_ctrl_get_src_addr() c->address=%s should return src_addr=" SRC_ADDR4 "\n", c->address); pass = false; } else { @@ -373,11 +373,11 @@ static bool test_src_addr() c->address = "traddr=1234::abcd,trsvcid=8009,src_addr=" SRC_ADDR6; printf(" - Test c->address = \"%s\" : src_addr = \"" SRC_ADDR6 "\" ", c->address); - src_addr = nvme_ctrl_get_src_addr(c, buffer, sizeof(buffer)); + src_addr = libnvme_ctrl_get_src_addr(c, buffer, sizeof(buffer)); if (!src_addr || strcmp(src_addr, SRC_ADDR6)) { printf("[FAIL]\n"); fprintf(stderr, - "nvme_ctrl_get_src_addr() c->address=%s should return src_addr=" SRC_ADDR6 "\n", + "libnvme_ctrl_get_src_addr() c->address=%s should return src_addr=" SRC_ADDR6 "\n", c->address); pass = false; } else { @@ -386,11 +386,11 @@ static bool test_src_addr() c->address = "traddr=1234::abcd,src_addr=" SRC_ADDR6 ",trsvcid=8009"; printf(" - Test c->address = \"%s\" : src_addr = \"" SRC_ADDR6 "\" ", c->address); - src_addr = nvme_ctrl_get_src_addr(c, buffer, sizeof(buffer)); + src_addr = libnvme_ctrl_get_src_addr(c, buffer, sizeof(buffer)); if (!src_addr || strcmp(src_addr, SRC_ADDR6)) { printf("[FAIL]\n"); fprintf(stderr, - "nvme_ctrl_get_src_addr() c->address=%s should return src_addr=" SRC_ADDR6 "\n", + "libnvme_ctrl_get_src_addr() c->address=%s should return src_addr=" SRC_ADDR6 "\n", c->address); pass = false; } else { @@ -399,11 +399,11 @@ static bool test_src_addr() c->address = "traddr=1234::abcd,trsvcid=8009,src_addr=" SRC_ADDR6 "%scope"; printf(" - Test c->address = \"%s\" : src_addr = \"" SRC_ADDR6 "\" ", c->address); - src_addr = nvme_ctrl_get_src_addr(c, buffer, sizeof(buffer)); + src_addr = libnvme_ctrl_get_src_addr(c, buffer, sizeof(buffer)); if (!src_addr || strcmp(src_addr, SRC_ADDR6)) { printf("[FAIL]\n"); fprintf(stderr, - "nvme_ctrl_get_src_addr() c->address=%s should return src_addr=" SRC_ADDR6 "\n", + "libnvme_ctrl_get_src_addr() c->address=%s should return src_addr=" SRC_ADDR6 "\n", c->address); pass = false; } else { @@ -412,11 +412,11 @@ static bool test_src_addr() c->address = "traddr=1234::abcd,src_addr=" SRC_ADDR6 "%scope,trsvcid=8009"; printf(" - Test c->address = \"%s\" : src_addr = \"" SRC_ADDR6 "\" ", c->address); - src_addr = nvme_ctrl_get_src_addr(c, buffer, sizeof(buffer)); + src_addr = libnvme_ctrl_get_src_addr(c, buffer, sizeof(buffer)); if (!src_addr || strcmp(src_addr, SRC_ADDR6)) { printf("[FAIL]\n"); fprintf(stderr, - "nvme_ctrl_get_src_addr() c->address=%s should return src_addr=" SRC_ADDR6 "\n", + "libnvme_ctrl_get_src_addr() c->address=%s should return src_addr=" SRC_ADDR6 "\n", c->address); pass = false; } else { @@ -425,7 +425,7 @@ static bool test_src_addr() c->address = NULL; /* Needed to avoid freeing non-malloced memory (see above) */ - nvme_free_global_ctx(ctx); + libnvme_free_global_ctx(ctx); return pass; } @@ -460,36 +460,36 @@ static bool ctrl_match(const char *tag, struct ctrl_args *candidate, bool should_match) { - struct nvme_global_ctx *ctx; - nvme_host_t h; - nvme_ctrl_t reference_ctrl; /* Existing controller (from sysfs) */ - nvme_ctrl_t candidate_ctrl; - nvme_ctrl_t found_ctrl; - nvme_subsystem_t s; - - ctx = nvme_create_global_ctx(stdout, LOG_INFO); + struct libnvme_global_ctx *ctx; + libnvme_host_t h; + libnvme_ctrl_t reference_ctrl; /* Existing controller (from sysfs) */ + libnvme_ctrl_t candidate_ctrl; + libnvme_ctrl_t found_ctrl; + libnvme_subsystem_t s; + + ctx = libnvme_create_global_ctx(stdout, LOG_INFO); assert(ctx); - nvme_get_host(ctx, DEFAULT_HOSTNQN, DEFAULT_HOSTID, &h); + libnvme_get_host(ctx, DEFAULT_HOSTNQN, DEFAULT_HOSTID, &h); assert(h); - assert(!nvme_get_subsystem(ctx, h, DEFAULT_SUBSYSNAME, + assert(!libnvme_get_subsystem(ctx, h, DEFAULT_SUBSYSNAME, reference->f.subsysnqn ? reference->f.subsysnqn : DEFAULT_SUBSYSNQN, &s)); assert(s); - reference_ctrl = nvme_lookup_ctrl(s, &reference->f, NULL); + reference_ctrl = libnvme_lookup_ctrl(s, &reference->f, NULL); assert(reference_ctrl); reference_ctrl->name = "nvme1"; /* fake the device name */ if (reference->address) { reference_ctrl->address = (char *)reference->address; } - /* nvme_ctrl_find() MUST BE RUN BEFORE nvme_lookup_ctrl() */ - found_ctrl = nvme_ctrl_find(s, &candidate->f); + /* libnvme_ctrl_find() MUST BE RUN BEFORE libnvme_lookup_ctrl() */ + found_ctrl = libnvme_ctrl_find(s, &candidate->f); - candidate_ctrl = nvme_lookup_ctrl(s, &candidate->f, NULL); + candidate_ctrl = libnvme_lookup_ctrl(s, &candidate->f, NULL); if (should_match) { if (candidate_ctrl != reference_ctrl) { @@ -546,7 +546,7 @@ static bool ctrl_match(const char *tag, reference_ctrl->name = NULL; reference_ctrl->address = NULL; - nvme_free_global_ctx(ctx); + libnvme_free_global_ctx(ctx); return true; } @@ -1083,32 +1083,32 @@ static bool ctrl_config_match(const char *tag, struct ctrl_args *candidate, bool should_match) { - struct nvme_global_ctx *ctx; + struct libnvme_global_ctx *ctx; bool match; - nvme_host_t h; - nvme_ctrl_t reference_ctrl; /* Existing controller (from sysfs) */ - nvme_subsystem_t s; + libnvme_host_t h; + libnvme_ctrl_t reference_ctrl; /* Existing controller (from sysfs) */ + libnvme_subsystem_t s; - ctx = nvme_create_global_ctx(stdout, LOG_INFO); + ctx = libnvme_create_global_ctx(stdout, LOG_INFO); assert(ctx); - nvme_get_host(ctx, DEFAULT_HOSTNQN, DEFAULT_HOSTID, &h); + libnvme_get_host(ctx, DEFAULT_HOSTNQN, DEFAULT_HOSTID, &h); assert(h); - assert(!nvme_get_subsystem(ctx, h, DEFAULT_SUBSYSNAME, + assert(!libnvme_get_subsystem(ctx, h, DEFAULT_SUBSYSNAME, reference->f.subsysnqn ? reference->f.subsysnqn : DEFAULT_SUBSYSNQN, &s)); assert(s); - reference_ctrl = nvme_lookup_ctrl(s, &reference->f, NULL); + reference_ctrl = libnvme_lookup_ctrl(s, &reference->f, NULL); assert(reference_ctrl); reference_ctrl->name = "nvme1"; /* fake the device name */ if (reference->address) { reference_ctrl->address = (char *)reference->address; } - match = _nvme_ctrl_match_config(reference_ctrl, &candidate->f); + match = _libnvme_ctrl_match_config(reference_ctrl, &candidate->f); if (should_match) { if (!match) { @@ -1136,7 +1136,7 @@ static bool ctrl_config_match(const char *tag, reference_ctrl->name = NULL; reference_ctrl->address = NULL; - nvme_free_global_ctx(ctx); + libnvme_free_global_ctx(ctx); return true; } diff --git a/libnvme/test/uriparser.c b/libnvme/test/uriparser.c index 9d5723b965..664c35a8c0 100644 --- a/libnvme/test/uriparser.c +++ b/libnvme/test/uriparser.c @@ -154,12 +154,12 @@ static void test_uriparser(void) printf("Testing URI parser:\n"); for (int i = 0; i < ARRAY_SIZE(test_data); i++) { const struct test_data *d = &test_data[i]; - struct nvme_fabrics_uri *parsed_data; + struct libnvme_fabrics_uri *parsed_data; char **s; int i; printf(" '%s'...", d->uri); - assert(!nvme_parse_uri(d->uri, &parsed_data)); + assert(!libnvme_parse_uri(d->uri, &parsed_data)); assert(strcmp(d->scheme, parsed_data->scheme) == 0); if (d->proto) { @@ -200,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 = NULL; + struct libnvme_fabrics_uri *parsed_data = NULL; printf(" '%s'...", test_data_bad[i]); - assert(nvme_parse_uri(test_data_bad[i], &parsed_data)); + assert(libnvme_parse_uri(test_data_bad[i], &parsed_data)); assert(parsed_data == NULL); printf(" OK\n"); } diff --git a/libnvme/test/uuid.c b/libnvme/test/uuid.c index 3b557969c4..939f217309 100644 --- a/libnvme/test/uuid.c +++ b/libnvme/test/uuid.c @@ -59,9 +59,9 @@ static void tostr_test(struct test_data *test) { char str[NVME_UUID_LEN_STRING]; - if (nvme_uuid_to_string(test->uuid, str)) { + if (libnvme_uuid_to_string(test->uuid, str)) { test_rc = 1; - printf("ERROR: nvme_uuid_to_string() failed\n"); + printf("ERROR: libnvme_uuid_to_string() failed\n"); return; } check_str(test->str, str); @@ -72,9 +72,9 @@ static void fromstr_test(struct test_data *test) unsigned char uuid[NVME_UUID_LEN]; - if (nvme_uuid_from_string(test->str, uuid)) { + if (libnvme_uuid_from_string(test->str, uuid)) { test_rc = 1; - printf("ERROR: nvme_uuid_from_string() failed\n"); + printf("ERROR: libnvme_uuid_from_string() failed\n"); return; } check_uuid(test->uuid, uuid); @@ -85,9 +85,9 @@ static void random_uuid_test(void) unsigned char uuid1[NVME_UUID_LEN], uuid2[NVME_UUID_LEN]; char str1[NVME_UUID_LEN_STRING], str2[NVME_UUID_LEN_STRING]; - if (nvme_random_uuid(uuid1) || nvme_random_uuid(uuid2)) { + if (libnvme_random_uuid(uuid1) || libnvme_random_uuid(uuid2)) { test_rc = 1; - printf("ERROR: nvme_random_uuid() failed\n"); + printf("ERROR: libnvme_random_uuid() failed\n"); return; } @@ -97,8 +97,8 @@ static void random_uuid_test(void) return; } - if (nvme_uuid_to_string(uuid1, str1) || - nvme_uuid_to_string(uuid2, str2)) { + if (libnvme_uuid_to_string(uuid1, str1) || + libnvme_uuid_to_string(uuid2, str2)) { test_rc = 1; printf("ERROR: could not stringify randomly generated UUID\n"); return; diff --git a/libnvme/test/zns.c b/libnvme/test/zns.c index 79051a10fc..12de63e4fc 100644 --- a/libnvme/test/zns.c +++ b/libnvme/test/zns.c @@ -21,16 +21,16 @@ #include "nvme/private.h" -static void show_zns_properties(nvme_ns_t n) +static void show_zns_properties(libnvme_ns_t n) { - struct nvme_transport_handle *hdl; - struct nvme_passthru_cmd cmd; + struct libnvme_transport_handle *hdl; + struct libnvme_passthru_cmd cmd; struct nvme_zns_id_ns zns_ns; struct nvme_zns_id_ctrl zns_ctrl; struct nvme_zone_report *zr; int err; - err = nvme_ns_get_transport_handle(n, &hdl); + err = libnvme_ns_get_transport_handle(n, &hdl); if (err) return; @@ -38,8 +38,8 @@ static void show_zns_properties(nvme_ns_t n) if (!zr) return; - nvme_init_zns_identify_ns(&cmd, nvme_ns_get_nsid(n), &zns_ns); - if (nvme_submit_admin_passthru(hdl, &cmd)) { + nvme_init_zns_identify_ns(&cmd, libnvme_ns_get_nsid(n), &zns_ns); + if (libnvme_submit_admin_passthru(hdl, &cmd)) { fprintf(stderr, "failed to identify zns ns, result %" PRIx64 "\n", (uint64_t)cmd.result); free(zr); @@ -51,17 +51,17 @@ static void show_zns_properties(nvme_ns_t n) le32_to_cpu(zns_ns.mor)); nvme_init_zns_identify_ctrl(&cmd, &zns_ctrl); - if (nvme_submit_admin_passthru(hdl, &cmd)) { + if (libnvme_submit_admin_passthru(hdl, &cmd)) { fprintf(stderr, "failed to identify zns ctrl\n");; free(zr); return; } printf("zasl:%u\n", zns_ctrl.zasl); - nvme_init_zns_report_zones(&cmd, nvme_ns_get_nsid(n), 0, + nvme_init_zns_report_zones(&cmd, libnvme_ns_get_nsid(n), 0, NVME_ZNS_ZRAS_REPORT_ALL, false, true, (void *)zr, 0x1000); - if (nvme_submit_io_passthru(hdl, &cmd)) { + if (libnvme_submit_io_passthru(hdl, &cmd)) { fprintf(stderr, "failed to report zones, result %" PRIx64"\n", (uint64_t)cmd.result); free(zr); @@ -74,38 +74,38 @@ static void show_zns_properties(nvme_ns_t n) int main() { - struct nvme_global_ctx *ctx; - nvme_subsystem_t s; - nvme_host_t h; - nvme_ctrl_t c; - nvme_ns_t n; + struct libnvme_global_ctx *ctx; + libnvme_subsystem_t s; + libnvme_host_t h; + libnvme_ctrl_t c; + libnvme_ns_t n; int err; - ctx = nvme_create_global_ctx(stdout, DEFAULT_LOGLEVEL); + ctx = libnvme_create_global_ctx(stdout, DEFAULT_LOGLEVEL); if (!ctx) return 1; - err = nvme_scan_topology(ctx, NULL, NULL); + err = libnvme_scan_topology(ctx, NULL, NULL); if (err && !(err == -ENOENT || err == -EACCES)) { - nvme_free_global_ctx(ctx); + libnvme_free_global_ctx(ctx); return 1; } - nvme_for_each_host(ctx, h) { - nvme_for_each_subsystem(h, s) { - nvme_subsystem_for_each_ctrl(s, c) { - nvme_ctrl_for_each_ns(c, n) { - if (nvme_ns_get_csi(n) == NVME_CSI_ZNS) + libnvme_for_each_host(ctx, h) { + libnvme_for_each_subsystem(h, s) { + libnvme_subsystem_for_each_ctrl(s, c) { + libnvme_ctrl_for_each_ns(c, n) { + if (libnvme_ns_get_csi(n) == NVME_CSI_ZNS) show_zns_properties(n); } } - nvme_subsystem_for_each_ns(s, n) { - if (nvme_ns_get_csi(n) == NVME_CSI_ZNS) + libnvme_subsystem_for_each_ns(s, n) { + if (libnvme_ns_get_csi(n) == NVME_CSI_ZNS) show_zns_properties(n); } } } - nvme_free_global_ctx(ctx); + libnvme_free_global_ctx(ctx); return 0; } diff --git a/logging.c b/logging.c index 556d383893..5f8a1cc18d 100644 --- a/logging.c +++ b/logging.c @@ -65,7 +65,7 @@ int map_log_level(int verbose, bool quiet) return log_level; } -static void nvme_show_common(struct nvme_passthru_cmd *cmd) +static void nvme_show_common(struct libnvme_passthru_cmd *cmd) { nvme_show_key_value("opcode ", "%02x", cmd->opcode); nvme_show_key_value("flags ", "%02x", cmd->flags); @@ -86,7 +86,7 @@ static void nvme_show_common(struct nvme_passthru_cmd *cmd) nvme_show_key_value("timeout_ms ", "%08x", cmd->timeout_ms); } -static void nvme_show_command(struct nvme_passthru_cmd *cmd, int err) +static void nvme_show_command(struct libnvme_passthru_cmd *cmd, int err) { nvme_show_common(cmd); nvme_show_key_value("result ", "%"PRIx64"", (uint64_t)(uintptr_t)cmd->result); @@ -105,11 +105,11 @@ static void nvme_log_retry(int errnum) if (log_level < LOG_DEBUG) return; - printf("passthru command returned '%s'\n", nvme_strerror(errnum)); + printf("passthru command returned '%s'\n", libnvme_strerror(errnum)); } -void *nvme_submit_entry(struct nvme_transport_handle *hdl, - struct nvme_passthru_cmd *cmd) +void *nvme_submit_entry(struct libnvme_transport_handle *hdl, + struct libnvme_passthru_cmd *cmd) { memset(&sb, 0, sizeof(sb)); @@ -119,8 +119,8 @@ void *nvme_submit_entry(struct nvme_transport_handle *hdl, return &sb; } -void nvme_submit_exit(struct nvme_transport_handle *hdl, - struct nvme_passthru_cmd *cmd, int err, void *user_data) +void nvme_submit_exit(struct libnvme_transport_handle *hdl, + struct libnvme_passthru_cmd *cmd, int err, void *user_data) { struct submit_data *sb = user_data; @@ -131,8 +131,8 @@ void nvme_submit_exit(struct nvme_transport_handle *hdl, } } -bool nvme_decide_retry(struct nvme_transport_handle *hdl, - struct nvme_passthru_cmd *cmd, int err) +bool nvme_decide_retry(struct libnvme_transport_handle *hdl, + struct libnvme_passthru_cmd *cmd, int err) { if (!nvme_args.no_retries) return false; @@ -148,7 +148,7 @@ bool nvme_decide_retry(struct nvme_transport_handle *hdl, static void nvme_show_req_admin(const struct nvme_mi_admin_req_hdr *hdr, size_t hdr_len, const void *data, size_t data_len) { - struct nvme_passthru_cmd cmd = { + struct libnvme_passthru_cmd cmd = { .opcode = hdr->opcode, .flags = hdr->flags, .nsid = le32_to_cpu(hdr->cdw1), @@ -192,7 +192,7 @@ static void nvme_show_req(__u8 type, const struct nvme_mi_msg_hdr *hdr, size_t h } } -void *nvme_mi_submit_entry(__u8 type, const struct nvme_mi_msg_hdr *hdr, size_t hdr_len, +void *libnvme_mi_submit_entry(__u8 type, const struct nvme_mi_msg_hdr *hdr, size_t hdr_len, const void *data, size_t data_len) { memset(&sb, 0, sizeof(sb)); @@ -235,7 +235,7 @@ static void nvme_show_resp(__u8 type, const struct nvme_mi_msg_hdr *hdr, size_t } } -void nvme_mi_submit_exit(__u8 type, const struct nvme_mi_msg_hdr *hdr, size_t hdr_len, +void libnvme_mi_submit_exit(__u8 type, const struct nvme_mi_msg_hdr *hdr, size_t hdr_len, const void *data, size_t data_len, void *user_data) { struct submit_data *sb = user_data; diff --git a/logging.h b/logging.h index 2f4633c83b..5d48a800ff 100644 --- a/logging.h +++ b/logging.h @@ -19,15 +19,15 @@ extern int log_level; -struct nvme_transport_handle; -struct nvme_passthru_cmd; - -void *nvme_submit_entry(struct nvme_transport_handle *hdl, - struct nvme_passthru_cmd *cmd); -void nvme_submit_exit(struct nvme_transport_handle *hdl, - struct nvme_passthru_cmd *cmd, int err, void *user_data); -bool nvme_decide_retry(struct nvme_transport_handle *hdl, - struct nvme_passthru_cmd *cmd, int err); +struct libnvme_transport_handle; +struct libnvme_passthru_cmd; + +void *nvme_submit_entry(struct libnvme_transport_handle *hdl, + struct libnvme_passthru_cmd *cmd); +void nvme_submit_exit(struct libnvme_transport_handle *hdl, + struct libnvme_passthru_cmd *cmd, int err, void *user_data); +bool nvme_decide_retry(struct libnvme_transport_handle *hdl, + struct libnvme_passthru_cmd *cmd, int err); bool is_printable_at_level(int level); int map_log_level(int verbose, bool quiet); diff --git a/nvme-cmds.c b/nvme-cmds.c index 11148379d0..a57d92614e 100644 --- a/nvme-cmds.c +++ b/nvme-cmds.c @@ -11,14 +11,14 @@ #include "nvme-cmds.h" -static int nvme_ns_attachment(struct nvme_transport_handle *hdl, bool ish, +static int nvme_ns_attachment(struct libnvme_transport_handle *hdl, bool ish, __u32 nsid, __u16 num_ctrls, __u16 *ctrlist, bool attach) { struct nvme_ctrl_list cntlist = { 0 }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; nvme_init_ctrl_list(&cntlist, num_ctrls, ctrlist); - if (ish && nvme_transport_handle_is_mi(hdl)) + if (ish && libnvme_transport_handle_is_mi(hdl)) nvme_init_mi_cmd_flags(&cmd, ish); if (attach) @@ -26,16 +26,16 @@ static int nvme_ns_attachment(struct nvme_transport_handle *hdl, bool ish, else nvme_init_ns_detach_ctrls(&cmd, nsid, &cntlist); - return nvme_submit_admin_passthru(hdl, &cmd); + return libnvme_submit_admin_passthru(hdl, &cmd); } -int nvme_namespace_attach_ctrls(struct nvme_transport_handle *hdl, bool ish, +int nvme_namespace_attach_ctrls(struct libnvme_transport_handle *hdl, bool ish, __u32 nsid, __u16 num_ctrls, __u16 *ctrlist) { return nvme_ns_attachment(hdl, ish, nsid, num_ctrls, ctrlist, true); } -int nvme_namespace_detach_ctrls(struct nvme_transport_handle *hdl, bool ish, +int nvme_namespace_detach_ctrls(struct libnvme_transport_handle *hdl, bool ish, __u32 nsid, __u16 num_ctrls, __u16 *ctrlist) { return nvme_ns_attachment(hdl, ish, nsid, num_ctrls, ctrlist, false); diff --git a/nvme-cmds.h b/nvme-cmds.h index 35d30f1620..1dd8038f6c 100644 --- a/nvme-cmds.h +++ b/nvme-cmds.h @@ -26,14 +26,14 @@ * 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(struct nvme_transport_handle *hdl, __u32 nsid) +static inline int nvme_flush(struct libnvme_transport_handle *hdl, __u32 nsid) { - struct nvme_passthru_cmd cmd = {}; + struct libnvme_passthru_cmd cmd = {}; cmd.opcode = nvme_cmd_flush; cmd.nsid = nsid; - return nvme_submit_io_passthru(hdl, &cmd); + return libnvme_submit_io_passthru(hdl, &cmd); } /** @@ -54,14 +54,14 @@ static inline int nvme_flush(struct nvme_transport_handle *hdl, __u32 nsid) * errno otherwise. */ static inline int -nvme_identify(struct nvme_transport_handle *hdl, __u32 nsid, enum nvme_csi csi, +nvme_identify(struct libnvme_transport_handle *hdl, __u32 nsid, enum nvme_csi csi, enum nvme_identify_cns cns, void *data, __u32 len) { - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; nvme_init_identify(&cmd, nsid, csi, cns, data, len); - return nvme_submit_admin_passthru(hdl, &cmd); + return libnvme_submit_admin_passthru(hdl, &cmd); } /** @@ -78,14 +78,14 @@ nvme_identify(struct nvme_transport_handle *hdl, __u32 nsid, enum nvme_csi csi, * errno otherwise. */ static inline int -nvme_identify_ctrl(struct nvme_transport_handle *hdl, +nvme_identify_ctrl(struct libnvme_transport_handle *hdl, struct nvme_id_ctrl *id) { - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; nvme_init_identify_ctrl(&cmd, id); - return nvme_submit_admin_passthru(hdl, &cmd); + return libnvme_submit_admin_passthru(hdl, &cmd); } /** @@ -102,14 +102,14 @@ nvme_identify_ctrl(struct nvme_transport_handle *hdl, * errno otherwise. */ static inline int -nvme_identify_active_ns_list(struct nvme_transport_handle *hdl, +nvme_identify_active_ns_list(struct libnvme_transport_handle *hdl, __u32 nsid, struct nvme_ns_list *ns_list) { - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; nvme_init_identify_active_ns_list(&cmd, nsid, ns_list); - return nvme_submit_admin_passthru(hdl, &cmd); + return libnvme_submit_admin_passthru(hdl, &cmd); } /** @@ -127,14 +127,14 @@ nvme_identify_active_ns_list(struct nvme_transport_handle *hdl, */ static inline int -nvme_identify_ns(struct nvme_transport_handle *hdl, +nvme_identify_ns(struct libnvme_transport_handle *hdl, __u32 nsid, struct nvme_id_ns *ns) { - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; nvme_init_identify_ns(&cmd, nsid, ns); - return nvme_submit_admin_passthru(hdl, &cmd); + return libnvme_submit_admin_passthru(hdl, &cmd); } /** @@ -153,14 +153,14 @@ nvme_identify_ns(struct nvme_transport_handle *hdl, * errno otherwise. */ static inline int -nvme_identify_csi_ns(struct nvme_transport_handle *hdl, __u32 nsid, +nvme_identify_csi_ns(struct libnvme_transport_handle *hdl, __u32 nsid, enum nvme_csi csi, __u8 uidx, struct nvme_nvm_id_ns *id_ns) { - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; nvme_init_identify_csi_ns(&cmd, nsid, csi, uidx, id_ns); - return nvme_submit_admin_passthru(hdl, &cmd); + return libnvme_submit_admin_passthru(hdl, &cmd); } /** @@ -176,14 +176,14 @@ nvme_identify_csi_ns(struct nvme_transport_handle *hdl, __u32 nsid, * errno otherwise. */ static inline int -nvme_identify_uuid_list(struct nvme_transport_handle *hdl, +nvme_identify_uuid_list(struct libnvme_transport_handle *hdl, struct nvme_id_uuid_list *uuid_list) { - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; nvme_init_identify_uuid_list(&cmd, uuid_list); - return nvme_submit_admin_passthru(hdl, &cmd); + return libnvme_submit_admin_passthru(hdl, &cmd); } /** @@ -202,14 +202,14 @@ nvme_identify_uuid_list(struct nvme_transport_handle *hdl, * errno otherwise. */ static inline int -nvme_identify_csi_ns_user_data_format(struct nvme_transport_handle *hdl, +nvme_identify_csi_ns_user_data_format(struct libnvme_transport_handle *hdl, enum nvme_csi csi, __u16 fidx, __u8 uidx, void *data) { - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; nvme_init_identify_csi_ns_user_data_format(&cmd, csi, fidx, uidx, data); - return nvme_submit_admin_passthru(hdl, &cmd); + return libnvme_submit_admin_passthru(hdl, &cmd); } /** @@ -225,14 +225,14 @@ nvme_identify_csi_ns_user_data_format(struct nvme_transport_handle *hdl, * errno otherwise. */ static inline int -nvme_identify_ns_granularity(struct nvme_transport_handle *hdl, +nvme_identify_ns_granularity(struct libnvme_transport_handle *hdl, struct nvme_id_ns_granularity_list *gr_list) { - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; nvme_init_identify_ns_granularity(&cmd, gr_list); - return nvme_submit_admin_passthru(hdl, &cmd); + return libnvme_submit_admin_passthru(hdl, &cmd); } /** @@ -250,14 +250,14 @@ nvme_identify_ns_granularity(struct nvme_transport_handle *hdl, * errno otherwise. */ static inline int -nvme_identify_ns_descs_list(struct nvme_transport_handle *hdl, +nvme_identify_ns_descs_list(struct libnvme_transport_handle *hdl, __u32 nsid, struct nvme_ns_id_desc *descs) { - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; nvme_init_identify_ns_descs_list(&cmd, nsid, descs); - return nvme_submit_admin_passthru(hdl, &cmd); + return libnvme_submit_admin_passthru(hdl, &cmd); } /** @@ -274,14 +274,14 @@ nvme_identify_ns_descs_list(struct nvme_transport_handle *hdl, * errno otherwise. */ static inline int -nvme_zns_identify_ns(struct nvme_transport_handle *hdl, +nvme_zns_identify_ns(struct libnvme_transport_handle *hdl, __u32 nsid, struct nvme_zns_id_ns *data) { - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; nvme_init_zns_identify_ns(&cmd, nsid, data); - return nvme_submit_admin_passthru(hdl, &cmd); + return libnvme_submit_admin_passthru(hdl, &cmd); } /** @@ -300,14 +300,14 @@ nvme_zns_identify_ns(struct nvme_transport_handle *hdl, * errno otherwise. */ static inline int -nvme_get_log_simple(struct nvme_transport_handle *hdl, +nvme_get_log_simple(struct libnvme_transport_handle *hdl, enum nvme_cmd_get_log_lid lid, void *data, __u32 len) { - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; nvme_init_get_log(&cmd, NVME_NSID_ALL, lid, NVME_CSI_NVM, data, len); - return nvme_get_log(hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); + return libnvme_get_log(hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); } /** @@ -324,15 +324,15 @@ nvme_get_log_simple(struct nvme_transport_handle *hdl, * errno otherwise. */ static inline int -nvme_get_log_supported_log_pages(struct nvme_transport_handle *hdl, +nvme_get_log_supported_log_pages(struct libnvme_transport_handle *hdl, struct nvme_supported_log_pages *log) { - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; nvme_init_get_log(&cmd, NVME_NSID_ALL, NVME_LOG_LID_SUPPORTED_LOG_PAGES, NVME_CSI_NVM, log, sizeof(*log)); - return nvme_get_log(hdl, &cmd, false, sizeof(*log)); + return libnvme_get_log(hdl, &cmd, false, sizeof(*log)); } @@ -353,16 +353,16 @@ nvme_get_log_supported_log_pages(struct nvme_transport_handle *hdl, * errno otherwise. */ static inline int -nvme_get_log_error(struct nvme_transport_handle *hdl, __u32 nsid, +nvme_get_log_error(struct libnvme_transport_handle *hdl, __u32 nsid, unsigned int nr_entries, struct nvme_error_log_page *err_log) { - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; size_t len = sizeof(*err_log) * nr_entries; nvme_init_get_log(&cmd, nsid, NVME_LOG_LID_ERROR, NVME_CSI_NVM, err_log, len); - return nvme_get_log(hdl, &cmd, false, len); + return libnvme_get_log(hdl, &cmd, false, len); } /** @@ -383,15 +383,15 @@ nvme_get_log_error(struct nvme_transport_handle *hdl, __u32 nsid, * errno otherwise. */ static inline int -nvme_get_log_fw_slot(struct nvme_transport_handle *hdl, __u32 nsid, +nvme_get_log_fw_slot(struct libnvme_transport_handle *hdl, __u32 nsid, struct nvme_firmware_slot *fw_log) { - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; nvme_init_get_log(&cmd, nsid, NVME_LOG_LID_FW_SLOT, NVME_CSI_NVM, fw_log, sizeof(*fw_log)); - return nvme_get_log(hdl, &cmd, false, sizeof(*fw_log)); + return libnvme_get_log(hdl, &cmd, false, sizeof(*fw_log)); } /** @@ -413,15 +413,15 @@ nvme_get_log_fw_slot(struct nvme_transport_handle *hdl, __u32 nsid, * errno otherwise. */ static inline int -nvme_get_log_changed_ns_list(struct nvme_transport_handle *hdl, __u32 nsid, +nvme_get_log_changed_ns_list(struct libnvme_transport_handle *hdl, __u32 nsid, struct nvme_ns_list *ns_log) { - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; nvme_init_get_log(&cmd, nsid, NVME_LOG_LID_CHANGED_NS, NVME_CSI_NVM, ns_log, sizeof(*ns_log)); - return nvme_get_log(hdl, &cmd, true, sizeof(*ns_log)); + return libnvme_get_log(hdl, &cmd, true, sizeof(*ns_log)); } /** @@ -442,15 +442,15 @@ nvme_get_log_changed_ns_list(struct nvme_transport_handle *hdl, __u32 nsid, * errno otherwise. */ static inline int -nvme_get_log_cmd_effects(struct nvme_transport_handle *hdl, +nvme_get_log_cmd_effects(struct libnvme_transport_handle *hdl, enum nvme_csi csi, struct nvme_cmd_effects_log *effects_log) { - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; size_t len = sizeof(*effects_log); nvme_init_get_log_cmd_effects(&cmd, csi, effects_log); - return nvme_get_log(hdl, &cmd, false, len); + return libnvme_get_log(hdl, &cmd, false, len); } /** @@ -471,16 +471,16 @@ nvme_get_log_cmd_effects(struct nvme_transport_handle *hdl, * errno otherwise. */ static inline int -nvme_get_log_device_self_test(struct nvme_transport_handle *hdl, +nvme_get_log_device_self_test(struct libnvme_transport_handle *hdl, struct nvme_self_test_log *log) { - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; size_t len = sizeof(*log); nvme_init_get_log(&cmd, NVME_NSID_ALL, NVME_LOG_LID_DEVICE_SELF_TEST, NVME_CSI_NVM, log, len); - return nvme_get_log(hdl, &cmd, false, len); + return libnvme_get_log(hdl, &cmd, false, len); } /** @@ -503,14 +503,14 @@ nvme_get_log_device_self_test(struct nvme_transport_handle *hdl, * errno otherwise. */ static inline int -nvme_get_log_create_telemetry_host_mcda(struct nvme_transport_handle *hdl, +nvme_get_log_create_telemetry_host_mcda(struct libnvme_transport_handle *hdl, enum nvme_telemetry_da mcda, struct nvme_telemetry_log *log) { - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; nvme_init_get_log_create_telemetry_host_mcda(&cmd, mcda, log); - return nvme_get_log(hdl, &cmd, false, sizeof(*log)); + return libnvme_get_log(hdl, &cmd, false, sizeof(*log)); } /** @@ -530,14 +530,14 @@ nvme_get_log_create_telemetry_host_mcda(struct nvme_transport_handle *hdl, * errno otherwise. */ static inline int -nvme_get_log_create_telemetry_host(struct nvme_transport_handle *hdl, +nvme_get_log_create_telemetry_host(struct libnvme_transport_handle *hdl, struct nvme_telemetry_log *log) { - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; nvme_init_get_log_create_telemetry_host(&cmd, log); - return nvme_get_log(hdl, &cmd, false, sizeof(*log)); + return libnvme_get_log(hdl, &cmd, false, sizeof(*log)); } /** @@ -561,14 +561,14 @@ nvme_get_log_create_telemetry_host(struct nvme_transport_handle *hdl, * errno otherwise. */ static inline int -nvme_get_log_telemetry_host(struct nvme_transport_handle *hdl, +nvme_get_log_telemetry_host(struct libnvme_transport_handle *hdl, __u64 lpo, void *log, __u32 len) { - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; nvme_init_get_log_telemetry_host(&cmd, lpo, log, len); - return nvme_get_log(hdl, &cmd, false, len); + return libnvme_get_log(hdl, &cmd, false, len); } /** @@ -591,14 +591,14 @@ nvme_get_log_telemetry_host(struct nvme_transport_handle *hdl, * errno otherwise. */ static inline int -nvme_get_log_telemetry_ctrl(struct nvme_transport_handle *hdl, bool rae, +nvme_get_log_telemetry_ctrl(struct libnvme_transport_handle *hdl, bool rae, __u64 lpo, void *log, __u32 len) { - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; nvme_init_get_log_telemetry_ctrl(&cmd, lpo, log, len); - return nvme_get_log(hdl, &cmd, rae, len); + return libnvme_get_log(hdl, &cmd, rae, len); } /** @@ -621,14 +621,14 @@ nvme_get_log_telemetry_ctrl(struct nvme_transport_handle *hdl, bool rae, * errno otherwise. */ static inline int -nvme_get_log_endurance_group(struct nvme_transport_handle *hdl, +nvme_get_log_endurance_group(struct libnvme_transport_handle *hdl, __u16 endgid, struct nvme_endurance_group_log *log) { - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; nvme_init_get_log_endurance_group(&cmd, endgid, log); - return nvme_get_log(hdl, &cmd, false, sizeof(*log)); + return libnvme_get_log(hdl, &cmd, false, sizeof(*log)); } /** @@ -651,14 +651,14 @@ nvme_get_log_endurance_group(struct nvme_transport_handle *hdl, * errno otherwise. */ static inline int -nvme_get_log_predictable_lat_nvmset(struct nvme_transport_handle *hdl, +nvme_get_log_predictable_lat_nvmset(struct libnvme_transport_handle *hdl, __u16 nvmsetid, struct nvme_nvmset_predictable_lat_log *log) { - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; nvme_init_get_log_predictable_lat_nvmset(&cmd, nvmsetid, log); - return nvme_get_log(hdl, &cmd, false, sizeof(*log)); + return libnvme_get_log(hdl, &cmd, false, sizeof(*log)); } /** @@ -681,14 +681,14 @@ nvme_get_log_predictable_lat_nvmset(struct nvme_transport_handle *hdl, * errno otherwise. */ static inline int -nvme_get_log_predictable_lat_event(struct nvme_transport_handle *hdl, +nvme_get_log_predictable_lat_event(struct libnvme_transport_handle *hdl, bool rae, __u64 lpo, void *log, __u32 len) { - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; nvme_init_get_log_predictable_lat_event(&cmd, lpo, log, len); - return nvme_get_log(hdl, &cmd, rae, len); + return libnvme_get_log(hdl, &cmd, rae, len); } /** @@ -712,14 +712,14 @@ nvme_get_log_predictable_lat_event(struct nvme_transport_handle *hdl, * errno otherwise. */ static inline int -nvme_get_log_fdp_configurations(struct nvme_transport_handle *hdl, +nvme_get_log_fdp_configurations(struct libnvme_transport_handle *hdl, __u16 egid, __u64 lpo, void *log, __u32 len) { - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; nvme_init_get_log_fdp_configurations(&cmd, egid, lpo, log, len); - return nvme_get_log(hdl, &cmd, false, len); + return libnvme_get_log(hdl, &cmd, false, len); } /** @@ -742,14 +742,14 @@ nvme_get_log_fdp_configurations(struct nvme_transport_handle *hdl, * errno otherwise. */ static inline int -nvme_get_log_reclaim_unit_handle_usage(struct nvme_transport_handle *hdl, +nvme_get_log_reclaim_unit_handle_usage(struct libnvme_transport_handle *hdl, __u16 egid, __u64 lpo, void *log, __u32 len) { - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; nvme_init_get_log_reclaim_unit_handle_usage(&cmd, egid, lpo, log, len); - return nvme_get_log(hdl, &cmd, false, len); + return libnvme_get_log(hdl, &cmd, false, len); } /** @@ -772,14 +772,14 @@ nvme_get_log_reclaim_unit_handle_usage(struct nvme_transport_handle *hdl, * errno otherwise. */ static inline int -nvme_get_log_fdp_stats(struct nvme_transport_handle *hdl, +nvme_get_log_fdp_stats(struct libnvme_transport_handle *hdl, __u16 egid, __u64 lpo, void *log, __u32 len) { - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; nvme_init_get_log_fdp_stats(&cmd, egid, lpo, log, len); - return nvme_get_log(hdl, &cmd, false, len); + return libnvme_get_log(hdl, &cmd, false, len); } /** @@ -805,14 +805,14 @@ nvme_get_log_fdp_stats(struct nvme_transport_handle *hdl, * errno otherwise. */ static inline int -nvme_get_log_fdp_events(struct nvme_transport_handle *hdl, +nvme_get_log_fdp_events(struct libnvme_transport_handle *hdl, __u16 egid, bool host_events, __u64 lpo, void *log, __u32 len) { - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; nvme_init_get_log_fdp_events(&cmd, egid, host_events, lpo, log, len); - return nvme_get_log(hdl, &cmd, false, len); + return libnvme_get_log(hdl, &cmd, false, len); } /** @@ -837,14 +837,14 @@ nvme_get_log_fdp_events(struct nvme_transport_handle *hdl, * errno otherwise. */ static inline int -nvme_get_log_ana(struct nvme_transport_handle *hdl, bool rae, +nvme_get_log_ana(struct libnvme_transport_handle *hdl, bool rae, enum nvme_log_ana_lsp lsp, __u64 lpo, void *log, __u32 len) { - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; nvme_init_get_log_ana(&cmd, lsp, lpo, log, len); - return nvme_get_log(hdl, &cmd, rae, len); + return libnvme_get_log(hdl, &cmd, rae, len); } /** @@ -867,7 +867,7 @@ nvme_get_log_ana(struct nvme_transport_handle *hdl, bool rae, * errno otherwise. */ static inline int -nvme_get_log_ana_groups(struct nvme_transport_handle *hdl, bool rae, +nvme_get_log_ana_groups(struct libnvme_transport_handle *hdl, bool rae, struct nvme_ana_log *log, __u32 len) { return nvme_get_log_ana(hdl, rae, NVME_LOG_ANA_LSP_RGO_GROUPS_ONLY, @@ -890,14 +890,14 @@ nvme_get_log_ana_groups(struct nvme_transport_handle *hdl, bool rae, * errno otherwise. */ static inline int -nvme_get_log_lba_status(struct nvme_transport_handle *hdl, +nvme_get_log_lba_status(struct libnvme_transport_handle *hdl, bool rae, __u64 lpo, void *log, __u32 len) { - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; nvme_init_get_log_lba_status(&cmd, lpo, log, len); - return nvme_get_log(hdl, &cmd, rae, len); + return libnvme_get_log(hdl, &cmd, rae, len); } /** @@ -920,14 +920,14 @@ nvme_get_log_lba_status(struct nvme_transport_handle *hdl, * errno otherwise. */ static inline int -nvme_get_log_endurance_grp_evt(struct nvme_transport_handle *hdl, +nvme_get_log_endurance_grp_evt(struct libnvme_transport_handle *hdl, bool rae, __u64 lpo, void *log, __u32 len) { - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; nvme_init_get_log_endurance_grp_evt(&cmd, lpo, log, len); - return nvme_get_log(hdl, &cmd, rae, len); + return libnvme_get_log(hdl, &cmd, rae, len); } /** @@ -945,14 +945,14 @@ nvme_get_log_endurance_grp_evt(struct nvme_transport_handle *hdl, * errno otherwise. */ static inline int -nvme_get_log_fid_supported_effects(struct nvme_transport_handle *hdl, +nvme_get_log_fid_supported_effects(struct libnvme_transport_handle *hdl, enum nvme_csi csi, struct nvme_fid_supported_effects_log *log) { - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; nvme_init_get_log_fid_supported_effects(&cmd, csi, log); - return nvme_get_log(hdl, &cmd, false, sizeof(*log)); + return libnvme_get_log(hdl, &cmd, false, sizeof(*log)); } /** @@ -971,14 +971,14 @@ nvme_get_log_fid_supported_effects(struct nvme_transport_handle *hdl, * errno otherwise. */ static inline int -nvme_get_log_mi_cmd_supported_effects(struct nvme_transport_handle *hdl, +nvme_get_log_mi_cmd_supported_effects(struct libnvme_transport_handle *hdl, struct nvme_mi_cmd_supported_effects_log *log) { - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; nvme_init_get_log_mi_cmd_supported_effects(&cmd, log); - return nvme_get_log(hdl, &cmd, false, sizeof(*log)); + return libnvme_get_log(hdl, &cmd, false, sizeof(*log)); } /** @@ -1000,14 +1000,14 @@ nvme_get_log_mi_cmd_supported_effects(struct nvme_transport_handle *hdl, * errno otherwise. */ static inline int -nvme_get_log_boot_partition(struct nvme_transport_handle *hdl, +nvme_get_log_boot_partition(struct libnvme_transport_handle *hdl, __u8 lsp, struct nvme_boot_partition *part, __u32 len) { - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; nvme_init_get_log_boot_partition(&cmd, lsp, part, len); - return nvme_get_log(hdl, &cmd, false, len); + return libnvme_get_log(hdl, &cmd, false, len); } /** @@ -1032,15 +1032,15 @@ nvme_get_log_boot_partition(struct nvme_transport_handle *hdl, * errno otherwise. */ static inline int -nvme_get_log_rotational_media_info(struct nvme_transport_handle *hdl, +nvme_get_log_rotational_media_info(struct libnvme_transport_handle *hdl, __u16 endgid, struct nvme_rotational_media_info_log *log, __u32 len) { - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; nvme_init_get_log_rotational_media_info(&cmd, endgid, log, len); - return nvme_get_log(hdl, &cmd, false, len); + return libnvme_get_log(hdl, &cmd, false, len); } /** @@ -1061,15 +1061,15 @@ nvme_get_log_rotational_media_info(struct nvme_transport_handle *hdl, * errno otherwise. */ static inline int -nvme_get_log_dispersed_ns_participating_nss(struct nvme_transport_handle *hdl, +nvme_get_log_dispersed_ns_participating_nss(struct libnvme_transport_handle *hdl, __u32 nsid, struct nvme_dispersed_ns_participating_nss_log *log, __u32 len) { - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; nvme_init_get_log_dispersed_ns_participating_nss(&cmd, nsid, log, len); - return nvme_get_log(hdl, &cmd, false, len); + return libnvme_get_log(hdl, &cmd, false, len); } /** @@ -1090,14 +1090,14 @@ nvme_get_log_dispersed_ns_participating_nss(struct nvme_transport_handle *hdl, * errno otherwise. */ static inline int -nvme_get_log_mgmt_addr_list(struct nvme_transport_handle *hdl, +nvme_get_log_mgmt_addr_list(struct libnvme_transport_handle *hdl, struct nvme_mgmt_addr_list_log *log, __u32 len) { - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; nvme_init_get_log_mgmt_addr_list(&cmd, log, len); - return nvme_get_log(hdl, &cmd, false, len); + return libnvme_get_log(hdl, &cmd, false, len); } /** @@ -1117,14 +1117,14 @@ nvme_get_log_mgmt_addr_list(struct nvme_transport_handle *hdl, * errno otherwise. */ static inline int -nvme_get_log_power_measurement(struct nvme_transport_handle *hdl, +nvme_get_log_power_measurement(struct libnvme_transport_handle *hdl, struct nvme_power_meas_log *log, __u32 len) { - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; nvme_init_get_log_power_measurement(&cmd, log, len); - return nvme_get_log(hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); + return libnvme_get_log(hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); } /** @@ -1150,15 +1150,15 @@ nvme_get_log_power_measurement(struct nvme_transport_handle *hdl, * errno otherwise. */ static inline int -nvme_get_log_phy_rx_eom(struct nvme_transport_handle *hdl, +nvme_get_log_phy_rx_eom(struct libnvme_transport_handle *hdl, __u8 lsp, __u16 controller, struct nvme_phy_rx_eom_log *log, __u32 len) { - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; nvme_init_get_log_phy_rx_eom(&cmd, lsp, controller, log, len); - return nvme_get_log(hdl, &cmd, false, len); + return libnvme_get_log(hdl, &cmd, false, len); } /** @@ -1182,15 +1182,15 @@ nvme_get_log_phy_rx_eom(struct nvme_transport_handle *hdl, * errno otherwise. */ static inline int -nvme_get_log_reachability_groups(struct nvme_transport_handle *hdl, +nvme_get_log_reachability_groups(struct libnvme_transport_handle *hdl, __u32 nsid, bool rgo, struct nvme_reachability_groups_log *log, __u32 len) { - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; nvme_init_get_log_reachability_groups(&cmd, rgo, log, len); - return nvme_get_log(hdl, &cmd, false, len); + return libnvme_get_log(hdl, &cmd, false, len); } /** @@ -1216,15 +1216,15 @@ nvme_get_log_reachability_groups(struct nvme_transport_handle *hdl, * errno otherwise. */ static inline int -nvme_get_log_reachability_associations(struct nvme_transport_handle *hdl, +nvme_get_log_reachability_associations(struct libnvme_transport_handle *hdl, bool rae, bool rao, struct nvme_reachability_associations_log *log, __u32 len) { - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; nvme_init_get_log_reachability_associations(&cmd, rao, log, len); - return nvme_get_log(hdl, &cmd, rae, len); + return libnvme_get_log(hdl, &cmd, rae, len); } /** @@ -1245,14 +1245,14 @@ nvme_get_log_reachability_associations(struct nvme_transport_handle *hdl, * errno otherwise. */ static inline int -nvme_get_log_changed_alloc_ns_list(struct nvme_transport_handle *hdl, +nvme_get_log_changed_alloc_ns_list(struct libnvme_transport_handle *hdl, struct nvme_ns_list *log, __u32 len) { - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; nvme_init_get_log_changed_ns(&cmd, log); - return nvme_get_log(hdl, &cmd, true, len); + return libnvme_get_log(hdl, &cmd, true, len); } /** @@ -1271,14 +1271,14 @@ nvme_get_log_changed_alloc_ns_list(struct nvme_transport_handle *hdl, * errno otherwise. */ static inline int -nvme_get_log_discovery(struct nvme_transport_handle *hdl, +nvme_get_log_discovery(struct libnvme_transport_handle *hdl, __u64 lpo, __u32 len, void *log) { - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; nvme_init_get_log_discovery(&cmd, lpo, log, len); - return nvme_get_log(hdl, &cmd, false, len); + return libnvme_get_log(hdl, &cmd, false, len); } /** @@ -1300,15 +1300,15 @@ nvme_get_log_discovery(struct nvme_transport_handle *hdl, * errno otherwise. */ static inline int -nvme_get_log_host_discovery(struct nvme_transport_handle *hdl, +nvme_get_log_host_discovery(struct libnvme_transport_handle *hdl, bool rae, bool allhoste, struct nvme_host_discover_log *log, __u32 len) { - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; nvme_init_get_log_host_discovery(&cmd, allhoste, log, len); - return nvme_get_log(hdl, &cmd, false, len); + return libnvme_get_log(hdl, &cmd, false, len); } /** @@ -1327,14 +1327,14 @@ nvme_get_log_host_discovery(struct nvme_transport_handle *hdl, * errno otherwise. */ static inline int -nvme_get_log_ave_discovery(struct nvme_transport_handle *hdl, +nvme_get_log_ave_discovery(struct libnvme_transport_handle *hdl, bool rae, struct nvme_ave_discover_log *log, __u32 len) { - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; nvme_init_get_log_ave_discovery(&cmd, log, len); - return nvme_get_log(hdl, &cmd, rae, len); + return libnvme_get_log(hdl, &cmd, rae, len); } /** @@ -1353,14 +1353,14 @@ nvme_get_log_ave_discovery(struct nvme_transport_handle *hdl, * errno otherwise. */ static inline int -nvme_get_log_pull_model_ddc_req(struct nvme_transport_handle *hdl, +nvme_get_log_pull_model_ddc_req(struct libnvme_transport_handle *hdl, bool rae, struct nvme_pull_model_ddc_req_log *log, __u32 len) { - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; nvme_init_get_log_pull_model_ddc_req(&cmd, log, len); - return nvme_get_log(hdl, &cmd, rae, len); + return libnvme_get_log(hdl, &cmd, rae, len); } /** @@ -1384,14 +1384,14 @@ nvme_get_log_pull_model_ddc_req(struct nvme_transport_handle *hdl, * errno otherwise. */ static inline int -nvme_get_log_media_unit_stat(struct nvme_transport_handle *hdl, +nvme_get_log_media_unit_stat(struct libnvme_transport_handle *hdl, __u16 domid, struct nvme_media_unit_stat_log *mus) { - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; nvme_init_get_log_media_unit_stat(&cmd, domid, mus); - return nvme_get_log(hdl, &cmd, false, sizeof(*mus)); + return libnvme_get_log(hdl, &cmd, false, sizeof(*mus)); } /** @@ -1417,14 +1417,14 @@ nvme_get_log_media_unit_stat(struct nvme_transport_handle *hdl, * errno otherwise. */ static inline int -nvme_get_log_support_cap_config_list(struct nvme_transport_handle *hdl, +nvme_get_log_support_cap_config_list(struct libnvme_transport_handle *hdl, __u16 domid, struct nvme_supported_cap_config_list_log *cap) { - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; nvme_init_get_log_support_cap_config_list(&cmd, domid, cap); - return nvme_get_log(hdl, &cmd, false, sizeof(*cap)); + return libnvme_get_log(hdl, &cmd, false, sizeof(*cap)); } /** @@ -1440,14 +1440,14 @@ nvme_get_log_support_cap_config_list(struct nvme_transport_handle *hdl, * errno otherwise. */ static inline int -nvme_get_log_reservation(struct nvme_transport_handle *hdl, +nvme_get_log_reservation(struct libnvme_transport_handle *hdl, struct nvme_resv_notification_log *log) { - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; nvme_init_get_log_reservation(&cmd, log); - return nvme_get_log(hdl, &cmd, false, sizeof(*log)); + return libnvme_get_log(hdl, &cmd, false, sizeof(*log)); } /** @@ -1467,14 +1467,14 @@ nvme_get_log_reservation(struct nvme_transport_handle *hdl, * errno otherwise. */ static inline int -nvme_get_log_sanitize(struct nvme_transport_handle *hdl, +nvme_get_log_sanitize(struct libnvme_transport_handle *hdl, bool rae, struct nvme_sanitize_log_page *log) { - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; nvme_init_get_log_sanitize(&cmd, log); - return nvme_get_log(hdl, &cmd, rae, sizeof(*log)); + return libnvme_get_log(hdl, &cmd, rae, sizeof(*log)); } /** @@ -1495,14 +1495,14 @@ nvme_get_log_sanitize(struct nvme_transport_handle *hdl, * errno otherwise. */ static inline int -nvme_get_log_zns_changed_zones(struct nvme_transport_handle *hdl, +nvme_get_log_zns_changed_zones(struct libnvme_transport_handle *hdl, __u32 nsid, bool rae, struct nvme_zns_changed_zone_log *log) { - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; nvme_init_get_log_zns_changed_zones(&cmd, nsid, log); - return nvme_get_log(hdl, &cmd, rae, sizeof(*log)); + return libnvme_get_log(hdl, &cmd, rae, sizeof(*log)); } /** @@ -1523,10 +1523,10 @@ nvme_get_log_zns_changed_zones(struct nvme_transport_handle *hdl, * errno otherwise. */ static inline int -nvme_get_log_persistent_event(struct nvme_transport_handle *hdl, +nvme_get_log_persistent_event(struct libnvme_transport_handle *hdl, enum nvme_pevent_log_action action, void *pevent_log, __u32 len) { - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; nvme_init_get_log_persistent_event(&cmd, action, pevent_log, len); @@ -1534,7 +1534,7 @@ nvme_get_log_persistent_event(struct nvme_transport_handle *hdl, * Call the generic log execution function. * The data length is determined by the 'len' parameter. */ - return nvme_get_log(hdl, &cmd, false, len); + return libnvme_get_log(hdl, &cmd, false, len); } /** @@ -1557,14 +1557,14 @@ nvme_get_log_persistent_event(struct nvme_transport_handle *hdl, * errno otherwise. */ static inline int -nvme_get_log_lockdown(struct nvme_transport_handle *hdl, +nvme_get_log_lockdown(struct libnvme_transport_handle *hdl, __u8 cnscp, struct nvme_lockdown_log *log) { - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; nvme_init_get_log_lockdown(&cmd, cnscp, log); - return nvme_get_log(hdl, &cmd, false, sizeof(*log)); + return libnvme_get_log(hdl, &cmd, false, sizeof(*log)); } /** @@ -1582,14 +1582,14 @@ nvme_get_log_lockdown(struct nvme_transport_handle *hdl, * errno otherwise. */ static inline int -nvme_get_log_smart(struct nvme_transport_handle *hdl, +nvme_get_log_smart(struct libnvme_transport_handle *hdl, __u32 nsid, struct nvme_smart_log *smart_log) { - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; nvme_init_get_log_smart(&cmd, nsid, smart_log); - return nvme_get_log(hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); + return libnvme_get_log(hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); } @@ -1616,11 +1616,11 @@ nvme_get_log_smart(struct nvme_transport_handle *hdl, * errno otherwise. */ static inline int -nvme_set_features(struct nvme_transport_handle *hdl, __u32 nsid, __u8 fid, +nvme_set_features(struct libnvme_transport_handle *hdl, __u32 nsid, __u8 fid, bool sv, __u32 cdw11, __u32 cdw12, __u32 cdw13, __u8 uidx, __u32 cdw15, void *data, __u32 len, __u64 *result) { - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; nvme_init_set_features(&cmd, fid, sv); @@ -1635,7 +1635,7 @@ nvme_set_features(struct nvme_transport_handle *hdl, __u32 nsid, __u8 fid, cmd.data_len = len; cmd.addr = (__u64)(uintptr_t)data; - err = nvme_submit_admin_passthru(hdl, &cmd); + err = libnvme_submit_admin_passthru(hdl, &cmd); if (result) *result = cmd.result; return err; @@ -1658,17 +1658,17 @@ nvme_set_features(struct nvme_transport_handle *hdl, __u32 nsid, __u8 fid, * errno otherwise. */ static inline int -nvme_set_features_simple(struct nvme_transport_handle *hdl, +nvme_set_features_simple(struct libnvme_transport_handle *hdl, __u32 nsid, __u8 fid, bool sv, __u32 cdw11, __u64 *result) { - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; nvme_init_set_features(&cmd, fid, sv); cmd.nsid = nsid; cmd.cdw11 = cdw11; - err = nvme_submit_admin_passthru(hdl, &cmd); + err = libnvme_submit_admin_passthru(hdl, &cmd); if (result) *result = cmd.result; return err; @@ -1691,12 +1691,12 @@ nvme_set_features_simple(struct nvme_transport_handle *hdl, * errno otherwise. */ static inline int -nvme_get_features(struct nvme_transport_handle *hdl, __u32 nsid, +nvme_get_features(struct libnvme_transport_handle *hdl, __u32 nsid, __u8 fid, enum nvme_get_features_sel sel, __u32 cdw11, __u8 uidx, void *data, __u32 len, __u64 *result) { - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; nvme_init_get_features(&cmd, fid, sel); @@ -1709,7 +1709,7 @@ nvme_get_features(struct nvme_transport_handle *hdl, __u32 nsid, cmd.data_len = len; cmd.addr = (__u64)(uintptr_t)data; - err = nvme_submit_admin_passthru(hdl, &cmd); + err = libnvme_submit_admin_passthru(hdl, &cmd); if (result) *result = cmd.result; return err; @@ -1730,15 +1730,15 @@ nvme_get_features(struct nvme_transport_handle *hdl, __u32 nsid, * errno otherwise. */ static inline int -nvme_get_features_simple(struct nvme_transport_handle *hdl, __u8 fid, +nvme_get_features_simple(struct libnvme_transport_handle *hdl, __u8 fid, enum nvme_get_features_sel sel, __u64 *result) { - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; nvme_init_get_features(&cmd, fid, sel); - err = nvme_submit_admin_passthru(hdl, &cmd); + err = libnvme_submit_admin_passthru(hdl, &cmd); if (result) *result = cmd.result; return err; @@ -1755,7 +1755,7 @@ nvme_get_features_simple(struct nvme_transport_handle *hdl, __u8 fid, * 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(struct nvme_transport_handle *hdl, bool ish, +int nvme_namespace_attach_ctrls(struct libnvme_transport_handle *hdl, bool ish, __u32 nsid, __u16 num_ctrls, __u16 *ctrlist); /** @@ -1769,7 +1769,7 @@ int nvme_namespace_attach_ctrls(struct nvme_transport_handle *hdl, bool ish, * 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(struct nvme_transport_handle *hdl, bool ish, +int nvme_namespace_detach_ctrls(struct libnvme_transport_handle *hdl, bool ish, __u32 nsid, __u16 num_ctrls, __u16 *ctrlist); diff --git a/nvme-models.c b/nvme-models.c index eafbb629f1..4a94906deb 100644 --- a/nvme-models.c +++ b/nvme-models.c @@ -246,7 +246,7 @@ static int read_sys_node(char *where, char *save, size_t savesz) fd = open(where, O_RDONLY); if (fd < 0) { fprintf(stderr, "Failed to open %s with errno %s\n", - where, nvme_strerror(errno)); + where, libnvme_strerror(errno)); return 1; } /* -1 so we can safely use strstr below */ @@ -329,7 +329,7 @@ char *nvme_product_name(int id) line = malloc(1024); if (!line) { - fprintf(stderr, "malloc: %s\n", nvme_strerror(errno)); + fprintf(stderr, "malloc: %s\n", libnvme_strerror(errno)); goto error0; } diff --git a/nvme-print-json.c b/nvme-print-json.c index 4b58ad25c9..57b956fbcb 100644 --- a/nvme-print-json.c +++ b/nvme-print-json.c @@ -2663,26 +2663,26 @@ static void json_nvme_fdp_ruh_status(struct nvme_fdp_ruh_status *status, size_t json_print(r); } -static unsigned int json_print_nvme_subsystem_multipath(nvme_subsystem_t s, json_object *paths) +static unsigned int json_print_nvme_subsystem_multipath(libnvme_subsystem_t s, json_object *paths) { - nvme_ns_t n; - nvme_path_t p; + libnvme_ns_t n; + libnvme_path_t p; unsigned int i = 0; - n = nvme_subsystem_first_ns(s); + n = libnvme_subsystem_first_ns(s); if (!n) return 0; - nvme_namespace_for_each_path(n, p) { + libnvme_namespace_for_each_path(n, p) { struct json_object *path_attrs; - nvme_ctrl_t c = nvme_path_get_ctrl(p); + libnvme_ctrl_t c = libnvme_path_get_ctrl(p); path_attrs = json_create_object(); - obj_add_str(path_attrs, "Name", nvme_ctrl_get_name(c)); - obj_add_str(path_attrs, "Transport", nvme_ctrl_get_transport(c)); - obj_add_str(path_attrs, "Address", nvme_ctrl_get_traddr(c)); - obj_add_str(path_attrs, "State", nvme_ctrl_get_state(c)); - obj_add_str(path_attrs, "ANAState", nvme_path_get_ana_state(p)); + obj_add_str(path_attrs, "Name", libnvme_ctrl_get_name(c)); + obj_add_str(path_attrs, "Transport", libnvme_ctrl_get_transport(c)); + obj_add_str(path_attrs, "Address", libnvme_ctrl_get_traddr(c)); + obj_add_str(path_attrs, "State", libnvme_ctrl_get_state(c)); + obj_add_str(path_attrs, "ANAState", libnvme_path_get_ana_state(p)); array_add_obj(paths, path_attrs); i++; } @@ -2690,65 +2690,65 @@ static unsigned int json_print_nvme_subsystem_multipath(nvme_subsystem_t s, json return i; } -static void json_print_nvme_subsystem_ctrls(nvme_subsystem_t s, +static void json_print_nvme_subsystem_ctrls(libnvme_subsystem_t s, json_object *paths) { - nvme_ctrl_t c; + libnvme_ctrl_t c; - nvme_subsystem_for_each_ctrl(s, c) { + libnvme_subsystem_for_each_ctrl(s, c) { struct json_object *path_attrs; path_attrs = json_create_object(); - obj_add_str(path_attrs, "Name", nvme_ctrl_get_name(c)); - obj_add_str(path_attrs, "Transport", nvme_ctrl_get_transport(c)); - obj_add_str(path_attrs, "Address", nvme_ctrl_get_traddr(c)); - obj_add_str(path_attrs, "State", nvme_ctrl_get_state(c)); + obj_add_str(path_attrs, "Name", libnvme_ctrl_get_name(c)); + obj_add_str(path_attrs, "Transport", libnvme_ctrl_get_transport(c)); + obj_add_str(path_attrs, "Address", libnvme_ctrl_get_traddr(c)); + obj_add_str(path_attrs, "State", libnvme_ctrl_get_state(c)); array_add_obj(paths, path_attrs); } } -static void json_print_nvme_subsystem_list(struct nvme_global_ctx *ctx, +static void json_print_nvme_subsystem_list(struct libnvme_global_ctx *ctx, bool show_ana) { struct json_object *host_attrs, *subsystem_attrs; struct json_object *subsystems, *paths; struct json_object *a = json_create_array(); - nvme_host_t h; + libnvme_host_t h; - nvme_for_each_host(ctx, h) { - nvme_subsystem_t s; + libnvme_for_each_host(ctx, h) { + libnvme_subsystem_t s; const char *hostid; host_attrs = json_create_object(); - obj_add_str(host_attrs, "HostNQN", nvme_host_get_hostnqn(h)); - hostid = nvme_host_get_hostid(h); + obj_add_str(host_attrs, "HostNQN", libnvme_host_get_hostnqn(h)); + hostid = libnvme_host_get_hostid(h); if (hostid) obj_add_str(host_attrs, "HostID", hostid); subsystems = json_create_array(); - nvme_for_each_subsystem(h, s) { - nvme_ctrl_t c; + libnvme_for_each_subsystem(h, s) { + libnvme_ctrl_t c; bool no_ctrl = true; - nvme_subsystem_for_each_ctrl(s, c) + libnvme_subsystem_for_each_ctrl(s, c) no_ctrl = false; if (no_ctrl) continue; subsystem_attrs = json_create_object(); - obj_add_str(subsystem_attrs, "Name", nvme_subsystem_get_name(s)); - obj_add_str(subsystem_attrs, "NQN", nvme_subsystem_get_subsysnqn(s)); + obj_add_str(subsystem_attrs, "Name", libnvme_subsystem_get_name(s)); + obj_add_str(subsystem_attrs, "NQN", libnvme_subsystem_get_subsysnqn(s)); if (verbose_mode()) { obj_add_str(subsystem_attrs, "Model", - nvme_subsystem_get_model(s)); + libnvme_subsystem_get_model(s)); obj_add_str(subsystem_attrs, "Serial", - nvme_subsystem_get_serial(s)); + libnvme_subsystem_get_serial(s)); obj_add_str(subsystem_attrs, "Firmware", - nvme_subsystem_get_firmware(s)); + libnvme_subsystem_get_firmware(s)); obj_add_str(subsystem_attrs, "IOPolicy", - nvme_subsystem_get_iopolicy(s)); + libnvme_subsystem_get_iopolicy(s)); obj_add_str(subsystem_attrs, "Type", - nvme_subsystem_get_subsystype(s)); + libnvme_subsystem_get_subsystype(s)); } array_add_obj(subsystems, subsystem_attrs); @@ -3276,7 +3276,7 @@ static void json_nvme_id_ns_descs(void *data, unsigned int nsid) break; case NVME_NIDT_UUID: memcpy(desc.uuid, data + off, sizeof(desc.uuid)); - nvme_uuid_to_string(desc.uuid, json_str); + libnvme_uuid_to_string(desc.uuid, json_str); len = sizeof(desc.uuid); nidt_name = "uuid"; break; @@ -4609,50 +4609,50 @@ static void json_support_log(struct nvme_supported_log_pages *support_log, json_print(r); } -static void json_print_detail_list_multipath(nvme_subsystem_t s, +static void json_print_detail_list_multipath(libnvme_subsystem_t s, struct json_object *jss) { - nvme_ns_t n; - nvme_path_t p; + libnvme_ns_t n; + libnvme_path_t p; struct json_object *jnss = json_create_array(); - nvme_subsystem_for_each_ns(s, n) { + libnvme_subsystem_for_each_ns(s, n) { struct json_object *jns = json_create_object(); struct json_object *jpaths = json_create_array(); - int lba = nvme_ns_get_lba_size(n); - uint64_t nsze = nvme_ns_get_lba_count(n) * lba; - uint64_t nuse = nvme_ns_get_lba_util(n) * lba; + int lba = libnvme_ns_get_lba_size(n); + uint64_t nsze = libnvme_ns_get_lba_count(n) * lba; + uint64_t nuse = libnvme_ns_get_lba_util(n) * lba; - obj_add_str(jns, "NameSpace", nvme_ns_get_name(n)); - obj_add_str(jns, "Generic", nvme_ns_get_generic_name(n)); - obj_add_int(jns, "NSID", nvme_ns_get_nsid(n)); + obj_add_str(jns, "NameSpace", libnvme_ns_get_name(n)); + obj_add_str(jns, "Generic", libnvme_ns_get_generic_name(n)); + obj_add_int(jns, "NSID", libnvme_ns_get_nsid(n)); obj_add_uint64(jns, "UsedBytes", nuse); - obj_add_uint64(jns, "MaximumLBA", nvme_ns_get_lba_count(n)); + obj_add_uint64(jns, "MaximumLBA", libnvme_ns_get_lba_count(n)); obj_add_uint64(jns, "PhysicalSize", nsze); obj_add_int(jns, "SectorSize", lba); - nvme_namespace_for_each_path(n, p) { - nvme_ctrl_t c; + libnvme_namespace_for_each_path(n, p) { + libnvme_ctrl_t c; struct json_object *jpath = json_create_object(); - obj_add_str(jpath, "Path", nvme_path_get_name(p)); - obj_add_str(jpath, "ANAState", nvme_path_get_ana_state(p)); + obj_add_str(jpath, "Path", libnvme_path_get_name(p)); + obj_add_str(jpath, "ANAState", libnvme_path_get_ana_state(p)); /* * For multipath, each path maps to one controller. * So get the controller from the path and then add * controller attributes. */ - c = nvme_path_get_ctrl(p); - obj_add_str(jpath, "Controller", nvme_ctrl_get_name(c)); - obj_add_str(jpath, "Cntlid", nvme_ctrl_get_cntlid(c)); - obj_add_str(jpath, "SerialNumber", nvme_ctrl_get_serial(c)); - obj_add_str(jpath, "ModelNumber", nvme_ctrl_get_model(c)); - obj_add_str(jpath, "Firmware", nvme_ctrl_get_firmware(c)); - obj_add_str(jpath, "Transport", nvme_ctrl_get_transport(c)); - obj_add_str(jpath, "Address", nvme_ctrl_get_traddr(c)); - obj_add_str(jpath, "Slot", nvme_ctrl_get_phy_slot(c)); + c = libnvme_path_get_ctrl(p); + obj_add_str(jpath, "Controller", libnvme_ctrl_get_name(c)); + obj_add_str(jpath, "Cntlid", libnvme_ctrl_get_cntlid(c)); + obj_add_str(jpath, "SerialNumber", libnvme_ctrl_get_serial(c)); + obj_add_str(jpath, "ModelNumber", libnvme_ctrl_get_model(c)); + obj_add_str(jpath, "Firmware", libnvme_ctrl_get_firmware(c)); + obj_add_str(jpath, "Transport", libnvme_ctrl_get_transport(c)); + obj_add_str(jpath, "Address", libnvme_ctrl_get_traddr(c)); + obj_add_str(jpath, "Slot", libnvme_ctrl_get_phy_slot(c)); array_add_obj(jpaths, jpath); } @@ -4663,36 +4663,36 @@ static void json_print_detail_list_multipath(nvme_subsystem_t s, obj_add_obj(jss, "Namespaces", jnss); } -static void json_print_detail_list(nvme_subsystem_t s, struct json_object *jss) +static void json_print_detail_list(libnvme_subsystem_t s, struct json_object *jss) { - nvme_ctrl_t c; - nvme_ns_t n; + libnvme_ctrl_t c; + libnvme_ns_t n; struct json_object *jctrls = json_create_array(); - nvme_subsystem_for_each_ctrl(s, c) { + libnvme_subsystem_for_each_ctrl(s, c) { struct json_object *jctrl = json_create_object(); struct json_object *jnss = json_create_array(); - obj_add_str(jctrl, "Controller", nvme_ctrl_get_name(c)); - obj_add_str(jctrl, "Cntlid", nvme_ctrl_get_cntlid(c)); - obj_add_str(jctrl, "SerialNumber", nvme_ctrl_get_serial(c)); - obj_add_str(jctrl, "ModelNumber", nvme_ctrl_get_model(c)); - obj_add_str(jctrl, "Firmware", nvme_ctrl_get_firmware(c)); - obj_add_str(jctrl, "Transport", nvme_ctrl_get_transport(c)); - obj_add_str(jctrl, "Address", nvme_ctrl_get_traddr(c)); - obj_add_str(jctrl, "Slot", nvme_ctrl_get_phy_slot(c)); + obj_add_str(jctrl, "Controller", libnvme_ctrl_get_name(c)); + obj_add_str(jctrl, "Cntlid", libnvme_ctrl_get_cntlid(c)); + obj_add_str(jctrl, "SerialNumber", libnvme_ctrl_get_serial(c)); + obj_add_str(jctrl, "ModelNumber", libnvme_ctrl_get_model(c)); + obj_add_str(jctrl, "Firmware", libnvme_ctrl_get_firmware(c)); + obj_add_str(jctrl, "Transport", libnvme_ctrl_get_transport(c)); + obj_add_str(jctrl, "Address", libnvme_ctrl_get_traddr(c)); + obj_add_str(jctrl, "Slot", libnvme_ctrl_get_phy_slot(c)); - nvme_ctrl_for_each_ns(c, n) { + libnvme_ctrl_for_each_ns(c, n) { struct json_object *jns = json_create_object(); - int lba = nvme_ns_get_lba_size(n); - uint64_t nsze = nvme_ns_get_lba_count(n) * lba; - uint64_t nuse = nvme_ns_get_lba_util(n) * lba; + int lba = libnvme_ns_get_lba_size(n); + uint64_t nsze = libnvme_ns_get_lba_count(n) * lba; + uint64_t nuse = libnvme_ns_get_lba_util(n) * lba; - obj_add_str(jns, "NameSpace", nvme_ns_get_name(n)); - obj_add_str(jns, "Generic", nvme_ns_get_generic_name(n)); - obj_add_int(jns, "NSID", nvme_ns_get_nsid(n)); + obj_add_str(jns, "NameSpace", libnvme_ns_get_name(n)); + obj_add_str(jns, "Generic", libnvme_ns_get_generic_name(n)); + obj_add_int(jns, "NSID", libnvme_ns_get_nsid(n)); obj_add_uint64(jns, "UsedBytes", nuse); - obj_add_uint64(jns, "MaximumLBA", nvme_ns_get_lba_count(n)); + obj_add_uint64(jns, "MaximumLBA", libnvme_ns_get_lba_count(n)); obj_add_uint64(jns, "PhysicalSize", nsze); obj_add_int(jns, "SectorSize", lba); @@ -4706,29 +4706,29 @@ static void json_print_detail_list(nvme_subsystem_t s, struct json_object *jss) obj_add_obj(jss, "Controllers", jctrls); } -static void json_detail_list_v2(struct nvme_global_ctx *ctx) +static void json_detail_list_v2(struct libnvme_global_ctx *ctx) { struct json_object *r = json_create_object(); struct json_object *jdev = json_create_array(); - nvme_host_t h; - nvme_subsystem_t s; + libnvme_host_t h; + libnvme_subsystem_t s; - nvme_for_each_host(ctx, h) { + libnvme_for_each_host(ctx, h) { struct json_object *hss = json_create_object(); struct json_object *jsslist = json_create_array(); const char *hostid; - obj_add_str(hss, "HostNQN", nvme_host_get_hostnqn(h)); - hostid = nvme_host_get_hostid(h); + obj_add_str(hss, "HostNQN", libnvme_host_get_hostnqn(h)); + hostid = libnvme_host_get_hostid(h); if (hostid) obj_add_str(hss, "HostID", hostid); - nvme_for_each_subsystem(h, s) { + libnvme_for_each_subsystem(h, s) { struct json_object *jss = json_create_object(); - obj_add_str(jss, "Subsystem", nvme_subsystem_get_name(s)); - obj_add_str(jss, "SubsystemNQN", nvme_subsystem_get_subsysnqn(s)); + obj_add_str(jss, "Subsystem", libnvme_subsystem_get_name(s)); + obj_add_str(jss, "SubsystemNQN", libnvme_subsystem_get_subsysnqn(s)); if (nvme_is_multipath(s)) json_print_detail_list_multipath(s, jss); @@ -4747,60 +4747,60 @@ static void json_detail_list_v2(struct nvme_global_ctx *ctx) json_print(r); } -static void json_detail_list(struct nvme_global_ctx *ctx) +static void json_detail_list(struct libnvme_global_ctx *ctx) { struct json_object *r = json_create_object(); struct json_object *jdev = json_create_array(); - nvme_host_t h; - nvme_subsystem_t s; - nvme_ctrl_t c; - nvme_path_t p; - nvme_ns_t n; + libnvme_host_t h; + libnvme_subsystem_t s; + libnvme_ctrl_t c; + libnvme_path_t p; + libnvme_ns_t n; - nvme_for_each_host(ctx, h) { + libnvme_for_each_host(ctx, h) { struct json_object *hss = json_create_object(); struct json_object *jsslist = json_create_array(); const char *hostid; - obj_add_str(hss, "HostNQN", nvme_host_get_hostnqn(h)); - hostid = nvme_host_get_hostid(h); + obj_add_str(hss, "HostNQN", libnvme_host_get_hostnqn(h)); + hostid = libnvme_host_get_hostid(h); if (hostid) obj_add_str(hss, "HostID", hostid); - nvme_for_each_subsystem(h, s) { + libnvme_for_each_subsystem(h, s) { struct json_object *jss = json_create_object(); struct json_object *jctrls = json_create_array(); struct json_object *jnss = json_create_array(); - obj_add_str(jss, "Subsystem", nvme_subsystem_get_name(s)); - obj_add_str(jss, "SubsystemNQN", nvme_subsystem_get_subsysnqn(s)); + obj_add_str(jss, "Subsystem", libnvme_subsystem_get_name(s)); + obj_add_str(jss, "SubsystemNQN", libnvme_subsystem_get_subsysnqn(s)); - nvme_subsystem_for_each_ctrl(s, c) { + libnvme_subsystem_for_each_ctrl(s, c) { struct json_object *jctrl = json_create_object(); struct json_object *jnss = json_create_array(); struct json_object *jpaths = json_create_array(); - obj_add_str(jctrl, "Controller", nvme_ctrl_get_name(c)); - obj_add_str(jctrl, "Cntlid", nvme_ctrl_get_cntlid(c)); - obj_add_str(jctrl, "SerialNumber", nvme_ctrl_get_serial(c)); - obj_add_str(jctrl, "ModelNumber", nvme_ctrl_get_model(c)); - obj_add_str(jctrl, "Firmware", nvme_ctrl_get_firmware(c)); - obj_add_str(jctrl, "Transport", nvme_ctrl_get_transport(c)); - obj_add_str(jctrl, "Address", nvme_ctrl_get_traddr(c)); - obj_add_str(jctrl, "Slot", nvme_ctrl_get_phy_slot(c)); + obj_add_str(jctrl, "Controller", libnvme_ctrl_get_name(c)); + obj_add_str(jctrl, "Cntlid", libnvme_ctrl_get_cntlid(c)); + obj_add_str(jctrl, "SerialNumber", libnvme_ctrl_get_serial(c)); + obj_add_str(jctrl, "ModelNumber", libnvme_ctrl_get_model(c)); + obj_add_str(jctrl, "Firmware", libnvme_ctrl_get_firmware(c)); + obj_add_str(jctrl, "Transport", libnvme_ctrl_get_transport(c)); + obj_add_str(jctrl, "Address", libnvme_ctrl_get_traddr(c)); + obj_add_str(jctrl, "Slot", libnvme_ctrl_get_phy_slot(c)); - nvme_ctrl_for_each_ns(c, n) { + libnvme_ctrl_for_each_ns(c, n) { struct json_object *jns = json_create_object(); - int lba = nvme_ns_get_lba_size(n); - uint64_t nsze = nvme_ns_get_lba_count(n) * lba; - uint64_t nuse = nvme_ns_get_lba_util(n) * lba; + int lba = libnvme_ns_get_lba_size(n); + uint64_t nsze = libnvme_ns_get_lba_count(n) * lba; + uint64_t nuse = libnvme_ns_get_lba_util(n) * lba; - obj_add_str(jns, "NameSpace", nvme_ns_get_name(n)); - obj_add_str(jns, "Generic", nvme_ns_get_generic_name(n)); - obj_add_int(jns, "NSID", nvme_ns_get_nsid(n)); + obj_add_str(jns, "NameSpace", libnvme_ns_get_name(n)); + obj_add_str(jns, "Generic", libnvme_ns_get_generic_name(n)); + obj_add_int(jns, "NSID", libnvme_ns_get_nsid(n)); obj_add_uint64(jns, "UsedBytes", nuse); - obj_add_uint64(jns, "MaximumLBA", nvme_ns_get_lba_count(n)); + obj_add_uint64(jns, "MaximumLBA", libnvme_ns_get_lba_count(n)); obj_add_uint64(jns, "PhysicalSize", nsze); obj_add_int(jns, "SectorSize", lba); @@ -4808,11 +4808,11 @@ static void json_detail_list(struct nvme_global_ctx *ctx) } obj_add_obj(jctrl, "Namespaces", jnss); - nvme_ctrl_for_each_path(c, p) { + libnvme_ctrl_for_each_path(c, p) { struct json_object *jpath = json_create_object(); - obj_add_str(jpath, "Path", nvme_path_get_name(p)); - obj_add_str(jpath, "ANAState", nvme_path_get_ana_state(p)); + obj_add_str(jpath, "Path", libnvme_path_get_name(p)); + obj_add_str(jpath, "ANAState", libnvme_path_get_ana_state(p)); array_add_obj(jpaths, jpath); } @@ -4822,18 +4822,18 @@ static void json_detail_list(struct nvme_global_ctx *ctx) } obj_add_obj(jss, "Controllers", jctrls); - nvme_subsystem_for_each_ns(s, n) { + libnvme_subsystem_for_each_ns(s, n) { struct json_object *jns = json_create_object(); - int lba = nvme_ns_get_lba_size(n); - uint64_t nsze = nvme_ns_get_lba_count(n) * lba; - uint64_t nuse = nvme_ns_get_lba_util(n) * lba; + int lba = libnvme_ns_get_lba_size(n); + uint64_t nsze = libnvme_ns_get_lba_count(n) * lba; + uint64_t nuse = libnvme_ns_get_lba_util(n) * lba; - obj_add_str(jns, "NameSpace", nvme_ns_get_name(n)); - obj_add_str(jns, "Generic", nvme_ns_get_generic_name(n)); - obj_add_int(jns, "NSID", nvme_ns_get_nsid(n)); + obj_add_str(jns, "NameSpace", libnvme_ns_get_name(n)); + obj_add_str(jns, "Generic", libnvme_ns_get_generic_name(n)); + obj_add_int(jns, "NSID", libnvme_ns_get_nsid(n)); obj_add_uint64(jns, "UsedBytes", nuse); - obj_add_uint64(jns, "MaximumLBA", nvme_ns_get_lba_count(n)); + obj_add_uint64(jns, "MaximumLBA", libnvme_ns_get_lba_count(n)); obj_add_uint64(jns, "PhysicalSize", nsze); obj_add_int(jns, "SectorSize", lba); @@ -4853,49 +4853,49 @@ static void json_detail_list(struct nvme_global_ctx *ctx) json_print(r); } -static struct json_object *json_list_item_obj(nvme_ns_t n) +static struct json_object *json_list_item_obj(libnvme_ns_t n) { struct json_object *r = json_create_object(); char devname[NAME_LEN] = { 0 }; char genname[NAME_LEN] = { 0 }; - int lba = nvme_ns_get_lba_size(n); - uint64_t nsze = nvme_ns_get_lba_count(n) * lba; - uint64_t nuse = nvme_ns_get_lba_util(n) * lba; + int lba = libnvme_ns_get_lba_size(n); + uint64_t nsze = libnvme_ns_get_lba_count(n) * lba; + uint64_t nuse = libnvme_ns_get_lba_util(n) * lba; nvme_dev_full_path(n, devname, sizeof(devname)); nvme_generic_full_path(n, genname, sizeof(genname)); - obj_add_int(r, "NameSpace", nvme_ns_get_nsid(n)); + obj_add_int(r, "NameSpace", libnvme_ns_get_nsid(n)); obj_add_str(r, "DevicePath", devname); obj_add_str(r, "GenericPath", genname); - obj_add_str(r, "Firmware", nvme_ns_get_firmware(n)); - obj_add_str(r, "ModelNumber", nvme_ns_get_model(n)); - obj_add_str(r, "SerialNumber", nvme_ns_get_serial(n)); + obj_add_str(r, "Firmware", libnvme_ns_get_firmware(n)); + obj_add_str(r, "ModelNumber", libnvme_ns_get_model(n)); + obj_add_str(r, "SerialNumber", libnvme_ns_get_serial(n)); obj_add_uint64(r, "UsedBytes", nuse); - obj_add_uint64(r, "MaximumLBA", nvme_ns_get_lba_count(n)); + obj_add_uint64(r, "MaximumLBA", libnvme_ns_get_lba_count(n)); obj_add_uint64(r, "PhysicalSize", nsze); obj_add_int(r, "SectorSize", lba); return r; } -static void json_simple_list(struct nvme_global_ctx *ctx) +static void json_simple_list(struct libnvme_global_ctx *ctx) { struct json_object *r = json_create_object(); struct json_object *jdevices = json_create_array(); - nvme_host_t h; - nvme_subsystem_t s; - nvme_ctrl_t c; - nvme_ns_t n; + libnvme_host_t h; + libnvme_subsystem_t s; + libnvme_ctrl_t c; + libnvme_ns_t n; - nvme_for_each_host(ctx, h) { - nvme_for_each_subsystem(h, s) { - nvme_subsystem_for_each_ns(s, n) + libnvme_for_each_host(ctx, h) { + libnvme_for_each_subsystem(h, s) { + libnvme_subsystem_for_each_ns(s, n) array_add_obj(jdevices, json_list_item_obj(n)); - nvme_subsystem_for_each_ctrl(s, c) { - nvme_ctrl_for_each_ns(c, n) + libnvme_subsystem_for_each_ctrl(s, c) { + libnvme_ctrl_for_each_ns(c, n) array_add_obj(jdevices, json_list_item_obj(n)); } } @@ -4906,14 +4906,14 @@ static void json_simple_list(struct nvme_global_ctx *ctx) json_print(r); } -static void json_list_item(nvme_ns_t n, struct table *t) +static void json_list_item(libnvme_ns_t n, struct table *t) { struct json_object *r = json_list_item_obj(n); json_print(r); } -static void json_print_list_items(struct nvme_global_ctx *ctx) +static void json_print_list_items(struct libnvme_global_ctx *ctx) { if (json_print_ops.flags & VERBOSE) { if (nvme_args.output_format_ver == 2) @@ -4924,31 +4924,31 @@ static void json_print_list_items(struct nvme_global_ctx *ctx) json_simple_list(ctx); } -static unsigned int json_subsystem_topology_multipath(nvme_subsystem_t s, +static unsigned int json_subsystem_topology_multipath(libnvme_subsystem_t s, json_object *namespaces) { - nvme_ns_t n; - nvme_path_t p; + libnvme_ns_t n; + libnvme_path_t p; unsigned int i = 0; - const char *iopolicy = nvme_subsystem_get_iopolicy(s); + const char *iopolicy = libnvme_subsystem_get_iopolicy(s); - nvme_subsystem_for_each_ns(s, n) { + libnvme_subsystem_for_each_ns(s, n) { struct json_object *ns_attrs; struct json_object *paths; ns_attrs = json_create_object(); - obj_add_int(ns_attrs, "NSID", nvme_ns_get_nsid(n)); - obj_add_str(ns_attrs, "Name", nvme_ns_get_name(n)); + obj_add_int(ns_attrs, "NSID", libnvme_ns_get_nsid(n)); + obj_add_str(ns_attrs, "Name", libnvme_ns_get_name(n)); paths = json_create_array(); - nvme_namespace_for_each_path(n, p) { + libnvme_namespace_for_each_path(n, p) { struct json_object *path_attrs; struct json_object *ctrls, *ctrl_attrs; - nvme_ctrl_t c; + libnvme_ctrl_t c; path_attrs = json_create_object(); - obj_add_str(path_attrs, "Path", nvme_path_get_name(p)); - obj_add_str(path_attrs, "ANAState", nvme_path_get_ana_state(p)); + obj_add_str(path_attrs, "Path", libnvme_path_get_name(p)); + obj_add_str(path_attrs, "ANAState", libnvme_path_get_ana_state(p)); /* * For iopolicy numa exclude "Qdepth", for iopolicy @@ -4957,18 +4957,18 @@ static unsigned int json_subsystem_topology_multipath(nvme_subsystem_t s, */ if (!strcmp(iopolicy, "numa")) obj_add_str(path_attrs, "NUMANodes", - nvme_path_get_numa_nodes(p)); + libnvme_path_get_numa_nodes(p)); else if (!strcmp(iopolicy, "queue-depth")) obj_add_int(path_attrs, "Qdepth", - nvme_path_get_queue_depth(p)); + libnvme_path_get_queue_depth(p)); - c = nvme_path_get_ctrl(p); + c = libnvme_path_get_ctrl(p); ctrls = json_create_array(); ctrl_attrs = json_create_object(); - obj_add_str(ctrl_attrs, "Name", nvme_ctrl_get_name(c)); - obj_add_str(ctrl_attrs, "Transport", nvme_ctrl_get_transport(c)); - obj_add_str(ctrl_attrs, "Address", nvme_ctrl_get_traddr(c)); - obj_add_str(ctrl_attrs, "State", nvme_ctrl_get_state(c)); + obj_add_str(ctrl_attrs, "Name", libnvme_ctrl_get_name(c)); + obj_add_str(ctrl_attrs, "Transport", libnvme_ctrl_get_transport(c)); + obj_add_str(ctrl_attrs, "Address", libnvme_ctrl_get_traddr(c)); + obj_add_str(ctrl_attrs, "State", libnvme_ctrl_get_state(c)); array_add_obj(ctrls, ctrl_attrs); obj_add_array(path_attrs, "Controller", ctrls); @@ -4982,32 +4982,32 @@ static unsigned int json_subsystem_topology_multipath(nvme_subsystem_t s, return i; } -static void json_print_nvme_subsystem_topology(nvme_subsystem_t s, +static void json_print_nvme_subsystem_topology(libnvme_subsystem_t s, json_object *namespaces) { - nvme_ctrl_t c; - nvme_ns_t n; + libnvme_ctrl_t c; + libnvme_ns_t n; - nvme_subsystem_for_each_ctrl(s, c) { - nvme_ctrl_for_each_ns(c, n) { + libnvme_subsystem_for_each_ctrl(s, c) { + libnvme_ctrl_for_each_ns(c, n) { struct json_object *ctrl_attrs; struct json_object *ns_attrs; struct json_object *ctrl; ns_attrs = json_create_object(); - obj_add_int(ns_attrs, "NSID", nvme_ns_get_nsid(n)); - obj_add_str(ns_attrs, "Name", nvme_ns_get_name(n)); + obj_add_int(ns_attrs, "NSID", libnvme_ns_get_nsid(n)); + obj_add_str(ns_attrs, "Name", libnvme_ns_get_name(n)); ctrl = json_create_array(); ctrl_attrs = json_create_object(); obj_add_str(ctrl_attrs, "Name", - nvme_ctrl_get_name(c)); + libnvme_ctrl_get_name(c)); obj_add_str(ctrl_attrs, "Transport", - nvme_ctrl_get_transport(c)); + libnvme_ctrl_get_transport(c)); obj_add_str(ctrl_attrs, "Address", - nvme_ctrl_get_traddr(c)); + libnvme_ctrl_get_traddr(c)); obj_add_str(ctrl_attrs, "State", - nvme_ctrl_get_state(c)); + libnvme_ctrl_get_state(c)); array_add_obj(ctrl, ctrl_attrs); obj_add_array(ns_attrs, "Controller", ctrl); @@ -5016,39 +5016,39 @@ static void json_print_nvme_subsystem_topology(nvme_subsystem_t s, } } -static void json_simple_topology(struct nvme_global_ctx *ctx) +static void json_simple_topology(struct libnvme_global_ctx *ctx) { struct json_object *host_attrs, *subsystem_attrs; struct json_object *subsystems, *namespaces; struct json_object *a = json_create_array(); - nvme_host_t h; + libnvme_host_t h; - nvme_for_each_host(ctx, h) { - nvme_subsystem_t s; + libnvme_for_each_host(ctx, h) { + libnvme_subsystem_t s; const char *hostid; host_attrs = json_create_object(); - obj_add_str(host_attrs, "HostNQN", nvme_host_get_hostnqn(h)); - hostid = nvme_host_get_hostid(h); + obj_add_str(host_attrs, "HostNQN", libnvme_host_get_hostnqn(h)); + hostid = libnvme_host_get_hostid(h); if (hostid) obj_add_str(host_attrs, "HostID", hostid); subsystems = json_create_array(); - nvme_for_each_subsystem(h, s) { + libnvme_for_each_subsystem(h, s) { subsystem_attrs = json_create_object(); - obj_add_str(subsystem_attrs, "Name", nvme_subsystem_get_name(s)); - obj_add_str(subsystem_attrs, "NQN", nvme_subsystem_get_subsysnqn(s)); + obj_add_str(subsystem_attrs, "Name", libnvme_subsystem_get_name(s)); + obj_add_str(subsystem_attrs, "NQN", libnvme_subsystem_get_subsysnqn(s)); obj_add_str(subsystem_attrs, "IOPolicy", - nvme_subsystem_get_iopolicy(s)); + libnvme_subsystem_get_iopolicy(s)); if (verbose_mode()) { obj_add_str(subsystem_attrs, "Model", - nvme_subsystem_get_model(s)); + libnvme_subsystem_get_model(s)); obj_add_str(subsystem_attrs, "Serial", - nvme_subsystem_get_serial(s)); + libnvme_subsystem_get_serial(s)); obj_add_str(subsystem_attrs, "Firmware", - nvme_subsystem_get_firmware(s)); + libnvme_subsystem_get_firmware(s)); obj_add_str(subsystem_attrs, "Type", - nvme_subsystem_get_subsystype(s)); + libnvme_subsystem_get_subsystype(s)); } array_add_obj(subsystems, subsystem_attrs); @@ -5235,11 +5235,11 @@ static void json_discovery_log(struct nvmf_discovery_log *log, int numrec) static void json_discovery_log(struct nvmf_discovery_log *log, int numrec) {} #endif -static void json_connect_msg(nvme_ctrl_t c) +static void json_connect_msg(libnvme_ctrl_t c) { struct json_object *r = json_create_object(); - obj_add_str(r, "device", nvme_ctrl_get_name(c)); + obj_add_str(r, "device", libnvme_ctrl_get_name(c)); json_print(r); } @@ -5260,7 +5260,7 @@ static void json_output_status(int status) r = obj_create(json_str); if (status < 0) { - obj_add_str(r, "error", nvme_strerror(errno)); + obj_add_str(r, "error", libnvme_strerror(errno)); obj_print(r); return; } @@ -5270,11 +5270,11 @@ static void json_output_status(int status) switch (type) { case NVME_STATUS_TYPE_NVME: - obj_add_str(r, "error", nvme_status_to_string(val, false)); + obj_add_str(r, "error", libnvme_status_to_string(val, false)); obj_add_str(r, "type", "nvme"); break; case NVME_STATUS_TYPE_MI: - obj_add_str(r, "error", nvme_mi_status_to_string(val)); + obj_add_str(r, "error", libnvme_mi_status_to_string(val)); obj_add_str(r, "type", "nvme-mi"); break; default: @@ -5296,7 +5296,7 @@ static void json_output_opcode_status(int status, bool admin, __u8 opcode) sprintf(json_str, "status: %d", status); r = obj_create(json_str); obj_add_str(r, "error", - nvme_opcode_status_to_string(val, admin, opcode)); + libnvme_opcode_status_to_string(val, admin, opcode)); obj_add_str(r, "type", "nvme"); obj_print(r); return; @@ -5321,7 +5321,7 @@ static void json_output_error_status(int status, const char *msg, va_list ap) r = obj_create(json_str); if (status < 0) { - obj_add_str(r, "error", nvme_strerror(errno)); + obj_add_str(r, "error", libnvme_strerror(errno)); obj_print(r); return; } @@ -5331,11 +5331,11 @@ static void json_output_error_status(int status, const char *msg, va_list ap) switch (type) { case NVME_STATUS_TYPE_NVME: - obj_add_str(r, "status", nvme_status_to_string(val, false)); + obj_add_str(r, "status", libnvme_status_to_string(val, false)); obj_add_str(r, "type", "nvme"); break; case NVME_STATUS_TYPE_MI: - obj_add_str(r, "status", nvme_mi_status_to_string(val)); + obj_add_str(r, "status", libnvme_mi_status_to_string(val)); obj_add_str(r, "type", "nvme-mi"); break; default: @@ -5372,7 +5372,7 @@ static void json_output_perror(const char *msg, va_list ap) error = NULL; obj_add_key(r, "error", "%s: %s", error ? error : alloc_error, - nvme_strerror(errno)); + libnvme_strerror(errno)); json_output_object(r); } diff --git a/nvme-print-stdout.c b/nvme-print-stdout.c index 404dd363dc..13bdc19753 100644 --- a/nvme-print-stdout.c +++ b/nvme-print-stdout.c @@ -42,63 +42,63 @@ static const char dash[100] = {[0 ... 99] = '-'}; static struct print_ops stdout_print_ops; -static const char *subsys_key(const struct nvme_subsystem *s) +static const char *subsys_key(const struct libnvme_subsystem *s) { - return nvme_subsystem_get_name((nvme_subsystem_t)s); + return libnvme_subsystem_get_name((libnvme_subsystem_t)s); } -static const char *ctrl_key(const struct nvme_ctrl *c) +static const char *ctrl_key(const struct libnvme_ctrl *c) { - return nvme_ctrl_get_name((nvme_ctrl_t)c); + return libnvme_ctrl_get_name((libnvme_ctrl_t)c); } -static const char *ns_key(const struct nvme_ns *n) +static const char *ns_key(const struct libnvme_ns *n) { - return nvme_ns_get_name((nvme_ns_t)n); + return libnvme_ns_get_name((libnvme_ns_t)n); } -static bool subsys_cmp(const struct nvme_subsystem *s, const char *name) +static bool subsys_cmp(const struct libnvme_subsystem *s, const char *name) { - return !strcmp(nvme_subsystem_get_name((nvme_subsystem_t)s), name); + return !strcmp(libnvme_subsystem_get_name((libnvme_subsystem_t)s), name); } -static bool ctrl_cmp(const struct nvme_ctrl *c, const char *name) +static bool ctrl_cmp(const struct libnvme_ctrl *c, const char *name) { - return !strcmp(nvme_ctrl_get_name((nvme_ctrl_t)c), name); + return !strcmp(libnvme_ctrl_get_name((libnvme_ctrl_t)c), name); } -static bool ns_cmp(const struct nvme_ns *n, const char *name) +static bool ns_cmp(const struct libnvme_ns *n, const char *name) { - return !strcmp(nvme_ns_get_name((nvme_ns_t)n), name); + return !strcmp(libnvme_ns_get_name((libnvme_ns_t)n), name); } -HTABLE_DEFINE_TYPE(struct nvme_subsystem, subsys_key, hash_string, +HTABLE_DEFINE_TYPE(struct libnvme_subsystem, subsys_key, hash_string, subsys_cmp, htable_subsys); -HTABLE_DEFINE_TYPE(struct nvme_ctrl, ctrl_key, hash_string, +HTABLE_DEFINE_TYPE(struct libnvme_ctrl, ctrl_key, hash_string, ctrl_cmp, htable_ctrl); -HTABLE_DEFINE_TYPE(struct nvme_ns, ns_key, hash_string, +HTABLE_DEFINE_TYPE(struct libnvme_ns, ns_key, hash_string, ns_cmp, htable_ns); -static void htable_ctrl_add_unique(struct htable_ctrl *ht, nvme_ctrl_t c) +static void htable_ctrl_add_unique(struct htable_ctrl *ht, libnvme_ctrl_t c) { - if (htable_ctrl_get(ht, nvme_ctrl_get_name(c))) + if (htable_ctrl_get(ht, libnvme_ctrl_get_name(c))) return; htable_ctrl_add(ht, c); } -static void htable_ns_add_unique(struct htable_ns *ht, nvme_ns_t n) +static void htable_ns_add_unique(struct htable_ns *ht, libnvme_ns_t n) { struct htable_ns_iter it; - nvme_ns_t _n; + libnvme_ns_t _n; /* * Test if namespace pointer is already in the hash, and thus avoid * inserting severaltimes the same pointer. */ - for (_n = htable_ns_getfirst(ht, nvme_ns_get_name(n), &it); + for (_n = htable_ns_getfirst(ht, libnvme_ns_get_name(n), &it); _n; - _n = htable_ns_getnext(ht, nvme_ns_get_name(n), &it)) { + _n = htable_ns_getnext(ht, libnvme_ns_get_name(n), &it)) { if (_n == n) return; } @@ -106,7 +106,7 @@ static void htable_ns_add_unique(struct htable_ns *ht, nvme_ns_t n) } struct nvme_resources { - struct nvme_global_ctx *ctx; + struct libnvme_global_ctx *ctx; struct htable_subsys ht_s; struct htable_ctrl ht_c; @@ -121,13 +121,13 @@ struct nvme_resources_table { struct table *t; }; -static int nvme_resources_init(struct nvme_global_ctx *ctx, struct nvme_resources *res) +static int nvme_resources_init(struct libnvme_global_ctx *ctx, struct nvme_resources *res) { - nvme_host_t h; - nvme_subsystem_t s; - nvme_ctrl_t c; - nvme_ns_t n; - nvme_path_t p; + libnvme_host_t h; + libnvme_subsystem_t s; + libnvme_ctrl_t c; + libnvme_ns_t n; + libnvme_path_t p; res->ctx = ctx; htable_subsys_init(&res->ht_s); @@ -137,32 +137,32 @@ static int nvme_resources_init(struct nvme_global_ctx *ctx, struct nvme_resource strset_init(&res->ctrls); strset_init(&res->namespaces); - nvme_for_each_host(ctx, h) { - nvme_for_each_subsystem(h, s) { + libnvme_for_each_host(ctx, h) { + libnvme_for_each_subsystem(h, s) { htable_subsys_add(&res->ht_s, s); - strset_add(&res->subsystems, nvme_subsystem_get_name(s)); + strset_add(&res->subsystems, libnvme_subsystem_get_name(s)); - nvme_subsystem_for_each_ctrl(s, c) { + libnvme_subsystem_for_each_ctrl(s, c) { htable_ctrl_add_unique(&res->ht_c, c); - strset_add(&res->ctrls, nvme_ctrl_get_name(c)); + strset_add(&res->ctrls, libnvme_ctrl_get_name(c)); - nvme_ctrl_for_each_ns(c, n) { + libnvme_ctrl_for_each_ns(c, n) { htable_ns_add_unique(&res->ht_n, n); - strset_add(&res->namespaces, nvme_ns_get_name(n)); + strset_add(&res->namespaces, libnvme_ns_get_name(n)); } - nvme_ctrl_for_each_path(c, p) { - n = nvme_path_get_ns(p); + libnvme_ctrl_for_each_path(c, p) { + n = libnvme_path_get_ns(p); if (n) { htable_ns_add_unique(&res->ht_n, n); - strset_add(&res->namespaces, nvme_ns_get_name(n)); + strset_add(&res->namespaces, libnvme_ns_get_name(n)); } } } - nvme_subsystem_for_each_ns(s, n) { + libnvme_subsystem_for_each_ns(s, n) { htable_ns_add_unique(&res->ht_n, n); - strset_add(&res->namespaces, nvme_ns_get_name(n)); + strset_add(&res->namespaces, libnvme_ns_get_name(n)); } } } @@ -1171,25 +1171,25 @@ static void stdout_supported_cap_config_log(struct nvme_supported_cap_config_lis } } -static unsigned int stdout_subsystem_multipath(nvme_subsystem_t s) +static unsigned int stdout_subsystem_multipath(libnvme_subsystem_t s) { - nvme_ns_t n; - nvme_path_t p; + libnvme_ns_t n; + libnvme_path_t p; unsigned int i = 0; - n = nvme_subsystem_first_ns(s); + n = libnvme_subsystem_first_ns(s); if (!n) return 0; - nvme_namespace_for_each_path(n, p) { - nvme_ctrl_t c = nvme_path_get_ctrl(p); - const char *ana_state = ana_state = nvme_path_get_ana_state(p); + libnvme_namespace_for_each_path(n, p) { + libnvme_ctrl_t c = libnvme_path_get_ctrl(p); + const char *ana_state = ana_state = libnvme_path_get_ana_state(p); printf(" +- %s %s %s %s %s\n", - nvme_ctrl_get_name(c), - nvme_ctrl_get_transport(c), - nvme_ctrl_get_traddr(c), - nvme_ctrl_get_state(c), + libnvme_ctrl_get_name(c), + libnvme_ctrl_get_transport(c), + libnvme_ctrl_get_traddr(c), + libnvme_ctrl_get_state(c), ana_state); i++; } @@ -1197,56 +1197,56 @@ static unsigned int stdout_subsystem_multipath(nvme_subsystem_t s) return i; } -static void stdout_subsystem_ctrls(nvme_subsystem_t s) +static void stdout_subsystem_ctrls(libnvme_subsystem_t s) { - nvme_ctrl_t c; + libnvme_ctrl_t c; - nvme_subsystem_for_each_ctrl(s, c) { + libnvme_subsystem_for_each_ctrl(s, c) { printf(" +- %s %s %s %s\n", - nvme_ctrl_get_name(c), - nvme_ctrl_get_transport(c), - nvme_ctrl_get_traddr(c), - nvme_ctrl_get_state(c)); + libnvme_ctrl_get_name(c), + libnvme_ctrl_get_transport(c), + libnvme_ctrl_get_traddr(c), + libnvme_ctrl_get_state(c)); } } -static void stdout_subsys_config(nvme_subsystem_t s, bool show_iopolicy) +static void stdout_subsys_config(libnvme_subsystem_t s, bool show_iopolicy) { - int len = strlen(nvme_subsystem_get_name(s)); + int len = strlen(libnvme_subsystem_get_name(s)); - printf("%s - NQN=%s\n", nvme_subsystem_get_name(s), - nvme_subsystem_get_subsysnqn(s)); + printf("%s - NQN=%s\n", libnvme_subsystem_get_name(s), + libnvme_subsystem_get_subsysnqn(s)); printf("%*s hostnqn=%s\n", len, " ", - nvme_host_get_hostnqn(nvme_subsystem_get_host(s))); + libnvme_host_get_hostnqn(libnvme_subsystem_get_host(s))); if (show_iopolicy) printf("%*s iopolicy=%s\n", len, " ", - nvme_subsystem_get_iopolicy(s)); + libnvme_subsystem_get_iopolicy(s)); if (stdout_print_ops.flags & VERBOSE) { printf("%*s model=%s\n", len, " ", - nvme_subsystem_get_model(s)); + libnvme_subsystem_get_model(s)); printf("%*s serial=%s\n", len, " ", - nvme_subsystem_get_serial(s)); + libnvme_subsystem_get_serial(s)); printf("%*s firmware=%s\n", len, " ", - nvme_subsystem_get_firmware(s)); + libnvme_subsystem_get_firmware(s)); printf("%*s type=%s\n", len, " ", - nvme_subsystem_get_subsystype(s)); + libnvme_subsystem_get_subsystype(s)); } } -static void stdout_subsystem(struct nvme_global_ctx *ctx, bool show_ana) +static void stdout_subsystem(struct libnvme_global_ctx *ctx, bool show_ana) { - nvme_host_t h; + libnvme_host_t h; bool first = true; - nvme_for_each_host(ctx, h) { - nvme_subsystem_t s; + libnvme_for_each_host(ctx, h) { + libnvme_subsystem_t s; - nvme_for_each_subsystem(h, s) { + libnvme_for_each_subsystem(h, s) { bool no_ctrl = true; - nvme_ctrl_t c; + libnvme_ctrl_t c; - nvme_subsystem_for_each_ctrl(s, c) + libnvme_subsystem_for_each_ctrl(s, c) no_ctrl = false; if (no_ctrl) continue; @@ -1265,7 +1265,7 @@ static void stdout_subsystem(struct nvme_global_ctx *ctx, bool show_ana) } } -static void stdout_subsystem_list(struct nvme_global_ctx *ctx, bool show_ana) +static void stdout_subsystem_list(struct libnvme_global_ctx *ctx, bool show_ana) { stdout_subsystem(ctx, show_ana); } @@ -1801,7 +1801,7 @@ static void stdout_status(int status) * sensible fallback anyway */ if (status < 0) { - fprintf(stderr, "Error: %s\n", nvme_strerror(errno)); + fprintf(stderr, "Error: %s\n", libnvme_strerror(errno)); return; } @@ -1811,11 +1811,11 @@ static void stdout_status(int status) switch (type) { case NVME_STATUS_TYPE_NVME: fprintf(stderr, "NVMe status: %s(%#x)\n", - nvme_status_to_string(val, false), val); + libnvme_status_to_string(val, false), val); break; case NVME_STATUS_TYPE_MI: fprintf(stderr, "NVMe-MI status: %s(%#x)\n", - nvme_mi_status_to_string(val), val); + libnvme_mi_status_to_string(val), val); break; default: fprintf(stderr, "Unknown status type %d, value %#x\n", type, @@ -1831,7 +1831,7 @@ static void stdout_opcode_status(int status, bool admin, __u8 opcode) if (status >= 0 && type == NVME_STATUS_TYPE_NVME) { fprintf(stderr, "NVMe status: %s(0x%x)\n", - nvme_opcode_status_to_string(val, admin, opcode), val); + libnvme_opcode_status_to_string(val, admin, opcode), val); return; } @@ -3208,7 +3208,7 @@ static void stdout_id_ns_descs(void *data, unsigned int nsid) break; case NVME_NIDT_UUID: memcpy(uuid, data + pos + sizeof(*cur), 16); - nvme_uuid_to_string(uuid, uuid_str); + libnvme_uuid_to_string(uuid, uuid_str); if (verbose) printf("type : uuid\n"); printf("uuid : %s\n", uuid_str); @@ -4235,7 +4235,7 @@ static void stdout_error_log(struct nvme_error_log_page *err_log, int entries, printf("sqid : %d\n", err_log[i].sqid); printf("cmdid : %#x\n", err_log[i].cmdid); printf("status_field : %#x (%s)\n", status, - nvme_status_to_string(status, false)); + libnvme_status_to_string(status, false)); printf("phase_tag : %#x\n", le16_to_cpu(err_log[i].status_field) & 0x1); printf("parm_err_loc : %#x\n", err_log[i].parm_error_location); @@ -4749,7 +4749,7 @@ static void stdout_self_test_result(struct nvme_st_result *res) if (res->vdi & NVME_ST_VALID_DIAG_INFO_SC) { printf(" Status Code : %#x", res->sc); if (stdout_print_ops.flags & VERBOSE) - printf(" %s", nvme_status_to_string( + printf(" %s", libnvme_status_to_string( (res->sct & 7) << 8 | res->sc, false)); printf("\n"); } @@ -5563,15 +5563,15 @@ static void stdout_lba_status(struct nvme_lba_status *list, } } -static void stdout_dev_full_path(nvme_ns_t n, char *path, size_t len) +static void stdout_dev_full_path(libnvme_ns_t n, char *path, size_t len) { struct stat st; - snprintf(path, len, "%s", nvme_ns_get_name(n)); + snprintf(path, len, "%s", libnvme_ns_get_name(n)); if (strncmp(path, "/dev/spdk/", 10) == 0 && stat(path, &st) == 0) return; - snprintf(path, len, "/dev/%s", nvme_ns_get_name(n)); + snprintf(path, len, "/dev/%s", libnvme_ns_get_name(n)); if (stat(path, &st) == 0) return; @@ -5579,10 +5579,10 @@ static void stdout_dev_full_path(nvme_ns_t n, char *path, size_t len) * We could start trying to search for it but let's make * it simple and just don't show the path at all. */ - snprintf(path, len, "%s", nvme_ns_get_name(n)); + snprintf(path, len, "%s", libnvme_ns_get_name(n)); } -static void stdout_generic_full_path(nvme_ns_t n, char *path, size_t len) +static void stdout_generic_full_path(libnvme_ns_t n, char *path, size_t len) { int head_instance; int instance; @@ -5592,11 +5592,11 @@ static void stdout_generic_full_path(nvme_ns_t n, char *path, size_t len) * There is no block devices for SPDK, point generic path to existing * chardevice. */ - snprintf(path, len, "%s", nvme_ns_get_name(n)); + snprintf(path, len, "%s", libnvme_ns_get_name(n)); if (strncmp(path, "/dev/spdk/", 10) == 0 && stat(path, &st) == 0) return; - if (sscanf(nvme_ns_get_name(n), "nvme%dn%d", &instance, &head_instance) != 2) + if (sscanf(libnvme_ns_get_name(n), "nvme%dn%d", &instance, &head_instance) != 2) return; snprintf(path, len, "/dev/ng%dn%d", instance, head_instance); @@ -5611,14 +5611,14 @@ static void stdout_generic_full_path(nvme_ns_t n, char *path, size_t len) snprintf(path, len, "ng%dn%d", instance, head_instance); } -static void list_item(nvme_ns_t n, struct table *t) +static void list_item(libnvme_ns_t n, struct table *t) { char usage[128] = { 0 }, format[128] = { 0 }; char devname[128] = { 0 }; char genname[128] = { 0 }; - long long lba = nvme_ns_get_lba_size(n); - double nsze = nvme_ns_get_lba_count(n) * lba; - double nuse = nvme_ns_get_lba_util(n) * lba; + long long lba = libnvme_ns_get_lba_size(n); + double nsze = libnvme_ns_get_lba_count(n) * lba; + double nuse = libnvme_ns_get_lba_util(n) * lba; const char *s_suffix = suffix_si_get(&nsze); const char *u_suffix = suffix_si_get(&nuse); @@ -5629,7 +5629,7 @@ static void list_item(nvme_ns_t n, struct table *t) snprintf(usage, sizeof(usage), "%6.2f %2sB / %6.2f %2sB", nuse, u_suffix, nsze, s_suffix); snprintf(format, sizeof(format), "%3.0f %2sB + %2d B", (double)lba, - l_suffix, nvme_ns_get_meta_size(n)); + l_suffix, libnvme_ns_get_meta_size(n)); stdout_dev_full_path(n, devname, sizeof(devname)); stdout_generic_full_path(n, genname, sizeof(genname)); @@ -5647,15 +5647,15 @@ static void list_item(nvme_ns_t n, struct table *t) printf("Failed to set generic value\n"); return; } - if (table_set_value_str(t, SIMPLE_LIST_COL_SN, row, nvme_ns_get_serial(n), LEFT)) { + if (table_set_value_str(t, SIMPLE_LIST_COL_SN, row, libnvme_ns_get_serial(n), LEFT)) { printf("Failed to set sn value\n"); return; } - if (table_set_value_str(t, SIMPLE_LIST_COL_MODEL, row, nvme_ns_get_model(n), LEFT)) { + if (table_set_value_str(t, SIMPLE_LIST_COL_MODEL, row, libnvme_ns_get_model(n), LEFT)) { printf("Failed to set model value\n"); return; } - if (!sprintf(ns, "0x%x", nvme_ns_get_nsid(n))) { + if (!sprintf(ns, "0x%x", libnvme_ns_get_nsid(n))) { printf("Failed to output ns string\n"); return; } @@ -5671,19 +5671,19 @@ static void list_item(nvme_ns_t n, struct table *t) printf("Failed to set format value\n"); return; } - if (table_set_value_str(t, SIMPLE_LIST_COL_FW_REV, row, nvme_ns_get_firmware(n), LEFT)) { + if (table_set_value_str(t, SIMPLE_LIST_COL_FW_REV, row, libnvme_ns_get_firmware(n), LEFT)) { printf("Failed to set fw rev value\n"); return; } table_add_row(t, row); } -static void stdout_list_item(nvme_ns_t n, struct table *t) +static void stdout_list_item(libnvme_ns_t n, struct table *t) { list_item(n, t); } -static void stdout_list_item_table(nvme_ns_t n, struct table *t) +static void stdout_list_item_table(libnvme_ns_t n, struct table *t) { list_item(n, t); } @@ -5692,7 +5692,7 @@ static bool stdout_simple_ns(const char *name, void *arg) { struct nvme_resources_table *rst_t = arg; struct nvme_resources *res = rst_t->res; - nvme_ns_t n; + libnvme_ns_t n; n = htable_ns_get(&res->ht_n, name); stdout_list_item_table(n, rst_t->t); @@ -5700,7 +5700,7 @@ static bool stdout_simple_ns(const char *name, void *arg) return true; } -static void stdout_simple_list(struct nvme_global_ctx *ctx) +static void stdout_simple_list(struct libnvme_global_ctx *ctx) { struct nvme_resources res; struct table_column columns[] = { @@ -5731,14 +5731,14 @@ static void stdout_simple_list(struct nvme_global_ctx *ctx) table_free(t); } -static void stdout_ns_details(nvme_ns_t n) +static void stdout_ns_details(libnvme_ns_t n) { char usage[128] = { 0 }, format[128] = { 0 }, usage_binary[128] = { 0 }; char devname[128] = { 0 }, genname[128] = { 0 }; - long long lba = nvme_ns_get_lba_size(n); - double nsze = nvme_ns_get_lba_count(n) * lba; - double nuse = nvme_ns_get_lba_util(n) * lba; + long long lba = libnvme_ns_get_lba_size(n); + double nsze = libnvme_ns_get_lba_count(n) * lba; + double nuse = libnvme_ns_get_lba_util(n) * lba; double nsze_binary = nsze, nuse_binary = nuse; const char *s_suffix = suffix_si_get(&nsze); @@ -5749,7 +5749,7 @@ static void stdout_ns_details(nvme_ns_t n) sprintf(usage, "%6.2f %1sB / %6.2f %1sB", nuse, u_suffix, nsze, s_suffix); sprintf(format, "%3.0f %2sB + %2d B", (double)lba, l_suffix, - nvme_ns_get_meta_size(n)); + libnvme_ns_get_meta_size(n)); s_suffix_binary = suffix_dbinary_get(&nsze_binary); u_suffix_binary = suffix_dbinary_get(&nuse_binary); @@ -5760,7 +5760,7 @@ static void stdout_ns_details(nvme_ns_t n) nvme_generic_full_path(n, genname, sizeof(genname)); printf("%-17s %-17s %#-10x %-21s %-25s %-16s ", devname, - genname, nvme_ns_get_nsid(n), usage, usage_binary, format); + genname, libnvme_ns_get_nsid(n), usage, usage_binary, format); } static bool stdout_detailed_name(const char *name, void *arg) @@ -5778,8 +5778,8 @@ static bool stdout_detailed_subsys(const char *name, void *arg) struct nvme_resources *res = arg; struct htable_subsys_iter it; struct strset ctrls; - nvme_subsystem_t s; - nvme_ctrl_t c; + libnvme_subsystem_t s; + libnvme_ctrl_t c; bool first; strset_init(&ctrls); @@ -5789,12 +5789,12 @@ static bool stdout_detailed_subsys(const char *name, void *arg) s = htable_subsys_getnext(&res->ht_s, name, &it)) { if (first) { printf("%-16s %-96s ", name, - nvme_subsystem_get_subsysnqn(s)); + libnvme_subsystem_get_subsysnqn(s)); first = false; } - nvme_subsystem_for_each_ctrl(s, c) - strset_add(&ctrls, nvme_ctrl_get_name(c)); + libnvme_subsystem_for_each_ctrl(s, c) + strset_add(&ctrls, libnvme_ctrl_get_name(c)); } first = true; @@ -5809,34 +5809,34 @@ static bool stdout_detailed_ctrl(const char *name, void *arg) { struct nvme_resources *res = arg; struct strset namespaces; - nvme_ctrl_t c; - nvme_path_t p; - nvme_ns_t n; + libnvme_ctrl_t c; + libnvme_path_t p; + libnvme_ns_t n; bool first; c = htable_ctrl_get(&res->ht_c, name); assert(c); printf("%-16s %-6s %-20s %-40s %-8s %-6s %-14s %-6s %-12s ", - nvme_ctrl_get_name(c), - nvme_ctrl_get_cntlid(c), - nvme_ctrl_get_serial(c), - nvme_ctrl_get_model(c), - nvme_ctrl_get_firmware(c), - nvme_ctrl_get_transport(c), - nvme_ctrl_get_traddr(c), - nvme_ctrl_get_phy_slot(c), - nvme_subsystem_get_name(nvme_ctrl_get_subsystem(c))); + libnvme_ctrl_get_name(c), + libnvme_ctrl_get_cntlid(c), + libnvme_ctrl_get_serial(c), + libnvme_ctrl_get_model(c), + libnvme_ctrl_get_firmware(c), + libnvme_ctrl_get_transport(c), + libnvme_ctrl_get_traddr(c), + libnvme_ctrl_get_phy_slot(c), + libnvme_subsystem_get_name(libnvme_ctrl_get_subsystem(c))); strset_init(&namespaces); - nvme_ctrl_for_each_ns(c, n) - strset_add(&namespaces, nvme_ns_get_name(n)); - nvme_ctrl_for_each_path(c, p) { - n = nvme_path_get_ns(p); + libnvme_ctrl_for_each_ns(c, n) + strset_add(&namespaces, libnvme_ns_get_name(n)); + libnvme_ctrl_for_each_path(c, p) { + n = libnvme_path_get_ns(p); if (!n) continue; - strset_add(&namespaces, nvme_ns_get_name(n)); + strset_add(&namespaces, libnvme_ns_get_name(n)); } first = true; @@ -5853,9 +5853,9 @@ static bool stdout_detailed_ns(const char *name, void *arg) struct nvme_resources *res = arg; struct htable_ns_iter it; struct strset ctrls; - nvme_ctrl_t c; - nvme_path_t p; - nvme_ns_t n; + libnvme_ctrl_t c; + libnvme_path_t p; + libnvme_ns_t n; bool first; strset_init(&ctrls); @@ -5868,14 +5868,14 @@ static bool stdout_detailed_ns(const char *name, void *arg) first = false; } - if (nvme_ns_get_ctrl(n)) { - printf("%s\n", nvme_ctrl_get_name(nvme_ns_get_ctrl(n))); + if (libnvme_ns_get_ctrl(n)) { + printf("%s\n", libnvme_ctrl_get_name(libnvme_ns_get_ctrl(n))); return true; } - nvme_namespace_for_each_path(n, p) { - c = nvme_path_get_ctrl(p); - strset_add(&ctrls, nvme_ctrl_get_name(c)); + libnvme_namespace_for_each_path(n, p) { + c = libnvme_path_get_ctrl(p); + strset_add(&ctrls, libnvme_ctrl_get_name(c)); } } @@ -5887,7 +5887,7 @@ static bool stdout_detailed_ns(const char *name, void *arg) return true; } -static void stdout_detailed_list(struct nvme_global_ctx *ctx) +static void stdout_detailed_list(struct libnvme_global_ctx *ctx) { struct nvme_resources res; @@ -5915,7 +5915,7 @@ static void stdout_detailed_list(struct nvme_global_ctx *ctx) nvme_resources_free(&res); } -static void stdout_list_items(struct nvme_global_ctx *ctx) +static void stdout_list_items(struct libnvme_global_ctx *ctx) { if (stdout_print_ops.flags & VERBOSE) stdout_detailed_list(ctx); @@ -5925,8 +5925,8 @@ static void stdout_list_items(struct nvme_global_ctx *ctx) static bool subsystem_iopolicy_filter(const char *name, void *arg) { - nvme_subsystem_t s = arg; - const char *iopolicy = nvme_subsystem_get_iopolicy(s); + libnvme_subsystem_t s = arg; + const char *iopolicy = libnvme_subsystem_get_iopolicy(s); if (!strcmp(iopolicy, "queue-depth")) { /* exclude "Nodes" for iopolicy queue-depth */ @@ -5977,17 +5977,17 @@ static int subsystem_topology_multipath_add_row(struct table *t, return 0; } -static void stdout_tabular_subsystem_topology_multipath(nvme_subsystem_t s) +static void stdout_tabular_subsystem_topology_multipath(libnvme_subsystem_t s) { - nvme_ns_t n; - nvme_path_t p; - nvme_ctrl_t c; + libnvme_ns_t n; + libnvme_path_t p; + libnvme_ctrl_t c; bool first; char nshead[32], nsid[32]; char iopolicy_info[256]; int ret, num_path; struct table *t; - const char *iopolicy = nvme_subsystem_get_iopolicy(s); + const char *iopolicy = libnvme_subsystem_get_iopolicy(s); struct table_column columns[] = { {"NSHead", LEFT, 0}, {"NSID", LEFT, 0}, @@ -6013,10 +6013,10 @@ static void stdout_tabular_subsystem_topology_multipath(nvme_subsystem_t s) goto free_tbl; } - nvme_subsystem_for_each_ns(s, n) { + libnvme_subsystem_for_each_ns(s, n) { first = true; - nvme_namespace_for_each_path(n, p) { - c = nvme_path_get_ctrl(p); + libnvme_namespace_for_each_path(n, p) { + c = libnvme_path_get_ctrl(p); /* * For the first row we print actual NSHead name, @@ -6027,31 +6027,31 @@ static void stdout_tabular_subsystem_topology_multipath(nvme_subsystem_t s) */ if (first) { snprintf(nshead, sizeof(nshead), "%s", - nvme_ns_get_name(n)); + libnvme_ns_get_name(n)); first = false; } else snprintf(nshead, sizeof(nshead), "%s", "-->"); - snprintf(nsid, sizeof(nsid), "%u", nvme_ns_get_nsid(n)); + snprintf(nsid, sizeof(nsid), "%u", libnvme_ns_get_nsid(n)); if (!strcmp(iopolicy, "numa")) snprintf(iopolicy_info, sizeof(iopolicy_info), - "%s", nvme_path_get_numa_nodes(p)); + "%s", libnvme_path_get_numa_nodes(p)); else if (!strcmp(iopolicy, "queue-depth")) snprintf(iopolicy_info, sizeof(iopolicy_info), - "%d", nvme_path_get_queue_depth(p)); + "%d", libnvme_path_get_queue_depth(p)); ret = subsystem_topology_multipath_add_row(t, iopolicy, nshead, nsid, - nvme_path_get_name(p), - nvme_path_get_ana_state(p), + libnvme_path_get_name(p), + libnvme_path_get_ana_state(p), iopolicy_info, - nvme_ctrl_get_name(c), - nvme_ctrl_get_transport(c), - nvme_ctrl_get_traddr(c), - nvme_ctrl_get_state(c)); + libnvme_ctrl_get_name(c), + libnvme_ctrl_get_transport(c), + libnvme_ctrl_get_traddr(c), + libnvme_ctrl_get_state(c)); if (ret < 0) goto free_tbl; } @@ -6061,9 +6061,9 @@ static void stdout_tabular_subsystem_topology_multipath(nvme_subsystem_t s) * Next we print controller in the subsystem which may not have any * nvme path associated to it. */ - nvme_subsystem_for_each_ctrl(s, c) { + libnvme_subsystem_for_each_ctrl(s, c) { num_path = 0; - nvme_ctrl_for_each_path(c, p) + libnvme_ctrl_for_each_path(c, p) num_path++; if (!num_path) { @@ -6074,10 +6074,10 @@ static void stdout_tabular_subsystem_topology_multipath(nvme_subsystem_t s) "--", /* NSPath */ "--", /* ANAState */ "--", /* Nodes/Qdepth */ - nvme_ctrl_get_name(c), - nvme_ctrl_get_transport(c), - nvme_ctrl_get_traddr(c), - nvme_ctrl_get_state(c)); + libnvme_ctrl_get_name(c), + libnvme_ctrl_get_transport(c), + libnvme_ctrl_get_traddr(c), + libnvme_ctrl_get_state(c)); if (ret < 0) goto free_tbl; } @@ -6088,63 +6088,63 @@ static void stdout_tabular_subsystem_topology_multipath(nvme_subsystem_t s) table_free(t); } -static void stdout_subsystem_topology_multipath(nvme_subsystem_t s, +static void stdout_subsystem_topology_multipath(libnvme_subsystem_t s, enum nvme_cli_topo_ranking ranking) { - nvme_ns_t n; - nvme_path_t p; - nvme_ctrl_t c; - const char *iopolicy = nvme_subsystem_get_iopolicy(s); + libnvme_ns_t n; + libnvme_path_t p; + libnvme_ctrl_t c; + const char *iopolicy = libnvme_subsystem_get_iopolicy(s); if (ranking == NVME_CLI_TOPO_NAMESPACE) { - nvme_subsystem_for_each_ns(s, n) { - if (!nvme_namespace_first_path(n)) + libnvme_subsystem_for_each_ns(s, n) { + if (!libnvme_namespace_first_path(n)) continue; - printf(" +- ns %d\n", nvme_ns_get_nsid(n)); + printf(" +- ns %d\n", libnvme_ns_get_nsid(n)); printf(" \\\n"); - nvme_namespace_for_each_path(n, p) { - c = nvme_path_get_ctrl(p); + libnvme_namespace_for_each_path(n, p) { + c = libnvme_path_get_ctrl(p); printf(" +- %s %s %s %s %s\n", - nvme_ctrl_get_name(c), - nvme_ctrl_get_transport(c), - nvme_ctrl_get_traddr(c), - nvme_ctrl_get_state(c), - nvme_path_get_ana_state(p)); + libnvme_ctrl_get_name(c), + libnvme_ctrl_get_transport(c), + libnvme_ctrl_get_traddr(c), + libnvme_ctrl_get_state(c), + libnvme_path_get_ana_state(p)); } } } else if (ranking == NVME_CLI_TOPO_CTRL) { /* NVME_CLI_TOPO_CTRL */ - nvme_subsystem_for_each_ctrl(s, c) { + libnvme_subsystem_for_each_ctrl(s, c) { printf(" +- %s %s %s\n", - nvme_ctrl_get_name(c), - nvme_ctrl_get_transport(c), - nvme_ctrl_get_traddr(c)); + libnvme_ctrl_get_name(c), + libnvme_ctrl_get_transport(c), + libnvme_ctrl_get_traddr(c)); printf(" \\\n"); - nvme_subsystem_for_each_ns(s, n) { - nvme_namespace_for_each_path(n, p) { - if (nvme_path_get_ctrl(p) != c) + libnvme_subsystem_for_each_ns(s, n) { + libnvme_namespace_for_each_path(n, p) { + if (libnvme_path_get_ctrl(p) != c) continue; printf(" +- ns %d %s %s\n", - nvme_ns_get_nsid(n), - nvme_ctrl_get_state(c), - nvme_path_get_ana_state(p)); + libnvme_ns_get_nsid(n), + libnvme_ctrl_get_state(c), + libnvme_path_get_ana_state(p)); } } } } else { /* NVME_CLI_TOPO_MULTIPATH */ - nvme_subsystem_for_each_ns(s, n) { + libnvme_subsystem_for_each_ns(s, n) { printf(" +- %s (ns %d)\n", - nvme_ns_get_name(n), - nvme_ns_get_nsid(n)); + libnvme_ns_get_name(n), + libnvme_ns_get_nsid(n)); printf(" \\\n"); - nvme_namespace_for_each_path(n, p) { - c = nvme_path_get_ctrl(p); + libnvme_namespace_for_each_path(n, p) { + c = libnvme_path_get_ctrl(p); if (!strcmp(iopolicy, "numa")) { /* @@ -6152,13 +6152,13 @@ static void stdout_subsystem_topology_multipath(nvme_subsystem_t s, * qdepth. */ printf(" +- %s %s %s %s %s %s %s\n", - nvme_path_get_name(p), - nvme_path_get_ana_state(p), - nvme_path_get_numa_nodes(p), - nvme_ctrl_get_name(c), - nvme_ctrl_get_transport(c), - nvme_ctrl_get_traddr(c), - nvme_ctrl_get_state(c)); + libnvme_path_get_name(p), + libnvme_path_get_ana_state(p), + libnvme_path_get_numa_nodes(p), + libnvme_ctrl_get_name(c), + libnvme_ctrl_get_transport(c), + libnvme_ctrl_get_traddr(c), + libnvme_ctrl_get_state(c)); } else if (!strcmp(iopolicy, "queue-depth")) { /* @@ -6166,13 +6166,13 @@ static void stdout_subsystem_topology_multipath(nvme_subsystem_t s, * printing numa nodes. */ printf(" +- %s %s %d %s %s %s %s\n", - nvme_path_get_name(p), - nvme_path_get_ana_state(p), - nvme_path_get_queue_depth(p), - nvme_ctrl_get_name(c), - nvme_ctrl_get_transport(c), - nvme_ctrl_get_traddr(c), - nvme_ctrl_get_state(c)); + libnvme_path_get_name(p), + libnvme_path_get_ana_state(p), + libnvme_path_get_queue_depth(p), + libnvme_ctrl_get_name(c), + libnvme_ctrl_get_transport(c), + libnvme_ctrl_get_traddr(c), + libnvme_ctrl_get_state(c)); } else { /* round-robin */ /* @@ -6180,12 +6180,12 @@ static void stdout_subsystem_topology_multipath(nvme_subsystem_t s, * printing numa nodes and qdepth. */ printf(" +- %s %s %s %s %s %s\n", - nvme_path_get_name(p), - nvme_path_get_ana_state(p), - nvme_ctrl_get_name(c), - nvme_ctrl_get_transport(c), - nvme_ctrl_get_traddr(c), - nvme_ctrl_get_state(c)); + libnvme_path_get_name(p), + libnvme_path_get_ana_state(p), + libnvme_ctrl_get_name(c), + libnvme_ctrl_get_transport(c), + libnvme_ctrl_get_traddr(c), + libnvme_ctrl_get_state(c)); } } } @@ -6214,10 +6214,10 @@ static int subsystem_topology_add_row(struct table *t, return 0; } -static void stdout_tabular_subsystem_topology(nvme_subsystem_t s) +static void stdout_tabular_subsystem_topology(libnvme_subsystem_t s) { - nvme_ctrl_t c; - nvme_ns_t n; + libnvme_ctrl_t c; + libnvme_ns_t n; int ret, num_ns; struct table *t; struct table_column columns[] = { @@ -6240,36 +6240,36 @@ static void stdout_tabular_subsystem_topology(nvme_subsystem_t s) goto free_tbl; } - nvme_subsystem_for_each_ctrl(s, c) { + libnvme_subsystem_for_each_ctrl(s, c) { num_ns = 0; - nvme_ctrl_for_each_ns(c, n) + libnvme_ctrl_for_each_ns(c, n) num_ns++; if (!num_ns) { ret = subsystem_topology_add_row(t, "--", /* Namespace */ "--", /* NSID */ - nvme_ctrl_get_name(c), - nvme_ctrl_get_transport(c), - nvme_ctrl_get_traddr(c), - nvme_ctrl_get_state(c)); + libnvme_ctrl_get_name(c), + libnvme_ctrl_get_transport(c), + libnvme_ctrl_get_traddr(c), + libnvme_ctrl_get_state(c)); if (ret < 0) goto free_tbl; } else { - nvme_ctrl_for_each_ns(c, n) { + libnvme_ctrl_for_each_ns(c, n) { char nsid[32]; snprintf(nsid, sizeof(nsid), "%u", - nvme_ns_get_nsid(n)); + libnvme_ns_get_nsid(n)); ret = subsystem_topology_add_row(t, - nvme_ns_get_name(n), + libnvme_ns_get_name(n), (const char *)nsid, - nvme_ctrl_get_name(c), - nvme_ctrl_get_transport(c), - nvme_ctrl_get_traddr(c), - nvme_ctrl_get_state(c)); + libnvme_ctrl_get_name(c), + libnvme_ctrl_get_transport(c), + libnvme_ctrl_get_traddr(c), + libnvme_ctrl_get_state(c)); if (ret < 0) goto free_tbl; } @@ -6280,70 +6280,70 @@ static void stdout_tabular_subsystem_topology(nvme_subsystem_t s) table_free(t); } -static void stdout_subsystem_topology(nvme_subsystem_t s, +static void stdout_subsystem_topology(libnvme_subsystem_t s, enum nvme_cli_topo_ranking ranking) { - nvme_ctrl_t c; - nvme_ns_t n; + libnvme_ctrl_t c; + libnvme_ns_t n; if (ranking == NVME_CLI_TOPO_NAMESPACE) { - nvme_subsystem_for_each_ctrl(s, c) { - nvme_ctrl_for_each_ns(c, n) { - printf(" +- ns %d\n", nvme_ns_get_nsid(n)); + libnvme_subsystem_for_each_ctrl(s, c) { + libnvme_ctrl_for_each_ns(c, n) { + printf(" +- ns %d\n", libnvme_ns_get_nsid(n)); printf(" \\\n"); printf(" +- %s %s %s %s\n", - nvme_ctrl_get_name(c), - nvme_ctrl_get_transport(c), - nvme_ctrl_get_traddr(c), - nvme_ctrl_get_state(c)); + libnvme_ctrl_get_name(c), + libnvme_ctrl_get_transport(c), + libnvme_ctrl_get_traddr(c), + libnvme_ctrl_get_state(c)); } } } else if (ranking == NVME_CLI_TOPO_CTRL) { /* NVME_CLI_TOPO_CTRL */ - nvme_subsystem_for_each_ctrl(s, c) { + libnvme_subsystem_for_each_ctrl(s, c) { printf(" +- %s %s %s\n", - nvme_ctrl_get_name(c), - nvme_ctrl_get_transport(c), - nvme_ctrl_get_traddr(c)); + libnvme_ctrl_get_name(c), + libnvme_ctrl_get_transport(c), + libnvme_ctrl_get_traddr(c)); printf(" \\\n"); - nvme_ctrl_for_each_ns(c, n) { + libnvme_ctrl_for_each_ns(c, n) { printf(" +- ns %d %s\n", - nvme_ns_get_nsid(n), - nvme_ctrl_get_state(c)); + libnvme_ns_get_nsid(n), + libnvme_ctrl_get_state(c)); } } } else { /* NVME_CLI_TOPO_MULTIPATH */ - nvme_subsystem_for_each_ctrl(s, c) { - nvme_ctrl_for_each_ns(c, n) { - c = nvme_ns_get_ctrl(n); + libnvme_subsystem_for_each_ctrl(s, c) { + libnvme_ctrl_for_each_ns(c, n) { + c = libnvme_ns_get_ctrl(n); printf(" +- %s (ns %d)\n", - nvme_ns_get_name(n), - nvme_ns_get_nsid(n)); + libnvme_ns_get_name(n), + libnvme_ns_get_nsid(n)); printf(" \\\n"); printf(" +- %s %s %s %s\n", - nvme_ctrl_get_name(c), - nvme_ctrl_get_transport(c), - nvme_ctrl_get_traddr(c), - nvme_ctrl_get_state(c)); + libnvme_ctrl_get_name(c), + libnvme_ctrl_get_transport(c), + libnvme_ctrl_get_traddr(c), + libnvme_ctrl_get_state(c)); } } } } -static void stdout_topology_tabular(struct nvme_global_ctx *ctx) +static void stdout_topology_tabular(struct libnvme_global_ctx *ctx) { - nvme_host_t h; - nvme_subsystem_t s; + libnvme_host_t h; + libnvme_subsystem_t s; bool first = true; - nvme_for_each_host(ctx, h) { - nvme_for_each_subsystem(h, s) { + libnvme_for_each_host(ctx, h) { + libnvme_for_each_subsystem(h, s) { bool no_ctrl = true; - nvme_ctrl_t c; + libnvme_ctrl_t c; - nvme_subsystem_for_each_ctrl(s, c) + libnvme_subsystem_for_each_ctrl(s, c) no_ctrl = false; if (no_ctrl) @@ -6364,19 +6364,19 @@ static void stdout_topology_tabular(struct nvme_global_ctx *ctx) } } -static void stdout_simple_topology(struct nvme_global_ctx *ctx, +static void stdout_simple_topology(struct libnvme_global_ctx *ctx, enum nvme_cli_topo_ranking ranking) { - nvme_host_t h; - nvme_subsystem_t s; + libnvme_host_t h; + libnvme_subsystem_t s; bool first = true; - nvme_for_each_host(ctx, h) { - nvme_for_each_subsystem(h, s) { + libnvme_for_each_host(ctx, h) { + libnvme_for_each_subsystem(h, s) { bool no_ctrl = true; - nvme_ctrl_t c; + libnvme_ctrl_t c; - nvme_subsystem_for_each_ctrl(s, c) + libnvme_subsystem_for_each_ctrl(s, c) no_ctrl = false; if (no_ctrl) @@ -6397,17 +6397,17 @@ static void stdout_simple_topology(struct nvme_global_ctx *ctx, } } -static void stdout_topology_namespace(struct nvme_global_ctx *ctx) +static void stdout_topology_namespace(struct libnvme_global_ctx *ctx) { stdout_simple_topology(ctx, NVME_CLI_TOPO_NAMESPACE); } -static void stdout_topology_ctrl(struct nvme_global_ctx *ctx) +static void stdout_topology_ctrl(struct libnvme_global_ctx *ctx) { stdout_simple_topology(ctx, NVME_CLI_TOPO_CTRL); } -static void stdout_topology_multipath(struct nvme_global_ctx *ctx) +static void stdout_topology_multipath(struct libnvme_global_ctx *ctx) { stdout_simple_topology(ctx, NVME_CLI_TOPO_MULTIPATH); } @@ -6486,9 +6486,9 @@ static void stdout_discovery_log(struct nvmf_discovery_log *log, int numrec) static void stdout_discovery_log(struct nvmf_discovery_log *log, int numrec) {} #endif -static void stdout_connect_msg(nvme_ctrl_t c) +static void stdout_connect_msg(libnvme_ctrl_t c) { - printf("connecting to device: %s\n", nvme_ctrl_get_name(c)); + printf("connecting to device: %s\n", libnvme_ctrl_get_name(c)); } static void stdout_mgmt_addr_list_log(struct nvme_mgmt_addr_list_log *ma_list) @@ -6783,15 +6783,15 @@ static void stdout_power_meas_log(struct nvme_power_meas_log *log, __u32 size) } } -static void stdout_relatives(struct nvme_global_ctx *ctx, const char *name) +static void stdout_relatives(struct libnvme_global_ctx *ctx, const char *name) { struct nvme_resources res; struct htable_ns_iter it; bool block = true; bool first = true; - nvme_ctrl_t c; - nvme_path_t p; - nvme_ns_t n; + libnvme_ctrl_t c; + libnvme_path_t p; + libnvme_ns_t n; int nsid; int ret; int id; @@ -6814,13 +6814,13 @@ static void stdout_relatives(struct nvme_global_ctx *ctx, const char *name) fprintf(stderr, "Namespace %s has parent controller(s):", name); for (n = htable_ns_getfirst(&res.ht_n, name, &it); n; n = htable_ns_getnext(&res.ht_n, name, &it)) { - if (nvme_ns_get_ctrl(n)) { - fprintf(stderr, "%s", nvme_ctrl_get_name(nvme_ns_get_ctrl(n))); + if (libnvme_ns_get_ctrl(n)) { + fprintf(stderr, "%s", libnvme_ctrl_get_name(libnvme_ns_get_ctrl(n))); break; } - nvme_namespace_for_each_path(n, p) { - c = nvme_path_get_ctrl(p); - fprintf(stderr, "%s%s", first ? "" : ", ", nvme_ctrl_get_name(c)); + libnvme_namespace_for_each_path(n, p) { + c = libnvme_path_get_ctrl(p); + fprintf(stderr, "%s%s", first ? "" : ", ", libnvme_ctrl_get_name(c)); if (first) first = false; } @@ -6830,8 +6830,8 @@ static void stdout_relatives(struct nvme_global_ctx *ctx, const char *name) c = htable_ctrl_get(&res.ht_c, name); if (c) { fprintf(stderr, "Controller %s has child namespace(s):", name); - nvme_ctrl_for_each_ns(c, n) { - fprintf(stderr, "%s%s", first ? "" : ", ", nvme_ns_get_name(n)); + libnvme_ctrl_for_each_ns(c, n) { + fprintf(stderr, "%s%s", first ? "" : ", ", libnvme_ns_get_name(n)); if (first) first = false; } diff --git a/nvme-print.c b/nvme-print.c index 92c27646ba..4519474273 100644 --- a/nvme-print.c +++ b/nvme-print.c @@ -378,7 +378,7 @@ void nvme_show_supported_cap_config_log( nvme_print(supported_cap_config_list_log, flags, cap); } -void nvme_show_subsystem_list(struct nvme_global_ctx *ctx, bool show_ana, +void nvme_show_subsystem_list(struct libnvme_global_ctx *ctx, bool show_ana, nvme_print_flags_t flags) { nvme_print(print_nvme_subsystem_list, flags, ctx, show_ana); @@ -493,7 +493,7 @@ void nvme_show_single_property(int offset, uint64_t value64, nvme_print_flags_t nvme_print(single_property, flags, offset, value64); } -void nvme_show_relatives(struct nvme_global_ctx *ctx, const char *name, +void nvme_show_relatives(struct libnvme_global_ctx *ctx, const char *name, nvme_print_flags_t flags) { nvme_print(relatives, flags, ctx, name); @@ -527,7 +527,7 @@ static void nvme_show_cmd_err(const char *msg, bool admin, __u8 opcode, int err) if (!err) return; else if (err < 0) - nvme_show_error("%s: %s", msg, nvme_strerror(-err)); + nvme_show_error("%s: %s", msg, libnvme_strerror(-err)); else if (opcode) nvme_show_opcode_status(err, admin, opcode); else @@ -1624,25 +1624,25 @@ void nvme_show_lba_status(struct nvme_lba_status *list, unsigned long len, nvme_print(lba_status, flags, list, len); } -void nvme_dev_full_path(nvme_ns_t n, char *path, size_t len) +void nvme_dev_full_path(libnvme_ns_t n, char *path, size_t len) { struct stat st; - snprintf(path, len, "%s", nvme_ns_get_name(n)); + snprintf(path, len, "%s", libnvme_ns_get_name(n)); if (strncmp(path, "/dev/spdk/", 10) == 0 && stat(path, &st) == 0) return; - snprintf(path, len, "/dev/%s", nvme_ns_get_name(n)); + snprintf(path, len, "/dev/%s", libnvme_ns_get_name(n)); if (stat(path, &st) == 0) return; /* * We could start trying to search for it but let's make * it simple and just don't show the path at all. */ - snprintf(path, len, "%s", nvme_ns_get_name(n)); + snprintf(path, len, "%s", libnvme_ns_get_name(n)); } -void nvme_generic_full_path(nvme_ns_t n, char *path, size_t len) +void nvme_generic_full_path(libnvme_ns_t n, char *path, size_t len) { int head_instance; int instance; @@ -1652,11 +1652,11 @@ void nvme_generic_full_path(nvme_ns_t n, char *path, size_t len) * There is no block devices for SPDK, point generic path to existing * chardevice. */ - snprintf(path, len, "%s", nvme_ns_get_name(n)); + snprintf(path, len, "%s", libnvme_ns_get_name(n)); if (strncmp(path, "/dev/spdk/", 10) == 0 && stat(path, &st) == 0) return; - sscanf(nvme_ns_get_name(n), "nvme%dn%d", &instance, &head_instance); + sscanf(libnvme_ns_get_name(n), "nvme%dn%d", &instance, &head_instance); snprintf(path, len, "/dev/ng%dn%d", instance, head_instance); if (stat(path, &st) == 0) @@ -1668,17 +1668,17 @@ void nvme_generic_full_path(nvme_ns_t n, char *path, size_t len) snprintf(path, len, "ng%dn%d", instance, head_instance); } -void nvme_show_list_item(nvme_ns_t n, struct table *t) +void nvme_show_list_item(libnvme_ns_t n, struct table *t) { nvme_print(list_item, NORMAL, n, t); } -void nvme_show_list_items(struct nvme_global_ctx *ctx, nvme_print_flags_t flags) +void nvme_show_list_items(struct libnvme_global_ctx *ctx, nvme_print_flags_t flags) { nvme_print(list_items, flags, ctx); } -void nvme_show_topology(struct nvme_global_ctx *ctx, +void nvme_show_topology(struct libnvme_global_ctx *ctx, enum nvme_cli_topo_ranking ranking, nvme_print_flags_t flags) { @@ -1690,7 +1690,7 @@ void nvme_show_topology(struct nvme_global_ctx *ctx, nvme_print(topology_multipath, flags, ctx); } -void nvme_show_topology_tabular(struct nvme_global_ctx *ctx, nvme_print_flags_t flags) +void nvme_show_topology_tabular(struct libnvme_global_ctx *ctx, nvme_print_flags_t flags) { nvme_print(topology_tabular, flags, ctx); } @@ -1749,7 +1749,7 @@ void nvme_show_discovery_log(struct nvmf_discovery_log *log, uint64_t numrec, nvme_print(discovery_log, flags, log, numrec); } -void nvme_show_connect_msg(nvme_ctrl_t c, nvme_print_flags_t flags) +void nvme_show_connect_msg(libnvme_ctrl_t c, nvme_print_flags_t flags) { nvme_print(connect_msg, flags, c); } diff --git a/nvme-print.h b/nvme-print.h index a5b9ddb7ed..289f2e2d7e 100644 --- a/nvme-print.h +++ b/nvme-print.h @@ -68,7 +68,7 @@ struct print_ops { void (*predictable_latency_event_agg_log)(struct nvme_aggregate_predictable_lat_event *pea_log, __u64 log_entries, __u32 size, const char *devname); void (*predictable_latency_per_nvmset)(struct nvme_nvmset_predictable_lat_log *plpns_log, __u16 nvmset_id, const char *devname); void (*primary_ctrl_cap)(const struct nvme_primary_ctrl_cap *caps); - void (*relatives)(struct nvme_global_ctx *ctx, const char *name); + void (*relatives)(struct libnvme_global_ctx *ctx, const char *name); void (*resv_notification_log)(struct nvme_resv_notification_log *resv, const char *devname); void (*resv_report)(struct nvme_resv_status *status, int bytes, bool eds); void (*sanitize_log_page)(struct nvme_sanitize_log_page *sanitize_log, const char *devname); @@ -105,16 +105,16 @@ struct print_ops { void (*log)(const char *devname, struct nvme_get_log_args *args); /* libnvme tree print functions */ - void (*list_item)(nvme_ns_t n, struct table *t); - void (*list_items)(struct nvme_global_ctx *ctx); - void (*print_nvme_subsystem_list)(struct nvme_global_ctx *ctx, bool show_ana); - void (*topology_ctrl)(struct nvme_global_ctx *ctx); - void (*topology_namespace)(struct nvme_global_ctx *ctx); - void (*topology_multipath)(struct nvme_global_ctx *ctx); - void (*topology_tabular)(struct nvme_global_ctx *ctx); + void (*list_item)(libnvme_ns_t n, struct table *t); + void (*list_items)(struct libnvme_global_ctx *ctx); + void (*print_nvme_subsystem_list)(struct libnvme_global_ctx *ctx, bool show_ana); + void (*topology_ctrl)(struct libnvme_global_ctx *ctx); + void (*topology_namespace)(struct libnvme_global_ctx *ctx); + void (*topology_multipath)(struct libnvme_global_ctx *ctx); + void (*topology_tabular)(struct libnvme_global_ctx *ctx); /* status and error messages */ - void (*connect_msg)(nvme_ctrl_t c); + void (*connect_msg)(libnvme_ctrl_t c); void (*show_message)(bool error, const char *msg, va_list ap); void (*show_perror)(const char *msg, va_list ap); void (*show_status)(int status); @@ -166,7 +166,7 @@ void nvme_show_io_cmd_err(const char *msg, __u8 opcode, int err); void nvme_show_admin_cmd_err(const char *msg, __u8 opcode, int err); void nvme_show_opcode_status(int status, bool admin, __u8 opcode); void nvme_show_lba_status_info(__u64 result); -void nvme_show_relatives(struct nvme_global_ctx *ctx, const char *name, nvme_print_flags_t flags); +void nvme_show_relatives(struct libnvme_global_ctx *ctx, const char *name, nvme_print_flags_t flags); void nvme_show_id_iocs(struct nvme_id_iocs *iocs, nvme_print_flags_t flags); void nvme_show_id_ctrl(struct nvme_id_ctrl *ctrl, nvme_print_flags_t flags, @@ -237,8 +237,8 @@ void nvme_show_single_property(int offset, uint64_t prop, nvme_print_flags_t fla void nvme_show_id_ns_descs(void *data, unsigned int nsid, nvme_print_flags_t flags); void nvme_show_lba_status(struct nvme_lba_status *list, unsigned long len, nvme_print_flags_t flags); -void nvme_show_list_items(struct nvme_global_ctx *ctx, nvme_print_flags_t flags); -void nvme_show_subsystem_list(struct nvme_global_ctx *ctx, bool show_ana, +void nvme_show_list_items(struct libnvme_global_ctx *ctx, nvme_print_flags_t flags); +void nvme_show_subsystem_list(struct libnvme_global_ctx *ctx, bool show_ana, nvme_print_flags_t flags); void nvme_show_id_nvmset(struct nvme_id_nvmset_list *nvmset, unsigned nvmset_id, nvme_print_flags_t flags); @@ -258,10 +258,10 @@ void nvme_show_endurance_group_list(struct nvme_id_endurance_group_list *endgrp_ nvme_print_flags_t flags); void nvme_show_list_ns(struct nvme_ns_list *ns_list, nvme_print_flags_t flags); -void nvme_show_topology(struct nvme_global_ctx *ctx, +void nvme_show_topology(struct libnvme_global_ctx *ctx, enum nvme_cli_topo_ranking ranking, nvme_print_flags_t flags); -void nvme_show_topology_tabular(struct nvme_global_ctx *ctx, nvme_print_flags_t flags); +void nvme_show_topology_tabular(struct libnvme_global_ctx *ctx, nvme_print_flags_t flags); void nvme_feature_show(enum nvme_features_id fid, int sel, unsigned int result); void nvme_feature_show_fields(enum nvme_features_id fid, unsigned int result, unsigned char *buf); @@ -290,7 +290,7 @@ void nvme_show_zns_report_zones(void *report, __u32 descs, nvme_print_flags_t flags); void json_nvme_finish_zone_list(__u64 nr_zones, struct json_object *zone_list); -void nvme_show_list_item(nvme_ns_t n, struct table *t); +void nvme_show_list_item(libnvme_ns_t n, struct table *t); void nvme_show_fdp_configs(struct nvme_fdp_config_log *configs, size_t len, nvme_print_flags_t flags); @@ -305,7 +305,7 @@ void nvme_show_fdp_ruh_status(struct nvme_fdp_ruh_status *status, size_t len, void nvme_show_discovery_log(struct nvmf_discovery_log *log, uint64_t numrec, nvme_print_flags_t flags); -void nvme_show_connect_msg(nvme_ctrl_t c, nvme_print_flags_t flags); +void nvme_show_connect_msg(libnvme_ctrl_t c, nvme_print_flags_t flags); const char *nvme_ana_state_to_string(enum nvme_ana_state state); const char *nvme_cmd_to_string(int admin, __u8 opcode); @@ -346,8 +346,8 @@ const char *nvme_power_measurement_type_to_string(__u8 pmt); const char *nvme_power_measurement_action_to_string(__u8 act); const char *nvme_ipmsr_srs_to_string(__u8 srs); -void nvme_dev_full_path(nvme_ns_t n, char *path, size_t len); -void nvme_generic_full_path(nvme_ns_t n, char *path, size_t len); +void nvme_dev_full_path(libnvme_ns_t n, char *path, size_t len); +void nvme_generic_full_path(libnvme_ns_t n, char *path, size_t len); void nvme_show_message(bool error, const char *msg, ...); void nvme_show_perror(const char *msg, ...); void nvme_show_error_status(int status, const char *msg, ...); diff --git a/nvme-rpmb.c b/nvme-rpmb.c index 19cdd24e0a..c4e6b1b489 100644 --- a/nvme-rpmb.c +++ b/nvme-rpmb.c @@ -172,7 +172,7 @@ static int read_file(const char *file, unsigned char **data, unsigned int *len) if (file == NULL) return err; if ((fd = open(file, O_RDONLY)) < 0) { - fprintf(stderr, "Failed to open %s: %s\n", file, nvme_strerror(errno)); + fprintf(stderr, "Failed to open %s: %s\n", file, libnvme_strerror(errno)); return fd; } @@ -193,7 +193,7 @@ static int read_file(const char *file, unsigned char **data, unsigned int *len) if (err < 0) { err = -errno; fprintf(stderr, "Failed to read data from file" - " %s with %s\n", file, nvme_strerror(errno)); + " %s with %s\n", file, libnvme_strerror(errno)); free(buf); goto out; } @@ -275,24 +275,24 @@ struct rpmb_config_block_t { #define RPMB_NVME_SECP 0xEA #define RPMB_NVME_SPSP 0x0001 -static int send_rpmb_req(struct nvme_transport_handle *hdl, unsigned char tgt, +static int send_rpmb_req(struct libnvme_transport_handle *hdl, unsigned char tgt, int size, struct rpmb_data_frame_t *req) { - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; nvme_init_security_send(&cmd, NVME_NSID_NONE, tgt, RPMB_NVME_SPSP, RPMB_NVME_SECP, 0, req, size); - return nvme_submit_admin_passthru(hdl, &cmd); + return libnvme_submit_admin_passthru(hdl, &cmd); } -static int recv_rpmb_rsp(struct nvme_transport_handle *hdl, int tgt, int size, +static int recv_rpmb_rsp(struct libnvme_transport_handle *hdl, int tgt, int size, struct rpmb_data_frame_t *rsp) { - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; nvme_init_security_receive(&cmd, 0, tgt, RPMB_NVME_SPSP, RPMB_NVME_SECP, 0, rsp, size); - return nvme_submit_admin_passthru(hdl, &cmd); + return libnvme_submit_admin_passthru(hdl, &cmd); } /* Initialize nonce value in rpmb request frame */ @@ -398,7 +398,7 @@ static int check_rpmb_response(struct rpmb_data_frame_t *req, * successful completion (caller must free), NULL otherwise */ static struct rpmb_data_frame_t * -rpmb_read_request(struct nvme_transport_handle *hdl, +rpmb_read_request(struct libnvme_transport_handle *hdl, struct rpmb_data_frame_t *req, int req_size, int rsp_size) @@ -442,7 +442,7 @@ rpmb_read_request(struct nvme_transport_handle *hdl, } /* read current write counter value from controller */ -static int rpmb_read_write_counter(struct nvme_transport_handle *hdl, +static int rpmb_read_write_counter(struct libnvme_transport_handle *hdl, unsigned char target, unsigned int *counter) { @@ -470,7 +470,7 @@ static int rpmb_read_write_counter(struct nvme_transport_handle *hdl, * current write counter value returned as part of response, in case of error it * returns 0 */ -static unsigned int rpmb_read_config_block(struct nvme_transport_handle *hdl, +static unsigned int rpmb_read_config_block(struct libnvme_transport_handle *hdl, unsigned char **config_buf) { int req_size = sizeof(struct rpmb_data_frame_t); @@ -511,7 +511,7 @@ static unsigned int rpmb_read_config_block(struct nvme_transport_handle *hdl, } -static int rpmb_auth_data_read(struct nvme_transport_handle *hdl, +static int rpmb_auth_data_read(struct libnvme_transport_handle *hdl, unsigned char target, unsigned int offset, unsigned char **msg_buf, @@ -564,7 +564,7 @@ static int rpmb_auth_data_read(struct nvme_transport_handle *hdl, } /* Implementation of programming authentication key to given RPMB target */ -static int rpmb_program_auth_key(struct nvme_transport_handle *hdl, +static int rpmb_program_auth_key(struct libnvme_transport_handle *hdl, unsigned char target, unsigned char *key_buf, int key_size) { @@ -628,7 +628,7 @@ static int rpmb_program_auth_key(struct nvme_transport_handle *hdl, * number of bytes actually written to, otherwise negetive error code * on failures. */ -static int auth_data_write_chunk(struct nvme_transport_handle *hdl, +static int auth_data_write_chunk(struct libnvme_transport_handle *hdl, unsigned char tgt, unsigned int addr, unsigned char *msg_buf, int msg_size, unsigned char *keybuf, int keysize) @@ -706,7 +706,7 @@ static int auth_data_write_chunk(struct nvme_transport_handle *hdl, } /* send the request and get response */ -static int rpmb_auth_data_write(struct nvme_transport_handle *hdl, +static int rpmb_auth_data_write(struct libnvme_transport_handle *hdl, unsigned char target, unsigned int addr, int acc_size, unsigned char *msg_buf, int msg_size, unsigned char *keybuf, @@ -736,7 +736,7 @@ static int rpmb_auth_data_write(struct nvme_transport_handle *hdl, } /* writes given config_block buffer to the drive target 0 */ -static int rpmb_write_config_block(struct nvme_transport_handle *hdl, +static int rpmb_write_config_block(struct libnvme_transport_handle *hdl, unsigned char *cfg_buf, unsigned char *keybuf, int keysize) { @@ -871,8 +871,8 @@ int rpmb_cmd_option(int argc, char **argv, struct command *acmd, struct plugin * _cleanup_free_ unsigned char *key_buf = NULL; _cleanup_free_ unsigned char *msg_buf = NULL; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; unsigned int write_cntr = 0; unsigned int msg_size = 0; unsigned int key_size = 0; diff --git a/nvme.c b/nvme.c index 4b8823bd4e..ce3f20b437 100644 --- a/nvme.c +++ b/nvme.c @@ -258,7 +258,7 @@ struct nvme_args nvme_args = { .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, }; -static void *mmap_registers(struct nvme_transport_handle *hdl, bool writable); +static void *mmap_registers(struct libnvme_transport_handle *hdl, bool writable); static OPT_VALS(feature_name) = { VAL_BYTE("arbitration", NVME_FEAT_FID_ARBITRATION), @@ -318,9 +318,9 @@ static int check_arg_dev(int argc, char **argv) return 0; } -static int get_transport_handle(struct nvme_global_ctx *ctx, int argc, +static int get_transport_handle(struct libnvme_global_ctx *ctx, int argc, char **argv, int flags, - struct nvme_transport_handle **hdl) + struct libnvme_transport_handle **hdl) { char *devname; int ret; @@ -331,7 +331,7 @@ static int get_transport_handle(struct nvme_global_ctx *ctx, int argc, devname = argv[optind]; - ret = nvme_open(ctx, devname, hdl); + ret = libnvme_open(ctx, devname, hdl); if (ret) nvme_show_err(ret, devname); else if (log_level >= LOG_DEBUG) @@ -354,61 +354,61 @@ static int parse_args(int argc, char *argv[], const char *desc, return 0; } -int parse_and_open(struct nvme_global_ctx **ctx, - struct nvme_transport_handle **hdl, int argc, char **argv, +int parse_and_open(struct libnvme_global_ctx **ctx, + struct libnvme_transport_handle **hdl, int argc, char **argv, const char *desc, struct argconfig_commandline_options *opts) { - struct nvme_transport_handle *hdl_new; - struct nvme_global_ctx *ctx_new; + struct libnvme_transport_handle *hdl_new; + struct libnvme_global_ctx *ctx_new; int ret; ret = parse_args(argc, argv, desc, opts); if (ret) return ret; - ctx_new = nvme_create_global_ctx(stdout, log_level); + ctx_new = libnvme_create_global_ctx(stdout, log_level); if (!ctx_new) return -ENOMEM; - nvme_set_ioctl_probing(ctx_new, + libnvme_set_ioctl_probing(ctx_new, !argconfig_parse_seen(opts, "no-ioctl-probing")); ret = get_transport_handle(ctx_new, argc, argv, O_RDONLY, &hdl_new); if (ret) { - nvme_free_global_ctx(ctx_new); + libnvme_free_global_ctx(ctx_new); argconfig_print_help(desc, opts); return -ENXIO; } - nvme_transport_handle_set_submit_entry(hdl_new, nvme_submit_entry); - nvme_transport_handle_set_submit_exit(hdl_new , nvme_submit_exit); - nvme_transport_handle_set_decide_retry(hdl_new, nvme_decide_retry); - nvme_set_dry_run(ctx_new, argconfig_parse_seen(opts, "dry-run")); + libnvme_transport_handle_set_submit_entry(hdl_new, nvme_submit_entry); + libnvme_transport_handle_set_submit_exit(hdl_new , nvme_submit_exit); + libnvme_transport_handle_set_decide_retry(hdl_new, nvme_decide_retry); + libnvme_set_dry_run(ctx_new, argconfig_parse_seen(opts, "dry-run")); *ctx = ctx_new; *hdl = hdl_new; return 0; } -int open_exclusive(struct nvme_global_ctx **ctx, - struct nvme_transport_handle **hdl, int argc, char **argv, +int open_exclusive(struct libnvme_global_ctx **ctx, + struct libnvme_transport_handle **hdl, int argc, char **argv, int ignore_exclusive) { - struct nvme_transport_handle *hdl_new; - struct nvme_global_ctx *ctx_new; + struct libnvme_transport_handle *hdl_new; + struct libnvme_global_ctx *ctx_new; int flags = O_RDONLY; int ret; if (!ignore_exclusive) flags |= O_EXCL; - ctx_new = nvme_create_global_ctx(stdout, log_level); + ctx_new = libnvme_create_global_ctx(stdout, log_level); if (!ctx_new) return -ENOMEM; ret = get_transport_handle(ctx_new, argc, argv, flags, &hdl_new); if (ret) { - nvme_free_global_ctx(ctx_new); + libnvme_free_global_ctx(ctx_new); return -ENXIO; } @@ -417,14 +417,14 @@ int open_exclusive(struct nvme_global_ctx **ctx, return 0; } -static int open_fallback_chardev(struct nvme_global_ctx *ctx, +static int open_fallback_chardev(struct libnvme_global_ctx *ctx, __u32 nsid, - struct nvme_transport_handle **phdl) + struct libnvme_transport_handle **phdl) { - struct nvme_transport_handle *hdl = *phdl; + struct libnvme_transport_handle *hdl = *phdl; int err; - if (nvme_transport_handle_is_chardev(hdl)) { + if (libnvme_transport_handle_is_chardev(hdl)) { _cleanup_free_ char *cdev = NULL; if (!nsid) { @@ -433,12 +433,12 @@ static int open_fallback_chardev(struct nvme_global_ctx *ctx, } if (asprintf(&cdev, "/dev/%sn%d", - nvme_transport_handle_get_name(hdl), nsid) < 0) + libnvme_transport_handle_get_name(hdl), nsid) < 0) return -ENOMEM; - nvme_close(hdl); + libnvme_close(hdl); - err = nvme_open(ctx, cdev, &hdl); + err = libnvme_open(ctx, cdev, &hdl); if (err) { *phdl = NULL; @@ -495,8 +495,8 @@ static int get_smart_log(int argc, char **argv, struct command *acmd, struct plu "(default) or binary."; _cleanup_free_ struct nvme_smart_log *smart_log = NULL; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; const char *namespace = "(optional) desired namespace"; nvme_print_flags_t flags; int err = -1; @@ -545,7 +545,7 @@ static int get_smart_log(int argc, char **argv, struct command *acmd, struct plu } nvme_show_smart_log(smart_log, cfg.namespace_id, - nvme_transport_handle_get_name(hdl), flags); + libnvme_transport_handle_get_name(hdl), flags); return err; } @@ -557,8 +557,8 @@ static int get_ana_log(int argc, char **argv, struct command *acmd, "decoded format (default), json or binary."; const char *groups = "Return ANA groups only."; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; _cleanup_free_ struct nvme_id_ctrl *ctrl = NULL; _cleanup_free_ struct nvme_ana_log *ana_log = NULL; size_t max_ana_log_len; @@ -595,11 +595,11 @@ static int get_ana_log(int argc, char **argv, struct command *acmd, err = nvme_identify_ctrl(hdl, ctrl); if (err) { nvme_show_error("ERROR : nvme_identify_ctrl() failed: %s", - nvme_strerror(err)); + libnvme_strerror(err)); return err; } - max_ana_log_len = nvme_get_ana_log_len_from_id_ctrl(ctrl, cfg.groups); + max_ana_log_len = libnvme_get_ana_log_len_from_id_ctrl(ctrl, cfg.groups); ana_log_len = max_ana_log_len; if (ana_log_len < max_ana_log_len) { nvme_show_error("ANA log length %zu too large", max_ana_log_len); @@ -610,19 +610,19 @@ static int get_ana_log(int argc, char **argv, struct command *acmd, if (!ana_log) return -ENOMEM; - err = nvme_get_ana_log_atomic(hdl, true, cfg.groups, ana_log, &ana_log_len, 10); + err = libnvme_get_ana_log_atomic(hdl, true, cfg.groups, ana_log, &ana_log_len, 10); if (err) { nvme_show_err(err, "ana-log"); return err; } - nvme_show_ana_log(ana_log, nvme_transport_handle_get_name(hdl), + nvme_show_ana_log(ana_log, libnvme_transport_handle_get_name(hdl), ana_log_len, flags); return err; } -static int parse_telemetry_da(struct nvme_transport_handle *hdl, +static int parse_telemetry_da(struct libnvme_transport_handle *hdl, enum nvme_telemetry_da da, struct nvme_telemetry_log *telem, size_t *size, @@ -671,7 +671,7 @@ static int parse_telemetry_da(struct nvme_transport_handle *hdl, return 0; } -static int get_log_telemetry_ctrl(struct nvme_transport_handle *hdl, bool rae, size_t size, +static int get_log_telemetry_ctrl(struct libnvme_transport_handle *hdl, bool rae, size_t size, struct nvme_telemetry_log **buf) { struct nvme_telemetry_log *log; @@ -691,7 +691,7 @@ static int get_log_telemetry_ctrl(struct nvme_transport_handle *hdl, bool rae, s return 0; } -static int get_log_telemetry_host(struct nvme_transport_handle *hdl, size_t size, +static int get_log_telemetry_host(struct libnvme_transport_handle *hdl, size_t size, struct nvme_telemetry_log **buf) { struct nvme_telemetry_log *log; @@ -711,7 +711,7 @@ static int get_log_telemetry_host(struct nvme_transport_handle *hdl, size_t size return 0; } -static int __create_telemetry_log_host(struct nvme_transport_handle *hdl, +static int __create_telemetry_log_host(struct libnvme_transport_handle *hdl, enum nvme_telemetry_da da, size_t *size, struct nvme_telemetry_log **buf, @@ -735,7 +735,7 @@ static int __create_telemetry_log_host(struct nvme_transport_handle *hdl, return get_log_telemetry_host(hdl, *size, buf); } -static int __get_telemetry_log_ctrl(struct nvme_transport_handle *hdl, +static int __get_telemetry_log_ctrl(struct libnvme_transport_handle *hdl, bool rae, enum nvme_telemetry_da da, size_t *size, @@ -783,7 +783,7 @@ static int __get_telemetry_log_ctrl(struct nvme_transport_handle *hdl, return err; } -static int __get_telemetry_log_host(struct nvme_transport_handle *hdl, +static int __get_telemetry_log_host(struct libnvme_transport_handle *hdl, enum nvme_telemetry_da da, size_t *size, struct nvme_telemetry_log **buf, @@ -821,8 +821,8 @@ static int get_telemetry_log(int argc, char **argv, struct command *acmd, _cleanup_free_ struct nvme_telemetry_log *log = NULL; _cleanup_free_ struct nvme_id_ctrl *id_ctrl = NULL; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; _cleanup_fd_ int output = -1; int err = 0; size_t total_size = 0; @@ -902,7 +902,7 @@ static int get_telemetry_log(int argc, char **argv, struct command *acmd, return -EINVAL; } - err = nvme_set_etdas(hdl, &host_behavior_changed); + err = libnvme_set_etdas(hdl, &host_behavior_changed); if (err) { fprintf(stderr, "%s: Failed to set ETDAS bit\n", __func__); return err; @@ -912,7 +912,7 @@ static int get_telemetry_log(int argc, char **argv, struct command *acmd, output = open(cfg.file_name, O_WRONLY | O_CREAT | O_TRUNC, 0666); if (output < 0) { nvme_show_error("Failed to open output file %s: %s!", - cfg.file_name, nvme_strerror(errno)); + cfg.file_name, libnvme_strerror(errno)); return output; } @@ -947,7 +947,7 @@ static int get_telemetry_log(int argc, char **argv, struct command *acmd, if (data_written < 0) { err = -errno; nvme_show_error("ERROR: %s: : write failed with error : %s", - __func__, nvme_strerror(errno)); + __func__, libnvme_strerror(errno)); break; } else if (data_written <= data_remaining) { data_remaining -= data_written; @@ -962,13 +962,13 @@ static int get_telemetry_log(int argc, char **argv, struct command *acmd, } if (fsync(output) < 0) { - nvme_show_error("ERROR : %s: : fsync : %s", __func__, nvme_strerror(errno)); + nvme_show_error("ERROR : %s: : fsync : %s", __func__, libnvme_strerror(errno)); return -1; } if (host_behavior_changed) { host_behavior_changed = false; - err = nvme_clear_etdas(hdl, &host_behavior_changed); + err = libnvme_clear_etdas(hdl, &host_behavior_changed); if (err) { fprintf(stderr, "%s: Failed to clear ETDAS bit\n", __func__); return err; @@ -984,8 +984,8 @@ static int get_endurance_log(int argc, char **argv, struct command *acmd, struct const char *group_id = "The endurance group identifier"; _cleanup_free_ struct nvme_endurance_group_log *endurance_log = NULL; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; nvme_print_flags_t flags; int err; @@ -1022,12 +1022,12 @@ static int get_endurance_log(int argc, char **argv, struct command *acmd, struct } nvme_show_endurance_log(endurance_log, cfg.group_id, - nvme_transport_handle_get_name(hdl), flags); + libnvme_transport_handle_get_name(hdl), flags); return err; } -static int collect_effects_log(struct nvme_transport_handle *hdl, enum nvme_csi csi, +static int collect_effects_log(struct libnvme_transport_handle *hdl, enum nvme_csi csi, struct list_head *list, int flags) { nvme_effects_log_node_t *node; @@ -1052,9 +1052,9 @@ static int get_effects_log(int argc, char **argv, struct command *acmd, struct p { const char *desc = "Retrieve command effects log page and print the table."; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; - struct nvme_passthru_cmd cmd; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; + struct libnvme_passthru_cmd cmd; struct list_head log_pages; nvme_effects_log_node_t *node; @@ -1101,7 +1101,7 @@ static int get_effects_log(int argc, char **argv, struct command *acmd, struct p if (cfg.csi < 0) { __u64 cap; - if (nvme_transport_handle_is_blkdev(hdl)) { + if (libnvme_transport_handle_is_blkdev(hdl)) { nvme_show_error("Block device isn't allowed without csi"); return -EINVAL; } @@ -1112,7 +1112,7 @@ static int get_effects_log(int argc, char **argv, struct command *acmd, struct p munmap(bar, getpagesize()); } else { nvme_init_get_property(&cmd, NVME_REG_CAP); - err = nvme_submit_admin_passthru(hdl, &cmd); + err = libnvme_submit_admin_passthru(hdl, &cmd); if (err) goto cleanup_list; cap = cmd.result; @@ -1149,8 +1149,8 @@ static int get_supported_log_pages(int argc, char **argv, struct command *acmd, const char *desc = "Retrieve supported logs and print the table."; _cleanup_free_ struct nvme_supported_log_pages *supports = NULL; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; nvme_print_flags_t flags; int err = -1; @@ -1179,7 +1179,7 @@ static int get_supported_log_pages(int argc, char **argv, struct command *acmd, return err; } - nvme_show_supported_log(supports, nvme_transport_handle_get_name(hdl), + nvme_show_supported_log(supports, libnvme_transport_handle_get_name(hdl), flags); return err; @@ -1194,8 +1194,8 @@ static int get_error_log(int argc, char **argv, struct command *acmd, struct plu const char *raw = "dump in binary format"; _cleanup_free_ struct nvme_error_log_page *err_log = NULL; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; struct nvme_id_ctrl ctrl = { 0 }; nvme_print_flags_t flags; int err = -1; @@ -1253,7 +1253,7 @@ static int get_error_log(int argc, char **argv, struct command *acmd, struct plu } nvme_show_error_log(err_log, cfg.log_entries, - nvme_transport_handle_get_name(hdl), flags); + libnvme_transport_handle_get_name(hdl), flags); return err; } @@ -1264,8 +1264,8 @@ static int get_fw_log(int argc, char **argv, struct command *acmd, struct plugin "specified device in either decoded format (default) or binary."; _cleanup_free_ struct nvme_firmware_slot *fw_log = NULL; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; nvme_print_flags_t flags; int err; @@ -1303,7 +1303,7 @@ static int get_fw_log(int argc, char **argv, struct command *acmd, struct plugin return err; } - nvme_show_fw_log(fw_log, nvme_transport_handle_get_name(hdl), flags); + nvme_show_fw_log(fw_log, libnvme_transport_handle_get_name(hdl), flags); return err; } @@ -1312,8 +1312,8 @@ static int get_changed_ns_list_log(int argc, char **argv, bool alloc) { _cleanup_free_ char *desc = NULL; _cleanup_free_ struct nvme_ns_list *changed_ns_list_log = NULL; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; nvme_print_flags_t flags; int err; @@ -1363,7 +1363,7 @@ static int get_changed_ns_list_log(int argc, char **argv, bool alloc) } nvme_show_changed_ns_list_log(changed_ns_list_log, - nvme_transport_handle_get_name(hdl), + libnvme_transport_handle_get_name(hdl), flags, alloc); return err; @@ -1390,8 +1390,8 @@ static int get_pred_lat_per_nvmset_log(int argc, char **argv, const char *nvmset_id = "NVM Set Identifier"; _cleanup_free_ struct nvme_nvmset_predictable_lat_log *plpns_log = NULL; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; nvme_print_flags_t flags; int err; @@ -1434,7 +1434,7 @@ static int get_pred_lat_per_nvmset_log(int argc, char **argv, } nvme_show_predictable_latency_per_nvmset(plpns_log, cfg.nvmset_id, - nvme_transport_handle_get_name(hdl), flags); + libnvme_transport_handle_get_name(hdl), flags); return err; } @@ -1447,8 +1447,8 @@ static int get_pred_lat_event_agg_log(int argc, char **argv, "device in either decoded format(default), json or binary."; const char *log_entries = "Number of pending NVM Set log Entries list"; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; _cleanup_free_ struct nvme_id_ctrl *ctrl = NULL; _cleanup_free_ void *pea_log = NULL; nvme_print_flags_t flags; @@ -1516,7 +1516,7 @@ static int get_pred_lat_event_agg_log(int argc, char **argv, } nvme_show_predictable_latency_event_agg_log(pea_log, cfg.log_entries, - log_size, nvme_transport_handle_get_name(hdl), flags); + log_size, libnvme_transport_handle_get_name(hdl), flags); return err; } @@ -1533,8 +1533,8 @@ static int get_persistent_event_log(int argc, char **argv, _cleanup_free_ struct nvme_persistent_event_log *pevent = NULL; struct nvme_persistent_event_log *pevent_collected = NULL; _cleanup_huge_ struct nvme_mem_huge mh = { 0, }; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; nvme_print_flags_t flags; void *pevent_log_info; int err; @@ -1630,7 +1630,7 @@ static int get_persistent_event_log(int argc, char **argv, } nvme_show_persistent_event_log(pevent_log_info, cfg.action, - cfg.log_len, nvme_transport_handle_get_name(hdl), flags); + cfg.log_len, libnvme_transport_handle_get_name(hdl), flags); return err; } @@ -1643,8 +1643,8 @@ static int get_endurance_event_agg_log(int argc, char **argv, "device in either decoded format(default), json or binary."; const char *log_entries = "Number of pending Endurance Group Event log Entries list"; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; _cleanup_free_ struct nvme_id_ctrl *ctrl = NULL; _cleanup_free_ void *endurance_log = NULL; nvme_print_flags_t flags; @@ -1692,7 +1692,7 @@ static int get_endurance_event_agg_log(int argc, char **argv, err = nvme_identify_ctrl(hdl, ctrl); if (err < 0) { - nvme_show_error("identify controller: %s", nvme_strerror(-err)); + nvme_show_error("identify controller: %s", libnvme_strerror(-err)); return err; } else if (err) { nvme_show_error("could not identify controller"); @@ -1714,7 +1714,7 @@ static int get_endurance_event_agg_log(int argc, char **argv, } nvme_show_endurance_group_event_agg_log(endurance_log, cfg.log_entries, - log_size, nvme_transport_handle_get_name(hdl), flags); + log_size, libnvme_transport_handle_get_name(hdl), flags); return err; } @@ -1725,8 +1725,8 @@ static int get_lba_status_log(int argc, char **argv, const char *desc = "Retrieve Get LBA Status Info Log and prints it, " "for the given device in either decoded format(default),json or binary."; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; _cleanup_free_ void *lba_status = NULL; nvme_print_flags_t flags; __u32 lslplen; @@ -1770,7 +1770,7 @@ static int get_lba_status_log(int argc, char **argv, } nvme_show_lba_status_log(lba_status, lslplen, - nvme_transport_handle_get_name(hdl), flags); + libnvme_transport_handle_get_name(hdl), flags); return err; } @@ -1784,8 +1784,8 @@ static int get_resv_notif_log(int argc, char **argv, "device in either decoded format(default), json or binary."; _cleanup_free_ struct nvme_resv_notification_log *resv = NULL; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; nvme_print_flags_t flags; int err; @@ -1811,7 +1811,7 @@ static int get_resv_notif_log(int argc, char **argv, return err; } - nvme_show_resv_notif_log(resv, nvme_transport_handle_get_name(hdl), + nvme_show_resv_notif_log(resv, libnvme_transport_handle_get_name(hdl), flags); return err; @@ -1825,8 +1825,8 @@ static int get_boot_part_log(int argc, char **argv, struct command *acmd, struct "device in either decoded format(default), json or binary."; const char *fname = "boot partition data output file name"; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; _cleanup_free_ struct nvme_boot_partition *boot = NULL; _cleanup_free_ __u8 *bp_log = NULL; nvme_print_flags_t flags; @@ -1871,7 +1871,7 @@ static int get_boot_part_log(int argc, char **argv, struct command *acmd, struct output = open(cfg.file_name, O_WRONLY | O_CREAT | O_TRUNC, 0666); if (output < 0) { nvme_show_error("Failed to open output file %s: %s!", - cfg.file_name, nvme_strerror(errno)); + cfg.file_name, libnvme_strerror(errno)); return output; } @@ -1897,7 +1897,7 @@ static int get_boot_part_log(int argc, char **argv, struct command *acmd, struct nvme_show_err(err, "boot partition log"); else nvme_show_boot_part_log(&bp_log, - nvme_transport_handle_get_name(hdl), + libnvme_transport_handle_get_name(hdl), sizeof(*boot) + bpsz, flags); err = write(output, (void *) bp_log + sizeof(*boot), bpsz); @@ -1919,8 +1919,8 @@ static int get_phy_rx_eom_log(int argc, char **argv, struct command *acmd, _cleanup_free_ struct nvme_phy_rx_eom_log *phy_rx_eom_log = NULL; size_t phy_rx_eom_log_len; nvme_print_flags_t flags; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; int err = -1; __u8 lsp_tmp; @@ -2004,8 +2004,8 @@ static int get_media_unit_stat_log(int argc, char **argv, struct command *acmd, const char *desc = "Retrieve the configuration and wear of media units and print it"; _cleanup_free_ struct nvme_media_unit_stat_log *mus = NULL; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; nvme_print_flags_t flags; int err = -1; @@ -2057,8 +2057,8 @@ static int get_supp_cap_config_log(int argc, char **argv, struct command *acmd, const char *desc = "Retrieve the list of Supported Capacity Configuration Descriptors"; _cleanup_free_ struct nvme_supported_cap_config_list_log *cap_log = NULL; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; nvme_print_flags_t flags; int err = -1; @@ -2109,11 +2109,11 @@ static int io_mgmt_send(int argc, char **argv, struct command *acmd, struct plug const char *desc = "I/O Management Send"; const char *data = "optional file for data (default stdin)"; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; _cleanup_fd_ int dfd = STDIN_FILENO; _cleanup_free_ void *buf = NULL; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err = -1; struct config { @@ -2140,7 +2140,7 @@ static int io_mgmt_send(int argc, char **argv, struct command *acmd, struct plug return err; if (!cfg.nsid) { - err = nvme_get_nsid(hdl, &cfg.nsid); + err = libnvme_get_nsid(hdl, &cfg.nsid); if (err < 0) { nvme_show_perror("get-namespace-id"); return err; @@ -2168,7 +2168,7 @@ static int io_mgmt_send(int argc, char **argv, struct command *acmd, struct plug } nvme_init_io_mgmt_send(&cmd, cfg.nsid, cfg.mo, cfg.mos, buf, cfg.data_len); - err = nvme_submit_io_passthru(hdl, &cmd); + err = libnvme_submit_io_passthru(hdl, &cmd); if (err) { nvme_show_err(err, "io-mgmt-send"); return err; @@ -2185,10 +2185,10 @@ static int io_mgmt_recv(int argc, char **argv, struct command *acmd, struct plug const char *desc = "I/O Management Receive"; const char *data = "optional file for data (default stdout)"; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; _cleanup_free_ void *buf = NULL; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; _cleanup_fd_ int dfd = -1; int err = -1; @@ -2216,7 +2216,7 @@ static int io_mgmt_recv(int argc, char **argv, struct command *acmd, struct plug return err; if (!cfg.nsid) { - err = nvme_get_nsid(hdl, &cfg.nsid); + err = libnvme_get_nsid(hdl, &cfg.nsid); if (err < 0) { nvme_show_perror("get-namespace-id"); return err; @@ -2231,7 +2231,7 @@ static int io_mgmt_recv(int argc, char **argv, struct command *acmd, struct plug nvme_init_io_mgmt_recv(&cmd, cfg.nsid, cfg.mo, cfg.mos, buf, cfg.data_len); - err = nvme_submit_io_passthru(hdl, &cmd); + err = libnvme_submit_io_passthru(hdl, &cmd); if (err) { nvme_show_err(err, "io-mgmt-recv"); return err; @@ -2273,10 +2273,10 @@ static int get_log(int argc, char **argv, struct command *acmd, struct plugin *p const char *offset_type = "offset type"; const char *xfer_len = "read chunk size (default 4k)"; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; _cleanup_free_ unsigned char *log = NULL; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; nvme_print_flags_t flags; @@ -2432,7 +2432,7 @@ static int get_log(int argc, char **argv, struct command *acmd, struct plugin *p nvme_init_get_log(&cmd, cfg.namespace_id, cfg.log_id, cfg.csi, log, cfg.log_len); if (cfg.ish) { - if (nvme_transport_handle_is_mi(hdl)) + if (libnvme_transport_handle_is_mi(hdl)) nvme_init_mi_cmd_flags(&cmd, ish); else printf("ISH is supported only for NVMe-MI\n"); @@ -2452,7 +2452,7 @@ static int get_log(int argc, char **argv, struct command *acmd, struct plugin *p NVME_LOG_CDW14_OT_SHIFT, NVME_LOG_CDW14_OT_MASK); - err = nvme_get_log(hdl, &cmd, cfg.rae, NVME_LOG_PAGE_PDU_SIZE); + err = libnvme_get_log(hdl, &cmd, cfg.rae, NVME_LOG_PAGE_PDU_SIZE); if (err) { nvme_show_err(err, "log page"); return err; @@ -2460,11 +2460,11 @@ static int get_log(int argc, char **argv, struct command *acmd, struct plugin *p if (!cfg.raw_binary) { printf("Device:%s log-id:%d namespace-id:%#x\n", - nvme_transport_handle_get_name(hdl), cfg.log_id, + libnvme_transport_handle_get_name(hdl), cfg.log_id, cfg.namespace_id); d(log, cfg.log_len, 16, 1); if (argconfig_parse_seen(opts, "verbose")) - nvme_show_log(nvme_transport_handle_get_name(hdl), + nvme_show_log(libnvme_transport_handle_get_name(hdl), &args, VERBOSE); } else { d_raw((unsigned char *)log, cfg.log_len); @@ -2478,8 +2478,8 @@ static int sanitize_log(int argc, char **argv, struct command *acmd, struct plug const char *desc = "Retrieve sanitize log and show it."; _cleanup_free_ struct nvme_sanitize_log_page *sanitize_log = NULL; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; nvme_print_flags_t flags; int err; @@ -2527,7 +2527,7 @@ static int sanitize_log(int argc, char **argv, struct command *acmd, struct plug } nvme_show_sanitize_log(sanitize_log, - nvme_transport_handle_get_name(hdl), flags); + libnvme_transport_handle_get_name(hdl), flags); return err; } @@ -2538,8 +2538,8 @@ static int get_fid_support_effects_log(int argc, char **argv, struct command *ac const char *desc = "Retrieve FID Support and Effects log and show it."; _cleanup_free_ struct nvme_fid_supported_effects_log *fid_support_log = NULL; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; nvme_print_flags_t flags; int err = -1; @@ -2578,7 +2578,7 @@ static int get_fid_support_effects_log(int argc, char **argv, struct command *ac } nvme_show_fid_support_effects_log(fid_support_log, - nvme_transport_handle_get_name(hdl), + libnvme_transport_handle_get_name(hdl), flags); return err; @@ -2590,8 +2590,8 @@ static int get_mi_cmd_support_effects_log(int argc, char **argv, struct command const char *desc = "Retrieve NVMe-MI Command Support and Effects log and show it."; _cleanup_free_ struct nvme_mi_cmd_supported_effects_log *mi_cmd_support_log = NULL; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; nvme_print_flags_t flags; int err = -1; @@ -2630,7 +2630,7 @@ static int get_mi_cmd_support_effects_log(int argc, char **argv, struct command } nvme_show_mi_cmd_support_effects_log(mi_cmd_support_log, - nvme_transport_handle_get_name(hdl), flags); + libnvme_transport_handle_get_name(hdl), flags); return err; } @@ -2642,9 +2642,9 @@ static int list_ctrl(int argc, char **argv, struct command *acmd, struct plugin const char *controller = "controller to display"; _cleanup_free_ struct nvme_ctrl_list *cntlist = NULL; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; - struct nvme_passthru_cmd cmd; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; + struct libnvme_passthru_cmd cmd; nvme_print_flags_t flags; int err; @@ -2682,7 +2682,7 @@ static int list_ctrl(int argc, char **argv, struct command *acmd, struct plugin nvme_init_identify_ns_ctrl_list(&cmd, cfg.namespace_id, cfg.cntid, cntlist); - err = nvme_submit_admin_passthru(hdl, &cmd); + err = libnvme_submit_admin_passthru(hdl, &cmd); if (err) { nvme_show_err(err, "id controller list"); return err; @@ -2702,8 +2702,8 @@ static int list_ns(int argc, char **argv, struct command *acmd, struct plugin *p const char *all = "show all namespaces in the subsystem, whether attached or inactive"; _cleanup_free_ struct nvme_ns_list *ns_list = NULL; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; enum nvme_identify_cns cns; nvme_print_flags_t flags; int err; @@ -2774,8 +2774,8 @@ static int id_ns_lba_format(int argc, char **argv, struct command *acmd, struct "device, returns capability field properties of the specified " "LBA Format index in various formats."; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; _cleanup_free_ struct nvme_id_ns *ns = NULL; nvme_print_flags_t flags; int err = -1; @@ -2832,9 +2832,9 @@ static int id_endurance_grp_list(int argc, char **argv, struct command *acmd, const char *endurance_grp_id = "Endurance Group ID"; _cleanup_free_ struct nvme_id_endurance_group_list *endgrp_list = NULL; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; - struct nvme_passthru_cmd cmd; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; + struct libnvme_passthru_cmd cmd; nvme_print_flags_t flags; int err = -1; @@ -2865,7 +2865,7 @@ static int id_endurance_grp_list(int argc, char **argv, struct command *acmd, nvme_init_identify_endurance_group_id(&cmd, cfg.endgrp_id, endgrp_list); - err = nvme_submit_admin_passthru(hdl, &cmd); + err = libnvme_submit_admin_passthru(hdl, &cmd); if (err) { nvme_show_err(err, "Id endurance group list"); return err; @@ -2876,7 +2876,7 @@ static int id_endurance_grp_list(int argc, char **argv, struct command *acmd, return err; } -static bool is_ns_mgmt_support(struct nvme_transport_handle *hdl) +static bool is_ns_mgmt_support(struct libnvme_transport_handle *hdl) { int err; @@ -2892,10 +2892,10 @@ static bool is_ns_mgmt_support(struct nvme_transport_handle *hdl) return le16_to_cpu(ctrl->oacs) & NVME_CTRL_OACS_NS_MGMT; } -static void ns_mgmt_show_status(struct nvme_transport_handle *hdl, int err, char *cmd, __u32 nsid) +static void ns_mgmt_show_status(struct libnvme_transport_handle *hdl, int err, char *cmd, __u32 nsid) { if (err < 0) { - nvme_show_error("%s: %s", cmd, nvme_strerror(-err)); + nvme_show_error("%s: %s", cmd, libnvme_strerror(-err)); return; } @@ -2923,9 +2923,9 @@ static int delete_ns(int argc, char **argv, struct command *acmd, struct plugin "the namespace is not already inactive, once deleted."; const char *namespace_id = "namespace to delete"; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - struct nvme_passthru_cmd cmd; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + struct libnvme_passthru_cmd cmd; nvme_print_flags_t flags; int err; @@ -2954,21 +2954,21 @@ static int delete_ns(int argc, char **argv, struct command *acmd, struct plugin } if (!cfg.namespace_id) { - err = nvme_get_nsid(hdl, &cfg.namespace_id); + err = libnvme_get_nsid(hdl, &cfg.namespace_id); if (err < 0) { - nvme_show_error("get-namespace-id: %s", nvme_strerror(-err)); + nvme_show_error("get-namespace-id: %s", libnvme_strerror(-err)); return err; } } nvme_init_ns_mgmt_delete(&cmd, cfg.namespace_id); if (cfg.ish) { - if (nvme_transport_handle_is_mi(hdl)) + if (libnvme_transport_handle_is_mi(hdl)) nvme_init_mi_cmd_flags(&cmd, ish); else printf("ISH is supported only for NVMe-MI\n"); } - err = nvme_submit_admin_passthru(hdl, &cmd); + err = libnvme_submit_admin_passthru(hdl, &cmd); ns_mgmt_show_status(hdl, err, acmd->name, cfg.namespace_id); return err; @@ -2976,12 +2976,12 @@ static int delete_ns(int argc, char **argv, struct command *acmd, struct plugin static int nvme_attach_ns(int argc, char **argv, int attach, const char *desc, struct command *acmd) { - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; _cleanup_free_ struct nvme_ctrl_list *cntlist = NULL; __u16 list[NVME_ID_CTRL_LIST_MAX]; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; nvme_print_flags_t flags; int err, num; @@ -3015,9 +3015,9 @@ static int nvme_attach_ns(int argc, char **argv, int attach, const char *desc, s return err; } - if (nvme_transport_handle_is_blkdev(hdl)) { + if (libnvme_transport_handle_is_blkdev(hdl)) { nvme_show_error("%s: a block device opened (dev: %s, nsid: %d)", acmd->name, - nvme_transport_handle_get_name(hdl), cfg.nsid); + libnvme_transport_handle_get_name(hdl), cfg.nsid); return -EINVAL; } @@ -3044,7 +3044,7 @@ static int nvme_attach_ns(int argc, char **argv, int attach, const char *desc, s err = nvme_identify_ctrl(hdl, &ctrl); if (err) { - fprintf(stderr, "identify-ctrl %s\n", nvme_strerror(-err)); + fprintf(stderr, "identify-ctrl %s\n", libnvme_strerror(-err)); return err; } cntlist->num = cpu_to_le16(1); @@ -3057,12 +3057,12 @@ static int nvme_attach_ns(int argc, char **argv, int attach, const char *desc, s nvme_init_ns_detach_ctrls(&cmd, cfg.nsid, cntlist); if (cfg.ish) { - if (nvme_transport_handle_is_mi(hdl)) + if (libnvme_transport_handle_is_mi(hdl)) nvme_init_mi_cmd_flags(&cmd, ish); else printf("ISH is supported only for NVMe-MI\n"); } - err = nvme_submit_admin_passthru(hdl, &cmd); + err = libnvme_submit_admin_passthru(hdl, &cmd); ns_mgmt_show_status(hdl, err, acmd->name, cfg.nsid); return err; @@ -3089,7 +3089,7 @@ static int detach_ns(int argc, char **argv, struct command *acmd, struct plugin return nvme_attach_ns(argc, argv, 0, desc, acmd); } -static int parse_lba_num_si(struct nvme_transport_handle *hdl, const char *opt, +static int parse_lba_num_si(struct libnvme_transport_handle *hdl, const char *opt, const char *val, __u8 flbas, __u64 *num, __u64 align) { _cleanup_free_ struct nvme_ns_list *ns_list = NULL; @@ -3197,15 +3197,15 @@ static int create_ns(int argc, char **argv, struct command *acmd, struct plugin "Requested Number of ZRWA Resources (RNUMZRWA) for Zoned Namespace Command Set"; const char *phndls = "Comma separated list of Placement Handle Associated RUH"; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; _cleanup_free_ struct nvme_ns_mgmt_host_sw_specified *data = NULL; _cleanup_free_ struct nvme_id_ns_granularity_list *gr_list = NULL; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; _cleanup_free_ struct nvme_id_ctrl *id = NULL; _cleanup_free_ struct nvme_id_ns *ns = NULL; __u64 align_nsze = 1 << 20; /* Default 1 MiB */ __u64 align_ncap = align_nsze; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; uint16_t phndl[128] = { 0, }; nvme_print_flags_t flags; uint16_t num_phandle; @@ -3424,49 +3424,49 @@ static int create_ns(int argc, char **argv, struct command *acmd, struct plugin nvme_init_ns_mgmt_create(&cmd, cfg.csi, data); if (cfg.ish) { - if (nvme_transport_handle_is_mi(hdl)) + if (libnvme_transport_handle_is_mi(hdl)) nvme_init_mi_cmd_flags(&cmd, ish); else printf("ISH is supported only for NVMe-MI\n"); } - err = nvme_submit_admin_passthru(hdl, &cmd); + err = libnvme_submit_admin_passthru(hdl, &cmd); nsid = cmd.result; ns_mgmt_show_status(hdl, err, acmd->name, nsid); return err; } -static bool nvme_match_devname(char *devname, nvme_ns_t ns) +static bool nvme_match_devname(char *devname, libnvme_ns_t ns) { - nvme_ctrl_t c = nvme_ns_get_ctrl(ns); + libnvme_ctrl_t c = libnvme_ns_get_ctrl(ns); - if (!strcmp(devname, nvme_ns_get_name(ns)) || - (c && !strcmp(devname, nvme_ctrl_get_name(c))) || - !strcmp(devname, nvme_ns_get_generic_name(ns))) + if (!strcmp(devname, libnvme_ns_get_name(ns)) || + (c && !strcmp(devname, libnvme_ctrl_get_name(c))) || + !strcmp(devname, libnvme_ns_get_generic_name(ns))) return true; return false; } -static bool nvme_match_device_filter(nvme_subsystem_t s, - nvme_ctrl_t c, nvme_ns_t ns, void *f_args) +static bool nvme_match_device_filter(libnvme_subsystem_t s, + libnvme_ctrl_t c, libnvme_ns_t ns, void *f_args) { char *devname = f_args; - nvme_ns_t n; + libnvme_ns_t n; if (ns && nvme_match_devname(devname, ns)) return true; if (c) { - s = nvme_ctrl_get_subsystem(c); - nvme_ctrl_for_each_ns(c, n) { + s = libnvme_ctrl_get_subsystem(c); + libnvme_ctrl_for_each_ns(c, n) { if (nvme_match_devname(devname, n)) return true; } } if (s) { - nvme_subsystem_for_each_ns(s, n) { - if (!strcmp(devname, nvme_ns_get_name(n))) + libnvme_subsystem_for_each_ns(s, n) { + if (!strcmp(devname, libnvme_ns_get_name(n))) return true; } } @@ -3477,10 +3477,10 @@ static bool nvme_match_device_filter(nvme_subsystem_t s, static int list_subsys(int argc, char **argv, struct command *acmd, struct plugin *plugin) { - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; nvme_print_flags_t flags; const char *desc = "Retrieve information for subsystems"; - nvme_scan_filter_t filter = NULL; + libnvme_scan_filter_t filter = NULL; char *devname; int err; int nsid = NVME_NSID_ALL; @@ -3504,7 +3504,7 @@ static int list_subsys(int argc, char **argv, struct command *acmd, if (argconfig_parse_seen(opts, "verbose")) flags |= VERBOSE; - ctx = nvme_create_global_ctx(stdout, log_level); + ctx = libnvme_create_global_ctx(stdout, log_level); if (!ctx) { if (devname) nvme_show_error("Failed to scan nvme subsystem for %s", devname); @@ -3524,9 +3524,9 @@ static int list_subsys(int argc, char **argv, struct command *acmd, filter = nvme_match_device_filter; } - err = nvme_scan_topology(ctx, filter, (void *)devname); + err = libnvme_scan_topology(ctx, filter, (void *)devname); if (err) { - nvme_show_error("Failed to scan topology: %s", nvme_strerror(err)); + nvme_show_error("Failed to scan topology: %s", libnvme_strerror(err)); return -errno; } @@ -3539,7 +3539,7 @@ static int list(int argc, char **argv, struct command *acmd, struct plugin *plug { const char *desc = "Retrieve basic information for all NVMe namespaces"; nvme_print_flags_t flags; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; int err = 0; NVME_ARGS(opts); @@ -3557,14 +3557,14 @@ static int list(int argc, char **argv, struct command *acmd, struct plugin *plug if (argconfig_parse_seen(opts, "verbose")) flags |= VERBOSE; - ctx = nvme_create_global_ctx(stdout, log_level); + ctx = libnvme_create_global_ctx(stdout, log_level); if (!ctx) { nvme_show_error("Failed to create global context"); return -ENOMEM; } - err = nvme_scan_topology(ctx, NULL, NULL); + err = libnvme_scan_topology(ctx, NULL, NULL); if (err < 0) { - nvme_show_error("Failed to scan topology: %s", nvme_strerror(-err)); + nvme_show_error("Failed to scan topology: %s", libnvme_strerror(-err)); return err; } @@ -3584,8 +3584,8 @@ int __id_ctrl(int argc, char **argv, struct command *acmd, struct plugin *plugin const char *vendor_specific = "dump binary vendor field"; _cleanup_free_ struct nvme_id_ctrl *ctrl = NULL; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; nvme_print_flags_t flags; int err; @@ -3653,9 +3653,9 @@ static int nvm_id_ctrl(int argc, char **argv, struct command *acmd, "the specified controller in various formats."; _cleanup_free_ struct nvme_id_ctrl_nvm *ctrl_nvm = NULL; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; - struct nvme_passthru_cmd cmd; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; + struct libnvme_passthru_cmd cmd; nvme_print_flags_t flags; int err = -1; @@ -3679,7 +3679,7 @@ static int nvm_id_ctrl(int argc, char **argv, struct command *acmd, return -ENOMEM; nvme_init_identify_csi_ctrl(&cmd, NVME_CSI_NVM, ctrl_nvm); - err = nvme_submit_admin_passthru(hdl, &cmd); + err = libnvme_submit_admin_passthru(hdl, &cmd); if (err) { nvme_show_err(err, "nvm identify controller"); return err; @@ -3699,8 +3699,8 @@ static int nvm_id_ns(int argc, char **argv, struct command *acmd, _cleanup_free_ struct nvme_nvm_id_ns *id_ns = NULL; _cleanup_free_ struct nvme_id_ns *ns = NULL; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; nvme_print_flags_t flags; int err = -1; @@ -3732,7 +3732,7 @@ static int nvm_id_ns(int argc, char **argv, struct command *acmd, flags |= VERBOSE; if (!cfg.namespace_id) { - err = nvme_get_nsid(hdl, &cfg.namespace_id); + err = libnvme_get_nsid(hdl, &cfg.namespace_id); if (err < 0) { nvme_show_perror("get-namespace-id"); return err; @@ -3773,8 +3773,8 @@ static int nvm_id_ns_lba_format(int argc, char **argv, struct command *acmd, str _cleanup_free_ struct nvme_nvm_id_ns *nvm_ns = NULL; _cleanup_free_ struct nvme_id_ns *ns = NULL; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; nvme_print_flags_t flags; int err = -1; @@ -3840,8 +3840,8 @@ static int ns_descs(int argc, char **argv, struct command *acmd, struct plugin * "of the specific namespace in either human-readable or binary format."; const char *raw = "show descriptors in binary format"; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; _cleanup_free_ void *nsdescs = NULL; nvme_print_flags_t flags; int err; @@ -3877,9 +3877,9 @@ static int ns_descs(int argc, char **argv, struct command *acmd, struct plugin * flags |= VERBOSE; if (!cfg.namespace_id) { - err = nvme_get_nsid(hdl, &cfg.namespace_id); + err = libnvme_get_nsid(hdl, &cfg.namespace_id); if (err < 0) { - nvme_show_error("get-namespace-id: %s", nvme_strerror(-err)); + nvme_show_error("get-namespace-id: %s", libnvme_strerror(-err)); return err; } } @@ -3908,10 +3908,10 @@ static int id_ns(int argc, char **argv, struct command *acmd, struct plugin *plu const char *force = "Return this namespace, even if not attached (1.2 devices only)"; const char *vendor_specific = "dump binary vendor fields"; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; _cleanup_free_ struct nvme_id_ns *ns = NULL; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; nvme_print_flags_t flags; int err; @@ -3958,9 +3958,9 @@ static int id_ns(int argc, char **argv, struct command *acmd, struct plugin *plu flags |= VERBOSE; if (!cfg.namespace_id) { - err = nvme_get_nsid(hdl, &cfg.namespace_id); + err = libnvme_get_nsid(hdl, &cfg.namespace_id); if (err < 0) { - nvme_show_error("get-namespace-id: %s", nvme_strerror(-err)); + nvme_show_error("get-namespace-id: %s", libnvme_strerror(-err)); return err; } } @@ -3971,7 +3971,7 @@ static int id_ns(int argc, char **argv, struct command *acmd, struct plugin *plu if (cfg.force) { nvme_init_identify_allocated_ns(&cmd, cfg.namespace_id, ns); - err = nvme_submit_admin_passthru(hdl, &cmd); + err = libnvme_submit_admin_passthru(hdl, &cmd); } else { err = nvme_identify_ns(hdl, cfg.namespace_id, ns); } @@ -3994,9 +3994,9 @@ static int cmd_set_independent_id_ns(int argc, char **argv, struct command *acmd "specified namespace in human-readable or binary or json format."; _cleanup_free_ struct nvme_id_independent_id_ns *ns = NULL; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; - struct nvme_passthru_cmd cmd; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; + struct libnvme_passthru_cmd cmd; nvme_print_flags_t flags; int err = -1; @@ -4034,7 +4034,7 @@ static int cmd_set_independent_id_ns(int argc, char **argv, struct command *acmd flags |= VERBOSE; if (!cfg.namespace_id) { - err = nvme_get_nsid(hdl, &cfg.namespace_id); + err = libnvme_get_nsid(hdl, &cfg.namespace_id); if (err < 0) { nvme_show_perror("get-namespace-id"); return err; @@ -4047,7 +4047,7 @@ static int cmd_set_independent_id_ns(int argc, char **argv, struct command *acmd nvme_init_identify_csi_independent_identify_id_ns(&cmd, cfg.namespace_id, ns); - err = nvme_submit_admin_passthru(hdl, &cmd); + err = libnvme_submit_admin_passthru(hdl, &cmd); if (err) { nvme_show_err(err, "I/O command set independent identify namespace"); @@ -4066,8 +4066,8 @@ static int id_ns_granularity(int argc, char **argv, struct command *acmd, struct "in either human-readable or binary format."; _cleanup_free_ struct nvme_id_ns_granularity_list *granularity_list = NULL; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; nvme_print_flags_t flags; int err; @@ -4107,9 +4107,9 @@ static int id_nvmset(int argc, char **argv, struct command *acmd, struct plugin const char *nvmset_id = "NVM Set Identify value"; _cleanup_free_ struct nvme_id_nvmset_list *nvmset = NULL; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; - struct nvme_passthru_cmd cmd; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; + struct libnvme_passthru_cmd cmd; nvme_print_flags_t flags; int err; @@ -4140,7 +4140,7 @@ static int id_nvmset(int argc, char **argv, struct command *acmd, struct plugin nvme_init_identify_nvmset_list(&cmd, NVME_NSID_NONE, cfg.nvmset_id, nvmset); - err = nvme_submit_admin_passthru(hdl, &cmd); + err = libnvme_submit_admin_passthru(hdl, &cmd); if (err) { nvme_show_err(err, "identify nvm set list"); return err; @@ -4160,8 +4160,8 @@ static int id_uuid(int argc, char **argv, struct command *acmd, struct plugin *p const char *human_readable = "show uuid in readable format"; _cleanup_free_ struct nvme_id_uuid_list *uuid_list = NULL; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; nvme_print_flags_t flags; int err; @@ -4218,9 +4218,9 @@ static int id_iocs(int argc, char **argv, struct command *acmd, struct plugin *p const char *controller_id = "identifier of desired controller"; _cleanup_free_ struct nvme_id_iocs *iocs = NULL; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; - struct nvme_passthru_cmd cmd; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; + struct libnvme_passthru_cmd cmd; nvme_print_flags_t flags; int err; @@ -4253,7 +4253,7 @@ static int id_iocs(int argc, char **argv, struct command *acmd, struct plugin *p return -ENOMEM; nvme_init_identify_command_set_structure(&cmd, cfg.cntid, iocs); - err = nvme_submit_admin_passthru(hdl, &cmd); + err = libnvme_submit_admin_passthru(hdl, &cmd); if (err) { nvme_show_err(err, "NVMe Identify I/O Command Set"); return err; @@ -4273,9 +4273,9 @@ static int id_domain(int argc, char **argv, struct command *acmd, struct plugin const char *domain_id = "identifier of desired domain"; _cleanup_free_ struct nvme_id_domain_list *id_domain = NULL; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; - struct nvme_passthru_cmd cmd; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; + struct libnvme_passthru_cmd cmd; nvme_print_flags_t flags; int err; @@ -4305,7 +4305,7 @@ static int id_domain(int argc, char **argv, struct command *acmd, struct plugin return -ENOMEM; nvme_init_identify_domain_list(&cmd, cfg.dom_id, id_domain); - err = nvme_submit_admin_passthru(hdl, &cmd); + err = libnvme_submit_admin_passthru(hdl, &cmd); if (err) { nvme_show_err(err, "NVMe Identify Domain List"); return err; @@ -4322,8 +4322,8 @@ static int get_ns_id(int argc, char **argv, struct command *acmd, struct plugin { const char *desc = "Get namespace ID of a the block device."; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; unsigned int nsid; int err; nvme_print_flags_t flags; @@ -4340,13 +4340,13 @@ static int get_ns_id(int argc, char **argv, struct command *acmd, struct plugin return err; } - err = nvme_get_nsid(hdl, &nsid); + err = libnvme_get_nsid(hdl, &nsid); if (err < 0) { - nvme_show_error("get namespace ID: %s", nvme_strerror(-err)); + nvme_show_error("get namespace ID: %s", libnvme_strerror(-err)); return -errno; } - printf("%s: namespace-id:%d\n", nvme_transport_handle_get_name(hdl), nsid); + printf("%s: namespace-id:%d\n", libnvme_transport_handle_get_name(hdl), nsid); return 0; } @@ -4369,9 +4369,9 @@ static int virtual_mgmt(int argc, char **argv, struct command *acmd, struct plug "9h: Secondary Online"; const char *nr = "Number of Controller Resources(NR)"; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - struct nvme_passthru_cmd cmd; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + struct libnvme_passthru_cmd cmd; int err; struct config { @@ -4399,7 +4399,7 @@ static int virtual_mgmt(int argc, char **argv, struct command *acmd, struct plug return err; nvme_init_virtual_mgmt(&cmd, cfg.act, cfg.rt, cfg.cntlid, cfg.nr); - err = nvme_submit_admin_passthru(hdl, &cmd); + err = libnvme_submit_admin_passthru(hdl, &cmd); if (err) { nvme_show_err(err, "virt-mgmt"); return err; @@ -4419,9 +4419,9 @@ static int primary_ctrl_caps(int argc, char **argv, struct command *acmd, struct "decoded format (default), json or binary."; _cleanup_free_ struct nvme_primary_ctrl_cap *caps = NULL; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; - struct nvme_passthru_cmd cmd; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; + struct libnvme_passthru_cmd cmd; nvme_print_flags_t flags; int err; @@ -4457,7 +4457,7 @@ static int primary_ctrl_caps(int argc, char **argv, struct command *acmd, struct return -ENOMEM; nvme_init_identify_primary_ctrl_cap(&cmd, cfg.cntlid, caps); - err = nvme_submit_admin_passthru(hdl, &cmd); + err = libnvme_submit_admin_passthru(hdl, &cmd); if (err) { nvme_show_err(err, "identify primary controller capabilities"); return err; @@ -4476,9 +4476,9 @@ static int list_secondary_ctrl(int argc, char **argv, struct command *acmd, stru const char *num_entries = "number of entries to retrieve"; _cleanup_free_ struct nvme_secondary_ctrl_list *sc_list = NULL; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; - struct nvme_passthru_cmd cmd; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; + struct libnvme_passthru_cmd cmd; nvme_print_flags_t flags; int err; @@ -4516,7 +4516,7 @@ static int list_secondary_ctrl(int argc, char **argv, struct command *acmd, stru return -ENOMEM; nvme_init_identify_secondary_ctrl_list(&cmd, cfg.cntid, sc_list); - err = nvme_submit_admin_passthru(hdl, &cmd); + err = libnvme_submit_admin_passthru(hdl, &cmd); if (err) { nvme_show_err(err, "id secondary controller list"); return err; @@ -4541,7 +4541,7 @@ static int sleep_self_test(unsigned int seconds) return 0; } -static int wait_self_test(struct nvme_transport_handle *hdl) +static int wait_self_test(struct libnvme_transport_handle *hdl) { static const char spin[] = {'-', '\\', '|', '/' }; _cleanup_free_ struct nvme_self_test_log *log = NULL; @@ -4559,7 +4559,7 @@ static int wait_self_test(struct nvme_transport_handle *hdl) err = nvme_identify_ctrl(hdl, ctrl); if (err) { - nvme_show_error("identify-ctrl: %s", nvme_strerror(err)); + nvme_show_error("identify-ctrl: %s", libnvme_strerror(err)); return err; } @@ -4605,20 +4605,20 @@ static int wait_self_test(struct nvme_transport_handle *hdl) return 0; } -static void abort_self_test(struct nvme_transport_handle *hdl, bool ish, +static void abort_self_test(struct libnvme_transport_handle *hdl, bool ish, __u32 nsid) { - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; nvme_init_dev_self_test(&cmd, nsid, NVME_DST_STC_ABORT); if (ish) { - if (nvme_transport_handle_is_mi(hdl)) + if (libnvme_transport_handle_is_mi(hdl)) nvme_init_mi_cmd_flags(&cmd, ish); else printf("ISH is supported only for NVMe-MI\n"); } - err = nvme_submit_admin_passthru(hdl, &cmd); + err = libnvme_submit_admin_passthru(hdl, &cmd); if (err) { nvme_show_err(err, "Device self-test"); return; @@ -4643,9 +4643,9 @@ static int device_self_test(int argc, char **argv, struct command *acmd, struct "fh Abort the device self-test operation"; const char *wait = "Wait for the test to finish"; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - struct nvme_passthru_cmd cmd; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + struct libnvme_passthru_cmd cmd; nvme_print_flags_t flags; int err; @@ -4706,12 +4706,12 @@ static int device_self_test(int argc, char **argv, struct command *acmd, struct nvme_init_dev_self_test(&cmd, cfg.namespace_id, cfg.stc); if (cfg.ish) { - if (nvme_transport_handle_is_mi(hdl)) + if (libnvme_transport_handle_is_mi(hdl)) nvme_init_mi_cmd_flags(&cmd, ish); else printf("ISH is supported only for NVMe-MI\n"); } - err = nvme_submit_admin_passthru(hdl, &cmd); + err = libnvme_submit_admin_passthru(hdl, &cmd); if (err) { nvme_show_err(err, "Device self-test"); goto check_abort; @@ -4744,8 +4744,8 @@ static int self_test_log(int argc, char **argv, struct command *acmd, struct plu "by default all the 20 entries will be retrieved"; _cleanup_free_ struct nvme_self_test_log *log = NULL; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; nvme_print_flags_t flags; int err; @@ -4784,16 +4784,16 @@ static int self_test_log(int argc, char **argv, struct command *acmd, struct plu } nvme_show_self_test_log(log, cfg.dst_entries, 0, - nvme_transport_handle_get_name(hdl), flags); + libnvme_transport_handle_get_name(hdl), flags); return err; } -static int get_feature_id(struct nvme_transport_handle *hdl, struct feat_cfg *cfg, +static int get_feature_id(struct libnvme_transport_handle *hdl, struct feat_cfg *cfg, void **buf, __u64 *result) { if (!cfg->data_len) - nvme_get_feature_length(cfg->feature_id, cfg->cdw11, + libnvme_get_feature_length(cfg->feature_id, cfg->cdw11, NVME_DATA_TFR_CTRL_TO_HOST, &cfg->data_len); @@ -4844,7 +4844,7 @@ static void get_feature_id_print(struct feat_cfg cfg, int err, __u64 result, !nvme_status_equals(status, type, NVME_SC_INVALID_NS)) nvme_show_status(err); } else { - nvme_show_error("get-feature: %s", nvme_strerror(err)); + nvme_show_error("get-feature: %s", libnvme_strerror(err)); } } @@ -4861,7 +4861,7 @@ static bool is_get_feature_result_set(enum nvme_features_id feature_id) return true; } -static int get_feature_id_changed(struct nvme_transport_handle *hdl, struct feat_cfg cfg, +static int get_feature_id_changed(struct libnvme_transport_handle *hdl, struct feat_cfg cfg, nvme_print_flags_t flags) { _cleanup_free_ void *buf_def = NULL; @@ -4891,7 +4891,7 @@ static int get_feature_id_changed(struct nvme_transport_handle *hdl, struct feat return err; } -static int get_feature_ids(struct nvme_transport_handle *hdl, struct feat_cfg cfg, +static int get_feature_ids(struct libnvme_transport_handle *hdl, struct feat_cfg cfg, nvme_print_flags_t flags) { int err = 0; @@ -4944,8 +4944,8 @@ static int get_feature(int argc, char **argv, struct command *acmd, const char *changed = "show feature changed"; nvme_print_flags_t flags = NORMAL; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; int err; struct feat_cfg cfg = { @@ -4981,10 +4981,10 @@ static int get_feature(int argc, char **argv, struct command *acmd, } if (!argconfig_parse_seen(opts, "namespace-id")) { - err = nvme_get_nsid(hdl, &cfg.namespace_id); + err = libnvme_get_nsid(hdl, &cfg.namespace_id); if (err < 0) { if (errno != ENOTTY) { - nvme_show_error("get-namespace-id: %s", nvme_strerror(-err)); + nvme_show_error("get-namespace-id: %s", libnvme_strerror(-err)); return err; } cfg.namespace_id = NVME_NSID_ALL; @@ -5018,12 +5018,12 @@ static int get_feature(int argc, char **argv, struct command *acmd, * errors. Returns -1 on (fatal) error; signifying that the transfer should * be aborted. */ -static int fw_download_single(struct nvme_transport_handle *hdl, void *fw_buf, +static int fw_download_single(struct libnvme_transport_handle *hdl, void *fw_buf, bool ish, unsigned int fw_len, uint32_t offset, uint32_t len, bool progress, bool ignore_ovr) { const unsigned int max_retries = 3; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; bool retryable, ovr; int err, try; @@ -5032,7 +5032,7 @@ static int fw_download_single(struct nvme_transport_handle *hdl, void *fw_buf, offset, fw_len, (int)(100 * offset / fw_len)); } - if (nvme_transport_handle_is_mi(hdl)) + if (libnvme_transport_handle_is_mi(hdl)) nvme_init_mi_cmd_flags(&cmd, ish); for (try = 0; try < max_retries; try++) { @@ -5045,7 +5045,7 @@ static int fw_download_single(struct nvme_transport_handle *hdl, void *fw_buf, if (err) return err; - err = nvme_submit_admin_passthru(hdl, &cmd); + err = libnvme_submit_admin_passthru(hdl, &cmd); if (!err) return 0; @@ -5121,8 +5121,8 @@ static int fw_download(int argc, char **argv, struct command *acmd, struct plugi const char *progress = "display firmware transfer progress"; const char *ignore_ovr = "ignore overwrite errors"; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; _cleanup_huge_ struct nvme_mem_huge mh = { 0, }; _cleanup_fd_ int fw_fd = -1; unsigned int fw_size, pos; @@ -5171,7 +5171,7 @@ static int fw_download(int argc, char **argv, struct command *acmd, struct plugi fw_fd = open(cfg.fw, O_RDONLY); cfg.offset <<= 2; if (fw_fd < 0) { - nvme_show_error("Failed to open firmware file %s: %s", cfg.fw, nvme_strerror(errno)); + nvme_show_error("Failed to open firmware file %s: %s", cfg.fw, libnvme_strerror(errno)); return -EINVAL; } @@ -5190,7 +5190,7 @@ static int fw_download(int argc, char **argv, struct command *acmd, struct plugi if (cfg.xfer == 0) { err = nvme_identify_ctrl(hdl, &ctrl); if (err) { - nvme_show_error("identify-ctrl: %s", nvme_strerror(err)); + nvme_show_error("identify-ctrl: %s", libnvme_strerror(err)); return err; } if (ctrl.fwug == 0 || ctrl.fwug == 0xff) @@ -5212,11 +5212,11 @@ static int fw_download(int argc, char **argv, struct command *acmd, struct plugi if (read(fw_fd, fw_buf, fw_size) != ((ssize_t)(fw_size))) { err = -errno; - nvme_show_error("read :%s :%s", cfg.fw, nvme_strerror(errno)); + nvme_show_error("read :%s :%s", cfg.fw, libnvme_strerror(errno)); return err; } - if (cfg.ish && !nvme_transport_handle_is_mi(hdl)) { + if (cfg.ish && !libnvme_transport_handle_is_mi(hdl)) { printf("ISH is supported only for NVMe-MI\n"); } @@ -5254,7 +5254,7 @@ static char *nvme_fw_status_reset_type(__u16 status) } } -static bool fw_commit_support_mud(struct nvme_transport_handle *hdl) +static bool fw_commit_support_mud(struct libnvme_transport_handle *hdl) { _cleanup_free_ struct nvme_id_ctrl *ctrl = NULL; int err; @@ -5266,14 +5266,14 @@ static bool fw_commit_support_mud(struct nvme_transport_handle *hdl) err = nvme_identify_ctrl(hdl, ctrl); if (err) - nvme_show_error("identify-ctrl: %s", nvme_strerror(err)); + nvme_show_error("identify-ctrl: %s", libnvme_strerror(err)); else if (ctrl->frmw >> 5 & 0x1) return true; return false; } -static void fw_commit_print_mud(struct nvme_transport_handle *hdl, __u64 result) +static void fw_commit_print_mud(struct libnvme_transport_handle *hdl, __u64 result) { if (!fw_commit_support_mud(hdl)) return; @@ -5330,9 +5330,9 @@ static int fw_commit(int argc, char **argv, struct command *acmd, struct plugin "7 = activate boot partition"; const char *bpid = "[0,1]: boot partition identifier, if applicable (default: 0)"; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; - struct nvme_passthru_cmd cmd; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; + struct libnvme_passthru_cmd cmd; int err; nvme_print_flags_t flags; @@ -5404,12 +5404,12 @@ static int fw_commit(int argc, char **argv, struct command *acmd, struct plugin nvme_init_fw_commit(&cmd, cfg.slot, cfg.action, cfg.bpid); if (cfg.ish) { - if (nvme_transport_handle_is_mi(hdl)) + if (libnvme_transport_handle_is_mi(hdl)) nvme_init_mi_cmd_flags(&cmd, ish); else printf("ISH is supported only for NVMe-MI\n"); } - err = nvme_submit_admin_passthru(hdl, &cmd); + err = libnvme_submit_admin_passthru(hdl, &cmd); if (err) { fw_commit_err(err, cfg.action, cfg.slot, cfg.bpid); return err; @@ -5429,8 +5429,8 @@ static int subsystem_reset(int argc, char **argv, struct command *acmd, struct p { const char *desc = "Resets the NVMe subsystem"; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; int err; NVME_ARGS(opts); @@ -5439,19 +5439,19 @@ static int subsystem_reset(int argc, char **argv, struct command *acmd, struct p if (err) return err; - if (!nvme_transport_handle_is_chardev(hdl)) { + if (!libnvme_transport_handle_is_chardev(hdl)) { nvme_show_error(only_char_dev); return -EINVAL; } - err = nvme_reset_subsystem(hdl); + err = libnvme_reset_subsystem(hdl); if (err < 0) { if (errno == ENOTTY) nvme_show_error("Subsystem-reset: NVM Subsystem Reset not supported."); else - nvme_show_error("Subsystem-reset: %s", nvme_strerror(-err)); + nvme_show_error("Subsystem-reset: %s", libnvme_strerror(-err)); } else if (argconfig_parse_seen(opts, "verbose")) - printf("resetting subsystem through %s\n", nvme_transport_handle_get_name(hdl)); + printf("resetting subsystem through %s\n", libnvme_transport_handle_get_name(hdl)); return err; } @@ -5460,8 +5460,8 @@ static int reset(int argc, char **argv, struct command *acmd, struct plugin *plu { const char *desc = "Resets the NVMe controller\n"; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; int err; NVME_ARGS(opts); @@ -5470,16 +5470,16 @@ static int reset(int argc, char **argv, struct command *acmd, struct plugin *plu if (err) return err; - if (!nvme_transport_handle_is_chardev(hdl)) { + if (!libnvme_transport_handle_is_chardev(hdl)) { nvme_show_error(only_char_dev); return -EINVAL; } - err = nvme_reset_ctrl(hdl); + err = libnvme_reset_ctrl(hdl); if (err < 0) - nvme_show_error("Reset: %s", nvme_strerror(-err)); + nvme_show_error("Reset: %s", libnvme_strerror(-err)); else if (argconfig_parse_seen(opts, "verbose")) - printf("resetting controller %s\n", nvme_transport_handle_get_name(hdl)); + printf("resetting controller %s\n", libnvme_transport_handle_get_name(hdl)); return err; } @@ -5488,8 +5488,8 @@ static int ns_rescan(int argc, char **argv, struct command *acmd, struct plugin { const char *desc = "Rescans the NVMe namespaces\n"; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; int err; nvme_print_flags_t flags; @@ -5499,7 +5499,7 @@ static int ns_rescan(int argc, char **argv, struct command *acmd, struct plugin if (err) return err; - if (!nvme_transport_handle_is_chardev(hdl)) { + if (!libnvme_transport_handle_is_chardev(hdl)) { nvme_show_error(only_char_dev); return -EINVAL; } @@ -5510,11 +5510,11 @@ static int ns_rescan(int argc, char **argv, struct command *acmd, struct plugin return err; } - err = nvme_rescan_ns(hdl); + err = libnvme_rescan_ns(hdl); if (err < 0) - nvme_show_error("Namespace Rescan: %s\n", nvme_strerror(-err)); + nvme_show_error("Namespace Rescan: %s\n", libnvme_strerror(-err)); else if (argconfig_parse_seen(opts, "verbose")) - printf("rescanning namespaces through %s\n", nvme_transport_handle_get_name(hdl)); + printf("rescanning namespaces through %s\n", libnvme_transport_handle_get_name(hdl)); return err; } @@ -5531,9 +5531,9 @@ static int sanitize_cmd(int argc, char **argv, struct command *acmd, struct plug "3 = Start overwrite, 4 = Start crypto erase, 5 = Exit media verification"; const char *ovrpat_desc = "Overwrite pattern."; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - struct nvme_passthru_cmd cmd; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + struct libnvme_passthru_cmd cmd; nvme_print_flags_t flags; int err; @@ -5625,12 +5625,12 @@ static int sanitize_cmd(int argc, char **argv, struct command *acmd, struct plug nvme_init_sanitize_nvm(&cmd, cfg.sanact, cfg.ause, cfg.owpass, cfg.oipbp, cfg.no_dealloc, cfg.emvs, cfg.ovrpat); if (cfg.ish) { - if (nvme_transport_handle_is_mi(hdl)) + if (libnvme_transport_handle_is_mi(hdl)) nvme_init_mi_cmd_flags(&cmd, ish); else printf("ISH is supported only for NVMe-MI\n"); } - err = nvme_submit_admin_passthru(hdl, &cmd); + err = libnvme_submit_admin_passthru(hdl, &cmd); if (err) { nvme_show_err(err, "sanitize"); return err; @@ -5649,11 +5649,11 @@ static int sanitize_ns_cmd(int argc, char **argv, struct command *acmd, "4 = Start a crypto erase namespace sanitize operation,\n" "5 = Exit media verification state"; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - struct nvme_passthru_cmd cmd; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + struct libnvme_passthru_cmd cmd; nvme_print_flags_t flags; int err; @@ -5720,12 +5720,12 @@ static int sanitize_ns_cmd(int argc, char **argv, struct command *acmd, nvme_init_sanitize_ns(&cmd, cfg.sanact, cfg.ause, cfg.emvs); if (cfg.ish) { - if (nvme_transport_handle_is_mi(hdl)) + if (libnvme_transport_handle_is_mi(hdl)) nvme_init_mi_cmd_flags(&cmd, ish); else printf("ISH is supported only for NVMe-MI\n"); } - err = nvme_submit_admin_passthru(hdl, &cmd); + err = libnvme_submit_admin_passthru(hdl, &cmd); if (err) { nvme_show_admin_cmd_err("sanitize ns", cmd.opcode, err); return err; @@ -5734,14 +5734,14 @@ static int sanitize_ns_cmd(int argc, char **argv, struct command *acmd, return err; } -static int nvme_get_single_property(struct nvme_transport_handle *hdl, +static int nvme_get_single_property(struct libnvme_transport_handle *hdl, struct get_reg_config *cfg, __u64 *value) { - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; nvme_init_get_property(&cmd, cfg->offset); - err = nvme_submit_admin_passthru(hdl, &cmd); + err = libnvme_submit_admin_passthru(hdl, &cmd); if (!err) { *value = cmd.result; return 0; @@ -5763,7 +5763,7 @@ static int nvme_get_single_property(struct nvme_transport_handle *hdl, return err; } -static int nvme_get_properties(struct nvme_transport_handle *hdl, void **pbar, +static int nvme_get_properties(struct libnvme_transport_handle *hdl, void **pbar, struct get_reg_config *cfg) { int err, size = getpagesize(); @@ -5802,7 +5802,7 @@ static int nvme_get_properties(struct nvme_transport_handle *hdl, void **pbar, return err; } -static void *mmap_registers(struct nvme_transport_handle *hdl, bool writable) +static void *mmap_registers(struct libnvme_transport_handle *hdl, bool writable) { char path[512]; void *membase; @@ -5812,12 +5812,12 @@ static void *mmap_registers(struct nvme_transport_handle *hdl, bool writable) if (writable) prot |= PROT_WRITE; - sprintf(path, "/sys/class/nvme/%s/device/resource0", nvme_transport_handle_get_name(hdl)); + sprintf(path, "/sys/class/nvme/%s/device/resource0", libnvme_transport_handle_get_name(hdl)); fd = open(path, writable ? O_RDWR : O_RDONLY); if (fd < 0) { if (log_level >= LOG_INFO) nvme_show_error("%s did not find a pci resource, open failed %s", - nvme_transport_handle_get_name(hdl), nvme_strerror(errno)); + libnvme_transport_handle_get_name(hdl), libnvme_strerror(errno)); return NULL; } @@ -5844,8 +5844,8 @@ static int show_registers(int argc, char **argv, struct command *acmd, struct pl const char *human_readable = "show info in readable format in case of output_format == normal"; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; nvme_print_flags_t flags; void *bar; int err; @@ -5862,7 +5862,7 @@ static int show_registers(int argc, char **argv, struct command *acmd, struct pl if (err) return err; - if (nvme_transport_handle_is_blkdev(hdl)) { + if (libnvme_transport_handle_is_blkdev(hdl)) { nvme_show_error(only_char_dev); return -EINVAL; } @@ -5964,9 +5964,9 @@ static bool is_reg_selected(struct get_reg_config *cfg, int offset) return false; } -static int get_register_properties(struct nvme_transport_handle *hdl, void **pbar, struct get_reg_config *cfg) +static int get_register_properties(struct libnvme_transport_handle *hdl, void **pbar, struct get_reg_config *cfg) { - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int offset = NVME_REG_CRTO; __u64 value; int size; @@ -5984,11 +5984,11 @@ static int get_register_properties(struct nvme_transport_handle *hdl, void **pba continue; nvme_init_get_property(&cmd, offset); - err = nvme_submit_admin_passthru(hdl, &cmd); + err = libnvme_submit_admin_passthru(hdl, &cmd); if (nvme_status_equals(err, NVME_STATUS_TYPE_NVME, NVME_SC_INVALID_FIELD)) { value = -1; } else if (err) { - nvme_show_error("get-property: %s", nvme_strerror(err)); + nvme_show_error("get-property: %s", libnvme_strerror(err)); free(bar); return err; } else { @@ -6091,8 +6091,8 @@ static int get_register(int argc, char **argv, struct command *acmd, struct plug const char *pmrmscl = "PMRMSCL=0xe14 register offset"; const char *pmrmscu = "PMRMSCU=0xe18 register offset"; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; int err; nvme_print_flags_t flags; bool fabrics = false; @@ -6139,7 +6139,7 @@ static int get_register(int argc, char **argv, struct command *acmd, struct plug if (err) return err; - if (nvme_transport_handle_is_blkdev(hdl)) { + if (libnvme_transport_handle_is_blkdev(hdl)) { nvme_show_error(only_char_dev); return -EINVAL; } @@ -6178,13 +6178,13 @@ static int get_register(int argc, char **argv, struct command *acmd, struct plug return err; } -static int nvme_set_single_property(struct nvme_transport_handle *hdl, int offset, uint64_t value) +static int nvme_set_single_property(struct libnvme_transport_handle *hdl, int offset, uint64_t value) { - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; nvme_init_set_property(&cmd, offset, value); - err = nvme_submit_admin_passthru(hdl, &cmd); + err = libnvme_submit_admin_passthru(hdl, &cmd); if (err) { nvme_show_err(err, "set-property"); return err; @@ -6196,7 +6196,7 @@ static int nvme_set_single_property(struct nvme_transport_handle *hdl, int offse return err; } -static int set_register_property(struct nvme_transport_handle *hdl, int offset, uint64_t value) +static int set_register_property(struct libnvme_transport_handle *hdl, int offset, uint64_t value) { if (!nvme_is_fabrics_reg(offset)) { printf("register: %#04x (%s) not fabrics\n", offset, @@ -6207,7 +6207,7 @@ static int set_register_property(struct nvme_transport_handle *hdl, int offset, return nvme_set_single_property(hdl, offset, value); } -static int nvme_set_register(struct nvme_transport_handle *hdl, void *bar, int offset, uint64_t value, bool mmio32) +static int nvme_set_register(struct libnvme_transport_handle *hdl, void *bar, int offset, uint64_t value, bool mmio32) { if (!bar) return set_register_property(hdl, offset, value); @@ -6289,7 +6289,7 @@ static inline int set_register_names_check(struct argconfig_commandline_options return 0; } -static int set_register_offset(struct nvme_transport_handle *hdl, void *bar, struct argconfig_commandline_options *opts, +static int set_register_offset(struct libnvme_transport_handle *hdl, void *bar, struct argconfig_commandline_options *opts, struct set_reg_config *cfg) { int err; @@ -6312,7 +6312,7 @@ static int set_register_offset(struct nvme_transport_handle *hdl, void *bar, str return 0; } -static int set_register_names(struct nvme_transport_handle *hdl, void *bar, struct argconfig_commandline_options *opts, +static int set_register_names(struct libnvme_transport_handle *hdl, void *bar, struct argconfig_commandline_options *opts, struct set_reg_config *cfg) { int err; @@ -6410,8 +6410,8 @@ static int set_register(int argc, char **argv, struct command *acmd, struct plug const char *value = "the value of the register to be set"; const char *mmio32 = "Access 64-bit registers as 2 32-bit"; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; int err; void *bar; @@ -6443,7 +6443,7 @@ static int set_register(int argc, char **argv, struct command *acmd, struct plug if (err) return err; - if (nvme_transport_handle_is_blkdev(hdl)) { + if (libnvme_transport_handle_is_blkdev(hdl)) { nvme_show_error(only_char_dev); return -EINVAL; } @@ -6470,8 +6470,8 @@ static int get_property(int argc, char **argv, struct command *acmd, struct plug const char *offset = "offset of the requested property"; const char *human_readable = "show property in readable format"; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; __u64 value; int err; nvme_print_flags_t flags = NORMAL; @@ -6518,8 +6518,8 @@ static int set_property(int argc, char **argv, struct command *acmd, struct plug const char *offset = "the offset of the property"; const char *value = "the value of the property to be set"; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; int err; nvme_print_flags_t flags; @@ -6556,18 +6556,18 @@ static int set_property(int argc, char **argv, struct command *acmd, struct plug static void show_relatives(const char *name, nvme_print_flags_t flags) { - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx; int err; - ctx = nvme_create_global_ctx(stderr, log_level); + ctx = libnvme_create_global_ctx(stderr, log_level); if (!ctx) { nvme_show_error("Failed to create global context"); return; } - err = nvme_scan_topology(ctx, NULL, NULL); + err = libnvme_scan_topology(ctx, NULL, NULL); if (err < 0) { - nvme_show_error("Failed to scan topology: %s", nvme_strerror(-err)); + nvme_show_error("Failed to scan topology: %s", libnvme_strerror(-err)); return; } @@ -6589,12 +6589,12 @@ static int format_cmd(int argc, char **argv, struct command *acmd, struct plugin const char *bs = "target block size"; const char *force = "The \"I know what I'm doing\" flag, skip confirmation before sending command"; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; _cleanup_free_ struct nvme_id_ctrl *ctrl = NULL; _cleanup_free_ struct nvme_id_ns *ns = NULL; nvme_print_flags_t flags = NORMAL; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; __u32 timeout_ms = 600000; __u8 prev_lbaf = 0; int block_size; @@ -6684,7 +6684,7 @@ static int format_cmd(int argc, char **argv, struct command *acmd, struct plugin err = nvme_identify_ctrl(hdl, ctrl); if (err) { - nvme_show_error("identify-ctrl: %s", nvme_strerror(err)); + nvme_show_error("identify-ctrl: %s", libnvme_strerror(err)); return -errno; } @@ -6696,9 +6696,9 @@ static int format_cmd(int argc, char **argv, struct command *acmd, struct plugin */ cfg.namespace_id = NVME_NSID_ALL; } else if (!cfg.namespace_id) { - err = nvme_get_nsid(hdl, &cfg.namespace_id); + err = libnvme_get_nsid(hdl, &cfg.namespace_id); if (err < 0) { - nvme_show_error("get-namespace-id: %s", nvme_strerror(-err)); + nvme_show_error("get-namespace-id: %s", libnvme_strerror(-err)); return -errno; } } @@ -6772,9 +6772,9 @@ static int format_cmd(int argc, char **argv, struct command *acmd, struct plugin if (!cfg.force) { fprintf(stderr, "You are about to format %s, namespace %#x%s.\n", - nvme_transport_handle_get_name(hdl), cfg.namespace_id, + libnvme_transport_handle_get_name(hdl), cfg.namespace_id, cfg.namespace_id == NVME_NSID_ALL ? "(ALL namespaces)" : ""); - show_relatives(nvme_transport_handle_get_name(hdl), flags); + show_relatives(libnvme_transport_handle_get_name(hdl), flags); fprintf(stderr, "WARNING: Format may irrevocably delete this device's data.\n" "You have 10 seconds to press Ctrl-C to cancel this operation.\n\n" @@ -6787,21 +6787,21 @@ static int format_cmd(int argc, char **argv, struct command *acmd, struct plugin cfg.pi, cfg.pil, cfg.ses); cmd.timeout_ms = timeout_ms; if (cfg.ish) { - if (nvme_transport_handle_is_mi(hdl)) + if (libnvme_transport_handle_is_mi(hdl)) nvme_init_mi_cmd_flags(&cmd, ish); else printf("ISH is supported only for NVMe-MI\n"); } - err = nvme_submit_admin_passthru(hdl, &cmd); + err = libnvme_submit_admin_passthru(hdl, &cmd); if (err) { nvme_show_err(err, "format"); return err; } printf("Success formatting namespace:%x\n", cfg.namespace_id); - if (nvme_transport_handle_is_direct(hdl) && cfg.lbaf != prev_lbaf) { - if (nvme_transport_handle_is_chardev(hdl)) { - if (nvme_rescan_ns(hdl) < 0) { + if (libnvme_transport_handle_is_direct(hdl) && cfg.lbaf != prev_lbaf) { + if (libnvme_transport_handle_is_chardev(hdl)) { + if (libnvme_rescan_ns(hdl) < 0) { nvme_show_error("failed to rescan namespaces"); return -errno; } @@ -6815,7 +6815,7 @@ static int format_cmd(int argc, char **argv, struct command *acmd, struct plugin * to the given one because blkdev will not * update by itself without re-opening fd. */ - if (ioctl(nvme_transport_handle_get_fd(hdl), BLKBSZSET, + if (ioctl(libnvme_transport_handle_get_fd(hdl), BLKBSZSET, &block_size) < 0) { nvme_show_error( "failed to set block size to %d", @@ -6823,7 +6823,7 @@ static int format_cmd(int argc, char **argv, struct command *acmd, struct plugin return -errno; } - if (ioctl(nvme_transport_handle_get_fd(hdl), + if (ioctl(libnvme_transport_handle_get_fd(hdl), BLKRRPART) < 0) { nvme_show_error( "failed to re-read partition table"); @@ -6831,9 +6831,9 @@ static int format_cmd(int argc, char **argv, struct command *acmd, struct plugin } } } - if (nvme_transport_handle_is_direct(hdl) && cfg.reset && - nvme_transport_handle_is_chardev(hdl)) - nvme_reset_ctrl(hdl); + if (libnvme_transport_handle_is_direct(hdl) && cfg.reset && + libnvme_transport_handle_is_chardev(hdl)) + libnvme_reset_ctrl(hdl); return err; } @@ -6858,8 +6858,8 @@ static int set_feature(int argc, char **argv, struct command *acmd, struct plugi const char *cdw12 = "feature cdw12, if used"; const char *sv = "specifies that the controller shall save the attribute"; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; _cleanup_free_ void *buf = NULL; _cleanup_fd_ int ffd = STDIN_FILENO; int err; @@ -6908,10 +6908,10 @@ static int set_feature(int argc, char **argv, struct command *acmd, struct plugi } if (!argconfig_parse_seen(opts, "namespace-id")) { - err = nvme_get_nsid(hdl, &cfg.nsid); + err = libnvme_get_nsid(hdl, &cfg.nsid); if (err < 0) { if (errno != ENOTTY) { - nvme_show_error("get-namespace-id: %s", nvme_strerror(-err)); + nvme_show_error("get-namespace-id: %s", libnvme_strerror(-err)); return -errno; } cfg.nsid = NVME_NSID_ALL; @@ -6929,7 +6929,7 @@ static int set_feature(int argc, char **argv, struct command *acmd, struct plugi } if (!cfg.data_len) - nvme_get_feature_length(cfg.fid, cfg.value, + libnvme_get_feature_length(cfg.fid, cfg.value, NVME_DATA_TFR_HOST_TO_CTRL, &cfg.data_len); @@ -6955,14 +6955,14 @@ static int set_feature(int argc, char **argv, struct command *acmd, struct plugi if (ffd < 0) { nvme_show_error("Failed to open file %s: %s", - cfg.file, nvme_strerror(errno)); + cfg.file, libnvme_strerror(errno)); return -EINVAL; } err = read(ffd, buf, cfg.data_len); if (err < 0) { nvme_show_error("failed to read data buffer from input file: %s", - nvme_strerror(errno)); + libnvme_strerror(errno)); return -errno; } } @@ -7003,9 +7003,9 @@ static int sec_send(int argc, char **argv, struct command *acmd, struct plugin * const char *file = "transfer payload"; const char *tl = "transfer length (cf. SPC-4)"; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; - struct nvme_passthru_cmd cmd; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; + struct libnvme_passthru_cmd cmd; _cleanup_free_ void *sec_buf = NULL; _cleanup_fd_ int sec_fd = -1; unsigned int sec_size; @@ -7065,7 +7065,7 @@ static int sec_send(int argc, char **argv, struct command *acmd, struct plugin * } else { sec_fd = open(cfg.file, O_RDONLY); if (sec_fd < 0) { - nvme_show_error("Failed to open %s: %s", cfg.file, nvme_strerror(errno)); + nvme_show_error("Failed to open %s: %s", cfg.file, libnvme_strerror(errno)); return -EINVAL; } @@ -7085,19 +7085,19 @@ static int sec_send(int argc, char **argv, struct command *acmd, struct plugin * err = read(sec_fd, sec_buf, sec_size); if (err < 0) { nvme_show_error("Failed to read data from security file %s with %s", cfg.file, - nvme_strerror(errno)); + libnvme_strerror(errno)); return -errno; } nvme_init_security_send(&cmd, cfg.namespace_id, cfg.nssf, cfg.spsp, cfg.secp, cfg.tl, sec_buf, cfg.tl); if (cfg.ish) { - if (nvme_transport_handle_is_mi(hdl)) + if (libnvme_transport_handle_is_mi(hdl)) nvme_init_mi_cmd_flags(&cmd, ish); else printf("ISH is supported only for NVMe-MI\n"); } - err = nvme_submit_admin_passthru(hdl, &cmd); + err = libnvme_submit_admin_passthru(hdl, &cmd); if (err) { nvme_show_err(err, "security-send"); return err; @@ -7115,10 +7115,10 @@ static int dir_send(int argc, char **argv, struct command *acmd, struct plugin * const char *ttype = "target directive type to be enabled/disabled"; const char *input = "write/send file (default stdin)"; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; _cleanup_free_ void *buf = NULL; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; __u32 dw12 = 0; _cleanup_fd_ int ffd = STDIN_FILENO; int err; @@ -7206,7 +7206,7 @@ static int dir_send(int argc, char **argv, struct command *acmd, struct plugin * ffd = open(cfg.file, O_RDONLY); if (ffd <= 0) { nvme_show_error("Failed to open file %s: %s", - cfg.file, nvme_strerror(errno)); + cfg.file, libnvme_strerror(errno)); return -EINVAL; } } @@ -7214,7 +7214,7 @@ static int dir_send(int argc, char **argv, struct command *acmd, struct plugin * if (err < 0) { nvme_show_error( "failed to read data buffer from input file %s", - nvme_strerror(errno)); + libnvme_strerror(errno)); return -errno; } } @@ -7222,7 +7222,7 @@ static int dir_send(int argc, char **argv, struct command *acmd, struct plugin * nvme_init_directive_send(&cmd, cfg.namespace_id, cfg.doper, cfg.dtype, cfg.dspec, buf, cfg.data_len); cmd.cdw12 = dw12; - err = nvme_submit_admin_passthru(hdl, &cmd); + err = libnvme_submit_admin_passthru(hdl, &cmd); if (err) { nvme_show_err(err, "dir-send"); return err; @@ -7248,9 +7248,9 @@ static int write_uncor(int argc, char **argv, struct command *acmd, struct plugi const char *desc = "The Write Uncorrectable command is used to set a range of logical blocks to invalid."; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; - struct nvme_passthru_cmd cmd; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; + struct libnvme_passthru_cmd cmd; int err; struct config { @@ -7281,9 +7281,9 @@ static int write_uncor(int argc, char **argv, struct command *acmd, struct plugi return err; if (!cfg.namespace_id) { - err = nvme_get_nsid(hdl, &cfg.namespace_id); + err = libnvme_get_nsid(hdl, &cfg.namespace_id); if (err < 0) { - nvme_show_error("get-namespace-id: %s", nvme_strerror(-err)); + nvme_show_error("get-namespace-id: %s", libnvme_strerror(-err)); return err; } } @@ -7295,7 +7295,7 @@ static int write_uncor(int argc, char **argv, struct command *acmd, struct plugi nvme_init_write_uncorrectable(&cmd, cfg.namespace_id, cfg.start_block, cfg.block_count, cfg.dtype << 4, cfg.dspec); - err = nvme_submit_io_passthru(hdl, &cmd); + err = libnvme_submit_io_passthru(hdl, &cmd); if (err) { nvme_show_err(err, "write uncorrectable"); return err; @@ -7354,7 +7354,7 @@ static void get_pif_sts(struct nvme_id_ns *ns, struct nvme_nvm_id_ns *nvm_ns, *pif = (elbaf & NVME_NVM_ELBAF_QPIF_MASK) >> 9; } -static int get_pi_info(struct nvme_transport_handle *hdl, +static int get_pi_info(struct libnvme_transport_handle *hdl, __u32 nsid, __u8 prinfo, __u64 ilbrt, __u64 lbst, unsigned int *logical_block_size, __u16 *metadata_size) { @@ -7417,8 +7417,8 @@ static int get_pi_info(struct nvme_transport_handle *hdl, return 0; } -static int init_pi_tags(struct nvme_transport_handle *hdl, - struct nvme_passthru_cmd *cmd, __u32 nsid, __u64 ilbrt, __u64 lbst, +static int init_pi_tags(struct libnvme_transport_handle *hdl, + struct libnvme_passthru_cmd *cmd, __u32 nsid, __u64 ilbrt, __u64 lbst, __u16 lbat, __u16 lbatm) { _cleanup_free_ struct nvme_nvm_id_ns *nvm_ns = NULL; @@ -7464,9 +7464,9 @@ static int init_pi_tags(struct nvme_transport_handle *hdl, static int write_zeroes(int argc, char **argv, struct command *acmd, struct plugin *plugin) { - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - struct nvme_passthru_cmd cmd; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + struct libnvme_passthru_cmd cmd; __u16 control = 0; int err; @@ -7554,9 +7554,9 @@ static int write_zeroes(int argc, char **argv, control |= NVME_IO_NSZ; control |= (cfg.dtype << 4); if (!cfg.nsid) { - err = nvme_get_nsid(hdl, &cfg.nsid); + err = libnvme_get_nsid(hdl, &cfg.nsid); if (err < 0) { - nvme_show_error("get-namespace-id: %s", nvme_strerror(-err)); + nvme_show_error("get-namespace-id: %s", libnvme_strerror(-err)); return err; } } @@ -7569,7 +7569,7 @@ static int write_zeroes(int argc, char **argv, if (err && err != -ENAVAIL) return err; - err = nvme_submit_io_passthru(hdl, &cmd); + err = libnvme_submit_io_passthru(hdl, &cmd); if (err) { nvme_show_err(err, "write-zeroes"); return err; @@ -7603,10 +7603,10 @@ static int dsm(int argc, char **argv, struct command *acmd, struct plugin *plugi const char *idr = "Attribute Integral Dataset for Read"; const char *cdw11 = "All the command DWORD 11 attributes. Use instead of specifying individual attributes"; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; _cleanup_free_ struct nvme_dsm_range *dsm = NULL; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; __u32 ctx_attrs[256] = {0,}; __u32 nlbs[256] = {0,}; __u64 slbas[256] = {0,}; @@ -7674,9 +7674,9 @@ static int dsm(int argc, char **argv, struct command *acmd, struct plugin *plugi } if (!cfg.namespace_id) { - err = nvme_get_nsid(hdl, &cfg.namespace_id); + err = libnvme_get_nsid(hdl, &cfg.namespace_id); if (err < 0) { - nvme_show_error("get-namespace-id: %s", nvme_strerror(-err)); + nvme_show_error("get-namespace-id: %s", libnvme_strerror(-err)); return err; } } @@ -7693,7 +7693,7 @@ static int dsm(int argc, char **argv, struct command *acmd, struct plugin *plugi nvme_init_dsm_range(dsm, ctx_attrs, nlbs, slbas, nb); nvme_init_dsm(&cmd, cfg.namespace_id, nb, cfg.idr, cfg.idw, cfg.ad, dsm, sizeof(*dsm) * nb); - err = nvme_submit_io_passthru(hdl, &cmd); + err = libnvme_submit_io_passthru(hdl, &cmd); if (err) { nvme_show_err(err, "data-set management"); return err; @@ -7728,10 +7728,10 @@ static int copy_cmd(int argc, char **argv, struct command *acmd, struct plugin * const char *d_dspec = "directive specific (write part)"; const char *d_format = "source range entry format"; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; __u16 nr, nb, ns, nrts, natms, nats, nids; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; __u16 nlbs[256] = { 0 }; __u64 slbas[256] = { 0 }; __u32 snsids[256] = { 0 }; @@ -7874,9 +7874,9 @@ static int copy_cmd(int argc, char **argv, struct command *acmd, struct plugin * } if (!cfg.nsid) { - err = nvme_get_nsid(hdl, &cfg.nsid); + err = libnvme_get_nsid(hdl, &cfg.nsid); if (err < 0) { - nvme_show_error("get-namespace-id: %s", nvme_strerror(-err)); + nvme_show_error("get-namespace-id: %s", libnvme_strerror(-err)); return err; } } @@ -7911,7 +7911,7 @@ static int copy_cmd(int argc, char **argv, struct command *acmd, struct plugin * cfg.lbatm); if (err != 0 && err != -ENAVAIL) return err; - err = nvme_submit_io_passthru(hdl, &cmd); + err = libnvme_submit_io_passthru(hdl, &cmd); if (err) { nvme_show_err(err, "NVMe Copy"); return err; @@ -7930,8 +7930,8 @@ static int flush_cmd(int argc, char **argv, struct command *acmd, struct plugin "flushed by the controller, from any namespace, depending on controller and\n" "associated namespace status."; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; int err; struct config { @@ -7954,9 +7954,9 @@ static int flush_cmd(int argc, char **argv, struct command *acmd, struct plugin return err; if (!cfg.namespace_id) { - err = nvme_get_nsid(hdl, &cfg.namespace_id); + err = libnvme_get_nsid(hdl, &cfg.namespace_id); if (err < 0) { - nvme_show_error("get-namespace-id: %s", nvme_strerror(-err)); + nvme_show_error("get-namespace-id: %s", libnvme_strerror(-err)); return err; } } @@ -7982,9 +7982,9 @@ static int resv_acquire(int argc, char **argv, struct command *acmd, struct plug const char *prkey = "pre-empt reservation key"; const char *racqa = "reservation acquire action"; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - struct nvme_passthru_cmd cmd; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + struct libnvme_passthru_cmd cmd; nvme_print_flags_t flags; __le64 payload[2]; int err; @@ -8026,9 +8026,9 @@ static int resv_acquire(int argc, char **argv, struct command *acmd, struct plug } if (!cfg.namespace_id) { - err = nvme_get_nsid(hdl, &cfg.namespace_id); + err = libnvme_get_nsid(hdl, &cfg.namespace_id); if (err < 0) { - nvme_show_error("get-namespace-id: %s", nvme_strerror(-err)); + nvme_show_error("get-namespace-id: %s", libnvme_strerror(-err)); return err; } } @@ -8039,7 +8039,7 @@ static int resv_acquire(int argc, char **argv, struct command *acmd, struct plug nvme_init_resv_acquire(&cmd, cfg.namespace_id, cfg.racqa, cfg.iekey, false, cfg.rtype, cfg.crkey, cfg.prkey, payload); - err = nvme_submit_io_passthru(hdl, &cmd); + err = libnvme_submit_io_passthru(hdl, &cmd); if (err) { nvme_show_err(err, "reservation acquire"); return err; @@ -8059,9 +8059,9 @@ static int resv_register(int argc, char **argv, struct command *acmd, struct plu const char *rrega = "reservation registration action"; const char *cptpl = "change persistence through power loss setting"; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - struct nvme_passthru_cmd cmd; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + struct libnvme_passthru_cmd cmd; nvme_print_flags_t flags; __le64 payload[2]; int err; @@ -8102,9 +8102,9 @@ static int resv_register(int argc, char **argv, struct command *acmd, struct plu } if (!cfg.namespace_id) { - err = nvme_get_nsid(hdl, &cfg.namespace_id); + err = libnvme_get_nsid(hdl, &cfg.namespace_id); if (err < 0) { - nvme_show_error("get-namespace-id: %s", nvme_strerror(-err)); + nvme_show_error("get-namespace-id: %s", libnvme_strerror(-err)); return err; } } @@ -8121,7 +8121,7 @@ static int resv_register(int argc, char **argv, struct command *acmd, struct plu nvme_init_resv_register(&cmd, cfg.namespace_id, cfg.rrega, cfg.iekey, false, cfg.cptpl, cfg.crkey, cfg.nrkey, payload); - err = nvme_submit_io_passthru(hdl, &cmd); + err = libnvme_submit_io_passthru(hdl, &cmd); if (err) { nvme_show_err(err, "reservation register"); return err; @@ -8144,9 +8144,9 @@ static int resv_release(int argc, char **argv, struct command *acmd, struct plug "the issuing controller are notified."; const char *rrela = "reservation release action"; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - struct nvme_passthru_cmd cmd; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + struct libnvme_passthru_cmd cmd; nvme_print_flags_t flags; __le64 payload[1]; int err; @@ -8185,9 +8185,9 @@ static int resv_release(int argc, char **argv, struct command *acmd, struct plug } if (!cfg.nsid) { - err = nvme_get_nsid(hdl, &cfg.nsid); + err = libnvme_get_nsid(hdl, &cfg.nsid); if (err < 0) { - nvme_show_error("get-namespace-id: %s", nvme_strerror(-err)); + nvme_show_error("get-namespace-id: %s", libnvme_strerror(-err)); return err; } } @@ -8198,7 +8198,7 @@ static int resv_release(int argc, char **argv, struct command *acmd, struct plug nvme_init_resv_release(&cmd, cfg.nsid, cfg.rrela, cfg.iekey, false, cfg.rtype, cfg.crkey, payload); - err = nvme_submit_io_passthru(hdl, &cmd); + err = libnvme_submit_io_passthru(hdl, &cmd); if (err) { nvme_show_err(err, "reservation release"); return err; @@ -8218,11 +8218,11 @@ static int resv_report(int argc, char **argv, struct command *acmd, struct plugi const char *numd = "number of dwords to transfer"; const char *eds = "request extended data structure"; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; _cleanup_free_ struct nvme_resv_status *status = NULL; _cleanup_free_ struct nvme_id_ctrl *ctrl = NULL; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; nvme_print_flags_t flags; int err, size; @@ -8260,9 +8260,9 @@ static int resv_report(int argc, char **argv, struct command *acmd, struct plugi flags = BINARY; if (!cfg.nsid) { - err = nvme_get_nsid(hdl, &cfg.nsid); + err = libnvme_get_nsid(hdl, &cfg.nsid); if (err < 0) { - nvme_show_error("get-namespace-id: %s", nvme_strerror(-err)); + nvme_show_error("get-namespace-id: %s", libnvme_strerror(-err)); return err; } } @@ -8280,7 +8280,7 @@ static int resv_report(int argc, char **argv, struct command *acmd, struct plugi err = nvme_identify_ctrl(hdl, ctrl); if (err) { - nvme_show_error("identify-ctrl: %s", nvme_strerror(err)); + nvme_show_error("identify-ctrl: %s", libnvme_strerror(err)); return -errno; } @@ -8292,7 +8292,7 @@ static int resv_report(int argc, char **argv, struct command *acmd, struct plugi return -ENOMEM; nvme_init_resv_report(&cmd, cfg.nsid, cfg.eds, false, status, size); - err = nvme_submit_io_passthru(hdl, &cmd); + err = libnvme_submit_io_passthru(hdl, &cmd); if (err) { nvme_show_err(err, "reservation report"); return err; @@ -8313,8 +8313,8 @@ unsigned long long elapsed_utime(struct timeval start_time, static int submit_io(int opcode, char *command, const char *desc, int argc, char **argv) { - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; unsigned long long buffer_size = 0, mbuffer_size = 0; _cleanup_free_ struct nvme_nvm_id_ns *nvm_ns = NULL; _cleanup_huge_ struct nvme_mem_huge mh = { 0, }; @@ -8324,7 +8324,7 @@ static int submit_io(int opcode, char *command, const char *desc, int argc, char _cleanup_free_ void *mbuffer = NULL; _cleanup_fd_ int dfd = -1, mfd = -1; __u16 control = 0, nblocks = 0; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; __u8 sts = 0, pif = 0; bool pi_available; __u32 dsmgmt = 0; @@ -8446,9 +8446,9 @@ static int submit_io(int opcode, char *command, const char *desc, int argc, char } if (!cfg.nsid) { - err = nvme_get_nsid(hdl, &cfg.nsid); + err = libnvme_get_nsid(hdl, &cfg.nsid); if (err < 0) { - nvme_show_error("get-namespace-id: %s", nvme_strerror(-err)); + nvme_show_error("get-namespace-id: %s", libnvme_strerror(-err)); return err; } } @@ -8553,7 +8553,7 @@ static int submit_io(int opcode, char *command, const char *desc, int argc, char err = read(dfd, (void *)buffer, cfg.data_size); if (err < 0) { err = -errno; - nvme_show_error("failed to read data buffer from input file %s", nvme_strerror(errno)); + nvme_show_error("failed to read data buffer from input file %s", libnvme_strerror(errno)); return err; } } @@ -8562,7 +8562,7 @@ static int submit_io(int opcode, char *command, const char *desc, int argc, char err = read(mfd, (void *)mbuffer, mbuffer_size); if (err < 0) { err = -errno; - nvme_show_error("failed to read meta-data buffer from input file %s", nvme_strerror(errno)); + nvme_show_error("failed to read meta-data buffer from input file %s", libnvme_strerror(errno)); return err; } } @@ -8609,7 +8609,7 @@ static int submit_io(int opcode, char *command, const char *desc, int argc, char return err; } gettimeofday(&start_time, NULL); - err = nvme_submit_io_passthru(hdl, &cmd); + err = libnvme_submit_io_passthru(hdl, &cmd); gettimeofday(&end_time, NULL); if (cfg.latency) printf(" latency: %s: %llu us\n", command, elapsed_utime(start_time, end_time)); @@ -8621,13 +8621,13 @@ static int submit_io(int opcode, char *command, const char *desc, int argc, char if (!(opcode & 1) && write(dfd, (void *)buffer, buffer_size) < 0) { nvme_show_error( "write: %s: failed to write buffer to output file", - nvme_strerror(errno)); + libnvme_strerror(errno)); err = -EINVAL; } else if (!(opcode & 1) && cfg.metadata_size && write(mfd, (void *)mbuffer, mbuffer_size) < 0) { nvme_show_error( "write: %s: failed to write meta-data buffer to output file", - nvme_strerror(errno)); + libnvme_strerror(errno)); err = -EINVAL; } else { fprintf(stderr, "%s: Success\n", command); @@ -8663,9 +8663,9 @@ static int write_cmd(int argc, char **argv, struct command *acmd, struct plugin static int verify_cmd(int argc, char **argv, struct command *acmd, struct plugin *plugin) { - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - struct nvme_passthru_cmd cmd; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + struct libnvme_passthru_cmd cmd; __u16 control = 0; int err; @@ -8737,9 +8737,9 @@ static int verify_cmd(int argc, char **argv, struct command *acmd, struct plugin control |= NVME_IO_STC; if (!cfg.nsid) { - err = nvme_get_nsid(hdl, &cfg.nsid); + err = libnvme_get_nsid(hdl, &cfg.nsid); if (err < 0) { - nvme_show_error("get-namespace-id: %s", nvme_strerror(-err)); + nvme_show_error("get-namespace-id: %s", libnvme_strerror(-err)); return err; } } @@ -8750,7 +8750,7 @@ static int verify_cmd(int argc, char **argv, struct command *acmd, struct plugin cfg.lbat, cfg.lbatm); if (err != 0 && err != -ENAVAIL) return err; - err = nvme_submit_io_passthru(hdl, &cmd); + err = libnvme_submit_io_passthru(hdl, &cmd); if (err) { nvme_show_err(err, "verify"); return err; @@ -8772,10 +8772,10 @@ static int sec_recv(int argc, char **argv, struct command *acmd, struct plugin * const char *size = "size of buffer (prints to stdout on success)"; const char *al = "allocation length (cf. SPC-4)"; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; _cleanup_free_ void *sec_buf = NULL; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; nvme_print_flags_t flags; int err; @@ -8828,7 +8828,7 @@ static int sec_recv(int argc, char **argv, struct command *acmd, struct plugin * } if (cfg.ish) { - if (nvme_transport_handle_is_mi(hdl)) + if (libnvme_transport_handle_is_mi(hdl)) nvme_init_mi_cmd_flags(&cmd, ish); else printf("ISH is supported only for NVMe-MI\n"); @@ -8836,7 +8836,7 @@ static int sec_recv(int argc, char **argv, struct command *acmd, struct plugin * nvme_init_security_receive(&cmd, cfg.namespace_id, cfg.nssf, cfg.spsp, cfg.secp, cfg.al, sec_buf, cfg.size); - err = nvme_submit_admin_passthru(hdl, &cmd); + err = libnvme_submit_admin_passthru(hdl, &cmd); if (err) { nvme_show_err(err, "security receive"); return err; @@ -8864,9 +8864,9 @@ static int get_lba_status(int argc, char **argv, struct command *acmd, const char *rl = "Range Length(RL) specifies the length of the range of contiguous LBAs beginning at SLBA"; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; - struct nvme_passthru_cmd cmd; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; + struct libnvme_passthru_cmd cmd; _cleanup_free_ void *buf = NULL; nvme_print_flags_t flags; unsigned long buf_len; @@ -8921,12 +8921,12 @@ static int get_lba_status(int argc, char **argv, struct command *acmd, nvme_init_get_lba_status(&cmd, cfg.namespace_id, cfg.slba, cfg.mndw, cfg.atype, cfg.rl, buf); if (cfg.ish) { - if (nvme_transport_handle_is_mi(hdl)) + if (libnvme_transport_handle_is_mi(hdl)) nvme_init_mi_cmd_flags(&cmd, ish); else printf("ISH is supported only for NVMe-MI\n"); } - err = nvme_submit_admin_passthru(hdl, &cmd); + err = libnvme_submit_admin_passthru(hdl, &cmd); if (err) { nvme_show_err(err, "get lba status"); return err; @@ -8950,9 +8950,9 @@ static int capacity_mgmt(int argc, char **argv, struct command *acmd, struct plu const char *cap_upper = "Most significant 32 bits of the capacity in bytes of the Endurance Group or NVM Set to be created"; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; - struct nvme_passthru_cmd cmd; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; + struct libnvme_passthru_cmd cmd; int err = -1; nvme_print_flags_t flags; @@ -8998,12 +8998,12 @@ static int capacity_mgmt(int argc, char **argv, struct command *acmd, struct plu nvme_init_capacity_mgmt(&cmd, cfg.operation, cfg.element_id, (__u64)cfg.dw12 << 32 | cfg.dw11); if (cfg.ish) { - if (nvme_transport_handle_is_mi(hdl)) + if (libnvme_transport_handle_is_mi(hdl)) nvme_init_mi_cmd_flags(&cmd, ish); else printf("ISH is supported only for NVMe-MI\n"); } - err = nvme_submit_admin_passthru(hdl, &cmd); + err = libnvme_submit_admin_passthru(hdl, &cmd); if (err) { nvme_show_err(err, "capacity management"); return err; @@ -9028,10 +9028,10 @@ static int dir_receive(int argc, char **argv, struct command *acmd, struct plugi const char *nsr = "namespace stream requested"; nvme_print_flags_t flags = NORMAL; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; _cleanup_free_ void *buf = NULL; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; __u32 dw12 = 0; int err; @@ -9120,7 +9120,7 @@ static int dir_receive(int argc, char **argv, struct command *acmd, struct plugi nvme_init_directive_recv(&cmd, cfg.namespace_id, cfg.doper, cfg.dtype, cfg.dspec, buf, cfg.data_len); cmd.cdw12 = dw12; - err = nvme_submit_admin_passthru(hdl, &cmd); + err = libnvme_submit_admin_passthru(hdl, &cmd); if (err) { nvme_show_err(err, "dir-receive"); return err; @@ -9160,9 +9160,9 @@ static int lockdown_cmd(int argc, char **argv, struct command *acmd, struct plug "List that is used by the command.If this field is cleared to 0h,\n" "then no UUID index is specified"; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; - struct nvme_passthru_cmd cmd; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; + struct libnvme_passthru_cmd cmd; int err = -1; struct config { @@ -9212,7 +9212,7 @@ static int lockdown_cmd(int argc, char **argv, struct command *acmd, struct plug nvme_init_lockdown(&cmd, cfg.scp, cfg.prhbt, cfg.ifc, cfg.ofi, cfg.uuid); - err = nvme_submit_admin_passthru(hdl, &cmd); + err = libnvme_submit_admin_passthru(hdl, &cmd); if (err) { nvme_show_err(err, "lockdown"); return err; @@ -9272,8 +9272,8 @@ static int passthru(int argc, char **argv, bool admin, const char *prefill = "prefill buffers with known byte-value, default 0"; _cleanup_huge_ struct nvme_mem_huge mh = { 0, }; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; _cleanup_fd_ int dfd = -1, mfd = -1; int flags; int mode = 0644; @@ -9406,7 +9406,7 @@ static int passthru(int argc, char **argv, bool admin, } else if (cfg.write) { if (read(dfd, data, cfg.data_len) < 0) { err = -errno; - nvme_show_error("failed to read write buffer %s", nvme_strerror(errno)); + nvme_show_error("failed to read write buffer %s", libnvme_strerror(errno)); return err; } } @@ -9436,7 +9436,7 @@ static int passthru(int argc, char **argv, bool admin, gettimeofday(&start_time, NULL); - struct nvme_passthru_cmd cmd = { + struct libnvme_passthru_cmd cmd = { .opcode = cfg.opcode, .flags = cfg.flags, .nsid = cfg.namespace_id, @@ -9455,9 +9455,9 @@ static int passthru(int argc, char **argv, bool admin, .timeout_ms = nvme_args.timeout, }; if (admin) - err = nvme_submit_admin_passthru(hdl, &cmd); + err = libnvme_submit_admin_passthru(hdl, &cmd); else - err = nvme_submit_io_passthru(hdl, &cmd); + err = libnvme_submit_io_passthru(hdl, &cmd); gettimeofday(&end_time, NULL); cmd_name = nvme_cmd_to_string(admin, cfg.opcode); @@ -9501,7 +9501,7 @@ static int gen_hostnqn_cmd(int argc, char **argv, struct command *acmd, struct p { char *hostnqn; - hostnqn = nvme_generate_hostnqn(); + hostnqn = libnvme_generate_hostnqn(); if (!hostnqn) { nvme_show_error("\"%s\" not supported. Install lib uuid and rebuild.", acmd->name); @@ -9516,9 +9516,9 @@ static int show_hostnqn_cmd(int argc, char **argv, struct command *acmd, struct { char *hostnqn; - hostnqn = nvme_read_hostnqn(); + hostnqn = libnvme_read_hostnqn(); if (!hostnqn) - hostnqn = nvme_generate_hostnqn(); + hostnqn = libnvme_generate_hostnqn(); if (!hostnqn) { nvme_show_error("hostnqn is not available -- use nvme gen-hostnqn"); @@ -9543,7 +9543,7 @@ static int gen_dhchap_key(int argc, char **argv, struct command *acmd, struct pl "HMAC function to use for key transformation (0 = none, 1 = SHA-256, 2 = SHA-384, 3 = SHA-512)."; const char *nqn = "Host NQN to use for key transformation."; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; _cleanup_free_ unsigned char *raw_secret = NULL; _cleanup_free_ char *hnqn = NULL; unsigned char key[68]; @@ -9575,7 +9575,7 @@ static int gen_dhchap_key(int argc, char **argv, struct command *acmd, struct pl if (err) return err; - ctx = nvme_create_global_ctx(stderr, log_level); + ctx = libnvme_create_global_ctx(stderr, log_level); if (!ctx) { nvme_show_error("Failed to create global context"); return -ENOMEM; @@ -9618,19 +9618,19 @@ static int gen_dhchap_key(int argc, char **argv, struct command *acmd, struct pl cfg.key_len = 32; } - err = nvme_create_raw_secret(ctx, cfg.secret, cfg.key_len, &raw_secret); + err = libnvme_create_raw_secret(ctx, cfg.secret, cfg.key_len, &raw_secret); if (err) return err; if (!cfg.nqn) { - cfg.nqn = hnqn = nvme_read_hostnqn(); + cfg.nqn = hnqn = libnvme_read_hostnqn(); if (!cfg.nqn) { nvme_show_error("Could not read host NQN"); return -ENOENT; } } - err = nvme_gen_dhchap_key(ctx, cfg.nqn, cfg.hmac, + err = libnvme_gen_dhchap_key(ctx, cfg.nqn, cfg.hmac, cfg.key_len, raw_secret, key); if (err) return err; @@ -9737,7 +9737,7 @@ static int check_dhchap_key(int argc, char **argv, struct command *acmd, struct return 0; } -static int append_keyfile(struct nvme_global_ctx *ctx, const char *keyring, +static int append_keyfile(struct libnvme_global_ctx *ctx, const char *keyring, long id, const char *keyfile) { _cleanup_free_ unsigned char *key_data = NULL; @@ -9749,14 +9749,14 @@ static int append_keyfile(struct nvme_global_ctx *ctx, const char *keyring, long kr_id; char type; - err = nvme_lookup_keyring(ctx, keyring, &kr_id); + err = libnvme_lookup_keyring(ctx, keyring, &kr_id); if (err) { nvme_show_error("Failed to lookup keyring '%s', %s", - keyring, nvme_strerror(-err)); + keyring, libnvme_strerror(-err)); return err; } - identity = nvme_describe_key_serial(ctx, id); + identity = libnvme_describe_key_serial(ctx, id); if (!identity) { nvme_show_error("Failed to get identity info"); return -EINVAL; @@ -9767,18 +9767,18 @@ static int append_keyfile(struct nvme_global_ctx *ctx, const char *keyring, return -EINVAL; } - err = nvme_read_key(ctx, kr_id, id, &key_len, &key_data); + err = libnvme_read_key(ctx, kr_id, id, &key_len, &key_data); if (err) { nvme_show_error("Failed to read back derive TLS PSK, %s", - nvme_strerror(-err)); + libnvme_strerror(-err)); return err; } - err = nvme_export_tls_key_versioned(ctx, ver, hmac, key_data, + err = libnvme_export_tls_key_versioned(ctx, ver, hmac, key_data, key_len, &exported_key); if (err) { nvme_show_error("Failed to export key, %s", - nvme_strerror(-err)); + libnvme_strerror(-err)); return err; } @@ -9787,7 +9787,7 @@ static int append_keyfile(struct nvme_global_ctx *ctx, const char *keyring, fd = fopen(keyfile, "a"); if (!fd) { nvme_show_error("Failed to open '%s', %s", - keyfile, nvme_strerror(errno)); + keyfile, libnvme_strerror(errno)); err = -errno; goto out; } @@ -9795,7 +9795,7 @@ static int append_keyfile(struct nvme_global_ctx *ctx, const char *keyring, err = fprintf(fd, "%s %s\n", identity, exported_key); if (err < 0) { nvme_show_error("Failed to append key to '%s', %s", - keyfile, nvme_strerror(errno)); + keyfile, libnvme_strerror(errno)); err = -errno; } else { err = 0; @@ -9823,7 +9823,7 @@ static int gen_tls_key(int argc, char **argv, struct command *acmd, struct plugi const char *keyfile = "Update key file with the derive TLS PSK."; const char *compat = "Use non-RFC 8446 compliant algorithm for deriving TLS PSK for older implementations"; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; _cleanup_free_ unsigned char *raw_secret = NULL; _cleanup_free_ char *encoded_key = NULL; _cleanup_free_ char *hnqn = NULL; @@ -9887,7 +9887,7 @@ static int gen_tls_key(int argc, char **argv, struct command *acmd, struct plugi return -EINVAL; } if (!cfg.hostnqn) { - cfg.hostnqn = hnqn = nvme_read_hostnqn(); + cfg.hostnqn = hnqn = libnvme_read_hostnqn(); if (!cfg.hostnqn) { nvme_show_error("Failed to read host NQN"); return -EINVAL; @@ -9897,31 +9897,31 @@ static int gen_tls_key(int argc, char **argv, struct command *acmd, struct plugi if (cfg.hmac == 2) key_len = 48; - ctx = nvme_create_global_ctx(stderr, log_level); + ctx = libnvme_create_global_ctx(stderr, log_level); if (!ctx) { nvme_show_error("Failed to create global context"); return -ENOMEM; } - err = nvme_create_raw_secret(ctx, cfg.secret, key_len, &raw_secret); + err = libnvme_create_raw_secret(ctx, cfg.secret, key_len, &raw_secret); if (err) return err; - err = nvme_export_tls_key(ctx, raw_secret, key_len, &encoded_key); + err = libnvme_export_tls_key(ctx, raw_secret, key_len, &encoded_key); if (err) { - nvme_show_error("Failed to export key, %s", nvme_strerror(-err)); + nvme_show_error("Failed to export key, %s", libnvme_strerror(-err)); return err; } printf("%s\n", encoded_key); if (cfg.insert) { if (cfg.compat) - err = nvme_insert_tls_key_compat(ctx, cfg.keyring, + err = libnvme_insert_tls_key_compat(ctx, cfg.keyring, cfg.keytype, cfg.hostnqn, cfg.subsysnqn, cfg.version, cfg.hmac, raw_secret, key_len, &tls_key); else - err = nvme_insert_tls_key_versioned(ctx, cfg.keyring, + err = libnvme_insert_tls_key_versioned(ctx, cfg.keyring, cfg.keytype, cfg.hostnqn, cfg.subsysnqn, cfg.version, cfg.hmac, raw_secret, key_len, &tls_key); @@ -9956,7 +9956,7 @@ static int check_tls_key(int argc, char **argv, struct command *acmd, struct plu const char *keyfile = "Update key file with the derive TLS PSK."; const char *compat = "Use non-RFC 8446 compliant algorithm for checking TLS PSK for older implementations."; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; _cleanup_free_ unsigned char *decoded_key = NULL; _cleanup_free_ char *hnqn = NULL; int decoded_len, err = 0; @@ -10011,13 +10011,13 @@ static int check_tls_key(int argc, char **argv, struct command *acmd, struct plu return -EINVAL; } - ctx = nvme_create_global_ctx(stderr, log_level); + ctx = libnvme_create_global_ctx(stderr, log_level); if (!ctx) { nvme_show_error("Failed to create global context"); return -ENOMEM; } - err = nvme_import_tls_key(ctx, cfg.keydata, &decoded_len, + err = libnvme_import_tls_key(ctx, cfg.keydata, &decoded_len, &hmac, &decoded_key); if (err) { nvme_show_error("Key decoding failed, error %d\n"); @@ -10026,7 +10026,7 @@ static int check_tls_key(int argc, char **argv, struct command *acmd, struct plu if (cfg.subsysnqn) { if (!cfg.hostnqn) { - cfg.hostnqn = hnqn = nvme_read_hostnqn(); + cfg.hostnqn = hnqn = libnvme_read_hostnqn(); if (!cfg.hostnqn) { nvme_show_error("Failed to read host NQN"); return -EINVAL; @@ -10039,13 +10039,13 @@ static int check_tls_key(int argc, char **argv, struct command *acmd, struct plu if (cfg.insert) { if (cfg.compat) - err = nvme_insert_tls_key_compat(ctx, cfg.keyring, + err = libnvme_insert_tls_key_compat(ctx, cfg.keyring, cfg.keytype, cfg.hostnqn, cfg.subsysnqn, cfg.identity, hmac, decoded_key, decoded_len, &tls_key); else - err = nvme_insert_tls_key_versioned(ctx, cfg.keyring, + err = libnvme_insert_tls_key_versioned(ctx, cfg.keyring, cfg.keytype, cfg.hostnqn, cfg.subsysnqn, cfg.identity, hmac, decoded_key, decoded_len, @@ -10066,12 +10066,12 @@ static int check_tls_key(int argc, char **argv, struct command *acmd, struct plu _cleanup_free_ char *tls_id = NULL; if (cfg.compat) - err = nvme_generate_tls_key_identity_compat(ctx, + err = libnvme_generate_tls_key_identity_compat(ctx, cfg.hostnqn, cfg.subsysnqn, cfg.identity, hmac, decoded_key, decoded_len, &tls_id); else - err = nvme_generate_tls_key_identity(ctx, + err = libnvme_generate_tls_key_identity(ctx, cfg.hostnqn, cfg.subsysnqn, cfg.identity, hmac, decoded_key, decoded_len, &tls_id); @@ -10085,7 +10085,7 @@ static int check_tls_key(int argc, char **argv, struct command *acmd, struct plu return 0; } -static void __scan_tls_key(struct nvme_global_ctx *ctx, long keyring_id, +static void __scan_tls_key(struct libnvme_global_ctx *ctx, long keyring_id, long key_id, char *desc, int desc_len, void *data) { FILE *fd = data; @@ -10096,21 +10096,21 @@ static void __scan_tls_key(struct nvme_global_ctx *ctx, long keyring_id, char type; int err; - err = nvme_read_key(ctx, keyring_id, key_id, &key_len, &key_data); + err = libnvme_read_key(ctx, keyring_id, key_id, &key_len, &key_data); if (err) return; if (sscanf(desc, "NVMe%01d%c%02d %*s", &ver, &type, &hmac) != 3) return; - err = nvme_export_tls_key_versioned(ctx, ver, hmac, key_data, key_len, + err = libnvme_export_tls_key_versioned(ctx, ver, hmac, key_data, key_len, &encoded_key); if (err) return; fprintf(fd, "%s %s\n", desc, encoded_key); } -static int import_key(struct nvme_global_ctx *ctx, const char *keyring, +static int import_key(struct libnvme_global_ctx *ctx, const char *keyring, FILE *fd) { long keyring_id, key; @@ -10121,7 +10121,7 @@ static int import_key(struct nvme_global_ctx *ctx, const char *keyring, int linenum = -1, key_len; int err; - err = nvme_lookup_keyring(ctx, keyring, &keyring_id); + err = libnvme_lookup_keyring(ctx, keyring, &keyring_id); if (err) { nvme_show_error("Invalid keyring '%s'", keyring); return err; @@ -10138,13 +10138,13 @@ static int import_key(struct nvme_global_ctx *ctx, const char *keyring, *tls_key = '\0'; tls_key++; tls_key[strcspn(tls_key, "\n")] = 0; - err = nvme_import_tls_key(ctx, tls_key, &key_len, &hmac, &psk); + err = libnvme_import_tls_key(ctx, tls_key, &key_len, &hmac, &psk); if (err) { nvme_show_error("Failed to import key in line %d", linenum); continue; } - err = nvme_update_key(ctx, keyring_id, "psk", tls_str, + err = libnvme_update_key(ctx, keyring_id, "psk", tls_str, psk, key_len, &key); if (err) continue; @@ -10165,7 +10165,7 @@ static int tls_key(int argc, char **argv, struct command *acmd, struct plugin *p const char *export = "Export all keys from the keyring."; const char *revoke = "Revoke key from the keyring."; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; _cleanup_file_ FILE *fd = NULL; mode_t old_umask = 0; int cnt, err = 0; @@ -10200,7 +10200,7 @@ static int tls_key(int argc, char **argv, struct command *acmd, struct plugin *p if (err) return err; - ctx = nvme_create_global_ctx(stderr, log_level); + ctx = libnvme_create_global_ctx(stderr, log_level); if (!ctx) { nvme_show_error("Failed to create global context"); return -ENOMEM; @@ -10238,10 +10238,10 @@ static int tls_key(int argc, char **argv, struct command *acmd, struct plugin *p nvme_show_error("Must specify either --import, --export or --revoke"); return -EINVAL; } else if (cfg.export) { - err = nvme_scan_tls_keys(ctx, cfg.keyring, __scan_tls_key, fd); + err = libnvme_scan_tls_keys(ctx, cfg.keyring, __scan_tls_key, fd); if (err < 0) { nvme_show_error("Export of TLS keys failed with '%s'", - nvme_strerror(-err)); + libnvme_strerror(-err)); return err; } @@ -10253,18 +10253,18 @@ static int tls_key(int argc, char **argv, struct command *acmd, struct plugin *p err = import_key(ctx, cfg.keyring, fd); if (err) { nvme_show_error("Import of TLS keys failed with '%s'", - nvme_strerror(err)); + libnvme_strerror(err)); return err; } if (argconfig_parse_seen(opts, "verbose")) printf("importing from %s\n", cfg.keyfile); } else { - err = nvme_revoke_tls_key(ctx, cfg.keyring, cfg.keytype, + err = libnvme_revoke_tls_key(ctx, cfg.keyring, cfg.keytype, cfg.revoke); if (err) { nvme_show_error("Failed to revoke key '%s'", - nvme_strerror(err)); + libnvme_strerror(err)); return err; } @@ -10285,9 +10285,9 @@ static int show_topology_cmd(int argc, char **argv, struct command *acmd, struct const char *desc = "Show the topology\n"; const char *ranking = "Ranking order: namespace|ctrl|multipath"; nvme_print_flags_t flags; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; char *devname = NULL; - nvme_scan_filter_t filter = NULL; + libnvme_scan_filter_t filter = NULL; enum nvme_cli_topo_ranking rank; int err; @@ -10326,7 +10326,7 @@ static int show_topology_cmd(int argc, char **argv, struct command *acmd, struct return -EINVAL; } - ctx = nvme_create_global_ctx(stderr, log_level); + ctx = libnvme_create_global_ctx(stderr, log_level); if (!ctx) { nvme_show_error("Failed to create global context"); return -ENOMEM; @@ -10346,9 +10346,9 @@ static int show_topology_cmd(int argc, char **argv, struct command *acmd, struct filter = nvme_match_device_filter; } - err = nvme_scan_topology(ctx, filter, (void *)devname); + err = libnvme_scan_topology(ctx, filter, (void *)devname); if (err < 0) { - nvme_show_error("Failed to scan topology: %s", nvme_strerror(-err)); + nvme_show_error("Failed to scan topology: %s", libnvme_strerror(-err)); return err; } @@ -10413,7 +10413,7 @@ static int dim_cmd(int argc, char **argv, struct command *acmd, struct plugin *p } #endif -static int nvme_mi(int argc, char **argv, __u8 admin_opcode, const char *desc) +static int libnvme_mi(int argc, char **argv, __u8 admin_opcode, const char *desc) { const char *opcode = "opcode (required)"; const char *data_len = "data I/O length (bytes)"; @@ -10429,8 +10429,8 @@ static int nvme_mi(int argc, char **argv, __u8 admin_opcode, const char *desc) _cleanup_fd_ int fd = -1; int flags; _cleanup_huge_ struct nvme_mem_huge mh = { 0, }; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; __u32 result; struct config { @@ -10499,13 +10499,13 @@ static int nvme_mi(int argc, char **argv, __u8 admin_opcode, const char *desc) if (send) { if (read(fd, data, cfg.data_len) < 0) { err = -errno; - nvme_show_error("failed to read write buffer %s", nvme_strerror(errno)); + nvme_show_error("failed to read write buffer %s", libnvme_strerror(errno)); return err; } } } - struct nvme_passthru_cmd cmd = { + struct libnvme_passthru_cmd cmd = { .opcode = admin_opcode, .nsid = cfg.namespace_id, .cdw10 = cfg.nmimt << 11 | 4, @@ -10516,7 +10516,7 @@ static int nvme_mi(int argc, char **argv, __u8 admin_opcode, const char *desc) .data_len = cfg.data_len, }; - err = nvme_submit_admin_passthru(hdl, &cmd); + err = libnvme_submit_admin_passthru(hdl, &cmd); if (err) { nvme_show_err(err, "nmi_recv"); return err; @@ -10528,7 +10528,7 @@ static int nvme_mi(int argc, char **argv, __u8 admin_opcode, const char *desc) nvme_cmd_to_string(true, admin_opcode), result, result & 0xff, result >> 8); if (result & 0xff) - printf("status: %s\n", nvme_mi_status_to_string(result & 0xff)); + printf("status: %s\n", libnvme_mi_status_to_string(result & 0xff)); if (!send && strlen(cfg.input_file)) { if (write(fd, (void *)data, cfg.data_len) < 0) perror("failed to write data buffer"); @@ -10544,14 +10544,14 @@ static int nmi_recv(int argc, char **argv, struct command *acmd, struct plugin * const char *desc = "Send a NVMe-MI Receive command to the specified device, return results."; - return nvme_mi(argc, argv, nvme_admin_nvme_mi_recv, desc); + return libnvme_mi(argc, argv, nvme_admin_nvme_mi_recv, desc); } static int nmi_send(int argc, char **argv, struct command *acmd, struct plugin *plugin) { const char *desc = "Send a NVMe-MI Send command to the specified device, return results."; - return nvme_mi(argc, argv, nvme_admin_nvme_mi_send, desc); + return libnvme_mi(argc, argv, nvme_admin_nvme_mi_send, desc); } static int get_mgmt_addr_list_log(int argc, char **argv, struct command *acmd, struct plugin *plugin) @@ -10561,8 +10561,8 @@ static int get_mgmt_addr_list_log(int argc, char **argv, struct command *acmd, s int err = -1; _cleanup_free_ struct nvme_mgmt_addr_list_log *ma_log = NULL; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; NVME_ARGS(opts); @@ -10599,8 +10599,8 @@ static int get_rotational_media_info_log(int argc, char **argv, struct command * int err = -1; _cleanup_free_ struct nvme_rotational_media_info_log *info = NULL; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; struct config { __u16 endgid; @@ -10638,14 +10638,14 @@ static int get_rotational_media_info_log(int argc, char **argv, struct command * return err; } -static int get_dispersed_ns_psub(struct nvme_transport_handle *hdl, __u32 nsid, +static int get_dispersed_ns_psub(struct libnvme_transport_handle *hdl, __u32 nsid, struct nvme_dispersed_ns_participating_nss_log **logp) { int err; __u64 header_len = sizeof(**logp); __u64 psub_list_len; struct nvme_dispersed_ns_participating_nss_log *log = nvme_alloc(header_len); - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; if (!log) return -ENOMEM; @@ -10666,7 +10666,7 @@ static int get_dispersed_ns_psub(struct nvme_transport_handle *hdl, __u32 nsid, (void *)log->participating_nss, psub_list_len); cmd.cdw12 = header_len & 0xffffffff; cmd.cdw13 = header_len >> 32; - err = nvme_get_log(hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); + err = libnvme_get_log(hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); if (err) goto err_free; @@ -10685,8 +10685,8 @@ static int get_dispersed_ns_participating_nss_log(int argc, char **argv, struct nvme_print_flags_t flags; int err; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; _cleanup_free_ struct nvme_dispersed_ns_participating_nss_log *log = NULL; struct config { @@ -10727,8 +10727,8 @@ static int get_power_measurement_log(int argc, char **argv, struct command *acmd "for the given device in either decoded format (default), " "json, or binary."; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; _cleanup_free_ struct nvme_power_meas_log *log = NULL; nvme_print_flags_t flags; __u32 min_log_size = sizeof(struct nvme_power_meas_log); @@ -10797,11 +10797,11 @@ static int get_power_measurement_log(int argc, char **argv, struct command *acmd return err; } -static int get_log_offset(struct nvme_transport_handle *hdl, +static int get_log_offset(struct libnvme_transport_handle *hdl, struct nvme_get_log_args *args, __u64 *offset, __u32 len, void **log) { - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; args->lpo = *offset, @@ -10830,13 +10830,13 @@ static int get_log_offset(struct nvme_transport_handle *hdl, NVME_LOG_CDW14_OT_SHIFT, NVME_LOG_CDW14_OT_MASK); - err = nvme_get_log(hdl, &cmd, args->rae, NVME_LOG_PAGE_PDU_SIZE); + err = libnvme_get_log(hdl, &cmd, args->rae, NVME_LOG_PAGE_PDU_SIZE); if (*args->result) *args->result = cmd.result; return err; } -static int get_reachability_group_desc(struct nvme_transport_handle *hdl, struct nvme_get_log_args *args, +static int get_reachability_group_desc(struct libnvme_transport_handle *hdl, struct nvme_get_log_args *args, __u64 *offset, struct nvme_reachability_groups_log **logp) { int err; @@ -10864,7 +10864,7 @@ static int get_reachability_group_desc(struct nvme_transport_handle *hdl, struct return err; } -static int get_reachability_groups(struct nvme_transport_handle *hdl, bool rgo, bool rae, +static int get_reachability_groups(struct libnvme_transport_handle *hdl, bool rgo, bool rae, struct nvme_reachability_groups_log **logp, __u64 *lenp) { @@ -10908,8 +10908,8 @@ static int get_reachability_groups_log(int argc, char **argv, struct command *ac int err; __u64 len = 0; _cleanup_free_ struct nvme_reachability_groups_log *log = NULL; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; struct config { bool rgo; @@ -10946,7 +10946,7 @@ static int get_reachability_groups_log(int argc, char **argv, struct command *ac return err; } -static int get_reachability_association_desc(struct nvme_transport_handle *hdl, struct nvme_get_log_args *args, +static int get_reachability_association_desc(struct libnvme_transport_handle *hdl, struct nvme_get_log_args *args, __u64 *offset, struct nvme_reachability_associations_log **logp) { @@ -10975,7 +10975,7 @@ static int get_reachability_association_desc(struct nvme_transport_handle *hdl, return err; } -static int get_reachability_associations(struct nvme_transport_handle *hdl, bool rao, bool rae, +static int get_reachability_associations(struct libnvme_transport_handle *hdl, bool rao, bool rae, struct nvme_reachability_associations_log **logp, __u64 *lenp) { @@ -11019,8 +11019,8 @@ static int get_reachability_associations_log(int argc, char **argv, struct comma int err; __u64 len = 0; _cleanup_free_ struct nvme_reachability_associations_log *log = NULL; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; struct config { bool rao; @@ -11057,7 +11057,7 @@ static int get_reachability_associations_log(int argc, char **argv, struct comma return err; } -static int get_host_discovery(struct nvme_transport_handle *hdl, bool allhoste, bool rae, +static int get_host_discovery(struct libnvme_transport_handle *hdl, bool allhoste, bool rae, struct nvme_host_discover_log **logp) { int err; @@ -11099,8 +11099,8 @@ static int get_host_discovery_log(int argc, char **argv, struct command *acmd, s nvme_print_flags_t flags; int err; _cleanup_free_ struct nvme_host_discover_log *log = NULL; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; struct config { bool allhoste; @@ -11138,7 +11138,7 @@ static int get_host_discovery_log(int argc, char **argv, struct command *acmd, s return err; } -static int get_ave_discovery(struct nvme_transport_handle *hdl, bool rae, struct nvme_ave_discover_log **logp) +static int get_ave_discovery(struct libnvme_transport_handle *hdl, bool rae, struct nvme_ave_discover_log **logp) { int err; struct nvme_ave_discover_log *log; @@ -11178,8 +11178,8 @@ static int get_ave_discovery_log(int argc, char **argv, struct command *acmd, st int err; _cleanup_free_ struct nvme_ave_discover_log *log = NULL; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; struct config { bool rae; @@ -11212,7 +11212,7 @@ static int get_ave_discovery_log(int argc, char **argv, struct command *acmd, st return err; } -static int get_pull_model_ddc_req(struct nvme_transport_handle *hdl, +static int get_pull_model_ddc_req(struct libnvme_transport_handle *hdl, bool rae, struct nvme_pull_model_ddc_req_log **logp) { int err; @@ -11254,8 +11254,8 @@ static int get_pull_model_ddc_req_log(int argc, char **argv, struct command *acm int err; _cleanup_free_ struct nvme_pull_model_ddc_req_log *log = NULL; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; struct config { bool rae; diff --git a/nvme.h b/nvme.h index 254dde7ff4..cb9980e2cf 100644 --- a/nvme.h +++ b/nvme.h @@ -93,13 +93,13 @@ struct nvme_args { OPT_END() \ } -static inline bool nvme_is_multipath(nvme_subsystem_t s) +static inline bool nvme_is_multipath(libnvme_subsystem_t s) { - nvme_ns_t n; - nvme_path_t p; + libnvme_ns_t n; + libnvme_path_t p; - nvme_subsystem_for_each_ns(s, n) - nvme_namespace_for_each_path(n, p) + libnvme_subsystem_for_each_ns(s, n) + libnvme_namespace_for_each_path(n, p) return true; return false; @@ -110,13 +110,13 @@ void register_extension(struct plugin *plugin); /* * parse_and_open - parses arguments and opens the NVMe device, populating @ctx, @hdl */ -int parse_and_open(struct nvme_global_ctx **ctx, - struct nvme_transport_handle **hdl, int argc, char **argv, +int parse_and_open(struct libnvme_global_ctx **ctx, + struct libnvme_transport_handle **hdl, int argc, char **argv, const char *desc, struct argconfig_commandline_options *clo); // TODO: unsure if we need a double ptr here static inline DEFINE_CLEANUP_FUNC( - cleanup_nvme_transport_handle, struct nvme_transport_handle *, nvme_close) + cleanup_nvme_transport_handle, struct libnvme_transport_handle *, libnvme_close) #define _cleanup_nvme_transport_handle_ __cleanup__(cleanup_nvme_transport_handle) extern const char *uuid_index; @@ -128,7 +128,7 @@ bool nvme_is_output_format_json(void); int __id_ctrl(int argc, char **argv, struct command *acmd, struct plugin *plugin, void (*vs)(uint8_t *vs, struct json_object *root)); -const char *nvme_strerror(int errnum); +const char *libnvme_strerror(int errnum); unsigned long long elapsed_utime(struct timeval start_time, struct timeval end_time); @@ -142,15 +142,15 @@ void d_raw(unsigned char *buf, unsigned len); int get_reg_size(int offset); bool nvme_is_ctrl_reg(int offset); -static inline int nvme_get_nsid_log(struct nvme_transport_handle *hdl, +static inline int nvme_get_nsid_log(struct libnvme_transport_handle *hdl, __u32 nsid, bool rae, enum nvme_cmd_get_log_lid lid, void *log, __u32 len) { - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; nvme_init_get_log(&cmd, nsid, lid, NVME_CSI_NVM, log, len); - return nvme_get_log(hdl, &cmd, rae, NVME_LOG_PAGE_PDU_SIZE); + return libnvme_get_log(hdl, &cmd, rae, NVME_LOG_PAGE_PDU_SIZE); } #endif /* _NVME_H */ diff --git a/plugin.c b/plugin.c index d0e6ef57f7..eaa7647180 100644 --- a/plugin.c +++ b/plugin.c @@ -21,8 +21,8 @@ static int version_cmd(struct plugin *plugin) prog->name, prog->version, GIT_VERSION); } printf("libnvme version %s (git %s)\n", - nvme_get_version(NVME_VERSION_PROJECT), - nvme_get_version(NVME_VERSION_GIT)); + libnvme_get_version(LIBNVME_VERSION_PROJECT), + libnvme_get_version(LIBNVME_VERSION_GIT)); return 0; } diff --git a/plugins/amzn/amzn-nvme.c b/plugins/amzn/amzn-nvme.c index 5613095144..dc789eb94b 100644 --- a/plugins/amzn/amzn-nvme.c +++ b/plugins/amzn/amzn-nvme.c @@ -561,11 +561,11 @@ static int get_stats(int argc, char **argv, struct command *acmd, struct plugin *plugin) { const char *desc = "display command latency statistics"; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; struct amzn_latency_log_page log = { 0 }; nvme_print_flags_t flags = 0; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; struct nvme_id_ctrl ctrl; bool detail = false; unsigned int interval = 0; @@ -599,7 +599,7 @@ static int get_stats(int argc, char **argv, struct command *acmd, if (!strncmp((char *)ctrl.mn, AMZN_NVME_LOCAL_STORAGE_PREFIX, strlen(AMZN_NVME_LOCAL_STORAGE_PREFIX))) { - if (nvme_get_nsid(hdl, &nsid) < 0) { + if (libnvme_get_nsid(hdl, &nsid) < 0) { struct nvme_id_ctrl test_ctrl; if (nvme_identify_ctrl(hdl, &test_ctrl) == 0) { @@ -616,7 +616,7 @@ static int get_stats(int argc, char **argv, struct command *acmd, nvme_init_get_log(&cmd, nsid, AMZN_NVME_STATS_LOGPAGE_ID, NVME_CSI_NVM, &log, len); - rc = nvme_get_log(hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); + rc = libnvme_get_log(hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); if (rc != 0) { fprintf(stderr, "[ERROR] %s: Failed to get log page, rc = %d\n", __func__, rc); @@ -661,7 +661,7 @@ static int get_stats(int argc, char **argv, struct command *acmd, nvme_init_get_log(&cmd, nsid, AMZN_NVME_STATS_LOGPAGE_ID, NVME_CSI_NVM, &curr, len); - rc = nvme_get_log(hdl, &cmd, false, + rc = libnvme_get_log(hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); if (rc != 0) { nvme_show_error("get log page failed, rc=%d", diff --git a/plugins/dapustor/dapustor-nvme.c b/plugins/dapustor/dapustor-nvme.c index cb88df38f9..e5ecc48386 100644 --- a/plugins/dapustor/dapustor-nvme.c +++ b/plugins/dapustor/dapustor-nvme.c @@ -484,7 +484,7 @@ static void show_dapustor_smart_log(struct nvme_additional_smart_log *smart, } static int dapustor_additional_smart_log_data( - struct nvme_transport_handle *hdl, + struct libnvme_transport_handle *hdl, struct nvme_additional_smart_log *smart_log, struct nvme_extended_additional_smart_log *ext_smart_log, bool *has_ext) @@ -511,9 +511,9 @@ static int dapustor_additional_smart_log(int argc, char **argv, struct command * const char *json = "Dump output in json format"; #endif /* CONFIG_JSONC */ - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; struct nvme_extended_additional_smart_log ext_smart_log; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; struct nvme_additional_smart_log smart_log; nvme_print_flags_t flags; bool has_ext = false; @@ -550,12 +550,12 @@ static int dapustor_additional_smart_log(int argc, char **argv, struct command * if (flags & JSON || cfg.json) show_dapustor_smart_log_jsn(&smart_log, &ext_smart_log, cfg.namespace_id, - nvme_transport_handle_get_name(hdl), + libnvme_transport_handle_get_name(hdl), has_ext); else if (!cfg.raw_binary) show_dapustor_smart_log(&smart_log, &ext_smart_log, cfg.namespace_id, - nvme_transport_handle_get_name(hdl), has_ext); + libnvme_transport_handle_get_name(hdl), has_ext); else { d_raw((unsigned char *)&smart_log, sizeof(smart_log)); if (has_ext) diff --git a/plugins/dera/dera-nvme.c b/plugins/dera/dera-nvme.c index 0d01060ac9..bf1b336134 100644 --- a/plugins/dera/dera-nvme.c +++ b/plugins/dera/dera-nvme.c @@ -96,11 +96,11 @@ enum dera_device_status DEVICE_STAUTS__OVER_TEMPRATURE = 0x09, }; -static int nvme_dera_get_device_status(struct nvme_transport_handle *hdl, enum dera_device_status *result) +static int nvme_dera_get_device_status(struct libnvme_transport_handle *hdl, enum dera_device_status *result) { int err = 0; - struct nvme_passthru_cmd cmd = { + struct libnvme_passthru_cmd cmd = { .opcode = 0xc0, .addr = (__u64)(uintptr_t)NULL, .data_len = 0, @@ -108,7 +108,7 @@ static int nvme_dera_get_device_status(struct nvme_transport_handle *hdl, enum d .cdw12 = 0x104, }; - err = nvme_submit_admin_passthru(hdl, &cmd); + err = libnvme_submit_admin_passthru(hdl, &cmd); if (!err && result) *result = cmd.result; @@ -117,9 +117,9 @@ static int nvme_dera_get_device_status(struct nvme_transport_handle *hdl, enum d static int get_status(int argc, char **argv, struct command *acmd, struct plugin *plugin) { - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; enum dera_device_status state = DEVICE_STATUS_FATAL_ERROR; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; char *desc = "Get the Dera device status"; struct nvme_dera_smart_info_log log; int err; diff --git a/plugins/fdp/fdp.c b/plugins/fdp/fdp.c index 4c59d6d3f7..8136883833 100644 --- a/plugins/fdp/fdp.c +++ b/plugins/fdp/fdp.c @@ -27,8 +27,8 @@ static int fdp_configs(int argc, char **argv, struct command *acmd, const char *human_readable = "show log in readable format"; const char *raw = "use binary output"; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; _cleanup_free_ void *log = NULL; struct nvme_fdp_config_log hdr; nvme_print_flags_t flags; @@ -97,8 +97,8 @@ static int fdp_usage(int argc, char **argv, struct command *acmd, struct plugin const char *egid = "Endurance group identifier"; const char *raw = "use binary output"; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; _cleanup_free_ void *log = NULL; struct nvme_fdp_ruhu_log hdr; nvme_print_flags_t flags; @@ -161,8 +161,8 @@ static int fdp_stats(int argc, char **argv, struct command *acmd, struct plugin const char *egid = "Endurance group identifier"; const char *raw = "use binary output"; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; struct nvme_fdp_stats_log stats; nvme_print_flags_t flags; int err; @@ -219,8 +219,8 @@ static int fdp_events(int argc, char **argv, struct command *acmd, struct plugin const char *host_events = "Get host events"; const char *raw = "use binary output"; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; struct nvme_fdp_events_log events; nvme_print_flags_t flags; int err; @@ -278,11 +278,11 @@ static int fdp_status(int argc, char **argv, struct command *acmd, struct plugin const char *namespace_id = "Namespace identifier"; const char *raw = "use binary output"; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; _cleanup_free_ void *buf = NULL; struct nvme_fdp_ruh_status hdr; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; nvme_print_flags_t flags; int err = -1; size_t len; @@ -312,7 +312,7 @@ static int fdp_status(int argc, char **argv, struct command *acmd, struct plugin flags = BINARY; if (!cfg.nsid) { - err = nvme_get_nsid(hdl, &cfg.nsid); + err = libnvme_get_nsid(hdl, &cfg.nsid); if (err < 0) { perror("get-namespace-id"); return err; @@ -321,7 +321,7 @@ static int fdp_status(int argc, char **argv, struct command *acmd, struct plugin nvme_init_fdp_reclaim_unit_handle_status(&cmd, cfg.nsid, &hdr, sizeof(hdr)); - err = nvme_submit_io_passthru(hdl, &cmd); + err = libnvme_submit_io_passthru(hdl, &cmd); if (err) { nvme_show_status(err); return err; @@ -334,7 +334,7 @@ static int fdp_status(int argc, char **argv, struct command *acmd, struct plugin return -ENOMEM; nvme_init_fdp_reclaim_unit_handle_status(&cmd, cfg.nsid, buf, len); - err = nvme_submit_io_passthru(hdl, &cmd); + err = libnvme_submit_io_passthru(hdl, &cmd); if (err) { nvme_show_status(err); return err; @@ -351,9 +351,9 @@ static int fdp_update(int argc, char **argv, struct command *acmd, struct plugin const char *namespace_id = "Namespace identifier"; const char *_pids = "Comma-separated list of placement identifiers to update"; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - struct nvme_passthru_cmd cmd; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + struct libnvme_passthru_cmd cmd; unsigned short pids[256]; __u16 buf[256]; int err = -1; @@ -386,7 +386,7 @@ static int fdp_update(int argc, char **argv, struct command *acmd, struct plugin } if (!cfg.nsid) { - err = nvme_get_nsid(hdl, &cfg.nsid); + err = libnvme_get_nsid(hdl, &cfg.nsid); if (err < 0) { perror("get-namespace-id"); return err; @@ -397,7 +397,7 @@ static int fdp_update(int argc, char **argv, struct command *acmd, struct plugin buf[i] = cpu_to_le16(pids[i]); nvme_init_fdp_reclaim_unit_handle_status(&cmd, cfg.nsid, buf, npids); - err = nvme_submit_io_passthru(hdl, &cmd); + err = libnvme_submit_io_passthru(hdl, &cmd); if (err) { nvme_show_status(err); return err; @@ -417,8 +417,8 @@ static int fdp_set_events(int argc, char **argv, struct command *acmd, struct pl const char *ph = "Placement Handle"; const char *sv = "specifies that the controller shall save the attribute"; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; unsigned short evts[255]; __u8 buf[255]; int err = -1; @@ -461,10 +461,10 @@ static int fdp_set_events(int argc, char **argv, struct command *acmd, struct pl } if (!cfg.nsid) { - err = nvme_get_nsid(hdl, &cfg.nsid); + err = libnvme_get_nsid(hdl, &cfg.nsid); if (err < 0) { if (errno != ENOTTY) { - fprintf(stderr, "get-namespace-id: %s\n", nvme_strerror(errno)); + fprintf(stderr, "get-namespace-id: %s\n", libnvme_strerror(errno)); return err; } @@ -495,8 +495,8 @@ static int fdp_feature(int argc, char **argv, struct command *acmd, struct plugi const char *endurance_group = "Endurance group ID"; const char *disable = "Disable current FDP configuration"; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; bool enabling_conf_idx = false; __u64 result; int err = -1; diff --git a/plugins/feat/feat-nvme.c b/plugins/feat/feat-nvme.c index f474dd71c9..78e7e00971 100644 --- a/plugins/feat/feat-nvme.c +++ b/plugins/feat/feat-nvme.c @@ -62,7 +62,7 @@ static const char *power_meas_feat = "power measurement feature"; static const char *err_recovery_feat = "error recovery feature"; static const char *num_queues_feat = "number of queues feature"; -static int feat_get_nsid(struct nvme_transport_handle *hdl, __u32 nsid, +static int feat_get_nsid(struct libnvme_transport_handle *hdl, __u32 nsid, const __u8 fid, __u32 cdw11, __u8 sel, __u8 uidx, const char *feat) { @@ -73,7 +73,7 @@ static int feat_get_nsid(struct nvme_transport_handle *hdl, __u32 nsid, _cleanup_free_ void *buf = NULL; if (!NVME_CHECK(sel, GET_FEATURES_SEL, SUPPORTED)) - nvme_get_feature_length(fid, cdw11, NVME_DATA_TFR_CTRL_TO_HOST, &len); + libnvme_get_feature_length(fid, cdw11, NVME_DATA_TFR_CTRL_TO_HOST, &len); if (len) { buf = nvme_alloc(len - 1); @@ -101,13 +101,13 @@ static int feat_get_nsid(struct nvme_transport_handle *hdl, __u32 nsid, return err; } -static int feat_get(struct nvme_transport_handle *hdl, const __u8 fid, +static int feat_get(struct libnvme_transport_handle *hdl, const __u8 fid, __u32 cdw11, __u8 sel, __u8 uidx, const char *feat) { return feat_get_nsid(hdl, 0, fid, cdw11, sel, uidx, feat); } -static int power_mgmt_set(struct nvme_transport_handle *hdl, const __u8 fid, +static int power_mgmt_set(struct libnvme_transport_handle *hdl, const __u8 fid, __u8 ps, __u8 wh, bool sv) { __u32 cdw11 = NVME_SET(ps, FEAT_PWRMGMT_PS) | NVME_SET(wh, FEAT_PWRMGMT_WH); @@ -139,8 +139,8 @@ static int feat_power_mgmt(int argc, char **argv, struct command *acmd, struct p const char *wh = "workload hint"; const __u8 fid = NVME_FEAT_FID_POWER_MGMT; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; int err; struct config { @@ -168,7 +168,7 @@ static int feat_power_mgmt(int argc, char **argv, struct command *acmd, struct p return err; } -static int perfc_set(struct nvme_transport_handle *hdl, __u8 fid, __u32 cdw11, +static int perfc_set(struct libnvme_transport_handle *hdl, __u8 fid, __u32 cdw11, struct perfc_config *cfg, bool sv) { __u64 result; @@ -185,19 +185,19 @@ static int perfc_set(struct nvme_transport_handle *hdl, __u8 fid, __u32 cdw11, data.std_perf->r4karl = cfg->r4karl; break; case NVME_FEAT_PERFC_ATTRI_VS_MIN ... NVME_FEAT_PERFC_ATTRI_VS_MAX: - nvme_uuid_from_string(cfg->paid, data.vs_perf->paid); + libnvme_uuid_from_string(cfg->paid, data.vs_perf->paid); data.vs_perf->attrl = cfg->attrl; if (data.vs_perf->attrl && strlen(cfg->vs_data)) { ffd = open(cfg->vs_data, O_RDONLY); if (ffd < 0) { nvme_show_error("Failed to open file %s: %s", cfg->vs_data, - nvme_strerror(errno)); + libnvme_strerror(errno)); return -EINVAL; } err = read(ffd, data.vs_perf->vs, data.vs_perf->attrl); if (err < 0) { nvme_show_error("failed to read data buffer from input file: %s", - nvme_strerror(errno)); + libnvme_strerror(errno)); return -errno; } } @@ -234,8 +234,8 @@ static int feat_perfc(int argc, char **argv, struct command *acmd, struct plugin const char *attrl = "attribute length"; const char *vs_data = "vendor specific data"; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; int err; __u8 fid = NVME_FEAT_FID_PERF_CHARACTERISTICS; __u32 cdw11; @@ -268,7 +268,7 @@ static int feat_perfc(int argc, char **argv, struct command *acmd, struct plugin return err; } -static int hctm_set(struct nvme_transport_handle *hdl, const __u8 fid, +static int hctm_set(struct libnvme_transport_handle *hdl, const __u8 fid, __u16 tmt1, __u16 tmt2, bool sv) { __u32 cdw11 = NVME_SET(tmt1, FEAT_HCTM_TMT1) @@ -298,8 +298,8 @@ static int feat_hctm(int argc, char **argv, struct command *acmd, struct plugin { const __u8 fid = NVME_FEAT_FID_HCTM; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; int err; struct config { @@ -328,7 +328,7 @@ static int feat_hctm(int argc, char **argv, struct command *acmd, struct plugin return err; } -static int timestamp_set(struct nvme_transport_handle *hdl, const __u8 fid, +static int timestamp_set(struct libnvme_transport_handle *hdl, const __u8 fid, __u64 tstmp, bool sv) { __u64 result; @@ -361,8 +361,8 @@ static int feat_timestamp(int argc, char **argv, struct command *acmd, struct pl const __u8 fid = NVME_FEAT_FID_TIMESTAMP; const char *tstmp = "timestamp"; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; int err; struct config { @@ -387,12 +387,12 @@ static int feat_timestamp(int argc, char **argv, struct command *acmd, struct pl return err; } -static int temp_thresh_set(struct nvme_transport_handle *hdl, const __u8 fid, +static int temp_thresh_set(struct libnvme_transport_handle *hdl, const __u8 fid, struct argconfig_commandline_options *opts, struct temp_thresh_config *cfg) { enum nvme_get_features_sel sel = NVME_GET_FEATURES_SEL_CURRENT; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; __u16 tmpth; __u8 tmpsel; __u8 thsel; @@ -405,7 +405,7 @@ static int temp_thresh_set(struct nvme_transport_handle *hdl, const __u8 fid, sel = NVME_GET_FEATURES_SEL_SAVED; nvme_init_get_features_temp_thresh(&cmd, sel, cfg->tmpsel, cfg->thsel); - err = nvme_submit_admin_passthru(hdl, &cmd); + err = libnvme_submit_admin_passthru(hdl, &cmd); if (!err) { nvme_feature_decode_temp_threshold(cmd.result, &tmpth, &tmpsel, &thsel, &tmpthh); @@ -417,7 +417,7 @@ static int temp_thresh_set(struct nvme_transport_handle *hdl, const __u8 fid, nvme_init_set_features_temp_thresh(&cmd, sv, cfg->tmpth, cfg->tmpsel, cfg->thsel, cfg->tmpthh); - err = nvme_submit_admin_passthru(hdl, &cmd); + err = libnvme_submit_admin_passthru(hdl, &cmd); if (err) { nvme_show_err(err, "Set %s", temp_thresh_feat); return err; @@ -445,8 +445,8 @@ static int feat_temp_thresh(int argc, char **argv, struct command *acmd, struct const char *thsel = "threshold type select"; const char *tmpthh = "temperature threshold hysteresis"; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; int err; struct temp_thresh_config cfg = { 0 }; @@ -472,12 +472,12 @@ static int feat_temp_thresh(int argc, char **argv, struct command *acmd, struct return err; } -static int arbitration_set(struct nvme_transport_handle *hdl, const __u8 fid, +static int arbitration_set(struct libnvme_transport_handle *hdl, const __u8 fid, struct argconfig_commandline_options *opts, struct arbitration_config *cfg) { enum nvme_get_features_sel sel = NVME_GET_FEATURES_SEL_CURRENT; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; __u8 ab, lpw, mpw, hpw; bool sv; int err; @@ -487,7 +487,7 @@ static int arbitration_set(struct nvme_transport_handle *hdl, const __u8 fid, sel = NVME_GET_FEATURES_SEL_SAVED; nvme_init_get_features_arbitration(&cmd, sel); - err = nvme_submit_admin_passthru(hdl, &cmd); + err = libnvme_submit_admin_passthru(hdl, &cmd); if (!err) { nvme_feature_decode_arbitration(cmd.result, &ab, &lpw, &mpw, &hpw); @@ -503,7 +503,7 @@ static int arbitration_set(struct nvme_transport_handle *hdl, const __u8 fid, nvme_init_set_features_arbitration(&cmd, sv, cfg->ab, cfg->lpw, cfg->mpw, cfg->hpw); - err = nvme_submit_admin_passthru(hdl, &cmd); + err = libnvme_submit_admin_passthru(hdl, &cmd); if (err) { nvme_show_err(err, "Set %s", arbitration_feat); return err; @@ -533,8 +533,8 @@ static int feat_arbitration(int argc, char **argv, struct command *acmd, struct const char *mpw = "medium priority weight"; const char *hpw = "high priority weight"; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; int err; struct arbitration_config cfg = { 0 }; @@ -555,7 +555,7 @@ static int feat_arbitration(int argc, char **argv, struct command *acmd, struct return arbitration_set(hdl, fid, opts, &cfg); } -static int volatile_wc_set(struct nvme_transport_handle *hdl, const __u8 fid, +static int volatile_wc_set(struct libnvme_transport_handle *hdl, const __u8 fid, bool wce, bool sv) { __u32 cdw11 = NVME_SET(wce, FEAT_VWC_WCE); @@ -585,8 +585,8 @@ static int feat_volatile_wc(int argc, char **argv, struct command *acmd, struct const __u8 fid = NVME_FEAT_FID_VOLATILE_WC; const char *wce = "volatile write cache enable"; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; int err; struct config { @@ -611,7 +611,7 @@ static int feat_volatile_wc(int argc, char **argv, struct command *acmd, struct return err; } -static int power_limit_set(struct nvme_transport_handle *hdl, const __u8 fid, +static int power_limit_set(struct libnvme_transport_handle *hdl, const __u8 fid, __u8 plv, __u8 pls, __u8 uidx, bool sv) { __u32 cdw13 = NVME_SET(plv, FEAT_POWER_LIMIT_PLV) | @@ -644,9 +644,9 @@ static int feat_power_limit(int argc, char **argv, struct command *acmd, const char *pls = "power limit scale"; const __u8 fid = NVME_FEAT_FID_POWER_LIMIT; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; int err; @@ -678,7 +678,7 @@ static int feat_power_limit(int argc, char **argv, struct command *acmd, return err; } -static int power_thresh_set(struct nvme_transport_handle *hdl, const __u8 fid, +static int power_thresh_set(struct libnvme_transport_handle *hdl, const __u8 fid, __u16 ptv, __u8 pts, __u8 pmts, __u8 ept, __u8 uidx, bool sv) { @@ -716,9 +716,9 @@ static int feat_power_thresh(int argc, char **argv, struct command *acmd, const char *ept = "enable power threshold"; const __u8 fid = NVME_FEAT_FID_POWER_THRESH; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; int err; @@ -758,7 +758,7 @@ static int feat_power_thresh(int argc, char **argv, struct command *acmd, return err; } -static int power_meas_set(struct nvme_transport_handle *hdl, const __u8 fid, +static int power_meas_set(struct libnvme_transport_handle *hdl, const __u8 fid, __u8 action, __u8 pmts, __u16 smt, __u8 uidx, bool sv) { __u32 cdw11 = NVME_SET(action, FEAT_POWER_MEAS_ACT) | @@ -793,9 +793,9 @@ static int feat_power_meas(int argc, char **argv, struct command *cmd, const char *smt = "stop measurement time"; const __u8 fid = NVME_FEAT_FID_POWER_MEASUREMENT; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; int err; @@ -831,7 +831,7 @@ static int feat_power_meas(int argc, char **argv, struct command *cmd, return err; } -static int err_recovery_set(struct nvme_transport_handle *hdl, const __u8 fid, +static int err_recovery_set(struct libnvme_transport_handle *hdl, const __u8 fid, __u32 nsid, __u16 tler, bool dulbe, bool sv) { __u32 cdw11 = NVME_SET(tler, FEAT_ERROR_RECOVERY_TLER) | @@ -860,9 +860,9 @@ static int err_recovery_set(struct nvme_transport_handle *hdl, const __u8 fid, static int feat_err_recovery(int argc, char **argv, struct command *acmd, struct plugin *plugin) { - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; const char *dulbe = "deallocated or unwritten logical block error enable"; @@ -900,14 +900,14 @@ static int feat_err_recovery(int argc, char **argv, struct command *acmd, return err; } -static int num_queues_set(struct nvme_transport_handle *hdl, const __u8 fid, +static int num_queues_set(struct libnvme_transport_handle *hdl, const __u8 fid, __u16 nsqr, __u16 ncqr, bool sv, struct argconfig_commandline_options *opts) { enum nvme_get_features_sel sel = NVME_GET_FEATURES_SEL_CURRENT; __u32 cdw11 = NVME_SET(nsqr, FEAT_NRQS_NSQR) | NVME_SET(ncqr, FEAT_NRQS_NCQR); - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; __u64 result; int err; @@ -915,7 +915,7 @@ static int num_queues_set(struct nvme_transport_handle *hdl, const __u8 fid, sel = NVME_GET_FEATURES_SEL_SAVED; nvme_init_get_features_num_queues(&cmd, sel); - err = nvme_submit_admin_passthru(hdl, &cmd); + err = libnvme_submit_admin_passthru(hdl, &cmd); if (!err) { nvme_feature_decode_number_of_queues(cmd.result, &nsqr, &ncqr); if (!argconfig_parse_seen(opts, "nsqr")) @@ -945,9 +945,9 @@ static int num_queues_set(struct nvme_transport_handle *hdl, const __u8 fid, static int feat_num_queues(int argc, char **argv, struct command *acmd, struct plugin *plugin) { - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; const char *ncqr = "number of I/O completion queues requested"; const char *nsqr = "number of I/O submission queues requested"; diff --git a/plugins/huawei/huawei-nvme.c b/plugins/huawei/huawei-nvme.c index dcf4f3dc2b..97555ada0c 100644 --- a/plugins/huawei/huawei-nvme.c +++ b/plugins/huawei/huawei-nvme.c @@ -66,7 +66,7 @@ struct huawei_list_element_len { unsigned int array_name; }; -static int huawei_get_nvme_info(struct nvme_transport_handle *hdl, +static int huawei_get_nvme_info(struct libnvme_transport_handle *hdl, struct huawei_list_item *item, const char *node) { struct stat nvme_stat_info; @@ -87,12 +87,12 @@ static int huawei_get_nvme_info(struct nvme_transport_handle *hdl, } item->huawei_device = true; - err = nvme_get_nsid(hdl, &item->nsid); + err = libnvme_get_nsid(hdl, &item->nsid); err = nvme_identify_ns(hdl, item->nsid, &item->ns); if (err) return err; - err = fstat(nvme_transport_handle_get_fd(hdl), &nvme_stat_info); + err = fstat(libnvme_transport_handle_get_fd(hdl), &nvme_stat_info); if (err < 0) return err; @@ -296,8 +296,8 @@ static void huawei_print_list_items(struct huawei_list_item *list_items, unsigne static int huawei_list(int argc, char **argv, struct command *acmd, struct plugin *plugin) { - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = - nvme_create_global_ctx(stdout, DEFAULT_LOGLEVEL); + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = + libnvme_create_global_ctx(stdout, DEFAULT_LOGLEVEL); char path[264]; struct dirent **devices; struct huawei_list_item *list_items; @@ -319,7 +319,7 @@ static int huawei_list(int argc, char **argv, struct command *acmd, if (ret < 0 || (fmt != JSON && fmt != NORMAL)) return ret; - n = scandir("/dev", &devices, nvme_filter_namespace, alphasort); + n = scandir("/dev", &devices, libnvme_filter_namespace, alphasort); if (n <= 0) return n; @@ -331,13 +331,13 @@ static int huawei_list(int argc, char **argv, struct command *acmd, } for (i = 0; i < n; i++) { - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; snprintf(path, sizeof(path), "/dev/%s", devices[i]->d_name); - ret = nvme_open(ctx, path, &hdl); + ret = libnvme_open(ctx, path, &hdl); if (ret) { fprintf(stderr, "Cannot open device %s: %s\n", - path, nvme_strerror(-ret)); + path, libnvme_strerror(-ret)); continue; } ret = huawei_get_nvme_info(hdl, &list_items[huawei_num], path); diff --git a/plugins/ibm/ibm-nvme.c b/plugins/ibm/ibm-nvme.c index 38f3cf0fe1..19315a8980 100644 --- a/plugins/ibm/ibm-nvme.c +++ b/plugins/ibm/ibm-nvme.c @@ -225,8 +225,8 @@ static int get_ibm_addi_smart_log(int argc, char **argv, struct command *cmd, st const char *desc = "Get IBM specific additional smart log and show it."; const char *raw = "Dump output in binary format"; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; struct nvme_ibm_additional_smart_log smart_log; int err; @@ -250,13 +250,13 @@ static int get_ibm_addi_smart_log(int argc, char **argv, struct command *cmd, st if (!err) { if (!cfg.raw_binary) show_ibm_smart_log(&smart_log, - nvme_transport_handle_get_name(hdl)); + libnvme_transport_handle_get_name(hdl)); else d_raw((unsigned char *)&smart_log, sizeof(smart_log)); } else if (err > 0) nvme_show_status(err); else - nvme_show_error("ibm additional smart log: %s\n", nvme_strerror(errno)); + nvme_show_error("ibm additional smart log: %s\n", libnvme_strerror(errno)); return err; } @@ -352,8 +352,8 @@ static void show_ibm_vpd_log(struct nvme_ibm_vpd_log *vpd, const char *devname) static int get_ibm_vpd_log(int argc, char **argv, struct command *cmd, struct plugin *plugin) { - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; struct nvme_ibm_vpd_log vpd_log; int err; @@ -381,13 +381,13 @@ static int get_ibm_vpd_log(int argc, char **argv, struct command *cmd, struct pl if (!err) { if (!cfg.raw_binary) show_ibm_vpd_log(&vpd_log, - nvme_transport_handle_get_name(hdl)); + libnvme_transport_handle_get_name(hdl)); else d_raw((unsigned char *)&vpd_log, sizeof(vpd_log)); } else if (err > 0) nvme_show_status(err); else - nvme_show_error("ibm vpd log: %s\n", nvme_strerror(errno)); + nvme_show_error("ibm vpd log: %s\n", libnvme_strerror(errno)); return err; } @@ -525,8 +525,8 @@ static int get_ibm_persistent_event_log(int argc, char **argv, const char *action = "action the controller shall take during " "processing this persistent log page command."; const char *log_len = "number of bytes to retrieve"; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; struct nvme_persistent_event_log pevent_log; void *pevent_log_info = NULL; enum nvme_print_flags flags; @@ -590,7 +590,7 @@ static int get_ibm_persistent_event_log(int argc, char **argv, pevent_log_info, log_length); if (!err) { nvme_show_ibm_persistent_event_log(pevent_log_info, cfg.action, - log_length, nvme_transport_handle_get_name(hdl), + log_length, libnvme_transport_handle_get_name(hdl), flags); } diff --git a/plugins/innogrit/innogrit-nvme.c b/plugins/innogrit/innogrit-nvme.c index 2c130c4cd0..06817bc8af 100644 --- a/plugins/innogrit/innogrit-nvme.c +++ b/plugins/innogrit/innogrit-nvme.c @@ -18,12 +18,12 @@ #define CREATE_CMD #include "innogrit-nvme.h" -static int nvme_vucmd(struct nvme_transport_handle *hdl, unsigned char opcode, +static int nvme_vucmd(struct libnvme_transport_handle *hdl, unsigned char opcode, unsigned int cdw12, unsigned int cdw13, unsigned int cdw14, unsigned int cdw15, char *data, int data_len) { - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; memset(&cmd, 0, sizeof(cmd)); cmd.opcode = opcode; @@ -36,14 +36,14 @@ static int nvme_vucmd(struct nvme_transport_handle *hdl, unsigned char opcode, cmd.nsid = 0xffffffff; cmd.addr = (__u64)(__u64)(uintptr_t)data; cmd.data_len = data_len; - return nvme_submit_admin_passthru(hdl, &cmd); + return libnvme_submit_admin_passthru(hdl, &cmd); } -static int getlogpage(struct nvme_transport_handle *hdl, unsigned char ilogid, +static int getlogpage(struct libnvme_transport_handle *hdl, unsigned char ilogid, unsigned char ilsp, char *data, int data_len, __u64 *result) { - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; nvme_init_get_log(&cmd, NVME_NSID_ALL, ilogid, NVME_CSI_NVM, data, data_len); @@ -51,10 +51,10 @@ static int getlogpage(struct nvme_transport_handle *hdl, unsigned char ilogid, NVME_LOG_CDW10_LSP_SHIFT, NVME_LOG_CDW10_LSP_MASK); - return nvme_get_log(hdl, &cmd, true, NVME_LOG_PAGE_PDU_SIZE); + return libnvme_get_log(hdl, &cmd, true, NVME_LOG_PAGE_PDU_SIZE); } -static int getvsctype(struct nvme_transport_handle *hdl) +static int getvsctype(struct libnvme_transport_handle *hdl) { unsigned char ilogid; char data[4096]; @@ -76,7 +76,7 @@ static int getvsctype(struct nvme_transport_handle *hdl) return 0; } -static int getvsc_eventlog(struct nvme_transport_handle *hdl, FILE *fp) +static int getvsc_eventlog(struct libnvme_transport_handle *hdl, FILE *fp) { unsigned int errcnt, rxlen, start_flag; int ivsctype = getvsctype(hdl); @@ -136,7 +136,7 @@ static int getvsc_eventlog(struct nvme_transport_handle *hdl, FILE *fp) return IG_SUCCESS; } -int getlogpage_eventlog(struct nvme_transport_handle *hdl, FILE *fp) +int getlogpage_eventlog(struct libnvme_transport_handle *hdl, FILE *fp) { unsigned int i, total_size; char data[4096]; @@ -174,8 +174,8 @@ static int innogrit_geteventlog(int argc, char **argv, struct plugin *plugin) { const char *desc = "Recrieve event log for the given device "; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; _cleanup_file_ FILE *fp = NULL; char currentdir[128], filename[512]; struct tm *logtime; @@ -214,8 +214,8 @@ static int innogrit_vsc_getcdump(int argc, char **argv, struct command *acmd, { const char *desc = "Recrieve cdump data for the given device "; char currentdir[128], filename[512], fname[128]; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; unsigned int itotal, icur, ivsctype; unsigned int ipackcount, ipackindex; unsigned char busevsc = false; diff --git a/plugins/inspur/inspur-nvme.c b/plugins/inspur/inspur-nvme.c index 7e798c4916..280dffa536 100644 --- a/plugins/inspur/inspur-nvme.c +++ b/plugins/inspur/inspur-nvme.c @@ -209,8 +209,8 @@ void show_r1_media_err_log(r1_cli_vendor_log_t *vendorlog) static int nvme_get_vendor_log(int argc, char **argv, struct command *acmd, struct plugin *plugin) { char *desc = "Get the Inspur vendor log"; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; __u8 local_mem[BYTE_OF_4K]; int err; diff --git a/plugins/intel/intel-nvme.c b/plugins/intel/intel-nvme.c index 2d1d601b45..7eab056a75 100644 --- a/plugins/intel/intel-nvme.c +++ b/plugins/intel/intel-nvme.c @@ -343,8 +343,8 @@ static int get_additional_smart_log(int argc, char **argv, struct command *acmd, #endif /* CONFIG_JSONC */ struct nvme_additional_smart_log smart_log; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; nvme_print_flags_t flags; int err; @@ -377,10 +377,10 @@ static int get_additional_smart_log(int argc, char **argv, struct command *acmd, if (!err) { if (flags & JSON || cfg.json) show_intel_smart_log_jsn(&smart_log, cfg.namespace_id, - nvme_transport_handle_get_name(hdl)); + libnvme_transport_handle_get_name(hdl)); else if (!cfg.raw_binary) show_intel_smart_log(&smart_log, cfg.namespace_id, - nvme_transport_handle_get_name(hdl)); + libnvme_transport_handle_get_name(hdl)); else d_raw((unsigned char *)&smart_log, sizeof(smart_log)); } else if (err > 0) { @@ -393,8 +393,8 @@ static int get_market_log(int argc, char **argv, struct command *acmd, struct pl { const char *desc = "Get Intel Marketing Name log and show it."; const char *raw = "dump output in binary format"; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; char log[512]; int err; @@ -452,8 +452,8 @@ static void show_temp_stats(struct intel_temp_stats *stats) static int get_temp_stats_log(int argc, char **argv, struct command *acmd, struct plugin *plugin) { struct intel_temp_stats stats; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; int err; const char *desc = "Get Temperature Statistics log and show it."; @@ -1030,8 +1030,8 @@ static void show_lat_stats(int write) static int get_lat_stats_log(int argc, char **argv, struct command *acmd, struct plugin *plugin) { __u8 data[NAND_LAT_STATS_LEN]; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; nvme_print_flags_t flags; int err; @@ -1225,16 +1225,16 @@ static void print_intel_nlog(struct intel_vu_nlog *intel_nlog) intel_nlog->nlogbufnummax, intel_nlog->coreselected); } -static int read_entire_cmd(struct nvme_passthru_cmd *cmd, int total_size, +static int read_entire_cmd(struct libnvme_passthru_cmd *cmd, int total_size, const size_t max_tfer, int out_fd, - struct nvme_transport_handle *hdl, __u8 *buf) + struct libnvme_transport_handle *hdl, __u8 *buf) { int err = 0; size_t dword_tfer = 0; dword_tfer = min(max_tfer, total_size); while (total_size > 0) { - err = nvme_submit_admin_passthru(hdl, cmd); + err = libnvme_submit_admin_passthru(hdl, cmd); if (err) { fprintf(stderr, "failed on cmd.data_len %u cmd.cdw13 %u cmd.cdw12 %x cmd.cdw10 %u err %x remaining size %d\n", @@ -1268,8 +1268,8 @@ static int write_header(__u8 *buf, int fd, size_t amnt) return 0; } -static int read_header(struct nvme_passthru_cmd *cmd, __u8 *buf, - struct nvme_transport_handle *hdl, __u32 dw12, int nsid) +static int read_header(struct libnvme_passthru_cmd *cmd, __u8 *buf, + struct libnvme_transport_handle *hdl, __u32 dw12, int nsid) { memset(cmd, 0, sizeof(*cmd)); memset(buf, 0, 4096); @@ -1282,7 +1282,7 @@ static int read_header(struct nvme_passthru_cmd *cmd, __u8 *buf, return read_entire_cmd(cmd, 0x400, 0x400, -1, hdl, buf); } -static int setup_file(char *f, char *file, struct nvme_transport_handle *hdl, int type) +static int setup_file(char *f, char *file, struct libnvme_transport_handle *hdl, int type) { struct nvme_id_ctrl ctrl; int err = 0, i = sizeof(ctrl.sn) - 1; @@ -1304,8 +1304,8 @@ static int setup_file(char *f, char *file, struct nvme_transport_handle *hdl, in } static int get_internal_log_old(__u8 *buf, int output, - struct nvme_transport_handle *hdl, - struct nvme_passthru_cmd *cmd) + struct libnvme_transport_handle *hdl, + struct libnvme_passthru_cmd *cmd) { struct intel_vu_log *intel; int err = 0; @@ -1341,14 +1341,14 @@ static int get_internal_log(int argc, char **argv, struct command *acmd, __u8 buf[0x2000]; char f[0x100]; int err, output, i, j, count = 0, core_num = 1; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; struct intel_cd_log cdlog; struct intel_vu_log *intel = malloc(sizeof(struct intel_vu_log)); struct intel_vu_nlog *intel_nlog = (struct intel_vu_nlog *)buf; struct intel_assert_dump *ad = (struct intel_assert_dump *) intel->reserved; struct intel_event_header *ehdr = (struct intel_event_header *)intel->reserved; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; const char *desc = "Get Intel Firmware Log and save it."; const char *log = "Log type: 0, 1, or 2 for nlog, event log, and assert log, respectively."; @@ -1539,8 +1539,8 @@ static int enable_lat_stats_tracking(int argc, char **argv, const __u32 cdw12 = 0x0; const __u32 data_len = 32; const __u32 sv = 0; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; void *buf = NULL; __u64 result; int err; @@ -1623,8 +1623,8 @@ static int set_lat_stats_thresholds(int argc, char **argv, const __u8 fid = 0xf7; const __u32 cdw12 = 0x0; const __u32 sv = 0; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; __u64 result; int err, num; diff --git a/plugins/lm/lm-nvme.c b/plugins/lm/lm-nvme.c index 423cf2c9f9..08db541539 100644 --- a/plugins/lm/lm-nvme.c +++ b/plugins/lm/lm-nvme.c @@ -60,11 +60,11 @@ static int lm_create_cdq(int argc, char **argv, struct command *acmd, struct plu "will write to invalid memory, inevitably leading to MMU faults or " "worse."; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; struct lba_migration_queue_entry_type_0 *queue = NULL; _cleanup_huge_ struct nvme_mem_huge mh = { 0, }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err = -1; struct config { @@ -103,15 +103,15 @@ static int lm_create_cdq(int argc, char **argv, struct command *acmd, struct plu queue = nvme_alloc_huge(cfg.sz << 2, &mh); if (!queue) { nvme_show_error("ERROR: nvme_alloc of size %dB failed %s", cfg.sz << 2, - nvme_strerror(errno)); + libnvme_strerror(errno)); return -ENOMEM; } nvme_init_lm_cdq_create(&cmd, NVME_SET(cfg.qt, LM_QT), cfg.cntlid, cfg.sz, queue); - err = nvme_submit_admin_passthru(hdl, &cmd); + err = libnvme_submit_admin_passthru(hdl, &cmd); if (err < 0) - nvme_show_error("ERROR: nvme_lm_cdq() failed: %s", nvme_strerror(errno)); + nvme_show_error("ERROR: nvme_lm_cdq() failed: %s", libnvme_strerror(errno)); else if (err) nvme_show_status(err); else @@ -126,9 +126,9 @@ static int lm_delete_cdq(int argc, char **argv, struct command *acmd, struct plu const char *desc = "Delete Controller Data Queue"; const char *cdqid = "Controller Data Queue ID"; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - struct nvme_passthru_cmd cmd; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + struct libnvme_passthru_cmd cmd; int err = -1; struct config { @@ -147,9 +147,9 @@ static int lm_delete_cdq(int argc, char **argv, struct command *acmd, struct plu return err; nvme_init_lm_cdq_delete(&cmd, 0, cfg.cdqid); - err = nvme_submit_admin_passthru(hdl, &cmd); + err = libnvme_submit_admin_passthru(hdl, &cmd); if (err < 0) - nvme_show_error("ERROR: nvme_lm_cdq() failed: %s", nvme_strerror(errno)); + nvme_show_error("ERROR: nvme_lm_cdq() failed: %s", libnvme_strerror(errno)); else if (err > 0) nvme_show_status(err); else @@ -176,9 +176,9 @@ static int lm_track_send(int argc, char **argv, struct command *acmd, struct plu const char *stop = "Equivalent to stop tracking with defaults"; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - struct nvme_passthru_cmd cmd; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + struct libnvme_passthru_cmd cmd; int err = -1; struct config { @@ -230,9 +230,9 @@ static int lm_track_send(int argc, char **argv, struct command *acmd, struct plu } nvme_init_lm_track_send(&cmd, cfg.sel, cfg.mos, cfg.cdqid); - err = nvme_submit_admin_passthru(hdl, &cmd); + err = libnvme_submit_admin_passthru(hdl, &cmd); if (err < 0) - nvme_show_error("ERROR: nvme_lm_track_send() failed %s", nvme_strerror(errno)); + nvme_show_error("ERROR: nvme_lm_track_send() failed %s", libnvme_strerror(errno)); else if (err) nvme_show_status(err); else @@ -274,11 +274,11 @@ static int lm_migration_send(int argc, char **argv, struct command *acmd, struct const char *numd = "Number of Dwords (NUMD)"; const char *input = "Controller State Data input file"; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; _cleanup_huge_ struct nvme_mem_huge mh = { 0, }; _cleanup_file_ FILE *file = NULL; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; void *data = NULL; int err = -1; @@ -367,7 +367,7 @@ static int lm_migration_send(int argc, char **argv, struct command *acmd, struct fclose(file); if (n_data != (size_t)(cfg.numd << 2)) { - nvme_show_error("failed to read controller state data %s", nvme_strerror(errno)); + nvme_show_error("failed to read controller state data %s", libnvme_strerror(errno)); return -errno; } } @@ -377,9 +377,9 @@ static int lm_migration_send(int argc, char **argv, struct command *acmd, struct cfg.stype, cfg.dudmq, cfg.csvi, cfg.csuuidi, cfg.offset, cfg.uidx, data, (cfg.numd << 2)); - err = nvme_submit_admin_passthru(hdl, &cmd); + err = libnvme_submit_admin_passthru(hdl, &cmd); if (err < 0) - nvme_show_error("ERROR: nvme_lm_migration_send() failed %s", nvme_strerror(errno)); + nvme_show_error("ERROR: nvme_lm_migration_send() failed %s", libnvme_strerror(errno)); else if (err > 0) nvme_show_status(err); else @@ -406,11 +406,11 @@ static int lm_migration_recv(int argc, char **argv, struct command *acmd, struct const char *output = "Controller State Data output file"; const char *human_readable_info = "show info in readable format"; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; _cleanup_huge_ struct nvme_mem_huge mh = { 0, }; _cleanup_file_ FILE *fd = NULL; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; nvme_print_flags_t flags; void *data = NULL; __u64 result = 0; @@ -486,9 +486,9 @@ static int lm_migration_recv(int argc, char **argv, struct command *acmd, struct nvme_init_lm_migration_recv(&cmd, cfg.offset, mos, cfg.cntlid, cfg.csuuidi, cfg.sel, cfg.uidx, 0, data, (cfg.numd + 1) << 2); - err = nvme_submit_admin_passthru(hdl, &cmd); + err = libnvme_submit_admin_passthru(hdl, &cmd); if (err < 0) - nvme_show_error("ERROR: nvme_lm_migration_recv() failed %s", nvme_strerror(errno)); + nvme_show_error("ERROR: nvme_lm_migration_recv() failed %s", libnvme_strerror(errno)); else if (err) nvme_show_status(err); else if (cfg.sel == NVME_LM_SEL_GET_CONTROLLER_STATE) { @@ -501,7 +501,7 @@ static int lm_migration_recv(int argc, char **argv, struct command *acmd, struct if (cfg.output && strlen(cfg.output)) { if (fwrite(data, 1, cfg.numd << 2, fd) != (cfg.numd << 2)) { nvme_show_error("ERROR: %s: failed to write buffer to output file", - nvme_strerror(errno)); + libnvme_strerror(errno)); err = -errno; } } else { @@ -526,8 +526,8 @@ static int lm_set_cdq(int argc, char **argv, struct command *acmd, struct plugin const char *tpt = "If specified, the slot that causes the controller " " to issue a CDQ Tail Pointer event"; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; int err = -1; struct config { @@ -555,7 +555,7 @@ static int lm_set_cdq(int argc, char **argv, struct command *acmd, struct plugin ((cfg.tpt >= 0) ? NVME_SET(1, LM_CTRL_DATA_QUEUE_ETPT) : 0), cfg.hp, cfg.tpt, 0, 0, NULL, 0, NULL); if (err < 0) - nvme_show_error("ERROR: nvme_set_features() failed %s", nvme_strerror(errno)); + nvme_show_error("ERROR: nvme_set_features() failed %s", libnvme_strerror(errno)); else if (err) nvme_show_status(err); else @@ -570,8 +570,8 @@ static int lm_get_cdq(int argc, char **argv, struct command *acmd, struct plugin "of a CDQ and specify the configuration of a CDQ Tail event."; const char *cdqid = "Controller Data Queue ID"; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; nvme_print_flags_t flags; int err = -1; @@ -601,7 +601,7 @@ static int lm_get_cdq(int argc, char **argv, struct command *acmd, struct plugin err = nvme_get_features(hdl, 0, lm_cdq_feature_id, 0, cfg.cdqid, 0, &data, sizeof(data), NULL); if (err < 0) - nvme_show_error("ERROR: nvme_get_features() failed %s", nvme_strerror(errno)); + nvme_show_error("ERROR: nvme_get_features() failed %s", libnvme_strerror(errno)); else if (err) nvme_show_status(err); else diff --git a/plugins/memblaze/memblaze-nvme.c b/plugins/memblaze/memblaze-nvme.c index d1cd761912..a1738d984b 100644 --- a/plugins/memblaze/memblaze-nvme.c +++ b/plugins/memblaze/memblaze-nvme.c @@ -354,7 +354,7 @@ static void show_memblaze_smart_log_old(struct nvme_memblaze_smart_log *smart, } } -static int show_memblaze_smart_log(struct nvme_transport_handle *hdl, __u32 nsid, +static int show_memblaze_smart_log(struct libnvme_transport_handle *hdl, __u32 nsid, const char *devname, struct nvme_memblaze_smart_log *smart) { struct nvme_id_ctrl ctrl; @@ -422,8 +422,8 @@ static int mb_get_additional_smart_log(int argc, char **argv, struct command *ac "Get Memblaze vendor specific additional smart log, and show it."; const char *namespace = "(optional) desired namespace"; const char *raw = "dump output in binary format"; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; struct config { __u32 namespace_id; bool raw_binary; @@ -447,7 +447,7 @@ static int mb_get_additional_smart_log(int argc, char **argv, struct command *ac if (!err) { if (!cfg.raw_binary) err = show_memblaze_smart_log(hdl, cfg.namespace_id, - nvme_transport_handle_get_name(hdl), + libnvme_transport_handle_get_name(hdl), &smart_log); else d_raw((unsigned char *)&smart_log, sizeof(smart_log)); @@ -478,8 +478,8 @@ static int mb_get_powermanager_status(int argc, char **argv, struct command *acm const char *desc = "Get Memblaze power management ststus\n (value 0 - 25w, 1 - 20w, 2 - 15w)"; __u64 result; __u32 feature_id = MB_FEAT_POWER_MGMT; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; int err; NVME_ARGS(opts); @@ -506,8 +506,8 @@ static int mb_set_powermanager_status(int argc, char **argv, struct command *acm const char *desc = "Set Memblaze power management status\n (value 0 - 25w, 1 - 20w, 2 - 15w)"; const char *value = "new value of feature (required)"; const char *save = "specifies that the controller shall save the attribute"; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; __u64 result; int err; @@ -556,8 +556,8 @@ static int mb_set_high_latency_log(int argc, char **argv, struct command *acmd, " p2 value: 1 .. 5000 ms"; const char *param = "input parameters"; int param1 = 0, param2 = 0; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; __u64 result; int err; @@ -696,8 +696,8 @@ static int mb_high_latency_log_print(int argc, char **argv, struct command *acmd { const char *desc = "Get Memblaze high latency log"; char buf[LOG_PAGE_SIZE]; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; FILE *fdi = NULL; int err; @@ -729,15 +729,15 @@ static int mb_high_latency_log_print(int argc, char **argv, struct command *acmd return err; } -static int memblaze_fw_commit(struct nvme_transport_handle *hdl, int select) +static int memblaze_fw_commit(struct libnvme_transport_handle *hdl, int select) { - struct nvme_passthru_cmd cmd = { + struct libnvme_passthru_cmd cmd = { .opcode = nvme_admin_fw_commit, .cdw10 = 8, .cdw12 = select, }; - return nvme_submit_admin_passthru(hdl, &cmd); + return libnvme_submit_admin_passthru(hdl, &cmd); } static int mb_selective_download(int argc, char **argv, struct command *acmd, struct plugin *plugin) @@ -752,11 +752,11 @@ static int mb_selective_download(int argc, char **argv, struct command *acmd, st const char *fw = "firmware file (required)"; const char *select = "FW Select (e.g., --select=OOB, EEP, ALL)"; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; int selectNo, fw_fd, fw_size, err, offset = 0; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int xfer = 4096; struct stat sb; void *fw_buf; @@ -841,7 +841,7 @@ static int mb_selective_download(int argc, char **argv, struct command *acmd, st perror("fw-download"); goto out_free; } - err = nvme_submit_admin_passthru(hdl, &cmd); + err = libnvme_submit_admin_passthru(hdl, &cmd); if (err < 0) { perror("fw-download"); goto out_free; @@ -959,8 +959,8 @@ static int mb_lat_stats_log_print(int argc, char **argv, struct command *acmd, s char stats[LOG_PAGE_SIZE]; char f1[] = FID_C1_LOG_FILENAME; char f2[] = FID_C2_LOG_FILENAME; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; int err; @@ -996,8 +996,8 @@ static int memblaze_clear_error_log(int argc, char **argv, struct command *acmd, struct plugin *plugin) { char *desc = "Clear Memblaze devices error log."; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; int err; @@ -1048,8 +1048,8 @@ static int mb_set_lat_stats(int argc, char **argv, struct command *acmd, struct const __u32 cdw12 = 0x0; const __u32 data_len = 32; const __u32 save = 0; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; void *buf = NULL; __u64 result; @@ -1552,8 +1552,8 @@ static int mb_get_smart_log_add(int argc, char **argv, struct command *acmd, str NVME_ARGS(opts, OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, "dump the whole log buffer in binary format")); - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; err = parse_and_open(&ctx, &hdl, argc, argv, acmd->help, opts); @@ -1567,13 +1567,13 @@ static int mb_get_smart_log_add(int argc, char **argv, struct command *acmd, str err = nvme_get_log_simple(hdl, LID_SMART_LOG_ADD, &log, sizeof(struct smart_log_add)); if (!err) { if (!cfg.raw_binary) - smart_log_add_print(&log, nvme_transport_handle_get_name(hdl)); + smart_log_add_print(&log, libnvme_transport_handle_get_name(hdl)); else d_raw((unsigned char *)&log, sizeof(struct smart_log_add)); } else if (err > 0) { nvme_show_status(err); } else { - nvme_show_error("%s: %s", acmd->name, nvme_strerror(errno)); + nvme_show_error("%s: %s", acmd->name, libnvme_strerror(errno)); } return err; @@ -1713,8 +1713,8 @@ static int mb_set_latency_feature(int argc, char **argv, struct command *acmd, s OPT_UINT("set-trim-threshold", 't', &cfg.de_allocate_trim_threshold, "set trim high latency log threshold, it's a 0-based value and unit is 10ms")); - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; err = parse_and_open(&ctx, &hdl, argc, argv, acmd->help, opts); @@ -1738,7 +1738,7 @@ static int mb_set_latency_feature(int argc, char **argv, struct command *acmd, s else if (err > 0) nvme_show_status(err); else - nvme_show_error("%s: %s", acmd->name, nvme_strerror(errno)); + nvme_show_error("%s: %s", acmd->name, libnvme_strerror(errno)); return err; } @@ -1752,8 +1752,8 @@ static int mb_get_latency_feature(int argc, char **argv, struct command *acmd, s NVME_ARGS(opts); - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; err = parse_and_open(&ctx, &hdl, argc, argv, acmd->help, opts); if (err) @@ -1781,7 +1781,7 @@ static int mb_get_latency_feature(int argc, char **argv, struct command *acmd, s } else if (err > 0) { nvme_show_status(err); } else { - nvme_show_error("%s: %s", acmd->name, nvme_strerror(errno)); + nvme_show_error("%s: %s", acmd->name, libnvme_strerror(errno)); } return err; @@ -1903,8 +1903,8 @@ static int mb_get_latency_stats(int argc, char **argv, struct command *acmd, str &cfg.raw_binary, "dump the whole log buffer in binary format")); - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; int err = parse_and_open(&ctx, &hdl, argc, argv, acmd->help, opts); @@ -1918,13 +1918,13 @@ static int mb_get_latency_stats(int argc, char **argv, struct command *acmd, str err = nvme_get_log_simple(hdl, LID_LATENCY_STATISTICS, &log, sizeof(struct latency_stats)); if (!err) { if (!cfg.raw_binary) - latency_stats_print(&log, nvme_transport_handle_get_name(hdl)); + latency_stats_print(&log, libnvme_transport_handle_get_name(hdl)); else d_raw((unsigned char *)&log, sizeof(struct latency_stats)); } else if (err > 0) { nvme_show_status(err); } else { - nvme_show_error("%s: %s", acmd->name, nvme_strerror(errno)); + nvme_show_error("%s: %s", acmd->name, libnvme_strerror(errno)); } return err; @@ -2008,8 +2008,8 @@ static int mb_get_high_latency_log(int argc, char **argv, struct command *acmd, &cfg.raw_binary, "dump the whole log buffer in binary format")); - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; int err = parse_and_open(&ctx, &hdl, argc, argv, acmd->help, opts); if (err) @@ -2023,13 +2023,13 @@ static int mb_get_high_latency_log(int argc, char **argv, struct command *acmd, &log, sizeof(struct high_latency_log)); if (!err) { if (!cfg.raw_binary) - high_latency_log_print(&log, nvme_transport_handle_get_name(hdl)); + high_latency_log_print(&log, libnvme_transport_handle_get_name(hdl)); else d_raw((unsigned char *)&log, sizeof(struct high_latency_log)); } else if (err > 0) { nvme_show_status(err); } else { - nvme_show_error("%s: %s", acmd->name, nvme_strerror(errno)); + nvme_show_error("%s: %s", acmd->name, libnvme_strerror(errno)); } return err; @@ -2254,8 +2254,8 @@ static int mb_get_performance_stats(int argc, char **argv, struct command *acmd, &cfg.raw_binary, "dump the whole log buffer in binary format")); - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; int err = parse_and_open(&ctx, &hdl, argc, argv, acmd->help, opts); @@ -2280,13 +2280,13 @@ static int mb_get_performance_stats(int argc, char **argv, struct command *acmd, err = nvme_get_log_simple(hdl, LID_PERFORMANCE_STATISTICS, &log, xfer_size); if (!err) { if (!cfg.raw_binary) - performance_stats_print(&log, nvme_transport_handle_get_name(hdl), cfg.duration); + performance_stats_print(&log, libnvme_transport_handle_get_name(hdl), cfg.duration); else d_raw((unsigned char *)&log, log_size); } else if (err > 0) { nvme_show_status(err); } else { - nvme_show_error("%s: %s", acmd->name, nvme_strerror(errno)); + nvme_show_error("%s: %s", acmd->name, libnvme_strerror(errno)); } return err; diff --git a/plugins/micron/micron-nvme.c b/plugins/micron/micron-nvme.c index 655d85fc91..9f7f90242e 100644 --- a/plugins/micron/micron-nvme.c +++ b/plugins/micron/micron-nvme.c @@ -393,7 +393,7 @@ static int SetupDebugDataDirectories(char *strSN, char *strFilePath, return err; } -static int GetLogPageSize(struct nvme_transport_handle *hdl, unsigned char ucLogID, int *nLogSize) +static int GetLogPageSize(struct libnvme_transport_handle *hdl, unsigned char ucLogID, int *nLogSize) { int err = 0; unsigned char pTmpBuf[CommonChunkSize] = { 0 }; @@ -420,11 +420,11 @@ static int GetLogPageSize(struct nvme_transport_handle *hdl, unsigned char ucLog return err; } -static int NVMEGetLogPage(struct nvme_transport_handle *hdl, unsigned char ucLogID, unsigned char *pBuffer, int nBuffSize, +static int NVMEGetLogPage(struct libnvme_transport_handle *hdl, unsigned char ucLogID, unsigned char *pBuffer, int nBuffSize, int offset) { int err = 0; - struct nvme_passthru_cmd cmd = { 0 }; + struct libnvme_passthru_cmd cmd = { 0 }; unsigned int uiNumDwords = (unsigned int)nBuffSize / sizeof(unsigned int); unsigned int uiMaxChunk = uiNumDwords; unsigned int uiNumChunks = 1; @@ -472,7 +472,7 @@ static int NVMEGetLogPage(struct nvme_transport_handle *hdl, unsigned char ucLog cmd.addr = (__u64) (uintptr_t) pTempPtr; cmd.nsid = 0xFFFFFFFF; cmd.data_len = uiXferDwords * 4; - err = nvme_submit_admin_passthru(hdl, &cmd); + err = libnvme_submit_admin_passthru(hdl, &cmd); ullBytesRead += uiXferDwords * 4; if (ucLogID == 0x07 || ucLogID == 0x08 || ucLogID == 0xE9) pTempPtr = pBuffer + (ullBytesRead - offset); @@ -483,7 +483,7 @@ static int NVMEGetLogPage(struct nvme_transport_handle *hdl, unsigned char ucLog return err; } -static int NVMEResetLog(struct nvme_transport_handle *hdl, unsigned char ucLogID, int nBufferSize, +static int NVMEResetLog(struct libnvme_transport_handle *hdl, unsigned char ucLogID, int nBufferSize, long long llMaxSize) { unsigned int *pBuffer = NULL; @@ -510,7 +510,7 @@ static int NVMEResetLog(struct nvme_transport_handle *hdl, unsigned char ucLogID return err; } -static int GetCommonLogPage(struct nvme_transport_handle *hdl, unsigned char ucLogID, +static int GetCommonLogPage(struct libnvme_transport_handle *hdl, unsigned char ucLogID, unsigned char **pBuffer, int nBuffSize) { unsigned char *pTempPtr = NULL; @@ -530,8 +530,8 @@ static int GetCommonLogPage(struct nvme_transport_handle *hdl, unsigned char ucL /* * Plugin Commands */ -static int micron_parse_options(struct nvme_global_ctx **ctx, - struct nvme_transport_handle **hdl, int argc, +static int micron_parse_options(struct libnvme_global_ctx **ctx, + struct libnvme_transport_handle **hdl, int argc, char **argv, const char *desc, struct argconfig_commandline_options *opts, enum eDriveModel *modelp) @@ -553,15 +553,15 @@ static int micron_parse_options(struct nvme_global_ctx **ctx, return 0; } -static int micron_fw_commit(struct nvme_transport_handle *hdl, int select) +static int micron_fw_commit(struct libnvme_transport_handle *hdl, int select) { - struct nvme_passthru_cmd cmd = { + struct libnvme_passthru_cmd cmd = { .opcode = nvme_admin_fw_commit, .cdw10 = 8, .cdw12 = select, }; - return nvme_submit_admin_passthru(hdl, &cmd); + return libnvme_submit_admin_passthru(hdl, &cmd); } static int micron_selective_download(int argc, char **argv, @@ -577,11 +577,11 @@ static int micron_selective_download(int argc, char **argv, const char *fw = "firmware file (required)"; const char *select = "FW Select (e.g., --select=ALL)"; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; int selectNo, fw_fd, fw_size, err, offset = 0; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int xfer = 4096; struct stat sb; void *fw_buf; @@ -662,7 +662,7 @@ static int micron_selective_download(int argc, char **argv, perror("fw-download"); goto out_free; } - err = nvme_submit_admin_passthru(hdl, &cmd); + err = libnvme_submit_admin_passthru(hdl, &cmd); if (err < 0) { perror("fw-download"); goto out_free; @@ -703,8 +703,8 @@ static int micron_smbus_option(int argc, char **argv, const char *save = "1 - persistent, 0 - non-persistent (default)"; int fid = MICRON_FEATURE_SMBUS_OPTION; enum eDriveModel model = UNKNOWN_MODEL; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; int err = 0; struct { @@ -785,8 +785,8 @@ static int micron_temp_stats(int argc, char **argv, struct command *acmd, bool is_json = false; struct json_object *root; struct json_object *logPages; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; NVME_ARGS(opts, OPT_FMT("format", 'f', &cfg.fmt, fmt)); @@ -910,8 +910,8 @@ static int micron_pcie_stats(int argc, char **argv, { int i, err = 0, bus = 0, domain = 0, device = 0, function = 0, ctrlIdx; char strTempFile[1024], strTempFile2[1024], cmdbuf[1024]; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; nvme_print_flags_t flags; char *businfo = NULL; char *devicename = NULL; @@ -920,7 +920,7 @@ static int micron_pcie_stats(int argc, char **argv, FILE *fp; char correctable[8] = { 0 }; char uncorrectable[8] = { 0 }; - struct nvme_passthru_cmd admin_cmd = { 0 }; + struct libnvme_passthru_cmd admin_cmd = { 0 }; enum eDriveModel eModel = UNKNOWN_MODEL; char *res; bool is_json = true; @@ -969,7 +969,7 @@ static int micron_pcie_stats(int argc, char **argv, admin_cmd.addr = (__u64)(uintptr_t)&pcie_error_counters; admin_cmd.data_len = sizeof(pcie_error_counters); admin_cmd.cdw10 = 1; - err = nvme_submit_admin_passthru(hdl, &admin_cmd); + err = libnvme_submit_admin_passthru(hdl, &admin_cmd); if (!err) { counters = true; correctable_errors = 10; @@ -1099,14 +1099,14 @@ static int micron_clear_pcie_correctable_errors(int argc, char **argv, { int err = -EINVAL, bus, domain, device, function; char strTempFile[1024], strTempFile2[1024], cmdbuf[1024]; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; char *businfo = NULL; char *devicename = NULL; char tdevice[PATH_MAX] = { 0 }; ssize_t sLinkSize = 0; enum eDriveModel model = UNKNOWN_MODEL; - struct nvme_passthru_cmd admin_cmd = { 0 }; + struct libnvme_passthru_cmd admin_cmd = { 0 }; char correctable[8] = { 0 }; FILE *fp; char *res; @@ -1137,7 +1137,7 @@ static int micron_clear_pcie_correctable_errors(int argc, char **argv, admin_cmd.opcode = 0xD6; admin_cmd.addr = 0; admin_cmd.cdw10 = 0; - err = nvme_submit_admin_passthru(hdl, &admin_cmd); + err = libnvme_submit_admin_passthru(hdl, &admin_cmd); if (!err) { printf("Device correctable error counters are cleared!\n"); goto out; @@ -1810,8 +1810,8 @@ static int micron_nand_stats(int argc, char **argv, unsigned char logC0[C0_log_size] = { 0 }; enum eDriveModel eModel = UNKNOWN_MODEL; struct nvme_id_ctrl ctrl; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; int err, ctrlIdx; __u8 nsze; bool has_d0_log = true; @@ -1959,8 +1959,8 @@ static int micron_smart_ext_log(int argc, char **argv, enum eDriveModel eModel = UNKNOWN_MODEL; int err = 0, ctrlIdx = 0; __u8 log_id; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; bool is_json = true; struct format { char *fmt; @@ -2008,8 +2008,8 @@ static int micron_work_load_log(int argc, char **argv, struct command *acmd, str const char *desc = "Retrieve Micron Workload logs for the given device "; unsigned int micronWorkLoadLog[C5_MicronWorkLoad_log_size/sizeof(int)] = { 0 }; enum eDriveModel eModel = UNKNOWN_MODEL; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; int err = 0, ctrlIdx = 0; bool is_json = true; @@ -2060,8 +2060,8 @@ static int micron_vendor_telemetry_log(int argc, char **argv, enum eDriveModel eModel = UNKNOWN_MODEL; int err = 0, ctrlIdx = 0; bool is_json = true; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; struct format { char *fmt; @@ -2182,7 +2182,7 @@ static void GetCtrlIDDInfo(const char *dir, struct nvme_id_ctrl *ctrlp) "nvme_controller_identify_data.bin", "id-ctrl"); } -static void GetSmartlogData(struct nvme_transport_handle *hdl, const char *dir) +static void GetSmartlogData(struct libnvme_transport_handle *hdl, const char *dir) { struct nvme_smart_log smart_log; @@ -2191,7 +2191,7 @@ static void GetSmartlogData(struct nvme_transport_handle *hdl, const char *dir) "smart_data.bin", "smart log"); } -static void GetErrorlogData(struct nvme_transport_handle *hdl, int entries, const char *dir) +static void GetErrorlogData(struct libnvme_transport_handle *hdl, int entries, const char *dir) { int logSize = entries * sizeof(struct nvme_error_log_page); struct nvme_error_log_page *error_log = @@ -2207,7 +2207,7 @@ static void GetErrorlogData(struct nvme_transport_handle *hdl, int entries, cons free(error_log); } -static void GetGenericLogs(struct nvme_transport_handle *hdl, const char *dir) +static void GetGenericLogs(struct libnvme_transport_handle *hdl, const char *dir) { struct nvme_self_test_log self_test_log; struct nvme_firmware_slot fw_log; @@ -2258,7 +2258,7 @@ static void GetGenericLogs(struct nvme_transport_handle *hdl, const char *dir) "persistent_event_log.bin", "persistent event log"); } -static void GetNSIDDInfo(struct nvme_transport_handle *hdl, const char *dir, int nsid) +static void GetNSIDDInfo(struct libnvme_transport_handle *hdl, const char *dir, int nsid) { char file[PATH_MAX] = { 0 }; struct nvme_id_ns ns; @@ -2309,7 +2309,7 @@ static void GetOSConfig(const char *strOSDirName) } } -static int micron_telemetry_log(struct nvme_transport_handle *hdl, __u8 type, __u8 **data, +static int micron_telemetry_log(struct libnvme_transport_handle *hdl, __u8 type, __u8 **data, int *logSize, int da) { int err, bs = 512, offset = bs; @@ -2368,7 +2368,7 @@ static int micron_telemetry_log(struct nvme_transport_handle *hdl, __u8 type, __ return err; } -static int GetTelemetryData(struct nvme_transport_handle *hdl, const char *dir) +static int GetTelemetryData(struct libnvme_transport_handle *hdl, const char *dir) { unsigned char *buffer = NULL; int i, err, logSize = 0; @@ -2394,7 +2394,7 @@ static int GetTelemetryData(struct nvme_transport_handle *hdl, const char *dir) return err; } -static int GetFeatureSettings(struct nvme_transport_handle *hdl, const char *dir) +static int GetFeatureSettings(struct libnvme_transport_handle *hdl, const char *dir) { unsigned char *bufp, buf[4096] = { 0 }; int i, err, len, errcnt = 0; @@ -2448,7 +2448,7 @@ static int micron_drive_info(int argc, char **argv, struct command *acmd, { const char *desc = "Get drive HW information"; struct nvme_id_ctrl ctrl = { 0 }; - struct nvme_passthru_cmd admin_cmd = { 0 }; + struct libnvme_passthru_cmd admin_cmd = { 0 }; unsigned char logC0[C0_log_size] = { 0 }; struct fb_drive_info { unsigned char hw_ver_major; @@ -2463,8 +2463,8 @@ static int micron_drive_info(int argc, char **argv, struct command *acmd, bool is_json = false; struct json_object *root; struct json_object *driveInfo; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; struct format { char *fmt; }; @@ -2500,7 +2500,7 @@ static int micron_drive_info(int argc, char **argv, struct command *acmd, admin_cmd.addr = (__u64) (uintptr_t) &dinfo; admin_cmd.data_len = (__u32)sizeof(dinfo); admin_cmd.cdw12 = 3; - err = nvme_submit_admin_passthru(hdl, &admin_cmd); + err = libnvme_submit_admin_passthru(hdl, &admin_cmd); if (err) { fprintf(stderr, "ERROR : drive-info opcode failed with 0x%x\n", err); return -1; @@ -2777,8 +2777,8 @@ static int micron_fw_activation_history(int argc, char **argv, struct command *a int count = 0; unsigned int logC2[C2_log_size/sizeof(int)] = { 0 }; enum eDriveModel eModel = UNKNOWN_MODEL; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; int err; bool is_json = false; struct json_object *root, *fw_act, *element; @@ -2886,8 +2886,8 @@ static int micron_latency_stats_track(int argc, char **argv, struct command *acm uint32_t command_mask = 0x7; /* 1:read 2:write 4:trim 7:all */ uint32_t timing_mask = 0x08080800; /* R[31-24]:W[23:16]:T[15:8]:0 */ uint32_t enable = 2; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; struct { char *option; char *command; @@ -3023,8 +3023,8 @@ static int micron_latency_stats_logs(int argc, char **argv, struct command *acmd uint32_t rfu[6]; } log[LATENCY_LOG_ENTRIES]; enum eDriveModel model = UNKNOWN_MODEL; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; int err = -1; const char *desc = "Display Latency tracking log information"; @@ -3059,8 +3059,8 @@ static int micron_latency_stats_info(int argc, char **argv, struct command *acmd const char *desc = "display command latency statistics"; const char *cmdstr = "command to display stats - all|read|write|trim, default is all"; int err = 0; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; enum eDriveModel model = UNKNOWN_MODEL; #define LATENCY_BUCKET_COUNT 32 #define LATENCY_BUCKET_RSVD 32 @@ -3155,8 +3155,8 @@ static int micron_ocp_smart_health_logs(int argc, char **argv, struct command *a unsigned int logFB[FB_log_size/sizeof(int)] = { 0 }; struct nvme_id_ctrl ctrl; enum eDriveModel eModel = UNKNOWN_MODEL; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; bool is_json = true; nsze_from_oacs = false; struct format { @@ -3225,8 +3225,8 @@ static int micron_clr_fw_activation_history(int argc, char **argv, __u64 result = 0; __u8 fid = MICRON_FEATURE_CLEAR_FW_ACTIVATION_HISTORY; enum eDriveModel model = UNKNOWN_MODEL; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; NVME_ARGS(opts); int err = 0; @@ -3264,8 +3264,8 @@ static int micron_telemetry_cntrl_option(int argc, char **argv, int fid = MICRON_FEATURE_TELEMETRY_CONTROL_OPTION; enum eDriveModel model = UNKNOWN_MODEL; struct nvme_id_ctrl ctrl = { 0 }; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; struct { char *option; @@ -3335,11 +3335,11 @@ struct micron_common_log_header { }; /* helper function to retrieve logs with specific offset and max chunk size */ -int nvme_get_log_lpo(struct nvme_transport_handle *hdl, __u8 log_id, __u32 lpo, __u32 chunk, +int nvme_get_log_lpo(struct libnvme_transport_handle *hdl, __u8 log_id, __u32 lpo, __u32 chunk, __u32 data_len, void *data) { __u32 offset = lpo, xfer_len = data_len; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; void *ptr = data; int ret = 0; @@ -3352,7 +3352,7 @@ int nvme_get_log_lpo(struct nvme_transport_handle *hdl, __u8 log_id, __u32 lpo, nvme_init_get_log(&cmd, NVME_NSID_ALL, log_id, NVME_CSI_NVM, ptr, xfer_len); nvme_init_get_log_lpo(&cmd, lpo); - ret = nvme_get_log(hdl, &cmd, false, xfer_len); + ret = libnvme_get_log(hdl, &cmd, false, xfer_len); if (ret) return ret; offset += xfer_len; @@ -3362,7 +3362,7 @@ int nvme_get_log_lpo(struct nvme_transport_handle *hdl, __u8 log_id, __u32 lpo, } /* retrieves logs with common log format */ -static int get_common_log(struct nvme_transport_handle *hdl, uint8_t id, uint8_t **buf, int *size) +static int get_common_log(struct libnvme_transport_handle *hdl, uint8_t id, uint8_t **buf, int *size) { struct micron_common_log_header hdr = { 0 }; int log_size = sizeof(hdr), first = 0, second = 0; @@ -3453,7 +3453,7 @@ static int get_common_log(struct nvme_transport_handle *hdl, uint8_t id, uint8_t return ret; } -static int GetOcpEnhancedTelemetryLog(struct nvme_transport_handle *hdl, const char *dir, int nLogID) +static int GetOcpEnhancedTelemetryLog(struct libnvme_transport_handle *hdl, const char *dir, int nLogID) { int err = 0; unsigned char *pTelemetryDataHeader = 0; @@ -3588,8 +3588,8 @@ static int micron_internal_logs(int argc, char **argv, struct command *acmd, char sn[20] = { 0 }; char msg[256] = { 0 }; int c_logs_index = 8; /* should be current size of aVendorLogs */ - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; struct { unsigned char ucLogPage; const char *strFileName; @@ -3946,8 +3946,8 @@ static int micron_logpage_dir(int argc, char **argv, struct command *acmd, const char *desc = "List the supported log pages"; enum eDriveModel model = UNKNOWN_MODEL; char logbuf[MIN_LOG_SIZE]; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; int i; NVME_ARGS(opts); @@ -4012,8 +4012,8 @@ static int micron_cloud_boot_SSD_version(int argc, char **argv, struct nvme_id_ctrl ctrl; enum eDriveModel eModel = UNKNOWN_MODEL; int err = 0; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; struct format { char *fmt; }; @@ -4068,8 +4068,8 @@ static int micron_device_waf(int argc, char **argv, struct command *acmd, struct nvme_smart_log smart_log; enum eDriveModel eModel = UNKNOWN_MODEL; int err = 0; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; long double tlc_units_written, slc_units_written; long double data_units_written, write_amplification_factor; @@ -4132,8 +4132,8 @@ static int micron_cloud_log(int argc, char **argv, struct command *acmd, struct nvme_id_ctrl ctrl; enum eDriveModel eModel = UNKNOWN_MODEL; int err = 0; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; bool is_json = true; struct format { char *fmt; @@ -4364,8 +4364,8 @@ static void print_micron_health_log_json(struct nvme_smart_log *smart, static int micron_health_info(int argc, char **argv, struct command *acmd, struct plugin *plugin) { - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; const char *desc = "Retrieve SMART/Health log for Micron drives"; const char *fmt = "output format normal|json"; enum eDriveModel eModel = UNKNOWN_MODEL; @@ -4395,7 +4395,7 @@ static int micron_health_info(int argc, char **argv, struct command *acmd, err = nvme_get_log_smart(hdl, NVME_NSID_ALL, &smart_log); if (err) { fprintf(stderr, "Failed to get SMART log: %s\n", - nvme_strerror(err)); + libnvme_strerror(err)); return err; } @@ -4458,8 +4458,8 @@ static void micron_id_ctrl_vs(__u8 *vs, struct json_object *root) static int micron_id_ctrl(int argc, char **argv, struct command *acmd, struct plugin *plugin) { - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; const char *desc = "Identify Controller with Micron vendor fields"; enum eDriveModel eModel = UNKNOWN_MODEL; struct nvme_id_ctrl ctrl = { 0 }; @@ -4486,7 +4486,7 @@ static int micron_id_ctrl(int argc, char **argv, struct command *acmd, err = nvme_identify_ctrl(hdl, &ctrl); if (err) { fprintf(stderr, "identify controller failed: %s\n", - nvme_strerror(err)); + libnvme_strerror(err)); return err; } diff --git a/plugins/nbft/nbft-plugin.c b/plugins/nbft/nbft-plugin.c index d652d2044e..b4f6b294e4 100644 --- a/plugins/nbft/nbft-plugin.c +++ b/plugins/nbft/nbft-plugin.c @@ -151,7 +151,7 @@ static json_object *ssns_to_json(struct nbft_info_subsystem_ns *ss) case NBFT_INFO_NID_TYPE_NS_UUID: if (json_object_add_value_string(ss_json, "nid_type", "uuid")) goto fail; - nvme_uuid_to_string(ss->nid, json_str); + libnvme_uuid_to_string(ss->nid, json_str); break; default: @@ -536,7 +536,7 @@ int show_nbft(int argc, char **argv, struct command *acmd, struct plugin *plugin { const char *desc = "Display contents of the ACPI NBFT files."; bool show_subsys = false, show_hfi = false, show_discovery = false; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; struct nbft_file_entry *head = NULL; struct list_head nbft_list; char *nbft_path = NBFT_SYSFS_PATH; @@ -559,7 +559,7 @@ int show_nbft(int argc, char **argv, struct command *acmd, struct plugin *plugin if (ret < 0) return ret; - ctx = nvme_create_global_ctx(stderr, log_level); + ctx = libnvme_create_global_ctx(stderr, log_level); if (!ctx) { nvme_show_error("Failed to create global context"); return -ENOMEM; diff --git a/plugins/netapp/netapp-nvme.c b/plugins/netapp/netapp-nvme.c index a8d1add9f7..2d55ca257d 100644 --- a/plugins/netapp/netapp-nvme.c +++ b/plugins/netapp/netapp-nvme.c @@ -578,7 +578,7 @@ static void netapp_ontapdevices_print_verbose(struct ontapdevice_info *devices, &lba, &devices[i].ctrl, &devices[i].ns); ontap_get_subsysname(subnqn, subsysname, &devices[i].ctrl); - nvme_uuid_to_string(devices[i].uuid, uuid_str); + libnvme_uuid_to_string(devices[i].uuid, uuid_str); netapp_get_ontap_labels(vsname, nspath, devices[i].log_data); @@ -595,7 +595,7 @@ static void netapp_ontapdevices_print_verbose(struct ontapdevice_info *devices, &lba, &devices[i].ctrl, &devices[i].ns); ontap_get_subsysname(subnqn, subsysname, &devices[i].ctrl); - nvme_uuid_to_string(devices[i].uuid, uuid_str); + libnvme_uuid_to_string(devices[i].uuid, uuid_str); netapp_get_ontap_labels(vsname, nspath, devices[i].log_data); printf(formatstr, devices[i].dev, vsname, subsysname, @@ -639,7 +639,7 @@ static void netapp_ontapdevices_print_regular(struct ontapdevice_info *devices, if (devname && !strcmp(devname, basename(devices[i].dev))) { /* found the device, fetch and print for that alone */ netapp_get_ns_size(size, &lba, &devices[i].ns); - nvme_uuid_to_string(devices[i].uuid, uuid_str); + libnvme_uuid_to_string(devices[i].uuid, uuid_str); netapp_get_ontap_labels(vsname, nspath, devices[i].log_data); ontap_get_subsysname(subnqn, subsysname, @@ -654,7 +654,7 @@ static void netapp_ontapdevices_print_regular(struct ontapdevice_info *devices, for (i = 0; i < count; i++) { /* fetch info and print for all devices */ netapp_get_ns_size(size, &lba, &devices[i].ns); - nvme_uuid_to_string(devices[i].uuid, uuid_str); + libnvme_uuid_to_string(devices[i].uuid, uuid_str); netapp_get_ontap_labels(vsname, nspath, devices[i].log_data); ontap_get_subsysname(subnqn, subsysname, &devices[i].ctrl); @@ -688,7 +688,7 @@ static void netapp_ontapdevices_print_json(struct ontapdevice_info *devices, &lba, &devices[i].ctrl, &devices[i].ns); ontap_get_subsysname(subnqn, subsysname, &devices[i].ctrl); - nvme_uuid_to_string(devices[i].uuid, uuid_str); + libnvme_uuid_to_string(devices[i].uuid, uuid_str); netapp_get_ontap_labels(vsname, nspath, devices[i].log_data); @@ -707,7 +707,7 @@ static void netapp_ontapdevices_print_json(struct ontapdevice_info *devices, &lba, &devices[i].ctrl, &devices[i].ns); ontap_get_subsysname(subnqn, subsysname, &devices[i].ctrl); - nvme_uuid_to_string(devices[i].uuid, uuid_str); + libnvme_uuid_to_string(devices[i].uuid, uuid_str); netapp_get_ontap_labels(vsname, nspath, devices[i].log_data); netapp_ontapdevice_json(json_devices, devices[i].dev, @@ -725,13 +725,13 @@ static void netapp_ontapdevices_print_json(struct ontapdevice_info *devices, json_free_object(root); } -static int nvme_get_ontap_c2_log(struct nvme_transport_handle *hdl, __u32 nsid, void *buf, __u32 buflen) +static int nvme_get_ontap_c2_log(struct libnvme_transport_handle *hdl, __u32 nsid, void *buf, __u32 buflen) { - struct nvme_passthru_cmd get_log; + struct libnvme_passthru_cmd get_log; int err; memset(buf, 0, buflen); - memset(&get_log, 0, sizeof(struct nvme_passthru_cmd)); + memset(&get_log, 0, sizeof(struct libnvme_passthru_cmd)); get_log.opcode = nvme_admin_get_log_page; get_log.nsid = nsid; @@ -746,7 +746,7 @@ static int nvme_get_ontap_c2_log(struct nvme_transport_handle *hdl, __u32 nsid, get_log.cdw10 |= ONTAP_C2_LOG_NSINFO_LSP << 8; get_log.cdw11 = numdu; - err = nvme_submit_admin_passthru(hdl, &get_log); + err = libnvme_submit_admin_passthru(hdl, &get_log); if (err) { fprintf(stderr, "ioctl error %0x\n", err); return 1; @@ -755,7 +755,7 @@ static int nvme_get_ontap_c2_log(struct nvme_transport_handle *hdl, __u32 nsid, return 0; } -static int netapp_smdevices_get_info(struct nvme_transport_handle *hdl, +static int netapp_smdevices_get_info(struct libnvme_transport_handle *hdl, struct smdevice_info *item, const char *dev) { @@ -765,15 +765,15 @@ static int netapp_smdevices_get_info(struct nvme_transport_handle *hdl, if (err) { fprintf(stderr, "Identify Controller failed to %s (%s)\n", dev, - err < 0 ? nvme_strerror(-err) : - nvme_status_to_string(err, false)); + err < 0 ? libnvme_strerror(-err) : + libnvme_status_to_string(err, false)); return 0; } if (strncmp("NetApp E-Series", item->ctrl.mn, 15) != 0) return 0; /* not the right model of controller */ - err = nvme_get_nsid(hdl, &item->nsid); + err = libnvme_get_nsid(hdl, &item->nsid); if (err) return err; @@ -781,8 +781,8 @@ static int netapp_smdevices_get_info(struct nvme_transport_handle *hdl, if (err) { fprintf(stderr, "Unable to identify namespace for %s (%s)\n", - dev, err < 0 ? nvme_strerror(-err) : - nvme_status_to_string(err, false)); + dev, err < 0 ? libnvme_strerror(-err) : + libnvme_status_to_string(err, false)); return 0; } strncpy(item->dev, dev, sizeof(item->dev) - 1); @@ -790,7 +790,7 @@ static int netapp_smdevices_get_info(struct nvme_transport_handle *hdl, return 1; } -static int netapp_ontapdevices_get_info(struct nvme_transport_handle *hdl, +static int netapp_ontapdevices_get_info(struct libnvme_transport_handle *hdl, struct ontapdevice_info *item, const char *dev) { @@ -800,8 +800,8 @@ static int netapp_ontapdevices_get_info(struct nvme_transport_handle *hdl, err = nvme_identify_ctrl(hdl, &item->ctrl); if (err) { fprintf(stderr, "Identify Controller failed to %s (%s)\n", - dev, err < 0 ? nvme_strerror(-err) : - nvme_status_to_string(err, false)); + dev, err < 0 ? libnvme_strerror(-err) : + libnvme_status_to_string(err, false)); return 0; } @@ -809,13 +809,13 @@ static int netapp_ontapdevices_get_info(struct nvme_transport_handle *hdl, /* not the right controller model */ return 0; - err = nvme_get_nsid(hdl, &item->nsid); + err = libnvme_get_nsid(hdl, &item->nsid); err = nvme_identify_ns(hdl, item->nsid, &item->ns); if (err) { fprintf(stderr, "Unable to identify namespace for %s (%s)\n", - dev, err < 0 ? nvme_strerror(-err) : - nvme_status_to_string(err, false)); + dev, err < 0 ? libnvme_strerror(-err) : + libnvme_status_to_string(err, false)); return 0; } @@ -829,8 +829,8 @@ static int netapp_ontapdevices_get_info(struct nvme_transport_handle *hdl, err = nvme_identify_ns_descs_list(hdl, item->nsid, nsdescs); if (err) { fprintf(stderr, "Unable to identify namespace descriptor for %s (%s)\n", - dev, err < 0 ? nvme_strerror(-err) : - nvme_status_to_string(err, false)); + dev, err < 0 ? libnvme_strerror(-err) : + libnvme_status_to_string(err, false)); free(nsdescs); return 0; } @@ -841,8 +841,8 @@ static int netapp_ontapdevices_get_info(struct nvme_transport_handle *hdl, err = nvme_get_ontap_c2_log(hdl, item->nsid, item->log_data, ONTAP_C2_LOG_SIZE); if (err) { fprintf(stderr, "Unable to get log page data for %s (%s)\n", - dev, err < 0 ? nvme_strerror(-err) : - nvme_status_to_string(err, false)); + dev, err < 0 ? libnvme_strerror(-err) : + libnvme_status_to_string(err, false)); return 0; } @@ -893,14 +893,14 @@ static int netapp_smdevices(int argc, char **argv, struct command *acmd, struct plugin *plugin) { const char *desc = "Display information about E-Series volumes."; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = nvme_create_global_ctx(stdout, DEFAULT_LOGLEVEL); + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = libnvme_create_global_ctx(stdout, DEFAULT_LOGLEVEL); struct dirent **devices; int num, i, ret, fmt; struct smdevice_info *smdevices; char path[264]; char *devname = NULL; int num_smdevices = 0; - struct nvme_transport_handle *hdl; + struct libnvme_transport_handle *hdl; NVME_ARGS(opts); @@ -953,16 +953,16 @@ static int netapp_smdevices(int argc, char **argv, struct command *acmd, for (i = 0; i < num; i++) { snprintf(path, sizeof(path), "%s%s", dev_path, devices[i]->d_name); - ret = nvme_open(ctx, path, &hdl); + ret = libnvme_open(ctx, path, &hdl); if (ret) { fprintf(stderr, "Unable to open %s: %s\n", path, - nvme_strerror(-ret)); + libnvme_strerror(-ret)); continue; } num_smdevices += netapp_smdevices_get_info(hdl, &smdevices[num_smdevices], path); - nvme_close(hdl); + libnvme_close(hdl); } if (num_smdevices) { @@ -991,7 +991,7 @@ static int netapp_smdevices(int argc, char **argv, struct command *acmd, static int netapp_ontapdevices(int argc, char **argv, struct command *acmd, struct plugin *plugin) { - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = nvme_create_global_ctx(stdout, DEFAULT_LOGLEVEL); + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = libnvme_create_global_ctx(stdout, DEFAULT_LOGLEVEL); const char *desc = "Display information about ONTAP devices."; struct dirent **devices; int num, i, ret, fmt; @@ -999,7 +999,7 @@ static int netapp_ontapdevices(int argc, char **argv, struct command *acmd, char path[264]; char *devname = NULL; int num_ontapdevices = 0; - struct nvme_transport_handle *hdl; + struct libnvme_transport_handle *hdl; NVME_ARGS(opts); @@ -1052,17 +1052,17 @@ static int netapp_ontapdevices(int argc, char **argv, struct command *acmd, for (i = 0; i < num; i++) { snprintf(path, sizeof(path), "%s%s", dev_path, devices[i]->d_name); - ret = nvme_open(ctx, path, &hdl); + ret = libnvme_open(ctx, path, &hdl); if (ret) { fprintf(stderr, "Unable to open %s: %s\n", path, - nvme_strerror(-ret)); + libnvme_strerror(-ret)); continue; } num_ontapdevices += netapp_ontapdevices_get_info(hdl, &ontapdevices[num_ontapdevices], path); - nvme_close(hdl); + libnvme_close(hdl); } if (num_ontapdevices) { diff --git a/plugins/ocp/ocp-clear-features.c b/plugins/ocp/ocp-clear-features.c index 02001a1d0e..800d4888ab 100644 --- a/plugins/ocp/ocp-clear-features.c +++ b/plugins/ocp/ocp-clear-features.c @@ -17,8 +17,8 @@ static int ocp_clear_feature(int argc, char **argv, const char *desc, const __u8 fid) { - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; __u64 result = 0; __u32 clear = 1 << 31; __u8 uuid_index = 0; @@ -66,8 +66,8 @@ int get_ocp_error_counters(int argc, char **argv, struct command *acmd, const char *nsid = "Byte[04-07]: Namespace Identifier Valid/Invalid/Inactive"; const char *no_uuid = "Do not try to automatically detect UUID index"; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; __u64 result; int err; bool uuid; diff --git a/plugins/ocp/ocp-fw-activation-history.c b/plugins/ocp/ocp-fw-activation-history.c index aed8f3c8c8..5eaa2370d2 100644 --- a/plugins/ocp/ocp-fw-activation-history.c +++ b/plugins/ocp/ocp-fw-activation-history.c @@ -29,10 +29,10 @@ int ocp_fw_activation_history_log(int argc, char **argv, struct command *acmd, NVME_ARGS(opts); - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; struct fw_activation_history fw_history = { 0 }; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; __u8 uuid_index = 0; int err; @@ -51,7 +51,7 @@ int ocp_fw_activation_history_log(int argc, char **argv, struct command *acmd, cmd.cdw14 |= NVME_FIELD_ENCODE(uuid_index, NVME_LOG_CDW14_UUID_SHIFT, NVME_LOG_CDW14_UUID_MASK); - err = nvme_get_log(hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); + err = libnvme_get_log(hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); if (err) nvme_show_status(err); diff --git a/plugins/ocp/ocp-hardware-component-log.c b/plugins/ocp/ocp-hardware-component-log.c index 861ba8940d..fb5cb5dc26 100644 --- a/plugins/ocp/ocp-hardware-component-log.c +++ b/plugins/ocp/ocp-hardware-component-log.c @@ -167,10 +167,10 @@ const char *hwcomp_id_to_string(__u32 id) return "Reserved"; } -static int get_hwcomp_log_data(struct nvme_transport_handle *hdl, struct hwcomp_log *log) +static int get_hwcomp_log_data(struct libnvme_transport_handle *hdl, struct hwcomp_log *log) { size_t desc_offset = offsetof(struct hwcomp_log, desc); - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; nvme_uint128_t log_size; long double log_bytes; __u32 len; @@ -188,7 +188,7 @@ static int get_hwcomp_log_data(struct nvme_transport_handle *hdl, struct hwcomp_ cmd.cdw14 |= NVME_FIELD_ENCODE(uidx, NVME_LOG_CDW14_UUID_SHIFT, NVME_LOG_CDW14_UUID_MASK); - ret = nvme_get_log(hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); + ret = libnvme_get_log(hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); if (ret) { print_info_error("error: ocp: failed to get hwcomp log size (ret: %d)\n", ret); return ret; @@ -217,7 +217,7 @@ static int get_hwcomp_log_data(struct nvme_transport_handle *hdl, struct hwcomp_ log->desc = calloc(1, len); if (!log->desc) { - fprintf(stderr, "error: ocp: calloc: %s\n", nvme_strerror(errno)); + fprintf(stderr, "error: ocp: calloc: %s\n", libnvme_strerror(errno)); return -errno; } @@ -228,7 +228,7 @@ static int get_hwcomp_log_data(struct nvme_transport_handle *hdl, struct hwcomp_ (enum nvme_cmd_get_log_lid)OCP_LID_HWCOMP, NVME_CSI_NVM, log->desc, len); nvme_init_get_log_lpo(&cmd, desc_offset); - ret = nvme_get_log(hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); + ret = libnvme_get_log(hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); if (ret) { print_info_error("error: ocp: failed to get log page (hwcomp: %02X, ret: %d)\n", OCP_LID_HWCOMP, ret); @@ -240,7 +240,7 @@ static int get_hwcomp_log_data(struct nvme_transport_handle *hdl, struct hwcomp_ return ret; } -static int get_hwcomp_log(struct nvme_transport_handle *hdl, __u32 id, bool list) +static int get_hwcomp_log(struct libnvme_transport_handle *hdl, __u32 id, bool list) { int ret; nvme_print_flags_t fmt; @@ -270,8 +270,8 @@ static int get_hwcomp_log(struct nvme_transport_handle *hdl, __u32 id, bool list int ocp_hwcomp_log(int argc, char **argv, struct command *acmd, struct plugin *plugin) { - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; int ret = 0; const char *desc = "retrieve hardware component log"; struct config { diff --git a/plugins/ocp/ocp-nvme.c b/plugins/ocp/ocp-nvme.c index 280188558b..01aa6113e8 100644 --- a/plugins/ocp/ocp-nvme.c +++ b/plugins/ocp/ocp-nvme.c @@ -198,7 +198,7 @@ static const char *save = "Specifies that the controller shall save the attribut static const char *enable_ieee1667_silo = "enable IEEE1667 silo"; static const char *raw_use = "use binary output"; -static int get_c3_log_page(struct nvme_transport_handle *hdl, char *format) +static int get_c3_log_page(struct libnvme_transport_handle *hdl, char *format) { struct ssd_latency_monitor_log *log_data; nvme_print_flags_t fmt; @@ -214,7 +214,7 @@ static int get_c3_log_page(struct nvme_transport_handle *hdl, char *format) data = malloc(sizeof(__u8) * C3_LATENCY_MON_LOG_BUF_LEN); if (!data) { - fprintf(stderr, "ERROR : OCP : malloc : %s\n", nvme_strerror(errno)); + fprintf(stderr, "ERROR : OCP : malloc : %s\n", libnvme_strerror(errno)); return -1; } memset(data, 0, sizeof(__u8) * C3_LATENCY_MON_LOG_BUF_LEN); @@ -222,7 +222,7 @@ static int get_c3_log_page(struct nvme_transport_handle *hdl, char *format) ret = ocp_get_log_simple(hdl, OCP_LID_LMLOG, C3_LATENCY_MON_LOG_BUF_LEN, data); if (strcmp(format, "json")) - fprintf(stderr, "NVMe Status:%s(%x)\n", nvme_status_to_string(ret, false), ret); + fprintf(stderr, "NVMe Status:%s(%x)\n", libnvme_status_to_string(ret, false), ret); if (!ret) { log_data = (struct ssd_latency_monitor_log *)data; @@ -264,8 +264,8 @@ static int ocp_latency_monitor_log(int argc, char **argv, struct plugin *plugin) { const char *desc = "Retrieve latency monitor log data."; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; int ret = 0; NVME_ARGS(opts); @@ -286,8 +286,8 @@ static int ocp_latency_monitor_log(int argc, char **argv, int ocp_set_latency_monitor_feature(int argc, char **argv, struct command *acmd, struct plugin *plugin) { int err = -1; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; __u64 result; struct feature_latency_monitor buf = { 0 }; __u32 nsid = NVME_NSID_ALL; @@ -348,12 +348,12 @@ int ocp_set_latency_monitor_feature(int argc, char **argv, struct command *acmd, if (err) return err; - err = fstat(nvme_transport_handle_get_fd(hdl), &nvme_stat); + err = fstat(libnvme_transport_handle_get_fd(hdl), &nvme_stat); if (err < 0) return err; if (S_ISBLK(nvme_stat.st_mode)) { - err = nvme_get_nsid(hdl, &nsid); + err = libnvme_get_nsid(hdl, &nsid); if (err < 0) { perror("invalid-namespace-id"); return err; @@ -394,7 +394,7 @@ int ocp_set_latency_monitor_feature(int argc, char **argv, struct command *acmd, printf("discard debug log: 0x%x\n", buf.discard_debug_log); printf("latency monitor feature enable: 0x%x\n", buf.latency_monitor_feature_enable); } else if (err > 0) { - fprintf(stderr, "NVMe Status:%s(%x)\n", nvme_status_to_string(err, false), err); + fprintf(stderr, "NVMe Status:%s(%x)\n", libnvme_status_to_string(err, false), err); } return err; @@ -407,8 +407,8 @@ static int ocp_get_latency_monitor_feature(int argc, char **argv, struct command const char *sel = "[0-3]: current/default/saved/supported/"; const char *nsid = "Byte[04-07]: Namespace Identifier Valid/Invalid/Inactive"; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; __u64 result; int err; @@ -482,7 +482,7 @@ static const char *eol_plp_failure_mode_to_string(__u8 mode) return "Reserved"; } -static int eol_plp_failure_mode_get(struct nvme_transport_handle *hdl, const __u32 nsid, const __u8 fid, +static int eol_plp_failure_mode_get(struct libnvme_transport_handle *hdl, const __u32 nsid, const __u8 fid, __u8 sel, bool uuid) { __u8 uidx = 0; @@ -513,7 +513,7 @@ static int eol_plp_failure_mode_get(struct nvme_transport_handle *hdl, const __u return err; } -static int eol_plp_failure_mode_set(struct nvme_transport_handle *hdl, const __u32 nsid, +static int eol_plp_failure_mode_set(struct libnvme_transport_handle *hdl, const __u32 nsid, const __u8 fid, __u8 mode, bool sv, bool uuid) { @@ -555,8 +555,8 @@ static int eol_plp_failure_mode(int argc, char **argv, struct command *acmd, const char *mode = "[0-3]: default/rom/wtm/normal"; const __u32 nsid = 0; const __u8 fid = OCP_FID_ROWTM; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; int err; struct config { @@ -656,11 +656,11 @@ static void print_telemetry_header(struct telemetry_initiated_log *logheader, in } } -static int get_telemetry_data(struct nvme_transport_handle *hdl, __u32 ns, __u8 tele_type, +static int get_telemetry_data(struct libnvme_transport_handle *hdl, __u32 ns, __u8 tele_type, __u32 data_len, void *data, __u8 nLSP, __u8 nRAE, __u64 offset) { - struct nvme_passthru_cmd cmd = { + struct libnvme_passthru_cmd cmd = { .opcode = nvme_admin_get_log_page, .nsid = ns, .addr = (__u64)(uintptr_t) data, @@ -675,7 +675,7 @@ static int get_telemetry_data(struct nvme_transport_handle *hdl, __u32 ns, __u8 cmd.cdw12 = (__u32)(0x00000000FFFFFFFF & offset); cmd.cdw13 = (__u32)((0xFFFFFFFF00000000 & offset) >> 8); cmd.cdw14 = 0; - return nvme_submit_admin_passthru(hdl, &cmd); + return libnvme_submit_admin_passthru(hdl, &cmd); } static void print_telemetry_data_area_1(struct telemetry_data_area_1 *da1, @@ -795,7 +795,7 @@ static void print_telemetry_da_fifo(struct telemetry_event_desc *da_fifo, printf("===============================================\n\n"); } } -static int extract_dump_get_log(struct nvme_transport_handle *hdl, char *featurename, char *filename, char *sn, +static int extract_dump_get_log(struct libnvme_transport_handle *hdl, char *featurename, char *filename, char *sn, int dumpsize, int transfersize, __u32 nsid, __u8 log_id, __u8 lsp, __u64 offset, bool rae) { @@ -806,7 +806,7 @@ static int extract_dump_get_log(struct nvme_transport_handle *hdl, char *feature int output = 0; int total_loop_cnt = dumpsize / transfersize; int last_xfer_size = dumpsize % transfersize; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; if (last_xfer_size) total_loop_cnt++; @@ -824,7 +824,7 @@ static int extract_dump_get_log(struct nvme_transport_handle *hdl, char *feature nvme_init_get_log(&cmd, nsid, log_id, NVME_CSI_NVM, data, transfersize); nvme_init_get_log_lpo(&cmd, offset); - err = nvme_get_log(hdl, &cmd, rae, NVME_LOG_PAGE_PDU_SIZE); + err = libnvme_get_log(hdl, &cmd, rae, NVME_LOG_PAGE_PDU_SIZE); if (err) { if (i > 0) goto close_output; @@ -863,7 +863,7 @@ static int extract_dump_get_log(struct nvme_transport_handle *hdl, char *feature return err; } -static int get_telemetry_dump(struct nvme_transport_handle *hdl, char *filename, char *sn, +static int get_telemetry_dump(struct libnvme_transport_handle *hdl, char *filename, char *sn, enum TELEMETRY_TYPE tele_type, int data_area, bool header_print) { __u32 err = 0, nsid = 0; @@ -1164,7 +1164,7 @@ static int get_telemetry_dump(struct nvme_transport_handle *hdl, char *filename, return err; } -static int get_telemetry_log_page_data(struct nvme_transport_handle *hdl, +static int get_telemetry_log_page_data(struct libnvme_transport_handle *hdl, int tele_type, int tele_area, const char *output_file) @@ -1172,7 +1172,7 @@ static int get_telemetry_log_page_data(struct nvme_transport_handle *hdl, void *telemetry_log; const size_t bs = 512; struct nvme_telemetry_log *hdr; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; size_t full_size = 0, offset = bs; int err, fd; @@ -1186,7 +1186,7 @@ static int get_telemetry_log_page_data(struct nvme_transport_handle *hdl, telemetry_log = malloc(bs); if (!hdr || !telemetry_log) { fprintf(stderr, "Failed to allocate %zu bytes for log: %s\n", - bs, nvme_strerror(errno)); + bs, libnvme_strerror(errno)); err = -ENOMEM; goto exit_status; } @@ -1195,7 +1195,7 @@ static int get_telemetry_log_page_data(struct nvme_transport_handle *hdl, fd = open(output_file, O_WRONLY | O_CREAT | O_TRUNC, 0666); if (fd < 0) { fprintf(stderr, "Failed to open output file %s: %s!\n", - output_file, nvme_strerror(errno)); + output_file, libnvme_strerror(errno)); err = fd; goto exit_status; } @@ -1204,7 +1204,7 @@ static int get_telemetry_log_page_data(struct nvme_transport_handle *hdl, cmd.cdw10 |= NVME_FIELD_ENCODE(NVME_LOG_TELEM_HOST_LSP_CREATE, NVME_LOG_CDW10_LSP_SHIFT, NVME_LOG_CDW10_LSP_MASK); - err = nvme_get_log(hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); + err = libnvme_get_log(hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); if (err < 0) nvme_show_error("Failed to fetch the log from drive.\n"); else if (err > 0) { @@ -1241,7 +1241,7 @@ static int get_telemetry_log_page_data(struct nvme_transport_handle *hdl, nvme_init_get_log(&cmd, NVME_NSID_ALL, log_id, NVME_CSI_NVM, telemetry_log, bs); nvme_init_get_log_lpo(&cmd, offset); - err = nvme_get_log(hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); + err = libnvme_get_log(hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); if (err < 0) { nvme_show_error("Failed to fetch the log from drive.\n"); break; @@ -1269,7 +1269,7 @@ static int get_telemetry_log_page_data(struct nvme_transport_handle *hdl, return err; } -static int get_c9_log_page_data(struct nvme_transport_handle *hdl, +static int get_c9_log_page_data(struct libnvme_transport_handle *hdl, int print_data, int save_bin, const char *output_file) @@ -1284,7 +1284,7 @@ static int get_c9_log_page_data(struct nvme_transport_handle *hdl, header_data = (__u8 *)malloc(sizeof(__u8) * C9_TELEMETRY_STR_LOG_LEN); if (!header_data) { - fprintf(stderr, "ERROR : OCP : malloc : %s\n", nvme_strerror(errno)); + fprintf(stderr, "ERROR : OCP : malloc : %s\n", libnvme_strerror(errno)); return -1; } memset(header_data, 0, sizeof(__u8) * C9_TELEMETRY_STR_LOG_LEN); @@ -1326,7 +1326,7 @@ static int get_c9_log_page_data(struct nvme_transport_handle *hdl, pC9_string_buffer = (__u8 *)malloc(sizeof(__u8) * total_log_page_sz); if (!pC9_string_buffer) { - fprintf(stderr, "ERROR : OCP : malloc : %s\n", nvme_strerror(errno)); + fprintf(stderr, "ERROR : OCP : malloc : %s\n", libnvme_strerror(errno)); return -1; } memset(pC9_string_buffer, 0, sizeof(__u8) * total_log_page_sz); @@ -1341,7 +1341,7 @@ static int get_c9_log_page_data(struct nvme_transport_handle *hdl, fd = open(output_file, O_WRONLY | O_CREAT | O_TRUNC, 0666); if (fd < 0) { fprintf(stderr, "Failed to open output file %s: %s!\n", output_file, - nvme_strerror(errno)); + libnvme_strerror(errno)); ret = fd; goto free; } @@ -1431,8 +1431,8 @@ static int ocp_telemetry_log(int argc, char **argv, struct command *acmd, struct const char *telemetry_type = "Telemetry Type; 'host', 'host0', 'host1' or 'controller'"; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; int err = 0; __u32 nsid = NVME_NSID_ALL; struct stat nvme_stat; @@ -1461,12 +1461,12 @@ static int ocp_telemetry_log(int argc, char **argv, struct command *acmd, struct if (opt.telemetry_type == 0) opt.telemetry_type = "host"; - err = fstat(nvme_transport_handle_get_fd(hdl), &nvme_stat); + err = fstat(libnvme_transport_handle_get_fd(hdl), &nvme_stat); if (err < 0) return err; if (S_ISBLK(nvme_stat.st_mode)) { - err = nvme_get_nsid(hdl, &nsid); + err = libnvme_get_nsid(hdl, &nsid); if (err < 0) return err; } @@ -1522,7 +1522,7 @@ static int ocp_telemetry_log(int argc, char **argv, struct command *acmd, struct goto out; } - err = nvme_set_etdas(hdl, &host_behavior_changed); + err = libnvme_set_etdas(hdl, &host_behavior_changed); if (err) { fprintf(stderr, "%s: Failed to set ETDAS bit\n", __func__); return err; @@ -1544,7 +1544,7 @@ static int ocp_telemetry_log(int argc, char **argv, struct command *acmd, struct if (host_behavior_changed) { host_behavior_changed = false; - err = nvme_clear_etdas(hdl, &host_behavior_changed); + err = libnvme_clear_etdas(hdl, &host_behavior_changed); if (err) { /* Continue on if this fails, it's not a fatal condition */ nvme_show_error("Failed to clear ETDAS bit.\n"); @@ -1595,7 +1595,7 @@ static int ocp_telemetry_log(int argc, char **argv, struct command *acmd, struct err = get_telemetry_dump(hdl, opt.output_file, sn, tele_type, tele_area, true); if (err) - fprintf(stderr, "NVMe Status: %s(%x)\n", nvme_status_to_string(err, false), + fprintf(stderr, "NVMe Status: %s(%x)\n", libnvme_status_to_string(err, false), err); break; } @@ -1625,7 +1625,7 @@ static __u8 unsupported_req_guid[GUID_LEN] = { static int ocp_unsupported_requirements_log(int argc, char **argv, struct command *acmd, struct plugin *plugin); -static int get_c5_log_page(struct nvme_transport_handle *hdl, char *format) +static int get_c5_log_page(struct libnvme_transport_handle *hdl, char *format) { nvme_print_flags_t fmt; int ret; @@ -1642,7 +1642,7 @@ static int get_c5_log_page(struct nvme_transport_handle *hdl, char *format) data = (__u8 *)malloc(sizeof(__u8) * C5_UNSUPPORTED_REQS_LEN); if (!data) { - fprintf(stderr, "ERROR : OCP : malloc : %s\n", nvme_strerror(errno)); + fprintf(stderr, "ERROR : OCP : malloc : %s\n", libnvme_strerror(errno)); return -1; } memset(data, 0, sizeof(__u8) * C5_UNSUPPORTED_REQS_LEN); @@ -1684,8 +1684,8 @@ static int ocp_unsupported_requirements_log(int argc, char **argv, struct comman struct plugin *plugin) { const char *desc = "Retrieve unsupported requirements log data."; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; int ret = 0; struct config { @@ -1724,10 +1724,10 @@ static __u8 error_recovery_guid[GUID_LEN] = { 0xba, 0x83, 0x19, 0x5a }; -static int get_c1_log_page(struct nvme_transport_handle *hdl, char *format); +static int get_c1_log_page(struct libnvme_transport_handle *hdl, char *format); static int ocp_error_recovery_log(int argc, char **argv, struct command *acmd, struct plugin *plugin); -static int get_c1_log_page(struct nvme_transport_handle *hdl, char *format) +static int get_c1_log_page(struct libnvme_transport_handle *hdl, char *format) { struct ocp_error_recovery_log_page *log_data; nvme_print_flags_t fmt; @@ -1743,7 +1743,7 @@ static int get_c1_log_page(struct nvme_transport_handle *hdl, char *format) data = (__u8 *)malloc(sizeof(__u8) * C1_ERROR_RECOVERY_LOG_BUF_LEN); if (!data) { - fprintf(stderr, "ERROR : OCP : malloc : %s\n", nvme_strerror(errno)); + fprintf(stderr, "ERROR : OCP : malloc : %s\n", libnvme_strerror(errno)); return -1; } memset(data, 0, sizeof(__u8) * C1_ERROR_RECOVERY_LOG_BUF_LEN); @@ -1785,8 +1785,8 @@ static int get_c1_log_page(struct nvme_transport_handle *hdl, char *format) static int ocp_error_recovery_log(int argc, char **argv, struct command *acmd, struct plugin *plugin) { const char *desc = "Retrieve C1h Error Recovery Log data."; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; int ret = 0; struct config { @@ -1824,10 +1824,10 @@ static __u8 dev_cap_req_guid[GUID_LEN] = { 0x91, 0x3c, 0x05, 0xb7 }; -static int get_c4_log_page(struct nvme_transport_handle *hdl, char *format); +static int get_c4_log_page(struct libnvme_transport_handle *hdl, char *format); static int ocp_device_capabilities_log(int argc, char **argv, struct command *acmd, struct plugin *plugin); -static int get_c4_log_page(struct nvme_transport_handle *hdl, char *format) +static int get_c4_log_page(struct libnvme_transport_handle *hdl, char *format) { struct ocp_device_capabilities_log_page *log_data; nvme_print_flags_t fmt; @@ -1843,7 +1843,7 @@ static int get_c4_log_page(struct nvme_transport_handle *hdl, char *format) data = (__u8 *)malloc(sizeof(__u8) * C4_DEV_CAP_REQ_LEN); if (!data) { - fprintf(stderr, "ERROR : OCP : malloc : %s\n", nvme_strerror(errno)); + fprintf(stderr, "ERROR : OCP : malloc : %s\n", libnvme_strerror(errno)); return -1; } memset(data, 0, sizeof(__u8) * C4_DEV_CAP_REQ_LEN); @@ -1885,8 +1885,8 @@ static int get_c4_log_page(struct nvme_transport_handle *hdl, char *format) static int ocp_device_capabilities_log(int argc, char **argv, struct command *acmd, struct plugin *plugin) { const char *desc = "Retrieve C4h Device Capabilities Log data."; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; int ret = 0; struct config { @@ -1916,7 +1916,7 @@ static int ocp_device_capabilities_log(int argc, char **argv, struct command *ac /////////////////////////////////////////////////////////////////////////////// /// Set Telemetry Profile (Feature Identifier C8h) Set Feature -static int ocp_set_telemetry_profile(struct nvme_transport_handle *hdl, __u8 tps) +static int ocp_set_telemetry_profile(struct libnvme_transport_handle *hdl, __u8 tps) { __u64 result; int err; @@ -1949,8 +1949,8 @@ static int ocp_set_telemetry_profile_feature(int argc, char **argv, struct comma { const char *desc = "Set Telemetry Profile (Feature Identifier C8h) Set Feature."; const char *tps = "Telemetry Profile Select for device debug data collection"; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; int err; struct config { @@ -1988,8 +1988,8 @@ static int ocp_get_telemetry_profile_feature(int argc, char **argv, struct comma const char *sel = "[0-3]: current/default/saved/supported/"; const char *nsid = "Byte[04-07]: Namespace Identifier Valid/Invalid/Inactive"; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; __u64 result; int err; @@ -2048,7 +2048,7 @@ static int ocp_get_telemetry_profile_feature(int argc, char **argv, struct comma /// DSSD Power State (Feature Identifier C7h) Set Feature static int -set_dssd_power_state(struct nvme_transport_handle *hdl, +set_dssd_power_state(struct libnvme_transport_handle *hdl, const __u32 nsid, const __u8 fid, __u8 power_state, bool sv, bool uuid) @@ -2089,8 +2089,8 @@ static int set_dssd_power_state_feature(int argc, char **argv, struct command *a const char *power_state = "DSSD Power State to set in watts"; const char *save = "Specifies that the controller shall save the attribute"; const __u32 nsid = 0; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; int err; struct config { @@ -2125,7 +2125,7 @@ static int set_dssd_power_state_feature(int argc, char **argv, struct command *a /////////////////////////////////////////////////////////////////////////////// /// DSSD Power State (Feature Identifier C7h) Get Feature -static int get_dssd_power_state(struct nvme_transport_handle *hdl, const __u32 nsid, +static int get_dssd_power_state(struct libnvme_transport_handle *hdl, const __u32 nsid, const __u8 fid, __u8 sel, bool uuid) { __u64 result; @@ -2163,8 +2163,8 @@ static int get_dssd_power_state_feature(int argc, char **argv, struct command *a const char *sel = "[0-3]: current/default/saved/supported/"; const __u32 nsid = 0; const __u8 fid = OCP_FID_DSSDPS; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; int i, err; struct config { @@ -2216,8 +2216,8 @@ static int set_plp_health_check_interval(int argc, char **argv, struct command * const char *plp_health_interval = "[31:16]:PLP Health Check Interval"; const char *sv = "Specifies that the controller shall save the attribute"; const __u32 nsid = 0; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; int err; __u64 result; __u8 uidx = 0; @@ -2274,8 +2274,8 @@ static int get_plp_health_check_interval(int argc, char **argv, struct command * const char *desc = "Define Issue Get Feature command (FID : 0xC6) PLP Health Check Interval"; const __u32 nsid = 0; const __u8 fid = 0xc6; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; __u64 result; int err; @@ -2323,8 +2323,8 @@ static int set_dssd_async_event_config(int argc, char **argv, struct command *ac const char *epn = "[0]:Enable Panic Notices"; const char *sv = "Specifies that the controller shall save the attribute"; const __u32 nsid = 0; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; int err; __u64 result; __u8 uidx = 0; @@ -2377,8 +2377,8 @@ static int get_dssd_async_event_config(int argc, char **argv, struct command *ac const char *sel = "[0-3]: current/default/saved/supported"; const __u32 nsid = 0; const __u8 fid = OCP_FID_DAEC; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; __u64 result; int err; @@ -2421,7 +2421,7 @@ static int get_dssd_async_event_config(int argc, char **argv, struct command *ac static int ocp_telemetry_str_log_format(int argc, char **argv, struct command *acmd, struct plugin *plugin); -static int get_c9_log_page(struct nvme_transport_handle *hdl, +static int get_c9_log_page(struct libnvme_transport_handle *hdl, char *format, const char *output_file) { @@ -2448,8 +2448,8 @@ static int get_c9_log_page(struct nvme_transport_handle *hdl, static int ocp_telemetry_str_log_format(int argc, char **argv, struct command *acmd, struct plugin *plugin) { - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; int ret = 0; char file_path[PATH_MAX]; const char *string_suffix = ".bin"; @@ -2507,7 +2507,7 @@ static __u8 tcg_configuration_guid[GUID_LEN] = { static int ocp_tcg_configuration_log(int argc, char **argv, struct command *acmd, struct plugin *plugin); -static int get_c7_log_page(struct nvme_transport_handle *hdl, char *format) +static int get_c7_log_page(struct libnvme_transport_handle *hdl, char *format) { nvme_print_flags_t fmt; int ret; @@ -2524,7 +2524,7 @@ static int get_c7_log_page(struct nvme_transport_handle *hdl, char *format) data = (__u8 *)malloc(sizeof(__u8) * C7_TCG_CONFIGURATION_LEN); if (!data) { - fprintf(stderr, "ERROR : OCP : malloc : %s\n", nvme_strerror(errno)); + fprintf(stderr, "ERROR : OCP : malloc : %s\n", libnvme_strerror(errno)); return -1; } memset(data, 0, sizeof(__u8) * C7_TCG_CONFIGURATION_LEN); @@ -2566,8 +2566,8 @@ static int ocp_tcg_configuration_log(int argc, char **argv, struct command *acmd struct plugin *plugin) { const char *desc = "Retrieve TCG Configuration Log Page Data"; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; int ret = 0; struct config { @@ -2627,7 +2627,7 @@ static int fw_activation_history_log(int argc, char **argv, struct command *acmd return ocp_fw_activation_history_log(argc, argv, acmd, plugin); } -static int error_injection_get(struct nvme_transport_handle *hdl, const __u8 sel, bool uuid, __u32 nsid) +static int error_injection_get(struct libnvme_transport_handle *hdl, const __u8 sel, bool uuid, __u32 nsid) { _cleanup_free_ struct erri_entry *entry = NULL; struct erri_get_cq_entry cq_entry; @@ -2651,7 +2651,7 @@ static int error_injection_get(struct nvme_transport_handle *hdl, const __u8 sel entry = nvme_alloc(data_len); if (!entry) { - nvme_show_error("malloc: %s", nvme_strerror(errno)); + nvme_show_error("malloc: %s", libnvme_strerror(errno)); return -ENOMEM; } @@ -2680,8 +2680,8 @@ static int error_injection_get(struct nvme_transport_handle *hdl, const __u8 sel static int get_error_injection(int argc, char **argv, struct command *acmd, struct plugin *plugin) { const char *desc = "Return set of error injection"; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; int err; struct config { __u8 sel; @@ -2710,7 +2710,7 @@ static int get_error_injection(int argc, char **argv, struct command *acmd, stru return error_injection_get(hdl, cfg.sel, !argconfig_parse_seen(opts, "no-uuid"), nsid); } -static int error_injection_set(struct nvme_transport_handle *hdl, struct erri_config *cfg, bool uuid, __u32 nsid) +static int error_injection_set(struct libnvme_transport_handle *hdl, struct erri_config *cfg, bool uuid, __u32 nsid) { _cleanup_free_ struct erri_entry *entry = NULL; _cleanup_fd_ int ffd = -1; @@ -2730,20 +2730,20 @@ static int error_injection_set(struct nvme_transport_handle *hdl, struct erri_co data_len = cfg->number * sizeof(struct erri_entry); entry = nvme_alloc(data_len); if (!entry) { - nvme_show_error("malloc: %s", nvme_strerror(errno)); + nvme_show_error("malloc: %s", libnvme_strerror(errno)); return -ENOMEM; } if (cfg->file && strlen(cfg->file)) { ffd = open(cfg->file, O_RDONLY); if (ffd < 0) { - nvme_show_error("Failed to open file %s: %s", cfg->file, nvme_strerror(errno)); + nvme_show_error("Failed to open file %s: %s", cfg->file, libnvme_strerror(errno)); return -EINVAL; } err = read(ffd, entry, data_len); if (err < 0) { nvme_show_error("failed to read data buffer from input file: %s", - nvme_strerror(errno)); + libnvme_strerror(errno)); return -errno; } } else { @@ -2757,7 +2757,7 @@ static int error_injection_set(struct nvme_transport_handle *hdl, struct erri_co 0, 0, 0, 0, entry, data_len, NULL); if (err) { if (err < 0) - nvme_show_error("set-error-injection: %s", nvme_strerror(errno)); + nvme_show_error("set-error-injection: %s", libnvme_strerror(errno)); else if (err > 0) nvme_show_status(err); return err; @@ -2774,8 +2774,8 @@ static int error_injection_set(struct nvme_transport_handle *hdl, struct erri_co static int set_error_injection(int argc, char **argv, struct command *acmd, struct plugin *plugin) { const char *desc = "Inject error conditions"; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; __u32 nsid; int err; @@ -2805,7 +2805,7 @@ static int set_error_injection(int argc, char **argv, struct command *acmd, stru return error_injection_set(hdl, &cfg, !argconfig_parse_seen(opts, "no-uuid"), nsid); } -static int enable_ieee1667_silo_get(struct nvme_transport_handle *hdl, const __u8 sel, bool uuid) +static int enable_ieee1667_silo_get(struct libnvme_transport_handle *hdl, const __u8 sel, bool uuid) { struct ieee1667_get_cq_entry cq_entry = { 0 }; const __u8 fid = OCP_FID_1667; @@ -2848,8 +2848,8 @@ static int get_enable_ieee1667_silo(int argc, char **argv, struct command *acmd, }; struct config cfg = { 0 }; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; NVME_ARGS(opts, OPT_BYTE("sel", 's', &cfg.sel, sel), @@ -2862,7 +2862,7 @@ static int get_enable_ieee1667_silo(int argc, char **argv, struct command *acmd, return enable_ieee1667_silo_get(hdl, cfg.sel, !argconfig_parse_seen(opts, "no-uuid")); } -static int enable_ieee1667_silo_set(struct nvme_transport_handle *hdl, +static int enable_ieee1667_silo_set(struct libnvme_transport_handle *hdl, struct argconfig_commandline_options *opts) { bool enable = argconfig_parse_seen(opts, "enable"); @@ -2906,8 +2906,8 @@ static int set_enable_ieee1667_silo(int argc, char **argv, struct command *acmd, { int err; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; NVME_ARGS(opts, OPT_FLAG("enable", 'e', NULL, no_uuid), @@ -2938,8 +2938,8 @@ static int ocp_get_persistent_event_log(int argc, char **argv, _cleanup_free_ struct nvme_persistent_event_log *pevent = NULL; struct nvme_persistent_event_log *pevent_collected = NULL; _cleanup_huge_ struct nvme_mem_huge mh = { 0, }; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; nvme_print_flags_t flags; void *pevent_log_info; @@ -2982,7 +2982,7 @@ static int ocp_get_persistent_event_log(int argc, char **argv, err = nvme_get_log_persistent_event(hdl, cfg.action, pevent, sizeof(*pevent)); if (err < 0) { - nvme_show_error("persistent event log: %s", nvme_strerror(err)); + nvme_show_error("persistent event log: %s", libnvme_strerror(err)); return err; } else if (err) { nvme_show_status(err); @@ -3024,7 +3024,7 @@ static int ocp_get_persistent_event_log(int argc, char **argv, pevent, sizeof(*pevent)); if (err < 0) { - nvme_show_error("persistent event log: %s", nvme_strerror(err)); + nvme_show_error("persistent event log: %s", libnvme_strerror(err)); return err; } else if (err) { nvme_show_status(err); @@ -3038,11 +3038,11 @@ static int ocp_get_persistent_event_log(int argc, char **argv, } ocp_show_persistent_event_log(pevent_log_info, cfg.action, - cfg.log_len, nvme_transport_handle_get_name(hdl), flags); + cfg.log_len, libnvme_transport_handle_get_name(hdl), flags); } else if (err > 0) { nvme_show_status(err); } else { - nvme_show_error("persistent event log: %s", nvme_strerror(err)); + nvme_show_error("persistent event log: %s", libnvme_strerror(err)); } return err; @@ -3061,8 +3061,8 @@ static int ocp_get_idle_wakeup_time_config_feature(int argc, char **argv, const char *sel = "[0-3]: current/default/saved/supported/"; const char *nsid = "Byte[04-07]: NSID Valid/Invalid/Inactive"; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; __u64 result; diff --git a/plugins/ocp/ocp-print-binary.c b/plugins/ocp/ocp-print-binary.c index d98a062dde..c80654cb36 100644 --- a/plugins/ocp/ocp-print-binary.c +++ b/plugins/ocp/ocp-print-binary.c @@ -21,7 +21,7 @@ static void binary_persistent_event_log(void *pevent_log_info, d_raw((unsigned char *)pevent_log_info, size); } -static void binary_c5_log(struct nvme_transport_handle *hdl, struct unsupported_requirement_log *log_data) +static void binary_c5_log(struct libnvme_transport_handle *hdl, struct unsupported_requirement_log *log_data) { d_raw((unsigned char *)log_data, sizeof(*log_data)); } @@ -42,7 +42,7 @@ static void binary_c9_log(struct telemetry_str_log_format *log_data, __u8 *log_d d_raw((unsigned char *)log_data_buf, total_log_page_size); } -static void binary_c7_log(struct nvme_transport_handle *hdl, struct tcg_configuration_log *log_data) +static void binary_c7_log(struct libnvme_transport_handle *hdl, struct tcg_configuration_log *log_data) { d_raw((unsigned char *)log_data, sizeof(*log_data)); } diff --git a/plugins/ocp/ocp-print-json.c b/plugins/ocp/ocp-print-json.c index c5eb9125fa..b756916c07 100644 --- a/plugins/ocp/ocp-print-json.c +++ b/plugins/ocp/ocp-print-json.c @@ -556,7 +556,7 @@ static void json_telemetry_log(struct ocp_telemetry_parse_options *options) print_ocp_telemetry_json(options); } -static void json_c3_log(struct nvme_transport_handle *hdl, struct ssd_latency_monitor_log *log_data) +static void json_c3_log(struct libnvme_transport_handle *hdl, struct ssd_latency_monitor_log *log_data) { struct json_object *root; char ts_buf[128]; @@ -727,7 +727,7 @@ static void json_c3_log(struct nvme_transport_handle *hdl, struct ssd_latency_mo json_free_object(root); } -static void json_c5_log(struct nvme_transport_handle *hdl, struct unsupported_requirement_log *log_data) +static void json_c5_log(struct libnvme_transport_handle *hdl, struct unsupported_requirement_log *log_data) { int j; struct json_object *root; @@ -1111,7 +1111,7 @@ static void json_c9_log(struct telemetry_str_log_format *log_data, __u8 *log_dat json_free_object(root); } -static void json_c7_log(struct nvme_transport_handle *hdl, struct tcg_configuration_log *log_data) +static void json_c7_log(struct libnvme_transport_handle *hdl, struct tcg_configuration_log *log_data) { int j; struct json_object *root; diff --git a/plugins/ocp/ocp-print-stdout.c b/plugins/ocp/ocp-print-stdout.c index 8110f17670..dc3d0c6298 100644 --- a/plugins/ocp/ocp-print-stdout.c +++ b/plugins/ocp/ocp-print-stdout.c @@ -259,7 +259,7 @@ static void stdout_telemetry_log(struct ocp_telemetry_parse_options *options) #endif /* CONFIG_JSONC */ } -static void stdout_c3_log(struct nvme_transport_handle *hdl, struct ssd_latency_monitor_log *log_data) +static void stdout_c3_log(struct libnvme_transport_handle *hdl, struct ssd_latency_monitor_log *log_data) { char ts_buf[128]; int i, j; @@ -267,7 +267,7 @@ static void stdout_c3_log(struct nvme_transport_handle *hdl, struct ssd_latency_ printf("-Latency Monitor/C3 Log Page Data-\n"); printf(" Controller : %s\n", - nvme_transport_handle_get_name(hdl)); + libnvme_transport_handle_get_name(hdl)); printf(" Feature Status 0x%x\n", log_data->feature_status); printf(" Active Bucket Timer %d min\n", @@ -398,7 +398,7 @@ static void stdout_c3_log(struct nvme_transport_handle *hdl, struct ssd_latency_ } } -static void stdout_c5_log(struct nvme_transport_handle *hdl, struct unsupported_requirement_log *log_data) +static void stdout_c5_log(struct libnvme_transport_handle *hdl, struct unsupported_requirement_log *log_data) { int j; @@ -699,7 +699,7 @@ static void stdout_c9_log(struct telemetry_str_log_format *log_data, __u8 *log_d } } -static void stdout_c7_log(struct nvme_transport_handle *hdl, struct tcg_configuration_log *log_data) +static void stdout_c7_log(struct libnvme_transport_handle *hdl, struct tcg_configuration_log *log_data) { int j; __u16 log_page_version = le16_to_cpu(log_data->log_page_version); diff --git a/plugins/ocp/ocp-print.c b/plugins/ocp/ocp-print.c index 0dc5ba59d0..a9193edf28 100644 --- a/plugins/ocp/ocp-print.c +++ b/plugins/ocp/ocp-print.c @@ -55,14 +55,14 @@ void ocp_show_telemetry_log(struct ocp_telemetry_parse_options *options, nvme_pr ocp_print(telemetry_log, flags, options); } -void ocp_c3_log(struct nvme_transport_handle *hdl, +void ocp_c3_log(struct libnvme_transport_handle *hdl, struct ssd_latency_monitor_log *log_data, nvme_print_flags_t flags) { ocp_print(c3_log, flags, hdl, log_data); } -void ocp_c5_log(struct nvme_transport_handle *hdl, +void ocp_c5_log(struct libnvme_transport_handle *hdl, struct unsupported_requirement_log *log_data, nvme_print_flags_t flags) { @@ -85,7 +85,7 @@ void ocp_c9_log(struct telemetry_str_log_format *log_data, __u8 *log_data_buf, ocp_print(c9_log, flags, log_data, log_data_buf, total_log_page_size); } -void ocp_c7_log(struct nvme_transport_handle *hdl, +void ocp_c7_log(struct libnvme_transport_handle *hdl, struct tcg_configuration_log *log_data, nvme_print_flags_t flags) { diff --git a/plugins/ocp/ocp-print.h b/plugins/ocp/ocp-print.h index a1a72aa34f..377dfd4aad 100644 --- a/plugins/ocp/ocp-print.h +++ b/plugins/ocp/ocp-print.h @@ -14,13 +14,13 @@ struct ocp_print_ops { void (*persistent_event_log)(void *pevent_log_info, __u8 action, __u32 size, const char *devname); void (*smart_extended_log)(struct ocp_smart_extended_log *log, unsigned int version); void (*telemetry_log)(struct ocp_telemetry_parse_options *options); - void (*c3_log)(struct nvme_transport_handle *hdl, struct ssd_latency_monitor_log *log_data); - void (*c5_log)(struct nvme_transport_handle *hdl, struct unsupported_requirement_log *log_data); + void (*c3_log)(struct libnvme_transport_handle *hdl, struct ssd_latency_monitor_log *log_data); + void (*c5_log)(struct libnvme_transport_handle *hdl, struct unsupported_requirement_log *log_data); void (*c1_log)(struct ocp_error_recovery_log_page *log_data); void (*c4_log)(struct ocp_device_capabilities_log_page *log_data); void (*c9_log)(struct telemetry_str_log_format *log_data, __u8 *log_data_buf, int total_log_page_size); - void (*c7_log)(struct nvme_transport_handle *hdl, struct tcg_configuration_log *log_data); + void (*c7_log)(struct libnvme_transport_handle *hdl, struct tcg_configuration_log *log_data); nvme_print_flags_t flags; }; @@ -44,14 +44,14 @@ void ocp_show_persistent_event_log(void *pevent_log_info, void ocp_smart_extended_log(struct ocp_smart_extended_log *log, unsigned int version, nvme_print_flags_t flags); void ocp_show_telemetry_log(struct ocp_telemetry_parse_options *options, nvme_print_flags_t flags); -void ocp_c3_log(struct nvme_transport_handle *hdl, struct ssd_latency_monitor_log *log_data, +void ocp_c3_log(struct libnvme_transport_handle *hdl, struct ssd_latency_monitor_log *log_data, nvme_print_flags_t flags); -void ocp_c5_log(struct nvme_transport_handle *hdl, struct unsupported_requirement_log *log_data, +void ocp_c5_log(struct libnvme_transport_handle *hdl, struct unsupported_requirement_log *log_data, nvme_print_flags_t flags); void ocp_c1_log(struct ocp_error_recovery_log_page *log_data, nvme_print_flags_t flags); void ocp_c4_log(struct ocp_device_capabilities_log_page *log_data, nvme_print_flags_t flags); void ocp_c9_log(struct telemetry_str_log_format *log_data, __u8 *log_data_buf, int total_log_page_size, nvme_print_flags_t flags); -void ocp_c7_log(struct nvme_transport_handle *hdl, struct tcg_configuration_log *log_data, +void ocp_c7_log(struct libnvme_transport_handle *hdl, struct tcg_configuration_log *log_data, nvme_print_flags_t flags); #endif /* OCP_PRINT_H */ diff --git a/plugins/ocp/ocp-smart-extended-log.c b/plugins/ocp/ocp-smart-extended-log.c index 0c9c28cac3..fefe7bbb15 100644 --- a/plugins/ocp/ocp-smart-extended-log.c +++ b/plugins/ocp/ocp-smart-extended-log.c @@ -26,11 +26,11 @@ static __u8 scao_guid[GUID_LEN] = { 0xC9, 0x14, 0xD5, 0xAF }; -static int get_c0_log_page(struct nvme_transport_handle *hdl, char *format, +static int get_c0_log_page(struct libnvme_transport_handle *hdl, char *format, unsigned int format_version) { struct ocp_smart_extended_log *data; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; nvme_print_flags_t fmt; __u8 uidx; int ret; @@ -44,7 +44,7 @@ static int get_c0_log_page(struct nvme_transport_handle *hdl, char *format, data = malloc(sizeof(__u8) * C0_SMART_CLOUD_ATTR_LEN); if (!data) { - fprintf(stderr, "ERROR : OCP : malloc : %s\n", nvme_strerror(errno)); + fprintf(stderr, "ERROR : OCP : malloc : %s\n", libnvme_strerror(errno)); return -1; } memset(data, 0, sizeof(__u8) * C0_SMART_CLOUD_ATTR_LEN); @@ -56,11 +56,11 @@ static int get_c0_log_page(struct nvme_transport_handle *hdl, char *format, cmd.cdw14 |= NVME_FIELD_ENCODE(uidx, NVME_LOG_CDW14_UUID_SHIFT, NVME_LOG_CDW14_UUID_MASK); - ret = nvme_get_log(hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); + ret = libnvme_get_log(hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); if (strcmp(format, "json")) fprintf(stderr, "NVMe Status:%s(%x)\n", - nvme_status_to_string(ret, false), ret); + libnvme_status_to_string(ret, false), ret); if (ret == 0) { /* check log page guid */ @@ -99,8 +99,8 @@ int ocp_smart_add_log(int argc, char **argv, struct command *acmd, struct plugin *plugin) { const char *desc = "Retrieve the extended SMART health data."; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; int ret = 0; NVME_ARGS(opts); diff --git a/plugins/ocp/ocp-utils.c b/plugins/ocp/ocp-utils.c index 966a3e9b62..bc7460fc9d 100644 --- a/plugins/ocp/ocp-utils.c +++ b/plugins/ocp/ocp-utils.c @@ -20,7 +20,7 @@ const unsigned char ocp_uuid[NVME_UUID_LEN] = { int ocp_find_uuid_index(struct nvme_id_uuid_list *uuid_list, __u8 *index) { - int i = nvme_find_uuid(uuid_list, ocp_uuid); + int i = libnvme_find_uuid(uuid_list, ocp_uuid); *index = 0; if (i > 0) @@ -31,7 +31,7 @@ int ocp_find_uuid_index(struct nvme_id_uuid_list *uuid_list, __u8 *index) return 0; } -int ocp_get_uuid_index(struct nvme_transport_handle *hdl, __u8 *index) +int ocp_get_uuid_index(struct libnvme_transport_handle *hdl, __u8 *index) { struct nvme_id_uuid_list uuid_list; int err; @@ -45,10 +45,10 @@ int ocp_get_uuid_index(struct nvme_transport_handle *hdl, __u8 *index) return ocp_find_uuid_index(&uuid_list, index); } -int ocp_get_log_simple(struct nvme_transport_handle *hdl, +int ocp_get_log_simple(struct libnvme_transport_handle *hdl, enum ocp_dssd_log_id lid, __u32 len, void *log) { - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; __u8 uidx; ocp_get_uuid_index(hdl, &uidx); @@ -58,7 +58,7 @@ int ocp_get_log_simple(struct nvme_transport_handle *hdl, NVME_LOG_CDW14_UUID_SHIFT, NVME_LOG_CDW14_UUID_MASK); - return nvme_get_log(hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); + return libnvme_get_log(hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); } bool ocp_is_tcg_activity_event(struct nvme_persistent_event_entry *pevent_entry_head, diff --git a/plugins/ocp/ocp-utils.h b/plugins/ocp/ocp-utils.h index 422ec64b85..00dde6ba09 100644 --- a/plugins/ocp/ocp-utils.h +++ b/plugins/ocp/ocp-utils.h @@ -19,7 +19,7 @@ extern const unsigned char ocp_uuid[NVME_UUID_LEN]; * Return: Zero if nvme device has UUID list identify page, or positive result of get uuid list * or negative POSIX error code otherwise. */ -int ocp_get_uuid_index(struct nvme_transport_handle *hdl, __u8 *index); +int ocp_get_uuid_index(struct libnvme_transport_handle *hdl, __u8 *index); /** * ocp_find_uuid_index() - Find OCP UUID index in UUID list @@ -30,7 +30,7 @@ int ocp_get_uuid_index(struct nvme_transport_handle *hdl, __u8 *index); */ int ocp_find_uuid_index(struct nvme_id_uuid_list *uuid_list, __u8 *index); -int ocp_get_log_simple(struct nvme_transport_handle *hdl, enum ocp_dssd_log_id lid, __u32 len, void *log); +int ocp_get_log_simple(struct libnvme_transport_handle *hdl, enum ocp_dssd_log_id lid, __u32 len, void *log); /** * ocp_is_tcg_activity_event() - Determine if persistent event is TCG activity event diff --git a/plugins/sandisk/sandisk-nvme.c b/plugins/sandisk/sandisk-nvme.c index 2e1b5e96ae..2361399872 100644 --- a/plugins/sandisk/sandisk-nvme.c +++ b/plugins/sandisk/sandisk-nvme.c @@ -34,8 +34,8 @@ static __u8 ocp_C2_guid[SNDK_GUID_LENGTH] = { 0xE2, 0x4D, 0xB2, 0x8A, 0xAC, 0xF3, 0x1C, 0xD1 }; -static int sndk_do_cap_telemetry_log(struct nvme_global_ctx *ctx, - struct nvme_transport_handle *hdl, +static int sndk_do_cap_telemetry_log(struct libnvme_global_ctx *ctx, + struct libnvme_transport_handle *hdl, const char *file, __u32 bs, int type, int data_area) { @@ -62,7 +62,7 @@ static int sndk_do_cap_telemetry_log(struct nvme_global_ctx *ctx, return -EINVAL; } - err = nvme_scan_topology(ctx, NULL, NULL); + err = libnvme_scan_topology(ctx, NULL, NULL); if (err) return err; capabilities = sndk_get_drive_capabilities(ctx, hdl); @@ -74,7 +74,7 @@ static int sndk_do_cap_telemetry_log(struct nvme_global_ctx *ctx, return -EINVAL; } - err = nvme_set_etdas(hdl, &host_behavior_changed); + err = libnvme_set_etdas(hdl, &host_behavior_changed); if (err) { fprintf(stderr, "%s: Failed to set ETDAS bit\n", __func__); return err; @@ -110,18 +110,18 @@ static int sndk_do_cap_telemetry_log(struct nvme_global_ctx *ctx, output = open(file, O_WRONLY | O_CREAT | O_TRUNC, 0666); if (output < 0) { fprintf(stderr, "%s: Failed to open output file %s: %s!\n", - __func__, file, nvme_strerror(errno)); + __func__, file, libnvme_strerror(errno)); return output; } if (ctrl_init) - err = nvme_get_ctrl_telemetry(hdl, true, &log, + err = libnvme_get_ctrl_telemetry(hdl, true, &log, data_area, &full_size); else if (host_gen) - err = nvme_get_new_host_telemetry(hdl, &log, + err = libnvme_get_new_host_telemetry(hdl, &log, data_area, &full_size); else - err = nvme_get_host_telemetry(hdl, &log, data_area, + err = libnvme_get_host_telemetry(hdl, &log, data_area, &full_size); if (err < 0) { @@ -160,13 +160,13 @@ static int sndk_do_cap_telemetry_log(struct nvme_global_ctx *ctx, } if (fsync(output) < 0) { - fprintf(stderr, "ERROR: %s: fsync: %s\n", __func__, nvme_strerror(errno)); + fprintf(stderr, "ERROR: %s: fsync: %s\n", __func__, libnvme_strerror(errno)); err = -1; } if (host_behavior_changed) { host_behavior_changed = false; - err = nvme_clear_etdas(hdl, &host_behavior_changed); + err = libnvme_clear_etdas(hdl, &host_behavior_changed); if (err) { fprintf(stderr, "%s: Failed to clear ETDAS bit\n", __func__); return err; @@ -179,8 +179,8 @@ static int sndk_do_cap_telemetry_log(struct nvme_global_ctx *ctx, return err; } -static int sndk_do_cap_both_telemetry_log(struct nvme_global_ctx *ctx, - struct nvme_transport_handle *hdl, +static int sndk_do_cap_both_telemetry_log(struct libnvme_global_ctx *ctx, + struct libnvme_transport_handle *hdl, const char *tar_file, __u32 bs, int data_area) { @@ -254,20 +254,20 @@ static int sndk_do_cap_both_telemetry_log(struct nvme_global_ctx *ctx, return ret; } -static __u32 sndk_dump_udui_data(struct nvme_transport_handle *hdl, +static __u32 sndk_dump_udui_data(struct libnvme_transport_handle *hdl, __u32 dataLen, __u32 offset, __u8 *dump_data) { int ret; - struct nvme_passthru_cmd admin_cmd; + struct libnvme_passthru_cmd admin_cmd; - memset(&admin_cmd, 0, sizeof(struct nvme_passthru_cmd)); + memset(&admin_cmd, 0, sizeof(struct libnvme_passthru_cmd)); admin_cmd.opcode = SNDK_NVME_CAP_UDUI_OPCODE; admin_cmd.nsid = 0xFFFFFFFF; admin_cmd.addr = (__u64)(uintptr_t)dump_data; admin_cmd.data_len = dataLen; admin_cmd.cdw10 = ((dataLen >> 2) - 1); admin_cmd.cdw12 = offset; - ret = nvme_submit_admin_passthru(hdl, &admin_cmd); + ret = libnvme_submit_admin_passthru(hdl, &admin_cmd); if (ret) { fprintf(stderr, "ERROR: SNDK: reading DUI data failed\n"); nvme_show_status(ret); @@ -276,7 +276,7 @@ static __u32 sndk_dump_udui_data(struct nvme_transport_handle *hdl, return ret; } -static int sndk_do_cap_udui(struct nvme_transport_handle *hdl, char *file, +static int sndk_do_cap_udui(struct libnvme_transport_handle *hdl, char *file, __u32 xfer_size, int verbose) { int ret = 0; @@ -292,7 +292,7 @@ static int sndk_do_cap_udui(struct nvme_transport_handle *hdl, char *file, if (!log) { fprintf(stderr, "%s: ERROR: log header malloc failed : status %s, size 0x%x\n", - __func__, nvme_strerror(errno), udui_log_hdr_size); + __func__, libnvme_strerror(errno), udui_log_hdr_size); return -1; } memset(log, 0, udui_log_hdr_size); @@ -312,7 +312,7 @@ static int sndk_do_cap_udui(struct nvme_transport_handle *hdl, char *file, output = open(file, O_WRONLY | O_CREAT | O_TRUNC, 0666); if (output < 0) { fprintf(stderr, "%s: Failed to open output file %s: %s!\n", __func__, file, - nvme_strerror(errno)); + libnvme_strerror(errno)); goto out; } @@ -354,7 +354,7 @@ static int sndk_do_cap_udui(struct nvme_transport_handle *hdl, char *file, return ret; } -static int sndk_get_default_telemetry_da(struct nvme_transport_handle *hdl, +static int sndk_get_default_telemetry_da(struct libnvme_transport_handle *hdl, int *data_area) { struct nvme_id_ctrl ctrl; @@ -404,8 +404,8 @@ static int sndk_vs_internal_fw_log(int argc, char **argv, __u64 capabilities = 0; __u32 device_id, read_vendor_id; int ret = -1; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; struct config { char *file; @@ -441,7 +441,7 @@ static int sndk_vs_internal_fw_log(int argc, char **argv, if (ret) return ret; - ret = nvme_scan_topology(ctx, NULL, NULL); + ret = libnvme_scan_topology(ctx, NULL, NULL); if (ret || !sndk_check_device(ctx, hdl)) goto out; @@ -460,7 +460,7 @@ static int sndk_vs_internal_fw_log(int argc, char **argv, /* verify file name and path is valid before getting dump data */ verify_file = open(cfg.file, O_WRONLY | O_CREAT | O_TRUNC, 0666); if (verify_file < 0) { - fprintf(stderr, "ERROR: SNDK: open: %s\n", nvme_strerror(errno)); + fprintf(stderr, "ERROR: SNDK: open: %s\n", libnvme_strerror(errno)); goto out; } close(verify_file); @@ -613,15 +613,15 @@ static int sndk_clear_assert_dump(int argc, char **argv, #define SNDK_NVME_SN861_DRIVE_RESIZE_OPCODE 0xD1 #define SNDK_NVME_SN861_DRIVE_RESIZE_BUFFER_SIZE 0x1000 -static int sndk_do_sn861_drive_resize(struct nvme_transport_handle *hdl, +static int sndk_do_sn861_drive_resize(struct libnvme_transport_handle *hdl, uint64_t new_size, __u64 *result) { uint8_t buffer[SNDK_NVME_SN861_DRIVE_RESIZE_BUFFER_SIZE] = {0}; - struct nvme_passthru_cmd admin_cmd; + struct libnvme_passthru_cmd admin_cmd; int ret; - memset(&admin_cmd, 0, sizeof(struct nvme_passthru_cmd)); + memset(&admin_cmd, 0, sizeof(struct libnvme_passthru_cmd)); admin_cmd.opcode = SNDK_NVME_SN861_DRIVE_RESIZE_OPCODE; admin_cmd.cdw10 = 0x00000040; admin_cmd.cdw12 = 0x00000103; @@ -631,7 +631,7 @@ static int sndk_do_sn861_drive_resize(struct nvme_transport_handle *hdl, admin_cmd.addr = (__u64)(uintptr_t)buffer; admin_cmd.data_len = SNDK_NVME_SN861_DRIVE_RESIZE_BUFFER_SIZE; - ret = nvme_submit_admin_passthru(hdl, &admin_cmd); + ret = libnvme_submit_admin_passthru(hdl, &admin_cmd); if (result) *result = admin_cmd.result; return ret; @@ -643,8 +643,8 @@ static int sndk_drive_resize(int argc, char **argv, { const char *desc = "Send a Resize command."; const char *size = "The new size (in GB) to resize the drive to."; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; uint64_t capabilities = 0; int ret; uint32_t device_id = -1, vendor_id = -1; @@ -665,7 +665,7 @@ static int sndk_drive_resize(int argc, char **argv, if (ret) return ret; - ret = nvme_scan_topology(ctx, NULL, NULL); + ret = libnvme_scan_topology(ctx, NULL, NULL); if (ret) return ret; sndk_check_device(ctx, hdl); @@ -920,7 +920,7 @@ static int sndk_print_fw_act_history_log(__u8 *data, int num_entries, int fmt) return 0; } -static int sndk_get_fw_act_history_C2(struct nvme_global_ctx *ctx, struct nvme_transport_handle *hdl, +static int sndk_get_fw_act_history_C2(struct libnvme_global_ctx *ctx, struct libnvme_transport_handle *hdl, char *format) { struct sndk_fw_act_history_log_format_c2 *fw_act_history_log; @@ -941,7 +941,7 @@ static int sndk_get_fw_act_history_C2(struct nvme_global_ctx *ctx, struct nvme_t data = (__u8 *)malloc(sizeof(__u8) * SNDK_FW_ACT_HISTORY_C2_LOG_BUF_LEN); if (!data) { - fprintf(stderr, "ERROR: SNDK: malloc: %s\n", nvme_strerror(errno)); + fprintf(stderr, "ERROR: SNDK: malloc: %s\n", libnvme_strerror(errno)); return -1; } @@ -994,8 +994,8 @@ static int sndk_vs_fw_activate_history(int argc, char **argv, struct plugin *plugin) { const char *desc = "Retrieve FW activate history table."; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; uint64_t capabilities = 0; int ret; @@ -1013,7 +1013,7 @@ static int sndk_vs_fw_activate_history(int argc, char **argv, if (ret) return ret; - ret = nvme_scan_topology(ctx, NULL, NULL); + ret = libnvme_scan_topology(ctx, NULL, NULL); if (ret) return ret; capabilities = sndk_get_drive_capabilities(ctx, hdl); @@ -1032,7 +1032,7 @@ static int sndk_vs_fw_activate_history(int argc, char **argv, return ret; } -static int sndk_do_clear_fw_activate_history_fid(struct nvme_transport_handle *hdl) +static int sndk_do_clear_fw_activate_history_fid(struct libnvme_transport_handle *hdl) { int ret = -1; __u64 result; @@ -1050,8 +1050,8 @@ static int sndk_clear_fw_activate_history(int argc, char **argv, struct plugin *plugin) { const char *desc = "Clear FW activate history table."; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; __u64 capabilities = 0; int ret; @@ -1061,7 +1061,7 @@ static int sndk_clear_fw_activate_history(int argc, char **argv, if (ret) return ret; - ret = nvme_scan_topology(ctx, NULL, NULL); + ret = libnvme_scan_topology(ctx, NULL, NULL); if (ret) return ret; capabilities = sndk_get_drive_capabilities(ctx, hdl); @@ -1120,8 +1120,8 @@ static int sndk_capabilities(int argc, char **argv, struct plugin *plugin) { const char *desc = "Send a capabilities command."; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; uint64_t capabilities = 0; int ret; @@ -1132,14 +1132,14 @@ static int sndk_capabilities(int argc, char **argv, return ret; /* get capabilities */ - ret = nvme_scan_topology(ctx, NULL, NULL); + ret = libnvme_scan_topology(ctx, NULL, NULL); if (ret || !sndk_check_device(ctx, hdl)) return -1; capabilities = sndk_get_drive_capabilities(ctx, hdl); /* print command and supported status */ - printf("Sandisk Plugin Capabilities for NVME device:%s\n", nvme_transport_handle_get_name(hdl)); + printf("Sandisk Plugin Capabilities for NVME device:%s\n", libnvme_transport_handle_get_name(hdl)); printf("vs-internal-log : %s\n", capabilities & SNDK_DRIVE_CAP_INTERNAL_LOG_MASK ? "Supported" : "Not Supported"); printf("vs-nand-stats : %s\n", diff --git a/plugins/sandisk/sandisk-utils.c b/plugins/sandisk/sandisk-utils.c index 8b41ade6ca..4e7c72a0b7 100644 --- a/plugins/sandisk/sandisk-utils.c +++ b/plugins/sandisk/sandisk-utils.c @@ -40,35 +40,35 @@ static const __u8 SNDK_UUID[NVME_UUID_LEN] = { 0xad, 0xd8, 0x3c, 0x29, 0xd1, 0x23, 0x7c, 0x70 }; -int sndk_get_pci_ids(struct nvme_global_ctx *ctx, struct nvme_transport_handle *hdl, +int sndk_get_pci_ids(struct libnvme_global_ctx *ctx, struct libnvme_transport_handle *hdl, uint32_t *device_id, uint32_t *vendor_id) { char vid[256], did[256], id[32]; - nvme_ctrl_t c = NULL; - nvme_ns_t n = NULL; + libnvme_ctrl_t c = NULL; + libnvme_ns_t n = NULL; const char *name; int fd, ret; - name = nvme_transport_handle_get_name(hdl); - ret = nvme_scan_ctrl(ctx, name, &c); + name = libnvme_transport_handle_get_name(hdl); + ret = libnvme_scan_ctrl(ctx, name, &c); if (!ret) { snprintf(vid, sizeof(vid), "%s/device/vendor", - nvme_ctrl_get_sysfs_dir(c)); + libnvme_ctrl_get_sysfs_dir(c)); snprintf(did, sizeof(did), "%s/device/device", - nvme_ctrl_get_sysfs_dir(c)); - nvme_free_ctrl(c); + libnvme_ctrl_get_sysfs_dir(c)); + libnvme_free_ctrl(c); } else { - ret = nvme_scan_namespace(ctx, name, &n); + ret = libnvme_scan_namespace(ctx, name, &n); if (!ret) { fprintf(stderr, "Unable to find %s\n", name); return ret; } snprintf(vid, sizeof(vid), "%s/device/device/vendor", - nvme_ns_get_sysfs_dir(n)); + libnvme_ns_get_sysfs_dir(n)); snprintf(did, sizeof(did), "%s/device/device/device", - nvme_ns_get_sysfs_dir(n)); - nvme_free_ns(n); + libnvme_ns_get_sysfs_dir(n)); + libnvme_free_ns(n); } fd = open(vid, O_RDONLY); @@ -112,7 +112,7 @@ int sndk_get_pci_ids(struct nvme_global_ctx *ctx, struct nvme_transport_handle * return 0; } -int sndk_get_vendor_id(struct nvme_transport_handle *hdl, uint32_t *vendor_id) +int sndk_get_vendor_id(struct libnvme_transport_handle *hdl, uint32_t *vendor_id) { struct nvme_id_ctrl ctrl; int ret; @@ -129,8 +129,8 @@ int sndk_get_vendor_id(struct nvme_transport_handle *hdl, uint32_t *vendor_id) return ret; } -bool sndk_check_device(struct nvme_global_ctx *ctx, - struct nvme_transport_handle *hdl) +bool sndk_check_device(struct libnvme_global_ctx *ctx, + struct libnvme_transport_handle *hdl) { uint32_t read_device_id = -1, read_vendor_id = -1; bool supported; @@ -316,7 +316,7 @@ bool sndk_nvme_parse_dev_status_log_str(void *log_data, } -bool sndk_get_dev_mgment_data(struct nvme_global_ctx *ctx, struct nvme_transport_handle *hdl, +bool sndk_get_dev_mgment_data(struct libnvme_global_ctx *ctx, struct libnvme_transport_handle *hdl, void **data) { bool found = false; @@ -335,18 +335,18 @@ bool sndk_get_dev_mgment_data(struct nvme_global_ctx *ctx, struct nvme_transport sndk_get_pci_ids(ctx, hdl, &device_id, &vendor_id); memset(&uuid_list, 0, sizeof(struct nvme_id_uuid_list)); - if (!nvme_get_uuid_list(hdl, &uuid_list)) { + if (!libnvme_get_uuid_list(hdl, &uuid_list)) { /* check for the Sandisk UUID first */ - uuid_index = nvme_find_uuid(&uuid_list, SNDK_UUID); + uuid_index = libnvme_find_uuid(&uuid_list, SNDK_UUID); if (uuid_index < 0) { /* The Sandisk UUID is not found; * check for the WDC UUID second. */ - uuid_index = nvme_find_uuid(&uuid_list, WDC_UUID); + uuid_index = libnvme_find_uuid(&uuid_list, WDC_UUID); if (uuid_index < 0) /* Check for the UUID used on SN640 and SN655 drives */ - uuid_index = nvme_find_uuid(&uuid_list, WDC_UUID_SN640_3); + uuid_index = libnvme_find_uuid(&uuid_list, WDC_UUID_SN640_3); } if (uuid_index >= 0) @@ -439,12 +439,12 @@ bool sndk_validate_dev_mng_log(void *data) return valid_log; } -bool sndk_get_dev_mgmt_log_page_data(struct nvme_transport_handle *hdl, +bool sndk_get_dev_mgmt_log_page_data(struct libnvme_transport_handle *hdl, void **log_data, __u8 uuid_ix) { struct sndk_c2_log_page_header *hdr_ptr; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; bool valid = false; __u32 length = 0; void *data; @@ -452,7 +452,7 @@ bool sndk_get_dev_mgmt_log_page_data(struct nvme_transport_handle *hdl, data = (__u8 *)malloc(sizeof(__u8) * SNDK_DEV_MGMNT_LOG_PAGE_LEN); if (!data) { - fprintf(stderr, "ERROR: SNDK: malloc: %s\n", nvme_strerror(errno)); + fprintf(stderr, "ERROR: SNDK: malloc: %s\n", libnvme_strerror(errno)); return false; } @@ -465,7 +465,7 @@ bool sndk_get_dev_mgmt_log_page_data(struct nvme_transport_handle *hdl, cmd.cdw14 |= NVME_FIELD_ENCODE(uuid_ix, NVME_LOG_CDW14_UUID_SHIFT, NVME_LOG_CDW14_UUID_MASK); - ret = nvme_get_log(hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); + ret = libnvme_get_log(hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); if (ret) { fprintf(stderr, "ERROR: SNDK: Unable to get 0x%x Log Page with uuid %d, ret = 0x%x\n", @@ -481,7 +481,7 @@ bool sndk_get_dev_mgmt_log_page_data(struct nvme_transport_handle *hdl, free(data); data = calloc(length, sizeof(__u8)); if (!data) { - fprintf(stderr, "ERROR: SNDK: malloc: %s\n", nvme_strerror(errno)); + fprintf(stderr, "ERROR: SNDK: malloc: %s\n", libnvme_strerror(errno)); goto end; } @@ -492,7 +492,7 @@ bool sndk_get_dev_mgmt_log_page_data(struct nvme_transport_handle *hdl, cmd.cdw14 |= NVME_FIELD_ENCODE(uuid_ix, NVME_LOG_CDW14_UUID_SHIFT, NVME_LOG_CDW14_UUID_MASK); - ret = nvme_get_log(hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); + ret = libnvme_get_log(hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); if (ret) { fprintf(stderr, "ERROR: SNDK: Unable to read 0x%x Log with uuid %d, ret = 0x%x\n", @@ -506,7 +506,7 @@ bool sndk_get_dev_mgmt_log_page_data(struct nvme_transport_handle *hdl, /* Ensure size of log data matches length in log header */ *log_data = calloc(length, sizeof(__u8)); if (!*log_data) { - fprintf(stderr, "ERROR: SNDK: calloc: %s\n", nvme_strerror(errno)); + fprintf(stderr, "ERROR: SNDK: calloc: %s\n", libnvme_strerror(errno)); valid = false; goto end; } @@ -521,8 +521,8 @@ bool sndk_get_dev_mgmt_log_page_data(struct nvme_transport_handle *hdl, return valid; } -__u64 sndk_get_drive_capabilities(struct nvme_global_ctx *ctx, - struct nvme_transport_handle *hdl) +__u64 sndk_get_drive_capabilities(struct libnvme_global_ctx *ctx, + struct libnvme_transport_handle *hdl) { uint32_t read_device_id = -1, read_vendor_id = -1; __u64 capabilities = 0; @@ -654,8 +654,8 @@ __u64 sndk_get_drive_capabilities(struct nvme_global_ctx *ctx, return capabilities; } -__u64 sndk_get_enc_drive_capabilities(struct nvme_global_ctx *ctx, - struct nvme_transport_handle *hdl) +__u64 sndk_get_enc_drive_capabilities(struct libnvme_global_ctx *ctx, + struct libnvme_transport_handle *hdl) { int ret; uint32_t read_vendor_id; @@ -682,18 +682,18 @@ __u64 sndk_get_enc_drive_capabilities(struct nvme_global_ctx *ctx, /* Check for the Sandisk or WDC UUID index */ memset(&uuid_list, 0, sizeof(struct nvme_id_uuid_list)); - if (!nvme_get_uuid_list(hdl, &uuid_list)) { + if (!libnvme_get_uuid_list(hdl, &uuid_list)) { /* check for the Sandisk UUID first */ - uuid_index = nvme_find_uuid(&uuid_list, SNDK_UUID); + uuid_index = libnvme_find_uuid(&uuid_list, SNDK_UUID); if (uuid_index < 0) { /* The Sandisk UUID is not found; * check for the WDC UUID second. */ - uuid_index = nvme_find_uuid(&uuid_list, WDC_UUID); + uuid_index = libnvme_find_uuid(&uuid_list, WDC_UUID); if (uuid_index < 0) /* Check for the UUID used on SN640 and SN655 drives */ - uuid_index = nvme_find_uuid(&uuid_list, WDC_UUID_SN640_3); + uuid_index = libnvme_find_uuid(&uuid_list, WDC_UUID_SN640_3); } } else { /* UUID Lists not supported, Use default uuid index - 0 */ @@ -800,7 +800,7 @@ __u64 sndk_get_enc_drive_capabilities(struct nvme_global_ctx *ctx, return capabilities; } -int sndk_get_serial_name(struct nvme_transport_handle *hdl, char *file, +int sndk_get_serial_name(struct libnvme_transport_handle *hdl, char *file, size_t len, const char *suffix) { int i; @@ -876,7 +876,7 @@ int sndk_UtilsSnprintf(char *buffer, unsigned int sizeOfBuffer, } /* Verify the Controller Initiated Option is enabled */ -int sndk_check_ctrl_telemetry_option_disabled(struct nvme_transport_handle *hdl) +int sndk_check_ctrl_telemetry_option_disabled(struct libnvme_transport_handle *hdl) { int err; __u64 result; diff --git a/plugins/sandisk/sandisk-utils.h b/plugins/sandisk/sandisk-utils.h index 4b4703bf18..e522145e8b 100644 --- a/plugins/sandisk/sandisk-utils.h +++ b/plugins/sandisk/sandisk-utils.h @@ -295,16 +295,16 @@ struct __packed sndk_fw_act_history_log_format_c2 { __u8 log_page_guid[SNDK_GUID_LENGTH]; }; -int sndk_get_pci_ids(struct nvme_global_ctx *ctx, - struct nvme_transport_handle *hdl, +int sndk_get_pci_ids(struct libnvme_global_ctx *ctx, + struct libnvme_transport_handle *hdl, uint32_t *device_id, uint32_t *vendor_id); -int sndk_get_vendor_id(struct nvme_transport_handle *hdl, +int sndk_get_vendor_id(struct libnvme_transport_handle *hdl, uint32_t *vendor_id); -bool sndk_check_device(struct nvme_global_ctx *ctx, - struct nvme_transport_handle *hdl); +bool sndk_check_device(struct libnvme_global_ctx *ctx, + struct libnvme_transport_handle *hdl); void sndk_get_commit_action_bin(__u8 commit_action_type, char *action_bin); @@ -322,23 +322,23 @@ bool sndk_nvme_parse_dev_status_log_str(void *log_data, char *ret_data, __u32 *ret_data_len); -bool sndk_get_dev_mgment_data(struct nvme_global_ctx *ctx, - struct nvme_transport_handle *hdl, +bool sndk_get_dev_mgment_data(struct libnvme_global_ctx *ctx, + struct libnvme_transport_handle *hdl, void **data); bool sndk_validate_dev_mng_log(void *data); -bool sndk_get_dev_mgmt_log_page_data(struct nvme_transport_handle *hdl, +bool sndk_get_dev_mgmt_log_page_data(struct libnvme_transport_handle *hdl, void **log_data, __u8 uuid_ix); -__u64 sndk_get_drive_capabilities(struct nvme_global_ctx *ctx, - struct nvme_transport_handle *hdl); +__u64 sndk_get_drive_capabilities(struct libnvme_global_ctx *ctx, + struct libnvme_transport_handle *hdl); -__u64 sndk_get_enc_drive_capabilities(struct nvme_global_ctx *ctx, - struct nvme_transport_handle *hdl); +__u64 sndk_get_enc_drive_capabilities(struct libnvme_global_ctx *ctx, + struct libnvme_transport_handle *hdl); -int sndk_get_serial_name(struct nvme_transport_handle *hdl, char *file, size_t len, +int sndk_get_serial_name(struct libnvme_transport_handle *hdl, char *file, size_t len, const char *suffix); void sndk_UtilsGetTime(struct SNDK_UtilsTimeInfo *timeInfo); @@ -346,4 +346,4 @@ void sndk_UtilsGetTime(struct SNDK_UtilsTimeInfo *timeInfo); int sndk_UtilsSnprintf(char *buffer, unsigned int sizeOfBuffer, const char *format, ...); -int sndk_check_ctrl_telemetry_option_disabled(struct nvme_transport_handle *hdl); +int sndk_check_ctrl_telemetry_option_disabled(struct libnvme_transport_handle *hdl); diff --git a/plugins/scaleflux/sfx-nvme.c b/plugins/scaleflux/sfx-nvme.c index 6de7e36c79..10506ebc48 100644 --- a/plugins/scaleflux/sfx-nvme.c +++ b/plugins/scaleflux/sfx-nvme.c @@ -48,54 +48,54 @@ -int nvme_query_cap(struct nvme_transport_handle *hdl, __u32 nsid, __u32 data_len, void *data) +int nvme_query_cap(struct libnvme_transport_handle *hdl, __u32 nsid, __u32 data_len, void *data) { int rc = 0; - struct nvme_passthru_cmd cmd = { + struct libnvme_passthru_cmd cmd = { .opcode = nvme_admin_query_cap_info, .nsid = nsid, .addr = (__u64)(uintptr_t) data, .data_len = data_len, }; - rc = ioctl(nvme_transport_handle_get_fd(hdl), SFX_GET_FREESPACE, data); - return rc ? nvme_submit_admin_passthru(hdl, &cmd) : 0; + rc = ioctl(libnvme_transport_handle_get_fd(hdl), SFX_GET_FREESPACE, data); + return rc ? libnvme_submit_admin_passthru(hdl, &cmd) : 0; } -int nvme_change_cap(struct nvme_transport_handle *hdl, __u32 nsid, __u64 capacity) +int nvme_change_cap(struct libnvme_transport_handle *hdl, __u32 nsid, __u64 capacity) { - struct nvme_passthru_cmd cmd = { + struct libnvme_passthru_cmd cmd = { .opcode = nvme_admin_change_cap, .nsid = nsid, .cdw10 = (capacity & 0xffffffff), .cdw11 = (capacity >> 32), }; - return nvme_submit_admin_passthru(hdl, &cmd); + return libnvme_submit_admin_passthru(hdl, &cmd); } -int nvme_sfx_set_features(struct nvme_transport_handle *hdl, __u32 nsid, __u32 fid, __u32 value) +int nvme_sfx_set_features(struct libnvme_transport_handle *hdl, __u32 nsid, __u32 fid, __u32 value) { - struct nvme_passthru_cmd cmd = { + struct libnvme_passthru_cmd cmd = { .opcode = nvme_admin_sfx_set_features, .nsid = nsid, .cdw10 = fid, .cdw11 = value, }; - return nvme_submit_admin_passthru(hdl, &cmd); + return libnvme_submit_admin_passthru(hdl, &cmd); } -int nvme_sfx_get_features(struct nvme_transport_handle *hdl, __u32 nsid, __u32 fid, __u32 *result) +int nvme_sfx_get_features(struct libnvme_transport_handle *hdl, __u32 nsid, __u32 fid, __u32 *result) { int err = 0; - struct nvme_passthru_cmd cmd = { + struct libnvme_passthru_cmd cmd = { .opcode = nvme_admin_sfx_get_features, .nsid = nsid, .cdw10 = fid, }; - err = nvme_submit_admin_passthru(hdl, &cmd); + err = libnvme_submit_admin_passthru(hdl, &cmd); if (!err && result) *result = cmd.result; @@ -336,8 +336,8 @@ static int get_additional_smart_log(int argc, char **argv, struct command *acmd, #ifdef CONFIG_JSONC const char *json = "Dump output in json format"; #endif /* CONFIG_JSONC */ - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; nvme_print_flags_t flags; struct config { __u32 namespace_id; @@ -370,10 +370,10 @@ static int get_additional_smart_log(int argc, char **argv, struct command *acmd, if (!err) { if (flags & JSON || cfg.json) show_sfx_smart_log_jsn(&smart_log, cfg.namespace_id, - nvme_transport_handle_get_name(hdl)); + libnvme_transport_handle_get_name(hdl)); else if (!cfg.raw_binary) show_sfx_smart_log(&smart_log, cfg.namespace_id, - nvme_transport_handle_get_name(hdl)); + libnvme_transport_handle_get_name(hdl)); else d_raw((unsigned char *)&smart_log, sizeof(smart_log)); } else if (err > 0) { @@ -509,8 +509,8 @@ static int get_lat_stats_log(int argc, char **argv, struct command *acmd, struct char *desc = "Get ScaleFlux Latency Statistics log and show it."; const char *raw = "dump output in binary format"; const char *write = "Get write statistics (read default)"; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; struct config { bool raw_binary; bool write; @@ -551,9 +551,9 @@ static int get_lat_stats_log(int argc, char **argv, struct command *acmd, struct return err; } -int sfx_nvme_get_log(struct nvme_transport_handle *hdl, __u32 nsid, __u8 log_id, __u32 data_len, void *data) +int sfx_nvme_get_log(struct libnvme_transport_handle *hdl, __u32 nsid, __u8 log_id, __u32 data_len, void *data) { - struct nvme_passthru_cmd cmd = { + struct libnvme_passthru_cmd cmd = { .opcode = nvme_admin_get_log_page, .nsid = nsid, .addr = (__u64)(uintptr_t) data, @@ -565,7 +565,7 @@ int sfx_nvme_get_log(struct nvme_transport_handle *hdl, __u32 nsid, __u8 log_id, cmd.cdw10 = log_id | (numdl << 16); cmd.cdw11 = numdu; - return nvme_submit_admin_passthru(hdl, &cmd); + return libnvme_submit_admin_passthru(hdl, &cmd); } /** @@ -577,9 +577,9 @@ int sfx_nvme_get_log(struct nvme_transport_handle *hdl, __u32 nsid, __u8 log_id, * * @return -1 fail ; 0 success */ -static int get_bb_table(struct nvme_transport_handle *hdl, __u32 nsid, unsigned char *buf, __u64 size) +static int get_bb_table(struct libnvme_transport_handle *hdl, __u32 nsid, unsigned char *buf, __u64 size) { - if (nvme_transport_handle_get_fd(hdl) < 0 || !buf || size != 256*4096*sizeof(unsigned char)) { + if (libnvme_transport_handle_get_fd(hdl) < 0 || !buf || size != 256*4096*sizeof(unsigned char)) { fprintf(stderr, "Invalid Param \r\n"); return -EINVAL; } @@ -653,8 +653,8 @@ static int sfx_get_bad_block(int argc, char **argv, struct command *acmd, struct { const __u64 buf_size = 256*4096*sizeof(unsigned char); unsigned char *data_buf; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; int err = 0; char *desc = "Get bad block table of sfx block device."; @@ -705,8 +705,8 @@ static int query_cap_info(int argc, char **argv, struct command *acmd, struct pl struct sfx_freespace_ctx sfctx = { 0 }; char *desc = "query current capacity info"; const char *raw = "dump output in binary format"; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; struct config { bool raw_binary; }; @@ -734,7 +734,7 @@ static int query_cap_info(int argc, char **argv, struct command *acmd, struct pl return err; } -static int change_sanity_check(struct nvme_transport_handle *hdl, __u64 trg_in_4k, int *shrink) +static int change_sanity_check(struct libnvme_transport_handle *hdl, __u64 trg_in_4k, int *shrink) { struct sfx_freespace_ctx freespace_ctx = { 0 }; struct sysinfo s_info; @@ -822,8 +822,8 @@ static int change_cap(int argc, char **argv, struct command *acmd, struct plugin const char *cap_gb = "cap size in GB"; const char *cap_byte = "cap size in byte"; const char *force = "The \"I know what I'm doing\" flag, skip confirmation before sending command"; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; __u64 cap_in_4k = 0; __u64 cap_in_sec = 0; int shrink = 0; @@ -873,15 +873,15 @@ static int change_cap(int argc, char **argv, struct command *acmd, struct plugin nvme_show_status(err); } else { printf("ScaleFlux change-capacity: success\n"); - ioctl(nvme_transport_handle_get_fd(hdl), BLKRRPART); + ioctl(libnvme_transport_handle_get_fd(hdl), BLKRRPART); } return err; } -static int sfx_verify_chr(struct nvme_transport_handle *hdl) +static int sfx_verify_chr(struct libnvme_transport_handle *hdl) { static struct stat nvme_stat; - int err = fstat(nvme_transport_handle_get_fd(hdl), &nvme_stat); + int err = fstat(libnvme_transport_handle_get_fd(hdl), &nvme_stat); if (err < 0) { perror("fstat"); @@ -895,14 +895,14 @@ static int sfx_verify_chr(struct nvme_transport_handle *hdl) return 0; } -static int sfx_clean_card(struct nvme_transport_handle *hdl) +static int sfx_clean_card(struct libnvme_transport_handle *hdl) { int ret; ret = sfx_verify_chr(hdl); if (ret) return ret; - ret = ioctl(nvme_transport_handle_get_fd(hdl), NVME_IOCTL_CLR_CARD); + ret = ioctl(libnvme_transport_handle_get_fd(hdl), NVME_IOCTL_CLR_CARD); if (ret) perror("Ioctl Fail."); else @@ -933,8 +933,8 @@ static int sfx_set_feature(int argc, char **argv, struct command *acmd, struct p const char *feature_id = "hex feature name (required)"; const char *namespace_id = "desired namespace"; const char *force = "The \"I know what I'm doing\" flag, skip confirmation before sending command"; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; struct nvme_id_ns ns; int err = 0; @@ -1029,8 +1029,8 @@ static int sfx_get_feature(int argc, char **argv, struct command *acmd, struct p "feature id 1: ATOMIC"; const char *feature_id = "hex feature name (required)"; const char *namespace_id = "desired namespace"; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; __u32 result = 0; int err = 0; @@ -1199,7 +1199,7 @@ static int nvme_parse_evtlog(void *pevent_log_info, __u32 log_len, char *output) return err; } -static int nvme_dump_evtlog(struct nvme_transport_handle *hdl, __u32 namespace_id, __u32 storage_medium, +static int nvme_dump_evtlog(struct libnvme_transport_handle *hdl, __u32 namespace_id, __u32 storage_medium, char *file, bool parse, char *output) { _cleanup_huge_ struct nvme_mem_huge mh = { 0, }; @@ -1215,7 +1215,7 @@ static int nvme_dump_evtlog(struct nvme_transport_handle *hdl, __u32 namespace_i void *log; int err = 0; FILE *fd = NULL; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; if (!storage_medium) { lsp_base = 0; @@ -1239,7 +1239,7 @@ static int nvme_dump_evtlog(struct nvme_transport_handle *hdl, __u32 namespace_i cmd.cdw10 |= NVME_FIELD_ENCODE(lsp, NVME_LOG_CDW10_LSP_SHIFT, NVME_LOG_CDW10_LSP_MASK); - err = nvme_get_log(hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); + err = libnvme_get_log(hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); if (err) { fprintf(stderr, "Unable to get evtlog lsp=0x%x, ret = 0x%x\n", lsp, err); @@ -1252,7 +1252,7 @@ static int nvme_dump_evtlog(struct nvme_transport_handle *hdl, __u32 namespace_i cmd.cdw10 |= NVME_FIELD_ENCODE(lsp, NVME_LOG_CDW10_LSP_SHIFT, NVME_LOG_CDW10_LSP_MASK); - err = nvme_get_log(hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); + err = libnvme_get_log(hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); if (err) { fprintf(stderr, "Unable to get evtlog lsp=0x%x, ret = 0x%x\n", lsp, err); @@ -1294,7 +1294,7 @@ static int nvme_dump_evtlog(struct nvme_transport_handle *hdl, __u32 namespace_i NVME_LOG_CDW10_LSP_SHIFT, NVME_LOG_CDW10_LSP_MASK); nvme_init_get_log_lpo(&cmd, lpo); - err = nvme_get_log(hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); + err = libnvme_get_log(hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); if (err) { fprintf(stderr, "Unable to get evtlog offset=0x%x len 0x%x ret = 0x%x\n", @@ -1355,8 +1355,8 @@ static int sfx_dump_evtlog(int argc, char **argv, struct command *acmd, struct p "0: nand(default) 1: nor"; const char *parse = "parse error & warning evtlog from evtlog file"; const char *output = "parse result output file"; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; int err = 0; struct config { @@ -1400,7 +1400,7 @@ static int sfx_dump_evtlog(int argc, char **argv, struct command *acmd, struct p return 0; } -static int nvme_expand_cap(struct nvme_transport_handle *hdl, __u32 namespace_id, __u64 namespace_size, +static int nvme_expand_cap(struct libnvme_transport_handle *hdl, __u32 namespace_id, __u64 namespace_size, __u64 namespace_cap, __u32 lbaf, __u32 units) { struct dirent **devices; @@ -1417,12 +1417,12 @@ static int nvme_expand_cap(struct nvme_transport_handle *hdl, __u32 namespace_id __u8 reserve1[5]; } __packed; - if (nvme_transport_handle_is_chardev(hdl)) - snprintf(dev_name, 32, "%sn%u", nvme_transport_handle_get_name(hdl), namespace_id); + if (libnvme_transport_handle_is_chardev(hdl)) + snprintf(dev_name, 32, "%sn%u", libnvme_transport_handle_get_name(hdl), namespace_id); else - strcpy(dev_name, nvme_transport_handle_get_name(hdl)); + strcpy(dev_name, libnvme_transport_handle_get_name(hdl)); - num = scandir("/dev", &devices, nvme_filter_namespace, alphasort); + num = scandir("/dev", &devices, libnvme_filter_namespace, alphasort); if (num <= 0) { err = num; goto ret; @@ -1445,7 +1445,7 @@ static int nvme_expand_cap(struct nvme_transport_handle *hdl, __u32 namespace_id .lbaf = lbaf, }; - struct nvme_passthru_cmd cmd = { + struct libnvme_passthru_cmd cmd = { .opcode = nvme_admin_ns_mgmt, .nsid = namespace_id, .addr = (__u64)(uintptr_t)&info, @@ -1453,7 +1453,7 @@ static int nvme_expand_cap(struct nvme_transport_handle *hdl, __u32 namespace_id .cdw10 = 0x0e, }; - err = nvme_submit_admin_passthru(hdl, &cmd); + err = libnvme_submit_admin_passthru(hdl, &cmd); if (err) { fprintf(stderr, "Create ns failed\n"); nvme_show_status(err); @@ -1478,8 +1478,8 @@ static int sfx_expand_cap(int argc, char **argv, struct command *acmd, struct pl "0: 512(default) 1: 4096"; const char *units = "namespace size/capacity units\n" "0: GB(default) 1: LBA"; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; int err = 0; struct config { @@ -1507,11 +1507,11 @@ static int sfx_expand_cap(int argc, char **argv, struct command *acmd, struct pl return err; if (cfg.namespace_id == NVME_NSID_ALL) { - if (nvme_transport_handle_is_chardev(hdl)) { + if (libnvme_transport_handle_is_chardev(hdl)) { fprintf(stderr, "namespace_id or blk device required\n"); return -EINVAL; } else { - cfg.namespace_id = atoi(&nvme_transport_handle_get_name(hdl)[strlen(nvme_transport_handle_get_name(hdl)) - 1]); + cfg.namespace_id = atoi(&libnvme_transport_handle_get_name(hdl)[strlen(libnvme_transport_handle_get_name(hdl)) - 1]); } } @@ -1538,8 +1538,8 @@ static int sfx_status(int argc, char **argv, struct command *acmd, struct plugin { const char *desc = "Get ScaleFlux specific status information and print it"; const char *json_desc = "Print output in JSON format, otherwise human readable"; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; struct nvme_id_ctrl id_ctrl = { 0 }; struct extended_health_info_myrtle sfx_smart = { 0 }; struct nvme_smart_log smart_log = { 0 }; @@ -1579,7 +1579,7 @@ static int sfx_status(int argc, char **argv, struct command *acmd, struct plugin //Calculate formatted capacity, not concerned with errors, we may have a char device memset(&path, 0, 512); - snprintf(path, 512, "/dev/%s", nvme_transport_handle_get_name(hdl)); + snprintf(path, 512, "/dev/%s", libnvme_transport_handle_get_name(hdl)); fd = open(path, O_RDONLY | O_NONBLOCK); if (fd >= 0) { err = ioctl(fd, BLKSSZGET, §or_size); @@ -1596,7 +1596,7 @@ static int sfx_status(int argc, char **argv, struct command *acmd, struct plugin capacity = capacity / (1000 * 1000 * 1000); //B --> GB memset(&chr_dev, 0, 8); - strcpy(chr_dev, nvme_transport_handle_get_name(hdl)); + strcpy(chr_dev, libnvme_transport_handle_get_name(hdl)); for (len = 2; len < 8; len++) { if (chr_dev[len] == 'n') chr_dev[len] = '\0'; @@ -1903,7 +1903,7 @@ static int sfx_status(int argc, char **argv, struct command *acmd, struct plugin if (flags & JSON || cfg.json) { root = json_create_object(); - json_object_add_value_string(root, "ScaleFlux Status", nvme_transport_handle_get_name(hdl)); + json_object_add_value_string(root, "ScaleFlux Status", libnvme_transport_handle_get_name(hdl)); dev_stats = json_create_object(); link_stats = json_create_object(); @@ -1983,7 +1983,7 @@ static int sfx_status(int argc, char **argv, struct command *acmd, struct plugin if (len < 11) strcpy(path, "None"); - printf("%-35s%s%s\n", "ScaleFlux Drive:", "/dev/", nvme_transport_handle_get_name(hdl)); + printf("%-35s%s%s\n", "ScaleFlux Drive:", "/dev/", libnvme_transport_handle_get_name(hdl)); printf("%-35s%s\n", "PCIe Vendor ID:", pci_vid); printf("%-35s%s\n", "PCIe Subsystem Vendor ID:", pci_ssvid); printf("%-35s%s\n", "Manufacturer:", vendor); diff --git a/plugins/seagate/seagate-nvme.c b/plugins/seagate/seagate-nvme.c index be61e55e7f..ea408dd2a7 100644 --- a/plugins/seagate/seagate-nvme.c +++ b/plugins/seagate/seagate-nvme.c @@ -153,8 +153,8 @@ static int log_pages_supp(int argc, char **argv, struct command *acmd, __u32 i = 0; log_page_map logPageMap; const char *desc = "Retrieve Seagate Supported Log-Page information for the given device "; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; nvme_print_flags_t flags; int fmt; @@ -896,8 +896,8 @@ static int vs_smart_log(int argc, char **argv, struct command *acmd, struct plug struct json_object *lbafs_ExtSmart, *lbafs_DramSmart; const char *desc = "Retrieve the Firmware Activation History for Seagate NVMe drives"; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; nvme_print_flags_t flags; int err, index = 0; @@ -1075,8 +1075,8 @@ static int temp_stats(int argc, char **argv, struct command *acmd, struct plugin nvme_print_flags_t flags; unsigned int temperature = 0, PcbTemp = 0, SocTemp = 0, scCurrentTemp = 0, scMaxTemp = 0; unsigned long long maxTemperature = 0, MaxSocTemp = 0; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; NVME_ARGS(opts); @@ -1234,8 +1234,8 @@ static void json_vs_pcie_error_log(pcie_error_log_page pcieErrorLog) static int vs_pcie_error_log(int argc, char **argv, struct command *acmd, struct plugin *plugin) { pcie_error_log_page pcieErrorLog; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; const char *desc = "Retrieve Seagate PCIe error counters for the given device "; int err; @@ -1369,8 +1369,8 @@ static void json_stx_vs_fw_activate_history(stx_fw_activ_history_log_page fwActi static int stx_vs_fw_activate_history(int argc, char **argv, struct command *acmd, struct plugin *plugin) { stx_fw_activ_history_log_page fwActivHis; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; const char *desc = "Retrieve FW Activate History for Seagate device "; int err; @@ -1413,8 +1413,8 @@ static int clear_fw_activate_history(int argc, char **argv, struct command *acmd const char *desc = "Clear FW Activation History for the given Seagate device "; const char *save = "specifies that the controller shall save the attribute"; int err; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; struct nvme_id_ctrl ctrl; char modelNo[40]; __u64 result; @@ -1471,8 +1471,8 @@ static int vs_clr_pcie_correctable_errs(int argc, char **argv, struct command *a struct nvme_id_ctrl ctrl; char modelNo[40]; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; __u64 result; int err; @@ -1533,9 +1533,9 @@ static int get_host_tele(int argc, char **argv, struct command *acmd, struct plu const char *raw = "output in raw format"; struct nvme_temetry_log_hdr tele_log; int blkCnt, maxBlk = 0, blksToGet; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; - struct nvme_passthru_cmd cmd; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; + struct libnvme_passthru_cmd cmd; unsigned char *log; __le64 offset = 0; int err, dump_fd; @@ -1570,7 +1570,7 @@ static int get_host_tele(int argc, char **argv, struct command *acmd, struct plu if (!cfg.raw_binary) { printf("Device:%s log-id:%d namespace-id:%#x\n", - nvme_transport_handle_get_name(hdl), cfg.log_id, + libnvme_transport_handle_get_name(hdl), cfg.log_id, cfg.namespace_id); printf("Data Block 1 Last Block:%d Data Block 2 Last Block:%d Data Block 3 Last Block:%d\n", tele_log.tele_data_area1, tele_log.tele_data_area2, tele_log.tele_data_area3); @@ -1610,7 +1610,7 @@ static int get_host_tele(int argc, char **argv, struct command *acmd, struct plu nvme_init_get_log(&cmd, cfg.namespace_id, cfg.log_id, NVME_CSI_NVM, log, bytesToGet); nvme_init_get_log_lpo(&cmd, offset); - err = nvme_get_log(hdl, &cmd, true, NVME_LOG_PAGE_PDU_SIZE); + err = libnvme_get_log(hdl, &cmd, true, NVME_LOG_PAGE_PDU_SIZE); if (!err) { offset += (__le64)bytesToGet; @@ -1640,9 +1640,9 @@ static int get_ctrl_tele(int argc, char **argv, struct command *acmd, struct plu "Capture the Telemetry Controller-Initiated Data in either hex-dump (default) or binary format"; const char *namespace_id = "desired namespace"; const char *raw = "output in raw format"; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; - struct nvme_passthru_cmd cmd; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; + struct libnvme_passthru_cmd cmd; int err, dump_fd; struct nvme_temetry_log_hdr tele_log; __le64 offset = 0; @@ -1678,7 +1678,7 @@ static int get_ctrl_tele(int argc, char **argv, struct command *acmd, struct plu if (!cfg.raw_binary) { printf("Device:%s namespace-id:%#x\n", - nvme_transport_handle_get_name(hdl), cfg.namespace_id); + libnvme_transport_handle_get_name(hdl), cfg.namespace_id); printf("Data Block 1 Last Block:%d Data Block 2 Last Block:%d Data Block 3 Last Block:%d\n", tele_log.tele_data_area1, tele_log.tele_data_area2, tele_log.tele_data_area3); @@ -1714,7 +1714,7 @@ static int get_ctrl_tele(int argc, char **argv, struct command *acmd, struct plu nvme_init_get_log(&cmd, cfg.namespace_id, log_id, NVME_CSI_NVM, log, bytesToGet); nvme_init_get_log_lpo(&cmd, offset); - err = nvme_get_log(hdl, &cmd, true, NVME_LOG_PAGE_PDU_SIZE); + err = libnvme_get_log(hdl, &cmd, true, NVME_LOG_PAGE_PDU_SIZE); if (!err) { offset += (__le64)bytesToGet; @@ -1753,9 +1753,9 @@ static int vs_internal_log(int argc, char **argv, struct command *acmd, struct p const char *namespace_id = "desired namespace"; const char *file = "dump file"; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; - struct nvme_passthru_cmd cmd; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; + struct libnvme_passthru_cmd cmd; int err, dump_fd; int flags = O_WRONLY | O_CREAT; int mode = 0664; @@ -1831,7 +1831,7 @@ static int vs_internal_log(int argc, char **argv, struct command *acmd, struct p nvme_init_get_log(&cmd, cfg.namespace_id, log_id, NVME_CSI_NVM, log, bytesToGet); nvme_init_get_log_lpo(&cmd, offset); - err = nvme_get_log(hdl, &cmd, true, NVME_LOG_PAGE_PDU_SIZE); + err = libnvme_get_log(hdl, &cmd, true, NVME_LOG_PAGE_PDU_SIZE); if (!err) { offset += (__le64)bytesToGet; diff --git a/plugins/sed/sed.c b/plugins/sed/sed.c index fee0636362..6318c25071 100644 --- a/plugins/sed/sed.c +++ b/plugins/sed/sed.c @@ -65,7 +65,7 @@ OPT_ARGS(discovery_opts) = { * Open the NVMe device specified on the command line. It must be the * NVMe block device (e.g. /dev/nvme0n1). */ -static int sed_opal_open_device(struct nvme_global_ctx **ctx, struct nvme_transport_handle **hdl, int argc, char **argv, +static int sed_opal_open_device(struct libnvme_global_ctx **ctx, struct libnvme_transport_handle **hdl, int argc, char **argv, const char *desc, struct argconfig_commandline_options *opts) { int err; @@ -74,7 +74,7 @@ static int sed_opal_open_device(struct nvme_global_ctx **ctx, struct nvme_transp if (err) return err; - if (!nvme_transport_handle_is_blkdev(*hdl)) { + if (!libnvme_transport_handle_is_blkdev(*hdl)) { fprintf(stderr, "ERROR : The NVMe block device must be specified\n"); err = -EINVAL; @@ -87,15 +87,15 @@ static int sed_opal_discover(int argc, char **argv, struct command *acmd, struct plugin *plugin) { const char *desc = "Query SED device and display locking features"; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; int err; err = sed_opal_open_device(&ctx, &hdl, argc, argv, desc, discovery_opts); if (err) return err; - err = sedopal_cmd_discover(nvme_transport_handle_get_fd(hdl)); + err = sedopal_cmd_discover(libnvme_transport_handle_get_fd(hdl)); return err; } @@ -104,15 +104,15 @@ static int sed_opal_initialize(int argc, char **argv, struct command *acmd, struct plugin *plugin) { const char *desc = "Initialize a SED device for locking"; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; int err; err = sed_opal_open_device(&ctx, &hdl, argc, argv, desc, init_opts); if (err) return err; - err = sedopal_cmd_initialize(nvme_transport_handle_get_fd(hdl)); + err = sedopal_cmd_initialize(libnvme_transport_handle_get_fd(hdl)); if ((err != 0) && (err != -EOPNOTSUPP)) fprintf(stderr, "initialize: SED error - %s\n", sedopal_error_to_text(err)); @@ -124,15 +124,15 @@ static int sed_opal_revert(int argc, char **argv, struct command *acmd, struct plugin *plugin) { const char *desc = "Revert a SED device from locking state"; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; int err; err = sed_opal_open_device(&ctx, &hdl, argc, argv, desc, revert_opts); if (err) return err; - err = sedopal_cmd_revert(nvme_transport_handle_get_fd(hdl)); + err = sedopal_cmd_revert(libnvme_transport_handle_get_fd(hdl)); if ((err != 0) && (err != -EOPNOTSUPP) && (err != EPERM)) fprintf(stderr, "revert: SED error - %s\n", sedopal_error_to_text(err)); @@ -144,15 +144,15 @@ static int sed_opal_lock(int argc, char **argv, struct command *acmd, struct plugin *plugin) { const char *desc = "Lock a SED device"; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; int err; err = sed_opal_open_device(&ctx, &hdl, argc, argv, desc, lock_opts); if (err) return err; - err = sedopal_cmd_lock(nvme_transport_handle_get_fd(hdl)); + err = sedopal_cmd_lock(libnvme_transport_handle_get_fd(hdl)); if ((err != 0) && (err != -EOPNOTSUPP)) fprintf(stderr, "lock: SED error - %s\n", sedopal_error_to_text(err)); @@ -164,15 +164,15 @@ static int sed_opal_unlock(int argc, char **argv, struct command *acmd, struct plugin *plugin) { const char *desc = "Unlock a SED device"; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; int err; err = sed_opal_open_device(&ctx, &hdl, argc, argv, desc, lock_opts); if (err) return err; - err = sedopal_cmd_unlock(nvme_transport_handle_get_fd(hdl)); + err = sedopal_cmd_unlock(libnvme_transport_handle_get_fd(hdl)); if ((err != 0) && (err != -EOPNOTSUPP)) fprintf(stderr, "unlock: SED error - %s\n", sedopal_error_to_text(err)); @@ -185,14 +185,14 @@ static int sed_opal_password(int argc, char **argv, struct command *acmd, { int err; const char *desc = "Change the locking password of a SED device"; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; err = sed_opal_open_device(&ctx, &hdl, argc, argv, desc, no_opts); if (err) return err; - err = sedopal_cmd_password(nvme_transport_handle_get_fd(hdl)); + err = sedopal_cmd_password(libnvme_transport_handle_get_fd(hdl)); if ((err != 0) && (err != EPERM)) fprintf(stderr, "password: SED error - %s\n", sedopal_error_to_text(err)); diff --git a/plugins/shannon/shannon-nvme.c b/plugins/shannon/shannon-nvme.c index 490617bb86..1ffe06916b 100644 --- a/plugins/shannon/shannon-nvme.c +++ b/plugins/shannon/shannon-nvme.c @@ -120,8 +120,8 @@ static int get_additional_smart_log(int argc, char **argv, struct command *acmd, "Get Shannon vendor specific additional smart log (optionally, for the specified namespace), and show it."; const char *namespace = "(optional) desired namespace"; const char *raw = "dump output in binary format"; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; struct config { __u32 namespace_id; bool raw_binary; @@ -145,7 +145,7 @@ static int get_additional_smart_log(int argc, char **argv, struct command *acmd, if (!cfg.raw_binary) show_shannon_smart_log( &smart_log, cfg.namespace_id, - nvme_transport_handle_get_name(hdl)); + libnvme_transport_handle_get_name(hdl)); else d_raw((unsigned char *)&smart_log, sizeof(smart_log)); } else if (err > 0) { @@ -175,8 +175,8 @@ static int get_additional_feature(int argc, char **argv, struct command *acmd, s const char *data_len = "buffer len (if) data is returned"; const char *cdw11 = "dword 11 for interrupt vector config"; const char *human_readable = "show infos in readable format"; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; void *buf = NULL; __u64 result; int err; @@ -253,8 +253,8 @@ static int set_additional_feature(int argc, char **argv, struct command *acmd, s const char *data = "optional file for feature data (default stdin)"; const char *value = "new value of feature (required)"; const char *save = "specifies that the controller shall save the attribute"; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; _cleanup_free_ void *buf = NULL; int ffd = STDIN_FILENO; __u64 result; diff --git a/plugins/solidigm/solidigm-garbage-collection.c b/plugins/solidigm/solidigm-garbage-collection.c index 5d9c7b8f5c..5098ec3022 100644 --- a/plugins/solidigm/solidigm-garbage-collection.c +++ b/plugins/solidigm/solidigm-garbage-collection.c @@ -69,9 +69,9 @@ static void vu_gc_log_show(struct garbage_control_collection_log *payload, const int solidigm_get_garbage_collection_log(int argc, char **argv, struct command *acmd, struct plugin *plugin) { const char *desc = "Get and parse Solidigm vendor specific garbage collection event log."; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; - struct nvme_passthru_cmd cmd; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; + struct libnvme_passthru_cmd cmd; nvme_print_flags_t flags; int err; __u8 uuid_index; @@ -99,14 +99,14 @@ int solidigm_get_garbage_collection_log(int argc, char **argv, struct command *a cmd.cdw14 |= NVME_FIELD_ENCODE(uuid_index, NVME_LOG_CDW14_UUID_SHIFT, NVME_LOG_CDW14_UUID_MASK); - err = nvme_get_log(hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); + err = libnvme_get_log(hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); if (!err) { if (flags & BINARY) d_raw((unsigned char *)&gc_log, sizeof(gc_log)); else if (flags & JSON) - vu_gc_log_show_json(&gc_log, nvme_transport_handle_get_name(hdl)); + vu_gc_log_show_json(&gc_log, libnvme_transport_handle_get_name(hdl)); else - vu_gc_log_show(&gc_log, nvme_transport_handle_get_name(hdl), uuid_index); + vu_gc_log_show(&gc_log, libnvme_transport_handle_get_name(hdl), uuid_index); } else if (err > 0) { nvme_show_status(err); } diff --git a/plugins/solidigm/solidigm-get-drive-info.c b/plugins/solidigm/solidigm-get-drive-info.c index 729904578e..0bfe6ab399 100644 --- a/plugins/solidigm/solidigm-get-drive-info.c +++ b/plugins/solidigm/solidigm-get-drive-info.c @@ -13,11 +13,11 @@ int sldgm_get_drive_info(int argc, char **argv, struct command *acmd, struct plu { const char *desc = "Get drive HW information"; const char *FTL_unit_size_str = "FTL_unit_size"; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; nvme_print_flags_t flags; - nvme_ctrl_t c; - nvme_ns_t n; + libnvme_ctrl_t c; + libnvme_ns_t n; struct nvme_id_ns ns = { 0 }; __u8 flbaf_inUse; __u16 lba_size; @@ -36,25 +36,25 @@ int sldgm_get_drive_info(int argc, char **argv, struct command *acmd, struct plu return err; } - err = nvme_scan_topology(ctx, NULL, NULL); + err = libnvme_scan_topology(ctx, NULL, NULL); if (err) return err; - err = nvme_scan_ctrl(ctx, nvme_transport_handle_get_name(hdl), &c); + err = libnvme_scan_ctrl(ctx, libnvme_transport_handle_get_name(hdl), &c); if (!err) - n = nvme_ctrl_first_ns(c); + n = libnvme_ctrl_first_ns(c); else { - err = nvme_scan_namespace(ctx, - nvme_transport_handle_get_name(hdl), &n); + err = libnvme_scan_namespace(ctx, + libnvme_transport_handle_get_name(hdl), &n); if (err) { nvme_show_error("solidigm-vs-drive-info: drive missing namespace"); return err; } } - err = nvme_ns_identify(n, &ns); + err = libnvme_ns_identify(n, &ns); if (err) { - nvme_show_error("identify namespace: %s", nvme_strerror(errno)); + nvme_show_error("identify namespace: %s", libnvme_strerror(errno)); return err; } diff --git a/plugins/solidigm/solidigm-internal-logs.c b/plugins/solidigm/solidigm-internal-logs.c index e26e8bfcc0..e921a51a36 100644 --- a/plugins/solidigm/solidigm-internal-logs.c +++ b/plugins/solidigm/solidigm-internal-logs.c @@ -175,8 +175,8 @@ static void print_nlog_header(__u8 *buffer) #define INTERNAL_LOG_MAX_BYTE_TRANSFER 4096 #define INTERNAL_LOG_MAX_DWORD_TRANSFER (INTERNAL_LOG_MAX_BYTE_TRANSFER / 4) -static int cmd_dump_repeat(struct nvme_passthru_cmd *cmd, __u32 total_dw_size, - int out_fd, struct nvme_transport_handle *hdl, bool force_max_transfer) +static int cmd_dump_repeat(struct libnvme_passthru_cmd *cmd, __u32 total_dw_size, + int out_fd, struct libnvme_transport_handle *hdl, bool force_max_transfer) { int err = 0; @@ -185,7 +185,7 @@ static int cmd_dump_repeat(struct nvme_passthru_cmd *cmd, __u32 total_dw_size, cmd->cdw10 = force_max_transfer ? INTERNAL_LOG_MAX_DWORD_TRANSFER : dword_tfer; cmd->data_len = dword_tfer * 4; - err = nvme_submit_admin_passthru(hdl, cmd); + err = libnvme_submit_admin_passthru(hdl, cmd); if (err) return err; @@ -210,13 +210,13 @@ static int write_header(__u8 *buf, int fd, size_t amnt) return 0; } -static int read_header(struct nvme_passthru_cmd *cmd, struct nvme_transport_handle *hdl) +static int read_header(struct libnvme_passthru_cmd *cmd, struct libnvme_transport_handle *hdl) { memset((void *)(uintptr_t)cmd->addr, 0, INTERNAL_LOG_MAX_BYTE_TRANSFER); return cmd_dump_repeat(cmd, INTERNAL_LOG_MAX_DWORD_TRANSFER, -1, hdl, false); } -static int get_serial_number(char *str, struct nvme_transport_handle *hdl) +static int get_serial_number(char *str, struct libnvme_transport_handle *hdl) { struct nvme_id_ctrl ctrl = {0}; int err; @@ -232,14 +232,14 @@ static int get_serial_number(char *str, struct nvme_transport_handle *hdl) return err; } -static int ilog_dump_assert_logs(struct nvme_transport_handle *hdl, struct ilog *ilog) +static int ilog_dump_assert_logs(struct libnvme_transport_handle *hdl, struct ilog *ilog) { __u8 buf[INTERNAL_LOG_MAX_BYTE_TRANSFER]; __u8 head_buf[INTERNAL_LOG_MAX_BYTE_TRANSFER]; _cleanup_free_ char *file_path = NULL; char file_name[] = "AssertLog.bin"; struct assert_dump_header *ad = (struct assert_dump_header *) head_buf; - struct nvme_passthru_cmd cmd = { + struct libnvme_passthru_cmd cmd = { .opcode = 0xd2, .nsid = NVME_NSID_ALL, .addr = (unsigned long)(void *)head_buf, @@ -290,13 +290,13 @@ static int ilog_dump_assert_logs(struct nvme_transport_handle *hdl, struct ilog return err; } -static int ilog_dump_event_logs(struct nvme_transport_handle *hdl, struct ilog *ilog) +static int ilog_dump_event_logs(struct libnvme_transport_handle *hdl, struct ilog *ilog) { __u8 buf[INTERNAL_LOG_MAX_BYTE_TRANSFER]; __u8 head_buf[INTERNAL_LOG_MAX_BYTE_TRANSFER]; _cleanup_free_ char *file_path = NULL; struct event_dump_header *ehdr = (struct event_dump_header *) head_buf; - struct nvme_passthru_cmd cmd = { + struct libnvme_passthru_cmd cmd = { .opcode = 0xd2, .nsid = NVME_NSID_ALL, .addr = (unsigned long)(void *)head_buf, @@ -364,14 +364,14 @@ static size_t get_nlog_header_size(struct nlog_dump_header_common *nlog_header) } /* dumps nlogs from specified core or all cores when core = -1 */ -static int ilog_dump_nlogs(struct nvme_transport_handle *hdl, struct ilog *ilog, int core) +static int ilog_dump_nlogs(struct libnvme_transport_handle *hdl, struct ilog *ilog, int core) { int err = 0; __u32 count, core_num; __u8 buf[INTERNAL_LOG_MAX_BYTE_TRANSFER]; _cleanup_free_ char *file_path = NULL; struct nlog_dump_header_common *nlog_header = (struct nlog_dump_header_common *)buf; - struct nvme_passthru_cmd cmd = { + struct libnvme_passthru_cmd cmd = { .opcode = 0xd2, .nsid = NVME_NSID_ALL, .addr = (unsigned long)(void *)buf @@ -493,7 +493,7 @@ static int log_save(struct log *log, const char *parent_dir_name, const char *su return 0; } -static int ilog_dump_identify_page(struct nvme_transport_handle *hdl, +static int ilog_dump_identify_page(struct libnvme_transport_handle *hdl, struct ilog *ilog, struct log *cns, __u32 nsid) { __u8 data[NVME_IDENTIFY_DATA_SIZE]; @@ -514,7 +514,7 @@ static int ilog_dump_identify_page(struct nvme_transport_handle *hdl, sizeof(data)); } -static int ilog_ensure_dump_id_ctrl(struct nvme_transport_handle *hdl, +static int ilog_ensure_dump_id_ctrl(struct libnvme_transport_handle *hdl, struct ilog *ilog) { static bool first = true; @@ -534,13 +534,13 @@ static int ilog_ensure_dump_id_ctrl(struct nvme_transport_handle *hdl, return err; } -static bool is_atmos(struct nvme_transport_handle *hdl, struct ilog *ilog) +static bool is_atmos(struct libnvme_transport_handle *hdl, struct ilog *ilog) { ilog_ensure_dump_id_ctrl(hdl, ilog); return !strncmp(ilog->id_ctrl.mn, ATMOS_MODEL_PREFIX, sizeof(ATMOS_MODEL_PREFIX) - 1); } -static enum nvme_telemetry_da get_max_da(struct nvme_transport_handle *hdl, +static enum nvme_telemetry_da get_max_da(struct libnvme_transport_handle *hdl, struct ilog *ilog, enum log_type ttype) { enum nvme_telemetry_da max_da = NVME_TELEMETRY_DA_1; @@ -557,7 +557,7 @@ static enum nvme_telemetry_da get_max_da(struct nvme_transport_handle *hdl, return max_da; } -static int ilog_dump_telemetry(struct nvme_transport_handle *hdl, struct ilog *ilog, enum log_type ttype) +static int ilog_dump_telemetry(struct libnvme_transport_handle *hdl, struct ilog *ilog, enum log_type ttype) { int err = 0; enum nvme_telemetry_da da; @@ -565,7 +565,7 @@ static int ilog_dump_telemetry(struct nvme_transport_handle *hdl, struct ilog *i const char *file_name; struct nvme_feat_host_behavior prev = {0}; bool host_behavior_changed = false; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; struct log log = {0}; err = ilog_ensure_dump_id_ctrl(hdl, ilog); @@ -577,14 +577,14 @@ static int ilog_dump_telemetry(struct nvme_transport_handle *hdl, struct ilog *i if (da == 4) { nvme_init_get_features_host_behavior(&cmd, 0, &prev); - int err = nvme_submit_admin_passthru(hdl, &cmd); + int err = libnvme_submit_admin_passthru(hdl, &cmd); if (!err && !prev.etdas) { struct nvme_feat_host_behavior da4_enable = prev; da4_enable.etdas = 1; nvme_init_set_features_host_behavior(&cmd, 0, &da4_enable); - nvme_submit_admin_passthru(hdl, &cmd); + libnvme_submit_admin_passthru(hdl, &cmd); host_behavior_changed = true; } } @@ -612,7 +612,7 @@ static int ilog_dump_telemetry(struct nvme_transport_handle *hdl, struct ilog *i if (host_behavior_changed) { nvme_init_set_features_host_behavior(&cmd, 0, &prev); - nvme_submit_admin_passthru(hdl, &cmd); + libnvme_submit_admin_passthru(hdl, &cmd); } if (err) @@ -623,7 +623,7 @@ static int ilog_dump_telemetry(struct nvme_transport_handle *hdl, struct ilog *i return err; } -static int ilog_dump_identify_pages(struct nvme_transport_handle *hdl, struct ilog *ilog) +static int ilog_dump_identify_pages(struct libnvme_transport_handle *hdl, struct ilog *ilog) { struct nvme_ns_list ns_attached_list; struct nvme_ns_list ns_allocated_list; @@ -682,7 +682,7 @@ static int ilog_dump_identify_pages(struct nvme_transport_handle *hdl, struct il return 0; } -static int ilog_dump_log_page(struct nvme_transport_handle *hdl, struct ilog *ilog, struct log *lp, __u32 nsid) +static int ilog_dump_log_page(struct libnvme_transport_handle *hdl, struct ilog *ilog, struct log *lp, __u32 nsid) { __u8 *buff = lp->buffer; _cleanup_free_ char *filename = NULL; @@ -705,7 +705,7 @@ static int ilog_dump_log_page(struct nvme_transport_handle *hdl, struct ilog *il return log_save(lp, ilog->cfg->out_dir, "log_pages", filename, buff, lp->buffer_size); } -static int ilog_dump_no_lsp_log_pages(struct nvme_transport_handle *hdl, struct ilog *ilog) +static int ilog_dump_no_lsp_log_pages(struct libnvme_transport_handle *hdl, struct ilog *ilog) { struct lba_status_info { __u32 lslplen; @@ -774,7 +774,7 @@ static int ilog_dump_no_lsp_log_pages(struct nvme_transport_handle *hdl, struct return 0; } -static int ilog_dump_pel(struct nvme_transport_handle *hdl, struct ilog *ilog) +static int ilog_dump_pel(struct libnvme_transport_handle *hdl, struct ilog *ilog) { _cleanup_free_ struct nvme_persistent_event_log *pevent = NULL; _cleanup_huge_ struct nvme_mem_huge mh = {0}; @@ -838,8 +838,8 @@ int solidigm_get_internal_log(int argc, char **argv, struct command *acmd, _cleanup_free_ char *full_folder = NULL; _cleanup_free_ char *unique_folder = NULL; _cleanup_free_ char *zip_name = NULL; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; char *initial_folder; char *output_path; struct ilog ilog = {0}; diff --git a/plugins/solidigm/solidigm-latency-tracking.c b/plugins/solidigm/solidigm-latency-tracking.c index e007ea3401..9cbb6a0269 100644 --- a/plugins/solidigm/solidigm-latency-tracking.c +++ b/plugins/solidigm/solidigm-latency-tracking.c @@ -43,7 +43,7 @@ struct config { }; struct latency_tracker { - struct nvme_transport_handle *hdl; + struct libnvme_transport_handle *hdl; __u8 uuid_index; struct config cfg; nvme_print_flags_t print_flags; @@ -312,7 +312,7 @@ static int latency_tracking_enable(struct latency_tracker *lt) static int latency_tracker_get_log(struct latency_tracker *lt) { - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int err; if (lt->cfg.read && lt->cfg.write) { @@ -332,7 +332,7 @@ static int latency_tracker_get_log(struct latency_tracker *lt) cmd.cdw14 |= NVME_FIELD_ENCODE(lt->uuid_index, NVME_LOG_CDW14_UUID_SHIFT, NVME_LOG_CDW14_UUID_MASK); - err = nvme_get_log(lt->hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); + err = libnvme_get_log(lt->hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); if (err) return err; @@ -349,8 +349,8 @@ int solidigm_get_latency_tracking_log(int argc, char **argv, struct command *acm struct plugin *plugin) { const char *desc = "Get and Parse Solidigm Latency Tracking Statistics log."; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; __u64 enabled; int err; diff --git a/plugins/solidigm/solidigm-log-page-dir.c b/plugins/solidigm/solidigm-log-page-dir.c index 6583ac896d..0d920896e8 100644 --- a/plugins/solidigm/solidigm-log-page-dir.c +++ b/plugins/solidigm/solidigm-log-page-dir.c @@ -41,10 +41,10 @@ static void init_lid_dir(struct lid_dir *lid_dir) } } -static int get_supported_log_pages_log(struct nvme_transport_handle *hdl, int uuid_index, +static int get_supported_log_pages_log(struct libnvme_transport_handle *hdl, int uuid_index, struct nvme_supported_log_pages *supported) { - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; memset(supported, 0, sizeof(*supported)); nvme_init_get_log(&cmd, NVME_NSID_ALL, @@ -53,7 +53,7 @@ static int get_supported_log_pages_log(struct nvme_transport_handle *hdl, int uu cmd.cdw14 |= NVME_FIELD_ENCODE(uuid_index, NVME_LOG_CDW14_UUID_SHIFT, NVME_LOG_CDW14_UUID_MASK); - return nvme_get_log(hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); + return libnvme_get_log(hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); } static struct lid_dir *get_standard_lids(struct nvme_supported_log_pages *supported) @@ -185,8 +185,8 @@ int solidigm_get_log_page_directory_log(int argc, char **argv, struct command *a const int NO_UUID_INDEX = 0; const char *description = "Retrieves list of supported log pages for each UUID index."; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; NVME_ARGS(options); diff --git a/plugins/solidigm/solidigm-market-log.c b/plugins/solidigm/solidigm-market-log.c index 39b33daffe..124e3e1584 100644 --- a/plugins/solidigm/solidigm-market-log.c +++ b/plugins/solidigm/solidigm-market-log.c @@ -29,9 +29,9 @@ int sldgm_get_market_log(int argc, char **argv, struct command *acmd, { const char *desc = "Get Solidigm Marketing Name log and show it."; const char *raw = "dump output in binary format"; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; - struct nvme_passthru_cmd cmd; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; + struct libnvme_passthru_cmd cmd; char log[MARKET_LOG_MAX_SIZE]; int err; __u8 uuid_idx; @@ -52,7 +52,7 @@ int sldgm_get_market_log(int argc, char **argv, struct command *acmd, cmd.cdw14 |= NVME_FIELD_ENCODE(uuid_idx, NVME_LOG_CDW14_UUID_SHIFT, NVME_LOG_CDW14_UUID_MASK); - err = nvme_get_log(hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); + err = libnvme_get_log(hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); if (err) { nvme_show_status(err); return err; diff --git a/plugins/solidigm/solidigm-smart.c b/plugins/solidigm/solidigm-smart.c index d8e5fa7e82..508945072f 100644 --- a/plugins/solidigm/solidigm-smart.c +++ b/plugins/solidigm/solidigm-smart.c @@ -230,9 +230,9 @@ int solidigm_get_additional_smart_log(int argc, char **argv, struct command *acm const int solidigm_vu_smart_log_id = 0xCA; struct vu_smart_log smart_log_payload; nvme_print_flags_t flags; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; - struct nvme_passthru_cmd cmd; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; + struct libnvme_passthru_cmd cmd; int err; __u8 uuid_index; @@ -267,16 +267,16 @@ int solidigm_get_additional_smart_log(int argc, char **argv, struct command *acm cmd.cdw14 |= NVME_FIELD_ENCODE(uuid_index, NVME_LOG_CDW14_UUID_SHIFT, NVME_LOG_CDW14_UUID_MASK); - err = nvme_get_log(hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); + err = libnvme_get_log(hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); if (!err) { if (flags & JSON) vu_smart_log_show_json(&smart_log_payload, - cfg.namespace_id, nvme_transport_handle_get_name(hdl)); + cfg.namespace_id, libnvme_transport_handle_get_name(hdl)); else if (flags & BINARY) d_raw((unsigned char *)&smart_log_payload, sizeof(smart_log_payload)); else vu_smart_log_show(&smart_log_payload, cfg.namespace_id, - nvme_transport_handle_get_name(hdl), uuid_index); + libnvme_transport_handle_get_name(hdl), uuid_index); } else if (err > 0) { nvme_show_status(err); } diff --git a/plugins/solidigm/solidigm-telemetry.c b/plugins/solidigm/solidigm-telemetry.c index f6d5547eef..068df992fa 100644 --- a/plugins/solidigm/solidigm-telemetry.c +++ b/plugins/solidigm/solidigm-telemetry.c @@ -72,8 +72,8 @@ int solidigm_get_telemetry_log(int argc, char **argv, struct command *acmd, stru const char *sfile = "binary file containing log dump"; const char *jqfilt = "JSON config entry name containing jq filter"; bool has_binary_file = false; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; _cleanup_free_ struct nvme_telemetry_log *tlog = NULL; __attribute__((cleanup(cleanup_json_object))) struct json_object *configuration = NULL; @@ -167,7 +167,7 @@ int solidigm_get_telemetry_log(int argc, char **argv, struct command *acmd, stru size_t power2; __u8 mdts = 0; - err = nvme_get_telemetry_max(hdl, NULL, &max_data_tx); + err = libnvme_get_telemetry_max(hdl, NULL, &max_data_tx); if (err) { nvme_show_err(err, "identify_ctrl"); return err; diff --git a/plugins/solidigm/solidigm-temp-stats.c b/plugins/solidigm/solidigm-temp-stats.c index 8ea758b1ce..b6bc0ee0c9 100644 --- a/plugins/solidigm/solidigm-temp-stats.c +++ b/plugins/solidigm/solidigm-temp-stats.c @@ -40,10 +40,10 @@ static void show_temp_stats(struct temp_stats *stats) int sldgm_get_temp_stats_log(int argc, char **argv, struct command *acmd, struct plugin *plugin) { - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; unsigned char buffer[4096] = {0}; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; __u8 uuid_idx; int err; @@ -72,7 +72,7 @@ int sldgm_get_temp_stats_log(int argc, char **argv, struct command *acmd, struct cmd.cdw14 |= NVME_FIELD_ENCODE(uuid_idx, NVME_LOG_CDW14_UUID_SHIFT, NVME_LOG_CDW14_UUID_MASK); - err = nvme_get_log(hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); + err = libnvme_get_log(hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); if (err > 0) { nvme_init_get_log(&cmd, NVME_NSID_ALL, SLDGM_LEGACY_TEMP_STATS_LID, NVME_CSI_NVM, @@ -80,7 +80,7 @@ int sldgm_get_temp_stats_log(int argc, char **argv, struct command *acmd, struct cmd.cdw14 |= NVME_FIELD_ENCODE(uuid_idx, NVME_LOG_CDW14_UUID_SHIFT, NVME_LOG_CDW14_UUID_MASK); - err = nvme_get_log(hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); + err = libnvme_get_log(hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); if (!err) { uint64_t *guid = (uint64_t *)&buffer[4080]; diff --git a/plugins/solidigm/solidigm-util.c b/plugins/solidigm/solidigm-util.c index 5a9009da77..cfbedf0f52 100644 --- a/plugins/solidigm/solidigm-util.c +++ b/plugins/solidigm/solidigm-util.c @@ -18,7 +18,7 @@ const unsigned char solidigm_uuid[NVME_UUID_LEN] = { int sldgm_find_uuid_index(struct nvme_id_uuid_list *uuid_list, __u8 *index) { - int i = nvme_find_uuid(uuid_list, solidigm_uuid); + int i = libnvme_find_uuid(uuid_list, solidigm_uuid); *index = 0; if (i > 0) @@ -29,7 +29,7 @@ int sldgm_find_uuid_index(struct nvme_id_uuid_list *uuid_list, __u8 *index) return 0; } -int sldgm_get_uuid_index(struct nvme_transport_handle *hdl, __u8 *index) +int sldgm_get_uuid_index(struct libnvme_transport_handle *hdl, __u8 *index) { struct nvme_id_uuid_list uuid_list; int err; @@ -43,7 +43,7 @@ int sldgm_get_uuid_index(struct nvme_transport_handle *hdl, __u8 *index) return sldgm_find_uuid_index(&uuid_list, index); } -int sldgm_dynamic_telemetry(struct nvme_transport_handle *hdl, bool create, +int sldgm_dynamic_telemetry(struct libnvme_transport_handle *hdl, bool create, bool ctrl, bool log_page, __u8 mtds, enum nvme_telemetry_da da, struct nvme_telemetry_log **log_buffer, @@ -53,7 +53,7 @@ int sldgm_dynamic_telemetry(struct nvme_transport_handle *hdl, bool create, int err; do { - err = nvme_get_telemetry_log(hdl, create, ctrl, log_page, max_data_tx, da, + err = libnvme_get_telemetry_log(hdl, create, ctrl, log_page, max_data_tx, da, log_buffer, log_buffer_size); max_data_tx /= 2; create = false; diff --git a/plugins/solidigm/solidigm-util.h b/plugins/solidigm/solidigm-util.h index 7ab27ac3da..9bec9ea279 100644 --- a/plugins/solidigm/solidigm-util.h +++ b/plugins/solidigm/solidigm-util.h @@ -8,7 +8,7 @@ #include "nvme.h" int sldgm_find_uuid_index(struct nvme_id_uuid_list *uuid_list, __u8 *index); -int sldgm_get_uuid_index(struct nvme_transport_handle *hdl, __u8 *index); -int sldgm_dynamic_telemetry(struct nvme_transport_handle *hdl, bool create, bool ctrl, bool log_page, __u8 mtds, +int sldgm_get_uuid_index(struct libnvme_transport_handle *hdl, __u8 *index); +int sldgm_dynamic_telemetry(struct libnvme_transport_handle *hdl, bool create, bool ctrl, bool log_page, __u8 mtds, enum nvme_telemetry_da da, struct nvme_telemetry_log **log_buffer, size_t *log_buffer_size); diff --git a/plugins/solidigm/solidigm-workload-tracker.c b/plugins/solidigm/solidigm-workload-tracker.c index 5c408f6930..3d9b277bbe 100644 --- a/plugins/solidigm/solidigm-workload-tracker.c +++ b/plugins/solidigm/solidigm-workload-tracker.c @@ -198,7 +198,7 @@ struct workloadLog { // Full WL Log Structure #pragma pack(pop) struct wltracker { - struct nvme_transport_handle *hdl; + struct libnvme_transport_handle *hdl; __u8 uuid_index; struct workloadLog workload_log; size_t poll_count; @@ -284,7 +284,7 @@ static int wltracker_show_newer_entries(struct wltracker *wlt) struct workloadLog *log = &wlt->workload_log; union WorkloadLogEnable workloadEnable; static __u64 last_timestamp_us; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; __u64 timestamp_us = 0; __u64 timestamp = 0; __u8 content_group; @@ -296,7 +296,7 @@ static int wltracker_show_newer_entries(struct wltracker *wlt) cmd.cdw14 |= NVME_FIELD_ENCODE(wlt->uuid_index, NVME_LOG_CDW14_UUID_SHIFT, NVME_LOG_CDW14_UUID_MASK); - err = nvme_get_log(wlt->hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); + err = libnvme_get_log(wlt->hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); if (err > 0) { nvme_show_status(err); return err; @@ -493,8 +493,8 @@ int sldgm_get_workload_tracker(int argc, char **argv, struct command *acmd, stru const char *run_time = "Limit runtime capture time in seconds"; const char *flush_frequency = "Samples (1 to 126) to wait for extracting data. Default 100 samples"; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; struct wltracker wlt = {0}; union WorkloadLogEnable we = {0}; char type_options[80] = {0}; @@ -605,7 +605,7 @@ int sldgm_get_workload_tracker(int argc, char **argv, struct command *acmd, stru err = nvme_set_features(wlt.hdl, 0, 0xf5, 0, cfg.trigger_treshold, 0, 0, wlt.uuid_index, 0, NULL, 0, NULL); if (err < 0) { - nvme_show_error("Trigger Threshold set-feature: %s", nvme_strerror(errno)); + nvme_show_error("Trigger Threshold set-feature: %s", libnvme_strerror(errno)); return err; } else if (err > 0) { nvme_show_status(err); @@ -623,7 +623,7 @@ int sldgm_get_workload_tracker(int argc, char **argv, struct command *acmd, stru we.trackerEnable = true; err = wltracker_config(&wlt, &we); if (err < 0) { - nvme_show_error("tracker set-feature: %s", nvme_strerror(errno)); + nvme_show_error("tracker set-feature: %s", libnvme_strerror(errno)); return err; } else if (err > 0) { nvme_show_status(err); @@ -677,7 +677,7 @@ int sldgm_get_workload_tracker(int argc, char **argv, struct command *acmd, stru we2.triggerEnable = false; err = wltracker_config(&wlt, &we2); if (err < 0) { - nvme_show_error("tracker set-feature: %s", nvme_strerror(errno)); + nvme_show_error("tracker set-feature: %s", libnvme_strerror(errno)); return err; } else if (err > 0) { nvme_show_status(err); diff --git a/plugins/ssstc/ssstc-nvme.c b/plugins/ssstc/ssstc-nvme.c index 95c3b2c266..fb9ea92a01 100644 --- a/plugins/ssstc/ssstc-nvme.c +++ b/plugins/ssstc/ssstc-nvme.c @@ -389,8 +389,8 @@ int ssstc_get_add_smart_log(int argc, char **argv, struct command *acmd, struct #endif /* CONFIG_JSONC */ struct nvme_additional_smart_log smart_log_add; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; int err; struct config { @@ -417,11 +417,11 @@ int ssstc_get_add_smart_log(int argc, char **argv, struct command *acmd, struct if (cfg.json) show_ssstc_add_smart_log_jsn( &smart_log_add, cfg.namespace_id, - nvme_transport_handle_get_name(hdl)); + libnvme_transport_handle_get_name(hdl)); else if (!cfg.raw_binary) show_ssstc_add_smart_log( &smart_log_add, cfg.namespace_id, - nvme_transport_handle_get_name(hdl)); + libnvme_transport_handle_get_name(hdl)); else d_raw((unsigned char *)&smart_log_add, sizeof(smart_log_add)); } else if (err > 0) { diff --git a/plugins/toshiba/toshiba-nvme.c b/plugins/toshiba/toshiba-nvme.c index 3c0e46f926..2e68cc8a4f 100644 --- a/plugins/toshiba/toshiba-nvme.c +++ b/plugins/toshiba/toshiba-nvme.c @@ -49,20 +49,20 @@ enum { CODE_1 = 0x10 }; -static int nvme_sct_op(struct nvme_transport_handle *hdl, __u32 opcode, +static int nvme_sct_op(struct libnvme_transport_handle *hdl, __u32 opcode, __u32 cdw10, __u32 cdw11, void *data, __u32 data_len) { - struct nvme_passthru_cmd cmd = { + struct libnvme_passthru_cmd cmd = { .opcode = opcode, .cdw10 = cdw10, .cdw11 = cdw11, .data_len = data_len, .addr = (__u64)(uintptr_t)data, }; - return nvme_submit_admin_passthru(hdl, &cmd); + return libnvme_submit_admin_passthru(hdl, &cmd); } -static int nvme_get_sct_status(struct nvme_transport_handle *hdl, __u32 device_mask) +static int nvme_get_sct_status(struct libnvme_transport_handle *hdl, __u32 device_mask) { int err; void *data = NULL; @@ -114,7 +114,7 @@ static int nvme_get_sct_status(struct nvme_transport_handle *hdl, __u32 device_m return err; } -static int nvme_sct_command_transfer_log(struct nvme_transport_handle *hdl, bool current) +static int nvme_sct_command_transfer_log(struct libnvme_transport_handle *hdl, bool current) { int err; void *data = NULL; @@ -138,7 +138,7 @@ static int nvme_sct_command_transfer_log(struct nvme_transport_handle *hdl, bool return err; } -static int nvme_sct_data_transfer(struct nvme_transport_handle *hdl, void *data, +static int nvme_sct_data_transfer(struct libnvme_transport_handle *hdl, void *data, size_t data_len, size_t offset) { __u32 dw10, dw11, lba_count = (data_len) / 512; @@ -197,7 +197,7 @@ static void progress_runner(float progress) fflush(stdout); } -static int nvme_get_internal_log(struct nvme_transport_handle *hdl, +static int nvme_get_internal_log(struct libnvme_transport_handle *hdl, const char *const filename, bool current) { int err; @@ -318,7 +318,7 @@ static int nvme_get_internal_log(struct nvme_transport_handle *hdl, return err; } -static int nvme_get_internal_log_file(struct nvme_transport_handle *hdl, +static int nvme_get_internal_log_file(struct libnvme_transport_handle *hdl, const char *const filename, bool current) { int err; @@ -346,12 +346,12 @@ struct nvme_xdn_smart_log_c0 { __u8 resv[512 - NR_SMART_ITEMS_C0]; }; -static void default_show_vendor_log_c0(struct nvme_transport_handle *hdl, +static void default_show_vendor_log_c0(struct libnvme_transport_handle *hdl, __u32 nsid, struct nvme_xdn_smart_log_c0 *smart) { printf("Vendor Log Page Directory 0xC0 for NVME device:%s namespace-id:%x\n", - nvme_transport_handle_get_name(hdl), nsid); + libnvme_transport_handle_get_name(hdl), nsid); printf("Error Log : %u\n", smart->items[ERROR_LOG_C0]); printf("SMART Health Log : %u\n", smart->items[SMART_HEALTH_LOG_C0]); printf("Firmware Slot Info : %u\n", smart->items[FIRMWARE_SLOT_INFO_C0]); @@ -361,7 +361,7 @@ static void default_show_vendor_log_c0(struct nvme_transport_handle *hdl, printf("SMART Attributes : %u\n", smart->items[SMART_ATTRIBUTES_C0]); } -static int nvme_get_vendor_log(struct nvme_transport_handle *hdl, +static int nvme_get_vendor_log(struct libnvme_transport_handle *hdl, __u32 namespace_id, int log_page, const char *const filename) { @@ -421,8 +421,8 @@ static int vendor_log(int argc, char **argv, struct command *acmd, struct plugin const char *namespace = "(optional) desired namespace"; const char *output_file = "(optional) binary output filename"; const char *log = "(optional) log ID (0xC0, or 0xCA), default 0xCA"; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; int err; struct config { @@ -470,8 +470,8 @@ static int internal_log(int argc, char **argv, struct command *acmd, struct plug char *desc = "Get internal status log and show it."; const char *output_file = "(optional) binary output filename"; const char *prev_log = "(optional) use previous log. Otherwise uses current log."; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; int err; struct config { @@ -513,8 +513,8 @@ static int clear_correctable_errors(int argc, char **argv, struct command *acmd, struct plugin *plugin) { char *desc = "Clear PCIe correctable error count."; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; const __u32 namespace_id = 0xFFFFFFFF; const __u32 feature_id = 0xCA; const __u32 value = 1; /* Bit0 - reset clear PCIe correctable count */ diff --git a/plugins/transcend/transcend-nvme.c b/plugins/transcend/transcend-nvme.c index 425fc4cc2a..cde06891a1 100644 --- a/plugins/transcend/transcend-nvme.c +++ b/plugins/transcend/transcend-nvme.c @@ -24,8 +24,8 @@ static int getHealthValue(int argc, char **argv, struct command *acmd, struct pl struct nvme_smart_log smart_log; char *desc = "Get nvme health percentage."; int percent_used = 0, healthvalue = 0; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; int result; NVME_ARGS(opts); @@ -55,9 +55,9 @@ static int getBadblock(int argc, char **argv, struct command *acmd, struct plugi { char *desc = "Get nvme bad block number."; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; - struct nvme_passthru_cmd nvmecmd; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; + struct libnvme_passthru_cmd nvmecmd; unsigned char data[1] = {0}; int result; @@ -76,7 +76,7 @@ static int getBadblock(int argc, char **argv, struct command *acmd, struct plugi nvmecmd.addr = (__u64)(uintptr_t)data; nvmecmd.data_len = 0x1; - result = nvme_submit_admin_passthru(hdl, &nvmecmd); + result = libnvme_submit_admin_passthru(hdl, &nvmecmd); if (!result) { int badblock = data[0]; diff --git a/plugins/virtium/virtium-nvme.c b/plugins/virtium/virtium-nvme.c index 20367db310..83217e8e95 100644 --- a/plugins/virtium/virtium-nvme.c +++ b/plugins/virtium/virtium-nvme.c @@ -264,7 +264,7 @@ static void vt_process_string(char *str, const size_t size) } } -static int vt_add_entry_to_log(struct nvme_transport_handle *hdl, +static int vt_add_entry_to_log(struct libnvme_transport_handle *hdl, const char *path, const struct vtview_save_log_settings *cfg) { @@ -281,7 +281,7 @@ static int vt_add_entry_to_log(struct nvme_transport_handle *hdl, filename = cfg->output_file; smart.time_stamp = time(NULL); - ret = nvme_get_nsid(hdl, &nsid); + ret = libnvme_get_nsid(hdl, &nsid); if (ret < 0) { printf("Cannot read namespace-id\n"); @@ -314,7 +314,7 @@ static int vt_add_entry_to_log(struct nvme_transport_handle *hdl, } static int -vt_update_vtview_log_header(struct nvme_transport_handle *hdl, const char *path, +vt_update_vtview_log_header(struct libnvme_transport_handle *hdl, const char *path, const struct vtview_save_log_settings *cfg) { struct vtview_log_header header; @@ -949,8 +949,8 @@ static int vt_save_smart_to_vtview_log(int argc, char **argv, const char *freq = "(optional) How often you want to log SMART data (0.25 = 15' , 0.5 = 30' , 1 = 1 hour, 2 = 2 hours, etc.). Default = 10 hours."; const char *output_file = "(optional) Name of the log file (give it a name that easy for you to remember what the test is). You can leave it blank too, we will take care it for you."; const char *test_name = "(optional) Name of the test you are doing. We use this as part of the name of the log file."; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; struct vtview_save_log_settings cfg = { .run_time_hrs = 20, @@ -1026,8 +1026,8 @@ static int vt_show_identify(int argc, char **argv, struct command *acmd, struct char *desc = "Parse identify data to json format\n\n" "Typical usages:\n\n" "virtium show-identify /dev/yourDevice\n"; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; struct nvme_id_ctrl ctrl; int ret, err = 0; diff --git a/plugins/wdc/wdc-nvme-cmds.h b/plugins/wdc/wdc-nvme-cmds.h index ac8dace8e9..5a6bb40725 100644 --- a/plugins/wdc/wdc-nvme-cmds.h +++ b/plugins/wdc/wdc-nvme-cmds.h @@ -117,13 +117,13 @@ int run_wdc_cu_smart_log(int argc, char **argv, struct command *command, struct plugin *plugin); -bool run_wdc_nvme_check_supported_log_page(struct nvme_global_ctx *ctx, - struct nvme_transport_handle *hdl, +bool run_wdc_nvme_check_supported_log_page(struct libnvme_global_ctx *ctx, + struct libnvme_transport_handle *hdl, __u8 log_id, __u8 uuid_index); -__u32 run_wdc_get_fw_cust_id(struct nvme_global_ctx *ctx, - struct nvme_transport_handle *hdl); +__u32 run_wdc_get_fw_cust_id(struct libnvme_global_ctx *ctx, + struct libnvme_transport_handle *hdl); -__u64 run_wdc_get_drive_capabilities(struct nvme_global_ctx *ctx, - struct nvme_transport_handle *hdl); +__u64 run_wdc_get_drive_capabilities(struct libnvme_global_ctx *ctx, + struct libnvme_transport_handle *hdl); diff --git a/plugins/wdc/wdc-nvme.c b/plugins/wdc/wdc-nvme.c index 3b55b6a2cb..125674f9c8 100644 --- a/plugins/wdc/wdc-nvme.c +++ b/plugins/wdc/wdc-nvme.c @@ -941,66 +941,66 @@ struct __packed feature_latency_monitor { __u8 reserved[4083]; }; -static int wdc_get_serial_name(struct nvme_transport_handle *hdl, char *file, size_t len, const char *suffix); +static int wdc_get_serial_name(struct libnvme_transport_handle *hdl, char *file, size_t len, const char *suffix); static int wdc_create_log_file(const char *file, const __u8 *drive_log_data, __u32 drive_log_length); -static int wdc_do_clear_dump(struct nvme_transport_handle *hdl, __u8 opcode, __u32 cdw12); -static int wdc_do_dump(struct nvme_transport_handle *hdl, __u32 opcode, __u32 data_len, __u32 cdw12, +static int wdc_do_clear_dump(struct libnvme_transport_handle *hdl, __u8 opcode, __u32 cdw12); +static int wdc_do_dump(struct libnvme_transport_handle *hdl, __u32 opcode, __u32 data_len, __u32 cdw12, const char *file, __u32 xfer_size); -static int wdc_do_crash_dump(struct nvme_transport_handle *hdl, char *file, int type); -static int wdc_crash_dump(struct nvme_transport_handle *hdl, const char *file, int type); +static int wdc_do_crash_dump(struct libnvme_transport_handle *hdl, char *file, int type); +static int wdc_crash_dump(struct libnvme_transport_handle *hdl, const char *file, int type); static int wdc_get_crash_dump(int argc, char **argv, struct command *acmd, struct plugin *plugin); -static int wdc_do_drive_log(struct nvme_transport_handle *hdl, const char *file); +static int wdc_do_drive_log(struct libnvme_transport_handle *hdl, const char *file); static int wdc_drive_log(int argc, char **argv, struct command *acmd, struct plugin *plugin); static const char *wdc_purge_mon_status_to_string(__u32 status); static int wdc_purge(int argc, char **argv, struct command *acmd, struct plugin *plugin); static int wdc_purge_monitor(int argc, char **argv, struct command *acmd, struct plugin *plugin); -static bool wdc_nvme_check_supported_log_page(struct nvme_global_ctx *ctx, - struct nvme_transport_handle *hdl, +static bool wdc_nvme_check_supported_log_page(struct libnvme_global_ctx *ctx, + struct libnvme_transport_handle *hdl, __u8 log_id, __u8 uuid_index); static int wdc_clear_pcie_correctable_errors(int argc, char **argv, struct command *acmd, struct plugin *plugin); -static int wdc_do_drive_essentials(struct nvme_global_ctx *ctx, struct nvme_transport_handle *hdl, char *dir, char *key); +static int wdc_do_drive_essentials(struct libnvme_global_ctx *ctx, struct libnvme_transport_handle *hdl, char *dir, char *key); static int wdc_drive_essentials(int argc, char **argv, struct command *acmd, struct plugin *plugin); static int wdc_drive_status(int argc, char **argv, struct command *acmd, struct plugin *plugin); static int wdc_clear_assert_dump(int argc, char **argv, struct command *acmd, struct plugin *plugin); static int wdc_drive_resize(int argc, char **argv, struct command *acmd, struct plugin *plugin); -static int wdc_do_drive_resize(struct nvme_transport_handle *hdl, uint64_t new_size); +static int wdc_do_drive_resize(struct libnvme_transport_handle *hdl, uint64_t new_size); static int wdc_namespace_resize(int argc, char **argv, struct command *acmd, struct plugin *plugin); -static int wdc_do_namespace_resize(struct nvme_transport_handle *hdl, __u32 nsid, __u32 op_option); +static int wdc_do_namespace_resize(struct libnvme_transport_handle *hdl, __u32 nsid, __u32 op_option); static int wdc_reason_identifier(int argc, char **argv, struct command *acmd, struct plugin *plugin); -static int wdc_do_get_reason_id(struct nvme_transport_handle *hdl, const char *file, int log_id); -static int wdc_save_reason_id(struct nvme_transport_handle *hdl, __u8 *rsn_ident, int size); -static int wdc_clear_reason_id(struct nvme_transport_handle *hdl); +static int wdc_do_get_reason_id(struct libnvme_transport_handle *hdl, const char *file, int log_id); +static int wdc_save_reason_id(struct libnvme_transport_handle *hdl, __u8 *rsn_ident, int size); +static int wdc_clear_reason_id(struct libnvme_transport_handle *hdl); static int wdc_log_page_directory(int argc, char **argv, struct command *acmd, struct plugin *plugin); -static int wdc_do_drive_info(struct nvme_transport_handle *hdl, __u32 *result); +static int wdc_do_drive_info(struct libnvme_transport_handle *hdl, __u32 *result); static int wdc_vs_drive_info(int argc, char **argv, struct command *acmd, struct plugin *plugin); static int wdc_vs_temperature_stats(int argc, char **argv, struct command *acmd, struct plugin *plugin); -static __u64 wdc_get_enc_drive_capabilities(struct nvme_global_ctx *ctx, struct nvme_transport_handle *hdl); -static int wdc_enc_get_nic_log(struct nvme_transport_handle *hdl, __u8 log_id, __u32 xfer_size, __u32 data_len, +static __u64 wdc_get_enc_drive_capabilities(struct libnvme_global_ctx *ctx, struct libnvme_transport_handle *hdl); +static int wdc_enc_get_nic_log(struct libnvme_transport_handle *hdl, __u8 log_id, __u32 xfer_size, __u32 data_len, FILE *out); -static int wdc_enc_submit_move_data(struct nvme_transport_handle *hdl, char *cmd, int len, int xfer_size, +static int wdc_enc_submit_move_data(struct libnvme_transport_handle *hdl, char *cmd, int len, int xfer_size, FILE *out, int data_id, int cdw14, int cdw15); -static bool get_dev_mgment_cbs_data(struct nvme_global_ctx *ctx, struct nvme_transport_handle *hdl, __u8 log_id, +static bool get_dev_mgment_cbs_data(struct libnvme_global_ctx *ctx, struct libnvme_transport_handle *hdl, __u8 log_id, void **cbs_data); -static __u32 wdc_get_fw_cust_id(struct nvme_global_ctx *ctx, struct nvme_transport_handle *hdl); +static __u32 wdc_get_fw_cust_id(struct libnvme_global_ctx *ctx, struct libnvme_transport_handle *hdl); static int wdc_print_c0_cloud_attr_log(void *data, int fmt, - struct nvme_transport_handle *hdl); + struct libnvme_transport_handle *hdl); static int wdc_print_c0_eol_log(void *data, int fmt); static void wdc_show_cloud_smart_log_normal(struct ocp_cloud_smart_log *log, - struct nvme_transport_handle *hdl); + struct libnvme_transport_handle *hdl); static void wdc_show_cloud_smart_log_json(struct ocp_cloud_smart_log *log); -static bool get_dev_mgment_data(struct nvme_global_ctx *ctx, - struct nvme_transport_handle *hdl, +static bool get_dev_mgment_data(struct libnvme_global_ctx *ctx, + struct libnvme_transport_handle *hdl, void **data); static bool wdc_nvme_parse_dev_status_log_entry(void *log_data, __u32 *ret_data, @@ -1474,34 +1474,34 @@ static double calc_percent(uint64_t numerator, uint64_t denominator) (uint64_t)(((double)numerator / (double)denominator) * 100) : 0; } -static int wdc_get_pci_ids(struct nvme_global_ctx *ctx, struct nvme_transport_handle *hdl, +static int wdc_get_pci_ids(struct libnvme_global_ctx *ctx, struct libnvme_transport_handle *hdl, uint32_t *device_id, uint32_t *vendor_id) { - const char *name = nvme_transport_handle_get_name(hdl); + const char *name = libnvme_transport_handle_get_name(hdl); char vid[256], did[256], id[32]; - nvme_ctrl_t c = NULL; - nvme_ns_t n = NULL; + libnvme_ctrl_t c = NULL; + libnvme_ns_t n = NULL; int fd, ret; - ret = nvme_scan_ctrl(ctx, name, &c); + ret = libnvme_scan_ctrl(ctx, name, &c); if (!ret) { snprintf(vid, sizeof(vid), "%s/device/vendor", - nvme_ctrl_get_sysfs_dir(c)); + libnvme_ctrl_get_sysfs_dir(c)); snprintf(did, sizeof(did), "%s/device/device", - nvme_ctrl_get_sysfs_dir(c)); - nvme_free_ctrl(c); + libnvme_ctrl_get_sysfs_dir(c)); + libnvme_free_ctrl(c); } else { - ret = nvme_scan_namespace(ctx, name, &n); + ret = libnvme_scan_namespace(ctx, name, &n); if (ret) { fprintf(stderr, "Unable to find %s\n", name); return ret; } snprintf(vid, sizeof(vid), "%s/device/device/vendor", - nvme_ns_get_sysfs_dir(n)); + libnvme_ns_get_sysfs_dir(n)); snprintf(did, sizeof(did), "%s/device/device/device", - nvme_ns_get_sysfs_dir(n)); - nvme_free_ns(n); + libnvme_ns_get_sysfs_dir(n)); + libnvme_free_ns(n); } fd = open(vid, O_RDONLY); @@ -1545,7 +1545,7 @@ static int wdc_get_pci_ids(struct nvme_global_ctx *ctx, struct nvme_transport_ha return 0; } -static int wdc_get_vendor_id(struct nvme_transport_handle *hdl, uint32_t *vendor_id) +static int wdc_get_vendor_id(struct libnvme_transport_handle *hdl, uint32_t *vendor_id) { struct nvme_id_ctrl ctrl; int ret; @@ -1619,7 +1619,7 @@ static bool wdc_check_power_of_2(int num) return num && (!(num & (num-1))); } -static int wdc_get_model_number(struct nvme_transport_handle *hdl, char *model) +static int wdc_get_model_number(struct libnvme_transport_handle *hdl, char *model) { struct nvme_id_ctrl ctrl; int ret, i; @@ -1641,7 +1641,7 @@ static int wdc_get_model_number(struct nvme_transport_handle *hdl, char *model) return ret; } -static bool wdc_check_device(struct nvme_global_ctx *ctx, struct nvme_transport_handle *hdl) +static bool wdc_check_device(struct libnvme_global_ctx *ctx, struct libnvme_transport_handle *hdl) { int ret; bool supported; @@ -1668,7 +1668,7 @@ static bool wdc_check_device(struct nvme_global_ctx *ctx, struct nvme_transport_ return supported; } -static bool wdc_enc_check_model(struct nvme_transport_handle *hdl) +static bool wdc_enc_check_model(struct libnvme_transport_handle *hdl) { int ret; bool supported; @@ -1688,7 +1688,7 @@ static bool wdc_enc_check_model(struct nvme_transport_handle *hdl) return supported; } -static __u64 wdc_get_drive_capabilities(struct nvme_global_ctx *ctx, struct nvme_transport_handle *hdl) +static __u64 wdc_get_drive_capabilities(struct libnvme_global_ctx *ctx, struct libnvme_transport_handle *hdl) { int ret; uint32_t read_device_id = -1, read_vendor_id = -1; @@ -2079,8 +2079,8 @@ static __u64 wdc_get_drive_capabilities(struct nvme_global_ctx *ctx, struct nvme return capabilities; } -static __u64 wdc_get_enc_drive_capabilities(struct nvme_global_ctx *ctx, - struct nvme_transport_handle *hdl) +static __u64 wdc_get_enc_drive_capabilities(struct libnvme_global_ctx *ctx, + struct libnvme_transport_handle *hdl) { int ret; uint32_t read_vendor_id; @@ -2121,13 +2121,13 @@ static __u64 wdc_get_enc_drive_capabilities(struct nvme_global_ctx *ctx, memset(&uuid_list, 0, sizeof(struct nvme_id_uuid_list)); if (wdc_CheckUuidListSupport(hdl, &uuid_list)) { /* check for the Sandisk UUID first */ - uuid_index = nvme_find_uuid(&uuid_list, SNDK_UUID); + uuid_index = libnvme_find_uuid(&uuid_list, SNDK_UUID); if (uuid_index < 0) /* The Sandisk UUID is not found; * check for the WDC UUID second. */ - uuid_index = nvme_find_uuid(&uuid_list, WDC_UUID); + uuid_index = libnvme_find_uuid(&uuid_list, WDC_UUID); } /* WD UUID not found, use default uuid index - 0 */ @@ -2209,7 +2209,7 @@ static __u64 wdc_get_enc_drive_capabilities(struct nvme_global_ctx *ctx, return capabilities; } -static int wdc_get_serial_name(struct nvme_transport_handle *hdl, char *file, size_t len, +static int wdc_get_serial_name(struct libnvme_transport_handle *hdl, char *file, size_t len, const char *suffix) { int i; @@ -2259,14 +2259,14 @@ static int wdc_create_log_file(const char *file, const __u8 *drive_log_data, fd = open(file, O_WRONLY | O_CREAT | O_TRUNC, 0666); if (fd < 0) { - fprintf(stderr, "ERROR: WDC: open: %s\n", nvme_strerror(errno)); + fprintf(stderr, "ERROR: WDC: open: %s\n", libnvme_strerror(errno)); return -1; } while (drive_log_length > WRITE_SIZE) { ret = write(fd, drive_log_data, WRITE_SIZE); if (ret < 0) { - fprintf(stderr, "ERROR: WDC: write: %s\n", nvme_strerror(errno)); + fprintf(stderr, "ERROR: WDC: write: %s\n", libnvme_strerror(errno)); close(fd); return -1; } @@ -2276,13 +2276,13 @@ static int wdc_create_log_file(const char *file, const __u8 *drive_log_data, ret = write(fd, drive_log_data, drive_log_length); if (ret < 0) { - fprintf(stderr, "ERROR: WDC: write: %s\n", nvme_strerror(errno)); + fprintf(stderr, "ERROR: WDC: write: %s\n", libnvme_strerror(errno)); close(fd); return -1; } if (fsync(fd) < 0) { - fprintf(stderr, "ERROR: WDC: fsync: %s\n", nvme_strerror(errno)); + fprintf(stderr, "ERROR: WDC: fsync: %s\n", libnvme_strerror(errno)); close(fd); return -1; } @@ -2546,11 +2546,11 @@ bool wdc_get_dev_mng_log_entry(__u32 log_length, __u32 entry_id, return valid_log; } -static bool get_dev_mgmt_log_page_data(struct nvme_transport_handle *hdl, void **log_data, +static bool get_dev_mgmt_log_page_data(struct libnvme_transport_handle *hdl, void **log_data, __u8 uuid_ix) { struct wdc_c2_log_page_header *hdr_ptr; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; bool valid = false; __u32 length = 0; void *data; @@ -2558,7 +2558,7 @@ static bool get_dev_mgmt_log_page_data(struct nvme_transport_handle *hdl, void * data = (__u8 *)malloc(sizeof(__u8) * WDC_C2_LOG_BUF_LEN); if (!data) { - fprintf(stderr, "ERROR: WDC: malloc: %s\n", nvme_strerror(errno)); + fprintf(stderr, "ERROR: WDC: malloc: %s\n", libnvme_strerror(errno)); return false; } @@ -2571,7 +2571,7 @@ static bool get_dev_mgmt_log_page_data(struct nvme_transport_handle *hdl, void * cmd.cdw14 |= NVME_FIELD_ENCODE(uuid_ix, NVME_LOG_CDW14_UUID_SHIFT, NVME_LOG_CDW14_UUID_MASK); - ret = nvme_get_log(hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); + ret = libnvme_get_log(hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); if (ret) { fprintf(stderr, "ERROR: WDC: Unable to get 0x%x Log Page with uuid %d, ret = 0x%x\n", @@ -2587,7 +2587,7 @@ static bool get_dev_mgmt_log_page_data(struct nvme_transport_handle *hdl, void * free(data); data = calloc(length, sizeof(__u8)); if (!data) { - fprintf(stderr, "ERROR: WDC: malloc: %s\n", nvme_strerror(errno)); + fprintf(stderr, "ERROR: WDC: malloc: %s\n", libnvme_strerror(errno)); goto end; } @@ -2598,7 +2598,7 @@ static bool get_dev_mgmt_log_page_data(struct nvme_transport_handle *hdl, void * cmd.cdw14 |= NVME_FIELD_ENCODE(uuid_ix, NVME_LOG_CDW14_UUID_SHIFT, NVME_LOG_CDW14_UUID_MASK); - ret = nvme_get_log(hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); + ret = libnvme_get_log(hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); if (ret) { fprintf(stderr, "ERROR: WDC: Unable to read 0x%x Log with uuid %d, ret = 0x%x\n", @@ -2612,7 +2612,7 @@ static bool get_dev_mgmt_log_page_data(struct nvme_transport_handle *hdl, void * /* Ensure size of log data matches length in log header */ *log_data = calloc(length, sizeof(__u8)); if (!*log_data) { - fprintf(stderr, "ERROR: WDC: calloc: %s\n", nvme_strerror(errno)); + fprintf(stderr, "ERROR: WDC: calloc: %s\n", libnvme_strerror(errno)); valid = false; goto end; } @@ -2627,7 +2627,7 @@ static bool get_dev_mgmt_log_page_data(struct nvme_transport_handle *hdl, void * return valid; } -static bool get_dev_mgmt_log_page_lid_data(struct nvme_transport_handle *hdl, +static bool get_dev_mgmt_log_page_lid_data(struct libnvme_transport_handle *hdl, void **cbs_data, __u8 lid, __u8 log_id, @@ -2636,14 +2636,14 @@ static bool get_dev_mgmt_log_page_lid_data(struct nvme_transport_handle *hdl, void *data; struct wdc_c2_log_page_header *hdr_ptr; struct wdc_c2_log_subpage_header *sph; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; __u32 length = 0; int ret = 0; bool found = false; data = (__u8 *)malloc(sizeof(__u8) * WDC_C2_LOG_BUF_LEN); if (!data) { - fprintf(stderr, "ERROR: WDC: malloc: %s\n", nvme_strerror(errno)); + fprintf(stderr, "ERROR: WDC: malloc: %s\n", libnvme_strerror(errno)); return false; } @@ -2655,7 +2655,7 @@ static bool get_dev_mgmt_log_page_lid_data(struct nvme_transport_handle *hdl, cmd.cdw14 |= NVME_FIELD_ENCODE(uuid_ix, NVME_LOG_CDW14_UUID_SHIFT, NVME_LOG_CDW14_UUID_MASK); - ret = nvme_get_log(hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); + ret = libnvme_get_log(hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); if (ret) { fprintf(stderr, "ERROR: WDC: Unable to get 0x%x Log Page length with uuid %d, ret = 0x%x\n", @@ -2671,7 +2671,7 @@ static bool get_dev_mgmt_log_page_lid_data(struct nvme_transport_handle *hdl, free(data); data = calloc(length, sizeof(__u8)); if (!data) { - fprintf(stderr, "ERROR: WDC: malloc: %s\n", nvme_strerror(errno)); + fprintf(stderr, "ERROR: WDC: malloc: %s\n", libnvme_strerror(errno)); goto end; } @@ -2681,7 +2681,7 @@ static bool get_dev_mgmt_log_page_lid_data(struct nvme_transport_handle *hdl, cmd.cdw14 |= NVME_FIELD_ENCODE(uuid_ix, NVME_LOG_CDW14_UUID_SHIFT, NVME_LOG_CDW14_UUID_MASK); - ret = nvme_get_log(hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); + ret = libnvme_get_log(hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); if (ret) { fprintf(stderr, "ERROR: WDC: Unable to read 0x%x Log Page data with uuid %d, ret = 0x%x\n", @@ -2698,7 +2698,7 @@ static bool get_dev_mgmt_log_page_lid_data(struct nvme_transport_handle *hdl, if (found) { *cbs_data = calloc(le32_to_cpu(sph->length), sizeof(__u8)); if (!*cbs_data) { - fprintf(stderr, "ERROR: WDC: calloc: %s\n", nvme_strerror(errno)); + fprintf(stderr, "ERROR: WDC: calloc: %s\n", libnvme_strerror(errno)); found = false; goto end; } @@ -2713,7 +2713,7 @@ static bool get_dev_mgmt_log_page_lid_data(struct nvme_transport_handle *hdl, return found; } -static bool get_dev_mgment_data(struct nvme_global_ctx *ctx, struct nvme_transport_handle *hdl, +static bool get_dev_mgment_data(struct libnvme_global_ctx *ctx, struct libnvme_transport_handle *hdl, void **data) { bool found = false; @@ -2734,15 +2734,15 @@ static bool get_dev_mgment_data(struct nvme_global_ctx *ctx, struct nvme_transpo memset(&uuid_list, 0, sizeof(struct nvme_id_uuid_list)); if (wdc_CheckUuidListSupport(hdl, &uuid_list)) { /* check for the Sandisk UUID first */ - uuid_index = nvme_find_uuid(&uuid_list, SNDK_UUID); + uuid_index = libnvme_find_uuid(&uuid_list, SNDK_UUID); if (uuid_index < 0) { /* The Sandisk UUID is not found; * check for the WDC UUID second. */ - uuid_index = nvme_find_uuid(&uuid_list, WDC_UUID); + uuid_index = libnvme_find_uuid(&uuid_list, WDC_UUID); if (uuid_index < 0) - uuid_index = nvme_find_uuid(&uuid_list, WDC_UUID_SN640_3); + uuid_index = libnvme_find_uuid(&uuid_list, WDC_UUID_SN640_3); } if (uuid_index >= 0) @@ -2779,7 +2779,7 @@ static bool get_dev_mgment_data(struct nvme_global_ctx *ctx, struct nvme_transpo return found; } -static bool get_dev_mgment_cbs_data(struct nvme_global_ctx *ctx, struct nvme_transport_handle *hdl, +static bool get_dev_mgment_cbs_data(struct libnvme_global_ctx *ctx, struct libnvme_transport_handle *hdl, __u8 log_id, void **cbs_data) { bool found = false; @@ -2803,15 +2803,15 @@ static bool get_dev_mgment_cbs_data(struct nvme_global_ctx *ctx, struct nvme_tra memset(&uuid_list, 0, sizeof(struct nvme_id_uuid_list)); if (wdc_CheckUuidListSupport(hdl, &uuid_list)) { /* check for the Sandisk UUID first */ - uuid_index = nvme_find_uuid(&uuid_list, SNDK_UUID); + uuid_index = libnvme_find_uuid(&uuid_list, SNDK_UUID); if (uuid_index < 0) { /* The Sandisk UUID is not found; * check for the WDC UUID second. */ - uuid_index = nvme_find_uuid(&uuid_list, WDC_UUID); + uuid_index = libnvme_find_uuid(&uuid_list, WDC_UUID); if (uuid_index < 0) - uuid_index = nvme_find_uuid(&uuid_list, WDC_UUID_SN640_3); + uuid_index = libnvme_find_uuid(&uuid_list, WDC_UUID_SN640_3); } if (uuid_index >= 0) @@ -2848,11 +2848,11 @@ static bool get_dev_mgment_cbs_data(struct nvme_global_ctx *ctx, struct nvme_tra return found; } -static int wdc_get_supported_log_pages(struct nvme_transport_handle *hdl, +static int wdc_get_supported_log_pages(struct libnvme_transport_handle *hdl, struct nvme_supported_log_pages *supported, int uuid_index) { - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; memset(supported, 0, sizeof(*supported)); nvme_init_get_log(&cmd, NVME_NSID_ALL, NVME_LOG_LID_SUPPORTED_LOG_PAGES, @@ -2860,11 +2860,11 @@ static int wdc_get_supported_log_pages(struct nvme_transport_handle *hdl, cmd.cdw14 |= NVME_FIELD_ENCODE(uuid_index, NVME_LOG_CDW14_UUID_SHIFT, NVME_LOG_CDW14_UUID_MASK); - return nvme_get_log(hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); + return libnvme_get_log(hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); } -static bool wdc_nvme_check_supported_log_page(struct nvme_global_ctx *ctx, - struct nvme_transport_handle *hdl, +static bool wdc_nvme_check_supported_log_page(struct libnvme_global_ctx *ctx, + struct libnvme_transport_handle *hdl, __u8 log_id, __u8 uuid_index) { @@ -2969,7 +2969,7 @@ static bool wdc_nvme_parse_dev_status_log_str(void *log_data, return false; } -static bool wdc_nvme_get_dev_status_log_data(struct nvme_global_ctx *ctx, struct nvme_transport_handle *hdl, __le32 *ret_data, +static bool wdc_nvme_get_dev_status_log_data(struct libnvme_global_ctx *ctx, struct libnvme_transport_handle *hdl, __le32 *ret_data, __u8 log_id) { __u32 *cbs_data = NULL; @@ -2987,37 +2987,37 @@ static bool wdc_nvme_get_dev_status_log_data(struct nvme_global_ctx *ctx, struct return false; } -static int wdc_do_clear_dump(struct nvme_transport_handle *hdl, __u8 opcode, __u32 cdw12) +static int wdc_do_clear_dump(struct libnvme_transport_handle *hdl, __u8 opcode, __u32 cdw12) { int ret; - struct nvme_passthru_cmd admin_cmd; + struct libnvme_passthru_cmd admin_cmd; - memset(&admin_cmd, 0, sizeof(struct nvme_passthru_cmd)); + memset(&admin_cmd, 0, sizeof(struct libnvme_passthru_cmd)); admin_cmd.opcode = opcode; admin_cmd.cdw12 = cdw12; - ret = nvme_submit_admin_passthru(hdl, &admin_cmd); + ret = libnvme_submit_admin_passthru(hdl, &admin_cmd); if (ret) fprintf(stdout, "ERROR: WDC: Crash dump erase failed\n"); nvme_show_status(ret); return ret; } -static __u32 wdc_dump_length(struct nvme_transport_handle *link, __u32 opcode, __u32 cdw10, __u32 cdw12, __u32 *dump_length) +static __u32 wdc_dump_length(struct libnvme_transport_handle *link, __u32 opcode, __u32 cdw10, __u32 cdw12, __u32 *dump_length) { int ret; __u8 buf[WDC_NVME_LOG_SIZE_DATA_LEN] = {0}; struct wdc_log_size *l; - struct nvme_passthru_cmd admin_cmd; + struct libnvme_passthru_cmd admin_cmd; l = (struct wdc_log_size *) buf; - memset(&admin_cmd, 0, sizeof(struct nvme_passthru_cmd)); + memset(&admin_cmd, 0, sizeof(struct libnvme_passthru_cmd)); admin_cmd.opcode = opcode; admin_cmd.addr = (__u64)(uintptr_t)buf; admin_cmd.data_len = WDC_NVME_LOG_SIZE_DATA_LEN; admin_cmd.cdw10 = cdw10; admin_cmd.cdw12 = cdw12; - ret = nvme_submit_admin_passthru(link, &admin_cmd); + ret = libnvme_submit_admin_passthru(link, &admin_cmd); if (ret) { l->log_size = 0; ret = -1; @@ -3033,19 +3033,19 @@ static __u32 wdc_dump_length(struct nvme_transport_handle *link, __u32 opcode, _ return ret; } -static __u32 wdc_dump_length_e6(struct nvme_transport_handle *hdl, __u32 opcode, __u32 cdw10, __u32 cdw12, struct wdc_e6_log_hdr *dump_hdr) +static __u32 wdc_dump_length_e6(struct libnvme_transport_handle *hdl, __u32 opcode, __u32 cdw10, __u32 cdw12, struct wdc_e6_log_hdr *dump_hdr) { int ret; - struct nvme_passthru_cmd admin_cmd; + struct libnvme_passthru_cmd admin_cmd; - memset(&admin_cmd, 0, sizeof(struct nvme_passthru_cmd)); + memset(&admin_cmd, 0, sizeof(struct libnvme_passthru_cmd)); admin_cmd.opcode = opcode; admin_cmd.addr = (__u64)(uintptr_t)dump_hdr; admin_cmd.data_len = WDC_NVME_LOG_SIZE_HDR_LEN; admin_cmd.cdw10 = cdw10; admin_cmd.cdw12 = cdw12; - ret = nvme_submit_admin_passthru(hdl, &admin_cmd); + ret = libnvme_submit_admin_passthru(hdl, &admin_cmd); if (ret) { fprintf(stderr, "ERROR: WDC: reading dump length failed\n"); nvme_show_status(ret); @@ -3054,12 +3054,12 @@ static __u32 wdc_dump_length_e6(struct nvme_transport_handle *hdl, __u32 opcode, return ret; } -static __u32 wdc_dump_dui_data(struct nvme_transport_handle *hdl, __u32 dataLen, __u32 offset, __u8 *dump_data, bool last_xfer) +static __u32 wdc_dump_dui_data(struct libnvme_transport_handle *hdl, __u32 dataLen, __u32 offset, __u8 *dump_data, bool last_xfer) { int ret; - struct nvme_passthru_cmd admin_cmd; + struct libnvme_passthru_cmd admin_cmd; - memset(&admin_cmd, 0, sizeof(struct nvme_passthru_cmd)); + memset(&admin_cmd, 0, sizeof(struct libnvme_passthru_cmd)); admin_cmd.opcode = WDC_NVME_CAP_DUI_OPCODE; admin_cmd.nsid = 0xFFFFFFFF; admin_cmd.addr = (__u64)(uintptr_t)dump_data; @@ -3072,7 +3072,7 @@ static __u32 wdc_dump_dui_data(struct nvme_transport_handle *hdl, __u32 dataLen, admin_cmd.cdw14 = WDC_NVME_CAP_DUI_DISABLE_IO; - ret = nvme_submit_admin_passthru(hdl, &admin_cmd); + ret = libnvme_submit_admin_passthru(hdl, &admin_cmd); if (ret) { fprintf(stderr, "ERROR: WDC: reading DUI data failed\n"); nvme_show_status(ret); @@ -3081,13 +3081,13 @@ static __u32 wdc_dump_dui_data(struct nvme_transport_handle *hdl, __u32 dataLen, return ret; } -static __u32 wdc_dump_dui_data_v2(struct nvme_transport_handle *hdl, __u32 dataLen, __u64 offset, __u8 *dump_data, bool last_xfer) +static __u32 wdc_dump_dui_data_v2(struct libnvme_transport_handle *hdl, __u32 dataLen, __u64 offset, __u8 *dump_data, bool last_xfer) { int ret; - struct nvme_passthru_cmd admin_cmd; + struct libnvme_passthru_cmd admin_cmd; __u64 offset_lo, offset_hi; - memset(&admin_cmd, 0, sizeof(struct nvme_passthru_cmd)); + memset(&admin_cmd, 0, sizeof(struct libnvme_passthru_cmd)); admin_cmd.opcode = WDC_NVME_CAP_DUI_OPCODE; admin_cmd.nsid = 0xFFFFFFFF; admin_cmd.addr = (__u64)(uintptr_t)dump_data; @@ -3103,7 +3103,7 @@ static __u32 wdc_dump_dui_data_v2(struct nvme_transport_handle *hdl, __u32 dataL else admin_cmd.cdw14 = WDC_NVME_CAP_DUI_DISABLE_IO; - ret = nvme_submit_admin_passthru(hdl, &admin_cmd); + ret = libnvme_submit_admin_passthru(hdl, &admin_cmd); if (ret) { fprintf(stderr, "ERROR: WDC: reading DUI data V2 failed\n"); nvme_show_status(ret); @@ -3112,23 +3112,23 @@ static __u32 wdc_dump_dui_data_v2(struct nvme_transport_handle *hdl, __u32 dataL return ret; } -static int wdc_do_dump(struct nvme_transport_handle *hdl, __u32 opcode, __u32 data_len, +static int wdc_do_dump(struct libnvme_transport_handle *hdl, __u32 opcode, __u32 data_len, __u32 cdw12, const char *file, __u32 xfer_size) { int ret = 0; __u8 *dump_data; __u32 curr_data_offset, curr_data_len; int i; - struct nvme_passthru_cmd admin_cmd; + struct libnvme_passthru_cmd admin_cmd; __u32 dump_length = data_len; dump_data = (__u8 *)malloc(sizeof(__u8) * dump_length); if (!dump_data) { - fprintf(stderr, "%s: ERROR: malloc: %s\n", __func__, nvme_strerror(errno)); + fprintf(stderr, "%s: ERROR: malloc: %s\n", __func__, libnvme_strerror(errno)); return -1; } memset(dump_data, 0, sizeof(__u8) * dump_length); - memset(&admin_cmd, 0, sizeof(struct nvme_passthru_cmd)); + memset(&admin_cmd, 0, sizeof(struct libnvme_passthru_cmd)); curr_data_offset = 0; curr_data_len = xfer_size; i = 0; @@ -3141,7 +3141,7 @@ static int wdc_do_dump(struct nvme_transport_handle *hdl, __u32 opcode, __u32 da admin_cmd.cdw13 = curr_data_offset; while (curr_data_offset < data_len) { - ret = nvme_submit_admin_passthru(hdl, &admin_cmd); + ret = libnvme_submit_admin_passthru(hdl, &admin_cmd); if (ret) { nvme_show_status(ret); fprintf(stderr, "%s: ERROR: WDC: Get chunk %d, size = 0x%x, offset = 0x%x, addr = 0x%lx\n", @@ -3170,14 +3170,14 @@ static int wdc_do_dump(struct nvme_transport_handle *hdl, __u32 opcode, __u32 da return ret; } -static int wdc_do_dump_e6(struct nvme_transport_handle *hdl, __u32 opcode, __u32 data_len, +static int wdc_do_dump_e6(struct libnvme_transport_handle *hdl, __u32 opcode, __u32 data_len, __u32 cdw12, char *file, __u32 xfer_size, __u8 *log_hdr) { int ret = 0; __u8 *dump_data; __u32 curr_data_offset, log_size; int i; - struct nvme_passthru_cmd admin_cmd; + struct libnvme_passthru_cmd admin_cmd; /* if data_len is not 4 byte aligned */ if (data_len & 0x00000003) { @@ -3192,11 +3192,11 @@ static int wdc_do_dump_e6(struct nvme_transport_handle *hdl, __u32 opcode, __u32 dump_data = (__u8 *)malloc(sizeof(__u8) * data_len); if (!dump_data) { - fprintf(stderr, "%s: ERROR: malloc: %s\n", __func__, nvme_strerror(errno)); + fprintf(stderr, "%s: ERROR: malloc: %s\n", __func__, libnvme_strerror(errno)); return -1; } memset(dump_data, 0, sizeof(__u8) * data_len); - memset(&admin_cmd, 0, sizeof(struct nvme_passthru_cmd)); + memset(&admin_cmd, 0, sizeof(struct libnvme_passthru_cmd)); curr_data_offset = WDC_NVME_LOG_SIZE_HDR_LEN; i = 0; @@ -3216,7 +3216,7 @@ static int wdc_do_dump_e6(struct nvme_transport_handle *hdl, __u32 opcode, __u32 admin_cmd.cdw10 = xfer_size >> 2; admin_cmd.cdw13 = curr_data_offset >> 2; - ret = nvme_submit_admin_passthru(hdl, &admin_cmd); + ret = libnvme_submit_admin_passthru(hdl, &admin_cmd); if (ret) { nvme_show_status(ret); fprintf(stderr, "%s: ERROR: WDC: Get chunk %d, size = 0x%x, offset = 0x%x, addr = 0x%lx\n", @@ -3245,8 +3245,8 @@ static int wdc_do_dump_e6(struct nvme_transport_handle *hdl, __u32 opcode, __u32 return ret; } -static int wdc_do_cap_telemetry_log(struct nvme_global_ctx *ctx, - struct nvme_transport_handle *hdl, const char *file, +static int wdc_do_cap_telemetry_log(struct libnvme_global_ctx *ctx, + struct libnvme_transport_handle *hdl, const char *file, __u32 bs, int type, int data_area) { struct nvme_telemetry_log *log; @@ -3273,7 +3273,7 @@ static int wdc_do_cap_telemetry_log(struct nvme_global_ctx *ctx, return -EINVAL; } - err = nvme_scan_topology(ctx, NULL, NULL); + err = libnvme_scan_topology(ctx, NULL, NULL); if (err) { fprintf(stderr, "Failed to scan nvme subsystems\n"); return err; @@ -3322,18 +3322,18 @@ static int wdc_do_cap_telemetry_log(struct nvme_global_ctx *ctx, output = open(file, O_WRONLY | O_CREAT | O_TRUNC, 0666); if (output < 0) { fprintf(stderr, "%s: Failed to open output file %s: %s!\n", - __func__, file, nvme_strerror(errno)); + __func__, file, libnvme_strerror(errno)); return output; } if (ctrl_init) - err = nvme_get_ctrl_telemetry(hdl, true, &log, + err = libnvme_get_ctrl_telemetry(hdl, true, &log, data_area, &full_size); else if (host_gen) - err = nvme_get_new_host_telemetry(hdl, &log, + err = libnvme_get_new_host_telemetry(hdl, &log, data_area, &full_size); else - err = nvme_get_host_telemetry(hdl, &log, data_area, + err = libnvme_get_host_telemetry(hdl, &log, data_area, &full_size); if (err < 0) { @@ -3371,7 +3371,7 @@ static int wdc_do_cap_telemetry_log(struct nvme_global_ctx *ctx, } if (fsync(output) < 0) { - fprintf(stderr, "ERROR: %s: fsync: %s\n", __func__, nvme_strerror(errno)); + fprintf(stderr, "ERROR: %s: fsync: %s\n", __func__, libnvme_strerror(errno)); err = -1; } @@ -3381,7 +3381,7 @@ static int wdc_do_cap_telemetry_log(struct nvme_global_ctx *ctx, return err; } -static int wdc_do_cap_diag(struct nvme_global_ctx *ctx, struct nvme_transport_handle *hdl, char *file, +static int wdc_do_cap_diag(struct libnvme_global_ctx *ctx, struct libnvme_transport_handle *hdl, char *file, __u32 xfer_size, int type, int data_area) { int ret = -1; @@ -3391,7 +3391,7 @@ static int wdc_do_cap_diag(struct nvme_global_ctx *ctx, struct nvme_transport_ha log_hdr = (struct wdc_e6_log_hdr *)malloc(e6_log_hdr_size); if (!log_hdr) { - fprintf(stderr, "%s: ERROR: malloc: %s\n", __func__, nvme_strerror(errno)); + fprintf(stderr, "%s: ERROR: malloc: %s\n", __func__, libnvme_strerror(errno)); ret = -1; goto out; } @@ -3443,7 +3443,7 @@ static int wdc_do_cap_diag(struct nvme_global_ctx *ctx, struct nvme_transport_ha return ret; } -static int wdc_do_cap_dui_v1(struct nvme_transport_handle *hdl, char *file, __u32 xfer_size, int data_area, int verbose, +static int wdc_do_cap_dui_v1(struct libnvme_transport_handle *hdl, char *file, __u32 xfer_size, int data_area, int verbose, struct wdc_dui_log_hdr *log_hdr, __s64 *total_size) { __s32 log_size = 0; @@ -3492,7 +3492,7 @@ static int wdc_do_cap_dui_v1(struct nvme_transport_handle *hdl, char *file, __u3 dump_data = (__u8 *)malloc(sizeof(__u8) * xfer_size); if (!dump_data) { fprintf(stderr, "%s: ERROR: dump data V1 malloc failed : status %s, size = 0x%x\n", - __func__, nvme_strerror(errno), (unsigned int)xfer_size); + __func__, libnvme_strerror(errno), (unsigned int)xfer_size); return -1; } memset(dump_data, 0, sizeof(__u8) * xfer_size); @@ -3500,7 +3500,7 @@ static int wdc_do_cap_dui_v1(struct nvme_transport_handle *hdl, char *file, __u3 output = open(file, O_WRONLY | O_CREAT | O_TRUNC, 0666); if (output < 0) { fprintf(stderr, "%s: Failed to open output file %s: %s!\n", __func__, file, - nvme_strerror(errno)); + libnvme_strerror(errno)); free(dump_data); return output; } @@ -3553,7 +3553,7 @@ static int wdc_do_cap_dui_v1(struct nvme_transport_handle *hdl, char *file, __u3 return ret; } -static int wdc_do_cap_dui_v2_v3(struct nvme_transport_handle *hdl, char *file, __u32 xfer_size, int data_area, int verbose, +static int wdc_do_cap_dui_v2_v3(struct libnvme_transport_handle *hdl, char *file, __u32 xfer_size, int data_area, int verbose, struct wdc_dui_log_hdr *log_hdr, __s64 *total_size, __u64 file_size, __u64 offset) { @@ -3626,7 +3626,7 @@ static int wdc_do_cap_dui_v2_v3(struct nvme_transport_handle *hdl, char *file, _ if (!dump_data) { fprintf(stderr, "%s: ERROR: dump data v3 malloc failed : status %s, size = 0x%"PRIx64"\n", - __func__, nvme_strerror(errno), (uint64_t)xfer_size_long); + __func__, libnvme_strerror(errno), (uint64_t)xfer_size_long); return -1; } memset(dump_data, 0, sizeof(__u8) * xfer_size_long); @@ -3634,7 +3634,7 @@ static int wdc_do_cap_dui_v2_v3(struct nvme_transport_handle *hdl, char *file, _ output = open(file, O_WRONLY | O_CREAT | O_TRUNC, 0666); if (output < 0) { fprintf(stderr, "%s: Failed to open output file %s: %s!\n", - __func__, file, nvme_strerror(errno)); + __func__, file, libnvme_strerror(errno)); free(dump_data); return output; } @@ -3698,7 +3698,7 @@ static int wdc_do_cap_dui_v2_v3(struct nvme_transport_handle *hdl, char *file, _ return ret; } -static int wdc_do_cap_dui_v4(struct nvme_transport_handle *hdl, char *file, __u32 xfer_size, int data_area, int verbose, +static int wdc_do_cap_dui_v4(struct libnvme_transport_handle *hdl, char *file, __u32 xfer_size, int data_area, int verbose, struct wdc_dui_log_hdr *log_hdr, __s64 *total_size, __u64 file_size, __u64 offset) { @@ -3767,7 +3767,7 @@ static int wdc_do_cap_dui_v4(struct nvme_transport_handle *hdl, char *file, __u3 dump_data = (__u8 *)malloc(sizeof(__u8) * xfer_size_long); if (!dump_data) { fprintf(stderr, "%s: ERROR: dump data V4 malloc failed : status %s, size = 0x%x\n", - __func__, nvme_strerror(errno), (unsigned int)xfer_size_long); + __func__, libnvme_strerror(errno), (unsigned int)xfer_size_long); return -1; } memset(dump_data, 0, sizeof(__u8) * xfer_size_long); @@ -3775,7 +3775,7 @@ static int wdc_do_cap_dui_v4(struct nvme_transport_handle *hdl, char *file, __u3 output = open(file, O_WRONLY | O_CREAT | O_TRUNC, 0666); if (output < 0) { fprintf(stderr, "%s: Failed to open output file %s: %s!\n", __func__, file, - nvme_strerror(errno)); + libnvme_strerror(errno)); free(dump_data); return output; } @@ -3838,7 +3838,7 @@ static int wdc_do_cap_dui_v4(struct nvme_transport_handle *hdl, char *file, __u3 return ret; } -static int wdc_do_cap_dui(struct nvme_transport_handle *hdl, char *file, __u32 xfer_size, int data_area, int verbose, +static int wdc_do_cap_dui(struct libnvme_transport_handle *hdl, char *file, __u32 xfer_size, int data_area, int verbose, __u64 file_size, __u64 offset) { int ret = 0; @@ -3850,7 +3850,7 @@ static int wdc_do_cap_dui(struct nvme_transport_handle *hdl, char *file, __u32 x log_hdr = (struct wdc_dui_log_hdr *)malloc(dui_log_hdr_size); if (!log_hdr) { fprintf(stderr, "%s: ERROR: log header malloc failed : status %s, size 0x%x\n", - __func__, nvme_strerror(errno), dui_log_hdr_size); + __func__, libnvme_strerror(errno), dui_log_hdr_size); return -1; } memset(log_hdr, 0, dui_log_hdr_size); @@ -3901,8 +3901,8 @@ static int wdc_do_cap_dui(struct nvme_transport_handle *hdl, char *file, __u32 x static int wdc_cap_diag(int argc, char **argv, struct command *acmd, struct plugin *plugin) { - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; const char *desc = "Capture Diagnostics Log."; const char *file = "Output file pathname."; const char *size = "Data retrieval transfer size."; @@ -3929,7 +3929,7 @@ static int wdc_cap_diag(int argc, char **argv, struct command *acmd, if (ret) return ret; - ret = nvme_scan_topology(ctx, NULL, NULL); + ret = libnvme_scan_topology(ctx, NULL, NULL); if (ret) return ret; @@ -3958,19 +3958,19 @@ static int wdc_cap_diag(int argc, char **argv, struct command *acmd, return ret; } -static int wdc_do_get_sn730_log_len(struct nvme_transport_handle *hdl, uint32_t *len_buf, uint32_t subopcode) +static int wdc_do_get_sn730_log_len(struct libnvme_transport_handle *hdl, uint32_t *len_buf, uint32_t subopcode) { int ret; uint32_t *output = NULL; - struct nvme_passthru_cmd admin_cmd; + struct libnvme_passthru_cmd admin_cmd; output = (uint32_t *)malloc(sizeof(uint32_t)); if (!output) { - fprintf(stderr, "ERROR: WDC: malloc: %s\n", nvme_strerror(errno)); + fprintf(stderr, "ERROR: WDC: malloc: %s\n", libnvme_strerror(errno)); return -1; } memset(output, 0, sizeof(uint32_t)); - memset(&admin_cmd, 0, sizeof(struct nvme_passthru_cmd)); + memset(&admin_cmd, 0, sizeof(struct libnvme_passthru_cmd)); admin_cmd.data_len = 8; admin_cmd.opcode = SN730_NVME_GET_LOG_OPCODE; @@ -3978,25 +3978,25 @@ static int wdc_do_get_sn730_log_len(struct nvme_transport_handle *hdl, uint32_t admin_cmd.cdw12 = subopcode; admin_cmd.cdw10 = SN730_LOG_CHUNK_SIZE / 4; - ret = nvme_submit_admin_passthru(hdl, &admin_cmd); + ret = libnvme_submit_admin_passthru(hdl, &admin_cmd); if (!ret) *len_buf = *output; free(output); return ret; } -static int wdc_do_get_sn730_log(struct nvme_transport_handle *hdl, void *log_buf, uint32_t offset, uint32_t subopcode) +static int wdc_do_get_sn730_log(struct libnvme_transport_handle *hdl, void *log_buf, uint32_t offset, uint32_t subopcode) { int ret; uint8_t *output = NULL; - struct nvme_passthru_cmd admin_cmd; + struct libnvme_passthru_cmd admin_cmd; output = (uint8_t *)calloc(SN730_LOG_CHUNK_SIZE, sizeof(uint8_t)); if (!output) { - fprintf(stderr, "ERROR: WDC: calloc: %s\n", nvme_strerror(errno)); + fprintf(stderr, "ERROR: WDC: calloc: %s\n", libnvme_strerror(errno)); return -1; } - memset(&admin_cmd, 0, sizeof(struct nvme_passthru_cmd)); + memset(&admin_cmd, 0, sizeof(struct libnvme_passthru_cmd)); admin_cmd.data_len = SN730_LOG_CHUNK_SIZE; admin_cmd.opcode = SN730_NVME_GET_LOG_OPCODE; admin_cmd.addr = (uintptr_t)output; @@ -4004,13 +4004,13 @@ static int wdc_do_get_sn730_log(struct nvme_transport_handle *hdl, void *log_buf admin_cmd.cdw13 = offset; admin_cmd.cdw10 = SN730_LOG_CHUNK_SIZE / 4; - ret = nvme_submit_admin_passthru(hdl, &admin_cmd); + ret = libnvme_submit_admin_passthru(hdl, &admin_cmd); if (!ret) memcpy(log_buf, output, SN730_LOG_CHUNK_SIZE); return ret; } -static int get_sn730_log_chunks(struct nvme_transport_handle *hdl, uint8_t *log_buf, uint32_t log_len, uint32_t subopcode) +static int get_sn730_log_chunks(struct libnvme_transport_handle *hdl, uint8_t *log_buf, uint32_t log_len, uint32_t subopcode) { int ret = 0; uint8_t *chunk_buf = NULL; @@ -4019,7 +4019,7 @@ static int get_sn730_log_chunks(struct nvme_transport_handle *hdl, uint8_t *log_ chunk_buf = (uint8_t *)malloc(sizeof(uint8_t) * SN730_LOG_CHUNK_SIZE); if (!chunk_buf) { - fprintf(stderr, "ERROR: WDC: malloc: %s\n", nvme_strerror(errno)); + fprintf(stderr, "ERROR: WDC: malloc: %s\n", libnvme_strerror(errno)); ret = -1; goto out; } @@ -4046,7 +4046,7 @@ static int get_sn730_log_chunks(struct nvme_transport_handle *hdl, uint8_t *log_ return ret; } -static int wdc_do_sn730_get_and_tar(struct nvme_transport_handle *hdl, char *outputName) +static int wdc_do_sn730_get_and_tar(struct libnvme_transport_handle *hdl, char *outputName) { int ret = 0; void *retPtr; @@ -4062,7 +4062,7 @@ static int wdc_do_sn730_get_and_tar(struct nvme_transport_handle *hdl, char *out tarInfo = (struct tarfile_metadata *)malloc(sizeof(struct tarfile_metadata)); if (!tarInfo) { - fprintf(stderr, "ERROR: WDC: malloc: %s\n", nvme_strerror(errno)); + fprintf(stderr, "ERROR: WDC: malloc: %s\n", libnvme_strerror(errno)); ret = -1; goto free_buf; } @@ -4122,7 +4122,7 @@ static int wdc_do_sn730_get_and_tar(struct nvme_transport_handle *hdl, char *out extended_log_buf = (uint8_t *) calloc(extended_log_len, sizeof(uint8_t)); if (!full_log_buf || !key_log_buf || !core_dump_log_buf || !extended_log_buf) { - fprintf(stderr, "ERROR: WDC: malloc: %s\n", nvme_strerror(errno)); + fprintf(stderr, "ERROR: WDC: malloc: %s\n", libnvme_strerror(errno)); ret = -1; goto free_buf; } @@ -4191,13 +4191,13 @@ static int wdc_do_sn730_get_and_tar(struct nvme_transport_handle *hdl, char *out return ret; } -static int dump_internal_logs(struct nvme_transport_handle *hdl, const char *dir_name, int verbose) +static int dump_internal_logs(struct libnvme_transport_handle *hdl, const char *dir_name, int verbose) { char file_path[PATH_MAX]; void *telemetry_log; const size_t bs = 512; struct nvme_telemetry_log *hdr; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; size_t full_size, offset = bs; int err, output; @@ -4207,7 +4207,7 @@ static int dump_internal_logs(struct nvme_transport_handle *hdl, const char *dir hdr = malloc(bs); telemetry_log = malloc(bs); if (!hdr || !telemetry_log) { - fprintf(stderr, "Failed to allocate %zu bytes for log: %s\n", bs, nvme_strerror(errno)); + fprintf(stderr, "Failed to allocate %zu bytes for log: %s\n", bs, libnvme_strerror(errno)); err = -ENOMEM; goto free_mem; } @@ -4216,7 +4216,7 @@ static int dump_internal_logs(struct nvme_transport_handle *hdl, const char *dir sprintf(file_path, "%s/telemetry.bin", dir_name); output = open(file_path, O_WRONLY | O_CREAT | O_TRUNC, 0666); if (output < 0) { - fprintf(stderr, "Failed to open output file %s: %s!\n", file_path, nvme_strerror(errno)); + fprintf(stderr, "Failed to open output file %s: %s!\n", file_path, libnvme_strerror(errno)); err = output; goto free_mem; } @@ -4226,7 +4226,7 @@ static int dump_internal_logs(struct nvme_transport_handle *hdl, const char *dir cmd.cdw10 |= NVME_FIELD_ENCODE(NVME_LOG_TELEM_HOST_LSP_CREATE, NVME_LOG_CDW10_LSP_SHIFT, NVME_LOG_CDW10_LSP_MASK); - err = nvme_get_log(hdl, &cmd, true, NVME_LOG_PAGE_PDU_SIZE); + err = libnvme_get_log(hdl, &cmd, true, NVME_LOG_PAGE_PDU_SIZE); if (err < 0) perror("get-telemetry-log"); else if (err > 0) { @@ -4247,7 +4247,7 @@ static int dump_internal_logs(struct nvme_transport_handle *hdl, const char *dir nvme_init_get_log(&cmd, NVME_NSID_ALL, NVME_LOG_LID_TELEMETRY_HOST, NVME_CSI_NVM, telemetry_log, bs); nvme_init_get_log_lpo(&cmd, offset); - err = nvme_get_log(hdl, &cmd, true, NVME_LOG_PAGE_PDU_SIZE); + err = libnvme_get_log(hdl, &cmd, true, NVME_LOG_PAGE_PDU_SIZE); if (err < 0) { perror("get-telemetry-log"); break; @@ -4275,7 +4275,7 @@ static int dump_internal_logs(struct nvme_transport_handle *hdl, const char *dir return err; } -static int wdc_get_default_telemetry_da(struct nvme_transport_handle *hdl, +static int wdc_get_default_telemetry_da(struct libnvme_transport_handle *hdl, int *data_area) { struct nvme_id_ctrl ctrl; @@ -4317,8 +4317,8 @@ static int wdc_vs_internal_fw_log(int argc, char **argv, struct command *acmd, char f[PATH_MAX] = {0}; char fb[PATH_MAX/2] = {0}; char fileSuffix[PATH_MAX] = {0}; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; __u32 xfer_size = 0; int telemetry_type = 0, telemetry_data_area = 0; UtilsTimeInfo timeInfo; @@ -4363,7 +4363,7 @@ static int wdc_vs_internal_fw_log(int argc, char **argv, struct command *acmd, if (ret) return ret; - ret = nvme_scan_topology(ctx, NULL, NULL); + ret = libnvme_scan_topology(ctx, NULL, NULL); if (ret || !wdc_check_device(ctx, hdl)) goto out; @@ -4383,7 +4383,7 @@ static int wdc_vs_internal_fw_log(int argc, char **argv, struct command *acmd, /* verify file name and path is valid before getting dump data */ verify_file = open(cfg.file, O_WRONLY | O_CREAT | O_TRUNC, 0666); if (verify_file < 0) { - fprintf(stderr, "ERROR: WDC: open: %s\n", nvme_strerror(errno)); + fprintf(stderr, "ERROR: WDC: open: %s\n", libnvme_strerror(errno)); goto out; } close(verify_file); @@ -4576,7 +4576,7 @@ static int wdc_vs_internal_fw_log(int argc, char **argv, struct command *acmd, return ret; } -static int wdc_do_crash_dump(struct nvme_transport_handle *hdl, char *file, int type) +static int wdc_do_crash_dump(struct libnvme_transport_handle *hdl, char *file, int type) { int ret; __u32 crash_dump_length; @@ -4648,7 +4648,7 @@ static int wdc_do_crash_dump(struct nvme_transport_handle *hdl, char *file, int return ret; } -static int wdc_crash_dump(struct nvme_transport_handle *hdl, const char *file, int type) +static int wdc_crash_dump(struct libnvme_transport_handle *hdl, const char *file, int type) { char f[PATH_MAX] = {0}; const char *dump_type; @@ -4670,12 +4670,12 @@ static int wdc_crash_dump(struct nvme_transport_handle *hdl, const char *file, i return ret; } -static int wdc_do_drive_log(struct nvme_transport_handle *hdl, const char *file) +static int wdc_do_drive_log(struct libnvme_transport_handle *hdl, const char *file) { int ret; __u8 *drive_log_data; __u32 drive_log_length; - struct nvme_passthru_cmd admin_cmd; + struct libnvme_passthru_cmd admin_cmd; ret = wdc_dump_length(hdl, WDC_NVME_DRIVE_LOG_SIZE_OPCODE, WDC_NVME_DRIVE_LOG_SIZE_NDT, @@ -4687,12 +4687,12 @@ static int wdc_do_drive_log(struct nvme_transport_handle *hdl, const char *file) drive_log_data = (__u8 *)malloc(sizeof(__u8) * drive_log_length); if (!drive_log_data) { - fprintf(stderr, "ERROR: WDC: malloc: %s\n", nvme_strerror(errno)); + fprintf(stderr, "ERROR: WDC: malloc: %s\n", libnvme_strerror(errno)); return -1; } memset(drive_log_data, 0, sizeof(__u8) * drive_log_length); - memset(&admin_cmd, 0, sizeof(struct nvme_passthru_cmd)); + memset(&admin_cmd, 0, sizeof(struct libnvme_passthru_cmd)); admin_cmd.opcode = WDC_NVME_DRIVE_LOG_OPCODE; admin_cmd.addr = (__u64)(uintptr_t)drive_log_data; admin_cmd.data_len = drive_log_length; @@ -4700,7 +4700,7 @@ static int wdc_do_drive_log(struct nvme_transport_handle *hdl, const char *file) admin_cmd.cdw12 = ((WDC_NVME_DRIVE_LOG_SUBCMD << WDC_NVME_SUBCMD_SHIFT) | WDC_NVME_DRIVE_LOG_SIZE_CMD); - ret = nvme_submit_admin_passthru(hdl, &admin_cmd); + ret = libnvme_submit_admin_passthru(hdl, &admin_cmd); nvme_show_status(ret); if (!ret) ret = wdc_create_log_file(file, drive_log_data, drive_log_length); @@ -4713,8 +4713,8 @@ static int wdc_drive_log(int argc, char **argv, struct command *acmd, { const char *desc = "Capture Drive Log."; const char *file = "Output file pathname."; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; char f[PATH_MAX] = {0}; int ret; __u64 capabilities = 0; @@ -4733,7 +4733,7 @@ static int wdc_drive_log(int argc, char **argv, struct command *acmd, if (ret) return ret; - ret = nvme_scan_topology(ctx, NULL, NULL); + ret = libnvme_scan_topology(ctx, NULL, NULL); if (ret || !wdc_check_device(ctx, hdl)) return ret; @@ -4760,8 +4760,8 @@ static int wdc_get_crash_dump(int argc, char **argv, struct command *acmd, const char *desc = "Get Crash Dump."; const char *file = "Output file pathname."; __u64 capabilities = 0; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; int ret; struct config { @@ -4779,7 +4779,7 @@ static int wdc_get_crash_dump(int argc, char **argv, struct command *acmd, if (ret) return ret; - ret = nvme_scan_topology(ctx, NULL, NULL); + ret = libnvme_scan_topology(ctx, NULL, NULL); if (ret || !wdc_check_device(ctx, hdl)) return ret; @@ -4801,8 +4801,8 @@ static int wdc_get_pfail_dump(int argc, char **argv, struct command *acmd, { const char *desc = "Get Pfail Crash Dump."; const char *file = "Output file pathname."; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; __u64 capabilities = 0; struct config { char *file; @@ -4820,7 +4820,7 @@ static int wdc_get_pfail_dump(int argc, char **argv, struct command *acmd, if (ret) return ret; - ret = nvme_scan_topology(ctx, NULL, NULL); + ret = libnvme_scan_topology(ctx, NULL, NULL); if (ret || !wdc_check_device(ctx, hdl)) return ret; @@ -4886,9 +4886,9 @@ static int wdc_purge(int argc, char **argv, struct command *command, struct plugin *plugin) { const char *desc = "Send a Purge command."; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; - struct nvme_passthru_cmd admin_cmd; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; + struct libnvme_passthru_cmd admin_cmd; __u64 capabilities = 0; char *err_str; int ret; @@ -4899,7 +4899,7 @@ static int wdc_purge(int argc, char **argv, if (ret) return ret; - ret = nvme_scan_topology(ctx, NULL, NULL); + ret = libnvme_scan_topology(ctx, NULL, NULL); if (ret || !wdc_check_device(ctx, hdl)) return ret; @@ -4912,7 +4912,7 @@ static int wdc_purge(int argc, char **argv, memset(&admin_cmd, 0, sizeof(admin_cmd)); admin_cmd.opcode = WDC_NVME_PURGE_CMD_OPCODE; - ret = nvme_submit_admin_passthru(hdl, &admin_cmd); + ret = libnvme_submit_admin_passthru(hdl, &admin_cmd); if (ret > 0) { switch (ret) { case WDC_NVME_PURGE_CMD_SEQ_ERR: @@ -4937,10 +4937,10 @@ static int wdc_purge_monitor(int argc, char **argv, { const char *desc = "Send a Purge Monitor command."; __u8 output[WDC_NVME_PURGE_MONITOR_DATA_LEN]; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; double progress_percent; - struct nvme_passthru_cmd admin_cmd; + struct libnvme_passthru_cmd admin_cmd; struct wdc_nvme_purge_monitor_data *mon; __u64 capabilities; int ret; @@ -4951,7 +4951,7 @@ static int wdc_purge_monitor(int argc, char **argv, if (ret) return ret; - ret = nvme_scan_topology(ctx, NULL, NULL); + ret = libnvme_scan_topology(ctx, NULL, NULL); if (ret || !wdc_check_device(ctx, hdl)) return ret; @@ -4961,14 +4961,14 @@ static int wdc_purge_monitor(int argc, char **argv, fprintf(stderr, "ERROR: WDC: unsupported device for this command\n"); } else { memset(output, 0, sizeof(output)); - memset(&admin_cmd, 0, sizeof(struct nvme_passthru_cmd)); + memset(&admin_cmd, 0, sizeof(struct libnvme_passthru_cmd)); admin_cmd.opcode = WDC_NVME_PURGE_MONITOR_OPCODE; admin_cmd.addr = (__u64)(uintptr_t)output; admin_cmd.data_len = WDC_NVME_PURGE_MONITOR_DATA_LEN; admin_cmd.cdw10 = WDC_NVME_PURGE_MONITOR_CMD_CDW10; admin_cmd.timeout_ms = WDC_NVME_PURGE_MONITOR_TIMEOUT; - ret = nvme_submit_admin_passthru(hdl, &admin_cmd); + ret = libnvme_submit_admin_passthru(hdl, &admin_cmd); if (!ret) { mon = (struct wdc_nvme_purge_monitor_data *) output; printf("Purge state = 0x%0"PRIx64"\n", @@ -5116,11 +5116,11 @@ static int wdc_print_log(struct wdc_ssd_perf_stats *perf, int fmt) return 0; } -static int wdc_print_latency_monitor_log_normal(struct nvme_transport_handle *hdl, +static int wdc_print_latency_monitor_log_normal(struct libnvme_transport_handle *hdl, struct wdc_ssd_latency_monitor_log *log_data) { printf("Latency Monitor/C3 Log Page Data\n"); - printf(" Controller : %s\n", nvme_transport_handle_get_name(hdl)); + printf(" Controller : %s\n", libnvme_transport_handle_get_name(hdl)); int err = -1, i, j; struct nvme_id_ctrl ctrl; char ts_buf[128]; @@ -5601,7 +5601,7 @@ static void wdc_print_fb_ca_log_json(struct wdc_ssd_ca_perf_stats *perf) json_free_object(root); } -static void wdc_print_bd_ca_log_normal(struct nvme_transport_handle *hdl, void *data) +static void wdc_print_bd_ca_log_normal(struct libnvme_transport_handle *hdl, void *data) { struct wdc_bd_ca_log_format *bd_data = (struct wdc_bd_ca_log_format *)data; __u64 *raw; @@ -5620,7 +5620,7 @@ static void wdc_print_bd_ca_log_normal(struct nvme_transport_handle *hdl, void * switch (bd_data->field_id) { case 0x0: printf("Additional Smart Log for NVME device:%s namespace-id:%x\n", - nvme_transport_handle_get_name(hdl), WDC_DE_GLOBAL_NSID); + libnvme_transport_handle_get_name(hdl), WDC_DE_GLOBAL_NSID); printf("key normalized raw\n"); printf("program_fail_count : %3"PRIu8"%% %"PRIu64"\n", bd_data->normalized_value, (uint64_t)rawSwapped); @@ -6314,24 +6314,24 @@ static void wdc_print_fw_act_history_log_json(__u8 *data, int num_entries, json_free_object(root); } -static int nvme_get_print_ocp_cloud_smart_log(struct nvme_transport_handle *hdl, +static int nvme_get_print_ocp_cloud_smart_log(struct libnvme_transport_handle *hdl, int uuid_index, __u32 namespace_id, int fmt) { __u32 length = WDC_NVME_SMART_CLOUD_ATTR_LEN; struct ocp_cloud_smart_log *log_ptr = NULL; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int ret, i; log_ptr = (struct ocp_cloud_smart_log *)malloc(sizeof(__u8) * length); if (!log_ptr) { - fprintf(stderr, "ERROR: WDC: malloc: %s\n", nvme_strerror(errno)); + fprintf(stderr, "ERROR: WDC: malloc: %s\n", libnvme_strerror(errno)); return -1; } if (namespace_id == NVME_NSID_ALL) { - ret = nvme_get_nsid(hdl, &namespace_id); + ret = libnvme_get_nsid(hdl, &namespace_id); if (ret < 0) namespace_id = NVME_NSID_ALL; } @@ -6343,7 +6343,7 @@ static int nvme_get_print_ocp_cloud_smart_log(struct nvme_transport_handle *hdl, cmd.cdw14 |= NVME_FIELD_ENCODE(uuid_index, NVME_LOG_CDW14_UUID_SHIFT, NVME_LOG_CDW14_UUID_MASK); - ret = nvme_get_log(hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); + ret = libnvme_get_log(hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); if (fmt == JSON) nvme_show_status(ret); @@ -6379,24 +6379,24 @@ static int nvme_get_print_ocp_cloud_smart_log(struct nvme_transport_handle *hdl, return ret; } -static int nvme_get_print_c0_eol_log(struct nvme_transport_handle *hdl, +static int nvme_get_print_c0_eol_log(struct libnvme_transport_handle *hdl, int uuid_index, __u32 namespace_id, int fmt) { __u32 length = WDC_NVME_EOL_STATUS_LOG_LEN; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; void *log_ptr = NULL; int ret; log_ptr = (void *)malloc(sizeof(__u8) * length); if (!log_ptr) { - fprintf(stderr, "ERROR: WDC: malloc: %s\n", nvme_strerror(errno)); + fprintf(stderr, "ERROR: WDC: malloc: %s\n", libnvme_strerror(errno)); return -1; } if (namespace_id == NVME_NSID_ALL) { - ret = nvme_get_nsid(hdl, &namespace_id); + ret = libnvme_get_nsid(hdl, &namespace_id); if (ret < 0) namespace_id = NVME_NSID_ALL; } @@ -6408,7 +6408,7 @@ static int nvme_get_print_c0_eol_log(struct nvme_transport_handle *hdl, cmd.cdw14 |= NVME_FIELD_ENCODE(uuid_index, NVME_LOG_CDW14_UUID_SHIFT, NVME_LOG_CDW14_UUID_MASK); - ret = nvme_get_log(hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); + ret = libnvme_get_log(hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); if (fmt == JSON) nvme_show_status(ret); @@ -6425,15 +6425,15 @@ static int nvme_get_print_c0_eol_log(struct nvme_transport_handle *hdl, return ret; } -static int nvme_get_ext_smart_cloud_log(struct nvme_transport_handle *hdl, __u8 **data, int uuid_index, __u32 namespace_id) +static int nvme_get_ext_smart_cloud_log(struct libnvme_transport_handle *hdl, __u8 **data, int uuid_index, __u32 namespace_id) { - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; __u8 *log_ptr = NULL; int ret, i; log_ptr = (__u8 *)malloc(sizeof(__u8) * WDC_NVME_SMART_CLOUD_ATTR_LEN); if (!log_ptr) { - fprintf(stderr, "ERROR: WDC: malloc: %s\n", nvme_strerror(errno)); + fprintf(stderr, "ERROR: WDC: malloc: %s\n", libnvme_strerror(errno)); return -1; } @@ -6444,7 +6444,7 @@ static int nvme_get_ext_smart_cloud_log(struct nvme_transport_handle *hdl, __u8 cmd.cdw14 |= NVME_FIELD_ENCODE(uuid_index, NVME_LOG_CDW14_UUID_SHIFT, NVME_LOG_CDW14_UUID_MASK); - ret = nvme_get_log(hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); + ret = libnvme_get_log(hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); if (!ret) { /* Verify GUID matches */ for (i = 0; i < WDC_C0_GUID_LENGTH; i++) { @@ -6472,15 +6472,15 @@ static int nvme_get_ext_smart_cloud_log(struct nvme_transport_handle *hdl, __u8 } -static int nvme_get_hw_rev_log(struct nvme_transport_handle *hdl, __u8 **data, int uuid_index, __u32 namespace_id) +static int nvme_get_hw_rev_log(struct libnvme_transport_handle *hdl, __u8 **data, int uuid_index, __u32 namespace_id) { struct wdc_nvme_hw_rev_log *log_ptr = NULL; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; int ret, i; log_ptr = (struct wdc_nvme_hw_rev_log *)malloc(sizeof(__u8) * WDC_NVME_HW_REV_LOG_PAGE_LEN); if (!log_ptr) { - fprintf(stderr, "ERROR: WDC: malloc: %s\n", nvme_strerror(errno)); + fprintf(stderr, "ERROR: WDC: malloc: %s\n", libnvme_strerror(errno)); return -1; } @@ -6491,7 +6491,7 @@ static int nvme_get_hw_rev_log(struct nvme_transport_handle *hdl, __u8 **data, i cmd.cdw14 |= NVME_FIELD_ENCODE(uuid_index, NVME_LOG_CDW14_UUID_SHIFT, NVME_LOG_CDW14_UUID_MASK); - ret = nvme_get_log(hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); + ret = libnvme_get_log(hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); if (!ret) { /* Verify GUID matches */ for (i = 0; i < WDC_NVME_C6_GUID_LENGTH; i++) { @@ -7153,7 +7153,7 @@ static int wdc_print_ext_smart_cloud_log(void *data, int fmt) static int wdc_print_c0_cloud_attr_log(void *data, int fmt, - struct nvme_transport_handle *hdl) + struct libnvme_transport_handle *hdl) { struct ocp_cloud_smart_log *log = (struct ocp_cloud_smart_log *)data; @@ -7196,7 +7196,7 @@ static int wdc_print_c0_eol_log(void *data, int fmt) return 0; } -static int wdc_get_c0_log_page_sn_customer_id_0x100X(struct nvme_transport_handle *hdl, int uuid_index, +static int wdc_get_c0_log_page_sn_customer_id_0x100X(struct libnvme_transport_handle *hdl, int uuid_index, char *format, __u32 namespace_id, int fmt) { int ret; @@ -7219,7 +7219,7 @@ static int wdc_get_c0_log_page_sn_customer_id_0x100X(struct nvme_transport_handl return ret; } -static int wdc_get_c0_log_page_sn(struct nvme_global_ctx *ctx, struct nvme_transport_handle *hdl, int uuid_index, char *format, +static int wdc_get_c0_log_page_sn(struct libnvme_global_ctx *ctx, struct libnvme_transport_handle *hdl, int uuid_index, char *format, __u32 namespace_id, int fmt) { int ret = 0; @@ -7245,7 +7245,7 @@ static int wdc_get_c0_log_page_sn(struct nvme_global_ctx *ctx, struct nvme_trans return ret; } -static int wdc_get_c0_log_page(struct nvme_global_ctx *ctx, struct nvme_transport_handle *hdl, char *format, int uuid_index, +static int wdc_get_c0_log_page(struct libnvme_global_ctx *ctx, struct libnvme_transport_handle *hdl, char *format, int uuid_index, __u32 namespace_id) { uint32_t device_id, read_vendor_id; @@ -7339,7 +7339,7 @@ static int wdc_get_c0_log_page(struct nvme_global_ctx *ctx, struct nvme_transpor return ret; } -static int wdc_print_latency_monitor_log(struct nvme_transport_handle *hdl, +static int wdc_print_latency_monitor_log(struct libnvme_transport_handle *hdl, struct wdc_ssd_latency_monitor_log *log_data, int fmt) { @@ -7426,7 +7426,7 @@ static int wdc_print_fb_ca_log(struct wdc_ssd_ca_perf_stats *perf, int fmt) return 0; } -static int wdc_print_bd_ca_log(struct nvme_transport_handle *hdl, void *bd_data, int fmt) +static int wdc_print_bd_ca_log(struct libnvme_transport_handle *hdl, void *bd_data, int fmt) { if (!bd_data) { fprintf(stderr, "ERROR: WDC: Invalid buffer to read data\n"); @@ -7485,7 +7485,7 @@ static int wdc_print_fw_act_history_log(__u8 *data, int num_entries, int fmt, return 0; } -static int wdc_get_ca_log_page(struct nvme_global_ctx *ctx, struct nvme_transport_handle *hdl, char *format) +static int wdc_get_ca_log_page(struct libnvme_global_ctx *ctx, struct libnvme_transport_handle *hdl, char *format) { uint32_t read_device_id, read_vendor_id; struct wdc_ssd_ca_perf_stats *perf; @@ -7523,7 +7523,7 @@ static int wdc_get_ca_log_page(struct nvme_global_ctx *ctx, struct nvme_transpor if (cust_id == WDC_CUSTOMER_ID_0x1005) { data = (__u8 *)malloc(sizeof(__u8) * WDC_FB_CA_LOG_BUF_LEN); if (!data) { - fprintf(stderr, "ERROR: WDC: malloc: %s\n", nvme_strerror(errno)); + fprintf(stderr, "ERROR: WDC: malloc: %s\n", libnvme_strerror(errno)); return -1; } @@ -7559,7 +7559,7 @@ static int wdc_get_ca_log_page(struct nvme_global_ctx *ctx, struct nvme_transpor if (cust_id == WDC_CUSTOMER_ID_0x1005) { data = (__u8 *)malloc(sizeof(__u8) * WDC_FB_CA_LOG_BUF_LEN); if (!data) { - fprintf(stderr, "ERROR: WDC: malloc: %s\n", nvme_strerror(errno)); + fprintf(stderr, "ERROR: WDC: malloc: %s\n", libnvme_strerror(errno)); return -1; } @@ -7583,7 +7583,7 @@ static int wdc_get_ca_log_page(struct nvme_global_ctx *ctx, struct nvme_transpor (cust_id == WDC_CUSTOMER_ID_BD)) { data = (__u8 *)malloc(sizeof(__u8) * WDC_BD_CA_LOG_BUF_LEN); if (!data) { - fprintf(stderr, "ERROR: WDC: malloc: %s\n", nvme_strerror(errno)); + fprintf(stderr, "ERROR: WDC: malloc: %s\n", libnvme_strerror(errno)); return -1; } @@ -7615,8 +7615,8 @@ static int wdc_get_ca_log_page(struct nvme_global_ctx *ctx, struct nvme_transpor return ret; } -static int wdc_get_c1_log_page(struct nvme_global_ctx *ctx, - struct nvme_transport_handle *hdl, char *format, +static int wdc_get_c1_log_page(struct libnvme_global_ctx *ctx, + struct libnvme_transport_handle *hdl, char *format, uint8_t interval) { struct wdc_log_page_subpage_header *sph; @@ -7646,7 +7646,7 @@ static int wdc_get_c1_log_page(struct nvme_global_ctx *ctx, data = (__u8 *)malloc(sizeof(__u8) * WDC_ADD_LOG_BUF_LEN); if (!data) { - fprintf(stderr, "ERROR: WDC: malloc: %s\n", nvme_strerror(errno)); + fprintf(stderr, "ERROR: WDC: malloc: %s\n", libnvme_strerror(errno)); return -1; } memset(data, 0, sizeof(__u8) * WDC_ADD_LOG_BUF_LEN); @@ -7676,7 +7676,7 @@ static int wdc_get_c1_log_page(struct nvme_global_ctx *ctx, return ret; } -static int wdc_get_c3_log_page(struct nvme_global_ctx *ctx, struct nvme_transport_handle *hdl, char *format) +static int wdc_get_c3_log_page(struct libnvme_global_ctx *ctx, struct libnvme_transport_handle *hdl, char *format) { struct wdc_ssd_latency_monitor_log *log_data; nvme_print_flags_t fmt; @@ -7695,7 +7695,7 @@ static int wdc_get_c3_log_page(struct nvme_global_ctx *ctx, struct nvme_transpor data = (__u8 *)malloc(sizeof(__u8) * WDC_LATENCY_MON_LOG_BUF_LEN); if (!data) { - fprintf(stderr, "ERROR: WDC: malloc: %s\n", nvme_strerror(errno)); + fprintf(stderr, "ERROR: WDC: malloc: %s\n", libnvme_strerror(errno)); return -1; } memset(data, 0, sizeof(__u8) * WDC_LATENCY_MON_LOG_BUF_LEN); @@ -7704,7 +7704,7 @@ static int wdc_get_c3_log_page(struct nvme_global_ctx *ctx, struct nvme_transpor data, WDC_LATENCY_MON_LOG_BUF_LEN); if (strcmp(format, "json")) - fprintf(stderr, "NVMe Status:%s(%x)\n", nvme_status_to_string(ret, false), ret); + fprintf(stderr, "NVMe Status:%s(%x)\n", libnvme_status_to_string(ret, false), ret); if (!ret) { log_data = (struct wdc_ssd_latency_monitor_log *)data; @@ -7748,7 +7748,7 @@ static int wdc_get_c3_log_page(struct nvme_global_ctx *ctx, struct nvme_transpor } -static int wdc_get_ocp_c1_log_page(struct nvme_global_ctx *ctx, struct nvme_transport_handle *hdl, char *format) +static int wdc_get_ocp_c1_log_page(struct libnvme_global_ctx *ctx, struct libnvme_transport_handle *hdl, char *format) { struct wdc_ocp_c1_error_recovery_log *log_data; nvme_print_flags_t fmt; @@ -7767,7 +7767,7 @@ static int wdc_get_ocp_c1_log_page(struct nvme_global_ctx *ctx, struct nvme_tran data = (__u8 *)malloc(sizeof(__u8) * WDC_ERROR_REC_LOG_BUF_LEN); if (!data) { - fprintf(stderr, "ERROR: WDC: malloc: %s\n", nvme_strerror(errno)); + fprintf(stderr, "ERROR: WDC: malloc: %s\n", libnvme_strerror(errno)); return -1; } memset(data, 0, sizeof(__u8) * WDC_ERROR_REC_LOG_BUF_LEN); @@ -7776,7 +7776,7 @@ static int wdc_get_ocp_c1_log_page(struct nvme_global_ctx *ctx, struct nvme_tran data, WDC_ERROR_REC_LOG_BUF_LEN); if (strcmp(format, "json")) - fprintf(stderr, "NVMe Status:%s(%x)\n", nvme_status_to_string(ret, false), ret); + fprintf(stderr, "NVMe Status:%s(%x)\n", libnvme_status_to_string(ret, false), ret); if (!ret) { log_data = (struct wdc_ocp_c1_error_recovery_log *)data; @@ -7820,7 +7820,7 @@ static int wdc_get_ocp_c1_log_page(struct nvme_global_ctx *ctx, struct nvme_tran return ret; } -static int wdc_get_ocp_c4_log_page(struct nvme_global_ctx *ctx, struct nvme_transport_handle *hdl, char *format) +static int wdc_get_ocp_c4_log_page(struct libnvme_global_ctx *ctx, struct libnvme_transport_handle *hdl, char *format) { struct wdc_ocp_C4_dev_cap_log *log_data; nvme_print_flags_t fmt; @@ -7839,7 +7839,7 @@ static int wdc_get_ocp_c4_log_page(struct nvme_global_ctx *ctx, struct nvme_tran data = (__u8 *)malloc(sizeof(__u8) * WDC_DEV_CAP_LOG_BUF_LEN); if (!data) { - fprintf(stderr, "ERROR: WDC: malloc: %s\n", nvme_strerror(errno)); + fprintf(stderr, "ERROR: WDC: malloc: %s\n", libnvme_strerror(errno)); return -1; } memset(data, 0, sizeof(__u8) * WDC_DEV_CAP_LOG_BUF_LEN); @@ -7848,7 +7848,7 @@ static int wdc_get_ocp_c4_log_page(struct nvme_global_ctx *ctx, struct nvme_tran data, WDC_DEV_CAP_LOG_BUF_LEN); if (strcmp(format, "json")) - fprintf(stderr, "NVMe Status:%s(%x)\n", nvme_status_to_string(ret, false), ret); + fprintf(stderr, "NVMe Status:%s(%x)\n", libnvme_status_to_string(ret, false), ret); if (!ret) { log_data = (struct wdc_ocp_C4_dev_cap_log *)data; @@ -7890,7 +7890,7 @@ static int wdc_get_ocp_c4_log_page(struct nvme_global_ctx *ctx, struct nvme_tran return ret; } -static int wdc_get_ocp_c5_log_page(struct nvme_global_ctx *ctx, struct nvme_transport_handle *hdl, char *format) +static int wdc_get_ocp_c5_log_page(struct libnvme_global_ctx *ctx, struct libnvme_transport_handle *hdl, char *format) { struct wdc_ocp_C5_unsupported_reqs *log_data; nvme_print_flags_t fmt; @@ -7909,7 +7909,7 @@ static int wdc_get_ocp_c5_log_page(struct nvme_global_ctx *ctx, struct nvme_tran data = (__u8 *)malloc(sizeof(__u8) * WDC_UNSUPPORTED_REQS_LOG_BUF_LEN); if (!data) { - fprintf(stderr, "ERROR: WDC: malloc: %s\n", nvme_strerror(errno)); + fprintf(stderr, "ERROR: WDC: malloc: %s\n", libnvme_strerror(errno)); return -1; } memset(data, 0, sizeof(__u8) * WDC_UNSUPPORTED_REQS_LOG_BUF_LEN); @@ -7918,7 +7918,7 @@ static int wdc_get_ocp_c5_log_page(struct nvme_global_ctx *ctx, struct nvme_tran data, WDC_UNSUPPORTED_REQS_LOG_BUF_LEN); if (strcmp(format, "json")) - fprintf(stderr, "NVMe Status:%s(%x)\n", nvme_status_to_string(ret, false), ret); + fprintf(stderr, "NVMe Status:%s(%x)\n", libnvme_status_to_string(ret, false), ret); if (!ret) { log_data = (struct wdc_ocp_C5_unsupported_reqs *)data; @@ -7962,7 +7962,7 @@ static int wdc_get_ocp_c5_log_page(struct nvme_global_ctx *ctx, struct nvme_tran return ret; } -static int wdc_get_d0_log_page(struct nvme_global_ctx *ctx, struct nvme_transport_handle *hdl, char *format) +static int wdc_get_d0_log_page(struct libnvme_global_ctx *ctx, struct libnvme_transport_handle *hdl, char *format) { struct wdc_ssd_d0_smart_log *perf; nvme_print_flags_t fmt; @@ -7987,7 +7987,7 @@ static int wdc_get_d0_log_page(struct nvme_global_ctx *ctx, struct nvme_transpor data = (__u8 *)malloc(sizeof(__u8) * WDC_NVME_VU_SMART_LOG_LEN); if (!data) { - fprintf(stderr, "ERROR: WDC: malloc: %s\n", nvme_strerror(errno)); + fprintf(stderr, "ERROR: WDC: malloc: %s\n", libnvme_strerror(errno)); return -1; } memset(data, 0, sizeof(__u8) * WDC_NVME_VU_SMART_LOG_LEN); @@ -8186,13 +8186,13 @@ static void wdc_show_cloud_smart_log_json(struct ocp_cloud_smart_log *log) } static void wdc_show_cloud_smart_log_normal(struct ocp_cloud_smart_log *log, - struct nvme_transport_handle *hdl) + struct libnvme_transport_handle *hdl) { char buf[2 * sizeof(log->log_page_guid) + 3]; uint16_t smart_log_ver = (uint16_t)le16_to_cpu(log->log_page_version); printf("SMART Cloud Attributes for NVMe device : %s\n", - nvme_transport_handle_get_name(hdl)); + libnvme_transport_handle_get_name(hdl)); printf("Physical Media Units Written : %'.0Lf\n", le_to_float(log->physical_media_units_written, 16)); printf("Physical Media Units Read : %'.0Lf\n", @@ -8296,8 +8296,8 @@ static int wdc_vs_smart_add_log(int argc, char **argv, struct command *acmd, const char *log_page_mask = "Log Page Mask, comma separated list: 0xC0, 0xC1, 0xCA, 0xD0"; const char *namespace_id = "desired namespace id"; nvme_print_flags_t fmt; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; int ret = 0; int uuid_index = 0; int page_mask = 0, num, i; @@ -8329,7 +8329,7 @@ static int wdc_vs_smart_add_log(int argc, char **argv, struct command *acmd, if (ret) return ret; - ret = nvme_scan_topology(ctx, NULL, NULL); + ret = libnvme_scan_topology(ctx, NULL, NULL); if (ret) return ret; @@ -8437,9 +8437,9 @@ static int wdc_cu_smart_log(int argc, char **argv, struct command *acmd, { const char *desc = "Retrieve customer unique smart log statistics."; const char *uuid_index = "The uuid index to select the correct log page implementation."; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; - struct nvme_passthru_cmd cmd; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; + struct libnvme_passthru_cmd cmd; int ret = 0; __u64 capabilities = 0; uint32_t read_device_id, read_vendor_id; @@ -8461,7 +8461,7 @@ static int wdc_cu_smart_log(int argc, char **argv, struct command *acmd, if (ret) return ret; - ret = nvme_scan_topology(ctx, NULL, NULL); + ret = libnvme_scan_topology(ctx, NULL, NULL); if (ret) return ret; @@ -8497,7 +8497,7 @@ static int wdc_cu_smart_log(int argc, char **argv, struct command *acmd, case WDC_NVME_SN861_DEV_ID_1: data = (__u8 *)malloc(WDC_BD_CA_LOG_BUF_LEN); if (!data) { - fprintf(stderr, "ERROR: WDC: malloc: %s\n", nvme_strerror(errno)); + fprintf(stderr, "ERROR: WDC: malloc: %s\n", libnvme_strerror(errno)); ret = -1; break; } @@ -8511,7 +8511,7 @@ static int wdc_cu_smart_log(int argc, char **argv, struct command *acmd, cmd.cdw14 |= NVME_FIELD_ENCODE(cfg.uuid_index, NVME_LOG_CDW14_UUID_SHIFT, NVME_LOG_CDW14_UUID_MASK); - ret = nvme_get_log(hdl, &cmd, false, + ret = libnvme_get_log(hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); if (strcmp(nvme_args.output_format, "json")) @@ -8547,8 +8547,8 @@ static int wdc_vs_cloud_log(int argc, char **argv, struct command *acmd, const char *namespace_id = "desired namespace id"; nvme_print_flags_t fmt; __u64 capabilities = 0; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; int ret; __u8 *data; @@ -8569,7 +8569,7 @@ static int wdc_vs_cloud_log(int argc, char **argv, struct command *acmd, if (ret) return ret; - ret = nvme_scan_topology(ctx, NULL, NULL); + ret = libnvme_scan_topology(ctx, NULL, NULL); if (ret) return ret; @@ -8614,10 +8614,10 @@ static int wdc_vs_hw_rev_log(int argc, char **argv, struct command *acmd, const char *namespace_id = "desired namespace id"; nvme_print_flags_t fmt; __u64 capabilities = 0; - struct nvme_transport_handle *hdl; + struct libnvme_transport_handle *hdl; int ret; __u8 *data = NULL; - struct nvme_global_ctx *ctx; + struct libnvme_global_ctx *ctx; struct config { char *output_format; @@ -8636,7 +8636,7 @@ static int wdc_vs_hw_rev_log(int argc, char **argv, struct command *acmd, if (ret) return ret; - ret = nvme_scan_topology(ctx, NULL, NULL); + ret = libnvme_scan_topology(ctx, NULL, NULL); if (ret) return ret; @@ -8692,8 +8692,8 @@ static int wdc_vs_device_waf(int argc, char **argv, struct command *acmd, { const char *desc = "Retrieve Device Write Amplication Factor"; const char *namespace_id = "desired namespace id"; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; struct nvme_smart_log smart_log; nvme_print_flags_t fmt; __u8 *data; @@ -8724,7 +8724,7 @@ static int wdc_vs_device_waf(int argc, char **argv, struct command *acmd, if (ret) return ret; - ret = nvme_scan_topology(ctx, NULL, NULL); + ret = libnvme_scan_topology(ctx, NULL, NULL); if (ret) return ret; @@ -8745,7 +8745,7 @@ static int wdc_vs_device_waf(int argc, char **argv, struct command *acmd, ret = -1; goto out; } else { - fprintf(stderr, "smart log: %s\n", nvme_strerror(errno)); + fprintf(stderr, "smart log: %s\n", libnvme_strerror(errno)); ret = -1; goto out; } @@ -8810,8 +8810,8 @@ static int wdc_get_latency_monitor_log(int argc, char **argv, struct command *ac { const char *desc = "Retrieve latency monitor log data."; __u64 capabilities = 0; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; int ret = 0; struct config { @@ -8828,7 +8828,7 @@ static int wdc_get_latency_monitor_log(int argc, char **argv, struct command *ac if (ret) return ret; - ret = nvme_scan_topology(ctx, NULL, NULL); + ret = libnvme_scan_topology(ctx, NULL, NULL); if (ret) return ret; capabilities = wdc_get_drive_capabilities(ctx, hdl); @@ -8852,8 +8852,8 @@ static int wdc_get_error_recovery_log(int argc, char **argv, struct command *acm { const char *desc = "Retrieve error recovery log data."; __u64 capabilities = 0; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; int ret = 0; struct config { @@ -8870,7 +8870,7 @@ static int wdc_get_error_recovery_log(int argc, char **argv, struct command *acm if (ret) return ret; - ret = nvme_scan_topology(ctx, NULL, NULL); + ret = libnvme_scan_topology(ctx, NULL, NULL); if (ret) return ret; @@ -8895,8 +8895,8 @@ static int wdc_get_dev_capabilities_log(int argc, char **argv, struct command *a { const char *desc = "Retrieve device capabilities log data."; __u64 capabilities = 0; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; int ret = 0; struct config { @@ -8913,7 +8913,7 @@ static int wdc_get_dev_capabilities_log(int argc, char **argv, struct command *a if (ret) return ret; - ret = nvme_scan_topology(ctx, NULL, NULL); + ret = libnvme_scan_topology(ctx, NULL, NULL); if (ret) return ret; @@ -8938,8 +8938,8 @@ static int wdc_get_unsupported_reqs_log(int argc, char **argv, struct command *a { const char *desc = "Retrieve unsupported requirements log data."; __u64 capabilities = 0; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; int ret = 0; struct config { @@ -8956,7 +8956,7 @@ static int wdc_get_unsupported_reqs_log(int argc, char **argv, struct command *a if (ret) return ret; - ret = nvme_scan_topology(ctx, NULL, NULL); + ret = libnvme_scan_topology(ctx, NULL, NULL); if (ret) return ret; @@ -8976,35 +8976,35 @@ static int wdc_get_unsupported_reqs_log(int argc, char **argv, struct command *a return ret; } -static int wdc_do_clear_pcie_correctable_errors(struct nvme_transport_handle *hdl) +static int wdc_do_clear_pcie_correctable_errors(struct libnvme_transport_handle *hdl) { int ret; - struct nvme_passthru_cmd admin_cmd; + struct libnvme_passthru_cmd admin_cmd; memset(&admin_cmd, 0, sizeof(admin_cmd)); admin_cmd.opcode = WDC_NVME_CLEAR_PCIE_CORR_OPCODE; admin_cmd.cdw12 = ((WDC_NVME_CLEAR_PCIE_CORR_SUBCMD << WDC_NVME_SUBCMD_SHIFT) | WDC_NVME_CLEAR_PCIE_CORR_CMD); - ret = nvme_submit_admin_passthru(hdl, &admin_cmd); + ret = libnvme_submit_admin_passthru(hdl, &admin_cmd); nvme_show_status(ret); return ret; } -static int wdc_do_clear_pcie_correctable_errors_vuc(struct nvme_transport_handle *hdl) +static int wdc_do_clear_pcie_correctable_errors_vuc(struct libnvme_transport_handle *hdl) { int ret; - struct nvme_passthru_cmd admin_cmd; + struct libnvme_passthru_cmd admin_cmd; memset(&admin_cmd, 0, sizeof(admin_cmd)); admin_cmd.opcode = WDC_NVME_CLEAR_PCIE_CORR_OPCODE_VUC; - ret = nvme_submit_admin_passthru(hdl, &admin_cmd); + ret = libnvme_submit_admin_passthru(hdl, &admin_cmd); nvme_show_status(ret); return ret; } -static int wdc_do_clear_pcie_correctable_errors_fid(struct nvme_transport_handle *hdl) +static int wdc_do_clear_pcie_correctable_errors_fid(struct libnvme_transport_handle *hdl) { int ret; __u64 result; @@ -9021,8 +9021,8 @@ static int wdc_clear_pcie_correctable_errors(int argc, char **argv, struct comma struct plugin *plugin) { const char *desc = "Clear PCIE Correctable Errors."; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; __u64 capabilities = 0; int ret; @@ -9032,7 +9032,7 @@ static int wdc_clear_pcie_correctable_errors(int argc, char **argv, struct comma if (ret) return ret; - ret = nvme_scan_topology(ctx, NULL, NULL); + ret = libnvme_scan_topology(ctx, NULL, NULL); if (ret || !wdc_check_device(ctx, hdl)) return -1; @@ -9058,8 +9058,8 @@ static int wdc_drive_status(int argc, char **argv, struct command *acmd, struct plugin *plugin) { const char *desc = "Get Drive Status."; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; int ret = 0; int uuid_index; void *dev_mng_log = NULL; @@ -9078,7 +9078,7 @@ static int wdc_drive_status(int argc, char **argv, struct command *acmd, if (ret) return ret; - ret = nvme_scan_topology(ctx, NULL, NULL); + ret = libnvme_scan_topology(ctx, NULL, NULL); if (ret) return ret; @@ -9096,13 +9096,13 @@ static int wdc_drive_status(int argc, char **argv, struct command *acmd, memset(&uuid_list, 0, sizeof(struct nvme_id_uuid_list)); if (wdc_CheckUuidListSupport(hdl, &uuid_list)) { /* check for the Sandisk UUID first */ - uuid_index = nvme_find_uuid(&uuid_list, SNDK_UUID); + uuid_index = libnvme_find_uuid(&uuid_list, SNDK_UUID); if (uuid_index < 0) /* The Sandisk UUID is not found; * check for the WDC UUID second. */ - uuid_index = nvme_find_uuid(&uuid_list, WDC_UUID); + uuid_index = libnvme_find_uuid(&uuid_list, WDC_UUID); } /* WD UUID not found, use default uuid index - 0 */ @@ -9209,12 +9209,12 @@ static int wdc_clear_assert_dump(int argc, char **argv, struct command *acmd, struct plugin *plugin) { const char *desc = "Clear Assert Dump Present Status."; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; int ret = -1; __le32 assert_status = cpu_to_le32(0xFFFFFFFF); __u64 capabilities = 0; - struct nvme_passthru_cmd admin_cmd; + struct libnvme_passthru_cmd admin_cmd; NVME_ARGS(opts); @@ -9222,7 +9222,7 @@ static int wdc_clear_assert_dump(int argc, char **argv, struct command *acmd, if (ret) return ret; - ret = nvme_scan_topology(ctx, NULL, NULL); + ret = libnvme_scan_topology(ctx, NULL, NULL); if (ret) return ret; @@ -9247,7 +9247,7 @@ static int wdc_clear_assert_dump(int argc, char **argv, struct command *acmd, admin_cmd.cdw12 = ((WDC_NVME_CLEAR_ASSERT_DUMP_SUBCMD << WDC_NVME_SUBCMD_SHIFT) | WDC_NVME_CLEAR_ASSERT_DUMP_CMD); - ret = nvme_submit_admin_passthru(hdl, &admin_cmd); + ret = libnvme_submit_admin_passthru(hdl, &admin_cmd); nvme_show_status(ret); } else fprintf(stderr, "INFO: WDC: No Assert Dump Present\n"); @@ -9256,7 +9256,7 @@ static int wdc_clear_assert_dump(int argc, char **argv, struct command *acmd, return ret; } -static int wdc_get_fw_act_history(struct nvme_global_ctx *ctx, struct nvme_transport_handle *hdl, +static int wdc_get_fw_act_history(struct libnvme_global_ctx *ctx, struct libnvme_transport_handle *hdl, char *format) { struct wdc_fw_act_history_log_hdr *fw_act_history_hdr; @@ -9283,7 +9283,7 @@ static int wdc_get_fw_act_history(struct nvme_global_ctx *ctx, struct nvme_trans data = (__u8 *)malloc(sizeof(__u8) * WDC_FW_ACT_HISTORY_LOG_BUF_LEN); if (!data) { - fprintf(stderr, "ERROR: WDC: malloc: %s\n", nvme_strerror(errno)); + fprintf(stderr, "ERROR: WDC: malloc: %s\n", libnvme_strerror(errno)); return -1; } @@ -9322,7 +9322,7 @@ static int wdc_get_fw_act_history(struct nvme_global_ctx *ctx, struct nvme_trans return ret; } -static __u32 wdc_get_fw_cust_id(struct nvme_global_ctx *ctx, struct nvme_transport_handle *hdl) +static __u32 wdc_get_fw_cust_id(struct libnvme_global_ctx *ctx, struct libnvme_transport_handle *hdl) { __u32 cust_id = WDC_INVALID_CUSTOMER_ID; @@ -9338,7 +9338,7 @@ static __u32 wdc_get_fw_cust_id(struct nvme_global_ctx *ctx, struct nvme_transpo return cust_id; } -static int wdc_get_fw_act_history_C2(struct nvme_global_ctx *ctx, struct nvme_transport_handle *hdl, +static int wdc_get_fw_act_history_C2(struct libnvme_global_ctx *ctx, struct libnvme_transport_handle *hdl, char *format) { struct wdc_fw_act_history_log_format_c2 *fw_act_history_log; @@ -9363,7 +9363,7 @@ static int wdc_get_fw_act_history_C2(struct nvme_global_ctx *ctx, struct nvme_tr data = (__u8 *)malloc(sizeof(__u8) * WDC_FW_ACT_HISTORY_C2_LOG_BUF_LEN); if (!data) { - fprintf(stderr, "ERROR: WDC: malloc: %s\n", nvme_strerror(errno)); + fprintf(stderr, "ERROR: WDC: malloc: %s\n", libnvme_strerror(errno)); return -1; } @@ -9427,8 +9427,8 @@ static int wdc_vs_fw_activate_history(int argc, char **argv, struct command *acm { const char *desc = "Retrieve FW activate history table."; __u64 capabilities = 0; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; int ret = -1; struct config { @@ -9445,7 +9445,7 @@ static int wdc_vs_fw_activate_history(int argc, char **argv, struct command *acm if (ret) return ret; - ret = nvme_scan_topology(ctx, NULL, NULL); + ret = libnvme_scan_topology(ctx, NULL, NULL); if (ret) return ret; @@ -9484,23 +9484,23 @@ static int wdc_vs_fw_activate_history(int argc, char **argv, struct command *acm return ret; } -static int wdc_do_clear_fw_activate_history_vuc(struct nvme_transport_handle *hdl) +static int wdc_do_clear_fw_activate_history_vuc(struct libnvme_transport_handle *hdl) { int ret = -1; - struct nvme_passthru_cmd admin_cmd; + struct libnvme_passthru_cmd admin_cmd; memset(&admin_cmd, 0, sizeof(admin_cmd)); admin_cmd.opcode = WDC_NVME_CLEAR_FW_ACT_HIST_OPCODE; admin_cmd.cdw12 = ((WDC_NVME_CLEAR_FW_ACT_HIST_SUBCMD << WDC_NVME_SUBCMD_SHIFT) | WDC_NVME_CLEAR_FW_ACT_HIST_CMD); - ret = nvme_submit_admin_passthru(hdl, &admin_cmd); + ret = libnvme_submit_admin_passthru(hdl, &admin_cmd); nvme_show_status(ret); return ret; } -static int wdc_do_clear_fw_activate_history_fid(struct nvme_transport_handle *hdl) +static int wdc_do_clear_fw_activate_history_fid(struct libnvme_transport_handle *hdl) { int ret = -1; __u64 result; @@ -9518,8 +9518,8 @@ static int wdc_clear_fw_activate_history(int argc, char **argv, struct command * { const char *desc = "Clear FW activate history table."; __u64 capabilities = 0; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; int ret; NVME_ARGS(opts); @@ -9528,7 +9528,7 @@ static int wdc_clear_fw_activate_history(int argc, char **argv, struct command * if (ret) return ret; - ret = nvme_scan_topology(ctx, NULL, NULL); + ret = libnvme_scan_topology(ctx, NULL, NULL); if (ret) return ret; @@ -9557,8 +9557,8 @@ static int wdc_vs_telemetry_controller_option(int argc, char **argv, struct comm const char *enable = "Enable controller option of the telemetry log page."; const char *status = "Displays the current state of the controller initiated log page."; __u64 capabilities = 0; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; __u64 result; int ret = -1; @@ -9584,7 +9584,7 @@ static int wdc_vs_telemetry_controller_option(int argc, char **argv, struct comm if (ret) return ret; - ret = nvme_scan_topology(ctx, NULL, NULL); + ret = libnvme_scan_topology(ctx, NULL, NULL); if (ret) return ret; @@ -9641,7 +9641,7 @@ static int wdc_vs_telemetry_controller_option(int argc, char **argv, struct comm } -static int wdc_get_serial_and_fw_rev(struct nvme_transport_handle *hdl, char *sn, char *fw_rev) +static int wdc_get_serial_and_fw_rev(struct libnvme_transport_handle *hdl, char *sn, char *fw_rev) { struct nvme_id_ctrl ctrl; int ret; @@ -9667,7 +9667,7 @@ static int wdc_get_serial_and_fw_rev(struct nvme_transport_handle *hdl, char *sn return 0; } -static int wdc_get_max_transfer_len(struct nvme_transport_handle *hdl, __u32 *maxTransferLen) +static int wdc_get_max_transfer_len(struct libnvme_transport_handle *hdl, __u32 *maxTransferLen) { struct nvme_id_ctrl ctrl; int ret = 0; @@ -9687,23 +9687,23 @@ static int wdc_get_max_transfer_len(struct nvme_transport_handle *hdl, __u32 *ma return ret; } -static int wdc_de_VU_read_size(struct nvme_transport_handle *hdl, __u32 fileId, __u16 spiDestn, __u32 *logSize) +static int wdc_de_VU_read_size(struct libnvme_transport_handle *hdl, __u32 fileId, __u16 spiDestn, __u32 *logSize) { int ret = WDC_STATUS_FAILURE; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; if (!logSize) { ret = WDC_STATUS_INVALID_PARAMETER; goto end; } - memset(&cmd, 0, sizeof(struct nvme_passthru_cmd)); + memset(&cmd, 0, sizeof(struct libnvme_passthru_cmd)); cmd.opcode = WDC_DE_VU_READ_SIZE_OPCODE; cmd.nsid = WDC_DE_DEFAULT_NAMESPACE_ID; cmd.cdw13 = fileId << 16; cmd.cdw14 = spiDestn; - ret = nvme_submit_admin_passthru(hdl, &cmd); + ret = libnvme_submit_admin_passthru(hdl, &cmd); if (!ret && logSize) *logSize = cmd.result; @@ -9716,11 +9716,11 @@ static int wdc_de_VU_read_size(struct nvme_transport_handle *hdl, __u32 fileId, return ret; } -static int wdc_de_VU_read_buffer(struct nvme_transport_handle *hdl, __u32 fileId, __u16 spiDestn, +static int wdc_de_VU_read_buffer(struct libnvme_transport_handle *hdl, __u32 fileId, __u16 spiDestn, __u32 offsetInDwords, __u8 *dataBuffer, __u32 *bufferSize) { int ret = WDC_STATUS_FAILURE; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; __u32 noOfDwordExpected = 0; if (!dataBuffer || !bufferSize) { @@ -9728,7 +9728,7 @@ static int wdc_de_VU_read_buffer(struct nvme_transport_handle *hdl, __u32 fileId goto end; } - memset(&cmd, 0, sizeof(struct nvme_passthru_cmd)); + memset(&cmd, 0, sizeof(struct libnvme_passthru_cmd)); noOfDwordExpected = *bufferSize / sizeof(__u32); cmd.opcode = WDC_DE_VU_READ_BUFFER_OPCODE; cmd.nsid = WDC_DE_DEFAULT_NAMESPACE_ID; @@ -9740,7 +9740,7 @@ static int wdc_de_VU_read_buffer(struct nvme_transport_handle *hdl, __u32 fileId cmd.addr = (__u64)(__u64)(uintptr_t)dataBuffer; cmd.data_len = *bufferSize; - ret = nvme_submit_admin_passthru(hdl, &cmd); + ret = libnvme_submit_admin_passthru(hdl, &cmd); if (ret != WDC_STATUS_SUCCESS) { fprintf(stderr, "ERROR: WDC: VUReadBuffer() failed, "); @@ -9751,7 +9751,7 @@ static int wdc_de_VU_read_buffer(struct nvme_transport_handle *hdl, __u32 fileId return ret; } -static int wdc_get_log_dir_max_entries(struct nvme_transport_handle *hdl, __u32 *maxNumOfEntries) +static int wdc_get_log_dir_max_entries(struct libnvme_transport_handle *hdl, __u32 *maxNumOfEntries) { int ret = WDC_STATUS_FAILURE; __u32 headerPayloadSize = 0; @@ -9818,7 +9818,7 @@ static enum WDC_DRIVE_ESSENTIAL_TYPE wdc_get_essential_type(__u8 fileName[]) return essentialType; } -static int wdc_fetch_log_directory(struct nvme_transport_handle *hdl, struct WDC_DE_VU_LOG_DIRECTORY *directory) +static int wdc_fetch_log_directory(struct libnvme_transport_handle *hdl, struct WDC_DE_VU_LOG_DIRECTORY *directory) { int ret = WDC_STATUS_FAILURE; __u8 *fileOffset = NULL; @@ -9891,7 +9891,7 @@ static int wdc_fetch_log_directory(struct nvme_transport_handle *hdl, struct WDC return ret; } -static int wdc_fetch_log_file_from_device(struct nvme_transport_handle *hdl, __u32 fileId, +static int wdc_fetch_log_file_from_device(struct libnvme_transport_handle *hdl, __u32 fileId, __u16 spiDestn, __u64 fileSize, __u8 *dataBuffer) { int ret = WDC_STATUS_FAILURE; @@ -9944,7 +9944,7 @@ static int wdc_fetch_log_file_from_device(struct nvme_transport_handle *hdl, __u return ret; } -static int wdc_de_get_dump_trace(struct nvme_transport_handle *hdl, const char *filePath, __u16 binFileNameLen, +static int wdc_de_get_dump_trace(struct libnvme_transport_handle *hdl, const char *filePath, __u16 binFileNameLen, const char *binFileName) { int ret = WDC_STATUS_FAILURE; @@ -10038,7 +10038,7 @@ static int wdc_de_get_dump_trace(struct nvme_transport_handle *hdl, const char * return ret; } -int wdc_fetch_vu_file_directory(struct nvme_transport_handle *hdl, +int wdc_fetch_vu_file_directory(struct libnvme_transport_handle *hdl, struct WDC_DE_VU_LOG_DIRECTORY deEssentialsList, __s8 *bufferFolderPath, __u8 *serialNo, __u8 *timeString) { @@ -10089,7 +10089,7 @@ int wdc_fetch_vu_file_directory(struct nvme_transport_handle *hdl, return ret; } -int wdc_read_debug_directory(struct nvme_transport_handle *hdl, __s8 *bufferFolderPath, __u8 *serialNo, +int wdc_read_debug_directory(struct libnvme_transport_handle *hdl, __s8 *bufferFolderPath, __u8 *serialNo, __u8 *timeString) { __u32 maxNumOfVUFiles = 0; @@ -10115,7 +10115,7 @@ int wdc_read_debug_directory(struct nvme_transport_handle *hdl, __s8 *bufferFold return ret; } -static int wdc_do_drive_essentials(struct nvme_global_ctx *ctx, struct nvme_transport_handle *hdl, +static int wdc_do_drive_essentials(struct libnvme_global_ctx *ctx, struct libnvme_transport_handle *hdl, char *dir, char *key) { int ret = 0; @@ -10280,7 +10280,7 @@ static int wdc_do_drive_essentials(struct nvme_global_ctx *ctx, struct nvme_tran deVULogPagesList[vuLogIdx].logPageId, dataBuffer, dataBufferSize); if (ret) { - fprintf(stderr, "ERROR: WDC: nvme_get_log() for log page 0x%x failed, ret = %d\n", + fprintf(stderr, "ERROR: WDC: libnvme_get_log() for log page 0x%x failed, ret = %d\n", deVULogPagesList[vuLogIdx].logPageId, ret); } else { wdc_UtilsDeleteCharFromString((char *)deVULogPagesList[vuLogIdx].logPageIdStr, 4, ' '); @@ -10350,8 +10350,8 @@ static int wdc_drive_essentials(int argc, char **argv, struct command *acmd, { const char *desc = "Capture Drive Essentials."; const char *dirName = "Output directory pathname."; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; char d[PATH_MAX] = {0}; char k[PATH_MAX] = {0}; __u64 capabilities = 0; @@ -10374,7 +10374,7 @@ static int wdc_drive_essentials(int argc, char **argv, struct command *acmd, if (ret) return ret; - ret = nvme_scan_topology(ctx, NULL, NULL); + ret = libnvme_scan_topology(ctx, NULL, NULL); if (ret) return ret; @@ -10398,46 +10398,46 @@ static int wdc_drive_essentials(int argc, char **argv, struct command *acmd, return ret; } -static int wdc_do_drive_resize(struct nvme_transport_handle *hdl, uint64_t new_size) +static int wdc_do_drive_resize(struct libnvme_transport_handle *hdl, uint64_t new_size) { int ret; - struct nvme_passthru_cmd admin_cmd; + struct libnvme_passthru_cmd admin_cmd; - memset(&admin_cmd, 0, sizeof(struct nvme_passthru_cmd)); + memset(&admin_cmd, 0, sizeof(struct libnvme_passthru_cmd)); admin_cmd.opcode = WDC_NVME_DRIVE_RESIZE_OPCODE; admin_cmd.cdw12 = ((WDC_NVME_DRIVE_RESIZE_SUBCMD << WDC_NVME_SUBCMD_SHIFT) | WDC_NVME_DRIVE_RESIZE_CMD); admin_cmd.cdw13 = new_size; - ret = nvme_submit_admin_passthru(hdl, &admin_cmd); + ret = libnvme_submit_admin_passthru(hdl, &admin_cmd); return ret; } -static int wdc_do_namespace_resize(struct nvme_transport_handle *hdl, __u32 nsid, __u32 op_option) +static int wdc_do_namespace_resize(struct libnvme_transport_handle *hdl, __u32 nsid, __u32 op_option) { int ret; - struct nvme_passthru_cmd admin_cmd; + struct libnvme_passthru_cmd admin_cmd; - memset(&admin_cmd, 0, sizeof(struct nvme_passthru_cmd)); + memset(&admin_cmd, 0, sizeof(struct libnvme_passthru_cmd)); admin_cmd.opcode = WDC_NVME_NAMESPACE_RESIZE_OPCODE; admin_cmd.nsid = nsid; admin_cmd.cdw10 = op_option; - ret = nvme_submit_admin_passthru(hdl, &admin_cmd); + ret = libnvme_submit_admin_passthru(hdl, &admin_cmd); return ret; } -static int wdc_do_drive_info(struct nvme_transport_handle *hdl, __u32 *result) +static int wdc_do_drive_info(struct libnvme_transport_handle *hdl, __u32 *result) { int ret; - struct nvme_passthru_cmd admin_cmd; + struct libnvme_passthru_cmd admin_cmd; - memset(&admin_cmd, 0, sizeof(struct nvme_passthru_cmd)); + memset(&admin_cmd, 0, sizeof(struct libnvme_passthru_cmd)); admin_cmd.opcode = WDC_NVME_DRIVE_INFO_OPCODE; admin_cmd.cdw12 = ((WDC_NVME_DRIVE_INFO_SUBCMD << WDC_NVME_SUBCMD_SHIFT) | WDC_NVME_DRIVE_INFO_CMD); - ret = nvme_submit_admin_passthru(hdl, &admin_cmd); + ret = libnvme_submit_admin_passthru(hdl, &admin_cmd); if (!ret && result) *result = admin_cmd.result; @@ -10450,8 +10450,8 @@ static int wdc_drive_resize(int argc, char **argv, { const char *desc = "Send a Resize command."; const char *size = "The new size (in GB) to resize the drive to."; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; uint64_t capabilities = 0; int ret; @@ -10470,7 +10470,7 @@ static int wdc_drive_resize(int argc, char **argv, if (ret) return ret; - ret = nvme_scan_topology(ctx, NULL, NULL); + ret = libnvme_scan_topology(ctx, NULL, NULL); if (ret || !wdc_check_device(ctx, hdl)) return -1; @@ -10496,8 +10496,8 @@ static int wdc_namespace_resize(int argc, char **argv, const char *desc = "Send a Namespace Resize command."; const char *namespace_id = "The namespace id to resize."; const char *op_option = "The over provisioning option to set for namespace."; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; uint64_t capabilities = 0; int ret; @@ -10525,7 +10525,7 @@ static int wdc_namespace_resize(int argc, char **argv, return -1; } - ret = nvme_scan_topology(ctx, NULL, NULL); + ret = libnvme_scan_topology(ctx, NULL, NULL); if (ret || !wdc_check_device(ctx, hdl)) return -1; @@ -10552,8 +10552,8 @@ static int wdc_reason_identifier(int argc, char **argv, const char *desc = "Retrieve telemetry log reason identifier."; const char *log_id = "Log ID to retrieve - host - 7 or controller - 8"; const char *fname = "File name to save raw binary identifier"; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; int ret; uint64_t capabilities = 0; char f[PATH_MAX] = {0}; @@ -10580,7 +10580,7 @@ static int wdc_reason_identifier(int argc, char **argv, if (ret) return ret; - ret = nvme_scan_topology(ctx, NULL, NULL); + ret = libnvme_scan_topology(ctx, NULL, NULL); if (ret) return ret; @@ -10596,7 +10596,7 @@ static int wdc_reason_identifier(int argc, char **argv, /* verify the passed in file name and path is valid before getting the dump data */ verify_file = open(cfg.file, O_WRONLY | O_CREAT | O_TRUNC, 0666); if (verify_file < 0) { - fprintf(stderr, "ERROR: WDC: open: %s\n", nvme_strerror(errno)); + fprintf(stderr, "ERROR: WDC: open: %s\n", libnvme_strerror(errno)); return -1; } close(verify_file); @@ -10811,8 +10811,8 @@ static int wdc_log_page_directory(int argc, char **argv, struct command *acmd, struct plugin *plugin) { const char *desc = "Retrieve Log Page Directory."; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; nvme_print_flags_t fmt; int ret = 0; __u64 capabilities = 0; @@ -10843,7 +10843,7 @@ static int wdc_log_page_directory(int argc, char **argv, struct command *acmd, return ret; } - ret = nvme_scan_topology(ctx, NULL, NULL); + ret = libnvme_scan_topology(ctx, NULL, NULL); if (ret) return ret; @@ -10871,13 +10871,13 @@ static int wdc_log_page_directory(int argc, char **argv, struct command *acmd, if (!wdc_is_sn861(device_id)) { if (uuid_supported) { /* check for the Sandisk UUID first */ - uuid_index = nvme_find_uuid(&uuid_list, SNDK_UUID); + uuid_index = libnvme_find_uuid(&uuid_list, SNDK_UUID); if (uuid_index < 0) /* The Sandisk UUID is not found; * check for the WDC UUID second. */ - uuid_index = nvme_find_uuid(&uuid_list, WDC_UUID); + uuid_index = libnvme_find_uuid(&uuid_list, WDC_UUID); } /* WD UUID not found, use default uuid index - 0 */ @@ -10946,7 +10946,7 @@ static int wdc_log_page_directory(int argc, char **argv, struct command *acmd, } dir = (struct log_page_directory *)data; - struct nvme_passthru_cmd cmd = { + struct libnvme_passthru_cmd cmd = { .opcode = WDC_NVME_ADMIN_VUC_OPCODE_D2, .cdw10 = 8, .cdw12 = WDC_VUC_SUBOPCODE_LOG_PAGE_DIR_D2, @@ -10954,7 +10954,7 @@ static int wdc_log_page_directory(int argc, char **argv, struct command *acmd, .data_len = 32, }; - ret = nvme_submit_admin_passthru(hdl, &cmd); + ret = libnvme_submit_admin_passthru(hdl, &cmd); if (!ret) { switch (fmt) { case BINARY: @@ -10968,7 +10968,7 @@ static int wdc_log_page_directory(int argc, char **argv, struct command *acmd, } } else { fprintf(stderr, "NVMe Status:%s(%x)\n", - nvme_status_to_string(ret, false), ret); + libnvme_status_to_string(ret, false), ret); } } } @@ -10977,7 +10977,7 @@ static int wdc_log_page_directory(int argc, char **argv, struct command *acmd, return ret; } -static int wdc_get_drive_reason_id(struct nvme_transport_handle *hdl, char *drive_reason_id, size_t len) +static int wdc_get_drive_reason_id(struct libnvme_transport_handle *hdl, char *drive_reason_id, size_t len) { const char *reason_id_str = "reason_id"; struct nvme_id_ctrl ctrl; @@ -11015,7 +11015,7 @@ static int wdc_get_drive_reason_id(struct nvme_transport_handle *hdl, char *driv return 0; } -static int wdc_save_reason_id(struct nvme_transport_handle *hdl, __u8 *rsn_ident, int size) +static int wdc_save_reason_id(struct libnvme_transport_handle *hdl, __u8 *rsn_ident, int size) { int ret = 0; char *reason_id_file; @@ -11032,7 +11032,7 @@ static int wdc_save_reason_id(struct nvme_transport_handle *hdl, __u8 *rsn_ident if (stat(reason_id_path, &st) == -1) { if (mkdir(reason_id_path, 0700) < 0) { fprintf(stderr, "%s: ERROR: failed to mkdir %s: %s\n", - __func__, reason_id_path, nvme_strerror(errno)); + __func__, reason_id_path, libnvme_strerror(errno)); return -1; } } @@ -11050,7 +11050,7 @@ static int wdc_save_reason_id(struct nvme_transport_handle *hdl, __u8 *rsn_ident return ret; } -static int wdc_clear_reason_id(struct nvme_transport_handle *hdl) +static int wdc_clear_reason_id(struct libnvme_transport_handle *hdl) { int ret = -1; int verify_file; @@ -11083,7 +11083,7 @@ static int wdc_clear_reason_id(struct nvme_transport_handle *hdl) return ret; } -static int wdc_dump_telemetry_hdr(struct nvme_transport_handle *hdl, int log_id, struct nvme_telemetry_log *log_hdr) +static int wdc_dump_telemetry_hdr(struct libnvme_transport_handle *hdl, int log_id, struct nvme_telemetry_log *log_hdr) { int ret = 0; @@ -11102,7 +11102,7 @@ static int wdc_dump_telemetry_hdr(struct nvme_transport_handle *hdl, int log_id, return ret; } -static int wdc_do_get_reason_id(struct nvme_transport_handle *hdl, const char *file, int log_id) +static int wdc_do_get_reason_id(struct libnvme_transport_handle *hdl, const char *file, int log_id) { int ret; struct nvme_telemetry_log *log_hdr; @@ -11111,7 +11111,7 @@ static int wdc_do_get_reason_id(struct nvme_transport_handle *hdl, const char *f log_hdr = (struct nvme_telemetry_log *)malloc(log_hdr_size); if (!log_hdr) { - fprintf(stderr, "%s: ERROR: malloc failed, size : 0x%x, status: %s\n", __func__, log_hdr_size, nvme_strerror(errno)); + fprintf(stderr, "%s: ERROR: malloc failed, size : 0x%x, status: %s\n", __func__, log_hdr_size, libnvme_strerror(errno)); ret = -1; goto out; } @@ -11479,7 +11479,7 @@ static void wdc_print_pcie_stats_json(struct wdc_vs_pcie_stats *pcie_stats) json_free_object(root); } -static int wdc_do_vs_nand_stats_sn810_2(struct nvme_transport_handle *hdl, char *format) +static int wdc_do_vs_nand_stats_sn810_2(struct libnvme_transport_handle *hdl, char *format) { nvme_print_flags_t fmt; uint8_t *data = NULL; @@ -11517,7 +11517,7 @@ static int wdc_do_vs_nand_stats_sn810_2(struct nvme_transport_handle *hdl, char return ret; } -static int wdc_do_vs_nand_stats(struct nvme_transport_handle *hdl, char *format) +static int wdc_do_vs_nand_stats(struct libnvme_transport_handle *hdl, char *format) { nvme_print_flags_t fmt; uint8_t *output = NULL; @@ -11526,7 +11526,7 @@ static int wdc_do_vs_nand_stats(struct nvme_transport_handle *hdl, char *format) output = (uint8_t *)calloc(WDC_NVME_NAND_STATS_SIZE, sizeof(uint8_t)); if (!output) { - fprintf(stderr, "ERROR: WDC: calloc: %s\n", nvme_strerror(errno)); + fprintf(stderr, "ERROR: WDC: calloc: %s\n", libnvme_strerror(errno)); ret = -1; goto out; } @@ -11567,8 +11567,8 @@ static int wdc_vs_nand_stats(int argc, char **argv, struct command *acmd, struct plugin *plugin) { const char *desc = "Retrieve NAND statistics."; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; __u64 capabilities = 0; uint32_t read_device_id = 0, read_vendor_id = 0; int ret; @@ -11587,7 +11587,7 @@ static int wdc_vs_nand_stats(int argc, char **argv, struct command *acmd, if (ret) return ret; - ret = nvme_scan_topology(ctx, NULL, NULL); + ret = libnvme_scan_topology(ctx, NULL, NULL); if (ret) return ret; @@ -11620,19 +11620,19 @@ static int wdc_vs_nand_stats(int argc, char **argv, struct command *acmd, return ret; } -static int wdc_do_vs_pcie_stats(struct nvme_transport_handle *hdl, +static int wdc_do_vs_pcie_stats(struct libnvme_transport_handle *hdl, struct wdc_vs_pcie_stats *pcieStatsPtr) { int ret; - struct nvme_passthru_cmd admin_cmd; + struct libnvme_passthru_cmd admin_cmd; int pcie_stats_size = sizeof(struct wdc_vs_pcie_stats); - memset(&admin_cmd, 0, sizeof(struct nvme_passthru_cmd)); + memset(&admin_cmd, 0, sizeof(struct libnvme_passthru_cmd)); admin_cmd.opcode = WDC_NVME_PCIE_STATS_OPCODE; admin_cmd.addr = (__u64)(uintptr_t)pcieStatsPtr; admin_cmd.data_len = pcie_stats_size; - ret = nvme_submit_admin_passthru(hdl, &admin_cmd); + ret = libnvme_submit_admin_passthru(hdl, &admin_cmd); return ret; } @@ -11641,8 +11641,8 @@ static int wdc_vs_pcie_stats(int argc, char **argv, struct command *acmd, struct plugin *plugin) { const char *desc = "Retrieve PCIE statistics."; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; nvme_print_flags_t fmt; int ret; __u64 capabilities = 0; @@ -11664,7 +11664,7 @@ static int wdc_vs_pcie_stats(int argc, char **argv, struct command *acmd, if (ret) return ret; - ret = nvme_scan_topology(ctx, NULL, NULL); + ret = libnvme_scan_topology(ctx, NULL, NULL); if (ret) return ret; @@ -11676,7 +11676,7 @@ static int wdc_vs_pcie_stats(int argc, char **argv, struct command *acmd, pcieStatsPtr = nvme_alloc_huge(pcie_stats_size, &mh); if (!pcieStatsPtr) { - fprintf(stderr, "ERROR: WDC: PCIE Stats alloc: %s\n", nvme_strerror(errno)); + fprintf(stderr, "ERROR: WDC: PCIE Stats alloc: %s\n", libnvme_strerror(errno)); ret = -1; goto out; } @@ -11714,8 +11714,8 @@ static int wdc_vs_drive_info(int argc, char **argv, struct command *command, struct plugin *plugin) { const char *desc = "Send a vs-drive-info command."; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; nvme_print_flags_t fmt; uint64_t capabilities = 0; int ret; @@ -11764,7 +11764,7 @@ static int wdc_vs_drive_info(int argc, char **argv, return ret; } - ret = nvme_scan_topology(ctx, NULL, NULL); + ret = libnvme_scan_topology(ctx, NULL, NULL); if (ret || !wdc_check_device(ctx, hdl)) return -1; @@ -11919,14 +11919,14 @@ static int wdc_vs_drive_info(int argc, char **argv, if (data_len % 4 != 0) num_dwords += 1; - struct nvme_passthru_cmd cmd = { + struct libnvme_passthru_cmd cmd = { .opcode = WDC_NVME_ADMIN_VUC_OPCODE_D2, .cdw10 = num_dwords, .cdw12 = WDC_VUC_SUBOPCODE_VS_DRIVE_INFO_D2, .addr = (__u64)(uintptr_t)&info, .data_len = data_len, }; - ret = nvme_submit_admin_passthru(hdl, &cmd); + ret = libnvme_submit_admin_passthru(hdl, &cmd); if (!ret) { __u16 hw_rev_major, hw_rev_minor; @@ -11977,8 +11977,8 @@ static int wdc_vs_temperature_stats(int argc, char **argv, struct command *command, struct plugin *plugin) { const char *desc = "Send a vs-temperature-stats command."; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; struct nvme_smart_log smart_log; struct nvme_id_ctrl id_ctrl; nvme_print_flags_t fmt; @@ -12001,7 +12001,7 @@ static int wdc_vs_temperature_stats(int argc, char **argv, if (ret) return ret; - ret = nvme_scan_topology(ctx, NULL, NULL); + ret = libnvme_scan_topology(ctx, NULL, NULL); if (ret) return ret; @@ -12040,7 +12040,7 @@ static int wdc_vs_temperature_stats(int argc, char **argv, if (fmt == NORMAL) { /* print the temperature stats */ printf("Temperature Stats for NVME device:%s namespace-id:%x\n", - nvme_transport_handle_get_name(hdl), WDC_DE_GLOBAL_NSID); + libnvme_transport_handle_get_name(hdl), WDC_DE_GLOBAL_NSID); printf("Current Composite Temperature : %d °C\n", temperature); printf("WCTEMP : %"PRIu16" °C\n", id_ctrl.wctemp - 273); @@ -12092,8 +12092,8 @@ static int wdc_vs_temperature_stats(int argc, char **argv, static int wdc_capabilities(int argc, char **argv, struct command *acmd, struct plugin *plugin) { const char *desc = "Send a capabilities command."; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; uint64_t capabilities = 0; int ret; @@ -12104,14 +12104,14 @@ static int wdc_capabilities(int argc, char **argv, struct command *acmd, struct return ret; /* get capabilities */ - ret = nvme_scan_topology(ctx, NULL, NULL); + ret = libnvme_scan_topology(ctx, NULL, NULL); if (ret || !wdc_check_device(ctx, hdl)) return -1; capabilities = wdc_get_drive_capabilities(ctx, hdl); /* print command and supported status */ - printf("WDC Plugin Capabilities for NVME device:%s\n", nvme_transport_handle_get_name(hdl)); + printf("WDC Plugin Capabilities for NVME device:%s\n", libnvme_transport_handle_get_name(hdl)); printf("cap-diag : %s\n", capabilities & WDC_DRIVE_CAP_CAP_DIAG ? "Supported" : "Not Supported"); printf("drive-log : %s\n", @@ -12197,8 +12197,8 @@ static int wdc_cloud_ssd_plugin_version(int argc, char **argv, struct command *a struct plugin *plugin) { const char *desc = "Get Cloud SSD Plugin Version command."; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; uint64_t capabilities = 0; int ret; @@ -12209,7 +12209,7 @@ static int wdc_cloud_ssd_plugin_version(int argc, char **argv, struct command *a return ret; /* get capabilities */ - ret = nvme_scan_topology(ctx, NULL, NULL); + ret = libnvme_scan_topology(ctx, NULL, NULL); if (ret || !wdc_check_device(ctx, hdl)) return -1; @@ -12230,8 +12230,8 @@ static int wdc_cloud_boot_SSD_version(int argc, char **argv, struct command *acm { const char *desc = "Get Cloud Boot SSD Version command."; const char *namespace_id = "desired namespace id"; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; uint64_t capabilities = 0; int ret; int major = 0, minor = 0; @@ -12254,7 +12254,7 @@ static int wdc_cloud_boot_SSD_version(int argc, char **argv, struct command *acm return ret; /* get capabilities */ - ret = nvme_scan_topology(ctx, NULL, NULL); + ret = libnvme_scan_topology(ctx, NULL, NULL); if (ret || !wdc_check_device(ctx, hdl)) return -1; @@ -12291,8 +12291,8 @@ static int wdc_enc_get_log(int argc, char **argv, struct command *acmd, struct p const char *file = "Output file pathname."; const char *size = "Data retrieval transfer size."; const char *log = "Enclosure Log Page ID."; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; FILE *output_fd; int xfer_size = 0; int len; @@ -12346,7 +12346,7 @@ static int wdc_enc_get_log(int argc, char **argv, struct command *acmd, struct p output_fd = fopen(cfg.file, "wb"); if (!output_fd) { fprintf(stderr, "%s: ERROR: opening:%s: %s\n", __func__, cfg.file, - nvme_strerror(errno)); + libnvme_strerror(errno)); return -EINVAL; } } else { @@ -12378,7 +12378,7 @@ static int wdc_enc_get_log(int argc, char **argv, struct command *acmd, struct p return err; } -static int wdc_enc_submit_move_data(struct nvme_transport_handle *hdl, char *cmd, int len, +static int wdc_enc_submit_move_data(struct libnvme_transport_handle *hdl, char *cmd, int len, int xfer_size, FILE *out, int log_id, int cdw14, int cdw15) { @@ -12391,14 +12391,14 @@ static int wdc_enc_submit_move_data(struct nvme_transport_handle *hdl, char *cmd buf = (char *)malloc(sizeof(__u8) * xfer_size); if (!buf) { - fprintf(stderr, "%s: ERROR: malloc: %s\n", __func__, nvme_strerror(errno)); + fprintf(stderr, "%s: ERROR: malloc: %s\n", __func__, libnvme_strerror(errno)); return -1; } /* send something no matter what */ cmd = (len) ? cmd : buf; len = (len) ? len : 0x20; - struct nvme_passthru_cmd nvme_cmd = { + struct libnvme_passthru_cmd nvme_cmd = { .opcode = WDC_NVME_ADMIN_ENC_MGMT_SND, .nsid = 0, .addr = (__u64)(uintptr_t) cmd, @@ -12430,7 +12430,7 @@ static int wdc_enc_submit_move_data(struct nvme_transport_handle *hdl, char *cmd nvme_cmd.timeout_ms, nvme_cmd.result, md, d); #endif nvme_cmd.result = 0; - err = nvme_submit_admin_passthru(hdl, &nvme_cmd); + err = libnvme_submit_admin_passthru(hdl, &nvme_cmd); if (nvme_status_equals(err, NVME_STATUS_TYPE_NVME, NVME_SC_INTERNAL)) { fprintf(stderr, "%s: WARNING : WDC: No log ID:x%x available\n", __func__, log_id); } else if (err) { @@ -12455,7 +12455,7 @@ static int wdc_enc_submit_move_data(struct nvme_transport_handle *hdl, char *cmd nvme_cmd.cdw14 = cdw14; nvme_cmd.cdw15 = cdw15; nvme_cmd.result = 0; /* returned result !=0 indicates more data available */ - err = nvme_submit_admin_passthru(hdl, &nvme_cmd); + err = libnvme_submit_admin_passthru(hdl, &nvme_cmd); if (err) { more = 0; fprintf(stderr, "%s: ERROR: WDC: NVMe Rcv Mgmt ", __func__); @@ -12477,23 +12477,23 @@ static int wdc_enc_submit_move_data(struct nvme_transport_handle *hdl, char *cmd return err; } -static int wdc_enc_get_nic_log(struct nvme_transport_handle *hdl, __u8 log_id, __u32 xfer_size, __u32 data_len, FILE *out) +static int wdc_enc_get_nic_log(struct libnvme_transport_handle *hdl, __u8 log_id, __u32 xfer_size, __u32 data_len, FILE *out) { __u8 *dump_data; __u32 curr_data_offset, curr_data_len; int i, ret = -1; - struct nvme_passthru_cmd admin_cmd; + struct libnvme_passthru_cmd admin_cmd; __u32 dump_length = data_len; __u32 numd; __u16 numdu, numdl; dump_data = (__u8 *)malloc(sizeof(__u8) * dump_length); if (!dump_data) { - fprintf(stderr, "%s: ERROR: malloc: %s\n", __func__, nvme_strerror(errno)); + fprintf(stderr, "%s: ERROR: malloc: %s\n", __func__, libnvme_strerror(errno)); return -1; } memset(dump_data, 0, sizeof(__u8) * dump_length); - memset(&admin_cmd, 0, sizeof(struct nvme_passthru_cmd)); + memset(&admin_cmd, 0, sizeof(struct libnvme_passthru_cmd)); curr_data_offset = 0; curr_data_len = xfer_size; i = 0; @@ -12515,7 +12515,7 @@ static int wdc_enc_get_nic_log(struct nvme_transport_handle *hdl, __u8 log_id, _ admin_cmd.nsid, admin_cmd.addr, admin_cmd.data_len, admin_cmd.cdw10, admin_cmd.cdw11, admin_cmd.cdw12, admin_cmd.cdw13, admin_cmd.cdw14); #endif - ret = nvme_submit_admin_passthru(hdl, &admin_cmd); + ret = libnvme_submit_admin_passthru(hdl, &admin_cmd); if (ret) { nvme_show_status(ret); fprintf(stderr, "%s: ERROR: WDC: Get chunk %d, size = 0x%x, offset = 0x%x, addr = 0x%lx\n", @@ -12553,8 +12553,8 @@ int wdc_set_latency_monitor_feature(int argc, char **argv, struct command *acmd, const char *desc = "Set Latency Monitor feature."; struct feature_latency_monitor buf = {0,}; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; uint64_t capabilities = 0; __u64 result; int ret; @@ -12635,7 +12635,7 @@ int wdc_set_latency_monitor_feature(int argc, char **argv, struct command *acmd, return ret; /* get capabilities */ - ret = nvme_scan_topology(ctx, NULL, NULL); + ret = libnvme_scan_topology(ctx, NULL, NULL); if (ret || !wdc_check_device(ctx, hdl)) return -1; @@ -12683,7 +12683,7 @@ int wdc_set_latency_monitor_feature(int argc, char **argv, struct command *acmd, buf.latency_monitor_feature_enable); } else if (ret > 0) fprintf(stderr, "NVMe Status:%s(%x)\n", - nvme_status_to_string(ret, false), ret); + libnvme_status_to_string(ret, false), ret); return ret; } @@ -12881,14 +12881,14 @@ int run_wdc_cu_smart_log(int argc, char **argv, } -__u32 run_wdc_get_fw_cust_id(struct nvme_global_ctx *ctx, - struct nvme_transport_handle *hdl) +__u32 run_wdc_get_fw_cust_id(struct libnvme_global_ctx *ctx, + struct libnvme_transport_handle *hdl) { return wdc_get_fw_cust_id(ctx, hdl); } -bool run_wdc_nvme_check_supported_log_page(struct nvme_global_ctx *ctx, - struct nvme_transport_handle *hdl, +bool run_wdc_nvme_check_supported_log_page(struct libnvme_global_ctx *ctx, + struct libnvme_transport_handle *hdl, __u8 log_id, __u8 uuid_index) { @@ -12898,8 +12898,8 @@ bool run_wdc_nvme_check_supported_log_page(struct nvme_global_ctx *ctx, uuid_index); } -__u64 run_wdc_get_drive_capabilities(struct nvme_global_ctx *ctx, - struct nvme_transport_handle *hdl) +__u64 run_wdc_get_drive_capabilities(struct libnvme_global_ctx *ctx, + struct libnvme_transport_handle *hdl) { return wdc_get_drive_capabilities(ctx, hdl); } diff --git a/plugins/wdc/wdc-utils.c b/plugins/wdc/wdc-utils.c index 7e6afaf014..81ace2dfc7 100644 --- a/plugins/wdc/wdc-utils.c +++ b/plugins/wdc/wdc-utils.c @@ -169,7 +169,7 @@ void wdc_StrFormat(char *formatter, size_t fmt_sz, char *tofmt, size_t tofmtsz) } } -bool wdc_CheckUuidListSupport(struct nvme_transport_handle *hdl, +bool wdc_CheckUuidListSupport(struct libnvme_transport_handle *hdl, struct nvme_id_uuid_list *uuid_list) { struct nvme_id_ctrl ctrl; @@ -189,7 +189,7 @@ bool wdc_CheckUuidListSupport(struct nvme_transport_handle *hdl, else if (err > 0) nvme_show_status(err); else - nvme_show_error("identify UUID list: %s", nvme_strerror(errno)); + nvme_show_error("identify UUID list: %s", libnvme_strerror(errno)); } return false; diff --git a/plugins/wdc/wdc-utils.h b/plugins/wdc/wdc-utils.h index 6b87891543..d185d383ea 100644 --- a/plugins/wdc/wdc-utils.h +++ b/plugins/wdc/wdc-utils.h @@ -76,4 +76,4 @@ int wdc_UtilsStrCompare(const char *pcSrc, const char *pcDst); int wdc_UtilsCreateDir(const char *path); int wdc_WriteToFile(const char *fileName, const char *buffer, unsigned int bufferLen); void wdc_StrFormat(char *formatter, size_t fmt_sz, char *tofmt, size_t tofmtsz); -bool wdc_CheckUuidListSupport(struct nvme_transport_handle *hdl, struct nvme_id_uuid_list *uuid_list); +bool wdc_CheckUuidListSupport(struct libnvme_transport_handle *hdl, struct nvme_id_uuid_list *uuid_list); diff --git a/plugins/ymtc/ymtc-nvme.c b/plugins/ymtc/ymtc-nvme.c index 6f4a5e5d1d..dfbdd1c76c 100644 --- a/plugins/ymtc/ymtc-nvme.c +++ b/plugins/ymtc/ymtc-nvme.c @@ -22,7 +22,7 @@ static void get_ymtc_smart_info(struct nvme_ymtc_smart_log *smart, int index, u8 memcpy(raw_val, smart->itemArr[index].rawVal, RAW_SIZE); } -static int show_ymtc_smart_log(struct nvme_transport_handle *hdl, __u32 nsid, +static int show_ymtc_smart_log(struct libnvme_transport_handle *hdl, __u32 nsid, struct nvme_ymtc_smart_log *smart) { struct nvme_id_ctrl ctrl; @@ -53,7 +53,7 @@ static int show_ymtc_smart_log(struct nvme_transport_handle *hdl, __u32 nsid, /* Table Title */ printf("Additional Smart Log for NVME device:%s namespace-id:%x\n", - nvme_transport_handle_get_name(hdl), nsid); + libnvme_transport_handle_get_name(hdl), nsid); /* Column Name*/ printf("key normalized raw\n"); /* 00 SI_VD_PROGRAM_FAIL */ @@ -124,8 +124,8 @@ static int get_additional_smart_log(int argc, char **argv, struct command *acmd, "Get Ymtc vendor specific additional smart log (optionally, for the specified namespace), and show it."; const char *namespace = "(optional) desired namespace"; const char *raw = "dump output in binary format"; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; struct config { __u32 namespace_id; bool raw_binary; diff --git a/plugins/zns/zns.c b/plugins/zns/zns.c index 9a988e01dc..9aeec6e2ae 100644 --- a/plugins/zns/zns.c +++ b/plugins/zns/zns.c @@ -24,14 +24,14 @@ static const char *namespace_id = "Namespace identifier to use"; -static int detect_zns(nvme_ns_t ns, int *out_supported) +static int detect_zns(libnvme_ns_t ns, int *out_supported) { int err = 0; char *zoned; *out_supported = 0; - zoned = nvme_get_attr(nvme_ns_get_sysfs_dir(ns), "queue/zoned"); + zoned = libnvme_get_attr(libnvme_ns_get_sysfs_dir(ns), "queue/zoned"); if (!zoned) { *out_supported = 0; return err; @@ -43,7 +43,7 @@ static int detect_zns(nvme_ns_t ns, int *out_supported) return err; } -static int print_zns_list_ns(nvme_ns_t ns, struct table *t) +static int print_zns_list_ns(libnvme_ns_t ns, struct table *t) { int supported; int err = 0; @@ -60,24 +60,24 @@ static int print_zns_list_ns(nvme_ns_t ns, struct table *t) return err; } -static int print_zns_list(struct nvme_global_ctx *ctx, struct table *t) +static int print_zns_list(struct libnvme_global_ctx *ctx, struct table *t) { int err = 0; - nvme_host_t h; - nvme_subsystem_t s; - nvme_ctrl_t c; - nvme_ns_t n; - - nvme_for_each_host(ctx, h) { - nvme_for_each_subsystem(h, s) { - nvme_subsystem_for_each_ns(s, n) { + libnvme_host_t h; + libnvme_subsystem_t s; + libnvme_ctrl_t c; + libnvme_ns_t n; + + libnvme_for_each_host(ctx, h) { + libnvme_for_each_subsystem(h, s) { + libnvme_subsystem_for_each_ns(s, n) { err = print_zns_list_ns(n, t); if (err) return err; } - nvme_subsystem_for_each_ctrl(s, c) { - nvme_ctrl_for_each_ns(c, n) { + libnvme_subsystem_for_each_ctrl(s, c) { + libnvme_ctrl_for_each_ns(c, n) { err = print_zns_list_ns(n, t); if (err) return err; @@ -92,7 +92,7 @@ static int print_zns_list(struct nvme_global_ctx *ctx, struct table *t) static int list(int argc, char **argv, struct command *acmd, struct plugin *plugin) { - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; int err; struct table_column columns[] = { { "Node", LEFT, 21 }, @@ -106,13 +106,13 @@ static int list(int argc, char **argv, struct command *acmd, }; struct table *t = table_init_with_columns(columns, ARRAY_SIZE(columns)); - ctx = nvme_create_global_ctx(stdout, DEFAULT_LOGLEVEL); + ctx = libnvme_create_global_ctx(stdout, DEFAULT_LOGLEVEL); if (ctx) { fprintf(stderr, "Failed to create root object\n"); return -ENOMEM; } - err = nvme_scan_topology(ctx, NULL, NULL); + err = libnvme_scan_topology(ctx, NULL, NULL); if (err) { fprintf(stderr, "Failed to scan nvme subsystems\n"); return err; @@ -133,9 +133,9 @@ static int id_ctrl(int argc, char **argv, struct command *acmd, struct plugin *p "the given device and report information about the specified\n" "controller in various formats."; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; - struct nvme_passthru_cmd cmd; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; + struct libnvme_passthru_cmd cmd; struct nvme_zns_id_ctrl ctrl; nvme_print_flags_t flags; int err = -1; @@ -151,7 +151,7 @@ static int id_ctrl(int argc, char **argv, struct command *acmd, struct plugin *p return err; nvme_init_zns_identify_ctrl(&cmd, &ctrl); - err = nvme_submit_admin_passthru(hdl, &cmd); + err = libnvme_submit_admin_passthru(hdl, &cmd); if (!err) nvme_show_zns_id_ctrl(&ctrl, flags); else if (err > 0) @@ -170,8 +170,8 @@ static int id_ns(int argc, char **argv, struct command *acmd, struct plugin *plu const char *vendor_specific = "dump binary vendor fields"; const char *human_readable = "show identify in readable format"; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; nvme_print_flags_t flags; struct nvme_zns_id_ns ns; struct nvme_id_ns id_ns; @@ -203,7 +203,7 @@ static int id_ns(int argc, char **argv, struct command *acmd, struct plugin *plu flags |= VERBOSE; if (!cfg.namespace_id) { - err = nvme_get_nsid(hdl, &cfg.namespace_id); + err = libnvme_get_nsid(hdl, &cfg.namespace_id); if (err < 0) { perror("get-namespace-id"); return err; @@ -232,9 +232,9 @@ static int zns_mgmt_send(int argc, char **argv, struct command *acmd, struct plu { const char *zslba = "starting LBA of the zone for this command"; const char *select_all = "send command to all zones"; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - struct nvme_passthru_cmd cmd; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + struct libnvme_passthru_cmd cmd; int err, zcapc = 0; char *cmdstr; @@ -260,7 +260,7 @@ static int zns_mgmt_send(int argc, char **argv, struct command *acmd, struct plu return err; if (!cfg.namespace_id) { - err = nvme_get_nsid(hdl, &cfg.namespace_id); + err = libnvme_get_nsid(hdl, &cfg.namespace_id); if (err < 0) { perror("get-namespace-id"); goto free; @@ -269,7 +269,7 @@ static int zns_mgmt_send(int argc, char **argv, struct command *acmd, struct plu nvme_init_zns_mgmt_send(&cmd, cfg.namespace_id, cfg.zslba, zsa, cfg.select_all, 0, 0, NULL, 0); - err = nvme_submit_admin_passthru(hdl, &cmd); + err = libnvme_submit_admin_passthru(hdl, &cmd); if (!err) { if (zsa == NVME_ZNS_ZSA_RESET) zcapc = cmd.result & 0x1; @@ -287,7 +287,7 @@ static int zns_mgmt_send(int argc, char **argv, struct command *acmd, struct plu return err; } -static int get_zdes_bytes(struct nvme_transport_handle *hdl, __u32 nsid) +static int get_zdes_bytes(struct libnvme_transport_handle *hdl, __u32 nsid) { struct nvme_zns_id_ns ns; struct nvme_id_ns id_ns; @@ -327,10 +327,10 @@ static int zone_mgmt_send(int argc, char **argv, struct command *acmd, struct pl const char *data_len = "buffer length if data required"; const char *data = "optional file for data (default stdin)"; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; int ffd = STDIN_FILENO, err = -1; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; void *buf = NULL; struct config { @@ -359,7 +359,7 @@ static int zone_mgmt_send(int argc, char **argv, struct command *acmd, struct pl return errno; if (!cfg.namespace_id) { - err = nvme_get_nsid(hdl, &cfg.namespace_id); + err = libnvme_get_nsid(hdl, &cfg.namespace_id); if (err < 0) { perror("get-namespace-id"); return err; @@ -413,7 +413,7 @@ static int zone_mgmt_send(int argc, char **argv, struct command *acmd, struct pl nvme_init_zns_mgmt_send(&cmd, cfg.namespace_id, cfg.zslba, cfg.zsa, cfg.select_all, cfg.zsaso, 0, buf, cfg.data_len); - err = nvme_submit_admin_passthru(hdl, &cmd); + err = libnvme_submit_admin_passthru(hdl, &cmd); if (!err) printf("zone-mgmt-send: Success, action:%d zone:%"PRIx64" all:%d nsid:%d\n", cfg.zsa, (uint64_t)cfg.zslba, (int)cfg.select_all, cfg.namespace_id); @@ -450,9 +450,9 @@ static int open_zone(int argc, char **argv, struct command *acmd, struct plugin const char *zslba = "starting LBA of the zone for this command"; const char *zrwaa = "Allocate Zone Random Write Area to zone"; const char *select_all = "send command to all zones"; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - struct nvme_passthru_cmd cmd; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + struct libnvme_passthru_cmd cmd; int err; struct config { @@ -476,7 +476,7 @@ static int open_zone(int argc, char **argv, struct command *acmd, struct plugin return errno; if (!cfg.namespace_id) { - err = nvme_get_nsid(hdl, &cfg.namespace_id); + err = libnvme_get_nsid(hdl, &cfg.namespace_id); if (err < 0) { perror("get-namespace-id"); return err; @@ -486,7 +486,7 @@ static int open_zone(int argc, char **argv, struct command *acmd, struct plugin nvme_init_zns_mgmt_send(&cmd, cfg.namespace_id, cfg.zslba, NVME_ZNS_ZSA_OPEN, cfg.select_all, cfg.zrwaa, 0, NULL, 0); - err = nvme_submit_admin_passthru(hdl, &cmd); + err = libnvme_submit_admin_passthru(hdl, &cmd); if (!err) printf("zns-open-zone: Success zone slba:%"PRIx64" nsid:%d\n", (uint64_t)cfg.zslba, cfg.namespace_id); @@ -519,9 +519,9 @@ static int set_zone_desc(int argc, char **argv, struct command *acmd, struct plu const char *zrwaa = "Allocate Zone Random Write Area to zone"; const char *data = "optional file for zone extension data (default stdin)"; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - struct nvme_passthru_cmd cmd; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + struct libnvme_passthru_cmd cmd; int ffd = STDIN_FILENO, err; void *buf = NULL; int data_len; @@ -546,7 +546,7 @@ static int set_zone_desc(int argc, char **argv, struct command *acmd, struct plu return errno; if (!cfg.namespace_id) { - err = nvme_get_nsid(hdl, &cfg.namespace_id); + err = libnvme_get_nsid(hdl, &cfg.namespace_id); if (err < 0) { perror("get-namespace-id"); return err; @@ -585,7 +585,7 @@ static int set_zone_desc(int argc, char **argv, struct command *acmd, struct plu nvme_init_zns_mgmt_send(&cmd, cfg.namespace_id, cfg.zslba, NVME_ZNS_ZSA_SET_DESC_EXT, 0, cfg.zrwaa, 0, buf, data_len); - err = nvme_submit_admin_passthru(hdl, &cmd); + err = libnvme_submit_admin_passthru(hdl, &cmd); if (!err) printf("set-zone-desc: Success, zone:%"PRIx64" nsid:%d\n", (uint64_t)cfg.zslba, cfg.namespace_id); @@ -607,9 +607,9 @@ static int zrwa_flush_zone(int argc, char **argv, struct command *acmd, struct p { const char *desc = "Flush Explicit ZRWA Range"; const char *slba = "LBA to flush up to"; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - struct nvme_passthru_cmd cmd; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + struct libnvme_passthru_cmd cmd; int err; struct config { @@ -628,7 +628,7 @@ static int zrwa_flush_zone(int argc, char **argv, struct command *acmd, struct p return errno; if (!cfg.namespace_id) { - err = nvme_get_nsid(hdl, &cfg.namespace_id); + err = libnvme_get_nsid(hdl, &cfg.namespace_id); if (err < 0) { perror("get-namespace-id"); return err; @@ -637,7 +637,7 @@ static int zrwa_flush_zone(int argc, char **argv, struct command *acmd, struct p nvme_init_zns_mgmt_send(&cmd, cfg.namespace_id, cfg.lba, NVME_ZNS_ZSA_ZRWA_FLUSH, 0, 0, 0, NULL, 0); - err = nvme_submit_admin_passthru(hdl, &cmd); + err = libnvme_submit_admin_passthru(hdl, &cmd); if (!err) printf("zrwa-flush-zone: Success, lba:%"PRIx64" nsid:%d\n", (uint64_t)cfg.lba, cfg.namespace_id); @@ -658,9 +658,9 @@ static int zone_mgmt_recv(int argc, char **argv, struct command *acmd, struct pl const char *partial = "Zone Receive Action Specific Features(Partial Report)"; const char *data_len = "length of data in bytes"; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - struct nvme_passthru_cmd cmd; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + struct libnvme_passthru_cmd cmd; nvme_print_flags_t flags; void *data = NULL; int err = -1; @@ -693,7 +693,7 @@ static int zone_mgmt_recv(int argc, char **argv, struct command *acmd, struct pl return err; if (!cfg.namespace_id) { - err = nvme_get_nsid(hdl, &cfg.namespace_id); + err = libnvme_get_nsid(hdl, &cfg.namespace_id); if (err < 0) { perror("get-namespace-id"); return err; @@ -714,7 +714,7 @@ static int zone_mgmt_recv(int argc, char **argv, struct command *acmd, struct pl nvme_init_zns_mgmt_recv(&cmd, cfg.namespace_id, cfg.zslba, cfg.zra, cfg.zrasf, cfg.partial, data, cfg.data_len); - err = nvme_submit_admin_passthru(hdl, &cmd); + err = libnvme_submit_admin_passthru(hdl, &cmd); if (!err) printf("zone-mgmt-recv: Success, action:%d zone:%"PRIx64" nsid:%d\n", cfg.zra, (uint64_t)cfg.zslba, cfg.namespace_id); @@ -738,11 +738,11 @@ static int report_zones(int argc, char **argv, struct command *acmd, struct plug const char *part = "set to use the partial report"; const char *verbose = "show report zones verbosity"; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; _cleanup_huge_ struct nvme_mem_huge mh = { 0, }; struct nvme_zone_report *report, *buff; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; nvme_print_flags_t flags; int zdes = 0, err = -1; __u32 report_size; @@ -793,7 +793,7 @@ static int report_zones(int argc, char **argv, struct command *acmd, struct plug flags |= VERBOSE; if (!cfg.namespace_id) { - err = nvme_get_nsid(hdl, &cfg.namespace_id); + err = libnvme_get_nsid(hdl, &cfg.namespace_id); if (err < 0) { perror("get-namespace-id"); return err; @@ -830,7 +830,7 @@ static int report_zones(int argc, char **argv, struct command *acmd, struct plug nvme_init_zns_report_zones(&cmd, cfg.namespace_id, 0, cfg.state, false, false, buff, log_len); - err = nvme_submit_io_passthru(hdl, &cmd); + err = libnvme_submit_io_passthru(hdl, &cmd); if (err > 0) { nvme_show_status(err); goto free_buff; @@ -873,7 +873,7 @@ static int report_zones(int argc, char **argv, struct command *acmd, struct plug nvme_init_zns_report_zones(&cmd, cfg.namespace_id, offset, cfg.state, cfg.extended, cfg.partial, report, log_len); - err = nvme_submit_io_passthru(hdl, &cmd); + err = libnvme_submit_io_passthru(hdl, &cmd); if (err > 0) { nvme_show_status(err); break; @@ -914,13 +914,13 @@ static int zone_append(int argc, char **argv, struct command *acmd, struct plugi const char *data_size = "size of data in bytes"; const char *latency = "output latency statistics"; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; int err = -1, dfd = STDIN_FILENO, mfd = STDIN_FILENO; struct timeval start_time, end_time; unsigned int lba_size, meta_size; void *buf = NULL, *mbuf = NULL; - struct nvme_passthru_cmd cmd; + struct libnvme_passthru_cmd cmd; __u16 nblocks, control = 0; __u16 cev = 0, dspec = 0; __u8 lba_index; @@ -966,7 +966,7 @@ static int zone_append(int argc, char **argv, struct command *acmd, struct plugi } if (!cfg.namespace_id) { - err = nvme_get_nsid(hdl, &cfg.namespace_id); + err = libnvme_get_nsid(hdl, &cfg.namespace_id); if (err < 0) { perror("get-namespace-id"); return err;; @@ -1061,7 +1061,7 @@ static int zone_append(int argc, char **argv, struct command *acmd, struct plugi nvme_init_zns_append(&cmd, cfg.namespace_id, cfg.zslba, nblocks, control, cev, dspec, buf, cfg.data_size, mbuf, cfg.metadata_size); - err = nvme_submit_admin_passthru(hdl, &cmd); + err = libnvme_submit_admin_passthru(hdl, &cmd); gettimeofday(&end_time, NULL); if (cfg.latency) printf(" latency: zone append: %llu us\n", @@ -1094,8 +1094,8 @@ static int changed_zone_list(int argc, char **argv, struct command *acmd, struct const char *desc = "Retrieve Changed Zone log for the given device"; const char *rae = "retain an asynchronous event"; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; - _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL; + _cleanup_nvme_transport_handle_ struct libnvme_transport_handle *hdl = NULL; struct nvme_zns_changed_zone_log log; nvme_print_flags_t flags; int err = -1; @@ -1120,7 +1120,7 @@ static int changed_zone_list(int argc, char **argv, struct command *acmd, struct return err; if (!cfg.namespace_id) { - err = nvme_get_nsid(hdl, &cfg.namespace_id); + err = libnvme_get_nsid(hdl, &cfg.namespace_id); if (err < 0) { perror("get-namespace-id"); return err; diff --git a/unit/test-argconfig-parse.c b/unit/test-argconfig-parse.c index 29ab6907a8..5db83d7af1 100644 --- a/unit/test-argconfig-parse.c +++ b/unit/test-argconfig-parse.c @@ -11,7 +11,7 @@ #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) -const char *nvme_strerror(int errnum); +const char *libnvme_strerror(int errnum); static int test_rc; @@ -221,7 +221,7 @@ int main(void) setlocale(LC_NUMERIC, "C"); f = freopen("/dev/null", "w", stderr); if (!f) - printf("ERROR: reopening stderr failed: %s\n", nvme_strerror(errno)); + printf("ERROR: reopening stderr failed: %s\n", libnvme_strerror(errno)); for (i = 0; i < ARRAY_SIZE(toval_tests); i++) toval_test(&toval_tests[i]); diff --git a/util/argconfig.c b/util/argconfig.c index dded73c876..8557c82ae7 100644 --- a/util/argconfig.c +++ b/util/argconfig.c @@ -44,7 +44,7 @@ #include "cleanup.h" #include "suffix.h" -const char *nvme_strerror(int errnum); +const char *libnvme_strerror(int errnum); static bool is_null_or_empty(const char *s) { @@ -317,7 +317,7 @@ int argconfig_parse(int argc, char *argv[], const char *program_desc, short_opts = calloc(options_count * 3 + 3, sizeof(*short_opts)); if (!long_opts || !short_opts) { - fprintf(stderr, "failed to allocate memory for opts: %s\n", nvme_strerror(errno)); + fprintf(stderr, "failed to allocate memory for opts: %s\n", libnvme_strerror(errno)); return -errno; } diff --git a/util/cleanup.h b/util/cleanup.h index 95cba332f5..354effca94 100644 --- a/util/cleanup.h +++ b/util/cleanup.h @@ -36,17 +36,17 @@ static inline void cleanup_fd(int *fd) } #define _cleanup_fd_ __cleanup__(cleanup_fd) -static inline void cleanup_nvme_global_ctx(struct nvme_global_ctx **ctx) +static inline void cleanup_nvme_global_ctx(struct libnvme_global_ctx **ctx) { - nvme_free_global_ctx(*ctx); + libnvme_free_global_ctx(*ctx); } #define _cleanup_nvme_global_ctx_ __cleanup__(cleanup_nvme_global_ctx) -static inline DEFINE_CLEANUP_FUNC(cleanup_nvme_ctrl, nvme_ctrl_t, nvme_free_ctrl) +static inline DEFINE_CLEANUP_FUNC(cleanup_nvme_ctrl, libnvme_ctrl_t, libnvme_free_ctrl) #define _cleanup_nvme_ctrl_ __cleanup__(cleanup_nvme_ctrl) #ifdef CONFIG_FABRICS -static inline void free_uri(struct nvme_fabrics_uri **uri) +static inline void free_uri(struct libnvme_fabrics_uri **uri) { if (*uri) nvmf_free_uri(*uri); diff --git a/util/types.c b/util/types.c index 0c58f175dd..5d17af48c1 100644 --- a/util/types.c +++ b/util/types.c @@ -151,7 +151,7 @@ const char *util_uuid_to_string(unsigned char uuid[NVME_UUID_LEN]) { static char uuid_str[NVME_UUID_LEN_STRING]; - nvme_uuid_to_string(uuid, uuid_str); + libnvme_uuid_to_string(uuid, uuid_str); return uuid_str; }