fstests: move test group info to test files
[xfstests-dev.git] / tests / generic / 238
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. 238
6 #
7 # See what happens if we DIO CoW blocks 2-4 of a page's worth of blocks when
8 # the surrounding blocks vary between unwritten/regular/delalloc/hole.
9 #
10 # This test is dependent on the system page size, so we cannot use md5 in
11 # the golden output; we can only compare to a check file.
12 #
13 . ./common/preamble
14 _begin_fstest auto quick clone
15
16 # Override the default cleanup function.
17 _cleanup()
18 {
19     cd /
20     rm -rf $tmp.* $testdir
21 }
22
23 # Import common functions.
24 . ./common/filter
25 . ./common/reflink
26
27 # real QA test starts here
28 _require_scratch_reflink
29 _require_xfs_io_command "falloc"
30 _require_odirect
31
32 pagesz=$(getconf PAGE_SIZE)
33 blksz=$((pagesz / 4))
34
35 echo "Format and mount"
36 _scratch_mkfs_blocksized $blksz > $seqres.full 2>&1
37 _scratch_mount >> $seqres.full 2>&1
38
39 testdir=$SCRATCH_MNT/test-$seq
40 mkdir $testdir
41
42 real_blksz=$(_get_file_block_size $testdir)
43 test $real_blksz != $blksz && _notrun "Failed to format with small blocksize."
44
45 runtest() {
46         echo "runtest $1 $2"
47         b2=$1
48         b4=$2
49         dir=$3
50
51         echo "Create the original files"
52         mkdir -p $dir
53         _pwrite_byte 0x61 0 $pagesz $dir/file1 >> $seqres.full
54
55         $XFS_IO_PROG -f -c "truncate $pagesz" $dir/file2 >> $seqres.full
56         $XFS_IO_PROG -f -c "truncate $pagesz" $dir/file2.chk >> $seqres.full
57
58         case $b2 in
59         "regular")
60                 _pwrite_byte 0x61 $blksz $blksz $dir/file2 >> $seqres.full
61                 _pwrite_byte 0x61 $blksz $blksz $dir/file2.chk >> $seqres.full
62                 ;;
63         "unwritten")
64                 $XFS_IO_PROG -f -c "falloc -k $blksz $blksz" $dir/file2 >> $seqres.full
65                 _pwrite_byte 0x00 $blksz $blksz $dir/file2.chk >> $seqres.full
66                 ;;
67         "hole")
68                 ;;
69         esac
70
71         case $b4 in
72         "regular")
73                 _pwrite_byte 0x61 $((blksz * 3)) $blksz $dir/file2 >> $seqres.full
74                 _pwrite_byte 0x61 $((blksz * 3)) $blksz $dir/file2.chk >> $seqres.full
75                 ;;
76         "unwritten")
77                 $XFS_IO_PROG -f -c "falloc -k $((blksz * 3)) $blksz" $dir/file2 >> $seqres.full
78                 _pwrite_byte 0x00 $((blksz * 3)) $blksz $dir/file2.chk >> $seqres.full
79                 ;;
80         "hole")
81                 ;;
82         esac
83
84         _reflink_range $dir/file1 $blksz $dir/file2 $((blksz * 2)) $blksz >> $seqres.full
85         _pwrite_byte 0x61 $((blksz * 2)) $blksz $dir/file2.chk >> $seqres.full
86         _scratch_cycle_mount
87
88         echo "Compare files"
89         ! cmp -s $dir/file1 $dir/file2 || _fail "file1 and file2 don't match."
90         cmp -s $dir/file2 $dir/file2.chk || _fail "file2 and file2.chk don't match."
91
92         echo "CoW and unmount"
93         if [ $b2 = "delalloc" ]; then
94                 _pwrite_byte 0x61 $blksz $blksz $dir/file2 >> $seqres.full
95                 _pwrite_byte 0x61 $blksz $blksz $dir/file2.chk >> $seqres.full
96         fi
97
98         if [ $b4 = "delalloc" ]; then
99                 _pwrite_byte 0x61 $((blksz * 3)) $blksz $dir/file2 >> $seqres.full
100                 _pwrite_byte 0x61 $((blksz * 3)) $blksz $dir/file2.chk >> $seqres.full
101         fi
102
103         $XFS_IO_PROG -d -f -c "pwrite -S 0x63 $blksz $((blksz * 3))" $dir/file2 >> $seqres.full
104         $XFS_IO_PROG -f -c "pwrite -S 0x63 $blksz $((blksz * 3))" $dir/file2.chk >> $seqres.full
105         _scratch_cycle_mount
106
107         echo "Compare files"
108         ! cmp -s $dir/file1 $dir/file2 || _fail "file1 and file2 don't match."
109         cmp -s $dir/file2 $dir/file2.chk || _fail "file2 and file2.chk don't match."
110 }
111
112 runtest regular delalloc "$testdir/r-d"
113 runtest regular unwritten "$testdir/r-u"
114 runtest regular hole "$testdir/r-h"
115 runtest regular regular "$testdir/r-r"
116
117 runtest hole delalloc "$testdir/h-d"
118 runtest hole unwritten "$testdir/h-u"
119 runtest hole hole "$testdir/h-h"
120 runtest hole regular "$testdir/h-r"
121
122 runtest unwritten delalloc "$testdir/u-d"
123 runtest unwritten unwritten "$testdir/u-u"
124 runtest unwritten hole "$testdir/u-h"
125 runtest unwritten regular "$testdir/u-r"
126
127 runtest delalloc delalloc "$testdir/d-d"
128 runtest delalloc unwritten "$testdir/d-u"
129 runtest delalloc hole "$testdir/d-h"
130 runtest delalloc regular "$testdir/d-r"
131
132 # success, all done
133 status=0
134 exit