From owner-svn-src-head@FreeBSD.ORG Wed Jun 26 23:11:21 2013 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id A4991B7D; Wed, 26 Jun 2013 23:11:21 +0000 (UTC) (envelope-from jimharris@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) by mx1.freebsd.org (Postfix) with ESMTP id 884481462; Wed, 26 Jun 2013 23:11:21 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r5QNBLxJ000811; Wed, 26 Jun 2013 23:11:21 GMT (envelope-from jimharris@svn.freebsd.org) Received: (from jimharris@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r5QNBLov000809; Wed, 26 Jun 2013 23:11:21 GMT (envelope-from jimharris@svn.freebsd.org) Message-Id: <201306262311.r5QNBLov000809@svn.freebsd.org> From: Jim Harris Date: Wed, 26 Jun 2013 23:11:21 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r252269 - head/sbin/nvmecontrol X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 26 Jun 2013 23:11:21 -0000 Author: jimharris Date: Wed Jun 26 23:11:20 2013 New Revision: 252269 URL: http://svnweb.freebsd.org/changeset/base/252269 Log: 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. Sponsored by: Intel MFC after: 3 days Modified: head/sbin/nvmecontrol/nvmecontrol.c head/sbin/nvmecontrol/nvmecontrol.h Modified: head/sbin/nvmecontrol/nvmecontrol.c ============================================================================== --- head/sbin/nvmecontrol/nvmecontrol.c Wed Jun 26 23:05:48 2013 (r252268) +++ head/sbin/nvmecontrol/nvmecontrol.c Wed Jun 26 23:11:20 2013 (r252269) @@ -44,14 +44,31 @@ __FBSDID("$FreeBSD$"); #include "nvmecontrol.h" +typedef void (*nvme_fn_t)(int argc, char *argv[]); + +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: head/sbin/nvmecontrol/nvmecontrol.h ============================================================================== --- head/sbin/nvmecontrol/nvmecontrol.h Wed Jun 26 23:05:48 2013 (r252268) +++ head/sbin/nvmecontrol/nvmecontrol.h Wed Jun 26 23:11:20 2013 (r252269) @@ -46,14 +46,14 @@ #define RESET_USAGE \ " nvmecontrol reset \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