X-Git-Url: https://git.camperquake.de/gitweb.cgi?a=blobdiff_plain;f=module%2Fzcommon%2Fzprop_common.c;h=df2fdeab8ba1897122df63c70178f907ab11bb4e;hb=c65aa5b2b9c48375ea1c451f252f0056e16f4e49;hp=85f55c27628e504b0cc0001160236b49b7f6938a;hpb=9babb37438b58e77bad04e820d5702e15b79e6a6;p=zfs.git diff --git a/module/zcommon/zprop_common.c b/module/zcommon/zprop_common.c index 85f55c2..df2fdea 100644 --- a/module/zcommon/zprop_common.c +++ b/module/zcommon/zprop_common.c @@ -19,7 +19,7 @@ * CDDL HEADER END */ /* - * Copyright 2009 Sun Microsystems, Inc. All rights reserved. + * Copyright 2010 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -65,7 +65,7 @@ zprop_get_numprops(zfs_type_t type) } void -register_impl(int prop, const char *name, zprop_type_t type, +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) @@ -76,6 +76,8 @@ register_impl(int prop, const char *name, zprop_type_t type, 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; @@ -89,40 +91,44 @@ register_impl(int prop, const char *name, zprop_type_t type, 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++; } void -register_string(int prop, const char *name, const char *def, +zprop_register_string(int prop, const char *name, const char *def, zprop_attr_t attr, int objset_types, const char *values, const char *colname) { - register_impl(prop, name, PROP_TYPE_STRING, 0, def, attr, + zprop_register_impl(prop, name, PROP_TYPE_STRING, 0, def, attr, objset_types, values, colname, B_FALSE, B_TRUE, NULL); } void -register_number(int prop, const char *name, uint64_t def, zprop_attr_t attr, - int objset_types, const char *values, const char *colname) +zprop_register_number(int prop, const char *name, uint64_t def, + zprop_attr_t attr, int objset_types, const char *values, + const char *colname) { - register_impl(prop, name, PROP_TYPE_NUMBER, def, NULL, attr, + zprop_register_impl(prop, name, PROP_TYPE_NUMBER, def, NULL, attr, objset_types, values, colname, B_TRUE, B_TRUE, NULL); } void -register_index(int prop, const char *name, uint64_t def, zprop_attr_t attr, - int objset_types, const char *values, const char *colname, - const zprop_index_t *idx_tbl) +zprop_register_index(int prop, const char *name, uint64_t def, + zprop_attr_t attr, int objset_types, const char *values, + const char *colname, const zprop_index_t *idx_tbl) { - register_impl(prop, name, PROP_TYPE_INDEX, def, NULL, attr, + zprop_register_impl(prop, name, PROP_TYPE_INDEX, def, NULL, attr, objset_types, values, colname, B_TRUE, B_TRUE, idx_tbl); } void -register_hidden(int prop, const char *name, zprop_type_t type, +zprop_register_hidden(int prop, const char *name, zprop_type_t type, zprop_attr_t attr, int objset_types, const char *colname) { - register_impl(prop, name, type, 0, NULL, attr, + zprop_register_impl(prop, name, type, 0, NULL, attr, objset_types, NULL, colname, B_FALSE, B_FALSE, NULL); } @@ -156,7 +162,7 @@ int zprop_iter_common(zprop_func func, void *cb, boolean_t show_all, boolean_t ordered, zfs_type_t type) { - int i, num_props, size, prop; + int i, j, num_props, size, prop; zprop_desc_t *prop_tbl; zprop_desc_t **order; @@ -171,7 +177,7 @@ zprop_iter_common(zprop_func func, void *cb, boolean_t show_all, return (ZPROP_CONT); #endif - for (int j = 0; j < num_props; j++) + for (j = 0; j < num_props; j++) order[j] = &prop_tbl[j]; if (ordered) { @@ -307,6 +313,25 @@ zprop_index_to_string(int prop, uint64_t index, const char **string, return (-1); } +/* + * 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); +} + const char * zprop_values(int prop, zfs_type_t type) {