xfs: convert tests to SPDX license tags
[xfstests-dev.git] / tests / xfs / 125
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2015 Oracle, Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. 125
6 #
7 # Create and populate an XFS filesystem, corrupt a leaf xattr's index extent,
8 # then see how the kernel and xfs_repair deal with it.
9 #
10 seq=`basename $0`
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
13
14 here=`pwd`
15 tmp=/tmp/$$
16 status=1        # failure is the default!
17 trap "_cleanup; exit \$status" 0 1 2 3 15
18
19 _cleanup()
20 {
21     cd /
22     #rm -f $tmp.*
23 }
24
25 # get standard environment, filters and checks
26 . ./common/rc
27 . ./common/filter
28 . ./common/attr
29 . ./common/populate
30
31 # real QA test starts here
32 _supported_fs xfs
33 _supported_os Linux
34
35 _require_scratch
36 test -n "${FORCE_FUZZ}" || _require_scratch_xfs_crc
37 _require_attrs
38 _require_populate_commands
39 _require_xfs_db_blocktrash_z_command
40 test -z "${FUZZ_ARGS}" && FUZZ_ARGS="-n 8 -3"
41
42 rm -f $seqres.full
43
44 echo "+ create scratch fs"
45 _scratch_mkfs_xfs > /dev/null
46
47 echo "+ mount fs image"
48 _scratch_mount
49 blksz="$(stat -f -c '%s' "${SCRATCH_MNT}")"
50 nr="$((8 * blksz / 40))"
51
52 echo "+ make some files"
53 touch "${SCRATCH_MNT}/attrfile"
54 seq 0 "${nr}" | while read d; do
55         setfattr -n "user.x$(printf "%.08d" "$d")" -v "0000000000000000" "${SCRATCH_MNT}/attrfile"
56 done
57 seq 1 2 "${nr}" | while read d; do
58         setfattr -x "user.x$(printf "%.08d" "$d")" "${SCRATCH_MNT}/attrfile"
59 done
60 inode="$(stat -c '%i' "${SCRATCH_MNT}/attrfile")"
61 umount "${SCRATCH_MNT}"
62
63 echo "+ check fs"
64 _scratch_xfs_repair -n >> $seqres.full 2>&1 || _fail "xfs_repair should not fail"
65
66 echo "+ check xattr"
67 _scratch_xfs_db -x -c "inode ${inode}" -c "bmap" >> $seqres.full
68 _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)"
69 _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
71 echo "+ corrupt xattr"
72 _scratch_xfs_db -x -c "inode ${inode}" -c 'ablock 0' -c "stack" -c "blocktrash -x 32 -o +32 -y $((blksz * 8)) -z ${FUZZ_ARGS}" >> $seqres.full
73
74 echo "+ mount image"
75 if _try_scratch_mount >> $seqres.full 2>&1; then
76
77         echo "+ modify xattr"
78         setfattr -x "user.x00000000" "${SCRATCH_MNT}/attrfile" 2> /dev/null && _fail "modified corrupt xattr"
79         umount "${SCRATCH_MNT}"
80 fi
81
82 echo "+ repair fs"
83 _scratch_xfs_repair >> $seqres.full 2>&1
84 _scratch_xfs_repair >> $seqres.full 2>&1
85
86 echo "+ mount image (2)"
87 _scratch_mount
88
89 echo "+ chattr -R -i"
90 $CHATTR_PROG -R -f -i "${SCRATCH_MNT}/"
91
92 echo "+ modify xattr (2)"
93 setfattr -n "user.x00000000" -v "1111111111111111" "${SCRATCH_MNT}/attrfile" || _fail "modified corrupt xattr"
94 setfattr -x "user.x00000000" "${SCRATCH_MNT}/attrfile" || _fail "delete corrupt xattr"
95 umount "${SCRATCH_MNT}"
96
97 echo "+ check fs (2)"
98 _scratch_xfs_repair -n >> $seqres.full 2>&1 || _fail "xfs_repair should not fail"
99
100 status=0
101 exit