generic: test for creating duplicate filenames in encrypted dir
[xfstests-dev.git] / tests / generic / 538
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2019 Red Hat, Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. 538
6 #
7 # Non-block-aligned direct AIO write test with an initial truncate i_size.
8 #
9 # Uncover "ext4: Fix data corruption caused by unaligned direct AIO":
10 # (Ext4 needs to serialize unaligned direct AIO because the zeroing of
11 # partial blocks of two competing unaligned AIOs can result in data
12 # corruption.
13 #
14 # However it decides not to serialize if the potentially unaligned aio is
15 # past i_size with the rationale that no pending writes are possible past
16 # i_size. Unfortunately if the i_size is not block aligned and the second
17 # unaligned write lands past i_size, but still into the same block, it has
18 # the potential of corrupting the previous unaligned write to the same
19 # block.)
20 #
21 seq=`basename $0`
22 seqres=$RESULT_DIR/$seq
23 echo "QA output created by $seq"
24
25 here=`pwd`
26 tmp=/tmp/$$
27 status=1        # failure is the default!
28 trap "_cleanup; exit \$status" 0 1 2 3 15
29
30 _cleanup()
31 {
32         cd /
33         rm -f $tmp.*
34 }
35
36 # get standard environment, filters and checks
37 . ./common/rc
38 . ./common/filter
39
40 # remove previous $seqres.full before test
41 rm -f $seqres.full
42
43 # real QA test starts here
44 _supported_fs generic
45 _require_test
46 _require_aiodio aio-dio-write-verify
47
48 localfile=$TEST_DIR/${seq}-aio-dio-write-verify-testfile
49 diosize=`_min_dio_alignment $TEST_DEV`
50 blocksize=`_get_block_size $TEST_DIR`
51 bufsize=$((blocksize * 2))
52 truncsize=$((bufsize+diosize))
53
54 # Need smaller logical block size to do non-block-aligned test
55 if [ $diosize -ge $blocksize ];then
56         _notrun "Need device logical block size($diosize) < fs block size($blocksize)"
57 fi
58
59 rm -rf $localfile 2>/dev/null
60 # block-aligned aiodio write verification at first
61 $AIO_TEST -a size=$bufsize,off=0 -a size=$bufsize,off=$bufsize $localfile
62
63 # non-block-aligned aiodio write verification
64 #          **************** **************** ****************
65 #          *   block 1&2  * *  block 3&4   * *  block 5&6   *
66 #          **************** **************** ****************
67 # existing 0000000000000000 0000000000000000 0000000000000000
68 # truncate ---------------->|
69 # write 1   ZZZZZZZZZZZZZZZ Z
70 # write 2  |<----            ZZZZZZZZZZZZZZZ Z ---->|
71 #
72 # "Write 1" writes 2 blocks data at off=$diosize.
73 # "Write 2" seeks from 0 to "Write 1" end + block size, shift $diosize bytes each
74 # time, writes 2 blocksize data too.
75 # Verify there's not corruption each time.
76 i=0
77 while [ $((diosize * i)) -lt $((diosize + bufsize + blocksize)) ];do
78         position=$((diosize * i++))
79         # non-block-aligned AIO write on different i_size file
80         $AIO_TEST -t $truncsize -a size=$bufsize,off=$diosize \
81                   -a size=$bufsize,off=$position \
82                   $localfile
83         if [ $? -ne 0 ];then
84                 echo "FAIL: [$truncsize, $bufsize, $diosize, $position]"
85                 echo "-------------------------------------------------"
86         fi
87         rm -f $localfile
88 done
89
90 echo "Silence is golden"
91
92 # success, all done
93 status=0
94 exit