Patchwork [2/6] spice: client migration.

login
register
mail settings
Submitter Gerd Hoffmann
Date Jan. 10, 2011, 1:31 p.m.
Message ID <1294666311-23457-3-git-send-email-kraxel@redhat.com>
Download mbox | patch
Permalink /patch/78156/
State New
Headers show

Comments

Gerd Hoffmann - Jan. 10, 2011, 1:31 p.m.
Handle spice client migration, i.e. inform a spice client connected
about the new host and connection parameters, so it can move over the
connection automatically.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hmp-commands.hx |   20 ++++++++++++++++++++
 qmp-commands.hx |   35 +++++++++++++++++++++++++++++++++++
 ui/qemu-spice.h |    1 +
 ui/spice-core.c |   40 ++++++++++++++++++++++++++++++++++++++++
 4 files changed, 96 insertions(+), 0 deletions(-)
Daniel P. Berrange - Jan. 10, 2011, 3:49 p.m.
On Mon, Jan 10, 2011 at 02:31:47PM +0100, Gerd Hoffmann wrote:
> Handle spice client migration, i.e. inform a spice client connected
> about the new host and connection parameters, so it can move over the
> connection automatically.
> 
> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
> ---
>  hmp-commands.hx |   20 ++++++++++++++++++++
>  qmp-commands.hx |   35 +++++++++++++++++++++++++++++++++++
>  ui/qemu-spice.h |    1 +
>  ui/spice-core.c |   40 ++++++++++++++++++++++++++++++++++++++++
>  4 files changed, 96 insertions(+), 0 deletions(-)
> 
> diff --git a/hmp-commands.hx b/hmp-commands.hx
> index df134f8..e6d8f36 100644
> --- a/hmp-commands.hx
> +++ b/hmp-commands.hx
> @@ -815,6 +815,26 @@ ETEXI
>      },
>  
>  STEXI
> +@item spice_migrate_info @var{hostname} @var{port} @var{tls-port} @var{cert-subject}
> +@findex spice_migrate_info
> +Set the spice connection info for the migration target.  The spice
> +server will ask the spice client to automatically reconnect using the
> +new parameters (if specified) once the vm migration finished
> +successfully.
> +ETEXI


> +
> +#if defined(CONFIG_SPICE)
> +    {
> +        .name       = "spice_migrate_info",
> +        .args_type  = "hostname:s,port:i?,tls-port:i?,cert-subject:s?",
> +        .params     = "hostname port tls-port cert-subject",
> +        .help       = "send migration info to spice client",
> +        .user_print = monitor_user_noop,
> +        .mhandler.cmd_new = mon_spice_migrate,
> +    },
> +#endif
> +
> +STEXI
>  @item snapshot_blkdev
>  @findex snapshot_blkdev
>  Snapshot device, using snapshot file as target if provided
> diff --git a/qmp-commands.hx b/qmp-commands.hx
> index 56c4d8b..24ada04 100644
> --- a/qmp-commands.hx
> +++ b/qmp-commands.hx
> @@ -503,6 +503,41 @@ EQMP
>      },
>  
>  SQMP
> +spice_migrate_info
> +------------------
> +
> +Set the spice connection info for the migration target.  The spice
> +server will ask the spice client to automatically reconnect using the
> +new parameters (if specified) once the vm migration finished
> +successfully.
> +
> +Arguments:
> +
> +- "hostname":     migration target hostname (json-string)
> +- "port":         spice tcp port for plaintext channels (json-int, optional)
> +- "tls-port":     spice tcp port for tls-secured channels (json-int, optional)
> +- "cert-subject": server certificate subject (json-string, optional)
> +
> +Example:
> +
> +-> { "execute": "spice_migrate_info",
> +     "arguments": { "hostname": "virt42.lab.kraxel.org", "port": 1234 } }
> +<- { "return": {} }

I'm wondering whether we should make this command more
generic, because I could likely write up a VNC extension
that provides the same functionality that SPICE has here.
so, 'graphics_migrate_info @var{spice|vnc|...} ...other vars..'

