From: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
Subject: [Qemu-devel] [PATCH 4/6 v11] add-cow: support snapshot_blkde
Date: Wed, 1 Aug 2012 00:51:48 +0800 [thread overview]
Message-ID: <1343753510-24661-4-git-send-email-wdongxu@linux.vnet.ibm.com> (raw)
In-Reply-To: <1343753510-24661-1-git-send-email-wdongxu@linux.vnet.ibm.com>
add-cow will let raw file support snapshot_blkdev indirectly.
Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
---
blockdev.c | 45 +++++++++++++++++++++++++++++++++++++--------
docs/live-block-ops.txt | 11 ++++++++++-
2 files changed, 47 insertions(+), 9 deletions(-)
diff --git a/blockdev.c b/blockdev.c
index 3d75015..a1e9268 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -19,7 +19,7 @@
#include "qmp-commands.h"
#include "trace.h"
#include "arch_init.h"
-
+#include "block/add-cow.h"
static QTAILQ_HEAD(drivelist, DriveInfo) drives = QTAILQ_HEAD_INITIALIZER(drives);
static const char *const if_name[IF_COUNT] = {
@@ -665,6 +665,8 @@ static void blockdev_do_action(int kind, void *data, Error **errp)
void qmp_blockdev_snapshot_sync(const char *device, const char *snapshot_file,
bool has_format, const char *format,
bool has_mode, enum NewImageMode mode,
+ bool has_image_file, const char *image_filename,
+ bool has_image_format, const char *image_format,
Error **errp)
{
BlockdevSnapshot snapshot = {
@@ -674,6 +676,10 @@ void qmp_blockdev_snapshot_sync(const char *device, const char *snapshot_file,
.format = (char *) format,
.has_mode = has_mode,
.mode = mode,
+ .has_image_file = has_image_file,
+ .image_file = (char *) image_filename,
+ .has_image_format = has_image_format,
+ .image_format = (char *) image_format,
};
blockdev_do_action(BLOCKDEV_ACTION_KIND_BLOCKDEV_SNAPSHOT_SYNC, &snapshot,
errp);
@@ -776,15 +782,30 @@ 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,
- 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;
+ char option[1024];
+ uint64_t size;
+
+ bdrv_get_geometry(states->old_bs, &size);
+ size *= BDRV_SECTOR_SIZE;
+ if (dev_info->blockdev_snapshot_sync->image_file) {
+ sprintf(option, "image_file=%s,image_format=%s",
+ dev_info->blockdev_snapshot_sync->image_file,
+ dev_info->blockdev_snapshot_sync->has_image_format ? dev_info->blockdev_snapshot_sync->image_format : "raw");
+ ret = bdrv_img_create(new_image_file, format,
+ states->old_bs->filename,
+ states->old_bs->drv->format_name,
+ option, -1, flags);
+ } else {
+ 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;
+ }
/* We will manually add the backing_hd field to the bs later */
states->new_bs = bdrv_new("");
@@ -1083,6 +1104,14 @@ static void block_stream_cb(void *opaque, int ret)
}
qobject_decref(obj);
+ if (strcmp(bs->drv->format_name, "add-cow") == 0) {
+ BDRVAddCowState *s = bs->opaque;
+ char *format = s->image_file_format;
+ BlockDriver *drv = bdrv_find_format(format);
+ assert(drv);
+ bdrv_drain_all();
+ bdrv_swap(s->image_hd, bs);
+ }
drive_put_ref_bh_schedule(drive_get_by_blockdev(bs));
}
diff --git a/docs/live-block-ops.txt b/docs/live-block-ops.txt
index a257087..a53bab3 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,11 @@ 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 source.img raw
+
+source.img is a raw file, and should be pre-created. disk.img will be created
+using soure.img as image file. After block_stream process finished, it will
+reassociate the drive with source.img automatically.
--
1.7.1
next prev parent reply other threads:[~2012-07-31 16:52 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-07-31 16:51 [Qemu-devel] [PATCH 1/6 v11] docs: spec for add-cow file format Dong Xu Wang
2012-07-31 16:51 ` [Qemu-devel] [PATCH 2/6 v11 v11] block: make some functions public Dong Xu Wang
2012-08-01 13:53 ` Eric Blake
2012-08-02 7:10 ` Dong Xu Wang
2012-08-01 14:01 ` Stefan Hajnoczi
2012-08-02 7:11 ` Dong Xu Wang
2012-07-31 16:51 ` [Qemu-devel] [PATCH 3/6] add-cow file format Dong Xu Wang
2012-08-01 13:57 ` Eric Blake
2012-08-01 14:14 ` Stefan Hajnoczi
2012-08-01 14:21 ` Kevin Wolf
2012-08-02 7:20 ` Dong Xu Wang
2012-08-01 15:31 ` Stefan Hajnoczi
2012-08-02 7:20 ` Dong Xu Wang
2012-07-31 16:51 ` Dong Xu Wang [this message]
2012-08-01 15:37 ` [Qemu-devel] [PATCH 4/6 v11] add-cow: support snapshot_blkde Stefan Hajnoczi
2012-08-02 7:28 ` Dong Xu Wang
2012-08-02 10:37 ` Stefan Hajnoczi
2012-07-31 16:51 ` [Qemu-devel] [PATCH 5/6 v11] add-cow: hmp and qmp interface Dong Xu Wang
2012-07-31 16:51 ` [Qemu-devel] [PATCH 6/6 v11] add-cow: support qemu-iotests Dong Xu Wang
2012-08-01 13:51 ` [Qemu-devel] [PATCH 1/6 v11] docs: spec for add-cow file format Eric Blake
2012-08-02 7:03 ` Dong Xu Wang
2012-08-01 13:55 ` Stefan Hajnoczi
2012-08-02 7:09 ` Dong Xu Wang
2012-08-02 10:44 ` Stefan Hajnoczi
2012-08-03 5:56 ` Dong Xu Wang
2012-08-03 8:26 ` Stefan Hajnoczi
2012-08-06 2:05 ` 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=1343753510-24661-4-git-send-email-wdongxu@linux.vnet.ibm.com \
--to=wdongxu@linux.vnet.ibm.com \
--cc=kwolf@redhat.com \
--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).