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