Blame SOURCES/libvirt-conf-Add-helper-to-determine-whether-memory-hotplug-is-enabled-for-a-vm.patch

7a3408
From b0dc796ccdf858a0fdb22a811fd28b4ed3d6dce5 Mon Sep 17 00:00:00 2001
7a3408
Message-Id: <b0dc796ccdf858a0fdb22a811fd28b4ed3d6dce5@dist-git>
7a3408
From: Peter Krempa <pkrempa@redhat.com>
7a3408
Date: Tue, 22 Sep 2015 16:59:37 +0200
7a3408
Subject: [PATCH] conf: Add helper to determine whether memory hotplug is
7a3408
 enabled for a vm
7a3408
7a3408
https://bugzilla.redhat.com/show_bug.cgi?id=1252685
7a3408
7a3408
Add a simple helper so that the code doesn't have to rewrite the same
7a3408
condition multiple times.
7a3408
7a3408
(cherry picked from commit 1891cad5420a3a1727177d1c762b23104c9ccc6d)
7a3408
7a3408
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
7a3408
---
7a3408
 src/conf/domain_conf.c    | 11 +++++++++--
7a3408
 src/conf/domain_conf.h    |  1 +
7a3408
 src/libvirt_private.syms  |  1 +
7a3408
 src/qemu/qemu_command.c   |  2 +-
7a3408
 src/qemu/qemu_domain.c    |  2 +-
7a3408
 src/qemu/qemu_migration.c |  5 ++---
7a3408
 6 files changed, 15 insertions(+), 7 deletions(-)
7a3408
7a3408
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
7a3408
index 15d3a5e..2dc5912 100644
7a3408
--- a/src/conf/domain_conf.c
7a3408
+++ b/src/conf/domain_conf.c
7a3408
@@ -1141,7 +1141,7 @@ int
7a3408
 virDomainDefCheckUnsupportedMemoryHotplug(virDomainDefPtr def)
7a3408
 {
7a3408
     /* memory hotplug tunables are not supported by this driver */
7a3408
-    if (def->mem.max_memory > 0 || def->mem.memory_slots > 0) {
7a3408
+    if (virDomainDefHasMemoryHotplug(def)) {
7a3408
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
7a3408
                        _("memory hotplug tunables <maxMemory> are not "
7a3408
                          "supported by this hypervisor driver"));
7a3408
@@ -7637,6 +7637,13 @@ virDomainParseMemoryLimit(const char *xpath,
7a3408
 }
7a3408
 
7a3408
 
7a3408
+bool
7a3408
+virDomainDefHasMemoryHotplug(const virDomainDef *def)
7a3408
+{
7a3408
+    return def->mem.memory_slots > 0 || def->mem.max_memory > 0;
7a3408
+}
7a3408
+
7a3408
+
7a3408
 /**
7a3408
  * virDomainDefGetMemoryInitial:
7a3408
  * @def: domain definition
7a3408
@@ -21342,7 +21349,7 @@ virDomainDefFormatInternal(virDomainDefPtr def,
7a3408
         xmlIndentTreeOutput = oldIndentTreeOutput;
7a3408
     }
7a3408
 
7a3408
-    if (def->mem.max_memory) {
7a3408
+    if (virDomainDefHasMemoryHotplug(def)) {
7a3408
         virBufferAsprintf(buf,
7a3408
                           "<maxMemory slots='%u' unit='KiB'>%llu</maxMemory>\n",
7a3408
                           def->mem.memory_slots, def->mem.max_memory);
7a3408
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
7a3408
index 3040ddc..902dfb9 100644
7a3408
--- a/src/conf/domain_conf.h
7a3408
+++ b/src/conf/domain_conf.h
7a3408
@@ -2288,6 +2288,7 @@ struct _virDomainDef {
7a3408
 unsigned long long virDomainDefGetMemoryInitial(virDomainDefPtr def);
7a3408
 void virDomainDefSetMemoryInitial(virDomainDefPtr def, unsigned long long size);
7a3408
 unsigned long long virDomainDefGetMemoryActual(virDomainDefPtr def);
7a3408
+bool virDomainDefHasMemoryHotplug(const virDomainDef *def);
7a3408
 
7a3408
 typedef enum {
7a3408
     VIR_DOMAIN_KEY_WRAP_CIPHER_NAME_AES,
7a3408
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
7a3408
index 9332194..335f8d0 100644
7a3408
--- a/src/libvirt_private.syms
7a3408
+++ b/src/libvirt_private.syms
7a3408
@@ -215,6 +215,7 @@ virDomainDefGetMemoryActual;
7a3408
 virDomainDefGetMemoryInitial;
7a3408
 virDomainDefGetSecurityLabelDef;
7a3408
 virDomainDefHasDeviceAddress;
7a3408
+virDomainDefHasMemoryHotplug;
7a3408
 virDomainDefMaybeAddController;
7a3408
 virDomainDefMaybeAddInput;
7a3408
 virDomainDefNeedsPlacementAdvice;
7a3408
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
7a3408
index 47d91c6..ade75e3 100644
7a3408
--- a/src/qemu/qemu_command.c
7a3408
+++ b/src/qemu/qemu_command.c
7a3408
@@ -9045,7 +9045,7 @@ qemuBuildCommandLine(virConnectPtr conn,
7a3408
 
7a3408
     virCommandAddArg(cmd, "-m");
7a3408
 
7a3408
-    if (def->mem.max_memory) {
7a3408
+    if (virDomainDefHasMemoryHotplug(def)) {
7a3408
         if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_PC_DIMM)) {
7a3408
             virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
7a3408
                            _("memory hotplug isn't supported by this QEMU binary"));
7a3408
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
7a3408
index e4a9c55..9d9fb06 100644
7a3408
--- a/src/qemu/qemu_domain.c
7a3408
+++ b/src/qemu/qemu_domain.c
7a3408
@@ -1347,7 +1347,7 @@ qemuDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
7a3408
     }
7a3408
 
7a3408
     if (dev->type == VIR_DOMAIN_DEVICE_MEMORY &&
7a3408
-        def->mem.max_memory == 0) {
7a3408
+        !virDomainDefHasMemoryHotplug(def)) {
7a3408
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
7a3408
                        _("maxMemory has to be specified when using memory "
7a3408
                          "devices "));
7a3408
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
7a3408
index 58fcb94..93f561f 100644
7a3408
--- a/src/qemu/qemu_migration.c
7a3408
+++ b/src/qemu/qemu_migration.c
7a3408
@@ -2988,10 +2988,9 @@ qemuMigrationBeginPhase(virQEMUDriverPtr driver,
7a3408
         }
7a3408
     }
7a3408
 
7a3408
-    if (vm->def->mem.max_memory ||
7a3408
+    if (virDomainDefHasMemoryHotplug(vm->def) ||
7a3408
         ((flags & VIR_MIGRATE_PERSIST_DEST) &&
7a3408
-         vm->newDef &&
7a3408
-         vm->newDef->mem.max_memory))
7a3408
+         vm->newDef && virDomainDefHasMemoryHotplug(vm->newDef)))
7a3408
         cookieFlags |= QEMU_MIGRATION_COOKIE_MEMORY_HOTPLUG;
7a3408
 
7a3408
     if (!(mig = qemuMigrationEatCookie(driver, vm, NULL, 0, 0)))
7a3408
-- 
7a3408
2.5.3
7a3408