Example #1
0
/*ARGSUSED*/
static int
asru_verb1(fmd_log_t *lp, const fmd_log_record_t *rp, FILE *fp)
{
	char *uuid = "-";
	boolean_t f = 0, u = 0;
	char buf[32], state[32];

	(void) nvlist_lookup_string(rp->rec_nvl, FM_RSRC_ASRU_UUID, &uuid);
	(void) nvlist_lookup_boolean_value(rp->rec_nvl,
	    FM_RSRC_ASRU_FAULTY, &f);
	(void) nvlist_lookup_boolean_value(rp->rec_nvl,
	    FM_RSRC_ASRU_UNUSABLE, &u);

	state[0] = '\0';

	if (f)
		(void) strcat(state, ",faulty");
	if (u)
		(void) strcat(state, ",unusable");
	if (!f && !u)
		(void) strcat(state, ",ok");

	fmdump_printf(fp, "%-20s %-36s %s\n",
	    fmdump_date(buf, sizeof (buf), rp), uuid, state + 1);

	return (0);
}
Example #2
0
boolean_t
fnvlist_lookup_boolean_value(nvlist_t *nvl, const char *name)
{
	boolean_t rv;
	VERIFY0(nvlist_lookup_boolean_value(nvl, name, &rv));
	return (rv);
}
Example #3
0
void
setupInterface(nvlist_t *data)
{
    char *iface, *gateway, *netmask, *ip;
    boolean_t primary;
    int ret;

    ret = nvlist_lookup_string(data, "interface", &iface);
    if (ret == 0) {
        plumbIf(iface);

        ret = nvlist_lookup_string(data, "ip", &ip);
        if (ret == 0) {
            ret = nvlist_lookup_string(data, "netmask", &netmask);
            if (ret == 0) {
                if (raiseIf(iface, ip, netmask) != 0) {
                    fatal(ERR_RAISE_IF, "Error bringing up interface %s",
                        iface);
                }
            }
            ret = nvlist_lookup_boolean_value(data, "primary", &primary);
            if ((ret == 0) && (primary == B_TRUE)) {
                ret = nvlist_lookup_string(data, "gateway", &gateway);
                if (ret == 0) {
                    (void) addRoute(iface, gateway, "0.0.0.0", 0);
                }
            }
        }
    }
}
Example #4
0
static const cma_subscriber_t *
nvl2subr(fmd_hdl_t *hdl, nvlist_t *nvl, nvlist_t **asrup)
{
	const cma_subscriber_t *sp;
	nvlist_t *asru;
	char *scheme;
	uint8_t version;
	boolean_t retire;

	if (nvlist_lookup_boolean_value(nvl, FM_SUSPECT_RETIRE, &retire) == 0 &&
	    retire == 0) {
		fmd_hdl_debug(hdl, "cma_recv: retire suppressed");
		return (NULL);
	}

	if (nvlist_lookup_nvlist(nvl, FM_FAULT_ASRU, &asru) != 0 ||
	    nvlist_lookup_string(asru, FM_FMRI_SCHEME, &scheme) != 0 ||
	    nvlist_lookup_uint8(asru, FM_VERSION, &version) != 0) {
		cma_stats.bad_flts.fmds_value.ui64++;
		return (NULL);
	}

	for (sp = cma_subrs; sp->subr_class != NULL; sp++) {
		if (fmd_nvl_class_match(hdl, nvl, sp->subr_class) &&
		    strcmp(scheme, sp->subr_sname) == 0 &&
		    version <= sp->subr_svers) {
			*asrup = asru;
			return (sp);
		}
	}

	cma_stats.nop_flts.fmds_value.ui64++;
	return (NULL);
}
Example #5
0
static int
setupStaticRoute(nvlist_t *route, const char *idx)
{
    boolean_t linklocal = B_FALSE;
    char *slash;
    char *dstraw = NULL;
    char *dst;
    char *gateway;
    int dstpfx = -1;
    int ret = -1;

    if (nvlist_lookup_boolean_value(route, "linklocal", &linklocal) == 0 &&
      linklocal) {
        WARNLOG("route[%s]: linklocal routes not supported", idx);
        goto bail;
    }

    if (nvlist_lookup_string(route, "dst", &dst) != 0) {
        WARNLOG("route[%s]: route is missing \"dst\"", idx);
        goto bail;
    }

    if (nvlist_lookup_string(route, "gateway", &gateway) != 0) {
        WARNLOG("route[%s]: route is missing \"gateway\"", idx);
        goto bail;
    }

    /*
     * Parse the CIDR-notation destination specification.  For example:
     * "172.20.5.1/24" becomes a destination of "172.20.5.1" with a prefix
     * length of 24.
     */
    if ((dstraw = strdup(dst)) == NULL) {
        WARNLOG("route[%s]: strdup failure", idx);
        goto bail;
    }

    if ((slash = strchr(dstraw, '/')) == NULL) {
        WARNLOG("route[%s]: dst \"%s\" invalid", idx, dst);
        goto bail;
    }
    *slash = '\0';
    dstpfx = atoi(slash + 1);
    if (dstpfx < 0 || dstpfx > 32) {
        WARNLOG("route[%s]: dst \"%s\" pfx %d invalid", idx, dst, dstpfx);
        goto bail;
    }

    if ((ret = addRoute(NULL, gateway, dstraw, dstpfx)) != 0) {
        WARNLOG("route[%s]: failed to add (%d)", idx, ret);
        goto bail;
    }

    ret = 0;

bail:
    free(dstraw);
    return (ret);
}
Example #6
0
static void
mountNfsVolume(nvlist_t *data)
{
    boolean_t readonly;
    char *nfsvolume, *mountpoint;
    int ret;

    ret = nvlist_lookup_string(data, "nfsvolume", &nfsvolume);
    if (ret == 0) {
        ret = nvlist_lookup_string(data, "mountpoint", &mountpoint);
        if (ret == 0) {
            ret = nvlist_lookup_boolean_value(data, "readonly", &readonly);
            if (ret != 0) {
                readonly = B_FALSE;
            }
            doNfsMount(nfsvolume, mountpoint, readonly);
            return;
        }
    }

    fatal(ERR_INVALID_NFS_VOLUMES, "invalid nfsvolumes");
}
/*
 * Operates on a single di_node_t, collecting all the device properties
 * that we need. devnvl is allocated by the caller, and we add our nvpairs
 * to it if they don't already exist.
 *
 * We are _only_ interested in devices which have a devid. We pull in
 * devices even when they're excluded via stmsboot -D (driver), because
 * we don't want to miss out on any devid data that might be handy later.
 */
