mfiutil.c revision 223267
1196200Sscottl/*- 2196200Sscottl * Copyright (c) 2008, 2009 Yahoo!, Inc. 3196200Sscottl * All rights reserved. 4196200Sscottl * 5196200Sscottl * Redistribution and use in source and binary forms, with or without 6196200Sscottl * modification, are permitted provided that the following conditions 7196200Sscottl * are met: 8196200Sscottl * 1. Redistributions of source code must retain the above copyright 9196200Sscottl * notice, this list of conditions and the following disclaimer. 10196200Sscottl * 2. Redistributions in binary form must reproduce the above copyright 11196200Sscottl * notice, this list of conditions and the following disclaimer in the 12196200Sscottl * documentation and/or other materials provided with the distribution. 13196200Sscottl * 3. The names of the authors may not be used to endorse or promote 14196200Sscottl * products derived from this software without specific prior written 15196200Sscottl * permission. 16196200Sscottl * 17196200Sscottl * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18196200Sscottl * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19196200Sscottl * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20196200Sscottl * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21196200Sscottl * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22196200Sscottl * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23196200Sscottl * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24196200Sscottl * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25196200Sscottl * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26196200Sscottl * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27196200Sscottl * SUCH DAMAGE. 28196200Sscottl * 29196200Sscottl * $FreeBSD: head/usr.sbin/mfiutil/mfiutil.c 223267 2011-06-18 21:08:27Z bz $ 30196200Sscottl */ 31196200Sscottl 32196200Sscottl#include <sys/errno.h> 33196200Sscottl#include <err.h> 34196200Sscottl#include <stdio.h> 35196200Sscottl#include <stdlib.h> 36196200Sscottl#include <string.h> 37196200Sscottl#include <unistd.h> 38196200Sscottl#include "mfiutil.h" 39196200Sscottl 40196200SscottlSET_DECLARE(MFI_DATASET(top), struct mfiutil_command); 41196200Sscottl 42196200SscottlMFI_TABLE(top, start); 43196200SscottlMFI_TABLE(top, stop); 44196200SscottlMFI_TABLE(top, abort); 45196200Sscottl 46196200Sscottlint mfi_unit; 47196200Sscottl 48196200Sscottlstatic void 49196200Sscottlusage(void) 50196200Sscottl{ 51196200Sscottl 52196200Sscottl fprintf(stderr, "usage: mfiutil [-u unit] <command> ...\n\n"); 53196200Sscottl fprintf(stderr, "Commands include:\n"); 54196200Sscottl fprintf(stderr, " version\n"); 55196200Sscottl fprintf(stderr, " show adapter - display controller information\n"); 56196200Sscottl fprintf(stderr, " show battery - display battery information\n"); 57196200Sscottl fprintf(stderr, " show config - display RAID configuration\n"); 58196200Sscottl fprintf(stderr, " show drives - list physical drives\n"); 59196200Sscottl fprintf(stderr, " show events - display event log\n"); 60196200Sscottl fprintf(stderr, " show firmware - list firmware images\n"); 61223267Sbz fprintf(stderr, " show logstate - display event log sequence numbers\n"); 62196200Sscottl fprintf(stderr, " show volumes - list logical volumes\n"); 63196200Sscottl fprintf(stderr, " show patrol - display patrol read status\n"); 64221208Sjhb fprintf(stderr, " show progress - display status of active operations\n"); 65196200Sscottl fprintf(stderr, " fail <drive> - fail a physical drive\n"); 66196200Sscottl fprintf(stderr, " good <drive> - mark a bad physical drive as good\n"); 67196200Sscottl fprintf(stderr, " rebuild <drive> - mark failed drive ready for rebuild\n"); 68196200Sscottl fprintf(stderr, " drive progress <drive> - display status of active operations\n"); 69196200Sscottl fprintf(stderr, " drive clear <drive> <start|stop> - clear a drive with all 0x00\n"); 70196200Sscottl fprintf(stderr, " start rebuild <drive>\n"); 71196200Sscottl fprintf(stderr, " abort rebuild <drive>\n"); 72196200Sscottl fprintf(stderr, " locate <drive> <on|off> - toggle drive LED\n"); 73196200Sscottl fprintf(stderr, " cache <volume> [command [setting]]\n"); 74196200Sscottl fprintf(stderr, " name <volume> <name>\n"); 75196200Sscottl fprintf(stderr, " volume progress <volume> - display status of active operations\n"); 76196200Sscottl fprintf(stderr, " clear - clear volume configuration\n"); 77196200Sscottl fprintf(stderr, " create <type> [-v] <drive>[,<drive>[,...]] [<drive>[,<drive>[,...]]\n"); 78196200Sscottl fprintf(stderr, " delete <volume>\n"); 79196200Sscottl fprintf(stderr, " add <drive> [volume] - add a hot spare\n"); 80196200Sscottl fprintf(stderr, " remove <drive> - remove a hot spare\n"); 81196200Sscottl fprintf(stderr, " patrol <disable|auto|manual> [interval [start]]\n"); 82196200Sscottl fprintf(stderr, " start patrol - start a patrol read\n"); 83196200Sscottl fprintf(stderr, " stop patrol - stop a patrol read\n"); 84196200Sscottl fprintf(stderr, " flash <firmware>\n"); 85196200Sscottl#ifdef DEBUG 86196200Sscottl fprintf(stderr, " debug - debug 'show config'\n"); 87196200Sscottl fprintf(stderr, " dump - display 'saved' config\n"); 88196200Sscottl#endif 89196200Sscottl exit(1); 90196200Sscottl} 91196200Sscottl 92196200Sscottlstatic int 93196200Sscottlversion(int ac, char **av) 94196200Sscottl{ 95196200Sscottl 96196200Sscottl printf("mfiutil version 1.0.13"); 97196200Sscottl#ifdef DEBUG 98196200Sscottl printf(" (DEBUG)"); 99196200Sscottl#endif 100196200Sscottl printf("\n"); 101196200Sscottl return (0); 102196200Sscottl} 103196200SscottlMFI_COMMAND(top, version, version); 104196200Sscottl 105196200Sscottlint 106196200Sscottlmain(int ac, char **av) 107196200Sscottl{ 108196200Sscottl struct mfiutil_command **cmd; 109196200Sscottl int ch; 110196200Sscottl 111196200Sscottl while ((ch = getopt(ac, av, "u:")) != -1) { 112196200Sscottl switch (ch) { 113196200Sscottl case 'u': 114196200Sscottl mfi_unit = atoi(optarg); 115196200Sscottl break; 116196200Sscottl case '?': 117196200Sscottl usage(); 118196200Sscottl } 119196200Sscottl } 120196200Sscottl 121196200Sscottl av += optind; 122196200Sscottl ac -= optind; 123196200Sscottl 124196200Sscottl /* getopt() eats av[0], so we can't use mfi_table_handler() directly. */ 125196200Sscottl if (ac == 0) 126196200Sscottl usage(); 127196200Sscottl 128196200Sscottl SET_FOREACH(cmd, MFI_DATASET(top)) { 129196200Sscottl if (strcmp((*cmd)->name, av[0]) == 0) { 130213672Srandi if ((*cmd)->handler(ac, av)) 131213672Srandi return (1); 132213672Srandi else 133213672Srandi return (0); 134196200Sscottl } 135196200Sscottl } 136196200Sscottl warnx("Unknown command %s.", av[0]); 137213672Srandi return (1); 138196200Sscottl} 139