]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
bhyve: increase number of supported consoles to 4
authorRoman Bogorodskiy <bogorodskiy@gmail.com>
Wed, 18 Jun 2025 17:59:47 +0000 (19:59 +0200)
committerRoman Bogorodskiy <bogorodskiy@gmail.com>
Thu, 17 Jul 2025 17:29:11 +0000 (19:29 +0200)
Recent versions of bhyve support 4 com ports instead of just 2. Thus,
allow to use 4 console devices.

Also, there was a bug previously because the condition was
"if (chr->target.port > 2)", but as target.port start
with 0 and "com" ports start with 1, this condition allows com3 to be
used.

As bhyve supports 4 com ports already long enough, and all supported
FreeBSD versions include this capability, do not introduce driver
capability for that.

Add a couple of tests for that:

 - A domain that uses 4 serials, 2 of type 'nmdm'
   and the other 2 of type 'tcp'
 - A domain that uses unsupported port, such as target.port=4 which
   translates into com5.

Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
12 files changed:
src/bhyve/bhyve_command.c
tests/bhyvexml2argvdata/bhyvexml2argv-4-consoles.args [new file with mode: 0644]
tests/bhyvexml2argvdata/bhyvexml2argv-4-consoles.ldargs [new file with mode: 0644]
tests/bhyvexml2argvdata/bhyvexml2argv-4-consoles.xml [new file with mode: 0644]
tests/bhyvexml2argvdata/bhyvexml2argv-serial-invalid-port.args [new file with mode: 0644]
tests/bhyvexml2argvdata/bhyvexml2argv-serial-invalid-port.ldargs [new file with mode: 0644]
tests/bhyvexml2argvdata/bhyvexml2argv-serial-invalid-port.xml [new file with mode: 0644]
tests/bhyvexml2argvdata/bhyvexml2argv-serial-tcp.xml
tests/bhyvexml2argvtest.c
tests/bhyvexml2xmloutdata/bhyvexml2xmlout-4-consoles.xml [new file with mode: 0644]
tests/bhyvexml2xmloutdata/bhyvexml2xmlout-serial-tcp.xml
tests/bhyvexml2xmltest.c

