From: "Darrick J. Wong" <djwong@kernel.org>
To: fdmanana@kernel.org
Cc: fstests@vger.kernel.org, linux-btrfs@vger.kernel.org,
Filipe Manana <fdmanana@suse.com>
Subject: Re: [PATCH] generic: test fsync of a file truncated to a length of zero
Date: Wed, 18 Feb 2026 15:42:44 -0800 [thread overview]
Message-ID: <20260218234244.GA6478@frogsfrogsfrogs> (raw)
In-Reply-To: <f4a25aa2a17255493a9887e0ba6610a307a4961a.1771352543.git.fdmanana@suse.com>
On Tue, Feb 17, 2026 at 06:33:30PM +0000, fdmanana@kernel.org wrote:
> From: Filipe Manana <fdmanana@suse.com>
>
> Test that if we truncate a file to 0, fsync it, add a hard link to the
> file and then fsync the parent directory, after a power failure the file
> has a size of 0 (and the hardlink exists too).
>
> This exercises a bug fixed by the following kernel patch for btrfs:
>
> "btrfs: fix zero size inode with non-zero size after log replay"
>
> Signed-off-by: Filipe Manana <fdmanana@suse.com>
This looks ok to me
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>
--D
> ---
> tests/generic/788 | 59 +++++++++++++++++++++++++++++++++++++++++++
> tests/generic/788.out | 5 ++++
> 2 files changed, 64 insertions(+)
> create mode 100755 tests/generic/788
> create mode 100644 tests/generic/788.out
>
> diff --git a/tests/generic/788 b/tests/generic/788
> new file mode 100755
> index 00000000..0234cc7f
> --- /dev/null
> +++ b/tests/generic/788
> @@ -0,0 +1,59 @@
> +#! /bin/bash
> +# SPDX-License-Identifier: GPL-2.0
> +# Copyright (c) 2026 SUSE S.A. All Rights Reserved.
> +#
> +# FS QA Test 788
> +#
> +# Test that if we truncate a file to 0, fsync it, add a hard link to the file
> +# and then fsync the parent directory, after a power failure the file has a
> +# size of 0 (and the hardlink exists too).
> +#
> +. ./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: fix zero size inode with non-zero size after log replay"
> +
> +_scratch_mkfs >>$seqres.full 2>&1 || _fail "mkfs failed"
> +_require_metadata_journaling $SCRATCH_DEV
> +_init_flakey
> +_scratch_mount
> +
> +mkdir $SCRATCH_MNT/dir
> +$XFS_IO_PROG -f -c "pwrite -S 0xab 0 64K" $SCRATCH_MNT/dir/foo | _filter_xfs_io
> +
> +# Persist the file and directory.
> +_scratch_sync
> +
> +# Truncate the file to 0 and fsync it.
> +$XFS_IO_PROG -c "truncate 0" -c "fsync" $SCRATCH_MNT/dir/foo
> +
> +# Create a link to foo in the same dir.
> +ln $SCRATCH_MNT/dir/foo $SCRATCH_MNT/dir/bar
> +
> +# Fsync the directory.
> +$XFS_IO_PROG -c "fsync" $SCRATCH_MNT/dir
> +
> +# Simulate a power failure and then mount again the filesystem to replay the
> +# journal/log.
> +_flakey_drop_and_remount
> +
> +echo "file size after power failure: $(stat -c %s $SCRATCH_MNT/dir/foo)"
> +echo "file link count after power failure: $(stat -c %h $SCRATCH_MNT/dir/foo)"
> +[ -f $SCRATCH_MNT/dir/bar ] || echo "link dir/bar is missing"
> +
> +# success, all done
> +_exit 0
> diff --git a/tests/generic/788.out b/tests/generic/788.out
> new file mode 100644
> index 00000000..37f3f36a
> --- /dev/null
> +++ b/tests/generic/788.out
> @@ -0,0 +1,5 @@
> +QA output created by 788
> +wrote 65536/65536 bytes at offset 0
> +XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
> +file size after power failure: 0
> +file link count after power failure: 2
> --
> 2.47.2
>
>
next prev parent reply other threads:[~2026-02-18 23:42 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-17 18:33 [PATCH] generic: test fsync of a file truncated to a length of zero fdmanana
2026-02-18 23:42 ` Darrick J. Wong [this message]
2026-02-20 15:48 ` 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=20260218234244.GA6478@frogsfrogsfrogs \
--to=djwong@kernel.org \
--cc=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