Skip to contentSkip to conversation

ext4/064: add regression test for delalloc remount leak

PATCH In review guzebing 3 participants 3 messages Aug 18 – Sep 5

lore
Share & tools
lore

guzebing

author
#0 lore raw

PATCH 1/1 ext4/064: add regression test for delalloc remount leak

A delalloc filesystem rejects a remount with nodelalloc, but ext4 used to apply the option change before rejecting the remount. Concurrent buffered writes and truncates can observe the transient nodelalloc state and fail to release delayed allocation reservations. The leaked reservations are then reported when the inodes are evicted during unmount.

Add an ext4 regression test that starts concurrent write/truncate workers and an expected-failing remount,nodelalloc worker, stops them after a short stress window, and checks dmesg for leaked delayed allocation reservations.

The proposed kernel fix is still under review:
https://lore.kernel.org/linux-ext4/[email protected]/

Local validation showed that the test fails without the proposed kernel fix, with i_reserved_data_blocks not cleared warnings during unmount, and passes with the proposed fix applied.

---
 tests/ext4/064     | 216 +++++++++++++++++++++++++++++++++++++++++++++
 tests/ext4/064.out |   2 +
 2 files changed, 218 insertions(+)
 create mode 100755 tests/ext4/064
 create mode 100644 tests/ext4/064.out
tests/ext4/064 new file +216 -0
new file mode 100755
index 00000000..5d43764c
@@ -0,0 +1,216 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2026 guzebing.  All Rights Reserved.
+#
+# FS QA Test No. ext4/064
+#
+# Exercise rejected delalloc to nodelalloc remounts while buffered writes and
+# truncates are active.  A remount used to clear EXT4_MOUNT_DELALLOC before
+# rejecting the transition, so a concurrent truncate could fail to release
+# delayed allocation reservations.  The leaked inode reservation is reported
+# when the inode is evicted during unmount.
+#
+# This is a regression test for the issue fixed by the proposed patch:
+# "ext4: reject delalloc to nodelalloc remount before applying options"
+# https://lore.kernel.org/linux-ext4/[email protected]/
+#
+. ./common/preamble
+_begin_fstest auto stress mount
+
+writer_pids=()
+remounter_pid=
+stop_file=$tmp.stop
+worker_error=$tmp.worker_error
+remounter_error=$tmp.remounter_error
+remounter_count=$tmp.remounter_count
+
+stop_workload()
+{
+	touch "$stop_file"
+	if [ -n "$remounter_pid" ]; then
+		wait "$remounter_pid" 2>/dev/null
+		remounter_pid=
+	fi
+	if [ "${#writer_pids[@]}" -gt 0 ]; then
+		wait "${writer_pids[@]}" 2>/dev/null
+		writer_pids=()
+	fi
+}
+
+# Override the default cleanup function.
+_cleanup()
+{
+	stop_workload
+	cd /
+	_is_dir_mountpoint "$SCRATCH_MNT" >/dev/null &&
+		_scratch_unmount >/dev/null 2>&1
+	rm -f "$stop_file" "$worker_error" "$worker_error".* \
+		"$tmp.xfs_io_error".* "$remounter_error" "$remounter_count"
+}
+
+# Import common functions.
+. ./common/filter
+
+_exclude_fs ext2
+_exclude_fs ext3
+_exclude_scratch_mount_option "data=journal" "dax" "nodelalloc"
+_require_check_dmesg
+_require_scratch_size $((2 * 1024 * 1024))
+_require_xfs_io_command "pwrite"
+_require_xfs_io_command "truncate"
+
+record_worker_error()
+{
+	local command=$1
+	local file=$2
+	local err=$3
+	local log=$worker_error.$BASHPID
+
+	{
+		echo "worker failed:"
+		echo "  command: $command"
+		echo "  file: $file"
+		echo "  stderr:"
+		if [ -s "$err" ]; then
+			sed 's/^/    /' "$err"
+		else
+			echo "    <empty>"
+		fi
+	} > "$log"
+	touch "$worker_error"
+}
+
+write_truncate_loop()
+{
+	local file=$1
+	local err=$tmp.xfs_io_error.$BASHPID
+
+	while [ ! -e "$stop_file" ]; do
+		$XFS_IO_PROG -f -c "pwrite -q 0 32m" "$file" \
+			>/dev/null 2>"$err" || {
+			record_worker_error \
+				'xfs_io -f -c "pwrite -q 0 32m"' "$file" "$err"
+			break
+		}
+		$XFS_IO_PROG -c "truncate 256k" "$file" \
+			>/dev/null 2>"$err" || {
+			record_worker_error \
+				'xfs_io -c "truncate 256k"' "$file" "$err"
+			break
+		}
+	done
+	rm -f "$err"
+}
+
+log_worker_errors()
+{
+	local log
+
+	test -e "$worker_error" || return 0
+
+	echo "write/truncate worker failure details:" >> "$seqres.full"
+	for log in "$worker_error".*; do
+		test -f "$log" || continue
+		cat "$log" >> "$seqres.full"
+	done
+}
+
+remount_loop()
+{
+	local count=0
+
+	while [ ! -e "$stop_file" ]; do
+		# This remount is expected to fail.  The bug is that ext4 used
+		# to expose the transient nodelalloc state before failing it.
+		if $MOUNT_PROG -o remount,nodelalloc "$SCRATCH_DEV" "$SCRATCH_MNT" \
+			>/dev/null 2>&1; then
+			echo "delalloc to nodelalloc remount unexpectedly succeeded" \
+				> "$remounter_error"
+			touch "$stop_file"
+			break
+		fi
+		count=$((count + 1))
+	done
+	echo "$count" > "$remounter_count"
+}
+
+log_remount_result()
+{
+	local remounts=0
+
+	if [ -s "$remounter_count" ]; then
+		read -r remounts < "$remounter_count"
+	fi
+	echo "rejected remounts: $remounts" >> "$seqres.full"
+
+	if [ -s "$remounter_error" ]; then
+		echo "remount worker failure details:" >> "$seqres.full"
+		sed 's/^/  /' "$remounter_error" >> "$seqres.full"
+	fi
+}
+
+sleep_msg_ratelimit_interval()
+{
+	local dev=$(_short_dev "$SCRATCH_DEV")
+	local interval_file=/sys/fs/ext4/$dev/msg_ratelimit_interval_ms
+	local interval_ms=0
+	local sleep_secs
+
+	if [ -r "$interval_file" ]; then
+		read -r interval_ms < "$interval_file"
+	fi
+	case "$interval_ms" in
+	''|*[!0-9]*)
+		interval_ms=0
+		;;
+	esac
+
+	sleep_secs=$(((interval_ms + 999) / 1000 + 1))
+	# Repeated expected remount failures can consume ext4's message
+	# ratelimit budget.  Wait one interval plus one second before
+	# unmount so "i_reserved_data_blocks .* not cleared!" is not
+	# filtered out by the ratelimit.
+	echo "sleeping ${sleep_secs}s for ext4 msg ratelimit interval" \
+		"(${interval_ms}ms)" >> "$seqres.full"
+	sleep "$sleep_secs"
+}
+
+echo "Silence is golden"
+
+_scratch_mkfs >> "$seqres.full" 2>&1
+_scratch_mount -o delalloc
+
+options_file=/proc/fs/ext4/$(_short_dev "$SCRATCH_DEV")/options
+grep -qw delalloc "$options_file" ||
+	_fail "scratch filesystem is not mounted with delalloc"
+
+for ((i = 0; i < 16; i++)); do
+	write_truncate_loop "$SCRATCH_MNT/file-$i" &
+	writer_pids+=("$!")
+done
+
+remount_loop &
+remounter_pid=$!
+
+runtime=$((30 * TIME_FACTOR))
+sleep "$runtime"
+
+stop_workload
+log_worker_errors
+log_remount_result
+
+sleep_msg_ratelimit_interval
+_scratch_unmount || _fail "scratch filesystem unmount failed"
+
+warning="i_reserved_data_blocks .* not cleared!"
+if _check_dmesg_for "$warning"; then
+	_dmesg_since_test_start | grep -E "$warning" >> "$seqres.full"
+	_fail "delayed allocation reservations leaked during rejected remount"
+fi
+test ! -e "$remounter_error" ||
+	_fail "delalloc to nodelalloc remount unexpectedly succeeded"
+test ! -e "$worker_error" || _fail "write/truncate worker failed"
+
+# success, all done
+status=0
+exit
tests/ext4/064.out new file +2 -0
new file mode 100644
index 00000000..d9076546
@@ -0,0 +1,2 @@
+QA output created by 064
+Silence is golden

