]> git-server-git.apps.pok.os.sepia.ceph.com Git - xfstests-dev.git/commitdiff
generic: test a scenario of power failure after renames and fsyncs
authorFilipe Manana <fdmanana@suse.com>
Thu, 27 Nov 2025 18:17:44 +0000 (18:17 +0000)
committerZorro Lang <zlang@kernel.org>
Fri, 5 Dec 2025 07:46:17 +0000 (15:46 +0800)
Test moving a directory to another location, create a file in the old
location of the directory and with the same name, fsync the file, then
move the file elsewhere and fsync again the file. After a power failure
we expect to be able to mount the fs and have the same content as before
the power failure.

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

 "btrfs: don't log conflicting inode if it's a dir moved in the current transaction"

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/784 [new file with mode: 0755]
tests/generic/784.out [new file with mode: 0644]

diff --git a/tests/generic/784 b/tests/generic/784
new file mode 100755 (executable)
index 0000000..8e01dff
--- /dev/null
@@ -0,0 +1,76 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2025 SUSE S.A.  All Rights Reserved.
+#
+# FS QA Test 784
+#
+# Test moving a directory to another location, create a file in the old location
+# of the directory and with the same name, fsync the file, then move the file
+# elsewhere and fsync again the file. After a power failure we expect to be able
+# to mount the fs and have the same content as before the power failure.
+#
+. ./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: don't log conflicting inode if it's a dir moved in the current transaction"
+
+_scratch_mkfs >>$seqres.full 2>&1 || _fail "mkfs failed"
+_require_metadata_journaling $SCRATCH_DEV
+_init_flakey
+_mount_flakey
+
+list_fs_contents()
+{
+       # Remove the 'lost+found' directory which only exists in some
+       # filesystems like extN and remove empty lines to have a consistent
+       # output regardless of the existence of the 'lost+found' directory.
+       ls -1R $SCRATCH_MNT/ | grep -v 'lost+found' | grep -v -e '^$' | \
+               _filter_scratch
+}
+
+mkdir $SCRATCH_MNT/dir1
+mkdir $SCRATCH_MNT/dir2
+
+_scratch_sync
+
+mv $SCRATCH_MNT/dir1 $SCRATCH_MNT/dir2
+
+# Create a file with the old name of the first directory and persist it with
+# a fsync.
+$XFS_IO_PROG -f -c "fsync" $SCRATCH_MNT/dir1
+
+# Move the file to some other location.
+mv $SCRATCH_MNT/dir1 $SCRATCH_MNT/dir2/foo
+
+# Fsync again the file.
+$XFS_IO_PROG -c "fsync" $SCRATCH_MNT/dir2/foo
+
+echo -e "\nfs contents before power failure:\n"
+list_fs_contents
+
+# Simulate a power failure and then mount again the filesystem to replay the
+# journal/log. We expect the mount to succeed.
+_flakey_drop_and_remount
+
+# We expect the fs contents to be the same as before the power failure.
+echo -e "\nfs contents after power failure:\n"
+list_fs_contents
+
+_unmount_flakey
+
+# success, all done
+_exit 0
diff --git a/tests/generic/784.out b/tests/generic/784.out
new file mode 100644 (file)
index 0000000..87942d0
--- /dev/null
@@ -0,0 +1,19 @@
+QA output created by 784
+
+fs contents before power failure:
+
+SCRATCH_MNT/:
+dir2
+SCRATCH_MNT/dir2:
+dir1
+foo
+SCRATCH_MNT/dir2/dir1:
+
+fs contents after power failure:
+
+SCRATCH_MNT/:
+dir2
+SCRATCH_MNT/dir2:
+dir1
+foo
+SCRATCH_MNT/dir2/dir1: