diff mbox series

[2/9] btrfs: streamline fsid checks in alloc_fs_devices

Message ID 5113dde5d6f756818885c39bc8ec6f5b8e45ae54.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
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(-)

Comments

Christoph Hellwig May 23, 2023, 4:30 p.m. UTC | #1
On Tue, May 23, 2023 at 06:03:16PM +0800, Anand Jain wrote:
> +	ASSERT(!(fsid == NULL && metadata_fsid != NULL));

The more readable way to write this would be;

	ASSERT(fsid || !metadata_fsid);

or just throw a 

	ASSERT(!metadata_fsid);

into the else branch of the if (fsid) check.

> +	if (fsid){

missing whitespace before the opening brace.
Anand Jain May 24, 2023, 8:45 a.m. UTC | #2
On 24/05/2023 00:30, Christoph Hellwig wrote:
> On Tue, May 23, 2023 at 06:03:16PM +0800, Anand Jain wrote:
>> +	ASSERT(!(fsid == NULL && metadata_fsid != NULL));
> 
> The more readable way to write this would be;
> 
> 	ASSERT(fsid || !metadata_fsid);
> 

  Yeah. This is better.

> or just throw a
> 
> 	ASSERT(!metadata_fsid);
> 
> into the else branch of the if (fsid) check.
> 
>> +	if (fsid){
> 
> missing whitespace before the opening brace.
> 

  Both fixed locally.

Thanks, Anand
diff mbox series

Patch

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;
 }