render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
982648
From 2941ddd836bf42d62efd4488626673ab8ec33b03 Mon Sep 17 00:00:00 2001
982648
Message-Id: <2941ddd836bf42d62efd4488626673ab8ec33b03@dist-git>
982648
From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= <berrange@redhat.com>
982648
Date: Fri, 6 Jul 2018 15:47:00 +0100
982648
Subject: [PATCH] qemu: consolidate parameters of qemuBuildChrChardevStr into
982648
 flags
982648
MIME-Version: 1.0
982648
Content-Type: text/plain; charset=UTF-8
982648
Content-Transfer-Encoding: 8bit
982648
982648
https://bugzilla.redhat.com/show_bug.cgi?id=1597940
982648
982648
There are two boolean parameters passed to qemuBuildChrChardevStr,
982648
and soon there will be a third. It will be clearer to understand
982648
from callers' POV if we use named flags instead.
982648
982648
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
982648
(cherry picked from commit 0140d4c59b7fb26432b520bb7e85bd6834f560b0)
982648
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
982648
---
982648
 src/qemu/qemu_command.c | 94 ++++++++++++++++++++++++++---------------
982648
 1 file changed, 61 insertions(+), 33 deletions(-)
982648
982648
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
982648
index 41050bfea3..0c3ce98caf 100644
982648
--- a/src/qemu/qemu_command.c
982648
+++ b/src/qemu/qemu_command.c
982648
@@ -4934,6 +4934,12 @@ qemuOpenChrChardevUNIXSocket(const virDomainChrSourceDef *dev)
982648
     return -1;
982648
 }
982648
 
982648
+
982648
+enum {
982648
+    QEMU_BUILD_CHARDEV_TCP_NOWAIT = (1 << 0),
982648
+    QEMU_BUILD_CHARDEV_FILE_LOGD  = (1 << 1),
982648
+};
982648
+
982648
 /* This function outputs a -chardev command line option which describes only the
982648
  * host side of the character device */
982648
 static char *
982648
@@ -4945,8 +4951,7 @@ qemuBuildChrChardevStr(virLogManagerPtr logManager,
982648
                        const virDomainChrSourceDef *dev,
982648
                        const char *alias,
982648
                        virQEMUCapsPtr qemuCaps,
982648
-                       bool nowait,
982648
-                       bool chardevStdioLogd)
982648
+                       unsigned int flags)
982648
 {
982648
     virBuffer buf = VIR_BUFFER_INITIALIZER;
982648
     bool telnet;
982648
@@ -4985,7 +4990,8 @@ qemuBuildChrChardevStr(virLogManagerPtr logManager,
982648
                            _("append not supported in this QEMU binary"));
982648
             goto cleanup;
982648
         }
