xfs/007: fix regressions on V4 filesystems
[xfstests-dev.git] / tests / xfs / 130
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. 130
6 #
7 # Create and populate an XFS filesystem, corrupt the refcount btree,
8 # then see how the kernel and xfs_repair deal with it.
9 #
10 . ./common/preamble
11 _begin_fstest fuzzers clone
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/reflink
24
25 # real QA test starts here
26 _supported_fs xfs
27 _require_scratch_reflink
28 _require_cp_reflink
29 test -n "${FORCE_FUZZ}" || _require_scratch_xfs_crc
30
31 rm -f "$seqres.full"
32
33 echo "+ create scratch fs"
34 _scratch_mkfs_xfs > /dev/null
35
36 echo "+ mount fs image"
37 _scratch_mount
38 blksz="$(stat -f -c '%s' "${SCRATCH_MNT}")"
39 agcount="$(_xfs_mount_agcount $SCRATCH_MNT)"
40 _xfs_force_bdev data $SCRATCH_MNT
41
42 echo "+ make some files"
43 _pwrite_byte 0x62 0 $((blksz * 64)) "${SCRATCH_MNT}/file0" >> "$seqres.full"
44 _pwrite_byte 0x61 0 $((blksz * 64)) "${SCRATCH_MNT}/file1" >> "$seqres.full"
45 _cp_reflink "${SCRATCH_MNT}/file0" "${SCRATCH_MNT}/file2"
46 _cp_reflink "${SCRATCH_MNT}/file1" "${SCRATCH_MNT}/file3"
47 umount "${SCRATCH_MNT}"
48
49 echo "+ check fs"
50 _scratch_xfs_repair -n >> "$seqres.full" 2>&1 || \
51         _fail "xfs_repair should not fail"
52
53 echo "+ corrupt image"
54 seq 0 $((agcount - 1)) | while read ag; do
55         _scratch_xfs_db -x -c "agf ${ag}" -c "agf ${ag}" -c "addr refcntroot" \
56                 -c "stack" -c "blocktrash -x 4096 -y 4096 -z -n 8 -3" \
57                 >> "$seqres.full" 2>&1
58 done
59
60 echo "+ mount image"
61 _try_scratch_mount >> $seqres.full 2>&1 && \
62         echo "Should not be able to mount with broken refcountbt."
63 _scratch_unmount >> $seqres.full 2>&1
64
65 echo "+ repair fs"
66 _disable_dmesg_check
67 _repair_scratch_fs >> "$seqres.full" 2>&1
68 _repair_scratch_fs >> "$seqres.full" 2>&1
69
70 echo "+ mount image (2)"
71 _scratch_mount
72
73 echo "+ chattr -R -i"
74 $CHATTR_PROG -R -f -i "${SCRATCH_MNT}/"
75
76 echo "+ reflink more (2)"
77 _cp_reflink "${SCRATCH_MNT}/file1" "${SCRATCH_MNT}/file5" || \
78         _fail "modified refcount tree"
79 umount "${SCRATCH_MNT}"
80
81 echo "+ check fs (2)"
82 _scratch_xfs_repair -n >> "$seqres.full" 2>&1 || \
83         _fail "xfs_repair should not fail"
84
85 status=0
86 exit