2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2020 SUSE Linux Products GmbH. All Rights Reserved.
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.
12 seqres=$RESULT_DIR/$seq
13 echo "QA output created by $seq"
15 status=1 # failure is the default!
16 trap "_cleanup; exit \$status" 0 1 2 3 15
24 # get standard environment, filters and checks
28 # real QA test starts here
37 trap "wait; exit" SIGTERM
42 blocks=$(stat -c %b $filepath)
43 if [ $blocks -eq 0 ]; then
44 echo "error: stat(2) reported zero blocks"
50 _scratch_mkfs >>$seqres.full 2>&1
53 $XFS_IO_PROG -f -s -c "pwrite -b 64K 0 64K" $SCRATCH_MNT/foo > /dev/null
55 stat_loop $SCRATCH_MNT/foo &
58 echo "Testing buffered writes"
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
67 $XFS_IO_PROG -s -c "pwrite -b 64K 0 64K" $SCRATCH_MNT/foo > /dev/null
70 echo "Testing direct IO writes"
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
77 $XFS_IO_PROG -d -c "pwrite -b 64K 0 64K" $SCRATCH_MNT/foo > /dev/null
80 kill $loop_pid &> /dev/null