btrfs/012: check free size of scratch device before copying files
[xfstests-dev.git] / tests / xfs / 436
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. 436
6 #
7 # Ensure that we don't leak 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; and then corrupt the refcount btree to ensure that
11 # the CoW garbage collection (and therefore the mount) fail.
12 #
13 # On a subsequent mount attempt, we should be able to replay the bmap
14 # items for the linked and unlinked files without prematurely truncating
15 # the unlinked inode and without leaking the linked inode, and we should
16 # be able to release all the inodes when we're aborting the mount.
17 #
18 seq=`basename "$0"`
19 seqres="$RESULT_DIR/$seq"
20 echo "QA output created by $seq"
21
22 here=`pwd`
23 tmp=/tmp/$$
24 status=1    # failure is the default!
25 trap "_cleanup; exit \$status" 0 1 2 3 15
26
27 _cleanup()
28 {
29         cd /
30         rm -rf "$tmp".*
31 }
32
33 # get standard environment, filters and checks
34 . ./common/rc
35 . ./common/filter
36 . ./common/attr
37 . ./common/reflink
38 . ./common/inject
39 . ./common/module
40
41 # real QA test starts here
42 _supported_fs xfs
43 _require_loadable_fs_module "xfs"
44 _require_scratch_reflink
45 _require_cp_reflink
46 _require_command "$XFS_FSR_PROG" "xfs_fsr"
47 _require_xfs_io_error_injection "bmap_finish_one"
48 _require_xfs_scratch_rmapbt
49
50 rm -f "$seqres.full"
51
52 echo "Format and mount"
53 _scratch_mkfs > "$seqres.full" 2>&1
54 _scratch_mount -o noquota >> "$seqres.full" 2>&1
55
56 testdir="$SCRATCH_MNT/test-$seq"
57 blksz=65536
58 blks=3
59 mkdir "$testdir"
60
61 echo "Create a many-block file"
62 _pwrite_byte 0x62 0 $((blksz * blks)) $testdir/file1 >> $seqres.full
63 _pwrite_byte 0x63 0 $blksz $testdir/file2 >> $seqres.full
64 _reflink_range $testdir/file2 0 $testdir/file1 $blksz $blksz >> $seqres.full
65 _scratch_cycle_mount noquota
66
67 echo "Inject error"
68 _scratch_inject_error "bmap_finish_one"
69
70 echo "Defrag the file"
71 $XFS_FSR_PROG -v -d $testdir/file1 >> $seqres.full 2>&1
72
73 echo "FS should be shut down, touch will fail"
74 touch $SCRATCH_MNT/badfs 2>&1 | _filter_scratch
75
76 echo "Remount to replay log" | tee /dev/ttyprintk
77 _scratch_unmount
78 _scratch_dump_log >> $seqres.full
79 _scratch_xfs_db -x -c 'agf 0' -c 'addr refcntroot' -c 'fuzz -d recs[1].startblock ones' >> $seqres.full
80 _scratch_xfs_db -x -c 'agf 0' -c 'addr refcntroot' -c p >> $seqres.full
81 _try_scratch_mount -o noquota >> $seqres.full 2>&1
82 _scratch_unmount 2> /dev/null
83 rm -f ${RESULT_DIR}/require_scratch
84
85 echo "See if we leak"
86 _reload_fs_module "xfs"
87
88 # success, all done
89 status=0
90 exit