[PATCH v2 1/4] bhyve: support parsing fbuf PCI device

Roman Bogorodskiy bogorodskiy at gmail.com
Tue Sep 22 12:28:48 UTC 2020


From: Fabian Freyer <fabian.freyer at physik.tu-berlin.de>

Add a new helper function, bhyveParsePCIFbuf, to parse the bhyve-argv
parameters for a frame-buffer device to <graphics/> and <video/>
definitions.

For now, only the listen address, port, and vga mode are detected.
Unsupported parameters are silently skipped.

This involves upgrading the private API to expose the
virDomainGraphicsDefNew helper function, which is used by
bhyveParsePCIFbuf.

Signed-off-by: Fabian Freyer <fabian.freyer at physik.tu-berlin.de>
Signed-off-by: Roman Bogorodskiy <bogorodskiy at gmail.com>
---
 src/bhyve/bhyve_parse_command.c               | 91 ++++++++++++++++++-
 src/libvirt_private.syms                      |  1 +
 .../bhyveargv2xml-vnc-listen.args             | 10 ++
 .../bhyveargv2xml-vnc-listen.xml              | 22 +++++
 .../bhyveargv2xml-vnc-vga-io.args             | 10 ++
 .../bhyveargv2xml-vnc-vga-io.xml              | 22 +++++
 .../bhyveargv2xml-vnc-vga-off.args            | 10 ++
 .../bhyveargv2xml-vnc-vga-off.xml             | 23 +++++
 .../bhyveargv2xml-vnc-vga-on.args             | 10 ++
 .../bhyveargv2xml-vnc-vga-on.xml              | 23 +++++
 .../bhyveargv2xmldata/bhyveargv2xml-vnc.args  | 10 ++
 tests/bhyveargv2xmldata/bhyveargv2xml-vnc.xml | 22 +++++
 tests/bhyveargv2xmltest.c                     |  5 +
 13 files changed, 258 insertions(+), 1 deletion(-)
 create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-vnc-listen.args
 create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-vnc-listen.xml
 create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-vnc-vga-io.args
 create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-vnc-vga-io.xml
 create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-vnc-vga-off.args
 create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-vnc-vga-off.xml
 create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-vnc-vga-on.args
 create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-vnc-vga-on.xml
 create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-vnc.args
 create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-vnc.xml

diff --git a/src/bhyve/bhyve_parse_command.c b/src/bhyve/bhyve_parse_command.c
index 50a5e88408..388c565317 100644
--- a/src/bhyve/bhyve_parse_command.c
+++ b/src/bhyve/bhyve_parse_command.c
@@ -4,7 +4,7 @@
  * Copyright (C) 2006-2016 Red Hat, Inc.
  * Copyright (C) 2006 Daniel P. Berrange
  * Copyright (c) 2011 NetApp, Inc.
- * Copyright (C) 2016 Fabian Freyer
+ * Copyright (C) 2020 Fabian Freyer
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -553,6 +553,93 @@ bhyveParsePCINet(virDomainDefPtr def,
     return -1;
 }
 
