xfs: test xfs-specific reflink pieces
[xfstests-dev.git] / tests / xfs / 130
1 #! /bin/bash
2 # FS QA Test No. 130
3 #
4 # Create and populate an XFS filesystem, corrupt the refcount btree,
5 # then see how the kernel and xfs_repair 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 . ./common/reflink
45
46 # real QA test starts here
47 _supported_os Linux
48 _supported_fs xfs
49 _require_scratch_reflink
50 _require_cp_reflink
51 test -n "${FORCE_FUZZ}" || _require_scratch_xfs_crc
52
53 rm -f "$seqres.full"
54
55 echo "+ create scratch fs"
56 _scratch_mkfs_xfs > /dev/null
57
58 echo "+ mount fs image"
59 _scratch_mount
60 blksz="$(stat -f -c '%s' "${SCRATCH_MNT}")"
61 agcount="$(xfs_info "${SCRATCH_MNT}" | grep agcount= | sed -e 's/^.*agcount=\([0-9]*\),.*$/\1/g')"
62
63 echo "+ make some files"
64 _pwrite_byte 0x62 0 $((blksz * 64)) "${SCRATCH_MNT}/file0" >> "$seqres.full"
65 _pwrite_byte 0x61 0 $((blksz * 64)) "${SCRATCH_MNT}/file1" >> "$seqres.full"
66 _cp_reflink "${SCRATCH_MNT}/file0" "${SCRATCH_MNT}/file2"
67 _cp_reflink "${SCRATCH_MNT}/file1" "${SCRATCH_MNT}/file3"
68 umount "${SCRATCH_MNT}"
69
70 echo "+ check fs"
71 _scratch_xfs_repair -n >> "$seqres.full" 2>&1 || \
72         _fail "xfs_repair should not fail"
73
74 echo "+ corrupt image"
75 seq 0 $((agcount - 1)) | while read ag; do
76         $XFS_DB_PROG -x -c "agf ${ag}" -c "agf ${ag}" -c "addr refcntroot" \
77                 -c "stack" -c "blocktrash -x 4096 -y 4096 -z -n 8 -3" \
78                 "${SCRATCH_DEV}" >> "$seqres.full" 2>&1
79 done
80
81 echo "+ mount image"
82 _scratch_mount
83
84 echo "+ reflink more"
85 _cp_reflink "${SCRATCH_MNT}/file1" "${SCRATCH_MNT}/file4" 2> /dev/null && \
86         _fail "should not be able to reflink with busted refcount btree"
87 umount "${SCRATCH_MNT}"
88
89 echo "+ repair fs"
90 _scratch_xfs_repair >> "$seqres.full" 2>&1
91 _scratch_xfs_repair >> "$seqres.full" 2>&1
92
93 echo "+ mount image (2)"
94 _scratch_mount
95
96 echo "+ chattr -R -i"
97 chattr -R -f -i "${SCRATCH_MNT}/"
98
99 echo "+ reflink more (2)"
100 _cp_reflink "${SCRATCH_MNT}/file1" "${SCRATCH_MNT}/file5" || \
101         _fail "modified refcount tree"
102 umount "${SCRATCH_MNT}"
103
104 echo "+ check fs (2)"
105 _scratch_xfs_repair -n >> "$seqres.full" 2>&1 || \
106         _fail "xfs_repair should not fail"
107
108 status=0
109 exit