Linux EXT4 FS development
 help / color / mirror / Atom feed
* [PATCH v2 00/20] fstests: tests for cloned filesystem validation and f_fsid v2
@ 2026-11-30 11:03 Anand Jain
  2026-11-30 11:03 ` [PATCH v2 01/20] fstests: introduce _require_clone_mount() helper Anand Jain
                   ` (19 more replies)
  0 siblings, 20 replies; 21+ messages in thread
From: Anand Jain @ 2026-11-30 11:03 UTC (permalink / raw)
  To: fstests; +Cc: zlang, linux-btrfs, linux-ext4, linux-xfs, linux-f2fs-devel

This series adds tests validating cloned filesystem behavior and f_fsid
handling across filesystems and VFS/notification/security interfaces.

Changes since v1:
- Addressed Zorro's review comments:
  - Replace umount calls with _unmount.
  - Fix whitespace/spacing issues.
  - Drop the IMA patches ("fstests: introduce _require_security_ima()
    helper" and "fstests: verify IMA isolation on cloned filesystems").
  - Rename _require_fanotify_function() to _require_fanotify().
  - Remove the temp_dev=() array in _create_cloned_loop_devs().
  - Check kernel support via fanotify_init().
  - Use $SEMANAGE_PROG instead of a hardcoded binary.

v1: https://lore.kernel.org/fstests/awSPgGGZv7u6_SGM@zlang-mailbox/T/#t

Signed-off-by: Anand Jain <asj@kernel.org>
---
Anand Jain (20):
      fstests: introduce _require_clone_mount() helper
      fstests: introduce _create_cloned_loop_devs() helper
      fstests: add _clone_mount_options() helper
      fstests: add FSNOTIFYWAIT_PROG
      fstests: add _require_fanotify
      fstests: add _require_unique_f_fsid() helper
      fstests: add SEMANAGE_PROG
      fstests: verify fanotify isolation on cloned filesystems
      fstests: introduce helper _scratch_mkfs_uuid()
      fstests: add helpers to verify the expected f_fsid
      fstests: verify statfs f_fsid is derived from the filesystem UUID
      fstests: verify libblkid resolution of duplicate UUIDs
      fstests: verify exportfs file handles on cloned filesystems
      fstests: introduce _require_metadata_uuid() helper
      fstests: add _change_metadata_uuid helper
      fstests: test UUID consistency for clones with metadata_uuid
      fstests: generic/744: use new helper _require_clone_mount()
      fstests: generic/744: migrate to _create_cloned_loop_devs()
      fstests: _create_loop_device_like_bdev() remove unused variable
      fstests: verify f_fsid for cloned filesystems

 common/config         |   2 +
 common/rc             | 248 +++++++++++++++++++++++++++++++++++++++++++++++---
 src/Makefile          |   1 +
 src/feature.c         |  42 ++++++++-
 tests/generic/744     |  72 ++++++---------
 tests/generic/901     | 143 +++++++++++++++++++++++++++++
 tests/generic/901.out |   7 ++
 tests/generic/902     |  38 ++++++++
 tests/generic/902.out |   2 +
 tests/generic/903     |  71 +++++++++++++++
 tests/generic/903.out |   6 ++
 tests/generic/905     |  79 ++++++++++++++++
 tests/generic/905.out |   2 +
 tests/generic/906     |  74 +++++++++++++++
 tests/generic/906.out |   6 ++
 tests/generic/908     |  88 ++++++++++++++++++
 tests/generic/908.out |   2 +
 17 files changed, 821 insertions(+), 62 deletions(-)
---
base-commit: 71641219a506ac62bfa231592394265ca812670e
change-id: 20261130-f_fsid-4b6af701a1f2

Best regards,
-- 
Anand Jain <asj@kernel.org>

^ permalink raw reply	[flat|nested] 21+ messages in thread

* [PATCH v2 01/20] fstests: introduce _require_clone_mount() helper
  2026-11-30 11:03 [PATCH v2 00/20] fstests: tests for cloned filesystem validation and f_fsid v2 Anand Jain
@ 2026-11-30 11:03 ` Anand Jain
  2026-11-30 11:03 ` [PATCH v2 02/20] fstests: introduce _create_cloned_loop_devs() helper Anand Jain
                   ` (18 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Anand Jain @ 2026-11-30 11:03 UTC (permalink / raw)
  To: fstests; +Cc: zlang, linux-btrfs, linux-ext4, linux-xfs, linux-f2fs-devel

Add _require_clone_mount() to common/rc to check whether the filesystem
supports mounting cloned block devices simultaneously. For Btrfs, it
verifies kernel support for the temp_fsid feature, while skipping
unsupported filesystem types with _notrun.

Reviewed-by: Zorro Lang <zlang@kernel.org>
Signed-off-by: Anand Jain <asj@kernel.org>
---
 common/rc | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/common/rc b/common/rc
index 750a8d836ccd..e6d2acf84dc6 100644
--- a/common/rc
+++ b/common/rc
@@ -6193,6 +6193,21 @@ _force_inplace_writes()
 	esac
 }
 
+_require_clone_mount()
+{
+	case "$FSTYP" in
+	xfs|ext4|f2fs)
+		# No kernel-side restriction; always supported
+		;;
+	btrfs)
+		_require_fs_sysfs_feature_attr temp_fsid
+		;;
+	*)
+		_notrun "$FSTYP does not support mounting cloned devices simultaneously"
+		;;
+	esac
+}
+
 # Test that a filesystem can do writes to a file in place (without allocating
 # new extents, without Copy-On-Write semantics).
 _require_inplace_writes()

-- 
2.43.0

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH v2 02/20] fstests: introduce _create_cloned_loop_devs() helper
  2026-11-30 11:03 [PATCH v2 00/20] fstests: tests for cloned filesystem validation and f_fsid v2 Anand Jain
  2026-11-30 11:03 ` [PATCH v2 01/20] fstests: introduce _require_clone_mount() helper Anand Jain
@ 2026-11-30 11:03 ` Anand Jain
  2026-11-30 11:03 ` [PATCH v2 03/20] fstests: add _clone_mount_options() helper Anand Jain
                   ` (17 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Anand Jain @ 2026-11-30 11:03 UTC (permalink / raw)
  To: fstests; +Cc: zlang, linux-btrfs, linux-ext4, linux-xfs, linux-f2fs-devel

Introduce _create_cloned_loop_devs() and _destroy_cloned_loop_devs to mkfs an
image file and clone it to another image file, and attach a loop device to
them. And its destroy part.

Signed-off-by: Anand Jain <asj@kernel.org>
---
 common/rc | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 66 insertions(+)

diff --git a/common/rc b/common/rc
index e6d2acf84dc6..02d9a3562c3d 100644
--- a/common/rc
+++ b/common/rc
@@ -1534,6 +1534,72 @@ _scratch_resvblks()
 	esac
 }
 
+# Create a small loop image, run an optional tuning function ($2) on it,
+# clone it, and attach both to loop devices, returned in ($1).
+# Args:
+#   $1: Nameref to return the array of allocated loop devices [base, clone].
+#   $2: Optional callback function to tune the base filesystem before cloning.
+_create_cloned_loop_devs()
+{
+	local -n _ret=$1
+	local pre_clone_tune_func="$2"
+	local img_file="$TEST_DIR/${seq}/orig.img"
+	local img_file_clone="$TEST_DIR/${seq}/clone.img"
+	local size=$(_small_fs_size_mb 128) # Smallest possible
+	local temp_dev
+	local loop_devs=()
+
+	# All current callers mount the original and the clone simultaneously.
+	_require_clone_mount
+
+	# Since we copy the block device image, we keep its size small.
+	_require_fs_space $TEST_DIR $((size * 1024 * 2))
+
+	_create_file_sized $((size * 1024 * 1024)) $img_file ||
+				_fail "Failed: Create $img_file $size"
+
+	temp_dev="$(_create_loop_device_like_bdev $img_file ${TEST_DEV})"
+	_mkfs_dev "${temp_dev}"
+
+	# Only execute if the function argument is not empty
+	if [ -n "$pre_clone_tune_func" ]; then
+		$pre_clone_tune_func "${temp_dev}"
+	fi
+
+	# We are about to copy the loop device's backing file
+	# Flush loop device's buffer cache
+	blockdev --flushbufs "${temp_dev}"
+	# Sync system's dirty pages including backing file's
+	sync
+	_destroy_loop_device "${temp_dev}"
+
+	cp $img_file $img_file_clone || _fail "Failed to copy cloned image"
+
+	loop_devs=("$(_create_loop_device_like_bdev $img_file ${TEST_DEV})")
+	loop_devs+=("$(_create_loop_device_like_bdev $img_file_clone ${TEST_DEV})")
+
+	# Help debug
+	losetup --list "${loop_devs[0]}" >> $seqres.full
+	losetup --list "${loop_devs[1]}" >> $seqres.full
+
+	_ret=("${loop_devs[@]}")
+}
+
+# Teardown loop devices and delete their underlying backing image files.
+# Accepts a list of loop device paths (e.g., /dev/loop0 /dev/loop1).
+_destroy_cloned_loop_devs()
+{
+	for d in "$@"; do
+		# Retrieve the path of the backing file
+		local f=$(losetup --noheadings --output BACK-FILE $d)
+
+		# Detach the loop device from the backing file
+		_destroy_loop_device "$d"
+
+		# Clean up the backing disk image file
+		[ -n "$f" ] && rm -f "$f"
+	done
+}
 
 # Repair scratch filesystem.  Returns 0 if the FS is good to go (either no
 # errors found or errors were fixed) and nonzero otherwise; also spits out

-- 
2.43.0

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH v2 03/20] fstests: add _clone_mount_options() helper
  2026-11-30 11:03 [PATCH v2 00/20] fstests: tests for cloned filesystem validation and f_fsid v2 Anand Jain
  2026-11-30 11:03 ` [PATCH v2 01/20] fstests: introduce _require_clone_mount() helper Anand Jain
  2026-11-30 11:03 ` [PATCH v2 02/20] fstests: introduce _create_cloned_loop_devs() helper Anand Jain
@ 2026-11-30 11:03 ` Anand Jain
  2026-11-30 11:03 ` [PATCH v2 04/20] fstests: add FSNOTIFYWAIT_PROG Anand Jain
                   ` (16 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Anand Jain @ 2026-11-30 11:03 UTC (permalink / raw)
  To: fstests; +Cc: zlang, linux-btrfs, linux-ext4, linux-xfs, linux-f2fs-devel

Adds _clone_mount_options() helper function to handle filesystem-specific
requirements for mounting cloned devices. Abstract the need for -o nouuid
on XFS.

Reviewed-by: Zorro Lang <zlang@kernel.org>
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>
Signed-off-by: Anand Jain <asj@kernel.org>
---
 common/rc | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/common/rc b/common/rc
index 02d9a3562c3d..83a371fd7f48 100644
--- a/common/rc
+++ b/common/rc
@@ -428,6 +428,19 @@ _scratch_mount_options()
 					$SCRATCH_DEV $SCRATCH_MNT
 }
 
+# Return filesystem-specific mount options required for mounting clone/snapshot
+# devices.
+_clone_mount_options()
+{
+	case "$FSTYP" in
+	xfs)
+		# Allow mounting a duplicate filesystem on the same host
+		echo "-o nouuid"
+		;;
+	*)
+	esac
+}
+
 _supports_filetype()
 {
 	local dir=$1

-- 
2.43.0

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH v2 04/20] fstests: add FSNOTIFYWAIT_PROG
  2026-11-30 11:03 [PATCH v2 00/20] fstests: tests for cloned filesystem validation and f_fsid v2 Anand Jain
                   ` (2 preceding siblings ...)
  2026-11-30 11:03 ` [PATCH v2 03/20] fstests: add _clone_mount_options() helper Anand Jain
