diff mbox series

[v2,1/3] qemu-img: rebase: Reuse parent BlockDriverState

Message ID 20190502135828.42797-2-shmuel.eiderman@oracle.com (mailing list archive)
State New, archived
Headers show
Series qemu-img: rebase: Improve/optimize rebase operation | expand

Commit Message

Sam Eiderman May 2, 2019, 1:58 p.m. UTC
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 = 0.

Reviewed-by: Karl Heubaum <karl.heubaum@oracle.com>
Reviewed-by: Eyal Moscovici <eyal.moscovici@oracle.com>
Signed-off-by: Sagi Amit <sagi.amit@oracle.com>
Co-developed-by: Sagi Amit <sagi.amit@oracle.com>
Signed-off-by: Sam Eiderman <shmuel.eiderman@oracle.com>
---
 qemu-img.c | 29 ++++++++++++-----------------
 1 file changed, 12 insertions(+), 17 deletions(-)

Comments

Max Reitz May 23, 2019, 1:07 p.m. UTC | #1
On 02.05.19 15:58, Sam Eiderman wrote:
> 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 = 0.
> 
> Reviewed-by: Karl Heubaum <karl.heubaum@oracle.com>
> Reviewed-by: Eyal Moscovici <eyal.moscovici@oracle.com>
> Signed-off-by: Sagi Amit <sagi.amit@oracle.com>
> Co-developed-by: Sagi Amit <sagi.amit@oracle.com>
> Signed-off-by: Sam Eiderman <shmuel.eiderman@oracle.com>
> ---
>  qemu-img.c | 29 ++++++++++++-----------------
>  1 file changed, 12 insertions(+), 17 deletions(-)

Looks good!
But I’m afraid it will need a rebase on my “Allow rebase with no input
base” series (which is in master)...

Max
diff mbox series

Patch

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)
 
     /* For safe rebasing we need to compare old and new backing file */
     if (!unsafe) {
-        char backing_name[PATH_MAX];
         QDict *options = NULL;
+        BlockDriverState *base_bs = backing_bs(bs);
 
-        if (bs->backing_format[0] != '\0') {
-            options = 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 = -1;
+            goto out;
         }
 
-        if (force_share) {
-            if (!options) {
-                options = qdict_new();
-            }
-            qdict_put_bool(options, BDRV_OPT_FORCE_SHARE, true);
-        }
-        bdrv_get_backing_filename(bs, backing_name, sizeof(backing_name));
-        blk_old_backing = blk_new_open(backing_name, NULL,
-                                       options, src_flags, &local_err);
-        if (!blk_old_backing) {
+        blk_old_backing = blk_new(BLK_PERM_CONSISTENT_READ,
+                                  BLK_PERM_ALL);
+        ret = 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 = -1;
+                              "Could not reuse old backing file '%s': ",
+                              base_bs->filename);
             goto out;
         }