get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

GET /api/patches/818252/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 818252,
    "url": "http://patchwork.ozlabs.org/api/patches/818252/?format=api",
    "web_url": "http://patchwork.ozlabs.org/project/qemu-devel/patch/20170925135801.144261-7-vsementsov@virtuozzo.com/",
    "project": {
        "id": 14,
        "url": "http://patchwork.ozlabs.org/api/projects/14/?format=api",
        "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": "<20170925135801.144261-7-vsementsov@virtuozzo.com>",
    "list_archive_url": null,
    "date": "2017-09-25T13:57:59",
    "name": "[6/8] nbd: Minimal structured read for server",
    "commit_ref": null,
    "pull_url": null,
    "state": "new",
    "archived": false,
    "hash": "3af3ad2f6ad08979c49b157fb77847815c4b9c71",
    "submitter": {
        "id": 66592,
        "url": "http://patchwork.ozlabs.org/api/people/66592/?format=api",
        "name": "Vladimir Sementsov-Ogievskiy",
        "email": "vsementsov@virtuozzo.com"
    },
    "delegate": null,
    "mbox": "http://patchwork.ozlabs.org/project/qemu-devel/patch/20170925135801.144261-7-vsementsov@virtuozzo.com/mbox/",
    "series": [
        {
            "id": 4967,
            "url": "http://patchwork.ozlabs.org/api/series/4967/?format=api",
            "web_url": "http://patchwork.ozlabs.org/project/qemu-devel/list/?series=4967",
            "date": "2017-09-25T13:58:01",
            "name": "nbd minimal structured read",
            "version": 1,
            "mbox": "http://patchwork.ozlabs.org/series/4967/mbox/"
        }
    ],
    "comments": "http://patchwork.ozlabs.org/api/patches/818252/comments/",
    "check": "pending",
    "checks": "http://patchwork.ozlabs.org/api/patches/818252/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>)",
        "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 3y15LW4qDgz9tXC\n\tfor <incoming@patchwork.ozlabs.org>;\n\tMon, 25 Sep 2017 23:59:47 +1000 (AEST)",
            "from localhost ([::1]:42574 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 1dwTvF-00074B-N6\n\tfor incoming@patchwork.ozlabs.org; Mon, 25 Sep 2017 09:59:45 -0400",
            "from eggs.gnu.org ([2001:4830:134:3::10]:39657)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <vsementsov@virtuozzo.com>) id 1dwTtz-0006YZ-KV\n\tfor qemu-devel@nongnu.org; Mon, 25 Sep 2017 09:58:29 -0400",
            "from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <vsementsov@virtuozzo.com>) id 1dwTtv-0007DW-RN\n\tfor qemu-devel@nongnu.org; Mon, 25 Sep 2017 09:58:27 -0400",
            "from mailhub.sw.ru ([195.214.232.25]:33731 helo=relay.sw.ru)\n\tby eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32)\n\t(Exim 4.71) (envelope-from <vsementsov@virtuozzo.com>)\n\tid 1dwTtv-0007C2-An\n\tfor qemu-devel@nongnu.org; Mon, 25 Sep 2017 09:58:23 -0400",
            "from kvm.sw.ru (msk-vpn.virtuozzo.com [195.214.232.6])\n\tby relay.sw.ru (8.13.4/8.13.4) with ESMTP id v8PDw1fw013085;\n\tMon, 25 Sep 2017 16:58:03 +0300 (MSK)"
        ],
        "From": "Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>",
        "To": "qemu-devel@nongnu.org, qemu-block@nongnu.org",
        "Date": "Mon, 25 Sep 2017 16:57:59 +0300",
        "Message-Id": "<20170925135801.144261-7-vsementsov@virtuozzo.com>",
        "X-Mailer": "git-send-email 2.11.1",
        "In-Reply-To": "<20170925135801.144261-1-vsementsov@virtuozzo.com>",
        "References": "<20170925135801.144261-1-vsementsov@virtuozzo.com>",
        "X-detected-operating-system": "by eggs.gnu.org: OpenBSD 3.x [fuzzy]",
        "X-Received-From": "195.214.232.25",
        "Subject": "[Qemu-devel] [PATCH 6/8] nbd: Minimal structured read for server",
        "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": "kwolf@redhat.com, vsementsov@virtuozzo.com, Hmreitz@redhat.com,\n\tden@openvz.org, pbonzini@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": "Minimal implementation of structured read: one structured reply chunk,\nno segmentation.\nMinimal structured error implementation: no text message.\nSupport DF flag, but just ignore it, as there is no segmentation any\nway.\n\nSigned-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>\n---\n include/block/nbd.h |  31 ++++++++++++++++\n nbd/nbd-internal.h  |   1 +\n nbd/server.c        | 100 ++++++++++++++++++++++++++++++++++++++++++++++++----\n 3 files changed, 126 insertions(+), 6 deletions(-)",
    "diff": "diff --git a/include/block/nbd.h b/include/block/nbd.h\nindex a6df5ce8b5..314f2f9bbc 100644\n--- a/include/block/nbd.h\n+++ b/include/block/nbd.h\n@@ -69,6 +69,25 @@ typedef struct NBDSimpleReply {\n     uint64_t handle;\n } QEMU_PACKED NBDSimpleReply;\n \n+typedef struct NBDStructuredReplyChunk {\n+    uint32_t magic;  /* NBD_STRUCTURED_REPLY_MAGIC */\n+    uint16_t flags;  /* combination of NBD_SREP_FLAG_* */\n+    uint16_t type;   /* NBD_SREP_TYPE_* */\n+    uint64_t handle; /* request handle */\n+    uint32_t length; /* length of payload */\n+} QEMU_PACKED NBDStructuredReplyChunk;\n+\n+typedef struct NBDStructuredRead {\n+    NBDStructuredReplyChunk h;\n+    uint64_t offset;\n+} QEMU_PACKED NBDStructuredRead;\n+\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 +98,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 +145,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 +170,16 @@ enum {\n  * aren't overflowing some other buffer. */\n #define NBD_MAX_NAME_SIZE 256\n \n+/* Structured reply flags */\n+#define NBD_SREP_FLAG_DONE          (1 << 0) /* This reply-chunk is last */\n+\n+/* Structured reply types */\n+#define NBD_SREP_ERR(value)         ((1 << 15) | (value))\n+\n+#define NBD_SREP_TYPE_NONE          0\n+#define NBD_SREP_TYPE_OFFSET_DATA   1\n+#define NBD_SREP_TYPE_ERROR         NBD_SREP_ERR(1)\n+\n /* Details collected by NBD_OPT_EXPORT_NAME and NBD_OPT_GO */\n struct NBDExportInfo {\n     /* Set by client before nbd_receive_negotiate() */\ndiff --git a/nbd/nbd-internal.h b/nbd/nbd-internal.h\nindex d96c9cc7fd..6b0d1183ba 100644\n--- a/nbd/nbd-internal.h\n+++ b/nbd/nbd-internal.h\n@@ -48,6 +48,7 @@\n \n #define NBD_REQUEST_MAGIC           0x25609513\n #define NBD_SIMPLE_REPLY_MAGIC      0x67446698\n+#define NBD_STRUCTURED_REPLY_MAGIC  0x668e33ef\n #define NBD_OPTS_MAGIC              0x49484156454F5054LL\n #define NBD_CLIENT_MAGIC            0x0000420281861253LL\n #define NBD_REP_MAGIC               0x0003e889045565a9LL\ndiff --git a/nbd/server.c b/nbd/server.c\nindex 57d5598e0f..0af94a293d 100644\n--- a/nbd/server.c\n+++ b/nbd/server.c\n@@ -98,6 +98,8 @@ struct NBDClient {\n     QTAILQ_ENTRY(NBDClient) next;\n     int nb_requests;\n     bool closing;\n+\n+    bool structured_reply;\n };\n \n /* That's all folks */\n@@ -760,6 +762,20 @@ static int nbd_negotiate_options(NBDClient *client, uint16_t myflags,\n                     return ret;\n                 }\n                 break;\n+\n+            case NBD_OPT_STRUCTURED_REPLY:\n+                if (client->structured_reply) {\n+                    error_setg(errp, \"Double negotiation of structured reply\");\n+                    return -EINVAL;\n+                }\n+                ret = nbd_negotiate_send_rep(client->ioc, NBD_REP_ACK, option,\n+                                             errp);\n+                if (ret < 0) {\n+                    return ret;\n+                }\n+                client->structured_reply = true;\n+                break;\n+\n             default:\n                 if (nbd_drop(client->ioc, length, errp) < 0) {\n                     return -EIO;\n@@ -1233,6 +1249,61 @@ static int nbd_co_send_simple_reply(NBDClient *client,\n     return nbd_co_send_iov(client, iov, size ? 2 : 1, errp);\n }\n \n+static inline void set_be_chunk(NBDStructuredReplyChunk *chunk, uint16_t flags,\n+                                uint16_t type, uint64_t handle, uint32_t length)\n+{\n+    stl_be_p(&chunk->magic, NBD_STRUCTURED_REPLY_MAGIC);\n+    stw_be_p(&chunk->flags, flags);\n+    stw_be_p(&chunk->type, type);\n+    stq_be_p(&chunk->handle, handle);\n+    stl_be_p(&chunk->length, length);\n+}\n+\n+static inline int coroutine_fn nbd_co_send_buf(NBDClient *client, void *buf,\n+                                               size_t size, Error **errp)\n+{\n+    struct iovec iov[] = {\n+        {.iov_base = buf, .iov_len = size}\n+    };\n+\n+    return nbd_co_send_iov(client, iov, 1, errp);\n+}\n+\n+static int coroutine_fn nbd_co_send_structured_read(NBDClient *client,\n+                                                    uint64_t handle,\n+                                                    uint64_t offset,\n+                                                    void *data,\n+                                                    size_t size,\n+                                                    Error **errp)\n+{\n+    NBDStructuredRead chunk;\n+    struct iovec iov[] = {\n+        {.iov_base = &chunk, .iov_len = sizeof(chunk)},\n+        {.iov_base = data, .iov_len = size}\n+    };\n+\n+    set_be_chunk(&chunk.h, NBD_SREP_FLAG_DONE, NBD_SREP_TYPE_OFFSET_DATA,\n+                 handle, sizeof(chunk) - sizeof(chunk.h) + size);\n+    stq_be_p(&chunk.offset, offset);\n+\n+    return nbd_co_send_iov(client, iov, 2, errp);\n+}\n+\n+static int coroutine_fn nbd_co_send_structured_error(NBDClient *client,\n+                                                     uint64_t handle,\n+                                                     uint32_t error,\n+                                                     Error **errp)\n+{\n+    NBDStructuredError chunk;\n+\n+    set_be_chunk(&chunk.h, NBD_SREP_FLAG_DONE, NBD_SREP_TYPE_ERROR, handle,\n+                 sizeof(chunk) - sizeof(chunk.h));\n+    stl_be_p(&chunk.error, error);\n+    stw_be_p(&chunk.message_length, 0);\n+\n+    return nbd_co_send_buf(client, &chunk, sizeof(chunk), errp);\n+}\n+\n /* nbd_co_receive_request\n  * Collect a client request. Return 0 if request looks valid, -EIO to drop\n  * connection right away, and any other negative value to report an error to\n@@ -1304,10 +1375,17 @@ static int nbd_co_receive_request(NBDRequestData *req, NBDRequest *request,\n                    (uint64_t)client->exp->size);\n         return request->type == NBD_CMD_WRITE ? -ENOSPC : -EINVAL;\n     }\n-    if (request->flags & ~(NBD_CMD_FLAG_FUA | NBD_CMD_FLAG_NO_HOLE)) {\n+    if (request->flags & ~(NBD_CMD_FLAG_FUA | NBD_CMD_FLAG_NO_HOLE |\n+                           NBD_CMD_FLAG_DF))\n+    {\n         error_setg(errp, \"unsupported flags (got 0x%x)\", request->flags);\n         return -EINVAL;\n     }\n+    if (request->type != NBD_CMD_READ && (request->flags & NBD_CMD_FLAG_DF)) {\n+        error_setg(errp, \"DF flag used with command %d (%s) which is not READ\",\n+                   request->type, nbd_cmd_lookup(request->type));\n+        return -EINVAL;\n+    }\n     if (request->type != NBD_CMD_WRITE_ZEROES &&\n         (request->flags & NBD_CMD_FLAG_NO_HOLE)) {\n         error_setg(errp, \"unexpected flags (got 0x%x)\", request->flags);\n@@ -1374,7 +1452,6 @@ static coroutine_fn void nbd_trip(void *opaque)\n         }\n \n         reply_data_len = request.len;\n-\n         break;\n     case NBD_CMD_WRITE:\n         if (exp->nbdflags & NBD_FLAG_READ_ONLY) {\n@@ -1447,10 +1524,21 @@ reply:\n         local_err = NULL;\n     }\n \n-    if (nbd_co_send_simple_reply(req->client, request.handle,\n-                                 ret < 0 ? -ret : 0,\n-                                 req->data, reply_data_len, &local_err) < 0)\n-    {\n+    if (client->structured_reply && request.type == NBD_CMD_READ) {\n+        if (ret < 0) {\n+            ret = nbd_co_send_structured_error(req->client, request.handle,\n+                                               -ret, &local_err);\n+        } else {\n+            ret = nbd_co_send_structured_read(req->client, request.handle,\n+                                              request.from, req->data,\n+                                              reply_data_len, &local_err);\n+        }\n+    } else {\n+        ret = nbd_co_send_simple_reply(req->client, request.handle,\n+                                       ret < 0 ? -ret : 0,\n+                                       req->data, reply_data_len, &local_err);\n+    }\n+    if (ret < 0) {\n         error_prepend(&local_err, \"Failed to send reply: \");\n         goto disconnect;\n     }\n",
    "prefixes": [
        "6/8"
    ]
}