@ 2026-11-30 11:03 ` Anand Jain
  2026-11-30 11:03 ` [PATCH v2 05/20] fstests: add _require_fanotify Anand Jain
                   ` (15 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Anand Jain @ 2026-11-30 11:03 UTC (permalink / raw)
  To: fstests; +Cc: zlang, linux-btrfs, linux-ext4, linux-xfs, linux-f2fs-devel

Define `FSNOTIFYWAIT_PROG` for an upcoming test case that uses `fsnotifywait`.

Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>
Signed-off-by: Anand Jain <asj@kernel.org>
---
 common/config | 1 +
 1 file changed, 1 insertion(+)

diff --git a/common/config b/common/config
index 69e5d83319b8..76b43b8c6ad9 100644
--- a/common/config
+++ b/common/config
@@ -242,6 +242,7 @@ export BTRFS_MAP_LOGICAL_PROG=$(type -P btrfs-map-logical)
 export PARTED_PROG="$(type -P parted)"
 export XFS_PROPERTY_PROG="$(type -P xfs_property)"
 export FSCRYPTCTL_PROG="$(type -P fscryptctl)"
+export FSNOTIFYWAIT_PROG="$(type -P fsnotifywait)"
 
 # udev wait functions.
 #

-- 
2.43.0

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH v2 05/20] fstests: add _require_fanotify
  2026-11-30 11:03 [PATCH v2 00/20] fstests: tests for cloned filesystem validation and f_fsid v2 Anand Jain
                   ` (3 preceding siblings ...)
  2026-11-30 11:03 ` [PATCH v2 04/20] fstests: add FSNOTIFYWAIT_PROG Anand Jain
@ 2026-11-30 11:03 ` Anand Jain
  2026-11-30 11:03 ` [PATCH v2 06/20] fstests: add _require_unique_f_fsid() helper Anand Jain
                   ` (14 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Anand Jain @ 2026-11-30 11:03 UTC (permalink / raw)
  To: fstests; +Cc: zlang, linux-btrfs, linux-ext4, linux-xfs, linux-f2fs-devel

fanotify support may not be compiled into the kernel. Add
_require_fanotify to skip tests when fanotify is disabled.

Signed-off-by: Anand Jain <asj@kernel.org>
---
 common/rc     | 16 ++++++++++++++++
 src/Makefile  |  1 +
 src/feature.c | 42 +++++++++++++++++++++++++++++++++++++++---
 3 files changed, 56 insertions(+), 3 deletions(-)

diff --git a/common/rc b/common/rc
index 83a371fd7f48..47079bc0c60e 100644
--- a/common/rc
+++ b/common/rc
@@ -6453,6 +6453,22 @@ _require_max_file_range_blocks()
 	esac
 }
 
+# this test requires that the kernel supports fanotify
+_require_fanotify()
+{
+	$here/src/feature -F
+	case $? in
+	0)
+		;;
+	1)
+		_notrun "kernel does not support fanotify"
+		;;
+	*)
+		_fail "unexpected error testing for fanotify support"
+		;;
+	esac
+}
+
 _require_fanotify_ioerrors()
 {
 	local x
diff --git a/src/Makefile b/src/Makefile
index a1fc38d88b8a..a6cfafd57878 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -108,6 +108,7 @@ endif
 
 ifeq ($(HAVE_FANOTIFY_FID),yes)
      LINUX_TARGETS += fs-monitor
+     LCFLAGS += -DHAVE_FANOTIFY_FID
 endif
 
 ifeq ($(HAVE_LIBBTRFSUTIL), true)
diff --git a/src/feature.c b/src/feature.c
index 7df36acf4caf..8f73499bc799 100644
--- a/src/feature.c
+++ b/src/feature.c
@@ -19,6 +19,7 @@
  *
  * Test for machine features
  *   -A  test whether AIO syscalls are available
+ *   -F  test whether fanotify syscalls are available
  *   -r  test whether mount_setattr syscall is supported
  *   -R  test whether IO_URING syscalls are available
  *   -o  report a number of online cpus
@@ -46,6 +47,10 @@
 #include <liburing.h>
 #endif
 
+#ifdef HAVE_FANOTIFY_FID
+#include <sys/fanotify.h>
+#endif
+
 #include "vfs/missing.h"
 
 #ifndef USRQUOTA
@@ -68,7 +73,7 @@ usage(void)
 	fprintf(stderr, "Usage: feature [-v] -<q|u|g|p|U|G|P> <filesystem>\n");
 	fprintf(stderr, "       feature [-v] -c <file>\n");
 	fprintf(stderr, "       feature [-v] -t <file>\n");
-	fprintf(stderr, "       feature -A | -r | -R | -o | -s | -w\n");
+	fprintf(stderr, "       feature -A | -F | -r | -R | -o | -s | -w\n");
 	exit(1);
 }
 
@@ -224,6 +229,30 @@ check_aio_support(void)
 #endif
 }
 
