Ejemplo n.º 1
0
int
topo_fmri_nvl2str(topo_hdl_t *thp, nvlist_t *fmri, char **fmristr, int *err)
{
	char *scheme, *str;
	nvlist_t *out = NULL;
	tnode_t *rnode;

	if (nvlist_lookup_string(fmri, FM_FMRI_SCHEME, &scheme) != 0)
		return (set_error(thp, ETOPO_FMRI_MALFORM, err,
		    TOPO_METH_NVL2STR, out));

	if ((rnode = topo_hdl_root(thp, scheme)) == NULL)
		return (set_error(thp, ETOPO_METHOD_NOTSUP, err,
		    TOPO_METH_NVL2STR, out));

	if (topo_method_invoke(rnode, TOPO_METH_NVL2STR,
	    TOPO_METH_NVL2STR_VERSION, fmri, &out, err) != 0)
		return (set_error(thp, *err, err, TOPO_METH_NVL2STR, out));

	if (out == NULL || nvlist_lookup_string(out, "fmri-string", &str) != 0)
		return (set_error(thp, ETOPO_METHOD_INVAL, err,
		    TOPO_METH_NVL2STR, out));

	if ((*fmristr = topo_hdl_strdup(thp, str)) == NULL)
		return (set_error(thp, ETOPO_NOMEM, err,
		    TOPO_METH_NVL2STR, out));

	nvlist_free(out);

	return (0);
}
Ejemplo n.º 2
0
static int
hclist_contains(nvlist_t **erhcl, uint_t erhclsz, nvlist_t **eehcl,
    uint_t eehclsz)
{
	uint_t i;
	char *erval, *eeval;

	if (erhclsz > eehclsz || erhcl == NULL || eehcl == NULL)
		return (0);

	for (i = 0; i < erhclsz; i++) {
		(void) nvlist_lookup_string(erhcl[i], FM_FMRI_HC_NAME,
		    &erval);
		(void) nvlist_lookup_string(eehcl[i], FM_FMRI_HC_NAME,
		    &eeval);
		if (strcmp(erval, eeval) != 0)
			return (0);
		(void) nvlist_lookup_string(erhcl[i], FM_FMRI_HC_ID,
		    &erval);
		(void) nvlist_lookup_string(eehcl[i], FM_FMRI_HC_ID,
		    &eeval);
		if (strcmp(erval, eeval) != 0)
			return (0);
	}

	return (1);
}
Ejemplo n.º 3
0
int
topo_fmri_serial(topo_hdl_t *thp, nvlist_t *nvl, char **serial, int *err)
{
	nvlist_t *prop = NULL;
	char *sp;

	/*
	 * If there is a serial id in the resource fmri, then use that.
	 * Otherwise fall back to looking for a serial id property in the
	 * protocol group.
	 */
	if (nvlist_lookup_string(nvl, FM_FMRI_HC_SERIAL_ID, &sp) == 0) {
		if ((*serial = topo_hdl_strdup(thp, sp)) == NULL)
			return (set_error(thp, ETOPO_PROP_NOMEM, err,
			    "topo_fmri_serial", prop));
		else
			return (0);
	}

	if (fmri_prop(thp, nvl, TOPO_PGROUP_PROTOCOL, FM_FMRI_HC_SERIAL_ID,
	    NULL, &prop, err) < 0)
		return (set_error(thp, *err, err, "topo_fmri_serial", NULL));

	if (nvlist_lookup_string(prop, TOPO_PROP_VAL_VAL, &sp) != 0)
		return (set_error(thp, ETOPO_PROP_NVL, err, "topo_fmri_serial",
		    prop));

	if ((*serial = topo_hdl_strdup(thp, sp)) == NULL)
		return (set_error(thp, ETOPO_PROP_NOMEM, err,
		    "topo_fmri_serial", prop));

	nvlist_free(prop);

	return (0);
}
Ejemplo n.º 4
0
/*
 * Fetch the Facility Node properties (name, type) from the FMRI
 * for this node, or return -1 if we can't.
 */
