]> git-server-git.apps.pok.os.sepia.ceph.com Git - xfstests-dev.git/commitdiff
generic: test a directory fsync scenaro after replacing a subdir with a file
authorFilipe Manana <fdmanana@suse.com>
Tue, 3 Mar 2026 18:07:33 +0000 (18:07 +0000)
committerZorro Lang <zlang@kernel.org>
Wed, 4 Mar 2026 15:58:03 +0000 (23:58 +0800)
Test a scenario where we remove a directory previously persisted, create
a file with the same name and parent directory, create two directories in
the same parent directory, create a hard link for the new file in one of
the new directories, fsync the directory with the hard link and fsync the
parent directory. After a power failure we expect both directories to be
persisted as well as the new file and its hard link.

This exercises a bug on btrfs fixed by the following kernel patch:

  "btrfs: log new dentries when logging parent dir of a conflicting inode"

Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Zorro Lang <zlang@kernel.org>
tests/generic/790 [new file with mode: 0755]
tests/generic/790.out [new file with mode: 0644]

diff --git a/tests/generic/790 b/tests/generic/790
new file mode 100755 (executable)
index 0000000..c9bac6d
--- /dev/null
@@ -0,0 +1,70 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2026 SUSE S.A.  All Rights Reserved.
+#
+# FS QA Test 790
+#
+# Test a scenario where we remove a directory previously persisted, create a
+# file with the same name and parent directory, create two directories in the
+# same parent directory, create a hard link for the new file in one of the
+# new directories, fsync the directory with the hard link and fsync the parent
+# directory. After a power failure we expect both directories to be persisted
+# as well as the new file and its hard link.
+#
+. ./common/preamble
+_begin_fstest auto quick log
+
+_cleanup()
+{
+       _cleanup_flakey
+       cd /
+       rm -r -f $tmp.*
+}
+
+. ./common/filter
+. ./common/dmflakey
+
+_require_scratch
+_require_dm_target flakey
+
+[ "$FSTYP" = "btrfs" ] && _fixed_by_kernel_commit xxxxxxxxxxxx \
+       "btrfs: log new dentries when logging parent dir of a conflicting inode"
+
+_scratch_mkfs >>$seqres.full 2>&1 || _fail "mkfs failed"
+_require_metadata_journaling $SCRATCH_DEV
+_init_flakey
+_scratch_mount
+
+mkdir $SCRATCH_MNT/foo
+
+_scratch_sync
+
+rmdir $SCRATCH_MNT/foo
+
+# Create two new directories in the same parent directory as the new file.
+mkdir $SCRATCH_MNT/dir1
+mkdir $SCRATCH_MNT/dir2
+
+# Create a file with the name of the directly we deleted and was persisted
+# before.
+touch $SCRATCH_MNT/foo
+
+# Create a hard link for the new file inside one of the new directories.
+ln $SCRATCH_MNT/foo $SCRATCH_MNT/dir2/link
+
+$XFS_IO_PROG -c "fsync" $SCRATCH_MNT/dir2
+$XFS_IO_PROG -c "fsync" $SCRATCH_MNT/
+
+# Simulate a power failure and then mount again the filesystem to replay the
+# journal/log.
+_flakey_drop_and_remount
+
+# We expect to see dir1, dir2, file foo and its hard link, since dir2 was
+# explicitly fsynced as well as the parent directory.
+echo -e "Filesystem content after power failure:\n"
+# Exclude 'lost+found' dir from ext4 and last line if it's blank (due to removal
+# of 'lost+found').
+ls -R $SCRATCH_MNT/ | grep -v 'lost+found' | sed -e '${/^$/d;}' | _filter_scratch
+
+# success, all done
+_exit 0
diff --git a/tests/generic/790.out b/tests/generic/790.out
new file mode 100644 (file)
index 0000000..d9c0592
--- /dev/null
@@ -0,0 +1,12 @@
+QA output created by 790
+Filesystem content after power failure:
+
+SCRATCH_MNT/:
+dir1
+dir2
+foo
+
+SCRATCH_MNT/dir1:
+
+SCRATCH_MNT/dir2:
+link