Skip to contentSkip to conversation

generic: test overlayfs casefold flags and whiteouts

PATCH New Hungyu Lin 1 participant 3 messages Oct 31

lore
Share & tools
lore

Hungyu Lin

author
#0 lore raw

v2 cover generic: test overlayfs casefold flags and whiteouts

Add coverage for directory casefold flag changes and whiteout creation on casefolded overlayfs layers, following the setup in generic/783. The tests run on a casefold-capable backing filesystem and mount their own overlay.

The tests cover patches 2 and 3 of the following kernel series:
https://lore.kernel.org/linux-unionfs/[email protected]/

Tested on arm64 under QEMU with ext4 and tmpfs as the backing filesystems. The baseline kernel was overlayfs ovl-fixes at 1d27da7de3f7. The fixed kernel used the same baseline with all three patches from the series.

On both backing filesystems:
- generic/783 passes before and after the fixes.
- generic/998 fails before the fixes because a casefold flag change succeeds, and passes with the fixes.
- generic/999 fails before the fixes because removing a lower-only file returns EINVAL, and passes with the fixes.

The runtime tests used fstests at 22348afe338c. Both patches also apply to for-next at d07dca72d245 and pass bash -n there; the runtime tests were not repeated on that fstests base.

The tests also need "ovl: check the casefold flag of directories only", which is included in the kernel baseline above. The fix hints use placeholder IDs pending final kernel commit IDs. The test numbers 998 and 999 are temporary.

Changes in v2:
- Move the flag test into test_casefold() and call the enabled and disabled cases explicitly, as suggested by Amir.
- Add Amir's Reviewed-by to both patches.

v1: https://lore.kernel.org/r/[email protected]

Thanks,
Hungyu

Hungyu Lin (2):
generic: test overlayfs casefold flag changes
generic: test whiteouts on casefolded overlay layers

 tests/generic/998     | 147 ++++++++++++++++++++++++++++++++++++++++++++
 tests/generic/998.out |   3 +
 tests/generic/999     | 148 ++++++++++++++++++++++++++++++++++++++++++++++
 tests/generic/999.out |   2 +
 4 files changed, 300 insertions(+)
author
#1 lore raw

PATCH v2 1/2 generic: test overlayfs casefold flag changes

Changing the casefold flag of an overlay directory can leave its upper and the mount with different casefold states and break lookups.

Check that chattr +F/-F requests which would change that state fail with EOPNOTSUPP, preserve the casefold flag and leave files accessible. Cover lower-only directories with and without contents and the overlay root, with both casefold-enabled and casefold-disabled layers. Keep no-change requests as successful controls.

This covers "ovl: do not let chattr change the casefold flag" from the casefold fixes series linked below.

The test also reads regular files on a casefolded overlay. This needs the separate "ovl: check the casefold flag of directories only" fix, included in the tested overlayfs ovl-fixes baseline at 1d27da7de3f7.

---
 tests/generic/998     |  147 ++++++++++++++++++++++++++++++++++++++++++++++++
 tests/generic/998.out |    3 +++
 2 files changed, 150 insertions(+)
