From: Roman Bogorodskiy Date: Wed, 18 Jun 2025 17:07:49 +0000 (+0200) Subject: bhyve: support serial type 'tcp' X-Git-Tag: v11.6.0-rc1~100 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8b7db74d4a166c9cfbd97918f660096a0f8f38cf;p=thirdparty%2Flibvirt.git bhyve: support serial type 'tcp' In addition to the nmdm consoles, bhyve also supports a tcp console. It's configured with: .. -l com1,tcp=127.0.0.1:12345 Then a user could connect to the guest console port 0 by making a tcp connection to the host's 127.0.0.1:12345. In the domain XML this configuration is represented as: Also, update domain capabilities to include the TCP console support. Unfortunately, there's no way to detect that from the bhyve binary before trying to start a VM, so there's no capability probing for this feature. Signed-off-by: Roman Bogorodskiy Reviewed-by: Daniel P. Berrangé --- diff --git a/src/bhyve/bhyve_capabilities.c b/src/bhyve/bhyve_capabilities.c index 59fc81d26c..04a5a4cf29 100644 --- a/src/bhyve/bhyve_capabilities.c +++ b/src/bhyve/bhyve_capabilities.c @@ -128,7 +128,8 @@ virBhyveDomainCapsFill(virDomainCaps *caps, caps->console.supported = VIR_TRISTATE_BOOL_YES; caps->console.type.report = true; VIR_DOMAIN_CAPS_ENUM_SET(caps->console.type, - VIR_DOMAIN_CHR_TYPE_NMDM); + VIR_DOMAIN_CHR_TYPE_NMDM, + VIR_DOMAIN_CHR_TYPE_TCP); return 0; } diff --git a/src/bhyve/bhyve_command.c b/src/bhyve/bhyve_command.c index c82a07c2eb..89648f76cb 100644 --- a/src/bhyve/bhyve_command.c +++ b/src/bhyve/bhyve_command.c @@ -159,29 +159,41 @@ bhyveBuildNetArgStr(const virDomainDef *def, static int bhyveBuildConsoleArgStr(const virDomainDef *def, virCommand *cmd) { + size_t i = 0; virDomainChrDef *chr = NULL; if (!def->nserials) return 0; - chr = def->serials[0]; + for (i = 0; i < def->nserials; i++) { + chr = def->serials[i]; - if (chr->source->type != VIR_DOMAIN_CHR_TYPE_NMDM) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("only nmdm console types are supported")); - return -1; - } + /* bhyve supports only two ports: com1 and com2 */ + if (chr->target.port > 2) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("only two serial ports are supported")); + return -1; + } - /* bhyve supports only two ports: com1 and com2 */ - if (chr->target.port > 2) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("only two serial ports are supported")); - return -1; - } + virCommandAddArg(cmd, "-l"); - virCommandAddArg(cmd, "-l"); - virCommandAddArgFormat(cmd, "com%d,%s", - chr->target.port + 1, chr->source->data.file.path); + switch (chr->source->type) { + case VIR_DOMAIN_CHR_TYPE_NMDM: + virCommandAddArgFormat(cmd, "com%d,%s", + chr->target.port + 1, chr->source->data.file.path); + break; + case VIR_DOMAIN_CHR_TYPE_TCP: + virCommandAddArgFormat(cmd, "com%d,tcp=%s:%s", + chr->target.port + 1, + chr->source->data.tcp.host, + chr->source->data.tcp.service); + break; + default: + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("only nmdm and tcp console types are supported")); + return -1; + } + } return 0; } diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-serial-tcp.args b/tests/bhyvexml2argvdata/bhyvexml2argv-serial-tcp.args new file mode 100644 index 0000000000..8e4072d897 --- /dev/null +++ b/tests/bhyvexml2argvdata/bhyvexml2argv-serial-tcp.args @@ -0,0 +1,12 @@ +bhyve \ +-c 1 \ +-m 214 \ +-u \ +-H \ +-P \ +-s 0:0,hostbridge \ +-s 1:0,lpc \ +-s 2:0,ahci,hd:/tmp/freebsd.img \ +-s 3:0,virtio-net,faketapdev,mac=52:54:00:b1:42:eb \ +-l com1,tcp=127.0.0.1:12345 \ +bhyve diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-serial-tcp.ldargs b/tests/bhyvexml2argvdata/bhyvexml2argv-serial-tcp.ldargs new file mode 100644 index 0000000000..5905f4b3e6 --- /dev/null +++ b/tests/bhyvexml2argvdata/bhyvexml2argv-serial-tcp.ldargs @@ -0,0 +1,4 @@ +bhyveload \ +-m 214 \ +-d /tmp/freebsd.img \ +bhyve diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-serial-tcp.xml b/tests/bhyvexml2argvdata/bhyvexml2argv-serial-tcp.xml new file mode 100644 index 0000000000..61c9440e44 --- /dev/null +++ b/tests/bhyvexml2argvdata/bhyvexml2argv-serial-tcp.xml @@ -0,0 +1,27 @@ + + bhyve + df3be7e7-a104-11e3-aeb0-50e5492bd3dc + 219136 + 1 + + hvm + + + + + + +
+ + + + + +
+ + + + + + + diff --git a/tests/bhyvexml2argvtest.c b/tests/bhyvexml2argvtest.c index 58b404ca7d..d1786ff165 100644 --- a/tests/bhyvexml2argvtest.c +++ b/tests/bhyvexml2argvtest.c @@ -254,6 +254,7 @@ mymain(void) DO_TEST_FAILURE("virtio-rnd-transitional"); driver.bhyvecaps &= ~BHYVE_CAP_VIRTIO_RND; DO_TEST_FAILURE("virtio-rnd"); + DO_TEST("serial-tcp"); /* Address allocation tests */ DO_TEST("addr-single-sata-disk"); diff --git a/tests/bhyvexml2xmloutdata/bhyvexml2xmlout-serial-tcp.xml b/tests/bhyvexml2xmloutdata/bhyvexml2xmlout-serial-tcp.xml new file mode 100644 index 0000000000..641efcd602 --- /dev/null +++ b/tests/bhyvexml2xmloutdata/bhyvexml2xmlout-serial-tcp.xml @@ -0,0 +1,46 @@ + + bhyve + df3be7e7-a104-11e3-aeb0-50e5492bd3dc + 219136 + 219136 + 1 + + hvm + + + + destroy + restart + destroy + + + + + +
+ + + +
+ + +
+ + + + + +
+ + + + + + + + + + + + + diff --git a/tests/bhyvexml2xmltest.c b/tests/bhyvexml2xmltest.c index 98006dac04..0b858731a6 100644 --- a/tests/bhyvexml2xmltest.c +++ b/tests/bhyvexml2xmltest.c @@ -115,6 +115,7 @@ mymain(void) DO_TEST_DIFFERENT("isa-controller"); DO_TEST_DIFFERENT("fs-9p"); DO_TEST_DIFFERENT("virtio-rnd"); + DO_TEST_DIFFERENT("serial-tcp"); /* Address allocation tests */ DO_TEST_DIFFERENT("addr-single-sata-disk"); diff --git a/tests/domaincapsdata/bhyve_basic.x86_64.xml b/tests/domaincapsdata/bhyve_basic.x86_64.xml index d1211a5b5e..0c386c79d2 100644 --- a/tests/domaincapsdata/bhyve_basic.x86_64.xml +++ b/tests/domaincapsdata/bhyve_basic.x86_64.xml @@ -29,6 +29,7 @@ + tcp nmdm diff --git a/tests/domaincapsdata/bhyve_fbuf.x86_64.xml b/tests/domaincapsdata/bhyve_fbuf.x86_64.xml index 8d5e42dd82..2936281857 100644 --- a/tests/domaincapsdata/bhyve_fbuf.x86_64.xml +++ b/tests/domaincapsdata/bhyve_fbuf.x86_64.xml @@ -46,6 +46,7 @@ + tcp nmdm diff --git a/tests/domaincapsdata/bhyve_uefi.x86_64.xml b/tests/domaincapsdata/bhyve_uefi.x86_64.xml index 3a6f178dd4..fa87fd3640 100644 --- a/tests/domaincapsdata/bhyve_uefi.x86_64.xml +++ b/tests/domaincapsdata/bhyve_uefi.x86_64.xml @@ -38,6 +38,7 @@ + tcp nmdm