xfs: force file creation to the data device for certain layout tests
[xfstests-dev.git] / tests / ext4 / 015
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. 015
6 #
7 # Create and populate an ext4 filesystem, corrupt an extent tree block, 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
33 _require_xfs_io_command "falloc"
34 _require_xfs_io_command "fpunch"
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
46 echo "+ mount fs image"
47 _scratch_mount
48 blksz="$(stat -f -c '%s' "${SCRATCH_MNT}")"
49 freeblks="$((3 * blksz / 12))"
50
51 echo "+ make some files"
52 $XFS_IO_PROG -f -c "falloc 0 $((blksz * freeblks))" "${SCRATCH_MNT}/bigfile" >> $seqres.full
53 seq 1 2 ${freeblks} | while read lblk; do
54         $XFS_IO_PROG -f -c "fpunch $((lblk * blksz)) ${blksz}" "${SCRATCH_MNT}/bigfile" >> $seqres.full
55 done
56 umount "${SCRATCH_MNT}"
57
58 echo "+ check fs"
59 e2fsck -fn "${SCRATCH_DEV}" >> $seqres.full 2>&1 || _fail "fsck should not fail"
60
61 echo "+ corrupt image"
62 debugfs "${SCRATCH_DEV}" -R 'ex /bigfile' 2> /dev/null | grep '^ 0' | awk '{print $8}' | while read blk; do
63         $XFS_IO_PROG -f -c "pwrite -S 0x62 $((blk * blksz + 8)) 8" "${SCRATCH_DEV}" >> $seqres.full
64 done
65
66 echo "+ mount image"
67 _scratch_mount
68
69 echo "+ modify files"
70 echo moo >> "${SCRATCH_MNT}/bigfile" 2> /dev/null && _fail "extent tree should be corrupt"
71 umount "${SCRATCH_MNT}"
72
73 echo "+ repair fs"
74 e2fsck -fy "${SCRATCH_DEV}" >> $seqres.full 2>&1
75
76 echo "+ mount image (2)"
77 _scratch_mount
78
79 echo "+ modify files (2)"
80 $XFS_IO_PROG -f -c "pwrite ${blksz} ${blksz}" "${SCRATCH_MNT}/bigfile" >> $seqres.full
81 umount "${SCRATCH_MNT}"
82
83 echo "+ check fs (2)"
84 e2fsck -fn "${SCRATCH_DEV}" >> $seqres.full 2>&1 || _fail "fsck should not fail"
85
86 status=0
87 exit