}
+static void
+virDomainDefPostParseGraphics(virDomainDef *def)
+{
+ size_t i;
+
+ for (i = 0; i < def->ngraphics; i++) {
+ virDomainGraphicsDefPtr graphics = def->graphics[i];
+
+ /* If spice graphics is configured without ports and with autoport='no'
+ * then we start qemu with Spice to not listen anywhere. Let's convert
+ * this configuration to the new listen type='none' which does the
+ * same. */
+ if (graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_SPICE) {
+ virDomainGraphicsListenDefPtr glisten = &graphics->listens[0];
+
+ if (glisten->type == VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS &&
+ graphics->data.spice.port == 0 &&
+ graphics->data.spice.tlsPort == 0 &&
+ !graphics->data.spice.autoport) {
+ VIR_FREE(glisten->address);
+ glisten->type = VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NONE;
+ }
+ }
+ }
+}
+
+
/* Check if a drive type address $controller:$bus:$target:$unit is already
* taken by a disk or not.
*/
/* clean up possibly duplicated metadata entries */
virDomainDefMetadataSanitize(def);
+ virDomainDefPostParseGraphics(def);
+
return 0;
}
}
def->type = typeVal;
- if (def->type == VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_SOCKET &&
- graphics->type != VIR_DOMAIN_GRAPHICS_TYPE_VNC &&
- graphics->type != VIR_DOMAIN_GRAPHICS_TYPE_SPICE) {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
- _("listen type 'socket' is not available for "
- "graphics type '%s'"), graphicsType);
- goto error;
+ switch (def->type) {
+ case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_SOCKET:
+ if (graphics->type != VIR_DOMAIN_GRAPHICS_TYPE_VNC &&
+ graphics->type != VIR_DOMAIN_GRAPHICS_TYPE_SPICE) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("listen type 'socket' is not available for "
+ "graphics type '%s'"), graphicsType);
+ goto error;
+ }
+ break;
+ case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NONE:
+ if (graphics->type != VIR_DOMAIN_GRAPHICS_TYPE_SPICE) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("listen type 'none' is not available for "
+ "graphics type '%s'"), graphicsType);
+ goto error;
+ }
+ break;
+ case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS:
+ case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NETWORK:
+ case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_LAST:
+ break;
}
if (def->type == VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS) {
return;
virBufferAddLit(buf, "<listen");
- if (def->type) {
- virBufferAsprintf(buf, " type='%s'",
- virDomainGraphicsListenTypeToString(def->type));
- }
+ virBufferAsprintf(buf, " type='%s'",
+ virDomainGraphicsListenTypeToString(def->type));
if (def->address &&
(def->type == VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS ||
break;
case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NONE:
+ if (flags & VIR_DOMAIN_DEF_FORMAT_MIGRATABLE)
+ virBufferAddStr(buf, " autoport='no'");
+ break;
+
case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_SOCKET:
case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_LAST:
break;
}
for (i = 0; i < def->nListens; i++) {
- if (def->listens[i].type == VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NONE)
- continue;
if (flags & VIR_DOMAIN_DEF_FORMAT_MIGRATABLE) {
/* If the listen is based on config options from qemu.conf we need
* to skip it. It's up to user to properly configure both hosts for
def->listens[i].type == VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_SOCKET &&
!def->listens[i].autoGenerated)
continue;
+
+ /* The new listen type none is in the migratable XML represented as
+ * port=0 and autoport=no because old libvirt support this
+ * configuration for spice. */
+ if (def->type == VIR_DOMAIN_GRAPHICS_TYPE_SPICE &&
+ def->listens[i].type == VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NONE)
+ continue;
}
if (!children) {
virBufferAddLit(buf, ">\n");
break;
case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NONE:
+ /* QEMU requires either port or tls-port to be specified if there is no
+ * other argument. Use a dummy port=0. */
+ virBufferAddLit(&opt, "port=0,");
+ hasInsecure = true;
+ break;
case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_LAST:
break;
}
virBufferTrim(&opt, ",", -1);
virCommandAddArg(cmd, "-spice");
- /* If we did not add any SPICE arguments, add a dummy 'port=0' one
- * as -spice alone is not allowed on QEMU command line
- */
- if (virBufferUse(&opt) == 0)
- virCommandAddArg(cmd, "port=0");
- else
- virCommandAddArgBuffer(cmd, &opt);
+ virCommandAddArgBuffer(cmd, &opt);
if (graphics->data.spice.keymap)
virCommandAddArgList(cmd, "-k",
graphics->data.spice.keymap, NULL);