generic: add _require_odirect to generic/113 and generic/214
[xfstests-dev.git] / tests / generic / 101
1 #! /bin/bash
2 # FSQA Test No. 101
3 #
4 # Test that if we truncate a file to a smaller size, then truncate it to its
5 # original size or a larger size, then fsyncing it and a power failure happens,
6 # the file will have the range [first_truncate_size, last_size[ with all bytes
7 # having a value of 0x00 if we read it the next time the filesystem is mounted.
8 #
9 # This test is motivated by a bug found in btrfs.
10 #
11 #-----------------------------------------------------------------------
12 #
13 # Copyright (C) 2015 SUSE Linux Products GmbH. All Rights Reserved.
14 # Author: Filipe Manana <fdmanana@suse.com>
15 #
16 # This program is free software; you can redistribute it and/or
17 # modify it under the terms of the GNU General Public License as
18 # published by the Free Software Foundation.
19 #
20 # This program is distributed in the hope that it would be useful,
21 # but WITHOUT ANY WARRANTY; without even the implied warranty of
22 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23 # GNU General Public License for more details.
24 #
25 # You should have received a copy of the GNU General Public License
26 # along with this program; if not, write the Free Software Foundation,
27 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
28 #-----------------------------------------------------------------------
29 #
30
31 seq=`basename $0`
32 seqres=$RESULT_DIR/$seq
33 echo "QA output created by $seq"
34 tmp=/tmp/$$
35 status=1        # failure is the default!
36 trap "_cleanup; exit \$status" 0 1 2 3 15
37
38 _cleanup()
39 {
40         _cleanup_flakey
41         rm -f $tmp.*
42 }
43
44 # get standard environment, filters and checks
45 . ./common/rc
46 . ./common/filter
47 . ./common/dmflakey
48
49 # real QA test starts here
50 _need_to_be_root
51 _supported_fs generic
52 _supported_os Linux
53 _require_scratch
54 _require_dm_target flakey
55 _require_metadata_journaling $SCRATCH_DEV
56
57 # This test was motivated by an issue found in btrfs when the btrfs no-holes
58 # feature is enabled (introduced in kernel 3.14). So enable the feature if the
59 # fs being tested is btrfs.
60 if [ $FSTYP == "btrfs" ]; then
61         _require_btrfs_fs_feature "no_holes"
62         _require_btrfs_mkfs_feature "no-holes"
63         MKFS_OPTIONS="$MKFS_OPTIONS -O no-holes"
64 fi
65
66 rm -f $seqres.full
67
68 _scratch_mkfs >>$seqres.full 2>&1
69 _init_flakey
70 _mount_flakey
71
72 # Create our test files and make sure everything is durably persisted.
73 $XFS_IO_PROG -f -c "pwrite -S 0xaa 0 64K"         \
74                 -c "pwrite -S 0xbb 64K 61K"       \
75                 $SCRATCH_MNT/foo | _filter_xfs_io
76 $XFS_IO_PROG -f -c "pwrite -S 0xee 0 64K"         \
77                 -c "pwrite -S 0xff 64K 61K"       \
78                 $SCRATCH_MNT/bar | _filter_xfs_io
79 sync
80
81 # Now truncate our file foo to a smaller size (64Kb) and then truncate it to the
82 # size it had before the shrinking truncate (125Kb). Then fsync our file. If a
83 # power failure happens after the fsync, we expect our file to have a size of
84 # 125Kb, with the first 64Kb of data having the value 0xaa and the second 61Kb
85 # of data having the value 0x00.
86 $XFS_IO_PROG -c "truncate 64K" \
87                 -c "truncate 125K" \
88                 -c "fsync" \
89                 $SCRATCH_MNT/foo
90
91 # Do something similar to our file bar, but the first truncation sets the file
92 # size to 0 and the second truncation expands the size to the double of what it
93 # was initially.
94 $XFS_IO_PROG -c "truncate 0" \
95                 -c "truncate 253K" \
96                 -c "fsync" \
97                 $SCRATCH_MNT/bar
98
99 _flakey_drop_and_remount
100
101 # We expect foo to have a size of 125Kb, the first 64Kb of data all having the
102 # value 0xaa and the remaining 61Kb to be a hole (all bytes with value 0x00).
103 echo "File foo content after log replay:"
104 od -t x1 $SCRATCH_MNT/foo
105
106 # We expect bar to have a size of 253Kb and no extents (any byte read from bar
107 # has the value 0x00).
108 echo "File bar content after log replay:"
109 od -t x1 $SCRATCH_MNT/bar
110
111 status=0
112 exit