Skip to contentSkip to conversation

xl: create VFB for PV guest when VNC is specified

PATCH Superseded Wei Liu 3 participants 4 messages Dec 16, 2013

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Wei Liu

author
#0 lore raw

PATCH 1/1 xl: create VFB for PV guest when VNC is specified

This replicates a Xend behavior, when you specify:

vnc=1
vnclisten=XXXX
vncpasswd=XXXX

in a PV guest's config file, it creates a VFB for you.

Fixes bug #25.
http://bugs.xenproject.org/xen/bug/25

---
Changes in V2:
* use macros to reduce code duplication
* vfb=[] take precedence over top level VNC options
---

---
 tools/libxl/xl_cmdimpl.c |   96 ++++++++++++++++++++++++++++++++++------------
 1 file changed, 72 insertions(+), 24 deletions(-)
tools/libxl/xl_cmdimpl.c +72 -24
index bd26bcc..f3f4d71 100644
@@ -1357,11 +1357,37 @@ skip_nic:
         fprintf(stderr, "WARNING: vif2: netchannel2 is deprecated and not supported by xl\n");
     }
 
+#define add_vfb_vkb(vfb,vkb)                                            \
+        do {                                                            \
+            libxl_device_vfb *_vfb;                                     \
+            libxl_device_vkb *_vkb;                                     \
+                                                                        \
+            d_config->vfbs = (libxl_device_vfb *)                       \
+                xrealloc(d_config->vfbs,                                \
+                         sizeof(libxl_device_vfb) * (d_config->num_vfbs + 1)); \
+            _vfb = d_config->vfbs + d_config->num_vfbs;                 \
+            libxl_device_vfb_init(_vfb);                                \
+            _vfb->devid = d_config->num_vfbs;                           \
+                                                                        \
+            d_config->vkbs = (libxl_device_vkb *)                       \
+                xrealloc(d_config->vkbs,                                \
+                         sizeof(libxl_device_vkb) * (d_config->num_vkbs + 1)); \
+            _vkb = d_config->vkbs + d_config->num_vkbs;                 \
+            libxl_device_vkb_init(_vkb);                                \
+            _vkb->devid = d_config->num_vkbs;                           \
+                                                                        \
+            d_config->num_vfbs++;                                       \
+            d_config->num_vkbs++;                                       \
+            (vfb) = _vfb;                                               \
+            (vkb) = _vkb;                                               \
+        } while (0)
+
+    d_config->num_vfbs = 0;
+    d_config->num_vkbs = 0;
+    d_config->vfbs = NULL;
+    d_config->vkbs = NULL;
+
     if (!xlu_cfg_get_list (config, "vfb", &cvfbs, 0, 0)) {
-        d_config->num_vfbs = 0;
-        d_config->num_vkbs = 0;
-        d_config->vfbs = NULL;
-        d_config->vkbs = NULL;
         while ((buf = xlu_cfg_get_listitem (cvfbs, d_config->num_vfbs)) != NULL) {
             libxl_device_vfb *vfb;
             libxl_device_vkb *vkb;
@@ -1369,15 +1395,7 @@ skip_nic:
             char *buf2 = strdup(buf);
             char *p, *p2;
 
-            d_config->vfbs = (libxl_device_vfb *) realloc(d_config->vfbs, sizeof(libxl_device_vfb) * (d_config->num_vfbs + 1));
-            vfb = d_config->vfbs + d_config->num_vfbs;
-            libxl_device_vfb_init(vfb);
-            vfb->devid = d_config->num_vfbs;
-
-            d_config->vkbs = (libxl_device_vkb *) realloc(d_config->vkbs, sizeof(libxl_device_vkb) * (d_config->num_vkbs + 1));
-            vkb = d_config->vkbs + d_config->num_vkbs;
-            libxl_device_vkb_init(vkb);
-            vkb->devid = d_config->num_vkbs;
+            add_vfb_vkb(vfb, vkb);
 
             p = strtok(buf2, ",");
             if (!p)
@@ -1418,8 +1436,6 @@ skip_nic:
 
 skip_vfb:
             free(buf2);
-            d_config->num_vfbs++;
-            d_config->num_vkbs++;
         }
     }
 
@@ -1608,6 +1624,47 @@ skip_vfb:
 
 #undef parse_extra_args
 
