common/rc: Add _require_{chown,chmod}()
[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 +[AsSu] 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 -[AsSu] 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         rm -f $tmp.*
38 }
39
40 # get standard environment, filters and checks
41 . ./common/rc
42 . ./common/filter
43
44 # remove previous $seqres.full before test
45 rm -f $seqres.full
46
47 # real QA test starts here
48 _supported_fs generic
49
50 _require_command "$LSATTR_PROG" lasttr
51 _require_command "$CHATTR_PROG" chattr
52 _require_chattr AsSu
53
54 _require_scratch
55 _require_scratch_shutdown
56
57 _scratch_mkfs >/dev/null 2>&1
58 _require_metadata_journaling $SCRATCH_DEV
59
60 testfile=$SCRATCH_MNT/testfile
61
62 do_check()
63 {
64         attr=$1
65
66         _scratch_mount
67
68         touch $testfile
69
70         if [ "$2" == "sync" ]; then
71                 echo "sync" >> $seqres.full
72                 sync
73         fi
74
75         echo "Test chattr +$1" >> $seqres.full
76
77         # add attribute
78         $CHATTR_PROG +$attr $testfile
79
80         before=`$LSATTR_PROG $testfile`
81
82         $XFS_IO_PROG -f $testfile -c "fsync" | _filter_xfs_io
83
84         _scratch_shutdown | tee -a $seqres.full
85         _scratch_cycle_mount
86
87         after=`$LSATTR_PROG $testfile`
88
89         # check inode's i_flags
90         if [ "$before" != "$after" ]; then
91                 echo "Before: $before"
92                 echo "After : $after"
93         fi
94         echo "Before: $before" >> $seqres.full
95         echo "After : $after" >> $seqres.full
96
97         echo "Test chattr -$1" >> $seqres.full
98
99         # delete attribute
100         $CHATTR_PROG -$attr $testfile
101
102         before=`$LSATTR_PROG $testfile`
103
104         $XFS_IO_PROG -f $testfile -c "fsync" | _filter_xfs_io
105
106         _scratch_shutdown | tee -a $seqres.full
107         _scratch_cycle_mount
108
109         after=`$LSATTR_PROG $testfile`
110
111         # check inode's i_flags
112         if [ "$before" != "$after" ]; then
113                 echo "Before: $before"
114                 echo "After : $after"
115         fi
116         echo "Before: $before" >> $seqres.full
117         echo "After : $after" >> $seqres.full
118
119         rm -f $testfile
120         _scratch_unmount
121 }
122
123 echo "Silence is golden"
124
125 opts="A s S u"
126 for i in $opts; do
127         do_check $i
128         do_check $i sync
129 done
130
131 status=0
132 exit