Skip to content

Commit 2ba22df

Browse files
ikegami-tigaw
authored andcommitted
nvme-print: introduce nvme_show_err() helper function
This handles the negative error code and the postive status code. Note: Fix also to handle the negative error for nvme_strerror(). Fixes: 4fb93ad ("nvme-cli: update error handling") Signed-off-by: Tokunori Ikegami <[email protected]>
1 parent 10ca189 commit 2ba22df

File tree

3 files changed

+750
-783
lines changed

3 files changed

+750
-783
lines changed

nvme-print.c

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

523+
void nvme_show_err(const char *msg, int err)
524+
{
525+
if (err < 0)
526+
nvme_show_error("%s: %s", msg, nvme_strerror(-err));
527+
else if (err > 0)
528+
nvme_show_status(err);
529+
}
530+
523531
void nvme_show_opcode_status(int status, bool admin, __u8 opcode)
524532
{
525533
struct print_ops *ops = nvme_print_ops(NORMAL);

nvme-print.h

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

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

0 commit comments

Comments
 (0)