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
37 requires nbdsh
--version
40 files
="$sock exportname.pid"
42 cleanup_fn
rm -f $files
44 # Create an nbdkit sh plugin which reflects the export name back to
45 # the caller in the virtual device data and size.
46 start_nbdkit
-P exportname.pid
-U $sock \
50 # The export name is the handle. nbdkit-sh-plugin removes
51 # exactly one trailing \n for us, so we must add one in case
52 # the client's handle also has one.
56 # Returns the length of the export name / handle in _bytes_.
61 printf %s "$2" | dd skip=$4 count=$3 iflag=skip_bytes,count_bytes
67 # Try to read back various export names from the plugin.
68 for e
in "" "test" "/" "//" " " "/ " "?" "ใในใ" "-n" '\\' $
'\n' "%%" \
69 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
77 h.connect_unix (os.environ["sock"])
80 print ("size=%r e=%r" % (size, e))
81 assert size == len (e.encode("utf-8"))
83 # Zero-sized reads are not defined in the NBD protocol.
85 buf = h.pread (size, 0)
86 print ("buf=%r e=%r" % (buf, e))
87 assert buf == e.encode("utf-8")