--- a/usr/src/cmd/zfs/zfs_iter.c Fri Feb 13 13:38:46 2009 +0800
+++ b/usr/src/cmd/zfs/zfs_iter.c Fri Feb 13 11:33:56 2009 +0530
@@ -19,7 +19,7 @@
* CDDL HEADER END
*/
/*
- * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -58,6 +58,7 @@
zfs_type_t cb_types;
zfs_sort_column_t *cb_sortcol;
zprop_list_t **cb_proplist;
+ uint8_t cb_props_table[ZFS_NUM_PROPS];
} callback_data_t;
uu_avl_pool_t *avl_pool;
@@ -98,11 +99,20 @@
uu_avl_node_init(node, &node->zn_avlnode, avl_pool);
if (uu_avl_find(cb->cb_avl, node, cb->cb_sortcol,
&idx) == NULL) {
- if (cb->cb_proplist &&
- zfs_expand_proplist(zhp, cb->cb_proplist) != 0) {
- free(node);
- return (-1);
+
+ if (cb->cb_proplist) {
+ if ((*cb->cb_proplist) &&
+ !(*cb->cb_proplist)->pl_all)
+ zfs_prune_proplist(zhp,
+ cb->cb_props_table);
+
+ if (zfs_expand_proplist(zhp, cb->cb_proplist)
+ != 0) {
+ free(node);
+ return (-1);
+ }
}
+
uu_avl_insert(cb->cb_avl, node, idx);
dontclose = 1;
} else {
@@ -328,7 +338,7 @@
zfs_sort_column_t *sortcol, zprop_list_t **proplist,
zfs_iter_f callback, void *data)
{
- callback_data_t cb;
+ callback_data_t cb = {0};
int ret = 0;
zfs_node_t *node;
uu_avl_walk_t *walk;
@@ -346,6 +356,39 @@
cb.cb_flags = flags;
cb.cb_proplist = proplist;
cb.cb_types = types;
+
+ /*
+ * If cb_proplist is provided then in the zfs_handles created we
+ * retain only those properties listed in cb_proplist and sortcol.
+ * The rest are pruned. So, the caller should make sure that no other
+ * properties other than those listed in cb_proplist/sortcol are
+ * accessed.
+ *
+ * If cb_proplist is NULL then we retain all the properties.
+ */
+ if (cb.cb_proplist && *cb.cb_proplist) {
+ zprop_list_t *p = *cb.cb_proplist;
+
+ while (p) {
+ if (p->pl_prop >= ZFS_PROP_TYPE &&
+ p->pl_prop < ZFS_NUM_PROPS) {
+ cb.cb_props_table[p->pl_prop] = B_TRUE;
+ }
+ p = p->pl_next;
+ }
+
+ while (sortcol) {
+ if (sortcol->sc_prop >= ZFS_PROP_TYPE &&
+ sortcol->sc_prop < ZFS_NUM_PROPS) {
+ cb.cb_props_table[sortcol->sc_prop] = B_TRUE;
+ }
+ sortcol = sortcol->sc_next;
+ }
+ } else {
+ (void) memset(cb.cb_props_table, B_TRUE,
+ sizeof (cb.cb_props_table));
+ }
+
if ((cb.cb_avl = uu_avl_create(avl_pool, NULL, UU_DEFAULT)) == NULL) {
(void) fprintf(stderr,
gettext("internal error: out of memory\n"));