Blob Blame History Raw
From 6a085ddb32e48aad09d6a831c02bfd531ac048af Mon Sep 17 00:00:00 2001
Message-Id: <6a085ddb32e48aad09d6a831c02bfd531ac048af@dist-git>
From: Michal Privoznik <mprivozn@redhat.com>
Date: Tue, 8 Nov 2016 13:42:10 +0100
Subject: [PATCH] qemuBuildVhostuserCommandLine: Reuse qemuBuildChrChardevStr

RHEL-7.3: https://bugzilla.redhat.com/show_bug.cgi?id=1366108
RHEL-7.3.z: https://bugzilla.redhat.com/show_bug.cgi?id=1392032

There's no need to reinvent the wheel here. We already have a
function to format virDomainChrSourceDefPtr. It's called
qemuBuildChrChardevStr(). Use that instead of some dummy
virBufferAsprintf().

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
(cherry picked from commit 0c61cf315859a74326da93bbb6f04a08509ef91e)
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 src/qemu/qemu_command.c | 45 ++++++++++++++++++++++++++-------------------
 1 file changed, 26 insertions(+), 19 deletions(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index d28a367cc..b99fb7a8f 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -7908,13 +7908,16 @@ qemuBuildGraphicsCommandLine(virQEMUDriverConfigPtr cfg,
 }
 
 static int
-qemuBuildVhostuserCommandLine(virCommandPtr cmd,
+qemuBuildVhostuserCommandLine(virQEMUDriverPtr driver,
+                              virLogManagerPtr logManager,
+                              virCommandPtr cmd,
                               virDomainDefPtr def,
                               virDomainNetDefPtr net,
                               virQEMUCapsPtr qemuCaps,
                               unsigned int bootindex)
 {
-    virBuffer chardev_buf = VIR_BUFFER_INITIALIZER;
+    virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
+    char *chardev = NULL;
     virBuffer netdev_buf = VIR_BUFFER_INITIALIZER;
     unsigned int queues = net->driver.virtio.queues;
     char *nic = NULL;
@@ -7927,9 +7930,10 @@ qemuBuildVhostuserCommandLine(virCommandPtr cmd,
 
     switch ((virDomainChrType) net->data.vhostuser->type) {
     case VIR_DOMAIN_CHR_TYPE_UNIX:
-        virBufferAsprintf(&chardev_buf, "socket,id=char%s,path=%s%s",
-                          net->info.alias, net->data.vhostuser->data.nix.path,
-                          net->data.vhostuser->data.nix.listen ? ",server" : "");
+        if (!(chardev = qemuBuildChrChardevStr(logManager, cmd, cfg, def,
+                                               net->data.vhostuser,
+                                               net->info.alias, qemuCaps, false)))
+            goto error;
         break;
 
     case VIR_DOMAIN_CHR_TYPE_NULL:
@@ -7947,7 +7951,7 @@ qemuBuildVhostuserCommandLine(virCommandPtr cmd,
     case VIR_DOMAIN_CHR_TYPE_LAST:
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("vhost-user type '%s' not supported"),
-                        virDomainChrTypeToString(net->data.vhostuser->type));
+                       virDomainChrTypeToString(net->data.vhostuser->type));
         goto error;
     }
 
@@ -7965,7 +7969,8 @@ qemuBuildVhostuserCommandLine(virCommandPtr cmd,
     }
 
     virCommandAddArg(cmd, "-chardev");
-    virCommandAddArgBuffer(cmd, &chardev_buf);
+    virCommandAddArg(cmd, chardev);
+    VIR_FREE(chardev);
 
     virCommandAddArg(cmd, "-netdev");
     virCommandAddArgBuffer(cmd, &netdev_buf);
@@ -7979,11 +7984,13 @@ qemuBuildVhostuserCommandLine(virCommandPtr cmd,
 
     virCommandAddArgList(cmd, "-device", nic, NULL);
     VIR_FREE(nic);
+    virObjectUnref(cfg);
 
     return 0;
 
  error:
-    virBufferFreeAndReset(&chardev_buf);
+    virObjectUnref(cfg);
+    VIR_FREE(chardev);
     virBufferFreeAndReset(&netdev_buf);
     VIR_FREE(nic);
 
@@ -7991,8 +7998,9 @@ qemuBuildVhostuserCommandLine(virCommandPtr cmd,
 }
 
 static int
-qemuBuildInterfaceCommandLine(virCommandPtr cmd,
-                              virQEMUDriverPtr driver,
+qemuBuildInterfaceCommandLine(virQEMUDriverPtr driver,
+                              virLogManagerPtr logManager,
+                              virCommandPtr cmd,
                               virDomainDefPtr def,
                               virDomainNetDefPtr net,
                               virQEMUCapsPtr qemuCaps,
@@ -8012,7 +8020,6 @@ qemuBuildInterfaceCommandLine(virCommandPtr cmd,
     char **tapfdName = NULL;
     char **vhostfdName = NULL;
     virDomainNetType actualType = virDomainNetGetActualType(net);
-    virQEMUDriverConfigPtr cfg = NULL;
     virNetDevBandwidthPtr actualBandwidth;
     size_t i;
 
@@ -8055,8 +8062,6 @@ qemuBuildInterfaceCommandLine(virCommandPtr cmd,
         return -1;
     }
 
-    cfg = virQEMUDriverGetConfig(driver);
-
     switch (actualType) {
     case VIR_DOMAIN_NET_TYPE_NETWORK:
     case VIR_DOMAIN_NET_TYPE_BRIDGE:
@@ -8116,7 +8121,8 @@ qemuBuildInterfaceCommandLine(virCommandPtr cmd,
         break;
 
     case VIR_DOMAIN_NET_TYPE_VHOSTUSER:
-        ret = qemuBuildVhostuserCommandLine(cmd, def, net, qemuCaps, bootindex);
+        ret = qemuBuildVhostuserCommandLine(driver, logManager, cmd, def,
+                                            net, qemuCaps, bootindex);
         goto cleanup;
         break;
 
@@ -8289,7 +8295,6 @@ qemuBuildInterfaceCommandLine(virCommandPtr cmd,
     VIR_FREE(host);
     VIR_FREE(tapfdName);
     VIR_FREE(vhostfdName);
-    virObjectUnref(cfg);
     return ret;
 }
 
@@ -8299,8 +8304,9 @@ qemuBuildInterfaceCommandLine(virCommandPtr cmd,
  *       API domainSetSecurityTapFDLabel that doesn't use the const format.
  */
 static int
-qemuBuildNetCommandLine(virCommandPtr cmd,
-                        virQEMUDriverPtr driver,
+qemuBuildNetCommandLine(virQEMUDriverPtr driver,
+                        virLogManagerPtr logManager,
+                        virCommandPtr cmd,
                         virDomainDefPtr def,
                         virQEMUCapsPtr qemuCaps,
                         virNetDevVPortProfileOp vmop,
@@ -8339,7 +8345,7 @@ qemuBuildNetCommandLine(virCommandPtr cmd,
             else
                 vlan = i;
 
-            if (qemuBuildInterfaceCommandLine(cmd, driver, def, net,
+            if (qemuBuildInterfaceCommandLine(driver, logManager, cmd, def, net,
                                               qemuCaps, vlan, bootNet, vmop,
                                               standalone, nnicindexes,
                                               nicindexes) < 0)
@@ -9672,7 +9678,8 @@ qemuBuildCommandLine(virQEMUDriverPtr driver,
     if (qemuBuildFSDevCommandLine(cmd, def, qemuCaps) < 0)
         goto error;
 
-    if (qemuBuildNetCommandLine(cmd, driver, def, qemuCaps, vmop, standalone,
+    if (qemuBuildNetCommandLine(driver, logManager, cmd, def,
+                                qemuCaps, vmop, standalone,
                                 emitBootindex, nnicindexes, nicindexes,
                                 &bootHostdevNet) < 0)
         goto error;
-- 
2.11.0