+static int
+bhyveParsePCIFbuf(virDomainDefPtr def,
+                  virDomainXMLOptionPtr xmlopt,
+                  unsigned caps G_GNUC_UNUSED,
+                  unsigned bus,
+                  unsigned slot,
+                  unsigned function,
+                  const char *config)
+{
+    /* -s slot,fbuf,wait,vga=on|io|off,rfb=<ip>:port,w=width,h=height */
+
+    virDomainVideoDefPtr video = NULL;
+    virDomainGraphicsDefPtr graphics = NULL;
+    char **params = NULL;
+    char *param = NULL, *separator = NULL;
+    size_t nparams = 0;
+    unsigned int i = 0;
+
+    if (!(video = virDomainVideoDefNew(xmlopt)))
+        goto cleanup;
+
+    if (!(graphics = virDomainGraphicsDefNew(xmlopt)))
+        goto cleanup;
+
+    graphics->type = VIR_DOMAIN_GRAPHICS_TYPE_VNC;
+    video->info.addr.pci.bus = bus;
+    video->info.addr.pci.slot = slot;
+    video->info.addr.pci.function = function;
+
+    if (!config)
+        goto error;
+
+    if (!(params = virStringSplitCount(config, ",", 0, &nparams)))
+        goto error;
+
+    for (i = 0; i < nparams; i++) {
+        param = params[i];
+        if (!video->driver && VIR_ALLOC(video->driver) < 0)
+            goto error;
+
+        if (STREQ(param, "vga=on"))
+            video->driver->vgaconf = VIR_DOMAIN_VIDEO_VGACONF_ON;
+
+        if (STREQ(param, "vga=io"))
+            video->driver->vgaconf = VIR_DOMAIN_VIDEO_VGACONF_IO;
+
+        if (STREQ(param, "vga=off"))
+            video->driver->vgaconf = VIR_DOMAIN_VIDEO_VGACONF_OFF;
+
+        if (STRPREFIX(param, "rfb=") || STRPREFIX(param, "tcp=")) {
+            /* fortunately, this is the same length as "tcp=" */
+            param += strlen("rfb=");
+
+            if (!(separator = strchr(param, ':')))
+                goto error;
+
+            *separator = '\0';
+
+            if (separator != param)
+                virDomainGraphicsListenAppendAddress(graphics, param);
+            else
+                /* Default to 127.0.0.1, just like bhyve does */
+                virDomainGraphicsListenAppendAddress(graphics, "127.0.0.1");
+
+            param = ++separator;
+            if (virStrToLong_i(param, NULL, 10, &graphics->data.vnc.port))
+                goto error;
+        }
+    }
+
+ cleanup:
+    if (VIR_APPEND_ELEMENT(def->videos, def->nvideos, video) < 0)
+        goto error;
+
+    if (VIR_APPEND_ELEMENT(def->graphics, def->ngraphics, graphics) < 0)
+        goto error;
+
+    g_strfreev(params);
+    return 0;
+
+ error:
+    virDomainVideoDefFree(video);
+    virDomainGraphicsDefFree(graphics);
+    g_strfreev(params);
+    return -1;
+}
+
 static int
 bhyveParseBhyvePCIArg(virDomainDefPtr def,
                       virDomainXMLOptionPtr xmlopt,
@@ -615,6 +702,8 @@ bhyveParseBhyvePCIArg(virDomainDefPtr def,
     else if (STREQ(emulation, "e1000"))
         bhyveParsePCINet(def, xmlopt, caps, bus, slot, function,
                          VIR_DOMAIN_NET_MODEL_E1000, conf);
+    else if (STREQ(emulation, "fbuf"))
+        bhyveParsePCIFbuf(def, xmlopt, caps, bus, slot, function, conf);
 
     VIR_FREE(emulation);
     VIR_FREE(slotdef);
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index bdbe3431b8..96bc7cccb7 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -418,6 +418,7 @@ virDomainGraphicsAuthConnectedTypeFromString;
 virDomainGraphicsAuthConnectedTypeToString;
 virDomainGraphicsDefFree;
 virDomainGraphicsDefHasOpenGL;
+virDomainGraphicsDefNew;
 virDomainGraphicsGetListen;
 virDomainGraphicsGetRenderNode;
 virDomainGraphicsListenAppendAddress;
diff --git a/tests/bhyveargv2xmldata/bhyveargv2xml-vnc-listen.args b/tests/bhyveargv2xmldata/bhyveargv2xml-vnc-listen.args
new file mode 100644
index 0000000000..b97b64a0dc
--- /dev/null
+++ b/tests/bhyveargv2xmldata/bhyveargv2xml-vnc-listen.args
@@ -0,0 +1,10 @@
+/usr/sbin/bhyve \
+-c 1 \
+-m 214 \
+-u \
+-H \
+-P \
+-s 0:0,hostbridge \
+-l bootrom,/path/to/test.fd \
+-s 2:0,fbuf,tcp=1.2.3.4:5900 \
+-s 1,lpc bhyve
diff --git a/tests/bhyveargv2xmldata/bhyveargv2xml-vnc-listen.xml b/tests/bhyveargv2xmldata/bhyveargv2xml-vnc-listen.xml
new file mode 100644
index 0000000000..4ab17aef81
--- /dev/null
+++ b/tests/bhyveargv2xmldata/bhyveargv2xml-vnc-listen.xml
@@ -0,0 +1,22 @@
+<domain type='bhyve'>
+  <name>bhyve</name>
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+  <memory unit='KiB'>219136</memory>
+  <currentMemory unit='KiB'>219136</currentMemory>
+  <vcpu placement='static'>1</vcpu>
+  <os>
+    <type>hvm</type>
+  </os>
+  <clock offset='utc'/>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>destroy</on_reboot>
+  <on_crash>destroy</on_crash>
+  <devices>
+    <graphics type='vnc' port='5900' autoport='no' listen='1.2.3.4'>
+      <listen type='address' address='1.2.3.4'/>
+    </graphics>
+    <video>
+      <model type='default' heads='1'/>
+    </video>
+  </devices>
+</domain>
diff --git a/tests/bhyveargv2xmldata/bhyveargv2xml-vnc-vga-io.args b/tests/bhyveargv2xmldata/bhyveargv2xml-vnc-vga-io.args
new file mode 100644
index 0000000000..f4c0067b79
--- /dev/null
+++ b/tests/bhyveargv2xmldata/bhyveargv2xml-vnc-vga-io.args
@@ -0,0 +1,10 @@
+/usr/sbin/bhyve \
+-c 1 \
+-m 214 \
+-u \
+-H \
+-P \
+-s 0:0,hostbridge \
+-l bootrom,/path/to/test.fd \
+-s 2:0,fbuf,tcp=:5900,vga=io \
+-s 1,lpc bhyve
diff --git a/tests/bhyveargv2xmldata/bhyveargv2xml-vnc-vga-io.xml b/tests/bhyveargv2xmldata/bhyveargv2xml-vnc-vga-io.xml
new file mode 100644
index 0000000000..1e2f3d6938
--- /dev/null
+++ b/tests/bhyveargv2xmldata/bhyveargv2xml-vnc-vga-io.xml
@@ -0,0 +1,22 @@
+<domain type='bhyve'>
+  <name>bhyve</name>
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+  <memory unit='KiB'>219136</memory>
+  <currentMemory unit='KiB'>219136</currentMemory>
+  <vcpu placement='static'>1</vcpu>
+  <os>
+    <type>hvm</type>
+  </os>
+  <clock offset='utc'/>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>destroy</on_reboot>
+  <on_crash>destroy</on_crash>
+  <devices>
+    <graphics type='vnc' port='5900' autoport='no' listen='127.0.0.1'>
+      <listen type='address' address='127.0.0.1'/>
+    </graphics>
+    <video>
+      <model type='default' heads='1'/>
+    </video>
+  </devices>
+</domain>
diff --git a/tests/bhyveargv2xmldata/bhyveargv2xml-vnc-vga-off.args b/tests/bhyveargv2xmldata/bhyveargv2xml-vnc-vga-off.args
new file mode 100644
index 0000000000..4bd5ed1027
--- /dev/null
+++ b/tests/bhyveargv2xmldata/bhyveargv2xml-vnc-vga-off.args
@@ -0,0 +1,10 @@
+/usr/sbin/bhyve \
+-c 1 \
+-m 214 \
+-u \
+-H \
+-P \
+-s 0:0,hostbridge \
+-l bootrom,/path/to/test.fd \
+-s 2:0,fbuf,tcp=:5900,vga=off \
+-s 1,lpc bhyve
diff --git a/tests/bhyveargv2xmldata/bhyveargv2xml-vnc-vga-off.xml b/tests/bhyveargv2xmldata/bhyveargv2xml-vnc-vga-off.xml
new file mode 100644
index 0000000000..3c9c76e5aa
--- /dev/null
+++ b/tests/bhyveargv2xmldata/bhyveargv2xml-vnc-vga-off.xml
@@ -0,0 +1,23 @@
+<domain type='bhyve'>
+  <name>bhyve</name>
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+  <memory unit='KiB'>219136</memory>
+  <currentMemory unit='KiB'>219136</currentMemory>
+  <vcpu placement='static'>1</vcpu>
+  <os>
+    <type>hvm</type>
+  </os>
+  <clock offset='utc'/>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>destroy</on_reboot>
+  <on_crash>destroy</on_crash>
+  <devices>
+    <graphics type='vnc' port='5900' autoport='no' listen='127.0.0.1'>
+      <listen type='address' address='127.0.0.1'/>
+    </graphics>
+    <video>
+      <driver vgaconf='off'/>
+      <model type='default' heads='1'/>
+    </video>
+  </devices>
+</domain>
diff --git a/tests/bhyveargv2xmldata/bhyveargv2xml-vnc-vga-on.args b/tests/bhyveargv2xmldata/bhyveargv2xml-vnc-vga-on.args
new file mode 100644
index 0000000000..d17f347a39
--- /dev/null
+++ b/tests/bhyveargv2xmldata/bhyveargv2xml-vnc-vga-on.args
@@ -0,0 +1,10 @@
+/usr/sbin/bhyve \
+-c 1 \
+-m 214 \
+-u \
+-H \
+-P \
+-s 0:0,hostbridge \
+-l bootrom,/path/to/test.fd \
+-s 2:0,fbuf,tcp=:5900,vga=on \
+-s 1,lpc bhyve
diff --git a/tests/bhyveargv2xmldata/bhyveargv2xml-vnc-vga-on.xml b/tests/bhyveargv2xmldata/bhyveargv2xml-vnc-vga-on.xml
new file mode 100644
index 0000000000..b83772c47a
--- /dev/null
+++ b/tests/bhyveargv2xmldata/bhyveargv2xml-vnc-vga-on.xml
@@ -0,0 +1,23 @@
+<domain type='bhyve'>
+  <name>bhyve</name>
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+  <memory unit='KiB'>219136</memory>
+  <currentMemory unit='KiB'>219136</currentMemory>
+  <vcpu placement='static'>1</vcpu>
+  <os>
+    <type>hvm</type>
+  </os>
+  <clock offset='utc'/>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>destroy</on_reboot>
+  <on_crash>destroy</on_crash>
+  <devices>
+    <graphics type='vnc' port='5900' autoport='no' listen='127.0.0.1'>
+      <listen type='address' address='127.0.0.1'/>
+    </graphics>
+    <video>
+      <driver vgaconf='on'/>
+      <model type='default' heads='1'/>
+    </video>
+  </devices>
+</domain>
diff --git a/tests/bhyveargv2xmldata/bhyveargv2xml-vnc.args b/tests/bhyveargv2xmldata/bhyveargv2xml-vnc.args
new file mode 100644
index 0000000000..fd4178f0a8
--- /dev/null
+++ b/tests/bhyveargv2xmldata/bhyveargv2xml-vnc.args
@@ -0,0 +1,10 @@
+/usr/sbin/bhyve \
+-c 1 \
+-m 214 \
+-u \
+-H \
+-P \
+-s 0:0,hostbridge \
+-l bootrom,/path/to/test.fd \
+-s 2:0,fbuf,tcp=:5900 \
+-s 1,lpc bhyve
diff --git a/tests/bhyveargv2xmldata/bhyveargv2xml-vnc.xml b/tests/bhyveargv2xmldata/bhyveargv2xml-vnc.xml
new file mode 100644
index 0000000000..1e2f3d6938
--- /dev/null
+++ b/tests/bhyveargv2xmldata/bhyveargv2xml-vnc.xml
@@ -0,0 +1,22 @@
+<domain type='bhyve'>
+  <name>bhyve</name>
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+  <memory unit='KiB'>219136</memory>
+  <currentMemory unit='KiB'>219136</currentMemory>
+  <vcpu placement='static'>1</vcpu>
+  <os>
+    <type>hvm</type>
+  </os>
+  <clock offset='utc'/>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>destroy</on_reboot>
+  <on_crash>destroy</on_crash>
+  <devices>
+    <graphics type='vnc' port='5900' autoport='no' listen='127.0.0.1'>
+      <listen type='address' address='127.0.0.1'/>
+    </graphics>
+    <video>
+      <model type='default' heads='1'/>
+    </video>
+  </devices>
+</domain>
diff --git a/tests/bhyveargv2xmltest.c b/tests/bhyveargv2xmltest.c
index 2a497f48e8..0c0383f593 100644
--- a/tests/bhyveargv2xmltest.c
+++ b/tests/bhyveargv2xmltest.c
@@ -181,6 +181,11 @@ mymain(void)
     DO_TEST_FAIL("bhyveload-memsize-fail");
     DO_TEST("bhyveload-bootorder");
     DO_TEST_FAIL("extraargs");
+    DO_TEST("vnc");
+    DO_TEST("vnc-listen");
+    DO_TEST("vnc-vga-on");
+    DO_TEST("vnc-vga-off");
+    DO_TEST("vnc-vga-io");
 
     virObjectUnref(driver.caps);
     virObjectUnref(driver.xmlopt);
-- 
2.27.0




More information about the libvir-list mailing list