Skip to content

Commit 4b5ac98

Browse files
ikegami-tigaw
authored andcommitted
nvme: add NS management commands error message output
Print it if the commands failed and NS management not supported. Signed-off-by: Tokunori Ikegami <ikegami.t@gmail.com>
1 parent 140ce35 commit 4b5ac98

File tree

1 file changed

+29
-9
lines changed

1 file changed

+29
-9
lines changed

nvme.c

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2783,6 +2783,32 @@ static int id_endurance_grp_list(int argc, char **argv, struct command *cmd,
27832783
return err;
27842784
}
27852785

2786+
static void ns_mgmt_show_error(struct nvme_dev *dev, int err, const char *cmd)
2787+
{
2788+
_cleanup_free_ struct nvme_id_ctrl *ctrl = NULL;
2789+
2790+
if (err < 0) {
2791+
nvme_show_error("%s namespace: %s", cmd, nvme_strerror(errno));
2792+
return;
2793+
}
2794+
2795+
nvme_show_init();
2796+
2797+
nvme_show_status(err);
2798+
2799+
ctrl = nvme_alloc(sizeof(*ctrl));
2800+
if (!ctrl)
2801+
return;
2802+
2803+
err = nvme_cli_identify_ctrl(dev, ctrl);
2804+
if (!err) {
2805+
if (!(le16_to_cpu(ctrl->oacs) & NVME_CTRL_OACS_NS_MGMT))
2806+
nvme_show_result("NS management and attachment not supported");
2807+
}
2808+
2809+
nvme_show_finish();
2810+
}
2811+
27862812
static int delete_ns(int argc, char **argv, struct command *cmd, struct plugin *plugin)
27872813
{
27882814
const char *desc = "Delete the given namespace by "
@@ -2824,10 +2850,8 @@ static int delete_ns(int argc, char **argv, struct command *cmd, struct plugin *
28242850
err = nvme_cli_ns_mgmt_delete(dev, cfg.namespace_id, nvme_cfg.timeout);
28252851
if (!err)
28262852
printf("%s: Success, deleted nsid:%d\n", cmd->name, cfg.namespace_id);
2827-
else if (err > 0)
2828-
nvme_show_status(err);
28292853
else
2830-
nvme_show_error("delete namespace: %s", nvme_strerror(errno));
2854+
ns_mgmt_show_error(dev, err, "delete");
28312855

28322856
return err;
28332857
}
@@ -2890,10 +2914,8 @@ static int nvme_attach_ns(int argc, char **argv, int attach, const char *desc, s
28902914

28912915
if (!err)
28922916
printf("%s: Success, nsid:%d\n", cmd->name, cfg.namespace_id);
2893-
else if (err > 0)
2894-
nvme_show_status(err);
28952917
else
2896-
nvme_show_perror(attach ? "attach namespace" : "detach namespace");
2918+
ns_mgmt_show_error(dev, err, attach ? "attach" : "detach");
28972919

28982920
return err;
28992921
}
@@ -3261,10 +3283,8 @@ static int create_ns(int argc, char **argv, struct command *cmd, struct plugin *
32613283
err = nvme_cli_ns_mgmt_create(dev, data, &nsid, nvme_cfg.timeout, cfg.csi);
32623284
if (!err)
32633285
printf("%s: Success, created nsid:%d\n", cmd->name, nsid);
3264-
else if (err > 0)
3265-
nvme_show_status(err);
32663286
else
3267-
nvme_show_error("create namespace: %s", nvme_strerror(errno));
3287+
ns_mgmt_show_error(dev, err, "create");
32683288

32693289
return err;
32703290
}

0 commit comments

Comments
 (0)