]> git.hungrycats.org Git - linux/commitdiff
Revert "Btrfs: fix race between balance and unused block group deletion"
authorZygo Blaxell <zblaxell@serenity.furryterror.org>
Mon, 27 Jul 2015 17:18:52 +0000 (13:18 -0400)
committerZygo Blaxell <zblaxell@serenity.furryterror.org>
Mon, 27 Jul 2015 17:18:52 +0000 (13:18 -0400)
This reverts commit 05c4e0c613165564c12e07ca0adf08944d405ce4.

fs/btrfs/ctree.h
fs/btrfs/disk-io.c
fs/btrfs/extent-tree.c
fs/btrfs/volumes.c

index 14e915d13fbdfdb5bb5697526806db221f726149..6f364e1d8d3d1e9c08e246dbc1df443be49c33fd 100644 (file)
@@ -1780,7 +1780,6 @@ struct btrfs_fs_info {
        spinlock_t unused_bgs_lock;
        struct list_head unused_bgs;
        struct mutex unused_bg_unpin_mutex;
-       struct mutex delete_unused_bgs_mutex;
 
        /* For btrfs to record security options */
        struct security_mnt_opts security_opts;
index 404559a148f030e0a40729041913a32bb515eb06..5bcc56bfd83f0e0a2997eefd35e33fff38256326 100644 (file)
@@ -1774,6 +1774,7 @@ static int cleaner_kthread(void *arg)
                }
 
                btrfs_run_delayed_iputs(root);
+               btrfs_delete_unused_bgs(root->fs_info);
                again = btrfs_clean_one_deleted_snapshot(root);
                mutex_unlock(&root->fs_info->cleaner_mutex);
 
@@ -1782,16 +1783,6 @@ static int cleaner_kthread(void *arg)
                 * needn't do anything special here.
                 */
                btrfs_run_defrag_inodes(root->fs_info);
-
-               /*
-                * Acquires fs_info->delete_unused_bgs_mutex to avoid racing
-                * with relocation (btrfs_relocate_chunk) and relocation
-                * acquires fs_info->cleaner_mutex (btrfs_relocate_block_group)
-                * after acquiring fs_info->delete_unused_bgs_mutex. So we
-                * can't hold, nor need to, fs_info->cleaner_mutex when deleting
-                * unused block groups.
-                */
-               btrfs_delete_unused_bgs(root->fs_info);
 sleep:
                if (!try_to_freeze() && !again) {
                        set_current_state(TASK_INTERRUPTIBLE);
@@ -2527,7 +2518,6 @@ int open_ctree(struct super_block *sb,
        spin_lock_init(&fs_info->unused_bgs_lock);
        rwlock_init(&fs_info->tree_mod_log_lock);
        mutex_init(&fs_info->unused_bg_unpin_mutex);
-       mutex_init(&fs_info->delete_unused_bgs_mutex);
        mutex_init(&fs_info->reloc_mutex);
        mutex_init(&fs_info->delalloc_root_mutex);
        seqlock_init(&fs_info->profiles_lock);
index 5c0dcef24e6ffd117f1e052cc7757883fcf10155..0ec3acd14cbf5e1273f331231f09165710d80d91 100644 (file)
@@ -9931,8 +9931,6 @@ void btrfs_delete_unused_bgs(struct btrfs_fs_info *fs_info)
                }
                spin_unlock(&fs_info->unused_bgs_lock);
 
-               mutex_lock(&root->fs_info->delete_unused_bgs_mutex);
-
                /* Don't want to race with allocators so take the groups_sem */
                down_write(&space_info->groups_sem);
                spin_lock(&block_group->lock);
@@ -10027,7 +10025,6 @@ void btrfs_delete_unused_bgs(struct btrfs_fs_info *fs_info)
 end_trans:
                btrfs_end_transaction(trans, root);
 next:
-               mutex_unlock(&root->fs_info->delete_unused_bgs_mutex);
                btrfs_put_block_group(block_group);
                spin_lock(&fs_info->unused_bgs_lock);
        }