+static int
+check_fanotify_support(void)
+{
+#ifdef HAVE_FANOTIFY_FID
+	int fd;
+
+	fd = fanotify_init(FAN_CLASS_NOTIF, O_RDONLY);
+	if (fd >= 0) {
+		close(fd);
+		return 0;
+	}
+
+	if (errno == ENOSYS) /* CONFIG_FANOTIFY=n */
+		return 1;
+
+	fprintf(stderr, "unexpected error from fanotify_init(): %s\n",
+		strerror(errno));
+	return 2;
+#else
+	/* fanotify support was unavailable at build time */
+	return 1;
+#endif
+}
+
 static int
 check_uring_support(void)
 {
@@ -279,6 +308,7 @@ main(int argc, char **argv)
 {
 	int	c;
 	int	Aflag = 0;
+	int	Fflag = 0;
 	int	cflag = 0;
 	int	tflag = 0;
 	int	gflag = 0;
@@ -295,11 +325,14 @@ main(int argc, char **argv)
 	int	oflag = 0;
 	char	*fs = NULL;
 
-	while ((c = getopt(argc, argv, "ActgGopPqrRsuUvw")) != EOF) {
+	while ((c = getopt(argc, argv, "AFctgGopPqrRsuUvw")) != EOF) {
 		switch (c) {
 		case 'A':
 			Aflag++;
 			break;
+		case 'F':
+			Fflag++;
+			break;
 		case 'c':
 			cflag++;
 			break;
@@ -355,7 +388,7 @@ main(int argc, char **argv)
 		if (optind != argc-1)	/* need a device */
 			usage();
 		fs = argv[argc-1];
-	} else if (Aflag || rflag || Rflag || wflag || sflag || oflag) {
+	} else if (Aflag || Fflag || rflag || Rflag || wflag || sflag || oflag) {
 		if (optind != argc)
 			usage();
 	} else
@@ -383,6 +416,9 @@ main(int argc, char **argv)
 	if (Aflag)
 		return(check_aio_support());
 
+	if (Fflag)
+		return(check_fanotify_support());
+
 	if (rflag)
 		return(check_mount_setattr_support());
 

-- 
2.43.0

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH v2 06/20] fstests: add _require_unique_f_fsid() helper
  2026-11-30 11:03 [PATCH v2 00/20] fstests: tests for cloned filesystem validation and f_fsid v2 Anand Jain
                   ` (4 preceding siblings ...)
  2026-11-30 11:03 ` [PATCH v2 05/20] fstests: add _require_fanotify Anand Jain
@ 2026-11-30 11:03 ` Anand Jain
  2026-11-30 11:03 ` [PATCH v2 07/20] fstests: add SEMANAGE_PROG Anand Jain
                   ` (13 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Anand Jain @ 2026-11-30 11:03 UTC (permalink / raw)
  To: fstests; +Cc: zlang, linux-btrfs, linux-ext4, linux-xfs, linux-f2fs-devel

Add a helper to check if the target filesystem supports unique f_fsid
tracking across cloned or snapshot instances.

Certain filesystems like XFS, Btrfs, and F2FS ensure unique f_fsid
identifiers per filesystem instance. However, Ext4 derives its f_fsid
directly from its superblock UUID, which leads to identical f_fsid
values on cloned images until the UUID is manually modified by userspace.

Introduce _require_unique_f_fsid() to allow test cases requiring strict
f_fsid uniqueness to skip gracefully on unsupported filesystems.

Reviewed-by: Zorro Lang <zlang@kernel.org>
Signed-off-by: Anand Jain <asj@kernel.org>
---
 common/rc | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/common/rc b/common/rc
index 47079bc0c60e..52f884902c7c 100644
--- a/common/rc
+++ b/common/rc
@@ -6495,6 +6495,33 @@ _require_fanotify_ioerrors()
 	_notrun "$FSTYP does not support fanotify ioerrors"
 }
 
+# Skip the test if the filesystem does not enforce unique f_fsids
+# natively. Checking this dynamically requires recreating a clone
+# layout, so we use a static lookup based on FSTYP.
+#
+# Across all filesystems, a UUID collision causes libblkid tools to return
+# non-deterministic device mappings. It is ultimately the responsibility
+# of the userspace utility or use-case to enforce uniqueness when a clone
+# diverges. For details, see mailing list thread discussions:
+#   Link: https://lore.kernel.org/linux-ext4/20260409131238.GC18443@macsyma-wired.lan/
+_require_unique_f_fsid()
+{
+	case "$FSTYP" in
+	ext*)
+		# Ext4 derives f_fsid from the superblock UUID, meaning
+		# clones share the same f_fsid until their UUIDs
+		# diverge.
+		_notrun "Target filesystem ($FSTYP) does not guarantee unique f_fsid on clones."
+		;;
+	*)
+		# Conversely, XFS, Btrfs, and F2FS ensure f_fsid remains
+		# unique per filesystem instance (often by deriving it
+		# from the UUID and underlying block device.)
+		;;
+	esac
+}
+
+
 # Computes a percentage of the available space in a filesystem and
 # returns that quantity in MB. The percentage must not contain a percent
 # sign ("%").

-- 
2.43.0

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH v2 07/20] fstests: add SEMANAGE_PROG
  2026-11-30 11:03 [PATCH v2 00/20] fstests: tests for cloned filesystem validation and f_fsid v2 Anand Jain
                   ` (5 preceding siblings ...)
  2026-11-30 11:03 ` [PATCH v2 06/20] fstests: add _require_unique_f_fsid() helper Anand Jain
@ 2026-11-30 11:03 ` Anand Jain
  2026-11-30 11:03 ` [PATCH v2 08/20] fstests: verify fanotify isolation on cloned filesystems Anand Jain
                   ` (12 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Anand Jain @ 2026-11-30 11:03 UTC (permalink / raw)
  To: fstests; +Cc: zlang, linux-btrfs, linux-ext4, linux-xfs, linux-f2fs-devel

Define `SEMANAGE_PROG` for an upcoming test case that uses `semanage(8)`.

Reviewed-by: Zorro Lang <zlang@kernel.org>
Signed-off-by: Anand Jain <asj@kernel.org>
---
 common/config | 1 +
 1 file changed, 1 insertion(+)

diff --git a/common/config b/common/config
index 76b43b8c6ad9..e8fecc168e5a 100644
--- a/common/config
+++ b/common/config
@@ -243,6 +243,7 @@ export PARTED_PROG="$(type -P parted)"
 export XFS_PROPERTY_PROG="$(type -P xfs_property)"
 export FSCRYPTCTL_PROG="$(type -P fscryptctl)"
 export FSNOTIFYWAIT_PROG="$(type -P fsnotifywait)"
+export SEMANAGE_PROG="$(type -P semanage)"
 
 # udev wait functions.
 #

-- 
2.43.0

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH v2 08/20] fstests: verify fanotify isolation on cloned filesystems
  2026-11-30 11:03 [PATCH v2 00/20] fstests: tests for cloned filesystem validation and f_fsid v2 Anand Jain
                   ` (6 preceding siblings ...)
  2026-11-30 11:03 ` [PATCH v2 07/20] fstests: add SEMANAGE_PROG Anand Jain
@ 2026-11-30 11:03 ` Anand Jain
  2026-11-30 11:03 ` [PATCH v2 09/20] fstests: introduce helper _scratch_mkfs_uuid() Anand Jain
                   ` (11 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Anand Jain @ 2026-11-30 11:03 UTC (permalink / raw)
  To: fstests; +Cc: zlang, linux-btrfs, linux-ext4, linux-xfs, linux-f2fs-devel

Verify that fanotify events are correctly routed to the appropriate
watcher when cloned filesystems are mounted.
Helps verify kernel's event notification distinguishes between devices
sharing the same FSID/UUID.

Signed-off-by: Anand Jain <asj@kernel.org>
---
 tests/generic/901     | 143 ++++++++++++++++++++++++++++++++++++++++++++++++++
 tests/generic/901.out |   7 +++
 2 files changed, 150 insertions(+)

diff --git a/tests/generic/901 b/tests/generic/901
new file mode 100644
index 000000000000..d16e733f1c9a
--- /dev/null
+++ b/tests/generic/901
@@ -0,0 +1,143 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2026 Anand Jain <asj@kernel.org>.  All Rights Reserved.
+#
+# FS QA Test No. 901
+# Verify fanotify FID functionality on cloned filesystems by setting up
+# watchers and making sure notifications are in the correct logs files.
+
+. ./common/preamble
+
+_begin_fstest auto quick mount tempfsid
+
+_require_test
+_require_loop
+_require_command "$SEMANAGE_PROG" semanage
+_require_command "$FSNOTIFYWAIT_PROG" fsnotifywait
+_require_fanotify
+_require_unique_f_fsid
+
+_cleanup()
+{
+	cd /
+	[[ -n $pid1 ]] && { kill -TERM "$pid1" 2> /dev/null; wait $pid1; }
+	[[ -n $pid2 ]] && { kill -TERM "$pid2" 2> /dev/null; wait $pid2; }
+
+	if [ "$semanage_added" = "yes" ]; then
+		$SEMANAGE_PROG permissive -d unconfined_t >/dev/null 2>&1 || true
+	fi
+
+	_unmount $mnt1 $mnt2 >/dev/null 2>&1
+	_destroy_cloned_loop_devs "${devs[@]}" 2> /dev/null
+	rm -r -f $tmp.*
+}
+
+# Run fsnotifywait in unbuffered mode to watch filesystem-wide create events
+monitor_fanotify()
+{
+	local mmnt=$1
+	exec stdbuf -oL $FSNOTIFYWAIT_PROG -m -F -S -e create "$mmnt" 2>&1
+}
+
+# Transform f_fsid into the hi.lo format used in fanotify FID logs
+fsid_to_fid_parts()
+{
+	local fsid=$1
+	# Pad to 16 hex chars (64-bit), then split into two 32-bit halves
+	local padded=$(printf '%016x' "0x${fsid}")
+	local hi=$(printf '%x' "0x${padded:0:8}")   # strips leading zeros
+	local lo=$(printf '%x' "0x${padded:8:8}")   # strips leading zeros
+	echo "${hi}.${lo}"
+}
+
+rm -rf $TEST_DIR/$seq 2>/dev/null
+mkdir -p $TEST_DIR/$seq
+# Create base loop device and its clone
+devs=()
+_create_cloned_loop_devs devs
+mnt1=$TEST_DIR/$seq/mnt1
+mnt2=$TEST_DIR/$seq/mnt2
+mkdir -p $mnt1
+mkdir -p $mnt2
+
+# Mount both base and clone filesystems using required clone mount options
+_mount $(_common_dev_mount_options) $(_clone_mount_options) ${devs[0]} $mnt1 || \
+						_fail "Failed to mount dev1"
+_mount $(_common_dev_mount_options) $(_clone_mount_options) ${devs[1]} $mnt2 || \
+						_fail "Failed to mount dev2"
+
+# Fetch filesystem IDs to verify the kernel can differentiate between them
+fsid1=$(stat -f -c "%i" $mnt1)
+fsid2=$(stat -f -c "%i" $mnt2)
+
+log1=$tmp.fanotify1
+log2=$tmp.fanotify2
+
+pid1=""
+pid2=""
+echo "Setup FID fanotify watchers on both mnt1 and mnt2"
+
+# Permit unconfined_t domains when SELinux is enforcing to prevent fanotify
+# blockages
+semanage_added="no"
+if [ "$(getenforce 2>/dev/null)" = "Enforcing" ]; then
+	if ! $SEMANAGE_PROG permissive -l | grep -q "unconfined_t"; then
+		$SEMANAGE_PROG permissive -a unconfined_t >/dev/null 2>&1 && \
+							semanage_added="yes"
+	fi
+fi
+
+# Start asynchronous fanotify monitors
+( monitor_fanotify "$mnt1" > "$log1" ) &
+pid1=$!
+( monitor_fanotify "$mnt2" > "$log2" ) &
+pid2=$!
+sleep 2
+
+if ! kill -0 "$pid1" 2>/dev/null || ! kill -0 "$pid2" 2>/dev/null; then
+	cat "$log1"
+	cat "$log2"
+	_fail "$FSNOTIFYWAIT_PROG setup failed"
+fi
+
+echo "Trigger file creation on mnt1"
+touch $mnt1/file_on_mnt1
+sync
+sleep 1
+
+echo "Trigger file creation on mnt2"
+touch $mnt2/file_on_mnt2
+sync
+sleep 1
+
+echo "Verify fsid in the fanotify"
+kill $pid1 $pid2
+wait $pid1 $pid2 2>/dev/null
+pid1=""
+pid2=""
+
+e_fsid1=$(fsid_to_fid_parts "$fsid1")
+e_fsid2=$(fsid_to_fid_parts "$fsid2")
+
+# Dump debug details to the full log
+echo $fsid1 $e_fsid1 $fsid2 $e_fsid2 >> $seqres.full
+cat $log1 >> $seqres.full
+cat $log2 >> $seqres.full
+
+# Ensure monitor 1 only captured events belonging to mnt 1 and fsid 1
+if grep -qF "$e_fsid1" "$log1" && ! grep -qF "$e_fsid2" "$log1"; then
+	echo "SUCCESS: mnt1 events found"
+else
+	[ ! -s "$log1" ] && echo "  - mnt1 received no events."
+	grep -qF "$e_fsid2" "$log1" && echo "  - mnt1 received event from mnt2."
+fi
+
+# Ensure monitor 2 only captured events belonging to mnt 2 and fsid 2
+if grep -qF "$e_fsid2" "$log2" && ! grep -qF "$e_fsid1" "$log2"; then
+	echo "SUCCESS: mnt2 events found"
+else
+	[ ! -s "$log2" ] && echo "  - mnt2 received no events."
+	grep -qF "$e_fsid1" "$log2" && echo "  - mnt2 received event from mnt1."
+fi
+
+_exit 0
diff --git a/tests/generic/901.out b/tests/generic/901.out
new file mode 100644
index 000000000000..414e12d10b27
--- /dev/null
+++ b/tests/generic/901.out
@@ -0,0 +1,7 @@
+QA output created by 901
+Setup FID fanotify watchers on both mnt1 and mnt2
+Trigger file creation on mnt1
+Trigger file creation on mnt2
+Verify fsid in the fanotify
+SUCCESS: mnt1 events found
+SUCCESS: mnt2 events found

-- 
2.43.0

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH v2 09/20] fstests: introduce helper _scratch_mkfs_uuid()
  2026-11-30 11:03 [PATCH v2 00/20] fstests: tests for cloned filesystem validation and f_fsid v2 Anand Jain
                   ` (7 preceding siblings ...)
  2026-11-30 11:03 ` [PATCH v2 08/20] fstests: verify fanotify isolation on cloned filesystems Anand Jain
@ 2026-11-30 11:03 ` Anand Jain
  2026-11-30 11:03 ` [PATCH v2 10/20] fstests: add helpers to verify the expected f_fsid Anand Jain
                   ` (10 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Anand Jain @ 2026-11-30 11:03 UTC (permalink / raw)
  To: fstests; +Cc: zlang, linux-btrfs, linux-ext4, linux-xfs, linux-f2fs-devel

Reviewed-by: Zorro Lang <zlang@kernel.org>
Signed-off-by: Anand Jain <asj@kernel.org>
---
 common/rc | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/common/rc b/common/rc
index 52f884902c7c..6f09739c3dba 100644
--- a/common/rc
+++ b/common/rc
@@ -1449,6 +1449,36 @@ _scratch_mkfs_sized()
 	_try_scratch_mkfs_sized "$@" || _notrun "_scratch_mkfs_sized failed with ($*)"
 }
 
+# mkfs filesystem with a known uuid
+# Input argument : none
+_scratch_mkfs_uuid()
+{
+	case $FSTYP in
+	f2fs|ext4)
+		if echo "$MKFS_OPTIONS" | grep -E -q "-U"; then
+			_notrun "Config contains mkfs uuid option"
+		fi
+		MKFS_OPTIONS+=" -U 12345678-1234-1234-1234-123456789abc"
+		;;
+	xfs)
+		if echo "$MKFS_OPTIONS" | grep -E -q "uuid"; then
+			_notrun "Config contains mkfs uuid option"
+		fi
+		MKFS_OPTIONS+=" -m uuid=12345678-1234-1234-1234-123456789abc"
+		;;
+	btrfs)
+		if echo "$MKFS_OPTIONS" | grep -E -q "uuid|-U"; then
+			_notrun "Config contains mkfs uuid option"
+		fi
+		MKFS_OPTIONS+=" --uuid 12345678-1234-1234-1234-123456789abc"
+		;;
+	*)
+		_notrun "can't mkfs $FSTYP with uuid"
+		;;
+	esac
+	_scratch_mkfs
+}
+
 # Emulate an N-data-disk stripe w/ various stripe units
 # _scratch_mkfs_geom <sunit bytes> <swidth multiplier> [optional blocksize]
 _scratch_mkfs_geom()

