]> xenbits.xensource.com Git - libvirt.git/commitdiff
libxl: support SPICE graphics for HVM domains
authorJim Fehlig <jfehlig@suse.com>
Mon, 27 Apr 2015 22:27:52 +0000 (16:27 -0600)
committerJim Fehlig <jfehlig@suse.com>
Thu, 28 May 2015 18:40:43 +0000 (12:40 -0600)
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
src/libxl/libxl_conf.c

index fb601b79804f25386428859796dcc5f558209c38..b65d2617b8676c3f4a9212675d77dc736dd0b712 100644 (file)
@@ -1339,21 +1339,84 @@ libxlMakeVfbList(virPortAllocatorPtr graphicsports,
 
 /*
  * Populate vfb info in libxl_domain_build_info struct for HVM domains.
- * Use first libxl_device_vfb device in libxl_domain_config->vfbs.
  * Prior to calling this function, libxlMakeVfbList must be called to
  * populate libxl_domain_config->vfbs.
  */
 static int
-libxlMakeBuildInfoVfb(virDomainDefPtr def, libxl_domain_config *d_config)
+libxlMakeBuildInfoVfb(virPortAllocatorPtr graphicsports,
+                      virDomainDefPtr def,
+                      libxl_domain_config *d_config)
 {
     libxl_domain_build_info *b_info = &d_config->b_info;
     libxl_device_vfb x_vfb;
+    size_t i;
 
     if (def->os.type != VIR_DOMAIN_OSTYPE_HVM)
         return 0;
 
-    if (d_config->num_vfbs == 0)
+    if (def->ngraphics == 0)
+        return 0;
+
+    /*
+     * Prefer SPICE, otherwise use first libxl_device_vfb device in
+     * libxl_domain_config->vfbs. Prior to calling this function,
+     */
+    for (i = 0; i < def->ngraphics; i++) {
+        virDomainGraphicsDefPtr l_vfb = def->graphics[i];
+        unsigned short port;
+        const char *listenAddr;
+
+        if (l_vfb->type != VIR_DOMAIN_GRAPHICS_TYPE_SPICE)
+            continue;
+
+        libxl_defbool_set(&b_info->u.hvm.spice.enable, true);
+
+        if (l_vfb->data.spice.autoport) {
+            if (virPortAllocatorAcquire(graphicsports, &port) < 0)
+                return -1;
+            l_vfb->data.spice.port = port;
+        }
+        b_info->u.hvm.spice.port = l_vfb->data.spice.port;
+
+        listenAddr = virDomainGraphicsListenGetAddress(l_vfb, 0);
+        if (VIR_STRDUP(b_info->u.hvm.spice.host, listenAddr) < 0)
+            return -1;
+
+        if (VIR_STRDUP(b_info->u.hvm.keymap, l_vfb->data.spice.keymap) < 0)
+            return -1;
+
+        if (l_vfb->data.spice.auth.passwd) {
+            if (VIR_STRDUP(b_info->u.hvm.spice.passwd,
+                           l_vfb->data.spice.auth.passwd) < 0)
+                return -1;
+            libxl_defbool_set(&b_info->u.hvm.spice.disable_ticketing, false);
+        } else {
+            libxl_defbool_set(&b_info->u.hvm.spice.disable_ticketing, true);
+        }
+
+        switch (l_vfb->data.spice.mousemode) {
+            /* client mouse mode is default in xl.cfg */
+        case VIR_DOMAIN_GRAPHICS_SPICE_MOUSE_MODE_DEFAULT:
+        case VIR_DOMAIN_GRAPHICS_SPICE_MOUSE_MODE_CLIENT:
+            libxl_defbool_set(&b_info->u.hvm.spice.agent_mouse, true);
+            break;
+        case VIR_DOMAIN_GRAPHICS_SPICE_MOUSE_MODE_SERVER:
+            libxl_defbool_set(&b_info->u.hvm.spice.agent_mouse, false);
+            break;
+        }
+
+#ifdef LIBXL_HAVE_SPICE_VDAGENT
+        if (l_vfb->data.spice.copypaste == VIR_TRISTATE_BOOL_YES) {
+            libxl_defbool_set(&b_info->u.hvm.spice.vdagent, true);
+            libxl_defbool_set(&b_info->u.hvm.spice.clipboard_sharing, true);
+        } else {
+            libxl_defbool_set(&b_info->u.hvm.spice.vdagent, false);
+            libxl_defbool_set(&b_info->u.hvm.spice.clipboard_sharing, false);
+        }
+#endif
+
         return 0;
+    }
 
     x_vfb = d_config->vfbs[0];
 
@@ -1780,7 +1843,7 @@ libxlBuildDomainConfig(virPortAllocatorPtr graphicsports,
     if (libxlMakeVfbList(graphicsports, def, d_config) < 0)
         return -1;
 
-    if (libxlMakeBuildInfoVfb(def, d_config) < 0)
+    if (libxlMakeBuildInfoVfb(graphicsports, def, d_config) < 0)
         return -1;
 
     if (libxlMakePCIList(def, d_config) < 0)