From nobody Thu Dec 18 17:51:54 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1559072518; cv=none; d=zoho.com; s=zohoarc; b=jCbPMipVQL0pNNPQGBXd0SKtayoLypdC+tujQmdhYgL7hMSrwr+wN8JM7c8JPeS6bDs9Z7r8LFyzejcHhDTekSdDhh4LA10hRuryxaBfJmqThWJS9iuue4vDbHhHtd3asSuPq8MrwlbEkN7HYHzwh9nb5hvLQtm3DzMycRNUadE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559072518; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=qTIWdZbZrn+zulzy55gIkl1Iy2pXqdm4ff7CpGk4qhg=; b=QUhxJnkLcisdyhJWbHIBs8n2CE1hmenkin/aRL/n/mN55PCBFEwzAfAl7hdXF4v8T/LLgcZZCLKOnECokYGA8A+FAFiIAZWyHg8MTcGddFOxJfoabBsTowX3DO/M4UassbKqLWk/+6NgLzU+nJ6p9eaoY64kyIfdnK0iC7zAjWA= 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 1559072518991163.68763729166915; Tue, 28 May 2019 12:41:58 -0700 (PDT) Received: from localhost ([127.0.0.1]:41673 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hVhyt-0001zE-EM for importer@patchew.org; Tue, 28 May 2019 15:41:55 -0400 Received: from eggs.gnu.org ([209.51.188.92]:37105) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hVhoP-0001sI-3O for qemu-devel@nongnu.org; Tue, 28 May 2019 15:31:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hVhoH-0002Bq-7h for qemu-devel@nongnu.org; Tue, 28 May 2019 15:31:00 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42314) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hVho2-00017U-L5; Tue, 28 May 2019 15:30:44 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9C8CF300CA9A; Tue, 28 May 2019 19:29:42 +0000 (UTC) Received: from localhost (unknown [10.40.205.223]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3087A60C47; Tue, 28 May 2019 19:29:39 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Tue, 28 May 2019 21:28:44 +0200 Message-Id: <20190528192847.2730-19-mreitz@redhat.com> In-Reply-To: <20190528192847.2730-1-mreitz@redhat.com> References: <20190528192847.2730-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Tue, 28 May 2019 19:29:42 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 18/21] 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: Kevin Wolf , Peter Maydell , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Sam Eiderman 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 Message-id: 20190523163337.4497-4-shmuel.eiderman@oracle.com Signed-off-by: Max Reitz --- qemu-img.c | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 2d96a491e2..b0535919b1 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -3358,16 +3358,29 @@ 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) { + g_free(out_real_path); + 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.21.0