aboutsummaryrefslogtreecommitdiff
path: root/nbd
diff options
context:
space:
mode:
authorEric Blake <eblake@redhat.com>2017-10-27 12:40:28 +0200
committerEric Blake <eblake@redhat.com>2017-10-30 21:07:21 +0100
commitbae245d19a7fae77410cb8b09350b672df689a66 (patch)
treebd4bfd313e22a91e10ffa16c1dce6e9bb385b0b0 /nbd
parentdd6894404947d39a724ea265389fe0f2d6d5ecb7 (diff)
downloadqemu-bae245d19a7fae77410cb8b09350b672df689a66.zip
qemu-bae245d19a7fae77410cb8b09350b672df689a66.tar.gz
qemu-bae245d19a7fae77410cb8b09350b672df689a66.tar.bz2
nbd: Expose constants and structs for structured read
Upcoming patches will implement the NBD structured reply extension [1] for both client and server roles. Declare the constants, structs, and lookup routines that will be valuable whether the server or client code is backported in isolation. This includes moving one constant from an internal header to the public header, as part of the structured read processing will be done in block/nbd-client.c rather than nbd/client.c. [1]https://github.com/NetworkBlockDevice/nbd/blob/extension-structured-reply/doc/proto.md Based on patches from Vladimir Sementsov-Ogievskiy. Signed-off-by: Eric Blake <eblake@redhat.com> Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> Message-Id: <20171027104037.8319-4-eblake@redhat.com>
Diffstat (limited to 'nbd')
-rw-r--r--nbd/common.c27
-rw-r--r--nbd/nbd-internal.h2
-rw-r--r--nbd/server.c2
3 files changed, 30 insertions, 1 deletions
diff --git a/nbd/common.c b/nbd/common.c
index 593904f..6047d71 100644
--- a/nbd/common.c
+++ b/nbd/common.c
@@ -151,6 +151,28 @@ const char *nbd_cmd_lookup(uint16_t cmd)
}
+const char *nbd_reply_type_lookup(uint16_t type)
+{
+ switch (type) {
+ case NBD_REPLY_TYPE_NONE:
+ return "none";
+ case NBD_REPLY_TYPE_OFFSET_DATA:
+ return "data";
+ case NBD_REPLY_TYPE_OFFSET_HOLE:
+ return "hole";
+ case NBD_REPLY_TYPE_ERROR:
+ return "generic error";
+ case NBD_REPLY_TYPE_ERROR_OFFSET:
+ return "error at offset";
+ default:
+ if (type & (1 << 15)) {
+ return "<unknown error>";
+ }
+ return "<unknown>";
+ }
+}
+
+
const char *nbd_err_lookup(int err)
{
switch (err) {
@@ -166,6 +188,8 @@ const char *nbd_err_lookup(int err)
return "EINVAL";
case NBD_ENOSPC:
return "ENOSPC";
+ case NBD_EOVERFLOW:
+ return "EOVERFLOW";
case NBD_ESHUTDOWN:
return "ESHUTDOWN";
default:
@@ -193,6 +217,9 @@ int nbd_errno_to_system_errno(int err)
case NBD_ENOSPC:
ret = ENOSPC;
break;
+ case NBD_EOVERFLOW:
+ ret = EOVERFLOW;
+ break;
case NBD_ESHUTDOWN:
ret = ESHUTDOWN;
break;
diff --git a/nbd/nbd-internal.h b/nbd/nbd-internal.h
index df6c8b2..4f24d6e 100644
--- a/nbd/nbd-internal.h
+++ b/nbd/nbd-internal.h
@@ -47,7 +47,6 @@
#define NBD_OLDSTYLE_NEGOTIATE_SIZE (8 + 8 + 8 + 4 + 124)
#define NBD_REQUEST_MAGIC 0x25609513
-#define NBD_SIMPLE_REPLY_MAGIC 0x67446698
#define NBD_OPTS_MAGIC 0x49484156454F5054LL
#define NBD_CLIENT_MAGIC 0x0000420281861253LL
#define NBD_REP_MAGIC 0x0003e889045565a9LL
@@ -114,6 +113,7 @@ const char *nbd_opt_lookup(uint32_t opt);
const char *nbd_rep_lookup(uint32_t rep);
const char *nbd_info_lookup(uint16_t info);
const char *nbd_cmd_lookup(uint16_t info);
+const char *nbd_reply_type_lookup(uint16_t type);
const char *nbd_err_lookup(int err);
int nbd_drop(QIOChannel *ioc, size_t size, Error **errp);
diff --git a/nbd/server.c b/nbd/server.c
index 459e00c..efb6003 100644
--- a/nbd/server.c
+++ b/nbd/server.c
@@ -40,6 +40,8 @@ static int system_errno_to_nbd_errno(int err)
case EFBIG:
case ENOSPC:
return NBD_ENOSPC;
+ case EOVERFLOW:
+ return NBD_EOVERFLOW;
case ESHUTDOWN:
return NBD_ESHUTDOWN;
case EINVAL: