xfs: fix old fuzz test invocations of xfs_repair
[xfstests-dev.git] / tests / xfs / 123
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. 123
6 #
7 # Create and populate an XFS filesystem, corrupt a long symlink, then see how
8 # 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 blksz=1024
49
50 echo "+ make some files"
51 echo "file contents: moo" > "${SCRATCH_MNT}/x"
52 reps=$(( (blksz - (56 + 1)) / 2 ))
53 str="$(perl -e "print './' x $reps;")x"
54 (cd $SCRATCH_MNT; ln -s "${str}" "long_symlink")
55 cat "${SCRATCH_MNT}/long_symlink"
56 inode="$(stat -c '%i' "${SCRATCH_MNT}/long_symlink")"
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 "+ corrupt image"
63 _scratch_xfs_db -x -c "inode ${inode}" -c "dblock 0" -c "stack" -c "blocktrash -x 32 -o 256 -y $((blksz * 4)) -z ${FUZZ_ARGS}" >> $seqres.full
64
65 echo "+ mount image"
66 if _try_scratch_mount >> $seqres.full 2>&1; then
67         cat "${SCRATCH_MNT}/long_symlink" 2>/dev/null && _fail "symlink should be broken"
68         umount "${SCRATCH_MNT}"
69 fi
70
71 echo "+ repair fs"
72 _repair_scratch_fs >> $seqres.full 2>&1
73
74 echo "+ mount image (2)"
75 _scratch_mount
76 cat "${SCRATCH_MNT}/long_symlink" 2>/dev/null && _fail "symlink should be broken"
77 umount "${SCRATCH_MNT}"
78
79 echo "+ check fs (2)"
80 _scratch_xfs_repair -n >> $seqres.full 2>&1 || _fail "xfs_repair should not fail"
81
82 status=0
83 exit