Ejemplo n.º 1
0
int
zprop_index_to_string(int prop, uint64_t index, const char **string,
    zfs_type_t type)
{
	zprop_desc_t *prop_tbl;
	const zprop_index_t *idx_tbl;
	int i;

	if (prop == ZPROP_INVAL || prop == ZPROP_CONT)
		return (-1);

	ASSERT(prop < zprop_get_numprops(type));
	prop_tbl = zprop_get_proptable(type);
	if ((idx_tbl = prop_tbl[prop].pd_table) == NULL)
		return (-1);

	for (i = 0; idx_tbl[i].pi_name != NULL; i++) {
		if (idx_tbl[i].pi_value == index) {
			*string = idx_tbl[i].pi_name;
			return (0);
		}
	}

	return (-1);
}
Ejemplo n.º 2
0
void
zprop_register_impl(int prop, const char *name, zprop_type_t type,
    uint64_t numdefault, const char *strdefault, zprop_attr_t attr,
    int objset_types, const char *values, const char *colname,
    boolean_t rightalign, boolean_t visible, const zprop_index_t *idx_tbl)
{
	zprop_desc_t *prop_tbl = zprop_get_proptable(objset_types);
	zprop_desc_t *pd;

	pd = &prop_tbl[prop];

	ASSERT(pd->pd_name == NULL || pd->pd_name == name);
	ASSERT(name != NULL);
	ASSERT(colname != NULL);

	pd->pd_name = name;
	pd->pd_propnum = prop;
	pd->pd_proptype = type;
	pd->pd_numdefault = numdefault;
	pd->pd_strdefault = strdefault;
	pd->pd_attr = attr;
	pd->pd_types = objset_types;
	pd->pd_values = values;
	pd->pd_colname = colname;
	pd->pd_rightalign = rightalign;
	pd->pd_visible = visible;
	pd->pd_table = idx_tbl;
	pd->pd_table_size = 0;
	while (idx_tbl && (idx_tbl++)->pi_name != NULL)
		pd->pd_table_size++;
}
Ejemplo n.º 3
0
/*
 * Determines the minimum width for the column, and indicates whether it's fixed
 * or not.  Only string columns are non-fixed.
 */
size_t
zprop_width(int prop, boolean_t *fixed, zfs_type_t type)
{
	zprop_desc_t *prop_tbl, *pd;
	const zprop_index_t *idx;
	size_t ret;
	int i;

	ASSERT(prop != ZPROP_INVAL && prop != ZPROP_CONT);
	ASSERT(prop < zprop_get_numprops(type));

	prop_tbl = zprop_get_proptable(type);
	pd = &prop_tbl[prop];

	*fixed = B_TRUE;

	/*
	 * Start with the width of the column name.
	 */
	ret = strlen(pd->pd_colname);

	/*
	 * For fixed-width values, make sure the width is large enough to hold
	 * any possible value.
	 */
	switch (pd->pd_proptype) {
	case PROP_TYPE_NUMBER:
		/*
		 * The maximum length of a human-readable number is 5 characters
		 * ("20.4M", for example).
		 */
		if (ret < 5)
			ret = 5;
		/*
		 * 'creation' is handled specially because it's a number
		 * internally, but displayed as a date string.
		 */
		if (prop == ZFS_PROP_CREATION)
			*fixed = B_FALSE;
		break;
	case PROP_TYPE_INDEX:
		idx = prop_tbl[prop].pd_table;
		for (i = 0; idx[i].pi_name != NULL; i++) {
			if (strlen(idx[i].pi_name) > ret)
				ret = strlen(idx[i].pi_name);
		}
		break;

	case PROP_TYPE_STRING:
		*fixed = B_FALSE;
		break;
	}

	return (ret);
}
Ejemplo n.º 4
0
/*
 * Returns TRUE if the property applies to any of the given dataset types.
 */
