Chapter 9: The Extended Filesystem Family
Compute start block
alloc_new_reservation
search_reserve_window
find_next_reservable_window
return
Old reservation window available Update settings
No further window? Return with error code
Retry next reservable space
Free block in reserve window? Yes
No
Figure 9-17: Code flow diagram foralloc_new_reservation.
First,alloc_new_reservationdetermines the block from which the search for a reservation window
starts.
fs/ext2/balloc.c
static int alloc_new_reservation(struct ext2_reserve_window_node *my_rsv,
ext2_grpblk_t grp_goal, struct super_block *sb,
unsigned int group, struct buffer_head *bitmap_bh)
{
struct ext2_reserve_window_node *search_head;
ext2_fsblk_t group_first_block, group_end_block, start_block;
ext2_grpblk_t first_free_block;
struct rb_root *fs_rsv_root = &EXT2_SB(sb)->s_rsv_window_root;
unsigned long size;
int ret;
group_first_block = ext2_group_first_block_no(sb, group);
group_end_block = group_first_block + (EXT2_BLOCKS_PER_GROUP(sb) - 1);
if (grp_goal < 0)
start_block = group_first_block;
else
start_block = grp_goal + group_first_block;
size = my_rsv->rsv_goal_size;
...
If the inode is already equipped with a reservation window, the allocation hit counter is evaluated and
the window resized accordingly:
fs/ext2/balloc.c
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,