Skip to content

Commit 0f0fbf1

Browse files
Li Zefanchrismason-xx
authored andcommitted
Btrfs: fix to search one more bitmap for cluster setup
Suppose there are two bitmaps [0, 256], [256, 512] and one extent [100, 120] in the free space cache, and we want to setup a cluster with offset=100, bytes=50. In this case, there will be only one bitmap [256, 512] in the temporary bitmaps list, and then setup_cluster_bitmap() won't search bitmap [0, 256]. The cause is, the list is constructed in setup_cluster_no_bitmap(), and only bitmaps with bitmap_entry->offset >= offset will be added into the list, and the very bitmap that convers offset has bitmap_entry->offset <= offset. Signed-off-by: Li Zefan <lizf@cn.fujitsu.com> Signed-off-by: Chris Mason <chris.mason@oracle.com>
1 parent 32240a9 commit 0f0fbf1

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

‎fs/btrfs/free-space-cache.c‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2453,10 +2453,22 @@ setup_cluster_bitmap(struct btrfs_block_group_cache *block_group,
24532453
struct btrfs_free_space *entry;
24542454
struct rb_node *node;
24552455
int ret = -ENOSPC;
2456+
u64 bitmap_offset = offset_to_bitmap(ctl, offset);
24562457

24572458
if (ctl->total_bitmaps == 0)
24582459
return -ENOSPC;
24592460

2461+
/*
2462+
* The bitmap that covers offset won't be in the list unless offset
2463+
* is just its start offset.
2464+
*/
2465+
entry = list_first_entry(bitmaps, struct btrfs_free_space, list);
2466+
if (entry->offset != bitmap_offset) {
2467+
entry = tree_search_offset(ctl, bitmap_offset, 1, 0);
2468+
if (entry && list_empty(&entry->list))
2469+
list_add(&entry->list, bitmaps);
2470+
}
2471+
24602472
/*
24612473
* First check our cached list of bitmaps and see if there is an entry
24622474
* here that will work.

0 commit comments

Comments
 (0)