fsx/fsstress: round blocksize properly
[xfstests-dev.git] / tests / generic / 464
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2017 Red Hat Inc. All Rights Reserved.
4 #
5 # FS QA Test 464
6 #
7 # Run delalloc writes & append writes & non-data-integrity syncs concurrently
8 # to test the race between block map change vs writeback.
9 #
10 seq=`basename $0`
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
13
14 here=`pwd`
15 tmp=/tmp/$$
16 status=1        # failure is the default!
17 trap "_cleanup; exit \$status" 0 1 2 3 15
18
19 _cleanup()
20 {
21         cd /
22         rm -f $tmp.*
23 }
24
25 # get standard environment, filters and checks
26 . ./common/rc
27 . ./common/filter
28
29 MAXFILES=200
30 BLOCK_SZ=65536
31
32 LOOP_CNT=10
33 LOOP_TIME=5
34 PROC_CNT=16
35
36 stop=$tmp.stop
37
38 # get a random file to work on
39 getfile()
40 {
41         echo $SCRATCH_MNT/$((RANDOM % MAXFILES))
42 }
43
44 # delalloc write a relative big file to get enough dirty pages to be written
45 # back, and XFS needs big enough file to trigger speculative preallocations, so
46 # freeing these eofblocks could change the extent record
47 do_write()
48 {
49         local blockcount=$((RANDOM % 100))
50         local filesize=$((blockcount * BLOCK_SZ))
51         $XFS_IO_PROG -ftc "pwrite -b $BLOCK_SZ 0 $filesize" `getfile` \
52                 >/dev/null 2>&1
53 }
54
55 # append another dirty page to the file, the writeback might pick it up too if
56 # the file is already under writeback
57 do_append()
58 {
59         echo "test string" >> `getfile`
60 }
61
62 # issue WB_SYNC_NONE writeback with the '-w' option of sync_range xfs_io
63 # command, so that the last dirty page from append write can be picked up in
64 # this writeback cycle. This is not mandatory but could help reproduce XFS
65 # corruption more easily.
66 do_writeback()
67 {
68         $XFS_IO_PROG -c "sync_range -w 0 0" `getfile` >/dev/null 2>&1
69 }
70
71 # remove previous $seqres.full before test
72 rm -f $seqres.full
73
74 # real QA test starts here
75 _supported_fs generic
76 # do fsck after each iteration in test
77 _require_scratch_nocheck
78 _require_xfs_io_command "sync_range"
79
80 _scratch_mkfs >>$seqres.full 2>&1
81 _scratch_mount
82
83 # loop for $LOOP_CNT iterations, and each iteration starts $PROC_CNT processes
84 # for each operation and runs for $LOOP_TIME seconds, and check filesystem
85 # consistency after each iteration
86 for i in `seq 1 $LOOP_CNT`; do
87         rm -f $stop
88         for j in `seq 1 $PROC_CNT`; do
89                 while [ ! -e $stop ]; do
90                         do_write
91                 done &
92
93                 while [ ! -e $stop ]; do
94                         do_append
95                 done &
96
97                 while [ ! -e $stop ]; do
98                         do_writeback
99                 done &
100         done
101         sleep $LOOP_TIME
102         touch $stop
103         wait
104
105         _scratch_unmount
106         # test exits here if fs is inconsistent
107         _check_scratch_fs
108         _scratch_mount
109 done
110
111 echo "Silence is golden"
112
113 # success, all done
114 status=0
115 exit