qemu-nbd as of QEMU 3.1.5 stopped supporting old style of handshake.
This patch updates nbd_client.py to use new handshake.

Signed-off-by: Waldemar Kozaczuk <jwkozac...@gmail.com>
---
 scripts/nbd_client.py | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/scripts/nbd_client.py b/scripts/nbd_client.py
index e797b128..033233f5 100644
--- a/scripts/nbd_client.py
+++ b/scripts/nbd_client.py
@@ -32,7 +32,7 @@ class nbd_client(object):
         self._length = 0
         self._s = socket.create_connection((hostname, port))
         self._closed = False
-        self._old_style_handshake()
+        self._new_style_handshake()
 
     def __del__(self):
         self.close()
@@ -44,12 +44,23 @@ class nbd_client(object):
             self._disconnect()
             self._closed = True
 
-    def _old_style_handshake(self):
+    def _new_style_handshake(self):
+        # Perform handshake as specified in
+        # https://github.com/NetworkBlockDevice/nbd/blob/master/doc/proto.md
         nbd_magic = self._s.recv(len("NBDMAGIC"))
         assert(nbd_magic == b'NBDMAGIC')
-        buf = self._s.recv(8 + 8 + 4)
-        (magic, self._size, self._flags) = struct.unpack(">QQL", buf)
-        assert(magic == 0x00420281861253)
+        buf = self._s.recv(8 + 2)
+        (magic, self._flags) = struct.unpack(">QH", buf)
+        assert(magic == 0x49484156454F5054) # Should have received IHAVEOPT
+        client_flags = struct.pack('>L', 0)
+        self._s.send(client_flags)
+
+        options = struct.pack('>QLL', 0x49484156454F5054, 1, 0)
+        self._s.send(options)
+
+        buf = self._s.recv(8 + 2)
+        (self._size, self._flags) = struct.unpack(">QH", buf)
+
         # ignore trailing zeroes
         self._s.recv(124)
 
-- 
2.20.1

-- 
You received this message because you are subscribed to the Google Groups "OSv 
Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to osv-dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to