index 6b3a97a774a7390e38eff8d9923feccc6c4dcec4..174f5e1e00abfa533b1cb7483e44aae0f550e63a 100644 (file)
@@ -2678,20 +2678,6 @@ static int btrfs_relocate_chunk(struct btrfs_root *root,
        root = root->fs_info->chunk_root;
        extent_root = root->fs_info->extent_root;
 
-       /*
-        * Prevent races with automatic removal of unused block groups.
-        * After we relocate and before we remove the chunk with offset
-        * chunk_offset, automatic removal of the block group can kick in,
-        * resulting in a failure when calling btrfs_remove_chunk() below.
-        *
-        * Make sure to acquire this mutex before doing a tree search (dev
-        * or chunk trees) to find chunks. Otherwise the cleaner kthread might
-        * call btrfs_remove_chunk() (through btrfs_delete_unused_bgs()) after
-        * we release the path used to search the chunk/dev tree and before
-        * the current task acquires this mutex and calls us.
-        */
-       ASSERT(mutex_is_locked(&root->fs_info->delete_unused_bgs_mutex));
-
        ret = btrfs_can_relocate(extent_root, chunk_offset);
        if (ret)
                return -ENOSPC;
@@ -2740,18 +2726,13 @@ again:
        key.type = BTRFS_CHUNK_ITEM_KEY;
 
        while (1) {
-               mutex_lock(&root->fs_info->delete_unused_bgs_mutex);
                ret = btrfs_search_slot(NULL, chunk_root, &key, path, 0, 0);
-               if (ret < 0) {
-                       mutex_unlock(&root->fs_info->delete_unused_bgs_mutex);
+               if (ret < 0)
                        goto error;
-               }
                BUG_ON(ret == 0); /* Corruption */
 
                ret = btrfs_previous_item(chunk_root, path, key.objectid,
                                          key.type);
-               if (ret)
-                       mutex_unlock(&root->fs_info->delete_unused_bgs_mutex);
                if (ret < 0)
                        goto error;
                if (ret > 0)
@@ -2774,7 +2755,6 @@ again:
                        else
                                BUG_ON(ret);
                }
-               mutex_unlock(&root->fs_info->delete_unused_bgs_mutex);
 
                if (found_key.offset == 0)
                        break;
@@ -3231,12 +3211,9 @@ again:
                        goto error;
                }
 
-               mutex_lock(&fs_info->delete_unused_bgs_mutex);
                ret = btrfs_search_slot(NULL, chunk_root, &key, path, 0, 0);
-               if (ret < 0) {
-                       mutex_unlock(&fs_info->delete_unused_bgs_mutex);
+               if (ret < 0)
                        goto error;
-               }
 
                /*
                 * this shouldn't happen, it means the last relocate
@@ -3248,7 +3225,6 @@ again:
                ret = btrfs_previous_item(chunk_root, path, 0,
                                          BTRFS_CHUNK_ITEM_KEY);
                if (ret) {
-                       mutex_unlock(&fs_info->delete_unused_bgs_mutex);
                        ret = 0;
                        break;
                }
@@ -3257,10 +3233,8 @@ again:
                slot = path->slots[0];
                btrfs_item_key_to_cpu(leaf, &found_key, slot);
 
-               if (found_key.objectid != key.objectid) {
-                       mutex_unlock(&fs_info->delete_unused_bgs_mutex);
+               if (found_key.objectid != key.objectid)
                        break;
-               }
 
                chunk = btrfs_item_ptr(leaf, slot, struct btrfs_chunk);
 
@@ -3273,13 +3247,10 @@ again:
                ret = should_balance_chunk(chunk_root, leaf, chunk,
                                           found_key.offset);
                btrfs_release_path(path);
-               if (!ret) {
-                       mutex_unlock(&fs_info->delete_unused_bgs_mutex);
+               if (!ret)
                        goto loop;
-               }
 
                if (counting) {
-                       mutex_unlock(&fs_info->delete_unused_bgs_mutex);
                        spin_lock(&fs_info->balance_lock);
                        bctl->stat.expected++;
                        spin_unlock(&fs_info->balance_lock);
@@ -3289,7 +3260,6 @@ again:
                ret = btrfs_relocate_chunk(chunk_root,
                                           found_key.objectid,
                                           found_key.offset);
-               mutex_unlock(&fs_info->delete_unused_bgs_mutex);
                if (ret && ret != -ENOSPC)
                        goto error;
                if (ret == -ENOSPC) {
@@ -4028,16 +3998,11 @@ again:
        key.type = BTRFS_DEV_EXTENT_KEY;
 
        do {
-               mutex_lock(&root->fs_info->delete_unused_bgs_mutex);
                ret = btrfs_search_slot(NULL, root, &key, path, 0, 0);
-               if (ret < 0) {
-                       mutex_unlock(&root->fs_info->delete_unused_bgs_mutex);
+               if (ret < 0)
                        goto done;
-               }
 
                ret = btrfs_previous_item(root, path, 0, key.type);
-               if (ret)
-                       mutex_unlock(&root->fs_info->delete_unused_bgs_mutex);
                if (ret < 0)
                        goto done;
                if (ret) {
@@ -4051,7 +4016,6 @@ again:
                btrfs_item_key_to_cpu(l, &key, path->slots[0]);
 
                if (key.objectid != device->devid) {
-                       mutex_unlock(&root->fs_info->delete_unused_bgs_mutex);
                        btrfs_release_path(path);
                        break;
                }
@@ -4060,7 +4024,6 @@ again:
                length = btrfs_dev_extent_length(l, dev_extent);
 
                if (key.offset + length <= new_size) {
-                       mutex_unlock(&root->fs_info->delete_unused_bgs_mutex);
                        btrfs_release_path(path);
                        break;
                }
@@ -4070,7 +4033,6 @@ again:
                btrfs_release_path(path);
 
                ret = btrfs_relocate_chunk(root, chunk_objectid, chunk_offset);
-               mutex_unlock(&root->fs_info->delete_unused_bgs_mutex);
                if (ret && ret != -ENOSPC)
                        goto done;
                if (ret == -ENOSPC)