static int
get_facility_props(topo_hdl_t *hdl, tnode_t *node, char **facname,
    char **factype)
{
	int e, ret = -1;
	nvlist_t *fmri = NULL, *fnvl;
	char *nn = NULL, *tt = NULL;

	if (topo_node_resource(node, &fmri, &e) != 0)
		goto out;

	if (nvlist_lookup_nvlist(fmri, FM_FMRI_FACILITY, &fnvl) != 0)
		goto out;

	if (nvlist_lookup_string(fnvl, FM_FMRI_FACILITY_NAME, &nn) != 0)
		goto out;

	if (nvlist_lookup_string(fnvl, FM_FMRI_FACILITY_TYPE, &tt) != 0)
		goto out;

	*facname = topo_hdl_strdup(hdl, nn);
	*factype = topo_hdl_strdup(hdl, tt);
	ret = 0;

out:
	nvlist_free(fmri);
	return (ret);
}
Ejemplo n.º 5
0
nvlist_t *
cmd_boardfru_create_fault(fmd_hdl_t *hdl, nvlist_t *asru, const char *fltnm,
    uint_t cert, char *loc)
{
	nvlist_t *flt, *nvlfru;
	char *serialstr, *partstr;

	if ((loc == NULL) || (strcmp(loc, EMPTY_STR) == 0))
		return (NULL);

	if (nvlist_lookup_string(asru, FM_FMRI_HC_SERIAL_ID, &serialstr) != 0)
		serialstr = NULL;
	if (nvlist_lookup_string(asru, FM_FMRI_HC_PART, &partstr) != 0)
		partstr = NULL;

	nvlfru = cmd_mkboard_fru(hdl, loc, serialstr, partstr);
	if (nvlfru == NULL)
		return (NULL);

	flt = cmd_nvl_create_fault(hdl, fltnm, cert, nvlfru, nvlfru, NULL);
	flt = cmd_fault_add_location(hdl, flt, loc);
	if (nvlfru != NULL)
		nvlist_free(nvlfru);
	return (flt);
}
Ejemplo n.º 6
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);
                }
            }
        }
    }
}
Ejemplo n.º 7
0
/*
 * Handle a EC_DEV_ADD.ESC_DISK event.
 *
 * illumos
 *	Expects: DEV_PHYS_PATH string in schema
 *	Matches: vdev's ZPOOL_CONFIG_PHYS_PATH or ZPOOL_CONFIG_DEVID
 *
 *      path: '/dev/dsk/c0t1d0s0' (persistent)
 *     devid: 'id1,sd@SATA_____Hitachi_HDS72101______JP2940HZ3H74MC/a'
 * phys_path: '/pci@0,0/pci103c,1609@11/disk@1,0:a'
 *
 * linux
 *	provides: DEV_PHYS_PATH and DEV_IDENTIFIER strings in schema
 *	Matches: vdev's ZPOOL_CONFIG_PHYS_PATH or ZPOOL_CONFIG_DEVID
 *
 *      path: '/dev/sdc1' (not persistent)
 *     devid: 'ata-SAMSUNG_HD204UI_S2HGJD2Z805891-part1'
 * phys_path: 'pci-0000:04:00.0-sas-0x4433221106000000-lun-0'
 */
static int
zfs_deliver_add(nvlist_t *nvl, boolean_t is_lofi)
{
	char *devpath = NULL, *devid;
	boolean_t is_slice;

	/*
	 * Expecting a devid string and an optional physical location
	 */
	if (nvlist_lookup_string(nvl, DEV_IDENTIFIER, &devid) != 0)
		return (-1);

	(void) nvlist_lookup_string(nvl, DEV_PHYS_PATH, &devpath);

	is_slice = (nvlist_lookup_boolean(nvl, DEV_IS_PART) == 0);

	zed_log_msg(LOG_INFO, "zfs_deliver_add: adding %s (%s) (is_slice %d)",
	    devid, devpath ? devpath : "NULL", is_slice);

	/*
	 * Iterate over all vdevs looking for a match in the folllowing order:
	 * 1. ZPOOL_CONFIG_DEVID (identifies the unique disk)
	 * 2. ZPOOL_CONFIG_PHYS_PATH (identifies disk physical location).
	 *
	 * For disks, we only want to pay attention to vdevs marked as whole
	 * disks or are a multipath device.
	 */
	if (!devid_iter(devid, zfs_process_add, is_slice) && devpath != NULL)
		(void) devphys_iter(devpath, devid, zfs_process_add, is_slice);

	return (0);
}
Ejemplo n.º 8
0
static int
auth_compare(nvlist_t *nvl1, nvlist_t *nvl2)
{
	const char *names[] = {
		FM_FMRI_AUTH_PRODUCT,
		FM_FMRI_AUTH_PRODUCT_SN,
		FM_FMRI_AUTH_CHASSIS,
		FM_FMRI_AUTH_SERVER,
		FM_FMRI_AUTH_DOMAIN,
		FM_FMRI_AUTH_HOST,
		NULL
	};
	const char **namep;
	nvlist_t *auth1 = NULL, *auth2 = NULL;

	(void) nvlist_lookup_nvlist(nvl1, FM_FMRI_AUTHORITY, &auth1);
	(void) nvlist_lookup_nvlist(nvl2, FM_FMRI_AUTHORITY, &auth2);
	if (auth1 == NULL && auth2 == NULL)
		return (0);
	if (auth1 == NULL || auth2 == NULL)
		return (1);

	for (namep = names; *namep != NULL; namep++) {
		char *val1 = NULL, *val2 = NULL;

		(void) nvlist_lookup_string(auth1, *namep, &val1);
		(void) nvlist_lookup_string(auth2, *namep, &val2);
		if (val1 == NULL && val2 == NULL)
			continue;
		if (val1 == NULL || val2 == NULL || strcmp(val1, val2) != 0)
			return (1);
	}

	return (0);
}
Ejemplo n.º 9
0
int
main(void)
{
	uint_t i;
	uint8_t buf[256];

	bzero(buf, sizeof (buf));
	for (i = 0; i < UINT8_MAX; i++) {
		int ret;
		nvlist_t *nvl;
		char *val;

		buf[SFF_8472_CONNECTOR] = i;
		if ((ret = libsff_parse(buf, sizeof (buf), 0xa0, &nvl)) != 0) {
			errx(1, "TEST FAILED: failed to parse SFP connector "
			    "%d: %s\n", i, strerror(ret));
		}

		if ((ret = nvlist_lookup_string(nvl, LIBSFF_KEY_CONNECTOR,
		    &val)) != 0) {
			errx(1, "TEST FAILED: failed to find key %s with "
			    "value %d: %s", LIBSFF_KEY_CONNECTOR, i,
			    strerror(ret));
		}

		(void) puts(val);
		nvlist_free(nvl);
	}

	/*
	 * Now for QSFP+
	 */
	(void) puts("\n\nQSFP\n");
	bzero(buf, sizeof (buf));
	buf[SFF_8472_IDENTIFIER] = SFF_8024_ID_QSFP;
	for (i = 0; i < UINT8_MAX; i++) {
		int ret;
		nvlist_t *nvl;
		char *val;

		buf[SFF_8636_CONNECTOR] = i;
		if ((ret = libsff_parse(buf, sizeof (buf), 0xa0, &nvl)) != 0) {
			errx(1, "TEST FAILED: failed to parse QSFP connector "
			    "%d: %s\n", i, strerror(errno));
		}

		if ((ret = nvlist_lookup_string(nvl, LIBSFF_KEY_CONNECTOR,
		    &val)) != 0) {
			errx(1, "TEST FAILED: failed to find key %s with "
			    "value %d: %s", LIBSFF_KEY_CONNECTOR, i,
			    strerror(ret));
		}

		(void) puts(val);
		nvlist_free(nvl);
	}

	return (0);
}
Ejemplo n.º 10
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);
}
Ejemplo n.º 11
0
/*
 * DR event handler
 * respond to the picl events:
 *      PICLEVENT_DR_AP_STATE_CHANGE
 */
