1 /*- 2 * SPDX-License-Identifier: BSD-3-Clause 3 * 4 * Copyright (c) 2008, 2009 Yahoo!, Inc. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. The names of the authors may not be used to endorse or promote 16 * products derived from this software without specific prior written 17 * permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 * SUCH DAMAGE. 30 * 31 * $FreeBSD$ 32 */ 33 34 #include <sys/param.h> 35 36 #include <err.h> 37 #include <errno.h> 38 #include <stdio.h> 39 #include <stdlib.h> 40 #include <string.h> 41 #include <unistd.h> 42 #include <paths.h> 43 #include "mfiutil.h" 44 45 SET_DECLARE(MFI_DATASET(top), struct mfiutil_command); 46 47 MFI_TABLE(top, start); 48 MFI_TABLE(top, stop); 49 MFI_TABLE(top, abort); 50 51 char *mfi_device = NULL; 52 u_int mfi_opts; 53 static int fw_name_width, fw_version_width, fw_date_width, fw_time_width; 54 55 static void 56 usage(void) 57 { 58 59 fprintf(stderr, "usage: %s [-de] [-D device] [-u unit] [-t type] <command> ...\n\n", getprogname()); 60 fprintf(stderr, "Commands include:\n"); 61 fprintf(stderr, " version\n"); 62 fprintf(stderr, " show adapter - display controller information\n"); 63 fprintf(stderr, " show battery - display battery information\n"); 64 fprintf(stderr, " show config - display RAID configuration\n"); 65 fprintf(stderr, " show drives - list physical drives\n"); 66 fprintf(stderr, " show events - display event log\n"); 67 fprintf(stderr, " show firmware - list firmware images\n"); 68 fprintf(stderr, " show foreign - display detected foreign volumes\n"); 69 fprintf(stderr, " show logstate - display event log sequence numbers\n"); 70 fprintf(stderr, " show volumes - list logical volumes\n"); 71 fprintf(stderr, " show patrol - display patrol read status\n"); 72 fprintf(stderr, " show progress - display status of active operations\n"); 73 fprintf(stderr, " fail <drive> - fail a physical drive\n"); 74 fprintf(stderr, " good <drive> - set a failed/SYSPD drive as UNCONFIGURED\n"); 75 fprintf(stderr, " rebuild <drive> - mark failed drive ready for rebuild\n"); 76 fprintf(stderr, " syspd <drive> - set drive into use as SYSPD JBOD\n"); 77 fprintf(stderr, " drive progress <drive> - display status of active operations\n"); 78 fprintf(stderr, " drive clear <drive> <start|stop> - clear a drive with all 0x00\n"); 79 fprintf(stderr, " start rebuild <drive>\n"); 80 fprintf(stderr, " abort rebuild <drive>\n"); 81 fprintf(stderr, " locate <drive> <on|off> - toggle drive LED\n"); 82 fprintf(stderr, " cache <volume> [command [setting]]\n"); 83 fprintf(stderr, " name <volume> <name>\n"); 84 fprintf(stderr, " volume progress <volume> - display status of active operations\n"); 85 fprintf(stderr, " clear - clear volume configuration\n"); 86 fprintf(stderr, " create <type> [-v] [-s stripe_size] <drive>[,<drive>[,...]] [<drive>[,<drive>[,...]]\n"); 87 fprintf(stderr, " delete <volume>\n"); 88 fprintf(stderr, " add <drive> [volume] - add a hot spare\n"); 89 fprintf(stderr, " remove <drive> - remove a hot spare\n"); 90 fprintf(stderr, " patrol <disable|auto|manual> [interval [start]]\n"); 91 fprintf(stderr, " start patrol - start a patrol read\n"); 92 fprintf(stderr, " stop patrol - stop a patrol read\n"); 93 fprintf(stderr, " foreign scan - scan for foreign configurations\n"); 94 fprintf(stderr, " foreign clear [volume] - clear foreign configurations (default all)\n"); 95 fprintf(stderr, " foreign diag [volume] - diagnostic display foreign configurations (default all)\n"); 96 fprintf(stderr, " foreign preview [volume] - preview foreign configurations (default all)\n"); 97 fprintf(stderr, " foreign import [volume] - import foreign configurations (default all)\n"); 98 fprintf(stderr, " flash <firmware>\n"); 99 fprintf(stderr, " start learn - start a BBU relearn\n"); 100 fprintf(stderr, " bbu <setting> <value> - set BBU properties\n"); 101 fprintf(stderr, " ctrlprop rebuild [rate] - get/set the volume rebuild rate\n"); 102 fprintf(stderr, " ctrlprop alarm [0/1] - enable/disable controller alarms\n"); 103 #ifdef DEBUG 104 fprintf(stderr, " debug - debug 'show config'\n"); 105 fprintf(stderr, " dump - display 'saved' config\n"); 106 #endif 107 exit(1); 108 } 109 110 static int 111 version(int ac __unused, char **av __unused) 112 { 113 114 printf("mfiutil version 1.0.15"); 115 #ifdef DEBUG 116 printf(" (DEBUG)"); 117 #endif 118 printf("\n"); 119 return (0); 120 } 121 MFI_COMMAND(top, version, version); 122 123 int 124 main(int ac, char **av) 125 { 126 struct mfiutil_command **cmd; 127 int ch, mfi_unit; 128 const char *pn, *mfi_type; 129 char *temp; 130 131 mfi_unit = 0; 132 133 pn = getprogname(); 134 135 if (strcmp(pn, "mrsasutil") == 0) 136 mfi_type = MRSAS_TYPE; 137 else 138 mfi_type = MFI_TYPE; 139 140 while ((ch = getopt(ac, av, "D:det:u:")) != -1) { 141 switch (ch) { 142 case 'D': 143 mfi_device = optarg; 144 break; 145 case 'd': 146 mfi_opts |= MFI_DNAME_DEVICE_ID; 147 break; 148 case 'e': 149 mfi_opts |= MFI_DNAME_ES; 150 break; 151 case 'u': 152 mfi_unit = atoi(optarg); 153 break; 154 case 't': 155 mfi_type = optarg; 156 break; 157 case '?': 158 usage(); 159 } 160 } 161 162 if (mfi_device == NULL) { 163 if (asprintf(&mfi_device, "%s%s%d", _PATH_DEV, mfi_type, 164 mfi_unit) < 0) 165 errx(1, "Can't allocate memory for device name\n"); 166 } else { 167 if (strncmp(mfi_device, _PATH_DEV, strlen(_PATH_DEV)) != 0) { 168 if (asprintf(&temp, "%s%s%d", _PATH_DEV, mfi_type, 169 mfi_unit) < 0) 170 errx(1, "Can't allocate memory for device name\n"); 171 mfi_device = temp; 172 } 173 } 174 175 av += optind; 176 ac -= optind; 177 178 /* getopt() eats av[0], so we can't use mfi_table_handler() directly. */ 179 if (ac == 0) 180 usage(); 181 182 SET_FOREACH(cmd, MFI_DATASET(top)) { 183 if (strcmp((*cmd)->name, av[0]) == 0) { 184 if ((*cmd)->handler(ac, av)) 185 return (1); 186 else 187 return (0); 188 } 189 } 190 warnx("Unknown command %s.", av[0]); 191 return (1); 192 } 193 194 void 195 scan_firmware(struct mfi_info_component *comp) 196 { 197 int len; 198 199 len = strlen(comp->name); 200 if (fw_name_width < len) 201 fw_name_width = len; 202 len = strlen(comp->version); 203 if (fw_version_width < len) 204 fw_version_width = len; 205 len = strlen(comp->build_date); 206 if (fw_date_width < len) 207 fw_date_width = len; 208 len = strlen(comp->build_time); 209 if (fw_time_width < len) 210 fw_time_width = len; 211 } 212 213 void 214 display_firmware(struct mfi_info_component *comp, const char *tag) 215 { 216 217 printf("%-*s %-*s %-*s %-*s %s\n", fw_name_width, comp->name, 218 fw_version_width, comp->version, fw_date_width, comp->build_date, 219 fw_time_width, comp->build_time, tag); 220 } 221