4 # Create and populate an XFS filesystem, corrupt the refcount btree,
5 # then see how the kernel and xfs_repair deal with it.
7 #-----------------------------------------------------------------------
8 # Copyright (c) 2015 Oracle, Inc. All Rights Reserved.
10 # This program is free software; you can redistribute it and/or
11 # modify it under the terms of the GNU General Public License as
12 # published by the Free Software Foundation.
14 # This program is distributed in the hope that it would be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write the Free Software Foundation,
21 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #-----------------------------------------------------------------------
26 seqres="$RESULT_DIR/$seq"
27 echo "QA output created by $seq"
31 status=1 # failure is the default!
32 trap "_cleanup; exit \$status" 0 1 2 3 15
40 # get standard environment, filters and checks
46 # real QA test starts here
49 _require_scratch_reflink
51 test -n "${FORCE_FUZZ}" || _require_scratch_xfs_crc
55 echo "+ create scratch fs"
56 _scratch_mkfs_xfs > /dev/null
58 echo "+ mount fs image"
60 blksz="$(stat -f -c '%s' "${SCRATCH_MNT}")"
61 agcount="$(xfs_info "${SCRATCH_MNT}" | grep agcount= | sed -e 's/^.*agcount=\([0-9]*\),.*$/\1/g')"
63 echo "+ make some files"
64 _pwrite_byte 0x62 0 $((blksz * 64)) "${SCRATCH_MNT}/file0" >> "$seqres.full"
65 _pwrite_byte 0x61 0 $((blksz * 64)) "${SCRATCH_MNT}/file1" >> "$seqres.full"
66 _cp_reflink "${SCRATCH_MNT}/file0" "${SCRATCH_MNT}/file2"
67 _cp_reflink "${SCRATCH_MNT}/file1" "${SCRATCH_MNT}/file3"
68 umount "${SCRATCH_MNT}"
71 _scratch_xfs_repair -n >> "$seqres.full" 2>&1 || \
72 _fail "xfs_repair should not fail"
74 echo "+ corrupt image"
75 seq 0 $((agcount - 1)) | while read ag; do
76 $XFS_DB_PROG -x -c "agf ${ag}" -c "agf ${ag}" -c "addr refcntroot" \
77 -c "stack" -c "blocktrash -x 4096 -y 4096 -z -n 8 -3" \
78 "${SCRATCH_DEV}" >> "$seqres.full" 2>&1
85 _cp_reflink "${SCRATCH_MNT}/file1" "${SCRATCH_MNT}/file4" 2> /dev/null && \
86 _fail "should not be able to reflink with busted refcount btree"
87 umount "${SCRATCH_MNT}"
90 _scratch_xfs_repair >> "$seqres.full" 2>&1
91 _scratch_xfs_repair >> "$seqres.full" 2>&1
93 echo "+ mount image (2)"
97 chattr -R -f -i "${SCRATCH_MNT}/"
99 echo "+ reflink more (2)"
100 _cp_reflink "${SCRATCH_MNT}/file1" "${SCRATCH_MNT}/file5" || \
101 _fail "modified refcount tree"
102 umount "${SCRATCH_MNT}"
104 echo "+ check fs (2)"
105 _scratch_xfs_repair -n >> "$seqres.full" 2>&1 || \
106 _fail "xfs_repair should not fail"