static void
dr_handler(const char *ename, const void *earg, size_t size, void *cookie)
{
	nvlist_t	*nvlp = NULL;
	char		*dtype;
	char		*ap_id;
	char		*hint;


	if (strcmp(ename, PICLEVENT_DR_AP_STATE_CHANGE) != 0) {
		return;
	}

	if (nvlist_unpack((char *)earg, size, &nvlp, NULL)) {
		return;
	}

	if (nvlist_lookup_string(nvlp, PICLEVENTARG_DATA_TYPE, &dtype)) {
		nvlist_free(nvlp);
		return;
	}

	if (strcmp(dtype, PICLEVENTARG_PICLEVENT_DATA) != 0) {
		nvlist_free(nvlp);
		return;
	}

	if (nvlist_lookup_string(nvlp, PICLEVENTARG_AP_ID, &ap_id)) {
		nvlist_free(nvlp);
		return;
	}

	if (nvlist_lookup_string(nvlp, PICLEVENTARG_HINT, &hint)) {
		nvlist_free(nvlp);
		return;
	}

	mdp = mdesc_devinit();
	if (mdp == NULL) {
		nvlist_free(nvlp);
		return;
	}

	rootnode = md_root_node(mdp);

	if (strcmp(hint, DR_HINT_INSERT) == 0)
		(void) update_devices(ap_id, DEV_ADD);
	else if (strcmp(hint, DR_HINT_REMOVE) == 0)
		(void) update_devices(ap_id, DEV_REMOVE);

	mdesc_devfini(mdp);
	nvlist_free(nvlp);

	/*
	 * Signal the devtree plugin to add more cpu properties.
	 */
	signal_devtree();
}
Ejemplo n.º 12
0
static void
print_everstyle(tnode_t *node)
{
	char buf[PATH_MAX], numbuf[64];
	nvlist_t *fmri, **hcl;
	int i, err;
	uint_t n;

	if (topo_prop_get_fmri(node, TOPO_PGROUP_PROTOCOL,
	    TOPO_PROP_RESOURCE, &fmri, &err) < 0) {
		(void) fprintf(stderr, "%s: failed to get fmri for %s=%d: %s\n",
		    g_pname, topo_node_name(node),
		    topo_node_instance(node), topo_strerror(err));
		return;
	}

	if (nvlist_lookup_nvlist_array(fmri, FM_FMRI_HC_LIST, &hcl, &n) != 0) {
		(void) fprintf(stderr, "%s: failed to find %s for %s=%d\n",
		    g_pname, FM_FMRI_HC_LIST, topo_node_name(node),
		    topo_node_instance(node));
		nvlist_free(fmri);
		return;
	}

	buf[0] = '\0';

	for (i = 0; i < n; i++) {
		char *name, *inst, *estr;
		ulong_t ul;

		if (nvlist_lookup_string(hcl[i], FM_FMRI_HC_NAME, &name) != 0 ||
		    nvlist_lookup_string(hcl[i], FM_FMRI_HC_ID, &inst) != 0) {
			(void) fprintf(stderr, "%s: failed to get "
			    "name-instance for %s=%d\n", g_pname,
			    topo_node_name(node), topo_node_instance(node));
			nvlist_free(fmri);
			return;
		}

		errno = 0;
		ul = strtoul(inst, &estr, 10);

		if (errno != 0 || estr == inst) {
			(void) fprintf(stderr, "%s: instance %s does not "
			    "convert to an unsigned integer\n", g_pname, inst);
		}

		(void) strlcat(buf, "/", sizeof (buf));
		(void) strlcat(buf, name, sizeof (buf));
		(void) snprintf(numbuf, sizeof (numbuf), "%u", ul);
		(void) strlcat(buf, numbuf, sizeof (buf));
	}
	nvlist_free(fmri);

	(void) printf("%s\n", buf);
}
Ejemplo n.º 13
0
/*
 * This function is called when we receive a devfs add event.  This can be
 * either a disk event or a lofi event, and the behavior is slightly different
 * depending on which it is.
 */
