xfstests: include test subdirectory support
[xfstests-dev.git] / 291
1 #! /bin/bash
2 # FS QA Test No. 291
3 #
4 # Test xfs_repair on fragmented multi-block dir2 fs
5 #
6 #-----------------------------------------------------------------------
7 # Copyright (c) Red Hat, Inc.  All Rights Reserved.
8 #
9 # This program is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU General Public License as
11 # published by the Free Software Foundation.
12 #
13 # This program is distributed in the hope that it would be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write the Free Software Foundation,
20 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21 #-----------------------------------------------------------------------
22 #
23
24 seq=`basename $0`
25 echo "QA output created by $seq"
26
27 here=`pwd`
28 tmp=/tmp/$$
29 status=1        # failure is the default!
30 trap "_cleanup; exit \$status" 0 1 2 3 15
31
32 _cleanup()
33 {
34     cd /
35     rm -f $tmp.*
36 }
37
38 # get standard environment, filters and checks
39 . ./common.rc
40 . ./common.filter
41
42 _supported_fs xfs
43 _supported_os IRIX Linux
44
45 # real QA test starts here
46 rm -f $seq.full
47 _require_scratch
48 _scratch_mkfs_xfs -n size=16k -d size=128m >> $seq.full 2>&1
49 _scratch_mount
50
51 # First we cause very badly fragmented freespace, then
52 # make some multiblock directories in the filesystem, which
53 # should come out very fragmented as a result
54
55 # Step 1: Cause badly fragmented free space
56 mkdir $SCRATCH_MNT/fragdir
57 for I in `seq 0 27200`; do
58         (echo data > $SCRATCH_MNT/fragdir/f$I) >> $seq.full 2>&1
59 done
60 sync
61
62 for I in `seq 0 2 27200`; do
63         rm -f $SCRATCH_MNT/fragdir/f$I >> $seq.full 2>&1
64 done
65 sync
66
67 # Soak up any remaining freespace
68 xfs_io -f -c "pwrite 0 16m" -c "fsync" $SCRATCH_MNT/space_file.large >> $seq.full 2>&1
69
70 # Take a look at freespace for any post-mortem on the test
71 _scratch_unmount
72 xfs_db -c freesp $SCRATCH_DEV >> $seq.full 2>&1
73 _scratch_mount
74
75 # Step 2: Make a bunch of (hopefully fragmented) multiblock
76 # dir2 directories
77
78 # - FMT_LOCAL
79 mkdir $SCRATCH_MNT/S_IFDIR.FMT_LOCAL
80 touch $SCRATCH_MNT/S_IFDIR.FMT_LOCAL/localdirfile
81
82 # - FMT_EXTENTS
83 mkdir $SCRATCH_MNT/S_IFDIR.FMT_EXTENTS
84 for I in `seq 1 100`; do
85         touch $SCRATCH_MNT/S_IFDIR.FMT_EXTENTS/extent_dir_file_$I
86 done
87 # With a few missing
88 for I in `seq 10 2 20` 100; do
89         rm -f $SCRATCH_MNT/S_IFDIR.FMT_EXTENTS/extent_dir_file_$I
90 done
91
92 # - FMT_BTREE
93 mkdir $SCRATCH_MNT/S_IFDIR.FMT_BTREE
94 for I in `seq 1 1000`; do
95         touch $SCRATCH_MNT/S_IFDIR.FMT_BTREE/btree_dir_file_$I
96 done
97 # With a few missing
98 for I in `seq 10 2 20` 1000; do
99         rm -f $SCRATCH_MNT/S_IFDIR.FMT_BTREE/btree_dir_file_$I
100 done
101
102 # Dave's special hack - grow freespace tree
103 mkdir $SCRATCH_MNT/S_IFDIR.FMT_BTREE2
104 for I in `seq 1 5000`; do
105         touch $SCRATCH_MNT/S_IFDIR.FMT_BTREE2/btree2_dir_file_$I
106 done
107 # Remove every other (odds)
108 for I in `seq 1 2 5000`; do
109         rm -f $SCRATCH_MNT/S_IFDIR.FMT_BTREE2/btree2_dir_file_$I
110 done
111
112 _scratch_unmount
113 # Can xfs_repair and xfs_check cope with this monster?
114 _scratch_xfs_repair >> $seq.full 2>&1 || _fail "xfs_repair failed"
115 xfs_check $SCRATCH_DEV >> $seq.full 2>&1 || _fail "xfs_check failed"
116
117 # Yes they can!  Now...
118 # Can xfs_metadump cope with this monster?
119 xfs_metadump $SCRATCH_DEV $tmp.metadump || _fail "xfs_metadump failed"
120 xfs_mdrestore $tmp.metadump $tmp.img || _fail "xfs_mdrestore failed"
121 xfs_repair $tmp.img >> $seq.full 2>&1 || _fail "xfs_repair of metadump failed"
122
123 # Yes it can; success, all done
124 status=0
125 exit
126