From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, stefanha@linux.vnet.ibm.com, jcody@redhat.com,
lcapitulino@redhat.com, fsimonce@redhat.com, eblake@redhat.com
Subject: [Qemu-devel] [PATCH v2 6/6] add mirroring to blockdev-transaction
Date: Thu, 1 Mar 2012 12:21:48 +0100 [thread overview]
Message-ID: <1330600908-16202-7-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1330600908-16202-1-git-send-email-pbonzini@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
blockdev.c | 42 ++++++++++++++++++++++++++++++++----------
qapi-schema.json | 19 ++++++++++++++++++-
qmp-commands.hx | 12 +++++++++++-
3 files changed, 61 insertions(+), 12 deletions(-)
diff --git a/blockdev.c b/blockdev.c
index 8fcdf0e..f181c6f 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -733,6 +733,7 @@ void qmp_blockdev_transaction(BlockdevActionList *dev_list,
int ret = 0;
BlockdevActionList *dev_entry = dev_list;
BlkTransactionStates *states;
+ char *new_source = NULL;
QSIMPLEQ_HEAD(snap_bdrv_states, BlkTransactionStates) snap_bdrv_states;
QSIMPLEQ_INIT(&snap_bdrv_states);
@@ -744,12 +745,12 @@ void qmp_blockdev_transaction(BlockdevActionList *dev_list,
while (NULL != dev_entry) {
BlockdevAction *dev_info = NULL;
BlockDriver *proto_drv;
- BlockDriver *drv;
+ BlockDriver *target_drv;
+ BlockDriver *drv = NULL;
int flags;
const char *device;
const char *format = "qcow2";
const char *new_image_file = NULL;
- bool do_snapshot;
dev_info = dev_entry->value;
dev_entry = dev_entry->next;
@@ -760,21 +761,40 @@ void qmp_blockdev_transaction(BlockdevActionList *dev_list,
switch (dev_info->kind) {
case BLOCKDEV_ACTION_KIND_SNAPSHOT:
device = dev_info->snapshot->device;
- do_snapshot = !dev_info->snapshot->has_reuse || !dev_info->snapshot->reuse;
+ if (!dev_info->snapshot->has_reuse || !dev_info->snapshot->reuse) {
+ new_image_file = dev_info->snapshot->snapshot_file;
+ }
if (dev_info->snapshot->has_format) {
format = dev_info->snapshot->format;
}
- new_image_file = dev_info->snapshot->snapshot_file;
+ new_source = g_strdup(dev_info->snapshot->snapshot_file);
break;
+
+ case BLOCKDEV_ACTION_KIND_MIRROR:
+ device = dev_info->mirror->device;
+ drv = bdrv_find_format("blkmirror");
+ if (!dev_info->mirror->has_reuse || !dev_info->mirror->reuse) {
+ new_image_file = dev_info->mirror->target;
+ }
+ if (dev_info->mirror->has_format) {
+ format = dev_info->mirror->format;
+ }
+ new_source = g_strdup_printf("blkmirror:%s:%s", format,
+ dev_info->mirror->target);
+ break;
+
default:
abort();
}
- drv = bdrv_find_format(format);
- if (!drv) {
+ target_drv = bdrv_find_format(format);
+ if (!target_drv) {
error_set(errp, QERR_INVALID_BLOCK_FORMAT, format);
goto delete_and_fail;
}
+ if (!drv) {
+ drv = target_drv;
+ }
states->old_bs = bdrv_find(device);
if (!states->old_bs) {
@@ -798,14 +817,14 @@ void qmp_blockdev_transaction(BlockdevActionList *dev_list,
flags = states->old_bs->open_flags;
- proto_drv = bdrv_find_protocol(new_image_file);
+ proto_drv = bdrv_find_protocol(new_source);
if (!proto_drv) {
error_set(errp, QERR_INVALID_BLOCK_FORMAT, format);
goto delete_and_fail;
}
/* create new image w/backing file */
- if (do_snapshot) {
+ if (new_image_file) {
ret = bdrv_img_create(new_image_file, format,
states->old_bs->filename,
states->old_bs->drv->format_name,
@@ -818,12 +837,14 @@ void qmp_blockdev_transaction(BlockdevActionList *dev_list,
/* We will manually add the backing_hd field to the bs later */
states->new_bs = bdrv_new("");
- ret = bdrv_open(states->new_bs, new_image_file,
+ ret = bdrv_open(states->new_bs, new_source,
flags | BDRV_O_NO_BACKING, drv);
if (ret != 0) {
- error_set(errp, QERR_OPEN_FILE_FAILED, new_image_file);
+ error_set(errp, QERR_OPEN_FILE_FAILED, new_source);
goto delete_and_fail;
}
+ g_free(new_source);
+ new_source = NULL;
}
@@ -851,6 +872,7 @@ exit:
QSIMPLEQ_FOREACH(states, &snap_bdrv_states, entry) {
g_free(states);
}
+ g_free(new_source);
return;
}
diff --git a/qapi-schema.json b/qapi-schema.json
index 78df122..fd5973d 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -1131,6 +1131,22 @@
'*reuse': 'bool' } }
##
+# @BlockdevMirror
+#
+# @device: the name of the device to start mirroring.
+#
+# @target: the image that will start receiving writes for @device. A new
+# file will be created if @reuse is absent or false.
+#
+# @format: #optional the format of the target image, default is 'qcow2'.
+#
+# @reuse: #optional whether QEMU should create a new image.
+##
+{ 'type': 'BlockdevMirror',
+ 'data': { 'device': 'str', 'target': 'str', '*format': 'str',
+ '*reuse': 'bool' } }
+
+##
# @BlockdevAction
#
# A discriminated record of operations that can be performed with
@@ -1138,7 +1154,8 @@
##
{ 'union': 'BlockdevAction',
'data': {
- 'snapshot': 'BlockdevSnapshot'
+ 'snapshot': 'BlockdevSnapshot',
+ 'mirror': 'BlockdevMirror',
} }
##
diff --git a/qmp-commands.hx b/qmp-commands.hx
index 817b689..50ac5a0 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -701,7 +701,11 @@ operation for now is snapshotting. If there is any failure performing
any of the operations, all snapshots for the group are abandoned, and
the original disks pre-snapshot attempt are used.
+Mirrored writes keep the previous image file open, and start writing
+data also to the new file specified in the command.
+
A list of dictionaries is accepted, that contains the actions to be performed.
+
For snapshots this is the device, the file to use for the new snapshot,
and the format. The default format, if not specified, is qcow2.
@@ -716,7 +720,7 @@ Arguments:
actions array:
- "type": the operation to perform. The only supported
- value is "snapshot". (json-string)
+ values are "snapshot" and "mirror". (json-string)
- "data": a dictionary. The contents depend on the value
of "type". When "type" is "snapshot":
- "device": device name to snapshot (json-string)
@@ -724,6 +728,12 @@ actions array:
- "format": format of new image (json-string, optional)
- "reuse": whether QEMU should look for an existing image file
(json-bool, optional, default false)
+ When "type" is "mirror":
+ - "device": device name to snapshot (json-string)
+ - "target": name of destination image file (json-string)
+ - "format": format of new image (json-string, optional)
+ - "reuse": whether QEMU should look for an existing image file
+ (json-bool, optional, default false)
Example:
--
1.7.7.6
next prev parent reply other threads:[~2012-03-01 11:23 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-03-01 11:21 [Qemu-devel] [PATCH v2 0/6] Mirrored writes using blockdev-transaction Paolo Bonzini
2012-03-01 11:21 ` [Qemu-devel] [PATCH v2 1/6] fix format name for backing file Paolo Bonzini
2012-03-01 11:21 ` [Qemu-devel] [PATCH v2 2/6] qapi: complete implementation of unions Paolo Bonzini
2012-03-01 13:52 ` Kevin Wolf
2012-03-01 15:56 ` Luiz Capitulino
2012-03-01 11:21 ` [Qemu-devel] [PATCH v2 3/6] rename blockdev-group-snapshot-sync Paolo Bonzini
2012-03-01 11:21 ` [Qemu-devel] [PATCH v2 4/6] add reuse field Paolo Bonzini
2012-03-01 11:21 ` [Qemu-devel] [PATCH v2 5/6] Add blkmirror block driver Paolo Bonzini
2012-03-01 11:21 ` Paolo Bonzini [this message]
2012-03-01 16:02 ` [Qemu-devel] [PATCH v2 0/6] Mirrored writes using blockdev-transaction Luiz Capitulino
2012-03-01 16:18 ` Kevin Wolf
2012-03-01 16:43 ` Luiz Capitulino
2012-03-01 21:10 ` Anthony Liguori
2012-03-01 21:30 ` Eric Blake
2012-03-01 21:36 ` Anthony Liguori
2012-03-02 13:05 ` Anthony Liguori
2012-03-05 8:53 ` Kevin Wolf
2012-03-05 9:28 ` Paolo Bonzini
2012-03-05 12:13 ` Kevin Wolf
2012-03-05 13:05 ` Paolo Bonzini
2012-03-05 14:47 ` Anthony Liguori
2012-03-05 14:54 ` Paolo Bonzini
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=1330600908-16202-7-git-send-email-pbonzini@redhat.com \
--to=pbonzini@redhat.com \
--cc=eblake@redhat.com \
--cc=fsimonce@redhat.com \
--cc=jcody@redhat.com \
--cc=kwolf@redhat.com \
--cc=lcapitulino@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).