[libvirt] [PATCH 0/2] esx: Make esxNodeGetFreeMemory always use ESX host.

This patch is intended to make ESX driver behave more consistently. When calling virNodeGetFreeMemory, it would return the free bytes from a cluster when using vpx connection or ESX host when using esx connection. However, virGetNodeInfo always returns info from ESX host (specifying ESX host is mandatory, even for vpx connections) so to make this consitent, these patches make virNodeGetFreeMemory always return info from the ESX host. Dawid Zamirski (2): esx: add esxVI_GetInt esx: esxNodeGetFreeMemory return info from host. src/esx/esx_driver.c | 53 ++++++++++++++++++-------------------------------- src/esx/esx_vi.c | 32 ++++++++++++++++++++++++++++++ src/esx/esx_vi.h | 3 +++ src/esx/esx_vi_types.c | 3 +++ src/esx/esx_vi_types.h | 1 + 5 files changed, 58 insertions(+), 34 deletions(-) -- 2.1.0

Modeled after the already existing esxVI_GetLong. --- src/esx/esx_vi.c | 32 ++++++++++++++++++++++++++++++++ src/esx/esx_vi.h | 3 +++ src/esx/esx_vi_types.c | 3 +++ src/esx/esx_vi_types.h | 1 + 4 files changed, 39 insertions(+) diff --git a/src/esx/esx_vi.c b/src/esx/esx_vi.c index bbec912..af822b1 100644 --- a/src/esx/esx_vi.c +++ b/src/esx/esx_vi.c @@ -2413,6 +2413,38 @@ esxVI_GetBoolean(esxVI_ObjectContent *objectContent, const char *propertyName, int +esxVI_GetInt(esxVI_ObjectContent *objectContent, const char *propertyName, + esxVI_Int **value, esxVI_Occurrence occurence) +{ + esxVI_DynamicProperty *dynamicProperty; + + if (!value || *value) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument")); + return -1; + } + + for (dynamicProperty = objectContent->propSet; dynamicProperty; + dynamicProperty = dynamicProperty->_next) { + if (STREQ(dynamicProperty->name, propertyName)) { + if (esxVI_Int_CastFromAnyType(dynamicProperty->val, value) < 0) + return -1; + + break; + } + } + + if (!(*value) && occurence == esxVI_Occurrence_RequiredItem) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Missing '%s' property"), propertyName); + return -1; + } + + return 0; +} + + + +int esxVI_GetLong(esxVI_ObjectContent *objectContent, const char *propertyName, esxVI_Long **value, esxVI_Occurrence occurrence) { diff --git a/src/esx/esx_vi.h b/src/esx/esx_vi.h index b7f0160..c41541e 100644 --- a/src/esx/esx_vi.h +++ b/src/esx/esx_vi.h @@ -338,6 +338,9 @@ int esxVI_GetBoolean(esxVI_ObjectContent *objectContent, const char *propertyName, esxVI_Boolean *value, esxVI_Occurrence occurrence); +int esxVI_GetInt(esxVI_ObjectContent *objectContent, const char *propertyName, + esxVI_Int **value, esxVI_Occurrence occurrence); + int esxVI_GetLong(esxVI_ObjectContent *objectContent, const char *propertyName, esxVI_Long **value, esxVI_Occurrence occurrence); diff --git a/src/esx/esx_vi_types.c b/src/esx/esx_vi_types.c index 1502467..6b558e5 100644 --- a/src/esx/esx_vi_types.c +++ b/src/esx/esx_vi_types.c @@ -1376,6 +1376,9 @@ ESX_VI__TEMPLATE__DEEP_COPY(Int, (*dest)->value = src->value; }) +/* esxVI_Int_CastFromAnyType */ +ESX_VI__TEMPLATE__CAST_FROM_ANY_TYPE(Int) + /* esxVI_Int_Serialize */ ESX_VI__TEMPLATE__SERIALIZE(Int, { diff --git a/src/esx/esx_vi_types.h b/src/esx/esx_vi_types.h index 34901d7..66a5705 100644 --- a/src/esx/esx_vi_types.h +++ b/src/esx/esx_vi_types.h @@ -241,6 +241,7 @@ void esxVI_Int_Free(esxVI_Int **numberList); int esxVI_Int_Validate(esxVI_Int *number); int esxVI_Int_AppendToList(esxVI_Int **numberList, esxVI_Int *number); int esxVI_Int_DeepCopy(esxVI_Int **dest, esxVI_Int *src); +int esxVI_Int_CastFromAnyType(esxVI_AnyType *anyType, esxVI_Int **number); int esxVI_Int_Serialize(esxVI_Int *number, const char *element, virBufferPtr output); int esxVI_Int_SerializeList(esxVI_Int *numberList, const char *element, -- 2.1.0

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 179f44c..bfc8695 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) { - 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")); + /* 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; } - 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; } -- 2.1.0

On 09.03.2015 16:54, Dawid Zamirski wrote:
This patch is intended to make ESX driver behave more consistently. When calling virNodeGetFreeMemory, it would return the free bytes from a cluster when using vpx connection or ESX host when using esx connection. However, virGetNodeInfo always returns info from ESX host (specifying ESX host is mandatory, even for vpx connections) so to make this consitent, these patches make virNodeGetFreeMemory always return info from the ESX host.
Dawid Zamirski (2): esx: add esxVI_GetInt esx: esxNodeGetFreeMemory return info from host.
src/esx/esx_driver.c | 53 ++++++++++++++++++-------------------------------- src/esx/esx_vi.c | 32 ++++++++++++++++++++++++++++++ src/esx/esx_vi.h | 3 +++ src/esx/esx_vi_types.c | 3 +++ src/esx/esx_vi_types.h | 1 + 5 files changed, 58 insertions(+), 34 deletions(-)
ACKed and pushed. Michal
participants (2)
-
Dawid Zamirski
-
Michal Privoznik