common/rc: add _scratch_{u}mount_idmapped() helpers
[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
34 rm -f $seqres.full
35 _require_scratch
36 _require_scratch_shutdown
37 _require_xfs_io_command "fpunch"
38
39 _scratch_mkfs >/dev/null 2>&1
40 _require_metadata_journaling $SCRATCH_DEV
41 _scratch_mount
42
43 testfile=$SCRATCH_MNT/testfile
44
45 # check inode metadata after shutdown
46 check_inode_metadata()
47 {
48         sync_mode=$1
49
50         # fsync or fdatasync
51         if [ $sync_mode = "fsync" ]; then
52                 stat_opt='-c "b: %b s: %s a: %x m: %y c: %z"'
53         else
54                 stat_opt='-c "b: %b s: %s"'
55         fi
56
57         before=`stat "$stat_opt" $testfile`
58
59         $XFS_IO_PROG -c "$sync_mode" $testfile | _filter_xfs_io
60         _scratch_shutdown | tee -a $seqres.full
61         _scratch_cycle_mount
62
63         after=`stat "$stat_opt" $testfile`
64
65         if [ "$before" != "$after" ]; then
66                 echo "Before: $before"
67                 echo "After : $after"
68                 status=1;       # this is a failure!
69         fi
70         echo "Before: $before" >> $seqres.full
71         echo "After : $after" >> $seqres.full
72         rm $testfile
73 }
74
75 # append XX KB with f{data}sync, followed by power-cut
76 test_i_size()
77 {
78         echo "==== i_size $2 test with $1 ====" | tee -a $seqres.full
79         $XFS_IO_PROG -f -c "truncate 4M"        \
80                         -c "pwrite 0 4M"        \
81                         -c "fsync"              \
82                         -c "pwrite 4M $2"       \
83                         $testfile >/dev/null
84         check_inode_metadata $1
85 }
86
87 # update times with f{data}sync, followed by power-cut
88 test_i_time()
89 {
90         echo "==== i_time test with $1 ====" | tee -a $seqres.full
91         $XFS_IO_PROG -f -c "truncate 4M"        \
92                         -c "pwrite 0 4M"        \
93                         -c "fsync"              \
94                         $testfile >/dev/null
95         sleep 1
96         touch $testfile
97         check_inode_metadata $1
98 }
99
100 # punch XX KB with f{data}sync, followed by power-cut
101 test_punch()
102 {
103         echo "==== fpunch $2 test with $1 ====" | tee -a $seqres.full
104         $XFS_IO_PROG -f -c "truncate 4202496"   \
105                         -c "pwrite 0 4202496"   \
106                         -c "fsync"              \
107                         -c "fpunch 4194304 $2"\
108                         $testfile >/dev/null
109         check_inode_metadata $1
110 }
111
112 for i in fsync fdatasync; do
113         test_i_size $i 1024
114         test_i_size $i 4096
115         test_i_time $i
116         test_punch $i 1024
117         test_punch $i 4096
118 done
119
120 exit