[libvirt] [PATCH] esx: Don't try to change max-memory of an active domain

Report an VIR_ERR_OPERATION_INVALID error in that case instead of letting the SOAP call fail with an VIR_ERR_INTERNAL_ERROR error. --- src/esx/esx_driver.c | 21 ++++++++++++++++++--- 1 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c index 26f029c..2799487 100644 --- a/src/esx/esx_driver.c +++ b/src/esx/esx_driver.c @@ -2027,7 +2027,9 @@ esxDomainSetMaxMemory(virDomainPtr domain, unsigned long memory) { int result = -1; esxPrivate *priv = domain->conn->privateData; + esxVI_String *propertyNameList = NULL; esxVI_ObjectContent *virtualMachine = NULL; + esxVI_VirtualMachinePowerState powerState; esxVI_VirtualMachineConfigSpec *spec = NULL; esxVI_ManagedObjectReference *task = NULL; esxVI_TaskInfoState taskInfoState; @@ -2037,10 +2039,22 @@ esxDomainSetMaxMemory(virDomainPtr domain, unsigned long memory) return -1; } - if (esxVI_LookupVirtualMachineByUuidAndPrepareForTask - (priv->primary, domain->uuid, NULL, &virtualMachine, + if (esxVI_String_AppendValueToList(&propertyNameList, + "runtime.powerState") < 0 || + esxVI_LookupVirtualMachineByUuidAndPrepareForTask + (priv->primary, domain->uuid, propertyNameList, &virtualMachine, priv->autoAnswer) < 0 || - esxVI_VirtualMachineConfigSpec_Alloc(&spec) < 0 || + esxVI_GetVirtualMachinePowerState(virtualMachine, &powerState) < 0) { + goto cleanup; + } + + if (powerState != esxVI_VirtualMachinePowerState_PoweredOff) { + ESX_ERROR(VIR_ERR_OPERATION_INVALID, "%s", + _("Domain is not powered off")); + goto cleanup; + } + + if (esxVI_VirtualMachineConfigSpec_Alloc(&spec) < 0 || esxVI_Long_Alloc(&spec->memoryMB) < 0) { goto cleanup; } @@ -2067,6 +2081,7 @@ esxDomainSetMaxMemory(virDomainPtr domain, unsigned long memory) result = 0; cleanup: + esxVI_String_Free(&propertyNameList); esxVI_ObjectContent_Free(&virtualMachine); esxVI_VirtualMachineConfigSpec_Free(&spec); esxVI_ManagedObjectReference_Free(&task); -- 1.7.0.4

On 01/27/2011 02:35 PM, Matthias Bolte wrote:
Report an VIR_ERR_OPERATION_INVALID error in that case instead of letting the SOAP call fail with an VIR_ERR_INTERNAL_ERROR error. --- src/esx/esx_driver.c | 21 ++++++++++++++++++--- 1 files changed, 18 insertions(+), 3 deletions(-)
ACK. -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org

On 28/01/2011, at 8:56 AM, Eric Blake wrote:
On 01/27/2011 02:35 PM, Matthias Bolte wrote:
Report an VIR_ERR_OPERATION_INVALID error in that case instead of letting the SOAP call fail with an VIR_ERR_INTERNAL_ERROR error. --- src/esx/esx_driver.c | 21 ++++++++++++++++++--- 1 files changed, 18 insertions(+), 3 deletions(-)
ACK.
Just as an interesting data point, the Xen driver also lets the max memory changing function be called on active domains. In the Xen case, it indicates an error, but actually changes the "running" configs' XML value, losing the change when the domain is then shut down. It means a user can bump up the "max" value for the running domain, then (without error) bump up the "currentMemory" value to match. It just doesn't actually do anything though... the domain doesn't seem to get the extra ram.

2011/1/27 Eric Blake <eblake@redhat.com>:
On 01/27/2011 02:35 PM, Matthias Bolte wrote:
Report an VIR_ERR_OPERATION_INVALID error in that case instead of letting the SOAP call fail with an VIR_ERR_INTERNAL_ERROR error. --- src/esx/esx_driver.c | 21 ++++++++++++++++++--- 1 files changed, 18 insertions(+), 3 deletions(-)
ACK.
Thanks, pushed. Matthias
participants (3)
-
Eric Blake
-
Justin Clift
-
Matthias Bolte