tests/generic/998 new file +147 -0
new file mode 100755
index 0000000..26a4a19
@@ -0,0 +1,147 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2026 Hungyu Lin.  All Rights Reserved.
+#
+# FS QA Test 998
+#
+# Check that rejected casefold changes leave overlay directory casefold
+# flags unchanged and existing files accessible.
+#
+. ./common/preamble
+_begin_fstest auto quick ioctl casefold
+
+_cleanup()
+{
+	cd /
+	[ -n "$merge" ] && _unmount "$merge" 2>/dev/null
+	rm -f $tmp.*
+}
+
+. ./common/filter
+. ./common/casefold
+
+_exclude_fs overlay
+_require_extra_fs overlay
+_require_scratch
+_require_scratch_casefold
+_fixed_by_kernel_commit xxxxxxxxxxxx "ovl: do not let chattr change the casefold flag"
+_fixed_by_kernel_commit xxxxxxxxxxxx \
+	"ovl: check the casefold flag of directories only"
+
+check_casefold()
+{
+	local path=$1
+	local expected=$2
+	local expected_state=disabled
+	local flags
+	local actual=0
+
+	[ "$expected" -eq 1 ] && expected_state=enabled
+	flags=$($LSATTR_PROG -d "$path" 2> $tmp.err) || {
+		cat $tmp.err >> $seqres.full
+		_fail "cannot read flags on $path"
+	}
+	flags=${flags%% *}
+	echo "lsattr $path: $flags" >> $seqres.full
+	[[ "$flags" == *F* ]] && actual=1
+	[ "$actual" -eq "$expected" ] || \
+		_fail "$path: expected casefold $expected_state, got flags $flags"
+}
+
+reject_casefold_change()
+{
+	local change=$1
+	local path=$2
+	local ret
+
+	$CHATTR_PROG "$change" "$path" > $tmp.err 2>&1
+	ret=$?
+	echo "chattr $change $path: exit $ret" >> $seqres.full
+	cat $tmp.err >> $seqres.full
+	[ "$ret" -ne 0 ] || \
+		_fail "chattr $change $path succeeded, expected EOPNOTSUPP"
+	# Check the SETFLAGS error, rather than accepting any chattr failure.
+	grep -Fq \
+		-e "Operation not supported while setting flags on $path" \
+		-e "Not supported while setting flags on $path" \
+		$tmp.err || \
+		_fail "chattr $change $path: expected EOPNOTSUPP, got exit $ret: $(cat $tmp.err)"
+}
+
+test_casefold()
+{
+	local folded=$1
+
+	root=$SCRATCH_MNT/ovl-$folded
+	lower=$root/lower
+	upper=$root/upper
+	work=$root/work
+	merge=$root/merge
+	mkdir "$root" || _fail "cannot create $root"
+	if [ "$folded" -eq 1 ]; then
+		_casefold_set_attr "$root" >> $seqres.full 2>&1 || \
+			_notrun "cannot enable casefold on the scratch filesystem"
+		change=-F
+		same=+F
+	else
+		change=+F
+		same=-F
+	fi
+	mkdir "$lower" "$upper" "$work" "$merge" || \
+		_fail "cannot create overlay directories"
+	mkdir "$lower/empty" "$lower/dir" || \
+		_fail "cannot create lower directories"
+	cp $tmp.data "$lower/dir/file" || _fail "cannot create lower file"
+	cp $tmp.data "$lower/file" || _fail "cannot create lower file"
+
+	if [ "$folded" -eq 1 ]; then
+		_mount -t overlay overlay "$merge" \
+			-o lowerdir="$lower",upperdir="$upper",workdir="$work" \
+			>> $seqres.full 2>&1 || \
+			_notrun "overlayfs does not support casefold enabled layers"
+	else
+		_mount -t overlay overlay "$merge" \
+			-o lowerdir="$lower",upperdir="$upper",workdir="$work" \
+			>> $seqres.full 2>&1 || _fail "cannot mount overlay"
+	fi
+
+	# A lower-only directory would be copied up as an empty upper directory,
+	# even when its merged view contains files. The upper root is also empty.
+	for path in "$merge/empty" "$merge/dir" "$merge"; do
+		check_casefold "$path" "$folded"
+		reject_casefold_change "$change" "$path"
+		check_casefold "$path" "$folded"
+		cmp $tmp.data "$merge/file" >> $seqres.full 2>&1 || \
+			_fail "$merge/file: not readable with expected contents after chattr $change $path"
+		cmp $tmp.data "$merge/dir/file" >> $seqres.full 2>&1 || \
+			_fail "$merge/dir/file: not readable with expected contents after chattr $change $path"
+	done
+
+	# chattr still issues SETFLAGS for a no-change request.
+	for path in "$merge/empty" "$merge/dir" "$merge"; do
+		echo "chattr $same $path" >> $seqres.full
+		$CHATTR_PROG "$same" "$path" >> $seqres.full 2>&1 || \
+			_fail "chattr $same $path: expected success for unchanged casefold state, got exit $?"
+		check_casefold "$path" "$folded"
+	done
+	_unmount "$merge" || _fail "cannot unmount overlay"
+	merge=
+	cmp $tmp.data "$lower/file" >> $seqres.full 2>&1 || \
+		_fail "$lower/file: not readable with expected contents"
+	cmp $tmp.data "$lower/dir/file" >> $seqres.full 2>&1 || \
+		_fail "$lower/dir/file: not readable with expected contents"
+}
+
+_scratch_mkfs_casefold >> $seqres.full 2>&1 || \
+	_fail "cannot format the casefold scratch filesystem"
+_scratch_mount_casefold || _fail "cannot mount the casefold scratch filesystem"
+printf 'sentinel\n' > $tmp.data
+
+# Try the enabled mount first so kernels without overlay casefold support
+# skip before reaching the actual attribute-change checks.
+echo "Casefold enabled" | tee -a $seqres.full
+test_casefold 1
+echo "Casefold disabled" | tee -a $seqres.full
+test_casefold 0
+
+_exit 0
tests/generic/998.out new file +3 -0
new file mode 100644
index 0000000..9f5c8b0
@@ -0,0 +1,3 @@
+QA output created by 998
+Casefold enabled
+Casefold disabled
author
#2 lore raw

