Print this page
10120 smatch indenting fixes for usr/src/cmd
Reviewed by: Gergő Doma <domag02@gmail.com>
Portions contributed by: Joyce McIntosh <joyce.mcintosh@nexenta.com>
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/sbdadm/sbdadm.c
+++ new/usr/src/cmd/sbdadm/sbdadm.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
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.
↓ open down ↓ |
14 lines elided |
↑ open up ↑ |
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 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
23 23 * Use is subject to license terms.
24 24 * Copyright 2012 Milan Jurik. All rights reserved.
25 + * Copyright (c) 2018, Joyent, Inc.
25 26 */
26 27 #include <stdlib.h>
27 28 #include <stdio.h>
28 29 #include <sys/types.h>
29 30 #include <sys/stat.h>
30 31 #include <fcntl.h>
31 32 #include <unistd.h>
32 33 #include <libintl.h>
33 34 #include <errno.h>
34 35 #include <string.h>
35 36 #include <assert.h>
36 37 #include <getopt.h>
37 38 #include <strings.h>
38 39 #include <ctype.h>
39 40 #include <libnvpair.h>
40 41 #include <locale.h>
41 42
42 43 #include <cmdparse.h>
43 44 #include <sys/stmf_defines.h>
44 45 #include <libstmf.h>
45 46 #include <sys/stmf_sbd_ioctl.h>
46 47
47 48 #define MAX_LU_LIST 8192
48 49 #define LU_LIST_MAX_RETRIES 3
49 50 #define GUID_INPUT 32
50 51
51 52 #define VERSION_STRING_MAJOR "1"
52 53 #define VERSION_STRING_MINOR "0"
53 54 #define VERSION_STRING_MAX_LEN 10
54 55
55 56
56 57 char *cmdName;
57 58
58 59 static char *getExecBasename(char *);
59 60 int delete_lu(int argc, char *argv[], cmdOptions_t *options,
60 61 void *callData);
61 62 int create_lu(int argc, char *argv[], cmdOptions_t *options, void *callData);
62 63 int list_lus(int argc, char *argv[], cmdOptions_t *options, void *callData);
63 64 int modify_lu(int argc, char *argv[], cmdOptions_t *options, void *callData);
64 65 int import_lu(int argc, char *argv[], cmdOptions_t *options, void *callData);
65 66 static int callModify(char *, stmfGuid *, uint32_t, const char *, const char *);
66 67 int print_lu_attr(stmfGuid *);
67 68 void print_guid(uint8_t *g, FILE *f);
68 69 void print_attr_header();
69 70
70 71 optionTbl_t options[] = {
71 72 { "disk-size", required_argument, 's',
72 73 "Size with <none>/k/m/g/t/p/e modifier" },
73 74 { "keep-views", no_arg, 'k',
74 75 "Dont delete view entries related to the LU" },
75 76 { NULL, 0, 0 }
76 77 };
77 78
78 79 subCommandProps_t subCommands[] = {
79 80 { "create-lu", create_lu, "s", NULL, NULL,
80 81 OPERAND_MANDATORY_SINGLE,
81 82 "Full path of the file to initialize" },
82 83 { "delete-lu", delete_lu, "k", NULL, NULL,
83 84 OPERAND_MANDATORY_SINGLE, "GUID of the LU to deregister" },
84 85 { "import-lu", import_lu, NULL, NULL, NULL,
85 86 OPERAND_MANDATORY_SINGLE, "filename of the LU to import" },
86 87 { "list-lu", list_lus, NULL, NULL, NULL,
87 88 OPERAND_NONE, "List all the exported LUs" },
88 89 { "modify-lu", modify_lu, "s", "s", NULL,
89 90 OPERAND_MANDATORY_SINGLE,
90 91 "Full path of the LU or GUID of a registered LU" },
91 92 { NULL, 0, 0, NULL, 0, NULL}
92 93 };
93 94
94 95 /*ARGSUSED*/
95 96 int
96 97 create_lu(int argc, char *operands[], cmdOptions_t *options, void *callData)
97 98 {
98 99 luResource hdl = NULL;
99 100 int ret = 0;
100 101 stmfGuid createdGuid;
101 102
102 103 ret = stmfCreateLuResource(STMF_DISK, &hdl);
103 104
104 105 if (ret != STMF_STATUS_SUCCESS) {
105 106 (void) fprintf(stderr, "%s: %s\n",
106 107 cmdName, gettext("Failure to create lu resource\n"));
107 108 return (1);
108 109 }
109 110
110 111 for (; options->optval; options++) {
111 112 switch (options->optval) {
112 113 case 's':
113 114 ret = stmfSetLuProp(hdl, STMF_LU_PROP_SIZE,
114 115 options->optarg);
115 116 if (ret != STMF_STATUS_SUCCESS) {
116 117 (void) fprintf(stderr, "%s: %c: %s\n",
117 118 cmdName, options->optval,
118 119 gettext("size param invalid"));
119 120 (void) stmfFreeLuResource(hdl);
120 121 return (1);
121 122 }
122 123 break;
123 124 default:
124 125 (void) fprintf(stderr, "%s: %c: %s\n",
125 126 cmdName, options->optval,
126 127 gettext("unknown option"));
127 128 return (1);
128 129 }
129 130 }
130 131
131 132 ret = stmfSetLuProp(hdl, STMF_LU_PROP_FILENAME, operands[0]);
132 133
133 134 if (ret != STMF_STATUS_SUCCESS) {
134 135 (void) fprintf(stderr, "%s: %s\n",
135 136 cmdName, gettext("could not set filename"));
136 137 return (1);
137 138 }
138 139
139 140 ret = stmfCreateLu(hdl, &createdGuid);
140 141 switch (ret) {
141 142 case STMF_STATUS_SUCCESS:
142 143 break;
143 144 case STMF_ERROR_BUSY:
144 145 case STMF_ERROR_LU_BUSY:
145 146 (void) fprintf(stderr, "%s: %s\n", cmdName,
146 147 gettext("resource busy"));
147 148 ret++;
148 149 break;
149 150 case STMF_ERROR_PERM:
150 151 (void) fprintf(stderr, "%s: %s\n", cmdName,
151 152 gettext("permission denied"));
152 153 ret++;
153 154 break;
154 155 case STMF_ERROR_FILE_IN_USE:
155 156 (void) fprintf(stderr, "%s: filename %s: %s\n", cmdName,
156 157 operands[0], gettext("in use"));
157 158 ret++;
158 159 break;
159 160 case STMF_ERROR_INVALID_BLKSIZE:
160 161 (void) fprintf(stderr, "%s: %s\n", cmdName,
161 162 gettext("invalid block size"));
162 163 ret++;
163 164 break;
164 165 case STMF_ERROR_GUID_IN_USE:
165 166 (void) fprintf(stderr, "%s: %s\n", cmdName,
166 167 gettext("guid in use"));
167 168 ret++;
168 169 break;
169 170 case STMF_ERROR_META_FILE_NAME:
170 171 (void) fprintf(stderr, "%s: %s\n", cmdName,
171 172 gettext("meta file error"));
172 173 ret++;
173 174 break;
174 175 case STMF_ERROR_DATA_FILE_NAME:
175 176 (void) fprintf(stderr, "%s: %s\n", cmdName,
176 177 gettext("data file error"));
177 178 ret++;
178 179 break;
179 180 case STMF_ERROR_SIZE_OUT_OF_RANGE:
180 181 (void) fprintf(stderr, "%s: %s\n", cmdName,
181 182 gettext("invalid size"));
182 183 ret++;
183 184 break;
184 185 case STMF_ERROR_META_CREATION:
185 186 (void) fprintf(stderr, "%s: %s\n", cmdName,
186 187 gettext("could not create meta file"));
187 188 ret++;
188 189 break;
189 190 default:
190 191 (void) fprintf(stderr, "%s: %s\n", cmdName,
191 192 gettext("unknown error"));
192 193 ret++;
193 194 break;
194 195 }
195 196
196 197 if (ret != STMF_STATUS_SUCCESS) {
197 198 goto done;
198 199 }
199 200
200 201 (void) printf("Created the following LU:\n");
201 202 print_attr_header();
202 203 ret = print_lu_attr(&createdGuid);
203 204
204 205 done:
205 206 (void) stmfFreeLuResource(hdl);
206 207 return (ret);
207 208 }
208 209
209 210 /*ARGSUSED*/
210 211 int
211 212 import_lu(int argc, char *operands[], cmdOptions_t *options, void *callData)
212 213 {
213 214 int ret = 0;
214 215 stmfGuid createdGuid;
215 216
216 217 ret = stmfImportLu(STMF_DISK, operands[0], &createdGuid);
217 218 switch (ret) {
218 219 case STMF_STATUS_SUCCESS:
219 220 break;
220 221 case STMF_ERROR_BUSY:
221 222 case STMF_ERROR_LU_BUSY:
222 223 (void) fprintf(stderr, "%s: %s\n", cmdName,
223 224 gettext("resource busy"));
224 225 ret++;
225 226 break;
226 227 case STMF_ERROR_PERM:
227 228 (void) fprintf(stderr, "%s: %s\n", cmdName,
228 229 gettext("permission denied"));
229 230 ret++;
230 231 break;
231 232 case STMF_ERROR_FILE_IN_USE:
232 233 (void) fprintf(stderr, "%s: filename %s: %s\n", cmdName,
233 234 operands[0], gettext("in use"));
234 235 ret++;
235 236 break;
236 237 case STMF_ERROR_GUID_IN_USE:
237 238 (void) fprintf(stderr, "%s: %s\n", cmdName,
238 239 gettext("guid in use"));
239 240 ret++;
240 241 break;
241 242 case STMF_ERROR_META_FILE_NAME:
242 243 (void) fprintf(stderr, "%s: %s\n", cmdName,
243 244 gettext("meta file error"));
244 245 ret++;
245 246 break;
246 247 case STMF_ERROR_DATA_FILE_NAME:
247 248 (void) fprintf(stderr, "%s: %s\n", cmdName,
248 249 gettext("data file error"));
249 250 ret++;
250 251 break;
251 252 case STMF_ERROR_SIZE_OUT_OF_RANGE:
252 253 (void) fprintf(stderr, "%s: %s\n", cmdName,
253 254 gettext("invalid size"));
254 255 ret++;
255 256 break;
256 257 case STMF_ERROR_META_CREATION:
257 258 (void) fprintf(stderr, "%s: %s\n", cmdName,
258 259 gettext("could not create meta file"));
259 260 ret++;
260 261 break;
261 262 default:
262 263 (void) fprintf(stderr, "%s: %s\n", cmdName,
263 264 gettext("unknown error"));
264 265 ret++;
265 266 break;
266 267 }
267 268
268 269 if (ret != STMF_STATUS_SUCCESS) {
269 270 goto done;
270 271 }
271 272
272 273 (void) printf("Imported the following LU:\n");
273 274 print_attr_header();
274 275 ret = print_lu_attr(&createdGuid);
275 276
276 277 done:
277 278 return (ret);
278 279 }
279 280
280 281 /*ARGSUSED*/
281 282 int
282 283 delete_lu(int operandLen, char *operands[], cmdOptions_t *options,
283 284 void *callData)
284 285 {
285 286 int i, j;
286 287 int ret = 0;
287 288 int stmfRet;
288 289 unsigned int inGuid[sizeof (stmfGuid)];
289 290 stmfGuid delGuid;
290 291 boolean_t keepViews = B_FALSE;
291 292 boolean_t viewEntriesRemoved = B_FALSE;
292 293 boolean_t noLunFound = B_FALSE;
293 294 boolean_t views = B_FALSE;
294 295 boolean_t notValidHexNumber = B_FALSE;
295 296 char sGuid[GUID_INPUT + 1];
296 297 stmfViewEntryList *viewEntryList = NULL;
297 298
298 299 for (; options->optval; options++) {
299 300 switch (options->optval) {
300 301 /* Keep views for logical unit */
301 302 case 'k':
302 303 keepViews = B_TRUE;
303 304 break;
304 305 default:
305 306 (void) fprintf(stderr, "%s: %c: %s\n",
306 307 cmdName, options->optval,
307 308 gettext("unknown option"));
308 309 return (1);
↓ open down ↓ |
274 lines elided |
↑ open up ↑ |
309 310 }
310 311 }
311 312
312 313
313 314 for (i = 0; i < operandLen; i++) {
314 315 for (j = 0; j < GUID_INPUT; j++) {
315 316 if (!isxdigit(operands[i][j])) {
316 317 notValidHexNumber = B_TRUE;
317 318 break;
318 319 }
319 - sGuid[j] = tolower(operands[i][j]);
320 + sGuid[j] = tolower(operands[i][j]);
320 321 }
321 322 if ((notValidHexNumber == B_TRUE) ||
322 323 (strlen(operands[i]) != GUID_INPUT)) {
323 324 (void) fprintf(stderr, "%s: %s: %s%d%s\n",
324 325 cmdName, operands[i], gettext("must be "),
325 326 GUID_INPUT,
326 327 gettext(" hexadecimal digits long"));
327 328 notValidHexNumber = B_FALSE;
328 329 ret++;
329 330 continue;
330 331 }
331 332
332 333 sGuid[j] = 0;
333 334
334 335 (void) sscanf(sGuid,
335 336 "%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x",
336 337 &inGuid[0], &inGuid[1], &inGuid[2], &inGuid[3],
337 338 &inGuid[4], &inGuid[5], &inGuid[6], &inGuid[7],
338 339 &inGuid[8], &inGuid[9], &inGuid[10], &inGuid[11],
339 340 &inGuid[12], &inGuid[13], &inGuid[14], &inGuid[15]);
340 341
341 342 for (j = 0; j < sizeof (stmfGuid); j++) {
342 343 delGuid.guid[j] = inGuid[j];
343 344 }
344 345
345 346 stmfRet = stmfDeleteLu(&delGuid);
346 347 switch (stmfRet) {
347 348 case STMF_STATUS_SUCCESS:
348 349 break;
349 350 case STMF_ERROR_NOT_FOUND:
350 351 noLunFound = B_TRUE;
351 352 break;
352 353 case STMF_ERROR_BUSY:
353 354 (void) fprintf(stderr, "%s: %s\n", cmdName,
354 355 gettext("resource busy"));
355 356 ret++;
356 357 break;
357 358 case STMF_ERROR_PERM:
358 359 (void) fprintf(stderr, "%s: %s\n", cmdName,
359 360 gettext("permission denied"));
360 361 ret++;
361 362 break;
362 363 default:
363 364 (void) fprintf(stderr, "%s: %s\n", cmdName,
364 365 gettext("unknown error"));
365 366 ret++;
366 367 break;
367 368 }
368 369
369 370 if (!keepViews) {
370 371 stmfRet = stmfGetViewEntryList(&delGuid,
371 372 &viewEntryList);
372 373 if (stmfRet == STMF_STATUS_SUCCESS) {
373 374 for (j = 0; j < viewEntryList->cnt; j++) {
374 375 (void) stmfRemoveViewEntry(&delGuid,
375 376 viewEntryList->ve[j].veIndex);
376 377 }
377 378 /* check if viewEntryList is empty */
378 379 if (viewEntryList->cnt != 0)
379 380 viewEntriesRemoved = B_TRUE;
380 381 stmfFreeMemory(viewEntryList);
381 382 } else {
382 383 (void) fprintf(stderr, "%s: %s\n", cmdName,
383 384 gettext("unable to remove view entries\n"));
384 385 ret++;
385 386 }
386 387 }
387 388 if (keepViews) {
388 389 stmfRet = stmfGetViewEntryList(&delGuid,
389 390 &viewEntryList);
390 391 if (stmfRet == STMF_STATUS_SUCCESS) {
391 392 views = B_TRUE;
392 393 stmfFreeMemory(viewEntryList);
393 394 }
394 395 }
395 396
396 397 if ((!viewEntriesRemoved && noLunFound && !views) ||
397 398 (!views && keepViews && noLunFound)) {
398 399 (void) fprintf(stderr, "%s: %s: %s\n",
399 400 cmdName, sGuid,
400 401 gettext("not found"));
401 402 ret++;
402 403 }
403 404 noLunFound = viewEntriesRemoved = views = B_FALSE;
404 405 }
405 406 return (ret);
406 407 }
407 408
408 409 /*ARGSUSED*/
409 410 int
410 411 modify_lu(int operandLen, char *operands[], cmdOptions_t *options,
411 412 void *callData)
412 413 {
413 414 stmfGuid inGuid;
414 415 unsigned int guid[sizeof (stmfGuid)];
415 416 int ret = 0;
416 417 int i;
417 418 char *fname = NULL;
418 419 char sGuid[GUID_INPUT + 1];
419 420 boolean_t fnameUsed = B_FALSE;
420 421
421 422 if (operands[0][0] == '/') {
422 423 fnameUsed = B_TRUE;
423 424 fname = operands[0];
424 425 }
425 426
426 427 /* check input length */
427 428 if (!fnameUsed && strlen(operands[0]) != GUID_INPUT) {
428 429 (void) fprintf(stderr, "%s: %s: %s%d%s\n", cmdName, operands[0],
429 430 gettext("must be "), GUID_INPUT,
430 431 gettext(" hexadecimal digits"));
431 432 return (1);
432 433 }
433 434
434 435 if (!fnameUsed) {
435 436 /* convert to lower case for scan */
436 437 for (i = 0; i < 32; i++)
437 438 sGuid[i] = tolower(operands[0][i]);
438 439 sGuid[i] = 0;
439 440 (void) sscanf(sGuid,
440 441 "%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x",
441 442 &guid[0], &guid[1], &guid[2], &guid[3], &guid[4], &guid[5],
442 443 &guid[6], &guid[7], &guid[8], &guid[9], &guid[10],
443 444 &guid[11], &guid[12], &guid[13], &guid[14], &guid[15]);
444 445
445 446 for (i = 0; i < sizeof (stmfGuid); i++) {
446 447 inGuid.guid[i] = guid[i];
447 448 }
448 449 }
449 450
450 451 for (; options->optval; options++) {
451 452 switch (options->optval) {
452 453 case 's':
453 454 if (callModify(fname, &inGuid,
454 455 STMF_LU_PROP_SIZE, options->optarg,
455 456 "size") != 0) {
456 457 return (1);
457 458 }
458 459 break;
459 460 default:
460 461 (void) fprintf(stderr, "%s: %c: %s\n",
461 462 cmdName, options->optval,
462 463 gettext("unknown option"));
463 464 return (1);
464 465 }
465 466 }
466 467 return (ret);
467 468 }
468 469
469 470 static int
470 471 callModify(char *fname, stmfGuid *luGuid, uint32_t prop, const char *propVal,
471 472 const char *propString)
472 473 {
473 474 int ret = 0;
474 475 int stmfRet = 0;
475 476
476 477 if (!fname) {
477 478 stmfRet = stmfModifyLu(luGuid, prop, propVal);
478 479 } else {
479 480 stmfRet = stmfModifyLuByFname(STMF_DISK, fname, prop,
480 481 propVal);
481 482 }
482 483 switch (stmfRet) {
483 484 case STMF_STATUS_SUCCESS:
484 485 break;
485 486 case STMF_ERROR_BUSY:
486 487 case STMF_ERROR_LU_BUSY:
487 488 (void) fprintf(stderr, "%s: %s\n", cmdName,
488 489 gettext("resource busy"));
489 490 ret++;
490 491 break;
491 492 case STMF_ERROR_PERM:
492 493 (void) fprintf(stderr, "%s: %s\n", cmdName,
493 494 gettext("permission denied"));
494 495 ret++;
495 496 break;
496 497 case STMF_ERROR_INVALID_BLKSIZE:
497 498 (void) fprintf(stderr, "%s: %s\n", cmdName,
498 499 gettext("invalid block size"));
499 500 ret++;
500 501 break;
501 502 case STMF_ERROR_GUID_IN_USE:
502 503 (void) fprintf(stderr, "%s: %s\n", cmdName,
503 504 gettext("guid in use"));
504 505 ret++;
505 506 break;
506 507 case STMF_ERROR_META_FILE_NAME:
507 508 (void) fprintf(stderr, "%s: %s\n", cmdName,
508 509 gettext("meta file error"));
509 510 ret++;
510 511 break;
511 512 case STMF_ERROR_DATA_FILE_NAME:
512 513 (void) fprintf(stderr, "%s: %s\n", cmdName,
513 514 gettext("data file error"));
514 515 ret++;
515 516 break;
516 517 case STMF_ERROR_FILE_SIZE_INVALID:
517 518 (void) fprintf(stderr, "%s: %s\n", cmdName,
518 519 gettext("file size invalid"));
519 520 ret++;
520 521 break;
521 522 case STMF_ERROR_SIZE_OUT_OF_RANGE:
522 523 (void) fprintf(stderr, "%s: %s\n", cmdName,
523 524 gettext("invalid size"));
524 525 ret++;
525 526 break;
526 527 case STMF_ERROR_META_CREATION:
527 528 (void) fprintf(stderr, "%s: %s\n", cmdName,
528 529 gettext("could not create meta file"));
529 530 ret++;
530 531 break;
531 532 default:
532 533 (void) fprintf(stderr, "%s: %s: %s: %d\n", cmdName,
533 534 gettext("could not set property"), propString,
534 535 stmfRet);
535 536 ret++;
536 537 break;
537 538 }
538 539
539 540 return (ret);
540 541 }
541 542
542 543
543 544 /*ARGSUSED*/
544 545 int
545 546 list_lus(int argc, char *argv[], cmdOptions_t *options, void *callData)
546 547 {
547 548 int stmfRet;
548 549 stmfGuidList *luList;
549 550 stmfLogicalUnitProperties luProps;
550 551 int sbdLuCnt = 0;
551 552 int i;
552 553
553 554 if ((stmfRet = stmfGetLogicalUnitList(&luList))
554 555 != STMF_STATUS_SUCCESS) {
555 556 switch (stmfRet) {
556 557 case STMF_ERROR_SERVICE_NOT_FOUND:
557 558 (void) fprintf(stderr, "%s: %s\n", cmdName,
558 559 gettext("STMF service not found"));
559 560 break;
560 561 case STMF_ERROR_BUSY:
561 562 (void) fprintf(stderr, "%s: %s\n", cmdName,
562 563 gettext("resource busy"));
563 564 break;
564 565 case STMF_ERROR_PERM:
565 566 (void) fprintf(stderr, "%s: %s\n", cmdName,
566 567 gettext("permission denied"));
567 568 break;
568 569 case STMF_ERROR_SERVICE_DATA_VERSION:
569 570 (void) fprintf(stderr, "%s: %s\n", cmdName,
570 571 gettext("STMF service version incorrect"));
571 572 break;
572 573 default:
573 574 (void) fprintf(stderr, "%s: %s\n", cmdName,
574 575 gettext("list failed"));
575 576 break;
576 577 }
577 578 return (1);
578 579 }
579 580
580 581 for (i = 0; i < luList->cnt; i++) {
581 582 stmfRet = stmfGetLogicalUnitProperties(&luList->guid[i],
582 583 &luProps);
583 584 if (stmfRet != STMF_STATUS_SUCCESS) {
584 585 (void) fprintf(stderr, "%s: %s\n", cmdName,
585 586 gettext("list failed"));
586 587 return (1);
587 588 }
588 589 if (strcmp(luProps.providerName, "sbd") == 0) {
589 590 sbdLuCnt++;
590 591 }
591 592 }
592 593
593 594
594 595 if (sbdLuCnt == 0)
595 596 return (0);
596 597
597 598 (void) printf("\nFound %d LU(s)\n", sbdLuCnt);
598 599 print_attr_header();
599 600
600 601 for (i = 0; i < luList->cnt; i++) {
601 602 stmfRet = stmfGetLogicalUnitProperties(&luList->guid[i],
602 603 &luProps);
603 604 if (stmfRet != STMF_STATUS_SUCCESS) {
604 605 (void) fprintf(stderr, "%s: %s\n", cmdName,
605 606 gettext("list failed"));
606 607 return (1);
607 608 }
608 609 if (strcmp(luProps.providerName, "sbd") == 0) {
609 610 (void) print_lu_attr(&luList->guid[i]);
610 611 }
611 612 }
612 613 return (0);
613 614 }
614 615
615 616 void
616 617 print_attr_header()
617 618 {
618 619 (void) printf("\n");
619 620 (void) printf(" GUID DATA SIZE "
620 621 " SOURCE\n");
621 622 (void) printf("-------------------------------- -------------------"
622 623 " ----------------\n");
623 624 }
624 625
625 626 void
626 627 print_guid(uint8_t *g, FILE *f)
627 628 {
628 629 int i;
629 630
630 631 for (i = 0; i < 16; i++) {
631 632 (void) fprintf(f, "%02x", g[i]);
632 633 }
633 634 }
634 635
635 636 int
636 637 print_lu_attr(stmfGuid *guid)
637 638 {
638 639 luResource hdl = NULL;
639 640 int stmfRet = 0;
640 641 int ret = 0;
641 642 char propVal[MAXPATHLEN];
642 643 size_t propValSize = sizeof (propVal);
643 644
644 645 if ((stmfRet = stmfGetLuResource(guid, &hdl)) != STMF_STATUS_SUCCESS) {
645 646 switch (stmfRet) {
646 647 case STMF_ERROR_BUSY:
647 648 (void) fprintf(stderr, "%s: %s\n", cmdName,
648 649 gettext("resource busy"));
649 650 break;
650 651 case STMF_ERROR_PERM:
651 652 (void) fprintf(stderr, "%s: %s\n", cmdName,
652 653 gettext("permission denied"));
653 654 break;
654 655 case STMF_ERROR_NOT_FOUND:
655 656 /* No error here */
656 657 return (0);
657 658 default:
658 659 (void) fprintf(stderr, "%s: %s\n", cmdName,
659 660 gettext("get extended properties failed"));
660 661 break;
661 662 }
662 663 return (1);
663 664 }
664 665
665 666 print_guid((uint8_t *)guid, stdout);
666 667
667 668 stmfRet = stmfGetLuProp(hdl, STMF_LU_PROP_SIZE, propVal,
668 669 &propValSize);
669 670 if (stmfRet == STMF_STATUS_SUCCESS) {
670 671 (void) printf(" %-19s ", propVal);
671 672 } else if (stmfRet == STMF_ERROR_NO_PROP) {
672 673 (void) printf("not set\n");
673 674 } else {
674 675 (void) printf("<error retrieving property>\n");
675 676 ret++;
676 677 }
677 678
678 679 stmfRet = stmfGetLuProp(hdl, STMF_LU_PROP_FILENAME, propVal,
679 680 &propValSize);
680 681 if (stmfRet == STMF_STATUS_SUCCESS) {
681 682 (void) printf("%s\n", propVal);
682 683 } else if (stmfRet == STMF_ERROR_NO_PROP) {
683 684 (void) printf("not set\n");
684 685 } else {
685 686 (void) printf("<error retrieving property>\n");
686 687 ret++;
687 688 }
688 689
689 690
690 691 (void) stmfFreeLuResource(hdl);
691 692 return (ret);
692 693 }
693 694
694 695 /*
695 696 * input:
696 697 * execFullName - exec name of program (argv[0])
697 698 *
698 699 * copied from usr/src/cmd/zoneadm/zoneadm.c in OS/Net
699 700 * (changed name to lowerCamelCase to keep consistent with this file)
700 701 *
701 702 * Returns:
702 703 * command name portion of execFullName
703 704 */
704 705 static char *
705 706 getExecBasename(char *execFullname)
706 707 {
707 708 char *lastSlash, *execBasename;
708 709
709 710 /* guard against '/' at end of command invocation */
710 711 for (;;) {
711 712 lastSlash = strrchr(execFullname, '/');
712 713 if (lastSlash == NULL) {
713 714 execBasename = execFullname;
714 715 break;
715 716 } else {
716 717 execBasename = lastSlash + 1;
717 718 if (*execBasename == '\0') {
718 719 *lastSlash = '\0';
719 720 continue;
720 721 }
721 722 break;
722 723 }
723 724 }
724 725 return (execBasename);
725 726 }
726 727 int
727 728 main(int argc, char *argv[])
728 729 {
729 730 synTables_t synTables;
730 731 char versionString[VERSION_STRING_MAX_LEN];
731 732 int ret;
732 733 int funcRet;
733 734 void *subcommandArgs = NULL;
734 735
735 736 (void) setlocale(LC_ALL, "");
736 737 (void) textdomain(TEXT_DOMAIN);
737 738 /* set global command name */
738 739 cmdName = getExecBasename(argv[0]);
739 740
740 741 (void) snprintf(versionString, VERSION_STRING_MAX_LEN, "%s.%s",
741 742 VERSION_STRING_MAJOR, VERSION_STRING_MINOR);
742 743 synTables.versionString = versionString;
743 744 synTables.longOptionTbl = options;
744 745 synTables.subCommandPropsTbl = subCommands;
745 746
746 747 ret = cmdParse(argc, argv, synTables, subcommandArgs, &funcRet);
747 748 if (ret != 0) {
748 749 return (ret);
749 750 }
750 751
751 752 return (funcRet);
752 753 } /* end main */
↓ open down ↓ |
423 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX