From nobody Tue Nov 11 19:02:12 2025 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=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1565364872; cv=none; d=zoho.com; s=zohoarc; b=IY1wQ0X2cfQTyYo8uOT4t9pJr08bJF6ojrfRUQkV8OcTHgzsWDWLwpLo7fBrQQ40acquITM0HWQO7wgfkvR9dEdIIhse81yLrKVZtpIF+beeK1yEw1icz6jr5i9vyv73b8hA26QB2saZi72iBDNHvKjTaTZglzPH4paw4EGGziI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565364872; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=fQ+1h/7MeQt4hH/J3dDO5eXC4uSqVFaXxERylLizMMM=; b=MNsd3MILD/yXWeXY2WqClUAwP/jYLOofbSd4+WFfJ+D6WMc9ABDUUgBION7FxU7xWeltBFdv+XLzLmlmcCUUimnAl0aTNUHijdJZyHBXT3QWrPkdjVbk1Qpg1WWUDjmVIOWHgwXqMMrwsW89EFRD/5XN6Zapz19sEUhm/jqRJA0= 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 1565364872862205.43277413415262; Fri, 9 Aug 2019 08:34:32 -0700 (PDT) Received: from localhost ([::1]:60154 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hw6uV-0006fk-UD for importer@patchew.org; Fri, 09 Aug 2019 11:34:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49087) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hw6sN-00041j-IJ for qemu-devel@nongnu.org; Fri, 09 Aug 2019 11:32:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hw6sK-0002p3-Rv for qemu-devel@nongnu.org; Fri, 09 Aug 2019 11:32:19 -0400 Received: from relay.sw.ru ([185.231.240.75]:57586) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hw6sI-0002ij-1i; Fri, 09 Aug 2019 11:32:14 -0400 Received: from [10.94.3.0] (helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.92) (envelope-from ) id 1hw6sC-0004Cp-7N; Fri, 09 Aug 2019 18:32:08 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Date: Fri, 9 Aug 2019 18:32:01 +0300 Message-Id: <20190809153207.49288-2-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20190809153207.49288-1-vsementsov@virtuozzo.com> References: <20190809153207.49288-1-vsementsov@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 185.231.240.75 Subject: [Qemu-devel] [PATCH v2 1/7] block/backup: deal with zero detection 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: fam@euphon.net, kwolf@redhat.com, vsementsov@virtuozzo.com, armbru@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com, stefanha@redhat.com, den@openvz.org, jsnow@redhat.com 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" We have detect_zeroes option, so at least for blockdev-backup user should define it if zero-detection is needed. For drive-backup leave detection enabled by default but do it through existing option instead of open-coding. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Max Reitz --- block/backup.c | 15 ++++++--------- blockdev.c | 8 ++++---- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/block/backup.c b/block/backup.c index adc4d44244..d815436455 100644 --- a/block/backup.c +++ b/block/backup.c @@ -113,7 +113,10 @@ static int coroutine_fn backup_cow_with_bounce_buffer(= BackupBlockJob *job, BlockBackend *blk =3D job->common.blk; int nbytes; int read_flags =3D is_write_notifier ? BDRV_REQ_NO_SERIALISING : 0; - int write_flags =3D job->serialize_target_writes ? BDRV_REQ_SERIALISIN= G : 0; + int write_flags =3D + (job->serialize_target_writes ? BDRV_REQ_SERIALISING : 0) | + (job->compress ? BDRV_REQ_WRITE_COMPRESSED : 0); + =20 assert(QEMU_IS_ALIGNED(start, job->cluster_size)); bdrv_reset_dirty_bitmap(job->copy_bitmap, start, job->cluster_size); @@ -131,14 +134,8 @@ static int coroutine_fn backup_cow_with_bounce_buffer(= BackupBlockJob *job, goto fail; } =20 - if (buffer_is_zero(*bounce_buffer, nbytes)) { - ret =3D blk_co_pwrite_zeroes(job->target, start, - nbytes, write_flags | BDRV_REQ_MAY_UNMA= P); - } else { - ret =3D blk_co_pwrite(job->target, start, - nbytes, *bounce_buffer, write_flags | - (job->compress ? BDRV_REQ_WRITE_COMPRESSED : 0= )); - } + ret =3D blk_co_pwrite(job->target, start, nbytes, *bounce_buffer, + write_flags); if (ret < 0) { trace_backup_do_cow_write_fail(job, start, ret); if (error_is_read) { diff --git a/blockdev.c b/blockdev.c index 29c6c6044a..2d7e7be538 100644 --- a/blockdev.c +++ b/blockdev.c @@ -3613,7 +3613,7 @@ static BlockJob *do_drive_backup(DriveBackup *backup,= JobTxn *txn, BlockDriverState *source =3D NULL; BlockJob *job =3D NULL; AioContext *aio_context; - QDict *options =3D NULL; + QDict *options; Error *local_err =3D NULL; int flags; int64_t size; @@ -3686,10 +3686,10 @@ static BlockJob *do_drive_backup(DriveBackup *backu= p, JobTxn *txn, goto out; } =20 + options =3D qdict_new(); + qdict_put_str(options, "discard", "unmap"); + qdict_put_str(options, "detect-zeroes", "unmap"); if (backup->format) { - if (!options) { - options =3D qdict_new(); - } qdict_put_str(options, "driver", backup->format); } =20 --=20 2.18.0 From nobody Tue Nov 11 19:02:12 2025 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=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1565364898; cv=none; d=zoho.com; s=zohoarc; b=kfL6K+VgpBIkX5yp5wxUeFC2IYk280c4/SWwVNv0yE2/yCwGmW8KNACBgasqwb2aD3zBrbJFBNWhWzLZL8qM1CT4w5K2QzA+yhXZAQiACCL+V1wZJyxiirD2vgWcgzY9PFNbyMaPEsXJLW+hLrbbW0vmbWSyQbKjyleylHmSbx0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565364898; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=QAaryPl8e8bIbw3mXjYvTW8yGF1MvzneuZ3at1VqCQQ=; b=eXrWIERl1Rn+OjwDr/yoOyjS4Pp7bTr4WhHuyPnhh9PKImqOFADvxuHgWphYlA8KJ0IAIgOT/aY+m8V0CTDNtqKZbUgKKbWU0puk28fX5Ce8zWv/dAyku3ZOjjuV9okDd9u6BoX0fdw6uu7XuXSv37+JMa9MAvFexWZKCI41GFE= 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 1565364898787601.0644221389405; Fri, 9 Aug 2019 08:34:58 -0700 (PDT) Received: from localhost ([::1]:60164 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hw6uv-0007ut-SG for importer@patchew.org; Fri, 09 Aug 2019 11:34:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49086) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hw6sN-00041h-IE for qemu-devel@nongnu.org; Fri, 09 Aug 2019 11:32:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hw6sL-0002pQ-5k for qemu-devel@nongnu.org; Fri, 09 Aug 2019 11:32:19 -0400 Received: from relay.sw.ru ([185.231.240.75]:57596) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hw6sI-0002io-1r; Fri, 09 Aug 2019 11:32:14 -0400 Received: from [10.94.3.0] (helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.92) (envelope-from ) id 1hw6sC-0004Cp-FL; Fri, 09 Aug 2019 18:32:08 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Date: Fri, 9 Aug 2019 18:32:02 +0300 Message-Id: <20190809153207.49288-3-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20190809153207.49288-1-vsementsov@virtuozzo.com> References: <20190809153207.49288-1-vsementsov@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 185.231.240.75 Subject: [Qemu-devel] [PATCH v2 2/7] block/backup: refactor write_flags 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: fam@euphon.net, kwolf@redhat.com, vsementsov@virtuozzo.com, armbru@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com, stefanha@redhat.com, den@openvz.org, jsnow@redhat.com 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" write flags are constant, let's store it in BackupBlockJob instead of recalculating. It also makes two boolean fields to be unused, so, drop them. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: John Snow Reviewed-by: Max Reitz --- block/backup.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/block/backup.c b/block/backup.c index d815436455..c6a3b2b7bb 100644 --- a/block/backup.c +++ b/block/backup.c @@ -50,14 +50,13 @@ typedef struct BackupBlockJob { uint64_t len; uint64_t bytes_read; int64_t cluster_size; - bool compress; NotifierWithReturn before_write; QLIST_HEAD(, CowRequest) inflight_reqs; =20 bool use_copy_range; int64_t copy_range_size; =20 - bool serialize_target_writes; + BdrvRequestFlags write_flags; bool initializing_bitmap; } BackupBlockJob; =20 @@ -113,10 +112,6 @@ static int coroutine_fn backup_cow_with_bounce_buffer(= BackupBlockJob *job, BlockBackend *blk =3D job->common.blk; int nbytes; int read_flags =3D is_write_notifier ? BDRV_REQ_NO_SERIALISING : 0; - int write_flags =3D - (job->serialize_target_writes ? BDRV_REQ_SERIALISING : 0) | - (job->compress ? BDRV_REQ_WRITE_COMPRESSED : 0); - =20 assert(QEMU_IS_ALIGNED(start, job->cluster_size)); bdrv_reset_dirty_bitmap(job->copy_bitmap, start, job->cluster_size); @@ -135,7 +130,7 @@ static int coroutine_fn backup_cow_with_bounce_buffer(B= ackupBlockJob *job, } =20 ret =3D blk_co_pwrite(job->target, start, nbytes, *bounce_buffer, - write_flags); + job->write_flags); if (ret < 0) { trace_backup_do_cow_write_fail(job, start, ret); if (error_is_read) { @@ -163,7 +158,6 @@ static int coroutine_fn backup_cow_with_offload(BackupB= lockJob *job, BlockBackend *blk =3D job->common.blk; int nbytes; int read_flags =3D is_write_notifier ? BDRV_REQ_NO_SERIALISING : 0; - int write_flags =3D job->serialize_target_writes ? BDRV_REQ_SERIALISIN= G : 0; =20 assert(QEMU_IS_ALIGNED(job->copy_range_size, job->cluster_size)); assert(QEMU_IS_ALIGNED(start, job->cluster_size)); @@ -172,7 +166,7 @@ static int coroutine_fn backup_cow_with_offload(BackupB= lockJob *job, bdrv_reset_dirty_bitmap(job->copy_bitmap, start, job->cluster_size * nr_clusters); ret =3D blk_co_copy_range(blk, start, job->target, start, nbytes, - read_flags, write_flags); + read_flags, job->write_flags); if (ret < 0) { trace_backup_do_cow_copy_range_fail(job, start, ret); bdrv_set_dirty_bitmap(job->copy_bitmap, start, @@ -748,10 +742,16 @@ BlockJob *backup_job_create(const char *job_id, Block= DriverState *bs, job->sync_mode =3D sync_mode; job->sync_bitmap =3D sync_bitmap; job->bitmap_mode =3D bitmap_mode; - job->compress =3D compress; =20 - /* Detect image-fleecing (and similar) schemes */ - job->serialize_target_writes =3D bdrv_chain_contains(target, bs); + /* + * Set write flags: + * 1. Detect image-fleecing (and similar) schemes + * 2. Handle compression + */ + job->write_flags =3D + (bdrv_chain_contains(target, bs) ? BDRV_REQ_SERIALISING : 0) | + (compress ? BDRV_REQ_WRITE_COMPRESSED : 0); + job->cluster_size =3D cluster_size; job->copy_bitmap =3D copy_bitmap; copy_bitmap =3D NULL; --=20 2.18.0 From nobody Tue Nov 11 19:02:12 2025 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=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1565364987; cv=none; d=zoho.com; s=zohoarc; b=JB2hn5x8TfFe195aJbB1DZzn5SGUWJKGJrsR1lSLMVM90fe0wQYzkBpovN2q7OMQxv7b437ePvBQ5tm6H7w/APqyoVS5UCF+W+L8jZoP99GZo8LkSHxVH1SMofgam/FLdDMCYYAcQDt7BXHTJJYbQiCmVmjNvEm0X4nYosxnakk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565364987; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=P9o2fHwbiIsrxVA8UitQc/NzmgdVc/S1+YG1DinRd1A=; b=ZR5LZokuYX9hyuelBnX3fDPnTk9AuKee3zRd3xetNWXZ2Ciol25LCv03RbBh82x1N3DTDDvh92OaLNM4sC7LZLymj8zl2geq9n6VQAdcdwgzWh+ehJrqLNnBpijsMRq3npFuKGixt2AxpM0GCS+FiFHxoOjU6GKacnl78MGBWHE= 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 1565364987550271.5340111537513; Fri, 9 Aug 2019 08:36:27 -0700 (PDT) Received: from localhost ([::1]:60184 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hw6wM-0002OY-4B for importer@patchew.org; Fri, 09 Aug 2019 11:36:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49081) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hw6sN-00041c-I3 for qemu-devel@nongnu.org; Fri, 09 Aug 2019 11:32:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hw6sL-0002pb-7k for qemu-devel@nongnu.org; Fri, 09 Aug 2019 11:32:19 -0400 Received: from relay.sw.ru ([185.231.240.75]:57598) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hw6sI-0002ik-10; Fri, 09 Aug 2019 11:32:14 -0400 Received: from [10.94.3.0] (helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.92) (envelope-from ) id 1hw6sC-0004Cp-NW; Fri, 09 Aug 2019 18:32:08 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Date: Fri, 9 Aug 2019 18:32:03 +0300 Message-Id: <20190809153207.49288-4-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20190809153207.49288-1-vsementsov@virtuozzo.com> References: <20190809153207.49288-1-vsementsov@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 185.231.240.75 Subject: [Qemu-devel] [PATCH v2 3/7] block/io: handle alignment and max_transfer for copy_range 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: fam@euphon.net, kwolf@redhat.com, vsementsov@virtuozzo.com, armbru@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com, stefanha@redhat.com, den@openvz.org, jsnow@redhat.com 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" copy_range ignores these limitations, let's improve it. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Max Reitz --- block/io.c | 48 ++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 40 insertions(+), 8 deletions(-) diff --git a/block/io.c b/block/io.c index 06305c6ea6..a5efb2200f 100644 --- a/block/io.c +++ b/block/io.c @@ -3005,11 +3005,24 @@ static int coroutine_fn bdrv_co_copy_range_internal( { BdrvTrackedRequest req; int ret; + uint32_t align =3D MAX(src->bs->bl.request_alignment, + dst->bs->bl.request_alignment); + uint32_t max_transfer =3D + QEMU_ALIGN_DOWN(MIN_NON_ZERO(MIN_NON_ZERO(src->bs->bl.max_tran= sfer, + dst->bs->bl.max_tran= sfer), + INT_MAX), align); =20 /* TODO We can support BDRV_REQ_NO_FALLBACK here */ assert(!(read_flags & BDRV_REQ_NO_FALLBACK)); assert(!(write_flags & BDRV_REQ_NO_FALLBACK)); =20 + if (max_transfer =3D=3D 0 && bytes > 0) { + /* + * For example, if source max_transfer is smaller than target alig= nment. + */ + return -ENOTSUP; + } + if (!dst || !dst->bs) { return -ENOMEDIUM; } @@ -3031,7 +3044,10 @@ static int coroutine_fn bdrv_co_copy_range_internal( =20 if (!src->bs->drv->bdrv_co_copy_range_from || !dst->bs->drv->bdrv_co_copy_range_to - || src->bs->encrypted || dst->bs->encrypted) { + || src->bs->encrypted || dst->bs->encrypted || + !QEMU_IS_ALIGNED(src_offset, src->bs->bl.request_alignment) || + !QEMU_IS_ALIGNED(dst_offset, dst->bs->bl.request_alignment) || + !QEMU_IS_ALIGNED(bytes, align)) { return -ENOTSUP; } =20 @@ -3046,11 +3062,22 @@ static int coroutine_fn bdrv_co_copy_range_internal( wait_serialising_requests(&req); } =20 - ret =3D src->bs->drv->bdrv_co_copy_range_from(src->bs, - src, src_offset, - dst, dst_offset, - bytes, - read_flags, write_flag= s); + while (bytes) { + int num =3D MIN(bytes, max_transfer); + + ret =3D src->bs->drv->bdrv_co_copy_range_from(src->bs, + src, src_offset, + dst, dst_offset, + num, + read_flags, + write_flags); + if (ret < 0) { + break; + } + bytes -=3D num; + src_offset +=3D num; + dst_offset +=3D num; + } =20 tracked_request_end(&req); bdrv_dec_in_flight(src->bs); @@ -3060,12 +3087,17 @@ static int coroutine_fn bdrv_co_copy_range_internal( BDRV_TRACKED_WRITE); ret =3D bdrv_co_write_req_prepare(dst, dst_offset, bytes, &req, write_flags); - if (!ret) { + while (!ret && bytes) { + int num =3D MIN(bytes, max_transfer); + ret =3D dst->bs->drv->bdrv_co_copy_range_to(dst->bs, src, src_offset, dst, dst_offset, - bytes, + num, read_flags, write_fl= ags); + bytes -=3D num; + src_offset +=3D num; + dst_offset +=3D num; } bdrv_co_write_req_finish(dst, dst_offset, bytes, &req, ret); tracked_request_end(&req); --=20 2.18.0 From nobody Tue Nov 11 19:02:12 2025 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=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1565364956; cv=none; d=zoho.com; s=zohoarc; b=ZR0jZ9RpreHISX6Dd8b1OEqiy1ETVV4EQv/RkBL7G3pMaB3+HZVtAYZJmyge2qPCpBYZkKzTofeRgsFwZEmAOennxwHeVnLVolzGxsUhj/9CJtUahigrHmaqp2wiycWfQ6eH5//BvWhO/hLIMM7jrE1f/JaGLVsKyk4iuMtnEbU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565364956; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=tKJtNs73ajZ1RjHeS5oX4+hVvrOmazpmvkUA1k/LBM0=; b=FGcDk5Ro/W1mmzKKl24m8m2JOcJXGzpnUzSaToyrLOHA2vnvGEmCbEzDcvGR5w1VkMQolR636UKs99ctSCqciClLcYDbOYoG6gpkfiGma0h+TdnyiUE5hfepGzd7U5Z1vxyxFr9uagGOgXFdv9VYkcU4kD8sB9iapHd577y20ZQ= 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 1565364956775984.264941472371; Fri, 9 Aug 2019 08:35:56 -0700 (PDT) Received: from localhost ([::1]:60172 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hw6vr-0000s5-SO for importer@patchew.org; Fri, 09 Aug 2019 11:35:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49083) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hw6sN-00041e-I3 for qemu-devel@nongnu.org; Fri, 09 Aug 2019 11:32:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hw6sL-0002pd-7l for qemu-devel@nongnu.org; Fri, 09 Aug 2019 11:32:19 -0400 Received: from relay.sw.ru ([185.231.240.75]:57610) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hw6sI-0002im-2q; Fri, 09 Aug 2019 11:32:14 -0400 Received: from [10.94.3.0] (helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.92) (envelope-from ) id 1hw6sD-0004Cp-01; Fri, 09 Aug 2019 18:32:09 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Date: Fri, 9 Aug 2019 18:32:04 +0300 Message-Id: <20190809153207.49288-5-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20190809153207.49288-1-vsementsov@virtuozzo.com> References: <20190809153207.49288-1-vsementsov@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 185.231.240.75 Subject: [Qemu-devel] [PATCH v2 4/7] block/backup: drop handling of max_transfer for copy_range 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: fam@euphon.net, kwolf@redhat.com, vsementsov@virtuozzo.com, armbru@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com, stefanha@redhat.com, den@openvz.org, jsnow@redhat.com 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" Since previous commit, copy_range supports max_transfer, so we don't need to handle it by hand. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Max Reitz --- block/backup.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/block/backup.c b/block/backup.c index c6a3b2b7bb..228ba9423c 100644 --- a/block/backup.c +++ b/block/backup.c @@ -54,7 +54,6 @@ typedef struct BackupBlockJob { QLIST_HEAD(, CowRequest) inflight_reqs; =20 bool use_copy_range; - int64_t copy_range_size; =20 BdrvRequestFlags write_flags; bool initializing_bitmap; @@ -156,12 +155,11 @@ static int coroutine_fn backup_cow_with_offload(Backu= pBlockJob *job, int ret; int nr_clusters; BlockBackend *blk =3D job->common.blk; - int nbytes; + int nbytes =3D end - start; int read_flags =3D is_write_notifier ? BDRV_REQ_NO_SERIALISING : 0; =20 - assert(QEMU_IS_ALIGNED(job->copy_range_size, job->cluster_size)); + assert(end - start < INT_MAX); assert(QEMU_IS_ALIGNED(start, job->cluster_size)); - nbytes =3D MIN(job->copy_range_size, end - start); nr_clusters =3D DIV_ROUND_UP(nbytes, job->cluster_size); bdrv_reset_dirty_bitmap(job->copy_bitmap, start, job->cluster_size * nr_clusters); @@ -756,11 +754,6 @@ BlockJob *backup_job_create(const char *job_id, BlockD= riverState *bs, job->copy_bitmap =3D copy_bitmap; copy_bitmap =3D NULL; job->use_copy_range =3D !compress; /* compression isn't supported for = it */ - job->copy_range_size =3D MIN_NON_ZERO(blk_get_max_transfer(job->common= .blk), - blk_get_max_transfer(job->target)); - job->copy_range_size =3D MAX(job->cluster_size, - QEMU_ALIGN_UP(job->copy_range_size, - job->cluster_size)); =20 /* Required permissions are already taken with target's blk_new() */ block_job_add_bdrv(&job->common, "target", target, 0, BLK_PERM_ALL, --=20 2.18.0 From nobody Tue Nov 11 19:02:12 2025 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=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1565364854; cv=none; d=zoho.com; s=zohoarc; b=W3r3guFlTRwk10XXgUqmOnnwNPopqd2uwHmmVIr6xmOBd8nNIZNGRDxVAdcbHGwlNFa7ZdyZHLS8vP8OxrnHJOvbfPvbbbSSNzF6IUrH/4lkbse/fMBsqUHLnfLRAA+T2V0wMWrfmuPsUT12EY42cOe4vDbAGRbNMCUtu+2nAsg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565364854; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=905t/uiZ6C/Q0x2CpY1Bne+fC24Sjf1bwvvm1fd7QTI=; b=nq2mlkW7PZPIvkapLs0idORNcqD96Q9vIgQ/cryR+pA/wVTTaDwxQ5pnw+kGNsDVkDEQ7uKc8I7JqbocHYl2V/dr3Y+fk04RNyF8aDU+FjELCu71vUoSdhUAHEIgyghjDCQNUQjcAeIH/CAbxkUQLF+w/bOE1U5HU2yGuHIh9Nw= 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 1565364854531285.69751717021336; Fri, 9 Aug 2019 08:34:14 -0700 (PDT) Received: from localhost ([::1]:60150 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hw6uD-0005kL-Je for importer@patchew.org; Fri, 09 Aug 2019 11:34:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49052) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hw6sL-0003v2-IN for qemu-devel@nongnu.org; Fri, 09 Aug 2019 11:32:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hw6sK-0002oh-CT for qemu-devel@nongnu.org; Fri, 09 Aug 2019 11:32:17 -0400 Received: from relay.sw.ru ([185.231.240.75]:57606) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hw6sI-0002il-0r; Fri, 09 Aug 2019 11:32:14 -0400 Received: from [10.94.3.0] (helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.92) (envelope-from ) id 1hw6sD-0004Cp-7J; Fri, 09 Aug 2019 18:32:09 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Date: Fri, 9 Aug 2019 18:32:05 +0300 Message-Id: <20190809153207.49288-6-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20190809153207.49288-1-vsementsov@virtuozzo.com> References: <20190809153207.49288-1-vsementsov@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 185.231.240.75 Subject: [Qemu-devel] [PATCH v2 5/7] block/backup: fix backup_cow_with_offload for last cluster 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: fam@euphon.net, kwolf@redhat.com, vsementsov@virtuozzo.com, armbru@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com, stefanha@redhat.com, den@openvz.org, jsnow@redhat.com 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" We shouldn't try to copy bytes beyond EOF. Fix it. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Max Reitz --- block/backup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/block/backup.c b/block/backup.c index 228ba9423c..d482d93458 100644 --- a/block/backup.c +++ b/block/backup.c @@ -155,7 +155,7 @@ static int coroutine_fn backup_cow_with_offload(BackupB= lockJob *job, int ret; int nr_clusters; BlockBackend *blk =3D job->common.blk; - int nbytes =3D end - start; + int nbytes =3D MIN(end - start, job->len - start); int read_flags =3D is_write_notifier ? BDRV_REQ_NO_SERIALISING : 0; =20 assert(end - start < INT_MAX); --=20 2.18.0 From nobody Tue Nov 11 19:02:12 2025 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=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1565364907; cv=none; d=zoho.com; s=zohoarc; b=SORNNCaczYlynDIEP1SdvArcNjFHmc8heiPIuxTvq2agUNPcuIOKvzrMOTmviTO1yC3brN1Y+xq40Zt5PTWr7xY9X240UY0beqjoMvvOkTwKu32RhPZi/DIb2WhhV754APMa0e/yyW1Ncf3md0kyqEL7U2pXdCm3YOgGZw6Gr8I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565364907; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=kIQyD2PL/U6x40nxHqzni4t/vDOFpb753xtc3gY/lKE=; b=hKgSq60sfiUPp3V89dkiqMNjex0YQ6KhuWpvePE6oKEN0Fel1kYHRnBlTW5K8pHLrELuE6fyDcvs3QO91eNgUzQdjkn2VYQ8fiIoJJuikO6OTuIos4440Tl94otp8uUQzVHDgd+RvfJK4zXH2j7wucGqK+9+2esRsxfYaqUZtp4= 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 1565364907102654.5474746508556; Fri, 9 Aug 2019 08:35:07 -0700 (PDT) Received: from localhost ([::1]:60168 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hw6v3-0008IM-4Z for importer@patchew.org; Fri, 09 Aug 2019 11:35:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49089) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hw6sN-00041o-Ih for qemu-devel@nongnu.org; Fri, 09 Aug 2019 11:32:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hw6sL-0002pS-5o for qemu-devel@nongnu.org; Fri, 09 Aug 2019 11:32:19 -0400 Received: from relay.sw.ru ([185.231.240.75]:57612) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hw6sI-0002ih-1Z; Fri, 09 Aug 2019 11:32:14 -0400 Received: from [10.94.3.0] (helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.92) (envelope-from ) id 1hw6sD-0004Cp-Hj; Fri, 09 Aug 2019 18:32:09 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Date: Fri, 9 Aug 2019 18:32:06 +0300 Message-Id: <20190809153207.49288-7-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20190809153207.49288-1-vsementsov@virtuozzo.com> References: <20190809153207.49288-1-vsementsov@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 185.231.240.75 Subject: [Qemu-devel] [PATCH v2 6/7] block/backup: teach backup_cow_with_bounce_buffer to copy more at once 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: fam@euphon.net, kwolf@redhat.com, vsementsov@virtuozzo.com, armbru@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com, stefanha@redhat.com, den@openvz.org, jsnow@redhat.com 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" backup_cow_with_offload can transfer more than on cluster. Let backup_cow_with_bounce_buffer behave similarly. It reduces number of IO and there are no needs to copy cluster by cluster. Signed-off-by: Vladimir Sementsov-Ogievskiy --- block/backup.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/block/backup.c b/block/backup.c index d482d93458..155e21d0a3 100644 --- a/block/backup.c +++ b/block/backup.c @@ -104,22 +104,25 @@ static int coroutine_fn backup_cow_with_bounce_buffer= (BackupBlockJob *job, int64_t start, int64_t end, bool is_write_notifi= er, - bool *error_is_read, - void **bounce_buffer) + bool *error_is_read) { int ret; BlockBackend *blk =3D job->common.blk; int nbytes; int read_flags =3D is_write_notifier ? BDRV_REQ_NO_SERIALISING : 0; + void *bounce_buffer; =20 assert(QEMU_IS_ALIGNED(start, job->cluster_size)); - bdrv_reset_dirty_bitmap(job->copy_bitmap, start, job->cluster_size); - nbytes =3D MIN(job->cluster_size, job->len - start); - if (!*bounce_buffer) { - *bounce_buffer =3D blk_blockalign(blk, job->cluster_size); + + nbytes =3D MIN(end - start, job->len - start); + bounce_buffer =3D blk_try_blockalign(blk, nbytes); + if (!bounce_buffer) { + return -ENOMEM; } =20 - ret =3D blk_co_pread(blk, start, nbytes, *bounce_buffer, read_flags); + bdrv_reset_dirty_bitmap(job->copy_bitmap, start, end - start); + + ret =3D blk_co_pread(blk, start, nbytes, bounce_buffer, read_flags); if (ret < 0) { trace_backup_do_cow_read_fail(job, start, ret); if (error_is_read) { @@ -128,7 +131,7 @@ static int coroutine_fn backup_cow_with_bounce_buffer(B= ackupBlockJob *job, goto fail; } =20 - ret =3D blk_co_pwrite(job->target, start, nbytes, *bounce_buffer, + ret =3D blk_co_pwrite(job->target, start, nbytes, bounce_buffer, job->write_flags); if (ret < 0) { trace_backup_do_cow_write_fail(job, start, ret); @@ -138,9 +141,12 @@ static int coroutine_fn backup_cow_with_bounce_buffer(= BackupBlockJob *job, goto fail; } =20 + qemu_vfree(bounce_buffer); return nbytes; + fail: bdrv_set_dirty_bitmap(job->copy_bitmap, start, job->cluster_size); + qemu_vfree(bounce_buffer); return ret; =20 } @@ -254,7 +260,6 @@ static int coroutine_fn backup_do_cow(BackupBlockJob *j= ob, CowRequest cow_request; int ret =3D 0; int64_t start, end; /* bytes */ - void *bounce_buffer =3D NULL; int64_t skip_bytes; =20 qemu_co_rwlock_rdlock(&job->flush_rwlock); @@ -303,7 +308,7 @@ static int coroutine_fn backup_do_cow(BackupBlockJob *j= ob, if (!job->use_copy_range) { ret =3D backup_cow_with_bounce_buffer(job, start, dirty_end, is_write_notifier, - error_is_read, &bounce_buf= fer); + error_is_read); } if (ret < 0) { break; @@ -318,10 +323,6 @@ static int coroutine_fn backup_do_cow(BackupBlockJob *= job, ret =3D 0; } =20 - if (bounce_buffer) { - qemu_vfree(bounce_buffer); - } - cow_request_end(&cow_request); =20 trace_backup_do_cow_return(job, offset, bytes, ret); --=20 2.18.0 From nobody Tue Nov 11 19:02:12 2025 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=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1565365025; cv=none; d=zoho.com; s=zohoarc; b=nCwxWdfiKV8735mBfGvl4qNm5bt01ETfp9epJS1HEqBL8EvY7yqZXea+zyx22TX9IImv4z3Wix9cQ6Hke+zclx/VlaidMDn+A06KBPv1v7qq3vDDwvY77VDLRnRDP+z3aLQskIfkeWZfC/heJ4B3xmu8wV9L9v2F+mLvJL6Wj9M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565365025; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=+9OzqmcxQgWiSHFLQQ56qkNcnO3gIX3rHqy0alXK95U=; b=DLpFZ1od40x/6WvnxyCwO8VALcZ8NwR7PbGfw7vVGkUSF31YBp/+0BoZUhXHhFUeFrBL07qSviovIm1FQ8qE9qpXSiHFI9qTmRMbzFJMEuiMuuBM/qjkXAJtn5A3gbbEUfwjZcmJUDOdxI7Xvlvdo9VIyxkqhSrwqHjHu08p0tw= 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 1565365025648323.4936936903583; Fri, 9 Aug 2019 08:37:05 -0700 (PDT) Received: from localhost ([::1]:60194 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hw6wv-0003S4-MP for importer@patchew.org; Fri, 09 Aug 2019 11:37:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49127) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hw6sR-000431-Am for qemu-devel@nongnu.org; Fri, 09 Aug 2019 11:32:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hw6sN-0002qz-Gn for qemu-devel@nongnu.org; Fri, 09 Aug 2019 11:32:21 -0400 Received: from relay.sw.ru ([185.231.240.75]:57614) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hw6sI-0002ii-1a; Fri, 09 Aug 2019 11:32:14 -0400 Received: from [10.94.3.0] (helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.92) (envelope-from ) id 1hw6sD-0004Cp-To; Fri, 09 Aug 2019 18:32:10 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Date: Fri, 9 Aug 2019 18:32:07 +0300 Message-Id: <20190809153207.49288-8-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20190809153207.49288-1-vsementsov@virtuozzo.com> References: <20190809153207.49288-1-vsementsov@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 185.231.240.75 Subject: [Qemu-devel] [PATCH v2 7/7] block/backup: merge duplicated logic into backup_do_cow 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: fam@euphon.net, kwolf@redhat.com, vsementsov@virtuozzo.com, armbru@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com, stefanha@redhat.com, den@openvz.org, jsnow@redhat.com 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" backup_cow_with_offload and backup_cow_with_bounce_buffer contains a lot of duplicated logic. Move it into backup_do_cow. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Max Reitz --- block/backup.c | 84 +++++++++++++++++++------------------------------- 1 file changed, 31 insertions(+), 53 deletions(-) diff --git a/block/backup.c b/block/backup.c index 155e21d0a3..ae780e1260 100644 --- a/block/backup.c +++ b/block/backup.c @@ -100,85 +100,60 @@ static void cow_request_end(CowRequest *req) =20 /* Copy range to target with a bounce buffer and return the bytes copied. = If * error occurred, return a negative error number */ -static int coroutine_fn backup_cow_with_bounce_buffer(BackupBlockJob *job, - int64_t start, - int64_t end, - bool is_write_notifi= er, - bool *error_is_read) +static int coroutine_fn backup_cow_with_bounce_buffer( + BackupBlockJob *job, int64_t offset, int64_t bytes, + BdrvRequestFlags read_flags, bool *error_is_read) { - int ret; + int ret =3D 0; BlockBackend *blk =3D job->common.blk; - int nbytes; - int read_flags =3D is_write_notifier ? BDRV_REQ_NO_SERIALISING : 0; - void *bounce_buffer; - - assert(QEMU_IS_ALIGNED(start, job->cluster_size)); + void *bounce_buffer =3D blk_try_blockalign(blk, bytes); =20 - nbytes =3D MIN(end - start, job->len - start); - bounce_buffer =3D blk_try_blockalign(blk, nbytes); if (!bounce_buffer) { return -ENOMEM; } =20 - bdrv_reset_dirty_bitmap(job->copy_bitmap, start, end - start); - - ret =3D blk_co_pread(blk, start, nbytes, bounce_buffer, read_flags); + ret =3D blk_co_pread(blk, offset, bytes, bounce_buffer, read_flags); if (ret < 0) { - trace_backup_do_cow_read_fail(job, start, ret); + trace_backup_do_cow_read_fail(job, offset, ret); if (error_is_read) { *error_is_read =3D true; } - goto fail; + goto out; } =20 - ret =3D blk_co_pwrite(job->target, start, nbytes, bounce_buffer, + ret =3D blk_co_pwrite(job->target, offset, bytes, bounce_buffer, job->write_flags); if (ret < 0) { - trace_backup_do_cow_write_fail(job, start, ret); + trace_backup_do_cow_write_fail(job, offset, ret); if (error_is_read) { *error_is_read =3D false; } - goto fail; + goto out; } =20 +out: qemu_vfree(bounce_buffer); - return nbytes; =20 -fail: - bdrv_set_dirty_bitmap(job->copy_bitmap, start, job->cluster_size); - qemu_vfree(bounce_buffer); return ret; - } =20 /* Copy range to target and return the bytes copied. If error occurred, re= turn a * negative error number. */ static int coroutine_fn backup_cow_with_offload(BackupBlockJob *job, - int64_t start, - int64_t end, - bool is_write_notifier) + int64_t offset, + int64_t bytes, + BdrvRequestFlags read_flag= s) { int ret; - int nr_clusters; BlockBackend *blk =3D job->common.blk; - int nbytes =3D MIN(end - start, job->len - start); - int read_flags =3D is_write_notifier ? BDRV_REQ_NO_SERIALISING : 0; - - assert(end - start < INT_MAX); - assert(QEMU_IS_ALIGNED(start, job->cluster_size)); - nr_clusters =3D DIV_ROUND_UP(nbytes, job->cluster_size); - bdrv_reset_dirty_bitmap(job->copy_bitmap, start, - job->cluster_size * nr_clusters); - ret =3D blk_co_copy_range(blk, start, job->target, start, nbytes, + + ret =3D blk_co_copy_range(blk, offset, job->target, offset, bytes, read_flags, job->write_flags); if (ret < 0) { - trace_backup_do_cow_copy_range_fail(job, start, ret); - bdrv_set_dirty_bitmap(job->copy_bitmap, start, - job->cluster_size * nr_clusters); - return ret; + trace_backup_do_cow_copy_range_fail(job, offset, ret); } =20 - return nbytes; + return ret; } =20 /* @@ -261,6 +236,8 @@ static int coroutine_fn backup_do_cow(BackupBlockJob *j= ob, int ret =3D 0; int64_t start, end; /* bytes */ int64_t skip_bytes; + BdrvRequestFlags read_flags =3D + is_write_notifier ? BDRV_REQ_NO_SERIALISING : 0; =20 qemu_co_rwlock_rdlock(&job->flush_rwlock); =20 @@ -274,6 +251,7 @@ static int coroutine_fn backup_do_cow(BackupBlockJob *j= ob, =20 while (start < end) { int64_t dirty_end; + int64_t cur_bytes; =20 if (!bdrv_dirty_bitmap_get(job->copy_bitmap, start)) { trace_backup_do_cow_skip(job, start); @@ -297,30 +275,30 @@ static int coroutine_fn backup_do_cow(BackupBlockJob = *job, } =20 trace_backup_do_cow_process(job, start); + cur_bytes =3D MIN(dirty_end - start, job->len - start); + bdrv_reset_dirty_bitmap(job->copy_bitmap, start, dirty_end - start= ); =20 if (job->use_copy_range) { - ret =3D backup_cow_with_offload(job, start, dirty_end, - is_write_notifier); + ret =3D backup_cow_with_offload(job, start, cur_bytes, read_fl= ags); if (ret < 0) { job->use_copy_range =3D false; } } if (!job->use_copy_range) { - ret =3D backup_cow_with_bounce_buffer(job, start, dirty_end, - is_write_notifier, - error_is_read); + ret =3D backup_cow_with_bounce_buffer(job, start, cur_bytes, + read_flags, error_is_read); } if (ret < 0) { + bdrv_set_dirty_bitmap(job->copy_bitmap, start, dirty_end - sta= rt); break; } =20 /* Publish progress, guest I/O counts as progress too. Note that = the * offset field is an opaque progress value, it is not a disk offs= et. */ - start +=3D ret; - job->bytes_read +=3D ret; - job_progress_update(&job->common.job, ret); - ret =3D 0; + start +=3D cur_bytes; + job->bytes_read +=3D cur_bytes; + job_progress_update(&job->common.job, cur_bytes); } =20 cow_request_end(&cow_request); --=20 2.18.0