nvmet: never fail double namespace enablement
authorMax Gurtovoy <maxg@mellanox.com>
Tue, 2 Apr 2019 11:52:47 +0000 (14:52 +0300)
committerChristoph Hellwig <hch@lst.de>
Fri, 5 Apr 2019 06:07:58 +0000 (08:07 +0200)
In case we create N namespaces while N < NVMET_MAX_NAMESPACES, we can
perform "echo 1 > <nsid>/enable" as much as we want. In case N ==
NVMET_MAX_NAMESPACES we fail. Make sure we have the same flow for any N.

Signed-off-by: Max Gurtovoy <maxg@mellanox.com>
Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de>
Signed-off-by: Christoph Hellwig <hch@lst.de>
drivers/nvme/target/core.c

index b3e765a95af8ee7447c536ff48095504c8100d67..4dc388a2ecb0121f8ddb6911476abb9e011761c6 100644 (file)
@@ -494,13 +494,14 @@ int nvmet_ns_enable(struct nvmet_ns *ns)
        int ret;
 
        mutex_lock(&subsys->lock);
-       ret = -EMFILE;
-       if (subsys->nr_namespaces == NVMET_MAX_NAMESPACES)
-               goto out_unlock;
        ret = 0;
        if (ns->enabled)
                goto out_unlock;
 
+       ret = -EMFILE;
+       if (subsys->nr_namespaces == NVMET_MAX_NAMESPACES)
+               goto out_unlock;
+
        ret = nvmet_bdev_ns_enable(ns);
        if (ret == -ENOTBLK)
                ret = nvmet_file_ns_enable(ns);