]> www.infradead.org Git - users/hch/nvme-cli.git/commitdiff
remove block device checking for namespace
authorTomasz Kulasek <tomaszx.kulasek@intel.com>
Fri, 20 Sep 2019 08:29:03 +0000 (10:29 +0200)
committerKeith Busch <kbusch@kernel.org>
Mon, 4 May 2020 14:30:18 +0000 (08:30 -0600)
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 <tomaszx.kulasek@intel.com>
nvme-ioctl.c
nvme.c
plugins/netapp/netapp-nvme.c

index f3f17da3ceddc3219b4f45fe36f7fc044a6e3007..39685d6bd71bb4fb8005a94f40b8edf1f3b5bb35 100644 (file)
@@ -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 46341a64737ad25d6227002934954d1d5b735f25..64b57503c9d52a1bc323bf20b3ce4bf793b9a5f7 100644 (file)
--- 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);
index 915833abe9fb6bdf35d0321b70b4fbce5941c424..a942f57cc56b14b35a32f523eb75372242a30916 100644 (file)
@@ -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)