xfs: fix old fuzz test invocations of xfs_repair
[xfstests-dev.git] / tests / xfs / 158
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0-or-later
3 # Copyright (c) 2021 Oracle.  All Rights Reserved.
4 #
5 # FS QA Test No. 158
6 #
7 # Check that we can upgrade a filesystem to support inobtcount and that
8 # everything works properly after the upgrade.
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
25 # get standard environment, filters and checks
26 . ./common/rc
27 . ./common/filter
28
29 # real QA test starts here
30 _supported_fs xfs
31 _require_scratch_xfs_inobtcount
32 _require_command "$XFS_ADMIN_PROG" "xfs_admin"
33 _require_xfs_repair_upgrade inobtcount
34
35 rm -f $seqres.full
36
37 # Make sure we can't format a filesystem with inobtcount and not finobt.
38 _scratch_mkfs -m crc=1,inobtcount=1,finobt=0 &> $seqres.full && \
39         echo "Should not be able to format with inobtcount but not finobt."
40
41 # Make sure we can't upgrade a V4 filesystem
42 _scratch_mkfs -m crc=0,inobtcount=0,finobt=0 >> $seqres.full
43 _scratch_xfs_admin -O inobtcount=1 2>> $seqres.full
44 _check_scratch_xfs_features INOBTCNT
45
46 # Make sure we can't upgrade a filesystem to inobtcount without finobt.
47 _scratch_mkfs -m crc=1,inobtcount=0,finobt=0 >> $seqres.full
48 _scratch_xfs_admin -O inobtcount=1 2>> $seqres.full
49 _check_scratch_xfs_features INOBTCNT
50
51 # Format V5 filesystem without inode btree counter support and populate it.
52 _scratch_mkfs -m crc=1,inobtcount=0 >> $seqres.full
53 _scratch_mount
54
55 mkdir $SCRATCH_MNT/stress
56 $FSSTRESS_PROG -d $SCRATCH_MNT/stress -n 1000 >> $seqres.full
57 echo moo > $SCRATCH_MNT/urk
58
59 _scratch_unmount
60
61 # Upgrade filesystem to have the counters and inject failure into repair and
62 # make sure that the only path forward is to re-run repair on the filesystem.
63 echo "Fail partway through upgrading"
64 XFS_REPAIR_FAIL_AFTER_PHASE=2 _scratch_xfs_repair -c inobtcount=1 2>> $seqres.full
65 test $? -eq 137 || echo "repair should have been killed??"
66 _check_scratch_xfs_features NEEDSREPAIR INOBTCNT
67 _try_scratch_mount &> $tmp.mount
68 res=$?
69 _filter_scratch < $tmp.mount
70 if [ $res -eq 0 ]; then
71         echo "needsrepair should have prevented mount"
72         _scratch_unmount
73 fi
74
75 echo "Re-run repair to finish upgrade"
76 _scratch_xfs_repair 2>> $seqres.full
77 _check_scratch_xfs_features NEEDSREPAIR INOBTCNT
78
79 echo "Filesystem should be usable again"
80 _scratch_mount
81 $FSSTRESS_PROG -d $SCRATCH_MNT/stress -n 1000 >> $seqres.full
82 _scratch_unmount
83 _check_scratch_fs
84 _check_scratch_xfs_features INOBTCNT
85
86 echo "Make sure we have nonzero counters"
87 _scratch_xfs_db -c 'agi 0' -c 'print ino_blocks fino_blocks' | \
88         sed -e 's/= 0$/= ZERO/g' -e 's/= [0-9]*/= NONZERO/g'
89
90 echo "Make sure we can't re-add inobtcount"
91 _scratch_xfs_admin -O inobtcount=1 2>> $seqres.full
92
93 echo "Mount again, look at our files"
94 _scratch_mount >> $seqres.full
95 cat $SCRATCH_MNT/urk
96
97 status=0
98 exit