From: Anand Jain <asj@kernel.org>
To: linux-ext4@vger.kernel.org, linux-btrfs@vger.kernel.org
Cc: linux-xfs@vger.kernel.org, hch@infradead.org
Subject: [PATCH v2 3/3] ext4: derive f_fsid from block device to avoid collisions
Date: Sat, 21 Mar 2026 19:55:19 +0800 [thread overview]
Message-ID: <33e8eb64c304a4d42b60f608c26497bf9a2e9e19.1774092915.git.asj@kernel.org> (raw)
In-Reply-To: <cover.1774092915.git.asj@kernel.org>
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.
Place this change behind the new mount option "-o nouuid" for ABI
compatibility.
Signed-off-by: Anand Jain <asj@kernel.org>
---
fs/ext4/ext4.h | 1 +
fs/ext4/super.c | 12 ++++++++++--
2 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index 293f698b7042..64d98ab64c11 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -1282,6 +1282,7 @@ struct ext4_inode_info {
* scanning in mballoc
*/
#define EXT4_MOUNT2_ABORT 0x00000100 /* Abort filesystem */
+#define EXT4_MOUNT2_NOUUID 0x00000200 /* No duplicate f_fsid for cloned filesystem */
#define clear_opt(sb, opt) EXT4_SB(sb)->s_mount_opt &= \
~EXT4_MOUNT_##opt
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index 43f680c750ae..65b712af4ad7 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -1664,7 +1664,7 @@ static const struct export_operations ext4_export_ops = {
enum {
Opt_bsd_df, Opt_minix_df, Opt_grpid, Opt_nogrpid,
Opt_resgid, Opt_resuid, Opt_sb,
- Opt_nouid32, Opt_debug, Opt_removed,
+ Opt_nouid32, Opt_debug, Opt_removed, Opt_nouuid,
Opt_user_xattr, Opt_acl,
Opt_auto_da_alloc, Opt_noauto_da_alloc, Opt_noload,
Opt_commit, Opt_min_batch_time, Opt_max_batch_time, Opt_journal_dev,
@@ -1743,6 +1743,7 @@ static const struct fs_parameter_spec ext4_param_specs[] = {
fsparam_u32 ("sb", Opt_sb),
fsparam_enum ("errors", Opt_errors, ext4_param_errors),
fsparam_flag ("nouid32", Opt_nouid32),
+ fsparam_flag ("nouuid", Opt_nouuid),
fsparam_flag ("debug", Opt_debug),
fsparam_flag ("oldalloc", Opt_removed),
fsparam_flag ("orlov", Opt_removed),
@@ -1898,6 +1899,7 @@ static const struct mount_opts {
{Opt_acl, 0, MOPT_NOSUPPORT},
#endif
{Opt_nouid32, EXT4_MOUNT_NO_UID32, MOPT_SET},
+ {Opt_nouuid, EXT4_MOUNT2_NOUUID, MOPT_SET | MOPT_2},
{Opt_debug, EXT4_MOUNT_DEBUG, MOPT_SET},
{Opt_quota, EXT4_MOUNT_QUOTA | EXT4_MOUNT_USRQUOTA, MOPT_SET | MOPT_Q},
{Opt_usrquota, EXT4_MOUNT_QUOTA | EXT4_MOUNT_USRQUOTA,
@@ -2389,6 +2391,9 @@ static int ext4_parse_param(struct fs_context *fc, struct fs_parameter *param)
return -EINVAL;
}
return 0;
+ case Opt_nouuid:
+ ctx_set_mount_opt2(ctx, EXT4_MOUNT2_NOUUID);
+ return 0;
}
/*
@@ -6941,7 +6946,10 @@ static int ext4_statfs(struct dentry *dentry, struct kstatfs *buf)
buf->f_files = le32_to_cpu(es->s_inodes_count);
buf->f_ffree = percpu_counter_sum_positive(&sbi->s_freeinodes_counter);
buf->f_namelen = EXT4_NAME_LEN;
- buf->f_fsid = uuid_to_fsid(es->s_uuid);
+ if (test_opt2(sb, NOUUID))
+ buf->f_fsid = u64_to_fsid(huge_encode_dev(sb->s_bdev->bd_dev));
+ else
+ buf->f_fsid = uuid_to_fsid(es->s_uuid);
#ifdef CONFIG_QUOTA
if (ext4_test_inode_flag(dentry->d_inode, EXT4_INODE_PROJINHERIT) &&
--
2.43.0
next prev parent reply other threads:[~2026-03-21 11:55 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-21 11:55 [PATCH v2 0/3] fix s_uuid and f_fsid consistency for cloned filesystems Anand Jain
2026-03-21 11:55 ` [PATCH v2 1/3] btrfs: use on-disk uuid for s_uuid in temp_fsid mounts Anand Jain
2026-03-21 11:55 ` [PATCH v2 2/3] btrfs: derive f_fsid from on-disk fsuuid and dev_t Anand Jain
2026-03-21 11:55 ` Anand Jain [this message]
2026-03-23 4:16 ` [PATCH v2 3/3] ext4: derive f_fsid from block device to avoid collisions Theodore Tso
2026-03-23 15:29 ` Darrick J. Wong
2026-03-23 16:44 ` Darrick J. Wong
2026-03-25 10:02 ` Andreas Dilger
2026-03-25 10:59 ` Anand Jain
2026-03-25 12:59 ` Theodore Tso
2026-03-23 15:41 ` Anand Jain
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=33e8eb64c304a4d42b60f608c26497bf9a2e9e19.1774092915.git.asj@kernel.org \
--to=asj@kernel.org \
--cc=hch@infradead.org \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-xfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox