96 |
97 |
97 node->zn_handle = zhp; |
98 node->zn_handle = zhp; |
98 uu_avl_node_init(node, &node->zn_avlnode, avl_pool); |
99 uu_avl_node_init(node, &node->zn_avlnode, avl_pool); |
99 if (uu_avl_find(cb->cb_avl, node, cb->cb_sortcol, |
100 if (uu_avl_find(cb->cb_avl, node, cb->cb_sortcol, |
100 &idx) == NULL) { |
101 &idx) == NULL) { |
101 if (cb->cb_proplist && |
102 |
102 zfs_expand_proplist(zhp, cb->cb_proplist) != 0) { |
103 if (cb->cb_proplist) { |
103 free(node); |
104 if ((*cb->cb_proplist) && |
104 return (-1); |
105 !(*cb->cb_proplist)->pl_all) |
|
106 zfs_prune_proplist(zhp, |
|
107 cb->cb_props_table); |
|
108 |
|
109 if (zfs_expand_proplist(zhp, cb->cb_proplist) |
|
110 != 0) { |
|
111 free(node); |
|
112 return (-1); |
|
113 } |
105 } |
114 } |
|
115 |
106 uu_avl_insert(cb->cb_avl, node, idx); |
116 uu_avl_insert(cb->cb_avl, node, idx); |
107 dontclose = 1; |
117 dontclose = 1; |
108 } else { |
118 } else { |
109 free(node); |
119 free(node); |
110 } |
120 } |
326 int |
336 int |
327 zfs_for_each(int argc, char **argv, int flags, zfs_type_t types, |
337 zfs_for_each(int argc, char **argv, int flags, zfs_type_t types, |
328 zfs_sort_column_t *sortcol, zprop_list_t **proplist, |
338 zfs_sort_column_t *sortcol, zprop_list_t **proplist, |
329 zfs_iter_f callback, void *data) |
339 zfs_iter_f callback, void *data) |
330 { |
340 { |
331 callback_data_t cb; |
341 callback_data_t cb = {0}; |
332 int ret = 0; |
342 int ret = 0; |
333 zfs_node_t *node; |
343 zfs_node_t *node; |
334 uu_avl_walk_t *walk; |
344 uu_avl_walk_t *walk; |
335 |
345 |
336 avl_pool = uu_avl_pool_create("zfs_pool", sizeof (zfs_node_t), |
346 avl_pool = uu_avl_pool_create("zfs_pool", sizeof (zfs_node_t), |
344 |
354 |
345 cb.cb_sortcol = sortcol; |
355 cb.cb_sortcol = sortcol; |
346 cb.cb_flags = flags; |
356 cb.cb_flags = flags; |
347 cb.cb_proplist = proplist; |
357 cb.cb_proplist = proplist; |
348 cb.cb_types = types; |
358 cb.cb_types = types; |
|
359 |
|
360 /* |
|
361 * If cb_proplist is provided then in the zfs_handles created we |
|
362 * retain only those properties listed in cb_proplist and sortcol. |
|
363 * The rest are pruned. So, the caller should make sure that no other |
|
364 * properties other than those listed in cb_proplist/sortcol are |
|
365 * accessed. |
|
366 * |
|
367 * If cb_proplist is NULL then we retain all the properties. |
|
368 */ |
|
369 if (cb.cb_proplist && *cb.cb_proplist) { |
|
370 zprop_list_t *p = *cb.cb_proplist; |
|
371 |
|
372 while (p) { |
|
373 if (p->pl_prop >= ZFS_PROP_TYPE && |
|
374 p->pl_prop < ZFS_NUM_PROPS) { |
|
375 cb.cb_props_table[p->pl_prop] = B_TRUE; |
|
376 } |
|
377 p = p->pl_next; |
|
378 } |
|
379 |
|
380 while (sortcol) { |
|
381 if (sortcol->sc_prop >= ZFS_PROP_TYPE && |
|
382 sortcol->sc_prop < ZFS_NUM_PROPS) { |
|
383 cb.cb_props_table[sortcol->sc_prop] = B_TRUE; |
|
384 } |
|
385 sortcol = sortcol->sc_next; |
|
386 } |
|
387 } else { |
|
388 (void) memset(cb.cb_props_table, B_TRUE, |
|
389 sizeof (cb.cb_props_table)); |
|
390 } |
|
391 |
349 if ((cb.cb_avl = uu_avl_create(avl_pool, NULL, UU_DEFAULT)) == NULL) { |
392 if ((cb.cb_avl = uu_avl_create(avl_pool, NULL, UU_DEFAULT)) == NULL) { |
350 (void) fprintf(stderr, |
393 (void) fprintf(stderr, |
351 gettext("internal error: out of memory\n")); |
394 gettext("internal error: out of memory\n")); |
352 exit(1); |
395 exit(1); |
353 } |
396 } |