From 09f2faf9330d7fb3c83db6b03a57891874932b33 Mon Sep 17 00:00:00 2001 From: Jim Fehlig Date: Mon, 27 Apr 2015 12:32:55 -0600 Subject: [PATCH] libxl: populate build_info vfb in separate function For HVM domains, vfb info must be populated in the libxl_domain_build_info struct. Currently this is done in the libxlMakeVfbList function, but IMO it would be cleaner to populate the build_info vfb in a separate libxlMakeBuildInfoVfb function. libxlMakeVfbList would then handle only vfb devices, simiar to the other libxlMakeList functions. A future patch will extend libxlMakeBuildInfoVfb to support SPICE. Signed-off-by: Jim Fehlig --- src/libxl/libxl_conf.c | 79 +++++++++++++++++++++++++----------------- 1 file changed, 48 insertions(+), 31 deletions(-) diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c index 35b1d04ad0..fb601b7980 100644 --- a/src/libxl/libxl_conf.c +++ b/src/libxl/libxl_conf.c @@ -1325,37 +1325,6 @@ libxlMakeVfbList(virPortAllocatorPtr graphicsports, d_config->vkbs = x_vkbs; d_config->num_vfbs = d_config->num_vkbs = nvfbs; - /* - * VNC or SDL info must also be set in libxl_domain_build_info - * for HVM domains. Use the first vfb device. - */ - if (def->os.type == VIR_DOMAIN_OSTYPE_HVM) { - libxl_domain_build_info *b_info = &d_config->b_info; - libxl_device_vfb vfb = d_config->vfbs[0]; - - if (libxl_defbool_val(vfb.vnc.enable)) { - libxl_defbool_set(&b_info->u.hvm.vnc.enable, true); - if (VIR_STRDUP(b_info->u.hvm.vnc.listen, vfb.vnc.listen) < 0) - goto error; - if (VIR_STRDUP(b_info->u.hvm.vnc.passwd, vfb.vnc.passwd) < 0) - goto error; - b_info->u.hvm.vnc.display = vfb.vnc.display; - libxl_defbool_set(&b_info->u.hvm.vnc.findunused, - libxl_defbool_val(vfb.vnc.findunused)); - } else if (libxl_defbool_val(vfb.sdl.enable)) { - libxl_defbool_set(&b_info->u.hvm.sdl.enable, true); - libxl_defbool_set(&b_info->u.hvm.sdl.opengl, - libxl_defbool_val(vfb.sdl.opengl)); - if (VIR_STRDUP(b_info->u.hvm.sdl.display, vfb.sdl.display) < 0) - goto error; - if (VIR_STRDUP(b_info->u.hvm.sdl.xauthority, vfb.sdl.xauthority) < 0) - goto error; - } - - if (VIR_STRDUP(b_info->u.hvm.keymap, vfb.keymap) < 0) - goto error; - } - return 0; error: @@ -1368,6 +1337,51 @@ libxlMakeVfbList(virPortAllocatorPtr graphicsports, return -1; } +/* + * 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) +{ + libxl_domain_build_info *b_info = &d_config->b_info; + libxl_device_vfb x_vfb; + + if (def->os.type != VIR_DOMAIN_OSTYPE_HVM) + return 0; + + if (d_config->num_vfbs == 0) + return 0; + + x_vfb = d_config->vfbs[0]; + + if (libxl_defbool_val(x_vfb.vnc.enable)) { + libxl_defbool_set(&b_info->u.hvm.vnc.enable, true); + if (VIR_STRDUP(b_info->u.hvm.vnc.listen, x_vfb.vnc.listen) < 0) + return -1; + if (VIR_STRDUP(b_info->u.hvm.vnc.passwd, x_vfb.vnc.passwd) < 0) + return -1; + b_info->u.hvm.vnc.display = x_vfb.vnc.display; + libxl_defbool_set(&b_info->u.hvm.vnc.findunused, + libxl_defbool_val(x_vfb.vnc.findunused)); + } else if (libxl_defbool_val(x_vfb.sdl.enable)) { + libxl_defbool_set(&b_info->u.hvm.sdl.enable, true); + libxl_defbool_set(&b_info->u.hvm.sdl.opengl, + libxl_defbool_val(x_vfb.sdl.opengl)); + if (VIR_STRDUP(b_info->u.hvm.sdl.display, x_vfb.sdl.display) < 0) + return -1; + if (VIR_STRDUP(b_info->u.hvm.sdl.xauthority, x_vfb.sdl.xauthority) < 0) + return -1; + } + + if (VIR_STRDUP(b_info->u.hvm.keymap, x_vfb.keymap) < 0) + return -1; + + return 0; +} + /* * Get domain0 autoballoon configuration. Honor user-specified * setting in libxl.conf first. If not specified, autoballooning @@ -1766,6 +1780,9 @@ libxlBuildDomainConfig(virPortAllocatorPtr graphicsports, if (libxlMakeVfbList(graphicsports, def, d_config) < 0) return -1; + if (libxlMakeBuildInfoVfb(def, d_config) < 0) + return -1; + if (libxlMakePCIList(def, d_config) < 0) return -1; -- GitLab