generic: copy_file_range swapfile test
[xfstests-dev.git] / tests / generic / 201
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. 201
6 #
7 # See what happens if we dirty a lot of pages via CoW and immediately
8 # unlink the file.
9 #
10 seq=`basename $0`
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
13
14 here=`pwd`
15 tmp=/tmp/$$
16 status=1    # failure is the default!
17 trap "_cleanup; exit \$status" 0 1 2 3 15
18
19 _cleanup()
20 {
21     cd /
22     rm -rf $tmp.* $testdir
23 }
24
25 # get standard environment, filters and checks
26 . ./common/rc
27 . ./common/filter
28 . ./common/reflink
29
30 # real QA test starts here
31 _supported_os Linux
32 _require_scratch_reflink
33 _require_xfs_io_command "falloc"
34
35 rm -f $seqres.full
36
37 echo "Format and mount"
38 _scratch_mkfs > $seqres.full 2>&1
39 _scratch_mount >> $seqres.full 2>&1
40
41 testdir=$SCRATCH_MNT/test-$seq
42 mkdir $testdir
43
44 echo "Create the original files"
45 blksz=65536
46 nr=64
47 filesize=$((blksz * nr))
48 _pwrite_byte 0x61 0 $filesize $testdir/file1 >> $seqres.full
49 _pwrite_byte 0x62 0 $filesize $testdir/file3 >> $seqres.full
50 _pwrite_byte 0x62 0 $filesize $testdir/file3.chk >> $seqres.full
51 seq 0 2 $((nr-1)) | while read f; do
52         _reflink_range $testdir/file1 $((blksz * f)) $testdir/file3 $((blksz * f)) $blksz >> $seqres.full
53         _pwrite_byte 0x61 $((blksz * f)) $blksz $testdir/file3.chk >> $seqres.full
54 done
55 _scratch_cycle_mount
56
57 echo "Compare files"
58 md5sum $testdir/file1 | _filter_scratch
59 md5sum $testdir/file3 | _filter_scratch
60 md5sum $testdir/file3.chk | _filter_scratch
61
62 echo "CoW and unmount"
63 cowoff=$((filesize / 4))
64 cowsz=$((filesize / 2))
65 $XFS_IO_PROG -f -c "pwrite -S 0x63 -b $cowsz $cowoff $cowsz" $testdir/file3 >> $seqres.full
66 rm $testdir/file3
67
68 # success, all done
69 status=0
70 exit