static int
popcheck_devnvl(di_node_t thisnode, nvlist_t *devnvl, char *strdevid)
{
	char *path = NULL;
	char *curpath = NULL;
	char *devfspath = NULL;
	char *prop = NULL;
	int scsivhciparent = 0;
	int rv = 0;
	boolean_t mpxenp = B_FALSE;

	errno = 0;
	devfspath = di_devfs_path(thisnode);
	if (devfspath == NULL) {
		logmsg(MSG_ERROR,
		    gettext("Unable to determine devfs path for node: %s\n"),
		    strerror(errno));
		return (-1);
	}

	/* Add a convenient devfspath to devid inverse map */
	if (nvlist_add_string(mapnvl, devfspath, strdevid) != 0) {
		logmsg(MSG_ERROR,
		    gettext("Unable to add device path %s with devid "
		    "%s to mapnvl\n"), devfspath, strdevid);
		return (-1);
	}
	if (di_prop_lookup_strings(DDI_DEV_T_ANY, di_parent_node(thisnode),
	    "mpxio-disable", &prop) >= 0) {
		if (strncmp(prop, "yes", 3) == 0) {
			if (!mpxprop)
				mpxprop++;
		}
	}

	if (strncmp(di_driver_name(di_parent_node(thisnode)),
	    "scsi_vhci", 9) == 0) {
		scsivhciparent = 1;
		if (!mpxenabled)
			mpxenabled++;

		rv = nvlist_lookup_boolean_value(devnvl, NVL_MPXEN, &mpxenp);
		if (rv || (mpxenp == B_FALSE)) {
			rv = nvlist_add_boolean_value(devnvl,
			    NVL_MPXEN, B_TRUE);
			if (rv) {
				logmsg(MSG_ERROR,
				    gettext("Unable to add property %s "
				    "(set to B_TRUE) for device %s: "
				    "%s (%d)\n"),
				    NVL_MPXEN, devfspath,
				    strerror(rv), rv);
				return (-1);
			}
			logmsg(MSG_INFO, "NVL_MPXEN :: (B_FALSE->B_TRUE)\n");
		}
	} else {
		/* turn _off_ the flag if it was enabled */
		rv = nvlist_add_boolean_value(devnvl, NVL_MPXEN, B_FALSE);
		if (rv) {
			logmsg(MSG_ERROR,
			    gettext("Unable to add property %s "
			    "(set to B_FALSE) for device %s: %s (%d)\n"),
			    NVL_MPXEN, devfspath,
			    strerror(rv), rv);
			return (-1);
		}
		logmsg(MSG_INFO, "NVL_MPXEN :: (B_TRUE-> B_FALSE)\n");
	}

	rv = nvlist_add_string(devnvl, NVL_PHYSPATH, devfspath);
	if (rv) {
		logmsg(MSG_ERROR,
		    gettext("Unable to add physical device path (%s) "
		    "property to nvl\n"));
		return (-1);
	}

	if ((curpath = calloc(1, MAXPATHLEN)) == NULL) {
		logmsg(MSG_ERROR,
		    gettext("Unable to allocate space for current path\n"));
		return (-1);
	}
	curpath = find_link(thisnode);
	if (curpath == NULL) {
		if (readonlyroot) {
			return (0);
		}
		logmsg(MSG_ERROR,
		    gettext("Unable to determine device path for node %s\n"),
		    devfspath);
		return (-1);
	}

	rv = nvlist_lookup_string(devnvl, NVL_MPXPATH, &path);

	if (scsivhciparent) {
		(void) nvlist_add_string(devnvl, NVL_MPXPATH, curpath);
	} else {
		(void) nvlist_add_string(devnvl, NVL_PATH, curpath);
		path = curpath;
	}

	/*
	 * This next block provides the path to devid inverse mapping
	 * that other functions require
	 */
	if (path != NULL) {
		if (nvlist_add_string(mapnvl, path, strdevid) != 0) {
			logmsg(MSG_ERROR,
			    gettext("Unable to add device %s with devid "
			    "%s to mapnvl\n"), path, strdevid);
			return (-1);
		}
		logmsg(MSG_INFO, "popcheck_devnvl: added path %s :: %s\n",
		    path, strdevid);
	}

	if (nvlist_add_string(mapnvl, curpath, strdevid) != 0) {
			logmsg(MSG_ERROR,
			    gettext("Unable to add device %s with devid "
			    "%s to mapnvl: %s\n"),
			    curpath, strdevid, strerror(errno));
			return (-1);
	}
	logmsg(MSG_INFO, "popcheck_devnvl: added curpath %s :: %s\n",
	    curpath, strdevid);

	return (0);
}
/*
 * We get passed a device name which we search the mapnvl for. If we find
 * it, we print the mapping as it is found. It is up to the caller of this
 * utility to do any pretty-printing of the results. If a device listed on
 * the command line does not exist in the mapnvl, then we print NOT_MAPPED.
 * Otherwise we print the command-line device name as it maps to what is
 * stashed in the mapnvl - even if that's a "no change" device mapping.
 *
 * Example output (-p maps to physpath=BOOT)
 * # /lib/mpxio/stmsboot_util -p \
 *	/pci@0,0/pci1022,7450@2/pci1000,3060@3/sd@1,0:a
 * /scsi_vhci/disk@g500000e011e17720:a
 *
 * Or the reverse:
 * # /lib/mpxio/stmsboot_util -p /scsi_vhci/disk@g500000e011e17720:a
 * /pci@0,0/pci1022,7450@2/pci1000,3060@3/sd@1,0:a
 *
 * For the -m option, used when we're trying to find the root device mapping:
 *
 * # /lib/mpxio/stmsboot_util -m /dev/dsk/c2t0d0s2
 * /dev/dsk/c3t500000E011637CF0d0s2
 */
