overlay: run unionmount testsuite test cases
[xfstests-dev.git] / tests / xfs / 434
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2017, Oracle and/or its affiliates.  All Rights Reserved.
4 #
5 # FS QA Test No. 434
6 #
7 # Ensure that we don't leak quota inodes when CoW recovery fails.
8 #
9 # Use xfs_fsr to inject bmap redo items in the log for a linked file and
10 # an unlinked file; enable quota so that we always mount with the quota
11 # inodes; and then corrupt the refcount btree to ensure that the CoW
12 # garbage collection (and therefore the mount) fail.
13 #
14 # On a subsequent mount attempt, we should be able to replay the bmap
15 # items for the linked and unlinked files without prematurely truncating
16 # the unlinked inode and without leaking the linked inode, and we should
17 # be able to release the quota inodes when we're aborting the mount.  We
18 # also should not leak dquots.
19 #
20 seq=`basename "$0"`
21 seqres="$RESULT_DIR/$seq"
22 echo "QA output created by $seq"
23
24 here=`pwd`
25 tmp=/tmp/$$
26 status=1    # failure is the default!
27 trap "_cleanup; exit \$status" 0 1 2 3 15
28
29 _cleanup()
30 {
31         cd /
32         rm -rf "$tmp".*
33 }
34
35 # get standard environment, filters and checks
36 . ./common/rc
37 . ./common/filter
38 . ./common/attr
39 . ./common/reflink
40 . ./common/inject
41 . ./common/quota
42 . ./common/module
43
44 # real QA test starts here
45 _supported_os Linux
46 _supported_fs xfs
47 _require_loadable_fs_module "xfs"
48 _require_quota
49 _require_scratch_reflink
50 _require_cp_reflink
51 _require_command "$XFS_FSR_PROG" "xfs_fsr"
52 _require_xfs_io_error_injection "bmap_finish_one"
53 _require_xfs_scratch_rmapbt
54
55 rm -f "$seqres.full"
56
57 echo "Format and mount"
58 _scratch_mkfs > "$seqres.full" 2>&1
59 _scratch_mount -o noquota >> "$seqres.full" 2>&1
60
61 testdir="$SCRATCH_MNT/test-$seq"
62 blksz=65536
63 blks=3
64 mkdir "$testdir"
65
66 echo "Create a many-block file"
67 _pwrite_byte 0x62 0 $((blksz * blks)) $testdir/file1 >> $seqres.full
68 _pwrite_byte 0x63 0 $blksz $testdir/file2 >> $seqres.full
69 _reflink_range $testdir/file2 0 $testdir/file1 $blksz $blksz >> $seqres.full
70 _scratch_cycle_mount noquota
71
72 echo "Inject error"
73 _scratch_inject_error "bmap_finish_one"
74
75 echo "Defrag the file"
76 $XFS_FSR_PROG -v -d $testdir/file1 >> $seqres.full 2>&1
77
78 echo "FS should be shut down, touch will fail"
79 touch $SCRATCH_MNT/badfs 2>&1 | _filter_scratch
80
81 echo "Remount to replay log" | tee /dev/ttyprintk
82 _scratch_unmount
83 _scratch_dump_log >> $seqres.full
84 _scratch_xfs_db -x -c 'agf 0' -c 'addr refcntroot' -c 'fuzz -d recs[1].startblock ones' >> $seqres.full
85 _scratch_xfs_db -x -c 'agf 0' -c 'addr refcntroot' -c p >> $seqres.full
86
87 # Suddenly enable quota to test if we can leak the quotacheck dquots!
88 _try_scratch_mount -o quota >> $seqres.full 2>&1
89 _scratch_unmount 2> /dev/null
90 rm -f ${RESULT_DIR}/require_scratch
91
92 echo "See if we leak"
93 _reload_fs_module "xfs"
94
95 # success, all done
96 status=0
97 exit