generic: add _require_odirect to generic/113 and generic/214
[xfstests-dev.git] / tests / generic / 183
1 #! /bin/bash
2 # FS QA Test No. 183
3 #
4 # Ensuring that copy on write in direct-io mode works when the CoW
5 # range originally covers multiple extents.
6 #   - Create two files
7 #   - Reflink the odd blocks of the first file into a third file.
8 #   - Reflink the even blocks of the second file into the third file.
9 #   - directio CoW across the halfway mark.
10 #   - Check that the files are now different where we say they're different.
11 #
12 #-----------------------------------------------------------------------
13 # Copyright (c) 2015, Oracle and/or its affiliates.  All Rights Reserved.
14 #
15 # This program is free software; you can redistribute it and/or
16 # modify it under the terms of the GNU General Public License as
17 # published by the Free Software Foundation.
18 #
19 # This program is distributed in the hope that it would be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22 # GNU General Public License for more details.
23 #
24 # You should have received a copy of the GNU General Public License
25 # along with this program; if not, write the Free Software Foundation,
26 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
27 #-----------------------------------------------------------------------
28
29 seq=`basename $0`
30 seqres=$RESULT_DIR/$seq
31 echo "QA output created by $seq"
32
33 here=`pwd`
34 tmp=/tmp/$$
35 status=1    # failure is the default!
36 trap "_cleanup; exit \$status" 0 1 2 3 15
37
38 _cleanup()
39 {
40     cd /
41     rm -rf $tmp.* $testdir
42 }
43
44 # get standard environment, filters and checks
45 . ./common/rc
46 . ./common/filter
47 . ./common/reflink
48
49 # real QA test starts here
50 _supported_os Linux
51 _require_scratch_reflink
52 _require_odirect
53
54 rm -f $seqres.full
55
56 echo "Format and mount"
57 _scratch_mkfs > $seqres.full 2>&1
58 _scratch_mount >> $seqres.full 2>&1
59
60 testdir=$SCRATCH_MNT/test-$seq
61 mkdir $testdir
62
63 echo "Create the original files"
64 blksz=65536
65 nr=64
66 filesize=$((blksz * nr))
67 _pwrite_byte 0x61 0 $filesize $testdir/file1 >> $seqres.full
68 _pwrite_byte 0x62 0 $filesize $testdir/file2 >> $seqres.full
69 seq 0 2 $((nr-1)) | while read f; do
70         _reflink_range $testdir/file1 $((blksz * f)) $testdir/file3 $((blksz * f)) $blksz >> $seqres.full
71         _pwrite_byte 0x61 $((blksz * f)) $blksz $testdir/file3.chk >> $seqres.full
72 done
73 seq 1 2 $((nr-1)) | while read f; do
74         _reflink_range $testdir/file2 $((blksz * f)) $testdir/file3 $((blksz * f)) $blksz >> $seqres.full
75         _pwrite_byte 0x62 $((blksz * f)) $blksz $testdir/file3.chk >> $seqres.full
76 done
77 _scratch_remount
78
79 echo "Compare files"
80 md5sum $testdir/file1 | _filter_scratch
81 md5sum $testdir/file2 | _filter_scratch
82 md5sum $testdir/file3 | _filter_scratch
83 md5sum $testdir/file3.chk | _filter_scratch
84
85 echo "directio CoW across the transition"
86 cowoff=$((filesize / 4))
87 cowsz=$((filesize / 2))
88 $XFS_IO_PROG -d -f -c "pwrite -S 0x63 -b $cowsz $cowoff $cowsz" $testdir/file3 >> $seqres.full
89 _pwrite_byte 0x63 $cowoff $cowsz $testdir/file3.chk >> $seqres.full
90 _scratch_remount
91
92 echo "Compare files"
93 md5sum $testdir/file1 | _filter_scratch
94 md5sum $testdir/file2 | _filter_scratch
95 md5sum $testdir/file3 | _filter_scratch
96 md5sum $testdir/file3.chk | _filter_scratch
97
98 # success, all done
99 status=0
100 exit