get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 1307016,
    "url": "http://patchwork.ozlabs.org/api/patches/1307016/?format=api",
    "web_url": "http://patchwork.ozlabs.org/project/qemu-devel/patch/c07bba15ee7253bd08d67241bcd806938c70d3cf.1591801197.git.berto@igalia.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": "<c07bba15ee7253bd08d67241bcd806938c70d3cf.1591801197.git.berto@igalia.com>",
    "list_archive_url": null,
    "date": "2020-06-10T15:02:52",
    "name": "[v8,14/34] qcow2: Add QCow2SubclusterType and qcow2_get_subcluster_type()",
    "commit_ref": null,
    "pull_url": null,
    "state": "new",
    "archived": false,
    "hash": "1844dd882fd0d5df3e90f37a86599cf6eff84408",
    "submitter": {
        "id": 65704,
        "url": "http://patchwork.ozlabs.org/api/people/65704/?format=api",
        "name": "Alberto Garcia",
        "email": "berto@igalia.com"
    },
    "delegate": null,
    "mbox": "http://patchwork.ozlabs.org/project/qemu-devel/patch/c07bba15ee7253bd08d67241bcd806938c70d3cf.1591801197.git.berto@igalia.com/mbox/",
    "series": [
        {
            "id": 182563,
            "url": "http://patchwork.ozlabs.org/api/series/182563/?format=api",
            "web_url": "http://patchwork.ozlabs.org/project/qemu-devel/list/?series=182563",
            "date": "2020-06-10T15:02:49",
            "name": "Add subcluster allocation to qcow2",
            "version": 8,
            "mbox": "http://patchwork.ozlabs.org/series/182563/mbox/"
        }
    ],
    "comments": "http://patchwork.ozlabs.org/api/patches/1307016/comments/",
    "check": "pending",
    "checks": "http://patchwork.ozlabs.org/api/patches/1307016/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 spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org\n (client-ip=209.51.188.17; helo=lists.gnu.org;\n envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n receiver=<UNKNOWN>)",
            "ozlabs.org;\n dmarc=none (p=none dis=none) header.from=igalia.com",
            "ozlabs.org;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n unprotected) header.d=igalia.com header.i=@igalia.com header.a=rsa-sha256\n header.s=20170329 header.b=bUg7llAE;\n\tdkim-atps=neutral"
        ],
        "Received": [
            "from lists.gnu.org (lists.gnu.org [209.51.188.17])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 49hrCm3Y4Lz9sQx\n\tfor <incoming@patchwork.ozlabs.org>; Thu, 11 Jun 2020 01:15:47 +1000 (AEST)",
            "from localhost ([::1]:56296 helo=lists1p.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.90_1)\n\t(envelope-from <qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>)\n\tid 1jj2S7-0001o0-Ef\n\tfor incoming@patchwork.ozlabs.org; Wed, 10 Jun 2020 11:15:43 -0400",
            "from eggs.gnu.org ([2001:470:142:3::10]:36148)\n by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)\n (Exim 4.90_1) (envelope-from <berto@igalia.com>)\n id 1jj2Gw-0002iX-HV; Wed, 10 Jun 2020 11:04:10 -0400",
            "from fanzine.igalia.com ([178.60.130.6]:58106)\n by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)\n (Exim 4.90_1) (envelope-from <berto@igalia.com>)\n id 1jj2Gr-0006w4-8P; Wed, 10 Jun 2020 11:04:10 -0400",
            "from [81.0.38.199] (helo=perseus.local)\n by fanzine.igalia.com with esmtpsa\n (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim)\n id 1jj2GR-0007gu-Cv; Wed, 10 Jun 2020 17:03:39 +0200",
            "from berto by perseus.local with local (Exim 4.92)\n (envelope-from <berto@igalia.com>)\n id 1jj2GC-0007N0-2R; Wed, 10 Jun 2020 17:03:24 +0200"
        ],
        "DKIM-Signature": "v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com;\n s=20170329;\n h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From;\n bh=+DmjjyZHHWdutW0VaiL2W0gHvH6gXYupbWQx9py7wZo=;\n b=bUg7llAETu5/0/pZgn6NOsq+fq4U6JYoLHr4yJu0YAn8OuyWf1FENSMjpEpLPaQb/Qe/NYvjxfsP1GAn+81rPcwbWdBdkUdXbalOpvv6YlYYAlJx2+PVXDCw0mQrfhb+FbGck5bv1RUe5eF3/Jg7uAKsZ5AjxPl9io9HYk4WYDMxntltrZWyEiUaiHHUKkcCwwRP78KqFjCSZy5VXOJ5TmAWRNYxWIoxG9tgZ7GYsJ1MLjEUMjPafZYGGXC3FnQsGI+WeMrTBi5MgB6k/u8SoU+bcIMj0RwdngSuJnz4C65WePdJnXGagID6C4yw6ePAgC/8c2Smd5XIDRtN1aWztA==;",
        "From": "Alberto Garcia <berto@igalia.com>",
        "To": "qemu-devel@nongnu.org",
        "Subject": "[PATCH v8 14/34] qcow2: Add QCow2SubclusterType and\n qcow2_get_subcluster_type()",
        "Date": "Wed, 10 Jun 2020 17:02:52 +0200",
        "Message-Id": "\n <c07bba15ee7253bd08d67241bcd806938c70d3cf.1591801197.git.berto@igalia.com>",
        "X-Mailer": "git-send-email 2.20.1",
        "In-Reply-To": "<cover.1591801197.git.berto@igalia.com>",
        "References": "<cover.1591801197.git.berto@igalia.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Received-SPF": "pass client-ip=178.60.130.6; envelope-from=berto@igalia.com;\n helo=fanzine.igalia.com",
        "X-detected-operating-system": "by eggs.gnu.org: First seen = 2020/06/10 11:03:39",
        "X-ACL-Warn": "Detected OS   = Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy]",
        "X-Spam_score_int": "-20",
        "X-Spam_score": "-2.1",
        "X-Spam_bar": "--",
        "X-Spam_report": "(-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1,\n DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001,\n SPF_PASS=-0.001 autolearn=_AUTOLEARN",
        "X-Spam_action": "no action",
        "X-BeenThere": "qemu-devel@nongnu.org",
        "X-Mailman-Version": "2.1.23",
        "Precedence": "list",
        "List-Id": "<qemu-devel.nongnu.org>",
        "List-Unsubscribe": "<https://lists.nongnu.org/mailman/options/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>",
        "List-Archive": "<https://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 <mailto:qemu-devel-request@nongnu.org?subject=subscribe>",
        "Cc": "Kevin Wolf <kwolf@redhat.com>,\n Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>,\n Alberto Garcia <berto@igalia.com>, qemu-block@nongnu.org,\n Derek Su <dereksu@qnap.com>, Max Reitz <mreitz@redhat.com>",
        "Errors-To": "qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org",
        "Sender": "\"Qemu-devel\"\n <qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>"
    },
    "content": "This patch adds QCow2SubclusterType, which is the subcluster-level\nversion of QCow2ClusterType. All QCOW2_SUBCLUSTER_* values have the\nthe same meaning as their QCOW2_CLUSTER_* equivalents (when they\nexist). See below for details and caveats.\n\nIn images without extended L2 entries clusters are treated as having\nexactly one subcluster so it is possible to replace one data type with\nthe other while keeping the exact same semantics.\n\nWith extended L2 entries there are new possible values, and every\nsubcluster in the same cluster can obviously have a different\nQCow2SubclusterType so functions need to be adapted to work on the\nsubcluster level.\n\nThere are several things that have to be taken into account:\n\n  a) QCOW2_SUBCLUSTER_COMPRESSED means that the whole cluster is\n     compressed. We do not support compression at the subcluster\n     level.\n\n  b) There are two different values for unallocated subclusters:\n     QCOW2_SUBCLUSTER_UNALLOCATED_PLAIN which means that the whole\n     cluster is unallocated, and QCOW2_SUBCLUSTER_UNALLOCATED_ALLOC\n     which means that the cluster is allocated but the subcluster is\n     not. The latter can only happen in images with extended L2\n     entries.\n\n  c) QCOW2_SUBCLUSTER_INVALID is used to detect the cases where an L2\n     entry has a value that violates the specification. The caller is\n     responsible for handling these situations.\n\n     To prevent compatibility problems with images that have invalid\n     values but are currently being read by QEMU without causing side\n     effects, QCOW2_SUBCLUSTER_INVALID is only returned for images\n     with extended L2 entries.\n\nqcow2_cluster_to_subcluster_type() is added as a separate function\nfrom qcow2_get_subcluster_type(), but this is only temporary and both\nwill be merged in a subsequent patch.\n\nSigned-off-by: Alberto Garcia <berto@igalia.com>\nReviewed-by: Eric Blake <eblake@redhat.com>\n---\n block/qcow2.h | 126 +++++++++++++++++++++++++++++++++++++++++++++++++-\n 1 file changed, 125 insertions(+), 1 deletion(-)",
    "diff": "diff --git a/block/qcow2.h b/block/qcow2.h\nindex 82b86f6cec..3aec6f452a 100644\n--- a/block/qcow2.h\n+++ b/block/qcow2.h\n@@ -80,6 +80,21 @@\n \n #define QCOW_EXTL2_SUBCLUSTERS_PER_CLUSTER 32\n \n+/* The subcluster X [0..31] is allocated */\n+#define QCOW_OFLAG_SUB_ALLOC(X)   (1ULL << (X))\n+/* The subcluster X [0..31] reads as zeroes */\n+#define QCOW_OFLAG_SUB_ZERO(X)    (QCOW_OFLAG_SUB_ALLOC(X) << 32)\n+/* Subclusters [X, Y) (0 <= X <= Y <= 32) are allocated */\n+#define QCOW_OFLAG_SUB_ALLOC_RANGE(X, Y) \\\n+    (QCOW_OFLAG_SUB_ALLOC(Y) - QCOW_OFLAG_SUB_ALLOC(X))\n+/* Subclusters [X, Y) (0 <= X <= Y <= 32) read as zeroes */\n+#define QCOW_OFLAG_SUB_ZERO_RANGE(X, Y) \\\n+    (QCOW_OFLAG_SUB_ALLOC_RANGE(X, Y) << 32)\n+/* L2 entry bitmap with all allocation bits set */\n+#define QCOW_L2_BITMAP_ALL_ALLOC  (QCOW_OFLAG_SUB_ALLOC_RANGE(0, 32))\n+/* L2 entry bitmap with all \"read as zeroes\" bits set */\n+#define QCOW_L2_BITMAP_ALL_ZEROES (QCOW_OFLAG_SUB_ZERO_RANGE(0, 32))\n+\n /* Size of normal and extended L2 entries */\n #define L2E_SIZE_NORMAL   (sizeof(uint64_t))\n #define L2E_SIZE_EXTENDED (sizeof(uint64_t) * 2)\n@@ -462,6 +477,33 @@ typedef struct QCowL2Meta\n     QLIST_ENTRY(QCowL2Meta) next_in_flight;\n } QCowL2Meta;\n \n+/*\n+ * In images with standard L2 entries all clusters are treated as if\n+ * they had one subcluster so QCow2ClusterType and QCow2SubclusterType\n+ * can be mapped to each other and have the exact same meaning\n+ * (QCOW2_SUBCLUSTER_UNALLOCATED_ALLOC cannot happen in these images).\n+ *\n+ * In images with extended L2 entries QCow2ClusterType refers to the\n+ * complete cluster and QCow2SubclusterType to each of the individual\n+ * subclusters, so there are several possible combinations:\n+ *\n+ *     |--------------+---------------------------|\n+ *     | Cluster type | Possible subcluster types |\n+ *     |--------------+---------------------------|\n+ *     | UNALLOCATED  |         UNALLOCATED_PLAIN |\n+ *     |              |                ZERO_PLAIN |\n+ *     |--------------+---------------------------|\n+ *     | NORMAL       |         UNALLOCATED_ALLOC |\n+ *     |              |                ZERO_ALLOC |\n+ *     |              |                    NORMAL |\n+ *     |--------------+---------------------------|\n+ *     | COMPRESSED   |                COMPRESSED |\n+ *     |--------------+---------------------------|\n+ *\n+ * QCOW2_SUBCLUSTER_INVALID means that the L2 entry is incorrect and\n+ * the image should be marked corrupt.\n+ */\n+\n typedef enum QCow2ClusterType {\n     QCOW2_CLUSTER_UNALLOCATED,\n     QCOW2_CLUSTER_ZERO_PLAIN,\n@@ -470,6 +512,16 @@ typedef enum QCow2ClusterType {\n     QCOW2_CLUSTER_COMPRESSED,\n } QCow2ClusterType;\n \n+typedef enum QCow2SubclusterType {\n+    QCOW2_SUBCLUSTER_UNALLOCATED_PLAIN,\n+    QCOW2_SUBCLUSTER_UNALLOCATED_ALLOC,\n+    QCOW2_SUBCLUSTER_ZERO_PLAIN,\n+    QCOW2_SUBCLUSTER_ZERO_ALLOC,\n+    QCOW2_SUBCLUSTER_NORMAL,\n+    QCOW2_SUBCLUSTER_COMPRESSED,\n+    QCOW2_SUBCLUSTER_INVALID,\n+} QCow2SubclusterType;\n+\n typedef enum QCow2MetadataOverlap {\n     QCOW2_OL_MAIN_HEADER_BITNR      = 0,\n     QCOW2_OL_ACTIVE_L1_BITNR        = 1,\n@@ -634,9 +686,11 @@ static inline int64_t qcow2_vm_state_offset(BDRVQcow2State *s)\n static inline QCow2ClusterType qcow2_get_cluster_type(BlockDriverState *bs,\n                                                       uint64_t l2_entry)\n {\n+    BDRVQcow2State *s = bs->opaque;\n+\n     if (l2_entry & QCOW_OFLAG_COMPRESSED) {\n         return QCOW2_CLUSTER_COMPRESSED;\n-    } else if (l2_entry & QCOW_OFLAG_ZERO) {\n+    } else if ((l2_entry & QCOW_OFLAG_ZERO) && !has_subclusters(s)) {\n         if (l2_entry & L2E_OFFSET_MASK) {\n             return QCOW2_CLUSTER_ZERO_ALLOC;\n         }\n@@ -656,6 +710,76 @@ static inline QCow2ClusterType qcow2_get_cluster_type(BlockDriverState *bs,\n     }\n }\n \n+/*\n+ * For an image without extended L2 entries, return the\n+ * QCow2SubclusterType equivalent of a given QCow2ClusterType.\n+ */\n+static inline\n+QCow2SubclusterType qcow2_cluster_to_subcluster_type(QCow2ClusterType type)\n+{\n+    switch (type) {\n+    case QCOW2_CLUSTER_COMPRESSED:\n+        return QCOW2_SUBCLUSTER_COMPRESSED;\n+    case QCOW2_CLUSTER_ZERO_PLAIN:\n+        return QCOW2_SUBCLUSTER_ZERO_PLAIN;\n+    case QCOW2_CLUSTER_ZERO_ALLOC:\n+        return QCOW2_SUBCLUSTER_ZERO_ALLOC;\n+    case QCOW2_CLUSTER_NORMAL:\n+        return QCOW2_SUBCLUSTER_NORMAL;\n+    case QCOW2_CLUSTER_UNALLOCATED:\n+        return QCOW2_SUBCLUSTER_UNALLOCATED_PLAIN;\n+    default:\n+        g_assert_not_reached();\n+    }\n+}\n+\n+/*\n+ * In an image without subsclusters @l2_bitmap is ignored and\n+ * @sc_index must be 0.\n+ * Return QCOW2_SUBCLUSTER_INVALID if an invalid l2 entry is detected\n+ * (this checks the whole entry and bitmap, not only the bits related\n+ * to subcluster @sc_index).\n+ */\n+static inline\n+QCow2SubclusterType qcow2_get_subcluster_type(BlockDriverState *bs,\n+                                              uint64_t l2_entry,\n+                                              uint64_t l2_bitmap,\n+                                              unsigned sc_index)\n+{\n+    BDRVQcow2State *s = bs->opaque;\n+    QCow2ClusterType type = qcow2_get_cluster_type(bs, l2_entry);\n+    assert(sc_index < s->subclusters_per_cluster);\n+\n+    if (has_subclusters(s)) {\n+        switch (type) {\n+        case QCOW2_CLUSTER_COMPRESSED:\n+            return QCOW2_SUBCLUSTER_COMPRESSED;\n+        case QCOW2_CLUSTER_NORMAL:\n+            if ((l2_bitmap >> 32) & l2_bitmap) {\n+                return QCOW2_SUBCLUSTER_INVALID;\n+            } else if (l2_bitmap & QCOW_OFLAG_SUB_ZERO(sc_index)) {\n+                return QCOW2_SUBCLUSTER_ZERO_ALLOC;\n+            } else if (l2_bitmap & QCOW_OFLAG_SUB_ALLOC(sc_index)) {\n+                return QCOW2_SUBCLUSTER_NORMAL;\n+            } else {\n+                return QCOW2_SUBCLUSTER_UNALLOCATED_ALLOC;\n+            }\n+        case QCOW2_CLUSTER_UNALLOCATED:\n+            if (l2_bitmap & QCOW_L2_BITMAP_ALL_ALLOC) {\n+                return QCOW2_SUBCLUSTER_INVALID;\n+            } else if (l2_bitmap & QCOW_OFLAG_SUB_ZERO(sc_index)) {\n+                return QCOW2_SUBCLUSTER_ZERO_PLAIN;\n+            } else {\n+                return QCOW2_SUBCLUSTER_UNALLOCATED_PLAIN;\n+            }\n+        default:\n+            g_assert_not_reached();\n+        }\n+    } else {\n+        return qcow2_cluster_to_subcluster_type(type);\n+    }\n+}\n+\n /* Check whether refcounts are eager or lazy */\n static inline bool qcow2_need_accurate_refcounts(BDRVQcow2State *s)\n {\n",
    "prefixes": [
        "v8",
        "14/34"
    ]
}