base-commit: acb6d4cb84205a8e3f19ca470cfcf7bf6d93a509

Signature · 1 line
2.20.1
#1 lore raw
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider: - [High] The test is misplaced in the Linux kernel repository instead of the standalone fstests repository.…

Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:
- [High] The test is misplaced in the Linux kernel repository instead of the standalone fstests repository.
- [High] Incorrect sysfs and procfs device path resolution for Device-Mapper/LVM setups.
- [High] Test calls an undefined function _check_dmesg_for, leading to silent false negatives.
- [Medium] Unsafe wait in cleanup routine can cause the test harness to block indefinitely.
- [Low] Overridden _cleanup function leaks fstests temporary framework files.
--

--- Patch [1]: [PATCH] ext4/064: add regression test for delalloc remount leak --- commit dd8f7afb5b15cd0c26af3c7b7793de74e5f8db76
Author: guzebing <[email protected]>
ext4/064: add regression test for delalloc remount leak

This commit adds an ext4 regression test to exercise rejected delalloc to nodelalloc remounts while buffered writes and truncates are active. The workload checks for leaked delayed allocation reservations during unmount.

Quoted 9 lines
tests/ext4/064 new file +3 -0
new file mode 100755
index 0000000000000..5d43764c77687
@@ -0,0 +1,216 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2026 guzebing.  All Rights Reserved.

[ ... ]

Quoted 2 lines

+. ./common/preamble
+_begin_fstest auto stress mount

[Severity: High]
Is this test file intended for the standalone fstests repository rather than the Linux kernel tree?

The test framework dependencies, such as common/preamble, are not present in the kernel repository. Tests submitted directly to the kernel tree usually use the kselftest framework under tools/testing/selftests/.

[ ... ]

tests/ext4/064 line 35

Quoted 9 lines
tests/ext4/064 new file +9 -0
+stop_workload()
+{
+	touch "$stop_file"
+	if [ -n "$remounter_pid" ]; then
+		wait "$remounter_pid" 2>/dev/null
+		remounter_pid=
+	fi
+	if [ "${#writer_pids[@]}" -gt 0 ]; then
+		wait "${writer_pids[@]}" 2>/dev/null

[Severity: Medium]
Will using wait without a timeout block the test runner indefinitely if a workload enters an unkillable state?

Would it be safer to send a terminate signal to the background processes before waiting for their termination?

Quoted 4 lines
tests/ext4/064 new file +4 -0
+		writer_pids=()
+	fi
+}
+

tests/ext4/064 line 49

Quoted 10 lines
tests/ext4/064 new file +10 -0
+# Override the default cleanup function.
+_cleanup()
+{
+	stop_workload
+	cd /
+	_is_dir_mountpoint "$SCRATCH_MNT" >/dev/null &&
+		_scratch_unmount >/dev/null 2>&1
+	rm -f "$stop_file" "$worker_error" "$worker_error".* \
+		"$tmp.xfs_io_error".* "$remounter_error" "$remounter_count"
+}

[Severity: Low]
Could overriding the default cleanup function without including the standard rm -r -f $tmp.* command leave fstests framework temporary files in the system temporary directory?

[ ... ]

tests/ext4/064 line 155

