示例#1
0
/*
 * Dump content of nvlist.
 */
static void
nvlist_xdump(const nvlist_t *nvl, int fd, int level)
{
	nvpair_t *nvp;

	PJDLOG_ASSERT(level < 3);

	if (nvlist_error(nvl) != 0) {
		dprintf(fd, "%*serror: %d\n", level * 4, "",
		    nvlist_error(nvl));
		return;
	}

	for (nvp = nvlist_first_nvpair(nvl); nvp != NULL;
	    nvp = nvlist_next_nvpair(nvl, nvp)) {
		dprintf(fd, "%*s%s (%s):", level * 4, "", nvpair_name(nvp),
		    nvpair_type_string(nvpair_type(nvp)));
		switch (nvpair_type(nvp)) {
		case NV_TYPE_NULL:
			dprintf(fd, " null\n");
			break;
		case NV_TYPE_BOOL:
			dprintf(fd, " %s\n", nvpair_get_bool(nvp) ?
			    "TRUE" : "FALSE");
			break;
		case NV_TYPE_NUMBER:
			dprintf(fd, " %ju (%jd) (0x%jx)\n",
			    (uintmax_t)nvpair_get_number(nvp),
			    (intmax_t)nvpair_get_number(nvp),
			    (uintmax_t)nvpair_get_number(nvp));
			break;
		case NV_TYPE_STRING:
			dprintf(fd, " [%s]\n", nvpair_get_string(nvp));
			break;
		case NV_TYPE_NVLIST:
			dprintf(fd, "\n");
			nvlist_xdump(nvpair_get_nvlist(nvp), fd, level + 1);
			break;
		case NV_TYPE_DESCRIPTOR:
			dprintf(fd, " %d\n", nvpair_get_descriptor(nvp));
			break;
		case NV_TYPE_BINARY:
		    {
			const unsigned char *binary;
			unsigned int ii;
			size_t size;

			binary = nvpair_get_binary(nvp, &size);
			dprintf(fd, " %zu ", size);
			for (ii = 0; ii < size; ii++)
				dprintf(fd, "%02hhx", binary[ii]);
			dprintf(fd, "\n");
			break;
		    }
		default:
			PJDLOG_ABORT("Unknown type: %d.", nvpair_type(nvp));
		}
	}
}
示例#2
0
static boolean_t
nvlist_equal(nvlist_t *nvla, nvlist_t *nvlb)
{
	if (fnvlist_num_pairs(nvla) != fnvlist_num_pairs(nvlb))
		return (B_FALSE);
	/*
	 * The nvlists have the same number of pairs and keys are unique, so
	 * if every key in A is also in B and assigned to the same value, the
	 * lists are identical.
	 */
	for (nvpair_t *pair = nvlist_next_nvpair(nvla, NULL);
	    pair != NULL; pair = nvlist_next_nvpair(nvla, pair)) {
		char *key = nvpair_name(pair);

		if (!nvlist_exists(nvlb, key))
			return (B_FALSE);

		if (nvpair_type(pair) !=
		    nvpair_type(fnvlist_lookup_nvpair(nvlb, key)))
			return (B_FALSE);

		switch (nvpair_type(pair)) {
		case DATA_TYPE_BOOLEAN_VALUE:
			if (fnvpair_value_boolean_value(pair) !=
			    fnvlist_lookup_boolean_value(nvlb, key)) {
				return (B_FALSE);
			}
			break;
		case DATA_TYPE_STRING:
			if (strcmp(fnvpair_value_string(pair),
			    fnvlist_lookup_string(nvlb, key))) {
				return (B_FALSE);
			}
			break;
		case DATA_TYPE_INT64:
			if (fnvpair_value_int64(pair) !=
			    fnvlist_lookup_int64(nvlb, key)) {
				return (B_FALSE);
			}
			break;
		case DATA_TYPE_NVLIST:
			if (!nvlist_equal(fnvpair_value_nvlist(pair),
			    fnvlist_lookup_nvlist(nvlb, key))) {
				return (B_FALSE);
			}
			break;
		default:
			(void) printf("Unexpected type for nvlist_equal\n");
			return (B_FALSE);
		}
	}
	return (B_TRUE);
}
示例#3
0
文件: nvpair.c 项目: 2asoft/freebsd
void
nvpair_remove(struct nvl_head *head, nvpair_t *nvp, const nvlist_t *nvl)
{

	NVPAIR_ASSERT(nvp);
	PJDLOG_ASSERT(nvp->nvp_list == nvl);

	if (nvpair_type(nvp) == NV_TYPE_NVLIST)
		nvpair_remove_nvlist(nvp);
	else if (nvpair_type(nvp) == NV_TYPE_NVLIST_ARRAY)
		nvpair_remove_nvlist_array(nvp);

	TAILQ_REMOVE(head, nvp, nvp_next);
	nvp->nvp_list = NULL;
}
示例#4
0
void
setupInterfaces()
{
    char *json;
    nvlist_t *data, *nvl;
    nvpair_t *pair;

    if ((json = mdataGet("sdc:nics")) == NULL) {
        dlog("WARN no NICs found in sdc:nics\n");
        return;
    }

    if (nvlist_parse_json(json, strlen(json), &nvl, NVJSON_FORCE_INTEGER,
      NULL) != 0) {
        fatal(ERR_PARSE_JSON, "failed to parse nvpair json"
            " for sdc:nics: %s\n", strerror(errno));
    }
    free(json);

    for (pair = nvlist_next_nvpair(nvl, NULL); pair != NULL;
      pair = nvlist_next_nvpair(nvl, pair)) {
        if (nvpair_type(pair) == DATA_TYPE_NVLIST) {
            if (nvpair_value_nvlist(pair, &data) != 0) {
                fatal(ERR_PARSE_JSON, "failed to parse nvpair json"
                    " for NIC: %s\n", strerror(errno));
            }
            setupInterface(data);
        }
    }

    nvlist_free(nvl);
}
示例#5
0
static void
mountNfsVolumes()
{
    char *json;
    nvlist_t *data, *nvl;
    nvpair_t *pair;

    if ((json = mdataGet("docker:nfsvolumes")) == NULL) {
        dlog("No docker:nfsvolumes, nothing to mount\n");
        return;
    }

    if (nvlist_parse_json(json, strlen(json), &nvl, NVJSON_FORCE_INTEGER,
      NULL) != 0) {
        fatal(ERR_PARSE_JSON, "failed to parse nvpair json"
            " for docker:nfsvolumes: %s\n", strerror(errno));
    }
    free(json);

    for (pair = nvlist_next_nvpair(nvl, NULL); pair != NULL;
      pair = nvlist_next_nvpair(nvl, pair)) {
        if (nvpair_type(pair) == DATA_TYPE_NVLIST) {
            if (nvpair_value_nvlist(pair, &data) != 0) {
                fatal(ERR_PARSE_JSON, "failed to parse nvpair json"
                    " for NFS volume: %s\n", strerror(errno));
            }
            mountNfsVolume(data);
        }
    }

    nvlist_free(nvl);
}
示例#6
0
文件: zed_event.c 项目: Ramzec/zfs
static int
_zed_event_add_uint64_array(uint64_t eid, zed_strings_t *zsp,
    const char *prefix, nvpair_t *nvp)
{
	char buf[MAXBUF];
	int buflen = sizeof (buf);
	const char *name;
	const char *fmt;
	uint64_t *u64p;
	uint_t nelem;
	uint_t i;
	char *p;
	int n;

	assert((nvp != NULL) && (nvpair_type(nvp) == DATA_TYPE_UINT64_ARRAY));

	name = nvpair_name(nvp);
	fmt = _zed_event_value_is_hex(name) ? "0x%.16llX " : "%llu ";
	(void) nvpair_value_uint64_array(nvp, &u64p, &nelem);
	for (i = 0, p = buf; (i < nelem) && (buflen > 0); i++) {
		n = snprintf(p, buflen, fmt, (u_longlong_t) u64p[i]);
		if ((n < 0) || (n >= buflen))
			return (_zed_event_add_array_err(eid, name));
		p += n;
		buflen -= n;
	}
	if (nelem > 0)
		*--p = '\0';

	return (_zed_event_add_var(eid, zsp, prefix, name, "%s", buf));
}
示例#7
0
static size_t
nvlist_xndescriptors(const nvlist_t *nvl, int level)
{
	const nvpair_t *nvp;
	size_t ndescs;

	NVLIST_ASSERT(nvl);
	PJDLOG_ASSERT(nvl->nvl_error == 0);
	PJDLOG_ASSERT(level < 3);

	ndescs = 0;
	for (nvp = nvlist_first_nvpair(nvl); nvp != NULL;
	    nvp = nvlist_next_nvpair(nvl, nvp)) {
		switch (nvpair_type(nvp)) {
		case NV_TYPE_DESCRIPTOR:
			ndescs++;
			break;
		case NV_TYPE_NVLIST:
			ndescs += nvlist_xndescriptors(nvpair_get_nvlist(nvp),
			    level + 1);
			break;
		}
	}

	return (ndescs);
}
示例#8
0
static int *
nvlist_xdescriptors(const nvlist_t *nvl, int *descs, int level)
{
	const nvpair_t *nvp;

	NVLIST_ASSERT(nvl);
	PJDLOG_ASSERT(nvl->nvl_error == 0);
	PJDLOG_ASSERT(level < 3);

	for (nvp = nvlist_first_nvpair(nvl); nvp != NULL;
	    nvp = nvlist_next_nvpair(nvl, nvp)) {
		switch (nvpair_type(nvp)) {
		case NV_TYPE_DESCRIPTOR:
			*descs = nvpair_get_descriptor(nvp);
			descs++;
			break;
		case NV_TYPE_NVLIST:
			descs = nvlist_xdescriptors(nvpair_get_nvlist(nvp),
			    descs, level + 1);
			break;
		}
	}

	return (descs);
}
示例#9
0
static nvpair_t *
nvlist_findv(const nvlist_t *nvl, int type, const char *namefmt, va_list nameap)
{
	nvpair_t *nvp;
	char *name;

	NVLIST_ASSERT(nvl);
	PJDLOG_ASSERT(nvl->nvl_error == 0);
	PJDLOG_ASSERT(type == NV_TYPE_NONE ||
	    (type >= NV_TYPE_FIRST && type <= NV_TYPE_LAST));

	if (vasprintf(&name, namefmt, nameap) < 0)
		return (NULL);

	for (nvp = nvlist_first_nvpair(nvl); nvp != NULL;
	    nvp = nvlist_next_nvpair(nvl, nvp)) {
		if (type != NV_TYPE_NONE && nvpair_type(nvp) != type)
			continue;
		if ((nvl->nvl_flags & NV_FLAG_IGNORE_CASE) != 0) {
			if (strcasecmp(nvpair_name(nvp), name) != 0)
				continue;
		} else {
			if (strcmp(nvpair_name(nvp), name) != 0)
				continue;
		}
		break;
	}

	free(name);

	if (nvp == NULL)
		errno = ENOENT;

	return (nvp);
}
示例#10
0
文件: zed_event.c 项目: Ramzec/zfs
static int
_zed_event_add_string_array(uint64_t eid, zed_strings_t *zsp,
    const char *prefix, nvpair_t *nvp)
{
	char buf[MAXBUF];
	int buflen = sizeof (buf);
	const char *name;
	char **strp;
	uint_t nelem;
	uint_t i;
	char *p;
	int n;

	assert((nvp != NULL) && (nvpair_type(nvp) == DATA_TYPE_STRING_ARRAY));

	name = nvpair_name(nvp);
	(void) nvpair_value_string_array(nvp, &strp, &nelem);
	for (i = 0, p = buf; (i < nelem) && (buflen > 0); i++) {
		n = snprintf(p, buflen, "%s ", strp[i] ? strp[i] : "<NULL>");
		if ((n < 0) || (n >= buflen))
			return (_zed_event_add_array_err(eid, name));
		p += n;
		buflen -= n;
	}
	if (nelem > 0)
		*--p = '\0';

	return (_zed_event_add_var(eid, zsp, prefix, name, "%s", buf));
}
示例#11
0
void nvl_convert(nvlist_t *nvl, const struct convert_info *table)
{
	int ret;
	int i;

	/*
	 * If we weren't given a table, we have nothing to do other than the
	 * generic conversion (see above)
	 */
	if (!table)
		return;

	for (i = 0; table[i].name; i++) {
		nvpair_t *pair;

		ret = nvlist_lookup_nvpair(nvl, table[i].name, &pair);
		if (ret)
			continue;

		switch (nvpair_type(pair)) {
			case DATA_TYPE_STRING:
				cvt_string(nvl, pair, table[i].type);
				break;
			default:
				break;
		}
	}
}
示例#12
0
static nvpair_t *
nvlist_find(const nvlist_t *nvl, int type, const char *name)
{
	nvpair_t *nvp;

	NVLIST_ASSERT(nvl);
	PJDLOG_ASSERT(nvl->nvl_error == 0);
	PJDLOG_ASSERT(type == NV_TYPE_NONE ||
	    (type >= NV_TYPE_FIRST && type <= NV_TYPE_LAST));

	for (nvp = nvlist_first_nvpair(nvl); nvp != NULL;
	    nvp = nvlist_next_nvpair(nvl, nvp)) {
		if (type != NV_TYPE_NONE && nvpair_type(nvp) != type)
			continue;
		if ((nvl->nvl_flags & NV_FLAG_IGNORE_CASE) != 0) {
			if (strcasecmp(nvpair_name(nvp), name) != 0)
				continue;
		} else {
			if (strcmp(nvpair_name(nvp), name) != 0)
				continue;
		}
		break;
	}

	if (nvp == NULL)
		ERRNO_SET(ENOENT);

	return (nvp);
}
示例#13
0
/*
 * Given an nvlist of properties and an array of property handlers, invoke the
 * appropriate handler for all supported properties.
 */