982648
-        if (qemuBuildChrChardevFileStr(chardevStdioLogd ? logManager : NULL,
982648
+        if (qemuBuildChrChardevFileStr(flags & QEMU_BUILD_CHARDEV_FILE_LOGD ?
982648
+                                       logManager : NULL,
982648
                                        cmd, def, &buf,
982648
                                        "path", dev->data.file.path,
982648
                                        "append", dev->data.file.append) < 0)
982648
@@ -5031,8 +5037,11 @@ qemuBuildChrChardevStr(virLogManagerPtr logManager,
982648
                           dev->data.tcp.service,
982648
                           telnet ? ",telnet" : "");
982648
 
982648
-        if (dev->data.tcp.listen)
982648
-            virBufferAdd(&buf, nowait ? ",server,nowait" : ",server", -1);
982648
+        if (dev->data.tcp.listen) {
982648
+            virBufferAddLit(&buf, ",server");
982648
+            if (flags & QEMU_BUILD_CHARDEV_TCP_NOWAIT)
982648
+                virBufferAddLit(&buf, ",nowait");
982648
+        }
982648
 
982648
         qemuBuildChrChardevReconnectStr(&buf, &dev->data.tcp.reconnect);
982648
 
982648
@@ -5090,8 +5099,11 @@ qemuBuildChrChardevStr(virLogManagerPtr logManager,
982648
             virBufferAsprintf(&buf, "socket,id=%s,path=", charAlias);
982648
             virQEMUBuildBufferEscapeComma(&buf, dev->data.nix.path);
982648
         }
982648
-        if (dev->data.nix.listen)
982648
-            virBufferAdd(&buf, nowait ? ",server,nowait" : ",server", -1);
982648
+        if (dev->data.nix.listen) {
982648
+            virBufferAddLit(&buf, ",server");
982648
+            if (flags & QEMU_BUILD_CHARDEV_TCP_NOWAIT)
982648
+                virBufferAddLit(&buf, ",nowait");
982648
+        }
982648
 
982648
         qemuBuildChrChardevReconnectStr(&buf, &dev->data.nix.reconnect);
982648
         break;
982648
@@ -5425,6 +5437,9 @@ qemuBuildMonitorCommandLine(virLogManagerPtr logManager,
982648
                             qemuDomainObjPrivatePtr priv)
982648
 {
982648
     char *chrdev;
982648
+    unsigned int cdevflags = QEMU_BUILD_CHARDEV_TCP_NOWAIT;
982648
+    if (priv->chardevStdioLogd)
982648
+        cdevflags |= QEMU_BUILD_CHARDEV_FILE_LOGD;
982648
 
982648
     if (!priv->monConfig)
982648
         return 0;
982648
@@ -5432,8 +5447,7 @@ qemuBuildMonitorCommandLine(virLogManagerPtr logManager,
982648
     if (!(chrdev = qemuBuildChrChardevStr(logManager, secManager,
982648
                                           cmd, cfg, def,
982648
                                           priv->monConfig, "monitor",
982648
-                                          priv->qemuCaps, true,
982648
-                                          priv->chardevStdioLogd)))
982648
+                                          priv->qemuCaps, cdevflags)))
982648
         return -1;
982648
     virCommandAddArg(cmd, "-chardev");
982648
     virCommandAddArg(cmd, chrdev);
982648
@@ -5558,6 +5572,9 @@ qemuBuildRNGBackendChrdevStr(virLogManagerPtr logManager,
982648
                              char **chr,
982648
                              bool chardevStdioLogd)
982648
 {
982648
+    unsigned int cdevflags = QEMU_BUILD_CHARDEV_TCP_NOWAIT;
982648
+    if (chardevStdioLogd)
982648
+        cdevflags |= QEMU_BUILD_CHARDEV_FILE_LOGD;
982648
     *chr = NULL;
982648
 
982648
     switch ((virDomainRNGBackend) rng->backend) {
982648
@@ -5570,8 +5587,8 @@ qemuBuildRNGBackendChrdevStr(virLogManagerPtr logManager,
982648
         if (!(*chr = qemuBuildChrChardevStr(logManager, secManager,
982648
                                             cmd, cfg, def,
982648
                                             rng->source.chardev,
982648
-                                            rng->info.alias, qemuCaps, true,
982648
-                                            chardevStdioLogd)))
982648
+                                            rng->info.alias, qemuCaps,
982648
+                                            cdevflags)))
982648
             return -1;
982648
     }
982648
 
982648
@@ -8243,8 +8260,7 @@ qemuBuildVhostuserCommandLine(virQEMUDriverPtr driver,
982648
         if (!(chardev = qemuBuildChrChardevStr(logManager, secManager,
982648
                                                cmd, cfg, def,
982648
                                                net->data.vhostuser,
982648
-                                               net->info.alias, qemuCaps, false,
982648
-                                               false)))
982648
+                                               net->info.alias, qemuCaps, 0)))
982648
             goto cleanup;
982648
         break;
982648
 
