Skip to content

Commit ec419f2

Browse files
committed
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 4544439 commit ec419f2

File tree

3 files changed

+588
-809
lines changed

3 files changed

+588
-809
lines changed

nvme-print.c

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

523+
int 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+
return err;
531+
}
532+
523533
void nvme_show_opcode_status(int status, bool admin, __u8 opcode)
524534
{
525535
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+
int 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)