Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/813534/?format=api
{ "id": 813534, "url": "http://patchwork.ozlabs.org/api/patches/813534/?format=api", "web_url": "http://patchwork.ozlabs.org/project/qemu-devel/patch/20170913160333.23622-20-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-20-eblake@redhat.com>", "list_archive_url": null, "date": "2017-09-13T16:03:29", "name": "[v4,19/23] qemu-img: Change img_rebase() to be byte-based", "commit_ref": null, "pull_url": null, "state": "new", "archived": false, "hash": "053ddc978aa267e40b14e50be8f61dacb21df433", "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-20-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/813534/comments/", "check": "pending", "checks": "http://patchwork.ozlabs.org/api/patches/813534/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-mx02.extmail.prod.ext.phx2.redhat.com;\n\tdmarc=none (p=none dis=none) header.from=redhat.com", "ext-mx02.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 3xsnD75h80z9s7C\n\tfor <incoming@patchwork.ozlabs.org>;\n\tThu, 14 Sep 2017 02:28:55 +1000 (AEST)", "from localhost ([::1]:43488 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 1dsAWy-0001Cm-P9\n\tfor incoming@patchwork.ozlabs.org; Wed, 13 Sep 2017 12:28:52 -0400", "from eggs.gnu.org ([2001:4830:134:3::10]:46141)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <eblake@redhat.com>) id 1dsA9m-00029D-9d\n\tfor qemu-devel@nongnu.org; Wed, 13 Sep 2017 12:05:02 -0400", "from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <eblake@redhat.com>) id 1dsA9k-0006TG-V4\n\tfor qemu-devel@nongnu.org; Wed, 13 Sep 2017 12:04:54 -0400", "from mx1.redhat.com ([209.132.183.28]:41398)\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 1dsA9i-0006Ps-11; Wed, 13 Sep 2017 12:04:50 -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 1A09AEEAC0;\n\tWed, 13 Sep 2017 16:04:49 +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 252B519E72;\n\tWed, 13 Sep 2017 16:04:45 +0000 (UTC)" ], "DMARC-Filter": "OpenDMARC Filter v1.3.2 mx1.redhat.com 1A09AEEAC0", "From": "Eric Blake <eblake@redhat.com>", "To": "qemu-devel@nongnu.org", "Date": "Wed, 13 Sep 2017 11:03:29 -0500", "Message-Id": "<20170913160333.23622-20-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.26]);\n\tWed, 13 Sep 2017 16:04:49 +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 19/23] qemu-img: Change img_rebase() to be\n\tbyte-based", "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, jsnow@redhat.com, famz@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": "In the continuing quest to make more things byte-based, change\nthe internal iteration of img_rebase(). We can finally drop the\nTODO assertion added earlier, now that the entire algorithm is\nbyte-based and no longer has to shift from bytes to sectors.\n\nMost of the change is mechanical ('num_sectors' becomes 'size',\n'sector' becomes 'offset', 'n' goes from sectors to bytes); some\nof it is also a cleanup (use of MIN() instead of open-coding,\nloss of variable 'count' added earlier in commit d6a644bb).\n\nSigned-off-by: Eric Blake <eblake@redhat.com>\n\n---\nv3: new patch\n---\n qemu-img.c | 84 +++++++++++++++++++++++++-------------------------------------\n 1 file changed, 34 insertions(+), 50 deletions(-)", "diff": "diff --git a/qemu-img.c b/qemu-img.c\nindex 034122eba5..028c34a2cc 100644\n--- a/qemu-img.c\n+++ b/qemu-img.c\n@@ -3244,70 +3244,58 @@ static int img_rebase(int argc, char **argv)\n * the image is the same as the original one at any time.\n */\n if (!unsafe) {\n- int64_t num_sectors;\n- int64_t old_backing_num_sectors;\n- int64_t new_backing_num_sectors = 0;\n- uint64_t sector;\n- int n;\n- int64_t count;\n+ int64_t size;\n+ int64_t old_backing_size;\n+ int64_t new_backing_size = 0;\n+ uint64_t offset;\n+ int64_t n;\n float local_progress = 0;\n\n buf_old = blk_blockalign(blk, IO_BUF_SIZE);\n buf_new = blk_blockalign(blk, IO_BUF_SIZE);\n\n- num_sectors = blk_nb_sectors(blk);\n- if (num_sectors < 0) {\n+ size = blk_getlength(blk);\n+ if (size < 0) {\n error_report(\"Could not get size of '%s': %s\",\n- filename, strerror(-num_sectors));\n+ filename, strerror(-size));\n ret = -1;\n goto out;\n }\n- old_backing_num_sectors = blk_nb_sectors(blk_old_backing);\n- if (old_backing_num_sectors < 0) {\n+ old_backing_size = blk_getlength(blk_old_backing);\n+ if (old_backing_size < 0) {\n char backing_name[PATH_MAX];\n\n bdrv_get_backing_filename(bs, backing_name, sizeof(backing_name));\n error_report(\"Could not get size of '%s': %s\",\n- backing_name, strerror(-old_backing_num_sectors));\n+ backing_name, strerror(-old_backing_size));\n ret = -1;\n goto out;\n }\n if (blk_new_backing) {\n- new_backing_num_sectors = blk_nb_sectors(blk_new_backing);\n- if (new_backing_num_sectors < 0) {\n+ new_backing_size = blk_getlength(blk_new_backing);\n+ if (new_backing_size < 0) {\n error_report(\"Could not get size of '%s': %s\",\n- out_baseimg, strerror(-new_backing_num_sectors));\n+ out_baseimg, strerror(-new_backing_size));\n ret = -1;\n goto out;\n }\n }\n\n- if (num_sectors != 0) {\n- local_progress = (float)100 /\n- (num_sectors / MIN(num_sectors, IO_BUF_SIZE / 512));\n+ if (size != 0) {\n+ local_progress = (float)100 / (size / MIN(size, IO_BUF_SIZE));\n }\n\n- for (sector = 0; sector < num_sectors; sector += n) {\n-\n- /* How many sectors can we handle with the next read? */\n- if (sector + (IO_BUF_SIZE / 512) <= num_sectors) {\n- n = (IO_BUF_SIZE / 512);\n- } else {\n- n = num_sectors - sector;\n- }\n+ for (offset = 0; offset < size; offset += n) {\n+ /* How many bytes can we handle with the next read? */\n+ n = MIN(IO_BUF_SIZE, size - offset);\n\n /* If the cluster is allocated, we don't need to take action */\n- ret = bdrv_is_allocated(bs, sector << BDRV_SECTOR_BITS,\n- n << BDRV_SECTOR_BITS, &count);\n+ ret = bdrv_is_allocated(bs, offset, n, &n);\n if (ret < 0) {\n error_report(\"error while reading image metadata: %s\",\n strerror(-ret));\n goto out;\n }\n- /* TODO relax this once bdrv_is_allocated does not enforce\n- * sector alignment */\n- assert(QEMU_IS_ALIGNED(count, BDRV_SECTOR_SIZE));\n- n = count >> BDRV_SECTOR_BITS;\n if (ret) {\n continue;\n }\n@@ -3316,30 +3304,28 @@ static int img_rebase(int argc, char **argv)\n * Read old and new backing file and take into consideration that\n * backing files may be smaller than the COW image.\n */\n- if (sector >= old_backing_num_sectors) {\n- memset(buf_old, 0, n * BDRV_SECTOR_SIZE);\n+ if (offset >= old_backing_size) {\n+ memset(buf_old, 0, n);\n } else {\n- if (sector + n > old_backing_num_sectors) {\n- n = old_backing_num_sectors - sector;\n+ if (offset + n > old_backing_size) {\n+ n = old_backing_size - offset;\n }\n\n- ret = blk_pread(blk_old_backing, sector << BDRV_SECTOR_BITS,\n- buf_old, n << BDRV_SECTOR_BITS);\n+ ret = blk_pread(blk_old_backing, offset, buf_old, n);\n if (ret < 0) {\n error_report(\"error while reading from old backing file\");\n goto out;\n }\n }\n\n- if (sector >= new_backing_num_sectors || !blk_new_backing) {\n- memset(buf_new, 0, n * BDRV_SECTOR_SIZE);\n+ if (offset >= new_backing_size || !blk_new_backing) {\n+ memset(buf_new, 0, n);\n } else {\n- if (sector + n > new_backing_num_sectors) {\n- n = new_backing_num_sectors - sector;\n+ if (offset + n > new_backing_size) {\n+ n = new_backing_size - offset;\n }\n\n- ret = blk_pread(blk_new_backing, sector << BDRV_SECTOR_BITS,\n- buf_new, n << BDRV_SECTOR_BITS);\n+ ret = blk_pread(blk_new_backing, offset, buf_new, n);\n if (ret < 0) {\n error_report(\"error while reading from new backing file\");\n goto out;\n@@ -3349,15 +3335,13 @@ static int img_rebase(int argc, char **argv)\n /* If they differ, we need to write to the COW file */\n uint64_t written = 0;\n\n- while (written < n * BDRV_SECTOR_SIZE) {\n+ while (written < n) {\n int64_t pnum;\n\n- if (compare_buffers(buf_old + written,\n- buf_new + written,\n- n * BDRV_SECTOR_SIZE - written, &pnum))\n+ if (compare_buffers(buf_old + written, buf_new + written,\n+ n - written, &pnum))\n {\n- ret = blk_pwrite(blk,\n- (sector << BDRV_SECTOR_BITS) + written,\n+ ret = blk_pwrite(blk, offset + written,\n buf_old + written, pnum, 0);\n if (ret < 0) {\n error_report(\"Error while writing to COW image: %s\",\n", "prefixes": [ "v4", "19/23" ] }