btrfs: use on-disk uuid for s_uuid in temp_fsid mounts

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>
This commit is contained in:
Anand Jain 2026-04-27 18:18:03 +08:00 committed by Johannes Thumshirn
parent 5d40d064db
commit df84f6c773

View 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);