[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v2 6/6] add mirroring to blockdev-transaction
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PATCH v2 6/6] add mirroring to blockdev-transaction |
Date: |
Thu, 1 Mar 2012 12:21:48 +0100 |
Signed-off-by: Paolo Bonzini <address@hidden>
---
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
- [Qemu-devel] [PATCH v2 0/6] Mirrored writes using blockdev-transaction, Paolo Bonzini, 2012/03/01
- [Qemu-devel] [PATCH v2 1/6] fix format name for backing file, Paolo Bonzini, 2012/03/01
- [Qemu-devel] [PATCH v2 2/6] qapi: complete implementation of unions, Paolo Bonzini, 2012/03/01
- [Qemu-devel] [PATCH v2 4/6] add reuse field, Paolo Bonzini, 2012/03/01
- [Qemu-devel] [PATCH v2 5/6] Add blkmirror block driver, Paolo Bonzini, 2012/03/01
- [Qemu-devel] [PATCH v2 3/6] rename blockdev-group-snapshot-sync, Paolo Bonzini, 2012/03/01
- [Qemu-devel] [PATCH v2 6/6] add mirroring to blockdev-transaction,
Paolo Bonzini <=
- Re: [Qemu-devel] [PATCH v2 0/6] Mirrored writes using blockdev-transaction, Luiz Capitulino, 2012/03/01
- Re: [Qemu-devel] [PATCH v2 0/6] Mirrored writes using blockdev-transaction, Anthony Liguori, 2012/03/01
- Re: [Qemu-devel] [PATCH v2 0/6] Mirrored writes using blockdev-transaction, Kevin Wolf, 2012/03/05