2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2015 Oracle, Inc. All Rights Reserved.
7 # Create and populate an XFS filesystem, corrupt the refcount btree,
8 # then see how the kernel and xfs_repair deal with it.
11 seqres="$RESULT_DIR/$seq"
12 echo "QA output created by $seq"
16 status=1 # failure is the default!
17 trap "_cleanup; exit \$status" 0 1 2 3 15
25 # get standard environment, filters and checks
31 # real QA test starts here
33 _require_scratch_reflink
35 test -n "${FORCE_FUZZ}" || _require_scratch_xfs_crc
39 echo "+ create scratch fs"
40 _scratch_mkfs_xfs > /dev/null
42 echo "+ mount fs image"
44 blksz="$(stat -f -c '%s' "${SCRATCH_MNT}")"
45 agcount="$(_xfs_mount_agcount $SCRATCH_MNT)"
47 echo "+ make some files"
48 _pwrite_byte 0x62 0 $((blksz * 64)) "${SCRATCH_MNT}/file0" >> "$seqres.full"
49 _pwrite_byte 0x61 0 $((blksz * 64)) "${SCRATCH_MNT}/file1" >> "$seqres.full"
50 _cp_reflink "${SCRATCH_MNT}/file0" "${SCRATCH_MNT}/file2"
51 _cp_reflink "${SCRATCH_MNT}/file1" "${SCRATCH_MNT}/file3"
52 umount "${SCRATCH_MNT}"
55 _scratch_xfs_repair -n >> "$seqres.full" 2>&1 || \
56 _fail "xfs_repair should not fail"
58 echo "+ corrupt image"
59 seq 0 $((agcount - 1)) | while read ag; do
60 _scratch_xfs_db -x -c "agf ${ag}" -c "agf ${ag}" -c "addr refcntroot" \
61 -c "stack" -c "blocktrash -x 4096 -y 4096 -z -n 8 -3" \
62 >> "$seqres.full" 2>&1
66 _try_scratch_mount >> $seqres.full 2>&1 && \
67 echo "Should not be able to mount with broken refcountbt."
68 _scratch_unmount >> $seqres.full 2>&1
72 _repair_scratch_fs >> "$seqres.full" 2>&1
73 _scratch_xfs_repair >> "$seqres.full" 2>&1
75 echo "+ mount image (2)"
79 $CHATTR_PROG -R -f -i "${SCRATCH_MNT}/"
81 echo "+ reflink more (2)"
82 _cp_reflink "${SCRATCH_MNT}/file1" "${SCRATCH_MNT}/file5" || \
83 _fail "modified refcount tree"
84 umount "${SCRATCH_MNT}"
87 _scratch_xfs_repair -n >> "$seqres.full" 2>&1 || \
88 _fail "xfs_repair should not fail"