int
ses2_setprop(ses_plugin_t *sp, ses_node_t *np,
             const ses2_ctl_prop_t *ctlprops, nvlist_t *props)
{
    const ses2_ctl_prop_t *cpp;
    nvpair_t *nvp, *next;

    for (nvp = nvlist_next_nvpair(props, NULL); nvp != NULL;
            nvp = next) {
        next = nvlist_next_nvpair(props, nvp);
        for (cpp = ctlprops; cpp->scp_name != NULL; cpp++)
            if (strcmp(cpp->scp_name, nvpair_name(nvp)) == 0)
                break;
        if (cpp->scp_name == NULL)
            continue;

        if (cpp->scp_setprop(sp, np, cpp->scp_num, nvp) != 0)
            return (-1);

        (void) nvlist_remove(props, nvpair_name(nvp),
                             nvpair_type(nvp));
    }

    return (0);
}
示例#14
0
static void
print_fmri_pgroup(topo_hdl_t *thp, const char *pgn, nvlist_t *nvl)
{
	char *dstab = NULL, *nstab = NULL;
	int32_t version = -1;
	nvlist_t *pnvl;
	nvpair_t *pnvp;

	(void) nvlist_lookup_string(nvl, TOPO_PROP_GROUP_NSTAB, &nstab);
	(void) nvlist_lookup_string(nvl, TOPO_PROP_GROUP_DSTAB, &dstab);
	(void) nvlist_lookup_int32(nvl, TOPO_PROP_GROUP_VERSION, &version);

	print_pgroup(thp, NULL, pgn, dstab, nstab, version);

	for (pnvp = nvlist_next_nvpair(nvl, NULL); pnvp != NULL;
	    pnvp = nvlist_next_nvpair(nvl, pnvp)) {

		/*
		 * Print property group and property name-value pair
		 */
		if (strcmp(TOPO_PROP_VAL, nvpair_name(pnvp))
		    == 0 && nvpair_type(pnvp) == DATA_TYPE_NVLIST) {
			(void) nvpair_value_nvlist(pnvp, &pnvl);
				print_prop_nameval(thp, NULL, pnvl);

		}

	}
}
示例#15
0
const void *
cnvlist_get_binary(void *cookiep, size_t *sizep)
{

	if (nvpair_type(cookiep) != NV_TYPE_BINARY)
		nvlist_report_missing(NV_TYPE_BINARY, nvpair_name(cookiep));
	return (nvpair_get_binary(cookiep, sizep));
}
示例#16
0
/*
 * Goes through the ini property list and validates
 * each entry.  If errs is non-NULL, will return explicit errors
 * for each property that fails validation.
 */