PATCH v2 2/2 generic: test whiteouts on casefolded overlay layers

In reply to Hungyu Lin

Whiteout creation in casefolded directories can fail when removing names that exist in a lower layer.

Exercise unlink and rmdir for lower-only names, a copied-up file and a merged directory, including lookups with different ASCII case. Also recursively remove a populated lower directory. Check that removed names stay hidden after recreation and a mount cycle, while the surviving file and the lower layer remain unchanged.

This covers "ovl: fix whiteout creation in casefolded directories" from the casefold fixes series linked below.

Regular-file lookup and copy-up also need the separate "ovl: check the casefold flag of directories only" fix, included in the tested overlayfs ovl-fixes baseline at 1d27da7de3f7.

---
 tests/generic/999     |  148 ++++++++++++++++++++++++++++++++++++++++++++++++
 tests/generic/999.out |    2 ++
 2 files changed, 150 insertions(+)
tests/generic/999 new file +148 -0
new file mode 100755
index 0000000..75e13b5
@@ -0,0 +1,148 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2026 Hungyu Lin.  All Rights Reserved.
+#
+# FS QA Test 999
+#
+# Check removal of files and directories from casefolded overlay layers,
+# including copied-up files, merged directories and recursive removal.
+#
+. ./common/preamble
+_begin_fstest auto quick dir casefold
+
+_cleanup()
+{
+	cd /
+	[ -n "$merge" ] && _unmount "$merge" 2>/dev/null
+	rm -f $tmp.*
+}
+
+. ./common/filter
+. ./common/casefold
+
+_exclude_fs overlay
+_require_extra_fs overlay
+_require_scratch
+_require_scratch_casefold
+_fixed_by_kernel_commit xxxxxxxxxxxx "ovl: fix whiteout creation in casefolded directories"
+_fixed_by_kernel_commit xxxxxxxxxxxx \
+	"ovl: check the casefold flag of directories only"
+
+mount_overlay()
+{
+	_mount -t overlay overlay "$merge" \
+		-o lowerdir="$lower",upperdir="$upper",workdir="$work"
+}
+
+check_absent()
+{
+	local name=$1
+	local ret
+
+	stat "$merge/$name" > $tmp.stat 2>&1
+	ret=$?
+	echo "stat $merge/$name: exit $ret" >> $seqres.full
+	cat $tmp.stat >> $seqres.full
+	[ "$ret" -ne 0 ] || _fail "$name: expected ENOENT, stat succeeded"
+	grep -q ': No such file or directory$' $tmp.stat || \
+		_fail "$name: expected ENOENT, got $(cat $tmp.stat)"
+}
+
+check_view()
+{
+	local phase=$1
+	local name
+
+	echo "Checking merged view $phase" >> $seqres.full
+	for name in lowerfile anotherfile copyfile lowerdir mergeddir tree upperonly; do
+		check_absent "$name"
+		check_absent "$(printf '%s' "$name" | tr a-z A-Z)"
+	done
+	cmp $tmp.data "$merge/keep" >> $seqres.full 2>&1 || \
+		_fail "$merge/keep: not readable with expected contents $phase"
+	ls -1 "$merge" > $tmp.names || _fail "cannot list $merge $phase"
+	printf 'keep\n' > $tmp.expected
+	diff -u $tmp.expected $tmp.names >> $seqres.full 2>&1 || \
+		_fail "$merge: expected only keep $phase (directory listing in $seqres.full)"
+}
+
+_scratch_mkfs_casefold >> $seqres.full 2>&1 || \
+	_fail "cannot format the casefold scratch filesystem"
+_scratch_mount_casefold || _fail "cannot mount the casefold scratch filesystem"
+root=$SCRATCH_MNT/ovl
+lower=$root/lower
+upper=$root/upper
+work=$root/work
+merge=$root/merge
+mkdir "$root" || _fail "cannot create $root"
+_casefold_set_attr "$root" >> $seqres.full 2>&1 || \
+	_notrun "cannot enable casefold on the scratch filesystem"
+mkdir "$lower" "$upper" "$work" "$merge" || \
+	_fail "cannot create overlay directories"
+
+printf 'lower data\n' > $tmp.data
+printf 'upper data\n' > $tmp.upper
+for name in lowerfile anotherfile copyfile keep; do
+	cp $tmp.data "$lower/$name" || _fail "cannot create lower $name"
+done
+mkdir "$lower/lowerdir" "$lower/mergeddir" "$lower/tree" "$upper/mergeddir" || \
+	_fail "cannot prepare lower and merged directories"
+for name in one two; do
+	cp $tmp.data "$lower/tree/$name" || _fail "cannot create lower tree/$name"
+done
+cp $tmp.upper "$upper/upperonly" || _fail "cannot create upper-only file"
+mount_overlay >> $seqres.full 2>&1 || \
+	_notrun "overlayfs does not support casefold enabled layers"
+
+# Copy up through the overlay, without changing the backing layers directly.
+cat $tmp.upper > "$merge/copyfile" || _fail "copy-up write failed"
+cmp $tmp.upper "$upper/copyfile" >> $seqres.full 2>&1 || \
+	_fail "copyfile was not copied up with the expected data"
+
+# The first removal is a control that does not need a lower whiteout.
+rm "$merge/upperonly" || \
+	_fail "cannot remove upper-only file"
+rm "$merge/lowerfile" || \
+	_fail "cannot remove lower-only file"
+rm "$merge/ANOTHERFILE" || \
+	_fail "cannot remove another lower-only file using different case"
+rm "$merge/COPYFILE" || \
+	_fail "cannot remove copied-up file using different case"
+rmdir "$merge/LOWERDIR" || \
+	_fail "cannot remove lower-only directory using different case"
+rmdir "$merge/mergeddir" || \
+	_fail "cannot remove merged directory"
+# Removing the children leaves whiteouts in the copied-up directory.
+rm -r "$merge/TREE" || _fail "cannot recursively remove lower directory"
+check_view "after removal"
+
+cat $tmp.upper > "$merge/LOWERFILE" || _fail "cannot recreate removed name"
+cmp $tmp.upper "$merge/lowerfile" >> $seqres.full 2>&1 || \
+	_fail "recreated name is not accessible with different case"
+rm "$merge/lowerfile" || \
+	_fail "cannot remove recreated name"
+check_view "after recreating and removing a name"
+
+_unmount "$merge" || _fail "cannot unmount overlay"
+mount_overlay >> $seqres.full 2>&1 || _fail "cannot remount overlay"
+check_view "after remount"
+_unmount "$merge" || _fail "cannot unmount overlay"
+merge=
+
+for name in lowerfile anotherfile copyfile keep; do
+	cmp $tmp.data "$lower/$name" >> $seqres.full 2>&1 || \
+		_fail "$lower/$name: not readable with expected contents"
+done
+for name in lowerdir mergeddir tree; do
+	[ -d "$lower/$name" ] || {
+		stat "$lower/$name" >> $seqres.full 2>&1
+		_fail "$lower/$name: expected the lower directory to remain"
+	}
+done
+for name in one two; do
+	cmp $tmp.data "$lower/tree/$name" >> $seqres.full 2>&1 || \
+		_fail "$lower/tree/$name: not readable with expected contents"
+done
+
+echo "Silence is golden"
+_exit 0
tests/generic/999.out new file +2 -0
new file mode 100644
index 0000000..3b276ca
@@ -0,0 +1,2 @@
+QA output created by 999
+Silence is golden