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 leaf xattr's data extent,
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
35 test -n "${FORCE_FUZZ}" || _require_scratch_xfs_crc
37 _require_populate_commands
38 _require_xfs_db_blocktrash_z_command
39 test -z "${FUZZ_ARGS}" && FUZZ_ARGS="-n 8 -3"
43 echo "+ create scratch fs"
44 _scratch_mkfs_xfs > /dev/null
46 echo "+ mount fs image"
48 blksz="$(stat -f -c '%s' "${SCRATCH_MNT}")"
49 nr="$((8 * blksz / 40))"
51 echo "+ make some files"
52 touch "${SCRATCH_MNT}/attrfile"
53 seq 0 "${nr}" | while read d; do
54 setfattr -n "user.x$(printf "%.08d" "$d")" -v "0000000000000000" "${SCRATCH_MNT}/attrfile"
56 seq 1 2 "${nr}" | while read d; do
57 setfattr -x "user.x$(printf "%.08d" "$d")" "${SCRATCH_MNT}/attrfile"
59 inode="$(stat -c '%i' "${SCRATCH_MNT}/attrfile")"
60 umount "${SCRATCH_MNT}"
63 _scratch_xfs_repair -n >> $seqres.full 2>&1 || _fail "xfs_repair should not fail"
66 _scratch_xfs_db -x -c "inode ${inode}" -c "bmap" >> $seqres.full
67 _scratch_xfs_db -x -c "inode ${inode}" -c "ablock 0" -c "stack" | grep -q 'file attr block is unmapped' && _fail "failed to create a leaf xattr (index)"
68 _scratch_xfs_db -x -c "inode ${inode}" -c "ablock 1" -c "stack" | grep -q 'file attr block is unmapped' && _fail "failed to create a leaf xattr (data)"
70 echo "+ corrupt xattr"
73 _scratch_xfs_db -x -c "inode ${inode}" -c "ablock ${loff}" -c "stack" | grep -q 'file attr block is unmapped' && break
74 _scratch_xfs_db -x -c "inode ${inode}" -c "ablock ${loff}" -c "stack" -c "blocktrash -o 4 -x 32 -y $((blksz * 8)) -z ${FUZZ_ARGS}" >> $seqres.full
78 echo "+ mount image && modify xattr"
79 if _try_scratch_mount >> $seqres.full 2>&1; then
81 setfattr -x "user.x00000000" "${SCRATCH_MNT}/attrfile" 2> /dev/null && _fail "modified corrupt xattr"
82 umount "${SCRATCH_MNT}"
86 _scratch_xfs_repair >> $seqres.full 2>&1
87 _scratch_xfs_repair >> $seqres.full 2>&1
89 echo "+ mount image (2)"
93 $CHATTR_PROG -R -f -i "${SCRATCH_MNT}/"
95 echo "+ modify xattr (2)"
96 getfattr "${SCRATCH_MNT}/attrfile" -n "user.x00000000" 2> /dev/null && (setfattr -x "user.x00000000" "${SCRATCH_MNT}/attrfile" || _fail "modified corrupt xattr")
97 umount "${SCRATCH_MNT}"
100 _scratch_xfs_repair -n >> $seqres.full 2>&1 || _fail "xfs_repair should not fail"