generic: add test for boundary in xfs_attr_shortform_verify
[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 _supported_os Linux
77 # do fsck after each iteration in test
78 _require_scratch_nocheck
79 _require_xfs_io_command "sync_range"
80
81 _scratch_mkfs >>$seqres.full 2>&1
82 _scratch_mount
83
84 # loop for $LOOP_CNT iterations, and each iteration starts $PROC_CNT processes
85 # for each operation and runs for $LOOP_TIME seconds, and check filesystem
86 # consistency after each iteration
87 for i in `seq 1 $LOOP_CNT`; do
88         rm -f $stop
89         for j in `seq 1 $PROC_CNT`; do
90                 while [ ! -e $stop ]; do
91                         do_write
92                 done &
93
94                 while [ ! -e $stop ]; do
95                         do_append
96                 done &
97
98                 while [ ! -e $stop ]; do
99                         do_writeback
100                 done &
101         done
102         sleep $LOOP_TIME
103         touch $stop
104         wait
105
106         _scratch_unmount
107         # test exits here if fs is inconsistent
108         _check_scratch_fs
109         _scratch_mount
110 done
111
112 echo "Silence is golden"
113
114 # success, all done
115 status=0
116 exit