3 # Copyright (C) 2019-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
39 # Test handling of NBD maximum string length of 4k.
42 requires qemu-io
--version
43 requires qemu-nbd
--version
46 name16
=1234567812345678
47 name64
=$name16$name16$name16$name16
48 name256
=$name64$name64$name64$name64
49 name1k
=$name256$name256$name256$name256
50 name4k
=$name1k$name1k$name1k$name1k
51 almost4k
=${name4k%8$name16}
53 # Test that $exportname and $uri reflect the name
54 out
=$
(nbdkit
-U - -e $name4k null
--run 'echo $exportname')
55 if test "$name4k" != "$out"; then
56 echo "$0: \$exportname contains wrong contents" >&2
59 out
=$
(nbdkit
-U - -e $name4k null
--run 'echo "$uri"')
61 nbd
+unix
:///$name4k\?socket
=*) ;;
62 *) echo "$0: \$uri contains wrong contents" >&2
66 out
=$
(nbdkit
-i localhost
-p $port -e $name4k null
--run 'echo "$uri"')
68 nbd
://localhost
:$port/$name4k) ;;
69 *) echo "$0: \$uri contains wrong contents" >&2
73 # Use largest possible export name, then oversize, with NBD_OPT_EXPORT_NAME.
74 nbdkit
-U - --mask-handshake=0 null
--run 'qemu-io -r -f raw -c quit \
75 nbd+unix:///'$name4k'\?socket=$unixsocket' || fail
=1
76 # qemu 4.1 did not length check, letting it send an invalid NBD client
77 # request which nbdkit must filter out. Later qemu might refuse to
78 # send the request (like libnbd does), at which point this is no longer
79 # testing nbdkit proper, so we may remove it later:
80 nbdkit
-U - --mask-handshake=0 null
--run 'qemu-io -r -f raw -c quit \
81 nbd+unix:///'a
$name4k'\?socket=$unixsocket' && fail
=1
83 # Repeat with NBD_OPT_GO.
84 nbdkit
-U - null
--run 'qemu-io -r -f raw -c quit \
85 nbd+unix:///'$name4k'\?socket=$unixsocket' || fail
=1
86 # See above comment about whether this is testing nbdkit or qemu:
87 nbdkit
-U - null
--run 'qemu-io -r -f raw -c quit \
88 nbd+unix:///'a
$name4k'\?socket=$unixsocket' && fail
=1
90 # Use nbdsh to provoke an extremely large NBD_OPT_SET_META_CONTEXT.
91 nbdkit
-U - -e $almost4k null
--run 'export exportname uri
94 long = os.environ["exportname"]
95 h.set_export_name(long)
96 h.add_meta_context("a" + long)
97 h.add_meta_context("b" + long)
98 h.add_meta_context("c" + long)
99 h.add_meta_context("d" + long)
100 h.add_meta_context("e" + long)
101 h.connect_uri(os.environ["uri"])
102 assert h.get_size() == 0
106 # See also test-eval-exports.sh for NBD_OPT_LIST with long name