9e4ac761acf3452add69ee0e4aeaf1af55c793e1
[xfstests-dev.git] / tests / ext4 / 009
1 #! /bin/bash
2 # FS QA Test No. 009
3 #
4 # Create and populate an ext4 filesystem, corrupt a block bitmap, then
5 # see how the kernel and e2fsck deal with it.
6 #
7 #-----------------------------------------------------------------------
8 # Copyright (c) 2015 Oracle, Inc.  All Rights Reserved.
9 #
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.
13 #
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.
18 #
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 #-----------------------------------------------------------------------
23 #
24
25 seq=`basename $0`
26 seqres=$RESULT_DIR/$seq
27 echo "QA output created by $seq"
28
29 here=`pwd`
30 tmp=/tmp/$$
31 status=1        # failure is the default!
32 trap "_cleanup; exit \$status" 0 1 2 3 15
33
34 _cleanup()
35 {
36     cd /
37     #rm -f $tmp.*
38 }
39
40 # get standard environment, filters and checks
41 . ./common/rc
42 . ./common/filter
43 . ./common/attr
44
45 # real QA test starts here
46 _supported_fs ext4
47 _supported_os Linux
48
49 _require_xfs_io_command "falloc"
50 _require_scratch
51 test -n "${FORCE_FUZZ}" || _require_scratch_ext4_crc
52 _require_attrs
53
54 rm -f $seqres.full
55 TESTDIR="${SCRATCH_MNT}/scratchdir"
56 TESTFILE="${TESTDIR}/testfile"
57
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)"
62
63 echo "+ mount fs image"
64 _scratch_mount
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}"
68 done
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}"
73
74 echo "+ make some files"
75 _scratch_mount
76 rm -rf "${SCRATCH_MNT}/bigfile2"
77 touch "${SCRATCH_MNT}/bigfile"
78 umount "${SCRATCH_MNT}"
79
80 echo "+ check fs"
81 e2fsck -fn "${SCRATCH_DEV}" >> $seqres.full 2>&1 || _fail "fsck should not fail"
82
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"
86 done
87
88 echo "+ mount image"
89 _scratch_mount
90
91 echo "+ modify files"
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}"
98
99 echo "+ repair fs"
100 e2fsck -fy "${SCRATCH_DEV}" >> $seqres.full 2>&1
101
102 echo "+ mount image (2)"
103 _scratch_mount
104
105 echo "+ modify files (2)"
106 $XFS_IO_PROG -f -c "falloc 0 $((blksz * freeblks))" "${SCRATCH_MNT}/bigfile" >> $seqres.full
107 umount "${SCRATCH_MNT}"
108
109 echo "+ check fs (2)"
110 e2fsck -fn "${SCRATCH_DEV}" >> $seqres.full 2>&1 || _fail "fsck should not fail"
111
112 status=0
113 exit