diff mbox series

[8/9] btrfs: consolidate uuid memcmp in btrfs_validate_super

Message ID f76753ad3f140e24b41c9b6f4e245d720a76fa51.1684826247.git.anand.jain@oracle.com (mailing list archive)
State New, archived
Headers show
Series btrfs: metadata_uuid refactors part1 | expand

Commit Message

Anand Jain May 23, 2023, 10:03 a.m. UTC
There are three ways the fsid is validated in btrfs_validate_super():

First, it verifies that super_copy::fsid is the same as fs_devices::fsid.
Second, if the metadata_uuid flag is set, it verifies if
 super_copy::metadata_uuid and fs_devices::metadata_uuid are the same.
Third, a few lines below, often missed out, it verifies if dev_item::fsid
 is the same as fs_devices::metadata_uuid.

The function btrfs_validate_super() contains multiple if-statements with
memcmp() to check UUIDs. This patch consolidates them into a single
location.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 fs/btrfs/disk-io.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
diff mbox series

Patch

diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 5a3e92fedcde..85e75d84675f 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -2574,6 +2574,14 @@  int btrfs_validate_super(struct btrfs_fs_info *fs_info,
 		ret = -EINVAL;
 	}
 
+	if (memcmp(fs_info->fs_devices->metadata_uuid, sb->dev_item.fsid,
+		   BTRFS_FSID_SIZE) != 0) {
+		btrfs_err(fs_info,
+			"dev_item UUID does not match metadata fsid: %pU != %pU",
+			fs_info->fs_devices->metadata_uuid, sb->dev_item.fsid);
+		ret = -EINVAL;
+	}
+
 	/*
 	 * Artificial requirement for block-group-tree to force newer features
 	 * (free-space-tree, no-holes) so the test matrix is smaller.
@@ -2586,14 +2594,6 @@  int btrfs_validate_super(struct btrfs_fs_info *fs_info,
 		ret = -EINVAL;
 	}
 
-	if (memcmp(fs_info->fs_devices->metadata_uuid, sb->dev_item.fsid,
-		   BTRFS_FSID_SIZE) != 0) {
-		btrfs_err(fs_info,
-			"dev_item UUID does not match metadata fsid: %pU != %pU",
-			fs_info->fs_devices->metadata_uuid, sb->dev_item.fsid);
-		ret = -EINVAL;
-	}
-
 	/*
 	 * Hint to catch really bogus numbers, bitflips or so, more exact checks are
 	 * done later