]> xenbits.xensource.com Git - libvirt.git/commitdiff
spice: introduce listen type none
authorPavel Hrdina <phrdina@redhat.com>
Wed, 18 May 2016 06:33:28 +0000 (08:33 +0200)
committerPavel Hrdina <phrdina@redhat.com>
Thu, 9 Jun 2016 12:44:08 +0000 (14:44 +0200)
This new listen type is currently supported only by spice graphics.
It's introduced to make it easier and clearer specify to not listen
anywhere in order to start a guest with OpenGL support.

The old way to do this was set spice graphics autoport='no' and don't
specify any ports.  The new way is to use <listen type='none'/>.  In
order to be able to migrate to old libvirt the migratable XML will be
generated without the listen element and with autoport='no'.  Also the
old configuration will be automatically converted to the this listen
type.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
docs/formatdomain.html.in
docs/schemas/domaincommon.rng
src/conf/domain_conf.c
src/qemu/qemu_command.c
tests/qemuxml2argvdata/qemuxml2argv-video-virtio-gpu-spice-gl.args
tests/qemuxml2xmloutdata/qemuxml2xmlout-video-virtio-gpu-spice-gl.xml

index 29b24edb4fafbff91868a5f6df3ef0fd65b5e9bd..cf983ca04298f35d3900412dd7eefbd0ff2fa19a 100644 (file)
@@ -5376,6 +5376,17 @@ qemu-kvm -net nic,model=? /dev/null
           attribute all <code>listen</code> elements are ignored.
         </p>
       </dd>
+      <dt><code>none</code> <span class="since">since 1.3.6 (QEMU only)</span></dt>
+      <dd>
+        <p>
+          This listen type doesn't have any other attribute. Libvirt supports
+          passing a file descriptor through our APIs virDomainOpenGraphics() and
+          virDomainOpenGraphicsFD(). No other listen types are allowed if this
+          one is used and the graphics device doesn't listen anywhere. You need
+          to use one of the two APIs to pass a FD to QEMU in order to connect to
+          this graphics device. Supported by graphics type <code>spice</code>.
+        </p>
+      </dd>
     </dl>
 
     <h4><a name="elementsVideo">Video devices</a></h4>
index f0640cce10217216c8813531da296fbe540cc2c5..02078d73460a9b9fea29209dd75117418020ce86 100644 (file)
               </attribute>
             </optional>
           </group>
+          <group>
+            <attribute name="type">
+              <value>none</value>
+            </attribute>
+          </group>
         </choice>
       </element>
     </zeroOrMore>
index fedfb61c6f2fc3b48beef9224e6538dbba15ac98..1193c0864ba316a47cd09979bf244e42fdd57a0b 100644 (file)
@@ -3921,6 +3921,33 @@ virDomainDefPostParseTimer(virDomainDefPtr def)
 }
 
 
+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.
  */
@@ -4463,6 +4490,8 @@ virDomainDefPostParseInternal(virDomainDefPtr def,
     /* clean up possibly duplicated metadata entries */
     virDomainDefMetadataSanitize(def);
 
+    virDomainDefPostParseGraphics(def);
+
     return 0;
 }
 
@@ -10942,13 +10971,28 @@ virDomainGraphicsListenDefParseXML(virDomainGraphicsListenDefPtr def,
     }
     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) {
@@ -21753,10 +21797,8 @@ virDomainGraphicsListenDefFormat(virBufferPtr buf,
         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 ||
@@ -21943,6 +21985,10 @@ virDomainGraphicsDefFormat(virBufferPtr buf,
             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;
@@ -21964,8 +22010,6 @@ virDomainGraphicsDefFormat(virBufferPtr buf,
     }
 
     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
@@ -21982,6 +22026,13 @@ virDomainGraphicsDefFormat(virBufferPtr buf,
                 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");
index 21331b1e1fd4710915f0c520341fb1739fe93d18..d3e8172b878502c92b8ffde0b64bf7815013fbad 100644 (file)
@@ -7392,6 +7392,11 @@ qemuBuildGraphicsSPICECommandLine(virQEMUDriverConfigPtr cfg,
         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;
     }
@@ -7539,13 +7544,7 @@ qemuBuildGraphicsSPICECommandLine(virQEMUDriverConfigPtr cfg,
     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);
index b80ad1638abeb86f0b1316cc43441fbd17e69221..edecca15ce86785407c8a7351c8d4740eabe68b6 100644 (file)
@@ -19,6 +19,6 @@ QEMU_AUDIO_DRV=spice \
 -drive file=/var/lib/libvirt/images/QEMUGuest1,format=qcow2,if=none,\
 id=drive-ide0-0-0,cache=none \
 -device ide-drive,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0 \
--spice gl=on \
+-spice port=0,gl=on \
 -device virtio-vga,id=video0,virgl=on,bus=pci.0,addr=0x2 \
 -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3
index a6dddab5628ed0b0df14da6025e237f9514d44f0..9fb533ad90d8230c3016ea8774ab362ab69b43c0 100644 (file)
@@ -29,8 +29,8 @@
     <controller type='pci' index='0' model='pci-root'/>
     <input type='mouse' bus='ps2'/>
     <input type='keyboard' bus='ps2'/>
-    <graphics type='spice' autoport='no'>
-      <listen type='address'/>
+    <graphics type='spice'>
+      <listen type='none'/>
       <gl enable='yes'/>
     </graphics>
     <video>