]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
nvme/id-ns: do not try to get namespace id from non-block device.
authorXiao Liang <xiliang@redhat.com>
Wed, 1 Nov 2017 14:49:32 +0000 (22:49 +0800)
committerXiao Liang <xiliang@redhat.com>
Wed, 1 Nov 2017 15:21:10 +0000 (23:21 +0800)
namespace id's default value is 0 and changed to 15 by get_nsid()
when device is not a block device.

With this change:
# ./nvme id-ns /dev/nvme0 -n 0
Error: requesting namespace-id from non-block device
NVMe Status:INVALID_NS(b) NSID:0
                               ^^
Without this change:
Missleading output when user passed 0 or 15 as namespace id.
# nvme id-ns /dev/nvme0
Error: requesting namespace-id from non-block device
NVMe Status:INVALID_NS(b) NSID:15
                               ^^
# nvme id-ns /dev/nvme0 -n 0
Error: requesting namespace-id from non-block device
NVMe Status:INVALID_NS(b) NSID:15
                               ^^
# nvme id-ns /dev/nvme0 -n 15
NVMe Status:INVALID_NS(b) NSID:15

Signed-off-by: Xiao Liang <xiliang@redhat.com>
nvme.c

diff --git a/nvme.c b/nvme.c
index ed1c61f0fd7e7ffe77baa969b57ca3f1c4ee8da5..555201009982c630e386f3a6fce07007fbdb1255 100644 (file)
--- a/nvme.c
+++ b/nvme.c
@@ -1178,8 +1178,11 @@ static int id_ns(int argc, char **argv, struct command *cmd, struct plugin *plug
                flags |= VS;
        if (cfg.human_readable)
                flags |= HUMAN;
-       if (!cfg.namespace_id)
+       if (!cfg.namespace_id && S_ISBLK(nvme_stat.st_mode))
                cfg.namespace_id = get_nsid(fd);
+       else if(!cfg.namespace_id)
+               fprintf(stderr,
+                       "Error: requesting namespace-id from non-block device\n");`
 
        err = nvme_identify_ns(fd, cfg.namespace_id, cfg.force, &ns);
        if (!err) {