From c8a3a1b6c4034cf53cdbd953331c72f9573edb77 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Fri, 14 Oct 2016 13:33:10 -0500 Subject: nbd: Share common option-sending code in client Rather than open-coding each option request, it's easier to have common helper functions do the work. That in turn requires having convenient packed types for handling option requests and replies. Signed-off-by: Eric Blake Message-Id: <1476469998-28592-9-git-send-email-eblake@redhat.com> Signed-off-by: Paolo Bonzini --- include/block/nbd.h | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/block/nbd.h b/include/block/nbd.h index a33581b6a9..b69bf1dc68 100644 --- a/include/block/nbd.h +++ b/include/block/nbd.h @@ -26,15 +26,34 @@ #include "io/channel-socket.h" #include "crypto/tlscreds.h" -/* Note: these are _NOT_ the same as the network representation of an NBD +/* Handshake phase structs - this struct is passed on the wire */ + +struct nbd_option { + uint64_t magic; /* NBD_OPTS_MAGIC */ + uint32_t option; /* NBD_OPT_* */ + uint32_t length; +} QEMU_PACKED; +typedef struct nbd_option nbd_option; + +struct nbd_opt_reply { + uint64_t magic; /* NBD_REP_MAGIC */ + uint32_t option; /* NBD_OPT_* */ + uint32_t type; /* NBD_REP_* */ + uint32_t length; +} QEMU_PACKED; +typedef struct nbd_opt_reply nbd_opt_reply; + +/* Transmission phase structs + * + * Note: these are _NOT_ the same as the network representation of an NBD * request and reply! */ struct NBDRequest { uint64_t handle; uint64_t from; uint32_t len; - uint16_t flags; - uint16_t type; + uint16_t flags; /* NBD_CMD_FLAG_* */ + uint16_t type; /* NBD_CMD_* */ }; typedef struct NBDRequest NBDRequest; -- cgit v1.2.1