ovl: brtfs' temp_fsid doesn't work with ovl index=on
Subsystems (3)
cover ovl: brtfs' temp_fsid doesn't work with ovl index=on
Hi everyone,
When using overlayfs with the mount option index=on, the first time a directory is used as upper dir, overlayfs stores in a xattr "overlay.origin" the UUID of the filesystem being used in the layers. If the upper dir is reused, overlayfs refuses to mount for a different filesystem, by comparing the UUID with what's stored at overlay.origin, and it fails with "failed to verify upper root origin" on dmesg. Remounting with the very same fs is supported and works fine.
However, btrfs mounts may have volatiles UUIDs. When mounting the exact same disk image with btrfs, a random UUID is assigned for the following disks each time they are mounted, stored at temp_fsid and used across the kernel as the disk UUID. btrfs filesystem show presents that. Calling statfs() however shows the original (and duplicated) UUID for all disks.
This feature doesn't work well with overlayfs with index=on, as when the image is mounted a second time, will get a different UUID and ovl will refuse to mount, breaking the user expectation that using the same image should work. A small script can be find in the end of this cover letter that illustrates this.
From this, I can think of some options:
- Use statfs() internally to always get the fsid, that is persistent. The patch here illustrates that approach, but doesn't fully implement it.
- Create a new sb op, called get_uuid() so the filesystem returns what's appropriated.
- Have a workaround in ovl for btrfs.
- Document this as unsupported, and userland needs to erase overlay.origin each time it wants to remount.
- If ovl detects that temp_fsid and index are being used at the same time, refuses to mount.
I'm not sure which one would be better here, so I would like to hear some ideas on this.
Thanks!
André
---
To reproduce:
mkdir -p dir1 dir2
fallocate -l 300m ./disk1.img
mkfs.btrfs -q -f ./disk1.img
# cloning the disks cp disk1.img disk2.img sudo mount -o loop ./disk1.img dir1 sudo mount -o loop ./disk2.img dir2
mkdir -p dir2/lower aux/upper aux/work
# this works sudo mount -t overlay -o lowerdir=dir2/lower,upperdir=aux/upper,workdir=aux/work,userxattr none dir2/lower
sudo umount dir2/lower
sudo umount dir2
sudo mount -o loop ./disk2.img dir2
# this doesn't works sudo mount -t overlay -o lowerdir=dir2/lower,upperdir=aux/upper,workdir=aux/work,userxattr none dir2/lower
André Almeida (1):
ovl: Use fsid as unique identifier for trusted origin
fs/overlayfs/copy_up.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
Signature · 1 line
2.51.0
RFC PATCH 1/1 ovl: Use fsid as unique identifier for trusted origin
Some filesystem have non-persistent UUIDs, that can change between mounting, even if the filesystem is not modified. To prevent false-positives when mounting overlayfs with index enabled, use the fsid reported from statfs that is persistent across mounts.
---
This patch is just for illustrative purposes and doesn't work.
--- fs/overlayfs/copy_up.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
fs/overlayfs/copy_up.c +7 -1
@@ -8,6 +8,7 @@#include <linux/fs.h> #include <linux/slab.h> #include <linux/file.h> +#include <linux/statfs.h> #include <linux/fileattr.h> #include <linux/splice.h> #include <linux/xattr.h>
@@ -421,9 +422,14 @@ struct ovl_fh *ovl_encode_real_fh(struct ovl_fs *ofs, struct inode *realinode,struct ovl_fh *fh;int fh_type, dwords;int buflen =MAX_HANDLE_SZ ; -uuid_t *uuid = &realinode->i_sb->s_uuid; +uuid_t uuid; +struct kstatfs ks;int err; +// RFC: dentry can't be NULL, uuid needs a type cast + realinode->i_sb->s_op->statfs (NULL , &ks); + uuid.b = ks.f_fsid; +/* Make sure the real fid stays 32bit aligned */ BUILD_BUG_ON (OVL_FH_FID_OFFSET %4 );BUILD_BUG_ON (MAX_HANDLE_SZ +OVL_FH_FID_OFFSET >255 );
Signature · 1 line
2.51.0
Re: [RFC PATCH 1/1] ovl: Use fsid as unique identifier for trusted origin
Quoted 4 lines · André Almeida
Some filesystem have non-persistent UUIDs, that can change between mounting, even if the filesystem is not modified. To prevent false-positives when mounting overlayfs with index enabled, use the fsid reported from statfs that is persistent across mounts.
Please fix btrfs to not change uuids, as that completely defeats the point of uuids.
Re: [RFC PATCH 1/1] ovl: Use fsid as unique identifier for trusted origin
Quoted 9 lines · Christoph Hellwig
Quoted 4 lines · André Almeida
Some filesystem have non-persistent UUIDs, that can change between mounting, even if the filesystem is not modified. To prevent false-positives when mounting overlayfs with index enabled, use the fsid reported from statfs that is persistent across mounts.
Please fix btrfs to not change uuids, as that completely defeats the point of uuids.
That is the temp-fsid feature from Anand, introduced by commit a5b8a5f9f835 ("btrfs: support cloned-device mount capability").
I'm not 100% sure if it's really that important to support mounting cloned devices in the first place, as LVM will reject activating any LVs if there is even conflicting VGs names, not to mention conflicting UUIDs.
If temp-fsid is causing problems with overlayfs, I'm happy to remove it, as this really looks like a niche that no one is asking.
Yes, mounting cloned devices can be useful for certain cases, but with metadata_uuid changing the uuid should not even take a second, or one can just unregister the previously scanned device.
I'd say we paid too much cost for a niche that is not worthy.
Thanks,
Qu
Re: [RFC PATCH 1/1] ovl: Use fsid as unique identifier for trusted origin
Quoted 14 lines · Qu Wenruo
Quoted 9 lines · Christoph Hellwig
Quoted 4 lines · André Almeida
Some filesystem have non-persistent UUIDs, that can change between mounting, even if the filesystem is not modified. To prevent false-positives when mounting overlayfs with index enabled, use the fsid reported from statfs that is persistent across mounts.
Please fix btrfs to not change uuids, as that completely defeats the point of uuids.
That is the temp-fsid feature from Anand, introduced by commit
a5b8a5f9f835("btrfs: support cloned-device mount capability").
Quoted 6 lines
I'm not 100% sure if it's really that important to support mounting cloned devices in the first place, as LVM will reject activating any LVs if there is even conflicting VGs names, not to mention conflicting UUIDs.
If temp-fsid is causing problems with overlayfs, I'm happy to remove it, as this really looks like a niche that no one is asking.
What do you mean no one asking? This was specifically asked for by Steam to do A/B root partition mounts for recovery. It is a niche use case but it has its users.
Re: [RFC PATCH 1/1] ovl: Use fsid as unique identifier for trusted origin
Quoted 17 lines · David Sterba
Quoted 16 lines · Qu Wenruo
Quoted 8 lines · Christoph Hellwig
Quoted 4 lines · André Almeida
Some filesystem have non-persistent UUIDs, that can change between mounting, even if the filesystem is not modified. To prevent false-positives when mounting overlayfs with index enabled, use the fsid reported from statfs that is persistent across mounts.
Please fix btrfs to not change uuids, as that completely defeats the point of uuids.
That is the temp-fsid feature from Anand, introduced by commit
a5b8a5f9f835("btrfs: support cloned-device mount capability").I'm not 100% sure if it's really that important to support mounting cloned devices in the first place, as LVM will reject activating any LVs if there is even conflicting VGs names, not to mention conflicting UUIDs.
Quoted 5 lines
Quoted 2 lines
If temp-fsid is causing problems with overlayfs, I'm happy to remove it, as this really looks like a niche that no one is asking.
What do you mean no one asking? This was specifically asked for by Steam to do A/B root partition mounts for recovery. It is a niche use case but it has its users.
That's right, I've come across the issue reported here while working with SteamOS partitions, so it's being used. The original thread for this feature has more information about the use case: https://lore.kernel.org/linux-btrfs/[email protected]/
Re: [RFC PATCH 1/1] ovl: Use fsid as unique identifier for trusted origin
In reply to Christoph HellwigQuoted 8 lines · Christoph Hellwig
Quoted 4 lines · André Almeida
Some filesystem have non-persistent UUIDs, that can change between mounting, even if the filesystem is not modified. To prevent false-positives when mounting overlayfs with index enabled, use the fsid reported from statfs that is persistent across mounts.
Please fix btrfs to not change uuids, as that completely defeats the point of uuids.
We needed cloned device mount support for an A/B testing use case, but changing the on-disk UUID defeats the purpose.
Right now, ext4 and Btrfs can mount identical devices, but XFS can't. How about extending this to the common VFS layer and adding a parameter to tell apart a cloned device from the same device accessed through multiple paths? I haven't looked into the details yet, but I can dig it further.
Re: [RFC PATCH 1/1] ovl: Use fsid as unique identifier for trusted origin
Quoted 9 lines · Anand Jain
We needed cloned device mount support for an A/B testing use case, but changing the on-disk UUID defeats the purpose.
Right now, ext4 and Btrfs can mount identical devices, but XFS can't. How about extending this to the common VFS layer and adding a parameter to tell apart a cloned device from the same device accessed through multiple paths? I haven't looked into the details yet, but I can dig it further.
If you clone a device you need to change the user visible uuid/fsid, and you need to do that explicitly to a known either saved or user controlled value. Assigning a random ID is highly dangerous as seen here.
Re: [RFC PATCH 1/1] ovl: Use fsid as unique identifier for trusted origin
In reply to Anand JainQuoted 8 lines · Anand Jain
Quoted 7 lines · Christoph Hellwig
Quoted 5 lines · André Almeida
Some filesystem have non-persistent UUIDs, that can change between mounting, even if the filesystem is not modified. To prevent false-positives when mounting overlayfs with index enabled, use the fsid reported from statfs that is persistent across mounts.
Quoted 8 lines
Quoted 2 lines
Please fix btrfs to not change uuids, as that completely defeats the point of uuids.
We needed cloned device mount support for an A/B testing use case, but changing the on-disk UUID defeats the purpose.
Right now, ext4 and Btrfs can mount identical devices, but XFS can't.
Absolutely not true.
XFS has been able to mount filesystems with duplicate UUIDs on Linux for almost 25 years. The "-o nouuid" mount option (introduced in 2001) to bypass the duplicate uuid checks done at mount time.
XFS tracks all mounted filesystem UUIDs largely to prevent multiple mounts of the same filesystem due to multipath storage presenting it via multiple different block devices.
The nouuid mount option was added back when enterprise storage arrays started supporting hardware level thinp and LUN clone/snapshot functionality. Adding "-o nouuid" allowed cloned LUNs to be mounted for for backup/recovery purposes whilst the main filesystem was still mounted and in active use.
Quoted 4 lines
How about extending this to the common
VFS layer and adding a parameter to tell apart a cloned device from the same device accessed through multiple paths?
Perhaps we should lift the XFS UUID tracking code to the VFS and intercept "-o nouuid" at the VFS to allow duplicates only when that mount option is set?
-Dave.
Signature · 2 lines
Dave Chinner [email protected]
Re: [RFC PATCH 1/1] ovl: Use fsid as unique identifier for trusted origin
Quoted 15 lines · Dave Chinner
Quoted 14 lines · Anand Jain
Quoted 9 lines · Christoph Hellwig
Quoted 5 lines · André Almeida
Some filesystem have non-persistent UUIDs, that can change between mounting, even if the filesystem is not modified. To prevent false-positives when mounting overlayfs with index enabled, use the fsid reported from statfs that is persistent across mounts.
Please fix btrfs to not change uuids, as that completely defeats the point of uuids.
We needed cloned device mount support for an A/B testing use case, but changing the on-disk UUID defeats the purpose.
Quoted 9 lines
Quoted 2 lines
Right now, ext4 and Btrfs can mount identical devices, but XFS can't.
Absolutely not true.
XFS has been able to mount filesystems with duplicate UUIDs on Linux for almost 25 years. The "-o nouuid" mount option (introduced in 2001) to bypass the duplicate uuid checks done at mount time.
Damn, I completely missed the nouuid XFS option. My bad!!
Quoted 9 lines
XFS tracks all mounted filesystem UUIDs largely to prevent multiple mounts of the same filesystem due to multipath storage presenting it via multiple different block devices.
Quoted 1 line
The nouuid mount option was added back when enterprise storage
arrays started supporting hardware level thinp and LUN clone/snapshot functionality. Adding "-o nouuid" allowed cloned LUNs to be mounted for for backup/recovery purposes whilst the main filesystem was still mounted and in active use.
Agree. Also, in some SAN error situations, the same device may disappear and reappear with a new maj:min.
Quoted 10 lines
Quoted 4 lines
How about extending this to the common
VFS layer and adding a parameter to tell apart a cloned device from the same device accessed through multiple paths?Perhaps we should lift the XFS UUID tracking code to the VFS and intercept "-o nouuid" at the VFS to allow duplicates only when that mount option is set?
-Dave.
It looks like XFS (with -o nouuid) and ext4 allow duplicate FSIDs to pass into VFS. We may be able to extend this to Btrfs, though there could be conflicts with fanotify? I'm not sure yet. we still need -o nouuid, to alert admins to handle cases where a device reappears with a new devt. I'm digging more.
Thanks, Anand
kernel test robot
build botRe: [RFC PATCH 1/1] ovl: Use fsid as unique identifier for trusted origin
In reply to André Almeidakernel test robot noticed the following build errors:
Hi André,
[This is a private test report for your RFC patch.] kernel test robot noticed the following build errors:
[auto build test ERROR on brauner-vfs/vfs.all]
[also build test ERROR on linus/master v6.18-rc1 next-20251014] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Andr-Almeida/ovl-Use-fsid-as-unique-identifier-for-trusted-origin/20251014-100119 base: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git vfs.all patch link: https://lore.kernel.org/r/20251014015707.129013-2-andrealmeid%40igalia.com patch subject: [RFC PATCH 1/1] ovl: Use fsid as unique identifier for trusted origin config: s390-randconfig-001-20251015 (https://download.01.org/0day-ci/archive/20251015/[email protected]/config) compiler: s390-linux-gcc (GCC) 12.5.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251015/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
fs/overlayfs/copy_up.c: In function 'ovl_encode_real_fh':
>> fs/overlayfs/copy_up.c:431:16: error: assignment to expression with array type
431 | uuid.b = ks.f_fsid;
| ^
>> fs/overlayfs/copy_up.c:470:31: error: invalid type argument of unary '*' (have 'uuid_t')
470 | fh->fb.uuid = *uuid;
| ^~~~~vim +431 fs/overlayfs/copy_up.c
418
419 struct ovl_fh *ovl_encode_real_fh(struct ovl_fs *ofs, struct inode *realinode,
420 bool is_upper)
421 {
422 struct ovl_fh *fh;
423 int fh_type, dwords;
424 int buflen = MAX_HANDLE_SZ;
425 uuid_t uuid;
426 struct kstatfs ks;
427 int err;
428
429 // RFC: dentry can't be NULL, uuid needs a type cast
430 realinode->i_sb->s_op->statfs(NULL, &ks);
> 431 uuid.b = ks.f_fsid; 432 433 /* Make sure the real fid stays 32bit aligned */ 434 BUILD_BUG_ON(OVL_FH_FID_OFFSET % 4); 435 BUILD_BUG_ON(MAX_HANDLE_SZ + OVL_FH_FID_OFFSET > 255); 436 437 fh = kzalloc(buflen + OVL_FH_FID_OFFSET, GFP_KERNEL); 438 if (!fh) 439 return ERR_PTR(-ENOMEM); 440 441 /* 442 * We encode a non-connectable file handle for non-dir, because we 443 * only need to find the lower inode number and we don't want to pay 444 * the price or reconnecting the dentry. 445 */ 446 dwords = buflen >> 2; 447 fh_type = exportfs_encode_inode_fh(realinode, (void *)fh->fb.fid, 448 &dwords, NULL, 0); 449 buflen = (dwords << 2); 450 451 err = -EIO; 452 if (fh_type < 0 || fh_type == FILEID_INVALID || 453 WARN_ON(buflen > MAX_HANDLE_SZ)) 454 goto out_err; 455 456 fh->fb.version = OVL_FH_VERSION; 457 fh->fb.magic = OVL_FH_MAGIC; 458 fh->fb.type = fh_type; 459 fh->fb.flags = OVL_FH_FLAG_CPU_ENDIAN; 460 /* 461 * When we will want to decode an overlay dentry from this handle 462 * and all layers are on the same fs, if we get a disconncted real 463 * dentry when we decode fid, the only way to tell if we should assign 464 * it to upperdentry or to lowerstack is by checking this flag. 465 */ 466 if (is_upper) 467 fh->fb.flags |= OVL_FH_FLAG_PATH_UPPER; 468 fh->fb.len = sizeof(fh->fb) + buflen; 469 if (ovl_origin_uuid(ofs)) > 470 fh->fb.uuid = *uuid;
471
472 return fh;
473
474 out_err:
475 kfree(fh);
476 return ERR_PTR(err);
477 }
478
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Amir Goldstein
maintainerRe: [RFC PATCH 1/1] ovl: Use fsid as unique identifier for trusted origin
In reply to André AlmeidaQuoted 28 lines · André Almeida
Some filesystem have non-persistent UUIDs, that can change between mounting, even if the filesystem is not modified. To prevent false-positives when mounting overlayfs with index enabled, use the fsid reported from statfs that is persistent across mounts.
Signed-off-by André Almeida <[email protected]>---
This patch is just for illustrative purposes and doesn't work.--- fs/overlayfs/copy_up.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)fs/overlayfs/copy_up.c +1
-0@@ -8,6 +8,7 @@#include <linux/fs.h> #include <linux/slab.h> #include <linux/file.h> +#include <linux/statfs.h> #include <linux/fileattr.h> #include <linux/splice.h> #include <linux/xattr.h> @@ -421,9 +422,14 @@ struct ovl_fh *ovl_encode_real_fh(struct ovl_fs *ofs, struct inode *realinode,struct ovl_fh *fh;int fh_type, dwords;
fs/overlayfs/copy_up.c struct ovl_fh *ovl_encode_real_fh(struct ovl_fs *ofs, struct inode *realinode, · line 432
Quoted 10 lines
fs/overlayfs/copy_up.c +6
-1int buflen =MAX_HANDLE_SZ ; -uuid_t *uuid = &realinode->i_sb->s_uuid; +uuid_t uuid; +struct kstatfs ks;int err; +// RFC: dentry can't be NULL, uuid needs a type cast + realinode->i_sb->s_op->statfs (NULL , &ks); + uuid.b = ks.f_fsid; +
Just wanted to add that from overlayfs POV, this is completely wrong, because there are many fs whose fsid is not persistent including the default fs that are used in many distros and the whole idea of the origin xattr value is that it needs to be a persistent descriptor of the lower layer directory.
Thanks,
Amir.
Quoted 9 lines · André Almeida
Hi everyone,
When using overlayfs with the mount option index=on, the first time a directory is used as upper dir, overlayfs stores in a xattr "overlay.origin" the UUID of the filesystem being used in the layers. If the upper dir is reused, overlayfs refuses to mount for a different filesystem, by comparing the UUID with what's stored at overlay.origin, and it fails with "failed to verify upper root origin" on dmesg. Remounting with the very same fs is supported and works fine.
Quoted 5 lines
However, btrfs mounts may have volatiles UUIDs. When mounting the exact same disk image with btrfs, a random UUID is assigned for the following disks each time they are mounted, stored at
temp_fsidand used across the kernel as the disk UUID.btrfs filesystem showpresents that. Callingstatfs()however shows the original (and duplicated) UUID for all disks.
Yep, that's the btrfs' hack to allowing mounting cloned devices (as long as they are all single-device only btrfs)
Although I'm not a huge fan for that, without that you can not even mount any cloned btrfs in the first place.
Quoted 8 lines
This feature doesn't work well with overlayfs with index=on, as when the image is mounted a second time, will get a different UUID and ovl will refuse to mount, breaking the user expectation that using the same image should work. A small script can be find in the end of this cover letter that illustrates this.
From this, I can think of some options:
Quoted 9 lines
- Use
statfs()internally to always get the fsid, that is persistent. The patch here illustrates that approach, but doesn't fully implement it.
- Create a new sb op, calledget_uuid()so the filesystem returns what's appropriated.
- Have a workaround in ovl for btrfs.
- Document this as unsupported, and userland needs to erase overlay.origin each time it wants to remount.
- If ovl detects thattemp_fsidand index are being used at the same time, refuses to mount.
Or, let btrfs to reject the cloned device in the first place.
Quoted 11 lines
I'm not sure which one would be better here, so I would like to hear some ideas on this.
Thanks!
André---
To reproduce:
Quoted 7 lines
mkdir -p dir1 dir2
fallocate -l 300m ./disk1.img
mkfs.btrfs -q -f ./disk1.img# cloning the disks cp disk1.img disk2.img
If you really want to use the same copied fs, at least you can usebtrfstune -m disk2.img to change it to a new metadata uuid (without re-writing all metadata).
Then everything should work.
Thanks,
Qu
Quoted 22 lines
sudo mount -o loop ./disk1.img dir1
sudo mount -o loop ./disk2.img dir2mkdir -p dir2/lower aux/upper aux/work
# this works sudo mount -t overlay -o lowerdir=dir2/lower,upperdir=aux/upper,workdir=aux/work,userxattr none dir2/lowersudo umount dir2/lower
sudo umount dir2sudo mount -o loop ./disk2.img dir2
# this doesn't works sudo mount -t overlay -o lowerdir=dir2/lower,upperdir=aux/upper,workdir=aux/work,userxattr none dir2/lowerAndré Almeida (1):
ovl: Use fsid as unique identifier for trusted originfs/overlayfs/copy_up.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
Quoted 32 lines · André Almeida
Hi everyone,
When using overlayfs with the mount option index=on, the first time a directory is used as upper dir, overlayfs stores in a xattr "overlay.origin" the UUID of the filesystem being used in the layers. If the upper dir is reused, overlayfs refuses to mount for a different filesystem, by comparing the UUID with what's stored at overlay.origin, and it fails with "failed to verify upper root origin" on dmesg. Remounting with the very same fs is supported and works fine.
However, btrfs mounts may have volatiles UUIDs. When mounting the exact same disk image with btrfs, a random UUID is assigned for the following disks each time they are mounted, stored at
temp_fsidand used across the kernel as the disk UUID.btrfs filesystem showpresents that. Callingstatfs()however shows the original (and duplicated) UUID for all disks.This feature doesn't work well with overlayfs with index=on, as when the image is mounted a second time, will get a different UUID and ovl will refuse to mount, breaking the user expectation that using the same image should work. A small script can be find in the end of this cover letter that illustrates this.
Quoted 1 line
From this, I can think of some options:
- Use
statfs()internally to always get the fsid, that is persistent. The patch here illustrates that approach, but doesn't fully implement it.
- Create a new sb op, calledget_uuid()so the filesystem returns what's appropriated.
- Have a workaround in ovl for btrfs.
- Document this as unsupported, and userland needs to erase overlay.origin each time it wants to remount.
- If ovl detects thattemp_fsidand index are being used at the same time, refuses to mount.
Quoted 2 lines
I'm not sure which one would be better here, so I would like to hear some ideas on this.
I haven't looked deeper if there's a workable solution, but the feature combination should be refused. I don't think this will affect many users.
Quoted 33 lines · David Sterba
Quoted 32 lines · André Almeida
Hi everyone,
When using overlayfs with the mount option index=on, the first time a directory is used as upper dir, overlayfs stores in a xattr "overlay.origin" the UUID of the filesystem being used in the layers. If the upper dir is reused, overlayfs refuses to mount for a different filesystem, by comparing the UUID with what's stored at overlay.origin, and it fails with "failed to verify upper root origin" on dmesg. Remounting with the very same fs is supported and works fine.
However, btrfs mounts may have volatiles UUIDs. When mounting the exact same disk image with btrfs, a random UUID is assigned for the following disks each time they are mounted, stored at
temp_fsidand used across the kernel as the disk UUID.btrfs filesystem showpresents that. Callingstatfs()however shows the original (and duplicated) UUID for all disks.This feature doesn't work well with overlayfs with index=on, as when the image is mounted a second time, will get a different UUID and ovl will refuse to mount, breaking the user expectation that using the same image should work. A small script can be find in the end of this cover letter that illustrates this.
Quoted 1 line
From this, I can think of some options:
- Use
statfs()internally to always get the fsid, that is persistent. The patch here illustrates that approach, but doesn't fully implement it.
- Create a new sb op, calledget_uuid()so the filesystem returns what's appropriated.
- Have a workaround in ovl for btrfs.
- Document this as unsupported, and userland needs to erase overlay.origin each time it wants to remount.
- If ovl detects thattemp_fsidand index are being used at the same time, refuses to mount.
Quoted 7 lines
Quoted 2 lines
I'm not sure which one would be better here, so I would like to hear some ideas on this.
I haven't looked deeper if there's a workable solution, but the feature combination should be refused. I don't think this will affect many users.
I believe the root problem is that we're not fully implementing the proper handling just like other single-device fses.
We do not use on-disk flags which means at least one fsid is registered into btrfs, thus we have to use different temp-fsid.
If fully single-device feature flag is properly implemented, we should be able to return the same uuid without extra hacks thus solve the problem.
Thanks,
Qu
Quoted 47 lines · Qu Wenruo
Quoted 36 lines · David Sterba
Quoted 35 lines · André Almeida
Hi everyone,
When using overlayfs with the mount option index=on, the first time a directory is used as upper dir, overlayfs stores in a xattr "overlay.origin" the UUID of the filesystem being used in the layers. If the upper dir is reused, overlayfs refuses to mount for a different filesystem, by comparing the UUID with what's stored at overlay.origin, and it fails with "failed to verify upper root origin" on dmesg. Remounting with the very same fs is supported and works fine.
However, btrfs mounts may have volatiles UUIDs. When mounting the exact same disk image with btrfs, a random UUID is assigned for the following disks each time they are mounted, stored at
temp_fsidand used across the kernel as the disk UUID.btrfs filesystem showpresents that. Callingstatfs()however shows the original (and duplicated) UUID for all disks.This feature doesn't work well with overlayfs with index=on, as when the image is mounted a second time, will get a different UUID and ovl will refuse to mount, breaking the user expectation that using the same image should work. A small script can be find in the end of this cover letter that illustrates this.
Quoted 1 line
From this, I can think of some options:
- Use
statfs()internally to always get the fsid, that is persistent. The patch
here illustrates that approach, but doesn't fully implement it.
- Create a new sb op, calledget_uuid()so the filesystem returns what's appropriated.
- Have a workaround in ovl for btrfs.
- Document this as unsupported, and userland needs to erase overlay.origin each
time it wants to remount.
- If ovl detects thattemp_fsidand index are being used at the same time,
refuses to mount.Quoted 7 lines
Quoted 2 lines
I'm not sure which one would be better here, so I would like to hear some ideas on this.
I haven't looked deeper if there's a workable solution, but the feature combination should be refused. I don't think this will affect many users.
Quoted 5 lines
I believe the root problem is that we're not fully implementing the proper handling just like other single-device fses.
We do not use on-disk flags which means at least one fsid is registered into btrfs, thus we have to use different temp-fsid.
If fully single-device feature flag is properly implemented, we should be able to return the same uuid without extra hacks thus solve the problem.
I had looked into this some time ago. Some libs, like libblkid, don't handle multi-device filesystems or cloned devices with temp FSIDs very well. I'm aware of it.
I've been making some progress on fixing those cases, but it's a bit extensive since we first need enough test coverage, and recent reappear-device inline with that.
Let's see how we can support use cases with identical devices (where changing the UUID isn't an option) and keep things compatible with systemd and library tools.
Quoted 59 lines · Anand Jain
Quoted 48 lines · Qu Wenruo
Quoted 37 lines · David Sterba
Quoted 36 lines · André Almeida
Hi everyone,
When using overlayfs with the mount option index=on, the first time a directory is used as upper dir, overlayfs stores in a xattr "overlay.origin" the UUID of the filesystem being used in the layers. If the upper dir is reused, overlayfs refuses to mount for a different filesystem, by comparing the UUID with what's stored at overlay.origin, and it fails with "failed to verify upper root origin" on dmesg. Remounting with the very same fs is supported and works fine.
However, btrfs mounts may have volatiles UUIDs. When mounting the exact same disk image with btrfs, a random UUID is assigned for the following disks each time they are mounted, stored at
temp_fsidand used across the kernel as the disk UUID.btrfs filesystem showpresents that. Callingstatfs()however shows the original (and duplicated) UUID for all disks.This feature doesn't work well with overlayfs with index=on, as when the image is mounted a second time, will get a different UUID and ovl will refuse to mount, breaking the user expectation that using the same image should work. A small script can be find in the end of this cover letter that illustrates this.
Quoted 1 line
From this, I can think of some options:
- Use
statfs()internally to always get the fsid, that is persistent. The patch
here illustrates that approach, but doesn't fully implement it.
- Create a new sb op, calledget_uuid()so the filesystem returns what's
appropriated.
- Have a workaround in ovl for btrfs.
- Document this as unsupported, and userland needs to erase overlay.origin each
time it wants to remount.
- If ovl detects thattemp_fsidand index are being used at the same time,
refuses to mount.Quoted 7 lines
Quoted 2 lines
I'm not sure which one would be better here, so I would like to hear some ideas on this.
I haven't looked deeper if there's a workable solution, but the feature combination should be refused. I don't think this will affect many users.
Quoted 5 lines
I believe the root problem is that we're not fully implementing the proper handling just like other single-device fses.
We do not use on-disk flags which means at least one fsid is registered into btrfs, thus we have to use different temp-fsid.
If fully single-device feature flag is properly implemented, we should be able to return the same uuid without extra hacks thus solve the problem.
I had looked into this some time ago. Some libs, like libblkid, don't handle multi-device filesystems or cloned devices with temp FSIDs very well. I'm aware of it.
Quoted 8 lines
I've been making some progress on fixing those cases, but it's a bit extensive since we first need enough test coverage, and recent reappear-device inline with that.
Let's see how we can support use cases with identical devices (where changing the UUID isn't an option) and keep things compatible with systemd and library tools.
My current idea is to introduce a new ro compat flag, so that mounting that device will not go through the fsid lookup procedure completely.
But go through the common get_tree_bdev() routine, which will check if the fs is already mounted using bdev holder. (And of course, no fsid recorded inside btrfs module)
This will make single device btrfs with that special flag to behave exactly like all the other filesystems.
Quoted 54 lines · André Almeida
Hi everyone,
When using overlayfs with the mount option index=on, the first time a directory is used as upper dir, overlayfs stores in a xattr "overlay.origin" the UUID of the filesystem being used in the layers. If the upper dir is reused, overlayfs refuses to mount for a different filesystem, by comparing the UUID with what's stored at overlay.origin, and it fails with "failed to verify upper root origin" on dmesg. Remounting with the very same fs is supported and works fine.
However, btrfs mounts may have volatiles UUIDs. When mounting the exact same disk image with btrfs, a random UUID is assigned for the following disks each time they are mounted, stored at
temp_fsidand used across the kernel as the disk UUID.btrfs filesystem showpresents that. Callingstatfs()however shows the original (and duplicated) UUID for all disks.This feature doesn't work well with overlayfs with index=on, as when the image is mounted a second time, will get a different UUID and ovl will refuse to mount, breaking the user expectation that using the same image should work. A small script can be find in the end of this cover letter that illustrates this.
From this, I can think of some options:
- Use
statfs()internally to always get the fsid, that is persistent. The patch here illustrates that approach, but doesn't fully implement it.
- Create a new sb op, calledget_uuid()so the filesystem returns what's appropriated.
- Have a workaround in ovl for btrfs.
- Document this as unsupported, and userland needs to erase overlay.origin each time it wants to remount.
- If ovl detects thattemp_fsidand index are being used at the same time, refuses to mount.I'm not sure which one would be better here, so I would like to hear some ideas on this.
Thanks!
André---
To reproduce:
mkdir -p dir1 dir2
fallocate -l 300m ./disk1.img
mkfs.btrfs -q -f ./disk1.img# cloning the disks cp disk1.img disk2.img sudo mount -o loop ./disk1.img dir1 sudo mount -o loop ./disk2.img dir2mkdir -p dir2/lower aux/upper aux/work
Quoted 7 lines
# this works sudo mount -t overlay -o lowerdir=dir2/lower,upperdir=aux/upper,workdir=aux/work,userxattr none dir2/lowersudo umount dir2/lower
sudo umount dir2sudo mount -o loop ./disk2.img dir2
At this point, Btrfs assigns a new temporary FSID, but without it, the test case fails.
Temp FSID support only came in with kernel v6.7, so wondering, how is this test supposed to work on older kernels?
Thanks, Anand
Quoted 10 lines
# this doesn't works sudo mount -t overlay -o lowerdir=dir2/lower,upperdir=aux/upper,workdir=aux/work,userxattr none dir2/lowerAndré Almeida (1):
ovl: Use fsid as unique identifier for trusted originfs/overlayfs/copy_up.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
Amir Goldstein
maintainerQuoted 21 lines · André Almeida
Hi everyone,
When using overlayfs with the mount option index=on, the first time a directory is used as upper dir, overlayfs stores in a xattr "overlay.origin" the UUID of the filesystem being used in the layers. If the upper dir is reused, overlayfs refuses to mount for a different filesystem, by comparing the UUID with what's stored at overlay.origin, and it fails with "failed to verify upper root origin" on dmesg. Remounting with the very same fs is supported and works fine.
However, btrfs mounts may have volatiles UUIDs. When mounting the exact same disk image with btrfs, a random UUID is assigned for the following disks each time they are mounted, stored at
temp_fsidand used across the kernel as the disk UUID.btrfs filesystem showpresents that. Callingstatfs()however shows the original (and duplicated) UUID for all disks.This feature doesn't work well with overlayfs with index=on, as when the image is mounted a second time, will get a different UUID and ovl will refuse to mount, breaking the user expectation that using the same image should work. A small script can be find in the end of this cover letter that illustrates this.
Quoted 6 lines
From this, I can think of some options:
- Use
statfs()internally to always get the fsid, that is persistent. The patch here illustrates that approach, but doesn't fully implement it.
- Create a new sb op, calledget_uuid()so the filesystem returns what's appropriated.
FWIW this operation already exists in export_operations. It is currently only used by pnfs and only implemented by xfs. I would nor object for overlayfs to use this method if implemented and fall back to copying uuid directly from s_uuid (better yet make it a vfs helper)
Note that commit8f720d9f892e0 xfs: publish UUID in struct super_block was done for a similar reason.
The xfs mount option nouuid is the poor man's solution for mounting cloned disk images.
Thanks,
Amir.
Quoted 4 lines · Amir Goldstein
FWIW this operation already exists in
export_operations. It is currently only used by pnfs and only implemented by xfs. I would nor object for overlayfs to use this method if implemented and fall back to copying uuid directly froms_uuid
The get_uuid export operation is specifically about an on-disk superblock that the pnfs client can match. Overloading it for in-core information would be very confusing and also problematic if it doesn't exist on-disk in this format. In retrospective it should be called get_disk_uuid or something similar.