static int
zfs_deliver_add(nvlist_t *nvl, boolean_t is_lofi)
{
	char *devpath, *devname;
	char path[PATH_MAX], realpath[PATH_MAX];
	char *colon, *raw;
	int ret;

	/*
	 * The main unit of operation is the physical device path.  For disks,
	 * this is the device node, as all minor nodes are affected.  For lofi
	 * devices, this includes the minor path.  Unfortunately, this isn't
	 * represented in the DEV_PHYS_PATH for various reasons.
	 */
	if (nvlist_lookup_string(nvl, DEV_PHYS_PATH, &devpath) != 0)
		return (-1);

	/*
	 * If this is a lofi device, then also get the minor instance name.
	 * Unfortunately, the current payload doesn't include an easy way to get
	 * this information.  So we cheat by resolving the 'dev_name' (which
	 * refers to the raw device) and taking the portion between ':(*),raw'.
	 */
	(void) strlcpy(realpath, devpath, sizeof (realpath));
	if (is_lofi) {
		if (nvlist_lookup_string(nvl, DEV_NAME,
		    &devname) == 0 &&
		    (ret = resolvepath(devname, path,
		    sizeof (path))) > 0) {
			path[ret] = '\0';
			colon = strchr(path, ':');
			if (colon != NULL)
				raw = strstr(colon + 1, ",raw");
			if (colon != NULL && raw != NULL) {
				*raw = '\0';
				(void) snprintf(realpath,
				    sizeof (realpath), "%s%s",
				    devpath, colon);
				*raw = ',';
			}
		}
	}

	/*
	 * Iterate over all vdevs with a matching devid, and then those with a
	 * matching /devices path.  For disks, we only want to pay attention to
	 * vdevs marked as whole disks.  For lofi, we don't care (because we're
	 * matching an exact minor name).
	 */
	if (!devid_iter(realpath, zfs_process_add, !is_lofi))
		(void) devpath_iter(realpath, zfs_process_add, !is_lofi);

	return (0);
}
Ejemplo n.º 14
0
static void
set_fstyp_properties (LibHalContext *ctx, const char *udi, const char *fstype, nvlist_t *fsattr)
{
	char buf[256];
	DBusError error;
	char *uuid = NULL;
	char *label_orig = NULL;
	char *label = NULL;
	int  err;
	LibHalChangeSet *cs;

	dbus_error_init (&error);

	if ((cs = libhal_device_new_changeset (udi)) == NULL) {
		return;
	}

	libhal_changeset_set_property_string (cs, "volume.fsusage", "filesystem");
	libhal_changeset_set_property_string (cs, "volume.fstype", fstype);

	/* label */
	(void) nvlist_lookup_string(fsattr, "gen_volume_label", &label_orig);
	if (label_orig != NULL) {
		label = rtrim_copy(label_orig, 0);
	}
	/* Check if label is utf8 format */
	if ((label != NULL) && (label[0] != '\0') &&
	    (u8_validate(label, strlen(label), (char **)NULL,
	    U8_VALIDATE_ENTIRE, &err) != -1)) {
	        libhal_changeset_set_property_string (cs, "volume.label", label);
	        libhal_changeset_set_property_string (cs, "info.product", label);
	} else {
		libhal_changeset_set_property_string (cs, "volume.label", "");
		snprintf (buf, sizeof (buf), "Volume (%s)", fstype);
		libhal_changeset_set_property_string (cs, "info.product", buf);
	}
	free(label);

	/* uuid */
	if (nvlist_lookup_string(fsattr, "gen_uuid", &uuid) == 0) {
		libhal_changeset_set_property_string (cs, "volume.uuid", uuid);
	} else {
		libhal_changeset_set_property_string (cs, "volume.uuid", "");
	}

	libhal_device_commit_changeset (ctx, cs, &error);
	libhal_device_free_changeset (cs);

	my_dbus_error_free (&error);
}
Ejemplo n.º 15
0
gmem_dimm_t *
gmem_dimm_create(fmd_hdl_t *hdl, nvlist_t *asru, nvlist_t *det)
{
	gmem_dimm_t *dimm;
	nvlist_t *fmri;
	char *serial;
	uint32_t chip_id;

	if (nvlist_lookup_string(asru, FM_FMRI_HC_SERIAL_ID, &serial) != 0) {
		fmd_hdl_debug(hdl, "Unable to get dimm serial\n");
		return (NULL);
	}

	if (nvlist_dup(asru, &fmri, 0) != 0) {
		fmd_hdl_debug(hdl, "dimm create nvlist dup failed");
		return (NULL);
	}

	(void) gmem_find_dimm_chip(det, &chip_id);

	fmd_hdl_debug(hdl, "dimm_create: creating new DIMM serial=%s\n",
	    serial);
	GMEM_STAT_BUMP(dimm_creat);

	dimm = fmd_hdl_zalloc(hdl, sizeof (gmem_dimm_t), FMD_SLEEP);
	dimm->dimm_nodetype = GMEM_NT_DIMM;
	dimm->dimm_version = GMEM_DIMM_VERSION;
	dimm->dimm_phys_addr_low = ULLONG_MAX;
	dimm->dimm_phys_addr_hi = 0;
	dimm->dimm_syl_error = USHRT_MAX;
	dimm->dimm_chipid = chip_id;

	gmem_bufname(dimm->dimm_bufname, sizeof (dimm->dimm_bufname), "dimm_%s",
	    serial);
	gmem_fmri_init(hdl, &dimm->dimm_asru, fmri, "dimm_asru_%s", serial);

	nvlist_free(fmri);

	(void) nvlist_lookup_string(dimm->dimm_asru_nvl, FM_FMRI_HC_SERIAL_ID,
	    (char **)&dimm->dimm_serial);

	gmem_mem_retirestat_create(hdl, &dimm->dimm_retstat, dimm->dimm_serial,
	    0, GMEM_DIMM_STAT_PREFIX);

	gmem_list_append(&gmem.gm_dimms, dimm);
	gmem_dimm_dirty(hdl, dimm);

	return (dimm);
}
Ejemplo n.º 16
0
char *
fnvlist_lookup_string(nvlist_t *nvl, const char *name)
{
	char *rv;
	VERIFY0(nvlist_lookup_string(nvl, name, &rv));
	return (rv);
}
Ejemplo n.º 17
0
/*
 * Look up the diagcode for this case and cache it in ci_code.  If no suspects
 * were defined for this case or if the lookup fails, the event dictionary or
 * module code is broken, and we set the event code to a precomputed default.
 */
