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

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



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 c4690b2..3f0fbc1 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


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