prev_rsv = find_next_reservable_window(search_head, size, &start_block, group_end_block); if (prev_rsv == NULL) goto failed; reservable_space_start = start_block; 
ret = find_next_reservable_window(search_head, my_rsv, sb, start_block, group_end_block);  if (ret == -1) { if (!rsv_is_empty(&my_rsv->rsv_window)) rsv_window_remove(sb, my_rsv); spin_unlock(rsv_lock); return -1; }  
static int alloc_new_reservation(struct ext3_reserve_window_node *my_rsv,		int goal, struct super_block *sb,		unsigned int group, struct buffer_head *bitmap_bh){	struct ext3_reserve_window_node *search_head;	int group_first_block, group_end_block, start_block;	int first_free_block;	int reservable_space_start;	struct ext3_reserve_window_node *prev_rsv;	struct rb_root *fs_rsv_root = &EXT3_SB(sb)->s_rsv_window_root;	unsigned long size;	group_first_block = le32_to_cpu(EXT3_SB(sb)->s_es->s_first_data_block) +				group * EXT3_BLOCKS_PER_GROUP(sb);	group_end_block = group_first_block + EXT3_BLOCKS_PER_GROUP(sb) - 1;	if (goal < 0)		start_block = group_first_block;	else		start_block = goal + group_first_block;	size = my_rsv->rsv_goal_size;	if (!rsv_is_empty(&my_rsv->rsv_window)) {		/*		 * if the old reservation is cross group boundary		 * and if the goal is inside the old reservation window,		 * we will come here when we just failed to allocate from		 * the first part of the window. We still have another part		 * that belongs to the next group. In this case, there is no		 * point to discard our window and try to allocate a new one		 * in this group(which will fail). we should		 * keep the reservation window, just simply move on.		 *		 * Maybe we could shift the start block of the reservation		 * window to the first block of next group.		 */		if ((my_rsv->rsv_start <= group_end_block) &&				(my_rsv->rsv_end > group_end_block) &&				(start_block >= my_rsv->rsv_start))			return -1;		if ((my_rsv->rsv_alloc_hit >		     (my_rsv->rsv_end - my_rsv->rsv_start + 1) / 2)) {			/*			 * if we previously allocation hit ration is greater than half			 * we double the size of reservation window next time			 * otherwise keep the same			 */			size = size * 2;			if (size > EXT3_MAX_RESERVE_BLOCKS)				size = EXT3_MAX_RESERVE_BLOCKS;			my_rsv->rsv_goal_size= size;		}	}	/*	 * shift the search start to the window near the goal block	 */	search_head = search_reserve_window(fs_rsv_root, start_block);	/*	 * find_next_reservable_window() simply finds a reservable window	 * inside the given range(start_block, group_end_block).	 *	 * To make sure the reservation window has a free bit inside it, we	 * need to check the bitmap after we found a reservable window.	 */retry:	prev_rsv = find_next_reservable_window(search_head, size,						&start_block, group_end_block);	if (prev_rsv == NULL)		goto failed;	reservable_space_start = start_block;	/*	 * On success, find_next_reservable_window() returns the	 * reservation window where there is a reservable space after it.	 * Before we reserve this reservable space, we need	 * to make sure there is at least a free block inside this region.	 *	 * searching the first free bit on the block bitmap and copy of	 * last committed bitmap alternatively, until we found a allocatable	 * block. Search start from the start block of the reservable space	 * we just found.	 */	first_free_block = bitmap_search_next_usable_block(			reservable_space_start - group_first_block,			bitmap_bh, group_end_block - group_first_block + 1);	if (first_free_block < 0) {		/*		 * no free block left on the bitmap, no point		 * to reserve the space. return failed.		 */		goto failed;	}	start_block = first_free_block + group_first_block;	/*	 * check if the first free block is within the	 * free space we just found	 */	if ((start_block >= reservable_space_start) &&	  (start_block < reservable_space_start + size))		goto found_rsv_window;	/*	 * if the first free bit we found is out of the reservable space	 * this means there is no free block on the reservable space	 * we should continue search for next reservable space,	 * start from where the free block is,	 * we also shift the list head to where we stopped last time	 */	search_head = prev_rsv;	goto retry;found_rsv_window:	/*	 * great! the reservable space contains some free blocks.	 * if the search returns that we should add the new	 * window just next to where the old window, we don't 	 * need to remove the old window first then add it to the	 * same place, just update the new start and new end.	 */	if (my_rsv != prev_rsv)  {		if (!rsv_is_empty(&my_rsv->rsv_window))			rsv_window_remove(sb, my_rsv);	}	my_rsv->rsv_start = reservable_space_start;	my_rsv->rsv_end = my_rsv->rsv_start + size - 1;	my_rsv->rsv_alloc_hit = 0;	if (my_rsv != prev_rsv)  {		ext3_rsv_window_add(sb, my_rsv);	}	return 0;		/* succeed */failed:	/*	 * failed to find a new reservation window in the current	 * group, remove the current(stale) reservation window	 * if there is any	 */	if (!rsv_is_empty(&my_rsv->rsv_window))		rsv_window_remove(sb, my_rsv);	return -1;		/* failed */}
10457	/local/tlutelli/issta_data/temp/c/2005_temp/2005/10457/21fe3471c3aaa5c489c5d3a4d705291eb7511248/balloc.c/buggy/fs/ext3/balloc.c