static void
report_map(char *argdev, int physpath)
{
	nvlist_t *thisdev;
	int rv = 0;
	char *thisdevid;
	char *mpxpath = NULL;
	char *prefixt = NULL;
	char *prefixp = NULL;
	char *stripdev = NULL;
	char *slice = NULL;
	boolean_t mpxenp;
	uint_t slicelen = 0;

	mpxenp = B_FALSE;

	if ((prefixt = calloc(1, strlen(argdev) + 1)) == NULL) {
		logmsg(MSG_INFO, "Unable to allocate memory\n");
		(void) printf("NOT_MAPPED\n");
		return;
	}

	(void) strlcpy(prefixt, argdev, strlen(argdev) + 1);

	slice = strrchr(argdev, (physpath == NONBOOT) ? 's' : ':');
	if (slice != NULL) {
		slicelen = strlen(slice);
		if (slicelen > 3)
			/* invalid size - max is 3 chars */
			slicelen = 0;
	}

	if ((stripdev = calloc(1, strlen(prefixt) + 1)) == NULL) {
		logmsg(MSG_INFO, "Unable to allocate memory\n");
		(void) printf("NOT_MAPPED\n");
		free(prefixt);
		return;
	}

	if ((strstr(prefixt, "/scsi_vhci") == NULL) &&
	    (strstr(prefixt, "/pci") == NULL) &&
	    (strstr(prefixt, "/sbus") == NULL)) {
		prefixp = strrchr(prefixt, '/');
		(void) strlcpy(stripdev,
		    (prefixp == NULL) ? prefixt : prefixp + 1,
		    (prefixp == NULL) ?
		    strlen(prefixt) + 1: strlen(prefixp) + 1);
		if (prefixp != NULL)
			prefixt[strlen(argdev) - strlen(prefixp) + 1] = '\0';
	} else {
		if ((physpath != BOOT) &&
		    (physpath != BOOT_PATH)) {
			logmsg(MSG_INFO, "Invalid device path provided\n");
			(void) printf("NOT_MAPPED\n");
			free(stripdev);
			free(prefixt);
			return;
		}
		(void) strlcpy(stripdev, argdev, strlen(argdev) + 1);
	}

	logmsg(MSG_INFO,
	    "stripdev (%s), prefixt(%s), prefixp(%s), slice(%s)\n",
	    (stripdev == NULL) ? "null" : stripdev,
	    (prefixt == NULL) ? "null" : prefixt,
	    (prefixp == NULL) ? "null" : prefixp,
	    (slice == NULL) ? "null" : slice);

	if (slicelen > 0)
		stripdev[strlen(stripdev) - slicelen] = '\0';

	/* search for the shortened version */
	rv = nvlist_lookup_string(mapnvl, stripdev, &thisdevid);
	if (rv) {
		if ((physpath != BOOT) &&
		    (physpath != BOOT_PATH)) {
			logmsg(MSG_INFO,
			    "searched mapnvl for '%s', got %s (%d)\n",
			    stripdev, strerror(rv), rv);
			(void) printf("NOT_MAPPED\n");
			free(stripdev);
			free(prefixt);
			return;
		}
	}

	logmsg(MSG_INFO, "device %s has devid %s\n", stripdev, thisdevid);

	if (nvlist_lookup_nvlist(mapnvl, thisdevid, &thisdev) != 0) {
		logmsg(MSG_INFO, "device (%s) in mapnvl but "
		    "not mapped!\n", thisdevid);
		(void) printf("NOT_MAPPED\n");
		free(stripdev);
		free(prefixt);
		return;
	}

	/* quick exit */
	if (!mpxenabled && (strstr(argdev, "/pci") != NULL ||
	    strstr(argdev, "/sbus") != NULL)) {
		(void) printf("%s\n", argdev);
		free(stripdev);
		free(prefixt);
		return;
	}

	(void) nvlist_lookup_boolean_value(thisdev, NVL_MPXEN, &mpxenp);

	if (physpath == BOOT) {
		(void) nvlist_lookup_string(thisdev, NVL_PHYSPATH, &mpxpath);
		if ((strstr(argdev, "/scsi_vhci") != NULL) &&
		    (strncmp(argdev, mpxpath, strlen(mpxpath)) == 0)) {
			/* Need to translate vhci to phci */
			vhci_to_phci(stripdev, slice, DISPLAY_ONE_PATH);
		} else {
			(void) printf("%s%s\n", mpxpath,
			    ((slicelen > 0) && slice != NULL) ? slice : "");
		}
	} else if (physpath == BOOT_PATH) {
		(void) nvlist_lookup_string(thisdev, NVL_PHYSPATH, &mpxpath);
		if ((strstr(argdev, "/scsi_vhci") != NULL) &&
		    (strncmp(argdev, mpxpath, strlen(mpxpath)) == 0)) {
			/* Need to translate vhci to phci */
			vhci_to_phci(stripdev, slice, DISPLAY_ALL_PATH);
		} else {
			(void) printf("%s%s\n", mpxpath,
			    ((slicelen > 0) && slice != NULL) ? slice : "");
		}
	} else {
		(void) nvlist_lookup_string(thisdev,
		    ((readonlyroot) ? NVL_PHYSPATH :
		    ((mpxenp == B_TRUE) ? NVL_MPXPATH : NVL_PATH)),
		    &mpxpath);
		logmsg(MSG_INFO, "mpxpath = %s\n",
		    (mpxpath == NULL) ? "null" : mpxpath);
		if (readonlyroot ||
		    (strstr(mpxpath, "/scsi_vhci") != NULL) ||
		    (strstr(mpxpath, "/pci") != NULL) ||
		    (strstr(mpxpath, "/sbus") != NULL)) {
			/*
			 * If we see a physical path here it means that
			 * devlinks aren't fully initialised yet, so we
			 * are still in maintenance/single-user mode.
			 */
			(void) printf("/devices%s:%c\n", mpxpath,
			    slice[1] + '1');
		} else {
			(void) printf("%s%s%s\n",
			    (prefixt[0] == '/') ? prefixt : "",
			    mpxpath,
			    ((slicelen > 0) && slice != NULL) ? slice : "");
		}
	}
	free(prefixt);
	free(stripdev);
}
/*
 * It's up to the caller to do any sorting or pretty-printing of the device
 * mappings we report. Since we're storing the device links as just the cXtYdZ
 * part, we'll add /dev/rdsk/ back on when we print the listing so we maintain
 * compatibility with previous versions of this tool. There's a little bit
 * of footwork involved to make sure that we show all the paths to a device
 * rather than just the first one we stashed away.
 */
