diff options
Diffstat (limited to 'fs/btrfs/free-space-cache.c')
-rw-r--r-- | fs/btrfs/free-space-cache.c | 63 |
1 files changed, 26 insertions, 37 deletions
diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c index 181760f9d2ab..6e5b7e463698 100644 --- a/fs/btrfs/free-space-cache.c +++ b/fs/btrfs/free-space-cache.c | |||
@@ -351,6 +351,11 @@ static int io_ctl_prepare_pages(struct io_ctl *io_ctl, struct inode *inode, | |||
351 | } | 351 | } |
352 | } | 352 | } |
353 | 353 | ||
354 | for (i = 0; i < io_ctl->num_pages; i++) { | ||
355 | clear_page_dirty_for_io(io_ctl->pages[i]); | ||
356 | set_page_extent_mapped(io_ctl->pages[i]); | ||
357 | } | ||
358 | |||
354 | return 0; | 359 | return 0; |
355 | } | 360 | } |
356 | 361 | ||
@@ -1844,7 +1849,13 @@ again: | |||
1844 | info = tree_search_offset(ctl, offset_to_bitmap(ctl, offset), | 1849 | info = tree_search_offset(ctl, offset_to_bitmap(ctl, offset), |
1845 | 1, 0); | 1850 | 1, 0); |
1846 | if (!info) { | 1851 | if (!info) { |
1847 | WARN_ON(1); | 1852 | /* the tree logging code might be calling us before we |
1853 | * have fully loaded the free space rbtree for this | ||
1854 | * block group. So it is possible the entry won't | ||
1855 | * be in the rbtree yet at all. The caching code | ||
1856 | * will make sure not to put it in the rbtree if | ||
1857 | * the logging code has pinned it. | ||
1858 | */ | ||
1848 | goto out_lock; | 1859 | goto out_lock; |
1849 | } | 1860 | } |
1850 | } | 1861 | } |
@@ -2451,16 +2462,23 @@ setup_cluster_bitmap(struct btrfs_block_group_cache *block_group, | |||
2451 | { | 2462 | { |
2452 | struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; | 2463 | struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; |
2453 | struct btrfs_free_space *entry; | 2464 | struct btrfs_free_space *entry; |
2454 | struct rb_node *node; | ||
2455 | int ret = -ENOSPC; | 2465 | int ret = -ENOSPC; |
2466 | u64 bitmap_offset = offset_to_bitmap(ctl, offset); | ||
2456 | 2467 | ||
2457 | if (ctl->total_bitmaps == 0) | 2468 | if (ctl->total_bitmaps == 0) |
2458 | return -ENOSPC; | 2469 | return -ENOSPC; |
2459 | 2470 | ||
2460 | /* | 2471 | /* |
2461 | * First check our cached list of bitmaps and see if there is an entry | 2472 | * The bitmap that covers offset won't be in the list unless offset |
2462 | * here that will work. | 2473 | * is just its start offset. |
2463 | */ | 2474 | */ |
2475 | entry = list_first_entry(bitmaps, struct btrfs_free_space, list); | ||
2476 | if (entry->offset != bitmap_offset) { | ||
2477 | entry = tree_search_offset(ctl, bitmap_offset, 1, 0); | ||
2478 | if (entry && list_empty(&entry->list)) | ||
2479 | list_add(&entry->list, bitmaps); | ||
2480 | } | ||
2481 | |||
2464 | list_for_each_entry(entry, bitmaps, list) { | 2482 | list_for_each_entry(entry, bitmaps, list) { |
2465 | if (entry->bytes < min_bytes) | 2483 | if (entry->bytes < min_bytes) |
2466 | continue; | 2484 | continue; |
@@ -2471,38 +2489,10 @@ setup_cluster_bitmap(struct btrfs_block_group_cache *block_group, | |||
2471 | } | 2489 | } |
2472 | 2490 | ||
2473 | /* | 2491 | /* |
2474 | * If we do have entries on our list and we are here then we didn't find | 2492 | * The bitmaps list has all the bitmaps that record free space |
2475 | * anything, so go ahead and get the next entry after the last entry in | 2493 | * starting after offset, so no more search is required. |
2476 | * this list and start the search from there. | ||
2477 | */ | 2494 | */ |
2478 | if (!list_empty(bitmaps)) { | 2495 | return -ENOSPC; |
2479 | entry = list_entry(bitmaps->prev, struct btrfs_free_space, | ||
2480 | list); | ||
2481 | node = rb_next(&entry->offset_index); | ||
2482 | if (!node) | ||
2483 | return -ENOSPC; | ||
2484 | entry = rb_entry(node, struct btrfs_free_space, offset_index); | ||
2485 | goto search; | ||
2486 | } | ||
2487 | |||
2488 | entry = tree_search_offset(ctl, offset_to_bitmap(ctl, offset), 0, 1); | ||
2489 | if (!entry) | ||
2490 | return -ENOSPC; | ||
2491 | |||
2492 | search: | ||
2493 | node = &entry->offset_index; | ||
2494 | do { | ||
2495 | entry = rb_entry(node, struct btrfs_free_space, offset_index); | ||
2496 | node = rb_next(&entry->offset_index); | ||
2497 | if (!entry->bitmap) | ||
2498 | continue; | ||
2499 | if (entry->bytes < min_bytes) | ||
2500 | continue; | ||
2501 | ret = btrfs_bitmap_cluster(block_group, entry, cluster, offset, | ||
2502 | bytes, min_bytes); | ||
2503 | } while (ret && node); | ||
2504 | |||
2505 | return ret; | ||
2506 | } | 2496 | } |
2507 | 2497 | ||
2508 | /* | 2498 | /* |
@@ -2520,8 +2510,8 @@ int btrfs_find_space_cluster(struct btrfs_trans_handle *trans, | |||
2520 | u64 offset, u64 bytes, u64 empty_size) | 2510 | u64 offset, u64 bytes, u64 empty_size) |
2521 | { | 2511 | { |
2522 | struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; | 2512 | struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; |
2523 | struct list_head bitmaps; | ||
2524 | struct btrfs_free_space *entry, *tmp; | 2513 | struct btrfs_free_space *entry, *tmp; |
2514 | LIST_HEAD(bitmaps); | ||
2525 | u64 min_bytes; | 2515 | u64 min_bytes; |
2526 | int ret; | 2516 | int ret; |
2527 | 2517 | ||
@@ -2560,7 +2550,6 @@ int btrfs_find_space_cluster(struct btrfs_trans_handle *trans, | |||
2560 | goto out; | 2550 | goto out; |
2561 | } | 2551 | } |
2562 | 2552 | ||
2563 | INIT_LIST_HEAD(&bitmaps); | ||
2564 | ret = setup_cluster_no_bitmap(block_group, cluster, &bitmaps, offset, | 2553 | ret = setup_cluster_no_bitmap(block_group, cluster, &bitmaps, offset, |
2565 | bytes, min_bytes); | 2554 | bytes, min_bytes); |
2566 | if (ret) | 2555 | if (ret) |