From nobody Thu May 16 06:18:29 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; 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=1556787354; cv=none; d=zoho.com; s=zohoarc; b=YlQekgwVrdiWoxYJp6EV097RoxE28KZeYEo80f9AgGGAWsR+yxOSvpq8pVpBwggwJeLTFp6Dmhp5i5Ghauys6G0G30Z6Fxlja1BLbzW+FjE2tGxU0c++NBSPlcqdnuqQvxguAW6/clL/4AIO0XHmqo8CRHMBkYY75ZoeAaGa5S0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1556787354; 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=9ccw3z6s2hPMEok4793CteM3gasxj/Ia2H+u0wiDWIc=; b=nVmY0REyjUSO3VIblS4xr5vD3KC/rfhX3swJMQ52+nNM3wYyewvDiM4xSDBbA2F7mAqD37VjOaAGHeTyl9Glm9xF38+CI288BX4fmvVDQWaqLi48fjbCaA8GlMpyqSBhGDezDAnLV0LBMYBniinLnBi0R6JhQB513KXjCJ1f9dE= 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 (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1556787354794741.8592057025684; Thu, 2 May 2019 01:55:54 -0700 (PDT) Received: from localhost ([127.0.0.1]:47819 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hM7VO-0004yO-JK for importer@patchew.org; Thu, 02 May 2019 04:55:50 -0400 Received: from eggs.gnu.org ([209.51.188.92]:52021) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hM7R5-0000WS-RV for qemu-devel@nongnu.org; Thu, 02 May 2019 04:51:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hM7R4-0000ZJ-HX for qemu-devel@nongnu.org; Thu, 02 May 2019 04:51:23 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:58396) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hM7R1-0000Ao-GA; Thu, 02 May 2019 04:51:19 -0400 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x428nmlX190140; Thu, 2 May 2019 08:50:59 GMT Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by userp2120.oracle.com with ESMTP id 2s6xhyq56y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 02 May 2019 08:50:59 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x428okYN186684; Thu, 2 May 2019 08:50:58 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserp3030.oracle.com with ESMTP id 2s7rtbksfy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 02 May 2019 08:50:58 +0000 Received: from abhmp0018.oracle.com (abhmp0018.oracle.com [141.146.116.24]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x428ovtc006722; Thu, 2 May 2019 08:50:57 GMT Received: from nexus.ravello.local (/213.57.127.2) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 02 May 2019 01:50:56 -0700 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=9ccw3z6s2hPMEok4793CteM3gasxj/Ia2H+u0wiDWIc=; b=ZlWXilddp5nYadHxRHXjtvDEaSN2eTD/wEuMzZQBg0+i/W+nvOsQiHJ8yTYMKWr8KKl0 P0b3pueeVGl+u/tfMEHmAk1A9V1nTV8i2JA6cLDjIeJ9kq6szXxqm50lTmwh+5qKcwfI lbc40kgklq5Wapzg7nB3w9OyVz6NlsAOmPEXAyJbwegPED97z8vITkFrC0kTWC6Ovk3x EgBOzNBymZtd7u7h72DRr+HLcVKOzYjKCVFJ4BB4KImXugMrw3t7uEIT6aek4oq0bHTJ /USQMUL22k3raPytHYXEM3+moIYTHmw2CMLZj1JzyDmpYZmrfCcZXz+isxJVh7BoYgc4 5g== From: Sam Eiderman To: kwolf@redhat.com, mreitz@redhat.com, qemu-block@nongnu.org, qemu-devel@nongnu.org Date: Thu, 2 May 2019 11:50:27 +0300 Message-Id: <20190502085029.30776-2-shmuel.eiderman@oracle.com> X-Mailer: git-send-email 2.13.3 In-Reply-To: <20190502085029.30776-1-shmuel.eiderman@oracle.com> References: <20190502085029.30776-1-shmuel.eiderman@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9244 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=963 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1905020067 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9244 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=983 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1905020067 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 156.151.31.85 Subject: [Qemu-devel] [PATCH 1/3] qemu-img: rebase: Reuse parent BlockDriverState 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 safe mode we open the entire chain, including the parent backing file of the rebased file. Do not open a new BlockBackend for the parent backing file, which saves opening the rest of the chain twice, which for long chains saves many "pricy" bdrv_open() calls. Permissions for blk_new() were copied from blk_new_open() when flags =3D 0. Reviewed-by: Karl Heubaum Reviewed-by: Eyal Moscovici Signed-off-by: Sagi Amit Co-developed-by: Sagi Amit Signed-off-by: Sam Eiderman --- qemu-img.c | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 8ee63daeae..d9b609b3f0 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -3297,28 +3297,23 @@ static int img_rebase(int argc, char **argv) =20 /* For safe rebasing we need to compare old and new backing file */ if (!unsafe) { - char backing_name[PATH_MAX]; QDict *options =3D NULL; + BlockDriverState *base_bs =3D backing_bs(bs); =20 - if (bs->backing_format[0] !=3D '\0') { - options =3D qdict_new(); - qdict_put_str(options, "driver", bs->backing_format); + if (!base_bs) { + error_setg(&local_err, "Image does not have a backing file"); + ret =3D -1; + goto out; } =20 - if (force_share) { - if (!options) { - options =3D qdict_new(); - } - qdict_put_bool(options, BDRV_OPT_FORCE_SHARE, true); - } - bdrv_get_backing_filename(bs, backing_name, sizeof(backing_name)); - blk_old_backing =3D blk_new_open(backing_name, NULL, - options, src_flags, &local_err); - if (!blk_old_backing) { + blk_old_backing =3D blk_new(BLK_PERM_CONSISTENT_READ, + BLK_PERM_ALL); + ret =3D blk_insert_bs(blk_old_backing, base_bs, + &local_err); + if (ret < 0) { error_reportf_err(local_err, - "Could not open old backing file '%s': ", - backing_name); - ret =3D -1; + "Could not reuse old backing file '%s': ", + base_bs->filename); goto out; } =20 --=20 2.13.3 From nobody Thu May 16 06:18:29 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; 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=1556787379; cv=none; d=zoho.com; s=zohoarc; b=HApezUGaG+WB7iHZ9/2jJhkAONoxmzaN2okRG6VMEJ6m9JQ02SmFuisYhUASXUOGPeGnS5O4ovt6MRlD5HcWP9f++ADhnAPyzltV52CFXvcq27vgmrDGe/6gnlQpqndoE6sn6/z6klFK/znkxuGKgsPXtV6e0sl8+EwhvMpAaf8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1556787379; 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=+GmqDTr4A0b+4arMEn7WVVZ2pJzJXgiEeewztayhFGY=; b=ltgYPgGPVAFH9YZqSuKWl27fzThiFtCSSiK8Jw0BgJw77dmbicNtAOThxvGWrqXE7W1E+8fOOyK1XTgCXQiw5t5itaabx0Zk4L1d6vK0V1Hm07yTzjbcQZ8HPiKHhEJ4STc5b7LGGZLRrS1IB5JukHgGyinYYMHPU1n2a9fiZhI= 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 (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1556787379976156.39863624386214; Thu, 2 May 2019 01:56:19 -0700 (PDT) Received: from localhost ([127.0.0.1]:47843 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hM7Vo-0005KO-Uf for importer@patchew.org; Thu, 02 May 2019 04:56:16 -0400 Received: from eggs.gnu.org ([209.51.188.92]:52589) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hM7Ss-0002we-RI for qemu-devel@nongnu.org; Thu, 02 May 2019 04:53:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hM7Sr-0002Ws-72 for qemu-devel@nongnu.org; Thu, 02 May 2019 04:53:14 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:34282) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hM7Sl-0002Kt-F6; Thu, 02 May 2019 04:53:09 -0400 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x428oHM7170259; Thu, 2 May 2019 08:53:00 GMT Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2130.oracle.com with ESMTP id 2s6xhyf62k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 02 May 2019 08:53:00 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x428nlTr003329; Thu, 2 May 2019 08:51:00 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userp3030.oracle.com with ESMTP id 2s7p89namm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 02 May 2019 08:51:00 +0000 Received: from abhmp0018.oracle.com (abhmp0018.oracle.com [141.146.116.24]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x428oxhh025956; Thu, 2 May 2019 08:50:59 GMT Received: from nexus.ravello.local (/213.57.127.2) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 02 May 2019 01:50:59 -0700 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=+GmqDTr4A0b+4arMEn7WVVZ2pJzJXgiEeewztayhFGY=; b=JA62vR26nAj5wJCIE+xE4yk2KWyZJ1CwW6gifcThKiQXkBYzI1FnNLEFok6B+Pu+vAsX qfBgDsM69HhtSpKfwywnhrlgDFZ/hEF2TrL+7BtB3y/FWjA92Sn5NKy2ywVuhd4v1Vjs c3v+OyDFtpTvQurszO4CSIvXkVKmm777ox3UZRrUD8LFxaBV3q9FWTkaSWxJzlip/lBN IJir/wZ8P2GHQAey1GAUqDBOm2oXE1KrU8hoIdOFuOo9GypSSxsClxkv/bljcPwKdP++ fKSA3JimlhCqXCL8Xm7119MdWvKqdGbPCWZ16pmuteK3YA3EBywrPh2cIra2NmDY1OLI vA== From: Sam Eiderman To: kwolf@redhat.com, mreitz@redhat.com, qemu-block@nongnu.org, qemu-devel@nongnu.org Date: Thu, 2 May 2019 11:50:28 +0300 Message-Id: <20190502085029.30776-3-shmuel.eiderman@oracle.com> X-Mailer: git-send-email 2.13.3 In-Reply-To: <20190502085029.30776-1-shmuel.eiderman@oracle.com> References: <20190502085029.30776-1-shmuel.eiderman@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9244 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=2 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=995 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1905020067 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9244 signatures=668685 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=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1905020067 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 156.151.31.86 Subject: [Qemu-devel] [PATCH 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 d9b609b3f0..7f20858cb9 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -3152,7 +3152,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; @@ -3343,6 +3343,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); @@ -3422,6 +3428,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(bs, prefix_chain_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 From nobody Thu May 16 06:18:29 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; 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=1556787430; cv=none; d=zoho.com; s=zohoarc; b=MlzgUv4W2/CkdUwcWmGvm5/0ECAIPDo7SqhItVdHTEZ2dEo8sL/qA4TxTUUqlmt9bejHO9KfaqyrYSVHRlCAVPhbqHpI0Bmt1ndoL66/nHVrp85NWMnFn5b70zkdUFnnHF5F/pqWJudQSLBXxW5VV8lbuRXtmmFEAGcw9zqeEtE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1556787430; 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=OhNujW0uUPrsvhY2jFpWhGkBGbqlUe3einP1bk6MFDM=; b=Q4ppCXgHwqPHEuH/rsC3axxMuuifJgyU3bUBpz5q51uiP0C613zP639EkGB3dOOZCT7/zUs2cuGhwq0KIm+HYm1roo/EYqay5udsiijl+RAtvAcZdmdX7MkAJFaKDv23/1kRNMS7M+X4GUcsIUTGaI7EvSBmGf4Pqdk6E2KOzqE= 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 (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1556787430835501.82286755446546; Thu, 2 May 2019 01:57:10 -0700 (PDT) Received: from localhost ([127.0.0.1]:47856 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hM7Wa-00064x-QX for importer@patchew.org; Thu, 02 May 2019 04:57:04 -0400 Received: from eggs.gnu.org ([209.51.188.92]:52022) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hM7R5-0000WW-Ro for qemu-devel@nongnu.org; Thu, 02 May 2019 04:51:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hM7R4-0000ZN-HJ for qemu-devel@nongnu.org; Thu, 02 May 2019 04:51:23 -0400 Received: from aserp2130.oracle.com ([141.146.126.79]:55314) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hM7R1-0000Do-9l; Thu, 02 May 2019 04:51:19 -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 x428na14177565; Thu, 2 May 2019 08:51:03 GMT Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by aserp2130.oracle.com with ESMTP id 2s6xhyf4mm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 02 May 2019 08:51:03 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x428olAP186783; Thu, 2 May 2019 08:51:03 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserp3030.oracle.com with ESMTP id 2s7rtbksgx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 02 May 2019 08:51:02 +0000 Received: from abhmp0018.oracle.com (abhmp0018.oracle.com [141.146.116.24]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x428p18m006758; Thu, 2 May 2019 08:51:01 GMT Received: from nexus.ravello.local (/213.57.127.2) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 02 May 2019 01:51:01 -0700 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=OhNujW0uUPrsvhY2jFpWhGkBGbqlUe3einP1bk6MFDM=; b=ujSW3wW5HwfZcTysfDz5wx4Qi8ln7PB9KZcPVpj+tFvmj4Fo17yPbIbRpEPnvo1e0GF0 OzA77GhNrNgkSeMtDJpk4JE+9+rtaxRs7CmAndDxOWpMLb7F/ovrJ/bY6U3LS42Vkzpl wG/pq79DceZmyxvDZlb4mjNZnPhPNWK9sUTLmV8bPIVedKubnIchqake1VpSvQt5JjX9 Ysg7oG/V8AniVSK8G+i4ZC5IC0HaRH2TuZJzNBHV5kH8NX2kmALtHIRwngqdUyUIXqlW DVuEZgK4JYl+U/XM17Mp4HltED3YnFHlGghWDbZ0wJgX3/8QGGL4W7eT9sRJKk93/9vZ nw== From: Sam Eiderman To: kwolf@redhat.com, mreitz@redhat.com, qemu-block@nongnu.org, qemu-devel@nongnu.org Date: Thu, 2 May 2019 11:50:29 +0300 Message-Id: <20190502085029.30776-4-shmuel.eiderman@oracle.com> X-Mailer: git-send-email 2.13.3 In-Reply-To: <20190502085029.30776-1-shmuel.eiderman@oracle.com> References: <20190502085029.30776-1-shmuel.eiderman@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9244 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=2 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1905020067 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9244 signatures=668685 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=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1905020067 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 141.146.126.79 Subject: [Qemu-devel] [PATCH 3/3] qemu-img: rebase: Reuse in-chain BlockDriverState 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" If a chain was detected, don't open a new BlockBackend from the target backing file which will create a new BlockDriverState. Instead, create an empty BlockBackend and attach the already open BlockDriverState. Permissions for blk_new() were copied from blk_new_open() when flags =3D 0. Reviewed-by: Karl Heubaum Reviewed-by: Eyal Moscovici Signed-off-by: Sagi Amit Co-developed-by: Sagi Amit Signed-off-by: Sam Eiderman --- qemu-img.c | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 7f20858cb9..970cd9bf63 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -3348,16 +3348,28 @@ static int img_rebase(int argc, char **argv) * 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); - if (!blk_new_backing) { - error_reportf_err(local_err, - "Could not open new backing file '%s': ", - out_baseimg); - ret =3D -1; - goto out; + if (prefix_chain_bs) { + blk_new_backing =3D blk_new(BLK_PERM_CONSISTENT_READ, + BLK_PERM_ALL); + ret =3D blk_insert_bs(blk_new_backing, prefix_chain_bs, + &local_err); + if (ret < 0) { + error_reportf_err(local_err, + "Could not reuse backing file '%s': = ", + out_baseimg); + goto out; + } + } else { + blk_new_backing =3D blk_new_open(out_real_path, NULL, + options, src_flags, &local_= err); + g_free(out_real_path); + if (!blk_new_backing) { + error_reportf_err(local_err, + "Could not open new backing file '%s= ': ", + out_baseimg); + ret =3D -1; + goto out; + } } } } --=20 2.13.3