-- 
2.43.0

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH v2 10/20] fstests: add helpers to verify the expected f_fsid
  2026-11-30 11:03 [PATCH v2 00/20] fstests: tests for cloned filesystem validation and f_fsid v2 Anand Jain
                   ` (8 preceding siblings ...)
  2026-11-30 11:03 ` [PATCH v2 09/20] fstests: introduce helper _scratch_mkfs_uuid() Anand Jain
@ 2026-11-30 11:03 ` Anand Jain
  2026-11-30 11:03 ` [PATCH v2 11/20] fstests: verify statfs f_fsid is derived from the filesystem UUID Anand Jain
                   ` (9 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Anand Jain @ 2026-11-30 11:03 UTC (permalink / raw)
  To: fstests; +Cc: zlang, linux-btrfs, linux-ext4, linux-xfs, linux-f2fs-devel

Add two helpers to common/rc:

_require_uuid_based_fsid() skips the test unless the filesystem derives
statfs f_fsid from the UUID alone (currently btrfs and ext4).

_scratch_expected_fsid() prints the f_fsid expected for a filesystem
created with the fixed test UUID.

Reviewed-by: Zorro Lang <zlang@kernel.org>
Signed-off-by: Anand Jain <asj@kernel.org>
---
 common/rc | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/common/rc b/common/rc
index 6f09739c3dba..5d28f6b3b780 100644
--- a/common/rc
+++ b/common/rc
@@ -6134,6 +6134,37 @@ hexdump()
 	_fail "Use _hexdump(), please!"
 }
 
+# Require a filesystem whose statfs f_fsid is derived from the filesystem
+# UUID only, so that it is stable across devices and mounts.
+_require_uuid_based_fsid()
+{
+	case $FSTYP in
+	btrfs|ext4)
+		;;
+	*)
+		_notrun "Require a filesystem that derives f_fsid from the UUID only"
+		;;
+	esac
+}
+
+# Print the statfs f_fsid expected for a filesystem created with the test
+# UUID 12345678-1234-1234-1234-123456789abc.
+# Must be guarded by _require_uuid_based_fsid.
+_scratch_expected_fsid()
+{
+	case $FSTYP in
+	ext4)
+		echo "4c44000088884c44"
+		;;
+	btrfs)
+		echo "444c444c888d"
+		;;
+	*)
+		return 1
+		;;
+	esac
+}
+
 # Try to create a file with inode->i_blocks >= (length / blocksize).
 # There may be some small overhead, e.g. ext2 filesystem allocates a
 # substantial number of blocks to store block mappings. Those are accounted

-- 
2.43.0

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH v2 11/20] fstests: verify statfs f_fsid is derived from the filesystem UUID
  2026-11-30 11:03 [PATCH v2 00/20] fstests: tests for cloned filesystem validation and f_fsid v2 Anand Jain
                   ` (9 preceding siblings ...)
  2026-11-30 11:03 ` [PATCH v2 10/20] fstests: add helpers to verify the expected f_fsid Anand Jain
@ 2026-11-30 11:03 ` Anand Jain
  2026-11-30 11:03 ` [PATCH v2 12/20] fstests: verify libblkid resolution of duplicate UUIDs Anand Jain
                   ` (8 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Anand Jain @ 2026-11-30 11:03 UTC (permalink / raw)
  To: fstests; +Cc: zlang, linux-btrfs, linux-ext4, linux-xfs, linux-f2fs-devel

On btrfs and ext4, statfs f_fsid is computed from the filesystem UUID,
so a filesystem created with a known UUID must always report the same
f_fsid. Userspace relies on this, for example fanotify and file handle
users that identify a filesystem across mounts.

Guards against f_fsid changing across kernel versions, which would break
userspace that relies on it.

Reviewed-by: Zorro Lang <zlang@kernel.org>
Signed-off-by: Anand Jain <asj@kernel.org>
---
 tests/generic/902     | 38 ++++++++++++++++++++++++++++++++++++++
 tests/generic/902.out |  2 ++
 2 files changed, 40 insertions(+)

diff --git a/tests/generic/902 b/tests/generic/902
new file mode 100644
index 000000000000..44dd685a887b
--- /dev/null
+++ b/tests/generic/902
@@ -0,0 +1,38 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2026 Anand Jain <asj@kernel.org>.  All Rights Reserved.
+#
+# FS QA Test No. 902
+#
+# Verify that statfs f_fsid is derived from the filesystem UUID.
+# Create a filesystem with a fixed UUID, mount it, and check that f_fsid
+# matches the expected value. Applies only to filesystems that derive
+# f_fsid from the UUID (btrfs, ext4).
+
+. ./common/preamble
+
+_begin_fstest auto quick
+
+_require_scratch
+_require_uuid_based_fsid
+
+_fixed_by_fs_commit btrfs 72de4807ba84 \
+	"btrfs: derive f_fsid with dev_t only when temp_fsid is active"
+
+_scratch_mkfs_uuid >> $seqres.full 2>&1 || _fail "mkfs failed"
+
+_scratch_mount
+
+blkid $SCRATCH_DEV >> $seqres.full
+f_fsid=$(stat -f -c "%i" $SCRATCH_MNT)
+expected=$(_scratch_expected_fsid)
+
+echo "f_fsid=$f_fsid expected=$expected" >> $seqres.full
+
+[[ $f_fsid == "$expected" ]] || _fail "f_fsid mismatch"
+
+_scratch_unmount
+
+echo "Silence is golden"
+
+_exit 0
diff --git a/tests/generic/902.out b/tests/generic/902.out
new file mode 100644
index 000000000000..e20395365cb5
--- /dev/null
+++ b/tests/generic/902.out
@@ -0,0 +1,2 @@
+QA output created by 902
+Silence is golden

-- 
2.43.0

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH v2 12/20] fstests: verify libblkid resolution of duplicate UUIDs
  2026-11-30 11:03 [PATCH v2 00/20] fstests: tests for cloned filesystem validation and f_fsid v2 Anand Jain
                   ` (10 preceding siblings ...)
  2026-11-30 11:03 ` [PATCH v2 11/20] fstests: verify statfs f_fsid is derived from the filesystem UUID Anand Jain
