common/xfs: refactor commands to select a particular xfs backing device
[xfstests-dev.git] / tests / xfs / 162
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0-or-later
3 # Copyright (c) 2021 Oracle.  All Rights Reserved.
4 #
5 # FS QA Test No. 162
6 #
7 # Make sure that attrs are handled properly when repair has to reset the root
8 # directory.
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 7 15
18
19 _cleanup()
20 {
21         cd /
22         rm -rf $tmp.*
23 }
24
25 # get standard environment, filters and checks
26 . ./common/rc
27 . ./common/filter
28 . ./common/populate
29 . ./common/fuzzy
30
31 # real QA test starts here
32 _supported_fs xfs
33 _require_scratch_nocheck
34 _require_populate_commands
35 _require_xfs_db_command "fuzz"
36
37 rm -f $seqres.full
38
39 echo "Format and populate btree attr root dir"
40 _scratch_mkfs > "$seqres.full" 2>&1
41 _scratch_mount
42
43 blksz="$(stat -f -c '%s' "${SCRATCH_MNT}")"
44 __populate_create_attr "${SCRATCH_MNT}" "$((64 * blksz / 40))" true
45 _scratch_unmount
46
47 echo "Break the root directory"
48 _scratch_xfs_fuzz_metadata_field core.mode zeroes 'sb 0' 'addr rootino' >> $seqres.full 2>&1
49
50 echo "Detect bad root directory"
51 _scratch_xfs_repair -n >> $seqres.full 2>&1 && \
52         echo "Should have detected bad root dir"
53
54 echo "Fix bad root directory"
55 _scratch_xfs_repair >> $seqres.full 2>&1
56
57 echo "Detect fixed root directory"
58 _scratch_xfs_repair -n >> $seqres.full 2>&1
59
60 echo "Mount test"
61 _scratch_mount
62
63 # success, all done
64 status=0
65 exit