static int
it_validate_iniprops(nvlist_t *nvl, nvlist_t *errs)
{
	int				errcnt = 0;
	nvpair_t			*nvp = NULL;
	data_type_t			nvtype;
	char				*name;
	char				*val;

	if (!nvl) {
		return (0);
	}

	while ((nvp = nvlist_next_nvpair(nvl, nvp)) != NULL) {
		name = nvpair_name(nvp);
		nvtype = nvpair_type(nvp);

		if (!name) {
			continue;
		}

		if (strcmp(name, PROP_CHAP_USER) == 0) {
			if (nvtype != DATA_TYPE_STRING) {
				PROPERR(errs, name,
				    gettext("must be a string value"));
				errcnt++;
				continue;
			}
		} else if (strcmp(name, PROP_CHAP_SECRET) == 0) {
			/*
			 * must be between 12 and 255 chars in cleartext.
			 * will be base64 encoded when it's set.
			 */
			if (nvtype == DATA_TYPE_STRING) {
				val = NULL;
				(void) nvpair_value_string(nvp, &val);
			}

			if (!val) {
				PROPERR(errs, name,
				    gettext("must be a string value"));
				errcnt++;
				continue;
			}
		} else {
			/* unrecognized property */
			PROPERR(errs, name, gettext("unrecognized property"));
			errcnt++;
		}
	}

	if (errcnt) {
		return (EINVAL);
	}

	return (0);
}
示例#17
0
/*
 * Use the supplied nvpair_t to set the name, type and value of the
 * supplied pool_value_t.
 *
 * Return: PO_SUCCESS/PO_FAIL
 */