@ 2026-11-30 11:03 ` Anand Jain
  2026-11-30 11:03 ` [PATCH v2 13/20] fstests: verify exportfs file handles on cloned filesystems Anand Jain
                   ` (7 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Anand Jain @ 2026-11-30 11:03 UTC (permalink / raw)
  To: fstests; +Cc: zlang, linux-btrfs, linux-ext4, linux-xfs, linux-f2fs-devel

Verify how findmnt, df (libblkid) resolve device paths when multiple
block devices share the same FSUUID.

Signed-off-by: Anand Jain <asj@kernel.org>
---
 tests/generic/903     | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++
 tests/generic/903.out |  6 +++++
 2 files changed, 77 insertions(+)

diff --git a/tests/generic/903 b/tests/generic/903
new file mode 100644
index 000000000000..915a0a07f476
--- /dev/null
+++ b/tests/generic/903
@@ -0,0 +1,71 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2026 Anand Jain <asj@kernel.org>.  All Rights Reserved.
+#
+# FS QA Test No. 903
+# Check if the mountinfo based findmnt would resolve to the common uuid
+# as per the blkid (libblkid based).
+
+. ./common/preamble
+. ./common/filter
+
+_begin_fstest auto quick mount tempfsid
+
+_require_test
+_require_loop
+
+_cleanup()
+{
+	cd /
+	rm -r -f $tmp.*
+	_unmount $mnt1 $mnt2 2>/dev/null
+	_destroy_cloned_loop_devs "${devs[@]}" 2> /dev/null
+}
+
+# Normalize pool devices and mount points names
+filter_pool()
+{
+	sed -e "s|${devs[0]}|DEV1|g" -e "s|${mnt1}|MNT1|g" \
+	    -e "s|${devs[1]}|DEV2|g" -e "s|${mnt2}|MNT2|g" | _filter_spaces
+}
+
+rm -rf $TEST_DIR/$seq 2>/dev/null
+mkdir -p $TEST_DIR/$seq
+# Setup base loop device and its clone
+devs=()
+_create_cloned_loop_devs devs
+mnt1=$TEST_DIR/$seq/mnt1
+mnt2=$TEST_DIR/$seq/mnt2
+mkdir -p $mnt1
+mkdir -p $mnt2
+
+# Get the uuid from the source device
+fsuuid=$(blkid -s UUID -o value ${devs[0]})
+
+# Mount both identical UUID filesystems simultaneously
+_mount $(_common_dev_mount_options) $(_clone_mount_options) ${devs[0]} $mnt1 || \
+						_fail "Failed to mount dev1"
+_mount $(_common_dev_mount_options) $(_clone_mount_options) ${devs[1]} $mnt2 || \
+						_fail "Failed to mount dev2"
+
+findmnt --noheadings -o SOURCE,TARGET,UUID "${devs[0]}" | \
+				sed -e "s/${fsuuid}/FSUUID/g" | filter_pool
+findmnt --noheadings -o SOURCE,TARGET,UUID "${devs[1]}" | \
+				sed -e "s/${fsuuid}/FSUUID/g" | filter_pool
+
+# Btrfs assigned a random uuid for the clone fs before the fix.
+# Cycle mounts and reverse the initialization (source and clone fs) order.
+echo "**** mount cycle ****"
+_unmount $mnt1
+_unmount $mnt2
+_mount $(_common_dev_mount_options) $(_clone_mount_options) ${devs[1]} $mnt2 || \
+						_fail "Failed to mount dev2"
+_mount $(_common_dev_mount_options) $(_clone_mount_options) ${devs[0]} $mnt1 || \
+						_fail "Failed to mount dev1"
+
+findmnt --noheadings -o SOURCE,TARGET,UUID "${devs[0]}" | \
+				sed -e "s/${fsuuid}/FSUUID/g" | filter_pool
+findmnt --noheadings -o SOURCE,TARGET,UUID "${devs[1]}" | \
+				sed -e "s/${fsuuid}/FSUUID/g" | filter_pool
+
+_exit 0
diff --git a/tests/generic/903.out b/tests/generic/903.out
new file mode 100644
index 000000000000..7683506e1c94
--- /dev/null
+++ b/tests/generic/903.out
@@ -0,0 +1,6 @@
+QA output created by 903
+DEV1 MNT1 FSUUID
+DEV2 MNT2 FSUUID
+**** mount cycle ****
+DEV1 MNT1 FSUUID
+DEV2 MNT2 FSUUID

-- 
2.43.0

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH v2 13/20] fstests: verify exportfs file handles on cloned filesystems
  2026-11-30 11:03 [PATCH v2 00/20] fstests: tests for cloned filesystem validation and f_fsid v2 Anand Jain
                   ` (11 preceding siblings ...)
  2026-11-30 11:03 ` [PATCH v2 12/20] fstests: verify libblkid resolution of duplicate UUIDs Anand Jain
@ 2026-11-30 11:03 ` Anand Jain
  2026-11-30 11:03 ` [PATCH v2 14/20] fstests: introduce _require_metadata_uuid() helper Anand Jain
                   ` (6 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Anand Jain @ 2026-11-30 11:03 UTC (permalink / raw)
  To: fstests; +Cc: zlang, linux-btrfs, linux-ext4, linux-xfs, linux-f2fs-devel

Ensure that exportfs can correctly decode file handles on a cloned
filesystem across a mount cycle, by file handles generated on a
cloned device remain valid after mount cycle.

Reviewed-by: Zorro Lang <zlang@kernel.org>
Signed-off-by: Anand Jain <asj@kernel.org>
---
 tests/generic/905     | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++
 tests/generic/905.out |  2 ++
 2 files changed, 81 insertions(+)

diff --git a/tests/generic/905 b/tests/generic/905
new file mode 100644
index 000000000000..d69c613110db
--- /dev/null
+++ b/tests/generic/905
@@ -0,0 +1,79 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2026 Anand Jain <asj@kernel.org>.  All Rights Reserved.
+#
+# FS QA Test No. 905
+# Verify that file handles encoded on a cloned filesystem remain valid and
+# resolvable via open_by_handle across a mount cycle and mount order swap.
+
+. ./common/preamble
+
+_begin_fstest auto quick exportfs tempfsid
+
+_require_test
+_require_exportfs
+_require_loop
+_require_test_program "open_by_handle"
+
+_cleanup()
+{
+	cd /
+	rm -r -f $tmp.*
+	_unmount $mnt1 2>/dev/null
+	_unmount $mnt2 2>/dev/null
+	_destroy_cloned_loop_devs "${devs[@]}" 2> /dev/null
+}
+
+# Create test dir and test files, encode file handles and store to tmp file
+create_test_files()
+{
+	rm -rf $testdir
+	mkdir -p $testdir
+	$here/src/open_by_handle -cwp -o $tmp.handles_file $testdir $NUMFILES
+}
+
+# Attempt to read and decode the saved file handles on the targeted mount point.
+test_file_handles()
+{
+	local opt=$1
+	local when=$2
+
+	echo test_file_handles after $when
+	$here/src/open_by_handle $opt -i $tmp.handles_file $mnt2 $NUMFILES
+}
+
+rm -rf $TEST_DIR/$seq 2>/dev/null
+mkdir -p $TEST_DIR/$seq
+# Setup base loop device and its clone
+devs=()
+_create_cloned_loop_devs devs
+mnt1=$TEST_DIR/$seq/mnt1
+mnt2=$TEST_DIR/$seq/mnt2
+mkdir -p $mnt1
+mkdir -p $mnt2
+
+# Mount both identical UUID filesystems simultaneously
+_mount $(_common_dev_mount_options) $(_clone_mount_options) ${devs[0]} $mnt1 || \
+						_fail "Failed to mount dev1"
+_mount $(_common_dev_mount_options) $(_clone_mount_options) ${devs[1]} $mnt2 || \
+						_fail "Failed to mount dev2"
+
+NUMFILES=1
+testdir=$mnt2/testdir
+
+# Decode file handles of files/dir after cycle mount
+create_test_files
+
+# Cycle mounts and reverse initialization sequence to check if
+# file handle lookups are okay
+_unmount $mnt1
+_unmount $mnt2
+_mount $(_common_dev_mount_options) $(_clone_mount_options) ${devs[1]} $mnt2 || \
+						_fail "Failed to mount dev2"
+_mount $(_common_dev_mount_options) $(_clone_mount_options) ${devs[0]} $mnt1 || \
+						_fail "Failed to mount dev1"
+
+# Verify file handles can still be resolved post-mount-cycle
+test_file_handles -rp "cycle mount"
+
+_exit 0
diff --git a/tests/generic/905.out b/tests/generic/905.out
new file mode 100644
index 000000000000..234f5ec35863
--- /dev/null
+++ b/tests/generic/905.out
@@ -0,0 +1,2 @@
+QA output created by 905
+test_file_handles after cycle mount

-- 
2.43.0

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH v2 14/20] fstests: introduce _require_metadata_uuid() helper
  2026-11-30 11:03 [PATCH v2 00/20] fstests: tests for cloned filesystem validation and f_fsid v2 Anand Jain
                   ` (12 preceding siblings ...)
  2026-11-30 11:03 ` [PATCH v2 13/20] fstests: verify exportfs file handles on cloned filesystems Anand Jain
