common/fuzzy: try to clear blocking flags first in _scratch_fuzz_modify
[xfstests-dev.git] / tests / ext4 / 009
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. 009
6 #
7 # Create and populate an ext4 filesystem, corrupt a block bitmap, then
8 # see how the kernel and e2fsck 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
30 # real QA test starts here
31 _supported_fs ext4
32 _supported_os Linux
33
34 _require_xfs_io_command "falloc"
35 _require_scratch
36 test -n "${FORCE_FUZZ}" || _require_scratch_ext4_crc
37 _require_attrs
38
39 rm -f $seqres.full
40 TESTDIR="${SCRATCH_MNT}/scratchdir"
41 TESTFILE="${TESTDIR}/testfile"
42
43 echo "+ create scratch fs"
44 _scratch_mkfs_ext4 > /dev/null 2>&1
45 dumpe2fs -g "${SCRATCH_DEV}" > /dev/null 2>&1 || _notrun "dumpe2fs -g not supported"
46 nr_groups="$(dumpe2fs -g "${SCRATCH_DEV}" 2> /dev/null | tail -n 1 | cut -d : -f 1)"
47
48 echo "+ mount fs image"
49 _scratch_mount
50 # abuse orlov allocator in the hopes that each bg ends up with some inodes
51 for i in `seq 1 $((nr_groups * 8))`; do
52         mkdir -p "${SCRATCH_MNT}/d_${i}"
53 done
54 blksz="$(stat -f -c '%s' "${SCRATCH_MNT}")"
55 freeblks="$(stat -f -c '%a' "${SCRATCH_MNT}")"
56 $XFS_IO_PROG -f -c "falloc 0 $((blksz * freeblks))" "${SCRATCH_MNT}/bigfile2" >> $seqres.full
57 umount "${SCRATCH_MNT}"
58
59 echo "+ make some files"
60 _scratch_mount
61 rm -rf "${SCRATCH_MNT}/bigfile2"
62 touch "${SCRATCH_MNT}/bigfile"
63 umount "${SCRATCH_MNT}"
64
65 echo "+ check fs"
66 e2fsck -fn "${SCRATCH_DEV}" >> $seqres.full 2>&1 || _fail "fsck should not fail"
67
68 echo "+ corrupt image"
69 dumpe2fs -g "${SCRATCH_DEV}" 2>/dev/null | awk -F ':' '{if (int($5) > 0) {print $5}}' | while read blk; do
70         debugfs -w -n -R "zap_block -p 0xff ${blk}" "${SCRATCH_DEV}" >> $seqres.full 2>&1 || _fail "block bitmap fuzz failed"
71 done
72
73 echo "+ mount image"
74 _scratch_mount
75
76 echo "+ modify files"
77 b_bytes="$(stat -c '%B' "${SCRATCH_MNT}/bigfile")"
78 $XFS_IO_PROG -f -c "falloc 0 $((blksz * freeblks))" "${SCRATCH_MNT}/bigfile" >> $seqres.full 2> /dev/null
79 after="$(stat -c '%b' "${SCRATCH_MNT}/bigfile")"
80 echo "$((after * b_bytes))" lt "$((blksz * freeblks / 4))" >> $seqres.full
81 test "$((after * b_bytes))" -lt "$((blksz * freeblks / 4))" || _fail "falloc should fail"
82 umount "${SCRATCH_MNT}"
83
84 echo "+ repair fs"
85 e2fsck -fy "${SCRATCH_DEV}" >> $seqres.full 2>&1
86
87 echo "+ mount image (2)"
88 _scratch_mount
89
90 echo "+ modify files (2)"
91 $XFS_IO_PROG -f -c "falloc 0 $((blksz * freeblks))" "${SCRATCH_MNT}/bigfile" >> $seqres.full
92 umount "${SCRATCH_MNT}"
93
94 echo "+ check fs (2)"
95 e2fsck -fn "${SCRATCH_DEV}" >> $seqres.full 2>&1 || _fail "fsck should not fail"
96
97 status=0
98 exit