{"id":831188,"url":"http://patchwork.ozlabs.org/api/1.2/patches/831188/?format=json","web_url":"http://patchwork.ozlabs.org/project/qemu-devel/patch/20171027104037.8319-4-eblake@redhat.com/","project":{"id":14,"url":"http://patchwork.ozlabs.org/api/1.2/projects/14/?format=json","name":"QEMU Development","link_name":"qemu-devel","list_id":"qemu-devel.nongnu.org","list_email":"qemu-devel@nongnu.org","web_url":"","scm_url":"","webscm_url":"","list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20171027104037.8319-4-eblake@redhat.com>","list_archive_url":null,"date":"2017-10-27T10:40:28","name":"[v6,03/12] nbd: Expose constants and structs for structured read","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"73e23280caef39a0ea20f601f4aba18e23fa9501","submitter":{"id":6591,"url":"http://patchwork.ozlabs.org/api/1.2/people/6591/?format=json","name":"Eric Blake","email":"eblake@redhat.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/qemu-devel/patch/20171027104037.8319-4-eblake@redhat.com/mbox/","series":[{"id":10552,"url":"http://patchwork.ozlabs.org/api/1.2/series/10552/?format=json","web_url":"http://patchwork.ozlabs.org/project/qemu-devel/list/?series=10552","date":"2017-10-27T10:40:27","name":"nbd minimal structured read","version":6,"mbox":"http://patchwork.ozlabs.org/series/10552/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/831188/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/831188/checks/","tags":{},"related":[],"headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=nongnu.org\n\t(client-ip=2001:4830:134:3::11; helo=lists.gnu.org;\n\tenvelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n\treceiver=<UNKNOWN>)","ext-mx07.extmail.prod.ext.phx2.redhat.com;\n\tdmarc=none (p=none dis=none) header.from=redhat.com","ext-mx07.extmail.prod.ext.phx2.redhat.com;\n\tspf=fail smtp.mailfrom=eblake@redhat.com"],"Received":["from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11])\n\t(using TLSv1 with cipher AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3yNgVJ2zMXz9t2d\n\tfor <incoming@patchwork.ozlabs.org>;\n\tFri, 27 Oct 2017 21:44:24 +1100 (AEDT)","from localhost ([::1]:56555 helo=lists.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.71) (envelope-from\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>)\n\tid 1e827i-0003n6-H8\n\tfor incoming@patchwork.ozlabs.org; Fri, 27 Oct 2017 06:44:22 -0400","from eggs.gnu.org ([2001:4830:134:3::10]:57216)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <eblake@redhat.com>) id 1e824N-0001Cc-OB\n\tfor qemu-devel@nongnu.org; Fri, 27 Oct 2017 06:40:57 -0400","from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <eblake@redhat.com>) id 1e824M-0005a7-At\n\tfor qemu-devel@nongnu.org; Fri, 27 Oct 2017 06:40:55 -0400","from mx1.redhat.com ([209.132.183.28]:42656)\n\tby eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32)\n\t(Exim 4.71) (envelope-from <eblake@redhat.com>)\n\tid 1e824H-0005Uu-9t; Fri, 27 Oct 2017 06:40:49 -0400","from smtp.corp.redhat.com\n\t(int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16])\n\t(using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby mx1.redhat.com (Postfix) with ESMTPS id 5B1A6C034E16;\n\tFri, 27 Oct 2017 10:40:48 +0000 (UTC)","from red.redhat.com (ovpn-120-166.rdu2.redhat.com [10.10.120.166])\n\tby smtp.corp.redhat.com (Postfix) with ESMTP id 8568E5C881;\n\tFri, 27 Oct 2017 10:40:46 +0000 (UTC)"],"DMARC-Filter":"OpenDMARC Filter v1.3.2 mx1.redhat.com 5B1A6C034E16","From":"Eric Blake <eblake@redhat.com>","To":"qemu-devel@nongnu.org","Date":"Fri, 27 Oct 2017 12:40:28 +0200","Message-Id":"<20171027104037.8319-4-eblake@redhat.com>","In-Reply-To":"<20171027104037.8319-1-eblake@redhat.com>","References":"<20171027104037.8319-1-eblake@redhat.com>","X-Scanned-By":"MIMEDefang 2.79 on 10.5.11.16","X-Greylist":"Sender IP whitelisted, not delayed by milter-greylist-4.5.16\n\t(mx1.redhat.com [10.5.110.31]);\n\tFri, 27 Oct 2017 10:40:48 +0000 (UTC)","X-detected-operating-system":"by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]\n\t[fuzzy]","X-Received-From":"209.132.183.28","Subject":"[Qemu-devel] [PATCH v6 03/12] nbd: Expose constants and structs for\n\tstructured read","X-BeenThere":"qemu-devel@nongnu.org","X-Mailman-Version":"2.1.21","Precedence":"list","List-Id":"<qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<http://lists.nongnu.org/archive/html/qemu-devel/>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Cc":"Kevin Wolf <kwolf@redhat.com>, pbonzini@redhat.com,\n\tvsementsov@virtuozzo.com, qemu-block@nongnu.org,\n\tMax Reitz <mreitz@redhat.com>","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"\"Qemu-devel\"\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>"},"content":"Upcoming patches will implement the NBD structured reply\nextension [1] for both client and server roles.  Declare the\nconstants, structs, and lookup routines that will be valuable\nwhether the server or client code is backported in isolation.\n\nThis includes moving one constant from an internal header to\nthe public header, as part of the structured read processing\nwill be done in block/nbd-client.c rather than nbd/client.c.\n\n[1]https://github.com/NetworkBlockDevice/nbd/blob/extension-structured-reply/doc/proto.md\n\nBased on patches from Vladimir Sementsov-Ogievskiy.\n\nSigned-off-by: Eric Blake <eblake@redhat.com>\nReviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>\n\n---\nv6: add R-b\n---\n include/block/nbd.h | 41 +++++++++++++++++++++++++++++++++++++++++\n nbd/nbd-internal.h  |  2 +-\n nbd/common.c        | 27 +++++++++++++++++++++++++++\n nbd/server.c        |  2 ++\n 4 files changed, 71 insertions(+), 1 deletion(-)","diff":"diff --git a/include/block/nbd.h b/include/block/nbd.h\nindex dc62b5cd19..225e9575e4 100644\n--- a/include/block/nbd.h\n+++ b/include/block/nbd.h\n@@ -69,6 +69,28 @@ typedef struct NBDSimpleReply {\n     uint64_t handle;\n } QEMU_PACKED NBDSimpleReply;\n\n+/* Header of all structured replies */\n+typedef struct NBDStructuredReplyChunk {\n+    uint32_t magic;  /* NBD_STRUCTURED_REPLY_MAGIC */\n+    uint16_t flags;  /* combination of NBD_REPLY_FLAG_* */\n+    uint16_t type;   /* NBD_REPLY_TYPE_* */\n+    uint64_t handle; /* request handle */\n+    uint32_t length; /* length of payload */\n+} QEMU_PACKED NBDStructuredReplyChunk;\n+\n+/* Header of NBD_REPLY_TYPE_OFFSET_DATA, complete NBD_REPLY_TYPE_OFFSET_HOLE */\n+typedef struct NBDStructuredRead {\n+    NBDStructuredReplyChunk h;\n+    uint64_t offset;\n+} QEMU_PACKED NBDStructuredRead;\n+\n+/* Header of all NBD_REPLY_TYPE_ERROR* errors */\n+typedef struct NBDStructuredError {\n+    NBDStructuredReplyChunk h;\n+    uint32_t error;\n+    uint16_t message_length;\n+} QEMU_PACKED NBDStructuredError;\n+\n /* Transmission (export) flags: sent from server to client during handshake,\n    but describe what will happen during transmission */\n #define NBD_FLAG_HAS_FLAGS         (1 << 0) /* Flags are there */\n@@ -79,6 +101,7 @@ typedef struct NBDSimpleReply {\n                                                rotational media */\n #define NBD_FLAG_SEND_TRIM         (1 << 5) /* Send TRIM (discard) */\n #define NBD_FLAG_SEND_WRITE_ZEROES (1 << 6) /* Send WRITE_ZEROES */\n+#define NBD_FLAG_SEND_DF           (1 << 7) /* Send DF (Do not Fragment) */\n\n /* New-style handshake (global) flags, sent from server to client, and\n    control what will happen during handshake phase. */\n@@ -125,6 +148,7 @@ typedef struct NBDSimpleReply {\n /* Request flags, sent from client to server during transmission phase */\n #define NBD_CMD_FLAG_FUA        (1 << 0) /* 'force unit access' during write */\n #define NBD_CMD_FLAG_NO_HOLE    (1 << 1) /* don't punch hole on zero run */\n+#define NBD_CMD_FLAG_DF         (1 << 2) /* don't fragment structured read */\n\n /* Supported request types */\n enum {\n@@ -149,6 +173,22 @@ enum {\n  * aren't overflowing some other buffer. */\n #define NBD_MAX_NAME_SIZE 256\n\n+/* Two types of reply structures */\n+#define NBD_SIMPLE_REPLY_MAGIC      0x67446698\n+#define NBD_STRUCTURED_REPLY_MAGIC  0x668e33ef\n+\n+/* Structured reply flags */\n+#define NBD_REPLY_FLAG_DONE          (1 << 0) /* This reply-chunk is last */\n+\n+/* Structured reply types */\n+#define NBD_REPLY_ERR(value)         ((1 << 15) | (value))\n+\n+#define NBD_REPLY_TYPE_NONE          0\n+#define NBD_REPLY_TYPE_OFFSET_DATA   1\n+#define NBD_REPLY_TYPE_OFFSET_HOLE   2\n+#define NBD_REPLY_TYPE_ERROR         NBD_REPLY_ERR(1)\n+#define NBD_REPLY_TYPE_ERROR_OFFSET  NBD_REPLY_ERR(2)\n+\n /* NBD errors are based on errno numbers, so there is a 1:1 mapping,\n  * but only a limited set of errno values is specified in the protocol.\n  * Everything else is squashed to EINVAL.\n@@ -159,6 +199,7 @@ enum {\n #define NBD_ENOMEM     12\n #define NBD_EINVAL     22\n #define NBD_ENOSPC     28\n+#define NBD_EOVERFLOW  75\n #define NBD_ESHUTDOWN  108\n\n /* Details collected by NBD_OPT_EXPORT_NAME and NBD_OPT_GO */\ndiff --git a/nbd/nbd-internal.h b/nbd/nbd-internal.h\nindex df6c8b2f24..4f24d6e57d 100644\n--- a/nbd/nbd-internal.h\n+++ b/nbd/nbd-internal.h\n@@ -47,7 +47,6 @@\n #define NBD_OLDSTYLE_NEGOTIATE_SIZE (8 + 8 + 8 + 4 + 124)\n\n #define NBD_REQUEST_MAGIC           0x25609513\n-#define NBD_SIMPLE_REPLY_MAGIC      0x67446698\n #define NBD_OPTS_MAGIC              0x49484156454F5054LL\n #define NBD_CLIENT_MAGIC            0x0000420281861253LL\n #define NBD_REP_MAGIC               0x0003e889045565a9LL\n@@ -114,6 +113,7 @@ const char *nbd_opt_lookup(uint32_t opt);\n const char *nbd_rep_lookup(uint32_t rep);\n const char *nbd_info_lookup(uint16_t info);\n const char *nbd_cmd_lookup(uint16_t info);\n+const char *nbd_reply_type_lookup(uint16_t type);\n const char *nbd_err_lookup(int err);\n\n int nbd_drop(QIOChannel *ioc, size_t size, Error **errp);\ndiff --git a/nbd/common.c b/nbd/common.c\nindex 593904f148..6047d71748 100644\n--- a/nbd/common.c\n+++ b/nbd/common.c\n@@ -151,6 +151,28 @@ const char *nbd_cmd_lookup(uint16_t cmd)\n }\n\n\n+const char *nbd_reply_type_lookup(uint16_t type)\n+{\n+    switch (type) {\n+    case NBD_REPLY_TYPE_NONE:\n+        return \"none\";\n+    case NBD_REPLY_TYPE_OFFSET_DATA:\n+        return \"data\";\n+    case NBD_REPLY_TYPE_OFFSET_HOLE:\n+        return \"hole\";\n+    case NBD_REPLY_TYPE_ERROR:\n+        return \"generic error\";\n+    case NBD_REPLY_TYPE_ERROR_OFFSET:\n+        return \"error at offset\";\n+    default:\n+        if (type & (1 << 15)) {\n+            return \"<unknown error>\";\n+        }\n+        return \"<unknown>\";\n+    }\n+}\n+\n+\n const char *nbd_err_lookup(int err)\n {\n     switch (err) {\n@@ -166,6 +188,8 @@ const char *nbd_err_lookup(int err)\n         return \"EINVAL\";\n     case NBD_ENOSPC:\n         return \"ENOSPC\";\n+    case NBD_EOVERFLOW:\n+        return \"EOVERFLOW\";\n     case NBD_ESHUTDOWN:\n         return \"ESHUTDOWN\";\n     default:\n@@ -193,6 +217,9 @@ int nbd_errno_to_system_errno(int err)\n     case NBD_ENOSPC:\n         ret = ENOSPC;\n         break;\n+    case NBD_EOVERFLOW:\n+        ret = EOVERFLOW;\n+        break;\n     case NBD_ESHUTDOWN:\n         ret = ESHUTDOWN;\n         break;\ndiff --git a/nbd/server.c b/nbd/server.c\nindex 459e00c553..efb6003364 100644\n--- a/nbd/server.c\n+++ b/nbd/server.c\n@@ -40,6 +40,8 @@ static int system_errno_to_nbd_errno(int err)\n     case EFBIG:\n     case ENOSPC:\n         return NBD_ENOSPC;\n+    case EOVERFLOW:\n+        return NBD_EOVERFLOW;\n     case ESHUTDOWN:\n         return NBD_ESHUTDOWN;\n     case EINVAL:\n","prefixes":["v6","03/12"]}