1219089Spjd/*- 2209962Smm * Copyright (c) 2008 Yahoo!, Inc. 3209962Smm * All rights reserved. 4209962Smm * Written by: John Baldwin <jhb@FreeBSD.org> 5209962Smm * 6209962Smm * Redistribution and use in source and binary forms, with or without 7209962Smm * modification, are permitted provided that the following conditions 8209962Smm * are met: 9209962Smm * 1. Redistributions of source code must retain the above copyright 10209962Smm * notice, this list of conditions and the following disclaimer. 11209962Smm * 2. Redistributions in binary form must reproduce the above copyright 12209962Smm * notice, this list of conditions and the following disclaimer in the 13209962Smm * documentation and/or other materials provided with the distribution. 14209962Smm * 3. Neither the name of the author nor the names of any co-contributors 15209962Smm * may be used to endorse or promote products derived from this software 16209962Smm * without specific prior written permission. 17209962Smm * 18209962Smm * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 19209962Smm * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20209962Smm * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21209962Smm * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 22219089Spjd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23209962Smm * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24209962Smm * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25209962Smm * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26209962Smm * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27209962Smm * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28209962Smm * SUCH DAMAGE. 29209962Smm */ 30209962Smm 31209962Smm#include <sys/cdefs.h> 32209962Smm__RCSID("$FreeBSD: releng/10.3/usr.sbin/mptutil/mptutil.c 213672 2010-10-10 20:37:38Z randi $"); 33219089Spjd 34219089Spjd#include <sys/param.h> 35219089Spjd#include <sys/errno.h> 36219089Spjd#include <err.h> 37219089Spjd#include <stdio.h> 38209962Smm#include <stdlib.h> 39209962Smm#include <string.h> 40209962Smm#include <unistd.h> 41209962Smm#include "mptutil.h" 42209962Smm 43209962SmmSET_DECLARE(MPT_DATASET(top), struct mptutil_command); 44209962Smm 45209962Smmint mpt_unit; 46209962Smm 47209962Smmstatic void 48209962Smmusage(void) 49209962Smm{ 50209962Smm 51209962Smm fprintf(stderr, "usage: mptutil [-u unit] <command> ...\n\n"); 52209962Smm fprintf(stderr, "Commands include:\n"); 53209962Smm fprintf(stderr, " version\n"); 54209962Smm fprintf(stderr, " show adapter - display controller information\n"); 55209962Smm fprintf(stderr, " show config - display RAID configuration\n"); 56209962Smm fprintf(stderr, " show drives - list physical drives\n"); 57209962Smm fprintf(stderr, " show events - display event log\n"); 58209962Smm fprintf(stderr, " show volumes - list logical volumes\n"); 59209962Smm fprintf(stderr, " fail <drive> - fail a physical drive\n"); 60209962Smm fprintf(stderr, " online <drive> - bring an offline physical drive online\n"); 61209962Smm fprintf(stderr, " offline <drive> - mark a physical drive offline\n"); 62209962Smm fprintf(stderr, " name <volume> <name>\n"); 63209962Smm fprintf(stderr, " volume status <volume> - display volume status\n"); 64209962Smm fprintf(stderr, " volume cache <volume> <enable|disable>\n"); 65209962Smm fprintf(stderr, " - Enable or disable the volume drive caches\n"); 66209962Smm fprintf(stderr, " clear - clear volume configuration\n"); 67209962Smm fprintf(stderr, " create <type> [-vq] [-s stripe] <drive>[,<drive>[,...]]\n"); 68209962Smm fprintf(stderr, " delete <volume>\n"); 69209962Smm fprintf(stderr, " add <drive> [volume] - add a hot spare\n"); 70209962Smm fprintf(stderr, " remove <drive> - remove a hot spare\n"); 71219089Spjd#ifdef DEBUG 72209962Smm fprintf(stderr, " pd create <drive> - create RAID physdisk\n"); 73219089Spjd fprintf(stderr, " pd delete <drive> - delete RAID physdisk\n"); 74209962Smm fprintf(stderr, " debug - debug 'show config'\n"); 75209962Smm#endif 76209962Smm exit(1); 77209962Smm} 78209962Smm 79209962Smmstatic int 80209962Smmversion(int ac, char **av) 81209962Smm{ 82209962Smm 83209962Smm printf("mptutil version 1.0.3"); 84209962Smm#ifdef DEBUG 85209962Smm printf(" (DEBUG)"); 86209962Smm#endif 87209962Smm printf("\n"); 88209962Smm return (0); 89209962Smm} 90209962SmmMPT_COMMAND(top, version, version); 91209962Smm 92209962Smmint 93209962Smmmain(int ac, char **av) 94209962Smm{ 95209962Smm struct mptutil_command **cmd; 96209962Smm int ch; 97209962Smm 98209962Smm while ((ch = getopt(ac, av, "u:")) != -1) { 99209962Smm switch (ch) { 100209962Smm case 'u': 101209962Smm mpt_unit = atoi(optarg); 102209962Smm break; 103219089Spjd case '?': 104219089Spjd usage(); 105209962Smm } 106209962Smm } 107209962Smm 108209962Smm av += optind; 109209962Smm ac -= optind; 110209962Smm 111209962Smm /* getopt() eats av[0], so we can't use mpt_table_handler() directly. */ 112219089Spjd if (ac == 0) 113209962Smm usage(); 114209962Smm 115209962Smm SET_FOREACH(cmd, MPT_DATASET(top)) { 116209962Smm if (strcmp((*cmd)->name, av[0]) == 0) { 117209962Smm if ((*cmd)->handler(ac, av)) 118209962Smm return (1); 119209962Smm else 120209962Smm return (0); 121209962Smm } 122209962Smm } 123209962Smm warnx("Unknown command %s.", av[0]); 124209962Smm return (1); 125209962Smm} 126209962Smm