Commit edf6e2d1 authored by Li Zefan's avatar Li Zefan

btrfs: Add helper function free_bitmap()

Remove some duplicated code.

This prepares for the next patch.
Reviewed-by: default avatarJosef Bacik <josef@redhat.com>
Signed-off-by: default avatarLi Zefan <lizf@cn.fujitsu.com>
parent 8eb2d829
...@@ -1175,6 +1175,16 @@ static void add_new_bitmap(struct btrfs_block_group_cache *block_group, ...@@ -1175,6 +1175,16 @@ static void add_new_bitmap(struct btrfs_block_group_cache *block_group,
recalculate_thresholds(block_group); recalculate_thresholds(block_group);
} }
static void free_bitmap(struct btrfs_block_group_cache *block_group,
struct btrfs_free_space *bitmap_info)
{
unlink_free_space(block_group, bitmap_info);
kfree(bitmap_info->bitmap);
kfree(bitmap_info);
block_group->total_bitmaps--;
recalculate_thresholds(block_group);
}
static noinline int remove_from_bitmap(struct btrfs_block_group_cache *block_group, static noinline int remove_from_bitmap(struct btrfs_block_group_cache *block_group,
struct btrfs_free_space *bitmap_info, struct btrfs_free_space *bitmap_info,
u64 *offset, u64 *bytes) u64 *offset, u64 *bytes)
...@@ -1215,13 +1225,8 @@ static noinline int remove_from_bitmap(struct btrfs_block_group_cache *block_gro ...@@ -1215,13 +1225,8 @@ static noinline int remove_from_bitmap(struct btrfs_block_group_cache *block_gro
if (*bytes) { if (*bytes) {
struct rb_node *next = rb_next(&bitmap_info->offset_index); struct rb_node *next = rb_next(&bitmap_info->offset_index);
if (!bitmap_info->bytes) { if (!bitmap_info->bytes)
unlink_free_space(block_group, bitmap_info); free_bitmap(block_group, bitmap_info);
kfree(bitmap_info->bitmap);
kfree(bitmap_info);
block_group->total_bitmaps--;
recalculate_thresholds(block_group);
}
/* /*
* no entry after this bitmap, but we still have bytes to * no entry after this bitmap, but we still have bytes to
...@@ -1254,13 +1259,8 @@ static noinline int remove_from_bitmap(struct btrfs_block_group_cache *block_gro ...@@ -1254,13 +1259,8 @@ static noinline int remove_from_bitmap(struct btrfs_block_group_cache *block_gro
return -EAGAIN; return -EAGAIN;
goto again; goto again;
} else if (!bitmap_info->bytes) { } else if (!bitmap_info->bytes)
unlink_free_space(block_group, bitmap_info); free_bitmap(block_group, bitmap_info);
kfree(bitmap_info->bitmap);
kfree(bitmap_info);
block_group->total_bitmaps--;
recalculate_thresholds(block_group);
}
return 0; return 0;
} }
...@@ -1689,13 +1689,8 @@ u64 btrfs_find_space_for_alloc(struct btrfs_block_group_cache *block_group, ...@@ -1689,13 +1689,8 @@ u64 btrfs_find_space_for_alloc(struct btrfs_block_group_cache *block_group,
ret = offset; ret = offset;
if (entry->bitmap) { if (entry->bitmap) {
bitmap_clear_bits(block_group, entry, offset, bytes); bitmap_clear_bits(block_group, entry, offset, bytes);
if (!entry->bytes) { if (!entry->bytes)
unlink_free_space(block_group, entry); free_bitmap(block_group, entry);
kfree(entry->bitmap);
kfree(entry);
block_group->total_bitmaps--;
recalculate_thresholds(block_group);
}
} else { } else {
unlink_free_space(block_group, entry); unlink_free_space(block_group, entry);
entry->offset += bytes; entry->offset += bytes;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment