Cast 'zfs bad bloc' to ULL for x86
[zfs.git] / module / zcommon / zprop_common.c
index bd267e2..0a0af23 100644 (file)
  * CDDL HEADER END
  */
 /*
- * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
-#pragma ident  "%Z%%M% %I%     %E% SMI"
-
 /*
  * Common routines used by zfs and zpool property management.
  */
@@ -67,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)
@@ -78,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;
@@ -91,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);
 }
 
@@ -158,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;
 
@@ -167,13 +171,13 @@ zprop_iter_common(zprop_func func, void *cb, boolean_t show_all,
        size = num_props * sizeof (zprop_desc_t *);
 
 #if defined(_KERNEL)
-       order = kmem_alloc(size, KM_SLEEP);
+       order = kmem_alloc(size, KM_PUSHPAGE);
 #else
        if ((order = malloc(size)) == NULL)
                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) {
@@ -205,9 +209,6 @@ propname_match(const char *p, size_t len, zprop_desc_t *prop_entry)
 #ifndef _KERNEL
        const char *colname = prop_entry->pd_colname;
        int c;
-
-       if (colname == NULL)
-               return (B_FALSE);
 #endif
 
        if (len == strlen(propname) &&
@@ -215,7 +216,7 @@ propname_match(const char *p, size_t len, zprop_desc_t *prop_entry)
                return (B_TRUE);
 
 #ifndef _KERNEL
-       if (len != strlen(colname))
+       if (colname == NULL || len != strlen(colname))
                return (B_FALSE);
 
        for (c = 0; c < len; c++)
@@ -312,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)
 {
@@ -404,3 +424,21 @@ zprop_width(int prop, boolean_t *fixed, zfs_type_t type)
 }
 
 #endif
+
+#if defined(_KERNEL) && defined(HAVE_SPL)
+/* Common routines to initialize property tables */
+EXPORT_SYMBOL(zprop_register_impl);
+EXPORT_SYMBOL(zprop_register_string);
+EXPORT_SYMBOL(zprop_register_number);
+EXPORT_SYMBOL(zprop_register_index);
+EXPORT_SYMBOL(zprop_register_hidden);
+
+/* Common routines for zfs and zpool property management */
+EXPORT_SYMBOL(zprop_iter_common);
+EXPORT_SYMBOL(zprop_name_to_prop);
+EXPORT_SYMBOL(zprop_string_to_index);
+EXPORT_SYMBOL(zprop_index_to_string);
+EXPORT_SYMBOL(zprop_random_value);
+EXPORT_SYMBOL(zprop_values);
+EXPORT_SYMBOL(zprop_valid_for_type);
+#endif