From e521a61a6c4000569d57dd2f5eae9ac83f53ccba Mon Sep 17 00:00:00 2001 From: Tokunori Ikegami Date: Tue, 4 Feb 2025 00:38:14 +0900 Subject: [PATCH] nvme: change attach-ns to error out if wrong device given Also updating the documentation. Signed-off-by: Tokunori Ikegami --- Documentation/nvme-attach-ns.txt | 5 ++++- nvme.c | 6 ++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Documentation/nvme-attach-ns.txt b/Documentation/nvme-attach-ns.txt index 601c20df30..1d50759312 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 0591fc7218..44a44317ce 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;