186d7f5d3SJohn Marino /*-
286d7f5d3SJohn Marino * Copyright (c) 2008 Yahoo!, Inc.
386d7f5d3SJohn Marino * All rights reserved.
486d7f5d3SJohn Marino * Written by: John Baldwin <jhb@FreeBSD.org>
586d7f5d3SJohn Marino *
686d7f5d3SJohn Marino * Redistribution and use in source and binary forms, with or without
786d7f5d3SJohn Marino * modification, are permitted provided that the following conditions
886d7f5d3SJohn Marino * are met:
986d7f5d3SJohn Marino * 1. Redistributions of source code must retain the above copyright
1086d7f5d3SJohn Marino * notice, this list of conditions and the following disclaimer.
1186d7f5d3SJohn Marino * 2. Redistributions in binary form must reproduce the above copyright
1286d7f5d3SJohn Marino * notice, this list of conditions and the following disclaimer in the
1386d7f5d3SJohn Marino * documentation and/or other materials provided with the distribution.
1486d7f5d3SJohn Marino * 3. Neither the name of the author nor the names of any co-contributors
1586d7f5d3SJohn Marino * may be used to endorse or promote products derived from this software
1686d7f5d3SJohn Marino * without specific prior written permission.
1786d7f5d3SJohn Marino *
1886d7f5d3SJohn Marino * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1986d7f5d3SJohn Marino * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2086d7f5d3SJohn Marino * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2186d7f5d3SJohn Marino * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2286d7f5d3SJohn Marino * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2386d7f5d3SJohn Marino * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2486d7f5d3SJohn Marino * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2586d7f5d3SJohn Marino * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2686d7f5d3SJohn Marino * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2786d7f5d3SJohn Marino * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2886d7f5d3SJohn Marino * SUCH DAMAGE.
2986d7f5d3SJohn Marino *
3086d7f5d3SJohn Marino * $FreeBSD: src/usr.sbin/mptutil/mptutil.c,v 1.2 2010/10/10 20:37:38 randi Exp $
3186d7f5d3SJohn Marino */
3286d7f5d3SJohn Marino
3386d7f5d3SJohn Marino #include <sys/param.h>
3486d7f5d3SJohn Marino #include <sys/errno.h>
3586d7f5d3SJohn Marino #include <err.h>
3686d7f5d3SJohn Marino #include <stdio.h>
3786d7f5d3SJohn Marino #include <stdlib.h>
3886d7f5d3SJohn Marino #include <string.h>
3986d7f5d3SJohn Marino #include <unistd.h>
4086d7f5d3SJohn Marino #include "mptutil.h"
4186d7f5d3SJohn Marino
4286d7f5d3SJohn Marino SET_DECLARE(MPT_DATASET(top), struct mptutil_command);
4386d7f5d3SJohn Marino
4486d7f5d3SJohn Marino int mpt_unit;
4586d7f5d3SJohn Marino
4686d7f5d3SJohn Marino static void
usage(void)4786d7f5d3SJohn Marino usage(void)
4886d7f5d3SJohn Marino {
4986d7f5d3SJohn Marino
5086d7f5d3SJohn Marino fprintf(stderr, "usage: mptutil [-u unit] <command> ...\n\n");
5186d7f5d3SJohn Marino fprintf(stderr, "Commands include:\n");
5286d7f5d3SJohn Marino fprintf(stderr, " version\n");
5386d7f5d3SJohn Marino fprintf(stderr, " show adapter - display controller information\n");
5486d7f5d3SJohn Marino fprintf(stderr, " show config - display RAID configuration\n");
5586d7f5d3SJohn Marino fprintf(stderr, " show drives - list physical drives\n");
5686d7f5d3SJohn Marino fprintf(stderr, " show events - display event log\n");
5786d7f5d3SJohn Marino fprintf(stderr, " show volumes - list logical volumes\n");
5886d7f5d3SJohn Marino fprintf(stderr, " fail <drive> - fail a physical drive\n");
5986d7f5d3SJohn Marino fprintf(stderr, " online <drive> - bring an offline physical drive online\n");
6086d7f5d3SJohn Marino fprintf(stderr, " offline <drive> - mark a physical drive offline\n");
6186d7f5d3SJohn Marino fprintf(stderr, " name <volume> <name>\n");
6286d7f5d3SJohn Marino fprintf(stderr, " volume status <volume> - display volume status\n");
6386d7f5d3SJohn Marino fprintf(stderr, " volume cache <volume> <enable|disable>\n");
6486d7f5d3SJohn Marino fprintf(stderr, " - Enable or disable the volume drive caches\n");
6586d7f5d3SJohn Marino fprintf(stderr, " clear - clear volume configuration\n");
6686d7f5d3SJohn Marino fprintf(stderr, " create <type> [-vq] [-s stripe] <drive>[,<drive>[,...]]\n");
6786d7f5d3SJohn Marino fprintf(stderr, " delete <volume>\n");
6886d7f5d3SJohn Marino fprintf(stderr, " add <drive> [volume] - add a hot spare\n");
6986d7f5d3SJohn Marino fprintf(stderr, " remove <drive> - remove a hot spare\n");
7086d7f5d3SJohn Marino #ifdef DEBUG
7186d7f5d3SJohn Marino fprintf(stderr, " pd create <drive> - create RAID physdisk\n");
7286d7f5d3SJohn Marino fprintf(stderr, " pd delete <drive> - delete RAID physdisk\n");
7386d7f5d3SJohn Marino fprintf(stderr, " debug - debug 'show config'\n");
7486d7f5d3SJohn Marino #endif
7586d7f5d3SJohn Marino exit(1);
7686d7f5d3SJohn Marino }
7786d7f5d3SJohn Marino
7886d7f5d3SJohn Marino static int
version(int ac __unused,char ** av __unused)7986d7f5d3SJohn Marino version(int ac __unused, char **av __unused)
8086d7f5d3SJohn Marino {
8186d7f5d3SJohn Marino
8286d7f5d3SJohn Marino printf("mptutil version 1.0.3");
8386d7f5d3SJohn Marino #ifdef DEBUG
8486d7f5d3SJohn Marino printf(" (DEBUG)");
8586d7f5d3SJohn Marino #endif
8686d7f5d3SJohn Marino printf("\n");
8786d7f5d3SJohn Marino return (0);
8886d7f5d3SJohn Marino }
8986d7f5d3SJohn Marino MPT_COMMAND(top, version, version);
9086d7f5d3SJohn Marino
9186d7f5d3SJohn Marino int
main(int ac,char ** av)9286d7f5d3SJohn Marino main(int ac, char **av)
9386d7f5d3SJohn Marino {
9486d7f5d3SJohn Marino struct mptutil_command **cmd;
9586d7f5d3SJohn Marino int ch;
9686d7f5d3SJohn Marino
9786d7f5d3SJohn Marino while ((ch = getopt(ac, av, "u:")) != -1) {
9886d7f5d3SJohn Marino switch (ch) {
9986d7f5d3SJohn Marino case 'u':
10086d7f5d3SJohn Marino mpt_unit = atoi(optarg);
10186d7f5d3SJohn Marino break;
10286d7f5d3SJohn Marino case '?':
10386d7f5d3SJohn Marino usage();
10486d7f5d3SJohn Marino }
10586d7f5d3SJohn Marino }
10686d7f5d3SJohn Marino
10786d7f5d3SJohn Marino av += optind;
10886d7f5d3SJohn Marino ac -= optind;
10986d7f5d3SJohn Marino
11086d7f5d3SJohn Marino /* getopt() eats av[0], so we can't use mpt_table_handler() directly. */
11186d7f5d3SJohn Marino if (ac == 0)
11286d7f5d3SJohn Marino usage();
11386d7f5d3SJohn Marino
11486d7f5d3SJohn Marino SET_FOREACH(cmd, MPT_DATASET(top)) {
11586d7f5d3SJohn Marino if (strcmp((*cmd)->name, av[0]) == 0) {
11686d7f5d3SJohn Marino if ((*cmd)->handler(ac, av))
11786d7f5d3SJohn Marino return (1);
11886d7f5d3SJohn Marino else
11986d7f5d3SJohn Marino return (0);
12086d7f5d3SJohn Marino }
12186d7f5d3SJohn Marino }
12286d7f5d3SJohn Marino warnx("Unknown command %s.", av[0]);
12386d7f5d3SJohn Marino return (1);
12486d7f5d3SJohn Marino }
125