All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: qemu-block@nongnu.org
Cc: kwolf@redhat.com, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PULL 13/15] qemu-img: Allow rebase with no input base
Date: Fri, 10 May 2019 18:16:12 +0200	[thread overview]
Message-ID: <20190510161614.23236-14-kwolf@redhat.com> (raw)
In-Reply-To: <20190510161614.23236-1-kwolf@redhat.com>

From: Max Reitz <mreitz@redhat.com>

Currently, without -u, you cannot add a backing file to an image when it
currently has none:

$ qemu-img rebase -b base.qcow2 foo.qcow2
qemu-img: Could not open old backing file '': The 'file' block driver
requires a file name

It is really simple to allow this, though (effectively by setting
old_backing_size to 0), so this patch does just that.

Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 qemu-img.c | 61 ++++++++++++++++++++++++++++++------------------------
 1 file changed, 34 insertions(+), 27 deletions(-)

diff --git a/qemu-img.c b/qemu-img.c
index 71c92f142a..cfa44b4153 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -3312,26 +3312,30 @@ static int img_rebase(int argc, char **argv)
         char backing_name[PATH_MAX];
         QDict *options = NULL;
 
-        if (bs->backing_format[0] != '\0') {
-            options = qdict_new();
-            qdict_put_str(options, "driver", bs->backing_format);
-        }
-
-        if (force_share) {
-            if (!options) {
+        if (bs->backing) {
+            if (bs->backing_format[0] != '\0') {
                 options = qdict_new();
+                qdict_put_str(options, "driver", bs->backing_format);
             }
-            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) {
-            error_reportf_err(local_err,
-                              "Could not open old backing file '%s': ",
-                              backing_name);
-            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) {
+                error_reportf_err(local_err,
+                                  "Could not open old backing file '%s': ",
+                                  backing_name);
+                ret = -1;
+                goto out;
+            }
+        } else {
+            blk_old_backing = NULL;
         }
 
         if (out_baseimg[0]) {
@@ -3384,7 +3388,7 @@ static int img_rebase(int argc, char **argv)
      */
     if (!unsafe) {
         int64_t size;
-        int64_t old_backing_size;
+        int64_t old_backing_size = 0;
         int64_t new_backing_size = 0;
         uint64_t offset;
         int64_t n;
@@ -3400,15 +3404,18 @@ static int img_rebase(int argc, char **argv)
             ret = -1;
             goto out;
         }
-        old_backing_size = blk_getlength(blk_old_backing);
-        if (old_backing_size < 0) {
-            char backing_name[PATH_MAX];
+        if (blk_old_backing) {
+            old_backing_size = blk_getlength(blk_old_backing);
+            if (old_backing_size < 0) {
+                char backing_name[PATH_MAX];
 
-            bdrv_get_backing_filename(bs, backing_name, sizeof(backing_name));
-            error_report("Could not get size of '%s': %s",
-                         backing_name, strerror(-old_backing_size));
-            ret = -1;
-            goto out;
+                bdrv_get_backing_filename(bs, backing_name,
+                                          sizeof(backing_name));
+                error_report("Could not get size of '%s': %s",
+                             backing_name, strerror(-old_backing_size));
+                ret = -1;
+                goto out;
+            }
         }
         if (blk_new_backing) {
             new_backing_size = blk_getlength(blk_new_backing);
-- 
2.20.1



  parent reply	other threads:[~2019-05-10 16:37 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-10 16:15 [Qemu-devel] [PULL 00/15] Block layer patches Kevin Wolf
2019-05-10 16:16 ` [Qemu-devel] [PULL 01/15] block: remove bs from lists before closing Kevin Wolf
2019-05-10 16:16 ` [Qemu-devel] [PULL 02/15] MAINTAINERS: Downgrade status of block sections without "M:" to "Odd Fixes" Kevin Wolf
2019-05-10 16:16 ` [Qemu-devel] [PULL 03/15] MAINTAINERS: Add an entry for the Parallel NOR Flash devices Kevin Wolf
2019-05-10 16:16 ` [Qemu-devel] [PULL 04/15] qemu-iotests: Fix cleanup for 192 Kevin Wolf
2019-05-10 16:16 ` [Qemu-devel] [PULL 05/15] blockjob: Fix coroutine thread after AioContext change Kevin Wolf
2019-05-10 16:16 ` [Qemu-devel] [PULL 06/15] test-block-iothread: Job coroutine thread after AioContext switch Kevin Wolf
2019-05-10 16:16 ` [Qemu-devel] [PULL 07/15] qemu-img: Use IEC binary prefixes for size constants Kevin Wolf
2019-05-10 16:16 ` [Qemu-devel] [PULL 08/15] qcow2: Replace bdrv_write() with bdrv_pwrite() Kevin Wolf
2019-05-10 16:16 ` [Qemu-devel] [PULL 09/15] vdi: Replace bdrv_{read, write}() with bdrv_{pread, pwrite}() Kevin Wolf
2019-05-10 16:16 ` [Qemu-devel] [PULL 10/15] vvfat: " Kevin Wolf
2019-05-10 16:16 ` [Qemu-devel] [PULL 11/15] block: Remove bdrv_read() and bdrv_write() Kevin Wolf
2019-05-10 16:16 ` [Qemu-devel] [PULL 12/15] qcow2: Remove BDRVQcow2State.cluster_sectors Kevin Wolf
2019-05-10 16:16 ` Kevin Wolf [this message]
2019-05-20 15:33   ` [Qemu-devel] [PULL 13/15] qemu-img: Allow rebase with no input base Peter Maydell
2019-05-10 16:16 ` [Qemu-devel] [PULL 14/15] qemu-img: Use zero writes after source backing EOF Kevin Wolf
2019-05-10 16:16 ` [Qemu-devel] [PULL 15/15] iotests: Add test for rebase without input base Kevin Wolf
2019-05-13  9:44 ` [Qemu-devel] [PULL 00/15] Block layer patches Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190510161614.23236-14-kwolf@redhat.com \
    --to=kwolf@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.