int
pool_value_from_nvpair(pool_value_t *pv, nvpair_t *pn)
{
	uchar_t bval;
	uint64_t uval;
	int64_t ival;
	double dval;
	uint_t nelem;
	uchar_t *dval_b;
	char *sval;

	if (pool_value_set_name(pv, nvpair_name(pn)) != PO_SUCCESS)
		return (PO_FAIL);
	switch (nvpair_type(pn)) {
	case DATA_TYPE_BYTE:
		if (nvpair_value_byte(pn, &bval) != 0) {
			pool_seterror(POE_SYSTEM);
			return (PO_FAIL);
		}
		pool_value_set_bool(pv, bval);
		break;
	case DATA_TYPE_BYTE_ARRAY:
		if (nvpair_value_byte_array(pn, &dval_b, &nelem) != 0) {
			pool_seterror(POE_SYSTEM);
			return (PO_FAIL);
		}
		(void) memcpy(&dval, dval_b, sizeof (double));
		pool_value_set_double(pv, dval);
		break;
	case DATA_TYPE_INT64:
		if (nvpair_value_int64(pn, &ival) != 0) {
			pool_seterror(POE_SYSTEM);
			return (PO_FAIL);
		}
		pool_value_set_int64(pv, ival);
		break;
	case DATA_TYPE_UINT64:
		if (nvpair_value_uint64(pn, &uval) != 0) {
			pool_seterror(POE_SYSTEM);
			return (PO_FAIL);
		}
		pool_value_set_uint64(pv, uval);
		break;
	case DATA_TYPE_STRING:
		if (nvpair_value_string(pn, &sval) != 0) {
			pool_seterror(POE_SYSTEM);
			return (PO_FAIL);
		}
		if (pool_value_set_string(pv, sval) != PO_SUCCESS)
			return (PO_FAIL);
		break;
	default:
		pool_seterror(POE_SYSTEM);
		return (PO_FAIL);
	}
	return (PO_SUCCESS);
}
示例#18
0
文件: zfs_util.c 项目: derzzle/zfs
void
zpool_read_cachefile(void)
{
	int fd;
	struct stat stbf;
	void *buf = NULL;
	nvlist_t *nvlist, *child;
	nvpair_t *nvpair;
	uint64_t guid;
	int importrc = 0;

	printf("reading cachefile\n");

	fd = open(ZPOOL_CACHE, O_RDONLY);
	if (fd < 0)
		return;

	if (fstat(fd, &stbf) || !stbf.st_size)
		goto out;

	buf = kmem_alloc(stbf.st_size, 0);
	if (!buf)
		goto out;

	if (read(fd, buf, stbf.st_size) != stbf.st_size)
		goto out;

	if (nvlist_unpack(buf, stbf.st_size, &nvlist, KM_PUSHPAGE) != 0)
		goto out;

	nvpair = NULL;
	while ((nvpair = nvlist_next_nvpair(nvlist, nvpair)) != NULL) {
		if (nvpair_type(nvpair) != DATA_TYPE_NVLIST)
			continue;

		VERIFY(nvpair_value_nvlist(nvpair, &child) == 0);

		printf("Cachefile has pool '%s'\n", nvpair_name(nvpair));

		if (nvlist_lookup_uint64(child, ZPOOL_CONFIG_POOL_GUID,
		    &guid) == 0) {
			printf("Cachefile has pool '%s' guid %llu\n",
			    nvpair_name(nvpair), guid);

			importrc = zpool_import_by_guid(guid);
			printf("zpool import error %d\n", importrc);
		}

	}
	nvlist_free(nvlist);

out:
	close(fd);
	if (buf)
		kmem_free(buf, stbf.st_size);

}
示例#19
0
文件: vars_dump.c 项目: jeffpc/blahgd
static void __dump(nvlist_t *list, int indent)
{
	nvpair_t *pair;

	for (pair = nvlist_next_nvpair(list, NULL);
	     pair;
	     pair = nvlist_next_nvpair(list, pair)) {
		fprintf(stderr, "%*sname='%s' type=%d", indent, "",
			nvpair_name(pair), nvpair_type(pair));

		switch (nvpair_type(pair)) {
			case DATA_TYPE_STRING:
				fprintf(stderr, "\n%*svalue='%s'\n",
					indent + INDENT, "", pair2str(pair));
				break;
			case DATA_TYPE_STRING_ARRAY:
				__dump_string_array(pair, indent + INDENT);
				break;
			case DATA_TYPE_BOOLEAN_VALUE:
				fprintf(stderr, "\n%*svalue=%s\n",
					indent + INDENT, "",
					pair2bool(pair) ? "true" : "false");
				break;
			case DATA_TYPE_UINT8:
				fprintf(stderr, "\n%*svalue='%c'\n",
					indent + INDENT, "", pair2char(pair));
				break;
			case DATA_TYPE_UINT64:
				fprintf(stderr, "\n%*svalue=%"PRIu64"\n",
					indent + INDENT, "", pair2int(pair));
				break;
			case DATA_TYPE_NVLIST:
				fprintf(stderr, "\n");
				__dump(pair2nvl(pair), indent + INDENT);
				break;
			case DATA_TYPE_NVLIST_ARRAY:
				__dump_nvlist_array(pair, indent + INDENT);
				break;
			default:
				fprintf(stderr, "\n");
				break;
		}
	}
}
示例#20
0
nvpair_t *
nvpair_clone(const nvpair_t *nvp)
{
	nvpair_t *newnvp;
	const char *name;
	const void *data;
	size_t datasize;

	NVPAIR_ASSERT(nvp);

	name = nvpair_name(nvp);

	switch (nvpair_type(nvp)) {
	case NV_TYPE_NULL:
		newnvp = nvpair_create_null(name);
		break;
	case NV_TYPE_BOOL:
		newnvp = nvpair_create_bool(name, nvpair_get_bool(nvp));
		break;
	case NV_TYPE_NUMBER:
		newnvp = nvpair_create_number(name, nvpair_get_number(nvp));
		break;
	case NV_TYPE_STRING:
		newnvp = nvpair_create_string(name, nvpair_get_string(nvp));
		break;
	case NV_TYPE_NVLIST:
		newnvp = nvpair_create_nvlist(name, nvpair_get_nvlist(nvp));
		break;
#ifndef _KERNEL
	case NV_TYPE_DESCRIPTOR:
		newnvp = nvpair_create_descriptor(name,
		    nvpair_get_descriptor(nvp));
		break;
#endif
	case NV_TYPE_BINARY:
		data = nvpair_get_binary(nvp, &datasize);
		newnvp = nvpair_create_binary(name, data, datasize);
		break;
	default:
		PJDLOG_ABORT("Unknown type: %d.", nvpair_type(nvp));
	}

	return (newnvp);
}
示例#21
0
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);
}
示例#22
0
static PyObject *
nvl2py(nvlist_t *nvl)
{
	PyObject *pyo;
	nvpair_t *nvp;

	pyo = PyDict_New();

	for (nvp = nvlist_next_nvpair(nvl, NULL); nvp;
	    nvp = nvlist_next_nvpair(nvl, nvp)) {
		PyObject *pyval;
		char *sval;
		uint64_t ival;
		boolean_t bval;
		nvlist_t *nval;

		switch (nvpair_type(nvp)) {
		case DATA_TYPE_STRING:
			(void) nvpair_value_string(nvp, &sval);
			pyval = Py_BuildValue("s", sval);
			break;

		case DATA_TYPE_UINT64:
			(void) nvpair_value_uint64(nvp, &ival);
			pyval = Py_BuildValue("K", ival);
			break;

		case DATA_TYPE_NVLIST:
			(void) nvpair_value_nvlist(nvp, &nval);
			pyval = nvl2py(nval);
			break;

		case DATA_TYPE_BOOLEAN:
			Py_INCREF(Py_None);
			pyval = Py_None;
			break;

		case DATA_TYPE_BOOLEAN_VALUE:
			(void) nvpair_value_boolean_value(nvp, &bval);
			pyval = Py_BuildValue("i", bval);
			break;

		default:
			PyErr_SetNone(PyExc_ValueError);
			Py_DECREF(pyo);
			return (NULL);
		}

		PyDict_SetItemString(pyo, nvpair_name(nvp), pyval);
		Py_DECREF(pyval);
	}

	return (pyo);
}
示例#23
0
static int
sysev_evc_handler(sysevent_t *ev, void *cookie)
{
  char *name, *zonename, *oldstate, *newstate;
  nvlist_t *nvlist;
  nvpair_t *curr, *next;

  cookie = cookie; // SILENCE!

  if (sysevent_get_attr_list(ev, &nvlist) != 0) {
    // XXX Error
    return (1);
  }

  // loop through event nvpairs to get our interesting values
  curr = nvlist_next_nvpair(nvlist, NULL);
  while (curr != NULL) {
    // all fields we're interested in are strings
    if (nvpair_type(curr) == DATA_TYPE_STRING) {
      name = nvpair_name(curr);

      if (strcmp(name, ZONE_CB_NAME) == 0) {
        nvpair_value_string(curr, &zonename);
      } else if (strcmp(name, ZONE_CB_NEWSTATE) == 0) {
        nvpair_value_string(curr, &newstate);
      } else if (strcmp(name, ZONE_CB_OLDSTATE) == 0) {
        nvpair_value_string(curr, &oldstate);
      }
    }

    next = nvlist_next_nvpair(nvlist, curr);
    curr = next;
  }

  // if it is a boot into running we need to enable the gate
  if (strcmp(oldstate, ZONE_EVENT_READY) == 0 &&
      strcmp(newstate, ZONE_EVENT_RUNNING) == 0) {
    gate_attach(zonename);
  }

  // ignore multiple shutting_down -> shutting_down transitions
  if (strcmp(oldstate, newstate) != 0) {
    char zonebrand[MAXNAMELEN];

    // get brand for zone
    if (zone_get_brand(zonename, zonebrand, sizeof (zonebrand)) == Z_OK) {
      request_send_state_event(zonename, zonebrand, oldstate, newstate);
    } else {
      request_send_state_event(zonename, NULL, oldstate, newstate);
    }
  }

  return (0);
}
示例#24
0
void *
cnvlist_take_binary(nvlist_t *nvl, void *cookiep, size_t *sizep)
{
	void *value;

	if (nvpair_type(cookiep) != NV_TYPE_BINARY)
		nvlist_report_missing(NV_TYPE_BINARY, nvpair_name(cookiep));
	value = (void *)(intptr_t)nvpair_get_binary(cookiep, sizep);
	nvlist_remove_nvpair(nvl, cookiep);
	nvpair_free_structure(cookiep);
	return (value);
}
示例#25
0
nvlist_t *
sysattr_list(char *cmd, int fd, char *fname)
{
	boolean_t	value;
	data_type_t	type;
	nvlist_t	*response;
	nvpair_t	*pair;
	f_attr_t	fattr;
	char		*name;

	if (fgetattr(fd, XATTR_VIEW_READWRITE, &response) != 0) {
		(void) fprintf(stderr, dgettext(TEXT_DOMAIN,
		    "%s: %s: fgetattr failed\n"),
		    cmd, fname);
		return (NULL);
	}
	pair = NULL;
	while ((pair = nvlist_next_nvpair(response, pair)) != NULL) {

		name = nvpair_name(pair);

		if (name != NULL)
			fattr = name_to_attr(name);
		else
			return (response);

		type = nvpair_type(pair);
		switch (type) {
			case DATA_TYPE_BOOLEAN_VALUE:
				if (nvpair_value_boolean_value(pair,
				    &value) != 0) {
					(void) fprintf(stderr,
					    dgettext(TEXT_DOMAIN, "%s "
					    "nvpair_value_boolean_value "
					    "failed\n"), cmd);
					continue;
				}
				if (value && fattr != F_ARCHIVE &&
				    fattr != F_AV_MODIFIED)
					return (response);
				break;
			case DATA_TYPE_UINT64_ARRAY:
				if (fattr != F_CRTIME)
					return (response);
				break;
			case DATA_TYPE_NVLIST:
			default:
				return (response);
		}
	}
	nvlist_free(response);
	return (NULL);
}
示例#26
0
/*
 * Lookup seq_num. We can not use the standard nvlist_lookup functions since
 * the nvlist is not allocated with NV_UNIQUE_NAME or NV_UNIQUE_NAME_TYPE.
 */
