180 lines
5.1 KiB
Diff
180 lines
5.1 KiB
Diff
From 80b1dac2be1487d31e6766abe2359fcff1bf0481 Mon Sep 17 00:00:00 2001
|
|
From: Gerd Hoffmann <kraxel@redhat.com>
|
|
Date: Fri, 23 Apr 2010 13:28:21 +0200
|
|
Subject: [PATCH 19/39] spice: live migration (wip).
|
|
|
|
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.
|
|
---
|
|
monitor.c | 1 +
|
|
qemu-monitor.hx | 11 +++++++
|
|
qemu-spice.h | 2 +
|
|
spice.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
4 files changed, 101 insertions(+), 0 deletions(-)
|
|
|
|
diff --git a/monitor.c b/monitor.c
|
|
index e51df62..6674a8c 100644
|
|
--- a/monitor.c
|
|
+++ b/monitor.c
|
|
@@ -57,6 +57,7 @@
|
|
#include "osdep.h"
|
|
#include "exec-all.h"
|
|
#include "qemu-kvm.h"
|
|
+#include "qemu-spice.h"
|
|
|
|
//#define DEBUG
|
|
//#define DEBUG_COMPLETION
|
|
diff --git a/qemu-monitor.hx b/qemu-monitor.hx
|
|
index da7b796..c2570d9 100644
|
|
--- a/qemu-monitor.hx
|
|
+++ b/qemu-monitor.hx
|
|
@@ -2510,6 +2510,17 @@ ETEXI
|
|
|
|
HXCOMM DO NOT add new commands after 'info', move your addition before it!
|
|
|
|
+#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
|
|
@end table
|
|
ETEXI
|
|
diff --git a/qemu-spice.h b/qemu-spice.h
|
|
index 6f19ba7..3c8e959 100644
|
|
--- a/qemu-spice.h
|
|
+++ b/qemu-spice.h
|
|
@@ -16,6 +16,8 @@ void qemu_spice_input_init(void);
|
|
void qemu_spice_audio_init(void);
|
|
void qemu_spice_display_init(DisplayState *ds);
|
|
|
|
+int mon_spice_migrate(Monitor *mon, const QDict *qdict, QObject **ret_data);
|
|
+
|
|
#else /* CONFIG_SPICE */
|
|
|
|
#define using_spice 0
|
|
diff --git a/spice.c b/spice.c
|
|
index fc76ef7..1109b4f 100644
|
|
--- a/spice.c
|
|
+++ b/spice.c
|
|
@@ -11,6 +11,7 @@
|
|
#include "qemu-queue.h"
|
|
#include "qemu-x509.h"
|
|
#include "monitor.h"
|
|
+#include "hw/hw.h"
|
|
|
|
/* core bits */
|
|
|
|
@@ -122,8 +123,90 @@ static SpiceCoreInterface core_interface = {
|
|
.watch_remove = watch_remove,
|
|
};
|
|
|
|
+/* handle client migration */
|
|
+
|
|
+static int spice_live(Monitor *mon, QEMUFile *f, int stage, void *opaque)
|
|
+{
|
|
+ static int last_stage;
|
|
+ static int migrate_client, client_connected;
|
|
+ int ret = 1;
|
|
+
|
|
+ if (last_stage != stage) {
|
|
+ last_stage = stage;
|
|
+ fprintf(stderr, "%s: stage %d\n", __FUNCTION__, stage);
|
|
+ } else {
|
|
+ fprintf(stderr, ".");
|
|
+ }
|
|
+
|
|
+ switch (stage) {
|
|
+ case 1:
|
|
+ migrate_client = 1;
|
|
+ client_connected = 0;
|
|
+ fprintf(stderr, "%s: start client migration\n", __FUNCTION__);
|
|
+ if (spice_server_migrate_start(spice_server) != 0) {
|
|
+ fprintf(stderr, "%s: fail -> no client migration\n", __FUNCTION__);
|
|
+ migrate_client = 0;
|
|
+ }
|
|
+ break;
|
|
+ case 2:
|
|
+ if (!migrate_client)
|
|
+ break;
|
|
+ switch (spice_server_migrate_client_state(spice_server)) {
|
|
+ case SPICE_MIGRATE_CLIENT_NONE:
|
|
+ fprintf(stderr, "%s: no client connected\n", __FUNCTION__);
|
|
+ migrate_client = 0;
|
|
+ break;
|
|
+ case SPICE_MIGRATE_CLIENT_WAITING:
|
|
+ ret = 0;
|
|
+ break;
|
|
+ case SPICE_MIGRATE_CLIENT_READY:
|
|
+ if (!client_connected) {
|
|
+ fprintf(stderr, "%s: client connected to target\n", __FUNCTION__);
|
|
+ client_connected = 1;
|
|
+ }
|
|
+ break;
|
|
+ }
|
|
+ break;
|
|
+ case 3:
|
|
+ if (migrate_client && client_connected) {
|
|
+ fprintf(stderr, "%s: finish client migration\n", __FUNCTION__);
|
|
+ spice_server_migrate_end(spice_server, 1);
|
|
+ }
|
|
+ break;
|
|
+ }
|
|
+ return ret;
|
|
+}
|
|
+
|
|
+static void spice_save(QEMUFile *f, void *opaque)
|
|
+{
|
|
+ fprintf(stderr, "%s:\n", __FUNCTION__);
|
|
+}
|
|
+
|
|
+static int spice_load(QEMUFile *f, void *opaque, int version_id)
|
|
+{
|
|
+ fprintf(stderr, "%s:\n", __FUNCTION__);
|
|
+ return 0;
|
|
+}
|
|
+
|
|
/* functions for the rest of qemu */
|
|
|
|
+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);
|
|
+
|
|
+ if (!spice_server) {
|
|
+ qerror_report(QERR_DEVICE_NOT_ACTIVE, "spice");
|
|
+ return -1;
|
|
+ }
|
|
+
|
|
+ /* TODO: Convert to QError */
|
|
+ return spice_server_migrate_info(spice_server, hostname,
|
|
+ port, tls_port, subject);
|
|
+}
|
|
+
|
|
void qemu_spice_init(void)
|
|
{
|
|
QemuOpts *opts = QTAILQ_FIRST(&qemu_spice_opts.head);
|
|
@@ -206,6 +289,10 @@ void qemu_spice_init(void)
|
|
qemu_spice_input_init();
|
|
qemu_spice_audio_init();
|
|
|
|
+ register_savevm_live(NULL, "spice", -1, 1, NULL,
|
|
+ spice_live, spice_save, spice_load,
|
|
+ spice_server);
|
|
+
|
|
qemu_free(x509_key_file);
|
|
qemu_free(x509_cert_file);
|
|
qemu_free(x509_cacert_file);
|
|
--
|
|
1.7.2.3
|
|
|