get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 1307032,
    "url": "http://patchwork.ozlabs.org/api/patches/1307032/?format=api",
    "web_url": "http://patchwork.ozlabs.org/project/qemu-devel/patch/aacf29b7a4c23558959d42228e691f928e5df8bb.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": "<aacf29b7a4c23558959d42228e691f928e5df8bb.1591801197.git.berto@igalia.com>",
    "list_archive_url": null,
    "date": "2020-06-10T15:03:06",
    "name": "[v8,28/34] qcow2: Add subcluster support to qcow2_co_pwrite_zeroes()",
    "commit_ref": null,
    "pull_url": null,
    "state": "new",
    "archived": false,
    "hash": "7526d3b6b67d32f3dcf074aaba0fa03cced78984",
    "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/aacf29b7a4c23558959d42228e691f928e5df8bb.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/1307032/comments/",
    "check": "pending",
    "checks": "http://patchwork.ozlabs.org/api/patches/1307032/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=REekFI+f;\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 49hrT15JGkz9sQx\n\tfor <incoming@patchwork.ozlabs.org>; Thu, 11 Jun 2020 01:27:17 +1000 (AEST)",
            "from localhost ([::1]:37940 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 1jj2dH-0002mQ-Bh\n\tfor incoming@patchwork.ozlabs.org; Wed, 10 Jun 2020 11:27:15 -0400",
            "from eggs.gnu.org ([2001:470:142:3::10]:36208)\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 1jj2H7-0002r2-8a; Wed, 10 Jun 2020 11:04:21 -0400",
            "from fanzine.igalia.com ([178.60.130.6]:58284)\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 1jj2Gs-0006wv-MB; Wed, 10 Jun 2020 11:04:20 -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-0007hF-UK; Wed, 10 Jun 2020 17:03:40 +0200",
            "from berto by perseus.local with local (Exim 4.92)\n (envelope-from <berto@igalia.com>)\n id 1jj2GC-0007Ni-GV; 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=CYYIsGbNfQ8aUWsdEewnnnQ2tWKfH0bSZ5YzfF9GsOE=;\n b=REekFI+fa3Y5hnnwqcRfRop5B0JnR25Qn4augQYYcwzdJ9oKtGfwMES0uTbdVUuwq937sQSjFK6gZn1VkItKQiilroox4oQ4fq9iv4kmDNdHCe/gcGGyy17hWPiTN6oN6PzbLkjzNZ+tN9oZAXBClqmqJLFpp0qQpi8gZtIsILDbFR3EqLcYe2bPkDE7fbIDnVEI9HZmO4YT+wi1FyAxmzFWIANdh9pSnKGfzgNBN31/ovXpxkTAc+Sv7ZKETkFkt87o5EwdMMS+m1jAh0izyFcROHdLpYU4GXyw8HsGx5ra8PgK+ojevkUfIfwRFjsHCx6BbR/92CQThl/Zkrvxmg==;",
        "From": "Alberto Garcia <berto@igalia.com>",
        "To": "qemu-devel@nongnu.org",
        "Subject": "[PATCH v8 28/34] qcow2: Add subcluster support to\n qcow2_co_pwrite_zeroes()",
        "Date": "Wed, 10 Jun 2020 17:03:06 +0200",
        "Message-Id": "\n <aacf29b7a4c23558959d42228e691f928e5df8bb.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 works now at the subcluster level and pwrite_zeroes_alignment is\nupdated accordingly.\n\nqcow2_cluster_zeroize() is turned into qcow2_subcluster_zeroize() with\nthe following changes:\n\n   - The request can now be subcluster-aligned.\n\n   - The cluster-aligned body of the request is still zeroized using\n     zero_in_l2_slice() as before.\n\n   - The subcluster-aligned head and tail of the request are zeroized\n     with the new zero_l2_subclusters() function.\n\nThere is just one thing to take into account for a possible future\nimprovement: compressed clusters cannot be partially zeroized so\nzero_l2_subclusters() on the head or the tail can return -ENOTSUP.\nThis makes the caller repeat the *complete* request and write actual\nzeroes to disk. This is sub-optimal because\n\n   1) if the head area was compressed we would still be able to use\n      the fast path for the body and possibly the tail.\n\n   2) if the tail area was compressed we are writing zeroes to the\n      head and the body areas, which are already zeroized.\n\nSigned-off-by: Alberto Garcia <berto@igalia.com>\nReviewed-by: Eric Blake <eblake@redhat.com>\n---\n block/qcow2.h         |  4 +--\n block/qcow2-cluster.c | 80 +++++++++++++++++++++++++++++++++++++++----\n block/qcow2.c         | 27 ++++++++-------\n 3 files changed, 90 insertions(+), 21 deletions(-)",
    "diff": "diff --git a/block/qcow2.h b/block/qcow2.h\nindex 4fad40b96b..4ef4ae4ab0 100644\n--- a/block/qcow2.h\n+++ b/block/qcow2.h\n@@ -898,8 +898,8 @@ void qcow2_alloc_cluster_abort(BlockDriverState *bs, QCowL2Meta *m);\n int qcow2_cluster_discard(BlockDriverState *bs, uint64_t offset,\n                           uint64_t bytes, enum qcow2_discard_type type,\n                           bool full_discard);\n-int qcow2_cluster_zeroize(BlockDriverState *bs, uint64_t offset,\n-                          uint64_t bytes, int flags);\n+int qcow2_subcluster_zeroize(BlockDriverState *bs, uint64_t offset,\n+                             uint64_t bytes, int flags);\n \n int qcow2_expand_zero_clusters(BlockDriverState *bs,\n                                BlockDriverAmendStatusCB *status_cb,\ndiff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c\nindex deff838fe8..1641976028 100644\n--- a/block/qcow2-cluster.c\n+++ b/block/qcow2-cluster.c\n@@ -2015,12 +2015,58 @@ static int zero_in_l2_slice(BlockDriverState *bs, uint64_t offset,\n     return nb_clusters;\n }\n \n-int qcow2_cluster_zeroize(BlockDriverState *bs, uint64_t offset,\n-                          uint64_t bytes, int flags)\n+static int zero_l2_subclusters(BlockDriverState *bs, uint64_t offset,\n+                               unsigned nb_subclusters)\n+{\n+    BDRVQcow2State *s = bs->opaque;\n+    uint64_t *l2_slice;\n+    uint64_t old_l2_bitmap, l2_bitmap;\n+    int l2_index, ret, sc = offset_to_sc_index(s, offset);\n+\n+    /* For full clusters use zero_in_l2_slice() instead */\n+    assert(nb_subclusters > 0 && nb_subclusters < s->subclusters_per_cluster);\n+    assert(sc + nb_subclusters <= s->subclusters_per_cluster);\n+\n+    ret = get_cluster_table(bs, offset, &l2_slice, &l2_index);\n+    if (ret < 0) {\n+        return ret;\n+    }\n+\n+    switch (qcow2_get_cluster_type(bs, get_l2_entry(s, l2_slice, l2_index))) {\n+    case QCOW2_CLUSTER_COMPRESSED:\n+        ret = -ENOTSUP; /* We cannot partially zeroize compressed clusters */\n+        goto out;\n+    case QCOW2_CLUSTER_NORMAL:\n+    case QCOW2_CLUSTER_UNALLOCATED:\n+        break;\n+    default:\n+        g_assert_not_reached();\n+    }\n+\n+    old_l2_bitmap = l2_bitmap = get_l2_bitmap(s, l2_slice, l2_index);\n+\n+    l2_bitmap |=  QCOW_OFLAG_SUB_ZERO_RANGE(sc, sc + nb_subclusters);\n+    l2_bitmap &= ~QCOW_OFLAG_SUB_ALLOC_RANGE(sc, sc + nb_subclusters);\n+\n+    if (old_l2_bitmap != l2_bitmap) {\n+        set_l2_bitmap(s, l2_slice, l2_index, l2_bitmap);\n+        qcow2_cache_entry_mark_dirty(s->l2_table_cache, l2_slice);\n+    }\n+\n+    ret = 0;\n+out:\n+    qcow2_cache_put(s->l2_table_cache, (void **) &l2_slice);\n+\n+    return ret;\n+}\n+\n+int qcow2_subcluster_zeroize(BlockDriverState *bs, uint64_t offset,\n+                             uint64_t bytes, int flags)\n {\n     BDRVQcow2State *s = bs->opaque;\n     uint64_t end_offset = offset + bytes;\n     uint64_t nb_clusters;\n+    unsigned head, tail;\n     int64_t cleared;\n     int ret;\n \n@@ -2035,8 +2081,8 @@ int qcow2_cluster_zeroize(BlockDriverState *bs, uint64_t offset,\n     }\n \n     /* Caller must pass aligned values, except at image end */\n-    assert(QEMU_IS_ALIGNED(offset, s->cluster_size));\n-    assert(QEMU_IS_ALIGNED(end_offset, s->cluster_size) ||\n+    assert(offset_into_subcluster(s, offset) == 0);\n+    assert(offset_into_subcluster(s, end_offset) == 0 ||\n            end_offset >= bs->total_sectors << BDRV_SECTOR_BITS);\n \n     /* The zero flag is only supported by version 3 and newer */\n@@ -2044,11 +2090,26 @@ int qcow2_cluster_zeroize(BlockDriverState *bs, uint64_t offset,\n         return -ENOTSUP;\n     }\n \n-    /* Each L2 slice is handled by its own loop iteration */\n-    nb_clusters = size_to_clusters(s, bytes);\n+    head = MIN(end_offset, ROUND_UP(offset, s->cluster_size)) - offset;\n+    offset += head;\n+\n+    tail = (end_offset >= bs->total_sectors << BDRV_SECTOR_BITS) ? 0 :\n+        end_offset - MAX(offset, start_of_cluster(s, end_offset));\n+    end_offset -= tail;\n \n     s->cache_discards = true;\n \n+    if (head) {\n+        ret = zero_l2_subclusters(bs, offset - head,\n+                                  size_to_subclusters(s, head));\n+        if (ret < 0) {\n+            goto fail;\n+        }\n+    }\n+\n+    /* Each L2 slice is handled by its own loop iteration */\n+    nb_clusters = size_to_clusters(s, end_offset - offset);\n+\n     while (nb_clusters > 0) {\n         cleared = zero_in_l2_slice(bs, offset, nb_clusters, flags);\n         if (cleared < 0) {\n@@ -2060,6 +2121,13 @@ int qcow2_cluster_zeroize(BlockDriverState *bs, uint64_t offset,\n         offset += (cleared * s->cluster_size);\n     }\n \n+    if (tail) {\n+        ret = zero_l2_subclusters(bs, end_offset, size_to_subclusters(s, tail));\n+        if (ret < 0) {\n+            goto fail;\n+        }\n+    }\n+\n     ret = 0;\n fail:\n     s->cache_discards = false;\ndiff --git a/block/qcow2.c b/block/qcow2.c\nindex 86258fbc22..4edc3c72b9 100644\n--- a/block/qcow2.c\n+++ b/block/qcow2.c\n@@ -1903,7 +1903,7 @@ static void qcow2_refresh_limits(BlockDriverState *bs, Error **errp)\n         /* Encryption works on a sector granularity */\n         bs->bl.request_alignment = qcrypto_block_get_sector_size(s->crypto);\n     }\n-    bs->bl.pwrite_zeroes_alignment = s->cluster_size;\n+    bs->bl.pwrite_zeroes_alignment = s->subcluster_size;\n     bs->bl.pdiscard_alignment = s->cluster_size;\n }\n \n@@ -3840,8 +3840,9 @@ static coroutine_fn int qcow2_co_pwrite_zeroes(BlockDriverState *bs,\n     int ret;\n     BDRVQcow2State *s = bs->opaque;\n \n-    uint32_t head = offset % s->cluster_size;\n-    uint32_t tail = (offset + bytes) % s->cluster_size;\n+    uint32_t head = offset_into_subcluster(s, offset);\n+    uint32_t tail = ROUND_UP(offset + bytes, s->subcluster_size) -\n+        (offset + bytes);\n \n     trace_qcow2_pwrite_zeroes_start_req(qemu_coroutine_self(), offset, bytes);\n     if (offset + bytes == bs->total_sectors * BDRV_SECTOR_SIZE) {\n@@ -3853,20 +3854,19 @@ static coroutine_fn int qcow2_co_pwrite_zeroes(BlockDriverState *bs,\n         unsigned int nr;\n         QCow2SubclusterType type;\n \n-        assert(head + bytes <= s->cluster_size);\n+        assert(head + bytes + tail <= s->subcluster_size);\n \n         /* check whether remainder of cluster already reads as zero */\n         if (!(is_zero(bs, offset - head, head) &&\n-              is_zero(bs, offset + bytes,\n-                      tail ? s->cluster_size - tail : 0))) {\n+              is_zero(bs, offset + bytes, tail))) {\n             return -ENOTSUP;\n         }\n \n         qemu_co_mutex_lock(&s->lock);\n         /* We can have new write after previous check */\n-        offset = QEMU_ALIGN_DOWN(offset, s->cluster_size);\n-        bytes = s->cluster_size;\n-        nr = s->cluster_size;\n+        offset -= head;\n+        bytes = s->subcluster_size;\n+        nr = s->subcluster_size;\n         ret = qcow2_get_host_offset(bs, offset, &nr, &off, &type);\n         if (ret < 0 ||\n             (type != QCOW2_SUBCLUSTER_UNALLOCATED_PLAIN &&\n@@ -3882,8 +3882,8 @@ static coroutine_fn int qcow2_co_pwrite_zeroes(BlockDriverState *bs,\n \n     trace_qcow2_pwrite_zeroes(qemu_coroutine_self(), offset, bytes);\n \n-    /* Whatever is left can use real zero clusters */\n-    ret = qcow2_cluster_zeroize(bs, offset, bytes, flags);\n+    /* Whatever is left can use real zero subclusters */\n+    ret = qcow2_subcluster_zeroize(bs, offset, bytes, flags);\n     qemu_co_mutex_unlock(&s->lock);\n \n     return ret;\n@@ -4367,12 +4367,13 @@ static int coroutine_fn qcow2_co_truncate(BlockDriverState *bs, int64_t offset,\n         uint64_t zero_start = QEMU_ALIGN_UP(old_length, s->cluster_size);\n \n         /*\n-         * Use zero clusters as much as we can. qcow2_cluster_zeroize()\n+         * Use zero clusters as much as we can. qcow2_subcluster_zeroize()\n          * requires a cluster-aligned start. The end may be unaligned if it is\n          * at the end of the image (which it is here).\n          */\n         if (offset > zero_start) {\n-            ret = qcow2_cluster_zeroize(bs, zero_start, offset - zero_start, 0);\n+            ret = qcow2_subcluster_zeroize(bs, zero_start, offset - zero_start,\n+                                           0);\n             if (ret < 0) {\n                 error_setg_errno(errp, -ret, \"Failed to zero out new clusters\");\n                 goto fail;\n",
    "prefixes": [
        "v8",
        "28/34"
    ]
}