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