Skip to content

Commit

Permalink
nvme: change attach-ns to error out if wrong device given
Browse files Browse the repository at this point in the history
Also updating the documentation.

Signed-off-by: Tokunori Ikegami <[email protected]>
  • Loading branch information
ikegami-t committed Feb 3, 2025
1 parent 56cf51b commit e521a61
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Documentation/nvme-attach-ns.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@ For the NVMe device given, sends the nvme namespace attach command for
the provided namespace identifier, attaching to the provided list of
controller identifiers.

The <device> parameter is mandatory NVMe character device (ex: /dev/nvme0) but
not a namespace block device (ex: /dev/nvme0n1).

OPTIONS
-------
-n <nsid>::
--namespace-id=<nsid>::
The namespace identifier to attach.
The namespace identifier to attach but not attached already.

-c <ctrl-list,>::
-controllers=<ctrl-list,>::
Expand Down
6 changes: 6 additions & 0 deletions nvme.c
Original file line number Diff line number Diff line change
Expand Up @@ -2928,6 +2928,12 @@ static int nvme_attach_ns(int argc, char **argv, int attach, const char *desc, s
if (err)
return err;

if (is_blkdev(dev)) {
nvme_show_error("%s: a block device opened (dev: %s, nsid: %d)", cmd->name,
dev->name, cfg.namespace_id);
return -EINVAL;
}

if (!cfg.namespace_id) {
nvme_show_error("%s: namespace-id parameter required", cmd->name);
return -EINVAL;
Expand Down

0 comments on commit e521a61

Please sign in to comment.