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
34 _require_scratch_reflink
36 test -n "${FORCE_FUZZ}" || _require_scratch_xfs_crc
40 echo "+ create scratch fs"
41 _scratch_mkfs_xfs > /dev/null
43 echo "+ mount fs image"
45 blksz="$(stat -f -c '%s' "${SCRATCH_MNT}")"
46 agcount="$(_xfs_mount_agcount $SCRATCH_MNT)"
48 echo "+ make some files"
49 _pwrite_byte 0x62 0 $((blksz * 64)) "${SCRATCH_MNT}/file0" >> "$seqres.full"
50 _pwrite_byte 0x61 0 $((blksz * 64)) "${SCRATCH_MNT}/file1" >> "$seqres.full"
51 _cp_reflink "${SCRATCH_MNT}/file0" "${SCRATCH_MNT}/file2"
52 _cp_reflink "${SCRATCH_MNT}/file1" "${SCRATCH_MNT}/file3"
53 umount "${SCRATCH_MNT}"
56 _scratch_xfs_repair -n >> "$seqres.full" 2>&1 || \
57 _fail "xfs_repair should not fail"
59 echo "+ corrupt image"
60 seq 0 $((agcount - 1)) | while read ag; do
61 _scratch_xfs_db -x -c "agf ${ag}" -c "agf ${ag}" -c "addr refcntroot" \
62 -c "stack" -c "blocktrash -x 4096 -y 4096 -z -n 8 -3" \
63 >> "$seqres.full" 2>&1
67 _try_scratch_mount >> $seqres.full 2>&1 && \
68 echo "Should not be able to mount with broken refcountbt."
69 _scratch_unmount >> $seqres.full 2>&1
73 _repair_scratch_fs >> "$seqres.full" 2>&1
74 _scratch_xfs_repair >> "$seqres.full" 2>&1
76 echo "+ mount image (2)"
80 $CHATTR_PROG -R -f -i "${SCRATCH_MNT}/"
82 echo "+ reflink more (2)"
83 _cp_reflink "${SCRATCH_MNT}/file1" "${SCRATCH_MNT}/file5" || \
84 _fail "modified refcount tree"
85 umount "${SCRATCH_MNT}"
88 _scratch_xfs_repair -n >> "$seqres.full" 2>&1 || \
89 _fail "xfs_repair should not fail"