From nobody Fri May 3 03:10:14 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=1558620396; cv=none; d=zoho.com; s=zohoarc; b=YkKeGCpqDZGtR/Pgdf/W4BC301lxqW6GD/RjcKdJ0z2Pfew9U9HXgEW+jtEsuzXbN41OPrSOYt4Ru1KUBdFM+SXjYf0JDvl3b95q02zWI9wa03S9ejgo1oA4tSRZT1kqxrxPnJH/1RoUL2ggPMY4AsuFtRPFg4nBEzLba41wXs4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1558620396; 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=oYQNiLLInCaatn1i0R555HgKyXewzttIoWAlCHlEROk=; b=l0wn2g8ofNgrOmeFvko+pnmXwF72Ty4Cos8vWo9xfGhg6PjS97l7RvpAzT54WicKr3Hu+nEGy9t1sARLWggxSTcj4lvMzgEYdAqm1mCGJMDXumUIGbn3KGIhBPSUOUH67szl9SR7BHUhEM2FITL8TE2jYyx/y9l8c3okDLTHpaI= 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 1558620396604730.5386787027473; Thu, 23 May 2019 07:06:36 -0700 (PDT) Received: from localhost ([127.0.0.1]:37019 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hToMX-0001Lc-Iy for importer@patchew.org; Thu, 23 May 2019 10:06:29 -0400 Received: from eggs.gnu.org ([209.51.188.92]:44373) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTo93-0008RZ-IG for qemu-devel@nongnu.org; Thu, 23 May 2019 09:52:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hTo92-0007Ug-GO for qemu-devel@nongnu.org; Thu, 23 May 2019 09:52:33 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:51932) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hTo8z-0007OC-Vx; Thu, 23 May 2019 09:52:30 -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 x4NDhRJk167055; Thu, 23 May 2019 13:52:27 GMT Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by userp2120.oracle.com with ESMTP id 2smsk5afks-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 23 May 2019 13:52:27 +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 x4NDpa7i079268; Thu, 23 May 2019 13:52:27 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserp3030.oracle.com with ESMTP id 2smsgt8ks4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 23 May 2019 13:52:26 +0000 Received: from abhmp0012.oracle.com (abhmp0012.oracle.com [141.146.116.18]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x4NDqPjs029408; Thu, 23 May 2019 13:52:25 GMT Received: from nexus.ravello.local (/213.57.127.2) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 23 May 2019 13:52:25 +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=oYQNiLLInCaatn1i0R555HgKyXewzttIoWAlCHlEROk=; b=UZnSfD89x93Bgv7P5dkLADiSDOITXblJYBLYN7sBHMg0rpQWj2r0jYtT0ZM9mT+zo1zE gKC0IKxiYiB/cuDjIpM3uyaQBm70STZuinhKA140sNUg+vjF7hz8ARL+LbT0SxV8b5Rs Ys6BDQpndXF1Yk3PKc1DzfGkusolVB6tD6IwC/x7mzjDN10jzJCvLX0iXFQLsUovpeWu YPd46b7DXcjgKTyE9iLhi+rTCzw00NuRw7Vw09u16cEHBErsTy0D5Tk+e8RVFXv7qjNa EEebqBr/KXw0kr+w93rwewJxC+EJS4hu+Rw8lBRiFea4mOA+OHt2wwWgG2ESjJTrWQ1Q Zw== From: Sam Eiderman To: kwolf@redhat.com, qemu-block@nongnu.org, qemu-devel@nongnu.org, mreitz@redhat.com Date: Thu, 23 May 2019 16:51:37 +0300 Message-Id: <20190523135139.2147-2-shmuel.eiderman@oracle.com> X-Mailer: git-send-email 2.13.3 In-Reply-To: <20190523135139.2147-1-shmuel.eiderman@oracle.com> References: <20190523135139.2147-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=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=928 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1905230096 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=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=957 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1905230096 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 156.151.31.85 Subject: [Qemu-devel] [PATCH v3 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, 9 insertions(+), 20 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 28fba1e7a7..9bd0bb1e47 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -3309,29 +3309,18 @@ 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) { - if (bs->backing_format[0] !=3D '\0') { - options =3D qdict_new(); - qdict_put_str(options, "driver", bs->backing_format); - } - - 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_nam= e)); - blk_old_backing =3D blk_new_open(backing_name, NULL, - options, src_flags, &local_err); - if (!blk_old_backing) { + if (base_bs) { + 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; } } else { --=20 2.13.3 From nobody Fri May 3 03:10:14 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=1558620245; cv=none; d=zoho.com; s=zohoarc; b=EK9PJGnb/oPRpW9nl4E85eaJ++zi1wDGawoBYjUGAN0S0pYfly5dGsIuCD+8qxmAzWYJROWDUM5jiTjNyij+miOJpinIWqbDOPfD82Xttar3awVrBAirMwW9IkPBPNoA3DFA3Dui/XTHDecU0UCokEG/wVuAUWIQEwko3/BiHxs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1558620245; 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=VQn+8g7OVSHfojIXASPlc8b/d32RkbBUIb4er9L8jgw=; b=f/YktGrKl6NAqjJVkiwd/rKwXhcXrjILGqIS7js+rdAMTHl5veKcLK488rYD6UGk1l+vqselx2gMDZoAm8GBNZmBDfp+3JVX9BQeDRlSEEfXHLmRGVk/l+muxcheEeDdLJESiqtbGDa6iFZqpx4jasMuGvO4BB9u1VYtTGx4Lmc= 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 1558620245611113.65051584478738; Thu, 23 May 2019 07:04:05 -0700 (PDT) Received: from localhost ([127.0.0.1]:36961 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hToJI-00079p-ML for importer@patchew.org; Thu, 23 May 2019 10:03:08 -0400 Received: from eggs.gnu.org ([209.51.188.92]:44369) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTo93-0008RW-Gu for qemu-devel@nongnu.org; Thu, 23 May 2019 09:52:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hTo92-0007UZ-F2 for qemu-devel@nongnu.org; Thu, 23 May 2019 09:52:33 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:44930) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hTo8z-0007P2-RU; Thu, 23 May 2019 09:52:30 -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 x4NDhRsW155156; Thu, 23 May 2019 13:52:29 GMT Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2130.oracle.com with ESMTP id 2smsk5jfb6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 23 May 2019 13:52:28 +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 x4NDp78Y014825; Thu, 23 May 2019 13:52:28 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userp3030.oracle.com with ESMTP id 2smshf8ewr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 23 May 2019 13:52:28 +0000 Received: from abhmp0012.oracle.com (abhmp0012.oracle.com [141.146.116.18]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x4NDqRQa029436; Thu, 23 May 2019 13:52:27 GMT Received: from nexus.ravello.local (/213.57.127.2) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 23 May 2019 13:52:27 +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=VQn+8g7OVSHfojIXASPlc8b/d32RkbBUIb4er9L8jgw=; b=1Itaga0PnsWNwlcwbRzwi4WrC9/hF5M7Fjm4QgJBDcBA5u34R8yuEifyLC05YPL5eAGw cJ0hTMbUjk0yKa15i6fAMBbdjgOUidj2YxLPOd2rYOecR12UpIiKsXbUkHj0CSlquJRM B8Mpp+KIkrIbL4vtjAgGaxx8BVMqqj0KXMp3Qkiq/n+PNo1UjocT+UvQ+VDKGCIKyLUd TVqNd7tVnQgHX60Na9Jetc5m5I66RTSaDw5rQBgJmthKzxTisORhkoVXwJ4jAVEp8Mhi TQW6DYKLB2StzCt5G5dkxki+1gz4W5curc1X+uSOMOvekpvhZz2iC6u4gAJiQG/1FkQ/ cA== From: Sam Eiderman To: kwolf@redhat.com, qemu-block@nongnu.org, qemu-devel@nongnu.org, mreitz@redhat.com Date: Thu, 23 May 2019 16:51:38 +0300 Message-Id: <20190523135139.2147-3-shmuel.eiderman@oracle.com> X-Mailer: git-send-email 2.13.3 In-Reply-To: <20190523135139.2147-1-shmuel.eiderman@oracle.com> References: <20190523135139.2147-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=961 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1905230096 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=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1905230096 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 156.151.31.86 Subject: [Qemu-devel] [PATCH v3 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..e6fd8e1a98 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(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 Fri May 3 03:10:14 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=1558619948; cv=none; d=zoho.com; s=zohoarc; b=fUR8TCKESwtyiPfWz8ZG+hdVN7eJXg4cH85HhuRfZiNVbmauHyS/Dy6FIRT8ebOIJoauU39zgu2KcvN3XPwP2kp2H/zCTflGItZVFpczlzMCM1GY39uY408gxFNt7dGetvRl4IklHRDLaWIbL6Djr/D7qFHYZVlooR8pa7MA9YI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1558619948; 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=qe8PLR9/UiNEo6e1lHVkJVCotNDWuaHF+uQaPNfv3zg=; b=CH6YdKFL+DH9LCysYPKbmMcHUfkzfjfA04KnJHiWQayLR4p7/I2ZyLA63XKSV9RMdS1fukQOiQKXiT5xDy0s77PSvUaiqqZmZ45uQACxkPX5DHAl3RRbdGO8mVh1tCaS7Gxa7UDMgPR3NxBEtNyEt9vWpkkGeeXOoWCXf5TKyJs= 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 1558619948689165.58405286841764; Thu, 23 May 2019 06:59:08 -0700 (PDT) Received: from localhost ([127.0.0.1]:36889 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hToFJ-0004dT-Hl for importer@patchew.org; Thu, 23 May 2019 09:59:01 -0400 Received: from eggs.gnu.org ([209.51.188.92]:45510) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hToDv-0003ql-Iw for qemu-devel@nongnu.org; Thu, 23 May 2019 09:57:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hToDu-0002D0-LF for qemu-devel@nongnu.org; Thu, 23 May 2019 09:57:35 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:44966) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hTo92-0007Tu-8B; Thu, 23 May 2019 09:52:32 -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 x4NDhSf7155184; Thu, 23 May 2019 13:52:31 GMT Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2130.oracle.com with ESMTP id 2smsk5jfbb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 23 May 2019 13:52:31 +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 x4NDqCqj101169; Thu, 23 May 2019 13:52:30 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserp3020.oracle.com with ESMTP id 2smsh28rgq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 23 May 2019 13:52:30 +0000 Received: from abhmp0012.oracle.com (abhmp0012.oracle.com [141.146.116.18]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x4NDqTZb000431; Thu, 23 May 2019 13:52:29 GMT Received: from nexus.ravello.local (/213.57.127.2) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 23 May 2019 13:52:29 +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=qe8PLR9/UiNEo6e1lHVkJVCotNDWuaHF+uQaPNfv3zg=; b=wfPQvqVqGAYiRoWVnvG9bzkoCp+8hK4AXM2VMGk52k0bJtC25DZ0eeaDORFZspMdQRSb cr2hi/+0VBhkB0POI3BloPhFCOE3jY3PFX/sc/HuMDnV9iBhK5ezf82dp9wUBfN3NE8N svnhTqL5OmIBieVf7funlUneUuWWSDMUTztbhcqTjYO8HdNXimq7IRmqJbR5jP/vpnvw 61Le8K0OU+keaM1Vnjb40wVQjYBmf9tv+i8oI1YZPFna+R2MgEkPRons4v/QAja0aRMq KVXV5Fl+uOm7x9VtMXo7yXB3or+3/I3PjdbapRCTf35REm37WiqpvVmwEhXRebVPoZzz Xw== From: Sam Eiderman To: kwolf@redhat.com, qemu-block@nongnu.org, qemu-devel@nongnu.org, mreitz@redhat.com Date: Thu, 23 May 2019 16:51:39 +0300 Message-Id: <20190523135139.2147-4-shmuel.eiderman@oracle.com> X-Mailer: git-send-email 2.13.3 In-Reply-To: <20190523135139.2147-1-shmuel.eiderman@oracle.com> References: <20190523135139.2147-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=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1905230096 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=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1905230096 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 156.151.31.86 Subject: [Qemu-devel] [PATCH v3 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 | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index e6fd8e1a98..b3a1c76fb6 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.13.3