xfs: force file creation to the data device for certain layout tests
[xfstests-dev.git] / tests / generic / 468
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2017 Huawei.  All Rights Reserved.
4 #
5 # FS QA Test 468
6 #
7 # This testcase is a fallocate variant of generic/392, it expands to test
8 # block preallocation functionality of fallocate.
9 # In this case, we are trying to execute:
10 # 1. fallocate {,-k}
11 # 2. f{data,}sync
12 # 3. power-cuts
13 # 4. recovery filesystem during mount
14 # 5. check inode's metadata
15 #
16 # In the case of fsync, filesystem should recover all the inode metadata, while
17 # recovering i_blocks and i_size at least for fdatasync, so this testcase excepts
18 # that inode metadata will be unchanged after recovery.
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 _require_xfs_io_command "falloc" "-k"
48
49 _scratch_mkfs >/dev/null 2>&1
50 _require_metadata_journaling $SCRATCH_DEV
51 _scratch_mount
52
53 testfile=$SCRATCH_MNT/testfile
54
55 # check inode metadata after shutdown
56 check_inode_metadata()
57 {
58         sync_mode=$1
59
60         # fsync or fdatasync
61         if [ "$sync_mode" = "fsync" ]; then
62                 stat_opt='-c "b: %b s: %s a: %x m: %y c: %z"'
63         else
64                 stat_opt='-c "b: %b s: %s"'
65         fi
66
67         before=`stat "$stat_opt" $testfile`
68
69         $XFS_IO_PROG -c "$sync_mode" $testfile | _filter_xfs_io
70         _scratch_shutdown | tee -a $seqres.full
71         _scratch_cycle_mount
72
73         after=`stat "$stat_opt" $testfile`
74
75         if [ "$before" != "$after" ]; then
76                 echo "Before: $before"
77                 echo "After : $after"
78         fi
79         echo "Before: $before" >> $seqres.full
80         echo "After : $after" >> $seqres.full
81         rm $testfile
82 }
83
84 # fallocate XX KB with f{data}sync, followed by power-cut
85 test_falloc()
86 {
87         # 4202496 = 4m + 8k
88         echo "==== falloc $2$3 test with $1 ====" | tee -a $seqres.full
89         $XFS_IO_PROG -f -c "truncate 4202496"   \
90                         -c "pwrite 0 4202496"   \
91                         -c "fsync"              \
92                         -c "falloc $2 4202496 $3"\
93                         $testfile >/dev/null
94         check_inode_metadata $1
95 }
96
97 for i in fsync fdatasync; do
98         test_falloc $i "" 1024
99         test_falloc $i "" 4096
100         test_falloc $i "" 104857600
101         test_falloc $i "-k " 1024
102         test_falloc $i "-k " 4096
103         test_falloc $i "-k " 104857600
104 done
105
106 status=0
107 exit