982648
@@ -8724,6 +8740,9 @@ qemuBuildSmartcardCommandLine(virLogManagerPtr logManager,
982648
     virBuffer opt = VIR_BUFFER_INITIALIZER;
982648
     const char *database;
982648
     const char *contAlias = NULL;
982648
+    unsigned int cdevflags = QEMU_BUILD_CHARDEV_TCP_NOWAIT;
982648
+    if (chardevStdioLogd)
982648
+        cdevflags |= QEMU_BUILD_CHARDEV_FILE_LOGD;
982648
 
982648
     if (!def->nsmartcards)
982648
         return 0;
982648
@@ -8789,8 +8808,7 @@ qemuBuildSmartcardCommandLine(virLogManagerPtr logManager,
982648
                                               cmd, cfg, def,
982648
                                               smartcard->data.passthru,
982648
                                               smartcard->info.alias,
982648
-                                              qemuCaps, true,
982648
-                                              chardevStdioLogd))) {
982648
+                                              qemuCaps, cdevflags))) {
982648
             virBufferFreeAndReset(&opt;;
982648
             return -1;
982648
         }
982648
@@ -8958,6 +8976,9 @@ qemuBuildShmemCommandLine(virLogManagerPtr logManager,
982648
     virBuffer buf = VIR_BUFFER_INITIALIZER;
982648
     char *devstr = NULL;
982648
     int rc;
982648
+    unsigned int cdevflags = QEMU_BUILD_CHARDEV_TCP_NOWAIT;
982648
+    if (chardevStdioLogd)
982648
+        cdevflags |= QEMU_BUILD_CHARDEV_FILE_LOGD;
982648
 
982648
     if (shmem->size) {
982648
         /*
982648
@@ -9021,8 +9042,8 @@ qemuBuildShmemCommandLine(virLogManagerPtr logManager,
982648
         devstr = qemuBuildChrChardevStr(logManager, secManager,
982648
                                         cmd, cfg, def,
982648
                                         &shmem->server.chr,
982648
-                                        shmem->info.alias, qemuCaps, true,
982648
-                                        chardevStdioLogd);
982648
+                                        shmem->info.alias, qemuCaps,
982648
+                                        cdevflags);
982648
         if (!devstr)
982648
             return -1;
982648
 
982648
@@ -9115,6 +9136,9 @@ qemuBuildSerialCommandLine(virLogManagerPtr logManager,
982648
 {
982648
     size_t i;
982648
     bool havespice = false;
982648
+    unsigned int cdevflags = QEMU_BUILD_CHARDEV_TCP_NOWAIT;
982648
+    if (chardevStdioLogd)
982648
+        cdevflags |= QEMU_BUILD_CHARDEV_FILE_LOGD;
982648
 
982648
     if (def->nserials) {
982648
         for (i = 0; i < def->ngraphics && !havespice; i++) {
982648
@@ -9134,8 +9158,7 @@ qemuBuildSerialCommandLine(virLogManagerPtr logManager,
982648
                                               cmd, cfg, def,
982648
                                               serial->source,
982648
                                               serial->info.alias,
982648
-                                              qemuCaps, true,
982648
-                                              chardevStdioLogd)))
982648
+                                              qemuCaps, cdevflags)))
982648
             return -1;
982648
         virCommandAddArg(cmd, "-chardev");
982648
         virCommandAddArg(cmd, devstr);
982648
@@ -9176,6 +9199,9 @@ qemuBuildParallelsCommandLine(virLogManagerPtr logManager,
982648
                               bool chardevStdioLogd)
982648
 {
982648
     size_t i;
982648
+    unsigned int cdevflags = QEMU_BUILD_CHARDEV_TCP_NOWAIT;
982648
+    if (chardevStdioLogd)
982648
+        cdevflags |= QEMU_BUILD_CHARDEV_FILE_LOGD;
982648
 
982648
     for (i = 0; i < def->nparallels; i++) {
982648
         virDomainChrDefPtr parallel = def->parallels[i];
982648
@@ -9185,8 +9211,7 @@ qemuBuildParallelsCommandLine(virLogManagerPtr logManager,
982648
                                               cmd, cfg, def,
982648
                                               parallel->source,
982648
                                               parallel->info.alias,
982648
-                                              qemuCaps, true,
982648
-                                              chardevStdioLogd)))
982648
+                                              qemuCaps, cdevflags)))
982648
             return -1;
982648
         virCommandAddArg(cmd, "-chardev");
982648
         virCommandAddArg(cmd, devstr);
982648
@@ -9211,6 +9236,9 @@ qemuBuildChannelsCommandLine(virLogManagerPtr logManager,
982648
                              bool chardevStdioLogd)
982648
 {
982648
     size_t i;
982648
+    unsigned int cdevflags = QEMU_BUILD_CHARDEV_TCP_NOWAIT;
982648
+    if (chardevStdioLogd)
982648
+        cdevflags |= QEMU_BUILD_CHARDEV_FILE_LOGD;
982648
 
982648
     for (i = 0; i < def->nchannels; i++) {
982648
         virDomainChrDefPtr channel = def->channels[i];
982648
@@ -9222,8 +9250,7 @@ qemuBuildChannelsCommandLine(virLogManagerPtr logManager,
982648
                                                   cmd, cfg, def,
982648
                                                   channel->source,
982648
                                                   channel->info.alias,
982648
-                                                  qemuCaps, true,
982648
-                                                  chardevStdioLogd)))
982648
+                                                  qemuCaps, cdevflags)))
982648
                 return -1;
982648
             virCommandAddArg(cmd, "-chardev");
982648
             virCommandAddArg(cmd, devstr);
982648
@@ -9240,8 +9267,7 @@ qemuBuildChannelsCommandLine(virLogManagerPtr logManager,
982648
                                                   cmd, cfg, def,
982648
                                                   channel->source,
982648
                                                   channel->info.alias,
982648
-                                                  qemuCaps, true,
982648
-                                                  chardevStdioLogd)))
982648
+                                                  qemuCaps, cdevflags)))
982648
                 return -1;
982648
             virCommandAddArg(cmd, "-chardev");
982648
             virCommandAddArg(cmd, devstr);
982648
@@ -9267,6 +9293,9 @@ qemuBuildConsoleCommandLine(virLogManagerPtr logManager,
982648
                             bool chardevStdioLogd)
982648
 {
982648
     size_t i;
982648
+    unsigned int cdevflags = QEMU_BUILD_CHARDEV_TCP_NOWAIT;
982648
+    if (chardevStdioLogd)
982648
+        cdevflags |= QEMU_BUILD_CHARDEV_FILE_LOGD;
982648
 
982648
     /* Explicit console devices */
982648
     for (i = 0; i < def->nconsoles; i++) {
982648
@@ -9285,8 +9314,7 @@ qemuBuildConsoleCommandLine(virLogManagerPtr logManager,
982648
                                                   cmd, cfg, def,
982648
                                                   console->source,
982648
                                                   console->info.alias,
982648
-                                                  qemuCaps, true,
982648
-                                                  chardevStdioLogd)))
982648
+                                                  qemuCaps, cdevflags)))
982648
                 return -1;
