]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
nvme: change attach-ns to error out if wrong device given
authorTokunori Ikegami <ikegami.t@gmail.com>
Mon, 3 Feb 2025 15:38:14 +0000 (00:38 +0900)
committerDaniel Wagner <wagi@monom.org>
Fri, 7 Feb 2025 16:01:41 +0000 (17:01 +0100)
Also updating the documentation.

Signed-off-by: Tokunori Ikegami <ikegami.t@gmail.com>
Documentation/nvme-attach-ns.txt
nvme.c

index 601c20df300f012a8c0f17dbab2133d8de9b9d6a..1d507593129efc6344132db0d214304f7468cf23 100644 (file)
@@ -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,>::
diff --git a/nvme.c b/nvme.c
index 0591fc72183ba664a8fe7ce859436e95b7ec9350..44a44317ced07afdb7e130879b1f4609a1a83f95 100644 (file)
--- a/nvme.c
+++ b/nvme.c
@@ -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;