From 1891cad5420a3a1727177d1c762b23104c9ccc6d Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Mon, 14 Sep 2015 16:42:46 +0200 Subject: [PATCH] conf: Add helper to determine whether memory hotplug is enabled for a vm Add a simple helper so that the code doesn't have to rewrite the same condition multiple times. --- src/conf/domain_conf.c | 11 +++++++++-- src/conf/domain_conf.h | 1 + src/libvirt_private.syms | 1 + src/qemu/qemu_command.c | 2 +- src/qemu/qemu_domain.c | 2 +- src/qemu/qemu_migration.c | 5 ++--- 6 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index a3b3ccb0d7..32430d8458 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -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 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, "%llu\n", def->mem.memory_slots, def->mem.max_memory); diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 8be390b781..cfd2600830 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -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, diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 8c1f388146..1a9242293a 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -217,6 +217,7 @@ virDomainDefGetMemoryActual; virDomainDefGetMemoryInitial; virDomainDefGetSecurityLabelDef; virDomainDefHasDeviceAddress; +virDomainDefHasMemoryHotplug; virDomainDefMaybeAddController; virDomainDefMaybeAddInput; virDomainDefNeedsPlacementAdvice; diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 25f57f2412..e1f199c225 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -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")); diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 2bc818e2f4..d7b66ab513 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -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 ")); diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index 903612bb39..948ad3b604 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -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))) -- GitLab