Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/813529/?format=api
{ "id": 813529, "url": "http://patchwork.ozlabs.org/api/patches/813529/?format=api", "web_url": "http://patchwork.ozlabs.org/project/qemu-devel/patch/20170913160333.23622-13-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-13-eblake@redhat.com>", "list_archive_url": null, "date": "2017-09-13T16:03:22", "name": "[v4,12/23] block: Convert bdrv_get_block_status_above() to bytes", "commit_ref": null, "pull_url": null, "state": "new", "archived": false, "hash": "051eab4ee62c85a43a7671cbfca74d628ab84fff", "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-13-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/813529/comments/", "check": "pending", "checks": "http://patchwork.ozlabs.org/api/patches/813529/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>)", "ext-mx07.extmail.prod.ext.phx2.redhat.com;\n\tdmarc=none (p=none dis=none) header.from=redhat.com", "ext-mx07.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 3xsn6Z5tgYz9s7M\n\tfor <incoming@patchwork.ozlabs.org>;\n\tThu, 14 Sep 2017 02:24:06 +1000 (AEST)", "from localhost ([::1]:43454 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 1dsASK-0004yk-Qz\n\tfor incoming@patchwork.ozlabs.org; Wed, 13 Sep 2017 12:24:04 -0400", "from eggs.gnu.org ([2001:4830:134:3::10]:46050)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <eblake@redhat.com>) id 1dsA9h-000227-1v\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 1dsA9a-0006KQ-Kr\n\tfor qemu-devel@nongnu.org; Wed, 13 Sep 2017 12:04:49 -0400", "from mx1.redhat.com ([209.132.183.28]:49971)\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 1dsA9M-0006BZ-UL; Wed, 13 Sep 2017 12:04:29 -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 F36C7C047B88;\n\tWed, 13 Sep 2017 16:04:27 +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 4661D5C6D2;\n\tWed, 13 Sep 2017 16:04:26 +0000 (UTC)" ], "DMARC-Filter": "OpenDMARC Filter v1.3.2 mx1.redhat.com F36C7C047B88", "From": "Eric Blake <eblake@redhat.com>", "To": "qemu-devel@nongnu.org", "Date": "Wed, 13 Sep 2017 11:03:22 -0500", "Message-Id": "<20170913160333.23622-13-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.31]);\n\tWed, 13 Sep 2017 16:04:28 +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 12/23] block: Convert\n\tbdrv_get_block_status_above() to bytes", "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, famz@redhat.com, qemu-block@nongnu.org,\n\tJeff Cody <jcody@redhat.com>, Max Reitz <mreitz@redhat.com>,\n\tStefan Hajnoczi <stefanha@redhat.com>, jsnow@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": "We are gradually moving away from sector-based interfaces, towards\nbyte-based. In the common case, allocation is unlikely to ever use\nvalues that are not naturally sector-aligned, but it is possible\nthat byte-based values will let us be more precise about allocation\nat the end of an unaligned file that can do byte-based access.\n\nChanging the name of the function from bdrv_get_block_status_above()\nto bdrv_block_status_above() ensures that the compiler enforces that\nall callers are updated. For now, the io.c layer still assert()s\nthat all callers are sector-aligned, but that can be relaxed when a\nlater patch implements byte-based block status in the drivers.\n\nFor the most part this patch is just the addition of scaling at the\ncallers followed by inverse scaling at bdrv_block_status(). But some\ncode, particularly bdrv_block_status(), gets a lot simpler because\nit no longer has to mess with sectors. Likewise, mirror code no\nlonger computes s->granularity >> BDRV_SECTOR_BITS, and can therefore\ndrop an assertion (fix a neighboring assertion to use is_power_of_2\nwhile there).\n\nFor ease of review, bdrv_get_block_status() was tackled separately.\n\nSigned-off-by: Eric Blake <eblake@redhat.com>\n\n---\nv4: rebase to earlier changes\nv3: rebase to allocation/mapping sense change and qcow2-measure, tweak\nmirror assertions, drop R-b\nv2: rebase to earlier changes\n---\n include/block/block.h | 10 +++++-----\n block/io.c | 39 ++++++++-------------------------------\n block/mirror.c | 16 +++++-----------\n block/qcow2.c | 25 +++++++++----------------\n qemu-img.c | 39 +++++++++++++++++++++++----------------\n 5 files changed, 50 insertions(+), 79 deletions(-)", "diff": "diff --git a/include/block/block.h b/include/block/block.h\nindex 7a9a8db588..e87348dcfa 100644\n--- a/include/block/block.h\n+++ b/include/block/block.h\n@@ -426,11 +426,11 @@ bool bdrv_can_write_zeroes_with_unmap(BlockDriverState *bs);\n int64_t bdrv_block_status(BlockDriverState *bs, int64_t offset,\n int64_t bytes, int64_t *pnum,\n BlockDriverState **file);\n-int64_t bdrv_get_block_status_above(BlockDriverState *bs,\n- BlockDriverState *base,\n- int64_t sector_num,\n- int nb_sectors, int *pnum,\n- BlockDriverState **file);\n+int64_t bdrv_block_status_above(BlockDriverState *bs,\n+ BlockDriverState *base,\n+ int64_t offset,\n+ int64_t bytes, int64_t *pnum,\n+ BlockDriverState **file);\n int bdrv_is_allocated(BlockDriverState *bs, int64_t offset, int64_t bytes,\n int64_t *pnum);\n int bdrv_is_allocated_above(BlockDriverState *top, BlockDriverState *base,\ndiff --git a/block/io.c b/block/io.c\nindex 409cfe0938..ea63d19480 100644\n--- a/block/io.c\n+++ b/block/io.c\n@@ -1931,7 +1931,7 @@ static int64_t coroutine_fn bdrv_co_block_status_above(BlockDriverState *bs,\n return ret;\n }\n\n-/* Coroutine wrapper for bdrv_get_block_status_above() */\n+/* Coroutine wrapper for bdrv_block_status_above() */\n static void coroutine_fn bdrv_block_status_above_co_entry(void *opaque)\n {\n BdrvCoBlockStatusData *data = opaque;\n@@ -1978,43 +1978,20 @@ static int64_t bdrv_common_block_status_above(BlockDriverState *bs,\n return data.ret;\n }\n\n-int64_t bdrv_get_block_status_above(BlockDriverState *bs,\n- BlockDriverState *base,\n- int64_t sector_num,\n- int nb_sectors, int *pnum,\n- BlockDriverState **file)\n+int64_t bdrv_block_status_above(BlockDriverState *bs, BlockDriverState *base,\n+ int64_t offset, int64_t bytes, int64_t *pnum,\n+ BlockDriverState **file)\n {\n- int64_t ret;\n- int64_t n;\n-\n- ret = bdrv_common_block_status_above(bs, base, true,\n- sector_num * BDRV_SECTOR_SIZE,\n- nb_sectors * BDRV_SECTOR_SIZE,\n- &n, file);\n- if (ret < 0) {\n- return ret;\n- }\n- assert(QEMU_IS_ALIGNED(n, BDRV_SECTOR_SIZE));\n- *pnum = n >> BDRV_SECTOR_BITS;\n- return ret;\n+ return bdrv_common_block_status_above(bs, base, true, offset, bytes,\n+ pnum, file);\n }\n\n int64_t bdrv_block_status(BlockDriverState *bs,\n int64_t offset, int64_t bytes, int64_t *pnum,\n BlockDriverState **file)\n {\n- int64_t ret;\n- int n;\n-\n- assert(QEMU_IS_ALIGNED(offset | bytes, BDRV_SECTOR_SIZE));\n- bytes = MIN(bytes, BDRV_REQUEST_MAX_BYTES);\n- ret = bdrv_get_block_status_above(bs, backing_bs(bs),\n- offset >> BDRV_SECTOR_BITS,\n- bytes >> BDRV_SECTOR_BITS, &n, file);\n- if (pnum) {\n- *pnum = n * BDRV_SECTOR_SIZE;\n- }\n- return ret;\n+ return bdrv_block_status_above(bs, backing_bs(bs),\n+ offset, bytes, pnum, file);\n }\n\n int coroutine_fn bdrv_is_allocated(BlockDriverState *bs, int64_t offset,\ndiff --git a/block/mirror.c b/block/mirror.c\nindex 67f45cec4e..fab59739c5 100644\n--- a/block/mirror.c\n+++ b/block/mirror.c\n@@ -328,7 +328,6 @@ static uint64_t coroutine_fn mirror_iteration(MirrorBlockJob *s)\n uint64_t delay_ns = 0;\n /* At least the first dirty chunk is mirrored in one iteration. */\n int nb_chunks = 1;\n- int sectors_per_chunk = s->granularity >> BDRV_SECTOR_BITS;\n bool write_zeroes_ok = bdrv_can_write_zeroes_with_unmap(blk_bs(s->target));\n int max_io_bytes = MAX(s->buf_size / MAX_IN_FLIGHT, MAX_IO_BYTES);\n\n@@ -376,7 +375,7 @@ static uint64_t coroutine_fn mirror_iteration(MirrorBlockJob *s)\n }\n\n /* Clear dirty bits before querying the block status, because\n- * calling bdrv_get_block_status_above could yield - if some blocks are\n+ * calling bdrv_block_status_above could yield - if some blocks are\n * marked dirty in this window, we need to know.\n */\n bdrv_reset_dirty_bitmap_locked(s->dirty_bitmap, offset,\n@@ -386,7 +385,6 @@ static uint64_t coroutine_fn mirror_iteration(MirrorBlockJob *s)\n bitmap_set(s->in_flight_bitmap, offset / s->granularity, nb_chunks);\n while (nb_chunks > 0 && offset < s->bdev_length) {\n int64_t ret;\n- int io_sectors;\n int64_t io_bytes;\n int64_t io_bytes_acct;\n enum MirrorMethod {\n@@ -396,11 +394,9 @@ static uint64_t coroutine_fn mirror_iteration(MirrorBlockJob *s)\n } mirror_method = MIRROR_METHOD_COPY;\n\n assert(!(offset % s->granularity));\n- ret = bdrv_get_block_status_above(source, NULL,\n- offset >> BDRV_SECTOR_BITS,\n- nb_chunks * sectors_per_chunk,\n- &io_sectors, NULL);\n- io_bytes = io_sectors * BDRV_SECTOR_SIZE;\n+ ret = bdrv_block_status_above(source, NULL, offset,\n+ nb_chunks * s->granularity,\n+ &io_bytes, NULL);\n if (ret < 0) {\n io_bytes = MIN(nb_chunks * s->granularity, max_io_bytes);\n } else if (ret & BDRV_BLOCK_DATA) {\n@@ -1121,9 +1117,7 @@ static void mirror_start_job(const char *job_id, BlockDriverState *bs,\n granularity = bdrv_get_default_bitmap_granularity(target);\n }\n\n- assert ((granularity & (granularity - 1)) == 0);\n- /* Granularity must be large enough for sector-based dirty bitmap */\n- assert(granularity >= BDRV_SECTOR_SIZE);\n+ assert(is_power_of_2(granularity));\n\n if (buf_size < 0) {\n error_setg(errp, \"Invalid parameter 'buf-size'\");\ndiff --git a/block/qcow2.c b/block/qcow2.c\nindex eb498b56d4..721cb077fe 100644\n--- a/block/qcow2.c\n+++ b/block/qcow2.c\n@@ -2973,7 +2973,7 @@ finish:\n\n static bool is_zero(BlockDriverState *bs, int64_t offset, int64_t bytes)\n {\n- int nr;\n+ int64_t nr;\n int64_t res;\n int64_t start;\n\n@@ -2989,10 +2989,8 @@ static bool is_zero(BlockDriverState *bs, int64_t offset, int64_t bytes)\n if (!bytes) {\n return true;\n }\n- res = bdrv_get_block_status_above(bs, NULL, start >> BDRV_SECTOR_BITS,\n- bytes >> BDRV_SECTOR_BITS, &nr, NULL);\n- return res >= 0 && (res & BDRV_BLOCK_ZERO) &&\n- nr * BDRV_SECTOR_SIZE == bytes;\n+ res = bdrv_block_status_above(bs, NULL, start, bytes, &nr, NULL);\n+ return res >= 0 && (res & BDRV_BLOCK_ZERO) && nr == bytes;\n }\n\n static coroutine_fn int qcow2_co_pwrite_zeroes(BlockDriverState *bs,\n@@ -3650,17 +3648,13 @@ static BlockMeasureInfo *qcow2_measure(QemuOpts *opts, BlockDriverState *in_bs,\n required = virtual_size;\n } else {\n int64_t offset;\n- int pnum = 0;\n+ int64_t pnum = 0;\n\n- for (offset = 0; offset < ssize;\n- offset += pnum * BDRV_SECTOR_SIZE) {\n- int nb_sectors = MIN(ssize - offset,\n- BDRV_REQUEST_MAX_BYTES) / BDRV_SECTOR_SIZE;\n+ for (offset = 0; offset < ssize; offset += pnum) {\n int64_t ret;\n\n- ret = bdrv_get_block_status_above(in_bs, NULL,\n- offset >> BDRV_SECTOR_BITS,\n- nb_sectors, &pnum, NULL);\n+ ret = bdrv_block_status_above(in_bs, NULL, offset,\n+ ssize - offset, &pnum, NULL);\n if (ret < 0) {\n error_setg_errno(&local_err, -ret,\n \"Unable to get block status\");\n@@ -3672,11 +3666,10 @@ 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(offset + pnum * BDRV_SECTOR_SIZE,\n- cluster_size) - offset) >> BDRV_SECTOR_BITS;\n+ pnum = ROUND_UP(offset + pnum, cluster_size) - offset;\n\n /* Count clusters we've seen */\n- required += offset % cluster_size + pnum * BDRV_SECTOR_SIZE;\n+ required += offset % cluster_size + pnum;\n }\n }\n }\ndiff --git a/qemu-img.c b/qemu-img.c\nindex 897f80abb3..b91133b922 100644\n--- a/qemu-img.c\n+++ b/qemu-img.c\n@@ -1225,7 +1225,7 @@ static int img_compare(int argc, char **argv)\n BlockDriverState *bs1, *bs2;\n int64_t total_sectors1, total_sectors2;\n uint8_t *buf1 = NULL, *buf2 = NULL;\n- int pnum1, pnum2;\n+ int64_t pnum1, pnum2;\n int allocated1, allocated2;\n int ret = 0; /* return value - 0 Ident, 1 Different, >1 Error */\n bool progress = false, quiet = false, strict = false;\n@@ -1379,9 +1379,11 @@ static int img_compare(int argc, char **argv)\n if (nb_sectors <= 0) {\n break;\n }\n- status1 = bdrv_get_block_status_above(bs1, NULL, sector_num,\n- total_sectors1 - sector_num,\n- &pnum1, NULL);\n+ status1 = bdrv_block_status_above(bs1, NULL,\n+ sector_num * BDRV_SECTOR_SIZE,\n+ (total_sectors1 - sector_num) *\n+ BDRV_SECTOR_SIZE,\n+ &pnum1, NULL);\n if (status1 < 0) {\n ret = 3;\n error_report(\"Sector allocation test failed for %s\", filename1);\n@@ -1389,9 +1391,11 @@ static int img_compare(int argc, char **argv)\n }\n allocated1 = status1 & BDRV_BLOCK_ALLOCATED;\n\n- status2 = bdrv_get_block_status_above(bs2, NULL, sector_num,\n- total_sectors2 - sector_num,\n- &pnum2, NULL);\n+ status2 = bdrv_block_status_above(bs2, NULL,\n+ sector_num * BDRV_SECTOR_SIZE,\n+ (total_sectors2 - sector_num) *\n+ BDRV_SECTOR_SIZE,\n+ &pnum2, NULL);\n if (status2 < 0) {\n ret = 3;\n error_report(\"Sector allocation test failed for %s\", filename2);\n@@ -1399,10 +1403,12 @@ static int img_compare(int argc, char **argv)\n }\n allocated2 = status2 & BDRV_BLOCK_ALLOCATED;\n if (pnum1) {\n- nb_sectors = MIN(nb_sectors, 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, pnum2);\n+ nb_sectors = MIN(nb_sectors,\n+ DIV_ROUND_UP(pnum2, BDRV_SECTOR_SIZE));\n }\n\n if (strict) {\n@@ -1416,7 +1422,7 @@ static int img_compare(int argc, char **argv)\n }\n }\n if ((status1 & BDRV_BLOCK_ZERO) && (status2 & BDRV_BLOCK_ZERO)) {\n- nb_sectors = MIN(pnum1, pnum2);\n+ nb_sectors = DIV_ROUND_UP(MIN(pnum1, pnum2), BDRV_SECTOR_SIZE);\n } else if (allocated1 == allocated2) {\n if (allocated1) {\n ret = blk_pread(blk1, sector_num << BDRV_SECTOR_BITS, buf1,\n@@ -1597,23 +1603,24 @@ static int convert_iteration_sectors(ImgConvertState *s, int64_t sector_num)\n n = MIN(s->total_sectors - sector_num, BDRV_REQUEST_MAX_SECTORS);\n\n if (s->sector_next_status <= sector_num) {\n+ int64_t count = n * BDRV_SECTOR_SIZE;\n+\n if (s->target_has_backing) {\n- int64_t count = n * BDRV_SECTOR_SIZE;\n\n ret = bdrv_block_status(blk_bs(s->src[src_cur]),\n (sector_num - src_cur_offset) *\n BDRV_SECTOR_SIZE,\n count, &count, NULL);\n- assert(ret < 0 || QEMU_IS_ALIGNED(count, BDRV_SECTOR_SIZE));\n- n = count >> BDRV_SECTOR_BITS;\n } else {\n- ret = bdrv_get_block_status_above(blk_bs(s->src[src_cur]), NULL,\n- sector_num - src_cur_offset,\n- n, &n, NULL);\n+ ret = bdrv_block_status_above(blk_bs(s->src[src_cur]), NULL,\n+ (sector_num - src_cur_offset) *\n+ BDRV_SECTOR_SIZE,\n+ count, &count, NULL);\n }\n if (ret < 0) {\n return ret;\n }\n+ n = DIV_ROUND_UP(count, BDRV_SECTOR_SIZE);\n\n if (ret & BDRV_BLOCK_ZERO) {\n s->status = BLK_ZERO;\n", "prefixes": [ "v4", "12/23" ] }