OSDN Git Service

btrfs: free alien device after device add
authorAnand Jain <anand.jain@oracle.com>
Mon, 4 May 2020 18:58:26 +0000 (02:58 +0800)
committerDavid Sterba <dsterba@suse.com>
Mon, 25 May 2020 09:25:28 +0000 (11:25 +0200)
commit7f551d969037cc128eca60688d9c5a300d84e665
tree487f02e99c3811ebe19c4b3bf2d05604ec1866c5
parent998a0671961f66e9fad4990ed75f80ba3088c2f1
btrfs: free alien device after device add

When an old device has new fsid through 'btrfs device add -f <dev>' our
fs_devices list has an alien device in one of the fs_devices lists.

By having an alien device in fs_devices, we have two issues so far

1. missing device does not not show as missing in the userland

2. degraded mount will fail

Both issues are caused by the fact that there's an alien device in the
fs_devices list. (Alien means that it does not belong to the filesystem,
identified by fsid, or does not contain btrfs filesystem at all, eg. due
to overwrite).

A device can be scanned/added through the control device ioctls
SCAN_DEV, DEVICES_READY or by ADD_DEV.

And device coming through the control device is checked against the all
other devices in the lists, but this was not the case for ADD_DEV.

This patch fixes both issues above by removing the alien device.

CC: stable@vger.kernel.org # 5.4+
Signed-off-by: Anand Jain <anand.jain@oracle.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/volumes.c