xref: /dflybsd-src/usr.sbin/mptutil/mptutil.c (revision 86d7f5d305c6adaa56ff4582ece9859d73106103)
1*86d7f5d3SJohn Marino /*-
2*86d7f5d3SJohn Marino  * Copyright (c) 2008 Yahoo!, Inc.
3*86d7f5d3SJohn Marino  * All rights reserved.
4*86d7f5d3SJohn Marino  * Written by: John Baldwin <jhb@FreeBSD.org>
5*86d7f5d3SJohn Marino  *
6*86d7f5d3SJohn Marino  * Redistribution and use in source and binary forms, with or without
7*86d7f5d3SJohn Marino  * modification, are permitted provided that the following conditions
8*86d7f5d3SJohn Marino  * are met:
9*86d7f5d3SJohn Marino  * 1. Redistributions of source code must retain the above copyright
10*86d7f5d3SJohn Marino  *    notice, this list of conditions and the following disclaimer.
11*86d7f5d3SJohn Marino  * 2. Redistributions in binary form must reproduce the above copyright
12*86d7f5d3SJohn Marino  *    notice, this list of conditions and the following disclaimer in the
13*86d7f5d3SJohn Marino  *    documentation and/or other materials provided with the distribution.
14*86d7f5d3SJohn Marino  * 3. Neither the name of the author nor the names of any co-contributors
15*86d7f5d3SJohn Marino  *    may be used to endorse or promote products derived from this software
16*86d7f5d3SJohn Marino  *    without specific prior written permission.
17*86d7f5d3SJohn Marino  *
18*86d7f5d3SJohn Marino  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19*86d7f5d3SJohn Marino  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20*86d7f5d3SJohn Marino  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21*86d7f5d3SJohn Marino  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22*86d7f5d3SJohn Marino  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23*86d7f5d3SJohn Marino  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24*86d7f5d3SJohn Marino  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25*86d7f5d3SJohn Marino  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26*86d7f5d3SJohn Marino  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27*86d7f5d3SJohn Marino  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28*86d7f5d3SJohn Marino  * SUCH DAMAGE.
29*86d7f5d3SJohn Marino  *
30*86d7f5d3SJohn Marino  * $FreeBSD: src/usr.sbin/mptutil/mptutil.c,v 1.2 2010/10/10 20:37:38 randi Exp $
31*86d7f5d3SJohn Marino  */
32*86d7f5d3SJohn Marino 
33*86d7f5d3SJohn Marino #include <sys/param.h>
34*86d7f5d3SJohn Marino #include <sys/errno.h>
35*86d7f5d3SJohn Marino #include <err.h>
36*86d7f5d3SJohn Marino #include <stdio.h>
37*86d7f5d3SJohn Marino #include <stdlib.h>
38*86d7f5d3SJohn Marino #include <string.h>
39*86d7f5d3SJohn Marino #include <unistd.h>
40*86d7f5d3SJohn Marino #include "mptutil.h"
41*86d7f5d3SJohn Marino 
42*86d7f5d3SJohn Marino SET_DECLARE(MPT_DATASET(top), struct mptutil_command);
43*86d7f5d3SJohn Marino 
44*86d7f5d3SJohn Marino int mpt_unit;
45*86d7f5d3SJohn Marino 
46*86d7f5d3SJohn Marino static void
usage(void)47*86d7f5d3SJohn Marino usage(void)
48*86d7f5d3SJohn Marino {
49*86d7f5d3SJohn Marino 
50*86d7f5d3SJohn Marino 	fprintf(stderr, "usage: mptutil [-u unit] <command> ...\n\n");
51*86d7f5d3SJohn Marino 	fprintf(stderr, "Commands include:\n");
52*86d7f5d3SJohn Marino 	fprintf(stderr, "    version\n");
53*86d7f5d3SJohn Marino 	fprintf(stderr, "    show adapter              - display controller information\n");
54*86d7f5d3SJohn Marino 	fprintf(stderr, "    show config               - display RAID configuration\n");
55*86d7f5d3SJohn Marino 	fprintf(stderr, "    show drives               - list physical drives\n");
56*86d7f5d3SJohn Marino 	fprintf(stderr, "    show events               - display event log\n");
57*86d7f5d3SJohn Marino 	fprintf(stderr, "    show volumes              - list logical volumes\n");
58*86d7f5d3SJohn Marino 	fprintf(stderr, "    fail <drive>              - fail a physical drive\n");
59*86d7f5d3SJohn Marino 	fprintf(stderr, "    online <drive>            - bring an offline physical drive online\n");
60*86d7f5d3SJohn Marino 	fprintf(stderr, "    offline <drive>           - mark a physical drive offline\n");
61*86d7f5d3SJohn Marino 	fprintf(stderr, "    name <volume> <name>\n");
62*86d7f5d3SJohn Marino 	fprintf(stderr, "    volume status <volume>    - display volume status\n");
63*86d7f5d3SJohn Marino 	fprintf(stderr, "    volume cache <volume> <enable|disable>\n");
64*86d7f5d3SJohn Marino 	fprintf(stderr, "                              - Enable or disable the volume drive caches\n");
65*86d7f5d3SJohn Marino 	fprintf(stderr, "    clear                     - clear volume configuration\n");
66*86d7f5d3SJohn Marino 	fprintf(stderr, "    create <type> [-vq] [-s stripe] <drive>[,<drive>[,...]]\n");
67*86d7f5d3SJohn Marino 	fprintf(stderr, "    delete <volume>\n");
68*86d7f5d3SJohn Marino 	fprintf(stderr, "    add <drive> [volume]      - add a hot spare\n");
69*86d7f5d3SJohn Marino 	fprintf(stderr, "    remove <drive>            - remove a hot spare\n");
70*86d7f5d3SJohn Marino #ifdef DEBUG
71*86d7f5d3SJohn Marino 	fprintf(stderr, "    pd create <drive>         - create RAID physdisk\n");
72*86d7f5d3SJohn Marino 	fprintf(stderr, "    pd delete <drive>         - delete RAID physdisk\n");
73*86d7f5d3SJohn Marino 	fprintf(stderr, "    debug                     - debug 'show config'\n");
74*86d7f5d3SJohn Marino #endif
75*86d7f5d3SJohn Marino 	exit(1);
76*86d7f5d3SJohn Marino }
77*86d7f5d3SJohn Marino 
78*86d7f5d3SJohn Marino static int
version(int ac __unused,char ** av __unused)79*86d7f5d3SJohn Marino version(int ac __unused, char **av __unused)
80*86d7f5d3SJohn Marino {
81*86d7f5d3SJohn Marino 
82*86d7f5d3SJohn Marino 	printf("mptutil version 1.0.3");
83*86d7f5d3SJohn Marino #ifdef DEBUG
84*86d7f5d3SJohn Marino 	printf(" (DEBUG)");
85*86d7f5d3SJohn Marino #endif
86*86d7f5d3SJohn Marino 	printf("\n");
87*86d7f5d3SJohn Marino 	return (0);
88*86d7f5d3SJohn Marino }
89*86d7f5d3SJohn Marino MPT_COMMAND(top, version, version);
90*86d7f5d3SJohn Marino 
91*86d7f5d3SJohn Marino int
main(int ac,char ** av)92*86d7f5d3SJohn Marino main(int ac, char **av)
93*86d7f5d3SJohn Marino {
94*86d7f5d3SJohn Marino 	struct mptutil_command **cmd;
95*86d7f5d3SJohn Marino 	int ch;
96*86d7f5d3SJohn Marino 
97*86d7f5d3SJohn Marino 	while ((ch = getopt(ac, av, "u:")) != -1) {
98*86d7f5d3SJohn Marino 		switch (ch) {
99*86d7f5d3SJohn Marino 		case 'u':
100*86d7f5d3SJohn Marino 			mpt_unit = atoi(optarg);
101*86d7f5d3SJohn Marino 			break;
102*86d7f5d3SJohn Marino 		case '?':
103*86d7f5d3SJohn Marino 			usage();
104*86d7f5d3SJohn Marino 		}
105*86d7f5d3SJohn Marino 	}
106*86d7f5d3SJohn Marino 
107*86d7f5d3SJohn Marino 	av += optind;
108*86d7f5d3SJohn Marino 	ac -= optind;
109*86d7f5d3SJohn Marino 
110*86d7f5d3SJohn Marino 	/* getopt() eats av[0], so we can't use mpt_table_handler() directly. */
111*86d7f5d3SJohn Marino 	if (ac == 0)
112*86d7f5d3SJohn Marino 		usage();
113*86d7f5d3SJohn Marino 
114*86d7f5d3SJohn Marino 	SET_FOREACH(cmd, MPT_DATASET(top)) {
115*86d7f5d3SJohn Marino 		if (strcmp((*cmd)->name, av[0]) == 0) {
116*86d7f5d3SJohn Marino 			if ((*cmd)->handler(ac, av))
117*86d7f5d3SJohn Marino 				return (1);
118*86d7f5d3SJohn Marino 			else
119*86d7f5d3SJohn Marino 				return (0);
120*86d7f5d3SJohn Marino 		}
121*86d7f5d3SJohn Marino 	}
122*86d7f5d3SJohn Marino 	warnx("Unknown command %s.", av[0]);
123*86d7f5d3SJohn Marino 	return (1);
124*86d7f5d3SJohn Marino }
125