Commit a3c54b0b authored by Anand Jain's avatar Anand Jain Committed by David Sterba

btrfs: simplify how changed fsid and metadata_uuid is checked

We often check if the metadata_uuid is not the same as fsid, and then we
check if the given fsid matches the metadata_uuid. This patch refactors
this logic into function match_fsid_changed and utilize it.
Signed-off-by: default avatarAnand Jain <anand.jain@oracle.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 1a898345
...@@ -457,6 +457,19 @@ static noinline struct btrfs_fs_devices *find_fsid( ...@@ -457,6 +457,19 @@ static noinline struct btrfs_fs_devices *find_fsid(
return NULL; return NULL;
} }
/*
* First check if the metadata_uuid is different from the fsid in the given
* fs_devices. Then check if the given fsid is the same as the metadata_uuid
* in the fs_devices. If it is, return true; otherwise, return false.
*/
static inline bool check_fsid_changed(const struct btrfs_fs_devices *fs_devices,
const u8 *fsid)
{
return memcmp(fs_devices->fsid, fs_devices->metadata_uuid,
BTRFS_FSID_SIZE) != 0 &&
memcmp(fs_devices->metadata_uuid, fsid, BTRFS_FSID_SIZE) == 0;
}
static struct btrfs_fs_devices *find_fsid_with_metadata_uuid( static struct btrfs_fs_devices *find_fsid_with_metadata_uuid(
struct btrfs_super_block *disk_super) struct btrfs_super_block *disk_super)
{ {
...@@ -485,13 +498,11 @@ static struct btrfs_fs_devices *find_fsid_with_metadata_uuid( ...@@ -485,13 +498,11 @@ static struct btrfs_fs_devices *find_fsid_with_metadata_uuid(
* CHANGING_FSID_V2 flag set. * CHANGING_FSID_V2 flag set.
*/ */
list_for_each_entry(fs_devices, &fs_uuids, fs_list) { list_for_each_entry(fs_devices, &fs_uuids, fs_list) {
if (fs_devices->fsid_change && if (!fs_devices->fsid_change)
memcmp(fs_devices->metadata_uuid, continue;
fs_devices->fsid, BTRFS_FSID_SIZE) != 0 &&
memcmp(disk_super->metadata_uuid, fs_devices->metadata_uuid, if (check_fsid_changed(fs_devices, disk_super->metadata_uuid))
BTRFS_FSID_SIZE) == 0) {
return fs_devices; return fs_devices;
}
} }
return find_fsid(disk_super->fsid, disk_super->metadata_uuid); return find_fsid(disk_super->fsid, disk_super->metadata_uuid);
...@@ -682,18 +693,16 @@ static struct btrfs_fs_devices *find_fsid_inprogress( ...@@ -682,18 +693,16 @@ static struct btrfs_fs_devices *find_fsid_inprogress(
struct btrfs_fs_devices *fs_devices; struct btrfs_fs_devices *fs_devices;
list_for_each_entry(fs_devices, &fs_uuids, fs_list) { list_for_each_entry(fs_devices, &fs_uuids, fs_list) {
if (memcmp(fs_devices->metadata_uuid, fs_devices->fsid, if (fs_devices->fsid_change)
BTRFS_FSID_SIZE) != 0 && continue;
memcmp(fs_devices->metadata_uuid, disk_super->fsid,
BTRFS_FSID_SIZE) == 0 && !fs_devices->fsid_change) { if (check_fsid_changed(fs_devices, disk_super->fsid))
return fs_devices; return fs_devices;
}
} }
return find_fsid(disk_super->fsid, NULL); return find_fsid(disk_super->fsid, NULL);
} }
static struct btrfs_fs_devices *find_fsid_changed( static struct btrfs_fs_devices *find_fsid_changed(
struct btrfs_super_block *disk_super) struct btrfs_super_block *disk_super)
{ {
...@@ -710,10 +719,7 @@ static struct btrfs_fs_devices *find_fsid_changed( ...@@ -710,10 +719,7 @@ static struct btrfs_fs_devices *find_fsid_changed(
*/ */
list_for_each_entry(fs_devices, &fs_uuids, fs_list) { list_for_each_entry(fs_devices, &fs_uuids, fs_list) {
/* Changed UUIDs */ /* Changed UUIDs */
if (memcmp(fs_devices->metadata_uuid, fs_devices->fsid, if (check_fsid_changed(fs_devices, disk_super->metadata_uuid) &&
BTRFS_FSID_SIZE) != 0 &&
memcmp(fs_devices->metadata_uuid, disk_super->metadata_uuid,
BTRFS_FSID_SIZE) == 0 &&
memcmp(fs_devices->fsid, disk_super->fsid, memcmp(fs_devices->fsid, disk_super->fsid,
BTRFS_FSID_SIZE) != 0) BTRFS_FSID_SIZE) != 0)
return fs_devices; return fs_devices;
...@@ -744,11 +750,10 @@ static struct btrfs_fs_devices *find_fsid_reverted_metadata( ...@@ -744,11 +750,10 @@ static struct btrfs_fs_devices *find_fsid_reverted_metadata(
* fs_devices equal to the FSID of the disk. * fs_devices equal to the FSID of the disk.
*/ */
list_for_each_entry(fs_devices, &fs_uuids, fs_list) { list_for_each_entry(fs_devices, &fs_uuids, fs_list) {
if (memcmp(fs_devices->fsid, fs_devices->metadata_uuid, if (!fs_devices->fsid_change)
BTRFS_FSID_SIZE) != 0 && continue;
memcmp(fs_devices->metadata_uuid, disk_super->fsid,
BTRFS_FSID_SIZE) == 0 && if (check_fsid_changed(fs_devices, disk_super->fsid))
fs_devices->fsid_change)
return fs_devices; return fs_devices;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment