{"id":807896,"url":"http://patchwork.ozlabs.org/api/1.0/patches/807896/?format=json","project":{"id":14,"url":"http://patchwork.ozlabs.org/api/1.0/projects/14/?format=json","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":""},"msgid":"<20170830210542.2153-15-eblake@redhat.com>","date":"2017-08-30T21:05:38","name":"[v6,14/18] qcow2: Switch qcow2_measure() to byte-based iteration","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"107991b7ebb6540db11160f90467e98c8ba98911","submitter":{"id":6591,"url":"http://patchwork.ozlabs.org/api/1.0/people/6591/?format=json","name":"Eric Blake","email":"eblake@redhat.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/qemu-devel/patch/20170830210542.2153-15-eblake@redhat.com/mbox/","series":[{"id":700,"url":"http://patchwork.ozlabs.org/api/1.0/series/700/?format=json","date":"2017-08-30T21:05:25","name":"make dirty-bitmap byte-based","version":6,"mbox":"http://patchwork.ozlabs.org/series/700/mbox/"}],"check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/807896/checks/","tags":{},"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>)","ext-mx04.extmail.prod.ext.phx2.redhat.com;\n\tdmarc=none (p=none dis=none) header.from=redhat.com","ext-mx04.extmail.prod.ext.phx2.redhat.com;\n\tspf=fail smtp.mailfrom=eblake@redhat.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 3xjJ7J3C4Wz9s8P\n\tfor <incoming@patchwork.ozlabs.org>;\n\tThu, 31 Aug 2017 07:10:20 +1000 (AEST)","from localhost ([::1]:52704 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 1dnAFe-0006Xa-DV\n\tfor incoming@patchwork.ozlabs.org; Wed, 30 Aug 2017 17:10:18 -0400","from eggs.gnu.org ([2001:4830:134:3::10]:37142)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <eblake@redhat.com>) id 1dnABy-00047R-Ns\n\tfor qemu-devel@nongnu.org; Wed, 30 Aug 2017 17:06:31 -0400","from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <eblake@redhat.com>) id 1dnABv-0007iR-JV\n\tfor qemu-devel@nongnu.org; Wed, 30 Aug 2017 17:06:30 -0400","from mx1.redhat.com ([209.132.183.28]:60078)\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 1dnABt-0007h5-6j; Wed, 30 Aug 2017 17:06:25 -0400","from smtp.corp.redhat.com\n\t(int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16])\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 3AE508046A;\n\tWed, 30 Aug 2017 21:06:24 +0000 (UTC)","from red.redhat.com (ovpn-122-186.rdu2.redhat.com [10.10.122.186])\n\tby smtp.corp.redhat.com (Postfix) with ESMTP id E202C98172;\n\tWed, 30 Aug 2017 21:06:22 +0000 (UTC)"],"DMARC-Filter":"OpenDMARC Filter v1.3.2 mx1.redhat.com 3AE508046A","From":"Eric Blake <eblake@redhat.com>","To":"qemu-devel@nongnu.org","Date":"Wed, 30 Aug 2017 16:05:38 -0500","Message-Id":"<20170830210542.2153-15-eblake@redhat.com>","In-Reply-To":"<20170830210542.2153-1-eblake@redhat.com>","References":"<20170830210542.2153-1-eblake@redhat.com>","X-Scanned-By":"MIMEDefang 2.79 on 10.5.11.16","X-Greylist":"Sender IP whitelisted, not delayed by milter-greylist-4.5.16\n\t(mx1.redhat.com [10.5.110.28]);\n\tWed, 30 Aug 2017 21:06:24 +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 v6 14/18] qcow2: Switch qcow2_measure() to\n\tbyte-based iteration","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, vsementsov@virtuozzo.com, jsnow@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":"This is new code, but it is easier to read if it makes passes over\nthe image using bytes rather than sectors (and will get easier in\nthe future when bdrv_get_block_status is converted to byte-based).\n\nSigned-off-by: Eric Blake <eblake@redhat.com>\nReviewed-by: John Snow <jsnow@redhat.com>\n\n---\nv6: separate bug fix to earlier patch\nv5: new patch\n---\n block/qcow2.c | 22 ++++++++++------------\n 1 file changed, 10 insertions(+), 12 deletions(-)","diff":"diff --git a/block/qcow2.c b/block/qcow2.c\nindex 40ba26c111..57e3c5e7d5 100644\n--- a/block/qcow2.c\n+++ b/block/qcow2.c\n@@ -3666,20 +3666,19 @@ static BlockMeasureInfo *qcow2_measure(QemuOpts *opts, BlockDriverState *in_bs,\n              */\n             required = virtual_size;\n         } else {\n-            int cluster_sectors = cluster_size / BDRV_SECTOR_SIZE;\n-            int64_t sector_num;\n+            int64_t offset;\n             int pnum = 0;\n\n-            for (sector_num = 0;\n-                 sector_num < ssize / BDRV_SECTOR_SIZE;\n-                 sector_num += pnum) {\n-                int nb_sectors = MIN(ssize / BDRV_SECTOR_SIZE - sector_num,\n-                                     BDRV_REQUEST_MAX_SECTORS);\n+            for (offset = 0; offset < ssize;\n+                 offset += pnum * BDRV_SECTOR_SIZE) {\n+                int nb_sectors = MIN(ssize - offset,\n+                                     INT_MAX) / BDRV_SECTOR_SIZE;\n                 BlockDriverState *file;\n                 int64_t ret;\n\n                 ret = bdrv_get_block_status_above(in_bs, NULL,\n-                                                  sector_num, nb_sectors,\n+                                                  offset >> BDRV_SECTOR_BITS,\n+                                                  nb_sectors,\n                                                   &pnum, &file);\n                 if (ret < 0) {\n                     error_setg_errno(&local_err, -ret,\n@@ -3692,12 +3691,11 @@ static BlockMeasureInfo *qcow2_measure(QemuOpts *opts, BlockDriverState *in_bs,\n                 } else if ((ret & (BDRV_BLOCK_DATA | BDRV_BLOCK_ALLOCATED)) ==\n                            (BDRV_BLOCK_DATA | BDRV_BLOCK_ALLOCATED)) {\n                     /* Extend pnum to end of cluster for next iteration */\n-                    pnum = ROUND_UP(sector_num + pnum, cluster_sectors) -\n-                           sector_num;\n+                    pnum = (ROUND_UP(offset + pnum * BDRV_SECTOR_SIZE,\n+                                 cluster_size) - offset) >> BDRV_SECTOR_BITS;\n\n                     /* Count clusters we've seen */\n-                    required += (sector_num % cluster_sectors + pnum) *\n-                                BDRV_SECTOR_SIZE;\n+                    required += offset % cluster_size + pnum * BDRV_SECTOR_SIZE;\n                 }\n             }\n         }\n","prefixes":["v6","14/18"]}