get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 814904,
    "url": "http://patchwork.ozlabs.org/api/patches/814904/?format=api",
    "web_url": "http://patchwork.ozlabs.org/project/qemu-devel/patch/20170918124230.8152-5-pbutsykin@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": "<20170918124230.8152-5-pbutsykin@virtuozzo.com>",
    "list_archive_url": null,
    "date": "2017-09-18T12:42:30",
    "name": "[v8,4/4] qemu-iotests: add shrinking image test",
    "commit_ref": null,
    "pull_url": null,
    "state": "new",
    "archived": false,
    "hash": "4869da55b38c57497669dc8f84e4cc54e094c76f",
    "submitter": {
        "id": 67271,
        "url": "http://patchwork.ozlabs.org/api/people/67271/?format=api",
        "name": "Pavel Butsykin",
        "email": "pbutsykin@virtuozzo.com"
    },
    "delegate": null,
    "mbox": "http://patchwork.ozlabs.org/project/qemu-devel/patch/20170918124230.8152-5-pbutsykin@virtuozzo.com/mbox/",
    "series": [
        {
            "id": 3635,
            "url": "http://patchwork.ozlabs.org/api/series/3635/?format=api",
            "web_url": "http://patchwork.ozlabs.org/project/qemu-devel/list/?series=3635",
            "date": "2017-09-18T12:42:28",
            "name": "Add shrink image for qcow2",
            "version": 8,
            "mbox": "http://patchwork.ozlabs.org/series/3635/mbox/"
        }
    ],
    "comments": "http://patchwork.ozlabs.org/api/patches/814904/comments/",
    "check": "pending",
    "checks": "http://patchwork.ozlabs.org/api/patches/814904/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>)",
            "ozlabs.org;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=virtuozzo.com header.i=@virtuozzo.com\n\theader.b=\"Dql69krn\"; dkim-atps=neutral",
            "spf=none (sender IP is )\n\tsmtp.mailfrom=pbutsykin@virtuozzo.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 3xwm2h1BF2z9s78\n\tfor <incoming@patchwork.ozlabs.org>;\n\tMon, 18 Sep 2017 22:46:03 +1000 (AEST)",
            "from localhost ([::1]:36381 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 1dtvR2-0005Rd-Bs\n\tfor incoming@patchwork.ozlabs.org; Mon, 18 Sep 2017 08:46:00 -0400",
            "from eggs.gnu.org ([2001:4830:134:3::10]:33476)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <pbutsykin@virtuozzo.com>) id 1dtvOH-0003Tf-Bl\n\tfor qemu-devel@nongnu.org; Mon, 18 Sep 2017 08:43:13 -0400",
            "from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <pbutsykin@virtuozzo.com>) id 1dtvOD-0003U2-6c\n\tfor qemu-devel@nongnu.org; Mon, 18 Sep 2017 08:43:09 -0400",
            "from mail-eopbgr00138.outbound.protection.outlook.com\n\t([40.107.0.138]:27658\n\thelo=EUR02-AM5-obe.outbound.protection.outlook.com)\n\tby eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32)\n\t(Exim 4.71) (envelope-from <pbutsykin@virtuozzo.com>)\n\tid 1dtvO2-0003IH-PC; Mon, 18 Sep 2017 08:42:55 -0400",
            "from pavelb-Z68P-DS3.sw.ru (195.214.232.6) by\n\tDB6PR0802MB2549.eurprd08.prod.outlook.com (2603:10a6:4:a1::19) with\n\tMicrosoft SMTP Server (version=TLS1_2,\n\tcipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.35.12;\n\tMon, 18 Sep 2017 12:42:50 +0000"
        ],
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com;\n\ts=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version;\n\tbh=4b8KLvws7piRFKwocd1fAA3y6MAKVD5B09ZO5bOD2mA=;\n\tb=Dql69krngcV/kTAohWFDz+JCJhIEloX+UPbmaxMbgRdx34zC19v44+uhjrGYSYiJQGovksdvzUYZWxlwi6/iiUAKp/Q7at1fSkx8ibqRbwoejVq0hSt90VqTYW/zeqMJUu8HY8HoWjjg7roY/YQ/Iz/Fwz1x5dki16Ey1Cbsqes=",
        "From": "Pavel Butsykin <pbutsykin@virtuozzo.com>",
        "To": "qemu-block@nongnu.org,\n\tqemu-devel@nongnu.org",
        "Date": "Mon, 18 Sep 2017 15:42:30 +0300",
        "Message-Id": "<20170918124230.8152-5-pbutsykin@virtuozzo.com>",
        "X-Mailer": "git-send-email 2.14.1",
        "In-Reply-To": "<20170918124230.8152-1-pbutsykin@virtuozzo.com>",
        "References": "<20170918124230.8152-1-pbutsykin@virtuozzo.com>",
        "MIME-Version": "1.0",
        "Content-Type": "text/plain",
        "X-Originating-IP": "[195.214.232.6]",
        "X-ClientProxiedBy": "DB6PR0202CA0006.eurprd02.prod.outlook.com\n\t(2603:10a6:4:29::16) To DB6PR0802MB2549.eurprd08.prod.outlook.com\n\t(2603:10a6:4:a1::19)",
        "X-MS-PublicTrafficType": "Email",
        "X-MS-Office365-Filtering-Correlation-Id": "e290b776-9a68-4bea-4014-08d4fe92c696",
        "X-Microsoft-Antispam": "UriScan:; BCL:0; PCL:0;\n\tRULEID:(300000500095)(300135000095)(300000501095)(300135300095)(22001)(300000502095)(300135100095)(2017030254152)(300000503095)(300135400095)(201703131423075)(201703031133081)(201702281549075)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095);\n\tSRVR:DB6PR0802MB2549; ",
        "X-Microsoft-Exchange-Diagnostics": [
            "1; DB6PR0802MB2549;\n\t3:sB7XLFIoF/AG2+kySkfyQxfzEPtISSJzxeDav+/fXx08dK8bJZFYJsckwXUJKIDTD2xzkUNxhOxHpgcFJgqS6YE8wrgzAYDMgzvMtAUiNv6MQnBOlecZ8vHBYaS0rPMEqaKtVvEKzF/6hAUfM2y24SUqOYitD148UDHMBd290LnK8JKjbaBceeJOJPQK8W4xAaRT41CS6EapPXLOdJJUeQVM40u+G4AJXYXZB137drqSSAaZAzwzg/pIymVUiC2H;\n\t25:eEx03SNuDvdtfEyDKYXvHSXRlkcOMEZT/UZBlvup9/Zp3QJFj/8KXixLHOO4sdu/+ecitNJ30p5Bu73hDiAzWj4V3Fb/cR82T581ZgUDRwL/rloNLXbE/BUWNQg7HpWc143nEm25U1k+js3G/SAO+cULyzUj5d963epnbajuerEzN6Yyu9gr+InzBp1MuV4tdpODyfQj1UVB+VEvFDJjYNmnhXkm34XTGXvjSsVzBub1j6utq7wfcPZEPRbHlvnxf1DHlGYPdOlWSJQKqup8vGqBwRk3CLhgEZbAjfP1w11HaFwqoAwmZ32HGA/cX1ztbWI5juk6OosLrCKSgAkasQ==;\n\t31:cUQFp6E8wg28xEi4eTJIxVtcrUcHuMeg9D3jekdu8/zsfHrfFRRhHOWDgDruurMjfbxH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4k3iHL4DtTGXjidxF/tzBX1cJvmDuMFADTHUu88BkIZ+gGr1wAWPzwHn3LiJyyrysgfDECNbQZo8mXmS66eM57ZdmfiqOjXbmVpSXJ/tTr0KQDKlfJ2grGJWYkvONQ="
        ],
        "X-MS-TrafficTypeDiagnostic": "DB6PR0802MB2549:",
        "X-Exchange-Antispam-Report-Test": "UriScan:(250305191791016)(22074186197030);",
        "X-Microsoft-Antispam-PRVS": "<DB6PR0802MB2549EB483915FC46FD98EA91AC630@DB6PR0802MB2549.eurprd08.prod.outlook.com>",
        "X-Exchange-Antispam-Report-CFA-Test": "BCL:0; PCL:0;\n\tRULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(2401047)(5005006)(8121501046)(3002001)(10201501046)(93006095)(93001095)(100000703101)(100105400095)(6041248)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123562025)(20161123558100)(20161123564025)(20161123555025)(20161123560025)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095);\n\tSRVR:DB6PR0802MB2549; BCL:0; PCL:0;\n\tRULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095);\n\tSRVR:DB6PR0802MB2549; ",
        "X-Forefront-PRVS": "04347F8039",
        "X-Forefront-Antispam-Report": "SFV:NSPM;\n\tSFS:(10019020)(7370300001)(4630300001)(6009001)(346002)(376002)(39830400002)(199003)(189002)(36756003)(48376002)(105586002)(50466002)(107886003)(101416001)(110136004)(53416004)(50226002)(25786009)(305945005)(7736002)(53936002)(81156014)(4326008)(81166006)(6666003)(5003940100001)(68736007)(2906002)(8676002)(6506006)(3846002)(6306002)(86362001)(478600001)(6486002)(6512007)(1076002)(6116002)(50986999)(76176999)(47776003)(2950100002)(33646002)(16586007)(7350300001)(97736004)(16526017)(106356001)(316002)(5660300001)(66066001)(69596002)(189998001)(2004002);\n\tDIR:OUT; SFP:1102; SCL:1; SRVR:DB6PR0802MB2549;\n\tH:pavelb-Z68P-DS3.sw.ru; FPR:; SPF:None; PTR:InfoNoRecords; A:1;\n\tMX:1; LANG:en; ",
        "Received-SPF": "None (protection.outlook.com: virtuozzo.com does not designate\n\tpermitted sender hosts)",
        "SpamDiagnosticOutput": "1:99",
        "SpamDiagnosticMetadata": "NSPM",
        "X-OriginatorOrg": "virtuozzo.com",
        "X-MS-Exchange-CrossTenant-OriginalArrivalTime": "18 Sep 2017 12:42:50.8842\n\t(UTC)",
        "X-MS-Exchange-CrossTenant-FromEntityHeader": "Hosted",
        "X-MS-Exchange-Transport-CrossTenantHeadersStamped": "DB6PR0802MB2549",
        "X-detected-operating-system": "by eggs.gnu.org: Windows 7 or 8 [fuzzy]",
        "X-Received-From": "40.107.0.138",
        "Subject": "[Qemu-devel] [PATCH v8 4/4] qemu-iotests: add shrinking image test",
        "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, pbutsykin@virtuozzo.com, jsnow@redhat.com,\n\tarmbru@redhat.com, mreitz@redhat.com, den@openvz.org",
        "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: Pavel Butsykin <pbutsykin@virtuozzo.com>\nReviewed-by: Max Reitz <mreitz@redhat.com>\nReviewed-by: John Snow <jsnow@redhat.com>\n---\n tests/qemu-iotests/163     | 170 +++++++++++++++++++++++++++++++++++++++++++++\n tests/qemu-iotests/163.out |   5 ++\n tests/qemu-iotests/group   |   1 +\n 3 files changed, 176 insertions(+)\n create mode 100644 tests/qemu-iotests/163\n create mode 100644 tests/qemu-iotests/163.out",
    "diff": "diff --git a/tests/qemu-iotests/163 b/tests/qemu-iotests/163\nnew file mode 100644\nindex 0000000000..403842354e\n--- /dev/null\n+++ b/tests/qemu-iotests/163\n@@ -0,0 +1,170 @@\n+#!/usr/bin/env python\n+#\n+# Tests for shrinking images\n+#\n+# Copyright (c) 2016-2017 Parallels International GmbH\n+#\n+# This program is free software; you can redistribute it and/or modify\n+# it under the terms of the GNU General Public License as published by\n+# the Free Software Foundation; either version 2 of the License, or\n+# (at your option) any later version.\n+#\n+# This program is distributed in the hope that it will be useful,\n+# but WITHOUT ANY WARRANTY; without even the implied warranty of\n+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+# GNU General Public License for more details.\n+#\n+# You should have received a copy of the GNU General Public License\n+# along with this program.  If not, see <http://www.gnu.org/licenses/>.\n+#\n+\n+import os, random, iotests, struct, qcow2\n+from iotests import qemu_img, qemu_io, image_size\n+\n+test_img = os.path.join(iotests.test_dir, 'test.img')\n+check_img = os.path.join(iotests.test_dir, 'check.img')\n+\n+def size_to_int(str):\n+    suff = ['B', 'K', 'M', 'G', 'T']\n+    return int(str[:-1]) * 1024**suff.index(str[-1:])\n+\n+class ShrinkBaseClass(iotests.QMPTestCase):\n+    image_len = '128M'\n+    shrink_size = '10M'\n+    chunk_size = '16M'\n+    refcount_bits = '16'\n+\n+    def __qcow2_check(self, filename):\n+        entry_bits = 3\n+        entry_size = 1 << entry_bits\n+        l1_mask = 0x00fffffffffffe00\n+        div_roundup = lambda n, d: (n + d - 1) / d\n+\n+        def split_by_n(data, n):\n+            for x in xrange(0, len(data), n):\n+                yield struct.unpack('>Q', data[x:x + n])[0] & l1_mask\n+\n+        def check_l1_table(h, l1_data):\n+            l1_list = list(split_by_n(l1_data, entry_size))\n+            real_l1_size = div_roundup(h.size,\n+                                       1 << (h.cluster_bits*2 - entry_size))\n+            used, unused = l1_list[:real_l1_size], l1_list[real_l1_size:]\n+\n+            self.assertTrue(len(used) != 0, \"Verifying l1 table content\")\n+            self.assertFalse(any(unused), \"Verifying l1 table content\")\n+\n+        def check_reftable(fd, h, reftable):\n+            for offset in split_by_n(reftable, entry_size):\n+                if offset != 0:\n+                    fd.seek(offset)\n+                    cluster = fd.read(1 << h.cluster_bits)\n+                    self.assertTrue(any(cluster), \"Verifying reftable content\")\n+\n+        with open(filename, \"rb\") as fd:\n+            h = qcow2.QcowHeader(fd)\n+\n+            fd.seek(h.l1_table_offset)\n+            l1_table = fd.read(h.l1_size << entry_bits)\n+\n+            fd.seek(h.refcount_table_offset)\n+            reftable = fd.read(h.refcount_table_clusters << h.cluster_bits)\n+\n+            check_l1_table(h, l1_table)\n+            check_reftable(fd, h, reftable)\n+\n+    def __raw_check(self, filename):\n+        pass\n+\n+    image_check = {\n+        'qcow2' : __qcow2_check,\n+        'raw' : __raw_check\n+    }\n+\n+    def setUp(self):\n+        if iotests.imgfmt == 'raw':\n+            qemu_img('create', '-f', iotests.imgfmt, test_img, self.image_len)\n+            qemu_img('create', '-f', iotests.imgfmt, check_img,\n+                     self.shrink_size)\n+        else:\n+            qemu_img('create', '-f', iotests.imgfmt,\n+                     '-o', 'cluster_size=' + self.cluster_size +\n+                     ',refcount_bits=' + self.refcount_bits,\n+                     test_img, self.image_len)\n+            qemu_img('create', '-f', iotests.imgfmt,\n+                     '-o', 'cluster_size=%s'% self.cluster_size,\n+                     check_img, self.shrink_size)\n+        qemu_io('-c', 'write -P 0xff 0 ' + self.shrink_size, check_img)\n+\n+    def tearDown(self):\n+        os.remove(test_img)\n+        os.remove(check_img)\n+\n+    def image_verify(self):\n+        self.assertEqual(image_size(test_img), image_size(check_img),\n+                         \"Verifying image size\")\n+        self.image_check[iotests.imgfmt](self, test_img)\n+\n+        if iotests.imgfmt == 'raw':\n+            return\n+        self.assertEqual(qemu_img('check', test_img), 0,\n+                         \"Verifying image corruption\")\n+\n+    def test_empty_image(self):\n+        qemu_img('resize',  '-f', iotests.imgfmt, '--shrink', test_img,\n+                 self.shrink_size)\n+\n+        self.assertEqual(\n+            qemu_io('-c', 'read -P 0x00 %s'%self.shrink_size, test_img),\n+            qemu_io('-c', 'read -P 0x00 %s'%self.shrink_size, check_img),\n+            \"Verifying image content\")\n+\n+        self.image_verify()\n+\n+    def test_sequential_write(self):\n+        for offs in range(0, size_to_int(self.image_len),\n+                          size_to_int(self.chunk_size)):\n+            qemu_io('-c', 'write -P 0xff %d %s' % (offs, self.chunk_size),\n+                    test_img)\n+\n+        qemu_img('resize',  '-f', iotests.imgfmt, '--shrink', test_img,\n+                 self.shrink_size)\n+\n+        self.assertEqual(qemu_img(\"compare\", test_img, check_img), 0,\n+                         \"Verifying image content\")\n+\n+        self.image_verify()\n+\n+    def test_random_write(self):\n+        offs_list = range(0, size_to_int(self.image_len),\n+                          size_to_int(self.chunk_size))\n+        random.shuffle(offs_list)\n+        for offs in offs_list:\n+            qemu_io('-c', 'write -P 0xff %d %s' % (offs, self.chunk_size),\n+                    test_img)\n+\n+        qemu_img('resize',  '-f', iotests.imgfmt, '--shrink', test_img,\n+                 self.shrink_size)\n+\n+        self.assertEqual(qemu_img(\"compare\", test_img, check_img), 0,\n+                         \"Verifying image content\")\n+\n+        self.image_verify()\n+\n+class TestShrink512(ShrinkBaseClass):\n+    image_len = '3M'\n+    shrink_size = '1M'\n+    chunk_size = '256K'\n+    cluster_size = '512'\n+    refcount_bits = '64'\n+\n+class TestShrink64K(ShrinkBaseClass):\n+    cluster_size = '64K'\n+\n+class TestShrink1M(ShrinkBaseClass):\n+    cluster_size = '1M'\n+    refcount_bits = '1'\n+\n+ShrinkBaseClass = None\n+\n+if __name__ == '__main__':\n+    iotests.main(supported_fmts=['raw', 'qcow2'])\ndiff --git a/tests/qemu-iotests/163.out b/tests/qemu-iotests/163.out\nnew file mode 100644\nindex 0000000000..dae404e278\n--- /dev/null\n+++ b/tests/qemu-iotests/163.out\n@@ -0,0 +1,5 @@\n+.........\n+----------------------------------------------------------------------\n+Ran 9 tests\n+\n+OK\ndiff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group\nindex 4bd5017008..82c38b403b 100644\n--- a/tests/qemu-iotests/group\n+++ b/tests/qemu-iotests/group\n@@ -166,6 +166,7 @@\n 159 rw auto quick\n 160 rw auto quick\n 162 auto quick\n+163 rw auto quick\n 165 rw auto quick\n 170 rw auto quick\n 171 rw auto quick\n",
    "prefixes": [
        "v8",
        "4/4"
    ]
}