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