1fcf3ce44SJohn Forte /* 2fcf3ce44SJohn Forte * CDDL HEADER START 3fcf3ce44SJohn Forte * 4fcf3ce44SJohn Forte * The contents of this file are subject to the terms of the 5fcf3ce44SJohn Forte * Common Development and Distribution License (the "License"). 6fcf3ce44SJohn Forte * You may not use this file except in compliance with the License. 7fcf3ce44SJohn Forte * 8fcf3ce44SJohn Forte * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9fcf3ce44SJohn Forte * or http://www.opensolaris.org/os/licensing. 10fcf3ce44SJohn Forte * See the License for the specific language governing permissions 11fcf3ce44SJohn Forte * and limitations under the License. 12fcf3ce44SJohn Forte * 13fcf3ce44SJohn Forte * When distributing Covered Code, include this CDDL HEADER in each 14fcf3ce44SJohn Forte * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15fcf3ce44SJohn Forte * If applicable, add the following below this CDDL HEADER, with the 16fcf3ce44SJohn Forte * fields enclosed by brackets "[]" replaced with your own identifying 17fcf3ce44SJohn Forte * information: Portions Copyright [yyyy] [name of copyright owner] 18fcf3ce44SJohn Forte * 19fcf3ce44SJohn Forte * CDDL HEADER END 20fcf3ce44SJohn Forte */ 21fcf3ce44SJohn Forte /* 22e17f3b22Stim szeto * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 23fcf3ce44SJohn Forte * Use is subject to license terms. 24fcf3ce44SJohn Forte */ 25fcf3ce44SJohn Forte 26fcf3ce44SJohn Forte #include <stdlib.h> 27fcf3ce44SJohn Forte #include <stdio.h> 28fcf3ce44SJohn Forte #include <strings.h> 29fcf3ce44SJohn Forte #include <sys/types.h> 30fcf3ce44SJohn Forte #include <unistd.h> 31fcf3ce44SJohn Forte #include <wchar.h> 32fcf3ce44SJohn Forte #include <libintl.h> 33fcf3ce44SJohn Forte #include <errno.h> 34fcf3ce44SJohn Forte #include <time.h> 35fcf3ce44SJohn Forte #include <string.h> 36fcf3ce44SJohn Forte #include <assert.h> 37fcf3ce44SJohn Forte #include <getopt.h> 38fcf3ce44SJohn Forte #include <cmdparse.h> 39fcf3ce44SJohn Forte #include <stmfadm.h> 40fcf3ce44SJohn Forte #include <libstmf.h> 41fcf3ce44SJohn Forte #include <signal.h> 42fcf3ce44SJohn Forte #include <pthread.h> 43fcf3ce44SJohn Forte #include <locale.h> 44fcf3ce44SJohn Forte 45fcf3ce44SJohn Forte static int addHostGroupMemberFunc(int, char **, cmdOptions_t *, void *); 46fcf3ce44SJohn Forte static int addTargetGroupMemberFunc(int, char **, cmdOptions_t *, void *); 47fcf3ce44SJohn Forte static int addViewFunc(int, char **, cmdOptions_t *, void *); 48fcf3ce44SJohn Forte static int createHostGroupFunc(int, char **, cmdOptions_t *, void *); 49*8fe96085Stim szeto static int createLuFunc(int, char **, cmdOptions_t *, void *); 50*8fe96085Stim szeto static int modifyLuFunc(int, char **, cmdOptions_t *, void *); 51*8fe96085Stim szeto static int importLuFunc(int, char **, cmdOptions_t *, void *); 52*8fe96085Stim szeto static int deleteLuFunc(int, char **, cmdOptions_t *, void *); 53fcf3ce44SJohn Forte static int createTargetGroupFunc(int, char **, cmdOptions_t *, void *); 54fcf3ce44SJohn Forte static int deleteHostGroupFunc(int, char **, cmdOptions_t *, void *); 55fcf3ce44SJohn Forte static int deleteTargetGroupFunc(int, char **, cmdOptions_t *, void *); 56fcf3ce44SJohn Forte static int listLuFunc(int, char **, cmdOptions_t *, void *); 57fcf3ce44SJohn Forte static int listTargetFunc(int, char **, cmdOptions_t *, void *); 58fcf3ce44SJohn Forte static int listViewFunc(int, char **, cmdOptions_t *, void *); 59fcf3ce44SJohn Forte static int listHostGroupFunc(int, char **, cmdOptions_t *, void *); 60fcf3ce44SJohn Forte static int listStateFunc(int, char **, cmdOptions_t *, void *); 61fcf3ce44SJohn Forte static int listTargetGroupFunc(int, char **, cmdOptions_t *, void *); 62fcf3ce44SJohn Forte static int offlineTargetFunc(int, char **, cmdOptions_t *, void *); 63fcf3ce44SJohn Forte static int offlineLuFunc(int, char **, cmdOptions_t *, void *); 64fcf3ce44SJohn Forte static int onlineTargetFunc(int, char **, cmdOptions_t *, void *); 65fcf3ce44SJohn Forte static int onlineLuFunc(int, char **, cmdOptions_t *, void *); 66fcf3ce44SJohn Forte static int onlineOfflineTarget(char *, int); 67fcf3ce44SJohn Forte static int onlineOfflineLu(char *, int); 68fcf3ce44SJohn Forte static int removeHostGroupMemberFunc(int, char **, cmdOptions_t *, void *); 69fcf3ce44SJohn Forte static int removeTargetGroupMemberFunc(int, char **, cmdOptions_t *, void *); 70*8fe96085Stim szeto static int callModify(char *, stmfGuid *, uint32_t, const char *, const char *); 71fcf3ce44SJohn Forte static int removeViewFunc(int, char **, cmdOptions_t *, void *); 72fcf3ce44SJohn Forte static char *getExecBasename(char *); 73fcf3ce44SJohn Forte static int parseDevid(char *input, stmfDevid *devid); 74fcf3ce44SJohn Forte static void printGroupProps(stmfGroupProperties *groupProps); 75fcf3ce44SJohn Forte static int checkScsiNameString(wchar_t *, stmfDevid *); 76fcf3ce44SJohn Forte static int checkHexUpper(char *); 77fcf3ce44SJohn Forte static int checkIscsiName(wchar_t *); 78fcf3ce44SJohn Forte static void printLuProps(stmfLogicalUnitProperties *luProps); 79*8fe96085Stim szeto static int printExtLuProps(stmfGuid *guid); 80fcf3ce44SJohn Forte static void printGuid(stmfGuid *guid, FILE *printWhere); 81fcf3ce44SJohn Forte static void printTargetProps(stmfTargetProperties *); 82fcf3ce44SJohn Forte static void printSessionProps(stmfSessionList *); 83*8fe96085Stim szeto static int setLuPropFromInput(luResource, char *); 84*8fe96085Stim szeto static int convertCharToPropId(char *, uint32_t *); 85fcf3ce44SJohn Forte 86fcf3ce44SJohn Forte 87fcf3ce44SJohn Forte 88fcf3ce44SJohn Forte /* 89fcf3ce44SJohn Forte * MAJOR - This should only change when there is an incompatible change made 90fcf3ce44SJohn Forte * to the interfaces or the output. 91fcf3ce44SJohn Forte * 92fcf3ce44SJohn Forte * MINOR - This should change whenever there is a new command or new feature 93fcf3ce44SJohn Forte * with no incompatible change. 94fcf3ce44SJohn Forte */ 95fcf3ce44SJohn Forte #define VERSION_STRING_MAJOR "1" 96fcf3ce44SJohn Forte #define VERSION_STRING_MINOR "0" 97fcf3ce44SJohn Forte #define MAX_DEVID_INPUT 256 98fcf3ce44SJohn Forte #define GUID_INPUT 32 99fcf3ce44SJohn Forte #define MAX_LU_NBR 16383 100fcf3ce44SJohn Forte #define ONLINE_LU 0 101fcf3ce44SJohn Forte #define OFFLINE_LU 1 102fcf3ce44SJohn Forte #define ONLINE_TARGET 2 103fcf3ce44SJohn Forte #define OFFLINE_TARGET 3 104fcf3ce44SJohn Forte #define PROPS_FORMAT " %-18s: " 105fcf3ce44SJohn Forte #define VIEW_FORMAT " %-13s: " 106fcf3ce44SJohn Forte #define LVL3_FORMAT " %s" 107fcf3ce44SJohn Forte #define LVL4_FORMAT " %s" 108fcf3ce44SJohn Forte 109fcf3ce44SJohn Forte /* SCSI Name String length definitions */ 110fcf3ce44SJohn Forte #define SNS_EUI_16 16 111fcf3ce44SJohn Forte #define SNS_EUI_24 24 112fcf3ce44SJohn Forte #define SNS_EUI_32 32 113fcf3ce44SJohn Forte #define SNS_NAA_16 16 114fcf3ce44SJohn Forte #define SNS_NAA_32 32 115fcf3ce44SJohn Forte #define SNS_WWN_16 16 116fcf3ce44SJohn Forte #define SNS_IQN_223 223 117fcf3ce44SJohn Forte 118*8fe96085Stim szeto /* LU Property strings */ 119*8fe96085Stim szeto #define GUID "GUID" 120*8fe96085Stim szeto #define ALIAS "ALIAS" 121*8fe96085Stim szeto #define VID "VID" 122*8fe96085Stim szeto #define PID "PID" 123*8fe96085Stim szeto #define META_FILE "META" 124*8fe96085Stim szeto #define WRITE_PROTECT "WP" 125*8fe96085Stim szeto #define WRITEBACK_CACHE_DISABLE "WCD" 126*8fe96085Stim szeto #define COMPANY_ID "OUI" 127*8fe96085Stim szeto #define BLOCK_SIZE "BLK" 128*8fe96085Stim szeto #define SERIAL_NUMBER "SERIAL" 129*8fe96085Stim szeto 130*8fe96085Stim szeto #define MODIFY_HELP "\n"\ 131*8fe96085Stim szeto "Description: Modify properties of a logical unit. \n" \ 132*8fe96085Stim szeto "Valid properties for -p, --lu-prop are: \n" \ 133*8fe96085Stim szeto " alias - alias for logical unit (up to 255 chars)\n" \ 134*8fe96085Stim szeto " wcd - write cache disabled (true, false)\n" \ 135*8fe96085Stim szeto " wp - write protect (true, false)\n\n" \ 136*8fe96085Stim szeto "-f alters the meaning of the operand to be a file name\n" \ 137*8fe96085Stim szeto "rather than a LU name. This allows for modification\n" \ 138*8fe96085Stim szeto "of a logical unit that is not yet imported into stmf\n" 139*8fe96085Stim szeto 140*8fe96085Stim szeto #define CREATE_HELP "\n"\ 141*8fe96085Stim szeto "Description: Create a logical unit. \n" \ 142*8fe96085Stim szeto "Valid properties for -p, --lu-prop are: \n" \ 143*8fe96085Stim szeto " alias - alias for logical unit (up to 255 chars)\n" \ 144*8fe96085Stim szeto " blk - block size in bytes in 2^n\n" \ 145*8fe96085Stim szeto " guid - 32 ascii hex characters in NAA format \n" \ 146*8fe96085Stim szeto " meta - separate meta data file name\n" \ 147*8fe96085Stim szeto " oui - organizational unique identifier\n" \ 148*8fe96085Stim szeto " 6 ascii hex characters of valid format\n" \ 149*8fe96085Stim szeto " pid - product identifier (up to 16 chars)\n" \ 150*8fe96085Stim szeto " serial- serial number (up to 252 chars)\n" \ 151*8fe96085Stim szeto " vid - vendor identifier (up to 8 chars)\n" \ 152*8fe96085Stim szeto " wp - write protect (true, false)\n" \ 153*8fe96085Stim szeto " wcd - write cache disabled (true, false)\n" 154*8fe96085Stim szeto #define ADD_VIEW_HELP "\n"\ 155*8fe96085Stim szeto "Description: Add a view entry to a logical unit. \n" \ 156*8fe96085Stim szeto "A view entry is comprised of three elements; the \n" \ 157*8fe96085Stim szeto "logical unit number, the target group name and the\n" \ 158*8fe96085Stim szeto "host group name. These three elements combine together\n" \ 159*8fe96085Stim szeto "to form a view for a given COMSTAR logical unit.\n" \ 160*8fe96085Stim szeto "This view is realized by a client, a SCSI initiator,\n" \ 161*8fe96085Stim szeto "via a REPORT LUNS command. \n" 162*8fe96085Stim szeto 163*8fe96085Stim szeto 164*8fe96085Stim szeto 165fcf3ce44SJohn Forte /* tables set up based on cmdparse instructions */ 166fcf3ce44SJohn Forte 167fcf3ce44SJohn Forte /* add new options here */ 168fcf3ce44SJohn Forte optionTbl_t longOptions[] = { 169fcf3ce44SJohn Forte {"all", no_arg, 'a', NULL}, 170fcf3ce44SJohn Forte {"group-name", required_arg, 'g', "group-name"}, 171*8fe96085Stim szeto {"keep-views", no_arg, 'k', NULL}, 172fcf3ce44SJohn Forte {"lu-name", required_arg, 'l', "LU-Name"}, 173fcf3ce44SJohn Forte {"lun", required_arg, 'n', "logical-unit-number"}, 174*8fe96085Stim szeto {"lu-prop", required_arg, 'p', "logical-unit-property=value"}, 175*8fe96085Stim szeto {"file", no_arg, 'f', "filename"}, 176*8fe96085Stim szeto {"size", required_arg, 's', "size K/M/G/T/P"}, 177fcf3ce44SJohn Forte {"target-group", required_arg, 't', "group-name"}, 178fcf3ce44SJohn Forte {"host-group", required_arg, 'h', "group-name"}, 179*8fe96085Stim szeto {"verbose", no_arg, 'v', NULL}, 180fcf3ce44SJohn Forte {NULL, 0, 0, 0} 181fcf3ce44SJohn Forte }; 182fcf3ce44SJohn Forte 183fcf3ce44SJohn Forte /* 184fcf3ce44SJohn Forte * Add new subcommands here 185fcf3ce44SJohn Forte */ 186fcf3ce44SJohn Forte subCommandProps_t subcommands[] = { 187fcf3ce44SJohn Forte {"add-hg-member", addHostGroupMemberFunc, "g", "g", NULL, 188*8fe96085Stim szeto OPERAND_MANDATORY_MULTIPLE, OPERANDSTRING_GROUP_MEMBER, NULL}, 189fcf3ce44SJohn Forte {"add-tg-member", addTargetGroupMemberFunc, "g", "g", NULL, 190*8fe96085Stim szeto OPERAND_MANDATORY_MULTIPLE, OPERANDSTRING_GROUP_MEMBER, NULL}, 191fcf3ce44SJohn Forte {"add-view", addViewFunc, "nth", NULL, NULL, 192*8fe96085Stim szeto OPERAND_MANDATORY_SINGLE, OPERANDSTRING_LU, ADD_VIEW_HELP}, 193fcf3ce44SJohn Forte {"create-hg", createHostGroupFunc, NULL, NULL, NULL, 194*8fe96085Stim szeto OPERAND_MANDATORY_SINGLE, OPERANDSTRING_GROUP_NAME, NULL}, 195fcf3ce44SJohn Forte {"create-tg", createTargetGroupFunc, NULL, NULL, NULL, 196*8fe96085Stim szeto OPERAND_MANDATORY_SINGLE, OPERANDSTRING_GROUP_NAME, NULL}, 197*8fe96085Stim szeto {"create-lu", createLuFunc, "ps", NULL, NULL, OPERAND_MANDATORY_SINGLE, 198*8fe96085Stim szeto "lu file", CREATE_HELP}, 199fcf3ce44SJohn Forte {"delete-hg", deleteHostGroupFunc, NULL, NULL, NULL, 200*8fe96085Stim szeto OPERAND_MANDATORY_SINGLE, OPERANDSTRING_GROUP_NAME, NULL}, 201*8fe96085Stim szeto {"modify-lu", modifyLuFunc, "psf", NULL, NULL, OPERAND_MANDATORY_SINGLE, 202*8fe96085Stim szeto OPERANDSTRING_LU, MODIFY_HELP}, 203*8fe96085Stim szeto {"delete-lu", deleteLuFunc, "k", NULL, NULL, 204*8fe96085Stim szeto OPERAND_MANDATORY_MULTIPLE, OPERANDSTRING_LU, NULL}, 205fcf3ce44SJohn Forte {"delete-tg", deleteTargetGroupFunc, NULL, NULL, NULL, 206*8fe96085Stim szeto OPERAND_MANDATORY_SINGLE, OPERANDSTRING_GROUP_NAME, NULL}, 207*8fe96085Stim szeto {"import-lu", importLuFunc, NULL, NULL, NULL, 208*8fe96085Stim szeto OPERAND_MANDATORY_SINGLE, "file name", NULL}, 209fcf3ce44SJohn Forte {"list-hg", listHostGroupFunc, "v", NULL, NULL, 210*8fe96085Stim szeto OPERAND_OPTIONAL_MULTIPLE, OPERANDSTRING_GROUP_NAME, NULL}, 211fcf3ce44SJohn Forte {"list-lu", listLuFunc, "v", NULL, NULL, OPERAND_OPTIONAL_MULTIPLE, 212*8fe96085Stim szeto OPERANDSTRING_LU, NULL}, 213fcf3ce44SJohn Forte {"list-state", listStateFunc, NULL, NULL, NULL, OPERAND_NONE, NULL}, 214fcf3ce44SJohn Forte {"list-target", listTargetFunc, "v", NULL, NULL, 215*8fe96085Stim szeto OPERAND_OPTIONAL_MULTIPLE, OPERANDSTRING_TARGET, NULL}, 216fcf3ce44SJohn Forte {"list-tg", listTargetGroupFunc, "v", NULL, NULL, 217*8fe96085Stim szeto OPERAND_OPTIONAL_MULTIPLE, OPERANDSTRING_GROUP_NAME, NULL}, 218fcf3ce44SJohn Forte {"list-view", listViewFunc, "l", "l", NULL, 219*8fe96085Stim szeto OPERAND_OPTIONAL_MULTIPLE, OPERANDSTRING_VIEW_ENTRY, NULL}, 220fcf3ce44SJohn Forte {"online-lu", onlineLuFunc, NULL, NULL, NULL, 221*8fe96085Stim szeto OPERAND_MANDATORY_SINGLE, OPERANDSTRING_LU, NULL}, 222fcf3ce44SJohn Forte {"offline-lu", offlineLuFunc, NULL, NULL, NULL, 223*8fe96085Stim szeto OPERAND_MANDATORY_SINGLE, OPERANDSTRING_LU, NULL}, 224fcf3ce44SJohn Forte {"online-target", onlineTargetFunc, NULL, NULL, NULL, 225*8fe96085Stim szeto OPERAND_MANDATORY_SINGLE, OPERANDSTRING_TARGET, NULL}, 226fcf3ce44SJohn Forte {"offline-target", offlineTargetFunc, NULL, NULL, NULL, 227*8fe96085Stim szeto OPERAND_MANDATORY_SINGLE, OPERANDSTRING_TARGET, NULL}, 228fcf3ce44SJohn Forte {"remove-hg-member", removeHostGroupMemberFunc, "g", "g", NULL, 229*8fe96085Stim szeto OPERAND_MANDATORY_MULTIPLE, OPERANDSTRING_GROUP_MEMBER, NULL}, 230fcf3ce44SJohn Forte {"remove-tg-member", removeTargetGroupMemberFunc, "g", "g", NULL, 231*8fe96085Stim szeto OPERAND_MANDATORY_MULTIPLE, OPERANDSTRING_GROUP_MEMBER, NULL}, 232fcf3ce44SJohn Forte {"remove-view", removeViewFunc, "la", "l", NULL, 233*8fe96085Stim szeto OPERAND_OPTIONAL_MULTIPLE, OPERANDSTRING_VIEW_ENTRY, NULL}, 234*8fe96085Stim szeto {NULL, 0, NULL, NULL, 0, NULL, 0, NULL, NULL} 235fcf3ce44SJohn Forte }; 236fcf3ce44SJohn Forte 237fcf3ce44SJohn Forte /* globals */ 238fcf3ce44SJohn Forte char *cmdName; 239fcf3ce44SJohn Forte 240fcf3ce44SJohn Forte /* 241fcf3ce44SJohn Forte * addHostGroupMemberFunc 242fcf3ce44SJohn Forte * 243fcf3ce44SJohn Forte * Add members to a host group 244fcf3ce44SJohn Forte * 245fcf3ce44SJohn Forte */ 246fcf3ce44SJohn Forte /*ARGSUSED*/ 247fcf3ce44SJohn Forte static int 248fcf3ce44SJohn Forte addHostGroupMemberFunc(int operandLen, char *operands[], cmdOptions_t *options, 249fcf3ce44SJohn Forte void *args) 250fcf3ce44SJohn Forte { 251fcf3ce44SJohn Forte int i; 252fcf3ce44SJohn Forte int ret = 0; 253fcf3ce44SJohn Forte int stmfRet; 2543e7352aeSJohn Forte stmfGroupName groupName = {0}; 2553e7352aeSJohn Forte wchar_t groupNamePrint[sizeof (stmfGroupName)] = {0}; 256fcf3ce44SJohn Forte stmfDevid devid; 257fcf3ce44SJohn Forte 258fcf3ce44SJohn Forte for (; options->optval; options++) { 259fcf3ce44SJohn Forte switch (options->optval) { 260fcf3ce44SJohn Forte /* host group name */ 261fcf3ce44SJohn Forte case 'g': 262fcf3ce44SJohn Forte (void) mbstowcs(groupNamePrint, options->optarg, 2633e7352aeSJohn Forte sizeof (stmfGroupName) - 1); 264fcf3ce44SJohn Forte bcopy(options->optarg, groupName, 265fcf3ce44SJohn Forte strlen(options->optarg)); 266fcf3ce44SJohn Forte break; 267fcf3ce44SJohn Forte default: 268fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %c: %s\n", 269fcf3ce44SJohn Forte cmdName, options->optval, 270fcf3ce44SJohn Forte gettext("unknown option")); 271fcf3ce44SJohn Forte return (1); 272fcf3ce44SJohn Forte } 273fcf3ce44SJohn Forte } 274fcf3ce44SJohn Forte 275fcf3ce44SJohn Forte for (i = 0; i < operandLen; i++) { 276fcf3ce44SJohn Forte if (parseDevid(operands[i], &devid) != 0) { 277fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", 278fcf3ce44SJohn Forte cmdName, operands[i], 279fcf3ce44SJohn Forte gettext("unrecognized device id")); 280fcf3ce44SJohn Forte ret++; 281fcf3ce44SJohn Forte continue; 282fcf3ce44SJohn Forte } 283fcf3ce44SJohn Forte stmfRet = stmfAddToHostGroup(&groupName, &devid); 284fcf3ce44SJohn Forte switch (stmfRet) { 285fcf3ce44SJohn Forte case STMF_STATUS_SUCCESS: 286fcf3ce44SJohn Forte break; 287fcf3ce44SJohn Forte case STMF_ERROR_EXISTS: 288fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 289fcf3ce44SJohn Forte operands[i], gettext("already exists")); 290fcf3ce44SJohn Forte ret++; 291fcf3ce44SJohn Forte break; 292fcf3ce44SJohn Forte case STMF_ERROR_GROUP_NOT_FOUND: 293fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %ws: %s\n", cmdName, 294fcf3ce44SJohn Forte groupNamePrint, gettext("not found")); 295fcf3ce44SJohn Forte ret++; 296fcf3ce44SJohn Forte break; 297fcf3ce44SJohn Forte case STMF_ERROR_PERM: 298fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 299fcf3ce44SJohn Forte gettext("permission denied")); 300fcf3ce44SJohn Forte break; 301fcf3ce44SJohn Forte case STMF_ERROR_BUSY: 302fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 303fcf3ce44SJohn Forte operands[i], gettext("resource busy")); 304fcf3ce44SJohn Forte ret++; 305fcf3ce44SJohn Forte break; 306fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_NOT_FOUND: 307fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 308fcf3ce44SJohn Forte gettext("STMF service not found")); 309fcf3ce44SJohn Forte ret++; 310fcf3ce44SJohn Forte break; 311fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_DATA_VERSION: 312fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 313fcf3ce44SJohn Forte gettext("STMF service version incorrect")); 314fcf3ce44SJohn Forte ret++; 315fcf3ce44SJohn Forte break; 316fcf3ce44SJohn Forte default: 317fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 318fcf3ce44SJohn Forte operands[i], gettext("unknown error")); 319fcf3ce44SJohn Forte ret++; 320fcf3ce44SJohn Forte break; 321fcf3ce44SJohn Forte } 322fcf3ce44SJohn Forte } 323fcf3ce44SJohn Forte 324fcf3ce44SJohn Forte return (ret); 325fcf3ce44SJohn Forte } 326fcf3ce44SJohn Forte 327fcf3ce44SJohn Forte /* 328fcf3ce44SJohn Forte * addTargetGroupMemberFunc 329fcf3ce44SJohn Forte * 330fcf3ce44SJohn Forte * Add members to a target group 331fcf3ce44SJohn Forte * 332fcf3ce44SJohn Forte */ 333fcf3ce44SJohn Forte /*ARGSUSED*/ 334fcf3ce44SJohn Forte static int 335fcf3ce44SJohn Forte addTargetGroupMemberFunc(int operandLen, char *operands[], 336fcf3ce44SJohn Forte cmdOptions_t *options, void *args) 337fcf3ce44SJohn Forte { 338fcf3ce44SJohn Forte int i; 339fcf3ce44SJohn Forte int ret = 0; 340fcf3ce44SJohn Forte int stmfRet; 3413e7352aeSJohn Forte stmfGroupName groupName = {0}; 3423e7352aeSJohn Forte wchar_t groupNamePrint[sizeof (stmfGroupName)] = {0}; 343fcf3ce44SJohn Forte stmfDevid devid; 344fcf3ce44SJohn Forte 345fcf3ce44SJohn Forte for (; options->optval; options++) { 346fcf3ce44SJohn Forte switch (options->optval) { 347fcf3ce44SJohn Forte /* target group name */ 348fcf3ce44SJohn Forte case 'g': 349fcf3ce44SJohn Forte (void) mbstowcs(groupNamePrint, options->optarg, 3503e7352aeSJohn Forte sizeof (stmfGroupName) - 1); 351fcf3ce44SJohn Forte bcopy(options->optarg, groupName, 352fcf3ce44SJohn Forte strlen(options->optarg)); 353fcf3ce44SJohn Forte break; 354fcf3ce44SJohn Forte default: 355fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %c: %s\n", 356fcf3ce44SJohn Forte cmdName, options->optval, 357fcf3ce44SJohn Forte gettext("unknown option")); 358fcf3ce44SJohn Forte return (1); 359fcf3ce44SJohn Forte } 360fcf3ce44SJohn Forte } 361fcf3ce44SJohn Forte 362fcf3ce44SJohn Forte for (i = 0; i < operandLen; i++) { 363fcf3ce44SJohn Forte if (parseDevid(operands[i], &devid) != 0) { 364fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", 365fcf3ce44SJohn Forte cmdName, operands[i], 366fcf3ce44SJohn Forte gettext("unrecognized device id")); 367fcf3ce44SJohn Forte ret++; 368fcf3ce44SJohn Forte continue; 369fcf3ce44SJohn Forte } 370fcf3ce44SJohn Forte stmfRet = stmfAddToTargetGroup(&groupName, &devid); 371fcf3ce44SJohn Forte switch (stmfRet) { 372fcf3ce44SJohn Forte case STMF_STATUS_SUCCESS: 373fcf3ce44SJohn Forte break; 374fcf3ce44SJohn Forte case STMF_ERROR_EXISTS: 375fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 376fcf3ce44SJohn Forte operands[i], gettext("already exists")); 377fcf3ce44SJohn Forte ret++; 378fcf3ce44SJohn Forte break; 379fcf3ce44SJohn Forte case STMF_ERROR_GROUP_NOT_FOUND: 380fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %ws: %s\n", cmdName, 381fcf3ce44SJohn Forte groupNamePrint, gettext("not found")); 382fcf3ce44SJohn Forte ret++; 383fcf3ce44SJohn Forte break; 384fcf3ce44SJohn Forte case STMF_ERROR_PERM: 385fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 386fcf3ce44SJohn Forte gettext("permission denied")); 387fcf3ce44SJohn Forte break; 388fcf3ce44SJohn Forte case STMF_ERROR_BUSY: 389fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 390fcf3ce44SJohn Forte operands[i], gettext("resource busy")); 391fcf3ce44SJohn Forte ret++; 392fcf3ce44SJohn Forte break; 393fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_NOT_FOUND: 394fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 395fcf3ce44SJohn Forte gettext("STMF service not found")); 396fcf3ce44SJohn Forte ret++; 397fcf3ce44SJohn Forte break; 398fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_ONLINE: 399fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 400fcf3ce44SJohn Forte gettext("STMF service must be offline")); 401fcf3ce44SJohn Forte ret++; 402fcf3ce44SJohn Forte break; 403fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_DATA_VERSION: 404fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 405fcf3ce44SJohn Forte gettext("STMF service version incorrect")); 406fcf3ce44SJohn Forte ret++; 407fcf3ce44SJohn Forte break; 408fcf3ce44SJohn Forte default: 409fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 410fcf3ce44SJohn Forte operands[i], gettext("unknown error")); 411fcf3ce44SJohn Forte ret++; 412fcf3ce44SJohn Forte break; 413fcf3ce44SJohn Forte } 414fcf3ce44SJohn Forte } 415fcf3ce44SJohn Forte 416fcf3ce44SJohn Forte return (ret); 417fcf3ce44SJohn Forte } 418fcf3ce44SJohn Forte 419fcf3ce44SJohn Forte /* 420fcf3ce44SJohn Forte * parseDevid 421fcf3ce44SJohn Forte * 422fcf3ce44SJohn Forte * Converts char * input to a stmfDevid 423fcf3ce44SJohn Forte * 424fcf3ce44SJohn Forte * input - this should be in the following format with either a 425fcf3ce44SJohn Forte * wwn. iqn. or eui. representation. 426fcf3ce44SJohn Forte * A name string of the format: 427fcf3ce44SJohn Forte * wwn.<WWN> (FC/SAS address) 428fcf3ce44SJohn Forte * iqn.<iSCSI name> (iSCSI iqn) 429fcf3ce44SJohn Forte * eui.<WWN> (iSCSI eui name) 430fcf3ce44SJohn Forte * 431fcf3ce44SJohn Forte * devid - pointer to stmfDevid structure allocated by the caller. 432fcf3ce44SJohn Forte * 433fcf3ce44SJohn Forte * Returns: 434fcf3ce44SJohn Forte * 0 on success 435fcf3ce44SJohn Forte * non-zero on failure 436fcf3ce44SJohn Forte */ 437fcf3ce44SJohn Forte static int 438fcf3ce44SJohn Forte parseDevid(char *input, stmfDevid *devid) 439fcf3ce44SJohn Forte { 4403e7352aeSJohn Forte wchar_t inputWc[MAX_DEVID_INPUT + 1] = {0}; 441fcf3ce44SJohn Forte 442fcf3ce44SJohn Forte /* convert to wcs */ 4433e7352aeSJohn Forte (void) mbstowcs(inputWc, input, MAX_DEVID_INPUT); 444fcf3ce44SJohn Forte 445fcf3ce44SJohn Forte /* 446fcf3ce44SJohn Forte * Check for known scsi name string formats 447fcf3ce44SJohn Forte * If one is found, we're done 448fcf3ce44SJohn Forte * If not, then it's a failure to parse 449fcf3ce44SJohn Forte */ 450fcf3ce44SJohn Forte if (checkScsiNameString(inputWc, devid) == 0) { 451fcf3ce44SJohn Forte return (0); 452fcf3ce44SJohn Forte } 453fcf3ce44SJohn Forte 454fcf3ce44SJohn Forte return (-1); 455fcf3ce44SJohn Forte } 456fcf3ce44SJohn Forte 457fcf3ce44SJohn Forte /* 458fcf3ce44SJohn Forte * checkScsiNameString 459fcf3ce44SJohn Forte * 460fcf3ce44SJohn Forte * Validates known SCSI name string formats and converts to stmfDevid 461fcf3ce44SJohn Forte * format 462fcf3ce44SJohn Forte * 463fcf3ce44SJohn Forte * input - input SCSI name string 464fcf3ce44SJohn Forte * devid - pointer to stmfDevid structure allocated by the caller 465fcf3ce44SJohn Forte * on successful return, contains the devid based on input 466fcf3ce44SJohn Forte * 467fcf3ce44SJohn Forte * returns: 468fcf3ce44SJohn Forte * 0 on success 469fcf3ce44SJohn Forte * -1 on failure 470fcf3ce44SJohn Forte */ 471fcf3ce44SJohn Forte static int 472fcf3ce44SJohn Forte checkScsiNameString(wchar_t *input, stmfDevid *devid) 473fcf3ce44SJohn Forte { 474fcf3ce44SJohn Forte char *mbString = NULL; 475fcf3ce44SJohn Forte int mbStringLen; 476fcf3ce44SJohn Forte int len; 477fcf3ce44SJohn Forte int i; 478fcf3ce44SJohn Forte 479fcf3ce44SJohn Forte /* 480fcf3ce44SJohn Forte * Convert to multi-byte string 481fcf3ce44SJohn Forte * 482fcf3ce44SJohn Forte * This is used for either eui or naa formats 483fcf3ce44SJohn Forte */ 484fcf3ce44SJohn Forte mbString = calloc(1, (mbStringLen = wcstombs(mbString, input, 0)) + 1); 485fcf3ce44SJohn Forte if (mbString == NULL) { 486fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", 487fcf3ce44SJohn Forte cmdName, "Insufficient memory\n"); 488fcf3ce44SJohn Forte return (-1); 489fcf3ce44SJohn Forte } 490fcf3ce44SJohn Forte if (wcstombs(mbString, input, mbStringLen) == (size_t)-1) { 491fcf3ce44SJohn Forte return (-1); 492fcf3ce44SJohn Forte } 493fcf3ce44SJohn Forte 494fcf3ce44SJohn Forte /* 495fcf3ce44SJohn Forte * check for iqn format 496fcf3ce44SJohn Forte */ 497fcf3ce44SJohn Forte if (strncmp(mbString, "iqn.", 4) == 0) { 498fcf3ce44SJohn Forte if ((len = strlen(mbString)) > (SNS_IQN_223)) { 499fcf3ce44SJohn Forte return (-1); 500fcf3ce44SJohn Forte } 501fcf3ce44SJohn Forte for (i = 0; i < len; i++) { 502fcf3ce44SJohn Forte mbString[i] = tolower(mbString[i]); 503fcf3ce44SJohn Forte } 504fcf3ce44SJohn Forte if (checkIscsiName(input + 4) != 0) { 505fcf3ce44SJohn Forte return (-1); 506fcf3ce44SJohn Forte } 507fcf3ce44SJohn Forte } else if (strncmp(mbString, "wwn.", 4) == 0) { 508fcf3ce44SJohn Forte if ((len = strlen(mbString + 4)) != SNS_WWN_16) { 509fcf3ce44SJohn Forte return (-1); 510fcf3ce44SJohn Forte } else if (checkHexUpper(mbString + 4) != 0) { 511fcf3ce44SJohn Forte return (-1); 512fcf3ce44SJohn Forte } 513fcf3ce44SJohn Forte } else if (strncmp(mbString, "eui.", 4) == 0) { 514fcf3ce44SJohn Forte if ((len = strlen(mbString + 4)) != SNS_EUI_16) { 515fcf3ce44SJohn Forte return (-1); 516fcf3ce44SJohn Forte } else if (checkHexUpper(mbString + 4) != 0) { 517fcf3ce44SJohn Forte return (-1); 518fcf3ce44SJohn Forte } 519fcf3ce44SJohn Forte } else { 520fcf3ce44SJohn Forte return (-1); 521fcf3ce44SJohn Forte } 522fcf3ce44SJohn Forte 523fcf3ce44SJohn Forte /* 524fcf3ce44SJohn Forte * We have a validated name string. 525fcf3ce44SJohn Forte * Go ahead and set the length and copy it. 526fcf3ce44SJohn Forte */ 527fcf3ce44SJohn Forte devid->identLength = strlen(mbString); 528fcf3ce44SJohn Forte bzero(devid->ident, STMF_IDENT_LENGTH); 529fcf3ce44SJohn Forte bcopy(mbString, devid->ident, devid->identLength); 530fcf3ce44SJohn Forte 531fcf3ce44SJohn Forte return (0); 532fcf3ce44SJohn Forte } 533fcf3ce44SJohn Forte 534fcf3ce44SJohn Forte 535fcf3ce44SJohn Forte /* 536fcf3ce44SJohn Forte * Checks whether the entire string is in hex and converts to upper 537fcf3ce44SJohn Forte */ 538fcf3ce44SJohn Forte static int 539fcf3ce44SJohn Forte checkHexUpper(char *input) 540fcf3ce44SJohn Forte { 541fcf3ce44SJohn Forte int i; 542fcf3ce44SJohn Forte 543fcf3ce44SJohn Forte for (i = 0; i < strlen(input); i++) { 544fcf3ce44SJohn Forte if (isxdigit(input[i])) { 545fcf3ce44SJohn Forte input[i] = toupper(input[i]); 546fcf3ce44SJohn Forte continue; 547fcf3ce44SJohn Forte } 548fcf3ce44SJohn Forte return (-1); 549fcf3ce44SJohn Forte } 550fcf3ce44SJohn Forte 551fcf3ce44SJohn Forte return (0); 552fcf3ce44SJohn Forte } 553fcf3ce44SJohn Forte 554fcf3ce44SJohn Forte /* 555fcf3ce44SJohn Forte * checkIscsiName 556fcf3ce44SJohn Forte * 557fcf3ce44SJohn Forte * Purpose: Basic string checking on name 558fcf3ce44SJohn Forte */ 559fcf3ce44SJohn Forte static int 560fcf3ce44SJohn Forte checkIscsiName(wchar_t *input) 561fcf3ce44SJohn Forte { 562fcf3ce44SJohn Forte int i; 563fcf3ce44SJohn Forte 564fcf3ce44SJohn Forte for (i = 0; input[i] != 0; i++) { 565fcf3ce44SJohn Forte if (!iswalnum(input[i]) && input[i] != '-' && 566fcf3ce44SJohn Forte input[i] != '.' && input[i] != ':') { 567fcf3ce44SJohn Forte return (-1); 568fcf3ce44SJohn Forte } 569fcf3ce44SJohn Forte } 570fcf3ce44SJohn Forte 571fcf3ce44SJohn Forte return (0); 572fcf3ce44SJohn Forte } 573fcf3ce44SJohn Forte 574fcf3ce44SJohn Forte 575fcf3ce44SJohn Forte /* 576fcf3ce44SJohn Forte * addViewFunc 577fcf3ce44SJohn Forte * 578fcf3ce44SJohn Forte * Adds a view entry to a logical unit 579fcf3ce44SJohn Forte * 580fcf3ce44SJohn Forte */ 581fcf3ce44SJohn Forte /*ARGSUSED*/ 582fcf3ce44SJohn Forte static int 583fcf3ce44SJohn Forte addViewFunc(int operandLen, char *operands[], cmdOptions_t *options, 584fcf3ce44SJohn Forte void *args) 585fcf3ce44SJohn Forte { 586fcf3ce44SJohn Forte stmfViewEntry viewEntry; 587fcf3ce44SJohn Forte stmfGuid inGuid; 588fcf3ce44SJohn Forte unsigned int guid[sizeof (stmfGuid)]; 589fcf3ce44SJohn Forte uint16_t inputLuNbr; 590fcf3ce44SJohn Forte int ret = 0; 591fcf3ce44SJohn Forte int stmfRet; 592fcf3ce44SJohn Forte int i; 593fcf3ce44SJohn Forte char sGuid[GUID_INPUT + 1]; 594fcf3ce44SJohn Forte 595fcf3ce44SJohn Forte bzero(&viewEntry, sizeof (viewEntry)); 596fcf3ce44SJohn Forte /* init view entry structure */ 597fcf3ce44SJohn Forte viewEntry.allHosts = B_TRUE; 598fcf3ce44SJohn Forte viewEntry.allTargets = B_TRUE; 599fcf3ce44SJohn Forte viewEntry.luNbrValid = B_FALSE; 600fcf3ce44SJohn Forte 601fcf3ce44SJohn Forte /* check input length */ 602fcf3ce44SJohn Forte if (strlen(operands[0]) != GUID_INPUT) { 603fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s%d%s\n", cmdName, operands[0], 604fcf3ce44SJohn Forte gettext("must be "), GUID_INPUT, 605fcf3ce44SJohn Forte gettext(" hexadecimal digits")); 606fcf3ce44SJohn Forte return (1); 607fcf3ce44SJohn Forte } 608fcf3ce44SJohn Forte 609fcf3ce44SJohn Forte for (; options->optval; options++) { 610fcf3ce44SJohn Forte switch (options->optval) { 611fcf3ce44SJohn Forte /* logical unit number */ 612fcf3ce44SJohn Forte case 'n': 613fcf3ce44SJohn Forte viewEntry.luNbrValid = B_TRUE; 614fcf3ce44SJohn Forte inputLuNbr = atoi(options->optarg); 615fcf3ce44SJohn Forte if (inputLuNbr > MAX_LU_NBR) { 616fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %d: %s\n", 617fcf3ce44SJohn Forte cmdName, inputLuNbr, 618fcf3ce44SJohn Forte gettext("Logical unit number" 619fcf3ce44SJohn Forte " must be less than 16384")); 620fcf3ce44SJohn Forte return (1); 621fcf3ce44SJohn Forte } 622fcf3ce44SJohn Forte viewEntry.luNbr[0] = inputLuNbr >> 8; 623fcf3ce44SJohn Forte viewEntry.luNbr[1] = inputLuNbr & 0xff; 624fcf3ce44SJohn Forte break; 625fcf3ce44SJohn Forte /* host group */ 626fcf3ce44SJohn Forte case 'h': 627fcf3ce44SJohn Forte viewEntry.allHosts = B_FALSE; 628fcf3ce44SJohn Forte bcopy(options->optarg, viewEntry.hostGroup, 629fcf3ce44SJohn Forte strlen(options->optarg)); 630fcf3ce44SJohn Forte break; 631fcf3ce44SJohn Forte /* target group */ 632fcf3ce44SJohn Forte case 't': 633fcf3ce44SJohn Forte viewEntry.allTargets = B_FALSE; 634fcf3ce44SJohn Forte bcopy(options->optarg, viewEntry.targetGroup, 635fcf3ce44SJohn Forte strlen(options->optarg)); 636fcf3ce44SJohn Forte break; 637fcf3ce44SJohn Forte default: 638fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %c: %s\n", 639fcf3ce44SJohn Forte cmdName, options->optval, 640fcf3ce44SJohn Forte gettext("unknown option")); 641fcf3ce44SJohn Forte return (1); 642fcf3ce44SJohn Forte } 643fcf3ce44SJohn Forte } 644fcf3ce44SJohn Forte 645fcf3ce44SJohn Forte /* convert to lower case for scan */ 646fcf3ce44SJohn Forte for (i = 0; i < 32; i++) 647fcf3ce44SJohn Forte sGuid[i] = tolower(operands[0][i]); 648fcf3ce44SJohn Forte sGuid[i] = 0; 649fcf3ce44SJohn Forte 650fcf3ce44SJohn Forte (void) sscanf(sGuid, "%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x", 651fcf3ce44SJohn Forte &guid[0], &guid[1], &guid[2], &guid[3], &guid[4], &guid[5], 652fcf3ce44SJohn Forte &guid[6], &guid[7], &guid[8], &guid[9], &guid[10], &guid[11], 653fcf3ce44SJohn Forte &guid[12], &guid[13], &guid[14], &guid[15]); 654fcf3ce44SJohn Forte 655fcf3ce44SJohn Forte for (i = 0; i < sizeof (stmfGuid); i++) { 656fcf3ce44SJohn Forte inGuid.guid[i] = guid[i]; 657fcf3ce44SJohn Forte } 658fcf3ce44SJohn Forte 659fcf3ce44SJohn Forte /* add the view entry */ 660fcf3ce44SJohn Forte stmfRet = stmfAddViewEntry(&inGuid, &viewEntry); 661fcf3ce44SJohn Forte switch (stmfRet) { 662fcf3ce44SJohn Forte case STMF_STATUS_SUCCESS: 663fcf3ce44SJohn Forte break; 664fcf3ce44SJohn Forte case STMF_ERROR_EXISTS: 665fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 666fcf3ce44SJohn Forte operands[0], gettext("already exists")); 667fcf3ce44SJohn Forte ret++; 668fcf3ce44SJohn Forte break; 669fcf3ce44SJohn Forte case STMF_ERROR_BUSY: 670fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 671fcf3ce44SJohn Forte operands[0], gettext("resource busy")); 672fcf3ce44SJohn Forte ret++; 673fcf3ce44SJohn Forte break; 674fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_NOT_FOUND: 675fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 676fcf3ce44SJohn Forte gettext("STMF service not found")); 677fcf3ce44SJohn Forte ret++; 678fcf3ce44SJohn Forte break; 679fcf3ce44SJohn Forte case STMF_ERROR_PERM: 680fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 681fcf3ce44SJohn Forte gettext("permission denied")); 682fcf3ce44SJohn Forte ret++; 683fcf3ce44SJohn Forte break; 684fcf3ce44SJohn Forte case STMF_ERROR_LUN_IN_USE: 685fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 686fcf3ce44SJohn Forte gettext("LUN already in use")); 687fcf3ce44SJohn Forte ret++; 688fcf3ce44SJohn Forte break; 689fcf3ce44SJohn Forte case STMF_ERROR_VE_CONFLICT: 690fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 691fcf3ce44SJohn Forte gettext("view entry exists")); 692fcf3ce44SJohn Forte ret++; 693fcf3ce44SJohn Forte break; 694fcf3ce44SJohn Forte case STMF_ERROR_CONFIG_NONE: 695fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 696fcf3ce44SJohn Forte gettext("STMF service is not initialized")); 697fcf3ce44SJohn Forte ret++; 698fcf3ce44SJohn Forte break; 699fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_DATA_VERSION: 700fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 701fcf3ce44SJohn Forte gettext("STMF service version incorrect")); 702fcf3ce44SJohn Forte ret++; 703fcf3ce44SJohn Forte break; 704fcf3ce44SJohn Forte case STMF_ERROR_INVALID_HG: 705fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 706fcf3ce44SJohn Forte gettext("invalid host group")); 707fcf3ce44SJohn Forte ret++; 708fcf3ce44SJohn Forte break; 709fcf3ce44SJohn Forte case STMF_ERROR_INVALID_TG: 710fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 711fcf3ce44SJohn Forte gettext("invalid target group")); 712fcf3ce44SJohn Forte ret++; 713fcf3ce44SJohn Forte break; 714fcf3ce44SJohn Forte default: 715fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 716fcf3ce44SJohn Forte operands[0], gettext("unknown error")); 717fcf3ce44SJohn Forte ret++; 718fcf3ce44SJohn Forte break; 719fcf3ce44SJohn Forte } 720fcf3ce44SJohn Forte 721fcf3ce44SJohn Forte return (ret); 722fcf3ce44SJohn Forte } 723fcf3ce44SJohn Forte 724fcf3ce44SJohn Forte /* 725fcf3ce44SJohn Forte * createHostGroupFunc 726fcf3ce44SJohn Forte * 727fcf3ce44SJohn Forte * Create a host group 728fcf3ce44SJohn Forte * 729fcf3ce44SJohn Forte */ 730fcf3ce44SJohn Forte /*ARGSUSED*/ 731fcf3ce44SJohn Forte static int 732fcf3ce44SJohn Forte createHostGroupFunc(int operandLen, char *operands[], 733fcf3ce44SJohn Forte cmdOptions_t *options, void *args) 734fcf3ce44SJohn Forte { 735fcf3ce44SJohn Forte int ret = 0; 736fcf3ce44SJohn Forte int stmfRet; 7373e7352aeSJohn Forte wchar_t groupNamePrint[sizeof (stmfGroupName)] = {0}; 7383e7352aeSJohn Forte stmfGroupName groupName = {0}; 739fcf3ce44SJohn Forte 740fcf3ce44SJohn Forte (void) strlcpy(groupName, operands[0], sizeof (groupName)); 741fcf3ce44SJohn Forte (void) mbstowcs(groupNamePrint, (char *)groupName, 7423e7352aeSJohn Forte sizeof (stmfGroupName) - 1); 743fcf3ce44SJohn Forte /* call create group */ 744fcf3ce44SJohn Forte stmfRet = stmfCreateHostGroup(&groupName); 745fcf3ce44SJohn Forte switch (stmfRet) { 746fcf3ce44SJohn Forte case STMF_STATUS_SUCCESS: 747fcf3ce44SJohn Forte break; 748fcf3ce44SJohn Forte case STMF_ERROR_EXISTS: 749fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 750fcf3ce44SJohn Forte operands[0], gettext("already exists")); 751fcf3ce44SJohn Forte ret++; 752fcf3ce44SJohn Forte break; 753fcf3ce44SJohn Forte case STMF_ERROR_BUSY: 754fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %ws: %s\n", cmdName, 755fcf3ce44SJohn Forte operands[0], gettext("resource busy")); 756fcf3ce44SJohn Forte ret++; 757fcf3ce44SJohn Forte break; 758fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_NOT_FOUND: 759fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 760fcf3ce44SJohn Forte gettext("STMF service not found")); 761fcf3ce44SJohn Forte ret++; 762fcf3ce44SJohn Forte break; 763fcf3ce44SJohn Forte case STMF_ERROR_PERM: 764fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 765fcf3ce44SJohn Forte gettext("permission denied")); 766fcf3ce44SJohn Forte ret++; 767fcf3ce44SJohn Forte break; 768fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_DATA_VERSION: 769fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 770fcf3ce44SJohn Forte gettext("STMF service version incorrect")); 771fcf3ce44SJohn Forte ret++; 772fcf3ce44SJohn Forte break; 773fcf3ce44SJohn Forte default: 774fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 775fcf3ce44SJohn Forte operands[0], gettext("unknown error")); 776fcf3ce44SJohn Forte ret++; 777fcf3ce44SJohn Forte break; 778fcf3ce44SJohn Forte } 779fcf3ce44SJohn Forte 780fcf3ce44SJohn Forte return (ret); 781fcf3ce44SJohn Forte } 782fcf3ce44SJohn Forte 783fcf3ce44SJohn Forte /* 784*8fe96085Stim szeto * createLuFunc 785*8fe96085Stim szeto * 786*8fe96085Stim szeto * Create a logical unit 787*8fe96085Stim szeto * 788*8fe96085Stim szeto */ 789*8fe96085Stim szeto /*ARGSUSED*/ 790*8fe96085Stim szeto static int 791*8fe96085Stim szeto createLuFunc(int operandLen, char *operands[], cmdOptions_t *options, 792*8fe96085Stim szeto void *args) 793*8fe96085Stim szeto { 794*8fe96085Stim szeto luResource hdl = NULL; 795*8fe96085Stim szeto int ret = 0; 796*8fe96085Stim szeto int stmfRet = 0; 797*8fe96085Stim szeto char guidAsciiBuf[33]; 798*8fe96085Stim szeto stmfGuid createdGuid; 799*8fe96085Stim szeto 800*8fe96085Stim szeto stmfRet = stmfCreateLuResource(STMF_DISK, &hdl); 801*8fe96085Stim szeto 802*8fe96085Stim szeto if (stmfRet != STMF_STATUS_SUCCESS) { 803*8fe96085Stim szeto (void) fprintf(stderr, "%s: %s\n", 804*8fe96085Stim szeto cmdName, gettext("Failure to create lu resource\n")); 805*8fe96085Stim szeto return (1); 806*8fe96085Stim szeto } 807*8fe96085Stim szeto 808*8fe96085Stim szeto for (; options->optval; options++) { 809*8fe96085Stim szeto switch (options->optval) { 810*8fe96085Stim szeto case 'p': 811*8fe96085Stim szeto ret = setLuPropFromInput(hdl, options->optarg); 812*8fe96085Stim szeto if (ret != 0) { 813*8fe96085Stim szeto (void) stmfFreeLuResource(hdl); 814*8fe96085Stim szeto return (1); 815*8fe96085Stim szeto } 816*8fe96085Stim szeto break; 817*8fe96085Stim szeto case 's': 818*8fe96085Stim szeto stmfRet = stmfSetLuProp(hdl, STMF_LU_PROP_SIZE, 819*8fe96085Stim szeto options->optarg); 820*8fe96085Stim szeto if (stmfRet != STMF_STATUS_SUCCESS) { 821*8fe96085Stim szeto (void) fprintf(stderr, "%s: %c: %s\n", 822*8fe96085Stim szeto cmdName, options->optval, 823*8fe96085Stim szeto gettext("size param invalid")); 824*8fe96085Stim szeto (void) stmfFreeLuResource(hdl); 825*8fe96085Stim szeto return (1); 826*8fe96085Stim szeto } 827*8fe96085Stim szeto break; 828*8fe96085Stim szeto default: 829*8fe96085Stim szeto (void) fprintf(stderr, "%s: %c: %s\n", 830*8fe96085Stim szeto cmdName, options->optval, 831*8fe96085Stim szeto gettext("unknown option")); 832*8fe96085Stim szeto return (1); 833*8fe96085Stim szeto } 834*8fe96085Stim szeto } 835*8fe96085Stim szeto 836*8fe96085Stim szeto stmfRet = stmfSetLuProp(hdl, STMF_LU_PROP_FILENAME, operands[0]); 837*8fe96085Stim szeto 838*8fe96085Stim szeto if (stmfRet != STMF_STATUS_SUCCESS) { 839*8fe96085Stim szeto (void) fprintf(stderr, "%s: %s\n", 840*8fe96085Stim szeto cmdName, gettext("could not set filename")); 841*8fe96085Stim szeto return (1); 842*8fe96085Stim szeto } 843*8fe96085Stim szeto 844*8fe96085Stim szeto stmfRet = stmfCreateLu(hdl, &createdGuid); 845*8fe96085Stim szeto switch (stmfRet) { 846*8fe96085Stim szeto case STMF_STATUS_SUCCESS: 847*8fe96085Stim szeto break; 848*8fe96085Stim szeto case STMF_ERROR_BUSY: 849*8fe96085Stim szeto case STMF_ERROR_LU_BUSY: 850*8fe96085Stim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 851*8fe96085Stim szeto gettext("resource busy")); 852*8fe96085Stim szeto ret++; 853*8fe96085Stim szeto break; 854*8fe96085Stim szeto case STMF_ERROR_PERM: 855*8fe96085Stim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 856*8fe96085Stim szeto gettext("permission denied")); 857*8fe96085Stim szeto ret++; 858*8fe96085Stim szeto break; 859*8fe96085Stim szeto case STMF_ERROR_FILE_IN_USE: 860*8fe96085Stim szeto (void) fprintf(stderr, "%s: filename %s: %s\n", cmdName, 861*8fe96085Stim szeto operands[0], gettext("in use")); 862*8fe96085Stim szeto ret++; 863*8fe96085Stim szeto break; 864*8fe96085Stim szeto case STMF_ERROR_INVALID_BLKSIZE: 865*8fe96085Stim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 866*8fe96085Stim szeto gettext("invalid block size")); 867*8fe96085Stim szeto ret++; 868*8fe96085Stim szeto break; 869*8fe96085Stim szeto case STMF_ERROR_GUID_IN_USE: 870*8fe96085Stim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 871*8fe96085Stim szeto gettext("guid in use")); 872*8fe96085Stim szeto ret++; 873*8fe96085Stim szeto break; 874*8fe96085Stim szeto case STMF_ERROR_META_FILE_NAME: 875*8fe96085Stim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 876*8fe96085Stim szeto gettext("meta file error")); 877*8fe96085Stim szeto ret++; 878*8fe96085Stim szeto break; 879*8fe96085Stim szeto case STMF_ERROR_DATA_FILE_NAME: 880*8fe96085Stim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 881*8fe96085Stim szeto gettext("data file error")); 882*8fe96085Stim szeto ret++; 883*8fe96085Stim szeto break; 884*8fe96085Stim szeto case STMF_ERROR_FILE_SIZE_INVALID: 885*8fe96085Stim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 886*8fe96085Stim szeto gettext("file size invalid")); 887*8fe96085Stim szeto ret++; 888*8fe96085Stim szeto break; 889*8fe96085Stim szeto case STMF_ERROR_SIZE_OUT_OF_RANGE: 890*8fe96085Stim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 891*8fe96085Stim szeto gettext("invalid size")); 892*8fe96085Stim szeto ret++; 893*8fe96085Stim szeto break; 894*8fe96085Stim szeto case STMF_ERROR_META_CREATION: 895*8fe96085Stim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 896*8fe96085Stim szeto gettext("could not create meta file")); 897*8fe96085Stim szeto ret++; 898*8fe96085Stim szeto break; 899*8fe96085Stim szeto case STMF_ERROR_WRITE_CACHE_SET: 900*8fe96085Stim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 901*8fe96085Stim szeto gettext("could not set write cache")); 902*8fe96085Stim szeto ret++; 903*8fe96085Stim szeto break; 904*8fe96085Stim szeto default: 905*8fe96085Stim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 906*8fe96085Stim szeto gettext("unknown error")); 907*8fe96085Stim szeto ret++; 908*8fe96085Stim szeto break; 909*8fe96085Stim szeto } 910*8fe96085Stim szeto 911*8fe96085Stim szeto if (ret != 0) { 912*8fe96085Stim szeto goto done; 913*8fe96085Stim szeto } 914*8fe96085Stim szeto 915*8fe96085Stim szeto (void) snprintf(guidAsciiBuf, sizeof (guidAsciiBuf), 916*8fe96085Stim szeto "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X" 917*8fe96085Stim szeto "%02X%02X%02X%02X%02X%02X", 918*8fe96085Stim szeto createdGuid.guid[0], createdGuid.guid[1], createdGuid.guid[2], 919*8fe96085Stim szeto createdGuid.guid[3], createdGuid.guid[4], createdGuid.guid[5], 920*8fe96085Stim szeto createdGuid.guid[6], createdGuid.guid[7], createdGuid.guid[8], 921*8fe96085Stim szeto createdGuid.guid[9], createdGuid.guid[10], createdGuid.guid[11], 922*8fe96085Stim szeto createdGuid.guid[12], createdGuid.guid[13], createdGuid.guid[14], 923*8fe96085Stim szeto createdGuid.guid[15]); 924*8fe96085Stim szeto (void) printf("Logical unit created: %s\n", guidAsciiBuf); 925*8fe96085Stim szeto 926*8fe96085Stim szeto done: 927*8fe96085Stim szeto (void) stmfFreeLuResource(hdl); 928*8fe96085Stim szeto return (ret); 929*8fe96085Stim szeto } 930*8fe96085Stim szeto 931*8fe96085Stim szeto /* 932*8fe96085Stim szeto * createLuFunc 933*8fe96085Stim szeto * 934*8fe96085Stim szeto * Create a logical unit 935*8fe96085Stim szeto * 936*8fe96085Stim szeto */ 937*8fe96085Stim szeto /*ARGSUSED*/ 938*8fe96085Stim szeto static int 939*8fe96085Stim szeto modifyLuFunc(int operandLen, char *operands[], cmdOptions_t *options, 940*8fe96085Stim szeto void *args) 941*8fe96085Stim szeto { 942*8fe96085Stim szeto stmfGuid inGuid; 943*8fe96085Stim szeto unsigned int guid[sizeof (stmfGuid)]; 944*8fe96085Stim szeto int ret = 0; 945*8fe96085Stim szeto int i; 946*8fe96085Stim szeto char *fname = NULL; 947*8fe96085Stim szeto char *lasts = NULL; 948*8fe96085Stim szeto char sGuid[GUID_INPUT + 1]; 949*8fe96085Stim szeto char *prop = NULL; 950*8fe96085Stim szeto char *propVal = NULL; 951*8fe96085Stim szeto boolean_t fnameUsed = B_FALSE; 952*8fe96085Stim szeto uint32_t propId; 953*8fe96085Stim szeto cmdOptions_t *optionStart = options; 954*8fe96085Stim szeto 955*8fe96085Stim szeto 956*8fe96085Stim szeto for (; options->optval; options++) { 957*8fe96085Stim szeto switch (options->optval) { 958*8fe96085Stim szeto case 'f': 959*8fe96085Stim szeto fnameUsed = B_TRUE; 960*8fe96085Stim szeto fname = operands[0]; 961*8fe96085Stim szeto break; 962*8fe96085Stim szeto } 963*8fe96085Stim szeto } 964*8fe96085Stim szeto options = optionStart; 965*8fe96085Stim szeto 966*8fe96085Stim szeto /* check input length */ 967*8fe96085Stim szeto if (!fnameUsed && strlen(operands[0]) != GUID_INPUT) { 968*8fe96085Stim szeto (void) fprintf(stderr, "%s: %s: %s%d%s\n", cmdName, operands[0], 969*8fe96085Stim szeto gettext("must be "), GUID_INPUT, 970*8fe96085Stim szeto gettext(" hexadecimal digits")); 971*8fe96085Stim szeto return (1); 972*8fe96085Stim szeto } 973*8fe96085Stim szeto 974*8fe96085Stim szeto if (!fnameUsed) { 975*8fe96085Stim szeto /* convert to lower case for scan */ 976*8fe96085Stim szeto for (i = 0; i < 32; i++) 977*8fe96085Stim szeto sGuid[i] = tolower(operands[0][i]); 978*8fe96085Stim szeto sGuid[i] = 0; 979*8fe96085Stim szeto (void) sscanf(sGuid, 980*8fe96085Stim szeto "%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x", 981*8fe96085Stim szeto &guid[0], &guid[1], &guid[2], &guid[3], &guid[4], &guid[5], 982*8fe96085Stim szeto &guid[6], &guid[7], &guid[8], &guid[9], &guid[10], 983*8fe96085Stim szeto &guid[11], &guid[12], &guid[13], &guid[14], &guid[15]); 984*8fe96085Stim szeto 985*8fe96085Stim szeto for (i = 0; i < sizeof (stmfGuid); i++) { 986*8fe96085Stim szeto inGuid.guid[i] = guid[i]; 987*8fe96085Stim szeto } 988*8fe96085Stim szeto } 989*8fe96085Stim szeto 990*8fe96085Stim szeto for (; options->optval; options++) { 991*8fe96085Stim szeto switch (options->optval) { 992*8fe96085Stim szeto case 'p': 993*8fe96085Stim szeto prop = strtok_r(options->optarg, "=", &lasts); 994*8fe96085Stim szeto if ((propVal = strtok_r(NULL, "=", &lasts)) 995*8fe96085Stim szeto == NULL) { 996*8fe96085Stim szeto (void) fprintf(stderr, "%s: %s: %s\n", 997*8fe96085Stim szeto cmdName, options->optarg, 998*8fe96085Stim szeto gettext("invalid property specifier" 999*8fe96085Stim szeto "- prop=val\n")); 1000*8fe96085Stim szeto return (1); 1001*8fe96085Stim szeto } 1002*8fe96085Stim szeto ret = convertCharToPropId(prop, &propId); 1003*8fe96085Stim szeto if (ret != 0) { 1004*8fe96085Stim szeto (void) fprintf(stderr, "%s: %s: %s\n", 1005*8fe96085Stim szeto cmdName, 1006*8fe96085Stim szeto gettext("invalid property specified"), 1007*8fe96085Stim szeto prop); 1008*8fe96085Stim szeto return (1); 1009*8fe96085Stim szeto } 1010*8fe96085Stim szeto if (callModify(fname, &inGuid, propId, propVal, 1011*8fe96085Stim szeto prop) != 0) { 1012*8fe96085Stim szeto return (1); 1013*8fe96085Stim szeto } 1014*8fe96085Stim szeto break; 1015*8fe96085Stim szeto case 's': 1016*8fe96085Stim szeto if (callModify(fname, &inGuid, 1017*8fe96085Stim szeto STMF_LU_PROP_SIZE, options->optarg, 1018*8fe96085Stim szeto "size") != 0) { 1019*8fe96085Stim szeto return (1); 1020*8fe96085Stim szeto } 1021*8fe96085Stim szeto break; 1022*8fe96085Stim szeto case 'f': 1023*8fe96085Stim szeto break; 1024*8fe96085Stim szeto default: 1025*8fe96085Stim szeto (void) fprintf(stderr, "%s: %c: %s\n", 1026*8fe96085Stim szeto cmdName, options->optval, 1027*8fe96085Stim szeto gettext("unknown option")); 1028*8fe96085Stim szeto return (1); 1029*8fe96085Stim szeto } 1030*8fe96085Stim szeto } 1031*8fe96085Stim szeto return (ret); 1032*8fe96085Stim szeto } 1033*8fe96085Stim szeto 1034*8fe96085Stim szeto static int 1035*8fe96085Stim szeto callModify(char *fname, stmfGuid *luGuid, uint32_t prop, const char *propVal, 1036*8fe96085Stim szeto const char *propString) 1037*8fe96085Stim szeto { 1038*8fe96085Stim szeto int ret = 0; 1039*8fe96085Stim szeto int stmfRet = 0; 1040*8fe96085Stim szeto 1041*8fe96085Stim szeto if (!fname) { 1042*8fe96085Stim szeto stmfRet = stmfModifyLu(luGuid, prop, propVal); 1043*8fe96085Stim szeto } else { 1044*8fe96085Stim szeto stmfRet = stmfModifyLuByFname(STMF_DISK, fname, prop, 1045*8fe96085Stim szeto propVal); 1046*8fe96085Stim szeto } 1047*8fe96085Stim szeto switch (stmfRet) { 1048*8fe96085Stim szeto case STMF_STATUS_SUCCESS: 1049*8fe96085Stim szeto break; 1050*8fe96085Stim szeto case STMF_ERROR_BUSY: 1051*8fe96085Stim szeto case STMF_ERROR_LU_BUSY: 1052*8fe96085Stim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 1053*8fe96085Stim szeto gettext("resource busy")); 1054*8fe96085Stim szeto ret++; 1055*8fe96085Stim szeto break; 1056*8fe96085Stim szeto case STMF_ERROR_PERM: 1057*8fe96085Stim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 1058*8fe96085Stim szeto gettext("permission denied")); 1059*8fe96085Stim szeto ret++; 1060*8fe96085Stim szeto break; 1061*8fe96085Stim szeto case STMF_ERROR_INVALID_BLKSIZE: 1062*8fe96085Stim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 1063*8fe96085Stim szeto gettext("invalid block size")); 1064*8fe96085Stim szeto ret++; 1065*8fe96085Stim szeto break; 1066*8fe96085Stim szeto case STMF_ERROR_GUID_IN_USE: 1067*8fe96085Stim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 1068*8fe96085Stim szeto gettext("guid in use")); 1069*8fe96085Stim szeto ret++; 1070*8fe96085Stim szeto break; 1071*8fe96085Stim szeto case STMF_ERROR_META_FILE_NAME: 1072*8fe96085Stim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 1073*8fe96085Stim szeto gettext("meta file error")); 1074*8fe96085Stim szeto ret++; 1075*8fe96085Stim szeto break; 1076*8fe96085Stim szeto case STMF_ERROR_DATA_FILE_NAME: 1077*8fe96085Stim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 1078*8fe96085Stim szeto gettext("data file error")); 1079*8fe96085Stim szeto ret++; 1080*8fe96085Stim szeto break; 1081*8fe96085Stim szeto case STMF_ERROR_FILE_SIZE_INVALID: 1082*8fe96085Stim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 1083*8fe96085Stim szeto gettext("file size invalid")); 1084*8fe96085Stim szeto ret++; 1085*8fe96085Stim szeto break; 1086*8fe96085Stim szeto case STMF_ERROR_SIZE_OUT_OF_RANGE: 1087*8fe96085Stim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 1088*8fe96085Stim szeto gettext("invalid size")); 1089*8fe96085Stim szeto ret++; 1090*8fe96085Stim szeto break; 1091*8fe96085Stim szeto case STMF_ERROR_META_CREATION: 1092*8fe96085Stim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 1093*8fe96085Stim szeto gettext("could not create meta file")); 1094*8fe96085Stim szeto ret++; 1095*8fe96085Stim szeto break; 1096*8fe96085Stim szeto case STMF_ERROR_INVALID_PROP: 1097*8fe96085Stim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 1098*8fe96085Stim szeto gettext("invalid property for modify")); 1099*8fe96085Stim szeto ret++; 1100*8fe96085Stim szeto break; 1101*8fe96085Stim szeto case STMF_ERROR_WRITE_CACHE_SET: 1102*8fe96085Stim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 1103*8fe96085Stim szeto gettext("could not set write cache")); 1104*8fe96085Stim szeto ret++; 1105*8fe96085Stim szeto break; 1106*8fe96085Stim szeto default: 1107*8fe96085Stim szeto (void) fprintf(stderr, "%s: %s: %s: %d\n", cmdName, 1108*8fe96085Stim szeto gettext("could not set property"), propString, 1109*8fe96085Stim szeto stmfRet); 1110*8fe96085Stim szeto ret++; 1111*8fe96085Stim szeto break; 1112*8fe96085Stim szeto } 1113*8fe96085Stim szeto 1114*8fe96085Stim szeto return (ret); 1115*8fe96085Stim szeto } 1116*8fe96085Stim szeto 1117*8fe96085Stim szeto 1118*8fe96085Stim szeto /* 1119*8fe96085Stim szeto * importLuFunc 1120*8fe96085Stim szeto * 1121*8fe96085Stim szeto * Create a logical unit 1122*8fe96085Stim szeto * 1123*8fe96085Stim szeto */ 1124*8fe96085Stim szeto /*ARGSUSED*/ 1125*8fe96085Stim szeto static int 1126*8fe96085Stim szeto importLuFunc(int operandLen, char *operands[], cmdOptions_t *options, 1127*8fe96085Stim szeto void *args) 1128*8fe96085Stim szeto { 1129*8fe96085Stim szeto int stmfRet = 0; 1130*8fe96085Stim szeto int ret = 0; 1131*8fe96085Stim szeto char guidAsciiBuf[33]; 1132*8fe96085Stim szeto stmfGuid createdGuid; 1133*8fe96085Stim szeto 1134*8fe96085Stim szeto stmfRet = stmfImportLu(STMF_DISK, operands[0], &createdGuid); 1135*8fe96085Stim szeto switch (stmfRet) { 1136*8fe96085Stim szeto case STMF_STATUS_SUCCESS: 1137*8fe96085Stim szeto break; 1138*8fe96085Stim szeto case STMF_ERROR_BUSY: 1139*8fe96085Stim szeto case STMF_ERROR_LU_BUSY: 1140*8fe96085Stim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 1141*8fe96085Stim szeto gettext("resource busy")); 1142*8fe96085Stim szeto ret++; 1143*8fe96085Stim szeto break; 1144*8fe96085Stim szeto case STMF_ERROR_PERM: 1145*8fe96085Stim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 1146*8fe96085Stim szeto gettext("permission denied")); 1147*8fe96085Stim szeto ret++; 1148*8fe96085Stim szeto break; 1149*8fe96085Stim szeto case STMF_ERROR_FILE_IN_USE: 1150*8fe96085Stim szeto (void) fprintf(stderr, "%s: filename %s: %s\n", cmdName, 1151*8fe96085Stim szeto operands[0], gettext("in use")); 1152*8fe96085Stim szeto ret++; 1153*8fe96085Stim szeto break; 1154*8fe96085Stim szeto case STMF_ERROR_GUID_IN_USE: 1155*8fe96085Stim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 1156*8fe96085Stim szeto gettext("guid in use")); 1157*8fe96085Stim szeto ret++; 1158*8fe96085Stim szeto break; 1159*8fe96085Stim szeto case STMF_ERROR_META_FILE_NAME: 1160*8fe96085Stim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 1161*8fe96085Stim szeto gettext("meta file error")); 1162*8fe96085Stim szeto ret++; 1163*8fe96085Stim szeto break; 1164*8fe96085Stim szeto case STMF_ERROR_DATA_FILE_NAME: 1165*8fe96085Stim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 1166*8fe96085Stim szeto gettext("data file error")); 1167*8fe96085Stim szeto ret++; 1168*8fe96085Stim szeto break; 1169*8fe96085Stim szeto case STMF_ERROR_META_CREATION: 1170*8fe96085Stim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 1171*8fe96085Stim szeto gettext("could not create meta file")); 1172*8fe96085Stim szeto ret++; 1173*8fe96085Stim szeto break; 1174*8fe96085Stim szeto case STMF_ERROR_WRITE_CACHE_SET: 1175*8fe96085Stim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 1176*8fe96085Stim szeto gettext("could not set write cache")); 1177*8fe96085Stim szeto ret++; 1178*8fe96085Stim szeto break; 1179*8fe96085Stim szeto default: 1180*8fe96085Stim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 1181*8fe96085Stim szeto gettext("unknown error")); 1182*8fe96085Stim szeto ret++; 1183*8fe96085Stim szeto break; 1184*8fe96085Stim szeto } 1185*8fe96085Stim szeto 1186*8fe96085Stim szeto if (ret != STMF_STATUS_SUCCESS) { 1187*8fe96085Stim szeto goto done; 1188*8fe96085Stim szeto } 1189*8fe96085Stim szeto 1190*8fe96085Stim szeto (void) snprintf(guidAsciiBuf, sizeof (guidAsciiBuf), 1191*8fe96085Stim szeto "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X" 1192*8fe96085Stim szeto "%02X%02X%02X%02X%02X%02X", 1193*8fe96085Stim szeto createdGuid.guid[0], createdGuid.guid[1], createdGuid.guid[2], 1194*8fe96085Stim szeto createdGuid.guid[3], createdGuid.guid[4], createdGuid.guid[5], 1195*8fe96085Stim szeto createdGuid.guid[6], createdGuid.guid[7], createdGuid.guid[8], 1196*8fe96085Stim szeto createdGuid.guid[9], createdGuid.guid[10], createdGuid.guid[11], 1197*8fe96085Stim szeto createdGuid.guid[12], createdGuid.guid[13], createdGuid.guid[14], 1198*8fe96085Stim szeto createdGuid.guid[15]); 1199*8fe96085Stim szeto (void) printf("Logical unit imported: %s\n", guidAsciiBuf); 1200*8fe96085Stim szeto 1201*8fe96085Stim szeto done: 1202*8fe96085Stim szeto return (ret); 1203*8fe96085Stim szeto } 1204*8fe96085Stim szeto 1205*8fe96085Stim szeto static int 1206*8fe96085Stim szeto setLuPropFromInput(luResource hdl, char *optarg) 1207*8fe96085Stim szeto { 1208*8fe96085Stim szeto char *prop = NULL; 1209*8fe96085Stim szeto char *propVal = NULL; 1210*8fe96085Stim szeto char *lasts = NULL; 1211*8fe96085Stim szeto uint32_t propId; 1212*8fe96085Stim szeto int ret = 0; 1213*8fe96085Stim szeto 1214*8fe96085Stim szeto prop = strtok_r(optarg, "=", &lasts); 1215*8fe96085Stim szeto if ((propVal = strtok_r(NULL, "=", &lasts)) == NULL) { 1216*8fe96085Stim szeto (void) fprintf(stderr, "%s: %s: %s\n", 1217*8fe96085Stim szeto cmdName, optarg, 1218*8fe96085Stim szeto gettext("invalid property specifier - prop=val\n")); 1219*8fe96085Stim szeto return (1); 1220*8fe96085Stim szeto } 1221*8fe96085Stim szeto 1222*8fe96085Stim szeto ret = convertCharToPropId(prop, &propId); 1223*8fe96085Stim szeto if (ret != 0) { 1224*8fe96085Stim szeto (void) fprintf(stderr, "%s: %s: %s\n", 1225*8fe96085Stim szeto cmdName, gettext("invalid property specified"), prop); 1226*8fe96085Stim szeto return (1); 1227*8fe96085Stim szeto } 1228*8fe96085Stim szeto 1229*8fe96085Stim szeto ret = stmfSetLuProp(hdl, propId, propVal); 1230*8fe96085Stim szeto if (ret != STMF_STATUS_SUCCESS) { 1231*8fe96085Stim szeto (void) fprintf(stderr, "%s: %s %s: ", 1232*8fe96085Stim szeto cmdName, gettext("unable to set"), prop); 1233*8fe96085Stim szeto switch (ret) { 1234*8fe96085Stim szeto case STMF_ERROR_INVALID_PROPSIZE: 1235*8fe96085Stim szeto (void) fprintf(stderr, "invalid length\n"); 1236*8fe96085Stim szeto break; 1237*8fe96085Stim szeto case STMF_ERROR_INVALID_ARG: 1238*8fe96085Stim szeto (void) fprintf(stderr, "bad format\n"); 1239*8fe96085Stim szeto break; 1240*8fe96085Stim szeto default: 1241*8fe96085Stim szeto (void) fprintf(stderr, "\n"); 1242*8fe96085Stim szeto break; 1243*8fe96085Stim szeto } 1244*8fe96085Stim szeto return (1); 1245*8fe96085Stim szeto } 1246*8fe96085Stim szeto 1247*8fe96085Stim szeto return (0); 1248*8fe96085Stim szeto } 1249*8fe96085Stim szeto 1250*8fe96085Stim szeto static int 1251*8fe96085Stim szeto convertCharToPropId(char *prop, uint32_t *propId) 1252*8fe96085Stim szeto { 1253*8fe96085Stim szeto if (strcasecmp(prop, GUID) == 0) { 1254*8fe96085Stim szeto *propId = STMF_LU_PROP_GUID; 1255*8fe96085Stim szeto } else if (strcasecmp(prop, ALIAS) == 0) { 1256*8fe96085Stim szeto *propId = STMF_LU_PROP_ALIAS; 1257*8fe96085Stim szeto } else if (strcasecmp(prop, VID) == 0) { 1258*8fe96085Stim szeto *propId = STMF_LU_PROP_VID; 1259*8fe96085Stim szeto } else if (strcasecmp(prop, PID) == 0) { 1260*8fe96085Stim szeto *propId = STMF_LU_PROP_PID; 1261*8fe96085Stim szeto } else if (strcasecmp(prop, WRITE_PROTECT) == 0) { 1262*8fe96085Stim szeto *propId = STMF_LU_PROP_WRITE_PROTECT; 1263*8fe96085Stim szeto } else if (strcasecmp(prop, WRITEBACK_CACHE_DISABLE) == 0) { 1264*8fe96085Stim szeto *propId = STMF_LU_PROP_WRITE_CACHE_DISABLE; 1265*8fe96085Stim szeto } else if (strcasecmp(prop, BLOCK_SIZE) == 0) { 1266*8fe96085Stim szeto *propId = STMF_LU_PROP_BLOCK_SIZE; 1267*8fe96085Stim szeto } else if (strcasecmp(prop, SERIAL_NUMBER) == 0) { 1268*8fe96085Stim szeto *propId = STMF_LU_PROP_SERIAL_NUM; 1269*8fe96085Stim szeto } else if (strcasecmp(prop, COMPANY_ID) == 0) { 1270*8fe96085Stim szeto *propId = STMF_LU_PROP_COMPANY_ID; 1271*8fe96085Stim szeto } else if (strcasecmp(prop, META_FILE) == 0) { 1272*8fe96085Stim szeto *propId = STMF_LU_PROP_META_FILENAME; 1273*8fe96085Stim szeto } else { 1274*8fe96085Stim szeto return (1); 1275*8fe96085Stim szeto } 1276*8fe96085Stim szeto return (0); 1277*8fe96085Stim szeto } 1278*8fe96085Stim szeto 1279*8fe96085Stim szeto /* 1280*8fe96085Stim szeto * deleteLuFunc 1281*8fe96085Stim szeto * 1282*8fe96085Stim szeto * Delete a logical unit 1283*8fe96085Stim szeto * 1284*8fe96085Stim szeto */ 1285*8fe96085Stim szeto /*ARGSUSED*/ 1286*8fe96085Stim szeto static int 1287*8fe96085Stim szeto deleteLuFunc(int operandLen, char *operands[], cmdOptions_t *options, 1288*8fe96085Stim szeto void *args) 1289*8fe96085Stim szeto { 1290*8fe96085Stim szeto int i, j; 1291*8fe96085Stim szeto int ret = 0; 1292*8fe96085Stim szeto int stmfRet; 1293*8fe96085Stim szeto unsigned int inGuid[sizeof (stmfGuid)]; 1294*8fe96085Stim szeto stmfGuid delGuid; 1295*8fe96085Stim szeto boolean_t keepViews = B_FALSE; 1296*8fe96085Stim szeto boolean_t viewEntriesRemoved = B_FALSE; 1297*8fe96085Stim szeto boolean_t noLunFound = B_FALSE; 1298*8fe96085Stim szeto boolean_t views = B_FALSE; 1299*8fe96085Stim szeto char sGuid[GUID_INPUT + 1]; 1300*8fe96085Stim szeto stmfViewEntryList *viewEntryList = NULL; 1301*8fe96085Stim szeto 1302*8fe96085Stim szeto for (; options->optval; options++) { 1303*8fe96085Stim szeto switch (options->optval) { 1304*8fe96085Stim szeto /* Keep views for logical unit */ 1305*8fe96085Stim szeto case 'k': 1306*8fe96085Stim szeto keepViews = B_TRUE; 1307*8fe96085Stim szeto break; 1308*8fe96085Stim szeto default: 1309*8fe96085Stim szeto (void) fprintf(stderr, "%s: %c: %s\n", 1310*8fe96085Stim szeto cmdName, options->optval, 1311*8fe96085Stim szeto gettext("unknown option")); 1312*8fe96085Stim szeto return (1); 1313*8fe96085Stim szeto } 1314*8fe96085Stim szeto } 1315*8fe96085Stim szeto 1316*8fe96085Stim szeto 1317*8fe96085Stim szeto for (i = 0; i < operandLen; i++) { 1318*8fe96085Stim szeto for (j = 0; j < GUID_INPUT; j++) { 1319*8fe96085Stim szeto if (!isxdigit(operands[i][j])) { 1320*8fe96085Stim szeto break; 1321*8fe96085Stim szeto } 1322*8fe96085Stim szeto sGuid[j] = tolower(operands[i][j]); 1323*8fe96085Stim szeto } 1324*8fe96085Stim szeto if (j != GUID_INPUT) { 1325*8fe96085Stim szeto (void) fprintf(stderr, "%s: %s: %s%d%s\n", 1326*8fe96085Stim szeto cmdName, operands[i], gettext("must be "), 1327*8fe96085Stim szeto GUID_INPUT, 1328*8fe96085Stim szeto gettext(" hexadecimal digits long")); 1329*8fe96085Stim szeto continue; 1330*8fe96085Stim szeto } 1331*8fe96085Stim szeto 1332*8fe96085Stim szeto sGuid[j] = 0; 1333*8fe96085Stim szeto 1334*8fe96085Stim szeto (void) sscanf(sGuid, 1335*8fe96085Stim szeto "%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x", 1336*8fe96085Stim szeto &inGuid[0], &inGuid[1], &inGuid[2], &inGuid[3], 1337*8fe96085Stim szeto &inGuid[4], &inGuid[5], &inGuid[6], &inGuid[7], 1338*8fe96085Stim szeto &inGuid[8], &inGuid[9], &inGuid[10], &inGuid[11], 1339*8fe96085Stim szeto &inGuid[12], &inGuid[13], &inGuid[14], &inGuid[15]); 1340*8fe96085Stim szeto 1341*8fe96085Stim szeto for (j = 0; j < sizeof (stmfGuid); j++) { 1342*8fe96085Stim szeto delGuid.guid[j] = inGuid[j]; 1343*8fe96085Stim szeto } 1344*8fe96085Stim szeto 1345*8fe96085Stim szeto stmfRet = stmfDeleteLu(&delGuid); 1346*8fe96085Stim szeto switch (stmfRet) { 1347*8fe96085Stim szeto case STMF_STATUS_SUCCESS: 1348*8fe96085Stim szeto break; 1349*8fe96085Stim szeto case STMF_ERROR_NOT_FOUND: 1350*8fe96085Stim szeto noLunFound = B_TRUE; 1351*8fe96085Stim szeto break; 1352*8fe96085Stim szeto case STMF_ERROR_BUSY: 1353*8fe96085Stim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 1354*8fe96085Stim szeto gettext("resource busy")); 1355*8fe96085Stim szeto ret++; 1356*8fe96085Stim szeto break; 1357*8fe96085Stim szeto case STMF_ERROR_PERM: 1358*8fe96085Stim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 1359*8fe96085Stim szeto gettext("permission denied")); 1360*8fe96085Stim szeto ret++; 1361*8fe96085Stim szeto break; 1362*8fe96085Stim szeto default: 1363*8fe96085Stim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 1364*8fe96085Stim szeto gettext("unknown error")); 1365*8fe96085Stim szeto ret++; 1366*8fe96085Stim szeto break; 1367*8fe96085Stim szeto } 1368*8fe96085Stim szeto 1369*8fe96085Stim szeto if (!keepViews) { 1370*8fe96085Stim szeto stmfRet = stmfGetViewEntryList(&delGuid, 1371*8fe96085Stim szeto &viewEntryList); 1372*8fe96085Stim szeto if (stmfRet == STMF_STATUS_SUCCESS) { 1373*8fe96085Stim szeto for (j = 0; j < viewEntryList->cnt; j++) { 1374*8fe96085Stim szeto (void) stmfRemoveViewEntry(&delGuid, 1375*8fe96085Stim szeto viewEntryList->ve[j].veIndex); 1376*8fe96085Stim szeto } 1377*8fe96085Stim szeto viewEntriesRemoved = B_TRUE; 1378*8fe96085Stim szeto stmfFreeMemory(viewEntryList); 1379*8fe96085Stim szeto } else if (stmfRet != STMF_ERROR_NOT_FOUND) { 1380*8fe96085Stim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 1381*8fe96085Stim szeto gettext("unable to remove view entries\n")); 1382*8fe96085Stim szeto ret++; 1383*8fe96085Stim szeto } /* No view entries to remove */ 1384*8fe96085Stim szeto } 1385*8fe96085Stim szeto if (keepViews) { 1386*8fe96085Stim szeto stmfRet = stmfGetViewEntryList(&delGuid, 1387*8fe96085Stim szeto &viewEntryList); 1388*8fe96085Stim szeto if (stmfRet == STMF_STATUS_SUCCESS) { 1389*8fe96085Stim szeto views = B_TRUE; 1390*8fe96085Stim szeto stmfFreeMemory(viewEntryList); 1391*8fe96085Stim szeto } 1392*8fe96085Stim szeto } 1393*8fe96085Stim szeto 1394*8fe96085Stim szeto if ((!viewEntriesRemoved && noLunFound && !views) || 1395*8fe96085Stim szeto (!views && keepViews && noLunFound)) { 1396*8fe96085Stim szeto (void) fprintf(stderr, "%s: %s: %s\n", 1397*8fe96085Stim szeto cmdName, sGuid, 1398*8fe96085Stim szeto gettext("not found")); 1399*8fe96085Stim szeto ret++; 1400*8fe96085Stim szeto } 1401*8fe96085Stim szeto noLunFound = viewEntriesRemoved = views = B_FALSE; 1402*8fe96085Stim szeto } 1403*8fe96085Stim szeto return (ret); 1404*8fe96085Stim szeto } 1405*8fe96085Stim szeto 1406*8fe96085Stim szeto 1407*8fe96085Stim szeto /* 1408fcf3ce44SJohn Forte * createTargetGroupFunc 1409fcf3ce44SJohn Forte * 1410fcf3ce44SJohn Forte * Create a target group 1411fcf3ce44SJohn Forte * 1412fcf3ce44SJohn Forte */ 1413fcf3ce44SJohn Forte /*ARGSUSED*/ 1414fcf3ce44SJohn Forte static int 1415fcf3ce44SJohn Forte createTargetGroupFunc(int operandLen, char *operands[], cmdOptions_t *options, 1416fcf3ce44SJohn Forte void *args) 1417fcf3ce44SJohn Forte { 1418fcf3ce44SJohn Forte int ret = 0; 1419fcf3ce44SJohn Forte int stmfRet; 14203e7352aeSJohn Forte wchar_t groupNamePrint[sizeof (stmfGroupName)] = {0}; 14213e7352aeSJohn Forte stmfGroupName groupName = {0}; 1422fcf3ce44SJohn Forte 1423fcf3ce44SJohn Forte (void) strlcpy(groupName, operands[0], sizeof (groupName)); 1424fcf3ce44SJohn Forte (void) mbstowcs(groupNamePrint, (char *)groupName, 14253e7352aeSJohn Forte sizeof (stmfGroupName) - 1); 1426fcf3ce44SJohn Forte /* call create group */ 1427fcf3ce44SJohn Forte stmfRet = stmfCreateTargetGroup(&groupName); 1428fcf3ce44SJohn Forte switch (stmfRet) { 1429fcf3ce44SJohn Forte case STMF_STATUS_SUCCESS: 1430fcf3ce44SJohn Forte break; 1431fcf3ce44SJohn Forte case STMF_ERROR_EXISTS: 1432fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %ws: %s\n", cmdName, 1433fcf3ce44SJohn Forte groupNamePrint, gettext("already exists")); 1434fcf3ce44SJohn Forte ret++; 1435fcf3ce44SJohn Forte break; 1436fcf3ce44SJohn Forte case STMF_ERROR_BUSY: 1437fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %ws: %s\n", cmdName, 1438fcf3ce44SJohn Forte groupNamePrint, gettext("resource busy")); 1439fcf3ce44SJohn Forte ret++; 1440fcf3ce44SJohn Forte break; 1441fcf3ce44SJohn Forte case STMF_ERROR_PERM: 1442fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 1443fcf3ce44SJohn Forte gettext("permission denied")); 1444fcf3ce44SJohn Forte ret++; 1445fcf3ce44SJohn Forte break; 1446fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_NOT_FOUND: 1447fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 1448fcf3ce44SJohn Forte gettext("STMF service not found")); 1449fcf3ce44SJohn Forte ret++; 1450fcf3ce44SJohn Forte break; 1451fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_DATA_VERSION: 1452fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 1453fcf3ce44SJohn Forte gettext("STMF service version incorrect")); 1454fcf3ce44SJohn Forte ret++; 1455fcf3ce44SJohn Forte break; 1456fcf3ce44SJohn Forte default: 1457fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %ws: %s\n", cmdName, 1458fcf3ce44SJohn Forte groupNamePrint, gettext("unknown error")); 1459fcf3ce44SJohn Forte ret++; 1460fcf3ce44SJohn Forte break; 1461fcf3ce44SJohn Forte } 1462fcf3ce44SJohn Forte 1463fcf3ce44SJohn Forte return (ret); 1464fcf3ce44SJohn Forte } 1465fcf3ce44SJohn Forte 1466fcf3ce44SJohn Forte /* 1467fcf3ce44SJohn Forte * deleteHostGroupFunc 1468fcf3ce44SJohn Forte * 1469fcf3ce44SJohn Forte * Delete a host group 1470fcf3ce44SJohn Forte * 1471fcf3ce44SJohn Forte */ 1472fcf3ce44SJohn Forte /*ARGSUSED*/ 1473fcf3ce44SJohn Forte static int 1474fcf3ce44SJohn Forte deleteHostGroupFunc(int operandLen, char *operands[], 1475fcf3ce44SJohn Forte cmdOptions_t *options, void *args) 1476fcf3ce44SJohn Forte { 1477fcf3ce44SJohn Forte int ret = 0; 1478fcf3ce44SJohn Forte int stmfRet; 14793e7352aeSJohn Forte wchar_t groupNamePrint[sizeof (stmfGroupName)] = {0}; 14803e7352aeSJohn Forte stmfGroupName groupName = {0}; 1481fcf3ce44SJohn Forte 1482fcf3ce44SJohn Forte (void) strlcpy(groupName, operands[0], sizeof (groupName)); 1483fcf3ce44SJohn Forte (void) mbstowcs(groupNamePrint, (char *)groupName, 14843e7352aeSJohn Forte sizeof (stmfGroupName) - 1); 1485fcf3ce44SJohn Forte /* call delete group */ 1486fcf3ce44SJohn Forte stmfRet = stmfDeleteHostGroup(&groupName); 1487fcf3ce44SJohn Forte switch (stmfRet) { 1488fcf3ce44SJohn Forte case STMF_STATUS_SUCCESS: 1489fcf3ce44SJohn Forte break; 1490fcf3ce44SJohn Forte case STMF_ERROR_NOT_FOUND: 1491fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %ws: %s\n", cmdName, 1492fcf3ce44SJohn Forte groupNamePrint, gettext("not found")); 1493fcf3ce44SJohn Forte ret++; 1494fcf3ce44SJohn Forte break; 1495fcf3ce44SJohn Forte case STMF_ERROR_BUSY: 1496fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %ws: %s\n", cmdName, 1497fcf3ce44SJohn Forte groupNamePrint, gettext("resource busy")); 1498fcf3ce44SJohn Forte ret++; 1499fcf3ce44SJohn Forte break; 1500fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_NOT_FOUND: 1501fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 1502fcf3ce44SJohn Forte gettext("STMF service not found")); 1503fcf3ce44SJohn Forte ret++; 1504fcf3ce44SJohn Forte break; 1505fcf3ce44SJohn Forte case STMF_ERROR_PERM: 1506fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 1507fcf3ce44SJohn Forte gettext("permission denied")); 1508fcf3ce44SJohn Forte ret++; 1509fcf3ce44SJohn Forte break; 1510fcf3ce44SJohn Forte case STMF_ERROR_GROUP_IN_USE: 1511fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %ws: %s\n", cmdName, 1512fcf3ce44SJohn Forte groupNamePrint, 1513fcf3ce44SJohn Forte gettext("group is in use by existing view entry")); 1514fcf3ce44SJohn Forte ret++; 1515fcf3ce44SJohn Forte break; 1516fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_DATA_VERSION: 1517fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 1518fcf3ce44SJohn Forte gettext("STMF service version incorrect")); 1519fcf3ce44SJohn Forte ret++; 1520fcf3ce44SJohn Forte break; 1521fcf3ce44SJohn Forte default: 1522fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %ws: %s\n", cmdName, 1523fcf3ce44SJohn Forte groupNamePrint, gettext("unknown error")); 1524fcf3ce44SJohn Forte ret++; 1525fcf3ce44SJohn Forte break; 1526fcf3ce44SJohn Forte } 1527fcf3ce44SJohn Forte 1528fcf3ce44SJohn Forte return (ret); 1529fcf3ce44SJohn Forte } 1530fcf3ce44SJohn Forte 1531fcf3ce44SJohn Forte /* 1532fcf3ce44SJohn Forte * deleteTargetGroupFunc 1533fcf3ce44SJohn Forte * 1534fcf3ce44SJohn Forte * Delete a target group 1535fcf3ce44SJohn Forte * 1536fcf3ce44SJohn Forte */ 1537fcf3ce44SJohn Forte /*ARGSUSED*/ 1538fcf3ce44SJohn Forte static int 1539fcf3ce44SJohn Forte deleteTargetGroupFunc(int operandLen, char *operands[], cmdOptions_t *options, 1540fcf3ce44SJohn Forte void *args) 1541fcf3ce44SJohn Forte { 1542fcf3ce44SJohn Forte int ret = 0; 1543fcf3ce44SJohn Forte int stmfRet; 15443e7352aeSJohn Forte wchar_t groupNamePrint[sizeof (stmfGroupName)] = {0}; 15453e7352aeSJohn Forte stmfGroupName groupName = {0}; 1546fcf3ce44SJohn Forte 1547fcf3ce44SJohn Forte (void) strlcpy(groupName, operands[0], sizeof (groupName)); 1548fcf3ce44SJohn Forte (void) mbstowcs(groupNamePrint, (char *)groupName, 15493e7352aeSJohn Forte sizeof (stmfGroupName) - 1); 1550fcf3ce44SJohn Forte /* call delete group */ 1551fcf3ce44SJohn Forte stmfRet = stmfDeleteTargetGroup(&groupName); 1552fcf3ce44SJohn Forte switch (stmfRet) { 1553fcf3ce44SJohn Forte case STMF_STATUS_SUCCESS: 1554fcf3ce44SJohn Forte break; 1555fcf3ce44SJohn Forte case STMF_ERROR_NOT_FOUND: 1556fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %ws: %s\n", cmdName, 1557fcf3ce44SJohn Forte groupNamePrint, gettext("not found")); 1558fcf3ce44SJohn Forte ret++; 1559fcf3ce44SJohn Forte break; 1560fcf3ce44SJohn Forte case STMF_ERROR_BUSY: 1561fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %ws: %s\n", cmdName, 1562fcf3ce44SJohn Forte groupNamePrint, gettext("resource busy")); 1563fcf3ce44SJohn Forte ret++; 1564fcf3ce44SJohn Forte break; 1565fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_NOT_FOUND: 1566fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 1567fcf3ce44SJohn Forte gettext("STMF service not found")); 1568fcf3ce44SJohn Forte ret++; 1569fcf3ce44SJohn Forte break; 1570fcf3ce44SJohn Forte case STMF_ERROR_PERM: 1571fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 1572fcf3ce44SJohn Forte gettext("permission denied")); 1573fcf3ce44SJohn Forte ret++; 1574fcf3ce44SJohn Forte break; 1575fcf3ce44SJohn Forte case STMF_ERROR_GROUP_IN_USE: 1576fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %ws: %s\n", cmdName, 1577fcf3ce44SJohn Forte groupNamePrint, 1578fcf3ce44SJohn Forte gettext("group is in use by existing view entry")); 1579fcf3ce44SJohn Forte ret++; 1580fcf3ce44SJohn Forte break; 1581fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_DATA_VERSION: 1582fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 1583fcf3ce44SJohn Forte gettext("STMF service version incorrect")); 1584fcf3ce44SJohn Forte ret++; 1585fcf3ce44SJohn Forte break; 1586fcf3ce44SJohn Forte default: 1587fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %ws: %s\n", cmdName, 1588fcf3ce44SJohn Forte groupNamePrint, gettext("unknown error")); 1589fcf3ce44SJohn Forte ret++; 1590fcf3ce44SJohn Forte break; 1591fcf3ce44SJohn Forte } 1592fcf3ce44SJohn Forte 1593fcf3ce44SJohn Forte return (ret); 1594fcf3ce44SJohn Forte } 1595fcf3ce44SJohn Forte 1596fcf3ce44SJohn Forte /* 1597fcf3ce44SJohn Forte * listHostGroupFunc 1598fcf3ce44SJohn Forte * 1599fcf3ce44SJohn Forte * Lists the specified host groups or all if none are specified 1600fcf3ce44SJohn Forte * 1601fcf3ce44SJohn Forte */ 1602fcf3ce44SJohn Forte /*ARGSUSED*/ 1603fcf3ce44SJohn Forte static int 1604fcf3ce44SJohn Forte listHostGroupFunc(int operandLen, char *operands[], cmdOptions_t *options, 1605fcf3ce44SJohn Forte void *args) 1606fcf3ce44SJohn Forte { 1607fcf3ce44SJohn Forte int ret = 0; 1608fcf3ce44SJohn Forte int stmfRet; 1609fcf3ce44SJohn Forte int i, j, outerLoop; 1610fcf3ce44SJohn Forte boolean_t verbose = B_FALSE; 1611fcf3ce44SJohn Forte boolean_t found = B_TRUE; 1612fcf3ce44SJohn Forte boolean_t operandEntered; 1613fcf3ce44SJohn Forte stmfGroupList *groupList; 1614fcf3ce44SJohn Forte stmfGroupProperties *groupProps; 1615fcf3ce44SJohn Forte wchar_t operandName[sizeof (stmfGroupName)]; 1616fcf3ce44SJohn Forte wchar_t groupNamePrint[sizeof (stmfGroupName)]; 1617fcf3ce44SJohn Forte 1618fcf3ce44SJohn Forte for (; options->optval; options++) { 1619fcf3ce44SJohn Forte switch (options->optval) { 1620fcf3ce44SJohn Forte case 'v': 1621fcf3ce44SJohn Forte verbose = B_TRUE; 1622fcf3ce44SJohn Forte break; 1623fcf3ce44SJohn Forte default: 1624fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %c: %s\n", 1625fcf3ce44SJohn Forte cmdName, options->optval, 1626fcf3ce44SJohn Forte gettext("unknown option")); 1627fcf3ce44SJohn Forte return (1); 1628fcf3ce44SJohn Forte } 1629fcf3ce44SJohn Forte } 1630fcf3ce44SJohn Forte 1631fcf3ce44SJohn Forte if (operandLen > 0) { 1632fcf3ce44SJohn Forte outerLoop = operandLen; 1633fcf3ce44SJohn Forte operandEntered = B_TRUE; 1634fcf3ce44SJohn Forte } else { 1635fcf3ce44SJohn Forte outerLoop = 1; 1636fcf3ce44SJohn Forte operandEntered = B_FALSE; 1637fcf3ce44SJohn Forte } 1638fcf3ce44SJohn Forte 1639fcf3ce44SJohn Forte stmfRet = stmfGetHostGroupList(&groupList); 1640fcf3ce44SJohn Forte if (stmfRet != STMF_STATUS_SUCCESS) { 1641fcf3ce44SJohn Forte switch (stmfRet) { 1642fcf3ce44SJohn Forte case STMF_ERROR_BUSY: 1643fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 1644fcf3ce44SJohn Forte gettext("resource busy")); 1645fcf3ce44SJohn Forte break; 1646fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_NOT_FOUND: 1647fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 1648fcf3ce44SJohn Forte gettext("STMF service not found")); 1649fcf3ce44SJohn Forte break; 1650fcf3ce44SJohn Forte case STMF_ERROR_PERM: 1651fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 1652fcf3ce44SJohn Forte gettext("permission denied")); 1653fcf3ce44SJohn Forte break; 1654fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_DATA_VERSION: 1655fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 1656fcf3ce44SJohn Forte gettext("STMF service version incorrect")); 1657fcf3ce44SJohn Forte break; 1658fcf3ce44SJohn Forte default: 1659fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 1660fcf3ce44SJohn Forte gettext("unknown error")); 1661fcf3ce44SJohn Forte break; 1662fcf3ce44SJohn Forte } 1663fcf3ce44SJohn Forte return (1); 1664fcf3ce44SJohn Forte } 1665fcf3ce44SJohn Forte 1666fcf3ce44SJohn Forte for (i = 0; i < outerLoop; i++) { 1667fcf3ce44SJohn Forte for (found = B_FALSE, j = 0; j < groupList->cnt; j++) { 1668fcf3ce44SJohn Forte (void) mbstowcs(groupNamePrint, 1669fcf3ce44SJohn Forte (char *)groupList->name[j], 16703e7352aeSJohn Forte sizeof (stmfGroupName) - 1); 16713e7352aeSJohn Forte groupNamePrint[sizeof (stmfGroupName) - 1] = 0; 1672fcf3ce44SJohn Forte if (operandEntered) { 1673fcf3ce44SJohn Forte (void) mbstowcs(operandName, operands[i], 16743e7352aeSJohn Forte sizeof (stmfGroupName) - 1); 16753e7352aeSJohn Forte operandName[sizeof (stmfGroupName) - 1] = 0; 1676fcf3ce44SJohn Forte if (wcscmp(operandName, groupNamePrint) 1677fcf3ce44SJohn Forte == 0) { 1678fcf3ce44SJohn Forte found = B_TRUE; 1679fcf3ce44SJohn Forte } 1680fcf3ce44SJohn Forte } 1681fcf3ce44SJohn Forte if ((found && operandEntered) || !operandEntered) { 1682fcf3ce44SJohn Forte (void) printf("Host Group: %ws\n", 1683fcf3ce44SJohn Forte groupNamePrint); 1684fcf3ce44SJohn Forte if (verbose) { 1685fcf3ce44SJohn Forte stmfRet = stmfGetHostGroupMembers( 1686fcf3ce44SJohn Forte &(groupList->name[j]), &groupProps); 1687fcf3ce44SJohn Forte if (stmfRet != STMF_STATUS_SUCCESS) { 1688fcf3ce44SJohn Forte return (1); 1689fcf3ce44SJohn Forte } 1690fcf3ce44SJohn Forte printGroupProps(groupProps); 1691fcf3ce44SJohn Forte } 1692fcf3ce44SJohn Forte if (found && operandEntered) { 1693fcf3ce44SJohn Forte break; 1694fcf3ce44SJohn Forte } 1695fcf3ce44SJohn Forte } 1696fcf3ce44SJohn Forte 1697fcf3ce44SJohn Forte } 1698fcf3ce44SJohn Forte if (operandEntered && !found) { 1699fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 1700fcf3ce44SJohn Forte operands[i], gettext("not found")); 1701fcf3ce44SJohn Forte ret = 1; 1702fcf3ce44SJohn Forte } 1703fcf3ce44SJohn Forte } 1704fcf3ce44SJohn Forte return (ret); 1705fcf3ce44SJohn Forte } 1706fcf3ce44SJohn Forte 1707fcf3ce44SJohn Forte /* 1708fcf3ce44SJohn Forte * printGroupProps 1709fcf3ce44SJohn Forte * 1710fcf3ce44SJohn Forte * Prints group members for target or host groups 1711fcf3ce44SJohn Forte * 1712fcf3ce44SJohn Forte */ 1713fcf3ce44SJohn Forte static void 1714fcf3ce44SJohn Forte printGroupProps(stmfGroupProperties *groupProps) 1715fcf3ce44SJohn Forte { 1716fcf3ce44SJohn Forte int i; 17173e7352aeSJohn Forte wchar_t memberIdent[sizeof (groupProps->name[0].ident) + 1] = {0}; 1718fcf3ce44SJohn Forte 1719fcf3ce44SJohn Forte 1720fcf3ce44SJohn Forte for (i = 0; i < groupProps->cnt; i++) { 1721fcf3ce44SJohn Forte (void) mbstowcs(memberIdent, (char *)groupProps->name[i].ident, 17223e7352aeSJohn Forte sizeof (groupProps->name[0].ident)); 1723fcf3ce44SJohn Forte (void) printf("\tMember: %ws\n", memberIdent); 1724fcf3ce44SJohn Forte } 1725fcf3ce44SJohn Forte } 1726fcf3ce44SJohn Forte 1727fcf3ce44SJohn Forte /* 1728fcf3ce44SJohn Forte * listTargetGroupFunc 1729fcf3ce44SJohn Forte * 1730fcf3ce44SJohn Forte * Lists the specified target groups or all if none are specified 1731fcf3ce44SJohn Forte * 1732fcf3ce44SJohn Forte */ 1733fcf3ce44SJohn Forte /*ARGSUSED*/ 1734fcf3ce44SJohn Forte static int 1735fcf3ce44SJohn Forte listTargetGroupFunc(int operandLen, char *operands[], cmdOptions_t *options, 1736fcf3ce44SJohn Forte void *args) 1737fcf3ce44SJohn Forte { 1738fcf3ce44SJohn Forte int ret = 0; 1739fcf3ce44SJohn Forte int stmfRet; 1740fcf3ce44SJohn Forte int i, j, outerLoop; 1741fcf3ce44SJohn Forte boolean_t verbose = B_FALSE; 1742fcf3ce44SJohn Forte boolean_t found = B_TRUE; 1743fcf3ce44SJohn Forte boolean_t operandEntered; 1744fcf3ce44SJohn Forte stmfGroupList *groupList; 1745fcf3ce44SJohn Forte stmfGroupProperties *groupProps; 1746fcf3ce44SJohn Forte wchar_t operandName[sizeof (stmfGroupName)]; 1747fcf3ce44SJohn Forte wchar_t groupNamePrint[sizeof (stmfGroupName)]; 1748fcf3ce44SJohn Forte 1749fcf3ce44SJohn Forte for (; options->optval; options++) { 1750fcf3ce44SJohn Forte switch (options->optval) { 1751fcf3ce44SJohn Forte case 'v': 1752fcf3ce44SJohn Forte verbose = B_TRUE; 1753fcf3ce44SJohn Forte break; 1754fcf3ce44SJohn Forte default: 1755fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %c: %s\n", 1756fcf3ce44SJohn Forte cmdName, options->optval, 1757fcf3ce44SJohn Forte gettext("unknown option")); 1758fcf3ce44SJohn Forte return (1); 1759fcf3ce44SJohn Forte } 1760fcf3ce44SJohn Forte } 1761fcf3ce44SJohn Forte 1762fcf3ce44SJohn Forte if (operandLen > 0) { 1763fcf3ce44SJohn Forte outerLoop = operandLen; 1764fcf3ce44SJohn Forte operandEntered = B_TRUE; 1765fcf3ce44SJohn Forte } else { 1766fcf3ce44SJohn Forte outerLoop = 1; 1767fcf3ce44SJohn Forte operandEntered = B_FALSE; 1768fcf3ce44SJohn Forte } 1769fcf3ce44SJohn Forte 1770fcf3ce44SJohn Forte stmfRet = stmfGetTargetGroupList(&groupList); 1771fcf3ce44SJohn Forte if (stmfRet != STMF_STATUS_SUCCESS) { 1772fcf3ce44SJohn Forte switch (stmfRet) { 1773fcf3ce44SJohn Forte case STMF_ERROR_BUSY: 1774fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 1775fcf3ce44SJohn Forte gettext("resource busy")); 1776fcf3ce44SJohn Forte break; 1777fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_NOT_FOUND: 1778fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 1779fcf3ce44SJohn Forte gettext("STMF service not found")); 1780fcf3ce44SJohn Forte break; 1781fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_DATA_VERSION: 1782fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 1783fcf3ce44SJohn Forte gettext("STMF service version incorrect")); 1784fcf3ce44SJohn Forte break; 1785fcf3ce44SJohn Forte case STMF_ERROR_PERM: 1786fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 1787fcf3ce44SJohn Forte gettext("permission denied")); 1788fcf3ce44SJohn Forte break; 1789fcf3ce44SJohn Forte default: 1790fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 1791fcf3ce44SJohn Forte gettext("unknown error")); 1792fcf3ce44SJohn Forte break; 1793fcf3ce44SJohn Forte } 1794fcf3ce44SJohn Forte return (1); 1795fcf3ce44SJohn Forte } 1796fcf3ce44SJohn Forte 1797fcf3ce44SJohn Forte for (i = 0; i < outerLoop; i++) { 1798fcf3ce44SJohn Forte for (found = B_FALSE, j = 0; j < groupList->cnt; j++) { 1799fcf3ce44SJohn Forte (void) mbstowcs(groupNamePrint, 1800fcf3ce44SJohn Forte (char *)groupList->name[j], 18013e7352aeSJohn Forte sizeof (stmfGroupName) - 1); 18023e7352aeSJohn Forte groupNamePrint[sizeof (stmfGroupName) - 1] = 0; 1803fcf3ce44SJohn Forte if (operandEntered) { 1804fcf3ce44SJohn Forte (void) mbstowcs(operandName, operands[i], 18053e7352aeSJohn Forte sizeof (stmfGroupName) - 1); 18063e7352aeSJohn Forte operandName[sizeof (stmfGroupName) - 1] = 0; 1807fcf3ce44SJohn Forte if (wcscmp(operandName, groupNamePrint) 1808fcf3ce44SJohn Forte == 0) { 1809fcf3ce44SJohn Forte found = B_TRUE; 1810fcf3ce44SJohn Forte } 1811fcf3ce44SJohn Forte } 1812fcf3ce44SJohn Forte if ((found && operandEntered) || !operandEntered) { 1813fcf3ce44SJohn Forte (void) printf("Target Group: %ws\n", 1814fcf3ce44SJohn Forte groupNamePrint); 1815fcf3ce44SJohn Forte if (verbose) { 1816fcf3ce44SJohn Forte stmfRet = stmfGetTargetGroupMembers( 1817fcf3ce44SJohn Forte &(groupList->name[j]), &groupProps); 1818fcf3ce44SJohn Forte if (stmfRet != STMF_STATUS_SUCCESS) { 1819fcf3ce44SJohn Forte return (1); 1820fcf3ce44SJohn Forte } 1821fcf3ce44SJohn Forte printGroupProps(groupProps); 1822fcf3ce44SJohn Forte } 1823fcf3ce44SJohn Forte if (found && operandEntered) { 1824fcf3ce44SJohn Forte break; 1825fcf3ce44SJohn Forte } 1826fcf3ce44SJohn Forte } 1827fcf3ce44SJohn Forte 1828fcf3ce44SJohn Forte } 1829fcf3ce44SJohn Forte if (operandEntered && !found) { 1830fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 1831fcf3ce44SJohn Forte operands[i], gettext("not found")); 1832fcf3ce44SJohn Forte ret = 1; 1833fcf3ce44SJohn Forte } 1834fcf3ce44SJohn Forte } 1835fcf3ce44SJohn Forte return (ret); 1836fcf3ce44SJohn Forte } 1837fcf3ce44SJohn Forte 1838fcf3ce44SJohn Forte /* 1839fcf3ce44SJohn Forte * listLuFunc 1840fcf3ce44SJohn Forte * 1841fcf3ce44SJohn Forte * List the logical units and optionally the properties 1842fcf3ce44SJohn Forte * 1843fcf3ce44SJohn Forte */ 1844fcf3ce44SJohn Forte /*ARGSUSED*/ 1845fcf3ce44SJohn Forte static int 1846fcf3ce44SJohn Forte listLuFunc(int operandLen, char *operands[], cmdOptions_t *options, void *args) 1847fcf3ce44SJohn Forte { 1848fcf3ce44SJohn Forte cmdOptions_t *optionList = options; 1849fcf3ce44SJohn Forte boolean_t operandEntered; 1850fcf3ce44SJohn Forte int i, j; 1851fcf3ce44SJohn Forte int ret = 0; 1852fcf3ce44SJohn Forte int stmfRet; 1853fcf3ce44SJohn Forte int outerLoop; 1854fcf3ce44SJohn Forte unsigned int inGuid[sizeof (stmfGuid)]; 1855fcf3ce44SJohn Forte stmfGuid cmpGuid; 1856fcf3ce44SJohn Forte boolean_t verbose = B_FALSE; 1857fcf3ce44SJohn Forte boolean_t found; 1858fcf3ce44SJohn Forte char sGuid[GUID_INPUT + 1]; 1859fcf3ce44SJohn Forte stmfGuidList *luList; 1860fcf3ce44SJohn Forte stmfLogicalUnitProperties luProps; 1861fcf3ce44SJohn Forte boolean_t invalidInput = B_FALSE; 1862fcf3ce44SJohn Forte stmfViewEntryList *viewEntryList; 1863fcf3ce44SJohn Forte 1864fcf3ce44SJohn Forte for (; optionList->optval; optionList++) { 1865fcf3ce44SJohn Forte switch (optionList->optval) { 1866fcf3ce44SJohn Forte case 'v': 1867fcf3ce44SJohn Forte verbose = B_TRUE; 1868fcf3ce44SJohn Forte break; 1869fcf3ce44SJohn Forte } 1870fcf3ce44SJohn Forte } 1871fcf3ce44SJohn Forte 1872fcf3ce44SJohn Forte if ((stmfRet = stmfGetLogicalUnitList(&luList)) 1873fcf3ce44SJohn Forte != STMF_STATUS_SUCCESS) { 1874fcf3ce44SJohn Forte switch (stmfRet) { 1875fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_NOT_FOUND: 1876fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 1877fcf3ce44SJohn Forte gettext("STMF service not found")); 1878fcf3ce44SJohn Forte break; 1879fcf3ce44SJohn Forte case STMF_ERROR_BUSY: 1880fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 1881fcf3ce44SJohn Forte gettext("resource busy")); 1882fcf3ce44SJohn Forte break; 1883fcf3ce44SJohn Forte case STMF_ERROR_PERM: 1884fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 1885fcf3ce44SJohn Forte gettext("permission denied")); 1886fcf3ce44SJohn Forte break; 1887fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_DATA_VERSION: 1888fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 1889fcf3ce44SJohn Forte gettext("STMF service version incorrect")); 1890fcf3ce44SJohn Forte break; 1891fcf3ce44SJohn Forte default: 1892fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 1893fcf3ce44SJohn Forte gettext("list failed")); 1894fcf3ce44SJohn Forte break; 1895fcf3ce44SJohn Forte } 1896fcf3ce44SJohn Forte return (1); 1897fcf3ce44SJohn Forte } 1898fcf3ce44SJohn Forte 1899fcf3ce44SJohn Forte if (operandLen > 0) { 1900fcf3ce44SJohn Forte operandEntered = B_TRUE; 1901fcf3ce44SJohn Forte outerLoop = operandLen; 1902fcf3ce44SJohn Forte } else { 1903fcf3ce44SJohn Forte operandEntered = B_FALSE; 1904fcf3ce44SJohn Forte outerLoop = 1; 1905fcf3ce44SJohn Forte } 1906fcf3ce44SJohn Forte 1907fcf3ce44SJohn Forte 1908fcf3ce44SJohn Forte for (invalidInput = B_FALSE, i = 0; i < outerLoop; i++) { 1909fcf3ce44SJohn Forte if (operandEntered) { 1910fcf3ce44SJohn Forte if (strlen(operands[i]) != GUID_INPUT) { 1911fcf3ce44SJohn Forte invalidInput = B_TRUE; 1912fcf3ce44SJohn Forte } else { 1913fcf3ce44SJohn Forte for (j = 0; j < GUID_INPUT; j++) { 1914fcf3ce44SJohn Forte if (!isxdigit(operands[i][j])) { 1915fcf3ce44SJohn Forte invalidInput = B_TRUE; 1916fcf3ce44SJohn Forte break; 1917fcf3ce44SJohn Forte } 1918fcf3ce44SJohn Forte } 1919fcf3ce44SJohn Forte } 1920fcf3ce44SJohn Forte if (invalidInput) { 1921fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s%d%s\n", 1922fcf3ce44SJohn Forte cmdName, operands[i], gettext("must be "), 1923fcf3ce44SJohn Forte GUID_INPUT, 1924fcf3ce44SJohn Forte gettext(" hexadecimal digits long")); 1925*8fe96085Stim szeto invalidInput = B_FALSE; 1926fcf3ce44SJohn Forte continue; 1927fcf3ce44SJohn Forte } 1928fcf3ce44SJohn Forte 1929fcf3ce44SJohn Forte for (j = 0; j < GUID_INPUT; j++) { 1930fcf3ce44SJohn Forte sGuid[j] = tolower(operands[i][j]); 1931fcf3ce44SJohn Forte } 1932fcf3ce44SJohn Forte sGuid[j] = 0; 1933fcf3ce44SJohn Forte 1934fcf3ce44SJohn Forte (void) sscanf(sGuid, 1935fcf3ce44SJohn Forte "%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x", 1936fcf3ce44SJohn Forte &inGuid[0], &inGuid[1], &inGuid[2], &inGuid[3], 1937fcf3ce44SJohn Forte &inGuid[4], &inGuid[5], &inGuid[6], &inGuid[7], 1938fcf3ce44SJohn Forte &inGuid[8], &inGuid[9], &inGuid[10], &inGuid[11], 1939fcf3ce44SJohn Forte &inGuid[12], &inGuid[13], &inGuid[14], &inGuid[15]); 1940fcf3ce44SJohn Forte 1941fcf3ce44SJohn Forte for (j = 0; j < sizeof (stmfGuid); j++) { 1942fcf3ce44SJohn Forte cmpGuid.guid[j] = inGuid[j]; 1943fcf3ce44SJohn Forte } 1944fcf3ce44SJohn Forte } 1945fcf3ce44SJohn Forte 1946fcf3ce44SJohn Forte for (found = B_FALSE, j = 0; j < luList->cnt; j++) { 1947fcf3ce44SJohn Forte if (operandEntered) { 1948fcf3ce44SJohn Forte if (bcmp(luList->guid[j].guid, cmpGuid.guid, 1949fcf3ce44SJohn Forte sizeof (stmfGuid)) == 0) { 1950fcf3ce44SJohn Forte found = B_TRUE; 1951fcf3ce44SJohn Forte } 1952fcf3ce44SJohn Forte } 1953fcf3ce44SJohn Forte if ((found && operandEntered) || !operandEntered) { 1954fcf3ce44SJohn Forte (void) printf("LU Name: "); 1955fcf3ce44SJohn Forte printGuid(&luList->guid[j], stdout); 1956fcf3ce44SJohn Forte (void) printf("\n"); 1957fcf3ce44SJohn Forte 1958fcf3ce44SJohn Forte if (verbose) { 1959fcf3ce44SJohn Forte stmfRet = stmfGetLogicalUnitProperties( 1960fcf3ce44SJohn Forte &(luList->guid[j]), &luProps); 1961fcf3ce44SJohn Forte if (stmfRet == STMF_STATUS_SUCCESS) { 1962fcf3ce44SJohn Forte printLuProps(&luProps); 1963fcf3ce44SJohn Forte } else { 1964fcf3ce44SJohn Forte (void) fprintf(stderr, "%s:", 1965fcf3ce44SJohn Forte cmdName); 1966fcf3ce44SJohn Forte printGuid(&luList->guid[j], 1967fcf3ce44SJohn Forte stderr); 1968fcf3ce44SJohn Forte (void) fprintf(stderr, "%s\n", 1969fcf3ce44SJohn Forte gettext(" get properties " 1970fcf3ce44SJohn Forte "failed")); 1971fcf3ce44SJohn Forte } 1972fcf3ce44SJohn Forte stmfRet = stmfGetViewEntryList( 1973fcf3ce44SJohn Forte &(luList->guid[j]), 1974fcf3ce44SJohn Forte &viewEntryList); 1975fcf3ce44SJohn Forte (void) printf(PROPS_FORMAT, 1976fcf3ce44SJohn Forte "View Entry Count"); 1977fcf3ce44SJohn Forte if (stmfRet == STMF_STATUS_SUCCESS) { 1978fcf3ce44SJohn Forte (void) printf("%d", 1979fcf3ce44SJohn Forte viewEntryList->cnt); 1980fcf3ce44SJohn Forte } else if (stmfRet == 1981fcf3ce44SJohn Forte STMF_ERROR_NOT_FOUND) { 1982fcf3ce44SJohn Forte (void) printf("0"); 1983fcf3ce44SJohn Forte } else { 1984fcf3ce44SJohn Forte (void) printf("unknown"); 1985fcf3ce44SJohn Forte } 1986fcf3ce44SJohn Forte (void) printf("\n"); 1987*8fe96085Stim szeto ret = printExtLuProps( 1988*8fe96085Stim szeto &(luList->guid[j])); 1989fcf3ce44SJohn Forte } 1990fcf3ce44SJohn Forte if (found && operandEntered) { 1991fcf3ce44SJohn Forte break; 1992fcf3ce44SJohn Forte } 1993fcf3ce44SJohn Forte } 1994fcf3ce44SJohn Forte 1995fcf3ce44SJohn Forte } 1996fcf3ce44SJohn Forte if (operandEntered && !found) { 1997fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 1998fcf3ce44SJohn Forte operands[i], gettext("not found")); 1999fcf3ce44SJohn Forte ret = 1; 2000fcf3ce44SJohn Forte } 2001fcf3ce44SJohn Forte } 2002fcf3ce44SJohn Forte 2003fcf3ce44SJohn Forte return (ret); 2004fcf3ce44SJohn Forte } 2005fcf3ce44SJohn Forte 2006fcf3ce44SJohn Forte static void 2007fcf3ce44SJohn Forte printGuid(stmfGuid *guid, FILE *stream) 2008fcf3ce44SJohn Forte { 2009fcf3ce44SJohn Forte int i; 2010fcf3ce44SJohn Forte for (i = 0; i < 16; i++) { 2011fcf3ce44SJohn Forte (void) fprintf(stream, "%02X", guid->guid[i]); 2012fcf3ce44SJohn Forte } 2013fcf3ce44SJohn Forte } 2014fcf3ce44SJohn Forte 2015*8fe96085Stim szeto static int 2016*8fe96085Stim szeto printExtLuProps(stmfGuid *guid) 2017*8fe96085Stim szeto { 2018*8fe96085Stim szeto int stmfRet; 2019*8fe96085Stim szeto luResource hdl = NULL; 2020*8fe96085Stim szeto int ret = 0; 2021*8fe96085Stim szeto char propVal[MAXNAMELEN]; 2022*8fe96085Stim szeto size_t propValSize = sizeof (propVal); 2023*8fe96085Stim szeto 2024*8fe96085Stim szeto if ((stmfRet = stmfGetLuResource(guid, &hdl)) 2025*8fe96085Stim szeto != STMF_STATUS_SUCCESS) { 2026*8fe96085Stim szeto switch (stmfRet) { 2027*8fe96085Stim szeto case STMF_ERROR_BUSY: 2028*8fe96085Stim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 2029*8fe96085Stim szeto gettext("resource busy")); 2030*8fe96085Stim szeto break; 2031*8fe96085Stim szeto case STMF_ERROR_PERM: 2032*8fe96085Stim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 2033*8fe96085Stim szeto gettext("permission denied")); 2034*8fe96085Stim szeto break; 2035*8fe96085Stim szeto case STMF_ERROR_NOT_FOUND: 2036*8fe96085Stim szeto /* No error here */ 2037*8fe96085Stim szeto return (0); 2038*8fe96085Stim szeto break; 2039*8fe96085Stim szeto default: 2040*8fe96085Stim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 2041*8fe96085Stim szeto gettext("get extended properties failed")); 2042*8fe96085Stim szeto break; 2043*8fe96085Stim szeto } 2044*8fe96085Stim szeto return (1); 2045*8fe96085Stim szeto } 2046*8fe96085Stim szeto 2047*8fe96085Stim szeto stmfRet = stmfGetLuProp(hdl, STMF_LU_PROP_FILENAME, propVal, 2048*8fe96085Stim szeto &propValSize); 2049*8fe96085Stim szeto (void) printf(PROPS_FORMAT, "Data File"); 2050*8fe96085Stim szeto if (stmfRet == STMF_STATUS_SUCCESS) { 2051*8fe96085Stim szeto (void) printf("%s\n", propVal); 2052*8fe96085Stim szeto } else if (stmfRet == STMF_ERROR_NO_PROP) { 2053*8fe96085Stim szeto (void) printf("not set\n"); 2054*8fe96085Stim szeto } else { 2055*8fe96085Stim szeto (void) printf("<error retrieving property>\n"); 2056*8fe96085Stim szeto ret++; 2057*8fe96085Stim szeto } 2058*8fe96085Stim szeto 2059*8fe96085Stim szeto stmfRet = stmfGetLuProp(hdl, STMF_LU_PROP_META_FILENAME, propVal, 2060*8fe96085Stim szeto &propValSize); 2061*8fe96085Stim szeto (void) printf(PROPS_FORMAT, "Meta File"); 2062*8fe96085Stim szeto if (stmfRet == STMF_STATUS_SUCCESS) { 2063*8fe96085Stim szeto (void) printf("%s\n", propVal); 2064*8fe96085Stim szeto } else if (stmfRet == STMF_ERROR_NO_PROP) { 2065*8fe96085Stim szeto (void) printf("not set\n"); 2066*8fe96085Stim szeto } else { 2067*8fe96085Stim szeto (void) printf("<error retrieving property>\n"); 2068*8fe96085Stim szeto ret++; 2069*8fe96085Stim szeto } 2070*8fe96085Stim szeto 2071*8fe96085Stim szeto stmfRet = stmfGetLuProp(hdl, STMF_LU_PROP_SIZE, propVal, 2072*8fe96085Stim szeto &propValSize); 2073*8fe96085Stim szeto (void) printf(PROPS_FORMAT, "Size"); 2074*8fe96085Stim szeto if (stmfRet == STMF_STATUS_SUCCESS) { 2075*8fe96085Stim szeto (void) printf("%s\n", propVal); 2076*8fe96085Stim szeto } else if (stmfRet == STMF_ERROR_NO_PROP) { 2077*8fe96085Stim szeto (void) printf("not set\n"); 2078*8fe96085Stim szeto } else { 2079*8fe96085Stim szeto (void) printf("<error retrieving property>\n"); 2080*8fe96085Stim szeto ret++; 2081*8fe96085Stim szeto } 2082*8fe96085Stim szeto 2083*8fe96085Stim szeto stmfRet = stmfGetLuProp(hdl, STMF_LU_PROP_BLOCK_SIZE, propVal, 2084*8fe96085Stim szeto &propValSize); 2085*8fe96085Stim szeto (void) printf(PROPS_FORMAT, "Block Size"); 2086*8fe96085Stim szeto if (stmfRet == STMF_STATUS_SUCCESS) { 2087*8fe96085Stim szeto (void) printf("%s\n", propVal); 2088*8fe96085Stim szeto } else if (stmfRet == STMF_ERROR_NO_PROP) { 2089*8fe96085Stim szeto (void) printf("not set\n"); 2090*8fe96085Stim szeto } else { 2091*8fe96085Stim szeto (void) printf("<error retrieving property>\n"); 2092*8fe96085Stim szeto ret++; 2093*8fe96085Stim szeto } 2094*8fe96085Stim szeto 2095*8fe96085Stim szeto stmfRet = stmfGetLuProp(hdl, STMF_LU_PROP_VID, propVal, 2096*8fe96085Stim szeto &propValSize); 2097*8fe96085Stim szeto (void) printf(PROPS_FORMAT, "Vendor ID"); 2098*8fe96085Stim szeto if (stmfRet == STMF_STATUS_SUCCESS) { 2099*8fe96085Stim szeto (void) printf("%s\n", propVal); 2100*8fe96085Stim szeto } else if (stmfRet == STMF_ERROR_NO_PROP) { 2101*8fe96085Stim szeto (void) printf("not set\n"); 2102*8fe96085Stim szeto } else { 2103*8fe96085Stim szeto (void) printf("<error retrieving property>\n"); 2104*8fe96085Stim szeto ret++; 2105*8fe96085Stim szeto } 2106*8fe96085Stim szeto 2107*8fe96085Stim szeto stmfRet = stmfGetLuProp(hdl, STMF_LU_PROP_PID, propVal, 2108*8fe96085Stim szeto &propValSize); 2109*8fe96085Stim szeto (void) printf(PROPS_FORMAT, "Product ID"); 2110*8fe96085Stim szeto if (stmfRet == STMF_STATUS_SUCCESS) { 2111*8fe96085Stim szeto (void) printf("%s\n", propVal); 2112*8fe96085Stim szeto } else if (stmfRet == STMF_ERROR_NO_PROP) { 2113*8fe96085Stim szeto (void) printf("not set\n"); 2114*8fe96085Stim szeto } else { 2115*8fe96085Stim szeto (void) printf("<error retrieving property>\n"); 2116*8fe96085Stim szeto ret++; 2117*8fe96085Stim szeto } 2118*8fe96085Stim szeto 2119*8fe96085Stim szeto stmfRet = stmfGetLuProp(hdl, STMF_LU_PROP_SERIAL_NUM, propVal, 2120*8fe96085Stim szeto &propValSize); 2121*8fe96085Stim szeto (void) printf(PROPS_FORMAT, "Serial Num"); 2122*8fe96085Stim szeto if (stmfRet == STMF_STATUS_SUCCESS) { 2123*8fe96085Stim szeto (void) printf("%s\n", propVal); 2124*8fe96085Stim szeto } else if (stmfRet == STMF_ERROR_NO_PROP) { 2125*8fe96085Stim szeto (void) printf("not set\n"); 2126*8fe96085Stim szeto } else { 2127*8fe96085Stim szeto (void) printf("<error retrieving property>\n"); 2128*8fe96085Stim szeto ret++; 2129*8fe96085Stim szeto } 2130*8fe96085Stim szeto 2131*8fe96085Stim szeto stmfRet = stmfGetLuProp(hdl, STMF_LU_PROP_WRITE_PROTECT, propVal, 2132*8fe96085Stim szeto &propValSize); 2133*8fe96085Stim szeto (void) printf(PROPS_FORMAT, "Write Protect"); 2134*8fe96085Stim szeto if (stmfRet == STMF_STATUS_SUCCESS) { 2135*8fe96085Stim szeto (void) printf("%s\n", 2136*8fe96085Stim szeto strcasecmp(propVal, "true") ? "Disabled" : "Enabled"); 2137*8fe96085Stim szeto } else if (stmfRet == STMF_ERROR_NO_PROP) { 2138*8fe96085Stim szeto (void) printf("not set\n"); 2139*8fe96085Stim szeto } else { 2140*8fe96085Stim szeto (void) printf("<error retrieving property>\n"); 2141*8fe96085Stim szeto ret++; 2142*8fe96085Stim szeto } 2143*8fe96085Stim szeto 2144*8fe96085Stim szeto stmfRet = stmfGetLuProp(hdl, STMF_LU_PROP_WRITE_CACHE_DISABLE, propVal, 2145*8fe96085Stim szeto &propValSize); 2146*8fe96085Stim szeto (void) printf(PROPS_FORMAT, "Writeback Cache"); 2147*8fe96085Stim szeto if (stmfRet == STMF_STATUS_SUCCESS) { 2148*8fe96085Stim szeto (void) printf("%s\n", 2149*8fe96085Stim szeto strcasecmp(propVal, "true") ? "Enabled" : "Disabled"); 2150*8fe96085Stim szeto } else if (stmfRet == STMF_ERROR_NO_PROP) { 2151*8fe96085Stim szeto (void) printf("not set\n"); 2152*8fe96085Stim szeto } else { 2153*8fe96085Stim szeto (void) printf("<error retrieving property>\n"); 2154*8fe96085Stim szeto ret++; 2155*8fe96085Stim szeto } 2156*8fe96085Stim szeto 2157*8fe96085Stim szeto 2158*8fe96085Stim szeto (void) stmfFreeLuResource(hdl); 2159*8fe96085Stim szeto return (ret); 2160*8fe96085Stim szeto 2161*8fe96085Stim szeto } 2162*8fe96085Stim szeto 2163fcf3ce44SJohn Forte 2164fcf3ce44SJohn Forte /* 2165fcf3ce44SJohn Forte * printLuProps 2166fcf3ce44SJohn Forte * 2167fcf3ce44SJohn Forte * Prints the properties for a logical unit 2168fcf3ce44SJohn Forte * 2169fcf3ce44SJohn Forte */ 2170fcf3ce44SJohn Forte static void 2171fcf3ce44SJohn Forte printLuProps(stmfLogicalUnitProperties *luProps) 2172fcf3ce44SJohn Forte { 2173fcf3ce44SJohn Forte (void) printf(PROPS_FORMAT, "Operational Status"); 2174fcf3ce44SJohn Forte switch (luProps->status) { 2175fcf3ce44SJohn Forte case STMF_LOGICAL_UNIT_ONLINE: 2176fcf3ce44SJohn Forte (void) printf("Online"); 2177fcf3ce44SJohn Forte break; 2178fcf3ce44SJohn Forte case STMF_LOGICAL_UNIT_OFFLINE: 2179fcf3ce44SJohn Forte (void) printf("Offline"); 2180fcf3ce44SJohn Forte break; 2181fcf3ce44SJohn Forte case STMF_LOGICAL_UNIT_ONLINING: 2182fcf3ce44SJohn Forte (void) printf("Onlining"); 2183fcf3ce44SJohn Forte break; 2184fcf3ce44SJohn Forte case STMF_LOGICAL_UNIT_OFFLINING: 2185fcf3ce44SJohn Forte (void) printf("Offlining"); 2186fcf3ce44SJohn Forte break; 2187fcf3ce44SJohn Forte case STMF_LOGICAL_UNIT_UNREGISTERED: 2188fcf3ce44SJohn Forte (void) printf("unregistered"); 2189fcf3ce44SJohn Forte (void) strncpy(luProps->providerName, "unregistered", 2190fcf3ce44SJohn Forte sizeof (luProps->providerName)); 2191fcf3ce44SJohn Forte break; 2192fcf3ce44SJohn Forte default: 2193fcf3ce44SJohn Forte (void) printf("unknown"); 2194fcf3ce44SJohn Forte break; 2195fcf3ce44SJohn Forte } 2196fcf3ce44SJohn Forte (void) printf("\n"); 2197fcf3ce44SJohn Forte (void) printf(PROPS_FORMAT, "Provider Name"); 2198fcf3ce44SJohn Forte if (luProps->providerName[0] != 0) { 2199fcf3ce44SJohn Forte (void) printf("%s", luProps->providerName); 2200fcf3ce44SJohn Forte } else { 2201fcf3ce44SJohn Forte (void) printf("unknown"); 2202fcf3ce44SJohn Forte } 2203fcf3ce44SJohn Forte (void) printf("\n"); 2204fcf3ce44SJohn Forte (void) printf(PROPS_FORMAT, "Alias"); 2205fcf3ce44SJohn Forte if (luProps->alias[0] != 0) { 2206fcf3ce44SJohn Forte (void) printf("%s", luProps->alias); 2207fcf3ce44SJohn Forte } else { 2208fcf3ce44SJohn Forte (void) printf("-"); 2209fcf3ce44SJohn Forte } 2210fcf3ce44SJohn Forte (void) printf("\n"); 2211fcf3ce44SJohn Forte } 2212fcf3ce44SJohn Forte 2213fcf3ce44SJohn Forte /* 2214fcf3ce44SJohn Forte * printTargetProps 2215fcf3ce44SJohn Forte * 2216fcf3ce44SJohn Forte * Prints the properties for a target 2217fcf3ce44SJohn Forte * 2218fcf3ce44SJohn Forte */ 2219fcf3ce44SJohn Forte static void 2220fcf3ce44SJohn Forte printTargetProps(stmfTargetProperties *targetProps) 2221fcf3ce44SJohn Forte { 2222fcf3ce44SJohn Forte (void) printf(PROPS_FORMAT, "Operational Status"); 2223fcf3ce44SJohn Forte switch (targetProps->status) { 2224fcf3ce44SJohn Forte case STMF_TARGET_PORT_ONLINE: 2225fcf3ce44SJohn Forte (void) printf("Online"); 2226fcf3ce44SJohn Forte break; 2227fcf3ce44SJohn Forte case STMF_TARGET_PORT_OFFLINE: 2228fcf3ce44SJohn Forte (void) printf("Offline"); 2229fcf3ce44SJohn Forte break; 2230fcf3ce44SJohn Forte case STMF_TARGET_PORT_ONLINING: 2231fcf3ce44SJohn Forte (void) printf("Onlining"); 2232fcf3ce44SJohn Forte break; 2233fcf3ce44SJohn Forte case STMF_TARGET_PORT_OFFLINING: 2234fcf3ce44SJohn Forte (void) printf("Offlining"); 2235fcf3ce44SJohn Forte break; 2236fcf3ce44SJohn Forte default: 2237fcf3ce44SJohn Forte (void) printf("unknown"); 2238fcf3ce44SJohn Forte break; 2239fcf3ce44SJohn Forte } 2240fcf3ce44SJohn Forte (void) printf("\n"); 2241fcf3ce44SJohn Forte (void) printf(PROPS_FORMAT, "Provider Name"); 2242fcf3ce44SJohn Forte if (targetProps->providerName[0] != 0) { 2243fcf3ce44SJohn Forte (void) printf("%s", targetProps->providerName); 2244fcf3ce44SJohn Forte } 2245fcf3ce44SJohn Forte (void) printf("\n"); 2246fcf3ce44SJohn Forte (void) printf(PROPS_FORMAT, "Alias"); 2247fcf3ce44SJohn Forte if (targetProps->alias[0] != 0) { 2248fcf3ce44SJohn Forte (void) printf("%s", targetProps->alias); 2249fcf3ce44SJohn Forte } else { 2250fcf3ce44SJohn Forte (void) printf("-"); 2251fcf3ce44SJohn Forte } 2252fcf3ce44SJohn Forte (void) printf("\n"); 2253fcf3ce44SJohn Forte } 2254fcf3ce44SJohn Forte 2255fcf3ce44SJohn Forte /* 2256fcf3ce44SJohn Forte * printSessionProps 2257fcf3ce44SJohn Forte * 2258fcf3ce44SJohn Forte * Prints the session data 2259fcf3ce44SJohn Forte * 2260fcf3ce44SJohn Forte */ 2261fcf3ce44SJohn Forte static void 2262fcf3ce44SJohn Forte printSessionProps(stmfSessionList *sessionList) 2263fcf3ce44SJohn Forte { 2264fcf3ce44SJohn Forte int i; 2265fcf3ce44SJohn Forte char *cTime; 2266fcf3ce44SJohn Forte wchar_t initiator[STMF_IDENT_LENGTH + 1]; 2267fcf3ce44SJohn Forte 2268fcf3ce44SJohn Forte (void) printf(PROPS_FORMAT, "Sessions"); 2269fcf3ce44SJohn Forte (void) printf("%d\n", sessionList->cnt); 2270fcf3ce44SJohn Forte for (i = 0; i < sessionList->cnt; i++) { 2271fcf3ce44SJohn Forte (void) mbstowcs(initiator, 2272fcf3ce44SJohn Forte (char *)sessionList->session[i].initiator.ident, 22733e7352aeSJohn Forte STMF_IDENT_LENGTH); 22743e7352aeSJohn Forte initiator[STMF_IDENT_LENGTH] = 0; 2275fcf3ce44SJohn Forte (void) printf(LVL3_FORMAT, "Initiator: "); 2276fcf3ce44SJohn Forte (void) printf("%ws\n", initiator); 2277fcf3ce44SJohn Forte (void) printf(LVL4_FORMAT, "Alias: "); 2278fcf3ce44SJohn Forte if (sessionList->session[i].alias[0] != 0) { 2279fcf3ce44SJohn Forte (void) printf("%s", sessionList->session[i].alias); 2280fcf3ce44SJohn Forte } else { 2281fcf3ce44SJohn Forte (void) printf("-"); 2282fcf3ce44SJohn Forte } 2283fcf3ce44SJohn Forte (void) printf("\n"); 2284fcf3ce44SJohn Forte (void) printf(LVL4_FORMAT, "Logged in since: "); 2285fcf3ce44SJohn Forte cTime = ctime(&(sessionList->session[i].creationTime)); 2286fcf3ce44SJohn Forte if (cTime != NULL) { 2287fcf3ce44SJohn Forte (void) printf("%s", cTime); 2288fcf3ce44SJohn Forte } else { 2289fcf3ce44SJohn Forte (void) printf("unknown\n"); 2290fcf3ce44SJohn Forte } 2291fcf3ce44SJohn Forte } 2292fcf3ce44SJohn Forte } 2293fcf3ce44SJohn Forte 2294e17f3b22Stim szeto static int 2295e17f3b22Stim szeto getStmfState(stmfState *state) 2296e17f3b22Stim szeto { 2297e17f3b22Stim szeto int ret; 2298e17f3b22Stim szeto 2299e17f3b22Stim szeto ret = stmfGetState(state); 2300e17f3b22Stim szeto switch (ret) { 2301e17f3b22Stim szeto case STMF_STATUS_SUCCESS: 2302e17f3b22Stim szeto break; 2303e17f3b22Stim szeto case STMF_ERROR_PERM: 2304e17f3b22Stim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 2305e17f3b22Stim szeto gettext("permission denied")); 2306e17f3b22Stim szeto break; 2307e17f3b22Stim szeto case STMF_ERROR_SERVICE_NOT_FOUND: 2308e17f3b22Stim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 2309e17f3b22Stim szeto gettext("STMF service not found")); 2310e17f3b22Stim szeto break; 2311e17f3b22Stim szeto case STMF_ERROR_BUSY: 2312e17f3b22Stim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 2313e17f3b22Stim szeto gettext("resource busy")); 2314e17f3b22Stim szeto break; 2315e17f3b22Stim szeto case STMF_ERROR_SERVICE_DATA_VERSION: 2316e17f3b22Stim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 2317e17f3b22Stim szeto gettext("STMF service version incorrect")); 2318e17f3b22Stim szeto break; 2319e17f3b22Stim szeto default: 2320*8fe96085Stim szeto (void) fprintf(stderr, "%s: %s: %d\n", cmdName, 2321*8fe96085Stim szeto gettext("unknown error"), ret); 2322e17f3b22Stim szeto break; 2323e17f3b22Stim szeto } 2324e17f3b22Stim szeto return (ret); 2325e17f3b22Stim szeto } 2326e17f3b22Stim szeto 2327fcf3ce44SJohn Forte /* 2328fcf3ce44SJohn Forte * listStateFunc 2329fcf3ce44SJohn Forte * 2330fcf3ce44SJohn Forte * List the operational and config state of the stmf service 2331fcf3ce44SJohn Forte * 2332fcf3ce44SJohn Forte */ 2333fcf3ce44SJohn Forte /*ARGSUSED*/ 2334fcf3ce44SJohn Forte static int 2335fcf3ce44SJohn Forte listStateFunc(int operandLen, char *operands[], cmdOptions_t *options, 2336fcf3ce44SJohn Forte void *args) 2337fcf3ce44SJohn Forte { 2338fcf3ce44SJohn Forte int ret; 2339fcf3ce44SJohn Forte stmfState state; 2340fcf3ce44SJohn Forte 2341e17f3b22Stim szeto if ((ret = getStmfState(&state)) != STMF_STATUS_SUCCESS) 2342e17f3b22Stim szeto return (ret); 2343fcf3ce44SJohn Forte 2344fcf3ce44SJohn Forte (void) printf("%-18s: ", "Operational Status"); 2345fcf3ce44SJohn Forte switch (state.operationalState) { 2346fcf3ce44SJohn Forte case STMF_SERVICE_STATE_ONLINE: 2347fcf3ce44SJohn Forte (void) printf("online"); 2348fcf3ce44SJohn Forte break; 2349fcf3ce44SJohn Forte case STMF_SERVICE_STATE_OFFLINE: 2350fcf3ce44SJohn Forte (void) printf("offline"); 2351fcf3ce44SJohn Forte break; 2352fcf3ce44SJohn Forte case STMF_SERVICE_STATE_ONLINING: 2353fcf3ce44SJohn Forte (void) printf("onlining"); 2354fcf3ce44SJohn Forte break; 2355fcf3ce44SJohn Forte case STMF_SERVICE_STATE_OFFLINING: 2356fcf3ce44SJohn Forte (void) printf("offlining"); 2357fcf3ce44SJohn Forte break; 2358fcf3ce44SJohn Forte default: 2359fcf3ce44SJohn Forte (void) printf("unknown"); 2360fcf3ce44SJohn Forte break; 2361fcf3ce44SJohn Forte } 2362fcf3ce44SJohn Forte (void) printf("\n"); 2363fcf3ce44SJohn Forte (void) printf("%-18s: ", "Config Status"); 2364fcf3ce44SJohn Forte switch (state.configState) { 2365fcf3ce44SJohn Forte case STMF_CONFIG_STATE_NONE: 2366fcf3ce44SJohn Forte (void) printf("uninitialized"); 2367fcf3ce44SJohn Forte break; 2368fcf3ce44SJohn Forte case STMF_CONFIG_STATE_INIT: 2369fcf3ce44SJohn Forte (void) printf("initializing"); 2370fcf3ce44SJohn Forte break; 2371fcf3ce44SJohn Forte case STMF_CONFIG_STATE_INIT_DONE: 2372fcf3ce44SJohn Forte (void) printf("initialized"); 2373fcf3ce44SJohn Forte break; 2374fcf3ce44SJohn Forte default: 2375fcf3ce44SJohn Forte (void) printf("unknown"); 2376fcf3ce44SJohn Forte break; 2377fcf3ce44SJohn Forte } 2378fcf3ce44SJohn Forte (void) printf("\n"); 2379fcf3ce44SJohn Forte return (0); 2380fcf3ce44SJohn Forte } 2381fcf3ce44SJohn Forte 2382fcf3ce44SJohn Forte /* 2383fcf3ce44SJohn Forte * listTargetFunc 2384fcf3ce44SJohn Forte * 2385fcf3ce44SJohn Forte * list the targets and optionally their properties 2386fcf3ce44SJohn Forte * 2387fcf3ce44SJohn Forte */ 2388fcf3ce44SJohn Forte /*ARGSUSED*/ 2389fcf3ce44SJohn Forte static int 2390fcf3ce44SJohn Forte listTargetFunc(int operandLen, char *operands[], cmdOptions_t *options, 2391fcf3ce44SJohn Forte void *args) 2392fcf3ce44SJohn Forte { 2393fcf3ce44SJohn Forte cmdOptions_t *optionList = options; 2394fcf3ce44SJohn Forte int ret = 0; 2395fcf3ce44SJohn Forte int stmfRet; 2396fcf3ce44SJohn Forte int i, j; 2397fcf3ce44SJohn Forte int outerLoop; 2398fcf3ce44SJohn Forte stmfSessionList *sessionList; 2399fcf3ce44SJohn Forte stmfDevid devid; 2400fcf3ce44SJohn Forte boolean_t operandEntered, found, verbose = B_FALSE; 2401fcf3ce44SJohn Forte stmfDevidList *targetList; 2402fcf3ce44SJohn Forte wchar_t targetIdent[STMF_IDENT_LENGTH + 1]; 2403fcf3ce44SJohn Forte stmfTargetProperties targetProps; 2404fcf3ce44SJohn Forte 2405fcf3ce44SJohn Forte if ((stmfRet = stmfGetTargetList(&targetList)) != STMF_STATUS_SUCCESS) { 2406fcf3ce44SJohn Forte switch (stmfRet) { 2407fcf3ce44SJohn Forte case STMF_ERROR_NOT_FOUND: 2408fcf3ce44SJohn Forte ret = 0; 2409fcf3ce44SJohn Forte break; 2410fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_OFFLINE: 2411fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 2412fcf3ce44SJohn Forte gettext("STMF service offline")); 2413fcf3ce44SJohn Forte break; 2414fcf3ce44SJohn Forte case STMF_ERROR_BUSY: 2415fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 2416fcf3ce44SJohn Forte gettext("resource busy")); 2417fcf3ce44SJohn Forte break; 2418fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_DATA_VERSION: 2419fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 2420fcf3ce44SJohn Forte gettext("STMF service version incorrect")); 2421fcf3ce44SJohn Forte break; 2422fcf3ce44SJohn Forte case STMF_ERROR_PERM: 2423fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 2424fcf3ce44SJohn Forte gettext("permission denied")); 2425fcf3ce44SJohn Forte break; 2426fcf3ce44SJohn Forte default: 2427fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 2428fcf3ce44SJohn Forte gettext("unknown error")); 2429fcf3ce44SJohn Forte break; 2430fcf3ce44SJohn Forte } 2431fcf3ce44SJohn Forte return (1); 2432fcf3ce44SJohn Forte } 2433fcf3ce44SJohn Forte 2434fcf3ce44SJohn Forte for (; optionList->optval; optionList++) { 2435fcf3ce44SJohn Forte switch (optionList->optval) { 2436fcf3ce44SJohn Forte case 'v': 2437fcf3ce44SJohn Forte verbose = B_TRUE; 2438fcf3ce44SJohn Forte break; 2439fcf3ce44SJohn Forte } 2440fcf3ce44SJohn Forte } 2441fcf3ce44SJohn Forte 2442fcf3ce44SJohn Forte if (operandLen > 0) { 2443fcf3ce44SJohn Forte outerLoop = operandLen; 2444fcf3ce44SJohn Forte operandEntered = B_TRUE; 2445fcf3ce44SJohn Forte } else { 2446fcf3ce44SJohn Forte outerLoop = 1; 2447fcf3ce44SJohn Forte operandEntered = B_FALSE; 2448fcf3ce44SJohn Forte } 2449fcf3ce44SJohn Forte 2450fcf3ce44SJohn Forte for (i = 0; i < outerLoop; i++) { 2451fcf3ce44SJohn Forte if (operandEntered) { 2452fcf3ce44SJohn Forte bzero(&devid, sizeof (devid)); 2453fcf3ce44SJohn Forte (void) parseDevid(operands[i], &devid); 2454fcf3ce44SJohn Forte } 2455fcf3ce44SJohn Forte for (found = B_FALSE, j = 0; j < targetList->cnt; j++) { 2456fcf3ce44SJohn Forte if (operandEntered) { 2457fcf3ce44SJohn Forte if (bcmp(&devid, &(targetList->devid[j]), 2458fcf3ce44SJohn Forte sizeof (devid)) == 0) { 2459fcf3ce44SJohn Forte found = B_TRUE; 2460fcf3ce44SJohn Forte } 2461fcf3ce44SJohn Forte } 2462fcf3ce44SJohn Forte if ((found && operandEntered) || !operandEntered) { 2463fcf3ce44SJohn Forte (void) mbstowcs(targetIdent, 2464fcf3ce44SJohn Forte (char *)targetList->devid[j].ident, 24653e7352aeSJohn Forte STMF_IDENT_LENGTH); 24663e7352aeSJohn Forte targetIdent[STMF_IDENT_LENGTH] = 0; 2467fcf3ce44SJohn Forte (void) printf("Target: %ws\n", targetIdent); 2468fcf3ce44SJohn Forte if (verbose) { 2469fcf3ce44SJohn Forte stmfRet = stmfGetTargetProperties( 2470fcf3ce44SJohn Forte &(targetList->devid[j]), 2471fcf3ce44SJohn Forte &targetProps); 2472fcf3ce44SJohn Forte if (stmfRet == STMF_STATUS_SUCCESS) { 2473fcf3ce44SJohn Forte printTargetProps(&targetProps); 2474fcf3ce44SJohn Forte } else { 2475fcf3ce44SJohn Forte (void) fprintf(stderr, "%s:", 2476fcf3ce44SJohn Forte cmdName); 2477fcf3ce44SJohn Forte (void) fprintf(stderr, "%s\n", 2478fcf3ce44SJohn Forte gettext(" get properties" 2479fcf3ce44SJohn Forte " failed")); 2480fcf3ce44SJohn Forte } 2481fcf3ce44SJohn Forte stmfRet = stmfGetSessionList( 2482fcf3ce44SJohn Forte &(targetList->devid[j]), 2483fcf3ce44SJohn Forte &sessionList); 2484fcf3ce44SJohn Forte if (stmfRet == STMF_STATUS_SUCCESS) { 2485fcf3ce44SJohn Forte printSessionProps(sessionList); 2486fcf3ce44SJohn Forte } else { 2487fcf3ce44SJohn Forte (void) fprintf(stderr, "%s:", 2488fcf3ce44SJohn Forte cmdName); 2489fcf3ce44SJohn Forte (void) fprintf(stderr, "%s\n", 2490fcf3ce44SJohn Forte gettext(" get session info" 2491fcf3ce44SJohn Forte " failed")); 2492fcf3ce44SJohn Forte } 2493fcf3ce44SJohn Forte } 2494fcf3ce44SJohn Forte if (found && operandEntered) { 2495fcf3ce44SJohn Forte break; 2496fcf3ce44SJohn Forte } 2497fcf3ce44SJohn Forte } 2498fcf3ce44SJohn Forte 2499fcf3ce44SJohn Forte } 2500fcf3ce44SJohn Forte if (operandEntered && !found) { 2501fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 2502fcf3ce44SJohn Forte operands[i], "not found"); 2503fcf3ce44SJohn Forte ret = 1; 2504fcf3ce44SJohn Forte } 2505fcf3ce44SJohn Forte } 2506fcf3ce44SJohn Forte return (ret); 2507fcf3ce44SJohn Forte } 2508fcf3ce44SJohn Forte 2509fcf3ce44SJohn Forte /* 2510fcf3ce44SJohn Forte * listViewFunc 2511fcf3ce44SJohn Forte * 2512fcf3ce44SJohn Forte * list the view entries for the specified logical unit 2513fcf3ce44SJohn Forte * 2514fcf3ce44SJohn Forte */ 2515fcf3ce44SJohn Forte /*ARGSUSED*/ 2516fcf3ce44SJohn Forte static int 2517fcf3ce44SJohn Forte listViewFunc(int operandLen, char *operands[], cmdOptions_t *options, 2518fcf3ce44SJohn Forte void *args) 2519fcf3ce44SJohn Forte { 2520fcf3ce44SJohn Forte stmfViewEntryList *viewEntryList; 2521fcf3ce44SJohn Forte stmfGuid inGuid; 2522fcf3ce44SJohn Forte unsigned int guid[sizeof (stmfGuid)]; 2523fcf3ce44SJohn Forte int ret = 0; 2524fcf3ce44SJohn Forte int stmfRet; 2525fcf3ce44SJohn Forte int i, j, outerLoop; 2526fcf3ce44SJohn Forte boolean_t found = B_TRUE; 2527fcf3ce44SJohn Forte boolean_t operandEntered; 2528fcf3ce44SJohn Forte uint16_t outputLuNbr; 2529fcf3ce44SJohn Forte wchar_t groupName[sizeof (stmfGroupName)]; 2530fcf3ce44SJohn Forte char sGuid[GUID_INPUT + 1]; 2531fcf3ce44SJohn Forte 2532fcf3ce44SJohn Forte 2533fcf3ce44SJohn Forte for (; options->optval; options++) { 2534fcf3ce44SJohn Forte switch (options->optval) { 2535fcf3ce44SJohn Forte case 'l': 2536fcf3ce44SJohn Forte if (strlen(options->optarg) != GUID_INPUT) { 2537fcf3ce44SJohn Forte (void) fprintf(stderr, 2538fcf3ce44SJohn Forte "%s: %s: %s%d%s\n", 2539fcf3ce44SJohn Forte cmdName, options->optarg, 2540fcf3ce44SJohn Forte gettext("must be "), GUID_INPUT, 2541fcf3ce44SJohn Forte gettext(" hexadecimal digits" 2542fcf3ce44SJohn Forte " long")); 2543fcf3ce44SJohn Forte return (1); 2544fcf3ce44SJohn Forte } 2545fcf3ce44SJohn Forte bcopy(options->optarg, sGuid, GUID_INPUT); 2546fcf3ce44SJohn Forte break; 2547fcf3ce44SJohn Forte default: 2548fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %c: %s\n", 2549fcf3ce44SJohn Forte cmdName, options->optval, 2550fcf3ce44SJohn Forte gettext("unknown option")); 2551fcf3ce44SJohn Forte return (1); 2552fcf3ce44SJohn Forte } 2553fcf3ce44SJohn Forte } 2554fcf3ce44SJohn Forte 2555fcf3ce44SJohn Forte if (operandLen > 0) { 2556fcf3ce44SJohn Forte outerLoop = operandLen; 2557fcf3ce44SJohn Forte operandEntered = B_TRUE; 2558fcf3ce44SJohn Forte } else { 2559fcf3ce44SJohn Forte outerLoop = 1; 2560fcf3ce44SJohn Forte operandEntered = B_FALSE; 2561fcf3ce44SJohn Forte } 2562fcf3ce44SJohn Forte 2563fcf3ce44SJohn Forte for (i = 0; i < 32; i++) 2564fcf3ce44SJohn Forte sGuid[i] = tolower(sGuid[i]); 2565fcf3ce44SJohn Forte sGuid[i] = 0; 2566fcf3ce44SJohn Forte 2567fcf3ce44SJohn Forte (void) sscanf(sGuid, "%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x", 2568fcf3ce44SJohn Forte &guid[0], &guid[1], &guid[2], &guid[3], &guid[4], &guid[5], 2569fcf3ce44SJohn Forte &guid[6], &guid[7], &guid[8], &guid[9], &guid[10], &guid[11], 2570fcf3ce44SJohn Forte &guid[12], &guid[13], &guid[14], &guid[15]); 2571fcf3ce44SJohn Forte 2572fcf3ce44SJohn Forte for (i = 0; i < sizeof (stmfGuid); i++) { 2573fcf3ce44SJohn Forte inGuid.guid[i] = guid[i]; 2574fcf3ce44SJohn Forte } 2575fcf3ce44SJohn Forte 2576fcf3ce44SJohn Forte if ((stmfRet = stmfGetViewEntryList(&inGuid, &viewEntryList)) 2577fcf3ce44SJohn Forte != STMF_STATUS_SUCCESS) { 2578fcf3ce44SJohn Forte 2579fcf3ce44SJohn Forte switch (stmfRet) { 2580fcf3ce44SJohn Forte case STMF_ERROR_BUSY: 2581fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 2582fcf3ce44SJohn Forte sGuid, gettext("resource busy")); 2583fcf3ce44SJohn Forte break; 2584fcf3ce44SJohn Forte case STMF_ERROR_NOT_FOUND: 2585fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 2586fcf3ce44SJohn Forte sGuid, gettext("no views found")); 2587fcf3ce44SJohn Forte break; 2588fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_NOT_FOUND: 2589fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 2590fcf3ce44SJohn Forte gettext("STMF service not found")); 2591fcf3ce44SJohn Forte break; 2592fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_DATA_VERSION: 2593fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 2594fcf3ce44SJohn Forte gettext("STMF service version incorrect")); 2595fcf3ce44SJohn Forte break; 2596fcf3ce44SJohn Forte case STMF_ERROR_PERM: 2597fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 2598fcf3ce44SJohn Forte gettext("permission denied")); 2599fcf3ce44SJohn Forte break; 2600fcf3ce44SJohn Forte default: 2601fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 2602fcf3ce44SJohn Forte sGuid, gettext("unknown error")); 2603fcf3ce44SJohn Forte break; 2604fcf3ce44SJohn Forte } 2605fcf3ce44SJohn Forte return (1); 2606fcf3ce44SJohn Forte } 2607fcf3ce44SJohn Forte 2608fcf3ce44SJohn Forte for (i = 0; i < outerLoop; i++) { 2609fcf3ce44SJohn Forte for (found = B_FALSE, j = 0; j < viewEntryList->cnt; j++) { 2610fcf3ce44SJohn Forte if (operandEntered) { 2611fcf3ce44SJohn Forte if (atoi(operands[i]) == 2612fcf3ce44SJohn Forte viewEntryList->ve[j].veIndex) { 2613fcf3ce44SJohn Forte found = B_TRUE; 2614fcf3ce44SJohn Forte } 2615fcf3ce44SJohn Forte } 2616fcf3ce44SJohn Forte if ((found && operandEntered) || !operandEntered) { 2617fcf3ce44SJohn Forte (void) printf("View Entry: %d\n", 2618fcf3ce44SJohn Forte viewEntryList->ve[j].veIndex); 2619fcf3ce44SJohn Forte (void) printf(VIEW_FORMAT, "Host group"); 2620fcf3ce44SJohn Forte if (viewEntryList->ve[j].allHosts) { 2621fcf3ce44SJohn Forte (void) printf("All\n"); 2622fcf3ce44SJohn Forte } else { 2623fcf3ce44SJohn Forte (void) mbstowcs(groupName, 2624fcf3ce44SJohn Forte viewEntryList->ve[j].hostGroup, 26253e7352aeSJohn Forte sizeof (stmfGroupName) - 1); 26263e7352aeSJohn Forte groupName[sizeof (stmfGroupName) - 1] 26273e7352aeSJohn Forte = 0; 2628fcf3ce44SJohn Forte (void) printf("%ws\n", groupName); 2629fcf3ce44SJohn Forte } 2630fcf3ce44SJohn Forte (void) printf(VIEW_FORMAT, "Target group"); 2631fcf3ce44SJohn Forte if (viewEntryList->ve[j].allTargets) { 2632fcf3ce44SJohn Forte (void) printf("All\n"); 2633fcf3ce44SJohn Forte } else { 2634fcf3ce44SJohn Forte (void) mbstowcs(groupName, 2635fcf3ce44SJohn Forte viewEntryList->ve[j].targetGroup, 26363e7352aeSJohn Forte sizeof (stmfGroupName) - 1); 26373e7352aeSJohn Forte groupName[sizeof (stmfGroupName) - 1] 26383e7352aeSJohn Forte = 0; 2639fcf3ce44SJohn Forte (void) printf("%ws\n", groupName); 2640fcf3ce44SJohn Forte } 2641fcf3ce44SJohn Forte outputLuNbr = ((viewEntryList->ve[j].luNbr[0] & 2642fcf3ce44SJohn Forte 0x3F) << 8) | viewEntryList->ve[j].luNbr[1]; 2643fcf3ce44SJohn Forte (void) printf(VIEW_FORMAT, "LUN"); 2644fcf3ce44SJohn Forte (void) printf("%d\n", outputLuNbr); 2645fcf3ce44SJohn Forte if (found && operandEntered) { 2646fcf3ce44SJohn Forte break; 2647fcf3ce44SJohn Forte } 2648fcf3ce44SJohn Forte } 2649fcf3ce44SJohn Forte } 2650fcf3ce44SJohn Forte if (operandEntered && !found) { 2651fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s, %s: %s\n", cmdName, 2652fcf3ce44SJohn Forte sGuid, operands[i], gettext("not found")); 2653fcf3ce44SJohn Forte ret = 1; 2654fcf3ce44SJohn Forte } 2655fcf3ce44SJohn Forte } 2656fcf3ce44SJohn Forte 2657fcf3ce44SJohn Forte return (ret); 2658fcf3ce44SJohn Forte } 2659fcf3ce44SJohn Forte 2660fcf3ce44SJohn Forte 2661fcf3ce44SJohn Forte /* 2662fcf3ce44SJohn Forte * onlineOfflineLu 2663fcf3ce44SJohn Forte * 2664fcf3ce44SJohn Forte * Purpose: Online or offline a logical unit 2665fcf3ce44SJohn Forte * 2666fcf3ce44SJohn Forte * lu - logical unit to online or offline 2667fcf3ce44SJohn Forte * 2668fcf3ce44SJohn Forte * state - ONLINE_LU 2669fcf3ce44SJohn Forte * OFFLINE_LU 2670fcf3ce44SJohn Forte */ 2671fcf3ce44SJohn Forte static int 2672fcf3ce44SJohn Forte onlineOfflineLu(char *lu, int state) 2673fcf3ce44SJohn Forte { 2674fcf3ce44SJohn Forte char sGuid[GUID_INPUT + 1]; 2675fcf3ce44SJohn Forte stmfGuid inGuid; 2676fcf3ce44SJohn Forte unsigned int guid[sizeof (stmfGuid)]; 2677fcf3ce44SJohn Forte int i; 2678fcf3ce44SJohn Forte int ret = 0; 2679fcf3ce44SJohn Forte 2680fcf3ce44SJohn Forte if (strlen(lu) != GUID_INPUT) { 2681fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s %d %s\n", cmdName, lu, 2682fcf3ce44SJohn Forte gettext("must be"), GUID_INPUT, 2683fcf3ce44SJohn Forte gettext("hexadecimal digits long")); 2684fcf3ce44SJohn Forte return (1); 2685fcf3ce44SJohn Forte } 2686fcf3ce44SJohn Forte 2687fcf3ce44SJohn Forte bcopy(lu, sGuid, GUID_INPUT); 2688fcf3ce44SJohn Forte 2689fcf3ce44SJohn Forte for (i = 0; i < 32; i++) 2690fcf3ce44SJohn Forte sGuid[i] = tolower(sGuid[i]); 2691fcf3ce44SJohn Forte sGuid[i] = 0; 2692fcf3ce44SJohn Forte 2693fcf3ce44SJohn Forte (void) sscanf(sGuid, "%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x", 2694fcf3ce44SJohn Forte &guid[0], &guid[1], &guid[2], &guid[3], &guid[4], &guid[5], 2695fcf3ce44SJohn Forte &guid[6], &guid[7], &guid[8], &guid[9], &guid[10], &guid[11], 2696fcf3ce44SJohn Forte &guid[12], &guid[13], &guid[14], &guid[15]); 2697fcf3ce44SJohn Forte 2698fcf3ce44SJohn Forte for (i = 0; i < sizeof (stmfGuid); i++) { 2699fcf3ce44SJohn Forte inGuid.guid[i] = guid[i]; 2700fcf3ce44SJohn Forte } 2701fcf3ce44SJohn Forte 2702fcf3ce44SJohn Forte if (state == ONLINE_LU) { 2703fcf3ce44SJohn Forte ret = stmfOnlineLogicalUnit(&inGuid); 2704fcf3ce44SJohn Forte } else if (state == OFFLINE_LU) { 2705fcf3ce44SJohn Forte ret = stmfOfflineLogicalUnit(&inGuid); 2706fcf3ce44SJohn Forte } 2707fcf3ce44SJohn Forte if (ret != STMF_STATUS_SUCCESS) { 2708fcf3ce44SJohn Forte switch (ret) { 2709fcf3ce44SJohn Forte case STMF_ERROR_PERM: 2710fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 2711fcf3ce44SJohn Forte gettext("permission denied")); 2712fcf3ce44SJohn Forte break; 2713fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_NOT_FOUND: 2714fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 2715fcf3ce44SJohn Forte gettext("STMF service not found")); 2716fcf3ce44SJohn Forte break; 2717fcf3ce44SJohn Forte case STMF_ERROR_NOT_FOUND: 2718fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 2719fcf3ce44SJohn Forte lu, gettext("not found")); 2720fcf3ce44SJohn Forte break; 2721fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_DATA_VERSION: 2722fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 2723fcf3ce44SJohn Forte gettext("STMF service version incorrect")); 2724fcf3ce44SJohn Forte break; 2725fcf3ce44SJohn Forte default: 2726fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 2727fcf3ce44SJohn Forte gettext("unknown error")); 2728fcf3ce44SJohn Forte break; 2729fcf3ce44SJohn Forte } 2730fcf3ce44SJohn Forte } 2731fcf3ce44SJohn Forte return (ret); 2732fcf3ce44SJohn Forte } 2733fcf3ce44SJohn Forte 2734fcf3ce44SJohn Forte /* 2735fcf3ce44SJohn Forte * onlineLuFunc 2736fcf3ce44SJohn Forte * 2737fcf3ce44SJohn Forte * Purpose: Online a logical unit 2738fcf3ce44SJohn Forte * 2739fcf3ce44SJohn Forte */ 2740fcf3ce44SJohn Forte /*ARGSUSED*/ 2741fcf3ce44SJohn Forte static int 2742fcf3ce44SJohn Forte onlineLuFunc(int operandLen, char *operands[], cmdOptions_t *options, 2743fcf3ce44SJohn Forte void *args) 2744fcf3ce44SJohn Forte { 2745e17f3b22Stim szeto int ret; 2746e17f3b22Stim szeto stmfState state; 2747e17f3b22Stim szeto 2748e17f3b22Stim szeto ret = getStmfState(&state); 2749e17f3b22Stim szeto if (ret != STMF_STATUS_SUCCESS) 2750e17f3b22Stim szeto return (ret); 2751e17f3b22Stim szeto if (state.operationalState == STMF_SERVICE_STATE_OFFLINE || 2752e17f3b22Stim szeto state.operationalState == STMF_SERVICE_STATE_OFFLINING) { 2753e17f3b22Stim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 2754e17f3b22Stim szeto gettext("STMF service is offline")); 2755e17f3b22Stim szeto return (1); 2756e17f3b22Stim szeto } 2757fcf3ce44SJohn Forte return (onlineOfflineLu(operands[0], ONLINE_LU)); 2758fcf3ce44SJohn Forte } 2759fcf3ce44SJohn Forte 2760fcf3ce44SJohn Forte /* 2761fcf3ce44SJohn Forte * offlineLuFunc 2762fcf3ce44SJohn Forte * 2763fcf3ce44SJohn Forte * Purpose: Offline a logical unit 2764fcf3ce44SJohn Forte * 2765fcf3ce44SJohn Forte */ 2766fcf3ce44SJohn Forte /*ARGSUSED*/ 2767fcf3ce44SJohn Forte static int 2768fcf3ce44SJohn Forte offlineLuFunc(int operandLen, char *operands[], cmdOptions_t *options, 2769fcf3ce44SJohn Forte void *args) 2770fcf3ce44SJohn Forte { 2771fcf3ce44SJohn Forte return (onlineOfflineLu(operands[0], OFFLINE_LU)); 2772fcf3ce44SJohn Forte } 2773fcf3ce44SJohn Forte 2774fcf3ce44SJohn Forte /* 2775fcf3ce44SJohn Forte * onlineOfflineTarget 2776fcf3ce44SJohn Forte * 2777fcf3ce44SJohn Forte * Purpose: Online or offline a target 2778fcf3ce44SJohn Forte * 2779fcf3ce44SJohn Forte * target - target to online or offline 2780fcf3ce44SJohn Forte * 2781fcf3ce44SJohn Forte * state - ONLINE_TARGET 2782fcf3ce44SJohn Forte * OFFLINE_TARGET 2783fcf3ce44SJohn Forte */ 2784fcf3ce44SJohn Forte static int 2785fcf3ce44SJohn Forte onlineOfflineTarget(char *target, int state) 2786fcf3ce44SJohn Forte { 2787fcf3ce44SJohn Forte int ret = 0; 2788fcf3ce44SJohn Forte stmfDevid devid; 2789fcf3ce44SJohn Forte 2790fcf3ce44SJohn Forte if (parseDevid(target, &devid) != 0) { 2791fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", 2792fcf3ce44SJohn Forte cmdName, target, gettext("unrecognized device id")); 2793fcf3ce44SJohn Forte return (1); 2794fcf3ce44SJohn Forte } 2795fcf3ce44SJohn Forte if (state == ONLINE_TARGET) { 2796fcf3ce44SJohn Forte ret = stmfOnlineTarget(&devid); 2797fcf3ce44SJohn Forte } else if (state == OFFLINE_TARGET) { 2798fcf3ce44SJohn Forte ret = stmfOfflineTarget(&devid); 2799fcf3ce44SJohn Forte } 2800fcf3ce44SJohn Forte if (ret != STMF_STATUS_SUCCESS) { 2801fcf3ce44SJohn Forte switch (ret) { 2802fcf3ce44SJohn Forte case STMF_ERROR_PERM: 2803fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 2804fcf3ce44SJohn Forte gettext("permission denied")); 2805fcf3ce44SJohn Forte break; 2806fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_NOT_FOUND: 2807fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 2808fcf3ce44SJohn Forte gettext("STMF service not found")); 2809fcf3ce44SJohn Forte break; 2810fcf3ce44SJohn Forte case STMF_ERROR_NOT_FOUND: 2811fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 2812fcf3ce44SJohn Forte target, gettext("not found")); 2813fcf3ce44SJohn Forte break; 2814fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_DATA_VERSION: 2815fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 2816fcf3ce44SJohn Forte gettext("STMF service version incorrect")); 2817fcf3ce44SJohn Forte break; 2818fcf3ce44SJohn Forte default: 2819fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 2820fcf3ce44SJohn Forte gettext("unknown error")); 2821fcf3ce44SJohn Forte break; 2822fcf3ce44SJohn Forte } 2823fcf3ce44SJohn Forte } 2824fcf3ce44SJohn Forte return (ret); 2825fcf3ce44SJohn Forte } 2826fcf3ce44SJohn Forte 2827fcf3ce44SJohn Forte /* 2828fcf3ce44SJohn Forte * onlineTargetFunc 2829fcf3ce44SJohn Forte * 2830fcf3ce44SJohn Forte * Purpose: Online a target 2831fcf3ce44SJohn Forte * 2832fcf3ce44SJohn Forte */ 2833fcf3ce44SJohn Forte /*ARGSUSED*/ 2834fcf3ce44SJohn Forte static int 2835fcf3ce44SJohn Forte onlineTargetFunc(int operandLen, char *operands[], cmdOptions_t *options, 2836fcf3ce44SJohn Forte void *args) 2837fcf3ce44SJohn Forte { 2838e17f3b22Stim szeto int ret; 2839e17f3b22Stim szeto stmfState state; 2840e17f3b22Stim szeto 2841e17f3b22Stim szeto ret = getStmfState(&state); 2842e17f3b22Stim szeto if (ret != STMF_STATUS_SUCCESS) 2843e17f3b22Stim szeto return (ret); 2844e17f3b22Stim szeto if (state.operationalState == STMF_SERVICE_STATE_OFFLINE || 2845e17f3b22Stim szeto state.operationalState == STMF_SERVICE_STATE_OFFLINING) { 2846e17f3b22Stim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 2847e17f3b22Stim szeto gettext("STMF service is offline")); 2848e17f3b22Stim szeto return (1); 2849e17f3b22Stim szeto } 2850fcf3ce44SJohn Forte return (onlineOfflineTarget(operands[0], ONLINE_TARGET)); 2851fcf3ce44SJohn Forte } 2852fcf3ce44SJohn Forte 2853fcf3ce44SJohn Forte /* 2854fcf3ce44SJohn Forte * offlineTargetFunc 2855fcf3ce44SJohn Forte * 2856fcf3ce44SJohn Forte * Purpose: Offline a target 2857fcf3ce44SJohn Forte * 2858fcf3ce44SJohn Forte */ 2859fcf3ce44SJohn Forte /*ARGSUSED*/ 2860fcf3ce44SJohn Forte static int 2861fcf3ce44SJohn Forte offlineTargetFunc(int operandLen, char *operands[], cmdOptions_t *options, 2862fcf3ce44SJohn Forte void *args) 2863fcf3ce44SJohn Forte { 2864fcf3ce44SJohn Forte return (onlineOfflineTarget(operands[0], OFFLINE_TARGET)); 2865fcf3ce44SJohn Forte } 2866fcf3ce44SJohn Forte 2867fcf3ce44SJohn Forte 2868fcf3ce44SJohn Forte /*ARGSUSED*/ 2869fcf3ce44SJohn Forte static int 2870fcf3ce44SJohn Forte removeHostGroupMemberFunc(int operandLen, char *operands[], 2871fcf3ce44SJohn Forte cmdOptions_t *options, void *args) 2872fcf3ce44SJohn Forte { 2873fcf3ce44SJohn Forte int i; 2874fcf3ce44SJohn Forte int ret = 0; 2875fcf3ce44SJohn Forte int stmfRet; 28763e7352aeSJohn Forte stmfGroupName groupName = {0}; 2877fcf3ce44SJohn Forte stmfDevid devid; 28783e7352aeSJohn Forte wchar_t groupNamePrint[sizeof (stmfGroupName)] = {0}; 2879fcf3ce44SJohn Forte 2880fcf3ce44SJohn Forte for (; options->optval; options++) { 2881fcf3ce44SJohn Forte switch (options->optval) { 2882fcf3ce44SJohn Forte case 'g': 2883fcf3ce44SJohn Forte (void) mbstowcs(groupNamePrint, options->optarg, 28843e7352aeSJohn Forte sizeof (stmfGroupName) - 1); 2885fcf3ce44SJohn Forte bcopy(options->optarg, groupName, 2886fcf3ce44SJohn Forte strlen(options->optarg)); 2887fcf3ce44SJohn Forte break; 2888fcf3ce44SJohn Forte default: 2889fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %c: %s\n", 2890fcf3ce44SJohn Forte cmdName, options->optval, 2891fcf3ce44SJohn Forte gettext("unknown option")); 2892fcf3ce44SJohn Forte return (1); 2893fcf3ce44SJohn Forte } 2894fcf3ce44SJohn Forte } 2895fcf3ce44SJohn Forte 2896fcf3ce44SJohn Forte for (i = 0; i < operandLen; i++) { 2897fcf3ce44SJohn Forte if (parseDevid(operands[i], &devid) != 0) { 2898fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", 2899fcf3ce44SJohn Forte cmdName, operands[i], 2900fcf3ce44SJohn Forte gettext("unrecognized device id")); 2901fcf3ce44SJohn Forte ret++; 2902fcf3ce44SJohn Forte continue; 2903fcf3ce44SJohn Forte } 2904fcf3ce44SJohn Forte stmfRet = stmfRemoveFromHostGroup(&groupName, &devid); 2905fcf3ce44SJohn Forte switch (stmfRet) { 2906fcf3ce44SJohn Forte case STMF_STATUS_SUCCESS: 2907fcf3ce44SJohn Forte break; 2908fcf3ce44SJohn Forte case STMF_ERROR_MEMBER_NOT_FOUND: 2909fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 2910fcf3ce44SJohn Forte operands[i], gettext("not found")); 2911fcf3ce44SJohn Forte ret++; 2912fcf3ce44SJohn Forte break; 2913fcf3ce44SJohn Forte case STMF_ERROR_GROUP_NOT_FOUND: 2914fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %ws: %s\n", cmdName, 2915fcf3ce44SJohn Forte groupNamePrint, gettext("not found")); 2916fcf3ce44SJohn Forte ret++; 2917fcf3ce44SJohn Forte break; 2918fcf3ce44SJohn Forte case STMF_ERROR_BUSY: 2919fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 2920fcf3ce44SJohn Forte operands[i], "resource busy"); 2921fcf3ce44SJohn Forte ret++; 2922fcf3ce44SJohn Forte break; 2923fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_NOT_FOUND: 2924fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 2925fcf3ce44SJohn Forte gettext("STMF service not found")); 2926fcf3ce44SJohn Forte ret++; 2927fcf3ce44SJohn Forte break; 2928fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_DATA_VERSION: 2929fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 2930fcf3ce44SJohn Forte gettext("STMF service version incorrect")); 2931fcf3ce44SJohn Forte ret++; 2932fcf3ce44SJohn Forte break; 2933fcf3ce44SJohn Forte case STMF_ERROR_PERM: 2934fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 2935fcf3ce44SJohn Forte gettext("permission denied")); 2936fcf3ce44SJohn Forte ret++; 2937fcf3ce44SJohn Forte break; 2938fcf3ce44SJohn Forte default: 2939fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 2940fcf3ce44SJohn Forte operands[i], gettext("unknown error")); 2941fcf3ce44SJohn Forte ret++; 2942fcf3ce44SJohn Forte break; 2943fcf3ce44SJohn Forte } 2944fcf3ce44SJohn Forte } 2945fcf3ce44SJohn Forte 2946fcf3ce44SJohn Forte return (ret); 2947fcf3ce44SJohn Forte } 2948fcf3ce44SJohn Forte 2949fcf3ce44SJohn Forte /* 2950fcf3ce44SJohn Forte * removeTargetGroupMemberFunc 2951fcf3ce44SJohn Forte * 2952fcf3ce44SJohn Forte * Removes one or more members from a target group 2953fcf3ce44SJohn Forte * 2954fcf3ce44SJohn Forte */ 2955fcf3ce44SJohn Forte /*ARGSUSED*/ 2956fcf3ce44SJohn Forte static int 2957fcf3ce44SJohn Forte removeTargetGroupMemberFunc(int operandLen, char *operands[], 2958fcf3ce44SJohn Forte cmdOptions_t *options, void *args) 2959fcf3ce44SJohn Forte { 2960fcf3ce44SJohn Forte int i; 2961fcf3ce44SJohn Forte int ret = 0; 2962fcf3ce44SJohn Forte int stmfRet; 29633e7352aeSJohn Forte stmfGroupName groupName = {0}; 2964fcf3ce44SJohn Forte stmfDevid devid; 29653e7352aeSJohn Forte wchar_t groupNamePrint[sizeof (stmfGroupName)] = {0}; 2966fcf3ce44SJohn Forte 2967fcf3ce44SJohn Forte for (; options->optval; options++) { 2968fcf3ce44SJohn Forte switch (options->optval) { 2969fcf3ce44SJohn Forte case 'g': 2970fcf3ce44SJohn Forte (void) mbstowcs(groupNamePrint, options->optarg, 29713e7352aeSJohn Forte sizeof (stmfGroupName) - 1); 2972fcf3ce44SJohn Forte bcopy(options->optarg, groupName, 2973fcf3ce44SJohn Forte strlen(options->optarg)); 2974fcf3ce44SJohn Forte break; 2975fcf3ce44SJohn Forte default: 2976fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %c: %s\n", 2977fcf3ce44SJohn Forte cmdName, options->optval, 2978fcf3ce44SJohn Forte gettext("unknown option")); 2979fcf3ce44SJohn Forte return (1); 2980fcf3ce44SJohn Forte } 2981fcf3ce44SJohn Forte } 2982fcf3ce44SJohn Forte 2983fcf3ce44SJohn Forte for (i = 0; i < operandLen; i++) { 2984fcf3ce44SJohn Forte if (parseDevid(operands[i], &devid) != 0) { 2985fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", 2986fcf3ce44SJohn Forte cmdName, operands[i], 2987fcf3ce44SJohn Forte gettext("unrecognized device id")); 2988fcf3ce44SJohn Forte ret++; 2989fcf3ce44SJohn Forte continue; 2990fcf3ce44SJohn Forte } 2991fcf3ce44SJohn Forte stmfRet = stmfRemoveFromTargetGroup(&groupName, &devid); 2992fcf3ce44SJohn Forte switch (stmfRet) { 2993fcf3ce44SJohn Forte case STMF_STATUS_SUCCESS: 2994fcf3ce44SJohn Forte break; 2995fcf3ce44SJohn Forte case STMF_ERROR_MEMBER_NOT_FOUND: 2996fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 2997fcf3ce44SJohn Forte operands[i], gettext("not found")); 2998fcf3ce44SJohn Forte ret++; 2999fcf3ce44SJohn Forte break; 3000fcf3ce44SJohn Forte case STMF_ERROR_GROUP_NOT_FOUND: 3001fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %ws: %s\n", cmdName, 3002fcf3ce44SJohn Forte groupNamePrint, gettext("not found")); 3003fcf3ce44SJohn Forte ret++; 3004fcf3ce44SJohn Forte break; 3005fcf3ce44SJohn Forte case STMF_ERROR_BUSY: 3006fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 3007fcf3ce44SJohn Forte operands[i], gettext("resource busy")); 3008fcf3ce44SJohn Forte ret++; 3009fcf3ce44SJohn Forte break; 3010fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_NOT_FOUND: 3011fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 3012fcf3ce44SJohn Forte gettext("STMF service not found")); 3013fcf3ce44SJohn Forte ret++; 3014fcf3ce44SJohn Forte break; 3015fcf3ce44SJohn Forte case STMF_ERROR_PERM: 3016fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 3017fcf3ce44SJohn Forte gettext("permission denied")); 3018fcf3ce44SJohn Forte ret++; 3019fcf3ce44SJohn Forte break; 3020fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_DATA_VERSION: 3021fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 3022fcf3ce44SJohn Forte gettext("STMF service version incorrect")); 3023fcf3ce44SJohn Forte ret++; 3024fcf3ce44SJohn Forte break; 3025fcf3ce44SJohn Forte default: 3026fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 3027fcf3ce44SJohn Forte operands[i], gettext("unknown error")); 3028fcf3ce44SJohn Forte ret++; 3029fcf3ce44SJohn Forte break; 3030fcf3ce44SJohn Forte } 3031fcf3ce44SJohn Forte } 3032fcf3ce44SJohn Forte 3033fcf3ce44SJohn Forte return (ret); 3034fcf3ce44SJohn Forte } 3035fcf3ce44SJohn Forte 3036fcf3ce44SJohn Forte /* 3037fcf3ce44SJohn Forte * removeViewFunc 3038fcf3ce44SJohn Forte * 3039fcf3ce44SJohn Forte * Removes one or more view entries from a logical unit 3040fcf3ce44SJohn Forte * 3041fcf3ce44SJohn Forte */ 3042fcf3ce44SJohn Forte /*ARGSUSED*/ 3043fcf3ce44SJohn Forte static int 3044fcf3ce44SJohn Forte removeViewFunc(int operandLen, char *operands[], cmdOptions_t *options, 3045fcf3ce44SJohn Forte void *args) 3046fcf3ce44SJohn Forte { 3047fcf3ce44SJohn Forte char sGuid[GUID_INPUT + 1]; 3048fcf3ce44SJohn Forte stmfViewEntryList *viewEntryList; 3049fcf3ce44SJohn Forte stmfGuid inGuid; 3050fcf3ce44SJohn Forte uint32_t count; 3051fcf3ce44SJohn Forte unsigned int guid[sizeof (stmfGuid)]; 3052fcf3ce44SJohn Forte char *endPtr; 3053fcf3ce44SJohn Forte uint32_t veNbr; 3054fcf3ce44SJohn Forte int i; 3055fcf3ce44SJohn Forte boolean_t all = B_FALSE; 3056fcf3ce44SJohn Forte boolean_t luInput = B_FALSE; 3057fcf3ce44SJohn Forte int ret = 0; 3058fcf3ce44SJohn Forte int stmfRet; 3059fcf3ce44SJohn Forte 3060fcf3ce44SJohn Forte /* Note: 'l' is required */ 3061fcf3ce44SJohn Forte for (; options->optval; options++) { 3062fcf3ce44SJohn Forte switch (options->optval) { 3063fcf3ce44SJohn Forte case 'l': 3064fcf3ce44SJohn Forte if (strlen(options->optarg) != GUID_INPUT) { 3065fcf3ce44SJohn Forte (void) fprintf(stderr, 3066fcf3ce44SJohn Forte "%s: %s: %s %d %s\n", 3067fcf3ce44SJohn Forte cmdName, options->optarg, 3068fcf3ce44SJohn Forte gettext("must be"), GUID_INPUT, 3069fcf3ce44SJohn Forte gettext("hexadecimal digits long")); 3070fcf3ce44SJohn Forte return (1); 3071fcf3ce44SJohn Forte } 3072fcf3ce44SJohn Forte bcopy(options->optarg, sGuid, GUID_INPUT); 3073fcf3ce44SJohn Forte luInput = B_TRUE; 3074fcf3ce44SJohn Forte break; 3075fcf3ce44SJohn Forte case 'a': 3076fcf3ce44SJohn Forte /* removing all view entries for this GUID */ 3077fcf3ce44SJohn Forte all = B_TRUE; 3078fcf3ce44SJohn Forte break; 3079fcf3ce44SJohn Forte default: 3080fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %c: %s\n", 3081fcf3ce44SJohn Forte cmdName, options->optval, 3082fcf3ce44SJohn Forte "unknown option"); 3083fcf3ce44SJohn Forte return (1); 3084fcf3ce44SJohn Forte } 3085fcf3ce44SJohn Forte } 3086fcf3ce44SJohn Forte 3087fcf3ce44SJohn Forte if (!all && operandLen == 0) { 3088fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 3089fcf3ce44SJohn Forte gettext("no view entries specified")); 3090fcf3ce44SJohn Forte return (1); 3091fcf3ce44SJohn Forte } 3092fcf3ce44SJohn Forte 3093fcf3ce44SJohn Forte if (!luInput) { 3094fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 3095fcf3ce44SJohn Forte gettext("logical unit (-l) not specified")); 3096fcf3ce44SJohn Forte return (1); 3097fcf3ce44SJohn Forte } 3098fcf3ce44SJohn Forte 3099fcf3ce44SJohn Forte for (i = 0; i < 32; i++) 3100fcf3ce44SJohn Forte sGuid[i] = tolower(sGuid[i]); 3101fcf3ce44SJohn Forte sGuid[i] = 0; 3102fcf3ce44SJohn Forte 3103fcf3ce44SJohn Forte (void) sscanf(sGuid, "%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x", 3104fcf3ce44SJohn Forte &guid[0], &guid[1], &guid[2], &guid[3], &guid[4], &guid[5], 3105fcf3ce44SJohn Forte &guid[6], &guid[7], &guid[8], &guid[9], &guid[10], &guid[11], 3106fcf3ce44SJohn Forte &guid[12], &guid[13], &guid[14], &guid[15]); 3107fcf3ce44SJohn Forte 3108fcf3ce44SJohn Forte for (i = 0; i < sizeof (stmfGuid); i++) { 3109fcf3ce44SJohn Forte inGuid.guid[i] = guid[i]; 3110fcf3ce44SJohn Forte } 3111fcf3ce44SJohn Forte 3112fcf3ce44SJohn Forte if ((stmfRet = stmfGetViewEntryList(&inGuid, &viewEntryList)) 3113fcf3ce44SJohn Forte != STMF_STATUS_SUCCESS) { 3114fcf3ce44SJohn Forte 3115fcf3ce44SJohn Forte switch (stmfRet) { 3116fcf3ce44SJohn Forte case STMF_ERROR_BUSY: 3117fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 3118fcf3ce44SJohn Forte sGuid, gettext("resource busy")); 3119fcf3ce44SJohn Forte break; 3120fcf3ce44SJohn Forte case STMF_ERROR_NOT_FOUND: 3121fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 3122fcf3ce44SJohn Forte sGuid, gettext("no views found")); 3123fcf3ce44SJohn Forte break; 3124fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_NOT_FOUND: 3125fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 3126fcf3ce44SJohn Forte gettext("STMF service not found")); 3127fcf3ce44SJohn Forte break; 3128fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_DATA_VERSION: 3129fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 3130fcf3ce44SJohn Forte gettext("STMF service version incorrect")); 3131fcf3ce44SJohn Forte break; 3132fcf3ce44SJohn Forte case STMF_ERROR_PERM: 3133fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 3134fcf3ce44SJohn Forte gettext("permission denied")); 3135fcf3ce44SJohn Forte break; 3136fcf3ce44SJohn Forte default: 3137fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 3138fcf3ce44SJohn Forte sGuid, gettext("unknown error")); 3139fcf3ce44SJohn Forte break; 3140fcf3ce44SJohn Forte } 3141fcf3ce44SJohn Forte return (1); 3142fcf3ce44SJohn Forte } 3143fcf3ce44SJohn Forte 3144fcf3ce44SJohn Forte if (all) { 3145fcf3ce44SJohn Forte count = viewEntryList->cnt; 3146fcf3ce44SJohn Forte } else { 3147fcf3ce44SJohn Forte count = operandLen; 3148fcf3ce44SJohn Forte } 3149fcf3ce44SJohn Forte 3150fcf3ce44SJohn Forte for (i = 0; i < count; i++) { 3151fcf3ce44SJohn Forte if (all) { 3152fcf3ce44SJohn Forte veNbr = viewEntryList->ve[i].veIndex; 3153fcf3ce44SJohn Forte } else { 3154fcf3ce44SJohn Forte endPtr = NULL; 3155fcf3ce44SJohn Forte veNbr = strtol(operands[i], &endPtr, 10); 3156fcf3ce44SJohn Forte if (endPtr && *endPtr != 0) { 3157fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 3158fcf3ce44SJohn Forte operands[i], gettext("invalid input")); 3159fcf3ce44SJohn Forte continue; 3160fcf3ce44SJohn Forte } 3161fcf3ce44SJohn Forte } 3162fcf3ce44SJohn Forte stmfRet = stmfRemoveViewEntry(&inGuid, veNbr); 3163fcf3ce44SJohn Forte switch (stmfRet) { 3164fcf3ce44SJohn Forte case STMF_STATUS_SUCCESS: 3165fcf3ce44SJohn Forte break; 3166fcf3ce44SJohn Forte case STMF_ERROR_NOT_FOUND: 3167fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %d: %s\n", 3168fcf3ce44SJohn Forte cmdName, sGuid, veNbr, 3169fcf3ce44SJohn Forte gettext("not found")); 3170fcf3ce44SJohn Forte ret++; 3171fcf3ce44SJohn Forte break; 3172fcf3ce44SJohn Forte case STMF_ERROR_BUSY: 3173fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 3174fcf3ce44SJohn Forte sGuid, gettext("resource busy")); 3175fcf3ce44SJohn Forte ret++; 3176fcf3ce44SJohn Forte break; 3177fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_NOT_FOUND: 3178fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 3179fcf3ce44SJohn Forte gettext("STMF service not found")); 3180fcf3ce44SJohn Forte ret++; 3181fcf3ce44SJohn Forte break; 3182fcf3ce44SJohn Forte case STMF_ERROR_CONFIG_NONE: 3183fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 3184fcf3ce44SJohn Forte gettext("STMF service is not initialized")); 3185fcf3ce44SJohn Forte ret++; 3186fcf3ce44SJohn Forte break; 3187fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_DATA_VERSION: 3188fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 3189fcf3ce44SJohn Forte gettext("STMF service version incorrect")); 3190fcf3ce44SJohn Forte ret++; 3191fcf3ce44SJohn Forte break; 3192fcf3ce44SJohn Forte default: 3193fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s, %d: %s", 3194fcf3ce44SJohn Forte cmdName, sGuid, veNbr, 3195fcf3ce44SJohn Forte gettext("unknown error")); 3196fcf3ce44SJohn Forte ret++; 3197fcf3ce44SJohn Forte break; 3198fcf3ce44SJohn Forte } 3199fcf3ce44SJohn Forte } 3200fcf3ce44SJohn Forte 3201fcf3ce44SJohn Forte return (ret); 3202fcf3ce44SJohn Forte } 3203fcf3ce44SJohn Forte 3204fcf3ce44SJohn Forte /* 3205fcf3ce44SJohn Forte * input: 3206fcf3ce44SJohn Forte * execFullName - exec name of program (argv[0]) 3207fcf3ce44SJohn Forte * 3208fcf3ce44SJohn Forte * copied from usr/src/cmd/zoneadm/zoneadm.c in OS/Net 3209fcf3ce44SJohn Forte * (changed name to lowerCamelCase to keep consistent with this file) 3210fcf3ce44SJohn Forte * 3211fcf3ce44SJohn Forte * Returns: 3212fcf3ce44SJohn Forte * command name portion of execFullName 3213fcf3ce44SJohn Forte */ 3214fcf3ce44SJohn Forte static char * 3215fcf3ce44SJohn Forte getExecBasename(char *execFullname) 3216fcf3ce44SJohn Forte { 3217fcf3ce44SJohn Forte char *lastSlash, *execBasename; 3218fcf3ce44SJohn Forte 3219fcf3ce44SJohn Forte /* guard against '/' at end of command invocation */ 3220fcf3ce44SJohn Forte for (;;) { 3221fcf3ce44SJohn Forte lastSlash = strrchr(execFullname, '/'); 3222fcf3ce44SJohn Forte if (lastSlash == NULL) { 3223fcf3ce44SJohn Forte execBasename = execFullname; 3224fcf3ce44SJohn Forte break; 3225fcf3ce44SJohn Forte } else { 3226fcf3ce44SJohn Forte execBasename = lastSlash + 1; 3227fcf3ce44SJohn Forte if (*execBasename == '\0') { 3228fcf3ce44SJohn Forte *lastSlash = '\0'; 3229fcf3ce44SJohn Forte continue; 3230fcf3ce44SJohn Forte } 3231fcf3ce44SJohn Forte break; 3232fcf3ce44SJohn Forte } 3233fcf3ce44SJohn Forte } 3234fcf3ce44SJohn Forte return (execBasename); 3235fcf3ce44SJohn Forte } 3236fcf3ce44SJohn Forte 3237fcf3ce44SJohn Forte int 3238fcf3ce44SJohn Forte main(int argc, char *argv[]) 3239fcf3ce44SJohn Forte { 3240fcf3ce44SJohn Forte synTables_t synTables; 3241fcf3ce44SJohn Forte char versionString[VERSION_STRING_MAX_LEN]; 3242fcf3ce44SJohn Forte int ret; 3243fcf3ce44SJohn Forte int funcRet; 3244fcf3ce44SJohn Forte void *subcommandArgs = NULL; 3245fcf3ce44SJohn Forte 3246fcf3ce44SJohn Forte (void) setlocale(LC_ALL, ""); 3247fcf3ce44SJohn Forte (void) textdomain(TEXT_DOMAIN); 3248fcf3ce44SJohn Forte /* set global command name */ 3249fcf3ce44SJohn Forte cmdName = getExecBasename(argv[0]); 3250fcf3ce44SJohn Forte 3251fcf3ce44SJohn Forte (void) snprintf(versionString, VERSION_STRING_MAX_LEN, "%s.%s", 3252fcf3ce44SJohn Forte VERSION_STRING_MAJOR, VERSION_STRING_MINOR); 3253fcf3ce44SJohn Forte synTables.versionString = versionString; 3254fcf3ce44SJohn Forte synTables.longOptionTbl = &longOptions[0]; 3255fcf3ce44SJohn Forte synTables.subCommandPropsTbl = &subcommands[0]; 3256fcf3ce44SJohn Forte 3257fcf3ce44SJohn Forte ret = cmdParse(argc, argv, synTables, subcommandArgs, &funcRet); 3258fcf3ce44SJohn Forte if (ret != 0) { 3259fcf3ce44SJohn Forte return (ret); 3260fcf3ce44SJohn Forte } 3261fcf3ce44SJohn Forte 3262fcf3ce44SJohn Forte return (funcRet); 3263fcf3ce44SJohn Forte } /* end main */ 3264