4 # Create and populate an ext4 filesystem, corrupt a block bitmap, then
5 # see how the kernel and e2fsck deal with it.
7 #-----------------------------------------------------------------------
8 # Copyright (c) 2015 Oracle, Inc. All Rights Reserved.
10 # This program is free software; you can redistribute it and/or
11 # modify it under the terms of the GNU General Public License as
12 # published by the Free Software Foundation.
14 # This program is distributed in the hope that it would be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write the Free Software Foundation,
21 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #-----------------------------------------------------------------------
26 seqres=$RESULT_DIR/$seq
27 echo "QA output created by $seq"
31 status=1 # failure is the default!
32 trap "_cleanup; exit \$status" 0 1 2 3 15
40 # get standard environment, filters and checks
45 # real QA test starts here
49 _require_xfs_io_command "falloc"
51 test -n "${FORCE_FUZZ}" || _require_scratch_ext4_crc
55 TESTDIR="${SCRATCH_MNT}/scratchdir"
56 TESTFILE="${TESTDIR}/testfile"
58 echo "+ create scratch fs"
59 _scratch_mkfs_ext4 > /dev/null 2>&1
60 dumpe2fs -g "${SCRATCH_DEV}" > /dev/null 2>&1 || _notrun "dumpe2fs -g not supported"
61 nr_groups="$(dumpe2fs -g "${SCRATCH_DEV}" 2> /dev/null | tail -n 1 | cut -d : -f 1)"
63 echo "+ mount fs image"
65 # abuse orlov allocator in the hopes that each bg ends up with some inodes
66 for i in `seq 1 $((nr_groups * 8))`; do
67 mkdir -p "${SCRATCH_MNT}/d_${i}"
69 blksz="$(stat -f -c '%s' "${SCRATCH_MNT}")"
70 freeblks="$(stat -f -c '%a' "${SCRATCH_MNT}")"
71 $XFS_IO_PROG -f -c "falloc 0 $((blksz * freeblks))" "${SCRATCH_MNT}/bigfile2" >> $seqres.full
72 umount "${SCRATCH_MNT}"
74 echo "+ make some files"
76 rm -rf "${SCRATCH_MNT}/bigfile2"
77 touch "${SCRATCH_MNT}/bigfile"
78 umount "${SCRATCH_MNT}"
81 e2fsck -fn "${SCRATCH_DEV}" >> $seqres.full 2>&1 || _fail "fsck should not fail"
83 echo "+ corrupt image"
84 dumpe2fs -g "${SCRATCH_DEV}" 2>/dev/null | awk -F ':' '{if (int($5) > 0) {print $5}}' | while read blk; do
85 debugfs -w -n -R "zap_block -p 0xff ${blk}" "${SCRATCH_DEV}" >> $seqres.full 2>&1 || _fail "block bitmap fuzz failed"
92 b_bytes="$(stat -c '%B' "${SCRATCH_MNT}/bigfile")"
93 $XFS_IO_PROG -f -c "falloc 0 $((blksz * freeblks))" "${SCRATCH_MNT}/bigfile" >> $seqres.full 2> /dev/null
94 after="$(stat -c '%b' "${SCRATCH_MNT}/bigfile")"
95 echo "$((after * b_bytes))" lt "$((blksz * freeblks / 4))" >> $seqres.full
96 test "$((after * b_bytes))" -lt "$((blksz * freeblks / 4))" || _fail "falloc should fail"
97 umount "${SCRATCH_MNT}"
100 e2fsck -fy "${SCRATCH_DEV}" >> $seqres.full 2>&1
102 echo "+ mount image (2)"
105 echo "+ modify files (2)"
106 $XFS_IO_PROG -f -c "falloc 0 $((blksz * freeblks))" "${SCRATCH_MNT}/bigfile" >> $seqres.full
107 umount "${SCRATCH_MNT}"
109 echo "+ check fs (2)"
110 e2fsck -fn "${SCRATCH_DEV}" >> $seqres.full 2>&1 || _fail "fsck should not fail"