reflink: ensure that we can handle reflinking a lot of extents
[xfstests-dev.git] / tests / generic / 177
1 #! /bin/bash
2 # FSQA Test No. 177
3 #
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
6 # correct.
7 #
8 # This test is motivated by a bug found in btrfs.
9 #
10 #-----------------------------------------------------------------------
11 #
12 # Copyright (C) 2015 SUSE Linux Products GmbH. All Rights Reserved.
13 # Author: Filipe Manana <fdmanana@suse.com>
14 #
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.
18 #
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.
23 #
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 #-----------------------------------------------------------------------
28 #
29
30 seq=`basename $0`
31 seqres=$RESULT_DIR/$seq
32 echo "QA output created by $seq"
33 tmp=/tmp/$$
34 status=1        # failure is the default!
35 trap "_cleanup; exit \$status" 0 1 2 3 15
36
37 _cleanup()
38 {
39         _cleanup_flakey
40         cd /
41         rm -f $tmp.*
42 }
43
44 # get standard environment, filters and checks
45 . ./common/rc
46 . ./common/filter
47 . ./common/punch
48 . ./common/dmflakey
49
50 # real QA test starts here
51 _need_to_be_root
52 _supported_fs generic
53 _supported_os Linux
54 _require_scratch
55 _require_xfs_io_command "fpunch"
56 _require_xfs_io_command "fiemap"
57 _require_dm_target flakey
58 _require_metadata_journaling $SCRATCH_DEV
59
60 rm -f $seqres.full
61
62 _scratch_mkfs >>$seqres.full 2>&1
63 _init_flakey
64 _mount_flakey
65
66 # Create out test file with some data and then fsync it.
67 # We do the fsync only to make sure the last fsync we do in this test triggers
68 # the fast code path of btrfs' fsync implementation, a condition necessary to
69 # trigger the bug btrfs had.
70 $XFS_IO_PROG -f -c "pwrite -S 0xaa 0K 128K" \
71                 -c "fsync"                  \
72                 $SCRATCH_MNT/foobar | _filter_xfs_io
73
74 # Now punch a hole against the range [96K, 128K[.
75 $XFS_IO_PROG -c "fpunch 96K 32K" $SCRATCH_MNT/foobar
76
77 # Punch another hole against a range that overlaps the previous range and ends
78 # beyond eof.
79 $XFS_IO_PROG -c "fpunch 64K 128K" $SCRATCH_MNT/foobar
80
81 # Punch another hole against a range that overlaps the first range ([96K, 128K[)
82 # and ends at eof.
83 $XFS_IO_PROG -c "fpunch 32K 96K" $SCRATCH_MNT/foobar
84
85 # Fsync our file. We want to verify that, after a power failure and mounting the
86 # filesystem again, the file content reflects all the hole punch operations.
87 $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/foobar
88
89 echo "File digest before power failure:"
90 md5sum $SCRATCH_MNT/foobar | _filter_scratch
91
92 echo "Fiemap before power failure:"
93 $XFS_IO_PROG -c "fiemap -v" $SCRATCH_MNT/foobar | _filter_fiemap
94
95 _flakey_drop_and_remount
96
97 echo "File digest after log replay:"
98 # Must match the same digest we got before the power failure.
99 md5sum $SCRATCH_MNT/foobar | _filter_scratch
100
101 echo "Fiemap after log replay:"
102 # Must match the same extent listing we got before the power failure.
103 $XFS_IO_PROG -c "fiemap -v" $SCRATCH_MNT/foobar | _filter_fiemap
104
105 _unmount_flakey
106
107 status=0
108 exit