4 # Test that after syncing the filesystem, adding a hard link to a file,
5 # syncing the filesystem again, doing a write to the file that increases
6 # its size and then doing a fsync against that file, durably persists the
7 # data written to the file. That is, after log/journal replay, the data
10 # This test is motivated by a bug found in btrfs.
12 #-----------------------------------------------------------------------
13 # Copyright (C) 2015 SUSE Linux Products GmbH. All Rights Reserved.
14 # Author: Filipe Manana <fdmanana@suse.com>
16 # This program is free software; you can redistribute it and/or
17 # modify it under the terms of the GNU General Public License as
18 # published by the Free Software Foundation.
20 # This program is distributed in the hope that it would be useful,
21 # but WITHOUT ANY WARRANTY; without even the implied warranty of
22 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 # GNU General Public License for more details.
25 # You should have received a copy of the GNU General Public License
26 # along with this program; if not, write the Free Software Foundation,
27 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28 #-----------------------------------------------------------------------
32 seqres=$RESULT_DIR/$seq
33 echo "QA output created by $seq"
37 status=1 # failure is the default!
44 trap "_cleanup; exit \$status" 0 1 2 3 15
46 # get standard environment, filters and checks
51 # real QA test starts here
55 _require_dm_target flakey
56 _require_metadata_journaling $SCRATCH_DEV
60 _scratch_mkfs >> $seqres.full 2>&1
64 # Create the test file with some initial data and then fsync it.
65 # The fsync here is only needed to trigger the issue in btrfs, as it causes the
66 # the flag BTRFS_INODE_NEEDS_FULL_SYNC to be removed from the btrfs inode.
67 $XFS_IO_PROG -f -c "pwrite -S 0xaa 0 32k" \
69 $SCRATCH_MNT/foo | _filter_xfs_io
72 # Add a hard link to our file.
73 # On btrfs this sets the flag BTRFS_INODE_COPY_EVERYTHING on the btrfs inode,
74 # which is a necessary condition to trigger the issue.
75 ln $SCRATCH_MNT/foo $SCRATCH_MNT/bar
77 # Sync the filesystem to force a commit of the current btrfs transaction, this
78 # is a necessary condition to trigger the bug on btrfs.
81 # Now append more data to our file, increasing its size, and fsync the file.
82 # In btrfs because the inode flag BTRFS_INODE_COPY_EVERYTHING was set and the
83 # write path did not update the inode item in the btree nor the delayed inode
84 # item (in memory structure) in the current transaction (created by the fsync
85 # handler), the fsync did not record the inode's new i_size in the fsync
86 # log/journal. This made the data unavailable after the fsync log/journal is
88 $XFS_IO_PROG -c "pwrite -S 0xbb 32K 32K" \
90 $SCRATCH_MNT/foo | _filter_xfs_io
92 echo "File content after fsync and before crash:"
93 od -t x1 $SCRATCH_MNT/foo
95 _flakey_drop_and_remount
97 echo "File content after crash and log replay:"
98 od -t x1 $SCRATCH_MNT/foo