2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2017 Huawei. All Rights Reserved.
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:
13 # 4. recovery filesystem during mount
14 # 5. check inode's metadata
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.
21 seqres=$RESULT_DIR/$seq
22 echo "QA output created by $seq"
26 status=1 # failure is the default!
27 trap "_cleanup; exit \$status" 0 1 2 3 15
35 # get standard environment, filters and checks
39 # remove previous $seqres.full before test
42 # real QA test starts here
46 _require_scratch_shutdown
47 _require_xfs_io_command "falloc" "-k"
49 _scratch_mkfs >/dev/null 2>&1
50 _require_metadata_journaling $SCRATCH_DEV
53 testfile=$SCRATCH_MNT/testfile
55 # check inode metadata after shutdown
56 check_inode_metadata()
61 if [ "$sync_mode" = "fsync" ]; then
62 stat_opt='-c "b: %b s: %s a: %x m: %y c: %z"'
64 stat_opt='-c "b: %b s: %s"'
67 before=`stat "$stat_opt" $testfile`
69 $XFS_IO_PROG -c "$sync_mode" $testfile | _filter_xfs_io
70 _scratch_shutdown | tee -a $seqres.full
73 after=`stat "$stat_opt" $testfile`
75 if [ "$before" != "$after" ]; then
76 echo "Before: $before"
79 echo "Before: $before" >> $seqres.full
80 echo "After : $after" >> $seqres.full
84 # fallocate XX KB with f{data}sync, followed by power-cut
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" \
92 -c "falloc $2 4202496 $3"\
94 check_inode_metadata $1
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