4 # Test that after truncating a file into the middle of a hole causes the new
5 # size of the file to be persisted after a clean unmount of the filesystem (or
6 # after the inode is evicted). This is for the case where all the data following
7 # the hole is not yet durably persisted, that is, that data is only present in
10 # This test is motivated by an issue found in btrfs.
12 #-----------------------------------------------------------------------
14 # Copyright (C) 2015 SUSE Linux Products GmbH. All Rights Reserved.
15 # Author: Filipe Manana <fdmanana@suse.com>
17 # This program is free software; you can redistribute it and/or
18 # modify it under the terms of the GNU General Public License as
19 # published by the Free Software Foundation.
21 # This program is distributed in the hope that it would be useful,
22 # but WITHOUT ANY WARRANTY; without even the implied warranty of
23 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 # GNU General Public License for more details.
26 # You should have received a copy of the GNU General Public License
27 # along with this program; if not, write the Free Software Foundation,
28 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 #-----------------------------------------------------------------------
33 seqres=$RESULT_DIR/$seq
34 echo "QA output created by $seq"
36 status=1 # failure is the default!
37 trap "_cleanup; exit \$status" 0 1 2 3 15
44 # get standard environment, filters and checks
48 # real QA test starts here
53 # This test was motivated by an issue found in btrfs when the btrfs no-holes
54 # feature is enabled (introduced in kernel 3.14). So enable the feature if the
55 # fs being tested is btrfs.
56 if [ $FSTYP == "btrfs" ]; then
57 _require_btrfs_fs_feature "no_holes"
58 _require_btrfs_mkfs_feature "no-holes"
59 MKFS_OPTIONS="$MKFS_OPTIONS -O no-holes"
64 _scratch_mkfs >>$seqres.full 2>&1
67 # Create our test file with some data and durably persist it.
68 $XFS_IO_PROG -f -c "pwrite -S 0xaa 0 128K" $SCRATCH_MNT/foo | _filter_xfs_io
71 # Append some data to the file, increasing its size, and leave a hole between
72 # the old size and the start offset if the following write. So our file gets
73 # a hole in the range [128Kb, 256Kb[.
74 $XFS_IO_PROG -c "pwrite -S 0xbb 256K 32K" $SCRATCH_MNT/foo | _filter_xfs_io
76 # Now truncate our file to a smaller size that is in the middle of the hole we
77 # previously created. On most truncate implementations the data we appended
78 # before gets discarded from memory (with truncate_setsize()) and never ends
79 # up being written to disk.
80 $XFS_IO_PROG -c "truncate 160K" $SCRATCH_MNT/foo
84 # We expect to see a file with a size of 160Kb, with the first 128Kb of data all
85 # having the value 0xaa and the remaining 32Kb of data all having the value 0x00
86 echo "File content after remount:"
87 od -t x1 $SCRATCH_MNT/foo