[Qemu-devel] [PATCH 2/8] spice/vnc: client migration.

2011-01-27 Thread Gerd Hoffmann
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.

The monitor command has a not-yet used protocol argument simliar to
set_password and expire_password commands.  This allows to add a simliar
feature to vnc in the future.  Daniel Berrange plans to work on this.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hmp-commands.hx |   17 +
 monitor.c   |   27 +++
 qmp-commands.hx |   35 +++
 ui/qemu-spice.h |4 
 ui/spice-core.c |   25 +
 5 files changed, 108 insertions(+), 0 deletions(-)

diff --git a/hmp-commands.hx b/hmp-commands.hx
index 1cea572..4906d89 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -815,6 +815,23 @@ ETEXI
 },
 
 STEXI
+@item client_migrate_info @var{protocol} @var{hostname} @var{port} 
@var{tls-port} @var{cert-subject}
+@findex client_migrate_info
+Set the spice/vnc connection info for the migration target.  The spice/vnc
+server will ask the spice/vnc client to automatically reconnect using the
+new parameters (if specified) once the vm migration finished successfully.
+ETEXI
+
+{
+.name   = client_migrate_info,
+.args_type  = 
protocol:s,hostname:s,port:i?,tls-port:i?,cert-subject:s?,
+.params = protocol hostname port tls-port cert-subject,
+.help   = send migration info to spice/vnc client,
+.user_print = monitor_user_noop,
+.mhandler.cmd_new = client_migrate_info,
+},
+
+STEXI
 @item snapshot_blkdev
 @findex snapshot_blkdev
 Snapshot device, using snapshot file as target if provided
diff --git a/monitor.c b/monitor.c
index c5f54f4..384d87b 100644
--- a/monitor.c
+++ b/monitor.c
@@ -1173,6 +1173,33 @@ static int expire_password(Monitor *mon, const QDict 
*qdict, QObject **ret_data)
 return -1;
 }
 
+static int client_migrate_info(Monitor *mon, const QDict *qdict, QObject 
**ret_data)
+{
+const char *protocol = qdict_get_str(qdict, protocol);
+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 (strcmp(protocol, spice) == 0) {
+if (!using_spice) {
+qerror_report(QERR_DEVICE_NOT_ACTIVE, spice);
+return -1;
+}
+
+ret = qemu_spice_migrate_info(hostname, port, tls_port, subject);
+if (ret != 0) {
+qerror_report(QERR_UNDEFINED_ERROR);
+return -1;
+}
+return 0;
+}
+
+qerror_report(QERR_INVALID_PARAMETER, protocol);
+return -1;
+}
+
 static int do_screen_dump(Monitor *mon, const QDict *qdict, QObject **ret_data)
 {
 vga_hw_screen_dump(qdict_get_str(qdict, filename));
diff --git a/qmp-commands.hx b/qmp-commands.hx
index 56c4d8b..2ed8f44 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -503,6 +503,41 @@ EQMP
 },
 
 SQMP
+client_migrate_info
+--
+
+Set the spice/vnc connection info for the migration target.  The spice/vnc
+server will ask the spice/vnc client to automatically reconnect using the
+new parameters (if specified) once the vm migration finished successfully.
+
+Arguments:
+
+- protocol: protocol: spice or vnc (json-string)
+- hostname: migration target hostname (json-string)
+- port: spice/vnc 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: client_migrate_info,
+ arguments: { protocol: spice,
+hostname: virt42.lab.kraxel.org,
+port: 1234 } }
+- { return: {} }
+
+EQMP
+
+{
+.name   = client_migrate_info,
+.args_type  = 
protocol:s,hostname:s,port:i?,tls-port:i?,cert-subject:s?,
+.params = protocol hostname port tls-port cert-subject,
+.help   = send migration info to spice/vnc client,
+.user_print = monitor_user_noop,
+.mhandler.cmd_new = client_migrate_info,
+},
+
+SQMP
 migrate_set_speed
 -
 
diff --git a/ui/qemu-spice.h b/ui/qemu-spice.h
index 48239c3..05dc50a 100644
--- a/ui/qemu-spice.h
+++ b/ui/qemu-spice.h
@@ -35,6 +35,8 @@ int qemu_spice_add_interface(SpiceBaseInstance *sin);
 int qemu_spice_set_passwd(const char *passwd,
   bool fail_if_connected, bool 
disconnect_if_connected);
 int qemu_spice_set_pw_expire(time_t expires);
+int qemu_spice_migrate_info(const char *hostname, int port, int tls_port,
+const char *subject);
 
 void do_info_spice_print(Monitor *mon, const QObject *data);
 void do_info_spice(Monitor *mon, QObject **ret_data);
