summaryrefslogtreecommitdiff
path: root/tests/generic/568
blob: a3c0b4aed178f20db8eca7ccd715cf6893354c26 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (c) 2019 Red Hat, Inc.  All Rights Reserved.
#
# FS QA Test No. generic/568
#
# Test that fallocating an unaligned range allocates all blocks
# touched by that range
#
seq=$(basename $0)
seqres="$RESULT_DIR/$seq"
echo "QA output created by $seq"

here=$PWD
tmp=/tmp/$$
status=1	# failure is the default!
trap "_cleanup; exit \$status" 0 1 2 3 15

_cleanup()
{
	cd /
	rm -f "$tmp".*
	rm -f "$TEST_DIR/falloctest-$seq"
}

# get standard environment, filters and checks
. ./common/rc
. ./common/filter

# real QA test starts here
_supported_fs generic
_supported_os Linux
_require_xfs_io_command "falloc"

testfile="$TEST_DIR/falloctest-$seq"

# Fallocate 2 bytes across a block boundary
block_size=$(_get_file_block_size "$TEST_DIR")
$XFS_IO_PROG -f -c "falloc $((block_size - 1)) 2" "$testfile"

# Both the first blocks should be allocated now.  Check that by
# inquiring whether the file grows when we write to the two bytes we
# have just fallocated.

allocated_size_before=$(($(stat -c '%b * %B' "$testfile")))

$XFS_IO_PROG -c "pwrite $((block_size - 1)) 2" "$testfile" \
	| _filter_xfs_io | sed -e "s/$((block_size - 1))/block_size - 1/"

allocated_size_after=$(($(stat -c '%b * %B' "$testfile")))

if [ $allocated_size_after -gt $allocated_size_before ]; then
	echo "ERROR: File grew from ${allocated_size_before} B to" \
	     "${allocated_size_after} B when writing to the fallocated range."
else
	echo "OK: File did not grow."
fi

status=0
exit