static void
list_devs(int listguids, int ctrl)
{
	nvlist_t *thisdevnvl;
	nvpair_t *pair;
	char *diskpath, *livepath, *key, *querydev;
	char *matchctrl = NULL;
	char checkctrl[MAXPATHLEN];
	int rv;

	if (!mpxenabled) {
		if (mpxprop) {
			logmsg(MSG_ERROR, gettext("MPXIO disabled\n"));
		} else {
			logmsg(MSG_ERROR, gettext("No STMS devices have "
			    "been found\n"));
		}
		return;
	}

	if (listguids) {
		(void) printf(gettext("non-STMS device name\t\t\tGUID\n"
		    "------------------------------------------"
		    "------------------------\n"));
	} else {
		(void) printf(gettext("non-STMS device name\t\t\t"
		    "STMS device name\n"
		    "------------------------------------------"
		    "------------------------\n"));
	}

	bzero(checkctrl, MAXPATHLEN);
	pair = NULL;
	while ((pair = nvlist_next_nvpair(mapnvl, pair))
	    != NULL) {
		boolean_t livescsivhcip = B_FALSE;

		if ((((rv = nvpair_value_string(pair, &querydev)) < 0) ||
		    ((key = nvpair_name(pair)) == NULL)) ||
		    ((strstr(key, "/pci") != NULL) ||
		    (strstr(key, "/sbus") != NULL) ||
		    (strstr(key, "/scsi_vhci") != NULL) ||
		    (strncmp(key, "id1", 3) == 0))) {
			logmsg(MSG_INFO,
			    "list_devs: rv = %d; (%s) is not a devlink, "
			    "continuing.\n", rv,
			    (key != NULL) ? key : "null");
			querydev = NULL;
			continue;
		}

		(void) nvlist_lookup_nvlist(mapnvl, querydev, &thisdevnvl);
		(void) nvlist_lookup_boolean_value(thisdevnvl, NVL_MPXEN,
		    &livescsivhcip);
		(void) nvlist_lookup_string(thisdevnvl, NVL_MPXPATH,
		    &livepath);

		if ((!livescsivhcip) ||
		    (livescsivhcip &&
		    (strncmp(key, livepath, strlen(key)) == 0)))
			continue;

		(void) nvlist_lookup_string(thisdevnvl, NVL_PATH,
		    &diskpath);

		logmsg(MSG_INFO,
		    "list_devs: %s :: %s ::%s :: MPXEN (%s)\n",
		    key, diskpath, livepath,
		    ((livescsivhcip) ? "TRUE" : "FALSE"));

		if (ctrl > -1) {
			(void) sprintf(checkctrl, "c%dt", ctrl);
			matchctrl = strstr(key, checkctrl);
			if (matchctrl == NULL)
				continue;
		}
		if (listguids != 0) {
			char *tempguid;
			ddi_devid_t curdevid;
			int rv;

			rv = devid_str_decode(querydev, &curdevid, NULL);
			if (rv == -1) {
				logmsg(MSG_INFO, "Unable to decode devid %s\n",
				    key);
				continue;
			}
			tempguid = devid_to_guid(curdevid);
			if (tempguid != NULL)
				(void) printf("/dev/rdsk/%s\t%s\n",
				    diskpath, tempguid);

			devid_free_guid(tempguid);
			devid_free(curdevid);
			continue;
		}

		(void) printf("/dev/rdsk/%s\t/dev/rdsk/%s\n",
		    (strstr(key, diskpath) == NULL) ? key : diskpath,
		    livepath);
	}
}
Example #10
0
/*
 * Write /etc/vfstab to /etc/vfstab.new, with any remapped device
 * names substituted.
 *
 * Returns:
 *	0	successful operation
 *	-1	failed
 */
