Print this page
patch cleanup
6659 nvlist_free(NULL) is a no-op
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/fm/modules/common/disk-monitor/diskmon_conf.c
+++ new/usr/src/cmd/fm/modules/common/disk-monitor/diskmon_conf.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.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
↓ open down ↓ |
16 lines elided |
↑ open up ↑ |
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21
22 22 /*
23 23 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
24 24 * Use is subject to license terms.
25 25 */
26 26
27 -#pragma ident "%Z%%M% %I% %E% SMI"
28 -
29 27 /*
30 28 * Disk & Indicator Monitor configuration file support routines
31 29 */
32 30
33 31 #include <sys/types.h>
34 32 #include <sys/stat.h>
35 33 #include <fcntl.h>
36 34 #include <unistd.h>
37 35 #include <string.h>
38 36 #include <strings.h>
39 37 #include <errno.h>
40 38 #include <limits.h>
41 39 #include <pthread.h>
42 40
43 41 #include "disk_monitor.h"
44 42 #include "util.h"
45 43 #include "topo_gather.h"
46 44
47 45 extern log_class_t g_verbose;
48 46
49 47 const char *
50 48 hotplug_state_string(hotplug_state_t state)
51 49 {
52 50 switch (state & ~HPS_FAULTED) {
53 51 default:
54 52 case HPS_UNKNOWN:
55 53 return ("Unknown");
56 54 case HPS_ABSENT:
57 55 return ("Absent");
58 56 case HPS_PRESENT:
59 57 return ("Present");
60 58 case HPS_CONFIGURED:
61 59 return ("Configured");
62 60 case HPS_UNCONFIGURED:
63 61 return ("Unconfigured");
64 62 }
65 63 }
66 64
67 65 void
68 66 conf_error_msg(conf_err_t err, char *buf, int buflen, void *arg)
69 67 {
70 68 switch (err) {
71 69 case E_MULTIPLE_IND_LISTS_DEFINED:
72 70 (void) snprintf(buf, buflen, "Multiple Indicator lists "
73 71 "defined");
74 72 break;
75 73 case E_MULTIPLE_INDRULE_LISTS_DEFINED:
76 74 (void) snprintf(buf, buflen, "Multiple Indicator rule lists "
77 75 "defined");
78 76 break;
79 77 case E_INVALID_STATE_CHANGE:
80 78 (void) snprintf(buf, buflen, "Invalid state change");
81 79 break;
82 80 case E_IND_MULTIPLY_DEFINED:
83 81 (void) snprintf(buf, buflen,
84 82 "Multiple Indicator definitions (name & state) detected");
85 83 break;
86 84 case E_IND_ACTION_REDUNDANT:
87 85 (void) snprintf(buf, buflen, "Redundant Indicator actions "
88 86 "specified");
89 87 break;
90 88 case E_IND_ACTION_CONFLICT:
91 89 (void) snprintf(buf, buflen, "Indicator action conflict (+/- "
92 90 "same Indicator) found");
93 91 break;
94 92 case E_IND_MISSING_FAULT_ON:
95 93 (void) snprintf(buf, buflen, "Missing declaration of `+"
96 94 INDICATOR_FAULT_IDENTIFIER "'");
97 95 break;
98 96 case E_IND_MISSING_FAULT_OFF:
99 97 (void) snprintf(buf, buflen, "Missing declaration of `-"
100 98 INDICATOR_FAULT_IDENTIFIER "'");
101 99 break;
102 100 case E_INDRULE_REFERENCES_NONEXISTENT_IND_ACTION:
103 101 (void) snprintf(buf, buflen, "`%c%s': Undefined Indicator in "
104 102 BAY_IND_ACTION " property",
105 103 (((ind_action_t *)arg)->ind_state == INDICATOR_ON)
106 104 ? '+' : '-',
107 105 ((ind_action_t *)arg)->ind_name);
108 106 break;
109 107 case E_DUPLICATE_STATE_TRANSITION:
110 108 (void) snprintf(buf, buflen, "Duplicate state transition "
111 109 "(%s -> %s)",
112 110 hotplug_state_string(((state_transition_t *)arg)->begin),
113 111 hotplug_state_string(((state_transition_t *)arg)->end));
114 112 break;
115 113 default:
116 114 (void) snprintf(buf, buflen, "Unknown error");
117 115 break;
118 116 }
119 117 }
120 118
121 119 static int
122 120 string_to_integer(const char *prop, int *value)
123 121 {
124 122 long val;
125 123
126 124 errno = 0;
127 125
128 126 val = strtol(prop, NULL, 0);
129 127
130 128 if (val == 0 && errno != 0)
131 129 return (-1);
132 130 else if (val > INT_MAX || val < INT_MIN) {
133 131 errno = ERANGE;
134 132 return (-1);
135 133 }
136 134
137 135 if (value != NULL)
138 136 *value = (int)val;
139 137
140 138 return (0);
141 139 }
142 140
143 141 const char *
144 142 dm_prop_lookup(nvlist_t *props, const char *prop_name)
145 143 {
146 144 char *str;
147 145
148 146 if (nvlist_lookup_string(props, prop_name, &str) == 0)
149 147 return ((const char *)str);
150 148 else
151 149 return (NULL);
152 150 }
153 151
154 152 int
155 153 dm_prop_lookup_int(nvlist_t *props, const char *prop_name, int *value)
156 154 {
157 155 const char *prop = dm_prop_lookup(props, prop_name);
158 156
159 157 if (prop == NULL)
160 158 return (-1);
161 159
162 160 return (string_to_integer(prop, value));
163 161 }
164 162
165 163 nvlist_t *
166 164 namevalpr_to_nvlist(namevalpr_t *nvprp)
167 165 {
168 166 nvlist_t *nvlp = NULL;
169 167
170 168 if (nvlist_alloc(&nvlp, NV_UNIQUE_NAME, 0) != 0) {
171 169 return (NULL);
172 170 }
173 171
174 172 if (nvlist_add_string(nvlp, nvprp->name, nvprp->value) != 0) {
175 173 nvlist_free(nvlp);
176 174 return (NULL);
177 175 }
178 176
179 177 return (nvlp);
180 178 }
181 179
182 180 indicator_t *
183 181 new_indicator(ind_state_t lstate, char *namep, char *actionp)
184 182 {
185 183 indicator_t *newindicator =
186 184 (indicator_t *)dmalloc(sizeof (indicator_t));
187 185 newindicator->ind_state = lstate;
188 186 newindicator->ind_name = namep ? dstrdup(namep) : NULL;
189 187 newindicator->ind_instr_spec = actionp ? dstrdup(actionp) : NULL;
190 188 newindicator->next = NULL;
191 189 return (newindicator);
192 190 }
193 191
194 192 void
195 193 link_indicator(indicator_t **first, indicator_t *to_add)
196 194 {
197 195 indicator_t *travptr;
198 196 dm_assert(first != NULL);
199 197
200 198 if (*first == NULL)
201 199 *first = to_add;
202 200 else {
203 201 travptr = *first;
204 202 while (travptr->next != NULL) {
205 203 travptr = travptr->next;
206 204 }
207 205 travptr->next = to_add;
208 206 }
209 207 }
210 208
211 209 void
212 210 ind_free(indicator_t *indp)
213 211 {
214 212 indicator_t *nextp;
215 213
216 214 while (indp != NULL) {
217 215 nextp = indp->next;
218 216 if (indp->ind_name)
219 217 dstrfree(indp->ind_name);
220 218 if (indp->ind_instr_spec)
221 219 dstrfree(indp->ind_instr_spec);
222 220 dfree(indp, sizeof (indicator_t));
223 221 indp = nextp;
224 222 }
225 223 }
226 224
227 225 ind_action_t *
228 226 new_indaction(ind_state_t state, char *namep)
229 227 {
230 228 ind_action_t *lap = (ind_action_t *)dmalloc(sizeof (ind_action_t));
231 229 lap->ind_state = state;
232 230 lap->ind_name = namep ? dstrdup(namep) : NULL;
233 231 lap->next = NULL;
234 232 return (lap);
235 233 }
236 234
237 235 void
238 236 link_indaction(ind_action_t **first, ind_action_t *to_add)
239 237 {
240 238 ind_action_t *travptr;
241 239 dm_assert(first != NULL);
242 240
243 241 if (*first == NULL)
244 242 *first = to_add;
245 243 else {
246 244 travptr = *first;
247 245 while (travptr->next != NULL) {
248 246 travptr = travptr->next;
249 247 }
250 248 travptr->next = to_add;
251 249 }
252 250 }
253 251
254 252 void
255 253 indaction_free(ind_action_t *lap)
256 254 {
257 255 ind_action_t *nextp;
258 256
259 257 /* Free the whole list */
260 258 while (lap != NULL) {
261 259 nextp = lap->next;
262 260 if (lap->ind_name)
263 261 dstrfree(lap->ind_name);
264 262 dfree(lap, sizeof (ind_action_t));
265 263 lap = nextp;
266 264 }
267 265 }
268 266
269 267 indrule_t *
270 268 new_indrule(state_transition_t *st, ind_action_t *actionp)
271 269 {
272 270 indrule_t *lrp = (indrule_t *)dmalloc(sizeof (indrule_t));
273 271 if (st != NULL)
274 272 lrp->strans = *st;
275 273 lrp->action_list = actionp;
276 274 lrp->next = NULL;
277 275 return (lrp);
278 276 }
279 277
280 278 void
281 279 link_indrule(indrule_t **first, indrule_t *to_add)
282 280 {
283 281 indrule_t *travptr;
284 282 dm_assert(first != NULL);
285 283
286 284 if (*first == NULL)
287 285 *first = to_add;
288 286 else {
289 287 travptr = *first;
290 288 while (travptr->next != NULL) {
291 289 travptr = travptr->next;
292 290 }
293 291 travptr->next = to_add;
294 292 }
295 293 }
296 294
297 295 void
298 296 indrule_free(indrule_t *lrp)
299 297 {
300 298 indrule_t *nextp;
301 299
302 300 /* Free the whole list */
303 301 while (lrp != NULL) {
304 302 nextp = lrp->next;
305 303 if (lrp->action_list)
306 304 indaction_free(lrp->action_list);
307 305 dfree(lrp, sizeof (indrule_t));
308 306 lrp = nextp;
309 307 }
310 308 }
311 309
312 310 dm_fru_t *
313 311 new_dmfru(char *manu, char *modl, char *firmrev, char *serno, uint64_t capa)
314 312 {
315 313 dm_fru_t *frup = (dm_fru_t *)dzmalloc(sizeof (dm_fru_t));
316 314
317 315 bcopy(manu, frup->manuf, MIN(sizeof (frup->manuf), strlen(manu) + 1));
318 316 bcopy(modl, frup->model, MIN(sizeof (frup->model), strlen(modl) + 1));
319 317 bcopy(firmrev, frup->rev, MIN(sizeof (frup->rev), strlen(firmrev) + 1));
320 318 bcopy(serno, frup->serial,
321 319 MIN(sizeof (frup->serial), strlen(serno) + 1));
322 320 frup->size_in_bytes = capa;
323 321 return (frup);
324 322 }
325 323
326 324 void
327 325 dmfru_free(dm_fru_t *frup)
328 326 {
329 327 dfree(frup, sizeof (dm_fru_t));
330 328 }
331 329
332 330 diskmon_t *
333 331 new_diskmon(nvlist_t *app_props, indicator_t *indp, indrule_t *indrp,
334 332 nvlist_t *nvlp)
335 333 {
336 334 diskmon_t *dmp = (diskmon_t *)dmalloc(sizeof (diskmon_t));
337 335
338 336 if (nvlp != NULL)
339 337 dmp->props = nvlp;
340 338 else
341 339 (void) nvlist_alloc(&dmp->props, NV_UNIQUE_NAME, 0);
342 340
343 341 if (app_props)
344 342 dmp->app_props = app_props;
345 343 else
346 344 (void) nvlist_alloc(&dmp->app_props, NV_UNIQUE_NAME, 0);
347 345 dmp->ind_list = indp;
348 346 dmp->indrule_list = indrp;
349 347
350 348 dm_assert(pthread_mutex_init(&dmp->manager_mutex, NULL) == 0);
351 349
352 350 dmp->state = HPS_UNKNOWN;
353 351
354 352 dmp->initial_configuration = B_TRUE;
355 353
356 354 dm_assert(pthread_mutex_init(&dmp->fault_indicator_mutex, NULL) == 0);
357 355 dmp->fault_indicator_state = INDICATOR_UNKNOWN;
358 356
359 357 dmp->configured_yet = B_FALSE;
360 358 dmp->state_change_count = 0;
361 359
362 360 dm_assert(pthread_mutex_init(&dmp->fru_mutex, NULL) == 0);
363 361 dmp->frup = NULL;
364 362
365 363 dmp->next = NULL;
366 364 return (dmp);
367 365 }
↓ open down ↓ |
329 lines elided |
↑ open up ↑ |
368 366
369 367 void
370 368 diskmon_free(diskmon_t *dmp)
371 369 {
372 370 diskmon_t *nextp;
373 371
374 372 /* Free the whole list */
375 373 while (dmp != NULL) {
376 374 nextp = dmp->next;
377 375
378 - if (dmp->props)
379 - nvlist_free(dmp->props);
376 + nvlist_free(dmp->props);
380 377 if (dmp->location)
381 378 dstrfree(dmp->location);
382 379 if (dmp->ind_list)
383 380 ind_free(dmp->ind_list);
384 381 if (dmp->indrule_list)
385 382 indrule_free(dmp->indrule_list);
386 - if (dmp->app_props)
387 - nvlist_free(dmp->app_props);
383 + nvlist_free(dmp->app_props);
388 384 if (dmp->frup)
389 385 dmfru_free(dmp->frup);
390 386 dfree(dmp, sizeof (diskmon_t));
391 387
392 388 dmp = nextp;
393 389 }
394 390 }
395 391
396 392 static cfgdata_t *
397 393 new_cfgdata(namevalpr_t *nvp, diskmon_t *dmp)
398 394 {
399 395 cfgdata_t *cdp = (cfgdata_t *)dzmalloc(sizeof (cfgdata_t));
400 396
401 397 if (nvp != NULL)
402 398 cdp->props = namevalpr_to_nvlist(nvp);
403 399 else if (nvlist_alloc(&cdp->props, NV_UNIQUE_NAME, 0) != 0) {
404 400 return (NULL);
405 401 }
406 402
407 403 if (dmp != NULL)
408 404 cdp->disk_list = dmp;
409 405 return (cdp);
410 406
411 407 }
412 408
413 409 static void
414 410 cfgdata_add_namevalpr(cfgdata_t *cfgp, namevalpr_t *nvp)
415 411 {
416 412 if (cfgp->props == NULL) {
417 413 (void) nvlist_alloc(&cfgp->props, NV_UNIQUE_NAME, 0);
418 414 }
419 415 (void) nvlist_add_string(cfgp->props, nvp->name, nvp->value);
420 416 }
421 417
422 418 void
423 419 cfgdata_add_diskmon(cfgdata_t *cfgp, diskmon_t *dmp)
424 420 {
425 421 if (cfgp->disk_list == NULL) {
426 422 cfgp->disk_list = dmp;
427 423 } else {
428 424 diskmon_t *disklist = cfgp->disk_list;
429 425
430 426 while (disklist->next != NULL)
431 427 disklist = disklist->next;
432 428
433 429 disklist->next = dmp;
434 430 }
435 431 }
436 432
437 433 static void
438 434 cfgdata_free(cfgdata_t *cdp)
439 435 {
440 436 nvlist_free(cdp->props);
441 437 diskmon_free(cdp->disk_list);
442 438 dfree(cdp, sizeof (cfgdata_t));
443 439 }
444 440
445 441 conf_err_t
446 442 check_indactions(ind_action_t *indrp)
447 443 {
448 444 char *buf;
449 445 conf_err_t rv = E_NO_ERROR;
450 446 nvlist_t *nvp = NULL;
451 447 int len;
452 448
453 449 (void) nvlist_alloc(&nvp, NV_UNIQUE_NAME, 0);
454 450
455 451 /*
456 452 * Check indicator actions for conflicts
457 453 */
458 454 while (indrp != NULL && rv == E_NO_ERROR) {
459 455 len = strlen(indrp->ind_name) + 2;
460 456 buf = dmalloc(len);
461 457 (void) snprintf(buf, len, "%c%s",
462 458 indrp->ind_state == INDICATOR_ON ? '+' : '-',
463 459 indrp->ind_name);
464 460 switch (nvlist_lookup_boolean(nvp, buf)) {
465 461 case ENOENT:
466 462 (void) nvlist_add_boolean(nvp, buf);
467 463 break;
468 464 case 0:
469 465 rv = E_IND_ACTION_REDUNDANT;
470 466 break;
471 467 default:
472 468 break;
473 469 }
474 470
475 471 /* Look for the opposite action. If found, that's an error */
476 472 (void) snprintf(buf, len, "%c%s",
477 473 indrp->ind_state == INDICATOR_ON ? '-' : '+',
478 474 indrp->ind_name);
479 475 switch (nvlist_lookup_boolean(nvp, buf)) {
480 476 case ENOENT:
481 477 break;
482 478 case 0:
483 479 rv = E_IND_ACTION_CONFLICT;
484 480 break;
485 481 default:
486 482 break;
487 483 }
488 484 dfree(buf, len);
489 485 indrp = indrp->next;
490 486 }
491 487
492 488 nvlist_free(nvp);
493 489 return (rv);
494 490 }
495 491
496 492 conf_err_t
497 493 check_inds(indicator_t *indp)
498 494 {
499 495 char *buf;
500 496 conf_err_t rv = E_NO_ERROR;
501 497 nvlist_t *nvp = NULL;
502 498 int len;
503 499 boolean_t fault_on = B_FALSE, fault_off = B_FALSE;
504 500
505 501 (void) nvlist_alloc(&nvp, NV_UNIQUE_NAME, 0);
506 502
507 503 /*
508 504 * Check inds for multiple definitions (same identifier or same action)
509 505 */
510 506 while (indp != NULL && rv == E_NO_ERROR) {
511 507 len = strlen(indp->ind_name) + 2;
512 508 buf = dmalloc(len);
513 509 (void) snprintf(buf, len, "%c%s",
514 510 indp->ind_state == INDICATOR_ON ? '+' : '-',
515 511 indp->ind_name);
516 512
517 513 /* Keep track of the +/-FAULT for checking later */
518 514 if (strcasecmp(buf, "+" INDICATOR_FAULT_IDENTIFIER) == 0)
519 515 fault_on = B_TRUE;
520 516 else if (strcasecmp(buf, "-" INDICATOR_FAULT_IDENTIFIER) == 0)
521 517 fault_off = B_TRUE;
522 518
523 519 switch (nvlist_lookup_boolean(nvp, buf)) {
524 520 case ENOENT:
525 521 (void) nvlist_add_boolean(nvp, buf);
526 522 break;
527 523 case 0:
528 524 rv = E_IND_MULTIPLY_DEFINED;
529 525 break;
530 526 default:
531 527 break;
532 528 }
533 529 dfree(buf, len);
534 530 indp = indp->next;
535 531 }
536 532
537 533 /*
538 534 * Make sure we have a -FAULT and +FAULT
539 535 */
540 536 if (!fault_on)
541 537 rv = E_IND_MISSING_FAULT_ON;
542 538 else if (!fault_off)
543 539 rv = E_IND_MISSING_FAULT_OFF;
544 540
545 541 nvlist_free(nvp);
546 542 return (rv);
547 543 }
548 544
549 545 conf_err_t
550 546 check_indrules(indrule_t *indrp, state_transition_t **offender)
551 547 {
552 548 char buf[32];
553 549 conf_err_t rv = E_NO_ERROR;
554 550 nvlist_t *nvp = NULL;
555 551
556 552 /*
557 553 * Ensure that no two rules have the same state transitions.
558 554 */
559 555
560 556 (void) nvlist_alloc(&nvp, NV_UNIQUE_NAME, 0);
561 557
562 558 while (indrp != NULL && rv == E_NO_ERROR) {
563 559 (void) snprintf(buf, sizeof (buf), "%d-%d",
564 560 (int)indrp->strans.begin, (int)indrp->strans.end);
565 561 switch (nvlist_lookup_boolean(nvp, buf)) {
566 562 case 0:
567 563 *offender = &indrp->strans;
568 564 rv = E_DUPLICATE_STATE_TRANSITION;
569 565 break;
570 566 case ENOENT:
571 567 (void) nvlist_add_boolean(nvp, buf);
572 568 break;
573 569 default:
574 570 break;
575 571 }
576 572 indrp = indrp->next;
577 573 }
578 574
579 575 nvlist_free(nvp);
580 576 return (rv);
581 577 }
582 578
583 579
584 580 conf_err_t
585 581 check_consistent_ind_indrules(indicator_t *indp, indrule_t *indrp,
586 582 ind_action_t **offender)
587 583 {
588 584 char *buf;
589 585 conf_err_t rv = E_NO_ERROR;
590 586 nvlist_t *nvp = NULL;
591 587 ind_action_t *alp;
592 588 int len;
593 589
594 590 /*
595 591 * Ensure that every indicator action referenced in each ruleset
596 592 * exists in the indicator list given.
597 593 */
598 594
599 595 (void) nvlist_alloc(&nvp, NV_UNIQUE_NAME, 0);
600 596
601 597 while (indp != NULL) {
602 598 len = strlen(indp->ind_name) + 2;
603 599 buf = dmalloc(len);
604 600 (void) snprintf(buf, len, "%c%s",
605 601 indp->ind_state == INDICATOR_ON ? '+' : '-',
606 602 indp->ind_name);
607 603 (void) nvlist_add_boolean(nvp, buf);
608 604 dfree(buf, len);
609 605 indp = indp->next;
610 606 }
611 607
612 608 while (indrp != NULL && rv == E_NO_ERROR) {
613 609 alp = indrp->action_list;
614 610 while (alp != NULL && rv == E_NO_ERROR) {
615 611 len = strlen(alp->ind_name) + 2;
616 612 buf = dmalloc(len);
617 613 (void) snprintf(buf, len, "%c%s",
618 614 alp->ind_state == INDICATOR_ON ? '+' : '-',
619 615 alp->ind_name);
620 616
621 617 switch (nvlist_lookup_boolean(nvp, buf)) {
622 618 case 0: /* Normal case */
623 619 break;
624 620 case ENOENT:
625 621 *offender = alp;
626 622 rv =
627 623 E_INDRULE_REFERENCES_NONEXISTENT_IND_ACTION;
628 624 break;
629 625 default:
630 626 break;
631 627 }
632 628 dfree(buf, len);
633 629 alp = alp->next;
634 630 }
635 631 indrp = indrp->next;
636 632 }
637 633
638 634 nvlist_free(nvp);
639 635 return (rv);
640 636 }
641 637
642 638 conf_err_t
643 639 check_state_transition(hotplug_state_t s1, hotplug_state_t s2)
644 640 {
645 641 /*
646 642 * The following are valid transitions:
647 643 *
648 644 * HPS_ABSENT -> HPS_PRESENT
649 645 * HPS_ABSENT -> HPS_CONFIGURED
650 646 * HPS_PRESENT -> HPS_CONFIGURED
651 647 * HPS_PRESENT -> HPS_ABSENT
652 648 * HPS_CONFIGURED -> HPS_UNCONFIGURED
653 649 * HPS_CONFIGURED -> HPS_ABSENT
654 650 * HPS_UNCONFIGURED -> HPS_ABSENT
655 651 * HPS_UNCONFIGURED -> HPS_CONFIGURED
656 652 *
657 653 */
658 654 if (s1 == HPS_ABSENT && s2 != HPS_PRESENT && s2 != HPS_CONFIGURED)
659 655 return (E_INVALID_STATE_CHANGE);
660 656 else if (s1 == HPS_PRESENT && (s2 != HPS_CONFIGURED &&
661 657 s2 != HPS_ABSENT))
662 658 return (E_INVALID_STATE_CHANGE);
663 659 else if (s1 == HPS_CONFIGURED && (s2 != HPS_UNCONFIGURED &&
664 660 s2 != HPS_ABSENT))
665 661 return (E_INVALID_STATE_CHANGE);
666 662 else if (s1 == HPS_UNCONFIGURED && (s2 != HPS_ABSENT &&
667 663 s2 != HPS_CONFIGURED))
668 664 return (E_INVALID_STATE_CHANGE);
669 665 else
670 666 return (E_NO_ERROR);
671 667 }
672 668
673 669 static void
674 670 print_inds(indicator_t *indp, FILE *fp, char *prefix)
675 671 {
676 672 char plusminus;
677 673
678 674 (void) fprintf(fp, "%sindicators {\n", prefix);
679 675 while (indp != NULL) {
680 676 plusminus = (indp->ind_state == INDICATOR_ON) ? '+' : '-';
681 677 (void) fprintf(fp, "%s\t%c%s = \"%s\"\n", prefix, plusminus,
682 678 indp->ind_name, indp->ind_instr_spec);
683 679 indp = indp->next;
684 680 }
685 681 (void) fprintf(fp, "%s}\n", prefix);
686 682 }
687 683
688 684 static void
689 685 print_indrules(indrule_t *lrp, FILE *fp, char *prefix)
690 686 {
691 687 char plusminus;
692 688 ind_action_t *lap;
693 689
694 690 (void) fprintf(fp, "%sindicator_rules {\n", prefix);
695 691 while (lrp != NULL) {
696 692 (void) fprintf(fp, "%s\t%12s -> %12s\t{ ", prefix,
697 693 hotplug_state_string(lrp->strans.begin),
698 694 hotplug_state_string(lrp->strans.end));
699 695 lap = lrp->action_list;
700 696 while (lap != NULL) {
701 697 plusminus = (lap->ind_state == INDICATOR_ON)
702 698 ? '+' : '-';
703 699 (void) fprintf(fp, "%c%s", plusminus, lap->ind_name);
704 700 lap = lap->next;
705 701 if (lap != NULL)
706 702 (void) fprintf(fp, ", ");
707 703 }
708 704 (void) fprintf(fp, " }\n");
709 705 lrp = lrp->next;
710 706 }
711 707 (void) fprintf(fp, "%s}\n", prefix);
712 708 }
713 709
714 710 static void
715 711 print_props(nvlist_t *nvlp, FILE *fp, char *prefix)
716 712 {
717 713 nvpair_t *nvp = nvlist_next_nvpair(nvlp, NULL);
718 714 char *name, *str;
719 715
720 716 while (nvp != NULL) {
721 717 dm_assert(nvpair_type(nvp) == DATA_TYPE_STRING);
722 718 name = nvpair_name(nvp);
723 719 (void) nvlist_lookup_string(nvlp, name, &str);
724 720 (void) fprintf(fp, "%s%s = \"%s\"\n", prefix, name, str);
725 721 nvp = nvlist_next_nvpair(nvlp, nvp);
726 722 }
727 723 }
728 724
729 725 static void
730 726 print_ap(nvlist_t *dpp, FILE *fp, char *prefix)
731 727 {
732 728 int len = strlen(prefix) + 2;
733 729 char *buf = dmalloc(len);
734 730
735 731 (void) snprintf(buf, len, "%s\t", prefix);
736 732
737 733 (void) fprintf(fp, "%sap_props {\n", prefix);
738 734 print_props(dpp, fp, buf);
739 735 (void) fprintf(fp, "%s}\n", prefix);
740 736
741 737 dfree(buf, len);
742 738 }
743 739
744 740 static void
745 741 print_disks(diskmon_t *dmp, FILE *fp, char *prefix)
746 742 {
747 743 int len = strlen(prefix) + 2;
748 744 char *buf = dmalloc(len);
749 745
750 746 (void) snprintf(buf, len, "%s\t", prefix);
751 747
752 748 while (dmp != NULL) {
753 749 (void) fprintf(fp, "%sdisk \"%s\" {\n", prefix, dmp->location);
754 750 if (dmp->props) {
755 751 print_props(dmp->props, fp, buf);
756 752 }
757 753 if (dmp->app_props) {
758 754 print_ap(dmp->app_props, fp, buf);
759 755 }
760 756 (void) fprintf(fp, "%s\n", prefix);
761 757 print_inds(dmp->ind_list, fp, buf);
762 758 (void) fprintf(fp, "%s\n", prefix);
763 759 print_indrules(dmp->indrule_list, fp, buf);
764 760 (void) fprintf(fp, "%s}\n", prefix);
765 761
766 762 if (dmp->next != NULL)
767 763 (void) fprintf(fp, "%s\n", prefix);
768 764
769 765 dmp = dmp->next;
770 766 }
771 767
772 768 dfree(buf, len);
773 769 }
774 770
775 771 static void
776 772 print_cfgdata(cfgdata_t *cfgp, FILE *fp, char *prefix)
777 773 {
778 774 /* First, print the properties, then the disks */
779 775
780 776 print_props(cfgp->props, fp, prefix);
781 777 (void) fprintf(fp, "%s\n", prefix);
782 778 print_disks(cfgp->disk_list, fp, prefix);
783 779 }
784 780
785 781 int
786 782 config_init(void)
787 783 {
788 784 if (init_configuration_from_topo() == 0) {
789 785 config_data = new_cfgdata(NULL, NULL);
790 786 return (0);
791 787 }
792 788 return (-1);
793 789 }
794 790
795 791 int
796 792 config_get(fmd_hdl_t *hdl, const fmd_prop_t *fmd_props)
797 793 {
798 794 int err, i = 0;
799 795 char *str = NULL;
800 796 namevalpr_t nvp;
801 797 uint64_t u64;
802 798 boolean_t intfound = B_FALSE, strfound = B_FALSE;
803 799 #define INT64_BUF_LEN 128
804 800 char buf[INT64_BUF_LEN];
805 801
806 802 u64 = fmd_prop_get_int32(hdl, GLOBAL_PROP_LOG_LEVEL);
807 803 g_verbose = (int)u64;
808 804
809 805 err = update_configuration_from_topo(hdl, NULL);
810 806
811 807 /* Pull in the properties from the DE configuration file */
812 808 while (fmd_props[i].fmdp_name != NULL) {
813 809
814 810 nvp.name = (char *)fmd_props[i].fmdp_name;
815 811
816 812 switch (fmd_props[i].fmdp_type) {
817 813 case FMD_TYPE_UINT32:
818 814 case FMD_TYPE_INT32:
819 815 intfound = B_TRUE;
820 816 u64 = fmd_prop_get_int32(hdl, fmd_props[i].fmdp_name);
821 817 break;
822 818 case FMD_TYPE_UINT64:
823 819 case FMD_TYPE_INT64:
824 820 intfound = B_TRUE;
825 821 u64 = fmd_prop_get_int64(hdl, fmd_props[i].fmdp_name);
826 822 break;
827 823 case FMD_TYPE_STRING:
828 824 strfound = B_TRUE;
829 825 str = fmd_prop_get_string(hdl, fmd_props[i].fmdp_name);
830 826 break;
831 827
832 828 }
833 829
834 830 if (intfound) {
835 831 (void) snprintf(buf, INT64_BUF_LEN, "0x%llx", u64);
836 832 nvp.value = buf;
837 833 intfound = B_FALSE;
838 834 } else if (strfound) {
839 835 nvp.value = str;
840 836 }
841 837
842 838 log_msg(MM_CONF, "Adding property `%s' with value `%s'\n",
843 839 nvp.name, nvp.value);
844 840
845 841 cfgdata_add_namevalpr(config_data, &nvp);
846 842
847 843 if (strfound) {
848 844 strfound = B_FALSE;
849 845 fmd_prop_free_string(hdl, str);
850 846 }
851 847
852 848
853 849 i++;
854 850 }
855 851
856 852 if ((g_verbose & (MM_CONF|MM_OTHER)) == (MM_CONF|MM_OTHER))
857 853 print_cfgdata(config_data, stderr, "");
858 854
859 855 return (err);
860 856 }
861 857
862 858 void
863 859 config_fini(void)
864 860 {
865 861 fini_configuration_from_topo();
866 862 cfgdata_free(config_data);
867 863 config_data = NULL;
868 864 }
869 865
870 866 nvlist_t *
871 867 dm_global_proplist(void)
872 868 {
873 869 return (config_data->props);
874 870 }
↓ open down ↓ |
477 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX