svn commit: r252662 - stable/9/sbin/nvmecontrol
Jim Harris
jimharris at FreeBSD.org
Wed Jul 3 23:53:29 UTC 2013
Author: jimharris
Date: Wed Jul 3 23:53:28 2013
New Revision: 252662
URL: http://svnweb.freebsd.org/changeset/base/252662
Log:
MFC r252269:
Add an nvme_function structure array, defining the name, C function and
usage message for each nvmecontrol command. This helps reduce some code
clutter both now and for future commits which will add logpage and
firmware support to nvmecontrol(8).
Also move helper function prototypes to the end of the header file, after
the per-command functions.
Also add missing static keyword that glebius@ fixed as part of r252302.
Sponsored by: Intel
Modified:
stable/9/sbin/nvmecontrol/nvmecontrol.c
stable/9/sbin/nvmecontrol/nvmecontrol.h
Directory Properties:
stable/9/sbin/nvmecontrol/ (props changed)
Modified: stable/9/sbin/nvmecontrol/nvmecontrol.c
==============================================================================
--- stable/9/sbin/nvmecontrol/nvmecontrol.c Wed Jul 3 23:52:15 2013 (r252661)
+++ stable/9/sbin/nvmecontrol/nvmecontrol.c Wed Jul 3 23:53:28 2013 (r252662)
@@ -44,14 +44,31 @@ __FBSDID("$FreeBSD$");
#include "nvmecontrol.h"
+typedef void (*nvme_fn_t)(int argc, char *argv[]);
+
+static struct nvme_function {
+ const char *name;
+ nvme_fn_t fn;
+ const char *usage;
+} funcs[] = {
+ {"devlist", devlist, DEVLIST_USAGE},
+ {"identify", identify, IDENTIFY_USAGE},
+ {"perftest", perftest, PERFTEST_USAGE},
+ {"reset", reset, RESET_USAGE},
+ {NULL, NULL, NULL},
+};
+
static void
usage(void)
{
+ struct nvme_function *f;
+
+ f = funcs;
fprintf(stderr, "usage:\n");
- fprintf(stderr, DEVLIST_USAGE);
- fprintf(stderr, IDENTIFY_USAGE);
- fprintf(stderr, RESET_USAGE);
- fprintf(stderr, PERFTEST_USAGE);
+ while (f->name != NULL) {
+ fprintf(stderr, "%s", f->usage);
+ f++;
+ }
exit(EX_USAGE);
}
@@ -136,18 +153,17 @@ open_dev(const char *str, int *fd, int s
int
main(int argc, char *argv[])
{
+ struct nvme_function *f;
if (argc < 2)
usage();
- if (strcmp(argv[1], "devlist") == 0)
- devlist(argc-1, &argv[1]);
- else if (strcmp(argv[1], "identify") == 0)
- identify(argc-1, &argv[1]);
- else if (strcmp(argv[1], "perftest") == 0)
- perftest(argc-1, &argv[1]);
- else if (strcmp(argv[1], "reset") == 0)
- reset(argc-1, &argv[1]);
+ f = funcs;
+ while (f->name != NULL) {
+ if (strcmp(argv[1], f->name) == 0)
+ f->fn(argc-1, &argv[1]);
+ f++;
+ }
usage();
Modified: stable/9/sbin/nvmecontrol/nvmecontrol.h
==============================================================================
--- stable/9/sbin/nvmecontrol/nvmecontrol.h Wed Jul 3 23:52:15 2013 (r252661)
+++ stable/9/sbin/nvmecontrol/nvmecontrol.h Wed Jul 3 23:53:28 2013 (r252662)
@@ -46,14 +46,14 @@
#define RESET_USAGE \
" nvmecontrol reset <controller id>\n"
-int open_dev(const char *str, int *fd, int show_error, int exit_on_error);
-void read_controller_data(int fd, struct nvme_controller_data *cdata);
-void read_namespace_data(int fd, int nsid, struct nvme_namespace_data *nsdata);
-
void devlist(int argc, char *argv[]);
void identify(int argc, char *argv[]);
void perftest(int argc, char *argv[]);
void reset(int argc, char *argv[]);
+int open_dev(const char *str, int *fd, int show_error, int exit_on_error);
+void read_controller_data(int fd, struct nvme_controller_data *cdata);
+void read_namespace_data(int fd, int nsid, struct nvme_namespace_data *nsdata);
+
#endif
More information about the svn-src-stable-9
mailing list