All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anand Jain <anand.jain@oracle.com>
To: linux-btrfs@vger.kernel.org
Cc: Anand Jain <anand.jain@oracle.com>
Subject: [PATCH v2 8/9] btrfs: consolidate uuid memcmp in btrfs_validate_super
Date: Wed, 24 May 2023 20:02:42 +0800	[thread overview]
Message-ID: <f6c697aa32c6bdb8478ec463433ce6a6ed3b8389.1684928629.git.anand.jain@oracle.com> (raw)
In-Reply-To: <cover.1684928629.git.anand.jain@oracle.com>

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>
---
v2: None.

 fs/btrfs/disk-io.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 6681e82900b0..d09f767c7bda 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -2392,6 +2392,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.
@@ -2404,14 +2412,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
-- 
2.38.1


  parent reply	other threads:[~2023-05-24 12:04 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-24 12:02 [PATCH v2 0/9] btrfs: metadata_uuid refactors part1 Anand Jain
2023-05-24 12:02 ` [PATCH v2 1/9] btrfs: reduce struct btrfs_fs_devices size relocate fsid_change Anand Jain
2023-05-24 20:05   ` David Sterba
2023-05-24 12:02 ` [PATCH v2 2/9] btrfs: streamline fsid checks in alloc_fs_devices Anand Jain
2023-05-24 12:02 ` [PATCH v2 3/9] btrfs: localise has_metadata_uuid check in alloc_fs_devices args Anand Jain
2023-05-24 12:02 ` [PATCH v2 4/9] btrfs: add comment about metadata_uuid in btrfs_fs_devices Anand Jain
2023-05-24 12:02 ` [PATCH v2 5/9] btrfs: simplify check_tree_block_fsid return arg to bool Anand Jain
2023-05-24 12:02 ` [PATCH v2 6/9] btrfs: refactor with match_fsid_fs_devices helper Anand Jain
2023-05-24 20:56   ` David Sterba
2023-05-24 12:02 ` [PATCH v2 7/9] btrfs: refactor with match_fsid_changed helper Anand Jain
2023-05-24 20:56   ` David Sterba
2023-05-24 12:02 ` Anand Jain [this message]
2023-05-24 12:02 ` [PATCH v2 9/9] btrfs: add and fix comments in btrfs_fs_devices Anand Jain
2023-05-24 20:57 ` [PATCH v2 0/9] btrfs: metadata_uuid refactors part1 David Sterba
2023-06-27 14:55 ` Guilherme G. Piccoli
2023-06-28  3:52   ` Anand Jain
2023-06-28 13:07     ` Guilherme G. Piccoli

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f6c697aa32c6bdb8478ec463433ce6a6ed3b8389.1684928629.git.anand.jain@oracle.com \
    --to=anand.jain@oracle.com \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.