Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/813523/?format=api
{ "id": 813523, "url": "http://patchwork.ozlabs.org/api/patches/813523/?format=api", "web_url": "http://patchwork.ozlabs.org/project/qemu-devel/patch/20170913160333.23622-22-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-22-eblake@redhat.com>", "list_archive_url": null, "date": "2017-09-13T16:03:31", "name": "[v4,21/23] block: Align block status requests", "commit_ref": null, "pull_url": null, "state": "new", "archived": false, "hash": "c3238a9fb930f2911772bdc3180e1ea7648cc683", "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-22-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/813523/comments/", "check": "pending", "checks": "http://patchwork.ozlabs.org/api/patches/813523/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-mx01.extmail.prod.ext.phx2.redhat.com;\n\tdmarc=none (p=none dis=none) header.from=redhat.com", "ext-mx01.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 3xsn0z54v1z9s72\n\tfor <incoming@patchwork.ozlabs.org>;\n\tThu, 14 Sep 2017 02:19:15 +1000 (AEST)", "from localhost ([::1]:43427 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 1dsANd-0000k1-Kb\n\tfor incoming@patchwork.ozlabs.org; Wed, 13 Sep 2017 12:19:13 -0400", "from eggs.gnu.org ([2001:4830:134:3::10]:46522)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <eblake@redhat.com>) id 1dsAAT-00030y-RA\n\tfor qemu-devel@nongnu.org; Wed, 13 Sep 2017 12:05:39 -0400", "from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <eblake@redhat.com>) id 1dsAAS-0006zr-63\n\tfor qemu-devel@nongnu.org; Wed, 13 Sep 2017 12:05:37 -0400", "from mx1.redhat.com ([209.132.183.28]:39362)\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 1dsAAM-0006xD-T0; Wed, 13 Sep 2017 12:05:31 -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 F098881DE3;\n\tWed, 13 Sep 2017 16:05:29 +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 B52AB69FAE;\n\tWed, 13 Sep 2017 16:05:04 +0000 (UTC)" ], "DMARC-Filter": "OpenDMARC Filter v1.3.2 mx1.redhat.com F098881DE3", "From": "Eric Blake <eblake@redhat.com>", "To": "qemu-devel@nongnu.org", "Date": "Wed, 13 Sep 2017 11:03:31 -0500", "Message-Id": "<20170913160333.23622-22-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.25]);\n\tWed, 13 Sep 2017 16:05:30 +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 21/23] block: Align block status requests", "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": "Any device that has request_alignment greater than 512 should be\nunable to report status at a finer granularity; it may also be\nsimpler for such devices to be guaranteed that the block layer\nhas rounded things out to the granularity boundary (the way the\nblock layer already rounds all other I/O out). Besides, getting\nthe code correct for super-sector alignment also benefits us\nfor the fact that our public interface now has byte granularity,\neven though none of our drivers have byte-level callbacks.\n\nAdd an assertion in blkdebug that proves that the block layer\nnever requests status of unaligned sections, similar to what it\ndoes on other requests (while still keeping the generic helper\nin place for when future patches add a throttle driver). Note\nthat iotest 177 already covers this (it would fail if you use\njust the blkdebug.c hunk without the io.c changes). Meanwhile,\nwe can drop assertions in callers that no longer have to pass\nin sector-aligned addresses.\n\nThere is a mid-function scope added for 'int count', for a\ncouple of reasons: first, an upcoming patch will add an 'if'\nstatement that checks whether a driver has an old- or new-style\ncallback, and can conveniently use the same scope for less\nindentation churn at that time. Second, since we are trying\nto get rid of sector-based computations, wrapping things in\na scope makes it easier to group and see what will be deleted\nin a final cleanup patch once all drivers have been converted\nto the new-style callback.\n\nSigned-off-by: Eric Blake <eblake@redhat.com>\n\n---\nv3: tweak commit message [Fam], rebase to context conflicts, ensure\nwe don't exceed 32-bit limit, drop R-b\nv2: new patch\n---\n include/block/block_int.h | 3 ++-\n block/io.c | 55 +++++++++++++++++++++++++++++++----------------\n block/blkdebug.c | 13 ++++++++++-\n 3 files changed, 51 insertions(+), 20 deletions(-)", "diff": "diff --git a/include/block/block_int.h b/include/block/block_int.h\nindex 7f71c585a0..b1ceffba78 100644\n--- a/include/block/block_int.h\n+++ b/include/block/block_int.h\n@@ -207,7 +207,8 @@ struct BlockDriver {\n * according to the current layer, and should not set\n * BDRV_BLOCK_ALLOCATED, but may set BDRV_BLOCK_RAW. See block.h\n * for the meaning of _DATA, _ZERO, and _OFFSET_VALID. The block\n- * layer guarantees non-NULL pnum and file.\n+ * layer guarantees input aligned to request_alignment, as well as\n+ * non-NULL pnum and file.\n */\n int64_t coroutine_fn (*bdrv_co_get_block_status)(BlockDriverState *bs,\n int64_t sector_num, int nb_sectors, int *pnum,\ndiff --git a/block/io.c b/block/io.c\nindex ea63d19480..c78201b8eb 100644\n--- a/block/io.c\n+++ b/block/io.c\n@@ -1773,7 +1773,8 @@ static int64_t coroutine_fn bdrv_co_block_status(BlockDriverState *bs,\n int64_t n; /* bytes */\n int64_t ret, ret2;\n BlockDriverState *local_file = NULL;\n- int count; /* sectors */\n+ int64_t aligned_offset, aligned_bytes;\n+ uint32_t align;\n\n assert(pnum);\n total_size = bdrv_getlength(bs);\n@@ -1815,28 +1816,45 @@ static int64_t coroutine_fn bdrv_co_block_status(BlockDriverState *bs,\n }\n\n bdrv_inc_in_flight(bs);\n- /*\n- * TODO: Rather than require aligned offsets, we could instead\n- * round to the driver's request_alignment here, then touch up\n- * count afterwards back to the caller's expectations.\n- */\n- assert(QEMU_IS_ALIGNED(offset | bytes, BDRV_SECTOR_SIZE));\n- bytes = MIN(bytes, BDRV_REQUEST_MAX_BYTES);\n- ret = bs->drv->bdrv_co_get_block_status(bs, offset >> BDRV_SECTOR_BITS,\n- bytes >> BDRV_SECTOR_BITS, &count,\n- &local_file);\n- if (ret < 0) {\n- *pnum = 0;\n- goto out;\n+\n+ /* Round out to request_alignment boundaries */\n+ align = MAX(bs->bl.request_alignment, BDRV_SECTOR_SIZE);\n+ aligned_offset = QEMU_ALIGN_DOWN(offset, align);\n+ aligned_bytes = ROUND_UP(offset + bytes, align) - aligned_offset;\n+\n+ {\n+ int count; /* sectors */\n+\n+ assert(QEMU_IS_ALIGNED(aligned_offset | aligned_bytes,\n+ BDRV_SECTOR_SIZE));\n+ ret = bs->drv->bdrv_co_get_block_status(\n+ bs, aligned_offset >> BDRV_SECTOR_BITS,\n+ MIN(INT_MAX, aligned_bytes) >> BDRV_SECTOR_BITS, &count,\n+ &local_file);\n+ if (ret < 0) {\n+ *pnum = 0;\n+ goto out;\n+ }\n+ *pnum = count * BDRV_SECTOR_SIZE;\n+ }\n+\n+ /* Clamp pnum and ret to original request */\n+ assert(QEMU_IS_ALIGNED(*pnum, align));\n+ *pnum -= offset - aligned_offset;\n+ if (aligned_offset >> BDRV_SECTOR_BITS != offset >> BDRV_SECTOR_BITS &&\n+ ret & BDRV_BLOCK_OFFSET_VALID) {\n+ ret += QEMU_ALIGN_DOWN(offset - aligned_offset, BDRV_SECTOR_SIZE);\n+ }\n+ if (*pnum > bytes) {\n+ *pnum = bytes;\n }\n- *pnum = count * BDRV_SECTOR_SIZE;\n\n if (ret & BDRV_BLOCK_RAW) {\n assert(ret & BDRV_BLOCK_OFFSET_VALID && local_file);\n ret = bdrv_co_block_status(local_file, mapping,\n- ret & BDRV_BLOCK_OFFSET_MASK,\n+ (ret & BDRV_BLOCK_OFFSET_MASK) |\n+ (offset & ~BDRV_BLOCK_OFFSET_MASK),\n *pnum, pnum, &local_file);\n- assert(QEMU_IS_ALIGNED(*pnum, BDRV_SECTOR_SIZE));\n goto out;\n }\n\n@@ -1860,7 +1878,8 @@ static int64_t coroutine_fn bdrv_co_block_status(BlockDriverState *bs,\n int64_t file_pnum;\n\n ret2 = bdrv_co_block_status(local_file, mapping,\n- ret & BDRV_BLOCK_OFFSET_MASK,\n+ (ret & BDRV_BLOCK_OFFSET_MASK) |\n+ (offset & ~BDRV_BLOCK_OFFSET_MASK),\n *pnum, &file_pnum, NULL);\n if (ret2 >= 0) {\n /* Ignore errors. This is just providing extra information, it\ndiff --git a/block/blkdebug.c b/block/blkdebug.c\nindex 46e53f2f09..f54fe33cae 100644\n--- a/block/blkdebug.c\n+++ b/block/blkdebug.c\n@@ -628,6 +628,17 @@ static int coroutine_fn blkdebug_co_pdiscard(BlockDriverState *bs,\n return bdrv_co_pdiscard(bs->file->bs, offset, bytes);\n }\n\n+static int64_t coroutine_fn blkdebug_co_get_block_status(\n+ BlockDriverState *bs, int64_t sector_num, int nb_sectors, int *pnum,\n+ BlockDriverState **file)\n+{\n+ assert(QEMU_IS_ALIGNED(sector_num | nb_sectors,\n+ DIV_ROUND_UP(bs->bl.request_alignment,\n+ BDRV_SECTOR_SIZE)));\n+ return bdrv_co_get_block_status_from_file(bs, sector_num, nb_sectors,\n+ pnum, file);\n+}\n+\n static void blkdebug_close(BlockDriverState *bs)\n {\n BDRVBlkdebugState *s = bs->opaque;\n@@ -897,7 +908,7 @@ static BlockDriver bdrv_blkdebug = {\n .bdrv_co_flush_to_disk = blkdebug_co_flush,\n .bdrv_co_pwrite_zeroes = blkdebug_co_pwrite_zeroes,\n .bdrv_co_pdiscard = blkdebug_co_pdiscard,\n- .bdrv_co_get_block_status = bdrv_co_get_block_status_from_file,\n+ .bdrv_co_get_block_status = blkdebug_co_get_block_status,\n\n .bdrv_debug_event = blkdebug_debug_event,\n .bdrv_debug_breakpoint = blkdebug_debug_breakpoint,\n", "prefixes": [ "v4", "21/23" ] }