qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>,
	Marcelo Tosatti <mtosatti@redhat.com>,
	Dong Xu Wang <wdongxu@linux.vnet.ibm.com>,
	Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Subject: [Qemu-devel] [PATCH 2/2] block: add-cow support snapshot_blkdev
Date: Thu,  1 Mar 2012 10:49:28 +0800	[thread overview]
Message-ID: <1330570168-8226-2-git-send-email-wdongxu@linux.vnet.ibm.com> (raw)
In-Reply-To: <1330570168-8226-1-git-send-email-wdongxu@linux.vnet.ibm.com>

From: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>

We can not use raw to support snapshot_file, but add-cow can do this.

CC: Marcelo Tosatti <mtosatti@redhat.com>
CC: Kevin Wolf <kwolf@redhat.com>
CC: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
---
 blockdev.c              |   53 ++++++++++++++++++++++++++++++++++++++++++----
 docs/live-block-ops.txt |    8 ++++++-
 2 files changed, 55 insertions(+), 6 deletions(-)

diff --git a/blockdev.c b/blockdev.c
index d78aa51..c820fcb 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -687,12 +687,55 @@ void qmp_blockdev_snapshot_sync(const char *device, const char *snapshot_file,
         return;
     }
 
-    ret = bdrv_img_create(snapshot_file, format, bs->filename,
-                          bs->drv->format_name, NULL, -1, flags);
-    if (ret) {
-        error_set(errp, QERR_UNDEFINED_ERROR);
-        return;
+    if (strcmp(format, "add-cow")) {
+        ret = bdrv_img_create(snapshot_file, format, bs->filename,
+                              bs->drv->format_name, NULL, -1, flags);
+        if (ret) {
+            error_set(errp, QERR_UNDEFINED_ERROR);
+            return;
+        }
+    } else {
+        char image_file[1024];
+        char option[1024];
+
+        uint64_t size;
+        BlockDriver *backing_drv = NULL;
+        BlockDriverState *backing_bs = NULL;
+
+        backing_bs = bdrv_new("");
+        backing_drv = bdrv_find_format(bs->drv->format_name);
+        if (!backing_drv) {
+            error_report("Unknown backing file format '%s'",
+                         bs->drv->format_name);
+            error_set(errp, QERR_UNDEFINED_ERROR);
+            return;
+        }
+        ret = bdrv_open(backing_bs, bs->filename, flags, backing_drv);
+        if (ret < 0) {
+            error_set(errp, QERR_UNDEFINED_ERROR);
+            return;
+        }
+        bdrv_get_geometry(backing_bs, &size);
+        size *= 512;
+        bdrv_delete(backing_bs);
+
+        sprintf(image_file, "%s.raw", snapshot_file);
+
+        ret = bdrv_img_create(image_file, "raw", NULL,
+                              NULL, NULL, size, flags);
+        if (ret) {
+            error_set(errp, QERR_UNDEFINED_ERROR);
+            return;
+        }
+        sprintf(option, "image_file=%s.raw", snapshot_file);
+        ret = bdrv_img_create(snapshot_file, format, bs->filename,
+                              bs->drv->format_name, option, -1, flags);
+        if (ret) {
+            error_set(errp, QERR_UNDEFINED_ERROR);
+            return;
+        }
     }
+    bs->backing_format[0] = '\0';
 
     bdrv_drain_all();
     bdrv_flush(bs);
diff --git a/docs/live-block-ops.txt b/docs/live-block-ops.txt
index a257087..7edbf91 100644
--- a/docs/live-block-ops.txt
+++ b/docs/live-block-ops.txt
@@ -2,7 +2,8 @@ LIVE BLOCK OPERATIONS
 =====================
 
 High level description of live block operations. Note these are not
-supported for use with the raw format at the moment.
+supported for use with the raw format at the moment, but we can use
+add-cow as metadata to suport raw format.
 
 Snapshot live merge
 ===================
@@ -55,4 +56,9 @@ into that image. Example:
 
 (qemu) block_stream ide0-hd0
 
+Raw is not supported, but we can use add-cow in the 1st step:
 
+(qemu) snapshot_blkdev ide0-hd0 /new-path/disk.img add-cow
+
+It will create a raw file named disk.img.raw, with the same virtual size of
+ide0-hd0 first, and then create disk.img.
-- 
1.7.5.4

  reply	other threads:[~2012-03-01  2:50 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-01  2:49 [Qemu-devel] [PATCH 1/2 v7] block: add-cow file format Dong Xu Wang
2012-03-01  2:49 ` Dong Xu Wang [this message]
2012-03-07 13:10   ` [Qemu-devel] [PATCH 2/2] block: add-cow support snapshot_blkdev Stefan Hajnoczi
2012-03-08  1:50     ` Dong Xu Wang
2012-03-08 10:53       ` Stefan Hajnoczi
2012-03-01  2:58 ` [Qemu-devel] [PATCH 1/2 v7] block: add-cow file format Dong Xu Wang

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=1330570168-8226-2-git-send-email-wdongxu@linux.vnet.ibm.com \
    --to=wdongxu@linux.vnet.ibm.com \
    --cc=kwolf@redhat.com \
    --cc=mtosatti@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@linux.vnet.ibm.com \
    /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).