Quoted 4 lines
tests/ext4/064 new file +4 -0
+sleep_msg_ratelimit_interval()
+{
+	local dev=$(_short_dev "$SCRATCH_DEV")
+	local interval_file=/sys/fs/ext4/$dev/msg_ratelimit_interval_ms

[Severity: High]
Does _short_dev reliably resolve the correct sysfs and procfs entries on setups using Device-Mapper or LVM?

The kernel exports ext4 sysfs entries using the underlying block device name like dm-0, instead of the logical volume name that _short_dev returns. This will also affect the procfs options_file check later in the test.

Would an fstests helper like _sysfs_dev be more appropriate here?

[ ... ]

tests/ext4/064 line 206

Quoted 4 lines
tests/ext4/064 new file +4 -0
+_scratch_unmount || _fail "scratch filesystem unmount failed"
+
+warning="i_reserved_data_blocks .* not cleared!"
+if _check_dmesg_for "$warning"; then

[Severity: High]
Does _check_dmesg_for exist in the standard fstests framework?

If the shell evaluates an undefined function, it will return a command not found error, causing this conditional check to silently evaluate to false even when the delayed allocation reservation bug is triggered.

Should this use a standard check like:
if _dmesg_since_test_start | grep -qE "$warning"; then

Quoted 3 lines
tests/ext4/064 new file +3 -0
+	_dmesg_since_test_start | grep -E "$warning" >> "$seqres.full"
+	_fail "delayed allocation reservations leaked during rejected remount"
+fi
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#2 lore raw
In reply to guzebing
Quoted 31 lines · guzebing

A delalloc filesystem rejects a remount with nodelalloc, but ext4 used to apply the option change before rejecting the remount. Concurrent buffered writes and truncates can observe the transient nodelalloc state and fail to release delayed allocation reservations. The leaked reservations are then reported when the inodes are evicted during unmount.

Add an ext4 regression test that starts concurrent write/truncate workers and an expected-failing remount,nodelalloc worker, stops them after a short stress window, and checks dmesg for leaked delayed allocation reservations.

The proposed kernel fix is still under review:
https://lore.kernel.org/linux-ext4/[email protected]/

Local validation showed that the test fails without the proposed kernel fix, with i_reserved_data_blocks not cleared warnings during unmount, and passes with the proposed fix applied.

---
 tests/ext4/064     | 216 +++++++++++++++++++++++++++++++++++++++++++++
 tests/ext4/064.out |   2 +
 2 files changed, 218 insertions(+)
 create mode 100755 tests/ext4/064
 create mode 100644 tests/ext4/064.out
tests/ext4/064 new file +0 -0
new file mode 100755
index 00000000..5d43764c

tests/ext4/064 line 5

Quoted 5 lines
tests/ext4/064 new file +5 -0
@@ -0,0 +1,216 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2026 guzebing.  All Rights Reserved.
+#
+# FS QA Test No. ext4/064

Did you write this line manually? Please remove "ext4/" part, or the tools/mvtest can't match this line.

tests/ext4/064 line 15

Quoted 10 lines
tests/ext4/064 new file +10 -0
+#
+# Exercise rejected delalloc to nodelalloc remounts while buffered writes and
+# truncates are active.  A remount used to clear EXT4_MOUNT_DELALLOC before
+# rejecting the transition, so a concurrent truncate could fail to release
+# delayed allocation reservations.  The leaked inode reservation is reported
+# when the inode is evicted during unmount.
+#
+# This is a regression test for the issue fixed by the proposed patch:
+# "ext4: reject delalloc to nodelalloc remount before applying options"
+# https://lore.kernel.org/linux-ext4/[email protected]/

_fixed_by_fs_commit ext4 xxxxxxxxxxxx \
"ext4: reject delalloc to nodelalloc remount before applying options"

Quoted 21 lines
tests/ext4/064 new file +21 -0
+#
+. ./common/preamble
+_begin_fstest auto stress mount
+
+writer_pids=()
+remounter_pid=
+stop_file=$tmp.stop
+worker_error=$tmp.worker_error
+remounter_error=$tmp.remounter_error
+remounter_count=$tmp.remounter_count
+
+stop_workload()
+{
+	touch "$stop_file"
+	if [ -n "$remounter_pid" ]; then
+		wait "$remounter_pid" 2>/dev/null
+		remounter_pid=
+	fi
+	if [ "${#writer_pids[@]}" -gt 0 ]; then
+		wait "${writer_pids[@]}" 2>/dev/null
+		writer_pids=()

tests/ext4/064 line 46

Quoted 10 lines
tests/ext4/064 new file +10 -0
+	fi
+}
+
+# Override the default cleanup function.
+_cleanup()
+{
+	stop_workload
+	cd /
+	_is_dir_mountpoint "$SCRATCH_MNT" >/dev/null &&
+		_scratch_unmount >/dev/null 2>&1

fstests/check automatically unmounts scratch and runs fsck at the end of each test. You don't need to invoke _scratch_unmount in _cleanup unless an extra unmount is explicitly required.

tests/ext4/064 line 48

Quoted 2 lines
tests/ext4/064 new file +2 -0
+	rm -f "$stop_file" "$worker_error" "$worker_error".* \
+		"$tmp.xfs_io_error".* "$remounter_error" "$remounter_count"

The original rm -r -f $tmp.* can remove all these files.

Quoted 97 lines
tests/ext4/064 new file +97 -0
+}
+
+# Import common functions.
+. ./common/filter
+
+_exclude_fs ext2
+_exclude_fs ext3
+_exclude_scratch_mount_option "data=journal" "dax" "nodelalloc"
+_require_check_dmesg
+_require_scratch_size $((2 * 1024 * 1024))
+_require_xfs_io_command "pwrite"
+_require_xfs_io_command "truncate"
+
+record_worker_error()
+{
+	local command=$1
+	local file=$2
+	local err=$3
+	local log=$worker_error.$BASHPID
+
+	{
+		echo "worker failed:"
+		echo "  command: $command"
+		echo "  file: $file"
+		echo "  stderr:"
+		if [ -s "$err" ]; then
+			sed 's/^/    /' "$err"
+		else
+			echo "    <empty>"
+		fi
+	} > "$log"
+	touch "$worker_error"
+}
+
+write_truncate_loop()
+{
+	local file=$1
+	local err=$tmp.xfs_io_error.$BASHPID
+
+	while [ ! -e "$stop_file" ]; do
+		$XFS_IO_PROG -f -c "pwrite -q 0 32m" "$file" \
+			>/dev/null 2>"$err" || {
+			record_worker_error \
+				'xfs_io -f -c "pwrite -q 0 32m"' "$file" "$err"
+			break
+		}
+		$XFS_IO_PROG -c "truncate 256k" "$file" \
+			>/dev/null 2>"$err" || {
+			record_worker_error \
+				'xfs_io -c "truncate 256k"' "$file" "$err"
+			break
+		}
+	done
+	rm -f "$err"
+}
+
+log_worker_errors()
+{
+	local log
+
+	test -e "$worker_error" || return 0
+
+	echo "write/truncate worker failure details:" >> "$seqres.full"
+	for log in "$worker_error".*; do
+		test -f "$log" || continue
+		cat "$log" >> "$seqres.full"
+	done
+}
+
+remount_loop()
+{
+	local count=0
+
+	while [ ! -e "$stop_file" ]; do
+		# This remount is expected to fail.  The bug is that ext4 used
+		# to expose the transient nodelalloc state before failing it.
+		if $MOUNT_PROG -o remount,nodelalloc "$SCRATCH_DEV" "$SCRATCH_MNT" \
+			>/dev/null 2>&1; then
+			echo "delalloc to nodelalloc remount unexpectedly succeeded" \
+				> "$remounter_error"
+			touch "$stop_file"
+			break
+		fi
+		count=$((count + 1))
+	done
+	echo "$count" > "$remounter_count"
+}
+
+log_remount_result()
+{
+	local remounts=0
+
+	if [ -s "$remounter_count" ]; then
+		read -r remounts < "$remounter_count"
+	fi
+	echo "rejected remounts: $remounts" >> "$seqres.full"
+

tests/ext4/064 line 155

Quoted 10 lines
tests/ext4/064 new file +10 -0
+	if [ -s "$remounter_error" ]; then
+		echo "remount worker failure details:" >> "$seqres.full"
+		sed 's/^/  /' "$remounter_error" >> "$seqres.full"
+	fi
+}
+
+sleep_msg_ratelimit_interval()
+{
+	local dev=$(_short_dev "$SCRATCH_DEV")
+	local interval_file=/sys/fs/ext4/$dev/msg_ratelimit_interval_ms

_require_fs_sysfs msg_ratelimit_interval_ms ?

Quoted 16 lines
tests/ext4/064 new file +16 -0
+	local interval_ms=0
+	local sleep_secs
+
+	if [ -r "$interval_file" ]; then
+		read -r interval_ms < "$interval_file"
+	fi
+	case "$interval_ms" in
+	''|*[!0-9]*)
+		interval_ms=0
+		;;
+	esac
+
+	sleep_secs=$(((interval_ms + 999) / 1000 + 1))
+	# Repeated expected remount failures can consume ext4's message
+	# ratelimit budget.  Wait one interval plus one second before
+	# unmount so "i_reserved_data_blocks .* not cleared!" is not

tests/ext4/064 line 181

Quoted 10 lines
tests/ext4/064 new file +10 -0
+	# filtered out by the ratelimit.
+	echo "sleeping ${sleep_secs}s for ext4 msg ratelimit interval" \
+		"(${interval_ms}ms)" >> "$seqres.full"
+	sleep "$sleep_secs"
+}
+
+echo "Silence is golden"
+
+_scratch_mkfs >> "$seqres.full" 2>&1
+_scratch_mount -o delalloc

