xfs/31[2-7]: hide pwrite fsync errors that are supposed to fail
[xfstests-dev.git] / tests / xfs / 326
1 #! /bin/bash
2 # FS QA Test No. 326
3 #
4 # Reflink a file with a few dozen extents, CoW a few blocks, and rm.
5 # Inject an error during refcount updates to test log recovery.  Use
6 # cowextsize so that the refcount failure is somewhere in the CoW remap
7 # instead of when we're stashing the CoW orphan record.
8 #
9 #-----------------------------------------------------------------------
10 # Copyright (c) 2016, Oracle and/or its affiliates.  All Rights Reserved.
11 #
12 # This program is free software; you can redistribute it and/or
13 # modify it under the terms of the GNU General Public License as
14 # published by the Free Software Foundation.
15 #
16 # This program is distributed in the hope that it would be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 # GNU General Public License for more details.
20 #
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write the Free Software Foundation,
23 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
24 #-----------------------------------------------------------------------
25
26 seq=`basename $0`
27 seqres=$RESULT_DIR/$seq
28 echo "QA output created by $seq"
29
30 here=`pwd`
31 tmp=/tmp/$$
32 status=1    # failure is the default!
33 trap "_cleanup; exit \$status" 0 1 2 3 15
34
35 _cleanup()
36 {
37         cd /
38         _scratch_unmount > /dev/null 2>&1
39         rm -rf $tmp.*
40 }
41
42 # get standard environment, filters and checks
43 . ./common/rc
44 . ./common/filter
45 . ./common/reflink
46 . ./common/inject
47
48 # real QA test starts here
49 _supported_os Linux
50 _supported_fs xfs
51 _require_cp_reflink
52 _require_scratch_reflink
53 _require_xfs_io_command "cowextsize"
54 _require_xfs_io_error_injection "refcount_finish_one"
55
56 rm -f $seqres.full
57
58 blksz=65536
59 blks=64
60 sz=$((blksz * blks))
61 echo "Format filesystem"
62 _scratch_mkfs >/dev/null 2>&1
63 _scratch_mount >> $seqres.full
64
65 $XFS_IO_PROG -c "cowextsize $sz" $SCRATCH_MNT
66
67 echo "Create files"
68 _pwrite_byte 0x66 0 $sz $SCRATCH_MNT/file1 >> $seqres.full
69 _cp_reflink $SCRATCH_MNT/file1 $SCRATCH_MNT/file2
70 _cp_reflink $SCRATCH_MNT/file1 $SCRATCH_MNT/file3
71
72 # Punch holes in file3
73 seq 1 2 $blks | while read off; do
74         $XFS_IO_PROG -c "fpunch $((off * blksz)) $blksz" $SCRATCH_MNT/file3 >> $seqres.full
75 done
76 sync
77
78 echo "Check files"
79 md5sum $SCRATCH_MNT/file1 | _filter_scratch
80 md5sum $SCRATCH_MNT/file2 | _filter_scratch
81 md5sum $SCRATCH_MNT/file3 | _filter_scratch
82
83 $XFS_IO_PROG -c "pwrite -W -S 0x67 $((10 * blksz)) 1" $SCRATCH_MNT/file2 >> $seqres.full
84 sync
85
86 echo "Inject error"
87 _scratch_inject_error "refcount_finish_one"
88
89 echo "CoW a few blocks"
90 $XFS_IO_PROG -c "pwrite -W -S 0x67 -b $sz $((10 * blksz)) $((10 * blksz))" $SCRATCH_MNT/file2 >> $seqres.full 2>&1
91
92 echo "FS should be shut down, touch will fail"
93 touch $SCRATCH_MNT/badfs 2>&1 | _filter_scratch
94
95 echo "Remount to replay log"
96 _scratch_inject_logprint >> $seqres.full
97
98 echo "FS should be online, touch should succeed"
99 touch $SCRATCH_MNT/goodfs
100
101 echo "Check files again"
102 md5sum $SCRATCH_MNT/file1 | _filter_scratch
103 md5sum $SCRATCH_MNT/file2 | _filter_scratch
104 md5sum $SCRATCH_MNT/file3 | _filter_scratch
105
106 echo "Done"
107
108 # success, all done
109 status=0
110 exit