diff --git a/nvme.c b/nvme.c index f946bb509a..f5d07e0e34 100644 --- a/nvme.c +++ b/nvme.c @@ -2088,16 +2088,17 @@ 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_global_ctx_ struct nvme_global_ctx *ctx = NULL; _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; + _cleanup_fd_ int dfd = STDIN_FILENO; _cleanup_free_ void *buf = NULL; + struct nvme_passthru_cmd cmd; int err = -1; - _cleanup_fd_ int dfd = STDIN_FILENO; struct config { + __u32 nsid; __u16 mos; __u8 mo; - __u32 namespace_id; char *file; __u32 data_len; }; @@ -2107,18 +2108,18 @@ static int io_mgmt_send(int argc, char **argv, struct command *acmd, struct plug }; NVME_ARGS(opts, - OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_id_desired), - OPT_SHRT("mos", 's', &cfg.mos, mos), - OPT_BYTE("mo", 'm', &cfg.mo, mo), - OPT_FILE("data", 'd', &cfg.file, data), - OPT_UINT("data-len", 'l', &cfg.data_len, buf_len)); + OPT_UINT("namespace-id", 'n', &cfg.nsid, namespace_id_desired), + OPT_SHRT("mos", 's', &cfg.mos, mos), + OPT_BYTE("mo", 'm', &cfg.mo, mo), + OPT_FILE("data", 'd', &cfg.file, data), + OPT_UINT("data-len", 'l', &cfg.data_len, buf_len)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) return err; - if (!cfg.namespace_id) { - err = nvme_get_nsid(hdl, &cfg.namespace_id); + if (!cfg.nsid) { + err = nvme_get_nsid(hdl, &cfg.nsid); if (err < 0) { nvme_show_perror("get-namespace-id"); return err; @@ -2145,20 +2146,11 @@ static int io_mgmt_send(int argc, char **argv, struct command *acmd, struct plug return err; } - struct nvme_io_mgmt_send_args args = { - .args_size = sizeof(args), - .nsid = cfg.namespace_id, - .mos = cfg.mos, - .mo = cfg.mo, - .data_len = cfg.data_len, - .data = buf, - .timeout = nvme_cfg.timeout, - }; - - err = nvme_io_mgmt_send(hdl, &args); + nvme_init_io_mgmt_send(&cmd, cfg.nsid, cfg.mo, cfg.mos, buf, cfg.data_len); + err = nvme_submit_io_passthru(hdl, &cmd, NULL); if (!err) printf("io-mgmt-send: Success, mos:%u mo:%u nsid:%d\n", - cfg.mos, cfg.mo, cfg.namespace_id); + cfg.mos, cfg.mo, cfg.nsid); else if (err > 0) nvme_show_status(err); else @@ -2172,16 +2164,17 @@ 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_global_ctx_ struct nvme_global_ctx *ctx = NULL; _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; _cleanup_free_ void *buf = NULL; - int err = -1; + struct nvme_passthru_cmd cmd; _cleanup_fd_ int dfd = -1; + int err = -1; struct config { __u16 mos; __u8 mo; - __u32 namespace_id; + __u32 nsid; char *file; __u32 data_len; }; @@ -2191,18 +2184,18 @@ static int io_mgmt_recv(int argc, char **argv, struct command *acmd, struct plug }; NVME_ARGS(opts, - OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_id_desired), - OPT_SHRT("mos", 's', &cfg.mos, mos), - OPT_BYTE("mo", 'm', &cfg.mo, mo), - OPT_FILE("data", 'd', &cfg.file, data), - OPT_UINT("data-len", 'l', &cfg.data_len, buf_len)); + OPT_UINT("namespace-id", 'n', &cfg.nsid, namespace_id_desired), + OPT_SHRT("mos", 's', &cfg.mos, mos), + OPT_BYTE("mo", 'm', &cfg.mo, mo), + OPT_FILE("data", 'd', &cfg.file, data), + OPT_UINT("data-len", 'l', &cfg.data_len, buf_len)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) return err; - if (!cfg.namespace_id) { - err = nvme_get_nsid(hdl, &cfg.namespace_id); + if (!cfg.nsid) { + err = nvme_get_nsid(hdl, &cfg.nsid); if (err < 0) { nvme_show_perror("get-namespace-id"); return err; @@ -2215,20 +2208,12 @@ static int io_mgmt_recv(int argc, char **argv, struct command *acmd, struct plug return -ENOMEM; } - struct nvme_io_mgmt_recv_args args = { - .args_size = sizeof(args), - .nsid = cfg.namespace_id, - .mos = cfg.mos, - .mo = cfg.mo, - .data_len = cfg.data_len, - .data = buf, - .timeout = nvme_cfg.timeout, - }; - - err = nvme_io_mgmt_recv(hdl, &args); + nvme_init_io_mgmt_recv(&cmd, cfg.nsid, cfg.mo, cfg.mos, buf, + cfg.data_len); + err = nvme_submit_io_passthru(hdl, &cmd, NULL); if (!err) { printf("io-mgmt-recv: Success, mos:%u mo:%u nsid:%d\n", - cfg.mos, cfg.mo, cfg.namespace_id); + cfg.mos, cfg.mo, cfg.nsid); if (cfg.file) { dfd = open(cfg.file, O_WRONLY | O_CREAT, 0644); @@ -7814,13 +7799,15 @@ 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_global_ctx_ struct nvme_global_ctx *ctx = NULL; _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; - int err; + _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; + struct nvme_passthru_cmd cmd; nvme_print_flags_t flags; + __le64 payload[1]; + int err; struct config { - __u32 namespace_id; + __u32 nsid; __u64 crkey; __u8 rtype; __u8 rrela; @@ -7828,7 +7815,7 @@ static int resv_release(int argc, char **argv, struct command *acmd, struct plug }; struct config cfg = { - .namespace_id = 0, + .nsid = 0, .crkey = 0, .rtype = 0, .rrela = 0, @@ -7836,11 +7823,11 @@ static int resv_release(int argc, char **argv, struct command *acmd, struct plug }; NVME_ARGS(opts, - OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_desired), - OPT_SUFFIX("crkey", 'c', &cfg.crkey, crkey), - OPT_BYTE("rtype", 't', &cfg.rtype, rtype), - OPT_BYTE("rrela", 'a', &cfg.rrela, rrela), - OPT_FLAG("iekey", 'i', &cfg.iekey, iekey)); + OPT_UINT("namespace-id", 'n', &cfg.nsid, namespace_desired), + OPT_SUFFIX("crkey", 'c', &cfg.crkey, crkey), + OPT_BYTE("rtype", 't', &cfg.rtype, rtype), + OPT_BYTE("rrela", 'a', &cfg.rrela, rrela), + OPT_FLAG("iekey", 'i', &cfg.iekey, iekey)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) @@ -7852,8 +7839,8 @@ static int resv_release(int argc, char **argv, struct command *acmd, struct plug return err; } - if (!cfg.namespace_id) { - err = nvme_get_nsid(hdl, &cfg.namespace_id); + if (!cfg.nsid) { + err = nvme_get_nsid(hdl, &cfg.nsid); if (err < 0) { nvme_show_error("get-namespace-id: %s", nvme_strerror(-err)); return err; @@ -7864,17 +7851,9 @@ static int resv_release(int argc, char **argv, struct command *acmd, struct plug return -EINVAL; } - struct nvme_resv_release_args args = { - .args_size = sizeof(args), - .nsid = cfg.namespace_id, - .rtype = cfg.rtype, - .rrela = cfg.rrela, - .iekey = !!cfg.iekey, - .crkey = cfg.crkey, - .timeout = nvme_cfg.timeout, - .result = NULL, - }; - err = nvme_resv_release(hdl, &args); + nvme_init_resv_release(&cmd, cfg.nsid, cfg.rrela, cfg.iekey, false, + cfg.rtype, cfg.crkey, payload); + err = nvme_submit_io_passthru(hdl, &cmd, NULL); if (err < 0) nvme_show_error("reservation release: %s", nvme_strerror(-err)); else if (err != 0) @@ -7894,32 +7873,33 @@ 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_free_ struct nvme_resv_status *status = NULL; _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; + struct nvme_passthru_cmd cmd; nvme_print_flags_t flags; int err, size; struct config { - __u32 namespace_id; + __u32 nsid; __u32 numd; __u8 eds; bool raw_binary; }; struct config cfg = { - .namespace_id = 0, + .nsid = 0, .numd = 0, .eds = false, .raw_binary = false, }; NVME_ARGS(opts, - OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_id_desired), - OPT_UINT("numd", 'd', &cfg.numd, numd), - OPT_FLAG("eds", 'e', &cfg.eds, eds), - OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw_dump)); + OPT_UINT("namespace-id", 'n', &cfg.nsid, namespace_id_desired), + OPT_UINT("numd", 'd', &cfg.numd, numd), + OPT_FLAG("eds", 'e', &cfg.eds, eds), + OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw_dump)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) @@ -7934,8 +7914,8 @@ static int resv_report(int argc, char **argv, struct command *acmd, struct plugi if (cfg.raw_binary) flags = BINARY; - if (!cfg.namespace_id) { - err = nvme_get_nsid(hdl, &cfg.namespace_id); + if (!cfg.nsid) { + err = nvme_get_nsid(hdl, &cfg.nsid); if (err < 0) { nvme_show_error("get-namespace-id: %s", nvme_strerror(-err)); return err; @@ -7966,16 +7946,8 @@ static int resv_report(int argc, char **argv, struct command *acmd, struct plugi if (!status) return -ENOMEM; - struct nvme_resv_report_args args = { - .args_size = sizeof(args), - .nsid = cfg.namespace_id, - .eds = cfg.eds, - .len = size, - .report = status, - .timeout = nvme_cfg.timeout, - .result = NULL, - }; - err = nvme_resv_report(hdl, &args); + nvme_init_resv_report(&cmd, cfg.nsid, cfg.eds, false, status, size); + err = nvme_submit_io_passthru(hdl, &cmd, NULL); if (!err) nvme_show_resv_report(status, size, cfg.eds, flags); else if (err > 0) diff --git a/plugins/fdp/fdp.c b/plugins/fdp/fdp.c index abbd434d18..00ba0335d6 100644 --- a/plugins/fdp/fdp.c +++ b/plugins/fdp/fdp.c @@ -293,16 +293,17 @@ 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_global_ctx_ struct nvme_global_ctx *ctx = NULL; _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; _cleanup_free_ void *buf = NULL; struct nvme_fdp_ruh_status hdr; + struct nvme_passthru_cmd cmd; nvme_print_flags_t flags; int err = -1; size_t len; struct config { - __u32 namespace_id; + __u32 nsid; char *output_format; bool raw_binary; }; @@ -313,9 +314,9 @@ static int fdp_status(int argc, char **argv, struct command *acmd, struct plugin }; OPT_ARGS(opts) = { - OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_id), - OPT_FMT("output-format", 'o', &cfg.output_format, output_format), - OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw), + OPT_UINT("namespace-id", 'n', &cfg.nsid, namespace_id), + OPT_FMT("output-format", 'o', &cfg.output_format, output_format), + OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw), OPT_END() }; @@ -330,16 +331,17 @@ static int fdp_status(int argc, char **argv, struct command *acmd, struct plugin if (cfg.raw_binary) flags = BINARY; - if (!cfg.namespace_id) { - err = nvme_get_nsid(hdl, &cfg.namespace_id); + if (!cfg.nsid) { + err = nvme_get_nsid(hdl, &cfg.nsid); if (err < 0) { perror("get-namespace-id"); return err; } } - err = nvme_fdp_reclaim_unit_handle_status(hdl, - cfg.namespace_id, sizeof(hdr), &hdr); + nvme_init_fdp_reclaim_unit_handle_status(&cmd, cfg.nsid, &hdr, + sizeof(hdr)); + err = nvme_submit_io_passthru(hdl, &cmd, NULL); if (err) { nvme_show_status(err); return err; @@ -351,8 +353,8 @@ static int fdp_status(int argc, char **argv, struct command *acmd, struct plugin if (!buf) return -ENOMEM; - err = nvme_fdp_reclaim_unit_handle_status(hdl, - cfg.namespace_id, len, buf); + nvme_init_fdp_reclaim_unit_handle_status(&cmd, cfg.nsid, buf, len); + err = nvme_submit_io_passthru(hdl, &cmd, NULL); if (err) { nvme_show_status(err); return err; @@ -369,15 +371,16 @@ 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_global_ctx_ struct nvme_global_ctx *ctx = NULL; _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; unsigned short pids[256]; __u16 buf[256]; - int npids; int err = -1; + int npids; struct config { - __u32 namespace_id; + __u32 nsid; char *pids; }; @@ -386,8 +389,8 @@ static int fdp_update(int argc, char **argv, struct command *acmd, struct plugin }; OPT_ARGS(opts) = { - OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_id), - OPT_LIST("pids", 'p', &cfg.pids, _pids), + OPT_UINT("namespace-id", 'n', &cfg.nsid, namespace_id), + OPT_LIST("pids", 'p', &cfg.pids, _pids), OPT_END() }; @@ -404,8 +407,8 @@ static int fdp_update(int argc, char **argv, struct command *acmd, struct plugin return -EINVAL; } - if (!cfg.namespace_id) { - err = nvme_get_nsid(hdl, &cfg.namespace_id); + if (!cfg.nsid) { + err = nvme_get_nsid(hdl, &cfg.nsid); if (err < 0) { perror("get-namespace-id"); return err; @@ -415,7 +418,8 @@ static int fdp_update(int argc, char **argv, struct command *acmd, struct plugin for (unsigned int i = 0; i < npids; i++) buf[i] = cpu_to_le16(pids[i]); - err = nvme_fdp_reclaim_unit_handle_update(hdl, cfg.namespace_id, npids, buf); + nvme_init_fdp_reclaim_unit_handle_status(&cmd, cfg.nsid, buf, npids); + err = nvme_submit_io_passthru(hdl, &cmd, NULL); if (err) { nvme_show_status(err); return err;