xfs/007: fix regressions on V4 filesystems
[xfstests-dev.git] / tests / xfs / 126
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. 126
6 #
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.
9 #
10 . ./common/preamble
11 _begin_fstest fuzzers
12
13 # Override the default cleanup function.
14 _cleanup()
15 {
16     cd /
17     #rm -f $tmp.*
18 }
19
20 # Import common functions.
21 . ./common/filter
22 . ./common/attr
23 . ./common/populate
24
25 # real QA test starts here
26 _supported_fs xfs
27
28 _require_scratch
29 test -n "${FORCE_FUZZ}" || _require_scratch_xfs_crc
30 _require_attrs
31 _require_populate_commands
32 _require_xfs_db_blocktrash_z_command
33 test -z "${FUZZ_ARGS}" && FUZZ_ARGS="-n 8 -3"
34
35 echo "+ create scratch fs"
36 _scratch_mkfs_xfs > /dev/null
37
38 echo "+ mount fs image"
39 _scratch_mount
40 blksz="$(stat -f -c '%s' "${SCRATCH_MNT}")"
41 nr="$((8 * blksz / 40))"
42
43 echo "+ make some files"
44 touch "${SCRATCH_MNT}/attrfile"
45 seq 0 "${nr}" | while read d; do
46         setfattr -n "user.x$(printf "%.08d" "$d")" -v "0000000000000000" "${SCRATCH_MNT}/attrfile"
47 done
48 seq 1 2 "${nr}" | while read d; do
49         setfattr -x "user.x$(printf "%.08d" "$d")" "${SCRATCH_MNT}/attrfile"
50 done
51 inode="$(stat -c '%i' "${SCRATCH_MNT}/attrfile")"
52 umount "${SCRATCH_MNT}"
53
54 echo "+ check fs"
55 _scratch_xfs_repair -n >> $seqres.full 2>&1 || _fail "xfs_repair should not fail"
56
57 echo "+ check xattr"
58 _scratch_xfs_db -x -c "inode ${inode}" -c "bmap" >> $seqres.full
59 _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)"
60 _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)"
61
62 echo "+ corrupt xattr"
63 loff=1
64 while true; do
65         _scratch_xfs_db -x -c "inode ${inode}" -c "ablock ${loff}" -c "stack" | grep -q 'file attr block is unmapped' && break
66         _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
67         loff="$((loff + 1))"
68 done
69
70 echo "+ mount image && modify xattr"
71 if _try_scratch_mount >> $seqres.full 2>&1; then
72
73         setfattr -x "user.x00000000" "${SCRATCH_MNT}/attrfile" 2> /dev/null && _fail "modified corrupt xattr"
74         umount "${SCRATCH_MNT}"
75 fi
76
77 echo "+ repair fs"
78 _repair_scratch_fs >> $seqres.full 2>&1
79 _repair_scratch_fs >> $seqres.full 2>&1
80
81 echo "+ mount image (2)"
82 _scratch_mount
83
84 echo "+ chattr -R -i"
85 $CHATTR_PROG -R -f -i "${SCRATCH_MNT}/"
86
87 echo "+ modify xattr (2)"
88 getfattr "${SCRATCH_MNT}/attrfile" -n "user.x00000000" 2> /dev/null && (setfattr -x "user.x00000000" "${SCRATCH_MNT}/attrfile" || _fail "modified corrupt xattr")
89 umount "${SCRATCH_MNT}"
90
91 echo "+ check fs (2)"
92 _scratch_xfs_repair -n >> $seqres.full 2>&1 || _fail "xfs_repair should not fail"
93
94 status=0
95 exit