@@ -741,6 +741,35 @@ static struct btrfs_fs_devices *find_fsid_changing_metada_uuid(
return find_fsid(disk_super->fsid, disk_super->metadata_uuid);
}
+static struct btrfs_fs_devices *find_fsid_changing(
+ struct btrfs_super_block *disk_super)
+{
+ struct btrfs_fs_devices *fs_devices;
+
+ /*
+ * Handles the case where scanned device is part of an fs that had
+ * multiple successful changes of FSID but currently device didn't
+ * observe it.
+ * Since the scanned devices does not own the metadata_uuid feature,
+ * fsid and metadata_uuid of the changing devices must differ, and
+ * their metadata_uuid must be same as disk_super->fsid.
+ */
+ list_for_each_entry(fs_devices, &fs_uuids, fs_list) {
+ if (!fs_devices->fsid_change)
+ continue;
+ if (memcmp(fs_devices->fsid, fs_devices->metadata_uuid,
+ BTRFS_FSID_SIZE) != 0 &&
+ memcmp(fs_devices->metadata_uuid, disk_super->fsid,
+ BTRFS_FSID_SIZE) == 0)
+ return fs_devices;
+ }
+
+ /*
+ * Back to find newer fs_devices is changeing or some in same stage.
+ */
+ return find_fsid(disk_super->fsid, NULL);
+}
+
/*
* Add new device to list of registered devices
*
@@ -782,7 +811,7 @@ static noinline struct btrfs_device *device_list_add(const char *path,
} else if (has_metadata_uuid) {
fs_devices = find_fsid_changing_metada_uuid(disk_super);
} else {
- fs_devices = find_fsid(disk_super->fsid, NULL);
+ fs_devices = find_fsid_changing(disk_super);
}
if (!fs_devices) {