/* core bits */
static SpiceServer *spice_server;
-static Notifier migration_state;
+static NotifierWithReturn migration_state;
static const char *auth = "spice";
static char *auth_passwd;
static time_t auth_expires = TIME_MAX;
static void watch_read(void *opaque)
{
SpiceWatch *watch = opaque;
- watch->func(watch->fd, SPICE_WATCH_EVENT_READ, watch->opaque);
+ int fd = watch->fd;
+
+#ifdef WIN32
+ fd = _get_osfhandle(fd);
+#endif
+ watch->func(fd, SPICE_WATCH_EVENT_READ, watch->opaque);
}
static void watch_write(void *opaque)
{
SpiceWatch *watch = opaque;
- watch->func(watch->fd, SPICE_WATCH_EVENT_WRITE, watch->opaque);
+ int fd = watch->fd;
+
+#ifdef WIN32
+ fd = _get_osfhandle(fd);
+#endif
+ watch->func(fd, SPICE_WATCH_EVENT_WRITE, watch->opaque);
}
static void watch_update_mask(SpiceWatch *watch, int event_mask)
{
SpiceWatch *watch;
+#ifdef WIN32
+ fd = _open_osfhandle(fd, _O_BINARY);
+ if (fd < 0) {
+ error_setg_win32(&error_warn, WSAGetLastError(), "Couldn't associate a FD with the SOCKET");
+ return NULL;
+ }
+#endif
+
watch = g_malloc0(sizeof(*watch));
watch->fd = fd;
watch->func = func;
static void watch_remove(SpiceWatch *watch)
{
qemu_set_fd_handler(watch->fd, NULL, NULL, NULL);
+#ifdef WIN32
+ /* SOCKET is owned by spice */
+ qemu_close_socket_osfhandle(watch->fd);
+#endif
g_free(watch);
}
* not do that. It isn't that easy to fix it in spice and even
* when it is fixed we still should cover the already released
* spice versions. So detect that we've been called from another
- * thread and grab the iothread lock if so before calling qemu
+ * thread and grab the BQL if so before calling qemu
* functions.
*/
bool need_lock = !qemu_thread_is_self(&me);
if (need_lock) {
- qemu_mutex_lock_iothread();
+ bql_lock();
}
if (info->flags & SPICE_CHANNEL_EVENT_FLAG_ADDR_EXT) {
break;
case SPICE_CHANNEL_EVENT_INITIALIZED:
if (auth) {
- server->has_auth = true;
server->auth = g_strdup(auth);
}
add_channel_info(client, info);
}
if (need_lock) {
- qemu_mutex_unlock_iothread();
+ bql_unlock();
}
qapi_free_SpiceServerInfo(server);
.name = "unix",
.type = QEMU_OPT_BOOL,
#endif
- },{
- .name = "password",
- .type = QEMU_OPT_STRING,
},{
.name = "password-secret",
.type = QEMU_OPT_STRING,
port = qemu_opt_get_number(opts, "port", 0);
tls_port = qemu_opt_get_number(opts, "tls-port", 0);
- info->has_auth = true;
info->auth = g_strdup(auth);
-
- info->has_host = true;
info->host = g_strdup(addr ? addr : "*");
- info->has_compiled_version = true;
major = (SPICE_SERVER_VERSION & 0xff0000) >> 16;
minor = (SPICE_SERVER_VERSION & 0xff00) >> 8;
micro = SPICE_SERVER_VERSION & 0xff;
return info;
}
-static void migration_state_notifier(Notifier *notifier, void *data)
+static int migration_state_notifier(NotifierWithReturn *notifier,
+ MigrationEvent *e, Error **errp)
{
- MigrationState *s = data;
-
if (!spice_have_target_host) {
- return;
+ return 0;
}
- if (migration_in_setup(s)) {
+ if (e->type == MIG_EVENT_PRECOPY_SETUP) {
spice_server_migrate_start(spice_server);
- } else if (migration_has_finished(s) ||
- migration_in_postcopy_after_devices(s)) {
+ } else if (e->type == MIG_EVENT_PRECOPY_DONE) {
spice_server_migrate_end(spice_server, true);
spice_have_target_host = false;
- } else if (migration_has_failed(s)) {
+ } else if (e->type == MIG_EVENT_PRECOPY_FAILED) {
spice_server_migrate_end(spice_server, false);
spice_have_target_host = false;
}
+ return 0;
}
int qemu_spice_migrate_info(const char *hostname, int port, int tls_port,
}
passwordSecret = qemu_opt_get(opts, "password-secret");
if (passwordSecret) {
- Error *local_err = NULL;
- if (qemu_opt_get(opts, "password")) {
- error_report("'password' option is mutually exclusive with "
- "'password-secret'");
- exit(1);
- }
password = qcrypto_secret_lookup_as_utf8(passwordSecret,
- &local_err);
- if (!password) {
- error_report_err(local_err);
- exit(1);
- }
- } else {
- str = qemu_opt_get(opts, "password");
- if (str) {
- warn_report("'password' option is deprecated and insecure, "
- "use 'password-secret' instead");
- password = g_strdup(str);
- }
+ &error_fatal);
}
if (tls_port) {
};
using_spice = 1;
- migration_state.notify = migration_state_notifier;
- add_migration_state_change_notifier(&migration_state);
+ migration_add_notifier(&migration_state, migration_state_notifier);
spice_migrate.base.sif = &migrate_interface.base;
qemu_spice.add_interface(&spice_migrate.base);
"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;
+ egl_init(qemu_opt_get(opts, "rendernode"), DISPLAYGL_MODE_ON, &error_fatal);
spice_opengl = 1;
}
#endif
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);
- }
-
- 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)) {
static int qemu_spice_display_add_client(int csock, int skipauth, int tls)
{
+#ifdef WIN32
+ csock = qemu_close_socket_osfhandle(csock);
+#endif
if (tls) {
return spice_server_add_ssl_client(spice_server, csock, skipauth);
} else {
qemu_add_opts(&qemu_spice_opts);
}
opts_init(spice_register_config);
+module_opts("spice");
+
+#ifdef HAVE_SPICE_GL
+module_dep("ui-opengl");
+#endif