]> www.infradead.org Git - users/sagi/libnvme.git/commitdiff
fix up get_nsid api
authorKeith Busch <kbusch@kernel.org>
Fri, 5 Jun 2020 15:01:27 +0000 (08:01 -0700)
committerKeith Busch <kbusch@kernel.org>
Fri, 5 Jun 2020 15:13:42 +0000 (08:13 -0700)
namespaces can be anything from 1 to 0xfffffffe, which means they must
be unsigned. Change the api to take a parameter for the nsid value
rather than try to return an 'int', which would have confusing
signedness.

Signed-off-by: Keith Busch <kbusch@kernel.org>
src/nvme/ioctl.c
src/nvme/ioctl.h
src/nvme/tree.c

index ced189b516f5da4fba7962b3fa0ceaa6a84d0ada..d02df36f0c82ccf66edff3d6e6f7e6cde7f9eaf8 100644 (file)
@@ -66,19 +66,11 @@ int nvme_ns_rescan(int fd)
        return ioctl(fd, NVME_IOCTL_RESCAN);
 }
 
-int nvme_get_nsid(int fd)
+int nvme_get_nsid(int fd, __u32 *nsid)
 {
-       static struct stat nvme_stat;
-       int err = fstat(fd, &nvme_stat);
-
-       if (err < 0)
-               return -1;
-
-       if (!S_ISBLK(nvme_stat.st_mode)) {
-               errno = ENOTBLK;
-               return -1;
-       }
-       return ioctl(fd, NVME_IOCTL_ID);
+       errno = 0;
+       *nsid = ioctl(fd, NVME_IOCTL_ID);
+       return -1 * (errno != 0);
 }
 
 static int nvme_submit_passthru64(int fd, unsigned long ioctl_cmd,
index 22edcbe2be357d70264c34097ca0a64b1ac9f8dd..6c7b8c256e241ffa3a899089ab659cccffe70168 100644 (file)
@@ -358,13 +358,13 @@ int nvme_ns_rescan(int fd);
 /**
  * nvme_get_nsid() - Retrieve the NSID from a namespace file descriptor
  * @fd:                File descriptor of nvme namespace
+ * @nsid:      User pointer to namespace id
  *
  * This should only be sent to namespace handles, not to controllers.
  *
- * Return: The namespace identifier if a succecssful or -1 with errno set
- * otherwise.
+ * Return: 0 if @nsid was set succecssfully or -1 with errno set otherwise.
  */
-int nvme_get_nsid(int fd);
+int nvme_get_nsid(int fd, __u32 *nsid);
 
 /**
  * enum nvme_admin_opcode - Known NVMe admin opcodes
index 097d6165eb656956fba340760d9805899e3b0647..74aba7dfaf78ab166c24b7811eed587a8a73001d 100644 (file)
@@ -57,7 +57,7 @@ struct nvme_ns {
        struct nvme_ctrl *c;
 
        int fd;
-       int nsid;
+       __u32 nsid;
        char *name;
        char *sysfs_dir;
 
@@ -898,8 +898,7 @@ static nvme_ns_t nvme_ns_open(const char *name)
        if (n->fd < 0)
                goto free_ns;
 
-       n->nsid = nvme_get_nsid(n->fd);
-       if (n->nsid < 0)
+       if (nvme_get_nsid(n->fd, &n->nsid) < 0)
                goto close_fd;
 
        list_head_init(&n->paths);