From nobody Wed Apr 16 03:21:50 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1531238556055718.8866972765115; Tue, 10 Jul 2018 09:02:36 -0700 (PDT) Received: from localhost ([::1]:48567 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fcv5z-0004Xr-Bu for importer@patchew.org; Tue, 10 Jul 2018 12:02:31 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44189) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fcunT-00051N-RE for qemu-devel@nongnu.org; Tue, 10 Jul 2018 11:43:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fcunS-0001aN-Oy for qemu-devel@nongnu.org; Tue, 10 Jul 2018 11:43:23 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:38806 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fcunN-0001Wn-Pv; Tue, 10 Jul 2018 11:43:17 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 53D3185629; Tue, 10 Jul 2018 15:43:17 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-156.ams2.redhat.com [10.36.116.156]) by smtp.corp.redhat.com (Postfix) with ESMTP id 80F612026D6B; Tue, 10 Jul 2018 15:43:16 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 10 Jul 2018 17:42:41 +0200 Message-Id: <20180710154304.18304-2-kwolf@redhat.com> In-Reply-To: <20180710154304.18304-1-kwolf@redhat.com> References: <20180710154304.18304-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Tue, 10 Jul 2018 15:43:17 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Tue, 10 Jul 2018 15:43:17 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 01/24] block: Poll after drain on attaching a node X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Commit dcf94a23b1 ('block: Don't poll in parent drain callbacks') removed polling in bdrv_child_cb_drained_begin() on the grounds that the original bdrv_drain() already will poll and BdrvChildRole.drained_begin calls must not cause graph changes (and therefore must not call aio_poll() or the recursion through the graph will break. This reasoning is correct for calls through bdrv_do_drained_begin(). However, BdrvChildRole.drained_begin is also called when a node that is already in a drained section (i.e. bdrv_do_drained_begin() has already returned and therefore can't poll any more) is attached to a new parent. In this case, we must explicitly poll to have all requests completed before the drained new child can be attached to the parent. In bdrv_replace_child_noperm(), we know that we're not inside the recursion of bdrv_do_drained_begin() because graph changes are not allowed there, and bdrv_replace_child_noperm() is a graph change. The call of BdrvChildRole.drained_begin() must therefore be followed by a BDRV_POLL_WHILE() that waits for the completion of requests. Reported-by: Max Reitz Signed-off-by: Kevin Wolf --- include/block/block.h | 8 ++++++++ include/block/block_int.h | 3 +++ block.c | 2 +- block/io.c | 26 ++++++++++++++++++++------ 4 files changed, 32 insertions(+), 7 deletions(-) diff --git a/include/block/block.h b/include/block/block.h index bc76b1e59f..706ef009ad 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -569,6 +569,14 @@ void bdrv_parent_drained_begin(BlockDriverState *bs, B= drvChild *ignore, bool ignore_bds_parents); =20 /** + * bdrv_parent_drained_begin_single: + * + * Begin a quiesced section for the parent of @c. If @poll is true, wait f= or + * any pending activity to cease. + */ +void bdrv_parent_drained_begin_single(BdrvChild *c, bool poll); + +/** * bdrv_parent_drained_end: * * End a quiesced section of all users of @bs. This is part of diff --git a/include/block/block_int.h b/include/block/block_int.h index af71b414be..81cd3db7a9 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -606,6 +606,9 @@ struct BdrvChildRole { * requests after returning from .drained_begin() until .drained_end()= is * called. * + * These functions must not change the graph (and therefore also must = not + * call aio_poll(), which could change the graph indirectly). + * * Note that this can be nested. If drained_begin() was called twice, = new * I/O is allowed only after drained_end() was called twice, too. */ diff --git a/block.c b/block.c index ac8b3a3511..a2fe05ea96 100644 --- a/block.c +++ b/block.c @@ -2066,7 +2066,7 @@ static void bdrv_replace_child_noperm(BdrvChild *chil= d, } assert(num >=3D 0); for (i =3D 0; i < num; i++) { - child->role->drained_begin(child); + bdrv_parent_drained_begin_single(child, true); } } =20 diff --git a/block/io.c b/block/io.c index 1a2272fad3..038449f81f 100644 --- a/block/io.c +++ b/block/io.c @@ -52,9 +52,7 @@ void bdrv_parent_drained_begin(BlockDriverState *bs, Bdrv= Child *ignore, if (c =3D=3D ignore || (ignore_bds_parents && c->role->parent_is_b= ds)) { continue; } - if (c->role->drained_begin) { - c->role->drained_begin(c); - } + bdrv_parent_drained_begin_single(c, false); } } =20 @@ -73,6 +71,14 @@ void bdrv_parent_drained_end(BlockDriverState *bs, BdrvC= hild *ignore, } } =20 +static bool bdrv_parent_drained_poll_single(BdrvChild *c) +{ + if (c->role->drained_poll) { + return c->role->drained_poll(c); + } + return false; +} + static bool bdrv_parent_drained_poll(BlockDriverState *bs, BdrvChild *igno= re, bool ignore_bds_parents) { @@ -83,14 +89,22 @@ static bool bdrv_parent_drained_poll(BlockDriverState *= bs, BdrvChild *ignore, if (c =3D=3D ignore || (ignore_bds_parents && c->role->parent_is_b= ds)) { continue; } - if (c->role->drained_poll) { - busy |=3D c->role->drained_poll(c); - } + busy |=3D bdrv_parent_drained_poll_single(c); } =20 return busy; } =20 +void bdrv_parent_drained_begin_single(BdrvChild *c, bool poll) +{ + if (c->role->drained_begin) { + c->role->drained_begin(c); + } + if (poll) { + BDRV_POLL_WHILE(c->bs, bdrv_parent_drained_poll_single(c)); + } +} + static void bdrv_merge_limits(BlockLimits *dst, const BlockLimits *src) { dst->opt_transfer =3D MAX(dst->opt_transfer, src->opt_transfer); --=20 2.13.6 From nobody Wed Apr 16 03:21:50 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1531237557023203.45956430894466; Tue, 10 Jul 2018 08:45:57 -0700 (PDT) Received: from localhost ([::1]:48459 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fcupv-0007BF-Qk for importer@patchew.org; Tue, 10 Jul 2018 11:45:55 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44168) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fcunT-00050r-88 for qemu-devel@nongnu.org; Tue, 10 Jul 2018 11:43:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fcunS-0001a5-F9 for qemu-devel@nongnu.org; Tue, 10 Jul 2018 11:43:23 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:38810 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fcunO-0001XT-QR; Tue, 10 Jul 2018 11:43:18 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6218385629; Tue, 10 Jul 2018 15:43:18 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-156.ams2.redhat.com [10.36.116.156]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8FB842026D6B; Tue, 10 Jul 2018 15:43:17 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 10 Jul 2018 17:42:42 +0200 Message-Id: <20180710154304.18304-3-kwolf@redhat.com> In-Reply-To: <20180710154304.18304-1-kwolf@redhat.com> References: <20180710154304.18304-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Tue, 10 Jul 2018 15:43:18 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Tue, 10 Jul 2018 15:43:18 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 02/24] test-bdrv-drain: Test bdrv_append() to drained node X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Kevin Wolf --- tests/test-bdrv-drain.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c index 291a050f86..17bb8508ae 100644 --- a/tests/test-bdrv-drain.c +++ b/tests/test-bdrv-drain.c @@ -1250,6 +1250,47 @@ static void test_detach_by_driver_cb(void) test_detach_indirect(false); } =20 +static void test_append_to_drained(void) +{ + BlockBackend *blk; + BlockDriverState *base, *overlay; + BDRVTestState *base_s, *overlay_s; + + blk =3D blk_new(BLK_PERM_ALL, BLK_PERM_ALL); + base =3D bdrv_new_open_driver(&bdrv_test, "base", BDRV_O_RDWR, &error_= abort); + base_s =3D base->opaque; + blk_insert_bs(blk, base, &error_abort); + + overlay =3D bdrv_new_open_driver(&bdrv_test, "overlay", BDRV_O_RDWR, + &error_abort); + overlay_s =3D overlay->opaque; + + do_drain_begin(BDRV_DRAIN, base); + g_assert_cmpint(base->quiesce_counter, =3D=3D, 1); + g_assert_cmpint(base_s->drain_count, =3D=3D, 1); + g_assert_cmpint(base->in_flight, =3D=3D, 0); + + /* Takes ownership of overlay, so we don't have to unref it later */ + bdrv_append(overlay, base, &error_abort); + g_assert_cmpint(base->in_flight, =3D=3D, 0); + g_assert_cmpint(overlay->in_flight, =3D=3D, 0); + + g_assert_cmpint(base->quiesce_counter, =3D=3D, 1); + g_assert_cmpint(base_s->drain_count, =3D=3D, 1); + g_assert_cmpint(overlay->quiesce_counter, =3D=3D, 1); + g_assert_cmpint(overlay_s->drain_count, =3D=3D, 1); + + do_drain_end(BDRV_DRAIN, base); + + g_assert_cmpint(base->quiesce_counter, =3D=3D, 0); + g_assert_cmpint(base_s->drain_count, =3D=3D, 0); + g_assert_cmpint(overlay->quiesce_counter, =3D=3D, 0); + g_assert_cmpint(overlay_s->drain_count, =3D=3D, 0); + + bdrv_unref(base); + blk_unref(blk); +} + int main(int argc, char **argv) { int ret; @@ -1308,6 +1349,8 @@ int main(int argc, char **argv) g_test_add_func("/bdrv-drain/detach/parent_cb", test_detach_by_parent_= cb); g_test_add_func("/bdrv-drain/detach/driver_cb", test_detach_by_driver_= cb); =20 + g_test_add_func("/bdrv-drain/attach/drain", test_append_to_drained); + ret =3D g_test_run(); qemu_event_destroy(&done_event); return ret; --=20 2.13.6 From nobody Wed Apr 16 03:21:50 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 15312375237601023.3822070765713; Tue, 10 Jul 2018 08:45:23 -0700 (PDT) Received: from localhost ([::1]:48450 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fcupO-0006jM-Jo for importer@patchew.org; Tue, 10 Jul 2018 11:45:22 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44183) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fcunT-00051F-LQ for qemu-devel@nongnu.org; Tue, 10 Jul 2018 11:43:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fcunS-0001aD-K5 for qemu-devel@nongnu.org; Tue, 10 Jul 2018 11:43:23 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:47614 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fcunP-0001YB-Sq; Tue, 10 Jul 2018 11:43:19 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 70C9E8151D46; Tue, 10 Jul 2018 15:43:19 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-156.ams2.redhat.com [10.36.116.156]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9EC082026D6B; Tue, 10 Jul 2018 15:43:18 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 10 Jul 2018 17:42:43 +0200 Message-Id: <20180710154304.18304-4-kwolf@redhat.com> In-Reply-To: <20180710154304.18304-1-kwolf@redhat.com> References: <20180710154304.18304-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Tue, 10 Jul 2018 15:43:19 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Tue, 10 Jul 2018 15:43:19 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 03/24] block: Fix copy-on-read crash with partial final cluster X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" If the virtual disk size isn't aligned to full clusters, bdrv_co_do_copy_on_readv() may get pnum =3D=3D 0 before having the full cluster completed, which will let it run into an assertion failure: qemu-io: block/io.c:1203: bdrv_co_do_copy_on_readv: Assertion `skip_bytes <= pnum' failed. Check for EOF, assert that we read at least as much as the read request originally wanted to have (which is true at EOF because otherwise bdrv_check_byte_request() would already have returned an error) and return success early even though we couldn't copy the full cluster. Signed-off-by: Kevin Wolf --- block/io.c | 6 ++++++ tests/qemu-iotests/197 | 9 +++++++++ tests/qemu-iotests/197.out | 8 ++++++++ 3 files changed, 23 insertions(+) diff --git a/block/io.c b/block/io.c index 038449f81f..4c0831149c 100644 --- a/block/io.c +++ b/block/io.c @@ -1200,6 +1200,12 @@ static int coroutine_fn bdrv_co_do_copy_on_readv(Bdr= vChild *child, pnum =3D MIN(cluster_bytes, max_transfer); } =20 + /* Stop at EOF if the image ends in the middle of the cluster */ + if (ret =3D=3D 0 && pnum =3D=3D 0) { + assert(progress >=3D bytes); + break; + } + assert(skip_bytes < pnum); =20 if (ret <=3D 0) { diff --git a/tests/qemu-iotests/197 b/tests/qemu-iotests/197 index 3ae4975eec..0369aa5cff 100755 --- a/tests/qemu-iotests/197 +++ b/tests/qemu-iotests/197 @@ -109,6 +109,15 @@ $QEMU_IO -f qcow2 -c map "$TEST_WRAP" _check_test_img $QEMU_IMG compare -f $IMGFMT -F qcow2 "$TEST_IMG" "$TEST_WRAP" =20 +echo +echo '=3D=3D=3D Partial final cluster =3D=3D=3D' +echo + +_make_test_img 1024 +$QEMU_IO -f $IMGFMT -C -c 'read 0 1024' "$TEST_IMG" | _filter_qemu_io +$QEMU_IO -f $IMGFMT -c map "$TEST_IMG" +_check_test_img + # success, all done echo '*** done' status=3D0 diff --git a/tests/qemu-iotests/197.out b/tests/qemu-iotests/197.out index 52b4137d7b..8febda5dea 100644 --- a/tests/qemu-iotests/197.out +++ b/tests/qemu-iotests/197.out @@ -23,4 +23,12 @@ can't open device TEST_DIR/t.wrap.qcow2: Can't use copy-= on-read on read-only dev 1023.938 MiB (0x3fff0000) bytes not allocated at offset 3 GiB (0xc0010000) No errors were found on the image. Images are identical. + +=3D=3D=3D Partial final cluster =3D=3D=3D + +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1024 +read 1024/1024 bytes at offset 0 +1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +1 KiB (0x400) bytes allocated at offset 0 bytes (0x0) +No errors were found on the image. *** done --=20 2.13.6 From nobody Wed Apr 16 03:21:50 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1531238368005713.051627426292; Tue, 10 Jul 2018 08:59:28 -0700 (PDT) Received: from localhost ([::1]:48543 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fcv30-0001kj-Ub for importer@patchew.org; Tue, 10 Jul 2018 11:59:26 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44193) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fcunT-00051R-Tx for qemu-devel@nongnu.org; Tue, 10 Jul 2018 11:43:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fcunT-0001ab-6M for qemu-devel@nongnu.org; Tue, 10 Jul 2018 11:43:23 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:45876 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fcunQ-0001Yn-VT; Tue, 10 Jul 2018 11:43:21 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7FE7277889; Tue, 10 Jul 2018 15:43:20 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-156.ams2.redhat.com [10.36.116.156]) by smtp.corp.redhat.com (Postfix) with ESMTP id ADC922026D6B; Tue, 10 Jul 2018 15:43:19 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 10 Jul 2018 17:42:44 +0200 Message-Id: <20180710154304.18304-5-kwolf@redhat.com> In-Reply-To: <20180710154304.18304-1-kwolf@redhat.com> References: <20180710154304.18304-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Tue, 10 Jul 2018 15:43:20 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Tue, 10 Jul 2018 15:43:20 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 04/24] iotests: 222: Don't run with luks X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Fam Zheng Luks needs special parameters to operate the image. Since this test is focusing on image fleecing, skip skip that format. Signed-off-by: Fam Zheng Signed-off-by: Kevin Wolf --- tests/qemu-iotests/222 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/qemu-iotests/222 b/tests/qemu-iotests/222 index ff3bfc1470..0ead56d574 100644 --- a/tests/qemu-iotests/222 +++ b/tests/qemu-iotests/222 @@ -25,6 +25,8 @@ import iotests from iotests import log, qemu_img, qemu_io, qemu_io_silent =20 iotests.verify_platform(['linux']) +iotests.verify_image_format(supported_fmts=3D['qcow2', 'qcow', 'qed', 'vmd= k', + 'vhdx', 'raw']) =20 patterns =3D [("0x5d", "0", "64k"), ("0xd5", "1M", "64k"), --=20 2.13.6 From nobody Wed Apr 16 03:21:50 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1531238751271902.677840882951; Tue, 10 Jul 2018 09:05:51 -0700 (PDT) Received: from localhost ([::1]:48588 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fcv9C-0007KO-3w for importer@patchew.org; Tue, 10 Jul 2018 12:05:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44234) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fcunV-00053o-UF for qemu-devel@nongnu.org; Tue, 10 Jul 2018 11:43:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fcunU-0001be-ML for qemu-devel@nongnu.org; Tue, 10 Jul 2018 11:43:25 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:34316 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fcunS-0001Zb-1B; Tue, 10 Jul 2018 11:43:22 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8E781402315B; Tue, 10 Jul 2018 15:43:21 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-156.ams2.redhat.com [10.36.116.156]) by smtp.corp.redhat.com (Postfix) with ESMTP id BCA542026D6B; Tue, 10 Jul 2018 15:43:20 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 10 Jul 2018 17:42:45 +0200 Message-Id: <20180710154304.18304-6-kwolf@redhat.com> In-Reply-To: <20180710154304.18304-1-kwolf@redhat.com> References: <20180710154304.18304-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Tue, 10 Jul 2018 15:43:21 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Tue, 10 Jul 2018 15:43:21 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 05/24] block/io: fix copy_range X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy Here two things are fixed: 1. Architecture On each recursion step, we go to the child of src or dst, only for one of them. So, it's wrong to create tracked requests for both on each step. It leads to tracked requests duplication. 2. Wait for serializing requests on write path independently of BDRV_REQ_NO_SERIALISING Before commit 9ded4a01149 "backup: Use copy offloading", BDRV_REQ_NO_SERIALISING was used for only one case: read in copy-on-write operation during backup. Also, the flag was handled only on read path (in bdrv_co_preadv and bdrv_aligned_preadv). After 9ded4a01149, flag is used for not waiting serializing operations on backup target (in same case of copy-on-write operation). This behavior change is unsubstantiated and potentially dangerous, let's drop it and add additional asserts and documentation. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Fam Zheng Signed-off-by: Kevin Wolf --- include/block/block.h | 12 ++++++++++++ block/io.c | 42 +++++++++++++++++++++++++++--------------- 2 files changed, 39 insertions(+), 15 deletions(-) diff --git a/include/block/block.h b/include/block/block.h index 706ef009ad..f7ddff45b6 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -50,6 +50,18 @@ typedef enum { * opened with BDRV_O_UNMAP. */ BDRV_REQ_MAY_UNMAP =3D 0x4, + + /* + * The BDRV_REQ_NO_SERIALISING flag is only valid for reads and means = that + * we don't want wait_serialising_requests() during the read operation. + * + * This flag is used for backup copy-on-write operations, when we need= to + * read old data before write (write notifier triggered). It is okay s= ince + * we already waited for other serializing requests in the initiating = write + * (see bdrv_aligned_pwritev), and it is necessary if the initiating w= rite + * is already serializing (without the flag, the read would deadlock + * waiting for the serialising write to complete). + */ BDRV_REQ_NO_SERIALISING =3D 0x8, BDRV_REQ_FUA =3D 0x10, BDRV_REQ_WRITE_COMPRESSED =3D 0x20, diff --git a/block/io.c b/block/io.c index 4c0831149c..3a321d69d3 100644 --- a/block/io.c +++ b/block/io.c @@ -1592,6 +1592,8 @@ static int coroutine_fn bdrv_aligned_pwritev(BdrvChil= d *child, max_transfer =3D QEMU_ALIGN_DOWN(MIN_NON_ZERO(bs->bl.max_transfer, INT= _MAX), align); =20 + /* BDRV_REQ_NO_SERIALISING is only for read operation */ + assert(!(flags & BDRV_REQ_NO_SERIALISING)); waited =3D wait_serialising_requests(req); assert(!waited || !req->serialising); assert(req->overlap_offset <=3D offset); @@ -2916,7 +2918,7 @@ static int coroutine_fn bdrv_co_copy_range_internal(B= drvChild *src, BdrvRequestFlags flags, bool recurse_src) { - BdrvTrackedRequest src_req, dst_req; + BdrvTrackedRequest req; int ret; =20 if (!dst || !dst->bs) { @@ -2943,32 +2945,42 @@ static int coroutine_fn bdrv_co_copy_range_internal= (BdrvChild *src, || src->bs->encrypted || dst->bs->encrypted) { return -ENOTSUP; } - bdrv_inc_in_flight(src->bs); - bdrv_inc_in_flight(dst->bs); - tracked_request_begin(&src_req, src->bs, src_offset, - bytes, BDRV_TRACKED_READ); - tracked_request_begin(&dst_req, dst->bs, dst_offset, - bytes, BDRV_TRACKED_WRITE); =20 - if (!(flags & BDRV_REQ_NO_SERIALISING)) { - wait_serialising_requests(&src_req); - wait_serialising_requests(&dst_req); - } if (recurse_src) { + bdrv_inc_in_flight(src->bs); + tracked_request_begin(&req, src->bs, src_offset, bytes, + BDRV_TRACKED_READ); + + if (!(flags & BDRV_REQ_NO_SERIALISING)) { + wait_serialising_requests(&req); + } + ret =3D src->bs->drv->bdrv_co_copy_range_from(src->bs, src, src_offset, dst, dst_offset, bytes, flags); + + tracked_request_end(&req); + bdrv_dec_in_flight(src->bs); } else { + bdrv_inc_in_flight(dst->bs); + tracked_request_begin(&req, dst->bs, dst_offset, bytes, + BDRV_TRACKED_WRITE); + + /* BDRV_REQ_NO_SERIALISING is only for read operation, + * so we ignore it in flags. + */ + wait_serialising_requests(&req); + ret =3D dst->bs->drv->bdrv_co_copy_range_to(dst->bs, src, src_offset, dst, dst_offset, bytes, flags); + + tracked_request_end(&req); + bdrv_dec_in_flight(dst->bs); } - tracked_request_end(&src_req); - tracked_request_end(&dst_req); - bdrv_dec_in_flight(src->bs); - bdrv_dec_in_flight(dst->bs); + return ret; } =20 --=20 2.13.6 From nobody Wed Apr 16 03:21:50 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1531239132569385.072579452397; Tue, 10 Jul 2018 09:12:12 -0700 (PDT) Received: from localhost ([::1]:48702 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fcvF8-0004DZ-5c for importer@patchew.org; Tue, 10 Jul 2018 12:11:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44307) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fcunb-00057z-6u for qemu-devel@nongnu.org; Tue, 10 Jul 2018 11:43:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fcunY-0001dk-9c for qemu-devel@nongnu.org; Tue, 10 Jul 2018 11:43:31 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:38814 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fcunT-0001aV-6K; Tue, 10 Jul 2018 11:43:23 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BDDF285629; Tue, 10 Jul 2018 15:43:22 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-156.ams2.redhat.com [10.36.116.156]) by smtp.corp.redhat.com (Postfix) with ESMTP id CB3BC2026D6B; Tue, 10 Jul 2018 15:43:21 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 10 Jul 2018 17:42:46 +0200 Message-Id: <20180710154304.18304-7-kwolf@redhat.com> In-Reply-To: <20180710154304.18304-1-kwolf@redhat.com> References: <20180710154304.18304-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Tue, 10 Jul 2018 15:43:22 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Tue, 10 Jul 2018 15:43:22 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 06/24] block: split flags in copy_range X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy Pass read flags and write flags separately. This is needed to handle coming BDRV_REQ_NO_SERIALISING clearly in following patches. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Fam Zheng Signed-off-by: Kevin Wolf --- include/block/block.h | 3 ++- include/block/block_int.h | 14 +++++++++---- include/sysemu/block-backend.h | 3 ++- block/backup.c | 2 +- block/block-backend.c | 5 +++-- block/file-posix.c | 21 +++++++++++-------- block/io.c | 46 +++++++++++++++++++++++---------------= ---- block/iscsi.c | 9 ++++++--- block/qcow2.c | 20 +++++++++--------- block/raw-format.c | 24 ++++++++++++++-------- qemu-img.c | 2 +- 11 files changed, 90 insertions(+), 59 deletions(-) diff --git a/include/block/block.h b/include/block/block.h index f7ddff45b6..e474f2541b 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -699,5 +699,6 @@ void bdrv_unregister_buf(BlockDriverState *bs, void *ho= st); **/ int coroutine_fn bdrv_co_copy_range(BdrvChild *src, uint64_t src_offset, BdrvChild *dst, uint64_t dst_offset, - uint64_t bytes, BdrvRequestFlags flags= ); + uint64_t bytes, BdrvRequestFlags read_= flags, + BdrvRequestFlags write_flags); #endif diff --git a/include/block/block_int.h b/include/block/block_int.h index 81cd3db7a9..920d3d122b 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -218,7 +218,8 @@ struct BlockDriver { BdrvChild *dst, uint64_t dst_offset, uint64_t bytes, - BdrvRequestFlags flags); + BdrvRequestFlags read_flag= s, + BdrvRequestFlags write_fla= gs); =20 /* Map [offset, offset + nbytes) range onto a child of bs to copy data= to, * and invoke bdrv_co_copy_range_to(child, src, ...), or perform the c= opy @@ -234,7 +235,8 @@ struct BlockDriver { BdrvChild *dst, uint64_t dst_offset, uint64_t bytes, - BdrvRequestFlags flags); + BdrvRequestFlags read_flags, + BdrvRequestFlags write_flags= ); =20 /* * Building block for bdrv_block_status[_above] and @@ -1156,10 +1158,14 @@ void blockdev_close_all_bdrv_states(void); =20 int coroutine_fn bdrv_co_copy_range_from(BdrvChild *src, uint64_t src_offs= et, BdrvChild *dst, uint64_t dst_offs= et, - uint64_t bytes, BdrvRequestFlags = flags); + uint64_t bytes, + BdrvRequestFlags read_flags, + BdrvRequestFlags write_flags); int coroutine_fn bdrv_co_copy_range_to(BdrvChild *src, uint64_t src_offset, BdrvChild *dst, uint64_t dst_offset, - uint64_t bytes, BdrvRequestFlags fl= ags); + uint64_t bytes, + BdrvRequestFlags read_flags, + BdrvRequestFlags write_flags); =20 int refresh_total_sectors(BlockDriverState *bs, int64_t hint); =20 diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h index 8d03d493c2..830d873f24 100644 --- a/include/sysemu/block-backend.h +++ b/include/sysemu/block-backend.h @@ -234,6 +234,7 @@ void blk_unregister_buf(BlockBackend *blk, void *host); =20 int coroutine_fn blk_co_copy_range(BlockBackend *blk_in, int64_t off_in, BlockBackend *blk_out, int64_t off_out, - int bytes, BdrvRequestFlags flags); + int bytes, BdrvRequestFlags read_flags, + BdrvRequestFlags write_flags); =20 #endif diff --git a/block/backup.c b/block/backup.c index 81895ddbe2..f3e4e814b6 100644 --- a/block/backup.c +++ b/block/backup.c @@ -163,7 +163,7 @@ static int coroutine_fn backup_cow_with_offload(BackupB= lockJob *job, hbitmap_reset(job->copy_bitmap, start / job->cluster_size, nr_clusters); ret =3D blk_co_copy_range(blk, start, job->target, start, nbytes, - is_write_notifier ? BDRV_REQ_NO_SERIALISING : = 0); + is_write_notifier ? BDRV_REQ_NO_SERIALISING : = 0, 0); if (ret < 0) { trace_backup_do_cow_copy_range_fail(job, start, ret); hbitmap_set(job->copy_bitmap, start / job->cluster_size, diff --git a/block/block-backend.c b/block/block-backend.c index 6b75bca317..ac8c3e0b1c 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -2218,7 +2218,8 @@ void blk_unregister_buf(BlockBackend *blk, void *host) =20 int coroutine_fn blk_co_copy_range(BlockBackend *blk_in, int64_t off_in, BlockBackend *blk_out, int64_t off_out, - int bytes, BdrvRequestFlags flags) + int bytes, BdrvRequestFlags read_flags, + BdrvRequestFlags write_flags) { int r; r =3D blk_check_byte_request(blk_in, off_in, bytes); @@ -2231,5 +2232,5 @@ int coroutine_fn blk_co_copy_range(BlockBackend *blk_= in, int64_t off_in, } return bdrv_co_copy_range(blk_in->root, off_in, blk_out->root, off_out, - bytes, flags); + bytes, read_flags, write_flags); } diff --git a/block/file-posix.c b/block/file-posix.c index 98987b80f1..4fec8cb53c 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -2589,18 +2589,23 @@ static void raw_abort_perm_update(BlockDriverState = *bs) raw_handle_perm_lock(bs, RAW_PL_ABORT, 0, 0, NULL); } =20 -static int coroutine_fn raw_co_copy_range_from(BlockDriverState *bs, - BdrvChild *src, uint64_t sr= c_offset, - BdrvChild *dst, uint64_t ds= t_offset, - uint64_t bytes, BdrvRequest= Flags flags) +static int coroutine_fn raw_co_copy_range_from( + BlockDriverState *bs, BdrvChild *src, uint64_t src_offset, + BdrvChild *dst, uint64_t dst_offset, uint64_t bytes, + BdrvRequestFlags read_flags, BdrvRequestFlags write_flags) { - return bdrv_co_copy_range_to(src, src_offset, dst, dst_offset, bytes, = flags); + return bdrv_co_copy_range_to(src, src_offset, dst, dst_offset, bytes, + read_flags, write_flags); } =20 static int coroutine_fn raw_co_copy_range_to(BlockDriverState *bs, - BdrvChild *src, uint64_t src_= offset, - BdrvChild *dst, uint64_t dst_= offset, - uint64_t bytes, BdrvRequestFl= ags flags) + BdrvChild *src, + uint64_t src_offset, + BdrvChild *dst, + uint64_t dst_offset, + uint64_t bytes, + BdrvRequestFlags read_flags, + BdrvRequestFlags write_flags) { BDRVRawState *s =3D bs->opaque; BDRVRawState *src_s; diff --git a/block/io.c b/block/io.c index 3a321d69d3..75ab26fd58 100644 --- a/block/io.c +++ b/block/io.c @@ -2910,13 +2910,11 @@ void bdrv_unregister_buf(BlockDriverState *bs, void= *host) } } =20 -static int coroutine_fn bdrv_co_copy_range_internal(BdrvChild *src, - uint64_t src_offset, - BdrvChild *dst, - uint64_t dst_offset, - uint64_t bytes, - BdrvRequestFlags flags, - bool recurse_src) +static int coroutine_fn bdrv_co_copy_range_internal( + BdrvChild *src, uint64_t src_offset, BdrvChild *dst, + uint64_t dst_offset, uint64_t bytes, + BdrvRequestFlags read_flags, BdrvRequestFlags write_flags, + bool recurse_src) { BdrvTrackedRequest req; int ret; @@ -2928,8 +2926,8 @@ static int coroutine_fn bdrv_co_copy_range_internal(B= drvChild *src, if (ret) { return ret; } - if (flags & BDRV_REQ_ZERO_WRITE) { - return bdrv_co_pwrite_zeroes(dst, dst_offset, bytes, flags); + if (write_flags & BDRV_REQ_ZERO_WRITE) { + return bdrv_co_pwrite_zeroes(dst, dst_offset, bytes, write_flags); } =20 if (!src || !src->bs) { @@ -2951,14 +2949,15 @@ static int coroutine_fn bdrv_co_copy_range_internal= (BdrvChild *src, tracked_request_begin(&req, src->bs, src_offset, bytes, BDRV_TRACKED_READ); =20 - if (!(flags & BDRV_REQ_NO_SERIALISING)) { + if (!(read_flags & BDRV_REQ_NO_SERIALISING)) { wait_serialising_requests(&req); } =20 ret =3D src->bs->drv->bdrv_co_copy_range_from(src->bs, src, src_offset, dst, dst_offset, - bytes, flags); + bytes, + read_flags, write_flag= s); =20 tracked_request_end(&req); bdrv_dec_in_flight(src->bs); @@ -2967,15 +2966,15 @@ static int coroutine_fn bdrv_co_copy_range_internal= (BdrvChild *src, tracked_request_begin(&req, dst->bs, dst_offset, bytes, BDRV_TRACKED_WRITE); =20 - /* BDRV_REQ_NO_SERIALISING is only for read operation, - * so we ignore it in flags. - */ + /* BDRV_REQ_NO_SERIALISING is only for read operation */ + assert(!(write_flags & BDRV_REQ_NO_SERIALISING)); wait_serialising_requests(&req); =20 ret =3D dst->bs->drv->bdrv_co_copy_range_to(dst->bs, src, src_offset, dst, dst_offset, - bytes, flags); + bytes, + read_flags, write_flags); =20 tracked_request_end(&req); bdrv_dec_in_flight(dst->bs); @@ -2990,10 +2989,12 @@ static int coroutine_fn bdrv_co_copy_range_internal= (BdrvChild *src, * semantics. */ int coroutine_fn bdrv_co_copy_range_from(BdrvChild *src, uint64_t src_offs= et, BdrvChild *dst, uint64_t dst_offs= et, - uint64_t bytes, BdrvRequestFlags = flags) + uint64_t bytes, + BdrvRequestFlags read_flags, + BdrvRequestFlags write_flags) { return bdrv_co_copy_range_internal(src, src_offset, dst, dst_offset, - bytes, flags, true); + bytes, read_flags, write_flags, tru= e); } =20 /* Copy range from @src to @dst. @@ -3002,19 +3003,22 @@ int coroutine_fn bdrv_co_copy_range_from(BdrvChild = *src, uint64_t src_offset, * semantics. */ int coroutine_fn bdrv_co_copy_range_to(BdrvChild *src, uint64_t src_offset, BdrvChild *dst, uint64_t dst_offset, - uint64_t bytes, BdrvRequestFlags fl= ags) + uint64_t bytes, + BdrvRequestFlags read_flags, + BdrvRequestFlags write_flags) { return bdrv_co_copy_range_internal(src, src_offset, dst, dst_offset, - bytes, flags, false); + bytes, read_flags, write_flags, fal= se); } =20 int coroutine_fn bdrv_co_copy_range(BdrvChild *src, uint64_t src_offset, BdrvChild *dst, uint64_t dst_offset, - uint64_t bytes, BdrvRequestFlags flags) + uint64_t bytes, BdrvRequestFlags read_= flags, + BdrvRequestFlags write_flags) { return bdrv_co_copy_range_from(src, src_offset, dst, dst_offset, - bytes, flags); + bytes, read_flags, write_flags); } =20 static void bdrv_parent_cb_resize(BlockDriverState *bs) diff --git a/block/iscsi.c b/block/iscsi.c index ead2bd5aa7..38b917a1e5 100644 --- a/block/iscsi.c +++ b/block/iscsi.c @@ -2193,9 +2193,11 @@ static int coroutine_fn iscsi_co_copy_range_from(Blo= ckDriverState *bs, BdrvChild *dst, uint64_t dst_offset, uint64_t bytes, - BdrvRequestFlags flags) + BdrvRequestFlags read_fla= gs, + BdrvRequestFlags write_fl= ags) { - return bdrv_co_copy_range_to(src, src_offset, dst, dst_offset, bytes, = flags); + return bdrv_co_copy_range_to(src, src_offset, dst, dst_offset, bytes, + read_flags, write_flags); } =20 static struct scsi_task *iscsi_xcopy_task(int param_len) @@ -2332,7 +2334,8 @@ static int coroutine_fn iscsi_co_copy_range_to(BlockD= riverState *bs, BdrvChild *dst, uint64_t dst_offset, uint64_t bytes, - BdrvRequestFlags flags) + BdrvRequestFlags read_flags, + BdrvRequestFlags write_flag= s) { IscsiLun *dst_lun =3D dst->bs->opaque; IscsiLun *src_lun; diff --git a/block/qcow2.c b/block/qcow2.c index 33b61b7480..867ce02d50 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -3253,13 +3253,14 @@ static int coroutine_fn qcow2_co_copy_range_from(BlockDriverState *bs, BdrvChild *src, uint64_t src_offset, BdrvChild *dst, uint64_t dst_offset, - uint64_t bytes, BdrvRequestFlags flags) + uint64_t bytes, BdrvRequestFlags read_flags, + BdrvRequestFlags write_flags) { BDRVQcow2State *s =3D bs->opaque; int ret; unsigned int cur_bytes; /* number of bytes in current iteration */ BdrvChild *child =3D NULL; - BdrvRequestFlags cur_flags; + BdrvRequestFlags cur_write_flags; =20 assert(!bs->encrypted); qemu_co_mutex_lock(&s->lock); @@ -3268,7 +3269,7 @@ qcow2_co_copy_range_from(BlockDriverState *bs, uint64_t copy_offset =3D 0; /* prepare next request */ cur_bytes =3D MIN(bytes, INT_MAX); - cur_flags =3D flags; + cur_write_flags =3D write_flags; =20 ret =3D qcow2_get_cluster_offset(bs, src_offset, &cur_bytes, ©= _offset); if (ret < 0) { @@ -3280,20 +3281,20 @@ qcow2_co_copy_range_from(BlockDriverState *bs, if (bs->backing && bs->backing->bs) { int64_t backing_length =3D bdrv_getlength(bs->backing->bs); if (src_offset >=3D backing_length) { - cur_flags |=3D BDRV_REQ_ZERO_WRITE; + cur_write_flags |=3D BDRV_REQ_ZERO_WRITE; } else { child =3D bs->backing; cur_bytes =3D MIN(cur_bytes, backing_length - src_offs= et); copy_offset =3D src_offset; } } else { - cur_flags |=3D BDRV_REQ_ZERO_WRITE; + cur_write_flags |=3D BDRV_REQ_ZERO_WRITE; } break; =20 case QCOW2_CLUSTER_ZERO_PLAIN: case QCOW2_CLUSTER_ZERO_ALLOC: - cur_flags |=3D BDRV_REQ_ZERO_WRITE; + cur_write_flags |=3D BDRV_REQ_ZERO_WRITE; break; =20 case QCOW2_CLUSTER_COMPRESSED: @@ -3317,7 +3318,7 @@ qcow2_co_copy_range_from(BlockDriverState *bs, ret =3D bdrv_co_copy_range_from(child, copy_offset, dst, dst_offset, - cur_bytes, cur_flags); + cur_bytes, read_flags, cur_write_fla= gs); qemu_co_mutex_lock(&s->lock); if (ret < 0) { goto out; @@ -3338,7 +3339,8 @@ static int coroutine_fn qcow2_co_copy_range_to(BlockDriverState *bs, BdrvChild *src, uint64_t src_offset, BdrvChild *dst, uint64_t dst_offset, - uint64_t bytes, BdrvRequestFlags flags) + uint64_t bytes, BdrvRequestFlags read_flags, + BdrvRequestFlags write_flags) { BDRVQcow2State *s =3D bs->opaque; int offset_in_cluster; @@ -3382,7 +3384,7 @@ qcow2_co_copy_range_to(BlockDriverState *bs, ret =3D bdrv_co_copy_range_to(src, src_offset, bs->file, cluster_offset + offset_in_cluster, - cur_bytes, flags); + cur_bytes, read_flags, write_flags); qemu_co_mutex_lock(&s->lock); if (ret < 0) { goto fail; diff --git a/block/raw-format.c b/block/raw-format.c index b78da564d4..a3591985f6 100644 --- a/block/raw-format.c +++ b/block/raw-format.c @@ -498,9 +498,13 @@ static int raw_probe_geometry(BlockDriverState *bs, HD= Geometry *geo) } =20 static int coroutine_fn raw_co_copy_range_from(BlockDriverState *bs, - BdrvChild *src, uint64_t sr= c_offset, - BdrvChild *dst, uint64_t ds= t_offset, - uint64_t bytes, BdrvRequest= Flags flags) + BdrvChild *src, + uint64_t src_offset, + BdrvChild *dst, + uint64_t dst_offset, + uint64_t bytes, + BdrvRequestFlags read_flags, + BdrvRequestFlags write_flag= s) { int ret; =20 @@ -509,13 +513,17 @@ static int coroutine_fn raw_co_copy_range_from(BlockD= riverState *bs, return ret; } return bdrv_co_copy_range_from(bs->file, src_offset, dst, dst_offset, - bytes, flags); + bytes, read_flags, write_flags); } =20 static int coroutine_fn raw_co_copy_range_to(BlockDriverState *bs, - BdrvChild *src, uint64_t src_= offset, - BdrvChild *dst, uint64_t dst_= offset, - uint64_t bytes, BdrvRequestFl= ags flags) + BdrvChild *src, + uint64_t src_offset, + BdrvChild *dst, + uint64_t dst_offset, + uint64_t bytes, + BdrvRequestFlags read_flags, + BdrvRequestFlags write_flags) { int ret; =20 @@ -524,7 +532,7 @@ static int coroutine_fn raw_co_copy_range_to(BlockDrive= rState *bs, return ret; } return bdrv_co_copy_range_to(src, src_offset, bs->file, dst_offset, by= tes, - flags); + read_flags, write_flags); } =20 BlockDriver bdrv_raw =3D { diff --git a/qemu-img.c b/qemu-img.c index 7651d8172c..f4074ebf75 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -1783,7 +1783,7 @@ static int coroutine_fn convert_co_copy_range(ImgConv= ertState *s, int64_t sector =20 ret =3D blk_co_copy_range(blk, offset, s->target, sector_num << BDRV_SECTOR_BITS, - n << BDRV_SECTOR_BITS, 0); + n << BDRV_SECTOR_BITS, 0, 0); if (ret < 0) { return ret; } --=20 2.13.6 From nobody Wed Apr 16 03:21:50 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1531238944039470.52852434590955; Tue, 10 Jul 2018 09:09:04 -0700 (PDT) Received: from localhost ([::1]:48665 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fcvCI-0001OF-Gm for importer@patchew.org; Tue, 10 Jul 2018 12:09:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44309) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fcunb-000581-6v for qemu-devel@nongnu.org; Tue, 10 Jul 2018 11:43:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fcunX-0001ct-3s for qemu-devel@nongnu.org; Tue, 10 Jul 2018 11:43:31 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:45880 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fcunU-0001bJ-9q; Tue, 10 Jul 2018 11:43:24 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CE7C977889; Tue, 10 Jul 2018 15:43:23 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-156.ams2.redhat.com [10.36.116.156]) by smtp.corp.redhat.com (Postfix) with ESMTP id 06BDD2026D6B; Tue, 10 Jul 2018 15:43:22 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 10 Jul 2018 17:42:47 +0200 Message-Id: <20180710154304.18304-8-kwolf@redhat.com> In-Reply-To: <20180710154304.18304-1-kwolf@redhat.com> References: <20180710154304.18304-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Tue, 10 Jul 2018 15:43:23 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Tue, 10 Jul 2018 15:43:23 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 07/24] block: add BDRV_REQ_SERIALISING flag X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy Serialized writes should be used in copy-on-write of backup(sync=3Dnone) for image fleecing scheme. We need to change an assert in bdrv_aligned_pwritev, added in 28de2dcd88de. The assert may fail now, because call to wait_serialising_requests here may become first call to it for this request with serializing flag set. It occurs if the request is aligned (otherwise, we should already set serializing flag before calling bdrv_aligned_pwritev and correspondingly waited for all intersecting requests). However, for aligned requests, we should not care about outdating of previously read data, as there no such data. Therefore, let's just update an assert to not care about aligned requests. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Fam Zheng Signed-off-by: Kevin Wolf --- include/block/block.h | 14 +++++++++++++- block/io.c | 28 +++++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/include/block/block.h b/include/block/block.h index e474f2541b..a91f37bedf 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -70,8 +70,20 @@ typedef enum { * content. */ BDRV_REQ_WRITE_UNCHANGED =3D 0x40, =20 + /* + * BDRV_REQ_SERIALISING forces request serialisation for writes. + * It is used to ensure that writes to the backing file of a backup pr= ocess + * target cannot race with a read of the backup target that defers to = the + * backing file. + * + * Note, that BDRV_REQ_SERIALISING is _not_ opposite in meaning to + * BDRV_REQ_NO_SERIALISING. A more descriptive name for the latter mig= ht be + * _DO_NOT_WAIT_FOR_SERIALISING, except that is too long. + */ + BDRV_REQ_SERIALISING =3D 0x80, + /* Mask of valid flags */ - BDRV_REQ_MASK =3D 0x7f, + BDRV_REQ_MASK =3D 0xff, } BdrvRequestFlags; =20 typedef struct BlockSizes { diff --git a/block/io.c b/block/io.c index 75ab26fd58..6be9c40f23 100644 --- a/block/io.c +++ b/block/io.c @@ -637,6 +637,18 @@ static void mark_request_serialising(BdrvTrackedReques= t *req, uint64_t align) req->overlap_bytes =3D MAX(req->overlap_bytes, overlap_bytes); } =20 +static bool is_request_serialising_and_aligned(BdrvTrackedRequest *req) +{ + /* + * If the request is serialising, overlap_offset and overlap_bytes are= set, + * so we can check if the request is aligned. Otherwise, don't care and + * return false. + */ + + return req->serialising && (req->offset =3D=3D req->overlap_offset) && + (req->bytes =3D=3D req->overlap_bytes); +} + /** * Round a region to cluster boundaries */ @@ -1311,6 +1323,9 @@ static int coroutine_fn bdrv_aligned_preadv(BdrvChild= *child, mark_request_serialising(req, bdrv_get_cluster_size(bs)); } =20 + /* BDRV_REQ_SERIALISING is only for write operation */ + assert(!(flags & BDRV_REQ_SERIALISING)); + if (!(flags & BDRV_REQ_NO_SERIALISING)) { wait_serialising_requests(req); } @@ -1594,8 +1609,14 @@ static int coroutine_fn bdrv_aligned_pwritev(BdrvChi= ld *child, =20 /* BDRV_REQ_NO_SERIALISING is only for read operation */ assert(!(flags & BDRV_REQ_NO_SERIALISING)); + + if (flags & BDRV_REQ_SERIALISING) { + mark_request_serialising(req, bdrv_get_cluster_size(bs)); + } + waited =3D wait_serialising_requests(req); - assert(!waited || !req->serialising); + assert(!waited || !req->serialising || + is_request_serialising_and_aligned(req)); assert(req->overlap_offset <=3D offset); assert(offset + bytes <=3D req->overlap_offset + req->overlap_bytes); if (flags & BDRV_REQ_WRITE_UNCHANGED) { @@ -2949,6 +2970,8 @@ static int coroutine_fn bdrv_co_copy_range_internal( tracked_request_begin(&req, src->bs, src_offset, bytes, BDRV_TRACKED_READ); =20 + /* BDRV_REQ_SERIALISING is only for write operation */ + assert(!(read_flags & BDRV_REQ_SERIALISING)); if (!(read_flags & BDRV_REQ_NO_SERIALISING)) { wait_serialising_requests(&req); } @@ -2968,6 +2991,9 @@ static int coroutine_fn bdrv_co_copy_range_internal( =20 /* BDRV_REQ_NO_SERIALISING is only for read operation */ assert(!(write_flags & BDRV_REQ_NO_SERIALISING)); + if (write_flags & BDRV_REQ_SERIALISING) { + mark_request_serialising(&req, bdrv_get_cluster_size(dst->bs)); + } wait_serialising_requests(&req); =20 ret =3D dst->bs->drv->bdrv_co_copy_range_to(dst->bs, --=20 2.13.6 From nobody Wed Apr 16 03:21:50 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1531237761009616.7311918926204; Tue, 10 Jul 2018 08:49:21 -0700 (PDT) Received: from localhost ([::1]:48481 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fcutD-0001GV-PU for importer@patchew.org; Tue, 10 Jul 2018 11:49:19 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44311) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fcunb-000582-79 for qemu-devel@nongnu.org; Tue, 10 Jul 2018 11:43:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fcunY-0001dc-5D for qemu-devel@nongnu.org; Tue, 10 Jul 2018 11:43:31 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:45884 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fcunV-0001bm-Ad; Tue, 10 Jul 2018 11:43:25 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DC8AB77889; Tue, 10 Jul 2018 15:43:24 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-156.ams2.redhat.com [10.36.116.156]) by smtp.corp.redhat.com (Postfix) with ESMTP id 169832026D6B; Tue, 10 Jul 2018 15:43:23 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 10 Jul 2018 17:42:48 +0200 Message-Id: <20180710154304.18304-9-kwolf@redhat.com> In-Reply-To: <20180710154304.18304-1-kwolf@redhat.com> References: <20180710154304.18304-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Tue, 10 Jul 2018 15:43:24 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Tue, 10 Jul 2018 15:43:24 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 08/24] block/backup: fix fleecing scheme: use serialized writes X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy Fleecing scheme works as follows: we want a kind of temporary snapshot of active drive A. We create temporary image B, with B->backing =3D A. Then we start backup(sync=3Dnone) from A to B. From this point, B reads as point-in-time snapshot of A (A continues to be active drive, accepting guest IO). This scheme needs some additional synchronization between reads from B and backup COW operations, otherwise, the following situation is theoretically possible: (assume B is qcow2, client is NBD client, reading from B) 1. client starts reading and take qcow2 mutex in qcow2_co_preadv, and goes up to l2 table loading (assume cache miss) 2) guest write =3D> backup COW =3D> qcow2 write =3D> try to take qcow2 mutex =3D> waiting 3. l2 table loaded, we see that cluster is UNALLOCATED, go to "case QCOW2_CLUSTER_UNALLOCATED" and unlock mutex before bdrv_co_preadv(bs->backing, ...) 4) aha, mutex unlocked, backup COW continues, and we finally finish guest write and change cluster in our active disk A 5. actually, do bdrv_co_preadv(bs->backing, ...) and read _new updated_ data. To avoid this, let's make backup writes serializing, to not intersect with reads from B. Note: we expand range of handled cases from (sync=3Dnone and B->backing =3D A) to just (A in backing chain of B), to finally allow safe reading from B during backup for all cases when A in backing chain of B, i.e. B formally looks like point-in-time snapshot of A. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Fam Zheng Signed-off-by: Kevin Wolf --- block/backup.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/block/backup.c b/block/backup.c index f3e4e814b6..319fc922e8 100644 --- a/block/backup.c +++ b/block/backup.c @@ -47,6 +47,8 @@ typedef struct BackupBlockJob { HBitmap *copy_bitmap; bool use_copy_range; int64_t copy_range_size; + + bool serialize_target_writes; } BackupBlockJob; =20 static const BlockJobDriver backup_job_driver; @@ -102,6 +104,8 @@ static int coroutine_fn backup_cow_with_bounce_buffer(B= ackupBlockJob *job, QEMUIOVector qiov; BlockBackend *blk =3D job->common.blk; int nbytes; + int read_flags =3D is_write_notifier ? BDRV_REQ_NO_SERIALISING : 0; + int write_flags =3D job->serialize_target_writes ? BDRV_REQ_SERIALISIN= G : 0; =20 hbitmap_reset(job->copy_bitmap, start / job->cluster_size, 1); nbytes =3D MIN(job->cluster_size, job->len - start); @@ -112,8 +116,7 @@ static int coroutine_fn backup_cow_with_bounce_buffer(B= ackupBlockJob *job, iov.iov_len =3D nbytes; qemu_iovec_init_external(&qiov, &iov, 1); =20 - ret =3D blk_co_preadv(blk, start, qiov.size, &qiov, - is_write_notifier ? BDRV_REQ_NO_SERIALISING : 0); + ret =3D blk_co_preadv(blk, start, qiov.size, &qiov, read_flags); if (ret < 0) { trace_backup_do_cow_read_fail(job, start, ret); if (error_is_read) { @@ -124,11 +127,11 @@ static int coroutine_fn backup_cow_with_bounce_buffer= (BackupBlockJob *job, =20 if (qemu_iovec_is_zero(&qiov)) { ret =3D blk_co_pwrite_zeroes(job->target, start, - qiov.size, BDRV_REQ_MAY_UNMAP); + qiov.size, write_flags | BDRV_REQ_MAY_U= NMAP); } else { ret =3D blk_co_pwritev(job->target, start, - qiov.size, &qiov, - job->compress ? BDRV_REQ_WRITE_COMPRESSED : 0= ); + qiov.size, &qiov, write_flags | + (job->compress ? BDRV_REQ_WRITE_COMPRESSED : = 0)); } if (ret < 0) { trace_backup_do_cow_write_fail(job, start, ret); @@ -156,6 +159,8 @@ static int coroutine_fn backup_cow_with_offload(BackupB= lockJob *job, int nr_clusters; BlockBackend *blk =3D job->common.blk; int nbytes; + int read_flags =3D is_write_notifier ? BDRV_REQ_NO_SERIALISING : 0; + int write_flags =3D job->serialize_target_writes ? BDRV_REQ_SERIALISIN= G : 0; =20 assert(QEMU_IS_ALIGNED(job->copy_range_size, job->cluster_size)); nbytes =3D MIN(job->copy_range_size, end - start); @@ -163,7 +168,7 @@ static int coroutine_fn backup_cow_with_offload(BackupB= lockJob *job, hbitmap_reset(job->copy_bitmap, start / job->cluster_size, nr_clusters); ret =3D blk_co_copy_range(blk, start, job->target, start, nbytes, - is_write_notifier ? BDRV_REQ_NO_SERIALISING : = 0, 0); + read_flags, write_flags); if (ret < 0) { trace_backup_do_cow_copy_range_fail(job, start, ret); hbitmap_set(job->copy_bitmap, start / job->cluster_size, @@ -701,6 +706,9 @@ BlockJob *backup_job_create(const char *job_id, BlockDr= iverState *bs, sync_bitmap : NULL; job->compress =3D compress; =20 + /* Detect image-fleecing (and similar) schemes */ + job->serialize_target_writes =3D bdrv_chain_contains(target, bs); + /* If there is no backing file on the target, we cannot rely on COW if= our * backup cluster size is smaller than the target cluster size. Even f= or * targets with a backing file, try to avoid COW if possible. */ --=20 2.13.6 From nobody Wed Apr 16 03:21:50 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1531237861490652.1505232527279; Tue, 10 Jul 2018 08:51:01 -0700 (PDT) Received: from localhost ([::1]:48493 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fcuuq-0002cD-CB for importer@patchew.org; Tue, 10 Jul 2018 11:51:00 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44348) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fcunc-00059r-H4 for qemu-devel@nongnu.org; Tue, 10 Jul 2018 11:43:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fcunb-0001fX-L7 for qemu-devel@nongnu.org; Tue, 10 Jul 2018 11:43:32 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:38820 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fcunW-0001cO-DN; Tue, 10 Jul 2018 11:43:26 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EBA18DFEB; Tue, 10 Jul 2018 15:43:25 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-156.ams2.redhat.com [10.36.116.156]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2549A2026D6B; Tue, 10 Jul 2018 15:43:25 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 10 Jul 2018 17:42:49 +0200 Message-Id: <20180710154304.18304-10-kwolf@redhat.com> In-Reply-To: <20180710154304.18304-1-kwolf@redhat.com> References: <20180710154304.18304-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Tue, 10 Jul 2018 15:43:25 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Tue, 10 Jul 2018 15:43:25 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 09/24] qapi/block-core.json: Add missing documentation for blklogwrites log-append option X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Ari Sundholm This was accidentally omitted. Thanks to Eric Blake for spotting this. Signed-off-by: Ari Sundholm Reviewed-by: Eric Blake Signed-off-by: Kevin Wolf --- qapi/block-core.json | 2 ++ 1 file changed, 2 insertions(+) diff --git a/qapi/block-core.json b/qapi/block-core.json index 38b31250f9..62a92fa4f4 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -3057,6 +3057,8 @@ # @log-sector-size: sector size used in logging writes to @file, determines # granularity of offsets and sizes of writes (default: 5= 12) # +# @log-append: append to an existing log (default: false) +# # @log-super-update-interval: interval of write requests after which the l= og # super block is updated to disk (default: 409= 6) # --=20 2.13.6 From nobody Wed Apr 16 03:21:50 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1531238034076350.87663508378614; Tue, 10 Jul 2018 08:53:54 -0700 (PDT) Received: from localhost ([::1]:48507 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fcuxc-0004tc-Ri for importer@patchew.org; Tue, 10 Jul 2018 11:53:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44382) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fcund-0005BJ-Oy for qemu-devel@nongnu.org; Tue, 10 Jul 2018 11:43:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fcunc-0001g9-Fr for qemu-devel@nongnu.org; Tue, 10 Jul 2018 11:43:33 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:47624 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fcunX-0001cx-Eu; Tue, 10 Jul 2018 11:43:27 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 06810808255B; Tue, 10 Jul 2018 15:43:27 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-156.ams2.redhat.com [10.36.116.156]) by smtp.corp.redhat.com (Postfix) with ESMTP id 344442026D6B; Tue, 10 Jul 2018 15:43:26 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 10 Jul 2018 17:42:50 +0200 Message-Id: <20180710154304.18304-11-kwolf@redhat.com> In-Reply-To: <20180710154304.18304-1-kwolf@redhat.com> References: <20180710154304.18304-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Tue, 10 Jul 2018 15:43:27 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Tue, 10 Jul 2018 15:43:27 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 10/24] block/blklogwrites: Make sure the log sector size is not too small X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Ari Sundholm The sector size needs to be large enough to accommodate the data structures for the log super block and log write entries. This was previously not properly checked, which made it possible to cause QEMU to badly misbehave. Signed-off-by: Ari Sundholm Signed-off-by: Kevin Wolf --- block/blklogwrites.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/block/blklogwrites.c b/block/blklogwrites.c index 63bf6b34a9..efa2c7a66a 100644 --- a/block/blklogwrites.c +++ b/block/blklogwrites.c @@ -89,7 +89,10 @@ static inline uint32_t blk_log_writes_log2(uint32_t valu= e) =20 static inline bool blk_log_writes_sector_size_valid(uint32_t sector_size) { - return sector_size < (1ull << 24) && is_power_of_2(sector_size); + return is_power_of_2(sector_size) && + sector_size >=3D sizeof(struct log_write_super) && + sector_size >=3D sizeof(struct log_write_entry) && + sector_size < (1ull << 24); } =20 static uint64_t blk_log_writes_find_cur_log_sector(BdrvChild *log, --=20 2.13.6 From nobody Wed Apr 16 03:21:50 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1531239279959663.1105635475978; Tue, 10 Jul 2018 09:14:39 -0700 (PDT) Received: from localhost ([::1]:48723 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fcvHa-0006Nq-10 for importer@patchew.org; Tue, 10 Jul 2018 12:14:30 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44380) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fcund-0005BH-Mt for qemu-devel@nongnu.org; Tue, 10 Jul 2018 11:43:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fcunc-0001g2-FX for qemu-devel@nongnu.org; Tue, 10 Jul 2018 11:43:33 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:47628 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fcunY-0001dh-GZ; Tue, 10 Jul 2018 11:43:28 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 14F72808255B; Tue, 10 Jul 2018 15:43:28 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-156.ams2.redhat.com [10.36.116.156]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4360E2026D6B; Tue, 10 Jul 2018 15:43:27 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 10 Jul 2018 17:42:51 +0200 Message-Id: <20180710154304.18304-12-kwolf@redhat.com> In-Reply-To: <20180710154304.18304-1-kwolf@redhat.com> References: <20180710154304.18304-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Tue, 10 Jul 2018 15:43:28 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Tue, 10 Jul 2018 15:43:28 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 11/24] Revert "block: Remove dead deprecation warning code" X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Cornelia Huck This reverts commit 6266e900b8083945cb766b45c124fb3c42932cb3. Some deprecated -drive options were still in use by libvirt, only fixed with libvirt commit b340c6c614 ("qemu: format serial and geometry on frontend disk device"), which is not yet in any released version of libvirt. So let's hold off removing the deprecated options for one more QEMU release. Reported-by: Christian Borntraeger Signed-off-by: Cornelia Huck Signed-off-by: Kevin Wolf --- blockdev.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/blockdev.c b/blockdev.c index 72f5347df5..37eb40670b 100644 --- a/blockdev.c +++ b/blockdev.c @@ -775,6 +775,8 @@ DriveInfo *drive_new(QemuOpts *all_opts, BlockInterface= Type block_default_type) const char *filename; Error *local_err =3D NULL; int i; + const char *deprecated[] =3D { + }; =20 /* Change legacy command line options into QMP ones */ static const struct { @@ -851,6 +853,16 @@ DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfac= eType block_default_type) goto fail; } =20 + /* Other deprecated options */ + if (!qtest_enabled()) { + for (i =3D 0; i < ARRAY_SIZE(deprecated); i++) { + if (qemu_opt_get(legacy_opts, deprecated[i]) !=3D NULL) { + error_report("'%s' is deprecated, please use the correspon= ding " + "option of '-device' instead", deprecated[i]); + } + } + } + /* Media type */ value =3D qemu_opt_get(legacy_opts, "media"); if (value) { --=20 2.13.6 From nobody Wed Apr 16 03:21:50 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1531237776768520.6276607674748; Tue, 10 Jul 2018 08:49:36 -0700 (PDT) Received: from localhost ([::1]:48483 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fcutQ-0001NA-FJ for importer@patchew.org; Tue, 10 Jul 2018 11:49:32 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44428) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fcunf-0005E5-Pg for qemu-devel@nongnu.org; Tue, 10 Jul 2018 11:43:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fcune-0001hG-4W for qemu-devel@nongnu.org; Tue, 10 Jul 2018 11:43:35 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:60786 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fcunZ-0001eF-MY; Tue, 10 Jul 2018 11:43:29 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 239B7407048A; Tue, 10 Jul 2018 15:43:29 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-156.ams2.redhat.com [10.36.116.156]) by smtp.corp.redhat.com (Postfix) with ESMTP id 51A082026D6B; Tue, 10 Jul 2018 15:43:28 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 10 Jul 2018 17:42:52 +0200 Message-Id: <20180710154304.18304-13-kwolf@redhat.com> In-Reply-To: <20180710154304.18304-1-kwolf@redhat.com> References: <20180710154304.18304-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Tue, 10 Jul 2018 15:43:29 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Tue, 10 Jul 2018 15:43:29 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 12/24] Revert "block: Remove deprecated -drive option serial" X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Cornelia Huck This reverts commit b0083267444a5e0f28391f6c2831a539f878d424. Hold off removing this for one more QEMU release (current libvirt release still uses it.) Signed-off-by: Cornelia Huck Signed-off-by: Kevin Wolf --- include/hw/block/block.h | 1 + include/sysemu/blockdev.h | 1 + block/block-backend.c | 1 + blockdev.c | 10 ++++++++++ hw/block/block.c | 13 +++++++++++++ hw/block/nvme.c | 1 + hw/block/virtio-blk.c | 1 + hw/ide/qdev.c | 1 + hw/scsi/scsi-disk.c | 1 + hw/usb/dev-storage.c | 1 + tests/ahci-test.c | 6 +++--- tests/ide-test.c | 8 ++++---- qemu-doc.texi | 5 +++++ qemu-options.hx | 6 +++++- 14 files changed, 48 insertions(+), 8 deletions(-) diff --git a/include/hw/block/block.h b/include/hw/block/block.h index e9f9e2223f..d4f4dfffab 100644 --- a/include/hw/block/block.h +++ b/include/hw/block/block.h @@ -72,6 +72,7 @@ static inline unsigned int get_physical_block_exp(BlockCo= nf *conf) =20 /* Configuration helpers */ =20 +void blkconf_serial(BlockConf *conf, char **serial); bool blkconf_geometry(BlockConf *conf, int *trans, unsigned cyls_max, unsigned heads_max, unsigned secs= _max, Error **errp); diff --git a/include/sysemu/blockdev.h b/include/sysemu/blockdev.h index 24954b94e0..c0ae3700ec 100644 --- a/include/sysemu/blockdev.h +++ b/include/sysemu/blockdev.h @@ -35,6 +35,7 @@ struct DriveInfo { bool is_default; /* Added by default_drive() ? */ int media_cd; QemuOpts *opts; + char *serial; QTAILQ_ENTRY(DriveInfo) next; }; =20 diff --git a/block/block-backend.c b/block/block-backend.c index ac8c3e0b1c..e94e3d5929 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -419,6 +419,7 @@ static void drive_info_del(DriveInfo *dinfo) return; } qemu_opts_del(dinfo->opts); + g_free(dinfo->serial); g_free(dinfo); } =20 diff --git a/blockdev.c b/blockdev.c index 37eb40670b..6c530769fd 100644 --- a/blockdev.c +++ b/blockdev.c @@ -731,6 +731,10 @@ QemuOptsList qemu_legacy_drive_opts =3D { .type =3D QEMU_OPT_STRING, .help =3D "interface (ide, scsi, sd, mtd, floppy, pflash, virt= io)", },{ + .name =3D "serial", + .type =3D QEMU_OPT_STRING, + .help =3D "disk serial number", + },{ .name =3D "file", .type =3D QEMU_OPT_STRING, .help =3D "file name", @@ -772,10 +776,12 @@ DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfa= ceType block_default_type) const char *werror, *rerror; bool read_only =3D false; bool copy_on_read; + const char *serial; const char *filename; Error *local_err =3D NULL; int i; const char *deprecated[] =3D { + "serial" }; =20 /* Change legacy command line options into QMP ones */ @@ -943,6 +949,9 @@ DriveInfo *drive_new(QemuOpts *all_opts, BlockInterface= Type block_default_type) goto fail; } =20 + /* Serial number */ + serial =3D qemu_opt_get(legacy_opts, "serial"); + /* no id supplied -> create one */ if (qemu_opts_id(all_opts) =3D=3D NULL) { char *new_id; @@ -1017,6 +1026,7 @@ DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfa= ceType block_default_type) dinfo->type =3D type; dinfo->bus =3D bus_id; dinfo->unit =3D unit_id; + dinfo->serial =3D g_strdup(serial); =20 blk_set_legacy_dinfo(blk, dinfo); =20 diff --git a/hw/block/block.c b/hw/block/block.c index cf0eb826f1..b6c80ab0b7 100644 --- a/hw/block/block.c +++ b/hw/block/block.c @@ -15,6 +15,19 @@ #include "qapi/qapi-types-block.h" #include "qemu/error-report.h" =20 +void blkconf_serial(BlockConf *conf, char **serial) +{ + DriveInfo *dinfo; + + if (!*serial) { + /* try to fall back to value set with legacy -drive serial=3D... */ + dinfo =3D blk_legacy_dinfo(conf->blk); + if (dinfo) { + *serial =3D g_strdup(dinfo->serial); + } + } +} + void blkconf_blocksizes(BlockConf *conf) { BlockBackend *blk =3D conf->blk; diff --git a/hw/block/nvme.c b/hw/block/nvme.c index fc7dacb816..5e508ab1b3 100644 --- a/hw/block/nvme.c +++ b/hw/block/nvme.c @@ -1217,6 +1217,7 @@ static void nvme_realize(PCIDevice *pci_dev, Error **= errp) return; } =20 + blkconf_serial(&n->conf, &n->serial); if (!n->serial) { error_setg(errp, "serial property not set"); return; diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index 225fe44b7a..50b5c869e3 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -935,6 +935,7 @@ static void virtio_blk_device_realize(DeviceState *dev,= Error **errp) return; } =20 + blkconf_serial(&conf->conf, &conf->serial); if (!blkconf_apply_backend_options(&conf->conf, blk_is_read_only(conf->conf.blk), t= rue, errp)) { diff --git a/hw/ide/qdev.c b/hw/ide/qdev.c index 573b022e1e..f395d24592 100644 --- a/hw/ide/qdev.c +++ b/hw/ide/qdev.c @@ -188,6 +188,7 @@ static void ide_dev_initfn(IDEDevice *dev, IDEDriveKind= kind, Error **errp) return; } =20 + blkconf_serial(&dev->conf, &dev->serial); if (kind !=3D IDE_CD) { if (!blkconf_geometry(&dev->conf, &dev->chs_trans, 65535, 16, 255, errp)) { diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c index 32f3f96ff8..d7df357029 100644 --- a/hw/scsi/scsi-disk.c +++ b/hw/scsi/scsi-disk.c @@ -2378,6 +2378,7 @@ static void scsi_realize(SCSIDevice *dev, Error **err= p) return; } =20 + blkconf_serial(&s->qdev.conf, &s->serial); blkconf_blocksizes(&s->qdev.conf); =20 if (s->qdev.conf.logical_block_size > diff --git a/hw/usb/dev-storage.c b/hw/usb/dev-storage.c index cd5551d94f..45a9487cdb 100644 --- a/hw/usb/dev-storage.c +++ b/hw/usb/dev-storage.c @@ -599,6 +599,7 @@ static void usb_msd_storage_realize(USBDevice *dev, Err= or **errp) return; } =20 + blkconf_serial(&s->conf, &dev->serial); blkconf_blocksizes(&s->conf); if (!blkconf_apply_backend_options(&s->conf, blk_is_read_only(blk), tr= ue, errp)) { diff --git a/tests/ahci-test.c b/tests/ahci-test.c index 937ed2f910..1a7b761304 100644 --- a/tests/ahci-test.c +++ b/tests/ahci-test.c @@ -180,12 +180,12 @@ static AHCIQState *ahci_boot(const char *cli, ...) s =3D ahci_vboot(cli, ap); va_end(ap); } else { - cli =3D "-drive if=3Dnone,id=3Ddrive0,file=3D%s,cache=3Dwriteback,= format=3D%s" + cli =3D "-drive if=3Dnone,id=3Ddrive0,file=3D%s,cache=3Dwriteback,= serial=3D%s" + ",format=3D%s" " -M q35 " "-device ide-hd,drive=3Ddrive0 " - "-global ide-hd.serial=3D%s " "-global ide-hd.ver=3D%s"; - s =3D ahci_boot(cli, tmp_path, imgfmt, "testdisk", "version"); + s =3D ahci_boot(cli, tmp_path, "testdisk", imgfmt, "version"); } =20 return s; diff --git a/tests/ide-test.c b/tests/ide-test.c index f39431b1a9..2384c2c3e2 100644 --- a/tests/ide-test.c +++ b/tests/ide-test.c @@ -529,8 +529,8 @@ static void test_bmdma_no_busmaster(void) static void test_bmdma_setup(void) { ide_test_start( - "-drive file=3D%s,if=3Dide,cache=3Dwriteback,format=3Draw " - "-global ide-hd.serial=3D%s -global ide-hd.ver=3D%s", + "-drive file=3D%s,if=3Dide,serial=3D%s,cache=3Dwriteback,format=3D= raw " + "-global ide-hd.ver=3D%s", tmp_path, "testdisk", "version"); qtest_irq_intercept_in(global_qtest, "ioapic"); } @@ -561,8 +561,8 @@ static void test_identify(void) int ret; =20 ide_test_start( - "-drive file=3D%s,if=3Dide,cache=3Dwriteback,format=3Draw " - "-global ide-hd.serial=3D%s -global ide-hd.ver=3D%s", + "-drive file=3D%s,if=3Dide,serial=3D%s,cache=3Dwriteback,format=3D= raw " + "-global ide-hd.ver=3D%s", tmp_path, "testdisk", "version"); =20 dev =3D get_pci_device(&bmdma_bar, &ide_bar); diff --git a/qemu-doc.texi b/qemu-doc.texi index d3924e928e..d343affd6d 100644 --- a/qemu-doc.texi +++ b/qemu-doc.texi @@ -2887,6 +2887,11 @@ with ``-device ...,netdev=3Dx''), or ``-nic user,smb= =3D/some/dir'' (for embedded NICs). The new syntax allows different settings to be provided per NIC. =20 +@subsection -drive serial=3D... (since 2.10.0) + +The drive serial argument is replaced by the the serial argument +that can be specified with the ``-device'' parameter. + @subsection -usbdevice (since 2.10.0) =20 The ``-usbdevice DEV'' argument is now a synonym for setting diff --git a/qemu-options.hx b/qemu-options.hx index 16208f63f2..381648b9cb 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -805,7 +805,7 @@ ETEXI DEF("drive", HAS_ARG, QEMU_OPTION_drive, "-drive [file=3Dfile][,if=3Dtype][,bus=3Dn][,unit=3Dm][,media=3Dd][,in= dex=3Di]\n" " [,cache=3Dwritethrough|writeback|none|directsync|unsafe][,form= at=3Df]\n" - " [,snapshot=3Don|off][,rerror=3Dignore|stop|report]\n" + " [,snapshot=3Don|off][,serial=3Ds][,rerror=3Dignore|stop|report= ]\n" " [,werror=3Dignore|stop|report|enospc][,id=3Dname][,aio=3Dthrea= ds|native]\n" " [,readonly=3Don|off][,copy-on-read=3Don|off]\n" " [,discard=3Dignore|unmap][,detect-zeroes=3Don|off|unmap]\n" @@ -879,6 +879,10 @@ The default mode is @option{cache=3Dwriteback}. Specify which disk @var{format} will be used rather than detecting the format. Can be used to specify format=3Draw to avoid interpreting an untrusted format header. +@item serial=3D@var{serial} +This option specifies the serial number to assign to the device. This +parameter is deprecated, use the corresponding parameter of @code{-device} +instead. @item werror=3D@var{action},rerror=3D@var{action} Specify which @var{action} to take on write and read errors. Valid actions= are: "ignore" (ignore the error and try to continue), "stop" (pause QEMU), --=20 2.13.6 From nobody Wed Apr 16 03:21:50 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1531239387532658.9320834317049; Tue, 10 Jul 2018 09:16:27 -0700 (PDT) Received: from localhost ([::1]:48739 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fcvJP-0008La-30 for importer@patchew.org; Tue, 10 Jul 2018 12:16:23 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44417) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fcunf-0005DN-8E for qemu-devel@nongnu.org; Tue, 10 Jul 2018 11:43:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fcune-0001h9-2q for qemu-devel@nongnu.org; Tue, 10 Jul 2018 11:43:35 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:45890 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fcuna-0001ej-Kr; Tue, 10 Jul 2018 11:43:30 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 326D577889; Tue, 10 Jul 2018 15:43:30 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-156.ams2.redhat.com [10.36.116.156]) by smtp.corp.redhat.com (Postfix) with ESMTP id 60A7C2026D6B; Tue, 10 Jul 2018 15:43:29 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 10 Jul 2018 17:42:53 +0200 Message-Id: <20180710154304.18304-14-kwolf@redhat.com> In-Reply-To: <20180710154304.18304-1-kwolf@redhat.com> References: <20180710154304.18304-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Tue, 10 Jul 2018 15:43:30 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Tue, 10 Jul 2018 15:43:30 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 13/24] Revert "block: Remove deprecated -drive option addr" X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Cornelia Huck This reverts commit eae3bd1eb7c6b105d30ec06008b3bc3dfc5f45bb. Reverted to avoid conflicts for geometry options revert. Signed-off-by: Cornelia Huck Signed-off-by: Kevin Wolf --- include/sysemu/blockdev.h | 1 + blockdev.c | 17 ++++++++++++++++- device-hotplug.c | 4 ++++ qemu-doc.texi | 5 +++++ qemu-options.hx | 5 ++++- 5 files changed, 30 insertions(+), 2 deletions(-) diff --git a/include/sysemu/blockdev.h b/include/sysemu/blockdev.h index c0ae3700ec..37ea39719e 100644 --- a/include/sysemu/blockdev.h +++ b/include/sysemu/blockdev.h @@ -28,6 +28,7 @@ typedef enum { } BlockInterfaceType; =20 struct DriveInfo { + const char *devaddr; BlockInterfaceType type; int bus; int unit; diff --git a/blockdev.c b/blockdev.c index 6c530769fd..c23587b075 100644 --- a/blockdev.c +++ b/blockdev.c @@ -731,6 +731,10 @@ QemuOptsList qemu_legacy_drive_opts =3D { .type =3D QEMU_OPT_STRING, .help =3D "interface (ide, scsi, sd, mtd, floppy, pflash, virt= io)", },{ + .name =3D "addr", + .type =3D QEMU_OPT_STRING, + .help =3D "pci address (virtio only)", + },{ .name =3D "serial", .type =3D QEMU_OPT_STRING, .help =3D "disk serial number", @@ -773,6 +777,7 @@ DriveInfo *drive_new(QemuOpts *all_opts, BlockInterface= Type block_default_type) DriveMediaType media =3D MEDIA_DISK; BlockInterfaceType type; int max_devs, bus_id, unit_id, index; + const char *devaddr; const char *werror, *rerror; bool read_only =3D false; bool copy_on_read; @@ -781,7 +786,7 @@ DriveInfo *drive_new(QemuOpts *all_opts, BlockInterface= Type block_default_type) Error *local_err =3D NULL; int i; const char *deprecated[] =3D { - "serial" + "serial", "addr" }; =20 /* Change legacy command line options into QMP ones */ @@ -971,6 +976,12 @@ DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfac= eType block_default_type) } =20 /* Add virtio block device */ + devaddr =3D qemu_opt_get(legacy_opts, "addr"); + if (devaddr && type !=3D IF_VIRTIO) { + error_report("addr is not supported by this bus type"); + goto fail; + } + if (type =3D=3D IF_VIRTIO) { QemuOpts *devopts; devopts =3D qemu_opts_create(qemu_find_opts("device"), NULL, 0, @@ -982,6 +993,9 @@ DriveInfo *drive_new(QemuOpts *all_opts, BlockInterface= Type block_default_type) } qemu_opt_set(devopts, "drive", qdict_get_str(bs_opts, "id"), &error_abort); + if (devaddr) { + qemu_opt_set(devopts, "addr", devaddr, &error_abort); + } } =20 filename =3D qemu_opt_get(legacy_opts, "file"); @@ -1026,6 +1040,7 @@ DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfa= ceType block_default_type) dinfo->type =3D type; dinfo->bus =3D bus_id; dinfo->unit =3D unit_id; + dinfo->devaddr =3D devaddr; dinfo->serial =3D g_strdup(serial); =20 blk_set_legacy_dinfo(blk, dinfo); diff --git a/device-hotplug.c b/device-hotplug.c index cd427e2c76..23fd6656f1 100644 --- a/device-hotplug.c +++ b/device-hotplug.c @@ -69,6 +69,10 @@ void hmp_drive_add(Monitor *mon, const QDict *qdict) if (!dinfo) { goto err; } + if (dinfo->devaddr) { + monitor_printf(mon, "Parameter addr not supported\n"); + goto err; + } =20 switch (dinfo->type) { case IF_NONE: diff --git a/qemu-doc.texi b/qemu-doc.texi index d343affd6d..ae5531a053 100644 --- a/qemu-doc.texi +++ b/qemu-doc.texi @@ -2892,6 +2892,11 @@ provided per NIC. The drive serial argument is replaced by the the serial argument that can be specified with the ``-device'' parameter. =20 +@subsection -drive addr=3D... (since 2.10.0) + +The drive addr argument is replaced by the the addr argument +that can be specified with the ``-device'' parameter. + @subsection -usbdevice (since 2.10.0) =20 The ``-usbdevice DEV'' argument is now a synonym for setting diff --git a/qemu-options.hx b/qemu-options.hx index 381648b9cb..df248d1568 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -805,7 +805,7 @@ ETEXI DEF("drive", HAS_ARG, QEMU_OPTION_drive, "-drive [file=3Dfile][,if=3Dtype][,bus=3Dn][,unit=3Dm][,media=3Dd][,in= dex=3Di]\n" " [,cache=3Dwritethrough|writeback|none|directsync|unsafe][,form= at=3Df]\n" - " [,snapshot=3Don|off][,serial=3Ds][,rerror=3Dignore|stop|report= ]\n" + " [,snapshot=3Don|off][,serial=3Ds][,addr=3DA][,rerror=3Dignore|= stop|report]\n" " [,werror=3Dignore|stop|report|enospc][,id=3Dname][,aio=3Dthrea= ds|native]\n" " [,readonly=3Don|off][,copy-on-read=3Don|off]\n" " [,discard=3Dignore|unmap][,detect-zeroes=3Don|off|unmap]\n" @@ -883,6 +883,9 @@ an untrusted format header. This option specifies the serial number to assign to the device. This parameter is deprecated, use the corresponding parameter of @code{-device} instead. +@item addr=3D@var{addr} +Specify the controller's PCI address (if=3Dvirtio only). This parameter is +deprecated, use the corresponding parameter of @code{-device} instead. @item werror=3D@var{action},rerror=3D@var{action} Specify which @var{action} to take on write and read errors. Valid actions= are: "ignore" (ignore the error and try to continue), "stop" (pause QEMU), --=20 2.13.6 From nobody Wed Apr 16 03:21:50 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1531239519386282.57433873971036; Tue, 10 Jul 2018 09:18:39 -0700 (PDT) Received: from localhost ([::1]:48753 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fcvLa-0001P7-Dh for importer@patchew.org; Tue, 10 Jul 2018 12:18:38 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44488) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fcuni-0005H3-9R for qemu-devel@nongnu.org; Tue, 10 Jul 2018 11:43:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fcung-0001ic-FV for qemu-devel@nongnu.org; Tue, 10 Jul 2018 11:43:38 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:34324 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fcunc-0001fS-0u; Tue, 10 Jul 2018 11:43:32 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 433FB402315B; Tue, 10 Jul 2018 15:43:31 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-156.ams2.redhat.com [10.36.116.156]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6FB4A2026D6B; Tue, 10 Jul 2018 15:43:30 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 10 Jul 2018 17:42:54 +0200 Message-Id: <20180710154304.18304-15-kwolf@redhat.com> In-Reply-To: <20180710154304.18304-1-kwolf@redhat.com> References: <20180710154304.18304-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Tue, 10 Jul 2018 15:43:31 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Tue, 10 Jul 2018 15:43:31 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 14/24] Revert "block: Remove deprecated -drive geometry options" X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Cornelia Huck This reverts commit a7aff6dd10b16b67e8b142d0c94c5d92c3fe88f6. Hold off removing this for one more QEMU release (current libvirt release still uses it.) Signed-off-by: Cornelia Huck Signed-off-by: Kevin Wolf --- include/sysemu/blockdev.h | 1 + blockdev.c | 75 +++++++++++++++++++++++++++++++++++++++++++= +++- hw/block/block.c | 14 +++++++++ tests/hd-geo-test.c | 37 ++++++++++++++++++----- hmp-commands.hx | 1 + qemu-doc.texi | 5 ++++ qemu-options.hx | 7 ++++- 7 files changed, 131 insertions(+), 9 deletions(-) diff --git a/include/sysemu/blockdev.h b/include/sysemu/blockdev.h index 37ea39719e..ac22f2ae1f 100644 --- a/include/sysemu/blockdev.h +++ b/include/sysemu/blockdev.h @@ -35,6 +35,7 @@ struct DriveInfo { int auto_del; /* see blockdev_mark_auto_del() */ bool is_default; /* Added by default_drive() ? */ int media_cd; + int cyls, heads, secs, trans; QemuOpts *opts; char *serial; QTAILQ_ENTRY(DriveInfo) next; diff --git a/blockdev.c b/blockdev.c index c23587b075..dcf8c8d2ab 100644 --- a/blockdev.c +++ b/blockdev.c @@ -731,6 +731,22 @@ QemuOptsList qemu_legacy_drive_opts =3D { .type =3D QEMU_OPT_STRING, .help =3D "interface (ide, scsi, sd, mtd, floppy, pflash, virt= io)", },{ + .name =3D "cyls", + .type =3D QEMU_OPT_NUMBER, + .help =3D "number of cylinders (ide disk geometry)", + },{ + .name =3D "heads", + .type =3D QEMU_OPT_NUMBER, + .help =3D "number of heads (ide disk geometry)", + },{ + .name =3D "secs", + .type =3D QEMU_OPT_NUMBER, + .help =3D "number of sectors (ide disk geometry)", + },{ + .name =3D "trans", + .type =3D QEMU_OPT_STRING, + .help =3D "chs translation (auto, lba, none)", + },{ .name =3D "addr", .type =3D QEMU_OPT_STRING, .help =3D "pci address (virtio only)", @@ -776,6 +792,7 @@ DriveInfo *drive_new(QemuOpts *all_opts, BlockInterface= Type block_default_type) QemuOpts *legacy_opts; DriveMediaType media =3D MEDIA_DISK; BlockInterfaceType type; + int cyls, heads, secs, translation; int max_devs, bus_id, unit_id, index; const char *devaddr; const char *werror, *rerror; @@ -786,7 +803,7 @@ DriveInfo *drive_new(QemuOpts *all_opts, BlockInterface= Type block_default_type) Error *local_err =3D NULL; int i; const char *deprecated[] =3D { - "serial", "addr" + "serial", "trans", "secs", "heads", "cyls", "addr" }; =20 /* Change legacy command line options into QMP ones */ @@ -915,6 +932,57 @@ DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfac= eType block_default_type) type =3D block_default_type; } =20 + /* Geometry */ + cyls =3D qemu_opt_get_number(legacy_opts, "cyls", 0); + heads =3D qemu_opt_get_number(legacy_opts, "heads", 0); + secs =3D qemu_opt_get_number(legacy_opts, "secs", 0); + + if (cyls || heads || secs) { + if (cyls < 1) { + error_report("invalid physical cyls number"); + goto fail; + } + if (heads < 1) { + error_report("invalid physical heads number"); + goto fail; + } + if (secs < 1) { + error_report("invalid physical secs number"); + goto fail; + } + } + + translation =3D BIOS_ATA_TRANSLATION_AUTO; + value =3D qemu_opt_get(legacy_opts, "trans"); + if (value !=3D NULL) { + if (!cyls) { + error_report("'%s' trans must be used with cyls, heads and sec= s", + value); + goto fail; + } + if (!strcmp(value, "none")) { + translation =3D BIOS_ATA_TRANSLATION_NONE; + } else if (!strcmp(value, "lba")) { + translation =3D BIOS_ATA_TRANSLATION_LBA; + } else if (!strcmp(value, "large")) { + translation =3D BIOS_ATA_TRANSLATION_LARGE; + } else if (!strcmp(value, "rechs")) { + translation =3D BIOS_ATA_TRANSLATION_RECHS; + } else if (!strcmp(value, "auto")) { + translation =3D BIOS_ATA_TRANSLATION_AUTO; + } else { + error_report("'%s' invalid translation type", value); + goto fail; + } + } + + if (media =3D=3D MEDIA_CDROM) { + if (cyls || secs || heads) { + error_report("CHS can't be set with media=3Dcdrom"); + goto fail; + } + } + /* Device address specified by bus/unit or index. * If none was specified, try to find the first free one. */ bus_id =3D qemu_opt_get_number(legacy_opts, "bus", 0); @@ -1037,6 +1105,11 @@ DriveInfo *drive_new(QemuOpts *all_opts, BlockInterf= aceType block_default_type) dinfo =3D g_malloc0(sizeof(*dinfo)); dinfo->opts =3D all_opts; =20 + dinfo->cyls =3D cyls; + dinfo->heads =3D heads; + dinfo->secs =3D secs; + dinfo->trans =3D translation; + dinfo->type =3D type; dinfo->bus =3D bus_id; dinfo->unit =3D unit_id; diff --git a/hw/block/block.c b/hw/block/block.c index b6c80ab0b7..b91e2b6d7e 100644 --- a/hw/block/block.c +++ b/hw/block/block.c @@ -108,6 +108,20 @@ bool blkconf_geometry(BlockConf *conf, int *ptrans, unsigned cyls_max, unsigned heads_max, unsigned secs= _max, Error **errp) { + DriveInfo *dinfo; + + if (!conf->cyls && !conf->heads && !conf->secs) { + /* try to fall back to value set with legacy -drive cyls=3D... */ + dinfo =3D blk_legacy_dinfo(conf->blk); + if (dinfo) { + conf->cyls =3D dinfo->cyls; + conf->heads =3D dinfo->heads; + conf->secs =3D dinfo->secs; + if (ptrans) { + *ptrans =3D dinfo->trans; + } + } + } if (!conf->cyls && !conf->heads && !conf->secs) { hd_geometry_guess(conf->blk, &conf->cyls, &conf->heads, &conf->secs, diff --git a/tests/hd-geo-test.c b/tests/hd-geo-test.c index ce665f1f83..24870b38f4 100644 --- a/tests/hd-geo-test.c +++ b/tests/hd-geo-test.c @@ -201,7 +201,7 @@ static void setup_mbr(int img_idx, MBRcontents mbr) =20 static int setup_ide(int argc, char *argv[], int argv_sz, int ide_idx, const char *dev, int img_idx, - MBRcontents mbr) + MBRcontents mbr, const char *opts) { char *s1, *s2, *s3; =20 @@ -216,7 +216,7 @@ static int setup_ide(int argc, char *argv[], int argv_s= z, s3 =3D g_strdup(",media=3Dcdrom"); } argc =3D append_arg(argc, argv, argv_sz, - g_strdup_printf("%s%s%s", s1, s2, s3)); + g_strdup_printf("%s%s%s%s", s1, s2, s3, opts)); g_free(s1); g_free(s2); g_free(s3); @@ -260,7 +260,7 @@ static void test_ide_mbr(bool use_device, MBRcontents m= br) for (i =3D 0; i < backend_last; i++) { cur_ide[i] =3D &hd_chst[i][mbr]; dev =3D use_device ? (is_hd(cur_ide[i]) ? "ide-hd" : "ide-cd") : N= ULL; - argc =3D setup_ide(argc, argv, ARGV_SIZE, i, dev, i, mbr); + argc =3D setup_ide(argc, argv, ARGV_SIZE, i, dev, i, mbr, ""); } args =3D g_strjoinv(" ", argv); qtest_start(args); @@ -327,12 +327,16 @@ static void test_ide_drive_user(const char *dev, bool= trans) const CHST expected_chst =3D { secs / (4 * 32) , 4, 32, trans }; =20 argc =3D setup_common(argv, ARGV_SIZE); - opts =3D g_strdup_printf("%s,%scyls=3D%d,heads=3D%d,secs=3D%d", - dev, trans ? "bios-chs-trans=3Dlba," : "", + opts =3D g_strdup_printf("%s,%s%scyls=3D%d,heads=3D%d,secs=3D%d", + dev ?: "", + trans && dev ? "bios-chs-" : "", + trans ? "trans=3Dlba," : "", expected_chst.cyls, expected_chst.heads, expected_chst.secs); cur_ide[0] =3D &expected_chst; - argc =3D setup_ide(argc, argv, ARGV_SIZE, 0, opts, backend_small, mbr_= chs); + argc =3D setup_ide(argc, argv, ARGV_SIZE, + 0, dev ? opts : NULL, backend_small, mbr_chs, + dev ? "" : opts); g_free(opts); args =3D g_strjoinv(" ", argv); qtest_start(args); @@ -343,6 +347,22 @@ static void test_ide_drive_user(const char *dev, bool = trans) } =20 /* + * Test case: IDE device (if=3Dide) with explicit CHS + */ +static void test_ide_drive_user_chs(void) +{ + test_ide_drive_user(NULL, false); +} + +/* + * Test case: IDE device (if=3Dide) with explicit CHS and translation + */ +static void test_ide_drive_user_chst(void) +{ + test_ide_drive_user(NULL, true); +} + +/* * Test case: IDE device (if=3Dnone) with explicit CHS */ static void test_ide_device_user_chs(void) @@ -372,7 +392,8 @@ static void test_ide_drive_cd_0(void) for (i =3D 0; i <=3D backend_empty; i++) { ide_idx =3D backend_empty - i; cur_ide[ide_idx] =3D &hd_chst[i][mbr_blank]; - argc =3D setup_ide(argc, argv, ARGV_SIZE, ide_idx, NULL, i, mbr_bl= ank); + argc =3D setup_ide(argc, argv, ARGV_SIZE, + ide_idx, NULL, i, mbr_blank, ""); } args =3D g_strjoinv(" ", argv); qtest_start(args); @@ -401,6 +422,8 @@ int main(int argc, char **argv) qtest_add_func("hd-geo/ide/drive/mbr/blank", test_ide_drive_mbr_blank); qtest_add_func("hd-geo/ide/drive/mbr/lba", test_ide_drive_mbr_lba); qtest_add_func("hd-geo/ide/drive/mbr/chs", test_ide_drive_mbr_chs); + qtest_add_func("hd-geo/ide/drive/user/chs", test_ide_drive_user_chs); + qtest_add_func("hd-geo/ide/drive/user/chst", test_ide_drive_user_chst); qtest_add_func("hd-geo/ide/drive/cd_0", test_ide_drive_cd_0); qtest_add_func("hd-geo/ide/device/mbr/blank", test_ide_device_mbr_blan= k); qtest_add_func("hd-geo/ide/device/mbr/lba", test_ide_device_mbr_lba); diff --git a/hmp-commands.hx b/hmp-commands.hx index c1fc747403..91dfe51c37 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -1306,6 +1306,7 @@ ETEXI .params =3D "[-n] [[:]:]\n" "[file=3Dfile][,if=3Dtype][,bus=3Dn]\n" "[,unit=3Dm][,media=3Dd][,index=3Di]\n" + "[,cyls=3Dc,heads=3Dh,secs=3Ds[,trans=3Dt]]\n" "[,snapshot=3Don|off][,cache=3Don|off]\n" "[,readonly=3Don|off][,copy-on-read=3Don|off]", .help =3D "add drive to PCI storage controller", diff --git a/qemu-doc.texi b/qemu-doc.texi index ae5531a053..0fbf8b108b 100644 --- a/qemu-doc.texi +++ b/qemu-doc.texi @@ -2887,6 +2887,11 @@ with ``-device ...,netdev=3Dx''), or ``-nic user,smb= =3D/some/dir'' (for embedded NICs). The new syntax allows different settings to be provided per NIC. =20 +@subsection -drive cyls=3D...,heads=3D...,secs=3D...,trans=3D... (since 2.= 10.0) + +The drive geometry arguments are replaced by the the geometry arguments +that can be specified with the ``-device'' parameter. + @subsection -drive serial=3D... (since 2.10.0) =20 The drive serial argument is replaced by the the serial argument diff --git a/qemu-options.hx b/qemu-options.hx index df248d1568..654e69cc3b 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -804,8 +804,9 @@ ETEXI =20 DEF("drive", HAS_ARG, QEMU_OPTION_drive, "-drive [file=3Dfile][,if=3Dtype][,bus=3Dn][,unit=3Dm][,media=3Dd][,in= dex=3Di]\n" + " [,cyls=3Dc,heads=3Dh,secs=3Ds[,trans=3Dt]][,snapshot=3Don|off]= \n" " [,cache=3Dwritethrough|writeback|none|directsync|unsafe][,form= at=3Df]\n" - " [,snapshot=3Don|off][,serial=3Ds][,addr=3DA][,rerror=3Dignore|= stop|report]\n" + " [,serial=3Ds][,addr=3DA][,rerror=3Dignore|stop|report]\n" " [,werror=3Dignore|stop|report|enospc][,id=3Dname][,aio=3Dthrea= ds|native]\n" " [,readonly=3Don|off][,copy-on-read=3Don|off]\n" " [,discard=3Dignore|unmap][,detect-zeroes=3Don|off|unmap]\n" @@ -846,6 +847,10 @@ This option defines where is connected the drive by us= ing an index in the list of available connectors of a given interface type. @item media=3D@var{media} This option defines the type of the media: disk or cdrom. +@item cyls=3D@var{c},heads=3D@var{h},secs=3D@var{s}[,trans=3D@var{t}] +Force disk physical geometry and the optional BIOS translation (trans=3Dno= ne or +lba). These parameters are deprecated, use the corresponding parameters +of @code{-device} instead. @item snapshot=3D@var{snapshot} @var{snapshot} is "on" or "off" and controls snapshot mode for the given d= rive (see @option{-snapshot}). --=20 2.13.6 From nobody Wed Apr 16 03:21:50 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 153123795441197.71637559932526; Tue, 10 Jul 2018 08:52:34 -0700 (PDT) Received: from localhost ([::1]:48504 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fcuwL-0003pg-C4 for importer@patchew.org; Tue, 10 Jul 2018 11:52:33 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44440) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fcung-0005ES-3k for qemu-devel@nongnu.org; Tue, 10 Jul 2018 11:43:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fcunf-0001hm-8n for qemu-devel@nongnu.org; Tue, 10 Jul 2018 11:43:36 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:47632 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fcunc-0001gD-OY; Tue, 10 Jul 2018 11:43:32 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 52775808255B; Tue, 10 Jul 2018 15:43:32 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-156.ams2.redhat.com [10.36.116.156]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7F9CB2026D6B; Tue, 10 Jul 2018 15:43:31 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 10 Jul 2018 17:42:55 +0200 Message-Id: <20180710154304.18304-16-kwolf@redhat.com> In-Reply-To: <20180710154304.18304-1-kwolf@redhat.com> References: <20180710154304.18304-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Tue, 10 Jul 2018 15:43:32 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Tue, 10 Jul 2018 15:43:32 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 15/24] block: Prefix file driver trace points with "file_" X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Fam Zheng With in one module, trace points usually have a common prefix named after the module name. paio_submit and paio_submit_co are the only two trace points so far in the two file protocol drivers. As we are adding more, having a common prefix here is better so that trace points can be enabled with a glob. Rename them. Suggested-by: Kevin Wolf Signed-off-by: Fam Zheng Signed-off-by: Kevin Wolf --- block/file-posix.c | 2 +- block/file-win32.c | 2 +- block/trace-events | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index 4fec8cb53c..1185c7c5cc 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1743,7 +1743,7 @@ static int paio_submit_co_full(BlockDriverState *bs, = int fd, assert(qiov->size =3D=3D bytes); } =20 - trace_paio_submit_co(offset, bytes, type); + trace_file_paio_submit_co(offset, bytes, type); pool =3D aio_get_thread_pool(bdrv_get_aio_context(bs)); return thread_pool_submit_co(pool, aio_worker, acb); } diff --git a/block/file-win32.c b/block/file-win32.c index 0411fe80fd..f1e2187f3b 100644 --- a/block/file-win32.c +++ b/block/file-win32.c @@ -162,7 +162,7 @@ static BlockAIOCB *paio_submit(BlockDriverState *bs, HA= NDLE hfile, acb->aio_nbytes =3D count; acb->aio_offset =3D offset; =20 - trace_paio_submit(acb, opaque, offset, count, type); + trace_file_paio_submit(acb, opaque, offset, count, type); pool =3D aio_get_thread_pool(bdrv_get_aio_context(bs)); return thread_pool_submit_aio(pool, aio_worker, acb, cb, opaque); } diff --git a/block/trace-events b/block/trace-events index c35287b48a..854d5525af 100644 --- a/block/trace-events +++ b/block/trace-events @@ -55,8 +55,8 @@ qmp_block_stream(void *bs, void *job) "bs %p job %p" =20 # block/file-win32.c # block/file-posix.c -paio_submit_co(int64_t offset, int count, int type) "offset %"PRId64" coun= t %d type %d" -paio_submit(void *acb, void *opaque, int64_t offset, int count, int type) = "acb %p opaque %p offset %"PRId64" count %d type %d" +file_paio_submit_co(int64_t offset, int count, int type) "offset %"PRId64"= count %d type %d" +file_paio_submit(void *acb, void *opaque, int64_t offset, int count, int t= ype) "acb %p opaque %p offset %"PRId64" count %d type %d" =20 # block/qcow2.c qcow2_writev_start_req(void *co, int64_t offset, int bytes) "co %p offset = 0x%" PRIx64 " bytes %d" --=20 2.13.6 From nobody Wed Apr 16 03:21:50 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1531238207675606.9611275534; Tue, 10 Jul 2018 08:56:47 -0700 (PDT) Received: from localhost ([::1]:48528 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fcv0Q-0007ff-GW for importer@patchew.org; Tue, 10 Jul 2018 11:56:46 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44524) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fcunl-0005Kf-3A for qemu-devel@nongnu.org; Tue, 10 Jul 2018 11:43:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fcung-0001iu-Vn for qemu-devel@nongnu.org; Tue, 10 Jul 2018 11:43:41 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:45894 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fcund-0001gi-Rc; Tue, 10 Jul 2018 11:43:33 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6054A77889; Tue, 10 Jul 2018 15:43:33 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-156.ams2.redhat.com [10.36.116.156]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8EA542026D6B; Tue, 10 Jul 2018 15:43:32 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 10 Jul 2018 17:42:56 +0200 Message-Id: <20180710154304.18304-17-kwolf@redhat.com> In-Reply-To: <20180710154304.18304-1-kwolf@redhat.com> References: <20180710154304.18304-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Tue, 10 Jul 2018 15:43:33 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Tue, 10 Jul 2018 15:43:33 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 16/24] block: Add copy offloading trace points X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Fam Zheng A few trace points that can help reveal what is happening in a copy offloading I/O path. Signed-off-by: Fam Zheng Signed-off-by: Kevin Wolf --- block/file-posix.c | 2 ++ block/io.c | 4 ++++ block/iscsi.c | 3 +++ block/trace-events | 6 ++++++ 4 files changed, 15 insertions(+) diff --git a/block/file-posix.c b/block/file-posix.c index 1185c7c5cc..09f6b938f6 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1488,6 +1488,8 @@ static ssize_t handle_aiocb_copy_range(RawPosixAIODat= a *aiocb) ssize_t ret =3D copy_file_range(aiocb->aio_fildes, &in_off, aiocb->aio_fd2, &out_off, bytes, 0); + trace_file_copy_file_range(aiocb->bs, aiocb->aio_fildes, in_off, + aiocb->aio_fd2, out_off, bytes, 0, ret); if (ret =3D=3D 0) { /* No progress (e.g. when beyond EOF), let the caller fall bac= k to * buffer I/O. */ diff --git a/block/io.c b/block/io.c index 6be9c40f23..9b2aa04010 100644 --- a/block/io.c +++ b/block/io.c @@ -3019,6 +3019,8 @@ int coroutine_fn bdrv_co_copy_range_from(BdrvChild *s= rc, uint64_t src_offset, BdrvRequestFlags read_flags, BdrvRequestFlags write_flags) { + trace_bdrv_co_copy_range_from(src, src_offset, dst, dst_offset, bytes, + read_flags, write_flags); return bdrv_co_copy_range_internal(src, src_offset, dst, dst_offset, bytes, read_flags, write_flags, tru= e); } @@ -3033,6 +3035,8 @@ int coroutine_fn bdrv_co_copy_range_to(BdrvChild *src= , uint64_t src_offset, BdrvRequestFlags read_flags, BdrvRequestFlags write_flags) { + trace_bdrv_co_copy_range_to(src, src_offset, dst, dst_offset, bytes, + read_flags, write_flags); return bdrv_co_copy_range_internal(src, src_offset, dst, dst_offset, bytes, read_flags, write_flags, fal= se); } diff --git a/block/iscsi.c b/block/iscsi.c index 38b917a1e5..bb69faf34a 100644 --- a/block/iscsi.c +++ b/block/iscsi.c @@ -44,6 +44,7 @@ #include "qapi/qmp/qstring.h" #include "crypto/secret.h" #include "scsi/utils.h" +#include "trace.h" =20 /* Conflict between scsi/utils.h and libiscsi! :( */ #define SCSI_XFER_NONE ISCSI_XFER_NONE @@ -2399,6 +2400,8 @@ retry: } =20 out_unlock: + + trace_iscsi_xcopy(src_lun, src_offset, dst_lun, dst_offset, bytes, r); g_free(iscsi_task.task); qemu_mutex_unlock(&dst_lun->mutex); g_free(iscsi_task.err_str); diff --git a/block/trace-events b/block/trace-events index 854d5525af..3e8c47bb24 100644 --- a/block/trace-events +++ b/block/trace-events @@ -15,6 +15,8 @@ bdrv_co_preadv(void *bs, int64_t offset, int64_t nbytes, = unsigned int flags) "bs bdrv_co_pwritev(void *bs, int64_t offset, int64_t nbytes, unsigned int fla= gs) "bs %p offset %"PRId64" nbytes %"PRId64" flags 0x%x" bdrv_co_pwrite_zeroes(void *bs, int64_t offset, int count, int flags) "bs = %p offset %"PRId64" count %d flags 0x%x" bdrv_co_do_copy_on_readv(void *bs, int64_t offset, unsigned int bytes, int= 64_t cluster_offset, int64_t cluster_bytes) "bs %p offset %"PRId64" bytes %= u cluster_offset %"PRId64" cluster_bytes %"PRId64 +bdrv_co_copy_range_from(void *src, uint64_t src_offset, void *dst, uint64_= t dst_offset, uint64_t bytes, int read_flags, int write_flags) "src %p offs= et %"PRIu64" dst %p offset %"PRIu64" bytes %"PRIu64" rw flags 0x%x 0x%x" +bdrv_co_copy_range_to(void *src, uint64_t src_offset, void *dst, uint64_t = dst_offset, uint64_t bytes, int read_flags, int write_flags) "src %p offset= %"PRIu64" dst %p offset %"PRIu64" bytes %"PRIu64" rw flags 0x%x 0x%x" =20 # block/stream.c stream_one_iteration(void *s, int64_t offset, uint64_t bytes, int is_alloc= ated) "s %p offset %" PRId64 " bytes %" PRIu64 " is_allocated %d" @@ -57,6 +59,7 @@ qmp_block_stream(void *bs, void *job) "bs %p job %p" # block/file-posix.c file_paio_submit_co(int64_t offset, int count, int type) "offset %"PRId64"= count %d type %d" file_paio_submit(void *acb, void *opaque, int64_t offset, int count, int t= ype) "acb %p opaque %p offset %"PRId64" count %d type %d" +file_copy_file_range(void *bs, int src, int64_t src_off, int dst, int64_t = dst_off, int64_t bytes, int flags, int64_t ret) "bs %p src_fd %d offset %"P= RIu64" dst_fd %d offset %"PRIu64" bytes %"PRIu64" flags %d ret %"PRId64 =20 # block/qcow2.c qcow2_writev_start_req(void *co, int64_t offset, int bytes) "co %p offset = 0x%" PRIx64 " bytes %d" @@ -150,3 +153,6 @@ nvme_free_req_queue_wait(void *q) "q %p" nvme_cmd_map_qiov(void *s, void *cmd, void *req, void *qiov, int entries) = "s %p cmd %p req %p qiov %p entries %d" nvme_cmd_map_qiov_pages(void *s, int i, uint64_t page) "s %p page[%d] 0x%"= PRIx64 nvme_cmd_map_qiov_iov(void *s, int i, void *page, int pages) "s %p iov[%d]= %p pages %d" + +# block/iscsi.c +iscsi_xcopy(void *src_lun, uint64_t src_off, void *dst_lun, uint64_t dst_o= ff, uint64_t bytes, int ret) "src_lun %p offset %"PRIu64" dst_lun %p offset= %"PRIu64" bytes %"PRIu64" ret %d" --=20 2.13.6 From nobody Wed Apr 16 03:21:50 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1531238375693364.1570296740184; Tue, 10 Jul 2018 08:59:35 -0700 (PDT) Received: from localhost ([::1]:48544 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fcv38-0001qj-Ca for importer@patchew.org; Tue, 10 Jul 2018 11:59:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44516) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fcunl-0005KO-0I for qemu-devel@nongnu.org; Tue, 10 Jul 2018 11:43:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fcuni-0001jb-A6 for qemu-devel@nongnu.org; Tue, 10 Jul 2018 11:43:41 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:45898 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fcune-0001hV-Sw; Tue, 10 Jul 2018 11:43:35 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6F90577889; Tue, 10 Jul 2018 15:43:34 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-156.ams2.redhat.com [10.36.116.156]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9D6082026D6B; Tue, 10 Jul 2018 15:43:33 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 10 Jul 2018 17:42:57 +0200 Message-Id: <20180710154304.18304-18-kwolf@redhat.com> In-Reply-To: <20180710154304.18304-1-kwolf@redhat.com> References: <20180710154304.18304-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Tue, 10 Jul 2018 15:43:34 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Tue, 10 Jul 2018 15:43:34 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 17/24] block: Use BdrvChild to discard X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Fam Zheng Other I/O functions are already using a BdrvChild pointer in the API, so make discard do the same. It makes it possible to initiate the same permission checks before doing I/O, and much easier to share the helper functions for this, which will be added and used by write, truncate and copy range paths. Signed-off-by: Fam Zheng Signed-off-by: Kevin Wolf --- include/block/block.h | 4 ++-- block/blkdebug.c | 2 +- block/blklogwrites.c | 2 +- block/blkreplay.c | 2 +- block/block-backend.c | 2 +- block/copy-on-read.c | 2 +- block/io.c | 18 +++++++++--------- block/mirror.c | 2 +- block/qcow2-refcount.c | 2 +- block/raw-format.c | 2 +- block/throttle.c | 2 +- 11 files changed, 20 insertions(+), 20 deletions(-) diff --git a/include/block/block.h b/include/block/block.h index a91f37bedf..f85e3a6ed3 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -418,8 +418,8 @@ AioWait *bdrv_get_aio_wait(BlockDriverState *bs); bdrv_get_aio_context(bs_), \ cond); }) =20 -int bdrv_pdiscard(BlockDriverState *bs, int64_t offset, int bytes); -int bdrv_co_pdiscard(BlockDriverState *bs, int64_t offset, int bytes); +int bdrv_pdiscard(BdrvChild *child, int64_t offset, int bytes); +int bdrv_co_pdiscard(BdrvChild *child, int64_t offset, int bytes); int bdrv_has_zero_init_1(BlockDriverState *bs); int bdrv_has_zero_init(BlockDriverState *bs); bool bdrv_unallocated_blocks_are_zero(BlockDriverState *bs); diff --git a/block/blkdebug.c b/block/blkdebug.c index 526af2a808..0457bf5b66 100644 --- a/block/blkdebug.c +++ b/block/blkdebug.c @@ -625,7 +625,7 @@ static int coroutine_fn blkdebug_co_pdiscard(BlockDrive= rState *bs, return err; } =20 - return bdrv_co_pdiscard(bs->file->bs, offset, bytes); + return bdrv_co_pdiscard(bs->file, offset, bytes); } =20 static int coroutine_fn blkdebug_co_block_status(BlockDriverState *bs, diff --git a/block/blklogwrites.c b/block/blklogwrites.c index efa2c7a66a..ff98cd5533 100644 --- a/block/blklogwrites.c +++ b/block/blklogwrites.c @@ -486,7 +486,7 @@ static int coroutine_fn blk_log_writes_co_do_file_flush= (BlkLogWritesFileReq *fr) static int coroutine_fn blk_log_writes_co_do_file_pdiscard(BlkLogWritesFileReq *fr) { - return bdrv_co_pdiscard(fr->bs->file->bs, fr->offset, fr->bytes); + return bdrv_co_pdiscard(fr->bs->file, fr->offset, fr->bytes); } =20 static int coroutine_fn diff --git a/block/blkreplay.c b/block/blkreplay.c index b016dbeee7..766150ade6 100755 --- a/block/blkreplay.c +++ b/block/blkreplay.c @@ -113,7 +113,7 @@ static int coroutine_fn blkreplay_co_pdiscard(BlockDriv= erState *bs, int64_t offset, int bytes) { uint64_t reqid =3D blkreplay_next_id(); - int ret =3D bdrv_co_pdiscard(bs->file->bs, offset, bytes); + int ret =3D bdrv_co_pdiscard(bs->file, offset, bytes); block_request_create(reqid, bs, qemu_coroutine_self()); qemu_coroutine_yield(); =20 diff --git a/block/block-backend.c b/block/block-backend.c index e94e3d5929..f2f75a977d 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -1560,7 +1560,7 @@ int blk_co_pdiscard(BlockBackend *blk, int64_t offset= , int bytes) return ret; } =20 - return bdrv_co_pdiscard(blk_bs(blk), offset, bytes); + return bdrv_co_pdiscard(blk->root, offset, bytes); } =20 int blk_co_flush(BlockBackend *blk) diff --git a/block/copy-on-read.c b/block/copy-on-read.c index 1dcdaeed69..a19164f9eb 100644 --- a/block/copy-on-read.c +++ b/block/copy-on-read.c @@ -116,7 +116,7 @@ static int coroutine_fn cor_co_pwrite_zeroes(BlockDrive= rState *bs, static int coroutine_fn cor_co_pdiscard(BlockDriverState *bs, int64_t offset, int bytes) { - return bdrv_co_pdiscard(bs->file->bs, offset, bytes); + return bdrv_co_pdiscard(bs->file, offset, bytes); } =20 =20 diff --git a/block/io.c b/block/io.c index 9b2aa04010..fbcd93304b 100644 --- a/block/io.c +++ b/block/io.c @@ -2633,7 +2633,7 @@ int bdrv_flush(BlockDriverState *bs) } =20 typedef struct DiscardCo { - BlockDriverState *bs; + BdrvChild *child; int64_t offset; int bytes; int ret; @@ -2642,17 +2642,17 @@ static void coroutine_fn bdrv_pdiscard_co_entry(voi= d *opaque) { DiscardCo *rwco =3D opaque; =20 - rwco->ret =3D bdrv_co_pdiscard(rwco->bs, rwco->offset, rwco->bytes); + rwco->ret =3D bdrv_co_pdiscard(rwco->child, rwco->offset, rwco->bytes); } =20 -int coroutine_fn bdrv_co_pdiscard(BlockDriverState *bs, int64_t offset, - int bytes) +int coroutine_fn bdrv_co_pdiscard(BdrvChild *child, int64_t offset, int by= tes) { BdrvTrackedRequest req; int max_pdiscard, ret; int head, tail, align; + BlockDriverState *bs =3D child->bs; =20 - if (!bs->drv) { + if (!bs || !bs->drv) { return -ENOMEDIUM; } =20 @@ -2763,11 +2763,11 @@ out: return ret; } =20 -int bdrv_pdiscard(BlockDriverState *bs, int64_t offset, int bytes) +int bdrv_pdiscard(BdrvChild *child, int64_t offset, int bytes) { Coroutine *co; DiscardCo rwco =3D { - .bs =3D bs, + .child =3D child, .offset =3D offset, .bytes =3D bytes, .ret =3D NOT_DONE, @@ -2778,8 +2778,8 @@ int bdrv_pdiscard(BlockDriverState *bs, int64_t offse= t, int bytes) bdrv_pdiscard_co_entry(&rwco); } else { co =3D qemu_coroutine_create(bdrv_pdiscard_co_entry, &rwco); - bdrv_coroutine_enter(bs, co); - BDRV_POLL_WHILE(bs, rwco.ret =3D=3D NOT_DONE); + bdrv_coroutine_enter(child->bs, co); + BDRV_POLL_WHILE(child->bs, rwco.ret =3D=3D NOT_DONE); } =20 return rwco.ret; diff --git a/block/mirror.c b/block/mirror.c index 61bd9f3cf1..b48c3f8cf5 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -1333,7 +1333,7 @@ static int coroutine_fn bdrv_mirror_top_do_write(Bloc= kDriverState *bs, break; =20 case MIRROR_METHOD_DISCARD: - ret =3D bdrv_co_pdiscard(bs->backing->bs, offset, bytes); + ret =3D bdrv_co_pdiscard(bs->backing, offset, bytes); break; =20 default: diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index 18c729aa27..4e1589ad7a 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -734,7 +734,7 @@ void qcow2_process_discards(BlockDriverState *bs, int r= et) =20 /* Discard is optional, ignore the return value */ if (ret >=3D 0) { - bdrv_pdiscard(bs->file->bs, d->offset, d->bytes); + bdrv_pdiscard(bs->file, d->offset, d->bytes); } =20 g_free(d); diff --git a/block/raw-format.c b/block/raw-format.c index a3591985f6..dee262875a 100644 --- a/block/raw-format.c +++ b/block/raw-format.c @@ -297,7 +297,7 @@ static int coroutine_fn raw_co_pdiscard(BlockDriverStat= e *bs, if (ret) { return ret; } - return bdrv_co_pdiscard(bs->file->bs, offset, bytes); + return bdrv_co_pdiscard(bs->file, offset, bytes); } =20 static int64_t raw_getlength(BlockDriverState *bs) diff --git a/block/throttle.c b/block/throttle.c index f617f23a12..636c9764aa 100644 --- a/block/throttle.c +++ b/block/throttle.c @@ -149,7 +149,7 @@ static int coroutine_fn throttle_co_pdiscard(BlockDrive= rState *bs, ThrottleGroupMember *tgm =3D bs->opaque; throttle_group_co_io_limits_intercept(tgm, bytes, true); =20 - return bdrv_co_pdiscard(bs->file->bs, offset, bytes); + return bdrv_co_pdiscard(bs->file, offset, bytes); } =20 static int throttle_co_flush(BlockDriverState *bs) --=20 2.13.6 From nobody Wed Apr 16 03:21:50 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 153123856155489.68081831995653; Tue, 10 Jul 2018 09:02:41 -0700 (PDT) Received: from localhost ([::1]:48568 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fcv68-0004fD-Go for importer@patchew.org; Tue, 10 Jul 2018 12:02:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44558) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fcunm-0005Lf-6E for qemu-devel@nongnu.org; Tue, 10 Jul 2018 11:43:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fcunl-0001lI-7g for qemu-devel@nongnu.org; Tue, 10 Jul 2018 11:43:42 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:38824 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fcunf-0001i7-V7; Tue, 10 Jul 2018 11:43:36 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7ED0985629; Tue, 10 Jul 2018 15:43:35 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-156.ams2.redhat.com [10.36.116.156]) by smtp.corp.redhat.com (Postfix) with ESMTP id ACC122026D6B; Tue, 10 Jul 2018 15:43:34 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 10 Jul 2018 17:42:58 +0200 Message-Id: <20180710154304.18304-19-kwolf@redhat.com> In-Reply-To: <20180710154304.18304-1-kwolf@redhat.com> References: <20180710154304.18304-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Tue, 10 Jul 2018 15:43:35 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Tue, 10 Jul 2018 15:43:35 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 18/24] block: Use uint64_t for BdrvTrackedRequest byte fields X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Fam Zheng This matches the types used for bytes in the rest parts of block layer. In the case of bdrv_co_truncate, new_bytes can be the image size which probably doesn't fit in a 32 bit int. Signed-off-by: Fam Zheng Signed-off-by: Kevin Wolf --- include/block/block_int.h | 4 ++-- block/io.c | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/include/block/block_int.h b/include/block/block_int.h index 920d3d122b..903b9c1034 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -69,12 +69,12 @@ enum BdrvTrackedRequestType { typedef struct BdrvTrackedRequest { BlockDriverState *bs; int64_t offset; - unsigned int bytes; + uint64_t bytes; enum BdrvTrackedRequestType type; =20 bool serialising; int64_t overlap_offset; - unsigned int overlap_bytes; + uint64_t overlap_bytes; =20 QLIST_ENTRY(BdrvTrackedRequest) list; Coroutine *co; /* owner, used for deadlock detection */ diff --git a/block/io.c b/block/io.c index fbcd93304b..6293612e73 100644 --- a/block/io.c +++ b/block/io.c @@ -601,9 +601,11 @@ static void tracked_request_end(BdrvTrackedRequest *re= q) static void tracked_request_begin(BdrvTrackedRequest *req, BlockDriverState *bs, int64_t offset, - unsigned int bytes, + uint64_t bytes, enum BdrvTrackedRequestType type) { + assert(bytes <=3D INT64_MAX && offset <=3D INT64_MAX - bytes); + *req =3D (BdrvTrackedRequest){ .bs =3D bs, .offset =3D offset, @@ -625,7 +627,7 @@ static void tracked_request_begin(BdrvTrackedRequest *r= eq, static void mark_request_serialising(BdrvTrackedRequest *req, uint64_t ali= gn) { int64_t overlap_offset =3D req->offset & ~(align - 1); - unsigned int overlap_bytes =3D ROUND_UP(req->offset + req->bytes, alig= n) + uint64_t overlap_bytes =3D ROUND_UP(req->offset + req->bytes, align) - overlap_offset; =20 if (!req->serialising) { @@ -683,7 +685,7 @@ static int bdrv_get_cluster_size(BlockDriverState *bs) } =20 static bool tracked_request_overlaps(BdrvTrackedRequest *req, - int64_t offset, unsigned int bytes) + int64_t offset, uint64_t bytes) { /* aaaa bbbb */ if (offset >=3D req->overlap_offset + req->overlap_bytes) { --=20 2.13.6 From nobody Wed Apr 16 03:21:50 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1531239632620987.2004042699621; Tue, 10 Jul 2018 09:20:32 -0700 (PDT) Received: from localhost ([::1]:48769 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fcvNP-0002og-4g for importer@patchew.org; Tue, 10 Jul 2018 12:20:31 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44622) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fcunn-0005OG-Uq for qemu-devel@nongnu.org; Tue, 10 Jul 2018 11:43:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fcunm-0001mV-Rx for qemu-devel@nongnu.org; Tue, 10 Jul 2018 11:43:43 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:45902 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fcunh-0001io-2O; Tue, 10 Jul 2018 11:43:37 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8E57F77889; Tue, 10 Jul 2018 15:43:36 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-156.ams2.redhat.com [10.36.116.156]) by smtp.corp.redhat.com (Postfix) with ESMTP id BBD832026D6B; Tue, 10 Jul 2018 15:43:35 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 10 Jul 2018 17:42:59 +0200 Message-Id: <20180710154304.18304-20-kwolf@redhat.com> In-Reply-To: <20180710154304.18304-1-kwolf@redhat.com> References: <20180710154304.18304-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Tue, 10 Jul 2018 15:43:36 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Tue, 10 Jul 2018 15:43:36 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 19/24] block: Extract common write req handling X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Fam Zheng As a mechanical refactoring patch, this is the first step towards unified and more correct write code paths. This is helpful because multiple BlockDriverState fields need to be updated after modifying image data, and it's hard to maintain in multiple places such as copy offload, discard and truncate. Suggested-by: Kevin Wolf Signed-off-by: Fam Zheng Signed-off-by: Kevin Wolf --- block/io.c | 91 +++++++++++++++++++++++++++++++++++++++-------------------= ---- 1 file changed, 57 insertions(+), 34 deletions(-) diff --git a/block/io.c b/block/io.c index 6293612e73..313fe0776c 100644 --- a/block/io.c +++ b/block/io.c @@ -1575,6 +1575,61 @@ fail: return ret; } =20 +static inline int coroutine_fn +bdrv_co_write_req_prepare(BdrvChild *child, int64_t offset, uint64_t bytes, + BdrvTrackedRequest *req, int flags) +{ + BlockDriverState *bs =3D child->bs; + bool waited; + int64_t end_sector =3D DIV_ROUND_UP(offset + bytes, BDRV_SECTOR_SIZE); + + if (bs->read_only) { + return -EPERM; + } + + /* BDRV_REQ_NO_SERIALISING is only for read operation */ + assert(!(flags & BDRV_REQ_NO_SERIALISING)); + assert(!(bs->open_flags & BDRV_O_INACTIVE)); + assert((bs->open_flags & BDRV_O_NO_IO) =3D=3D 0); + assert(!(flags & ~BDRV_REQ_MASK)); + + if (flags & BDRV_REQ_SERIALISING) { + mark_request_serialising(req, bdrv_get_cluster_size(bs)); + } + + waited =3D wait_serialising_requests(req); + + assert(!waited || !req->serialising || + is_request_serialising_and_aligned(req)); + assert(req->overlap_offset <=3D offset); + assert(offset + bytes <=3D req->overlap_offset + req->overlap_bytes); + + if (flags & BDRV_REQ_WRITE_UNCHANGED) { + assert(child->perm & (BLK_PERM_WRITE_UNCHANGED | BLK_PERM_WRITE)); + } else { + assert(child->perm & BLK_PERM_WRITE); + } + assert(end_sector <=3D bs->total_sectors || child->perm & BLK_PERM_RES= IZE); + return notifier_with_return_list_notify(&bs->before_write_notifiers, r= eq); +} + +static inline void coroutine_fn +bdrv_co_write_req_finish(BdrvChild *child, int64_t offset, uint64_t bytes, + BdrvTrackedRequest *req, int ret) +{ + int64_t end_sector =3D DIV_ROUND_UP(offset + bytes, BDRV_SECTOR_SIZE); + BlockDriverState *bs =3D child->bs; + + atomic_inc(&bs->write_gen); + bdrv_set_dirty(bs, offset, bytes); + + stat64_max(&bs->wr_highest_offset, offset + bytes); + + if (ret =3D=3D 0) { + bs->total_sectors =3D MAX(bs->total_sectors, end_sector); + } +} + /* * Forwards an already correctly aligned write request to the BlockDriver, * after possibly fragmenting it. @@ -1585,10 +1640,8 @@ static int coroutine_fn bdrv_aligned_pwritev(BdrvChi= ld *child, { BlockDriverState *bs =3D child->bs; BlockDriver *drv =3D bs->drv; - bool waited; int ret; =20 - int64_t end_sector =3D DIV_ROUND_UP(offset + bytes, BDRV_SECTOR_SIZE); uint64_t bytes_remaining =3D bytes; int max_transfer; =20 @@ -1604,31 +1657,10 @@ static int coroutine_fn bdrv_aligned_pwritev(BdrvCh= ild *child, assert((offset & (align - 1)) =3D=3D 0); assert((bytes & (align - 1)) =3D=3D 0); assert(!qiov || bytes =3D=3D qiov->size); - assert((bs->open_flags & BDRV_O_NO_IO) =3D=3D 0); - assert(!(flags & ~BDRV_REQ_MASK)); max_transfer =3D QEMU_ALIGN_DOWN(MIN_NON_ZERO(bs->bl.max_transfer, INT= _MAX), align); =20 - /* BDRV_REQ_NO_SERIALISING is only for read operation */ - assert(!(flags & BDRV_REQ_NO_SERIALISING)); - - if (flags & BDRV_REQ_SERIALISING) { - mark_request_serialising(req, bdrv_get_cluster_size(bs)); - } - - waited =3D wait_serialising_requests(req); - assert(!waited || !req->serialising || - is_request_serialising_and_aligned(req)); - assert(req->overlap_offset <=3D offset); - assert(offset + bytes <=3D req->overlap_offset + req->overlap_bytes); - if (flags & BDRV_REQ_WRITE_UNCHANGED) { - assert(child->perm & (BLK_PERM_WRITE_UNCHANGED | BLK_PERM_WRITE)); - } else { - assert(child->perm & BLK_PERM_WRITE); - } - assert(end_sector <=3D bs->total_sectors || child->perm & BLK_PERM_RES= IZE); - - ret =3D notifier_with_return_list_notify(&bs->before_write_notifiers, = req); + ret =3D bdrv_co_write_req_prepare(child, offset, bytes, req, flags); =20 if (!ret && bs->detect_zeroes !=3D BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF = && !(flags & BDRV_REQ_ZERO_WRITE) && drv->bdrv_co_pwrite_zeroes && @@ -1677,15 +1709,10 @@ static int coroutine_fn bdrv_aligned_pwritev(BdrvCh= ild *child, } bdrv_debug_event(bs, BLKDBG_PWRITEV_DONE); =20 - atomic_inc(&bs->write_gen); - bdrv_set_dirty(bs, offset, bytes); - - stat64_max(&bs->wr_highest_offset, offset + bytes); - if (ret >=3D 0) { - bs->total_sectors =3D MAX(bs->total_sectors, end_sector); ret =3D 0; } + bdrv_co_write_req_finish(child, offset, bytes, req, ret); =20 return ret; } @@ -1800,10 +1827,6 @@ int coroutine_fn bdrv_co_pwritev(BdrvChild *child, if (!bs->drv) { return -ENOMEDIUM; } - if (bs->read_only) { - return -EPERM; - } - assert(!(bs->open_flags & BDRV_O_INACTIVE)); =20 ret =3D bdrv_check_byte_request(bs, offset, bytes); if (ret < 0) { --=20 2.13.6 From nobody Wed Apr 16 03:21:50 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1531238053740259.00725702734803; Tue, 10 Jul 2018 08:54:13 -0700 (PDT) Received: from localhost ([::1]:48512 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fcuxw-00058f-L3 for importer@patchew.org; Tue, 10 Jul 2018 11:54:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44593) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fcunn-0005N3-4I for qemu-devel@nongnu.org; Tue, 10 Jul 2018 11:43:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fcunm-0001lv-8c for qemu-devel@nongnu.org; Tue, 10 Jul 2018 11:43:43 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:60790 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fcuni-0001jL-2b; Tue, 10 Jul 2018 11:43:38 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9D00B4067720; Tue, 10 Jul 2018 15:43:37 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-156.ams2.redhat.com [10.36.116.156]) by smtp.corp.redhat.com (Postfix) with ESMTP id CB8BC2026D6B; Tue, 10 Jul 2018 15:43:36 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 10 Jul 2018 17:43:00 +0200 Message-Id: <20180710154304.18304-21-kwolf@redhat.com> In-Reply-To: <20180710154304.18304-1-kwolf@redhat.com> References: <20180710154304.18304-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Tue, 10 Jul 2018 15:43:37 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Tue, 10 Jul 2018 15:43:37 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 20/24] block: Fix handling of image enlarging write X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Fam Zheng Two problems exist when a write request that enlarges the image (i.e. write beyond EOF) finishes: 1) parent is not notified about size change; 2) dirty bitmap is not resized although we try to set the dirty bits; Fix them just like how bdrv_co_truncate works. Reported-by: Kevin Wolf Signed-off-by: Fam Zheng Signed-off-by: Kevin Wolf --- block/io.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/block/io.c b/block/io.c index 313fe0776c..c88b2b48d7 100644 --- a/block/io.c +++ b/block/io.c @@ -40,6 +40,7 @@ =20 static AioWait drain_all_aio_wait; =20 +static void bdrv_parent_cb_resize(BlockDriverState *bs); static int coroutine_fn bdrv_co_do_pwrite_zeroes(BlockDriverState *bs, int64_t offset, int bytes, BdrvRequestFlags flags); =20 @@ -1621,13 +1622,16 @@ bdrv_co_write_req_finish(BdrvChild *child, int64_t = offset, uint64_t bytes, BlockDriverState *bs =3D child->bs; =20 atomic_inc(&bs->write_gen); - bdrv_set_dirty(bs, offset, bytes); =20 stat64_max(&bs->wr_highest_offset, offset + bytes); =20 - if (ret =3D=3D 0) { - bs->total_sectors =3D MAX(bs->total_sectors, end_sector); + if (ret =3D=3D 0 && + end_sector > bs->total_sectors) { + bs->total_sectors =3D end_sector; + bdrv_parent_cb_resize(bs); + bdrv_dirty_bitmap_truncate(bs, end_sector << BDRV_SECTOR_BITS); } + bdrv_set_dirty(bs, offset, bytes); } =20 /* --=20 2.13.6 From nobody Wed Apr 16 03:21:50 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1531238223007697.0707206399622; Tue, 10 Jul 2018 08:57:03 -0700 (PDT) Received: from localhost ([::1]:48532 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fcv0g-0007tK-0v for importer@patchew.org; Tue, 10 Jul 2018 11:57:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44607) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fcunn-0005Nk-Il for qemu-devel@nongnu.org; Tue, 10 Jul 2018 11:43:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fcunm-0001mN-Je for qemu-devel@nongnu.org; Tue, 10 Jul 2018 11:43:43 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:45906 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fcunj-0001jx-4Z; Tue, 10 Jul 2018 11:43:39 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AC7D277889; Tue, 10 Jul 2018 15:43:38 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-156.ams2.redhat.com [10.36.116.156]) by smtp.corp.redhat.com (Postfix) with ESMTP id DA2BF2026D6B; Tue, 10 Jul 2018 15:43:37 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 10 Jul 2018 17:43:01 +0200 Message-Id: <20180710154304.18304-22-kwolf@redhat.com> In-Reply-To: <20180710154304.18304-1-kwolf@redhat.com> References: <20180710154304.18304-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Tue, 10 Jul 2018 15:43:38 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Tue, 10 Jul 2018 15:43:38 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 21/24] block: Use common req handling for discard X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Fam Zheng Reuse the new bdrv_co_write_req_prepare/finish helpers. The variation here is that discard requests don't affect bs->wr_highest_offset, and it cannot extend the image. Signed-off-by: Fam Zheng Signed-off-by: Kevin Wolf --- block/io.c | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/block/io.c b/block/io.c index c88b2b48d7..72cfd9bd16 100644 --- a/block/io.c +++ b/block/io.c @@ -1623,15 +1623,32 @@ bdrv_co_write_req_finish(BdrvChild *child, int64_t = offset, uint64_t bytes, =20 atomic_inc(&bs->write_gen); =20 - stat64_max(&bs->wr_highest_offset, offset + bytes); - + /* + * Discard cannot extend the image, but in error handling cases, such = as + * when reverting a qcow2 cluster allocation, the discarded range can = pass + * the end of image file, so we cannot assert about BDRV_TRACKED_DISCA= RD + * here. Instead, just skip it, since semantically a discard request + * beyond EOF cannot expand the image anyway. + */ if (ret =3D=3D 0 && - end_sector > bs->total_sectors) { + end_sector > bs->total_sectors && + req->type !=3D BDRV_TRACKED_DISCARD) { bs->total_sectors =3D end_sector; bdrv_parent_cb_resize(bs); bdrv_dirty_bitmap_truncate(bs, end_sector << BDRV_SECTOR_BITS); } - bdrv_set_dirty(bs, offset, bytes); + if (req->bytes) { + switch (req->type) { + case BDRV_TRACKED_WRITE: + stat64_max(&bs->wr_highest_offset, offset + bytes); + /* fall through, to set dirty bits */ + case BDRV_TRACKED_DISCARD: + bdrv_set_dirty(bs, offset, bytes); + break; + default: + break; + } + } } =20 /* @@ -2692,10 +2709,7 @@ int coroutine_fn bdrv_co_pdiscard(BdrvChild *child, = int64_t offset, int bytes) ret =3D bdrv_check_byte_request(bs, offset, bytes); if (ret < 0) { return ret; - } else if (bs->read_only) { - return -EPERM; } - assert(!(bs->open_flags & BDRV_O_INACTIVE)); =20 /* Do nothing if disabled. */ if (!(bs->open_flags & BDRV_O_UNMAP)) { @@ -2719,7 +2733,7 @@ int coroutine_fn bdrv_co_pdiscard(BdrvChild *child, i= nt64_t offset, int bytes) bdrv_inc_in_flight(bs); tracked_request_begin(&req, bs, offset, bytes, BDRV_TRACKED_DISCARD); =20 - ret =3D notifier_with_return_list_notify(&bs->before_write_notifiers, = &req); + ret =3D bdrv_co_write_req_prepare(child, offset, bytes, &req, 0); if (ret < 0) { goto out; } @@ -2785,8 +2799,7 @@ int coroutine_fn bdrv_co_pdiscard(BdrvChild *child, i= nt64_t offset, int bytes) } ret =3D 0; out: - atomic_inc(&bs->write_gen); - bdrv_set_dirty(bs, req.offset, req.bytes); + bdrv_co_write_req_finish(child, req.offset, req.bytes, &req, ret); tracked_request_end(&req); bdrv_dec_in_flight(bs); return ret; --=20 2.13.6 From nobody Wed Apr 16 03:21:50 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1531238757582313.25676523978836; Tue, 10 Jul 2018 09:05:57 -0700 (PDT) Received: from localhost ([::1]:48591 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fcv9I-0007QK-GY for importer@patchew.org; Tue, 10 Jul 2018 12:05:56 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44596) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fcunn-0005N6-5t for qemu-devel@nongnu.org; Tue, 10 Jul 2018 11:43:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fcunm-0001m5-B1 for qemu-devel@nongnu.org; Tue, 10 Jul 2018 11:43:43 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:34330 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fcunk-0001kW-6L; Tue, 10 Jul 2018 11:43:40 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BADB0402315B; Tue, 10 Jul 2018 15:43:39 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-156.ams2.redhat.com [10.36.116.156]) by smtp.corp.redhat.com (Postfix) with ESMTP id E90B72026D6B; Tue, 10 Jul 2018 15:43:38 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 10 Jul 2018 17:43:02 +0200 Message-Id: <20180710154304.18304-23-kwolf@redhat.com> In-Reply-To: <20180710154304.18304-1-kwolf@redhat.com> References: <20180710154304.18304-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Tue, 10 Jul 2018 15:43:39 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Tue, 10 Jul 2018 15:43:39 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 22/24] block: Use common req handling in copy offloading X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Fam Zheng This brings the request handling logic inline with write and discard, fixing write_gen, resize_cb, dirty bitmaps and image size refreshing. The last of these issues broke iotest case 222, which is now fixed. Signed-off-by: Fam Zheng Signed-off-by: Kevin Wolf --- block/io.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/block/io.c b/block/io.c index 72cfd9bd16..2832214db4 100644 --- a/block/io.c +++ b/block/io.c @@ -3030,20 +3030,16 @@ static int coroutine_fn bdrv_co_copy_range_internal( bdrv_inc_in_flight(dst->bs); tracked_request_begin(&req, dst->bs, dst_offset, bytes, BDRV_TRACKED_WRITE); - - /* BDRV_REQ_NO_SERIALISING is only for read operation */ - assert(!(write_flags & BDRV_REQ_NO_SERIALISING)); - if (write_flags & BDRV_REQ_SERIALISING) { - mark_request_serialising(&req, bdrv_get_cluster_size(dst->bs)); - } - wait_serialising_requests(&req); - - ret =3D dst->bs->drv->bdrv_co_copy_range_to(dst->bs, - src, src_offset, - dst, dst_offset, - bytes, - read_flags, write_flags); - + ret =3D bdrv_co_write_req_prepare(dst, dst_offset, bytes, &req, + write_flags); + if (!ret) { + ret =3D dst->bs->drv->bdrv_co_copy_range_to(dst->bs, + src, src_offset, + dst, dst_offset, + bytes, + read_flags, write_fl= ags); + } + bdrv_co_write_req_finish(dst, dst_offset, bytes, &req, ret); tracked_request_end(&req); bdrv_dec_in_flight(dst->bs); } --=20 2.13.6 From nobody Wed Apr 16 03:21:50 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1531239707826105.93219895270181; Tue, 10 Jul 2018 09:21:47 -0700 (PDT) Received: from localhost ([::1]:48773 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fcvOY-0003VA-S4 for importer@patchew.org; Tue, 10 Jul 2018 12:21:42 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44627) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fcuno-0005Oc-8V for qemu-devel@nongnu.org; Tue, 10 Jul 2018 11:43:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fcunn-0001ms-Ev for qemu-devel@nongnu.org; Tue, 10 Jul 2018 11:43:44 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:45912 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fcunl-0001ks-AO; Tue, 10 Jul 2018 11:43:41 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CA98A77889; Tue, 10 Jul 2018 15:43:40 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-156.ams2.redhat.com [10.36.116.156]) by smtp.corp.redhat.com (Postfix) with ESMTP id 03DB62026D6B; Tue, 10 Jul 2018 15:43:39 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 10 Jul 2018 17:43:03 +0200 Message-Id: <20180710154304.18304-24-kwolf@redhat.com> In-Reply-To: <20180710154304.18304-1-kwolf@redhat.com> References: <20180710154304.18304-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Tue, 10 Jul 2018 15:43:40 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Tue, 10 Jul 2018 15:43:40 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 23/24] block: Fix bdrv_co_truncate overlap check X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Fam Zheng If we are growing the image and potentially using preallocation for the new area, we need to make sure that no write requests are made to the "preallocated" area which is [@old_size, @offset), not [@offset, offset * 2 - @old_size). Signed-off-by: Fam Zheng Reviewed-by: Eric Blake Signed-off-by: Kevin Wolf --- block/io.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/block/io.c b/block/io.c index 2832214db4..77d38ca1d3 100644 --- a/block/io.c +++ b/block/io.c @@ -3136,7 +3136,8 @@ int coroutine_fn bdrv_co_truncate(BdrvChild *child, i= nt64_t offset, } =20 bdrv_inc_in_flight(bs); - tracked_request_begin(&req, bs, offset, new_bytes, BDRV_TRACKED_TRUNCA= TE); + tracked_request_begin(&req, bs, offset - new_bytes, new_bytes, + BDRV_TRACKED_TRUNCATE); =20 /* If we are growing the image and potentially using preallocation for= the * new area, we need to make sure that no write requests are made to it --=20 2.13.6 From nobody Wed Apr 16 03:21:50 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1531238402713467.61171357315834; Tue, 10 Jul 2018 09:00:02 -0700 (PDT) Received: from localhost ([::1]:48547 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fcv3Z-0002Dp-LX for importer@patchew.org; Tue, 10 Jul 2018 12:00:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44647) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fcunq-0005Qw-17 for qemu-devel@nongnu.org; Tue, 10 Jul 2018 11:43:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fcuno-0001nb-UO for qemu-devel@nongnu.org; Tue, 10 Jul 2018 11:43:46 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:38828 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fcunm-0001li-Al; Tue, 10 Jul 2018 11:43:42 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D948585629; Tue, 10 Jul 2018 15:43:41 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-156.ams2.redhat.com [10.36.116.156]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1355B2026D6B; Tue, 10 Jul 2018 15:43:40 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 10 Jul 2018 17:43:04 +0200 Message-Id: <20180710154304.18304-25-kwolf@redhat.com> In-Reply-To: <20180710154304.18304-1-kwolf@redhat.com> References: <20180710154304.18304-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Tue, 10 Jul 2018 15:43:41 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Tue, 10 Jul 2018 15:43:41 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 24/24] block: Use common write req handling in truncate X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Fam Zheng Truncation is the last to convert from open coded req handling to reusing helpers. This time the permission check in prepare has to adapt to the new caller: it checks a different permission bit, and doesn't trigger the before write notifier. Also, truncation should always trigger a bs->total_sectors update and in turn call parent resize_cb. Update the condition in finish helper, too. It's intended to do a duplicated bs->read_only check before calling bdrv_co_write_req_prepare() so that we can be more informative with the error message, as bdrv_co_write_req_prepare() doesn't have Error parameter. Signed-off-by: Fam Zheng Signed-off-by: Kevin Wolf --- block/io.c | 55 +++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 35 insertions(+), 20 deletions(-) diff --git a/block/io.c b/block/io.c index 77d38ca1d3..7100344c7b 100644 --- a/block/io.c +++ b/block/io.c @@ -1604,14 +1604,24 @@ bdrv_co_write_req_prepare(BdrvChild *child, int64_t= offset, uint64_t bytes, is_request_serialising_and_aligned(req)); assert(req->overlap_offset <=3D offset); assert(offset + bytes <=3D req->overlap_offset + req->overlap_bytes); + assert(end_sector <=3D bs->total_sectors || child->perm & BLK_PERM_RES= IZE); =20 - if (flags & BDRV_REQ_WRITE_UNCHANGED) { - assert(child->perm & (BLK_PERM_WRITE_UNCHANGED | BLK_PERM_WRITE)); - } else { - assert(child->perm & BLK_PERM_WRITE); + switch (req->type) { + case BDRV_TRACKED_WRITE: + case BDRV_TRACKED_DISCARD: + if (flags & BDRV_REQ_WRITE_UNCHANGED) { + assert(child->perm & (BLK_PERM_WRITE_UNCHANGED | BLK_PERM_WRIT= E)); + } else { + assert(child->perm & BLK_PERM_WRITE); + } + return notifier_with_return_list_notify(&bs->before_write_notifier= s, + req); + case BDRV_TRACKED_TRUNCATE: + assert(child->perm & BLK_PERM_RESIZE); + return 0; + default: + abort(); } - assert(end_sector <=3D bs->total_sectors || child->perm & BLK_PERM_RES= IZE); - return notifier_with_return_list_notify(&bs->before_write_notifiers, r= eq); } =20 static inline void coroutine_fn @@ -1631,8 +1641,9 @@ bdrv_co_write_req_finish(BdrvChild *child, int64_t of= fset, uint64_t bytes, * beyond EOF cannot expand the image anyway. */ if (ret =3D=3D 0 && - end_sector > bs->total_sectors && - req->type !=3D BDRV_TRACKED_DISCARD) { + (req->type =3D=3D BDRV_TRACKED_TRUNCATE || + end_sector > bs->total_sectors) && + req->type !=3D BDRV_TRACKED_DISCARD) { bs->total_sectors =3D end_sector; bdrv_parent_cb_resize(bs); bdrv_dirty_bitmap_truncate(bs, end_sector << BDRV_SECTOR_BITS); @@ -3111,7 +3122,6 @@ int coroutine_fn bdrv_co_truncate(BdrvChild *child, i= nt64_t offset, int64_t old_size, new_bytes; int ret; =20 - assert(child->perm & BLK_PERM_RESIZE); =20 /* if bs->drv =3D=3D NULL, bs is closed, so there's nothing to do here= */ if (!drv) { @@ -3144,7 +3154,18 @@ int coroutine_fn bdrv_co_truncate(BdrvChild *child, = int64_t offset, * concurrently or they might be overwritten by preallocation. */ if (new_bytes) { mark_request_serialising(&req, 1); - wait_serialising_requests(&req); + } + if (bs->read_only) { + error_setg(errp, "Image is read-only"); + ret =3D -EACCES; + goto out; + } + ret =3D bdrv_co_write_req_prepare(child, offset - new_bytes, new_bytes= , &req, + 0); + if (ret < 0) { + error_setg_errno(errp, -ret, + "Failed to prepare request for truncation"); + goto out; } =20 if (!drv->bdrv_co_truncate) { @@ -3156,13 +3177,6 @@ int coroutine_fn bdrv_co_truncate(BdrvChild *child, = int64_t offset, ret =3D -ENOTSUP; goto out; } - if (bs->read_only) { - error_setg(errp, "Image is read-only"); - ret =3D -EACCES; - goto out; - } - - assert(!(bs->open_flags & BDRV_O_INACTIVE)); =20 ret =3D drv->bdrv_co_truncate(bs, offset, prealloc, errp); if (ret < 0) { @@ -3174,9 +3188,10 @@ int coroutine_fn bdrv_co_truncate(BdrvChild *child, = int64_t offset, } else { offset =3D bs->total_sectors * BDRV_SECTOR_SIZE; } - bdrv_dirty_bitmap_truncate(bs, offset); - bdrv_parent_cb_resize(bs); - atomic_inc(&bs->write_gen); + /* It's possible that truncation succeeded but refresh_total_sectors + * failed, but the latter doesn't affect how we should finish the requ= est. + * Pass 0 as the last parameter so that dirty bitmaps etc. are handled= . */ + bdrv_co_write_req_finish(child, offset - new_bytes, new_bytes, &req, 0= ); =20 out: tracked_request_end(&req); --=20 2.13.6