1*45039663SJohn Forte /* 2*45039663SJohn Forte * CDDL HEADER START 3*45039663SJohn Forte * 4*45039663SJohn Forte * The contents of this file are subject to the terms of the 5*45039663SJohn Forte * Common Development and Distribution License (the "License"). 6*45039663SJohn Forte * You may not use this file except in compliance with the License. 7*45039663SJohn Forte * 8*45039663SJohn Forte * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9*45039663SJohn Forte * or http://www.opensolaris.org/os/licensing. 10*45039663SJohn Forte * See the License for the specific language governing permissions 11*45039663SJohn Forte * and limitations under the License. 12*45039663SJohn Forte * 13*45039663SJohn Forte * When distributing Covered Code, include this CDDL HEADER in each 14*45039663SJohn Forte * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15*45039663SJohn Forte * If applicable, add the following below this CDDL HEADER, with the 16*45039663SJohn Forte * fields enclosed by brackets "[]" replaced with your own identifying 17*45039663SJohn Forte * information: Portions Copyright [yyyy] [name of copyright owner] 18*45039663SJohn Forte * 19*45039663SJohn Forte * CDDL HEADER END 20*45039663SJohn Forte */ 21*45039663SJohn Forte /* 22*45039663SJohn Forte * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 23*45039663SJohn Forte * Use is subject to license terms. 24*45039663SJohn Forte */ 25*45039663SJohn Forte 26*45039663SJohn Forte #include <stdlib.h> 27*45039663SJohn Forte #include <stdio.h> 28*45039663SJohn Forte #include <strings.h> 29*45039663SJohn Forte #include <sys/types.h> 30*45039663SJohn Forte #include <unistd.h> 31*45039663SJohn Forte #include <wchar.h> 32*45039663SJohn Forte #include <libintl.h> 33*45039663SJohn Forte #include <errno.h> 34*45039663SJohn Forte #include <time.h> 35*45039663SJohn Forte #include <string.h> 36*45039663SJohn Forte #include <assert.h> 37*45039663SJohn Forte #include <getopt.h> 38*45039663SJohn Forte #include <cmdparse.h> 39*45039663SJohn Forte #include <libstmf.h> 40*45039663SJohn Forte #include <signal.h> 41*45039663SJohn Forte #include <pthread.h> 42*45039663SJohn Forte #include <locale.h> 43*45039663SJohn Forte 44*45039663SJohn Forte static char *getExecBasename(char *); 45*45039663SJohn Forte static int setLuStandbyFunc(int, char **, cmdOptions_t *, void *); 46*45039663SJohn Forte static int disableAluaFunc(int, char **, cmdOptions_t *, void *); 47*45039663SJohn Forte static int enableAluaFunc(int, char **, cmdOptions_t *, void *); 48*45039663SJohn Forte 49*45039663SJohn Forte #define OPERANDSTRING_LU "LU-name" 50*45039663SJohn Forte #define OPERANDSTRING_NODE_ID "node ID (0 or 1)" 51*45039663SJohn Forte 52*45039663SJohn Forte #define VERSION_STRING_MAJOR "1" 53*45039663SJohn Forte #define VERSION_STRING_MINOR "0" 54*45039663SJohn Forte #define VERSION_STRING_MAX_LEN 10 55*45039663SJohn Forte 56*45039663SJohn Forte #define GUID_INPUT 32 57*45039663SJohn Forte 58*45039663SJohn Forte /* tables set up based on cmdparse instructions */ 59*45039663SJohn Forte 60*45039663SJohn Forte /* add new options here */ 61*45039663SJohn Forte optionTbl_t longOptions[] = { 62*45039663SJohn Forte {NULL, 0, 0, 0} 63*45039663SJohn Forte }; 64*45039663SJohn Forte 65*45039663SJohn Forte /* 66*45039663SJohn Forte * Add new subcommands here 67*45039663SJohn Forte */ 68*45039663SJohn Forte subCommandProps_t subcommands[] = { 69*45039663SJohn Forte {"standby", setLuStandbyFunc, NULL, NULL, NULL, 70*45039663SJohn Forte OPERAND_MANDATORY_SINGLE, OPERANDSTRING_LU, NULL}, 71*45039663SJohn Forte {"disable", disableAluaFunc, NULL, NULL, NULL, 72*45039663SJohn Forte OPERAND_NONE, NULL, NULL}, 73*45039663SJohn Forte {"enable", enableAluaFunc, NULL, NULL, NULL, 74*45039663SJohn Forte OPERAND_MANDATORY_SINGLE, OPERANDSTRING_NODE_ID, NULL}, 75*45039663SJohn Forte {NULL, 0, NULL, NULL, 0, NULL, 0, NULL, NULL} 76*45039663SJohn Forte }; 77*45039663SJohn Forte 78*45039663SJohn Forte /* globals */ 79*45039663SJohn Forte char *cmdName; 80*45039663SJohn Forte 81*45039663SJohn Forte /* 82*45039663SJohn Forte * setLuStandbyFunc 83*45039663SJohn Forte * 84*45039663SJohn Forte * Purpose: set lu to standby 85*45039663SJohn Forte * 86*45039663SJohn Forte */ 87*45039663SJohn Forte /*ARGSUSED*/ 88*45039663SJohn Forte static int 89*45039663SJohn Forte setLuStandbyFunc(int operandLen, char *operands[], cmdOptions_t *options, 90*45039663SJohn Forte void *args) 91*45039663SJohn Forte { 92*45039663SJohn Forte char sGuid[GUID_INPUT + 1]; 93*45039663SJohn Forte stmfGuid inGuid; 94*45039663SJohn Forte unsigned int guid[sizeof (stmfGuid)]; 95*45039663SJohn Forte int i; 96*45039663SJohn Forte int ret = 0; 97*45039663SJohn Forte 98*45039663SJohn Forte if (strlen(operands[0]) != GUID_INPUT) { 99*45039663SJohn Forte (void) fprintf(stderr, "%s: %s: %s %d %s\n", cmdName, 100*45039663SJohn Forte operands[0], gettext("must be"), GUID_INPUT, 101*45039663SJohn Forte gettext("hexadecimal digits long")); 102*45039663SJohn Forte return (1); 103*45039663SJohn Forte } 104*45039663SJohn Forte 105*45039663SJohn Forte bcopy(operands[0], sGuid, GUID_INPUT); 106*45039663SJohn Forte 107*45039663SJohn Forte for (i = 0; i < GUID_INPUT; i++) 108*45039663SJohn Forte sGuid[i] = tolower(sGuid[i]); 109*45039663SJohn Forte sGuid[i] = 0; 110*45039663SJohn Forte 111*45039663SJohn Forte (void) sscanf(sGuid, "%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x", 112*45039663SJohn Forte &guid[0], &guid[1], &guid[2], &guid[3], &guid[4], &guid[5], 113*45039663SJohn Forte &guid[6], &guid[7], &guid[8], &guid[9], &guid[10], &guid[11], 114*45039663SJohn Forte &guid[12], &guid[13], &guid[14], &guid[15]); 115*45039663SJohn Forte 116*45039663SJohn Forte for (i = 0; i < sizeof (stmfGuid); i++) { 117*45039663SJohn Forte inGuid.guid[i] = guid[i]; 118*45039663SJohn Forte } 119*45039663SJohn Forte 120*45039663SJohn Forte ret = stmfLuStandby(&inGuid); 121*45039663SJohn Forte if (ret != STMF_STATUS_SUCCESS) { 122*45039663SJohn Forte switch (ret) { 123*45039663SJohn Forte case STMF_ERROR_PERM: 124*45039663SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 125*45039663SJohn Forte gettext("permission denied")); 126*45039663SJohn Forte break; 127*45039663SJohn Forte case STMF_ERROR_SERVICE_NOT_FOUND: 128*45039663SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 129*45039663SJohn Forte gettext("STMF service not found")); 130*45039663SJohn Forte break; 131*45039663SJohn Forte case STMF_ERROR_NOT_FOUND: 132*45039663SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 133*45039663SJohn Forte operands[0], gettext("not found")); 134*45039663SJohn Forte break; 135*45039663SJohn Forte case STMF_ERROR_SERVICE_DATA_VERSION: 136*45039663SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 137*45039663SJohn Forte gettext("STMF service version incorrect")); 138*45039663SJohn Forte break; 139*45039663SJohn Forte default: 140*45039663SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 141*45039663SJohn Forte gettext("unknown error")); 142*45039663SJohn Forte break; 143*45039663SJohn Forte } 144*45039663SJohn Forte } 145*45039663SJohn Forte return (ret); 146*45039663SJohn Forte } 147*45039663SJohn Forte 148*45039663SJohn Forte /* 149*45039663SJohn Forte * disableAluaFunc 150*45039663SJohn Forte * 151*45039663SJohn Forte * Purpose: disable alua mode 152*45039663SJohn Forte * 153*45039663SJohn Forte */ 154*45039663SJohn Forte /*ARGSUSED*/ 155*45039663SJohn Forte static int 156*45039663SJohn Forte disableAluaFunc(int operandLen, char *operands[], cmdOptions_t *options, 157*45039663SJohn Forte void *args) 158*45039663SJohn Forte { 159*45039663SJohn Forte return (stmfSetAluaState(B_FALSE, 0)); 160*45039663SJohn Forte } 161*45039663SJohn Forte 162*45039663SJohn Forte /* 163*45039663SJohn Forte * enableAluaFunc 164*45039663SJohn Forte * 165*45039663SJohn Forte * Purpose: enable alua mode 166*45039663SJohn Forte * 167*45039663SJohn Forte */ 168*45039663SJohn Forte /*ARGSUSED*/ 169*45039663SJohn Forte static int 170*45039663SJohn Forte enableAluaFunc(int operandLen, char *operands[], cmdOptions_t *options, 171*45039663SJohn Forte void *args) 172*45039663SJohn Forte { 173*45039663SJohn Forte uint8_t node_id = 0; 174*45039663SJohn Forte if (operands[0][1] == '1') { 175*45039663SJohn Forte node_id = 1; 176*45039663SJohn Forte } 177*45039663SJohn Forte return (stmfSetAluaState(B_TRUE, node_id)); 178*45039663SJohn Forte } 179*45039663SJohn Forte 180*45039663SJohn Forte 181*45039663SJohn Forte /* 182*45039663SJohn Forte * input: 183*45039663SJohn Forte * execFullName - exec name of program (argv[0]) 184*45039663SJohn Forte * 185*45039663SJohn Forte * copied from usr/src/cmd/zoneadm/zoneadm.c in OS/Net 186*45039663SJohn Forte * (changed name to lowerCamelCase to keep consistent with this file) 187*45039663SJohn Forte * 188*45039663SJohn Forte * Returns: 189*45039663SJohn Forte * command name portion of execFullName 190*45039663SJohn Forte */ 191*45039663SJohn Forte static char * 192*45039663SJohn Forte getExecBasename(char *execFullname) 193*45039663SJohn Forte { 194*45039663SJohn Forte char *lastSlash, *execBasename; 195*45039663SJohn Forte 196*45039663SJohn Forte /* guard against '/' at end of command invocation */ 197*45039663SJohn Forte for (;;) { 198*45039663SJohn Forte lastSlash = strrchr(execFullname, '/'); 199*45039663SJohn Forte if (lastSlash == NULL) { 200*45039663SJohn Forte execBasename = execFullname; 201*45039663SJohn Forte break; 202*45039663SJohn Forte } else { 203*45039663SJohn Forte execBasename = lastSlash + 1; 204*45039663SJohn Forte if (*execBasename == '\0') { 205*45039663SJohn Forte *lastSlash = '\0'; 206*45039663SJohn Forte continue; 207*45039663SJohn Forte } 208*45039663SJohn Forte break; 209*45039663SJohn Forte } 210*45039663SJohn Forte } 211*45039663SJohn Forte return (execBasename); 212*45039663SJohn Forte } 213*45039663SJohn Forte 214*45039663SJohn Forte int 215*45039663SJohn Forte main(int argc, char *argv[]) 216*45039663SJohn Forte { 217*45039663SJohn Forte synTables_t synTables; 218*45039663SJohn Forte char versionString[VERSION_STRING_MAX_LEN]; 219*45039663SJohn Forte int ret; 220*45039663SJohn Forte int funcRet; 221*45039663SJohn Forte void *subcommandArgs = NULL; 222*45039663SJohn Forte 223*45039663SJohn Forte (void) setlocale(LC_ALL, ""); 224*45039663SJohn Forte (void) textdomain(TEXT_DOMAIN); 225*45039663SJohn Forte /* set global command name */ 226*45039663SJohn Forte cmdName = getExecBasename(argv[0]); 227*45039663SJohn Forte 228*45039663SJohn Forte (void) snprintf(versionString, VERSION_STRING_MAX_LEN, "%s.%s", 229*45039663SJohn Forte VERSION_STRING_MAJOR, VERSION_STRING_MINOR); 230*45039663SJohn Forte synTables.versionString = versionString; 231*45039663SJohn Forte synTables.longOptionTbl = &longOptions[0]; 232*45039663SJohn Forte synTables.subCommandPropsTbl = &subcommands[0]; 233*45039663SJohn Forte 234*45039663SJohn Forte ret = cmdParse(argc, argv, synTables, subcommandArgs, &funcRet); 235*45039663SJohn Forte if (ret != 0) { 236*45039663SJohn Forte return (ret); 237*45039663SJohn Forte } 238*45039663SJohn Forte 239*45039663SJohn Forte return (funcRet); 240*45039663SJohn Forte } /* end main */ 241