@ 2026-11-30 11:03 ` Anand Jain
  2026-11-30 11:03 ` [PATCH v2 15/20] fstests: add _change_metadata_uuid helper Anand Jain
                   ` (5 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Anand Jain @ 2026-11-30 11:03 UTC (permalink / raw)
  To: fstests; +Cc: zlang, linux-btrfs, linux-ext4, linux-xfs, linux-f2fs-devel

Add _require_metadata_uuid() to common/rc to check for the required
userspace tools (xfs_admin and btrfstune) on XFS and Btrfs, and verify
kernel metadata_uuid feature support on Btrfs before testing filesystem
UUID changes.

Reviewed-by: Zorro Lang <zlang@kernel.org>
Signed-off-by: Anand Jain <asj@kernel.org>
---
 common/rc | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/common/rc b/common/rc
index 5d28f6b3b780..1f58a15283cf 100644
--- a/common/rc
+++ b/common/rc
@@ -6582,6 +6582,24 @@ _require_unique_f_fsid()
 	esac
 }
 
+_require_metadata_uuid()
+{
+	case $FSTYP in
+	xfs)
+		# The xfs_admin utility is required to modify the filesystem UUID.
+		# Kernel support for metadata_uuid has been present since 4.16, so
+		# it is assumed to be available.
+		_require_command "$XFS_ADMIN_PROG" "xfs_admin"
+		;;
+	btrfs)
+		_require_fs_sysfs_feature_attr metadata_uuid
+		_require_command "$BTRFS_TUNE_PROG" "btrfstune"
+		;;
+	*)
+		_notrun "Require filesystem with metadata_uuid feature"
+		;;
+	esac
+}
 
 # Computes a percentage of the available space in a filesystem and
 # returns that quantity in MB. The percentage must not contain a percent

-- 
2.43.0

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH v2 15/20] fstests: add _change_metadata_uuid helper
  2026-11-30 11:03 [PATCH v2 00/20] fstests: tests for cloned filesystem validation and f_fsid v2 Anand Jain
                   ` (13 preceding siblings ...)
  2026-11-30 11:03 ` [PATCH v2 14/20] fstests: introduce _require_metadata_uuid() helper Anand Jain
@ 2026-11-30 11:03 ` Anand Jain
  2026-11-30 11:03 ` [PATCH v2 16/20] fstests: test UUID consistency for clones with metadata_uuid Anand Jain
                   ` (4 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Anand Jain @ 2026-11-30 11:03 UTC (permalink / raw)
  To: fstests; +Cc: zlang, linux-btrfs, linux-ext4, linux-xfs, linux-f2fs-devel

_change_metadata_uuid changes the UUID of the golden filesystem before it
is cloned.

Reviewed-by: Zorro Lang <zlang@kernel.org>
Signed-off-by: Anand Jain <asj@kernel.org>
---
 common/rc | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/common/rc b/common/rc
index 1f58a15283cf..22a5e2cfeadb 100644
--- a/common/rc
+++ b/common/rc
@@ -1577,6 +1577,23 @@ _scratch_resvblks()
 	esac
 }
 
+# Change the metadata UUID of the given device to a newly generated one.
+# Args:
+#   $1: Block device path to modify.
+_change_metadata_uuid()
+{
+	local dev=$1
+
+	case $FSTYP in
+	xfs)
+		$XFS_ADMIN_PROG -U generate $dev >> $seqres.full
+		;;
+	btrfs)
+		$BTRFS_TUNE_PROG -m $dev
+		;;
+	esac
+}
+
 # Create a small loop image, run an optional tuning function ($2) on it,
 # clone it, and attach both to loop devices, returned in ($1).
 # Args:

-- 
2.43.0

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH v2 16/20] fstests: test UUID consistency for clones with metadata_uuid
  2026-11-30 11:03 [PATCH v2 00/20] fstests: tests for cloned filesystem validation and f_fsid v2 Anand Jain
                   ` (14 preceding siblings ...)
  2026-11-30 11:03 ` [PATCH v2 15/20] fstests: add _change_metadata_uuid helper Anand Jain
