generic/223: make sure all files get created on the data device
[xfstests-dev.git] / tests / generic / 615
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2020 SUSE Linux Products GmbH. All Rights Reserved.
4 #
5 # FS QA Test No. 615
6 #
7 # Test that if we keep overwriting an entire file, either with buffered writes
8 # or direct IO writes, the number of used blocks reported by stat(2) is never
9 # zero while writeback is in progress.
10 #
11 seq=`basename $0`
12 seqres=$RESULT_DIR/$seq
13 echo "QA output created by $seq"
14 tmp=/tmp/$$
15 status=1        # failure is the default!
16 trap "_cleanup; exit \$status" 0 1 2 3 15
17
18 _cleanup()
19 {
20         cd /
21         rm -f $tmp.*
22 }
23
24 # get standard environment, filters and checks
25 . ./common/rc
26 . ./common/filter
27
28 # real QA test starts here
29 _supported_fs generic
30 _require_scratch
31 _require_odirect
32
33 rm -f $seqres.full
34
35 stat_loop()
36 {
37         trap "wait; exit" SIGTERM
38         local filepath=$1
39         local blocks
40
41         while :; do
42                 blocks=$(stat -c %b $filepath)
43                 if [ $blocks -eq 0 ]; then
44                     echo "error: stat(2) reported zero blocks"
45                     break
46                 fi
47         done
48 }
49
50 _scratch_mkfs >>$seqres.full 2>&1
51 _scratch_mount
52
53 $XFS_IO_PROG -f -s -c "pwrite -b 64K 0 64K" $SCRATCH_MNT/foo > /dev/null
54
55 stat_loop $SCRATCH_MNT/foo &
56 loop_pid=$!
57
58 echo "Testing buffered writes"
59
60 # Now keep overwriting the entire file, triggering writeback after each write,
61 # while another process is calling stat(2) on the file. We expect the number of
62 # used blocks reported by stat(2) to be always greater than 0.
63 for ((i = 0; i < 2000; i++)); do
64         if ! kill -s 0 $loop_pid &> /dev/null; then
65             break
66         fi
67         $XFS_IO_PROG -s -c "pwrite -b 64K 0 64K" $SCRATCH_MNT/foo > /dev/null
68 done
69
70 echo "Testing direct IO writes"
71
72 # Now similar to what we did before but for direct IO writes.
73 for ((i = 0; i < 2000; i++)); do
74         if ! kill -s 0 $loop_pid &> /dev/null; then
75             break
76         fi
77         $XFS_IO_PROG -d -c "pwrite -b 64K 0 64K" $SCRATCH_MNT/foo > /dev/null
78 done
79
80 kill $loop_pid &> /dev/null
81 wait
82
83 status=0
84 exit