3 # Copyright (C) 2017-2019 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
39 nbdkit
--dump-plugin nbd |
grep -q ^thread_model
=parallel ||
40 { echo "nbdkit lacks support for parallel requests"; exit 77; }
43 files
="test-parallel-nbd.out $sock test-parallel-nbd.data test-parallel-nbd.pid"
45 cleanup_fn
rm -f $files
47 # Populate file, and sanity check that qemu-io can issue parallel requests
48 printf '%1024s' .
> test-parallel-nbd.data
49 qemu-io
-f raw
-c "aio_write -P 1 0 512" -c "aio_write -P 2 512 512" \
50 -c aio_flush test-parallel-nbd.data ||
51 { echo "'qemu-io' can't drive parallel requests"; exit 77; }
53 # Set up the file plugin to delay both reads and writes (for a good chance
54 # that parallel requests are in flight), and with writes longer than reads
55 # (to more easily detect if out-of-order completion happens). This test
56 # may have spurious failures under heavy loads on the test machine, where
57 # tuning the delays may help.
59 start_nbdkit
-P test-parallel-nbd.pid \
62 file test-parallel-nbd.data wdelay
=2 rdelay
=1
64 # With --threads=1, the write should complete first because it was issued first
65 nbdkit
-v -t 1 -U - nbd socket
=$sock --run '
66 qemu-io -f raw -c "aio_write -P 2 512 512" -c "aio_read -P 1 0 512" \
67 -c aio_flush $nbd' |
tee test-parallel-nbd.out
68 if test "$(grep '512/512' test-parallel-nbd.out)" != \
69 "wrote 512/512 bytes at offset 512
70 read 512/512 bytes at offset 0"; then
74 # With default --threads, the faster read should complete first
75 nbdkit
-v -U - nbd socket
=$sock --run '
76 qemu-io -f raw -c "aio_write -P 2 512 512" -c "aio_read -P 1 0 512" \
77 -c aio_flush $nbd' |
tee test-parallel-nbd.out
78 if test "$(grep '512/512' test-parallel-nbd.out)" != \
79 "read 512/512 bytes at offset 0
80 wrote 512/512 bytes at offset 512"; then