bhyve: support parsing fbuf PCI device

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>
This commit is contained in:
Fabian Freyer 2020-05-06 13:35:52 +00:00 committed by Roman Bogorodskiy
parent 54c207a13d
commit cdd31d72ed
13 changed files with 258 additions and 1 deletions

View 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);

View File

@ -418,6 +418,7 @@ virDomainGraphicsAuthConnectedTypeFromString;
virDomainGraphicsAuthConnectedTypeToString;
virDomainGraphicsDefFree;
virDomainGraphicsDefHasOpenGL;
virDomainGraphicsDefNew;
virDomainGraphicsGetListen;
virDomainGraphicsGetRenderNode;
virDomainGraphicsListenAppendAddress;

View File

@ -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

View File

@ -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>

View File

@ -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

View File

@ -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>

View File

@ -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

View File

@ -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>

View File

@ -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

View File

@ -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>

View File

@ -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

View File

@ -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>

View 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);