990b4856d0eaada6f8140335733a1b1771ed2746lling * CDDL HEADER START
990b4856d0eaada6f8140335733a1b1771ed2746lling * The contents of this file are subject to the terms of the
990b4856d0eaada6f8140335733a1b1771ed2746lling * Common Development and Distribution License (the "License").
990b4856d0eaada6f8140335733a1b1771ed2746lling * You may not use this file except in compliance with the License.
990b4856d0eaada6f8140335733a1b1771ed2746lling * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
990b4856d0eaada6f8140335733a1b1771ed2746lling * See the License for the specific language governing permissions
990b4856d0eaada6f8140335733a1b1771ed2746lling * and limitations under the License.
990b4856d0eaada6f8140335733a1b1771ed2746lling * When distributing Covered Code, include this CDDL HEADER in each
990b4856d0eaada6f8140335733a1b1771ed2746lling * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
990b4856d0eaada6f8140335733a1b1771ed2746lling * If applicable, add the following below this CDDL HEADER, with the
990b4856d0eaada6f8140335733a1b1771ed2746lling * fields enclosed by brackets "[]" replaced with your own identifying
990b4856d0eaada6f8140335733a1b1771ed2746lling * information: Portions Copyright [yyyy] [name of copyright owner]
990b4856d0eaada6f8140335733a1b1771ed2746lling * CDDL HEADER END
83d7f9fe6bbb3e281a1ca55fdc5d1ec82ecc3e70Tom Erickson * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
990b4856d0eaada6f8140335733a1b1771ed2746lling * Use is subject to license terms.
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * Copyright (c) 2012 by Delphix. All rights reserved.
990b4856d0eaada6f8140335733a1b1771ed2746lling * Common routines used by zfs and zpool property management.
990b4856d0eaada6f8140335733a1b1771ed2746lling#if defined(_KERNEL)
83d7f9fe6bbb3e281a1ca55fdc5d1ec82ecc3e70Tom Ericksonzprop_register_impl(int prop, const char *name, zprop_type_t type,
990b4856d0eaada6f8140335733a1b1771ed2746lling uint64_t numdefault, const char *strdefault, zprop_attr_t attr,
990b4856d0eaada6f8140335733a1b1771ed2746lling int objset_types, const char *values, const char *colname,
990b4856d0eaada6f8140335733a1b1771ed2746lling boolean_t rightalign, boolean_t visible, const zprop_index_t *idx_tbl)
990b4856d0eaada6f8140335733a1b1771ed2746lling zprop_desc_t *prop_tbl = zprop_get_proptable(objset_types);
b24ab6762772a3f6a89393947930c7fa61306783Jeff Bonwick while (idx_tbl && (idx_tbl++)->pi_name != NULL)
83d7f9fe6bbb3e281a1ca55fdc5d1ec82ecc3e70Tom Ericksonzprop_register_string(int prop, const char *name, const char *def,
990b4856d0eaada6f8140335733a1b1771ed2746lling zprop_attr_t attr, int objset_types, const char *values,
990b4856d0eaada6f8140335733a1b1771ed2746lling const char *colname)
83d7f9fe6bbb3e281a1ca55fdc5d1ec82ecc3e70Tom Erickson zprop_register_impl(prop, name, PROP_TYPE_STRING, 0, def, attr,
990b4856d0eaada6f8140335733a1b1771ed2746lling objset_types, values, colname, B_FALSE, B_TRUE, NULL);
83d7f9fe6bbb3e281a1ca55fdc5d1ec82ecc3e70Tom Ericksonzprop_register_number(int prop, const char *name, uint64_t def,
83d7f9fe6bbb3e281a1ca55fdc5d1ec82ecc3e70Tom Erickson zprop_attr_t attr, int objset_types, const char *values,
83d7f9fe6bbb3e281a1ca55fdc5d1ec82ecc3e70Tom Erickson zprop_register_impl(prop, name, PROP_TYPE_NUMBER, def, NULL, attr,
83d7f9fe6bbb3e281a1ca55fdc5d1ec82ecc3e70Tom Ericksonzprop_register_index(int prop, const char *name, uint64_t def,
83d7f9fe6bbb3e281a1ca55fdc5d1ec82ecc3e70Tom Erickson zprop_attr_t attr, int objset_types, const char *values,
83d7f9fe6bbb3e281a1ca55fdc5d1ec82ecc3e70Tom Erickson const char *colname, const zprop_index_t *idx_tbl)
83d7f9fe6bbb3e281a1ca55fdc5d1ec82ecc3e70Tom Erickson zprop_register_impl(prop, name, PROP_TYPE_INDEX, def, NULL, attr,
990b4856d0eaada6f8140335733a1b1771ed2746lling objset_types, values, colname, B_TRUE, B_TRUE, idx_tbl);
83d7f9fe6bbb3e281a1ca55fdc5d1ec82ecc3e70Tom Ericksonzprop_register_hidden(int prop, const char *name, zprop_type_t type,
990b4856d0eaada6f8140335733a1b1771ed2746lling zprop_attr_t attr, int objset_types, const char *colname)
83d7f9fe6bbb3e281a1ca55fdc5d1ec82ecc3e70Tom Erickson zprop_register_impl(prop, name, type, 0, NULL, attr,
990b4856d0eaada6f8140335733a1b1771ed2746lling * A comparison function we can use to order indexes into property tables.
990b4856d0eaada6f8140335733a1b1771ed2746lling * Iterate over all properties in the given property table, calling back
990b4856d0eaada6f8140335733a1b1771ed2746lling * into the specified function for each property. We will continue to
990b4856d0eaada6f8140335733a1b1771ed2746lling * iterate until we either reach the end or the callback function returns
990b4856d0eaada6f8140335733a1b1771ed2746lling * something other than ZPROP_CONT.
990b4856d0eaada6f8140335733a1b1771ed2746llingzprop_iter_common(zprop_func func, void *cb, boolean_t show_all,
990b4856d0eaada6f8140335733a1b1771ed2746lling#if defined(_KERNEL)
990b4856d0eaada6f8140335733a1b1771ed2746lling for (int j = 0; j < num_props; j++)
990b4856d0eaada6f8140335733a1b1771ed2746lling qsort((void *)order, num_props, sizeof (zprop_desc_t *),
990b4856d0eaada6f8140335733a1b1771ed2746lling for (i = 0; i < num_props; i++) {
990b4856d0eaada6f8140335733a1b1771ed2746lling#if defined(_KERNEL)
990b4856d0eaada6f8140335733a1b1771ed2746llingpropname_match(const char *p, size_t len, zprop_desc_t *prop_entry)
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens if (colname == NULL || len != strlen(colname))
990b4856d0eaada6f8140335733a1b1771ed2746lling for (c = 0; c < len; c++)
990b4856d0eaada6f8140335733a1b1771ed2746lling if (propname_match(data->propname, strlen(data->propname),
990b4856d0eaada6f8140335733a1b1771ed2746llingzprop_name_to_prop(const char *propname, zfs_type_t type)
990b4856d0eaada6f8140335733a1b1771ed2746lling prop = zprop_iter_common(zprop_name_to_prop_cb, &cb_data,
990b4856d0eaada6f8140335733a1b1771ed2746llingzprop_string_to_index(int prop, const char *string, uint64_t *index,
7991292307fd1c555120800d965c4c6c4b304f3fgw return (-1);
990b4856d0eaada6f8140335733a1b1771ed2746lling return (-1);
990b4856d0eaada6f8140335733a1b1771ed2746lling return (0);
990b4856d0eaada6f8140335733a1b1771ed2746lling return (-1);
990b4856d0eaada6f8140335733a1b1771ed2746llingzprop_index_to_string(int prop, uint64_t index, const char **string,
7991292307fd1c555120800d965c4c6c4b304f3fgw return (-1);
990b4856d0eaada6f8140335733a1b1771ed2746lling return (-1);
990b4856d0eaada6f8140335733a1b1771ed2746lling return (0);
990b4856d0eaada6f8140335733a1b1771ed2746lling return (-1);
b24ab6762772a3f6a89393947930c7fa61306783Jeff Bonwick * Return a random valid property value. Used by ztest.
b24ab6762772a3f6a89393947930c7fa61306783Jeff Bonwickzprop_random_value(int prop, uint64_t seed, zfs_type_t type)
b24ab6762772a3f6a89393947930c7fa61306783Jeff Bonwick ASSERT((uint_t)prop < zprop_get_numprops(type));
b24ab6762772a3f6a89393947930c7fa61306783Jeff Bonwick return (idx_tbl[seed % prop_tbl[prop].pd_table_size].pi_value);
990b4856d0eaada6f8140335733a1b1771ed2746llingconst char *
990b4856d0eaada6f8140335733a1b1771ed2746lling * Returns TRUE if the property applies to any of the given dataset types.
990b4856d0eaada6f8140335733a1b1771ed2746lling * Determines the minimum width for the column, and indicates whether it's fixed
990b4856d0eaada6f8140335733a1b1771ed2746lling * or not. Only string columns are non-fixed.
990b4856d0eaada6f8140335733a1b1771ed2746llingzprop_width(int prop, boolean_t *fixed, zfs_type_t type)
990b4856d0eaada6f8140335733a1b1771ed2746lling * Start with the width of the column name.
990b4856d0eaada6f8140335733a1b1771ed2746lling * For fixed-width values, make sure the width is large enough to hold
990b4856d0eaada6f8140335733a1b1771ed2746lling * any possible value.
990b4856d0eaada6f8140335733a1b1771ed2746lling * The maximum length of a human-readable number is 5 characters
990b4856d0eaada6f8140335733a1b1771ed2746lling * ("20.4M", for example).
990b4856d0eaada6f8140335733a1b1771ed2746lling * 'creation' is handled specially because it's a number
990b4856d0eaada6f8140335733a1b1771ed2746lling * internally, but displayed as a date string.