blob: 95752d3bfc9247ba004794a1bb84749adc396a89 [file] [log] [blame]
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (c) 2017 Huawei. All Rights Reserved.
#
# FS QA Test 468
#
# This testcase is a fallocate variant of generic/392, it expands to test
# block preallocation functionality of fallocate.
# In this case, we are trying to execute:
# 1. fallocate {,-k}
# 2. f{data,}sync
# 3. power-cuts
# 4. recovery filesystem during mount
# 5. check inode's metadata
#
# In the case of fsync, filesystem should recover all the inode metadata, while
# recovering i_blocks and i_size at least for fdatasync, so this testcase excepts
# that inode metadata will be unchanged after recovery.
#
. ./common/preamble
_begin_fstest shutdown auto quick metadata
# Import common functions.
. ./common/filter
# real QA test starts here
_supported_fs generic
_require_scratch
_require_scratch_shutdown
_require_xfs_io_command "falloc" "-k"
_scratch_mkfs >/dev/null 2>&1
_require_metadata_journaling $SCRATCH_DEV
_scratch_mount
testfile=$SCRATCH_MNT/testfile
# check inode metadata after shutdown
check_inode_metadata()
{
sync_mode=$1
# fsync or fdatasync
if [ "$sync_mode" = "fsync" ]; then
stat_opt='-c "b: %b s: %s a: %x m: %y c: %z"'
else
stat_opt='-c "b: %b s: %s"'
fi
before=`stat "$stat_opt" $testfile`
$XFS_IO_PROG -c "$sync_mode" $testfile | _filter_xfs_io
_scratch_shutdown | tee -a $seqres.full
_scratch_cycle_mount
after=`stat "$stat_opt" $testfile`
if [ "$before" != "$after" ]; then
echo "Before: $before"
echo "After : $after"
fi
echo "Before: $before" >> $seqres.full
echo "After : $after" >> $seqres.full
rm $testfile
}
# fallocate XX KB with f{data}sync, followed by power-cut
test_falloc()
{
# 4202496 = 4m + 8k
echo "==== falloc $2$3 test with $1 ====" | tee -a $seqres.full
$XFS_IO_PROG -f -c "truncate 4202496" \
-c "pwrite 0 4202496" \
-c "fsync" \
-c "falloc $2 4202496 $3"\
$testfile >/dev/null
check_inode_metadata $1
}
for i in fsync fdatasync; do
test_falloc $i "" 1024
test_falloc $i "" 4096
test_falloc $i "" 104857600
test_falloc $i "-k " 1024
test_falloc $i "-k " 4096
test_falloc $i "-k " 104857600
done
status=0
exit