[libvirt] [PATCH 3/4] chardev: Add function to output -chardev options

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Note that, on its own, this patch will generate a warning about an unused static
function.
---
 src/qemu/qemu_conf.c |   87 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 87 insertions(+), 0 deletions(-)

diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index e5d19ef..3e37c66 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -1386,6 +1386,93 @@ qemuBuildHostNetStr(virConnectPtr conn,
     return 0;
 }
 
+/* This function outputs a -chardev command line option which describes only the
+ * host side of the character device */
+static int qemudBuildCommandLineChrDevChardevStr(virDomainChrDefPtr dev,
+                                                 const char *const id,
+                                                 char *buf,
+                                                 int buflen)
+{
+    switch(dev->type) {
+    case VIR_DOMAIN_CHR_TYPE_NULL:
+        if (snprintf(buf, buflen, "null,id=%s", id) >= buflen)
+            return -1;
+        break;
+
+    case VIR_DOMAIN_CHR_TYPE_VC:
+        if (snprintf(buf, buflen, "vc,id=%s", id) >= buflen)
+            return -1;
+        break;
+
+    case VIR_DOMAIN_CHR_TYPE_PTY:
+        if (snprintf(buf, buflen, "pty,id=%s", id) >= buflen)
+            return -1;
+        break;
+
+    case VIR_DOMAIN_CHR_TYPE_DEV:
+        if (snprintf(buf, buflen, "tty,id=%s,path=%s",
+                     id, dev->data.file.path) >= buflen)
+            return -1;
+        break;
+
+    case VIR_DOMAIN_CHR_TYPE_FILE:
+        if (snprintf(buf, buflen, "file,id=%s,path=%s",
+                     id, dev->data.file.path) >= buflen)
+            return -1;
+        break;
+
+    case VIR_DOMAIN_CHR_TYPE_PIPE:
+        if (snprintf(buf, buflen, "pipe,id=%s,path=%s",
+                     id, dev->data.file.path) >= buflen)
+            return -1;
+        break;
+
+    case VIR_DOMAIN_CHR_TYPE_STDIO:
+        if (snprintf(buf, buflen, "stdio,id=%s", id) >= buflen)
+            return -1;
+        break;
+
+    case VIR_DOMAIN_CHR_TYPE_UDP:
+        if (snprintf(buf, buflen,
+                    "udp,id=%s,host=%s,port=%s,localaddr=%s,localport=%s",
+                     id,
+                     dev->data.udp.connectHost,
+                     dev->data.udp.connectService,
+                     dev->data.udp.bindHost,
+                     dev->data.udp.bindService) >= buflen)
+            return -1;
+        break;
+
+    case VIR_DOMAIN_CHR_TYPE_TCP:
+    {
+        bool telnet =
+            dev->data.tcp.protocol == VIR_DOMAIN_CHR_TCP_PROTOCOL_TELNET;
+
+        if (snprintf(buf, buflen,
+                     "socket,id=%s,host=%s,port=%s%s%s",
+                     id,
+                     dev->data.tcp.host,
+                     dev->data.tcp.service,
+                     telnet ? ",telnet" : "",
+                     dev->data.tcp.listen ? ",server,nowait" : "") >= buflen)
+            return -1;
+        break;
+    }
+
+    case VIR_DOMAIN_CHR_TYPE_UNIX:
+        if (snprintf(buf, buflen,
+                     "socket,id=%s,path=%s%s",
+                     id,
+                     dev->data.nix.path,
+                     dev->data.nix.listen ? ",server,nowait" : "") >= buflen)
+            return -1;
+        break;
+    }
+
+    return 0;
+}
+
+/* This function outputs an all-in-one character device command line option */
 static int qemudBuildCommandLineChrDevStr(virDomainChrDefPtr dev,
                                           char *buf,
                                           int buflen)
-- 
1.6.2.5

--
Libvir-list mailing list
Libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]