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

[libvirt] [PATCH 2/3] qemu: Move channel path generation out of command creation



Put it into separate function called qemuDomainPrepareChannel() and call
it from the new qemuProcessPrepareDomain().

Signed-off-by: Martin Kletzander <mkletzan redhat com>
---
 src/qemu/qemu_command.c | 25 +++----------------------
 src/qemu/qemu_command.h |  5 ++---
 src/qemu/qemu_domain.c  | 19 +++++++++++++++++++
 src/qemu/qemu_domain.h  |  4 ++++
 src/qemu/qemu_process.c | 12 ++++++++----
 5 files changed, 36 insertions(+), 29 deletions(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 45c5398ad8b9..bb9357e41c3b 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -8468,8 +8468,7 @@ static int
 qemuBuildChannelsCommandLine(virLogManagerPtr logManager,
                              virCommandPtr cmd,
                              const virDomainDef *def,
-                             virQEMUCapsPtr qemuCaps,
-                             const char *domainChannelTargetDir)
+                             virQEMUCapsPtr qemuCaps)
 {
     size_t i;

@@ -8508,22 +8507,6 @@ qemuBuildChannelsCommandLine(virLogManagerPtr logManager,
                 return -1;
             }

-            /*
-             * TODO: Refactor so that we generate this (and onther
-             * things) somewhere else then where we are building the
-             * command line.
-             */
-            if (channel->source.type == VIR_DOMAIN_CHR_TYPE_UNIX &&
-                !channel->source.data.nix.path) {
-                if (virAsprintf(&channel->source.data.nix.path,
-                                "%s/%s", domainChannelTargetDir,
-                                channel->target.name ? channel->target.name
-                                : "unknown.sock") < 0)
-                    return -1;
-
-                channel->source.data.nix.listen = true;
-            }
-
             if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_SPICEVMC) &&
                 channel->source.type == VIR_DOMAIN_CHR_TYPE_SPICEVMC) {
                 /* spicevmc was originally introduced via a -device
@@ -9198,8 +9181,7 @@ qemuBuildCommandLine(virConnectPtr conn,
                      virBitmapPtr nodeset,
                      size_t *nnicindexes,
                      int **nicindexes,
-                     const char *domainLibDir,
-                     const char *domainChannelTargetDir)
+                     const char *domainLibDir)
 {
     size_t i;
     char uuid[VIR_UUID_STRING_BUFLEN];
@@ -9340,8 +9322,7 @@ qemuBuildCommandLine(virConnectPtr conn,
     if (qemuBuildParallelsCommandLine(logManager, cmd, def, qemuCaps) < 0)
         goto error;

-    if (qemuBuildChannelsCommandLine(logManager, cmd, def, qemuCaps,
-                                     domainChannelTargetDir) < 0)
+    if (qemuBuildChannelsCommandLine(logManager, cmd, def, qemuCaps) < 0)
         goto error;

     if (qemuBuildConsoleCommandLine(logManager, cmd, def, qemuCaps) < 0)
diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h
index 7c13d459f8c5..60dc76c45bdb 100644
--- a/src/qemu/qemu_command.h
+++ b/src/qemu/qemu_command.h
@@ -74,10 +74,9 @@ virCommandPtr qemuBuildCommandLine(virConnectPtr conn,
                                    virBitmapPtr nodeset,
                                    size_t *nnicindexes,
                                    int **nicindexes,
-                                   const char *domainLibDir,
-                                   const char *domainChannelTargetDir)
+                                   const char *domainLibDir)
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(11)
-    ATTRIBUTE_NONNULL(17) ATTRIBUTE_NONNULL(18);
+    ATTRIBUTE_NONNULL(17);

 /* Generate '-device' string for chardev device */
 int
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 403f01e75e46..645e1232d2f9 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -4639,3 +4639,22 @@ qemuDomainDiskByName(virDomainDefPtr def,

     return ret;
 }
+
+int
+qemuDomainPrepareChannel(virDomainChrDefPtr channel,
+                         const char *domainChannelTargetDir)
+{
+    if (channel->targetType == VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_VIRTIO &&
+        channel->source.type == VIR_DOMAIN_CHR_TYPE_UNIX &&
+        !channel->source.data.nix.path) {
+        if (virAsprintf(&channel->source.data.nix.path,
+                        "%s/%s", domainChannelTargetDir,
+                        channel->target.name ? channel->target.name
+                        : "unknown.sock") < 0)
+            return -1;
+
+        channel->source.data.nix.listen = true;
+    }
+
+    return 0;
+}
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index 02c6012c9c87..e893aa17cacd 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -560,4 +560,8 @@ int qemuDomainSetPrivatePaths(char **domainLibDir,

 virDomainDiskDefPtr qemuDomainDiskByName(virDomainDefPtr def, const char *name);

+int
+qemuDomainPrepareChannel(virDomainChrDefPtr chr,
+                         const char *domainChannelTargetDir);
+
 #endif /* __QEMU_DOMAIN_H__ */
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 07b9df27397c..6a4fe17125b0 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -5008,6 +5008,12 @@ qemuProcessPrepareDomain(virConnectPtr conn,
             goto cleanup;
     }

+    for (i = 0; i < vm->def->nchannels; i++) {
+        if (qemuDomainPrepareChannel(vm->def->channels[i],
+                                     priv->channelTargetDir) < 0)
+            goto cleanup;
+    }
+
     if (VIR_ALLOC(priv->monConfig) < 0)
         goto cleanup;

@@ -5234,8 +5240,7 @@ qemuProcessLaunch(virConnectPtr conn,
                                      qemuCheckFips(),
                                      priv->autoNodeset,
                                      &nnicindexes, &nicindexes,
-                                     priv->libDir,
-                                     priv->channelTargetDir)))
+                                     priv->libDir)))
         goto cleanup;

     if (incoming && incoming->fd != -1)
@@ -5656,8 +5661,7 @@ qemuProcessCreatePretendCmd(virConnectPtr conn,
                                priv->autoNodeset,
                                NULL,
                                NULL,
-                               priv->libDir,
-                               priv->channelTargetDir);
+                               priv->libDir);

  cleanup:
     return cmd;
-- 
2.8.0


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