1*fcf3ce44SJohn Forte /* 2*fcf3ce44SJohn Forte * CDDL HEADER START 3*fcf3ce44SJohn Forte * 4*fcf3ce44SJohn Forte * The contents of this file are subject to the terms of the 5*fcf3ce44SJohn Forte * Common Development and Distribution License (the "License"). 6*fcf3ce44SJohn Forte * You may not use this file except in compliance with the License. 7*fcf3ce44SJohn Forte * 8*fcf3ce44SJohn Forte * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9*fcf3ce44SJohn Forte * or http://www.opensolaris.org/os/licensing. 10*fcf3ce44SJohn Forte * See the License for the specific language governing permissions 11*fcf3ce44SJohn Forte * and limitations under the License. 12*fcf3ce44SJohn Forte * 13*fcf3ce44SJohn Forte * When distributing Covered Code, include this CDDL HEADER in each 14*fcf3ce44SJohn Forte * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15*fcf3ce44SJohn Forte * If applicable, add the following below this CDDL HEADER, with the 16*fcf3ce44SJohn Forte * fields enclosed by brackets "[]" replaced with your own identifying 17*fcf3ce44SJohn Forte * information: Portions Copyright [yyyy] [name of copyright owner] 18*fcf3ce44SJohn Forte * 19*fcf3ce44SJohn Forte * CDDL HEADER END 20*fcf3ce44SJohn Forte */ 21*fcf3ce44SJohn Forte /* 22*fcf3ce44SJohn Forte * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 23*fcf3ce44SJohn Forte * Use is subject to license terms. 24*fcf3ce44SJohn Forte */ 25*fcf3ce44SJohn Forte 26*fcf3ce44SJohn Forte #include <stdlib.h> 27*fcf3ce44SJohn Forte #include <stdio.h> 28*fcf3ce44SJohn Forte #include <strings.h> 29*fcf3ce44SJohn Forte #include <sys/types.h> 30*fcf3ce44SJohn Forte #include <unistd.h> 31*fcf3ce44SJohn Forte #include <wchar.h> 32*fcf3ce44SJohn Forte #include <libintl.h> 33*fcf3ce44SJohn Forte #include <errno.h> 34*fcf3ce44SJohn Forte #include <time.h> 35*fcf3ce44SJohn Forte #include <string.h> 36*fcf3ce44SJohn Forte #include <assert.h> 37*fcf3ce44SJohn Forte #include <getopt.h> 38*fcf3ce44SJohn Forte #include <cmdparse.h> 39*fcf3ce44SJohn Forte #include <stmfadm.h> 40*fcf3ce44SJohn Forte #include <libstmf.h> 41*fcf3ce44SJohn Forte #include <signal.h> 42*fcf3ce44SJohn Forte #include <pthread.h> 43*fcf3ce44SJohn Forte #include <locale.h> 44*fcf3ce44SJohn Forte 45*fcf3ce44SJohn Forte static int addHostGroupMemberFunc(int, char **, cmdOptions_t *, void *); 46*fcf3ce44SJohn Forte static int addTargetGroupMemberFunc(int, char **, cmdOptions_t *, void *); 47*fcf3ce44SJohn Forte static int addViewFunc(int, char **, cmdOptions_t *, void *); 48*fcf3ce44SJohn Forte static int createHostGroupFunc(int, char **, cmdOptions_t *, void *); 49*fcf3ce44SJohn Forte static int createTargetGroupFunc(int, char **, cmdOptions_t *, void *); 50*fcf3ce44SJohn Forte static int deleteHostGroupFunc(int, char **, cmdOptions_t *, void *); 51*fcf3ce44SJohn Forte static int deleteTargetGroupFunc(int, char **, cmdOptions_t *, void *); 52*fcf3ce44SJohn Forte static int listLuFunc(int, char **, cmdOptions_t *, void *); 53*fcf3ce44SJohn Forte static int listTargetFunc(int, char **, cmdOptions_t *, void *); 54*fcf3ce44SJohn Forte static int listViewFunc(int, char **, cmdOptions_t *, void *); 55*fcf3ce44SJohn Forte static int listHostGroupFunc(int, char **, cmdOptions_t *, void *); 56*fcf3ce44SJohn Forte static int listStateFunc(int, char **, cmdOptions_t *, void *); 57*fcf3ce44SJohn Forte static int listTargetGroupFunc(int, char **, cmdOptions_t *, void *); 58*fcf3ce44SJohn Forte static int offlineTargetFunc(int, char **, cmdOptions_t *, void *); 59*fcf3ce44SJohn Forte static int offlineLuFunc(int, char **, cmdOptions_t *, void *); 60*fcf3ce44SJohn Forte static int onlineTargetFunc(int, char **, cmdOptions_t *, void *); 61*fcf3ce44SJohn Forte static int onlineLuFunc(int, char **, cmdOptions_t *, void *); 62*fcf3ce44SJohn Forte static int onlineOfflineTarget(char *, int); 63*fcf3ce44SJohn Forte static int onlineOfflineLu(char *, int); 64*fcf3ce44SJohn Forte static int removeHostGroupMemberFunc(int, char **, cmdOptions_t *, void *); 65*fcf3ce44SJohn Forte static int removeTargetGroupMemberFunc(int, char **, cmdOptions_t *, void *); 66*fcf3ce44SJohn Forte static int removeViewFunc(int, char **, cmdOptions_t *, void *); 67*fcf3ce44SJohn Forte static char *getExecBasename(char *); 68*fcf3ce44SJohn Forte static int parseDevid(char *input, stmfDevid *devid); 69*fcf3ce44SJohn Forte static void printGroupProps(stmfGroupProperties *groupProps); 70*fcf3ce44SJohn Forte static int checkScsiNameString(wchar_t *, stmfDevid *); 71*fcf3ce44SJohn Forte static int checkHexUpper(char *); 72*fcf3ce44SJohn Forte static int checkIscsiName(wchar_t *); 73*fcf3ce44SJohn Forte static void printLuProps(stmfLogicalUnitProperties *luProps); 74*fcf3ce44SJohn Forte static void printGuid(stmfGuid *guid, FILE *printWhere); 75*fcf3ce44SJohn Forte static void printTargetProps(stmfTargetProperties *); 76*fcf3ce44SJohn Forte static void printSessionProps(stmfSessionList *); 77*fcf3ce44SJohn Forte 78*fcf3ce44SJohn Forte 79*fcf3ce44SJohn Forte 80*fcf3ce44SJohn Forte /* 81*fcf3ce44SJohn Forte * MAJOR - This should only change when there is an incompatible change made 82*fcf3ce44SJohn Forte * to the interfaces or the output. 83*fcf3ce44SJohn Forte * 84*fcf3ce44SJohn Forte * MINOR - This should change whenever there is a new command or new feature 85*fcf3ce44SJohn Forte * with no incompatible change. 86*fcf3ce44SJohn Forte */ 87*fcf3ce44SJohn Forte #define VERSION_STRING_MAJOR "1" 88*fcf3ce44SJohn Forte #define VERSION_STRING_MINOR "0" 89*fcf3ce44SJohn Forte #define MAX_DEVID_INPUT 256 90*fcf3ce44SJohn Forte #define GUID_INPUT 32 91*fcf3ce44SJohn Forte #define MAX_LU_NBR 16383 92*fcf3ce44SJohn Forte #define ONLINE_LU 0 93*fcf3ce44SJohn Forte #define OFFLINE_LU 1 94*fcf3ce44SJohn Forte #define ONLINE_TARGET 2 95*fcf3ce44SJohn Forte #define OFFLINE_TARGET 3 96*fcf3ce44SJohn Forte #define PROPS_FORMAT " %-18s: " 97*fcf3ce44SJohn Forte #define VIEW_FORMAT " %-13s: " 98*fcf3ce44SJohn Forte #define LVL3_FORMAT " %s" 99*fcf3ce44SJohn Forte #define LVL4_FORMAT " %s" 100*fcf3ce44SJohn Forte 101*fcf3ce44SJohn Forte /* SCSI Name String length definitions */ 102*fcf3ce44SJohn Forte #define SNS_EUI_16 16 103*fcf3ce44SJohn Forte #define SNS_EUI_24 24 104*fcf3ce44SJohn Forte #define SNS_EUI_32 32 105*fcf3ce44SJohn Forte #define SNS_NAA_16 16 106*fcf3ce44SJohn Forte #define SNS_NAA_32 32 107*fcf3ce44SJohn Forte #define SNS_WWN_16 16 108*fcf3ce44SJohn Forte #define SNS_IQN_223 223 109*fcf3ce44SJohn Forte 110*fcf3ce44SJohn Forte /* tables set up based on cmdparse instructions */ 111*fcf3ce44SJohn Forte 112*fcf3ce44SJohn Forte /* add new options here */ 113*fcf3ce44SJohn Forte optionTbl_t longOptions[] = { 114*fcf3ce44SJohn Forte {"all", no_arg, 'a', NULL}, 115*fcf3ce44SJohn Forte {"group-name", required_arg, 'g', "group-name"}, 116*fcf3ce44SJohn Forte {"secure-data", no_arg, 's', NULL}, 117*fcf3ce44SJohn Forte {"lu-name", required_arg, 'l', "LU-Name"}, 118*fcf3ce44SJohn Forte {"lun", required_arg, 'n', "logical-unit-number"}, 119*fcf3ce44SJohn Forte {"verbose", no_arg, 'v', NULL}, 120*fcf3ce44SJohn Forte {"target-group", required_arg, 't', "group-name"}, 121*fcf3ce44SJohn Forte {"host-group", required_arg, 'h', "group-name"}, 122*fcf3ce44SJohn Forte {"size", required_arg, 's', "size (k/M/G)"}, 123*fcf3ce44SJohn Forte {"force", no_arg, 'r', NULL}, 124*fcf3ce44SJohn Forte {"new", no_arg, 'n', NULL}, 125*fcf3ce44SJohn Forte {NULL, 0, 0, 0} 126*fcf3ce44SJohn Forte }; 127*fcf3ce44SJohn Forte 128*fcf3ce44SJohn Forte /* 129*fcf3ce44SJohn Forte * Add new subcommands here 130*fcf3ce44SJohn Forte */ 131*fcf3ce44SJohn Forte subCommandProps_t subcommands[] = { 132*fcf3ce44SJohn Forte {"add-hg-member", addHostGroupMemberFunc, "g", "g", NULL, 133*fcf3ce44SJohn Forte OPERAND_MANDATORY_MULTIPLE, OPERANDSTRING_GROUP_MEMBER}, 134*fcf3ce44SJohn Forte {"add-tg-member", addTargetGroupMemberFunc, "g", "g", NULL, 135*fcf3ce44SJohn Forte OPERAND_MANDATORY_MULTIPLE, OPERANDSTRING_GROUP_MEMBER}, 136*fcf3ce44SJohn Forte {"add-view", addViewFunc, "nth", NULL, NULL, 137*fcf3ce44SJohn Forte OPERAND_MANDATORY_SINGLE, OPERANDSTRING_LU}, 138*fcf3ce44SJohn Forte {"create-hg", createHostGroupFunc, NULL, NULL, NULL, 139*fcf3ce44SJohn Forte OPERAND_MANDATORY_SINGLE, OPERANDSTRING_GROUP_NAME}, 140*fcf3ce44SJohn Forte {"create-tg", createTargetGroupFunc, NULL, NULL, NULL, 141*fcf3ce44SJohn Forte OPERAND_MANDATORY_SINGLE, OPERANDSTRING_GROUP_NAME}, 142*fcf3ce44SJohn Forte {"delete-hg", deleteHostGroupFunc, NULL, NULL, NULL, 143*fcf3ce44SJohn Forte OPERAND_MANDATORY_SINGLE, OPERANDSTRING_GROUP_NAME}, 144*fcf3ce44SJohn Forte {"delete-tg", deleteTargetGroupFunc, NULL, NULL, NULL, 145*fcf3ce44SJohn Forte OPERAND_MANDATORY_SINGLE, OPERANDSTRING_GROUP_NAME}, 146*fcf3ce44SJohn Forte {"list-hg", listHostGroupFunc, "v", NULL, NULL, 147*fcf3ce44SJohn Forte OPERAND_OPTIONAL_MULTIPLE, OPERANDSTRING_GROUP_NAME}, 148*fcf3ce44SJohn Forte {"list-lu", listLuFunc, "v", NULL, NULL, OPERAND_OPTIONAL_MULTIPLE, 149*fcf3ce44SJohn Forte OPERANDSTRING_LU}, 150*fcf3ce44SJohn Forte {"list-state", listStateFunc, NULL, NULL, NULL, OPERAND_NONE, NULL}, 151*fcf3ce44SJohn Forte {"list-target", listTargetFunc, "v", NULL, NULL, 152*fcf3ce44SJohn Forte OPERAND_OPTIONAL_MULTIPLE, OPERANDSTRING_TARGET}, 153*fcf3ce44SJohn Forte {"list-tg", listTargetGroupFunc, "v", NULL, NULL, 154*fcf3ce44SJohn Forte OPERAND_OPTIONAL_MULTIPLE, OPERANDSTRING_GROUP_NAME}, 155*fcf3ce44SJohn Forte {"list-view", listViewFunc, "l", "l", NULL, 156*fcf3ce44SJohn Forte OPERAND_OPTIONAL_MULTIPLE, OPERANDSTRING_VIEW_ENTRY}, 157*fcf3ce44SJohn Forte {"online-lu", onlineLuFunc, NULL, NULL, NULL, 158*fcf3ce44SJohn Forte OPERAND_MANDATORY_SINGLE, OPERANDSTRING_LU}, 159*fcf3ce44SJohn Forte {"offline-lu", offlineLuFunc, NULL, NULL, NULL, 160*fcf3ce44SJohn Forte OPERAND_MANDATORY_SINGLE, OPERANDSTRING_LU}, 161*fcf3ce44SJohn Forte {"online-target", onlineTargetFunc, NULL, NULL, NULL, 162*fcf3ce44SJohn Forte OPERAND_MANDATORY_SINGLE, OPERANDSTRING_TARGET}, 163*fcf3ce44SJohn Forte {"offline-target", offlineTargetFunc, NULL, NULL, NULL, 164*fcf3ce44SJohn Forte OPERAND_MANDATORY_SINGLE, OPERANDSTRING_TARGET}, 165*fcf3ce44SJohn Forte {"remove-hg-member", removeHostGroupMemberFunc, "g", "g", NULL, 166*fcf3ce44SJohn Forte OPERAND_MANDATORY_MULTIPLE, OPERANDSTRING_GROUP_MEMBER}, 167*fcf3ce44SJohn Forte {"remove-tg-member", removeTargetGroupMemberFunc, "g", "g", NULL, 168*fcf3ce44SJohn Forte OPERAND_MANDATORY_MULTIPLE, OPERANDSTRING_GROUP_MEMBER}, 169*fcf3ce44SJohn Forte {"remove-view", removeViewFunc, "la", "l", NULL, 170*fcf3ce44SJohn Forte OPERAND_OPTIONAL_MULTIPLE, OPERANDSTRING_VIEW_ENTRY}, 171*fcf3ce44SJohn Forte {NULL, 0, NULL, NULL, 0, NULL, 0, NULL} 172*fcf3ce44SJohn Forte }; 173*fcf3ce44SJohn Forte 174*fcf3ce44SJohn Forte /* globals */ 175*fcf3ce44SJohn Forte char *cmdName; 176*fcf3ce44SJohn Forte 177*fcf3ce44SJohn Forte /* 178*fcf3ce44SJohn Forte * addHostGroupMemberFunc 179*fcf3ce44SJohn Forte * 180*fcf3ce44SJohn Forte * Add members to a host group 181*fcf3ce44SJohn Forte * 182*fcf3ce44SJohn Forte */ 183*fcf3ce44SJohn Forte /*ARGSUSED*/ 184*fcf3ce44SJohn Forte static int 185*fcf3ce44SJohn Forte addHostGroupMemberFunc(int operandLen, char *operands[], cmdOptions_t *options, 186*fcf3ce44SJohn Forte void *args) 187*fcf3ce44SJohn Forte { 188*fcf3ce44SJohn Forte int i; 189*fcf3ce44SJohn Forte int ret = 0; 190*fcf3ce44SJohn Forte int stmfRet; 191*fcf3ce44SJohn Forte stmfGroupName groupName; 192*fcf3ce44SJohn Forte wchar_t groupNamePrint[sizeof (stmfGroupName)]; 193*fcf3ce44SJohn Forte stmfDevid devid; 194*fcf3ce44SJohn Forte 195*fcf3ce44SJohn Forte for (; options->optval; options++) { 196*fcf3ce44SJohn Forte switch (options->optval) { 197*fcf3ce44SJohn Forte /* host group name */ 198*fcf3ce44SJohn Forte case 'g': 199*fcf3ce44SJohn Forte (void) mbstowcs(groupNamePrint, options->optarg, 200*fcf3ce44SJohn Forte sizeof (groupNamePrint)); 201*fcf3ce44SJohn Forte bzero(groupName, sizeof (groupName)); 202*fcf3ce44SJohn Forte bcopy(options->optarg, groupName, 203*fcf3ce44SJohn Forte strlen(options->optarg)); 204*fcf3ce44SJohn Forte break; 205*fcf3ce44SJohn Forte default: 206*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %c: %s\n", 207*fcf3ce44SJohn Forte cmdName, options->optval, 208*fcf3ce44SJohn Forte gettext("unknown option")); 209*fcf3ce44SJohn Forte return (1); 210*fcf3ce44SJohn Forte } 211*fcf3ce44SJohn Forte } 212*fcf3ce44SJohn Forte 213*fcf3ce44SJohn Forte for (i = 0; i < operandLen; i++) { 214*fcf3ce44SJohn Forte if (parseDevid(operands[i], &devid) != 0) { 215*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", 216*fcf3ce44SJohn Forte cmdName, operands[i], 217*fcf3ce44SJohn Forte gettext("unrecognized device id")); 218*fcf3ce44SJohn Forte ret++; 219*fcf3ce44SJohn Forte continue; 220*fcf3ce44SJohn Forte } 221*fcf3ce44SJohn Forte stmfRet = stmfAddToHostGroup(&groupName, &devid); 222*fcf3ce44SJohn Forte switch (stmfRet) { 223*fcf3ce44SJohn Forte case STMF_STATUS_SUCCESS: 224*fcf3ce44SJohn Forte break; 225*fcf3ce44SJohn Forte case STMF_ERROR_EXISTS: 226*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 227*fcf3ce44SJohn Forte operands[i], gettext("already exists")); 228*fcf3ce44SJohn Forte ret++; 229*fcf3ce44SJohn Forte break; 230*fcf3ce44SJohn Forte case STMF_ERROR_GROUP_NOT_FOUND: 231*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %ws: %s\n", cmdName, 232*fcf3ce44SJohn Forte groupNamePrint, gettext("not found")); 233*fcf3ce44SJohn Forte ret++; 234*fcf3ce44SJohn Forte break; 235*fcf3ce44SJohn Forte case STMF_ERROR_PERM: 236*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 237*fcf3ce44SJohn Forte gettext("permission denied")); 238*fcf3ce44SJohn Forte break; 239*fcf3ce44SJohn Forte case STMF_ERROR_BUSY: 240*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 241*fcf3ce44SJohn Forte operands[i], gettext("resource busy")); 242*fcf3ce44SJohn Forte ret++; 243*fcf3ce44SJohn Forte break; 244*fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_NOT_FOUND: 245*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 246*fcf3ce44SJohn Forte gettext("STMF service not found")); 247*fcf3ce44SJohn Forte ret++; 248*fcf3ce44SJohn Forte break; 249*fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_DATA_VERSION: 250*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 251*fcf3ce44SJohn Forte gettext("STMF service version incorrect")); 252*fcf3ce44SJohn Forte ret++; 253*fcf3ce44SJohn Forte break; 254*fcf3ce44SJohn Forte default: 255*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 256*fcf3ce44SJohn Forte operands[i], gettext("unknown error")); 257*fcf3ce44SJohn Forte ret++; 258*fcf3ce44SJohn Forte break; 259*fcf3ce44SJohn Forte } 260*fcf3ce44SJohn Forte } 261*fcf3ce44SJohn Forte 262*fcf3ce44SJohn Forte return (ret); 263*fcf3ce44SJohn Forte } 264*fcf3ce44SJohn Forte 265*fcf3ce44SJohn Forte /* 266*fcf3ce44SJohn Forte * addTargetGroupMemberFunc 267*fcf3ce44SJohn Forte * 268*fcf3ce44SJohn Forte * Add members to a target group 269*fcf3ce44SJohn Forte * 270*fcf3ce44SJohn Forte */ 271*fcf3ce44SJohn Forte /*ARGSUSED*/ 272*fcf3ce44SJohn Forte static int 273*fcf3ce44SJohn Forte addTargetGroupMemberFunc(int operandLen, char *operands[], 274*fcf3ce44SJohn Forte cmdOptions_t *options, void *args) 275*fcf3ce44SJohn Forte { 276*fcf3ce44SJohn Forte int i; 277*fcf3ce44SJohn Forte int ret = 0; 278*fcf3ce44SJohn Forte int stmfRet; 279*fcf3ce44SJohn Forte stmfGroupName groupName; 280*fcf3ce44SJohn Forte wchar_t groupNamePrint[sizeof (stmfGroupName)]; 281*fcf3ce44SJohn Forte stmfDevid devid; 282*fcf3ce44SJohn Forte 283*fcf3ce44SJohn Forte for (; options->optval; options++) { 284*fcf3ce44SJohn Forte switch (options->optval) { 285*fcf3ce44SJohn Forte /* target group name */ 286*fcf3ce44SJohn Forte case 'g': 287*fcf3ce44SJohn Forte (void) mbstowcs(groupNamePrint, options->optarg, 288*fcf3ce44SJohn Forte sizeof (groupNamePrint)); 289*fcf3ce44SJohn Forte bzero(groupName, sizeof (groupName)); 290*fcf3ce44SJohn Forte bcopy(options->optarg, groupName, 291*fcf3ce44SJohn Forte strlen(options->optarg)); 292*fcf3ce44SJohn Forte break; 293*fcf3ce44SJohn Forte default: 294*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %c: %s\n", 295*fcf3ce44SJohn Forte cmdName, options->optval, 296*fcf3ce44SJohn Forte gettext("unknown option")); 297*fcf3ce44SJohn Forte return (1); 298*fcf3ce44SJohn Forte } 299*fcf3ce44SJohn Forte } 300*fcf3ce44SJohn Forte 301*fcf3ce44SJohn Forte for (i = 0; i < operandLen; i++) { 302*fcf3ce44SJohn Forte if (parseDevid(operands[i], &devid) != 0) { 303*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", 304*fcf3ce44SJohn Forte cmdName, operands[i], 305*fcf3ce44SJohn Forte gettext("unrecognized device id")); 306*fcf3ce44SJohn Forte ret++; 307*fcf3ce44SJohn Forte continue; 308*fcf3ce44SJohn Forte } 309*fcf3ce44SJohn Forte stmfRet = stmfAddToTargetGroup(&groupName, &devid); 310*fcf3ce44SJohn Forte switch (stmfRet) { 311*fcf3ce44SJohn Forte case STMF_STATUS_SUCCESS: 312*fcf3ce44SJohn Forte break; 313*fcf3ce44SJohn Forte case STMF_ERROR_EXISTS: 314*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 315*fcf3ce44SJohn Forte operands[i], gettext("already exists")); 316*fcf3ce44SJohn Forte ret++; 317*fcf3ce44SJohn Forte break; 318*fcf3ce44SJohn Forte case STMF_ERROR_GROUP_NOT_FOUND: 319*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %ws: %s\n", cmdName, 320*fcf3ce44SJohn Forte groupNamePrint, gettext("not found")); 321*fcf3ce44SJohn Forte ret++; 322*fcf3ce44SJohn Forte break; 323*fcf3ce44SJohn Forte case STMF_ERROR_PERM: 324*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 325*fcf3ce44SJohn Forte gettext("permission denied")); 326*fcf3ce44SJohn Forte break; 327*fcf3ce44SJohn Forte case STMF_ERROR_BUSY: 328*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 329*fcf3ce44SJohn Forte operands[i], gettext("resource busy")); 330*fcf3ce44SJohn Forte ret++; 331*fcf3ce44SJohn Forte break; 332*fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_NOT_FOUND: 333*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 334*fcf3ce44SJohn Forte gettext("STMF service not found")); 335*fcf3ce44SJohn Forte ret++; 336*fcf3ce44SJohn Forte break; 337*fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_ONLINE: 338*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 339*fcf3ce44SJohn Forte gettext("STMF service must be offline")); 340*fcf3ce44SJohn Forte ret++; 341*fcf3ce44SJohn Forte break; 342*fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_DATA_VERSION: 343*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 344*fcf3ce44SJohn Forte gettext("STMF service version incorrect")); 345*fcf3ce44SJohn Forte ret++; 346*fcf3ce44SJohn Forte break; 347*fcf3ce44SJohn Forte default: 348*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 349*fcf3ce44SJohn Forte operands[i], gettext("unknown error")); 350*fcf3ce44SJohn Forte ret++; 351*fcf3ce44SJohn Forte break; 352*fcf3ce44SJohn Forte } 353*fcf3ce44SJohn Forte } 354*fcf3ce44SJohn Forte 355*fcf3ce44SJohn Forte return (ret); 356*fcf3ce44SJohn Forte } 357*fcf3ce44SJohn Forte 358*fcf3ce44SJohn Forte /* 359*fcf3ce44SJohn Forte * parseDevid 360*fcf3ce44SJohn Forte * 361*fcf3ce44SJohn Forte * Converts char * input to a stmfDevid 362*fcf3ce44SJohn Forte * 363*fcf3ce44SJohn Forte * input - this should be in the following format with either a 364*fcf3ce44SJohn Forte * wwn. iqn. or eui. representation. 365*fcf3ce44SJohn Forte * A name string of the format: 366*fcf3ce44SJohn Forte * wwn.<WWN> (FC/SAS address) 367*fcf3ce44SJohn Forte * iqn.<iSCSI name> (iSCSI iqn) 368*fcf3ce44SJohn Forte * eui.<WWN> (iSCSI eui name) 369*fcf3ce44SJohn Forte * 370*fcf3ce44SJohn Forte * devid - pointer to stmfDevid structure allocated by the caller. 371*fcf3ce44SJohn Forte * 372*fcf3ce44SJohn Forte * Returns: 373*fcf3ce44SJohn Forte * 0 on success 374*fcf3ce44SJohn Forte * non-zero on failure 375*fcf3ce44SJohn Forte */ 376*fcf3ce44SJohn Forte static int 377*fcf3ce44SJohn Forte parseDevid(char *input, stmfDevid *devid) 378*fcf3ce44SJohn Forte { 379*fcf3ce44SJohn Forte wchar_t inputWc[MAX_DEVID_INPUT]; 380*fcf3ce44SJohn Forte 381*fcf3ce44SJohn Forte /* convert to wcs */ 382*fcf3ce44SJohn Forte (void) mbstowcs(inputWc, input, sizeof (inputWc)); 383*fcf3ce44SJohn Forte 384*fcf3ce44SJohn Forte /* 385*fcf3ce44SJohn Forte * Check for known scsi name string formats 386*fcf3ce44SJohn Forte * If one is found, we're done 387*fcf3ce44SJohn Forte * If not, then it's a failure to parse 388*fcf3ce44SJohn Forte */ 389*fcf3ce44SJohn Forte if (checkScsiNameString(inputWc, devid) == 0) { 390*fcf3ce44SJohn Forte return (0); 391*fcf3ce44SJohn Forte } 392*fcf3ce44SJohn Forte 393*fcf3ce44SJohn Forte return (-1); 394*fcf3ce44SJohn Forte } 395*fcf3ce44SJohn Forte 396*fcf3ce44SJohn Forte /* 397*fcf3ce44SJohn Forte * checkScsiNameString 398*fcf3ce44SJohn Forte * 399*fcf3ce44SJohn Forte * Validates known SCSI name string formats and converts to stmfDevid 400*fcf3ce44SJohn Forte * format 401*fcf3ce44SJohn Forte * 402*fcf3ce44SJohn Forte * input - input SCSI name string 403*fcf3ce44SJohn Forte * devid - pointer to stmfDevid structure allocated by the caller 404*fcf3ce44SJohn Forte * on successful return, contains the devid based on input 405*fcf3ce44SJohn Forte * 406*fcf3ce44SJohn Forte * returns: 407*fcf3ce44SJohn Forte * 0 on success 408*fcf3ce44SJohn Forte * -1 on failure 409*fcf3ce44SJohn Forte */ 410*fcf3ce44SJohn Forte static int 411*fcf3ce44SJohn Forte checkScsiNameString(wchar_t *input, stmfDevid *devid) 412*fcf3ce44SJohn Forte { 413*fcf3ce44SJohn Forte char *mbString = NULL; 414*fcf3ce44SJohn Forte int mbStringLen; 415*fcf3ce44SJohn Forte int len; 416*fcf3ce44SJohn Forte int i; 417*fcf3ce44SJohn Forte 418*fcf3ce44SJohn Forte /* 419*fcf3ce44SJohn Forte * Convert to multi-byte string 420*fcf3ce44SJohn Forte * 421*fcf3ce44SJohn Forte * This is used for either eui or naa formats 422*fcf3ce44SJohn Forte */ 423*fcf3ce44SJohn Forte mbString = calloc(1, (mbStringLen = wcstombs(mbString, input, 0)) + 1); 424*fcf3ce44SJohn Forte if (mbString == NULL) { 425*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", 426*fcf3ce44SJohn Forte cmdName, "Insufficient memory\n"); 427*fcf3ce44SJohn Forte return (-1); 428*fcf3ce44SJohn Forte } 429*fcf3ce44SJohn Forte if (wcstombs(mbString, input, mbStringLen) == (size_t)-1) { 430*fcf3ce44SJohn Forte return (-1); 431*fcf3ce44SJohn Forte } 432*fcf3ce44SJohn Forte 433*fcf3ce44SJohn Forte /* 434*fcf3ce44SJohn Forte * check for iqn format 435*fcf3ce44SJohn Forte */ 436*fcf3ce44SJohn Forte if (strncmp(mbString, "iqn.", 4) == 0) { 437*fcf3ce44SJohn Forte if ((len = strlen(mbString)) > (SNS_IQN_223)) { 438*fcf3ce44SJohn Forte return (-1); 439*fcf3ce44SJohn Forte } 440*fcf3ce44SJohn Forte for (i = 0; i < len; i++) { 441*fcf3ce44SJohn Forte mbString[i] = tolower(mbString[i]); 442*fcf3ce44SJohn Forte } 443*fcf3ce44SJohn Forte if (checkIscsiName(input + 4) != 0) { 444*fcf3ce44SJohn Forte return (-1); 445*fcf3ce44SJohn Forte } 446*fcf3ce44SJohn Forte } else if (strncmp(mbString, "wwn.", 4) == 0) { 447*fcf3ce44SJohn Forte if ((len = strlen(mbString + 4)) != SNS_WWN_16) { 448*fcf3ce44SJohn Forte return (-1); 449*fcf3ce44SJohn Forte } else if (checkHexUpper(mbString + 4) != 0) { 450*fcf3ce44SJohn Forte return (-1); 451*fcf3ce44SJohn Forte } 452*fcf3ce44SJohn Forte } else if (strncmp(mbString, "eui.", 4) == 0) { 453*fcf3ce44SJohn Forte if ((len = strlen(mbString + 4)) != SNS_EUI_16) { 454*fcf3ce44SJohn Forte return (-1); 455*fcf3ce44SJohn Forte } else if (checkHexUpper(mbString + 4) != 0) { 456*fcf3ce44SJohn Forte return (-1); 457*fcf3ce44SJohn Forte } 458*fcf3ce44SJohn Forte } else { 459*fcf3ce44SJohn Forte return (-1); 460*fcf3ce44SJohn Forte } 461*fcf3ce44SJohn Forte 462*fcf3ce44SJohn Forte /* 463*fcf3ce44SJohn Forte * We have a validated name string. 464*fcf3ce44SJohn Forte * Go ahead and set the length and copy it. 465*fcf3ce44SJohn Forte */ 466*fcf3ce44SJohn Forte devid->identLength = strlen(mbString); 467*fcf3ce44SJohn Forte bzero(devid->ident, STMF_IDENT_LENGTH); 468*fcf3ce44SJohn Forte bcopy(mbString, devid->ident, devid->identLength); 469*fcf3ce44SJohn Forte 470*fcf3ce44SJohn Forte return (0); 471*fcf3ce44SJohn Forte } 472*fcf3ce44SJohn Forte 473*fcf3ce44SJohn Forte 474*fcf3ce44SJohn Forte /* 475*fcf3ce44SJohn Forte * Checks whether the entire string is in hex and converts to upper 476*fcf3ce44SJohn Forte */ 477*fcf3ce44SJohn Forte static int 478*fcf3ce44SJohn Forte checkHexUpper(char *input) 479*fcf3ce44SJohn Forte { 480*fcf3ce44SJohn Forte int i; 481*fcf3ce44SJohn Forte 482*fcf3ce44SJohn Forte for (i = 0; i < strlen(input); i++) { 483*fcf3ce44SJohn Forte if (isxdigit(input[i])) { 484*fcf3ce44SJohn Forte input[i] = toupper(input[i]); 485*fcf3ce44SJohn Forte continue; 486*fcf3ce44SJohn Forte } 487*fcf3ce44SJohn Forte return (-1); 488*fcf3ce44SJohn Forte } 489*fcf3ce44SJohn Forte 490*fcf3ce44SJohn Forte return (0); 491*fcf3ce44SJohn Forte } 492*fcf3ce44SJohn Forte 493*fcf3ce44SJohn Forte /* 494*fcf3ce44SJohn Forte * checkIscsiName 495*fcf3ce44SJohn Forte * 496*fcf3ce44SJohn Forte * Purpose: Basic string checking on name 497*fcf3ce44SJohn Forte */ 498*fcf3ce44SJohn Forte static int 499*fcf3ce44SJohn Forte checkIscsiName(wchar_t *input) 500*fcf3ce44SJohn Forte { 501*fcf3ce44SJohn Forte int i; 502*fcf3ce44SJohn Forte 503*fcf3ce44SJohn Forte for (i = 0; input[i] != 0; i++) { 504*fcf3ce44SJohn Forte if (!iswalnum(input[i]) && input[i] != '-' && 505*fcf3ce44SJohn Forte input[i] != '.' && input[i] != ':') { 506*fcf3ce44SJohn Forte return (-1); 507*fcf3ce44SJohn Forte } 508*fcf3ce44SJohn Forte } 509*fcf3ce44SJohn Forte 510*fcf3ce44SJohn Forte return (0); 511*fcf3ce44SJohn Forte } 512*fcf3ce44SJohn Forte 513*fcf3ce44SJohn Forte 514*fcf3ce44SJohn Forte /* 515*fcf3ce44SJohn Forte * addViewFunc 516*fcf3ce44SJohn Forte * 517*fcf3ce44SJohn Forte * Adds a view entry to a logical unit 518*fcf3ce44SJohn Forte * 519*fcf3ce44SJohn Forte */ 520*fcf3ce44SJohn Forte /*ARGSUSED*/ 521*fcf3ce44SJohn Forte static int 522*fcf3ce44SJohn Forte addViewFunc(int operandLen, char *operands[], cmdOptions_t *options, 523*fcf3ce44SJohn Forte void *args) 524*fcf3ce44SJohn Forte { 525*fcf3ce44SJohn Forte stmfViewEntry viewEntry; 526*fcf3ce44SJohn Forte stmfGuid inGuid; 527*fcf3ce44SJohn Forte unsigned int guid[sizeof (stmfGuid)]; 528*fcf3ce44SJohn Forte uint16_t inputLuNbr; 529*fcf3ce44SJohn Forte int ret = 0; 530*fcf3ce44SJohn Forte int stmfRet; 531*fcf3ce44SJohn Forte int i; 532*fcf3ce44SJohn Forte char sGuid[GUID_INPUT + 1]; 533*fcf3ce44SJohn Forte 534*fcf3ce44SJohn Forte bzero(&viewEntry, sizeof (viewEntry)); 535*fcf3ce44SJohn Forte /* init view entry structure */ 536*fcf3ce44SJohn Forte viewEntry.allHosts = B_TRUE; 537*fcf3ce44SJohn Forte viewEntry.allTargets = B_TRUE; 538*fcf3ce44SJohn Forte viewEntry.luNbrValid = B_FALSE; 539*fcf3ce44SJohn Forte 540*fcf3ce44SJohn Forte /* check input length */ 541*fcf3ce44SJohn Forte if (strlen(operands[0]) != GUID_INPUT) { 542*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s%d%s\n", cmdName, operands[0], 543*fcf3ce44SJohn Forte gettext("must be "), GUID_INPUT, 544*fcf3ce44SJohn Forte gettext(" hexadecimal digits")); 545*fcf3ce44SJohn Forte return (1); 546*fcf3ce44SJohn Forte } 547*fcf3ce44SJohn Forte 548*fcf3ce44SJohn Forte for (; options->optval; options++) { 549*fcf3ce44SJohn Forte switch (options->optval) { 550*fcf3ce44SJohn Forte /* logical unit number */ 551*fcf3ce44SJohn Forte case 'n': 552*fcf3ce44SJohn Forte viewEntry.luNbrValid = B_TRUE; 553*fcf3ce44SJohn Forte inputLuNbr = atoi(options->optarg); 554*fcf3ce44SJohn Forte if (inputLuNbr > MAX_LU_NBR) { 555*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %d: %s\n", 556*fcf3ce44SJohn Forte cmdName, inputLuNbr, 557*fcf3ce44SJohn Forte gettext("Logical unit number" 558*fcf3ce44SJohn Forte " must be less than 16384")); 559*fcf3ce44SJohn Forte return (1); 560*fcf3ce44SJohn Forte } 561*fcf3ce44SJohn Forte viewEntry.luNbr[0] = inputLuNbr >> 8; 562*fcf3ce44SJohn Forte viewEntry.luNbr[1] = inputLuNbr & 0xff; 563*fcf3ce44SJohn Forte break; 564*fcf3ce44SJohn Forte /* host group */ 565*fcf3ce44SJohn Forte case 'h': 566*fcf3ce44SJohn Forte viewEntry.allHosts = B_FALSE; 567*fcf3ce44SJohn Forte bcopy(options->optarg, viewEntry.hostGroup, 568*fcf3ce44SJohn Forte strlen(options->optarg)); 569*fcf3ce44SJohn Forte break; 570*fcf3ce44SJohn Forte /* target group */ 571*fcf3ce44SJohn Forte case 't': 572*fcf3ce44SJohn Forte viewEntry.allTargets = B_FALSE; 573*fcf3ce44SJohn Forte bcopy(options->optarg, viewEntry.targetGroup, 574*fcf3ce44SJohn Forte strlen(options->optarg)); 575*fcf3ce44SJohn Forte break; 576*fcf3ce44SJohn Forte default: 577*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %c: %s\n", 578*fcf3ce44SJohn Forte cmdName, options->optval, 579*fcf3ce44SJohn Forte gettext("unknown option")); 580*fcf3ce44SJohn Forte return (1); 581*fcf3ce44SJohn Forte } 582*fcf3ce44SJohn Forte } 583*fcf3ce44SJohn Forte 584*fcf3ce44SJohn Forte /* convert to lower case for scan */ 585*fcf3ce44SJohn Forte for (i = 0; i < 32; i++) 586*fcf3ce44SJohn Forte sGuid[i] = tolower(operands[0][i]); 587*fcf3ce44SJohn Forte sGuid[i] = 0; 588*fcf3ce44SJohn Forte 589*fcf3ce44SJohn Forte (void) sscanf(sGuid, "%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x", 590*fcf3ce44SJohn Forte &guid[0], &guid[1], &guid[2], &guid[3], &guid[4], &guid[5], 591*fcf3ce44SJohn Forte &guid[6], &guid[7], &guid[8], &guid[9], &guid[10], &guid[11], 592*fcf3ce44SJohn Forte &guid[12], &guid[13], &guid[14], &guid[15]); 593*fcf3ce44SJohn Forte 594*fcf3ce44SJohn Forte for (i = 0; i < sizeof (stmfGuid); i++) { 595*fcf3ce44SJohn Forte inGuid.guid[i] = guid[i]; 596*fcf3ce44SJohn Forte } 597*fcf3ce44SJohn Forte 598*fcf3ce44SJohn Forte /* add the view entry */ 599*fcf3ce44SJohn Forte stmfRet = stmfAddViewEntry(&inGuid, &viewEntry); 600*fcf3ce44SJohn Forte switch (stmfRet) { 601*fcf3ce44SJohn Forte case STMF_STATUS_SUCCESS: 602*fcf3ce44SJohn Forte break; 603*fcf3ce44SJohn Forte case STMF_ERROR_EXISTS: 604*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 605*fcf3ce44SJohn Forte operands[0], gettext("already exists")); 606*fcf3ce44SJohn Forte ret++; 607*fcf3ce44SJohn Forte break; 608*fcf3ce44SJohn Forte case STMF_ERROR_BUSY: 609*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 610*fcf3ce44SJohn Forte operands[0], gettext("resource busy")); 611*fcf3ce44SJohn Forte ret++; 612*fcf3ce44SJohn Forte break; 613*fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_NOT_FOUND: 614*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 615*fcf3ce44SJohn Forte gettext("STMF service not found")); 616*fcf3ce44SJohn Forte ret++; 617*fcf3ce44SJohn Forte break; 618*fcf3ce44SJohn Forte case STMF_ERROR_PERM: 619*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 620*fcf3ce44SJohn Forte gettext("permission denied")); 621*fcf3ce44SJohn Forte ret++; 622*fcf3ce44SJohn Forte break; 623*fcf3ce44SJohn Forte case STMF_ERROR_LUN_IN_USE: 624*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 625*fcf3ce44SJohn Forte gettext("LUN already in use")); 626*fcf3ce44SJohn Forte ret++; 627*fcf3ce44SJohn Forte break; 628*fcf3ce44SJohn Forte case STMF_ERROR_VE_CONFLICT: 629*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 630*fcf3ce44SJohn Forte gettext("view entry exists")); 631*fcf3ce44SJohn Forte ret++; 632*fcf3ce44SJohn Forte break; 633*fcf3ce44SJohn Forte case STMF_ERROR_CONFIG_NONE: 634*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 635*fcf3ce44SJohn Forte gettext("STMF service is not initialized")); 636*fcf3ce44SJohn Forte ret++; 637*fcf3ce44SJohn Forte break; 638*fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_DATA_VERSION: 639*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 640*fcf3ce44SJohn Forte gettext("STMF service version incorrect")); 641*fcf3ce44SJohn Forte ret++; 642*fcf3ce44SJohn Forte break; 643*fcf3ce44SJohn Forte case STMF_ERROR_INVALID_HG: 644*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 645*fcf3ce44SJohn Forte gettext("invalid host group")); 646*fcf3ce44SJohn Forte ret++; 647*fcf3ce44SJohn Forte break; 648*fcf3ce44SJohn Forte case STMF_ERROR_INVALID_TG: 649*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 650*fcf3ce44SJohn Forte gettext("invalid target group")); 651*fcf3ce44SJohn Forte ret++; 652*fcf3ce44SJohn Forte break; 653*fcf3ce44SJohn Forte default: 654*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 655*fcf3ce44SJohn Forte operands[0], gettext("unknown error")); 656*fcf3ce44SJohn Forte ret++; 657*fcf3ce44SJohn Forte break; 658*fcf3ce44SJohn Forte } 659*fcf3ce44SJohn Forte 660*fcf3ce44SJohn Forte return (ret); 661*fcf3ce44SJohn Forte } 662*fcf3ce44SJohn Forte 663*fcf3ce44SJohn Forte /* 664*fcf3ce44SJohn Forte * createHostGroupFunc 665*fcf3ce44SJohn Forte * 666*fcf3ce44SJohn Forte * Create a host group 667*fcf3ce44SJohn Forte * 668*fcf3ce44SJohn Forte */ 669*fcf3ce44SJohn Forte /*ARGSUSED*/ 670*fcf3ce44SJohn Forte static int 671*fcf3ce44SJohn Forte createHostGroupFunc(int operandLen, char *operands[], 672*fcf3ce44SJohn Forte cmdOptions_t *options, void *args) 673*fcf3ce44SJohn Forte { 674*fcf3ce44SJohn Forte int ret = 0; 675*fcf3ce44SJohn Forte int stmfRet; 676*fcf3ce44SJohn Forte wchar_t groupNamePrint[sizeof (stmfGroupName)]; 677*fcf3ce44SJohn Forte stmfGroupName groupName; 678*fcf3ce44SJohn Forte 679*fcf3ce44SJohn Forte (void) strlcpy(groupName, operands[0], sizeof (groupName)); 680*fcf3ce44SJohn Forte (void) mbstowcs(groupNamePrint, (char *)groupName, 681*fcf3ce44SJohn Forte sizeof (groupNamePrint)); 682*fcf3ce44SJohn Forte /* call create group */ 683*fcf3ce44SJohn Forte stmfRet = stmfCreateHostGroup(&groupName); 684*fcf3ce44SJohn Forte switch (stmfRet) { 685*fcf3ce44SJohn Forte case STMF_STATUS_SUCCESS: 686*fcf3ce44SJohn Forte break; 687*fcf3ce44SJohn Forte case STMF_ERROR_EXISTS: 688*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 689*fcf3ce44SJohn Forte operands[0], gettext("already exists")); 690*fcf3ce44SJohn Forte ret++; 691*fcf3ce44SJohn Forte break; 692*fcf3ce44SJohn Forte case STMF_ERROR_BUSY: 693*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %ws: %s\n", cmdName, 694*fcf3ce44SJohn Forte operands[0], gettext("resource busy")); 695*fcf3ce44SJohn Forte ret++; 696*fcf3ce44SJohn Forte break; 697*fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_NOT_FOUND: 698*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 699*fcf3ce44SJohn Forte gettext("STMF service not found")); 700*fcf3ce44SJohn Forte ret++; 701*fcf3ce44SJohn Forte break; 702*fcf3ce44SJohn Forte case STMF_ERROR_PERM: 703*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 704*fcf3ce44SJohn Forte gettext("permission denied")); 705*fcf3ce44SJohn Forte ret++; 706*fcf3ce44SJohn Forte break; 707*fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_DATA_VERSION: 708*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 709*fcf3ce44SJohn Forte gettext("STMF service version incorrect")); 710*fcf3ce44SJohn Forte ret++; 711*fcf3ce44SJohn Forte break; 712*fcf3ce44SJohn Forte default: 713*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 714*fcf3ce44SJohn Forte operands[0], gettext("unknown error")); 715*fcf3ce44SJohn Forte ret++; 716*fcf3ce44SJohn Forte break; 717*fcf3ce44SJohn Forte } 718*fcf3ce44SJohn Forte 719*fcf3ce44SJohn Forte return (ret); 720*fcf3ce44SJohn Forte } 721*fcf3ce44SJohn Forte 722*fcf3ce44SJohn Forte /* 723*fcf3ce44SJohn Forte * createTargetGroupFunc 724*fcf3ce44SJohn Forte * 725*fcf3ce44SJohn Forte * Create a target group 726*fcf3ce44SJohn Forte * 727*fcf3ce44SJohn Forte */ 728*fcf3ce44SJohn Forte /*ARGSUSED*/ 729*fcf3ce44SJohn Forte static int 730*fcf3ce44SJohn Forte createTargetGroupFunc(int operandLen, char *operands[], cmdOptions_t *options, 731*fcf3ce44SJohn Forte void *args) 732*fcf3ce44SJohn Forte { 733*fcf3ce44SJohn Forte int ret = 0; 734*fcf3ce44SJohn Forte int stmfRet; 735*fcf3ce44SJohn Forte wchar_t groupNamePrint[sizeof (stmfGroupName)]; 736*fcf3ce44SJohn Forte stmfGroupName groupName; 737*fcf3ce44SJohn Forte 738*fcf3ce44SJohn Forte (void) strlcpy(groupName, operands[0], sizeof (groupName)); 739*fcf3ce44SJohn Forte (void) mbstowcs(groupNamePrint, (char *)groupName, 740*fcf3ce44SJohn Forte sizeof (groupNamePrint)); 741*fcf3ce44SJohn Forte /* call create group */ 742*fcf3ce44SJohn Forte stmfRet = stmfCreateTargetGroup(&groupName); 743*fcf3ce44SJohn Forte switch (stmfRet) { 744*fcf3ce44SJohn Forte case STMF_STATUS_SUCCESS: 745*fcf3ce44SJohn Forte break; 746*fcf3ce44SJohn Forte case STMF_ERROR_EXISTS: 747*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %ws: %s\n", cmdName, 748*fcf3ce44SJohn Forte groupNamePrint, gettext("already exists")); 749*fcf3ce44SJohn Forte ret++; 750*fcf3ce44SJohn Forte break; 751*fcf3ce44SJohn Forte case STMF_ERROR_BUSY: 752*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %ws: %s\n", cmdName, 753*fcf3ce44SJohn Forte groupNamePrint, gettext("resource busy")); 754*fcf3ce44SJohn Forte ret++; 755*fcf3ce44SJohn Forte break; 756*fcf3ce44SJohn Forte case STMF_ERROR_PERM: 757*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 758*fcf3ce44SJohn Forte gettext("permission denied")); 759*fcf3ce44SJohn Forte ret++; 760*fcf3ce44SJohn Forte break; 761*fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_NOT_FOUND: 762*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 763*fcf3ce44SJohn Forte gettext("STMF service not found")); 764*fcf3ce44SJohn Forte ret++; 765*fcf3ce44SJohn Forte break; 766*fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_DATA_VERSION: 767*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 768*fcf3ce44SJohn Forte gettext("STMF service version incorrect")); 769*fcf3ce44SJohn Forte ret++; 770*fcf3ce44SJohn Forte break; 771*fcf3ce44SJohn Forte default: 772*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %ws: %s\n", cmdName, 773*fcf3ce44SJohn Forte groupNamePrint, gettext("unknown error")); 774*fcf3ce44SJohn Forte ret++; 775*fcf3ce44SJohn Forte break; 776*fcf3ce44SJohn Forte } 777*fcf3ce44SJohn Forte 778*fcf3ce44SJohn Forte return (ret); 779*fcf3ce44SJohn Forte } 780*fcf3ce44SJohn Forte 781*fcf3ce44SJohn Forte /* 782*fcf3ce44SJohn Forte * deleteHostGroupFunc 783*fcf3ce44SJohn Forte * 784*fcf3ce44SJohn Forte * Delete a host group 785*fcf3ce44SJohn Forte * 786*fcf3ce44SJohn Forte */ 787*fcf3ce44SJohn Forte /*ARGSUSED*/ 788*fcf3ce44SJohn Forte static int 789*fcf3ce44SJohn Forte deleteHostGroupFunc(int operandLen, char *operands[], 790*fcf3ce44SJohn Forte cmdOptions_t *options, void *args) 791*fcf3ce44SJohn Forte { 792*fcf3ce44SJohn Forte int ret = 0; 793*fcf3ce44SJohn Forte int stmfRet; 794*fcf3ce44SJohn Forte wchar_t groupNamePrint[sizeof (stmfGroupName)]; 795*fcf3ce44SJohn Forte stmfGroupName groupName; 796*fcf3ce44SJohn Forte 797*fcf3ce44SJohn Forte (void) strlcpy(groupName, operands[0], sizeof (groupName)); 798*fcf3ce44SJohn Forte (void) mbstowcs(groupNamePrint, (char *)groupName, 799*fcf3ce44SJohn Forte sizeof (groupNamePrint)); 800*fcf3ce44SJohn Forte /* call delete group */ 801*fcf3ce44SJohn Forte stmfRet = stmfDeleteHostGroup(&groupName); 802*fcf3ce44SJohn Forte switch (stmfRet) { 803*fcf3ce44SJohn Forte case STMF_STATUS_SUCCESS: 804*fcf3ce44SJohn Forte break; 805*fcf3ce44SJohn Forte case STMF_ERROR_NOT_FOUND: 806*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %ws: %s\n", cmdName, 807*fcf3ce44SJohn Forte groupNamePrint, gettext("not found")); 808*fcf3ce44SJohn Forte ret++; 809*fcf3ce44SJohn Forte break; 810*fcf3ce44SJohn Forte case STMF_ERROR_BUSY: 811*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %ws: %s\n", cmdName, 812*fcf3ce44SJohn Forte groupNamePrint, gettext("resource busy")); 813*fcf3ce44SJohn Forte ret++; 814*fcf3ce44SJohn Forte break; 815*fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_NOT_FOUND: 816*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 817*fcf3ce44SJohn Forte gettext("STMF service not found")); 818*fcf3ce44SJohn Forte ret++; 819*fcf3ce44SJohn Forte break; 820*fcf3ce44SJohn Forte case STMF_ERROR_PERM: 821*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 822*fcf3ce44SJohn Forte gettext("permission denied")); 823*fcf3ce44SJohn Forte ret++; 824*fcf3ce44SJohn Forte break; 825*fcf3ce44SJohn Forte case STMF_ERROR_GROUP_IN_USE: 826*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %ws: %s\n", cmdName, 827*fcf3ce44SJohn Forte groupNamePrint, 828*fcf3ce44SJohn Forte gettext("group is in use by existing view entry")); 829*fcf3ce44SJohn Forte ret++; 830*fcf3ce44SJohn Forte break; 831*fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_DATA_VERSION: 832*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 833*fcf3ce44SJohn Forte gettext("STMF service version incorrect")); 834*fcf3ce44SJohn Forte ret++; 835*fcf3ce44SJohn Forte break; 836*fcf3ce44SJohn Forte default: 837*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %ws: %s\n", cmdName, 838*fcf3ce44SJohn Forte groupNamePrint, gettext("unknown error")); 839*fcf3ce44SJohn Forte ret++; 840*fcf3ce44SJohn Forte break; 841*fcf3ce44SJohn Forte } 842*fcf3ce44SJohn Forte 843*fcf3ce44SJohn Forte return (ret); 844*fcf3ce44SJohn Forte } 845*fcf3ce44SJohn Forte 846*fcf3ce44SJohn Forte /* 847*fcf3ce44SJohn Forte * deleteTargetGroupFunc 848*fcf3ce44SJohn Forte * 849*fcf3ce44SJohn Forte * Delete a target group 850*fcf3ce44SJohn Forte * 851*fcf3ce44SJohn Forte */ 852*fcf3ce44SJohn Forte /*ARGSUSED*/ 853*fcf3ce44SJohn Forte static int 854*fcf3ce44SJohn Forte deleteTargetGroupFunc(int operandLen, char *operands[], cmdOptions_t *options, 855*fcf3ce44SJohn Forte void *args) 856*fcf3ce44SJohn Forte { 857*fcf3ce44SJohn Forte int ret = 0; 858*fcf3ce44SJohn Forte int stmfRet; 859*fcf3ce44SJohn Forte wchar_t groupNamePrint[sizeof (stmfGroupName)]; 860*fcf3ce44SJohn Forte stmfGroupName groupName; 861*fcf3ce44SJohn Forte 862*fcf3ce44SJohn Forte (void) strlcpy(groupName, operands[0], sizeof (groupName)); 863*fcf3ce44SJohn Forte (void) mbstowcs(groupNamePrint, (char *)groupName, 864*fcf3ce44SJohn Forte sizeof (groupNamePrint)); 865*fcf3ce44SJohn Forte /* call delete group */ 866*fcf3ce44SJohn Forte stmfRet = stmfDeleteTargetGroup(&groupName); 867*fcf3ce44SJohn Forte switch (stmfRet) { 868*fcf3ce44SJohn Forte case STMF_STATUS_SUCCESS: 869*fcf3ce44SJohn Forte break; 870*fcf3ce44SJohn Forte case STMF_ERROR_NOT_FOUND: 871*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %ws: %s\n", cmdName, 872*fcf3ce44SJohn Forte groupNamePrint, gettext("not found")); 873*fcf3ce44SJohn Forte ret++; 874*fcf3ce44SJohn Forte break; 875*fcf3ce44SJohn Forte case STMF_ERROR_BUSY: 876*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %ws: %s\n", cmdName, 877*fcf3ce44SJohn Forte groupNamePrint, gettext("resource busy")); 878*fcf3ce44SJohn Forte ret++; 879*fcf3ce44SJohn Forte break; 880*fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_NOT_FOUND: 881*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 882*fcf3ce44SJohn Forte gettext("STMF service not found")); 883*fcf3ce44SJohn Forte ret++; 884*fcf3ce44SJohn Forte break; 885*fcf3ce44SJohn Forte case STMF_ERROR_PERM: 886*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 887*fcf3ce44SJohn Forte gettext("permission denied")); 888*fcf3ce44SJohn Forte ret++; 889*fcf3ce44SJohn Forte break; 890*fcf3ce44SJohn Forte case STMF_ERROR_GROUP_IN_USE: 891*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %ws: %s\n", cmdName, 892*fcf3ce44SJohn Forte groupNamePrint, 893*fcf3ce44SJohn Forte gettext("group is in use by existing view entry")); 894*fcf3ce44SJohn Forte ret++; 895*fcf3ce44SJohn Forte break; 896*fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_DATA_VERSION: 897*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 898*fcf3ce44SJohn Forte gettext("STMF service version incorrect")); 899*fcf3ce44SJohn Forte ret++; 900*fcf3ce44SJohn Forte break; 901*fcf3ce44SJohn Forte default: 902*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %ws: %s\n", cmdName, 903*fcf3ce44SJohn Forte groupNamePrint, gettext("unknown error")); 904*fcf3ce44SJohn Forte ret++; 905*fcf3ce44SJohn Forte break; 906*fcf3ce44SJohn Forte } 907*fcf3ce44SJohn Forte 908*fcf3ce44SJohn Forte return (ret); 909*fcf3ce44SJohn Forte } 910*fcf3ce44SJohn Forte 911*fcf3ce44SJohn Forte /* 912*fcf3ce44SJohn Forte * listHostGroupFunc 913*fcf3ce44SJohn Forte * 914*fcf3ce44SJohn Forte * Lists the specified host groups or all if none are specified 915*fcf3ce44SJohn Forte * 916*fcf3ce44SJohn Forte */ 917*fcf3ce44SJohn Forte /*ARGSUSED*/ 918*fcf3ce44SJohn Forte static int 919*fcf3ce44SJohn Forte listHostGroupFunc(int operandLen, char *operands[], cmdOptions_t *options, 920*fcf3ce44SJohn Forte void *args) 921*fcf3ce44SJohn Forte { 922*fcf3ce44SJohn Forte int ret = 0; 923*fcf3ce44SJohn Forte int stmfRet; 924*fcf3ce44SJohn Forte int i, j, outerLoop; 925*fcf3ce44SJohn Forte boolean_t verbose = B_FALSE; 926*fcf3ce44SJohn Forte boolean_t found = B_TRUE; 927*fcf3ce44SJohn Forte boolean_t operandEntered; 928*fcf3ce44SJohn Forte stmfGroupList *groupList; 929*fcf3ce44SJohn Forte stmfGroupProperties *groupProps; 930*fcf3ce44SJohn Forte wchar_t operandName[sizeof (stmfGroupName)]; 931*fcf3ce44SJohn Forte wchar_t groupNamePrint[sizeof (stmfGroupName)]; 932*fcf3ce44SJohn Forte 933*fcf3ce44SJohn Forte for (; options->optval; options++) { 934*fcf3ce44SJohn Forte switch (options->optval) { 935*fcf3ce44SJohn Forte case 'v': 936*fcf3ce44SJohn Forte verbose = B_TRUE; 937*fcf3ce44SJohn Forte break; 938*fcf3ce44SJohn Forte default: 939*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %c: %s\n", 940*fcf3ce44SJohn Forte cmdName, options->optval, 941*fcf3ce44SJohn Forte gettext("unknown option")); 942*fcf3ce44SJohn Forte return (1); 943*fcf3ce44SJohn Forte } 944*fcf3ce44SJohn Forte } 945*fcf3ce44SJohn Forte 946*fcf3ce44SJohn Forte if (operandLen > 0) { 947*fcf3ce44SJohn Forte outerLoop = operandLen; 948*fcf3ce44SJohn Forte operandEntered = B_TRUE; 949*fcf3ce44SJohn Forte } else { 950*fcf3ce44SJohn Forte outerLoop = 1; 951*fcf3ce44SJohn Forte operandEntered = B_FALSE; 952*fcf3ce44SJohn Forte } 953*fcf3ce44SJohn Forte 954*fcf3ce44SJohn Forte stmfRet = stmfGetHostGroupList(&groupList); 955*fcf3ce44SJohn Forte if (stmfRet != STMF_STATUS_SUCCESS) { 956*fcf3ce44SJohn Forte switch (stmfRet) { 957*fcf3ce44SJohn Forte case STMF_ERROR_BUSY: 958*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 959*fcf3ce44SJohn Forte gettext("resource busy")); 960*fcf3ce44SJohn Forte break; 961*fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_NOT_FOUND: 962*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 963*fcf3ce44SJohn Forte gettext("STMF service not found")); 964*fcf3ce44SJohn Forte break; 965*fcf3ce44SJohn Forte case STMF_ERROR_PERM: 966*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 967*fcf3ce44SJohn Forte gettext("permission denied")); 968*fcf3ce44SJohn Forte break; 969*fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_DATA_VERSION: 970*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 971*fcf3ce44SJohn Forte gettext("STMF service version incorrect")); 972*fcf3ce44SJohn Forte break; 973*fcf3ce44SJohn Forte default: 974*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 975*fcf3ce44SJohn Forte gettext("unknown error")); 976*fcf3ce44SJohn Forte break; 977*fcf3ce44SJohn Forte } 978*fcf3ce44SJohn Forte return (1); 979*fcf3ce44SJohn Forte } 980*fcf3ce44SJohn Forte 981*fcf3ce44SJohn Forte for (i = 0; i < outerLoop; i++) { 982*fcf3ce44SJohn Forte for (found = B_FALSE, j = 0; j < groupList->cnt; j++) { 983*fcf3ce44SJohn Forte (void) mbstowcs(groupNamePrint, 984*fcf3ce44SJohn Forte (char *)groupList->name[j], 985*fcf3ce44SJohn Forte sizeof (groupNamePrint)); 986*fcf3ce44SJohn Forte if (operandEntered) { 987*fcf3ce44SJohn Forte (void) mbstowcs(operandName, operands[i], 988*fcf3ce44SJohn Forte sizeof (operandName)); 989*fcf3ce44SJohn Forte if (wcscmp(operandName, groupNamePrint) 990*fcf3ce44SJohn Forte == 0) { 991*fcf3ce44SJohn Forte found = B_TRUE; 992*fcf3ce44SJohn Forte } 993*fcf3ce44SJohn Forte } 994*fcf3ce44SJohn Forte if ((found && operandEntered) || !operandEntered) { 995*fcf3ce44SJohn Forte (void) printf("Host Group: %ws\n", 996*fcf3ce44SJohn Forte groupNamePrint); 997*fcf3ce44SJohn Forte if (verbose) { 998*fcf3ce44SJohn Forte stmfRet = stmfGetHostGroupMembers( 999*fcf3ce44SJohn Forte &(groupList->name[j]), &groupProps); 1000*fcf3ce44SJohn Forte if (stmfRet != STMF_STATUS_SUCCESS) { 1001*fcf3ce44SJohn Forte return (1); 1002*fcf3ce44SJohn Forte } 1003*fcf3ce44SJohn Forte printGroupProps(groupProps); 1004*fcf3ce44SJohn Forte } 1005*fcf3ce44SJohn Forte if (found && operandEntered) { 1006*fcf3ce44SJohn Forte break; 1007*fcf3ce44SJohn Forte } 1008*fcf3ce44SJohn Forte } 1009*fcf3ce44SJohn Forte 1010*fcf3ce44SJohn Forte } 1011*fcf3ce44SJohn Forte if (operandEntered && !found) { 1012*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 1013*fcf3ce44SJohn Forte operands[i], gettext("not found")); 1014*fcf3ce44SJohn Forte ret = 1; 1015*fcf3ce44SJohn Forte } 1016*fcf3ce44SJohn Forte } 1017*fcf3ce44SJohn Forte return (ret); 1018*fcf3ce44SJohn Forte } 1019*fcf3ce44SJohn Forte 1020*fcf3ce44SJohn Forte /* 1021*fcf3ce44SJohn Forte * printGroupProps 1022*fcf3ce44SJohn Forte * 1023*fcf3ce44SJohn Forte * Prints group members for target or host groups 1024*fcf3ce44SJohn Forte * 1025*fcf3ce44SJohn Forte */ 1026*fcf3ce44SJohn Forte static void 1027*fcf3ce44SJohn Forte printGroupProps(stmfGroupProperties *groupProps) 1028*fcf3ce44SJohn Forte { 1029*fcf3ce44SJohn Forte int i; 1030*fcf3ce44SJohn Forte wchar_t memberIdent[sizeof (groupProps->name[0].ident) + 1]; 1031*fcf3ce44SJohn Forte 1032*fcf3ce44SJohn Forte 1033*fcf3ce44SJohn Forte for (i = 0; i < groupProps->cnt; i++) { 1034*fcf3ce44SJohn Forte (void) mbstowcs(memberIdent, (char *)groupProps->name[i].ident, 1035*fcf3ce44SJohn Forte sizeof (memberIdent)); 1036*fcf3ce44SJohn Forte (void) printf("\tMember: %ws\n", memberIdent); 1037*fcf3ce44SJohn Forte } 1038*fcf3ce44SJohn Forte } 1039*fcf3ce44SJohn Forte 1040*fcf3ce44SJohn Forte /* 1041*fcf3ce44SJohn Forte * listTargetGroupFunc 1042*fcf3ce44SJohn Forte * 1043*fcf3ce44SJohn Forte * Lists the specified target groups or all if none are specified 1044*fcf3ce44SJohn Forte * 1045*fcf3ce44SJohn Forte */ 1046*fcf3ce44SJohn Forte /*ARGSUSED*/ 1047*fcf3ce44SJohn Forte static int 1048*fcf3ce44SJohn Forte listTargetGroupFunc(int operandLen, char *operands[], cmdOptions_t *options, 1049*fcf3ce44SJohn Forte void *args) 1050*fcf3ce44SJohn Forte { 1051*fcf3ce44SJohn Forte int ret = 0; 1052*fcf3ce44SJohn Forte int stmfRet; 1053*fcf3ce44SJohn Forte int i, j, outerLoop; 1054*fcf3ce44SJohn Forte boolean_t verbose = B_FALSE; 1055*fcf3ce44SJohn Forte boolean_t found = B_TRUE; 1056*fcf3ce44SJohn Forte boolean_t operandEntered; 1057*fcf3ce44SJohn Forte stmfGroupList *groupList; 1058*fcf3ce44SJohn Forte stmfGroupProperties *groupProps; 1059*fcf3ce44SJohn Forte wchar_t operandName[sizeof (stmfGroupName)]; 1060*fcf3ce44SJohn Forte wchar_t groupNamePrint[sizeof (stmfGroupName)]; 1061*fcf3ce44SJohn Forte 1062*fcf3ce44SJohn Forte for (; options->optval; options++) { 1063*fcf3ce44SJohn Forte switch (options->optval) { 1064*fcf3ce44SJohn Forte case 'v': 1065*fcf3ce44SJohn Forte verbose = B_TRUE; 1066*fcf3ce44SJohn Forte break; 1067*fcf3ce44SJohn Forte default: 1068*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %c: %s\n", 1069*fcf3ce44SJohn Forte cmdName, options->optval, 1070*fcf3ce44SJohn Forte gettext("unknown option")); 1071*fcf3ce44SJohn Forte return (1); 1072*fcf3ce44SJohn Forte } 1073*fcf3ce44SJohn Forte } 1074*fcf3ce44SJohn Forte 1075*fcf3ce44SJohn Forte if (operandLen > 0) { 1076*fcf3ce44SJohn Forte outerLoop = operandLen; 1077*fcf3ce44SJohn Forte operandEntered = B_TRUE; 1078*fcf3ce44SJohn Forte } else { 1079*fcf3ce44SJohn Forte outerLoop = 1; 1080*fcf3ce44SJohn Forte operandEntered = B_FALSE; 1081*fcf3ce44SJohn Forte } 1082*fcf3ce44SJohn Forte 1083*fcf3ce44SJohn Forte stmfRet = stmfGetTargetGroupList(&groupList); 1084*fcf3ce44SJohn Forte if (stmfRet != STMF_STATUS_SUCCESS) { 1085*fcf3ce44SJohn Forte switch (stmfRet) { 1086*fcf3ce44SJohn Forte case STMF_ERROR_BUSY: 1087*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 1088*fcf3ce44SJohn Forte gettext("resource busy")); 1089*fcf3ce44SJohn Forte break; 1090*fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_NOT_FOUND: 1091*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 1092*fcf3ce44SJohn Forte gettext("STMF service not found")); 1093*fcf3ce44SJohn Forte break; 1094*fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_DATA_VERSION: 1095*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 1096*fcf3ce44SJohn Forte gettext("STMF service version incorrect")); 1097*fcf3ce44SJohn Forte break; 1098*fcf3ce44SJohn Forte case STMF_ERROR_PERM: 1099*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 1100*fcf3ce44SJohn Forte gettext("permission denied")); 1101*fcf3ce44SJohn Forte break; 1102*fcf3ce44SJohn Forte default: 1103*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 1104*fcf3ce44SJohn Forte gettext("unknown error")); 1105*fcf3ce44SJohn Forte break; 1106*fcf3ce44SJohn Forte } 1107*fcf3ce44SJohn Forte return (1); 1108*fcf3ce44SJohn Forte } 1109*fcf3ce44SJohn Forte 1110*fcf3ce44SJohn Forte for (i = 0; i < outerLoop; i++) { 1111*fcf3ce44SJohn Forte for (found = B_FALSE, j = 0; j < groupList->cnt; j++) { 1112*fcf3ce44SJohn Forte (void) mbstowcs(groupNamePrint, 1113*fcf3ce44SJohn Forte (char *)groupList->name[j], 1114*fcf3ce44SJohn Forte sizeof (groupNamePrint)); 1115*fcf3ce44SJohn Forte if (operandEntered) { 1116*fcf3ce44SJohn Forte (void) mbstowcs(operandName, operands[i], 1117*fcf3ce44SJohn Forte sizeof (operandName)); 1118*fcf3ce44SJohn Forte if (wcscmp(operandName, groupNamePrint) 1119*fcf3ce44SJohn Forte == 0) { 1120*fcf3ce44SJohn Forte found = B_TRUE; 1121*fcf3ce44SJohn Forte } 1122*fcf3ce44SJohn Forte } 1123*fcf3ce44SJohn Forte if ((found && operandEntered) || !operandEntered) { 1124*fcf3ce44SJohn Forte (void) printf("Target Group: %ws\n", 1125*fcf3ce44SJohn Forte groupNamePrint); 1126*fcf3ce44SJohn Forte if (verbose) { 1127*fcf3ce44SJohn Forte stmfRet = stmfGetTargetGroupMembers( 1128*fcf3ce44SJohn Forte &(groupList->name[j]), &groupProps); 1129*fcf3ce44SJohn Forte if (stmfRet != STMF_STATUS_SUCCESS) { 1130*fcf3ce44SJohn Forte return (1); 1131*fcf3ce44SJohn Forte } 1132*fcf3ce44SJohn Forte printGroupProps(groupProps); 1133*fcf3ce44SJohn Forte } 1134*fcf3ce44SJohn Forte if (found && operandEntered) { 1135*fcf3ce44SJohn Forte break; 1136*fcf3ce44SJohn Forte } 1137*fcf3ce44SJohn Forte } 1138*fcf3ce44SJohn Forte 1139*fcf3ce44SJohn Forte } 1140*fcf3ce44SJohn Forte if (operandEntered && !found) { 1141*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 1142*fcf3ce44SJohn Forte operands[i], gettext("not found")); 1143*fcf3ce44SJohn Forte ret = 1; 1144*fcf3ce44SJohn Forte } 1145*fcf3ce44SJohn Forte } 1146*fcf3ce44SJohn Forte return (ret); 1147*fcf3ce44SJohn Forte } 1148*fcf3ce44SJohn Forte 1149*fcf3ce44SJohn Forte /* 1150*fcf3ce44SJohn Forte * listLuFunc 1151*fcf3ce44SJohn Forte * 1152*fcf3ce44SJohn Forte * List the logical units and optionally the properties 1153*fcf3ce44SJohn Forte * 1154*fcf3ce44SJohn Forte */ 1155*fcf3ce44SJohn Forte /*ARGSUSED*/ 1156*fcf3ce44SJohn Forte static int 1157*fcf3ce44SJohn Forte listLuFunc(int operandLen, char *operands[], cmdOptions_t *options, void *args) 1158*fcf3ce44SJohn Forte { 1159*fcf3ce44SJohn Forte cmdOptions_t *optionList = options; 1160*fcf3ce44SJohn Forte boolean_t operandEntered; 1161*fcf3ce44SJohn Forte int i, j; 1162*fcf3ce44SJohn Forte int ret = 0; 1163*fcf3ce44SJohn Forte int stmfRet; 1164*fcf3ce44SJohn Forte int outerLoop; 1165*fcf3ce44SJohn Forte unsigned int inGuid[sizeof (stmfGuid)]; 1166*fcf3ce44SJohn Forte stmfGuid cmpGuid; 1167*fcf3ce44SJohn Forte boolean_t verbose = B_FALSE; 1168*fcf3ce44SJohn Forte boolean_t found; 1169*fcf3ce44SJohn Forte char sGuid[GUID_INPUT + 1]; 1170*fcf3ce44SJohn Forte stmfGuidList *luList; 1171*fcf3ce44SJohn Forte stmfLogicalUnitProperties luProps; 1172*fcf3ce44SJohn Forte boolean_t invalidInput = B_FALSE; 1173*fcf3ce44SJohn Forte stmfViewEntryList *viewEntryList; 1174*fcf3ce44SJohn Forte 1175*fcf3ce44SJohn Forte for (; optionList->optval; optionList++) { 1176*fcf3ce44SJohn Forte switch (optionList->optval) { 1177*fcf3ce44SJohn Forte case 'v': 1178*fcf3ce44SJohn Forte verbose = B_TRUE; 1179*fcf3ce44SJohn Forte break; 1180*fcf3ce44SJohn Forte } 1181*fcf3ce44SJohn Forte } 1182*fcf3ce44SJohn Forte 1183*fcf3ce44SJohn Forte if ((stmfRet = stmfGetLogicalUnitList(&luList)) 1184*fcf3ce44SJohn Forte != STMF_STATUS_SUCCESS) { 1185*fcf3ce44SJohn Forte switch (stmfRet) { 1186*fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_NOT_FOUND: 1187*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 1188*fcf3ce44SJohn Forte gettext("STMF service not found")); 1189*fcf3ce44SJohn Forte break; 1190*fcf3ce44SJohn Forte case STMF_ERROR_BUSY: 1191*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 1192*fcf3ce44SJohn Forte gettext("resource busy")); 1193*fcf3ce44SJohn Forte break; 1194*fcf3ce44SJohn Forte case STMF_ERROR_PERM: 1195*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 1196*fcf3ce44SJohn Forte gettext("permission denied")); 1197*fcf3ce44SJohn Forte break; 1198*fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_DATA_VERSION: 1199*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 1200*fcf3ce44SJohn Forte gettext("STMF service version incorrect")); 1201*fcf3ce44SJohn Forte break; 1202*fcf3ce44SJohn Forte default: 1203*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 1204*fcf3ce44SJohn Forte gettext("list failed")); 1205*fcf3ce44SJohn Forte break; 1206*fcf3ce44SJohn Forte } 1207*fcf3ce44SJohn Forte return (1); 1208*fcf3ce44SJohn Forte } 1209*fcf3ce44SJohn Forte 1210*fcf3ce44SJohn Forte if (operandLen > 0) { 1211*fcf3ce44SJohn Forte operandEntered = B_TRUE; 1212*fcf3ce44SJohn Forte outerLoop = operandLen; 1213*fcf3ce44SJohn Forte } else { 1214*fcf3ce44SJohn Forte operandEntered = B_FALSE; 1215*fcf3ce44SJohn Forte outerLoop = 1; 1216*fcf3ce44SJohn Forte } 1217*fcf3ce44SJohn Forte 1218*fcf3ce44SJohn Forte 1219*fcf3ce44SJohn Forte for (invalidInput = B_FALSE, i = 0; i < outerLoop; i++) { 1220*fcf3ce44SJohn Forte if (operandEntered) { 1221*fcf3ce44SJohn Forte if (strlen(operands[i]) != GUID_INPUT) { 1222*fcf3ce44SJohn Forte invalidInput = B_TRUE; 1223*fcf3ce44SJohn Forte } else { 1224*fcf3ce44SJohn Forte for (j = 0; j < GUID_INPUT; j++) { 1225*fcf3ce44SJohn Forte if (!isxdigit(operands[i][j])) { 1226*fcf3ce44SJohn Forte invalidInput = B_TRUE; 1227*fcf3ce44SJohn Forte break; 1228*fcf3ce44SJohn Forte } 1229*fcf3ce44SJohn Forte } 1230*fcf3ce44SJohn Forte } 1231*fcf3ce44SJohn Forte if (invalidInput) { 1232*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s%d%s\n", 1233*fcf3ce44SJohn Forte cmdName, operands[i], gettext("must be "), 1234*fcf3ce44SJohn Forte GUID_INPUT, 1235*fcf3ce44SJohn Forte gettext(" hexadecimal digits long")); 1236*fcf3ce44SJohn Forte continue; 1237*fcf3ce44SJohn Forte } 1238*fcf3ce44SJohn Forte 1239*fcf3ce44SJohn Forte for (j = 0; j < GUID_INPUT; j++) { 1240*fcf3ce44SJohn Forte sGuid[j] = tolower(operands[i][j]); 1241*fcf3ce44SJohn Forte } 1242*fcf3ce44SJohn Forte sGuid[j] = 0; 1243*fcf3ce44SJohn Forte 1244*fcf3ce44SJohn Forte (void) sscanf(sGuid, 1245*fcf3ce44SJohn Forte "%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x", 1246*fcf3ce44SJohn Forte &inGuid[0], &inGuid[1], &inGuid[2], &inGuid[3], 1247*fcf3ce44SJohn Forte &inGuid[4], &inGuid[5], &inGuid[6], &inGuid[7], 1248*fcf3ce44SJohn Forte &inGuid[8], &inGuid[9], &inGuid[10], &inGuid[11], 1249*fcf3ce44SJohn Forte &inGuid[12], &inGuid[13], &inGuid[14], &inGuid[15]); 1250*fcf3ce44SJohn Forte 1251*fcf3ce44SJohn Forte for (j = 0; j < sizeof (stmfGuid); j++) { 1252*fcf3ce44SJohn Forte cmpGuid.guid[j] = inGuid[j]; 1253*fcf3ce44SJohn Forte } 1254*fcf3ce44SJohn Forte } 1255*fcf3ce44SJohn Forte 1256*fcf3ce44SJohn Forte for (found = B_FALSE, j = 0; j < luList->cnt; j++) { 1257*fcf3ce44SJohn Forte if (operandEntered) { 1258*fcf3ce44SJohn Forte if (bcmp(luList->guid[j].guid, cmpGuid.guid, 1259*fcf3ce44SJohn Forte sizeof (stmfGuid)) == 0) { 1260*fcf3ce44SJohn Forte found = B_TRUE; 1261*fcf3ce44SJohn Forte } 1262*fcf3ce44SJohn Forte } 1263*fcf3ce44SJohn Forte if ((found && operandEntered) || !operandEntered) { 1264*fcf3ce44SJohn Forte (void) printf("LU Name: "); 1265*fcf3ce44SJohn Forte printGuid(&luList->guid[j], stdout); 1266*fcf3ce44SJohn Forte (void) printf("\n"); 1267*fcf3ce44SJohn Forte 1268*fcf3ce44SJohn Forte if (verbose) { 1269*fcf3ce44SJohn Forte stmfRet = stmfGetLogicalUnitProperties( 1270*fcf3ce44SJohn Forte &(luList->guid[j]), &luProps); 1271*fcf3ce44SJohn Forte if (stmfRet == STMF_STATUS_SUCCESS) { 1272*fcf3ce44SJohn Forte printLuProps(&luProps); 1273*fcf3ce44SJohn Forte } else { 1274*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s:", 1275*fcf3ce44SJohn Forte cmdName); 1276*fcf3ce44SJohn Forte printGuid(&luList->guid[j], 1277*fcf3ce44SJohn Forte stderr); 1278*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s\n", 1279*fcf3ce44SJohn Forte gettext(" get properties " 1280*fcf3ce44SJohn Forte "failed")); 1281*fcf3ce44SJohn Forte } 1282*fcf3ce44SJohn Forte stmfRet = stmfGetViewEntryList( 1283*fcf3ce44SJohn Forte &(luList->guid[j]), 1284*fcf3ce44SJohn Forte &viewEntryList); 1285*fcf3ce44SJohn Forte (void) printf(PROPS_FORMAT, 1286*fcf3ce44SJohn Forte "View Entry Count"); 1287*fcf3ce44SJohn Forte if (stmfRet == STMF_STATUS_SUCCESS) { 1288*fcf3ce44SJohn Forte (void) printf("%d", 1289*fcf3ce44SJohn Forte viewEntryList->cnt); 1290*fcf3ce44SJohn Forte } else if (stmfRet == 1291*fcf3ce44SJohn Forte STMF_ERROR_NOT_FOUND) { 1292*fcf3ce44SJohn Forte (void) printf("0"); 1293*fcf3ce44SJohn Forte } else { 1294*fcf3ce44SJohn Forte (void) printf("unknown"); 1295*fcf3ce44SJohn Forte } 1296*fcf3ce44SJohn Forte (void) printf("\n"); 1297*fcf3ce44SJohn Forte } 1298*fcf3ce44SJohn Forte if (found && operandEntered) { 1299*fcf3ce44SJohn Forte break; 1300*fcf3ce44SJohn Forte } 1301*fcf3ce44SJohn Forte } 1302*fcf3ce44SJohn Forte 1303*fcf3ce44SJohn Forte } 1304*fcf3ce44SJohn Forte if (operandEntered && !found) { 1305*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 1306*fcf3ce44SJohn Forte operands[i], gettext("not found")); 1307*fcf3ce44SJohn Forte ret = 1; 1308*fcf3ce44SJohn Forte } 1309*fcf3ce44SJohn Forte } 1310*fcf3ce44SJohn Forte 1311*fcf3ce44SJohn Forte return (ret); 1312*fcf3ce44SJohn Forte } 1313*fcf3ce44SJohn Forte 1314*fcf3ce44SJohn Forte static void 1315*fcf3ce44SJohn Forte printGuid(stmfGuid *guid, FILE *stream) 1316*fcf3ce44SJohn Forte { 1317*fcf3ce44SJohn Forte int i; 1318*fcf3ce44SJohn Forte for (i = 0; i < 16; i++) { 1319*fcf3ce44SJohn Forte (void) fprintf(stream, "%02X", guid->guid[i]); 1320*fcf3ce44SJohn Forte } 1321*fcf3ce44SJohn Forte } 1322*fcf3ce44SJohn Forte 1323*fcf3ce44SJohn Forte 1324*fcf3ce44SJohn Forte /* 1325*fcf3ce44SJohn Forte * printLuProps 1326*fcf3ce44SJohn Forte * 1327*fcf3ce44SJohn Forte * Prints the properties for a logical unit 1328*fcf3ce44SJohn Forte * 1329*fcf3ce44SJohn Forte */ 1330*fcf3ce44SJohn Forte static void 1331*fcf3ce44SJohn Forte printLuProps(stmfLogicalUnitProperties *luProps) 1332*fcf3ce44SJohn Forte { 1333*fcf3ce44SJohn Forte (void) printf(PROPS_FORMAT, "Operational Status"); 1334*fcf3ce44SJohn Forte switch (luProps->status) { 1335*fcf3ce44SJohn Forte case STMF_LOGICAL_UNIT_ONLINE: 1336*fcf3ce44SJohn Forte (void) printf("Online"); 1337*fcf3ce44SJohn Forte break; 1338*fcf3ce44SJohn Forte case STMF_LOGICAL_UNIT_OFFLINE: 1339*fcf3ce44SJohn Forte (void) printf("Offline"); 1340*fcf3ce44SJohn Forte break; 1341*fcf3ce44SJohn Forte case STMF_LOGICAL_UNIT_ONLINING: 1342*fcf3ce44SJohn Forte (void) printf("Onlining"); 1343*fcf3ce44SJohn Forte break; 1344*fcf3ce44SJohn Forte case STMF_LOGICAL_UNIT_OFFLINING: 1345*fcf3ce44SJohn Forte (void) printf("Offlining"); 1346*fcf3ce44SJohn Forte break; 1347*fcf3ce44SJohn Forte case STMF_LOGICAL_UNIT_UNREGISTERED: 1348*fcf3ce44SJohn Forte (void) printf("unregistered"); 1349*fcf3ce44SJohn Forte (void) strncpy(luProps->providerName, "unregistered", 1350*fcf3ce44SJohn Forte sizeof (luProps->providerName)); 1351*fcf3ce44SJohn Forte break; 1352*fcf3ce44SJohn Forte default: 1353*fcf3ce44SJohn Forte (void) printf("unknown"); 1354*fcf3ce44SJohn Forte break; 1355*fcf3ce44SJohn Forte } 1356*fcf3ce44SJohn Forte (void) printf("\n"); 1357*fcf3ce44SJohn Forte (void) printf(PROPS_FORMAT, "Provider Name"); 1358*fcf3ce44SJohn Forte if (luProps->providerName[0] != 0) { 1359*fcf3ce44SJohn Forte (void) printf("%s", luProps->providerName); 1360*fcf3ce44SJohn Forte } else { 1361*fcf3ce44SJohn Forte (void) printf("unknown"); 1362*fcf3ce44SJohn Forte } 1363*fcf3ce44SJohn Forte (void) printf("\n"); 1364*fcf3ce44SJohn Forte (void) printf(PROPS_FORMAT, "Alias"); 1365*fcf3ce44SJohn Forte if (luProps->alias[0] != 0) { 1366*fcf3ce44SJohn Forte (void) printf("%s", luProps->alias); 1367*fcf3ce44SJohn Forte } else { 1368*fcf3ce44SJohn Forte (void) printf("-"); 1369*fcf3ce44SJohn Forte } 1370*fcf3ce44SJohn Forte (void) printf("\n"); 1371*fcf3ce44SJohn Forte } 1372*fcf3ce44SJohn Forte 1373*fcf3ce44SJohn Forte /* 1374*fcf3ce44SJohn Forte * printTargetProps 1375*fcf3ce44SJohn Forte * 1376*fcf3ce44SJohn Forte * Prints the properties for a target 1377*fcf3ce44SJohn Forte * 1378*fcf3ce44SJohn Forte */ 1379*fcf3ce44SJohn Forte static void 1380*fcf3ce44SJohn Forte printTargetProps(stmfTargetProperties *targetProps) 1381*fcf3ce44SJohn Forte { 1382*fcf3ce44SJohn Forte (void) printf(PROPS_FORMAT, "Operational Status"); 1383*fcf3ce44SJohn Forte switch (targetProps->status) { 1384*fcf3ce44SJohn Forte case STMF_TARGET_PORT_ONLINE: 1385*fcf3ce44SJohn Forte (void) printf("Online"); 1386*fcf3ce44SJohn Forte break; 1387*fcf3ce44SJohn Forte case STMF_TARGET_PORT_OFFLINE: 1388*fcf3ce44SJohn Forte (void) printf("Offline"); 1389*fcf3ce44SJohn Forte break; 1390*fcf3ce44SJohn Forte case STMF_TARGET_PORT_ONLINING: 1391*fcf3ce44SJohn Forte (void) printf("Onlining"); 1392*fcf3ce44SJohn Forte break; 1393*fcf3ce44SJohn Forte case STMF_TARGET_PORT_OFFLINING: 1394*fcf3ce44SJohn Forte (void) printf("Offlining"); 1395*fcf3ce44SJohn Forte break; 1396*fcf3ce44SJohn Forte default: 1397*fcf3ce44SJohn Forte (void) printf("unknown"); 1398*fcf3ce44SJohn Forte break; 1399*fcf3ce44SJohn Forte } 1400*fcf3ce44SJohn Forte (void) printf("\n"); 1401*fcf3ce44SJohn Forte (void) printf(PROPS_FORMAT, "Provider Name"); 1402*fcf3ce44SJohn Forte if (targetProps->providerName[0] != 0) { 1403*fcf3ce44SJohn Forte (void) printf("%s", targetProps->providerName); 1404*fcf3ce44SJohn Forte } 1405*fcf3ce44SJohn Forte (void) printf("\n"); 1406*fcf3ce44SJohn Forte (void) printf(PROPS_FORMAT, "Alias"); 1407*fcf3ce44SJohn Forte if (targetProps->alias[0] != 0) { 1408*fcf3ce44SJohn Forte (void) printf("%s", targetProps->alias); 1409*fcf3ce44SJohn Forte } else { 1410*fcf3ce44SJohn Forte (void) printf("-"); 1411*fcf3ce44SJohn Forte } 1412*fcf3ce44SJohn Forte (void) printf("\n"); 1413*fcf3ce44SJohn Forte } 1414*fcf3ce44SJohn Forte 1415*fcf3ce44SJohn Forte /* 1416*fcf3ce44SJohn Forte * printSessionProps 1417*fcf3ce44SJohn Forte * 1418*fcf3ce44SJohn Forte * Prints the session data 1419*fcf3ce44SJohn Forte * 1420*fcf3ce44SJohn Forte */ 1421*fcf3ce44SJohn Forte static void 1422*fcf3ce44SJohn Forte printSessionProps(stmfSessionList *sessionList) 1423*fcf3ce44SJohn Forte { 1424*fcf3ce44SJohn Forte int i; 1425*fcf3ce44SJohn Forte char *cTime; 1426*fcf3ce44SJohn Forte wchar_t initiator[STMF_IDENT_LENGTH + 1]; 1427*fcf3ce44SJohn Forte 1428*fcf3ce44SJohn Forte (void) printf(PROPS_FORMAT, "Sessions"); 1429*fcf3ce44SJohn Forte (void) printf("%d\n", sessionList->cnt); 1430*fcf3ce44SJohn Forte for (i = 0; i < sessionList->cnt; i++) { 1431*fcf3ce44SJohn Forte (void) mbstowcs(initiator, 1432*fcf3ce44SJohn Forte (char *)sessionList->session[i].initiator.ident, 1433*fcf3ce44SJohn Forte sizeof (initiator)); 1434*fcf3ce44SJohn Forte (void) printf(LVL3_FORMAT, "Initiator: "); 1435*fcf3ce44SJohn Forte (void) printf("%ws\n", initiator); 1436*fcf3ce44SJohn Forte (void) printf(LVL4_FORMAT, "Alias: "); 1437*fcf3ce44SJohn Forte if (sessionList->session[i].alias[0] != 0) { 1438*fcf3ce44SJohn Forte (void) printf("%s", sessionList->session[i].alias); 1439*fcf3ce44SJohn Forte } else { 1440*fcf3ce44SJohn Forte (void) printf("-"); 1441*fcf3ce44SJohn Forte } 1442*fcf3ce44SJohn Forte (void) printf("\n"); 1443*fcf3ce44SJohn Forte (void) printf(LVL4_FORMAT, "Logged in since: "); 1444*fcf3ce44SJohn Forte cTime = ctime(&(sessionList->session[i].creationTime)); 1445*fcf3ce44SJohn Forte if (cTime != NULL) { 1446*fcf3ce44SJohn Forte (void) printf("%s", cTime); 1447*fcf3ce44SJohn Forte } else { 1448*fcf3ce44SJohn Forte (void) printf("unknown\n"); 1449*fcf3ce44SJohn Forte } 1450*fcf3ce44SJohn Forte } 1451*fcf3ce44SJohn Forte } 1452*fcf3ce44SJohn Forte 1453*fcf3ce44SJohn Forte /* 1454*fcf3ce44SJohn Forte * listStateFunc 1455*fcf3ce44SJohn Forte * 1456*fcf3ce44SJohn Forte * List the operational and config state of the stmf service 1457*fcf3ce44SJohn Forte * 1458*fcf3ce44SJohn Forte */ 1459*fcf3ce44SJohn Forte /*ARGSUSED*/ 1460*fcf3ce44SJohn Forte static int 1461*fcf3ce44SJohn Forte listStateFunc(int operandLen, char *operands[], cmdOptions_t *options, 1462*fcf3ce44SJohn Forte void *args) 1463*fcf3ce44SJohn Forte { 1464*fcf3ce44SJohn Forte int ret; 1465*fcf3ce44SJohn Forte stmfState state; 1466*fcf3ce44SJohn Forte 1467*fcf3ce44SJohn Forte if ((ret = stmfGetState(&state)) != STMF_STATUS_SUCCESS) { 1468*fcf3ce44SJohn Forte switch (ret) { 1469*fcf3ce44SJohn Forte case STMF_ERROR_PERM: 1470*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 1471*fcf3ce44SJohn Forte gettext("permission denied")); 1472*fcf3ce44SJohn Forte ret++; 1473*fcf3ce44SJohn Forte break; 1474*fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_NOT_FOUND: 1475*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 1476*fcf3ce44SJohn Forte gettext("STMF service not found")); 1477*fcf3ce44SJohn Forte ret++; 1478*fcf3ce44SJohn Forte break; 1479*fcf3ce44SJohn Forte case STMF_ERROR_BUSY: 1480*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 1481*fcf3ce44SJohn Forte gettext("resource busy")); 1482*fcf3ce44SJohn Forte break; 1483*fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_DATA_VERSION: 1484*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 1485*fcf3ce44SJohn Forte gettext("STMF service version incorrect")); 1486*fcf3ce44SJohn Forte ret++; 1487*fcf3ce44SJohn Forte break; 1488*fcf3ce44SJohn Forte default: 1489*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 1490*fcf3ce44SJohn Forte gettext("unknown error")); 1491*fcf3ce44SJohn Forte ret++; 1492*fcf3ce44SJohn Forte break; 1493*fcf3ce44SJohn Forte } 1494*fcf3ce44SJohn Forte return (1); 1495*fcf3ce44SJohn Forte } 1496*fcf3ce44SJohn Forte 1497*fcf3ce44SJohn Forte (void) printf("%-18s: ", "Operational Status"); 1498*fcf3ce44SJohn Forte switch (state.operationalState) { 1499*fcf3ce44SJohn Forte case STMF_SERVICE_STATE_ONLINE: 1500*fcf3ce44SJohn Forte (void) printf("online"); 1501*fcf3ce44SJohn Forte break; 1502*fcf3ce44SJohn Forte case STMF_SERVICE_STATE_OFFLINE: 1503*fcf3ce44SJohn Forte (void) printf("offline"); 1504*fcf3ce44SJohn Forte break; 1505*fcf3ce44SJohn Forte case STMF_SERVICE_STATE_ONLINING: 1506*fcf3ce44SJohn Forte (void) printf("onlining"); 1507*fcf3ce44SJohn Forte break; 1508*fcf3ce44SJohn Forte case STMF_SERVICE_STATE_OFFLINING: 1509*fcf3ce44SJohn Forte (void) printf("offlining"); 1510*fcf3ce44SJohn Forte break; 1511*fcf3ce44SJohn Forte default: 1512*fcf3ce44SJohn Forte (void) printf("unknown"); 1513*fcf3ce44SJohn Forte break; 1514*fcf3ce44SJohn Forte } 1515*fcf3ce44SJohn Forte (void) printf("\n"); 1516*fcf3ce44SJohn Forte (void) printf("%-18s: ", "Config Status"); 1517*fcf3ce44SJohn Forte switch (state.configState) { 1518*fcf3ce44SJohn Forte case STMF_CONFIG_STATE_NONE: 1519*fcf3ce44SJohn Forte (void) printf("uninitialized"); 1520*fcf3ce44SJohn Forte break; 1521*fcf3ce44SJohn Forte case STMF_CONFIG_STATE_INIT: 1522*fcf3ce44SJohn Forte (void) printf("initializing"); 1523*fcf3ce44SJohn Forte break; 1524*fcf3ce44SJohn Forte case STMF_CONFIG_STATE_INIT_DONE: 1525*fcf3ce44SJohn Forte (void) printf("initialized"); 1526*fcf3ce44SJohn Forte break; 1527*fcf3ce44SJohn Forte default: 1528*fcf3ce44SJohn Forte (void) printf("unknown"); 1529*fcf3ce44SJohn Forte break; 1530*fcf3ce44SJohn Forte } 1531*fcf3ce44SJohn Forte (void) printf("\n"); 1532*fcf3ce44SJohn Forte return (0); 1533*fcf3ce44SJohn Forte } 1534*fcf3ce44SJohn Forte 1535*fcf3ce44SJohn Forte /* 1536*fcf3ce44SJohn Forte * listTargetFunc 1537*fcf3ce44SJohn Forte * 1538*fcf3ce44SJohn Forte * list the targets and optionally their properties 1539*fcf3ce44SJohn Forte * 1540*fcf3ce44SJohn Forte */ 1541*fcf3ce44SJohn Forte /*ARGSUSED*/ 1542*fcf3ce44SJohn Forte static int 1543*fcf3ce44SJohn Forte listTargetFunc(int operandLen, char *operands[], cmdOptions_t *options, 1544*fcf3ce44SJohn Forte void *args) 1545*fcf3ce44SJohn Forte { 1546*fcf3ce44SJohn Forte cmdOptions_t *optionList = options; 1547*fcf3ce44SJohn Forte int ret = 0; 1548*fcf3ce44SJohn Forte int stmfRet; 1549*fcf3ce44SJohn Forte int i, j; 1550*fcf3ce44SJohn Forte int outerLoop; 1551*fcf3ce44SJohn Forte stmfSessionList *sessionList; 1552*fcf3ce44SJohn Forte stmfDevid devid; 1553*fcf3ce44SJohn Forte boolean_t operandEntered, found, verbose = B_FALSE; 1554*fcf3ce44SJohn Forte stmfDevidList *targetList; 1555*fcf3ce44SJohn Forte wchar_t targetIdent[STMF_IDENT_LENGTH + 1]; 1556*fcf3ce44SJohn Forte stmfTargetProperties targetProps; 1557*fcf3ce44SJohn Forte 1558*fcf3ce44SJohn Forte if ((stmfRet = stmfGetTargetList(&targetList)) != STMF_STATUS_SUCCESS) { 1559*fcf3ce44SJohn Forte switch (stmfRet) { 1560*fcf3ce44SJohn Forte case STMF_ERROR_NOT_FOUND: 1561*fcf3ce44SJohn Forte ret = 0; 1562*fcf3ce44SJohn Forte break; 1563*fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_OFFLINE: 1564*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 1565*fcf3ce44SJohn Forte gettext("STMF service offline")); 1566*fcf3ce44SJohn Forte break; 1567*fcf3ce44SJohn Forte case STMF_ERROR_BUSY: 1568*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 1569*fcf3ce44SJohn Forte gettext("resource busy")); 1570*fcf3ce44SJohn Forte break; 1571*fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_DATA_VERSION: 1572*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 1573*fcf3ce44SJohn Forte gettext("STMF service version incorrect")); 1574*fcf3ce44SJohn Forte break; 1575*fcf3ce44SJohn Forte case STMF_ERROR_PERM: 1576*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 1577*fcf3ce44SJohn Forte gettext("permission denied")); 1578*fcf3ce44SJohn Forte break; 1579*fcf3ce44SJohn Forte default: 1580*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 1581*fcf3ce44SJohn Forte gettext("unknown error")); 1582*fcf3ce44SJohn Forte break; 1583*fcf3ce44SJohn Forte } 1584*fcf3ce44SJohn Forte return (1); 1585*fcf3ce44SJohn Forte } 1586*fcf3ce44SJohn Forte 1587*fcf3ce44SJohn Forte for (; optionList->optval; optionList++) { 1588*fcf3ce44SJohn Forte switch (optionList->optval) { 1589*fcf3ce44SJohn Forte case 'v': 1590*fcf3ce44SJohn Forte verbose = B_TRUE; 1591*fcf3ce44SJohn Forte break; 1592*fcf3ce44SJohn Forte } 1593*fcf3ce44SJohn Forte } 1594*fcf3ce44SJohn Forte 1595*fcf3ce44SJohn Forte if (operandLen > 0) { 1596*fcf3ce44SJohn Forte outerLoop = operandLen; 1597*fcf3ce44SJohn Forte operandEntered = B_TRUE; 1598*fcf3ce44SJohn Forte } else { 1599*fcf3ce44SJohn Forte outerLoop = 1; 1600*fcf3ce44SJohn Forte operandEntered = B_FALSE; 1601*fcf3ce44SJohn Forte } 1602*fcf3ce44SJohn Forte 1603*fcf3ce44SJohn Forte for (i = 0; i < outerLoop; i++) { 1604*fcf3ce44SJohn Forte if (operandEntered) { 1605*fcf3ce44SJohn Forte bzero(&devid, sizeof (devid)); 1606*fcf3ce44SJohn Forte (void) parseDevid(operands[i], &devid); 1607*fcf3ce44SJohn Forte } 1608*fcf3ce44SJohn Forte for (found = B_FALSE, j = 0; j < targetList->cnt; j++) { 1609*fcf3ce44SJohn Forte if (operandEntered) { 1610*fcf3ce44SJohn Forte if (bcmp(&devid, &(targetList->devid[j]), 1611*fcf3ce44SJohn Forte sizeof (devid)) == 0) { 1612*fcf3ce44SJohn Forte found = B_TRUE; 1613*fcf3ce44SJohn Forte } 1614*fcf3ce44SJohn Forte } 1615*fcf3ce44SJohn Forte if ((found && operandEntered) || !operandEntered) { 1616*fcf3ce44SJohn Forte (void) mbstowcs(targetIdent, 1617*fcf3ce44SJohn Forte (char *)targetList->devid[j].ident, 1618*fcf3ce44SJohn Forte sizeof (targetIdent)); 1619*fcf3ce44SJohn Forte (void) printf("Target: %ws\n", targetIdent); 1620*fcf3ce44SJohn Forte if (verbose) { 1621*fcf3ce44SJohn Forte stmfRet = stmfGetTargetProperties( 1622*fcf3ce44SJohn Forte &(targetList->devid[j]), 1623*fcf3ce44SJohn Forte &targetProps); 1624*fcf3ce44SJohn Forte if (stmfRet == STMF_STATUS_SUCCESS) { 1625*fcf3ce44SJohn Forte printTargetProps(&targetProps); 1626*fcf3ce44SJohn Forte } else { 1627*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s:", 1628*fcf3ce44SJohn Forte cmdName); 1629*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s\n", 1630*fcf3ce44SJohn Forte gettext(" get properties" 1631*fcf3ce44SJohn Forte " failed")); 1632*fcf3ce44SJohn Forte } 1633*fcf3ce44SJohn Forte stmfRet = stmfGetSessionList( 1634*fcf3ce44SJohn Forte &(targetList->devid[j]), 1635*fcf3ce44SJohn Forte &sessionList); 1636*fcf3ce44SJohn Forte if (stmfRet == STMF_STATUS_SUCCESS) { 1637*fcf3ce44SJohn Forte printSessionProps(sessionList); 1638*fcf3ce44SJohn Forte } else { 1639*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s:", 1640*fcf3ce44SJohn Forte cmdName); 1641*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s\n", 1642*fcf3ce44SJohn Forte gettext(" get session info" 1643*fcf3ce44SJohn Forte " failed")); 1644*fcf3ce44SJohn Forte } 1645*fcf3ce44SJohn Forte } 1646*fcf3ce44SJohn Forte if (found && operandEntered) { 1647*fcf3ce44SJohn Forte break; 1648*fcf3ce44SJohn Forte } 1649*fcf3ce44SJohn Forte } 1650*fcf3ce44SJohn Forte 1651*fcf3ce44SJohn Forte } 1652*fcf3ce44SJohn Forte if (operandEntered && !found) { 1653*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 1654*fcf3ce44SJohn Forte operands[i], "not found"); 1655*fcf3ce44SJohn Forte ret = 1; 1656*fcf3ce44SJohn Forte } 1657*fcf3ce44SJohn Forte } 1658*fcf3ce44SJohn Forte return (ret); 1659*fcf3ce44SJohn Forte } 1660*fcf3ce44SJohn Forte 1661*fcf3ce44SJohn Forte /* 1662*fcf3ce44SJohn Forte * listViewFunc 1663*fcf3ce44SJohn Forte * 1664*fcf3ce44SJohn Forte * list the view entries for the specified logical unit 1665*fcf3ce44SJohn Forte * 1666*fcf3ce44SJohn Forte */ 1667*fcf3ce44SJohn Forte /*ARGSUSED*/ 1668*fcf3ce44SJohn Forte static int 1669*fcf3ce44SJohn Forte listViewFunc(int operandLen, char *operands[], cmdOptions_t *options, 1670*fcf3ce44SJohn Forte void *args) 1671*fcf3ce44SJohn Forte { 1672*fcf3ce44SJohn Forte stmfViewEntryList *viewEntryList; 1673*fcf3ce44SJohn Forte stmfGuid inGuid; 1674*fcf3ce44SJohn Forte unsigned int guid[sizeof (stmfGuid)]; 1675*fcf3ce44SJohn Forte int ret = 0; 1676*fcf3ce44SJohn Forte int stmfRet; 1677*fcf3ce44SJohn Forte int i, j, outerLoop; 1678*fcf3ce44SJohn Forte boolean_t found = B_TRUE; 1679*fcf3ce44SJohn Forte boolean_t operandEntered; 1680*fcf3ce44SJohn Forte uint16_t outputLuNbr; 1681*fcf3ce44SJohn Forte wchar_t groupName[sizeof (stmfGroupName)]; 1682*fcf3ce44SJohn Forte char sGuid[GUID_INPUT + 1]; 1683*fcf3ce44SJohn Forte 1684*fcf3ce44SJohn Forte 1685*fcf3ce44SJohn Forte for (; options->optval; options++) { 1686*fcf3ce44SJohn Forte switch (options->optval) { 1687*fcf3ce44SJohn Forte case 'l': 1688*fcf3ce44SJohn Forte if (strlen(options->optarg) != GUID_INPUT) { 1689*fcf3ce44SJohn Forte (void) fprintf(stderr, 1690*fcf3ce44SJohn Forte "%s: %s: %s%d%s\n", 1691*fcf3ce44SJohn Forte cmdName, options->optarg, 1692*fcf3ce44SJohn Forte gettext("must be "), GUID_INPUT, 1693*fcf3ce44SJohn Forte gettext(" hexadecimal digits" 1694*fcf3ce44SJohn Forte " long")); 1695*fcf3ce44SJohn Forte return (1); 1696*fcf3ce44SJohn Forte } 1697*fcf3ce44SJohn Forte bcopy(options->optarg, sGuid, GUID_INPUT); 1698*fcf3ce44SJohn Forte break; 1699*fcf3ce44SJohn Forte default: 1700*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %c: %s\n", 1701*fcf3ce44SJohn Forte cmdName, options->optval, 1702*fcf3ce44SJohn Forte gettext("unknown option")); 1703*fcf3ce44SJohn Forte return (1); 1704*fcf3ce44SJohn Forte } 1705*fcf3ce44SJohn Forte } 1706*fcf3ce44SJohn Forte 1707*fcf3ce44SJohn Forte if (operandLen > 0) { 1708*fcf3ce44SJohn Forte outerLoop = operandLen; 1709*fcf3ce44SJohn Forte operandEntered = B_TRUE; 1710*fcf3ce44SJohn Forte } else { 1711*fcf3ce44SJohn Forte outerLoop = 1; 1712*fcf3ce44SJohn Forte operandEntered = B_FALSE; 1713*fcf3ce44SJohn Forte } 1714*fcf3ce44SJohn Forte 1715*fcf3ce44SJohn Forte for (i = 0; i < 32; i++) 1716*fcf3ce44SJohn Forte sGuid[i] = tolower(sGuid[i]); 1717*fcf3ce44SJohn Forte sGuid[i] = 0; 1718*fcf3ce44SJohn Forte 1719*fcf3ce44SJohn Forte (void) sscanf(sGuid, "%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x", 1720*fcf3ce44SJohn Forte &guid[0], &guid[1], &guid[2], &guid[3], &guid[4], &guid[5], 1721*fcf3ce44SJohn Forte &guid[6], &guid[7], &guid[8], &guid[9], &guid[10], &guid[11], 1722*fcf3ce44SJohn Forte &guid[12], &guid[13], &guid[14], &guid[15]); 1723*fcf3ce44SJohn Forte 1724*fcf3ce44SJohn Forte for (i = 0; i < sizeof (stmfGuid); i++) { 1725*fcf3ce44SJohn Forte inGuid.guid[i] = guid[i]; 1726*fcf3ce44SJohn Forte } 1727*fcf3ce44SJohn Forte 1728*fcf3ce44SJohn Forte if ((stmfRet = stmfGetViewEntryList(&inGuid, &viewEntryList)) 1729*fcf3ce44SJohn Forte != STMF_STATUS_SUCCESS) { 1730*fcf3ce44SJohn Forte 1731*fcf3ce44SJohn Forte switch (stmfRet) { 1732*fcf3ce44SJohn Forte case STMF_ERROR_BUSY: 1733*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 1734*fcf3ce44SJohn Forte sGuid, gettext("resource busy")); 1735*fcf3ce44SJohn Forte break; 1736*fcf3ce44SJohn Forte case STMF_ERROR_NOT_FOUND: 1737*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 1738*fcf3ce44SJohn Forte sGuid, gettext("no views found")); 1739*fcf3ce44SJohn Forte break; 1740*fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_NOT_FOUND: 1741*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 1742*fcf3ce44SJohn Forte gettext("STMF service not found")); 1743*fcf3ce44SJohn Forte break; 1744*fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_DATA_VERSION: 1745*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 1746*fcf3ce44SJohn Forte gettext("STMF service version incorrect")); 1747*fcf3ce44SJohn Forte break; 1748*fcf3ce44SJohn Forte case STMF_ERROR_PERM: 1749*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 1750*fcf3ce44SJohn Forte gettext("permission denied")); 1751*fcf3ce44SJohn Forte break; 1752*fcf3ce44SJohn Forte default: 1753*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 1754*fcf3ce44SJohn Forte sGuid, gettext("unknown error")); 1755*fcf3ce44SJohn Forte break; 1756*fcf3ce44SJohn Forte } 1757*fcf3ce44SJohn Forte return (1); 1758*fcf3ce44SJohn Forte } 1759*fcf3ce44SJohn Forte 1760*fcf3ce44SJohn Forte for (i = 0; i < outerLoop; i++) { 1761*fcf3ce44SJohn Forte for (found = B_FALSE, j = 0; j < viewEntryList->cnt; j++) { 1762*fcf3ce44SJohn Forte if (operandEntered) { 1763*fcf3ce44SJohn Forte if (atoi(operands[i]) == 1764*fcf3ce44SJohn Forte viewEntryList->ve[j].veIndex) { 1765*fcf3ce44SJohn Forte found = B_TRUE; 1766*fcf3ce44SJohn Forte } 1767*fcf3ce44SJohn Forte } 1768*fcf3ce44SJohn Forte if ((found && operandEntered) || !operandEntered) { 1769*fcf3ce44SJohn Forte (void) printf("View Entry: %d\n", 1770*fcf3ce44SJohn Forte viewEntryList->ve[j].veIndex); 1771*fcf3ce44SJohn Forte (void) printf(VIEW_FORMAT, "Host group"); 1772*fcf3ce44SJohn Forte if (viewEntryList->ve[j].allHosts) { 1773*fcf3ce44SJohn Forte (void) printf("All\n"); 1774*fcf3ce44SJohn Forte } else { 1775*fcf3ce44SJohn Forte (void) mbstowcs(groupName, 1776*fcf3ce44SJohn Forte viewEntryList->ve[j].hostGroup, 1777*fcf3ce44SJohn Forte sizeof (groupName)); 1778*fcf3ce44SJohn Forte (void) printf("%ws\n", groupName); 1779*fcf3ce44SJohn Forte } 1780*fcf3ce44SJohn Forte (void) printf(VIEW_FORMAT, "Target group"); 1781*fcf3ce44SJohn Forte if (viewEntryList->ve[j].allTargets) { 1782*fcf3ce44SJohn Forte (void) printf("All\n"); 1783*fcf3ce44SJohn Forte } else { 1784*fcf3ce44SJohn Forte (void) mbstowcs(groupName, 1785*fcf3ce44SJohn Forte viewEntryList->ve[j].targetGroup, 1786*fcf3ce44SJohn Forte sizeof (groupName)); 1787*fcf3ce44SJohn Forte (void) printf("%ws\n", groupName); 1788*fcf3ce44SJohn Forte } 1789*fcf3ce44SJohn Forte outputLuNbr = ((viewEntryList->ve[j].luNbr[0] & 1790*fcf3ce44SJohn Forte 0x3F) << 8) | viewEntryList->ve[j].luNbr[1]; 1791*fcf3ce44SJohn Forte (void) printf(VIEW_FORMAT, "LUN"); 1792*fcf3ce44SJohn Forte (void) printf("%d\n", outputLuNbr); 1793*fcf3ce44SJohn Forte if (found && operandEntered) { 1794*fcf3ce44SJohn Forte break; 1795*fcf3ce44SJohn Forte } 1796*fcf3ce44SJohn Forte } 1797*fcf3ce44SJohn Forte } 1798*fcf3ce44SJohn Forte if (operandEntered && !found) { 1799*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s, %s: %s\n", cmdName, 1800*fcf3ce44SJohn Forte sGuid, operands[i], gettext("not found")); 1801*fcf3ce44SJohn Forte ret = 1; 1802*fcf3ce44SJohn Forte } 1803*fcf3ce44SJohn Forte } 1804*fcf3ce44SJohn Forte 1805*fcf3ce44SJohn Forte return (ret); 1806*fcf3ce44SJohn Forte } 1807*fcf3ce44SJohn Forte 1808*fcf3ce44SJohn Forte 1809*fcf3ce44SJohn Forte /* 1810*fcf3ce44SJohn Forte * onlineOfflineLu 1811*fcf3ce44SJohn Forte * 1812*fcf3ce44SJohn Forte * Purpose: Online or offline a logical unit 1813*fcf3ce44SJohn Forte * 1814*fcf3ce44SJohn Forte * lu - logical unit to online or offline 1815*fcf3ce44SJohn Forte * 1816*fcf3ce44SJohn Forte * state - ONLINE_LU 1817*fcf3ce44SJohn Forte * OFFLINE_LU 1818*fcf3ce44SJohn Forte */ 1819*fcf3ce44SJohn Forte static int 1820*fcf3ce44SJohn Forte onlineOfflineLu(char *lu, int state) 1821*fcf3ce44SJohn Forte { 1822*fcf3ce44SJohn Forte char sGuid[GUID_INPUT + 1]; 1823*fcf3ce44SJohn Forte stmfGuid inGuid; 1824*fcf3ce44SJohn Forte unsigned int guid[sizeof (stmfGuid)]; 1825*fcf3ce44SJohn Forte int i; 1826*fcf3ce44SJohn Forte int ret = 0; 1827*fcf3ce44SJohn Forte 1828*fcf3ce44SJohn Forte if (strlen(lu) != GUID_INPUT) { 1829*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s %d %s\n", cmdName, lu, 1830*fcf3ce44SJohn Forte gettext("must be"), GUID_INPUT, 1831*fcf3ce44SJohn Forte gettext("hexadecimal digits long")); 1832*fcf3ce44SJohn Forte return (1); 1833*fcf3ce44SJohn Forte } 1834*fcf3ce44SJohn Forte 1835*fcf3ce44SJohn Forte bcopy(lu, sGuid, GUID_INPUT); 1836*fcf3ce44SJohn Forte 1837*fcf3ce44SJohn Forte for (i = 0; i < 32; i++) 1838*fcf3ce44SJohn Forte sGuid[i] = tolower(sGuid[i]); 1839*fcf3ce44SJohn Forte sGuid[i] = 0; 1840*fcf3ce44SJohn Forte 1841*fcf3ce44SJohn Forte (void) sscanf(sGuid, "%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x", 1842*fcf3ce44SJohn Forte &guid[0], &guid[1], &guid[2], &guid[3], &guid[4], &guid[5], 1843*fcf3ce44SJohn Forte &guid[6], &guid[7], &guid[8], &guid[9], &guid[10], &guid[11], 1844*fcf3ce44SJohn Forte &guid[12], &guid[13], &guid[14], &guid[15]); 1845*fcf3ce44SJohn Forte 1846*fcf3ce44SJohn Forte for (i = 0; i < sizeof (stmfGuid); i++) { 1847*fcf3ce44SJohn Forte inGuid.guid[i] = guid[i]; 1848*fcf3ce44SJohn Forte } 1849*fcf3ce44SJohn Forte 1850*fcf3ce44SJohn Forte if (state == ONLINE_LU) { 1851*fcf3ce44SJohn Forte ret = stmfOnlineLogicalUnit(&inGuid); 1852*fcf3ce44SJohn Forte } else if (state == OFFLINE_LU) { 1853*fcf3ce44SJohn Forte ret = stmfOfflineLogicalUnit(&inGuid); 1854*fcf3ce44SJohn Forte } 1855*fcf3ce44SJohn Forte if (ret != STMF_STATUS_SUCCESS) { 1856*fcf3ce44SJohn Forte switch (ret) { 1857*fcf3ce44SJohn Forte case STMF_ERROR_PERM: 1858*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 1859*fcf3ce44SJohn Forte gettext("permission denied")); 1860*fcf3ce44SJohn Forte break; 1861*fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_NOT_FOUND: 1862*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 1863*fcf3ce44SJohn Forte gettext("STMF service not found")); 1864*fcf3ce44SJohn Forte break; 1865*fcf3ce44SJohn Forte case STMF_ERROR_NOT_FOUND: 1866*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 1867*fcf3ce44SJohn Forte lu, gettext("not found")); 1868*fcf3ce44SJohn Forte break; 1869*fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_DATA_VERSION: 1870*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 1871*fcf3ce44SJohn Forte gettext("STMF service version incorrect")); 1872*fcf3ce44SJohn Forte break; 1873*fcf3ce44SJohn Forte default: 1874*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 1875*fcf3ce44SJohn Forte gettext("unknown error")); 1876*fcf3ce44SJohn Forte break; 1877*fcf3ce44SJohn Forte } 1878*fcf3ce44SJohn Forte } 1879*fcf3ce44SJohn Forte return (ret); 1880*fcf3ce44SJohn Forte } 1881*fcf3ce44SJohn Forte 1882*fcf3ce44SJohn Forte /* 1883*fcf3ce44SJohn Forte * onlineLuFunc 1884*fcf3ce44SJohn Forte * 1885*fcf3ce44SJohn Forte * Purpose: Online a logical unit 1886*fcf3ce44SJohn Forte * 1887*fcf3ce44SJohn Forte */ 1888*fcf3ce44SJohn Forte /*ARGSUSED*/ 1889*fcf3ce44SJohn Forte static int 1890*fcf3ce44SJohn Forte onlineLuFunc(int operandLen, char *operands[], cmdOptions_t *options, 1891*fcf3ce44SJohn Forte void *args) 1892*fcf3ce44SJohn Forte { 1893*fcf3ce44SJohn Forte return (onlineOfflineLu(operands[0], ONLINE_LU)); 1894*fcf3ce44SJohn Forte } 1895*fcf3ce44SJohn Forte 1896*fcf3ce44SJohn Forte /* 1897*fcf3ce44SJohn Forte * offlineLuFunc 1898*fcf3ce44SJohn Forte * 1899*fcf3ce44SJohn Forte * Purpose: Offline a logical unit 1900*fcf3ce44SJohn Forte * 1901*fcf3ce44SJohn Forte */ 1902*fcf3ce44SJohn Forte /*ARGSUSED*/ 1903*fcf3ce44SJohn Forte static int 1904*fcf3ce44SJohn Forte offlineLuFunc(int operandLen, char *operands[], cmdOptions_t *options, 1905*fcf3ce44SJohn Forte void *args) 1906*fcf3ce44SJohn Forte { 1907*fcf3ce44SJohn Forte return (onlineOfflineLu(operands[0], OFFLINE_LU)); 1908*fcf3ce44SJohn Forte } 1909*fcf3ce44SJohn Forte 1910*fcf3ce44SJohn Forte /* 1911*fcf3ce44SJohn Forte * onlineOfflineTarget 1912*fcf3ce44SJohn Forte * 1913*fcf3ce44SJohn Forte * Purpose: Online or offline a target 1914*fcf3ce44SJohn Forte * 1915*fcf3ce44SJohn Forte * target - target to online or offline 1916*fcf3ce44SJohn Forte * 1917*fcf3ce44SJohn Forte * state - ONLINE_TARGET 1918*fcf3ce44SJohn Forte * OFFLINE_TARGET 1919*fcf3ce44SJohn Forte */ 1920*fcf3ce44SJohn Forte static int 1921*fcf3ce44SJohn Forte onlineOfflineTarget(char *target, int state) 1922*fcf3ce44SJohn Forte { 1923*fcf3ce44SJohn Forte int ret = 0; 1924*fcf3ce44SJohn Forte stmfDevid devid; 1925*fcf3ce44SJohn Forte 1926*fcf3ce44SJohn Forte if (parseDevid(target, &devid) != 0) { 1927*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", 1928*fcf3ce44SJohn Forte cmdName, target, gettext("unrecognized device id")); 1929*fcf3ce44SJohn Forte return (1); 1930*fcf3ce44SJohn Forte } 1931*fcf3ce44SJohn Forte if (state == ONLINE_TARGET) { 1932*fcf3ce44SJohn Forte ret = stmfOnlineTarget(&devid); 1933*fcf3ce44SJohn Forte } else if (state == OFFLINE_TARGET) { 1934*fcf3ce44SJohn Forte ret = stmfOfflineTarget(&devid); 1935*fcf3ce44SJohn Forte } 1936*fcf3ce44SJohn Forte if (ret != STMF_STATUS_SUCCESS) { 1937*fcf3ce44SJohn Forte switch (ret) { 1938*fcf3ce44SJohn Forte case STMF_ERROR_PERM: 1939*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 1940*fcf3ce44SJohn Forte gettext("permission denied")); 1941*fcf3ce44SJohn Forte break; 1942*fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_NOT_FOUND: 1943*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 1944*fcf3ce44SJohn Forte gettext("STMF service not found")); 1945*fcf3ce44SJohn Forte break; 1946*fcf3ce44SJohn Forte case STMF_ERROR_NOT_FOUND: 1947*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 1948*fcf3ce44SJohn Forte target, gettext("not found")); 1949*fcf3ce44SJohn Forte break; 1950*fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_DATA_VERSION: 1951*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 1952*fcf3ce44SJohn Forte gettext("STMF service version incorrect")); 1953*fcf3ce44SJohn Forte break; 1954*fcf3ce44SJohn Forte default: 1955*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 1956*fcf3ce44SJohn Forte gettext("unknown error")); 1957*fcf3ce44SJohn Forte break; 1958*fcf3ce44SJohn Forte } 1959*fcf3ce44SJohn Forte } 1960*fcf3ce44SJohn Forte return (ret); 1961*fcf3ce44SJohn Forte } 1962*fcf3ce44SJohn Forte 1963*fcf3ce44SJohn Forte /* 1964*fcf3ce44SJohn Forte * onlineTargetFunc 1965*fcf3ce44SJohn Forte * 1966*fcf3ce44SJohn Forte * Purpose: Online a target 1967*fcf3ce44SJohn Forte * 1968*fcf3ce44SJohn Forte */ 1969*fcf3ce44SJohn Forte /*ARGSUSED*/ 1970*fcf3ce44SJohn Forte static int 1971*fcf3ce44SJohn Forte onlineTargetFunc(int operandLen, char *operands[], cmdOptions_t *options, 1972*fcf3ce44SJohn Forte void *args) 1973*fcf3ce44SJohn Forte { 1974*fcf3ce44SJohn Forte return (onlineOfflineTarget(operands[0], ONLINE_TARGET)); 1975*fcf3ce44SJohn Forte } 1976*fcf3ce44SJohn Forte 1977*fcf3ce44SJohn Forte /* 1978*fcf3ce44SJohn Forte * offlineTargetFunc 1979*fcf3ce44SJohn Forte * 1980*fcf3ce44SJohn Forte * Purpose: Offline a target 1981*fcf3ce44SJohn Forte * 1982*fcf3ce44SJohn Forte */ 1983*fcf3ce44SJohn Forte /*ARGSUSED*/ 1984*fcf3ce44SJohn Forte static int 1985*fcf3ce44SJohn Forte offlineTargetFunc(int operandLen, char *operands[], cmdOptions_t *options, 1986*fcf3ce44SJohn Forte void *args) 1987*fcf3ce44SJohn Forte { 1988*fcf3ce44SJohn Forte return (onlineOfflineTarget(operands[0], OFFLINE_TARGET)); 1989*fcf3ce44SJohn Forte } 1990*fcf3ce44SJohn Forte 1991*fcf3ce44SJohn Forte 1992*fcf3ce44SJohn Forte /*ARGSUSED*/ 1993*fcf3ce44SJohn Forte static int 1994*fcf3ce44SJohn Forte removeHostGroupMemberFunc(int operandLen, char *operands[], 1995*fcf3ce44SJohn Forte cmdOptions_t *options, void *args) 1996*fcf3ce44SJohn Forte { 1997*fcf3ce44SJohn Forte int i; 1998*fcf3ce44SJohn Forte int ret = 0; 1999*fcf3ce44SJohn Forte int stmfRet; 2000*fcf3ce44SJohn Forte stmfGroupName groupName; 2001*fcf3ce44SJohn Forte stmfDevid devid; 2002*fcf3ce44SJohn Forte wchar_t groupNamePrint[sizeof (stmfGroupName)]; 2003*fcf3ce44SJohn Forte 2004*fcf3ce44SJohn Forte for (; options->optval; options++) { 2005*fcf3ce44SJohn Forte switch (options->optval) { 2006*fcf3ce44SJohn Forte case 'g': 2007*fcf3ce44SJohn Forte (void) mbstowcs(groupNamePrint, options->optarg, 2008*fcf3ce44SJohn Forte sizeof (groupNamePrint)); 2009*fcf3ce44SJohn Forte bzero(groupName, sizeof (groupName)); 2010*fcf3ce44SJohn Forte bcopy(options->optarg, groupName, 2011*fcf3ce44SJohn Forte strlen(options->optarg)); 2012*fcf3ce44SJohn Forte break; 2013*fcf3ce44SJohn Forte default: 2014*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %c: %s\n", 2015*fcf3ce44SJohn Forte cmdName, options->optval, 2016*fcf3ce44SJohn Forte gettext("unknown option")); 2017*fcf3ce44SJohn Forte return (1); 2018*fcf3ce44SJohn Forte } 2019*fcf3ce44SJohn Forte } 2020*fcf3ce44SJohn Forte 2021*fcf3ce44SJohn Forte for (i = 0; i < operandLen; i++) { 2022*fcf3ce44SJohn Forte if (parseDevid(operands[i], &devid) != 0) { 2023*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", 2024*fcf3ce44SJohn Forte cmdName, operands[i], 2025*fcf3ce44SJohn Forte gettext("unrecognized device id")); 2026*fcf3ce44SJohn Forte ret++; 2027*fcf3ce44SJohn Forte continue; 2028*fcf3ce44SJohn Forte } 2029*fcf3ce44SJohn Forte stmfRet = stmfRemoveFromHostGroup(&groupName, &devid); 2030*fcf3ce44SJohn Forte switch (stmfRet) { 2031*fcf3ce44SJohn Forte case STMF_STATUS_SUCCESS: 2032*fcf3ce44SJohn Forte break; 2033*fcf3ce44SJohn Forte case STMF_ERROR_MEMBER_NOT_FOUND: 2034*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 2035*fcf3ce44SJohn Forte operands[i], gettext("not found")); 2036*fcf3ce44SJohn Forte ret++; 2037*fcf3ce44SJohn Forte break; 2038*fcf3ce44SJohn Forte case STMF_ERROR_GROUP_NOT_FOUND: 2039*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %ws: %s\n", cmdName, 2040*fcf3ce44SJohn Forte groupNamePrint, gettext("not found")); 2041*fcf3ce44SJohn Forte ret++; 2042*fcf3ce44SJohn Forte break; 2043*fcf3ce44SJohn Forte case STMF_ERROR_BUSY: 2044*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 2045*fcf3ce44SJohn Forte operands[i], "resource busy"); 2046*fcf3ce44SJohn Forte ret++; 2047*fcf3ce44SJohn Forte break; 2048*fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_NOT_FOUND: 2049*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 2050*fcf3ce44SJohn Forte gettext("STMF service not found")); 2051*fcf3ce44SJohn Forte ret++; 2052*fcf3ce44SJohn Forte break; 2053*fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_DATA_VERSION: 2054*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 2055*fcf3ce44SJohn Forte gettext("STMF service version incorrect")); 2056*fcf3ce44SJohn Forte ret++; 2057*fcf3ce44SJohn Forte break; 2058*fcf3ce44SJohn Forte case STMF_ERROR_PERM: 2059*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 2060*fcf3ce44SJohn Forte gettext("permission denied")); 2061*fcf3ce44SJohn Forte ret++; 2062*fcf3ce44SJohn Forte break; 2063*fcf3ce44SJohn Forte default: 2064*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 2065*fcf3ce44SJohn Forte operands[i], gettext("unknown error")); 2066*fcf3ce44SJohn Forte ret++; 2067*fcf3ce44SJohn Forte break; 2068*fcf3ce44SJohn Forte } 2069*fcf3ce44SJohn Forte } 2070*fcf3ce44SJohn Forte 2071*fcf3ce44SJohn Forte return (ret); 2072*fcf3ce44SJohn Forte } 2073*fcf3ce44SJohn Forte 2074*fcf3ce44SJohn Forte /* 2075*fcf3ce44SJohn Forte * removeTargetGroupMemberFunc 2076*fcf3ce44SJohn Forte * 2077*fcf3ce44SJohn Forte * Removes one or more members from a target group 2078*fcf3ce44SJohn Forte * 2079*fcf3ce44SJohn Forte */ 2080*fcf3ce44SJohn Forte /*ARGSUSED*/ 2081*fcf3ce44SJohn Forte static int 2082*fcf3ce44SJohn Forte removeTargetGroupMemberFunc(int operandLen, char *operands[], 2083*fcf3ce44SJohn Forte cmdOptions_t *options, void *args) 2084*fcf3ce44SJohn Forte { 2085*fcf3ce44SJohn Forte int i; 2086*fcf3ce44SJohn Forte int ret = 0; 2087*fcf3ce44SJohn Forte int stmfRet; 2088*fcf3ce44SJohn Forte stmfGroupName groupName; 2089*fcf3ce44SJohn Forte stmfDevid devid; 2090*fcf3ce44SJohn Forte wchar_t groupNamePrint[sizeof (stmfGroupName)]; 2091*fcf3ce44SJohn Forte 2092*fcf3ce44SJohn Forte for (; options->optval; options++) { 2093*fcf3ce44SJohn Forte switch (options->optval) { 2094*fcf3ce44SJohn Forte case 'g': 2095*fcf3ce44SJohn Forte (void) mbstowcs(groupNamePrint, options->optarg, 2096*fcf3ce44SJohn Forte sizeof (groupNamePrint)); 2097*fcf3ce44SJohn Forte bzero(groupName, sizeof (groupName)); 2098*fcf3ce44SJohn Forte bcopy(options->optarg, groupName, 2099*fcf3ce44SJohn Forte strlen(options->optarg)); 2100*fcf3ce44SJohn Forte break; 2101*fcf3ce44SJohn Forte default: 2102*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %c: %s\n", 2103*fcf3ce44SJohn Forte cmdName, options->optval, 2104*fcf3ce44SJohn Forte gettext("unknown option")); 2105*fcf3ce44SJohn Forte return (1); 2106*fcf3ce44SJohn Forte } 2107*fcf3ce44SJohn Forte } 2108*fcf3ce44SJohn Forte 2109*fcf3ce44SJohn Forte for (i = 0; i < operandLen; i++) { 2110*fcf3ce44SJohn Forte if (parseDevid(operands[i], &devid) != 0) { 2111*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", 2112*fcf3ce44SJohn Forte cmdName, operands[i], 2113*fcf3ce44SJohn Forte gettext("unrecognized device id")); 2114*fcf3ce44SJohn Forte ret++; 2115*fcf3ce44SJohn Forte continue; 2116*fcf3ce44SJohn Forte } 2117*fcf3ce44SJohn Forte stmfRet = stmfRemoveFromTargetGroup(&groupName, &devid); 2118*fcf3ce44SJohn Forte switch (stmfRet) { 2119*fcf3ce44SJohn Forte case STMF_STATUS_SUCCESS: 2120*fcf3ce44SJohn Forte break; 2121*fcf3ce44SJohn Forte case STMF_ERROR_MEMBER_NOT_FOUND: 2122*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 2123*fcf3ce44SJohn Forte operands[i], gettext("not found")); 2124*fcf3ce44SJohn Forte ret++; 2125*fcf3ce44SJohn Forte break; 2126*fcf3ce44SJohn Forte case STMF_ERROR_GROUP_NOT_FOUND: 2127*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %ws: %s\n", cmdName, 2128*fcf3ce44SJohn Forte groupNamePrint, gettext("not found")); 2129*fcf3ce44SJohn Forte ret++; 2130*fcf3ce44SJohn Forte break; 2131*fcf3ce44SJohn Forte case STMF_ERROR_BUSY: 2132*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 2133*fcf3ce44SJohn Forte operands[i], gettext("resource busy")); 2134*fcf3ce44SJohn Forte ret++; 2135*fcf3ce44SJohn Forte break; 2136*fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_NOT_FOUND: 2137*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 2138*fcf3ce44SJohn Forte gettext("STMF service not found")); 2139*fcf3ce44SJohn Forte ret++; 2140*fcf3ce44SJohn Forte break; 2141*fcf3ce44SJohn Forte case STMF_ERROR_PERM: 2142*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 2143*fcf3ce44SJohn Forte gettext("permission denied")); 2144*fcf3ce44SJohn Forte ret++; 2145*fcf3ce44SJohn Forte break; 2146*fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_DATA_VERSION: 2147*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 2148*fcf3ce44SJohn Forte gettext("STMF service version incorrect")); 2149*fcf3ce44SJohn Forte ret++; 2150*fcf3ce44SJohn Forte break; 2151*fcf3ce44SJohn Forte default: 2152*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 2153*fcf3ce44SJohn Forte operands[i], gettext("unknown error")); 2154*fcf3ce44SJohn Forte ret++; 2155*fcf3ce44SJohn Forte break; 2156*fcf3ce44SJohn Forte } 2157*fcf3ce44SJohn Forte } 2158*fcf3ce44SJohn Forte 2159*fcf3ce44SJohn Forte return (ret); 2160*fcf3ce44SJohn Forte } 2161*fcf3ce44SJohn Forte 2162*fcf3ce44SJohn Forte /* 2163*fcf3ce44SJohn Forte * removeViewFunc 2164*fcf3ce44SJohn Forte * 2165*fcf3ce44SJohn Forte * Removes one or more view entries from a logical unit 2166*fcf3ce44SJohn Forte * 2167*fcf3ce44SJohn Forte */ 2168*fcf3ce44SJohn Forte /*ARGSUSED*/ 2169*fcf3ce44SJohn Forte static int 2170*fcf3ce44SJohn Forte removeViewFunc(int operandLen, char *operands[], cmdOptions_t *options, 2171*fcf3ce44SJohn Forte void *args) 2172*fcf3ce44SJohn Forte { 2173*fcf3ce44SJohn Forte char sGuid[GUID_INPUT + 1]; 2174*fcf3ce44SJohn Forte stmfViewEntryList *viewEntryList; 2175*fcf3ce44SJohn Forte stmfGuid inGuid; 2176*fcf3ce44SJohn Forte uint32_t count; 2177*fcf3ce44SJohn Forte unsigned int guid[sizeof (stmfGuid)]; 2178*fcf3ce44SJohn Forte char *endPtr; 2179*fcf3ce44SJohn Forte uint32_t veNbr; 2180*fcf3ce44SJohn Forte int i; 2181*fcf3ce44SJohn Forte boolean_t all = B_FALSE; 2182*fcf3ce44SJohn Forte boolean_t luInput = B_FALSE; 2183*fcf3ce44SJohn Forte int ret = 0; 2184*fcf3ce44SJohn Forte int stmfRet; 2185*fcf3ce44SJohn Forte 2186*fcf3ce44SJohn Forte /* Note: 'l' is required */ 2187*fcf3ce44SJohn Forte for (; options->optval; options++) { 2188*fcf3ce44SJohn Forte switch (options->optval) { 2189*fcf3ce44SJohn Forte case 'l': 2190*fcf3ce44SJohn Forte if (strlen(options->optarg) != GUID_INPUT) { 2191*fcf3ce44SJohn Forte (void) fprintf(stderr, 2192*fcf3ce44SJohn Forte "%s: %s: %s %d %s\n", 2193*fcf3ce44SJohn Forte cmdName, options->optarg, 2194*fcf3ce44SJohn Forte gettext("must be"), GUID_INPUT, 2195*fcf3ce44SJohn Forte gettext("hexadecimal digits long")); 2196*fcf3ce44SJohn Forte return (1); 2197*fcf3ce44SJohn Forte } 2198*fcf3ce44SJohn Forte bcopy(options->optarg, sGuid, GUID_INPUT); 2199*fcf3ce44SJohn Forte luInput = B_TRUE; 2200*fcf3ce44SJohn Forte break; 2201*fcf3ce44SJohn Forte case 'a': 2202*fcf3ce44SJohn Forte /* removing all view entries for this GUID */ 2203*fcf3ce44SJohn Forte all = B_TRUE; 2204*fcf3ce44SJohn Forte break; 2205*fcf3ce44SJohn Forte default: 2206*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %c: %s\n", 2207*fcf3ce44SJohn Forte cmdName, options->optval, 2208*fcf3ce44SJohn Forte "unknown option"); 2209*fcf3ce44SJohn Forte return (1); 2210*fcf3ce44SJohn Forte } 2211*fcf3ce44SJohn Forte } 2212*fcf3ce44SJohn Forte 2213*fcf3ce44SJohn Forte if (!all && operandLen == 0) { 2214*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 2215*fcf3ce44SJohn Forte gettext("no view entries specified")); 2216*fcf3ce44SJohn Forte return (1); 2217*fcf3ce44SJohn Forte } 2218*fcf3ce44SJohn Forte 2219*fcf3ce44SJohn Forte if (!luInput) { 2220*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 2221*fcf3ce44SJohn Forte gettext("logical unit (-l) not specified")); 2222*fcf3ce44SJohn Forte return (1); 2223*fcf3ce44SJohn Forte } 2224*fcf3ce44SJohn Forte 2225*fcf3ce44SJohn Forte for (i = 0; i < 32; i++) 2226*fcf3ce44SJohn Forte sGuid[i] = tolower(sGuid[i]); 2227*fcf3ce44SJohn Forte sGuid[i] = 0; 2228*fcf3ce44SJohn Forte 2229*fcf3ce44SJohn Forte (void) sscanf(sGuid, "%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x", 2230*fcf3ce44SJohn Forte &guid[0], &guid[1], &guid[2], &guid[3], &guid[4], &guid[5], 2231*fcf3ce44SJohn Forte &guid[6], &guid[7], &guid[8], &guid[9], &guid[10], &guid[11], 2232*fcf3ce44SJohn Forte &guid[12], &guid[13], &guid[14], &guid[15]); 2233*fcf3ce44SJohn Forte 2234*fcf3ce44SJohn Forte for (i = 0; i < sizeof (stmfGuid); i++) { 2235*fcf3ce44SJohn Forte inGuid.guid[i] = guid[i]; 2236*fcf3ce44SJohn Forte } 2237*fcf3ce44SJohn Forte 2238*fcf3ce44SJohn Forte if ((stmfRet = stmfGetViewEntryList(&inGuid, &viewEntryList)) 2239*fcf3ce44SJohn Forte != STMF_STATUS_SUCCESS) { 2240*fcf3ce44SJohn Forte 2241*fcf3ce44SJohn Forte switch (stmfRet) { 2242*fcf3ce44SJohn Forte case STMF_ERROR_BUSY: 2243*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 2244*fcf3ce44SJohn Forte sGuid, gettext("resource busy")); 2245*fcf3ce44SJohn Forte break; 2246*fcf3ce44SJohn Forte case STMF_ERROR_NOT_FOUND: 2247*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 2248*fcf3ce44SJohn Forte sGuid, gettext("no views found")); 2249*fcf3ce44SJohn Forte break; 2250*fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_NOT_FOUND: 2251*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 2252*fcf3ce44SJohn Forte gettext("STMF service not found")); 2253*fcf3ce44SJohn Forte break; 2254*fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_DATA_VERSION: 2255*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 2256*fcf3ce44SJohn Forte gettext("STMF service version incorrect")); 2257*fcf3ce44SJohn Forte break; 2258*fcf3ce44SJohn Forte case STMF_ERROR_PERM: 2259*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 2260*fcf3ce44SJohn Forte gettext("permission denied")); 2261*fcf3ce44SJohn Forte break; 2262*fcf3ce44SJohn Forte default: 2263*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 2264*fcf3ce44SJohn Forte sGuid, gettext("unknown error")); 2265*fcf3ce44SJohn Forte break; 2266*fcf3ce44SJohn Forte } 2267*fcf3ce44SJohn Forte return (1); 2268*fcf3ce44SJohn Forte } 2269*fcf3ce44SJohn Forte 2270*fcf3ce44SJohn Forte if (all) { 2271*fcf3ce44SJohn Forte count = viewEntryList->cnt; 2272*fcf3ce44SJohn Forte } else { 2273*fcf3ce44SJohn Forte count = operandLen; 2274*fcf3ce44SJohn Forte } 2275*fcf3ce44SJohn Forte 2276*fcf3ce44SJohn Forte for (i = 0; i < count; i++) { 2277*fcf3ce44SJohn Forte if (all) { 2278*fcf3ce44SJohn Forte veNbr = viewEntryList->ve[i].veIndex; 2279*fcf3ce44SJohn Forte } else { 2280*fcf3ce44SJohn Forte endPtr = NULL; 2281*fcf3ce44SJohn Forte veNbr = strtol(operands[i], &endPtr, 10); 2282*fcf3ce44SJohn Forte if (endPtr && *endPtr != 0) { 2283*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 2284*fcf3ce44SJohn Forte operands[i], gettext("invalid input")); 2285*fcf3ce44SJohn Forte continue; 2286*fcf3ce44SJohn Forte } 2287*fcf3ce44SJohn Forte } 2288*fcf3ce44SJohn Forte stmfRet = stmfRemoveViewEntry(&inGuid, veNbr); 2289*fcf3ce44SJohn Forte switch (stmfRet) { 2290*fcf3ce44SJohn Forte case STMF_STATUS_SUCCESS: 2291*fcf3ce44SJohn Forte break; 2292*fcf3ce44SJohn Forte case STMF_ERROR_NOT_FOUND: 2293*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %d: %s\n", 2294*fcf3ce44SJohn Forte cmdName, sGuid, veNbr, 2295*fcf3ce44SJohn Forte gettext("not found")); 2296*fcf3ce44SJohn Forte ret++; 2297*fcf3ce44SJohn Forte break; 2298*fcf3ce44SJohn Forte case STMF_ERROR_BUSY: 2299*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 2300*fcf3ce44SJohn Forte sGuid, gettext("resource busy")); 2301*fcf3ce44SJohn Forte ret++; 2302*fcf3ce44SJohn Forte break; 2303*fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_NOT_FOUND: 2304*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 2305*fcf3ce44SJohn Forte gettext("STMF service not found")); 2306*fcf3ce44SJohn Forte ret++; 2307*fcf3ce44SJohn Forte break; 2308*fcf3ce44SJohn Forte case STMF_ERROR_CONFIG_NONE: 2309*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 2310*fcf3ce44SJohn Forte gettext("STMF service is not initialized")); 2311*fcf3ce44SJohn Forte ret++; 2312*fcf3ce44SJohn Forte break; 2313*fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_DATA_VERSION: 2314*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 2315*fcf3ce44SJohn Forte gettext("STMF service version incorrect")); 2316*fcf3ce44SJohn Forte ret++; 2317*fcf3ce44SJohn Forte break; 2318*fcf3ce44SJohn Forte default: 2319*fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s, %d: %s", 2320*fcf3ce44SJohn Forte cmdName, sGuid, veNbr, 2321*fcf3ce44SJohn Forte gettext("unknown error")); 2322*fcf3ce44SJohn Forte ret++; 2323*fcf3ce44SJohn Forte break; 2324*fcf3ce44SJohn Forte } 2325*fcf3ce44SJohn Forte } 2326*fcf3ce44SJohn Forte 2327*fcf3ce44SJohn Forte return (ret); 2328*fcf3ce44SJohn Forte } 2329*fcf3ce44SJohn Forte 2330*fcf3ce44SJohn Forte /* 2331*fcf3ce44SJohn Forte * input: 2332*fcf3ce44SJohn Forte * execFullName - exec name of program (argv[0]) 2333*fcf3ce44SJohn Forte * 2334*fcf3ce44SJohn Forte * copied from usr/src/cmd/zoneadm/zoneadm.c in OS/Net 2335*fcf3ce44SJohn Forte * (changed name to lowerCamelCase to keep consistent with this file) 2336*fcf3ce44SJohn Forte * 2337*fcf3ce44SJohn Forte * Returns: 2338*fcf3ce44SJohn Forte * command name portion of execFullName 2339*fcf3ce44SJohn Forte */ 2340*fcf3ce44SJohn Forte static char * 2341*fcf3ce44SJohn Forte getExecBasename(char *execFullname) 2342*fcf3ce44SJohn Forte { 2343*fcf3ce44SJohn Forte char *lastSlash, *execBasename; 2344*fcf3ce44SJohn Forte 2345*fcf3ce44SJohn Forte /* guard against '/' at end of command invocation */ 2346*fcf3ce44SJohn Forte for (;;) { 2347*fcf3ce44SJohn Forte lastSlash = strrchr(execFullname, '/'); 2348*fcf3ce44SJohn Forte if (lastSlash == NULL) { 2349*fcf3ce44SJohn Forte execBasename = execFullname; 2350*fcf3ce44SJohn Forte break; 2351*fcf3ce44SJohn Forte } else { 2352*fcf3ce44SJohn Forte execBasename = lastSlash + 1; 2353*fcf3ce44SJohn Forte if (*execBasename == '\0') { 2354*fcf3ce44SJohn Forte *lastSlash = '\0'; 2355*fcf3ce44SJohn Forte continue; 2356*fcf3ce44SJohn Forte } 2357*fcf3ce44SJohn Forte break; 2358*fcf3ce44SJohn Forte } 2359*fcf3ce44SJohn Forte } 2360*fcf3ce44SJohn Forte return (execBasename); 2361*fcf3ce44SJohn Forte } 2362*fcf3ce44SJohn Forte 2363*fcf3ce44SJohn Forte int 2364*fcf3ce44SJohn Forte main(int argc, char *argv[]) 2365*fcf3ce44SJohn Forte { 2366*fcf3ce44SJohn Forte synTables_t synTables; 2367*fcf3ce44SJohn Forte char versionString[VERSION_STRING_MAX_LEN]; 2368*fcf3ce44SJohn Forte int ret; 2369*fcf3ce44SJohn Forte int funcRet; 2370*fcf3ce44SJohn Forte void *subcommandArgs = NULL; 2371*fcf3ce44SJohn Forte 2372*fcf3ce44SJohn Forte (void) setlocale(LC_ALL, ""); 2373*fcf3ce44SJohn Forte (void) textdomain(TEXT_DOMAIN); 2374*fcf3ce44SJohn Forte /* set global command name */ 2375*fcf3ce44SJohn Forte cmdName = getExecBasename(argv[0]); 2376*fcf3ce44SJohn Forte 2377*fcf3ce44SJohn Forte (void) snprintf(versionString, VERSION_STRING_MAX_LEN, "%s.%s", 2378*fcf3ce44SJohn Forte VERSION_STRING_MAJOR, VERSION_STRING_MINOR); 2379*fcf3ce44SJohn Forte synTables.versionString = versionString; 2380*fcf3ce44SJohn Forte synTables.longOptionTbl = &longOptions[0]; 2381*fcf3ce44SJohn Forte synTables.subCommandPropsTbl = &subcommands[0]; 2382*fcf3ce44SJohn Forte 2383*fcf3ce44SJohn Forte ret = cmdParse(argc, argv, synTables, subcommandArgs, &funcRet); 2384*fcf3ce44SJohn Forte if (ret != 0) { 2385*fcf3ce44SJohn Forte return (ret); 2386*fcf3ce44SJohn Forte } 2387*fcf3ce44SJohn Forte 2388*fcf3ce44SJohn Forte return (funcRet); 2389*fcf3ce44SJohn Forte } /* end main */ 2390