static const char *
fmd_case_mkcode(fmd_case_t *cp)
{
	fmd_case_impl_t *cip = (fmd_case_impl_t *)cp;
	fmd_case_susp_t *cis;

	char **keys, **keyp;
	const char *s;

	ASSERT(MUTEX_HELD(&cip->ci_lock));
	ASSERT(cip->ci_state >= FMD_CASE_SOLVED);

	fmd_free(cip->ci_code, cip->ci_codelen);
	cip->ci_codelen = cip->ci_mod->mod_codelen;
	cip->ci_code = fmd_zalloc(cip->ci_codelen, FMD_SLEEP);
	keys = keyp = alloca(sizeof (char *) * (cip->ci_nsuspects + 1));

	for (cis = cip->ci_suspects; cis != NULL; cis = cis->cis_next) {
		if (nvlist_lookup_string(cis->cis_nvl, FM_CLASS, keyp) == 0)
			keyp++;
	}

	*keyp = NULL; /* mark end of keys[] array for libdiagcode */

	if (cip->ci_nsuspects == 0 || fmd_module_dc_key2code(
	    cip->ci_mod, keys, cip->ci_code, cip->ci_codelen) != 0) {
		(void) fmd_conf_getprop(fmd.d_conf, "nodiagcode", &s);
		fmd_free(cip->ci_code, cip->ci_codelen);
		cip->ci_codelen = strlen(s) + 1;
		cip->ci_code = fmd_zalloc(cip->ci_codelen, FMD_SLEEP);
		(void) strcpy(cip->ci_code, s);
	}

	return (cip->ci_code);
}
Ejemplo n.º 18
0
/*
 * If an asru has a unum string that is an hc path string then return
 * a new nvl (to be freed by the caller) that is a duplicate of the
 * original but with an additional member of a reconstituted hc fmri.
 */
