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