a24ef50ce287600110f42ac1b1c0fe1b5f288dec
[xfstests-dev.git] / tests / xfs / 178
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2007 Silicon Graphics, Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. 178
6 #
7 # Reproduce PV#:967665
8 # Test if mkfs.xfs wipes old AG headers when using -f option
9 #
10 seq=`basename $0`
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
13
14 here=`pwd`
15 tmp=/tmp/$$
16 status=1        # failure is the default!
17 trap "_cleanup; exit \$status" 0 1 2 3 15
18
19 _cleanup()
20 {
21     cd /
22     rm -f $tmp.*
23 }
24 # dd the 1st sector then repair
25 _dd_repair_check()
26 {
27         #dd first sector
28         dd if=/dev/zero of=$1 bs=$2 count=1 2>&1 | _filter_dd
29         #xfs_repair
30         _scratch_xfs_repair 2>&1 | _filter_repair
31         #check repair
32         if _check_scratch_fs; then
33                 echo "repair passed"
34         else
35                 echo "repair failed!"
36         fi
37 }
38
39 # get standard environment, filters and checks
40 . ./common/rc
41 . ./common/filter
42 . ./common/repair
43
44 # real QA test starts here
45
46 # Modify as appropriate.
47 _supported_fs xfs
48
49 # From the PV
50 # o Summary of testing:
51 #    1. mkfs.xfs a default filesystem, note agcount value.
52 #    2. dd zero first sector and repair and verify.
53 #    3. mkfs.xfs overriding agcount to a smaller value
54 #             (ie. each AG is bigger)
55 #    4. dd zero first sector, repair and verify.
56 #          -> old mkfs.xfs will cause repair to incorrectly
57 #             fix filesystem, new mkfs.xfs will be fine.
58
59 _require_scratch
60 _scratch_mkfs_xfs | _filter_mkfs 2>$tmp.mkfs \
61         || _fail "mkfs failed!"
62
63 # By executing the followint tmp file, will get on the mkfs options stored in
64 # variables
65 . $tmp.mkfs
66
67 # if the default agcount is too small, bump it up and re-mkfs before testing
68 if [ $agcount -lt 8 ]; then
69         agcount=8
70         _scratch_mkfs_xfs -dagcount=$agcount >/dev/null 2>&1 \
71                 || _notrun "Test requires at least 8 AGs."
72 fi
73
74 _dd_repair_check $SCRATCH_DEV $sectsz
75
76 # smaller AGCOUNT
77 let "agcount=$agcount-2"
78 _scratch_mkfs_xfs -dagcount=$agcount >/dev/null 2>&1 \
79         || _fail "mkfs failed!"
80
81 _dd_repair_check $SCRATCH_DEV $sectsz
82
83 # success, all done
84 status=0
85 exit