@ 2026-11-30 11:03 ` Anand Jain
  2026-11-30 11:03 ` [PATCH v2 17/20] fstests: generic/744: use new helper _require_clone_mount() Anand Jain
                   ` (3 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Anand Jain @ 2026-11-30 11:03 UTC (permalink / raw)
  To: fstests; +Cc: zlang, linux-btrfs, linux-ext4, linux-xfs, linux-f2fs-devel

Btrfs and xfs uses the metadata_uuid superblock feature to change the
on-disk UUID without rewriting every block header. This patch adds a
sanity check to ensure UUID consistency when a filesystem with
metadata_uuid enabled is cloned.

Signed-off-by: Anand Jain <asj@kernel.org>
---
 tests/generic/906     | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++
 tests/generic/906.out |  6 +++++
 2 files changed, 80 insertions(+)

diff --git a/tests/generic/906 b/tests/generic/906
new file mode 100644
index 000000000000..66cdc1f23168
--- /dev/null
+++ b/tests/generic/906
@@ -0,0 +1,74 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2026 Anand Jain <asj@kernel.org>.  All Rights Reserved.
+#
+# FS QA Test No. 906
+#
+# Verify that the cloned filesystem UUID remains consistent, even when the
+# `metadata_uuid` feature is enabled.
+#
+
+. ./common/preamble
+. ./common/filter
+
+_begin_fstest auto quick mount tempfsid
+
+_require_test
+_require_loop
+_require_metadata_uuid
+
+_cleanup()
+{
+	cd /
+	rm -r -f $tmp.*
+	_unmount $mnt1 $mnt2 2>/dev/null
+	_destroy_cloned_loop_devs "${devs[@]}" 2> /dev/null
+}
+
+filter_pool()
+{
+	sed -e "s|${devs[0]}|DEV1|g" -e "s|${mnt1}|MNT1|g" \
+	    -e "s|${devs[1]}|DEV2|g" -e "s|${mnt2}|MNT2|g" | _filter_spaces
+}
+
+rm -rf $TEST_DIR/$seq 2>/dev/null
+mkdir -p $TEST_DIR/$seq
+# Create base loop device and its clone, applying the metadata_uuid tuning
+# callback to the base filesystem before the copy occurs.
+devs=()
+_create_cloned_loop_devs devs _change_metadata_uuid
+mnt1=$TEST_DIR/$seq/mnt1
+mnt2=$TEST_DIR/$seq/mnt2
+mkdir -p $mnt1
+mkdir -p $mnt2
+
+# Get the uuid from the source device
+fsuuid=$(blkid -s UUID -o value ${devs[0]})
+
+# Mount both clone and baseline
+_mount $(_common_dev_mount_options) $(_clone_mount_options) ${devs[0]} $mnt1 || \
+						_fail "Failed to mount dev1"
+_mount $(_common_dev_mount_options) $(_clone_mount_options) ${devs[1]} $mnt2 || \
+						_fail "Failed to mount dev2"
+
+findmnt -o SOURCE,TARGET,UUID "${devs[0]}" | tail -n +2 | \
+				sed -e "s/${fsuuid}/FSUUID/g" | filter_pool
+findmnt -o SOURCE,TARGET,UUID "${devs[1]}" | tail -n +2 | \
+				sed -e "s/${fsuuid}/FSUUID/g" | filter_pool
+
+# Cycle mounts and reverse the initialization order to ensure UUID tracking
+# doesn't mismatch or flip when metadata_uuid optimization is active.
+echo "**** mount cycle ****"
+_unmount $mnt1
+_unmount $mnt2
+_mount $(_common_dev_mount_options) $(_clone_mount_options) ${devs[1]} $mnt2 || \
+						_fail "Failed to mount dev2"
+_mount $(_common_dev_mount_options) $(_clone_mount_options) ${devs[0]} $mnt1 || \
+						_fail "Failed to mount dev1"
+
+findmnt -o SOURCE,TARGET,UUID "${devs[0]}" | tail -n +2 | \
+				sed -e "s/${fsuuid}/FSUUID/g" | filter_pool
+findmnt -o SOURCE,TARGET,UUID "${devs[1]}" | tail -n +2 | \
+				sed -e "s/${fsuuid}/FSUUID/g" | filter_pool
+
+_exit 0
diff --git a/tests/generic/906.out b/tests/generic/906.out
new file mode 100644
index 000000000000..b484c86d8e7f
--- /dev/null
+++ b/tests/generic/906.out
@@ -0,0 +1,6 @@
+QA output created by 906
+DEV1 MNT1 FSUUID
+DEV2 MNT2 FSUUID
+**** mount cycle ****
+DEV1 MNT1 FSUUID
+DEV2 MNT2 FSUUID

-- 
2.43.0

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH v2 17/20] fstests: generic/744: use new helper _require_clone_mount()
  2026-11-30 11:03 [PATCH v2 00/20] fstests: tests for cloned filesystem validation and f_fsid v2 Anand Jain
                   ` (15 preceding siblings ...)
  2026-11-30 11:03 ` [PATCH v2 16/20] fstests: test UUID consistency for clones with metadata_uuid Anand Jain
@ 2026-11-30 11:03 ` Anand Jain
  2026-11-30 11:03 ` [PATCH v2 18/20] fstests: generic/744: migrate to _create_cloned_loop_devs() Anand Jain
                   ` (2 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Anand Jain @ 2026-11-30 11:03 UTC (permalink / raw)
  To: fstests; +Cc: zlang, linux-btrfs, linux-ext4, linux-xfs, linux-f2fs-devel

Replace _require_duplicate_fsid() with the newly introduced
_require_clone_mount() helper to verify kernel support for mounting
cloned block devices with duplicate UUIDs.

Reviewed-by: Zorro Lang <zlang@kernel.org>
Signed-off-by: Anand Jain <asj@kernel.org>
---
 common/rc         | 14 --------------
 tests/generic/744 |  8 ++++----
 2 files changed, 4 insertions(+), 18 deletions(-)

diff --git a/common/rc b/common/rc
index 22a5e2cfeadb..4bd83cdc11f4 100644
--- a/common/rc
+++ b/common/rc
@@ -6304,20 +6304,6 @@ _random_file() {
 	echo "$basedir/$(ls -U $basedir | shuf -n 1)"
 }
 
-_require_duplicate_fsid()
-{
-	case "$FSTYP" in
-	"btrfs")
-		_require_fs_sysfs_feature_attr temp_fsid
-		;;
-	"ext4")
-		;;
-	*)
-		_notrun "$FSTYP does not support duplicate fsid"
-		;;
-	esac
-}
-
 # Can we find a program in the $PATH?
 _have_program() {
 	command -v "$1" &>/dev/null
diff --git a/tests/generic/744 b/tests/generic/744
index cda10e0f66ba..330d86ce826a 100755
--- a/tests/generic/744
+++ b/tests/generic/744
@@ -25,8 +25,7 @@ _cleanup()
 . ./common/filter
 . ./common/reflink
 
-# Modify as appropriate.
-_require_duplicate_fsid
+_require_clone_mount
 _require_test
 _require_block_device $TEST_DEV
 _require_test_reflink
@@ -66,11 +65,12 @@ loop_dev2=$(_create_loop_device "$loop_file2")
 clone_filesystem ${loop_dev1} ${loop_dev2}
 
 # Mounting original device
-_mount $loop_dev1 $mnt1
+_mount $(_common_dev_mount_options) $(_clone_mount_options) $loop_dev1 $mnt1
 $XFS_IO_PROG -fc 'pwrite -S 0x61 0 9000' $mnt1/foo | _filter_xfs_io
 
 # Mounting cloned device
-_mount $loop_dev2 $mnt2 || _fail "mount of cloned device failed"
+_mount $(_common_dev_mount_options) $(_clone_mount_options) $loop_dev2 $mnt2 \
+					|| _fail "mount of cloned device failed"
 
 # cp reflink across two different filesystems must fail
 _cp_reflink $mnt1/foo $mnt2/bar 2>&1 | _filter_test_dir

-- 
2.43.0

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH v2 18/20] fstests: generic/744: migrate to _create_cloned_loop_devs()
  2026-11-30 11:03 [PATCH v2 00/20] fstests: tests for cloned filesystem validation and f_fsid v2 Anand Jain
                   ` (16 preceding siblings ...)
  2026-11-30 11:03 ` [PATCH v2 17/20] fstests: generic/744: use new helper _require_clone_mount() Anand Jain
@ 2026-11-30 11:03 ` Anand Jain
  2026-11-30 11:03 ` [PATCH v2 19/20] fstests: _create_loop_device_like_bdev() remove unused variable Anand Jain
  2026-11-30 11:03 ` [PATCH v2 20/20] fstests: verify f_fsid for cloned filesystems Anand Jain
  19 siblings, 0 replies; 21+ messages in thread
From: Anand Jain @ 2026-11-30 11:03 UTC (permalink / raw)
  To: fstests; +Cc: zlang, linux-btrfs, linux-ext4, linux-xfs, linux-f2fs-devel

Switch generic/744 to use the common _create_cloned_loop_devs() helper
to format, modify, and clone the underlying loop devices, avoiding
open-coded clone setup and teardown logic.

Reviewed-by: Zorro Lang <zlang@kernel.org>
Signed-off-by: Anand Jain <asj@kernel.org>
---
 tests/generic/744 | 70 +++++++++++++++++++++----------------------------------
 1 file changed, 27 insertions(+), 43 deletions(-)

diff --git a/tests/generic/744 b/tests/generic/744
index 330d86ce826a..c522d6f46713 100755
--- a/tests/generic/744
+++ b/tests/generic/744
@@ -10,71 +10,55 @@
 . ./common/preamble
 _begin_fstest auto clone volume tempfsid
 
-_cleanup()
-{
-	cd /
-	rm -r -f $tmp.*
-
-	_unmount $mnt2 &> /dev/null
-	_unmount $mnt1 &> /dev/null
-	[ -b "$loop_dev2" ] && _destroy_loop_device $loop_dev2
-	[ -b "$loop_dev1" ] && _destroy_loop_device $loop_dev1
-	[ -n "$seq" ] && rm -rf $TEST_DIR/$seq
-}
-
 . ./common/filter
 . ./common/reflink
 
-_require_clone_mount
 _require_test
 _require_block_device $TEST_DEV
 _require_test_reflink
 _require_cp_reflink
 _require_loop
 
-clone_filesystem()
+_cleanup()
 {
-	local dev1=$1
-	local dev2=$2
-
-	_mkfs_dev $dev1
-
-	_mount $dev1 $mnt1
-	$XFS_IO_PROG -fc 'pwrite -S 0x61 0 9000' $mnt1/foo >> $seqres.full
-	_unmount $mnt1
+	cd /
+	rm -r -f $tmp.*
 
-	# device dump of $dev1 to $dev2
-	dd if=$dev1 of=$dev2 conv=fsync status=none || _fail "dd failed: $?"
+	_unmount $mnt2 &> /dev/null
+	_unmount $mnt1 &> /dev/null
+	_destroy_cloned_loop_devs "${devs[@]}" 2> /dev/null
 }
 
-[ -n "$seq" ] && rm -rf $TEST_DIR/$seq
-mkdir $TEST_DIR/$seq
+add_foo()
+{
+	local orig_dev="$1"
+	local temp_mnt="$TEST_DIR/$seq/temp_mnt"
+
+	mkdir -p $temp_mnt
+	_mount $(_common_dev_mount_options) $(_clone_mount_options) $orig_dev $temp_mnt
+	$XFS_IO_PROG -fc 'pwrite -S 0x61 0 9000' $temp_mnt/foo >> $seqres.full
+	$XFS_IO_PROG -c 'fsync' $temp_mnt/foo
+	_unmount $temp_mnt
+}
 
+rm -rf $TEST_DIR/$seq 2>/dev/null
+mkdir -p $TEST_DIR/$seq
+# Setup base loop device and its clone
+devs=()
+_create_cloned_loop_devs devs add_foo
 mnt1=$TEST_DIR/$seq/mnt1
 mnt2=$TEST_DIR/$seq/mnt2
-mkdir -p $mnt1 $mnt2
-
-loop_file1="$TEST_DIR/$seq/image1"
-truncate -s 300m "$loop_file1"
-loop_dev1=$(_create_loop_device "$loop_file1")
-
-loop_file2="$TEST_DIR/$seq/image2"
-truncate -s 300m "$loop_file2"
-loop_dev2=$(_create_loop_device "$loop_file2")
-
-clone_filesystem ${loop_dev1} ${loop_dev2}
+mkdir -p $mnt1
+mkdir -p $mnt2
 
 # Mounting original device
-_mount $(_common_dev_mount_options) $(_clone_mount_options) $loop_dev1 $mnt1
+_mount $(_common_dev_mount_options) $(_clone_mount_options) ${devs[0]} $mnt1
 $XFS_IO_PROG -fc 'pwrite -S 0x61 0 9000' $mnt1/foo | _filter_xfs_io
-
 # Mounting cloned device
-_mount $(_common_dev_mount_options) $(_clone_mount_options) $loop_dev2 $mnt2 \
+_mount $(_common_dev_mount_options) $(_clone_mount_options) ${devs[1]} $mnt2 \
 					|| _fail "mount of cloned device failed"
 
 # cp reflink across two different filesystems must fail
 _cp_reflink $mnt1/foo $mnt2/bar 2>&1 | _filter_test_dir
 
-# success, all done
-status=0
-exit
+_exit 0

-- 
2.43.0

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH v2 19/20] fstests: _create_loop_device_like_bdev() remove unused variable
  2026-11-30 11:03 [PATCH v2 00/20] fstests: tests for cloned filesystem validation and f_fsid v2 Anand Jain
                   ` (17 preceding siblings ...)
  2026-11-30 11:03 ` [PATCH v2 18/20] fstests: generic/744: migrate to _create_cloned_loop_devs() Anand Jain
@ 2026-11-30 11:03 ` Anand Jain
  2026-11-30 11:03 ` [PATCH v2 20/20] fstests: verify f_fsid for cloned filesystems Anand Jain
  19 siblings, 0 replies; 21+ messages in thread
From: Anand Jain @ 2026-11-30 11:03 UTC (permalink / raw)
  To: fstests; +Cc: zlang, linux-btrfs, linux-ext4, linux-xfs, linux-f2fs-devel

Remove unused local dev.

Reviewed-by: Zorro Lang <zlang@kernel.org>
Signed-off-by: Anand Jain <asj@kernel.org>
---
 common/rc | 1 -
 1 file changed, 1 deletion(-)

diff --git a/common/rc b/common/rc
index 4bd83cdc11f4..48aa2373369b 100644
--- a/common/rc
+++ b/common/rc
@@ -4829,7 +4829,6 @@ _create_loop_device_like_bdev()
 {
 	local file=$1
 	local bdev=$2
-	local dev
 	local blksize
 
 	test -b "$bdev" || \

-- 
2.43.0

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH v2 20/20] fstests: verify f_fsid for cloned filesystems
  2026-11-30 11:03 [PATCH v2 00/20] fstests: tests for cloned filesystem validation and f_fsid v2 Anand Jain
                   ` (18 preceding siblings ...)
  2026-11-30 11:03 ` [PATCH v2 19/20] fstests: _create_loop_device_like_bdev() remove unused variable Anand Jain
@ 2026-11-30 11:03 ` Anand Jain
  19 siblings, 0 replies; 21+ messages in thread
