This patch adds support for automatic VNC port assignment for bhyve guests.
Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
}
static int
-bhyveBuildGraphicsArgStr(const virDomainDef *def ATTRIBUTE_UNUSED,
+bhyveBuildGraphicsArgStr(const virDomainDef *def,
virDomainGraphicsDefPtr graphics,
virDomainVideoDefPtr video,
virConnectPtr conn,
- virCommandPtr cmd)
+ virCommandPtr cmd,
+ bool dryRun)
{
virBuffer opt = VIR_BUFFER_INITIALIZER;
virDomainGraphicsListenDefPtr glisten = NULL;
bool escapeAddr;
+ unsigned short port;
+
+ bhyveConnPtr driver = conn->privateData;
if (!(bhyveDriverGetCaps(conn) & BHYVE_CAP_LPC_BOOTROM) ||
def->os.bootloader ||
virBufferAdd(&opt, glisten->address, -1);
}
+ if (!dryRun) {
+ if (graphics->data.vnc.autoport) {
+ if (virPortAllocatorAcquire(driver->remotePorts, &port) < 0)
+ return -1;
+ graphics->data.vnc.port = port;
+ } else {
+ if (virPortAllocatorSetUsed(driver->remotePorts,
+ graphics->data.vnc.port,
+ true) < 0)
+ VIR_WARN("Failed to mark VNC port '%d' as used by '%s'",
+ graphics->data.vnc.port, def->name);
+ }
+ }
+
virBufferAsprintf(&opt, ":%d", graphics->data.vnc.port);
break;
default:
if (def->ngraphics && def->nvideos) {
if (def->ngraphics == 1 && def->nvideos == 1) {
- if (bhyveBuildGraphicsArgStr(def, def->graphics[0], def->videos[0], conn, cmd) < 0)
+ if (bhyveBuildGraphicsArgStr(def, def->graphics[0], def->videos[0],
+ conn, cmd, dryRun) < 0)
goto error;
add_lpc = true;
} else {
#include "viraccessapicheck.h"
#include "virhostcpu.h"
#include "virhostmem.h"
+#include "virportallocator.h"
#include "conf/domain_capabilities.h"
#include "bhyve_conf.h"
virObjectUnref(bhyve_driver->closeCallbacks);
virObjectUnref(bhyve_driver->domainEventState);
virObjectUnref(bhyve_driver->config);
+ virObjectUnref(bhyve_driver->remotePorts);
virMutexDestroy(&bhyve_driver->lock);
VIR_FREE(bhyve_driver);
if (!(bhyve_driver->domainEventState = virObjectEventStateNew()))
goto cleanup;
+ if (!(bhyve_driver->remotePorts = virPortAllocatorNew(_("display"), 5900, 65535, 0)))
+ goto cleanup;
+
bhyve_driver->hostsysinfo = virSysinfoRead();
if (!(bhyve_driver->config = virBhyveDriverConfigNew()))
/* Cleanup network interfaces */
bhyveNetCleanup(vm);
+ /* VNC autoport cleanup */
+ if ((vm->def->ngraphics == 1) &&
+ vm->def->graphics[0]->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC) {
+ if (virPortAllocatorRelease(driver->remotePorts,
+ vm->def->graphics[0]->data.vnc.port) < 0) {
+ VIR_WARN("Failed to release VNC port for '%s'",
+ vm->def->name);
+ }
+ }
+
ret = 0;
virCloseCallbacksUnset(driver->closeCallbacks, vm,
if (STREQ(expected_proctitle, proc_argv[0])) {
ret = 0;
priv->mon = bhyveMonitorOpen(vm, data->driver);
+ if (vm->def->ngraphics == 1 &&
+ vm->def->graphics[0]->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC) {
+ int vnc_port = vm->def->graphics[0]->data.vnc.port;
+ if (virPortAllocatorSetUsed(data->driver->remotePorts,
+ vnc_port,
+ true) < 0) {
+ VIR_WARN("Failed to mark VNC port '%d' as used by '%s'",
+ vnc_port, vm->def->name);
+ }
+ }
}
}
# include "virdomainobjlist.h"
# include "virthread.h"
# include "virclosecallbacks.h"
+# include "virportallocator.h"
# define BHYVE_AUTOSTART_DIR SYSCONFDIR "/libvirt/bhyve/autostart"
# define BHYVE_CONFIG_DIR SYSCONFDIR "/libvirt/bhyve"
virCloseCallbacksPtr closeCallbacks;
+ virPortAllocatorPtr remotePorts;
+
unsigned bhyvecaps;
unsigned grubcaps;
};
--- /dev/null
+/usr/sbin/bhyve \
+-c 1 \
+-m 214 \
+-u \
+-H \
+-P \
+-s 0:0,hostbridge \
+-l bootrom,/path/to/test.fd \
+-s 2:0,ahci,hd:/tmp/freebsd.img \
+-s 3:0,virtio-net,faketapdev,mac=52:54:00:00:00:00 \
+-s 4:0,fbuf,tcp=127.0.0.1:5900 \
+-s 1,lpc bhyve
--- /dev/null
+<domain type='bhyve'>
+ <name>bhyve</name>
+ <uuid>df3be7e7-a104-11e3-aeb0-50e5492bd3dc</uuid>
+ <memory>219136</memory>
+ <vcpu>1</vcpu>
+ <os>
+ <type>hvm</type>
+ <loader readonly="yes" type="pflash">/path/to/test.fd</loader>
+ </os>
+ <devices>
+ <disk type='file'>
+ <driver name='file' type='raw'/>
+ <source file='/tmp/freebsd.img'/>
+ <target dev='hda' bus='sata'/>
+ <address type='drive' controller='0' bus='0' target='2' unit='0'/>
+ </disk>
+ <interface type='bridge'>
+ <model type='virtio'/>
+ <source bridge="virbr0"/>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
+ </interface>
+ <graphics type='vnc' port='-1' autoport='yes'>
+ <listen type='address' address='127.0.0.1'/>
+ </graphics>
+ </devices>
+</domain>
if ((driver.xmlopt = virBhyveDriverCreateXMLConf(&driver)) == NULL)
return EXIT_FAILURE;
+ if (!(driver.remotePorts = virPortAllocatorNew("display", 5900, 65535,
+ VIR_PORT_ALLOCATOR_SKIP_BIND_CHECK)))
+ return EXIT_FAILURE;
+
+
# define DO_TEST_FULL(name, flags) \
do { \
static struct testInfo info = { \
DO_TEST("vnc-vgaconf-on");
DO_TEST("vnc-vgaconf-off");
DO_TEST("vnc-vgaconf-io");
+ DO_TEST("vnc-autoport");
/* Address allocation tests */
DO_TEST("addr-single-sata-disk");
virObjectUnref(driver.caps);
virObjectUnref(driver.xmlopt);
+ virObjectUnref(driver.remotePorts);
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
}
--- /dev/null
+<domain type='bhyve'>
+ <name>bhyve</name>
+ <uuid>df3be7e7-a104-11e3-aeb0-50e5492bd3dc</uuid>
+ <memory unit='KiB'>219136</memory>
+ <currentMemory unit='KiB'>219136</currentMemory>
+ <vcpu placement='static'>1</vcpu>
+ <os>
+ <type arch='x86_64'>hvm</type>
+ <loader readonly='yes' type='pflash'>/path/to/test.fd</loader>
+ <boot dev='hd'/>
+ </os>
+ <clock offset='utc'/>
+ <on_poweroff>destroy</on_poweroff>
+ <on_reboot>restart</on_reboot>
+ <on_crash>destroy</on_crash>
+ <devices>
+ <disk type='file' device='disk'>
+ <driver name='file' type='raw'/>
+ <source file='/tmp/freebsd.img'/>
+ <target dev='hda' bus='sata'/>
+ <address type='drive' controller='0' bus='0' target='2' unit='0'/>
+ </disk>
+ <controller type='pci' index='0' model='pci-root'/>
+ <controller type='sata' index='0'>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
+ </controller>
+ <interface type='bridge'>
+ <mac address='52:54:00:00:00:00'/>
+ <source bridge='virbr0'/>
+ <model type='virtio'/>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
+ </interface>
+ <graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1'>
+ <listen type='address' address='127.0.0.1'/>
+ </graphics>
+ <video>
+ <model type='gop' heads='1' primary='yes'/>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
+ </video>
+ </devices>
+</domain>
DO_TEST_DIFFERENT("vnc-vgaconf-on");
DO_TEST_DIFFERENT("vnc-vgaconf-off");
DO_TEST_DIFFERENT("vnc-vgaconf-io");
+ DO_TEST_DIFFERENT("vnc-autoport");
/* Address allocation tests */
DO_TEST_DIFFERENT("addr-single-sata-disk");