]> git.hungrycats.org Git - linux/commitdiff
Btrfs: fill relocation block rsv after allocation
authorJosef Bacik <jbacik@fb.com>
Fri, 27 May 2016 17:08:26 +0000 (13:08 -0400)
committerZygo Blaxell <zblaxell@thirteen.furryterror.org>
Wed, 17 Aug 2016 02:10:00 +0000 (22:10 -0400)
Since we set the reloc control before we've reserved our space for relocation we
could race with a root being dirtied and not actually have space to do our init
reloc root.  So once we've allocated it and set it up go ahead and make our
reservation before setting the relocate control, that way anybody who tries to
do the reloc root init has space to use.  Thanks,

Signed-off-by: Josef Bacik <jbacik@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
(cherry picked from commit ac2fabac4211431b607b326c2233e73b81e86af2)

fs/btrfs/relocation.c

index 9d2fcac5fbe89aa3d44b3eb03665b37113ef656c..2fc8c26f055ad0f03ddec05f8bb61163235759ca 100644 (file)
@@ -3877,6 +3877,7 @@ static noinline_for_stack
 int prepare_to_relocate(struct reloc_control *rc)
 {
        struct btrfs_trans_handle *trans;
+       int ret;
 
        rc->block_rsv = btrfs_alloc_block_rsv(rc->extent_root,
                                              BTRFS_BLOCK_RSV_TEMP);
@@ -3891,6 +3892,11 @@ int prepare_to_relocate(struct reloc_control *rc)
        rc->reserved_bytes = 0;
        rc->block_rsv->size = rc->extent_root->nodesize *
                              RELOCATION_RESERVED_NODES;
+       ret = btrfs_block_rsv_refill(rc->extent_root,
+                                    rc->block_rsv, rc->block_rsv->size,
+                                    BTRFS_RESERVE_FLUSH_ALL);
+       if (ret)
+               return ret;
 
        rc->create_reloc_tree = 1;
        set_reloc_control(rc);