xfs/530: skip test if user MKFS_OPTIONS screw up formatting
[xfstests-dev.git] / tests / xfs / 120
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. 120
6 #
7 # Create and populate an XFS filesystem, corrupt the bmbt, then see how
8 # the kernel and xfs_repair 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 . ./common/populate
24
25 # real QA test starts here
26 _supported_fs xfs
27
28 _require_scratch
29 test -n "${FORCE_FUZZ}" || _require_scratch_xfs_crc
30 _require_attrs
31 _require_populate_commands
32 _require_xfs_db_blocktrash_z_command
33 test -z "${FUZZ_ARGS}" && FUZZ_ARGS="-n 8 -3"
34
35 echo "+ create scratch fs"
36 _scratch_mkfs_xfs > /dev/null
37
38 echo "+ mount fs image"
39 _scratch_mount
40 blksz="$(stat -f -c '%s' "${SCRATCH_MNT}")"
41 nr="$((blksz * 2 / 16))"
42 _xfs_force_bdev data $SCRATCH_MNT
43
44 echo "+ make some files"
45 $XFS_IO_PROG -f -c "pwrite -S 0x62 0 $((blksz * nr))" -c 'fsync' "${SCRATCH_MNT}/bigfile" >> $seqres.full
46 for i in $(seq 1 2 ${nr}); do
47         $XFS_IO_PROG -f -c "fpunch $((i * blksz)) ${blksz}" "${SCRATCH_MNT}/bigfile" >> $seqres.full
48 done
49 inode="$(stat -c '%i' "${SCRATCH_MNT}/bigfile")"
50 umount "${SCRATCH_MNT}"
51
52 echo "+ check fs"
53 _scratch_xfs_repair -n >> $seqres.full 2>&1 || _fail "xfs_repair should not fail"
54
55 echo "+ corrupt image"
56 _scratch_xfs_db -x -c "inode ${inode}" -c "addr u.bmbt.ptrs[1]" -c "addr u3.bmbt.ptrs[1]" -c "stack" -c "blocktrash -x 32 -y $((blksz * 8)) -z ${FUZZ_ARGS}" >> $seqres.full
57
58 echo "+ mount image && modify files"
59 if _try_scratch_mount >> $seqres.full 2>&1; then
60
61         before="$(stat -c '%b' "${SCRATCH_MNT}/bigfile")"
62         $XFS_IO_PROG -f -c "pwrite -S 0x62 ${blksz} ${blksz}" -c 'fsync' "${SCRATCH_MNT}/bigfile" >> $seqres.full 2> /dev/null
63         after="$(stat -c '%b' "${SCRATCH_MNT}/bigfile")"
64         test "${before}" -eq "${after}" || _fail "pwrite should fail on corrupt bmbt"
65         umount "${SCRATCH_MNT}"
66 fi
67
68 echo "+ repair fs"
69 _repair_scratch_fs >> $seqres.full 2>&1
70
71 echo "+ mount image (2)"
72 _scratch_mount
73
74 echo "+ chattr -R -i"
75 $CHATTR_PROG -R -f -i "${SCRATCH_MNT}/"
76
77 echo "+ modify files (2)"
78 touch "${SCRATCH_MNT}/bigfile"
79 before="$(stat -c '%b' "${SCRATCH_MNT}/bigfile")"
80 $XFS_IO_PROG -f -c "pwrite -S 0x62 ${blksz} ${blksz}" -c 'fsync' "${SCRATCH_MNT}/bigfile" >> $seqres.full 2> /dev/null
81 after="$(stat -c '%b' "${SCRATCH_MNT}/bigfile")"
82 test "${before}" -ne "${after}" || _fail "pwrite failed after fixing corrupt bmbt"
83 umount "${SCRATCH_MNT}"
84
85 echo "+ check fs (2)"
86 _scratch_xfs_repair -n >> $seqres.full 2>&1 || _fail "xfs_repair should not fail"
87
88 status=0
89 exit