domain: Add helper to determine presence of memory baloon

This commit is contained in:
Peter Krempa 2016-04-06 15:02:31 +02:00
parent 33b9598c41
commit d6cb0d256a
7 changed files with 22 additions and 10 deletions

View File

@ -24316,3 +24316,17 @@ virDomainDefCheckDuplicateDiskInfo(virDomainDefPtr def)
return 0; return 0;
} }
/**
* virDomainDefHasMemballoon:
* @def: domain definition
*
* Returns true if domain has a memory ballooning device configured.
*/
bool
virDomainDefHasMemballoon(const virDomainDef *def)
{
return def->memballoon &&
def->memballoon->model != VIR_DOMAIN_MEMBALLOON_MODEL_NONE;
}

View File

@ -3160,4 +3160,6 @@ int virDomainDefGetVcpuPinInfoHelper(virDomainDefPtr def,
virBitmapPtr autoCpuset) virBitmapPtr autoCpuset)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(4) ATTRIBUTE_RETURN_CHECK; ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(4) ATTRIBUTE_RETURN_CHECK;
bool virDomainDefHasMemballoon(const virDomainDef *def) ATTRIBUTE_NONNULL(1);
#endif /* __DOMAIN_CONF_H */ #endif /* __DOMAIN_CONF_H */

View File

@ -225,6 +225,7 @@ virDomainDefGetVcpuPinInfoHelper;
virDomainDefGetVcpus; virDomainDefGetVcpus;
virDomainDefGetVcpusMax; virDomainDefGetVcpusMax;
virDomainDefHasDeviceAddress; virDomainDefHasDeviceAddress;
virDomainDefHasMemballoon;
virDomainDefHasMemoryHotplug; virDomainDefHasMemoryHotplug;
virDomainDefHasVcpusOffline; virDomainDefHasVcpusOffline;
virDomainDefMaybeAddController; virDomainDefMaybeAddController;

View File

@ -3481,8 +3481,7 @@ qemuBuildMemballoonCommandLine(virCommandPtr cmd,
virQEMUCapsGet(qemuCaps, QEMU_CAPS_VIRTIO_S390) && def->memballoon) virQEMUCapsGet(qemuCaps, QEMU_CAPS_VIRTIO_S390) && def->memballoon)
def->memballoon->model = VIR_DOMAIN_MEMBALLOON_MODEL_NONE; def->memballoon->model = VIR_DOMAIN_MEMBALLOON_MODEL_NONE;
if (!def->memballoon || if (!virDomainDefHasMemballoon(def))
def->memballoon->model == VIR_DOMAIN_MEMBALLOON_MODEL_NONE)
return 0; return 0;
if (def->memballoon->model != VIR_DOMAIN_MEMBALLOON_MODEL_VIRTIO) { if (def->memballoon->model != VIR_DOMAIN_MEMBALLOON_MODEL_VIRTIO) {

View File

@ -4534,8 +4534,7 @@ qemuDomainUpdateCurrentMemorySize(virQEMUDriverPtr driver,
/* if no balloning is available, the current size equals to the current /* if no balloning is available, the current size equals to the current
* full memory size */ * full memory size */
if (!vm->def->memballoon || if (!virDomainDefHasMemballoon(vm->def)) {
vm->def->memballoon->model == VIR_DOMAIN_MEMBALLOON_MODEL_NONE) {
vm->def->mem.cur_balloon = virDomainDefGetMemoryActual(vm->def); vm->def->mem.cur_balloon = virDomainDefGetMemoryActual(vm->def);
return 0; return 0;
} }

View File

@ -19099,8 +19099,7 @@ qemuDomainGetStatsBalloon(virQEMUDriverPtr driver ATTRIBUTE_UNUSED,
unsigned long long cur_balloon = 0; unsigned long long cur_balloon = 0;
int err = 0; int err = 0;
if (dom->def->memballoon && if (!virDomainDefHasMemballoon(dom->def)) {
dom->def->memballoon->model == VIR_DOMAIN_MEMBALLOON_MODEL_NONE) {
cur_balloon = virDomainDefGetMemoryActual(dom->def); cur_balloon = virDomainDefGetMemoryActual(dom->def);
} else if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BALLOON_EVENT)) { } else if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BALLOON_EVENT)) {
cur_balloon = dom->def->mem.cur_balloon; cur_balloon = dom->def->mem.cur_balloon;

View File

@ -2003,8 +2003,7 @@ qemuProcessRefreshBalloonState(virQEMUDriverPtr driver,
/* if no ballooning is available, the current size equals to the current /* if no ballooning is available, the current size equals to the current
* full memory size */ * full memory size */
if (!vm->def->memballoon || if (!virDomainDefHasMemballoon(vm->def)) {
vm->def->memballoon->model == VIR_DOMAIN_MEMBALLOON_MODEL_NONE) {
vm->def->mem.cur_balloon = virDomainDefGetMemoryActual(vm->def); vm->def->mem.cur_balloon = virDomainDefGetMemoryActual(vm->def);
return 0; return 0;
} }
@ -4456,8 +4455,7 @@ qemuProcessSetupBalloon(virQEMUDriverPtr driver,
int period; int period;
int ret = -1; int ret = -1;
if (!vm->def->memballoon || if (!virDomainDefHasMemballoon(vm->def))
vm->def->memballoon->model == VIR_DOMAIN_MEMBALLOON_MODEL_NONE)
return 0; return 0;
period = vm->def->memballoon->period; period = vm->def->memballoon->period;