Patchwork [2/2,v8] add-cow: support snapshot_blkdev

login
register
mail settings
Submitter Robert Wang
Date April 18, 2012, 8:18 a.m.
Message ID <1334737097-20680-2-git-send-email-wdongxu@linux.vnet.ibm.com>
Download mbox | patch
Permalink /patch/153434/
State New
Headers show

Comments

Robert Wang - April 18, 2012, 8:18 a.m.
From: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>

Raw file format does not support snapshot_blkdev command, we can use add-cow
to 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              |   31 +++++++++++++++++++++++++++----
 docs/live-block-ops.txt |   10 +++++++++-
 2 files changed, 36 insertions(+), 5 deletions(-)

Patch

diff --git a/blockdev.c b/blockdev.c
index 0c2440e..0332b49 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -780,15 +780,38 @@  void qmp_transaction(BlockdevActionList *dev_list, Error **errp)
 
         /* create new image w/backing file */
         if (mode != NEW_IMAGE_MODE_EXISTING) {
-            ret = bdrv_img_create(new_image_file, format,
+            if (strcmp(format, "add-cow")) {
+                ret = bdrv_img_create(new_image_file, format,
                                   states->old_bs->filename,
                                   states->old_bs->drv->format_name,
                                   NULL, -1, flags);
-            if (ret) {
-                error_set(errp, QERR_OPEN_FILE_FAILED, new_image_file);
-                goto delete_and_fail;
+            } else {
+                char image_file[1024];
+                char option[1024];
+                uint64_t size;
+
+                bdrv_get_geometry(states->old_bs, &size);
+                size *= BDRV_SECTOR_SIZE;
+
+                sprintf(image_file, "%s.raw", new_image_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", new_image_file);
+                ret = bdrv_img_create(new_image_file, format,
+                                      states->old_bs->filename,
+                                      states->old_bs->drv->format_name,
+                                      option, -1, flags);
             }
         }
+        if (ret) {
+            error_set(errp, QERR_OPEN_FILE_FAILED, new_image_file);
+            goto delete_and_fail;
+        }
 
         /* We will manually add the backing_hd field to the bs later */
         states->new_bs = bdrv_new("");
diff --git a/docs/live-block-ops.txt b/docs/live-block-ops.txt
index a257087..c97344b 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
 ===================
@@ -56,3 +57,10 @@  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.