]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
bhyve: support parsing fbuf PCI device
authorFabian Freyer <fabian.freyer@physik.tu-berlin.de>
Wed, 6 May 2020 13:35:52 +0000 (13:35 +0000)
committerRoman Bogorodskiy <bogorodskiy@gmail.com>
Tue, 22 Sep 2020 13:19:26 +0000 (17:19 +0400)
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@physik.tu-berlin.de>
Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
13 files changed:
src/bhyve/bhyve_parse_command.c
src/libvirt_private.syms
tests/bhyveargv2xmldata/bhyveargv2xml-vnc-listen.args [new file with mode: 0644]
tests/bhyveargv2xmldata/bhyveargv2xml-vnc-listen.xml [new file with mode: 0644]
tests/bhyveargv2xmldata/bhyveargv2xml-vnc-vga-io.args [new file with mode: 0644]
tests/bhyveargv2xmldata/bhyveargv2xml-vnc-vga-io.xml [new file with mode: 0644]
tests/bhyveargv2xmldata/bhyveargv2xml-vnc-vga-off.args [new file with mode: 0644]
tests/bhyveargv2xmldata/bhyveargv2xml-vnc-vga-off.xml [new file with mode: 0644]
tests/bhyveargv2xmldata/bhyveargv2xml-vnc-vga-on.args [new file with mode: 0644]
tests/bhyveargv2xmldata/bhyveargv2xml-vnc-vga-on.xml [new file with mode: 0644]
tests/bhyveargv2xmldata/bhyveargv2xml-vnc.args [new file with mode: 0644]
tests/bhyveargv2xmldata/bhyveargv2xml-vnc.xml [new file with mode: 0644]
tests/bhyveargv2xmltest.c

index 50a5e884081a52dd11f009dd577cf16345c6c430..604bd6b22ed94ca55f7fee45e0ec6f74dee0d835 100644 (file)
@@ -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;
+    size_t 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);
index bdbe3431b83b6157dcb15a1f11838685dd361d96..96bc7cccb70f1e705b8fc37210246ccdc9fbcf7b 100644 (file)
@@ -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 (file)
index 0000000..b97b64a
--- /dev/null
@@ -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 (file)
index 0000000..4ab17ae
--- /dev/null
@@ -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 (file)
index 0000000..f4c0067
--- /dev/null
@@ -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 (file)
index 0000000..1e2f3d6
--- /dev/null
@@ -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 (file)
index 0000000..4bd5ed1
--- /dev/null
@@ -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 (file)
index 0000000..3c9c76e
--- /dev/null
@@ -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 (file)
index 0000000..d17f347
--- /dev/null
@@ -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 (file)
index 0000000..b83772c
--- /dev/null
@@ -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 (file)
index 0000000..fd4178f
--- /dev/null
@@ -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 (file)
index 0000000..1e2f3d6
--- /dev/null
@@ -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>
index 2a497f48e854d3825e4a9d6c1eb6ca518e2ecf74..0c0383f593af7f13d995546c66f388485b79c6d2 100644 (file)
@@ -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);