index 89648f76cb21ee62615ef80d807580c02ff8801d..18f65cf7577a428882300ddbef718c5aa63fd608 100644 (file)
@@ -168,8 +168,8 @@ bhyveBuildConsoleArgStr(const virDomainDef *def, virCommand *cmd)
     for (i = 0; i < def->nserials; i++) {
         chr = def->serials[i];
 
-        /* bhyve supports only two ports: com1 and com2 */
-        if (chr->target.port > 2) {
+        /* bhyve supports 4 ports: com1, com2, com3, com4 */
+        if (chr->target.port > 3) {
             virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                            _("only two serial ports are supported"));
             return -1;
diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-4-consoles.args b/tests/bhyvexml2argvdata/bhyvexml2argv-4-consoles.args
new file mode 100644 (file)
index 0000000..16c7bd7
--- /dev/null
@@ -0,0 +1,15 @@
+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,/dev/nmdmdf3be7e7-a104-11e3-aeb0-50e5492bd3dcA \
+-l com2,tcp=127.0.0.1:12345 \
+-l com3,tcp=0.0.0.0:54321 \
+-l com4,/dev/nmdm0A \
+bhyve
diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-4-consoles.ldargs b/tests/bhyvexml2argvdata/bhyvexml2argv-4-consoles.ldargs
new file mode 100644 (file)
index 0000000..5905f4b
--- /dev/null
@@ -0,0 +1,4 @@
+bhyveload \
+-m 214 \
+-d /tmp/freebsd.img \
+bhyve
diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-4-consoles.xml b/tests/bhyvexml2argvdata/bhyvexml2argv-4-consoles.xml
new file mode 100644 (file)
index 0000000..c32680a
--- /dev/null
@@ -0,0 +1,35 @@
+<domain type='bhyve'>
+  <name>bhyve</name>
+  <uuid>df3be7e7-a104-11e3-aeb0-50e5492bd3dc</uuid>
+  <memory>219136</memory>
+  <vcpu>1</vcpu>
+  <os>
+    <type>hvm</type>
+  </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'>
+      <mac address='52:54:00:b1:42:eb'/>
+      <model type='virtio'/>
+      <source bridge="virbr0"/>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
+    </interface>
+    <serial type='nmdm'/>
+    <serial type='tcp'>
+      <source mode='bind' host='127.0.0.1' service='12345'/>
+      <protocol type="raw"/>
+    </serial>
+    <serial type='tcp'>
+      <source mode='bind' host='0.0.0.0' service='54321'/>
+      <protocol type="raw"/>
+    </serial>
+    <serial type='nmdm'>
+      <source master="/dev/nmdm0A" slave="/dev/nmdm0B"/>
+    </serial>
+  </devices>
+</domain>
diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-serial-invalid-port.args b/tests/bhyvexml2argvdata/bhyvexml2argv-serial-invalid-port.args
new file mode 100644 (file)
index 0000000..8e4072d
--- /dev/null
@@ -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-invalid-port.ldargs b/tests/bhyvexml2argvdata/bhyvexml2argv-serial-invalid-port.ldargs
new file mode 100644 (file)
index 0000000..5905f4b
--- /dev/null
@@ -0,0 +1,4 @@
+bhyveload \
+-m 214 \
+-d /tmp/freebsd.img \
+bhyve
diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-serial-invalid-port.xml b/tests/bhyvexml2argvdata/bhyvexml2argv-serial-invalid-port.xml
new file mode 100644 (file)
index 0000000..36ecd1a
--- /dev/null
@@ -0,0 +1,28 @@
+<domain type='bhyve'>
+  <name>bhyve</name>
+  <uuid>df3be7e7-a104-11e3-aeb0-50e5492bd3dc</uuid>
+  <memory>219136</memory>
+  <vcpu>1</vcpu>
+  <os>
+    <type>hvm</type>
+  </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'>
+      <mac address='52:54:00:b1:42:eb'/>
+      <model type='virtio'/>
+      <source bridge="virbr0"/>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
+    </interface>
+    <serial type='tcp'>
+      <source mode='connect' host='127.0.0.1' service='12345'/>
+      <protocol type="raw"/>
+      <target port="4"/>
+    </serial>
+  </devices>
+</domain>
index 61c9440e44672b6aa21db7a566c34792533d93bb..a52b507ddab87760736d2fde1d7038a64996dcf6 100644 (file)
@@ -20,7 +20,7 @@
       <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
     </interface>
     <serial type='tcp'>
-      <source mode='connect' host='127.0.0.1' service='12345'/>
+      <source mode='bind' host='127.0.0.1' service='12345'/>
       <protocol type="raw"/>
     </serial>
   </devices>
index d1786ff1659859c0f4e4d056ab654b95e7b34dcf..2838b20c293351de0b4b789517d0d6131e2f3e5f 100644 (file)
@@ -255,6 +255,8 @@ mymain(void)
     driver.bhyvecaps &= ~BHYVE_CAP_VIRTIO_RND;
     DO_TEST_FAILURE("virtio-rnd");
     DO_TEST("serial-tcp");
+    DO_TEST("4-consoles");
+    DO_TEST_FAILURE("serial-invalid-port");
 
     /* Address allocation tests */
     DO_TEST("addr-single-sata-disk");
diff --git a/tests/bhyvexml2xmloutdata/bhyvexml2xmlout-4-consoles.xml b/tests/bhyvexml2xmloutdata/bhyvexml2xmlout-4-consoles.xml
new file mode 100644 (file)
index 0000000..fba7d37
--- /dev/null
@@ -0,0 +1,58 @@
+<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>
+    <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='isa' index='0'>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x0'/>
+    </controller>
+    <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:b1:42:eb'/>
+      <source bridge='virbr0'/>
+      <model type='virtio'/>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
+    </interface>
+    <serial type='nmdm'>
+      <source master='/dev/nmdmdf3be7e7-a104-11e3-aeb0-50e5492bd3dcA' slave='/dev/nmdmdf3be7e7-a104-11e3-aeb0-50e5492bd3dcB'/>
+      <target port='0'/>
+    </serial>
+    <serial type='tcp'>
+      <source mode='bind' host='127.0.0.1' service='12345'/>
+      <protocol type='raw'/>
+      <target port='1'/>
+    </serial>
+    <serial type='tcp'>
+      <source mode='bind' host='0.0.0.0' service='54321'/>
+      <protocol type='raw'/>
+      <target port='2'/>
+    </serial>
+    <serial type='nmdm'>
+      <source master='/dev/nmdm0A' slave='/dev/nmdm0B'/>
+      <target port='3'/>
+    </serial>
+    <console type='nmdm'>
+      <source master='/dev/nmdmdf3be7e7-a104-11e3-aeb0-50e5492bd3dcA' slave='/dev/nmdmdf3be7e7-a104-11e3-aeb0-50e5492bd3dcB'/>
+      <target type='serial' port='0'/>
+    </console>
+  </devices>
+</domain>
index 641efcd6021ed6918de50f7b288e049f943cf953..529f1e8f0264e2b3d72720eda41ad4bc65186910 100644 (file)
       <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
     </interface>
     <serial type='tcp'>
-      <source mode='connect' host='127.0.0.1' service='12345'/>
+      <source mode='bind' host='127.0.0.1' service='12345'/>
       <protocol type='raw'/>
       <target port='0'/>
     </serial>
     <console type='tcp'>
-      <source mode='connect' host='127.0.0.1' service='12345'/>
+      <source mode='bind' host='127.0.0.1' service='12345'/>
       <protocol type='raw'/>
       <target type='serial' port='0'/>
     </console>
index 0b858731a67b4dd5fc48ef621d936f53e7e441d0..df093a553982be299946db827e22f204b0925278 100644 (file)
@@ -116,6 +116,7 @@ mymain(void)
     DO_TEST_DIFFERENT("fs-9p");
     DO_TEST_DIFFERENT("virtio-rnd");
     DO_TEST_DIFFERENT("serial-tcp");
+    DO_TEST_DIFFERENT("4-consoles");
 
     /* Address allocation tests */
     DO_TEST_DIFFERENT("addr-single-sata-disk");