tests: remove udf/101
[xfstests-dev.git] / tests / generic / 187
1 #! /bin/bash
2 # FS QA Test No. 187
3 #
4 # Ensuring that copy on write in directio mode works when free space
5 # is heavily fragmented.
6 #   - Create two files
7 #   - Reflink the odd blocks of the first file into a third file.
8 #   - Reflink the even blocks of the second file into the third file.
9 #   - Try to fragment the free space by allocating a huge file and
10 #     punching out every other block.
11 #   - CoW across the halfway mark.
12 #   - Check that the files are now different where we say they're different.
13 #
14 #-----------------------------------------------------------------------
15 # Copyright (c) 2015, Oracle and/or its affiliates.  All Rights Reserved.
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 seq=`basename $0`
32 seqres=$RESULT_DIR/$seq
33 echo "QA output created by $seq"
34
35 here=`pwd`
36 tmp=/tmp/$$
37 status=1    # failure is the default!
38 trap "_cleanup; exit \$status" 0 1 2 3 15
39
40 _cleanup()
41 {
42     cd /
43 #    rm -rf $tmp.* $testdir
44 }
45
46 # get standard environment, filters and checks
47 . ./common/rc
48 . ./common/filter
49 . ./common/reflink
50
51 # real QA test starts here
52 _supported_os Linux
53 _require_scratch_reflink
54 _require_cp_reflink
55 _require_xfs_io_command "falloc"
56 _require_xfs_io_command "fpunch"
57 test $FSTYP = "btrfs" && _notrun "Can't fragment free space on btrfs."
58 _require_odirect
59
60 rm -f $seqres.full
61
62 _fragment_freesp()
63 {
64         file=$1
65
66         # consume nearly all available space (leave ~1MB)
67         avail=`_get_available_space $SCRATCH_MNT`
68         echo "$avail bytes left"
69         filesize=$((avail - 1048576))
70         $XFS_IO_PROG -fc "truncate $filesize" $file
71
72         chunks=20
73         chunksizemb=$((filesize / chunks / 1048576))
74         seq 1 $chunks | while read f; do
75                 echo "$((f * chunksizemb)) file size $f / 20"
76                 $XFS_IO_PROG -fc "falloc -k $(( (f - 1) * chunksizemb))m ${chunksizemb}m" $file
77         done
78
79         chunks=100
80         chunksizemb=$((filesize / chunks / 1048576))
81         seq 80 $chunks | while read f; do
82                 echo "$((f * chunksizemb)) file size $f / $chunks"
83                 $XFS_IO_PROG -fc "falloc -k $(( (f - 1) * chunksizemb))m ${chunksizemb}m" $file
84         done
85
86         filesizemb=$((filesize / 1048576))
87         $XFS_IO_PROG -fc "falloc -k 0 ${filesizemb}m" $file
88
89         # Try again anyway
90         avail=`_get_available_space $SCRATCH_MNT`
91         $XFS_IO_PROG -fc "pwrite -S 0x65 0 $avail" ${file}
92
93         # Punch out whatever we need
94         seq 1 $((nr * 4)) | while read f; do
95                 $XFS_IO_PROG -f -c "fpunch $((f * 2 * blksz)) $blksz" $file
96         done
97 }
98
99 echo "Format and mount"
100 _scratch_mkfs > $seqres.full 2>&1
101 _scratch_mount >> $seqres.full 2>&1
102
103 testdir=$SCRATCH_MNT/test-$seq
104 mkdir $testdir
105
106 echo "Create the original files"
107 blksz=65536
108 nr=1024
109 filesize=$((blksz * nr))
110 _pwrite_byte 0x61 0 $filesize $testdir/file1 >> $seqres.full
111 _pwrite_byte 0x62 0 $filesize $testdir/file2 >> $seqres.full
112 seq 0 2 $((nr-1)) | while read f; do
113         _reflink_range $testdir/file1 $((blksz * f)) $testdir/file3 $((blksz * f)) $blksz >> $seqres.full
114         _pwrite_byte 0x61 $((blksz * f)) $blksz $testdir/file3.chk >> $seqres.full
115 done
116 seq 1 2 $((nr-1)) | while read f; do
117         _reflink_range $testdir/file2 $((blksz * f)) $testdir/file3 $((blksz * f)) $blksz >> $seqres.full
118         _pwrite_byte 0x62 $((blksz * f)) $blksz $testdir/file3.chk >> $seqres.full
119 done
120 _scratch_cycle_mount
121 _fragment_freesp $testdir/bigfile >> $seqres.full 2>&1
122 filesize=$((blksz * nr))
123 _scratch_cycle_mount
124
125 echo "Compare files"
126 md5sum $testdir/file1 | _filter_scratch
127 md5sum $testdir/file2 | _filter_scratch
128 md5sum $testdir/file3 | _filter_scratch
129 md5sum $testdir/file3.chk | _filter_scratch
130
131 echo "CoW with multiple extents?"
132 cowoff=$((filesize / 4))
133 cowsz=$((filesize / 2))
134 $XFS_IO_PROG -d -f -c "pwrite -S 0x63 -b $cowsz $cowoff $cowsz" $testdir/file3 >> $seqres.full
135 _pwrite_byte 0x63 $cowoff $cowsz $testdir/file3.chk >> $seqres.full
136 _scratch_cycle_mount
137
138 echo "Compare files"
139 md5sum $testdir/file1 | _filter_scratch
140 md5sum $testdir/file2 | _filter_scratch
141 md5sum $testdir/file3 | _filter_scratch
142 md5sum $testdir/file3.chk | _filter_scratch
143
144 # success, all done
145 status=0
146 exit