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