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
This commit is contained in:
parent
dd433dd0fb
commit
47e56bb131
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=248772
@ -245,13 +245,15 @@ devlist(int argc, char *argv[])
|
|||||||
|
|
||||||
fd = open(path, O_RDWR);
|
fd = open(path, O_RDWR);
|
||||||
if (fd < 0) {
|
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;
|
exit_code = EX_NOPERM;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ioctl(fd, NVME_IDENTIFY_CONTROLLER, &cdata) == -1) {
|
if (ioctl(fd, NVME_IDENTIFY_CONTROLLER, &cdata) < 0) {
|
||||||
printf("ioctl to %s failed.\n", path);
|
printf("Identify request to %s failed. errno=%d (%s)\n",
|
||||||
|
path, errno, strerror(errno));
|
||||||
exit_code = EX_IOERR;
|
exit_code = EX_IOERR;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -264,12 +266,15 @@ devlist(int argc, char *argv[])
|
|||||||
|
|
||||||
fd = open(path, O_RDWR);
|
fd = open(path, O_RDWR);
|
||||||
if (fd < 0) {
|
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;
|
exit_code = EX_NOPERM;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (ioctl(fd, NVME_IDENTIFY_NAMESPACE, &nsdata) == -1) {
|
if (ioctl(fd, NVME_IDENTIFY_NAMESPACE, &nsdata) < 0) {
|
||||||
printf("ioctl to %s failed.\n", path);
|
printf("Identify request to %s failed. "
|
||||||
|
"errno=%d (%s)\n", path, errno,
|
||||||
|
strerror(errno));
|
||||||
exit_code = EX_IOERR;
|
exit_code = EX_IOERR;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -311,19 +316,22 @@ identify_ctrlr(int argc, char *argv[])
|
|||||||
|
|
||||||
sprintf(path, "/dev/%s", argv[optind]);
|
sprintf(path, "/dev/%s", argv[optind]);
|
||||||
|
|
||||||
if (stat(path, &devstat) != 0) {
|
if (stat(path, &devstat) < 0) {
|
||||||
printf("Invalid device node '%s'.\n", path);
|
printf("Invalid device node %s. errno=%d (%s)\n", path, errno,
|
||||||
|
strerror(errno));
|
||||||
exit(EX_IOERR);
|
exit(EX_IOERR);
|
||||||
}
|
}
|
||||||
|
|
||||||
fd = open(path, O_RDWR);
|
fd = open(path, O_RDWR);
|
||||||
if (fd < 0) {
|
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);
|
exit(EX_NOPERM);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ioctl(fd, NVME_IDENTIFY_CONTROLLER, &cdata) == -1) {
|
if (ioctl(fd, NVME_IDENTIFY_CONTROLLER, &cdata) < 0) {
|
||||||
printf("ioctl to %s failed.\n", path);
|
printf("Identify request to %s failed. errno=%d (%s)\n", path,
|
||||||
|
errno, strerror(errno));
|
||||||
exit(EX_IOERR);
|
exit(EX_IOERR);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -370,19 +378,22 @@ identify_ns(int argc, char *argv[])
|
|||||||
|
|
||||||
sprintf(path, "/dev/%s", argv[optind]);
|
sprintf(path, "/dev/%s", argv[optind]);
|
||||||
|
|
||||||
if (stat(path, &devstat) != 0) {
|
if (stat(path, &devstat) < 0) {
|
||||||
printf("Invalid device node '%s'.\n", path);
|
printf("Invalid device node %s. errno=%d (%s)\n", path, errno,
|
||||||
|
strerror(errno));
|
||||||
exit(EX_IOERR);
|
exit(EX_IOERR);
|
||||||
}
|
}
|
||||||
|
|
||||||
fd = open(path, O_RDWR);
|
fd = open(path, O_RDWR);
|
||||||
if (fd < 0) {
|
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);
|
exit(EX_NOPERM);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ioctl(fd, NVME_IDENTIFY_NAMESPACE, &nsdata) == -1) {
|
if (ioctl(fd, NVME_IDENTIFY_NAMESPACE, &nsdata) < 0) {
|
||||||
printf("ioctl to %s failed.\n", path);
|
printf("Identify request to %s failed. errno=%d (%s)\n", path,
|
||||||
|
errno, strerror(errno));
|
||||||
exit(EX_IOERR);
|
exit(EX_IOERR);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -479,7 +490,7 @@ perftest(int argc, char *argv[])
|
|||||||
char path[64];
|
char path[64];
|
||||||
u_long ioctl_cmd = NVME_IO_TEST;
|
u_long ioctl_cmd = NVME_IO_TEST;
|
||||||
bool nflag, oflag, sflag, tflag;
|
bool nflag, oflag, sflag, tflag;
|
||||||
int err, perthread = 0;
|
int perthread = 0;
|
||||||
|
|
||||||
nflag = oflag = sflag = tflag = false;
|
nflag = oflag = sflag = tflag = false;
|
||||||
name = NULL;
|
name = NULL;
|
||||||
@ -569,14 +580,14 @@ perftest(int argc, char *argv[])
|
|||||||
|
|
||||||
fd = open(path, O_RDWR);
|
fd = open(path, O_RDWR);
|
||||||
if (fd < 0) {
|
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();
|
perftest_usage();
|
||||||
}
|
}
|
||||||
|
|
||||||
err = ioctl(fd, ioctl_cmd, &io_test);
|
if (ioctl(fd, ioctl_cmd, &io_test) < 0) {
|
||||||
|
fprintf(stderr, "NVME_IO_TEST failed. errno=%d (%s)\n", errno,
|
||||||
if (err) {
|
strerror(errno));
|
||||||
fprintf(stderr, "NVME_IO_TEST returned %d\n", errno);
|
|
||||||
exit(EX_IOERR);
|
exit(EX_IOERR);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -600,19 +611,22 @@ reset_ctrlr(int argc, char *argv[])
|
|||||||
|
|
||||||
sprintf(path, "/dev/%s", argv[optind]);
|
sprintf(path, "/dev/%s", argv[optind]);
|
||||||
|
|
||||||
if (stat(path, &devstat) != 0) {
|
if (stat(path, &devstat) < 0) {
|
||||||
printf("Invalid device node '%s'.\n", path);
|
printf("Invalid device node %s. errno=%d (%s)\n", path, errno,
|
||||||
|
strerror(errno));
|
||||||
exit(EX_IOERR);
|
exit(EX_IOERR);
|
||||||
}
|
}
|
||||||
|
|
||||||
fd = open(path, O_RDWR);
|
fd = open(path, O_RDWR);
|
||||||
if (fd < 0) {
|
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);
|
exit(EX_NOPERM);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ioctl(fd, NVME_RESET_CONTROLLER) == -1) {
|
if (ioctl(fd, NVME_RESET_CONTROLLER) < 0) {
|
||||||
printf("ioctl to %s failed.\n", path);
|
printf("Reset request to %s failed. errno=%d (%s)\n", path,
|
||||||
|
errno, strerror(errno));
|
||||||
exit(EX_IOERR);
|
exit(EX_IOERR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user