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