generic: test MADV_POPULATE_READ with IO errors
[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 . ./common/preamble
11 _begin_fstest mkfs other auto
12
13 filter_repair() {
14         _filter_repair | sed \
15                 -e '/unable to verify superblock, continuing/d' \
16                 -e '/found candidate secondary superblock/d' \
17                 -e '/error reading superblock.*-- seek to offset/d'
18 }
19
20 # dd the 1st sector then repair
21 _dd_repair_check()
22 {
23         #dd first sector
24         dd if=/dev/zero of=$1 bs=$2 count=1 2>&1 | _filter_dd
25         #xfs_repair
26         _scratch_xfs_repair 2>&1 | filter_repair
27         #check repair
28         if _check_scratch_fs; then
29                 echo "repair passed"
30         else
31                 echo "repair failed!"
32         fi
33 }
34
35 # Import common functions.
36 . ./common/filter
37 . ./common/repair
38
39 # real QA test starts here
40
41 # Modify as appropriate.
42 _supported_fs xfs
43
44 # From the PV
45 # o Summary of testing:
46 #    1. mkfs.xfs a default filesystem, note agcount value.
47 #    2. dd zero first sector and repair and verify.
48 #    3. mkfs.xfs overriding agcount to a smaller value
49 #             (ie. each AG is bigger)
50 #    4. dd zero first sector, repair and verify.
51 #          -> old mkfs.xfs will cause repair to incorrectly
52 #             fix filesystem, new mkfs.xfs will be fine.
53
54 _require_scratch
55 _scratch_mkfs_xfs | _filter_mkfs 2>$tmp.mkfs
56 test "${PIPESTATUS[0]}" -eq 0 || _fail "mkfs failed!"
57
58 # By executing the followint tmp file, will get on the mkfs options stored in
59 # variables
60 . $tmp.mkfs
61
62 # if the default agcount is too small, bump it up and re-mkfs before testing
63 if [ $agcount -lt 8 ]; then
64         agcount=8
65         _scratch_mkfs_xfs -dagcount=$agcount >/dev/null 2>&1 \
66                 || _notrun "Test requires at least 8 AGs."
67 fi
68
69 _dd_repair_check $SCRATCH_DEV $sectsz
70
71 # smaller AGCOUNT
72 let "agcount=$agcount-2"
73 _scratch_mkfs_xfs -dagcount=$agcount >/dev/null 2>&1 \
74         || _fail "mkfs failed!"
75
76 _dd_repair_check $SCRATCH_DEV $sectsz
77
78 # success, all done
79 status=0
80 exit