From: Anand Jain @ 2026-11-30 11:03 UTC (permalink / raw)
  To: fstests; +Cc: zlang, linux-btrfs, linux-ext4, linux-xfs, linux-f2fs-devel

Verify that the cloned filesystem provides an f_fsid that is persistent
across mount cycles, yet unique from the original filesystem's f_fsid.

Signed-off-by: Anand Jain <asj@kernel.org>
---
 tests/generic/908     | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++
 tests/generic/908.out |  2 ++
 2 files changed, 90 insertions(+)

diff --git a/tests/generic/908 b/tests/generic/908
new file mode 100644
index 000000000000..ae30c0c263e4
--- /dev/null
+++ b/tests/generic/908
@@ -0,0 +1,88 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2026 Anand Jain <asj@kernel.org>.  All Rights Reserved.
+#
+# FS QA Test No. 908
+# Check that the cloned filesystem provides an f_fsid that is persistent
+# across mount cycles if the block device maj:min remains unchanged.
+#
+# Currently, there are three different approaches for deriving statfs f_fsid:
+#   - XFS and F2FS: f_fsid is a hash of the uuid and dev_t.
+#   - Ext4: f_fsid is a hash of the uuid only.
+#   - Btrfs: f_fsid is a hash of the uuid for the original filesystem,
+#            and a hash of the uuid and dev_t for cloned filesystems.
+#            Mount order determines which is identified as the original
+#            versus the cloned filesystem.
+#
+# For Btrfs and Ext4, use external tools to update the uuid
+# and ensure a unique/consistent f_fsid for cloned filesystems.
+
+. ./common/preamble
+
+_begin_fstest auto quick mount tempfsid
+
+_require_test
+_require_loop
+
+_fixed_by_fs_commit btrfs df84f6c77377 \
+        "btrfs: use on-disk uuid for s_uuid in temp_fsid mounts"
+_fixed_by_fs_commit btrfs c2a74ed0494c \
+        "btrfs: derive f_fsid from on-disk fsuuid and dev_t"
+_fixed_by_fs_commit btrfs 72de4807ba84 \
+        "btrfs: derive f_fsid with dev_t only when temp_fsid is active"
+
+_cleanup()
+{
+	cd /
+	rm -r -f $tmp.*
+	umount $mnt1 $mnt2 2>/dev/null
+	_destroy_cloned_loop_devs "${devs[@]}" 2> /dev/null
+}
+
+rm -rf $TEST_DIR/$seq 2>/dev/null
+mkdir -p $TEST_DIR/$seq
+# Setup base loop device and its clone
+devs=()
+_create_cloned_loop_devs devs
+mnt1=$TEST_DIR/$seq/mnt1
+mnt2=$TEST_DIR/$seq/mnt2
+mkdir -p $mnt1
+mkdir -p $mnt2
+
+# Mount both filesystems simultaneously using mandatory clone mount options
+_mount $(_common_dev_mount_options) $(_clone_mount_options) ${devs[0]} $mnt1 || \
+						_fail "Failed to mount dev1"
+_mount $(_common_dev_mount_options) $(_clone_mount_options) ${devs[1]} $mnt2 || \
+						_fail "Failed to mount dev2"
+
+# Capture baseline filesystem IDs for comparison
+fsid_scratch=$(stat -f -c "%i" $mnt1)
+fsid_clone=$(stat -f -c "%i" $mnt2)
+
+# Verify that the fsids remain stable after a mount cycle, even when the
+# mount order is reversed.
+_unmount $mnt1
+_unmount $mnt2
+_mount $(_common_dev_mount_options) $(_clone_mount_options) ${devs[1]} $mnt2 || \
+						_fail "Failed to mount dev2"
+_mount $(_common_dev_mount_options) $(_clone_mount_options) ${devs[0]} $mnt1 || \
+						_fail "Failed to mount dev1"
+
+# Compare post mount-cycle values against the baseline
+fsid_mnt1=$(stat -f -c "%i" $mnt2)
+fsid_mnt2=$(stat -f -c "%i" $mnt1)
+
+case "$FSTYP" in
+btrfs)
+	[[ "$fsid_mnt1" != "$fsid_scratch" ]] && \
+		_fail "fsid does not match the original filesystem"
+	;;
+xfs|f2fs|ext4)
+	[[ "$fsid_mnt1" != "$fsid_clone" ]] && \
+		_fail "Cloned filesystem f_fsid is inconsistent"
+	;;
+esac
+
+echo Silence is golden
+
+_exit 0
diff --git a/tests/generic/908.out b/tests/generic/908.out
new file mode 100644
index 000000000000..e07ef7c28d50
--- /dev/null
+++ b/tests/generic/908.out
@@ -0,0 +1,2 @@
+QA output created by 908
+Silence is golden

-- 
2.43.0

^ permalink raw reply related	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2026-11-30 11:04 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-30 11:03 [PATCH v2 00/20] fstests: tests for cloned filesystem validation and f_fsid v2 Anand Jain
2026-11-30 11:03 ` [PATCH v2 01/20] fstests: introduce _require_clone_mount() helper Anand Jain
2026-11-30 11:03 ` [PATCH v2 02/20] fstests: introduce _create_cloned_loop_devs() helper Anand Jain
2026-11-30 11:03 ` [PATCH v2 03/20] fstests: add _clone_mount_options() helper Anand Jain
2026-11-30 11:03 ` [PATCH v2 04/20] fstests: add FSNOTIFYWAIT_PROG Anand Jain
2026-11-30 11:03 ` [PATCH v2 05/20] fstests: add _require_fanotify Anand Jain
2026-11-30 11:03 ` [PATCH v2 06/20] fstests: add _require_unique_f_fsid() helper Anand Jain
2026-11-30 11:03 ` [PATCH v2 07/20] fstests: add SEMANAGE_PROG Anand Jain
2026-11-30 11:03 ` [PATCH v2 08/20] fstests: verify fanotify isolation on cloned filesystems Anand Jain
2026-11-30 11:03 ` [PATCH v2 09/20] fstests: introduce helper _scratch_mkfs_uuid() Anand Jain
2026-11-30 11:03 ` [PATCH v2 10/20] fstests: add helpers to verify the expected f_fsid Anand Jain
2026-11-30 11:03 ` [PATCH v2 11/20] fstests: verify statfs f_fsid is derived from the filesystem UUID Anand Jain
2026-11-30 11:03 ` [PATCH v2 12/20] fstests: verify libblkid resolution of duplicate UUIDs Anand Jain
2026-11-30 11:03 ` [PATCH v2 13/20] fstests: verify exportfs file handles on cloned filesystems Anand Jain
2026-11-30 11:03 ` [PATCH v2 14/20] fstests: introduce _require_metadata_uuid() helper Anand Jain
2026-11-30 11:03 ` [PATCH v2 15/20] fstests: add _change_metadata_uuid helper Anand Jain
2026-11-30 11:03 ` [PATCH v2 16/20] fstests: test UUID consistency for clones with metadata_uuid Anand Jain
2026-11-30 11:03 ` [PATCH v2 17/20] fstests: generic/744: use new helper _require_clone_mount() Anand Jain
2026-11-30 11:03 ` [PATCH v2 18/20] fstests: generic/744: migrate to _create_cloned_loop_devs() Anand Jain
2026-11-30 11:03 ` [PATCH v2 19/20] fstests: _create_loop_device_like_bdev() remove unused variable Anand Jain
2026-11-30 11:03 ` [PATCH v2 20/20] fstests: verify f_fsid for cloned filesystems Anand Jain

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox