diff --git a/hw/display/qxl.c b/hw/display/qxl.c index 074ed43e27da8eda21c3269494c24dd3d923d6b5..c2cea1ce8877925ae69b6d2fd4561f60d976bcbe 100644 --- a/hw/display/qxl.c +++ b/hw/display/qxl.c @@ -2037,8 +2037,7 @@ static int qxl_init_common(PCIQXLDevice *qxl) qxl->vram32_size < qxl->vram_size ? "[region 4]" : "[unmapped]"); qxl->ssd.qxl.base.sif = &qxl_interface.base; - qxl->ssd.qxl.id = qxl->id; - if (qemu_spice_add_interface(&qxl->ssd.qxl.base) != 0) { + if (qemu_spice_add_display_interface(&qxl->ssd.qxl, qxl->vga.con) != 0) { error_report("qxl interface %d.%d not supported by spice-server", SPICE_INTERFACE_QXL_MAJOR, SPICE_INTERFACE_QXL_MINOR); return -1; diff --git a/include/ui/qemu-spice.h b/include/ui/qemu-spice.h index c6c756b23d80f667ff13273877079a6a37cd49a0..86c75c7a719f0d5c116660da60f006469121628b 100644 --- a/include/ui/qemu-spice.h +++ b/include/ui/qemu-spice.h @@ -27,14 +27,15 @@ #include "monitor/monitor.h" extern int using_spice; -extern int spice_displays; void qemu_spice_init(void); void qemu_spice_input_init(void); void qemu_spice_audio_init(void); -void qemu_spice_display_init(DisplayState *ds); +void qemu_spice_display_init(void); int qemu_spice_display_add_client(int csock, int skipauth, int tls); int qemu_spice_add_interface(SpiceBaseInstance *sin); +bool qemu_spice_have_display_interface(QemuConsole *con); +int qemu_spice_add_display_interface(QXLInstance *qxlin, QemuConsole *con); 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); diff --git a/ui/spice-core.c b/ui/spice-core.c index 1976b712ba64b46c464f901ca9428309c5ce68bf..e4d533d4c4f2a69ed999574f564f5a47436f131b 100644 --- a/ui/spice-core.c +++ b/ui/spice-core.c @@ -48,7 +48,6 @@ static char *auth_passwd; static time_t auth_expires = TIME_MAX; static int spice_migration_completed; int using_spice = 0; -int spice_displays; static QemuThread me; @@ -837,11 +836,28 @@ int qemu_spice_add_interface(SpiceBaseInstance *sin) 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; +static int display_id; + +bool qemu_spice_have_display_interface(QemuConsole *con) +{ + if (g_slist_find(spice_consoles, con)) { + return true; } + return false; +} - return spice_server_add_interface(spice_server, sin); +int qemu_spice_add_display_interface(QXLInstance *qxlin, QemuConsole *con) +{ + if (g_slist_find(spice_consoles, con)) { + return -1; + } + qxlin->id = display_id++; + 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) diff --git a/ui/spice-display.c b/ui/spice-display.c index c15c5554a9aca6ea43471d4ad31754095d038a63..f23a31854de7d164d4316f94d2bdcd85ed7e9e9e 100644 --- a/ui/spice-display.c +++ b/ui/spice-display.c @@ -612,21 +612,38 @@ static const DisplayChangeListenerOps display_listener_ops = { .dpy_refresh = display_refresh, }; -void qemu_spice_display_init(DisplayState *ds) +static void qemu_spice_display_init_one(QemuConsole *con) { SimpleSpiceDisplay *ssd = g_new0(SimpleSpiceDisplay, 1); qemu_spice_display_init_common(ssd); ssd->qxl.base.sif = &dpy_interface.base; - qemu_spice_add_interface(&ssd->qxl.base); + qemu_spice_add_display_interface(&ssd->qxl, con); assert(ssd->worker); qemu_spice_create_host_memslot(ssd); ssd->dcl.ops = &display_listener_ops; - ssd->dcl.con = qemu_console_lookup_by_index(0); + ssd->dcl.con = con; register_displaychangelistener(&ssd->dcl); qemu_spice_create_host_primary(ssd); } + +void qemu_spice_display_init(void) +{ + QemuConsole *con; + int i; + + for (i = 0;; i++) { + con = qemu_console_lookup_by_index(i); + if (!con || !qemu_console_is_graphic(con)) { + break; + } + if (qemu_spice_have_display_interface(con)) { + continue; + } + qemu_spice_display_init_one(con); + } +} diff --git a/vl.c b/vl.c index 7e1f40880d23acc6f6be8f3f3a77032eb2d92352..b42ac67100ac76b8b6fb649181a1a7c1fb9b5765 100644 --- a/vl.c +++ b/vl.c @@ -4315,8 +4315,8 @@ int main(int argc, char **argv, char **envp) } #endif #ifdef CONFIG_SPICE - if (using_spice && !spice_displays) { - qemu_spice_display_init(ds); + if (using_spice) { + qemu_spice_display_init(); } #endif