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.
9 # This test is motivated by a bug found in btrfs.
11 #-----------------------------------------------------------------------
13 # Copyright (C) 2015 SUSE Linux Products GmbH. All Rights Reserved.
14 # Author: Filipe Manana <fdmanana@suse.com>
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.
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.
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 #-----------------------------------------------------------------------
32 seqres=$RESULT_DIR/$seq
33 echo "QA output created by $seq"
35 status=1 # failure is the default!
36 trap "_cleanup; exit \$status" 0 1 2 3 15
44 # get standard environment, filters and checks
49 # real QA test starts here
53 _require_dm_target flakey
54 _require_metadata_journaling $SCRATCH_DEV
56 # This test was motivated by an issue found in btrfs when the btrfs no-holes
57 # feature is enabled (introduced in kernel 3.14). So enable the feature if the
58 # fs being tested is btrfs.
59 if [ $FSTYP == "btrfs" ]; then
60 _require_btrfs_fs_feature "no_holes"
61 _require_btrfs_mkfs_feature "no-holes"
62 MKFS_OPTIONS="$MKFS_OPTIONS -O no-holes"
67 _scratch_mkfs >>$seqres.full 2>&1
71 # Create our test files and make sure everything is durably persisted.
72 $XFS_IO_PROG -f -c "pwrite -S 0xaa 0 64K" \
73 -c "pwrite -S 0xbb 64K 61K" \
74 $SCRATCH_MNT/foo | _filter_xfs_io
75 $XFS_IO_PROG -f -c "pwrite -S 0xee 0 64K" \
76 -c "pwrite -S 0xff 64K 61K" \
77 $SCRATCH_MNT/bar | _filter_xfs_io
80 # Now truncate our file foo to a smaller size (64Kb) and then truncate it to the
81 # size it had before the shrinking truncate (125Kb). Then fsync our file. If a
82 # power failure happens after the fsync, we expect our file to have a size of
83 # 125Kb, with the first 64Kb of data having the value 0xaa and the second 61Kb
84 # of data having the value 0x00.
85 $XFS_IO_PROG -c "truncate 64K" \
90 # Do something similar to our file bar, but the first truncation sets the file
91 # size to 0 and the second truncation expands the size to the double of what it
93 $XFS_IO_PROG -c "truncate 0" \
98 _flakey_drop_and_remount
100 # We expect foo to have a size of 125Kb, the first 64Kb of data all having the
101 # value 0xaa and the remaining 61Kb to be a hole (all bytes with value 0x00).
102 echo "File foo content after log replay:"
103 od -t x1 $SCRATCH_MNT/foo
105 # We expect bar to have a size of 253Kb and no extents (any byte read from bar
106 # has the value 0x00).
107 echo "File bar content after log replay:"
108 od -t x1 $SCRATCH_MNT/bar