[PATCH v3 1/3] qemu: Move channel path generation out of command creation

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

 



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

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

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

@@ -8510,22 +8509,6 @@ qemuBuildChannelsCommandLine(virLogManagerPtr logManager,
             break;

         case VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_VIRTIO:
-            /*
-             * 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
@@ -9189,8 +9172,7 @@ qemuBuildCommandLine(virQEMUDriverPtr driver,
                      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];
@@ -9335,8 +9317,7 @@ qemuBuildCommandLine(virQEMUDriverPtr driver,
     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 1c2270564c16..22d835117ca1 100644
--- a/src/qemu/qemu_command.h
+++ b/src/qemu/qemu_command.h
@@ -62,9 +62,8 @@ virCommandPtr qemuBuildCommandLine(virQEMUDriverPtr driver,
                                    virBitmapPtr nodeset,
                                    size_t *nnicindexes,
                                    int **nicindexes,
-                                   const char *domainLibDir,
-                                   const char *domainChannelTargetDir)
-    ATTRIBUTE_NONNULL(15) ATTRIBUTE_NONNULL(16);
+                                   const char *domainLibDir)
+    ATTRIBUTE_NONNULL(15);

 /* Generate '-device' string for chardev device */
 int
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index c21465d41c76..93220183b2c0 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -5471,3 +5471,23 @@ qemuDomainDefValidateDiskLunSource(const virStorageSource *src)

     return 0;
 }
+
+
+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 a9a7295557ca..f037367ef2a8 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -681,4 +681,8 @@ int qemuDomainSecretPrepare(virConnectPtr conn, virDomainObjPtr vm)
 int qemuDomainDefValidateDiskLunSource(const virStorageSource *src)
     ATTRIBUTE_NONNULL(1);

+int qemuDomainPrepareChannel(virDomainChrDefPtr chr,
+                             const char *domainChannelTargetDir)
+    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
+
 #endif /* __QEMU_DOMAIN_H__ */
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index e847cd1f13d1..66d370d98d18 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -4884,6 +4884,12 @@ qemuProcessPrepareDomain(virConnectPtr conn,
     if (qemuDomainSecretPrepare(conn, vm) < 0)
         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;

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

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

  cleanup:
     return cmd;
-- 
2.8.3

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]