FreeBSD/cddl/contrib/opensolaris/cmd/zfs/zfs_iter.c
/*
 * Called for each dataset.  If the object is of an appropriate type,
 * add it to the avl tree and recurse over any children as necessary.
 */
Called for each dataset.  If the object is of an appropriate type,
add it to the avl tree and recurse over any children as necessary.
Called for each dataset . If the object is of an appropriate type add it to the avl tree and recurse over any children as necessary .
static int
zfs_callback(zfs_handle_t *zhp, void *data)
{
	callback_data_t *cb = data;
	boolean_t should_close = B_TRUE;
	boolean_t include_snaps = zfs_include_snapshots(zhp, cb);
	boolean_t include_bmarks = (cb->cb_types & ZFS_TYPE_BOOKMARK);
	if ((zfs_get_type(zhp) & cb->cb_types) ||
	    ((zfs_get_type(zhp) == ZFS_TYPE_SNAPSHOT) && include_snaps)) {
		uu_avl_index_t idx;
		zfs_node_t *node = safe_malloc(sizeof (zfs_node_t));
		node->zn_handle = zhp;
		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) {
				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,
				    (cb->cb_flags & ZFS_ITER_RECVD_PROPS),
				    (cb->cb_flags & ZFS_ITER_LITERAL_PROPS))
				    != 0) {
					free(node);
					return (-1);
				}
			}
			uu_avl_insert(cb->cb_avl, node, idx);
			should_close = B_FALSE;
		} else {
			free(node);
		}
	}
	if (cb->cb_flags & ZFS_ITER_RECURSE &&
	    ((cb->cb_flags & ZFS_ITER_DEPTH_LIMIT) == 0 ||
	    cb->cb_depth < cb->cb_depth_limit)) {
		cb->cb_depth++;
		if (zfs_get_type(zhp) == ZFS_TYPE_FILESYSTEM)
			(void) zfs_iter_filesystems(zhp, zfs_callback, data);
		if (((zfs_get_type(zhp) & (ZFS_TYPE_SNAPSHOT |
		    ZFS_TYPE_BOOKMARK)) == 0) && include_snaps)
			(void) zfs_iter_snapshots(zhp,
			    (cb->cb_flags & ZFS_ITER_SIMPLE) != 0, zfs_callback,
			    data);
		if (((zfs_get_type(zhp) & (ZFS_TYPE_SNAPSHOT |
		    ZFS_TYPE_BOOKMARK)) == 0) && include_bmarks)
			(void) zfs_iter_bookmarks(zhp, zfs_callback, data);
		cb->cb_depth--;
	}
	if (should_close)
		zfs_close(zhp);
	return (0);
}
static int zfs_callback ( zfs_handle_t * zhp , void * data ) { callback_data_t * cb = data ; boolean_t should_close = B_TRUE ; boolean_t include_snaps = zfs_include_snapshots ( zhp , cb ) ; boolean_t include_bmarks = ( cb -> cb_types & ZFS_TYPE_BOOKMARK ) ; if ( ( zfs_get_type ( zhp ) & cb -> cb_types ) || ( ( zfs_get_type ( zhp ) == ZFS_TYPE_SNAPSHOT ) && include_snaps ) ) { uu_avl_index_t idx ; zfs_node_t * node = safe_malloc ( sizeof ( zfs_node_t ) ) ; node -> zn_handle = zhp ; 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 ) { 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 , ( cb -> cb_flags & ZFS_ITER_RECVD_PROPS ) , ( cb -> cb_flags & ZFS_ITER_LITERAL_PROPS ) ) != 0 ) { free ( node ) ; return ( -1 ) ; } } uu_avl_insert ( cb -> cb_avl , node , idx ) ; should_close = B_FALSE ; } else { free ( node ) ; } } if ( cb -> cb_flags & ZFS_ITER_RECURSE && ( ( cb -> cb_flags & ZFS_ITER_DEPTH_LIMIT ) == 0 || cb -> cb_depth < cb -> cb_depth_limit ) ) { cb -> cb_depth ++ ; if ( zfs_get_type ( zhp ) == ZFS_TYPE_FILESYSTEM ) ( void ) zfs_iter_filesystems ( zhp , zfs_callback , data ) ; if ( ( ( zfs_get_type ( zhp ) & ( ZFS_TYPE_SNAPSHOT | ZFS_TYPE_BOOKMARK ) ) == 0 ) && include_snaps ) ( void ) zfs_iter_snapshots ( zhp , ( cb -> cb_flags & ZFS_ITER_SIMPLE ) != 0 , zfs_callback , data ) ; if ( ( ( zfs_get_type ( zhp ) & ( ZFS_TYPE_SNAPSHOT | ZFS_TYPE_BOOKMARK ) ) == 0 ) && include_bmarks ) ( void ) zfs_iter_bookmarks ( zhp , zfs_callback , data ) ; cb -> cb_depth -- ; } if ( should_close ) zfs_close ( zhp ) ; return ( 0 ) ; }
Called for each dataset.
Called for each dataset .
/*
	 * Recurse if necessary.
	 */