generic: copy_file_range swapfile test
[xfstests-dev.git] / tests / generic / 268
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. 268
6 #
7 # Test CoW behavior when the write temporarily fails but the userspace
8 # program writes again.
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.*
23     _dmerror_cleanup
24 }
25
26 # get standard environment, filters and checks
27 . ./common/rc
28 . ./common/filter
29 . ./common/reflink
30 . ./common/dmerror
31
32 # real QA test starts here
33 _supported_os Linux
34 _require_scratch_reflink
35 _require_cp_reflink
36 _require_dm_target error
37
38 rm -f $seqres.full
39
40
41 echo "Format and mount"
42 _scratch_mkfs > $seqres.full 2>&1
43 _dmerror_init
44 _dmerror_mount >> $seqres.full 2>&1
45
46 testdir=$SCRATCH_MNT/test-$seq
47 mkdir $testdir
48
49 blksz=65536
50 nr=640
51 bufnr=128
52 filesize=$((blksz * nr))
53 bufsize=$((blksz * bufnr))
54
55 _require_fs_space $SCRATCH_MNT $((filesize / 1024 * 3 * 5 / 4))
56
57 echo "Create the original files"
58 $XFS_IO_PROG -f -c "pwrite -S 0x61 -b $bufsize 0 $filesize" $testdir/file1 >> $seqres.full
59 _cp_reflink $testdir/file1 $testdir/file2 >> $seqres.full
60 _dmerror_unmount
61 _dmerror_mount
62
63 echo "Compare files"
64 md5sum $testdir/file1 | _filter_scratch
65 md5sum $testdir/file2 | _filter_scratch
66
67 echo "CoW and unmount"
68 sync
69 _dmerror_load_error_table
70 urk=$($XFS_IO_PROG -f -c "pwrite -S 0x63 -b $bufsize 0 $filesize" \
71         -c "fdatasync" $testdir/file2 2>&1)
72 echo $urk >> $seqres.full
73 echo "$urk" | grep -q "error" || _fail "pwrite did not fail"
74 _dmerror_load_working_table
75
76 echo "Rewrite"
77 $XFS_IO_PROG -f -c "pwrite -S 0x64 -b $bufsize 0 $filesize" -c "fdatasync" $testdir/file2 >> $seqres.full 2>&1
78 _dmerror_unmount
79 _dmerror_mount
80
81 echo "Compare files"
82 md5sum $testdir/file1 | _filter_scratch
83
84 echo "Check for damage"
85 _dmerror_unmount
86 _dmerror_cleanup
87 _repair_scratch_fs >> $seqres.full
88
89 # success, all done
90 status=0
91 exit