generic: test MADV_POPULATE_READ with IO errors
[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 . ./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=1024
41
42 echo "+ make some files"
43 echo "file contents: moo" > "${SCRATCH_MNT}/x"
44 reps=$(( (blksz - (56 + 1)) / 2 ))
45 str="$(perl -e "print './' x $reps;")x"
46 (cd $SCRATCH_MNT; ln -s "${str}" "long_symlink")
47 cat "${SCRATCH_MNT}/long_symlink"
48 inode="$(stat -c '%i' "${SCRATCH_MNT}/long_symlink")"
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 "+ corrupt image"
55 _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
56
57 echo "+ mount image"
58 if _try_scratch_mount >> $seqres.full 2>&1; then
59         cat "${SCRATCH_MNT}/long_symlink" 2>/dev/null && _fail "symlink should be broken"
60         umount "${SCRATCH_MNT}"
61 fi
62
63 echo "+ repair fs"
64 _repair_scratch_fs >> $seqres.full 2>&1
65
66 echo "+ mount image (2)"
67 _scratch_mount
68 cat "${SCRATCH_MNT}/long_symlink" 2>/dev/null && _fail "symlink should be broken"
69 umount "${SCRATCH_MNT}"
70
71 echo "+ check fs (2)"
72 _scratch_xfs_repair -n >> $seqres.full 2>&1 || _fail "xfs_repair should not fail"
73
74 status=0
75 exit