summaryrefslogtreecommitdiff
path: root/tests/generic/538
blob: f6f5496b4f24033514d68c1e00df068c7762541d (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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (c) 2019 Red Hat, Inc.  All Rights Reserved.
#
# FS QA Test No. 538
#
# Non-block-aligned direct AIO write test with an initial truncate i_size.
#
# Uncover "ext4: Fix data corruption caused by unaligned direct AIO":
# (Ext4 needs to serialize unaligned direct AIO because the zeroing of
# partial blocks of two competing unaligned AIOs can result in data
# corruption.
#
# However it decides not to serialize if the potentially unaligned aio is
# past i_size with the rationale that no pending writes are possible past
# i_size. Unfortunately if the i_size is not block aligned and the second
# unaligned write lands past i_size, but still into the same block, it has
# the potential of corrupting the previous unaligned write to the same
# block.)
#
. ./common/preamble
_begin_fstest auto quick aio

# Import common functions.
. ./common/filter

# real QA test starts here
_supported_fs generic
_require_test
_require_aiodio aio-dio-write-verify

localfile=$TEST_DIR/${seq}-aio-dio-write-verify-testfile
diosize=`_min_dio_alignment $TEST_DEV`
blocksize=`_get_block_size $TEST_DIR`
bufsize=$((blocksize * 2))
truncsize=$((bufsize+diosize))

# Need smaller logical block size to do non-block-aligned test
if [ $diosize -ge $blocksize ];then
	_notrun "Need device logical block size($diosize) < fs block size($blocksize)"
fi

rm -rf $localfile 2>/dev/null
# block-aligned aiodio write verification at first
$AIO_TEST -a size=$bufsize,off=0 -a size=$bufsize,off=$bufsize $localfile

# non-block-aligned aiodio write verification
#          **************** **************** ****************
#          *   block 1&2  * *  block 3&4   * *  block 5&6   *
#          **************** **************** ****************
# existing 0000000000000000 0000000000000000 0000000000000000
# truncate ---------------->|
# write 1   ZZZZZZZZZZZZZZZ Z
# write 2  |<----            ZZZZZZZZZZZZZZZ Z ---->|
#
# "Write 1" writes 2 blocks data at off=$diosize.
# "Write 2" seeks from 0 to "Write 1" end + block size, shift $diosize bytes each
# time, writes 2 blocksize data too.
# Verify there's not corruption each time.
i=0
while [ $((diosize * i)) -lt $((diosize + bufsize + blocksize)) ];do
	position=$((diosize * i++))
	# non-block-aligned AIO write on different i_size file
	$AIO_TEST -t $truncsize -a size=$bufsize,off=$diosize \
		  -a size=$bufsize,off=$position \
		  $localfile
	if [ $? -ne 0 ];then
		echo "FAIL: [$truncsize, $bufsize, $diosize, $position]"
		echo "-------------------------------------------------"
	fi
	rm -f $localfile
done

echo "Silence is golden"

# success, all done
status=0
exit