generic/405: test mkfs against thin provision device
[xfstests-dev.git] / tests / generic / 098
1 #! /bin/bash
2 # FSQA Test No. 098
3 #
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
8 # the page cache.
9 #
10 # This test is motivated by an issue found in btrfs.
11 #
12 #-----------------------------------------------------------------------
13 #
14 # Copyright (C) 2015 SUSE Linux Products GmbH. All Rights Reserved.
15 # Author: Filipe Manana <fdmanana@suse.com>
16 #
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.
20 #
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.
25 #
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 #-----------------------------------------------------------------------
30 #
31
32 seq=`basename $0`
33 seqres=$RESULT_DIR/$seq
34 echo "QA output created by $seq"
35 tmp=/tmp/$$
36 status=1        # failure is the default!
37 trap "_cleanup; exit \$status" 0 1 2 3 15
38
39 _cleanup()
40 {
41         rm -f $tmp.*
42 }
43
44 # get standard environment, filters and checks
45 . ./common/rc
46 . ./common/filter
47
48 # real QA test starts here
49 _supported_fs generic
50 _supported_os Linux
51 _require_scratch
52
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"
60 fi
61
62 rm -f $seqres.full
63
64 _scratch_mkfs >>$seqres.full 2>&1
65 _scratch_mount
66
67 workout()
68 {
69         local need_sync=$1
70
71         # Create our test file with some data and durably persist it.
72         $XFS_IO_PROG -t -f -c "pwrite -S 0xaa 0 128K" $SCRATCH_MNT/foo | _filter_xfs_io
73         sync
74
75         # Append some data to the file, increasing its size, and leave a hole between
76         # the old size and the start offset if the following write. So our file gets
77         # a hole in the range [128Kb, 256Kb[.
78         $XFS_IO_PROG -c "pwrite -S 0xbb 256K 32K" $SCRATCH_MNT/foo | _filter_xfs_io
79
80         # This 'sync' is to flush file extent on disk and update on-disk inode size.
81         # This is required to trigger a bug in btrfs truncate where it updates on-disk
82         # inode size incorrectly.
83         if [ $need_sync -eq 1 ]; then
84                 sync
85         fi
86
87         # Now truncate our file to a smaller size that is in the middle of the hole we
88         # previously created.
89         # If we don't flush dirty page cache above, on most truncate
90         # implementations the data we appended before gets discarded from
91         # memory (with truncate_setsize()) and never ends up being written to
92         # disk.
93         $XFS_IO_PROG -c "truncate 160K" $SCRATCH_MNT/foo
94
95         _scratch_cycle_mount
96
97         # We expect to see a file with a size of 160Kb, with the first 128Kb of data all
98         # having the value 0xaa and the remaining 32Kb of data all having the value 0x00
99         echo "File content after remount:"
100         od -t x1 $SCRATCH_MNT/foo
101 }
102
103 workout 0
104 # flush after each write
105 workout 1
106
107 status=0
108 exit