From nobody Wed Nov 12 04:59:46 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