generic/405: test mkfs against thin provision device
[xfstests-dev.git] / tests / generic / 238
1 #! /bin/bash
2 # FS QA Test No. 238
3 #
4 # See what happens if we DIO CoW blocks 2-4 of a page's worth of blocks when
5 # the surrounding blocks vary between unwritten/regular/delalloc/hole.
6 #
7 # This test is dependent on the system page size, so we cannot use md5 in
8 # the golden output; we can only compare to a check file.
9 #
10 #-----------------------------------------------------------------------
11 # Copyright (c) 2015, Oracle and/or its affiliates.  All Rights Reserved.
12 #
13 # This program is free software; you can redistribute it and/or
14 # modify it under the terms of the GNU General Public License as
15 # published by the Free Software Foundation.
16 #
17 # This program is distributed in the hope that it would be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 # GNU General Public License for more details.
21 #
22 # You should have received a copy of the GNU General Public License
23 # along with this program; if not, write the Free Software Foundation,
24 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
25 #-----------------------------------------------------------------------
26
27 seq=`basename $0`
28 seqres=$RESULT_DIR/$seq
29 echo "QA output created by $seq"
30
31 here=`pwd`
32 tmp=/tmp/$$
33 status=1    # failure is the default!
34 trap "_cleanup; exit \$status" 0 1 2 3 15
35
36 _cleanup()
37 {
38     cd /
39     rm -rf $tmp.* $testdir
40 }
41
42 # get standard environment, filters and checks
43 . ./common/rc
44 . ./common/filter
45 . ./common/reflink
46
47 # real QA test starts here
48 _supported_os Linux
49 _require_scratch_reflink
50 _require_xfs_io_command "falloc"
51 _require_odirect
52
53 rm -f $seqres.full
54
55 pagesz=$(getconf PAGE_SIZE)
56 blksz=$((pagesz / 4))
57
58 echo "Format and mount"
59 _scratch_mkfs_blocksized $blksz > $seqres.full 2>&1
60 _scratch_mount >> $seqres.full 2>&1
61
62 testdir=$SCRATCH_MNT/test-$seq
63 mkdir $testdir
64
65 real_blksz=$(_get_file_block_size $testdir)
66 test $real_blksz != $blksz && _notrun "Failed to format with small blocksize."
67
68 runtest() {
69         echo "runtest $1 $2"
70         b2=$1
71         b4=$2
72         dir=$3
73
74         echo "Create the original files"
75         mkdir -p $dir
76         _pwrite_byte 0x61 0 $pagesz $dir/file1 >> $seqres.full
77
78         $XFS_IO_PROG -f -c "truncate $pagesz" $dir/file2 >> $seqres.full
79         $XFS_IO_PROG -f -c "truncate $pagesz" $dir/file2.chk >> $seqres.full
80
81         case $b2 in
82         "regular")
83                 _pwrite_byte 0x61 $blksz $blksz $dir/file2 >> $seqres.full
84                 _pwrite_byte 0x61 $blksz $blksz $dir/file2.chk >> $seqres.full
85                 ;;
86         "unwritten")
87                 $XFS_IO_PROG -f -c "falloc -k $blksz $blksz" $dir/file2 >> $seqres.full
88                 _pwrite_byte 0x00 $blksz $blksz $dir/file2.chk >> $seqres.full
89                 ;;
90         "hole")
91                 ;;
92         esac
93
94
95
96         case $b4 in
97         "regular")
98                 _pwrite_byte 0x61 $((blksz * 3)) $blksz $dir/file2 >> $seqres.full
99                 _pwrite_byte 0x61 $((blksz * 3)) $blksz $dir/file2.chk >> $seqres.full
100                 ;;
101         "unwritten")
102                 $XFS_IO_PROG -f -c "falloc -k $((blksz * 3)) $blksz" $dir/file2 >> $seqres.full
103                 _pwrite_byte 0x00 $((blksz * 3)) $blksz $dir/file2.chk >> $seqres.full
104                 ;;
105         "hole")
106                 ;;
107         esac
108
109         _reflink_range $dir/file1 $blksz $dir/file2 $((blksz * 2)) $blksz >> $seqres.full
110         _pwrite_byte 0x61 $((blksz * 2)) $blksz $dir/file2.chk >> $seqres.full
111         _scratch_cycle_mount
112
113         echo "Compare files"
114         ! cmp -s $dir/file1 $dir/file2 || _fail "file1 and file2 don't match."
115         cmp -s $dir/file2 $dir/file2.chk || _fail "file2 and file2.chk don't match."
116
117         echo "CoW and unmount"
118         if [ $b2 = "delalloc" ]; then
119                 _pwrite_byte 0x61 $blksz $blksz $dir/file2 >> $seqres.full
120                 _pwrite_byte 0x61 $blksz $blksz $dir/file2.chk >> $seqres.full
121         fi
122
123         if [ $b4 = "delalloc" ]; then
124                 _pwrite_byte 0x61 $((blksz * 3)) $blksz $dir/file2 >> $seqres.full
125                 _pwrite_byte 0x61 $((blksz * 3)) $blksz $dir/file2.chk >> $seqres.full
126         fi
127
128         $XFS_IO_PROG -d -f -c "pwrite -S 0x63 $blksz $((blksz * 3))" $dir/file2 >> $seqres.full
129         $XFS_IO_PROG -f -c "pwrite -S 0x63 $blksz $((blksz * 3))" $dir/file2.chk >> $seqres.full
130         _scratch_cycle_mount
131
132         echo "Compare files"
133         ! cmp -s $dir/file1 $dir/file2 || _fail "file1 and file2 don't match."
134         cmp -s $dir/file2 $dir/file2.chk || _fail "file2 and file2.chk don't match."
135 }
136
137 runtest regular delalloc "$testdir/r-d"
138 runtest regular unwritten "$testdir/r-u"
139 runtest regular hole "$testdir/r-h"
140 runtest regular regular "$testdir/r-r"
141
142 runtest hole delalloc "$testdir/h-d"
143 runtest hole unwritten "$testdir/h-u"
144 runtest hole hole "$testdir/h-h"
145 runtest hole regular "$testdir/h-r"
146
147 runtest unwritten delalloc "$testdir/u-d"
148 runtest unwritten unwritten "$testdir/u-u"
149 runtest unwritten hole "$testdir/u-h"
150 runtest unwritten regular "$testdir/u-r"
151
152 runtest delalloc delalloc "$testdir/d-d"
153 runtest delalloc unwritten "$testdir/d-u"
154 runtest delalloc hole "$testdir/d-h"
155 runtest delalloc regular "$testdir/d-r"
156
157 # success, all done
158 status=0
159 exit