If this test needs specific mount options, I recommend either unsetting MOUNT_OPTIONS or setting it to the options you need, then removing above _exclude_scratch_mount_option ....

tests/ext4/064 line 183

Quoted 2 lines
tests/ext4/064 new file +2 -0
+
+options_file=/proc/fs/ext4/$(_short_dev "$SCRATCH_DEV")/options

_require_fs_sysfs options ?

Quoted 10 lines
tests/ext4/064 new file +10 -0
+grep -qw delalloc "$options_file" ||
+	_fail "scratch filesystem is not mounted with delalloc"
+
+for ((i = 0; i < 16; i++)); do
+	write_truncate_loop "$SCRATCH_MNT/file-$i" &
+	writer_pids+=("$!")
+done
+
+remount_loop &
+remounter_pid=$!

tests/ext4/064 line 203

Quoted 10 lines
tests/ext4/064 new file +10 -0
+
+runtime=$((30 * TIME_FACTOR))
+sleep "$runtime"
+
+stop_workload
+log_worker_errors
+log_remount_result
+
+sleep_msg_ratelimit_interval
+_scratch_unmount || _fail "scratch filesystem unmount failed"

In general, we don't need to call _scratch_unmount explicitly unless it's part of the test steps. Could an unmount failure be one of the issues caused by this bug?