int
mem_unum_rewrite(nvlist_t *nvl, nvlist_t **rnvl)
{
	int err;
	char *unumstr;
	nvlist_t *unum;
	struct topo_hdl *thp;

	if (nvlist_lookup_string(nvl, FM_FMRI_MEM_UNUM, &unumstr) != 0 ||
	    !ISHCUNUM(unumstr))
		return (0);

	if ((thp = fmd_fmri_topo_hold(TOPO_VERSION)) == NULL)
		return (EINVAL);

	if (topo_fmri_str2nvl(thp, unumstr, &unum, &err) != 0) {
		fmd_fmri_topo_rele(thp);
		return (EINVAL);
	}

	fmd_fmri_topo_rele(thp);

	if ((err = nvlist_dup(nvl, rnvl, 0)) != 0) {
		nvlist_free(unum);
		return (err);
	}

	err = nvlist_add_nvlist(*rnvl, FM_FMRI_MEM_UNUM "-fmri", unum);
	nvlist_free(unum);

	if (err != 0)
		nvlist_free(*rnvl);

	return (err);
}
Ejemplo n.º 19
0
int
zfs_deliver_dle(nvlist_t *nvl)
{
	char *devname;
	if (nvlist_lookup_string(nvl, DEV_PHYS_PATH, &devname) != 0) {
		syseventd_print(9, "zfs_deliver_event: no physpath\n");
		return (-1);
	}
	if (strncmp(devname, DEVICE_PREFIX, strlen(DEVICE_PREFIX)) != 0) {
		syseventd_print(9, "zfs_deliver_event: invalid "
		    "device '%s'", devname);
		return (-1);
	}

	/*
	 * We try to find the device using the physical
	 * path that has been supplied. We need to strip off
	 * the /devices prefix before starting our search.
	 */
	devname += strlen(DEVICE_PREFIX);
	if (zpool_iter(g_zfshdl, zfsdle_vdev_online, devname) != 1) {
		syseventd_print(9, "zfs_deliver_event: device '%s' not"
		    " found\n", devname);
		return (1);
	}
	return (0);
}
Ejemplo n.º 20
0
static boolean_t
proplist_has_encryption_props(nvlist_t *props)
{
	int ret;
	uint64_t intval;
	char *strval;

	ret = nvlist_lookup_uint64(props,
	    zfs_prop_to_name(ZFS_PROP_ENCRYPTION), &intval);
	if (ret == 0 && intval != ZIO_CRYPT_OFF)
		return (B_TRUE);

	ret = nvlist_lookup_string(props,
	    zfs_prop_to_name(ZFS_PROP_KEYLOCATION), &strval);
	if (ret == 0 && strcmp(strval, "none") != 0)
		return (B_TRUE);

	ret = nvlist_lookup_uint64(props,
	    zfs_prop_to_name(ZFS_PROP_KEYFORMAT), &intval);
	if (ret == 0)
		return (B_TRUE);

	ret = nvlist_lookup_uint64(props,
	    zfs_prop_to_name(ZFS_PROP_PBKDF2_ITERS), &intval);
	if (ret == 0)
		return (B_TRUE);

	return (B_FALSE);
}
Ejemplo n.º 21
0
int
fstyp_zfs(FILE *fp, char *label, size_t labelsize)
{
	vdev_label_t *vdev_label = NULL;
	vdev_phys_t *vdev_phys;
	char *zpool_name = NULL;
	nvlist_t *config = NULL;
	int err = 0;

	/*
	 * Read in the first ZFS vdev label ("L0"), located at the beginning
	 * of the vdev and extract the pool name from it.
	 *
	 * TODO: the checksum of label should be validated.
	 */
	vdev_label = (vdev_label_t *)read_buf(fp, 0, sizeof(*vdev_label));
	if (vdev_label == NULL)
		return (1);

	vdev_phys = &(vdev_label->vl_vdev_phys);

	if ((nvlist_unpack(vdev_phys->vp_nvlist, sizeof(vdev_phys->vp_nvlist),
	    &config, 0)) == 0 &&
	    (nvlist_lookup_string(config, "name", &zpool_name) == 0)) {
		strlcpy(label, zpool_name, labelsize);
	} else
		err = 1;

	nvlist_free(config);
	free(vdev_label);

	return (err);
}
Ejemplo n.º 22
0
/*
 * Function:	be_activate
 * Description:	Calls _be_activate which activates the BE named in the
 *		attributes passed in through be_attrs. The process of
 *		activation sets the bootfs property of the root pool, resets
 *		the canmount property to noauto, and sets the default in the
 *		grub menu to the entry corresponding to the entry for the named
 *		BE.
 * Parameters:
 *		be_attrs - pointer to nvlist_t of attributes being passed in.
 *			The follow attribute values are used by this function:
 *
 *			BE_ATTR_ORIG_BE_NAME		*required
 * Return:
 *		BE_SUCCESS - Success
 *		be_errno_t - Failure
 * Scope:
 *		Public
 */
int
be_activate(nvlist_t *be_attrs)
{
	int	ret = BE_SUCCESS;
	char	*be_name = NULL;

	/* Initialize libzfs handle */
	if (!be_zfs_init())
		return (BE_ERR_INIT);

	/* Get the BE name to activate */
	if (nvlist_lookup_string(be_attrs, BE_ATTR_ORIG_BE_NAME, &be_name)
	    != 0) {
		be_print_err(gettext("be_activate: failed to "
		    "lookup BE_ATTR_ORIG_BE_NAME attribute\n"));
		be_zfs_fini();
		return (BE_ERR_INVAL);
	}

	/* Validate BE name */
	if (!be_valid_be_name(be_name)) {
		be_print_err(gettext("be_activate: invalid BE name %s\n"),
		    be_name);
		be_zfs_fini();
		return (BE_ERR_INVAL);
	}

	ret = _be_activate(be_name);

	be_zfs_fini();

	return (ret);
}
Ejemplo n.º 23
0
/*
 * 'avail_spare' is set to TRUE if the provided guid refers to an AVAIL
 * spare; but FALSE if its an INUSE spare.
 */
