}
if (esxVI_EnsureSession(priv->host) < 0) {
- goto failure;
+ return esxVI_Boolean_Undefined;
}
if (esxVI_String_AppendValueToList(&propertyNameList,
esxVI_LookupObjectContentByType(priv->host, priv->host->hostFolder,
"HostSystem", propertyNameList,
esxVI_Boolean_True, &hostSystem) < 0) {
- goto failure;
+ goto cleanup;
}
if (hostSystem == NULL) {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
_("Could not retrieve the HostSystem object"));
- goto failure;
+ goto cleanup;
}
for (dynamicProperty = hostSystem->propSet; dynamicProperty != NULL;
if (STREQ(dynamicProperty->name, "hardware.cpuFeature")) {
if (esxVI_HostCpuIdInfo_CastListFromAnyType
(dynamicProperty->val, &hostCpuIdInfoList) < 0) {
- goto failure;
+ goto cleanup;
}
for (hostCpuIdInfo = hostCpuIdInfoList; hostCpuIdInfo != NULL;
if (hostCpuIdInfo->level->value == -2147483647) { /* 0x80000001 */
if (esxVI_ParseHostCpuIdInfo(&parsedHostCpuIdInfo,
hostCpuIdInfo) < 0) {
- goto failure;
+ goto cleanup;
}
edxLongModeBit = parsedHostCpuIdInfo.edx[29];
"'hardware.cpuFeature[].edx' with value '%s' "
"has unexpected value '%c', expecting '0' "
"or '1'"), hostCpuIdInfo->edx, edxLongModeBit);
- goto failure;
+ goto cleanup;
}
break;
}
cleanup:
+ /*
+ * If we goto cleanup in case of an error then priv->supportsLongMode
+ * is still esxVI_Boolean_Undefined, therefore we don't need to set it.
+ */
esxVI_String_Free(&propertyNameList);
esxVI_ObjectContent_Free(&hostSystem);
esxVI_HostCpuIdInfo_Free(&hostCpuIdInfoList);
return priv->supportsLongMode;
-
- failure:
- priv->supportsLongMode = esxVI_Boolean_Undefined;
-
- goto cleanup;
}
static virDrvOpenStatus
esxOpen(virConnectPtr conn, virConnectAuthPtr auth, int flags ATTRIBUTE_UNUSED)
{
- virDrvOpenStatus result = VIR_DRV_OPEN_SUCCESS;
+ virDrvOpenStatus result = VIR_DRV_OPEN_ERROR;
esxPrivate *priv = NULL;
char hostIpAddress[NI_MAXHOST] = "";
char vCenterIpAddress[NI_MAXHOST] = "";
/* Allocate per-connection private data */
if (VIR_ALLOC(priv) < 0) {
virReportOOMError();
- goto failure;
+ goto cleanup;
}
priv->maxVcpus = -1;
if (esxUtil_ParseQuery(conn->uri, &priv->transport, &vCenter, &noVerify,
&autoAnswer) < 0) {
- goto failure;
+ goto cleanup;
}
if (autoAnswer) {
/* Login to host */
if (esxUtil_ResolveHostname(conn->uri->server, hostIpAddress,
NI_MAXHOST) < 0) {
- goto failure;
+ goto cleanup;
}
if (virAsprintf(&url, "%s://%s:%d/sdk", priv->transport,
conn->uri->server, conn->uri->port) < 0) {
virReportOOMError();
- goto failure;
+ goto cleanup;
}
if (conn->uri->user != NULL) {
if (username == NULL) {
virReportOOMError();
- goto failure;
+ goto cleanup;
}
} else {
username = virRequestUsername(auth, "root", conn->uri->server);
if (username == NULL) {
ESX_ERROR(VIR_ERR_AUTH_FAILED, "%s", _("Username request failed"));
- goto failure;
+ goto cleanup;
}
}
if (esxVI_Context_Alloc(&priv->host) < 0) {
- goto failure;
+ goto cleanup;
}
password = virRequestPassword(auth, username, conn->uri->server);
if (password == NULL) {
ESX_ERROR(VIR_ERR_AUTH_FAILED, "%s", _("Password request failed"));
- goto failure;
+ goto cleanup;
}
if (esxVI_Context_Connect(priv->host, url, hostIpAddress, username,
password, noVerify) < 0) {
- goto failure;
+ goto cleanup;
}
if (STRCASEEQ(conn->uri->scheme, "esx")) {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("%s is neither an ESX 3.5 host nor an ESX 4.0 host"),
conn->uri->server);
- goto failure;
+ goto cleanup;
}
} else { /* GSX */
if (priv->host->productVersion != esxVI_ProductVersion_GSX20) {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("%s isn't a GSX 2.0 host"), conn->uri->server);
- goto failure;
+ goto cleanup;
}
}
"summary.managementServerIp\0") < 0 ||
esxVI_LookupHostSystemByIp(priv->host, hostIpAddress, propertyNameList,
&hostSystem) < 0) {
- goto failure;
+ goto cleanup;
}
/* Warn if host is in maintenance mode */
if (STREQ(dynamicProperty->name, "runtime.inMaintenanceMode")) {
if (esxVI_AnyType_ExpectType(dynamicProperty->val,
esxVI_Type_Boolean) < 0) {
- goto failure;
+ goto cleanup;
}
if (dynamicProperty->val->boolean == esxVI_Boolean_True) {
if (STRNEQ(vCenter, "*") &&
esxUtil_ResolveHostname(vCenter, vCenterIpAddress,
NI_MAXHOST) < 0) {
- goto failure;
+ goto cleanup;
}
/* Lookup the vCenter from the ESX host */
if (STREQ(dynamicProperty->name, "summary.managementServerIp")) {
if (esxVI_AnyType_ExpectType(dynamicProperty->val,
esxVI_Type_String) < 0) {
- goto failure;
+ goto cleanup;
}
/* Get the vCenter IP address or verify the specified one */
if (vCenter == NULL) {
virReportOOMError();
- goto failure;
+ goto cleanup;
}
if (virStrcpyStatic(vCenterIpAddress,
_("vCenter IP address %s too big for "
"destination"),
dynamicProperty->val->string);
- goto failure;
+ goto cleanup;
}
} else if (STRNEQ(vCenterIpAddress,
dynamicProperty->val->string)) {
"(%s) has been specified"),
dynamicProperty->val->string, vCenter,
vCenterIpAddress);
- goto failure;
+ goto cleanup;
}
break;
if (STREQ(vCenter, "*")) {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
_("This host is not managed by a vCenter"));
- goto failure;
+ goto cleanup;
}
if (virAsprintf(&url, "%s://%s/sdk", priv->transport,
vCenter) < 0) {
virReportOOMError();
- goto failure;
+ goto cleanup;
}
if (esxVI_Context_Alloc(&priv->vCenter) < 0) {
- goto failure;
+ goto cleanup;
}
username = virRequestUsername(auth, "administrator", vCenter);
if (username == NULL) {
ESX_ERROR(VIR_ERR_AUTH_FAILED, "%s", _("Username request failed"));
- goto failure;
+ goto cleanup;
}
password = virRequestPassword(auth, username, vCenter);
if (password == NULL) {
ESX_ERROR(VIR_ERR_AUTH_FAILED, "%s", _("Password request failed"));
- goto failure;
+ goto cleanup;
}
if (esxVI_Context_Connect(priv->vCenter, url, vCenterIpAddress,
username, password, noVerify) < 0) {
- goto failure;
+ goto cleanup;
}
if (priv->vCenter->productVersion != esxVI_ProductVersion_VPX25 &&
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("%s is neither a vCenter 2.5 server nor a vCenter "
"4.0 server"), conn->uri->server);
- goto failure;
+ goto cleanup;
}
}
priv->caps = esxCapsInit(priv);
if (priv->caps == NULL) {
- goto failure;
+ goto cleanup;
}
- cleanup:
- VIR_FREE(url);
- VIR_FREE(vCenter);
- VIR_FREE(password);
- VIR_FREE(username);
- esxVI_String_Free(&propertyNameList);
- esxVI_ObjectContent_Free(&hostSystem);
-
- return result;
+ result = VIR_DRV_OPEN_SUCCESS;
- failure:
- if (priv != NULL) {
+ cleanup:
+ if (result == VIR_DRV_OPEN_ERROR && priv != NULL) {
esxVI_Context_Free(&priv->host);
esxVI_Context_Free(&priv->vCenter);
VIR_FREE(priv);
}
- result = VIR_DRV_OPEN_ERROR;
+ VIR_FREE(url);
+ VIR_FREE(vCenter);
+ VIR_FREE(password);
+ VIR_FREE(username);
+ esxVI_String_Free(&propertyNameList);
+ esxVI_ObjectContent_Free(&hostSystem);
- goto cleanup;
+ return result;
}
}
if (esxVI_EnsureSession(priv->host) < 0) {
- goto failure;
+ return esxVI_Boolean_Undefined;
}
if (esxVI_String_AppendValueToList(&propertyNameList,
esxVI_LookupObjectContentByType(priv->host, priv->host->hostFolder,
"HostSystem", propertyNameList,
esxVI_Boolean_True, &hostSystem) < 0) {
- goto failure;
+ goto cleanup;
}
if (hostSystem == NULL) {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
_("Could not retrieve the HostSystem object"));
- goto failure;
+ goto cleanup;
}
for (dynamicProperty = hostSystem->propSet; dynamicProperty != NULL;
if (STREQ(dynamicProperty->name, "capability.vmotionSupported")) {
if (esxVI_AnyType_ExpectType(dynamicProperty->val,
esxVI_Type_Boolean) < 0) {
- goto failure;
+ goto cleanup;
}
priv->supportsVMotion = dynamicProperty->val->boolean;
}
cleanup:
+ /*
+ * If we goto cleanup in case of an error then priv->supportsVMotion is
+ * still esxVI_Boolean_Undefined, therefore we don't need to set it.
+ */
esxVI_String_Free(&propertyNameList);
esxVI_ObjectContent_Free(&hostSystem);
return priv->supportsVMotion;
-
- failure:
- priv->supportsVMotion = esxVI_Boolean_Undefined;
-
- goto cleanup;
}
char *complete = NULL;
if (esxVI_EnsureSession(priv->host) < 0) {
- goto failure;
+ return NULL;
}
if (esxVI_String_AppendValueListToList
esxVI_LookupObjectContentByType(priv->host, priv->host->hostFolder,
"HostSystem", propertyNameList,
esxVI_Boolean_True, &hostSystem) < 0) {
- goto failure;
+ goto cleanup;
}
if (hostSystem == NULL) {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
_("Could not retrieve the HostSystem object"));
- goto failure;
+ goto cleanup;
}
for (dynamicProperty = hostSystem->propSet; dynamicProperty != NULL;
"config.network.dnsConfig.hostName")) {
if (esxVI_AnyType_ExpectType(dynamicProperty->val,
esxVI_Type_String) < 0) {
- goto failure;
+ goto cleanup;
}
hostName = dynamicProperty->val->string;
"config.network.dnsConfig.domainName")) {
if (esxVI_AnyType_ExpectType(dynamicProperty->val,
esxVI_Type_String) < 0) {
- goto failure;
+ goto cleanup;
}
domainName = dynamicProperty->val->string;
if (hostName == NULL || strlen(hostName) < 1) {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
_("Missing or empty 'hostName' property"));
- goto failure;
+ goto cleanup;
}
if (domainName == NULL || strlen(domainName) < 1) {
if (complete == NULL) {
virReportOOMError();
- goto failure;
+ goto cleanup;
}
} else {
if (virAsprintf(&complete, "%s.%s", hostName, domainName) < 0) {
virReportOOMError();
- goto failure;
+ goto cleanup;
}
}
cleanup:
+ /*
+ * If we goto cleanup in case of an error then complete is still NULL,
+ * either strdup returned NULL or virAsprintf failed. When virAsprintf
+ * fails it guarantees setting complete to NULL
+ */
esxVI_String_Free(&propertyNameList);
esxVI_ObjectContent_Free(&hostSystem);
return complete;
-
- failure:
- VIR_FREE(complete);
-
- goto cleanup;
}
static int
esxNodeGetInfo(virConnectPtr conn, virNodeInfoPtr nodeinfo)
{
- int result = 0;
+ int result = -1;
esxPrivate *priv = conn->privateData;
esxVI_String *propertyNameList = NULL;
esxVI_ObjectContent *hostSystem = NULL;
int32_t numaInfo_numNodes = 0;
char *ptr = NULL;
- memset(nodeinfo, 0, sizeof(virNodeInfo));
+ memset(nodeinfo, 0, sizeof (*nodeinfo));
if (esxVI_EnsureSession(priv->host) < 0) {
- goto failure;
+ return -1;
}
if (esxVI_String_AppendValueListToList(&propertyNameList,
esxVI_LookupObjectContentByType(priv->host, priv->host->hostFolder,
"HostSystem", propertyNameList,
esxVI_Boolean_True, &hostSystem) < 0) {
- goto failure;
+ goto cleanup;
}
if (hostSystem == NULL) {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
_("Could not retrieve the HostSystem object"));
- goto failure;
+ goto cleanup;
}
for (dynamicProperty = hostSystem->propSet; dynamicProperty != NULL;
if (STREQ(dynamicProperty->name, "hardware.cpuInfo.hz")) {
if (esxVI_AnyType_ExpectType(dynamicProperty->val,
esxVI_Type_Long) < 0) {
- goto failure;
+ goto cleanup;
}
cpuInfo_hz = dynamicProperty->val->int64;
"hardware.cpuInfo.numCpuCores")) {
if (esxVI_AnyType_ExpectType(dynamicProperty->val,
esxVI_Type_Short) < 0) {
- goto failure;
+ goto cleanup;
}
cpuInfo_numCpuCores = dynamicProperty->val->int16;
"hardware.cpuInfo.numCpuPackages")) {
if (esxVI_AnyType_ExpectType(dynamicProperty->val,
esxVI_Type_Short) < 0) {
- goto failure;
+ goto cleanup;
}
cpuInfo_numCpuPackages = dynamicProperty->val->int16;
"hardware.cpuInfo.numCpuThreads")) {
if (esxVI_AnyType_ExpectType(dynamicProperty->val,
esxVI_Type_Short) < 0) {
- goto failure;
+ goto cleanup;
}
cpuInfo_numCpuThreads = dynamicProperty->val->int16;
} else if (STREQ(dynamicProperty->name, "hardware.memorySize")) {
if (esxVI_AnyType_ExpectType(dynamicProperty->val,
esxVI_Type_Long) < 0) {
- goto failure;
+ goto cleanup;
}
memorySize = dynamicProperty->val->int64;
"hardware.numaInfo.numNodes")) {
if (esxVI_AnyType_ExpectType(dynamicProperty->val,
esxVI_Type_Int) < 0) {
- goto failure;
+ goto cleanup;
}
numaInfo_numNodes = dynamicProperty->val->int32;
"summary.hardware.cpuModel")) {
if (esxVI_AnyType_ExpectType(dynamicProperty->val,
esxVI_Type_String) < 0) {
- goto failure;
+ goto cleanup;
}
ptr = dynamicProperty->val->string;
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("CPU Model %s too long for destination"),
dynamicProperty->val->string);
- goto failure;
+ goto cleanup;
}
} else {
VIR_WARN("Unexpected '%s' property", dynamicProperty->name);
? cpuInfo_numCpuThreads / cpuInfo_numCpuCores
: 0;
+ result = 0;
+
cleanup:
esxVI_String_Free(&propertyNameList);
esxVI_ObjectContent_Free(&hostSystem);
return result;
-
- failure:
- result = -1;
-
- goto cleanup;
}
static int
esxListDomains(virConnectPtr conn, int *ids, int maxids)
{
+ bool success = false;
esxPrivate *priv = conn->privateData;
esxVI_ObjectContent *virtualMachineList = NULL;
esxVI_ObjectContent *virtualMachine = NULL;
}
if (esxVI_EnsureSession(priv->host) < 0) {
- goto failure;
+ return -1;
}
if (esxVI_String_AppendValueToList(&propertyNameList,
"VirtualMachine", propertyNameList,
esxVI_Boolean_True,
&virtualMachineList) < 0) {
- goto failure;
+ goto cleanup;
}
for (virtualMachine = virtualMachineList; virtualMachine != NULL;
virtualMachine = virtualMachine->_next) {
if (esxVI_GetVirtualMachinePowerState(virtualMachine,
&powerState) < 0) {
- goto failure;
+ goto cleanup;
}
if (powerState != esxVI_VirtualMachinePowerState_PoweredOn) {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Failed to parse positive integer from '%s'"),
virtualMachine->obj->value);
- goto failure;
+ goto cleanup;
}
count++;
}
}
+ success = true;
+
cleanup:
esxVI_String_Free(&propertyNameList);
esxVI_ObjectContent_Free(&virtualMachineList);
- return count;
-
- failure:
- count = -1;
-
- goto cleanup;
+ return success ? count : -1;
}
virDomainPtr domain = NULL;
if (esxVI_EnsureSession(priv->host) < 0) {
- goto failure;
+ return NULL;
}
if (esxVI_String_AppendValueListToList(&propertyNameList,
"VirtualMachine", propertyNameList,
esxVI_Boolean_True,
&virtualMachineList) < 0) {
- goto failure;
+ goto cleanup;
}
for (virtualMachine = virtualMachineList; virtualMachine != NULL;
virtualMachine = virtualMachine->_next) {
if (esxVI_GetVirtualMachinePowerState(virtualMachine,
&powerState) < 0) {
- goto failure;
+ goto cleanup;
}
/* Only running/suspended domains have an ID != -1 */
if (esxVI_GetVirtualMachineIdentity(virtualMachine,
&id_candidate, &name_candidate,
uuid_candidate) < 0) {
- goto failure;
+ goto cleanup;
}
if (id != id_candidate) {
domain = virGetDomain(conn, name_candidate, uuid_candidate);
if (domain == NULL) {
- goto failure;
+ goto cleanup;
}
domain->id = id;
VIR_FREE(name_candidate);
return domain;
-
- failure:
- domain = NULL;
-
- goto cleanup;
}
virDomainPtr domain = NULL;
if (esxVI_EnsureSession(priv->host) < 0) {
- goto failure;
+ return NULL;
}
if (esxVI_String_AppendValueListToList(&propertyNameList,
esxVI_Occurrence_RequiredItem) < 0 ||
esxVI_GetVirtualMachineIdentity(virtualMachine, &id, &name, NULL) < 0 ||
esxVI_GetVirtualMachinePowerState(virtualMachine, &powerState) < 0) {
- goto failure;
+ goto cleanup;
}
domain = virGetDomain(conn, name, uuid);
if (domain == NULL) {
- goto failure;
+ goto cleanup;
}
/* Only running/suspended virtual machines have an ID != -1 */
VIR_FREE(name);
return domain;
-
- failure:
- domain = NULL;
-
- goto cleanup;
}
virDomainPtr domain = NULL;
if (esxVI_EnsureSession(priv->host) < 0) {
- goto failure;
+ return NULL;
}
if (esxVI_String_AppendValueListToList(&propertyNameList,
esxVI_LookupVirtualMachineByName(priv->host, name, propertyNameList,
&virtualMachine,
esxVI_Occurrence_OptionalItem) < 0) {
- goto failure;
+ goto cleanup;
}
if (virtualMachine == NULL) {
ESX_ERROR(VIR_ERR_NO_DOMAIN, _("No domain with name '%s'"), name);
- goto failure;
+ goto cleanup;
}
- if (esxVI_GetVirtualMachineIdentity(virtualMachine, &id, NULL, uuid) < 0) {
- goto failure;
- }
-
- if (esxVI_GetVirtualMachinePowerState(virtualMachine,
- &powerState) < 0) {
- goto failure;
+ if (esxVI_GetVirtualMachineIdentity(virtualMachine, &id, NULL, uuid) < 0 ||
+ esxVI_GetVirtualMachinePowerState(virtualMachine, &powerState) < 0) {
+ goto cleanup;
}
domain = virGetDomain(conn, name, uuid);
if (domain == NULL) {
- goto failure;
+ goto cleanup;
}
/* Only running/suspended virtual machines have an ID != -1 */
esxVI_ObjectContent_Free(&virtualMachine);
return domain;
-
- failure:
- domain = NULL;
-
- goto cleanup;
}
static int
esxDomainSuspend(virDomainPtr domain)
{
- int result = 0;
+ int result = -1;
esxPrivate *priv = domain->conn->privateData;
esxVI_ObjectContent *virtualMachine = NULL;
esxVI_String *propertyNameList = NULL;
esxVI_TaskInfoState taskInfoState;
if (esxVI_EnsureSession(priv->host) < 0) {
- goto failure;
+ return -1;
}
if (esxVI_String_AppendValueToList(&propertyNameList,
(priv->host, domain->uuid, propertyNameList, &virtualMachine,
priv->autoAnswer) < 0 ||
esxVI_GetVirtualMachinePowerState(virtualMachine, &powerState) < 0) {
- goto failure;
+ goto cleanup;
}
if (powerState != esxVI_VirtualMachinePowerState_PoweredOn) {
ESX_ERROR(VIR_ERR_OPERATION_INVALID, "%s",
_("Domain is not powered on"));
- goto failure;
+ goto cleanup;
}
if (esxVI_SuspendVM_Task(priv->host, virtualMachine->obj, &task) < 0 ||
esxVI_WaitForTaskCompletion(priv->host, task, domain->uuid,
priv->autoAnswer, &taskInfoState) < 0) {
- goto failure;
+ goto cleanup;
}
if (taskInfoState != esxVI_TaskInfoState_Success) {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not suspend domain"));
- goto failure;
+ goto cleanup;
}
+ result = 0;
+
cleanup:
esxVI_ObjectContent_Free(&virtualMachine);
esxVI_String_Free(&propertyNameList);
esxVI_ManagedObjectReference_Free(&task);
return result;
-
- failure:
- result = -1;
-
- goto cleanup;
}
static int
esxDomainResume(virDomainPtr domain)
{
- int result = 0;
+ int result = -1;
esxPrivate *priv = domain->conn->privateData;
esxVI_ObjectContent *virtualMachine = NULL;
esxVI_String *propertyNameList = NULL;
esxVI_TaskInfoState taskInfoState;
if (esxVI_EnsureSession(priv->host) < 0) {
- goto failure;
+ return -1;
}
if (esxVI_String_AppendValueToList(&propertyNameList,
(priv->host, domain->uuid, propertyNameList, &virtualMachine,
priv->autoAnswer) < 0 ||
esxVI_GetVirtualMachinePowerState(virtualMachine, &powerState) < 0) {
- goto failure;
+ goto cleanup;
}
if (powerState != esxVI_VirtualMachinePowerState_Suspended) {
ESX_ERROR(VIR_ERR_OPERATION_INVALID, "%s", _("Domain is not suspended"));
- goto failure;
+ goto cleanup;
}
if (esxVI_PowerOnVM_Task(priv->host, virtualMachine->obj, NULL,
&task) < 0 ||
esxVI_WaitForTaskCompletion(priv->host, task, domain->uuid,
priv->autoAnswer, &taskInfoState) < 0) {
- goto failure;
+ goto cleanup;
}
if (taskInfoState != esxVI_TaskInfoState_Success) {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not resume domain"));
- goto failure;
+ goto cleanup;
}
+ result = 0;
+
cleanup:
esxVI_ObjectContent_Free(&virtualMachine);
esxVI_String_Free(&propertyNameList);
esxVI_ManagedObjectReference_Free(&task);
return result;
-
- failure:
- result = -1;
-
- goto cleanup;
}
static int
esxDomainShutdown(virDomainPtr domain)
{
- int result = 0;
+ int result = -1;
esxPrivate *priv = domain->conn->privateData;
esxVI_ObjectContent *virtualMachine = NULL;
esxVI_String *propertyNameList = NULL;
esxVI_VirtualMachinePowerState powerState;
if (esxVI_EnsureSession(priv->host) < 0) {
- goto failure;
+ return -1;
}
if (esxVI_String_AppendValueToList(&propertyNameList,
propertyNameList, &virtualMachine,
esxVI_Occurrence_RequiredItem) < 0 ||
esxVI_GetVirtualMachinePowerState(virtualMachine, &powerState) < 0) {
- goto failure;
+ goto cleanup;
}
if (powerState != esxVI_VirtualMachinePowerState_PoweredOn) {
ESX_ERROR(VIR_ERR_OPERATION_INVALID, "%s",
_("Domain is not powered on"));
- goto failure;
+ goto cleanup;
}
if (esxVI_ShutdownGuest(priv->host, virtualMachine->obj) < 0) {
- goto failure;
+ goto cleanup;
}
+ result = 0;
+
cleanup:
esxVI_ObjectContent_Free(&virtualMachine);
esxVI_String_Free(&propertyNameList);
return result;
-
- failure:
- result = -1;
-
- goto cleanup;
}
static int
esxDomainReboot(virDomainPtr domain, unsigned int flags ATTRIBUTE_UNUSED)
{
- int result = 0;
+ int result = -1;
esxPrivate *priv = domain->conn->privateData;
esxVI_ObjectContent *virtualMachine = NULL;
esxVI_String *propertyNameList = NULL;
esxVI_VirtualMachinePowerState powerState;
if (esxVI_EnsureSession(priv->host) < 0) {
- goto failure;
+ return -1;
}
if (esxVI_String_AppendValueToList(&propertyNameList,
propertyNameList, &virtualMachine,
esxVI_Occurrence_RequiredItem) < 0 ||
esxVI_GetVirtualMachinePowerState(virtualMachine, &powerState) < 0) {
- goto failure;
+ goto cleanup;
}
if (powerState != esxVI_VirtualMachinePowerState_PoweredOn) {
ESX_ERROR(VIR_ERR_OPERATION_INVALID, "%s",
_("Domain is not powered on"));
- goto failure;
+ goto cleanup;
}
if (esxVI_RebootGuest(priv->host, virtualMachine->obj) < 0) {
- goto failure;
+ goto cleanup;
}
+ result = 0;
+
cleanup:
esxVI_ObjectContent_Free(&virtualMachine);
esxVI_String_Free(&propertyNameList);
return result;
-
- failure:
- result = -1;
-
- goto cleanup;
}
static int
esxDomainDestroy(virDomainPtr domain)
{
- int result = 0;
+ int result = -1;
esxPrivate *priv = domain->conn->privateData;
esxVI_Context *ctx = NULL;
esxVI_ObjectContent *virtualMachine = NULL;
}
if (esxVI_EnsureSession(ctx) < 0) {
- goto failure;
+ return -1;
}
if (esxVI_String_AppendValueToList(&propertyNameList,
(ctx, domain->uuid, propertyNameList, &virtualMachine,
priv->autoAnswer) < 0 ||
esxVI_GetVirtualMachinePowerState(virtualMachine, &powerState) < 0) {
- goto failure;
+ goto cleanup;
}
if (powerState != esxVI_VirtualMachinePowerState_PoweredOn) {
ESX_ERROR(VIR_ERR_OPERATION_INVALID, "%s",
_("Domain is not powered on"));
- goto failure;
+ goto cleanup;
}
if (esxVI_PowerOffVM_Task(ctx, virtualMachine->obj, &task) < 0 ||
esxVI_WaitForTaskCompletion(ctx, task, domain->uuid, priv->autoAnswer,
&taskInfoState) < 0) {
- goto failure;
+ goto cleanup;
}
if (taskInfoState != esxVI_TaskInfoState_Success) {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not destroy domain"));
- goto failure;
+ goto cleanup;
}
+ result = 0;
+
cleanup:
esxVI_ObjectContent_Free(&virtualMachine);
esxVI_String_Free(&propertyNameList);
esxVI_ManagedObjectReference_Free(&task);
return result;
-
- failure:
- result = -1;
-
- goto cleanup;
}
unsigned long memoryMB = 0;
if (esxVI_EnsureSession(priv->host) < 0) {
- goto failure;
+ return 0;
}
if (esxVI_String_AppendValueToList(&propertyNameList,
esxVI_LookupVirtualMachineByUuid(priv->host, domain->uuid,
propertyNameList, &virtualMachine,
esxVI_Occurrence_RequiredItem) < 0) {
- goto failure;
+ goto cleanup;
}
for (dynamicProperty = virtualMachine->propSet; dynamicProperty != NULL;
if (STREQ(dynamicProperty->name, "config.hardware.memoryMB")) {
if (esxVI_AnyType_ExpectType(dynamicProperty->val,
esxVI_Type_Int) < 0) {
- goto failure;
+ goto cleanup;
}
if (dynamicProperty->val->int32 < 0) {
esxVI_ObjectContent_Free(&virtualMachine);
return memoryMB * 1024; /* Scale from megabyte to kilobyte */
-
- failure:
- memoryMB = 0;
-
- goto cleanup;
}
static int
esxDomainSetMaxMemory(virDomainPtr domain, unsigned long memory)
{
- int result = 0;
+ int result = -1;
esxPrivate *priv = domain->conn->privateData;
esxVI_ObjectContent *virtualMachine = NULL;
esxVI_VirtualMachineConfigSpec *spec = NULL;
esxVI_TaskInfoState taskInfoState;
if (esxVI_EnsureSession(priv->host) < 0) {
- goto failure;
+ return -1;
}
if (esxVI_LookupVirtualMachineByUuidAndPrepareForTask
priv->autoAnswer) < 0 ||
esxVI_VirtualMachineConfigSpec_Alloc(&spec) < 0 ||
esxVI_Long_Alloc(&spec->memoryMB) < 0) {
- goto failure;
+ goto cleanup;
}
spec->memoryMB->value =
&task) < 0 ||
esxVI_WaitForTaskCompletion(priv->host, task, domain->uuid,
priv->autoAnswer, &taskInfoState) < 0) {
- goto failure;
+ goto cleanup;
}
if (taskInfoState != esxVI_TaskInfoState_Success) {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Could not set max-memory to %lu kilobytes"), memory);
- goto failure;
+ goto cleanup;
}
+ result = 0;
+
cleanup:
esxVI_ObjectContent_Free(&virtualMachine);
esxVI_VirtualMachineConfigSpec_Free(&spec);
esxVI_ManagedObjectReference_Free(&task);
return result;
-
- failure:
- result = -1;
-
- goto cleanup;
}
static int
esxDomainSetMemory(virDomainPtr domain, unsigned long memory)
{
- int result = 0;
+ int result = -1;
esxPrivate *priv = domain->conn->privateData;
esxVI_ObjectContent *virtualMachine = NULL;
esxVI_VirtualMachineConfigSpec *spec = NULL;
esxVI_TaskInfoState taskInfoState;
if (esxVI_EnsureSession(priv->host) < 0) {
- goto failure;
+ return -1;
}
if (esxVI_LookupVirtualMachineByUuidAndPrepareForTask
esxVI_VirtualMachineConfigSpec_Alloc(&spec) < 0 ||
esxVI_ResourceAllocationInfo_Alloc(&spec->memoryAllocation) < 0 ||
esxVI_Long_Alloc(&spec->memoryAllocation->limit) < 0) {
- goto failure;
+ goto cleanup;
}
spec->memoryAllocation->limit->value =
&task) < 0 ||
esxVI_WaitForTaskCompletion(priv->host, task, domain->uuid,
priv->autoAnswer, &taskInfoState) < 0) {
- goto failure;
+ goto cleanup;
}
if (taskInfoState != esxVI_TaskInfoState_Success) {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Could not set memory to %lu kilobytes"), memory);
- goto failure;
+ goto cleanup;
}
+ result = 0;
+
cleanup:
esxVI_ObjectContent_Free(&virtualMachine);
esxVI_VirtualMachineConfigSpec_Free(&spec);
esxVI_ManagedObjectReference_Free(&task);
return result;
-
- failure:
- result = -1;
-
- goto cleanup;
}
static int
esxDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info)
{
- int result = 0;
+ int result = -1;
esxPrivate *priv = domain->conn->privateData;
esxVI_String *propertyNameList = NULL;
esxVI_ObjectContent *virtualMachine = NULL;
esxVI_PerfMetricIntSeries *perfMetricIntSeries = NULL;
esxVI_Long *value = NULL;
+ memset(info, 0, sizeof (*info));
+
if (esxVI_EnsureSession(priv->host) < 0) {
- goto failure;
+ return -1;
}
if (esxVI_String_AppendValueListToList(&propertyNameList,
esxVI_LookupVirtualMachineByUuid(priv->host, domain->uuid,
propertyNameList, &virtualMachine,
esxVI_Occurrence_RequiredItem) < 0) {
- goto failure;
+ goto cleanup;
}
info->state = VIR_DOMAIN_NOSTATE;
- info->maxMem = 0;
- info->memory = 0;
- info->nrVirtCpu = 0;
- info->cpuTime = 0; /* FIXME */
for (dynamicProperty = virtualMachine->propSet; dynamicProperty != NULL;
dynamicProperty = dynamicProperty->_next) {
if (STREQ(dynamicProperty->name, "runtime.powerState")) {
if (esxVI_VirtualMachinePowerState_CastFromAnyType
(dynamicProperty->val, &powerState) < 0) {
- goto failure;
+ goto cleanup;
}
info->state = esxVI_VirtualMachinePowerState_ConvertToLibvirt
} else if (STREQ(dynamicProperty->name, "config.hardware.memoryMB")) {
if (esxVI_AnyType_ExpectType(dynamicProperty->val,
esxVI_Type_Int) < 0) {
- goto failure;
+ goto cleanup;
}
info->maxMem = dynamicProperty->val->int32 * 1024; /* Scale from megabyte to kilobyte */
} else if (STREQ(dynamicProperty->name, "config.hardware.numCPU")) {
if (esxVI_AnyType_ExpectType(dynamicProperty->val,
esxVI_Type_Int) < 0) {
- goto failure;
+ goto cleanup;
}
info->nrVirtCpu = dynamicProperty->val->int32;
"config.memoryAllocation.limit")) {
if (esxVI_AnyType_ExpectType(dynamicProperty->val,
esxVI_Type_Long) < 0) {
- goto failure;
+ goto cleanup;
}
memory_limit = dynamicProperty->val->int64;
/* Verify the cached 'used CPU time' performance counter ID */
if (info->state == VIR_DOMAIN_RUNNING && priv->usedCpuTimeCounterId >= 0) {
if (esxVI_Int_Alloc(&counterId) < 0) {
- goto failure;
+ goto cleanup;
}
counterId->value = priv->usedCpuTimeCounterId;
if (esxVI_Int_AppendToList(&counterIdList, counterId) < 0) {
- goto failure;
+ goto cleanup;
}
if (esxVI_QueryPerfCounter(priv->host, counterIdList,
&perfCounterInfo) < 0) {
- goto failure;
+ goto cleanup;
}
if (STRNEQ(perfCounterInfo->groupInfo->key, "cpu") ||
if (esxVI_QueryAvailablePerfMetric(priv->host, virtualMachine->obj,
NULL, NULL, NULL,
&perfMetricIdList) < 0) {
- goto failure;
+ goto cleanup;
}
for (perfMetricId = perfMetricIdList; perfMetricId != NULL;
if (esxVI_Int_DeepCopy(&counterId, perfMetricId->counterId) < 0 ||
esxVI_Int_AppendToList(&counterIdList, counterId) < 0) {
- goto failure;
+ goto cleanup;
}
}
if (esxVI_QueryPerfCounter(priv->host, counterIdList,
&perfCounterInfoList) < 0) {
- goto failure;
+ goto cleanup;
}
for (perfCounterInfo = perfCounterInfoList; perfCounterInfo != NULL;
esxVI_Int_Alloc(&querySpec->maxSample) < 0 ||
esxVI_PerfMetricId_Alloc(&querySpec->metricId) < 0 ||
esxVI_Int_Alloc(&querySpec->metricId->counterId) < 0) {
- goto failure;
+ goto cleanup;
}
querySpec->entity = virtualMachine->obj;
querySpec->entity = NULL;
querySpec->metricId->instance = NULL;
querySpec->format = NULL;
- goto failure;
+ goto cleanup;
}
for (perfEntityMetricBase = perfEntityMetricBaseList;
querySpec->format = NULL;
VIR_DEBUG("usedCpuTimeCounterId %d END", priv->usedCpuTimeCounterId);
+
+ /*
+ * FIXME: Cannot map between realtive used-cpu-time and absolute
+ * info->cpuTime
+ */
}
+ result = 0;
+
cleanup:
esxVI_String_Free(&propertyNameList);
esxVI_ObjectContent_Free(&virtualMachine);
esxVI_PerfEntityMetricBase_Free(&perfEntityMetricBaseList);
return result;
-
- failure:
- result = -1;
-
- goto cleanup;
}
static int
esxDomainSetVcpus(virDomainPtr domain, unsigned int nvcpus)
{
- int result = 0;
+ int result = -1;
esxPrivate *priv = domain->conn->privateData;
int maxVcpus;
esxVI_ObjectContent *virtualMachine = NULL;
if (nvcpus < 1) {
ESX_ERROR(VIR_ERR_INVALID_ARG, "%s",
_("Requested number of virtual CPUs must at least be 1"));
- goto failure;
+ return -1;
}
if (esxVI_EnsureSession(priv->host) < 0) {
- goto failure;
+ return -1;
}
maxVcpus = esxDomainGetMaxVcpus(domain);
if (maxVcpus < 0) {
- goto failure;
+ return -1;
}
if (nvcpus > maxVcpus) {
_("Requested number of virtual CPUs is greater than max "
"allowable number of virtual CPUs for the domain: %d > %d"),
nvcpus, maxVcpus);
- goto failure;
+ return -1;
}
if (esxVI_LookupVirtualMachineByUuidAndPrepareForTask
priv->autoAnswer) < 0 ||
esxVI_VirtualMachineConfigSpec_Alloc(&spec) < 0 ||
esxVI_Int_Alloc(&spec->numCPUs) < 0) {
- goto failure;
+ goto cleanup;
}
spec->numCPUs->value = nvcpus;
&task) < 0 ||
esxVI_WaitForTaskCompletion(priv->host, task, domain->uuid,
priv->autoAnswer, &taskInfoState) < 0) {
- goto failure;
+ goto cleanup;
}
if (taskInfoState != esxVI_TaskInfoState_Success) {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Could not set number of virtual CPUs to %d"), nvcpus);
- goto failure;
+ goto cleanup;
}
+ result = 0;
+
cleanup:
esxVI_ObjectContent_Free(&virtualMachine);
esxVI_VirtualMachineConfigSpec_Free(&spec);
esxVI_ManagedObjectReference_Free(&task);
return result;
-
- failure:
- result = -1;
-
- goto cleanup;
}
return priv->maxVcpus;
}
+ priv->maxVcpus = -1;
+
if (esxVI_EnsureSession(priv->host) < 0) {
- goto failure;
+ return -1;
}
if (esxVI_String_AppendValueToList(&propertyNameList,
esxVI_LookupObjectContentByType(priv->host, priv->host->hostFolder,
"HostSystem", propertyNameList,
esxVI_Boolean_True, &hostSystem) < 0) {
- goto failure;
+ goto cleanup;
}
if (hostSystem == NULL) {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
_("Could not retrieve the HostSystem object"));
- goto failure;
+ goto cleanup;
}
for (dynamicProperty = hostSystem->propSet; dynamicProperty != NULL;
if (STREQ(dynamicProperty->name, "capability.maxSupportedVcpus")) {
if (esxVI_AnyType_ExpectType(dynamicProperty->val,
esxVI_Type_Int) < 0) {
- goto failure;
+ goto cleanup;
}
priv->maxVcpus = dynamicProperty->val->int32;
esxVI_ObjectContent_Free(&hostSystem);
return priv->maxVcpus;
-
- failure:
- priv->maxVcpus = -1;
-
- goto cleanup;
}
char *xml = NULL;
if (esxVI_EnsureSession(priv->host) < 0) {
- goto failure;
+ return NULL;
}
if (esxVI_String_AppendValueToList(&propertyNameList,
esxVI_LookupVirtualMachineByUuid(priv->host, domain->uuid,
propertyNameList, &virtualMachine,
esxVI_Occurrence_RequiredItem) < 0) {
- goto failure;
+ goto cleanup;
}
for (dynamicProperty = virtualMachine->propSet; dynamicProperty != NULL;
if (STREQ(dynamicProperty->name, "config.files.vmPathName")) {
if (esxVI_AnyType_ExpectType(dynamicProperty->val,
esxVI_Type_String) < 0) {
- goto failure;
+ goto cleanup;
}
vmPathName = dynamicProperty->val->string;
if (esxUtil_ParseDatastoreRelatedPath(vmPathName, &datastoreName,
&directoryName, &fileName) < 0) {
- goto failure;
+ goto cleanup;
}
virBufferVSprintf(&buffer, "%s://%s:%d/folder/", priv->transport,
if (virBufferError(&buffer)) {
virReportOOMError();
- goto failure;
+ goto cleanup;
}
url = virBufferContentAndReset(&buffer);
if (esxVI_Context_DownloadFile(priv->host, url, &vmx) < 0) {
- goto failure;
+ goto cleanup;
}
def = esxVMX_ParseConfig(priv->host, vmx, datastoreName, directoryName,
}
cleanup:
+ if (url == NULL) {
+ virBufferFreeAndReset(&buffer);
+ }
+
esxVI_String_Free(&propertyNameList);
esxVI_ObjectContent_Free(&virtualMachine);
VIR_FREE(datastoreName);
virDomainDefFree(def);
return xml;
-
- failure:
- virBufferFreeAndReset(&buffer);
- VIR_FREE(xml);
-
- goto cleanup;
}
static int
esxListDefinedDomains(virConnectPtr conn, char **const names, int maxnames)
{
+ bool success = false;
esxPrivate *priv = conn->privateData;
esxVI_String *propertyNameList = NULL;
esxVI_ObjectContent *virtualMachineList = NULL;
}
if (esxVI_EnsureSession(priv->host) < 0) {
- goto failure;
+ return -1;
}
if (esxVI_String_AppendValueListToList(&propertyNameList,
"VirtualMachine", propertyNameList,
esxVI_Boolean_True,
&virtualMachineList) < 0) {
- goto failure;
+ goto cleanup;
}
for (virtualMachine = virtualMachineList; virtualMachine != NULL;
virtualMachine = virtualMachine->_next) {
if (esxVI_GetVirtualMachinePowerState(virtualMachine,
&powerState) < 0) {
- goto failure;
+ goto cleanup;
}
if (powerState == esxVI_VirtualMachinePowerState_PoweredOn) {
if (STREQ(dynamicProperty->name, "name")) {
if (esxVI_AnyType_ExpectType(dynamicProperty->val,
esxVI_Type_String) < 0) {
- goto failure;
+ goto cleanup;
}
names[count] = strdup(dynamicProperty->val->string);
if (names[count] == NULL) {
virReportOOMError();
- goto failure;
+ goto cleanup;
}
count++;
}
}
- cleanup:
- esxVI_String_Free(&propertyNameList);
- esxVI_ObjectContent_Free(&virtualMachineList);
+ success = true;
- return count;
+ cleanup:
+ if (! success) {
+ for (i = 0; i < count; ++i) {
+ VIR_FREE(names[i]);
+ }
- failure:
- for (i = 0; i < count; ++i) {
- VIR_FREE(names[i]);
+ count = -1;
}
- count = -1;
+ esxVI_String_Free(&propertyNameList);
+ esxVI_ObjectContent_Free(&virtualMachineList);
- goto cleanup;
+ return count;
}
static int
esxDomainCreate(virDomainPtr domain)
{
- int result = 0;
+ int result = -1;
esxPrivate *priv = domain->conn->privateData;
esxVI_ObjectContent *virtualMachine = NULL;
esxVI_String *propertyNameList = NULL;
esxVI_TaskInfoState taskInfoState;
if (esxVI_EnsureSession(priv->host) < 0) {
- goto failure;
+ return -1;
}
if (esxVI_String_AppendValueToList(&propertyNameList,
priv->autoAnswer) < 0 ||
esxVI_GetVirtualMachinePowerState(virtualMachine,
&powerState) < 0) {
- goto failure;
+ goto cleanup;
}
if (powerState != esxVI_VirtualMachinePowerState_PoweredOff) {
ESX_ERROR(VIR_ERR_OPERATION_INVALID, "%s",
_("Domain is not powered off"));
- goto failure;
+ goto cleanup;
}
if (esxVI_PowerOnVM_Task(priv->host, virtualMachine->obj, NULL,
&task) < 0 ||
esxVI_WaitForTaskCompletion(priv->host, task, domain->uuid,
priv->autoAnswer, &taskInfoState) < 0) {
- goto failure;
+ goto cleanup;
}
if (taskInfoState != esxVI_TaskInfoState_Success) {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not start domain"));
- goto failure;
+ goto cleanup;
}
+ result = 0;
+
cleanup:
esxVI_ObjectContent_Free(&virtualMachine);
esxVI_String_Free(&propertyNameList);
esxVI_ManagedObjectReference_Free(&task);
return result;
-
- failure:
- result = -1;
-
- goto cleanup;
}
virDomainPtr domain = NULL;
if (esxVI_EnsureSession(priv->host) < 0) {
- goto failure;
+ return NULL;
}
/* Parse domain XML */
VIR_DOMAIN_XML_INACTIVE);
if (def == NULL) {
- goto failure;
+ return NULL;
}
/* Check if an existing domain should be edited */
if (esxVI_LookupVirtualMachineByUuid(priv->host, def->uuid, NULL,
&virtualMachine,
esxVI_Occurrence_OptionalItem) < 0) {
- goto failure;
+ goto cleanup;
}
if (virtualMachine != NULL) {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
_("Domain already exists, editing existing domains is not "
"supported yet"));
- goto failure;
+ goto cleanup;
}
/* Build VMX from domain XML */
vmx = esxVMX_FormatConfig(priv->host, def, priv->host->productVersion);
if (vmx == NULL) {
- goto failure;
+ goto cleanup;
}
/*
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
_("Domain XML doesn't contain any disks, cannot deduce "
"datastore and path for VMX file"));
- goto failure;
+ goto cleanup;
}
for (i = 0; i < def->ndisks; ++i) {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
_("Domain XML doesn't contain any file-based harddisks, "
"cannot deduce datastore and path for VMX file"));
- goto failure;
+ goto cleanup;
}
if (disk->src == NULL) {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
_("First file-based harddisk has no source, cannot deduce "
"datastore and path for VMX file"));
- goto failure;
+ goto cleanup;
}
if (esxUtil_ParseDatastoreRelatedPath(disk->src, &datastoreName,
&directoryName, &fileName) < 0) {
- goto failure;
+ goto cleanup;
}
if (! virFileHasSuffix(fileName, ".vmdk")) {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Expecting source '%s' of first file-based harddisk to "
"be a VMDK image"), disk->src);
- goto failure;
+ goto cleanup;
}
virBufferVSprintf(&buffer, "%s://%s:%d/folder/", priv->transport,
if (virBufferError(&buffer)) {
virReportOOMError();
- goto failure;
+ goto cleanup;
}
url = virBufferContentAndReset(&buffer);
if (virAsprintf(&datastoreRelatedPath, "[%s] %s/%s.vmx", datastoreName,
directoryName, def->name) < 0) {
virReportOOMError();
- goto failure;
+ goto cleanup;
}
} else {
if (virAsprintf(&datastoreRelatedPath, "[%s] %s.vmx", datastoreName,
def->name) < 0) {
virReportOOMError();
- goto failure;
+ goto cleanup;
}
}
if (esxVI_String_AppendValueToList(&propertyNameList, "parent") < 0 ||
esxVI_LookupHostSystemByIp(priv->host, priv->host->ipAddress,
propertyNameList, &hostSystem) < 0) {
- goto failure;
+ goto cleanup;
}
if (esxVI_LookupResourcePoolByHostSystem(priv->host, hostSystem,
&resourcePool) < 0) {
- goto failure;
+ goto cleanup;
}
/* Check, if VMX file already exists */
/* Upload VMX file */
if (esxVI_Context_UploadFile(priv->host, url, vmx) < 0) {
- goto failure;
+ goto cleanup;
}
/* Register the domain */
resourcePool, hostSystem->obj, &task) < 0 ||
esxVI_WaitForTaskCompletion(priv->host, task, def->uuid,
priv->autoAnswer, &taskInfoState) < 0) {
- goto failure;
+ goto cleanup;
}
if (taskInfoState != esxVI_TaskInfoState_Success) {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not define domain"));
- goto failure;
+ goto cleanup;
}
domain = virGetDomain(conn, def->name, def->uuid);
/* FIXME: Add proper rollback in case of an error */
cleanup:
+ if (url == NULL) {
+ virBufferFreeAndReset(&buffer);
+ }
+
virDomainDefFree(def);
VIR_FREE(vmx);
VIR_FREE(datastoreName);
esxVI_ManagedObjectReference_Free(&task);
return domain;
-
- failure:
- virBufferFreeAndReset(&buffer);
-
- domain = NULL;
-
- goto cleanup;
}
static int
esxDomainUndefine(virDomainPtr domain)
{
- int result = 0;
+ int result = -1;
esxPrivate *priv = domain->conn->privateData;
esxVI_Context *ctx = NULL;
esxVI_ObjectContent *virtualMachine = NULL;
}
if (esxVI_EnsureSession(ctx) < 0) {
- goto failure;
+ return -1;
}
if (esxVI_String_AppendValueToList(&propertyNameList,
&virtualMachine,
esxVI_Occurrence_RequiredItem) < 0 ||
esxVI_GetVirtualMachinePowerState(virtualMachine, &powerState) < 0) {
- goto failure;
+ goto cleanup;
}
if (powerState != esxVI_VirtualMachinePowerState_Suspended &&
powerState != esxVI_VirtualMachinePowerState_PoweredOff) {
ESX_ERROR(VIR_ERR_OPERATION_INVALID, "%s",
_("Domain is not suspended or powered off"));
- goto failure;
+ goto cleanup;
}
if (esxVI_UnregisterVM(ctx, virtualMachine->obj) < 0) {
- goto failure;
+ goto cleanup;
}
+ result = 0;
+
cleanup:
esxVI_ObjectContent_Free(&virtualMachine);
esxVI_String_Free(&propertyNameList);
return result;
-
- failure:
- result = -1;
-
- goto cleanup;
}
esxDomainGetSchedulerParameters(virDomainPtr domain,
virSchedParameterPtr params, int *nparams)
{
- int result = 0;
+ int result = -1;
esxPrivate *priv = domain->conn->privateData;
esxVI_String *propertyNameList = NULL;
esxVI_ObjectContent *virtualMachine = NULL;
if (*nparams < 3) {
ESX_ERROR(VIR_ERR_INVALID_ARG, "%s",
_("Parameter array must have space for 3 items"));
- goto failure;
+ return -1;
}
if (esxVI_EnsureSession(priv->host) < 0) {
- goto failure;
+ return -1;
}
if (esxVI_String_AppendValueListToList(&propertyNameList,
esxVI_LookupVirtualMachineByUuid(priv->host, domain->uuid,
propertyNameList, &virtualMachine,
esxVI_Occurrence_RequiredItem) < 0) {
- goto failure;
+ goto cleanup;
}
for (dynamicProperty = virtualMachine->propSet;
if (esxVI_AnyType_ExpectType(dynamicProperty->val,
esxVI_Type_Long) < 0) {
- goto failure;
+ goto cleanup;
}
params[i].value.l = dynamicProperty->val->int64;
if (esxVI_AnyType_ExpectType(dynamicProperty->val,
esxVI_Type_Long) < 0) {
- goto failure;
+ goto cleanup;
}
params[i].value.l = dynamicProperty->val->int64;
if (esxVI_SharesInfo_CastFromAnyType(dynamicProperty->val,
&sharesInfo) < 0) {
- goto failure;
+ goto cleanup;
}
switch (sharesInfo->level) {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Shares level has unknown value %d"),
(int)sharesInfo->level);
- goto failure;
+ goto cleanup;
}
esxVI_SharesInfo_Free(&sharesInfo);
}
*nparams = i;
+ result = 0;
cleanup:
esxVI_String_Free(&propertyNameList);
esxVI_ObjectContent_Free(&virtualMachine);
return result;
-
- failure:
- result = -1;
-
- goto cleanup;
}
esxDomainSetSchedulerParameters(virDomainPtr domain,
virSchedParameterPtr params, int nparams)
{
- int result = 0;
+ int result = -1;
esxPrivate *priv = domain->conn->privateData;
esxVI_ObjectContent *virtualMachine = NULL;
esxVI_VirtualMachineConfigSpec *spec = NULL;
int i;
if (esxVI_EnsureSession(priv->host) < 0) {
- goto failure;
+ return -1;
}
if (esxVI_LookupVirtualMachineByUuidAndPrepareForTask
priv->autoAnswer) < 0 ||
esxVI_VirtualMachineConfigSpec_Alloc(&spec) < 0 ||
esxVI_ResourceAllocationInfo_Alloc(&spec->cpuAllocation) < 0) {
- goto failure;
+ goto cleanup;
}
for (i = 0; i < nparams; ++i) {
if (STREQ (params[i].field, "reservation") &&
params[i].type == VIR_DOMAIN_SCHED_FIELD_LLONG) {
if (esxVI_Long_Alloc(&spec->cpuAllocation->reservation) < 0) {
- goto failure;
+ goto cleanup;
}
if (params[i].value.l < 0) {
ESX_ERROR(VIR_ERR_INVALID_ARG,
_("Could not set reservation to %lld MHz, expecting "
"positive value"), params[i].value.l);
- goto failure;
+ goto cleanup;
}
spec->cpuAllocation->reservation->value = params[i].value.l;
} else if (STREQ (params[i].field, "limit") &&
params[i].type == VIR_DOMAIN_SCHED_FIELD_LLONG) {
if (esxVI_Long_Alloc(&spec->cpuAllocation->limit) < 0) {
- goto failure;
+ goto cleanup;
}
if (params[i].value.l < -1) {
_("Could not set limit to %lld MHz, expecting "
"positive value or -1 (unlimited)"),
params[i].value.l);
- goto failure;
+ goto cleanup;
}
spec->cpuAllocation->limit->value = params[i].value.l;
params[i].type == VIR_DOMAIN_SCHED_FIELD_INT) {
if (esxVI_SharesInfo_Alloc(&sharesInfo) < 0 ||
esxVI_Int_Alloc(&sharesInfo->shares) < 0) {
- goto failure;
+ goto cleanup;
}
spec->cpuAllocation->shares = sharesInfo;
_("Could not set shares to %d, expecting positive "
"value or -1 (low), -2 (normal) or -3 (high)"),
params[i].value.i);
- goto failure;
+ goto cleanup;
}
}
} else {
ESX_ERROR(VIR_ERR_INVALID_ARG, _("Unknown field '%s'"),
params[i].field);
- goto failure;
+ goto cleanup;
}
}
&task) < 0 ||
esxVI_WaitForTaskCompletion(priv->host, task, domain->uuid,
priv->autoAnswer, &taskInfoState) < 0) {
- goto failure;
+ goto cleanup;
}
if (taskInfoState != esxVI_TaskInfoState_Success) {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
_("Could not change scheduler parameters"));
- goto failure;
+ goto cleanup;
}
+ result = 0;
+
cleanup:
esxVI_ObjectContent_Free(&virtualMachine);
esxVI_VirtualMachineConfigSpec_Free(&spec);
esxVI_ManagedObjectReference_Free(&task);
return result;
-
- failure:
- result = -1;
-
- goto cleanup;
}
const char *dname ATTRIBUTE_UNUSED,
unsigned long resource ATTRIBUTE_UNUSED)
{
- int result = 0;
+ int result = -1;
char *transport = NULL;
if (uri_in == NULL) {
if (virAsprintf(uri_out, "%s://%s:%d/sdk", transport,
dconn->uri->server, dconn->uri->port) < 0) {
virReportOOMError();
- goto failure;
+ goto cleanup;
}
}
+ result = 0;
+
cleanup:
VIR_FREE(transport);
return result;
-
- failure:
- result = -1;
-
- goto cleanup;
}
const char *dname,
unsigned long bandwidth ATTRIBUTE_UNUSED)
{
- int result = 0;
+ int result = -1;
esxPrivate *priv = domain->conn->privateData;
xmlURIPtr xmlUri = NULL;
char hostIpAddress[NI_MAXHOST] = "";
if (priv->vCenter == NULL) {
ESX_ERROR(VIR_ERR_INVALID_ARG, "%s",
_("Migration not possible without a vCenter"));
- goto failure;
+ return -1;
}
if (dname != NULL) {
ESX_ERROR(VIR_ERR_INVALID_ARG, "%s",
_("Renaming domains on migration not supported"));
- goto failure;
+ return -1;
}
if (esxVI_EnsureSession(priv->vCenter) < 0) {
- goto failure;
+ return -1;
}
/* Parse the destination URI and resolve the hostname */
if (xmlUri == NULL) {
virReportOOMError();
- goto failure;
+ return -1;
}
if (esxUtil_ResolveHostname(xmlUri->server, hostIpAddress,
NI_MAXHOST) < 0) {
- goto failure;
+ goto cleanup;
}
/* Lookup VirtualMachine, HostSystem and ResourcePool */
esxVI_String_AppendValueToList(&propertyNameList, "parent") < 0 ||
esxVI_LookupHostSystemByIp(priv->vCenter, hostIpAddress,
propertyNameList, &hostSystem) < 0) {
- goto failure;
+ goto cleanup;
}
if (esxVI_LookupResourcePoolByHostSystem(priv->vCenter, hostSystem,
&resourcePool) < 0) {
- goto failure;
+ goto cleanup;
}
/* Validate the purposed migration */
esxVI_VirtualMachinePowerState_Undefined,
NULL, resourcePool, hostSystem->obj,
&eventList) < 0) {
- goto failure;
+ goto cleanup;
}
if (eventList != NULL) {
"problem"));
}
- goto failure;
+ goto cleanup;
}
/* Perform the purposed migration */
&task) < 0 ||
esxVI_WaitForTaskCompletion(priv->vCenter, task, domain->uuid,
priv->autoAnswer, &taskInfoState) < 0) {
- goto failure;
+ goto cleanup;
}
if (taskInfoState != esxVI_TaskInfoState_Success) {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
_("Could not migrate domain, migration task finished with "
"an error"));
- goto failure;
+ goto cleanup;
}
+ result = 0;
+
cleanup:
xmlFreeURI(xmlUri);
esxVI_ObjectContent_Free(&virtualMachine);
esxVI_ManagedObjectReference_Free(&task);
return result;
-
- failure:
- result = -1;
-
- goto cleanup;
}
esxVI_ResourcePoolResourceUsage *resourcePoolResourceUsage = NULL;
if (esxVI_EnsureSession(priv->host) < 0) {
- goto failure;
+ return 0;
}
/* Lookup host system with its resource pool */
if (esxVI_String_AppendValueToList(&propertyNameList, "parent") < 0 ||
esxVI_LookupHostSystemByIp(priv->host, priv->host->ipAddress,
propertyNameList, &hostSystem) < 0) {
- goto failure;
+ goto cleanup;
}
if (esxVI_LookupResourcePoolByHostSystem(priv->host, hostSystem,
&managedObjectReference) < 0) {
- goto failure;
+ goto cleanup;
}
esxVI_String_Free(&propertyNameList);
"ResourcePool", propertyNameList,
esxVI_Boolean_False,
&resourcePool) < 0) {
- goto failure;
+ goto cleanup;
}
for (dynamicProperty = resourcePool->propSet; dynamicProperty != NULL;
if (STREQ(dynamicProperty->name, "runtime.memory")) {
if (esxVI_ResourcePoolResourceUsage_CastFromAnyType
(dynamicProperty->val, &resourcePoolResourceUsage) < 0) {
- goto failure;
+ goto cleanup;
}
break;
if (resourcePoolResourceUsage == NULL) {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
_("Could not retrieve memory usage of resource pool"));
- goto failure;
+ goto cleanup;
}
result = resourcePoolResourceUsage->unreservedForVm->value;
esxVI_ResourcePoolResourceUsage_Free(&resourcePoolResourceUsage);
return result;
-
- failure:
- result = 0;
-
- goto cleanup;
}
static int
esxDomainIsActive(virDomainPtr domain)
{
- int result = 0;
+ int result = -1;
esxPrivate *priv = domain->conn->privateData;
esxVI_ObjectContent *virtualMachine = NULL;
esxVI_String *propertyNameList = NULL;
esxVI_VirtualMachinePowerState powerState;
if (esxVI_EnsureSession(priv->host) < 0) {
- goto failure;
+ return -1;
}
if (esxVI_String_AppendValueToList(&propertyNameList,
propertyNameList, &virtualMachine,
esxVI_Occurrence_RequiredItem) < 0 ||
esxVI_GetVirtualMachinePowerState(virtualMachine, &powerState) < 0) {
- goto failure;
+ goto cleanup;
}
if (powerState != esxVI_VirtualMachinePowerState_PoweredOff) {
esxVI_String_Free(&propertyNameList);
return result;
-
- failure:
- result = -1;
-
- goto cleanup;
}
virCheckFlags(0, NULL);
if (esxVI_EnsureSession(priv->host) < 0) {
- goto failure;
+ return NULL;
}
def = virDomainSnapshotDefParseString(xmlDesc, 1);
if (def == NULL) {
- goto failure;
+ return NULL;
}
if (esxVI_LookupVirtualMachineByUuidAndPrepareForTask
esxVI_GetSnapshotTreeByName(rootSnapshotList, def->name,
&snapshotTree, &snapshotTreeParent,
esxVI_Occurrence_OptionalItem) < 0) {
- goto failure;
+ goto cleanup;
}
if (snapshotTree != NULL) {
ESX_ERROR(VIR_ERR_OPERATION_INVALID,
_("Snapshot '%s' already exists"), def->name);
- goto failure;
+ goto cleanup;
}
if (esxVI_CreateSnapshot_Task(priv->host, virtualMachine->obj,
esxVI_Boolean_False, &task) < 0 ||
esxVI_WaitForTaskCompletion(priv->host, task, domain->uuid,
priv->autoAnswer, &taskInfoState) < 0) {
- goto failure;
+ goto cleanup;
}
if (taskInfoState != esxVI_TaskInfoState_Success) {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not create snapshot"));
- goto failure;
+ goto cleanup;
}
snapshot = virGetDomainSnapshot(domain, def->name);
esxVI_ManagedObjectReference_Free(&task);
return snapshot;
-
- failure:
- domain = NULL;
-
- goto cleanup;
}
virCheckFlags(0, NULL);
- memset(&def, 0, sizeof (virDomainSnapshotDef));
+ memset(&def, 0, sizeof (def));
if (esxVI_EnsureSession(priv->host) < 0) {
- goto failure;
+ return NULL;
}
if (esxVI_LookupRootSnapshotTreeList(priv->host, snapshot->domain->uuid,
esxVI_GetSnapshotTreeByName(rootSnapshotList, snapshot->name,
&snapshotTree, &snapshotTreeParent,
esxVI_Occurrence_RequiredItem) < 0) {
- goto failure;
+ goto cleanup;
}
def.name = snapshot->name;
if (esxVI_DateTime_ConvertToCalendarTime(snapshotTree->createTime,
&def.creationTime) < 0) {
- goto failure;
+ goto cleanup;
}
def.state = esxVI_VirtualMachinePowerState_ConvertToLibvirt
esxVI_VirtualMachineSnapshotTree_Free(&rootSnapshotList);
return xml;
-
- failure:
- VIR_FREE(xml);
-
- goto cleanup;
}
static int
esxDomainSnapshotNum(virDomainPtr domain, unsigned int flags)
{
- int result = 0;
+ int count;
esxPrivate *priv = domain->conn->privateData;
esxVI_VirtualMachineSnapshotTree *rootSnapshotTreeList = NULL;
virCheckFlags(0, -1);
if (esxVI_EnsureSession(priv->host) < 0) {
- goto failure;
+ return -1;
}
if (esxVI_LookupRootSnapshotTreeList(priv->host, domain->uuid,
&rootSnapshotTreeList) < 0) {
- goto failure;
+ return -1;
}
- result = esxVI_GetNumberOfSnapshotTrees(rootSnapshotTreeList);
+ count = esxVI_GetNumberOfSnapshotTrees(rootSnapshotTreeList);
- cleanup:
esxVI_VirtualMachineSnapshotTree_Free(&rootSnapshotTreeList);
- return result;
-
- failure:
- result = -1;
-
- goto cleanup;
+ return count;
}
esxDomainSnapshotListNames(virDomainPtr domain, char **names, int nameslen,
unsigned int flags)
{
- int result = 0;
+ int result;
esxPrivate *priv = domain->conn->privateData;
esxVI_VirtualMachineSnapshotTree *rootSnapshotTreeList = NULL;
}
if (esxVI_EnsureSession(priv->host) < 0) {
- goto failure;
+ return -1;
}
if (esxVI_LookupRootSnapshotTreeList(priv->host, domain->uuid,
&rootSnapshotTreeList) < 0) {
- goto failure;
+ return -1;
}
result = esxVI_GetSnapshotTreeNames(rootSnapshotTreeList, names, nameslen);
- cleanup:
esxVI_VirtualMachineSnapshotTree_Free(&rootSnapshotTreeList);
return result;
-
- failure:
- result = -1;
-
- goto cleanup;
}
virCheckFlags(0, NULL);
if (esxVI_EnsureSession(priv->host) < 0) {
- goto cleanup;
+ return NULL;
}
if (esxVI_LookupRootSnapshotTreeList(priv->host, domain->uuid,
static int
esxDomainHasCurrentSnapshot(virDomainPtr domain, unsigned int flags)
{
- int result = 0;
esxPrivate *priv = domain->conn->privateData;
esxVI_VirtualMachineSnapshotTree *currentSnapshotTree = NULL;
virCheckFlags(0, -1);
if (esxVI_EnsureSession(priv->host) < 0) {
- goto failure;
+ return -1;
}
if (esxVI_LookupCurrentSnapshotTree(priv->host, domain->uuid,
¤tSnapshotTree,
esxVI_Occurrence_OptionalItem) < 0) {
- goto failure;
+ return -1;
}
if (currentSnapshotTree != NULL) {
- result = 1;
+ esxVI_VirtualMachineSnapshotTree_Free(¤tSnapshotTree);
+ return 1;
}
- cleanup:
- esxVI_VirtualMachineSnapshotTree_Free(¤tSnapshotTree);
-
- return result;
-
- failure:
- result = -1;
-
- goto cleanup;
+ return 0;
}
static virDomainSnapshotPtr
esxDomainSnapshotCurrent(virDomainPtr domain, unsigned int flags)
{
- virDomainSnapshotPtr snapshot = NULL;
esxPrivate *priv = domain->conn->privateData;
esxVI_VirtualMachineSnapshotTree *currentSnapshotTree = NULL;
+ virDomainSnapshotPtr snapshot = NULL;
virCheckFlags(0, NULL);
if (esxVI_EnsureSession(priv->host) < 0) {
- goto cleanup;
+ return NULL;
}
if (esxVI_LookupCurrentSnapshotTree(priv->host, domain->uuid,
¤tSnapshotTree,
esxVI_Occurrence_RequiredItem) < 0) {
- goto cleanup;
+ return NULL;
}
snapshot = virGetDomainSnapshot(domain, currentSnapshotTree->name);
- cleanup:
esxVI_VirtualMachineSnapshotTree_Free(¤tSnapshotTree);
return snapshot;
static int
esxDomainRevertToSnapshot(virDomainSnapshotPtr snapshot, unsigned int flags)
{
- int result = 0;
+ int result = -1;
esxPrivate *priv = snapshot->domain->conn->privateData;
esxVI_VirtualMachineSnapshotTree *rootSnapshotList = NULL;
esxVI_VirtualMachineSnapshotTree *snapshotTree = NULL;
virCheckFlags(0, -1);
if (esxVI_EnsureSession(priv->host) < 0) {
- goto failure;
+ return -1;
}
if (esxVI_LookupRootSnapshotTreeList(priv->host, snapshot->domain->uuid,
esxVI_GetSnapshotTreeByName(rootSnapshotList, snapshot->name,
&snapshotTree, &snapshotTreeParent,
esxVI_Occurrence_RequiredItem) < 0) {
- goto failure;
+ goto cleanup;
}
if (esxVI_RevertToSnapshot_Task(priv->host, snapshotTree->snapshot, NULL,
&task) < 0 ||
esxVI_WaitForTaskCompletion(priv->host, task, snapshot->domain->uuid,
priv->autoAnswer, &taskInfoState) < 0) {
- goto failure;
+ goto cleanup;
}
if (taskInfoState != esxVI_TaskInfoState_Success) {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Could not revert to snapshot '%s'"), snapshot->name);
- goto failure;
+ goto cleanup;
}
+ result = 0;
+
cleanup:
esxVI_VirtualMachineSnapshotTree_Free(&rootSnapshotList);
esxVI_ManagedObjectReference_Free(&task);
return result;
-
- failure:
- result = -1;
-
- goto cleanup;
}
static int
esxDomainSnapshotDelete(virDomainSnapshotPtr snapshot, unsigned int flags)
{
- int result = 0;
+ int result = -1;
esxPrivate *priv = snapshot->domain->conn->privateData;
esxVI_VirtualMachineSnapshotTree *rootSnapshotList = NULL;
esxVI_VirtualMachineSnapshotTree *snapshotTree = NULL;
virCheckFlags(VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN, -1);
if (esxVI_EnsureSession(priv->host) < 0) {
- goto failure;
+ return -1;
}
if (flags & VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN) {
esxVI_GetSnapshotTreeByName(rootSnapshotList, snapshot->name,
&snapshotTree, &snapshotTreeParent,
esxVI_Occurrence_RequiredItem) < 0) {
- goto failure;
+ goto cleanup;
}
if (esxVI_RemoveSnapshot_Task(priv->host, snapshotTree->snapshot,
removeChildren, &task) < 0 ||
esxVI_WaitForTaskCompletion(priv->host, task, snapshot->domain->uuid,
priv->autoAnswer, &taskInfoState) < 0) {
- goto failure;
+ goto cleanup;
}
if (taskInfoState != esxVI_TaskInfoState_Success) {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Could not delete snapshot '%s'"), snapshot->name);
- goto failure;
+ goto cleanup;
}
+ result = 0;
+
cleanup:
esxVI_VirtualMachineSnapshotTree_Free(&rootSnapshotList);
esxVI_ManagedObjectReference_Free(&task);
return result;
-
- failure:
- result = -1;
-
- goto cleanup;
}
result = 0;
cleanup:
- if (result < 0) {
- memset(info, 0, sizeof (*info));
- }
-
esxVI_String_Free(&propertyNameList);
esxVI_ObjectContent_Free(&datastore);
esxUtil_ParseQuery(xmlURIPtr uri, char **transport, char **vCenter,
int *noVerify, int *autoAnswer)
{
- int result = 0;
+ int result = -1;
int i;
struct qparam_set *queryParamSet = NULL;
struct qparam *queryParam = NULL;
#endif
if (queryParamSet == NULL) {
- goto failure;
+ return -1;
}
for (i = 0; i < queryParamSet->n; i++) {
if (*transport == NULL) {
virReportOOMError();
- goto failure;
+ goto cleanup;
}
if (STRNEQ(*transport, "http") && STRNEQ(*transport, "https")) {
ESX_ERROR(VIR_ERR_INVALID_ARG,
_("Query parameter 'transport' has unexpected value "
"'%s' (should be http|https)"), *transport);
- goto failure;
+ goto cleanup;
}
} else if (STRCASEEQ(queryParam->name, "vcenter")) {
if (vCenter == NULL) {
if (*vCenter == NULL) {
virReportOOMError();
- goto failure;
+ goto cleanup;
}
} else if (STRCASEEQ(queryParam->name, "no_verify")) {
if (noVerify == NULL) {
ESX_ERROR(VIR_ERR_INVALID_ARG,
_("Query parameter 'no_verify' has unexpected value "
"'%s' (should be 0 or 1)"), queryParam->value);
- goto failure;
+ goto cleanup;
}
} else if (STRCASEEQ(queryParam->name, "auto_answer")) {
if (autoAnswer == NULL) {
ESX_ERROR(VIR_ERR_INVALID_ARG,
_("Query parameter 'auto_answer' has unexpected "
"value '%s' (should be 0 or 1)"), queryParam->value);
- goto failure;
+ goto cleanup;
}
} else {
VIR_WARN("Ignoring unexpected query parameter '%s'",
if (*transport == NULL) {
virReportOOMError();
- goto failure;
+ goto cleanup;
}
}
- cleanup:
- if (queryParamSet != NULL) {
- free_qparam_set(queryParamSet);
- }
+ result = 0;
- return result;
+ cleanup:
+ if (result < 0) {
+ if (transport != NULL) {
+ VIR_FREE(*transport);
+ }
- failure:
- if (transport != NULL) {
- VIR_FREE(*transport);
+ if (vCenter != NULL) {
+ VIR_FREE(*vCenter);
+ }
}
- if (vCenter != NULL) {
- VIR_FREE(*vCenter);
+ if (queryParamSet != NULL) {
+ free_qparam_set(queryParamSet);
}
- result = -1;
-
- goto cleanup;
+ return result;
}
char **datastoreName,
char **directoryName, char **fileName)
{
- int result = 0;
+ int result = -1;
char *copyOfDatastoreRelatedPath = NULL;
char *tmp = NULL;
char *saveptr = NULL;
if (esxVI_String_DeepCopyValue(©OfDatastoreRelatedPath,
datastoreRelatedPath) < 0) {
- goto failure;
+ goto cleanup;
}
/* Expected format: '[<datastore>] <path>' */
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Datastore related path '%s' doesn't have expected format "
"'[<datastore>] <path>'"), datastoreRelatedPath);
- goto failure;
+ goto cleanup;
}
if (esxVI_String_DeepCopyValue(datastoreName,
preliminaryDatastoreName) < 0) {
- goto failure;
+ goto cleanup;
}
directoryAndFileName += strspn(directoryAndFileName, " ");
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Datastore related path '%s' doesn't reference a file"),
datastoreRelatedPath);
- goto failure;
+ goto cleanup;
}
if (esxVI_String_DeepCopyValue(directoryName,
directoryAndFileName) < 0 ||
esxVI_String_DeepCopyValue(fileName, separator) < 0) {
- goto failure;
+ goto cleanup;
}
} else {
if (esxVI_String_DeepCopyValue(fileName, directoryAndFileName) < 0) {
- goto failure;
+ goto cleanup;
}
}
+ result = 0;
+
cleanup:
+ if (result < 0) {
+ VIR_FREE(*datastoreName);
+ VIR_FREE(*directoryName);
+ VIR_FREE(*fileName);
+ }
+
VIR_FREE(copyOfDatastoreRelatedPath);
return result;
-
- failure:
- VIR_FREE(*datastoreName);
- VIR_FREE(*directoryName);
- VIR_FREE(*fileName);
-
- result = -1;
-
- goto cleanup;
}
struct addrinfo *result = NULL;
int errcode;
- memset(&hints, 0, sizeof(struct addrinfo));
+ memset(&hints, 0, sizeof (hints));
hints.ai_flags = AI_ADDRCONFIG;
hints.ai_family = AF_INET;
const char *ipAddress, const char *username,
const char *password, int noVerify)
{
- int result = 0;
+ int result = -1;
esxVI_String *propertyNameList = NULL;
esxVI_ObjectContent *datacenterList = NULL;
esxVI_DynamicProperty *dynamicProperty = NULL;
password == NULL || ctx->url != NULL || ctx->service != NULL ||
ctx->curl_handle != NULL || ctx->curl_headers != NULL) {
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
- goto failure;
+ return -1;
}
if (esxVI_String_DeepCopyValue(&ctx->url, url) < 0 ||
esxVI_String_DeepCopyValue(&ctx->ipAddress, ipAddress) < 0) {
- goto failure;
+ goto cleanup;
}
ctx->curl_handle = curl_easy_init();
if (ctx->curl_handle == NULL) {
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
_("Could not initialize CURL"));
- goto failure;
+ goto cleanup;
}
ctx->curl_headers = curl_slist_append(ctx->curl_headers, "Content-Type: "
if (ctx->curl_headers == NULL) {
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
_("Could not build CURL header list"));
- goto failure;
+ goto cleanup;
}
curl_easy_setopt(ctx->curl_handle, CURLOPT_URL, ctx->url);
if (virMutexInit(&ctx->curl_lock) < 0) {
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
_("Could not initialize CURL mutex"));
- goto failure;
+ goto cleanup;
}
ctx->username = strdup(username);
if (ctx->username == NULL || ctx->password == NULL) {
virReportOOMError();
- goto failure;
+ goto cleanup;
}
if (esxVI_RetrieveServiceContent(ctx, &ctx->service) < 0) {
- goto failure;
+ goto cleanup;
}
if (STREQ(ctx->service->about->apiType, "HostAgent") ||
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Expecting VI API major/minor version '2.5' or '4.0' "
"but found '%s'"), ctx->service->about->apiVersion);
- goto failure;
+ goto cleanup;
}
if (STREQ(ctx->service->about->productLineId, "gsx")) {
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Expecting GSX major/minor version '2.0' but "
"found '%s'"), ctx->service->about->version);
- goto failure;
+ goto cleanup;
}
} else if (STREQ(ctx->service->about->productLineId, "esx") ||
STREQ(ctx->service->about->productLineId, "embeddedEsx")) {
_("Expecting ESX major/minor version '3.5' or "
"'4.0' but found '%s'"),
ctx->service->about->version);
- goto failure;
+ goto cleanup;
}
} else if (STREQ(ctx->service->about->productLineId, "vpx")) {
if (STRPREFIX(ctx->service->about->version, "2.5")) {
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Expecting VPX major/minor version '2.5' or '4.0' "
"but found '%s'"), ctx->service->about->version);
- goto failure;
+ goto cleanup;
}
} else {
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Expecting product 'gsx' or 'esx' or 'embeddedEsx' "
"or 'vpx' but found '%s'"),
ctx->service->about->productLineId);
- goto failure;
+ goto cleanup;
}
} else {
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Expecting VI API type 'HostAgent' or 'VirtualCenter' "
"but found '%s'"), ctx->service->about->apiType);
- goto failure;
+ goto cleanup;
}
if (esxVI_Login(ctx, username, password, NULL, &ctx->session) < 0) {
- goto failure;
+ goto cleanup;
}
esxVI_BuildFullTraversalSpecList(&ctx->fullTraversalSpecList);
if (esxVI_String_AppendValueListToList(&propertyNameList,
"vmFolder\0"
"hostFolder\0") < 0) {
- goto failure;
+ goto cleanup;
}
/* Get pointer to Datacenter for later use */
"Datacenter", propertyNameList,
esxVI_Boolean_True,
&datacenterList) < 0) {
- goto failure;
+ goto cleanup;
}
if (datacenterList == NULL) {
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
_("Could not retrieve the 'datacenter' object from the "
"VI host/center"));
- goto failure;
+ goto cleanup;
}
ctx->datacenter = datacenterList->obj;
if (STREQ(dynamicProperty->name, "vmFolder")) {
if (esxVI_ManagedObjectReference_CastFromAnyType
(dynamicProperty->val, &ctx->vmFolder)) {
- goto failure;
+ goto cleanup;
}
} else if (STREQ(dynamicProperty->name, "hostFolder")) {
if (esxVI_ManagedObjectReference_CastFromAnyType
(dynamicProperty->val, &ctx->hostFolder)) {
- goto failure;
+ goto cleanup;
}
} else {
VIR_WARN("Unexpected '%s' property", dynamicProperty->name);
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
_("The 'datacenter' object is missing the "
"'vmFolder'/'hostFolder' property"));
- goto failure;
+ goto cleanup;
}
+ result = 0;
+
cleanup:
esxVI_String_Free(&propertyNameList);
esxVI_ObjectContent_Free(&datacenterList);
return result;
-
- failure:
- result = -1;
-
- goto cleanup;
}
int
if (content == NULL || *content != NULL) {
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
- goto failure;
+ return -1;
}
virMutexLock(&ctx->curl_lock);
virMutexUnlock(&ctx->curl_lock);
if (responseCode < 0) {
- goto failure;
+ goto cleanup;
} else if (responseCode != 200) {
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
_("HTTP response code %d for download from '%s'"),
responseCode, url);
- goto failure;
+ goto cleanup;
}
if (virBufferError(&buffer)) {
virReportOOMError();
- goto failure;
+ goto cleanup;
}
*content = virBufferContentAndReset(&buffer);
- return 0;
-
- failure:
- virBufferFreeAndReset(&buffer);
+ cleanup:
+ if (*content == NULL) {
+ virBufferFreeAndReset(&buffer);
+ return -1;
+ }
- return -1;
+ return 0;
}
int
const char *request, esxVI_Response **response,
esxVI_Occurrence occurrence)
{
- int result = 0;
+ int result = -1;
virBuffer buffer = VIR_BUFFER_INITIALIZER;
esxVI_Fault *fault = NULL;
char *xpathExpression = NULL;
if (request == NULL || response == NULL || *response != NULL) {
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
- goto failure;
+ return -1;
}
if (esxVI_Response_Alloc(response) < 0) {
- goto failure;
+ return -1;
}
virMutexLock(&ctx->curl_lock);
virMutexUnlock(&ctx->curl_lock);
if ((*response)->responseCode < 0) {
- goto failure;
+ goto cleanup;
}
if (virBufferError(&buffer)) {
virReportOOMError();
- goto failure;
+ goto cleanup;
}
(*response)->content = virBufferContentAndReset(&buffer);
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Response for call to '%s' could not be parsed"),
methodName);
- goto failure;
+ goto cleanup;
}
if (xmlDocGetRootElement((*response)->document) == NULL) {
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Response for call to '%s' is an empty XML document"),
methodName);
- goto failure;
+ goto cleanup;
}
xpathContext = xmlXPathNewContext((*response)->document);
if (xpathContext == NULL) {
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
_("Could not create XPath context"));
- goto failure;
+ goto cleanup;
}
xmlXPathRegisterNs(xpathContext, BAD_CAST "soapenv",
_("HTTP response code %d for call to '%s'. "
"Fault is unknown, XPath evaluation failed"),
(*response)->responseCode, methodName);
- goto failure;
+ goto cleanup;
}
if (esxVI_Fault_Deserialize((*response)->node, &fault) < 0) {
_("HTTP response code %d for call to '%s'. "
"Fault is unknown, deserialization failed"),
(*response)->responseCode, methodName);
- goto failure;
+ goto cleanup;
}
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
(*response)->responseCode, methodName,
(*response)->content);
- goto failure;
+ goto cleanup;
} else {
if (virAsprintf(&xpathExpression,
"/soapenv:Envelope/soapenv:Body/vim:%sResponse",
methodName) < 0) {
virReportOOMError();
- goto failure;
+ goto cleanup;
}
responseNode = virXPathNode(xpathExpression, xpathContext);
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
_("XPath evaluation of response for call to '%s' "
"failed"), methodName);
- goto failure;
+ goto cleanup;
}
xpathContext->node = responseNode;
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Call to '%s' returned an empty result, "
"expecting a non-empty result"), methodName);
- goto failure;
+ goto cleanup;
} else if ((*response)->node->next != NULL) {
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Call to '%s' returned a list, expecting "
"exactly one item"), methodName);
- goto failure;
+ goto cleanup;
}
break;
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Call to '%s' returned an empty result, "
"expecting a non-empty result"), methodName);
- goto failure;
+ goto cleanup;
}
break;
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Call to '%s' returned a list, expecting "
"exactly one item"), methodName);
- goto failure;
+ goto cleanup;
}
break;
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Call to '%s' returned something, expecting "
"an empty result"), methodName);
- goto failure;
+ goto cleanup;
}
break;
default:
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
_("Invalid argument (occurrence)"));
- goto failure;
+ goto cleanup;
}
}
} else {
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
_("HTTP response code %d for call to '%s'"),
(*response)->responseCode, methodName);
- goto failure;
+ goto cleanup;
}
+ result = 0;
+
cleanup:
+ if (result < 0) {
+ virBufferFreeAndReset(&buffer);
+ esxVI_Response_Free(response);
+ esxVI_Fault_Free(&fault);
+ }
+
VIR_FREE(xpathExpression);
xmlXPathFreeContext(xpathContext);
return result;
-
- failure:
- virBufferFreeAndReset(&buffer);
- esxVI_Response_Free(response);
- esxVI_Fault_Free(&fault);
-
- result = -1;
-
- goto cleanup;
}
xmlNodePtr node, int *value)
{
int i;
- int result = 0;
+ int result = -1;
char *name = NULL;
if (value == NULL) {
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
- goto failure;
+ return -1;
}
*value = 0; /* undefined */
if (esxVI_String_DeserializeValue(node, &name) < 0) {
- goto failure;
+ return -1;
}
for (i = 0; enumeration->values[i].name != NULL; ++i) {
if (STREQ(name, enumeration->values[i].name)) {
*value = enumeration->values[i].value;
- goto cleanup;
+ result = 0;
+ break;
}
}
- ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, _("Unknown value '%s' for %s"),
- name, esxVI_Type_ToString(enumeration->type));
+ if (result < 0) {
+ ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, _("Unknown value '%s' for %s"),
+ name, esxVI_Type_ToString(enumeration->type));
+ }
- cleanup:
VIR_FREE(name);
return result;
-
- failure:
- result = -1;
-
- goto cleanup;
}
if (destList == NULL || *destList != NULL) {
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
- goto failure;
+ return -1;
}
for (src = srcList; src != NULL; src = src->_next) {
esxVI_List_CastFromAnyTypeFunc castFromAnyTypeFunc,
esxVI_List_FreeFunc freeFunc)
{
- int result = 0;
+ int result = -1;
xmlNodePtr childNode = NULL;
esxVI_AnyType *childAnyType = NULL;
esxVI_List *item = NULL;
if (childNode->type != XML_ELEMENT_NODE) {
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Wrong XML element type %d"), childNode->type);
- goto failure;
+ goto cleanup;
}
esxVI_AnyType_Free(&childAnyType);
if (esxVI_AnyType_Deserialize(childNode, &childAnyType) < 0 ||
castFromAnyTypeFunc(childAnyType, &item) < 0 ||
esxVI_List_Append(list, item) < 0) {
- goto failure;
+ goto cleanup;
}
item = NULL;
}
+ result = 0;
+
cleanup:
+ if (result < 0) {
+ freeFunc(&item);
+ freeFunc(list);
+ }
+
esxVI_AnyType_Free(&childAnyType);
return result;
-
- failure:
- freeFunc(&item);
- freeFunc(list);
-
- result = -1;
-
- goto cleanup;
}
int
#if ESX_VI_USE_SESSION_IS_ACTIVE
esxVI_Boolean active = esxVI_Boolean_Undefined;
#else
- int result = 0;
+ int result = -1;
esxVI_String *propertyNameList = NULL;
esxVI_ObjectContent *sessionManager = NULL;
esxVI_DynamicProperty *dynamicProperty = NULL;
"SessionManager", propertyNameList,
esxVI_Boolean_False,
&sessionManager) < 0) {
- goto failure;
+ goto cleanup;
}
for (dynamicProperty = sessionManager->propSet; dynamicProperty != NULL;
if (STREQ(dynamicProperty->name, "currentSession")) {
if (esxVI_UserSession_CastFromAnyType(dynamicProperty->val,
¤tSession) < 0) {
- goto failure;
+ goto cleanup;
}
break;
if (esxVI_Login(ctx, ctx->username, ctx->password, NULL,
&ctx->session) < 0) {
- goto failure;
+ goto cleanup;
}
} else if (STRNEQ(ctx->session->key, currentSession->key)) {
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
_("Key of the current session differs from the key at "
"last login"));
- goto failure;
+ goto cleanup;
}
+ result = 0;
+
cleanup:
esxVI_String_Free(&propertyNameList);
esxVI_ObjectContent_Free(&sessionManager);
esxVI_UserSession_Free(¤tSession);
return result;
-
- failure:
- result = -1;
-
- goto cleanup;
#endif
}
esxVI_Boolean recurse,
esxVI_ObjectContent **objectContentList)
{
- int result = 0;
+ int result = -1;
esxVI_ObjectSpec *objectSpec = NULL;
esxVI_PropertySpec *propertySpec = NULL;
esxVI_PropertyFilterSpec *propertyFilterSpec = NULL;
}
if (esxVI_ObjectSpec_Alloc(&objectSpec) < 0) {
- goto failure;
+ return -1;
}
objectSpec->obj = root;
}
if (esxVI_PropertySpec_Alloc(&propertySpec) < 0) {
- goto failure;
+ goto cleanup;
}
propertySpec->type = (char *)type;
propertySpec) < 0 ||
esxVI_ObjectSpec_AppendToList(&propertyFilterSpec->objectSet,
objectSpec) < 0) {
- goto failure;
+ goto cleanup;
}
result = esxVI_RetrieveProperties(ctx, propertyFilterSpec,
esxVI_PropertyFilterSpec_Free(&propertyFilterSpec);
return result;
-
- failure:
- result = -1;
-
- goto cleanup;
}
esxVI_VirtualMachinePowerState powerState,
esxVI_Boolean inverse)
{
+ bool success = false;
esxVI_String *propertyNameList = NULL;
esxVI_ObjectContent *virtualMachineList = NULL;
esxVI_ObjectContent *virtualMachine = NULL;
esxVI_DynamicProperty *dynamicProperty = NULL;
esxVI_VirtualMachinePowerState powerState_;
- int numberOfDomains = 0;
+ int count = 0;
if (esxVI_String_AppendValueToList(&propertyNameList,
"runtime.powerState") < 0 ||
esxVI_LookupObjectContentByType(ctx, ctx->vmFolder, "VirtualMachine",
propertyNameList, esxVI_Boolean_True,
&virtualMachineList) < 0) {
- goto failure;
+ goto cleanup;
}
for (virtualMachine = virtualMachineList; virtualMachine != NULL;
if (STREQ(dynamicProperty->name, "runtime.powerState")) {
if (esxVI_VirtualMachinePowerState_CastFromAnyType
(dynamicProperty->val, &powerState_) < 0) {
- goto failure;
+ goto cleanup;
}
if ((inverse != esxVI_Boolean_True &&
powerState_ == powerState) ||
(inverse == esxVI_Boolean_True &&
powerState_ != powerState)) {
- numberOfDomains++;
+ count++;
}
} else {
VIR_WARN("Unexpected '%s' property", dynamicProperty->name);
}
}
+ success = true;
+
cleanup:
esxVI_String_Free(&propertyNameList);
esxVI_ObjectContent_Free(&virtualMachineList);
- return numberOfDomains;
-
- failure:
- numberOfDomains = -1;
-
- goto cleanup;
+ return success ? count : -1;
}
(esxVI_Context *ctx, esxVI_ObjectContent *hostSystem,
esxVI_ManagedObjectReference **resourcePool)
{
- int result = 0;
+ int result = -1;
esxVI_String *propertyNameList = NULL;
esxVI_DynamicProperty *dynamicProperty = NULL;
esxVI_ManagedObjectReference *managedObjectReference = NULL;
if (STREQ(dynamicProperty->name, "parent")) {
if (esxVI_ManagedObjectReference_CastFromAnyType
(dynamicProperty->val, &managedObjectReference) < 0) {
- goto failure;
+ goto cleanup;
}
break;
if (managedObjectReference == NULL) {
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
_("Could not retrieve compute resource of host system"));
- goto failure;
+ goto cleanup;
}
if (esxVI_String_AppendValueToList(&propertyNameList, "resourcePool") < 0 ||
"ComputeResource", propertyNameList,
esxVI_Boolean_False,
&computeResource) < 0) {
- goto failure;
+ goto cleanup;
}
if (computeResource == NULL) {
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
_("Could not retrieve compute resource of host system"));
- goto failure;
+ goto cleanup;
}
for (dynamicProperty = computeResource->propSet; dynamicProperty != NULL;
if (STREQ(dynamicProperty->name, "resourcePool")) {
if (esxVI_ManagedObjectReference_CastFromAnyType
(dynamicProperty->val, resourcePool) < 0) {
- goto failure;
+ goto cleanup;
}
break;
if ((*resourcePool) == NULL) {
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
_("Could not retrieve resource pool of compute resource"));
- goto failure;
+ goto cleanup;
}
+ result = 0;
+
cleanup:
esxVI_String_Free(&propertyNameList);
esxVI_ManagedObjectReference_Free(&managedObjectReference);
esxVI_ObjectContent_Free(&computeResource);
return result;
-
- failure:
- result = -1;
-
- goto cleanup;
}
esxVI_String *propertyNameList,
esxVI_ObjectContent **hostSystem)
{
- int result = 0;
+ int result = -1;
esxVI_ManagedObjectReference *managedObjectReference = NULL;
if (hostSystem == NULL || *hostSystem != NULL) {
if (esxVI_FindByIp(ctx, ctx->datacenter, ipAddress, esxVI_Boolean_False,
&managedObjectReference) < 0) {
- goto failure;
+ return -1;
}
if (managedObjectReference == NULL) {
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Could not find host system with IP address '%s'"),
ipAddress);
- goto failure;
+ goto cleanup;
}
if (esxVI_LookupObjectContentByType(ctx, managedObjectReference,
"HostSystem", propertyNameList,
esxVI_Boolean_False, hostSystem) < 0) {
- goto failure;
+ goto cleanup;
}
+ result = 0;
+
cleanup:
esxVI_ManagedObjectReference_Free(&managedObjectReference);
return result;
-
- failure:
- result = -1;
-
- goto cleanup;
}
esxVI_ObjectContent **virtualMachine,
esxVI_Occurrence occurrence)
{
- int result = 0;
+ int result = -1;
esxVI_ManagedObjectReference *managedObjectReference = NULL;
char uuid_string[VIR_UUID_STRING_BUFLEN] = "";
if (esxVI_FindByUuid(ctx, ctx->datacenter, uuid_string, esxVI_Boolean_True,
&managedObjectReference) < 0) {
- goto failure;
+ return -1;
}
if (managedObjectReference == NULL) {
ESX_VI_ERROR(VIR_ERR_NO_DOMAIN,
_("Could not find domain with UUID '%s'"),
uuid_string);
- goto failure;
+ goto cleanup;
}
}
"VirtualMachine", propertyNameList,
esxVI_Boolean_False,
virtualMachine) < 0) {
- goto failure;
+ goto cleanup;
}
+ result = 0;
+
cleanup:
esxVI_ManagedObjectReference_Free(&managedObjectReference);
return result;
-
- failure:
- result = -1;
-
- goto cleanup;
}
esxVI_ObjectContent **virtualMachine,
esxVI_Occurrence occurrence)
{
- int result = 0;
+ int result = -1;
esxVI_String *completePropertyNameList = NULL;
esxVI_ObjectContent *virtualMachineList = NULL;
esxVI_ObjectContent *candidate = NULL;
completePropertyNameList,
esxVI_Boolean_True,
&virtualMachineList) < 0) {
- goto failure;
+ goto cleanup;
}
for (candidate = virtualMachineList; candidate != NULL;
if (esxVI_GetVirtualMachineIdentity(candidate, NULL, &name_candidate,
NULL) < 0) {
- goto failure;
+ goto cleanup;
}
if (STRNEQ(name, name_candidate)) {
}
if (esxVI_ObjectContent_DeepCopy(virtualMachine, candidate) < 0) {
- goto failure;
+ goto cleanup;
}
break;
} else {
ESX_VI_ERROR(VIR_ERR_NO_DOMAIN,
_("Could not find domain with name '%s'"), name);
- goto failure;
+ goto cleanup;
}
}
+ result = 0;
+
cleanup:
esxVI_String_Free(&completePropertyNameList);
esxVI_ObjectContent_Free(&virtualMachineList);
VIR_FREE(name_candidate);
return result;
-
- failure:
- result = -1;
-
- goto cleanup;
}
esxVI_String *propertyNameList, esxVI_ObjectContent **virtualMachine,
esxVI_Boolean autoAnswer)
{
- int result = 0;
+ int result = -1;
esxVI_String *completePropertyNameList = NULL;
esxVI_VirtualMachineQuestionInfo *questionInfo = NULL;
esxVI_TaskInfo *pendingTaskInfoList = NULL;
&questionInfo) < 0 ||
esxVI_LookupPendingTaskInfoListByVirtualMachine
(ctx, *virtualMachine, &pendingTaskInfoList) < 0) {
- goto failure;
+ goto cleanup;
}
if (questionInfo != NULL &&
esxVI_HandleVirtualMachineQuestion(ctx, (*virtualMachine)->obj,
questionInfo, autoAnswer) < 0) {
- goto failure;
+ goto cleanup;
}
if (pendingTaskInfoList != NULL) {
ESX_VI_ERROR(VIR_ERR_OPERATION_INVALID, "%s",
_("Other tasks are pending for this domain"));
- goto failure;
+ goto cleanup;
}
+ result = 0;
+
cleanup:
esxVI_String_Free(&completePropertyNameList);
esxVI_VirtualMachineQuestionInfo_Free(&questionInfo);
esxVI_TaskInfo_Free(&pendingTaskInfoList);
return result;
-
- failure:
- result = -1;
-
- goto cleanup;
}
esxVI_ObjectContent **datastore,
esxVI_Occurrence occurrence)
{
- int result = 0;
+ int result = -1;
esxVI_String *completePropertyNameList = NULL;
esxVI_ObjectContent *datastoreList = NULL;
esxVI_ObjectContent *candidate = NULL;
"summary.accessible\0"
"summary.name\0"
"summary.url\0") < 0) {
- goto failure;
+ goto cleanup;
}
if (esxVI_LookupObjectContentByType(ctx, ctx->datacenter, "Datastore",
completePropertyNameList,
esxVI_Boolean_True,
&datastoreList) < 0) {
- goto failure;
+ goto cleanup;
}
if (datastoreList == NULL) {
if (occurrence == esxVI_Occurrence_OptionalItem) {
- goto cleanup;
+ goto success;
} else {
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
_("No datastores available"));
- goto failure;
+ goto cleanup;
}
}
if (STREQ(dynamicProperty->name, "summary.accessible")) {
if (esxVI_AnyType_ExpectType(dynamicProperty->val,
esxVI_Type_Boolean) < 0) {
- goto failure;
+ goto cleanup;
}
accessible = dynamicProperty->val->boolean;
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
_("Got incomplete response while querying for the "
"datastore 'summary.accessible' property"));
- goto failure;
+ goto cleanup;
}
if (accessible == esxVI_Boolean_False) {
if (STREQ(dynamicProperty->name, "summary.name")) {
if (esxVI_AnyType_ExpectType(dynamicProperty->val,
esxVI_Type_String) < 0) {
- goto failure;
+ goto cleanup;
}
if (STREQ(dynamicProperty->val->string, name)) {
if (esxVI_ObjectContent_DeepCopy(datastore,
candidate) < 0) {
- goto failure;
+ goto cleanup;
}
/* Found datastore with matching name */
- goto cleanup;
+ goto success;
}
} else if (STREQ(dynamicProperty->name, "summary.url") &&
ctx->productVersion & esxVI_ProductVersion_ESX) {
if (esxVI_AnyType_ExpectType(dynamicProperty->val,
esxVI_Type_String) < 0) {
- goto failure;
+ goto cleanup;
}
if (! STRPREFIX(dynamicProperty->val->string,
_("Datastore URL '%s' has unexpected prefix, "
"expecting '/vmfs/volumes/' prefix"),
dynamicProperty->val->string);
- goto failure;
+ goto cleanup;
}
if (STREQ(dynamicProperty->val->string + offset, name)) {
if (esxVI_ObjectContent_DeepCopy(datastore,
candidate) < 0) {
- goto failure;
+ goto cleanup;
}
/* Found datastore with matching URL suffix */
- goto cleanup;
+ goto success;
}
}
}
_("Could not find datastore '%s'"), name);
}
- goto failure;
+ goto cleanup;
}
+ success:
+ result = 0;
+
cleanup:
esxVI_String_Free(&completePropertyNameList);
esxVI_ObjectContent_Free(&datastoreList);
return result;
-
- failure:
- result = -1;
-
- goto cleanup;
}
esxVI_ManagedObjectReference *task,
esxVI_TaskInfo **taskInfo)
{
- int result = 0;
+ int result = -1;
esxVI_String *propertyNameList = NULL;
esxVI_ObjectContent *objectContent = NULL;
esxVI_DynamicProperty *dynamicProperty = NULL;
esxVI_LookupObjectContentByType(ctx, task, "Task", propertyNameList,
esxVI_Boolean_False,
&objectContent) < 0) {
- goto failure;
+ goto cleanup;
}
for (dynamicProperty = objectContent->propSet; dynamicProperty != NULL;
if (STREQ(dynamicProperty->name, "info")) {
if (esxVI_TaskInfo_CastFromAnyType(dynamicProperty->val,
taskInfo) < 0) {
- goto failure;
+ goto cleanup;
}
break;
}
}
+ result = 0;
+
cleanup:
esxVI_String_Free(&propertyNameList);
esxVI_ObjectContent_Free(&objectContent);
return result;
-
- failure:
- result = -1;
-
- goto cleanup;
}
(esxVI_Context *ctx, esxVI_ObjectContent *virtualMachine,
esxVI_TaskInfo **pendingTaskInfoList)
{
- int result = 0;
+ int result = -1;
esxVI_String *propertyNameList = NULL;
esxVI_ManagedObjectReference *recentTaskList = NULL;
esxVI_ManagedObjectReference *recentTask = NULL;
if (STREQ(dynamicProperty->name, "recentTask")) {
if (esxVI_ManagedObjectReference_CastListFromAnyType
(dynamicProperty->val, &recentTaskList) < 0) {
- goto failure;
+ goto cleanup;
}
break;
for (recentTask = recentTaskList; recentTask != NULL;
recentTask = recentTask->_next) {
if (esxVI_LookupTaskInfoByTask(ctx, recentTask, &taskInfo) < 0) {
- goto failure;
+ goto cleanup;
}
if (taskInfo->state == esxVI_TaskInfoState_Queued ||
taskInfo->state == esxVI_TaskInfoState_Running) {
if (esxVI_TaskInfo_AppendToList(pendingTaskInfoList,
taskInfo) < 0) {
- goto failure;
+ goto cleanup;
}
taskInfo = NULL;
}
}
+ result = 0;
+
cleanup:
+ if (result < 0) {
+ esxVI_TaskInfo_Free(pendingTaskInfoList);
+ }
+
esxVI_String_Free(&propertyNameList);
esxVI_ManagedObjectReference_Free(&recentTaskList);
esxVI_TaskInfo_Free(&taskInfo);
return result;
-
- failure:
- esxVI_TaskInfo_Free(pendingTaskInfoList);
-
- result = -1;
-
- goto cleanup;
}
const unsigned char *uuid,
esxVI_Boolean autoAnswer)
{
- int result = 0;
+ int result = -1;
esxVI_ObjectContent *virtualMachine = NULL;
esxVI_String *propertyNameList = NULL;
esxVI_VirtualMachineQuestionInfo *questionInfo = NULL;
esxVI_Occurrence_RequiredItem) < 0 ||
esxVI_GetVirtualMachineQuestionInfo(virtualMachine,
&questionInfo) < 0) {
- goto failure;
+ goto cleanup;
}
if (questionInfo != NULL &&
esxVI_HandleVirtualMachineQuestion(ctx, virtualMachine->obj,
questionInfo, autoAnswer) < 0) {
- goto failure;
+ goto cleanup;
}
+ result = 0;
+
cleanup:
esxVI_ObjectContent_Free(&virtualMachine);
esxVI_String_Free(&propertyNameList);
esxVI_VirtualMachineQuestionInfo_Free(&questionInfo);
return result;
-
- failure:
- result = -1;
-
- goto cleanup;
}
(esxVI_Context *ctx, const unsigned char *virtualMachineUuid,
esxVI_VirtualMachineSnapshotTree **rootSnapshotTreeList)
{
- int result = 0;
+ int result = -1;
esxVI_String *propertyNameList = NULL;
esxVI_ObjectContent *virtualMachine = NULL;
esxVI_DynamicProperty *dynamicProperty = NULL;
esxVI_LookupVirtualMachineByUuid(ctx, virtualMachineUuid,
propertyNameList, &virtualMachine,
esxVI_Occurrence_RequiredItem) < 0) {
- goto failure;
+ goto cleanup;
}
for (dynamicProperty = virtualMachine->propSet; dynamicProperty != NULL;
if (STREQ(dynamicProperty->name, "snapshot.rootSnapshotList")) {
if (esxVI_VirtualMachineSnapshotTree_CastListFromAnyType
(dynamicProperty->val, rootSnapshotTreeList) < 0) {
- goto failure;
+ goto cleanup;
}
break;
}
}
+ result = 0;
+
cleanup:
+ if (result < 0) {
+ esxVI_VirtualMachineSnapshotTree_Free(rootSnapshotTreeList);
+ }
+
esxVI_String_Free(&propertyNameList);
esxVI_ObjectContent_Free(&virtualMachine);
return result;
-
- failure:
- esxVI_VirtualMachineSnapshotTree_Free(rootSnapshotTreeList);
-
- result = -1;
-
- goto cleanup;
}
esxVI_VirtualMachineSnapshotTree **currentSnapshotTree,
esxVI_Occurrence occurrence)
{
- int result = 0;
+ int result = -1;
esxVI_String *propertyNameList = NULL;
esxVI_ObjectContent *virtualMachine = NULL;
esxVI_DynamicProperty *dynamicProperty = NULL;
esxVI_LookupVirtualMachineByUuid(ctx, virtualMachineUuid,
propertyNameList, &virtualMachine,
esxVI_Occurrence_RequiredItem) < 0) {
- goto failure;
+ goto cleanup;
}
for (dynamicProperty = virtualMachine->propSet; dynamicProperty != NULL;
if (STREQ(dynamicProperty->name, "snapshot.currentSnapshot")) {
if (esxVI_ManagedObjectReference_CastFromAnyType
(dynamicProperty->val, ¤tSnapshot) < 0) {
- goto failure;
+ goto cleanup;
}
} else if (STREQ(dynamicProperty->name, "snapshot.rootSnapshotList")) {
if (esxVI_VirtualMachineSnapshotTree_CastListFromAnyType
(dynamicProperty->val, &rootSnapshotTreeList) < 0) {
- goto failure;
+ goto cleanup;
}
} else {
VIR_WARN("Unexpected '%s' property", dynamicProperty->name);
} else {
ESX_VI_ERROR(VIR_ERR_NO_DOMAIN_SNAPSHOT, "%s",
_("Domain has no current snapshot"));
- goto failure;
+ goto cleanup;
}
}
if (rootSnapshotTreeList == NULL) {
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
_("Could not lookup root snapshot list"));
- goto failure;
+ goto cleanup;
}
if (esxVI_GetSnapshotTreeBySnapshot(rootSnapshotTreeList, currentSnapshot,
&snapshotTree) < 0 ||
esxVI_VirtualMachineSnapshotTree_DeepCopy(currentSnapshotTree,
snapshotTree) < 0) {
- goto failure;
+ goto cleanup;
}
+ result = 0;
+
cleanup:
esxVI_String_Free(&propertyNameList);
esxVI_ObjectContent_Free(&virtualMachine);
esxVI_VirtualMachineSnapshotTree_Free(&rootSnapshotTreeList);
return result;
-
- failure:
- result = -1;
-
- goto cleanup;
}
esxVI_VirtualMachineQuestionInfo *questionInfo,
esxVI_Boolean autoAnswer)
{
- int result = 0;
+ int result = -1;
esxVI_ElementDescription *elementDescription = NULL;
virBuffer buffer = VIR_BUFFER_INITIALIZER;
esxVI_ElementDescription *answerChoice = NULL;
if (virBufferError(&buffer)) {
virReportOOMError();
- goto failure;
+ goto cleanup;
}
possibleAnswers = virBufferContentAndReset(&buffer);
_("Pending question blocks virtual machine execution, "
"question is '%s', no possible answers"),
questionInfo->text);
- goto failure;
+ goto cleanup;
} else if (answerChoice == NULL) {
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Pending question blocks virtual machine execution, "
"question is '%s', possible answers are %s, but no "
"default answer is specified"), questionInfo->text,
possibleAnswers);
- goto failure;
+ goto cleanup;
}
VIR_INFO("Pending question blocks virtual machine execution, "
if (esxVI_AnswerVM(ctx, virtualMachine, questionInfo->id,
answerChoice->key) < 0) {
- goto failure;
+ goto cleanup;
}
} else {
if (possibleAnswers != NULL) {
questionInfo->text);
}
- goto failure;
+ goto cleanup;
}
+ result = 0;
+
cleanup:
+ if (result < 0) {
+ virBufferFreeAndReset(&buffer);
+ }
+
VIR_FREE(possibleAnswers);
return result;
-
- failure:
- virBufferFreeAndReset(&buffer);
-
- result = -1;
-
- goto cleanup;
}
esxVI_Boolean autoAnswer,
esxVI_TaskInfoState *finalState)
{
- int result = 0;
+ int result = -1;
esxVI_ObjectSpec *objectSpec = NULL;
esxVI_PropertySpec *propertySpec = NULL;
esxVI_PropertyFilterSpec *propertyFilterSpec = NULL;
if (version == NULL) {
virReportOOMError();
- goto failure;
+ return -1;
}
if (esxVI_ObjectSpec_Alloc(&objectSpec) < 0) {
- goto failure;
+ goto cleanup;
}
objectSpec->obj = task;
objectSpec->skip = esxVI_Boolean_False;
if (esxVI_PropertySpec_Alloc(&propertySpec) < 0) {
- goto failure;
+ goto cleanup;
}
propertySpec->type = task->type;
objectSpec) < 0 ||
esxVI_CreateFilter(ctx, propertyFilterSpec, esxVI_Boolean_True,
&propertyFilter) < 0) {
- goto failure;
+ goto cleanup;
}
while (state != esxVI_TaskInfoState_Success &&
* don't overwrite the actual error
*/
if (esxVI_LookupTaskInfoByTask(ctx, task, &taskInfo)) {
- goto failure;
+ goto cleanup;
}
if (taskInfo->cancelable == esxVI_Boolean_True) {
/* FIXME: Enable error reporting here again */
- goto failure;
+ goto cleanup;
}
}
if (esxVI_WaitForUpdates(ctx, version, &updateSet) < 0) {
- goto failure;
+ goto cleanup;
}
VIR_FREE(version);
if (version == NULL) {
virReportOOMError();
- goto failure;
+ goto cleanup;
}
if (updateSet->filterSet == NULL) {
}
if (esxVI_TaskInfoState_CastFromAnyType(propertyValue, &state) < 0) {
- goto failure;
+ goto cleanup;
}
}
}
if (esxVI_TaskInfoState_CastFromAnyType(propertyValue, finalState) < 0) {
- goto failure;
+ goto cleanup;
}
+ result = 0;
+
cleanup:
/*
* Remove values given by the caller from the data structures to prevent
esxVI_TaskInfo_Free(&taskInfo);
return result;
-
- failure:
- result = -1;
-
- goto cleanup;
}
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
_("HostCpuIdInfo register '%s' has an unexpected length"),
name[r]);
- goto failure;
+ return -1;
}
/* Strip the ':' and invert the "bit" order from 31..0 to 0..31 */
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
_("HostCpuIdInfo register '%s' has an unexpected format"),
name[r]);
- goto failure;
+ return -1;
}
}
}
return 0;
-
- failure:
- memset(parsedHostCpuIdInfo, 0, sizeof (*parsedHostCpuIdInfo));
-
- return -1;
}
#define ESX_VI__METHOD__DESERIALIZE_OUTPUT__RequiredItem(_type) \
if (esxVI_##_type##_Deserialize(response->node, output) < 0) { \
- goto failure; \
+ goto cleanup; \
}
#define ESX_VI__METHOD__DESERIALIZE_OUTPUT__RequiredList(_type) \
if (esxVI_##_type##_DeserializeList(response->node, output) < 0) { \
- goto failure; \
+ goto cleanup; \
}
#define ESX_VI__METHOD__DESERIALIZE_OUTPUT__OptionalItem(_type) \
if (response->node != NULL && \
esxVI_##_type##_Deserialize(response->node, output) < 0) { \
- goto failure; \
+ goto cleanup; \
}
#define ESX_VI__METHOD__DESERIALIZE_OUTPUT__OptionalList(_type) \
if (response->node != NULL && \
esxVI_##_type##_DeserializeList(response->node, output) < 0) { \
- goto failure; \
+ goto cleanup; \
}
int \
esxVI_##_name _parameters \
{ \
- int result = 0; \
+ int result = -1; \
const char *methodName = #_name; \
virBuffer buffer = VIR_BUFFER_INITIALIZER; \
char *request = NULL; \
\
if (virBufferError(&buffer)) { \
virReportOOMError(); \
- goto failure; \
+ goto cleanup; \
} \
\
request = virBufferContentAndReset(&buffer); \
\
if (esxVI_Context_Execute(ctx, methodName, request, &response, \
esxVI_Occurrence_##_occurrence) < 0) { \
- goto failure; \
+ goto cleanup; \
} \
\
ESX_VI__METHOD__DESERIALIZE_OUTPUT__##_occurrence(_output_type) \
\
+ result = 0; \
+ \
cleanup: \
+ if (result < 0) { \
+ virBufferFreeAndReset(&buffer); \
+ } \
+ \
VIR_FREE(request); \
esxVI_Response_Free(&response); \
\
return result; \
- \
- failure: \
- virBufferFreeAndReset(&buffer); \
- \
- result = -1; \
- \
- goto cleanup; \
}
#define ESX_VI__METHOD__PARAMETER__SERIALIZE(_type, _name) \
if (esxVI_##_type##_Serialize(_name, #_name, &buffer) < 0) { \
- goto failure; \
+ goto cleanup; \
}
#define ESX_VI__METHOD__PARAMETER__SERIALIZE_LIST(_type, _name) \
if (esxVI_##_type##_SerializeList(_name, #_name, &buffer) < 0) { \
- goto failure; \
+ goto cleanup; \
}
#define ESX_VI__METHOD__PARAMETER__SERIALIZE_VALUE(_type, _name) \
if (esxVI_##_type##_SerializeValue(_name, #_name, &buffer) < 0) { \
- goto failure; \
+ goto cleanup; \
}
esxVI_RetrieveServiceContent(esxVI_Context *ctx,
esxVI_ServiceContent **serviceContent)
{
- int result = 0;
+ int result = -1;
const char *request = ESX_VI__SOAP__REQUEST_HEADER
"<RetrieveServiceContent xmlns=\"urn:vim25\">"
"<_this xmlns=\"urn:vim25\" "
if (esxVI_Context_Execute(ctx, "RetrieveServiceContent", request,
&response, esxVI_Occurrence_RequiredItem) < 0 ||
esxVI_ServiceContent_Deserialize(response->node, serviceContent) < 0) {
- goto failure;
+ goto cleanup;
}
+ result = 0;
+
cleanup:
esxVI_Response_Free(&response);
return result;
-
- failure:
- result = -1;
-
- goto cleanup;
}
int \
esxVI_##_type##_Deserialize(xmlNodePtr node, esxVI_##_type **number) \
{ \
- int result = 0; \
+ int result = -1; \
char *string; \
long long value; \
\
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, \
"XML node doesn't contain text, expecting an " \
_xsdType" value"); \
- goto failure; \
+ goto cleanup; \
} \
\
if (virStrToLong_ll(string, NULL, 10, &value) < 0) { \
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, \
"Unknown value '%s' for "_xsdType, string); \
- goto failure; \
+ goto cleanup; \
} \
\
if (value < (_min) || value > (_max)) { \
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, \
"Value '%s' is not representable as "_xsdType, \
(const char *)string); \
- goto failure; \
+ goto cleanup; \
} \
\
(*number)->value = value; \
\
+ result = 0; \
+ \
cleanup: \
+ if (result < 0) { \
+ esxVI_##_type##_Free(number); \
+ } \
+ \
VIR_FREE(string); \
\
return result; \
- \
- failure: \
- esxVI_##_type##_Free(number); \
- \
- result = -1; \
- \
- goto cleanup; \
}
esxVI_String *string = NULL;
if (esxVI_String_Alloc(&string) < 0) {
- goto failure;
+ return -1;
}
string->value = strdup(value);
esxVMX_AbsolutePathToDatastoreRelatedPath(esxVI_Context *ctx,
const char *absolutePath)
{
+ bool success = false;
char *copyOfAbsolutePath = NULL;
char *tmp = NULL;
char *saveptr = NULL;
const char *datastoreName = NULL;
if (esxVI_String_DeepCopyValue(©OfAbsolutePath, absolutePath) < 0) {
- goto failure;
+ return NULL;
}
/* Expected format: '/vmfs/volumes/<datastore>/<path>' */
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Absolute path '%s' doesn't have expected format "
"'/vmfs/volumes/<datastore>/<path>'"), absolutePath);
- goto failure;
+ goto cleanup;
}
if (ctx != NULL) {
if (esxVI_LookupDatastoreByName(ctx, preliminaryDatastoreName,
NULL, &datastore,
esxVI_Occurrence_OptionalItem) < 0) {
- goto failure;
+ goto cleanup;
}
if (datastore != NULL) {
} else if (STREQ(dynamicProperty->name, "summary.name")) {
if (esxVI_AnyType_ExpectType(dynamicProperty->val,
esxVI_Type_String) < 0) {
- goto failure;
+ goto cleanup;
}
datastoreName = dynamicProperty->val->string;
if (virAsprintf(&datastoreRelatedPath, "[%s] %s", datastoreName,
directoryAndFileName) < 0) {
virReportOOMError();
- goto failure;
+ goto cleanup;
}
/* FIXME: Check if referenced path/file really exists */
+ success = true;
+
cleanup:
+ if (! success) {
+ VIR_FREE(datastoreRelatedPath);
+ }
+
VIR_FREE(copyOfAbsolutePath);
esxVI_ObjectContent_Free(&datastore);
return datastoreRelatedPath;
-
- failure:
- VIR_FREE(datastoreRelatedPath);
-
- goto cleanup;
}
const char *datastoreName, const char *directoryName,
esxVI_ProductVersion productVersion)
{
+ bool success = false;
virConfPtr conf = NULL;
virDomainDefPtr def = NULL;
long long config_version = 0;
if (VIR_ALLOC(def) < 0) {
virReportOOMError();
- goto failure;
+ return NULL;
}
def->virtType = VIR_DOMAIN_VIRT_VMWARE; /* FIXME: maybe add VIR_DOMAIN_VIRT_ESX ? */
/* vmx:config.version */
if (esxUtil_GetConfigLong(conf, "config.version", &config_version, 0,
0) < 0) {
- goto failure;
+ goto cleanup;
}
if (config_version != 8) {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Expecting VMX entry 'config.version' to be 8 but found "
"%lld"), config_version);
- goto failure;
+ goto cleanup;
}
/* vmx:virtualHW.version */
if (esxUtil_GetConfigLong(conf, "virtualHW.version", &virtualHW_version, 0,
0) < 0) {
- goto failure;
+ goto cleanup;
}
/*
_("Expecting VMX entry 'virtualHW.version' to be 4 "
"but found %lld"),
virtualHW_version);
- goto failure;
+ goto cleanup;
}
break;
_("Expecting VMX entry 'virtualHW.version' to be 4 or 7 "
"but found %lld"),
virtualHW_version);
- goto failure;
+ goto cleanup;
}
break;
default:
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
_("Unexpected product version"));
- goto failure;
+ goto cleanup;
}
/* vmx:uuid.bios -> def:uuid */
/* FIXME: Need to handle 'uuid.action = "create"' */
if (esxUtil_GetConfigUUID(conf, "uuid.bios", def->uuid, 1) < 0) {
- goto failure;
+ goto cleanup;
}
/* vmx:displayName -> def:name */
if (esxUtil_GetConfigString(conf, "displayName", &def->name, 1) < 0) {
- goto failure;
+ goto cleanup;
}
/* vmx:memsize -> def:maxmem */
if (esxUtil_GetConfigLong(conf, "memsize", &memsize, 32, 1) < 0) {
- goto failure;
+ goto cleanup;
}
if (memsize <= 0 || memsize % 4 != 0) {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Expecting VMX entry 'memsize' to be an unsigned "
"integer (multiple of 4) but found %lld"), memsize);
- goto failure;
+ goto cleanup;
}
def->maxmem = memsize * 1024; /* Scale from megabytes to kilobytes */
/* vmx:sched.mem.max -> def:memory */
if (esxUtil_GetConfigLong(conf, "sched.mem.max", &memory, memsize, 1) < 0) {
- goto failure;
+ goto cleanup;
}
if (memory < 0) {
/* vmx:numvcpus -> def:vcpus */
if (esxUtil_GetConfigLong(conf, "numvcpus", &numvcpus, 1, 1) < 0) {
- goto failure;
+ goto cleanup;
}
if (numvcpus <= 0 || (numvcpus % 2 != 0 && numvcpus != 1)) {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Expecting VMX entry 'numvcpus' to be an unsigned "
"integer (1 or a multiple of 2) but found %lld"), numvcpus);
- goto failure;
+ goto cleanup;
}
def->vcpus = numvcpus;
// VirtualMachine:config.cpuAffinity.affinitySet
if (esxUtil_GetConfigString(conf, "sched.cpu.affinity", &sched_cpu_affinity,
1) < 0) {
- goto failure;
+ goto cleanup;
}
if (sched_cpu_affinity != NULL && STRNEQ(sched_cpu_affinity, "all")) {
if (VIR_ALLOC_N(def->cpumask, VIR_DOMAIN_CPUMASK_LEN) < 0) {
virReportOOMError();
- goto failure;
+ goto cleanup;
}
while (*current != '\0') {
_("Expecting VMX entry 'sched.cpu.affinity' to be "
"a comma separated list of unsigned integers but "
"found '%s'"), sched_cpu_affinity);
- goto failure;
+ goto cleanup;
}
if (number >= VIR_DOMAIN_CPUMASK_LEN) {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("VMX entry 'sched.cpu.affinity' contains a %d, "
"this value is too large"), number);
- goto failure;
+ goto cleanup;
}
if (number + 1 > def->cpumasklen) {
_("Expecting VMX entry 'sched.cpu.affinity' to be "
"a comma separated list of unsigned integers but "
"found '%s'"), sched_cpu_affinity);
- goto failure;
+ goto cleanup;
}
virSkipSpaces(¤t);
_("Expecting VMX entry 'sched.cpu.affinity' to contain "
"at least as many values as 'numvcpus' (%lld) but "
"found only %d value(s)"), numvcpus, count);
- goto failure;
+ goto cleanup;
}
}
if (def->os.type == NULL) {
virReportOOMError();
- goto failure;
+ goto cleanup;
}
/* vmx:guestOS -> def:os.arch */
if (esxUtil_GetConfigString(conf, "guestOS", &guestOS, 1) < 0) {
- goto failure;
+ goto cleanup;
}
if (guestOS != NULL && virFileHasSuffix(guestOS, "-64")) {
if (def->os.arch == NULL) {
virReportOOMError();
- goto failure;
+ goto cleanup;
}
/*
/* def:graphics */
if (VIR_ALLOC_N(def->graphics, 1) < 0) {
virReportOOMError();
- goto failure;
+ goto cleanup;
}
def->ngraphics = 0;
if (esxVMX_ParseVNC(conf, &def->graphics[def->ngraphics]) < 0) {
- goto failure;
+ goto cleanup;
}
if (def->graphics[def->ngraphics] != NULL) {
/* def:disks: 4 * 15 scsi + 2 * 2 ide + 2 floppy = 66 */
if (VIR_ALLOC_N(def->disks, 66) < 0) {
virReportOOMError();
- goto failure;
+ goto cleanup;
}
def->ndisks = 0;
if (esxVMX_ParseSCSIController(conf, controller, &present,
&scsi_virtualDev) < 0) {
- goto failure;
+ goto cleanup;
}
if (! present) {
VIR_DOMAIN_DISK_BUS_SCSI, controller, id,
scsi_virtualDev, datastoreName, directoryName,
&def->disks[def->ndisks]) < 0) {
- goto failure;
+ goto cleanup;
}
if (def->disks[def->ndisks] != NULL) {
VIR_DOMAIN_DISK_BUS_SCSI, controller, id,
scsi_virtualDev, datastoreName, directoryName,
&def->disks[def->ndisks]) < 0) {
- goto failure;
+ goto cleanup;
}
if (def->disks[def->ndisks] != NULL) {
VIR_DOMAIN_DISK_BUS_IDE, controller, id,
NULL, datastoreName, directoryName,
&def->disks[def->ndisks]) < 0) {
- goto failure;
+ goto cleanup;
}
if (def->disks[def->ndisks] != NULL) {
VIR_DOMAIN_DISK_BUS_IDE, controller, id,
NULL, datastoreName, directoryName,
&def->disks[def->ndisks]) < 0) {
- goto failure;
+ goto cleanup;
}
if (def->disks[def->ndisks] != NULL) {
VIR_DOMAIN_DISK_BUS_FDC, controller, -1, NULL,
datastoreName, directoryName,
&def->disks[def->ndisks]) < 0) {
- goto failure;
+ goto cleanup;
}
if (def->disks[def->ndisks] != NULL) {
/* def:nets */
if (VIR_ALLOC_N(def->nets, 4) < 0) {
virReportOOMError();
- goto failure;
+ goto cleanup;
}
def->nnets = 0;
for (controller = 0; controller < 4; ++controller) {
if (esxVMX_ParseEthernet(conf, controller,
&def->nets[def->nnets]) < 0) {
- goto failure;
+ goto cleanup;
}
if (def->nets[def->nnets] != NULL) {
/* def:serials */
if (VIR_ALLOC_N(def->serials, 4) < 0) {
virReportOOMError();
- goto failure;
+ goto cleanup;
}
def->nserials = 0;
if (esxVMX_ParseSerial(ctx, conf, port, datastoreName,
directoryName,
&def->serials[def->nserials]) < 0) {
- goto failure;
+ goto cleanup;
}
if (def->serials[def->nserials] != NULL) {
/* def:parallels */
if (VIR_ALLOC_N(def->parallels, 3) < 0) {
virReportOOMError();
- goto failure;
+ goto cleanup;
}
def->nparallels = 0;
if (esxVMX_ParseParallel(ctx, conf, port, datastoreName,
directoryName,
&def->parallels[def->nparallels]) < 0) {
- goto failure;
+ goto cleanup;
}
if (def->parallels[def->nparallels] != NULL) {
}
}
+ success = true;
+
cleanup:
+ if (! success) {
+ virDomainDefFree(def);
+ def = NULL;
+ }
+
virConfFree(conf);
VIR_FREE(sched_cpu_affinity);
VIR_FREE(guestOS);
VIR_FREE(scsi_virtualDev);
return def;
-
- failure:
- virDomainDefFree(def);
- def = NULL;
-
- goto cleanup;
}
* virtualDev = NULL
*/
- int result = 0;
+ int result = -1;
char *prefix = NULL;
char present_name[32] = "";
if (VIR_ALLOC(*def) < 0) {
virReportOOMError();
- goto failure;
+ return -1;
}
(*def)->device = device;
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("SCSI controller index %d out of [0..3] range"),
controller);
- goto failure;
+ goto cleanup;
}
if (id < 0 || id > 15 || id == 7) {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("SCSI ID %d out of [0..6,8..15] range"), id);
- goto failure;
+ goto cleanup;
}
if (virAsprintf(&prefix, "scsi%d:%d", controller, id) < 0) {
virReportOOMError();
- goto failure;
+ goto cleanup;
}
(*def)->dst =
(controller * 15 + (id < 7 ? id : id - 1), "sd");
if ((*def)->dst == NULL) {
- goto failure;
+ goto cleanup;
}
if (virtualDev != NULL) {
if ((*def)->driverName == NULL) {
virReportOOMError();
- goto failure;
+ goto cleanup;
}
}
} else if (bus == VIR_DOMAIN_DISK_BUS_IDE) {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("IDE controller index %d out of [0..1] range"),
controller);
- goto failure;
+ goto cleanup;
}
if (id < 0 || id > 1) {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("IDE ID %d out of [0..1] range"), id);
- goto failure;
+ goto cleanup;
}
if (virAsprintf(&prefix, "ide%d:%d", controller, id) < 0) {
virReportOOMError();
- goto failure;
+ goto cleanup;
}
(*def)->dst = virIndexToDiskName(controller * 2 + id, "hd");
if ((*def)->dst == NULL) {
- goto failure;
+ goto cleanup;
}
} else {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Unsupported bus type '%s' for device type '%s'"),
virDomainDiskBusTypeToString(bus),
virDomainDiskDeviceTypeToString(device));
- goto failure;
+ goto cleanup;
}
} else if (device == VIR_DOMAIN_DISK_DEVICE_FLOPPY) {
if (bus == VIR_DOMAIN_DISK_BUS_FDC) {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Floppy controller index %d out of [0..1] range"),
controller);
- goto failure;
+ goto cleanup;
}
if (virAsprintf(&prefix, "floppy%d", controller) < 0) {
virReportOOMError();
- goto failure;
+ goto cleanup;
}
(*def)->dst = virIndexToDiskName(controller, "fd");
if ((*def)->dst == NULL) {
- goto failure;
+ goto cleanup;
}
} else {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Unsupported bus type '%s' for device type '%s'"),
virDomainDiskBusTypeToString(bus),
virDomainDiskDeviceTypeToString(device));
- goto failure;
+ goto cleanup;
}
} else {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Unsupported device type '%s'"),
virDomainDiskDeviceTypeToString(device));
- goto failure;
+ goto cleanup;
}
ESX_BUILD_VMX_NAME(present);
/* vmx:present */
if (esxUtil_GetConfigBoolean(conf, present_name, &present, 0, 1) < 0) {
- goto failure;
+ goto cleanup;
}
/* vmx:startConnected */
if (esxUtil_GetConfigBoolean(conf, startConnected_name, &startConnected,
1, 1) < 0) {
- goto failure;
+ goto cleanup;
}
/* FIXME: Need to distiguish between active and inactive domains here */
/* vmx:deviceType -> def:type */
if (esxUtil_GetConfigString(conf, deviceType_name, &deviceType, 1) < 0) {
- goto failure;
+ goto cleanup;
}
/* vmx:clientDevice */
if (esxUtil_GetConfigBoolean(conf, clientDevice_name, &clientDevice, 0,
1) < 0) {
- goto failure;
+ goto cleanup;
}
if (clientDevice) {
/* vmx:fileType -> def:type */
if (esxUtil_GetConfigString(conf, fileType_name, &fileType, 1) < 0) {
- goto failure;
+ goto cleanup;
}
/* vmx:fileName -> def:src, def:type */
if (esxUtil_GetConfigString(conf, fileName_name, &fileName, 0) < 0) {
- goto failure;
+ goto cleanup;
}
/* vmx:writeThrough -> def:cachemode */
if (esxUtil_GetConfigBoolean(conf, writeThrough_name, &writeThrough, 0,
1) < 0) {
- goto failure;
+ goto cleanup;
}
/* Setup virDomainDiskDef */
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Expecting VMX entry '%s' to be 'scsi-hardDisk' "
"but found '%s'"), deviceType_name, deviceType);
- goto failure;
+ goto cleanup;
} else if (bus == VIR_DOMAIN_DISK_BUS_IDE &&
STRCASENEQ(deviceType, "ata-hardDisk")) {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Expecting VMX entry '%s' to be 'ata-hardDisk' "
"but found '%s'"), deviceType_name, deviceType);
- goto failure;
+ goto cleanup;
}
}
: VIR_DOMAIN_DISK_CACHE_DEFAULT;
if ((*def)->src == NULL) {
- goto failure;
+ goto cleanup;
}
} else if (virFileHasSuffix(fileName, ".iso") ||
STREQ(deviceType, "atapi-cdrom")) {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Invalid or not yet handled value '%s' for VMX entry "
"'%s'"), fileName, fileName_name);
- goto failure;
+ goto cleanup;
}
} else if (device == VIR_DOMAIN_DISK_DEVICE_CDROM) {
if (virFileHasSuffix(fileName, ".iso")) {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Expecting VMX entry '%s' to be 'cdrom-image' "
"but found '%s'"), deviceType_name, deviceType);
- goto failure;
+ goto cleanup;
}
}
directoryName);
if ((*def)->src == NULL) {
- goto failure;
+ goto cleanup;
}
} else if (virFileHasSuffix(fileName, ".vmdk")) {
/*
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Invalid or not yet handled value '%s' for VMX entry "
"'%s'"), fileName, fileName_name);
- goto failure;
+ goto cleanup;
}
} else if (device == VIR_DOMAIN_DISK_DEVICE_FLOPPY) {
if (virFileHasSuffix(fileName, ".flp")) {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Expecting VMX entry '%s' to be 'file' but "
"found '%s'"), fileType_name, fileType);
- goto failure;
+ goto cleanup;
}
}
directoryName);
if ((*def)->src == NULL) {
- goto failure;
+ goto cleanup;
}
} else if (fileType != NULL && STREQ(fileType, "device")) {
(*def)->type = VIR_DOMAIN_DISK_TYPE_BLOCK;
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Invalid or not yet handled value '%s' for VMX entry "
"'%s'"), fileName, fileName_name);
- goto failure;
+ goto cleanup;
}
} else {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, _("Unsupported device type '%s'"),
virDomainDiskDeviceTypeToString(device));
- goto failure;
+ goto cleanup;
}
+ result = 0;
+
cleanup:
+ if (result < 0) {
+ virDomainDiskDefFree(*def);
+ *def = NULL;
+ }
+
VIR_FREE(prefix);
VIR_FREE(deviceType);
VIR_FREE(fileType);
return result;
- failure:
- result = -1;
-
ignore:
virDomainDiskDefFree(*def);
*def = NULL;
+ result = 0;
+
goto cleanup;
}
int
esxVMX_ParseEthernet(virConfPtr conf, int controller, virDomainNetDefPtr *def)
{
- int result = 0;
+ int result = -1;
char prefix[48] = "";
char present_name[48] = "";
if (VIR_ALLOC(*def) < 0) {
virReportOOMError();
- goto failure;
+ return -1;
}
snprintf(prefix, sizeof(prefix), "ethernet%d", controller);
/* vmx:present */
if (esxUtil_GetConfigBoolean(conf, present_name, &present, 0, 1) < 0) {
- goto failure;
+ goto cleanup;
}
/* vmx:startConnected */
if (esxUtil_GetConfigBoolean(conf, startConnected_name, &startConnected, 1,
1) < 0) {
- goto failure;
+ goto cleanup;
}
/* FIXME: Need to distiguish between active and inactive domains here */
/* vmx:connectionType -> def:type */
if (esxUtil_GetConfigString(conf, connectionType_name, &connectionType,
1) < 0) {
- goto failure;
+ goto cleanup;
}
/* vmx:addressType, vmx:generatedAddress, vmx:address -> def:mac */
esxUtil_GetConfigString(conf, generatedAddress_name, &generatedAddress,
1) < 0 ||
esxUtil_GetConfigString(conf, address_name, &address, 1) < 0) {
- goto failure;
+ goto cleanup;
}
if (addressType == NULL || STRCASEEQ(addressType, "generated") ||
_("Expecting VMX entry '%s' to be MAC address but "
"found '%s'"), generatedAddress_name,
generatedAddress);
- goto failure;
+ goto cleanup;
}
}
} else if (STRCASEEQ(addressType, "static")) {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Expecting VMX entry '%s' to be MAC address but "
"found '%s'"), address_name, address);
- goto failure;
+ goto cleanup;
}
}
} else {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Expecting VMX entry '%s' to be 'generated' or 'static' or "
"'vpx' but found '%s'"), addressType_name, addressType);
- goto failure;
+ goto cleanup;
}
/* vmx:virtualDev, vmx:features -> def:model */
if (esxUtil_GetConfigString(conf, virtualDev_name, &virtualDev, 1) < 0 ||
esxUtil_GetConfigLong(conf, features_name, &features, 0, 1) < 0) {
- goto failure;
+ goto cleanup;
}
if (virtualDev != NULL) {
_("Expecting VMX entry '%s' to be 'vlance' or 'vmxnet' or "
"'vmxnet3' or 'e1000' but found '%s'"), virtualDev_name,
virtualDev);
- goto failure;
+ goto cleanup;
}
if (STRCASEEQ(virtualDev, "vmxnet") && features == 15) {
if (virtualDev == NULL) {
virReportOOMError();
- goto failure;
+ goto cleanup;
}
}
}
STRCASEEQ(connectionType, "bridged") ||
STRCASEEQ(connectionType, "custom")) &&
esxUtil_GetConfigString(conf, networkName_name, &networkName, 0) < 0) {
- goto failure;
+ goto cleanup;
}
/* vmx:vnet -> def:data.ifname */
if (connectionType != NULL && STRCASEEQ(connectionType, "custom") &&
esxUtil_GetConfigString(conf, vnet_name, &vnet, 0) < 0) {
- goto failure;
+ goto cleanup;
}
/* Setup virDomainNetDef */
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("No yet handled value '%s' for VMX entry '%s'"),
connectionType, connectionType_name);
- goto failure;
+ goto cleanup;
} else if (STRCASEEQ(connectionType, "nat")) {
/* FIXME */
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("No yet handled value '%s' for VMX entry '%s'"),
connectionType, connectionType_name);
- goto failure;
+ goto cleanup;
} else if (STRCASEEQ(connectionType, "custom")) {
(*def)->type = VIR_DOMAIN_NET_TYPE_BRIDGE;
(*def)->model = virtualDev;
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Invalid value '%s' for VMX entry '%s'"), connectionType,
connectionType_name);
- goto failure;
+ goto cleanup;
}
+ result = 0;
+
cleanup:
+ if (result < 0) {
+ virDomainNetDefFree(*def);
+ *def = NULL;
+ }
+
VIR_FREE(connectionType);
VIR_FREE(addressType);
VIR_FREE(generatedAddress);
return result;
- failure:
- result = -1;
-
ignore:
virDomainNetDefFree(*def);
*def = NULL;
+ result = 0;
+
goto cleanup;
}
const char *datastoreName, const char *directoryName,
virDomainChrDefPtr *def)
{
- int result = 0;
+ int result = -1;
char prefix[48] = "";
char present_name[48] = "";
if (VIR_ALLOC(*def) < 0) {
virReportOOMError();
- goto failure;
+ return -1;
}
(*def)->targetType = VIR_DOMAIN_CHR_TARGET_TYPE_SERIAL;
/* vmx:present */
if (esxUtil_GetConfigBoolean(conf, present_name, &present, 0, 1) < 0) {
- goto failure;
+ goto cleanup;
}
/* vmx:startConnected */
if (esxUtil_GetConfigBoolean(conf, startConnected_name, &startConnected, 1,
1) < 0) {
- goto failure;
+ goto cleanup;
}
/* FIXME: Need to distiguish between active and inactive domains here */
/* vmx:fileType -> def:type */
if (esxUtil_GetConfigString(conf, fileType_name, &fileType, 0) < 0) {
- goto failure;
+ goto cleanup;
}
/* vmx:fileName -> def:data.file.path */
if (esxUtil_GetConfigString(conf, fileName_name, &fileName, 0) < 0) {
- goto failure;
+ goto cleanup;
}
/* Setup virDomainChrDef */
directoryName);
if ((*def)->data.file.path == NULL) {
- goto failure;
+ goto cleanup;
}
} else if (STRCASEEQ(fileType, "pipe")) {
/*
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Expecting VMX entry '%s' to be 'device', 'file' or 'pipe' "
"but found '%s'"), fileType_name, fileType);
- goto failure;
+ goto cleanup;
}
+ result = 0;
+
cleanup:
+ if (result < 0) {
+ virDomainChrDefFree(*def);
+ *def = NULL;
+ }
+
VIR_FREE(fileType);
VIR_FREE(fileName);
return result;
- failure:
- result = -1;
-
ignore:
virDomainChrDefFree(*def);
*def = NULL;
+ result = 0;
+
goto cleanup;
}
const char *datastoreName, const char *directoryName,
virDomainChrDefPtr *def)
{
- int result = 0;
+ int result = -1;
char prefix[48] = "";
char present_name[48] = "";
if (VIR_ALLOC(*def) < 0) {
virReportOOMError();
- goto failure;
+ return -1;
}
(*def)->targetType = VIR_DOMAIN_CHR_TARGET_TYPE_PARALLEL;
/* vmx:present */
if (esxUtil_GetConfigBoolean(conf, present_name, &present, 0, 1) < 0) {
- goto failure;
+ goto cleanup;
}
/* vmx:startConnected */
if (esxUtil_GetConfigBoolean(conf, startConnected_name, &startConnected, 1,
1) < 0) {
- goto failure;
+ goto cleanup;
}
/* FIXME: Need to distiguish between active and inactive domains here */
/* vmx:fileType -> def:type */
if (esxUtil_GetConfigString(conf, fileType_name, &fileType, 0) < 0) {
- goto failure;
+ goto cleanup;
}
/* vmx:fileName -> def:data.file.path */
if (esxUtil_GetConfigString(conf, fileName_name, &fileName, 0) < 0) {
- goto failure;
+ goto cleanup;
}
/* Setup virDomainChrDef */
directoryName);
if ((*def)->data.file.path == NULL) {
- goto failure;
+ goto cleanup;
}
} else {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Expecting VMX entry '%s' to be 'device' or 'file' but "
"found '%s'"), fileType_name, fileType);
- goto failure;
+ goto cleanup;
}
+ result = 0;
+
cleanup:
+ if (result < 0) {
+ virDomainChrDefFree(*def);
+ *def = NULL;
+ }
+
VIR_FREE(fileType);
VIR_FREE(fileName);
return result;
- failure:
- result = -1;
-
ignore:
virDomainChrDefFree(*def);
*def = NULL;
+ result = 0;
+
goto cleanup;
}
char *
esxVMX_FormatFileName(esxVI_Context *ctx ATTRIBUTE_UNUSED, const char *src)
{
+ bool success = false;
char *datastoreName = NULL;
char *directoryName = NULL;
char *fileName = NULL;
/* Found potential datastore related path */
if (esxUtil_ParseDatastoreRelatedPath(src, &datastoreName,
&directoryName, &fileName) < 0) {
- goto failure;
+ goto cleanup;
}
if (directoryName == NULL) {
if (virAsprintf(&absolutePath, "/vmfs/volumes/%s/%s",
datastoreName, fileName) < 0) {
virReportOOMError();
- goto failure;
+ goto cleanup;
}
} else {
if (virAsprintf(&absolutePath, "/vmfs/volumes/%s/%s/%s",
datastoreName, directoryName, fileName) < 0) {
virReportOOMError();
- goto failure;
+ goto cleanup;
}
}
} else if (STRPREFIX(src, "/")) {
if (absolutePath == NULL) {
virReportOOMError();
- goto failure;
+ goto cleanup;
}
} else {
/* Found relative path, this is not supported */
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Found relative path '%s' in domain XML, this is not "
"supported"), src);
- goto failure;
+ goto cleanup;
}
/* FIXME: Check if referenced path/file really exists */
+ success = true;
+
cleanup:
+ if (! success) {
+ VIR_FREE(absolutePath);
+ }
+
VIR_FREE(datastoreName);
VIR_FREE(directoryName);
VIR_FREE(fileName);
return absolutePath;
-
- failure:
- VIR_FREE(absolutePath);
-
- goto cleanup;
}