Skip to contentSkip to conversation

fstests: tests for cloned filesystem validation and f_fsid v2

PATCH New Anand Jain 1 participant 21 messages Nov 30 Btrfs file system

lore
Share & tools
lore

Anand Jain

author
#0 lore raw

v2 cover fstests: tests for cloned filesystem validation and f_fsid v2

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

---
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,

Signature · 1 line
Anand Jain <[email protected]>
author
#1 lore raw

PATCH v2 1/20 fstests: introduce _require_clone_mount() helper

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.

---
 common/rc | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
common/rc +15 -0
index 750a8d836ccd..e6d2acf84dc6 100644
@@ -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()
Signature · 1 line
2.43.0
author
#2 lore raw

PATCH v2 2/20 fstests: introduce _create_cloned_loop_devs() helper

In reply to Anand Jain

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.

---
 common/rc | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 66 insertions(+)
common/rc +66 -0
index e6d2acf84dc6..02d9a3562c3d 100644
@@ -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
Signature · 1 line
2.43.0
author
#3 lore raw

PATCH v2 3/20 fstests: add _clone_mount_options() helper

In reply to Anand Jain

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

---
 common/rc | 13 +++++++++++++
 1 file changed, 13 insertions(+)
common/rc +13 -0
index 02d9a3562c3d..83a371fd7f48 100644
@@ -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
Signature · 1 line
2.43.0
author
#4 lore raw

PATCH v2 4/20 fstests: add FSNOTIFYWAIT_PROG

In reply to Anand Jain

Define FSNOTIFYWAIT_PROG for an upcoming test case that uses fsnotifywait.

---
 common/config | 1 +
 1 file changed, 1 insertion(+)
common/config +1 -0
index 69e5d83319b8..76b43b8c6ad9 100644
@@ -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.
 #
Signature · 1 line
2.43.0
author
#5 lore raw

PATCH v2 5/20 fstests: add _require_fanotify

In reply to Anand Jain

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

---
 common/rc     | 16 ++++++++++++++++
 src/Makefile  |  1 +
 src/feature.c | 42 +++++++++++++++++++++++++++++++++++++++---
 3 files changed, 56 insertions(+), 3 deletions(-)
common/rc +16 -0
index 83a371fd7f48..47079bc0c60e 100644
@@ -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
src/Makefile +1 -0
index a1fc38d88b8a..a6cfafd57878 100644
@@ -108,6 +108,7 @@ endif
 
 ifeq ($(HAVE_FANOTIFY_FID),yes)
      LINUX_TARGETS += fs-monitor
+     LCFLAGS += -DHAVE_FANOTIFY_FID
 endif
 
 ifeq ($(HAVE_LIBBTRFSUTIL), true)
src/feature.c +39 -3

94 lines not on this page · raw message

Signature · 1 line
2.43.0
author
#6 lore raw

PATCH v2 6/20 fstests: add _require_unique_f_fsid() helper

In reply to Anand Jain

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.

---
 common/rc | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)
common/rc +27 -0
index 47079bc0c60e..52f884902c7c 100644
@@ -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/[email protected]/
+_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 ("%").
Signature · 1 line
2.43.0
author
#7 lore raw

PATCH v2 7/20 fstests: add SEMANAGE_PROG

In reply to Anand Jain

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

---
 common/config | 1 +
 1 file changed, 1 insertion(+)
common/config +1 -0
index 76b43b8c6ad9..e8fecc168e5a 100644
@@ -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.
 #
Signature · 1 line
2.43.0
author
#8 lore raw

PATCH v2 8/20 fstests: verify fanotify isolation on cloned filesystems

In reply to Anand Jain

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.

---
 tests/generic/901     | 143 ++++++++++++++++++++++++++++++++++++++++++++++++++
 tests/generic/901.out |   7 +++
 2 files changed, 150 insertions(+)
tests/generic/901 new file +143 -0
new file mode 100644
index 000000000000..d16e733f1c9a
@@ -0,0 +1,143 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2026 Anand Jain <[email protected]>.  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
tests/generic/901.out new file +7 -0
new file mode 100644
index 000000000000..414e12d10b27
@@ -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
Signature · 1 line
2.43.0
author
#9 lore raw

PATCH v2 9/20 fstests: introduce helper _scratch_mkfs_uuid()

In reply to Anand Jain
---
 common/rc | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)
common/rc +30 -0
index 52f884902c7c..6f09739c3dba 100644
@@ -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()
Signature · 1 line
2.43.0
author
#10 lore raw

PATCH v2 10/20 fstests: add helpers to verify the expected f_fsid

In reply to Anand Jain

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.

---
 common/rc | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
common/rc +31 -0
index 6f09739c3dba..5d28f6b3b780 100644
@@ -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
Signature · 1 line
2.43.0
author
#11 lore raw

PATCH v2 11/20 fstests: verify statfs f_fsid is derived from the filesystem UUID

In reply to Anand Jain

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.

---
 tests/generic/902     | 38 ++++++++++++++++++++++++++++++++++++++
 tests/generic/902.out |  2 ++
 2 files changed, 40 insertions(+)
tests/generic/902 new file +38 -0
new file mode 100644
index 000000000000..44dd685a887b
@@ -0,0 +1,38 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2026 Anand Jain <[email protected]>.  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
tests/generic/902.out new file +2 -0
new file mode 100644
index 000000000000..e20395365cb5
@@ -0,0 +1,2 @@
+QA output created by 902
+Silence is golden
Signature · 1 line
2.43.0
author
#12 lore raw

