From nobody Mon Feb 9 07:44:41 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1563988400; cv=none; d=zoho.com; s=zohoarc; b=elNkmMCPTpnmKFxArMJnILeJZ62LdwCLnJubwGbPO0NG3Tb2z/GXbYFekWTd6toy8bxtzaIiamp2+H8mMIMDxVOsZfZzRB7OnVY3OT8KgQ34L/VUmfLzFM3ZgX0HeFhhpRkZ2E8/7ntL42ZLCO4/IXHtxLOaNG3h0DMKQJE87I4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563988400; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=5hEGGa+FFpfi3nBVmBmOTCyHaIgefkG53Z3/HMrGfl8=; b=R5+H+Gas+uUG84VLZiJi4z05YPEos23H6N8p6OlpHbYkzEuhN3CeXnDIx1lr1Ta4vzas0DbbeubI3VstAilCzme3NLW2T409UAMoMw/uq6Pkra4r7UIGkTCb0HcIEoyBvxkm17bZbv5AdY2mQQkaj4Jw1l8YsB/Ve2Feh0zgQ7I= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1563988400316518.5196495720029; Wed, 24 Jul 2019 10:13:20 -0700 (PDT) Received: from localhost ([::1]:53594 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hqKpG-0004SC-IT for importer@patchew.org; Wed, 24 Jul 2019 13:13:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49364) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hqKot-0003Nv-Fv for qemu-devel@nongnu.org; Wed, 24 Jul 2019 13:12:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hqKos-0004XD-GU for qemu-devel@nongnu.org; Wed, 24 Jul 2019 13:12:51 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59218) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hqKoo-0004FS-DU; Wed, 24 Jul 2019 13:12:46 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6FFA5356E7; Wed, 24 Jul 2019 17:12:45 +0000 (UTC) Received: from localhost (ovpn-204-115.brq.redhat.com [10.40.204.115]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DBE185C22D; Wed, 24 Jul 2019 17:12:44 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Wed, 24 Jul 2019 19:12:29 +0200 Message-Id: <20190724171239.8764-2-mreitz@redhat.com> In-Reply-To: <20190724171239.8764-1-mreitz@redhat.com> References: <20190724171239.8764-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 24 Jul 2019 17:12:45 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 01/11] qemu-img: Fix bdrv_has_zero_init() use in convert X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Stefano Garzarella , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" bdrv_has_zero_init() only has meaning for newly created images or image areas. If qemu-img convert did not create the image itself, it cannot rely on bdrv_has_zero_init()'s result to carry any meaning. Signed-off-by: Max Reitz Reviewed-by: Maxim Levitsky Reviewed-by: Stefano Garzarella --- qemu-img.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 79983772de..0f4be80c10 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -1578,6 +1578,7 @@ typedef struct ImgConvertState { bool has_zero_init; bool compressed; bool unallocated_blocks_are_zero; + bool target_is_new; bool target_has_backing; int64_t target_backing_sectors; /* negative if unknown */ bool wr_in_order; @@ -1975,9 +1976,11 @@ static int convert_do_copy(ImgConvertState *s) int64_t sector_num =3D 0; =20 /* Check whether we have zero initialisation or can get it efficiently= */ - s->has_zero_init =3D s->min_sparse && !s->target_has_backing - ? bdrv_has_zero_init(blk_bs(s->target)) - : false; + if (s->target_is_new && s->min_sparse && !s->target_has_backing) { + s->has_zero_init =3D bdrv_has_zero_init(blk_bs(s->target)); + } else { + s->has_zero_init =3D false; + } =20 if (!s->has_zero_init && !s->target_has_backing && bdrv_can_write_zeroes_with_unmap(blk_bs(s->target))) @@ -2423,6 +2426,8 @@ static int img_convert(int argc, char **argv) } } =20 + s.target_is_new =3D !skip_create; + flags =3D s.min_sparse ? (BDRV_O_RDWR | BDRV_O_UNMAP) : BDRV_O_RDWR; ret =3D bdrv_parse_cache_mode(cache, &flags, &writethrough); if (ret < 0) { --=20 2.21.0 From nobody Mon Feb 9 07:44:41 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1563988439; cv=none; d=zoho.com; s=zohoarc; b=jQc6cWYEBRWa3TFHEoEHaTuQZepAr3Zw4qeVpExsX5IfpKYw7gGjfg6Hmp3C8OUwDms8PBo79AGpD8y1tGKBLsaGF6eqRLhviYChaTiHPBfKE5ltO7mCmn2eY5uq6RftVpKcIBxbZKshEVkONy6aILX6ygnm/vPpCIcINz8ueCE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563988439; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=zr7Bz2yOfxrvZiXxBQCodVvBfyz7W/eEI4x3XMgLQAM=; b=nXMKGidZbQsrhna00/ApeXMkRGXxPX72LUXnVxem5B2xOHFmp932jOZSO4YjS0UfClXr1Xa29y6Ft7S+7ZgpdxB3kcKBZi3FUG2LFhzTct5w185XeCjkTmIy0SzCS77sKbwUxVI9UqE5Wfr3aMIvjmXoqWvSrQPZTNH/rjYjwog= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1563988439183335.8249020105644; Wed, 24 Jul 2019 10:13:59 -0700 (PDT) Received: from localhost ([::1]:53614 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hqKpv-00079b-EV for importer@patchew.org; Wed, 24 Jul 2019 13:13:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49436) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hqKp0-0003go-C2 for qemu-devel@nongnu.org; Wed, 24 Jul 2019 13:12:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hqKov-0004kN-OY for qemu-devel@nongnu.org; Wed, 24 Jul 2019 13:12:56 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34396) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hqKor-0004TU-UF; Wed, 24 Jul 2019 13:12:50 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3E1B53086262; Wed, 24 Jul 2019 17:12:49 +0000 (UTC) Received: from localhost (ovpn-204-115.brq.redhat.com [10.40.204.115]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5CCB75C22D; Wed, 24 Jul 2019 17:12:48 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Wed, 24 Jul 2019 19:12:30 +0200 Message-Id: <20190724171239.8764-3-mreitz@redhat.com> In-Reply-To: <20190724171239.8764-1-mreitz@redhat.com> References: <20190724171239.8764-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Wed, 24 Jul 2019 17:12:49 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 02/11] mirror: Fix bdrv_has_zero_init() use X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Stefano Garzarella , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" bdrv_has_zero_init() only has meaning for newly created images or image areas. If the mirror job itself did not create the image, it cannot rely on bdrv_has_zero_init()'s result to carry any meaning. This is the case for drive-mirror with mode=3Dexisting and always for blockdev-mirror. Note that we only have to zero-initialize the target with sync=3Dfull, because other modes actually do not promise that the target will contain the same data as the source after the job -- sync=3Dtop only promises to copy anything allocated in the top layer, and sync=3Dnone will only copy new I/O. (Which is how mirror has always handled it.) Signed-off-by: Max Reitz Reviewed-by: Maxim Levitsky --- include/block/block_int.h | 2 ++ block/mirror.c | 11 ++++++++--- blockdev.c | 16 +++++++++++++--- tests/test-block-iothread.c | 2 +- 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/include/block/block_int.h b/include/block/block_int.h index 3aa1e832a8..6a0b1b5008 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -1116,6 +1116,7 @@ BlockJob *commit_active_start(const char *job_id, Blo= ckDriverState *bs, * @buf_size: The amount of data that can be in flight at one time. * @mode: Whether to collapse all images in the chain to the target. * @backing_mode: How to establish the target's backing chain after comple= tion. + * @zero_target: Whether the target should be explicitly zero-initialized * @on_source_error: The action to take upon error reading from the source. * @on_target_error: The action to take upon error writing to the target. * @unmap: Whether to unmap target where source sectors only contain zeroe= s. @@ -1135,6 +1136,7 @@ void mirror_start(const char *job_id, BlockDriverStat= e *bs, int creation_flags, int64_t speed, uint32_t granularity, int64_t buf_size, MirrorSyncMode mode, BlockMirrorBackingMode backing_mode, + bool zero_target, BlockdevOnError on_source_error, BlockdevOnError on_target_error, bool unmap, const char *filter_node_name, diff --git a/block/mirror.c b/block/mirror.c index 8cb75fb409..50188ce6e9 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -51,6 +51,8 @@ typedef struct MirrorBlockJob { Error *replace_blocker; bool is_none_mode; BlockMirrorBackingMode backing_mode; + /* Whether the target image requires explicit zero-initialization */ + bool zero_target; MirrorCopyMode copy_mode; BlockdevOnError on_source_error, on_target_error; bool synced; @@ -763,7 +765,7 @@ static int coroutine_fn mirror_dirty_init(MirrorBlockJo= b *s) int ret; int64_t count; =20 - if (base =3D=3D NULL && !bdrv_has_zero_init(target_bs)) { + if (s->zero_target) { if (!bdrv_can_write_zeroes_with_unmap(target_bs)) { bdrv_set_dirty_bitmap(s->dirty_bitmap, 0, s->bdev_length); return 0; @@ -1501,6 +1503,7 @@ static BlockJob *mirror_start_job( const char *replaces, int64_t speed, uint32_t granularity, int64_t buf_size, BlockMirrorBackingMode backing_mode, + bool zero_target, BlockdevOnError on_source_error, BlockdevOnError on_target_error, bool unmap, @@ -1628,6 +1631,7 @@ static BlockJob *mirror_start_job( s->on_target_error =3D on_target_error; s->is_none_mode =3D is_none_mode; s->backing_mode =3D backing_mode; + s->zero_target =3D zero_target; s->copy_mode =3D copy_mode; s->base =3D base; s->granularity =3D granularity; @@ -1713,6 +1717,7 @@ void mirror_start(const char *job_id, BlockDriverStat= e *bs, int creation_flags, int64_t speed, uint32_t granularity, int64_t buf_size, MirrorSyncMode mode, BlockMirrorBackingMode backing_mode, + bool zero_target, BlockdevOnError on_source_error, BlockdevOnError on_target_error, bool unmap, const char *filter_node_name, @@ -1728,7 +1733,7 @@ void mirror_start(const char *job_id, BlockDriverStat= e *bs, is_none_mode =3D mode =3D=3D MIRROR_SYNC_MODE_NONE; base =3D mode =3D=3D MIRROR_SYNC_MODE_TOP ? backing_bs(bs) : NULL; mirror_start_job(job_id, bs, creation_flags, target, replaces, - speed, granularity, buf_size, backing_mode, + speed, granularity, buf_size, backing_mode, zero_targ= et, on_source_error, on_target_error, unmap, NULL, NULL, &mirror_job_driver, is_none_mode, base, false, filter_node_name, true, copy_mode, errp); @@ -1755,7 +1760,7 @@ BlockJob *commit_active_start(const char *job_id, Blo= ckDriverState *bs, =20 ret =3D mirror_start_job( job_id, bs, creation_flags, base, NULL, speed, 0, 0, - MIRROR_LEAVE_BACKING_CHAIN, + MIRROR_LEAVE_BACKING_CHAIN, false, on_error, on_error, true, cb, opaque, &commit_active_job_driver, false, base, auto_complete, filter_node_name, false, MIRROR_COPY_MODE_BACKGROUND, diff --git a/blockdev.c b/blockdev.c index 4d141e9a1f..0323f77850 100644 --- a/blockdev.c +++ b/blockdev.c @@ -3705,6 +3705,7 @@ static void blockdev_mirror_common(const char *job_id= , BlockDriverState *bs, bool has_replaces, const char *replaces, enum MirrorSyncMode sync, BlockMirrorBackingMode backing_mode, + bool zero_target, bool has_speed, int64_t speed, bool has_granularity, uint32_t granular= ity, bool has_buf_size, int64_t buf_size, @@ -3813,7 +3814,7 @@ static void blockdev_mirror_common(const char *job_id= , BlockDriverState *bs, */ mirror_start(job_id, bs, target, has_replaces ? replaces : NULL, job_flags, - speed, granularity, buf_size, sync, backing_mode, + speed, granularity, buf_size, sync, backing_mode, zero_ta= rget, on_source_error, on_target_error, unmap, filter_node_name, copy_mode, errp); } @@ -3829,6 +3830,7 @@ void qmp_drive_mirror(DriveMirror *arg, Error **errp) int flags; int64_t size; const char *format =3D arg->format; + bool zero_target; int ret; =20 bs =3D qmp_get_root_bs(arg->device, errp); @@ -3930,6 +3932,10 @@ void qmp_drive_mirror(DriveMirror *arg, Error **errp) goto out; } =20 + zero_target =3D (arg->sync =3D=3D MIRROR_SYNC_MODE_FULL && + (arg->mode =3D=3D NEW_IMAGE_MODE_EXISTING || + !bdrv_has_zero_init(target_bs))); + ret =3D bdrv_try_set_aio_context(target_bs, aio_context, errp); if (ret < 0) { bdrv_unref(target_bs); @@ -3938,7 +3944,8 @@ void qmp_drive_mirror(DriveMirror *arg, Error **errp) =20 blockdev_mirror_common(arg->has_job_id ? arg->job_id : NULL, bs, targe= t_bs, arg->has_replaces, arg->replaces, arg->sync, - backing_mode, arg->has_speed, arg->speed, + backing_mode, zero_target, + arg->has_speed, arg->speed, arg->has_granularity, arg->granularity, arg->has_buf_size, arg->buf_size, arg->has_on_source_error, arg->on_source_error, @@ -3978,6 +3985,7 @@ void qmp_blockdev_mirror(bool has_job_id, const char = *job_id, AioContext *aio_context; BlockMirrorBackingMode backing_mode =3D MIRROR_LEAVE_BACKING_CHAIN; Error *local_err =3D NULL; + bool zero_target; int ret; =20 bs =3D qmp_get_root_bs(device, errp); @@ -3990,6 +3998,8 @@ void qmp_blockdev_mirror(bool has_job_id, const char = *job_id, return; } =20 + zero_target =3D (sync =3D=3D MIRROR_SYNC_MODE_FULL); + aio_context =3D bdrv_get_aio_context(bs); aio_context_acquire(aio_context); =20 @@ -4000,7 +4010,7 @@ void qmp_blockdev_mirror(bool has_job_id, const char = *job_id, =20 blockdev_mirror_common(has_job_id ? job_id : NULL, bs, target_bs, has_replaces, replaces, sync, backing_mode, - has_speed, speed, + zero_target, has_speed, speed, has_granularity, granularity, has_buf_size, buf_size, has_on_source_error, on_source_error, diff --git a/tests/test-block-iothread.c b/tests/test-block-iothread.c index 1949d5e61a..debfb69bfb 100644 --- a/tests/test-block-iothread.c +++ b/tests/test-block-iothread.c @@ -611,7 +611,7 @@ static void test_propagate_mirror(void) =20 /* Start a mirror job */ mirror_start("job0", src, target, NULL, JOB_DEFAULT, 0, 0, 0, - MIRROR_SYNC_MODE_NONE, MIRROR_OPEN_BACKING_CHAIN, + MIRROR_SYNC_MODE_NONE, MIRROR_OPEN_BACKING_CHAIN, false, BLOCKDEV_ON_ERROR_REPORT, BLOCKDEV_ON_ERROR_REPORT, false, "filter_node", MIRROR_COPY_MODE_BACKGROUND, &error_abort); --=20 2.21.0 From nobody Mon Feb 9 07:44:41 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1563988412; cv=none; d=zoho.com; s=zohoarc; b=AtqGbfzf5r9XGO9H8y9/Yoi+zmDhxkDN1ztG9Qef8nuSJ5Slbg9YzyP9mwP+OC0m3t16vHxpvPy/1+ax6FB4VJQHevI3thKEIyP4qJmBY+iH4I5dMW1KtR4V/ZR1brGIMyam7k2HU2kONF5rU4Cb8yktfWMZOcJeMq6tkpq1Rwc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563988412; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=upVsQanHDwjLmzmn1pUs/8Hw+O9Q1WYs1VRmNXr/wRg=; b=fIU/No6VO0dHIpFSWXYMYQkOlxKzBgCPtmWRo8lrCm6b+CPl8xpA2I9+e4unXSxsTDMOISQK8lxkwCm5sqhLXjDUJv/iYfR4MKKxwaLD6D5VMNKKcMNORswNIpkpfkugcndtYyiBwdSm3Q5wvwjMY8bnpTTXaKVtJUdMYTBTbcQ= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1563988412959324.626880815665; Wed, 24 Jul 2019 10:13:32 -0700 (PDT) Received: from localhost ([::1]:53598 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hqKpX-0005Xp-C6 for importer@patchew.org; Wed, 24 Jul 2019 13:13:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49454) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hqKp0-0003lQ-HM for qemu-devel@nongnu.org; Wed, 24 Jul 2019 13:12:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hqKoy-0004sT-Cf for qemu-devel@nongnu.org; Wed, 24 Jul 2019 13:12:57 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56110) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hqKou-0004es-O9; Wed, 24 Jul 2019 13:12:52 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 10A88307D85B; Wed, 24 Jul 2019 17:12:52 +0000 (UTC) Received: from localhost (ovpn-204-115.brq.redhat.com [10.40.204.115]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9AFF91001DDE; Wed, 24 Jul 2019 17:12:51 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Wed, 24 Jul 2019 19:12:31 +0200 Message-Id: <20190724171239.8764-4-mreitz@redhat.com> In-Reply-To: <20190724171239.8764-1-mreitz@redhat.com> References: <20190724171239.8764-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Wed, 24 Jul 2019 17:12:52 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 03/11] block: Add bdrv_has_zero_init_truncate() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Stefano Garzarella , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" No .bdrv_has_zero_init() implementation returns 1 if growing the file would add non-zero areas (at least with PREALLOC_MODE_OFF), so using it in lieu of this new function was always safe. But on the other hand, it is possible that growing an image that is not zero-initialized would still add a zero-initialized area, like when using nonpreallocating truncation on a preallocated image. For callers that care only about truncation, not about creation with potential preallocation, this new function is useful. Alternatively, we could have added a PreallocMode parameter to bdrv_has_zero_init(). But the only user would have been qemu-img convert, which does not have a plain PreallocMode value right now -- it would have to parse the creation option to obtain it. Therefore, the simpler solution is to let bdrv_has_zero_init() inquire the preallocation status and add the new bdrv_has_zero_init_truncate() that presupposes PREALLOC_MODE_OFF. Signed-off-by: Max Reitz Reviewed-by: Maxim Levitsky Reviewed-by: Stefano Garzarella --- include/block/block.h | 1 + include/block/block_int.h | 7 +++++++ block.c | 21 +++++++++++++++++++++ 3 files changed, 29 insertions(+) diff --git a/include/block/block.h b/include/block/block.h index 50a07c1c33..5321d8afdf 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -438,6 +438,7 @@ int bdrv_pdiscard(BdrvChild *child, int64_t offset, int= 64_t bytes); int bdrv_co_pdiscard(BdrvChild *child, int64_t offset, int64_t bytes); int bdrv_has_zero_init_1(BlockDriverState *bs); int bdrv_has_zero_init(BlockDriverState *bs); +int bdrv_has_zero_init_truncate(BlockDriverState *bs); bool bdrv_unallocated_blocks_are_zero(BlockDriverState *bs); bool bdrv_can_write_zeroes_with_unmap(BlockDriverState *bs); int bdrv_block_status(BlockDriverState *bs, int64_t offset, diff --git a/include/block/block_int.h b/include/block/block_int.h index 6a0b1b5008..d7fc6b296b 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -420,9 +420,16 @@ struct BlockDriver { /* * Returns 1 if newly created images are guaranteed to contain only * zeros, 0 otherwise. + * Must return 0 if .bdrv_has_zero_init_truncate() returns 0. */ int (*bdrv_has_zero_init)(BlockDriverState *bs); =20 + /* + * Returns 1 if new areas added by growing the image with + * PREALLOC_MODE_OFF contain only zeros, 0 otherwise. + */ + int (*bdrv_has_zero_init_truncate)(BlockDriverState *bs); + /* Remove fd handlers, timers, and other event loop callbacks so the e= vent * loop is no longer in use. Called with no in-flight requests and in * depth-first traversal order with parents before child nodes. diff --git a/block.c b/block.c index cbd8da5f3b..81ae44dcf3 100644 --- a/block.c +++ b/block.c @@ -5066,6 +5066,27 @@ int bdrv_has_zero_init(BlockDriverState *bs) return 0; } =20 +int bdrv_has_zero_init_truncate(BlockDriverState *bs) +{ + if (!bs->drv) { + return 0; + } + + if (bs->backing) { + /* Depends on the backing image length, but better safe than sorry= */ + return 0; + } + if (bs->drv->bdrv_has_zero_init_truncate) { + return bs->drv->bdrv_has_zero_init_truncate(bs); + } + if (bs->file && bs->drv->is_filter) { + return bdrv_has_zero_init_truncate(bs->file->bs); + } + + /* safe default */ + return 0; +} + bool bdrv_unallocated_blocks_are_zero(BlockDriverState *bs) { BlockDriverInfo bdi; --=20 2.21.0 From nobody Mon Feb 9 07:44:41 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1563988482; cv=none; d=zoho.com; s=zohoarc; b=BqwSB+13DcHrHsI5HuB3Ofbv9vsWRy0OGWi22jzV/4y5N+Z8xnjC9QWroe4hP3ZkitK3i+iuaDBS9ONI7Mxb7oESsDoahL1+3udE/hlFK6w0w99NwGi2XWi56lqN4+mgHnTEliC6Rot7YingJUbp3tXD3zeLTDDN0ioGxZhWQfc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563988482; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=bYcbqkPg+Ag4UqcN9AysNXbE3ut06yhgxnkX25Pqfi0=; b=MW2zl9U/SDdFZq3xRlziLYdbYSabWoss16vY6Jy39GkybeRJ7zOGZzv7krbWr97CM2TKK+QGt/3VZxR/LK29F5CPbZIGEu4pKyfKvsb9e31aW00NV+7a6u6+7PAIk7z6eZURzW9vsPQwQCW2XHUX6Oad+FKnkwIhyb/mjpMg3sc= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1563988482262954.0908845490126; Wed, 24 Jul 2019 10:14:42 -0700 (PDT) Received: from localhost ([::1]:53642 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hqKqe-0002IO-NH for importer@patchew.org; Wed, 24 Jul 2019 13:14:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49522) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hqKp3-000445-Tv for qemu-devel@nongnu.org; Wed, 24 Jul 2019 13:13:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hqKp2-0005Ad-Ju for qemu-devel@nongnu.org; Wed, 24 Jul 2019 13:13:01 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40098) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hqKoz-0004pc-7W; Wed, 24 Jul 2019 13:12:57 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5E0A530833A5; Wed, 24 Jul 2019 17:12:55 +0000 (UTC) Received: from localhost (ovpn-204-115.brq.redhat.com [10.40.204.115]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B31395D9DE; Wed, 24 Jul 2019 17:12:54 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Wed, 24 Jul 2019 19:12:32 +0200 Message-Id: <20190724171239.8764-5-mreitz@redhat.com> In-Reply-To: <20190724171239.8764-1-mreitz@redhat.com> References: <20190724171239.8764-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Wed, 24 Jul 2019 17:12:55 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 04/11] block: Implement .bdrv_has_zero_init_truncate() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Stefano Garzarella , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" We need to implement .bdrv_has_zero_init_truncate() for every block driver that supports truncation and has a .bdrv_has_zero_init() implementation. Implement it the same way each driver implements .bdrv_has_zero_init(). This is at least not any more unsafe than what we had before. Signed-off-by: Max Reitz Reviewed-by: Maxim Levitsky Reviewed-by: Stefano Garzarella --- block/file-posix.c | 1 + block/file-win32.c | 1 + block/gluster.c | 4 ++++ block/nfs.c | 1 + block/qcow2.c | 1 + block/qed.c | 1 + block/raw-format.c | 6 ++++++ block/rbd.c | 1 + block/sheepdog.c | 1 + block/ssh.c | 1 + 10 files changed, 18 insertions(+) diff --git a/block/file-posix.c b/block/file-posix.c index 4479cc7ab4..0208006f3c 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -2924,6 +2924,7 @@ BlockDriver bdrv_file =3D { .bdrv_co_create =3D raw_co_create, .bdrv_co_create_opts =3D raw_co_create_opts, .bdrv_has_zero_init =3D bdrv_has_zero_init_1, + .bdrv_has_zero_init_truncate =3D bdrv_has_zero_init_1, .bdrv_co_block_status =3D raw_co_block_status, .bdrv_co_invalidate_cache =3D raw_co_invalidate_cache, .bdrv_co_pwrite_zeroes =3D raw_co_pwrite_zeroes, diff --git a/block/file-win32.c b/block/file-win32.c index 6b2d67b239..41f55dfece 100644 --- a/block/file-win32.c +++ b/block/file-win32.c @@ -635,6 +635,7 @@ BlockDriver bdrv_file =3D { .bdrv_close =3D raw_close, .bdrv_co_create_opts =3D raw_co_create_opts, .bdrv_has_zero_init =3D bdrv_has_zero_init_1, + .bdrv_has_zero_init_truncate =3D bdrv_has_zero_init_1, =20 .bdrv_aio_preadv =3D raw_aio_preadv, .bdrv_aio_pwritev =3D raw_aio_pwritev, diff --git a/block/gluster.c b/block/gluster.c index f64dc5b01e..64028b2cba 100644 --- a/block/gluster.c +++ b/block/gluster.c @@ -1567,6 +1567,7 @@ static BlockDriver bdrv_gluster =3D { .bdrv_co_writev =3D qemu_gluster_co_writev, .bdrv_co_flush_to_disk =3D qemu_gluster_co_flush_to_disk, .bdrv_has_zero_init =3D qemu_gluster_has_zero_init, + .bdrv_has_zero_init_truncate =3D qemu_gluster_has_zero_init, #ifdef CONFIG_GLUSTERFS_DISCARD .bdrv_co_pdiscard =3D qemu_gluster_co_pdiscard, #endif @@ -1598,6 +1599,7 @@ static BlockDriver bdrv_gluster_tcp =3D { .bdrv_co_writev =3D qemu_gluster_co_writev, .bdrv_co_flush_to_disk =3D qemu_gluster_co_flush_to_disk, .bdrv_has_zero_init =3D qemu_gluster_has_zero_init, + .bdrv_has_zero_init_truncate =3D qemu_gluster_has_zero_init, #ifdef CONFIG_GLUSTERFS_DISCARD .bdrv_co_pdiscard =3D qemu_gluster_co_pdiscard, #endif @@ -1629,6 +1631,7 @@ static BlockDriver bdrv_gluster_unix =3D { .bdrv_co_writev =3D qemu_gluster_co_writev, .bdrv_co_flush_to_disk =3D qemu_gluster_co_flush_to_disk, .bdrv_has_zero_init =3D qemu_gluster_has_zero_init, + .bdrv_has_zero_init_truncate =3D qemu_gluster_has_zero_init, #ifdef CONFIG_GLUSTERFS_DISCARD .bdrv_co_pdiscard =3D qemu_gluster_co_pdiscard, #endif @@ -1666,6 +1669,7 @@ static BlockDriver bdrv_gluster_rdma =3D { .bdrv_co_writev =3D qemu_gluster_co_writev, .bdrv_co_flush_to_disk =3D qemu_gluster_co_flush_to_disk, .bdrv_has_zero_init =3D qemu_gluster_has_zero_init, + .bdrv_has_zero_init_truncate =3D qemu_gluster_has_zero_init, #ifdef CONFIG_GLUSTERFS_DISCARD .bdrv_co_pdiscard =3D qemu_gluster_co_pdiscard, #endif diff --git a/block/nfs.c b/block/nfs.c index d93241b3bb..97c815085f 100644 --- a/block/nfs.c +++ b/block/nfs.c @@ -863,6 +863,7 @@ static BlockDriver bdrv_nfs =3D { .create_opts =3D &nfs_create_opts, =20 .bdrv_has_zero_init =3D nfs_has_zero_init, + .bdrv_has_zero_init_truncate =3D nfs_has_zero_init, .bdrv_get_allocated_file_size =3D nfs_get_allocated_file_size, .bdrv_co_truncate =3D nfs_file_co_truncate, =20 diff --git a/block/qcow2.c b/block/qcow2.c index 039bdc2f7e..5c40f54d64 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -5187,6 +5187,7 @@ BlockDriver bdrv_qcow2 =3D { .bdrv_co_create_opts =3D qcow2_co_create_opts, .bdrv_co_create =3D qcow2_co_create, .bdrv_has_zero_init =3D bdrv_has_zero_init_1, + .bdrv_has_zero_init_truncate =3D bdrv_has_zero_init_1, .bdrv_co_block_status =3D qcow2_co_block_status, =20 .bdrv_co_preadv =3D qcow2_co_preadv, diff --git a/block/qed.c b/block/qed.c index 77c7cef175..daaedb6864 100644 --- a/block/qed.c +++ b/block/qed.c @@ -1668,6 +1668,7 @@ static BlockDriver bdrv_qed =3D { .bdrv_co_create =3D bdrv_qed_co_create, .bdrv_co_create_opts =3D bdrv_qed_co_create_opts, .bdrv_has_zero_init =3D bdrv_has_zero_init_1, + .bdrv_has_zero_init_truncate =3D bdrv_has_zero_init_1, .bdrv_co_block_status =3D bdrv_qed_co_block_status, .bdrv_co_readv =3D bdrv_qed_co_readv, .bdrv_co_writev =3D bdrv_qed_co_writev, diff --git a/block/raw-format.c b/block/raw-format.c index bffd424dd0..42c28cc29a 100644 --- a/block/raw-format.c +++ b/block/raw-format.c @@ -413,6 +413,11 @@ static int raw_has_zero_init(BlockDriverState *bs) return bdrv_has_zero_init(bs->file->bs); } =20 +static int raw_has_zero_init_truncate(BlockDriverState *bs) +{ + return bdrv_has_zero_init_truncate(bs->file->bs); +} + static int coroutine_fn raw_co_create_opts(const char *filename, QemuOpts = *opts, Error **errp) { @@ -572,6 +577,7 @@ BlockDriver bdrv_raw =3D { .bdrv_co_ioctl =3D &raw_co_ioctl, .create_opts =3D &raw_create_opts, .bdrv_has_zero_init =3D &raw_has_zero_init, + .bdrv_has_zero_init_truncate =3D &raw_has_zero_init_truncate, .strong_runtime_opts =3D raw_strong_runtime_opts, .mutable_opts =3D mutable_opts, }; diff --git a/block/rbd.c b/block/rbd.c index 59757b3120..057af43d48 100644 --- a/block/rbd.c +++ b/block/rbd.c @@ -1288,6 +1288,7 @@ static BlockDriver bdrv_rbd =3D { .bdrv_co_create =3D qemu_rbd_co_create, .bdrv_co_create_opts =3D qemu_rbd_co_create_opts, .bdrv_has_zero_init =3D bdrv_has_zero_init_1, + .bdrv_has_zero_init_truncate =3D bdrv_has_zero_init_1, .bdrv_get_info =3D qemu_rbd_getinfo, .create_opts =3D &qemu_rbd_create_opts, .bdrv_getlength =3D qemu_rbd_getlength, diff --git a/block/sheepdog.c b/block/sheepdog.c index 6f402e5d4d..a4e111f981 100644 --- a/block/sheepdog.c +++ b/block/sheepdog.c @@ -3228,6 +3228,7 @@ static BlockDriver bdrv_sheepdog =3D { .bdrv_co_create =3D sd_co_create, .bdrv_co_create_opts =3D sd_co_create_opts, .bdrv_has_zero_init =3D bdrv_has_zero_init_1, + .bdrv_has_zero_init_truncate =3D bdrv_has_zero_init_1, .bdrv_getlength =3D sd_getlength, .bdrv_get_allocated_file_size =3D sd_get_allocated_file_size, .bdrv_co_truncate =3D sd_co_truncate, diff --git a/block/ssh.c b/block/ssh.c index 501933b855..84d01e892b 100644 --- a/block/ssh.c +++ b/block/ssh.c @@ -1390,6 +1390,7 @@ static BlockDriver bdrv_ssh =3D { .bdrv_co_create_opts =3D ssh_co_create_opts, .bdrv_close =3D ssh_close, .bdrv_has_zero_init =3D ssh_has_zero_init, + .bdrv_has_zero_init_truncate =3D ssh_has_zero_init, .bdrv_co_readv =3D ssh_co_readv, .bdrv_co_writev =3D ssh_co_writev, .bdrv_getlength =3D ssh_getlength, --=20 2.21.0 From nobody Mon Feb 9 07:44:41 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1563988532; cv=none; d=zoho.com; s=zohoarc; b=h0YD/KKEk54sDgog/fPWHCFW+SH1K+10490PelmIaRsRUVAvf4Bh+of/oAan22fPoMyYYbPL4ribp245EgvL7yei0J57iwAy2V8LF8wY+XRNNbXEJI+B9fZpbSpn1IZs6zlnxYpCi1yDW1qohMjxSxo2QxKE2h0CVbiGwu6+Vrc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563988532; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=pC8WoBrdnATv1CQUvcOs90VMlVt1J+035CMaQqcze2Q=; b=HAj1CmWdxcTB73WoXUxZAE3QOwNgPTGEdY8EMi2JMJpMAglk9exF5bcsyxzOaH6qs5YloVDfZlvoflTBOvbzIcTM/H67YwofIKOAg0JOxfu4fiU+t8nx4VjQlV0HnItMCHH8tPFZI5QqjLnpUuLEU0WM+E7scNP/+zKKRY3H1y8= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1563988532319424.4067181481265; Wed, 24 Jul 2019 10:15:32 -0700 (PDT) Received: from localhost ([::1]:53676 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hqKrS-0005d2-Tu for importer@patchew.org; Wed, 24 Jul 2019 13:15:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49596) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hqKp6-0004FU-C6 for qemu-devel@nongnu.org; Wed, 24 Jul 2019 13:13:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hqKp5-0005Pf-De for qemu-devel@nongnu.org; Wed, 24 Jul 2019 13:13:04 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52878) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hqKp2-00052C-As; Wed, 24 Jul 2019 13:13:00 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8FC2630A7C69; Wed, 24 Jul 2019 17:12:58 +0000 (UTC) Received: from localhost (ovpn-204-115.brq.redhat.com [10.40.204.115]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 00CEB1001DD7; Wed, 24 Jul 2019 17:12:57 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Wed, 24 Jul 2019 19:12:33 +0200 Message-Id: <20190724171239.8764-6-mreitz@redhat.com> In-Reply-To: <20190724171239.8764-1-mreitz@redhat.com> References: <20190724171239.8764-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Wed, 24 Jul 2019 17:12:58 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 05/11] block: Use bdrv_has_zero_init_truncate() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Stefano Garzarella , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Signed-off-by: Max Reitz Reviewed-by: Maxim Levitsky Reviewed-by: Stefano Garzarella --- block/parallels.c | 2 +- block/vhdx.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/block/parallels.c b/block/parallels.c index 00fae125d1..7cd2714b69 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -835,7 +835,7 @@ static int parallels_open(BlockDriverState *bs, QDict *= options, int flags, goto fail_options; } =20 - if (!bdrv_has_zero_init(bs->file->bs)) { + if (!bdrv_has_zero_init_truncate(bs->file->bs)) { s->prealloc_mode =3D PRL_PREALLOC_MODE_FALLOCATE; } =20 diff --git a/block/vhdx.c b/block/vhdx.c index d6070b6fa8..a02d1c99a7 100644 --- a/block/vhdx.c +++ b/block/vhdx.c @@ -1282,7 +1282,7 @@ static coroutine_fn int vhdx_co_writev(BlockDriverSta= te *bs, int64_t sector_num, /* Queue another write of zero buffers if the underlying f= ile * does not zero-fill on file extension */ =20 - if (bdrv_has_zero_init(bs->file->bs) =3D=3D 0) { + if (bdrv_has_zero_init_truncate(bs->file->bs) =3D=3D 0) { use_zero_buffers =3D true; =20 /* zero fill the front, if any */ --=20 2.21.0 From nobody Mon Feb 9 07:44:41 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1563988462; cv=none; d=zoho.com; s=zohoarc; b=OkqEdRmxZemuUGDwfF62ZZsUa1X0gREa51PXQnDbyw+nM6WsdySP6K4fCBISElvfsXNlxB7kRL48G2RLpF5fylsoVRpA7yQl1Wvci07VnOF81+dLCcdG0ytqZ5rQ7HoXgJvEvNzPq4n0Cz8mmErhxlBR2/oEgLoMe6ENvMgYQzA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563988462; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=k3ZYXRAMhxNhjbgYkua+5cghGLKEESVgQKsCwyVOFcA=; b=MwNaUFOXHDkwQRI2yXpV4x0750lw2czX7uesZqAUCGNSjta9ILdwZQl/xjHE11Uy+L1cySM9M2CrW4rbiV2WnujOMBwWk30OtgnE0w6+8DB8le2tRvrRhyNvbZ1UcLIykXW22xa0jLhcANroGlMEmyU+tBeIA92n3zSzDHEFUqY= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1563988462274445.5290563608587; Wed, 24 Jul 2019 10:14:22 -0700 (PDT) Received: from localhost ([::1]:53634 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hqKqK-0000ah-Na for importer@patchew.org; Wed, 24 Jul 2019 13:14:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49635) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hqKp7-0004Mr-Sh for qemu-devel@nongnu.org; Wed, 24 Jul 2019 13:13:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hqKp6-0005Up-N9 for qemu-devel@nongnu.org; Wed, 24 Jul 2019 13:13:05 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54318) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hqKp4-0005Hm-8i; Wed, 24 Jul 2019 13:13:02 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 994F9C03D478; Wed, 24 Jul 2019 17:13:01 +0000 (UTC) Received: from localhost (ovpn-204-115.brq.redhat.com [10.40.204.115]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 13AD919C70; Wed, 24 Jul 2019 17:13:00 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Wed, 24 Jul 2019 19:12:34 +0200 Message-Id: <20190724171239.8764-7-mreitz@redhat.com> In-Reply-To: <20190724171239.8764-1-mreitz@redhat.com> References: <20190724171239.8764-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 24 Jul 2019 17:13:01 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 06/11] qcow2: Fix .bdrv_has_zero_init() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Stefano Garzarella , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" If a qcow2 file is preallocated, it can no longer guarantee that it initially appears as filled with zeroes. So implement .bdrv_has_zero_init() by checking whether the file is preallocated; if so, forward the call to the underlying storage node, except for when it is encrypted: Encrypted preallocated images always return effectively random data, so .bdrv_has_zero_init() must always return 0 for them. .bdrv_has_zero_init_truncate() can remain bdrv_has_zero_init_1(), because it presupposes PREALLOC_MODE_OFF. Reported-by: Stefano Garzarella Signed-off-by: Max Reitz Reviewed-by: Maxim Levitsky --- block/qcow2.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/block/qcow2.c b/block/qcow2.c index 5c40f54d64..b4e73aa443 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -4631,6 +4631,33 @@ static ImageInfoSpecific *qcow2_get_specific_info(Bl= ockDriverState *bs, return spec_info; } =20 +static int qcow2_has_zero_init(BlockDriverState *bs) +{ + BDRVQcow2State *s =3D bs->opaque; + bool preallocated; + + if (qemu_in_coroutine()) { + qemu_co_mutex_lock(&s->lock); + } + /* + * Check preallocation status: Preallocated images have all L2 + * tables allocated, nonpreallocated images have none. It is + * therefore enough to check the first one. + */ + preallocated =3D s->l1_size > 0 && s->l1_table[0] !=3D 0; + if (qemu_in_coroutine()) { + qemu_co_mutex_unlock(&s->lock); + } + + if (!preallocated) { + return 1; + } else if (bs->encrypted) { + return 0; + } else { + return bdrv_has_zero_init(s->data_file->bs); + } +} + static int qcow2_save_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos) { @@ -5186,7 +5213,7 @@ BlockDriver bdrv_qcow2 =3D { .bdrv_child_perm =3D bdrv_format_default_perms, .bdrv_co_create_opts =3D qcow2_co_create_opts, .bdrv_co_create =3D qcow2_co_create, - .bdrv_has_zero_init =3D bdrv_has_zero_init_1, + .bdrv_has_zero_init =3D qcow2_has_zero_init, .bdrv_has_zero_init_truncate =3D bdrv_has_zero_init_1, .bdrv_co_block_status =3D qcow2_co_block_status, =20 --=20 2.21.0 From nobody Mon Feb 9 07:44:41 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1563988578; cv=none; d=zoho.com; s=zohoarc; b=WQb+eiDfvvLYBxOve2alJEtULVbwFGZwXQPEqPLOJhiLywD4KY9t5Bb+0ktXgRr/1n38BE8F4UYT23buc+h5zT4r1BuvtLpWokh44CRnVtHzbpU0m2HiEVmmgUvYHfRsgLpwQ90A+tXroaKV7+pVxowlxaaj2+21KJeas9Iqo5Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563988578; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=i7MLovY2okbSk1DenPCWUwQ8Ee5sAHth9Oi8YlLw0HA=; b=SNvyVwo9rUuT7zGSbC+p91Lhc0gVv/VxKGYVP3Jmw3R3JYxx+oKCo1KI/64g7fUCm52ejniraXvGH+eFYB4aurdASFskhKgiCXIwEfxrDM7pD+eiUQdmIXnFHsPELdtxQlvY6hmD62WUV67PidTlMtgq92i5QDgriV/4l+N5k/c= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1563988578217216.10016300721657; Wed, 24 Jul 2019 10:16:18 -0700 (PDT) Received: from localhost ([::1]:53704 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hqKsB-0000GD-4A for importer@patchew.org; Wed, 24 Jul 2019 13:16:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49723) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hqKpC-0004iC-JE for qemu-devel@nongnu.org; Wed, 24 Jul 2019 13:13:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hqKpB-0005m4-Ho for qemu-devel@nongnu.org; Wed, 24 Jul 2019 13:13:10 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59344) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hqKp7-0005V0-91; Wed, 24 Jul 2019 13:13:05 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 913993E2D7; Wed, 24 Jul 2019 17:13:04 +0000 (UTC) Received: from localhost (ovpn-204-115.brq.redhat.com [10.40.204.115]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0D44719C70; Wed, 24 Jul 2019 17:13:03 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Wed, 24 Jul 2019 19:12:35 +0200 Message-Id: <20190724171239.8764-8-mreitz@redhat.com> In-Reply-To: <20190724171239.8764-1-mreitz@redhat.com> References: <20190724171239.8764-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 24 Jul 2019 17:13:04 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 07/11] vdi: Fix .bdrv_has_zero_init() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Stefano Garzarella , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Static VDI images cannot guarantee to be zero-initialized. If the image has been statically allocated, forward the call to the underlying storage node. Reported-by: Stefano Garzarella Signed-off-by: Max Reitz Reviewed-by: Stefan Weil Acked-by: Stefano Garzarella Tested-by: Stefano Garzarella Reviewed-by: Maxim Levitsky --- block/vdi.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/block/vdi.c b/block/vdi.c index b9845a4cbd..0caa3f281d 100644 --- a/block/vdi.c +++ b/block/vdi.c @@ -988,6 +988,17 @@ static void vdi_close(BlockDriverState *bs) error_free(s->migration_blocker); } =20 +static int vdi_has_zero_init(BlockDriverState *bs) +{ + BDRVVdiState *s =3D bs->opaque; + + if (s->header.image_type =3D=3D VDI_TYPE_STATIC) { + return bdrv_has_zero_init(bs->file->bs); + } else { + return 1; + } +} + static QemuOptsList vdi_create_opts =3D { .name =3D "vdi-create-opts", .head =3D QTAILQ_HEAD_INITIALIZER(vdi_create_opts.head), @@ -1028,7 +1039,7 @@ static BlockDriver bdrv_vdi =3D { .bdrv_child_perm =3D bdrv_format_default_perms, .bdrv_co_create =3D vdi_co_create, .bdrv_co_create_opts =3D vdi_co_create_opts, - .bdrv_has_zero_init =3D bdrv_has_zero_init_1, + .bdrv_has_zero_init =3D vdi_has_zero_init, .bdrv_co_block_status =3D vdi_co_block_status, .bdrv_make_empty =3D vdi_make_empty, =20 --=20 2.21.0 From nobody Mon Feb 9 07:44:41 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1563988512; cv=none; d=zoho.com; s=zohoarc; b=Qa/pqdHl4U7wjweKJI9qMbC7M7yurXGYw86cceLRSA+g7FqAJJIQb27BOvJeaAGpA8HQqJrcvJvC9tL4UV8Ryp+HPX6UmRhr3XTRF/gRjYITUwE5dYHMxhBTVW6HnSdF31TpCdIVGvwScSPH91oigcynqnQPpQ2H+kun7VkMjvY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563988512; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=lew6YSgeJMGA+TImySFFztZwCAzCkgrOE8rJvQW12+Y=; b=iniElZEZCuLzGs6VeysH6UMZrd6JUuhjaWZ3Ifqb52rAYwutRhGaqwCkH5jvJJDdqNl91kAlc/t0sVsTjmteQMAqpcFwSX/lh0wUbi2kasUwL+H3Pw+O7Fq7WbjMqoxPX4FW96iz4fqUloaUvcdxblkLcyTII2/ocfpGsqVoKOM= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1563988512493382.4423445662693; Wed, 24 Jul 2019 10:15:12 -0700 (PDT) Received: from localhost ([::1]:53664 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hqKr3-00042O-H1 for importer@patchew.org; Wed, 24 Jul 2019 13:15:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49763) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hqKpF-0004x1-Vq for qemu-devel@nongnu.org; Wed, 24 Jul 2019 13:13:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hqKpE-0005yQ-Pl for qemu-devel@nongnu.org; Wed, 24 Jul 2019 13:13:13 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54412) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hqKpB-0005kZ-Mm; Wed, 24 Jul 2019 13:13:09 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0BE3913A98; Wed, 24 Jul 2019 17:13:09 +0000 (UTC) Received: from localhost (ovpn-204-115.brq.redhat.com [10.40.204.115]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 17AF319C70; Wed, 24 Jul 2019 17:13:06 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Wed, 24 Jul 2019 19:12:36 +0200 Message-Id: <20190724171239.8764-9-mreitz@redhat.com> In-Reply-To: <20190724171239.8764-1-mreitz@redhat.com> References: <20190724171239.8764-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Wed, 24 Jul 2019 17:13:09 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 08/11] vhdx: Fix .bdrv_has_zero_init() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Stefano Garzarella , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Fixed VHDX images cannot guarantee to be zero-initialized. If the image has the "fixed" subformat, forward the call to the underlying storage node. Reported-by: Stefano Garzarella Signed-off-by: Max Reitz Reviewed-by: Maxim Levitsky --- block/vhdx.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/block/vhdx.c b/block/vhdx.c index a02d1c99a7..6a09d0a55c 100644 --- a/block/vhdx.c +++ b/block/vhdx.c @@ -2075,6 +2075,30 @@ static int coroutine_fn vhdx_co_check(BlockDriverSta= te *bs, return 0; } =20 +static int vhdx_has_zero_init(BlockDriverState *bs) +{ + BDRVVHDXState *s =3D bs->opaque; + int state; + + /* + * Check the subformat: Fixed images have all BAT entries present, + * dynamic images have none (right after creation). It is + * therefore enough to check the first BAT entry. + */ + if (!s->bat_entries) { + return 1; + } + + state =3D s->bat[0] & VHDX_BAT_STATE_BIT_MASK; + if (state =3D=3D PAYLOAD_BLOCK_FULLY_PRESENT) { + /* Fixed subformat */ + return bdrv_has_zero_init(bs->file->bs); + } + + /* Dynamic subformat */ + return 1; +} + static QemuOptsList vhdx_create_opts =3D { .name =3D "vhdx-create-opts", .head =3D QTAILQ_HEAD_INITIALIZER(vhdx_create_opts.head), @@ -2128,7 +2152,7 @@ static BlockDriver bdrv_vhdx =3D { .bdrv_co_create_opts =3D vhdx_co_create_opts, .bdrv_get_info =3D vhdx_get_info, .bdrv_co_check =3D vhdx_co_check, - .bdrv_has_zero_init =3D bdrv_has_zero_init_1, + .bdrv_has_zero_init =3D vhdx_has_zero_init, =20 .create_opts =3D &vhdx_create_opts, }; --=20 2.21.0 From nobody Mon Feb 9 07:44:41 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1563988470; cv=none; d=zoho.com; s=zohoarc; b=IiBa6lxumqcoQErKlhG+OarC8bQxca3RBvW0Ho3ljctreW89j10H+SCWv8jCOcXwZVybv4Kqyr4+TGfmGObMkRUgEysxbuDFCWEB67rAnjz8wsSDFg5U6YJrsuFoTbKjRZUB+rC1EH0eR6q1ccj4HwAcPLV0F689oAMSdTYij8g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563988470; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=fjjdMySbwBd8pdj4lcLGbMReoxOUvGugKti1QcA5+U4=; b=hc0AQnzSuurB4HKhbF9zLk33QPXnS2+xJ2tKDedLTOzobrRQ0QS7q9WBksLXoC02+IBCzSQATn1+fZQltnp0+DcCIFlm+9TyabrFzhLSDaS0Reg13ttBjLbN2rDdo2T6wHby2U7uCiEI+hW+Fbb7NMp0Osz1DE0qM/SDfeHsmKw= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1563988470708798.692829712695; Wed, 24 Jul 2019 10:14:30 -0700 (PDT) Received: from localhost ([::1]:53638 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hqKqT-0001Kb-2d for importer@patchew.org; Wed, 24 Jul 2019 13:14:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49815) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hqKpJ-0005EE-Py for qemu-devel@nongnu.org; Wed, 24 Jul 2019 13:13:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hqKpI-0006AS-Gw for qemu-devel@nongnu.org; Wed, 24 Jul 2019 13:13:17 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41850) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hqKpG-0005xZ-3M; Wed, 24 Jul 2019 13:13:14 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5E5D930B1AD1; Wed, 24 Jul 2019 17:13:12 +0000 (UTC) Received: from localhost (ovpn-204-115.brq.redhat.com [10.40.204.115]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CA62760BEC; Wed, 24 Jul 2019 17:13:11 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Wed, 24 Jul 2019 19:12:37 +0200 Message-Id: <20190724171239.8764-10-mreitz@redhat.com> In-Reply-To: <20190724171239.8764-1-mreitz@redhat.com> References: <20190724171239.8764-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Wed, 24 Jul 2019 17:13:12 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 09/11] iotests: Convert to preallocated encrypted qcow2 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Stefano Garzarella , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Add a test case for converting an empty image (which only returns zeroes when read) to a preallocated encrypted qcow2 image. qcow2_has_zero_init() should return 0 then, thus forcing qemu-img convert to create zero clusters. Signed-off-by: Max Reitz Acked-by: Stefano Garzarella Tested-by: Stefano Garzarella Reviewed-by: Maxim Levitsky --- tests/qemu-iotests/188 | 20 +++++++++++++++++++- tests/qemu-iotests/188.out | 4 ++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/tests/qemu-iotests/188 b/tests/qemu-iotests/188 index be7278aa65..afca44df54 100755 --- a/tests/qemu-iotests/188 +++ b/tests/qemu-iotests/188 @@ -48,7 +48,7 @@ SECRETALT=3D"secret,id=3Dsec0,data=3Dplatypus" =20 _make_test_img --object $SECRET -o "encrypt.format=3Dluks,encrypt.key-secr= et=3Dsec0,encrypt.iter-time=3D10" $size =20 -IMGSPEC=3D"driver=3D$IMGFMT,file.filename=3D$TEST_IMG,encrypt.key-secret= =3Dsec0" +IMGSPEC=3D"driver=3D$IMGFMT,encrypt.key-secret=3Dsec0,file.filename=3D$TES= T_IMG" =20 QEMU_IO_OPTIONS=3D$QEMU_IO_OPTIONS_NO_FMT =20 @@ -68,6 +68,24 @@ echo echo "=3D=3D verify open failure with wrong password =3D=3D" $QEMU_IO --object $SECRETALT -c "read -P 0xa 0 $size" --image-opts $IMGSPE= C | _filter_qemu_io | _filter_testdir =20 +_cleanup_test_img + +echo +echo "=3D=3D verify that has_zero_init returns false when preallocating = =3D=3D" + +# Empty source file +if [ -n "$TEST_IMG_FILE" ]; then + TEST_IMG_FILE=3D"${TEST_IMG_FILE}.orig" _make_test_img $size +else + TEST_IMG=3D"${TEST_IMG}.orig" _make_test_img $size +fi + +$QEMU_IMG convert -O "$IMGFMT" --object $SECRET \ + -o "encrypt.format=3Dluks,encrypt.key-secret=3Dsec0,encrypt.iter-time= =3D10,preallocation=3Dmetadata" \ + "${TEST_IMG}.orig" "$TEST_IMG" + +$QEMU_IMG compare --object $SECRET --image-opts "${IMGSPEC}.orig" "$IMGSPE= C" + =20 # success, all done echo "*** done" diff --git a/tests/qemu-iotests/188.out b/tests/qemu-iotests/188.out index 97b1402671..c568ef3701 100644 --- a/tests/qemu-iotests/188.out +++ b/tests/qemu-iotests/188.out @@ -15,4 +15,8 @@ read 16777216/16777216 bytes at offset 0 =20 =3D=3D verify open failure with wrong password =3D=3D qemu-io: can't open: Invalid password, cannot unlock any keyslot + +=3D=3D verify that has_zero_init returns false when preallocating =3D=3D +Formatting 'TEST_DIR/t.IMGFMT.orig', fmt=3DIMGFMT size=3D16777216 +Images are identical. *** done --=20 2.21.0 From nobody Mon Feb 9 07:44:41 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1563988517; cv=none; d=zoho.com; s=zohoarc; b=accGASlqguDo0OIpw9gwRNnXGb/D8R+h1KyW+MXzxmVK2Zgj3cVb+xRjjY8SOBczMjQOdCsvv/XEKvGfgDk9fkJX/rWOlF74vsDVR+rZ8cx35NhS4HJs0iqxdZ9F8cDBtfX29ErK2OknAYrMbvcl7/98CV5F+9bU6jgUyusLSnw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563988517; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=89gjXn377XJmAVvC2htf3ypFr2WAsTVrcBP0/LGTGuk=; b=IXmjQpD4AFW/8QmtV5OaWeAJDoGc6B/heKE8+4KB3W9I0Akot4SXmoXaQ1/EPEbCzlGHXj+RZLFXmGjztLYIeRqW3VPhOC5fNpgmJsbdH9b7C8vfevG7MrthgFIODQUg3DMa9H6OgA5ZuQpl3z0TAmoyMVgrL+6SSpF3qeuezEU= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1563988517253366.1802033973645; Wed, 24 Jul 2019 10:15:17 -0700 (PDT) Received: from localhost ([::1]:53672 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hqKrD-0004hq-LE for importer@patchew.org; Wed, 24 Jul 2019 13:15:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49831) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hqKpM-0005Q6-DP for qemu-devel@nongnu.org; Wed, 24 Jul 2019 13:13:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hqKpK-0006FK-A2 for qemu-devel@nongnu.org; Wed, 24 Jul 2019 13:13:19 -0400 Received: from mx1.redhat.com ([209.132.183.28]:27234) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hqKpH-00067D-TH; Wed, 24 Jul 2019 13:13:16 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3869781F10; Wed, 24 Jul 2019 17:13:15 +0000 (UTC) Received: from localhost (ovpn-204-115.brq.redhat.com [10.40.204.115]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B4B1A60A35; Wed, 24 Jul 2019 17:13:14 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Wed, 24 Jul 2019 19:12:38 +0200 Message-Id: <20190724171239.8764-11-mreitz@redhat.com> In-Reply-To: <20190724171239.8764-1-mreitz@redhat.com> References: <20190724171239.8764-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Wed, 24 Jul 2019 17:13:15 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 10/11] iotests: Test convert -n to pre-filled image X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Stefano Garzarella , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Signed-off-by: Max Reitz Reviewed-by: Maxim Levitsky --- tests/qemu-iotests/122 | 17 +++++++++++++++++ tests/qemu-iotests/122.out | 8 ++++++++ 2 files changed, 25 insertions(+) diff --git a/tests/qemu-iotests/122 b/tests/qemu-iotests/122 index 85c3a8d047..059011ebb1 100755 --- a/tests/qemu-iotests/122 +++ b/tests/qemu-iotests/122 @@ -257,6 +257,23 @@ for min_sparse in 4k 8k; do $QEMU_IMG map --output=3Djson "$TEST_IMG".orig | _filter_qemu_img_map done =20 + +echo +echo '=3D=3D=3D -n to a non-zero image =3D=3D=3D' +echo + +# Keep source zero +_make_test_img 64M + +# Output is not zero, but has bdrv_has_zero_init() =3D=3D 1 +TEST_IMG=3D"$TEST_IMG".orig _make_test_img 64M +$QEMU_IO -c "write -P 42 0 64k" "$TEST_IMG".orig | _filter_qemu_io + +# Convert with -n, which should not assume that the target is zeroed +$QEMU_IMG convert -O $IMGFMT -n "$TEST_IMG" "$TEST_IMG".orig + +$QEMU_IMG compare "$TEST_IMG" "$TEST_IMG".orig + # success, all done echo '*** done' rm -f $seq.full diff --git a/tests/qemu-iotests/122.out b/tests/qemu-iotests/122.out index c576705284..849b6cc2ef 100644 --- a/tests/qemu-iotests/122.out +++ b/tests/qemu-iotests/122.out @@ -220,4 +220,12 @@ convert -c -S 8k { "start": 9216, "length": 8192, "depth": 0, "zero": true, "data": false}, { "start": 17408, "length": 1024, "depth": 0, "zero": false, "data": true}, { "start": 18432, "length": 67090432, "depth": 0, "zero": true, "data": fa= lse}] + +=3D=3D=3D -n to a non-zero image =3D=3D=3D + +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D67108864 +Formatting 'TEST_DIR/t.IMGFMT.orig', fmt=3DIMGFMT size=3D67108864 +wrote 65536/65536 bytes at offset 0 +64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +Images are identical. *** done --=20 2.21.0 From nobody Mon Feb 9 07:44:41 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1563988560; cv=none; d=zoho.com; s=zohoarc; b=jvotqRGwb/iTPnvSJ1V+33tvaM+oMh9s8D8rrwBtkTRaYSfT55ST+IGN0ZEtsBZLGj8KC9CfreSHPlrLx1YZY7cvoLkPeVMe3fIkKAxLtc4ueZhrXzwLOMspvBHD6LQr7Ok99jDz+NriH3syNSsB+L0HSry/oXj8Po+dBAOpwpI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563988560; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=/n9CICWPmx/YpTwtCAj2JSESXFrBHVr+QKZpmCZcYGQ=; b=bSWc9lokv3y4YUqrYc8KtnUd5MN+1PlI2sfXRAgTaoaWtoWa2TT2ene3lR2Lb06Jl6pYMY90Emu+qybA5D8BAnKvgdnha5AZra3sN6tdCJnSj5WyFDQRt6l29cMSktyiCV3eBzlvoomz01zRzcb19D7/B83H7jqX3B2tSVFChgM= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1563988560680356.41485672967394; Wed, 24 Jul 2019 10:16:00 -0700 (PDT) Received: from localhost ([::1]:53694 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hqKrv-0007QA-4w for importer@patchew.org; Wed, 24 Jul 2019 13:15:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49904) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hqKpV-00060m-IG for qemu-devel@nongnu.org; Wed, 24 Jul 2019 13:13:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hqKpT-0006iP-8P for qemu-devel@nongnu.org; Wed, 24 Jul 2019 13:13:28 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38072) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hqKpM-0006Fr-Du; Wed, 24 Jul 2019 13:13:20 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4DD0F58569; Wed, 24 Jul 2019 17:13:18 +0000 (UTC) Received: from localhost (ovpn-204-115.brq.redhat.com [10.40.204.115]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BD4161001DDE; Wed, 24 Jul 2019 17:13:17 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Wed, 24 Jul 2019 19:12:39 +0200 Message-Id: <20190724171239.8764-12-mreitz@redhat.com> In-Reply-To: <20190724171239.8764-1-mreitz@redhat.com> References: <20190724171239.8764-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Wed, 24 Jul 2019 17:13:18 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 11/11] iotests: Full mirror to existing non-zero image X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Stefano Garzarella , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" The result of a sync=3Dfull mirror should always be the equal to the input. Therefore, existing images should be treated as potentially non-zero and thus should be explicitly initialized to be zero beforehand. Signed-off-by: Max Reitz --- tests/qemu-iotests/041 | 62 +++++++++++++++++++++++++++++++++++--- tests/qemu-iotests/041.out | 4 +-- 2 files changed, 60 insertions(+), 6 deletions(-) diff --git a/tests/qemu-iotests/041 b/tests/qemu-iotests/041 index 26bf1701eb..8bc8f81db7 100755 --- a/tests/qemu-iotests/041 +++ b/tests/qemu-iotests/041 @@ -741,8 +741,15 @@ class TestUnbackedSource(iotests.QMPTestCase): def setUp(self): qemu_img('create', '-f', iotests.imgfmt, test_img, str(TestUnbackedSource.image_len)) - self.vm =3D iotests.VM().add_drive(test_img) + self.vm =3D iotests.VM() self.vm.launch() + result =3D self.vm.qmp('blockdev-add', node_name=3D'drive0', + driver=3Diotests.imgfmt, + file=3D{ + 'driver': 'file', + 'filename': test_img, + }) + self.assert_qmp(result, 'return', {}) =20 def tearDown(self): self.vm.shutdown() @@ -751,7 +758,7 @@ class TestUnbackedSource(iotests.QMPTestCase): =20 def test_absolute_paths_full(self): self.assert_no_active_block_jobs() - result =3D self.vm.qmp('drive-mirror', device=3D'drive0', + result =3D self.vm.qmp('drive-mirror', job_id=3D'drive0', device= =3D'drive0', sync=3D'full', target=3Dtarget_img, mode=3D'absolute-paths') self.assert_qmp(result, 'return', {}) @@ -760,7 +767,7 @@ class TestUnbackedSource(iotests.QMPTestCase): =20 def test_absolute_paths_top(self): self.assert_no_active_block_jobs() - result =3D self.vm.qmp('drive-mirror', device=3D'drive0', + result =3D self.vm.qmp('drive-mirror', job_id=3D'drive0', device= =3D'drive0', sync=3D'top', target=3Dtarget_img, mode=3D'absolute-paths') self.assert_qmp(result, 'return', {}) @@ -769,13 +776,60 @@ class TestUnbackedSource(iotests.QMPTestCase): =20 def test_absolute_paths_none(self): self.assert_no_active_block_jobs() - result =3D self.vm.qmp('drive-mirror', device=3D'drive0', + result =3D self.vm.qmp('drive-mirror', job_id=3D'drive0', device= =3D'drive0', sync=3D'none', target=3Dtarget_img, mode=3D'absolute-paths') self.assert_qmp(result, 'return', {}) self.complete_and_wait() self.assert_no_active_block_jobs() =20 + def test_existing_full(self): + qemu_img('create', '-f', iotests.imgfmt, target_img, + str(self.image_len)) + qemu_io('-c', 'write -P 42 0 64k', target_img) + + self.assert_no_active_block_jobs() + result =3D self.vm.qmp('drive-mirror', job_id=3D'drive0', device= =3D'drive0', + sync=3D'full', target=3Dtarget_img, mode=3D'e= xisting') + self.assert_qmp(result, 'return', {}) + self.complete_and_wait() + self.assert_no_active_block_jobs() + + result =3D self.vm.qmp('blockdev-del', node_name=3D'drive0') + self.assert_qmp(result, 'return', {}) + + self.assertTrue(iotests.compare_images(test_img, target_img), + 'target image does not match source after mirrorin= g') + + def test_blockdev_full(self): + qemu_img('create', '-f', iotests.imgfmt, target_img, + str(self.image_len)) + qemu_io('-c', 'write -P 42 0 64k', target_img) + + result =3D self.vm.qmp('blockdev-add', node_name=3D'target', + driver=3Diotests.imgfmt, + file=3D{ + 'driver': 'file', + 'filename': target_img, + }) + self.assert_qmp(result, 'return', {}) + + self.assert_no_active_block_jobs() + result =3D self.vm.qmp('blockdev-mirror', job_id=3D'drive0', devic= e=3D'drive0', + sync=3D'full', target=3D'target') + self.assert_qmp(result, 'return', {}) + self.complete_and_wait() + self.assert_no_active_block_jobs() + + result =3D self.vm.qmp('blockdev-del', node_name=3D'drive0') + self.assert_qmp(result, 'return', {}) + + result =3D self.vm.qmp('blockdev-del', node_name=3D'target') + self.assert_qmp(result, 'return', {}) + + self.assertTrue(iotests.compare_images(test_img, target_img), + 'target image does not match source after mirrorin= g') + class TestGranularity(iotests.QMPTestCase): image_len =3D 10 * 1024 * 1024 # MB =20 diff --git a/tests/qemu-iotests/041.out b/tests/qemu-iotests/041.out index e071d0b261..2c448b4239 100644 --- a/tests/qemu-iotests/041.out +++ b/tests/qemu-iotests/041.out @@ -1,5 +1,5 @@ -..........................................................................= .............. +..........................................................................= ................ ---------------------------------------------------------------------- -Ran 88 tests +Ran 90 tests =20 OK --=20 2.21.0