]> git.hungrycats.org Git - linux/commitdiff
Revert "Revert "btrfs: relocation: Delay reloc tree deletion after merge_reloc_roots""
authorZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Mon, 9 Dec 2019 01:43:26 +0000 (20:43 -0500)
committerZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Mon, 9 Dec 2019 01:43:26 +0000 (20:43 -0500)
This reverts commit d83a4f402698420e1b7ff30af2342534461cbeb4.

fs/btrfs/ctree.h
fs/btrfs/disk-io.c
fs/btrfs/relocation.c

index da0b1d802938bc4334385dbd5a409b3a45a5bac3..df83a3e92c69571f3d94997a2d593ea27692006e 100644 (file)
@@ -1335,6 +1335,14 @@ struct btrfs_root {
        struct list_head ordered_root;
        u64 nr_ordered_extents;
 
+       /*
+        * Not empty if this subvolume root has gone through tree block swap
+        * (relocation)
+        *
+        * Will be used by reloc_control::dirty_subvol_roots.
+        */
+       struct list_head reloc_dirty_list;
+
        /*
         * Number of currently running SEND ioctls to prevent
         * manipulation with the read-only status via SUBVOL_SETFLAGS
index 30331f6045fbbdd949c93338c4515de8d6e77969..d5a73f5cb0656d2ed2703d92c62ca4665b4bab43 100644 (file)
@@ -1183,6 +1183,7 @@ static void __setup_root(struct btrfs_root *root, struct btrfs_fs_info *fs_info,
        INIT_LIST_HEAD(&root->delalloc_root);
        INIT_LIST_HEAD(&root->ordered_extents);
        INIT_LIST_HEAD(&root->ordered_root);
+       INIT_LIST_HEAD(&root->reloc_dirty_list);
        INIT_LIST_HEAD(&root->logged_list[0]);
        INIT_LIST_HEAD(&root->logged_list[1]);
        spin_lock_init(&root->inode_lock);
index d07907c5d58851f8feb70087db30a6c6c3c4f0dc..efc1f36749d777bc2f728fdc12af7a57d28f34c3 100644 (file)
@@ -163,6 +163,8 @@ struct reloc_control {
        struct mapping_tree reloc_root_tree;
        /* list of reloc trees */
        struct list_head reloc_roots;
+       /* list of subvolume trees that get relocated */
+       struct list_head dirty_subvol_roots;
        /* size of metadata reservation for merging reloc trees */
        u64 merging_rsv_size;
        /* size of relocated tree nodes */
@@ -1468,15 +1470,17 @@ int btrfs_update_reloc_root(struct btrfs_trans_handle *trans,
        struct btrfs_root_item *root_item;
        int ret;
 
-       if (!root->reloc_root)
+       if (test_bit(BTRFS_ROOT_DEAD_RELOC_TREE, &root->state) ||
+           !root->reloc_root)
                goto out;
 
        reloc_root = root->reloc_root;
        root_item = &reloc_root->root_item;
 
+       /* root->reloc_root will stay until current relocation finished */
        if (fs_info->reloc_ctl->merge_reloc_tree &&
            btrfs_root_refs(root_item) == 0) {
-               root->reloc_root = NULL;
+               set_bit(BTRFS_ROOT_DEAD_RELOC_TREE, &root->state);
                __del_reloc_root(reloc_root);
        }
 
@@ -2126,6 +2130,58 @@ static int find_next_key(struct btrfs_path *path, int level,
        return 1;
 }
 
+/*
+ * Insert current subvolume into reloc_control::dirty_subvol_roots
+ */
+static void insert_dirty_subvol(struct btrfs_trans_handle *trans,
+                               struct reloc_control *rc,
+                               struct btrfs_root *root)
+{
+       struct btrfs_root *reloc_root = root->reloc_root;
+       struct btrfs_root_item *reloc_root_item;
+
+       /* @root must be a subvolume tree root with a valid reloc tree */
+       ASSERT(root->root_key.objectid != BTRFS_TREE_RELOC_OBJECTID);
+       ASSERT(reloc_root);
+
+       reloc_root_item = &reloc_root->root_item;
+       memset(&reloc_root_item->drop_progress, 0,
+               sizeof(reloc_root_item->drop_progress));
+       reloc_root_item->drop_level = 0;
+       btrfs_set_root_refs(reloc_root_item, 0);
+       btrfs_update_reloc_root(trans, root);
+
+       if (list_empty(&root->reloc_dirty_list)) {
+               btrfs_grab_fs_root(root);
+               list_add_tail(&root->reloc_dirty_list, &rc->dirty_subvol_roots);
+       }
+}
+
+static int clean_dirty_subvols(struct reloc_control *rc)
+{
+       struct btrfs_root *root;
+       struct btrfs_root *next;
+       int ret = 0;
+
+       list_for_each_entry_safe(root, next, &rc->dirty_subvol_roots,
+                                reloc_dirty_list) {
+               struct btrfs_root *reloc_root = root->reloc_root;
+
+               clear_bit(BTRFS_ROOT_DEAD_RELOC_TREE, &root->state);
+               list_del_init(&root->reloc_dirty_list);
+               root->reloc_root = NULL;
+               if (reloc_root) {
+                       int ret2;
+
+                       ret2 = btrfs_drop_snapshot(reloc_root, NULL, 0, 1);
+                       if (ret2 < 0 && !ret)
+                               ret = ret2;
+               }
+               btrfs_put_fs_root(root);
+       }
+       return ret;
+}
+
 /*
  * merge the relocated tree blocks in reloc tree with corresponding
  * fs tree.
@@ -2264,13 +2320,8 @@ static noinline_for_stack int merge_reloc_root(struct reloc_control *rc,
 out:
        btrfs_free_path(path);
 
-       if (err == 0) {
-               memset(&root_item->drop_progress, 0,
-                      sizeof(root_item->drop_progress));
-               root_item->drop_level = 0;
-               btrfs_set_root_refs(root_item, 0);
-               btrfs_update_reloc_root(trans, root);
-       }
+       if (err == 0)
+               insert_dirty_subvol(trans, rc, root);
 
        if (trans)
                btrfs_end_transaction_throttle(trans);
@@ -2415,14 +2466,6 @@ again:
                } else {
                        list_del_init(&reloc_root->root_list);
                }
-
-               ret = btrfs_drop_snapshot(reloc_root, rc->block_rsv, 0, 1);
-               if (ret < 0) {
-                       if (list_empty(&reloc_root->root_list))
-                               list_add_tail(&reloc_root->root_list,
-                                             &reloc_roots);
-                       goto out;
-               }
        }
 
        if (found) {
@@ -4110,6 +4153,9 @@ restart:
                goto out_free;
        }
        btrfs_commit_transaction(trans);
+       ret = clean_dirty_subvols(rc);
+       if (ret < 0 && !err)
+               err = ret;
 out_free:
        btrfs_free_block_rsv(fs_info, rc->block_rsv);
        btrfs_free_path(path);
@@ -4204,6 +4250,7 @@ static struct reloc_control *alloc_reloc_control(void)
                return NULL;
 
        INIT_LIST_HEAD(&rc->reloc_roots);
+       INIT_LIST_HEAD(&rc->dirty_subvol_roots);
        backref_cache_init(&rc->backref_cache);
        mapping_tree_init(&rc->reloc_root_tree);
        extent_io_tree_init(&rc->processed_blocks, NULL);
@@ -4525,6 +4572,10 @@ int btrfs_recover_relocation(struct btrfs_root *root)
                goto out_free;
        }
        err = btrfs_commit_transaction(trans);
+
+       ret = clean_dirty_subvols(rc);
+       if (ret < 0 && !err)
+               err = ret;
 out_free:
        kfree(rc);
 out: