Patchwork [1/4] spice: notify spice server on vm start/stop

login
register
mail settings
Submitter Yonit Halperin
Date Aug. 16, 2012, 8:23 a.m.
Message ID <1345105406-15082-2-git-send-email-yhalperi@redhat.com>
Download mbox | patch
Permalink /patch/177916/
State New
Headers show

Comments

Yonit Halperin - Aug. 16, 2012, 8:23 a.m.
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.

Signed-off-by: Yonit Halperin <yhalperi@redhat.com>
---
 ui/spice-core.c |   14 ++++++++++++++
 1 files changed, 14 insertions(+), 0 deletions(-)
Gerd Hoffmann - Aug. 16, 2012, 9:42 a.m.
On 08/16/12 10:23, Yonit Halperin wrote:
> 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
Yonit Halperin - Aug. 16, 2012, 1 p.m.
On 08/16/2012 12:42 PM, Gerd Hoffmann wrote:
> On 08/16/12 10:23, Yonit Halperin wrote:
>> 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.

>
> cheers,
>    Gerd
>
>
Gerd Hoffmann - Aug. 16, 2012, 6:19 p.m.
On 08/16/12 15:00, Yonit Halperin wrote:
> On 08/16/2012 12:42 PM, Gerd Hoffmann wrote:
>> On 08/16/12 10:23, Yonit Halperin wrote:
>>> 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.

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

Patch

diff --git a/ui/spice-core.c b/ui/spice-core.c
index 4fc48f8..32de1f1 100644
--- a/ui/spice-core.c
+++ b/ui/spice-core.c
@@ -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);