Skip to content

Commit 093a53d

Browse files
keithbuschigaw
authored andcommitted
nvme-cli: attach ns to local controller if none specified
Assume the user meant to attach the namespace to the controller the command was sent to if the user didn't provide a controller id list. Suggested-by: Nilay Shroff <[email protected]> Signed-off-by: Keith Busch <[email protected]> Signed-off-by: Daniel Wagner <[email protected]>
1 parent 4064edc commit 093a53d

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

Documentation/nvme-attach-ns.txt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ OPTIONS
2929

3030
-c <ctrl-list,>::
3131
-controllers=<ctrl-list,>::
32-
The comma separated list of controller identifiers to attach
33-
the namespace too.
32+
The comma separated list of controller identifiers to attach the
33+
namespace too. If no list is provided, the namespace will be attached
34+
to the <device> controller used for this command.
3435

3536
-o <fmt>::
3637
--output-format=<fmt>::
@@ -43,9 +44,13 @@ OPTIONS
4344

4445
EXAMPLES
4546
--------
46-
Attach namespace to the controller:
47+
Attach namespace 2 to the controllers with id 0x21 and 0x22:
4748

48-
# nvme attach-ns /dev/nvme1 -n 0x2 -c 0x21
49+
# nvme attach-ns /dev/nvme1 -n 0x2 -c 0x21,0x22
50+
51+
Attach namespace 3 to nvme0:
52+
53+
# nvme attach-ns /dev/nvme0 -n 3
4954

5055
NVME
5156
----

nvme.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2953,9 +2953,6 @@ static int nvme_attach_ns(int argc, char **argv, int attach, const char *desc, s
29532953

29542954
num = argconfig_parse_comma_sep_array_u16(cfg.cntlist,
29552955
list, ARRAY_SIZE(list));
2956-
if (!num)
2957-
fprintf(stderr, "warning: empty controller-id list will result in no actual change in namespace attachment\n");
2958-
29592956
if (num == -1) {
29602957
nvme_show_error("%s: controller id list is malformed", cmd->name);
29612958
return -EINVAL;
@@ -2965,7 +2962,18 @@ static int nvme_attach_ns(int argc, char **argv, int attach, const char *desc, s
29652962
if (!cntlist)
29662963
return -ENOMEM;
29672964

2968-
nvme_init_ctrl_list(cntlist, num, list);
2965+
if (argconfig_parse_seen(opts, "controllers")) {
2966+
nvme_init_ctrl_list(cntlist, num, list);
2967+
} else {
2968+
struct nvme_id_ctrl ctrl = { 0 };
2969+
2970+
if (nvme_cli_identify_ctrl(dev, &ctrl)) {
2971+
perror("identify-ctrl");
2972+
return -errno;
2973+
}
2974+
cntlist->num = cpu_to_le16(1);
2975+
cntlist->identifier[0] = ctrl.cntlid;
2976+
}
29692977

29702978
if (attach)
29712979
err = nvme_cli_ns_attach_ctrls(dev, cfg.namespace_id,

0 commit comments

Comments
 (0)