Commit 65d41e98 authored by Josef Bacik's avatar Josef Bacik Committed by Greg Kroah-Hartman

btrfs: set max_extent_size properly

commit ad22cf6e upstream.

We can't use entry->bytes if our entry is a bitmap entry, we need to use
entry->max_extent_size in that case.  Fix up all the logic to make this
consistent.

CC: stable@vger.kernel.org # 4.4+
Signed-off-by: default avatarJosef Bacik <jbacik@fb.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 947a9b02
...@@ -1795,6 +1795,13 @@ static int search_bitmap(struct btrfs_free_space_ctl *ctl, ...@@ -1795,6 +1795,13 @@ static int search_bitmap(struct btrfs_free_space_ctl *ctl,
return -1; return -1;
} }
static inline u64 get_max_extent_size(struct btrfs_free_space *entry)
{
if (entry->bitmap)
return entry->max_extent_size;
return entry->bytes;
}
/* Cache the size of the max extent in bytes */ /* Cache the size of the max extent in bytes */
static struct btrfs_free_space * static struct btrfs_free_space *
find_free_space(struct btrfs_free_space_ctl *ctl, u64 *offset, u64 *bytes, find_free_space(struct btrfs_free_space_ctl *ctl, u64 *offset, u64 *bytes,
...@@ -1816,8 +1823,8 @@ find_free_space(struct btrfs_free_space_ctl *ctl, u64 *offset, u64 *bytes, ...@@ -1816,8 +1823,8 @@ find_free_space(struct btrfs_free_space_ctl *ctl, u64 *offset, u64 *bytes,
for (node = &entry->offset_index; node; node = rb_next(node)) { for (node = &entry->offset_index; node; node = rb_next(node)) {
entry = rb_entry(node, struct btrfs_free_space, offset_index); entry = rb_entry(node, struct btrfs_free_space, offset_index);
if (entry->bytes < *bytes) { if (entry->bytes < *bytes) {
if (entry->bytes > *max_extent_size) *max_extent_size = max(get_max_extent_size(entry),
*max_extent_size = entry->bytes; *max_extent_size);
continue; continue;
} }
...@@ -1835,8 +1842,8 @@ find_free_space(struct btrfs_free_space_ctl *ctl, u64 *offset, u64 *bytes, ...@@ -1835,8 +1842,8 @@ find_free_space(struct btrfs_free_space_ctl *ctl, u64 *offset, u64 *bytes,
} }
if (entry->bytes < *bytes + align_off) { if (entry->bytes < *bytes + align_off) {
if (entry->bytes > *max_extent_size) *max_extent_size = max(get_max_extent_size(entry),
*max_extent_size = entry->bytes; *max_extent_size);
continue; continue;
} }
...@@ -1848,8 +1855,10 @@ find_free_space(struct btrfs_free_space_ctl *ctl, u64 *offset, u64 *bytes, ...@@ -1848,8 +1855,10 @@ find_free_space(struct btrfs_free_space_ctl *ctl, u64 *offset, u64 *bytes,
*offset = tmp; *offset = tmp;
*bytes = size; *bytes = size;
return entry; return entry;
} else if (size > *max_extent_size) { } else {
*max_extent_size = size; *max_extent_size =
max(get_max_extent_size(entry),
*max_extent_size);
} }
continue; continue;
} }
...@@ -2709,8 +2718,8 @@ static u64 btrfs_alloc_from_bitmap(struct btrfs_block_group_cache *block_group, ...@@ -2709,8 +2718,8 @@ static u64 btrfs_alloc_from_bitmap(struct btrfs_block_group_cache *block_group,
err = search_bitmap(ctl, entry, &search_start, &search_bytes, true); err = search_bitmap(ctl, entry, &search_start, &search_bytes, true);
if (err) { if (err) {
if (search_bytes > *max_extent_size) *max_extent_size = max(get_max_extent_size(entry),
*max_extent_size = search_bytes; *max_extent_size);
return 0; return 0;
} }
...@@ -2747,8 +2756,9 @@ u64 btrfs_alloc_from_cluster(struct btrfs_block_group_cache *block_group, ...@@ -2747,8 +2756,9 @@ u64 btrfs_alloc_from_cluster(struct btrfs_block_group_cache *block_group,
entry = rb_entry(node, struct btrfs_free_space, offset_index); entry = rb_entry(node, struct btrfs_free_space, offset_index);
while (1) { while (1) {
if (entry->bytes < bytes && entry->bytes > *max_extent_size) if (entry->bytes < bytes)
*max_extent_size = entry->bytes; *max_extent_size = max(get_max_extent_size(entry),
*max_extent_size);
if (entry->bytes < bytes || if (entry->bytes < bytes ||
(!entry->bitmap && entry->offset < min_start)) { (!entry->bitmap && entry->offset < min_start)) {
......
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