summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjimharris <jimharris@FreeBSD.org>2013-06-26 23:41:07 +0000
committerjimharris <jimharris@FreeBSD.org>2013-06-26 23:41:07 +0000
commitc089ab01fb8f33d060ae82f527fd60d9dfa9f084 (patch)
treeb17baaf7bb34767a5388f3000f63c1fdc8862cb2
parentb86441f01bc7663535df2b9b367d150f311b9d78 (diff)
downloadFreeBSD-src-c089ab01fb8f33d060ae82f527fd60d9dfa9f084.zip
FreeBSD-src-c089ab01fb8f33d060ae82f527fd60d9dfa9f084.tar.gz
Ensure that a device node is specified when invoking the identify or reset
commands. Also improve the checking of device node names, so that better error messages are displayed when incorrect names are specified. Sponsored by: Intel MFC after: 3 days
-rw-r--r--sbin/nvmecontrol/identify.c8
-rw-r--r--sbin/nvmecontrol/nvmecontrol.c18
-rw-r--r--sbin/nvmecontrol/reset.c4
3 files changed, 27 insertions, 3 deletions
diff --git a/sbin/nvmecontrol/identify.c b/sbin/nvmecontrol/identify.c
index cd1d746..c405508 100644
--- a/sbin/nvmecontrol/identify.c
+++ b/sbin/nvmecontrol/identify.c
@@ -200,6 +200,10 @@ identify_ctrlr(int argc, char *argv[])
}
}
+ /* Check that a controller was specified. */
+ if (optind >= argc)
+ identify_usage();
+
open_dev(argv[optind], &fd, 1, 1);
read_controller_data(fd, &cdata);
close(fd);
@@ -245,6 +249,10 @@ identify_ns(int argc, char *argv[])
}
}
+ /* Check that a namespace was specified. */
+ if (optind >= argc)
+ identify_usage();
+
/*
* Check if the specified device node exists before continuing.
* This is a cleaner check for cases where the correct controller
diff --git a/sbin/nvmecontrol/nvmecontrol.c b/sbin/nvmecontrol/nvmecontrol.c
index af5e148..b95ff32 100644
--- a/sbin/nvmecontrol/nvmecontrol.c
+++ b/sbin/nvmecontrol/nvmecontrol.c
@@ -126,10 +126,22 @@ open_dev(const char *str, int *fd, int show_error, int exit_on_error)
struct stat devstat;
char full_path[64];
+ if (!strnstr(str, NVME_CTRLR_PREFIX, strlen(NVME_CTRLR_PREFIX))) {
+ if (show_error)
+ fprintf(stderr,
+ "Controller/namespace IDs must begin with '%s'.\n",
+ NVME_CTRLR_PREFIX);
+ if (exit_on_error)
+ exit(EX_USAGE);
+ else
+ return (EX_USAGE);
+ }
+
snprintf(full_path, sizeof(full_path), "/dev/%s", str);
if (stat(full_path, &devstat) != 0) {
if (show_error)
- fprintf(stderr, "error\n");
+ fprintf(stderr, "Could not stat %s. errno=%d (%s)\n",
+ full_path, errno, strerror(errno));
if (exit_on_error)
exit(EX_NOINPUT);
else
@@ -139,8 +151,8 @@ open_dev(const char *str, int *fd, int show_error, int exit_on_error)
*fd = open(full_path, O_RDWR);
if (*fd < 0) {
if (show_error)
- printf("Could not open %s. errno=%d (%s)\n", full_path,
- errno, strerror(errno));
+ fprintf(stderr, "Could not open %s. errno=%d (%s)\n",
+ full_path, errno, strerror(errno));
if (exit_on_error)
exit(EX_NOPERM);
else
diff --git a/sbin/nvmecontrol/reset.c b/sbin/nvmecontrol/reset.c
index f197145..a96722c 100644
--- a/sbin/nvmecontrol/reset.c
+++ b/sbin/nvmecontrol/reset.c
@@ -60,6 +60,10 @@ reset(int argc, char *argv[])
}
}
+ /* Check that a controller was specified. */
+ if (optind >= argc)
+ reset_usage();
+
open_dev(argv[optind], &fd, 1, 1);
if (ioctl(fd, NVME_RESET_CONTROLLER) < 0) {
printf("Reset request to %s failed. errno=%d (%s)\n",
OpenPOWER on IntegriCloud