diff --git a/libnvme/src/nvme/ioctl.c b/libnvme/src/nvme/ioctl.c index ea21520f65..cda6863a37 100644 --- a/libnvme/src/nvme/ioctl.c +++ b/libnvme/src/nvme/ioctl.c @@ -178,6 +178,8 @@ static int nvme_submit_passthru64(struct nvme_transport_handle *hdl, int nvme_submit_io_passthru(struct nvme_transport_handle *hdl, struct nvme_passthru_cmd *cmd) { + cmd->admin = false; + if (hdl->ioctl64) return nvme_submit_passthru64(hdl, NVME_IOCTL_IO64_CMD, cmd); return nvme_submit_passthru32(hdl, NVME_IOCTL_IO_CMD, cmd); @@ -186,6 +188,8 @@ int nvme_submit_io_passthru(struct nvme_transport_handle *hdl, int nvme_submit_admin_passthru(struct nvme_transport_handle *hdl, struct nvme_passthru_cmd *cmd) { + cmd->admin = true; + switch (hdl->type) { case NVME_TRANSPORT_HANDLE_TYPE_DIRECT: if (hdl->ioctl64) diff --git a/libnvme/src/nvme/ioctl.h b/libnvme/src/nvme/ioctl.h index 9f27307584..4caae34459 100644 --- a/libnvme/src/nvme/ioctl.h +++ b/libnvme/src/nvme/ioctl.h @@ -70,6 +70,7 @@ * @timeout_ms: If non-zero, overrides system default timeout in milliseconds * @rsvd2: Reserved for future use (and fills an implicit struct pad * @result: Set on completion to the command's CQE DWORD 0-1 controller response + * @admin: If true admin command else io command */ struct nvme_passthru_cmd { __u8 opcode; @@ -91,6 +92,7 @@ struct nvme_passthru_cmd { __u32 timeout_ms; __u32 rsvd2; __u64 result; + bool admin; }; /** @@ -462,7 +464,7 @@ int nvme_submit_admin_passthru(struct nvme_transport_handle *hdl, struct nvme_passthru_cmd *cmd); /** - * nvme_submit_io_passthru() - Submit an nvme passthrough command + * nvme_submit_io_passthru() - Submit an nvme passthrough io command * @hdl: Transport handle * @cmd: The nvme io command to send * diff --git a/nvme-print.c b/nvme-print.c index 9305117300..68712b1712 100644 --- a/nvme-print.c +++ b/nvme-print.c @@ -522,9 +522,18 @@ void nvme_show_status(int status) void nvme_show_err(const char *msg, int err) { - if (err < 0) + nvme_show_cmd_err(msg, NULL, err); +} + +void nvme_show_cmd_err(const char *msg, struct nvme_passthru_cmd *cmd, int err) +{ + if (!err) + return; + else if (err < 0) nvme_show_error("%s: %s", msg, nvme_strerror(-err)); - else if (err > 0) + else if (cmd) + nvme_show_opcode_status(err, cmd->admin, cmd->opcode); + else nvme_show_status(err); } diff --git a/nvme-print.h b/nvme-print.h index db194d7833..c1df215387 100644 --- a/nvme-print.h +++ b/nvme-print.h @@ -160,6 +160,7 @@ struct print_ops *nvme_get_binary_print_ops(nvme_print_flags_t flags); void nvme_show_status(int status); void nvme_show_err(const char *msg, int err); +void nvme_show_cmd_err(const char *msg, struct nvme_passthru_cmd *cmd, 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); diff --git a/nvme.c b/nvme.c index 231fc1aa81..7dbcb1b6e4 100644 --- a/nvme.c +++ b/nvme.c @@ -5604,10 +5604,10 @@ static int sanitize_ns_cmd(int argc, char **argv, struct command *acmd, nvme_init_sanitize_ns(&cmd, cfg.sanact, cfg.ause, cfg.emvs); err = nvme_submit_admin_passthru(hdl, &cmd); - if (err < 0) - nvme_show_error("sanitize ns: %s", nvme_strerror(err)); - else if (err > 0) - nvme_show_status(err); + if (err) { + nvme_show_cmd_err("sanitize ns", &cmd, err); + return err; + } return err; }