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
54 _require_dm_target flakey
55 _require_metadata_journaling $SCRATCH_DEV
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"
68 _scratch_mkfs >>$seqres.full 2>&1
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
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" \
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
94 $XFS_IO_PROG -c "truncate 0" \
99 _flakey_drop_and_remount
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
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