btrfs: streamline fsid checks in alloc_fs_devices
authorAnand Jain <anand.jain@oracle.com>
Wed, 24 May 2023 12:02:36 +0000 (20:02 +0800)
committerDavid Sterba <dsterba@suse.com>
Mon, 19 Jun 2023 11:59:28 +0000 (13:59 +0200)
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>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/volumes.c

index 1a7620680f50d63c75d63441954e72c6cb9d1553..c98b45c350db915059a96e3bb89ef8745d1f49d8 100644 (file)
@@ -370,6 +370,8 @@ static struct btrfs_fs_devices *alloc_fs_devices(const u8 *fsid,
 {
        struct btrfs_fs_devices *fs_devs;
 
+       ASSERT(fsid || !metadata_fsid);
+
        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 ?: fsid, BTRFS_FSID_SIZE);
+       }
 
        return fs_devs;
 }