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 bmbt, then see how
8 # 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
36 test -n "${FORCE_FUZZ}" || _require_scratch_xfs_crc
38 _require_populate_commands
39 _require_xfs_db_blocktrash_z_command
40 test -z "${FUZZ_ARGS}" && FUZZ_ARGS="-n 8 -3"
44 echo "+ create scratch fs"
45 _scratch_mkfs_xfs > /dev/null
47 echo "+ mount fs image"
49 blksz="$(stat -f -c '%s' "${SCRATCH_MNT}")"
50 nr="$((blksz * 2 / 16))"
52 echo "+ make some files"
53 $XFS_IO_PROG -f -c "pwrite -S 0x62 0 $((blksz * nr))" -c 'fsync' "${SCRATCH_MNT}/bigfile" >> $seqres.full
54 for i in $(seq 1 2 ${nr}); do
55 $XFS_IO_PROG -f -c "fpunch $((i * blksz)) ${blksz}" "${SCRATCH_MNT}/bigfile" >> $seqres.full
57 inode="$(stat -c '%i' "${SCRATCH_MNT}/bigfile")"
58 umount "${SCRATCH_MNT}"
61 _scratch_xfs_repair -n >> $seqres.full 2>&1 || _fail "xfs_repair should not fail"
63 echo "+ corrupt image"
64 _scratch_xfs_db -x -c "inode ${inode}" -c "addr u.bmbt.ptrs[1]" -c "addr u3.bmbt.ptrs[1]" -c "stack" -c "blocktrash -x 32 -y $((blksz * 8)) -z ${FUZZ_ARGS}" >> $seqres.full
66 echo "+ mount image && modify files"
67 if _try_scratch_mount >> $seqres.full 2>&1; then
69 before="$(stat -c '%b' "${SCRATCH_MNT}/bigfile")"
70 $XFS_IO_PROG -f -c "pwrite -S 0x62 ${blksz} ${blksz}" -c 'fsync' "${SCRATCH_MNT}/bigfile" >> $seqres.full 2> /dev/null
71 after="$(stat -c '%b' "${SCRATCH_MNT}/bigfile")"
72 test "${before}" -eq "${after}" || _fail "pwrite should fail on corrupt bmbt"
73 umount "${SCRATCH_MNT}"
77 _scratch_xfs_repair >> $seqres.full 2>&1
79 echo "+ mount image (2)"
83 $CHATTR_PROG -R -f -i "${SCRATCH_MNT}/"
85 echo "+ modify files (2)"
86 touch "${SCRATCH_MNT}/bigfile"
87 before="$(stat -c '%b' "${SCRATCH_MNT}/bigfile")"
88 $XFS_IO_PROG -f -c "pwrite -S 0x62 ${blksz} ${blksz}" -c 'fsync' "${SCRATCH_MNT}/bigfile" >> $seqres.full 2> /dev/null
89 after="$(stat -c '%b' "${SCRATCH_MNT}/bigfile")"
90 test "${before}" -ne "${after}" || _fail "pwrite failed after fixing corrupt bmbt"
91 umount "${SCRATCH_MNT}"
94 _scratch_xfs_repair -n >> $seqres.full 2>&1 || _fail "xfs_repair should not fail"