764f09be21a8996bef6a41c2e08cdcdd0908b3af
[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 # creator
24 owner=sandeen@sandeen.net
25
26 seq=`basename $0`
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
44 _supported_fs xfs
45 _supported_os IRIX Linux
46
47 # real QA test starts here
48 rm -f $seq.full
49 _require_scratch
50 _scratch_mkfs_xfs -n size=16k -d size=128m >> $seq.full 2>&1
51 _scratch_mount
52
53 # First we cause very badly fragmented freespace, then
54 # make some multiblock directories in the filesystem, which
55 # should come out very fragmented as a result
56
57 # Step 1: Cause badly fragmented free space
58 mkdir $SCRATCH_MNT/fragdir
59 for I in `seq 0 27200`; do
60         (echo data > $SCRATCH_MNT/fragdir/f$I) >> $seq.full 2>&1
61 done
62 sync
63
64 for I in `seq 0 2 27200`; do
65         rm -f $SCRATCH_MNT/fragdir/f$I >> $seq.full 2>&1
66 done
67 sync
68
69 # Soak up any remaining freespace
70 xfs_io -f -c "pwrite 0 16m" -c "fsync" $SCRATCH_MNT/space_file.large >> $seq.full 2>&1
71
72 # Take a look at freespace for any post-mortem on the test
73 _scratch_unmount
74 xfs_db -c freesp $SCRATCH_DEV >> $seq.full 2>&1
75 _scratch_mount
76
77 # Step 2: Make a bunch of (hopefully fragmented) multiblock
78 # dir2 directories
79
80 # - FMT_LOCAL
81 mkdir $SCRATCH_MNT/S_IFDIR.FMT_LOCAL
82 touch $SCRATCH_MNT/S_IFDIR.FMT_LOCAL/localdirfile
83
84 # - FMT_EXTENTS
85 mkdir $SCRATCH_MNT/S_IFDIR.FMT_EXTENTS
86 for I in `seq 1 100`; do
87         touch $SCRATCH_MNT/S_IFDIR.FMT_EXTENTS/extent_dir_file_$I
88 done
89 # With a few missing
90 for I in `seq 10 2 20` 100; do
91         rm -f $SCRATCH_MNT/S_IFDIR.FMT_EXTENTS/extent_dir_file_$I
92 done
93
94 # - FMT_BTREE
95 mkdir $SCRATCH_MNT/S_IFDIR.FMT_BTREE
96 for I in `seq 1 1000`; do
97         touch $SCRATCH_MNT/S_IFDIR.FMT_BTREE/btree_dir_file_$I
98 done
99 # With a few missing
100 for I in `seq 10 2 20` 1000; do
101         rm -f $SCRATCH_MNT/S_IFDIR.FMT_BTREE/btree_dir_file_$I
102 done
103
104 # Dave's special hack - grow freespace tree
105 mkdir $SCRATCH_MNT/S_IFDIR.FMT_BTREE2
106 for I in `seq 1 5000`; do
107         touch $SCRATCH_MNT/S_IFDIR.FMT_BTREE2/btree2_dir_file_$I
108 done
109 # Remove every other (odds)
110 for I in `seq 1 2 5000`; do
111         rm -f $SCRATCH_MNT/S_IFDIR.FMT_BTREE2/btree2_dir_file_$I
112 done
113
114 _scratch_unmount
115 # Can xfs_repair and xfs_check cope with this monster?
116 _scratch_xfs_repair >> $seq.full 2>&1 || _fail "xfs_repair failed"
117 xfs_check $SCRATCH_DEV >> $seq.full 2>&1 || _fail "xfs_check failed"
118
119 # Yes they can!  Now...
120 # Can xfs_metadump cope with this monster?
121 xfs_metadump $SCRATCH_DEV $tmp.metadump || _fail "xfs_metadump failed"
122 xfs_mdrestore $tmp.metadump $tmp.img || _fail "xfs_mdrestore failed"
123 xfs_repair $tmp.img >> $seq.full 2>&1 || _fail "xfs_repair of metadump failed"
124
125 # Yes it can; success, all done
126 status=0
127 exit
128