3 # Copyright (C) 2017-2020 Red Hat Inc.
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions are
9 # * Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
12 # * Redistributions in binary form must reproduce the above copyright
13 # notice, this list of conditions and the following disclaimer in the
14 # documentation and/or other materials provided with the distribution.
16 # * Neither the name of Red Hat nor the names of its contributors may be
17 # used to endorse or promote products derived from this software without
18 # specific prior written permission.
20 # THIS SOFTWARE IS PROVIDED BY RED HAT AND CONTRIBUTORS ''AS IS'' AND
21 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23 # PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT OR
24 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
27 # USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
30 # OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 # Check file-data was created by Makefile and qemu-io exists.
36 requires
test -f file-data
37 requires qemu-io
--version
38 requires timeout
60s true
40 nbdkit
--dump-plugin file |
grep -q ^thread_model
=parallel ||
41 { echo "nbdkit lacks support for parallel requests"; exit 77; }
43 cleanup_fn
rm -f test-parallel-file.data test-parallel-file.out
45 # Populate file, and sanity check that qemu-io can issue parallel requests
46 printf '%1024s' .
> test-parallel-file.data
47 timeout
30s
</dev
/null qemu-io
-f raw
-c "aio_write -P 1 0 512" \
48 -c "aio_write -P 2 512 512" -c aio_flush test-parallel-file.data ||
49 { echo "'qemu-io' can't drive parallel requests"; exit 77; }
51 # Set up the file plugin to delay both reads and writes (for a good chance
52 # that parallel requests are in flight), and with writes longer than reads
53 # (to more easily detect if out-of-order completion happens). This test
54 # may have spurious failures under heavy loads on the test machine, where
55 # tuning the delays may help.
57 # With --threads=1, the write should complete first because it was issued first
58 nbdkit
-v -t 1 -U - --filter=delay
file test-parallel-file.data \
59 wdelay
=2 rdelay
=1 --run 'timeout 60s </dev/null qemu-io -f raw \
60 -c "aio_write -P 2 512 512" -c "aio_read -P 1 0 512" -c aio_flush $nbd' |
61 tee test-parallel-file.out
62 if test "$(grep '512/512' test-parallel-file.out)" != \
63 "wrote 512/512 bytes at offset 512
64 read 512/512 bytes at offset 0"; then
68 # With default --threads, the faster read should complete first
69 nbdkit
-v -U - --filter=delay
file test-parallel-file.data \
70 wdelay
=2 rdelay
=1 --run 'timeout 60s </dev/null qemu-io -f raw \
71 -c "aio_write -P 2 512 512" -c "aio_read -P 1 0 512" -c aio_flush $nbd' |
72 tee test-parallel-file.out
73 if test "$(grep '512/512' test-parallel-file.out)" != \
74 "read 512/512 bytes at offset 0
75 wrote 512/512 bytes at offset 512"; then
79 # With --filter=noparallel, the write should complete first because it was issued first
80 nbdkit
-v -U - --filter=noparallel
--filter=delay
file test-parallel-file.data \
81 wdelay
=2 rdelay
=1 --run 'timeout 60s </dev/null qemu-io -f raw \
82 -c "aio_write -P 2 512 512" -c "aio_read -P 1 0 512" -c aio_flush $nbd' |
83 tee test-parallel-file.out
84 if test "$(grep '512/512' test-parallel-file.out)" != \
85 "wrote 512/512 bytes at offset 512
86 read 512/512 bytes at offset 0"; then