2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2015 Oracle, Inc. All Rights Reserved.
7 # Create and populate an XFS filesystem, corrupt a block directory, then see
8 # 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
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 dblksz="$($XFS_INFO_PROG "${SCRATCH_MNT}" | grep naming.*bsize | sed -e 's/^.*bsize=//g' -e 's/\([0-9]*\).*$/\1/g')"
51 blksz="$(stat -f -c '%s' "${SCRATCH_MNT}")"
52 leaf_lblk="$((32 * 1073741824 / blksz))"
53 node_lblk="$((64 * 1073741824 / blksz))"
55 echo "+ make some files"
56 __populate_create_dir "${SCRATCH_MNT}/blockdir" "${nr}"
57 inode="$(stat -c '%i' "${SCRATCH_MNT}/blockdir")"
58 umount "${SCRATCH_MNT}"
61 _scratch_xfs_repair -n >> $seqres.full 2>&1 || _fail "xfs_repair should not fail"
64 __populate_check_xfs_dir "${inode}" block
67 _scratch_xfs_db -x -c "inode ${inode}" -c 'dblock 0' -c "stack" -c "blocktrash -x 32 -y $((blksz * 8)) -z ${FUZZ_ARGS}" >> $seqres.full
69 echo "+ mount image && modify dir"
70 if _try_scratch_mount >> $seqres.full 2>&1; then
72 rm -rf "${SCRATCH_MNT}/blockdir/00000000" 2> /dev/null && _fail "modified corrupt directory"
73 mkdir "${SCRATCH_MNT}/blockdir/xxxxxxxx" 2> /dev/null && _fail "add to corrupt directory"
74 umount "${SCRATCH_MNT}"
78 _scratch_xfs_repair >> $seqres.full 2>&1
79 _scratch_xfs_repair >> $seqres.full 2>&1
81 echo "+ mount image (2)"
85 $CHATTR_PROG -R -f -i "${SCRATCH_MNT}/"
87 echo "+ modify dir (2)"
88 mkdir -p "${SCRATCH_MNT}/blockdir"
89 rm -rf "${SCRATCH_MNT}/blockdir/00000000" || _fail "couldn't modify repaired directory"
90 mkdir "${SCRATCH_MNT}/blockdir/xxxxxxxx" || _fail "add to repaired directory"
91 umount "${SCRATCH_MNT}"
94 _scratch_xfs_repair -n >> $seqres.full 2>&1 || _fail "xfs_repair should not fail"