Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 232984
b: refs/heads/master
c: f333adb
h: refs/heads/master
v: v3
  • Loading branch information
Li Zefan committed Jan 26, 2011
1 parent 26d4542 commit 8d20904
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 120d66eec0dcb966fbd03f743598b2ff2513436b
refs/heads/master: f333adb5d64bc1c4d6099072fc341c3c8f84e0cf
26 changes: 20 additions & 6 deletions trunk/fs/btrfs/free-space-cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -987,11 +987,18 @@ tree_search_offset(struct btrfs_block_group_cache *block_group,
return entry;
}

static void unlink_free_space(struct btrfs_block_group_cache *block_group,
struct btrfs_free_space *info)
static inline void
__unlink_free_space(struct btrfs_block_group_cache *block_group,
struct btrfs_free_space *info)
{
rb_erase(&info->offset_index, &block_group->free_space_offset);
block_group->free_extents--;
}

static void unlink_free_space(struct btrfs_block_group_cache *block_group,
struct btrfs_free_space *info)
{
__unlink_free_space(block_group, info);
block_group->free_space -= info->bytes;
}

Expand Down Expand Up @@ -1364,7 +1371,7 @@ static int insert_into_bitmap(struct btrfs_block_group_cache *block_group,
}

bool try_merge_free_space(struct btrfs_block_group_cache *block_group,
struct btrfs_free_space *info)
struct btrfs_free_space *info, bool update_stat)
{
struct btrfs_free_space *left_info;
struct btrfs_free_space *right_info;
Expand All @@ -1385,15 +1392,21 @@ bool try_merge_free_space(struct btrfs_block_group_cache *block_group,
left_info = tree_search_offset(block_group, offset - 1, 0, 0);

if (right_info && !right_info->bitmap) {
unlink_free_space(block_group, right_info);
if (update_stat)
unlink_free_space(block_group, right_info);
else
__unlink_free_space(block_group, right_info);
info->bytes += right_info->bytes;
kfree(right_info);
merged = true;
}

if (left_info && !left_info->bitmap &&
left_info->offset + left_info->bytes == offset) {
unlink_free_space(block_group, left_info);
if (update_stat)
unlink_free_space(block_group, left_info);
else
__unlink_free_space(block_group, left_info);
info->offset = left_info->offset;
info->bytes += left_info->bytes;
kfree(left_info);
Expand All @@ -1418,7 +1431,7 @@ int btrfs_add_free_space(struct btrfs_block_group_cache *block_group,

spin_lock(&block_group->tree_lock);

if (try_merge_free_space(block_group, info))
if (try_merge_free_space(block_group, info, true))
goto link;

/*
Expand Down Expand Up @@ -1636,6 +1649,7 @@ __btrfs_return_cluster_to_free_space(
node = rb_next(&entry->offset_index);
rb_erase(&entry->offset_index, &cluster->root);
BUG_ON(entry->bitmap);
try_merge_free_space(block_group, entry, false);
tree_insert_offset(&block_group->free_space_offset,
entry->offset, &entry->offset_index, 0);
}
Expand Down

0 comments on commit 8d20904

Please sign in to comment.