From nobody Mon Feb 9 22:04:15 2026 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; dkim=fail; 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=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1558629359; cv=none; d=zoho.com; s=zohoarc; b=Gg7xzyetbmPoaLs3Wu9AUw5Kv+RL01LrfgwA2AhQt3FRX4aSevbew80SvgkztAg2/E5F3U9PT+QOjyHPn6MoJlvYxPkkOcAmIa4KlS1YiD+YZ/0Q+vXDlnyyAD51QRgnrlk+JIL+YqZgkiPayh95HfDNIYOssxHoHx1WdFfuxuQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1558629359; 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=ud4KqU+M+aj77AvMEO2QAvfX1xgBXAKGcMA9RsIp7Vc=; b=lIZG5XBkLkeFlixqIVduYK1aSapsG/gccnqXIlAUoxWjdBJwS8WNINItf0+3Z/OohWalpeiJizBeFPLFxzDroQ6Vz05ogMGw5ihBLu28dsFV1fb+gmL2zBODYIDHmY1ZvQ8qNlNot2R0pCjRLfne5bhiAyp2zp0q2gPey4UuPOI= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; 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 (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1558629359596526.7813291036116; Thu, 23 May 2019 09:35:59 -0700 (PDT) Received: from localhost ([127.0.0.1]:40475 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTqh1-0004Jm-3l for importer@patchew.org; Thu, 23 May 2019 12:35:47 -0400 Received: from eggs.gnu.org ([209.51.188.92]:41780) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTqfJ-00037M-TA for qemu-devel@nongnu.org; Thu, 23 May 2019 12:34:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hTqfI-0000mV-Q0 for qemu-devel@nongnu.org; Thu, 23 May 2019 12:34:01 -0400 Received: from aserp2130.oracle.com ([141.146.126.79]:52906) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hTqfE-0000jG-V9; Thu, 23 May 2019 12:33:57 -0400 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x4NGTV09132630; Thu, 23 May 2019 16:33:55 GMT Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by aserp2130.oracle.com with ESMTP id 2smsk5km3f-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 23 May 2019 16:33:55 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x4NGW71A182570; Thu, 23 May 2019 16:33:55 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserp3020.oracle.com with ESMTP id 2smsh2bvq5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 23 May 2019 16:33:55 +0000 Received: from abhmp0001.oracle.com (abhmp0001.oracle.com [141.146.116.7]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x4NGXtfi006082; Thu, 23 May 2019 16:33:55 GMT Received: from nexus.ravello.local (/213.57.127.2) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 23 May 2019 16:33:54 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2018-07-02; bh=ud4KqU+M+aj77AvMEO2QAvfX1xgBXAKGcMA9RsIp7Vc=; b=TMJiLS4eKhN+th8Mv60ow4GySI/ZOM3kdZZTdJBtVIIbWwpOmD0NjzRhQ4bhx2nEYHK0 UwZwrsGOozMhnlcfmosKb2y9U+N6OXhi25PNdRKptmJKlbKRhfOUf4ePpwQL6izFXE4A O7uYk1zUK+pqoaHpLRlEf2qKHYAMflsa5NSCpWGLhKMZuIk5MfvH4l3aM3C4JjOqvsoO 8W2+dNQmU0BJoCxXbgRt6nuyGUbDAqS738VqsaO7i8QBLBQQnRQM3ZArLsUhIFya8E+H j1LO9DMhFSZYjIQkcgbvBf09W09zK58QeGBleKI2cpYw7pGchHEmr6+d9IH/Qrmn/25n eA== From: Sam Eiderman To: kwolf@redhat.com, qemu-block@nongnu.org, qemu-devel@nongnu.org, mreitz@redhat.com Date: Thu, 23 May 2019 19:33:36 +0300 Message-Id: <20190523163337.4497-3-shmuel.eiderman@oracle.com> X-Mailer: git-send-email 2.13.3 In-Reply-To: <20190523163337.4497-1-shmuel.eiderman@oracle.com> References: <20190523163337.4497-1-shmuel.eiderman@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9265 signatures=668687 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=2 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=959 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1905230112 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9265 signatures=668687 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=2 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=997 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1905230112 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 141.146.126.79 Subject: [Qemu-devel] [PATCH v5 2/3] qemu-img: rebase: Reduce reads on in-chain rebase 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: eyal.moscovici@oracle.com, arbel.moshe@oracle.com, liran.alon@oracle.com, shmuel.eiderman@oracle.com, sagi.amit@oracle.com, karl.heubaum@oracle.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" In the following case: (base) A <- B <- C (tip) when running: qemu-img rebase -b A C QEMU would read all sectors not allocated in the file being rebased (C) and compare them to the new base image (A), regardless of whether they were changed or even allocated anywhere along the chain between the new base and the top image (B). This causes many unneeded reads when rebasing an image which represents a small diff of a large disk, as it would read most of the disk's sectors. Instead, use bdrv_is_allocated_above() to reduce the number of unnecessary reads. Reviewed-by: Karl Heubaum Signed-off-by: Sam Eiderman Signed-off-by: Eyal Moscovici --- qemu-img.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/qemu-img.c b/qemu-img.c index 9bd0bb1e47..2d96a491e2 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -3164,7 +3164,7 @@ static int img_rebase(int argc, char **argv) BlockBackend *blk =3D NULL, *blk_old_backing =3D NULL, *blk_new_backin= g =3D NULL; uint8_t *buf_old =3D NULL; uint8_t *buf_new =3D NULL; - BlockDriverState *bs =3D NULL; + BlockDriverState *bs =3D NULL, *prefix_chain_bs =3D NULL; char *filename; const char *fmt, *cache, *src_cache, *out_basefmt, *out_baseimg; int c, flags, src_flags, ret; @@ -3353,6 +3353,12 @@ static int img_rebase(int argc, char **argv) goto out; } =20 + /* + * Find out whether we rebase an image on top of a previous im= age + * in its chain. + */ + prefix_chain_bs =3D bdrv_find_backing_image(bs, out_real_path); + blk_new_backing =3D blk_new_open(out_real_path, NULL, options, src_flags, &local_err); g_free(out_real_path); @@ -3437,6 +3443,23 @@ static int img_rebase(int argc, char **argv) continue; } =20 + if (prefix_chain_bs) { + /* + * If cluster wasn't changed since prefix_chain, we don't = need + * to take action + */ + ret =3D bdrv_is_allocated_above(backing_bs(bs), prefix_cha= in_bs, + offset, n, &n); + if (ret < 0) { + error_report("error while reading image metadata: %s", + strerror(-ret)); + goto out; + } + if (!ret) { + continue; + } + } + /* * Read old and new backing file and take into consideration t= hat * backing files may be smaller than the COW image. --=20 2.13.3