Skip to content

Commit cc5de4e

Browse files
lorddoskiaskdave
authored andcommitted
btrfs: Handle final split-brain possibility during fsid change
This patch lands the last case which needs to be handled by the fsid change code. Namely, this is the case where a multidisk filesystem has already undergone at least one successful fsid change i.e all disks have the METADATA_UUID incompat bit and power failure occurs as another fsid change is in progress. When such an event occurs, disks could be split in 2 groups. One of the groups will have both METADATA_UUID and CHANGING_FSID_V2 flags set coupled with old fsid/metadata_uuid pairs. The other group of disks will have only METADATA_UUID bit set and their fsid will be different than the one in disks in the first group. Here we look at the following cases: a) A disk from the first group is scanned first, so fs_devices is created with stale fsid/metdata_uuid. Then when a disk from the second group is scanned it needs to first check whether there exists such an fs_devices that has fsid_change set to true (because it was created with a disk having the CHANGING_FSID_V2 flag), the metadata_uuid and fsid of the fs_devices will be different (since it was created by a disk which already has had at least 1 successful fsid change) and finally the metadata_uuid of the fs_devices will equal that of the currently scanned disk (because metadata_uuid never really changes). When the correct fs_devices is found the information from the scanned disk will replace the current one in fs_devices since the scanned disk will have higher generation number. b) A disk from the second group is scanned so fs_devices is created as usual with differing fsid/metdata_uid. Then when a disk from the first group is scanned the code detects that it has both CHANGING_FSID_V2 and METADATA_UUID flags set and will search for fs_devices that has differing metadata_uuid/fsid and whose metadata_uuid is the same as that of the scanned device. Signed-off-by: Nikolay Borisov <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 7a62d0f commit cc5de4e

File tree

1 file changed

+53
-11
lines changed

1 file changed

+53
-11
lines changed

fs/btrfs/volumes.c

Lines changed: 53 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,21 @@ static noinline struct btrfs_fs_devices *find_fsid(
405405
return fs_devices;
406406
}
407407
}
408+
/*
409+
* Handle scanned device having completed its fsid change but
410+
* belonging to a fs_devices that was created by a device that
411+
* has an outdated pair of fsid/metadata_uuid and
412+
* CHANGING_FSID_V2 flag set.
413+
*/
414+
list_for_each_entry(fs_devices, &fs_uuids, fs_list) {
415+
if (fs_devices->fsid_change &&
416+
memcmp(fs_devices->metadata_uuid,
417+
fs_devices->fsid, BTRFS_FSID_SIZE) != 0 &&
418+
memcmp(metadata_fsid, fs_devices->metadata_uuid,
419+
BTRFS_FSID_SIZE) == 0) {
420+
return fs_devices;
421+
}
422+
}
408423
}
409424

410425
/* Handle non-split brain cases */
@@ -814,6 +829,30 @@ static struct btrfs_fs_devices *find_fsid_inprogress(
814829
return NULL;
815830
}
816831

832+
833+
static struct btrfs_fs_devices *find_fsid_changed(
834+
struct btrfs_super_block *disk_super)
835+
{
836+
struct btrfs_fs_devices *fs_devices;
837+
838+
/*
839+
* Handles the case where scanned device is part of an fs that had
840+
* multiple successful changes of FSID but curently device didn't
841+
* observe it. Meaning our fsid will be different than theirs.
842+
*/
843+
list_for_each_entry(fs_devices, &fs_uuids, fs_list) {
844+
if (memcmp(fs_devices->metadata_uuid, fs_devices->fsid,
845+
BTRFS_FSID_SIZE) != 0 &&
846+
memcmp(fs_devices->metadata_uuid, disk_super->metadata_uuid,
847+
BTRFS_FSID_SIZE) == 0 &&
848+
memcmp(fs_devices->fsid, disk_super->fsid,
849+
BTRFS_FSID_SIZE) != 0) {
850+
return fs_devices;
851+
}
852+
}
853+
854+
return NULL;
855+
}
817856
/*
818857
* Add new device to list of registered devices
819858
*
@@ -835,17 +874,20 @@ static noinline struct btrfs_device *device_list_add(const char *path,
835874
bool fsid_change_in_progress = (btrfs_super_flags(disk_super) &
836875
BTRFS_SUPER_FLAG_CHANGING_FSID_V2);
837876

838-
if (fsid_change_in_progress && !has_metadata_uuid) {
839-
/*
840-
* When we have an image which has CHANGING_FSID_V2 set it might
841-
* belong to either a filesystem which has disks with completed
842-
* fsid change or it might belong to fs with no UUID changes in
843-
* effect, handle both.
844-
*/
845-
fs_devices = find_fsid_inprogress(disk_super);
846-
if (!fs_devices)
847-
fs_devices = find_fsid(disk_super->fsid, NULL);
848-
877+
if (fsid_change_in_progress) {
878+
if (!has_metadata_uuid) {
879+
/*
880+
* When we have an image which has CHANGING_FSID_V2 set
881+
* it might belong to either a filesystem which has
882+
* disks with completed fsid change or it might belong
883+
* to fs with no UUID changes in effect, handle both.
884+
*/
885+
fs_devices = find_fsid_inprogress(disk_super);
886+
if (!fs_devices)
887+
fs_devices = find_fsid(disk_super->fsid, NULL);
888+
} else {
889+
fs_devices = find_fsid_changed(disk_super);
890+
}
849891
} else if (has_metadata_uuid) {
850892
fs_devices = find_fsid(disk_super->fsid,
851893
disk_super->metadata_uuid);

0 commit comments

Comments
 (0)