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