static int
update_vfstab()
{
	FILE *fdin, *fdout;
	char *buf, *tmpbuf;
	char fname[MAXPATHLEN];
	int rv = -1, rval = -1;
	char cdev[MAXPATHLEN];
	char bdev[MAXPATHLEN];
	char mntpt[MAXPATHLEN];
	char fstype[512];
	char fsckpass[512];
	char mntboot[512];
	char mntopt[MAXPATHLEN];
	char fmt[80];
	char *prefixt = NULL;
	char *curdev = NULL;
	char *thisdevid = NULL;
	char *slice = NULL;
	nvlist_t *thisdev;
	boolean_t devmpx = B_FALSE;

	buf = calloc(1, MAXPATHLEN);
	tmpbuf = calloc(1, MAXPATHLEN);
	if (buf == NULL || tmpbuf == NULL)
		return (-1);

	(void) snprintf(fname, MAXPATHLEN, "/etc/mpxio/vfstab.new");

	fdin = fopen("/etc/vfstab", "r");
	fdout = fopen(fname, "w+");
	if (fdin == NULL || fdout == NULL) {
		logmsg(MSG_INFO, "Unable to open vfstab or create a backup "
		    "vfstab %s\n");
		return (-1);
	}

	(void) snprintf(fmt, sizeof (fmt),
	    "%%%ds %%%ds %%%ds %%%ds %%%ds %%%ds %%%ds", sizeof (bdev) - 1,
	    sizeof (cdev) - 1, sizeof (mntpt) - 1, sizeof (fstype) - 1,
	    sizeof (fsckpass) - 1, sizeof (mntboot) - 1, sizeof (mntopt) - 1);

	while (fgets(buf, MAXPATHLEN, fdin) != NULL) {
		if (strlen(buf) == (MAXPATHLEN - 1) &&
		    buf[MAXPATHLEN-2] != '\n') {
			logmsg(MSG_ERROR,
			    gettext("/etc/vfstab line length too long, "
			    "exceeded %2$d: \"%3$s\"\n"),
			    MAXPATHLEN - 2, buf);
			goto out;
		}

		prefixt = NULL;
		curdev = NULL;
		slice = NULL;
		thisdevid = NULL;
		thisdev = NULL;

		/* LINTED - variable format specifier */
		rv = sscanf(buf, fmt, bdev, cdev, mntpt, fstype, fsckpass,
		    mntboot, mntopt);

		/*
		 * Walk through the lines in the input file (/etc/vfstab),
		 * skipping anything which is _not_ a COGD (common or garden
		 * disk), ie all the /devices, /system, /dev/md, /dev/vx and
		 * /dev/zvol and so forth.
		 */
		if ((rv == 7) && (bdev[0] == '/') &&
		    (strstr(bdev, "/dev/dsk"))) {
			slice = strrchr(bdev, 's');
			/* take a copy, strip off /dev/dsk/ */
			prefixt = strrchr(bdev, 'c');
			prefixt[strlen(bdev) - 9 - strlen(slice)] = '\0';
			slice++; /* advance past the s */
			rval = nvlist_lookup_string(mapnvl, prefixt,
			    &thisdevid);
			if (rval) {
				/* Whoa, where did this device go?! */
				logmsg(MSG_INFO,
				    "error looking up device %s\n", prefixt);
				/* Comment-out this line in the new version */
				(void) snprintf(tmpbuf, MAXPATHLEN,
				    "# DEVICE NOT FOUND %s", buf);
				(void) fprintf(fdout, "%s", tmpbuf);
				continue;
			} else {
				/* The device exists in our mapnvl */
				(void) nvlist_lookup_nvlist(mapnvl, thisdevid,
				    &thisdev);
				(void) nvlist_lookup_boolean_value(thisdev,
				    NVL_MPXEN, &devmpx);
				(void) nvlist_lookup_string(thisdev,
				    ((devmpx == B_TRUE)
				    ? NVL_MPXPATH : NVL_PATH),
				    &curdev);
			}
		}

		if ((prefixt != NULL) && (curdev != NULL) &&
		    (rv = (strncmp(prefixt, curdev, strlen(prefixt)) != 0))) {
			/* Mapping change for this device */
			if (strcmp(fstype, "swap") == 0) {
				(void) snprintf(tmpbuf, MAXPATHLEN,
				    "/dev/dsk/%ss%s\t-\t-\tswap\t"
				    "%s\t%s\t%s\n",
				    curdev, slice, fsckpass, mntboot, mntopt);
			} else {
				(void) snprintf(tmpbuf, MAXPATHLEN,
				    "/dev/dsk/%ss%s\t/dev/rdsk/%ss%s\t"
				    "%s\t%s\t%s\t%s\t%s\n",
				    curdev, slice, curdev, slice,
				    mntpt, fstype, fsckpass, mntboot, mntopt);
			}
			errno = 0;
			(void) fprintf(fdout, "%s", tmpbuf);
		} else {
			(void) fprintf(fdout, "%s", buf);
		}

		errno = 0;
		if (fflush(fdout) != 0) {
			logmsg(MSG_ERROR,
			    gettext("fprintf failed to write to %s: %s (%d)\n"),
			    fname, strerror(errno), errno);
			goto out;
		}
	}
out:
	(void) fclose(fdin);
	(void) fclose(fdout);
	free(buf);
	free(tmpbuf);
	return (errno);
}
Example #11
0
static void
print_disks(dm_descriptor_t media, di_opts_t *opts)
{
	dm_descriptor_t *disk, *controller;
	nvlist_t *mattrs, *dattrs, *cattrs;
	int error;

	uint64_t size, total;
	uint32_t blocksize;
	double total_in_GiB;
	char sizestr[32];

	char *vid, *pid, *opath, *c, *ctype;
	boolean_t removable;
	char device[MAXPATHLEN];
	size_t len;

	mattrs = dm_get_attributes(media, &error);
	assert(nvlist_lookup_uint64(mattrs, DM_SIZE, &size) == 0);
	assert(nvlist_lookup_uint32(mattrs, DM_BLOCKSIZE, &blocksize) == 0);
	nvlist_free(mattrs);

	if ((disk = dm_get_associated_descriptors(media,
	    DM_DRIVE, &error)) != NULL) {
		dattrs = dm_get_attributes(disk[0], &error);

		nvlist_query_string(dattrs, DM_VENDOR_ID, &vid);
		nvlist_query_string(dattrs, DM_PRODUCT_ID, &pid);
		nvlist_query_string(dattrs, DM_OPATH, &opath);

		removable = B_FALSE;
		(void) nvlist_lookup_boolean_value(dattrs,
		    DM_REMOVABLE, &removable);

		if ((controller = dm_get_associated_descriptors(disk[0],
		    DM_CONTROLLER, &error)) != NULL) {
			cattrs = dm_get_attributes(controller[0], &error);
			nvlist_query_string(cattrs, DM_CTYPE, &ctype);
			for (c = ctype; *c != '\0'; c++)
				*c = toupper(*c);
		}

		/*
		 * Parse full device path to only show the device name, i.e.
		 * c0t1d0.  Many paths will reference a particular slice
		 * (c0t1d0s0), so remove the slice if present.
		 */
		if ((c = strrchr(opath, '/')) != NULL)
			(void) strlcpy(device, c + 1, sizeof (device));
		else
			(void) strlcpy(device, opath, sizeof (device));
		len = strlen(device);
		if (device[len - 2] == 's' &&
		    (device[len - 1] >= '0' && device[len - 1] <= '9'))
			device[len - 2] = '\0';

		/*
		 * The size is given in blocks, so multiply the number of blocks
		 * by the block size to get the total size, then convert to GiB.
		 */
		total = size * blocksize;

		if (opts->di_parseable) {
			(void) snprintf(sizestr, sizeof (sizestr),
			    "%llu", total);
		} else {
			total_in_GiB = (double)total/ 1024.0 / 1024.0 / 1024.0;
			(void) snprintf(sizestr, sizeof (sizestr),
			    "%.2f GiB", total_in_GiB);
		}

		if (opts->di_scripted) {
			printf("%s\t%s\t%s\t%s\t%s\t%s\n",
			    ctype, device, vid, pid, sizestr,
			    removable ? "yes" : "no");
		} else {
			printf("%-4s    %-6s    %-8s    %-16s   "
			    "%-12s    %-4s\n", ctype, device,
			    vid, pid, sizestr, removable ? "yes" : "no");
		}

		nvlist_free(cattrs);
		nvlist_free(dattrs);
		dm_free_descriptors(controller);
	}

	dm_free_descriptors(disk);
}
Example #12
0
/*
 * iser_notice_key_values() activates the negotiated key values for
 * this connection.
 */
