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 2/9] btrfs: streamline fsid checks in alloc_fs_devices
Date: Tue, 23 May 2023 18:03:16 +0800	[thread overview]
Message-ID: <5113dde5d6f756818885c39bc8ec6f5b8e45ae54.1684826247.git.anand.jain@oracle.com> (raw)
In-Reply-To: <cover.1684826246.git.anand.jain@oracle.com>

We currently have redundant checks for the non-null value of fsid
simplify it.

And, no one is using alloc_fs_devices() with a NULL metadata_uuid
while fsid is not NULL, add an assert() to verify this condition.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 fs/btrfs/volumes.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 1a7620680f50..6f231e679667 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -370,6 +370,8 @@ static struct btrfs_fs_devices *alloc_fs_devices(const u8 *fsid,
 {
 	struct btrfs_fs_devices *fs_devs;
 
+	ASSERT(!(fsid == NULL && metadata_fsid != NULL));
+
 	fs_devs = kzalloc(sizeof(*fs_devs), GFP_KERNEL);
 	if (!fs_devs)
 		return ERR_PTR(-ENOMEM);
@@ -380,13 +382,12 @@ static struct btrfs_fs_devices *alloc_fs_devices(const u8 *fsid,
 	INIT_LIST_HEAD(&fs_devs->alloc_list);
 	INIT_LIST_HEAD(&fs_devs->fs_list);
 	INIT_LIST_HEAD(&fs_devs->seed_list);
-	if (fsid)
-		memcpy(fs_devs->fsid, fsid, BTRFS_FSID_SIZE);
 
-	if (metadata_fsid)
-		memcpy(fs_devs->metadata_uuid, metadata_fsid, BTRFS_FSID_SIZE);
-	else if (fsid)
-		memcpy(fs_devs->metadata_uuid, fsid, BTRFS_FSID_SIZE);
+	if (fsid){
+		memcpy(fs_devs->fsid, fsid, BTRFS_FSID_SIZE);
+		memcpy(fs_devs->metadata_uuid,
+		       metadata_fsid ? metadata_fsid : fsid, BTRFS_FSID_SIZE);
+	}
 
 	return fs_devs;
 }
-- 
2.39.2


  parent reply	other threads:[~2023-05-23 10:04 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-23 10:03 [PATCH 0/9] btrfs: metadata_uuid refactors part1 Anand Jain
2023-05-23 10:03 ` [PATCH 1/9] btrfs: reduce struct btrfs_fs_devices size relocate fsid_change Anand Jain
2023-05-23 16:27   ` Christoph Hellwig
2023-05-23 20:59     ` David Sterba
2023-05-24  5:56       ` Christoph Hellwig
2023-05-24 11:00         ` Anand Jain
2023-05-23 21:31   ` David Sterba
2023-05-24  5:15     ` Anand Jain
2023-05-23 10:03 ` Anand Jain [this message]
2023-05-23 16:30   ` [PATCH 2/9] btrfs: streamline fsid checks in alloc_fs_devices Christoph Hellwig
2023-05-24  8:45     ` Anand Jain
2023-05-23 10:03 ` [PATCH 3/9] btrfs: localise has_metadata_uuid check in alloc_fs_devices args Anand Jain
2023-05-23 10:03 ` [PATCH 4/9] btrfs: add comment about metadata_uuid in btrfs_fs_devices Anand Jain
2023-05-23 10:03 ` [PATCH 5/9] btrfs: simplify check_tree_block_fsid return arg to bool Anand Jain
2023-05-23 10:03 ` [PATCH 6/9] btrfs: refactor with memcmp_fsid_fs_devices helper Anand Jain
2023-05-23 21:23   ` David Sterba
2023-05-24  5:55     ` Anand Jain
2023-05-23 10:03 ` [PATCH 7/9] btrfs: refactor with memcmp_fsid_changed helper Anand Jain
2023-05-23 16:31   ` Christoph Hellwig
2023-05-23 10:03 ` [PATCH 8/9] btrfs: consolidate uuid memcmp in btrfs_validate_super Anand Jain
2023-05-23 10:03 ` [PATCH 9/9] btrfs: fix source code style in find_fsid Anand Jain
2023-05-23 21:29   ` David Sterba
2023-05-24  5:57     ` Anand Jain
2023-05-23 21:33 ` [PATCH 0/9] btrfs: metadata_uuid refactors part1 David Sterba

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=5113dde5d6f756818885c39bc8ec6f5b8e45ae54.1684826247.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.