4 # Test file A fsync after moving one other unrelated file B between directories
5 # and fsyncing B's old parent directory before fsyncing the file A. Check that
6 # after a crash all the file A data we fsynced is available.
8 # This test is motivated by an issue discovered in btrfs which caused the file
9 # data to be lost (despite fsync returning success to user space). That btrfs
10 # bug was fixed by the following linux kernel patch:
12 # Btrfs: fix data loss in the fast fsync path
14 #-----------------------------------------------------------------------
15 # Copyright (C) 2015 SUSE Linux Products GmbH. All Rights Reserved.
16 # Author: Filipe Manana <fdmanana@suse.com>
18 # This program is free software; you can redistribute it and/or
19 # modify it under the terms of the GNU General Public License as
20 # published by the Free Software Foundation.
22 # This program is distributed in the hope that it would be useful,
23 # but WITHOUT ANY WARRANTY; without even the implied warranty of
24 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 # GNU General Public License for more details.
27 # You should have received a copy of the GNU General Public License
28 # along with this program; if not, write the Free Software Foundation,
29 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
30 #-----------------------------------------------------------------------
34 seqres=$RESULT_DIR/$seq
35 echo "QA output created by $seq"
39 status=1 # failure is the default!
46 trap "_cleanup; exit \$status" 0 1 2 3 15
48 # get standard environment, filters and checks
53 # real QA test starts here
57 _require_dm_target flakey
58 _require_metadata_journaling $SCRATCH_DEV
62 _scratch_mkfs >> $seqres.full 2>&1
66 # Create our main test file 'foo', the one we check for data loss.
67 # By doing an fsync against our file, it makes btrfs clear the 'needs_full_sync'
68 # bit from its flags (btrfs inode specific flags).
69 $XFS_IO_PROG -f -c "pwrite -S 0xaa 0 8K" \
70 -c "fsync" $SCRATCH_MNT/foo | _filter_xfs_io
72 # Now create one other file and 2 directories. We will move this second file
73 # from one directory to the other later because it forces btrfs to commit its
74 # currently open transaction if we fsync the old parent directory. This is
75 # necessary to trigger the data loss bug that affected btrfs.
76 mkdir $SCRATCH_MNT/testdir_1
77 touch $SCRATCH_MNT/testdir_1/bar
78 mkdir $SCRATCH_MNT/testdir_2
80 # Make sure everything is durably persisted.
83 # Write more 8Kb of data to our file.
84 $XFS_IO_PROG -c "pwrite -S 0xbb 8K 8K" $SCRATCH_MNT/foo | _filter_xfs_io
86 # Move our 'bar' file into a new directory.
87 mv $SCRATCH_MNT/testdir_1/bar $SCRATCH_MNT/testdir_2/bar
89 # Fsync our first directory. Because it had a file moved into some other
90 # directory, this made btrfs commit the currently open transaction. This is
91 # a condition necessary to trigger the data loss bug.
92 $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/testdir_1
94 # Now fsync our main test file. If the fsync succeeds, we expect the 8Kb of
95 # data we wrote previously to be persisted and available if a crash happens.
96 # This did not happen with btrfs, because of the transaction commit that
97 # happened when we fsynced the parent directory.
98 $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/foo
100 _flakey_drop_and_remount
102 # Now check that all data we wrote before are available.
103 echo "File content after log replay:"
104 od -t x1 $SCRATCH_MNT/foo