summaryrefslogtreecommitdiffstats
path: root/sbin
diff options
context:
space:
mode:
authorjimharris <jimharris@FreeBSD.org>2013-03-26 22:14:47 +0000
committerjimharris <jimharris@FreeBSD.org>2013-03-26 22:14:47 +0000
commit73ba6bd9456829995453b1b29a0d6c5c2576fd13 (patch)
treee80173bce1cf6cd523fb08088fa8c2814a26c50f /sbin
parent8f8689b1b6afaa3b4a9d7677dafa88ba92b74982 (diff)
downloadFreeBSD-src-73ba6bd9456829995453b1b29a0d6c5c2576fd13.zip
FreeBSD-src-73ba6bd9456829995453b1b29a0d6c5c2576fd13.tar.gz
Use errno and strerror to print more descriptive messages when operations
fail in nvmecontrol(8). While here, use consistent checks of return values from stat, open and ioctl. Sponsored by: Intel Suggested by: carl Reviewed by: carl
Diffstat (limited to 'sbin')
-rw-r--r--sbin/nvmecontrol/nvmecontrol.c68
1 files changed, 41 insertions, 27 deletions
diff --git a/sbin/nvmecontrol/nvmecontrol.c b/sbin/nvmecontrol/nvmecontrol.c
index b6b6908..e9e4280 100644
--- a/sbin/nvmecontrol/nvmecontrol.c
+++ b/sbin/nvmecontrol/nvmecontrol.c
@@ -245,13 +245,15 @@ devlist(int argc, char *argv[])
fd = open(path, O_RDWR);
if (fd < 0) {
- printf("Could not open %s.\n", path);
+ printf("Could not open %s. errno=%d (%s)\n", path,
+ errno, strerror(errno));
exit_code = EX_NOPERM;
continue;
}
- if (ioctl(fd, NVME_IDENTIFY_CONTROLLER, &cdata) == -1) {
- printf("ioctl to %s failed.\n", path);
+ if (ioctl(fd, NVME_IDENTIFY_CONTROLLER, &cdata) < 0) {
+ printf("Identify request to %s failed. errno=%d (%s)\n",
+ path, errno, strerror(errno));
exit_code = EX_IOERR;
continue;
}
@@ -264,12 +266,15 @@ devlist(int argc, char *argv[])
fd = open(path, O_RDWR);
if (fd < 0) {
- printf("Could not open %s.\n", path);
+ printf("Could not open %s. errno=%d (%s)\n",
+ path, errno, strerror(errno));
exit_code = EX_NOPERM;
continue;
}
- if (ioctl(fd, NVME_IDENTIFY_NAMESPACE, &nsdata) == -1) {
- printf("ioctl to %s failed.\n", path);
+ if (ioctl(fd, NVME_IDENTIFY_NAMESPACE, &nsdata) < 0) {
+ printf("Identify request to %s failed. "
+ "errno=%d (%s)\n", path, errno,
+ strerror(errno));
exit_code = EX_IOERR;
continue;
}
@@ -311,19 +316,22 @@ identify_ctrlr(int argc, char *argv[])
sprintf(path, "/dev/%s", argv[optind]);
- if (stat(path, &devstat) != 0) {
- printf("Invalid device node '%s'.\n", path);
+ if (stat(path, &devstat) < 0) {
+ printf("Invalid device node %s. errno=%d (%s)\n", path, errno,
+ strerror(errno));
exit(EX_IOERR);
}
fd = open(path, O_RDWR);
if (fd < 0) {
- printf("Could not open %s.\n", path);
+ printf("Could not open %s. errno=%d (%s)\n", path, errno,
+ strerror(errno));
exit(EX_NOPERM);
}
- if (ioctl(fd, NVME_IDENTIFY_CONTROLLER, &cdata) == -1) {
- printf("ioctl to %s failed.\n", path);
+ if (ioctl(fd, NVME_IDENTIFY_CONTROLLER, &cdata) < 0) {
+ printf("Identify request to %s failed. errno=%d (%s)\n", path,
+ errno, strerror(errno));
exit(EX_IOERR);
}
@@ -370,19 +378,22 @@ identify_ns(int argc, char *argv[])
sprintf(path, "/dev/%s", argv[optind]);
- if (stat(path, &devstat) != 0) {
- printf("Invalid device node '%s'.\n", path);
+ if (stat(path, &devstat) < 0) {
+ printf("Invalid device node %s. errno=%d (%s)\n", path, errno,
+ strerror(errno));
exit(EX_IOERR);
}
fd = open(path, O_RDWR);
if (fd < 0) {
- printf("Could not open %s.\n", path);
+ printf("Could not open %s. errno=%d (%s)\n", path, errno,
+ strerror(errno));
exit(EX_NOPERM);
}
- if (ioctl(fd, NVME_IDENTIFY_NAMESPACE, &nsdata) == -1) {
- printf("ioctl to %s failed.\n", path);
+ if (ioctl(fd, NVME_IDENTIFY_NAMESPACE, &nsdata) < 0) {
+ printf("Identify request to %s failed. errno=%d (%s)\n", path,
+ errno, strerror(errno));
exit(EX_IOERR);
}
@@ -479,7 +490,7 @@ perftest(int argc, char *argv[])
char path[64];
u_long ioctl_cmd = NVME_IO_TEST;
bool nflag, oflag, sflag, tflag;
- int err, perthread = 0;
+ int perthread = 0;
nflag = oflag = sflag = tflag = false;
name = NULL;
@@ -569,14 +580,14 @@ perftest(int argc, char *argv[])
fd = open(path, O_RDWR);
if (fd < 0) {
- fprintf(stderr, "%s not valid device.\n", path);
+ fprintf(stderr, "%s not valid device. errno=%d (%s)\n", path,
+ errno, strerror(errno));
perftest_usage();
}
- err = ioctl(fd, ioctl_cmd, &io_test);
-
- if (err) {
- fprintf(stderr, "NVME_IO_TEST returned %d\n", errno);
+ if (ioctl(fd, ioctl_cmd, &io_test) < 0) {
+ fprintf(stderr, "NVME_IO_TEST failed. errno=%d (%s)\n", errno,
+ strerror(errno));
exit(EX_IOERR);
}
@@ -600,19 +611,22 @@ reset_ctrlr(int argc, char *argv[])
sprintf(path, "/dev/%s", argv[optind]);
- if (stat(path, &devstat) != 0) {
- printf("Invalid device node '%s'.\n", path);
+ if (stat(path, &devstat) < 0) {
+ printf("Invalid device node %s. errno=%d (%s)\n", path, errno,
+ strerror(errno));
exit(EX_IOERR);
}
fd = open(path, O_RDWR);
if (fd < 0) {
- printf("Could not open %s.\n", path);
+ printf("Could not open %s. errno=%d (%s)\n", path, errno,
+ strerror(errno));
exit(EX_NOPERM);
}
- if (ioctl(fd, NVME_RESET_CONTROLLER) == -1) {
- printf("ioctl to %s failed.\n", path);
+ if (ioctl(fd, NVME_RESET_CONTROLLER) < 0) {
+ printf("Reset request to %s failed. errno=%d (%s)\n", path,
+ errno, strerror(errno));
exit(EX_IOERR);
}
OpenPOWER on IntegriCloud