@@ 

[Qemu-devel] [PATCH 2/8] spice/vnc: client migration.

2011-01-24 Thread Gerd Hoffmann
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.

The monitor command has a not-yet used protocol argument simliar to
set_password and expire_password commands.  This allows to add a simliar
feature to vnc in the future.  Daniel Berrange plans to work on this.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hmp-commands.hx |   17 +
 monitor.c   |   27 +++
 qmp-commands.hx |   35 +++
 ui/qemu-spice.h |4 
 ui/spice-core.c |   25 +
 5 files changed, 108 insertions(+), 0 deletions(-)

diff --git a/hmp-commands.hx b/hmp-commands.hx
index 1cea572..4906d89 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -815,6 +815,23 @@ ETEXI
 },
 
 STEXI
+@item client_migrate_info @var{protocol} @var{hostname} @var{port} 
@var{tls-port} @var{cert-subject}
+@findex client_migrate_info
+Set the spice/vnc connection info for the migration target.  The spice/vnc
+server will ask the spice/vnc client to automatically reconnect using the
+new parameters (if specified) once the vm migration finished successfully.
+ETEXI
+
+{
+.name   = client_migrate_info,
+.args_type  = 
protocol:s,hostname:s,port:i?,tls-port:i?,cert-subject:s?,
+.params = protocol hostname port tls-port cert-subject,
+.help   = send migration info to spice/vnc client,
+.user_print = monitor_user_noop,
+.mhandler.cmd_new = client_migrate_info,
+},
+
+STEXI
 @item snapshot_blkdev
 @findex snapshot_blkdev
 Snapshot device, using snapshot file as target if provided
diff --git a/monitor.c b/monitor.c
index d291158..4c92d38 100644
--- a/monitor.c
+++ b/monitor.c
@@ -1173,6 +1173,33 @@ static int expire_password(Monitor *mon, const QDict 
*qdict, QObject **ret_data)
 return -1;
 }
 
+static int client_migrate_info(Monitor *mon, const QDict *qdict, QObject 
**ret_data)
+{
+const char *protocol = qdict_get_str(qdict, protocol);
+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 (strcmp(protocol, spice) == 0) {
+if (!using_spice) {
+qerror_report(QERR_DEVICE_NOT_ACTIVE, spice);
+return -1;
+}
+
+ret = qemu_spice_migrate_info(hostname, port, tls_port, subject);
+if (ret != 0) {
+qerror_report(QERR_UNDEFINED_ERROR);
+return -1;
+}
+return 0;
+}
+
+qerror_report(QERR_INVALID_PARAMETER, protocol);
+return -1;
+}
+
 static int do_screen_dump(Monitor *mon, const QDict *qdict, QObject **ret_data)
 {
 vga_hw_screen_dump(qdict_get_str(qdict, filename));
diff --git a/qmp-commands.hx b/qmp-commands.hx
index 56c4d8b..2ed8f44 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -503,6 +503,41 @@ EQMP
 },
 
 SQMP
+client_migrate_info
+--
+
+Set the spice/vnc connection info for the migration target.  The spice/vnc
+server will ask the spice/vnc client to automatically reconnect using the
+new parameters (if specified) once the vm migration finished successfully.
+
+Arguments:
+
+- protocol: protocol: spice or vnc (json-string)
+- hostname: migration target hostname (json-string)
+- port: spice/vnc 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: client_migrate_info,
+ arguments: { protocol: spice,
+hostname: virt42.lab.kraxel.org,
+port: 1234 } }
+- { return: {} }
+
+EQMP
+
+{
+.name   = client_migrate_info,
+.args_type  = 
protocol:s,hostname:s,port:i?,tls-port:i?,cert-subject:s?,
+.params = protocol hostname port tls-port cert-subject,
+.help   = send migration info to spice/vnc client,
+.user_print = monitor_user_noop,
+.mhandler.cmd_new = client_migrate_info,
+},
+
+SQMP
 migrate_set_speed
 -
 
diff --git a/ui/qemu-spice.h b/ui/qemu-spice.h
index 48239c3..05dc50a 100644
--- a/ui/qemu-spice.h
+++ b/ui/qemu-spice.h
@@ -35,6 +35,8 @@ int qemu_spice_add_interface(SpiceBaseInstance *sin);
 int qemu_spice_set_passwd(const char *passwd,
   bool fail_if_connected, bool 
disconnect_if_connected);
 int qemu_spice_set_pw_expire(time_t expires);
+int qemu_spice_migrate_info(const char *hostname, int port, int tls_port,
+const char *subject);
 
 void do_info_spice_print(Monitor *mon, const QObject *data);
 void do_info_spice(Monitor *mon, QObject **ret_data);
@@