e2d336993c4230e3053ffc8b979fed9385f3c595
[xfstests-dev.git] / tests / xfs / 180
1 #! /bin/bash
2 # FS QA Test No. 180
3 #
4 # Test fragmentation after a lot of random CoW:
5 # - Create two reflinked files.  Set extsz hint on second file.
6 # - Buffered write to random offsets to scatter CoW reservations.
7 # - Rewrite the whole file to use up reservations.
8 # - Check the number of extents.
9 #
10 #-----------------------------------------------------------------------
11 # Copyright (c) 2016, 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.*
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 _supported_fs xfs
50 _require_scratch_reflink
51 _require_cp_reflink
52 _require_fiemap
53 _require_xfs_io_command "cowextsize"
54
55 rm -f $seqres.full
56
57 echo "Format and mount"
58 _scratch_mkfs > $seqres.full 2>&1
59 _scratch_mount >> $seqres.full 2>&1
60
61 testdir=$SCRATCH_MNT/test-$seq
62 mkdir $testdir
63
64 blksz=65536
65 nr=128
66 filesize=$((blksz * nr))
67 bufnr=16
68 bufsize=$((blksz * bufnr))
69
70 _require_fs_space $SCRATCH_MNT $((filesize / 1024 * 3 * 5 / 4))
71 real_blksz=$(get_block_size $testdir)
72 internal_blks=$((filesize / real_blksz))
73
74 echo "Create the original files"
75 $XFS_IO_PROG -f -c "pwrite -S 0x61 -b $bufsize 0 $((filesize + 1))" $testdir/file1 >> $seqres.full
76 $XFS_IO_PROG -f -c "cowextsize $bufsize" $testdir/file2
77 _cp_reflink $testdir/file1 $testdir/file2 >> $seqres.full
78 _scratch_cycle_mount
79
80 echo "Compare files"
81 md5sum $testdir/file1 | _filter_scratch
82 md5sum $testdir/file2 | _filter_scratch
83
84 echo "CoW and unmount"
85 $XFS_IO_PROG -f -c "cowextsize" $testdir/file2 >> $seqres.full
86 $XFS_IO_PROG -f -c "pwrite -R -S 0x63 -b $real_blksz 0 $filesize" -c "fdatasync" $testdir/file2 >> $seqres.full
87 $XFS_IO_PROG -f -c "pwrite -S 0x63 -b $real_blksz 0 $((filesize + 1))" -c "fdatasync" $testdir/file2 >> $seqres.full
88 _scratch_cycle_mount
89
90 echo "Compare files"
91 md5sum $testdir/file1 | _filter_scratch
92 md5sum $testdir/file2 | _filter_scratch
93
94 echo "Check extent counts"
95 old_extents=$(_count_extents $testdir/file1)
96 new_extents=$(_count_extents $testdir/file2)
97
98 echo "old extents: $old_extents" >> $seqres.full
99 echo "new extents: $new_extents" >> $seqres.full
100 echo "maximum extents: $internal_blks" >> $seqres.full
101 test $new_extents -lt $((internal_blks / 20)) || test $new_extents -lt 15 \
102         || echo "file2 badly fragmented"
103
104 # success, all done
105 status=0
106 exit