generic: copy_file_range swapfile test
[xfstests-dev.git] / tests / generic / 183
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. 183
6 #
7 # Ensuring that copy on write in direct-io mode works when the CoW
8 # range originally covers multiple extents.
9 #   - Create two files
10 #   - Reflink the odd blocks of the first file into a third file.
11 #   - Reflink the even blocks of the second file into the third file.
12 #   - directio CoW across the halfway mark.
13 #   - Check that the files are now different where we say they're different.
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.* $testdir
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 _require_scratch_reflink
38 _require_odirect
39
40 rm -f $seqres.full
41
42 echo "Format and mount"
43 _scratch_mkfs > $seqres.full 2>&1
44 _scratch_mount >> $seqres.full 2>&1
45
46 testdir=$SCRATCH_MNT/test-$seq
47 mkdir $testdir
48
49 echo "Create the original files"
50 blksz=65536
51 nr=64
52 filesize=$((blksz * nr))
53 _pwrite_byte 0x61 0 $filesize $testdir/file1 >> $seqres.full
54 _pwrite_byte 0x62 0 $filesize $testdir/file2 >> $seqres.full
55 seq 0 2 $((nr-1)) | while read f; do
56         _reflink_range $testdir/file1 $((blksz * f)) $testdir/file3 $((blksz * f)) $blksz >> $seqres.full
57         _pwrite_byte 0x61 $((blksz * f)) $blksz $testdir/file3.chk >> $seqres.full
58 done
59 seq 1 2 $((nr-1)) | while read f; do
60         _reflink_range $testdir/file2 $((blksz * f)) $testdir/file3 $((blksz * f)) $blksz >> $seqres.full
61         _pwrite_byte 0x62 $((blksz * f)) $blksz $testdir/file3.chk >> $seqres.full
62 done
63 _scratch_cycle_mount
64
65 echo "Compare files"
66 md5sum $testdir/file1 | _filter_scratch
67 md5sum $testdir/file2 | _filter_scratch
68 md5sum $testdir/file3 | _filter_scratch
69 md5sum $testdir/file3.chk | _filter_scratch
70
71 echo "directio CoW across the transition"
72 cowoff=$((filesize / 4))
73 cowsz=$((filesize / 2))
74 $XFS_IO_PROG -d -f -c "pwrite -S 0x63 -b $cowsz $cowoff $cowsz" $testdir/file3 >> $seqres.full
75 _pwrite_byte 0x63 $cowoff $cowsz $testdir/file3.chk >> $seqres.full
76 _scratch_cycle_mount
77
78 echo "Compare files"
79 md5sum $testdir/file1 | _filter_scratch
80 md5sum $testdir/file2 | _filter_scratch
81 md5sum $testdir/file3 | _filter_scratch
82 md5sum $testdir/file3.chk | _filter_scratch
83
84 # success, all done
85 status=0
86 exit