summaryrefslogtreecommitdiff
path: root/ui/spice-core.c
diff options
context:
space:
mode:
Diffstat (limited to 'ui/spice-core.c')
-rw-r--r--ui/spice-core.c423
1 files changed, 271 insertions, 152 deletions
diff --git a/ui/spice-core.c b/ui/spice-core.c
index bd7a248f9..eea52f538 100644
--- a/ui/spice-core.c
+++ b/ui/spice-core.c
@@ -15,28 +15,27 @@
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
+#include "qemu/osdep.h"
#include <spice.h>
-#include <spice-experimental.h>
-#include <netdb.h>
#include "sysemu/sysemu.h"
-
-#include "qemu-common.h"
+#include "sysemu/runstate.h"
#include "ui/qemu-spice.h"
+#include "qemu/error-report.h"
+#include "qemu/main-loop.h"
+#include "qemu/module.h"
#include "qemu/thread.h"
#include "qemu/timer.h"
#include "qemu/queue.h"
#include "qemu-x509.h"
#include "qemu/sockets.h"
-#include "qmp-commands.h"
-#include "qapi/qmp/qint.h"
-#include "qapi/qmp/qbool.h"
-#include "qapi/qmp/qstring.h"
-#include "qapi/qmp/qjson.h"
+#include "qapi/error.h"
+#include "qapi/qapi-commands-ui.h"
+#include "qapi/qapi-events-ui.h"
#include "qemu/notify.h"
-#include "migration/migration.h"
-#include "monitor/monitor.h"
-#include "hw/hw.h"
+#include "qemu/option.h"
+#include "migration/misc.h"
+#include "hw/pci/pci_bus.h"
#include "ui/spice-display.h"
/* core bits */
@@ -47,53 +46,46 @@ 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;
-int spice_displays;
+static int spice_display_is_running;
+static int spice_have_target_host;
static QemuThread me;
struct SpiceTimer {
QEMUTimer *timer;
- QTAILQ_ENTRY(SpiceTimer) next;
};
-static QTAILQ_HEAD(, SpiceTimer) timers = QTAILQ_HEAD_INITIALIZER(timers);
static SpiceTimer *timer_add(SpiceTimerFunc func, void *opaque)
{
SpiceTimer *timer;
timer = g_malloc0(sizeof(*timer));
- timer->timer = qemu_new_timer_ms(rt_clock, func, opaque);
- QTAILQ_INSERT_TAIL(&timers, timer, next);
+ timer->timer = timer_new_ms(QEMU_CLOCK_REALTIME, func, opaque);
return timer;
}
static void timer_start(SpiceTimer *timer, uint32_t ms)
{
- qemu_mod_timer(timer->timer, qemu_get_clock_ms(rt_clock) + ms);
+ timer_mod(timer->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + ms);
}
static void timer_cancel(SpiceTimer *timer)
{
- qemu_del_timer(timer->timer);
+ timer_del(timer->timer);
}
static void timer_remove(SpiceTimer *timer)
{
- qemu_del_timer(timer->timer);
- qemu_free_timer(timer->timer);
- QTAILQ_REMOVE(&timers, timer, next);
+ timer_del(timer->timer);
+ timer_free(timer->timer);
g_free(timer);
}
struct SpiceWatch {
int fd;
- int event_mask;
SpiceWatchFunc func;
void *opaque;
- QTAILQ_ENTRY(SpiceWatch) next;
};
-static QTAILQ_HEAD(, SpiceWatch) watches = QTAILQ_HEAD_INITIALIZER(watches);
static void watch_read(void *opaque)
{
@@ -112,11 +104,10 @@ static void watch_update_mask(SpiceWatch *watch, int event_mask)
IOHandler *on_read = NULL;
IOHandler *on_write = NULL;
- watch->event_mask = event_mask;
- if (watch->event_mask & SPICE_WATCH_EVENT_READ) {
+ if (event_mask & SPICE_WATCH_EVENT_READ) {
on_read = watch_read;
}
- if (watch->event_mask & SPICE_WATCH_EVENT_WRITE) {
+ if (event_mask & SPICE_WATCH_EVENT_WRITE) {
on_write = watch_write;
}
qemu_set_fd_handler(watch->fd, on_read, on_write, watch);
@@ -130,7 +121,6 @@ static SpiceWatch *watch_add(int fd, int event_mask, SpiceWatchFunc func, void *
watch->fd = fd;
watch->func = func;
watch->opaque = opaque;
- QTAILQ_INSERT_TAIL(&watches, watch, next);
watch_update_mask(watch, event_mask);
return watch;
@@ -139,7 +129,6 @@ static SpiceWatch *watch_add(int fd, int event_mask, SpiceWatchFunc func, void *
static void watch_remove(SpiceWatch *watch)
{
qemu_set_fd_handler(watch->fd, NULL, NULL, NULL);
- QTAILQ_REMOVE(&watches, watch, next);
g_free(watch);
}
@@ -173,39 +162,32 @@ static void channel_list_del(SpiceChannelEventInfo *info)
}
}
-static void add_addr_info(QDict *dict, struct sockaddr *addr, int len)
+static void add_addr_info(SpiceBasicInfo *info, struct sockaddr *addr, int len)
{
char host[NI_MAXHOST], port[NI_MAXSERV];
- const char *family;
getnameinfo(addr, len, host, sizeof(host), port, sizeof(port),
NI_NUMERICHOST | NI_NUMERICSERV);
- family = inet_strfamily(addr->sa_family);
- qdict_put(dict, "host", qstring_from_str(host));
- qdict_put(dict, "port", qstring_from_str(port));
- qdict_put(dict, "family", qstring_from_str(family));
+ info->host = g_strdup(host);
+ info->port = g_strdup(port);
+ info->family = inet_netfamily(addr->sa_family);
}
-static void add_channel_info(QDict *dict, SpiceChannelEventInfo *info)
+static void add_channel_info(SpiceChannel *sc, SpiceChannelEventInfo *info)
{
int tls = info->flags & SPICE_CHANNEL_EVENT_FLAG_TLS;
- qdict_put(dict, "connection-id", qint_from_int(info->connection_id));
- qdict_put(dict, "channel-type", qint_from_int(info->type));
- qdict_put(dict, "channel-id", qint_from_int(info->id));
- qdict_put(dict, "tls", qbool_from_int(tls));
+ sc->connection_id = info->connection_id;
+ sc->channel_type = info->type;
+ sc->channel_id = info->id;
+ sc->tls = !!tls;
}
static void channel_event(int event, SpiceChannelEventInfo *info)
{
- static const int qevent[] = {
- [ SPICE_CHANNEL_EVENT_CONNECTED ] = QEVENT_SPICE_CONNECTED,
- [ SPICE_CHANNEL_EVENT_INITIALIZED ] = QEVENT_SPICE_INITIALIZED,
- [ SPICE_CHANNEL_EVENT_DISCONNECTED ] = QEVENT_SPICE_DISCONNECTED,
- };
- QDict *server, *client;
- QObject *data;
+ SpiceServerInfo *server = g_malloc0(sizeof(*server));
+ SpiceChannel *client = g_malloc0(sizeof(*client));
/*
* Spice server might have called us from spice worker thread
@@ -221,36 +203,47 @@ static void channel_event(int event, SpiceChannelEventInfo *info)
qemu_mutex_lock_iothread();
}
- client = qdict_new();
- server = qdict_new();
-
if (info->flags & SPICE_CHANNEL_EVENT_FLAG_ADDR_EXT) {
- add_addr_info(client, (struct sockaddr *)&info->paddr_ext,
+ add_addr_info(qapi_SpiceChannel_base(client),
+ (struct sockaddr *)&info->paddr_ext,
info->plen_ext);
- add_addr_info(server, (struct sockaddr *)&info->laddr_ext,
+ add_addr_info(qapi_SpiceServerInfo_base(server),
+ (struct sockaddr *)&info->laddr_ext,
info->llen_ext);
} else {
error_report("spice: %s, extended address is expected",
__func__);
}
- if (event == SPICE_CHANNEL_EVENT_INITIALIZED) {
- qdict_put(server, "auth", qstring_from_str(auth));
+ switch (event) {
+ case SPICE_CHANNEL_EVENT_CONNECTED:
+ qapi_event_send_spice_connected(qapi_SpiceServerInfo_base(server),
+ qapi_SpiceChannel_base(client));
+ break;
+ case SPICE_CHANNEL_EVENT_INITIALIZED:
+ if (auth) {
+ server->has_auth = true;
+ server->auth = g_strdup(auth);
+ }
add_channel_info(client, info);
channel_list_add(info);
- }
- if (event == SPICE_CHANNEL_EVENT_DISCONNECTED) {
+ qapi_event_send_spice_initialized(server, client);
+ break;
+ case SPICE_CHANNEL_EVENT_DISCONNECTED:
channel_list_del(info);
+ qapi_event_send_spice_disconnected(qapi_SpiceServerInfo_base(server),
+ qapi_SpiceChannel_base(client));
+ break;
+ default:
+ break;
}
- data = qobject_from_jsonf("{ 'client': %p, 'server': %p }",
- QOBJECT(client), QOBJECT(server));
- monitor_protocol_event(qevent[event], data);
- qobject_decref(data);
-
if (need_lock) {
qemu_mutex_unlock_iothread();
}
+
+ qapi_free_SpiceServerInfo(server);
+ qapi_free_SpiceChannel(client);
}
static SpiceCoreInterface core_interface = {
@@ -271,14 +264,6 @@ static SpiceCoreInterface core_interface = {
.channel_event = channel_event,
};
-typedef struct SpiceMigration {
- SpiceMigrateInstance sin;
- struct {
- MonitorCompletion *cb;
- void *opaque;
- } connect_complete;
-} SpiceMigration;
-
static void migrate_connect_complete_cb(SpiceMigrateInstance *sin);
static void migrate_end_complete_cb(SpiceMigrateInstance *sin);
@@ -291,20 +276,16 @@ static const SpiceMigrateInterface migrate_interface = {
.migrate_end_complete = migrate_end_complete_cb,
};
-static SpiceMigration spice_migrate;
+static SpiceMigrateInstance spice_migrate;
static void migrate_connect_complete_cb(SpiceMigrateInstance *sin)
{
- SpiceMigration *sm = container_of(sin, SpiceMigration, sin);
- if (sm->connect_complete.cb) {
- sm->connect_complete.cb(sm->connect_complete.opaque, NULL);
- }
- sm->connect_complete.cb = NULL;
+ /* nothing, but libspice-server expects this cb being present. */
}
static void migrate_end_complete_cb(SpiceMigrateInstance *sin)
{
- monitor_protocol_event(QEVENT_SPICE_MIGRATE_COMPLETED, NULL);
+ qapi_event_send_spice_migrate_completed();
spice_migration_completed = true;
}
@@ -383,23 +364,19 @@ static SpiceChannelList *qmp_query_spice_channels(void)
struct sockaddr *paddr;
socklen_t plen;
+ assert(item->info->flags & SPICE_CHANNEL_EVENT_FLAG_ADDR_EXT);
+
chan = g_malloc0(sizeof(*chan));
chan->value = g_malloc0(sizeof(*chan->value));
- if (item->info->flags & SPICE_CHANNEL_EVENT_FLAG_ADDR_EXT) {
- paddr = (struct sockaddr *)&item->info->paddr_ext;
- plen = item->info->plen_ext;
- } else {
- paddr = &item->info->paddr;
- plen = item->info->plen;
- }
-
+ paddr = (struct sockaddr *)&item->info->paddr_ext;
+ plen = item->info->plen_ext;
getnameinfo(paddr, plen,
host, sizeof(host), port, sizeof(port),
NI_NUMERICHOST | NI_NUMERICSERV);
chan->value->host = g_strdup(host);
chan->value->port = g_strdup(port);
- chan->value->family = g_strdup(inet_strfamily(paddr->sa_family));
+ chan->value->family = inet_netfamily(paddr->sa_family);
chan->value->connection_id = item->info->connection_id;
chan->value->channel_type = item->info->type;
@@ -421,6 +398,7 @@ static SpiceChannelList *qmp_query_spice_channels(void)
static QemuOptsList qemu_spice_opts = {
.name = "spice",
.head = QTAILQ_HEAD_INITIALIZER(qemu_spice_opts.head),
+ .merge_lists = true,
.desc = {
{
.name = "port",
@@ -437,6 +415,11 @@ static QemuOptsList qemu_spice_opts = {
},{
.name = "ipv6",
.type = QEMU_OPT_BOOL,
+#ifdef SPICE_ADDR_FLAG_UNIX_ONLY
+ },{
+ .name = "unix",
+ .type = QEMU_OPT_BOOL,
+#endif
},{
.name = "password",
.type = QEMU_OPT_STRING,
@@ -497,21 +480,37 @@ static QemuOptsList qemu_spice_opts = {
},{
.name = "playback-compression",
.type = QEMU_OPT_BOOL,
- }, {
+ },{
.name = "seamless-migration",
.type = QEMU_OPT_BOOL,
+ },{
+ .name = "display",
+ .type = QEMU_OPT_STRING,
+ },{
+ .name = "head",
+ .type = QEMU_OPT_NUMBER,
+#ifdef HAVE_SPICE_GL
+ },{
+ .name = "gl",
+ .type = QEMU_OPT_BOOL,
+ },{
+ .name = "rendernode",
+ .type = QEMU_OPT_STRING,
+#endif
},
{ /* end of list */ }
},
};
-SpiceInfo *qmp_query_spice(Error **errp)
+static SpiceInfo *qmp_query_spice_real(Error **errp)
{
QemuOpts *opts = QTAILQ_FIRST(&qemu_spice_opts.head);
int port, tls_port;
const char *addr;
SpiceInfo *info;
- char version_string[20]; /* 12 = |255.255.255\0| is the max */
+ unsigned int major;
+ unsigned int minor;
+ unsigned int micro;
info = g_malloc0(sizeof(*info));
@@ -531,14 +530,13 @@ SpiceInfo *qmp_query_spice(Error **errp)
info->auth = g_strdup(auth);
info->has_host = true;
- info->host = g_strdup(addr ? addr : "0.0.0.0");
+ info->host = g_strdup(addr ? addr : "*");
info->has_compiled_version = true;
- snprintf(version_string, sizeof(version_string), "%d.%d.%d",
- (SPICE_SERVER_VERSION & 0xff0000) >> 16,
- (SPICE_SERVER_VERSION & 0xff00) >> 8,
- SPICE_SERVER_VERSION & 0xff);
- info->compiled_version = g_strdup(version_string);
+ major = (SPICE_SERVER_VERSION & 0xff0000) >> 16;
+ minor = (SPICE_SERVER_VERSION & 0xff00) >> 8;
+ micro = SPICE_SERVER_VERSION & 0xff;
+ info->compiled_version = g_strdup_printf("%d.%d.%d", major, minor, micro);
if (port) {
info->has_port = true;
@@ -564,29 +562,35 @@ static void migration_state_notifier(Notifier *notifier, void *data)
{
MigrationState *s = data;
+ if (!spice_have_target_host) {
+ return;
+ }
+
if (migration_in_setup(s)) {
spice_server_migrate_start(spice_server);
- } else if (migration_has_finished(s)) {
+ } else if (migration_has_finished(s) ||
+ migration_in_postcopy_after_devices(s)) {
spice_server_migrate_end(spice_server, true);
+ spice_have_target_host = false;
} else if (migration_has_failed(s)) {
spice_server_migrate_end(spice_server, false);
+ spice_have_target_host = false;
}
}
int qemu_spice_migrate_info(const char *hostname, int port, int tls_port,
- const char *subject,
- MonitorCompletion *cb, void *opaque)
+ const char *subject)
{
int ret;
- spice_migrate.connect_complete.cb = cb;
- spice_migrate.connect_complete.opaque = opaque;
ret = spice_server_migrate_connect(spice_server, hostname,
port, tls_port, subject);
+ spice_have_target_host = true;
return ret;
}
-static int add_channel(const char *name, const char *value, void *opaque)
+static int add_channel(void *opaque, const char *name, const char *value,
+ Error **errp)
{
int security = 0;
int rc;
@@ -594,9 +598,9 @@ static int add_channel(const char *name, const char *value, void *opaque)
if (strcmp(name, "tls-channel") == 0) {
int *tls_port = opaque;
if (!*tls_port) {
- error_report("spice: tried to setup tls-channel"
- " without specifying a TLS port");
- exit(1);
+ error_setg(errp, "spice: tried to setup tls-channel"
+ " without specifying a TLS port");
+ return -1;
}
security = SPICE_CHANNEL_SECURITY_SSL;
}
@@ -612,8 +616,9 @@ static int add_channel(const char *name, const char *value, void *opaque)
rc = spice_server_set_channel_security(spice_server, value, security);
}
if (rc != 0) {
- error_report("spice: failed to set channel security for %s", value);
- exit(1);
+ error_setg(errp, "spice: failed to set channel security for %s",
+ value);
+ return -1;
}
return 0;
}
@@ -623,14 +628,12 @@ static void vm_change_state_handler(void *opaque, int running,
{
if (running) {
qemu_spice_display_start();
- spice_server_vm_start(spice_server);
- } else {
- spice_server_vm_stop(spice_server);
+ } else if (state != RUN_STATE_PAUSED) {
qemu_spice_display_stop();
}
}
-void qemu_spice_init(void)
+static void qemu_spice_init(void)
{
QemuOpts *opts = QTAILQ_FIRST(&qemu_spice_opts.head);
const char *password, *str, *x509_dir, *addr,
@@ -640,7 +643,7 @@ void qemu_spice_init(void)
char *x509_key_file = NULL,
*x509_cert_file = NULL,
*x509_cacert_file = NULL;
- int port, tls_port, len, addr_flags;
+ int port, tls_port, addr_flags;
spice_image_compression_t compression;
spice_wan_compression_t wan_compr;
bool seamless_migration;
@@ -652,10 +655,6 @@ void qemu_spice_init(void)
}
port = qemu_opt_get_number(opts, "port", 0);
tls_port = qemu_opt_get_number(opts, "tls-port", 0);
- if (!port && !tls_port) {
- error_report("neither port nor tls-port specified for spice");
- exit(1);
- }
if (port < 0 || port > 65535) {
error_report("spice port is out of range");
exit(1);
@@ -668,33 +667,32 @@ void qemu_spice_init(void)
if (tls_port) {
x509_dir = qemu_opt_get(opts, "x509-dir");
- if (NULL == x509_dir) {
+ if (!x509_dir) {
x509_dir = ".";
}
- len = strlen(x509_dir) + 32;
str = qemu_opt_get(opts, "x509-key-file");
if (str) {
x509_key_file = g_strdup(str);
} else {
- x509_key_file = g_malloc(len);
- snprintf(x509_key_file, len, "%s/%s", x509_dir, X509_SERVER_KEY_FILE);
+ x509_key_file = g_strdup_printf("%s/%s", x509_dir,
+ X509_SERVER_KEY_FILE);
}
str = qemu_opt_get(opts, "x509-cert-file");
if (str) {
x509_cert_file = g_strdup(str);
} else {
- x509_cert_file = g_malloc(len);
- snprintf(x509_cert_file, len, "%s/%s", x509_dir, X509_SERVER_CERT_FILE);
+ x509_cert_file = g_strdup_printf("%s/%s", x509_dir,
+ X509_SERVER_CERT_FILE);
}
str = qemu_opt_get(opts, "x509-cacert-file");
if (str) {
x509_cacert_file = g_strdup(str);
} else {
- x509_cacert_file = g_malloc(len);
- snprintf(x509_cacert_file, len, "%s/%s", x509_dir, X509_CA_CERT_FILE);
+ x509_cacert_file = g_strdup_printf("%s/%s", x509_dir,
+ X509_CA_CERT_FILE);
}
x509_key_password = qemu_opt_get(opts, "x509-key-password");
@@ -708,6 +706,10 @@ void qemu_spice_init(void)
addr_flags |= SPICE_ADDR_FLAG_IPV4_ONLY;
} else if (qemu_opt_get_bool(opts, "ipv6", 0)) {
addr_flags |= SPICE_ADDR_FLAG_IPV6_ONLY;
+#ifdef SPICE_ADDR_FLAG_UNIX_ONLY
+ } else if (qemu_opt_get_bool(opts, "unix", 0)) {
+ addr_flags |= SPICE_ADDR_FLAG_UNIX_ONLY;
+#endif
}
spice_server = spice_server_new();
@@ -725,14 +727,14 @@ void qemu_spice_init(void)
tls_ciphers);
}
if (password) {
- spice_server_set_ticket(spice_server, password, 0, 0, 0);
+ qemu_spice.set_passwd(password, false, false);
}
if (qemu_opt_get_bool(opts, "sasl", 0)) {
- if (spice_server_set_sasl_appname(spice_server, "qemu") == -1 ||
- spice_server_set_sasl(spice_server, 1) == -1) {
+ if (spice_server_set_sasl(spice_server, 1) == -1) {
error_report("spice: failed to enable sasl");
exit(1);
}
+ auth = "sasl";
}
if (qemu_opt_get_bool(opts, "disable-ticketing", 0)) {
auth = "none";
@@ -744,13 +746,7 @@ void qemu_spice_init(void)
}
if (qemu_opt_get_bool(opts, "disable-agent-file-xfer", 0)) {
-#if SPICE_SERVER_VERSION >= 0x000c04
spice_server_set_agent_file_xfer(spice_server, false);
-#else
- error_report("this qemu build does not support the "
- "\"disable-agent-file-xfer\" option");
- exit(1);
-#endif
}
compression = SPICE_IMAGE_COMPRESS_AUTO_GLZ;
@@ -778,6 +774,8 @@ void qemu_spice_init(void)
if (str) {
int streaming_video = parse_stream_video(str);
spice_server_set_streaming_video(spice_server, streaming_video);
+ } else {
+ spice_server_set_streaming_video(spice_server, SPICE_STREAM_VIDEO_OFF);
}
spice_server_set_agent_mouse
@@ -785,14 +783,15 @@ void qemu_spice_init(void)
spice_server_set_playback_compression
(spice_server, qemu_opt_get_bool(opts, "playback-compression", 1));
- qemu_opt_foreach(opts, add_channel, &tls_port, 0);
+ qemu_opt_foreach(opts, add_channel, &tls_port, &error_fatal);
- spice_server_set_name(spice_server, qemu_name);
- spice_server_set_uuid(spice_server, qemu_uuid);
+ spice_server_set_name(spice_server, qemu_name ?: "QEMU " QEMU_VERSION);
+ spice_server_set_uuid(spice_server, (unsigned char *)&qemu_uuid);
seamless_migration = qemu_opt_get_bool(opts, "seamless-migration", 0);
spice_server_set_seamless_migration(spice_server, seamless_migration);
- if (0 != spice_server_init(spice_server, &core_interface)) {
+ spice_server_set_sasl_appname(spice_server, "qemu");
+ if (spice_server_init(spice_server, &core_interface) != 0) {
error_report("failed to initialize spice server");
exit(1);
};
@@ -800,25 +799,37 @@ void qemu_spice_init(void)
migration_state.notify = migration_state_notifier;
add_migration_state_change_notifier(&migration_state);
- spice_migrate.sin.base.sif = &migrate_interface.base;
- spice_migrate.connect_complete.cb = NULL;
- qemu_spice_add_interface(&spice_migrate.sin.base);
+ spice_migrate.base.sif = &migrate_interface.base;
+ qemu_spice.add_interface(&spice_migrate.base);
qemu_spice_input_init();
- qemu_spice_audio_init();
qemu_add_vm_change_state_handler(vm_change_state_handler, NULL);
+ qemu_spice_display_stop();
g_free(x509_key_file);
g_free(x509_cert_file);
g_free(x509_cacert_file);
-#if SPICE_SERVER_VERSION >= 0x000c02
- qemu_spice_register_ports();
+#ifdef HAVE_SPICE_GL
+ if (qemu_opt_get_bool(opts, "gl", 0)) {
+ if ((port != 0) || (tls_port != 0)) {
+ error_report("SPICE GL support is local-only for now and "
+ "incompatible with -spice port/tls-port");
+ exit(1);
+ }
+ if (egl_rendernode_init(qemu_opt_get(opts, "rendernode"),
+ DISPLAYGL_MODE_ON) != 0) {
+ error_report("Failed to initialize EGL render node for SPICE GL");
+ exit(1);
+ }
+ display_opengl = 1;
+ spice_opengl = 1;
+ }
#endif
}
-int qemu_spice_add_interface(SpiceBaseInstance *sin)
+static int qemu_spice_add_interface(SpiceBaseInstance *sin)
{
if (!spice_server) {
if (QTAILQ_FIRST(&qemu_spice_opts.head) != NULL) {
@@ -833,15 +844,82 @@ int qemu_spice_add_interface(SpiceBaseInstance *sin)
* With a command line like '-vnc :0 -vga qxl' you'll end up here.
*/
spice_server = spice_server_new();
+ spice_server_set_sasl_appname(spice_server, "qemu");
spice_server_init(spice_server, &core_interface);
qemu_add_vm_change_state_handler(vm_change_state_handler, NULL);
}
- if (strcmp(sin->sif->type, SPICE_INTERFACE_QXL) == 0) {
- spice_displays++;
+ return spice_server_add_interface(spice_server, sin);
+}
+
+static GSList *spice_consoles;
+
+bool qemu_spice_have_display_interface(QemuConsole *con)
+{
+ if (g_slist_find(spice_consoles, con)) {
+ return true;
+ }
+ return false;
+}
+
+/*
+ * Recursively (in reverse order) appends addresses of PCI devices as it moves
+ * up in the PCI hierarchy.
+ *
+ * @returns true on success, false when the buffer wasn't large enough
+ */
+static bool append_pci_address(char *buf, size_t buf_size, const PCIDevice *pci)
+{
+ PCIBus *bus = pci_get_bus(pci);
+ /*
+ * equivalent to if (!pci_bus_is_root(bus)), but the function is not built
+ * with PCI_CONFIG=n, avoid using an #ifdef by checking directly
+ */
+ if (bus->parent_dev != NULL) {
+ append_pci_address(buf, buf_size, bus->parent_dev);
}
- return spice_server_add_interface(spice_server, sin);
+ size_t len = strlen(buf);
+ ssize_t written = snprintf(buf + len, buf_size - len, "/%02x.%x",
+ PCI_SLOT(pci->devfn), PCI_FUNC(pci->devfn));
+
+ return written > 0 && written < buf_size - len;
+}
+
+bool qemu_spice_fill_device_address(QemuConsole *con,
+ char *device_address,
+ size_t size)
+{
+ DeviceState *dev = DEVICE(object_property_get_link(OBJECT(con),
+ "device",
+ &error_abort));
+ PCIDevice *pci = (PCIDevice *) object_dynamic_cast(OBJECT(dev),
+ TYPE_PCI_DEVICE);
+
+ if (pci == NULL) {
+ warn_report("Setting device address of a display device to SPICE: "
+ "Not a PCI device.");
+ return false;
+ }
+
+ strncpy(device_address, "pci/0000", size);
+ if (!append_pci_address(device_address, size, pci)) {
+ warn_report("Setting device address of a display device to SPICE: "
+ "Too many PCI devices in the chain.");
+ return false;
+ }
+
+ return true;
+}
+
+int qemu_spice_add_display_interface(QXLInstance *qxlin, QemuConsole *con)
+{
+ if (g_slist_find(spice_consoles, con)) {
+ return -1;
+ }
+ qxlin->id = qemu_console_get_index(con);
+ spice_consoles = g_slist_append(spice_consoles, con);
+ return qemu_spice_add_interface(&qxlin->base);
}
static int qemu_spice_set_ticket(bool fail_if_conn, bool disconnect_if_conn)
@@ -863,21 +941,25 @@ static int qemu_spice_set_ticket(bool fail_if_conn, bool disconnect_if_conn)
fail_if_conn, disconnect_if_conn);
}
-int qemu_spice_set_passwd(const char *passwd,
- bool fail_if_conn, bool disconnect_if_conn)
+static int qemu_spice_set_passwd(const char *passwd,
+ bool fail_if_conn, bool disconnect_if_conn)
{
+ if (strcmp(auth, "spice") != 0) {
+ return -1;
+ }
+
g_free(auth_passwd);
auth_passwd = g_strdup(passwd);
return qemu_spice_set_ticket(fail_if_conn, disconnect_if_conn);
}
-int qemu_spice_set_pw_expire(time_t expires)
+static int qemu_spice_set_pw_expire(time_t expires)
{
auth_expires = expires;
return qemu_spice_set_ticket(false, false);
}
-int qemu_spice_display_add_client(int csock, int skipauth, int tls)
+static int qemu_spice_display_add_client(int csock, int skipauth, int tls)
{
if (tls) {
return spice_server_add_ssl_client(spice_server, csock, skipauth);
@@ -886,8 +968,45 @@ int qemu_spice_display_add_client(int csock, int skipauth, int tls)
}
}
+void qemu_spice_display_start(void)
+{
+ if (spice_display_is_running) {
+ return;
+ }
+
+ spice_display_is_running = true;
+ spice_server_vm_start(spice_server);
+}
+
+void qemu_spice_display_stop(void)
+{
+ if (!spice_display_is_running) {
+ return;
+ }
+
+ spice_server_vm_stop(spice_server);
+ spice_display_is_running = false;
+}
+
+int qemu_spice_display_is_running(SimpleSpiceDisplay *ssd)
+{
+ return spice_display_is_running;
+}
+
+static struct QemuSpiceOps real_spice_ops = {
+ .init = qemu_spice_init,
+ .display_init = qemu_spice_display_init,
+ .migrate_info = qemu_spice_migrate_info,
+ .set_passwd = qemu_spice_set_passwd,
+ .set_pw_expire = qemu_spice_set_pw_expire,
+ .display_add_client = qemu_spice_display_add_client,
+ .add_interface = qemu_spice_add_interface,
+ .qmp_query = qmp_query_spice_real,
+};
+
static void spice_register_config(void)
{
+ qemu_spice = real_spice_ops;
qemu_add_opts(&qemu_spice_opts);
}
-machine_init(spice_register_config);
+opts_init(spice_register_config);