3 # Copyright (C) 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
39 # Test handling of NBD maximum string length of 4k.
41 requires qemu-io
--version
42 requires qemu-nbd
--version
43 requires nbdsh
-c 'exit(not h.supports_uri())'
45 name16
=1234567812345678
46 name64
=$name16$name16$name16$name16
47 name256
=$name64$name64$name64$name64
48 name1k
=$name256$name256$name256$name256
49 name4k
=$name1k$name1k$name1k$name1k
50 almost4k
=${name4k%8$name16}
52 # Test behavior of -e: accept 4k max, reject longer
53 nbdkit
-U - -e $name4k null
--run true || fail
=1
54 nbdkit
-U - -e a
$name4k null
--run true
&& fail
=1
56 # Test that $exportname and $uri reflect the name
57 out
=$
(nbdkit
-U - -e $name4k null
--run 'echo $exportname')
58 if test "$name4k" != "$out"; then
59 echo "$0: \$exportname contains wrong contents" >&2
62 out
=$
(nbdkit
-U - -e $name4k null
--run 'echo $uri')
64 nbd
+unix
:///$name4k\?socket
=*) ;;
65 *) echo "$0: \$uri contains wrong contents" >&2
69 out
=$
(nbdkit
-i localhost
-p $port -e $name4k null
--run 'echo $uri')
71 nbd
://localhost
:$port/$name4k) ;;
72 *) echo "$0: \$uri contains wrong contents" >&2
76 # Use largest possible export name, then oversize, with NBD_OPT_EXPORT_NAME.
77 nbdkit
-U - --mask-handshake=0 null
--run 'qemu-io -r -f raw -c quit \
78 nbd+unix:///'$name4k'\?socket=$unixsocket' || fail
=1
79 # qemu 4.1 did not length check, letting it send an invalid NBD client
80 # request which nbdkit must filter out. Later qemu might refuse to
81 # send the request (like libnbd does), at which point this is no longer
82 # testing nbdkit proper, so we may remove it later:
83 nbdkit
-U - --mask-handshake=0 null
--run 'qemu-io -r -f raw -c quit \
84 nbd+unix:///'a
$name4k'\?socket=$unixsocket' && fail
=1
86 # Repeat with NBD_OPT_GO.
87 nbdkit
-U - null
--run 'qemu-io -r -f raw -c quit \
88 nbd+unix:///'$name4k'\?socket=$unixsocket' || fail
=1
89 # See above comment about whether this is testing nbdkit or qemu:
90 nbdkit
-U - null
--run 'qemu-io -r -f raw -c quit \
91 nbd+unix:///'a
$name4k'\?socket=$unixsocket' && fail
=1
93 # Use nbdsh to provoke an extremely large NBD_OPT_SET_META_CONTEXT.
94 nbdkit
-U - -e $almost4k null
--run 'export exportname uri
97 long = os.environ["exportname"]
98 h.set_export_name (long)
99 h.add_meta_context ("a" + long)
100 h.add_meta_context ("b" + long)
101 h.add_meta_context ("c" + long)
102 h.add_meta_context ("d" + long)
103 h.add_meta_context ("e" + long)
104 h.connect_uri (os.environ["uri"])
105 assert h.get_size() == 0
109 # The rest of this test uses the ‘qemu-nbd --list’ option added in qemu 4.0.
110 if ! qemu-nbd
--help |
grep -sq -- --list; then
111 echo "$0: skipping because qemu-nbd does not support the --list option"
115 # Test response to NBD_OPT_LIST
116 nbdkit
-U - -e $name4k null
--run 'qemu-nbd --list -k $unixsocket' || fail
=1