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
47 _require_scratch_shutdown
48 _require_xfs_io_command "falloc" "-k"
50 _scratch_mkfs >/dev/null 2>&1
51 _require_metadata_journaling $SCRATCH_DEV
54 testfile=$SCRATCH_MNT/testfile
56 # check inode metadata after shutdown
57 check_inode_metadata()
62 if [ "$sync_mode" = "fsync" ]; then
63 stat_opt='-c "b: %b s: %s a: %x m: %y c: %z"'
65 stat_opt='-c "b: %b s: %s"'
68 before=`stat "$stat_opt" $testfile`
70 $XFS_IO_PROG -c "$sync_mode" $testfile | _filter_xfs_io
71 _scratch_shutdown | tee -a $seqres.full
74 after=`stat "$stat_opt" $testfile`
76 if [ "$before" != "$after" ]; then
77 echo "Before: $before"
80 echo "Before: $before" >> $seqres.full
81 echo "After : $after" >> $seqres.full
85 # fallocate XX KB with f{data}sync, followed by power-cut
89 echo "==== falloc $2$3 test with $1 ====" | tee -a $seqres.full
90 $XFS_IO_PROG -f -c "truncate 4202496" \
91 -c "pwrite 0 4202496" \
93 -c "falloc $2 4202496 $3"\
95 check_inode_metadata $1
98 for i in fsync fdatasync; do
99 test_falloc $i "" 1024
100 test_falloc $i "" 4096
101 test_falloc $i "" 104857600
102 test_falloc $i "-k " 1024
103 test_falloc $i "-k " 4096
104 test_falloc $i "-k " 104857600