xref: /freebsd/usr.sbin/mfiutil/mfiutil.c (revision 4ee8bfc521a048d8fd318c9c7dbad129b0da87d7)
1763fae79SScott Long /*-
2763fae79SScott Long  * Copyright (c) 2008, 2009 Yahoo!, Inc.
3763fae79SScott Long  * All rights reserved.
4763fae79SScott Long  *
5763fae79SScott Long  * Redistribution and use in source and binary forms, with or without
6763fae79SScott Long  * modification, are permitted provided that the following conditions
7763fae79SScott Long  * are met:
8763fae79SScott Long  * 1. Redistributions of source code must retain the above copyright
9763fae79SScott Long  *    notice, this list of conditions and the following disclaimer.
10763fae79SScott Long  * 2. Redistributions in binary form must reproduce the above copyright
11763fae79SScott Long  *    notice, this list of conditions and the following disclaimer in the
12763fae79SScott Long  *    documentation and/or other materials provided with the distribution.
13763fae79SScott Long  * 3. The names of the authors may not be used to endorse or promote
14763fae79SScott Long  *    products derived from this software without specific prior written
15763fae79SScott Long  *    permission.
16763fae79SScott Long  *
17763fae79SScott Long  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18763fae79SScott Long  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19763fae79SScott Long  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20763fae79SScott Long  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21763fae79SScott Long  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22763fae79SScott Long  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23763fae79SScott Long  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24763fae79SScott Long  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25763fae79SScott Long  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26763fae79SScott Long  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27763fae79SScott Long  * SUCH DAMAGE.
28763fae79SScott Long  *
29763fae79SScott Long  * $FreeBSD$
30763fae79SScott Long  */
31763fae79SScott Long 
32763fae79SScott Long #include <sys/errno.h>
33763fae79SScott Long #include <err.h>
34763fae79SScott Long #include <stdio.h>
35763fae79SScott Long #include <stdlib.h>
36763fae79SScott Long #include <string.h>
37763fae79SScott Long #include <unistd.h>
38763fae79SScott Long #include "mfiutil.h"
39763fae79SScott Long 
40763fae79SScott Long SET_DECLARE(MFI_DATASET(top), struct mfiutil_command);
41763fae79SScott Long 
42763fae79SScott Long MFI_TABLE(top, start);
43763fae79SScott Long MFI_TABLE(top, stop);
44763fae79SScott Long MFI_TABLE(top, abort);
45763fae79SScott Long 
46763fae79SScott Long int mfi_unit;
47763fae79SScott Long 
48763fae79SScott Long static void
49763fae79SScott Long usage(void)
50763fae79SScott Long {
51763fae79SScott Long 
52763fae79SScott Long 	fprintf(stderr, "usage: mfiutil [-u unit] <command> ...\n\n");
53763fae79SScott Long 	fprintf(stderr, "Commands include:\n");
54763fae79SScott Long 	fprintf(stderr, "    version\n");
55763fae79SScott Long 	fprintf(stderr, "    show adapter              - display controller information\n");
56763fae79SScott Long 	fprintf(stderr, "    show battery              - display battery information\n");
57763fae79SScott Long 	fprintf(stderr, "    show config               - display RAID configuration\n");
58763fae79SScott Long 	fprintf(stderr, "    show drives               - list physical drives\n");
59763fae79SScott Long 	fprintf(stderr, "    show events               - display event log\n");
60763fae79SScott Long 	fprintf(stderr, "    show firmware             - list firmware images\n");
61763fae79SScott Long 	fprintf(stderr, "    show volumes              - list logical volumes\n");
62763fae79SScott Long 	fprintf(stderr, "    show patrol               - display patrol read status\n");
63763fae79SScott Long 	fprintf(stderr, "    fail <drive>              - fail a physical drive\n");
64763fae79SScott Long 	fprintf(stderr, "    good <drive>              - mark a bad physical drive as good\n");
65763fae79SScott Long 	fprintf(stderr, "    rebuild <drive>           - mark failed drive ready for rebuild\n");
66763fae79SScott Long 	fprintf(stderr, "    drive progress <drive>    - display status of active operations\n");
67763fae79SScott Long 	fprintf(stderr, "    drive clear <drive> <start|stop> - clear a drive with all 0x00\n");
68763fae79SScott Long 	fprintf(stderr, "    start rebuild <drive>\n");
69763fae79SScott Long 	fprintf(stderr, "    abort rebuild <drive>\n");
70763fae79SScott Long 	fprintf(stderr, "    locate <drive> <on|off>   - toggle drive LED\n");
71763fae79SScott Long 	fprintf(stderr, "    cache <volume> [command [setting]]\n");
72763fae79SScott Long 	fprintf(stderr, "    name <volume> <name>\n");
73763fae79SScott Long 	fprintf(stderr, "    volume progress <volume>  - display status of active operations\n");
74763fae79SScott Long 	fprintf(stderr, "    clear                     - clear volume configuration\n");
75763fae79SScott Long 	fprintf(stderr, "    create <type> [-v] <drive>[,<drive>[,...]] [<drive>[,<drive>[,...]]\n");
76763fae79SScott Long 	fprintf(stderr, "    delete <volume>\n");
77763fae79SScott Long 	fprintf(stderr, "    add <drive> [volume]      - add a hot spare\n");
78763fae79SScott Long 	fprintf(stderr, "    remove <drive>            - remove a hot spare\n");
79763fae79SScott Long 	fprintf(stderr, "    patrol <disable|auto|manual> [interval [start]]\n");
80763fae79SScott Long 	fprintf(stderr, "    start patrol              - start a patrol read\n");
81763fae79SScott Long 	fprintf(stderr, "    stop patrol               - stop a patrol read\n");
82763fae79SScott Long 	fprintf(stderr, "    flash <firmware>\n");
83763fae79SScott Long #ifdef DEBUG
84763fae79SScott Long 	fprintf(stderr, "    debug                     - debug 'show config'\n");
85763fae79SScott Long 	fprintf(stderr, "    dump                      - display 'saved' config\n");
86763fae79SScott Long #endif
87763fae79SScott Long 	exit(1);
88763fae79SScott Long }
89763fae79SScott Long 
90763fae79SScott Long static int
91763fae79SScott Long version(int ac, char **av)
92763fae79SScott Long {
93763fae79SScott Long 
94763fae79SScott Long 	printf("mfiutil version 1.0.13");
95763fae79SScott Long #ifdef DEBUG
96763fae79SScott Long 	printf(" (DEBUG)");
97763fae79SScott Long #endif
98763fae79SScott Long 	printf("\n");
99763fae79SScott Long 	return (0);
100763fae79SScott Long }
101763fae79SScott Long MFI_COMMAND(top, version, version);
102763fae79SScott Long 
103763fae79SScott Long int
104763fae79SScott Long main(int ac, char **av)
105763fae79SScott Long {
106763fae79SScott Long 	struct mfiutil_command **cmd;
107763fae79SScott Long 	int ch;
108763fae79SScott Long 
109763fae79SScott Long 	while ((ch = getopt(ac, av, "u:")) != -1) {
110763fae79SScott Long 		switch (ch) {
111763fae79SScott Long 		case 'u':
112763fae79SScott Long 			mfi_unit = atoi(optarg);
113763fae79SScott Long 			break;
114763fae79SScott Long 		case '?':
115763fae79SScott Long 			usage();
116763fae79SScott Long 		}
117763fae79SScott Long 	}
118763fae79SScott Long 
119763fae79SScott Long 	av += optind;
120763fae79SScott Long 	ac -= optind;
121763fae79SScott Long 
122763fae79SScott Long 	/* getopt() eats av[0], so we can't use mfi_table_handler() directly. */
123763fae79SScott Long 	if (ac == 0)
124763fae79SScott Long 		usage();
125763fae79SScott Long 
126763fae79SScott Long 	SET_FOREACH(cmd, MFI_DATASET(top)) {
127763fae79SScott Long 		if (strcmp((*cmd)->name, av[0]) == 0) {
128*4ee8bfc5SRandi Harper 			if ((*cmd)->handler(ac, av))
129*4ee8bfc5SRandi Harper 				return (1);
130*4ee8bfc5SRandi Harper 			else
131763fae79SScott Long 				return (0);
132763fae79SScott Long 		}
133763fae79SScott Long 	}
134763fae79SScott Long 	warnx("Unknown command %s.", av[0]);
135*4ee8bfc5SRandi Harper 	return (1);
136763fae79SScott Long }
137