From: Keith Busch Date: Fri, 5 Jun 2020 15:01:27 +0000 (-0700) Subject: fix up get_nsid api X-Git-Tag: v1.0-rc0~147 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=0895b50cead4ebd39b1409e6f3e87e6423c0974b;p=users%2Fsagi%2Flibnvme.git fix up get_nsid api 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 --- diff --git a/src/nvme/ioctl.c b/src/nvme/ioctl.c index ced189b5..d02df36f 100644 --- a/src/nvme/ioctl.c +++ b/src/nvme/ioctl.c @@ -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, diff --git a/src/nvme/ioctl.h b/src/nvme/ioctl.h index 22edcbe2..6c7b8c25 100644 --- a/src/nvme/ioctl.h +++ b/src/nvme/ioctl.h @@ -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 diff --git a/src/nvme/tree.c b/src/nvme/tree.c index 097d6165..74aba7df 100644 --- a/src/nvme/tree.c +++ b/src/nvme/tree.c @@ -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);