]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
btrfs: use on-disk uuid for s_uuid in temp_fsid mounts
authorAnand Jain <asj@kernel.org>
Mon, 27 Apr 2026 10:18:03 +0000 (18:18 +0800)
committerJohannes Thumshirn <johannes.thumshirn@wdc.com>
Tue, 9 Jun 2026 16:22:45 +0000 (18:22 +0200)
When mounting a cloned filesystem with a temporary fsuuid (temp_fsid),
layered modules like overlayfs require a persistent identifier.

While internal in-memory fs_devices->fsid must remain unique to
the kernel module, let s_uuid carry the original on-disk UUID.

Signed-off-by: Anand Jain <asj@kernel.org>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/disk-io.c

index a6203bcf16e285140e15be6c2d6672a8ea1870e1..ec13eac2b3d7b10edf28c2dfd6dadd31dfd14785 100644 (file)
@@ -3529,7 +3529,16 @@ int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_device
        /* Update the values for the current filesystem. */
        sb->s_blocksize = sectorsize;
        sb->s_blocksize_bits = blksize_bits(sectorsize);
-       memcpy(&sb->s_uuid, fs_info->fs_devices->fsid, BTRFS_FSID_SIZE);
+       /*
+        * When temp_fsid is active, fs_devices->fsid is assigned a random UUID
+        * at mount. This inconsistent UUID causes issues for layered filesystems
+        * like OverlayFS. Since metadata_uuid may or may not be set, provide the
+        * on-disk UUID directly from the super_copy.
+        */
+       if (fs_info->fs_devices->temp_fsid)
+               memcpy(&sb->s_uuid, fs_info->super_copy->fsid, BTRFS_FSID_SIZE);
+       else
+               memcpy(&sb->s_uuid, fs_info->fs_devices->fsid, BTRFS_FSID_SIZE);
 
        mutex_lock(&fs_info->chunk_mutex);
        ret = btrfs_read_sys_array(fs_info);