2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2015 SUSE Linux Products GmbH. All Rights Reserved.
7 # Test that after syncing the filesystem, adding a hard link to a file,
8 # syncing the filesystem again, doing a write to the file that increases
9 # its size and then doing a fsync against that file, durably persists the
10 # data written to the file. That is, after log/journal replay, the data
13 # This test is motivated by a bug found in btrfs.
16 _begin_fstest metadata auto quick log
18 # Override the default cleanup function.
25 # Import common functions.
29 # real QA test starts here
33 _require_dm_target flakey
35 _scratch_mkfs >> $seqres.full 2>&1
36 _require_metadata_journaling $SCRATCH_DEV
40 # Create the test file with some initial data and then fsync it.
41 # The fsync here is only needed to trigger the issue in btrfs, as it causes the
42 # the flag BTRFS_INODE_NEEDS_FULL_SYNC to be removed from the btrfs inode.
43 $XFS_IO_PROG -f -c "pwrite -S 0xaa 0 32k" \
45 $SCRATCH_MNT/foo | _filter_xfs_io
48 # Add a hard link to our file.
49 # On btrfs this sets the flag BTRFS_INODE_COPY_EVERYTHING on the btrfs inode,
50 # which is a necessary condition to trigger the issue.
51 ln $SCRATCH_MNT/foo $SCRATCH_MNT/bar
53 # Sync the filesystem to force a commit of the current btrfs transaction, this
54 # is a necessary condition to trigger the bug on btrfs.
57 # Now append more data to our file, increasing its size, and fsync the file.
58 # In btrfs because the inode flag BTRFS_INODE_COPY_EVERYTHING was set and the
59 # write path did not update the inode item in the btree nor the delayed inode
60 # item (in memory structure) in the current transaction (created by the fsync
61 # handler), the fsync did not record the inode's new i_size in the fsync
62 # log/journal. This made the data unavailable after the fsync log/journal is
64 $XFS_IO_PROG -c "pwrite -S 0xbb 32K 32K" \
66 $SCRATCH_MNT/foo | _filter_xfs_io
68 echo "File content after fsync and before crash:"
69 od -t x1 $SCRATCH_MNT/foo
71 _flakey_drop_and_remount
73 echo "File content after crash and log replay:"
74 od -t x1 $SCRATCH_MNT/foo