static int
lookup_seq_num(nvlist_t *nvl, uint64_t *seq_num)
{
	nvpair_t *nvp = NULL;

	while ((nvp = nvlist_next_nvpair(nvl, nvp)) != NULL) {
		if (strcmp(nvpair_name(nvp), RCM_SEQ_NUM) == 0 &&
		    nvpair_type(nvp) == DATA_TYPE_UINT64)
			return (nvpair_value_uint64(nvp, seq_num));
	}

	return (ENOENT);
}
示例#27
0
/*
 * This function is invoked when a share is disabled to disconnect trees
 * and close files.  Cleaning up may involve VOP and/or VFS calls, which
 * may conflict/deadlock with stuck threads if something is amiss with the
 * file system.  Queueing the request for asynchronous processing allows the
 * call to return immediately so that, if the unshare is being done in the
 * context of a forced unmount, the forced unmount will always be able to
 * proceed (unblocking stuck I/O and eventually allowing all blocked unshare
 * processes to complete).
 *
 * The path lookup to find the root vnode of the VFS in question and the
 * release of this vnode are done synchronously prior to any associated
 * unmount.  Doing these asynchronous to an associated unmount could run
 * the risk of a spurious EBUSY for a standard unmount or an EIO during
 * the path lookup due to a forced unmount finishing first.
 */
