]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
ch_monitor: Add pty json builder function
authorWilliam Douglas <william.douglas@intel.com>
Wed, 8 Sep 2021 18:01:19 +0000 (11:01 -0700)
committerDaniel P. Berrangé <berrange@redhat.com>
Thu, 9 Sep 2021 13:51:02 +0000 (14:51 +0100)
Add function to build the the json structure to configure a PTY in
cloud-hypervisor.

The devices themselves still aren't allowed in configurations yet
though.

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: William Douglas <william.douglas@intel.com>
src/ch/ch_monitor.c

index fe29af03e67845cd96c6664dc0d4321351af9a79..4ed7cbfee7c5c00f87f0c2fc9c0aadcef7cbfe44 100644 (file)
@@ -89,6 +89,30 @@ virCHMonitorBuildCPUJson(virJSONValue *content, virDomainDef *vmdef)
     return -1;
 }
 
+static int
+virCHMonitorBuildPTYJson(virJSONValue *content, virDomainDef *vmdef)
+{
+    virJSONValue *ptys = virJSONValueNewObject();
+
+    if (vmdef->nconsoles) {
+        g_autoptr(virJSONValue) pty = virJSONValueNewObject();
+        if (virJSONValueObjectAppendString(pty, "mode", "Pty") < 0)
+            return -1;
+        if (virJSONValueObjectAppend(content, "console", &pty) < 0)
+            return -1;
+    }
+
+    if (vmdef->nserials) {
+        g_autoptr(virJSONValue) pty = virJSONValueNewObject();
+        if (virJSONValueObjectAppendString(ptys, "mode", "Pty") < 0)
+            return -1;
+        if (virJSONValueObjectAppend(content, "serial", &pty) < 0)
+            return -1;
+    }
+
+    return 0;
+}
+
 static int
 virCHMonitorBuildKernelRelatedJson(virJSONValue *content, virDomainDef *vmdef)
 {
@@ -370,6 +394,9 @@ virCHMonitorBuildVMJson(virDomainDef *vmdef, char **jsonstr)
         goto cleanup;
     }
 
+    if (virCHMonitorBuildPTYJson(content, vmdef) < 0)
+        goto cleanup;
+
     if (virCHMonitorBuildCPUJson(content, vmdef) < 0)
         goto cleanup;