boolean_t
zprop_valid_for_type(int prop, zfs_type_t type)
{
	zprop_desc_t *prop_tbl;

	if (prop == ZPROP_INVAL || prop == ZPROP_CONT)
		return (B_FALSE);

	ASSERT(prop < zprop_get_numprops(type));
	prop_tbl = zprop_get_proptable(type);
	return ((prop_tbl[prop].pd_types & type) != 0);
}
Ejemplo n.º 5
0
const char *
zprop_values(int prop, zfs_type_t type)
{
	zprop_desc_t *prop_tbl;

	ASSERT(prop != ZPROP_INVAL && prop != ZPROP_CONT);
	ASSERT(prop < zprop_get_numprops(type));

	prop_tbl = zprop_get_proptable(type);

	return (prop_tbl[prop].pd_values);
}
Ejemplo n.º 6
0
int
zprop_name_to_prop(const char *propname, zfs_type_t type)
{
	int prop;
	name_to_prop_cb_t cb_data;

	cb_data.propname = propname;
	cb_data.prop_tbl = zprop_get_proptable(type);

	prop = zprop_iter_common(zprop_name_to_prop_cb, &cb_data,
	    B_TRUE, B_FALSE, type);

	return (prop == ZPROP_CONT ? ZPROP_INVAL : prop);
}
Ejemplo n.º 7
0
/*
 * Returns TRUE if the property applies to any of the given dataset types.
 *
 * If headcheck is set, the check is being made against the head dataset
 * type of a snapshot which requires to return B_TRUE when the property
 * is only valid for snapshots.
 */
boolean_t
zprop_valid_for_type(int prop, zfs_type_t type, boolean_t headcheck)
{
	zprop_desc_t *prop_tbl;

	if (prop == ZPROP_INVAL || prop == ZPROP_CONT)
		return (B_FALSE);

	ASSERT(prop < zprop_get_numprops(type));
	prop_tbl = zprop_get_proptable(type);
	if (headcheck && prop_tbl[prop].pd_types == ZFS_TYPE_SNAPSHOT)
		return (B_TRUE);
	return ((prop_tbl[prop].pd_types & type) != 0);
}
Ejemplo n.º 8
0
/*
 * Return a random valid property value.  Used by ztest.
 */
uint64_t
zprop_random_value(int prop, uint64_t seed, zfs_type_t type)
{
	zprop_desc_t *prop_tbl;
	const zprop_index_t *idx_tbl;

	ASSERT((uint_t)prop < zprop_get_numprops(type));
	prop_tbl = zprop_get_proptable(type);
	idx_tbl = prop_tbl[prop].pd_table;

	if (idx_tbl == NULL)
		return (seed);

	return (idx_tbl[seed % prop_tbl[prop].pd_table_size].pi_value);
}
Ejemplo n.º 9
0
/*
 * Iterate over all properties in the given property table, calling back
 * into the specified function for each property. We will continue to
 * iterate until we either reach the end or the callback function returns
 * something other than ZPROP_CONT.
 */
int
zprop_iter_common(zprop_func func, void *cb, boolean_t show_all,
    boolean_t ordered, zfs_type_t type)
{
	int i, j, num_props, size, prop;
	zprop_desc_t *prop_tbl;
	zprop_desc_t **order;

	prop_tbl = zprop_get_proptable(type);
	num_props = zprop_get_numprops(type);
	size = num_props * sizeof (zprop_desc_t *);

#if defined(_KERNEL)
	order = kmem_alloc(size, KM_PUSHPAGE);
#else
	if ((order = malloc(size)) == NULL)
		return (ZPROP_CONT);
#endif

	for (j = 0; j < num_props; j++)
		order[j] = &prop_tbl[j];

	if (ordered) {
#ifndef _KERNEL
		qsort((void *)order, num_props, sizeof (zprop_desc_t *),
		    zprop_compare);
#endif
	}

	prop = ZPROP_CONT;
	for (i = 0; i < num_props; i++) {
		if ((order[i]->pd_visible || show_all) &&
		    (func(order[i]->pd_propnum, cb) != ZPROP_CONT)) {
			prop = order[i]->pd_propnum;
			break;
		}
	}

#if defined(_KERNEL)
	kmem_free(order, size);
#else
	free(order);
#endif
	return (prop);
}