]> xenbits.xensource.com Git - libvirt.git/commitdiff
conf: Add helper to determine whether memory hotplug is enabled for a vm
authorPeter Krempa <pkrempa@redhat.com>
Mon, 14 Sep 2015 14:42:46 +0000 (16:42 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 22 Sep 2015 14:09:27 +0000 (16:09 +0200)
Add a simple helper so that the code doesn't have to rewrite the same
condition multiple times.

src/conf/domain_conf.c
src/conf/domain_conf.h
src/libvirt_private.syms
src/qemu/qemu_command.c
src/qemu/qemu_domain.c
src/qemu/qemu_migration.c

index a3b3ccb0d7ccf3ca3dc95c61b67739b8b5eb8949..32430d84587b97f85f27ebc1889a29af70b44e8b 100644 (file)
@@ -1154,7 +1154,7 @@ int
 virDomainDefCheckUnsupportedMemoryHotplug(virDomainDefPtr def)
 {
     /* memory hotplug tunables are not supported by this driver */
-    if (def->mem.max_memory > 0 || def->mem.memory_slots > 0) {
+    if (virDomainDefHasMemoryHotplug(def)) {
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                        _("memory hotplug tunables <maxMemory> are not "
                          "supported by this hypervisor driver"));
@@ -7671,6 +7671,13 @@ virDomainParseMemoryLimit(const char *xpath,
 }
 
 
+bool
+virDomainDefHasMemoryHotplug(const virDomainDef *def)
+{
+    return def->mem.memory_slots > 0 || def->mem.max_memory > 0;
+}
+
+
 /**
  * virDomainDefGetMemoryInitial:
  * @def: domain definition
@@ -21537,7 +21544,7 @@ virDomainDefFormatInternal(virDomainDefPtr def,
         xmlIndentTreeOutput = oldIndentTreeOutput;
     }
 
-    if (def->mem.max_memory) {
+    if (virDomainDefHasMemoryHotplug(def)) {
         virBufferAsprintf(buf,
                           "<maxMemory slots='%u' unit='KiB'>%llu</maxMemory>\n",
                           def->mem.memory_slots, def->mem.max_memory);
index 8be390b7811a2b4ab3066e31b86067fe616909f3..cfd2600830fd3fc6c1a73f1434cdb7fde2c183db 100644 (file)
@@ -2324,6 +2324,7 @@ struct _virDomainDef {
 unsigned long long virDomainDefGetMemoryInitial(virDomainDefPtr def);
 void virDomainDefSetMemoryInitial(virDomainDefPtr def, unsigned long long size);
 unsigned long long virDomainDefGetMemoryActual(virDomainDefPtr def);
+bool virDomainDefHasMemoryHotplug(const virDomainDef *def);
 
 typedef enum {
     VIR_DOMAIN_KEY_WRAP_CIPHER_NAME_AES,
index 8c1f388146531ead708578efb54dd825a72a42ca..1a9242293aec219a4c5a22a155d0a4a795b4106d 100644 (file)
@@ -217,6 +217,7 @@ virDomainDefGetMemoryActual;
 virDomainDefGetMemoryInitial;
 virDomainDefGetSecurityLabelDef;
 virDomainDefHasDeviceAddress;
+virDomainDefHasMemoryHotplug;
 virDomainDefMaybeAddController;
 virDomainDefMaybeAddInput;
 virDomainDefNeedsPlacementAdvice;
index 25f57f2412424e7ae5aa115a6ee433ec20e49961..e1f199c225a8eebf305db583a71b86c281e6df8e 100644 (file)
@@ -9323,7 +9323,7 @@ qemuBuildCommandLine(virConnectPtr conn,
 
     virCommandAddArg(cmd, "-m");
 
-    if (def->mem.max_memory) {
+    if (virDomainDefHasMemoryHotplug(def)) {
         if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_PC_DIMM)) {
             virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                            _("memory hotplug isn't supported by this QEMU binary"));
index 2bc818e2f477be7667655cd3d8417adb252b2307..d7b66ab5136beb2687b77dd2a61a0965e88a0d6b 100644 (file)
@@ -1361,7 +1361,7 @@ qemuDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
     }
 
     if (dev->type == VIR_DOMAIN_DEVICE_MEMORY &&
-        def->mem.max_memory == 0) {
+        !virDomainDefHasMemoryHotplug(def)) {
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                        _("maxMemory has to be specified when using memory "
                          "devices "));
index 903612bb394d6b897b1acde58e02e8ea9691d12a..948ad3b6046bbad579b95cdb47d61d69943bebd5 100644 (file)
@@ -3000,10 +3000,9 @@ qemuMigrationBeginPhase(virQEMUDriverPtr driver,
         }
     }
 
-    if (vm->def->mem.max_memory ||
+    if (virDomainDefHasMemoryHotplug(vm->def) ||
         ((flags & VIR_MIGRATE_PERSIST_DEST) &&
-         vm->newDef &&
-         vm->newDef->mem.max_memory))
+         vm->newDef && virDomainDefHasMemoryHotplug(vm->newDef)))
         cookieFlags |= QEMU_MIGRATION_COOKIE_MEMORY_HOTPLUG;
 
     if (!(mig = qemuMigrationEatCookie(driver, vm, NULL, 0, 0)))