From nobody Thu Mar 28 11:18:20 2024 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=1565465603; cv=none; d=zoho.com; s=zohoarc; b=G9N/h67oNjnwnU27IxSJJ6snCsk96MdDqT1rjkeAeFn4+uSW7Xvufuo4Zof1SGRTL5NZo3j9u0CSvATrsp/LGwqJa7xb5WrZa14TPId8NVBTmm/CmigT5LnOfPZUTkd036HhIgJo/+owFWaCGuruv3fn+Nd0urTly4zCansl7bQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565465603; 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=ArVnQGjM8ceDeI6JNx5ge6wUMFVWZUKBvRjfMEFDb9Nej+UwS1egDWJCIjfjMsguCGKZlW2sqvtGdr3rqRGuSNvm64NmeIg68w3QYYzZCIwD5XruoTys+N9khV9VdjRsNxf4xpGpfpRq57NhiCRYQzSGZJI+j5jKx0KqdPjUH0w= 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 1565465603161279.3055524171972; Sat, 10 Aug 2019 12:33:23 -0700 (PDT) Received: from localhost ([::1]:37862 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hwX7C-0002la-9G for importer@patchew.org; Sat, 10 Aug 2019 15:33:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44022) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hwX5y-0000Ii-U4 for qemu-devel@nongnu.org; Sat, 10 Aug 2019 15:32:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hwX5x-0007By-Q2 for qemu-devel@nongnu.org; Sat, 10 Aug 2019 15:32:06 -0400 Received: from relay.sw.ru ([185.231.240.75]:48794) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hwX5s-000773-FE; Sat, 10 Aug 2019 15:32:01 -0400 Received: from [10.94.3.0] (helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.92) (envelope-from ) id 1hwX5o-0000nK-QL; Sat, 10 Aug 2019 22:31:56 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Date: Sat, 10 Aug 2019 22:31:49 +0300 Message-Id: <20190810193155.58637-2-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20190810193155.58637-1-vsementsov@virtuozzo.com> References: <20190810193155.58637-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 v3 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 Thu Mar 28 11:18:20 2024 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=1565465605; cv=none; d=zoho.com; s=zohoarc; b=Jz1/3So/1AaHEhKDieuK+rFTH9DOpf2+/DPi8kbwbQuLot/bcfv6I3+8MWIQnVDpjBAoaKQ5SwmrQu1xV3EHeI0L41haHXPTwm2SvriNrAQlea3KMOpeD6+lPtNmvLbhnKzu8RWWR7dZGmHoLpB91GvAunKw/44pF39XkMdxbtk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565465605; 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=fNa+oOO3eksyxEQYZM9xpY+hgomf/bMJM2r3ljTyE30ZNnphsT8SguvFbKjTOUYjhU0WfX1Oxk06S8sfS9NifzLB3l6oILT9kjLONYQA05MhtQ3N1j+O7M7f+x9mAXjLRKIBD6pwKRrhauSfEcJ7vO6wZSBUHAlP8cgyItYKDr4= 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 1565465605945574.531195691117; Sat, 10 Aug 2019 12:33:25 -0700 (PDT) Received: from localhost ([::1]:37864 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hwX7B-0002m1-VC for importer@patchew.org; Sat, 10 Aug 2019 15:33:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44039) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hwX5z-0000Jv-AN for qemu-devel@nongnu.org; Sat, 10 Aug 2019 15:32:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hwX5x-0007CH-TQ for qemu-devel@nongnu.org; Sat, 10 Aug 2019 15:32:07 -0400 Received: from relay.sw.ru ([185.231.240.75]:48780) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hwX5s-000772-FA; Sat, 10 Aug 2019 15:32:01 -0400 Received: from [10.94.3.0] (helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.92) (envelope-from ) id 1hwX5o-0000nK-UQ; Sat, 10 Aug 2019 22:31:56 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Date: Sat, 10 Aug 2019 22:31:50 +0300 Message-Id: <20190810193155.58637-3-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20190810193155.58637-1-vsementsov@virtuozzo.com> References: <20190810193155.58637-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 v3 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 Thu Mar 28 11:18:20 2024 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=1565465685; cv=none; d=zoho.com; s=zohoarc; b=ESDQBFsrZg/CMj3OgQpwG3VcX/r7lMgK0oEWdUuDa8w5/MdOKBni3OzRoE5qIsG7A3aCPnaHiQNuClT0fUw3PQ/JCVC2f5yXL9T4btzhzbAF2ah2lE2eqUn564MJrWQ73fQ92sfYo7gRkPX49xOsdTm2cYF2ZRwVTB15Ro4MskM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565465685; 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=XDpoYUsWostjlQF1DaC050+qDzPYyTP/XlAm8LZP0o4=; b=PjNxqfW0Han00cLXUqO8LcaEmlkMdYYLJmDXjI5ghuf2pgWR2mppNxLdT108EDbt45ieDzp7Dj5Nj8qzKlENx7vns84VQ32e5A1DkhSvSgDnoGTWXA2Dmf1zQ2/ACq5kEQzVzyESLBiAqC/19YHRBBWYbwd1AdAT3DwBQHBvnL0= 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 1565465685575460.9638852303366; Sat, 10 Aug 2019 12:34:45 -0700 (PDT) Received: from localhost ([::1]:37880 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hwX8W-0005Oe-Gt for importer@patchew.org; Sat, 10 Aug 2019 15:34:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44030) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hwX5z-0000Iw-0W for qemu-devel@nongnu.org; Sat, 10 Aug 2019 15:32:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hwX5x-0007Bz-QG for qemu-devel@nongnu.org; Sat, 10 Aug 2019 15:32:06 -0400 Received: from relay.sw.ru ([185.231.240.75]:48790) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hwX5s-000774-FS; Sat, 10 Aug 2019 15:32:01 -0400 Received: from [10.94.3.0] (helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.92) (envelope-from ) id 1hwX5p-0000nK-2A; Sat, 10 Aug 2019 22:31:57 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Date: Sat, 10 Aug 2019 22:31:51 +0300 Message-Id: <20190810193155.58637-4-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20190810193155.58637-1-vsementsov@virtuozzo.com> References: <20190810193155.58637-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 v3 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 | 44 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/block/io.c b/block/io.c index 06305c6ea6..45b1e1f76e 100644 --- a/block/io.c +++ b/block/io.c @@ -3005,11 +3005,13 @@ static int coroutine_fn bdrv_co_copy_range_internal( { BdrvTrackedRequest req; int ret; + uint32_t align, max_transfer; =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 (!dst || !dst->bs) { return -ENOMEDIUM; } @@ -3029,9 +3031,19 @@ static int coroutine_fn bdrv_co_copy_range_internal( return ret; } =20 + align =3D MAX(src->bs->bl.request_alignment, dst->bs->bl.request_align= ment); + 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); + 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 || + (max_transfer =3D=3D 0 && bytes > 0) || + !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 +3058,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 +3083,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 Thu Mar 28 11:18:20 2024 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=1565465735; cv=none; d=zoho.com; s=zohoarc; b=Zunyrxigf4g41eQjw77npbgf4XYguu/MwPAHLGfCCW+pOE/CFE+seDUCrbYItn7co5Nxui3UnhL4NhsHvXBprtULNnBTpTEzfRuWq951lXaThjFB/SYJL4SofTdcRS//7kzzloveFBBL2MhTbaSYWRIQkC2VoSlqqyu5nbZHFDw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565465735; 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=Dto1+ZooUqoYz36S+t1jqH4ROftUgVC29BpQov9jSE8=; b=DaQzpLSoQhplnkjZzwrYY8rR1cKcCfKSb6dJFW2N9X8N0zwi9pSoAn2eLu22pcGYBjkxdtssn6IeM2rIQP+dB7hA+yCZ/3z2XvPgUuhCB1/RQQgJCUss3Lc0l88DNYfZR9y5D3fC302VAXEQrsi+3MEGECfDN/zktZ1iKKhqCVU= 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 1565465735411800.298737161686; Sat, 10 Aug 2019 12:35:35 -0700 (PDT) Received: from localhost ([::1]:37896 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hwX9K-0007o1-Hs for importer@patchew.org; Sat, 10 Aug 2019 15:35:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44054) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hwX5z-0000LL-NY for qemu-devel@nongnu.org; Sat, 10 Aug 2019 15:32:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hwX5y-0007Cp-LL for qemu-devel@nongnu.org; Sat, 10 Aug 2019 15:32:07 -0400 Received: from relay.sw.ru ([185.231.240.75]:48772) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hwX5s-00076y-IY; Sat, 10 Aug 2019 15:32:01 -0400 Received: from [10.94.3.0] (helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.92) (envelope-from ) id 1hwX5p-0000nK-7l; Sat, 10 Aug 2019 22:31:57 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Date: Sat, 10 Aug 2019 22:31:52 +0300 Message-Id: <20190810193155.58637-5-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20190810193155.58637-1-vsementsov@virtuozzo.com> References: <20190810193155.58637-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 v3 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 Thu Mar 28 11:18:20 2024 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=1565465598; cv=none; d=zoho.com; s=zohoarc; b=k0stKMtTpEjQTFnFMCHeciMlCGYMAHfZgYQuf3j96btJMHsieanv4xd8/79sCwpphAnUvt56fPZrrxNCbx6PHd8wtAisj71878F9abvWoCIhTiHbcU93dh3IHkgelHxJk9pIV95iSMjCvx+l68SVVC0OBzHCbyNRnFOJFobUGbo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565465598; 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=htQ5NmBfVDa7xl80yVB1dw2JEdSLnO9DqQ7nheodezd2ZguP2l/ZlLDQhtNjlr/Tij4cGmDE39VoLgFv8x9PTQexCGNE0tFD9ea0+rSV4NR6QO2vQAgpb833tLcYx8ZA80S5XpCjmVDXuw3B20mfhCwV9HArMK55cKKG/OFhcDo= 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 1565465598522564.6055139734359; Sat, 10 Aug 2019 12:33:18 -0700 (PDT) Received: from localhost ([::1]:37858 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hwX74-0002LG-FU for importer@patchew.org; Sat, 10 Aug 2019 15:33:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44010) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hwX5y-0000Hw-ME for qemu-devel@nongnu.org; Sat, 10 Aug 2019 15:32:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hwX5x-0007Bs-PX for qemu-devel@nongnu.org; Sat, 10 Aug 2019 15:32:06 -0400 Received: from relay.sw.ru ([185.231.240.75]:48782) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hwX5s-000771-FC; Sat, 10 Aug 2019 15:32:01 -0400 Received: from [10.94.3.0] (helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.92) (envelope-from ) id 1hwX5p-0000nK-B5; Sat, 10 Aug 2019 22:31:57 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Date: Sat, 10 Aug 2019 22:31:53 +0300 Message-Id: <20190810193155.58637-6-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20190810193155.58637-1-vsementsov@virtuozzo.com> References: <20190810193155.58637-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 v3 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 Thu Mar 28 11:18:20 2024 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=1565465687; cv=none; d=zoho.com; s=zohoarc; b=C9Qdl73PfSOoCJpS/fpHGGHvCCvfQRdRIvdmEBqJIl9zFvTvxEXAq0Z12p7/bN0/siXBpcWuGZlWjKg4WsU/8c2CLynleEfmpSGTeY+nIugT/YVmULtQF7Mmv1ZNlL/oGxjJNr6P0Cctax3O37iqVOzpFy5Tm5S/hkuy0TswFk8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565465687; 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=sVP2tI1e6f7dZaMiHs1iq7kO1Ba8bSKvu5BAguB9d/w=; b=GrdAoZxGHQ2kNXhqY4VzOmzFLStEa4BOWJ1BtRYs7pbGrvH9E4F2KnvDp6qrVOX/vpla1WGMwe8X1koFsshzz5FVLeFUwqbpbQKbJ7CfrIIalJ5Ce55CdyAT8NB5b7bXzSsvGVMDHStlHWM0hXKzkI+bzDtwoQAOQvFTtPi1ly0= 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 1565465687879205.4063213745012; Sat, 10 Aug 2019 12:34:47 -0700 (PDT) Received: from localhost ([::1]:37882 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hwX8Y-0005Ua-Rm for importer@patchew.org; Sat, 10 Aug 2019 15:34:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44035) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hwX5z-0000Jn-9p for qemu-devel@nongnu.org; Sat, 10 Aug 2019 15:32:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hwX5x-0007CC-RV for qemu-devel@nongnu.org; Sat, 10 Aug 2019 15:32:07 -0400 Received: from relay.sw.ru ([185.231.240.75]:48776) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hwX5s-00076z-FR; Sat, 10 Aug 2019 15:32:01 -0400 Received: from [10.94.3.0] (helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.92) (envelope-from ) id 1hwX5p-0000nK-Ho; Sat, 10 Aug 2019 22:31:57 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Date: Sat, 10 Aug 2019 22:31:54 +0300 Message-Id: <20190810193155.58637-7-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20190810193155.58637-1-vsementsov@virtuozzo.com> References: <20190810193155.58637-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 v3 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 one cluster. Let backup_cow_with_bounce_buffer behave similarly. It reduces the number of IO requests, since there is no need to copy cluster by cluster. Logic around bounce_buffer allocation changed: we can't just allocate one-cluster-sized buffer to share for all iterations. We can't also allocate buffer of full-request length it may be too large, so BACKUP_MAX_BOUNCE_BUFFER is introduced. And finally, allocation logic is to allocate a buffer sufficient to handle all remaining iterations at the point where we need the buffer for the first time. Bonus: get rid of pointer-to-pointer. Signed-off-by: Vladimir Sementsov-Ogievskiy --- block/backup.c | 65 +++++++++++++++++++++++++++++++------------------- 1 file changed, 41 insertions(+), 24 deletions(-) diff --git a/block/backup.c b/block/backup.c index d482d93458..65f7212c85 100644 --- a/block/backup.c +++ b/block/backup.c @@ -27,6 +27,7 @@ #include "qemu/error-report.h" =20 #define BACKUP_CLUSTER_SIZE_DEFAULT (1 << 16) +#define BACKUP_MAX_BOUNCE_BUFFER (64 * 1024 * 1024) =20 typedef struct CowRequest { int64_t start_byte; @@ -98,44 +99,55 @@ static void cow_request_end(CowRequest *req) qemu_co_queue_restart_all(&req->wait_queue); } =20 -/* Copy range to target with a bounce buffer and return the bytes copied. = If - * error occurred, return a negative error number */ +/* + * Copy range to target with a bounce buffer and return the bytes copied. = If + * error occurred, return a negative error number + * + * @bounce_buffer is assumed to enough to store + * MIN(BACKUP_MAX_BOUNCE_BUFFER, @end - @start) bytes + */ 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) + void *bounce_buffer) { int ret; BlockBackend *blk =3D job->common.blk; - int nbytes; + int nbytes, remaining_bytes; int read_flags =3D is_write_notifier ? BDRV_REQ_NO_SERIALISING : 0; =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); - } + bdrv_reset_dirty_bitmap(job->copy_bitmap, start, end - start); + nbytes =3D MIN(end - start, job->len - start); =20 - 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) { - *error_is_read =3D true; + + remaining_bytes =3D nbytes; + while (remaining_bytes) { + int chunk =3D MIN(BACKUP_MAX_BOUNCE_BUFFER, remaining_bytes); + + ret =3D blk_co_pread(blk, start, chunk, bounce_buffer, read_flags); + if (ret < 0) { + trace_backup_do_cow_read_fail(job, start, ret); + if (error_is_read) { + *error_is_read =3D true; + } + goto fail; } - goto fail; - } =20 - 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); - if (error_is_read) { - *error_is_read =3D false; + ret =3D blk_co_pwrite(job->target, start, chunk, bounce_buffer, + job->write_flags); + if (ret < 0) { + trace_backup_do_cow_write_fail(job, start, ret); + if (error_is_read) { + *error_is_read =3D false; + } + goto fail; } - goto fail; + + start +=3D chunk; + remaining_bytes -=3D chunk; } =20 return nbytes; @@ -301,9 +313,14 @@ static int coroutine_fn backup_do_cow(BackupBlockJob *= job, } } if (!job->use_copy_range) { + if (!bounce_buffer) { + size_t len =3D MIN(BACKUP_MAX_BOUNCE_BUFFER, + MAX(dirty_end - start, end - dirty_end)); + bounce_buffer =3D blk_try_blockalign(job->common.blk, len); + } ret =3D backup_cow_with_bounce_buffer(job, start, dirty_end, is_write_notifier, - error_is_read, &bounce_buf= fer); + error_is_read, bounce_buff= er); } if (ret < 0) { break; --=20 2.18.0 From nobody Thu Mar 28 11:18:20 2024 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=1565465695; cv=none; d=zoho.com; s=zohoarc; b=Dv9V9BRN2zHWbtKW8Sp27OxbpuDISo3ihkPlQkf2xB5TsATQHUZj5vM/42U7Vi2sKRzbQDZrEgOSFh8v8OO+Ak1//Um8NCVuP1lxlTHnphVE8j19xk5R+tVmn8d3rp6dZJ6kmLf7bVY6Z6zBNStBOqyCaT7TyuUV+/rXdluBM8E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565465695; 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=81gpE2uM/FP2XvGJDL3I7iYlmgeZAAQM1wBzSlZzwPI=; b=L3pWNVd7Baz39KSHoyZU7nFIRgB6Q1X7pF+qvPa3wCia3VVNgjFeXXqTD39IceAd7bWrDW+im1sTzyutt3Lc07XYrZBaUlWl+rOWqOBB1NCx+ZppbtqyuPAr7tAC6c3VT2ZTUUlPgmtaFpEkhA1pLQYtCIzhK0rvFhIEAHBfhL0= 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 1565465695005405.97006402230556; Sat, 10 Aug 2019 12:34:55 -0700 (PDT) Received: from localhost ([::1]:37884 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hwX8g-0005ns-0d for importer@patchew.org; Sat, 10 Aug 2019 15:34:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44040) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hwX5z-0000Jw-Bh for qemu-devel@nongnu.org; Sat, 10 Aug 2019 15:32:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hwX5x-0007CM-TX for qemu-devel@nongnu.org; Sat, 10 Aug 2019 15:32:07 -0400 Received: from relay.sw.ru ([185.231.240.75]:48766) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hwX5s-000770-FH; Sat, 10 Aug 2019 15:32:01 -0400 Received: from [10.94.3.0] (helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.92) (envelope-from ) id 1hwX5p-0000nK-RP; Sat, 10 Aug 2019 22:31:57 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Date: Sat, 10 Aug 2019 22:31:55 +0300 Message-Id: <20190810193155.58637-8-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20190810193155.58637-1-vsementsov@virtuozzo.com> References: <20190810193155.58637-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 v3 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 | 97 ++++++++++++++++++++------------------------------ 1 file changed, 38 insertions(+), 59 deletions(-) diff --git a/block/backup.c b/block/backup.c index 65f7212c85..0ac31c2760 100644 --- a/block/backup.c +++ b/block/backup.c @@ -104,87 +104,61 @@ static void cow_request_end(CowRequest *req) * error occurred, return a negative error number * * @bounce_buffer is assumed to enough to store - * MIN(BACKUP_MAX_BOUNCE_BUFFER, @end - @start) bytes + * MIN(BACKUP_MAX_BOUNCE_BUFFER, @bytes) bytes */ -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) +static int coroutine_fn backup_cow_with_bounce_buffer( + BackupBlockJob *job, int64_t offset, int64_t bytes, + BdrvRequestFlags read_flags, bool *error_is_read, void *bounce_buf= fer) { - int ret; BlockBackend *blk =3D job->common.blk; - int nbytes, remaining_bytes; - int read_flags =3D is_write_notifier ? BDRV_REQ_NO_SERIALISING : 0; - - assert(QEMU_IS_ALIGNED(start, job->cluster_size)); - bdrv_reset_dirty_bitmap(job->copy_bitmap, start, end - start); - nbytes =3D MIN(end - start, job->len - start); - =20 - remaining_bytes =3D nbytes; - while (remaining_bytes) { - int chunk =3D MIN(BACKUP_MAX_BOUNCE_BUFFER, remaining_bytes); + while (bytes) { + int ret; + int chunk =3D MIN(BACKUP_MAX_BOUNCE_BUFFER, bytes); =20 - ret =3D blk_co_pread(blk, start, chunk, bounce_buffer, read_flags); + ret =3D blk_co_pread(blk, offset, chunk, 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; + return ret; } =20 - ret =3D blk_co_pwrite(job->target, start, chunk, bounce_buffer, + ret =3D blk_co_pwrite(job->target, offset, chunk, 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; + return ret; } =20 - start +=3D chunk; - remaining_bytes -=3D chunk; + offset +=3D chunk; + bytes -=3D chunk; } =20 - return nbytes; -fail: - bdrv_set_dirty_bitmap(job->copy_bitmap, start, job->cluster_size); - return ret; - + return 0; } =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 /* @@ -268,6 +242,8 @@ static int coroutine_fn backup_do_cow(BackupBlockJob *j= ob, int64_t start, end; /* bytes */ void *bounce_buffer =3D NULL; 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 @@ -281,6 +257,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); @@ -304,10 +281,11 @@ 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; } @@ -315,24 +293,25 @@ static int coroutine_fn backup_do_cow(BackupBlockJob = *job, if (!job->use_copy_range) { if (!bounce_buffer) { size_t len =3D MIN(BACKUP_MAX_BOUNCE_BUFFER, - MAX(dirty_end - start, end - dirty_end)); + MAX(cur_bytes, + end - start - cur_bytes)); bounce_buffer =3D blk_try_blockalign(job->common.blk, len); } - ret =3D backup_cow_with_bounce_buffer(job, start, dirty_end, - is_write_notifier, - error_is_read, bounce_buff= er); + ret =3D backup_cow_with_bounce_buffer(job, start, cur_bytes, + read_flags, error_is_read, + bounce_buffer); } 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 if (bounce_buffer) { --=20 2.18.0