]> xenbits.xensource.com Git - people/pauldu/linux.git/commitdiff
btrfs: sipmlify uuid parameters of alloc_fs_devices()
authorAnand Jain <anand.jain@oracle.com>
Wed, 23 Aug 2023 14:52:13 +0000 (22:52 +0800)
committerDavid Sterba <dsterba@suse.com>
Thu, 12 Oct 2023 14:44:02 +0000 (16:44 +0200)
Among all the callers, only the device_list_add() function uses the
second argument of alloc_fs_devices(). It passes metadata_uuid when
available, otherwise, it passes NULL. And in turn, alloc_fs_devices()
is designed to copy either metadata_uuid or fsid into
fs_devices::metadata_uuid.

So remove the second argument in alloc_fs_devices(), and always copy the
fsid.  In the caller device_list_add() function, we will overwrite it
with metadata_uuid when it is available.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/disk-io.c
fs/btrfs/volumes.c

index 68f60d50e1fd0c2fc1a643cf9d44bdcb5ae36036..6404b17a5bdcc3cb9b359865ff4de733f4e66635 100644 (file)
@@ -318,9 +318,10 @@ static bool check_tree_block_fsid(struct extent_buffer *eb)
                           BTRFS_FSID_SIZE);
 
        /*
-        * alloc_fs_devices() copies the fsid into metadata_uuid if the
-        * metadata_uuid is unset in the superblock, including for a seed device.
-        * So, we can use fs_devices->metadata_uuid.
+        * alloc_fsid_devices() copies the fsid into fs_devices::metadata_uuid.
+        * This is then overwritten by metadata_uuid if it is present in the
+        * device_list_add(). The same true for a seed device as well. So use of
+        * fs_devices::metadata_uuid is appropriate here.
         */
        if (memcmp(fsid, fs_info->fs_devices->metadata_uuid, BTRFS_FSID_SIZE) == 0)
                return false;
index 5a5a8d488a7bcd042175ca7499bea3a3c7d84ff4..1325f76fbd5075ddd44eae76b61b8dbec382ff1e 100644 (file)
@@ -357,21 +357,19 @@ struct list_head * __attribute_const__ btrfs_get_fs_uuids(void)
 }
 
 /*
- * alloc_fs_devices - allocate struct btrfs_fs_devices
- * @fsid:              if not NULL, copy the UUID to fs_devices::fsid
- * @metadata_fsid:     if not NULL, copy the UUID to fs_devices::metadata_fsid
+ * Allocate new btrfs_fs_devices structure identified by a fsid.
+ *
+ * @fsid:    if not NULL, copy the UUID to fs_devices::fsid and to
+ *           fs_devices::metadata_fsid
  *
  * Return a pointer to a new struct btrfs_fs_devices on success, or ERR_PTR().
  * The returned struct is not linked onto any lists and can be destroyed with
  * kfree() right away.
  */
-static struct btrfs_fs_devices *alloc_fs_devices(const u8 *fsid,
-                                                const u8 *metadata_fsid)
+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);
@@ -385,8 +383,7 @@ static struct btrfs_fs_devices *alloc_fs_devices(const u8 *fsid,
 
        if (fsid) {
                memcpy(fs_devs->fsid, fsid, BTRFS_FSID_SIZE);
-               memcpy(fs_devs->metadata_uuid,
-                      metadata_fsid ?: fsid, BTRFS_FSID_SIZE);
+               memcpy(fs_devs->metadata_uuid, fsid, BTRFS_FSID_SIZE);
        }
 
        return fs_devs;
@@ -812,8 +809,11 @@ static noinline struct btrfs_device *device_list_add(const char *path,
 
 
        if (!fs_devices) {
-               fs_devices = alloc_fs_devices(disk_super->fsid,
-                               has_metadata_uuid ? disk_super->metadata_uuid : NULL);
+               fs_devices = alloc_fs_devices(disk_super->fsid);
+               if (has_metadata_uuid)
+                       memcpy(fs_devices->metadata_uuid,
+                              disk_super->metadata_uuid, BTRFS_FSID_SIZE);
+
                if (IS_ERR(fs_devices))
                        return ERR_CAST(fs_devices);
 
@@ -997,7 +997,7 @@ static struct btrfs_fs_devices *clone_fs_devices(struct btrfs_fs_devices *orig)
 
        lockdep_assert_held(&uuid_mutex);
 
-       fs_devices = alloc_fs_devices(orig->fsid, NULL);
+       fs_devices = alloc_fs_devices(orig->fsid);
        if (IS_ERR(fs_devices))
                return fs_devices;
 
@@ -2451,7 +2451,7 @@ static struct btrfs_fs_devices *btrfs_init_sprout(struct btrfs_fs_info *fs_info)
         * Private copy of the seed devices, anchored at
         * fs_info->fs_devices->seed_list
         */
-       seed_devices = alloc_fs_devices(NULL, NULL);
+       seed_devices = alloc_fs_devices(NULL);
        if (IS_ERR(seed_devices))
                return seed_devices;
 
@@ -6901,7 +6901,7 @@ static struct btrfs_fs_devices *open_seed_devices(struct btrfs_fs_info *fs_info,
                if (!btrfs_test_opt(fs_info, DEGRADED))
                        return ERR_PTR(-ENOENT);
 
-               fs_devices = alloc_fs_devices(fsid, NULL);
+               fs_devices = alloc_fs_devices(fsid);
                if (IS_ERR(fs_devices))
                        return fs_devices;