tests/ext4/064 line 209

Quoted 6 lines
tests/ext4/064 new file +6 -0
+
+warning="i_reserved_data_blocks .* not cleared!"
+if _check_dmesg_for "$warning"; then
+	_dmesg_since_test_start | grep -E "$warning" >> "$seqres.full"
+	_fail "delayed allocation reservations leaked during rejected remount"
+fi

fstests/check calls _check_dmesg at the end of each test case. What is the full dmesg line you want to check? Is it already covered by the default check patterns below:

        grep -E -q -e "kernel BUG at" \
             -e "WARNING:" \
             -e "\bBUG:" \
             -e "Oops:" \
             -e "possible recursive locking detected" \
             -e "(INFO|ERR): suspicious RCU usage" \
             -e "INFO: possible circular locking dependency detected" \
             -e "general protection fault:" \
             -e "BUG .* remaining" \
             -e "oom-kill" \
             -e "UBSAN:" \
             $seqres.dmesg

tests/ext4/064 line 216

Quoted 7 lines
tests/ext4/064 new file +7 -0
+test ! -e "$remounter_error" ||
+	_fail "delalloc to nodelalloc remount unexpectedly succeeded"
+test ! -e "$worker_error" || _fail "write/truncate worker failed"
+
+# success, all done
+status=0
+exit

_exit 0

Thanks,
Zorro

Quoted 13 lines
tests/ext4/064.out new file +2 -0
new file mode 100644
index 00000000..d9076546
@@ -0,0 +1,2 @@
+QA output created by 064
+Silence is golden

base-commit: acb6d4cb84205a8e3f19ca470cfcf7bf6d93a509

Signature · 1 line
2.20.1