Mirrored writes using blockdev-transaction
Subsystems (2)
v2 cover Mirrored writes using blockdev-transaction
This implements all ingredients to establish mirrored writes. The drive-reopen command that is used to terminate mirrored writes is not included in this series.
Tested with the following scenarios:
a) mirror only
1) create base.qcow2 and start QEMU with it
2) Execute the following QMP command
{ "execute": "qmp_capabilities" }
{ "execute": "blockdev-transaction", "arguments":
{'actions': [
{ 'type': 'mirror', 'data' :
{ 'device': 'ide0-hd0', 'target': '/home/pbonzini/mirror.qcow2' } } ] } }{ "execute": "cont" }
3) hibernate the guest (this requires an IDE disk and -cpu kvm64,-kvmclock)
4) restart the guest with mirror.qcow2
b) atomic snapshot+mirror
1) start QEMU with an existing image test.img
2) Execute the following QMP command
{ "execute": "qmp_capabilities" }
{ "execute": "blockdev-transaction", "arguments":
{'actions': [
{ 'type': 'snapshot', 'data' :
{ 'device': 'ide0-hd0', 'snapshot-file': '/home/pbonzini/base.qcow2' } },
{ 'type': 'mirror', 'data' :
{ 'device': 'ide0-hd0', 'target': '/home/pbonzini/mirror.qcow2' } } ] } }{ "execute": "cont" }
3) hibernate the guest (this requires an IDE disk and -cpu kvm64,-kvmclock)
4) check that mirror.qcow2 has test.img as the base
5) restart the guest with base.qcow2
6) restart the guest with mirror.qcow2
v1->v2:
Removed wrong assertions in patches 3 and 6
Move new_image_file and other variables inside the while loop (Federico) Rename new_source_file to new_source (Federico)
Fix image name in error message (Federico)
Fixed documentation in qapi-schema.json (Federico)
Fixed documentation and example in qmp-commands.hx (Eric) Added back AIO (Stefan), with fixes to cancellation
Marcelo Tosatti (1):
Add blkmirror block driver
Paolo Bonzini (5):
fix format name for backing file
qapi: complete implementation of unions
rename blockdev-group-snapshot-sync
add reuse field
add mirroring to blockdev-transaction
Makefile.objs | 2 +- block/blkmirror.c | 239 +++++++++++++++++++++++++++++++++++++++++++++ blockdev.c | 114 ++++++++++++++-------- qapi-schema-test.json | 10 ++ qapi-schema.json | 51 ++++++++-- qmp-commands.hx | 68 +++++++++---- scripts/qapi-types.py | 5 + scripts/qapi-visit.py | 31 ++++++- test-qmp-input-visitor.c | 18 ++++ test-qmp-output-visitor.c | 34 +++++++ 10 files changed, 496 insertions(+), 76 deletions(-) create mode 100644 block/blkmirror.c
Signature · 1 line
1.7.7.6
PATCH v2 1/6 fix format name for backing file
--- blockdev.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
blockdev.c +2 -1
@@ -800,7 +800,8 @@ void qmp_blockdev_group_snapshot_sync(SnapshotDevList *dev_list,/* create new image w/backing file */ ret =bdrv_img_create (snapshot_file, format, states->old_bs->filename, - drv->format_name,NULL ,-1 , flags); + states->old_bs->drv->format_name, +NULL ,-1 , flags);if (ret) {error_set (errp,QERR_OPEN_FILE_FAILED , snapshot_file); goto delete_and_fail;
Signature · 1 line
1.7.7.6
PATCH v2 2/6 qapi: complete implementation of unions
In reply to Paolo Bonzini--- qapi-schema-test.json | 10 ++++++++++ scripts/qapi-types.py | 5 +++++ scripts/qapi-visit.py | 31 ++++++++++++++++++++++++++++++- test-qmp-input-visitor.c | 18 ++++++++++++++++++ test-qmp-output-visitor.c | 34 ++++++++++++++++++++++++++++++++++ 5 files changed, 97 insertions(+), 1 deletions(-)
qapi-schema-test.json +10 -0
@@ -22,6 +22,16 @@ 'dict2': { 'userdef1': 'UserDefOne', 'string2': 'str' }, '*dict3': { 'userdef2': 'UserDefOne', 'string3': 'str' } } } } +# for testing unions +{ 'type': 'UserDefA', + 'data': { 'boolean': 'bool' } } + +{ 'type': 'UserDefB', + 'data': { 'integer': 'int' } } + +{ 'union': 'UserDefUnion', + 'data': { 'a' : 'UserDefA', 'b' : 'UserDefB' } } + # testing commands { 'command': 'user_def_cmd', 'data': {} } { 'command': 'user_def_cmd1', 'data': {'ud1a': 'UserDefOne'} }
scripts/qapi-types.py +5 -0
@@ -269,6 +269,7 @@ for expr in exprs: elif expr.has_key('union'): ret += generate_fwd_struct(expr['union'], expr['data']) + "\n" ret += generate_enum('%sKind' % expr['union'], expr['data'].keys()) + fdef.write(generate_enum_lookup('%sKind' % expr['union'], expr['data'].keys())) else: continue fdecl.write(ret)
@@ -283,6 +284,10 @@ for expr in exprs: fdef.write(generate_type_cleanup(expr['type']) + "\n") elif expr.has_key('union'): ret += generate_union(expr['union'], expr['data']) + ret += generate_type_cleanup_decl(expr['union'] + "List") + fdef.write(generate_type_cleanup(expr['union'] + "List") + "\n") + ret += generate_type_cleanup_decl(expr['union']) + fdef.write(generate_type_cleanup(expr['union']) + "\n") else: continue fdecl.write(ret)
scripts/qapi-visit.py +30 -1
@@ -110,10 +110,38 @@ def generate_visit_union(name, members): void visit_type_%(name)s(Visitor *m, %(name)s ** obj, const char *name, Error **errp) { -} + Error *err = NULL; + + visit_start_struct(m, (void **)obj, "%(name)s", name, sizeof(%(name)s), &err); + visit_type_%(name)sKind(m, &(*obj)->kind, "type", &err); + if (err) { + error_propagate(errp, err); + goto end; + } + switch ((*obj)->kind) { ''', name=name) + for key in members: + ret += mcgen(''' + case %(abbrev)s_KIND_%(enum)s: + visit_type_%(c_type)s(m, &(*obj)->%(c_name)s, "data", errp); + break; +''', + abbrev = de_camel_case(name).upper(), + enum = de_camel_case(key).upper(), + c_type=members[key], + c_name=c_var(key)) + + ret += mcgen(''' + default: + abort(); + } +end: + visit_end_struct(m, errp); +} +''') + return ret def generate_declaration(name, members, genlist=True):
@@ -242,6 +270,7 @@ for expr in exprs: fdecl.write(ret) elif expr.has_key('union'): ret = generate_visit_union(expr['union'], expr['data']) + ret += generate_visit_list(expr['union'], expr['data']) fdef.write(ret) ret = generate_decl_enum('%sKind' % expr['union'], expr['data'].keys())
test-qmp-input-visitor.c +18 -0
@@ -234,6 +234,22 @@ static void test_visitor_in_list(TestInputVisitorData *data,qapi_free_UserDefOneList (head); } +static void test_visitor_in_union (TestInputVisitorData *data, +const void *unused) +{ +Visitor *v; +Error *err =NULL ; +UserDefUnion *tmp; + + v =visitor_input_test_init (data,"{ 'type': 'b', 'data' : { 'integer': 42 } }" ); + +visit_type_UserDefUnion (v, &tmp,NULL , &err); +g_assert (err ==NULL ); + g_assert_cmpint(tmp->kind, ==, USER_DEF_UNION_KIND_B); + g_assert_cmpint(tmp->b->integer, ==, 42); +qapi_free_UserDefUnion (tmp); +} +static void input_visitor_test_add (const char *testpath,TestInputVisitorData *data,void (*test_func)(TestInputVisitorData *data,const void *user_data))
@@ -264,6 +280,8 @@ int main(int argc, char **argv) &in_visitor_data, test_visitor_in_struct_nested);input_visitor_test_add ("/visitor/input/list" , &in_visitor_data, test_visitor_in_list); +input_visitor_test_add ("/visitor/input/union" , + &in_visitor_data, test_visitor_in_union);g_test_run ();
test-qmp-output-visitor.c +34 -0
@@ -380,6 +380,38 @@ static void test_visitor_out_list_qapi_free(TestOutputVisitorData *data,qapi_free_UserDefNestedList (head); } +static void test_visitor_out_union (TestOutputVisitorData *data, +const void *unused) +{ +QObject *arg, *qvalue; +QDict *qdict, *value; + +Error *err =NULL ; + +UserDefUnion *tmp =g_malloc0 (sizeof (UserDefUnion)); + tmp->kind =USER_DEF_UNION_KIND_A ; + tmp->a =g_malloc0 (sizeof (UserDefA)); + tmp->a->boolean = true; + +visit_type_UserDefUnion (data->ov, &tmp,NULL , &err); +g_assert (err ==NULL ); + arg =qmp_output_get_qobject (data->qov); + +g_assert (qobject_type (arg) ==QTYPE_QDICT ); + qdict =qobject_to_qdict (arg); + + g_assert_cmpstr(qdict_get_str(qdict, "type"), ==, "a"); + + qvalue =qdict_get (qdict,"data" ); +g_assert (data !=NULL ); +g_assert (qobject_type (qvalue) ==QTYPE_QDICT ); + value =qobject_to_qdict (qvalue); + g_assert_cmpint(qdict_get_bool(value, "boolean"), ==, true); + +qapi_free_UserDefUnion (tmp); +QDECREF (qdict); +} +static void output_visitor_test_add (const char *testpath,TestOutputVisitorData *data,void (*test_func)(TestOutputVisitorData *data,const void *user_data))
@@ -416,6 +448,8 @@ int main(int argc, char **argv) &out_visitor_data, test_visitor_out_list);output_visitor_test_add ("/visitor/output/list-qapi-free" , &out_visitor_data, test_visitor_out_list_qapi_free); +output_visitor_test_add ("/visitor/output/union" , + &out_visitor_data, test_visitor_out_union);g_test_run ();
Signature · 1 line
1.7.7.6
Re: [Qemu-devel] [PATCH v2 2/6] qapi: complete implementation of unions
Am 01.03.2012 12:21, schrieb Paolo Bonzini:
Quoted 8 lines
Signed-off-by Paolo Bonzini <[email protected]>--- qapi-schema-test.json | 10 ++++++++++ scripts/qapi-types.py | 5 +++++ scripts/qapi-visit.py | 31 ++++++++++++++++++++++++++++++- test-qmp-input-visitor.c | 18 ++++++++++++++++++ test-qmp-output-visitor.c | 34 ++++++++++++++++++++++++++++++++++ 5 files changed, 97 insertions(+), 1 deletions(-)
Makes sense to me, but before applying this patch I'd like to get an Acked-by from Luiz.
Kevin
Luiz Capitulino
Acked-byRe: [Qemu-devel] [PATCH v2 2/6] qapi: complete implementation of unions
Quoted 10 lines · On Thu, 01 Mar 2012 14:52:02 +0100 Kevin Wolf <[email protected]> wrote:
Am 01.03.2012 12:21, schrieb Paolo Bonzini:
Quoted 8 lines
Signed-off-by Paolo Bonzini <[email protected]>--- qapi-schema-test.json | 10 ++++++++++ scripts/qapi-types.py | 5 +++++ scripts/qapi-visit.py | 31 ++++++++++++++++++++++++++++++- test-qmp-input-visitor.c | 18 ++++++++++++++++++ test-qmp-output-visitor.c | 34 ++++++++++++++++++++++++++++++++++ 5 files changed, 97 insertions(+), 1 deletions(-)
Quoted 2 lines
Makes sense to me, but before applying this patch I'd like to get an Acked-by from Luiz.
PATCH v2 3/6 rename blockdev-group-snapshot-sync
In reply to Paolo BonziniWe will add other kinds of operation. Prepare for this by adjusting the schema.
--- blockdev.c | 79 ++++++++++++++++++++++++++++------------------------- qapi-schema.json | 33 +++++++++++++++------- qmp-commands.hx | 50 ++++++++++++++++++--------------- 3 files changed, 91 insertions(+), 71 deletions(-)
blockdev.c +42 -37
@@ -716,31 +716,25 @@ void qmp_blockdev_snapshot_sync(const char *device, const char *snapshot_file,/* New and old BlockDriverState structs for group snapshots */ -typedef struct BlkGroupSnapshotStates { +typedef struct BlkTransactionStates {BlockDriverState *old_bs;BlockDriverState *new_bs; -QSIMPLEQ_ENTRY (BlkGroupSnapshotStates) entry; -}BlkGroupSnapshotStates ; +QSIMPLEQ_ENTRY (BlkTransactionStates) entry; +}BlkTransactionStates ;/* * 'Atomic' group snapshots. The snapshots are taken as a set, and if any fail * then we do not pivot any of the devices in the group, and abandon the * snapshots */ -void qmp_blockdev_group_snapshot_sync (SnapshotDevList *dev_list, -Error **errp) +void qmp_blockdev_transaction (BlockdevActionList *dev_list, +Error **errp) {int ret =0 ; -SnapshotDevList *dev_entry = dev_list; -SnapshotDev *dev_info =NULL ; -BlkGroupSnapshotStates *states; -BlockDriver *proto_drv; -BlockDriver *drv; -int flags; -const char *format; -const char *snapshot_file; +BlockdevActionList *dev_entry = dev_list; +BlkTransactionStates *states; - QSIMPLEQ_HEAD(snap_bdrv_states, BlkGroupSnapshotStates) snap_bdrv_states; + QSIMPLEQ_HEAD(snap_bdrv_states, BlkTransactionStates) snap_bdrv_states;QSIMPLEQ_INIT (&snap_bdrv_states);/* drain all i/o before any snapshots */
@@ -748,21 +742,46 @@ void qmp_blockdev_group_snapshot_sync(SnapshotDevList *dev_list,/* We don't do anything in this loop that commits us to the snapshot */ while (NULL != dev_entry) { +BlockdevAction *dev_info =NULL ; +BlockDriver *proto_drv; +BlockDriver *drv; +int flags; +const char *device; +const char *format ="qcow2" ; +const char *new_image_file =NULL ; + dev_info = dev_entry->value; dev_entry = dev_entry->next; - states =g_malloc0 (sizeof (BlkGroupSnapshotStates)); + states =g_malloc0 (sizeof (BlkTransactionStates));QSIMPLEQ_INSERT_TAIL (&snap_bdrv_states, states, entry); - states->old_bs =bdrv_find (dev_info->device); +switch (dev_info->kind) { +case BLOCKDEV_ACTION_KIND_SNAPSHOT : + device = dev_info->snapshot->device; +if (dev_info->snapshot->has_format) { + format = dev_info->snapshot->format; + } + new_image_file = dev_info->snapshot->snapshot_file; +break ; +default : +abort (); + } + + drv =bdrv_find_format (format); +if (!drv) { +error_set (errp,QERR_INVALID_BLOCK_FORMAT , format); + goto delete_and_fail; + } + states->old_bs =bdrv_find (device);if (!states->old_bs) { -error_set (errp,QERR_DEVICE_NOT_FOUND , dev_info->device); +error_set (errp,QERR_DEVICE_NOT_FOUND , device); goto delete_and_fail; }if (bdrv_in_use (states->old_bs)) { -error_set (errp,QERR_DEVICE_IN_USE , dev_info->device); +error_set (errp,QERR_DEVICE_IN_USE , device); goto delete_and_fail; }
@@ -775,44 +794,30 @@ void qmp_blockdev_group_snapshot_sync(SnapshotDevList *dev_list, } } - snapshot_file = dev_info->snapshot_file; - flags = states->old_bs->open_flags; -if (!dev_info->has_format) { - format ="qcow2" ; - }else { - format = dev_info->format; - } - - drv =bdrv_find_format (format); -if (!drv) { -error_set (errp,QERR_INVALID_BLOCK_FORMAT , format); - goto delete_and_fail; - } - - proto_drv =bdrv_find_protocol (snapshot_file); + proto_drv =bdrv_find_protocol (new_image_file);if (!proto_drv) {error_set (errp,QERR_INVALID_BLOCK_FORMAT , format); goto delete_and_fail; }/* create new image w/backing file */ - ret =bdrv_img_create (snapshot_file, format, + 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 , snapshot_file); +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 ("" ); - ret =bdrv_open (states->new_bs, snapshot_file, + ret =bdrv_open (states->new_bs, new_image_file, flags |BDRV_O_NO_BACKING , drv);if (ret !=0 ) { -error_set (errp,QERR_OPEN_FILE_FAILED , snapshot_file); +error_set (errp,QERR_OPEN_FILE_FAILED , new_image_file); goto delete_and_fail; } }
qapi-schema.json +22 -11
@@ -1118,7 +1118,7 @@ { 'command': 'block_resize', 'data': { 'device': 'str', 'size': 'int' }} ## -# @SnapshotDev +# @BlockdevSnapshot # # @device: the name of the device to generate the snapshot from. #
@@ -1126,19 +1126,30 @@ # # @format: #optional the format of the snapshot image, default is 'qcow2'. ## -{ 'type': 'SnapshotDev', - 'data': {'device': 'str', 'snapshot-file': 'str', '*format': 'str' } } +{ 'type': 'BlockdevSnapshot', + 'data': { 'device': 'str', 'snapshot-file': 'str', '*format': 'str' } } + +## +# @BlockdevAction +# +# A discriminated record of operations that can be performed with +# @blockdev-transaction. +## +{ 'union': 'BlockdevAction', + 'data': { + 'snapshot': 'BlockdevSnapshot' + } } ## -# @blockdev-group-snapshot-sync +# @blockdev-transaction # -# Generates a synchronous snapshot of a group of one or more block devices, -# as atomically as possible. If the snapshot of any device in the group -# fails, then the entire group snapshot will be abandoned and the -# appropriate error returned. +# Atomically operate on a group of one or more block devices. If +# any operation fails, then the entire set of actions will be +# abandoned and the appropriate error returned. The only operation +# supported is currently snapshot. # # List of: -# @SnapshotDev: information needed for the device snapshot +# @BlockdevAction: information needed for the device snapshot # # Returns: nothing on success # If @device is not a valid block device, DeviceNotFound
@@ -1152,8 +1163,8 @@ # returned in an error condition, and subsequent devices will not have been # attempted. ## -{ 'command': 'blockdev-group-snapshot-sync', - 'data': { 'devlist': [ 'SnapshotDev' ] } } +{ 'command': 'blockdev-transaction', + 'data': { 'actions': [ 'BlockdevAction' ] } } ## # @blockdev-snapshot-sync
qmp-commands.hx +27 -23
68 lines not on this page · raw message
Signature · 1 line
1.7.7.6
PATCH v2 4/6 add reuse field
In reply to Paolo Bonzini--- blockdev.c | 18 +++++++++++------- qapi-schema.json | 3 ++- qmp-commands.hx | 10 ++++++++++ 3 files changed, 23 insertions(+), 8 deletions(-)
blockdev.c +11 -7
@@ -749,6 +749,7 @@ void qmp_blockdev_transaction(BlockdevActionList *dev_list,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,6 +761,7 @@ 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_format) { format = dev_info->snapshot->format; }
@@ -803,13 +805,15 @@ void qmp_blockdev_transaction(BlockdevActionList *dev_list, }/* create new image w/backing file */ - 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; +if (do_snapshot) { + 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 */
qapi-schema.json +2 -1
@@ -1127,7 +1127,8 @@ # @format: #optional the format of the snapshot image, default is 'qcow2'. ## { 'type': 'BlockdevSnapshot', - 'data': { 'device': 'str', 'snapshot-file': 'str', '*format': 'str' } } + 'data': { 'device': 'str', 'snapshot-file': 'str', '*format': 'str', + '*reuse': 'bool' } } ## # @BlockdevAction
qmp-commands.hx +10 -0
@@ -705,6 +705,13 @@ 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. +Each new snapshot defaults to being created by QEMU (wiping any +contents if the file already exists), but it is also possible to reuse +an externally-created file. In the latter case, you should ensure that +the new image file has the same contents as the current one; QEMU cannot +perform any meaningful check. Typically this is achieved by using the +current image file as the backing file for the new image. + Arguments: actions array:
@@ -715,6 +722,8 @@ actions array: - "device": device name to snapshot (json-string) - "snapshot-file": name of new 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:
@@ -725,6 +734,7 @@ Example: "format": "qcow2" } }, { 'type': 'snapshot, 'data' : { "device": "ide-hd1", "snapshot-file": "/some/place/my-image2", + "reuse": true, "format": "qcow2" } } ] } } <- { "return": {} }
Signature · 1 line
1.7.7.6
PATCH v2 5/6 Add blkmirror block driver
In reply to Paolo BonziniFrom: Marcelo Tosatti <[email protected]>
Mirrored writes are used by live block copy.
--- Makefile.objs | 2 +- block/blkmirror.c | 239 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 240 insertions(+), 1 deletions(-) create mode 100644 block/blkmirror.c
Makefile.objs +1 -1
@@ -74,7 +74,7 @@ fsdev-obj-$(CONFIG_VIRTFS) += $(addprefix fsdev/, $(fsdev-nested-y)) # suppress *all* target specific code in case of system emulation, i.e. a # single QEMU executable should support all CPUs and machines. -common-obj-y = $(block-obj-y) blockdev.o +common-obj-y = $(block-obj-y) blockdev.o block/blkmirror.o common-obj-y += $(net-obj-y) common-obj-y += $(qobject-obj-y) common-obj-$(CONFIG_LINUX) += $(fsdev-obj-$(CONFIG_LINUX))
block/blkmirror.c new file +239 -0
239 lines not on this page · raw message
Signature · 1 line
1.7.7.6
PATCH v2 6/6 add mirroring to blockdev-transaction
In reply to Paolo Bonzini--- blockdev.c | 42 ++++++++++++++++++++++++++++++++---------- qapi-schema.json | 19 ++++++++++++++++++- qmp-commands.hx | 12 +++++++++++- 3 files changed, 61 insertions(+), 12 deletions(-)
blockdev.c +33 -10
@@ -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 ; }
qapi-schema.json +18 -1
@@ -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', } } ##
qmp-commands.hx +11 -1
@@ -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:
Signature · 1 line
1.7.7.6
Quoted 1 line · On Thu, 1 Mar 2012 12:21:42 +0100 Paolo Bonzini <[email protected]> wrote:
This implements all ingredients to establish mirrored writes.
This looks good to me. I just have two comments:
1. I'm wondering if it would make more sense to have this transaction operation in qmp instead of the block layer. Looks more complex to do though, so I'm ok with this implementation
2. Anthony had a different proposal for this and would be good to get input from him. I pinged him on irc and he said he will try to review this series later today
Am 01.03.2012 17:02, schrieb Luiz Capitulino:
Quoted 10 lines
Quoted 1 line · On Thu, 1 Mar 2012 12:21:42 +0100 Paolo Bonzini <[email protected]> wrote:
This implements all ingredients to establish mirrored writes.
This looks good to me. I just have two comments:
1. I'm wondering if it would make more sense to have this transaction operation in qmp instead of the block layer. Looks more complex to do though, so I'm ok with this implementation
Depends on what you're thinking of. Renaming the command to just 'transaction' and allowing anything to be added to the union wouldn't be very complex.
The one thing we would need to change in order to make it generally useful is to move the actual logic into prepare/commit/abort handlers. I discussed this with Paolo on IRC and I think the conclusion was that for now the approach in the patches is good enough, but in the long run we'll switch. It doesn't affect external interfaces, so we can do it whenever we like.
Kevin
Quoted 16 lines · On Thu, 01 Mar 2012 17:18:04 +0100 Kevin Wolf <[email protected]> wrote:
Am 01.03.2012 17:02, schrieb Luiz Capitulino:
Quoted 10 lines
Quoted 1 line · On Thu, 1 Mar 2012 12:21:42 +0100 Paolo Bonzini <[email protected]> wrote:
This implements all ingredients to establish mirrored writes.
This looks good to me. I just have two comments:
1. I'm wondering if it would make more sense to have this transaction operation in qmp instead of the block layer. Looks more complex to do though, so I'm ok with this implementation
Depends on what you're thinking of. Renaming the command to just 'transaction' and allowing anything to be added to the union wouldn't be very complex.
Quoted 6 lines
The one thing we would need to change in order to make it generally useful is to move the actual logic into prepare/commit/abort handlers. I discussed this with Paolo on IRC and I think the conclusion was that for now the approach in the patches is good enough, but in the long run we'll switch. It doesn't affect external interfaces, so we can do it whenever we like.
Yes, that's what I called "transaction operation in qmp", but I don't mind accepting this one and deferring the more complex idea to the future.
Quoted 30 lines · Paolo Bonzini
This implements all ingredients to establish mirrored writes. The drive-reopen command that is used to terminate mirrored writes is not included in this series.
Tested with the following scenarios:
a) mirror only
1) create base.qcow2 and start QEMU with it
2) Execute the following QMP command
{ "execute": "
qmp_capabilities" }
{ "execute": "blockdev-transaction", "arguments":{'actions': [ { 'type': 'mirror', 'data' : { 'device': 'ide0-hd0', 'target': '/home/pbonzini/mirror.qcow2' } } ] } }{ "execute": "cont" }
3) hibernate the guest (this requires an IDE disk and -cpu kvm64,-kvmclock)
4) restart the guest with mirror.qcow2
b) atomic snapshot+mirror
1) start QEMU with an existing image test.img
2) Execute the following QMP command
Quoted 8 lines
{ "execute": "
qmp_capabilities" }
{ "execute": "blockdev-transaction", "arguments":{'actions': [ { 'type': 'snapshot', 'data' : { 'device': 'ide0-hd0', 'snapshot-file': '/home/pbonzini/base.qcow2' } }, { 'type': 'mirror', 'data' : { 'device': 'ide0-hd0', 'target': '/home/pbonzini/mirror.qcow2' } } ] } }{ "execute": "cont" }
We don't have schema introspection today. How would one determine when new transaction types are available?
I think we need some sort of introspection method too in order for clients to figure out when the command is extended.
Regards,
Anthony Liguori
Quoted 42 lines
3) hibernate the guest (this requires an IDE disk and -cpu kvm64,-kvmclock)
4) check that mirror.qcow2 has test.img as the base
5) restart the guest with base.qcow2
6) restart the guest with mirror.qcow2
v1->v2:
Removed wrong assertions in patches 3 and 6
Movenew_image_fileand other variables inside the while loop (Federico) Renamenew_source_filetonew_source(Federico)
Fix image name in error message (Federico)
Fixed documentation in qapi-schema.json (Federico)
Fixed documentation and example in qmp-commands.hx (Eric) Added back AIO (Stefan), with fixes to cancellationMarcelo Tosatti (1):
Add blkmirror block driverPaolo Bonzini (5):
fix format name for backing file
qapi: complete implementation of unions
rename blockdev-group-snapshot-sync
add reuse field
add mirroring to blockdev-transactionMakefile.objs | 2 +- block/blkmirror.c | 239 +++++++++++++++++++++++++++++++++++++++++++++ blockdev.c | 114 ++++++++++++++-------- qapi-schema-test.json | 10 ++ qapi-schema.json | 51 ++++++++-- qmp-commands.hx | 68 +++++++++---- scripts/qapi-types.py | 5 + scripts/qapi-visit.py | 31 ++++++- test-qmp-input-visitor.c | 18 ++++ test-qmp-output-visitor.c | 34 +++++++ 10 files changed, 496 insertions(+), 76 deletions(-)create mode 100644
block/blkmirror.c
Quoted 13 lines · Anthony Liguori
Quoted 4 lines
2) Execute the following QMP command
{ "execute": "
qmp_capabilities" }
{ "execute": "blockdev-transaction", "arguments":Quoted 8 lines
{'actions': [ { 'type': 'snapshot', 'data' : { 'device': 'ide0-hd0', 'snapshot-file': '/home/pbonzini/base.qcow2' } }, { 'type': 'mirror', 'data' : { 'device': 'ide0-hd0', 'target': '/home/pbonzini/mirror.qcow2' } } ] } }{ "execute": "cont" }
Quoted 6 lines
We don't have schema introspection today. How would one determine when new transaction types are available?
I think we need some sort of introspection method too in order for clients to figure out when the command is extended.
I agree that introspection is necessary. Up till now, libvirt could get by with query-commands (either a command exists or it doesn't). But now we have the case where blockdev-transaction might exist, but doesn't support the particular union action such as 'mirror' that libvirt wants to use.
Could this be something we wire up to the query-commands command?
Something like:
{ 'type': 'CommandInfo', 'data': {'name': 'str', '*syntax': 'str'} } { 'command': 'query-commands,
'data': { '*syntax': 'bool', '*names': ['str'] }, 'returns': ['CommandInfo'] }
where the normal {"execute":"qemu-commands"} just returns the list of command names, but {"execute":"qemu-commands", "arguments": { "syntax":
"true", "names" : [ "blockdev-transaction" ] } } then returns:
{"return":[{"name":"blockdev-transaction", "syntax":"{ 'command' ... }"}], "id":"..."}
that is, return back the qapi-schema.json description of the command. Actually, I'd guess you'd also want to be able to query 'type' listings, not just 'command's, so maybe this deserves a new monitor command rather than shoe-horning it onto an existing one.
Signature · 2 lines
Eric Blake [email protected] +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Quoted 40 lines · Eric Blake
Quoted 13 lines · Anthony Liguori
Quoted 4 lines
2) Execute the following QMP command
{ "execute": "
qmp_capabilities" }
{ "execute": "blockdev-transaction", "arguments":Quoted 8 lines
{'actions': [ { 'type': 'snapshot', 'data' : { 'device': 'ide0-hd0', 'snapshot-file': '/home/pbonzini/base.qcow2' } }, { 'type': 'mirror', 'data' : { 'device': 'ide0-hd0', 'target': '/home/pbonzini/mirror.qcow2' } } ] } }{ "execute": "cont" }
Quoted 6 lines
We don't have schema introspection today. How would one determine when new transaction types are available?
I think we need some sort of introspection method too in order for clients to figure out when the command is extended.
I agree that introspection is necessary. Up till now, libvirt could get by with query-commands (either a command exists or it doesn't). But now we have the case where blockdev-transaction might exist, but doesn't support the particular union action such as 'mirror' that libvirt wants to use.
Could this be something we wire up to the query-commands command?
Something like:
{ 'type': 'CommandInfo', 'data': {'name': 'str', '*syntax': 'str'} } { 'command': 'query-commands,
'data': { '*syntax': 'bool', '*names': ['str'] }, 'returns': ['CommandInfo'] }where the normal {"execute":"qemu-commands"} just returns the list of command names, but {"execute":"qemu-commands", "arguments": { "syntax":
"true", "names" : [ "blockdev-transaction" ] } } then returns:
Quoted 7 lines
{"return":[{"name":"blockdev-transaction", "syntax":"{ 'command' ... }"}], "id":"..."}
that is, return back the qapi-schema.json description of the command. Actually, I'd guess you'd also want to be able to query 'type' listings, not just 'command's, so maybe this deserves a new monitor command rather than shoe-horning it onto an existing one.
Yes, this is what I would like to do, but it's a requires a bit of work to implement. You'd have to either install qapi-schema.json and read it at run time or serialize it to a C data structure that can then be used to initialize a QObject.
Nothing Earth shattering, just a fair amount of bit moving.
Regards,
Anthony Liguori
Quoted 1 line
Quoted 49 lines · Anthony Liguori
Quoted 40 lines · Eric Blake
Quoted 13 lines · Anthony Liguori
Quoted 12 lines
2) Execute the following QMP command
{ "execute": "
qmp_capabilities" }
{ "execute": "blockdev-transaction", "arguments":
{'actions': [
{ 'type': 'snapshot', 'data' :
{ 'device': 'ide0-hd0', 'snapshot-file':
'/home/pbonzini/base.qcow2' } },
{ 'type': 'mirror', 'data' :
{ 'device': 'ide0-hd0', 'target': '/home/pbonzini/mirror.qcow2' } } ] } }
{ "execute": "cont" }Quoted 6 lines
We don't have schema introspection today. How would one determine when new transaction types are available?
I think we need some sort of introspection method too in order for clients to figure out when the command is extended.
I agree that introspection is necessary. Up till now, libvirt could get by with query-commands (either a command exists or it doesn't). But now we have the case where blockdev-transaction might exist, but doesn't support the particular union action such as 'mirror' that libvirt wants to use.
Could this be something we wire up to the query-commands command?
Something like:
{ 'type': 'CommandInfo', 'data': {'name': 'str', '*syntax': 'str'} } { 'command': 'query-commands,
'data': { '*syntax': 'bool', '*names': ['str'] }, 'returns': ['CommandInfo'] }where the normal {"execute":"qemu-commands"} just returns the list of command names, but {"execute":"qemu-commands", "arguments": { "syntax":
"true", "names" : [ "blockdev-transaction" ] } } then returns:Quoted 7 lines
{"return":[{"name":"blockdev-transaction", "syntax":"{ 'command' ... }"}], "id":"..."}
that is, return back the qapi-schema.json description of the command. Actually, I'd guess you'd also want to be able to query 'type' listings, not just 'command's, so maybe this deserves a new monitor command rather than shoe-horning it onto an existing one.
Quoted 6 lines
Yes, this is what I would like to do, but it's a requires a bit of work to implement. You'd have to either install qapi-schema.json and read it at run time or serialize it to a C data structure that can then be used to initialize a QObject.
Nothing Earth shattering, just a fair amount of bit moving.
BTW, in the short term, this can be addressed with careful documentation. Just make it clear that in the absence of introspection, the only two supported operations are what's currently here.
And realize that to add new commands in the future, we need introspection first.
Regards,
Anthony Liguori
Quoted 8 lines
Regards,
Anthony Liguori
Quoted 1 line
Am 01.03.2012 22:10, schrieb Anthony Liguori:
Quoted 40 lines · Paolo Bonzini
Quoted 30 lines
This implements all ingredients to establish mirrored writes. The drive-reopen command that is used to terminate mirrored writes is not included in this series.
Tested with the following scenarios:
a) mirror only
1) create base.qcow2 and start QEMU with it
2) Execute the following QMP command
{ "execute": "
qmp_capabilities" }
{ "execute": "blockdev-transaction", "arguments":{'actions': [ { 'type': 'mirror', 'data' : { 'device': 'ide0-hd0', 'target': '/home/pbonzini/mirror.qcow2' } } ] } }{ "execute": "cont" }
3) hibernate the guest (this requires an IDE disk and -cpu kvm64,-kvmclock)
4) restart the guest with mirror.qcow2
b) atomic snapshot+mirror
1) start QEMU with an existing image test.img
2) Execute the following QMP command
Quoted 8 lines
{ "execute": "
qmp_capabilities" }
{ "execute": "blockdev-transaction", "arguments":{'actions': [ { 'type': 'snapshot', 'data' : { 'device': 'ide0-hd0', 'snapshot-file': '/home/pbonzini/base.qcow2' } }, { 'type': 'mirror', 'data' : { 'device': 'ide0-hd0', 'target': '/home/pbonzini/mirror.qcow2' } } ] } }{ "execute": "cont" }
Quoted 5 lines
We don't have schema introspection today. How would one determine when new transaction types are available?
I think we need some sort of introspection method too in order for clients to figure out when the command is extended.
How about coupling the types with independently available commands for now? We would rename 'snapshot' to 'blockdev-snapshot-sync', which does the same thing outside of transactions. The mirror patches would then introduce a 'drive-mirror' top-level command at the same time as they introduce a 'drive-mirror' transaction type.
Kevin
Il 05/03/2012 09:53, Kevin Wolf ha scritto:
Quoted 8 lines
Quoted 3 lines
Quoted 3 lines
I think we need some sort of introspection method too in order for clients to figure out when the command is extended.
How about coupling the types with independently available commands for now? We would rename 'snapshot' to 'blockdev-snapshot-sync', which does the same thing outside of transactions. The mirror patches would then introduce a 'drive-mirror' top-level command at the same time as they introduce a 'drive-mirror' transaction type.
Makes sense. It would also be a good excuse to port blockdev-snapshot-sync to the new fail-safe way. I'll refresh my patches if there's consensus.
Paolo
Am 05.03.2012 10:28, schrieb Paolo Bonzini:
Quoted 10 lines
Il 05/03/2012 09:53, Kevin Wolf ha scritto:
Quoted 8 lines
Quoted 3 lines
Quoted 3 lines
I think we need some sort of introspection method too in order for clients to figure out when the command is extended.
How about coupling the types with independently available commands for now? We would rename 'snapshot' to 'blockdev-snapshot-sync', which does the same thing outside of transactions. The mirror patches would then introduce a 'drive-mirror' top-level command at the same time as they introduce a 'drive-mirror' transaction type.
Quoted 3 lines
Makes sense. It would also be a good excuse to port blockdev-snapshot-sync to the new fail-safe way. I'll refresh my patches if there's consensus.
Will you also replace 'blockdev-transaction' by 'transaction' to keep things generic at the interface level? The necessary refactoring to actually make it useful outside the block layer can come later, but we can leave the external API stable then.
Kevin
Il 05/03/2012 13:13, Kevin Wolf ha scritto:
Quoted 8 lines
Quoted 3 lines
Makes sense. It would also be a good excuse to port blockdev-snapshot-sync to the new fail-safe way. I'll refresh my patches if there's consensus.
Will you also replace 'blockdev-transaction' by 'transaction' to keep things generic at the interface level? The necessary refactoring to actually make it useful outside the block layer can come later, but we can leave the external API stable then.
Ok.
Paolo
Quoted 44 lines · Kevin Wolf
Am 01.03.2012 22:10, schrieb Anthony Liguori:
Quoted 43 lines · Paolo Bonzini
Quoted 30 lines
This implements all ingredients to establish mirrored writes. The drive-reopen command that is used to terminate mirrored writes is not included in this series.
Tested with the following scenarios:
a) mirror only
1) create base.qcow2 and start QEMU with it
2) Execute the following QMP command
{ "execute": "
qmp_capabilities" }
{ "execute": "blockdev-transaction", "arguments":{'actions': [ { 'type': 'mirror', 'data' : { 'device': 'ide0-hd0', 'target': '/home/pbonzini/mirror.qcow2' } } ] } }{ "execute": "cont" }
3) hibernate the guest (this requires an IDE disk and -cpu kvm64,-kvmclock)
4) restart the guest with mirror.qcow2
b) atomic snapshot+mirror
1) start QEMU with an existing image test.img
2) Execute the following QMP command
Quoted 8 lines
{ "execute": "
qmp_capabilities" }
{ "execute": "blockdev-transaction", "arguments":{'actions': [ { 'type': 'snapshot', 'data' : { 'device': 'ide0-hd0', 'snapshot-file': '/home/pbonzini/base.qcow2' } }, { 'type': 'mirror', 'data' : { 'device': 'ide0-hd0', 'target': '/home/pbonzini/mirror.qcow2' } } ] } }{ "execute": "cont" }
We don't have schema introspection today. How would one determine when new transaction types are available?
Quoted 8 lines
Quoted 2 lines
I think we need some sort of introspection method too in order for clients to figure out when the command is extended.
How about coupling the types with independently available commands for now? We would rename 'snapshot' to 'blockdev-snapshot-sync', which does the same thing outside of transactions. The mirror patches would then introduce a 'drive-mirror' top-level command at the same time as they introduce a 'drive-mirror' transaction type.
I think it's reasonable but we need to make sure to document the relationship here explicitly in the schema.
Regards,
Anthony Liguori
Quoted 2 lines
Kevin
Il 05/03/2012 15:47, Anthony Liguori ha scritto:
Quoted 8 lines
Quoted 5 lines
How about coupling the types with independently available commands for now? We would rename 'snapshot' to 'blockdev-snapshot-sync', which does the same thing outside of transactions. The mirror patches would then introduce a 'drive-mirror' top-level command at the same time as they introduce a 'drive-mirror' transaction type.
I think it's reasonable but we need to make sure to document the relationship here explicitly in the schema.
We can easily add a query-commands-transaction that returns the commands that can be placed in a transaction.
Paolo