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 From: Sam Eiderman Date: Thu, 2 May 2019 11:50:29 +0300 Message-Id: <20190502085029.30776-4-shmuel.eiderman@oracle.com> In-Reply-To: <20190502085029.30776-1-shmuel.eiderman@oracle.com> References: <20190502085029.30776-1-shmuel.eiderman@oracle.com> Subject: [Qemu-devel] [PATCH 3/3] qemu-img: rebase: Reuse in-chain BlockDriverState List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: kwolf@redhat.com, mreitz@redhat.com, qemu-block@nongnu.org, qemu-devel@nongnu.org Cc: shmuel.eiderman@oracle.com, eyal.moscovici@oracle.com, sagi.amit@oracle.com, karl.heubaum@oracle.com, liran.alon@oracle.com, arbel.moshe@oracle.com 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 = 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 = bdrv_find_backing_image(bs, out_real_path); - - blk_new_backing = 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 = -1; - goto out; + if (prefix_chain_bs) { + blk_new_backing = blk_new(BLK_PERM_CONSISTENT_READ, + BLK_PERM_ALL); + ret = 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 = 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 = -1; + goto out; + } } } } -- 2.13.3