982648
             virCommandAddArg(cmd, "-chardev");
982648
             virCommandAddArg(cmd, devstr);
982648
@@ -9307,8 +9335,7 @@ qemuBuildConsoleCommandLine(virLogManagerPtr logManager,
982648
                                                   cmd, cfg, def,
982648
                                                   console->source,
982648
                                                   console->info.alias,
982648
-                                                  qemuCaps, true,
982648
-                                                  chardevStdioLogd)))
982648
+                                                  qemuCaps, cdevflags)))
982648
                 return -1;
982648
             virCommandAddArg(cmd, "-chardev");
982648
             virCommandAddArg(cmd, devstr);
982648
@@ -9323,8 +9350,7 @@ qemuBuildConsoleCommandLine(virLogManagerPtr logManager,
982648
                                                   cmd, cfg, def,
982648
                                                   console->source,
982648
                                                   console->info.alias,
982648
-                                                  qemuCaps, true,
982648
-                                                  chardevStdioLogd)))
982648
+                                                  qemuCaps, cdevflags)))
982648
                 return -1;
982648
             virCommandAddArg(cmd, "-chardev");
982648
             virCommandAddArg(cmd, devstr);
982648
@@ -9447,6 +9473,9 @@ qemuBuildRedirdevCommandLine(virLogManagerPtr logManager,
982648
                              bool chardevStdioLogd)
982648
 {
982648
     size_t i;
982648
+    unsigned int cdevflags = QEMU_BUILD_CHARDEV_TCP_NOWAIT;
982648
+    if (chardevStdioLogd)
982648
+        cdevflags |= QEMU_BUILD_CHARDEV_FILE_LOGD;
982648
 
982648
     for (i = 0; i < def->nredirdevs; i++) {
982648
         virDomainRedirdevDefPtr redirdev = def->redirdevs[i];
982648
@@ -9456,8 +9485,7 @@ qemuBuildRedirdevCommandLine(virLogManagerPtr logManager,
982648
                                               cmd, cfg, def,
982648
                                               redirdev->source,
982648
                                               redirdev->info.alias,
982648
-                                              qemuCaps, true,
982648
-                                              chardevStdioLogd))) {
982648
+                                              qemuCaps, cdevflags))) {
982648
             return -1;
982648
         }
982648
 
982648
-- 
982648
2.18.0
982648