1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 /* 22 * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved. 23 * 24 * platform.c -- interfaces to the platform's configuration information 25 * 26 * this platform.c allows eft to run on Solaris systems. 27 */ 28 29 #include <stdio.h> 30 #include <stdlib.h> 31 #include <string.h> 32 #include <strings.h> 33 #include <ctype.h> 34 #include <dirent.h> 35 #include <libnvpair.h> 36 #include <dlfcn.h> 37 #include <unistd.h> 38 #include <errno.h> 39 #include <stropts.h> 40 #include <sys/types.h> 41 #include <sys/stat.h> 42 #include <sys/wait.h> 43 #include <sys/filio.h> 44 #include <sys/param.h> 45 #include <sys/fm/protocol.h> 46 #include <fm/fmd_api.h> 47 #include <fm/fmd_fmri.h> 48 #include <fm/libtopo.h> 49 #include <fm/topo_hc.h> 50 #include "alloc.h" 51 #include "out.h" 52 #include "tree.h" 53 #include "itree.h" 54 #include "ipath.h" 55 #include "ptree.h" 56 #include "fme.h" 57 #include "stable.h" 58 #include "eval.h" 59 #include "config.h" 60 #include "platform.h" 61 62 extern fmd_hdl_t *Hdl; /* handle from eft.c */ 63 64 /* 65 * Lastcfg points to the last configuration snapshot we made. 66 */ 67 static struct cfgdata *Lastcfg; 68 static fmd_hdl_t *Lasthdl; 69 static fmd_case_t *Lastfmcase; 70 static const char *lastcomp; 71 static int in_getpath; 72 extern struct lut *Usednames; 73 int prune_raw_config = 0; 74 75 static topo_hdl_t *Eft_topo_hdl; 76 77 void * 78 topo_use_alloc(size_t bytes) 79 { 80 void *p = alloc_malloc(bytes, NULL, 0); 81 82 bzero(p, bytes); 83 return (p); 84 } 85 86 void 87 topo_use_free(void *p) 88 { 89 alloc_free(p, NULL, 0); 90 } 91 92 /*ARGSUSED*/ 93 static void * 94 alloc_nv_alloc(nv_alloc_t *nva, size_t size) 95 { 96 return (alloc_malloc(size, NULL, 0)); 97 } 98 99 /*ARGSUSED*/ 100 static void 101 alloc_nv_free(nv_alloc_t *nva, void *p, size_t sz) 102 { 103 alloc_free(p, NULL, 0); 104 } 105 106 const nv_alloc_ops_t Eft_nv_alloc_ops = { 107 NULL, /* nv_ao_init() */ 108 NULL, /* nv_ao_fini() */ 109 alloc_nv_alloc, /* nv_ao_alloc() */ 110 alloc_nv_free, /* nv_ao_free() */ 111 NULL /* nv_ao_reset() */ 112 }; 113 114 nv_alloc_t Eft_nv_hdl; 115 116 static char *Root; 117 static char *Mach; 118 static char *Plat; 119 static char tmpbuf[MAXPATHLEN]; 120 static char numbuf[MAXPATHLEN]; 121 122 /* 123 * platform_globals -- set global variables based on sysinfo() calls 124 */ 125 static void 126 platform_globals() 127 { 128 Root = fmd_prop_get_string(Hdl, "fmd.rootdir"); 129 Mach = fmd_prop_get_string(Hdl, "fmd.machine"); 130 Plat = fmd_prop_get_string(Hdl, "fmd.platform"); 131 } 132 133 static void 134 platform_free_globals() 135 { 136 fmd_prop_free_string(Hdl, Root); 137 fmd_prop_free_string(Hdl, Mach); 138 fmd_prop_free_string(Hdl, Plat); 139 } 140 141 /* 142 * platform_init -- perform any platform-specific initialization 143 */ 144 void 145 platform_init(void) 146 { 147 (void) nv_alloc_init(&Eft_nv_hdl, &Eft_nv_alloc_ops); 148 Eft_topo_hdl = fmd_hdl_topo_hold(Hdl, TOPO_VERSION); 149 platform_globals(); 150 151 out(O_ALTFP, "platform_init() sucessful"); 152 } 153 154 void 155 platform_fini(void) 156 { 157 if (Lastcfg != NULL) { 158 config_free(Lastcfg); 159 Lastcfg = NULL; 160 } 161 fmd_hdl_topo_rele(Hdl, Eft_topo_hdl); 162 platform_free_globals(); 163 (void) nv_alloc_fini(&Eft_nv_hdl); 164 165 out(O_ALTFP, "platform_fini() sucessful"); 166 } 167 168 /* 169 * hc_fmri_nodeize -- convert hc-scheme FMRI to eft compatible format 170 * 171 * this is an internal platform.c helper routine 172 */ 173 static struct node * 174 hc_fmri_nodeize(nvlist_t *hcfmri) 175 { 176 struct node *pathtree = NULL; 177 struct node *tmpn; 178 nvlist_t **hc_prs; 179 uint_t hc_nprs; 180 const char *sname; 181 char *ename; 182 char *eid; 183 int e, r; 184 185 /* 186 * What to do with/about hc-root? Would we have any clue what 187 * to do with it if it weren't /? For now, we don't bother 188 * even looking it up. 189 */ 190 191 /* 192 * Get the hc-list of elements in the FMRI 193 */ 194 if (nvlist_lookup_nvlist_array(hcfmri, FM_FMRI_HC_LIST, 195 &hc_prs, &hc_nprs) != 0) { 196 out(O_ALTFP, "XFILE: hc FMRI missing %s", FM_FMRI_HC_LIST); 197 return (NULL); 198 } 199 200 for (e = 0; e < hc_nprs; e++) { 201 ename = NULL; 202 eid = NULL; 203 r = nvlist_lookup_string(hc_prs[e], FM_FMRI_HC_NAME, &ename); 204 r |= nvlist_lookup_string(hc_prs[e], FM_FMRI_HC_ID, &eid); 205 if (r != 0) { 206 /* probably should bail */ 207 continue; 208 } 209 sname = stable(ename); 210 tmpn = tree_name_iterator( 211 tree_name(sname, IT_VERTICAL, NULL, 0), 212 tree_num(eid, NULL, 0)); 213 214 if (pathtree == NULL) 215 pathtree = tmpn; 216 else 217 (void) tree_name_append(pathtree, tmpn); 218 } 219 220 return (pathtree); 221 } 222 223 /* 224 * platform_getpath -- extract eft-compatible path from ereport 225 */ 226 struct node * 227 platform_getpath(nvlist_t *nvl) 228 { 229 struct node *ret; 230 nvlist_t *dfmri, *real_fmri, *resource; 231 char *scheme; 232 char *path; 233 char *devid; 234 char *tp; 235 uint32_t cpuid; 236 int err; 237 enum {DT_HC, DT_DEVID, DT_TP, DT_DEV, DT_CPU, DT_UNKNOWN} type = 238 DT_UNKNOWN; 239 240 /* Find the detector */ 241 if (nvlist_lookup_nvlist(nvl, FM_EREPORT_DETECTOR, &dfmri) != 0) { 242 out(O_ALTFP, "XFILE: ereport has no detector FMRI"); 243 return (NULL); 244 } 245 246 /* get the scheme from the detector */ 247 if (nvlist_lookup_string(dfmri, FM_FMRI_SCHEME, &scheme) != 0) { 248 out(O_ALTFP, "XFILE: detector FMRI missing scheme"); 249 return (NULL); 250 } 251 252 /* based on scheme, determine type */ 253 if (strcmp(scheme, FM_FMRI_SCHEME_HC) == 0) { 254 /* already in hc scheme */ 255 type = DT_HC; 256 } else if (strcmp(scheme, FM_FMRI_SCHEME_DEV) == 0) { 257 /* 258 * devid takes precedence over tp which takes precedence over 259 * path 260 */ 261 if (nvlist_lookup_string(dfmri, 262 FM_FMRI_DEV_ID, &devid) == 0) 263 type = DT_DEVID; 264 else if (nvlist_lookup_string(dfmri, 265 TOPO_STORAGE_TARGET_PORT_L0ID, &tp) == 0) 266 type = DT_TP; 267 else if (nvlist_lookup_string(dfmri, 268 FM_FMRI_DEV_PATH, &path) == 0) 269 type = DT_DEV; 270 else { 271 out(O_ALTFP, "XFILE: detector FMRI missing %s or %s", 272 FM_FMRI_DEV_ID, FM_FMRI_DEV_PATH); 273 return (NULL); 274 } 275 } else if (strcmp(scheme, FM_FMRI_SCHEME_CPU) == 0) { 276 if (nvlist_lookup_uint32(dfmri, FM_FMRI_CPU_ID, &cpuid) == 0) 277 type = DT_CPU; 278 else { 279 out(O_ALTFP, "XFILE: detector FMRI missing %s", 280 FM_FMRI_CPU_ID); 281 return (NULL); 282 } 283 } else { 284 out(O_ALTFP, "XFILE: detector FMRI not recognized " 285 "(scheme is %s, expect %s or %s or %s)", 286 scheme, FM_FMRI_SCHEME_HC, FM_FMRI_SCHEME_DEV, 287 FM_FMRI_SCHEME_CPU); 288 return (NULL); 289 } 290 291 out(O_ALTFP|O_VERB, "Received ereport in scheme %s", scheme); 292 293 /* take a config snapshot */ 294 lut_free(Usednames, NULL, NULL); 295 Usednames = NULL; 296 in_getpath = 1; 297 if (config_snapshot() == NULL) { 298 if (type == DT_HC) { 299 /* 300 * If hc-scheme use the fmri that was passed in. 301 */ 302 in_getpath = 0; 303 return (hc_fmri_nodeize(dfmri)); 304 } 305 out(O_ALTFP, "XFILE: cannot snapshot configuration"); 306 in_getpath = 0; 307 return (NULL); 308 } 309 310 /* 311 * For hc scheme, if we can find the resource from the tolopogy, use 312 * that - otherwise use the fmri that was passed in. For other schemes 313 * look up the path, cpuid, tp or devid in the topology. 314 */ 315 switch (type) { 316 case DT_HC: 317 if (topo_fmri_getprop(Eft_topo_hdl, dfmri, TOPO_PGROUP_PROTOCOL, 318 TOPO_PROP_RESOURCE, NULL, &resource, &err) == -1) { 319 ret = hc_fmri_nodeize(dfmri); 320 break; 321 } else if (nvlist_lookup_nvlist(resource, 322 TOPO_PROP_VAL_VAL, &real_fmri) != 0) 323 ret = hc_fmri_nodeize(dfmri); 324 else 325 ret = hc_fmri_nodeize(real_fmri); 326 327 nvlist_free(resource); 328 break; 329 330 case DT_DEV: 331 if ((ret = config_bydev_lookup(Lastcfg, path)) == NULL) 332 out(O_ALTFP, "platform_getpath: no configuration node " 333 "has device path matching \"%s\".", path); 334 335 break; 336 337 case DT_TP: 338 if ((ret = config_bytp_lookup(Lastcfg, tp)) == NULL) 339 out(O_ALTFP, "platform_getpath: no configuration node " 340 "has tp matching \"%s\".", tp); 341 break; 342 343 case DT_DEVID: 344 if ((ret = config_bydevid_lookup(Lastcfg, devid)) == NULL) 345 out(O_ALTFP, "platform_getpath: no configuration node " 346 "has devid matching \"%s\".", devid); 347 break; 348 349 case DT_CPU: 350 if ((ret = config_bycpuid_lookup(Lastcfg, cpuid)) == NULL) 351 out(O_ALTFP, "platform_getpath: no configuration node " 352 "has cpu-id matching %u.", cpuid); 353 break; 354 } 355 356 /* free the snapshot */ 357 structconfig_free(Lastcfg->cooked); 358 config_free(Lastcfg); 359 in_getpath = 0; 360 return (ret); 361 } 362 363 /* Allocate space for raw config strings in chunks of this size */ 364 #define STRSBUFLEN 512 365 366 /* 367 * cfgadjust -- Make sure the amount we want to add to the raw config string 368 * buffer will fit, and if not, increase the size of the buffer. 369 */ 370 static void 371 cfgadjust(struct cfgdata *rawdata, int addlen) 372 { 373 int curnext, newlen; 374 375 if (rawdata->nextfree + addlen >= rawdata->end) { 376 newlen = (((rawdata->nextfree - rawdata->begin + 1 + addlen) 377 / STRSBUFLEN) + 1) * STRSBUFLEN; 378 curnext = rawdata->nextfree - rawdata->begin; 379 rawdata->begin = REALLOC(rawdata->begin, newlen); 380 rawdata->nextfree = rawdata->begin + curnext; 381 rawdata->end = rawdata->begin + newlen; 382 } 383 } 384 385 static char * 386 hc_path(tnode_t *node) 387 { 388 int i, err; 389 char *name, *instance, *estr; 390 nvlist_t *fmri, **hcl; 391 ulong_t ul; 392 uint_t nhc; 393 394 if (topo_prop_get_fmri(node, TOPO_PGROUP_PROTOCOL, TOPO_PROP_RESOURCE, 395 &fmri, &err) < 0) 396 return (NULL); 397 398 if (nvlist_lookup_nvlist_array(fmri, FM_FMRI_HC_LIST, &hcl, &nhc) 399 != 0) { 400 nvlist_free(fmri); 401 return (NULL); 402 } 403 404 tmpbuf[0] = '\0'; 405 for (i = 0; i < nhc; ++i) { 406 err = nvlist_lookup_string(hcl[i], FM_FMRI_HC_NAME, &name); 407 err |= nvlist_lookup_string(hcl[i], FM_FMRI_HC_ID, &instance); 408 if (err) { 409 nvlist_free(fmri); 410 return (NULL); 411 } 412 413 ul = strtoul(instance, &estr, 10); 414 /* conversion to number failed? */ 415 if (estr == instance) { 416 nvlist_free(fmri); 417 return (NULL); 418 } 419 420 (void) strlcat(tmpbuf, "/", MAXPATHLEN); 421 (void) strlcat(tmpbuf, name, MAXPATHLEN); 422 (void) snprintf(numbuf, MAXPATHLEN, "%lu", ul); 423 (void) strlcat(tmpbuf, numbuf, MAXPATHLEN); 424 lastcomp = stable(name); 425 } 426 427 nvlist_free(fmri); 428 429 return (tmpbuf); 430 } 431 432 static void 433 add_prop_val(topo_hdl_t *thp, struct cfgdata *rawdata, char *propn, 434 nvpair_t *pv_nvp) 435 { 436 int addlen, err; 437 char *propv, *fmristr = NULL; 438 nvlist_t *fmri; 439 uint32_t ui32; 440 int64_t i64; 441 int32_t i32; 442 boolean_t bool; 443 uint64_t ui64; 444 char buf[32]; /* big enough for any 64-bit int */ 445 uint_t nelem; 446 int i, j, sz; 447 char **propvv; 448 449 /* 450 * malformed prop nvpair 451 */ 452 if (propn == NULL) 453 return; 454 455 switch (nvpair_type(pv_nvp)) { 456 case DATA_TYPE_STRING_ARRAY: 457 /* 458 * Convert string array into single space-separated string 459 */ 460 (void) nvpair_value_string_array(pv_nvp, &propvv, &nelem); 461 for (sz = 0, i = 0; i < nelem; i++) 462 sz += strlen(propvv[i]) + 1; 463 propv = MALLOC(sz); 464 for (j = 0, i = 0; i < nelem; j++, i++) { 465 (void) strcpy(&propv[j], propvv[i]); 466 j += strlen(propvv[i]); 467 if (i < nelem - 1) 468 propv[j] = ' '; 469 } 470 break; 471 472 case DATA_TYPE_STRING: 473 (void) nvpair_value_string(pv_nvp, &propv); 474 break; 475 476 case DATA_TYPE_NVLIST: 477 /* 478 * At least try to collect the protocol 479 * properties 480 */ 481 (void) nvpair_value_nvlist(pv_nvp, &fmri); 482 if (topo_fmri_nvl2str(thp, fmri, &fmristr, &err) < 0) { 483 out(O_ALTFP, "cfgcollect: failed to convert fmri to " 484 "string"); 485 return; 486 } else { 487 propv = fmristr; 488 } 489 break; 490 491 case DATA_TYPE_UINT64: 492 /* 493 * Convert uint64 to hex strings 494 */ 495 (void) nvpair_value_uint64(pv_nvp, &ui64); 496 (void) snprintf(buf, sizeof (buf), "0x%llx", ui64); 497 propv = buf; 498 break; 499 500 case DATA_TYPE_BOOLEAN_VALUE: 501 /* 502 * Convert boolean_t to hex strings 503 */ 504 (void) nvpair_value_boolean_value(pv_nvp, &bool); 505 (void) snprintf(buf, sizeof (buf), "0x%llx", (uint64_t)bool); 506 propv = buf; 507 break; 508 509 case DATA_TYPE_INT32: 510 /* 511 * Convert int32 to hex strings 512 */ 513 (void) nvpair_value_int32(pv_nvp, &i32); 514 (void) snprintf(buf, sizeof (buf), "0x%llx", 515 (uint64_t)(int64_t)i32); 516 propv = buf; 517 break; 518 519 case DATA_TYPE_INT64: 520 /* 521 * Convert int64 to hex strings 522 */ 523 (void) nvpair_value_int64(pv_nvp, &i64); 524 (void) snprintf(buf, sizeof (buf), "0x%llx", (uint64_t)i64); 525 propv = buf; 526 break; 527 528 case DATA_TYPE_UINT32: 529 /* 530 * Convert uint32 to hex strings 531 */ 532 (void) nvpair_value_uint32(pv_nvp, &ui32); 533 (void) snprintf(buf, sizeof (buf), "0x%llx", (uint64_t)ui32); 534 propv = buf; 535 break; 536 537 default: 538 out(O_ALTFP, "cfgcollect: failed to get property value for " 539 "%s", propn); 540 return; 541 } 542 543 /* = & NULL */ 544 addlen = strlen(propn) + strlen(propv) + 2; 545 cfgadjust(rawdata, addlen); 546 (void) snprintf(rawdata->nextfree, 547 rawdata->end - rawdata->nextfree, "%s=%s", 548 propn, propv); 549 if (strcmp(propn, TOPO_PROP_RESOURCE) == 0) 550 out(O_ALTFP|O_VERB3, "cfgcollect: %s", propv); 551 552 if (nvpair_type(pv_nvp) == DATA_TYPE_STRING_ARRAY) 553 FREE(propv); 554 555 rawdata->nextfree += addlen; 556 557 if (fmristr != NULL) 558 topo_hdl_strfree(thp, fmristr); 559 } 560 561 /* 562 * cfgcollect -- Assemble raw configuration data in string form suitable 563 * for checkpointing. 564 */ 565 static int 566 cfgcollect(topo_hdl_t *thp, tnode_t *node, void *arg) 567 { 568 struct cfgdata *rawdata = (struct cfgdata *)arg; 569 int err, addlen; 570 char *propn, *path = NULL; 571 nvlist_t *p_nv, *pg_nv, *pv_nv; 572 nvpair_t *nvp, *pg_nvp, *pv_nvp; 573 574 if (topo_node_flags(node) == TOPO_NODE_FACILITY) 575 return (TOPO_WALK_NEXT); 576 577 path = hc_path(node); 578 if (path == NULL) 579 return (TOPO_WALK_ERR); 580 581 addlen = strlen(path) + 1; 582 583 cfgadjust(rawdata, addlen); 584 (void) strcpy(rawdata->nextfree, path); 585 rawdata->nextfree += addlen; 586 587 /* 588 * If the prune_raw_config flag is set then we will only include in the 589 * raw config those nodes that are used by the rules remaining after 590 * prune_propagations() has been run - ie only those that could possibly 591 * be relevant to the incoming ereport given the current rules. This 592 * means that any other parts of the config will not get saved to the 593 * checkpoint file (even if they may theoretically be used if the 594 * rules are subsequently modified). 595 * 596 * For now prune_raw_config is 0 for Solaris, though it is expected to 597 * be set to 1 for fmsp. 598 * 599 * Note we only prune the raw config like this if we have been called 600 * from newfme(), not if we have been called when handling dev or cpu 601 * scheme ereports from platform_getpath(), as this is called before 602 * prune_propagations() - again this is not an issue on fmsp as the 603 * ereports are all in hc scheme. 604 */ 605 if (!in_getpath && prune_raw_config && 606 lut_lookup(Usednames, (void *)lastcomp, NULL) == NULL) 607 return (TOPO_WALK_NEXT); 608 609 /* 610 * Collect properties 611 * 612 * eversholt should support alternate property types 613 * Better yet, topo properties could be represented as 614 * a packed nvlist 615 */ 616 p_nv = topo_prop_getprops(node, &err); 617 for (nvp = nvlist_next_nvpair(p_nv, NULL); nvp != NULL; 618 nvp = nvlist_next_nvpair(p_nv, nvp)) { 619 if (strcmp(TOPO_PROP_GROUP, nvpair_name(nvp)) != 0 || 620 nvpair_type(nvp) != DATA_TYPE_NVLIST) 621 continue; 622 623 (void) nvpair_value_nvlist(nvp, &pg_nv); 624 625 for (pg_nvp = nvlist_next_nvpair(pg_nv, NULL); pg_nvp != NULL; 626 pg_nvp = nvlist_next_nvpair(pg_nv, pg_nvp)) { 627 628 if (strcmp(TOPO_PROP_VAL, nvpair_name(pg_nvp)) != 0 || 629 nvpair_type(pg_nvp) != DATA_TYPE_NVLIST) 630 continue; 631 632 (void) nvpair_value_nvlist(pg_nvp, &pv_nv); 633 634 propn = NULL; 635 for (pv_nvp = nvlist_next_nvpair(pv_nv, NULL); 636 pv_nvp != NULL; 637 pv_nvp = nvlist_next_nvpair(pv_nv, pv_nvp)) { 638 639 /* Get property name */ 640 if (strcmp(TOPO_PROP_VAL_NAME, 641 nvpair_name(pv_nvp)) == 0) 642 (void) nvpair_value_string(pv_nvp, 643 &propn); 644 645 /* 646 * Get property value 647 */ 648 if (strcmp(TOPO_PROP_VAL_VAL, 649 nvpair_name(pv_nvp)) == 0) 650 add_prop_val(thp, rawdata, propn, 651 pv_nvp); 652 } 653 654 } 655 } 656 657 nvlist_free(p_nv); 658 659 return (TOPO_WALK_NEXT); 660 } 661 662 void 663 platform_restore_config(fmd_hdl_t *hdl, fmd_case_t *fmcase) 664 { 665 if (hdl == Lasthdl && fmcase == Lastfmcase) { 666 size_t cfglen; 667 668 fmd_buf_read(Lasthdl, Lastfmcase, WOBUF_CFGLEN, (void *)&cfglen, 669 sizeof (size_t)); 670 Lastcfg->begin = MALLOC(cfglen); 671 Lastcfg->end = Lastcfg->nextfree = Lastcfg->begin + cfglen; 672 fmd_buf_read(Lasthdl, Lastfmcase, WOBUF_CFG, Lastcfg->begin, 673 cfglen); 674 Lasthdl = NULL; 675 Lastfmcase = NULL; 676 } 677 } 678 679 void 680 platform_save_config(fmd_hdl_t *hdl, fmd_case_t *fmcase) 681 { 682 size_t cfglen; 683 684 /* 685 * Put the raw config into an fmd_buf. Then we can free it to 686 * save space. 687 */ 688 Lastfmcase = fmcase; 689 Lasthdl = hdl; 690 cfglen = Lastcfg->nextfree - Lastcfg->begin; 691 fmd_buf_create(hdl, fmcase, WOBUF_CFGLEN, sizeof (cfglen)); 692 fmd_buf_write(hdl, fmcase, WOBUF_CFGLEN, (void *)&cfglen, 693 sizeof (cfglen)); 694 if (cfglen != 0) { 695 fmd_buf_create(hdl, fmcase, WOBUF_CFG, cfglen); 696 fmd_buf_write(hdl, fmcase, WOBUF_CFG, Lastcfg->begin, cfglen); 697 } 698 FREE(Lastcfg->begin); 699 Lastcfg->begin = NULL; 700 Lastcfg->end = NULL; 701 Lastcfg->nextfree = NULL; 702 } 703 704 /* 705 * platform_config_snapshot -- gather a snapshot of the current configuration 706 */ 707 struct cfgdata * 708 platform_config_snapshot(void) 709 { 710 int err; 711 topo_walk_t *twp; 712 static uint64_t lastgen; 713 uint64_t curgen; 714 715 /* 716 * If the DR generation number has changed, 717 * we need to grab a new snapshot, otherwise we 718 * can simply point them at the last config. 719 */ 720 if (prune_raw_config == 0 && (curgen = fmd_fmri_get_drgen()) <= 721 lastgen && Lastcfg != NULL) { 722 Lastcfg->raw_refcnt++; 723 /* 724 * if config has been backed away to an fmd_buf, restore it 725 */ 726 if (Lastcfg->begin == NULL) 727 platform_restore_config(Lasthdl, Lastfmcase); 728 return (Lastcfg); 729 } 730 731 lastgen = curgen; 732 /* we're getting a new config, so clean up the last one */ 733 if (Lastcfg != NULL) { 734 if (--Lastcfg->raw_refcnt == 0) { 735 if (Lastcfg->begin != NULL) 736 FREE(Lastcfg->begin); 737 FREE(Lastcfg); 738 } 739 } 740 741 Lastcfg = MALLOC(sizeof (struct cfgdata)); 742 Lastcfg->raw_refcnt = 2; /* caller + Lastcfg */ 743 Lastcfg->begin = Lastcfg->nextfree = Lastcfg->end = NULL; 744 Lastcfg->cooked = NULL; 745 Lastcfg->devcache = NULL; 746 Lastcfg->devidcache = NULL; 747 Lastcfg->tpcache = NULL; 748 Lastcfg->cpucache = NULL; 749 750 751 fmd_hdl_topo_rele(Hdl, Eft_topo_hdl); 752 Eft_topo_hdl = fmd_hdl_topo_hold(Hdl, TOPO_VERSION); 753 754 if ((twp = topo_walk_init(Eft_topo_hdl, FM_FMRI_SCHEME_HC, cfgcollect, 755 Lastcfg, &err)) == NULL) { 756 out(O_DIE, "platform_config_snapshot: NULL topology tree: %s", 757 topo_strerror(err)); 758 } 759 760 if (topo_walk_step(twp, TOPO_WALK_CHILD) == TOPO_WALK_ERR) { 761 topo_walk_fini(twp); 762 out(O_DIE, "platform_config_snapshot: error walking topology " 763 "tree"); 764 } 765 766 topo_walk_fini(twp); 767 out(O_ALTFP|O_STAMP, "raw config complete"); 768 769 770 return (Lastcfg); 771 } 772 773 static const char * 774 cfgstrprop_lookup(struct config *croot, char *path, char *pname) 775 { 776 struct config *cresource; 777 const char *fmristr; 778 779 /* 780 * The first order of business is to find the resource in the 781 * config database so we can examine properties associated with 782 * that node. 783 */ 784 if ((cresource = config_lookup(croot, path, 0)) == NULL) { 785 out(O_ALTFP, "Cannot find config info for %s.", path); 786 return (NULL); 787 } 788 if ((fmristr = config_getprop(cresource, pname)) == NULL) { 789 out(O_ALTFP, "Cannot find %s property for %s resource " 790 "re-write", pname, path); 791 return (NULL); 792 } 793 return (fmristr); 794 } 795 796 /* 797 * Get resource FMRI from libtopo 798 */ 799 /*ARGSUSED*/ 800 void 801 platform_units_translate(int isdefect, struct config *croot, 802 nvlist_t **dfltasru, nvlist_t **dfltfru, nvlist_t **dfltrsrc, char *path) 803 { 804 const char *fmristr; 805 char *serial; 806 nvlist_t *rsrc; 807 int err; 808 809 fmristr = cfgstrprop_lookup(croot, path, TOPO_PROP_RESOURCE); 810 if (fmristr == NULL) { 811 out(O_ALTFP, "Cannot rewrite resource for %s.", path); 812 return; 813 } 814 if (topo_fmri_str2nvl(Eft_topo_hdl, fmristr, &rsrc, &err) < 0) { 815 out(O_ALTFP, "Can not convert config info: %s", 816 topo_strerror(err)); 817 out(O_ALTFP, "Cannot rewrite resource for %s.", path); 818 return; 819 } 820 821 /* 822 * If we don't have a serial number in the resource then check if it 823 * is available as a separate property and if so then add it. 824 */ 825 if (nvlist_lookup_string(rsrc, FM_FMRI_HC_SERIAL_ID, &serial) != 0) { 826 serial = (char *)cfgstrprop_lookup(croot, path, 827 FM_FMRI_HC_SERIAL_ID); 828 if (serial != NULL) 829 (void) nvlist_add_string(rsrc, FM_FMRI_HC_SERIAL_ID, 830 serial); 831 } 832 833 *dfltrsrc = rsrc; 834 } 835 836 /* 837 * platform_get_files -- return names of all files we should load 838 * 839 * search directories in dirname[] for all files with names ending with the 840 * substring fnstr. dirname[] should be a NULL-terminated array. fnstr 841 * may be set to "*" to indicate all files in a directory. 842 * 843 * if nodups is non-zero, then the first file of a given name found is 844 * the only file added to the list of names. for example if nodups is 845 * set and we're looking for .efts, and find a pci.eft in the dirname[0], 846 * then no pci.eft found in any of the other dirname[] entries will be 847 * included in the final list of names. 848 * 849 * this routine doesn't return NULL, even if no files are found (in that 850 * case, a char ** is returned with the first element NULL). 851 */ 852 static char ** 853 platform_get_files(const char *dirname[], const char *fnstr, int nodups) 854 { 855 DIR *dirp; 856 struct dirent *dp; 857 struct lut *foundnames = NULL; 858 char **files = NULL; /* char * array of filenames found */ 859 int nfiles = 0; /* files found so far */ 860 int slots = 0; /* char * slots allocated in files */ 861 size_t fnlen, d_namelen; 862 size_t totlen; 863 int i; 864 static char *nullav; 865 866 ASSERT(fnstr != NULL); 867 fnlen = strlen(fnstr); 868 869 for (i = 0; dirname[i] != NULL; i++) { 870 out(O_DEBUG, "Looking for %s files in %s", fnstr, dirname[i]); 871 if ((dirp = opendir(dirname[i])) == NULL) { 872 out(O_DEBUG|O_SYS, 873 "platform_get_files: opendir failed for %s", 874 dirname[i]); 875 continue; 876 } 877 while ((dp = readdir(dirp)) != NULL) { 878 if ((fnlen == 1 && *fnstr == '*') || 879 ((d_namelen = strlen(dp->d_name)) >= fnlen && 880 strncmp(dp->d_name + d_namelen - fnlen, 881 fnstr, fnlen) == 0)) { 882 883 if (nodups != 0) { 884 const char *snm = stable(dp->d_name); 885 886 if (lut_lookup(foundnames, 887 (void *)snm, 888 NULL) != NULL) { 889 out(O_DEBUG, 890 "platform_get_files: " 891 "skipping repeated name " 892 "%s/%s", 893 dirname[i], 894 snm); 895 continue; 896 } 897 foundnames = lut_add(foundnames, 898 (void *)snm, 899 (void *)snm, 900 NULL); 901 } 902 903 if (nfiles > slots - 2) { 904 /* allocate ten more slots */ 905 slots += 10; 906 files = (char **)REALLOC(files, 907 slots * sizeof (char *)); 908 } 909 /* prepend directory name and / */ 910 totlen = strlen(dirname[i]) + 1; 911 totlen += strlen(dp->d_name) + 1; 912 files[nfiles] = MALLOC(totlen); 913 out(O_DEBUG, "File %d: \"%s/%s\"", nfiles, 914 dirname[i], dp->d_name); 915 (void) snprintf(files[nfiles++], totlen, 916 "%s/%s", dirname[i], dp->d_name); 917 } 918 } 919 (void) closedir(dirp); 920 } 921 922 if (foundnames != NULL) 923 lut_free(foundnames, NULL, NULL); 924 925 if (nfiles == 0) 926 return (&nullav); 927 928 files[nfiles] = NULL; 929 return (files); 930 } 931 932 /* 933 * search for files in a standard set of directories 934 */ 935 static char ** 936 platform_get_files_stddirs(char *fname, int nodups) 937 { 938 const char *dirlist[4]; 939 char **flist; 940 char *eftgendir, *eftmachdir, *eftplatdir; 941 942 eftgendir = MALLOC(MAXPATHLEN); 943 eftmachdir = MALLOC(MAXPATHLEN); 944 eftplatdir = MALLOC(MAXPATHLEN); 945 946 /* Generic files that apply to any machine */ 947 (void) snprintf(eftgendir, MAXPATHLEN, "%s/usr/lib/fm/eft", Root); 948 949 (void) snprintf(eftmachdir, 950 MAXPATHLEN, "%s/usr/platform/%s/lib/fm/eft", Root, Mach); 951 952 (void) snprintf(eftplatdir, 953 MAXPATHLEN, "%s/usr/platform/%s/lib/fm/eft", Root, Plat); 954 955 dirlist[0] = eftplatdir; 956 dirlist[1] = eftmachdir; 957 dirlist[2] = eftgendir; 958 dirlist[3] = NULL; 959 960 flist = platform_get_files(dirlist, fname, nodups); 961 962 FREE(eftplatdir); 963 FREE(eftmachdir); 964 FREE(eftgendir); 965 966 return (flist); 967 } 968 969 /* 970 * platform_run_poller -- execute a poller 971 * 972 * when eft needs to know if a polled ereport exists this routine 973 * is called so the poller code may be run in a platform-specific way. 974 * there's no return value from this routine -- either the polled ereport 975 * is generated (and delivered *before* this routine returns) or not. 976 * any errors, like "poller unknown" are considered platform-specific 977 * should be handled here rather than passing an error back up. 978 */ 979 /*ARGSUSED*/ 980 void 981 platform_run_poller(const char *poller) 982 { 983 } 984 985 /* 986 * fork and execve path with argument array argv and environment array 987 * envp. data from stdout and stderr are placed in outbuf and errbuf, 988 * respectively. 989 * 990 * see execve(2) for more descriptions for path, argv and envp. 991 */ 992 static int 993 forkandexecve(const char *path, char *const argv[], char *const envp[], 994 char *outbuf, size_t outbuflen, char *errbuf, size_t errbuflen) 995 { 996 pid_t pid; 997 int outpipe[2], errpipe[2]; 998 int rt = 0; 999 1000 /* 1001 * run the cmd and see if it failed. this function is *not* a 1002 * generic command runner -- we depend on some knowledge we 1003 * have about the commands we run. first of all, we expect 1004 * errors to spew something to stdout, and that something is 1005 * typically short enough to fit into a pipe so we can wait() 1006 * for the command to complete and then fetch the error text 1007 * from the pipe. 1008 */ 1009 if (pipe(outpipe) < 0) 1010 if (strlcat(errbuf, ": pipe(outpipe) failed", 1011 errbuflen) >= errbuflen) 1012 return (1); 1013 if (pipe(errpipe) < 0) 1014 if (strlcat(errbuf, ": pipe(errpipe) failed", 1015 errbuflen) >= errbuflen) 1016 return (1); 1017 1018 if ((pid = fork()) < 0) { 1019 rt = (int)strlcat(errbuf, ": fork() failed", errbuflen); 1020 } else if (pid) { 1021 int wstat, count; 1022 1023 /* parent */ 1024 (void) close(errpipe[1]); 1025 (void) close(outpipe[1]); 1026 1027 /* PHASE2 need to guard against hang in child? */ 1028 if (waitpid(pid, &wstat, 0) < 0) 1029 if (strlcat(errbuf, ": waitpid() failed", 1030 errbuflen) >= errbuflen) 1031 return (1); 1032 1033 /* check for stderr contents */ 1034 if (ioctl(errpipe[0], FIONREAD, &count) >= 0 && count) { 1035 if (read(errpipe[0], errbuf, errbuflen) <= 0) { 1036 /* 1037 * read failed even though ioctl indicated 1038 * that nonzero bytes were available for 1039 * reading 1040 */ 1041 if (strlcat(errbuf, ": read(errpipe) failed", 1042 errbuflen) >= errbuflen) 1043 return (1); 1044 } 1045 /* 1046 * handle case where errbuf is not properly 1047 * terminated 1048 */ 1049 if (count > errbuflen - 1) 1050 count = errbuflen - 1; 1051 if (errbuf[count - 1] != '\0' && 1052 errbuf[count - 1] != '\n') 1053 errbuf[count] = '\0'; 1054 } else if (WIFSIGNALED(wstat)) 1055 if (strlcat(errbuf, ": signaled", 1056 errbuflen) >= errbuflen) 1057 return (1); 1058 else if (WIFEXITED(wstat) && WEXITSTATUS(wstat)) 1059 if (strlcat(errbuf, ": abnormal exit", 1060 errbuflen) >= errbuflen) 1061 return (1); 1062 1063 /* check for stdout contents */ 1064 if (ioctl(outpipe[0], FIONREAD, &count) >= 0 && count) { 1065 if (read(outpipe[0], outbuf, outbuflen) <= 0) { 1066 /* 1067 * read failed even though ioctl indicated 1068 * that nonzero bytes were available for 1069 * reading 1070 */ 1071 if (strlcat(errbuf, ": read(outpipe) failed", 1072 errbuflen) >= errbuflen) 1073 return (1); 1074 } 1075 /* 1076 * handle case where outbuf is not properly 1077 * terminated 1078 */ 1079 if (count > outbuflen - 1) 1080 count = outbuflen - 1; 1081 if (outbuf[count - 1] != '\0' && 1082 outbuf[count - 1] != '\n') 1083 outbuf[count] = '\0'; 1084 } 1085 1086 (void) close(errpipe[0]); 1087 (void) close(outpipe[0]); 1088 } else { 1089 /* child */ 1090 (void) dup2(errpipe[1], fileno(stderr)); 1091 (void) close(errpipe[0]); 1092 (void) dup2(outpipe[1], fileno(stdout)); 1093 (void) close(outpipe[0]); 1094 1095 if (execve(path, argv, envp)) 1096 perror(path); 1097 _exit(1); 1098 } 1099 1100 return (rt); 1101 } 1102 1103 #define MAXDIGITIDX 23 1104 1105 static int 1106 arglist2argv(struct node *np, struct lut **globals, struct config *croot, 1107 struct arrow *arrowp, char ***argv, int *argc, int *argvlen) 1108 { 1109 struct node *namep; 1110 char numbuf[MAXDIGITIDX + 1]; 1111 char *numstr, *nullbyte; 1112 char *addthisarg = NULL; 1113 1114 if (np == NULL) 1115 return (0); 1116 1117 switch (np->t) { 1118 case T_QUOTE: 1119 addthisarg = STRDUP(np->u.func.s); 1120 break; 1121 case T_LIST: 1122 if (arglist2argv(np->u.expr.left, globals, croot, arrowp, 1123 argv, argc, argvlen)) 1124 return (1); 1125 /* 1126 * only leftmost element of a list can provide the command 1127 * name (after which *argc becomes 1) 1128 */ 1129 ASSERT(*argc > 0); 1130 if (arglist2argv(np->u.expr.right, globals, croot, arrowp, 1131 argv, argc, argvlen)) 1132 return (1); 1133 break; 1134 case T_FUNC: 1135 case T_GLOBID: 1136 case T_ASSIGN: 1137 case T_CONDIF: 1138 case T_CONDELSE: 1139 case T_EQ: 1140 case T_NE: 1141 case T_LT: 1142 case T_LE: 1143 case T_GT: 1144 case T_GE: 1145 case T_BITAND: 1146 case T_BITOR: 1147 case T_BITXOR: 1148 case T_BITNOT: 1149 case T_LSHIFT: 1150 case T_RSHIFT: 1151 case T_AND: 1152 case T_OR: 1153 case T_NOT: 1154 case T_ADD: 1155 case T_SUB: 1156 case T_MUL: 1157 case T_DIV: 1158 case T_MOD: { 1159 struct evalue value; 1160 1161 if (!eval_expr(np, NULL, NULL, globals, croot, arrowp, 1162 0, &value)) 1163 return (1); 1164 1165 switch (value.t) { 1166 case UINT64: 1167 numbuf[MAXDIGITIDX] = '\0'; 1168 nullbyte = &numbuf[MAXDIGITIDX]; 1169 numstr = ulltostr(value.v, nullbyte); 1170 addthisarg = STRDUP(numstr); 1171 break; 1172 case STRING: 1173 addthisarg = STRDUP((const char *)(uintptr_t)value.v); 1174 break; 1175 case NODEPTR : 1176 namep = (struct node *)(uintptr_t)value.v; 1177 addthisarg = ipath2str(NULL, ipath(namep)); 1178 break; 1179 default: 1180 out(O_ERR, 1181 "call: arglist2argv: unexpected result from" 1182 " operation %s", 1183 ptree_nodetype2str(np->t)); 1184 return (1); 1185 } 1186 break; 1187 } 1188 case T_NUM: 1189 case T_TIMEVAL: 1190 numbuf[MAXDIGITIDX] = '\0'; 1191 nullbyte = &numbuf[MAXDIGITIDX]; 1192 numstr = ulltostr(np->u.ull, nullbyte); 1193 addthisarg = STRDUP(numstr); 1194 break; 1195 case T_NAME: 1196 addthisarg = ipath2str(NULL, ipath(np)); 1197 break; 1198 case T_EVENT: 1199 addthisarg = ipath2str(np->u.event.ename->u.name.s, 1200 ipath(np->u.event.epname)); 1201 break; 1202 default: 1203 out(O_ERR, "call: arglist2argv: node type %s is unsupported", 1204 ptree_nodetype2str(np->t)); 1205 return (1); 1206 /*NOTREACHED*/ 1207 break; 1208 } 1209 1210 if (*argc == 0 && addthisarg != NULL) { 1211 /* 1212 * first argument added is the command name. 1213 */ 1214 char **files; 1215 1216 files = platform_get_files_stddirs(addthisarg, 0); 1217 1218 /* do not proceed if number of files found != 1 */ 1219 if (files[0] == NULL) 1220 out(O_DIE, "call: function %s not found", addthisarg); 1221 if (files[1] != NULL) 1222 out(O_DIE, "call: multiple functions %s found", 1223 addthisarg); 1224 FREE(addthisarg); 1225 1226 addthisarg = STRDUP(files[0]); 1227 FREE(files[0]); 1228 FREE(files); 1229 } 1230 1231 if (addthisarg != NULL) { 1232 if (*argc >= *argvlen - 2) { 1233 /* 1234 * make sure argv is long enough so it has a 1235 * terminating element set to NULL 1236 */ 1237 *argvlen += 10; 1238 *argv = (char **)REALLOC(*argv, 1239 sizeof (char *) * *argvlen); 1240 } 1241 (*argv)[*argc] = addthisarg; 1242 (*argc)++; 1243 (*argv)[*argc] = NULL; 1244 } 1245 1246 return (0); 1247 } 1248 1249 static int 1250 generate_envp(struct arrow *arrowp, char ***envp, int *envc, int *envplen) 1251 { 1252 char *envnames[] = { "EFT_FROM_EVENT", "EFT_TO_EVENT", 1253 "EFT_FILE", "EFT_LINE", NULL }; 1254 char *envvalues[4]; 1255 char *none = "(none)"; 1256 size_t elen; 1257 int i; 1258 1259 *envc = 4; 1260 1261 /* 1262 * make sure envp is long enough so it has a terminating element 1263 * set to NULL 1264 */ 1265 *envplen = *envc + 1; 1266 *envp = (char **)MALLOC(sizeof (char *) * *envplen); 1267 1268 envvalues[0] = ipath2str( 1269 arrowp->tail->myevent->enode->u.event.ename->u.name.s, 1270 arrowp->tail->myevent->ipp); 1271 envvalues[1] = ipath2str( 1272 arrowp->head->myevent->enode->u.event.ename->u.name.s, 1273 arrowp->head->myevent->ipp); 1274 1275 if (arrowp->head->myevent->enode->file == NULL) { 1276 envvalues[2] = STRDUP(none); 1277 envvalues[3] = STRDUP(none); 1278 } else { 1279 envvalues[2] = STRDUP(arrowp->head->myevent->enode->file); 1280 1281 /* large enough for max int */ 1282 envvalues[3] = MALLOC(sizeof (char) * 25); 1283 (void) snprintf(envvalues[3], sizeof (envvalues[3]), "%d", 1284 arrowp->head->myevent->enode->line); 1285 } 1286 1287 for (i = 0; envnames[i] != NULL && i < *envc; i++) { 1288 elen = strlen(envnames[i]) + strlen(envvalues[i]) + 2; 1289 (*envp)[i] = MALLOC(elen); 1290 (void) snprintf((*envp)[i], elen, "%s=%s", 1291 envnames[i], envvalues[i]); 1292 FREE(envvalues[i]); 1293 } 1294 (*envp)[*envc] = NULL; 1295 1296 return (0); 1297 } 1298 1299 /* 1300 * platform_call -- call an external function 1301 * 1302 * evaluate a user-defined function and place result in valuep. return 0 1303 * if function evaluation was successful; 1 if otherwise. 1304 */ 1305 int 1306 platform_call(struct node *np, struct lut **globals, struct config *croot, 1307 struct arrow *arrowp, struct evalue *valuep) 1308 { 1309 /* 1310 * use rather short buffers. only the first string on outbuf[] is 1311 * taken as output from the called function. any message in 1312 * errbuf[] is echoed out as an error message. 1313 */ 1314 char outbuf[256], errbuf[512]; 1315 struct stat buf; 1316 char **argv, **envp; 1317 int argc, argvlen, envc, envplen; 1318 int i, ret; 1319 1320 /* 1321 * np is the argument list. the user-defined function is the first 1322 * element of the list. 1323 */ 1324 ASSERT(np->t == T_LIST); 1325 1326 argv = NULL; 1327 argc = 0; 1328 argvlen = 0; 1329 if (arglist2argv(np, globals, croot, arrowp, &argv, &argc, &argvlen) || 1330 argc == 0) 1331 return (1); 1332 1333 /* 1334 * make sure program has executable bit set 1335 */ 1336 if (stat(argv[0], &buf) == 0) { 1337 int exec_bit_set = 0; 1338 1339 if (buf.st_uid == geteuid() && buf.st_mode & S_IXUSR) 1340 exec_bit_set = 1; 1341 else if (buf.st_gid == getegid() && buf.st_mode & S_IXGRP) 1342 exec_bit_set = 1; 1343 else if (buf.st_mode & S_IXOTH) 1344 exec_bit_set = 1; 1345 1346 if (exec_bit_set == 0) 1347 out(O_DIE, "call: executable bit not set on %s", 1348 argv[0]); 1349 } else { 1350 out(O_DIE, "call: failure in stat(), errno = %d\n", errno); 1351 } 1352 1353 envp = NULL; 1354 envc = 0; 1355 envplen = 0; 1356 if (generate_envp(arrowp, &envp, &envc, &envplen)) 1357 return (1); 1358 1359 outbuf[0] = '\0'; 1360 errbuf[0] = '\0'; 1361 1362 ret = forkandexecve((const char *) argv[0], (char *const *) argv, 1363 (char *const *) envp, outbuf, sizeof (outbuf), 1364 errbuf, sizeof (errbuf)); 1365 1366 for (i = 0; i < envc; i++) 1367 FREE(envp[i]); 1368 if (envp) 1369 FREE(envp); 1370 1371 if (ret) { 1372 outfl(O_OK, np->file, np->line, 1373 "call: failure in fork + exec of %s", argv[0]); 1374 } else { 1375 char *ptr; 1376 1377 /* chomp the result */ 1378 for (ptr = outbuf; *ptr; ptr++) 1379 if (*ptr == '\n' || *ptr == '\r') { 1380 *ptr = '\0'; 1381 break; 1382 } 1383 valuep->t = STRING; 1384 valuep->v = (uintptr_t)stable(outbuf); 1385 } 1386 1387 if (errbuf[0] != '\0') { 1388 ret = 1; 1389 outfl(O_OK, np->file, np->line, 1390 "call: unexpected stderr output from %s: %s", 1391 argv[0], errbuf); 1392 } 1393 1394 for (i = 0; i < argc; i++) 1395 FREE(argv[i]); 1396 FREE(argv); 1397 1398 return (ret); 1399 } 1400 1401 /* 1402 * platform_confcall -- call a configuration database function 1403 * 1404 * returns result in *valuep, return 0 on success 1405 */ 1406 /*ARGSUSED*/ 1407 int 1408 platform_confcall(struct node *np, struct lut **globals, struct config *croot, 1409 struct arrow *arrowp, struct evalue *valuep) 1410 { 1411 outfl(O_ALTFP|O_VERB, np->file, np->line, "unknown confcall"); 1412 return (0); 1413 } 1414 1415 /* 1416 * platform_get_eft_files -- return names of all eft files we should load 1417 * 1418 * this routine doesn't return NULL, even if no files are found (in that 1419 * case, a char ** is returned with the first element NULL). 1420 */ 1421 char ** 1422 platform_get_eft_files(void) 1423 { 1424 return (platform_get_files_stddirs(".eft", 1)); 1425 } 1426 1427 void 1428 platform_free_eft_files(char **flist) 1429 { 1430 char **f; 1431 1432 if (flist == NULL || *flist == NULL) 1433 return; /* no files were found so we're done */ 1434 1435 f = flist; 1436 while (*f != NULL) { 1437 FREE(*f); 1438 f++; 1439 } 1440 FREE(flist); 1441 } 1442 1443 static nvlist_t *payloadnvp = NULL; 1444 1445 void 1446 platform_set_payloadnvp(nvlist_t *nvlp) 1447 { 1448 /* 1449 * cannot replace a non-NULL payloadnvp with a non-NULL nvlp 1450 */ 1451 ASSERT(payloadnvp != NULL ? nvlp == NULL : 1); 1452 payloadnvp = nvlp; 1453 } 1454 1455 /* 1456 * given array notation in inputstr such as "foo[1]" or "foo [ 1 ]" (spaces 1457 * allowed), figure out the array name and index. return 0 if successful, 1458 * nonzero if otherwise. 1459 */ 1460 static int 1461 get_array_info(const char *inputstr, const char **name, unsigned int *index) 1462 { 1463 char *indexptr, *indexend, *dupname, *endname; 1464 1465 if (strchr(inputstr, '[') == NULL) 1466 return (1); 1467 1468 dupname = STRDUP(inputstr); 1469 indexptr = strchr(dupname, '['); 1470 indexend = strchr(dupname, ']'); 1471 1472 /* 1473 * return if array notation is not complete or if index is negative 1474 */ 1475 if (indexend == NULL || indexptr >= indexend || 1476 strchr(indexptr, '-') != NULL) { 1477 FREE(dupname); 1478 return (1); 1479 } 1480 1481 /* 1482 * search past any spaces between the name string and '[' 1483 */ 1484 endname = indexptr; 1485 while (isspace(*(endname - 1)) && dupname < endname) 1486 endname--; 1487 *endname = '\0'; 1488 ASSERT(dupname < endname); 1489 1490 /* 1491 * search until indexptr points to the first digit and indexend 1492 * points to the last digit 1493 */ 1494 while (!isdigit(*indexptr) && indexptr < indexend) 1495 indexptr++; 1496 while (!isdigit(*indexend) && indexptr <= indexend) 1497 indexend--; 1498 1499 *(indexend + 1) = '\0'; 1500 *index = (unsigned int)atoi(indexptr); 1501 1502 *name = stable(dupname); 1503 FREE(dupname); 1504 1505 return (0); 1506 } 1507 1508 /* 1509 * platform_payloadprop -- fetch a payload value 1510 * 1511 * XXX this function should be replaced and eval_func() should be 1512 * XXX changed to use the more general platform_payloadprop_values(). 1513 */ 1514 int 1515 platform_payloadprop(struct node *np, struct evalue *valuep) 1516 { 1517 nvlist_t *basenvp; 1518 nvlist_t *embnvp = NULL; 1519 nvpair_t *nvpair; 1520 const char *nameptr, *propstr, *lastnameptr; 1521 int not_array = 0; 1522 unsigned int index = 0; 1523 uint_t nelem; 1524 char *nvpname, *nameslist = NULL; 1525 char *scheme = NULL; 1526 1527 ASSERT(np->t == T_QUOTE); 1528 1529 propstr = np->u.quote.s; 1530 if (payloadnvp == NULL) { 1531 out(O_ALTFP | O_VERB2, "platform_payloadprop: no nvp for %s", 1532 propstr); 1533 return (1); 1534 } 1535 basenvp = payloadnvp; 1536 1537 /* 1538 * first handle any embedded nvlists. if propstr is "foo.bar[2]" 1539 * then lastnameptr should end up being "bar[2]" with basenvp set 1540 * to the nvlist for "foo". (the search for "bar" within "foo" 1541 * will be done later.) 1542 */ 1543 if (strchr(propstr, '.') != NULL) { 1544 nvlist_t **arraynvp; 1545 uint_t nelem; 1546 char *w; 1547 int ier; 1548 1549 nameslist = STRDUP(propstr); 1550 lastnameptr = strtok(nameslist, "."); 1551 1552 /* 1553 * decompose nameslist into its component names while 1554 * extracting the embedded nvlist 1555 */ 1556 while ((w = strtok(NULL, ".")) != NULL) { 1557 if (get_array_info(lastnameptr, &nameptr, &index)) { 1558 ier = nvlist_lookup_nvlist(basenvp, 1559 lastnameptr, &basenvp); 1560 } else { 1561 /* handle array of nvlists */ 1562 ier = nvlist_lookup_nvlist_array(basenvp, 1563 nameptr, &arraynvp, &nelem); 1564 if (ier == 0) { 1565 if ((uint_t)index > nelem - 1) 1566 ier = 1; 1567 else 1568 basenvp = arraynvp[index]; 1569 } 1570 } 1571 1572 if (ier) { 1573 out(O_ALTFP, "platform_payloadprop: " 1574 " invalid list for %s (in %s)", 1575 lastnameptr, propstr); 1576 FREE(nameslist); 1577 return (1); 1578 } 1579 1580 lastnameptr = w; 1581 } 1582 } else { 1583 lastnameptr = propstr; 1584 } 1585 1586 /* if property is an array reference, extract array name and index */ 1587 not_array = get_array_info(lastnameptr, &nameptr, &index); 1588 if (not_array) 1589 nameptr = stable(lastnameptr); 1590 1591 if (nameslist != NULL) 1592 FREE(nameslist); 1593 1594 /* search for nvpair entry */ 1595 nvpair = NULL; 1596 while ((nvpair = nvlist_next_nvpair(basenvp, nvpair)) != NULL) { 1597 nvpname = nvpair_name(nvpair); 1598 ASSERT(nvpname != NULL); 1599 1600 if (nameptr == stable(nvpname)) 1601 break; 1602 } 1603 1604 if (nvpair == NULL) { 1605 out(O_ALTFP, "platform_payloadprop: no entry for %s", propstr); 1606 return (1); 1607 } else if (valuep == NULL) { 1608 /* 1609 * caller is interested in the existence of a property with 1610 * this name, regardless of type or value 1611 */ 1612 return (0); 1613 } 1614 1615 valuep->t = UNDEFINED; 1616 1617 /* 1618 * get to this point if we found an entry. figure out its data 1619 * type and copy its value. 1620 */ 1621 (void) nvpair_value_nvlist(nvpair, &embnvp); 1622 if (nvlist_lookup_string(embnvp, FM_FMRI_SCHEME, &scheme) == 0) { 1623 if (strcmp(scheme, FM_FMRI_SCHEME_HC) == 0) { 1624 valuep->t = NODEPTR; 1625 valuep->v = (uintptr_t)hc_fmri_nodeize(embnvp); 1626 return (0); 1627 } 1628 } 1629 switch (nvpair_type(nvpair)) { 1630 case DATA_TYPE_BOOLEAN: 1631 case DATA_TYPE_BOOLEAN_VALUE: { 1632 boolean_t val; 1633 (void) nvpair_value_boolean_value(nvpair, &val); 1634 valuep->t = UINT64; 1635 valuep->v = (unsigned long long)val; 1636 break; 1637 } 1638 case DATA_TYPE_BYTE: { 1639 uchar_t val; 1640 (void) nvpair_value_byte(nvpair, &val); 1641 valuep->t = UINT64; 1642 valuep->v = (unsigned long long)val; 1643 break; 1644 } 1645 case DATA_TYPE_STRING: { 1646 char *val; 1647 valuep->t = STRING; 1648 (void) nvpair_value_string(nvpair, &val); 1649 valuep->v = (uintptr_t)stable(val); 1650 break; 1651 } 1652 1653 case DATA_TYPE_INT8: { 1654 int8_t val; 1655 (void) nvpair_value_int8(nvpair, &val); 1656 valuep->t = UINT64; 1657 valuep->v = (unsigned long long)val; 1658 break; 1659 } 1660 case DATA_TYPE_UINT8: { 1661 uint8_t val; 1662 (void) nvpair_value_uint8(nvpair, &val); 1663 valuep->t = UINT64; 1664 valuep->v = (unsigned long long)val; 1665 break; 1666 } 1667 1668 case DATA_TYPE_INT16: { 1669 int16_t val; 1670 (void) nvpair_value_int16(nvpair, &val); 1671 valuep->t = UINT64; 1672 valuep->v = (unsigned long long)val; 1673 break; 1674 } 1675 case DATA_TYPE_UINT16: { 1676 uint16_t val; 1677 (void) nvpair_value_uint16(nvpair, &val); 1678 valuep->t = UINT64; 1679 valuep->v = (unsigned long long)val; 1680 break; 1681 } 1682 1683 case DATA_TYPE_INT32: { 1684 int32_t val; 1685 (void) nvpair_value_int32(nvpair, &val); 1686 valuep->t = UINT64; 1687 valuep->v = (unsigned long long)val; 1688 break; 1689 } 1690 case DATA_TYPE_UINT32: { 1691 uint32_t val; 1692 (void) nvpair_value_uint32(nvpair, &val); 1693 valuep->t = UINT64; 1694 valuep->v = (unsigned long long)val; 1695 break; 1696 } 1697 1698 case DATA_TYPE_INT64: { 1699 int64_t val; 1700 (void) nvpair_value_int64(nvpair, &val); 1701 valuep->t = UINT64; 1702 valuep->v = (unsigned long long)val; 1703 break; 1704 } 1705 case DATA_TYPE_UINT64: { 1706 uint64_t val; 1707 (void) nvpair_value_uint64(nvpair, &val); 1708 valuep->t = UINT64; 1709 valuep->v = (unsigned long long)val; 1710 break; 1711 } 1712 1713 case DATA_TYPE_BOOLEAN_ARRAY: { 1714 boolean_t *val; 1715 (void) nvpair_value_boolean_array(nvpair, &val, &nelem); 1716 if (not_array == 1 || index >= nelem) 1717 goto invalid; 1718 valuep->t = UINT64; 1719 valuep->v = (unsigned long long)val[index]; 1720 break; 1721 } 1722 case DATA_TYPE_BYTE_ARRAY: { 1723 uchar_t *val; 1724 (void) nvpair_value_byte_array(nvpair, &val, &nelem); 1725 if (not_array == 1 || index >= nelem) 1726 goto invalid; 1727 valuep->t = UINT64; 1728 valuep->v = (unsigned long long)val[index]; 1729 break; 1730 } 1731 case DATA_TYPE_STRING_ARRAY: { 1732 char **val; 1733 (void) nvpair_value_string_array(nvpair, &val, &nelem); 1734 if (not_array == 1 || index >= nelem) 1735 goto invalid; 1736 valuep->t = STRING; 1737 valuep->v = (uintptr_t)stable(val[index]); 1738 break; 1739 } 1740 1741 case DATA_TYPE_INT8_ARRAY: { 1742 int8_t *val; 1743 (void) nvpair_value_int8_array(nvpair, &val, &nelem); 1744 if (not_array == 1 || index >= nelem) 1745 goto invalid; 1746 valuep->t = UINT64; 1747 valuep->v = (unsigned long long)val[index]; 1748 break; 1749 } 1750 case DATA_TYPE_UINT8_ARRAY: { 1751 uint8_t *val; 1752 (void) nvpair_value_uint8_array(nvpair, &val, &nelem); 1753 if (not_array == 1 || index >= nelem) 1754 goto invalid; 1755 valuep->t = UINT64; 1756 valuep->v = (unsigned long long)val[index]; 1757 break; 1758 } 1759 case DATA_TYPE_INT16_ARRAY: { 1760 int16_t *val; 1761 (void) nvpair_value_int16_array(nvpair, &val, &nelem); 1762 if (not_array == 1 || index >= nelem) 1763 goto invalid; 1764 valuep->t = UINT64; 1765 valuep->v = (unsigned long long)val[index]; 1766 break; 1767 } 1768 case DATA_TYPE_UINT16_ARRAY: { 1769 uint16_t *val; 1770 (void) nvpair_value_uint16_array(nvpair, &val, &nelem); 1771 if (not_array == 1 || index >= nelem) 1772 goto invalid; 1773 valuep->t = UINT64; 1774 valuep->v = (unsigned long long)val[index]; 1775 break; 1776 } 1777 case DATA_TYPE_INT32_ARRAY: { 1778 int32_t *val; 1779 (void) nvpair_value_int32_array(nvpair, &val, &nelem); 1780 if (not_array == 1 || index >= nelem) 1781 goto invalid; 1782 valuep->t = UINT64; 1783 valuep->v = (unsigned long long)val[index]; 1784 break; 1785 } 1786 case DATA_TYPE_UINT32_ARRAY: { 1787 uint32_t *val; 1788 (void) nvpair_value_uint32_array(nvpair, &val, &nelem); 1789 if (not_array == 1 || index >= nelem) 1790 goto invalid; 1791 valuep->t = UINT64; 1792 valuep->v = (unsigned long long)val[index]; 1793 break; 1794 } 1795 case DATA_TYPE_INT64_ARRAY: { 1796 int64_t *val; 1797 (void) nvpair_value_int64_array(nvpair, &val, &nelem); 1798 if (not_array == 1 || index >= nelem) 1799 goto invalid; 1800 valuep->t = UINT64; 1801 valuep->v = (unsigned long long)val[index]; 1802 break; 1803 } 1804 case DATA_TYPE_UINT64_ARRAY: { 1805 uint64_t *val; 1806 (void) nvpair_value_uint64_array(nvpair, &val, &nelem); 1807 if (not_array == 1 || index >= nelem) 1808 goto invalid; 1809 valuep->t = UINT64; 1810 valuep->v = (unsigned long long)val[index]; 1811 break; 1812 } 1813 1814 default : 1815 out(O_ALTFP|O_VERB2, 1816 "platform_payloadprop: unsupported data type for %s", 1817 propstr); 1818 return (1); 1819 } 1820 1821 return (0); 1822 1823 invalid: 1824 out(O_ALTFP|O_VERB2, 1825 "platform_payloadprop: invalid array reference for %s", propstr); 1826 return (1); 1827 } 1828 1829 /*ARGSUSED*/ 1830 int 1831 platform_path_exists(nvlist_t *fmri) 1832 { 1833 return (fmd_nvl_fmri_present(Hdl, fmri)); 1834 } 1835 1836 struct evalue * 1837 platform_payloadprop_values(const char *propstr, int *nvals) 1838 { 1839 struct evalue *retvals; 1840 nvlist_t *basenvp; 1841 nvpair_t *nvpair; 1842 char *nvpname; 1843 1844 *nvals = 0; 1845 1846 if (payloadnvp == NULL) 1847 return (NULL); 1848 1849 basenvp = payloadnvp; 1850 1851 /* search for nvpair entry */ 1852 nvpair = NULL; 1853 while ((nvpair = nvlist_next_nvpair(basenvp, nvpair)) != NULL) { 1854 nvpname = nvpair_name(nvpair); 1855 ASSERT(nvpname != NULL); 1856 1857 if (strcmp(propstr, nvpname) == 0) 1858 break; 1859 } 1860 1861 if (nvpair == NULL) 1862 return (NULL); /* property not found */ 1863 1864 switch (nvpair_type(nvpair)) { 1865 case DATA_TYPE_NVLIST: { 1866 nvlist_t *embnvp = NULL; 1867 char *scheme = NULL; 1868 1869 (void) nvpair_value_nvlist(nvpair, &embnvp); 1870 if (nvlist_lookup_string(embnvp, FM_FMRI_SCHEME, 1871 &scheme) == 0) { 1872 if (strcmp(scheme, FM_FMRI_SCHEME_HC) == 0) { 1873 *nvals = 1; 1874 retvals = MALLOC(sizeof (struct evalue)); 1875 retvals->t = NODEPTR; 1876 retvals->v = 1877 (uintptr_t)hc_fmri_nodeize(embnvp); 1878 return (retvals); 1879 } 1880 } 1881 return (NULL); 1882 } 1883 case DATA_TYPE_NVLIST_ARRAY: { 1884 char *scheme = NULL; 1885 nvlist_t **nvap; 1886 uint_t nel; 1887 int i; 1888 int hccount; 1889 1890 /* 1891 * since we're only willing to handle hc fmri's, we 1892 * must count them first before allocating retvals. 1893 */ 1894 if (nvpair_value_nvlist_array(nvpair, &nvap, &nel) != 0) 1895 return (NULL); 1896 1897 hccount = 0; 1898 for (i = 0; i < nel; i++) { 1899 if (nvlist_lookup_string(nvap[i], FM_FMRI_SCHEME, 1900 &scheme) == 0 && 1901 strcmp(scheme, FM_FMRI_SCHEME_HC) == 0) { 1902 hccount++; 1903 } 1904 } 1905 1906 if (hccount == 0) 1907 return (NULL); 1908 1909 *nvals = hccount; 1910 retvals = MALLOC(sizeof (struct evalue) * hccount); 1911 1912 hccount = 0; 1913 for (i = 0; i < nel; i++) { 1914 if (nvlist_lookup_string(nvap[i], FM_FMRI_SCHEME, 1915 &scheme) == 0 && 1916 strcmp(scheme, FM_FMRI_SCHEME_HC) == 0) { 1917 retvals[hccount].t = NODEPTR; 1918 retvals[hccount].v = (uintptr_t) 1919 hc_fmri_nodeize(nvap[i]); 1920 hccount++; 1921 } 1922 } 1923 return (retvals); 1924 } 1925 case DATA_TYPE_BOOLEAN: 1926 case DATA_TYPE_BOOLEAN_VALUE: { 1927 boolean_t val; 1928 1929 *nvals = 1; 1930 retvals = MALLOC(sizeof (struct evalue)); 1931 (void) nvpair_value_boolean_value(nvpair, &val); 1932 retvals->t = UINT64; 1933 retvals->v = (unsigned long long)val; 1934 return (retvals); 1935 } 1936 case DATA_TYPE_BYTE: { 1937 uchar_t val; 1938 1939 *nvals = 1; 1940 retvals = MALLOC(sizeof (struct evalue)); 1941 (void) nvpair_value_byte(nvpair, &val); 1942 retvals->t = UINT64; 1943 retvals->v = (unsigned long long)val; 1944 return (retvals); 1945 } 1946 case DATA_TYPE_STRING: { 1947 char *val; 1948 1949 *nvals = 1; 1950 retvals = MALLOC(sizeof (struct evalue)); 1951 retvals->t = STRING; 1952 (void) nvpair_value_string(nvpair, &val); 1953 retvals->v = (uintptr_t)stable(val); 1954 return (retvals); 1955 } 1956 1957 case DATA_TYPE_INT8: { 1958 int8_t val; 1959 1960 *nvals = 1; 1961 retvals = MALLOC(sizeof (struct evalue)); 1962 (void) nvpair_value_int8(nvpair, &val); 1963 retvals->t = UINT64; 1964 retvals->v = (unsigned long long)val; 1965 return (retvals); 1966 } 1967 case DATA_TYPE_UINT8: { 1968 uint8_t val; 1969 1970 *nvals = 1; 1971 retvals = MALLOC(sizeof (struct evalue)); 1972 (void) nvpair_value_uint8(nvpair, &val); 1973 retvals->t = UINT64; 1974 retvals->v = (unsigned long long)val; 1975 return (retvals); 1976 } 1977 1978 case DATA_TYPE_INT16: { 1979 int16_t val; 1980 1981 *nvals = 1; 1982 retvals = MALLOC(sizeof (struct evalue)); 1983 (void) nvpair_value_int16(nvpair, &val); 1984 retvals->t = UINT64; 1985 retvals->v = (unsigned long long)val; 1986 return (retvals); 1987 } 1988 case DATA_TYPE_UINT16: { 1989 uint16_t val; 1990 1991 *nvals = 1; 1992 retvals = MALLOC(sizeof (struct evalue)); 1993 (void) nvpair_value_uint16(nvpair, &val); 1994 retvals->t = UINT64; 1995 retvals->v = (unsigned long long)val; 1996 return (retvals); 1997 } 1998 1999 case DATA_TYPE_INT32: { 2000 int32_t val; 2001 2002 *nvals = 1; 2003 retvals = MALLOC(sizeof (struct evalue)); 2004 (void) nvpair_value_int32(nvpair, &val); 2005 retvals->t = UINT64; 2006 retvals->v = (unsigned long long)val; 2007 return (retvals); 2008 } 2009 case DATA_TYPE_UINT32: { 2010 uint32_t val; 2011 2012 *nvals = 1; 2013 retvals = MALLOC(sizeof (struct evalue)); 2014 (void) nvpair_value_uint32(nvpair, &val); 2015 retvals->t = UINT64; 2016 retvals->v = (unsigned long long)val; 2017 return (retvals); 2018 } 2019 2020 case DATA_TYPE_INT64: { 2021 int64_t val; 2022 2023 *nvals = 1; 2024 retvals = MALLOC(sizeof (struct evalue)); 2025 (void) nvpair_value_int64(nvpair, &val); 2026 retvals->t = UINT64; 2027 retvals->v = (unsigned long long)val; 2028 return (retvals); 2029 } 2030 case DATA_TYPE_UINT64: { 2031 uint64_t val; 2032 2033 *nvals = 1; 2034 retvals = MALLOC(sizeof (struct evalue)); 2035 (void) nvpair_value_uint64(nvpair, &val); 2036 retvals->t = UINT64; 2037 retvals->v = (unsigned long long)val; 2038 return (retvals); 2039 } 2040 2041 case DATA_TYPE_BOOLEAN_ARRAY: { 2042 boolean_t *val; 2043 uint_t nel; 2044 int i; 2045 2046 (void) nvpair_value_boolean_array(nvpair, &val, &nel); 2047 *nvals = nel; 2048 retvals = MALLOC(sizeof (struct evalue) * nel); 2049 for (i = 0; i < nel; i++) { 2050 retvals[i].t = UINT64; 2051 retvals[i].v = (unsigned long long)val[i]; 2052 } 2053 return (retvals); 2054 } 2055 case DATA_TYPE_BYTE_ARRAY: { 2056 uchar_t *val; 2057 uint_t nel; 2058 int i; 2059 2060 (void) nvpair_value_byte_array(nvpair, &val, &nel); 2061 *nvals = nel; 2062 retvals = MALLOC(sizeof (struct evalue) * nel); 2063 for (i = 0; i < nel; i++) { 2064 retvals[i].t = UINT64; 2065 retvals[i].v = (unsigned long long)val[i]; 2066 } 2067 return (retvals); 2068 } 2069 case DATA_TYPE_STRING_ARRAY: { 2070 char **val; 2071 uint_t nel; 2072 int i; 2073 2074 (void) nvpair_value_string_array(nvpair, &val, &nel); 2075 *nvals = nel; 2076 retvals = MALLOC(sizeof (struct evalue) * nel); 2077 for (i = 0; i < nel; i++) { 2078 retvals[i].t = STRING; 2079 retvals[i].v = (uintptr_t)stable(val[i]); 2080 } 2081 return (retvals); 2082 } 2083 2084 case DATA_TYPE_INT8_ARRAY: { 2085 int8_t *val; 2086 uint_t nel; 2087 int i; 2088 2089 (void) nvpair_value_int8_array(nvpair, &val, &nel); 2090 *nvals = nel; 2091 retvals = MALLOC(sizeof (struct evalue) * nel); 2092 for (i = 0; i < nel; i++) { 2093 retvals[i].t = UINT64; 2094 retvals[i].v = (unsigned long long)val[i]; 2095 } 2096 return (retvals); 2097 } 2098 case DATA_TYPE_UINT8_ARRAY: { 2099 uint8_t *val; 2100 uint_t nel; 2101 int i; 2102 2103 (void) nvpair_value_uint8_array(nvpair, &val, &nel); 2104 *nvals = nel; 2105 retvals = MALLOC(sizeof (struct evalue) * nel); 2106 for (i = 0; i < nel; i++) { 2107 retvals[i].t = UINT64; 2108 retvals[i].v = (unsigned long long)val[i]; 2109 } 2110 return (retvals); 2111 } 2112 case DATA_TYPE_INT16_ARRAY: { 2113 int16_t *val; 2114 uint_t nel; 2115 int i; 2116 2117 (void) nvpair_value_int16_array(nvpair, &val, &nel); 2118 *nvals = nel; 2119 retvals = MALLOC(sizeof (struct evalue) * nel); 2120 for (i = 0; i < nel; i++) { 2121 retvals[i].t = UINT64; 2122 retvals[i].v = (unsigned long long)val[i]; 2123 } 2124 return (retvals); 2125 } 2126 case DATA_TYPE_UINT16_ARRAY: { 2127 uint16_t *val; 2128 uint_t nel; 2129 int i; 2130 2131 (void) nvpair_value_uint16_array(nvpair, &val, &nel); 2132 *nvals = nel; 2133 retvals = MALLOC(sizeof (struct evalue) * nel); 2134 for (i = 0; i < nel; i++) { 2135 retvals[i].t = UINT64; 2136 retvals[i].v = (unsigned long long)val[i]; 2137 } 2138 return (retvals); 2139 } 2140 case DATA_TYPE_INT32_ARRAY: { 2141 int32_t *val; 2142 uint_t nel; 2143 int i; 2144 2145 (void) nvpair_value_int32_array(nvpair, &val, &nel); 2146 *nvals = nel; 2147 retvals = MALLOC(sizeof (struct evalue) * nel); 2148 for (i = 0; i < nel; i++) { 2149 retvals[i].t = UINT64; 2150 retvals[i].v = (unsigned long long)val[i]; 2151 } 2152 return (retvals); 2153 } 2154 case DATA_TYPE_UINT32_ARRAY: { 2155 uint32_t *val; 2156 uint_t nel; 2157 int i; 2158 2159 (void) nvpair_value_uint32_array(nvpair, &val, &nel); 2160 *nvals = nel; 2161 retvals = MALLOC(sizeof (struct evalue) * nel); 2162 for (i = 0; i < nel; i++) { 2163 retvals[i].t = UINT64; 2164 retvals[i].v = (unsigned long long)val[i]; 2165 } 2166 return (retvals); 2167 } 2168 case DATA_TYPE_INT64_ARRAY: { 2169 int64_t *val; 2170 uint_t nel; 2171 int i; 2172 2173 (void) nvpair_value_int64_array(nvpair, &val, &nel); 2174 *nvals = nel; 2175 retvals = MALLOC(sizeof (struct evalue) * nel); 2176 for (i = 0; i < nel; i++) { 2177 retvals[i].t = UINT64; 2178 retvals[i].v = (unsigned long long)val[i]; 2179 } 2180 return (retvals); 2181 } 2182 case DATA_TYPE_UINT64_ARRAY: { 2183 uint64_t *val; 2184 uint_t nel; 2185 int i; 2186 2187 (void) nvpair_value_uint64_array(nvpair, &val, &nel); 2188 *nvals = nel; 2189 retvals = MALLOC(sizeof (struct evalue) * nel); 2190 for (i = 0; i < nel; i++) { 2191 retvals[i].t = UINT64; 2192 retvals[i].v = (unsigned long long)val[i]; 2193 } 2194 return (retvals); 2195 } 2196 2197 } 2198 2199 return (NULL); 2200 } 2201 2202 /* 2203 * When a list.repaired event is seen the following is called for 2204 * each fault in the associated fault list to convert the given FMRI 2205 * to an instanced path. Only hc scheme is supported. 2206 */ 2207 const struct ipath * 2208 platform_fault2ipath(nvlist_t *flt) 2209 { 2210 nvlist_t *rsrc; 2211 struct node *np; 2212 char *scheme; 2213 const struct ipath *ip; 2214 2215 if (nvlist_lookup_nvlist(flt, FM_FAULT_RESOURCE, &rsrc) != 0) { 2216 out(O_ALTFP, "platform_fault2ipath: no resource member"); 2217 return (NULL); 2218 } else if (nvlist_lookup_string(rsrc, FM_FMRI_SCHEME, &scheme) != 0) { 2219 out(O_ALTFP, "platform_fault2ipath: no scheme type for rsrc"); 2220 return (NULL); 2221 } 2222 2223 if (strncmp(scheme, FM_FMRI_SCHEME_HC, 2224 sizeof (FM_FMRI_SCHEME_HC) - 1) != 0) { 2225 out(O_ALTFP, "platform_fault2ipath: returning NULL for non-hc " 2226 "scheme %s", scheme); 2227 return (NULL); 2228 } 2229 2230 if ((np = hc_fmri_nodeize(rsrc)) == NULL) 2231 return (NULL); /* nodeize will already have whinged */ 2232 2233 ip = ipath(np); 2234 tree_free(np); 2235 return (ip); 2236 } 2237