lib/: spdx license conversion
[xfstests-dev.git] / tests / generic / 278
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. 278
6 #
7 # Test DIO 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 _require_odirect
38
39 rm -f $seqres.full
40
41
42 echo "Format and mount"
43 _scratch_mkfs > $seqres.full 2>&1
44 _dmerror_init
45 _dmerror_mount >> $seqres.full 2>&1
46
47 testdir=$SCRATCH_MNT/test-$seq
48 mkdir $testdir
49
50 blksz=65536
51 nr=640
52 filesize=$((blksz * nr))
53 bufnr=128
54 bufsize=$((blksz * bufnr))
55
56 _require_fs_space $SCRATCH_MNT $((filesize / 1024 * 3 * 5 / 4))
57
58 echo "Create the original files"
59 $XFS_IO_PROG -f -c "pwrite -S 0x61 -b $bufsize 0 $filesize" $testdir/file1 >> $seqres.full
60 _cp_reflink $testdir/file1 $testdir/file2 >> $seqres.full
61 _dmerror_unmount
62 _dmerror_mount
63
64 echo "Compare files"
65 md5sum $testdir/file1 | _filter_scratch
66 md5sum $testdir/file2 | _filter_scratch
67
68 echo "CoW and unmount"
69 sync
70 _dmerror_load_error_table
71 urk=$($XFS_IO_PROG -d -f -c "pwrite -S 0x63 -b $bufsize 0 $filesize" $testdir/file2 2>&1)
72 echo $urk >> $seqres.full
73 echo "$urk" | grep -q "error" || _fail "dio pwrite did not fail"
74 _dmerror_load_working_table
75
76 echo "Rewrite"
77 $XFS_IO_PROG -d -f -c "pwrite -S 0x64 -b $bufsize 0 $filesize" $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