From nobody Tue May 7 13:56:43 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1491564916597222.4266553495022; Fri, 7 Apr 2017 04:35:16 -0700 (PDT) Received: from localhost ([::1]:50254 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cwSAd-0007QJ-6B for importer@patchew.org; Fri, 07 Apr 2017 07:35:15 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36770) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cwS9f-0006xb-2T for qemu-devel@nongnu.org; Fri, 07 Apr 2017 07:34:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cwS9e-0002tO-90 for qemu-devel@nongnu.org; Fri, 07 Apr 2017 07:34:15 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:29070 helo=relay.sw.ru) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cwS9Z-0002rz-Kj; Fri, 07 Apr 2017 07:34:09 -0400 Received: from kvm.sw.ru (msk-vpn.virtuozzo.com [195.214.232.6]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id v37BY4M2024676; Fri, 7 Apr 2017 14:34:05 +0300 (MSK) From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Fri, 7 Apr 2017 14:34:04 +0300 Message-Id: <20170407113404.9351-1-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.11.1 X-detected-operating-system: by eggs.gnu.org: OpenBSD 3.x [fuzzy] X-Received-From: 195.214.232.25 Subject: [Qemu-devel] [PATCH] qemu-img: improve convert_iteration_sectors() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, den@openvz.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Do not do extra call to _get_block_status() Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: John Snow --- Also, I'm not sure about last line: s->status =3D s->target_has_backing ? BLK_BACKING_FILE : BLK_DATA; (which is equal to old code) may be, it should be s->status =3D s->target_has_backing ? BLK_BACKING_FILE : BLK_ZERO; as it is the case, when range is not allocated at all. Should we copy it in= this case? qemu-img.c | 32 ++++++++++---------------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index b220cf71d7..490f6e97f6 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -1554,9 +1554,15 @@ static int convert_iteration_sectors(ImgConvertState= *s, int64_t sector_num) =20 if (s->sector_next_status <=3D sector_num) { BlockDriverState *file; - ret =3D bdrv_get_block_status(blk_bs(s->src[src_cur]), - sector_num - src_cur_offset, - n, &n, &file); + if (s->target_has_backing) { + ret =3D bdrv_get_block_status(blk_bs(s->src[src_cur]), + sector_num - src_cur_offset, + n, &n, &file); + } else { + ret =3D bdrv_get_block_status_above(blk_bs(s->src[src_cur]), N= ULL, + sector_num - src_cur_offset, + n, &n, &file); + } if (ret < 0) { return ret; } @@ -1565,26 +1571,8 @@ static int convert_iteration_sectors(ImgConvertState= *s, int64_t sector_num) s->status =3D BLK_ZERO; } else if (ret & BDRV_BLOCK_DATA) { s->status =3D BLK_DATA; - } else if (!s->target_has_backing) { - /* Without a target backing file we must copy over the content= s of - * the backing file as well. */ - /* Check block status of the backing file chain to avoid - * needlessly reading zeroes and limiting the iteration to the - * buffer size */ - ret =3D bdrv_get_block_status_above(blk_bs(s->src[src_cur]), N= ULL, - sector_num - src_cur_offset, - n, &n, &file); - if (ret < 0) { - return ret; - } - - if (ret & BDRV_BLOCK_ZERO) { - s->status =3D BLK_ZERO; - } else { - s->status =3D BLK_DATA; - } } else { - s->status =3D BLK_BACKING_FILE; + s->status =3D s->target_has_backing ? BLK_BACKING_FILE : BLK_D= ATA; } =20 s->sector_next_status =3D sector_num + n; --=20 2.11.1