get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 817493,
    "url": "http://patchwork.ozlabs.org/api/patches/817493/?format=api",
    "web_url": "http://patchwork.ozlabs.org/project/qemu-devel/patch/1506083624-20621-8-git-send-email-amarnath.valluri@intel.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": "<1506083624-20621-8-git-send-email-amarnath.valluri@intel.com>",
    "list_archive_url": null,
    "date": "2017-09-22T12:33:43",
    "name": "[v7,7/8] tpm-passthrough: move reusable code to utils",
    "commit_ref": null,
    "pull_url": null,
    "state": "new",
    "archived": false,
    "hash": "9e00670c6a00226b5b3ba2eb119f6847f7d9ff70",
    "submitter": {
        "id": 71320,
        "url": "http://patchwork.ozlabs.org/api/people/71320/?format=api",
        "name": "Valluri, Amarnath",
        "email": "amarnath.valluri@intel.com"
    },
    "delegate": null,
    "mbox": "http://patchwork.ozlabs.org/project/qemu-devel/patch/1506083624-20621-8-git-send-email-amarnath.valluri@intel.com/mbox/",
    "series": [
        {
            "id": 4614,
            "url": "http://patchwork.ozlabs.org/api/series/4614/?format=api",
            "web_url": "http://patchwork.ozlabs.org/project/qemu-devel/list/?series=4614",
            "date": "2017-09-22T12:33:37",
            "name": "Provide support for the software TPM emulator",
            "version": 7,
            "mbox": "http://patchwork.ozlabs.org/series/4614/mbox/"
        }
    ],
    "comments": "http://patchwork.ozlabs.org/api/patches/817493/comments/",
    "check": "pending",
    "checks": "http://patchwork.ozlabs.org/api/patches/817493/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 3xzCwx34kjz9s7p\n\tfor <incoming@patchwork.ozlabs.org>;\n\tFri, 22 Sep 2017 22:49:37 +1000 (AEST)",
            "from localhost ([::1]:58702 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 1dvNOh-00068m-GF\n\tfor incoming@patchwork.ozlabs.org; Fri, 22 Sep 2017 08:49:35 -0400",
            "from eggs.gnu.org ([2001:4830:134:3::10]:56613)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <amarnath.valluri@intel.com>) id 1dvN8j-0000lq-Sk\n\tfor qemu-devel@nongnu.org; Fri, 22 Sep 2017 08:33:13 -0400",
            "from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <amarnath.valluri@intel.com>) id 1dvN8d-00060A-VG\n\tfor qemu-devel@nongnu.org; Fri, 22 Sep 2017 08:33:05 -0400",
            "from mga07.intel.com ([134.134.136.100]:27337)\n\tby eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32)\n\t(Exim 4.71) (envelope-from <amarnath.valluri@intel.com>)\n\tid 1dvN8d-0005pe-KW\n\tfor qemu-devel@nongnu.org; Fri, 22 Sep 2017 08:32:59 -0400",
            "from fmsmga003.fm.intel.com ([10.253.24.29])\n\tby orsmga105.jf.intel.com with ESMTP; 22 Sep 2017 05:32:59 -0700",
            "from avallurigigabyte.fi.intel.com ([10.237.68.147])\n\tby FMSMGA003.fm.intel.com with ESMTP; 22 Sep 2017 05:32:57 -0700"
        ],
        "X-ExtLoop1": "1",
        "X-IronPort-AV": "E=Sophos;i=\"5.42,427,1500966000\"; d=\"scan'208\";a=\"902897877\"",
        "From": "Amarnath Valluri <amarnath.valluri@intel.com>",
        "To": "qemu-devel@nongnu.org",
        "Date": "Fri, 22 Sep 2017 15:33:43 +0300",
        "Message-Id": "<1506083624-20621-8-git-send-email-amarnath.valluri@intel.com>",
        "X-Mailer": "git-send-email 2.7.4",
        "In-Reply-To": "<1506083624-20621-1-git-send-email-amarnath.valluri@intel.com>",
        "References": "<1506083624-20621-1-git-send-email-amarnath.valluri@intel.com>",
        "MIME-Version": "1.0",
        "Content-Type": "text/plain; charset=UTF-8",
        "Content-Transfer-Encoding": "8bit",
        "X-detected-operating-system": "by eggs.gnu.org: Genre and OS details not\n\trecognized.",
        "X-Received-From": "134.134.136.100",
        "Subject": "[Qemu-devel] [PATCH v7 7/8] tpm-passthrough: move reusable code to\n\tutils",
        "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": "Amarnath Valluri <amarnath.valluri@intel.com>, =?utf-8?q?Marc-Andr?=\n\t=?utf-8?b?w6kgTHVyZWF1?= <marcandre.lureau@gmail.com>,\n\tStefan Berger <stefanb@linux.vnet.ibm.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": "Signed-off-by: Amarnath Valluri <amarnath.valluri@intel.com>\nReviewed-by: Stefan Berger <stefanb@linux.vnet.ibm.com>\nReviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>\n---\n hw/tpm/tpm_passthrough.c | 64 ++++--------------------------------------------\n hw/tpm/tpm_util.c        | 25 +++++++++++++++++++\n hw/tpm/tpm_util.h        |  4 +++\n 3 files changed, 34 insertions(+), 59 deletions(-)",
    "diff": "diff --git a/hw/tpm/tpm_passthrough.c b/hw/tpm/tpm_passthrough.c\nindex 82e7003..637a6e4 100644\n--- a/hw/tpm/tpm_passthrough.c\n+++ b/hw/tpm/tpm_passthrough.c\n@@ -68,27 +68,6 @@ typedef struct TPMPassthruState TPMPassthruState;\n \n static void tpm_passthrough_cancel_cmd(TPMBackend *tb);\n \n-static int tpm_passthrough_unix_write(int fd, const uint8_t *buf, uint32_t len)\n-{\n-    int ret, remain;\n-\n-    remain = len;\n-    while (remain > 0) {\n-        ret = write(fd, buf, remain);\n-        if (ret < 0) {\n-            if (errno != EINTR && errno != EAGAIN) {\n-                return -1;\n-            }\n-        } else if (ret == 0) {\n-            break;\n-        } else {\n-            buf += ret;\n-            remain -= ret;\n-        }\n-    }\n-    return len - remain;\n-}\n-\n static int tpm_passthrough_unix_read(int fd, uint8_t *buf, uint32_t len)\n {\n     int ret;\n@@ -102,45 +81,12 @@ static int tpm_passthrough_unix_read(int fd, uint8_t *buf, uint32_t len)\n     }\n     return ret;\n }\n-\n-static uint32_t tpm_passthrough_get_size_from_buffer(const uint8_t *buf)\n-{\n-    struct tpm_resp_hdr *resp = (struct tpm_resp_hdr *)buf;\n-\n-    return be32_to_cpu(resp->len);\n-}\n-\n-/*\n- * Write an error message in the given output buffer.\n- */\n-static void tpm_write_fatal_error_response(uint8_t *out, uint32_t out_len)\n-{\n-    if (out_len >= sizeof(struct tpm_resp_hdr)) {\n-        struct tpm_resp_hdr *resp = (struct tpm_resp_hdr *)out;\n-\n-        resp->tag = cpu_to_be16(TPM_TAG_RSP_COMMAND);\n-        resp->len = cpu_to_be32(sizeof(struct tpm_resp_hdr));\n-        resp->errcode = cpu_to_be32(TPM_FAIL);\n-    }\n-}\n-\n-static bool tpm_passthrough_is_selftest(const uint8_t *in, uint32_t in_len)\n-{\n-    struct tpm_req_hdr *hdr = (struct tpm_req_hdr *)in;\n-\n-    if (in_len >= sizeof(*hdr)) {\n-        return (be32_to_cpu(hdr->ordinal) == TPM_ORD_ContinueSelfTest);\n-    }\n-\n-    return false;\n-}\n-\n static int tpm_passthrough_unix_tx_bufs(TPMPassthruState *tpm_pt,\n                                         const uint8_t *in, uint32_t in_len,\n                                         uint8_t *out, uint32_t out_len,\n                                         bool *selftest_done)\n {\n-    int ret;\n+    ssize_t ret;\n     bool is_selftest;\n     const struct tpm_resp_hdr *hdr;\n \n@@ -148,9 +94,9 @@ static int tpm_passthrough_unix_tx_bufs(TPMPassthruState *tpm_pt,\n     tpm_pt->tpm_executing = true;\n     *selftest_done = false;\n \n-    is_selftest = tpm_passthrough_is_selftest(in, in_len);\n+    is_selftest = tpm_util_is_selftest(in, in_len);\n \n-    ret = tpm_passthrough_unix_write(tpm_pt->tpm_fd, in, in_len);\n+    ret = qemu_write_full(tpm_pt->tpm_fd, (const void *)in, (size_t)in_len);\n     if (ret != in_len) {\n         if (!tpm_pt->tpm_op_canceled || errno != ECANCELED) {\n             error_report(\"tpm_passthrough: error while transmitting data \"\n@@ -170,7 +116,7 @@ static int tpm_passthrough_unix_tx_bufs(TPMPassthruState *tpm_pt,\n                          strerror(errno), errno);\n         }\n     } else if (ret < sizeof(struct tpm_resp_hdr) ||\n-               tpm_passthrough_get_size_from_buffer(out) != ret) {\n+               be32_to_cpu(((struct tpm_resp_hdr *)out)->len) != ret) {\n         ret = -1;\n         error_report(\"tpm_passthrough: received invalid response \"\n                      \"packet from TPM\");\n@@ -183,7 +129,7 @@ static int tpm_passthrough_unix_tx_bufs(TPMPassthruState *tpm_pt,\n \n err_exit:\n     if (ret < 0) {\n-        tpm_write_fatal_error_response(out, out_len);\n+        tpm_util_write_fatal_error_response(out, out_len);\n     }\n \n     tpm_pt->tpm_executing = false;\ndiff --git a/hw/tpm/tpm_util.c b/hw/tpm/tpm_util.c\nindex 7b35429..fb929f6 100644\n--- a/hw/tpm/tpm_util.c\n+++ b/hw/tpm/tpm_util.c\n@@ -24,6 +24,31 @@\n #include \"tpm_int.h\"\n \n /*\n+ * Write an error message in the given output buffer.\n+ */\n+void tpm_util_write_fatal_error_response(uint8_t *out, uint32_t out_len)\n+{\n+    if (out_len >= sizeof(struct tpm_resp_hdr)) {\n+        struct tpm_resp_hdr *resp = (struct tpm_resp_hdr *)out;\n+\n+        resp->tag = cpu_to_be16(TPM_TAG_RSP_COMMAND);\n+        resp->len = cpu_to_be32(sizeof(struct tpm_resp_hdr));\n+        resp->errcode = cpu_to_be32(TPM_FAIL);\n+    }\n+}\n+\n+bool tpm_util_is_selftest(const uint8_t *in, uint32_t in_len)\n+{\n+    struct tpm_req_hdr *hdr = (struct tpm_req_hdr *)in;\n+\n+    if (in_len >= sizeof(*hdr)) {\n+        return (be32_to_cpu(hdr->ordinal) == TPM_ORD_ContinueSelfTest);\n+    }\n+\n+    return false;\n+}\n+\n+/*\n  * A basic test of a TPM device. We expect a well formatted response header\n  * (error response is fine) within one second.\n  */\ndiff --git a/hw/tpm/tpm_util.h b/hw/tpm/tpm_util.h\nindex df76245..2f7c961 100644\n--- a/hw/tpm/tpm_util.h\n+++ b/hw/tpm/tpm_util.h\n@@ -24,6 +24,10 @@\n \n #include \"sysemu/tpm_backend.h\"\n \n+void tpm_util_write_fatal_error_response(uint8_t *out, uint32_t out_len);\n+\n+bool tpm_util_is_selftest(const uint8_t *in, uint32_t in_len);\n+\n int tpm_util_test_tpmdev(int tpm_fd, TPMVersion *tpm_version);\n \n #endif /* TPM_TPM_UTIL_H */\n",
    "prefixes": [
        "v7",
        "7/8"
    ]
}