[PATCH 08/10] qemu: Reorganize -smp argument

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

 



Reorganize the module to put all the -smp argument processing code together
after the memory arguments to form a logical order of processing for
qemuBuildCommandLine working top down in the module.

Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx>
---
 src/qemu/qemu_command.c | 102 ++++++++++++++++++++++++++++--------------------
 1 file changed, 60 insertions(+), 42 deletions(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index a8d1f4f..c90650f 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -976,6 +976,65 @@ qemuBuildMemCommandLine(virCommandPtr cmd,
 }
 
 
+/** Start SMP (-smp) arguments */
+static char *
+qemuBuildSmpArgStr(const virDomainDef *def,
+                   virQEMUCapsPtr qemuCaps)
+{
+    virBuffer buf = VIR_BUFFER_INITIALIZER;
+
+    virBufferAsprintf(&buf, "%u", virDomainDefGetVcpus(def));
+
+    if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_SMP_TOPOLOGY)) {
+        if (virDomainDefHasVcpusOffline(def))
+            virBufferAsprintf(&buf, ",maxcpus=%u", virDomainDefGetVcpusMax(def));
+        /* sockets, cores, and threads are either all zero
+         * or all non-zero, thus checking one of them is enough */
+        if (def->cpu && def->cpu->sockets) {
+            virBufferAsprintf(&buf, ",sockets=%u", def->cpu->sockets);
+            virBufferAsprintf(&buf, ",cores=%u", def->cpu->cores);
+            virBufferAsprintf(&buf, ",threads=%u", def->cpu->threads);
+        } else {
+            virBufferAsprintf(&buf, ",sockets=%u", virDomainDefGetVcpusMax(def));
+            virBufferAsprintf(&buf, ",cores=%u", 1);
+            virBufferAsprintf(&buf, ",threads=%u", 1);
+        }
+    } else if (virDomainDefHasVcpusOffline(def)) {
+        virBufferFreeAndReset(&buf);
+        /* FIXME - consider hot-unplugging cpus after boot for older qemu */
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                       _("setting current vcpu count less than maximum is "
+                         "not supported with this QEMU binary"));
+        return NULL;
+    }
+
+    if (virBufferCheckError(&buf) < 0)
+        return NULL;
+
+    return virBufferContentAndReset(&buf);
+}
+
+
+static int
+qemuBuildSmpCommandLine(virCommandPtr cmd,
+                        const virDomainDef *def,
+                        virQEMUCapsPtr qemuCaps)
+{
+    char *smp;
+
+    virCommandAddArg(cmd, "-smp");
+    if (!(smp = qemuBuildSmpArgStr(def, qemuCaps)))
+        goto error;
+    virCommandAddArg(cmd, smp);
+    VIR_FREE(smp);
+
+    return 0;
+
+ error:
+    return -1;
+}
+
+
 static int
 qemuBuildObjectCommandLinePropsInternal(const char *key,
                                         const virJSONValue *value,
@@ -5387,43 +5446,6 @@ qemuBuildClockArgStr(virDomainClockDefPtr def)
     return NULL;
 }
 
-static char *
-qemuBuildSmpArgStr(const virDomainDef *def,
-                   virQEMUCapsPtr qemuCaps)
-{
-    virBuffer buf = VIR_BUFFER_INITIALIZER;
-
-    virBufferAsprintf(&buf, "%u", virDomainDefGetVcpus(def));
-
-    if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_SMP_TOPOLOGY)) {
-        if (virDomainDefHasVcpusOffline(def))
-            virBufferAsprintf(&buf, ",maxcpus=%u", virDomainDefGetVcpusMax(def));
-        /* sockets, cores, and threads are either all zero
-         * or all non-zero, thus checking one of them is enough */
-        if (def->cpu && def->cpu->sockets) {
-            virBufferAsprintf(&buf, ",sockets=%u", def->cpu->sockets);
-            virBufferAsprintf(&buf, ",cores=%u", def->cpu->cores);
-            virBufferAsprintf(&buf, ",threads=%u", def->cpu->threads);
-        } else {
-            virBufferAsprintf(&buf, ",sockets=%u", virDomainDefGetVcpusMax(def));
-            virBufferAsprintf(&buf, ",cores=%u", 1);
-            virBufferAsprintf(&buf, ",threads=%u", 1);
-        }
-    } else if (virDomainDefHasVcpusOffline(def)) {
-        virBufferFreeAndReset(&buf);
-        /* FIXME - consider hot-unplugging cpus after boot for older qemu */
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                       _("setting current vcpu count less than maximum is "
-                         "not supported with this QEMU binary"));
-        return NULL;
-    }
-
-    if (virBufferCheckError(&buf) < 0)
-        return NULL;
-
-    return virBufferContentAndReset(&buf);
-}
-
 static int
 qemuBuildNumaArgStr(virQEMUDriverConfigPtr cfg,
                     virDomainDefPtr def,
@@ -6807,7 +6829,6 @@ qemuBuildCommandLine(virConnectPtr conn,
     virErrorPtr originalError = NULL;
     size_t i, j;
     char uuid[VIR_UUID_STRING_BUFLEN];
-    char *smp;
     int spicecnt = 0;
     int last_good_net = -1;
     virCommandPtr cmd = NULL;
@@ -6900,11 +6921,8 @@ qemuBuildCommandLine(virConnectPtr conn,
     if (qemuBuildMemCommandLine(cmd, cfg, def, qemuCaps) < 0)
         goto error;
 
-    virCommandAddArg(cmd, "-smp");
-    if (!(smp = qemuBuildSmpArgStr(def, qemuCaps)))
+    if (qemuBuildSmpCommandLine(cmd, def, qemuCaps) < 0)
         goto error;
-    virCommandAddArg(cmd, smp);
-    VIR_FREE(smp);
 
     if (def->niothreadids) {
         if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_OBJECT_IOTHREAD)) {
-- 
2.5.0

--
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]