overlay: run unionmount testsuite test cases
[xfstests-dev.git] / tests / xfs / 208
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. 208
6 #
7 # Ensure that the effective cow extent allocation size hint is the maximum of
8 # the cowextsize and extsize inode fields.
9 # - Create two reflinked files.  Set extsz hint on second file to $blocksize
10 #   and cowextsize hint to 1MB.
11 # - Buffered write to random offsets to scatter CoW reservations.
12 # - Rewrite the whole file to use up reservations.
13 # - Check the number of extents.
14 # - Repeat, but with extsz = 1MB and cowextsz = $blocksize.
15 #
16 seq=`basename $0`
17 seqres=$RESULT_DIR/$seq
18 echo "QA output created by $seq"
19
20 here=`pwd`
21 tmp=/tmp/$$
22 status=1    # failure is the default!
23 trap "_cleanup; exit \$status" 0 1 2 3 15
24
25 _cleanup()
26 {
27     cd /
28     rm -rf $tmp.*
29 }
30
31 # get standard environment, filters and checks
32 . ./common/rc
33 . ./common/filter
34 . ./common/reflink
35
36 # real QA test starts here
37 _supported_os Linux
38 _supported_fs xfs
39 _require_scratch_reflink
40 _require_cp_reflink
41 _require_xfs_io_command "fiemap"
42 _require_xfs_io_command "cowextsize"
43
44 rm -f $seqres.full
45
46 echo "Format and mount"
47 _scratch_mkfs > $seqres.full 2>&1
48 _scratch_mount >> $seqres.full 2>&1
49
50 testdir=$SCRATCH_MNT/test-$seq
51 mkdir $testdir
52
53 blksz=65536
54 nr=128
55 filesize=$((blksz * nr))
56 bufnr=16
57 bufsize=$((blksz * bufnr))
58
59 _require_fs_space $SCRATCH_MNT $((filesize / 1024 * 3 * 5 / 4))
60 real_blksz=$(_get_block_size $testdir)
61 internal_blks=$((filesize / real_blksz))
62
63 echo "Create the original files"
64 $XFS_IO_PROG -f -c "pwrite -S 0x61 -b $bufsize 0 $((filesize + 1))" $testdir/file1 >> $seqres.full
65
66 $XFS_IO_PROG -f -c "extsize $real_blksz" $testdir/file2
67 $XFS_IO_PROG -f -c "cowextsize $bufsize" $testdir/file2
68 _cp_reflink $testdir/file1 $testdir/file2 >> $seqres.full
69 _cp_reflink $testdir/file1 $testdir/file2 >> $seqres.full
70
71 $XFS_IO_PROG -f -c "extsize $bufsize" $testdir/file3
72 $XFS_IO_PROG -f -c "cowextsize $real_blksz" $testdir/file3
73 _cp_reflink $testdir/file1 $testdir/file3 >> $seqres.full
74 _scratch_cycle_mount
75
76 echo "Compare files"
77 md5sum $testdir/file1 | _filter_scratch
78 md5sum $testdir/file2 | _filter_scratch
79 md5sum $testdir/file3 | _filter_scratch
80
81 echo "CoW and unmount"
82 echo "extsize" >> $seqres.full
83 $XFS_IO_PROG -f -c "extsize" $testdir/file2 >> $seqres.full
84 echo "cowextsize" >> $seqres.full
85 $XFS_IO_PROG -f -c "cowextsize" $testdir/file2 >> $seqres.full
86
87 $XFS_IO_PROG -f -c "pwrite -R -S 0x63 -b $real_blksz 0 $filesize" -c "fdatasync" $testdir/file2 >> $seqres.full
88 $XFS_IO_PROG -f -c "pwrite -S 0x63 -b $real_blksz 0 $((filesize + 1))" -c "fdatasync" $testdir/file2 >> $seqres.full
89
90 echo "extsize" >> $seqres.full
91 $XFS_IO_PROG -f -c "extsize" $testdir/file3 >> $seqres.full
92 echo "cowextsize" >> $seqres.full
93 $XFS_IO_PROG -f -c "cowextsize" $testdir/file3 >> $seqres.full
94
95 $XFS_IO_PROG -f -c "pwrite -R -S 0x63 -b $real_blksz 0 $filesize" -c "fdatasync" $testdir/file3 >> $seqres.full
96 $XFS_IO_PROG -f -c "pwrite -S 0x63 -b $real_blksz 0 $((filesize + 1))" -c "fdatasync" $testdir/file3 >> $seqres.full
97 _scratch_cycle_mount
98
99 echo "Compare files"
100 md5sum $testdir/file1 | _filter_scratch
101 md5sum $testdir/file2 | _filter_scratch
102 md5sum $testdir/file3 | _filter_scratch
103
104 echo "Check extent counts"
105 old_extents=$(_count_extents $testdir/file1)
106 new_extents=$(_count_extents $testdir/file2)
107
108 echo "old extents: $old_extents" >> $seqres.full
109 echo "new extents: $new_extents" >> $seqres.full
110 echo "maximum extents: $internal_blks" >> $seqres.full
111 test $new_extents -lt $((internal_blks / 20)) || test $new_extents -lt 15 \
112         || echo "file2 badly fragmented"
113
114 new_extents=$(_count_extents $testdir/file3)
115
116 echo "old extents: $old_extents" >> $seqres.full
117 echo "new extents: $new_extents" >> $seqres.full
118 echo "maximum extents: $internal_blks" >> $seqres.full
119 test $new_extents -lt $((internal_blks / 20)) || test $new_extents -lt 15 \
120         || echo "file3 badly fragmented"
121
122 # success, all done
123 status=0
124 exit