misc: move exit status into trap handler
[xfstests-dev.git] / tests / xfs / 493
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2018 Oracle.  All Rights Reserved.
4 #
5 # FS QA Test No. 493
6 #
7 # Test detection & fixing of bad summary block counts at mount time.
8 # Corrupt the AGFs to test mount failure when mount-fixing fails.
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 # remove previous $seqres.full before test
30 rm -f $seqres.full
31
32 # real QA test starts here
33
34 # Modify as appropriate.
35 _supported_fs xfs
36 _require_scratch_nocheck
37
38 echo "Format and mount"
39 _scratch_mkfs > $seqres.full 2>&1
40 _scratch_mount >> $seqres.full 2>&1
41 echo "test file" > $SCRATCH_MNT/testfile
42
43 echo "Fuzz fdblocks and btreeblks"
44 _scratch_unmount
45 dblocks=$(_scratch_xfs_get_metadata_field dblocks 'sb 0')
46 _scratch_xfs_set_metadata_field fdblocks $((dblocks * 2)) 'sb 0' > $seqres.full 2>&1
47
48 aglen=$(_scratch_xfs_get_metadata_field length 'agf 0')
49 _scratch_xfs_set_metadata_field btreeblks $aglen 'agf 0' > $seqres.full 2>&1
50
51 echo "Detection and Correction"
52 if _try_scratch_mount >> $seqres.full 2>&1; then
53         echo "mount should have failed"
54         avail=$(stat -c '%a' -f $SCRATCH_MNT)
55         total=$(stat -c '%b' -f $SCRATCH_MNT)
56         echo "avail: $avail" >> $seqres.full
57         echo "total: $total" >> $seqres.full
58         test "$avail" -gt "$total" && echo "free space bad: $avail > $total"
59         _scratch_unmount
60 fi
61 _scratch_xfs_repair -n >> $seqres.full 2>&1 && echo "repair didn't find fuzz?"
62
63 # success, all done
64 status=0
65 exit