common/rc: Add _require_{chown,chmod}()
[xfstests-dev.git] / tests / generic / 505
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2018 Huawei.  All Rights Reserved.
4 #
5 # FS QA Test 505
6 #
7 # This testcase is trying to test recovery flow of generic filesystem, w/ below
8 # steps, once uid or gid changes, after we fsync that file, we can expect that
9 # uid/gid can be recovered after sudden power-cuts.
10 # 1. touch testfile;
11 # 1.1 sync (optional)
12 # 2. chown 100 testfile;
13 # 3. chgrp 100 testfile;
14 # 4. xfs_io -f testfile -c "fsync";
15 # 5. godown;
16 # 6. umount;
17 # 7. mount;
18 # 8. check uid/gid
19 #
20 seq=`basename $0`
21 seqres=$RESULT_DIR/$seq
22 echo "QA output created by $seq"
23
24 here=`pwd`
25 tmp=/tmp/$$
26 status=1        # failure is the default!
27 trap "_cleanup; exit \$status" 0 1 2 3 15
28
29 _cleanup()
30 {
31         cd /
32         rm -f $tmp.*
33 }
34
35 # get standard environment, filters and checks
36 . ./common/rc
37 . ./common/filter
38
39 # remove previous $seqres.full before test
40 rm -f $seqres.full
41
42 # real QA test starts here
43 _supported_fs generic
44
45 _require_scratch
46 _require_scratch_shutdown
47
48 _scratch_mkfs >/dev/null 2>&1
49 _require_metadata_journaling $SCRATCH_DEV
50
51 testfile=$SCRATCH_MNT/testfile
52 stat_opt='-c "uid: %u, gid: %g"'
53
54 do_check()
55 {
56         _scratch_mount
57
58         touch $testfile
59
60         if [ "$1" == "sync" ]; then
61                 sync
62         fi
63
64         chown 100 $testfile
65         chgrp 100 $testfile
66
67         before=`stat "$stat_opt" $testfile`
68
69         $XFS_IO_PROG -f $testfile -c "fsync" | _filter_xfs_io
70
71         _scratch_shutdown | tee -a $seqres.full
72         _scratch_cycle_mount
73
74         after=`stat "$stat_opt" $testfile`
75
76         # check inode's uid/gid
77         if [ "$before" != "$after" ]; then
78                 echo "Before: $before"
79                 echo "After : $after"
80         fi
81         echo "Before: $before" >> $seqres.full
82         echo "After : $after" >> $seqres.full
83
84         rm $testfile
85         _scratch_unmount
86 }
87
88 echo "Silence is golden"
89 do_check
90 do_check sync
91
92 status=0
93 exit