+#define parse_top_level_vnc_options(enable,listen,passwd,display,unused) \
+    do {                                                                \
+        long _l;                                                        \
+        xlu_cfg_get_defbool(config, "vnc", (enable), 0);                \
+        xlu_cfg_replace_string (config, "vnclisten", (listen), 0);      \
+        xlu_cfg_replace_string (config, "vncpasswd", (passwd), 0);      \
+        if (!xlu_cfg_get_long (config, "vncdisplay", &_l, 0))           \
+            (display) = _l;                                             \
+        xlu_cfg_get_defbool(config, "vncunused", (unused), 0);          \
+    } while (0)
+
+    /* If we've already got vfb=[] for PV guestthen ignore top level
+     * VNC config. */
+    if (c_info->type == LIBXL_DOMAIN_TYPE_PV && !d_config->num_vfbs) {
+        long vnc_enabled = 0;
+
+        if (!xlu_cfg_get_long (config, "vnc", &l, 0))
+            vnc_enabled = l;
+
+        if (vnc_enabled) {
+            libxl_device_vfb *vfb;
+            libxl_device_vkb *vkb;
+
+            add_vfb_vkb(vfb, vkb);
+
+            parse_top_level_vnc_options(&vfb->vnc.enable,
+                                        &vfb->vnc.listen,
+                                        &vfb->vnc.passwd,
+                                        vfb->vnc.display,
+                                        &vfb->vnc.findunused);
+
+        }
+    } else {
+        parse_top_level_vnc_options(&b_info->u.hvm.vnc.enable,
+                                    &b_info->u.hvm.vnc.listen,
+                                    &b_info->u.hvm.vnc.passwd,
+                                    b_info->u.hvm.vnc.display,
+                                    &b_info->u.hvm.vnc.findunused);
+    }
+#undef parse_top_level_vnc_options
+
     if (c_info->type == LIBXL_DOMAIN_TYPE_HVM) {
         if (!xlu_cfg_get_string (config, "vga", &buf, 0)) {
             if (!strcmp(buf, "stdvga")) {
@@ -1622,15 +1679,6 @@ skip_vfb:
             b_info->u.hvm.vga.kind = l ? LIBXL_VGA_INTERFACE_TYPE_STD :
                                          LIBXL_VGA_INTERFACE_TYPE_CIRRUS;
 
-        xlu_cfg_get_defbool(config, "vnc", &b_info->u.hvm.vnc.enable, 0);
-        xlu_cfg_replace_string (config, "vnclisten",
-                                &b_info->u.hvm.vnc.listen, 0);
-        xlu_cfg_replace_string (config, "vncpasswd",
-                                &b_info->u.hvm.vnc.passwd, 0);
-        if (!xlu_cfg_get_long (config, "vncdisplay", &l, 0))
-            b_info->u.hvm.vnc.display = l;
-        xlu_cfg_get_defbool(config, "vncunused",
-                            &b_info->u.hvm.vnc.findunused, 0);
         xlu_cfg_replace_string (config, "keymap", &b_info->u.hvm.keymap, 0);
         xlu_cfg_get_defbool(config, "sdl", &b_info->u.hvm.sdl.enable, 0);
         xlu_cfg_get_defbool(config, "opengl", &b_info->u.hvm.sdl.opengl, 0);
Signature · 1 line
1.7.10.4
author
#1 lore raw

This is version 2 of that patch, I forgot to add that in subject line, sorry.

#2 lore raw
In reply to Wei Liu
Quoted 30 lines · Wei Liu

This replicates a Xend behavior, when you specify:

vnc=1
vnclisten=XXXX
vncpasswd=XXXX

in a PV guest's config file, it creates a VFB for you.

Fixes bug #25.
http://bugs.xenproject.org/xen/bug/25

---
Changes in V2:
* use macros to reduce code duplication
* vfb=[] take precedence over top level VNC options
---

---
 tools/libxl/xl_cmdimpl.c |   96 ++++++++++++++++++++++++++++++++++------------
 1 file changed, 72 insertions(+), 24 deletions(-)
tools/libxl/xl_cmdimpl.c +0 -0
index bd26bcc..f3f4d71 100644

tools/libxl/xl_cmdimpl.c skip_nic: · line 1360

Quoted 4 lines
tools/libxl/xl_cmdimpl.c +1 -0
@@ -1357,11 +1357,37 @@ skip_nic:
         fprintf(stderr, "WARNING: vif2: netchannel2 is deprecated and not supported by xl\n");
     }
 
+#define add_vfb_vkb(vfb,vkb)                                            \

I think what Ian was suggesting was a single macro which could expand an arbitrary array given as a parameter, rather than this, which is pretty fuggly. e.g.

	vfb = ARRAY_EXTEND(d_config->vfbs, d_config->num_vfbs)

or something (making liberal use of typeof() etc). Perhaps even
vfb = ARRAY_EXTEND(d_config, vfbs)
and some cpp token pasting.

Once you have that you can use it for both vkb and vfb.

I think you would be better off skipping the ->devid set, but if you want to keep it you'd want to call it something more suitable like NEW_DEVICE() perhaps.

You don't need to use the new macro everywhere right now during code freeze but we can flip everything in 4.5.

tools/libxl/xl_cmdimpl.c skip_vfb: · line 1627

Quoted 5 lines
tools/libxl/xl_cmdimpl.c +1 -0
@@ -1608,6 +1624,47 @@ skip_vfb:
 
 #undef parse_extra_args
 
+#define parse_top_level_vnc_options(enable,listen,passwd,display,unused) \

I think this could be a function, which is would be preferable to a macro if possible.

Ian.

#3 lore raw

Ian Campbell writes ("Re: [PATCH] xl: create VFB for PV guest when VNC is specified"):

Quoted 7 lines

I think what Ian was suggesting was a single macro which could expand an arbitrary array given as a parameter, rather than this, which is pretty fuggly. e.g.

	vfb = ARRAY_EXTEND(d_config->vfbs, d_config->num_vfbs)

or something (making liberal use of typeof() etc). Perhaps even
vfb = ARRAY_EXTEND(d_config, vfbs)
and some cpp token pasting.

Exactly.

Quoted 8 lines

Once you have that you can use it for both vkb and vfb.

I think you would be better off skipping the ->devid set, but if you want to keep it you'd want to call it something more suitable like NEW_DEVICE() perhaps.

You don't need to use the new macro everywhere right now during code freeze but we can flip everything in 4.5.

Right.

Quoted 8 lines

tools/libxl/xl_cmdimpl.c skip_vfb: · line 1627

Quoted 5 lines
tools/libxl/xl_cmdimpl.c +1 -0
@@ -1608,6 +1624,47 @@ skip_vfb:
 
 #undef parse_extra_args
 
+#define parse_top_level_vnc_options(enable,listen,passwd,display,unused) \

I think this could be a function, which is would be preferable to a macro if possible.

Absolutely.

Ian.