2 # nbd client library in userspace
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2 of the License, or (at your option) any later version.
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 # Test interop with qemu-storage-daemon.
21 source ..
/tests
/functions.sh
25 requires
test "x$QEMU_STORAGE_DAEMON" != "x"
26 requires
sed --version
27 qsd_version
="$($QEMU_STORAGE_DAEMON --version | \
28 sed -n '1s/qemu-storage-daemon version \([0-9.]*\).*/\1/p')"
29 requires_not
test "$qsd_version" = "5.1.0"
30 requires_not
test "$qsd_version" = "5.2.0"
31 requires_not
test "$qsd_version" = "6.0.0"
32 requires nbdsh
--version
33 requires qemu-img
--version
35 f
="qemu-storage-daemon-disk.qcow2"
36 sock
=$
(mktemp
-u /tmp
/interop-qsd.XXXXXX
)
38 cleanup_fn
rm -f $f $sock
40 qemu-img create
$f 10M
-f qcow2
43 $VG nbdsh
-c - <<'EOF'
49 # Get the name of q-s-d defined by ./configure.
50 qsd = os.environ["QEMU_STORAGE_DAEMON"]
56 sock = os.environ["sock"]
58 # Create two sockets for client and server. We pass the listening
60 client_sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
61 qsd_sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
62 os.set_inheritable(qsd_sock.fileno(), True)
65 client_sock.connect(sock)
67 # Assemble q-s-d command line.
71 "qcow2,file.driver=file,file.filename=" + f + ",node-name=disk0",
72 "--nbd-server", "addr.type=fd,addr.str=" + str(qsd_sock.fileno()),
73 "--export", "nbd,node-name=disk0,id=nbd0,name=,writable=on"
75 print("server: %r" % argv, file=sys.stderr)
84 # Connect to the server and test.
85 h.connect_socket(client_sock.fileno())
90 buf2 = h.pread(1024, 0)
91 assert bytearray(512) + buf == buf2
96 os.kill(pid, signal.SIGTERM)