qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 2/2] block: add-cow support snapshot_blkdev


From: Dong Xu Wang
Subject: [Qemu-devel] [PATCH 2/2] block: add-cow support snapshot_blkdev
Date: Thu, 1 Mar 2012 10:49:28 +0800

From: Dong Xu Wang <address@hidden>

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

CC: Marcelo Tosatti <address@hidden>
CC: Kevin Wolf <address@hidden>
CC: Stefan Hajnoczi <address@hidden>
Signed-off-by: Dong Xu Wang <address@hidden>
---
 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 via email to

[Prev in Thread] Current Thread [Next in Thread]