int
smb_kshare_unexport_list(smb_ioc_share_t *ioc)
{
	smb_server_t	*sv = NULL;
	smb_unshare_t	*ux;
	nvlist_t	*shrlist = NULL;
	nvpair_t	*nvp;
	boolean_t	unexport = B_FALSE;
	char		*shrname;
	int		rc;

	if ((rc = smb_server_lookup(&sv)) != 0)
		return (rc);

	if ((rc = nvlist_unpack(ioc->shr, ioc->shrlen, &shrlist, 0)) != 0)
		goto out;

	for (nvp = nvlist_next_nvpair(shrlist, NULL); nvp != NULL;
	    nvp = nvlist_next_nvpair(shrlist, nvp)) {
		if (nvpair_type(nvp) != DATA_TYPE_NVLIST)
			continue;

		shrname = nvpair_name(nvp);
		ASSERT(shrname);

		if ((rc = smb_kshare_unexport(sv, shrname)) != 0)
			continue;

		ux = kmem_cache_alloc(smb_kshare_cache_unexport, KM_SLEEP);
		(void) strlcpy(ux->us_sharename, shrname, MAXNAMELEN);

		smb_slist_insert_tail(&sv->sv_export.e_unexport_list, ux);
		unexport = B_TRUE;
	}

	if (unexport)
		smb_thread_signal(&sv->sv_export.e_unexport_thread);
	rc = 0;

out:
	if (shrlist != NULL)
		nvlist_free(shrlist);
	smb_server_release(sv);
	return (rc);
}
示例#28
0
/*
 * Put new CPU property.
 * Handle special case of "cpu.status".
 */
