4 # Test that a file fsync works after punching a hole for the same file range
5 # multiple times and that after log/journal replay the file's content is
8 # This test is motivated by a bug found in btrfs.
10 #-----------------------------------------------------------------------
12 # Copyright (C) 2015 SUSE Linux Products GmbH. All Rights Reserved.
13 # Author: Filipe Manana <fdmanana@suse.com>
15 # This program is free software; you can redistribute it and/or
16 # modify it under the terms of the GNU General Public License as
17 # published by the Free Software Foundation.
19 # This program is distributed in the hope that it would be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 # GNU General Public License for more details.
24 # You should have received a copy of the GNU General Public License
25 # along with this program; if not, write the Free Software Foundation,
26 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27 #-----------------------------------------------------------------------
31 seqres=$RESULT_DIR/$seq
32 echo "QA output created by $seq"
34 status=1 # failure is the default!
35 trap "_cleanup; exit \$status" 0 1 2 3 15
44 # get standard environment, filters and checks
50 # real QA test starts here
54 _require_xfs_io_command "fpunch"
55 _require_xfs_io_command "fiemap"
56 _require_dm_target flakey
57 _require_metadata_journaling $SCRATCH_DEV
61 _scratch_mkfs >>$seqres.full 2>&1
65 # Create out test file with some data and then fsync it.
66 # We do the fsync only to make sure the last fsync we do in this test triggers
67 # the fast code path of btrfs' fsync implementation, a condition necessary to
68 # trigger the bug btrfs had.
69 $XFS_IO_PROG -f -c "pwrite -S 0xaa 0K 128K" \
71 $SCRATCH_MNT/foobar | _filter_xfs_io
73 # Now punch a hole against the range [96K, 128K[.
74 $XFS_IO_PROG -c "fpunch 96K 32K" $SCRATCH_MNT/foobar
76 # Punch another hole against a range that overlaps the previous range and ends
78 $XFS_IO_PROG -c "fpunch 64K 128K" $SCRATCH_MNT/foobar
80 # Punch another hole against a range that overlaps the first range ([96K, 128K[)
82 $XFS_IO_PROG -c "fpunch 32K 96K" $SCRATCH_MNT/foobar
84 # Fsync our file. We want to verify that, after a power failure and mounting the
85 # filesystem again, the file content reflects all the hole punch operations.
86 $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/foobar
88 echo "File digest before power failure:"
89 md5sum $SCRATCH_MNT/foobar | _filter_scratch
91 echo "Fiemap before power failure:"
92 $XFS_IO_PROG -c "fiemap -v" $SCRATCH_MNT/foobar | _filter_fiemap
94 _flakey_drop_and_remount
96 echo "File digest after log replay:"
97 # Must match the same digest we got before the power failure.
98 md5sum $SCRATCH_MNT/foobar | _filter_scratch
100 echo "Fiemap after log replay:"
101 # Must match the same extent listing we got before the power failure.
102 $XFS_IO_PROG -c "fiemap -v" $SCRATCH_MNT/foobar | _filter_fiemap