Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/813510/?format=api
{ "id": 813510, "url": "http://patchwork.ozlabs.org/api/patches/813510/?format=api", "web_url": "http://patchwork.ozlabs.org/project/qemu-devel/patch/20170913160333.23622-8-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-8-eblake@redhat.com>", "list_archive_url": null, "date": "2017-09-13T16:03:17", "name": "[v4,07/23] block: Convert bdrv_get_block_status() to bytes", "commit_ref": null, "pull_url": null, "state": "new", "archived": false, "hash": "8d2e7f5f4a17e875a6ff69b03b3b19bd8347c77f", "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-8-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/813510/comments/", "check": "pending", "checks": "http://patchwork.ozlabs.org/api/patches/813510/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-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 [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 3xsmqQ4B33z9ryT\n\tfor <incoming@patchwork.ozlabs.org>;\n\tThu, 14 Sep 2017 02:10:58 +1000 (AEST)", "from localhost ([::1]:43382 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 1dsAFc-0000GB-Et\n\tfor incoming@patchwork.ozlabs.org; Wed, 13 Sep 2017 12:10:56 -0400", "from eggs.gnu.org ([2001:4830:134:3::10]:45716)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <eblake@redhat.com>) id 1dsA9G-0001Un-3C\n\tfor qemu-devel@nongnu.org; Wed, 13 Sep 2017 12:04:23 -0400", "from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <eblake@redhat.com>) id 1dsA9C-00064w-SR\n\tfor qemu-devel@nongnu.org; Wed, 13 Sep 2017 12:04:22 -0400", "from mx1.redhat.com ([209.132.183.28]:56284)\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 1dsA96-0005zY-7Y; Wed, 13 Sep 2017 12:04:12 -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 4A669C04B31B;\n\tWed, 13 Sep 2017 16:04:11 +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 8300669FA2;\n\tWed, 13 Sep 2017 16:04:09 +0000 (UTC)" ], "DMARC-Filter": "OpenDMARC Filter v1.3.2 mx1.redhat.com 4A669C04B31B", "From": "Eric Blake <eblake@redhat.com>", "To": "qemu-devel@nongnu.org", "Date": "Wed, 13 Sep 2017 11:03:17 -0500", "Message-Id": "<20170913160333.23622-8-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:11 +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 07/23] block: Convert\n\tbdrv_get_block_status() 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\tMax 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() to\nbdrv_block_status() ensures that the compiler enforces that all\ncallers are updated. For now, the io.c layer still assert()s that\nall callers are sector-aligned, but that can be relaxed when a later\npatch implements byte-based block status in the drivers.\n\nNote that we have an inherent limitation in the BDRV_BLOCK_* return\nvalues: BDRV_BLOCK_OFFSET_VALID can only return the start of a\nsector, even if we later relax the interface to query for the status\nstarting at an intermediate byte; document the obvious interpretation\nthat valid offsets are always sector-relative.\n\nTherefore, for the most part this patch is just the addition of scaling\nat the callers followed by inverse scaling at bdrv_block_status(). But\nsome code, particularly bdrv_is_allocated(), gets a lot simpler because\nit no longer has to mess with sectors.\n\nFor ease of review, bdrv_get_block_status_above() will be tackled\nseparately.\n\nSigned-off-by: Eric Blake <eblake@redhat.com>\n\n---\nv3: clamp bytes to 32-bits, rather than asserting\nv2: rebase to earlier changes\n---\n include/block/block.h | 12 +++++++-----\n block/io.c | 31 +++++++++++++++++++------------\n block/qcow2-cluster.c | 2 +-\n qemu-img.c | 20 +++++++++++---------\n 4 files changed, 38 insertions(+), 27 deletions(-)", "diff": "diff --git a/include/block/block.h b/include/block/block.h\nindex bb3b95d491..7a9a8db588 100644\n--- a/include/block/block.h\n+++ b/include/block/block.h\n@@ -138,8 +138,10 @@ typedef struct HDGeometry {\n *\n * If BDRV_BLOCK_OFFSET_VALID is set, bits 9-62 (BDRV_BLOCK_OFFSET_MASK)\n * represent the offset in the returned BDS that is allocated for the\n- * corresponding raw data; however, whether that offset actually contains\n- * data also depends on BDRV_BLOCK_DATA and BDRV_BLOCK_ZERO, as follows:\n+ * corresponding raw data. Individual bytes are at the same sector-relative\n+ * locations (and thus, this bit cannot be set for mappings which are\n+ * not equivalent modulo 512). However, whether that offset actually\n+ * contains data also depends on BDRV_BLOCK_DATA, as follows:\n *\n * DATA ZERO OFFSET_VALID\n * t t t sectors read as zero, returned file is zero at offset\n@@ -421,9 +423,9 @@ int bdrv_has_zero_init_1(BlockDriverState *bs);\n int bdrv_has_zero_init(BlockDriverState *bs);\n bool bdrv_unallocated_blocks_are_zero(BlockDriverState *bs);\n bool bdrv_can_write_zeroes_with_unmap(BlockDriverState *bs);\n-int64_t bdrv_get_block_status(BlockDriverState *bs, int64_t sector_num,\n- int nb_sectors, int *pnum,\n- BlockDriverState **file);\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,\ndiff --git a/block/io.c b/block/io.c\nindex 638b3890b7..1ed46bcece 100644\n--- a/block/io.c\n+++ b/block/io.c\n@@ -695,7 +695,6 @@ int bdrv_make_zero(BdrvChild *child, BdrvRequestFlags flags)\n {\n int64_t target_size, ret, bytes, offset = 0;\n BlockDriverState *bs = child->bs;\n- int n; /* sectors */\n\n target_size = bdrv_getlength(bs);\n if (target_size < 0) {\n@@ -707,24 +706,23 @@ int bdrv_make_zero(BdrvChild *child, BdrvRequestFlags flags)\n if (bytes <= 0) {\n return 0;\n }\n- ret = bdrv_get_block_status(bs, offset >> BDRV_SECTOR_BITS,\n- bytes >> BDRV_SECTOR_BITS, &n, NULL);\n+ ret = bdrv_block_status(bs, offset, bytes, &bytes, NULL);\n if (ret < 0) {\n error_report(\"error getting block status at offset %\" PRId64 \": %s\",\n offset, strerror(-ret));\n return ret;\n }\n if (ret & BDRV_BLOCK_ZERO) {\n- offset += n * BDRV_SECTOR_BITS;\n+ offset += bytes;\n continue;\n }\n- ret = bdrv_pwrite_zeroes(child, offset, n * BDRV_SECTOR_SIZE, flags);\n+ ret = bdrv_pwrite_zeroes(child, offset, bytes, flags);\n if (ret < 0) {\n error_report(\"error writing zeroes at offset %\" PRId64 \": %s\",\n offset, strerror(-ret));\n return ret;\n }\n- offset += n * BDRV_SECTOR_SIZE;\n+ offset += bytes;\n }\n }\n\n@@ -1983,13 +1981,22 @@ int64_t bdrv_get_block_status_above(BlockDriverState *bs,\n nb_sectors, pnum, file);\n }\n\n-int64_t bdrv_get_block_status(BlockDriverState *bs,\n- int64_t sector_num,\n- int nb_sectors, int *pnum,\n- BlockDriverState **file)\n+int64_t bdrv_block_status(BlockDriverState *bs,\n+ int64_t offset, int64_t bytes, int64_t *pnum,\n+ BlockDriverState **file)\n {\n- return bdrv_get_block_status_above(bs, backing_bs(bs),\n- sector_num, nb_sectors, pnum, file);\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 }\n\n int coroutine_fn bdrv_is_allocated(BlockDriverState *bs, int64_t offset,\ndiff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c\nindex 0d4824993c..d837b3980d 100644\n--- a/block/qcow2-cluster.c\n+++ b/block/qcow2-cluster.c\n@@ -1584,7 +1584,7 @@ static int discard_single_l2(BlockDriverState *bs, uint64_t offset,\n * cluster is already marked as zero, or if it's unallocated and we\n * don't have a backing file.\n *\n- * TODO We might want to use bdrv_get_block_status(bs) here, but we're\n+ * TODO We might want to use bdrv_block_status(bs) here, but we're\n * holding s->lock, so that doesn't work today.\n *\n * If full_discard is true, the sector should not read back as zeroes,\ndiff --git a/qemu-img.c b/qemu-img.c\nindex 54f7682069..897f80abb3 100644\n--- a/qemu-img.c\n+++ b/qemu-img.c\n@@ -1598,9 +1598,14 @@ static int convert_iteration_sectors(ImgConvertState *s, int64_t sector_num)\n\n if (s->sector_next_status <= sector_num) {\n if (s->target_has_backing) {\n- ret = bdrv_get_block_status(blk_bs(s->src[src_cur]),\n- sector_num - src_cur_offset,\n- n, &n, NULL);\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@@ -2677,9 +2682,7 @@ static int get_block_status(BlockDriverState *bs, int64_t offset,\n int depth;\n BlockDriverState *file;\n bool has_offset;\n- int nb_sectors = bytes >> BDRV_SECTOR_BITS;\n\n- assert(bytes < INT_MAX);\n /* As an optimization, we could cache the current range of unallocated\n * clusters in each file of the chain, and avoid querying the same\n * range repeatedly.\n@@ -2687,12 +2690,11 @@ static int get_block_status(BlockDriverState *bs, int64_t offset,\n\n depth = 0;\n for (;;) {\n- ret = bdrv_get_block_status(bs, offset >> BDRV_SECTOR_BITS, nb_sectors,\n- &nb_sectors, &file);\n+ ret = bdrv_block_status(bs, offset, bytes, &bytes, &file);\n if (ret < 0) {\n return ret;\n }\n- assert(nb_sectors);\n+ assert(bytes);\n if (ret & (BDRV_BLOCK_ZERO|BDRV_BLOCK_DATA)) {\n break;\n }\n@@ -2709,7 +2711,7 @@ static int get_block_status(BlockDriverState *bs, int64_t offset,\n\n *e = (MapEntry) {\n .start = offset,\n- .length = nb_sectors * BDRV_SECTOR_SIZE,\n+ .length = bytes,\n .data = !!(ret & BDRV_BLOCK_DATA),\n .zero = !!(ret & BDRV_BLOCK_ZERO),\n .offset = ret & BDRV_BLOCK_OFFSET_MASK,\n", "prefixes": [ "v4", "07/23" ] }