From nobody Tue Feb 10 00:23:53 2026 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=virtuozzo.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1543568287091873.8008052319728; Fri, 30 Nov 2018 00:58:07 -0800 (PST) Received: from localhost ([::1]:58792 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gSecR-0002rd-Fx for importer@patchew.org; Fri, 30 Nov 2018 03:57:51 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55147) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gSeaI-0001d2-5G for qemu-devel@nongnu.org; Fri, 30 Nov 2018 03:55:40 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gSeaE-0000TJ-Iw for qemu-devel@nongnu.org; Fri, 30 Nov 2018 03:55:37 -0500 Received: from relay.sw.ru ([185.231.240.75]:41894) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gSeaE-0000RZ-5P; Fri, 30 Nov 2018 03:55:34 -0500 Received: from [172.16.25.136] (helo=localhost.sw.ru) by relay.sw.ru with esmtp (Exim 4.91) (envelope-from ) id 1gSea7-0004HZ-Cq; Fri, 30 Nov 2018 11:55:27 +0300 From: Andrey Shinkevich To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Fri, 30 Nov 2018 11:55:23 +0300 Message-Id: <1543568126-727235-3-git-send-email-andrey.shinkevich@virtuozzo.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1543568126-727235-1-git-send-email-andrey.shinkevich@virtuozzo.com> References: <1543568126-727235-1-git-send-email-andrey.shinkevich@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 185.231.240.75 Subject: [Qemu-devel] [PATCH v4 2/5] The discard flag for block stream operation 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, vsementsov@virtuozzo.com, armbru@redhat.com, mreitz@redhat.com, andrey.shinkevich@virtuozzo.com, den@openvz.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Adding a parameter to QMP block-stream command to allow discarding blocks in the backing chain while blocks are being copied to the active layer. Signed-off-by: Andrey Shinkevich --- block/stream.c | 3 +-- blockdev.c | 8 +++++++- hmp-commands.hx | 4 ++-- hmp.c | 4 +++- include/block/block_int.h | 2 +- qapi/block-core.json | 5 ++++- 6 files changed, 18 insertions(+), 8 deletions(-) diff --git a/block/stream.c b/block/stream.c index 9e85954..e844e94 100644 --- a/block/stream.c +++ b/block/stream.c @@ -584,10 +584,9 @@ static const BlockJobDriver stream_job_driver =3D { =20 void stream_start(const char *job_id, BlockDriverState *bs, BlockDriverState *base, const char *backing_file_str, - int creation_flags, int64_t speed, + int creation_flags, int64_t speed, bool discard, BlockdevOnError on_error, Error **errp) { - const bool discard =3D false; StreamBlockJob *s =3D NULL; BlockDriverState *iter; int orig_bs_flags; diff --git a/blockdev.c b/blockdev.c index 81f95d9..333592e 100644 --- a/blockdev.c +++ b/blockdev.c @@ -3141,6 +3141,7 @@ void qmp_block_stream(bool has_job_id, const char *jo= b_id, const char *device, bool has_base_node, const char *base_node, bool has_backing_file, const char *backing_file, bool has_speed, int64_t speed, + bool has_discard, bool discard, bool has_on_error, BlockdevOnError on_error, bool has_auto_finalize, bool auto_finalize, bool has_auto_dismiss, bool auto_dismiss, @@ -3157,6 +3158,10 @@ void qmp_block_stream(bool has_job_id, const char *j= ob_id, const char *device, on_error =3D BLOCKDEV_ON_ERROR_REPORT; } =20 + if (!has_discard) { + discard =3D false; + } + bs =3D bdrv_lookup_bs(device, device, errp); if (!bs) { return; @@ -3221,7 +3226,8 @@ void qmp_block_stream(bool has_job_id, const char *jo= b_id, const char *device, } =20 stream_start(has_job_id ? job_id : NULL, bs, base_bs, base_name, - job_flags, has_speed ? speed : 0, on_error, &local_err); + job_flags, has_speed ? speed : 0, + discard, on_error, &local_err); if (local_err) { error_propagate(errp, local_err); goto out; diff --git a/hmp-commands.hx b/hmp-commands.hx index db0c681..a7e2a10 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -95,8 +95,8 @@ ETEXI =20 { .name =3D "block_stream", - .args_type =3D "device:B,speed:o?,base:s?", - .params =3D "device [speed [base]]", + .args_type =3D "device:B,speed:o?,base:s?,discard:-d", + .params =3D "device [speed [base]] [-d]", .help =3D "copy data from a backing file into a block device= ", .cmd =3D hmp_block_stream, }, diff --git a/hmp.c b/hmp.c index 7828f93..0d263e4 100644 --- a/hmp.c +++ b/hmp.c @@ -1920,9 +1920,11 @@ void hmp_block_stream(Monitor *mon, const QDict *qdi= ct) const char *device =3D qdict_get_str(qdict, "device"); const char *base =3D qdict_get_try_str(qdict, "base"); int64_t speed =3D qdict_get_try_int(qdict, "speed", 0); + bool discard =3D qdict_get_try_bool(qdict, "discard", false); =20 qmp_block_stream(true, device, device, base !=3D NULL, base, false, NU= LL, - false, NULL, qdict_haskey(qdict, "speed"), speed, tru= e, + false, NULL, qdict_haskey(qdict, "speed"), speed, + true, discard, true, BLOCKDEV_ON_ERROR_REPORT, false, false, false, false, &error); =20 diff --git a/include/block/block_int.h b/include/block/block_int.h index f605622..2660336 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -970,7 +970,7 @@ int is_windows_drive(const char *filename); */ void stream_start(const char *job_id, BlockDriverState *bs, BlockDriverState *base, const char *backing_file_str, - int creation_flags, int64_t speed, + int creation_flags, int64_t speed, bool discard, BlockdevOnError on_error, Error **errp); =20 /** diff --git a/qapi/block-core.json b/qapi/block-core.json index d4fe710..f4538fa 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -2334,6 +2334,9 @@ # # @speed: the maximum speed, in bytes per second # +# @discard: true to delete blocks duplicated in old backing files. +# (default: false). Since 4.0. +# # @on-error: the action to take on an error (default report). # 'stop' and 'enospc' can only be used if the block device # supports io-status (see BlockInfo). Since 1.3. @@ -2366,7 +2369,7 @@ { 'command': 'block-stream', 'data': { '*job-id': 'str', 'device': 'str', '*base': 'str', '*base-node': 'str', '*backing-file': 'str', '*speed': 'int', - '*on-error': 'BlockdevOnError', + '*discard': 'bool', '*on-error': 'BlockdevOnError', '*auto-finalize': 'bool', '*auto-dismiss': 'bool' } } =20 ## --=20 1.8.3.1