From: Tokunori Ikegami Date: Mon, 3 Feb 2025 15:38:14 +0000 (+0900) Subject: nvme: change attach-ns to error out if wrong device given X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=5fee3d064673cc961451c29856675e07b959bc92;p=users%2Fsagi%2Fnvme-cli.git nvme: change attach-ns to error out if wrong device given Also updating the documentation. Signed-off-by: Tokunori Ikegami --- diff --git a/Documentation/nvme-attach-ns.txt b/Documentation/nvme-attach-ns.txt index 601c20df..1d507593 100644 --- a/Documentation/nvme-attach-ns.txt +++ b/Documentation/nvme-attach-ns.txt @@ -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 parameter is mandatory NVMe character device (ex: /dev/nvme0) but +not a namespace block device (ex: /dev/nvme0n1). + OPTIONS ------- -n :: --namespace-id=:: - The namespace identifier to attach. + The namespace identifier to attach but not attached already. -c :: -controllers=:: diff --git a/nvme.c b/nvme.c index 0591fc72..44a44317 100644 --- 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;