Console device handling in bhyve is different for amd64 and arm64.
On amd64, it's configured as an LPC device, and multiple consoles are
supported.

On arm64, only a single console can be configured, and the syntax is
different:

 -o console=/dev/nmdmguest0A

Update the bhyve command generation accordingly.

Signed-off-by: Roman Bogorodskiy <[email protected]>
---
 src/bhyve/bhyve_command.c                     | 59 ++++++++++++-------
 .../aarch64/bhyvexml2argv-console.args        | 11 ++++
 .../aarch64/bhyvexml2argv-console.ldargs      |  7 +++
 .../aarch64/bhyvexml2argv-console.xml         | 26 ++++++++
 tests/bhyvexml2argvtest.c                     |  1 +
 5 files changed, 84 insertions(+), 20 deletions(-)
 create mode 100644 tests/bhyvexml2argvdata/aarch64/bhyvexml2argv-console.args
 create mode 100644 tests/bhyvexml2argvdata/aarch64/bhyvexml2argv-console.ldargs
 create mode 100644 tests/bhyvexml2argvdata/aarch64/bhyvexml2argv-console.xml

diff --git a/src/bhyve/bhyve_command.c b/src/bhyve/bhyve_command.c
index bc37f4cef9..e6dddfcf97 100644
--- a/src/bhyve/bhyve_command.c
+++ b/src/bhyve/bhyve_command.c
@@ -172,34 +172,53 @@ bhyveBuildConsoleArgStr(const virDomainDef *def, 
virCommand *cmd)
     if (!def->nserials)
         return 0;
 
-    for (i = 0; i < def->nserials; i++) {
-        chr = def->serials[i];
+    if (ARCH_IS_X86(def->os.arch)) {
+        for (i = 0; i < def->nserials; i++) {
+            chr = def->serials[i];
 
-        /* bhyve supports 4 ports: com1, com2, com3, com4 */
-        if (chr->target.port > 3) {
+            /* bhyve supports 4 ports: com1, com2, com3, com4 */
+            if (chr->target.port > 3) {
+                virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                               _("Only four serial ports are supported"));
+                return -1;
+            }
+
+            virCommandAddArg(cmd, "-l");
+
+            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;
+            }
+        }
+    } else if (ARCH_IS_ARM(def->os.arch)) {
+        if (def->nserials > 1) {
             virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                           _("Only four serial ports are supported"));
+                           _("Only one console is supported on arm64"));
             return -1;
         }
 
-        virCommandAddArg(cmd, "-l");
-
-        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:
+        chr = def->serials[0];
+        if (chr->source->type != VIR_DOMAIN_CHR_TYPE_NMDM) {
             virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                           _("Only 'nmdm' and 'tcp' console types are 
supported"));
+                           _("Only 'nmdm' console type is supported on 
arm64"));
             return -1;
         }
+
+        virCommandAddArg(cmd, "-o");
+        virCommandAddArgFormat(cmd, "console=%s",
+                               chr->source->data.file.path);
     }
 
     return 0;
diff --git a/tests/bhyvexml2argvdata/aarch64/bhyvexml2argv-console.args 
b/tests/bhyvexml2argvdata/aarch64/bhyvexml2argv-console.args
new file mode 100644
index 0000000000..73d0005faf
--- /dev/null
+++ b/tests/bhyvexml2argvdata/aarch64/bhyvexml2argv-console.args
@@ -0,0 +1,11 @@
+bhyve \
+-c 1 \
+-m 214 \
+-u \
+-H \
+-P \
+-s 0:0,hostbridge \
+-s 3:0,virtio-net,faketapdev,mac=52:54:00:b9:94:02 \
+-s 2:0,virtio-blk,/tmp/freebsd.img \
+-o console=/dev/nmdm0A \
+bhyve
diff --git a/tests/bhyvexml2argvdata/aarch64/bhyvexml2argv-console.ldargs 
b/tests/bhyvexml2argvdata/aarch64/bhyvexml2argv-console.ldargs
new file mode 100644
index 0000000000..264ae48441
--- /dev/null
+++ b/tests/bhyvexml2argvdata/aarch64/bhyvexml2argv-console.ldargs
@@ -0,0 +1,7 @@
+timeout \
+--foreground \
+--verbose \
+-k 20s 300s bhyveload \
+-m 214 \
+-d /tmp/freebsd.img \
+bhyve
diff --git a/tests/bhyvexml2argvdata/aarch64/bhyvexml2argv-console.xml 
b/tests/bhyvexml2argvdata/aarch64/bhyvexml2argv-console.xml
new file mode 100644
index 0000000000..dd599b5133
--- /dev/null
+++ b/tests/bhyvexml2argvdata/aarch64/bhyvexml2argv-console.xml
@@ -0,0 +1,26 @@
+<domain type='bhyve'>
+  <name>bhyve</name>
+  <uuid>df3be7e7-a104-11e3-aeb0-50e5492bd3dc</uuid>
+  <memory>219136</memory>
+  <vcpu>1</vcpu>
+  <os>
+    <type arch='aarch64'>hvm</type>
+  </os>
+  <devices>
+    <disk type='file'>
+      <driver name='file' type='raw'/>
+      <source file='/tmp/freebsd.img'/>
+      <target dev='vda' bus='virtio'/>
+      <address type='drive' controller='0' bus='0' target='2' unit='0'/>
+    </disk>
+    <interface type='bridge'>
+      <mac address='52:54:00:b9:94:02'/>
+      <model type='virtio'/>
+      <source bridge="virbr0"/>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' 
function='0x0'/>
+    </interface>
+    <console type='nmdm'>
+      <source master='/dev/nmdm0A' slave='/dev/nmdm0B'/>
+    </console>
+  </devices>
+</domain>
diff --git a/tests/bhyvexml2argvtest.c b/tests/bhyvexml2argvtest.c
index e420fde1e9..564f3fb433 100644
--- a/tests/bhyvexml2argvtest.c
+++ b/tests/bhyvexml2argvtest.c
@@ -334,6 +334,7 @@ mymain(void)
     driver.caps = virBhyveCapsBuild();
 
     DO_TEST("base");
+    DO_TEST("console");
 
     virObjectUnref(driver.caps);
     virObjectUnref(driver.xmlopt);
-- 
2.51.2

Reply via email to