int
pool_cpu_propput(processorid_t cpuid, nvpair_t *pair)
{
	int ret = 0;
	cpu_t *cpu;

	ASSERT(pool_lock_held());
	ASSERT(INGLOBALZONE(curproc));

	if (nvpair_type(pair) == DATA_TYPE_STRING &&
	    strcmp(nvpair_name(pair), "cpu.status") == 0) {
		char *val;
		int status;
		int old_status;
		(void) nvpair_value_string(pair, &val);
		if (strcmp(val, PS_OFFLINE) == 0)
			status = P_OFFLINE;
		else if (strcmp(val, PS_ONLINE) == 0)
			status = P_ONLINE;
		else if (strcmp(val, PS_NOINTR) == 0)
			status = P_NOINTR;
		else if (strcmp(val, PS_FAULTED) == 0)
			status = P_FAULTED;
		else if (strcmp(val, PS_SPARE) == 0)
			status = P_SPARE;
		else
			return (EINVAL);
		ret = p_online_internal(cpuid, status, &old_status);
	} else {
		mutex_enter(&cpu_lock);
		if ((cpu = cpu_get(cpuid)) == NULL)
			ret = EINVAL;
		if (cpu->cpu_props == NULL) {
			(void) nvlist_alloc(&cpu->cpu_props,
			    NV_UNIQUE_NAME, KM_SLEEP);
			(void) nvlist_add_string(cpu->cpu_props,
			    "cpu.comment", "");
		}
		ret = pool_propput_common(cpu->cpu_props, pair, pool_cpu_props);
		if (ret == 0)
			pool_cpu_mod = gethrtime();
		mutex_exit(&cpu_lock);
	}
	return (ret);
}
示例#29
0
/*
 * The function obtains size of the nvlist after nvlist_pack().
 */
