xfstests: introduce a common directory
[xfstests-dev.git] / tests / xfs / 178
1 #! /bin/bash
2 # FS QA Test No. 178
3 #
4 # Reproduce PV#:967665
5 # Test if mkfs.xfs wipes old AG headers when using -f option
6 #
7 #-----------------------------------------------------------------------
8 # Copyright (c) 2007 Silicon Graphics, Inc.  All Rights Reserved.
9 #
10 # This program is free software; you can redistribute it and/or
11 # modify it under the terms of the GNU General Public License as
12 # published by the Free Software Foundation.
13 #
14 # This program is distributed in the hope that it would be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write the Free Software Foundation,
21 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
22 #
23 #-----------------------------------------------------------------------
24 #
25
26 seq=`basename $0`
27 seqres=$RESULT_DIR/$seq
28 seqres=$RESULT_DIR/$seq
29 seqres=$RESULT_DIR/$seq
30 echo "QA output created by $seq"
31
32 here=`pwd`
33 tmp=/tmp/$$
34 status=1        # failure is the default!
35 trap "_cleanup; exit \$status" 0 1 2 3 15
36
37 _cleanup()
38 {
39     cd /
40     rm -f $tmp.*
41 }
42 # dd the 1st sector then repair
43 _dd_repair_check()
44 {
45         #dd first sector
46         dd if=/dev/zero of=$1 bs=$2 count=1 2>&1 | _filter_dd
47         #xfs_repair
48         _scratch_xfs_repair 2>&1 | _filter_repair
49         #check repair
50         if _check_scratch_fs; then
51                 echo "repair passed"
52         else
53                 echo "repair failed!"
54         fi
55 }
56
57 # get standard environment, filters and checks
58 . ./common/rc
59 . ./common/filter
60 . ./common/repair
61
62 # real QA test starts here
63
64 # Modify as appropriate.
65 _supported_fs xfs
66 _supported_os Linux
67
68 # From the PV
69 # o Summary of testing:
70 #    1. mkfs.xfs a default filesystem, note agcount value.
71 #    2. dd zero first sector and repair and verify.
72 #    3. mkfs.xfs overriding agcount to a smaller value
73 #             (ie. each AG is bigger)
74 #    4. dd zero first sector, repair and verify.
75 #          -> old mkfs.xfs will cause repair to incorrectly
76 #             fix filesystem, new mkfs.xfs will be fine.
77
78 _require_scratch
79 _scratch_mkfs_xfs | _filter_mkfs 2>$tmp.mkfs \
80         || _fail "mkfs failed!"
81
82 # By executing the followint tmp file, will get on the mkfs options stored in
83 # variables
84 . $tmp.mkfs
85
86 # if the default agcount is too small, bump it up and re-mkfs before testing
87 if [ $agcount -lt 8 ]; then
88         agcount=8
89         _scratch_mkfs_xfs -dagcount=$agcount >/dev/null 2>&1 \
90                 || _notrun "Test requires at least 8 AGs."
91 fi
92
93 _dd_repair_check $SCRATCH_DEV $sectsz
94
95 # smaller AGCOUNT
96 let "agcount=$agcount-2"
97 _scratch_mkfs_xfs -dagcount=$agcount >/dev/null 2>&1 \
98         || _fail "mkfs failed!"
99
100 _dd_repair_check $SCRATCH_DEV $sectsz
101
102 # success, all done
103 status=0
104 exit