generic: test MADV_POPULATE_READ with IO errors
[xfstests-dev.git] / tests / ext4 / 010
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. 010
6 #
7 # Create and populate an ext4 filesystem, corrupt an inode bitmap, then
8 # see how the kernel and e2fsck 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
24 # real QA test starts here
25 _supported_fs ext4
26
27 _require_scratch
28 _require_dumpe2fs
29 test -n "${FORCE_FUZZ}" || _require_scratch_ext4_crc
30 _require_attrs
31 _require_command "$RESIZE2FS_PROG" resize2fs
32
33 TESTDIR="${SCRATCH_MNT}/scratchdir"
34 TESTFILE="${TESTDIR}/testfile"
35
36 echo "+ create scratch fs"
37 _scratch_mkfs_ext4 > /dev/null 2>&1
38 $DUMPE2FS_PROG -g "${SCRATCH_DEV}" > /dev/null 2>&1 || _notrun "dumpe2fs -g not supported"
39 $RESIZE2FS_PROG -M "${SCRATCH_DEV}" >> $seqres.full 2>&1
40 nr_groups="$($DUMPE2FS_PROG -g "${SCRATCH_DEV}" 2> /dev/null | tail -n 1 | cut -d : -f 1)"
41
42 echo "+ mount fs image"
43 _scratch_mount
44
45 echo "+ make some files"
46 # abuse orlov allocator in the hopes that each bg ends up with some inodes
47 for i in `seq 1 $((nr_groups * 8))`; do
48         mkdir -p "${SCRATCH_MNT}/d_${i}"
49 done
50 umount "${SCRATCH_MNT}"
51
52 echo "+ check fs"
53 e2fsck -fn "${SCRATCH_DEV}" >> $seqres.full 2>&1 || _fail "fsck should not fail"
54
55 echo "+ corrupt image"
56 $DUMPE2FS_PROG -g "${SCRATCH_DEV}" 2>/dev/null | awk -F ':' '{if (int($6) > 0) {print $6}}' | while read blk; do
57         debugfs -w -n -R "zap_block ${blk}" "${SCRATCH_DEV}" >> $seqres.full 2>&1 || _fail "inode bitmap fuzz failed"
58 done
59
60 echo "+ mount image"
61 _scratch_mount
62
63 echo "+ modify files"
64 touch "${SCRATCH_MNT}/file0" > /dev/null 2>&1 && _fail "touch should fail"
65 umount "${SCRATCH_MNT}"
66
67 echo "+ repair fs"
68 e2fsck -fy "${SCRATCH_DEV}" >> $seqres.full 2>&1
69
70 echo "+ mount image (2)"
71 _scratch_mount
72
73 echo "+ modify files (2)"
74 touch "${SCRATCH_MNT}/file1"
75 umount "${SCRATCH_MNT}"
76
77 echo "+ check fs (2)"
78 e2fsck -fn "${SCRATCH_DEV}" >> $seqres.full 2>&1 || _fail "fsck should not fail"
79
80 status=0
81 exit