Regards,
Daniel
Alon Levy - Jan. 10, 2011, 3:57 p.m.
On Mon, Jan 10, 2011 at 03:49:34PM +0000, Daniel P. Berrange wrote:
> On Mon, Jan 10, 2011 at 02:31:47PM +0100, Gerd Hoffmann wrote:
> > Handle spice client migration, i.e. inform a spice client connected
> > about the new host and connection parameters, so it can move over the
> > connection automatically.
> > 
> > Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
> > ---
> >  hmp-commands.hx |   20 ++++++++++++++++++++
> >  qmp-commands.hx |   35 +++++++++++++++++++++++++++++++++++
> >  ui/qemu-spice.h |    1 +
> >  ui/spice-core.c |   40 ++++++++++++++++++++++++++++++++++++++++
> >  4 files changed, 96 insertions(+), 0 deletions(-)
> > 
> > diff --git a/hmp-commands.hx b/hmp-commands.hx
> > index df134f8..e6d8f36 100644
> > --- a/hmp-commands.hx
> > +++ b/hmp-commands.hx
> > @@ -815,6 +815,26 @@ ETEXI
> >      },
> >  
> >  STEXI
> > +@item spice_migrate_info @var{hostname} @var{port} @var{tls-port} @var{cert-subject}
> > +@findex spice_migrate_info
> > +Set the spice connection info for the migration target.  The spice
> > +server will ask the spice client to automatically reconnect using the
> > +new parameters (if specified) once the vm migration finished
> > +successfully.
> > +ETEXI
> 
> 
> > +
> > +#if defined(CONFIG_SPICE)
> > +    {
> > +        .name       = "spice_migrate_info",
> > +        .args_type  = "hostname:s,port:i?,tls-port:i?,cert-subject:s?",
> > +        .params     = "hostname port tls-port cert-subject",
> > +        .help       = "send migration info to spice client",
> > +        .user_print = monitor_user_noop,
> > +        .mhandler.cmd_new = mon_spice_migrate,
> > +    },
> > +#endif
> > +
> > +STEXI
> >  @item snapshot_blkdev
> >  @findex snapshot_blkdev
> >  Snapshot device, using snapshot file as target if provided
> > diff --git a/qmp-commands.hx b/qmp-commands.hx
> > index 56c4d8b..24ada04 100644
> > --- a/qmp-commands.hx
> > +++ b/qmp-commands.hx
> > @@ -503,6 +503,41 @@ EQMP
> >      },
> >  
> >  SQMP
> > +spice_migrate_info
> > +------------------
> > +
> > +Set the spice connection info for the migration target.  The spice
> > +server will ask the spice client to automatically reconnect using the
> > +new parameters (if specified) once the vm migration finished
> > +successfully.
> > +
> > +Arguments:
> > +
> > +- "hostname":     migration target hostname (json-string)
> > +- "port":         spice tcp port for plaintext channels (json-int, optional)
> > +- "tls-port":     spice tcp port for tls-secured channels (json-int, optional)
> > +- "cert-subject": server certificate subject (json-string, optional)
> > +
> > +Example:
> > +
> > +-> { "execute": "spice_migrate_info",
> > +     "arguments": { "hostname": "virt42.lab.kraxel.org", "port": 1234 } }
> > +<- { "return": {} }
> 
> I'm wondering whether we should make this command more
> generic, because I could likely write up a VNC extension
> that provides the same functionality that SPICE has here.
> so, 'graphics_migrate_info @var{spice|vnc|...} ...other vars..'

Considering it isn't actually just graphics how about client_migrate_info?

> 
> Regards,
> Daniel
>
Gerd Hoffmann - Jan. 10, 2011, 4:08 p.m.
On 01/10/11 16:57, Alon Levy wrote:
>>> +spice_migrate_info
>>> +------------------
>>> +
>>> +Set the spice connection info for the migration target.  The spice
>>> +server will ask the spice client to automatically reconnect using the
>>> +new parameters (if specified) once the vm migration finished
>>> +successfully.
>>> +
>>> +Arguments:
>>> +
>>> +- "hostname":     migration target hostname (json-string)
>>> +- "port":         spice tcp port for plaintext channels (json-int, optional)
>>> +- "tls-port":     spice tcp port for tls-secured channels (json-int, optional)
>>> +- "cert-subject": server certificate subject (json-string, optional)
>>> +
>>> +Example:
>>> +
>>> +->  { "execute": "spice_migrate_info",
>>> +     "arguments": { "hostname": "virt42.lab.kraxel.org", "port": 1234 } }
>>> +<- { "return": {} }
>>
>> I'm wondering whether we should make this command more
>> generic, because I could likely write up a VNC extension
>> that provides the same functionality that SPICE has here.
>> so, 'graphics_migrate_info @var{spice|vnc|...} ...other vars..'
>
> Considering it isn't actually just graphics how about client_migrate_info?

I like client_migrate_info and it fits both spice+vnc naming too.

Given that vnc just needs hostname and port (which are present already) 
and the arguments not used by vnc are optional all we need to do is 
rename the command and add a "protocol" argument similar to 
"set_password", correct?

cheers,
   Gerd
Daniel P. Berrange - Jan. 10, 2011, 4:18 p.m.
On Mon, Jan 10, 2011 at 05:08:40PM +0100, Gerd Hoffmann wrote:
> On 01/10/11 16:57, Alon Levy wrote:
> >>>+spice_migrate_info
> >>>+------------------
> >>>+
> >>>+Set the spice connection info for the migration target.  The spice
> >>>+server will ask the spice client to automatically reconnect using the
> >>>+new parameters (if specified) once the vm migration finished
> >>>+successfully.
> >>>+
> >>>+Arguments:
> >>>+
> >>>+- "hostname":     migration target hostname (json-string)
> >>>+- "port":         spice tcp port for plaintext channels (json-int, optional)
> >>>+- "tls-port":     spice tcp port for tls-secured channels (json-int, optional)
> >>>+- "cert-subject": server certificate subject (json-string, optional)
> >>>+
> >>>+Example:
> >>>+
> >>>+->  { "execute": "spice_migrate_info",
> >>>+     "arguments": { "hostname": "virt42.lab.kraxel.org", "port": 1234 } }
> >>>+<- { "return": {} }
> >>
> >>I'm wondering whether we should make this command more
> >>generic, because I could likely write up a VNC extension
> >>that provides the same functionality that SPICE has here.
> >>so, 'graphics_migrate_info @var{spice|vnc|...} ...other vars..'
> >
> >Considering it isn't actually just graphics how about client_migrate_info?
> 
> I like client_migrate_info and it fits both spice+vnc naming too.
> 
> Given that vnc just needs hostname and port (which are present
> already) and the arguments not used by vnc are optional all we need
> to do is rename the command and add a "protocol" argument similar to
> "set_password", correct?

Yeah, that sounds sufficient to me.

Regards,
Daniel

Patch

diff --git a/hmp-commands.hx b/hmp-commands.hx
index df134f8..e6d8f36 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -815,6 +815,26 @@  ETEXI
     },
 
 STEXI
+@item spice_migrate_info @var{hostname} @var{port} @var{tls-port} @var{cert-subject}
+@findex spice_migrate_info
+Set the spice connection info for the migration target.  The spice
+server will ask the spice client to automatically reconnect using the
+new parameters (if specified) once the vm migration finished
+successfully.
+ETEXI
+
+#if defined(CONFIG_SPICE)
+    {
+        .name       = "spice_migrate_info",
+        .args_type  = "hostname:s,port:i?,tls-port:i?,cert-subject:s?",
+        .params     = "hostname port tls-port cert-subject",
+        .help       = "send migration info to spice client",
+        .user_print = monitor_user_noop,
+        .mhandler.cmd_new = mon_spice_migrate,
+    },
+#endif
+
+STEXI
 @item snapshot_blkdev
 @findex snapshot_blkdev
 Snapshot device, using snapshot file as target if provided
diff --git a/qmp-commands.hx b/qmp-commands.hx
index 56c4d8b..24ada04 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -503,6 +503,41 @@  EQMP
     },
 
 SQMP
+spice_migrate_info
+------------------
+
+Set the spice connection info for the migration target.  The spice
+server will ask the spice client to automatically reconnect using the
+new parameters (if specified) once the vm migration finished
+successfully.
+
+Arguments:
+
+- "hostname":     migration target hostname (json-string)
+- "port":         spice tcp port for plaintext channels (json-int, optional)
+- "tls-port":     spice tcp port for tls-secured channels (json-int, optional)
+- "cert-subject": server certificate subject (json-string, optional)
+
+Example:
+
+-> { "execute": "spice_migrate_info",
+     "arguments": { "hostname": "virt42.lab.kraxel.org", "port": 1234 } }
+<- { "return": {} }
+
+EQMP
+
+#if defined(CONFIG_SPICE)
+    {
+        .name       = "spice_migrate_info",
+        .args_type  = "hostname:s,port:i?,tls-port:i?,cert-subject:s?",
+        .params     = "hostname port tls-port cert-subject",
+        .help       = "send migration info to spice client",
+        .user_print = monitor_user_noop,
+        .mhandler.cmd_new = mon_spice_migrate,
+    },
+#endif
+
+SQMP
 migrate_set_speed
 -----------------
 
diff --git a/ui/qemu-spice.h b/ui/qemu-spice.h
index 48239c3..13de5ad 100644
--- a/ui/qemu-spice.h
+++ b/ui/qemu-spice.h
@@ -38,6 +38,7 @@  int qemu_spice_set_pw_expire(time_t expires);
 
 void do_info_spice_print(Monitor *mon, const QObject *data);
 void do_info_spice(Monitor *mon, QObject **ret_data);
+int mon_spice_migrate(Monitor *mon, const QDict *qdict, QObject **ret_data);
 
 #else  /* CONFIG_SPICE */
 
diff --git a/ui/spice-core.c b/ui/spice-core.c
index 27a1ced..95116cc 100644
--- a/ui/spice-core.c
+++ b/ui/spice-core.c
@@ -30,11 +30,15 @@ 
 #include "qbool.h"
 #include "qstring.h"
 #include "qjson.h"
+#include "notify.h"
+#include "migration.h"
 #include "monitor.h"
+#include "hw/hw.h"
 
 /* core bits */
 
 static SpiceServer *spice_server;
+static Notifier migration_state;
 static const char *auth = "spice";
 static char *auth_passwd;
 static time_t auth_expires = TIME_MAX;
@@ -416,6 +420,39 @@  void do_info_spice(Monitor *mon, QObject **ret_data)
     *ret_data = QOBJECT(server);
 }
 
+static void migration_state_notifier(Notifier *notifier)
+{
+    int state = get_migration_state();
+
+    if (state == MIG_STATE_COMPLETED) {
+#if SPICE_SERVER_VERSION >= 0x000701 /* 0.7.1 */
+        spice_server_migrate_switch(spice_server);
+#endif
+    }
+}
+
+int mon_spice_migrate(Monitor *mon, const QDict *qdict, QObject **ret_data)
+{
+    const char *hostname = qdict_get_str(qdict, "hostname");
+    const char *subject  = qdict_get_try_str(qdict, "cert-subject");
+    int port             = qdict_get_try_int(qdict, "port", -1);
+    int tls_port         = qdict_get_try_int(qdict, "tls-port", -1);
+    int ret;
+
+    if (!spice_server) {
+        qerror_report(QERR_DEVICE_NOT_ACTIVE, "spice");
+        return -1;
+    }
+
+    ret = spice_server_migrate_info(spice_server, hostname,
+                                    port, tls_port, subject);
+    if (ret != 0) {
+        qerror_report(QERR_UNDEFINED_ERROR);
+        return -1;
+    }
+    return 0;
+}
+
 static int add_channel(const char *name, const char *value, void *opaque)
 {
     int security = 0;
@@ -573,6 +610,9 @@  void qemu_spice_init(void)
     spice_server_init(spice_server, &core_interface);
     using_spice = 1;
 
+    migration_state.notify = migration_state_notifier;
+    add_migration_state_change_notifier(&migration_state);
+
     qemu_spice_input_init();
     qemu_spice_audio_init();