4 # This test is motivated by an fsync issue discovered in btrfs.
5 # The issue was that we could lose file data, that was previously fsync'ed
6 # successfully, if we end up adding a hard link to our inode and then persist
7 # the fsync log later via an fsync of other inode for example.
9 # The btrfs issue was fixed by the following linux kernel patch:
11 # Btrfs: fix fsync data loss after adding hard link to inode
13 #-----------------------------------------------------------------------
14 # Copyright (C) 2015 SUSE Linux Products GmbH. All Rights Reserved.
15 # Author: Filipe Manana <fdmanana@suse.com>
17 # This program is free software; you can redistribute it and/or
18 # modify it under the terms of the GNU General Public License as
19 # published by the Free Software Foundation.
21 # This program is distributed in the hope that it would be useful,
22 # but WITHOUT ANY WARRANTY; without even the implied warranty of
23 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 # GNU General Public License for more details.
26 # You should have received a copy of the GNU General Public License
27 # along with this program; if not, write the Free Software Foundation,
28 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 #-----------------------------------------------------------------------
33 seqres=$RESULT_DIR/$seq
34 echo "QA output created by $seq"
38 status=1 # failure is the default!
45 trap "_cleanup; exit \$status" 0 1 2 3 15
47 # get standard environment, filters and checks
52 # real QA test starts here
56 _require_dm_target flakey
60 _scratch_mkfs >> $seqres.full 2>&1
61 _require_metadata_journaling $SCRATCH_DEV
65 # Create one file with data and fsync it.
66 # This made the btrfs fsync log persist the data and the inode metadata with
67 # a correct inode->i_size (4096 bytes).
68 $XFS_IO_PROG -f -c "pwrite -S 0xaa -b 4K 0 4K" -c "fsync" \
69 $SCRATCH_MNT/foo | _filter_xfs_io
71 # Now add one hard link to our file. This made the btrfs code update the fsync
72 # log, in memory only, with an inode metadata having a size of 0.
73 ln $SCRATCH_MNT/foo $SCRATCH_MNT/foo_link
75 # Now force persistence of the fsync log to disk, for example, by fsyncing some
77 touch $SCRATCH_MNT/bar
78 $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/bar
80 # Before a power loss or crash, we could read the 4Kb of data from our file as
82 echo "File content before:"
83 od -t x1 $SCRATCH_MNT/foo
85 _flakey_drop_and_remount
87 # After the fsync log replay, because the fsync log had a value of 0 for our
88 # inode's i_size, we couldn't read anymore the 4Kb of data that we previously
89 # wrote and fsync'ed. The size of the file became 0 after the fsync log replay.
90 echo "File content after:"
91 od -t x1 $SCRATCH_MNT/foo