7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * CDDL HEADER START
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * The contents of this file are subject to the terms of the
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * Common Development and Distribution License (the "License").
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * You may not use this file except in compliance with the License.
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * See the License for the specific language governing permissions
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * and limitations under the License.
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * When distributing Covered Code, include this CDDL HEADER in each
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * If applicable, add the following below this CDDL HEADER, with the
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * fields enclosed by brackets "[]" replaced with your own identifying
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * information: Portions Copyright [yyyy] [name of copyright owner]
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * CDDL HEADER END
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
1410cb930a3e26032c59c6835837a28c47366b3cJoshua M. Clulow * Copyright (c) 2013, Joyent, Inc. All rights reserved.
b695575577bae0337af339d76949713bfe1c9013Robert Johnstonstatic const char optstr[] = "bCdem:P:pR:s:StVx";
a38fc4ea2efaea64cc89ed7a1ac251ae94199ae9Robert Johnston "Usage: %s [-bCedpSVx] [-P group.property[=type:value]] "
b695575577bae0337af339d76949713bfe1c9013Robert Johnston "[-R root] [-m method] [-s scheme] [fmri]\n", g_pname);
78432d5ed5122db8b0bbfa41e00d063bf8ae7171cy "\t-b walk in sibling-first order (default is child-first)\n"
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi "\t-C dump core after completing execution\n"
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi "\t-d set debug mode for libtopo modules\n"
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi "\t-e display FMRIs as paths using esc/eft notation\n"
b695575577bae0337af339d76949713bfe1c9013Robert Johnston "\t-m execute given method\n"
c40d7343efa60b18ad1ceb316eb337caeea79046cindi "\t-P get/set specified properties\n"
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi "\t-p display of FMRI protocol properties\n"
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi "\t-R set root directory for libtopo plug-ins and other files\n"
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi "\t-s display topology for the specified FMRI scheme\n"
c40d7343efa60b18ad1ceb316eb337caeea79046cindi "\t-S display FMRI status (present/usable)\n"
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi "\t-V set verbose mode\n"
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi "\t-x display a xml formatted topology\n");
c40d7343efa60b18ad1ceb316eb337caeea79046cindiprint_node(topo_hdl_t *thp, tnode_t *node, nvlist_t *nvl, const char *fmri)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi (void) fprintf(stderr, "%s: failed to get fmri for %s=%d: %s\n",
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (nvlist_lookup_nvlist_array(fmri, FM_FMRI_HC_LIST, &hcl, &n) != 0) {
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi (void) fprintf(stderr, "%s: failed to find %s for %s=%d\n",
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi for (i = 0; i < n; i++) {
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (nvlist_lookup_string(hcl[i], FM_FMRI_HC_NAME, &name) != 0 ||
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi nvlist_lookup_string(hcl[i], FM_FMRI_HC_ID, &inst) != 0) {
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robjprint_prop_nameval(topo_hdl_t *thp, tnode_t *node, nvlist_t *nvl)
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi /* Print property name */
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi if ((pv_nvp = nvlist_next_nvpair(nvl, NULL)) == NULL ||
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi strcmp(TOPO_PROP_VAL_NAME, nvpair_name(pv_nvp)) != 0) {
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi (void) fprintf(stderr, "%s: malformed property name\n",
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi if ((pv_nvp = nvlist_next_nvpair(nvl, pv_nvp)) == NULL ||
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi strcmp(nvpair_name(pv_nvp), TOPO_PROP_VAL_TYPE) != 0 ||
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi (void) fprintf(stderr, "%s: malformed property type for %s\n",
c40d7343efa60b18ad1ceb316eb337caeea79046cindi (void) nvpair_value_uint32(pv_nvp, (uint32_t *)&type);
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi case TOPO_TYPE_UINT32_ARRAY: tstr = "uint32[]"; break;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi case TOPO_TYPE_UINT64_ARRAY: tstr = "uint64[]"; break;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi case TOPO_TYPE_STRING_ARRAY: tstr = "string[]"; break;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi * Get property value
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi (void) fprintf(stderr, "%s: malformed property value\n",
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj * Special case code to do friendlier printing of
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj * facility node properties
88045cff0aae4ed8823cd0989168e8f56927f83eRobert Johnston (void) nvpair_value_int32_array(pv_nvp, &val, &nelem);
88045cff0aae4ed8823cd0989168e8f56927f83eRobert Johnston for (i = 0; i < nelem; i++)
9dd0f810214fdc8e1af881a9a5c4b6927629ff9ecindi (void) nvpair_value_uint32_array(pv_nvp, &val, &nelem);
9dd0f810214fdc8e1af881a9a5c4b6927629ff9ecindi for (i = 0; i < nelem; i++)
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj for (i = 0; i < nelem; i++)
88045cff0aae4ed8823cd0989168e8f56927f83eRobert Johnston (void) nvpair_value_uint64_array(pv_nvp, &val, &nelem);
88045cff0aae4ed8823cd0989168e8f56927f83eRobert Johnston for (i = 0; i < nelem; i++)
602ca9ea8f9ce0933f0944601cc5d230e91a950dcth for (i = 0; i < nelem; i++)
c40d7343efa60b18ad1ceb316eb337caeea79046cindiprint_pgroup(topo_hdl_t *thp, tnode_t *node, const char *pgn, char *dstab,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (node != NULL && (dstab == NULL || nstab == NULL || version == -1)) {
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if ((pgi = topo_pgroup_info(node, pgn, &err)) != NULL) {
c40d7343efa60b18ad1ceb316eb337caeea79046cindi dstab = (char *)topo_stability2name(pgi->tpi_datastab);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi nstab = (char *)topo_stability2name(pgi->tpi_namestab);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (dstab == NULL || nstab == NULL || version == -1) {
888e055994b8b0dc77b98c53dd97026237caec5dRobert Johnston (void) printf(" group: %-30s version: - stability: -/-\n",
888e055994b8b0dc77b98c53dd97026237caec5dRobert Johnston (void) printf(" group: %-30s version: %-3d stability: %s/%s\n",
888e055994b8b0dc77b98c53dd97026237caec5dRobert Johnston (void) printf(" group: %-30s version: %-3d stability: %s/%s\n",
c40d7343efa60b18ad1ceb316eb337caeea79046cindiprint_all_props(topo_hdl_t *thp, tnode_t *node, nvlist_t *p_nv,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi const char *group)
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi for (nvp = nvlist_next_nvpair(p_nv, NULL); nvp != NULL;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi for (pg_nvp = nvlist_next_nvpair(pg_nv, NULL); pg_nvp != NULL;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi * Print property group name and stability levels
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * Print property group and property name-value pair
c40d7343efa60b18ad1ceb316eb337caeea79046cindiset_prop(topo_hdl_t *thp, tnode_t *node, nvlist_t *fmri, struct prop_args *pp)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (pp->prop == NULL || pp->type == NULL || pp->value == NULL)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if ((type = str2type(pp->type)) == TOPO_TYPE_INVALID) {
c40d7343efa60b18ad1ceb316eb337caeea79046cindi (void) fprintf(stderr, "%s: invalid property type %s for %s\n",
c40d7343efa60b18ad1ceb316eb337caeea79046cindi (void) fprintf(stderr, "%s: nvlist allocation failed for "
c40d7343efa60b18ad1ceb316eb337caeea79046cindi "%s=%s:%s\n", g_pname, pp->prop, pp->type, pp->value);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi ret = nvlist_add_string(nvl, TOPO_PROP_VAL_NAME, pp->prop);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi ret |= nvlist_add_uint32(nvl, TOPO_PROP_VAL_TYPE, type);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (ret != 0) {
c40d7343efa60b18ad1ceb316eb337caeea79046cindi (void) fprintf(stderr, "%s: invalid property type %s for %s\n",
1410cb930a3e26032c59c6835837a28c47366b3cJoshua M. Clulow if ((ret = topo_fmri_str2nvl(thp, pp->value, &val,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (ret != 0) {
c40d7343efa60b18ad1ceb316eb337caeea79046cindi (void) fprintf(stderr, "%s: unable to set property value for "
1410cb930a3e26032c59c6835837a28c47366b3cJoshua M. Clulow if ((ret = topo_prop_setprop(node, pp->group, nvl,
1410cb930a3e26032c59c6835837a28c47366b3cJoshua M. Clulow if ((ret = topo_fmri_setprop(thp, fmri, pp->group, nvl,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * Now, get the property back for printing
1410cb930a3e26032c59c6835837a28c47366b3cJoshua M. Clulow if ((ret = topo_prop_getprop(node, pp->group, pp->prop, NULL,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi (void) fprintf(stderr, "%s: failed to get %s.%s: %s\n",
1410cb930a3e26032c59c6835837a28c47366b3cJoshua M. Clulow if ((ret = topo_fmri_getprop(thp, fmri, pp->group, pp->prop,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi (void) fprintf(stderr, "%s: failed to get %s.%s: %s\n",
c40d7343efa60b18ad1ceb316eb337caeea79046cindi for (i = 0; i < pcnt; ++i) {
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * If we have a valid value, this is a request to
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * set a property. Otherwise, just print the property
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * group and any specified properties.
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * Print all properties in this group
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi/*ARGSUSED*/
b695575577bae0337af339d76949713bfe1c9013Robert Johnston if (topo_method_invoke(node, opt_m, 0, NULL, &out, &err) == 0) {
b695575577bae0337af339d76949713bfe1c9013Robert Johnston (void) fprintf(stderr, "%s: method failed unexpectedly "
b695575577bae0337af339d76949713bfe1c9013Robert Johnston "on %s=%d (%s)\n", g_pname, topo_node_name(node),
b695575577bae0337af339d76949713bfe1c9013Robert Johnston topo_node_instance(node), topo_strerror(err));
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj } else if (pcnt > 0)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi char c, *s, *p;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if ((pargs = malloc(sizeof (struct prop_args *) * pcnt)) == NULL) {
c40d7343efa60b18ad1ceb316eb337caeea79046cindi (void) fprintf(stderr, "%s: failed to allocate property "
c40d7343efa60b18ad1ceb316eb337caeea79046cindi for (optind = 1; (c = getopt(argc, argv, optstr)) != EOF; ) {
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (c == 'P') {
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if ((pp = pargs[i] = malloc(sizeof (struct prop_args)))
c40d7343efa60b18ad1ceb316eb337caeea79046cindi *s++ = '\0';
c40d7343efa60b18ad1ceb316eb337caeea79046cindi "property type not "
c40d7343efa60b18ad1ceb316eb337caeea79046cindi "specified for assignment "
c40d7343efa60b18ad1ceb316eb337caeea79046cindi for (j = 0; j < i; ++j)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if ((twp = topo_walk_init(thp, opt_s, walk_node, NULL, &err))
c40d7343efa60b18ad1ceb316eb337caeea79046cindi (void) fprintf(stderr, "%s: failed to walk %s topology:"
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (-1);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * Print standard header
c40d7343efa60b18ad1ceb316eb337caeea79046cindi (void) strftime(buf, sizeof (buf), "%b %d %T", localtime(&tod));
c40d7343efa60b18ad1ceb316eb337caeea79046cindi (void) fprintf(stderr, "%s: failed to walk topology\n",
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (-1);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (0);
c40d7343efa60b18ad1ceb316eb337caeea79046cindiprint_fmri_pgroup(topo_hdl_t *thp, const char *pgn, nvlist_t *nvl)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi (void) nvlist_lookup_string(nvl, TOPO_PROP_GROUP_NSTAB, &nstab);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi (void) nvlist_lookup_string(nvl, TOPO_PROP_GROUP_DSTAB, &dstab);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi (void) nvlist_lookup_int32(nvl, TOPO_PROP_GROUP_VERSION, &version);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi for (pnvp = nvlist_next_nvpair(nvl, NULL); pnvp != NULL;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * Print property group and property name-value pair
c40d7343efa60b18ad1ceb316eb337caeea79046cindi for (i = 0; i < pcnt; ++i) {
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * If we have a valid value, this is a request to
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * set a property. Otherwise, just print the property
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * group and any specified properties.
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * Print all properties in this group
c40d7343efa60b18ad1ceb316eb337caeea79046cindi (void) fprintf(stderr, "%s: failed to convert %s to nvlist: "
c40d7343efa60b18ad1ceb316eb337caeea79046cindi (void) strftime(buf, sizeof (buf), "%b %d %T", localtime(&tod));
c40d7343efa60b18ad1ceb316eb337caeea79046cindi for (i = 0; i < pcnt; ++i)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi switch (c) {
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if ((thp = topo_open(TOPO_VERSION, opt_R, &err)) == NULL) {
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi (void) fprintf(stderr, "%s: failed to open topology tree: %s\n",
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if ((uuid = topo_snap_hold(thp, NULL, &err)) == NULL) {
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi (void) fprintf(stderr, "%s: failed to snapshot topology: %s\n",
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi } else if (err != 0) {
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby (void) fprintf(stderr, "%s: topology snapshot incomplete%s\n",
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby " (" FM_FMRI_SCHEME_HC " scheme does not enumerate "
78432d5ed5122db8b0bbfa41e00d063bf8ae7171cy "%s: -b and -x cannot be specified together\n",
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (fmtopo_exit(thp, uuid, err ? FMTOPO_EXIT_ERROR :
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * Try getting some useful information