Commit 5f316481 authored by Wang Shilong's avatar Wang Shilong Committed by Chris Mason

Btrfs: fix race between balance recovery and root deletion

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: default avatarWang Shilong <wangsl.fnst@cn.fujitsu.com>
Signed-off-by: default avatarChris Mason <clm@fb.com>
parent 3cc79392
...@@ -2905,7 +2905,9 @@ int open_ctree(struct super_block *sb, ...@@ -2905,7 +2905,9 @@ int open_ctree(struct super_block *sb,
if (ret) if (ret)
goto fail_qgroup; goto fail_qgroup;
mutex_lock(&fs_info->cleaner_mutex);
ret = btrfs_recover_relocation(tree_root); ret = btrfs_recover_relocation(tree_root);
mutex_unlock(&fs_info->cleaner_mutex);
if (ret < 0) { if (ret < 0) {
printk(KERN_WARNING printk(KERN_WARNING
"BTRFS: failed to recover relocation\n"); "BTRFS: failed to recover relocation\n");
......
...@@ -1467,7 +1467,9 @@ static int btrfs_remount(struct super_block *sb, int *flags, char *data) ...@@ -1467,7 +1467,9 @@ static int btrfs_remount(struct super_block *sb, int *flags, char *data)
goto restore; goto restore;
/* recover relocation */ /* recover relocation */
mutex_lock(&fs_info->cleaner_mutex);
ret = btrfs_recover_relocation(root); ret = btrfs_recover_relocation(root);
mutex_unlock(&fs_info->cleaner_mutex);
if (ret) if (ret)
goto restore; goto restore;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment