]> git.baikalelectronics.ru Git - kernel.git/commit
Btrfs: avoid losing data raid profile when deleting a device
authorLiu Bo <bo.li.liu@oracle.com>
Wed, 15 Nov 2017 23:28:11 +0000 (16:28 -0700)
committerDavid Sterba <dsterba@suse.com>
Mon, 22 Jan 2018 15:08:20 +0000 (16:08 +0100)
commita8c9a0b15925c4f22068cbfc0d098357a64dffd8
tree29bcedd6216570a3f34d63dff6e93eee99a63b30
parent5e60de43557d00b3f2632f1d55cb08d21589d096
Btrfs: avoid losing data raid profile when deleting a device

We've avoided data losing raid profile when doing balance, but it
turns out that deleting a device could also result in the same
problem.

Say we have 3 disks, and they're created with '-d raid1' profile.

- We have chunk P (the only data chunk on the empty btrfs).

- Suppose that chunk P's two raid1 copies reside in disk A and disk B.

- Now, 'btrfs device remove disk B'
         btrfs_rm_device()
   -> btrfs_shrink_device()
      -> btrfs_relocate_chunk() #relocate any chunk on disk B
          to other places.

- Chunk P will be removed and a new chunk will be created to hold
  those data, but as chunk P is the only one holding raid1 profile,
  after it goes away, the new chunk will be created as single profile
  which is our default profile.

This fixes the problem by creating an empty data chunk before
relocating the data chunk.

Metadata/System chunk are supposed to have non-zero bytes all the time
so their raid profile is preserved.

Reported-by: James Alandt <James.Alandt@wdc.com>
Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/volumes.c