fstests: convert remaining tests to SPDX license tags
[xfstests-dev.git] / tests / xfs / 182
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2016, Oracle and/or its affiliates.  All Rights Reserved.
4 #
5 # FS QA Test No. 182
6 #
7 # Test fragmentation after a lot of random CoW:
8 # - Create two reflinked files.  Set extsz hint on second file.
9 # - Directio write to random offsets to scatter CoW reservations.
10 # - Rewrite the whole file to use up reservations.
11 # - Check the number of extents.
12 #
13 seq=`basename $0`
14 seqres=$RESULT_DIR/$seq
15 echo "QA output created by $seq"
16
17 here=`pwd`
18 tmp=/tmp/$$
19 status=1    # failure is the default!
20 trap "_cleanup; exit \$status" 0 1 2 3 15
21
22 _cleanup()
23 {
24     cd /
25     rm -rf $tmp.*
26 }
27
28 # get standard environment, filters and checks
29 . ./common/rc
30 . ./common/filter
31 . ./common/reflink
32
33 # real QA test starts here
34 _supported_os Linux
35 _supported_fs xfs
36 _require_scratch_reflink
37 _require_cp_reflink
38 _require_xfs_io_command "fiemap"
39 _require_xfs_io_command "cowextsize"
40 _require_odirect
41
42 rm -f $seqres.full
43
44 echo "Format and mount"
45 _scratch_mkfs > $seqres.full 2>&1
46 _scratch_mount >> $seqres.full 2>&1
47
48 testdir=$SCRATCH_MNT/test-$seq
49 mkdir $testdir
50
51 blksz=65536
52 nr=128
53 filesize=$((blksz * nr))
54 bufnr=16
55 bufsize=$((blksz * bufnr))
56
57 _require_fs_space $SCRATCH_MNT $((filesize / 1024 * 3 * 5 / 4))
58 real_blksz=$(_get_block_size $testdir)
59 internal_blks=$((filesize / real_blksz))
60
61 echo "Create the original files"
62 $XFS_IO_PROG -f -c "pwrite -S 0x61 -b $bufsize 0 $((filesize + 1))" $testdir/file1 >> $seqres.full
63 $XFS_IO_PROG -f -c "cowextsize $bufsize" $testdir/file2
64 _cp_reflink $testdir/file1 $testdir/file2 >> $seqres.full
65 _scratch_cycle_mount
66
67 echo "Compare files"
68 md5sum $testdir/file1 | _filter_scratch
69 md5sum $testdir/file2 | _filter_scratch
70
71 echo "CoW and unmount"
72 $XFS_IO_PROG -f -c "cowextsize" $testdir/file2 >> $seqres.full
73 $XFS_IO_PROG -d -f -c "pwrite -R -S 0x63 -b $real_blksz 0 $((filesize + 1))" \
74         $testdir/file2 2>&1 >> $seqres.full | _filter_xfs_io_error
75 $XFS_IO_PROG -d -f -c "pwrite -S 0x63 -b $real_blksz 0 $((filesize + 1))" \
76         $testdir/file2 2>&1 >> $seqres.full | _filter_xfs_io_error
77 _scratch_cycle_mount
78
79 echo "Compare files"
80 md5sum $testdir/file1 | _filter_scratch
81 md5sum $testdir/file2 | _filter_scratch
82
83 echo "Check extent counts"
84 old_extents=$(_count_extents $testdir/file1)
85 new_extents=$(_count_extents $testdir/file2)
86
87 echo "old extents: $old_extents" >> $seqres.full
88 echo "new extents: $new_extents" >> $seqres.full
89 echo "maximum extents: $internal_blks" >> $seqres.full
90 test $new_extents -lt $((internal_blks / 20)) || test $new_extents -lt 15 \
91         || echo "file2 badly fragmented"
92
93 # success, all done
94 status=0
95 exit