Btrfs, XFS and ext4 currently handle s_uuid and f_fsid differently when
a filesystem is cloned (e.g. snapshot or block-level copy), leading to
inconsistent behaviour across filesystems.
The table below summarises the current and post-patch behaviour.
"same" means the value is identical on both the original and cloned
filesystem.
Cloned filesystem:
| s_uuid f_fsid
--------------|---------------------------
EXT4 | same same
Btrfs | random random
XFS | same f(devt)
EXT4-patched | same f(devt)
Btrfs-patched | same f(s_uuid,rootid,devt)
Problem
-------
Btrfs currently never duplicates s_uuid or f_fsid for cloned filesystems.
When an fsid collision is detected at mount time, btrfs generates a new
in-memory fsid (temp_fsid), but this is ephemeral — it changes on every
mount. This has two consequences:
1. IMA (Integrity Measurement Architecture) cannot reliably track the
filesystem across mount-cycle, since the f_fsid it sees keeps changing.
This does not scale. Whereas on the otherhand if you have same s_uuid
on multiple filesystems, monitoring per distint filesystem is lost.
2. If we instead allow cloned filesystems to share the same f_fsid (as
ext4 currently does), fanotify loses the ability to distinguish
between distinct filesystem instances. FAN_EVENT_INFO_TYPE_FID events
will fail to resolve to the correct mountpoint when f_fsid values
are identical across clones.
This series resolves the tradeoff by aligning btrfs and ext4 behaviour
with XFS: f_fsid incorporates device identity (devt) to remain unique
across clones, while s_uuid is preserved consistently matching the on-disk
uuid.
Patches
-------
Patch 1/3: btrfs: fix f_fsid to include rootid and devt
Patch 2/3: btrfs: fix s_uuid to be stable across mounts for cloned filesystems
Patch 3/3: ext4: fix f_fsid to use devt instead of s_uuid
Anand Jain (3):
btrfs: derive f_fsid from on-disk fsuuid and dev_t
btrfs: use on-disk uuid for s_uuid in temp_fsid mounts
ext4: derive f_fsid from block device to avoid collisions
fs/btrfs/disk-io.c | 3 ++-
fs/btrfs/super.c | 27 +++++++++++++++++++++++----
fs/ext4/super.c | 2 +-
3 files changed, 26 insertions(+), 6 deletions(-)
--
2.43.0
statfs() currently reports f_fsid derived from the on-disk UUID.
Cloned block devices share the same UUID, so distinct ext4 instances
can return identical f_fsid values. This leads to collisions in
fanotify.
Encode sb->s_dev into f_fsid instead of using the superblock UUID.
This provides a per-device identifier and avoids conflicts when
filesystem is cloned, matching the behavior with xfs.
Marking as RFC: it is unclear whether any usecase requires the f_fsid of
a cloned filesystem to be consistent with that of the source filesystem.
Signed-off-by: Anand Jain <asj@kernel.org>
---
fs/ext4/super.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
From: Christoph Hellwig <hch@infradead.org> Date: 2026-03-04 13:28:17
On Thu, Feb 26, 2026 at 10:23:32PM +0800, Anand Jain wrote:
This series resolves the tradeoff by aligning btrfs and ext4 behaviour
with XFS: f_fsid incorporates device identity (devt) to remain unique
across clones, while s_uuid is preserved consistently matching the on-disk
uuid.
While I like fixing this up, switching the f_fsid construction to a
different method might break things. Is there a way to only change
it for cloned file systems to reduce the surface of this change?
Patches
-------
Patch 1/3: btrfs: fix f_fsid to include rootid and devt
Patch 2/3: btrfs: fix s_uuid to be stable across mounts for cloned filesystems
Patch 3/3: ext4: fix f_fsid to use devt instead of s_uuid
I don't really see that patch 3 in my inbox on linux-btrfs.
On Thu, Feb 26, 2026 at 10:23:32PM +0800, Anand Jain wrote:
quoted
This series resolves the tradeoff by aligning btrfs and ext4 behaviour
with XFS: f_fsid incorporates device identity (devt) to remain unique
across clones, while s_uuid is preserved consistently matching the on-disk
uuid.
While I like fixing this up, switching the f_fsid construction to a
different method might break things. Is there a way to only change
it for cloned file systems to reduce the surface of this change?
The problem is that we won't know which filesystem is the original
and which is the clone. Generally, the first one mounted is treated
as the original and the following one as the clone. However, f_fsid
should remain consistent regardless of mount order, at least for
the duration that the block device is connected (or until a
system reboot).
quoted
Patches
-------
Patch 1/3: btrfs: fix f_fsid to include rootid and devt
Patch 2/3: btrfs: fix s_uuid to be stable across mounts for cloned filesystems
Patch 3/3: ext4: fix f_fsid to use devt instead of s_uuid
I don't really see that patch 3 in my inbox on linux-btrfs.
From: Christoph Hellwig <hch@infradead.org> Date: 2026-03-05 14:21:29
On Thu, Mar 05, 2026 at 05:32:36PM +0800, Anand Jain wrote:
The problem is that we won't know which filesystem is the original
and which is the clone. Generally, the first one mounted is treated
as the original and the following one as the clone. However, f_fsid
should remain consistent regardless of mount order, at least for
the duration that the block device is connected (or until a
system reboot).
Then maybe we need to make the new sane behavior dependent on a
feature flag so that only newly created file systems use it?
On Thu, Feb 26, 2026 at 10:23:32PM +0800, Anand Jain wrote:
| s_uuid f_fsid
--------------|---------------------------
EXT4 | same same
Btrfs | random random
XFS | same f(devt)
EXT4-patched | same f(devt)
Btrfs-patched | same f(s_uuid,rootid,devt)
I don't *object* to changing ext4 reports since having something that
is unique is probably better. However, my bigger concern is using
f_fsid in the first place. It's only 64 bits, and that's really not
enough to gaurantee uniqueness. And even as you've proposed to change
things, it's not consistent across file systems. In particular, your
proposed solution mixes s_uuid into btrfs-patched, but not
ext4-patched. Why?
Problem
-------
Btrfs currently never duplicates s_uuid or f_fsid for cloned filesystems.
When an fsid collision is detected at mount time, btrfs generates a new
in-memory fsid (temp_fsid), but this is ephemeral — it changes on every
mount. This has two consequences:
1. IMA (Integrity Measurement Architecture) cannot reliably track the
filesystem across mount-cycle, since the f_fsid it sees keeps changing.
This does not scale. Whereas on the otherhand if you have same s_uuid
on multiple filesystems, monitoring per distint filesystem is lost.
The problem with using f(dev_t) for IMA is that if you have a
removable device (e.g., an SD card), reporting f_fsid as purely being
a function of dev_t means that the if an SD card ejected, and replaced
with another, the fsid_t will manifestly *not* be unique. So in that
sense, replace f(dev_t) with f(s_uuid) would be worse if you think
"file system unique id" should be unique in the case of removable
storage devices.
If the audit log includes mounts and unmounts, then this might not be
fatal. But if less-than intelligent system administrator or LLM tries
to analyize an audit log using tools like "grep", it would be pretty
easy for someone to get misled.
I know you were primarily interested in cloned file systems, but I
think we also need to take into account other cases, including ones
where there might be more the file system associated with a block
device over time.
2. If we instead allow cloned filesystems to share the same f_fsid (as
ext4 currently does), fanotify loses the ability to distinguish
between distinct filesystem instances. FAN_EVENT_INFO_TYPE_FID events
will fail to resolve to the correct mountpoint when f_fsid values
are identical across clones.
My personal opinion is that f_fsuid is just a terrible interface, the
fact that IMA and fanotify used this is regrettable. I understand why
it happened, because there wasn't anything better, and for many use
cases, it's good enough. But not all.
So I hope we can just actively discourage anyone else using it. Given
that exactly it has not been standardized, across different operating
systems, and different file systems for Linux --- hopefully most
people will have already made that choice.
- Ted