PATCH v2 12/20 fstests: verify libblkid resolution of duplicate UUIDs

In reply to Anand Jain

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

---
 tests/generic/903     | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++
 tests/generic/903.out |  6 +++++
 2 files changed, 77 insertions(+)
tests/generic/903 new file +71 -0
new file mode 100644
index 000000000000..915a0a07f476
@@ -0,0 +1,71 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2026 Anand Jain <[email protected]>.  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
tests/generic/903.out new file +6 -0
new file mode 100644
index 000000000000..7683506e1c94
@@ -0,0 +1,6 @@
+QA output created by 903
+DEV1 MNT1 FSUUID
+DEV2 MNT2 FSUUID
+**** mount cycle ****
+DEV1 MNT1 FSUUID
+DEV2 MNT2 FSUUID
Signature · 1 line
2.43.0
author
#13 lore raw

PATCH v2 13/20 fstests: verify exportfs file handles on cloned filesystems

In reply to Anand Jain

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.

---
 tests/generic/905     | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++
 tests/generic/905.out |  2 ++
 2 files changed, 81 insertions(+)
tests/generic/905 new file +79 -0
new file mode 100644
index 000000000000..d69c613110db
@@ -0,0 +1,79 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2026 Anand Jain <[email protected]>.  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
tests/generic/905.out new file +2 -0
new file mode 100644
index 000000000000..234f5ec35863
@@ -0,0 +1,2 @@
+QA output created by 905
+test_file_handles after cycle mount
Signature · 1 line
2.43.0
author
#14 lore raw

PATCH v2 14/20 fstests: introduce _require_metadata_uuid() helper

In reply to Anand Jain

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.

---
 common/rc | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
common/rc +18 -0
index 5d28f6b3b780..1f58a15283cf 100644
@@ -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
Signature · 1 line
2.43.0
author
#15 lore raw

PATCH v2 15/20 fstests: add _change_metadata_uuid helper

In reply to Anand Jain

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

---
 common/rc | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
common/rc +17 -0
index 1f58a15283cf..22a5e2cfeadb 100644
@@ -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:
Signature · 1 line
2.43.0
author
#16 lore raw

PATCH v2 16/20 fstests: test UUID consistency for clones with metadata_uuid

In reply to Anand Jain

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.

---
 tests/generic/906     | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++
 tests/generic/906.out |  6 +++++
 2 files changed, 80 insertions(+)
tests/generic/906 new file +74 -0
new file mode 100644
index 000000000000..66cdc1f23168
@@ -0,0 +1,74 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2026 Anand Jain <[email protected]>.  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
tests/generic/906.out new file +6 -0
new file mode 100644
index 000000000000..b484c86d8e7f
@@ -0,0 +1,6 @@
+QA output created by 906
+DEV1 MNT1 FSUUID
+DEV2 MNT2 FSUUID
+**** mount cycle ****
+DEV1 MNT1 FSUUID
+DEV2 MNT2 FSUUID
Signature · 1 line
2.43.0
author
#17 lore raw

PATCH v2 17/20 fstests: generic/744: use new helper _require_clone_mount()

In reply to Anand Jain

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

---
 common/rc         | 14 --------------
 tests/generic/744 |  8 ++++----
 2 files changed, 4 insertions(+), 18 deletions(-)
common/rc +0 -14
index 22a5e2cfeadb..4bd83cdc11f4 100644
@@ -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
tests/generic/744 +4 -4
index cda10e0f66ba..330d86ce826a 100755
@@ -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
Signature · 1 line
2.43.0
author
#18 lore raw

PATCH v2 18/20 fstests: generic/744: migrate to _create_cloned_loop_devs()

In reply to Anand Jain

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.

---
 tests/generic/744 | 70 +++++++++++++++++++++----------------------------------
 1 file changed, 27 insertions(+), 43 deletions(-)
tests/generic/744 +27 -43
index 330d86ce826a..c522d6f46713 100755
@@ -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
Signature · 1 line
2.43.0
author
#19 lore raw

PATCH v2 19/20 fstests: _create_loop_device_like_bdev() remove unused variable

In reply to Anand Jain

Remove unused local dev.

---
 common/rc | 1 -
 1 file changed, 1 deletion(-)
common/rc +0 -1
index 4bd83cdc11f4..48aa2373369b 100644
@@ -4829,7 +4829,6 @@ _create_loop_device_like_bdev()
 {
 	local file=$1
 	local bdev=$2
-	local dev
 	local blksize
 
 	test -b "$bdev" || \
Signature · 1 line
2.43.0
author
#20 lore raw

PATCH v2 20/20 fstests: verify f_fsid for cloned filesystems

In reply to Anand Jain

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

---
 tests/generic/908     | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++
 tests/generic/908.out |  2 ++
 2 files changed, 90 insertions(+)
tests/generic/908 new file +88 -0
new file mode 100644
index 000000000000..ae30c0c263e4
@@ -0,0 +1,88 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2026 Anand Jain <[email protected]>.  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
tests/generic/908.out new file +2 -0
new file mode 100644
index 000000000000..e07ef7c28d50
@@ -0,0 +1,2 @@
+QA output created by 908
+Silence is golden
Signature · 1 line
2.43.0