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 xattr, then see
8 # how the kernel and xfs_repair deal with it.
13 # Override the default cleanup function.
20 # Import common functions.
25 # real QA test starts here
29 test -n "${FORCE_FUZZ}" || _require_scratch_xfs_crc
31 _require_populate_commands
32 _require_xfs_db_blocktrash_z_command
33 test -z "${FUZZ_ARGS}" && FUZZ_ARGS="-n 8 -3"
35 echo "+ create scratch fs"
36 _scratch_mkfs_xfs > /dev/null
38 echo "+ mount fs image"
40 blksz="$(stat -f -c '%s' "${SCRATCH_MNT}")"
42 leaf_lblk="$((32 * 1073741824 / blksz))"
43 node_lblk="$((64 * 1073741824 / blksz))"
45 echo "+ make some files"
46 touch "${SCRATCH_MNT}/attrfile"
47 seq 0 "${nr}" | while read d; do
48 setfattr -n "user.x$(printf "%.08d" "$d")" -v "0000000000000000" "${SCRATCH_MNT}/attrfile"
50 inode="$(stat -c '%i' "${SCRATCH_MNT}/attrfile")"
51 umount "${SCRATCH_MNT}"
54 _scratch_xfs_repair -n >> $seqres.full 2>&1 || _fail "xfs_repair should not fail"
57 _scratch_xfs_db -x -c "inode ${inode}" -c "bmap" >> $seqres.full
58 _scratch_xfs_db -x -c "inode ${inode}" -c "ablock 0" -c "stack" | grep -q 'file attr block is unmapped' && _fail "failed to create a block xattr (data)"
59 _scratch_xfs_db -x -c "inode ${inode}" -c "ablock ${leaf_lblk}" -c "stack" | grep -q 'file attr block is unmapped' || _fail "failed to create a block xattr (leaf)"
60 _scratch_xfs_db -x -c "inode ${inode}" -c "ablock ${node_lblk}" -c "stack" | grep -q 'file attr block is unmapped' || _fail "failed to create a block xattr (free)"
62 echo "+ corrupt xattr"
63 _scratch_xfs_db -x -c "inode ${inode}" -c 'ablock 0' -c "stack" -c "blocktrash -x 32 -y $((blksz * 8)) -z ${FUZZ_ARGS}" >> $seqres.full
65 echo "+ mount image && modify xattr"
66 if _try_scratch_mount >> $seqres.full 2>&1; then
68 setfattr -x "user.x00000000" "${SCRATCH_MNT}/attrfile" 2> /dev/null && _fail "modified corrupt xattr"
69 umount "${SCRATCH_MNT}"
73 _repair_scratch_fs >> $seqres.full 2>&1
74 _repair_scratch_fs >> $seqres.full 2>&1
76 echo "+ mount image (2)"
80 $CHATTR_PROG -R -f -i "${SCRATCH_MNT}/"
82 echo "+ modify xattr (2)"
83 getfattr "${SCRATCH_MNT}/attrfile" -n "user.x00000000" > /dev/null 2>&1 && (setfattr -x "user.x00000000" "${SCRATCH_MNT}/attrfile" || _fail "remove corrupt xattr")
84 setfattr -n "user.x00000000" -v 'x0x0x0x0' "${SCRATCH_MNT}/attrfile" || _fail "add corrupt xattr"
85 umount "${SCRATCH_MNT}"
88 _scratch_xfs_repair -n >> $seqres.full 2>&1 || _fail "xfs_repair should not fail"