From: Tomasz Kulasek Date: Fri, 20 Sep 2019 08:29:03 +0000 (+0200) Subject: remove block device checking for namespace X-Git-Tag: v1.12~26 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=e770466615096a6d41f038a28819b00bc3078e1d;p=users%2Fhch%2Fnvme-cli.git remove block device checking for namespace In SPDK project (see spdk.io) we have implemented the ability to set up devices via CUSE device exposing controller and namespaces as character devices. Namespace devices are also exposed as character devices, so nvme-cli tools will not recognize them as valid devices. To allow to use nvme-cli tool with SPDK NVMe CUSE devices we can't assume that namespaces are block devices. Change-Id: I52aa79d24002b8dec10e6fdd0cb9a71bb6750358 Signed-off-by: Tomasz Kulasek --- diff --git a/nvme-ioctl.c b/nvme-ioctl.c index f3f17da..39685d6 100644 --- a/nvme-ioctl.c +++ b/nvme-ioctl.c @@ -70,12 +70,6 @@ int nvme_get_nsid(int fd) if (err < 0) return -errno; - if (!S_ISBLK(nvme_stat.st_mode)) { - fprintf(stderr, - "Error: requesting namespace-id from non-block device\n"); - errno = ENOTBLK; - return -errno; - } return ioctl(fd, NVME_IOCTL_ID); } diff --git a/nvme.c b/nvme.c index 46341a6..64b5750 100644 --- a/nvme.c +++ b/nvme.c @@ -1024,16 +1024,13 @@ static int delete_ns(int argc, char **argv, struct command *cmd, struct plugin * if (fd < 0) goto ret; - if (S_ISBLK(nvme_stat.st_mode)) { - cfg.namespace_id = nvme_get_nsid(fd); - if (cfg.namespace_id < 0) { - err = cfg.namespace_id; - goto close_fd; - } - } else if (!cfg.namespace_id) { - fprintf(stderr, "%s: namespace-id parameter required\n", - cmd->name); - err = -EINVAL; + cfg.namespace_id = nvme_get_nsid(fd); + if (cfg.namespace_id == 0) { + err = -EINVAL; + goto close_fd; + } + if (cfg.namespace_id < 0) { + err = cfg.namespace_id; goto close_fd; } @@ -1562,7 +1559,7 @@ static int id_ns(int argc, char **argv, struct command *cmd, struct plugin *plug if (cfg.human_readable) flags |= VERBOSE; - if (!cfg.namespace_id && S_ISBLK(nvme_stat.st_mode)) { + if (!cfg.namespace_id) { cfg.namespace_id = nvme_get_nsid(fd); if (cfg.namespace_id < 0) { err = cfg.namespace_id; @@ -2764,7 +2761,7 @@ static int format(int argc, char **argv, struct command *cmd, struct plugin *plu * format of all namespaces. */ cfg.namespace_id = NVME_NSID_ALL; - } else if (S_ISBLK(nvme_stat.st_mode)) { + } else { cfg.namespace_id = nvme_get_nsid(fd); if (cfg.namespace_id < 0) { err = cfg.namespace_id; @@ -2862,7 +2859,7 @@ static int format(int argc, char **argv, struct command *cmd, struct plugin *plu nvme_show_status(err); else { printf("Success formatting namespace:%x\n", cfg.namespace_id); - if (S_ISBLK(nvme_stat.st_mode) && ioctl(fd, BLKRRPART) < 0) { + if (ioctl(fd, BLKRRPART) < 0) { fprintf(stderr, "failed to re-read partition table\n"); err = -errno; goto close_fd; @@ -3522,12 +3519,10 @@ static int flush(int argc, char **argv, struct command *cmd, struct plugin *plug if (fd < 0) goto ret; - if (S_ISBLK(nvme_stat.st_mode)) { - cfg.namespace_id = nvme_get_nsid(fd); - if (cfg.namespace_id < 0) { - err = cfg.namespace_id; - goto close_fd; - } + cfg.namespace_id = nvme_get_nsid(fd); + if (cfg.namespace_id < 0) { + err = cfg.namespace_id; + goto close_fd; } err = nvme_flush(fd, cfg.namespace_id); diff --git a/plugins/netapp/netapp-nvme.c b/plugins/netapp/netapp-nvme.c index 915833a..a942f57 100644 --- a/plugins/netapp/netapp-nvme.c +++ b/plugins/netapp/netapp-nvme.c @@ -472,8 +472,6 @@ static int netapp_nvme_filter(const struct dirent *d) snprintf(path, sizeof(path), "%s%s", dev_path, d->d_name); if (stat(path, &bd)) return 0; - if (!S_ISBLK(bd.st_mode)) - return 0; if (sscanf(d->d_name, "nvme%dn%d", &ctrl, &ns) != 2) return 0; if (sscanf(d->d_name, "nvme%dn%dp%d", &ctrl, &ns, &partition) == 3)