fstests: use _require_symlinks on all necessary tests
[xfstests-dev.git] / tests / generic / 392
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2016 Jaegeuk Kim.  All Rights Reserved.
4 #
5 # FS QA Test 392
6 #
7 # Test inode's metadata after fsync or fdatasync calls.
8 # In the case of fsync, filesystem should recover all the inode metadata, while
9 # recovering i_blocks and i_size at least for fdatasync.
10 #
11 seq=`basename $0`
12 seqres=$RESULT_DIR/$seq
13 echo "QA output created by $seq"
14
15 here=`pwd`
16 tmp=/tmp/$$
17 status=0        # failure will be detected in runtime!
18 trap "_cleanup; exit \$status" 0 1 2 3 15
19
20 _cleanup()
21 {
22         cd /
23         rm -f $tmp.*
24 }
25
26 # get standard environment, filters and checks
27 . ./common/rc
28 . ./common/filter
29 . ./common/punch
30
31 # real QA test starts here
32 _supported_fs generic
33 _supported_os Linux
34
35 rm -f $seqres.full
36 _require_scratch
37 _require_scratch_shutdown
38 _require_xfs_io_command "fpunch"
39
40 _scratch_mkfs >/dev/null 2>&1
41 _require_metadata_journaling $SCRATCH_DEV
42 _scratch_mount
43
44 testfile=$SCRATCH_MNT/testfile
45
46 # check inode metadata after shutdown
47 check_inode_metadata()
48 {
49         sync_mode=$1
50
51         # fsync or fdatasync
52         if [ $sync_mode = "fsync" ]; then
53                 stat_opt='-c "b: %b s: %s a: %x m: %y c: %z"'
54         else
55                 stat_opt='-c "b: %b s: %s"'
56         fi
57
58         before=`stat "$stat_opt" $testfile`
59
60         $XFS_IO_PROG -c "$sync_mode" $testfile | _filter_xfs_io
61         _scratch_shutdown | tee -a $seqres.full
62         _scratch_cycle_mount
63
64         after=`stat "$stat_opt" $testfile`
65
66         if [ "$before" != "$after" ]; then
67                 echo "Before: $before"
68                 echo "After : $after"
69                 status=1;       # this is a failure!
70         fi
71         echo "Before: $before" >> $seqres.full
72         echo "After : $after" >> $seqres.full
73         rm $testfile
74 }
75
76 # append XX KB with f{data}sync, followed by power-cut
77 test_i_size()
78 {
79         echo "==== i_size $2 test with $1 ====" | tee -a $seqres.full
80         $XFS_IO_PROG -f -c "truncate 4M"        \
81                         -c "pwrite 0 4M"        \
82                         -c "fsync"              \
83                         -c "pwrite 4M $2"       \
84                         $testfile >/dev/null
85         check_inode_metadata $1
86 }
87
88 # update times with f{data}sync, followed by power-cut
89 test_i_time()
90 {
91         echo "==== i_time test with $1 ====" | tee -a $seqres.full
92         $XFS_IO_PROG -f -c "truncate 4M"        \
93                         -c "pwrite 0 4M"        \
94                         -c "fsync"              \
95                         $testfile >/dev/null
96         sleep 1
97         touch $testfile
98         check_inode_metadata $1
99 }
100
101 # punch XX KB with f{data}sync, followed by power-cut
102 test_punch()
103 {
104         echo "==== fpunch $2 test with $1 ====" | tee -a $seqres.full
105         $XFS_IO_PROG -f -c "truncate 4202496"   \
106                         -c "pwrite 0 4202496"   \
107                         -c "fsync"              \
108                         -c "fpunch 4194304 $2"\
109                         $testfile >/dev/null
110         check_inode_metadata $1
111 }
112
113 for i in fsync fdatasync; do
114         test_i_size $i 1024
115         test_i_size $i 4096
116         test_i_time $i
117         test_punch $i 1024
118         test_punch $i 4096
119 done
120
121 exit