static nvlist_t *
vdev_to_nvlist_iter(nvlist_t *nv, const char *search, uint64_t guid,
    boolean_t *avail_spare)
{
	uint_t c, children;
	nvlist_t **child;
	uint64_t theguid, present;
	char *path;
	uint64_t wholedisk = 0;
	nvlist_t *ret;

	verify(nvlist_lookup_uint64(nv, ZPOOL_CONFIG_GUID, &theguid) == 0);

	if (search == NULL &&
	    nvlist_lookup_uint64(nv, ZPOOL_CONFIG_NOT_PRESENT, &present) == 0) {
		/*
		 * If the device has never been present since import, the only
		 * reliable way to match the vdev is by GUID.
		 */
		if (theguid == guid)
			return (nv);
	} else if (search != NULL &&
	    nvlist_lookup_string(nv, ZPOOL_CONFIG_PATH, &path) == 0) {
		(void) nvlist_lookup_uint64(nv, ZPOOL_CONFIG_WHOLE_DISK,
		    &wholedisk);
		if (wholedisk) {
			/*
			 * For whole disks, the internal path has 's0', but the
			 * path passed in by the user doesn't.
			 */
			if (strlen(search) == strlen(path) - 2 &&
			    strncmp(search, path, strlen(search)) == 0)
				return (nv);
		} else if (strcmp(search, path) == 0) {
			return (nv);
		}
	}

	if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_CHILDREN,
	    &child, &children) != 0)
		return (NULL);

	for (c = 0; c < children; c++)
		if ((ret = vdev_to_nvlist_iter(child[c], search, guid,
		    avail_spare)) != NULL)
			return (ret);

	if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_SPARES,
	    &child, &children) == 0) {
		for (c = 0; c < children; c++) {
			if ((ret = vdev_to_nvlist_iter(child[c], search, guid,
			    avail_spare)) != NULL) {
				*avail_spare = B_TRUE;
				return (ret);
			}
		}
	}

	return (NULL);
}
Ejemplo n.º 24
0
int
topo_fmri_unretire(topo_hdl_t *thp, nvlist_t *fmri, int *err)
{
	char *scheme;
	uint32_t status;
	nvlist_t *out = NULL;
	tnode_t *rnode;

	if (nvlist_lookup_string(fmri, FM_FMRI_SCHEME, &scheme) != 0)
		return (set_error(thp, ETOPO_FMRI_MALFORM, err,
		    TOPO_METH_UNRETIRE, out));

	if ((rnode = topo_hdl_root(thp, scheme)) == NULL)
		return (set_error(thp, ETOPO_METHOD_NOTSUP, err,
		    TOPO_METH_UNRETIRE, out));

	if (topo_method_invoke(rnode, TOPO_METH_UNRETIRE,
	    TOPO_METH_UNRETIRE_VERSION, fmri, &out, err) < 0)
		return (set_error(thp, *err, err, TOPO_METH_UNRETIRE, out));

	if (nvlist_lookup_uint32(out, TOPO_METH_UNRETIRE_RET, &status) != 0) {
		nvlist_free(out);
		return (set_error(thp, ETOPO_METHOD_FAIL, err,
		    TOPO_METH_UNRETIRE, out));
	}
	nvlist_free(out);

	return (status);
}
Ejemplo n.º 25
0
char *
fmdump_nvl2str(nvlist_t *nvl)
{
	fmd_scheme_t *sp;
	char c, *name, *s = NULL;
	ssize_t len;

	if (nvlist_lookup_string(nvl, FM_FMRI_SCHEME, &name) != 0) {
		fmdump_warn("fmri does not contain required '%s' nvpair\n",
		    FM_FMRI_SCHEME);
		return (NULL);
	}

	if ((sp = fmd_scheme_lookup("/usr/lib/fm/fmd/schemes", name)) == NULL ||
	    sp->sch_dlp == NULL || sp->sch_err != 0) {
		const char *msg =
		    sp->sch_err == ELIBACC ? dlerror() : strerror(sp->sch_err);

		fmdump_warn("cannot init '%s' scheme library to "
		    "format fmri: %s\n", name, msg ? msg : "unknown error");

		return (NULL);
	}

	if ((len = sp->sch_ops.sop_nvl2str(nvl, &c, sizeof (c))) == -1 ||
	    (s = malloc(len + 1)) == NULL ||
	    sp->sch_ops.sop_nvl2str(nvl, s, len + 1) == -1) {
		fmdump_warn("cannot format fmri using scheme '%s'", name);
		free(s);
		return (NULL);
	}

	return (s);
}
Ejemplo n.º 26
0
int
topo_fmri_service_state(topo_hdl_t *thp, nvlist_t *fmri, int *err)
{
	char *scheme;
	uint32_t service_state = FMD_SERVICE_STATE_UNKNOWN;
	nvlist_t *out = NULL;
	tnode_t *rnode;

	if (nvlist_lookup_string(fmri, FM_FMRI_SCHEME, &scheme) != 0)
		return (set_error(thp, ETOPO_FMRI_MALFORM, err,
		    TOPO_METH_SERVICE_STATE, out));

	if ((rnode = topo_hdl_root(thp, scheme)) == NULL)
		return (set_error(thp, ETOPO_METHOD_NOTSUP, err,
		    TOPO_METH_SERVICE_STATE, out));

	if (topo_method_invoke(rnode, TOPO_METH_SERVICE_STATE,
	    TOPO_METH_SERVICE_STATE_VERSION, fmri, &out, err) < 0)
		return (set_error(thp, *err, err, TOPO_METH_SERVICE_STATE,
		    out));

	(void) nvlist_lookup_uint32(out, TOPO_METH_SERVICE_STATE_RET,
	    &service_state);
	nvlist_free(out);

	return (service_state);
}
Ejemplo n.º 27
0
cmd_branch_t *
cmd_branch_create(fmd_hdl_t *hdl, nvlist_t *asru)
{
	cmd_branch_t *branch;
	const char *b_unum;

	if ((b_unum = cmd_fmri_get_unum(asru)) == NULL) {
		CMD_STAT_BUMP(bad_mem_asru);
		return (NULL);
	}

	fmd_hdl_debug(hdl, "branch_create: creating new branch %s\n", b_unum);
	CMD_STAT_BUMP(branch_creat);

	branch = fmd_hdl_zalloc(hdl, sizeof (cmd_branch_t), FMD_SLEEP);
	branch->branch_nodetype = CMD_NT_BRANCH;
	branch->branch_version = CMD_BRANCH_VERSION;

	cmd_bufname(branch->branch_bufname, sizeof (branch->branch_bufname),
	    "branch_%s", b_unum);
	cmd_fmri_init(hdl, &branch->branch_asru, asru, "branch_asru_%s",
	    b_unum);

	(void) nvlist_lookup_string(branch->branch_asru_nvl, FM_FMRI_MEM_UNUM,
	    (char **)&branch->branch_unum);

	cmd_list_append(&cmd.cmd_branches, branch);
	cmd_branch_dirty(hdl, branch);

	return (branch);
}
Ejemplo n.º 28
0
/*
 * Locate a jail based on an arbitrary identifier.  This may be either a name,
 * a jid, or a BE name.  Returns the jid or -1 on failure.
 */
