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 /* 227b506e25Ssrivijitha dugganapalli * Copyright 2010 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 *); 498fe96085Stim szeto static int createLuFunc(int, char **, cmdOptions_t *, void *); 508fe96085Stim szeto static int modifyLuFunc(int, char **, cmdOptions_t *, void *); 518fe96085Stim szeto static int importLuFunc(int, char **, cmdOptions_t *, void *); 528fe96085Stim szeto static int deleteLuFunc(int, char **, cmdOptions_t *, void *); 53fcf3ce44SJohn Forte static int createTargetGroupFunc(int, char **, cmdOptions_t *, void *); 54fcf3ce44SJohn Forte static int deleteHostGroupFunc(int, char **, cmdOptions_t *, void *); 55fcf3ce44SJohn Forte static int deleteTargetGroupFunc(int, char **, cmdOptions_t *, void *); 56fcf3ce44SJohn Forte static int listLuFunc(int, char **, cmdOptions_t *, void *); 57fcf3ce44SJohn Forte static int listTargetFunc(int, char **, cmdOptions_t *, void *); 58fcf3ce44SJohn Forte static int listViewFunc(int, char **, cmdOptions_t *, void *); 59fcf3ce44SJohn Forte static int listHostGroupFunc(int, char **, cmdOptions_t *, void *); 60fcf3ce44SJohn Forte static int listStateFunc(int, char **, cmdOptions_t *, void *); 61fcf3ce44SJohn Forte static int listTargetGroupFunc(int, char **, cmdOptions_t *, void *); 62fcf3ce44SJohn Forte static int offlineTargetFunc(int, char **, cmdOptions_t *, void *); 63fcf3ce44SJohn Forte static int offlineLuFunc(int, char **, cmdOptions_t *, void *); 64fcf3ce44SJohn Forte static int onlineTargetFunc(int, char **, cmdOptions_t *, void *); 65fcf3ce44SJohn Forte static int onlineLuFunc(int, char **, cmdOptions_t *, void *); 66fcf3ce44SJohn Forte static int onlineOfflineTarget(char *, int); 67fcf3ce44SJohn Forte static int onlineOfflineLu(char *, int); 68fcf3ce44SJohn Forte static int removeHostGroupMemberFunc(int, char **, cmdOptions_t *, void *); 69fcf3ce44SJohn Forte static int removeTargetGroupMemberFunc(int, char **, cmdOptions_t *, void *); 708fe96085Stim szeto static int callModify(char *, stmfGuid *, uint32_t, const char *, const char *); 71fcf3ce44SJohn Forte static int removeViewFunc(int, char **, cmdOptions_t *, void *); 72fcf3ce44SJohn Forte static char *getExecBasename(char *); 73fcf3ce44SJohn Forte static int parseDevid(char *input, stmfDevid *devid); 74fcf3ce44SJohn Forte static void printGroupProps(stmfGroupProperties *groupProps); 75fcf3ce44SJohn Forte static int checkScsiNameString(wchar_t *, stmfDevid *); 76fcf3ce44SJohn Forte static int checkHexUpper(char *); 77fcf3ce44SJohn Forte static int checkIscsiName(wchar_t *); 78fcf3ce44SJohn Forte static void printLuProps(stmfLogicalUnitProperties *luProps); 798fe96085Stim szeto static int printExtLuProps(stmfGuid *guid); 80fcf3ce44SJohn Forte static void printGuid(stmfGuid *guid, FILE *printWhere); 81fcf3ce44SJohn Forte static void printTargetProps(stmfTargetProperties *); 82fcf3ce44SJohn Forte static void printSessionProps(stmfSessionList *); 838fe96085Stim szeto static int setLuPropFromInput(luResource, char *); 848fe96085Stim szeto static int convertCharToPropId(char *, uint32_t *); 85fcf3ce44SJohn Forte 86fcf3ce44SJohn Forte 87fcf3ce44SJohn Forte 88fcf3ce44SJohn Forte /* 89fcf3ce44SJohn Forte * MAJOR - This should only change when there is an incompatible change made 90fcf3ce44SJohn Forte * to the interfaces or the output. 91fcf3ce44SJohn Forte * 92fcf3ce44SJohn Forte * MINOR - This should change whenever there is a new command or new feature 93fcf3ce44SJohn Forte * with no incompatible change. 94fcf3ce44SJohn Forte */ 95fcf3ce44SJohn Forte #define VERSION_STRING_MAJOR "1" 96fcf3ce44SJohn Forte #define VERSION_STRING_MINOR "0" 97fcf3ce44SJohn Forte #define MAX_DEVID_INPUT 256 98fcf3ce44SJohn Forte #define GUID_INPUT 32 99fcf3ce44SJohn Forte #define MAX_LU_NBR 16383 100fcf3ce44SJohn Forte #define ONLINE_LU 0 101fcf3ce44SJohn Forte #define OFFLINE_LU 1 102fcf3ce44SJohn Forte #define ONLINE_TARGET 2 103fcf3ce44SJohn Forte #define OFFLINE_TARGET 3 104fcf3ce44SJohn Forte #define PROPS_FORMAT " %-18s: " 105fcf3ce44SJohn Forte #define VIEW_FORMAT " %-13s: " 106fcf3ce44SJohn Forte #define LVL3_FORMAT " %s" 107fcf3ce44SJohn Forte #define LVL4_FORMAT " %s" 108*4f486358SNattuvetty Bhavyan #define DELAYED_EXEC_WAIT_INTERVAL 300 * 1000 * 1000 /* in nano sec */ 109*4f486358SNattuvetty Bhavyan #define DELAYED_EXEC_WAIT_MAX 30 /* Maximum number of interval times */ 110fcf3ce44SJohn Forte 111fcf3ce44SJohn Forte /* SCSI Name String length definitions */ 112fcf3ce44SJohn Forte #define SNS_EUI_16 16 113fcf3ce44SJohn Forte #define SNS_EUI_24 24 114fcf3ce44SJohn Forte #define SNS_EUI_32 32 115fcf3ce44SJohn Forte #define SNS_NAA_16 16 116fcf3ce44SJohn Forte #define SNS_NAA_32 32 117fcf3ce44SJohn Forte #define SNS_WWN_16 16 118fcf3ce44SJohn Forte #define SNS_IQN_223 223 119fcf3ce44SJohn Forte 1208fe96085Stim szeto /* LU Property strings */ 1218fe96085Stim szeto #define GUID "GUID" 1228fe96085Stim szeto #define ALIAS "ALIAS" 1238fe96085Stim szeto #define VID "VID" 1248fe96085Stim szeto #define PID "PID" 1258fe96085Stim szeto #define META_FILE "META" 1268fe96085Stim szeto #define WRITE_PROTECT "WP" 1278fe96085Stim szeto #define WRITEBACK_CACHE_DISABLE "WCD" 1288fe96085Stim szeto #define COMPANY_ID "OUI" 1298fe96085Stim szeto #define BLOCK_SIZE "BLK" 1308fe96085Stim szeto #define SERIAL_NUMBER "SERIAL" 1312f624233SNattuvetty Bhavyan #define MGMT_URL "MGMT-URL" 132fdcc480aSJohn Forte #define HOST_ID "HOST-ID" 1338fe96085Stim szeto 134*4f486358SNattuvetty Bhavyan #define STMFADM_SUCCESS 0 135*4f486358SNattuvetty Bhavyan #define STMFADM_FAILURE 1 136*4f486358SNattuvetty Bhavyan 1378fe96085Stim szeto #define MODIFY_HELP "\n"\ 1388fe96085Stim szeto "Description: Modify properties of a logical unit. \n" \ 1398fe96085Stim szeto "Valid properties for -p, --lu-prop are: \n" \ 1408fe96085Stim szeto " alias - alias for logical unit (up to 255 chars)\n" \ 1412f624233SNattuvetty Bhavyan " mgmt-url - Management URL address\n" \ 1428fe96085Stim szeto " wcd - write cache disabled (true, false)\n" \ 1438fe96085Stim szeto " wp - write protect (true, false)\n\n" \ 1448fe96085Stim szeto "-f alters the meaning of the operand to be a file name\n" \ 1458fe96085Stim szeto "rather than a LU name. This allows for modification\n" \ 1468fe96085Stim szeto "of a logical unit that is not yet imported into stmf\n" 1478fe96085Stim szeto 1488fe96085Stim szeto #define CREATE_HELP "\n"\ 1498fe96085Stim szeto "Description: Create a logical unit. \n" \ 1508fe96085Stim szeto "Valid properties for -p, --lu-prop are: \n" \ 1518fe96085Stim szeto " alias - alias for logical unit (up to 255 chars)\n" \ 1528fe96085Stim szeto " blk - block size in bytes in 2^n\n" \ 1538fe96085Stim szeto " guid - 32 ascii hex characters in NAA format \n" \ 154fdcc480aSJohn Forte " host-id - host identifier to be used for GUID generation \n" \ 155fdcc480aSJohn Forte " 8 ascii hex characters\n" \ 1568fe96085Stim szeto " meta - separate meta data file name\n" \ 1572f624233SNattuvetty Bhavyan " mgmt-url - Management URL address\n" \ 1588fe96085Stim szeto " oui - organizational unique identifier\n" \ 1598fe96085Stim szeto " 6 ascii hex characters of valid format\n" \ 1608fe96085Stim szeto " pid - product identifier (up to 16 chars)\n" \ 1618fe96085Stim szeto " serial - serial number (up to 252 chars)\n" \ 1628fe96085Stim szeto " vid - vendor identifier (up to 8 chars)\n" \ 1632f624233SNattuvetty Bhavyan " wcd - write cache disabled (true, false)\n" \ 1642f624233SNattuvetty Bhavyan " wp - write protect (true, false)\n" 1658fe96085Stim szeto #define ADD_VIEW_HELP "\n"\ 1668fe96085Stim szeto "Description: Add a view entry to a logical unit. \n" \ 1678fe96085Stim szeto "A view entry is comprised of three elements; the \n" \ 1688fe96085Stim szeto "logical unit number, the target group name and the\n" \ 1698fe96085Stim szeto "host group name. These three elements combine together\n" \ 1708fe96085Stim szeto "to form a view for a given COMSTAR logical unit.\n" \ 1718fe96085Stim szeto "This view is realized by a client, a SCSI initiator,\n" \ 1728fe96085Stim szeto "via a REPORT LUNS command. \n" 1738fe96085Stim szeto 1748fe96085Stim szeto 1758fe96085Stim szeto 176fcf3ce44SJohn Forte /* tables set up based on cmdparse instructions */ 177fcf3ce44SJohn Forte 178fcf3ce44SJohn Forte /* add new options here */ 179fcf3ce44SJohn Forte optionTbl_t longOptions[] = { 180fcf3ce44SJohn Forte {"all", no_arg, 'a', NULL}, 181fcf3ce44SJohn Forte {"group-name", required_arg, 'g', "group-name"}, 1828fe96085Stim szeto {"keep-views", no_arg, 'k', NULL}, 183fcf3ce44SJohn Forte {"lu-name", required_arg, 'l', "LU-Name"}, 184fcf3ce44SJohn Forte {"lun", required_arg, 'n', "logical-unit-number"}, 1858fe96085Stim szeto {"lu-prop", required_arg, 'p', "logical-unit-property=value"}, 1868fe96085Stim szeto {"file", no_arg, 'f', "filename"}, 1878fe96085Stim szeto {"size", required_arg, 's', "size K/M/G/T/P"}, 188fcf3ce44SJohn Forte {"target-group", required_arg, 't', "group-name"}, 189fcf3ce44SJohn Forte {"host-group", required_arg, 'h', "group-name"}, 1908fe96085Stim szeto {"verbose", no_arg, 'v', NULL}, 191fcf3ce44SJohn Forte {NULL, 0, 0, 0} 192fcf3ce44SJohn Forte }; 193fcf3ce44SJohn Forte 194fcf3ce44SJohn Forte /* 195fcf3ce44SJohn Forte * Add new subcommands here 196fcf3ce44SJohn Forte */ 197fcf3ce44SJohn Forte subCommandProps_t subcommands[] = { 198fcf3ce44SJohn Forte {"add-hg-member", addHostGroupMemberFunc, "g", "g", NULL, 1998fe96085Stim szeto OPERAND_MANDATORY_MULTIPLE, OPERANDSTRING_GROUP_MEMBER, NULL}, 200fcf3ce44SJohn Forte {"add-tg-member", addTargetGroupMemberFunc, "g", "g", NULL, 2018fe96085Stim szeto OPERAND_MANDATORY_MULTIPLE, OPERANDSTRING_GROUP_MEMBER, NULL}, 202fcf3ce44SJohn Forte {"add-view", addViewFunc, "nth", NULL, NULL, 2038fe96085Stim szeto OPERAND_MANDATORY_SINGLE, OPERANDSTRING_LU, ADD_VIEW_HELP}, 204fcf3ce44SJohn Forte {"create-hg", createHostGroupFunc, NULL, NULL, NULL, 2058fe96085Stim szeto OPERAND_MANDATORY_SINGLE, OPERANDSTRING_GROUP_NAME, NULL}, 206fcf3ce44SJohn Forte {"create-tg", createTargetGroupFunc, NULL, NULL, NULL, 2078fe96085Stim szeto OPERAND_MANDATORY_SINGLE, OPERANDSTRING_GROUP_NAME, NULL}, 2088fe96085Stim szeto {"create-lu", createLuFunc, "ps", NULL, NULL, OPERAND_MANDATORY_SINGLE, 2098fe96085Stim szeto "lu file", CREATE_HELP}, 210fcf3ce44SJohn Forte {"delete-hg", deleteHostGroupFunc, NULL, NULL, NULL, 2118fe96085Stim szeto OPERAND_MANDATORY_SINGLE, OPERANDSTRING_GROUP_NAME, NULL}, 2128fe96085Stim szeto {"modify-lu", modifyLuFunc, "psf", NULL, NULL, OPERAND_MANDATORY_SINGLE, 2138fe96085Stim szeto OPERANDSTRING_LU, MODIFY_HELP}, 2148fe96085Stim szeto {"delete-lu", deleteLuFunc, "k", NULL, NULL, 2158fe96085Stim szeto OPERAND_MANDATORY_MULTIPLE, OPERANDSTRING_LU, NULL}, 216fcf3ce44SJohn Forte {"delete-tg", deleteTargetGroupFunc, NULL, NULL, NULL, 2178fe96085Stim szeto OPERAND_MANDATORY_SINGLE, OPERANDSTRING_GROUP_NAME, NULL}, 2188fe96085Stim szeto {"import-lu", importLuFunc, NULL, NULL, NULL, 2198fe96085Stim szeto OPERAND_MANDATORY_SINGLE, "file name", NULL}, 220fcf3ce44SJohn Forte {"list-hg", listHostGroupFunc, "v", NULL, NULL, 2218fe96085Stim szeto OPERAND_OPTIONAL_MULTIPLE, OPERANDSTRING_GROUP_NAME, NULL}, 222fcf3ce44SJohn Forte {"list-lu", listLuFunc, "v", NULL, NULL, OPERAND_OPTIONAL_MULTIPLE, 2238fe96085Stim szeto OPERANDSTRING_LU, NULL}, 224fcf3ce44SJohn Forte {"list-state", listStateFunc, NULL, NULL, NULL, OPERAND_NONE, NULL}, 225fcf3ce44SJohn Forte {"list-target", listTargetFunc, "v", NULL, NULL, 2268fe96085Stim szeto OPERAND_OPTIONAL_MULTIPLE, OPERANDSTRING_TARGET, NULL}, 227fcf3ce44SJohn Forte {"list-tg", listTargetGroupFunc, "v", NULL, NULL, 2288fe96085Stim szeto OPERAND_OPTIONAL_MULTIPLE, OPERANDSTRING_GROUP_NAME, NULL}, 229fcf3ce44SJohn Forte {"list-view", listViewFunc, "l", "l", NULL, 2308fe96085Stim szeto OPERAND_OPTIONAL_MULTIPLE, OPERANDSTRING_VIEW_ENTRY, NULL}, 231fcf3ce44SJohn Forte {"online-lu", onlineLuFunc, NULL, NULL, NULL, 2328fe96085Stim szeto OPERAND_MANDATORY_SINGLE, OPERANDSTRING_LU, NULL}, 233fcf3ce44SJohn Forte {"offline-lu", offlineLuFunc, NULL, NULL, NULL, 2348fe96085Stim szeto OPERAND_MANDATORY_SINGLE, OPERANDSTRING_LU, NULL}, 235fcf3ce44SJohn Forte {"online-target", onlineTargetFunc, NULL, NULL, NULL, 2368fe96085Stim szeto OPERAND_MANDATORY_SINGLE, OPERANDSTRING_TARGET, NULL}, 237fcf3ce44SJohn Forte {"offline-target", offlineTargetFunc, NULL, NULL, NULL, 2388fe96085Stim szeto OPERAND_MANDATORY_SINGLE, OPERANDSTRING_TARGET, NULL}, 239fcf3ce44SJohn Forte {"remove-hg-member", removeHostGroupMemberFunc, "g", "g", NULL, 2408fe96085Stim szeto OPERAND_MANDATORY_MULTIPLE, OPERANDSTRING_GROUP_MEMBER, NULL}, 241fcf3ce44SJohn Forte {"remove-tg-member", removeTargetGroupMemberFunc, "g", "g", NULL, 2428fe96085Stim szeto OPERAND_MANDATORY_MULTIPLE, OPERANDSTRING_GROUP_MEMBER, NULL}, 243fcf3ce44SJohn Forte {"remove-view", removeViewFunc, "la", "l", NULL, 2448fe96085Stim szeto OPERAND_OPTIONAL_MULTIPLE, OPERANDSTRING_VIEW_ENTRY, NULL}, 2458fe96085Stim szeto {NULL, 0, NULL, NULL, 0, NULL, 0, NULL, NULL} 246fcf3ce44SJohn Forte }; 247fcf3ce44SJohn Forte 248fcf3ce44SJohn Forte /* globals */ 249fcf3ce44SJohn Forte char *cmdName; 250fcf3ce44SJohn Forte 251fcf3ce44SJohn Forte /* 252fcf3ce44SJohn Forte * addHostGroupMemberFunc 253fcf3ce44SJohn Forte * 254fcf3ce44SJohn Forte * Add members to a host group 255fcf3ce44SJohn Forte * 256fcf3ce44SJohn Forte */ 257fcf3ce44SJohn Forte /*ARGSUSED*/ 258fcf3ce44SJohn Forte static int 259fcf3ce44SJohn Forte addHostGroupMemberFunc(int operandLen, char *operands[], cmdOptions_t *options, 260fcf3ce44SJohn Forte void *args) 261fcf3ce44SJohn Forte { 262fcf3ce44SJohn Forte int i; 263fcf3ce44SJohn Forte int ret = 0; 264fcf3ce44SJohn Forte int stmfRet; 2653e7352aeSJohn Forte stmfGroupName groupName = {0}; 2663e7352aeSJohn Forte wchar_t groupNamePrint[sizeof (stmfGroupName)] = {0}; 267fcf3ce44SJohn Forte stmfDevid devid; 268fcf3ce44SJohn Forte 269fcf3ce44SJohn Forte for (; options->optval; options++) { 270fcf3ce44SJohn Forte switch (options->optval) { 271fcf3ce44SJohn Forte /* host group name */ 272fcf3ce44SJohn Forte case 'g': 273fcf3ce44SJohn Forte (void) mbstowcs(groupNamePrint, options->optarg, 2743e7352aeSJohn Forte sizeof (stmfGroupName) - 1); 275fcf3ce44SJohn Forte bcopy(options->optarg, groupName, 276fcf3ce44SJohn Forte strlen(options->optarg)); 277fcf3ce44SJohn Forte break; 278fcf3ce44SJohn Forte default: 279fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %c: %s\n", 280fcf3ce44SJohn Forte cmdName, options->optval, 281fcf3ce44SJohn Forte gettext("unknown option")); 282fcf3ce44SJohn Forte return (1); 283fcf3ce44SJohn Forte } 284fcf3ce44SJohn Forte } 285fcf3ce44SJohn Forte 286fcf3ce44SJohn Forte for (i = 0; i < operandLen; i++) { 287fcf3ce44SJohn Forte if (parseDevid(operands[i], &devid) != 0) { 288fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", 289fcf3ce44SJohn Forte cmdName, operands[i], 290fcf3ce44SJohn Forte gettext("unrecognized device id")); 291fcf3ce44SJohn Forte ret++; 292fcf3ce44SJohn Forte continue; 293fcf3ce44SJohn Forte } 294fcf3ce44SJohn Forte stmfRet = stmfAddToHostGroup(&groupName, &devid); 295fcf3ce44SJohn Forte switch (stmfRet) { 296fcf3ce44SJohn Forte case STMF_STATUS_SUCCESS: 297fcf3ce44SJohn Forte break; 298fcf3ce44SJohn Forte case STMF_ERROR_EXISTS: 299fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 300fcf3ce44SJohn Forte operands[i], gettext("already exists")); 301fcf3ce44SJohn Forte ret++; 302fcf3ce44SJohn Forte break; 303fcf3ce44SJohn Forte case STMF_ERROR_GROUP_NOT_FOUND: 304fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %ws: %s\n", cmdName, 305fcf3ce44SJohn Forte groupNamePrint, gettext("not found")); 306fcf3ce44SJohn Forte ret++; 307fcf3ce44SJohn Forte break; 308fcf3ce44SJohn Forte case STMF_ERROR_PERM: 309fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 310fcf3ce44SJohn Forte gettext("permission denied")); 3117b506e25Ssrivijitha dugganapalli ret++; 312fcf3ce44SJohn Forte break; 313fcf3ce44SJohn Forte case STMF_ERROR_BUSY: 314fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 315fcf3ce44SJohn Forte operands[i], gettext("resource busy")); 316fcf3ce44SJohn Forte ret++; 317fcf3ce44SJohn Forte break; 318fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_NOT_FOUND: 319fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 320fcf3ce44SJohn Forte gettext("STMF service not found")); 321fcf3ce44SJohn Forte ret++; 322fcf3ce44SJohn Forte break; 323fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_DATA_VERSION: 324fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 325fcf3ce44SJohn Forte gettext("STMF service version incorrect")); 326fcf3ce44SJohn Forte ret++; 327fcf3ce44SJohn Forte break; 328fcf3ce44SJohn Forte default: 329fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 330fcf3ce44SJohn Forte operands[i], gettext("unknown error")); 331fcf3ce44SJohn Forte ret++; 332fcf3ce44SJohn Forte break; 333fcf3ce44SJohn Forte } 334fcf3ce44SJohn Forte } 335fcf3ce44SJohn Forte 336fcf3ce44SJohn Forte return (ret); 337fcf3ce44SJohn Forte } 338fcf3ce44SJohn Forte 339fcf3ce44SJohn Forte /* 340fcf3ce44SJohn Forte * addTargetGroupMemberFunc 341fcf3ce44SJohn Forte * 342fcf3ce44SJohn Forte * Add members to a target group 343fcf3ce44SJohn Forte * 344fcf3ce44SJohn Forte */ 345fcf3ce44SJohn Forte /*ARGSUSED*/ 346fcf3ce44SJohn Forte static int 347fcf3ce44SJohn Forte addTargetGroupMemberFunc(int operandLen, char *operands[], 348fcf3ce44SJohn Forte cmdOptions_t *options, void *args) 349fcf3ce44SJohn Forte { 350fcf3ce44SJohn Forte int i; 351fcf3ce44SJohn Forte int ret = 0; 352fcf3ce44SJohn Forte int stmfRet; 3533e7352aeSJohn Forte stmfGroupName groupName = {0}; 3543e7352aeSJohn Forte wchar_t groupNamePrint[sizeof (stmfGroupName)] = {0}; 355fcf3ce44SJohn Forte stmfDevid devid; 356fcf3ce44SJohn Forte 357fcf3ce44SJohn Forte for (; options->optval; options++) { 358fcf3ce44SJohn Forte switch (options->optval) { 359fcf3ce44SJohn Forte /* target group name */ 360fcf3ce44SJohn Forte case 'g': 361fcf3ce44SJohn Forte (void) mbstowcs(groupNamePrint, options->optarg, 3623e7352aeSJohn Forte sizeof (stmfGroupName) - 1); 363fcf3ce44SJohn Forte bcopy(options->optarg, groupName, 364fcf3ce44SJohn Forte strlen(options->optarg)); 365fcf3ce44SJohn Forte break; 366fcf3ce44SJohn Forte default: 367fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %c: %s\n", 368fcf3ce44SJohn Forte cmdName, options->optval, 369fcf3ce44SJohn Forte gettext("unknown option")); 370fcf3ce44SJohn Forte return (1); 371fcf3ce44SJohn Forte } 372fcf3ce44SJohn Forte } 373fcf3ce44SJohn Forte 374fcf3ce44SJohn Forte for (i = 0; i < operandLen; i++) { 375fcf3ce44SJohn Forte if (parseDevid(operands[i], &devid) != 0) { 376fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", 377fcf3ce44SJohn Forte cmdName, operands[i], 378fcf3ce44SJohn Forte gettext("unrecognized device id")); 379fcf3ce44SJohn Forte ret++; 380fcf3ce44SJohn Forte continue; 381fcf3ce44SJohn Forte } 382fcf3ce44SJohn Forte stmfRet = stmfAddToTargetGroup(&groupName, &devid); 383fcf3ce44SJohn Forte switch (stmfRet) { 384fcf3ce44SJohn Forte case STMF_STATUS_SUCCESS: 385fcf3ce44SJohn Forte break; 386fcf3ce44SJohn Forte case STMF_ERROR_EXISTS: 387fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 388fcf3ce44SJohn Forte operands[i], gettext("already exists")); 389fcf3ce44SJohn Forte ret++; 390fcf3ce44SJohn Forte break; 391fcf3ce44SJohn Forte case STMF_ERROR_GROUP_NOT_FOUND: 392fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %ws: %s\n", cmdName, 393fcf3ce44SJohn Forte groupNamePrint, gettext("not found")); 394fcf3ce44SJohn Forte ret++; 395fcf3ce44SJohn Forte break; 396fcf3ce44SJohn Forte case STMF_ERROR_PERM: 397fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 398fcf3ce44SJohn Forte gettext("permission denied")); 3997b506e25Ssrivijitha dugganapalli ret++; 400fcf3ce44SJohn Forte break; 401fcf3ce44SJohn Forte case STMF_ERROR_BUSY: 402fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 403fcf3ce44SJohn Forte operands[i], gettext("resource busy")); 404fcf3ce44SJohn Forte ret++; 405fcf3ce44SJohn Forte break; 406fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_NOT_FOUND: 407fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 408fcf3ce44SJohn Forte gettext("STMF service not found")); 409fcf3ce44SJohn Forte ret++; 410fcf3ce44SJohn Forte break; 411fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_ONLINE: 412fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 413fcf3ce44SJohn Forte gettext("STMF service must be offline")); 414fcf3ce44SJohn Forte ret++; 415fcf3ce44SJohn Forte break; 416fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_DATA_VERSION: 417fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 418fcf3ce44SJohn Forte gettext("STMF service version incorrect")); 419fcf3ce44SJohn Forte ret++; 420fcf3ce44SJohn Forte break; 421f80ea9bbStim szeto case STMF_ERROR_TG_ONLINE: 422f80ea9bbStim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 423f80ea9bbStim szeto gettext("STMF target must be offline")); 424f80ea9bbStim szeto ret++; 425f80ea9bbStim szeto break; 426fcf3ce44SJohn Forte default: 427fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 428fcf3ce44SJohn Forte operands[i], gettext("unknown error")); 429fcf3ce44SJohn Forte ret++; 430fcf3ce44SJohn Forte break; 431fcf3ce44SJohn Forte } 432fcf3ce44SJohn Forte } 433fcf3ce44SJohn Forte 434fcf3ce44SJohn Forte return (ret); 435fcf3ce44SJohn Forte } 436fcf3ce44SJohn Forte 437fcf3ce44SJohn Forte /* 438fcf3ce44SJohn Forte * parseDevid 439fcf3ce44SJohn Forte * 440fcf3ce44SJohn Forte * Converts char * input to a stmfDevid 441fcf3ce44SJohn Forte * 442fcf3ce44SJohn Forte * input - this should be in the following format with either a 443fcf3ce44SJohn Forte * wwn. iqn. or eui. representation. 444fcf3ce44SJohn Forte * A name string of the format: 445fcf3ce44SJohn Forte * wwn.<WWN> (FC/SAS address) 446fcf3ce44SJohn Forte * iqn.<iSCSI name> (iSCSI iqn) 447fcf3ce44SJohn Forte * eui.<WWN> (iSCSI eui name) 448fcf3ce44SJohn Forte * 449fcf3ce44SJohn Forte * devid - pointer to stmfDevid structure allocated by the caller. 450fcf3ce44SJohn Forte * 451fcf3ce44SJohn Forte * Returns: 452fcf3ce44SJohn Forte * 0 on success 453fcf3ce44SJohn Forte * non-zero on failure 454fcf3ce44SJohn Forte */ 455fcf3ce44SJohn Forte static int 456fcf3ce44SJohn Forte parseDevid(char *input, stmfDevid *devid) 457fcf3ce44SJohn Forte { 4583e7352aeSJohn Forte wchar_t inputWc[MAX_DEVID_INPUT + 1] = {0}; 459fcf3ce44SJohn Forte 460fcf3ce44SJohn Forte /* convert to wcs */ 4613e7352aeSJohn Forte (void) mbstowcs(inputWc, input, MAX_DEVID_INPUT); 462fcf3ce44SJohn Forte 463fcf3ce44SJohn Forte /* 464fcf3ce44SJohn Forte * Check for known scsi name string formats 465fcf3ce44SJohn Forte * If one is found, we're done 466fcf3ce44SJohn Forte * If not, then it's a failure to parse 467fcf3ce44SJohn Forte */ 468fcf3ce44SJohn Forte if (checkScsiNameString(inputWc, devid) == 0) { 469fcf3ce44SJohn Forte return (0); 470fcf3ce44SJohn Forte } 471fcf3ce44SJohn Forte 472fcf3ce44SJohn Forte return (-1); 473fcf3ce44SJohn Forte } 474fcf3ce44SJohn Forte 475fcf3ce44SJohn Forte /* 476fcf3ce44SJohn Forte * checkScsiNameString 477fcf3ce44SJohn Forte * 478fcf3ce44SJohn Forte * Validates known SCSI name string formats and converts to stmfDevid 479fcf3ce44SJohn Forte * format 480fcf3ce44SJohn Forte * 481fcf3ce44SJohn Forte * input - input SCSI name string 482fcf3ce44SJohn Forte * devid - pointer to stmfDevid structure allocated by the caller 483fcf3ce44SJohn Forte * on successful return, contains the devid based on input 484fcf3ce44SJohn Forte * 485fcf3ce44SJohn Forte * returns: 486fcf3ce44SJohn Forte * 0 on success 487fcf3ce44SJohn Forte * -1 on failure 488fcf3ce44SJohn Forte */ 489fcf3ce44SJohn Forte static int 490fcf3ce44SJohn Forte checkScsiNameString(wchar_t *input, stmfDevid *devid) 491fcf3ce44SJohn Forte { 492fcf3ce44SJohn Forte char *mbString = NULL; 493fcf3ce44SJohn Forte int mbStringLen; 494fcf3ce44SJohn Forte int len; 495fcf3ce44SJohn Forte int i; 496fcf3ce44SJohn Forte 497fcf3ce44SJohn Forte /* 498fcf3ce44SJohn Forte * Convert to multi-byte string 499fcf3ce44SJohn Forte * 500fcf3ce44SJohn Forte * This is used for either eui or naa formats 501fcf3ce44SJohn Forte */ 502fcf3ce44SJohn Forte mbString = calloc(1, (mbStringLen = wcstombs(mbString, input, 0)) + 1); 503fcf3ce44SJohn Forte if (mbString == NULL) { 504fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", 505fcf3ce44SJohn Forte cmdName, "Insufficient memory\n"); 506fcf3ce44SJohn Forte return (-1); 507fcf3ce44SJohn Forte } 508fcf3ce44SJohn Forte if (wcstombs(mbString, input, mbStringLen) == (size_t)-1) { 509fcf3ce44SJohn Forte return (-1); 510fcf3ce44SJohn Forte } 511fcf3ce44SJohn Forte 512fcf3ce44SJohn Forte /* 513fcf3ce44SJohn Forte * check for iqn format 514fcf3ce44SJohn Forte */ 515fcf3ce44SJohn Forte if (strncmp(mbString, "iqn.", 4) == 0) { 516fcf3ce44SJohn Forte if ((len = strlen(mbString)) > (SNS_IQN_223)) { 517fcf3ce44SJohn Forte return (-1); 518fcf3ce44SJohn Forte } 519fcf3ce44SJohn Forte for (i = 0; i < len; i++) { 520fcf3ce44SJohn Forte mbString[i] = tolower(mbString[i]); 521fcf3ce44SJohn Forte } 522fcf3ce44SJohn Forte if (checkIscsiName(input + 4) != 0) { 523fcf3ce44SJohn Forte return (-1); 524fcf3ce44SJohn Forte } 525fcf3ce44SJohn Forte } else if (strncmp(mbString, "wwn.", 4) == 0) { 526fcf3ce44SJohn Forte if ((len = strlen(mbString + 4)) != SNS_WWN_16) { 527fcf3ce44SJohn Forte return (-1); 528fcf3ce44SJohn Forte } else if (checkHexUpper(mbString + 4) != 0) { 529fcf3ce44SJohn Forte return (-1); 530fcf3ce44SJohn Forte } 531fcf3ce44SJohn Forte } else if (strncmp(mbString, "eui.", 4) == 0) { 532fcf3ce44SJohn Forte if ((len = strlen(mbString + 4)) != SNS_EUI_16) { 533fcf3ce44SJohn Forte return (-1); 534fcf3ce44SJohn Forte } else if (checkHexUpper(mbString + 4) != 0) { 535fcf3ce44SJohn Forte return (-1); 536fcf3ce44SJohn Forte } 537fcf3ce44SJohn Forte } else { 538fcf3ce44SJohn Forte return (-1); 539fcf3ce44SJohn Forte } 540fcf3ce44SJohn Forte 541fcf3ce44SJohn Forte /* 542fcf3ce44SJohn Forte * We have a validated name string. 543fcf3ce44SJohn Forte * Go ahead and set the length and copy it. 544fcf3ce44SJohn Forte */ 545fcf3ce44SJohn Forte devid->identLength = strlen(mbString); 546fcf3ce44SJohn Forte bzero(devid->ident, STMF_IDENT_LENGTH); 547fcf3ce44SJohn Forte bcopy(mbString, devid->ident, devid->identLength); 548fcf3ce44SJohn Forte 549fcf3ce44SJohn Forte return (0); 550fcf3ce44SJohn Forte } 551fcf3ce44SJohn Forte 552fcf3ce44SJohn Forte 553fcf3ce44SJohn Forte /* 554fcf3ce44SJohn Forte * Checks whether the entire string is in hex and converts to upper 555fcf3ce44SJohn Forte */ 556fcf3ce44SJohn Forte static int 557fcf3ce44SJohn Forte checkHexUpper(char *input) 558fcf3ce44SJohn Forte { 559fcf3ce44SJohn Forte int i; 560fcf3ce44SJohn Forte 561fcf3ce44SJohn Forte for (i = 0; i < strlen(input); i++) { 562fcf3ce44SJohn Forte if (isxdigit(input[i])) { 563fcf3ce44SJohn Forte input[i] = toupper(input[i]); 564fcf3ce44SJohn Forte continue; 565fcf3ce44SJohn Forte } 566fcf3ce44SJohn Forte return (-1); 567fcf3ce44SJohn Forte } 568fcf3ce44SJohn Forte 569fcf3ce44SJohn Forte return (0); 570fcf3ce44SJohn Forte } 571fcf3ce44SJohn Forte 572fcf3ce44SJohn Forte /* 573fcf3ce44SJohn Forte * checkIscsiName 574fcf3ce44SJohn Forte * 575fcf3ce44SJohn Forte * Purpose: Basic string checking on name 576fcf3ce44SJohn Forte */ 577fcf3ce44SJohn Forte static int 578fcf3ce44SJohn Forte checkIscsiName(wchar_t *input) 579fcf3ce44SJohn Forte { 580fcf3ce44SJohn Forte int i; 581fcf3ce44SJohn Forte 582fcf3ce44SJohn Forte for (i = 0; input[i] != 0; i++) { 583fcf3ce44SJohn Forte if (!iswalnum(input[i]) && input[i] != '-' && 584fcf3ce44SJohn Forte input[i] != '.' && input[i] != ':') { 585fcf3ce44SJohn Forte return (-1); 586fcf3ce44SJohn Forte } 587fcf3ce44SJohn Forte } 588fcf3ce44SJohn Forte 589fcf3ce44SJohn Forte return (0); 590fcf3ce44SJohn Forte } 591fcf3ce44SJohn Forte 592fcf3ce44SJohn Forte 593fcf3ce44SJohn Forte /* 594fcf3ce44SJohn Forte * addViewFunc 595fcf3ce44SJohn Forte * 596fcf3ce44SJohn Forte * Adds a view entry to a logical unit 597fcf3ce44SJohn Forte * 598fcf3ce44SJohn Forte */ 599fcf3ce44SJohn Forte /*ARGSUSED*/ 600fcf3ce44SJohn Forte static int 601fcf3ce44SJohn Forte addViewFunc(int operandLen, char *operands[], cmdOptions_t *options, 602fcf3ce44SJohn Forte void *args) 603fcf3ce44SJohn Forte { 604fcf3ce44SJohn Forte stmfViewEntry viewEntry; 605fcf3ce44SJohn Forte stmfGuid inGuid; 606fcf3ce44SJohn Forte unsigned int guid[sizeof (stmfGuid)]; 607fcf3ce44SJohn Forte uint16_t inputLuNbr; 608fcf3ce44SJohn Forte int ret = 0; 609fcf3ce44SJohn Forte int stmfRet; 610fcf3ce44SJohn Forte int i; 611fcf3ce44SJohn Forte char sGuid[GUID_INPUT + 1]; 612fcf3ce44SJohn Forte 613fcf3ce44SJohn Forte bzero(&viewEntry, sizeof (viewEntry)); 614fcf3ce44SJohn Forte /* init view entry structure */ 615fcf3ce44SJohn Forte viewEntry.allHosts = B_TRUE; 616fcf3ce44SJohn Forte viewEntry.allTargets = B_TRUE; 617fcf3ce44SJohn Forte viewEntry.luNbrValid = B_FALSE; 618fcf3ce44SJohn Forte 619fcf3ce44SJohn Forte /* check input length */ 620fcf3ce44SJohn Forte if (strlen(operands[0]) != GUID_INPUT) { 621fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s%d%s\n", cmdName, operands[0], 622fcf3ce44SJohn Forte gettext("must be "), GUID_INPUT, 623fcf3ce44SJohn Forte gettext(" hexadecimal digits")); 624fcf3ce44SJohn Forte return (1); 625fcf3ce44SJohn Forte } 626fcf3ce44SJohn Forte 627fcf3ce44SJohn Forte for (; options->optval; options++) { 628fcf3ce44SJohn Forte switch (options->optval) { 629fcf3ce44SJohn Forte /* logical unit number */ 630fcf3ce44SJohn Forte case 'n': 631fcf3ce44SJohn Forte viewEntry.luNbrValid = B_TRUE; 632fcf3ce44SJohn Forte inputLuNbr = atoi(options->optarg); 633fcf3ce44SJohn Forte if (inputLuNbr > MAX_LU_NBR) { 634fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %d: %s\n", 635fcf3ce44SJohn Forte cmdName, inputLuNbr, 636fcf3ce44SJohn Forte gettext("Logical unit number" 637fcf3ce44SJohn Forte " must be less than 16384")); 638fcf3ce44SJohn Forte return (1); 639fcf3ce44SJohn Forte } 640fcf3ce44SJohn Forte viewEntry.luNbr[0] = inputLuNbr >> 8; 641fcf3ce44SJohn Forte viewEntry.luNbr[1] = inputLuNbr & 0xff; 642fcf3ce44SJohn Forte break; 643fcf3ce44SJohn Forte /* host group */ 644fcf3ce44SJohn Forte case 'h': 645fcf3ce44SJohn Forte viewEntry.allHosts = B_FALSE; 646fcf3ce44SJohn Forte bcopy(options->optarg, viewEntry.hostGroup, 647fcf3ce44SJohn Forte strlen(options->optarg)); 648fcf3ce44SJohn Forte break; 649fcf3ce44SJohn Forte /* target group */ 650fcf3ce44SJohn Forte case 't': 651fcf3ce44SJohn Forte viewEntry.allTargets = B_FALSE; 652fcf3ce44SJohn Forte bcopy(options->optarg, viewEntry.targetGroup, 653fcf3ce44SJohn Forte strlen(options->optarg)); 654fcf3ce44SJohn Forte break; 655fcf3ce44SJohn Forte default: 656fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %c: %s\n", 657fcf3ce44SJohn Forte cmdName, options->optval, 658fcf3ce44SJohn Forte gettext("unknown option")); 659fcf3ce44SJohn Forte return (1); 660fcf3ce44SJohn Forte } 661fcf3ce44SJohn Forte } 662fcf3ce44SJohn Forte 663fcf3ce44SJohn Forte /* convert to lower case for scan */ 664fcf3ce44SJohn Forte for (i = 0; i < 32; i++) 665fcf3ce44SJohn Forte sGuid[i] = tolower(operands[0][i]); 666fcf3ce44SJohn Forte sGuid[i] = 0; 667fcf3ce44SJohn Forte 668fcf3ce44SJohn Forte (void) sscanf(sGuid, "%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x", 669fcf3ce44SJohn Forte &guid[0], &guid[1], &guid[2], &guid[3], &guid[4], &guid[5], 670fcf3ce44SJohn Forte &guid[6], &guid[7], &guid[8], &guid[9], &guid[10], &guid[11], 671fcf3ce44SJohn Forte &guid[12], &guid[13], &guid[14], &guid[15]); 672fcf3ce44SJohn Forte 673fcf3ce44SJohn Forte for (i = 0; i < sizeof (stmfGuid); i++) { 674fcf3ce44SJohn Forte inGuid.guid[i] = guid[i]; 675fcf3ce44SJohn Forte } 676fcf3ce44SJohn Forte 677fcf3ce44SJohn Forte /* add the view entry */ 678fcf3ce44SJohn Forte stmfRet = stmfAddViewEntry(&inGuid, &viewEntry); 679fcf3ce44SJohn Forte switch (stmfRet) { 680fcf3ce44SJohn Forte case STMF_STATUS_SUCCESS: 681fcf3ce44SJohn Forte break; 682fcf3ce44SJohn Forte case STMF_ERROR_EXISTS: 683fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 684fcf3ce44SJohn Forte operands[0], gettext("already exists")); 685fcf3ce44SJohn Forte ret++; 686fcf3ce44SJohn Forte break; 687fcf3ce44SJohn Forte case STMF_ERROR_BUSY: 688fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 689fcf3ce44SJohn Forte operands[0], gettext("resource busy")); 690fcf3ce44SJohn Forte ret++; 691fcf3ce44SJohn Forte break; 692fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_NOT_FOUND: 693fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 694fcf3ce44SJohn Forte gettext("STMF service not found")); 695fcf3ce44SJohn Forte ret++; 696fcf3ce44SJohn Forte break; 697fcf3ce44SJohn Forte case STMF_ERROR_PERM: 698fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 699fcf3ce44SJohn Forte gettext("permission denied")); 700fcf3ce44SJohn Forte ret++; 701fcf3ce44SJohn Forte break; 702fcf3ce44SJohn Forte case STMF_ERROR_LUN_IN_USE: 703fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 704fcf3ce44SJohn Forte gettext("LUN already in use")); 705fcf3ce44SJohn Forte ret++; 706fcf3ce44SJohn Forte break; 707fcf3ce44SJohn Forte case STMF_ERROR_VE_CONFLICT: 708fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 709fcf3ce44SJohn Forte gettext("view entry exists")); 710fcf3ce44SJohn Forte ret++; 711fcf3ce44SJohn Forte break; 712fcf3ce44SJohn Forte case STMF_ERROR_CONFIG_NONE: 713fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 714fcf3ce44SJohn Forte gettext("STMF service is not initialized")); 715fcf3ce44SJohn Forte ret++; 716fcf3ce44SJohn Forte break; 717fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_DATA_VERSION: 718fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 719fcf3ce44SJohn Forte gettext("STMF service version incorrect")); 720fcf3ce44SJohn Forte ret++; 721fcf3ce44SJohn Forte break; 722fcf3ce44SJohn Forte case STMF_ERROR_INVALID_HG: 723fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 724fcf3ce44SJohn Forte gettext("invalid host group")); 725fcf3ce44SJohn Forte ret++; 726fcf3ce44SJohn Forte break; 727fcf3ce44SJohn Forte case STMF_ERROR_INVALID_TG: 728fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 729fcf3ce44SJohn Forte gettext("invalid target group")); 730fcf3ce44SJohn Forte ret++; 731fcf3ce44SJohn Forte break; 732fcf3ce44SJohn Forte default: 733fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 734fcf3ce44SJohn Forte operands[0], gettext("unknown error")); 735fcf3ce44SJohn Forte ret++; 736fcf3ce44SJohn Forte break; 737fcf3ce44SJohn Forte } 738fcf3ce44SJohn Forte 739fcf3ce44SJohn Forte return (ret); 740fcf3ce44SJohn Forte } 741fcf3ce44SJohn Forte 742fcf3ce44SJohn Forte /* 743fcf3ce44SJohn Forte * createHostGroupFunc 744fcf3ce44SJohn Forte * 745fcf3ce44SJohn Forte * Create a host group 746fcf3ce44SJohn Forte * 747fcf3ce44SJohn Forte */ 748fcf3ce44SJohn Forte /*ARGSUSED*/ 749fcf3ce44SJohn Forte static int 750fcf3ce44SJohn Forte createHostGroupFunc(int operandLen, char *operands[], 751fcf3ce44SJohn Forte cmdOptions_t *options, void *args) 752fcf3ce44SJohn Forte { 753fcf3ce44SJohn Forte int ret = 0; 754fcf3ce44SJohn Forte int stmfRet; 7553e7352aeSJohn Forte wchar_t groupNamePrint[sizeof (stmfGroupName)] = {0}; 7563e7352aeSJohn Forte stmfGroupName groupName = {0}; 757fcf3ce44SJohn Forte 758fcf3ce44SJohn Forte (void) strlcpy(groupName, operands[0], sizeof (groupName)); 759fcf3ce44SJohn Forte (void) mbstowcs(groupNamePrint, (char *)groupName, 7603e7352aeSJohn Forte sizeof (stmfGroupName) - 1); 761fcf3ce44SJohn Forte /* call create group */ 762fcf3ce44SJohn Forte stmfRet = stmfCreateHostGroup(&groupName); 763fcf3ce44SJohn Forte switch (stmfRet) { 764fcf3ce44SJohn Forte case STMF_STATUS_SUCCESS: 765fcf3ce44SJohn Forte break; 766fcf3ce44SJohn Forte case STMF_ERROR_EXISTS: 767fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 768fcf3ce44SJohn Forte operands[0], gettext("already exists")); 769fcf3ce44SJohn Forte ret++; 770fcf3ce44SJohn Forte break; 771fcf3ce44SJohn Forte case STMF_ERROR_BUSY: 772fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %ws: %s\n", cmdName, 773fcf3ce44SJohn Forte operands[0], gettext("resource busy")); 774fcf3ce44SJohn Forte ret++; 775fcf3ce44SJohn Forte break; 776fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_NOT_FOUND: 777fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 778fcf3ce44SJohn Forte gettext("STMF service not found")); 779fcf3ce44SJohn Forte ret++; 780fcf3ce44SJohn Forte break; 781fcf3ce44SJohn Forte case STMF_ERROR_PERM: 782fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 783fcf3ce44SJohn Forte gettext("permission denied")); 784fcf3ce44SJohn Forte ret++; 785fcf3ce44SJohn Forte break; 786fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_DATA_VERSION: 787fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 788fcf3ce44SJohn Forte gettext("STMF service version incorrect")); 789fcf3ce44SJohn Forte ret++; 790fcf3ce44SJohn Forte break; 791fcf3ce44SJohn Forte default: 792fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 793fcf3ce44SJohn Forte operands[0], gettext("unknown error")); 794fcf3ce44SJohn Forte ret++; 795fcf3ce44SJohn Forte break; 796fcf3ce44SJohn Forte } 797fcf3ce44SJohn Forte 798fcf3ce44SJohn Forte return (ret); 799fcf3ce44SJohn Forte } 800fcf3ce44SJohn Forte 801fcf3ce44SJohn Forte /* 8028fe96085Stim szeto * createLuFunc 8038fe96085Stim szeto * 8048fe96085Stim szeto * Create a logical unit 8058fe96085Stim szeto * 8068fe96085Stim szeto */ 8078fe96085Stim szeto /*ARGSUSED*/ 8088fe96085Stim szeto static int 8098fe96085Stim szeto createLuFunc(int operandLen, char *operands[], cmdOptions_t *options, 8108fe96085Stim szeto void *args) 8118fe96085Stim szeto { 8128fe96085Stim szeto luResource hdl = NULL; 8138fe96085Stim szeto int ret = 0; 8148fe96085Stim szeto int stmfRet = 0; 8158fe96085Stim szeto char guidAsciiBuf[33]; 8168fe96085Stim szeto stmfGuid createdGuid; 8178fe96085Stim szeto 8188fe96085Stim szeto stmfRet = stmfCreateLuResource(STMF_DISK, &hdl); 8198fe96085Stim szeto 8208fe96085Stim szeto if (stmfRet != STMF_STATUS_SUCCESS) { 8218fe96085Stim szeto (void) fprintf(stderr, "%s: %s\n", 8228fe96085Stim szeto cmdName, gettext("Failure to create lu resource\n")); 8238fe96085Stim szeto return (1); 8248fe96085Stim szeto } 8258fe96085Stim szeto 8268fe96085Stim szeto for (; options->optval; options++) { 8278fe96085Stim szeto switch (options->optval) { 8288fe96085Stim szeto case 'p': 8298fe96085Stim szeto ret = setLuPropFromInput(hdl, options->optarg); 8308fe96085Stim szeto if (ret != 0) { 8318fe96085Stim szeto (void) stmfFreeLuResource(hdl); 8328fe96085Stim szeto return (1); 8338fe96085Stim szeto } 8348fe96085Stim szeto break; 8358fe96085Stim szeto case 's': 8368fe96085Stim szeto stmfRet = stmfSetLuProp(hdl, STMF_LU_PROP_SIZE, 8378fe96085Stim szeto options->optarg); 8388fe96085Stim szeto if (stmfRet != STMF_STATUS_SUCCESS) { 8398fe96085Stim szeto (void) fprintf(stderr, "%s: %c: %s\n", 8408fe96085Stim szeto cmdName, options->optval, 8418fe96085Stim szeto gettext("size param invalid")); 8428fe96085Stim szeto (void) stmfFreeLuResource(hdl); 8438fe96085Stim szeto return (1); 8448fe96085Stim szeto } 8458fe96085Stim szeto break; 8468fe96085Stim szeto default: 8478fe96085Stim szeto (void) fprintf(stderr, "%s: %c: %s\n", 8488fe96085Stim szeto cmdName, options->optval, 8498fe96085Stim szeto gettext("unknown option")); 8508fe96085Stim szeto return (1); 8518fe96085Stim szeto } 8528fe96085Stim szeto } 8538fe96085Stim szeto 8548fe96085Stim szeto stmfRet = stmfSetLuProp(hdl, STMF_LU_PROP_FILENAME, operands[0]); 8558fe96085Stim szeto 8568fe96085Stim szeto if (stmfRet != STMF_STATUS_SUCCESS) { 8578fe96085Stim szeto (void) fprintf(stderr, "%s: %s\n", 8588fe96085Stim szeto cmdName, gettext("could not set filename")); 8598fe96085Stim szeto return (1); 8608fe96085Stim szeto } 8618fe96085Stim szeto 8628fe96085Stim szeto stmfRet = stmfCreateLu(hdl, &createdGuid); 8638fe96085Stim szeto switch (stmfRet) { 8648fe96085Stim szeto case STMF_STATUS_SUCCESS: 8658fe96085Stim szeto break; 8668fe96085Stim szeto case STMF_ERROR_BUSY: 8678fe96085Stim szeto case STMF_ERROR_LU_BUSY: 8688fe96085Stim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 8698fe96085Stim szeto gettext("resource busy")); 8708fe96085Stim szeto ret++; 8718fe96085Stim szeto break; 8728fe96085Stim szeto case STMF_ERROR_PERM: 8738fe96085Stim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 8748fe96085Stim szeto gettext("permission denied")); 8758fe96085Stim szeto ret++; 8768fe96085Stim szeto break; 8778fe96085Stim szeto case STMF_ERROR_FILE_IN_USE: 8788fe96085Stim szeto (void) fprintf(stderr, "%s: filename %s: %s\n", cmdName, 8798fe96085Stim szeto operands[0], gettext("in use")); 8808fe96085Stim szeto ret++; 8818fe96085Stim szeto break; 8828fe96085Stim szeto case STMF_ERROR_INVALID_BLKSIZE: 8838fe96085Stim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 8848fe96085Stim szeto gettext("invalid block size")); 8858fe96085Stim szeto ret++; 8868fe96085Stim szeto break; 8878fe96085Stim szeto case STMF_ERROR_GUID_IN_USE: 8888fe96085Stim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 8898fe96085Stim szeto gettext("guid in use")); 8908fe96085Stim szeto ret++; 8918fe96085Stim szeto break; 8928fe96085Stim szeto case STMF_ERROR_META_FILE_NAME: 8938fe96085Stim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 8948fe96085Stim szeto gettext("meta file error")); 8958fe96085Stim szeto ret++; 8968fe96085Stim szeto break; 8978fe96085Stim szeto case STMF_ERROR_DATA_FILE_NAME: 8988fe96085Stim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 8998fe96085Stim szeto gettext("data file error")); 9008fe96085Stim szeto ret++; 9018fe96085Stim szeto break; 9028fe96085Stim szeto case STMF_ERROR_FILE_SIZE_INVALID: 9038fe96085Stim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 9048fe96085Stim szeto gettext("file size invalid")); 9058fe96085Stim szeto ret++; 9068fe96085Stim szeto break; 9078fe96085Stim szeto case STMF_ERROR_SIZE_OUT_OF_RANGE: 9088fe96085Stim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 9098fe96085Stim szeto gettext("invalid size")); 9108fe96085Stim szeto ret++; 9118fe96085Stim szeto break; 9128fe96085Stim szeto case STMF_ERROR_META_CREATION: 9138fe96085Stim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 9148fe96085Stim szeto gettext("could not create meta file")); 9158fe96085Stim szeto ret++; 9168fe96085Stim szeto break; 9178fe96085Stim szeto case STMF_ERROR_WRITE_CACHE_SET: 9188fe96085Stim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 9198fe96085Stim szeto gettext("could not set write cache")); 9208fe96085Stim szeto ret++; 9218fe96085Stim szeto break; 9228fe96085Stim szeto default: 9238fe96085Stim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 9248fe96085Stim szeto gettext("unknown error")); 9258fe96085Stim szeto ret++; 9268fe96085Stim szeto break; 9278fe96085Stim szeto } 9288fe96085Stim szeto 9298fe96085Stim szeto if (ret != 0) { 9308fe96085Stim szeto goto done; 9318fe96085Stim szeto } 9328fe96085Stim szeto 9338fe96085Stim szeto (void) snprintf(guidAsciiBuf, sizeof (guidAsciiBuf), 9348fe96085Stim szeto "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X" 9358fe96085Stim szeto "%02X%02X%02X%02X%02X%02X", 9368fe96085Stim szeto createdGuid.guid[0], createdGuid.guid[1], createdGuid.guid[2], 9378fe96085Stim szeto createdGuid.guid[3], createdGuid.guid[4], createdGuid.guid[5], 9388fe96085Stim szeto createdGuid.guid[6], createdGuid.guid[7], createdGuid.guid[8], 9398fe96085Stim szeto createdGuid.guid[9], createdGuid.guid[10], createdGuid.guid[11], 9408fe96085Stim szeto createdGuid.guid[12], createdGuid.guid[13], createdGuid.guid[14], 9418fe96085Stim szeto createdGuid.guid[15]); 9428fe96085Stim szeto (void) printf("Logical unit created: %s\n", guidAsciiBuf); 9438fe96085Stim szeto 9448fe96085Stim szeto done: 9458fe96085Stim szeto (void) stmfFreeLuResource(hdl); 9468fe96085Stim szeto return (ret); 9478fe96085Stim szeto } 9488fe96085Stim szeto 9498fe96085Stim szeto /* 9508fe96085Stim szeto * createLuFunc 9518fe96085Stim szeto * 9528fe96085Stim szeto * Create a logical unit 9538fe96085Stim szeto * 9548fe96085Stim szeto */ 9558fe96085Stim szeto /*ARGSUSED*/ 9568fe96085Stim szeto static int 9578fe96085Stim szeto modifyLuFunc(int operandLen, char *operands[], cmdOptions_t *options, 9588fe96085Stim szeto void *args) 9598fe96085Stim szeto { 9608fe96085Stim szeto stmfGuid inGuid; 9618fe96085Stim szeto unsigned int guid[sizeof (stmfGuid)]; 9628fe96085Stim szeto int ret = 0; 9638fe96085Stim szeto int i; 9648fe96085Stim szeto char *fname = NULL; 9658fe96085Stim szeto char *lasts = NULL; 9668fe96085Stim szeto char sGuid[GUID_INPUT + 1]; 9678fe96085Stim szeto char *prop = NULL; 9688fe96085Stim szeto char *propVal = NULL; 9698fe96085Stim szeto boolean_t fnameUsed = B_FALSE; 9708fe96085Stim szeto uint32_t propId; 9718fe96085Stim szeto cmdOptions_t *optionStart = options; 9728fe96085Stim szeto 9738fe96085Stim szeto 9748fe96085Stim szeto for (; options->optval; options++) { 9758fe96085Stim szeto switch (options->optval) { 9768fe96085Stim szeto case 'f': 9778fe96085Stim szeto fnameUsed = B_TRUE; 9788fe96085Stim szeto fname = operands[0]; 9798fe96085Stim szeto break; 9808fe96085Stim szeto } 9818fe96085Stim szeto } 9828fe96085Stim szeto options = optionStart; 9838fe96085Stim szeto 9848fe96085Stim szeto /* check input length */ 9858fe96085Stim szeto if (!fnameUsed && strlen(operands[0]) != GUID_INPUT) { 9868fe96085Stim szeto (void) fprintf(stderr, "%s: %s: %s%d%s\n", cmdName, operands[0], 9878fe96085Stim szeto gettext("must be "), GUID_INPUT, 9888fe96085Stim szeto gettext(" hexadecimal digits")); 9898fe96085Stim szeto return (1); 9908fe96085Stim szeto } 9918fe96085Stim szeto 9928fe96085Stim szeto if (!fnameUsed) { 9938fe96085Stim szeto /* convert to lower case for scan */ 9948fe96085Stim szeto for (i = 0; i < 32; i++) 9958fe96085Stim szeto sGuid[i] = tolower(operands[0][i]); 9968fe96085Stim szeto sGuid[i] = 0; 9978fe96085Stim szeto (void) sscanf(sGuid, 9988fe96085Stim szeto "%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x", 9998fe96085Stim szeto &guid[0], &guid[1], &guid[2], &guid[3], &guid[4], &guid[5], 10008fe96085Stim szeto &guid[6], &guid[7], &guid[8], &guid[9], &guid[10], 10018fe96085Stim szeto &guid[11], &guid[12], &guid[13], &guid[14], &guid[15]); 10028fe96085Stim szeto 10038fe96085Stim szeto for (i = 0; i < sizeof (stmfGuid); i++) { 10048fe96085Stim szeto inGuid.guid[i] = guid[i]; 10058fe96085Stim szeto } 10068fe96085Stim szeto } 10078fe96085Stim szeto 10088fe96085Stim szeto for (; options->optval; options++) { 10098fe96085Stim szeto switch (options->optval) { 10108fe96085Stim szeto case 'p': 10118fe96085Stim szeto prop = strtok_r(options->optarg, "=", &lasts); 10122f624233SNattuvetty Bhavyan propVal = strtok_r(NULL, "=", &lasts); 10138fe96085Stim szeto ret = convertCharToPropId(prop, &propId); 10148fe96085Stim szeto if (ret != 0) { 10158fe96085Stim szeto (void) fprintf(stderr, "%s: %s: %s\n", 10168fe96085Stim szeto cmdName, 10178fe96085Stim szeto gettext("invalid property specified"), 10188fe96085Stim szeto prop); 10198fe96085Stim szeto return (1); 10208fe96085Stim szeto } 10212f624233SNattuvetty Bhavyan if (propVal == NULL && 10222f624233SNattuvetty Bhavyan propId != STMF_LU_PROP_MGMT_URL) { 10232f624233SNattuvetty Bhavyan (void) fprintf(stderr, "%s: %s: %s\n", 10242f624233SNattuvetty Bhavyan cmdName, options->optarg, 10252f624233SNattuvetty Bhavyan gettext("invalid property specifier" 10262f624233SNattuvetty Bhavyan "- prop=val\n")); 10272f624233SNattuvetty Bhavyan return (1); 10282f624233SNattuvetty Bhavyan } 10292f624233SNattuvetty Bhavyan if (propVal == NULL) { 10302f624233SNattuvetty Bhavyan ret = callModify(fname, &inGuid, propId, 10312f624233SNattuvetty Bhavyan "", prop); 10322f624233SNattuvetty Bhavyan } else { 10332f624233SNattuvetty Bhavyan ret = callModify(fname, &inGuid, propId, 10342f624233SNattuvetty Bhavyan propVal, prop); 10352f624233SNattuvetty Bhavyan } 10362f624233SNattuvetty Bhavyan if (ret != 0) { 10378fe96085Stim szeto return (1); 10388fe96085Stim szeto } 10398fe96085Stim szeto break; 10408fe96085Stim szeto case 's': 10418fe96085Stim szeto if (callModify(fname, &inGuid, 10428fe96085Stim szeto STMF_LU_PROP_SIZE, options->optarg, 10438fe96085Stim szeto "size") != 0) { 10448fe96085Stim szeto return (1); 10458fe96085Stim szeto } 10468fe96085Stim szeto break; 10478fe96085Stim szeto case 'f': 10488fe96085Stim szeto break; 10498fe96085Stim szeto default: 10508fe96085Stim szeto (void) fprintf(stderr, "%s: %c: %s\n", 10518fe96085Stim szeto cmdName, options->optval, 10528fe96085Stim szeto gettext("unknown option")); 10538fe96085Stim szeto return (1); 10548fe96085Stim szeto } 10558fe96085Stim szeto } 10568fe96085Stim szeto return (ret); 10578fe96085Stim szeto } 10588fe96085Stim szeto 10598fe96085Stim szeto static int 10608fe96085Stim szeto callModify(char *fname, stmfGuid *luGuid, uint32_t prop, const char *propVal, 10618fe96085Stim szeto const char *propString) 10628fe96085Stim szeto { 10638fe96085Stim szeto int ret = 0; 10648fe96085Stim szeto int stmfRet = 0; 10658fe96085Stim szeto 10668fe96085Stim szeto if (!fname) { 10678fe96085Stim szeto stmfRet = stmfModifyLu(luGuid, prop, propVal); 10688fe96085Stim szeto } else { 10698fe96085Stim szeto stmfRet = stmfModifyLuByFname(STMF_DISK, fname, prop, 10708fe96085Stim szeto propVal); 10718fe96085Stim szeto } 10728fe96085Stim szeto switch (stmfRet) { 10738fe96085Stim szeto case STMF_STATUS_SUCCESS: 10748fe96085Stim szeto break; 10758fe96085Stim szeto case STMF_ERROR_BUSY: 10768fe96085Stim szeto case STMF_ERROR_LU_BUSY: 10778fe96085Stim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 10788fe96085Stim szeto gettext("resource busy")); 10798fe96085Stim szeto ret++; 10808fe96085Stim szeto break; 10818fe96085Stim szeto case STMF_ERROR_PERM: 10828fe96085Stim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 10838fe96085Stim szeto gettext("permission denied")); 10848fe96085Stim szeto ret++; 10858fe96085Stim szeto break; 10868fe96085Stim szeto case STMF_ERROR_INVALID_BLKSIZE: 10878fe96085Stim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 10888fe96085Stim szeto gettext("invalid block size")); 10898fe96085Stim szeto ret++; 10908fe96085Stim szeto break; 10918fe96085Stim szeto case STMF_ERROR_GUID_IN_USE: 10928fe96085Stim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 10938fe96085Stim szeto gettext("guid in use")); 10948fe96085Stim szeto ret++; 10958fe96085Stim szeto break; 10968fe96085Stim szeto case STMF_ERROR_META_FILE_NAME: 10978fe96085Stim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 10988fe96085Stim szeto gettext("meta file error")); 10998fe96085Stim szeto ret++; 11008fe96085Stim szeto break; 11018fe96085Stim szeto case STMF_ERROR_DATA_FILE_NAME: 11028fe96085Stim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 11038fe96085Stim szeto gettext("data file error")); 11048fe96085Stim szeto ret++; 11058fe96085Stim szeto break; 11068fe96085Stim szeto case STMF_ERROR_FILE_SIZE_INVALID: 11078fe96085Stim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 11088fe96085Stim szeto gettext("file size invalid")); 11098fe96085Stim szeto ret++; 11108fe96085Stim szeto break; 11118fe96085Stim szeto case STMF_ERROR_SIZE_OUT_OF_RANGE: 11128fe96085Stim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 11138fe96085Stim szeto gettext("invalid size")); 11148fe96085Stim szeto ret++; 11158fe96085Stim szeto break; 11168fe96085Stim szeto case STMF_ERROR_META_CREATION: 11178fe96085Stim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 11188fe96085Stim szeto gettext("could not create meta file")); 11198fe96085Stim szeto ret++; 11208fe96085Stim szeto break; 11218fe96085Stim szeto case STMF_ERROR_INVALID_PROP: 11228fe96085Stim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 11238fe96085Stim szeto gettext("invalid property for modify")); 11248fe96085Stim szeto ret++; 11258fe96085Stim szeto break; 11268fe96085Stim szeto case STMF_ERROR_WRITE_CACHE_SET: 11278fe96085Stim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 11288fe96085Stim szeto gettext("could not set write cache")); 11298fe96085Stim szeto ret++; 11308fe96085Stim szeto break; 113145039663SJohn Forte case STMF_ERROR_ACCESS_STATE_SET: 113245039663SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 113345039663SJohn Forte gettext("cannot modify while in standby mode")); 113445039663SJohn Forte ret++; 113545039663SJohn Forte break; 11368fe96085Stim szeto default: 11378fe96085Stim szeto (void) fprintf(stderr, "%s: %s: %s: %d\n", cmdName, 11388fe96085Stim szeto gettext("could not set property"), propString, 11398fe96085Stim szeto stmfRet); 11408fe96085Stim szeto ret++; 11418fe96085Stim szeto break; 11428fe96085Stim szeto } 11438fe96085Stim szeto 11448fe96085Stim szeto return (ret); 11458fe96085Stim szeto } 11468fe96085Stim szeto 11478fe96085Stim szeto 11488fe96085Stim szeto /* 11498fe96085Stim szeto * importLuFunc 11508fe96085Stim szeto * 11518fe96085Stim szeto * Create a logical unit 11528fe96085Stim szeto * 11538fe96085Stim szeto */ 11548fe96085Stim szeto /*ARGSUSED*/ 11558fe96085Stim szeto static int 11568fe96085Stim szeto importLuFunc(int operandLen, char *operands[], cmdOptions_t *options, 11578fe96085Stim szeto void *args) 11588fe96085Stim szeto { 11598fe96085Stim szeto int stmfRet = 0; 11608fe96085Stim szeto int ret = 0; 11618fe96085Stim szeto char guidAsciiBuf[33]; 11628fe96085Stim szeto stmfGuid createdGuid; 11638fe96085Stim szeto 11648fe96085Stim szeto stmfRet = stmfImportLu(STMF_DISK, operands[0], &createdGuid); 11658fe96085Stim szeto switch (stmfRet) { 11668fe96085Stim szeto case STMF_STATUS_SUCCESS: 11678fe96085Stim szeto break; 11688fe96085Stim szeto case STMF_ERROR_BUSY: 11698fe96085Stim szeto case STMF_ERROR_LU_BUSY: 11708fe96085Stim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 11718fe96085Stim szeto gettext("resource busy")); 11728fe96085Stim szeto ret++; 11738fe96085Stim szeto break; 11748fe96085Stim szeto case STMF_ERROR_PERM: 11758fe96085Stim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 11768fe96085Stim szeto gettext("permission denied")); 11778fe96085Stim szeto ret++; 11788fe96085Stim szeto break; 11798fe96085Stim szeto case STMF_ERROR_FILE_IN_USE: 11808fe96085Stim szeto (void) fprintf(stderr, "%s: filename %s: %s\n", cmdName, 11818fe96085Stim szeto operands[0], gettext("in use")); 11828fe96085Stim szeto ret++; 11838fe96085Stim szeto break; 11848fe96085Stim szeto case STMF_ERROR_GUID_IN_USE: 11858fe96085Stim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 11868fe96085Stim szeto gettext("guid in use")); 11878fe96085Stim szeto ret++; 11888fe96085Stim szeto break; 11898fe96085Stim szeto case STMF_ERROR_META_FILE_NAME: 11908fe96085Stim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 11918fe96085Stim szeto gettext("meta file error")); 11928fe96085Stim szeto ret++; 11938fe96085Stim szeto break; 11948fe96085Stim szeto case STMF_ERROR_DATA_FILE_NAME: 11958fe96085Stim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 11968fe96085Stim szeto gettext("data file error")); 11978fe96085Stim szeto ret++; 11988fe96085Stim szeto break; 11998fe96085Stim szeto case STMF_ERROR_META_CREATION: 12008fe96085Stim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 12018fe96085Stim szeto gettext("could not create meta file")); 12028fe96085Stim szeto ret++; 12038fe96085Stim szeto break; 12048fe96085Stim szeto case STMF_ERROR_WRITE_CACHE_SET: 12058fe96085Stim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 12068fe96085Stim szeto gettext("could not set write cache")); 12078fe96085Stim szeto ret++; 12088fe96085Stim szeto break; 12098fe96085Stim szeto default: 12108fe96085Stim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 12118fe96085Stim szeto gettext("unknown error")); 12128fe96085Stim szeto ret++; 12138fe96085Stim szeto break; 12148fe96085Stim szeto } 12158fe96085Stim szeto 12168fe96085Stim szeto if (ret != STMF_STATUS_SUCCESS) { 12178fe96085Stim szeto goto done; 12188fe96085Stim szeto } 12198fe96085Stim szeto 12208fe96085Stim szeto (void) snprintf(guidAsciiBuf, sizeof (guidAsciiBuf), 12218fe96085Stim szeto "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X" 12228fe96085Stim szeto "%02X%02X%02X%02X%02X%02X", 12238fe96085Stim szeto createdGuid.guid[0], createdGuid.guid[1], createdGuid.guid[2], 12248fe96085Stim szeto createdGuid.guid[3], createdGuid.guid[4], createdGuid.guid[5], 12258fe96085Stim szeto createdGuid.guid[6], createdGuid.guid[7], createdGuid.guid[8], 12268fe96085Stim szeto createdGuid.guid[9], createdGuid.guid[10], createdGuid.guid[11], 12278fe96085Stim szeto createdGuid.guid[12], createdGuid.guid[13], createdGuid.guid[14], 12288fe96085Stim szeto createdGuid.guid[15]); 12298fe96085Stim szeto (void) printf("Logical unit imported: %s\n", guidAsciiBuf); 12308fe96085Stim szeto 12318fe96085Stim szeto done: 12328fe96085Stim szeto return (ret); 12338fe96085Stim szeto } 12348fe96085Stim szeto 12358fe96085Stim szeto static int 12368fe96085Stim szeto setLuPropFromInput(luResource hdl, char *optarg) 12378fe96085Stim szeto { 12388fe96085Stim szeto char *prop = NULL; 12398fe96085Stim szeto char *propVal = NULL; 12408fe96085Stim szeto char *lasts = NULL; 12418fe96085Stim szeto uint32_t propId; 12428fe96085Stim szeto int ret = 0; 12438fe96085Stim szeto 12448fe96085Stim szeto prop = strtok_r(optarg, "=", &lasts); 12458fe96085Stim szeto if ((propVal = strtok_r(NULL, "=", &lasts)) == NULL) { 12468fe96085Stim szeto (void) fprintf(stderr, "%s: %s: %s\n", 12478fe96085Stim szeto cmdName, optarg, 12488fe96085Stim szeto gettext("invalid property specifier - prop=val\n")); 12498fe96085Stim szeto return (1); 12508fe96085Stim szeto } 12518fe96085Stim szeto 12528fe96085Stim szeto ret = convertCharToPropId(prop, &propId); 12538fe96085Stim szeto if (ret != 0) { 12548fe96085Stim szeto (void) fprintf(stderr, "%s: %s: %s\n", 12558fe96085Stim szeto cmdName, gettext("invalid property specified"), prop); 12568fe96085Stim szeto return (1); 12578fe96085Stim szeto } 12588fe96085Stim szeto 12598fe96085Stim szeto ret = stmfSetLuProp(hdl, propId, propVal); 12608fe96085Stim szeto if (ret != STMF_STATUS_SUCCESS) { 12618fe96085Stim szeto (void) fprintf(stderr, "%s: %s %s: ", 12628fe96085Stim szeto cmdName, gettext("unable to set"), prop); 12638fe96085Stim szeto switch (ret) { 12648fe96085Stim szeto case STMF_ERROR_INVALID_PROPSIZE: 12658fe96085Stim szeto (void) fprintf(stderr, "invalid length\n"); 12668fe96085Stim szeto break; 12678fe96085Stim szeto case STMF_ERROR_INVALID_ARG: 12688fe96085Stim szeto (void) fprintf(stderr, "bad format\n"); 12698fe96085Stim szeto break; 12708fe96085Stim szeto default: 12718fe96085Stim szeto (void) fprintf(stderr, "\n"); 12728fe96085Stim szeto break; 12738fe96085Stim szeto } 12748fe96085Stim szeto return (1); 12758fe96085Stim szeto } 12768fe96085Stim szeto 12778fe96085Stim szeto return (0); 12788fe96085Stim szeto } 12798fe96085Stim szeto 12808fe96085Stim szeto static int 12818fe96085Stim szeto convertCharToPropId(char *prop, uint32_t *propId) 12828fe96085Stim szeto { 12838fe96085Stim szeto if (strcasecmp(prop, GUID) == 0) { 12848fe96085Stim szeto *propId = STMF_LU_PROP_GUID; 12858fe96085Stim szeto } else if (strcasecmp(prop, ALIAS) == 0) { 12868fe96085Stim szeto *propId = STMF_LU_PROP_ALIAS; 12878fe96085Stim szeto } else if (strcasecmp(prop, VID) == 0) { 12888fe96085Stim szeto *propId = STMF_LU_PROP_VID; 12898fe96085Stim szeto } else if (strcasecmp(prop, PID) == 0) { 12908fe96085Stim szeto *propId = STMF_LU_PROP_PID; 12918fe96085Stim szeto } else if (strcasecmp(prop, WRITE_PROTECT) == 0) { 12928fe96085Stim szeto *propId = STMF_LU_PROP_WRITE_PROTECT; 12938fe96085Stim szeto } else if (strcasecmp(prop, WRITEBACK_CACHE_DISABLE) == 0) { 12948fe96085Stim szeto *propId = STMF_LU_PROP_WRITE_CACHE_DISABLE; 12958fe96085Stim szeto } else if (strcasecmp(prop, BLOCK_SIZE) == 0) { 12968fe96085Stim szeto *propId = STMF_LU_PROP_BLOCK_SIZE; 12978fe96085Stim szeto } else if (strcasecmp(prop, SERIAL_NUMBER) == 0) { 12988fe96085Stim szeto *propId = STMF_LU_PROP_SERIAL_NUM; 12998fe96085Stim szeto } else if (strcasecmp(prop, COMPANY_ID) == 0) { 13008fe96085Stim szeto *propId = STMF_LU_PROP_COMPANY_ID; 13018fe96085Stim szeto } else if (strcasecmp(prop, META_FILE) == 0) { 13028fe96085Stim szeto *propId = STMF_LU_PROP_META_FILENAME; 13032f624233SNattuvetty Bhavyan } else if (strcasecmp(prop, MGMT_URL) == 0) { 13042f624233SNattuvetty Bhavyan *propId = STMF_LU_PROP_MGMT_URL; 1305fdcc480aSJohn Forte } else if (strcasecmp(prop, HOST_ID) == 0) { 1306fdcc480aSJohn Forte *propId = STMF_LU_PROP_HOST_ID; 13078fe96085Stim szeto } else { 13088fe96085Stim szeto return (1); 13098fe96085Stim szeto } 13108fe96085Stim szeto return (0); 13118fe96085Stim szeto } 13128fe96085Stim szeto 13138fe96085Stim szeto /* 13148fe96085Stim szeto * deleteLuFunc 13158fe96085Stim szeto * 13168fe96085Stim szeto * Delete a logical unit 13178fe96085Stim szeto * 13188fe96085Stim szeto */ 13198fe96085Stim szeto /*ARGSUSED*/ 13208fe96085Stim szeto static int 13218fe96085Stim szeto deleteLuFunc(int operandLen, char *operands[], cmdOptions_t *options, 13228fe96085Stim szeto void *args) 13238fe96085Stim szeto { 13248fe96085Stim szeto int i, j; 13258fe96085Stim szeto int ret = 0; 13268fe96085Stim szeto int stmfRet; 13278fe96085Stim szeto unsigned int inGuid[sizeof (stmfGuid)]; 13288fe96085Stim szeto stmfGuid delGuid; 13298fe96085Stim szeto boolean_t keepViews = B_FALSE; 13308fe96085Stim szeto boolean_t viewEntriesRemoved = B_FALSE; 13318fe96085Stim szeto boolean_t noLunFound = B_FALSE; 13328fe96085Stim szeto boolean_t views = B_FALSE; 13337b506e25Ssrivijitha dugganapalli boolean_t notValidHexNumber = B_FALSE; 13348fe96085Stim szeto char sGuid[GUID_INPUT + 1]; 13358fe96085Stim szeto stmfViewEntryList *viewEntryList = NULL; 13368fe96085Stim szeto 13378fe96085Stim szeto for (; options->optval; options++) { 13388fe96085Stim szeto switch (options->optval) { 13398fe96085Stim szeto /* Keep views for logical unit */ 13408fe96085Stim szeto case 'k': 13418fe96085Stim szeto keepViews = B_TRUE; 13428fe96085Stim szeto break; 13438fe96085Stim szeto default: 13448fe96085Stim szeto (void) fprintf(stderr, "%s: %c: %s\n", 13458fe96085Stim szeto cmdName, options->optval, 13468fe96085Stim szeto gettext("unknown option")); 13478fe96085Stim szeto return (1); 13488fe96085Stim szeto } 13498fe96085Stim szeto } 13508fe96085Stim szeto 13518fe96085Stim szeto 13528fe96085Stim szeto for (i = 0; i < operandLen; i++) { 13538fe96085Stim szeto for (j = 0; j < GUID_INPUT; j++) { 13548fe96085Stim szeto if (!isxdigit(operands[i][j])) { 13557b506e25Ssrivijitha dugganapalli notValidHexNumber = B_TRUE; 13568fe96085Stim szeto break; 13578fe96085Stim szeto } 13588fe96085Stim szeto sGuid[j] = tolower(operands[i][j]); 13598fe96085Stim szeto } 13607b506e25Ssrivijitha dugganapalli if ((notValidHexNumber == B_TRUE) || 13617b506e25Ssrivijitha dugganapalli (strlen(operands[i]) != GUID_INPUT)) { 13628fe96085Stim szeto (void) fprintf(stderr, "%s: %s: %s%d%s\n", 13638fe96085Stim szeto cmdName, operands[i], gettext("must be "), 13648fe96085Stim szeto GUID_INPUT, 13658fe96085Stim szeto gettext(" hexadecimal digits long")); 13667b506e25Ssrivijitha dugganapalli notValidHexNumber = B_FALSE; 13677b506e25Ssrivijitha dugganapalli ret++; 13688fe96085Stim szeto continue; 13698fe96085Stim szeto } 13708fe96085Stim szeto 13718fe96085Stim szeto sGuid[j] = 0; 13728fe96085Stim szeto 13738fe96085Stim szeto (void) sscanf(sGuid, 13748fe96085Stim szeto "%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x", 13758fe96085Stim szeto &inGuid[0], &inGuid[1], &inGuid[2], &inGuid[3], 13768fe96085Stim szeto &inGuid[4], &inGuid[5], &inGuid[6], &inGuid[7], 13778fe96085Stim szeto &inGuid[8], &inGuid[9], &inGuid[10], &inGuid[11], 13788fe96085Stim szeto &inGuid[12], &inGuid[13], &inGuid[14], &inGuid[15]); 13798fe96085Stim szeto 13808fe96085Stim szeto for (j = 0; j < sizeof (stmfGuid); j++) { 13818fe96085Stim szeto delGuid.guid[j] = inGuid[j]; 13828fe96085Stim szeto } 13838fe96085Stim szeto 13848fe96085Stim szeto stmfRet = stmfDeleteLu(&delGuid); 13858fe96085Stim szeto switch (stmfRet) { 13868fe96085Stim szeto case STMF_STATUS_SUCCESS: 13878fe96085Stim szeto break; 13888fe96085Stim szeto case STMF_ERROR_NOT_FOUND: 13898fe96085Stim szeto noLunFound = B_TRUE; 13908fe96085Stim szeto break; 13918fe96085Stim szeto case STMF_ERROR_BUSY: 13928fe96085Stim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 13938fe96085Stim szeto gettext("resource busy")); 13948fe96085Stim szeto ret++; 13958fe96085Stim szeto break; 13968fe96085Stim szeto case STMF_ERROR_PERM: 13978fe96085Stim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 13988fe96085Stim szeto gettext("permission denied")); 13998fe96085Stim szeto ret++; 14008fe96085Stim szeto break; 14018fe96085Stim szeto default: 14028fe96085Stim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 14038fe96085Stim szeto gettext("unknown error")); 14048fe96085Stim szeto ret++; 14058fe96085Stim szeto break; 14068fe96085Stim szeto } 14078fe96085Stim szeto 14088fe96085Stim szeto if (!keepViews) { 14098fe96085Stim szeto stmfRet = stmfGetViewEntryList(&delGuid, 14108fe96085Stim szeto &viewEntryList); 14118fe96085Stim szeto if (stmfRet == STMF_STATUS_SUCCESS) { 14128fe96085Stim szeto for (j = 0; j < viewEntryList->cnt; j++) { 14138fe96085Stim szeto (void) stmfRemoveViewEntry(&delGuid, 14148fe96085Stim szeto viewEntryList->ve[j].veIndex); 14158fe96085Stim szeto } 14167b506e25Ssrivijitha dugganapalli /* check if viewEntryList is empty */ 14177b506e25Ssrivijitha dugganapalli if (viewEntryList->cnt != 0) 14188fe96085Stim szeto viewEntriesRemoved = B_TRUE; 14198fe96085Stim szeto stmfFreeMemory(viewEntryList); 14207b506e25Ssrivijitha dugganapalli } else { 14218fe96085Stim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 14228fe96085Stim szeto gettext("unable to remove view entries\n")); 14238fe96085Stim szeto ret++; 14247b506e25Ssrivijitha dugganapalli } 14257b506e25Ssrivijitha dugganapalli 14268fe96085Stim szeto } 14278fe96085Stim szeto if (keepViews) { 14288fe96085Stim szeto stmfRet = stmfGetViewEntryList(&delGuid, 14298fe96085Stim szeto &viewEntryList); 14308fe96085Stim szeto if (stmfRet == STMF_STATUS_SUCCESS) { 14318fe96085Stim szeto views = B_TRUE; 14328fe96085Stim szeto stmfFreeMemory(viewEntryList); 14338fe96085Stim szeto } 14348fe96085Stim szeto } 14358fe96085Stim szeto 14368fe96085Stim szeto if ((!viewEntriesRemoved && noLunFound && !views) || 14378fe96085Stim szeto (!views && keepViews && noLunFound)) { 14388fe96085Stim szeto (void) fprintf(stderr, "%s: %s: %s\n", 14398fe96085Stim szeto cmdName, sGuid, 14408fe96085Stim szeto gettext("not found")); 14418fe96085Stim szeto ret++; 14428fe96085Stim szeto } 14438fe96085Stim szeto noLunFound = viewEntriesRemoved = views = B_FALSE; 14448fe96085Stim szeto } 14458fe96085Stim szeto return (ret); 14468fe96085Stim szeto } 14478fe96085Stim szeto 14488fe96085Stim szeto 14498fe96085Stim szeto /* 1450fcf3ce44SJohn Forte * createTargetGroupFunc 1451fcf3ce44SJohn Forte * 1452fcf3ce44SJohn Forte * Create a target group 1453fcf3ce44SJohn Forte * 1454fcf3ce44SJohn Forte */ 1455fcf3ce44SJohn Forte /*ARGSUSED*/ 1456fcf3ce44SJohn Forte static int 1457fcf3ce44SJohn Forte createTargetGroupFunc(int operandLen, char *operands[], cmdOptions_t *options, 1458fcf3ce44SJohn Forte void *args) 1459fcf3ce44SJohn Forte { 1460fcf3ce44SJohn Forte int ret = 0; 1461fcf3ce44SJohn Forte int stmfRet; 14623e7352aeSJohn Forte wchar_t groupNamePrint[sizeof (stmfGroupName)] = {0}; 14633e7352aeSJohn Forte stmfGroupName groupName = {0}; 1464fcf3ce44SJohn Forte 1465fcf3ce44SJohn Forte (void) strlcpy(groupName, operands[0], sizeof (groupName)); 1466fcf3ce44SJohn Forte (void) mbstowcs(groupNamePrint, (char *)groupName, 14673e7352aeSJohn Forte sizeof (stmfGroupName) - 1); 1468fcf3ce44SJohn Forte /* call create group */ 1469fcf3ce44SJohn Forte stmfRet = stmfCreateTargetGroup(&groupName); 1470fcf3ce44SJohn Forte switch (stmfRet) { 1471fcf3ce44SJohn Forte case STMF_STATUS_SUCCESS: 1472fcf3ce44SJohn Forte break; 1473fcf3ce44SJohn Forte case STMF_ERROR_EXISTS: 1474fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %ws: %s\n", cmdName, 1475fcf3ce44SJohn Forte groupNamePrint, gettext("already exists")); 1476fcf3ce44SJohn Forte ret++; 1477fcf3ce44SJohn Forte break; 1478fcf3ce44SJohn Forte case STMF_ERROR_BUSY: 1479fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %ws: %s\n", cmdName, 1480fcf3ce44SJohn Forte groupNamePrint, gettext("resource busy")); 1481fcf3ce44SJohn Forte ret++; 1482fcf3ce44SJohn Forte break; 1483fcf3ce44SJohn Forte case STMF_ERROR_PERM: 1484fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 1485fcf3ce44SJohn Forte gettext("permission denied")); 1486fcf3ce44SJohn Forte ret++; 1487fcf3ce44SJohn Forte break; 1488fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_NOT_FOUND: 1489fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 1490fcf3ce44SJohn Forte gettext("STMF service not found")); 1491fcf3ce44SJohn Forte ret++; 1492fcf3ce44SJohn Forte break; 1493fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_DATA_VERSION: 1494fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 1495fcf3ce44SJohn Forte gettext("STMF service version incorrect")); 1496fcf3ce44SJohn Forte ret++; 1497fcf3ce44SJohn Forte break; 1498fcf3ce44SJohn Forte default: 1499fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %ws: %s\n", cmdName, 1500fcf3ce44SJohn Forte groupNamePrint, gettext("unknown error")); 1501fcf3ce44SJohn Forte ret++; 1502fcf3ce44SJohn Forte break; 1503fcf3ce44SJohn Forte } 1504fcf3ce44SJohn Forte 1505fcf3ce44SJohn Forte return (ret); 1506fcf3ce44SJohn Forte } 1507fcf3ce44SJohn Forte 1508fcf3ce44SJohn Forte /* 1509fcf3ce44SJohn Forte * deleteHostGroupFunc 1510fcf3ce44SJohn Forte * 1511fcf3ce44SJohn Forte * Delete a host group 1512fcf3ce44SJohn Forte * 1513fcf3ce44SJohn Forte */ 1514fcf3ce44SJohn Forte /*ARGSUSED*/ 1515fcf3ce44SJohn Forte static int 1516fcf3ce44SJohn Forte deleteHostGroupFunc(int operandLen, char *operands[], 1517fcf3ce44SJohn Forte cmdOptions_t *options, void *args) 1518fcf3ce44SJohn Forte { 1519fcf3ce44SJohn Forte int ret = 0; 1520fcf3ce44SJohn Forte int stmfRet; 15213e7352aeSJohn Forte wchar_t groupNamePrint[sizeof (stmfGroupName)] = {0}; 15223e7352aeSJohn Forte stmfGroupName groupName = {0}; 1523fcf3ce44SJohn Forte 1524fcf3ce44SJohn Forte (void) strlcpy(groupName, operands[0], sizeof (groupName)); 1525fcf3ce44SJohn Forte (void) mbstowcs(groupNamePrint, (char *)groupName, 15263e7352aeSJohn Forte sizeof (stmfGroupName) - 1); 1527fcf3ce44SJohn Forte /* call delete group */ 1528fcf3ce44SJohn Forte stmfRet = stmfDeleteHostGroup(&groupName); 1529fcf3ce44SJohn Forte switch (stmfRet) { 1530fcf3ce44SJohn Forte case STMF_STATUS_SUCCESS: 1531fcf3ce44SJohn Forte break; 1532fcf3ce44SJohn Forte case STMF_ERROR_NOT_FOUND: 1533fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %ws: %s\n", cmdName, 1534fcf3ce44SJohn Forte groupNamePrint, gettext("not found")); 1535fcf3ce44SJohn Forte ret++; 1536fcf3ce44SJohn Forte break; 1537fcf3ce44SJohn Forte case STMF_ERROR_BUSY: 1538fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %ws: %s\n", cmdName, 1539fcf3ce44SJohn Forte groupNamePrint, gettext("resource busy")); 1540fcf3ce44SJohn Forte ret++; 1541fcf3ce44SJohn Forte break; 1542fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_NOT_FOUND: 1543fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 1544fcf3ce44SJohn Forte gettext("STMF service not found")); 1545fcf3ce44SJohn Forte ret++; 1546fcf3ce44SJohn Forte break; 1547fcf3ce44SJohn Forte case STMF_ERROR_PERM: 1548fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 1549fcf3ce44SJohn Forte gettext("permission denied")); 1550fcf3ce44SJohn Forte ret++; 1551fcf3ce44SJohn Forte break; 1552fcf3ce44SJohn Forte case STMF_ERROR_GROUP_IN_USE: 1553fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %ws: %s\n", cmdName, 1554fcf3ce44SJohn Forte groupNamePrint, 1555fcf3ce44SJohn Forte gettext("group is in use by existing view entry")); 1556fcf3ce44SJohn Forte ret++; 1557fcf3ce44SJohn Forte break; 1558fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_DATA_VERSION: 1559fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 1560fcf3ce44SJohn Forte gettext("STMF service version incorrect")); 1561fcf3ce44SJohn Forte ret++; 1562fcf3ce44SJohn Forte break; 1563fcf3ce44SJohn Forte default: 1564fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %ws: %s\n", cmdName, 1565fcf3ce44SJohn Forte groupNamePrint, gettext("unknown error")); 1566fcf3ce44SJohn Forte ret++; 1567fcf3ce44SJohn Forte break; 1568fcf3ce44SJohn Forte } 1569fcf3ce44SJohn Forte 1570fcf3ce44SJohn Forte return (ret); 1571fcf3ce44SJohn Forte } 1572fcf3ce44SJohn Forte 1573fcf3ce44SJohn Forte /* 1574fcf3ce44SJohn Forte * deleteTargetGroupFunc 1575fcf3ce44SJohn Forte * 1576fcf3ce44SJohn Forte * Delete a target group 1577fcf3ce44SJohn Forte * 1578fcf3ce44SJohn Forte */ 1579fcf3ce44SJohn Forte /*ARGSUSED*/ 1580fcf3ce44SJohn Forte static int 1581fcf3ce44SJohn Forte deleteTargetGroupFunc(int operandLen, char *operands[], cmdOptions_t *options, 1582fcf3ce44SJohn Forte void *args) 1583fcf3ce44SJohn Forte { 1584fcf3ce44SJohn Forte int ret = 0; 1585fcf3ce44SJohn Forte int stmfRet; 15863e7352aeSJohn Forte wchar_t groupNamePrint[sizeof (stmfGroupName)] = {0}; 15873e7352aeSJohn Forte stmfGroupName groupName = {0}; 1588fcf3ce44SJohn Forte 1589fcf3ce44SJohn Forte (void) strlcpy(groupName, operands[0], sizeof (groupName)); 1590fcf3ce44SJohn Forte (void) mbstowcs(groupNamePrint, (char *)groupName, 15913e7352aeSJohn Forte sizeof (stmfGroupName) - 1); 1592fcf3ce44SJohn Forte /* call delete group */ 1593fcf3ce44SJohn Forte stmfRet = stmfDeleteTargetGroup(&groupName); 1594fcf3ce44SJohn Forte switch (stmfRet) { 1595fcf3ce44SJohn Forte case STMF_STATUS_SUCCESS: 1596fcf3ce44SJohn Forte break; 1597fcf3ce44SJohn Forte case STMF_ERROR_NOT_FOUND: 1598fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %ws: %s\n", cmdName, 1599fcf3ce44SJohn Forte groupNamePrint, gettext("not found")); 1600fcf3ce44SJohn Forte ret++; 1601fcf3ce44SJohn Forte break; 1602fcf3ce44SJohn Forte case STMF_ERROR_BUSY: 1603fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %ws: %s\n", cmdName, 1604fcf3ce44SJohn Forte groupNamePrint, gettext("resource busy")); 1605fcf3ce44SJohn Forte ret++; 1606fcf3ce44SJohn Forte break; 1607fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_NOT_FOUND: 1608fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 1609fcf3ce44SJohn Forte gettext("STMF service not found")); 1610fcf3ce44SJohn Forte ret++; 1611fcf3ce44SJohn Forte break; 1612fcf3ce44SJohn Forte case STMF_ERROR_PERM: 1613fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 1614fcf3ce44SJohn Forte gettext("permission denied")); 1615fcf3ce44SJohn Forte ret++; 1616fcf3ce44SJohn Forte break; 1617fcf3ce44SJohn Forte case STMF_ERROR_GROUP_IN_USE: 1618fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %ws: %s\n", cmdName, 1619fcf3ce44SJohn Forte groupNamePrint, 1620fcf3ce44SJohn Forte gettext("group is in use by existing view entry")); 1621fcf3ce44SJohn Forte ret++; 1622fcf3ce44SJohn Forte break; 1623fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_DATA_VERSION: 1624fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 1625fcf3ce44SJohn Forte gettext("STMF service version incorrect")); 1626fcf3ce44SJohn Forte ret++; 1627fcf3ce44SJohn Forte break; 1628fcf3ce44SJohn Forte default: 1629fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %ws: %s\n", cmdName, 1630fcf3ce44SJohn Forte groupNamePrint, gettext("unknown error")); 1631fcf3ce44SJohn Forte ret++; 1632fcf3ce44SJohn Forte break; 1633fcf3ce44SJohn Forte } 1634fcf3ce44SJohn Forte 1635fcf3ce44SJohn Forte return (ret); 1636fcf3ce44SJohn Forte } 1637fcf3ce44SJohn Forte 1638fcf3ce44SJohn Forte /* 1639fcf3ce44SJohn Forte * listHostGroupFunc 1640fcf3ce44SJohn Forte * 1641fcf3ce44SJohn Forte * Lists the specified host groups or all if none are specified 1642fcf3ce44SJohn Forte * 1643fcf3ce44SJohn Forte */ 1644fcf3ce44SJohn Forte /*ARGSUSED*/ 1645fcf3ce44SJohn Forte static int 1646fcf3ce44SJohn Forte listHostGroupFunc(int operandLen, char *operands[], cmdOptions_t *options, 1647fcf3ce44SJohn Forte void *args) 1648fcf3ce44SJohn Forte { 1649fcf3ce44SJohn Forte int ret = 0; 1650fcf3ce44SJohn Forte int stmfRet; 1651fcf3ce44SJohn Forte int i, j, outerLoop; 1652fcf3ce44SJohn Forte boolean_t verbose = B_FALSE; 1653fcf3ce44SJohn Forte boolean_t found = B_TRUE; 1654fcf3ce44SJohn Forte boolean_t operandEntered; 1655fcf3ce44SJohn Forte stmfGroupList *groupList; 1656fcf3ce44SJohn Forte stmfGroupProperties *groupProps; 1657fcf3ce44SJohn Forte wchar_t operandName[sizeof (stmfGroupName)]; 1658fcf3ce44SJohn Forte wchar_t groupNamePrint[sizeof (stmfGroupName)]; 1659fcf3ce44SJohn Forte 1660fcf3ce44SJohn Forte for (; options->optval; options++) { 1661fcf3ce44SJohn Forte switch (options->optval) { 1662fcf3ce44SJohn Forte case 'v': 1663fcf3ce44SJohn Forte verbose = B_TRUE; 1664fcf3ce44SJohn Forte break; 1665fcf3ce44SJohn Forte default: 1666fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %c: %s\n", 1667fcf3ce44SJohn Forte cmdName, options->optval, 1668fcf3ce44SJohn Forte gettext("unknown option")); 1669fcf3ce44SJohn Forte return (1); 1670fcf3ce44SJohn Forte } 1671fcf3ce44SJohn Forte } 1672fcf3ce44SJohn Forte 1673fcf3ce44SJohn Forte if (operandLen > 0) { 1674fcf3ce44SJohn Forte outerLoop = operandLen; 1675fcf3ce44SJohn Forte operandEntered = B_TRUE; 1676fcf3ce44SJohn Forte } else { 1677fcf3ce44SJohn Forte outerLoop = 1; 1678fcf3ce44SJohn Forte operandEntered = B_FALSE; 1679fcf3ce44SJohn Forte } 1680fcf3ce44SJohn Forte 1681fcf3ce44SJohn Forte stmfRet = stmfGetHostGroupList(&groupList); 1682fcf3ce44SJohn Forte if (stmfRet != STMF_STATUS_SUCCESS) { 1683fcf3ce44SJohn Forte switch (stmfRet) { 1684fcf3ce44SJohn Forte case STMF_ERROR_BUSY: 1685fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 1686fcf3ce44SJohn Forte gettext("resource busy")); 1687fcf3ce44SJohn Forte break; 1688fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_NOT_FOUND: 1689fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 1690fcf3ce44SJohn Forte gettext("STMF service not found")); 1691fcf3ce44SJohn Forte break; 1692fcf3ce44SJohn Forte case STMF_ERROR_PERM: 1693fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 1694fcf3ce44SJohn Forte gettext("permission denied")); 1695fcf3ce44SJohn Forte break; 1696fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_DATA_VERSION: 1697fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 1698fcf3ce44SJohn Forte gettext("STMF service version incorrect")); 1699fcf3ce44SJohn Forte break; 1700fcf3ce44SJohn Forte default: 1701fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 1702fcf3ce44SJohn Forte gettext("unknown error")); 1703fcf3ce44SJohn Forte break; 1704fcf3ce44SJohn Forte } 1705fcf3ce44SJohn Forte return (1); 1706fcf3ce44SJohn Forte } 1707fcf3ce44SJohn Forte 1708fcf3ce44SJohn Forte for (i = 0; i < outerLoop; i++) { 1709fcf3ce44SJohn Forte for (found = B_FALSE, j = 0; j < groupList->cnt; j++) { 1710fcf3ce44SJohn Forte (void) mbstowcs(groupNamePrint, 1711fcf3ce44SJohn Forte (char *)groupList->name[j], 17123e7352aeSJohn Forte sizeof (stmfGroupName) - 1); 17133e7352aeSJohn Forte groupNamePrint[sizeof (stmfGroupName) - 1] = 0; 1714fcf3ce44SJohn Forte if (operandEntered) { 1715fcf3ce44SJohn Forte (void) mbstowcs(operandName, operands[i], 17163e7352aeSJohn Forte sizeof (stmfGroupName) - 1); 17173e7352aeSJohn Forte operandName[sizeof (stmfGroupName) - 1] = 0; 1718fcf3ce44SJohn Forte if (wcscmp(operandName, groupNamePrint) 1719fcf3ce44SJohn Forte == 0) { 1720fcf3ce44SJohn Forte found = B_TRUE; 1721fcf3ce44SJohn Forte } 1722fcf3ce44SJohn Forte } 1723fcf3ce44SJohn Forte if ((found && operandEntered) || !operandEntered) { 1724fcf3ce44SJohn Forte (void) printf("Host Group: %ws\n", 1725fcf3ce44SJohn Forte groupNamePrint); 1726fcf3ce44SJohn Forte if (verbose) { 1727fcf3ce44SJohn Forte stmfRet = stmfGetHostGroupMembers( 1728fcf3ce44SJohn Forte &(groupList->name[j]), &groupProps); 1729fcf3ce44SJohn Forte if (stmfRet != STMF_STATUS_SUCCESS) { 1730fcf3ce44SJohn Forte return (1); 1731fcf3ce44SJohn Forte } 1732fcf3ce44SJohn Forte printGroupProps(groupProps); 1733fcf3ce44SJohn Forte } 1734fcf3ce44SJohn Forte if (found && operandEntered) { 1735fcf3ce44SJohn Forte break; 1736fcf3ce44SJohn Forte } 1737fcf3ce44SJohn Forte } 1738fcf3ce44SJohn Forte 1739fcf3ce44SJohn Forte } 1740fcf3ce44SJohn Forte if (operandEntered && !found) { 1741fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 1742fcf3ce44SJohn Forte operands[i], gettext("not found")); 1743fcf3ce44SJohn Forte ret = 1; 1744fcf3ce44SJohn Forte } 1745fcf3ce44SJohn Forte } 1746fcf3ce44SJohn Forte return (ret); 1747fcf3ce44SJohn Forte } 1748fcf3ce44SJohn Forte 1749fcf3ce44SJohn Forte /* 1750fcf3ce44SJohn Forte * printGroupProps 1751fcf3ce44SJohn Forte * 1752fcf3ce44SJohn Forte * Prints group members for target or host groups 1753fcf3ce44SJohn Forte * 1754fcf3ce44SJohn Forte */ 1755fcf3ce44SJohn Forte static void 1756fcf3ce44SJohn Forte printGroupProps(stmfGroupProperties *groupProps) 1757fcf3ce44SJohn Forte { 1758fcf3ce44SJohn Forte int i; 17593e7352aeSJohn Forte wchar_t memberIdent[sizeof (groupProps->name[0].ident) + 1] = {0}; 1760fcf3ce44SJohn Forte 1761fcf3ce44SJohn Forte 1762fcf3ce44SJohn Forte for (i = 0; i < groupProps->cnt; i++) { 1763fcf3ce44SJohn Forte (void) mbstowcs(memberIdent, (char *)groupProps->name[i].ident, 17643e7352aeSJohn Forte sizeof (groupProps->name[0].ident)); 1765fcf3ce44SJohn Forte (void) printf("\tMember: %ws\n", memberIdent); 1766fcf3ce44SJohn Forte } 1767fcf3ce44SJohn Forte } 1768fcf3ce44SJohn Forte 1769fcf3ce44SJohn Forte /* 1770fcf3ce44SJohn Forte * listTargetGroupFunc 1771fcf3ce44SJohn Forte * 1772fcf3ce44SJohn Forte * Lists the specified target groups or all if none are specified 1773fcf3ce44SJohn Forte * 1774fcf3ce44SJohn Forte */ 1775fcf3ce44SJohn Forte /*ARGSUSED*/ 1776fcf3ce44SJohn Forte static int 1777fcf3ce44SJohn Forte listTargetGroupFunc(int operandLen, char *operands[], cmdOptions_t *options, 1778fcf3ce44SJohn Forte void *args) 1779fcf3ce44SJohn Forte { 1780fcf3ce44SJohn Forte int ret = 0; 1781fcf3ce44SJohn Forte int stmfRet; 1782fcf3ce44SJohn Forte int i, j, outerLoop; 1783fcf3ce44SJohn Forte boolean_t verbose = B_FALSE; 1784fcf3ce44SJohn Forte boolean_t found = B_TRUE; 1785fcf3ce44SJohn Forte boolean_t operandEntered; 1786fcf3ce44SJohn Forte stmfGroupList *groupList; 1787fcf3ce44SJohn Forte stmfGroupProperties *groupProps; 1788fcf3ce44SJohn Forte wchar_t operandName[sizeof (stmfGroupName)]; 1789fcf3ce44SJohn Forte wchar_t groupNamePrint[sizeof (stmfGroupName)]; 1790fcf3ce44SJohn Forte 1791fcf3ce44SJohn Forte for (; options->optval; options++) { 1792fcf3ce44SJohn Forte switch (options->optval) { 1793fcf3ce44SJohn Forte case 'v': 1794fcf3ce44SJohn Forte verbose = B_TRUE; 1795fcf3ce44SJohn Forte break; 1796fcf3ce44SJohn Forte default: 1797fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %c: %s\n", 1798fcf3ce44SJohn Forte cmdName, options->optval, 1799fcf3ce44SJohn Forte gettext("unknown option")); 1800fcf3ce44SJohn Forte return (1); 1801fcf3ce44SJohn Forte } 1802fcf3ce44SJohn Forte } 1803fcf3ce44SJohn Forte 1804fcf3ce44SJohn Forte if (operandLen > 0) { 1805fcf3ce44SJohn Forte outerLoop = operandLen; 1806fcf3ce44SJohn Forte operandEntered = B_TRUE; 1807fcf3ce44SJohn Forte } else { 1808fcf3ce44SJohn Forte outerLoop = 1; 1809fcf3ce44SJohn Forte operandEntered = B_FALSE; 1810fcf3ce44SJohn Forte } 1811fcf3ce44SJohn Forte 1812fcf3ce44SJohn Forte stmfRet = stmfGetTargetGroupList(&groupList); 1813fcf3ce44SJohn Forte if (stmfRet != STMF_STATUS_SUCCESS) { 1814fcf3ce44SJohn Forte switch (stmfRet) { 1815fcf3ce44SJohn Forte case STMF_ERROR_BUSY: 1816fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 1817fcf3ce44SJohn Forte gettext("resource busy")); 1818fcf3ce44SJohn Forte break; 1819fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_NOT_FOUND: 1820fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 1821fcf3ce44SJohn Forte gettext("STMF service not found")); 1822fcf3ce44SJohn Forte break; 1823fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_DATA_VERSION: 1824fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 1825fcf3ce44SJohn Forte gettext("STMF service version incorrect")); 1826fcf3ce44SJohn Forte break; 1827fcf3ce44SJohn Forte case STMF_ERROR_PERM: 1828fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 1829fcf3ce44SJohn Forte gettext("permission denied")); 1830fcf3ce44SJohn Forte break; 1831fcf3ce44SJohn Forte default: 1832fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 1833fcf3ce44SJohn Forte gettext("unknown error")); 1834fcf3ce44SJohn Forte break; 1835fcf3ce44SJohn Forte } 1836fcf3ce44SJohn Forte return (1); 1837fcf3ce44SJohn Forte } 1838fcf3ce44SJohn Forte 1839fcf3ce44SJohn Forte for (i = 0; i < outerLoop; i++) { 1840fcf3ce44SJohn Forte for (found = B_FALSE, j = 0; j < groupList->cnt; j++) { 1841fcf3ce44SJohn Forte (void) mbstowcs(groupNamePrint, 1842fcf3ce44SJohn Forte (char *)groupList->name[j], 18433e7352aeSJohn Forte sizeof (stmfGroupName) - 1); 18443e7352aeSJohn Forte groupNamePrint[sizeof (stmfGroupName) - 1] = 0; 1845fcf3ce44SJohn Forte if (operandEntered) { 1846fcf3ce44SJohn Forte (void) mbstowcs(operandName, operands[i], 18473e7352aeSJohn Forte sizeof (stmfGroupName) - 1); 18483e7352aeSJohn Forte operandName[sizeof (stmfGroupName) - 1] = 0; 1849fcf3ce44SJohn Forte if (wcscmp(operandName, groupNamePrint) 1850fcf3ce44SJohn Forte == 0) { 1851fcf3ce44SJohn Forte found = B_TRUE; 1852fcf3ce44SJohn Forte } 1853fcf3ce44SJohn Forte } 1854fcf3ce44SJohn Forte if ((found && operandEntered) || !operandEntered) { 1855fcf3ce44SJohn Forte (void) printf("Target Group: %ws\n", 1856fcf3ce44SJohn Forte groupNamePrint); 1857fcf3ce44SJohn Forte if (verbose) { 1858fcf3ce44SJohn Forte stmfRet = stmfGetTargetGroupMembers( 1859fcf3ce44SJohn Forte &(groupList->name[j]), &groupProps); 1860fcf3ce44SJohn Forte if (stmfRet != STMF_STATUS_SUCCESS) { 1861fcf3ce44SJohn Forte return (1); 1862fcf3ce44SJohn Forte } 1863fcf3ce44SJohn Forte printGroupProps(groupProps); 1864fcf3ce44SJohn Forte } 1865fcf3ce44SJohn Forte if (found && operandEntered) { 1866fcf3ce44SJohn Forte break; 1867fcf3ce44SJohn Forte } 1868fcf3ce44SJohn Forte } 1869fcf3ce44SJohn Forte 1870fcf3ce44SJohn Forte } 1871fcf3ce44SJohn Forte if (operandEntered && !found) { 1872fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 1873fcf3ce44SJohn Forte operands[i], gettext("not found")); 1874fcf3ce44SJohn Forte ret = 1; 1875fcf3ce44SJohn Forte } 1876fcf3ce44SJohn Forte } 1877fcf3ce44SJohn Forte return (ret); 1878fcf3ce44SJohn Forte } 1879fcf3ce44SJohn Forte 1880fcf3ce44SJohn Forte /* 1881fcf3ce44SJohn Forte * listLuFunc 1882fcf3ce44SJohn Forte * 1883fcf3ce44SJohn Forte * List the logical units and optionally the properties 1884fcf3ce44SJohn Forte * 1885fcf3ce44SJohn Forte */ 1886fcf3ce44SJohn Forte /*ARGSUSED*/ 1887fcf3ce44SJohn Forte static int 1888fcf3ce44SJohn Forte listLuFunc(int operandLen, char *operands[], cmdOptions_t *options, void *args) 1889fcf3ce44SJohn Forte { 1890fcf3ce44SJohn Forte cmdOptions_t *optionList = options; 1891fcf3ce44SJohn Forte boolean_t operandEntered; 1892fcf3ce44SJohn Forte int i, j; 1893fcf3ce44SJohn Forte int ret = 0; 1894fcf3ce44SJohn Forte int stmfRet; 1895fcf3ce44SJohn Forte int outerLoop; 1896fcf3ce44SJohn Forte unsigned int inGuid[sizeof (stmfGuid)]; 1897fcf3ce44SJohn Forte stmfGuid cmpGuid; 1898fcf3ce44SJohn Forte boolean_t verbose = B_FALSE; 1899fcf3ce44SJohn Forte boolean_t found; 1900fcf3ce44SJohn Forte char sGuid[GUID_INPUT + 1]; 1901fcf3ce44SJohn Forte stmfGuidList *luList; 1902fcf3ce44SJohn Forte stmfLogicalUnitProperties luProps; 1903fcf3ce44SJohn Forte boolean_t invalidInput = B_FALSE; 1904fcf3ce44SJohn Forte stmfViewEntryList *viewEntryList; 1905fcf3ce44SJohn Forte 1906fcf3ce44SJohn Forte for (; optionList->optval; optionList++) { 1907fcf3ce44SJohn Forte switch (optionList->optval) { 1908fcf3ce44SJohn Forte case 'v': 1909fcf3ce44SJohn Forte verbose = B_TRUE; 1910fcf3ce44SJohn Forte break; 1911fcf3ce44SJohn Forte } 1912fcf3ce44SJohn Forte } 1913fcf3ce44SJohn Forte 1914fcf3ce44SJohn Forte if ((stmfRet = stmfGetLogicalUnitList(&luList)) 1915fcf3ce44SJohn Forte != STMF_STATUS_SUCCESS) { 1916fcf3ce44SJohn Forte switch (stmfRet) { 1917fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_NOT_FOUND: 1918fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 1919fcf3ce44SJohn Forte gettext("STMF service not found")); 1920fcf3ce44SJohn Forte break; 1921fcf3ce44SJohn Forte case STMF_ERROR_BUSY: 1922fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 1923fcf3ce44SJohn Forte gettext("resource busy")); 1924fcf3ce44SJohn Forte break; 1925fcf3ce44SJohn Forte case STMF_ERROR_PERM: 1926fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 1927fcf3ce44SJohn Forte gettext("permission denied")); 1928fcf3ce44SJohn Forte break; 1929fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_DATA_VERSION: 1930fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 1931fcf3ce44SJohn Forte gettext("STMF service version incorrect")); 1932fcf3ce44SJohn Forte break; 1933fcf3ce44SJohn Forte default: 1934fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 1935fcf3ce44SJohn Forte gettext("list failed")); 1936fcf3ce44SJohn Forte break; 1937fcf3ce44SJohn Forte } 1938fcf3ce44SJohn Forte return (1); 1939fcf3ce44SJohn Forte } 1940fcf3ce44SJohn Forte 1941fcf3ce44SJohn Forte if (operandLen > 0) { 1942fcf3ce44SJohn Forte operandEntered = B_TRUE; 1943fcf3ce44SJohn Forte outerLoop = operandLen; 1944fcf3ce44SJohn Forte } else { 1945fcf3ce44SJohn Forte operandEntered = B_FALSE; 1946fcf3ce44SJohn Forte outerLoop = 1; 1947fcf3ce44SJohn Forte } 1948fcf3ce44SJohn Forte 1949fcf3ce44SJohn Forte 1950fcf3ce44SJohn Forte for (invalidInput = B_FALSE, i = 0; i < outerLoop; i++) { 1951fcf3ce44SJohn Forte if (operandEntered) { 1952fcf3ce44SJohn Forte if (strlen(operands[i]) != GUID_INPUT) { 1953fcf3ce44SJohn Forte invalidInput = B_TRUE; 1954fcf3ce44SJohn Forte } else { 1955fcf3ce44SJohn Forte for (j = 0; j < GUID_INPUT; j++) { 1956fcf3ce44SJohn Forte if (!isxdigit(operands[i][j])) { 1957fcf3ce44SJohn Forte invalidInput = B_TRUE; 1958fcf3ce44SJohn Forte break; 1959fcf3ce44SJohn Forte } 1960fcf3ce44SJohn Forte } 1961fcf3ce44SJohn Forte } 1962fcf3ce44SJohn Forte if (invalidInput) { 1963fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s%d%s\n", 1964fcf3ce44SJohn Forte cmdName, operands[i], gettext("must be "), 1965fcf3ce44SJohn Forte GUID_INPUT, 1966fcf3ce44SJohn Forte gettext(" hexadecimal digits long")); 19678fe96085Stim szeto invalidInput = B_FALSE; 1968fcf3ce44SJohn Forte continue; 1969fcf3ce44SJohn Forte } 1970fcf3ce44SJohn Forte 1971fcf3ce44SJohn Forte for (j = 0; j < GUID_INPUT; j++) { 1972fcf3ce44SJohn Forte sGuid[j] = tolower(operands[i][j]); 1973fcf3ce44SJohn Forte } 1974fcf3ce44SJohn Forte sGuid[j] = 0; 1975fcf3ce44SJohn Forte 1976fcf3ce44SJohn Forte (void) sscanf(sGuid, 1977fcf3ce44SJohn Forte "%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x", 1978fcf3ce44SJohn Forte &inGuid[0], &inGuid[1], &inGuid[2], &inGuid[3], 1979fcf3ce44SJohn Forte &inGuid[4], &inGuid[5], &inGuid[6], &inGuid[7], 1980fcf3ce44SJohn Forte &inGuid[8], &inGuid[9], &inGuid[10], &inGuid[11], 1981fcf3ce44SJohn Forte &inGuid[12], &inGuid[13], &inGuid[14], &inGuid[15]); 1982fcf3ce44SJohn Forte 1983fcf3ce44SJohn Forte for (j = 0; j < sizeof (stmfGuid); j++) { 1984fcf3ce44SJohn Forte cmpGuid.guid[j] = inGuid[j]; 1985fcf3ce44SJohn Forte } 1986fcf3ce44SJohn Forte } 1987fcf3ce44SJohn Forte 1988fcf3ce44SJohn Forte for (found = B_FALSE, j = 0; j < luList->cnt; j++) { 1989fcf3ce44SJohn Forte if (operandEntered) { 1990fcf3ce44SJohn Forte if (bcmp(luList->guid[j].guid, cmpGuid.guid, 1991fcf3ce44SJohn Forte sizeof (stmfGuid)) == 0) { 1992fcf3ce44SJohn Forte found = B_TRUE; 1993fcf3ce44SJohn Forte } 1994fcf3ce44SJohn Forte } 1995fcf3ce44SJohn Forte if ((found && operandEntered) || !operandEntered) { 1996fcf3ce44SJohn Forte (void) printf("LU Name: "); 1997fcf3ce44SJohn Forte printGuid(&luList->guid[j], stdout); 1998fcf3ce44SJohn Forte (void) printf("\n"); 1999fcf3ce44SJohn Forte 2000fcf3ce44SJohn Forte if (verbose) { 2001fcf3ce44SJohn Forte stmfRet = stmfGetLogicalUnitProperties( 2002fcf3ce44SJohn Forte &(luList->guid[j]), &luProps); 2003fcf3ce44SJohn Forte if (stmfRet == STMF_STATUS_SUCCESS) { 2004fcf3ce44SJohn Forte printLuProps(&luProps); 2005fcf3ce44SJohn Forte } else { 2006fcf3ce44SJohn Forte (void) fprintf(stderr, "%s:", 2007fcf3ce44SJohn Forte cmdName); 2008fcf3ce44SJohn Forte printGuid(&luList->guid[j], 2009fcf3ce44SJohn Forte stderr); 2010fcf3ce44SJohn Forte (void) fprintf(stderr, "%s\n", 2011fcf3ce44SJohn Forte gettext(" get properties " 2012fcf3ce44SJohn Forte "failed")); 2013fcf3ce44SJohn Forte } 2014fcf3ce44SJohn Forte stmfRet = stmfGetViewEntryList( 2015fcf3ce44SJohn Forte &(luList->guid[j]), 2016fcf3ce44SJohn Forte &viewEntryList); 2017fcf3ce44SJohn Forte (void) printf(PROPS_FORMAT, 2018fcf3ce44SJohn Forte "View Entry Count"); 2019fcf3ce44SJohn Forte if (stmfRet == STMF_STATUS_SUCCESS) { 2020fcf3ce44SJohn Forte (void) printf("%d", 2021fcf3ce44SJohn Forte viewEntryList->cnt); 2022fcf3ce44SJohn Forte } else { 2023fcf3ce44SJohn Forte (void) printf("unknown"); 2024fcf3ce44SJohn Forte } 2025fcf3ce44SJohn Forte (void) printf("\n"); 20268fe96085Stim szeto ret = printExtLuProps( 20278fe96085Stim szeto &(luList->guid[j])); 2028fcf3ce44SJohn Forte } 2029fcf3ce44SJohn Forte if (found && operandEntered) { 2030fcf3ce44SJohn Forte break; 2031fcf3ce44SJohn Forte } 2032fcf3ce44SJohn Forte } 2033fcf3ce44SJohn Forte 2034fcf3ce44SJohn Forte } 2035fcf3ce44SJohn Forte if (operandEntered && !found) { 2036fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 2037fcf3ce44SJohn Forte operands[i], gettext("not found")); 2038fcf3ce44SJohn Forte ret = 1; 2039fcf3ce44SJohn Forte } 2040fcf3ce44SJohn Forte } 2041fcf3ce44SJohn Forte 2042fcf3ce44SJohn Forte return (ret); 2043fcf3ce44SJohn Forte } 2044fcf3ce44SJohn Forte 2045fcf3ce44SJohn Forte static void 2046fcf3ce44SJohn Forte printGuid(stmfGuid *guid, FILE *stream) 2047fcf3ce44SJohn Forte { 2048fcf3ce44SJohn Forte int i; 2049fcf3ce44SJohn Forte for (i = 0; i < 16; i++) { 2050fcf3ce44SJohn Forte (void) fprintf(stream, "%02X", guid->guid[i]); 2051fcf3ce44SJohn Forte } 2052fcf3ce44SJohn Forte } 2053fcf3ce44SJohn Forte 20548fe96085Stim szeto static int 20558fe96085Stim szeto printExtLuProps(stmfGuid *guid) 20568fe96085Stim szeto { 20578fe96085Stim szeto int stmfRet; 20588fe96085Stim szeto luResource hdl = NULL; 20598fe96085Stim szeto int ret = 0; 20608fe96085Stim szeto char propVal[MAXNAMELEN]; 20618fe96085Stim szeto size_t propValSize = sizeof (propVal); 20628fe96085Stim szeto 20638fe96085Stim szeto if ((stmfRet = stmfGetLuResource(guid, &hdl)) 20648fe96085Stim szeto != STMF_STATUS_SUCCESS) { 20658fe96085Stim szeto switch (stmfRet) { 20668fe96085Stim szeto case STMF_ERROR_BUSY: 20678fe96085Stim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 20688fe96085Stim szeto gettext("resource busy")); 20698fe96085Stim szeto break; 20708fe96085Stim szeto case STMF_ERROR_PERM: 20718fe96085Stim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 20728fe96085Stim szeto gettext("permission denied")); 20738fe96085Stim szeto break; 20748fe96085Stim szeto case STMF_ERROR_NOT_FOUND: 20758fe96085Stim szeto /* No error here */ 20768fe96085Stim szeto return (0); 20778fe96085Stim szeto break; 20788fe96085Stim szeto default: 20798fe96085Stim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 20808fe96085Stim szeto gettext("get extended properties failed")); 20818fe96085Stim szeto break; 20828fe96085Stim szeto } 20838fe96085Stim szeto return (1); 20848fe96085Stim szeto } 20858fe96085Stim szeto 20868fe96085Stim szeto stmfRet = stmfGetLuProp(hdl, STMF_LU_PROP_FILENAME, propVal, 20878fe96085Stim szeto &propValSize); 20888fe96085Stim szeto (void) printf(PROPS_FORMAT, "Data File"); 20898fe96085Stim szeto if (stmfRet == STMF_STATUS_SUCCESS) { 20908fe96085Stim szeto (void) printf("%s\n", propVal); 20918fe96085Stim szeto } else if (stmfRet == STMF_ERROR_NO_PROP) { 20928fe96085Stim szeto (void) printf("not set\n"); 209345039663SJohn Forte } else if (stmfRet == STMF_ERROR_NO_PROP_STANDBY) { 209445039663SJohn Forte (void) printf("prop unavailable in standby\n"); 20958fe96085Stim szeto } else { 20968fe96085Stim szeto (void) printf("<error retrieving property>\n"); 20978fe96085Stim szeto ret++; 20988fe96085Stim szeto } 20998fe96085Stim szeto 21008fe96085Stim szeto stmfRet = stmfGetLuProp(hdl, STMF_LU_PROP_META_FILENAME, propVal, 21018fe96085Stim szeto &propValSize); 21028fe96085Stim szeto (void) printf(PROPS_FORMAT, "Meta File"); 21038fe96085Stim szeto if (stmfRet == STMF_STATUS_SUCCESS) { 21048fe96085Stim szeto (void) printf("%s\n", propVal); 21058fe96085Stim szeto } else if (stmfRet == STMF_ERROR_NO_PROP) { 21068fe96085Stim szeto (void) printf("not set\n"); 210745039663SJohn Forte } else if (stmfRet == STMF_ERROR_NO_PROP_STANDBY) { 210845039663SJohn Forte (void) printf("prop unavailable in standby\n"); 21098fe96085Stim szeto } else { 21108fe96085Stim szeto (void) printf("<error retrieving property>\n"); 21118fe96085Stim szeto ret++; 21128fe96085Stim szeto } 21138fe96085Stim szeto 21148fe96085Stim szeto stmfRet = stmfGetLuProp(hdl, STMF_LU_PROP_SIZE, propVal, 21158fe96085Stim szeto &propValSize); 21168fe96085Stim szeto (void) printf(PROPS_FORMAT, "Size"); 21178fe96085Stim szeto if (stmfRet == STMF_STATUS_SUCCESS) { 21188fe96085Stim szeto (void) printf("%s\n", propVal); 21198fe96085Stim szeto } else if (stmfRet == STMF_ERROR_NO_PROP) { 21208fe96085Stim szeto (void) printf("not set\n"); 212145039663SJohn Forte } else if (stmfRet == STMF_ERROR_NO_PROP_STANDBY) { 212245039663SJohn Forte (void) printf("prop unavailable in standby\n"); 21238fe96085Stim szeto } else { 21248fe96085Stim szeto (void) printf("<error retrieving property>\n"); 21258fe96085Stim szeto ret++; 21268fe96085Stim szeto } 21278fe96085Stim szeto 21288fe96085Stim szeto stmfRet = stmfGetLuProp(hdl, STMF_LU_PROP_BLOCK_SIZE, propVal, 21298fe96085Stim szeto &propValSize); 21308fe96085Stim szeto (void) printf(PROPS_FORMAT, "Block Size"); 21318fe96085Stim szeto if (stmfRet == STMF_STATUS_SUCCESS) { 21328fe96085Stim szeto (void) printf("%s\n", propVal); 21338fe96085Stim szeto } else if (stmfRet == STMF_ERROR_NO_PROP) { 21348fe96085Stim szeto (void) printf("not set\n"); 213545039663SJohn Forte } else if (stmfRet == STMF_ERROR_NO_PROP_STANDBY) { 213645039663SJohn Forte (void) printf("prop unavailable in standby\n"); 21378fe96085Stim szeto } else { 21388fe96085Stim szeto (void) printf("<error retrieving property>\n"); 21398fe96085Stim szeto ret++; 21408fe96085Stim szeto } 21418fe96085Stim szeto 21422f624233SNattuvetty Bhavyan stmfRet = stmfGetLuProp(hdl, STMF_LU_PROP_MGMT_URL, propVal, 21432f624233SNattuvetty Bhavyan &propValSize); 21442f624233SNattuvetty Bhavyan (void) printf(PROPS_FORMAT, "Management URL"); 21452f624233SNattuvetty Bhavyan if (stmfRet == STMF_STATUS_SUCCESS) { 21462f624233SNattuvetty Bhavyan (void) printf("%s\n", propVal); 21472f624233SNattuvetty Bhavyan } else if (stmfRet == STMF_ERROR_NO_PROP) { 21482f624233SNattuvetty Bhavyan (void) printf("not set\n"); 214945039663SJohn Forte } else if (stmfRet == STMF_ERROR_NO_PROP_STANDBY) { 215045039663SJohn Forte (void) printf("prop unavailable in standby\n"); 21512f624233SNattuvetty Bhavyan } else { 21522f624233SNattuvetty Bhavyan (void) printf("<error retrieving property>\n"); 21532f624233SNattuvetty Bhavyan ret++; 21542f624233SNattuvetty Bhavyan } 21552f624233SNattuvetty Bhavyan 21568fe96085Stim szeto stmfRet = stmfGetLuProp(hdl, STMF_LU_PROP_VID, propVal, 21578fe96085Stim szeto &propValSize); 21588fe96085Stim szeto (void) printf(PROPS_FORMAT, "Vendor ID"); 21598fe96085Stim szeto if (stmfRet == STMF_STATUS_SUCCESS) { 21608fe96085Stim szeto (void) printf("%s\n", propVal); 21618fe96085Stim szeto } else if (stmfRet == STMF_ERROR_NO_PROP) { 21628fe96085Stim szeto (void) printf("not set\n"); 216345039663SJohn Forte } else if (stmfRet == STMF_ERROR_NO_PROP_STANDBY) { 216445039663SJohn Forte (void) printf("prop unavailable in standby\n"); 21658fe96085Stim szeto } else { 21668fe96085Stim szeto (void) printf("<error retrieving property>\n"); 21678fe96085Stim szeto ret++; 21688fe96085Stim szeto } 21698fe96085Stim szeto 21708fe96085Stim szeto stmfRet = stmfGetLuProp(hdl, STMF_LU_PROP_PID, propVal, 21718fe96085Stim szeto &propValSize); 21728fe96085Stim szeto (void) printf(PROPS_FORMAT, "Product ID"); 21738fe96085Stim szeto if (stmfRet == STMF_STATUS_SUCCESS) { 21748fe96085Stim szeto (void) printf("%s\n", propVal); 21758fe96085Stim szeto } else if (stmfRet == STMF_ERROR_NO_PROP) { 21768fe96085Stim szeto (void) printf("not set\n"); 217745039663SJohn Forte } else if (stmfRet == STMF_ERROR_NO_PROP_STANDBY) { 217845039663SJohn Forte (void) printf("prop unavailable in standby\n"); 21798fe96085Stim szeto } else { 21808fe96085Stim szeto (void) printf("<error retrieving property>\n"); 21818fe96085Stim szeto ret++; 21828fe96085Stim szeto } 21838fe96085Stim szeto 21848fe96085Stim szeto stmfRet = stmfGetLuProp(hdl, STMF_LU_PROP_SERIAL_NUM, propVal, 21858fe96085Stim szeto &propValSize); 21868fe96085Stim szeto (void) printf(PROPS_FORMAT, "Serial Num"); 21878fe96085Stim szeto if (stmfRet == STMF_STATUS_SUCCESS) { 21888fe96085Stim szeto (void) printf("%s\n", propVal); 21898fe96085Stim szeto } else if (stmfRet == STMF_ERROR_NO_PROP) { 21908fe96085Stim szeto (void) printf("not set\n"); 219145039663SJohn Forte } else if (stmfRet == STMF_ERROR_NO_PROP_STANDBY) { 219245039663SJohn Forte (void) printf("prop unavailable in standby\n"); 21938fe96085Stim szeto } else { 21948fe96085Stim szeto (void) printf("<error retrieving property>\n"); 21958fe96085Stim szeto ret++; 21968fe96085Stim szeto } 21978fe96085Stim szeto 21988fe96085Stim szeto stmfRet = stmfGetLuProp(hdl, STMF_LU_PROP_WRITE_PROTECT, propVal, 21998fe96085Stim szeto &propValSize); 22008fe96085Stim szeto (void) printf(PROPS_FORMAT, "Write Protect"); 22018fe96085Stim szeto if (stmfRet == STMF_STATUS_SUCCESS) { 22028fe96085Stim szeto (void) printf("%s\n", 22038fe96085Stim szeto strcasecmp(propVal, "true") ? "Disabled" : "Enabled"); 22048fe96085Stim szeto } else if (stmfRet == STMF_ERROR_NO_PROP) { 22058fe96085Stim szeto (void) printf("not set\n"); 220645039663SJohn Forte } else if (stmfRet == STMF_ERROR_NO_PROP_STANDBY) { 220745039663SJohn Forte (void) printf("prop unavailable in standby\n"); 22088fe96085Stim szeto } else { 22098fe96085Stim szeto (void) printf("<error retrieving property>\n"); 22108fe96085Stim szeto ret++; 22118fe96085Stim szeto } 22128fe96085Stim szeto 22138fe96085Stim szeto stmfRet = stmfGetLuProp(hdl, STMF_LU_PROP_WRITE_CACHE_DISABLE, propVal, 22148fe96085Stim szeto &propValSize); 22158fe96085Stim szeto (void) printf(PROPS_FORMAT, "Writeback Cache"); 22168fe96085Stim szeto if (stmfRet == STMF_STATUS_SUCCESS) { 22178fe96085Stim szeto (void) printf("%s\n", 22188fe96085Stim szeto strcasecmp(propVal, "true") ? "Enabled" : "Disabled"); 22198fe96085Stim szeto } else if (stmfRet == STMF_ERROR_NO_PROP) { 22208fe96085Stim szeto (void) printf("not set\n"); 222145039663SJohn Forte } else if (stmfRet == STMF_ERROR_NO_PROP_STANDBY) { 222245039663SJohn Forte (void) printf("prop unavailable in standby\n"); 22238fe96085Stim szeto } else { 22248fe96085Stim szeto (void) printf("<error retrieving property>\n"); 22258fe96085Stim szeto ret++; 22268fe96085Stim szeto } 22278fe96085Stim szeto 222845039663SJohn Forte stmfRet = stmfGetLuProp(hdl, STMF_LU_PROP_ACCESS_STATE, propVal, 222945039663SJohn Forte &propValSize); 223045039663SJohn Forte (void) printf(PROPS_FORMAT, "Access State"); 223145039663SJohn Forte if (stmfRet == STMF_STATUS_SUCCESS) { 223245039663SJohn Forte if (strcmp(propVal, STMF_ACCESS_ACTIVE) == 0) { 223345039663SJohn Forte (void) printf("%s\n", "Active"); 223445039663SJohn Forte } else if (strcmp(propVal, 223545039663SJohn Forte STMF_ACCESS_ACTIVE_TO_STANDBY) == 0) { 223645039663SJohn Forte (void) printf("%s\n", "Active->Standby"); 223745039663SJohn Forte } else if (strcmp(propVal, STMF_ACCESS_STANDBY) == 0) { 223845039663SJohn Forte (void) printf("%s\n", "Standby"); 223945039663SJohn Forte } else if (strcmp(propVal, 224045039663SJohn Forte STMF_ACCESS_STANDBY_TO_ACTIVE) == 0) { 224145039663SJohn Forte (void) printf("%s\n", "Standby->Active"); 224245039663SJohn Forte } else { 224345039663SJohn Forte (void) printf("%s\n", "Unknown"); 224445039663SJohn Forte } 224545039663SJohn Forte } else if (stmfRet == STMF_ERROR_NO_PROP) { 224645039663SJohn Forte (void) printf("not set\n"); 224745039663SJohn Forte } else { 224845039663SJohn Forte (void) printf("<error retrieving property>\n"); 224945039663SJohn Forte ret++; 225045039663SJohn Forte } 22518fe96085Stim szeto 225245039663SJohn Forte done: 22538fe96085Stim szeto (void) stmfFreeLuResource(hdl); 22548fe96085Stim szeto return (ret); 22558fe96085Stim szeto 22568fe96085Stim szeto } 22578fe96085Stim szeto 2258fcf3ce44SJohn Forte 2259fcf3ce44SJohn Forte /* 2260fcf3ce44SJohn Forte * printLuProps 2261fcf3ce44SJohn Forte * 2262fcf3ce44SJohn Forte * Prints the properties for a logical unit 2263fcf3ce44SJohn Forte * 2264fcf3ce44SJohn Forte */ 2265fcf3ce44SJohn Forte static void 2266fcf3ce44SJohn Forte printLuProps(stmfLogicalUnitProperties *luProps) 2267fcf3ce44SJohn Forte { 2268fcf3ce44SJohn Forte (void) printf(PROPS_FORMAT, "Operational Status"); 2269fcf3ce44SJohn Forte switch (luProps->status) { 2270fcf3ce44SJohn Forte case STMF_LOGICAL_UNIT_ONLINE: 2271fcf3ce44SJohn Forte (void) printf("Online"); 2272fcf3ce44SJohn Forte break; 2273fcf3ce44SJohn Forte case STMF_LOGICAL_UNIT_OFFLINE: 2274fcf3ce44SJohn Forte (void) printf("Offline"); 2275fcf3ce44SJohn Forte break; 2276fcf3ce44SJohn Forte case STMF_LOGICAL_UNIT_ONLINING: 2277fcf3ce44SJohn Forte (void) printf("Onlining"); 2278fcf3ce44SJohn Forte break; 2279fcf3ce44SJohn Forte case STMF_LOGICAL_UNIT_OFFLINING: 2280fcf3ce44SJohn Forte (void) printf("Offlining"); 2281fcf3ce44SJohn Forte break; 2282fcf3ce44SJohn Forte case STMF_LOGICAL_UNIT_UNREGISTERED: 2283fcf3ce44SJohn Forte (void) printf("unregistered"); 2284fcf3ce44SJohn Forte (void) strncpy(luProps->providerName, "unregistered", 2285fcf3ce44SJohn Forte sizeof (luProps->providerName)); 2286fcf3ce44SJohn Forte break; 2287fcf3ce44SJohn Forte default: 2288fcf3ce44SJohn Forte (void) printf("unknown"); 2289fcf3ce44SJohn Forte break; 2290fcf3ce44SJohn Forte } 2291fcf3ce44SJohn Forte (void) printf("\n"); 2292fcf3ce44SJohn Forte (void) printf(PROPS_FORMAT, "Provider Name"); 2293fcf3ce44SJohn Forte if (luProps->providerName[0] != 0) { 2294fcf3ce44SJohn Forte (void) printf("%s", luProps->providerName); 2295fcf3ce44SJohn Forte } else { 2296fcf3ce44SJohn Forte (void) printf("unknown"); 2297fcf3ce44SJohn Forte } 2298fcf3ce44SJohn Forte (void) printf("\n"); 2299fcf3ce44SJohn Forte (void) printf(PROPS_FORMAT, "Alias"); 2300fcf3ce44SJohn Forte if (luProps->alias[0] != 0) { 2301fcf3ce44SJohn Forte (void) printf("%s", luProps->alias); 2302fcf3ce44SJohn Forte } else { 2303fcf3ce44SJohn Forte (void) printf("-"); 2304fcf3ce44SJohn Forte } 2305fcf3ce44SJohn Forte (void) printf("\n"); 2306fcf3ce44SJohn Forte } 2307fcf3ce44SJohn Forte 2308fcf3ce44SJohn Forte /* 2309fcf3ce44SJohn Forte * printTargetProps 2310fcf3ce44SJohn Forte * 2311fcf3ce44SJohn Forte * Prints the properties for a target 2312fcf3ce44SJohn Forte * 2313fcf3ce44SJohn Forte */ 2314fcf3ce44SJohn Forte static void 2315fcf3ce44SJohn Forte printTargetProps(stmfTargetProperties *targetProps) 2316fcf3ce44SJohn Forte { 2317fcf3ce44SJohn Forte (void) printf(PROPS_FORMAT, "Operational Status"); 2318fcf3ce44SJohn Forte switch (targetProps->status) { 2319fcf3ce44SJohn Forte case STMF_TARGET_PORT_ONLINE: 2320fcf3ce44SJohn Forte (void) printf("Online"); 2321fcf3ce44SJohn Forte break; 2322fcf3ce44SJohn Forte case STMF_TARGET_PORT_OFFLINE: 2323fcf3ce44SJohn Forte (void) printf("Offline"); 2324fcf3ce44SJohn Forte break; 2325fcf3ce44SJohn Forte case STMF_TARGET_PORT_ONLINING: 2326fcf3ce44SJohn Forte (void) printf("Onlining"); 2327fcf3ce44SJohn Forte break; 2328fcf3ce44SJohn Forte case STMF_TARGET_PORT_OFFLINING: 2329fcf3ce44SJohn Forte (void) printf("Offlining"); 2330fcf3ce44SJohn Forte break; 2331fcf3ce44SJohn Forte default: 2332fcf3ce44SJohn Forte (void) printf("unknown"); 2333fcf3ce44SJohn Forte break; 2334fcf3ce44SJohn Forte } 2335fcf3ce44SJohn Forte (void) printf("\n"); 2336fcf3ce44SJohn Forte (void) printf(PROPS_FORMAT, "Provider Name"); 2337fcf3ce44SJohn Forte if (targetProps->providerName[0] != 0) { 2338fcf3ce44SJohn Forte (void) printf("%s", targetProps->providerName); 2339fcf3ce44SJohn Forte } 2340fcf3ce44SJohn Forte (void) printf("\n"); 2341fcf3ce44SJohn Forte (void) printf(PROPS_FORMAT, "Alias"); 2342fcf3ce44SJohn Forte if (targetProps->alias[0] != 0) { 2343fcf3ce44SJohn Forte (void) printf("%s", targetProps->alias); 2344fcf3ce44SJohn Forte } else { 2345fcf3ce44SJohn Forte (void) printf("-"); 2346fcf3ce44SJohn Forte } 2347fcf3ce44SJohn Forte (void) printf("\n"); 234845039663SJohn Forte (void) printf(PROPS_FORMAT, "Protocol"); 234945039663SJohn Forte switch (targetProps->protocol) { 235045039663SJohn Forte case STMF_PROTOCOL_FIBRE_CHANNEL: 235145039663SJohn Forte (void) printf("%s", "Fibre Channel"); 235245039663SJohn Forte break; 235345039663SJohn Forte case STMF_PROTOCOL_ISCSI: 235445039663SJohn Forte (void) printf("%s", "iSCSI"); 235545039663SJohn Forte break; 235645039663SJohn Forte case STMF_PROTOCOL_SRP: 235745039663SJohn Forte (void) printf("%s", "SRP"); 235845039663SJohn Forte break; 235945039663SJohn Forte case STMF_PROTOCOL_SAS: 236045039663SJohn Forte (void) printf("%s", "SAS"); 236145039663SJohn Forte break; 236245039663SJohn Forte default: 236345039663SJohn Forte (void) printf("%s", "unknown"); 236445039663SJohn Forte break; 236545039663SJohn Forte } 236645039663SJohn Forte 236745039663SJohn Forte (void) printf("\n"); 2368fcf3ce44SJohn Forte } 2369fcf3ce44SJohn Forte 2370fcf3ce44SJohn Forte /* 2371fcf3ce44SJohn Forte * printSessionProps 2372fcf3ce44SJohn Forte * 2373fcf3ce44SJohn Forte * Prints the session data 2374fcf3ce44SJohn Forte * 2375fcf3ce44SJohn Forte */ 2376fcf3ce44SJohn Forte static void 2377fcf3ce44SJohn Forte printSessionProps(stmfSessionList *sessionList) 2378fcf3ce44SJohn Forte { 2379fcf3ce44SJohn Forte int i; 2380fcf3ce44SJohn Forte char *cTime; 2381fcf3ce44SJohn Forte wchar_t initiator[STMF_IDENT_LENGTH + 1]; 2382fcf3ce44SJohn Forte 2383fcf3ce44SJohn Forte (void) printf(PROPS_FORMAT, "Sessions"); 2384fcf3ce44SJohn Forte (void) printf("%d\n", sessionList->cnt); 2385fcf3ce44SJohn Forte for (i = 0; i < sessionList->cnt; i++) { 2386fcf3ce44SJohn Forte (void) mbstowcs(initiator, 2387fcf3ce44SJohn Forte (char *)sessionList->session[i].initiator.ident, 23883e7352aeSJohn Forte STMF_IDENT_LENGTH); 23893e7352aeSJohn Forte initiator[STMF_IDENT_LENGTH] = 0; 2390fcf3ce44SJohn Forte (void) printf(LVL3_FORMAT, "Initiator: "); 2391fcf3ce44SJohn Forte (void) printf("%ws\n", initiator); 2392fcf3ce44SJohn Forte (void) printf(LVL4_FORMAT, "Alias: "); 2393fcf3ce44SJohn Forte if (sessionList->session[i].alias[0] != 0) { 2394fcf3ce44SJohn Forte (void) printf("%s", sessionList->session[i].alias); 2395fcf3ce44SJohn Forte } else { 2396fcf3ce44SJohn Forte (void) printf("-"); 2397fcf3ce44SJohn Forte } 2398fcf3ce44SJohn Forte (void) printf("\n"); 2399fcf3ce44SJohn Forte (void) printf(LVL4_FORMAT, "Logged in since: "); 2400fcf3ce44SJohn Forte cTime = ctime(&(sessionList->session[i].creationTime)); 2401fcf3ce44SJohn Forte if (cTime != NULL) { 2402fcf3ce44SJohn Forte (void) printf("%s", cTime); 2403fcf3ce44SJohn Forte } else { 2404fcf3ce44SJohn Forte (void) printf("unknown\n"); 2405fcf3ce44SJohn Forte } 2406fcf3ce44SJohn Forte } 2407fcf3ce44SJohn Forte } 2408fcf3ce44SJohn Forte 2409e17f3b22Stim szeto static int 2410e17f3b22Stim szeto getStmfState(stmfState *state) 2411e17f3b22Stim szeto { 2412e17f3b22Stim szeto int ret; 2413e17f3b22Stim szeto 2414e17f3b22Stim szeto ret = stmfGetState(state); 2415e17f3b22Stim szeto switch (ret) { 2416e17f3b22Stim szeto case STMF_STATUS_SUCCESS: 2417e17f3b22Stim szeto break; 2418e17f3b22Stim szeto case STMF_ERROR_PERM: 2419e17f3b22Stim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 2420e17f3b22Stim szeto gettext("permission denied")); 2421e17f3b22Stim szeto break; 2422e17f3b22Stim szeto case STMF_ERROR_SERVICE_NOT_FOUND: 2423e17f3b22Stim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 2424e17f3b22Stim szeto gettext("STMF service not found")); 2425e17f3b22Stim szeto break; 2426e17f3b22Stim szeto case STMF_ERROR_BUSY: 2427e17f3b22Stim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 2428e17f3b22Stim szeto gettext("resource busy")); 2429e17f3b22Stim szeto break; 2430e17f3b22Stim szeto case STMF_ERROR_SERVICE_DATA_VERSION: 2431e17f3b22Stim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 2432e17f3b22Stim szeto gettext("STMF service version incorrect")); 2433e17f3b22Stim szeto break; 2434e17f3b22Stim szeto default: 24358fe96085Stim szeto (void) fprintf(stderr, "%s: %s: %d\n", cmdName, 24368fe96085Stim szeto gettext("unknown error"), ret); 2437e17f3b22Stim szeto break; 2438e17f3b22Stim szeto } 2439e17f3b22Stim szeto return (ret); 2440e17f3b22Stim szeto } 2441e17f3b22Stim szeto 2442fcf3ce44SJohn Forte /* 2443fcf3ce44SJohn Forte * listStateFunc 2444fcf3ce44SJohn Forte * 2445fcf3ce44SJohn Forte * List the operational and config state of the stmf service 2446fcf3ce44SJohn Forte * 2447fcf3ce44SJohn Forte */ 2448fcf3ce44SJohn Forte /*ARGSUSED*/ 2449fcf3ce44SJohn Forte static int 2450fcf3ce44SJohn Forte listStateFunc(int operandLen, char *operands[], cmdOptions_t *options, 2451fcf3ce44SJohn Forte void *args) 2452fcf3ce44SJohn Forte { 2453fcf3ce44SJohn Forte int ret; 2454fcf3ce44SJohn Forte stmfState state; 245545039663SJohn Forte boolean_t aluaEnabled; 245645039663SJohn Forte uint32_t node; 2457fcf3ce44SJohn Forte 2458e17f3b22Stim szeto if ((ret = getStmfState(&state)) != STMF_STATUS_SUCCESS) 2459e17f3b22Stim szeto return (ret); 2460fcf3ce44SJohn Forte 2461fcf3ce44SJohn Forte (void) printf("%-18s: ", "Operational Status"); 2462fcf3ce44SJohn Forte switch (state.operationalState) { 2463fcf3ce44SJohn Forte case STMF_SERVICE_STATE_ONLINE: 2464fcf3ce44SJohn Forte (void) printf("online"); 2465fcf3ce44SJohn Forte break; 2466fcf3ce44SJohn Forte case STMF_SERVICE_STATE_OFFLINE: 2467fcf3ce44SJohn Forte (void) printf("offline"); 2468fcf3ce44SJohn Forte break; 2469fcf3ce44SJohn Forte case STMF_SERVICE_STATE_ONLINING: 2470fcf3ce44SJohn Forte (void) printf("onlining"); 2471fcf3ce44SJohn Forte break; 2472fcf3ce44SJohn Forte case STMF_SERVICE_STATE_OFFLINING: 2473fcf3ce44SJohn Forte (void) printf("offlining"); 2474fcf3ce44SJohn Forte break; 2475fcf3ce44SJohn Forte default: 2476fcf3ce44SJohn Forte (void) printf("unknown"); 2477fcf3ce44SJohn Forte break; 2478fcf3ce44SJohn Forte } 2479fcf3ce44SJohn Forte (void) printf("\n"); 2480fcf3ce44SJohn Forte (void) printf("%-18s: ", "Config Status"); 2481fcf3ce44SJohn Forte switch (state.configState) { 2482fcf3ce44SJohn Forte case STMF_CONFIG_STATE_NONE: 2483fcf3ce44SJohn Forte (void) printf("uninitialized"); 2484fcf3ce44SJohn Forte break; 2485fcf3ce44SJohn Forte case STMF_CONFIG_STATE_INIT: 2486fcf3ce44SJohn Forte (void) printf("initializing"); 2487fcf3ce44SJohn Forte break; 2488fcf3ce44SJohn Forte case STMF_CONFIG_STATE_INIT_DONE: 2489fcf3ce44SJohn Forte (void) printf("initialized"); 2490fcf3ce44SJohn Forte break; 2491fcf3ce44SJohn Forte default: 2492fcf3ce44SJohn Forte (void) printf("unknown"); 2493fcf3ce44SJohn Forte break; 2494fcf3ce44SJohn Forte } 2495fcf3ce44SJohn Forte (void) printf("\n"); 249645039663SJohn Forte ret = stmfGetAluaState(&aluaEnabled, &node); 249745039663SJohn Forte switch (ret) { 249845039663SJohn Forte case STMF_STATUS_SUCCESS: 249945039663SJohn Forte break; 250045039663SJohn Forte case STMF_ERROR_PERM: 250145039663SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 250245039663SJohn Forte gettext("permission denied")); 250345039663SJohn Forte break; 250445039663SJohn Forte case STMF_ERROR_BUSY: 250545039663SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 250645039663SJohn Forte gettext("resource busy")); 250745039663SJohn Forte break; 250845039663SJohn Forte default: 250945039663SJohn Forte (void) fprintf(stderr, "%s: %s: %d\n", cmdName, 251045039663SJohn Forte gettext("unknown error"), ret); 251145039663SJohn Forte break; 251245039663SJohn Forte } 251345039663SJohn Forte (void) printf("%-18s: ", "ALUA Status"); 251445039663SJohn Forte if (ret == STMF_STATUS_SUCCESS) { 251545039663SJohn Forte if (aluaEnabled == B_TRUE) { 251645039663SJohn Forte (void) printf("enabled"); 251745039663SJohn Forte } else { 251845039663SJohn Forte (void) printf("disabled"); 251945039663SJohn Forte } 252045039663SJohn Forte } else { 252145039663SJohn Forte (void) printf("unknown"); 252245039663SJohn Forte } 252345039663SJohn Forte 252445039663SJohn Forte (void) printf("\n"); 252545039663SJohn Forte (void) printf("%-18s: ", "ALUA Node"); 252645039663SJohn Forte if (ret == STMF_STATUS_SUCCESS) { 252745039663SJohn Forte (void) printf("%d", node); 252845039663SJohn Forte } else { 252945039663SJohn Forte (void) printf("unknown"); 253045039663SJohn Forte } 253145039663SJohn Forte (void) printf("\n"); 253245039663SJohn Forte return (ret); 2533fcf3ce44SJohn Forte } 2534fcf3ce44SJohn Forte 2535fcf3ce44SJohn Forte /* 2536fcf3ce44SJohn Forte * listTargetFunc 2537fcf3ce44SJohn Forte * 2538fcf3ce44SJohn Forte * list the targets and optionally their properties 2539fcf3ce44SJohn Forte * 2540fcf3ce44SJohn Forte */ 2541fcf3ce44SJohn Forte /*ARGSUSED*/ 2542fcf3ce44SJohn Forte static int 2543fcf3ce44SJohn Forte listTargetFunc(int operandLen, char *operands[], cmdOptions_t *options, 2544fcf3ce44SJohn Forte void *args) 2545fcf3ce44SJohn Forte { 2546fcf3ce44SJohn Forte cmdOptions_t *optionList = options; 2547fcf3ce44SJohn Forte int ret = 0; 2548fcf3ce44SJohn Forte int stmfRet; 2549fcf3ce44SJohn Forte int i, j; 2550fcf3ce44SJohn Forte int outerLoop; 2551fcf3ce44SJohn Forte stmfSessionList *sessionList; 2552fcf3ce44SJohn Forte stmfDevid devid; 2553fcf3ce44SJohn Forte boolean_t operandEntered, found, verbose = B_FALSE; 2554fcf3ce44SJohn Forte stmfDevidList *targetList; 2555fcf3ce44SJohn Forte wchar_t targetIdent[STMF_IDENT_LENGTH + 1]; 2556fcf3ce44SJohn Forte stmfTargetProperties targetProps; 2557fcf3ce44SJohn Forte 2558fcf3ce44SJohn Forte if ((stmfRet = stmfGetTargetList(&targetList)) != STMF_STATUS_SUCCESS) { 2559fcf3ce44SJohn Forte switch (stmfRet) { 2560fcf3ce44SJohn Forte case STMF_ERROR_NOT_FOUND: 2561fcf3ce44SJohn Forte ret = 0; 2562fcf3ce44SJohn Forte break; 2563fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_OFFLINE: 2564fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 2565fcf3ce44SJohn Forte gettext("STMF service offline")); 2566fcf3ce44SJohn Forte break; 2567fcf3ce44SJohn Forte case STMF_ERROR_BUSY: 2568fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 2569fcf3ce44SJohn Forte gettext("resource busy")); 2570fcf3ce44SJohn Forte break; 2571fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_DATA_VERSION: 2572fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 2573fcf3ce44SJohn Forte gettext("STMF service version incorrect")); 2574fcf3ce44SJohn Forte break; 2575fcf3ce44SJohn Forte case STMF_ERROR_PERM: 2576fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 2577fcf3ce44SJohn Forte gettext("permission denied")); 2578fcf3ce44SJohn Forte break; 2579fcf3ce44SJohn Forte default: 2580fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 2581fcf3ce44SJohn Forte gettext("unknown error")); 2582fcf3ce44SJohn Forte break; 2583fcf3ce44SJohn Forte } 2584fcf3ce44SJohn Forte return (1); 2585fcf3ce44SJohn Forte } 2586fcf3ce44SJohn Forte 2587fcf3ce44SJohn Forte for (; optionList->optval; optionList++) { 2588fcf3ce44SJohn Forte switch (optionList->optval) { 2589fcf3ce44SJohn Forte case 'v': 2590fcf3ce44SJohn Forte verbose = B_TRUE; 2591fcf3ce44SJohn Forte break; 2592fcf3ce44SJohn Forte } 2593fcf3ce44SJohn Forte } 2594fcf3ce44SJohn Forte 2595fcf3ce44SJohn Forte if (operandLen > 0) { 2596fcf3ce44SJohn Forte outerLoop = operandLen; 2597fcf3ce44SJohn Forte operandEntered = B_TRUE; 2598fcf3ce44SJohn Forte } else { 2599fcf3ce44SJohn Forte outerLoop = 1; 2600fcf3ce44SJohn Forte operandEntered = B_FALSE; 2601fcf3ce44SJohn Forte } 2602fcf3ce44SJohn Forte 2603fcf3ce44SJohn Forte for (i = 0; i < outerLoop; i++) { 2604fcf3ce44SJohn Forte if (operandEntered) { 2605fcf3ce44SJohn Forte bzero(&devid, sizeof (devid)); 2606fcf3ce44SJohn Forte (void) parseDevid(operands[i], &devid); 2607fcf3ce44SJohn Forte } 2608fcf3ce44SJohn Forte for (found = B_FALSE, j = 0; j < targetList->cnt; j++) { 2609fcf3ce44SJohn Forte if (operandEntered) { 2610fcf3ce44SJohn Forte if (bcmp(&devid, &(targetList->devid[j]), 2611fcf3ce44SJohn Forte sizeof (devid)) == 0) { 2612fcf3ce44SJohn Forte found = B_TRUE; 2613fcf3ce44SJohn Forte } 2614fcf3ce44SJohn Forte } 2615fcf3ce44SJohn Forte if ((found && operandEntered) || !operandEntered) { 2616fcf3ce44SJohn Forte (void) mbstowcs(targetIdent, 2617fcf3ce44SJohn Forte (char *)targetList->devid[j].ident, 26183e7352aeSJohn Forte STMF_IDENT_LENGTH); 26193e7352aeSJohn Forte targetIdent[STMF_IDENT_LENGTH] = 0; 2620fcf3ce44SJohn Forte (void) printf("Target: %ws\n", targetIdent); 2621fcf3ce44SJohn Forte if (verbose) { 2622fcf3ce44SJohn Forte stmfRet = stmfGetTargetProperties( 2623fcf3ce44SJohn Forte &(targetList->devid[j]), 2624fcf3ce44SJohn Forte &targetProps); 2625fcf3ce44SJohn Forte if (stmfRet == STMF_STATUS_SUCCESS) { 2626fcf3ce44SJohn Forte printTargetProps(&targetProps); 2627fcf3ce44SJohn Forte } else { 2628fcf3ce44SJohn Forte (void) fprintf(stderr, "%s:", 2629fcf3ce44SJohn Forte cmdName); 2630fcf3ce44SJohn Forte (void) fprintf(stderr, "%s\n", 2631fcf3ce44SJohn Forte gettext(" get properties" 2632fcf3ce44SJohn Forte " failed")); 2633fcf3ce44SJohn Forte } 2634fcf3ce44SJohn Forte stmfRet = stmfGetSessionList( 2635fcf3ce44SJohn Forte &(targetList->devid[j]), 2636fcf3ce44SJohn Forte &sessionList); 2637fcf3ce44SJohn Forte if (stmfRet == STMF_STATUS_SUCCESS) { 2638fcf3ce44SJohn Forte printSessionProps(sessionList); 2639fcf3ce44SJohn Forte } else { 2640fcf3ce44SJohn Forte (void) fprintf(stderr, "%s:", 2641fcf3ce44SJohn Forte cmdName); 2642fcf3ce44SJohn Forte (void) fprintf(stderr, "%s\n", 2643fcf3ce44SJohn Forte gettext(" get session info" 2644fcf3ce44SJohn Forte " failed")); 2645fcf3ce44SJohn Forte } 2646fcf3ce44SJohn Forte } 2647fcf3ce44SJohn Forte if (found && operandEntered) { 2648fcf3ce44SJohn Forte break; 2649fcf3ce44SJohn Forte } 2650fcf3ce44SJohn Forte } 2651fcf3ce44SJohn Forte 2652fcf3ce44SJohn Forte } 2653fcf3ce44SJohn Forte if (operandEntered && !found) { 2654fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 2655fcf3ce44SJohn Forte operands[i], "not found"); 2656fcf3ce44SJohn Forte ret = 1; 2657fcf3ce44SJohn Forte } 2658fcf3ce44SJohn Forte } 2659fcf3ce44SJohn Forte return (ret); 2660fcf3ce44SJohn Forte } 2661fcf3ce44SJohn Forte 2662fcf3ce44SJohn Forte /* 2663fcf3ce44SJohn Forte * listViewFunc 2664fcf3ce44SJohn Forte * 2665fcf3ce44SJohn Forte * list the view entries for the specified logical unit 2666fcf3ce44SJohn Forte * 2667fcf3ce44SJohn Forte */ 2668fcf3ce44SJohn Forte /*ARGSUSED*/ 2669fcf3ce44SJohn Forte static int 2670fcf3ce44SJohn Forte listViewFunc(int operandLen, char *operands[], cmdOptions_t *options, 2671fcf3ce44SJohn Forte void *args) 2672fcf3ce44SJohn Forte { 2673fcf3ce44SJohn Forte stmfViewEntryList *viewEntryList; 2674fcf3ce44SJohn Forte stmfGuid inGuid; 2675fcf3ce44SJohn Forte unsigned int guid[sizeof (stmfGuid)]; 2676fcf3ce44SJohn Forte int ret = 0; 2677fcf3ce44SJohn Forte int stmfRet; 2678fcf3ce44SJohn Forte int i, j, outerLoop; 2679fcf3ce44SJohn Forte boolean_t found = B_TRUE; 2680fcf3ce44SJohn Forte boolean_t operandEntered; 2681fcf3ce44SJohn Forte uint16_t outputLuNbr; 2682fcf3ce44SJohn Forte wchar_t groupName[sizeof (stmfGroupName)]; 2683fcf3ce44SJohn Forte char sGuid[GUID_INPUT + 1]; 2684fcf3ce44SJohn Forte 2685fcf3ce44SJohn Forte 2686fcf3ce44SJohn Forte for (; options->optval; options++) { 2687fcf3ce44SJohn Forte switch (options->optval) { 2688fcf3ce44SJohn Forte case 'l': 2689fcf3ce44SJohn Forte if (strlen(options->optarg) != GUID_INPUT) { 2690fcf3ce44SJohn Forte (void) fprintf(stderr, 2691fcf3ce44SJohn Forte "%s: %s: %s%d%s\n", 2692fcf3ce44SJohn Forte cmdName, options->optarg, 2693fcf3ce44SJohn Forte gettext("must be "), GUID_INPUT, 2694fcf3ce44SJohn Forte gettext(" hexadecimal digits" 2695fcf3ce44SJohn Forte " long")); 2696fcf3ce44SJohn Forte return (1); 2697fcf3ce44SJohn Forte } 2698fcf3ce44SJohn Forte bcopy(options->optarg, sGuid, GUID_INPUT); 2699fcf3ce44SJohn Forte break; 2700fcf3ce44SJohn Forte default: 2701fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %c: %s\n", 2702fcf3ce44SJohn Forte cmdName, options->optval, 2703fcf3ce44SJohn Forte gettext("unknown option")); 2704fcf3ce44SJohn Forte return (1); 2705fcf3ce44SJohn Forte } 2706fcf3ce44SJohn Forte } 2707fcf3ce44SJohn Forte 2708fcf3ce44SJohn Forte if (operandLen > 0) { 2709fcf3ce44SJohn Forte outerLoop = operandLen; 2710fcf3ce44SJohn Forte operandEntered = B_TRUE; 2711fcf3ce44SJohn Forte } else { 2712fcf3ce44SJohn Forte outerLoop = 1; 2713fcf3ce44SJohn Forte operandEntered = B_FALSE; 2714fcf3ce44SJohn Forte } 2715fcf3ce44SJohn Forte 2716fcf3ce44SJohn Forte for (i = 0; i < 32; i++) 2717fcf3ce44SJohn Forte sGuid[i] = tolower(sGuid[i]); 2718fcf3ce44SJohn Forte sGuid[i] = 0; 2719fcf3ce44SJohn Forte 2720fcf3ce44SJohn Forte (void) sscanf(sGuid, "%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x", 2721fcf3ce44SJohn Forte &guid[0], &guid[1], &guid[2], &guid[3], &guid[4], &guid[5], 2722fcf3ce44SJohn Forte &guid[6], &guid[7], &guid[8], &guid[9], &guid[10], &guid[11], 2723fcf3ce44SJohn Forte &guid[12], &guid[13], &guid[14], &guid[15]); 2724fcf3ce44SJohn Forte 2725fcf3ce44SJohn Forte for (i = 0; i < sizeof (stmfGuid); i++) { 2726fcf3ce44SJohn Forte inGuid.guid[i] = guid[i]; 2727fcf3ce44SJohn Forte } 2728fcf3ce44SJohn Forte 2729fcf3ce44SJohn Forte if ((stmfRet = stmfGetViewEntryList(&inGuid, &viewEntryList)) 2730fcf3ce44SJohn Forte != STMF_STATUS_SUCCESS) { 2731fcf3ce44SJohn Forte 2732fcf3ce44SJohn Forte switch (stmfRet) { 2733fcf3ce44SJohn Forte case STMF_ERROR_BUSY: 2734fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 2735fcf3ce44SJohn Forte sGuid, gettext("resource busy")); 2736fcf3ce44SJohn Forte break; 2737fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_NOT_FOUND: 2738fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 2739fcf3ce44SJohn Forte gettext("STMF service not found")); 2740fcf3ce44SJohn Forte break; 2741fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_DATA_VERSION: 2742fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 2743fcf3ce44SJohn Forte gettext("STMF service version incorrect")); 2744fcf3ce44SJohn Forte break; 2745fcf3ce44SJohn Forte case STMF_ERROR_PERM: 2746fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 2747fcf3ce44SJohn Forte gettext("permission denied")); 2748fcf3ce44SJohn Forte break; 2749fcf3ce44SJohn Forte default: 2750fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 2751fcf3ce44SJohn Forte sGuid, gettext("unknown error")); 2752fcf3ce44SJohn Forte break; 2753fcf3ce44SJohn Forte } 2754fcf3ce44SJohn Forte return (1); 2755fcf3ce44SJohn Forte } 2756fcf3ce44SJohn Forte 27577b506e25Ssrivijitha dugganapalli if (viewEntryList->cnt == 0) { 27587b506e25Ssrivijitha dugganapalli (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 27597b506e25Ssrivijitha dugganapalli sGuid, gettext("no views found")); 27607b506e25Ssrivijitha dugganapalli return (1); 27617b506e25Ssrivijitha dugganapalli } 27627b506e25Ssrivijitha dugganapalli 2763fcf3ce44SJohn Forte for (i = 0; i < outerLoop; i++) { 2764fcf3ce44SJohn Forte for (found = B_FALSE, j = 0; j < viewEntryList->cnt; j++) { 2765fcf3ce44SJohn Forte if (operandEntered) { 2766fcf3ce44SJohn Forte if (atoi(operands[i]) == 2767fcf3ce44SJohn Forte viewEntryList->ve[j].veIndex) { 2768fcf3ce44SJohn Forte found = B_TRUE; 2769fcf3ce44SJohn Forte } 2770fcf3ce44SJohn Forte } 2771fcf3ce44SJohn Forte if ((found && operandEntered) || !operandEntered) { 2772fcf3ce44SJohn Forte (void) printf("View Entry: %d\n", 2773fcf3ce44SJohn Forte viewEntryList->ve[j].veIndex); 2774fcf3ce44SJohn Forte (void) printf(VIEW_FORMAT, "Host group"); 2775fcf3ce44SJohn Forte if (viewEntryList->ve[j].allHosts) { 2776fcf3ce44SJohn Forte (void) printf("All\n"); 2777fcf3ce44SJohn Forte } else { 2778fcf3ce44SJohn Forte (void) mbstowcs(groupName, 2779fcf3ce44SJohn Forte viewEntryList->ve[j].hostGroup, 27803e7352aeSJohn Forte sizeof (stmfGroupName) - 1); 27813e7352aeSJohn Forte groupName[sizeof (stmfGroupName) - 1] 27823e7352aeSJohn Forte = 0; 2783fcf3ce44SJohn Forte (void) printf("%ws\n", groupName); 2784fcf3ce44SJohn Forte } 2785fcf3ce44SJohn Forte (void) printf(VIEW_FORMAT, "Target group"); 2786fcf3ce44SJohn Forte if (viewEntryList->ve[j].allTargets) { 2787fcf3ce44SJohn Forte (void) printf("All\n"); 2788fcf3ce44SJohn Forte } else { 2789fcf3ce44SJohn Forte (void) mbstowcs(groupName, 2790fcf3ce44SJohn Forte viewEntryList->ve[j].targetGroup, 27913e7352aeSJohn Forte sizeof (stmfGroupName) - 1); 27923e7352aeSJohn Forte groupName[sizeof (stmfGroupName) - 1] 27933e7352aeSJohn Forte = 0; 2794fcf3ce44SJohn Forte (void) printf("%ws\n", groupName); 2795fcf3ce44SJohn Forte } 2796fcf3ce44SJohn Forte outputLuNbr = ((viewEntryList->ve[j].luNbr[0] & 2797fcf3ce44SJohn Forte 0x3F) << 8) | viewEntryList->ve[j].luNbr[1]; 2798fcf3ce44SJohn Forte (void) printf(VIEW_FORMAT, "LUN"); 2799fcf3ce44SJohn Forte (void) printf("%d\n", outputLuNbr); 2800fcf3ce44SJohn Forte if (found && operandEntered) { 2801fcf3ce44SJohn Forte break; 2802fcf3ce44SJohn Forte } 2803fcf3ce44SJohn Forte } 2804fcf3ce44SJohn Forte } 2805fcf3ce44SJohn Forte if (operandEntered && !found) { 2806fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s, %s: %s\n", cmdName, 2807fcf3ce44SJohn Forte sGuid, operands[i], gettext("not found")); 2808fcf3ce44SJohn Forte ret = 1; 2809fcf3ce44SJohn Forte } 2810fcf3ce44SJohn Forte } 2811fcf3ce44SJohn Forte 2812fcf3ce44SJohn Forte return (ret); 2813fcf3ce44SJohn Forte } 2814fcf3ce44SJohn Forte 2815fcf3ce44SJohn Forte 2816fcf3ce44SJohn Forte /* 2817fcf3ce44SJohn Forte * onlineOfflineLu 2818fcf3ce44SJohn Forte * 2819fcf3ce44SJohn Forte * Purpose: Online or offline a logical unit 2820fcf3ce44SJohn Forte * 2821fcf3ce44SJohn Forte * lu - logical unit to online or offline 2822fcf3ce44SJohn Forte * 2823fcf3ce44SJohn Forte * state - ONLINE_LU 2824fcf3ce44SJohn Forte * OFFLINE_LU 2825fcf3ce44SJohn Forte */ 2826fcf3ce44SJohn Forte static int 2827fcf3ce44SJohn Forte onlineOfflineLu(char *lu, int state) 2828fcf3ce44SJohn Forte { 2829fcf3ce44SJohn Forte char sGuid[GUID_INPUT + 1]; 2830fcf3ce44SJohn Forte stmfGuid inGuid; 2831fcf3ce44SJohn Forte unsigned int guid[sizeof (stmfGuid)]; 2832fcf3ce44SJohn Forte int i; 2833*4f486358SNattuvetty Bhavyan int ret = 0, stmfRet; 2834*4f486358SNattuvetty Bhavyan stmfLogicalUnitProperties luProps; 2835fcf3ce44SJohn Forte 2836fcf3ce44SJohn Forte if (strlen(lu) != GUID_INPUT) { 2837fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s %d %s\n", cmdName, lu, 2838fcf3ce44SJohn Forte gettext("must be"), GUID_INPUT, 2839fcf3ce44SJohn Forte gettext("hexadecimal digits long")); 2840fcf3ce44SJohn Forte return (1); 2841fcf3ce44SJohn Forte } 2842fcf3ce44SJohn Forte 2843fcf3ce44SJohn Forte bcopy(lu, sGuid, GUID_INPUT); 2844fcf3ce44SJohn Forte 2845fcf3ce44SJohn Forte for (i = 0; i < 32; i++) 2846fcf3ce44SJohn Forte sGuid[i] = tolower(sGuid[i]); 2847fcf3ce44SJohn Forte sGuid[i] = 0; 2848fcf3ce44SJohn Forte 2849fcf3ce44SJohn Forte (void) sscanf(sGuid, "%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x", 2850fcf3ce44SJohn Forte &guid[0], &guid[1], &guid[2], &guid[3], &guid[4], &guid[5], 2851fcf3ce44SJohn Forte &guid[6], &guid[7], &guid[8], &guid[9], &guid[10], &guid[11], 2852fcf3ce44SJohn Forte &guid[12], &guid[13], &guid[14], &guid[15]); 2853fcf3ce44SJohn Forte 2854fcf3ce44SJohn Forte for (i = 0; i < sizeof (stmfGuid); i++) { 2855fcf3ce44SJohn Forte inGuid.guid[i] = guid[i]; 2856fcf3ce44SJohn Forte } 2857fcf3ce44SJohn Forte 2858fcf3ce44SJohn Forte if (state == ONLINE_LU) { 2859fcf3ce44SJohn Forte ret = stmfOnlineLogicalUnit(&inGuid); 2860fcf3ce44SJohn Forte } else if (state == OFFLINE_LU) { 2861fcf3ce44SJohn Forte ret = stmfOfflineLogicalUnit(&inGuid); 2862*4f486358SNattuvetty Bhavyan } else { 2863*4f486358SNattuvetty Bhavyan return (STMFADM_FAILURE); 2864fcf3ce44SJohn Forte } 2865fcf3ce44SJohn Forte if (ret != STMF_STATUS_SUCCESS) { 2866fcf3ce44SJohn Forte switch (ret) { 2867fcf3ce44SJohn Forte case STMF_ERROR_PERM: 2868fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 2869fcf3ce44SJohn Forte gettext("permission denied")); 2870fcf3ce44SJohn Forte break; 2871fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_NOT_FOUND: 2872fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 2873fcf3ce44SJohn Forte gettext("STMF service not found")); 2874fcf3ce44SJohn Forte break; 2875*4f486358SNattuvetty Bhavyan case STMF_ERROR_BUSY: 2876*4f486358SNattuvetty Bhavyan (void) fprintf(stderr, "%s: %s\n", cmdName, 2877*4f486358SNattuvetty Bhavyan gettext("resource busy")); 2878*4f486358SNattuvetty Bhavyan break; 2879fcf3ce44SJohn Forte case STMF_ERROR_NOT_FOUND: 2880fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 2881fcf3ce44SJohn Forte lu, gettext("not found")); 2882fcf3ce44SJohn Forte break; 2883fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_DATA_VERSION: 2884fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 2885fcf3ce44SJohn Forte gettext("STMF service version incorrect")); 2886fcf3ce44SJohn Forte break; 2887fcf3ce44SJohn Forte default: 2888fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 2889fcf3ce44SJohn Forte gettext("unknown error")); 2890fcf3ce44SJohn Forte break; 2891fcf3ce44SJohn Forte } 2892*4f486358SNattuvetty Bhavyan } else { 2893*4f486358SNattuvetty Bhavyan struct timespec ts = {0}; 2894*4f486358SNattuvetty Bhavyan unsigned int count = 0; 2895*4f486358SNattuvetty Bhavyan uint32_t ret_state; 2896*4f486358SNattuvetty Bhavyan 2897*4f486358SNattuvetty Bhavyan ret_state = (state == ONLINE_LU) ? 2898*4f486358SNattuvetty Bhavyan STMF_LOGICAL_UNIT_ONLINING : STMF_LOGICAL_UNIT_OFFLINING; 2899*4f486358SNattuvetty Bhavyan ts.tv_nsec = DELAYED_EXEC_WAIT_INTERVAL; 2900*4f486358SNattuvetty Bhavyan 2901*4f486358SNattuvetty Bhavyan /* CONSTCOND */ 2902*4f486358SNattuvetty Bhavyan while (1) { 2903*4f486358SNattuvetty Bhavyan stmfRet = stmfGetLogicalUnitProperties(&inGuid, 2904*4f486358SNattuvetty Bhavyan &luProps); 2905*4f486358SNattuvetty Bhavyan if (stmfRet == STMF_STATUS_SUCCESS) 2906*4f486358SNattuvetty Bhavyan ret_state = luProps.status; 2907*4f486358SNattuvetty Bhavyan 2908*4f486358SNattuvetty Bhavyan if ((state == ONLINE_LU && 2909*4f486358SNattuvetty Bhavyan ret_state == STMF_LOGICAL_UNIT_ONLINE) || 2910*4f486358SNattuvetty Bhavyan (state == OFFLINE_LU && 2911*4f486358SNattuvetty Bhavyan ret_state == STMF_LOGICAL_UNIT_OFFLINE)) 2912*4f486358SNattuvetty Bhavyan return (STMFADM_SUCCESS); 2913*4f486358SNattuvetty Bhavyan 2914*4f486358SNattuvetty Bhavyan if ((state == ONLINE_LU && 2915*4f486358SNattuvetty Bhavyan ret_state == STMF_LOGICAL_UNIT_OFFLINE) || 2916*4f486358SNattuvetty Bhavyan (state == OFFLINE_LU && 2917*4f486358SNattuvetty Bhavyan ret_state == STMF_LOGICAL_UNIT_ONLINE)) 2918*4f486358SNattuvetty Bhavyan return (STMFADM_FAILURE); 2919*4f486358SNattuvetty Bhavyan 2920*4f486358SNattuvetty Bhavyan if (++count == DELAYED_EXEC_WAIT_MAX) { 2921*4f486358SNattuvetty Bhavyan (void) fprintf(stderr, "%s: %s\n", cmdName, 2922*4f486358SNattuvetty Bhavyan gettext("Logical Unit state change request " 2923*4f486358SNattuvetty Bhavyan "submitted. Waiting for completion " 2924*4f486358SNattuvetty Bhavyan "timed out")); 2925*4f486358SNattuvetty Bhavyan return (STMFADM_FAILURE); 2926fcf3ce44SJohn Forte } 2927*4f486358SNattuvetty Bhavyan (void) nanosleep(&ts, NULL); 2928*4f486358SNattuvetty Bhavyan } 2929*4f486358SNattuvetty Bhavyan } 2930*4f486358SNattuvetty Bhavyan return (STMFADM_FAILURE); 2931fcf3ce44SJohn Forte } 2932fcf3ce44SJohn Forte 2933fcf3ce44SJohn Forte /* 2934fcf3ce44SJohn Forte * onlineLuFunc 2935fcf3ce44SJohn Forte * 2936fcf3ce44SJohn Forte * Purpose: Online a logical unit 2937fcf3ce44SJohn Forte * 2938fcf3ce44SJohn Forte */ 2939fcf3ce44SJohn Forte /*ARGSUSED*/ 2940fcf3ce44SJohn Forte static int 2941fcf3ce44SJohn Forte onlineLuFunc(int operandLen, char *operands[], cmdOptions_t *options, 2942fcf3ce44SJohn Forte void *args) 2943fcf3ce44SJohn Forte { 2944e17f3b22Stim szeto int ret; 2945e17f3b22Stim szeto stmfState state; 2946e17f3b22Stim szeto 2947e17f3b22Stim szeto ret = getStmfState(&state); 2948e17f3b22Stim szeto if (ret != STMF_STATUS_SUCCESS) 2949e17f3b22Stim szeto return (ret); 2950e17f3b22Stim szeto if (state.operationalState == STMF_SERVICE_STATE_OFFLINE || 2951e17f3b22Stim szeto state.operationalState == STMF_SERVICE_STATE_OFFLINING) { 2952e17f3b22Stim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 2953e17f3b22Stim szeto gettext("STMF service is offline")); 2954e17f3b22Stim szeto return (1); 2955e17f3b22Stim szeto } 2956fcf3ce44SJohn Forte return (onlineOfflineLu(operands[0], ONLINE_LU)); 2957fcf3ce44SJohn Forte } 2958fcf3ce44SJohn Forte 2959fcf3ce44SJohn Forte /* 2960fcf3ce44SJohn Forte * offlineLuFunc 2961fcf3ce44SJohn Forte * 2962fcf3ce44SJohn Forte * Purpose: Offline a logical unit 2963fcf3ce44SJohn Forte * 2964fcf3ce44SJohn Forte */ 2965fcf3ce44SJohn Forte /*ARGSUSED*/ 2966fcf3ce44SJohn Forte static int 2967fcf3ce44SJohn Forte offlineLuFunc(int operandLen, char *operands[], cmdOptions_t *options, 2968fcf3ce44SJohn Forte void *args) 2969fcf3ce44SJohn Forte { 2970fcf3ce44SJohn Forte return (onlineOfflineLu(operands[0], OFFLINE_LU)); 2971fcf3ce44SJohn Forte } 2972fcf3ce44SJohn Forte 2973fcf3ce44SJohn Forte /* 2974fcf3ce44SJohn Forte * onlineOfflineTarget 2975fcf3ce44SJohn Forte * 2976fcf3ce44SJohn Forte * Purpose: Online or offline a target 2977fcf3ce44SJohn Forte * 2978fcf3ce44SJohn Forte * target - target to online or offline 2979fcf3ce44SJohn Forte * 2980fcf3ce44SJohn Forte * state - ONLINE_TARGET 2981fcf3ce44SJohn Forte * OFFLINE_TARGET 2982fcf3ce44SJohn Forte */ 2983fcf3ce44SJohn Forte static int 2984fcf3ce44SJohn Forte onlineOfflineTarget(char *target, int state) 2985fcf3ce44SJohn Forte { 2986*4f486358SNattuvetty Bhavyan int ret = 0, stmfRet = 0; 2987fcf3ce44SJohn Forte stmfDevid devid; 2988*4f486358SNattuvetty Bhavyan stmfTargetProperties targetProps; 2989fcf3ce44SJohn Forte 2990fcf3ce44SJohn Forte if (parseDevid(target, &devid) != 0) { 2991fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", 2992fcf3ce44SJohn Forte cmdName, target, gettext("unrecognized device id")); 2993fcf3ce44SJohn Forte return (1); 2994fcf3ce44SJohn Forte } 2995fcf3ce44SJohn Forte if (state == ONLINE_TARGET) { 2996fcf3ce44SJohn Forte ret = stmfOnlineTarget(&devid); 2997fcf3ce44SJohn Forte } else if (state == OFFLINE_TARGET) { 2998fcf3ce44SJohn Forte ret = stmfOfflineTarget(&devid); 2999*4f486358SNattuvetty Bhavyan } else { 3000*4f486358SNattuvetty Bhavyan return (STMFADM_FAILURE); 3001fcf3ce44SJohn Forte } 3002fcf3ce44SJohn Forte if (ret != STMF_STATUS_SUCCESS) { 3003fcf3ce44SJohn Forte switch (ret) { 3004fcf3ce44SJohn Forte case STMF_ERROR_PERM: 3005fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 3006fcf3ce44SJohn Forte gettext("permission denied")); 3007fcf3ce44SJohn Forte break; 3008fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_NOT_FOUND: 3009fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 3010fcf3ce44SJohn Forte gettext("STMF service not found")); 3011fcf3ce44SJohn Forte break; 3012*4f486358SNattuvetty Bhavyan case STMF_ERROR_BUSY: 3013*4f486358SNattuvetty Bhavyan (void) fprintf(stderr, "%s: %s\n", cmdName, 3014*4f486358SNattuvetty Bhavyan gettext("resource busy")); 3015*4f486358SNattuvetty Bhavyan break; 3016fcf3ce44SJohn Forte case STMF_ERROR_NOT_FOUND: 3017fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 3018fcf3ce44SJohn Forte target, gettext("not found")); 3019fcf3ce44SJohn Forte break; 3020fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_DATA_VERSION: 3021fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 3022fcf3ce44SJohn Forte gettext("STMF service version incorrect")); 3023fcf3ce44SJohn Forte break; 3024fcf3ce44SJohn Forte default: 3025fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 3026fcf3ce44SJohn Forte gettext("unknown error")); 3027fcf3ce44SJohn Forte break; 3028fcf3ce44SJohn Forte } 3029*4f486358SNattuvetty Bhavyan } else { 3030*4f486358SNattuvetty Bhavyan struct timespec ts = {0}; 3031*4f486358SNattuvetty Bhavyan unsigned int count = 0; 3032*4f486358SNattuvetty Bhavyan uint32_t ret_state; 3033*4f486358SNattuvetty Bhavyan 3034*4f486358SNattuvetty Bhavyan ret_state = (state == ONLINE_TARGET) ? 3035*4f486358SNattuvetty Bhavyan STMF_TARGET_PORT_ONLINING : STMF_TARGET_PORT_OFFLINING; 3036*4f486358SNattuvetty Bhavyan ts.tv_nsec = DELAYED_EXEC_WAIT_INTERVAL; 3037*4f486358SNattuvetty Bhavyan 3038*4f486358SNattuvetty Bhavyan /* CONSTCOND */ 3039*4f486358SNattuvetty Bhavyan while (1) { 3040*4f486358SNattuvetty Bhavyan stmfRet = stmfGetTargetProperties(&devid, &targetProps); 3041*4f486358SNattuvetty Bhavyan if (stmfRet == STMF_STATUS_SUCCESS) 3042*4f486358SNattuvetty Bhavyan ret_state = targetProps.status; 3043*4f486358SNattuvetty Bhavyan 3044*4f486358SNattuvetty Bhavyan if ((state == ONLINE_TARGET && 3045*4f486358SNattuvetty Bhavyan ret_state == STMF_TARGET_PORT_ONLINE) || 3046*4f486358SNattuvetty Bhavyan (state == OFFLINE_TARGET && 3047*4f486358SNattuvetty Bhavyan ret_state == STMF_TARGET_PORT_OFFLINE)) { 3048*4f486358SNattuvetty Bhavyan return (STMFADM_SUCCESS); 3049fcf3ce44SJohn Forte } 3050*4f486358SNattuvetty Bhavyan 3051*4f486358SNattuvetty Bhavyan if ((state == ONLINE_TARGET && 3052*4f486358SNattuvetty Bhavyan ret_state == STMF_TARGET_PORT_OFFLINE) || 3053*4f486358SNattuvetty Bhavyan (state == OFFLINE_TARGET && 3054*4f486358SNattuvetty Bhavyan ret_state == STMF_TARGET_PORT_ONLINE)) { 3055*4f486358SNattuvetty Bhavyan return (STMFADM_FAILURE); 3056*4f486358SNattuvetty Bhavyan } 3057*4f486358SNattuvetty Bhavyan 3058*4f486358SNattuvetty Bhavyan if (++count == DELAYED_EXEC_WAIT_MAX) { 3059*4f486358SNattuvetty Bhavyan (void) fprintf(stderr, "%s: %s\n", cmdName, 3060*4f486358SNattuvetty Bhavyan gettext("Target state change request " 3061*4f486358SNattuvetty Bhavyan "submitted. Waiting for completion " 3062*4f486358SNattuvetty Bhavyan "timed out.")); 3063*4f486358SNattuvetty Bhavyan return (STMFADM_FAILURE); 3064*4f486358SNattuvetty Bhavyan } 3065*4f486358SNattuvetty Bhavyan (void) nanosleep(&ts, NULL); 3066*4f486358SNattuvetty Bhavyan } 3067*4f486358SNattuvetty Bhavyan } 3068*4f486358SNattuvetty Bhavyan return (STMFADM_FAILURE); 3069fcf3ce44SJohn Forte } 3070fcf3ce44SJohn Forte 3071fcf3ce44SJohn Forte /* 3072fcf3ce44SJohn Forte * onlineTargetFunc 3073fcf3ce44SJohn Forte * 3074fcf3ce44SJohn Forte * Purpose: Online a target 3075fcf3ce44SJohn Forte * 3076fcf3ce44SJohn Forte */ 3077fcf3ce44SJohn Forte /*ARGSUSED*/ 3078fcf3ce44SJohn Forte static int 3079fcf3ce44SJohn Forte onlineTargetFunc(int operandLen, char *operands[], cmdOptions_t *options, 3080fcf3ce44SJohn Forte void *args) 3081fcf3ce44SJohn Forte { 3082e17f3b22Stim szeto int ret; 3083e17f3b22Stim szeto stmfState state; 3084e17f3b22Stim szeto 3085e17f3b22Stim szeto ret = getStmfState(&state); 3086e17f3b22Stim szeto if (ret != STMF_STATUS_SUCCESS) 3087e17f3b22Stim szeto return (ret); 3088e17f3b22Stim szeto if (state.operationalState == STMF_SERVICE_STATE_OFFLINE || 3089e17f3b22Stim szeto state.operationalState == STMF_SERVICE_STATE_OFFLINING) { 3090e17f3b22Stim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 3091e17f3b22Stim szeto gettext("STMF service is offline")); 3092e17f3b22Stim szeto return (1); 3093e17f3b22Stim szeto } 3094fcf3ce44SJohn Forte return (onlineOfflineTarget(operands[0], ONLINE_TARGET)); 3095fcf3ce44SJohn Forte } 3096fcf3ce44SJohn Forte 3097fcf3ce44SJohn Forte /* 3098fcf3ce44SJohn Forte * offlineTargetFunc 3099fcf3ce44SJohn Forte * 3100fcf3ce44SJohn Forte * Purpose: Offline a target 3101fcf3ce44SJohn Forte * 3102fcf3ce44SJohn Forte */ 3103fcf3ce44SJohn Forte /*ARGSUSED*/ 3104fcf3ce44SJohn Forte static int 3105fcf3ce44SJohn Forte offlineTargetFunc(int operandLen, char *operands[], cmdOptions_t *options, 3106fcf3ce44SJohn Forte void *args) 3107fcf3ce44SJohn Forte { 3108fcf3ce44SJohn Forte return (onlineOfflineTarget(operands[0], OFFLINE_TARGET)); 3109fcf3ce44SJohn Forte } 3110fcf3ce44SJohn Forte 3111fcf3ce44SJohn Forte 3112fcf3ce44SJohn Forte /*ARGSUSED*/ 3113fcf3ce44SJohn Forte static int 3114fcf3ce44SJohn Forte removeHostGroupMemberFunc(int operandLen, char *operands[], 3115fcf3ce44SJohn Forte cmdOptions_t *options, void *args) 3116fcf3ce44SJohn Forte { 3117fcf3ce44SJohn Forte int i; 3118fcf3ce44SJohn Forte int ret = 0; 3119fcf3ce44SJohn Forte int stmfRet; 31203e7352aeSJohn Forte stmfGroupName groupName = {0}; 3121fcf3ce44SJohn Forte stmfDevid devid; 31223e7352aeSJohn Forte wchar_t groupNamePrint[sizeof (stmfGroupName)] = {0}; 3123fcf3ce44SJohn Forte 3124fcf3ce44SJohn Forte for (; options->optval; options++) { 3125fcf3ce44SJohn Forte switch (options->optval) { 3126fcf3ce44SJohn Forte case 'g': 3127fcf3ce44SJohn Forte (void) mbstowcs(groupNamePrint, options->optarg, 31283e7352aeSJohn Forte sizeof (stmfGroupName) - 1); 3129fcf3ce44SJohn Forte bcopy(options->optarg, groupName, 3130fcf3ce44SJohn Forte strlen(options->optarg)); 3131fcf3ce44SJohn Forte break; 3132fcf3ce44SJohn Forte default: 3133fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %c: %s\n", 3134fcf3ce44SJohn Forte cmdName, options->optval, 3135fcf3ce44SJohn Forte gettext("unknown option")); 3136fcf3ce44SJohn Forte return (1); 3137fcf3ce44SJohn Forte } 3138fcf3ce44SJohn Forte } 3139fcf3ce44SJohn Forte 3140fcf3ce44SJohn Forte for (i = 0; i < operandLen; i++) { 3141fcf3ce44SJohn Forte if (parseDevid(operands[i], &devid) != 0) { 3142fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", 3143fcf3ce44SJohn Forte cmdName, operands[i], 3144fcf3ce44SJohn Forte gettext("unrecognized device id")); 3145fcf3ce44SJohn Forte ret++; 3146fcf3ce44SJohn Forte continue; 3147fcf3ce44SJohn Forte } 3148fcf3ce44SJohn Forte stmfRet = stmfRemoveFromHostGroup(&groupName, &devid); 3149fcf3ce44SJohn Forte switch (stmfRet) { 3150fcf3ce44SJohn Forte case STMF_STATUS_SUCCESS: 3151fcf3ce44SJohn Forte break; 3152fcf3ce44SJohn Forte case STMF_ERROR_MEMBER_NOT_FOUND: 3153fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 3154fcf3ce44SJohn Forte operands[i], gettext("not found")); 3155fcf3ce44SJohn Forte ret++; 3156fcf3ce44SJohn Forte break; 3157fcf3ce44SJohn Forte case STMF_ERROR_GROUP_NOT_FOUND: 3158fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %ws: %s\n", cmdName, 3159fcf3ce44SJohn Forte groupNamePrint, gettext("not found")); 3160fcf3ce44SJohn Forte ret++; 3161fcf3ce44SJohn Forte break; 3162fcf3ce44SJohn Forte case STMF_ERROR_BUSY: 3163fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 3164fcf3ce44SJohn Forte operands[i], "resource busy"); 3165fcf3ce44SJohn Forte ret++; 3166fcf3ce44SJohn Forte break; 3167fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_NOT_FOUND: 3168fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 3169fcf3ce44SJohn Forte gettext("STMF service not found")); 3170fcf3ce44SJohn Forte ret++; 3171fcf3ce44SJohn Forte break; 3172fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_DATA_VERSION: 3173fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 3174fcf3ce44SJohn Forte gettext("STMF service version incorrect")); 3175fcf3ce44SJohn Forte ret++; 3176fcf3ce44SJohn Forte break; 3177fcf3ce44SJohn Forte case STMF_ERROR_PERM: 3178fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 3179fcf3ce44SJohn Forte gettext("permission denied")); 3180fcf3ce44SJohn Forte ret++; 3181fcf3ce44SJohn Forte break; 3182fcf3ce44SJohn Forte default: 3183fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 3184fcf3ce44SJohn Forte operands[i], gettext("unknown error")); 3185fcf3ce44SJohn Forte ret++; 3186fcf3ce44SJohn Forte break; 3187fcf3ce44SJohn Forte } 3188fcf3ce44SJohn Forte } 3189fcf3ce44SJohn Forte 3190fcf3ce44SJohn Forte return (ret); 3191fcf3ce44SJohn Forte } 3192fcf3ce44SJohn Forte 3193fcf3ce44SJohn Forte /* 3194fcf3ce44SJohn Forte * removeTargetGroupMemberFunc 3195fcf3ce44SJohn Forte * 3196fcf3ce44SJohn Forte * Removes one or more members from a target group 3197fcf3ce44SJohn Forte * 3198fcf3ce44SJohn Forte */ 3199fcf3ce44SJohn Forte /*ARGSUSED*/ 3200fcf3ce44SJohn Forte static int 3201fcf3ce44SJohn Forte removeTargetGroupMemberFunc(int operandLen, char *operands[], 3202fcf3ce44SJohn Forte cmdOptions_t *options, void *args) 3203fcf3ce44SJohn Forte { 3204fcf3ce44SJohn Forte int i; 3205fcf3ce44SJohn Forte int ret = 0; 3206fcf3ce44SJohn Forte int stmfRet; 32073e7352aeSJohn Forte stmfGroupName groupName = {0}; 3208fcf3ce44SJohn Forte stmfDevid devid; 32093e7352aeSJohn Forte wchar_t groupNamePrint[sizeof (stmfGroupName)] = {0}; 3210fcf3ce44SJohn Forte 3211fcf3ce44SJohn Forte for (; options->optval; options++) { 3212fcf3ce44SJohn Forte switch (options->optval) { 3213fcf3ce44SJohn Forte case 'g': 3214fcf3ce44SJohn Forte (void) mbstowcs(groupNamePrint, options->optarg, 32153e7352aeSJohn Forte sizeof (stmfGroupName) - 1); 3216fcf3ce44SJohn Forte bcopy(options->optarg, groupName, 3217fcf3ce44SJohn Forte strlen(options->optarg)); 3218fcf3ce44SJohn Forte break; 3219fcf3ce44SJohn Forte default: 3220fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %c: %s\n", 3221fcf3ce44SJohn Forte cmdName, options->optval, 3222fcf3ce44SJohn Forte gettext("unknown option")); 3223fcf3ce44SJohn Forte return (1); 3224fcf3ce44SJohn Forte } 3225fcf3ce44SJohn Forte } 3226fcf3ce44SJohn Forte 3227fcf3ce44SJohn Forte for (i = 0; i < operandLen; i++) { 3228fcf3ce44SJohn Forte if (parseDevid(operands[i], &devid) != 0) { 3229fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", 3230fcf3ce44SJohn Forte cmdName, operands[i], 3231fcf3ce44SJohn Forte gettext("unrecognized device id")); 3232fcf3ce44SJohn Forte ret++; 3233fcf3ce44SJohn Forte continue; 3234fcf3ce44SJohn Forte } 3235fcf3ce44SJohn Forte stmfRet = stmfRemoveFromTargetGroup(&groupName, &devid); 3236fcf3ce44SJohn Forte switch (stmfRet) { 3237fcf3ce44SJohn Forte case STMF_STATUS_SUCCESS: 3238fcf3ce44SJohn Forte break; 3239fcf3ce44SJohn Forte case STMF_ERROR_MEMBER_NOT_FOUND: 3240fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 3241fcf3ce44SJohn Forte operands[i], gettext("not found")); 3242fcf3ce44SJohn Forte ret++; 3243fcf3ce44SJohn Forte break; 3244fcf3ce44SJohn Forte case STMF_ERROR_GROUP_NOT_FOUND: 3245fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %ws: %s\n", cmdName, 3246fcf3ce44SJohn Forte groupNamePrint, gettext("not found")); 3247fcf3ce44SJohn Forte ret++; 3248fcf3ce44SJohn Forte break; 3249fcf3ce44SJohn Forte case STMF_ERROR_BUSY: 3250fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 3251fcf3ce44SJohn Forte operands[i], gettext("resource busy")); 3252fcf3ce44SJohn Forte ret++; 3253fcf3ce44SJohn Forte break; 3254fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_NOT_FOUND: 3255fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 3256fcf3ce44SJohn Forte gettext("STMF service not found")); 3257fcf3ce44SJohn Forte ret++; 3258fcf3ce44SJohn Forte break; 3259fcf3ce44SJohn Forte case STMF_ERROR_PERM: 3260fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 3261fcf3ce44SJohn Forte gettext("permission denied")); 3262fcf3ce44SJohn Forte ret++; 3263fcf3ce44SJohn Forte break; 3264fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_DATA_VERSION: 3265fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 3266fcf3ce44SJohn Forte gettext("STMF service version incorrect")); 3267fcf3ce44SJohn Forte ret++; 3268fcf3ce44SJohn Forte break; 32695c8cac22Stim szeto case STMF_ERROR_TG_ONLINE: 32705c8cac22Stim szeto (void) fprintf(stderr, "%s: %s\n", cmdName, 32715c8cac22Stim szeto gettext("STMF target must be offline")); 32725c8cac22Stim szeto ret++; 32735c8cac22Stim szeto break; 3274fcf3ce44SJohn Forte default: 3275fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 3276fcf3ce44SJohn Forte operands[i], gettext("unknown error")); 3277fcf3ce44SJohn Forte ret++; 3278fcf3ce44SJohn Forte break; 3279fcf3ce44SJohn Forte } 3280fcf3ce44SJohn Forte } 3281fcf3ce44SJohn Forte 3282fcf3ce44SJohn Forte return (ret); 3283fcf3ce44SJohn Forte } 3284fcf3ce44SJohn Forte 3285fcf3ce44SJohn Forte /* 3286fcf3ce44SJohn Forte * removeViewFunc 3287fcf3ce44SJohn Forte * 3288fcf3ce44SJohn Forte * Removes one or more view entries from a logical unit 3289fcf3ce44SJohn Forte * 3290fcf3ce44SJohn Forte */ 3291fcf3ce44SJohn Forte /*ARGSUSED*/ 3292fcf3ce44SJohn Forte static int 3293fcf3ce44SJohn Forte removeViewFunc(int operandLen, char *operands[], cmdOptions_t *options, 3294fcf3ce44SJohn Forte void *args) 3295fcf3ce44SJohn Forte { 3296fcf3ce44SJohn Forte char sGuid[GUID_INPUT + 1]; 3297fcf3ce44SJohn Forte stmfViewEntryList *viewEntryList; 3298fcf3ce44SJohn Forte stmfGuid inGuid; 3299fcf3ce44SJohn Forte uint32_t count; 3300fcf3ce44SJohn Forte unsigned int guid[sizeof (stmfGuid)]; 3301fcf3ce44SJohn Forte char *endPtr; 3302fcf3ce44SJohn Forte uint32_t veNbr; 3303fcf3ce44SJohn Forte int i; 3304fcf3ce44SJohn Forte boolean_t all = B_FALSE; 3305fcf3ce44SJohn Forte boolean_t luInput = B_FALSE; 3306fcf3ce44SJohn Forte int ret = 0; 3307fcf3ce44SJohn Forte int stmfRet; 3308fcf3ce44SJohn Forte 3309fcf3ce44SJohn Forte /* Note: 'l' is required */ 3310fcf3ce44SJohn Forte for (; options->optval; options++) { 3311fcf3ce44SJohn Forte switch (options->optval) { 3312fcf3ce44SJohn Forte case 'l': 3313fcf3ce44SJohn Forte if (strlen(options->optarg) != GUID_INPUT) { 3314fcf3ce44SJohn Forte (void) fprintf(stderr, 3315fcf3ce44SJohn Forte "%s: %s: %s %d %s\n", 3316fcf3ce44SJohn Forte cmdName, options->optarg, 3317fcf3ce44SJohn Forte gettext("must be"), GUID_INPUT, 3318fcf3ce44SJohn Forte gettext("hexadecimal digits long")); 3319fcf3ce44SJohn Forte return (1); 3320fcf3ce44SJohn Forte } 3321fcf3ce44SJohn Forte bcopy(options->optarg, sGuid, GUID_INPUT); 3322fcf3ce44SJohn Forte luInput = B_TRUE; 3323fcf3ce44SJohn Forte break; 3324fcf3ce44SJohn Forte case 'a': 3325fcf3ce44SJohn Forte /* removing all view entries for this GUID */ 3326fcf3ce44SJohn Forte all = B_TRUE; 3327fcf3ce44SJohn Forte break; 3328fcf3ce44SJohn Forte default: 3329fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %c: %s\n", 3330fcf3ce44SJohn Forte cmdName, options->optval, 3331fcf3ce44SJohn Forte "unknown option"); 3332fcf3ce44SJohn Forte return (1); 3333fcf3ce44SJohn Forte } 3334fcf3ce44SJohn Forte } 3335fcf3ce44SJohn Forte 3336fcf3ce44SJohn Forte if (!all && operandLen == 0) { 3337fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 3338fcf3ce44SJohn Forte gettext("no view entries specified")); 3339fcf3ce44SJohn Forte return (1); 3340fcf3ce44SJohn Forte } 3341fcf3ce44SJohn Forte 3342fcf3ce44SJohn Forte if (!luInput) { 3343fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 3344fcf3ce44SJohn Forte gettext("logical unit (-l) not specified")); 3345fcf3ce44SJohn Forte return (1); 3346fcf3ce44SJohn Forte } 3347fcf3ce44SJohn Forte 3348fcf3ce44SJohn Forte for (i = 0; i < 32; i++) 3349fcf3ce44SJohn Forte sGuid[i] = tolower(sGuid[i]); 3350fcf3ce44SJohn Forte sGuid[i] = 0; 3351fcf3ce44SJohn Forte 3352fcf3ce44SJohn Forte (void) sscanf(sGuid, "%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x", 3353fcf3ce44SJohn Forte &guid[0], &guid[1], &guid[2], &guid[3], &guid[4], &guid[5], 3354fcf3ce44SJohn Forte &guid[6], &guid[7], &guid[8], &guid[9], &guid[10], &guid[11], 3355fcf3ce44SJohn Forte &guid[12], &guid[13], &guid[14], &guid[15]); 3356fcf3ce44SJohn Forte 3357fcf3ce44SJohn Forte for (i = 0; i < sizeof (stmfGuid); i++) { 3358fcf3ce44SJohn Forte inGuid.guid[i] = guid[i]; 3359fcf3ce44SJohn Forte } 3360fcf3ce44SJohn Forte 3361fcf3ce44SJohn Forte if ((stmfRet = stmfGetViewEntryList(&inGuid, &viewEntryList)) 3362fcf3ce44SJohn Forte != STMF_STATUS_SUCCESS) { 3363fcf3ce44SJohn Forte 3364fcf3ce44SJohn Forte switch (stmfRet) { 3365fcf3ce44SJohn Forte case STMF_ERROR_BUSY: 3366fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 3367fcf3ce44SJohn Forte sGuid, gettext("resource busy")); 3368fcf3ce44SJohn Forte break; 3369fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_NOT_FOUND: 3370fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 3371fcf3ce44SJohn Forte gettext("STMF service not found")); 3372fcf3ce44SJohn Forte break; 3373fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_DATA_VERSION: 3374fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 3375fcf3ce44SJohn Forte gettext("STMF service version incorrect")); 3376fcf3ce44SJohn Forte break; 3377fcf3ce44SJohn Forte case STMF_ERROR_PERM: 3378fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 3379fcf3ce44SJohn Forte gettext("permission denied")); 3380fcf3ce44SJohn Forte break; 3381fcf3ce44SJohn Forte default: 3382fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 3383fcf3ce44SJohn Forte sGuid, gettext("unknown error")); 3384fcf3ce44SJohn Forte break; 3385fcf3ce44SJohn Forte } 3386fcf3ce44SJohn Forte return (1); 3387fcf3ce44SJohn Forte } 3388fcf3ce44SJohn Forte 33897b506e25Ssrivijitha dugganapalli if (viewEntryList->cnt == 0) { 33907b506e25Ssrivijitha dugganapalli (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 33917b506e25Ssrivijitha dugganapalli sGuid, gettext("no views found")); 33927b506e25Ssrivijitha dugganapalli return (1); 33937b506e25Ssrivijitha dugganapalli } 33947b506e25Ssrivijitha dugganapalli 3395fcf3ce44SJohn Forte if (all) { 3396fcf3ce44SJohn Forte count = viewEntryList->cnt; 3397fcf3ce44SJohn Forte } else { 3398fcf3ce44SJohn Forte count = operandLen; 3399fcf3ce44SJohn Forte } 3400fcf3ce44SJohn Forte 3401fcf3ce44SJohn Forte for (i = 0; i < count; i++) { 3402fcf3ce44SJohn Forte if (all) { 3403fcf3ce44SJohn Forte veNbr = viewEntryList->ve[i].veIndex; 3404fcf3ce44SJohn Forte } else { 3405fcf3ce44SJohn Forte endPtr = NULL; 3406fcf3ce44SJohn Forte veNbr = strtol(operands[i], &endPtr, 10); 3407fcf3ce44SJohn Forte if (endPtr && *endPtr != 0) { 3408fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 3409fcf3ce44SJohn Forte operands[i], gettext("invalid input")); 3410fcf3ce44SJohn Forte continue; 3411fcf3ce44SJohn Forte } 3412fcf3ce44SJohn Forte } 3413fcf3ce44SJohn Forte stmfRet = stmfRemoveViewEntry(&inGuid, veNbr); 3414fcf3ce44SJohn Forte switch (stmfRet) { 3415fcf3ce44SJohn Forte case STMF_STATUS_SUCCESS: 3416fcf3ce44SJohn Forte break; 3417fcf3ce44SJohn Forte case STMF_ERROR_NOT_FOUND: 3418fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %d: %s\n", 3419fcf3ce44SJohn Forte cmdName, sGuid, veNbr, 3420fcf3ce44SJohn Forte gettext("not found")); 3421fcf3ce44SJohn Forte ret++; 3422fcf3ce44SJohn Forte break; 3423fcf3ce44SJohn Forte case STMF_ERROR_BUSY: 3424fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName, 3425fcf3ce44SJohn Forte sGuid, gettext("resource busy")); 3426fcf3ce44SJohn Forte ret++; 3427fcf3ce44SJohn Forte break; 3428fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_NOT_FOUND: 3429fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 3430fcf3ce44SJohn Forte gettext("STMF service not found")); 3431fcf3ce44SJohn Forte ret++; 3432fcf3ce44SJohn Forte break; 3433fcf3ce44SJohn Forte case STMF_ERROR_CONFIG_NONE: 3434fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 3435fcf3ce44SJohn Forte gettext("STMF service is not initialized")); 3436fcf3ce44SJohn Forte ret++; 3437fcf3ce44SJohn Forte break; 3438fcf3ce44SJohn Forte case STMF_ERROR_SERVICE_DATA_VERSION: 3439fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName, 3440fcf3ce44SJohn Forte gettext("STMF service version incorrect")); 3441fcf3ce44SJohn Forte ret++; 3442fcf3ce44SJohn Forte break; 3443fcf3ce44SJohn Forte default: 3444fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s, %d: %s", 3445fcf3ce44SJohn Forte cmdName, sGuid, veNbr, 3446fcf3ce44SJohn Forte gettext("unknown error")); 3447fcf3ce44SJohn Forte ret++; 3448fcf3ce44SJohn Forte break; 3449fcf3ce44SJohn Forte } 3450fcf3ce44SJohn Forte } 3451fcf3ce44SJohn Forte 3452fcf3ce44SJohn Forte return (ret); 3453fcf3ce44SJohn Forte } 3454fcf3ce44SJohn Forte 3455fcf3ce44SJohn Forte /* 3456fcf3ce44SJohn Forte * input: 3457fcf3ce44SJohn Forte * execFullName - exec name of program (argv[0]) 3458fcf3ce44SJohn Forte * 3459fcf3ce44SJohn Forte * copied from usr/src/cmd/zoneadm/zoneadm.c in OS/Net 3460fcf3ce44SJohn Forte * (changed name to lowerCamelCase to keep consistent with this file) 3461fcf3ce44SJohn Forte * 3462fcf3ce44SJohn Forte * Returns: 3463fcf3ce44SJohn Forte * command name portion of execFullName 3464fcf3ce44SJohn Forte */ 3465fcf3ce44SJohn Forte static char * 3466fcf3ce44SJohn Forte getExecBasename(char *execFullname) 3467fcf3ce44SJohn Forte { 3468fcf3ce44SJohn Forte char *lastSlash, *execBasename; 3469fcf3ce44SJohn Forte 3470fcf3ce44SJohn Forte /* guard against '/' at end of command invocation */ 3471fcf3ce44SJohn Forte for (;;) { 3472fcf3ce44SJohn Forte lastSlash = strrchr(execFullname, '/'); 3473fcf3ce44SJohn Forte if (lastSlash == NULL) { 3474fcf3ce44SJohn Forte execBasename = execFullname; 3475fcf3ce44SJohn Forte break; 3476fcf3ce44SJohn Forte } else { 3477fcf3ce44SJohn Forte execBasename = lastSlash + 1; 3478fcf3ce44SJohn Forte if (*execBasename == '\0') { 3479fcf3ce44SJohn Forte *lastSlash = '\0'; 3480fcf3ce44SJohn Forte continue; 3481fcf3ce44SJohn Forte } 3482fcf3ce44SJohn Forte break; 3483fcf3ce44SJohn Forte } 3484fcf3ce44SJohn Forte } 3485fcf3ce44SJohn Forte return (execBasename); 3486fcf3ce44SJohn Forte } 3487fcf3ce44SJohn Forte 3488fcf3ce44SJohn Forte int 3489fcf3ce44SJohn Forte main(int argc, char *argv[]) 3490fcf3ce44SJohn Forte { 3491fcf3ce44SJohn Forte synTables_t synTables; 3492fcf3ce44SJohn Forte char versionString[VERSION_STRING_MAX_LEN]; 3493fcf3ce44SJohn Forte int ret; 3494fcf3ce44SJohn Forte int funcRet; 3495fcf3ce44SJohn Forte void *subcommandArgs = NULL; 3496fcf3ce44SJohn Forte 3497fcf3ce44SJohn Forte (void) setlocale(LC_ALL, ""); 3498fcf3ce44SJohn Forte (void) textdomain(TEXT_DOMAIN); 3499fcf3ce44SJohn Forte /* set global command name */ 3500fcf3ce44SJohn Forte cmdName = getExecBasename(argv[0]); 3501fcf3ce44SJohn Forte 3502fcf3ce44SJohn Forte (void) snprintf(versionString, VERSION_STRING_MAX_LEN, "%s.%s", 3503fcf3ce44SJohn Forte VERSION_STRING_MAJOR, VERSION_STRING_MINOR); 3504fcf3ce44SJohn Forte synTables.versionString = versionString; 3505fcf3ce44SJohn Forte synTables.longOptionTbl = &longOptions[0]; 3506fcf3ce44SJohn Forte synTables.subCommandPropsTbl = &subcommands[0]; 3507fcf3ce44SJohn Forte 3508fcf3ce44SJohn Forte ret = cmdParse(argc, argv, synTables, subcommandArgs, &funcRet); 3509fcf3ce44SJohn Forte if (ret != 0) { 3510fcf3ce44SJohn Forte return (ret); 3511fcf3ce44SJohn Forte } 3512fcf3ce44SJohn Forte 3513fcf3ce44SJohn Forte return (funcRet); 3514fcf3ce44SJohn Forte } /* end main */ 3515