2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2017, Oracle and/or its affiliates. All Rights Reserved.
7 # Ensure that we don't leak inodes when CoW recovery fails.
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.
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.
19 _begin_fstest auto quick clone fsr
21 # Import common functions.
28 # real QA test starts here
30 _require_loadable_fs_module "xfs"
31 _require_scratch_reflink
33 _require_command "$XFS_FSR_PROG" "xfs_fsr"
34 _require_xfs_io_error_injection "bmap_finish_one"
35 _require_xfs_scratch_rmapbt
39 echo "Format and mount"
40 _scratch_mkfs > "$seqres.full" 2>&1
41 _scratch_mount -o noquota >> "$seqres.full" 2>&1
43 testdir="$SCRATCH_MNT/test-$seq"
48 echo "Create a many-block file"
49 _pwrite_byte 0x62 0 $((blksz * blks)) $testdir/file1 >> $seqres.full
50 _pwrite_byte 0x63 0 $blksz $testdir/file2 >> $seqres.full
51 _reflink_range $testdir/file2 0 $testdir/file1 $blksz $blksz >> $seqres.full
52 _scratch_cycle_mount noquota
55 _scratch_inject_error "bmap_finish_one"
57 echo "Defrag the file"
58 $XFS_FSR_PROG -v -d $testdir/file1 >> $seqres.full 2>&1
60 echo "FS should be shut down, touch will fail"
61 touch $SCRATCH_MNT/badfs 2>&1 | _filter_scratch
63 echo "Remount to replay log" | tee /dev/ttyprintk
65 _scratch_dump_log >> $seqres.full
66 _scratch_xfs_db -x -c 'agf 0' -c 'addr refcntroot' -c 'fuzz -d recs[1].startblock ones' >> $seqres.full
67 _scratch_xfs_db -x -c 'agf 0' -c 'addr refcntroot' -c p >> $seqres.full
68 _try_scratch_mount -o noquota >> $seqres.full 2>&1
69 _scratch_unmount 2> /dev/null
70 rm -f ${RESULT_DIR}/require_scratch
73 _reload_fs_module "xfs"