qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Alex Bligh <alex@alex.org.uk>
To: qemu-devel@nongnu.org
Cc: Alex Bligh <alex@alex.org.uk>
Subject: [Qemu-devel] [PATCH] qemu-img rebase: allow backing file to be specified as '-'
Date: Mon, 15 Oct 2012 18:29:34 +0100	[thread overview]
Message-ID: <CD6AD65A07E882F403F4BA91@Ximines.local> (raw)

This patch allows qemu-img rebase to rebase an image to
have no backing file, as opposed to merely allowing it to
rebase to an existing backing file.

Patch below, or pull from git at:
  https://github.com/abligh/qemu.git

Commit visible at:
https://github.com/abligh/qemu/commit/4d5b3b431d8dd276f4c564d8a82c6d25cb111381


Signed-off-by: Alex Bligh <alex@alex.org.uk>
---
 qemu-img.c    |   26 ++++++++++++++++----------
 qemu-img.texi |    4 +++-
 2 files changed, 19 insertions(+), 11 deletions(-)

diff --git a/qemu-img.c b/qemu-img.c
index f17f187..770e221 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -1558,13 +1558,14 @@ static int img_rebase(int argc, char **argv)
             error_report("Could not open old backing file '%s'", backing_name);
             goto out;
         }
-
-        bs_new_backing = bdrv_new("new_backing");
-        ret = bdrv_open(bs_new_backing, out_baseimg, BDRV_O_FLAGS,
+        if (strcmp("-", out_baseimg)) {
+            bs_new_backing = bdrv_new("new_backing");
+            ret = bdrv_open(bs_new_backing, out_baseimg, BDRV_O_FLAGS,
                         new_backing_drv);
-        if (ret) {
-            error_report("Could not open new backing file '%s'", out_baseimg);
-            goto out;
+            if (ret) {
+                error_report("Could not open new backing file '%s'", out_baseimg);
+                goto out;
+            }
         }
     }

@@ -1580,7 +1581,7 @@ static int img_rebase(int argc, char **argv)
     if (!unsafe) {
         uint64_t num_sectors;
         uint64_t old_backing_num_sectors;
-        uint64_t new_backing_num_sectors;
+        uint64_t new_backing_num_sectors=0;
         uint64_t sector;
         int n;
         uint8_t * buf_old;
@@ -1592,7 +1593,8 @@ static int img_rebase(int argc, char **argv)

         bdrv_get_geometry(bs, &num_sectors);
         bdrv_get_geometry(bs_old_backing, &old_backing_num_sectors);
-        bdrv_get_geometry(bs_new_backing, &new_backing_num_sectors);
+        if (bs_new_backing)
+            bdrv_get_geometry(bs_new_backing, &new_backing_num_sectors);

         local_progress = (float)100 /
             (num_sectors / MIN(num_sectors, IO_BUF_SIZE / 512));
@@ -1629,7 +1631,7 @@ static int img_rebase(int argc, char **argv)
                 }
             }

-            if (sector >= new_backing_num_sectors) {
+            if (sector >= new_backing_num_sectors || !bs_new_backing) {
                 memset(buf_new, 0, n * BDRV_SECTOR_SIZE);
             } else {
                 if (sector + n > new_backing_num_sectors) {
@@ -1675,7 +1677,11 @@ static int img_rebase(int argc, char **argv)
      * backing file are overwritten in the COW file now, so the visible content
      * doesn't change when we switch the backing file.
      */
-    ret = bdrv_change_backing_file(bs, out_baseimg, out_basefmt);
+    if (bs_new_backing)
+        ret = bdrv_change_backing_file(bs, out_baseimg, out_basefmt);
+    else
+        ret = bdrv_change_backing_file(bs, NULL, NULL);
+
     if (ret == -ENOSPC) {
         error_report("Could not change the backing file to '%s': No "
                      "space left in the file header", out_baseimg);
diff --git a/qemu-img.texi b/qemu-img.texi
index 8b05f2c..7c29f23 100644
--- a/qemu-img.texi
+++ b/qemu-img.texi
@@ -148,7 +148,9 @@ Changes the backing file of an image. Only the formats @code{qcow2} and

 The backing file is changed to @var{backing_file} and (if the image format of
 @var{filename} supports this) the backing file format is changed to
-@var{backing_fmt}.
+@var{backing_fmt}. If @var{backing_file} is specified as ``-'', then the image
+is rebased onto no backing file (i.e. it will exist independently of any
+backing file).

 There are two different modes in which @code{rebase} can operate:
 @table @option
-- 
1.7.0.4

             reply	other threads:[~2012-10-15 17:39 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-15 17:29 Alex Bligh [this message]
2012-10-15 18:07 ` [Qemu-devel] [PATCH] qemu-img rebase: allow backing file to be specified as '-' Eric Blake
2012-10-15 18:11   ` Eric Blake
2012-10-15 18:42     ` Alex Bligh
2012-10-15 19:28       ` Eric Blake
2012-10-15 20:28         ` Alex Bligh
2012-10-23 16:41   ` Christoph Hellwig

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=CD6AD65A07E882F403F4BA91@Ximines.local \
    --to=alex@alex.org.uk \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).