]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
Btrfs: fix race between balance recovery and root deletion
authorWang Shilong <wangsl.fnst@cn.fujitsu.com>
Thu, 26 Jun 2014 03:08:16 +0000 (11:08 +0800)
committerChris Mason <clm@fb.com>
Thu, 3 Jul 2014 14:04:04 +0000 (07:04 -0700)
Balance recovery is called when RW mounting or remounting from
RO to RW, it is called to finish roots merging.

When doing balance recovery, relocation root's corresponding
fs root(whose root refs is 0) might be destroyed by cleaner
thread, this will make btrfs fail to mount.

Fix this problem by holding @cleaner_mutex when doing balance
recovery.

Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
Signed-off-by: Chris Mason <clm@fb.com>
fs/btrfs/disk-io.c
fs/btrfs/super.c

index f00165de6fbf58b90408540a485fa0b1a5c656b4..08e65e9cf2aa97cb009249f5bf231d07e2c1f890 100644 (file)
@@ -2905,7 +2905,9 @@ retry_root_backup:
                if (ret)
                        goto fail_qgroup;
 
+               mutex_lock(&fs_info->cleaner_mutex);
                ret = btrfs_recover_relocation(tree_root);
+               mutex_unlock(&fs_info->cleaner_mutex);
                if (ret < 0) {
                        printk(KERN_WARNING
                               "BTRFS: failed to recover relocation\n");
index 4662d92a4b7386cf82c264a0474eca825f8e4f1e..b6ebde231de7c111f98fb292bbe245e21769ac27 100644 (file)
@@ -1467,7 +1467,9 @@ static int btrfs_remount(struct super_block *sb, int *flags, char *data)
                        goto restore;
 
                /* recover relocation */
+               mutex_lock(&fs_info->cleaner_mutex);
                ret = btrfs_recover_relocation(root);
+               mutex_unlock(&fs_info->cleaner_mutex);
                if (ret)
                        goto restore;