fstests: don't _require_metadata_journaling before _scratch_mkfs
[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 _supported_fs generic
52 _supported_os Linux
53 _require_scratch
54 _require_xfs_io_command "fpunch"
55 _require_xfs_io_command "fiemap"
56 _require_dm_target flakey
57
58 rm -f $seqres.full
59
60 _scratch_mkfs >>$seqres.full 2>&1
61 _require_metadata_journaling $SCRATCH_DEV
62 _init_flakey
63 _mount_flakey
64
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" \
70                 -c "fsync"                  \
71                 $SCRATCH_MNT/foobar | _filter_xfs_io
72
73 # Now punch a hole against the range [96K, 128K[.
74 $XFS_IO_PROG -c "fpunch 96K 32K" $SCRATCH_MNT/foobar
75
76 # Punch another hole against a range that overlaps the previous range and ends
77 # beyond eof.
78 $XFS_IO_PROG -c "fpunch 64K 128K" $SCRATCH_MNT/foobar
79
80 # Punch another hole against a range that overlaps the first range ([96K, 128K[)
81 # and ends at eof.
82 $XFS_IO_PROG -c "fpunch 32K 96K" $SCRATCH_MNT/foobar
83
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
87
88 echo "File digest before power failure:"
89 md5sum $SCRATCH_MNT/foobar | _filter_scratch
90
91 echo "Fiemap before power failure:"
92 $XFS_IO_PROG -c "fiemap -v" $SCRATCH_MNT/foobar | _filter_fiemap
93
94 _flakey_drop_and_remount
95
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
99
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
103
104 _unmount_flakey
105
106 status=0
107 exit