get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 813526,
    "url": "http://patchwork.ozlabs.org/api/patches/813526/?format=api",
    "web_url": "http://patchwork.ozlabs.org/project/qemu-devel/patch/20170913160333.23622-14-eblake@redhat.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": "<20170913160333.23622-14-eblake@redhat.com>",
    "list_archive_url": null,
    "date": "2017-09-13T16:03:23",
    "name": "[v4,13/23] qemu-img: Simplify logic in img_compare()",
    "commit_ref": null,
    "pull_url": null,
    "state": "new",
    "archived": false,
    "hash": "91dd7902db07623e6e793e73c33304054de808d4",
    "submitter": {
        "id": 6591,
        "url": "http://patchwork.ozlabs.org/api/people/6591/?format=api",
        "name": "Eric Blake",
        "email": "eblake@redhat.com"
    },
    "delegate": null,
    "mbox": "http://patchwork.ozlabs.org/project/qemu-devel/patch/20170913160333.23622-14-eblake@redhat.com/mbox/",
    "series": [
        {
            "id": 2944,
            "url": "http://patchwork.ozlabs.org/api/series/2944/?format=api",
            "web_url": "http://patchwork.ozlabs.org/project/qemu-devel/list/?series=2944",
            "date": "2017-09-13T16:03:10",
            "name": "make bdrv_get_block_status byte-based",
            "version": 4,
            "mbox": "http://patchwork.ozlabs.org/series/2944/mbox/"
        }
    ],
    "comments": "http://patchwork.ozlabs.org/api/patches/813526/comments/",
    "check": "pending",
    "checks": "http://patchwork.ozlabs.org/api/patches/813526/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=208.118.235.17; helo=lists.gnu.org;\n\tenvelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n\treceiver=<UNKNOWN>)",
            "ext-mx09.extmail.prod.ext.phx2.redhat.com;\n\tdmarc=none (p=none dis=none) header.from=redhat.com",
            "ext-mx09.extmail.prod.ext.phx2.redhat.com;\n\tspf=fail smtp.mailfrom=eblake@redhat.com"
        ],
        "Received": [
            "from lists.gnu.org (lists.gnu.org [208.118.235.17])\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 3xsn3K2wd0z9sPk\n\tfor <incoming@patchwork.ozlabs.org>;\n\tThu, 14 Sep 2017 02:21:17 +1000 (AEST)",
            "from localhost ([::1]:43442 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 1dsAPb-0002bf-4y\n\tfor incoming@patchwork.ozlabs.org; Wed, 13 Sep 2017 12:21:15 -0400",
            "from eggs.gnu.org ([2001:4830:134:3::10]:46035)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <eblake@redhat.com>) id 1dsA9f-00021L-82\n\tfor qemu-devel@nongnu.org; Wed, 13 Sep 2017 12:04:50 -0400",
            "from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <eblake@redhat.com>) id 1dsA9Z-0006Jb-A5\n\tfor qemu-devel@nongnu.org; Wed, 13 Sep 2017 12:04:47 -0400",
            "from mx1.redhat.com ([209.132.183.28]:48448)\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 1dsA9Q-0006Dq-KZ; Wed, 13 Sep 2017 12:04:32 -0400",
            "from smtp.corp.redhat.com\n\t(int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11])\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 AFB034A6E4;\n\tWed, 13 Sep 2017 16:04:31 +0000 (UTC)",
            "from red.redhat.com (ovpn-120-201.rdu2.redhat.com [10.10.120.201])\n\tby smtp.corp.redhat.com (Postfix) with ESMTP id 426FB5C47C;\n\tWed, 13 Sep 2017 16:04:28 +0000 (UTC)"
        ],
        "DMARC-Filter": "OpenDMARC Filter v1.3.2 mx1.redhat.com AFB034A6E4",
        "From": "Eric Blake <eblake@redhat.com>",
        "To": "qemu-devel@nongnu.org",
        "Date": "Wed, 13 Sep 2017 11:03:23 -0500",
        "Message-Id": "<20170913160333.23622-14-eblake@redhat.com>",
        "In-Reply-To": "<20170913160333.23622-1-eblake@redhat.com>",
        "References": "<20170913160333.23622-1-eblake@redhat.com>",
        "X-Scanned-By": "MIMEDefang 2.79 on 10.5.11.11",
        "X-Greylist": "Sender IP whitelisted, not delayed by milter-greylist-4.5.16\n\t(mx1.redhat.com [10.5.110.38]);\n\tWed, 13 Sep 2017 16:04:31 +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 v4 13/23] qemu-img: Simplify logic in\n\timg_compare()",
        "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, jsnow@redhat.com, famz@redhat.com,\n\tqemu-block@nongnu.org, Max 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": "As long as we are querying the status for a chunk smaller than\nthe known image size, we are guaranteed that a successful return\nwill have set pnum to a non-zero size (pnum is zero only for\nqueries beyond the end of the file).  Use that to slightly\nsimplify the calculation of the current chunk size being compared.\nLikewise, we don't have to shrink the amount of data operated on\nuntil we know we have to read the file, and therefore have to fit\nin the bounds of our buffer.  Also, note that 'total_sectors_over'\nis equivalent to 'progress_base'.\n\nWith these changes in place, sectors_to_process() is now dead code,\nand can be removed.\n\nSigned-off-by: Eric Blake <eblake@redhat.com>\n\n---\nv3: new patch\n---\n qemu-img.c | 40 +++++++++++-----------------------------\n 1 file changed, 11 insertions(+), 29 deletions(-)",
    "diff": "diff --git a/qemu-img.c b/qemu-img.c\nindex b91133b922..f8423e9b3f 100644\n--- a/qemu-img.c\n+++ b/qemu-img.c\n@@ -1171,11 +1171,6 @@ static int64_t sectors_to_bytes(int64_t sectors)\n     return sectors << BDRV_SECTOR_BITS;\n }\n\n-static int64_t sectors_to_process(int64_t total, int64_t from)\n-{\n-    return MIN(total - from, IO_BUF_SIZE >> BDRV_SECTOR_BITS);\n-}\n-\n /*\n  * Check if passed sectors are empty (not allocated or contain only 0 bytes)\n  *\n@@ -1372,13 +1367,9 @@ static int img_compare(int argc, char **argv)\n         goto out;\n     }\n\n-    for (;;) {\n+    while (sector_num < total_sectors) {\n         int64_t status1, status2;\n\n-        nb_sectors = sectors_to_process(total_sectors, sector_num);\n-        if (nb_sectors <= 0) {\n-            break;\n-        }\n         status1 = bdrv_block_status_above(bs1, NULL,\n                                           sector_num * BDRV_SECTOR_SIZE,\n                                           (total_sectors1 - sector_num) *\n@@ -1402,14 +1393,9 @@ static int img_compare(int argc, char **argv)\n             goto out;\n         }\n         allocated2 = status2 & BDRV_BLOCK_ALLOCATED;\n-        if (pnum1) {\n-            nb_sectors = MIN(nb_sectors,\n-                             DIV_ROUND_UP(pnum1, BDRV_SECTOR_SIZE));\n-        }\n-        if (pnum2) {\n-            nb_sectors = MIN(nb_sectors,\n-                             DIV_ROUND_UP(pnum2, BDRV_SECTOR_SIZE));\n-        }\n+\n+        assert(pnum1 && pnum2);\n+        nb_sectors = DIV_ROUND_UP(MIN(pnum1, pnum2), BDRV_SECTOR_SIZE);\n\n         if (strict) {\n             if ((status1 & ~BDRV_BLOCK_OFFSET_MASK) !=\n@@ -1422,9 +1408,10 @@ static int img_compare(int argc, char **argv)\n             }\n         }\n         if ((status1 & BDRV_BLOCK_ZERO) && (status2 & BDRV_BLOCK_ZERO)) {\n-            nb_sectors = DIV_ROUND_UP(MIN(pnum1, pnum2), BDRV_SECTOR_SIZE);\n+            /* nothing to do */\n         } else if (allocated1 == allocated2) {\n             if (allocated1) {\n+                nb_sectors = MIN(nb_sectors, IO_BUF_SIZE >> BDRV_SECTOR_BITS);\n                 ret = blk_pread(blk1, sector_num << BDRV_SECTOR_BITS, buf1,\n                                 nb_sectors << BDRV_SECTOR_BITS);\n                 if (ret < 0) {\n@@ -1453,7 +1440,7 @@ static int img_compare(int argc, char **argv)\n                 }\n             }\n         } else {\n-\n+            nb_sectors = MIN(nb_sectors, IO_BUF_SIZE >> BDRV_SECTOR_BITS);\n             if (allocated1) {\n                 ret = check_empty_sectors(blk1, sector_num, nb_sectors,\n                                           filename1, buf1, quiet);\n@@ -1476,30 +1463,24 @@ static int img_compare(int argc, char **argv)\n\n     if (total_sectors1 != total_sectors2) {\n         BlockBackend *blk_over;\n-        int64_t total_sectors_over;\n         const char *filename_over;\n\n         qprintf(quiet, \"Warning: Image size mismatch!\\n\");\n         if (total_sectors1 > total_sectors2) {\n-            total_sectors_over = total_sectors1;\n             blk_over = blk1;\n             filename_over = filename1;\n         } else {\n-            total_sectors_over = total_sectors2;\n             blk_over = blk2;\n             filename_over = filename2;\n         }\n\n-        for (;;) {\n+        while (sector_num < progress_base) {\n             int64_t count;\n\n-            nb_sectors = sectors_to_process(total_sectors_over, sector_num);\n-            if (nb_sectors <= 0) {\n-                break;\n-            }\n             ret = bdrv_is_allocated_above(blk_bs(blk_over), NULL,\n                                           sector_num * BDRV_SECTOR_SIZE,\n-                                          nb_sectors * BDRV_SECTOR_SIZE,\n+                                          (progress_base - sector_num) *\n+                                          BDRV_SECTOR_SIZE,\n                                           &count);\n             if (ret < 0) {\n                 ret = 3;\n@@ -1513,6 +1494,7 @@ static int img_compare(int argc, char **argv)\n             assert(QEMU_IS_ALIGNED(count, BDRV_SECTOR_SIZE));\n             nb_sectors = count >> BDRV_SECTOR_BITS;\n             if (ret) {\n+                nb_sectors = MIN(nb_sectors, IO_BUF_SIZE >> BDRV_SECTOR_BITS);\n                 ret = check_empty_sectors(blk_over, sector_num, nb_sectors,\n                                           filename_over, buf1, quiet);\n                 if (ret) {\n",
    "prefixes": [
        "v4",
        "13/23"
    ]
}