size_t
nvlist_size(const nvlist_t *nvl)
{
	const nvlist_t *tmpnvl;
	const nvpair_t *nvp, *tmpnvp;
	void *cookie;
	size_t size;

	NVLIST_ASSERT(nvl);
	PJDLOG_ASSERT(nvl->nvl_error == 0);

	size = sizeof(struct nvlist_header);
	nvp = nvlist_first_nvpair(nvl);
	while (nvp != NULL) {
		size += nvpair_header_size();
		size += strlen(nvpair_name(nvp)) + 1;
		if (nvpair_type(nvp) == NV_TYPE_NVLIST) {
			size += sizeof(struct nvlist_header);
			size += nvpair_header_size() + 1;
			tmpnvl = nvpair_get_nvlist(nvp);
			PJDLOG_ASSERT(tmpnvl->nvl_error == 0);
			tmpnvp = nvlist_first_nvpair(tmpnvl);
			if (tmpnvp != NULL) {
				nvl = tmpnvl;
				nvp = tmpnvp;
				continue;
			}
		} else {
			size += nvpair_size(nvp);
		}

		while ((nvp = nvlist_next_nvpair(nvl, nvp)) == NULL) {
			cookie = NULL;
			nvl = nvlist_get_parent(nvl, &cookie);
			if (nvl == NULL)
				goto out;
			nvp = cookie;
		}
	}

out:
	return (size);
}
示例#30
0
const char *
nvlist_next(const nvlist_t *nvl, int *typep, void **cookiep)
{
	nvpair_t *nvp;

	NVLIST_ASSERT(nvl);
	PJDLOG_ASSERT(cookiep != NULL);

	if (*cookiep == NULL)
		nvp = nvlist_first_nvpair(nvl);
	else
		nvp = nvlist_next_nvpair(nvl, *cookiep);
	if (nvp == NULL)
		return (NULL);
	if (typep != NULL)
		*typep = nvpair_type(nvp);
	*cookiep = nvp;
	return (nvpair_name(nvp));
}