summaryrefslogtreecommitdiff
path: root/nbd/common.c
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/common.c
parentdd6894404947d39a724ea265389fe0f2d6d5ecb7 (diff)
downloadqemu-bae245d19a7fae77410cb8b09350b672df689a66.tar.gz
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/common.c')
-rw-r--r--nbd/common.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/nbd/common.c b/nbd/common.c
index 593904f148..6047d71748 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;