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

[libvirt] [REPOST PATCH 5/8] qemu: Introduce qemuBuildMemballoonCommandLine



Add new function to manage adding the memballoon device options to the
command line removing that task from the mainline qemuBuildCommandLine.

Also modify the qemuBuildMemballoonDevStr to use const virDomainDef
instead of virDomainDefPtr.

Signed-off-by: John Ferlan <jferlan redhat com>
---
 src/qemu/qemu_command.c | 76 ++++++++++++++++++++++++++++---------------------
 src/qemu/qemu_command.h |  2 +-
 2 files changed, 45 insertions(+), 33 deletions(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 69026f9..0f9fe60 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -3408,7 +3408,7 @@ qemuBuildWatchdogCommandLine(virCommandPtr cmd,
 
 
 char *
-qemuBuildMemballoonDevStr(virDomainDefPtr def,
+qemuBuildMemballoonDevStr(const virDomainDef *def,
                           virDomainMemballoonDefPtr dev,
                           virQEMUCapsPtr qemuCaps)
 {
@@ -3456,6 +3456,47 @@ qemuBuildMemballoonDevStr(virDomainDefPtr def,
     return NULL;
 }
 
+
+static int
+qemuBuildMemballoonCommandLine(virCommandPtr cmd,
+                               const virDomainDef *def,
+                               virQEMUCapsPtr qemuCaps)
+{
+    /* QEMU changed its default behavior to not include the virtio balloon
+     * device.  Explicitly request it to ensure it will be present.
+     *
+     * NB: Earlier we declared that VirtIO balloon will always be in
+     * slot 0x3 on bus 0x0
+     */
+    if (STREQLEN(def->os.machine, "s390-virtio", 10) &&
+        virQEMUCapsGet(qemuCaps, QEMU_CAPS_VIRTIO_S390) && def->memballoon)
+        def->memballoon->model = VIR_DOMAIN_MEMBALLOON_MODEL_NONE;
+
+    if (def->memballoon &&
+        def->memballoon->model != VIR_DOMAIN_MEMBALLOON_MODEL_NONE) {
+        if (def->memballoon->model != VIR_DOMAIN_MEMBALLOON_MODEL_VIRTIO) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                           _("Memory balloon device type '%s' is not supported by this version of qemu"),
+                           virDomainMemballoonModelTypeToString(def->memballoon->model));
+            return -1;
+        }
+        if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE)) {
+            char *optstr;
+            virCommandAddArg(cmd, "-device");
+
+            optstr = qemuBuildMemballoonDevStr(def, def->memballoon, qemuCaps);
+            if (!optstr)
+                return -1;
+            virCommandAddArg(cmd, optstr);
+            VIR_FREE(optstr);
+        } else if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_BALLOON)) {
+            virCommandAddArgList(cmd, "-balloon", "virtio", NULL);
+        }
+    }
+    return 0;
+}
+
+
 static char *
 qemuBuildNVRAMDevStr(virDomainNVRAMDefPtr dev)
 {
@@ -9139,37 +9180,8 @@ qemuBuildCommandLine(virConnectPtr conn,
     if (migrateURI)
         virCommandAddArgList(cmd, "-incoming", migrateURI, NULL);
 
-    /* QEMU changed its default behavior to not include the virtio balloon
-     * device.  Explicitly request it to ensure it will be present.
-     *
-     * NB: Earlier we declared that VirtIO balloon will always be in
-     * slot 0x3 on bus 0x0
-     */
-    if (STREQLEN(def->os.machine, "s390-virtio", 10) &&
-        virQEMUCapsGet(qemuCaps, QEMU_CAPS_VIRTIO_S390) && def->memballoon)
-        def->memballoon->model = VIR_DOMAIN_MEMBALLOON_MODEL_NONE;
-
-    if (def->memballoon &&
-        def->memballoon->model != VIR_DOMAIN_MEMBALLOON_MODEL_NONE) {
-        if (def->memballoon->model != VIR_DOMAIN_MEMBALLOON_MODEL_VIRTIO) {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                           _("Memory balloon device type '%s' is not supported by this version of qemu"),
-                           virDomainMemballoonModelTypeToString(def->memballoon->model));
-            goto error;
-        }
-        if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE)) {
-            char *optstr;
-            virCommandAddArg(cmd, "-device");
-
-            optstr = qemuBuildMemballoonDevStr(def, def->memballoon, qemuCaps);
-            if (!optstr)
-                goto error;
-            virCommandAddArg(cmd, optstr);
-            VIR_FREE(optstr);
-        } else if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_BALLOON)) {
-            virCommandAddArgList(cmd, "-balloon", "virtio", NULL);
-        }
-    }
+    if (qemuBuildMemballoonCommandLine(cmd, def, qemuCaps) < 0)
+        goto error;
 
     for (i = 0; i < def->nrngs; i++) {
         virDomainRNGDefPtr rng = def->rngs[i];
diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h
index 4e22421..25de1abd 100644
--- a/src/qemu/qemu_command.h
+++ b/src/qemu/qemu_command.h
@@ -130,7 +130,7 @@ char *qemuBuildControllerDevStr(const virDomainDef *domainDef,
                                 virQEMUCapsPtr qemuCaps,
                                 int *nusbcontroller);
 
-char *qemuBuildMemballoonDevStr(virDomainDefPtr domainDef,
+char *qemuBuildMemballoonDevStr(const virDomainDef *domainDef,
                                 virDomainMemballoonDefPtr dev,
                                 virQEMUCapsPtr qemuCaps);
 
-- 
2.5.0


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