fstests: _fail test by default when _scratch_mount fails
[xfstests-dev.git] / tests / xfs / 434
1 #! /bin/bash
2 # FS QA Test No. 434
3 #
4 # Ensure that we don't leak quota inodes when CoW recovery fails.
5 #
6 # Use xfs_fsr to inject bmap redo items in the log for a linked file and
7 # an unlinked file; enable quota so that we always mount with the quota
8 # inodes; and then corrupt the refcount btree to ensure that the CoW
9 # garbage collection (and therefore the mount) fail.
10 #
11 # On a subsequent mount attempt, we should be able to replay the bmap
12 # items for the linked and unlinked files without prematurely truncating
13 # the unlinked inode and without leaking the linked inode, and we should
14 # be able to release the quota inodes when we're aborting the mount.  We
15 # also should not leak dquots.
16 #
17 #-----------------------------------------------------------------------
18 # Copyright (c) 2017, Oracle and/or its affiliates.  All Rights Reserved.
19 #
20 # This program is free software; you can redistribute it and/or
21 # modify it under the terms of the GNU General Public License as
22 # published by the Free Software Foundation.
23 #
24 # This program is distributed in the hope that it would be useful,
25 # but WITHOUT ANY WARRANTY; without even the implied warranty of
26 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27 # GNU General Public License for more details.
28 #
29 # You should have received a copy of the GNU General Public License
30 # along with this program; if not, write the Free Software Foundation,
31 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
32 #-----------------------------------------------------------------------
33
34 seq=`basename "$0"`
35 seqres="$RESULT_DIR/$seq"
36 echo "QA output created by $seq"
37
38 here=`pwd`
39 tmp=/tmp/$$
40 status=1    # failure is the default!
41 trap "_cleanup; exit \$status" 0 1 2 3 15
42
43 _cleanup()
44 {
45         cd /
46         rm -rf "$tmp".*
47 }
48
49 # get standard environment, filters and checks
50 . ./common/rc
51 . ./common/filter
52 . ./common/attr
53 . ./common/reflink
54 . ./common/inject
55 . ./common/quota
56 . ./common/module
57
58 # real QA test starts here
59 _supported_os Linux
60 _supported_fs xfs
61 _require_loadable_fs_module "xfs"
62 _require_quota
63 _require_scratch_reflink
64 _require_cp_reflink
65 _require_command "$XFS_FSR_PROG" "xfs_fsr"
66 _require_xfs_io_error_injection "bmap_finish_one"
67 _require_xfs_scratch_rmapbt
68
69 rm -f "$seqres.full"
70
71 echo "Format and mount"
72 _scratch_mkfs > "$seqres.full" 2>&1
73 _scratch_mount -o noquota >> "$seqres.full" 2>&1
74
75 testdir="$SCRATCH_MNT/test-$seq"
76 blksz=65536
77 blks=3
78 mkdir "$testdir"
79
80 echo "Create a many-block file"
81 _pwrite_byte 0x62 0 $((blksz * blks)) $testdir/file1 >> $seqres.full
82 _pwrite_byte 0x63 0 $blksz $testdir/file2 >> $seqres.full
83 _reflink_range $testdir/file2 0 $testdir/file1 $blksz $blksz >> $seqres.full
84 _scratch_cycle_mount noquota
85
86 echo "Inject error"
87 _scratch_inject_error "bmap_finish_one"
88
89 echo "Defrag the file"
90 $XFS_FSR_PROG -v -d $testdir/file1 >> $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" | tee /dev/ttyprintk
96 _scratch_unmount
97 _scratch_dump_log >> $seqres.full
98 _scratch_xfs_db -x -c 'agf 0' -c 'addr refcntroot' -c 'fuzz -d recs[1].startblock ones' >> $seqres.full
99 _scratch_xfs_db -x -c 'agf 0' -c 'addr refcntroot' -c p >> $seqres.full
100
101 # Suddenly enable quota to test if we can leak the quotacheck dquots!
102 _try_scratch_mount -o quota >> $seqres.full 2>&1
103 _scratch_unmount 2> /dev/null
104 rm -f ${RESULT_DIR}/require_scratch
105
106 echo "See if we leak"
107 _reload_fs_module "xfs"
108
109 # success, all done
110 status=0
111 exit