From: fdmanana@kernel.org
To: fstests@vger.kernel.org
Cc: linux-btrfs@vger.kernel.org, Filipe Manana <fdmanana@suse.com>
Subject: [PATCH] btrfs: test a directory fsync scenaro after replacing a subdir with a file
Date: Tue, 3 Mar 2026 17:20:10 +0000 [thread overview]
Message-ID: <8e3c1626b6e49678976db67a861cb5dcfdb532c0.1772558357.git.fdmanana@suse.com> (raw)
From: Filipe Manana <fdmanana@suse.com>
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>
---
tests/generic/790 | 69 +++++++++++++++++++++++++++++++++++++++++++
tests/generic/790.out | 12 ++++++++
2 files changed, 81 insertions(+)
create mode 100755 tests/generic/790
create mode 100644 tests/generic/790.out
diff --git a/tests/generic/790 b/tests/generic/790
new file mode 100755
index 00000000..a25203a1
--- /dev/null
+++ b/tests/generic/790
@@ -0,0 +1,69 @@
+#! /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/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;}'
+
+# success, all done
+_exit 0
diff --git a/tests/generic/790.out b/tests/generic/790.out
new file mode 100644
index 00000000..d2232a19
--- /dev/null
+++ b/tests/generic/790.out
@@ -0,0 +1,12 @@
+QA output created by 790
+Filesystem content after power failure:
+
+/home/fdmanana/btrfs-tests/scratch_1/:
+dir1
+dir2
+foo
+
+/home/fdmanana/btrfs-tests/scratch_1/dir1:
+
+/home/fdmanana/btrfs-tests/scratch_1/dir2:
+link
--
2.47.2
next reply other threads:[~2026-03-03 17:20 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-03 17:20 fdmanana [this message]
2026-03-03 18:01 ` [PATCH] btrfs: test a directory fsync scenaro after replacing a subdir with a file Darrick J. Wong
2026-03-03 18:08 ` Filipe Manana
2026-03-03 18:07 ` [PATCH v2] " fdmanana
2026-03-03 18:16 ` Darrick J. Wong
2026-03-04 13:05 ` Christoph Hellwig
2026-03-04 15:03 ` Filipe Manana
2026-03-04 15:18 ` Zorro Lang
2026-03-04 15:25 ` Christoph Hellwig
2026-03-04 15:56 ` Zorro Lang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=8e3c1626b6e49678976db67a861cb5dcfdb532c0.1772558357.git.fdmanana@suse.com \
--to=fdmanana@kernel.org \
--cc=fdmanana@suse.com \
--cc=fstests@vger.kernel.org \
--cc=linux-btrfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox