Merge tag 'for-5.11/drivers-2020-12-14' of git://git.kernel.dk/linux-block
[linux-2.6-microblaze.git] / fs / btrfs / extent-tree.c
index 0345f9d..56ea380 100644 (file)
@@ -2641,6 +2641,11 @@ static int __exclude_logged_extent(struct btrfs_fs_info *fs_info,
                BUG_ON(!btrfs_block_group_done(block_group));
                ret = btrfs_remove_free_space(block_group, start, num_bytes);
        } else {
+               /*
+                * We must wait for v1 caching to finish, otherwise we may not
+                * remove our space.
+                */
+               btrfs_wait_space_cache_v1_finished(block_group, caching_ctl);
                mutex_lock(&caching_ctl->mutex);
 
                if (start >= caching_ctl->progress) {
@@ -2708,31 +2713,6 @@ btrfs_inc_block_group_reservations(struct btrfs_block_group *bg)
        atomic_inc(&bg->reservations);
 }
 
-void btrfs_prepare_extent_commit(struct btrfs_fs_info *fs_info)
-{
-       struct btrfs_caching_control *next;
-       struct btrfs_caching_control *caching_ctl;
-       struct btrfs_block_group *cache;
-
-       down_write(&fs_info->commit_root_sem);
-
-       list_for_each_entry_safe(caching_ctl, next,
-                                &fs_info->caching_block_groups, list) {
-               cache = caching_ctl->block_group;
-               if (btrfs_block_group_done(cache)) {
-                       cache->last_byte_to_unpin = (u64)-1;
-                       list_del_init(&caching_ctl->list);
-                       btrfs_put_caching_control(caching_ctl);
-               } else {
-                       cache->last_byte_to_unpin = caching_ctl->progress;
-               }
-       }
-
-       up_write(&fs_info->commit_root_sem);
-
-       btrfs_update_global_block_rsv(fs_info);
-}
-
 /*
  * Returns the free cluster for the given space info and sets empty_cluster to
  * what it should be based on the mount options.
@@ -2794,11 +2774,13 @@ static int unpin_extent_range(struct btrfs_fs_info *fs_info,
                len = cache->start + cache->length - start;
                len = min(len, end + 1 - start);
 
+               down_read(&fs_info->commit_root_sem);
                if (start < cache->last_byte_to_unpin && return_free_space) {
                        u64 add_len = min(len, cache->last_byte_to_unpin - start);
 
                        btrfs_add_free_space(cache, start, add_len);
                }
+               up_read(&fs_info->commit_root_sem);
 
                start += len;
                total_unpinned += len;
@@ -4635,7 +4617,7 @@ btrfs_init_new_buffer(struct btrfs_trans_handle *trans, struct btrfs_root *root,
        struct btrfs_fs_info *fs_info = root->fs_info;
        struct extent_buffer *buf;
 
-       buf = btrfs_find_create_tree_block(fs_info, bytenr);
+       buf = btrfs_find_create_tree_block(fs_info, bytenr, owner, level);
        if (IS_ERR(buf))
                return buf;
 
@@ -4652,6 +4634,11 @@ btrfs_init_new_buffer(struct btrfs_trans_handle *trans, struct btrfs_root *root,
                return ERR_PTR(-EUCLEAN);
        }
 
+       /*
+        * This needs to stay, because we could allocate a freed block from an
+        * old tree into a new tree, so we need to make sure this new block is
+        * set to the appropriate level and owner.
+        */
        btrfs_set_buffer_lockdep_class(owner, buf, level);
        __btrfs_tree_lock(buf, nest);
        btrfs_clean_tree_block(buf);
@@ -4877,7 +4864,7 @@ static noinline void reada_walk_down(struct btrfs_trans_handle *trans,
                                continue;
                }
 reada:
-               readahead_tree_block(fs_info, bytenr);
+               btrfs_readahead_node_child(eb, slot);
                nread++;
        }
        wc->reada_slot = slot;
@@ -5036,12 +5023,10 @@ static noinline int do_walk_down(struct btrfs_trans_handle *trans,
 
        next = find_extent_buffer(fs_info, bytenr);
        if (!next) {
-               next = btrfs_find_create_tree_block(fs_info, bytenr);
+               next = btrfs_find_create_tree_block(fs_info, bytenr,
+                               root->root_key.objectid, level - 1);
                if (IS_ERR(next))
                        return PTR_ERR(next);
-
-               btrfs_set_buffer_lockdep_class(root->root_key.objectid, next,
-                                              level - 1);
                reada = 1;
        }
        btrfs_tree_lock(next);
@@ -5095,8 +5080,8 @@ static noinline int do_walk_down(struct btrfs_trans_handle *trans,
        if (!next) {
                if (reada && level == 1)
                        reada_walk_down(trans, root, wc, path);
-               next = read_tree_block(fs_info, bytenr, generation, level - 1,
-                                      &first_key);
+               next = read_tree_block(fs_info, bytenr, root->root_key.objectid,
+                                      generation, level - 1, &first_key);
                if (IS_ERR(next)) {
                        return PTR_ERR(next);
                } else if (!extent_buffer_uptodate(next)) {