aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2019-02-05 12:46:18 +0000
committerPeter Maydell <peter.maydell@linaro.org>2019-02-05 12:46:18 +0000
commit1c3d45df5e94042d5fb2bb31416072563ab30e49 (patch)
treeb93bbcb015f1a7e2b2cc14d26930536b0559faa1 /include
parent9ae805637a9cfab2edc15f56fbc3219815c8118e (diff)
parentbc5a03350c220698229e7d6929dd242d5d358345 (diff)
Merge remote-tracking branch 'remotes/ericb/tags/pull-nbd-2019-02-04' into staging
nbd patches for 2019-02-04 - deprecate 'qemu-nbd --partition' - preparation for NBD reconnect, including better logging of read errors # gpg: Signature made Tue 05 Feb 2019 03:50:56 GMT # gpg: using RSA key A7A16B4A2527436A # gpg: Good signature from "Eric Blake <eblake@redhat.com>" [full] # gpg: aka "Eric Blake (Free Software Programmer) <ebb9@byu.net>" [full] # gpg: aka "[jpeg image of size 6874]" [full] # Primary key fingerprint: 71C2 CC22 B1C4 6029 27D2 F3AA A7A1 6B4A 2527 436A * remotes/ericb/tags/pull-nbd-2019-02-04: block/nbd-client: rename read_reply_co to connection_co block/nbd-client: don't check ioc block/nbd-client: fix nbd_reply_chunk_iter_receive block/nbd-client: split connection from initialization block/nbd: move connection code from block/nbd to block/nbd-client block/nbd-client: split channel errors from export errors nbd: generalize usage of nbd_read qemu-nbd: Deprecate qemu-nbd --partition Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'include')
-rw-r--r--include/block/nbd.h32
1 files changed, 30 insertions, 2 deletions
diff --git a/include/block/nbd.h b/include/block/nbd.h
index 4faf394e34..96cfb1d7d5 100644
--- a/include/block/nbd.h
+++ b/include/block/nbd.h
@@ -23,6 +23,7 @@
#include "qapi/qapi-types-block.h"
#include "io/channel-socket.h"
#include "crypto/tlscreds.h"
+#include "qapi/error.h"
/* Handshake phase structs - this struct is passed on the wire */
@@ -336,11 +337,38 @@ void nbd_server_start(SocketAddress *addr, const char *tls_creds,
* Reads @size bytes from @ioc. Returns 0 on success.
*/
static inline int nbd_read(QIOChannel *ioc, void *buffer, size_t size,
- Error **errp)
+ const char *desc, Error **errp)
{
- return qio_channel_read_all(ioc, buffer, size, errp) < 0 ? -EIO : 0;
+ int ret = qio_channel_read_all(ioc, buffer, size, errp) < 0 ? -EIO : 0;
+
+ if (ret < 0) {
+ if (desc) {
+ error_prepend(errp, "Failed to read %s: ", desc);
+ }
+ return -1;
+ }
+
+ return 0;
+}
+
+#define DEF_NBD_READ_N(bits) \
+static inline int nbd_read##bits(QIOChannel *ioc, \
+ uint##bits##_t *val, \
+ const char *desc, Error **errp) \
+{ \
+ if (nbd_read(ioc, val, sizeof(*val), desc, errp) < 0) { \
+ return -1; \
+ } \
+ *val = be##bits##_to_cpu(*val); \
+ return 0; \
}
+DEF_NBD_READ_N(16) /* Defines nbd_read16(). */
+DEF_NBD_READ_N(32) /* Defines nbd_read32(). */
+DEF_NBD_READ_N(64) /* Defines nbd_read64(). */
+
+#undef DEF_NBD_READ_N
+
static inline bool nbd_reply_is_simple(NBDReply *reply)
{
return reply->magic == NBD_SIMPLE_REPLY_MAGIC;