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