Skip to content

Commit 1affcfa

Browse files
committed
nvme-print: introduce nvme_show_cmd_err() helper function
Add the cmd argument for nvme_show_err() to use nvme_show_opcode_status(). Do not change nvme_show_err() itself so add nvme_show_cmd_err() instead. Also add admin variable into the nvme_passthru_cmd structure. Signed-off-by: Tokunori Ikegami <ikegami.t@gmail.com>
1 parent 5f03495 commit 1affcfa

File tree

5 files changed

+23
-7
lines changed

5 files changed

+23
-7
lines changed

libnvme/src/nvme/ioctl.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@ static int nvme_submit_passthru64(struct nvme_transport_handle *hdl,
178178
int nvme_submit_io_passthru(struct nvme_transport_handle *hdl,
179179
struct nvme_passthru_cmd *cmd)
180180
{
181+
cmd->admin = false;
182+
181183
if (hdl->ioctl64)
182184
return nvme_submit_passthru64(hdl, NVME_IOCTL_IO64_CMD, cmd);
183185
return nvme_submit_passthru32(hdl, NVME_IOCTL_IO_CMD, cmd);
@@ -186,6 +188,8 @@ int nvme_submit_io_passthru(struct nvme_transport_handle *hdl,
186188
int nvme_submit_admin_passthru(struct nvme_transport_handle *hdl,
187189
struct nvme_passthru_cmd *cmd)
188190
{
191+
cmd->admin = true;
192+
189193
switch (hdl->type) {
190194
case NVME_TRANSPORT_HANDLE_TYPE_DIRECT:
191195
if (hdl->ioctl64)

libnvme/src/nvme/ioctl.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
* @timeout_ms: If non-zero, overrides system default timeout in milliseconds
7171
* @rsvd2: Reserved for future use (and fills an implicit struct pad
7272
* @result: Set on completion to the command's CQE DWORD 0-1 controller response
73+
* @admin: If true admin command else io command
7374
*/
7475
struct nvme_passthru_cmd {
7576
__u8 opcode;
@@ -91,6 +92,7 @@ struct nvme_passthru_cmd {
9192
__u32 timeout_ms;
9293
__u32 rsvd2;
9394
__u64 result;
95+
bool admin;
9496
};
9597

9698
/**
@@ -462,7 +464,7 @@ int nvme_submit_admin_passthru(struct nvme_transport_handle *hdl,
462464
struct nvme_passthru_cmd *cmd);
463465

464466
/**
465-
* nvme_submit_io_passthru() - Submit an nvme passthrough command
467+
* nvme_submit_io_passthru() - Submit an nvme passthrough io command
466468
* @hdl: Transport handle
467469
* @cmd: The nvme io command to send
468470
*

nvme-print.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -522,9 +522,18 @@ void nvme_show_status(int status)
522522

523523
void nvme_show_err(const char *msg, int err)
524524
{
525-
if (err < 0)
525+
nvme_show_cmd_err(msg, NULL, err);
526+
}
527+
528+
void nvme_show_cmd_err(const char *msg, struct nvme_passthru_cmd *cmd, int err)
529+
{
530+
if (!err)
531+
return;
532+
else if (err < 0)
526533
nvme_show_error("%s: %s", msg, nvme_strerror(-err));
527-
else if (err > 0)
534+
else if (cmd)
535+
nvme_show_opcode_status(err, cmd->admin, cmd->opcode);
536+
else
528537
nvme_show_status(err);
529538
}
530539

nvme-print.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ struct print_ops *nvme_get_binary_print_ops(nvme_print_flags_t flags);
160160

161161
void nvme_show_status(int status);
162162
void nvme_show_err(const char *msg, int err);
163+
void nvme_show_cmd_err(const char *msg, struct nvme_passthru_cmd *cmd, int err);
163164
void nvme_show_opcode_status(int status, bool admin, __u8 opcode);
164165
void nvme_show_lba_status_info(__u64 result);
165166
void nvme_show_relatives(struct nvme_global_ctx *ctx, const char *name, nvme_print_flags_t flags);

nvme.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5604,10 +5604,10 @@ static int sanitize_ns_cmd(int argc, char **argv, struct command *acmd,
56045604

56055605
nvme_init_sanitize_ns(&cmd, cfg.sanact, cfg.ause, cfg.emvs);
56065606
err = nvme_submit_admin_passthru(hdl, &cmd);
5607-
if (err < 0)
5608-
nvme_show_error("sanitize ns: %s", nvme_strerror(err));
5609-
else if (err > 0)
5610-
nvme_show_status(err);
5607+
if (err) {
5608+
nvme_show_cmd_err("sanitize ns", &cmd, err);
5609+
return err;
5610+
}
56115611

56125612
return err;
56135613
}

0 commit comments

Comments
 (0)