FreeBSD/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/metaslab.c
/*
 * This is a helper function that can be used by the allocator to find
 * a suitable block to allocate. This will search the specified AVL
 * tree looking for a block that matches the specified criteria.
 */
This is a helper function that can be used by the allocator to find
a suitable block to allocate. This will search the specified AVL
tree looking for a block that matches the specified criteria.
This is a helper function that can be used by the allocator to find a suitable block to allocate . This will search the specified AVL tree looking for a block that matches the specified criteria .
static uint64_t
metaslab_block_picker(avl_tree_t *t, uint64_t *cursor, uint64_t size,
    uint64_t align)
{
	range_seg_t *rs, rsearch;
	avl_index_t where;
	rsearch.rs_start = *cursor;
	rsearch.rs_end = *cursor + size;
	rs = avl_find(t, &rsearch, &where);
	if (rs == NULL)
		rs = avl_nearest(t, where, AVL_AFTER);
	while (rs != NULL) {
		uint64_t offset = P2ROUNDUP(rs->rs_start, align);
		if (offset + size <= rs->rs_end) {
			*cursor = offset + size;
			return (offset);
		}
		rs = AVL_NEXT(t, rs);
	}
	if (*cursor == 0)
		return (-1ULL);
	*cursor = 0;
	return (metaslab_block_picker(t, cursor, size, align));
}
static uint64_t metaslab_block_picker ( avl_tree_t * t , uint64_t * cursor , uint64_t size , uint64_t align ) { range_seg_t * rs , rsearch ; avl_index_t where ; rsearch . rs_start = * cursor ; rsearch . rs_end = * cursor + size ; rs = avl_find ( t , & rsearch , & where ) ; if ( rs == NULL ) rs = avl_nearest ( t , where , AVL_AFTER ) ; while ( rs != NULL ) { uint64_t offset = P2ROUNDUP ( rs -> rs_start , align ) ; if ( offset + size <= rs -> rs_end ) { * cursor = offset + size ; return ( offset ) ; } rs = AVL_NEXT ( t , rs ) ; } if ( * cursor == 0 ) return ( -1ULL ) ; * cursor = 0 ; return ( metaslab_block_picker ( t , cursor , size , align ) ) ; }
This is a helper function that can be used by the allocator to find
 a suitable block to allocate.
This is a helper function that can be used by the allocator to find a suitable block to allocate .
/*
	 * If we know we've searched the whole map (*cursor == 0), give up.
	 * Otherwise, reset the cursor to the beginning and try again.
	 */