Blame SOURCES/libvirt-qemu-consolidate-parameters-of-qemuBuildChrChardevStr-into-flags.patch

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