From nobody Fri Oct 24 22:16:59 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 1519842440960922.8212644476761; Wed, 28 Feb 2018 10:27:20 -0800 (PST) Received: from localhost ([::1]:46095 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1er6Rb-00075N-VL for importer@patchew.org; Wed, 28 Feb 2018 13:27:12 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41927) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1er67L-0004oo-Sr for qemu-devel@nongnu.org; Wed, 28 Feb 2018 13:06:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1er67K-0004i8-Ix for qemu-devel@nongnu.org; Wed, 28 Feb 2018 13:06:15 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:47154 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 1er67H-0004fB-IV; Wed, 28 Feb 2018 13:06:11 -0500 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 25C5F818AAF5; Wed, 28 Feb 2018 18:06:11 +0000 (UTC) Received: from localhost (unknown [10.40.205.159]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 92EC52024CA6; Wed, 28 Feb 2018 18:06:10 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Wed, 28 Feb 2018 19:05:06 +0100 Message-Id: <20180228180507.3964-16-mreitz@redhat.com> In-Reply-To: <20180228180507.3964-1-mreitz@redhat.com> References: <20180228180507.3964-1-mreitz@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]); Wed, 28 Feb 2018 18:06:11 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Wed, 28 Feb 2018 18:06:11 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'mreitz@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] [PATCH v3 15/16] block/mirror: Add copy mode QAPI interface 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: Kevin Wolf , Fam Zheng , qemu-devel@nongnu.org, Max Reitz , Stefan Hajnoczi , John Snow 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" This patch allows the user to specify whether to use active or only background mode for mirror block jobs. Currently, this setting will remain constant for the duration of the entire block job. Signed-off-by: Max Reitz --- qapi/block-core.json | 11 +++++++++-- include/block/block_int.h | 4 +++- block/mirror.c | 12 +++++++----- blockdev.c | 9 ++++++++- 4 files changed, 27 insertions(+), 9 deletions(-) diff --git a/qapi/block-core.json b/qapi/block-core.json index c73b769c27..1186c007ae 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -1573,6 +1573,9 @@ # written. Both will result in identical contents. # Default is true. (Since 2.4) # +# @copy-mode: when to copy data to the destination; defaults to 'backgroun= d' +# (Since: 2.12) +# # Since: 1.3 ## { 'struct': 'DriveMirror', @@ -1582,7 +1585,7 @@ '*speed': 'int', '*granularity': 'uint32', '*buf-size': 'int', '*on-source-error': 'BlockdevOnError', '*on-target-error': 'BlockdevOnError', - '*unmap': 'bool' } } + '*unmap': 'bool', '*copy-mode': 'MirrorCopyMode' } } =20 ## # @BlockDirtyBitmap: @@ -1761,6 +1764,9 @@ # above @device. If this option is not given, a node na= me is # autogenerated. (Since: 2.9) # +# @copy-mode: when to copy data to the destination; defaults to 'backgroun= d' +# (Since: 2.12) +# # Returns: nothing on success. # # Since: 2.6 @@ -1781,7 +1787,8 @@ '*speed': 'int', '*granularity': 'uint32', '*buf-size': 'int', '*on-source-error': 'BlockdevOnError', '*on-target-error': 'BlockdevOnError', - '*filter-node-name': 'str' } } + '*filter-node-name': 'str', + '*copy-mode': 'MirrorCopyMode' } } =20 ## # @block_set_io_throttle: diff --git a/include/block/block_int.h b/include/block/block_int.h index 7767fc28d3..f6e0937c47 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -962,6 +962,7 @@ void commit_active_start(const char *job_id, BlockDrive= rState *bs, * @filter_node_name: The node name that should be assigned to the filter * driver that the mirror job inserts into the graph above @bs. NULL means= that * a node name should be autogenerated. + * @copy_mode: When to trigger writes to the target. * @errp: Error object. * * Start a mirroring operation on @bs. Clusters that are allocated @@ -975,7 +976,8 @@ void mirror_start(const char *job_id, BlockDriverState = *bs, MirrorSyncMode mode, BlockMirrorBackingMode backing_mode, BlockdevOnError on_source_error, BlockdevOnError on_target_error, - bool unmap, const char *filter_node_name, Error **errp); + bool unmap, const char *filter_node_name, + MirrorCopyMode copy_mode, Error **errp); =20 /* * backup_job_create: diff --git a/block/mirror.c b/block/mirror.c index 77badbeb29..e12c46df9d 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -1470,7 +1470,7 @@ static void mirror_start_job(const char *job_id, Bloc= kDriverState *bs, const BlockJobDriver *driver, bool is_none_mode, BlockDriverState *base, bool auto_complete, const char *filter_node_n= ame, - bool is_mirror, + bool is_mirror, MirrorCopyMode copy_mode, Error **errp) { MirrorBlockJob *s; @@ -1576,7 +1576,7 @@ static void mirror_start_job(const char *job_id, Bloc= kDriverState *bs, s->on_target_error =3D on_target_error; s->is_none_mode =3D is_none_mode; s->backing_mode =3D backing_mode; - s->copy_mode =3D MIRROR_COPY_MODE_BACKGROUND; + s->copy_mode =3D copy_mode; s->base =3D base; s->granularity =3D granularity; s->buf_size =3D ROUND_UP(buf_size, granularity); @@ -1643,7 +1643,8 @@ void mirror_start(const char *job_id, BlockDriverStat= e *bs, MirrorSyncMode mode, BlockMirrorBackingMode backing_mode, BlockdevOnError on_source_error, BlockdevOnError on_target_error, - bool unmap, const char *filter_node_name, Error **errp) + bool unmap, const char *filter_node_name, + MirrorCopyMode copy_mode, Error **errp) { bool is_none_mode; BlockDriverState *base; @@ -1658,7 +1659,7 @@ void mirror_start(const char *job_id, BlockDriverStat= e *bs, speed, granularity, buf_size, backing_mode, on_source_error, on_target_error, unmap, NULL, NULL, &mirror_job_driver, is_none_mode, base, false, - filter_node_name, true, errp); + filter_node_name, true, copy_mode, errp); } =20 void commit_active_start(const char *job_id, BlockDriverState *bs, @@ -1681,7 +1682,8 @@ void commit_active_start(const char *job_id, BlockDri= verState *bs, MIRROR_LEAVE_BACKING_CHAIN, on_error, on_error, true, cb, opaque, &commit_active_job_driver, false, base, auto_complete, - filter_node_name, false, &local_err); + filter_node_name, false, MIRROR_COPY_MODE_BACKGROUND, + &local_err); if (local_err) { error_propagate(errp, local_err); goto error_restore_flags; diff --git a/blockdev.c b/blockdev.c index 3fb1ca803c..cf97aeddf7 100644 --- a/blockdev.c +++ b/blockdev.c @@ -3489,6 +3489,7 @@ static void blockdev_mirror_common(const char *job_id= , BlockDriverState *bs, bool has_unmap, bool unmap, bool has_filter_node_name, const char *filter_node_name, + bool has_copy_mode, MirrorCopyMode copy= _mode, Error **errp) { =20 @@ -3513,6 +3514,9 @@ static void blockdev_mirror_common(const char *job_id= , BlockDriverState *bs, if (!has_filter_node_name) { filter_node_name =3D NULL; } + if (!has_copy_mode) { + copy_mode =3D MIRROR_COPY_MODE_BACKGROUND; + } =20 if (granularity !=3D 0 && (granularity < 512 || granularity > 1048576 = * 64)) { error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "granularity", @@ -3543,7 +3547,7 @@ static void blockdev_mirror_common(const char *job_id= , BlockDriverState *bs, has_replaces ? replaces : NULL, speed, granularity, buf_size, sync, backing_mode, on_source_error, on_target_error, unmap, filter_node_name, - errp); + copy_mode, errp); } =20 void qmp_drive_mirror(DriveMirror *arg, Error **errp) @@ -3689,6 +3693,7 @@ void qmp_drive_mirror(DriveMirror *arg, Error **errp) arg->has_on_target_error, arg->on_target_error, arg->has_unmap, arg->unmap, false, NULL, + arg->has_copy_mode, arg->copy_mode, &local_err); bdrv_unref(target_bs); error_propagate(errp, local_err); @@ -3709,6 +3714,7 @@ void qmp_blockdev_mirror(bool has_job_id, const char = *job_id, BlockdevOnError on_target_error, bool has_filter_node_name, const char *filter_node_name, + bool has_copy_mode, MirrorCopyMode copy_mode, Error **errp) { BlockDriverState *bs; @@ -3741,6 +3747,7 @@ void qmp_blockdev_mirror(bool has_job_id, const char = *job_id, has_on_target_error, on_target_error, true, true, has_filter_node_name, filter_node_name, + has_copy_mode, copy_mode, &local_err); error_propagate(errp, local_err); =20 --=20 2.14.3