generic: test for file loss after mix of rename, fsync and inode eviction
[xfstests-dev.git] / tests / generic / 551
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. 551
6 #
7 # Randomly direct AIO write&verify stress test
8 #
9 . ./common/preamble
10 _begin_fstest auto stress aio
11
12 # Import common functions.
13 . ./common/filter
14
15 # real QA test starts here
16 _supported_fs generic
17 _require_scratch
18 _require_aiodio aio-dio-write-verify
19
20 _scratch_mkfs > $seqres.full 2>&1
21 _scratch_mount
22
23 localfile=$SCRATCH_MNT/testfile
24 diosize=`_min_dio_alignment $SCRATCH_DEV`
25
26 # The maximum write size and offset are both 32k diosize. So the maximum
27 # file size will be (32 * 2)k
28 free_size_k=`df -kP $SCRATCH_MNT | grep -v Filesystem | awk '{print $4}'`
29 max_io_size_b=$((32 * 1024))
30 if [ $max_io_size_b -gt $((free_size_k * 1024 / 2 / diosize)) ]; then
31         max_io_size_b=$((free_size_k * 1024 / 2 / diosize))
32 fi
33
34 do_test()
35 {
36         local num_oper
37         local oper_list=""
38         local size
39         local off
40         local truncsize
41         local total_size=0
42         local avail_mem=`_available_memory_bytes`
43
44         # the number of AIO write operation
45         num_oper=$((RANDOM % 64 + 1))
46
47         for ((i=0; i<num_oper; i++)); do
48                 size=$(((RANDOM % max_io_size_b + 1) * diosize))
49                 total_size=$((total_size + size*2))
50                 if [[ $total_size -ge $avail_mem ]]; then
51                         break
52                 fi
53                 off=$((RANDOM % max_io_size_b * diosize))
54                 oper_list="$oper_list -a size=$size,off=$off"
55         done
56         truncsize=$(((RANDOM * diosize + RANDOM % diosize) % max_io_size_b))
57
58         $AIO_TEST -t $truncsize $oper_list $localfile
59         if [ $? -ne 0 ];then
60                 echo "$AIO_TEST -t $truncsize $oper_list $localfile"
61                 echo "==========^^ Fail ^^=========="
62         fi
63 }
64
65 testimes=$((LOAD_FACTOR * 100))
66 while [ $testimes -gt 0 ]; do
67         echo > $localfile
68         do_test
69         ((testimes--))
70 done
71
72 echo "Silence is golden"
73
74 # success, all done
75 status=0
76 exit