static int
bectl_locate_jail(const char *ident)
{
	nvlist_t *belist, *props;
	char *mnt;
	int jid;

	/* Try the easy-match first */
	jid = jail_getid(ident);
	if (jid != -1)
		return (jid);

	/* Attempt to try it as a BE name, first */
	if (be_prop_list_alloc(&belist) != 0)
		return (-1);

	if (be_get_bootenv_props(be, belist) != 0)
		return (-1);

	if (nvlist_lookup_nvlist(belist, ident, &props) == 0) {

		/* path where a boot environment is mounted */
		if (nvlist_lookup_string(props, "mounted", &mnt) == 0) {

			/* looking for a jail that matches our bootenv path */
			jid = bectl_search_jail_paths(mnt);
			be_prop_list_free(belist);
			return (jid);
		}

		be_prop_list_free(belist);
	}

	return (-1);
}
Ejemplo n.º 29
0
static int
name_or_guid_exists(zpool_handle_t *zhp, void *data)
{
	importargs_t *import = data;
	int found = 0;

	if (import->poolname != NULL) {
		char *pool_name;

		verify(nvlist_lookup_string(zhp->zpool_config,
		    ZPOOL_CONFIG_POOL_NAME, &pool_name) == 0);
		if (strcmp(pool_name, import->poolname) == 0)
			found = 1;
	} else {
		uint64_t pool_guid;

		verify(nvlist_lookup_uint64(zhp->zpool_config,
		    ZPOOL_CONFIG_POOL_GUID, &pool_guid) == 0);
		if (pool_guid == import->guid)
			found = 1;
	}

	zpool_close(zhp);
	return (found);
}
Ejemplo n.º 30
0
/*ARGSUSED*/
static void
event_handler(void *cookie, char *argp, size_t asize,
    door_desc_t *dp, uint_t n_desc)
{
	door_cred_t		cred;
	nvlist_t		*nvlp;
	char			*dtype;

	if (piclevent_debug)
		syslog(LOG_INFO,
		    "piclevent: got SLM event cookie:%p evarg:%p size:0x%x\n",
		    cookie, argp, asize);
	if ((door_id < 0) || (argp == NULL) || (door_cred(&cred) < 0) ||
	    (cred.dc_euid != 0))
		(void) door_return(argp, 0, NULL, 0);

	if (nvlist_unpack(argp, asize, &nvlp, NULL))
		(void) door_return(argp, 0, NULL, 0);

	if (nvlist_lookup_string(nvlp, PICLEVENTARG_DATA_TYPE, &dtype)) {
		nvlist_free(nvlp);
		(void) door_return(argp, 0, NULL, 0);
	}

	if (strcmp(dtype, PICLEVENTARG_PICLEVENT_DATA) == 0)
		parse_piclevent(nvlp);
	/*
	 * ignore other event data types
	 */
	nvlist_free(nvlp);
	(void) door_return(argp, 0, NULL, 0);
}