cf0a36d0d768746cb273b859fcf000e3b5e0877f
[xfstests-dev.git] / tests / xfs / 112
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. 112
6 #
7 # Create and populate an XFS filesystem, corrupt a node directory's freeindex
8 # extent, 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
34 _require_scratch
35 test -n "${FORCE_FUZZ}" || _require_scratch_xfs_crc
36 _require_attrs
37 _require_populate_commands
38 _require_xfs_db_blocktrash_z_command
39 test -z "${FUZZ_ARGS}" && FUZZ_ARGS="-n 8 -3"
40
41 rm -f $seqres.full
42
43 echo "+ create scratch fs"
44 _scratch_mkfs_xfs > /dev/null
45
46 echo "+ mount fs image"
47 _scratch_mount
48 dblksz="$($XFS_INFO_PROG "${SCRATCH_MNT}" | grep naming.*bsize | sed -e 's/^.*bsize=//g' -e 's/\([0-9]*\).*$/\1/g')"
49 nr="$((16 * dblksz / 40))"
50 blksz="$(stat -f -c '%s' "${SCRATCH_MNT}")"
51 leaf_lblk="$((32 * 1073741824 / blksz))"
52 node_lblk="$((64 * 1073741824 / blksz))"
53
54 echo "+ make some files"
55 __populate_create_dir "${SCRATCH_MNT}/blockdir" "${nr}" true
56 inode="$(stat -c '%i' "${SCRATCH_MNT}/blockdir")"
57 umount "${SCRATCH_MNT}"
58
59 echo "+ check fs"
60 _scratch_xfs_repair -n >> $seqres.full 2>&1 || _fail "xfs_repair should not fail"
61
62 echo "+ check dir"
63 __populate_check_xfs_dir "${inode}" node
64
65 echo "+ corrupt dir"
66 loff="${node_lblk}"
67 while true; do
68         _scratch_xfs_db -x -c "inode ${inode}" -c "dblock ${loff}" -c "stack" | grep -q 'file data block is unmapped' && break
69         _scratch_xfs_db -x -c "inode ${inode}" -c "dblock ${loff}" -c "stack" -c "blocktrash -x 32 -y $((blksz * 8)) -z ${FUZZ_ARGS}" >> $seqres.full
70         loff="$((loff + 1))"
71 done
72
73 echo "+ mount image && modify dir"
74 if _try_scratch_mount >> $seqres.full 2>&1; then
75
76         rm -rf "${SCRATCH_MNT}/blockdir/00000000" 2> /dev/null && _fail "modified corrupt directory"
77         mkdir "${SCRATCH_MNT}/blockdir/xxxxxxxx" 2> /dev/null && _fail "add to corrupt directory"
78         umount "${SCRATCH_MNT}"
79 fi
80
81 echo "+ repair fs"
82 _scratch_xfs_repair >> $seqres.full 2>&1
83 if [ $? -eq 2 ]; then
84         _scratch_mount
85         umount "${SCRATCH_MNT}"
86         _scratch_xfs_repair >> $seqres.full 2>&1
87 fi
88
89 echo "+ mount image (2)"
90 _scratch_mount
91
92 echo "+ chattr -R -i"
93 $CHATTR_PROG -R -f -i "${SCRATCH_MNT}/"
94
95 echo "+ modify dir (2)"
96 mkdir -p "${SCRATCH_MNT}/blockdir"
97 rm -rf "${SCRATCH_MNT}/blockdir/00000000" || _fail "couldn't modify repaired directory"
98 mkdir "${SCRATCH_MNT}/blockdir/xxxxxxxx" || _fail "add to repaired directory"
99 umount "${SCRATCH_MNT}"
100
101 echo "+ check fs (2)"
102 _scratch_xfs_repair -n >> $seqres.full 2>&1 || _fail "xfs_repair should not fail"
103
104 status=0
105 exit