diff mbox

[01/10] Btrfs: Fix the problem that the replace destroys the seed filesystem

Message ID 1406173035-29478-1-git-send-email-miaox@cn.fujitsu.com (mailing list archive)
State Accepted
Headers show

Commit Message

Miao Xie July 24, 2014, 3:37 a.m. UTC
The seed filesystem was destroyed by the device replace, the reproduce
method is:
 # mkfs.btrfs -f <dev0>
 # btrfstune -S 1 <dev0>
 # mount <dev0> <mnt>
 # btrfs device add <dev1> <mnt>
 # umount <mnt>
 # mount <dev1> <mnt>
 # btrfs replace start -f <dev0> <dev2> <mnt>
 # umount <mnt>
 # mount <dev0> <mnt>

It is because we erase the super block on the seed device. It is wrong,
we should not change anything on the seed device.

Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
---
 fs/btrfs/volumes.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

Comments

David Sterba July 24, 2014, 1:13 p.m. UTC | #1
On Thu, Jul 24, 2014 at 11:37:06AM +0800, Miao Xie wrote:
> The seed filesystem was destroyed by the device replace, the reproduce
> method is:
>  # mkfs.btrfs -f <dev0>
>  # btrfstune -S 1 <dev0>
>  # mount <dev0> <mnt>
>  # btrfs device add <dev1> <mnt>
>  # umount <mnt>
>  # mount <dev1> <mnt>
>  # btrfs replace start -f <dev0> <dev2> <mnt>
>  # umount <mnt>
>  # mount <dev0> <mnt>
> 
> It is because we erase the super block on the seed device. It is wrong,
> we should not change anything on the seed device.
> 
> Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>

Reviewed-by: David Sterba <dsterba@suse.cz>
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Anand Jain July 25, 2014, 7:56 a.m. UTC | #2
Thanks for nailing down most of the seed related bugs, scratching
  off few from my list.


On 07/24/2014 11:37 AM, Miao Xie wrote:
> The seed filesystem was destroyed by the device replace, the reproduce
> method is:
>   # mkfs.btrfs -f <dev0>
>   # btrfstune -S 1 <dev0>
>   # mount <dev0> <mnt>
>   # btrfs device add <dev1> <mnt>
>   # umount <mnt>
>   # mount <dev1> <mnt>
>   # btrfs replace start -f <dev0> <dev2> <mnt>
>   # umount <mnt>
>   # mount <dev0> <mnt>
>
> It is because we erase the super block on the seed device. It is wrong,
> we should not change anything on the seed device.

nice fix.

Reviewed-by: Anand Jain <anand.jain@oracle.com>

> Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
> ---
>   fs/btrfs/volumes.c | 8 ++++++--
>   1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
> index 2776070f..19188df 100644
> --- a/fs/btrfs/volumes.c
> +++ b/fs/btrfs/volumes.c
> @@ -1853,8 +1853,12 @@ void btrfs_rm_dev_replace_srcdev(struct btrfs_fs_info *fs_info,
>   	if (srcdev->bdev) {
>   		fs_info->fs_devices->open_devices--;
>
> -		/* zero out the old super */
> -		btrfs_scratch_superblock(srcdev);
> +		/*
> +		 * zero out the old super if it is not writable
> +		 * (e.g. seed device)
> +		 */
> +		if (srcdev->writeable)
> +			btrfs_scratch_superblock(srcdev);
>   	}
>
>   	call_rcu(&srcdev->rcu, free_device);
>
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 2776070f..19188df 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -1853,8 +1853,12 @@  void btrfs_rm_dev_replace_srcdev(struct btrfs_fs_info *fs_info,
 	if (srcdev->bdev) {
 		fs_info->fs_devices->open_devices--;
 
-		/* zero out the old super */
-		btrfs_scratch_superblock(srcdev);
+		/*
+		 * zero out the old super if it is not writable
+		 * (e.g. seed device)
+		 */
+		if (srcdev->writeable)
+			btrfs_scratch_superblock(srcdev);
 	}
 
 	call_rcu(&srcdev->rcu, free_device);