diff --git a/plugins/lm/lm-nvme.c b/plugins/lm/lm-nvme.c index 9fb8f7f393..19b187e891 100644 --- a/plugins/lm/lm-nvme.c +++ b/plugins/lm/lm-nvme.c @@ -57,10 +57,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_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 nvme_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; int err = -1; struct config { @@ -105,22 +106,17 @@ static int lm_create_cdq(int argc, char **argv, struct command *acmd, struct plu return -ENOMEM; } - struct nvme_lm_cdq_args args = { - .args_size = sizeof(args), - .sel = NVME_LM_SEL_CREATE_CDQ, - .mos = NVME_SET(cfg.qt, LM_QT), - .cntlid = cfg.cntlid, - .sz = cfg.sz, - .data = queue - }; - - err = nvme_lm_cdq(hdl, &args); + // FIX: cdqid (last argument) has to be adapted + nvme_init_lm_cdq(&cmd, NVME_LM_SEL_CREATE_CDQ, NVME_SET(cfg.qt, LM_QT), + cfg.cntlid, cfg.sz, queue, 0xff); + err = nvme_submit_admin_passthru(hdl, &cmd, NULL); if (err < 0) nvme_show_error("ERROR: nvme_lm_cdq() failed: %s", nvme_strerror(errno)); else if (err) nvme_show_status(err); else - printf("Create CDQ Successful: CDQID=0x%04x\n", args.cdqid); + // FIX: where to get the CDQID + printf("Create CDQ Successful: CDQID=0x%04x\n", 0xff); return err; } @@ -130,8 +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_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; int err = -1; struct config { @@ -151,13 +148,9 @@ static int lm_delete_cdq(int argc, char **argv, struct command *acmd, struct plu if (err) return err; - struct nvme_lm_cdq_args args = { - .args_size = sizeof(args), - .sel = NVME_LM_SEL_DELETE_CDQ, - .cdqid = cfg.cdqid, - }; - - err = nvme_lm_cdq(hdl, &args); + nvme_init_lm_cdq(&cmd, NVME_LM_SEL_DELETE_CDQ, 0, 0, 0, NULL, + cfg.cdqid); + err = nvme_submit_admin_passthru(hdl, &cmd, NULL); if (err < 0) nvme_show_error("ERROR: nvme_lm_cdq() failed: %s", nvme_strerror(errno)); else if (err > 0) @@ -186,8 +179,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_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; int err = -1; struct config { @@ -240,14 +234,8 @@ static int lm_track_send(int argc, char **argv, struct command *acmd, struct plu cfg.mos = NVME_SET(NVME_LM_LACT_STOP_LOGGING, LM_LACT); } - struct nvme_lm_track_send_args args = { - .args_size = sizeof(args), - .cdqid = cfg.cdqid, - .sel = cfg.sel, - .mos = cfg.mos, - }; - - err = nvme_lm_track_send(hdl, &args); + nvme_init_lm_track_send(&cmd, cfg.sel, cfg.mos, cfg.cdqid); + err = nvme_submit_admin_passthru(hdl, &cmd, NULL); if (err < 0) nvme_show_error("ERROR: nvme_lm_track_send() failed %s", strerror(errno)); else if (err) @@ -291,10 +279,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_global_ctx_ struct nvme_global_ctx *ctx = NULL; _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; - _cleanup_file_ FILE *file = NULL; + _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; _cleanup_huge_ struct nvme_mem_huge mh = { 0, }; + _cleanup_file_ FILE *file = NULL; + struct nvme_passthru_cmd cmd; void *data = NULL; int err = -1; @@ -390,21 +379,12 @@ static int lm_migration_send(int argc, char **argv, struct command *acmd, struct } } - struct nvme_lm_migration_send_args args = { - .args_size = sizeof(args), - .sel = cfg.sel, - .mos = NVME_SET(cfg.seqind, LM_SEQIND), - .cntlid = cfg.cntlid, - .csuuidi = cfg.csuuidi, - .uidx = cfg.uidx, - .stype = cfg.stype, - .offset = cfg.offset, - .dudmq = cfg.dudmq, - .numd = cfg.numd, - .data = data, - }; - - err = nvme_lm_migration_send(hdl, &args); + nvme_init_lm_migration_send(&cmd, cfg.sel, + NVME_SET(cfg.seqind, LM_SEQIND), cfg.cntlid, + cfg.stype, cfg.dudmq, cfg.csvi, cfg.csuuidi, + cfg.offset, cfg.uidx, data, + (cfg.numd << 2)); + err = nvme_submit_admin_passthru(hdl, &cmd, NULL); if (err < 0) nvme_show_error("ERROR: nvme_lm_migration_send() failed %s", strerror(errno)); else if (err > 0) @@ -433,13 +413,16 @@ 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_global_ctx_ struct nvme_global_ctx *ctx = NULL; _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; - _cleanup_file_ FILE *fd = NULL; + _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; _cleanup_huge_ struct nvme_mem_huge mh = { 0, }; + _cleanup_file_ FILE *fd = NULL; + struct nvme_passthru_cmd cmd; nvme_print_flags_t flags; void *data = NULL; + __u32 result = 0; int err = -1; + __u16 mos; struct config { __u8 sel; @@ -511,21 +494,11 @@ static int lm_migration_recv(int argc, char **argv, struct command *acmd, struct if (!data) return -ENOMEM; - __u32 result = 0; - struct nvme_lm_migration_recv_args args = { - .args_size = sizeof(args), - .sel = cfg.sel, - .mos = NVME_SET(cfg.csvi, LM_GET_CONTROLLER_STATE_CSVI), - .uidx = cfg.uidx, - .csuuidi = cfg.csuuidi, - .offset = cfg.offset, - .cntlid = cfg.cntlid, - .numd = cfg.numd, - .data = data, - .result = &result, - }; - - err = nvme_lm_migration_recv(hdl, &args); + mos = NVME_SET(cfg.csvi, LM_GET_CONTROLLER_STATE_CSVI); + 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, &result); if (err < 0) nvme_show_error("ERROR: nvme_lm_migration_recv() failed %s", strerror(errno)); else if (err) diff --git a/plugins/zns/zns.c b/plugins/zns/zns.c index 94f39b5035..0b753b00f4 100644 --- a/plugins/zns/zns.c +++ b/plugins/zns/zns.c @@ -234,8 +234,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"; const char *timeout = "timeout value, in milliseconds"; - _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; int err, zcapc = 0; char *cmdstr; __u32 result; @@ -273,19 +274,9 @@ static int zns_mgmt_send(int argc, char **argv, struct command *acmd, struct plu } } - struct nvme_zns_mgmt_send_args args = { - .args_size = sizeof(args), - .nsid = cfg.namespace_id, - .slba = cfg.zslba, - .zsa = zsa, - .select_all = cfg.select_all, - .zsaso = 0, - .data_len = 0, - .data = NULL, - .timeout = cfg.timeout, - .result = &result, - }; - err = nvme_zns_mgmt_send(hdl, &args); + 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, &result); if (!err) { if (zsa == NVME_ZNS_ZSA_RESET) zcapc = result & 0x1; @@ -344,9 +335,10 @@ static int zone_mgmt_send(int argc, char **argv, struct command *acmd, struct pl const char *data = "optional file for data (default stdin)"; const char *timeout = "timeout value, in milliseconds"; - _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; int ffd = STDIN_FILENO, err = -1; + struct nvme_passthru_cmd cmd; void *buf = NULL; struct config { @@ -430,19 +422,10 @@ static int zone_mgmt_send(int argc, char **argv, struct command *acmd, struct pl } } - struct nvme_zns_mgmt_send_args args = { - .args_size = sizeof(args), - .nsid = cfg.namespace_id, - .slba = cfg.zslba, - .zsa = cfg.zsa, - .select_all = cfg.select_all, - .zsaso = cfg.zsaso, - .data_len = cfg.data_len, - .data = buf, - .timeout = cfg.timeout, - .result = NULL, - }; - err = nvme_zns_mgmt_send(hdl, &args); + 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, NULL); 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); @@ -480,8 +463,9 @@ static int open_zone(int argc, char **argv, struct command *acmd, struct plugin const char *zrwaa = "Allocate Zone Random Write Area to zone"; const char *select_all = "send command to all zones"; const char *timeout = "timeout value, in milliseconds"; - _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; int err; struct config { @@ -516,24 +500,17 @@ static int open_zone(int argc, char **argv, struct command *acmd, struct plugin } } - struct nvme_zns_mgmt_send_args args = { - .args_size = sizeof(args), - .nsid = cfg.namespace_id, - .slba = cfg.zslba, - .zsa = NVME_ZNS_ZSA_OPEN, - .select_all = cfg.select_all, - .zsaso = cfg.zrwaa, - .data_len = 0, - .data = NULL, - .timeout = cfg.timeout, - .result = NULL, - }; - err = nvme_zns_mgmt_send(hdl, &args); + 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, NULL); if (!err) printf("zns-open-zone: Success zone slba:%"PRIx64" nsid:%d\n", (uint64_t)cfg.zslba, cfg.namespace_id); - else + else if (err > 0) nvme_show_status(err); + else + perror("zns open-zone"); return err; } @@ -560,8 +537,9 @@ static int set_zone_desc(int argc, char **argv, struct command *acmd, struct plu const char *data = "optional file for zone extension data (default stdin)"; const char *timeout = "timeout value, in milliseconds"; - _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; int ffd = STDIN_FILENO, err; void *buf = NULL; int data_len; @@ -626,19 +604,10 @@ static int set_zone_desc(int argc, char **argv, struct command *acmd, struct plu goto close_ffd; } - struct nvme_zns_mgmt_send_args args = { - .args_size = sizeof(args), - .nsid = cfg.namespace_id, - .slba = cfg.zslba, - .zsa = NVME_ZNS_ZSA_SET_DESC_EXT, - .select_all = 0, - .zsaso = cfg.zrwaa, - .data_len = data_len, - .data = buf, - .timeout = cfg.timeout, - .result = NULL, - }; - err = nvme_zns_mgmt_send(hdl, &args); + 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, NULL); if (!err) printf("set-zone-desc: Success, zone:%"PRIx64" nsid:%d\n", (uint64_t)cfg.zslba, cfg.namespace_id); @@ -661,8 +630,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"; const char *timeout = "timeout value, in milliseconds"; - _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; int err; struct config { @@ -692,24 +662,16 @@ static int zrwa_flush_zone(int argc, char **argv, struct command *acmd, struct p } } - struct nvme_zns_mgmt_send_args args = { - .args_size = sizeof(args), - .nsid = cfg.namespace_id, - .slba = cfg.lba, - .zsa = NVME_ZNS_ZSA_ZRWA_FLUSH, - .select_all = 0, - .zsaso = 0, - .data_len = 0, - .data = NULL, - .timeout = cfg.timeout, - .result = NULL, - }; - err = nvme_zns_mgmt_send(hdl, &args); + 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, NULL); if (!err) printf("zrwa-flush-zone: Success, lba:%"PRIx64" nsid:%d\n", (uint64_t)cfg.lba, cfg.namespace_id); - else + else if (err > 0) nvme_show_status(err); + else + perror("zns zrwa-flush-zone"); return err; } @@ -723,8 +685,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_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; nvme_print_flags_t flags; void *data = NULL; int err = -1; @@ -782,19 +745,9 @@ static int zone_mgmt_recv(int argc, char **argv, struct command *acmd, struct pl } } - struct nvme_zns_mgmt_recv_args args = { - .args_size = sizeof(args), - .nsid = cfg.namespace_id, - .slba = cfg.zslba, - .zra = cfg.zra, - .zrasf = cfg.zrasf, - .zras_feat = cfg.partial, - .data_len = cfg.data_len, - .data = data, - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .result = NULL, - }; - err = nvme_zns_mgmt_recv(hdl, &args); + 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, NULL); if (!err) printf("zone-mgmt-recv: Success, action:%d zone:%"PRIx64" nsid:%d\n", cfg.zra, (uint64_t)cfg.zslba, cfg.namespace_id); @@ -818,13 +771,14 @@ 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_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_huge_ struct nvme_mem_huge mh = { 0, }; + struct nvme_zone_report *report, *buff; + struct nvme_passthru_cmd cmd; nvme_print_flags_t flags; int zdes = 0, err = -1; __u32 report_size; - struct nvme_zone_report *report, *buff; - _cleanup_huge_ struct nvme_mem_huge mh = { 0, }; unsigned int nr_zones_chunks = 1024, /* 1024 entries * 64 bytes per entry = 64k byte transfer */ nr_zones_retrieved = 0, @@ -912,10 +866,9 @@ static int report_zones(int argc, char **argv, struct command *acmd, struct plug return -ENOMEM; } - err = nvme_zns_report_zones(hdl, cfg.namespace_id, 0, - cfg.state, false, false, - log_len, buff, - NVME_DEFAULT_IOCTL_TIMEOUT, NULL); + nvme_init_zns_report_zones(&cmd, cfg.namespace_id, 0, cfg.state, false, + false, buff, log_len); + err = nvme_submit_io_passthru(hdl, &cmd, NULL); if (err > 0) { nvme_show_status(err); goto free_buff; @@ -955,15 +908,15 @@ static int report_zones(int argc, char **argv, struct command *acmd, struct plug log_len = sizeof(struct nvme_zone_report) + ((sizeof(struct nvme_zns_desc) * nr_zones_chunks) + (nr_zones_chunks * zdes)); } - err = nvme_zns_report_zones(hdl, cfg.namespace_id, - offset, - cfg.state, cfg.extended, - cfg.partial, log_len, report, - NVME_DEFAULT_IOCTL_TIMEOUT, NULL); + 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, NULL); if (err > 0) { nvme_show_status(err); break; } + // QUESTION: should we also check for < 0 here? if (!err) nvme_show_zns_report_zones(report, nr_zones_chunks, @@ -993,22 +946,21 @@ static int zone_append(int argc, char **argv, struct command *acmd, struct plugi const char *fua = "force unit access"; const char *prinfo = "protection information action and checks field"; const char *piremap = "protection information remap (for type 1 PI)"; - const char *ref_tag = "reference tag for end-to-end PI"; - const char *lbat = "logical block application tag for end-to-end PI"; - const char *lbatm = "logical block application tag mask for end-to-end PI"; const char *metadata_size = "size of metadata in bytes"; const char *data_size = "size of data in bytes"; const char *latency = "output latency statistics"; - int err = -1, dfd = STDIN_FILENO, mfd = STDIN_FILENO; - _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; + 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_cmd64 cmd; __u16 nblocks, control = 0; - __u64 result; + __u16 cev = 0, dspec = 0; __u8 lba_index; - struct timeval start_time, end_time; + __u64 result; struct nvme_id_ns ns; @@ -1021,9 +973,6 @@ static int zone_append(int argc, char **argv, struct command *acmd, struct plugi bool limited_retry; bool fua; __u32 namespace_id; - __u64 ref_tag; - __u16 lbat; - __u16 lbatm; __u8 prinfo; bool piremap; bool latency; @@ -1040,9 +989,6 @@ static int zone_append(int argc, char **argv, struct command *acmd, struct plugi OPT_FILE("metadata", 'M', &cfg.metadata, metadata), OPT_FLAG("limited-retry", 'l', &cfg.limited_retry, limited_retry), OPT_FLAG("force-unit-access", 'f', &cfg.fua, fua), - OPT_SUFFIX("ref-tag", 'r', &cfg.ref_tag, ref_tag), - OPT_SHRT("app-tag-mask", 'm', &cfg.lbatm, lbatm), - OPT_SHRT("app-tag", 'a', &cfg.lbat, lbat), OPT_BYTE("prinfo", 'p', &cfg.prinfo, prinfo), OPT_FLAG("piremap", 'P', &cfg.piremap, piremap), OPT_FLAG("latency", 't', &cfg.latency, latency), @@ -1150,25 +1096,11 @@ static int zone_append(int argc, char **argv, struct command *acmd, struct plugi if (cfg.piremap) control |= NVME_IO_ZNS_APPEND_PIREMAP; - struct nvme_zns_append_args args = { - .args_size = sizeof(args), - .nsid = cfg.namespace_id, - .zslba = cfg.zslba, - .nlb = nblocks, - .control = control, - .ilbrt_u64 = cfg.ref_tag, - .lbat = cfg.lbat, - .lbatm = cfg.lbatm, - .data_len = cfg.data_size, - .data = buf, - .metadata_len = cfg.metadata_size, - .metadata = mbuf, - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .result = &result, - }; - gettimeofday(&start_time, NULL); - err = nvme_zns_append(hdl, &args); + 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_passthru64(hdl, &cmd, &result); gettimeofday(&end_time, NULL); if (cfg.latency) printf(" latency: zone append: %llu us\n",