misc: move exit status into trap handler
[xfstests-dev.git] / tests / generic / 507
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2018 Huawei.  All Rights Reserved.
4 #
5 # FS QA Test 507
6 #
7 # This testcase is trying to test recovery flow of generic filesystem, w/ below
8 # steps, once i_flags changes, after we fsync that file, we can expect that
9 # i_flags can be recovered after sudden power-cuts.
10 # 1. touch testfile;
11 # 1.1 sync (optional)
12 # 2. chattr +[ASai] testfile
13 # 3. xfs_io -f testfile -c "fsync";
14 # 4. godown;
15 # 5. umount;
16 # 6. mount;
17 # 7. check i_flags
18 # 8. chattr -[ASai] testfile
19 # 9. xfs_io -f testfile -c "fsync";
20 # 10. godown;
21 # 11. umount;
22 # 12. mount;
23 # 13. check i_flags
24 #
25 seq=`basename $0`
26 seqres=$RESULT_DIR/$seq
27 echo "QA output created by $seq"
28
29 here=`pwd`
30 tmp=/tmp/$$
31 status=1        # failure is the default!
32 trap "_cleanup; exit \$status" 0 1 2 3 15
33
34 _cleanup()
35 {
36         cd /
37         $CHATTR_PROG -ai $testfile &> /dev/null
38         rm -f $tmp.*
39 }
40
41 # get standard environment, filters and checks
42 . ./common/rc
43 . ./common/filter
44
45 # remove previous $seqres.full before test
46 rm -f $seqres.full
47
48 # real QA test starts here
49 _supported_fs generic
50
51 _require_command "$LSATTR_PROG" lasttr
52 _require_command "$CHATTR_PROG" chattr
53 _require_chattr ASai
54
55 _require_scratch
56 _require_scratch_shutdown
57
58 _scratch_mkfs >/dev/null 2>&1
59 _require_metadata_journaling $SCRATCH_DEV
60
61 testfile=$SCRATCH_MNT/testfile
62
63 do_check()
64 {
65         attr=$1
66
67         _scratch_mount
68
69         touch $testfile
70
71         if [ "$2" == "sync" ]; then
72                 echo "sync" >> $seqres.full
73                 sync
74         fi
75
76         echo "Test chattr +$1" >> $seqres.full
77
78         # add attribute
79         $CHATTR_PROG +$attr $testfile
80
81         before=`$LSATTR_PROG $testfile`
82
83         $XFS_IO_PROG -r -f $testfile -c "fsync" | _filter_xfs_io
84
85         _scratch_shutdown | tee -a $seqres.full
86         _scratch_cycle_mount
87
88         after=`$LSATTR_PROG $testfile`
89
90         # check inode's i_flags
91         if [ "$before" != "$after" ]; then
92                 echo "Before: $before"
93                 echo "After : $after"
94         fi
95         echo "Before: $before" >> $seqres.full
96         echo "After : $after" >> $seqres.full
97
98         echo "Test chattr -$1" >> $seqres.full
99
100         # delete attribute
101         $CHATTR_PROG -$attr $testfile
102
103         before=`$LSATTR_PROG $testfile`
104
105         $XFS_IO_PROG -r -f $testfile -c "fsync" | _filter_xfs_io
106
107         _scratch_shutdown | tee -a $seqres.full
108         _scratch_cycle_mount
109
110         after=`$LSATTR_PROG $testfile`
111
112         # check inode's i_flags
113         if [ "$before" != "$after" ]; then
114                 echo "Before: $before"
115                 echo "After : $after"
116         fi
117         echo "Before: $before" >> $seqres.full
118         echo "After : $after" >> $seqres.full
119
120         rm -f $testfile
121         _scratch_unmount
122 }
123
124 echo "Silence is golden"
125
126 opts="A S a i"
127 for i in $opts; do
128         do_check $i
129         do_check $i sync
130 done
131
132 status=0
133 exit