xfs: refactor _xfs_check calls to the scratch device
[xfstests-dev.git] / tests / xfs / 291
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) Red Hat, Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. 291
6 #
7 # Test xfs_repair on fragmented multi-block dir2 fs
8 #
9 seq=`basename $0`
10 seqres=$RESULT_DIR/$seq
11 echo "QA output created by $seq"
12
13 here=`pwd`
14 tmp=/tmp/$$
15 status=1        # failure is the default!
16 trap "_cleanup; exit \$status" 0 1 2 3 15
17
18 _cleanup()
19 {
20     cd /
21     rm -f $tmp.*
22 }
23
24 # get standard environment, filters and checks
25 . ./common/rc
26 . ./common/filter
27
28 _supported_fs xfs
29 _supported_os Linux
30
31 # real QA test starts here
32 rm -f $seqres.full
33 _require_scratch
34 logblks=$(_scratch_find_xfs_min_logblocks -n size=16k -d size=133m)
35 _scratch_mkfs_xfs -n size=16k -l size=${logblks}b -d size=133m >> $seqres.full 2>&1
36 _scratch_mount
37
38 # First we cause very badly fragmented freespace, then
39 # make some multiblock directories in the filesystem, which
40 # should come out very fragmented as a result
41
42 # Step 1: Cause badly fragmented free space
43
44 # XXX: this needs to be factored to match what generic/204 does to support
45 # different inode sizes without ENOSPC
46 mkdir $SCRATCH_MNT/fragdir
47 for I in `seq 0 26200`; do
48         (echo data > $SCRATCH_MNT/fragdir/f$I) >> $seqres.full 2>&1
49 done
50 sync
51
52 for I in `seq 0 2 26200`; do
53         rm -f $SCRATCH_MNT/fragdir/f$I >> $seqres.full 2>&1
54 done
55 sync
56
57 # Soak up any remaining freespace
58 $XFS_IO_PROG -f -c "pwrite 0 16m" -c "fsync" $SCRATCH_MNT/space_file.large >> $seqres.full 2>&1
59
60 # Take a look at freespace for any post-mortem on the test
61 _scratch_unmount
62 _scratch_xfs_db -r -c freesp  >> $seqres.full 2>&1
63 _scratch_mount
64
65 # Step 2: Make a bunch of (hopefully fragmented) multiblock
66 # dir2 directories
67
68 # - FMT_LOCAL
69 mkdir $SCRATCH_MNT/S_IFDIR.FMT_LOCAL
70 touch $SCRATCH_MNT/S_IFDIR.FMT_LOCAL/localdirfile
71
72 # - FMT_EXTENTS
73 mkdir $SCRATCH_MNT/S_IFDIR.FMT_EXTENTS
74 for I in `seq 1 100`; do
75         touch $SCRATCH_MNT/S_IFDIR.FMT_EXTENTS/extent_dir_file_$I
76 done
77 # With a few missing
78 for I in `seq 10 2 20` 100; do
79         rm -f $SCRATCH_MNT/S_IFDIR.FMT_EXTENTS/extent_dir_file_$I
80 done
81
82 # - FMT_BTREE
83 mkdir $SCRATCH_MNT/S_IFDIR.FMT_BTREE
84 for I in `seq 1 1000`; do
85         touch $SCRATCH_MNT/S_IFDIR.FMT_BTREE/btree_dir_file_$I
86 done
87 # With a few missing
88 for I in `seq 10 2 20` 1000; do
89         rm -f $SCRATCH_MNT/S_IFDIR.FMT_BTREE/btree_dir_file_$I
90 done
91
92 # Dave's special hack - grow freespace tree
93 mkdir $SCRATCH_MNT/S_IFDIR.FMT_BTREE2
94 for I in `seq 1 5000`; do
95         touch $SCRATCH_MNT/S_IFDIR.FMT_BTREE2/btree2_dir_file_$I
96 done
97 # Remove every other (odds)
98 for I in `seq 1 2 5000`; do
99         rm -f $SCRATCH_MNT/S_IFDIR.FMT_BTREE2/btree2_dir_file_$I
100 done
101
102 _scratch_unmount
103 # Can xfs_repair and xfs_check cope with this monster?
104 _scratch_xfs_repair >> $seqres.full 2>&1 || _fail "xfs_repair failed"
105 _scratch_xfs_check >> $seqres.full 2>&1 || _fail "xfs_check failed"
106
107 # Yes they can!  Now...
108 # Can xfs_metadump cope with this monster?
109 _scratch_metadump $tmp.metadump || _fail "xfs_metadump failed"
110 xfs_mdrestore $tmp.metadump $tmp.img || _fail "xfs_mdrestore failed"
111 [ "$USE_EXTERNAL" = yes ] && [ -n "$SCRATCH_RTDEV" ] && \
112         rt_repair_opts="-r $SCRATCH_RTDEV"
113 $XFS_REPAIR_PROG $rt_repair_opts -f $tmp.img >> $seqres.full 2>&1 || \
114         _fail "xfs_repair of metadump failed"
115
116 # Yes it can; success, all done
117 status=0
118 exit
119