static void
iser_notice_key_values(idm_conn_t *ic, nvlist_t *negotiated_nvl)
{
    iser_conn_t		*iser_conn;
    boolean_t		boolean_val;
    uint64_t		uint64_val;
    int			nvrc;

    iser_conn = (iser_conn_t *)ic->ic_transport_private;

    /*
     * Validate the final negotiated operational parameters,
     * and save a copy.
     */
    if ((nvrc = nvlist_lookup_boolean_value(negotiated_nvl,
                                            "HeaderDigest", &boolean_val)) != ENOENT) {
        ASSERT(nvrc == 0);
        iser_conn->ic_op_params.op_header_digest = boolean_val;
    }

    if ((nvrc = nvlist_lookup_boolean_value(negotiated_nvl,
                                            "DataDigest", &boolean_val)) != ENOENT) {
        ASSERT(nvrc == 0);
        iser_conn->ic_op_params.op_data_digest = boolean_val;
    }

    if ((nvrc = nvlist_lookup_boolean_value(negotiated_nvl,
                                            "RDMAExtensions", &boolean_val)) != ENOENT) {
        ASSERT(nvrc == 0);
        iser_conn->ic_op_params.op_rdma_extensions = boolean_val;
    }

    if ((nvrc = nvlist_lookup_boolean_value(negotiated_nvl,
                                            "OFMarker", &boolean_val)) != ENOENT) {
        ASSERT(nvrc == 0);
        iser_conn->ic_op_params.op_ofmarker = boolean_val;
    }

    if ((nvrc = nvlist_lookup_boolean_value(negotiated_nvl,
                                            "IFMarker", &boolean_val)) != ENOENT) {
        ASSERT(nvrc == 0);
        iser_conn->ic_op_params.op_ifmarker = boolean_val;
    }

    if ((nvrc = nvlist_lookup_uint64(negotiated_nvl,
                                     "TargetRecvDataSegmentLength", &uint64_val)) != ENOENT) {
        ASSERT(nvrc == 0);
        iser_conn->ic_op_params.op_target_recv_data_segment_length =
            uint64_val;
    }

    if ((nvrc = nvlist_lookup_uint64(negotiated_nvl,
                                     "InitiatorRecvDataSegmentLength", &uint64_val)) != ENOENT) {
        ASSERT(nvrc == 0);
        iser_conn->ic_op_params.op_initiator_recv_data_segment_length =
            uint64_val;
    }

    if ((nvrc = nvlist_lookup_uint64(negotiated_nvl,
                                     "MaxOutstandingUnexpectedPDUs", &uint64_val)) != ENOENT) {
        ASSERT(nvrc == 0);
        iser_conn->ic_op_params.op_max_outstanding_unexpected_pdus =
            uint64_val;
    }

    /* Test boolean values which are required by RFC 5046 */
#ifdef ISER_DEBUG
    ASSERT(iser_conn->ic_op_params.op_rdma_extensions == B_TRUE);
    ASSERT(iser_conn->ic_op_params.op_header_digest == B_FALSE);
    ASSERT(iser_conn->ic_op_params.op_data_digest == B_FALSE);
    ASSERT(iser_conn->ic_op_params.op_ofmarker == B_FALSE);
    ASSERT(iser_conn->ic_op_params.op_ifmarker == B_FALSE);
#endif
}