static void print_props(topo_hdl_t *thp, tnode_t *node) { int i, err; nvlist_t *nvl; struct prop_args *pp; if (pcnt == 0) return; for (i = 0; i < pcnt; ++i) { pp = pargs[i]; if (pp->group == NULL) continue; /* * If we have a valid value, this is a request to * set a property. Otherwise, just print the property * group and any specified properties. */ if (pp->value == NULL) { if (pp->prop == NULL) { /* * Print all properties in this group */ if ((nvl = topo_prop_getprops(node, &err)) == NULL) { (void) fprintf(stderr, "%s: failed to " "get %s: %s\n", g_pname, pp->group, topo_strerror(err)); continue; } else { print_all_props(thp, node, nvl, pp->group); nvlist_free(nvl); continue; } } if (topo_prop_getprop(node, pp->group, pp->prop, NULL, &nvl, &err) < 0) { (void) fprintf(stderr, "%s: failed to get " "%s.%s: %s\n", g_pname, pp->group, pp->prop, topo_strerror(err)); continue; } else { print_pgroup(thp, node, pp->group, NULL, NULL, 0); print_prop_nameval(thp, node, nvl); nvlist_free(nvl); } } else { set_prop(thp, node, NULL, pp); } } }
static nvlist_t * find_disk_monitor_private_pgroup(tnode_t *node) { int err; nvlist_t *list_of_lists, *nvlp, *dupnvlp; nvlist_t *disk_monitor_pgrp = NULL; nvpair_t *nvp = NULL; char *pgroup_name; /* * topo_prop_get_all() returns an nvlist that contains other * nvlists (some of which are property groups). Since the private * property group we need will be among the list of property * groups returned (hopefully), we need to walk the list of nvlists * in the topo node's properties to find the property groups, then * check inside each embedded nvlist to see if it's the pgroup we're * looking for. */ if ((list_of_lists = topo_prop_getprops(node, &err)) != NULL) { /* * Go through the list of nvlists, looking for the * property group we need. */ while ((nvp = nvlist_next_nvpair(list_of_lists, nvp)) != NULL) { if (nvpair_type(nvp) != DATA_TYPE_NVLIST || strcmp(nvpair_name(nvp), TOPO_PROP_GROUP) != 0 || nvpair_value_nvlist(nvp, &nvlp) != 0) continue; dm_assert(nvlp != NULL); pgroup_name = NULL; if (nonunique_nvlist_lookup_string(nvlp, TOPO_PROP_GROUP_NAME, &pgroup_name) != 0 || strcmp(pgroup_name, DISK_MONITOR_PROPERTIES) != 0) continue; else { /* * Duplicate the nvlist so that when the * master nvlist is freed (below), we will * still refer to allocated memory. */ if (nvlist_dup(nvlp, &dupnvlp, 0) == 0) disk_monitor_pgrp = dupnvlp; else disk_monitor_pgrp = NULL; break; } } nvlist_free(list_of_lists); } return (disk_monitor_pgrp); }
/*ARGSUSED*/ static int walk_node(topo_hdl_t *thp, tnode_t *node, void *arg) { int err; nvlist_t *nvl; nvlist_t *rsrc, *out; char *s; if (opt_e && strcmp(opt_s, FM_FMRI_SCHEME_HC) == 0) { print_everstyle(node); return (TOPO_WALK_NEXT); } if (topo_node_resource(node, &rsrc, &err) < 0) { (void) fprintf(stderr, "%s: failed to get resource: " "%s", g_pname, topo_strerror(err)); return (TOPO_WALK_NEXT); } if (topo_fmri_nvl2str(thp, rsrc, &s, &err) < 0) { (void) fprintf(stderr, "%s: failed to convert " "resource to FMRI string: %s", g_pname, topo_strerror(err)); nvlist_free(rsrc); return (TOPO_WALK_NEXT); } if (g_fmri != NULL && fnmatch(g_fmri, s, 0) != 0) { nvlist_free(rsrc); topo_hdl_strfree(thp, s); return (TOPO_WALK_NEXT); } print_node(thp, node, rsrc, s); topo_hdl_strfree(thp, s); nvlist_free(rsrc); if (opt_m != NULL) { if (topo_method_invoke(node, opt_m, 0, NULL, &out, &err) == 0) { nvlist_print(stdout, out); nvlist_free(out); } else if (err != ETOPO_METHOD_NOTSUP) (void) fprintf(stderr, "%s: method failed unexpectedly " "on %s=%d (%s)\n", g_pname, topo_node_name(node), topo_node_instance(node), topo_strerror(err)); } if (opt_V || opt_all) { if ((nvl = topo_prop_getprops(node, &err)) == NULL) { (void) fprintf(stderr, "%s: failed to get " "properties for %s=%d: %s\n", g_pname, topo_node_name(node), topo_node_instance(node), topo_strerror(err)); } else { print_all_props(thp, node, nvl, ALL); nvlist_free(nvl); } } else if (pcnt > 0) print_props(thp, node); (void) printf("\n"); return (TOPO_WALK_NEXT); }