From 66fe31d12622cda48ea33005d2474ec8ed69a7b9 Mon Sep 17 00:00:00 2001 From: Dawid Zamirski Date: Mon, 9 Mar 2015 11:54:05 -0400 Subject: [PATCH] esx: esxNodeGetFreeMemory return info from host. Before this patch, when connected via vCenter, the free memory returned was from the resorcePool (usually a cluster). This is in conflict with e.g esxNodeGetInfo which always pulls info from the ESX host. Since libvirt ESX driver works primarily with ESX hosts, this patch changes esxNodeGetFreeMemory to pull that information from ESX host so it's consistent with behavior of esxNodeGetInfo. --- src/esx/esx_driver.c | 53 ++++++++++++++++---------------------------- 1 file changed, 19 insertions(+), 34 deletions(-) diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c index 179f44c351..bfc86958f1 100644 --- a/src/esx/esx_driver.c +++ b/src/esx/esx_driver.c @@ -3990,52 +3990,37 @@ static unsigned long long esxNodeGetFreeMemory(virConnectPtr conn) { unsigned long long result = 0; + unsigned long long usageBytes = 0; esxPrivate *priv = conn->privateData; esxVI_String *propertyNameList = NULL; - esxVI_ObjectContent *resourcePool = NULL; - esxVI_DynamicProperty *dynamicProperty = NULL; - esxVI_ResourcePoolResourceUsage *resourcePoolResourceUsage = NULL; + esxVI_ObjectContent *hostSystem = NULL; + esxVI_Int *memoryUsage = NULL; + esxVI_Long *memorySize = NULL; if (esxVI_EnsureSession(priv->primary) < 0) return 0; - /* Get memory usage of resource pool */ - if (esxVI_String_AppendValueToList(&propertyNameList, - "runtime.memory") < 0 || - esxVI_LookupObjectContentByType(priv->primary, - priv->primary->computeResource->resourcePool, - "ResourcePool", propertyNameList, - &resourcePool, - esxVI_Occurrence_RequiredItem) < 0) { + /* Get memory usage of host system */ + if (esxVI_String_AppendValueListToList(&propertyNameList, + "summary.quickStats.overallMemoryUsage\0" + "hardware.memorySize\0") < 0 || + esxVI_LookupHostSystemProperties(priv->primary, propertyNameList, + &hostSystem) < 0 || + esxVI_GetInt(hostSystem, "summary.quickStats.overallMemoryUsage", + &memoryUsage, esxVI_Occurrence_RequiredItem) < 0 || + esxVI_GetLong(hostSystem, "hardware.memorySize", &memorySize, + esxVI_Occurrence_RequiredItem) < 0) { goto cleanup; } - for (dynamicProperty = resourcePool->propSet; dynamicProperty; - dynamicProperty = dynamicProperty->_next) { - if (STREQ(dynamicProperty->name, "runtime.memory")) { - if (esxVI_ResourcePoolResourceUsage_CastFromAnyType - (dynamicProperty->val, &resourcePoolResourceUsage) < 0) { - goto cleanup; - } - - break; - } else { - VIR_WARN("Unexpected '%s' property", dynamicProperty->name); - } - } - - if (!resourcePoolResourceUsage) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Could not retrieve memory usage of resource pool")); - goto cleanup; - } - - result = resourcePoolResourceUsage->unreservedForVm->value; + usageBytes = (unsigned long long) (memoryUsage->value) * 1048576; + result = memorySize->value - usageBytes; cleanup: esxVI_String_Free(&propertyNameList); - esxVI_ObjectContent_Free(&resourcePool); - esxVI_ResourcePoolResourceUsage_Free(&resourcePoolResourceUsage); + esxVI_ObjectContent_Free(&hostSystem); + esxVI_Int_Free(&memoryUsage); + esxVI_Long_Free(&memorySize); return result; }