common/xfs: refactor commands to select a particular xfs backing device
[xfstests-dev.git] / tests / xfs / 124
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. 124
6 #
7 # Create and populate an XFS filesystem, corrupt a block xattr, then see
8 # how the kernel and xfs_repair 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 . ./common/populate
30
31 # real QA test starts here
32 _supported_fs xfs
33
34 _require_scratch
35 test -n "${FORCE_FUZZ}" || _require_scratch_xfs_crc
36 _require_attrs
37 _require_populate_commands
38 _require_xfs_db_blocktrash_z_command
39 test -z "${FUZZ_ARGS}" && FUZZ_ARGS="-n 8 -3"
40
41 rm -f $seqres.full
42
43 echo "+ create scratch fs"
44 _scratch_mkfs_xfs > /dev/null
45
46 echo "+ mount fs image"
47 _scratch_mount
48 blksz="$(stat -f -c '%s' "${SCRATCH_MNT}")"
49 nr="$((blksz / 40))"
50 leaf_lblk="$((32 * 1073741824 / blksz))"
51 node_lblk="$((64 * 1073741824 / blksz))"
52
53 echo "+ make some files"
54 touch "${SCRATCH_MNT}/attrfile"
55 seq 0 "${nr}" | while read d; do
56         setfattr -n "user.x$(printf "%.08d" "$d")" -v "0000000000000000" "${SCRATCH_MNT}/attrfile"
57 done
58 inode="$(stat -c '%i' "${SCRATCH_MNT}/attrfile")"
59 umount "${SCRATCH_MNT}"
60
61 echo "+ check fs"
62 _scratch_xfs_repair -n >> $seqres.full 2>&1 || _fail "xfs_repair should not fail"
63
64 echo "+ check xattr"
65 _scratch_xfs_db -x -c "inode ${inode}" -c "bmap" >> $seqres.full
66 _scratch_xfs_db -x -c "inode ${inode}" -c "ablock 0" -c "stack" | grep -q 'file attr block is unmapped' && _fail "failed to create a block xattr (data)"
67 _scratch_xfs_db -x -c "inode ${inode}" -c "ablock ${leaf_lblk}" -c "stack" | grep -q 'file attr block is unmapped' || _fail "failed to create a block xattr (leaf)"
68 _scratch_xfs_db -x -c "inode ${inode}" -c "ablock ${node_lblk}" -c "stack" | grep -q 'file attr block is unmapped' || _fail "failed to create a block xattr (free)"
69
70 echo "+ corrupt xattr"
71 _scratch_xfs_db -x -c "inode ${inode}" -c 'ablock 0' -c "stack" -c "blocktrash -x 32 -y $((blksz * 8)) -z ${FUZZ_ARGS}" >> $seqres.full
72
73 echo "+ mount image && modify xattr"
74 if _try_scratch_mount >> $seqres.full 2>&1; then
75
76         setfattr -x "user.x00000000" "${SCRATCH_MNT}/attrfile" 2> /dev/null && _fail "modified corrupt xattr"
77         umount "${SCRATCH_MNT}"
78 fi
79
80 echo "+ repair fs"
81 _repair_scratch_fs >> $seqres.full 2>&1
82 _repair_scratch_fs >> $seqres.full 2>&1
83
84 echo "+ mount image (2)"
85 _scratch_mount
86
87 echo "+ chattr -R -i"
88 $CHATTR_PROG -R -f -i "${SCRATCH_MNT}/"
89
90 echo "+ modify xattr (2)"
91 getfattr "${SCRATCH_MNT}/attrfile" -n "user.x00000000" > /dev/null 2>&1 && (setfattr -x "user.x00000000" "${SCRATCH_MNT}/attrfile" || _fail "remove corrupt xattr")
92 setfattr -n "user.x00000000" -v 'x0x0x0x0' "${SCRATCH_MNT}/attrfile" || _fail "add corrupt xattr"
93 umount "${SCRATCH_MNT}"
94
95 echo "+ check fs (2)"
96 _scratch_xfs_repair -n >> $seqres.full 2>&1 || _fail "xfs_repair should not fail"
97
98 status=0
99 exit