mfiutil.c revision 223345
149864Sobrien/*- 21823Sphk * Copyright (c) 2008, 2009 Yahoo!, Inc. 345299Sobrien * All rights reserved. 418390Speter * 545299Sobrien * Redistribution and use in source and binary forms, with or without 645299Sobrien * modification, are permitted provided that the following conditions 749864Sobrien * are met: 849347Sobrien * 1. Redistributions of source code must retain the above copyright 949864Sobrien * notice, this list of conditions and the following disclaimer. 1049864Sobrien * 2. Redistributions in binary form must reproduce the above copyright 1149864Sobrien * notice, this list of conditions and the following disclaimer in the 1245299Sobrien * documentation and/or other materials provided with the distribution. 1345299Sobrien * 3. The names of the authors may not be used to endorse or promote 141823Sphk * products derived from this software without specific prior written 151823Sphk * permission. 1627040Spst * 1710953Sphk * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1818441Speter * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1945299Sobrien * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 201823Sphk * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 2130113Sjkh * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2218390Speter * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2349152Sobrien * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2418390Speter * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2518390Speter * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2618390Speter * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2718390Speter * SUCH DAMAGE. 2845299Sobrien * 2945299Sobrien * $FreeBSD: head/usr.sbin/mfiutil/mfiutil.c 223345 2011-06-20 21:28:50Z bz $ 3045299Sobrien */ 3145299Sobrien 3249864Sobrien#include <sys/errno.h> 3349864Sobrien#include <err.h> 3445299Sobrien#include <stdio.h> 351823Sphk#include <stdlib.h> 36#include <string.h> 37#include <unistd.h> 38#include "mfiutil.h" 39 40SET_DECLARE(MFI_DATASET(top), struct mfiutil_command); 41 42MFI_TABLE(top, start); 43MFI_TABLE(top, stop); 44MFI_TABLE(top, abort); 45 46int mfi_unit; 47 48u_int mfi_opts; 49 50static void 51usage(void) 52{ 53 54 fprintf(stderr, "usage: mfiutil [-de] [-u unit] <command> ...\n\n"); 55 fprintf(stderr, "Commands include:\n"); 56 fprintf(stderr, " version\n"); 57 fprintf(stderr, " show adapter - display controller information\n"); 58 fprintf(stderr, " show battery - display battery information\n"); 59 fprintf(stderr, " show config - display RAID configuration\n"); 60 fprintf(stderr, " show drives - list physical drives\n"); 61 fprintf(stderr, " show events - display event log\n"); 62 fprintf(stderr, " show firmware - list firmware images\n"); 63 fprintf(stderr, " show logstate - display event log sequence numbers\n"); 64 fprintf(stderr, " show volumes - list logical volumes\n"); 65 fprintf(stderr, " show patrol - display patrol read status\n"); 66 fprintf(stderr, " show progress - display status of active operations\n"); 67 fprintf(stderr, " fail <drive> - fail a physical drive\n"); 68 fprintf(stderr, " good <drive> - mark a bad physical drive as good\n"); 69 fprintf(stderr, " rebuild <drive> - mark failed drive ready for rebuild\n"); 70 fprintf(stderr, " drive progress <drive> - display status of active operations\n"); 71 fprintf(stderr, " drive clear <drive> <start|stop> - clear a drive with all 0x00\n"); 72 fprintf(stderr, " start rebuild <drive>\n"); 73 fprintf(stderr, " abort rebuild <drive>\n"); 74 fprintf(stderr, " locate <drive> <on|off> - toggle drive LED\n"); 75 fprintf(stderr, " cache <volume> [command [setting]]\n"); 76 fprintf(stderr, " name <volume> <name>\n"); 77 fprintf(stderr, " volume progress <volume> - display status of active operations\n"); 78 fprintf(stderr, " clear - clear volume configuration\n"); 79 fprintf(stderr, " create <type> [-v] <drive>[,<drive>[,...]] [<drive>[,<drive>[,...]]\n"); 80 fprintf(stderr, " delete <volume>\n"); 81 fprintf(stderr, " add <drive> [volume] - add a hot spare\n"); 82 fprintf(stderr, " remove <drive> - remove a hot spare\n"); 83 fprintf(stderr, " patrol <disable|auto|manual> [interval [start]]\n"); 84 fprintf(stderr, " start patrol - start a patrol read\n"); 85 fprintf(stderr, " stop patrol - stop a patrol read\n"); 86 fprintf(stderr, " flash <firmware>\n"); 87#ifdef DEBUG 88 fprintf(stderr, " debug - debug 'show config'\n"); 89 fprintf(stderr, " dump - display 'saved' config\n"); 90#endif 91 exit(1); 92} 93 94static int 95version(int ac, char **av) 96{ 97 98 printf("mfiutil version 1.0.13"); 99#ifdef DEBUG 100 printf(" (DEBUG)"); 101#endif 102 printf("\n"); 103 return (0); 104} 105MFI_COMMAND(top, version, version); 106 107int 108main(int ac, char **av) 109{ 110 struct mfiutil_command **cmd; 111 int ch; 112 113 while ((ch = getopt(ac, av, "deu:")) != -1) { 114 switch (ch) { 115 case 'd': 116 mfi_opts |= MFI_DNAME_DEVICE_ID; 117 break; 118 case 'e': 119 mfi_opts |= MFI_DNAME_ES; 120 break; 121 case 'u': 122 mfi_unit = atoi(optarg); 123 break; 124 case '?': 125 usage(); 126 } 127 } 128 129 av += optind; 130 ac -= optind; 131 132 /* getopt() eats av[0], so we can't use mfi_table_handler() directly. */ 133 if (ac == 0) 134 usage(); 135 136 SET_FOREACH(cmd, MFI_DATASET(top)) { 137 if (strcmp((*cmd)->name, av[0]) == 0) { 138 if ((*cmd)->handler(ac, av)) 139 return (1); 140 else 141 return (0); 142 } 143 } 144 warnx("Unknown command %s.", av[0]); 145 return (1); 146} 147