]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
nvme-cli: fix perror when blkdev not given when get-ns-id
authorMinwoo Im <minwoo.im.dev@gmail.com>
Sun, 15 Apr 2018 16:23:45 +0000 (01:23 +0900)
committerMinwoo Im <minwoo.im.dev@gmail.com>
Sun, 15 Apr 2018 16:31:15 +0000 (01:31 +0900)
nvme-cli currently is printing out the error code via perror when nsid
from the nvme_get_nsid(fd) <= 0.  Once user gives a chrdev node instead of
blkdev node, following "Success" message is being printed-out even it's
a failure case.

  Error: requesting namespace-id from non-block device
  nvme0: Success

errno will *not* be set in case that blkdev is not given.  So set the
proper errno for this case.  The following message will be nicer than
previous one.

  Error: requesting namespace-id from non-block device
  nvme0: Block device required

This patch will also fix the return value of this subcommand.  0 will
*not* be given when the subcommand fails.

Signed-off-by: Minwoo Im <minwoo.im.dev@gmail.com>
nvme-ioctl.c

index e8ba9354032ff432f1235114bad173ea38f06ccc..8ddb0b8fd199cc5762a225ba43e14c70ab38c099 100644 (file)
@@ -79,7 +79,8 @@ int nvme_get_nsid(int fd)
        if (!S_ISBLK(nvme_stat.st_mode)) {
                fprintf(stderr,
                        "Error: requesting namespace-id from non-block device\n");
-               return -ENOTBLK;
+               errno = ENOTBLK;
+               return -errno;
        }
        return ioctl(fd, NVME_IOCTL_ID);
 }