add support for spice migration
cover add support for spice migration
The following series introduces support for keeping the spice session active after migration. For more details about spice seamless migration, see
http://lists.freedesktop.org/archives/spice-devel/2012-August/010412.html
Spice branches with seamless migration support can be found at:
spice-protocol: http://cgit.freedesktop.org/~yhalperi/spice-protocol/log/?h=seamless-migration.v1
spice-common: http://cgit.freedesktop.org/~yhalperi/spice-common/log/
spice: http://cgit.freedesktop.org/~yhalperi/spice/log/?h=seamless-migration.v1
spicei-gtk: http://cgit.freedesktop.org/~yhalperi/spice-gtk/log/
Regards,
Yonit.
Yonit Halperin (4):
spice: notify spice server on vm start/stop
spice migration: add QEVENT_SPICE_MIGRATE_COMPLETED
spice: add 'migrated' flag to spice info
spice: adding seamless-migration option to the command line
hmp.c | 2 ++ monitor.c | 1 + monitor.h | 1 + qapi-schema.json | 5 ++++- qemu-config.c | 3 +++ qemu-options.hx | 3 +++ ui/spice-core.c | 34 +++++++++++++++++++++++++++++++++- 7 files changed, 47 insertions(+), 2 deletions(-)
Signature · 1 line
1.7.7.6
PATCH 1/4 spice: notify spice server on vm start/stop
Spice server needs to know about the vm state in order to prevent attempts to write to devices when they are stopped, mainly during the non-live stage of migration.
Instead, spice will take care of restoring this writes, on the migration target side, after migration completes.
--- ui/spice-core.c | 14 ++++++++++++++ 1 files changed, 14 insertions(+), 0 deletions(-)
ui/spice-core.c +14 -0
@@ -545,6 +545,18 @@ static int add_channel(const char *name, const char *value, void *opaque)return 0 ; } +static void vm_change_state_handler (void *opaque,int running, +RunState state) +{ +#if SPICE_SERVER_VERSION >=0x000b02 /* 0.11.2 */ +if (running) { +spice_server_vm_start (spice_server); + }else { +spice_server_vm_stop (spice_server); + } +#endif +} +void qemu_spice_init (void ) {QemuOpts *opts =QTAILQ_FIRST (&qemu_spice_opts.head);
@@ -718,6 +730,8 @@ void qemu_spice_init(void)qemu_spice_input_init ();qemu_spice_audio_init (); +qemu_add_vm_change_state_handler (vm_change_state_handler, &spice_server); +g_free (x509_key_file);g_free (x509_cert_file);g_free (x509_cacert_file);
Signature · 1 line
1.7.7.6
PATCH 2/4 spice migration: add QEVENT_SPICE_MIGRATE_COMPLETED
In reply to Yonit HalperinWhen migrating, libvirt queries the migration status, and upon migration completions, it closes the migration src. On the other hand, when migration is completed, spice transfers data from the src to destination via the client. This data is required for keeping the spice session after migration, without suffering from data loss and inconsistencies. In order to allow this data transfer, we add QEVENT for signaling libvirt that spice migration has completed, and libvirt needs to wait for this event before quitting the src process.
--- monitor.c | 1 + monitor.h | 1 + ui/spice-core.c | 9 ++++++++- 3 files changed, 10 insertions(+), 1 deletions(-)
monitor.c +1 -0
@@ -455,6 +455,7 @@ static const char *monitor_event_names[] = { [QEVENT_SUSPEND_DISK] = "SUSPEND_DISK", [QEVENT_WAKEUP] = "WAKEUP", [QEVENT_BALLOON_CHANGE] = "BALLOON_CHANGE", + [QEVENT_SPICE_MIGRATE_COMPLETED ] ="SPICE_MIGRATE_COMPLETED" , };QEMU_BUILD_BUG_ON (ARRAY_SIZE (monitor_event_names) !=QEVENT_MAX )
monitor.h +1 -0
@@ -43,6 +43,7 @@ typedef enum MonitorEvent {QEVENT_SUSPEND_DISK ,QEVENT_WAKEUP ,QEVENT_BALLOON_CHANGE , + QEVENT_SPICE_MIGRATE_COMPLETED,/* Add to 'monitor_event_names' array in monitor.c when * defining new events here */
ui/spice-core.c +8 -1
@@ -284,6 +284,7 @@ typedef struct SpiceMigration { } SpiceMigration;static void migrate_connect_complete_cb (SpiceMigrateInstance *sin); +static void migrate_end_complete_cb (SpiceMigrateInstance *sin);static const SpiceMigrateInterface migrate_interface = { .base.type =SPICE_INTERFACE_MIGRATION ,
@@ -291,7 +292,7 @@ static const SpiceMigrateInterface migrate_interface = { .base.major_version = SPICE_INTERFACE_MIGRATION_MAJOR, .base.minor_version = SPICE_INTERFACE_MIGRATION_MINOR, .migrate_connect_complete = migrate_connect_complete_cb, - .migrate_end_complete = NULL, + .migrate_end_complete = migrate_end_complete_cb, };static SpiceMigration spice_migrate;
@@ -304,6 +305,11 @@ static void migrate_connect_complete_cb(SpiceMigrateInstance *sin) } sm->connect_complete.cb =NULL ; } + +static void migrate_end_complete_cb (SpiceMigrateInstance *sin) +{ +monitor_protocol_event (QEVENT_SPICE_MIGRATE_COMPLETED ,NULL ); +}#endif /* config string parsing */
@@ -487,6 +493,7 @@ static void migration_state_notifier(Notifier *notifier, void *data) }else if (migration_has_finished (s)) {#ifndef SPICE_INTERFACE_MIGRATION spice_server_migrate_switch (spice_server); +monitor_protocol_event (QEVENT_SPICE_MIGRATE_COMPLETED ,NULL );#else spice_server_migrate_end(spice_server, true); }else if (migration_has_failed (s)) {
Signature · 1 line
1.7.7.6
PATCH 3/4 spice: add 'migrated' flag to spice info
In reply to Yonit HalperinThe flag is 'true' when spice migration has completed on the src side. It is needed for a case where libvirt dies before migration completes and it misses the event QEVENT_SPICE_MIGRATE_COMPLETED.
When libvirt is restored and queries the migration status, it also needs to query spice and check if its migration has completed.
--- hmp.c | 2 ++ qapi-schema.json | 5 ++++- ui/spice-core.c | 4 ++++ 3 files changed, 10 insertions(+), 1 deletions(-)
hmp.c +2 -0
@@ -413,6 +413,8 @@ void hmp_info_spice(Monitor *mon)monitor_printf (mon," address: %s:%" PRId64" [tls]\n" , info->host, info->tls_port); } +monitor_printf (mon," migrated: %s\n" , + info->migrated ?"true" :"false" );monitor_printf (mon," auth: %s\n" , info->auth);monitor_printf (mon," compiled: %s\n" , info->compiled_version); monitor_printf(mon, " mouse-mode: %s\n",
qapi-schema.json +4 -1
@@ -808,6 +808,9 @@ # # @enabled: true if the SPICE server is enabled, false otherwise # +# @migrated: true if the last guest migration completed and spice +# migration had completed as well. false otherwise. +# # @host: #optional The hostname the SPICE server is bound to. This depends on # the name resolution on the host and may be an IP address. #
@@ -833,7 +836,7 @@ # Since: 0.14.0 ## { 'type': 'SpiceInfo', - 'data': {'enabled': 'bool', '*host': 'str', '*port': 'int', + 'data': {'enabled': 'bool', 'migrated': 'bool', '*host': 'str', '*port': 'int', '*tls-port': 'int', '*auth': 'str', '*compiled-version': 'str', 'mouse-mode': 'SpiceQueryMouseMode', '*channels': ['SpiceChannel']} }
ui/spice-core.c +4 -0
@@ -45,6 +45,7 @@ static Notifier migration_state;static const char *auth ="spice" ;static char *auth_passwd;static time_t auth_expires =TIME_MAX ; +static int spice_migration_completed;int using_spice =0 ;static QemuThread me;
@@ -309,6 +310,7 @@ static void migrate_connect_complete_cb(SpiceMigrateInstance *sin)static void migrate_end_complete_cb (SpiceMigrateInstance *sin) {monitor_protocol_event (QEVENT_SPICE_MIGRATE_COMPLETED ,NULL ); + spice_migration_completed = true; }#endif
@@ -441,6 +443,7 @@ SpiceInfo *qmp_query_spice(Error **errp) } info->enabled = true; + info->migrated = spice_migration_completed; addr =qemu_opt_get (opts,"addr" ); port =qemu_opt_get_number (opts,"port" ,0 );
@@ -494,6 +497,7 @@ static void migration_state_notifier(Notifier *notifier, void *data)#ifndef SPICE_INTERFACE_MIGRATION spice_server_migrate_switch (spice_server);monitor_protocol_event (QEVENT_SPICE_MIGRATE_COMPLETED ,NULL ); + spice_migration_completed = true;#else spice_server_migrate_end(spice_server, true); }else if (migration_has_failed (s)) {
Signature · 1 line
1.7.7.6
PATCH 4/4 spice: adding seamless-migration option to the command line
In reply to Yonit HalperinThe seamless-migration flag is required in order to identify
whether libvirt supports the new QEVENT_SPICE_MIGRATE_COMPLETED or not
(by default the flag is off).
New libvirt versions that wait for QEVENT_SPICE_MIGRATE_COMPLETED should turn on this flag. When this flag is off, spice fallbacks to its old migration method, which can result in data loss.
--- qemu-config.c | 3 +++ qemu-options.hx | 3 +++ ui/spice-core.c | 7 +++++++ 3 files changed, 13 insertions(+), 0 deletions(-)
qemu-config.c +3 -0
@@ -524,6 +524,9 @@ QemuOptsList qemu_spice_opts = { },{ .name = "playback-compression", .type = QEMU_OPT_BOOL, + }, { + .name = "seamless-migration", + .type = QEMU_OPT_BOOL, }, {/* end of list */ } },
qemu-options.hx +3 -0
@@ -917,6 +917,9 @@ Enable/disable passing mouse events via vdagent. Default is on. @item playback-compression=[on|off] Enable/disable audio stream compression (using celt 0.5.1). Default is on. +@item seamless-migration=[on|off] +Enable/disable spice seamless migration. Default is off. + @end table ETEXI
ui/spice-core.c +7 -0
@@ -581,6 +581,9 @@ void qemu_spice_init(void)int port, tls_port, len, addr_flags;spice_image_compression_t compression;spice_wan_compression_t wan_compr; +#if SPICE_SERVER_VERSION >=0x000b02 /* 0.11.2 */ +bool seamless_migration; +#endif qemu_thread_get_self (&me);
@@ -724,6 +727,10 @@ void qemu_spice_init(void)spice_server_set_uuid (spice_server, qemu_uuid);#endif +#if SPICE_SERVER_VERSION >=0x000b02 /* 0.11.2 */ + seamless_migration =qemu_opt_get_bool (opts,"seamless-migration" ,0 ); +spice_server_set_seamless_migration (spice_server, seamless_migration); +#endif if (0 !=spice_server_init (spice_server, &core_interface)) {error_report ("failed to initialize spice server" );exit (1 );
Signature · 1 line
1.7.7.6
Re: [Qemu-devel] [PATCH 1/4] spice: notify spice server on vm start/stop
In reply to Yonit HalperinQuoted 3 lines · Yonit Halperin
Spice server needs to know about the vm state in order to prevent attempts to write to devices when they are stopped, mainly during the non-live stage of migration.
Why this new hook?
qemu already notifies spice-server using QXLWorker start/stop callbacks.
cheers,
Gerd
Re: [Qemu-devel] [PATCH 1/4] spice: notify spice server on vm start/stop
Quoted 8 lines · Gerd Hoffmann
Quoted 3 lines · Yonit Halperin
Spice server needs to know about the vm state in order to prevent attempts to write to devices when they are stopped, mainly during the non-live stage of migration.
Why this new hook?
qemu already notifies spice-server using QXLWorker start/stop callbacks.
It notifies the QXLWorker, and it goes to the display_channel. Spice api changes anyway, by adding spice_server_set_seamless_migration, and as other channels need this notification as well, it would be nicer to explicitly notify the server about the vm start/stop and not abuse the QXLWorker notification. Another option would have been to add notifier for SpiceCharDeviceInterface as well, and then to any other new interface that will require it.
Regards,
Yonit.
Quoted 5 lines
cheers,
Gerd
Re: [Qemu-devel] [PATCH 1/4] spice: notify spice server on vm start/stop
Quoted 6 lines · Yonit Halperin
Quoted 5 lines · Gerd Hoffmann
Quoted 3 lines · Yonit Halperin
Spice server needs to know about the vm state in order to prevent attempts to write to devices when they are stopped, mainly during the non-live stage of migration.
Quoted 8 lines
Quoted 3 lines
Why this new hook?
qemu already notifies spice-server using QXLWorker start/stop callbacks.
It notifies the QXLWorker, and it goes to the
display_channel. Spice api changes anyway, by addingspice_server_set_seamless_migration, and as other channels need this notification as well, it would be nicer to explicitly notify the server about the vm start/stop and not abuse the QXLWorker notification.
It is indeed cleaner API-wise. Is it possible to skip QXLWorker notification when calling the new spice_server_vm_{start,stop} functions?
cheers,
Gerd