Skip to content

Commit a57c1b3

Browse files
ikegami-tigaw
authored andcommitted
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 <[email protected]>
1 parent feb4916 commit a57c1b3

3 files changed

Lines changed: 33 additions & 7 deletions

File tree

nvme-print.c

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -520,14 +520,36 @@ void nvme_show_status(int status)
520520
ops->show_status(status);
521521
}
522522

523-
void nvme_show_err(const char *msg, int err)
523+
static void nvme_show_cmd_err(const char *msg, bool admin,
524+
struct nvme_passthru_cmd *cmd, int err)
524525
{
525-
if (err < 0)
526+
if (!err)
527+
return;
528+
else if (err < 0)
526529
nvme_show_error("%s: %s", msg, nvme_strerror(-err));
527-
else if (err > 0)
530+
else if (cmd)
531+
nvme_show_opcode_status(err, false, cmd->opcode);
532+
else
528533
nvme_show_status(err);
529534
}
530535

536+
void nvme_show_err(const char *msg, int err)
537+
{
538+
nvme_show_cmd_err(msg, false, NULL, err);
539+
}
540+
541+
void nvme_show_io_cmd_err(const char *msg, struct nvme_passthru_cmd *cmd,
542+
int err)
543+
{
544+
nvme_show_cmd_err(msg, false, cmd, err);
545+
}
546+
547+
void nvme_show_admin_cmd_err(const char *msg, struct nvme_passthru_cmd *cmd,
548+
int err)
549+
{
550+
nvme_show_cmd_err(msg, true, cmd, err);
551+
}
552+
531553
void nvme_show_opcode_status(int status, bool admin, __u8 opcode)
532554
{
533555
struct print_ops *ops = nvme_print_ops(NORMAL);

nvme-print.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ 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_io_cmd_err(const char *msg, struct nvme_passthru_cmd *cmd,
164+
int err);
165+
void nvme_show_admin_cmd_err(const char *msg, struct nvme_passthru_cmd *cmd,
166+
int err);
163167
void nvme_show_opcode_status(int status, bool admin, __u8 opcode);
164168
void nvme_show_lba_status_info(__u64 result);
165169
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
@@ -5603,10 +5603,10 @@ static int sanitize_ns_cmd(int argc, char **argv, struct command *acmd,
56035603

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

56115611
return err;
56125612
}

0 commit comments

Comments
 (0)