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