render / rpms / libvirt

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