提交 041aac86 编写于 作者: M Matthias Bolte

esx: Simplify goto usage

Eliminate almost all backward jumps by replacing this common pattern:

int
some_random_function(void)
{
    int result = 0;
    ...

  cleanup:
    <unconditional cleanup code>
    return result;

  failure:
    <cleanup code in case of an error>
    result = -1;
    goto cleanup
}

with this simpler pattern:

int
some_random_function(void)
{
    int result = -1;
    ...
    result = 0;

  cleanup:
    if (result < 0) {
        <cleanup code in case of an error>
    }

    <unconditional cleanup code>
    return result;
}

Add a bool success variable in functions that don't have a int result
that can be used for the new pattern.

Also remove some unnecessary memsets in error paths.
上级 8b0cd876
...@@ -68,7 +68,7 @@ esxSupportsLongMode(esxPrivate *priv) ...@@ -68,7 +68,7 @@ esxSupportsLongMode(esxPrivate *priv)
} }
if (esxVI_EnsureSession(priv->host) < 0) { if (esxVI_EnsureSession(priv->host) < 0) {
goto failure; return esxVI_Boolean_Undefined;
} }
if (esxVI_String_AppendValueToList(&propertyNameList, if (esxVI_String_AppendValueToList(&propertyNameList,
...@@ -76,13 +76,13 @@ esxSupportsLongMode(esxPrivate *priv) ...@@ -76,13 +76,13 @@ esxSupportsLongMode(esxPrivate *priv)
esxVI_LookupObjectContentByType(priv->host, priv->host->hostFolder, esxVI_LookupObjectContentByType(priv->host, priv->host->hostFolder,
"HostSystem", propertyNameList, "HostSystem", propertyNameList,
esxVI_Boolean_True, &hostSystem) < 0) { esxVI_Boolean_True, &hostSystem) < 0) {
goto failure; goto cleanup;
} }
if (hostSystem == NULL) { if (hostSystem == NULL) {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
_("Could not retrieve the HostSystem object")); _("Could not retrieve the HostSystem object"));
goto failure; goto cleanup;
} }
for (dynamicProperty = hostSystem->propSet; dynamicProperty != NULL; for (dynamicProperty = hostSystem->propSet; dynamicProperty != NULL;
...@@ -90,7 +90,7 @@ esxSupportsLongMode(esxPrivate *priv) ...@@ -90,7 +90,7 @@ esxSupportsLongMode(esxPrivate *priv)
if (STREQ(dynamicProperty->name, "hardware.cpuFeature")) { if (STREQ(dynamicProperty->name, "hardware.cpuFeature")) {
if (esxVI_HostCpuIdInfo_CastListFromAnyType if (esxVI_HostCpuIdInfo_CastListFromAnyType
(dynamicProperty->val, &hostCpuIdInfoList) < 0) { (dynamicProperty->val, &hostCpuIdInfoList) < 0) {
goto failure; goto cleanup;
} }
for (hostCpuIdInfo = hostCpuIdInfoList; hostCpuIdInfo != NULL; for (hostCpuIdInfo = hostCpuIdInfoList; hostCpuIdInfo != NULL;
...@@ -98,7 +98,7 @@ esxSupportsLongMode(esxPrivate *priv) ...@@ -98,7 +98,7 @@ esxSupportsLongMode(esxPrivate *priv)
if (hostCpuIdInfo->level->value == -2147483647) { /* 0x80000001 */ if (hostCpuIdInfo->level->value == -2147483647) { /* 0x80000001 */
if (esxVI_ParseHostCpuIdInfo(&parsedHostCpuIdInfo, if (esxVI_ParseHostCpuIdInfo(&parsedHostCpuIdInfo,
hostCpuIdInfo) < 0) { hostCpuIdInfo) < 0) {
goto failure; goto cleanup;
} }
edxLongModeBit = parsedHostCpuIdInfo.edx[29]; edxLongModeBit = parsedHostCpuIdInfo.edx[29];
...@@ -113,7 +113,7 @@ esxSupportsLongMode(esxPrivate *priv) ...@@ -113,7 +113,7 @@ esxSupportsLongMode(esxPrivate *priv)
"'hardware.cpuFeature[].edx' with value '%s' " "'hardware.cpuFeature[].edx' with value '%s' "
"has unexpected value '%c', expecting '0' " "has unexpected value '%c', expecting '0' "
"or '1'"), hostCpuIdInfo->edx, edxLongModeBit); "or '1'"), hostCpuIdInfo->edx, edxLongModeBit);
goto failure; goto cleanup;
} }
break; break;
...@@ -127,16 +127,15 @@ esxSupportsLongMode(esxPrivate *priv) ...@@ -127,16 +127,15 @@ esxSupportsLongMode(esxPrivate *priv)
} }
cleanup: 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_String_Free(&propertyNameList);
esxVI_ObjectContent_Free(&hostSystem); esxVI_ObjectContent_Free(&hostSystem);
esxVI_HostCpuIdInfo_Free(&hostCpuIdInfoList); esxVI_HostCpuIdInfo_Free(&hostCpuIdInfoList);
return priv->supportsLongMode; return priv->supportsLongMode;
failure:
priv->supportsLongMode = esxVI_Boolean_Undefined;
goto cleanup;
} }
...@@ -313,7 +312,7 @@ esxCapsInit(esxPrivate *priv) ...@@ -313,7 +312,7 @@ esxCapsInit(esxPrivate *priv)
static virDrvOpenStatus static virDrvOpenStatus
esxOpen(virConnectPtr conn, virConnectAuthPtr auth, int flags ATTRIBUTE_UNUSED) esxOpen(virConnectPtr conn, virConnectAuthPtr auth, int flags ATTRIBUTE_UNUSED)
{ {
virDrvOpenStatus result = VIR_DRV_OPEN_SUCCESS; virDrvOpenStatus result = VIR_DRV_OPEN_ERROR;
esxPrivate *priv = NULL; esxPrivate *priv = NULL;
char hostIpAddress[NI_MAXHOST] = ""; char hostIpAddress[NI_MAXHOST] = "";
char vCenterIpAddress[NI_MAXHOST] = ""; char vCenterIpAddress[NI_MAXHOST] = "";
...@@ -347,7 +346,7 @@ esxOpen(virConnectPtr conn, virConnectAuthPtr auth, int flags ATTRIBUTE_UNUSED) ...@@ -347,7 +346,7 @@ esxOpen(virConnectPtr conn, virConnectAuthPtr auth, int flags ATTRIBUTE_UNUSED)
/* Allocate per-connection private data */ /* Allocate per-connection private data */
if (VIR_ALLOC(priv) < 0) { if (VIR_ALLOC(priv) < 0) {
virReportOOMError(); virReportOOMError();
goto failure; goto cleanup;
} }
priv->maxVcpus = -1; priv->maxVcpus = -1;
...@@ -358,7 +357,7 @@ esxOpen(virConnectPtr conn, virConnectAuthPtr auth, int flags ATTRIBUTE_UNUSED) ...@@ -358,7 +357,7 @@ esxOpen(virConnectPtr conn, virConnectAuthPtr auth, int flags ATTRIBUTE_UNUSED)
if (esxUtil_ParseQuery(conn->uri, &priv->transport, &vCenter, &noVerify, if (esxUtil_ParseQuery(conn->uri, &priv->transport, &vCenter, &noVerify,
&autoAnswer) < 0) { &autoAnswer) < 0) {
goto failure; goto cleanup;
} }
if (autoAnswer) { if (autoAnswer) {
...@@ -390,13 +389,13 @@ esxOpen(virConnectPtr conn, virConnectAuthPtr auth, int flags ATTRIBUTE_UNUSED) ...@@ -390,13 +389,13 @@ esxOpen(virConnectPtr conn, virConnectAuthPtr auth, int flags ATTRIBUTE_UNUSED)
/* Login to host */ /* Login to host */
if (esxUtil_ResolveHostname(conn->uri->server, hostIpAddress, if (esxUtil_ResolveHostname(conn->uri->server, hostIpAddress,
NI_MAXHOST) < 0) { NI_MAXHOST) < 0) {
goto failure; goto cleanup;
} }
if (virAsprintf(&url, "%s://%s:%d/sdk", priv->transport, if (virAsprintf(&url, "%s://%s:%d/sdk", priv->transport,
conn->uri->server, conn->uri->port) < 0) { conn->uri->server, conn->uri->port) < 0) {
virReportOOMError(); virReportOOMError();
goto failure; goto cleanup;
} }
if (conn->uri->user != NULL) { if (conn->uri->user != NULL) {
...@@ -404,31 +403,31 @@ esxOpen(virConnectPtr conn, virConnectAuthPtr auth, int flags ATTRIBUTE_UNUSED) ...@@ -404,31 +403,31 @@ esxOpen(virConnectPtr conn, virConnectAuthPtr auth, int flags ATTRIBUTE_UNUSED)
if (username == NULL) { if (username == NULL) {
virReportOOMError(); virReportOOMError();
goto failure; goto cleanup;
} }
} else { } else {
username = virRequestUsername(auth, "root", conn->uri->server); username = virRequestUsername(auth, "root", conn->uri->server);
if (username == NULL) { if (username == NULL) {
ESX_ERROR(VIR_ERR_AUTH_FAILED, "%s", _("Username request failed")); ESX_ERROR(VIR_ERR_AUTH_FAILED, "%s", _("Username request failed"));
goto failure; goto cleanup;
} }
} }
if (esxVI_Context_Alloc(&priv->host) < 0) { if (esxVI_Context_Alloc(&priv->host) < 0) {
goto failure; goto cleanup;
} }
password = virRequestPassword(auth, username, conn->uri->server); password = virRequestPassword(auth, username, conn->uri->server);
if (password == NULL) { if (password == NULL) {
ESX_ERROR(VIR_ERR_AUTH_FAILED, "%s", _("Password request failed")); ESX_ERROR(VIR_ERR_AUTH_FAILED, "%s", _("Password request failed"));
goto failure; goto cleanup;
} }
if (esxVI_Context_Connect(priv->host, url, hostIpAddress, username, if (esxVI_Context_Connect(priv->host, url, hostIpAddress, username,
password, noVerify) < 0) { password, noVerify) < 0) {
goto failure; goto cleanup;
} }
if (STRCASEEQ(conn->uri->scheme, "esx")) { if (STRCASEEQ(conn->uri->scheme, "esx")) {
...@@ -437,13 +436,13 @@ esxOpen(virConnectPtr conn, virConnectAuthPtr auth, int flags ATTRIBUTE_UNUSED) ...@@ -437,13 +436,13 @@ esxOpen(virConnectPtr conn, virConnectAuthPtr auth, int flags ATTRIBUTE_UNUSED)
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("%s is neither an ESX 3.5 host nor an ESX 4.0 host"), _("%s is neither an ESX 3.5 host nor an ESX 4.0 host"),
conn->uri->server); conn->uri->server);
goto failure; goto cleanup;
} }
} else { /* GSX */ } else { /* GSX */
if (priv->host->productVersion != esxVI_ProductVersion_GSX20) { if (priv->host->productVersion != esxVI_ProductVersion_GSX20) {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("%s isn't a GSX 2.0 host"), conn->uri->server); _("%s isn't a GSX 2.0 host"), conn->uri->server);
goto failure; goto cleanup;
} }
} }
...@@ -453,7 +452,7 @@ esxOpen(virConnectPtr conn, virConnectAuthPtr auth, int flags ATTRIBUTE_UNUSED) ...@@ -453,7 +452,7 @@ esxOpen(virConnectPtr conn, virConnectAuthPtr auth, int flags ATTRIBUTE_UNUSED)
"summary.managementServerIp\0") < 0 || "summary.managementServerIp\0") < 0 ||
esxVI_LookupHostSystemByIp(priv->host, hostIpAddress, propertyNameList, esxVI_LookupHostSystemByIp(priv->host, hostIpAddress, propertyNameList,
&hostSystem) < 0) { &hostSystem) < 0) {
goto failure; goto cleanup;
} }
/* Warn if host is in maintenance mode */ /* Warn if host is in maintenance mode */
...@@ -462,7 +461,7 @@ esxOpen(virConnectPtr conn, virConnectAuthPtr auth, int flags ATTRIBUTE_UNUSED) ...@@ -462,7 +461,7 @@ esxOpen(virConnectPtr conn, virConnectAuthPtr auth, int flags ATTRIBUTE_UNUSED)
if (STREQ(dynamicProperty->name, "runtime.inMaintenanceMode")) { if (STREQ(dynamicProperty->name, "runtime.inMaintenanceMode")) {
if (esxVI_AnyType_ExpectType(dynamicProperty->val, if (esxVI_AnyType_ExpectType(dynamicProperty->val,
esxVI_Type_Boolean) < 0) { esxVI_Type_Boolean) < 0) {
goto failure; goto cleanup;
} }
if (dynamicProperty->val->boolean == esxVI_Boolean_True) { if (dynamicProperty->val->boolean == esxVI_Boolean_True) {
...@@ -483,7 +482,7 @@ esxOpen(virConnectPtr conn, virConnectAuthPtr auth, int flags ATTRIBUTE_UNUSED) ...@@ -483,7 +482,7 @@ esxOpen(virConnectPtr conn, virConnectAuthPtr auth, int flags ATTRIBUTE_UNUSED)
if (STRNEQ(vCenter, "*") && if (STRNEQ(vCenter, "*") &&
esxUtil_ResolveHostname(vCenter, vCenterIpAddress, esxUtil_ResolveHostname(vCenter, vCenterIpAddress,
NI_MAXHOST) < 0) { NI_MAXHOST) < 0) {
goto failure; goto cleanup;
} }
/* Lookup the vCenter from the ESX host */ /* Lookup the vCenter from the ESX host */
...@@ -492,7 +491,7 @@ esxOpen(virConnectPtr conn, virConnectAuthPtr auth, int flags ATTRIBUTE_UNUSED) ...@@ -492,7 +491,7 @@ esxOpen(virConnectPtr conn, virConnectAuthPtr auth, int flags ATTRIBUTE_UNUSED)
if (STREQ(dynamicProperty->name, "summary.managementServerIp")) { if (STREQ(dynamicProperty->name, "summary.managementServerIp")) {
if (esxVI_AnyType_ExpectType(dynamicProperty->val, if (esxVI_AnyType_ExpectType(dynamicProperty->val,
esxVI_Type_String) < 0) { esxVI_Type_String) < 0) {
goto failure; goto cleanup;
} }
/* Get the vCenter IP address or verify the specified one */ /* Get the vCenter IP address or verify the specified one */
...@@ -503,7 +502,7 @@ esxOpen(virConnectPtr conn, virConnectAuthPtr auth, int flags ATTRIBUTE_UNUSED) ...@@ -503,7 +502,7 @@ esxOpen(virConnectPtr conn, virConnectAuthPtr auth, int flags ATTRIBUTE_UNUSED)
if (vCenter == NULL) { if (vCenter == NULL) {
virReportOOMError(); virReportOOMError();
goto failure; goto cleanup;
} }
if (virStrcpyStatic(vCenterIpAddress, if (virStrcpyStatic(vCenterIpAddress,
...@@ -512,7 +511,7 @@ esxOpen(virConnectPtr conn, virConnectAuthPtr auth, int flags ATTRIBUTE_UNUSED) ...@@ -512,7 +511,7 @@ esxOpen(virConnectPtr conn, virConnectAuthPtr auth, int flags ATTRIBUTE_UNUSED)
_("vCenter IP address %s too big for " _("vCenter IP address %s too big for "
"destination"), "destination"),
dynamicProperty->val->string); dynamicProperty->val->string);
goto failure; goto cleanup;
} }
} else if (STRNEQ(vCenterIpAddress, } else if (STRNEQ(vCenterIpAddress,
dynamicProperty->val->string)) { dynamicProperty->val->string)) {
...@@ -522,7 +521,7 @@ esxOpen(virConnectPtr conn, virConnectAuthPtr auth, int flags ATTRIBUTE_UNUSED) ...@@ -522,7 +521,7 @@ esxOpen(virConnectPtr conn, virConnectAuthPtr auth, int flags ATTRIBUTE_UNUSED)
"(%s) has been specified"), "(%s) has been specified"),
dynamicProperty->val->string, vCenter, dynamicProperty->val->string, vCenter,
vCenterIpAddress); vCenterIpAddress);
goto failure; goto cleanup;
} }
break; break;
...@@ -532,36 +531,36 @@ esxOpen(virConnectPtr conn, virConnectAuthPtr auth, int flags ATTRIBUTE_UNUSED) ...@@ -532,36 +531,36 @@ esxOpen(virConnectPtr conn, virConnectAuthPtr auth, int flags ATTRIBUTE_UNUSED)
if (STREQ(vCenter, "*")) { if (STREQ(vCenter, "*")) {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
_("This host is not managed by a vCenter")); _("This host is not managed by a vCenter"));
goto failure; goto cleanup;
} }
if (virAsprintf(&url, "%s://%s/sdk", priv->transport, if (virAsprintf(&url, "%s://%s/sdk", priv->transport,
vCenter) < 0) { vCenter) < 0) {
virReportOOMError(); virReportOOMError();
goto failure; goto cleanup;
} }
if (esxVI_Context_Alloc(&priv->vCenter) < 0) { if (esxVI_Context_Alloc(&priv->vCenter) < 0) {
goto failure; goto cleanup;
} }
username = virRequestUsername(auth, "administrator", vCenter); username = virRequestUsername(auth, "administrator", vCenter);
if (username == NULL) { if (username == NULL) {
ESX_ERROR(VIR_ERR_AUTH_FAILED, "%s", _("Username request failed")); ESX_ERROR(VIR_ERR_AUTH_FAILED, "%s", _("Username request failed"));
goto failure; goto cleanup;
} }
password = virRequestPassword(auth, username, vCenter); password = virRequestPassword(auth, username, vCenter);
if (password == NULL) { if (password == NULL) {
ESX_ERROR(VIR_ERR_AUTH_FAILED, "%s", _("Password request failed")); ESX_ERROR(VIR_ERR_AUTH_FAILED, "%s", _("Password request failed"));
goto failure; goto cleanup;
} }
if (esxVI_Context_Connect(priv->vCenter, url, vCenterIpAddress, if (esxVI_Context_Connect(priv->vCenter, url, vCenterIpAddress,
username, password, noVerify) < 0) { username, password, noVerify) < 0) {
goto failure; goto cleanup;
} }
if (priv->vCenter->productVersion != esxVI_ProductVersion_VPX25 && if (priv->vCenter->productVersion != esxVI_ProductVersion_VPX25 &&
...@@ -569,7 +568,7 @@ esxOpen(virConnectPtr conn, virConnectAuthPtr auth, int flags ATTRIBUTE_UNUSED) ...@@ -569,7 +568,7 @@ esxOpen(virConnectPtr conn, virConnectAuthPtr auth, int flags ATTRIBUTE_UNUSED)
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("%s is neither a vCenter 2.5 server nor a vCenter " _("%s is neither a vCenter 2.5 server nor a vCenter "
"4.0 server"), conn->uri->server); "4.0 server"), conn->uri->server);
goto failure; goto cleanup;
} }
} }
...@@ -579,21 +578,13 @@ esxOpen(virConnectPtr conn, virConnectAuthPtr auth, int flags ATTRIBUTE_UNUSED) ...@@ -579,21 +578,13 @@ esxOpen(virConnectPtr conn, virConnectAuthPtr auth, int flags ATTRIBUTE_UNUSED)
priv->caps = esxCapsInit(priv); priv->caps = esxCapsInit(priv);
if (priv->caps == NULL) { if (priv->caps == NULL) {
goto failure; goto cleanup;
} }
cleanup: result = VIR_DRV_OPEN_SUCCESS;
VIR_FREE(url);
VIR_FREE(vCenter);
VIR_FREE(password);
VIR_FREE(username);
esxVI_String_Free(&propertyNameList);
esxVI_ObjectContent_Free(&hostSystem);
return result;
failure: cleanup:
if (priv != NULL) { if (result == VIR_DRV_OPEN_ERROR && priv != NULL) {
esxVI_Context_Free(&priv->host); esxVI_Context_Free(&priv->host);
esxVI_Context_Free(&priv->vCenter); esxVI_Context_Free(&priv->vCenter);
...@@ -603,9 +594,14 @@ esxOpen(virConnectPtr conn, virConnectAuthPtr auth, int flags ATTRIBUTE_UNUSED) ...@@ -603,9 +594,14 @@ esxOpen(virConnectPtr conn, virConnectAuthPtr auth, int flags ATTRIBUTE_UNUSED)
VIR_FREE(priv); 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;
} }
...@@ -656,7 +652,7 @@ esxSupportsVMotion(esxPrivate *priv) ...@@ -656,7 +652,7 @@ esxSupportsVMotion(esxPrivate *priv)
} }
if (esxVI_EnsureSession(priv->host) < 0) { if (esxVI_EnsureSession(priv->host) < 0) {
goto failure; return esxVI_Boolean_Undefined;
} }
if (esxVI_String_AppendValueToList(&propertyNameList, if (esxVI_String_AppendValueToList(&propertyNameList,
...@@ -664,13 +660,13 @@ esxSupportsVMotion(esxPrivate *priv) ...@@ -664,13 +660,13 @@ esxSupportsVMotion(esxPrivate *priv)
esxVI_LookupObjectContentByType(priv->host, priv->host->hostFolder, esxVI_LookupObjectContentByType(priv->host, priv->host->hostFolder,
"HostSystem", propertyNameList, "HostSystem", propertyNameList,
esxVI_Boolean_True, &hostSystem) < 0) { esxVI_Boolean_True, &hostSystem) < 0) {
goto failure; goto cleanup;
} }
if (hostSystem == NULL) { if (hostSystem == NULL) {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
_("Could not retrieve the HostSystem object")); _("Could not retrieve the HostSystem object"));
goto failure; goto cleanup;
} }
for (dynamicProperty = hostSystem->propSet; dynamicProperty != NULL; for (dynamicProperty = hostSystem->propSet; dynamicProperty != NULL;
...@@ -678,7 +674,7 @@ esxSupportsVMotion(esxPrivate *priv) ...@@ -678,7 +674,7 @@ esxSupportsVMotion(esxPrivate *priv)
if (STREQ(dynamicProperty->name, "capability.vmotionSupported")) { if (STREQ(dynamicProperty->name, "capability.vmotionSupported")) {
if (esxVI_AnyType_ExpectType(dynamicProperty->val, if (esxVI_AnyType_ExpectType(dynamicProperty->val,
esxVI_Type_Boolean) < 0) { esxVI_Type_Boolean) < 0) {
goto failure; goto cleanup;
} }
priv->supportsVMotion = dynamicProperty->val->boolean; priv->supportsVMotion = dynamicProperty->val->boolean;
...@@ -689,15 +685,14 @@ esxSupportsVMotion(esxPrivate *priv) ...@@ -689,15 +685,14 @@ esxSupportsVMotion(esxPrivate *priv)
} }
cleanup: 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_String_Free(&propertyNameList);
esxVI_ObjectContent_Free(&hostSystem); esxVI_ObjectContent_Free(&hostSystem);
return priv->supportsVMotion; return priv->supportsVMotion;
failure:
priv->supportsVMotion = esxVI_Boolean_Undefined;
goto cleanup;
} }
...@@ -766,7 +761,7 @@ esxGetHostname(virConnectPtr conn) ...@@ -766,7 +761,7 @@ esxGetHostname(virConnectPtr conn)
char *complete = NULL; char *complete = NULL;
if (esxVI_EnsureSession(priv->host) < 0) { if (esxVI_EnsureSession(priv->host) < 0) {
goto failure; return NULL;
} }
if (esxVI_String_AppendValueListToList if (esxVI_String_AppendValueListToList
...@@ -776,13 +771,13 @@ esxGetHostname(virConnectPtr conn) ...@@ -776,13 +771,13 @@ esxGetHostname(virConnectPtr conn)
esxVI_LookupObjectContentByType(priv->host, priv->host->hostFolder, esxVI_LookupObjectContentByType(priv->host, priv->host->hostFolder,
"HostSystem", propertyNameList, "HostSystem", propertyNameList,
esxVI_Boolean_True, &hostSystem) < 0) { esxVI_Boolean_True, &hostSystem) < 0) {
goto failure; goto cleanup;
} }
if (hostSystem == NULL) { if (hostSystem == NULL) {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
_("Could not retrieve the HostSystem object")); _("Could not retrieve the HostSystem object"));
goto failure; goto cleanup;
} }
for (dynamicProperty = hostSystem->propSet; dynamicProperty != NULL; for (dynamicProperty = hostSystem->propSet; dynamicProperty != NULL;
...@@ -791,7 +786,7 @@ esxGetHostname(virConnectPtr conn) ...@@ -791,7 +786,7 @@ esxGetHostname(virConnectPtr conn)
"config.network.dnsConfig.hostName")) { "config.network.dnsConfig.hostName")) {
if (esxVI_AnyType_ExpectType(dynamicProperty->val, if (esxVI_AnyType_ExpectType(dynamicProperty->val,
esxVI_Type_String) < 0) { esxVI_Type_String) < 0) {
goto failure; goto cleanup;
} }
hostName = dynamicProperty->val->string; hostName = dynamicProperty->val->string;
...@@ -799,7 +794,7 @@ esxGetHostname(virConnectPtr conn) ...@@ -799,7 +794,7 @@ esxGetHostname(virConnectPtr conn)
"config.network.dnsConfig.domainName")) { "config.network.dnsConfig.domainName")) {
if (esxVI_AnyType_ExpectType(dynamicProperty->val, if (esxVI_AnyType_ExpectType(dynamicProperty->val,
esxVI_Type_String) < 0) { esxVI_Type_String) < 0) {
goto failure; goto cleanup;
} }
domainName = dynamicProperty->val->string; domainName = dynamicProperty->val->string;
...@@ -811,7 +806,7 @@ esxGetHostname(virConnectPtr conn) ...@@ -811,7 +806,7 @@ esxGetHostname(virConnectPtr conn)
if (hostName == NULL || strlen(hostName) < 1) { if (hostName == NULL || strlen(hostName) < 1) {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
_("Missing or empty 'hostName' property")); _("Missing or empty 'hostName' property"));
goto failure; goto cleanup;
} }
if (domainName == NULL || strlen(domainName) < 1) { if (domainName == NULL || strlen(domainName) < 1) {
...@@ -819,25 +814,25 @@ esxGetHostname(virConnectPtr conn) ...@@ -819,25 +814,25 @@ esxGetHostname(virConnectPtr conn)
if (complete == NULL) { if (complete == NULL) {
virReportOOMError(); virReportOOMError();
goto failure; goto cleanup;
} }
} else { } else {
if (virAsprintf(&complete, "%s.%s", hostName, domainName) < 0) { if (virAsprintf(&complete, "%s.%s", hostName, domainName) < 0) {
virReportOOMError(); virReportOOMError();
goto failure; goto cleanup;
} }
} }
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_String_Free(&propertyNameList);
esxVI_ObjectContent_Free(&hostSystem); esxVI_ObjectContent_Free(&hostSystem);
return complete; return complete;
failure:
VIR_FREE(complete);
goto cleanup;
} }
...@@ -845,7 +840,7 @@ esxGetHostname(virConnectPtr conn) ...@@ -845,7 +840,7 @@ esxGetHostname(virConnectPtr conn)
static int static int
esxNodeGetInfo(virConnectPtr conn, virNodeInfoPtr nodeinfo) esxNodeGetInfo(virConnectPtr conn, virNodeInfoPtr nodeinfo)
{ {
int result = 0; int result = -1;
esxPrivate *priv = conn->privateData; esxPrivate *priv = conn->privateData;
esxVI_String *propertyNameList = NULL; esxVI_String *propertyNameList = NULL;
esxVI_ObjectContent *hostSystem = NULL; esxVI_ObjectContent *hostSystem = NULL;
...@@ -858,10 +853,10 @@ esxNodeGetInfo(virConnectPtr conn, virNodeInfoPtr nodeinfo) ...@@ -858,10 +853,10 @@ esxNodeGetInfo(virConnectPtr conn, virNodeInfoPtr nodeinfo)
int32_t numaInfo_numNodes = 0; int32_t numaInfo_numNodes = 0;
char *ptr = NULL; char *ptr = NULL;
memset(nodeinfo, 0, sizeof(virNodeInfo)); memset(nodeinfo, 0, sizeof (*nodeinfo));
if (esxVI_EnsureSession(priv->host) < 0) { if (esxVI_EnsureSession(priv->host) < 0) {
goto failure; return -1;
} }
if (esxVI_String_AppendValueListToList(&propertyNameList, if (esxVI_String_AppendValueListToList(&propertyNameList,
...@@ -875,13 +870,13 @@ esxNodeGetInfo(virConnectPtr conn, virNodeInfoPtr nodeinfo) ...@@ -875,13 +870,13 @@ esxNodeGetInfo(virConnectPtr conn, virNodeInfoPtr nodeinfo)
esxVI_LookupObjectContentByType(priv->host, priv->host->hostFolder, esxVI_LookupObjectContentByType(priv->host, priv->host->hostFolder,
"HostSystem", propertyNameList, "HostSystem", propertyNameList,
esxVI_Boolean_True, &hostSystem) < 0) { esxVI_Boolean_True, &hostSystem) < 0) {
goto failure; goto cleanup;
} }
if (hostSystem == NULL) { if (hostSystem == NULL) {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
_("Could not retrieve the HostSystem object")); _("Could not retrieve the HostSystem object"));
goto failure; goto cleanup;
} }
for (dynamicProperty = hostSystem->propSet; dynamicProperty != NULL; for (dynamicProperty = hostSystem->propSet; dynamicProperty != NULL;
...@@ -889,7 +884,7 @@ esxNodeGetInfo(virConnectPtr conn, virNodeInfoPtr nodeinfo) ...@@ -889,7 +884,7 @@ esxNodeGetInfo(virConnectPtr conn, virNodeInfoPtr nodeinfo)
if (STREQ(dynamicProperty->name, "hardware.cpuInfo.hz")) { if (STREQ(dynamicProperty->name, "hardware.cpuInfo.hz")) {
if (esxVI_AnyType_ExpectType(dynamicProperty->val, if (esxVI_AnyType_ExpectType(dynamicProperty->val,
esxVI_Type_Long) < 0) { esxVI_Type_Long) < 0) {
goto failure; goto cleanup;
} }
cpuInfo_hz = dynamicProperty->val->int64; cpuInfo_hz = dynamicProperty->val->int64;
...@@ -897,7 +892,7 @@ esxNodeGetInfo(virConnectPtr conn, virNodeInfoPtr nodeinfo) ...@@ -897,7 +892,7 @@ esxNodeGetInfo(virConnectPtr conn, virNodeInfoPtr nodeinfo)
"hardware.cpuInfo.numCpuCores")) { "hardware.cpuInfo.numCpuCores")) {
if (esxVI_AnyType_ExpectType(dynamicProperty->val, if (esxVI_AnyType_ExpectType(dynamicProperty->val,
esxVI_Type_Short) < 0) { esxVI_Type_Short) < 0) {
goto failure; goto cleanup;
} }
cpuInfo_numCpuCores = dynamicProperty->val->int16; cpuInfo_numCpuCores = dynamicProperty->val->int16;
...@@ -905,7 +900,7 @@ esxNodeGetInfo(virConnectPtr conn, virNodeInfoPtr nodeinfo) ...@@ -905,7 +900,7 @@ esxNodeGetInfo(virConnectPtr conn, virNodeInfoPtr nodeinfo)
"hardware.cpuInfo.numCpuPackages")) { "hardware.cpuInfo.numCpuPackages")) {
if (esxVI_AnyType_ExpectType(dynamicProperty->val, if (esxVI_AnyType_ExpectType(dynamicProperty->val,
esxVI_Type_Short) < 0) { esxVI_Type_Short) < 0) {
goto failure; goto cleanup;
} }
cpuInfo_numCpuPackages = dynamicProperty->val->int16; cpuInfo_numCpuPackages = dynamicProperty->val->int16;
...@@ -913,14 +908,14 @@ esxNodeGetInfo(virConnectPtr conn, virNodeInfoPtr nodeinfo) ...@@ -913,14 +908,14 @@ esxNodeGetInfo(virConnectPtr conn, virNodeInfoPtr nodeinfo)
"hardware.cpuInfo.numCpuThreads")) { "hardware.cpuInfo.numCpuThreads")) {
if (esxVI_AnyType_ExpectType(dynamicProperty->val, if (esxVI_AnyType_ExpectType(dynamicProperty->val,
esxVI_Type_Short) < 0) { esxVI_Type_Short) < 0) {
goto failure; goto cleanup;
} }
cpuInfo_numCpuThreads = dynamicProperty->val->int16; cpuInfo_numCpuThreads = dynamicProperty->val->int16;
} else if (STREQ(dynamicProperty->name, "hardware.memorySize")) { } else if (STREQ(dynamicProperty->name, "hardware.memorySize")) {
if (esxVI_AnyType_ExpectType(dynamicProperty->val, if (esxVI_AnyType_ExpectType(dynamicProperty->val,
esxVI_Type_Long) < 0) { esxVI_Type_Long) < 0) {
goto failure; goto cleanup;
} }
memorySize = dynamicProperty->val->int64; memorySize = dynamicProperty->val->int64;
...@@ -928,7 +923,7 @@ esxNodeGetInfo(virConnectPtr conn, virNodeInfoPtr nodeinfo) ...@@ -928,7 +923,7 @@ esxNodeGetInfo(virConnectPtr conn, virNodeInfoPtr nodeinfo)
"hardware.numaInfo.numNodes")) { "hardware.numaInfo.numNodes")) {
if (esxVI_AnyType_ExpectType(dynamicProperty->val, if (esxVI_AnyType_ExpectType(dynamicProperty->val,
esxVI_Type_Int) < 0) { esxVI_Type_Int) < 0) {
goto failure; goto cleanup;
} }
numaInfo_numNodes = dynamicProperty->val->int32; numaInfo_numNodes = dynamicProperty->val->int32;
...@@ -936,7 +931,7 @@ esxNodeGetInfo(virConnectPtr conn, virNodeInfoPtr nodeinfo) ...@@ -936,7 +931,7 @@ esxNodeGetInfo(virConnectPtr conn, virNodeInfoPtr nodeinfo)
"summary.hardware.cpuModel")) { "summary.hardware.cpuModel")) {
if (esxVI_AnyType_ExpectType(dynamicProperty->val, if (esxVI_AnyType_ExpectType(dynamicProperty->val,
esxVI_Type_String) < 0) { esxVI_Type_String) < 0) {
goto failure; goto cleanup;
} }
ptr = dynamicProperty->val->string; ptr = dynamicProperty->val->string;
...@@ -963,7 +958,7 @@ esxNodeGetInfo(virConnectPtr conn, virNodeInfoPtr nodeinfo) ...@@ -963,7 +958,7 @@ esxNodeGetInfo(virConnectPtr conn, virNodeInfoPtr nodeinfo)
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("CPU Model %s too long for destination"), _("CPU Model %s too long for destination"),
dynamicProperty->val->string); dynamicProperty->val->string);
goto failure; goto cleanup;
} }
} else { } else {
VIR_WARN("Unexpected '%s' property", dynamicProperty->name); VIR_WARN("Unexpected '%s' property", dynamicProperty->name);
...@@ -982,16 +977,13 @@ esxNodeGetInfo(virConnectPtr conn, virNodeInfoPtr nodeinfo) ...@@ -982,16 +977,13 @@ esxNodeGetInfo(virConnectPtr conn, virNodeInfoPtr nodeinfo)
? cpuInfo_numCpuThreads / cpuInfo_numCpuCores ? cpuInfo_numCpuThreads / cpuInfo_numCpuCores
: 0; : 0;
result = 0;
cleanup: cleanup:
esxVI_String_Free(&propertyNameList); esxVI_String_Free(&propertyNameList);
esxVI_ObjectContent_Free(&hostSystem); esxVI_ObjectContent_Free(&hostSystem);
return result; return result;
failure:
result = -1;
goto cleanup;
} }
...@@ -1015,6 +1007,7 @@ esxGetCapabilities(virConnectPtr conn) ...@@ -1015,6 +1007,7 @@ esxGetCapabilities(virConnectPtr conn)
static int static int
esxListDomains(virConnectPtr conn, int *ids, int maxids) esxListDomains(virConnectPtr conn, int *ids, int maxids)
{ {
bool success = false;
esxPrivate *priv = conn->privateData; esxPrivate *priv = conn->privateData;
esxVI_ObjectContent *virtualMachineList = NULL; esxVI_ObjectContent *virtualMachineList = NULL;
esxVI_ObjectContent *virtualMachine = NULL; esxVI_ObjectContent *virtualMachine = NULL;
...@@ -1032,7 +1025,7 @@ esxListDomains(virConnectPtr conn, int *ids, int maxids) ...@@ -1032,7 +1025,7 @@ esxListDomains(virConnectPtr conn, int *ids, int maxids)
} }
if (esxVI_EnsureSession(priv->host) < 0) { if (esxVI_EnsureSession(priv->host) < 0) {
goto failure; return -1;
} }
if (esxVI_String_AppendValueToList(&propertyNameList, if (esxVI_String_AppendValueToList(&propertyNameList,
...@@ -1041,14 +1034,14 @@ esxListDomains(virConnectPtr conn, int *ids, int maxids) ...@@ -1041,14 +1034,14 @@ esxListDomains(virConnectPtr conn, int *ids, int maxids)
"VirtualMachine", propertyNameList, "VirtualMachine", propertyNameList,
esxVI_Boolean_True, esxVI_Boolean_True,
&virtualMachineList) < 0) { &virtualMachineList) < 0) {
goto failure; goto cleanup;
} }
for (virtualMachine = virtualMachineList; virtualMachine != NULL; for (virtualMachine = virtualMachineList; virtualMachine != NULL;
virtualMachine = virtualMachine->_next) { virtualMachine = virtualMachine->_next) {
if (esxVI_GetVirtualMachinePowerState(virtualMachine, if (esxVI_GetVirtualMachinePowerState(virtualMachine,
&powerState) < 0) { &powerState) < 0) {
goto failure; goto cleanup;
} }
if (powerState != esxVI_VirtualMachinePowerState_PoweredOn) { if (powerState != esxVI_VirtualMachinePowerState_PoweredOn) {
...@@ -1061,7 +1054,7 @@ esxListDomains(virConnectPtr conn, int *ids, int maxids) ...@@ -1061,7 +1054,7 @@ esxListDomains(virConnectPtr conn, int *ids, int maxids)
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Failed to parse positive integer from '%s'"), _("Failed to parse positive integer from '%s'"),
virtualMachine->obj->value); virtualMachine->obj->value);
goto failure; goto cleanup;
} }
count++; count++;
...@@ -1071,16 +1064,13 @@ esxListDomains(virConnectPtr conn, int *ids, int maxids) ...@@ -1071,16 +1064,13 @@ esxListDomains(virConnectPtr conn, int *ids, int maxids)
} }
} }
success = true;
cleanup: cleanup:
esxVI_String_Free(&propertyNameList); esxVI_String_Free(&propertyNameList);
esxVI_ObjectContent_Free(&virtualMachineList); esxVI_ObjectContent_Free(&virtualMachineList);
return count; return success ? count : -1;
failure:
count = -1;
goto cleanup;
} }
...@@ -1115,7 +1105,7 @@ esxDomainLookupByID(virConnectPtr conn, int id) ...@@ -1115,7 +1105,7 @@ esxDomainLookupByID(virConnectPtr conn, int id)
virDomainPtr domain = NULL; virDomainPtr domain = NULL;
if (esxVI_EnsureSession(priv->host) < 0) { if (esxVI_EnsureSession(priv->host) < 0) {
goto failure; return NULL;
} }
if (esxVI_String_AppendValueListToList(&propertyNameList, if (esxVI_String_AppendValueListToList(&propertyNameList,
...@@ -1127,14 +1117,14 @@ esxDomainLookupByID(virConnectPtr conn, int id) ...@@ -1127,14 +1117,14 @@ esxDomainLookupByID(virConnectPtr conn, int id)
"VirtualMachine", propertyNameList, "VirtualMachine", propertyNameList,
esxVI_Boolean_True, esxVI_Boolean_True,
&virtualMachineList) < 0) { &virtualMachineList) < 0) {
goto failure; goto cleanup;
} }
for (virtualMachine = virtualMachineList; virtualMachine != NULL; for (virtualMachine = virtualMachineList; virtualMachine != NULL;
virtualMachine = virtualMachine->_next) { virtualMachine = virtualMachine->_next) {
if (esxVI_GetVirtualMachinePowerState(virtualMachine, if (esxVI_GetVirtualMachinePowerState(virtualMachine,
&powerState) < 0) { &powerState) < 0) {
goto failure; goto cleanup;
} }
/* Only running/suspended domains have an ID != -1 */ /* Only running/suspended domains have an ID != -1 */
...@@ -1147,7 +1137,7 @@ esxDomainLookupByID(virConnectPtr conn, int id) ...@@ -1147,7 +1137,7 @@ esxDomainLookupByID(virConnectPtr conn, int id)
if (esxVI_GetVirtualMachineIdentity(virtualMachine, if (esxVI_GetVirtualMachineIdentity(virtualMachine,
&id_candidate, &name_candidate, &id_candidate, &name_candidate,
uuid_candidate) < 0) { uuid_candidate) < 0) {
goto failure; goto cleanup;
} }
if (id != id_candidate) { if (id != id_candidate) {
...@@ -1157,7 +1147,7 @@ esxDomainLookupByID(virConnectPtr conn, int id) ...@@ -1157,7 +1147,7 @@ esxDomainLookupByID(virConnectPtr conn, int id)
domain = virGetDomain(conn, name_candidate, uuid_candidate); domain = virGetDomain(conn, name_candidate, uuid_candidate);
if (domain == NULL) { if (domain == NULL) {
goto failure; goto cleanup;
} }
domain->id = id; domain->id = id;
...@@ -1175,11 +1165,6 @@ esxDomainLookupByID(virConnectPtr conn, int id) ...@@ -1175,11 +1165,6 @@ esxDomainLookupByID(virConnectPtr conn, int id)
VIR_FREE(name_candidate); VIR_FREE(name_candidate);
return domain; return domain;
failure:
domain = NULL;
goto cleanup;
} }
...@@ -1196,7 +1181,7 @@ esxDomainLookupByUUID(virConnectPtr conn, const unsigned char *uuid) ...@@ -1196,7 +1181,7 @@ esxDomainLookupByUUID(virConnectPtr conn, const unsigned char *uuid)
virDomainPtr domain = NULL; virDomainPtr domain = NULL;
if (esxVI_EnsureSession(priv->host) < 0) { if (esxVI_EnsureSession(priv->host) < 0) {
goto failure; return NULL;
} }
if (esxVI_String_AppendValueListToList(&propertyNameList, if (esxVI_String_AppendValueListToList(&propertyNameList,
...@@ -1207,13 +1192,13 @@ esxDomainLookupByUUID(virConnectPtr conn, const unsigned char *uuid) ...@@ -1207,13 +1192,13 @@ esxDomainLookupByUUID(virConnectPtr conn, const unsigned char *uuid)
esxVI_Occurrence_RequiredItem) < 0 || esxVI_Occurrence_RequiredItem) < 0 ||
esxVI_GetVirtualMachineIdentity(virtualMachine, &id, &name, NULL) < 0 || esxVI_GetVirtualMachineIdentity(virtualMachine, &id, &name, NULL) < 0 ||
esxVI_GetVirtualMachinePowerState(virtualMachine, &powerState) < 0) { esxVI_GetVirtualMachinePowerState(virtualMachine, &powerState) < 0) {
goto failure; goto cleanup;
} }
domain = virGetDomain(conn, name, uuid); domain = virGetDomain(conn, name, uuid);
if (domain == NULL) { if (domain == NULL) {
goto failure; goto cleanup;
} }
/* Only running/suspended virtual machines have an ID != -1 */ /* Only running/suspended virtual machines have an ID != -1 */
...@@ -1229,11 +1214,6 @@ esxDomainLookupByUUID(virConnectPtr conn, const unsigned char *uuid) ...@@ -1229,11 +1214,6 @@ esxDomainLookupByUUID(virConnectPtr conn, const unsigned char *uuid)
VIR_FREE(name); VIR_FREE(name);
return domain; return domain;
failure:
domain = NULL;
goto cleanup;
} }
...@@ -1250,7 +1230,7 @@ esxDomainLookupByName(virConnectPtr conn, const char *name) ...@@ -1250,7 +1230,7 @@ esxDomainLookupByName(virConnectPtr conn, const char *name)
virDomainPtr domain = NULL; virDomainPtr domain = NULL;
if (esxVI_EnsureSession(priv->host) < 0) { if (esxVI_EnsureSession(priv->host) < 0) {
goto failure; return NULL;
} }
if (esxVI_String_AppendValueListToList(&propertyNameList, if (esxVI_String_AppendValueListToList(&propertyNameList,
...@@ -1260,28 +1240,24 @@ esxDomainLookupByName(virConnectPtr conn, const char *name) ...@@ -1260,28 +1240,24 @@ esxDomainLookupByName(virConnectPtr conn, const char *name)
esxVI_LookupVirtualMachineByName(priv->host, name, propertyNameList, esxVI_LookupVirtualMachineByName(priv->host, name, propertyNameList,
&virtualMachine, &virtualMachine,
esxVI_Occurrence_OptionalItem) < 0) { esxVI_Occurrence_OptionalItem) < 0) {
goto failure; goto cleanup;
} }
if (virtualMachine == NULL) { if (virtualMachine == NULL) {
ESX_ERROR(VIR_ERR_NO_DOMAIN, _("No domain with name '%s'"), name); ESX_ERROR(VIR_ERR_NO_DOMAIN, _("No domain with name '%s'"), name);
goto failure; goto cleanup;
} }
if (esxVI_GetVirtualMachineIdentity(virtualMachine, &id, NULL, uuid) < 0) { if (esxVI_GetVirtualMachineIdentity(virtualMachine, &id, NULL, uuid) < 0 ||
goto failure; esxVI_GetVirtualMachinePowerState(virtualMachine, &powerState) < 0) {
} goto cleanup;
if (esxVI_GetVirtualMachinePowerState(virtualMachine,
&powerState) < 0) {
goto failure;
} }
domain = virGetDomain(conn, name, uuid); domain = virGetDomain(conn, name, uuid);
if (domain == NULL) { if (domain == NULL) {
goto failure; goto cleanup;
} }
/* Only running/suspended virtual machines have an ID != -1 */ /* Only running/suspended virtual machines have an ID != -1 */
...@@ -1296,11 +1272,6 @@ esxDomainLookupByName(virConnectPtr conn, const char *name) ...@@ -1296,11 +1272,6 @@ esxDomainLookupByName(virConnectPtr conn, const char *name)
esxVI_ObjectContent_Free(&virtualMachine); esxVI_ObjectContent_Free(&virtualMachine);
return domain; return domain;
failure:
domain = NULL;
goto cleanup;
} }
...@@ -1308,7 +1279,7 @@ esxDomainLookupByName(virConnectPtr conn, const char *name) ...@@ -1308,7 +1279,7 @@ esxDomainLookupByName(virConnectPtr conn, const char *name)
static int static int
esxDomainSuspend(virDomainPtr domain) esxDomainSuspend(virDomainPtr domain)
{ {
int result = 0; int result = -1;
esxPrivate *priv = domain->conn->privateData; esxPrivate *priv = domain->conn->privateData;
esxVI_ObjectContent *virtualMachine = NULL; esxVI_ObjectContent *virtualMachine = NULL;
esxVI_String *propertyNameList = NULL; esxVI_String *propertyNameList = NULL;
...@@ -1317,7 +1288,7 @@ esxDomainSuspend(virDomainPtr domain) ...@@ -1317,7 +1288,7 @@ esxDomainSuspend(virDomainPtr domain)
esxVI_TaskInfoState taskInfoState; esxVI_TaskInfoState taskInfoState;
if (esxVI_EnsureSession(priv->host) < 0) { if (esxVI_EnsureSession(priv->host) < 0) {
goto failure; return -1;
} }
if (esxVI_String_AppendValueToList(&propertyNameList, if (esxVI_String_AppendValueToList(&propertyNameList,
...@@ -1326,37 +1297,34 @@ esxDomainSuspend(virDomainPtr domain) ...@@ -1326,37 +1297,34 @@ esxDomainSuspend(virDomainPtr domain)
(priv->host, domain->uuid, propertyNameList, &virtualMachine, (priv->host, domain->uuid, propertyNameList, &virtualMachine,
priv->autoAnswer) < 0 || priv->autoAnswer) < 0 ||
esxVI_GetVirtualMachinePowerState(virtualMachine, &powerState) < 0) { esxVI_GetVirtualMachinePowerState(virtualMachine, &powerState) < 0) {
goto failure; goto cleanup;
} }
if (powerState != esxVI_VirtualMachinePowerState_PoweredOn) { if (powerState != esxVI_VirtualMachinePowerState_PoweredOn) {
ESX_ERROR(VIR_ERR_OPERATION_INVALID, "%s", ESX_ERROR(VIR_ERR_OPERATION_INVALID, "%s",
_("Domain is not powered on")); _("Domain is not powered on"));
goto failure; goto cleanup;
} }
if (esxVI_SuspendVM_Task(priv->host, virtualMachine->obj, &task) < 0 || if (esxVI_SuspendVM_Task(priv->host, virtualMachine->obj, &task) < 0 ||
esxVI_WaitForTaskCompletion(priv->host, task, domain->uuid, esxVI_WaitForTaskCompletion(priv->host, task, domain->uuid,
priv->autoAnswer, &taskInfoState) < 0) { priv->autoAnswer, &taskInfoState) < 0) {
goto failure; goto cleanup;
} }
if (taskInfoState != esxVI_TaskInfoState_Success) { if (taskInfoState != esxVI_TaskInfoState_Success) {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not suspend domain")); ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not suspend domain"));
goto failure; goto cleanup;
} }
result = 0;
cleanup: cleanup:
esxVI_ObjectContent_Free(&virtualMachine); esxVI_ObjectContent_Free(&virtualMachine);
esxVI_String_Free(&propertyNameList); esxVI_String_Free(&propertyNameList);
esxVI_ManagedObjectReference_Free(&task); esxVI_ManagedObjectReference_Free(&task);
return result; return result;
failure:
result = -1;
goto cleanup;
} }
...@@ -1364,7 +1332,7 @@ esxDomainSuspend(virDomainPtr domain) ...@@ -1364,7 +1332,7 @@ esxDomainSuspend(virDomainPtr domain)
static int static int
esxDomainResume(virDomainPtr domain) esxDomainResume(virDomainPtr domain)
{ {
int result = 0; int result = -1;
esxPrivate *priv = domain->conn->privateData; esxPrivate *priv = domain->conn->privateData;
esxVI_ObjectContent *virtualMachine = NULL; esxVI_ObjectContent *virtualMachine = NULL;
esxVI_String *propertyNameList = NULL; esxVI_String *propertyNameList = NULL;
...@@ -1373,7 +1341,7 @@ esxDomainResume(virDomainPtr domain) ...@@ -1373,7 +1341,7 @@ esxDomainResume(virDomainPtr domain)
esxVI_TaskInfoState taskInfoState; esxVI_TaskInfoState taskInfoState;
if (esxVI_EnsureSession(priv->host) < 0) { if (esxVI_EnsureSession(priv->host) < 0) {
goto failure; return -1;
} }
if (esxVI_String_AppendValueToList(&propertyNameList, if (esxVI_String_AppendValueToList(&propertyNameList,
...@@ -1382,37 +1350,34 @@ esxDomainResume(virDomainPtr domain) ...@@ -1382,37 +1350,34 @@ esxDomainResume(virDomainPtr domain)
(priv->host, domain->uuid, propertyNameList, &virtualMachine, (priv->host, domain->uuid, propertyNameList, &virtualMachine,
priv->autoAnswer) < 0 || priv->autoAnswer) < 0 ||
esxVI_GetVirtualMachinePowerState(virtualMachine, &powerState) < 0) { esxVI_GetVirtualMachinePowerState(virtualMachine, &powerState) < 0) {
goto failure; goto cleanup;
} }
if (powerState != esxVI_VirtualMachinePowerState_Suspended) { if (powerState != esxVI_VirtualMachinePowerState_Suspended) {
ESX_ERROR(VIR_ERR_OPERATION_INVALID, "%s", _("Domain is not 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, if (esxVI_PowerOnVM_Task(priv->host, virtualMachine->obj, NULL,
&task) < 0 || &task) < 0 ||
esxVI_WaitForTaskCompletion(priv->host, task, domain->uuid, esxVI_WaitForTaskCompletion(priv->host, task, domain->uuid,
priv->autoAnswer, &taskInfoState) < 0) { priv->autoAnswer, &taskInfoState) < 0) {
goto failure; goto cleanup;
} }
if (taskInfoState != esxVI_TaskInfoState_Success) { if (taskInfoState != esxVI_TaskInfoState_Success) {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not resume domain")); ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not resume domain"));
goto failure; goto cleanup;
} }
result = 0;
cleanup: cleanup:
esxVI_ObjectContent_Free(&virtualMachine); esxVI_ObjectContent_Free(&virtualMachine);
esxVI_String_Free(&propertyNameList); esxVI_String_Free(&propertyNameList);
esxVI_ManagedObjectReference_Free(&task); esxVI_ManagedObjectReference_Free(&task);
return result; return result;
failure:
result = -1;
goto cleanup;
} }
...@@ -1420,14 +1385,14 @@ esxDomainResume(virDomainPtr domain) ...@@ -1420,14 +1385,14 @@ esxDomainResume(virDomainPtr domain)
static int static int
esxDomainShutdown(virDomainPtr domain) esxDomainShutdown(virDomainPtr domain)
{ {
int result = 0; int result = -1;
esxPrivate *priv = domain->conn->privateData; esxPrivate *priv = domain->conn->privateData;
esxVI_ObjectContent *virtualMachine = NULL; esxVI_ObjectContent *virtualMachine = NULL;
esxVI_String *propertyNameList = NULL; esxVI_String *propertyNameList = NULL;
esxVI_VirtualMachinePowerState powerState; esxVI_VirtualMachinePowerState powerState;
if (esxVI_EnsureSession(priv->host) < 0) { if (esxVI_EnsureSession(priv->host) < 0) {
goto failure; return -1;
} }
if (esxVI_String_AppendValueToList(&propertyNameList, if (esxVI_String_AppendValueToList(&propertyNameList,
...@@ -1436,29 +1401,26 @@ esxDomainShutdown(virDomainPtr domain) ...@@ -1436,29 +1401,26 @@ esxDomainShutdown(virDomainPtr domain)
propertyNameList, &virtualMachine, propertyNameList, &virtualMachine,
esxVI_Occurrence_RequiredItem) < 0 || esxVI_Occurrence_RequiredItem) < 0 ||
esxVI_GetVirtualMachinePowerState(virtualMachine, &powerState) < 0) { esxVI_GetVirtualMachinePowerState(virtualMachine, &powerState) < 0) {
goto failure; goto cleanup;
} }
if (powerState != esxVI_VirtualMachinePowerState_PoweredOn) { if (powerState != esxVI_VirtualMachinePowerState_PoweredOn) {
ESX_ERROR(VIR_ERR_OPERATION_INVALID, "%s", ESX_ERROR(VIR_ERR_OPERATION_INVALID, "%s",
_("Domain is not powered on")); _("Domain is not powered on"));
goto failure; goto cleanup;
} }
if (esxVI_ShutdownGuest(priv->host, virtualMachine->obj) < 0) { if (esxVI_ShutdownGuest(priv->host, virtualMachine->obj) < 0) {
goto failure; goto cleanup;
} }
result = 0;
cleanup: cleanup:
esxVI_ObjectContent_Free(&virtualMachine); esxVI_ObjectContent_Free(&virtualMachine);
esxVI_String_Free(&propertyNameList); esxVI_String_Free(&propertyNameList);
return result; return result;
failure:
result = -1;
goto cleanup;
} }
...@@ -1466,14 +1428,14 @@ esxDomainShutdown(virDomainPtr domain) ...@@ -1466,14 +1428,14 @@ esxDomainShutdown(virDomainPtr domain)
static int static int
esxDomainReboot(virDomainPtr domain, unsigned int flags ATTRIBUTE_UNUSED) esxDomainReboot(virDomainPtr domain, unsigned int flags ATTRIBUTE_UNUSED)
{ {
int result = 0; int result = -1;
esxPrivate *priv = domain->conn->privateData; esxPrivate *priv = domain->conn->privateData;
esxVI_ObjectContent *virtualMachine = NULL; esxVI_ObjectContent *virtualMachine = NULL;
esxVI_String *propertyNameList = NULL; esxVI_String *propertyNameList = NULL;
esxVI_VirtualMachinePowerState powerState; esxVI_VirtualMachinePowerState powerState;
if (esxVI_EnsureSession(priv->host) < 0) { if (esxVI_EnsureSession(priv->host) < 0) {
goto failure; return -1;
} }
if (esxVI_String_AppendValueToList(&propertyNameList, if (esxVI_String_AppendValueToList(&propertyNameList,
...@@ -1482,29 +1444,26 @@ esxDomainReboot(virDomainPtr domain, unsigned int flags ATTRIBUTE_UNUSED) ...@@ -1482,29 +1444,26 @@ esxDomainReboot(virDomainPtr domain, unsigned int flags ATTRIBUTE_UNUSED)
propertyNameList, &virtualMachine, propertyNameList, &virtualMachine,
esxVI_Occurrence_RequiredItem) < 0 || esxVI_Occurrence_RequiredItem) < 0 ||
esxVI_GetVirtualMachinePowerState(virtualMachine, &powerState) < 0) { esxVI_GetVirtualMachinePowerState(virtualMachine, &powerState) < 0) {
goto failure; goto cleanup;
} }
if (powerState != esxVI_VirtualMachinePowerState_PoweredOn) { if (powerState != esxVI_VirtualMachinePowerState_PoweredOn) {
ESX_ERROR(VIR_ERR_OPERATION_INVALID, "%s", ESX_ERROR(VIR_ERR_OPERATION_INVALID, "%s",
_("Domain is not powered on")); _("Domain is not powered on"));
goto failure; goto cleanup;
} }
if (esxVI_RebootGuest(priv->host, virtualMachine->obj) < 0) { if (esxVI_RebootGuest(priv->host, virtualMachine->obj) < 0) {
goto failure; goto cleanup;
} }
result = 0;
cleanup: cleanup:
esxVI_ObjectContent_Free(&virtualMachine); esxVI_ObjectContent_Free(&virtualMachine);
esxVI_String_Free(&propertyNameList); esxVI_String_Free(&propertyNameList);
return result; return result;
failure:
result = -1;
goto cleanup;
} }
...@@ -1512,7 +1471,7 @@ esxDomainReboot(virDomainPtr domain, unsigned int flags ATTRIBUTE_UNUSED) ...@@ -1512,7 +1471,7 @@ esxDomainReboot(virDomainPtr domain, unsigned int flags ATTRIBUTE_UNUSED)
static int static int
esxDomainDestroy(virDomainPtr domain) esxDomainDestroy(virDomainPtr domain)
{ {
int result = 0; int result = -1;
esxPrivate *priv = domain->conn->privateData; esxPrivate *priv = domain->conn->privateData;
esxVI_Context *ctx = NULL; esxVI_Context *ctx = NULL;
esxVI_ObjectContent *virtualMachine = NULL; esxVI_ObjectContent *virtualMachine = NULL;
...@@ -1528,7 +1487,7 @@ esxDomainDestroy(virDomainPtr domain) ...@@ -1528,7 +1487,7 @@ esxDomainDestroy(virDomainPtr domain)
} }
if (esxVI_EnsureSession(ctx) < 0) { if (esxVI_EnsureSession(ctx) < 0) {
goto failure; return -1;
} }
if (esxVI_String_AppendValueToList(&propertyNameList, if (esxVI_String_AppendValueToList(&propertyNameList,
...@@ -1537,37 +1496,34 @@ esxDomainDestroy(virDomainPtr domain) ...@@ -1537,37 +1496,34 @@ esxDomainDestroy(virDomainPtr domain)
(ctx, domain->uuid, propertyNameList, &virtualMachine, (ctx, domain->uuid, propertyNameList, &virtualMachine,
priv->autoAnswer) < 0 || priv->autoAnswer) < 0 ||
esxVI_GetVirtualMachinePowerState(virtualMachine, &powerState) < 0) { esxVI_GetVirtualMachinePowerState(virtualMachine, &powerState) < 0) {
goto failure; goto cleanup;
} }
if (powerState != esxVI_VirtualMachinePowerState_PoweredOn) { if (powerState != esxVI_VirtualMachinePowerState_PoweredOn) {
ESX_ERROR(VIR_ERR_OPERATION_INVALID, "%s", ESX_ERROR(VIR_ERR_OPERATION_INVALID, "%s",
_("Domain is not powered on")); _("Domain is not powered on"));
goto failure; goto cleanup;
} }
if (esxVI_PowerOffVM_Task(ctx, virtualMachine->obj, &task) < 0 || if (esxVI_PowerOffVM_Task(ctx, virtualMachine->obj, &task) < 0 ||
esxVI_WaitForTaskCompletion(ctx, task, domain->uuid, priv->autoAnswer, esxVI_WaitForTaskCompletion(ctx, task, domain->uuid, priv->autoAnswer,
&taskInfoState) < 0) { &taskInfoState) < 0) {
goto failure; goto cleanup;
} }
if (taskInfoState != esxVI_TaskInfoState_Success) { if (taskInfoState != esxVI_TaskInfoState_Success) {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not destroy domain")); ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not destroy domain"));
goto failure; goto cleanup;
} }
result = 0;
cleanup: cleanup:
esxVI_ObjectContent_Free(&virtualMachine); esxVI_ObjectContent_Free(&virtualMachine);
esxVI_String_Free(&propertyNameList); esxVI_String_Free(&propertyNameList);
esxVI_ManagedObjectReference_Free(&task); esxVI_ManagedObjectReference_Free(&task);
return result; return result;
failure:
result = -1;
goto cleanup;
} }
...@@ -1597,7 +1553,7 @@ esxDomainGetMaxMemory(virDomainPtr domain) ...@@ -1597,7 +1553,7 @@ esxDomainGetMaxMemory(virDomainPtr domain)
unsigned long memoryMB = 0; unsigned long memoryMB = 0;
if (esxVI_EnsureSession(priv->host) < 0) { if (esxVI_EnsureSession(priv->host) < 0) {
goto failure; return 0;
} }
if (esxVI_String_AppendValueToList(&propertyNameList, if (esxVI_String_AppendValueToList(&propertyNameList,
...@@ -1605,7 +1561,7 @@ esxDomainGetMaxMemory(virDomainPtr domain) ...@@ -1605,7 +1561,7 @@ esxDomainGetMaxMemory(virDomainPtr domain)
esxVI_LookupVirtualMachineByUuid(priv->host, domain->uuid, esxVI_LookupVirtualMachineByUuid(priv->host, domain->uuid,
propertyNameList, &virtualMachine, propertyNameList, &virtualMachine,
esxVI_Occurrence_RequiredItem) < 0) { esxVI_Occurrence_RequiredItem) < 0) {
goto failure; goto cleanup;
} }
for (dynamicProperty = virtualMachine->propSet; dynamicProperty != NULL; for (dynamicProperty = virtualMachine->propSet; dynamicProperty != NULL;
...@@ -1613,7 +1569,7 @@ esxDomainGetMaxMemory(virDomainPtr domain) ...@@ -1613,7 +1569,7 @@ esxDomainGetMaxMemory(virDomainPtr domain)
if (STREQ(dynamicProperty->name, "config.hardware.memoryMB")) { if (STREQ(dynamicProperty->name, "config.hardware.memoryMB")) {
if (esxVI_AnyType_ExpectType(dynamicProperty->val, if (esxVI_AnyType_ExpectType(dynamicProperty->val,
esxVI_Type_Int) < 0) { esxVI_Type_Int) < 0) {
goto failure; goto cleanup;
} }
if (dynamicProperty->val->int32 < 0) { if (dynamicProperty->val->int32 < 0) {
...@@ -1635,11 +1591,6 @@ esxDomainGetMaxMemory(virDomainPtr domain) ...@@ -1635,11 +1591,6 @@ esxDomainGetMaxMemory(virDomainPtr domain)
esxVI_ObjectContent_Free(&virtualMachine); esxVI_ObjectContent_Free(&virtualMachine);
return memoryMB * 1024; /* Scale from megabyte to kilobyte */ return memoryMB * 1024; /* Scale from megabyte to kilobyte */
failure:
memoryMB = 0;
goto cleanup;
} }
...@@ -1647,7 +1598,7 @@ esxDomainGetMaxMemory(virDomainPtr domain) ...@@ -1647,7 +1598,7 @@ esxDomainGetMaxMemory(virDomainPtr domain)
static int static int
esxDomainSetMaxMemory(virDomainPtr domain, unsigned long memory) esxDomainSetMaxMemory(virDomainPtr domain, unsigned long memory)
{ {
int result = 0; int result = -1;
esxPrivate *priv = domain->conn->privateData; esxPrivate *priv = domain->conn->privateData;
esxVI_ObjectContent *virtualMachine = NULL; esxVI_ObjectContent *virtualMachine = NULL;
esxVI_VirtualMachineConfigSpec *spec = NULL; esxVI_VirtualMachineConfigSpec *spec = NULL;
...@@ -1655,7 +1606,7 @@ esxDomainSetMaxMemory(virDomainPtr domain, unsigned long memory) ...@@ -1655,7 +1606,7 @@ esxDomainSetMaxMemory(virDomainPtr domain, unsigned long memory)
esxVI_TaskInfoState taskInfoState; esxVI_TaskInfoState taskInfoState;
if (esxVI_EnsureSession(priv->host) < 0) { if (esxVI_EnsureSession(priv->host) < 0) {
goto failure; return -1;
} }
if (esxVI_LookupVirtualMachineByUuidAndPrepareForTask if (esxVI_LookupVirtualMachineByUuidAndPrepareForTask
...@@ -1663,7 +1614,7 @@ esxDomainSetMaxMemory(virDomainPtr domain, unsigned long memory) ...@@ -1663,7 +1614,7 @@ esxDomainSetMaxMemory(virDomainPtr domain, unsigned long memory)
priv->autoAnswer) < 0 || priv->autoAnswer) < 0 ||
esxVI_VirtualMachineConfigSpec_Alloc(&spec) < 0 || esxVI_VirtualMachineConfigSpec_Alloc(&spec) < 0 ||
esxVI_Long_Alloc(&spec->memoryMB) < 0) { esxVI_Long_Alloc(&spec->memoryMB) < 0) {
goto failure; goto cleanup;
} }
spec->memoryMB->value = spec->memoryMB->value =
...@@ -1673,26 +1624,23 @@ esxDomainSetMaxMemory(virDomainPtr domain, unsigned long memory) ...@@ -1673,26 +1624,23 @@ esxDomainSetMaxMemory(virDomainPtr domain, unsigned long memory)
&task) < 0 || &task) < 0 ||
esxVI_WaitForTaskCompletion(priv->host, task, domain->uuid, esxVI_WaitForTaskCompletion(priv->host, task, domain->uuid,
priv->autoAnswer, &taskInfoState) < 0) { priv->autoAnswer, &taskInfoState) < 0) {
goto failure; goto cleanup;
} }
if (taskInfoState != esxVI_TaskInfoState_Success) { if (taskInfoState != esxVI_TaskInfoState_Success) {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Could not set max-memory to %lu kilobytes"), memory); _("Could not set max-memory to %lu kilobytes"), memory);
goto failure; goto cleanup;
} }
result = 0;
cleanup: cleanup:
esxVI_ObjectContent_Free(&virtualMachine); esxVI_ObjectContent_Free(&virtualMachine);
esxVI_VirtualMachineConfigSpec_Free(&spec); esxVI_VirtualMachineConfigSpec_Free(&spec);
esxVI_ManagedObjectReference_Free(&task); esxVI_ManagedObjectReference_Free(&task);
return result; return result;
failure:
result = -1;
goto cleanup;
} }
...@@ -1700,7 +1648,7 @@ esxDomainSetMaxMemory(virDomainPtr domain, unsigned long memory) ...@@ -1700,7 +1648,7 @@ esxDomainSetMaxMemory(virDomainPtr domain, unsigned long memory)
static int static int
esxDomainSetMemory(virDomainPtr domain, unsigned long memory) esxDomainSetMemory(virDomainPtr domain, unsigned long memory)
{ {
int result = 0; int result = -1;
esxPrivate *priv = domain->conn->privateData; esxPrivate *priv = domain->conn->privateData;
esxVI_ObjectContent *virtualMachine = NULL; esxVI_ObjectContent *virtualMachine = NULL;
esxVI_VirtualMachineConfigSpec *spec = NULL; esxVI_VirtualMachineConfigSpec *spec = NULL;
...@@ -1708,7 +1656,7 @@ esxDomainSetMemory(virDomainPtr domain, unsigned long memory) ...@@ -1708,7 +1656,7 @@ esxDomainSetMemory(virDomainPtr domain, unsigned long memory)
esxVI_TaskInfoState taskInfoState; esxVI_TaskInfoState taskInfoState;
if (esxVI_EnsureSession(priv->host) < 0) { if (esxVI_EnsureSession(priv->host) < 0) {
goto failure; return -1;
} }
if (esxVI_LookupVirtualMachineByUuidAndPrepareForTask if (esxVI_LookupVirtualMachineByUuidAndPrepareForTask
...@@ -1717,7 +1665,7 @@ esxDomainSetMemory(virDomainPtr domain, unsigned long memory) ...@@ -1717,7 +1665,7 @@ esxDomainSetMemory(virDomainPtr domain, unsigned long memory)
esxVI_VirtualMachineConfigSpec_Alloc(&spec) < 0 || esxVI_VirtualMachineConfigSpec_Alloc(&spec) < 0 ||
esxVI_ResourceAllocationInfo_Alloc(&spec->memoryAllocation) < 0 || esxVI_ResourceAllocationInfo_Alloc(&spec->memoryAllocation) < 0 ||
esxVI_Long_Alloc(&spec->memoryAllocation->limit) < 0) { esxVI_Long_Alloc(&spec->memoryAllocation->limit) < 0) {
goto failure; goto cleanup;
} }
spec->memoryAllocation->limit->value = spec->memoryAllocation->limit->value =
...@@ -1727,26 +1675,23 @@ esxDomainSetMemory(virDomainPtr domain, unsigned long memory) ...@@ -1727,26 +1675,23 @@ esxDomainSetMemory(virDomainPtr domain, unsigned long memory)
&task) < 0 || &task) < 0 ||
esxVI_WaitForTaskCompletion(priv->host, task, domain->uuid, esxVI_WaitForTaskCompletion(priv->host, task, domain->uuid,
priv->autoAnswer, &taskInfoState) < 0) { priv->autoAnswer, &taskInfoState) < 0) {
goto failure; goto cleanup;
} }
if (taskInfoState != esxVI_TaskInfoState_Success) { if (taskInfoState != esxVI_TaskInfoState_Success) {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Could not set memory to %lu kilobytes"), memory); _("Could not set memory to %lu kilobytes"), memory);
goto failure; goto cleanup;
} }
result = 0;
cleanup: cleanup:
esxVI_ObjectContent_Free(&virtualMachine); esxVI_ObjectContent_Free(&virtualMachine);
esxVI_VirtualMachineConfigSpec_Free(&spec); esxVI_VirtualMachineConfigSpec_Free(&spec);
esxVI_ManagedObjectReference_Free(&task); esxVI_ManagedObjectReference_Free(&task);
return result; return result;
failure:
result = -1;
goto cleanup;
} }
...@@ -1754,7 +1699,7 @@ esxDomainSetMemory(virDomainPtr domain, unsigned long memory) ...@@ -1754,7 +1699,7 @@ esxDomainSetMemory(virDomainPtr domain, unsigned long memory)
static int static int
esxDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info) esxDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info)
{ {
int result = 0; int result = -1;
esxPrivate *priv = domain->conn->privateData; esxPrivate *priv = domain->conn->privateData;
esxVI_String *propertyNameList = NULL; esxVI_String *propertyNameList = NULL;
esxVI_ObjectContent *virtualMachine = NULL; esxVI_ObjectContent *virtualMachine = NULL;
...@@ -1774,8 +1719,10 @@ esxDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info) ...@@ -1774,8 +1719,10 @@ esxDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info)
esxVI_PerfMetricIntSeries *perfMetricIntSeries = NULL; esxVI_PerfMetricIntSeries *perfMetricIntSeries = NULL;
esxVI_Long *value = NULL; esxVI_Long *value = NULL;
memset(info, 0, sizeof (*info));
if (esxVI_EnsureSession(priv->host) < 0) { if (esxVI_EnsureSession(priv->host) < 0) {
goto failure; return -1;
} }
if (esxVI_String_AppendValueListToList(&propertyNameList, if (esxVI_String_AppendValueListToList(&propertyNameList,
...@@ -1786,21 +1733,17 @@ esxDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info) ...@@ -1786,21 +1733,17 @@ esxDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info)
esxVI_LookupVirtualMachineByUuid(priv->host, domain->uuid, esxVI_LookupVirtualMachineByUuid(priv->host, domain->uuid,
propertyNameList, &virtualMachine, propertyNameList, &virtualMachine,
esxVI_Occurrence_RequiredItem) < 0) { esxVI_Occurrence_RequiredItem) < 0) {
goto failure; goto cleanup;
} }
info->state = VIR_DOMAIN_NOSTATE; info->state = VIR_DOMAIN_NOSTATE;
info->maxMem = 0;
info->memory = 0;
info->nrVirtCpu = 0;
info->cpuTime = 0; /* FIXME */
for (dynamicProperty = virtualMachine->propSet; dynamicProperty != NULL; for (dynamicProperty = virtualMachine->propSet; dynamicProperty != NULL;
dynamicProperty = dynamicProperty->_next) { dynamicProperty = dynamicProperty->_next) {
if (STREQ(dynamicProperty->name, "runtime.powerState")) { if (STREQ(dynamicProperty->name, "runtime.powerState")) {
if (esxVI_VirtualMachinePowerState_CastFromAnyType if (esxVI_VirtualMachinePowerState_CastFromAnyType
(dynamicProperty->val, &powerState) < 0) { (dynamicProperty->val, &powerState) < 0) {
goto failure; goto cleanup;
} }
info->state = esxVI_VirtualMachinePowerState_ConvertToLibvirt info->state = esxVI_VirtualMachinePowerState_ConvertToLibvirt
...@@ -1808,14 +1751,14 @@ esxDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info) ...@@ -1808,14 +1751,14 @@ esxDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info)
} else if (STREQ(dynamicProperty->name, "config.hardware.memoryMB")) { } else if (STREQ(dynamicProperty->name, "config.hardware.memoryMB")) {
if (esxVI_AnyType_ExpectType(dynamicProperty->val, if (esxVI_AnyType_ExpectType(dynamicProperty->val,
esxVI_Type_Int) < 0) { esxVI_Type_Int) < 0) {
goto failure; goto cleanup;
} }
info->maxMem = dynamicProperty->val->int32 * 1024; /* Scale from megabyte to kilobyte */ info->maxMem = dynamicProperty->val->int32 * 1024; /* Scale from megabyte to kilobyte */
} else if (STREQ(dynamicProperty->name, "config.hardware.numCPU")) { } else if (STREQ(dynamicProperty->name, "config.hardware.numCPU")) {
if (esxVI_AnyType_ExpectType(dynamicProperty->val, if (esxVI_AnyType_ExpectType(dynamicProperty->val,
esxVI_Type_Int) < 0) { esxVI_Type_Int) < 0) {
goto failure; goto cleanup;
} }
info->nrVirtCpu = dynamicProperty->val->int32; info->nrVirtCpu = dynamicProperty->val->int32;
...@@ -1823,7 +1766,7 @@ esxDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info) ...@@ -1823,7 +1766,7 @@ esxDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info)
"config.memoryAllocation.limit")) { "config.memoryAllocation.limit")) {
if (esxVI_AnyType_ExpectType(dynamicProperty->val, if (esxVI_AnyType_ExpectType(dynamicProperty->val,
esxVI_Type_Long) < 0) { esxVI_Type_Long) < 0) {
goto failure; goto cleanup;
} }
memory_limit = dynamicProperty->val->int64; memory_limit = dynamicProperty->val->int64;
...@@ -1842,18 +1785,18 @@ esxDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info) ...@@ -1842,18 +1785,18 @@ esxDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info)
/* Verify the cached 'used CPU time' performance counter ID */ /* Verify the cached 'used CPU time' performance counter ID */
if (info->state == VIR_DOMAIN_RUNNING && priv->usedCpuTimeCounterId >= 0) { if (info->state == VIR_DOMAIN_RUNNING && priv->usedCpuTimeCounterId >= 0) {
if (esxVI_Int_Alloc(&counterId) < 0) { if (esxVI_Int_Alloc(&counterId) < 0) {
goto failure; goto cleanup;
} }
counterId->value = priv->usedCpuTimeCounterId; counterId->value = priv->usedCpuTimeCounterId;
if (esxVI_Int_AppendToList(&counterIdList, counterId) < 0) { if (esxVI_Int_AppendToList(&counterIdList, counterId) < 0) {
goto failure; goto cleanup;
} }
if (esxVI_QueryPerfCounter(priv->host, counterIdList, if (esxVI_QueryPerfCounter(priv->host, counterIdList,
&perfCounterInfo) < 0) { &perfCounterInfo) < 0) {
goto failure; goto cleanup;
} }
if (STRNEQ(perfCounterInfo->groupInfo->key, "cpu") || if (STRNEQ(perfCounterInfo->groupInfo->key, "cpu") ||
...@@ -1877,7 +1820,7 @@ esxDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info) ...@@ -1877,7 +1820,7 @@ esxDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info)
if (esxVI_QueryAvailablePerfMetric(priv->host, virtualMachine->obj, if (esxVI_QueryAvailablePerfMetric(priv->host, virtualMachine->obj,
NULL, NULL, NULL, NULL, NULL, NULL,
&perfMetricIdList) < 0) { &perfMetricIdList) < 0) {
goto failure; goto cleanup;
} }
for (perfMetricId = perfMetricIdList; perfMetricId != NULL; for (perfMetricId = perfMetricIdList; perfMetricId != NULL;
...@@ -1889,13 +1832,13 @@ esxDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info) ...@@ -1889,13 +1832,13 @@ esxDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info)
if (esxVI_Int_DeepCopy(&counterId, perfMetricId->counterId) < 0 || if (esxVI_Int_DeepCopy(&counterId, perfMetricId->counterId) < 0 ||
esxVI_Int_AppendToList(&counterIdList, counterId) < 0) { esxVI_Int_AppendToList(&counterIdList, counterId) < 0) {
goto failure; goto cleanup;
} }
} }
if (esxVI_QueryPerfCounter(priv->host, counterIdList, if (esxVI_QueryPerfCounter(priv->host, counterIdList,
&perfCounterInfoList) < 0) { &perfCounterInfoList) < 0) {
goto failure; goto cleanup;
} }
for (perfCounterInfo = perfCounterInfoList; perfCounterInfo != NULL; for (perfCounterInfo = perfCounterInfoList; perfCounterInfo != NULL;
...@@ -1933,7 +1876,7 @@ esxDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info) ...@@ -1933,7 +1876,7 @@ esxDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info)
esxVI_Int_Alloc(&querySpec->maxSample) < 0 || esxVI_Int_Alloc(&querySpec->maxSample) < 0 ||
esxVI_PerfMetricId_Alloc(&querySpec->metricId) < 0 || esxVI_PerfMetricId_Alloc(&querySpec->metricId) < 0 ||
esxVI_Int_Alloc(&querySpec->metricId->counterId) < 0) { esxVI_Int_Alloc(&querySpec->metricId->counterId) < 0) {
goto failure; goto cleanup;
} }
querySpec->entity = virtualMachine->obj; querySpec->entity = virtualMachine->obj;
...@@ -1947,7 +1890,7 @@ esxDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info) ...@@ -1947,7 +1890,7 @@ esxDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info)
querySpec->entity = NULL; querySpec->entity = NULL;
querySpec->metricId->instance = NULL; querySpec->metricId->instance = NULL;
querySpec->format = NULL; querySpec->format = NULL;
goto failure; goto cleanup;
} }
for (perfEntityMetricBase = perfEntityMetricBaseList; for (perfEntityMetricBase = perfEntityMetricBaseList;
...@@ -1986,8 +1929,15 @@ esxDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info) ...@@ -1986,8 +1929,15 @@ esxDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info)
querySpec->format = NULL; querySpec->format = NULL;
VIR_DEBUG("usedCpuTimeCounterId %d END", priv->usedCpuTimeCounterId); VIR_DEBUG("usedCpuTimeCounterId %d END", priv->usedCpuTimeCounterId);
/*
* FIXME: Cannot map between realtive used-cpu-time and absolute
* info->cpuTime
*/
} }
result = 0;
cleanup: cleanup:
esxVI_String_Free(&propertyNameList); esxVI_String_Free(&propertyNameList);
esxVI_ObjectContent_Free(&virtualMachine); esxVI_ObjectContent_Free(&virtualMachine);
...@@ -1998,11 +1948,6 @@ esxDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info) ...@@ -1998,11 +1948,6 @@ esxDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info)
esxVI_PerfEntityMetricBase_Free(&perfEntityMetricBaseList); esxVI_PerfEntityMetricBase_Free(&perfEntityMetricBaseList);
return result; return result;
failure:
result = -1;
goto cleanup;
} }
...@@ -2010,7 +1955,7 @@ esxDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info) ...@@ -2010,7 +1955,7 @@ esxDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info)
static int static int
esxDomainSetVcpus(virDomainPtr domain, unsigned int nvcpus) esxDomainSetVcpus(virDomainPtr domain, unsigned int nvcpus)
{ {
int result = 0; int result = -1;
esxPrivate *priv = domain->conn->privateData; esxPrivate *priv = domain->conn->privateData;
int maxVcpus; int maxVcpus;
esxVI_ObjectContent *virtualMachine = NULL; esxVI_ObjectContent *virtualMachine = NULL;
...@@ -2021,17 +1966,17 @@ esxDomainSetVcpus(virDomainPtr domain, unsigned int nvcpus) ...@@ -2021,17 +1966,17 @@ esxDomainSetVcpus(virDomainPtr domain, unsigned int nvcpus)
if (nvcpus < 1) { if (nvcpus < 1) {
ESX_ERROR(VIR_ERR_INVALID_ARG, "%s", ESX_ERROR(VIR_ERR_INVALID_ARG, "%s",
_("Requested number of virtual CPUs must at least be 1")); _("Requested number of virtual CPUs must at least be 1"));
goto failure; return -1;
} }
if (esxVI_EnsureSession(priv->host) < 0) { if (esxVI_EnsureSession(priv->host) < 0) {
goto failure; return -1;
} }
maxVcpus = esxDomainGetMaxVcpus(domain); maxVcpus = esxDomainGetMaxVcpus(domain);
if (maxVcpus < 0) { if (maxVcpus < 0) {
goto failure; return -1;
} }
if (nvcpus > maxVcpus) { if (nvcpus > maxVcpus) {
...@@ -2039,7 +1984,7 @@ esxDomainSetVcpus(virDomainPtr domain, unsigned int nvcpus) ...@@ -2039,7 +1984,7 @@ esxDomainSetVcpus(virDomainPtr domain, unsigned int nvcpus)
_("Requested number of virtual CPUs is greater than max " _("Requested number of virtual CPUs is greater than max "
"allowable number of virtual CPUs for the domain: %d > %d"), "allowable number of virtual CPUs for the domain: %d > %d"),
nvcpus, maxVcpus); nvcpus, maxVcpus);
goto failure; return -1;
} }
if (esxVI_LookupVirtualMachineByUuidAndPrepareForTask if (esxVI_LookupVirtualMachineByUuidAndPrepareForTask
...@@ -2047,7 +1992,7 @@ esxDomainSetVcpus(virDomainPtr domain, unsigned int nvcpus) ...@@ -2047,7 +1992,7 @@ esxDomainSetVcpus(virDomainPtr domain, unsigned int nvcpus)
priv->autoAnswer) < 0 || priv->autoAnswer) < 0 ||
esxVI_VirtualMachineConfigSpec_Alloc(&spec) < 0 || esxVI_VirtualMachineConfigSpec_Alloc(&spec) < 0 ||
esxVI_Int_Alloc(&spec->numCPUs) < 0) { esxVI_Int_Alloc(&spec->numCPUs) < 0) {
goto failure; goto cleanup;
} }
spec->numCPUs->value = nvcpus; spec->numCPUs->value = nvcpus;
...@@ -2056,26 +2001,23 @@ esxDomainSetVcpus(virDomainPtr domain, unsigned int nvcpus) ...@@ -2056,26 +2001,23 @@ esxDomainSetVcpus(virDomainPtr domain, unsigned int nvcpus)
&task) < 0 || &task) < 0 ||
esxVI_WaitForTaskCompletion(priv->host, task, domain->uuid, esxVI_WaitForTaskCompletion(priv->host, task, domain->uuid,
priv->autoAnswer, &taskInfoState) < 0) { priv->autoAnswer, &taskInfoState) < 0) {
goto failure; goto cleanup;
} }
if (taskInfoState != esxVI_TaskInfoState_Success) { if (taskInfoState != esxVI_TaskInfoState_Success) {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Could not set number of virtual CPUs to %d"), nvcpus); _("Could not set number of virtual CPUs to %d"), nvcpus);
goto failure; goto cleanup;
} }
result = 0;
cleanup: cleanup:
esxVI_ObjectContent_Free(&virtualMachine); esxVI_ObjectContent_Free(&virtualMachine);
esxVI_VirtualMachineConfigSpec_Free(&spec); esxVI_VirtualMachineConfigSpec_Free(&spec);
esxVI_ManagedObjectReference_Free(&task); esxVI_ManagedObjectReference_Free(&task);
return result; return result;
failure:
result = -1;
goto cleanup;
} }
...@@ -2092,8 +2034,10 @@ esxDomainGetMaxVcpus(virDomainPtr domain) ...@@ -2092,8 +2034,10 @@ esxDomainGetMaxVcpus(virDomainPtr domain)
return priv->maxVcpus; return priv->maxVcpus;
} }
priv->maxVcpus = -1;
if (esxVI_EnsureSession(priv->host) < 0) { if (esxVI_EnsureSession(priv->host) < 0) {
goto failure; return -1;
} }
if (esxVI_String_AppendValueToList(&propertyNameList, if (esxVI_String_AppendValueToList(&propertyNameList,
...@@ -2101,13 +2045,13 @@ esxDomainGetMaxVcpus(virDomainPtr domain) ...@@ -2101,13 +2045,13 @@ esxDomainGetMaxVcpus(virDomainPtr domain)
esxVI_LookupObjectContentByType(priv->host, priv->host->hostFolder, esxVI_LookupObjectContentByType(priv->host, priv->host->hostFolder,
"HostSystem", propertyNameList, "HostSystem", propertyNameList,
esxVI_Boolean_True, &hostSystem) < 0) { esxVI_Boolean_True, &hostSystem) < 0) {
goto failure; goto cleanup;
} }
if (hostSystem == NULL) { if (hostSystem == NULL) {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
_("Could not retrieve the HostSystem object")); _("Could not retrieve the HostSystem object"));
goto failure; goto cleanup;
} }
for (dynamicProperty = hostSystem->propSet; dynamicProperty != NULL; for (dynamicProperty = hostSystem->propSet; dynamicProperty != NULL;
...@@ -2115,7 +2059,7 @@ esxDomainGetMaxVcpus(virDomainPtr domain) ...@@ -2115,7 +2059,7 @@ esxDomainGetMaxVcpus(virDomainPtr domain)
if (STREQ(dynamicProperty->name, "capability.maxSupportedVcpus")) { if (STREQ(dynamicProperty->name, "capability.maxSupportedVcpus")) {
if (esxVI_AnyType_ExpectType(dynamicProperty->val, if (esxVI_AnyType_ExpectType(dynamicProperty->val,
esxVI_Type_Int) < 0) { esxVI_Type_Int) < 0) {
goto failure; goto cleanup;
} }
priv->maxVcpus = dynamicProperty->val->int32; priv->maxVcpus = dynamicProperty->val->int32;
...@@ -2130,11 +2074,6 @@ esxDomainGetMaxVcpus(virDomainPtr domain) ...@@ -2130,11 +2074,6 @@ esxDomainGetMaxVcpus(virDomainPtr domain)
esxVI_ObjectContent_Free(&hostSystem); esxVI_ObjectContent_Free(&hostSystem);
return priv->maxVcpus; return priv->maxVcpus;
failure:
priv->maxVcpus = -1;
goto cleanup;
} }
...@@ -2157,7 +2096,7 @@ esxDomainDumpXML(virDomainPtr domain, int flags) ...@@ -2157,7 +2096,7 @@ esxDomainDumpXML(virDomainPtr domain, int flags)
char *xml = NULL; char *xml = NULL;
if (esxVI_EnsureSession(priv->host) < 0) { if (esxVI_EnsureSession(priv->host) < 0) {
goto failure; return NULL;
} }
if (esxVI_String_AppendValueToList(&propertyNameList, if (esxVI_String_AppendValueToList(&propertyNameList,
...@@ -2165,7 +2104,7 @@ esxDomainDumpXML(virDomainPtr domain, int flags) ...@@ -2165,7 +2104,7 @@ esxDomainDumpXML(virDomainPtr domain, int flags)
esxVI_LookupVirtualMachineByUuid(priv->host, domain->uuid, esxVI_LookupVirtualMachineByUuid(priv->host, domain->uuid,
propertyNameList, &virtualMachine, propertyNameList, &virtualMachine,
esxVI_Occurrence_RequiredItem) < 0) { esxVI_Occurrence_RequiredItem) < 0) {
goto failure; goto cleanup;
} }
for (dynamicProperty = virtualMachine->propSet; dynamicProperty != NULL; for (dynamicProperty = virtualMachine->propSet; dynamicProperty != NULL;
...@@ -2173,7 +2112,7 @@ esxDomainDumpXML(virDomainPtr domain, int flags) ...@@ -2173,7 +2112,7 @@ esxDomainDumpXML(virDomainPtr domain, int flags)
if (STREQ(dynamicProperty->name, "config.files.vmPathName")) { if (STREQ(dynamicProperty->name, "config.files.vmPathName")) {
if (esxVI_AnyType_ExpectType(dynamicProperty->val, if (esxVI_AnyType_ExpectType(dynamicProperty->val,
esxVI_Type_String) < 0) { esxVI_Type_String) < 0) {
goto failure; goto cleanup;
} }
vmPathName = dynamicProperty->val->string; vmPathName = dynamicProperty->val->string;
...@@ -2183,7 +2122,7 @@ esxDomainDumpXML(virDomainPtr domain, int flags) ...@@ -2183,7 +2122,7 @@ esxDomainDumpXML(virDomainPtr domain, int flags)
if (esxUtil_ParseDatastoreRelatedPath(vmPathName, &datastoreName, if (esxUtil_ParseDatastoreRelatedPath(vmPathName, &datastoreName,
&directoryName, &fileName) < 0) { &directoryName, &fileName) < 0) {
goto failure; goto cleanup;
} }
virBufferVSprintf(&buffer, "%s://%s:%d/folder/", priv->transport, virBufferVSprintf(&buffer, "%s://%s:%d/folder/", priv->transport,
...@@ -2202,13 +2141,13 @@ esxDomainDumpXML(virDomainPtr domain, int flags) ...@@ -2202,13 +2141,13 @@ esxDomainDumpXML(virDomainPtr domain, int flags)
if (virBufferError(&buffer)) { if (virBufferError(&buffer)) {
virReportOOMError(); virReportOOMError();
goto failure; goto cleanup;
} }
url = virBufferContentAndReset(&buffer); url = virBufferContentAndReset(&buffer);
if (esxVI_Context_DownloadFile(priv->host, url, &vmx) < 0) { if (esxVI_Context_DownloadFile(priv->host, url, &vmx) < 0) {
goto failure; goto cleanup;
} }
def = esxVMX_ParseConfig(priv->host, vmx, datastoreName, directoryName, def = esxVMX_ParseConfig(priv->host, vmx, datastoreName, directoryName,
...@@ -2219,6 +2158,10 @@ esxDomainDumpXML(virDomainPtr domain, int flags) ...@@ -2219,6 +2158,10 @@ esxDomainDumpXML(virDomainPtr domain, int flags)
} }
cleanup: cleanup:
if (url == NULL) {
virBufferFreeAndReset(&buffer);
}
esxVI_String_Free(&propertyNameList); esxVI_String_Free(&propertyNameList);
esxVI_ObjectContent_Free(&virtualMachine); esxVI_ObjectContent_Free(&virtualMachine);
VIR_FREE(datastoreName); VIR_FREE(datastoreName);
...@@ -2229,12 +2172,6 @@ esxDomainDumpXML(virDomainPtr domain, int flags) ...@@ -2229,12 +2172,6 @@ esxDomainDumpXML(virDomainPtr domain, int flags)
virDomainDefFree(def); virDomainDefFree(def);
return xml; return xml;
failure:
virBufferFreeAndReset(&buffer);
VIR_FREE(xml);
goto cleanup;
} }
...@@ -2301,6 +2238,7 @@ esxDomainXMLToNative(virConnectPtr conn, const char *nativeFormat, ...@@ -2301,6 +2238,7 @@ esxDomainXMLToNative(virConnectPtr conn, const char *nativeFormat,
static int static int
esxListDefinedDomains(virConnectPtr conn, char **const names, int maxnames) esxListDefinedDomains(virConnectPtr conn, char **const names, int maxnames)
{ {
bool success = false;
esxPrivate *priv = conn->privateData; esxPrivate *priv = conn->privateData;
esxVI_String *propertyNameList = NULL; esxVI_String *propertyNameList = NULL;
esxVI_ObjectContent *virtualMachineList = NULL; esxVI_ObjectContent *virtualMachineList = NULL;
...@@ -2320,7 +2258,7 @@ esxListDefinedDomains(virConnectPtr conn, char **const names, int maxnames) ...@@ -2320,7 +2258,7 @@ esxListDefinedDomains(virConnectPtr conn, char **const names, int maxnames)
} }
if (esxVI_EnsureSession(priv->host) < 0) { if (esxVI_EnsureSession(priv->host) < 0) {
goto failure; return -1;
} }
if (esxVI_String_AppendValueListToList(&propertyNameList, if (esxVI_String_AppendValueListToList(&propertyNameList,
...@@ -2330,14 +2268,14 @@ esxListDefinedDomains(virConnectPtr conn, char **const names, int maxnames) ...@@ -2330,14 +2268,14 @@ esxListDefinedDomains(virConnectPtr conn, char **const names, int maxnames)
"VirtualMachine", propertyNameList, "VirtualMachine", propertyNameList,
esxVI_Boolean_True, esxVI_Boolean_True,
&virtualMachineList) < 0) { &virtualMachineList) < 0) {
goto failure; goto cleanup;
} }
for (virtualMachine = virtualMachineList; virtualMachine != NULL; for (virtualMachine = virtualMachineList; virtualMachine != NULL;
virtualMachine = virtualMachine->_next) { virtualMachine = virtualMachine->_next) {
if (esxVI_GetVirtualMachinePowerState(virtualMachine, if (esxVI_GetVirtualMachinePowerState(virtualMachine,
&powerState) < 0) { &powerState) < 0) {
goto failure; goto cleanup;
} }
if (powerState == esxVI_VirtualMachinePowerState_PoweredOn) { if (powerState == esxVI_VirtualMachinePowerState_PoweredOn) {
...@@ -2350,14 +2288,14 @@ esxListDefinedDomains(virConnectPtr conn, char **const names, int maxnames) ...@@ -2350,14 +2288,14 @@ esxListDefinedDomains(virConnectPtr conn, char **const names, int maxnames)
if (STREQ(dynamicProperty->name, "name")) { if (STREQ(dynamicProperty->name, "name")) {
if (esxVI_AnyType_ExpectType(dynamicProperty->val, if (esxVI_AnyType_ExpectType(dynamicProperty->val,
esxVI_Type_String) < 0) { esxVI_Type_String) < 0) {
goto failure; goto cleanup;
} }
names[count] = strdup(dynamicProperty->val->string); names[count] = strdup(dynamicProperty->val->string);
if (names[count] == NULL) { if (names[count] == NULL) {
virReportOOMError(); virReportOOMError();
goto failure; goto cleanup;
} }
count++; count++;
...@@ -2370,20 +2308,21 @@ esxListDefinedDomains(virConnectPtr conn, char **const names, int maxnames) ...@@ -2370,20 +2308,21 @@ esxListDefinedDomains(virConnectPtr conn, char **const names, int maxnames)
} }
} }
cleanup: success = true;
esxVI_String_Free(&propertyNameList);
esxVI_ObjectContent_Free(&virtualMachineList);
return count; cleanup:
if (! success) {
for (i = 0; i < count; ++i) {
VIR_FREE(names[i]);
}
failure: count = -1;
for (i = 0; i < count; ++i) {
VIR_FREE(names[i]);
} }
count = -1; esxVI_String_Free(&propertyNameList);
esxVI_ObjectContent_Free(&virtualMachineList);
goto cleanup; return count;
} }
...@@ -2407,7 +2346,7 @@ esxNumberOfDefinedDomains(virConnectPtr conn) ...@@ -2407,7 +2346,7 @@ esxNumberOfDefinedDomains(virConnectPtr conn)
static int static int
esxDomainCreate(virDomainPtr domain) esxDomainCreate(virDomainPtr domain)
{ {
int result = 0; int result = -1;
esxPrivate *priv = domain->conn->privateData; esxPrivate *priv = domain->conn->privateData;
esxVI_ObjectContent *virtualMachine = NULL; esxVI_ObjectContent *virtualMachine = NULL;
esxVI_String *propertyNameList = NULL; esxVI_String *propertyNameList = NULL;
...@@ -2416,7 +2355,7 @@ esxDomainCreate(virDomainPtr domain) ...@@ -2416,7 +2355,7 @@ esxDomainCreate(virDomainPtr domain)
esxVI_TaskInfoState taskInfoState; esxVI_TaskInfoState taskInfoState;
if (esxVI_EnsureSession(priv->host) < 0) { if (esxVI_EnsureSession(priv->host) < 0) {
goto failure; return -1;
} }
if (esxVI_String_AppendValueToList(&propertyNameList, if (esxVI_String_AppendValueToList(&propertyNameList,
...@@ -2426,38 +2365,35 @@ esxDomainCreate(virDomainPtr domain) ...@@ -2426,38 +2365,35 @@ esxDomainCreate(virDomainPtr domain)
priv->autoAnswer) < 0 || priv->autoAnswer) < 0 ||
esxVI_GetVirtualMachinePowerState(virtualMachine, esxVI_GetVirtualMachinePowerState(virtualMachine,
&powerState) < 0) { &powerState) < 0) {
goto failure; goto cleanup;
} }
if (powerState != esxVI_VirtualMachinePowerState_PoweredOff) { if (powerState != esxVI_VirtualMachinePowerState_PoweredOff) {
ESX_ERROR(VIR_ERR_OPERATION_INVALID, "%s", ESX_ERROR(VIR_ERR_OPERATION_INVALID, "%s",
_("Domain is not powered off")); _("Domain is not powered off"));
goto failure; goto cleanup;
} }
if (esxVI_PowerOnVM_Task(priv->host, virtualMachine->obj, NULL, if (esxVI_PowerOnVM_Task(priv->host, virtualMachine->obj, NULL,
&task) < 0 || &task) < 0 ||
esxVI_WaitForTaskCompletion(priv->host, task, domain->uuid, esxVI_WaitForTaskCompletion(priv->host, task, domain->uuid,
priv->autoAnswer, &taskInfoState) < 0) { priv->autoAnswer, &taskInfoState) < 0) {
goto failure; goto cleanup;
} }
if (taskInfoState != esxVI_TaskInfoState_Success) { if (taskInfoState != esxVI_TaskInfoState_Success) {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not start domain")); ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not start domain"));
goto failure; goto cleanup;
} }
result = 0;
cleanup: cleanup:
esxVI_ObjectContent_Free(&virtualMachine); esxVI_ObjectContent_Free(&virtualMachine);
esxVI_String_Free(&propertyNameList); esxVI_String_Free(&propertyNameList);
esxVI_ManagedObjectReference_Free(&task); esxVI_ManagedObjectReference_Free(&task);
return result; return result;
failure:
result = -1;
goto cleanup;
} }
...@@ -2485,7 +2421,7 @@ esxDomainDefineXML(virConnectPtr conn, const char *xml ATTRIBUTE_UNUSED) ...@@ -2485,7 +2421,7 @@ esxDomainDefineXML(virConnectPtr conn, const char *xml ATTRIBUTE_UNUSED)
virDomainPtr domain = NULL; virDomainPtr domain = NULL;
if (esxVI_EnsureSession(priv->host) < 0) { if (esxVI_EnsureSession(priv->host) < 0) {
goto failure; return NULL;
} }
/* Parse domain XML */ /* Parse domain XML */
...@@ -2493,14 +2429,14 @@ esxDomainDefineXML(virConnectPtr conn, const char *xml ATTRIBUTE_UNUSED) ...@@ -2493,14 +2429,14 @@ esxDomainDefineXML(virConnectPtr conn, const char *xml ATTRIBUTE_UNUSED)
VIR_DOMAIN_XML_INACTIVE); VIR_DOMAIN_XML_INACTIVE);
if (def == NULL) { if (def == NULL) {
goto failure; return NULL;
} }
/* Check if an existing domain should be edited */ /* Check if an existing domain should be edited */
if (esxVI_LookupVirtualMachineByUuid(priv->host, def->uuid, NULL, if (esxVI_LookupVirtualMachineByUuid(priv->host, def->uuid, NULL,
&virtualMachine, &virtualMachine,
esxVI_Occurrence_OptionalItem) < 0) { esxVI_Occurrence_OptionalItem) < 0) {
goto failure; goto cleanup;
} }
if (virtualMachine != NULL) { if (virtualMachine != NULL) {
...@@ -2508,14 +2444,14 @@ esxDomainDefineXML(virConnectPtr conn, const char *xml ATTRIBUTE_UNUSED) ...@@ -2508,14 +2444,14 @@ esxDomainDefineXML(virConnectPtr conn, const char *xml ATTRIBUTE_UNUSED)
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
_("Domain already exists, editing existing domains is not " _("Domain already exists, editing existing domains is not "
"supported yet")); "supported yet"));
goto failure; goto cleanup;
} }
/* Build VMX from domain XML */ /* Build VMX from domain XML */
vmx = esxVMX_FormatConfig(priv->host, def, priv->host->productVersion); vmx = esxVMX_FormatConfig(priv->host, def, priv->host->productVersion);
if (vmx == NULL) { if (vmx == NULL) {
goto failure; goto cleanup;
} }
/* /*
...@@ -2529,7 +2465,7 @@ esxDomainDefineXML(virConnectPtr conn, const char *xml ATTRIBUTE_UNUSED) ...@@ -2529,7 +2465,7 @@ esxDomainDefineXML(virConnectPtr conn, const char *xml ATTRIBUTE_UNUSED)
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
_("Domain XML doesn't contain any disks, cannot deduce " _("Domain XML doesn't contain any disks, cannot deduce "
"datastore and path for VMX file")); "datastore and path for VMX file"));
goto failure; goto cleanup;
} }
for (i = 0; i < def->ndisks; ++i) { for (i = 0; i < def->ndisks; ++i) {
...@@ -2544,26 +2480,26 @@ esxDomainDefineXML(virConnectPtr conn, const char *xml ATTRIBUTE_UNUSED) ...@@ -2544,26 +2480,26 @@ esxDomainDefineXML(virConnectPtr conn, const char *xml ATTRIBUTE_UNUSED)
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
_("Domain XML doesn't contain any file-based harddisks, " _("Domain XML doesn't contain any file-based harddisks, "
"cannot deduce datastore and path for VMX file")); "cannot deduce datastore and path for VMX file"));
goto failure; goto cleanup;
} }
if (disk->src == NULL) { if (disk->src == NULL) {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
_("First file-based harddisk has no source, cannot deduce " _("First file-based harddisk has no source, cannot deduce "
"datastore and path for VMX file")); "datastore and path for VMX file"));
goto failure; goto cleanup;
} }
if (esxUtil_ParseDatastoreRelatedPath(disk->src, &datastoreName, if (esxUtil_ParseDatastoreRelatedPath(disk->src, &datastoreName,
&directoryName, &fileName) < 0) { &directoryName, &fileName) < 0) {
goto failure; goto cleanup;
} }
if (! virFileHasSuffix(fileName, ".vmdk")) { if (! virFileHasSuffix(fileName, ".vmdk")) {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Expecting source '%s' of first file-based harddisk to " _("Expecting source '%s' of first file-based harddisk to "
"be a VMDK image"), disk->src); "be a VMDK image"), disk->src);
goto failure; goto cleanup;
} }
virBufferVSprintf(&buffer, "%s://%s:%d/folder/", priv->transport, virBufferVSprintf(&buffer, "%s://%s:%d/folder/", priv->transport,
...@@ -2582,7 +2518,7 @@ esxDomainDefineXML(virConnectPtr conn, const char *xml ATTRIBUTE_UNUSED) ...@@ -2582,7 +2518,7 @@ esxDomainDefineXML(virConnectPtr conn, const char *xml ATTRIBUTE_UNUSED)
if (virBufferError(&buffer)) { if (virBufferError(&buffer)) {
virReportOOMError(); virReportOOMError();
goto failure; goto cleanup;
} }
url = virBufferContentAndReset(&buffer); url = virBufferContentAndReset(&buffer);
...@@ -2591,13 +2527,13 @@ esxDomainDefineXML(virConnectPtr conn, const char *xml ATTRIBUTE_UNUSED) ...@@ -2591,13 +2527,13 @@ esxDomainDefineXML(virConnectPtr conn, const char *xml ATTRIBUTE_UNUSED)
if (virAsprintf(&datastoreRelatedPath, "[%s] %s/%s.vmx", datastoreName, if (virAsprintf(&datastoreRelatedPath, "[%s] %s/%s.vmx", datastoreName,
directoryName, def->name) < 0) { directoryName, def->name) < 0) {
virReportOOMError(); virReportOOMError();
goto failure; goto cleanup;
} }
} else { } else {
if (virAsprintf(&datastoreRelatedPath, "[%s] %s.vmx", datastoreName, if (virAsprintf(&datastoreRelatedPath, "[%s] %s.vmx", datastoreName,
def->name) < 0) { def->name) < 0) {
virReportOOMError(); virReportOOMError();
goto failure; goto cleanup;
} }
} }
...@@ -2605,12 +2541,12 @@ esxDomainDefineXML(virConnectPtr conn, const char *xml ATTRIBUTE_UNUSED) ...@@ -2605,12 +2541,12 @@ esxDomainDefineXML(virConnectPtr conn, const char *xml ATTRIBUTE_UNUSED)
if (esxVI_String_AppendValueToList(&propertyNameList, "parent") < 0 || if (esxVI_String_AppendValueToList(&propertyNameList, "parent") < 0 ||
esxVI_LookupHostSystemByIp(priv->host, priv->host->ipAddress, esxVI_LookupHostSystemByIp(priv->host, priv->host->ipAddress,
propertyNameList, &hostSystem) < 0) { propertyNameList, &hostSystem) < 0) {
goto failure; goto cleanup;
} }
if (esxVI_LookupResourcePoolByHostSystem(priv->host, hostSystem, if (esxVI_LookupResourcePoolByHostSystem(priv->host, hostSystem,
&resourcePool) < 0) { &resourcePool) < 0) {
goto failure; goto cleanup;
} }
/* Check, if VMX file already exists */ /* Check, if VMX file already exists */
...@@ -2618,7 +2554,7 @@ esxDomainDefineXML(virConnectPtr conn, const char *xml ATTRIBUTE_UNUSED) ...@@ -2618,7 +2554,7 @@ esxDomainDefineXML(virConnectPtr conn, const char *xml ATTRIBUTE_UNUSED)
/* Upload VMX file */ /* Upload VMX file */
if (esxVI_Context_UploadFile(priv->host, url, vmx) < 0) { if (esxVI_Context_UploadFile(priv->host, url, vmx) < 0) {
goto failure; goto cleanup;
} }
/* Register the domain */ /* Register the domain */
...@@ -2627,12 +2563,12 @@ esxDomainDefineXML(virConnectPtr conn, const char *xml ATTRIBUTE_UNUSED) ...@@ -2627,12 +2563,12 @@ esxDomainDefineXML(virConnectPtr conn, const char *xml ATTRIBUTE_UNUSED)
resourcePool, hostSystem->obj, &task) < 0 || resourcePool, hostSystem->obj, &task) < 0 ||
esxVI_WaitForTaskCompletion(priv->host, task, def->uuid, esxVI_WaitForTaskCompletion(priv->host, task, def->uuid,
priv->autoAnswer, &taskInfoState) < 0) { priv->autoAnswer, &taskInfoState) < 0) {
goto failure; goto cleanup;
} }
if (taskInfoState != esxVI_TaskInfoState_Success) { if (taskInfoState != esxVI_TaskInfoState_Success) {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not define domain")); ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not define domain"));
goto failure; goto cleanup;
} }
domain = virGetDomain(conn, def->name, def->uuid); domain = virGetDomain(conn, def->name, def->uuid);
...@@ -2644,6 +2580,10 @@ esxDomainDefineXML(virConnectPtr conn, const char *xml ATTRIBUTE_UNUSED) ...@@ -2644,6 +2580,10 @@ esxDomainDefineXML(virConnectPtr conn, const char *xml ATTRIBUTE_UNUSED)
/* FIXME: Add proper rollback in case of an error */ /* FIXME: Add proper rollback in case of an error */
cleanup: cleanup:
if (url == NULL) {
virBufferFreeAndReset(&buffer);
}
virDomainDefFree(def); virDomainDefFree(def);
VIR_FREE(vmx); VIR_FREE(vmx);
VIR_FREE(datastoreName); VIR_FREE(datastoreName);
...@@ -2658,13 +2598,6 @@ esxDomainDefineXML(virConnectPtr conn, const char *xml ATTRIBUTE_UNUSED) ...@@ -2658,13 +2598,6 @@ esxDomainDefineXML(virConnectPtr conn, const char *xml ATTRIBUTE_UNUSED)
esxVI_ManagedObjectReference_Free(&task); esxVI_ManagedObjectReference_Free(&task);
return domain; return domain;
failure:
virBufferFreeAndReset(&buffer);
domain = NULL;
goto cleanup;
} }
...@@ -2672,7 +2605,7 @@ esxDomainDefineXML(virConnectPtr conn, const char *xml ATTRIBUTE_UNUSED) ...@@ -2672,7 +2605,7 @@ esxDomainDefineXML(virConnectPtr conn, const char *xml ATTRIBUTE_UNUSED)
static int static int
esxDomainUndefine(virDomainPtr domain) esxDomainUndefine(virDomainPtr domain)
{ {
int result = 0; int result = -1;
esxPrivate *priv = domain->conn->privateData; esxPrivate *priv = domain->conn->privateData;
esxVI_Context *ctx = NULL; esxVI_Context *ctx = NULL;
esxVI_ObjectContent *virtualMachine = NULL; esxVI_ObjectContent *virtualMachine = NULL;
...@@ -2686,7 +2619,7 @@ esxDomainUndefine(virDomainPtr domain) ...@@ -2686,7 +2619,7 @@ esxDomainUndefine(virDomainPtr domain)
} }
if (esxVI_EnsureSession(ctx) < 0) { if (esxVI_EnsureSession(ctx) < 0) {
goto failure; return -1;
} }
if (esxVI_String_AppendValueToList(&propertyNameList, if (esxVI_String_AppendValueToList(&propertyNameList,
...@@ -2695,30 +2628,27 @@ esxDomainUndefine(virDomainPtr domain) ...@@ -2695,30 +2628,27 @@ esxDomainUndefine(virDomainPtr domain)
&virtualMachine, &virtualMachine,
esxVI_Occurrence_RequiredItem) < 0 || esxVI_Occurrence_RequiredItem) < 0 ||
esxVI_GetVirtualMachinePowerState(virtualMachine, &powerState) < 0) { esxVI_GetVirtualMachinePowerState(virtualMachine, &powerState) < 0) {
goto failure; goto cleanup;
} }
if (powerState != esxVI_VirtualMachinePowerState_Suspended && if (powerState != esxVI_VirtualMachinePowerState_Suspended &&
powerState != esxVI_VirtualMachinePowerState_PoweredOff) { powerState != esxVI_VirtualMachinePowerState_PoweredOff) {
ESX_ERROR(VIR_ERR_OPERATION_INVALID, "%s", ESX_ERROR(VIR_ERR_OPERATION_INVALID, "%s",
_("Domain is not suspended or powered off")); _("Domain is not suspended or powered off"));
goto failure; goto cleanup;
} }
if (esxVI_UnregisterVM(ctx, virtualMachine->obj) < 0) { if (esxVI_UnregisterVM(ctx, virtualMachine->obj) < 0) {
goto failure; goto cleanup;
} }
result = 0;
cleanup: cleanup:
esxVI_ObjectContent_Free(&virtualMachine); esxVI_ObjectContent_Free(&virtualMachine);
esxVI_String_Free(&propertyNameList); esxVI_String_Free(&propertyNameList);
return result; return result;
failure:
result = -1;
goto cleanup;
} }
...@@ -2774,7 +2704,7 @@ static int ...@@ -2774,7 +2704,7 @@ static int
esxDomainGetSchedulerParameters(virDomainPtr domain, esxDomainGetSchedulerParameters(virDomainPtr domain,
virSchedParameterPtr params, int *nparams) virSchedParameterPtr params, int *nparams)
{ {
int result = 0; int result = -1;
esxPrivate *priv = domain->conn->privateData; esxPrivate *priv = domain->conn->privateData;
esxVI_String *propertyNameList = NULL; esxVI_String *propertyNameList = NULL;
esxVI_ObjectContent *virtualMachine = NULL; esxVI_ObjectContent *virtualMachine = NULL;
...@@ -2786,11 +2716,11 @@ esxDomainGetSchedulerParameters(virDomainPtr domain, ...@@ -2786,11 +2716,11 @@ esxDomainGetSchedulerParameters(virDomainPtr domain,
if (*nparams < 3) { if (*nparams < 3) {
ESX_ERROR(VIR_ERR_INVALID_ARG, "%s", ESX_ERROR(VIR_ERR_INVALID_ARG, "%s",
_("Parameter array must have space for 3 items")); _("Parameter array must have space for 3 items"));
goto failure; return -1;
} }
if (esxVI_EnsureSession(priv->host) < 0) { if (esxVI_EnsureSession(priv->host) < 0) {
goto failure; return -1;
} }
if (esxVI_String_AppendValueListToList(&propertyNameList, if (esxVI_String_AppendValueListToList(&propertyNameList,
...@@ -2800,7 +2730,7 @@ esxDomainGetSchedulerParameters(virDomainPtr domain, ...@@ -2800,7 +2730,7 @@ esxDomainGetSchedulerParameters(virDomainPtr domain,
esxVI_LookupVirtualMachineByUuid(priv->host, domain->uuid, esxVI_LookupVirtualMachineByUuid(priv->host, domain->uuid,
propertyNameList, &virtualMachine, propertyNameList, &virtualMachine,
esxVI_Occurrence_RequiredItem) < 0) { esxVI_Occurrence_RequiredItem) < 0) {
goto failure; goto cleanup;
} }
for (dynamicProperty = virtualMachine->propSet; for (dynamicProperty = virtualMachine->propSet;
...@@ -2815,7 +2745,7 @@ esxDomainGetSchedulerParameters(virDomainPtr domain, ...@@ -2815,7 +2745,7 @@ esxDomainGetSchedulerParameters(virDomainPtr domain,
if (esxVI_AnyType_ExpectType(dynamicProperty->val, if (esxVI_AnyType_ExpectType(dynamicProperty->val,
esxVI_Type_Long) < 0) { esxVI_Type_Long) < 0) {
goto failure; goto cleanup;
} }
params[i].value.l = dynamicProperty->val->int64; params[i].value.l = dynamicProperty->val->int64;
...@@ -2831,7 +2761,7 @@ esxDomainGetSchedulerParameters(virDomainPtr domain, ...@@ -2831,7 +2761,7 @@ esxDomainGetSchedulerParameters(virDomainPtr domain,
if (esxVI_AnyType_ExpectType(dynamicProperty->val, if (esxVI_AnyType_ExpectType(dynamicProperty->val,
esxVI_Type_Long) < 0) { esxVI_Type_Long) < 0) {
goto failure; goto cleanup;
} }
params[i].value.l = dynamicProperty->val->int64; params[i].value.l = dynamicProperty->val->int64;
...@@ -2847,7 +2777,7 @@ esxDomainGetSchedulerParameters(virDomainPtr domain, ...@@ -2847,7 +2777,7 @@ esxDomainGetSchedulerParameters(virDomainPtr domain,
if (esxVI_SharesInfo_CastFromAnyType(dynamicProperty->val, if (esxVI_SharesInfo_CastFromAnyType(dynamicProperty->val,
&sharesInfo) < 0) { &sharesInfo) < 0) {
goto failure; goto cleanup;
} }
switch (sharesInfo->level) { switch (sharesInfo->level) {
...@@ -2871,7 +2801,7 @@ esxDomainGetSchedulerParameters(virDomainPtr domain, ...@@ -2871,7 +2801,7 @@ esxDomainGetSchedulerParameters(virDomainPtr domain,
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Shares level has unknown value %d"), _("Shares level has unknown value %d"),
(int)sharesInfo->level); (int)sharesInfo->level);
goto failure; goto cleanup;
} }
esxVI_SharesInfo_Free(&sharesInfo); esxVI_SharesInfo_Free(&sharesInfo);
...@@ -2884,17 +2814,13 @@ esxDomainGetSchedulerParameters(virDomainPtr domain, ...@@ -2884,17 +2814,13 @@ esxDomainGetSchedulerParameters(virDomainPtr domain,
} }
*nparams = i; *nparams = i;
result = 0;
cleanup: cleanup:
esxVI_String_Free(&propertyNameList); esxVI_String_Free(&propertyNameList);
esxVI_ObjectContent_Free(&virtualMachine); esxVI_ObjectContent_Free(&virtualMachine);
return result; return result;
failure:
result = -1;
goto cleanup;
} }
...@@ -2903,7 +2829,7 @@ static int ...@@ -2903,7 +2829,7 @@ static int
esxDomainSetSchedulerParameters(virDomainPtr domain, esxDomainSetSchedulerParameters(virDomainPtr domain,
virSchedParameterPtr params, int nparams) virSchedParameterPtr params, int nparams)
{ {
int result = 0; int result = -1;
esxPrivate *priv = domain->conn->privateData; esxPrivate *priv = domain->conn->privateData;
esxVI_ObjectContent *virtualMachine = NULL; esxVI_ObjectContent *virtualMachine = NULL;
esxVI_VirtualMachineConfigSpec *spec = NULL; esxVI_VirtualMachineConfigSpec *spec = NULL;
...@@ -2913,7 +2839,7 @@ esxDomainSetSchedulerParameters(virDomainPtr domain, ...@@ -2913,7 +2839,7 @@ esxDomainSetSchedulerParameters(virDomainPtr domain,
int i; int i;
if (esxVI_EnsureSession(priv->host) < 0) { if (esxVI_EnsureSession(priv->host) < 0) {
goto failure; return -1;
} }
if (esxVI_LookupVirtualMachineByUuidAndPrepareForTask if (esxVI_LookupVirtualMachineByUuidAndPrepareForTask
...@@ -2921,28 +2847,28 @@ esxDomainSetSchedulerParameters(virDomainPtr domain, ...@@ -2921,28 +2847,28 @@ esxDomainSetSchedulerParameters(virDomainPtr domain,
priv->autoAnswer) < 0 || priv->autoAnswer) < 0 ||
esxVI_VirtualMachineConfigSpec_Alloc(&spec) < 0 || esxVI_VirtualMachineConfigSpec_Alloc(&spec) < 0 ||
esxVI_ResourceAllocationInfo_Alloc(&spec->cpuAllocation) < 0) { esxVI_ResourceAllocationInfo_Alloc(&spec->cpuAllocation) < 0) {
goto failure; goto cleanup;
} }
for (i = 0; i < nparams; ++i) { for (i = 0; i < nparams; ++i) {
if (STREQ (params[i].field, "reservation") && if (STREQ (params[i].field, "reservation") &&
params[i].type == VIR_DOMAIN_SCHED_FIELD_LLONG) { params[i].type == VIR_DOMAIN_SCHED_FIELD_LLONG) {
if (esxVI_Long_Alloc(&spec->cpuAllocation->reservation) < 0) { if (esxVI_Long_Alloc(&spec->cpuAllocation->reservation) < 0) {
goto failure; goto cleanup;
} }
if (params[i].value.l < 0) { if (params[i].value.l < 0) {
ESX_ERROR(VIR_ERR_INVALID_ARG, ESX_ERROR(VIR_ERR_INVALID_ARG,
_("Could not set reservation to %lld MHz, expecting " _("Could not set reservation to %lld MHz, expecting "
"positive value"), params[i].value.l); "positive value"), params[i].value.l);
goto failure; goto cleanup;
} }
spec->cpuAllocation->reservation->value = params[i].value.l; spec->cpuAllocation->reservation->value = params[i].value.l;
} else if (STREQ (params[i].field, "limit") && } else if (STREQ (params[i].field, "limit") &&
params[i].type == VIR_DOMAIN_SCHED_FIELD_LLONG) { params[i].type == VIR_DOMAIN_SCHED_FIELD_LLONG) {
if (esxVI_Long_Alloc(&spec->cpuAllocation->limit) < 0) { if (esxVI_Long_Alloc(&spec->cpuAllocation->limit) < 0) {
goto failure; goto cleanup;
} }
if (params[i].value.l < -1) { if (params[i].value.l < -1) {
...@@ -2950,7 +2876,7 @@ esxDomainSetSchedulerParameters(virDomainPtr domain, ...@@ -2950,7 +2876,7 @@ esxDomainSetSchedulerParameters(virDomainPtr domain,
_("Could not set limit to %lld MHz, expecting " _("Could not set limit to %lld MHz, expecting "
"positive value or -1 (unlimited)"), "positive value or -1 (unlimited)"),
params[i].value.l); params[i].value.l);
goto failure; goto cleanup;
} }
spec->cpuAllocation->limit->value = params[i].value.l; spec->cpuAllocation->limit->value = params[i].value.l;
...@@ -2958,7 +2884,7 @@ esxDomainSetSchedulerParameters(virDomainPtr domain, ...@@ -2958,7 +2884,7 @@ esxDomainSetSchedulerParameters(virDomainPtr domain,
params[i].type == VIR_DOMAIN_SCHED_FIELD_INT) { params[i].type == VIR_DOMAIN_SCHED_FIELD_INT) {
if (esxVI_SharesInfo_Alloc(&sharesInfo) < 0 || if (esxVI_SharesInfo_Alloc(&sharesInfo) < 0 ||
esxVI_Int_Alloc(&sharesInfo->shares) < 0) { esxVI_Int_Alloc(&sharesInfo->shares) < 0) {
goto failure; goto cleanup;
} }
spec->cpuAllocation->shares = sharesInfo; spec->cpuAllocation->shares = sharesInfo;
...@@ -2990,13 +2916,13 @@ esxDomainSetSchedulerParameters(virDomainPtr domain, ...@@ -2990,13 +2916,13 @@ esxDomainSetSchedulerParameters(virDomainPtr domain,
_("Could not set shares to %d, expecting positive " _("Could not set shares to %d, expecting positive "
"value or -1 (low), -2 (normal) or -3 (high)"), "value or -1 (low), -2 (normal) or -3 (high)"),
params[i].value.i); params[i].value.i);
goto failure; goto cleanup;
} }
} }
} else { } else {
ESX_ERROR(VIR_ERR_INVALID_ARG, _("Unknown field '%s'"), ESX_ERROR(VIR_ERR_INVALID_ARG, _("Unknown field '%s'"),
params[i].field); params[i].field);
goto failure; goto cleanup;
} }
} }
...@@ -3004,26 +2930,23 @@ esxDomainSetSchedulerParameters(virDomainPtr domain, ...@@ -3004,26 +2930,23 @@ esxDomainSetSchedulerParameters(virDomainPtr domain,
&task) < 0 || &task) < 0 ||
esxVI_WaitForTaskCompletion(priv->host, task, domain->uuid, esxVI_WaitForTaskCompletion(priv->host, task, domain->uuid,
priv->autoAnswer, &taskInfoState) < 0) { priv->autoAnswer, &taskInfoState) < 0) {
goto failure; goto cleanup;
} }
if (taskInfoState != esxVI_TaskInfoState_Success) { if (taskInfoState != esxVI_TaskInfoState_Success) {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
_("Could not change scheduler parameters")); _("Could not change scheduler parameters"));
goto failure; goto cleanup;
} }
result = 0;
cleanup: cleanup:
esxVI_ObjectContent_Free(&virtualMachine); esxVI_ObjectContent_Free(&virtualMachine);
esxVI_VirtualMachineConfigSpec_Free(&spec); esxVI_VirtualMachineConfigSpec_Free(&spec);
esxVI_ManagedObjectReference_Free(&task); esxVI_ManagedObjectReference_Free(&task);
return result; return result;
failure:
result = -1;
goto cleanup;
} }
...@@ -3037,7 +2960,7 @@ esxDomainMigratePrepare(virConnectPtr dconn, ...@@ -3037,7 +2960,7 @@ esxDomainMigratePrepare(virConnectPtr dconn,
const char *dname ATTRIBUTE_UNUSED, const char *dname ATTRIBUTE_UNUSED,
unsigned long resource ATTRIBUTE_UNUSED) unsigned long resource ATTRIBUTE_UNUSED)
{ {
int result = 0; int result = -1;
char *transport = NULL; char *transport = NULL;
if (uri_in == NULL) { if (uri_in == NULL) {
...@@ -3048,19 +2971,16 @@ esxDomainMigratePrepare(virConnectPtr dconn, ...@@ -3048,19 +2971,16 @@ esxDomainMigratePrepare(virConnectPtr dconn,
if (virAsprintf(uri_out, "%s://%s:%d/sdk", transport, if (virAsprintf(uri_out, "%s://%s:%d/sdk", transport,
dconn->uri->server, dconn->uri->port) < 0) { dconn->uri->server, dconn->uri->port) < 0) {
virReportOOMError(); virReportOOMError();
goto failure; goto cleanup;
} }
} }
result = 0;
cleanup: cleanup:
VIR_FREE(transport); VIR_FREE(transport);
return result; return result;
failure:
result = -1;
goto cleanup;
} }
...@@ -3074,7 +2994,7 @@ esxDomainMigratePerform(virDomainPtr domain, ...@@ -3074,7 +2994,7 @@ esxDomainMigratePerform(virDomainPtr domain,
const char *dname, const char *dname,
unsigned long bandwidth ATTRIBUTE_UNUSED) unsigned long bandwidth ATTRIBUTE_UNUSED)
{ {
int result = 0; int result = -1;
esxPrivate *priv = domain->conn->privateData; esxPrivate *priv = domain->conn->privateData;
xmlURIPtr xmlUri = NULL; xmlURIPtr xmlUri = NULL;
char hostIpAddress[NI_MAXHOST] = ""; char hostIpAddress[NI_MAXHOST] = "";
...@@ -3089,17 +3009,17 @@ esxDomainMigratePerform(virDomainPtr domain, ...@@ -3089,17 +3009,17 @@ esxDomainMigratePerform(virDomainPtr domain,
if (priv->vCenter == NULL) { if (priv->vCenter == NULL) {
ESX_ERROR(VIR_ERR_INVALID_ARG, "%s", ESX_ERROR(VIR_ERR_INVALID_ARG, "%s",
_("Migration not possible without a vCenter")); _("Migration not possible without a vCenter"));
goto failure; return -1;
} }
if (dname != NULL) { if (dname != NULL) {
ESX_ERROR(VIR_ERR_INVALID_ARG, "%s", ESX_ERROR(VIR_ERR_INVALID_ARG, "%s",
_("Renaming domains on migration not supported")); _("Renaming domains on migration not supported"));
goto failure; return -1;
} }
if (esxVI_EnsureSession(priv->vCenter) < 0) { if (esxVI_EnsureSession(priv->vCenter) < 0) {
goto failure; return -1;
} }
/* Parse the destination URI and resolve the hostname */ /* Parse the destination URI and resolve the hostname */
...@@ -3107,12 +3027,12 @@ esxDomainMigratePerform(virDomainPtr domain, ...@@ -3107,12 +3027,12 @@ esxDomainMigratePerform(virDomainPtr domain,
if (xmlUri == NULL) { if (xmlUri == NULL) {
virReportOOMError(); virReportOOMError();
goto failure; return -1;
} }
if (esxUtil_ResolveHostname(xmlUri->server, hostIpAddress, if (esxUtil_ResolveHostname(xmlUri->server, hostIpAddress,
NI_MAXHOST) < 0) { NI_MAXHOST) < 0) {
goto failure; goto cleanup;
} }
/* Lookup VirtualMachine, HostSystem and ResourcePool */ /* Lookup VirtualMachine, HostSystem and ResourcePool */
...@@ -3122,12 +3042,12 @@ esxDomainMigratePerform(virDomainPtr domain, ...@@ -3122,12 +3042,12 @@ esxDomainMigratePerform(virDomainPtr domain,
esxVI_String_AppendValueToList(&propertyNameList, "parent") < 0 || esxVI_String_AppendValueToList(&propertyNameList, "parent") < 0 ||
esxVI_LookupHostSystemByIp(priv->vCenter, hostIpAddress, esxVI_LookupHostSystemByIp(priv->vCenter, hostIpAddress,
propertyNameList, &hostSystem) < 0) { propertyNameList, &hostSystem) < 0) {
goto failure; goto cleanup;
} }
if (esxVI_LookupResourcePoolByHostSystem(priv->vCenter, hostSystem, if (esxVI_LookupResourcePoolByHostSystem(priv->vCenter, hostSystem,
&resourcePool) < 0) { &resourcePool) < 0) {
goto failure; goto cleanup;
} }
/* Validate the purposed migration */ /* Validate the purposed migration */
...@@ -3135,7 +3055,7 @@ esxDomainMigratePerform(virDomainPtr domain, ...@@ -3135,7 +3055,7 @@ esxDomainMigratePerform(virDomainPtr domain,
esxVI_VirtualMachinePowerState_Undefined, esxVI_VirtualMachinePowerState_Undefined,
NULL, resourcePool, hostSystem->obj, NULL, resourcePool, hostSystem->obj,
&eventList) < 0) { &eventList) < 0) {
goto failure; goto cleanup;
} }
if (eventList != NULL) { if (eventList != NULL) {
...@@ -3153,7 +3073,7 @@ esxDomainMigratePerform(virDomainPtr domain, ...@@ -3153,7 +3073,7 @@ esxDomainMigratePerform(virDomainPtr domain,
"problem")); "problem"));
} }
goto failure; goto cleanup;
} }
/* Perform the purposed migration */ /* Perform the purposed migration */
...@@ -3164,16 +3084,18 @@ esxDomainMigratePerform(virDomainPtr domain, ...@@ -3164,16 +3084,18 @@ esxDomainMigratePerform(virDomainPtr domain,
&task) < 0 || &task) < 0 ||
esxVI_WaitForTaskCompletion(priv->vCenter, task, domain->uuid, esxVI_WaitForTaskCompletion(priv->vCenter, task, domain->uuid,
priv->autoAnswer, &taskInfoState) < 0) { priv->autoAnswer, &taskInfoState) < 0) {
goto failure; goto cleanup;
} }
if (taskInfoState != esxVI_TaskInfoState_Success) { if (taskInfoState != esxVI_TaskInfoState_Success) {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
_("Could not migrate domain, migration task finished with " _("Could not migrate domain, migration task finished with "
"an error")); "an error"));
goto failure; goto cleanup;
} }
result = 0;
cleanup: cleanup:
xmlFreeURI(xmlUri); xmlFreeURI(xmlUri);
esxVI_ObjectContent_Free(&virtualMachine); esxVI_ObjectContent_Free(&virtualMachine);
...@@ -3184,11 +3106,6 @@ esxDomainMigratePerform(virDomainPtr domain, ...@@ -3184,11 +3106,6 @@ esxDomainMigratePerform(virDomainPtr domain,
esxVI_ManagedObjectReference_Free(&task); esxVI_ManagedObjectReference_Free(&task);
return result; return result;
failure:
result = -1;
goto cleanup;
} }
...@@ -3218,19 +3135,19 @@ esxNodeGetFreeMemory(virConnectPtr conn) ...@@ -3218,19 +3135,19 @@ esxNodeGetFreeMemory(virConnectPtr conn)
esxVI_ResourcePoolResourceUsage *resourcePoolResourceUsage = NULL; esxVI_ResourcePoolResourceUsage *resourcePoolResourceUsage = NULL;
if (esxVI_EnsureSession(priv->host) < 0) { if (esxVI_EnsureSession(priv->host) < 0) {
goto failure; return 0;
} }
/* Lookup host system with its resource pool */ /* Lookup host system with its resource pool */
if (esxVI_String_AppendValueToList(&propertyNameList, "parent") < 0 || if (esxVI_String_AppendValueToList(&propertyNameList, "parent") < 0 ||
esxVI_LookupHostSystemByIp(priv->host, priv->host->ipAddress, esxVI_LookupHostSystemByIp(priv->host, priv->host->ipAddress,
propertyNameList, &hostSystem) < 0) { propertyNameList, &hostSystem) < 0) {
goto failure; goto cleanup;
} }
if (esxVI_LookupResourcePoolByHostSystem(priv->host, hostSystem, if (esxVI_LookupResourcePoolByHostSystem(priv->host, hostSystem,
&managedObjectReference) < 0) { &managedObjectReference) < 0) {
goto failure; goto cleanup;
} }
esxVI_String_Free(&propertyNameList); esxVI_String_Free(&propertyNameList);
...@@ -3242,7 +3159,7 @@ esxNodeGetFreeMemory(virConnectPtr conn) ...@@ -3242,7 +3159,7 @@ esxNodeGetFreeMemory(virConnectPtr conn)
"ResourcePool", propertyNameList, "ResourcePool", propertyNameList,
esxVI_Boolean_False, esxVI_Boolean_False,
&resourcePool) < 0) { &resourcePool) < 0) {
goto failure; goto cleanup;
} }
for (dynamicProperty = resourcePool->propSet; dynamicProperty != NULL; for (dynamicProperty = resourcePool->propSet; dynamicProperty != NULL;
...@@ -3250,7 +3167,7 @@ esxNodeGetFreeMemory(virConnectPtr conn) ...@@ -3250,7 +3167,7 @@ esxNodeGetFreeMemory(virConnectPtr conn)
if (STREQ(dynamicProperty->name, "runtime.memory")) { if (STREQ(dynamicProperty->name, "runtime.memory")) {
if (esxVI_ResourcePoolResourceUsage_CastFromAnyType if (esxVI_ResourcePoolResourceUsage_CastFromAnyType
(dynamicProperty->val, &resourcePoolResourceUsage) < 0) { (dynamicProperty->val, &resourcePoolResourceUsage) < 0) {
goto failure; goto cleanup;
} }
break; break;
...@@ -3262,7 +3179,7 @@ esxNodeGetFreeMemory(virConnectPtr conn) ...@@ -3262,7 +3179,7 @@ esxNodeGetFreeMemory(virConnectPtr conn)
if (resourcePoolResourceUsage == NULL) { if (resourcePoolResourceUsage == NULL) {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
_("Could not retrieve memory usage of resource pool")); _("Could not retrieve memory usage of resource pool"));
goto failure; goto cleanup;
} }
result = resourcePoolResourceUsage->unreservedForVm->value; result = resourcePoolResourceUsage->unreservedForVm->value;
...@@ -3275,11 +3192,6 @@ esxNodeGetFreeMemory(virConnectPtr conn) ...@@ -3275,11 +3192,6 @@ esxNodeGetFreeMemory(virConnectPtr conn)
esxVI_ResourcePoolResourceUsage_Free(&resourcePoolResourceUsage); esxVI_ResourcePoolResourceUsage_Free(&resourcePoolResourceUsage);
return result; return result;
failure:
result = 0;
goto cleanup;
} }
...@@ -3315,14 +3227,14 @@ esxIsSecure(virConnectPtr conn) ...@@ -3315,14 +3227,14 @@ esxIsSecure(virConnectPtr conn)
static int static int
esxDomainIsActive(virDomainPtr domain) esxDomainIsActive(virDomainPtr domain)
{ {
int result = 0; int result = -1;
esxPrivate *priv = domain->conn->privateData; esxPrivate *priv = domain->conn->privateData;
esxVI_ObjectContent *virtualMachine = NULL; esxVI_ObjectContent *virtualMachine = NULL;
esxVI_String *propertyNameList = NULL; esxVI_String *propertyNameList = NULL;
esxVI_VirtualMachinePowerState powerState; esxVI_VirtualMachinePowerState powerState;
if (esxVI_EnsureSession(priv->host) < 0) { if (esxVI_EnsureSession(priv->host) < 0) {
goto failure; return -1;
} }
if (esxVI_String_AppendValueToList(&propertyNameList, if (esxVI_String_AppendValueToList(&propertyNameList,
...@@ -3331,7 +3243,7 @@ esxDomainIsActive(virDomainPtr domain) ...@@ -3331,7 +3243,7 @@ esxDomainIsActive(virDomainPtr domain)
propertyNameList, &virtualMachine, propertyNameList, &virtualMachine,
esxVI_Occurrence_RequiredItem) < 0 || esxVI_Occurrence_RequiredItem) < 0 ||
esxVI_GetVirtualMachinePowerState(virtualMachine, &powerState) < 0) { esxVI_GetVirtualMachinePowerState(virtualMachine, &powerState) < 0) {
goto failure; goto cleanup;
} }
if (powerState != esxVI_VirtualMachinePowerState_PoweredOff) { if (powerState != esxVI_VirtualMachinePowerState_PoweredOff) {
...@@ -3345,11 +3257,6 @@ esxDomainIsActive(virDomainPtr domain) ...@@ -3345,11 +3257,6 @@ esxDomainIsActive(virDomainPtr domain)
esxVI_String_Free(&propertyNameList); esxVI_String_Free(&propertyNameList);
return result; return result;
failure:
result = -1;
goto cleanup;
} }
...@@ -3380,13 +3287,13 @@ esxDomainSnapshotCreateXML(virDomainPtr domain, const char *xmlDesc, ...@@ -3380,13 +3287,13 @@ esxDomainSnapshotCreateXML(virDomainPtr domain, const char *xmlDesc,
virCheckFlags(0, NULL); virCheckFlags(0, NULL);
if (esxVI_EnsureSession(priv->host) < 0) { if (esxVI_EnsureSession(priv->host) < 0) {
goto failure; return NULL;
} }
def = virDomainSnapshotDefParseString(xmlDesc, 1); def = virDomainSnapshotDefParseString(xmlDesc, 1);
if (def == NULL) { if (def == NULL) {
goto failure; return NULL;
} }
if (esxVI_LookupVirtualMachineByUuidAndPrepareForTask if (esxVI_LookupVirtualMachineByUuidAndPrepareForTask
...@@ -3397,13 +3304,13 @@ esxDomainSnapshotCreateXML(virDomainPtr domain, const char *xmlDesc, ...@@ -3397,13 +3304,13 @@ esxDomainSnapshotCreateXML(virDomainPtr domain, const char *xmlDesc,
esxVI_GetSnapshotTreeByName(rootSnapshotList, def->name, esxVI_GetSnapshotTreeByName(rootSnapshotList, def->name,
&snapshotTree, &snapshotTreeParent, &snapshotTree, &snapshotTreeParent,
esxVI_Occurrence_OptionalItem) < 0) { esxVI_Occurrence_OptionalItem) < 0) {
goto failure; goto cleanup;
} }
if (snapshotTree != NULL) { if (snapshotTree != NULL) {
ESX_ERROR(VIR_ERR_OPERATION_INVALID, ESX_ERROR(VIR_ERR_OPERATION_INVALID,
_("Snapshot '%s' already exists"), def->name); _("Snapshot '%s' already exists"), def->name);
goto failure; goto cleanup;
} }
if (esxVI_CreateSnapshot_Task(priv->host, virtualMachine->obj, if (esxVI_CreateSnapshot_Task(priv->host, virtualMachine->obj,
...@@ -3412,12 +3319,12 @@ esxDomainSnapshotCreateXML(virDomainPtr domain, const char *xmlDesc, ...@@ -3412,12 +3319,12 @@ esxDomainSnapshotCreateXML(virDomainPtr domain, const char *xmlDesc,
esxVI_Boolean_False, &task) < 0 || esxVI_Boolean_False, &task) < 0 ||
esxVI_WaitForTaskCompletion(priv->host, task, domain->uuid, esxVI_WaitForTaskCompletion(priv->host, task, domain->uuid,
priv->autoAnswer, &taskInfoState) < 0) { priv->autoAnswer, &taskInfoState) < 0) {
goto failure; goto cleanup;
} }
if (taskInfoState != esxVI_TaskInfoState_Success) { if (taskInfoState != esxVI_TaskInfoState_Success) {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not create snapshot")); ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not create snapshot"));
goto failure; goto cleanup;
} }
snapshot = virGetDomainSnapshot(domain, def->name); snapshot = virGetDomainSnapshot(domain, def->name);
...@@ -3429,11 +3336,6 @@ esxDomainSnapshotCreateXML(virDomainPtr domain, const char *xmlDesc, ...@@ -3429,11 +3336,6 @@ esxDomainSnapshotCreateXML(virDomainPtr domain, const char *xmlDesc,
esxVI_ManagedObjectReference_Free(&task); esxVI_ManagedObjectReference_Free(&task);
return snapshot; return snapshot;
failure:
domain = NULL;
goto cleanup;
} }
...@@ -3452,10 +3354,10 @@ esxDomainSnapshotDumpXML(virDomainSnapshotPtr snapshot, ...@@ -3452,10 +3354,10 @@ esxDomainSnapshotDumpXML(virDomainSnapshotPtr snapshot,
virCheckFlags(0, NULL); virCheckFlags(0, NULL);
memset(&def, 0, sizeof (virDomainSnapshotDef)); memset(&def, 0, sizeof (def));
if (esxVI_EnsureSession(priv->host) < 0) { if (esxVI_EnsureSession(priv->host) < 0) {
goto failure; return NULL;
} }
if (esxVI_LookupRootSnapshotTreeList(priv->host, snapshot->domain->uuid, if (esxVI_LookupRootSnapshotTreeList(priv->host, snapshot->domain->uuid,
...@@ -3463,7 +3365,7 @@ esxDomainSnapshotDumpXML(virDomainSnapshotPtr snapshot, ...@@ -3463,7 +3365,7 @@ esxDomainSnapshotDumpXML(virDomainSnapshotPtr snapshot,
esxVI_GetSnapshotTreeByName(rootSnapshotList, snapshot->name, esxVI_GetSnapshotTreeByName(rootSnapshotList, snapshot->name,
&snapshotTree, &snapshotTreeParent, &snapshotTree, &snapshotTreeParent,
esxVI_Occurrence_RequiredItem) < 0) { esxVI_Occurrence_RequiredItem) < 0) {
goto failure; goto cleanup;
} }
def.name = snapshot->name; def.name = snapshot->name;
...@@ -3472,7 +3374,7 @@ esxDomainSnapshotDumpXML(virDomainSnapshotPtr snapshot, ...@@ -3472,7 +3374,7 @@ esxDomainSnapshotDumpXML(virDomainSnapshotPtr snapshot,
if (esxVI_DateTime_ConvertToCalendarTime(snapshotTree->createTime, if (esxVI_DateTime_ConvertToCalendarTime(snapshotTree->createTime,
&def.creationTime) < 0) { &def.creationTime) < 0) {
goto failure; goto cleanup;
} }
def.state = esxVI_VirtualMachinePowerState_ConvertToLibvirt def.state = esxVI_VirtualMachinePowerState_ConvertToLibvirt
...@@ -3486,11 +3388,6 @@ esxDomainSnapshotDumpXML(virDomainSnapshotPtr snapshot, ...@@ -3486,11 +3388,6 @@ esxDomainSnapshotDumpXML(virDomainSnapshotPtr snapshot,
esxVI_VirtualMachineSnapshotTree_Free(&rootSnapshotList); esxVI_VirtualMachineSnapshotTree_Free(&rootSnapshotList);
return xml; return xml;
failure:
VIR_FREE(xml);
goto cleanup;
} }
...@@ -3498,32 +3395,26 @@ esxDomainSnapshotDumpXML(virDomainSnapshotPtr snapshot, ...@@ -3498,32 +3395,26 @@ esxDomainSnapshotDumpXML(virDomainSnapshotPtr snapshot,
static int static int
esxDomainSnapshotNum(virDomainPtr domain, unsigned int flags) esxDomainSnapshotNum(virDomainPtr domain, unsigned int flags)
{ {
int result = 0; int count;
esxPrivate *priv = domain->conn->privateData; esxPrivate *priv = domain->conn->privateData;
esxVI_VirtualMachineSnapshotTree *rootSnapshotTreeList = NULL; esxVI_VirtualMachineSnapshotTree *rootSnapshotTreeList = NULL;
virCheckFlags(0, -1); virCheckFlags(0, -1);
if (esxVI_EnsureSession(priv->host) < 0) { if (esxVI_EnsureSession(priv->host) < 0) {
goto failure; return -1;
} }
if (esxVI_LookupRootSnapshotTreeList(priv->host, domain->uuid, if (esxVI_LookupRootSnapshotTreeList(priv->host, domain->uuid,
&rootSnapshotTreeList) < 0) { &rootSnapshotTreeList) < 0) {
goto failure; return -1;
} }
result = esxVI_GetNumberOfSnapshotTrees(rootSnapshotTreeList); count = esxVI_GetNumberOfSnapshotTrees(rootSnapshotTreeList);
cleanup:
esxVI_VirtualMachineSnapshotTree_Free(&rootSnapshotTreeList); esxVI_VirtualMachineSnapshotTree_Free(&rootSnapshotTreeList);
return result; return count;
failure:
result = -1;
goto cleanup;
} }
...@@ -3532,7 +3423,7 @@ static int ...@@ -3532,7 +3423,7 @@ static int
esxDomainSnapshotListNames(virDomainPtr domain, char **names, int nameslen, esxDomainSnapshotListNames(virDomainPtr domain, char **names, int nameslen,
unsigned int flags) unsigned int flags)
{ {
int result = 0; int result;
esxPrivate *priv = domain->conn->privateData; esxPrivate *priv = domain->conn->privateData;
esxVI_VirtualMachineSnapshotTree *rootSnapshotTreeList = NULL; esxVI_VirtualMachineSnapshotTree *rootSnapshotTreeList = NULL;
...@@ -3548,25 +3439,19 @@ esxDomainSnapshotListNames(virDomainPtr domain, char **names, int nameslen, ...@@ -3548,25 +3439,19 @@ esxDomainSnapshotListNames(virDomainPtr domain, char **names, int nameslen,
} }
if (esxVI_EnsureSession(priv->host) < 0) { if (esxVI_EnsureSession(priv->host) < 0) {
goto failure; return -1;
} }
if (esxVI_LookupRootSnapshotTreeList(priv->host, domain->uuid, if (esxVI_LookupRootSnapshotTreeList(priv->host, domain->uuid,
&rootSnapshotTreeList) < 0) { &rootSnapshotTreeList) < 0) {
goto failure; return -1;
} }
result = esxVI_GetSnapshotTreeNames(rootSnapshotTreeList, names, nameslen); result = esxVI_GetSnapshotTreeNames(rootSnapshotTreeList, names, nameslen);
cleanup:
esxVI_VirtualMachineSnapshotTree_Free(&rootSnapshotTreeList); esxVI_VirtualMachineSnapshotTree_Free(&rootSnapshotTreeList);
return result; return result;
failure:
result = -1;
goto cleanup;
} }
...@@ -3584,7 +3469,7 @@ esxDomainSnapshotLookupByName(virDomainPtr domain, const char *name, ...@@ -3584,7 +3469,7 @@ esxDomainSnapshotLookupByName(virDomainPtr domain, const char *name,
virCheckFlags(0, NULL); virCheckFlags(0, NULL);
if (esxVI_EnsureSession(priv->host) < 0) { if (esxVI_EnsureSession(priv->host) < 0) {
goto cleanup; return NULL;
} }
if (esxVI_LookupRootSnapshotTreeList(priv->host, domain->uuid, if (esxVI_LookupRootSnapshotTreeList(priv->host, domain->uuid,
...@@ -3608,35 +3493,27 @@ esxDomainSnapshotLookupByName(virDomainPtr domain, const char *name, ...@@ -3608,35 +3493,27 @@ esxDomainSnapshotLookupByName(virDomainPtr domain, const char *name,
static int static int
esxDomainHasCurrentSnapshot(virDomainPtr domain, unsigned int flags) esxDomainHasCurrentSnapshot(virDomainPtr domain, unsigned int flags)
{ {
int result = 0;
esxPrivate *priv = domain->conn->privateData; esxPrivate *priv = domain->conn->privateData;
esxVI_VirtualMachineSnapshotTree *currentSnapshotTree = NULL; esxVI_VirtualMachineSnapshotTree *currentSnapshotTree = NULL;
virCheckFlags(0, -1); virCheckFlags(0, -1);
if (esxVI_EnsureSession(priv->host) < 0) { if (esxVI_EnsureSession(priv->host) < 0) {
goto failure; return -1;
} }
if (esxVI_LookupCurrentSnapshotTree(priv->host, domain->uuid, if (esxVI_LookupCurrentSnapshotTree(priv->host, domain->uuid,
&currentSnapshotTree, &currentSnapshotTree,
esxVI_Occurrence_OptionalItem) < 0) { esxVI_Occurrence_OptionalItem) < 0) {
goto failure; return -1;
} }
if (currentSnapshotTree != NULL) { if (currentSnapshotTree != NULL) {
result = 1; esxVI_VirtualMachineSnapshotTree_Free(&currentSnapshotTree);
return 1;
} }
cleanup: return 0;
esxVI_VirtualMachineSnapshotTree_Free(&currentSnapshotTree);
return result;
failure:
result = -1;
goto cleanup;
} }
...@@ -3644,25 +3521,24 @@ esxDomainHasCurrentSnapshot(virDomainPtr domain, unsigned int flags) ...@@ -3644,25 +3521,24 @@ esxDomainHasCurrentSnapshot(virDomainPtr domain, unsigned int flags)
static virDomainSnapshotPtr static virDomainSnapshotPtr
esxDomainSnapshotCurrent(virDomainPtr domain, unsigned int flags) esxDomainSnapshotCurrent(virDomainPtr domain, unsigned int flags)
{ {
virDomainSnapshotPtr snapshot = NULL;
esxPrivate *priv = domain->conn->privateData; esxPrivate *priv = domain->conn->privateData;
esxVI_VirtualMachineSnapshotTree *currentSnapshotTree = NULL; esxVI_VirtualMachineSnapshotTree *currentSnapshotTree = NULL;
virDomainSnapshotPtr snapshot = NULL;
virCheckFlags(0, NULL); virCheckFlags(0, NULL);
if (esxVI_EnsureSession(priv->host) < 0) { if (esxVI_EnsureSession(priv->host) < 0) {
goto cleanup; return NULL;
} }
if (esxVI_LookupCurrentSnapshotTree(priv->host, domain->uuid, if (esxVI_LookupCurrentSnapshotTree(priv->host, domain->uuid,
&currentSnapshotTree, &currentSnapshotTree,
esxVI_Occurrence_RequiredItem) < 0) { esxVI_Occurrence_RequiredItem) < 0) {
goto cleanup; return NULL;
} }
snapshot = virGetDomainSnapshot(domain, currentSnapshotTree->name); snapshot = virGetDomainSnapshot(domain, currentSnapshotTree->name);
cleanup:
esxVI_VirtualMachineSnapshotTree_Free(&currentSnapshotTree); esxVI_VirtualMachineSnapshotTree_Free(&currentSnapshotTree);
return snapshot; return snapshot;
...@@ -3673,7 +3549,7 @@ esxDomainSnapshotCurrent(virDomainPtr domain, unsigned int flags) ...@@ -3673,7 +3549,7 @@ esxDomainSnapshotCurrent(virDomainPtr domain, unsigned int flags)
static int static int
esxDomainRevertToSnapshot(virDomainSnapshotPtr snapshot, unsigned int flags) esxDomainRevertToSnapshot(virDomainSnapshotPtr snapshot, unsigned int flags)
{ {
int result = 0; int result = -1;
esxPrivate *priv = snapshot->domain->conn->privateData; esxPrivate *priv = snapshot->domain->conn->privateData;
esxVI_VirtualMachineSnapshotTree *rootSnapshotList = NULL; esxVI_VirtualMachineSnapshotTree *rootSnapshotList = NULL;
esxVI_VirtualMachineSnapshotTree *snapshotTree = NULL; esxVI_VirtualMachineSnapshotTree *snapshotTree = NULL;
...@@ -3684,7 +3560,7 @@ esxDomainRevertToSnapshot(virDomainSnapshotPtr snapshot, unsigned int flags) ...@@ -3684,7 +3560,7 @@ esxDomainRevertToSnapshot(virDomainSnapshotPtr snapshot, unsigned int flags)
virCheckFlags(0, -1); virCheckFlags(0, -1);
if (esxVI_EnsureSession(priv->host) < 0) { if (esxVI_EnsureSession(priv->host) < 0) {
goto failure; return -1;
} }
if (esxVI_LookupRootSnapshotTreeList(priv->host, snapshot->domain->uuid, if (esxVI_LookupRootSnapshotTreeList(priv->host, snapshot->domain->uuid,
...@@ -3692,32 +3568,29 @@ esxDomainRevertToSnapshot(virDomainSnapshotPtr snapshot, unsigned int flags) ...@@ -3692,32 +3568,29 @@ esxDomainRevertToSnapshot(virDomainSnapshotPtr snapshot, unsigned int flags)
esxVI_GetSnapshotTreeByName(rootSnapshotList, snapshot->name, esxVI_GetSnapshotTreeByName(rootSnapshotList, snapshot->name,
&snapshotTree, &snapshotTreeParent, &snapshotTree, &snapshotTreeParent,
esxVI_Occurrence_RequiredItem) < 0) { esxVI_Occurrence_RequiredItem) < 0) {
goto failure; goto cleanup;
} }
if (esxVI_RevertToSnapshot_Task(priv->host, snapshotTree->snapshot, NULL, if (esxVI_RevertToSnapshot_Task(priv->host, snapshotTree->snapshot, NULL,
&task) < 0 || &task) < 0 ||
esxVI_WaitForTaskCompletion(priv->host, task, snapshot->domain->uuid, esxVI_WaitForTaskCompletion(priv->host, task, snapshot->domain->uuid,
priv->autoAnswer, &taskInfoState) < 0) { priv->autoAnswer, &taskInfoState) < 0) {
goto failure; goto cleanup;
} }
if (taskInfoState != esxVI_TaskInfoState_Success) { if (taskInfoState != esxVI_TaskInfoState_Success) {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Could not revert to snapshot '%s'"), snapshot->name); _("Could not revert to snapshot '%s'"), snapshot->name);
goto failure; goto cleanup;
} }
result = 0;
cleanup: cleanup:
esxVI_VirtualMachineSnapshotTree_Free(&rootSnapshotList); esxVI_VirtualMachineSnapshotTree_Free(&rootSnapshotList);
esxVI_ManagedObjectReference_Free(&task); esxVI_ManagedObjectReference_Free(&task);
return result; return result;
failure:
result = -1;
goto cleanup;
} }
...@@ -3725,7 +3598,7 @@ esxDomainRevertToSnapshot(virDomainSnapshotPtr snapshot, unsigned int flags) ...@@ -3725,7 +3598,7 @@ esxDomainRevertToSnapshot(virDomainSnapshotPtr snapshot, unsigned int flags)
static int static int
esxDomainSnapshotDelete(virDomainSnapshotPtr snapshot, unsigned int flags) esxDomainSnapshotDelete(virDomainSnapshotPtr snapshot, unsigned int flags)
{ {
int result = 0; int result = -1;
esxPrivate *priv = snapshot->domain->conn->privateData; esxPrivate *priv = snapshot->domain->conn->privateData;
esxVI_VirtualMachineSnapshotTree *rootSnapshotList = NULL; esxVI_VirtualMachineSnapshotTree *rootSnapshotList = NULL;
esxVI_VirtualMachineSnapshotTree *snapshotTree = NULL; esxVI_VirtualMachineSnapshotTree *snapshotTree = NULL;
...@@ -3737,7 +3610,7 @@ esxDomainSnapshotDelete(virDomainSnapshotPtr snapshot, unsigned int flags) ...@@ -3737,7 +3610,7 @@ esxDomainSnapshotDelete(virDomainSnapshotPtr snapshot, unsigned int flags)
virCheckFlags(VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN, -1); virCheckFlags(VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN, -1);
if (esxVI_EnsureSession(priv->host) < 0) { if (esxVI_EnsureSession(priv->host) < 0) {
goto failure; return -1;
} }
if (flags & VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN) { if (flags & VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN) {
...@@ -3749,32 +3622,29 @@ esxDomainSnapshotDelete(virDomainSnapshotPtr snapshot, unsigned int flags) ...@@ -3749,32 +3622,29 @@ esxDomainSnapshotDelete(virDomainSnapshotPtr snapshot, unsigned int flags)
esxVI_GetSnapshotTreeByName(rootSnapshotList, snapshot->name, esxVI_GetSnapshotTreeByName(rootSnapshotList, snapshot->name,
&snapshotTree, &snapshotTreeParent, &snapshotTree, &snapshotTreeParent,
esxVI_Occurrence_RequiredItem) < 0) { esxVI_Occurrence_RequiredItem) < 0) {
goto failure; goto cleanup;
} }
if (esxVI_RemoveSnapshot_Task(priv->host, snapshotTree->snapshot, if (esxVI_RemoveSnapshot_Task(priv->host, snapshotTree->snapshot,
removeChildren, &task) < 0 || removeChildren, &task) < 0 ||
esxVI_WaitForTaskCompletion(priv->host, task, snapshot->domain->uuid, esxVI_WaitForTaskCompletion(priv->host, task, snapshot->domain->uuid,
priv->autoAnswer, &taskInfoState) < 0) { priv->autoAnswer, &taskInfoState) < 0) {
goto failure; goto cleanup;
} }
if (taskInfoState != esxVI_TaskInfoState_Success) { if (taskInfoState != esxVI_TaskInfoState_Success) {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Could not delete snapshot '%s'"), snapshot->name); _("Could not delete snapshot '%s'"), snapshot->name);
goto failure; goto cleanup;
} }
result = 0;
cleanup: cleanup:
esxVI_VirtualMachineSnapshotTree_Free(&rootSnapshotList); esxVI_VirtualMachineSnapshotTree_Free(&rootSnapshotList);
esxVI_ManagedObjectReference_Free(&task); esxVI_ManagedObjectReference_Free(&task);
return result; return result;
failure:
result = -1;
goto cleanup;
} }
......
...@@ -467,10 +467,6 @@ esxStoragePoolGetInfo(virStoragePoolPtr pool, virStoragePoolInfoPtr info) ...@@ -467,10 +467,6 @@ esxStoragePoolGetInfo(virStoragePoolPtr pool, virStoragePoolInfoPtr info)
result = 0; result = 0;
cleanup: cleanup:
if (result < 0) {
memset(info, 0, sizeof (*info));
}
esxVI_String_Free(&propertyNameList); esxVI_String_Free(&propertyNameList);
esxVI_ObjectContent_Free(&datastore); esxVI_ObjectContent_Free(&datastore);
......
...@@ -43,7 +43,7 @@ int ...@@ -43,7 +43,7 @@ int
esxUtil_ParseQuery(xmlURIPtr uri, char **transport, char **vCenter, esxUtil_ParseQuery(xmlURIPtr uri, char **transport, char **vCenter,
int *noVerify, int *autoAnswer) int *noVerify, int *autoAnswer)
{ {
int result = 0; int result = -1;
int i; int i;
struct qparam_set *queryParamSet = NULL; struct qparam_set *queryParamSet = NULL;
struct qparam *queryParam = NULL; struct qparam *queryParam = NULL;
...@@ -71,7 +71,7 @@ esxUtil_ParseQuery(xmlURIPtr uri, char **transport, char **vCenter, ...@@ -71,7 +71,7 @@ esxUtil_ParseQuery(xmlURIPtr uri, char **transport, char **vCenter,
#endif #endif
if (queryParamSet == NULL) { if (queryParamSet == NULL) {
goto failure; return -1;
} }
for (i = 0; i < queryParamSet->n; i++) { for (i = 0; i < queryParamSet->n; i++) {
...@@ -86,14 +86,14 @@ esxUtil_ParseQuery(xmlURIPtr uri, char **transport, char **vCenter, ...@@ -86,14 +86,14 @@ esxUtil_ParseQuery(xmlURIPtr uri, char **transport, char **vCenter,
if (*transport == NULL) { if (*transport == NULL) {
virReportOOMError(); virReportOOMError();
goto failure; goto cleanup;
} }
if (STRNEQ(*transport, "http") && STRNEQ(*transport, "https")) { if (STRNEQ(*transport, "http") && STRNEQ(*transport, "https")) {
ESX_ERROR(VIR_ERR_INVALID_ARG, ESX_ERROR(VIR_ERR_INVALID_ARG,
_("Query parameter 'transport' has unexpected value " _("Query parameter 'transport' has unexpected value "
"'%s' (should be http|https)"), *transport); "'%s' (should be http|https)"), *transport);
goto failure; goto cleanup;
} }
} else if (STRCASEEQ(queryParam->name, "vcenter")) { } else if (STRCASEEQ(queryParam->name, "vcenter")) {
if (vCenter == NULL) { if (vCenter == NULL) {
...@@ -104,7 +104,7 @@ esxUtil_ParseQuery(xmlURIPtr uri, char **transport, char **vCenter, ...@@ -104,7 +104,7 @@ esxUtil_ParseQuery(xmlURIPtr uri, char **transport, char **vCenter,
if (*vCenter == NULL) { if (*vCenter == NULL) {
virReportOOMError(); virReportOOMError();
goto failure; goto cleanup;
} }
} else if (STRCASEEQ(queryParam->name, "no_verify")) { } else if (STRCASEEQ(queryParam->name, "no_verify")) {
if (noVerify == NULL) { if (noVerify == NULL) {
...@@ -116,7 +116,7 @@ esxUtil_ParseQuery(xmlURIPtr uri, char **transport, char **vCenter, ...@@ -116,7 +116,7 @@ esxUtil_ParseQuery(xmlURIPtr uri, char **transport, char **vCenter,
ESX_ERROR(VIR_ERR_INVALID_ARG, ESX_ERROR(VIR_ERR_INVALID_ARG,
_("Query parameter 'no_verify' has unexpected value " _("Query parameter 'no_verify' has unexpected value "
"'%s' (should be 0 or 1)"), queryParam->value); "'%s' (should be 0 or 1)"), queryParam->value);
goto failure; goto cleanup;
} }
} else if (STRCASEEQ(queryParam->name, "auto_answer")) { } else if (STRCASEEQ(queryParam->name, "auto_answer")) {
if (autoAnswer == NULL) { if (autoAnswer == NULL) {
...@@ -128,7 +128,7 @@ esxUtil_ParseQuery(xmlURIPtr uri, char **transport, char **vCenter, ...@@ -128,7 +128,7 @@ esxUtil_ParseQuery(xmlURIPtr uri, char **transport, char **vCenter,
ESX_ERROR(VIR_ERR_INVALID_ARG, ESX_ERROR(VIR_ERR_INVALID_ARG,
_("Query parameter 'auto_answer' has unexpected " _("Query parameter 'auto_answer' has unexpected "
"value '%s' (should be 0 or 1)"), queryParam->value); "value '%s' (should be 0 or 1)"), queryParam->value);
goto failure; goto cleanup;
} }
} else { } else {
VIR_WARN("Ignoring unexpected query parameter '%s'", VIR_WARN("Ignoring unexpected query parameter '%s'",
...@@ -141,29 +141,28 @@ esxUtil_ParseQuery(xmlURIPtr uri, char **transport, char **vCenter, ...@@ -141,29 +141,28 @@ esxUtil_ParseQuery(xmlURIPtr uri, char **transport, char **vCenter,
if (*transport == NULL) { if (*transport == NULL) {
virReportOOMError(); virReportOOMError();
goto failure; goto cleanup;
} }
} }
cleanup: result = 0;
if (queryParamSet != NULL) {
free_qparam_set(queryParamSet);
}
return result; cleanup:
if (result < 0) {
if (transport != NULL) {
VIR_FREE(*transport);
}
failure: if (vCenter != NULL) {
if (transport != NULL) { VIR_FREE(*vCenter);
VIR_FREE(*transport); }
} }
if (vCenter != NULL) { if (queryParamSet != NULL) {
VIR_FREE(*vCenter); free_qparam_set(queryParamSet);
} }
result = -1; return result;
goto cleanup;
} }
...@@ -196,7 +195,7 @@ esxUtil_ParseDatastoreRelatedPath(const char *datastoreRelatedPath, ...@@ -196,7 +195,7 @@ esxUtil_ParseDatastoreRelatedPath(const char *datastoreRelatedPath,
char **datastoreName, char **datastoreName,
char **directoryName, char **fileName) char **directoryName, char **fileName)
{ {
int result = 0; int result = -1;
char *copyOfDatastoreRelatedPath = NULL; char *copyOfDatastoreRelatedPath = NULL;
char *tmp = NULL; char *tmp = NULL;
char *saveptr = NULL; char *saveptr = NULL;
...@@ -213,7 +212,7 @@ esxUtil_ParseDatastoreRelatedPath(const char *datastoreRelatedPath, ...@@ -213,7 +212,7 @@ esxUtil_ParseDatastoreRelatedPath(const char *datastoreRelatedPath,
if (esxVI_String_DeepCopyValue(&copyOfDatastoreRelatedPath, if (esxVI_String_DeepCopyValue(&copyOfDatastoreRelatedPath,
datastoreRelatedPath) < 0) { datastoreRelatedPath) < 0) {
goto failure; goto cleanup;
} }
/* Expected format: '[<datastore>] <path>' */ /* Expected format: '[<datastore>] <path>' */
...@@ -223,12 +222,12 @@ esxUtil_ParseDatastoreRelatedPath(const char *datastoreRelatedPath, ...@@ -223,12 +222,12 @@ esxUtil_ParseDatastoreRelatedPath(const char *datastoreRelatedPath,
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Datastore related path '%s' doesn't have expected format " _("Datastore related path '%s' doesn't have expected format "
"'[<datastore>] <path>'"), datastoreRelatedPath); "'[<datastore>] <path>'"), datastoreRelatedPath);
goto failure; goto cleanup;
} }
if (esxVI_String_DeepCopyValue(datastoreName, if (esxVI_String_DeepCopyValue(datastoreName,
preliminaryDatastoreName) < 0) { preliminaryDatastoreName) < 0) {
goto failure; goto cleanup;
} }
directoryAndFileName += strspn(directoryAndFileName, " "); directoryAndFileName += strspn(directoryAndFileName, " ");
...@@ -243,33 +242,32 @@ esxUtil_ParseDatastoreRelatedPath(const char *datastoreRelatedPath, ...@@ -243,33 +242,32 @@ esxUtil_ParseDatastoreRelatedPath(const char *datastoreRelatedPath,
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Datastore related path '%s' doesn't reference a file"), _("Datastore related path '%s' doesn't reference a file"),
datastoreRelatedPath); datastoreRelatedPath);
goto failure; goto cleanup;
} }
if (esxVI_String_DeepCopyValue(directoryName, if (esxVI_String_DeepCopyValue(directoryName,
directoryAndFileName) < 0 || directoryAndFileName) < 0 ||
esxVI_String_DeepCopyValue(fileName, separator) < 0) { esxVI_String_DeepCopyValue(fileName, separator) < 0) {
goto failure; goto cleanup;
} }
} else { } else {
if (esxVI_String_DeepCopyValue(fileName, directoryAndFileName) < 0) { if (esxVI_String_DeepCopyValue(fileName, directoryAndFileName) < 0) {
goto failure; goto cleanup;
} }
} }
result = 0;
cleanup: cleanup:
if (result < 0) {
VIR_FREE(*datastoreName);
VIR_FREE(*directoryName);
VIR_FREE(*fileName);
}
VIR_FREE(copyOfDatastoreRelatedPath); VIR_FREE(copyOfDatastoreRelatedPath);
return result; return result;
failure:
VIR_FREE(*datastoreName);
VIR_FREE(*directoryName);
VIR_FREE(*fileName);
result = -1;
goto cleanup;
} }
...@@ -282,7 +280,7 @@ esxUtil_ResolveHostname(const char *hostname, ...@@ -282,7 +280,7 @@ esxUtil_ResolveHostname(const char *hostname,
struct addrinfo *result = NULL; struct addrinfo *result = NULL;
int errcode; int errcode;
memset(&hints, 0, sizeof(struct addrinfo)); memset(&hints, 0, sizeof (hints));
hints.ai_flags = AI_ADDRCONFIG; hints.ai_flags = AI_ADDRCONFIG;
hints.ai_family = AF_INET; hints.ai_family = AF_INET;
......
...@@ -279,7 +279,7 @@ esxVI_Context_Connect(esxVI_Context *ctx, const char *url, ...@@ -279,7 +279,7 @@ esxVI_Context_Connect(esxVI_Context *ctx, const char *url,
const char *ipAddress, const char *username, const char *ipAddress, const char *username,
const char *password, int noVerify) const char *password, int noVerify)
{ {
int result = 0; int result = -1;
esxVI_String *propertyNameList = NULL; esxVI_String *propertyNameList = NULL;
esxVI_ObjectContent *datacenterList = NULL; esxVI_ObjectContent *datacenterList = NULL;
esxVI_DynamicProperty *dynamicProperty = NULL; esxVI_DynamicProperty *dynamicProperty = NULL;
...@@ -288,12 +288,12 @@ esxVI_Context_Connect(esxVI_Context *ctx, const char *url, ...@@ -288,12 +288,12 @@ esxVI_Context_Connect(esxVI_Context *ctx, const char *url,
password == NULL || ctx->url != NULL || ctx->service != NULL || password == NULL || ctx->url != NULL || ctx->service != NULL ||
ctx->curl_handle != NULL || ctx->curl_headers != NULL) { ctx->curl_handle != NULL || ctx->curl_headers != NULL) {
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument")); ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
goto failure; return -1;
} }
if (esxVI_String_DeepCopyValue(&ctx->url, url) < 0 || if (esxVI_String_DeepCopyValue(&ctx->url, url) < 0 ||
esxVI_String_DeepCopyValue(&ctx->ipAddress, ipAddress) < 0) { esxVI_String_DeepCopyValue(&ctx->ipAddress, ipAddress) < 0) {
goto failure; goto cleanup;
} }
ctx->curl_handle = curl_easy_init(); ctx->curl_handle = curl_easy_init();
...@@ -301,7 +301,7 @@ esxVI_Context_Connect(esxVI_Context *ctx, const char *url, ...@@ -301,7 +301,7 @@ esxVI_Context_Connect(esxVI_Context *ctx, const char *url,
if (ctx->curl_handle == NULL) { if (ctx->curl_handle == NULL) {
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
_("Could not initialize CURL")); _("Could not initialize CURL"));
goto failure; goto cleanup;
} }
ctx->curl_headers = curl_slist_append(ctx->curl_headers, "Content-Type: " ctx->curl_headers = curl_slist_append(ctx->curl_headers, "Content-Type: "
...@@ -321,7 +321,7 @@ esxVI_Context_Connect(esxVI_Context *ctx, const char *url, ...@@ -321,7 +321,7 @@ esxVI_Context_Connect(esxVI_Context *ctx, const char *url,
if (ctx->curl_headers == NULL) { if (ctx->curl_headers == NULL) {
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
_("Could not build CURL header list")); _("Could not build CURL header list"));
goto failure; goto cleanup;
} }
curl_easy_setopt(ctx->curl_handle, CURLOPT_URL, ctx->url); curl_easy_setopt(ctx->curl_handle, CURLOPT_URL, ctx->url);
...@@ -346,7 +346,7 @@ esxVI_Context_Connect(esxVI_Context *ctx, const char *url, ...@@ -346,7 +346,7 @@ esxVI_Context_Connect(esxVI_Context *ctx, const char *url,
if (virMutexInit(&ctx->curl_lock) < 0) { if (virMutexInit(&ctx->curl_lock) < 0) {
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
_("Could not initialize CURL mutex")); _("Could not initialize CURL mutex"));
goto failure; goto cleanup;
} }
ctx->username = strdup(username); ctx->username = strdup(username);
...@@ -354,11 +354,11 @@ esxVI_Context_Connect(esxVI_Context *ctx, const char *url, ...@@ -354,11 +354,11 @@ esxVI_Context_Connect(esxVI_Context *ctx, const char *url,
if (ctx->username == NULL || ctx->password == NULL) { if (ctx->username == NULL || ctx->password == NULL) {
virReportOOMError(); virReportOOMError();
goto failure; goto cleanup;
} }
if (esxVI_RetrieveServiceContent(ctx, &ctx->service) < 0) { if (esxVI_RetrieveServiceContent(ctx, &ctx->service) < 0) {
goto failure; goto cleanup;
} }
if (STREQ(ctx->service->about->apiType, "HostAgent") || if (STREQ(ctx->service->about->apiType, "HostAgent") ||
...@@ -371,7 +371,7 @@ esxVI_Context_Connect(esxVI_Context *ctx, const char *url, ...@@ -371,7 +371,7 @@ esxVI_Context_Connect(esxVI_Context *ctx, const char *url,
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Expecting VI API major/minor version '2.5' or '4.0' " _("Expecting VI API major/minor version '2.5' or '4.0' "
"but found '%s'"), ctx->service->about->apiVersion); "but found '%s'"), ctx->service->about->apiVersion);
goto failure; goto cleanup;
} }
if (STREQ(ctx->service->about->productLineId, "gsx")) { if (STREQ(ctx->service->about->productLineId, "gsx")) {
...@@ -381,7 +381,7 @@ esxVI_Context_Connect(esxVI_Context *ctx, const char *url, ...@@ -381,7 +381,7 @@ esxVI_Context_Connect(esxVI_Context *ctx, const char *url,
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Expecting GSX major/minor version '2.0' but " _("Expecting GSX major/minor version '2.0' but "
"found '%s'"), ctx->service->about->version); "found '%s'"), ctx->service->about->version);
goto failure; goto cleanup;
} }
} else if (STREQ(ctx->service->about->productLineId, "esx") || } else if (STREQ(ctx->service->about->productLineId, "esx") ||
STREQ(ctx->service->about->productLineId, "embeddedEsx")) { STREQ(ctx->service->about->productLineId, "embeddedEsx")) {
...@@ -394,7 +394,7 @@ esxVI_Context_Connect(esxVI_Context *ctx, const char *url, ...@@ -394,7 +394,7 @@ esxVI_Context_Connect(esxVI_Context *ctx, const char *url,
_("Expecting ESX major/minor version '3.5' or " _("Expecting ESX major/minor version '3.5' or "
"'4.0' but found '%s'"), "'4.0' but found '%s'"),
ctx->service->about->version); ctx->service->about->version);
goto failure; goto cleanup;
} }
} else if (STREQ(ctx->service->about->productLineId, "vpx")) { } else if (STREQ(ctx->service->about->productLineId, "vpx")) {
if (STRPREFIX(ctx->service->about->version, "2.5")) { if (STRPREFIX(ctx->service->about->version, "2.5")) {
...@@ -405,24 +405,24 @@ esxVI_Context_Connect(esxVI_Context *ctx, const char *url, ...@@ -405,24 +405,24 @@ esxVI_Context_Connect(esxVI_Context *ctx, const char *url,
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Expecting VPX major/minor version '2.5' or '4.0' " _("Expecting VPX major/minor version '2.5' or '4.0' "
"but found '%s'"), ctx->service->about->version); "but found '%s'"), ctx->service->about->version);
goto failure; goto cleanup;
} }
} else { } else {
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Expecting product 'gsx' or 'esx' or 'embeddedEsx' " _("Expecting product 'gsx' or 'esx' or 'embeddedEsx' "
"or 'vpx' but found '%s'"), "or 'vpx' but found '%s'"),
ctx->service->about->productLineId); ctx->service->about->productLineId);
goto failure; goto cleanup;
} }
} else { } else {
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Expecting VI API type 'HostAgent' or 'VirtualCenter' " _("Expecting VI API type 'HostAgent' or 'VirtualCenter' "
"but found '%s'"), ctx->service->about->apiType); "but found '%s'"), ctx->service->about->apiType);
goto failure; goto cleanup;
} }
if (esxVI_Login(ctx, username, password, NULL, &ctx->session) < 0) { if (esxVI_Login(ctx, username, password, NULL, &ctx->session) < 0) {
goto failure; goto cleanup;
} }
esxVI_BuildFullTraversalSpecList(&ctx->fullTraversalSpecList); esxVI_BuildFullTraversalSpecList(&ctx->fullTraversalSpecList);
...@@ -430,7 +430,7 @@ esxVI_Context_Connect(esxVI_Context *ctx, const char *url, ...@@ -430,7 +430,7 @@ esxVI_Context_Connect(esxVI_Context *ctx, const char *url,
if (esxVI_String_AppendValueListToList(&propertyNameList, if (esxVI_String_AppendValueListToList(&propertyNameList,
"vmFolder\0" "vmFolder\0"
"hostFolder\0") < 0) { "hostFolder\0") < 0) {
goto failure; goto cleanup;
} }
/* Get pointer to Datacenter for later use */ /* Get pointer to Datacenter for later use */
...@@ -438,14 +438,14 @@ esxVI_Context_Connect(esxVI_Context *ctx, const char *url, ...@@ -438,14 +438,14 @@ esxVI_Context_Connect(esxVI_Context *ctx, const char *url,
"Datacenter", propertyNameList, "Datacenter", propertyNameList,
esxVI_Boolean_True, esxVI_Boolean_True,
&datacenterList) < 0) { &datacenterList) < 0) {
goto failure; goto cleanup;
} }
if (datacenterList == NULL) { if (datacenterList == NULL) {
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
_("Could not retrieve the 'datacenter' object from the " _("Could not retrieve the 'datacenter' object from the "
"VI host/center")); "VI host/center"));
goto failure; goto cleanup;
} }
ctx->datacenter = datacenterList->obj; ctx->datacenter = datacenterList->obj;
...@@ -457,12 +457,12 @@ esxVI_Context_Connect(esxVI_Context *ctx, const char *url, ...@@ -457,12 +457,12 @@ esxVI_Context_Connect(esxVI_Context *ctx, const char *url,
if (STREQ(dynamicProperty->name, "vmFolder")) { if (STREQ(dynamicProperty->name, "vmFolder")) {
if (esxVI_ManagedObjectReference_CastFromAnyType if (esxVI_ManagedObjectReference_CastFromAnyType
(dynamicProperty->val, &ctx->vmFolder)) { (dynamicProperty->val, &ctx->vmFolder)) {
goto failure; goto cleanup;
} }
} else if (STREQ(dynamicProperty->name, "hostFolder")) { } else if (STREQ(dynamicProperty->name, "hostFolder")) {
if (esxVI_ManagedObjectReference_CastFromAnyType if (esxVI_ManagedObjectReference_CastFromAnyType
(dynamicProperty->val, &ctx->hostFolder)) { (dynamicProperty->val, &ctx->hostFolder)) {
goto failure; goto cleanup;
} }
} else { } else {
VIR_WARN("Unexpected '%s' property", dynamicProperty->name); VIR_WARN("Unexpected '%s' property", dynamicProperty->name);
...@@ -473,19 +473,16 @@ esxVI_Context_Connect(esxVI_Context *ctx, const char *url, ...@@ -473,19 +473,16 @@ esxVI_Context_Connect(esxVI_Context *ctx, const char *url,
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
_("The 'datacenter' object is missing the " _("The 'datacenter' object is missing the "
"'vmFolder'/'hostFolder' property")); "'vmFolder'/'hostFolder' property"));
goto failure; goto cleanup;
} }
result = 0;
cleanup: cleanup:
esxVI_String_Free(&propertyNameList); esxVI_String_Free(&propertyNameList);
esxVI_ObjectContent_Free(&datacenterList); esxVI_ObjectContent_Free(&datacenterList);
return result; return result;
failure:
result = -1;
goto cleanup;
} }
int int
...@@ -496,7 +493,7 @@ esxVI_Context_DownloadFile(esxVI_Context *ctx, const char *url, char **content) ...@@ -496,7 +493,7 @@ esxVI_Context_DownloadFile(esxVI_Context *ctx, const char *url, char **content)
if (content == NULL || *content != NULL) { if (content == NULL || *content != NULL) {
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument")); ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
goto failure; return -1;
} }
virMutexLock(&ctx->curl_lock); virMutexLock(&ctx->curl_lock);
...@@ -511,27 +508,28 @@ esxVI_Context_DownloadFile(esxVI_Context *ctx, const char *url, char **content) ...@@ -511,27 +508,28 @@ esxVI_Context_DownloadFile(esxVI_Context *ctx, const char *url, char **content)
virMutexUnlock(&ctx->curl_lock); virMutexUnlock(&ctx->curl_lock);
if (responseCode < 0) { if (responseCode < 0) {
goto failure; goto cleanup;
} else if (responseCode != 200) { } else if (responseCode != 200) {
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
_("HTTP response code %d for download from '%s'"), _("HTTP response code %d for download from '%s'"),
responseCode, url); responseCode, url);
goto failure; goto cleanup;
} }
if (virBufferError(&buffer)) { if (virBufferError(&buffer)) {
virReportOOMError(); virReportOOMError();
goto failure; goto cleanup;
} }
*content = virBufferContentAndReset(&buffer); *content = virBufferContentAndReset(&buffer);
return 0; cleanup:
if (*content == NULL) {
failure: virBufferFreeAndReset(&buffer);
virBufferFreeAndReset(&buffer); return -1;
}
return -1; return 0;
} }
int int
...@@ -573,7 +571,7 @@ esxVI_Context_Execute(esxVI_Context *ctx, const char *methodName, ...@@ -573,7 +571,7 @@ esxVI_Context_Execute(esxVI_Context *ctx, const char *methodName,
const char *request, esxVI_Response **response, const char *request, esxVI_Response **response,
esxVI_Occurrence occurrence) esxVI_Occurrence occurrence)
{ {
int result = 0; int result = -1;
virBuffer buffer = VIR_BUFFER_INITIALIZER; virBuffer buffer = VIR_BUFFER_INITIALIZER;
esxVI_Fault *fault = NULL; esxVI_Fault *fault = NULL;
char *xpathExpression = NULL; char *xpathExpression = NULL;
...@@ -582,11 +580,11 @@ esxVI_Context_Execute(esxVI_Context *ctx, const char *methodName, ...@@ -582,11 +580,11 @@ esxVI_Context_Execute(esxVI_Context *ctx, const char *methodName,
if (request == NULL || response == NULL || *response != NULL) { if (request == NULL || response == NULL || *response != NULL) {
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument")); ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
goto failure; return -1;
} }
if (esxVI_Response_Alloc(response) < 0) { if (esxVI_Response_Alloc(response) < 0) {
goto failure; return -1;
} }
virMutexLock(&ctx->curl_lock); virMutexLock(&ctx->curl_lock);
...@@ -602,12 +600,12 @@ esxVI_Context_Execute(esxVI_Context *ctx, const char *methodName, ...@@ -602,12 +600,12 @@ esxVI_Context_Execute(esxVI_Context *ctx, const char *methodName,
virMutexUnlock(&ctx->curl_lock); virMutexUnlock(&ctx->curl_lock);
if ((*response)->responseCode < 0) { if ((*response)->responseCode < 0) {
goto failure; goto cleanup;
} }
if (virBufferError(&buffer)) { if (virBufferError(&buffer)) {
virReportOOMError(); virReportOOMError();
goto failure; goto cleanup;
} }
(*response)->content = virBufferContentAndReset(&buffer); (*response)->content = virBufferContentAndReset(&buffer);
...@@ -620,14 +618,14 @@ esxVI_Context_Execute(esxVI_Context *ctx, const char *methodName, ...@@ -620,14 +618,14 @@ esxVI_Context_Execute(esxVI_Context *ctx, const char *methodName,
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Response for call to '%s' could not be parsed"), _("Response for call to '%s' could not be parsed"),
methodName); methodName);
goto failure; goto cleanup;
} }
if (xmlDocGetRootElement((*response)->document) == NULL) { if (xmlDocGetRootElement((*response)->document) == NULL) {
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Response for call to '%s' is an empty XML document"), _("Response for call to '%s' is an empty XML document"),
methodName); methodName);
goto failure; goto cleanup;
} }
xpathContext = xmlXPathNewContext((*response)->document); xpathContext = xmlXPathNewContext((*response)->document);
...@@ -635,7 +633,7 @@ esxVI_Context_Execute(esxVI_Context *ctx, const char *methodName, ...@@ -635,7 +633,7 @@ esxVI_Context_Execute(esxVI_Context *ctx, const char *methodName,
if (xpathContext == NULL) { if (xpathContext == NULL) {
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
_("Could not create XPath context")); _("Could not create XPath context"));
goto failure; goto cleanup;
} }
xmlXPathRegisterNs(xpathContext, BAD_CAST "soapenv", xmlXPathRegisterNs(xpathContext, BAD_CAST "soapenv",
...@@ -652,7 +650,7 @@ esxVI_Context_Execute(esxVI_Context *ctx, const char *methodName, ...@@ -652,7 +650,7 @@ esxVI_Context_Execute(esxVI_Context *ctx, const char *methodName,
_("HTTP response code %d for call to '%s'. " _("HTTP response code %d for call to '%s'. "
"Fault is unknown, XPath evaluation failed"), "Fault is unknown, XPath evaluation failed"),
(*response)->responseCode, methodName); (*response)->responseCode, methodName);
goto failure; goto cleanup;
} }
if (esxVI_Fault_Deserialize((*response)->node, &fault) < 0) { if (esxVI_Fault_Deserialize((*response)->node, &fault) < 0) {
...@@ -660,7 +658,7 @@ esxVI_Context_Execute(esxVI_Context *ctx, const char *methodName, ...@@ -660,7 +658,7 @@ esxVI_Context_Execute(esxVI_Context *ctx, const char *methodName,
_("HTTP response code %d for call to '%s'. " _("HTTP response code %d for call to '%s'. "
"Fault is unknown, deserialization failed"), "Fault is unknown, deserialization failed"),
(*response)->responseCode, methodName); (*response)->responseCode, methodName);
goto failure; goto cleanup;
} }
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
...@@ -673,13 +671,13 @@ esxVI_Context_Execute(esxVI_Context *ctx, const char *methodName, ...@@ -673,13 +671,13 @@ esxVI_Context_Execute(esxVI_Context *ctx, const char *methodName,
(*response)->responseCode, methodName, (*response)->responseCode, methodName,
(*response)->content); (*response)->content);
goto failure; goto cleanup;
} else { } else {
if (virAsprintf(&xpathExpression, if (virAsprintf(&xpathExpression,
"/soapenv:Envelope/soapenv:Body/vim:%sResponse", "/soapenv:Envelope/soapenv:Body/vim:%sResponse",
methodName) < 0) { methodName) < 0) {
virReportOOMError(); virReportOOMError();
goto failure; goto cleanup;
} }
responseNode = virXPathNode(xpathExpression, xpathContext); responseNode = virXPathNode(xpathExpression, xpathContext);
...@@ -688,7 +686,7 @@ esxVI_Context_Execute(esxVI_Context *ctx, const char *methodName, ...@@ -688,7 +686,7 @@ esxVI_Context_Execute(esxVI_Context *ctx, const char *methodName,
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
_("XPath evaluation of response for call to '%s' " _("XPath evaluation of response for call to '%s' "
"failed"), methodName); "failed"), methodName);
goto failure; goto cleanup;
} }
xpathContext->node = responseNode; xpathContext->node = responseNode;
...@@ -700,12 +698,12 @@ esxVI_Context_Execute(esxVI_Context *ctx, const char *methodName, ...@@ -700,12 +698,12 @@ esxVI_Context_Execute(esxVI_Context *ctx, const char *methodName,
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Call to '%s' returned an empty result, " _("Call to '%s' returned an empty result, "
"expecting a non-empty result"), methodName); "expecting a non-empty result"), methodName);
goto failure; goto cleanup;
} else if ((*response)->node->next != NULL) { } else if ((*response)->node->next != NULL) {
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Call to '%s' returned a list, expecting " _("Call to '%s' returned a list, expecting "
"exactly one item"), methodName); "exactly one item"), methodName);
goto failure; goto cleanup;
} }
break; break;
...@@ -715,7 +713,7 @@ esxVI_Context_Execute(esxVI_Context *ctx, const char *methodName, ...@@ -715,7 +713,7 @@ esxVI_Context_Execute(esxVI_Context *ctx, const char *methodName,
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Call to '%s' returned an empty result, " _("Call to '%s' returned an empty result, "
"expecting a non-empty result"), methodName); "expecting a non-empty result"), methodName);
goto failure; goto cleanup;
} }
break; break;
...@@ -726,7 +724,7 @@ esxVI_Context_Execute(esxVI_Context *ctx, const char *methodName, ...@@ -726,7 +724,7 @@ esxVI_Context_Execute(esxVI_Context *ctx, const char *methodName,
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Call to '%s' returned a list, expecting " _("Call to '%s' returned a list, expecting "
"exactly one item"), methodName); "exactly one item"), methodName);
goto failure; goto cleanup;
} }
break; break;
...@@ -740,7 +738,7 @@ esxVI_Context_Execute(esxVI_Context *ctx, const char *methodName, ...@@ -740,7 +738,7 @@ esxVI_Context_Execute(esxVI_Context *ctx, const char *methodName,
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Call to '%s' returned something, expecting " _("Call to '%s' returned something, expecting "
"an empty result"), methodName); "an empty result"), methodName);
goto failure; goto cleanup;
} }
break; break;
...@@ -748,30 +746,29 @@ esxVI_Context_Execute(esxVI_Context *ctx, const char *methodName, ...@@ -748,30 +746,29 @@ esxVI_Context_Execute(esxVI_Context *ctx, const char *methodName,
default: default:
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
_("Invalid argument (occurrence)")); _("Invalid argument (occurrence)"));
goto failure; goto cleanup;
} }
} }
} else { } else {
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
_("HTTP response code %d for call to '%s'"), _("HTTP response code %d for call to '%s'"),
(*response)->responseCode, methodName); (*response)->responseCode, methodName);
goto failure; goto cleanup;
} }
result = 0;
cleanup: cleanup:
if (result < 0) {
virBufferFreeAndReset(&buffer);
esxVI_Response_Free(response);
esxVI_Fault_Free(&fault);
}
VIR_FREE(xpathExpression); VIR_FREE(xpathExpression);
xmlXPathFreeContext(xpathContext); xmlXPathFreeContext(xpathContext);
return result; return result;
failure:
virBufferFreeAndReset(&buffer);
esxVI_Response_Free(response);
esxVI_Fault_Free(&fault);
result = -1;
goto cleanup;
} }
...@@ -877,39 +874,36 @@ esxVI_Enumeration_Deserialize(const esxVI_Enumeration *enumeration, ...@@ -877,39 +874,36 @@ esxVI_Enumeration_Deserialize(const esxVI_Enumeration *enumeration,
xmlNodePtr node, int *value) xmlNodePtr node, int *value)
{ {
int i; int i;
int result = 0; int result = -1;
char *name = NULL; char *name = NULL;
if (value == NULL) { if (value == NULL) {
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument")); ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
goto failure; return -1;
} }
*value = 0; /* undefined */ *value = 0; /* undefined */
if (esxVI_String_DeserializeValue(node, &name) < 0) { if (esxVI_String_DeserializeValue(node, &name) < 0) {
goto failure; return -1;
} }
for (i = 0; enumeration->values[i].name != NULL; ++i) { for (i = 0; enumeration->values[i].name != NULL; ++i) {
if (STREQ(name, enumeration->values[i].name)) { if (STREQ(name, enumeration->values[i].name)) {
*value = enumeration->values[i].value; *value = enumeration->values[i].value;
goto cleanup; result = 0;
break;
} }
} }
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, _("Unknown value '%s' for %s"), if (result < 0) {
name, esxVI_Type_ToString(enumeration->type)); ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, _("Unknown value '%s' for %s"),
name, esxVI_Type_ToString(enumeration->type));
}
cleanup:
VIR_FREE(name); VIR_FREE(name);
return result; return result;
failure:
result = -1;
goto cleanup;
} }
...@@ -954,7 +948,7 @@ esxVI_List_DeepCopy(esxVI_List **destList, esxVI_List *srcList, ...@@ -954,7 +948,7 @@ esxVI_List_DeepCopy(esxVI_List **destList, esxVI_List *srcList,
if (destList == NULL || *destList != NULL) { if (destList == NULL || *destList != NULL) {
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument")); ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
goto failure; return -1;
} }
for (src = srcList; src != NULL; src = src->_next) { for (src = srcList; src != NULL; src = src->_next) {
...@@ -980,7 +974,7 @@ esxVI_List_CastFromAnyType(esxVI_AnyType *anyType, esxVI_List **list, ...@@ -980,7 +974,7 @@ esxVI_List_CastFromAnyType(esxVI_AnyType *anyType, esxVI_List **list,
esxVI_List_CastFromAnyTypeFunc castFromAnyTypeFunc, esxVI_List_CastFromAnyTypeFunc castFromAnyTypeFunc,
esxVI_List_FreeFunc freeFunc) esxVI_List_FreeFunc freeFunc)
{ {
int result = 0; int result = -1;
xmlNodePtr childNode = NULL; xmlNodePtr childNode = NULL;
esxVI_AnyType *childAnyType = NULL; esxVI_AnyType *childAnyType = NULL;
esxVI_List *item = NULL; esxVI_List *item = NULL;
...@@ -1007,7 +1001,7 @@ esxVI_List_CastFromAnyType(esxVI_AnyType *anyType, esxVI_List **list, ...@@ -1007,7 +1001,7 @@ esxVI_List_CastFromAnyType(esxVI_AnyType *anyType, esxVI_List **list,
if (childNode->type != XML_ELEMENT_NODE) { if (childNode->type != XML_ELEMENT_NODE) {
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Wrong XML element type %d"), childNode->type); _("Wrong XML element type %d"), childNode->type);
goto failure; goto cleanup;
} }
esxVI_AnyType_Free(&childAnyType); esxVI_AnyType_Free(&childAnyType);
...@@ -1015,24 +1009,23 @@ esxVI_List_CastFromAnyType(esxVI_AnyType *anyType, esxVI_List **list, ...@@ -1015,24 +1009,23 @@ esxVI_List_CastFromAnyType(esxVI_AnyType *anyType, esxVI_List **list,
if (esxVI_AnyType_Deserialize(childNode, &childAnyType) < 0 || if (esxVI_AnyType_Deserialize(childNode, &childAnyType) < 0 ||
castFromAnyTypeFunc(childAnyType, &item) < 0 || castFromAnyTypeFunc(childAnyType, &item) < 0 ||
esxVI_List_Append(list, item) < 0) { esxVI_List_Append(list, item) < 0) {
goto failure; goto cleanup;
} }
item = NULL; item = NULL;
} }
result = 0;
cleanup: cleanup:
if (result < 0) {
freeFunc(&item);
freeFunc(list);
}
esxVI_AnyType_Free(&childAnyType); esxVI_AnyType_Free(&childAnyType);
return result; return result;
failure:
freeFunc(&item);
freeFunc(list);
result = -1;
goto cleanup;
} }
int int
...@@ -1300,7 +1293,7 @@ esxVI_EnsureSession(esxVI_Context *ctx) ...@@ -1300,7 +1293,7 @@ esxVI_EnsureSession(esxVI_Context *ctx)
#if ESX_VI_USE_SESSION_IS_ACTIVE #if ESX_VI_USE_SESSION_IS_ACTIVE
esxVI_Boolean active = esxVI_Boolean_Undefined; esxVI_Boolean active = esxVI_Boolean_Undefined;
#else #else
int result = 0; int result = -1;
esxVI_String *propertyNameList = NULL; esxVI_String *propertyNameList = NULL;
esxVI_ObjectContent *sessionManager = NULL; esxVI_ObjectContent *sessionManager = NULL;
esxVI_DynamicProperty *dynamicProperty = NULL; esxVI_DynamicProperty *dynamicProperty = NULL;
...@@ -1335,7 +1328,7 @@ esxVI_EnsureSession(esxVI_Context *ctx) ...@@ -1335,7 +1328,7 @@ esxVI_EnsureSession(esxVI_Context *ctx)
"SessionManager", propertyNameList, "SessionManager", propertyNameList,
esxVI_Boolean_False, esxVI_Boolean_False,
&sessionManager) < 0) { &sessionManager) < 0) {
goto failure; goto cleanup;
} }
for (dynamicProperty = sessionManager->propSet; dynamicProperty != NULL; for (dynamicProperty = sessionManager->propSet; dynamicProperty != NULL;
...@@ -1343,7 +1336,7 @@ esxVI_EnsureSession(esxVI_Context *ctx) ...@@ -1343,7 +1336,7 @@ esxVI_EnsureSession(esxVI_Context *ctx)
if (STREQ(dynamicProperty->name, "currentSession")) { if (STREQ(dynamicProperty->name, "currentSession")) {
if (esxVI_UserSession_CastFromAnyType(dynamicProperty->val, if (esxVI_UserSession_CastFromAnyType(dynamicProperty->val,
&currentSession) < 0) { &currentSession) < 0) {
goto failure; goto cleanup;
} }
break; break;
...@@ -1357,26 +1350,23 @@ esxVI_EnsureSession(esxVI_Context *ctx) ...@@ -1357,26 +1350,23 @@ esxVI_EnsureSession(esxVI_Context *ctx)
if (esxVI_Login(ctx, ctx->username, ctx->password, NULL, if (esxVI_Login(ctx, ctx->username, ctx->password, NULL,
&ctx->session) < 0) { &ctx->session) < 0) {
goto failure; goto cleanup;
} }
} else if (STRNEQ(ctx->session->key, currentSession->key)) { } else if (STRNEQ(ctx->session->key, currentSession->key)) {
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
_("Key of the current session differs from the key at " _("Key of the current session differs from the key at "
"last login")); "last login"));
goto failure; goto cleanup;
} }
result = 0;
cleanup: cleanup:
esxVI_String_Free(&propertyNameList); esxVI_String_Free(&propertyNameList);
esxVI_ObjectContent_Free(&sessionManager); esxVI_ObjectContent_Free(&sessionManager);
esxVI_UserSession_Free(&currentSession); esxVI_UserSession_Free(&currentSession);
return result; return result;
failure:
result = -1;
goto cleanup;
#endif #endif
} }
...@@ -1390,7 +1380,7 @@ esxVI_LookupObjectContentByType(esxVI_Context *ctx, ...@@ -1390,7 +1380,7 @@ esxVI_LookupObjectContentByType(esxVI_Context *ctx,
esxVI_Boolean recurse, esxVI_Boolean recurse,
esxVI_ObjectContent **objectContentList) esxVI_ObjectContent **objectContentList)
{ {
int result = 0; int result = -1;
esxVI_ObjectSpec *objectSpec = NULL; esxVI_ObjectSpec *objectSpec = NULL;
esxVI_PropertySpec *propertySpec = NULL; esxVI_PropertySpec *propertySpec = NULL;
esxVI_PropertyFilterSpec *propertyFilterSpec = NULL; esxVI_PropertyFilterSpec *propertyFilterSpec = NULL;
...@@ -1401,7 +1391,7 @@ esxVI_LookupObjectContentByType(esxVI_Context *ctx, ...@@ -1401,7 +1391,7 @@ esxVI_LookupObjectContentByType(esxVI_Context *ctx,
} }
if (esxVI_ObjectSpec_Alloc(&objectSpec) < 0) { if (esxVI_ObjectSpec_Alloc(&objectSpec) < 0) {
goto failure; return -1;
} }
objectSpec->obj = root; objectSpec->obj = root;
...@@ -1412,7 +1402,7 @@ esxVI_LookupObjectContentByType(esxVI_Context *ctx, ...@@ -1412,7 +1402,7 @@ esxVI_LookupObjectContentByType(esxVI_Context *ctx,
} }
if (esxVI_PropertySpec_Alloc(&propertySpec) < 0) { if (esxVI_PropertySpec_Alloc(&propertySpec) < 0) {
goto failure; goto cleanup;
} }
propertySpec->type = (char *)type; propertySpec->type = (char *)type;
...@@ -1423,7 +1413,7 @@ esxVI_LookupObjectContentByType(esxVI_Context *ctx, ...@@ -1423,7 +1413,7 @@ esxVI_LookupObjectContentByType(esxVI_Context *ctx,
propertySpec) < 0 || propertySpec) < 0 ||
esxVI_ObjectSpec_AppendToList(&propertyFilterSpec->objectSet, esxVI_ObjectSpec_AppendToList(&propertyFilterSpec->objectSet,
objectSpec) < 0) { objectSpec) < 0) {
goto failure; goto cleanup;
} }
result = esxVI_RetrieveProperties(ctx, propertyFilterSpec, result = esxVI_RetrieveProperties(ctx, propertyFilterSpec,
...@@ -1447,11 +1437,6 @@ esxVI_LookupObjectContentByType(esxVI_Context *ctx, ...@@ -1447,11 +1437,6 @@ esxVI_LookupObjectContentByType(esxVI_Context *ctx,
esxVI_PropertyFilterSpec_Free(&propertyFilterSpec); esxVI_PropertyFilterSpec_Free(&propertyFilterSpec);
return result; return result;
failure:
result = -1;
goto cleanup;
} }
...@@ -1642,19 +1627,20 @@ esxVI_LookupNumberOfDomainsByPowerState(esxVI_Context *ctx, ...@@ -1642,19 +1627,20 @@ esxVI_LookupNumberOfDomainsByPowerState(esxVI_Context *ctx,
esxVI_VirtualMachinePowerState powerState, esxVI_VirtualMachinePowerState powerState,
esxVI_Boolean inverse) esxVI_Boolean inverse)
{ {
bool success = false;
esxVI_String *propertyNameList = NULL; esxVI_String *propertyNameList = NULL;
esxVI_ObjectContent *virtualMachineList = NULL; esxVI_ObjectContent *virtualMachineList = NULL;
esxVI_ObjectContent *virtualMachine = NULL; esxVI_ObjectContent *virtualMachine = NULL;
esxVI_DynamicProperty *dynamicProperty = NULL; esxVI_DynamicProperty *dynamicProperty = NULL;
esxVI_VirtualMachinePowerState powerState_; esxVI_VirtualMachinePowerState powerState_;
int numberOfDomains = 0; int count = 0;
if (esxVI_String_AppendValueToList(&propertyNameList, if (esxVI_String_AppendValueToList(&propertyNameList,
"runtime.powerState") < 0 || "runtime.powerState") < 0 ||
esxVI_LookupObjectContentByType(ctx, ctx->vmFolder, "VirtualMachine", esxVI_LookupObjectContentByType(ctx, ctx->vmFolder, "VirtualMachine",
propertyNameList, esxVI_Boolean_True, propertyNameList, esxVI_Boolean_True,
&virtualMachineList) < 0) { &virtualMachineList) < 0) {
goto failure; goto cleanup;
} }
for (virtualMachine = virtualMachineList; virtualMachine != NULL; for (virtualMachine = virtualMachineList; virtualMachine != NULL;
...@@ -1665,14 +1651,14 @@ esxVI_LookupNumberOfDomainsByPowerState(esxVI_Context *ctx, ...@@ -1665,14 +1651,14 @@ esxVI_LookupNumberOfDomainsByPowerState(esxVI_Context *ctx,
if (STREQ(dynamicProperty->name, "runtime.powerState")) { if (STREQ(dynamicProperty->name, "runtime.powerState")) {
if (esxVI_VirtualMachinePowerState_CastFromAnyType if (esxVI_VirtualMachinePowerState_CastFromAnyType
(dynamicProperty->val, &powerState_) < 0) { (dynamicProperty->val, &powerState_) < 0) {
goto failure; goto cleanup;
} }
if ((inverse != esxVI_Boolean_True && if ((inverse != esxVI_Boolean_True &&
powerState_ == powerState) || powerState_ == powerState) ||
(inverse == esxVI_Boolean_True && (inverse == esxVI_Boolean_True &&
powerState_ != powerState)) { powerState_ != powerState)) {
numberOfDomains++; count++;
} }
} else { } else {
VIR_WARN("Unexpected '%s' property", dynamicProperty->name); VIR_WARN("Unexpected '%s' property", dynamicProperty->name);
...@@ -1680,16 +1666,13 @@ esxVI_LookupNumberOfDomainsByPowerState(esxVI_Context *ctx, ...@@ -1680,16 +1666,13 @@ esxVI_LookupNumberOfDomainsByPowerState(esxVI_Context *ctx,
} }
} }
success = true;
cleanup: cleanup:
esxVI_String_Free(&propertyNameList); esxVI_String_Free(&propertyNameList);
esxVI_ObjectContent_Free(&virtualMachineList); esxVI_ObjectContent_Free(&virtualMachineList);
return numberOfDomains; return success ? count : -1;
failure:
numberOfDomains = -1;
goto cleanup;
} }
...@@ -1955,7 +1938,7 @@ esxVI_LookupResourcePoolByHostSystem ...@@ -1955,7 +1938,7 @@ esxVI_LookupResourcePoolByHostSystem
(esxVI_Context *ctx, esxVI_ObjectContent *hostSystem, (esxVI_Context *ctx, esxVI_ObjectContent *hostSystem,
esxVI_ManagedObjectReference **resourcePool) esxVI_ManagedObjectReference **resourcePool)
{ {
int result = 0; int result = -1;
esxVI_String *propertyNameList = NULL; esxVI_String *propertyNameList = NULL;
esxVI_DynamicProperty *dynamicProperty = NULL; esxVI_DynamicProperty *dynamicProperty = NULL;
esxVI_ManagedObjectReference *managedObjectReference = NULL; esxVI_ManagedObjectReference *managedObjectReference = NULL;
...@@ -1971,7 +1954,7 @@ esxVI_LookupResourcePoolByHostSystem ...@@ -1971,7 +1954,7 @@ esxVI_LookupResourcePoolByHostSystem
if (STREQ(dynamicProperty->name, "parent")) { if (STREQ(dynamicProperty->name, "parent")) {
if (esxVI_ManagedObjectReference_CastFromAnyType if (esxVI_ManagedObjectReference_CastFromAnyType
(dynamicProperty->val, &managedObjectReference) < 0) { (dynamicProperty->val, &managedObjectReference) < 0) {
goto failure; goto cleanup;
} }
break; break;
...@@ -1983,7 +1966,7 @@ esxVI_LookupResourcePoolByHostSystem ...@@ -1983,7 +1966,7 @@ esxVI_LookupResourcePoolByHostSystem
if (managedObjectReference == NULL) { if (managedObjectReference == NULL) {
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
_("Could not retrieve compute resource of host system")); _("Could not retrieve compute resource of host system"));
goto failure; goto cleanup;
} }
if (esxVI_String_AppendValueToList(&propertyNameList, "resourcePool") < 0 || if (esxVI_String_AppendValueToList(&propertyNameList, "resourcePool") < 0 ||
...@@ -1991,13 +1974,13 @@ esxVI_LookupResourcePoolByHostSystem ...@@ -1991,13 +1974,13 @@ esxVI_LookupResourcePoolByHostSystem
"ComputeResource", propertyNameList, "ComputeResource", propertyNameList,
esxVI_Boolean_False, esxVI_Boolean_False,
&computeResource) < 0) { &computeResource) < 0) {
goto failure; goto cleanup;
} }
if (computeResource == NULL) { if (computeResource == NULL) {
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
_("Could not retrieve compute resource of host system")); _("Could not retrieve compute resource of host system"));
goto failure; goto cleanup;
} }
for (dynamicProperty = computeResource->propSet; dynamicProperty != NULL; for (dynamicProperty = computeResource->propSet; dynamicProperty != NULL;
...@@ -2005,7 +1988,7 @@ esxVI_LookupResourcePoolByHostSystem ...@@ -2005,7 +1988,7 @@ esxVI_LookupResourcePoolByHostSystem
if (STREQ(dynamicProperty->name, "resourcePool")) { if (STREQ(dynamicProperty->name, "resourcePool")) {
if (esxVI_ManagedObjectReference_CastFromAnyType if (esxVI_ManagedObjectReference_CastFromAnyType
(dynamicProperty->val, resourcePool) < 0) { (dynamicProperty->val, resourcePool) < 0) {
goto failure; goto cleanup;
} }
break; break;
...@@ -2017,20 +2000,17 @@ esxVI_LookupResourcePoolByHostSystem ...@@ -2017,20 +2000,17 @@ esxVI_LookupResourcePoolByHostSystem
if ((*resourcePool) == NULL) { if ((*resourcePool) == NULL) {
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
_("Could not retrieve resource pool of compute resource")); _("Could not retrieve resource pool of compute resource"));
goto failure; goto cleanup;
} }
result = 0;
cleanup: cleanup:
esxVI_String_Free(&propertyNameList); esxVI_String_Free(&propertyNameList);
esxVI_ManagedObjectReference_Free(&managedObjectReference); esxVI_ManagedObjectReference_Free(&managedObjectReference);
esxVI_ObjectContent_Free(&computeResource); esxVI_ObjectContent_Free(&computeResource);
return result; return result;
failure:
result = -1;
goto cleanup;
} }
...@@ -2040,7 +2020,7 @@ esxVI_LookupHostSystemByIp(esxVI_Context *ctx, const char *ipAddress, ...@@ -2040,7 +2020,7 @@ esxVI_LookupHostSystemByIp(esxVI_Context *ctx, const char *ipAddress,
esxVI_String *propertyNameList, esxVI_String *propertyNameList,
esxVI_ObjectContent **hostSystem) esxVI_ObjectContent **hostSystem)
{ {
int result = 0; int result = -1;
esxVI_ManagedObjectReference *managedObjectReference = NULL; esxVI_ManagedObjectReference *managedObjectReference = NULL;
if (hostSystem == NULL || *hostSystem != NULL) { if (hostSystem == NULL || *hostSystem != NULL) {
...@@ -2050,31 +2030,28 @@ esxVI_LookupHostSystemByIp(esxVI_Context *ctx, const char *ipAddress, ...@@ -2050,31 +2030,28 @@ esxVI_LookupHostSystemByIp(esxVI_Context *ctx, const char *ipAddress,
if (esxVI_FindByIp(ctx, ctx->datacenter, ipAddress, esxVI_Boolean_False, if (esxVI_FindByIp(ctx, ctx->datacenter, ipAddress, esxVI_Boolean_False,
&managedObjectReference) < 0) { &managedObjectReference) < 0) {
goto failure; return -1;
} }
if (managedObjectReference == NULL) { if (managedObjectReference == NULL) {
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Could not find host system with IP address '%s'"), _("Could not find host system with IP address '%s'"),
ipAddress); ipAddress);
goto failure; goto cleanup;
} }
if (esxVI_LookupObjectContentByType(ctx, managedObjectReference, if (esxVI_LookupObjectContentByType(ctx, managedObjectReference,
"HostSystem", propertyNameList, "HostSystem", propertyNameList,
esxVI_Boolean_False, hostSystem) < 0) { esxVI_Boolean_False, hostSystem) < 0) {
goto failure; goto cleanup;
} }
result = 0;
cleanup: cleanup:
esxVI_ManagedObjectReference_Free(&managedObjectReference); esxVI_ManagedObjectReference_Free(&managedObjectReference);
return result; return result;
failure:
result = -1;
goto cleanup;
} }
...@@ -2085,7 +2062,7 @@ esxVI_LookupVirtualMachineByUuid(esxVI_Context *ctx, const unsigned char *uuid, ...@@ -2085,7 +2062,7 @@ esxVI_LookupVirtualMachineByUuid(esxVI_Context *ctx, const unsigned char *uuid,
esxVI_ObjectContent **virtualMachine, esxVI_ObjectContent **virtualMachine,
esxVI_Occurrence occurrence) esxVI_Occurrence occurrence)
{ {
int result = 0; int result = -1;
esxVI_ManagedObjectReference *managedObjectReference = NULL; esxVI_ManagedObjectReference *managedObjectReference = NULL;
char uuid_string[VIR_UUID_STRING_BUFLEN] = ""; char uuid_string[VIR_UUID_STRING_BUFLEN] = "";
...@@ -2098,7 +2075,7 @@ esxVI_LookupVirtualMachineByUuid(esxVI_Context *ctx, const unsigned char *uuid, ...@@ -2098,7 +2075,7 @@ esxVI_LookupVirtualMachineByUuid(esxVI_Context *ctx, const unsigned char *uuid,
if (esxVI_FindByUuid(ctx, ctx->datacenter, uuid_string, esxVI_Boolean_True, if (esxVI_FindByUuid(ctx, ctx->datacenter, uuid_string, esxVI_Boolean_True,
&managedObjectReference) < 0) { &managedObjectReference) < 0) {
goto failure; return -1;
} }
if (managedObjectReference == NULL) { if (managedObjectReference == NULL) {
...@@ -2108,7 +2085,7 @@ esxVI_LookupVirtualMachineByUuid(esxVI_Context *ctx, const unsigned char *uuid, ...@@ -2108,7 +2085,7 @@ esxVI_LookupVirtualMachineByUuid(esxVI_Context *ctx, const unsigned char *uuid,
ESX_VI_ERROR(VIR_ERR_NO_DOMAIN, ESX_VI_ERROR(VIR_ERR_NO_DOMAIN,
_("Could not find domain with UUID '%s'"), _("Could not find domain with UUID '%s'"),
uuid_string); uuid_string);
goto failure; goto cleanup;
} }
} }
...@@ -2116,18 +2093,15 @@ esxVI_LookupVirtualMachineByUuid(esxVI_Context *ctx, const unsigned char *uuid, ...@@ -2116,18 +2093,15 @@ esxVI_LookupVirtualMachineByUuid(esxVI_Context *ctx, const unsigned char *uuid,
"VirtualMachine", propertyNameList, "VirtualMachine", propertyNameList,
esxVI_Boolean_False, esxVI_Boolean_False,
virtualMachine) < 0) { virtualMachine) < 0) {
goto failure; goto cleanup;
} }
result = 0;
cleanup: cleanup:
esxVI_ManagedObjectReference_Free(&managedObjectReference); esxVI_ManagedObjectReference_Free(&managedObjectReference);
return result; return result;
failure:
result = -1;
goto cleanup;
} }
...@@ -2138,7 +2112,7 @@ esxVI_LookupVirtualMachineByName(esxVI_Context *ctx, const char *name, ...@@ -2138,7 +2112,7 @@ esxVI_LookupVirtualMachineByName(esxVI_Context *ctx, const char *name,
esxVI_ObjectContent **virtualMachine, esxVI_ObjectContent **virtualMachine,
esxVI_Occurrence occurrence) esxVI_Occurrence occurrence)
{ {
int result = 0; int result = -1;
esxVI_String *completePropertyNameList = NULL; esxVI_String *completePropertyNameList = NULL;
esxVI_ObjectContent *virtualMachineList = NULL; esxVI_ObjectContent *virtualMachineList = NULL;
esxVI_ObjectContent *candidate = NULL; esxVI_ObjectContent *candidate = NULL;
...@@ -2156,7 +2130,7 @@ esxVI_LookupVirtualMachineByName(esxVI_Context *ctx, const char *name, ...@@ -2156,7 +2130,7 @@ esxVI_LookupVirtualMachineByName(esxVI_Context *ctx, const char *name,
completePropertyNameList, completePropertyNameList,
esxVI_Boolean_True, esxVI_Boolean_True,
&virtualMachineList) < 0) { &virtualMachineList) < 0) {
goto failure; goto cleanup;
} }
for (candidate = virtualMachineList; candidate != NULL; for (candidate = virtualMachineList; candidate != NULL;
...@@ -2165,7 +2139,7 @@ esxVI_LookupVirtualMachineByName(esxVI_Context *ctx, const char *name, ...@@ -2165,7 +2139,7 @@ esxVI_LookupVirtualMachineByName(esxVI_Context *ctx, const char *name,
if (esxVI_GetVirtualMachineIdentity(candidate, NULL, &name_candidate, if (esxVI_GetVirtualMachineIdentity(candidate, NULL, &name_candidate,
NULL) < 0) { NULL) < 0) {
goto failure; goto cleanup;
} }
if (STRNEQ(name, name_candidate)) { if (STRNEQ(name, name_candidate)) {
...@@ -2173,7 +2147,7 @@ esxVI_LookupVirtualMachineByName(esxVI_Context *ctx, const char *name, ...@@ -2173,7 +2147,7 @@ esxVI_LookupVirtualMachineByName(esxVI_Context *ctx, const char *name,
} }
if (esxVI_ObjectContent_DeepCopy(virtualMachine, candidate) < 0) { if (esxVI_ObjectContent_DeepCopy(virtualMachine, candidate) < 0) {
goto failure; goto cleanup;
} }
break; break;
...@@ -2185,21 +2159,18 @@ esxVI_LookupVirtualMachineByName(esxVI_Context *ctx, const char *name, ...@@ -2185,21 +2159,18 @@ esxVI_LookupVirtualMachineByName(esxVI_Context *ctx, const char *name,
} else { } else {
ESX_VI_ERROR(VIR_ERR_NO_DOMAIN, ESX_VI_ERROR(VIR_ERR_NO_DOMAIN,
_("Could not find domain with name '%s'"), name); _("Could not find domain with name '%s'"), name);
goto failure; goto cleanup;
} }
} }
result = 0;
cleanup: cleanup:
esxVI_String_Free(&completePropertyNameList); esxVI_String_Free(&completePropertyNameList);
esxVI_ObjectContent_Free(&virtualMachineList); esxVI_ObjectContent_Free(&virtualMachineList);
VIR_FREE(name_candidate); VIR_FREE(name_candidate);
return result; return result;
failure:
result = -1;
goto cleanup;
} }
...@@ -2210,7 +2181,7 @@ esxVI_LookupVirtualMachineByUuidAndPrepareForTask ...@@ -2210,7 +2181,7 @@ esxVI_LookupVirtualMachineByUuidAndPrepareForTask
esxVI_String *propertyNameList, esxVI_ObjectContent **virtualMachine, esxVI_String *propertyNameList, esxVI_ObjectContent **virtualMachine,
esxVI_Boolean autoAnswer) esxVI_Boolean autoAnswer)
{ {
int result = 0; int result = -1;
esxVI_String *completePropertyNameList = NULL; esxVI_String *completePropertyNameList = NULL;
esxVI_VirtualMachineQuestionInfo *questionInfo = NULL; esxVI_VirtualMachineQuestionInfo *questionInfo = NULL;
esxVI_TaskInfo *pendingTaskInfoList = NULL; esxVI_TaskInfo *pendingTaskInfoList = NULL;
...@@ -2227,32 +2198,29 @@ esxVI_LookupVirtualMachineByUuidAndPrepareForTask ...@@ -2227,32 +2198,29 @@ esxVI_LookupVirtualMachineByUuidAndPrepareForTask
&questionInfo) < 0 || &questionInfo) < 0 ||
esxVI_LookupPendingTaskInfoListByVirtualMachine esxVI_LookupPendingTaskInfoListByVirtualMachine
(ctx, *virtualMachine, &pendingTaskInfoList) < 0) { (ctx, *virtualMachine, &pendingTaskInfoList) < 0) {
goto failure; goto cleanup;
} }
if (questionInfo != NULL && if (questionInfo != NULL &&
esxVI_HandleVirtualMachineQuestion(ctx, (*virtualMachine)->obj, esxVI_HandleVirtualMachineQuestion(ctx, (*virtualMachine)->obj,
questionInfo, autoAnswer) < 0) { questionInfo, autoAnswer) < 0) {
goto failure; goto cleanup;
} }
if (pendingTaskInfoList != NULL) { if (pendingTaskInfoList != NULL) {
ESX_VI_ERROR(VIR_ERR_OPERATION_INVALID, "%s", ESX_VI_ERROR(VIR_ERR_OPERATION_INVALID, "%s",
_("Other tasks are pending for this domain")); _("Other tasks are pending for this domain"));
goto failure; goto cleanup;
} }
result = 0;
cleanup: cleanup:
esxVI_String_Free(&completePropertyNameList); esxVI_String_Free(&completePropertyNameList);
esxVI_VirtualMachineQuestionInfo_Free(&questionInfo); esxVI_VirtualMachineQuestionInfo_Free(&questionInfo);
esxVI_TaskInfo_Free(&pendingTaskInfoList); esxVI_TaskInfo_Free(&pendingTaskInfoList);
return result; return result;
failure:
result = -1;
goto cleanup;
} }
...@@ -2263,7 +2231,7 @@ esxVI_LookupDatastoreByName(esxVI_Context *ctx, const char *name, ...@@ -2263,7 +2231,7 @@ esxVI_LookupDatastoreByName(esxVI_Context *ctx, const char *name,
esxVI_ObjectContent **datastore, esxVI_ObjectContent **datastore,
esxVI_Occurrence occurrence) esxVI_Occurrence occurrence)
{ {
int result = 0; int result = -1;
esxVI_String *completePropertyNameList = NULL; esxVI_String *completePropertyNameList = NULL;
esxVI_ObjectContent *datastoreList = NULL; esxVI_ObjectContent *datastoreList = NULL;
esxVI_ObjectContent *candidate = NULL; esxVI_ObjectContent *candidate = NULL;
...@@ -2284,23 +2252,23 @@ esxVI_LookupDatastoreByName(esxVI_Context *ctx, const char *name, ...@@ -2284,23 +2252,23 @@ esxVI_LookupDatastoreByName(esxVI_Context *ctx, const char *name,
"summary.accessible\0" "summary.accessible\0"
"summary.name\0" "summary.name\0"
"summary.url\0") < 0) { "summary.url\0") < 0) {
goto failure; goto cleanup;
} }
if (esxVI_LookupObjectContentByType(ctx, ctx->datacenter, "Datastore", if (esxVI_LookupObjectContentByType(ctx, ctx->datacenter, "Datastore",
completePropertyNameList, completePropertyNameList,
esxVI_Boolean_True, esxVI_Boolean_True,
&datastoreList) < 0) { &datastoreList) < 0) {
goto failure; goto cleanup;
} }
if (datastoreList == NULL) { if (datastoreList == NULL) {
if (occurrence == esxVI_Occurrence_OptionalItem) { if (occurrence == esxVI_Occurrence_OptionalItem) {
goto cleanup; goto success;
} else { } else {
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
_("No datastores available")); _("No datastores available"));
goto failure; goto cleanup;
} }
} }
...@@ -2314,7 +2282,7 @@ esxVI_LookupDatastoreByName(esxVI_Context *ctx, const char *name, ...@@ -2314,7 +2282,7 @@ esxVI_LookupDatastoreByName(esxVI_Context *ctx, const char *name,
if (STREQ(dynamicProperty->name, "summary.accessible")) { if (STREQ(dynamicProperty->name, "summary.accessible")) {
if (esxVI_AnyType_ExpectType(dynamicProperty->val, if (esxVI_AnyType_ExpectType(dynamicProperty->val,
esxVI_Type_Boolean) < 0) { esxVI_Type_Boolean) < 0) {
goto failure; goto cleanup;
} }
accessible = dynamicProperty->val->boolean; accessible = dynamicProperty->val->boolean;
...@@ -2326,7 +2294,7 @@ esxVI_LookupDatastoreByName(esxVI_Context *ctx, const char *name, ...@@ -2326,7 +2294,7 @@ esxVI_LookupDatastoreByName(esxVI_Context *ctx, const char *name,
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
_("Got incomplete response while querying for the " _("Got incomplete response while querying for the "
"datastore 'summary.accessible' property")); "datastore 'summary.accessible' property"));
goto failure; goto cleanup;
} }
if (accessible == esxVI_Boolean_False) { if (accessible == esxVI_Boolean_False) {
...@@ -2338,17 +2306,17 @@ esxVI_LookupDatastoreByName(esxVI_Context *ctx, const char *name, ...@@ -2338,17 +2306,17 @@ esxVI_LookupDatastoreByName(esxVI_Context *ctx, const char *name,
if (STREQ(dynamicProperty->name, "summary.name")) { if (STREQ(dynamicProperty->name, "summary.name")) {
if (esxVI_AnyType_ExpectType(dynamicProperty->val, if (esxVI_AnyType_ExpectType(dynamicProperty->val,
esxVI_Type_String) < 0) { esxVI_Type_String) < 0) {
goto failure; goto cleanup;
} }
if (STREQ(dynamicProperty->val->string, name)) { if (STREQ(dynamicProperty->val->string, name)) {
if (esxVI_ObjectContent_DeepCopy(datastore, if (esxVI_ObjectContent_DeepCopy(datastore,
candidate) < 0) { candidate) < 0) {
goto failure; goto cleanup;
} }
/* Found datastore with matching name */ /* Found datastore with matching name */
goto cleanup; goto success;
} }
} else if (STREQ(dynamicProperty->name, "summary.url") && } else if (STREQ(dynamicProperty->name, "summary.url") &&
ctx->productVersion & esxVI_ProductVersion_ESX) { ctx->productVersion & esxVI_ProductVersion_ESX) {
...@@ -2362,7 +2330,7 @@ esxVI_LookupDatastoreByName(esxVI_Context *ctx, const char *name, ...@@ -2362,7 +2330,7 @@ esxVI_LookupDatastoreByName(esxVI_Context *ctx, const char *name,
if (esxVI_AnyType_ExpectType(dynamicProperty->val, if (esxVI_AnyType_ExpectType(dynamicProperty->val,
esxVI_Type_String) < 0) { esxVI_Type_String) < 0) {
goto failure; goto cleanup;
} }
if (! STRPREFIX(dynamicProperty->val->string, if (! STRPREFIX(dynamicProperty->val->string,
...@@ -2371,17 +2339,17 @@ esxVI_LookupDatastoreByName(esxVI_Context *ctx, const char *name, ...@@ -2371,17 +2339,17 @@ esxVI_LookupDatastoreByName(esxVI_Context *ctx, const char *name,
_("Datastore URL '%s' has unexpected prefix, " _("Datastore URL '%s' has unexpected prefix, "
"expecting '/vmfs/volumes/' prefix"), "expecting '/vmfs/volumes/' prefix"),
dynamicProperty->val->string); dynamicProperty->val->string);
goto failure; goto cleanup;
} }
if (STREQ(dynamicProperty->val->string + offset, name)) { if (STREQ(dynamicProperty->val->string + offset, name)) {
if (esxVI_ObjectContent_DeepCopy(datastore, if (esxVI_ObjectContent_DeepCopy(datastore,
candidate) < 0) { candidate) < 0) {
goto failure; goto cleanup;
} }
/* Found datastore with matching URL suffix */ /* Found datastore with matching URL suffix */
goto cleanup; goto success;
} }
} }
} }
...@@ -2397,19 +2365,17 @@ esxVI_LookupDatastoreByName(esxVI_Context *ctx, const char *name, ...@@ -2397,19 +2365,17 @@ esxVI_LookupDatastoreByName(esxVI_Context *ctx, const char *name,
_("Could not find datastore '%s'"), name); _("Could not find datastore '%s'"), name);
} }
goto failure; goto cleanup;
} }
success:
result = 0;
cleanup: cleanup:
esxVI_String_Free(&completePropertyNameList); esxVI_String_Free(&completePropertyNameList);
esxVI_ObjectContent_Free(&datastoreList); esxVI_ObjectContent_Free(&datastoreList);
return result; return result;
failure:
result = -1;
goto cleanup;
} }
...@@ -2419,7 +2385,7 @@ esxVI_LookupTaskInfoByTask(esxVI_Context *ctx, ...@@ -2419,7 +2385,7 @@ esxVI_LookupTaskInfoByTask(esxVI_Context *ctx,
esxVI_ManagedObjectReference *task, esxVI_ManagedObjectReference *task,
esxVI_TaskInfo **taskInfo) esxVI_TaskInfo **taskInfo)
{ {
int result = 0; int result = -1;
esxVI_String *propertyNameList = NULL; esxVI_String *propertyNameList = NULL;
esxVI_ObjectContent *objectContent = NULL; esxVI_ObjectContent *objectContent = NULL;
esxVI_DynamicProperty *dynamicProperty = NULL; esxVI_DynamicProperty *dynamicProperty = NULL;
...@@ -2433,7 +2399,7 @@ esxVI_LookupTaskInfoByTask(esxVI_Context *ctx, ...@@ -2433,7 +2399,7 @@ esxVI_LookupTaskInfoByTask(esxVI_Context *ctx,
esxVI_LookupObjectContentByType(ctx, task, "Task", propertyNameList, esxVI_LookupObjectContentByType(ctx, task, "Task", propertyNameList,
esxVI_Boolean_False, esxVI_Boolean_False,
&objectContent) < 0) { &objectContent) < 0) {
goto failure; goto cleanup;
} }
for (dynamicProperty = objectContent->propSet; dynamicProperty != NULL; for (dynamicProperty = objectContent->propSet; dynamicProperty != NULL;
...@@ -2441,7 +2407,7 @@ esxVI_LookupTaskInfoByTask(esxVI_Context *ctx, ...@@ -2441,7 +2407,7 @@ esxVI_LookupTaskInfoByTask(esxVI_Context *ctx,
if (STREQ(dynamicProperty->name, "info")) { if (STREQ(dynamicProperty->name, "info")) {
if (esxVI_TaskInfo_CastFromAnyType(dynamicProperty->val, if (esxVI_TaskInfo_CastFromAnyType(dynamicProperty->val,
taskInfo) < 0) { taskInfo) < 0) {
goto failure; goto cleanup;
} }
break; break;
...@@ -2450,16 +2416,13 @@ esxVI_LookupTaskInfoByTask(esxVI_Context *ctx, ...@@ -2450,16 +2416,13 @@ esxVI_LookupTaskInfoByTask(esxVI_Context *ctx,
} }
} }
result = 0;
cleanup: cleanup:
esxVI_String_Free(&propertyNameList); esxVI_String_Free(&propertyNameList);
esxVI_ObjectContent_Free(&objectContent); esxVI_ObjectContent_Free(&objectContent);
return result; return result;
failure:
result = -1;
goto cleanup;
} }
...@@ -2469,7 +2432,7 @@ esxVI_LookupPendingTaskInfoListByVirtualMachine ...@@ -2469,7 +2432,7 @@ esxVI_LookupPendingTaskInfoListByVirtualMachine
(esxVI_Context *ctx, esxVI_ObjectContent *virtualMachine, (esxVI_Context *ctx, esxVI_ObjectContent *virtualMachine,
esxVI_TaskInfo **pendingTaskInfoList) esxVI_TaskInfo **pendingTaskInfoList)
{ {
int result = 0; int result = -1;
esxVI_String *propertyNameList = NULL; esxVI_String *propertyNameList = NULL;
esxVI_ManagedObjectReference *recentTaskList = NULL; esxVI_ManagedObjectReference *recentTaskList = NULL;
esxVI_ManagedObjectReference *recentTask = NULL; esxVI_ManagedObjectReference *recentTask = NULL;
...@@ -2487,7 +2450,7 @@ esxVI_LookupPendingTaskInfoListByVirtualMachine ...@@ -2487,7 +2450,7 @@ esxVI_LookupPendingTaskInfoListByVirtualMachine
if (STREQ(dynamicProperty->name, "recentTask")) { if (STREQ(dynamicProperty->name, "recentTask")) {
if (esxVI_ManagedObjectReference_CastListFromAnyType if (esxVI_ManagedObjectReference_CastListFromAnyType
(dynamicProperty->val, &recentTaskList) < 0) { (dynamicProperty->val, &recentTaskList) < 0) {
goto failure; goto cleanup;
} }
break; break;
...@@ -2498,14 +2461,14 @@ esxVI_LookupPendingTaskInfoListByVirtualMachine ...@@ -2498,14 +2461,14 @@ esxVI_LookupPendingTaskInfoListByVirtualMachine
for (recentTask = recentTaskList; recentTask != NULL; for (recentTask = recentTaskList; recentTask != NULL;
recentTask = recentTask->_next) { recentTask = recentTask->_next) {
if (esxVI_LookupTaskInfoByTask(ctx, recentTask, &taskInfo) < 0) { if (esxVI_LookupTaskInfoByTask(ctx, recentTask, &taskInfo) < 0) {
goto failure; goto cleanup;
} }
if (taskInfo->state == esxVI_TaskInfoState_Queued || if (taskInfo->state == esxVI_TaskInfoState_Queued ||
taskInfo->state == esxVI_TaskInfoState_Running) { taskInfo->state == esxVI_TaskInfoState_Running) {
if (esxVI_TaskInfo_AppendToList(pendingTaskInfoList, if (esxVI_TaskInfo_AppendToList(pendingTaskInfoList,
taskInfo) < 0) { taskInfo) < 0) {
goto failure; goto cleanup;
} }
taskInfo = NULL; taskInfo = NULL;
...@@ -2514,19 +2477,18 @@ esxVI_LookupPendingTaskInfoListByVirtualMachine ...@@ -2514,19 +2477,18 @@ esxVI_LookupPendingTaskInfoListByVirtualMachine
} }
} }
result = 0;
cleanup: cleanup:
if (result < 0) {
esxVI_TaskInfo_Free(pendingTaskInfoList);
}
esxVI_String_Free(&propertyNameList); esxVI_String_Free(&propertyNameList);
esxVI_ManagedObjectReference_Free(&recentTaskList); esxVI_ManagedObjectReference_Free(&recentTaskList);
esxVI_TaskInfo_Free(&taskInfo); esxVI_TaskInfo_Free(&taskInfo);
return result; return result;
failure:
esxVI_TaskInfo_Free(pendingTaskInfoList);
result = -1;
goto cleanup;
} }
...@@ -2536,7 +2498,7 @@ esxVI_LookupAndHandleVirtualMachineQuestion(esxVI_Context *ctx, ...@@ -2536,7 +2498,7 @@ esxVI_LookupAndHandleVirtualMachineQuestion(esxVI_Context *ctx,
const unsigned char *uuid, const unsigned char *uuid,
esxVI_Boolean autoAnswer) esxVI_Boolean autoAnswer)
{ {
int result = 0; int result = -1;
esxVI_ObjectContent *virtualMachine = NULL; esxVI_ObjectContent *virtualMachine = NULL;
esxVI_String *propertyNameList = NULL; esxVI_String *propertyNameList = NULL;
esxVI_VirtualMachineQuestionInfo *questionInfo = NULL; esxVI_VirtualMachineQuestionInfo *questionInfo = NULL;
...@@ -2548,26 +2510,23 @@ esxVI_LookupAndHandleVirtualMachineQuestion(esxVI_Context *ctx, ...@@ -2548,26 +2510,23 @@ esxVI_LookupAndHandleVirtualMachineQuestion(esxVI_Context *ctx,
esxVI_Occurrence_RequiredItem) < 0 || esxVI_Occurrence_RequiredItem) < 0 ||
esxVI_GetVirtualMachineQuestionInfo(virtualMachine, esxVI_GetVirtualMachineQuestionInfo(virtualMachine,
&questionInfo) < 0) { &questionInfo) < 0) {
goto failure; goto cleanup;
} }
if (questionInfo != NULL && if (questionInfo != NULL &&
esxVI_HandleVirtualMachineQuestion(ctx, virtualMachine->obj, esxVI_HandleVirtualMachineQuestion(ctx, virtualMachine->obj,
questionInfo, autoAnswer) < 0) { questionInfo, autoAnswer) < 0) {
goto failure; goto cleanup;
} }
result = 0;
cleanup: cleanup:
esxVI_ObjectContent_Free(&virtualMachine); esxVI_ObjectContent_Free(&virtualMachine);
esxVI_String_Free(&propertyNameList); esxVI_String_Free(&propertyNameList);
esxVI_VirtualMachineQuestionInfo_Free(&questionInfo); esxVI_VirtualMachineQuestionInfo_Free(&questionInfo);
return result; return result;
failure:
result = -1;
goto cleanup;
} }
...@@ -2577,7 +2536,7 @@ esxVI_LookupRootSnapshotTreeList ...@@ -2577,7 +2536,7 @@ esxVI_LookupRootSnapshotTreeList
(esxVI_Context *ctx, const unsigned char *virtualMachineUuid, (esxVI_Context *ctx, const unsigned char *virtualMachineUuid,
esxVI_VirtualMachineSnapshotTree **rootSnapshotTreeList) esxVI_VirtualMachineSnapshotTree **rootSnapshotTreeList)
{ {
int result = 0; int result = -1;
esxVI_String *propertyNameList = NULL; esxVI_String *propertyNameList = NULL;
esxVI_ObjectContent *virtualMachine = NULL; esxVI_ObjectContent *virtualMachine = NULL;
esxVI_DynamicProperty *dynamicProperty = NULL; esxVI_DynamicProperty *dynamicProperty = NULL;
...@@ -2592,7 +2551,7 @@ esxVI_LookupRootSnapshotTreeList ...@@ -2592,7 +2551,7 @@ esxVI_LookupRootSnapshotTreeList
esxVI_LookupVirtualMachineByUuid(ctx, virtualMachineUuid, esxVI_LookupVirtualMachineByUuid(ctx, virtualMachineUuid,
propertyNameList, &virtualMachine, propertyNameList, &virtualMachine,
esxVI_Occurrence_RequiredItem) < 0) { esxVI_Occurrence_RequiredItem) < 0) {
goto failure; goto cleanup;
} }
for (dynamicProperty = virtualMachine->propSet; dynamicProperty != NULL; for (dynamicProperty = virtualMachine->propSet; dynamicProperty != NULL;
...@@ -2600,7 +2559,7 @@ esxVI_LookupRootSnapshotTreeList ...@@ -2600,7 +2559,7 @@ esxVI_LookupRootSnapshotTreeList
if (STREQ(dynamicProperty->name, "snapshot.rootSnapshotList")) { if (STREQ(dynamicProperty->name, "snapshot.rootSnapshotList")) {
if (esxVI_VirtualMachineSnapshotTree_CastListFromAnyType if (esxVI_VirtualMachineSnapshotTree_CastListFromAnyType
(dynamicProperty->val, rootSnapshotTreeList) < 0) { (dynamicProperty->val, rootSnapshotTreeList) < 0) {
goto failure; goto cleanup;
} }
break; break;
...@@ -2609,18 +2568,17 @@ esxVI_LookupRootSnapshotTreeList ...@@ -2609,18 +2568,17 @@ esxVI_LookupRootSnapshotTreeList
} }
} }
result = 0;
cleanup: cleanup:
if (result < 0) {
esxVI_VirtualMachineSnapshotTree_Free(rootSnapshotTreeList);
}
esxVI_String_Free(&propertyNameList); esxVI_String_Free(&propertyNameList);
esxVI_ObjectContent_Free(&virtualMachine); esxVI_ObjectContent_Free(&virtualMachine);
return result; return result;
failure:
esxVI_VirtualMachineSnapshotTree_Free(rootSnapshotTreeList);
result = -1;
goto cleanup;
} }
...@@ -2631,7 +2589,7 @@ esxVI_LookupCurrentSnapshotTree ...@@ -2631,7 +2589,7 @@ esxVI_LookupCurrentSnapshotTree
esxVI_VirtualMachineSnapshotTree **currentSnapshotTree, esxVI_VirtualMachineSnapshotTree **currentSnapshotTree,
esxVI_Occurrence occurrence) esxVI_Occurrence occurrence)
{ {
int result = 0; int result = -1;
esxVI_String *propertyNameList = NULL; esxVI_String *propertyNameList = NULL;
esxVI_ObjectContent *virtualMachine = NULL; esxVI_ObjectContent *virtualMachine = NULL;
esxVI_DynamicProperty *dynamicProperty = NULL; esxVI_DynamicProperty *dynamicProperty = NULL;
...@@ -2650,7 +2608,7 @@ esxVI_LookupCurrentSnapshotTree ...@@ -2650,7 +2608,7 @@ esxVI_LookupCurrentSnapshotTree
esxVI_LookupVirtualMachineByUuid(ctx, virtualMachineUuid, esxVI_LookupVirtualMachineByUuid(ctx, virtualMachineUuid,
propertyNameList, &virtualMachine, propertyNameList, &virtualMachine,
esxVI_Occurrence_RequiredItem) < 0) { esxVI_Occurrence_RequiredItem) < 0) {
goto failure; goto cleanup;
} }
for (dynamicProperty = virtualMachine->propSet; dynamicProperty != NULL; for (dynamicProperty = virtualMachine->propSet; dynamicProperty != NULL;
...@@ -2658,12 +2616,12 @@ esxVI_LookupCurrentSnapshotTree ...@@ -2658,12 +2616,12 @@ esxVI_LookupCurrentSnapshotTree
if (STREQ(dynamicProperty->name, "snapshot.currentSnapshot")) { if (STREQ(dynamicProperty->name, "snapshot.currentSnapshot")) {
if (esxVI_ManagedObjectReference_CastFromAnyType if (esxVI_ManagedObjectReference_CastFromAnyType
(dynamicProperty->val, &currentSnapshot) < 0) { (dynamicProperty->val, &currentSnapshot) < 0) {
goto failure; goto cleanup;
} }
} else if (STREQ(dynamicProperty->name, "snapshot.rootSnapshotList")) { } else if (STREQ(dynamicProperty->name, "snapshot.rootSnapshotList")) {
if (esxVI_VirtualMachineSnapshotTree_CastListFromAnyType if (esxVI_VirtualMachineSnapshotTree_CastListFromAnyType
(dynamicProperty->val, &rootSnapshotTreeList) < 0) { (dynamicProperty->val, &rootSnapshotTreeList) < 0) {
goto failure; goto cleanup;
} }
} else { } else {
VIR_WARN("Unexpected '%s' property", dynamicProperty->name); VIR_WARN("Unexpected '%s' property", dynamicProperty->name);
...@@ -2676,23 +2634,25 @@ esxVI_LookupCurrentSnapshotTree ...@@ -2676,23 +2634,25 @@ esxVI_LookupCurrentSnapshotTree
} else { } else {
ESX_VI_ERROR(VIR_ERR_NO_DOMAIN_SNAPSHOT, "%s", ESX_VI_ERROR(VIR_ERR_NO_DOMAIN_SNAPSHOT, "%s",
_("Domain has no current snapshot")); _("Domain has no current snapshot"));
goto failure; goto cleanup;
} }
} }
if (rootSnapshotTreeList == NULL) { if (rootSnapshotTreeList == NULL) {
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
_("Could not lookup root snapshot list")); _("Could not lookup root snapshot list"));
goto failure; goto cleanup;
} }
if (esxVI_GetSnapshotTreeBySnapshot(rootSnapshotTreeList, currentSnapshot, if (esxVI_GetSnapshotTreeBySnapshot(rootSnapshotTreeList, currentSnapshot,
&snapshotTree) < 0 || &snapshotTree) < 0 ||
esxVI_VirtualMachineSnapshotTree_DeepCopy(currentSnapshotTree, esxVI_VirtualMachineSnapshotTree_DeepCopy(currentSnapshotTree,
snapshotTree) < 0) { snapshotTree) < 0) {
goto failure; goto cleanup;
} }
result = 0;
cleanup: cleanup:
esxVI_String_Free(&propertyNameList); esxVI_String_Free(&propertyNameList);
esxVI_ObjectContent_Free(&virtualMachine); esxVI_ObjectContent_Free(&virtualMachine);
...@@ -2700,11 +2660,6 @@ esxVI_LookupCurrentSnapshotTree ...@@ -2700,11 +2660,6 @@ esxVI_LookupCurrentSnapshotTree
esxVI_VirtualMachineSnapshotTree_Free(&rootSnapshotTreeList); esxVI_VirtualMachineSnapshotTree_Free(&rootSnapshotTreeList);
return result; return result;
failure:
result = -1;
goto cleanup;
} }
...@@ -2715,7 +2670,7 @@ esxVI_HandleVirtualMachineQuestion ...@@ -2715,7 +2670,7 @@ esxVI_HandleVirtualMachineQuestion
esxVI_VirtualMachineQuestionInfo *questionInfo, esxVI_VirtualMachineQuestionInfo *questionInfo,
esxVI_Boolean autoAnswer) esxVI_Boolean autoAnswer)
{ {
int result = 0; int result = -1;
esxVI_ElementDescription *elementDescription = NULL; esxVI_ElementDescription *elementDescription = NULL;
virBuffer buffer = VIR_BUFFER_INITIALIZER; virBuffer buffer = VIR_BUFFER_INITIALIZER;
esxVI_ElementDescription *answerChoice = NULL; esxVI_ElementDescription *answerChoice = NULL;
...@@ -2743,7 +2698,7 @@ esxVI_HandleVirtualMachineQuestion ...@@ -2743,7 +2698,7 @@ esxVI_HandleVirtualMachineQuestion
if (virBufferError(&buffer)) { if (virBufferError(&buffer)) {
virReportOOMError(); virReportOOMError();
goto failure; goto cleanup;
} }
possibleAnswers = virBufferContentAndReset(&buffer); possibleAnswers = virBufferContentAndReset(&buffer);
...@@ -2755,14 +2710,14 @@ esxVI_HandleVirtualMachineQuestion ...@@ -2755,14 +2710,14 @@ esxVI_HandleVirtualMachineQuestion
_("Pending question blocks virtual machine execution, " _("Pending question blocks virtual machine execution, "
"question is '%s', no possible answers"), "question is '%s', no possible answers"),
questionInfo->text); questionInfo->text);
goto failure; goto cleanup;
} else if (answerChoice == NULL) { } else if (answerChoice == NULL) {
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Pending question blocks virtual machine execution, " _("Pending question blocks virtual machine execution, "
"question is '%s', possible answers are %s, but no " "question is '%s', possible answers are %s, but no "
"default answer is specified"), questionInfo->text, "default answer is specified"), questionInfo->text,
possibleAnswers); possibleAnswers);
goto failure; goto cleanup;
} }
VIR_INFO("Pending question blocks virtual machine execution, " VIR_INFO("Pending question blocks virtual machine execution, "
...@@ -2772,7 +2727,7 @@ esxVI_HandleVirtualMachineQuestion ...@@ -2772,7 +2727,7 @@ esxVI_HandleVirtualMachineQuestion
if (esxVI_AnswerVM(ctx, virtualMachine, questionInfo->id, if (esxVI_AnswerVM(ctx, virtualMachine, questionInfo->id,
answerChoice->key) < 0) { answerChoice->key) < 0) {
goto failure; goto cleanup;
} }
} else { } else {
if (possibleAnswers != NULL) { if (possibleAnswers != NULL) {
...@@ -2787,20 +2742,19 @@ esxVI_HandleVirtualMachineQuestion ...@@ -2787,20 +2742,19 @@ esxVI_HandleVirtualMachineQuestion
questionInfo->text); questionInfo->text);
} }
goto failure; goto cleanup;
} }
result = 0;
cleanup: cleanup:
if (result < 0) {
virBufferFreeAndReset(&buffer);
}
VIR_FREE(possibleAnswers); VIR_FREE(possibleAnswers);
return result; return result;
failure:
virBufferFreeAndReset(&buffer);
result = -1;
goto cleanup;
} }
...@@ -2812,7 +2766,7 @@ esxVI_WaitForTaskCompletion(esxVI_Context *ctx, ...@@ -2812,7 +2766,7 @@ esxVI_WaitForTaskCompletion(esxVI_Context *ctx,
esxVI_Boolean autoAnswer, esxVI_Boolean autoAnswer,
esxVI_TaskInfoState *finalState) esxVI_TaskInfoState *finalState)
{ {
int result = 0; int result = -1;
esxVI_ObjectSpec *objectSpec = NULL; esxVI_ObjectSpec *objectSpec = NULL;
esxVI_PropertySpec *propertySpec = NULL; esxVI_PropertySpec *propertySpec = NULL;
esxVI_PropertyFilterSpec *propertyFilterSpec = NULL; esxVI_PropertyFilterSpec *propertyFilterSpec = NULL;
...@@ -2830,18 +2784,18 @@ esxVI_WaitForTaskCompletion(esxVI_Context *ctx, ...@@ -2830,18 +2784,18 @@ esxVI_WaitForTaskCompletion(esxVI_Context *ctx,
if (version == NULL) { if (version == NULL) {
virReportOOMError(); virReportOOMError();
goto failure; return -1;
} }
if (esxVI_ObjectSpec_Alloc(&objectSpec) < 0) { if (esxVI_ObjectSpec_Alloc(&objectSpec) < 0) {
goto failure; goto cleanup;
} }
objectSpec->obj = task; objectSpec->obj = task;
objectSpec->skip = esxVI_Boolean_False; objectSpec->skip = esxVI_Boolean_False;
if (esxVI_PropertySpec_Alloc(&propertySpec) < 0) { if (esxVI_PropertySpec_Alloc(&propertySpec) < 0) {
goto failure; goto cleanup;
} }
propertySpec->type = task->type; propertySpec->type = task->type;
...@@ -2855,7 +2809,7 @@ esxVI_WaitForTaskCompletion(esxVI_Context *ctx, ...@@ -2855,7 +2809,7 @@ esxVI_WaitForTaskCompletion(esxVI_Context *ctx,
objectSpec) < 0 || objectSpec) < 0 ||
esxVI_CreateFilter(ctx, propertyFilterSpec, esxVI_Boolean_True, esxVI_CreateFilter(ctx, propertyFilterSpec, esxVI_Boolean_True,
&propertyFilter) < 0) { &propertyFilter) < 0) {
goto failure; goto cleanup;
} }
while (state != esxVI_TaskInfoState_Success && while (state != esxVI_TaskInfoState_Success &&
...@@ -2871,7 +2825,7 @@ esxVI_WaitForTaskCompletion(esxVI_Context *ctx, ...@@ -2871,7 +2825,7 @@ esxVI_WaitForTaskCompletion(esxVI_Context *ctx,
* don't overwrite the actual error * don't overwrite the actual error
*/ */
if (esxVI_LookupTaskInfoByTask(ctx, task, &taskInfo)) { if (esxVI_LookupTaskInfoByTask(ctx, task, &taskInfo)) {
goto failure; goto cleanup;
} }
if (taskInfo->cancelable == esxVI_Boolean_True) { if (taskInfo->cancelable == esxVI_Boolean_True) {
...@@ -2887,12 +2841,12 @@ esxVI_WaitForTaskCompletion(esxVI_Context *ctx, ...@@ -2887,12 +2841,12 @@ esxVI_WaitForTaskCompletion(esxVI_Context *ctx,
/* FIXME: Enable error reporting here again */ /* FIXME: Enable error reporting here again */
goto failure; goto cleanup;
} }
} }
if (esxVI_WaitForUpdates(ctx, version, &updateSet) < 0) { if (esxVI_WaitForUpdates(ctx, version, &updateSet) < 0) {
goto failure; goto cleanup;
} }
VIR_FREE(version); VIR_FREE(version);
...@@ -2900,7 +2854,7 @@ esxVI_WaitForTaskCompletion(esxVI_Context *ctx, ...@@ -2900,7 +2854,7 @@ esxVI_WaitForTaskCompletion(esxVI_Context *ctx,
if (version == NULL) { if (version == NULL) {
virReportOOMError(); virReportOOMError();
goto failure; goto cleanup;
} }
if (updateSet->filterSet == NULL) { if (updateSet->filterSet == NULL) {
...@@ -2932,7 +2886,7 @@ esxVI_WaitForTaskCompletion(esxVI_Context *ctx, ...@@ -2932,7 +2886,7 @@ esxVI_WaitForTaskCompletion(esxVI_Context *ctx,
} }
if (esxVI_TaskInfoState_CastFromAnyType(propertyValue, &state) < 0) { if (esxVI_TaskInfoState_CastFromAnyType(propertyValue, &state) < 0) {
goto failure; goto cleanup;
} }
} }
...@@ -2941,9 +2895,11 @@ esxVI_WaitForTaskCompletion(esxVI_Context *ctx, ...@@ -2941,9 +2895,11 @@ esxVI_WaitForTaskCompletion(esxVI_Context *ctx,
} }
if (esxVI_TaskInfoState_CastFromAnyType(propertyValue, finalState) < 0) { if (esxVI_TaskInfoState_CastFromAnyType(propertyValue, finalState) < 0) {
goto failure; goto cleanup;
} }
result = 0;
cleanup: cleanup:
/* /*
* Remove values given by the caller from the data structures to prevent * Remove values given by the caller from the data structures to prevent
...@@ -2964,11 +2920,6 @@ esxVI_WaitForTaskCompletion(esxVI_Context *ctx, ...@@ -2964,11 +2920,6 @@ esxVI_WaitForTaskCompletion(esxVI_Context *ctx,
esxVI_TaskInfo_Free(&taskInfo); esxVI_TaskInfo_Free(&taskInfo);
return result; return result;
failure:
result = -1;
goto cleanup;
} }
...@@ -2994,7 +2945,7 @@ esxVI_ParseHostCpuIdInfo(esxVI_ParsedHostCpuIdInfo *parsedHostCpuIdInfo, ...@@ -2994,7 +2945,7 @@ esxVI_ParseHostCpuIdInfo(esxVI_ParsedHostCpuIdInfo *parsedHostCpuIdInfo,
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
_("HostCpuIdInfo register '%s' has an unexpected length"), _("HostCpuIdInfo register '%s' has an unexpected length"),
name[r]); name[r]);
goto failure; return -1;
} }
/* Strip the ':' and invert the "bit" order from 31..0 to 0..31 */ /* Strip the ':' and invert the "bit" order from 31..0 to 0..31 */
...@@ -3008,15 +2959,10 @@ esxVI_ParseHostCpuIdInfo(esxVI_ParsedHostCpuIdInfo *parsedHostCpuIdInfo, ...@@ -3008,15 +2959,10 @@ esxVI_ParseHostCpuIdInfo(esxVI_ParsedHostCpuIdInfo *parsedHostCpuIdInfo,
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
_("HostCpuIdInfo register '%s' has an unexpected format"), _("HostCpuIdInfo register '%s' has an unexpected format"),
name[r]); name[r]);
goto failure; return -1;
} }
} }
} }
return 0; return 0;
failure:
memset(parsedHostCpuIdInfo, 0, sizeof (*parsedHostCpuIdInfo));
return -1;
} }
...@@ -74,14 +74,14 @@ ...@@ -74,14 +74,14 @@
#define ESX_VI__METHOD__DESERIALIZE_OUTPUT__RequiredItem(_type) \ #define ESX_VI__METHOD__DESERIALIZE_OUTPUT__RequiredItem(_type) \
if (esxVI_##_type##_Deserialize(response->node, output) < 0) { \ if (esxVI_##_type##_Deserialize(response->node, output) < 0) { \
goto failure; \ goto cleanup; \
} }
#define ESX_VI__METHOD__DESERIALIZE_OUTPUT__RequiredList(_type) \ #define ESX_VI__METHOD__DESERIALIZE_OUTPUT__RequiredList(_type) \
if (esxVI_##_type##_DeserializeList(response->node, output) < 0) { \ if (esxVI_##_type##_DeserializeList(response->node, output) < 0) { \
goto failure; \ goto cleanup; \
} }
...@@ -89,7 +89,7 @@ ...@@ -89,7 +89,7 @@
#define ESX_VI__METHOD__DESERIALIZE_OUTPUT__OptionalItem(_type) \ #define ESX_VI__METHOD__DESERIALIZE_OUTPUT__OptionalItem(_type) \
if (response->node != NULL && \ if (response->node != NULL && \
esxVI_##_type##_Deserialize(response->node, output) < 0) { \ esxVI_##_type##_Deserialize(response->node, output) < 0) { \
goto failure; \ goto cleanup; \
} }
...@@ -97,7 +97,7 @@ ...@@ -97,7 +97,7 @@
#define ESX_VI__METHOD__DESERIALIZE_OUTPUT__OptionalList(_type) \ #define ESX_VI__METHOD__DESERIALIZE_OUTPUT__OptionalList(_type) \
if (response->node != NULL && \ if (response->node != NULL && \
esxVI_##_type##_DeserializeList(response->node, output) < 0) { \ esxVI_##_type##_DeserializeList(response->node, output) < 0) { \
goto failure; \ goto cleanup; \
} }
...@@ -107,7 +107,7 @@ ...@@ -107,7 +107,7 @@
int \ int \
esxVI_##_name _parameters \ esxVI_##_name _parameters \
{ \ { \
int result = 0; \ int result = -1; \
const char *methodName = #_name; \ const char *methodName = #_name; \
virBuffer buffer = VIR_BUFFER_INITIALIZER; \ virBuffer buffer = VIR_BUFFER_INITIALIZER; \
char *request = NULL; \ char *request = NULL; \
...@@ -129,30 +129,29 @@ ...@@ -129,30 +129,29 @@
\ \
if (virBufferError(&buffer)) { \ if (virBufferError(&buffer)) { \
virReportOOMError(); \ virReportOOMError(); \
goto failure; \ goto cleanup; \
} \ } \
\ \
request = virBufferContentAndReset(&buffer); \ request = virBufferContentAndReset(&buffer); \
\ \
if (esxVI_Context_Execute(ctx, methodName, request, &response, \ if (esxVI_Context_Execute(ctx, methodName, request, &response, \
esxVI_Occurrence_##_occurrence) < 0) { \ esxVI_Occurrence_##_occurrence) < 0) { \
goto failure; \ goto cleanup; \
} \ } \
\ \
ESX_VI__METHOD__DESERIALIZE_OUTPUT__##_occurrence(_output_type) \ ESX_VI__METHOD__DESERIALIZE_OUTPUT__##_occurrence(_output_type) \
\ \
result = 0; \
\
cleanup: \ cleanup: \
if (result < 0) { \
virBufferFreeAndReset(&buffer); \
} \
\
VIR_FREE(request); \ VIR_FREE(request); \
esxVI_Response_Free(&response); \ esxVI_Response_Free(&response); \
\ \
return result; \ return result; \
\
failure: \
virBufferFreeAndReset(&buffer); \
\
result = -1; \
\
goto cleanup; \
} }
...@@ -216,21 +215,21 @@ ...@@ -216,21 +215,21 @@
#define ESX_VI__METHOD__PARAMETER__SERIALIZE(_type, _name) \ #define ESX_VI__METHOD__PARAMETER__SERIALIZE(_type, _name) \
if (esxVI_##_type##_Serialize(_name, #_name, &buffer) < 0) { \ if (esxVI_##_type##_Serialize(_name, #_name, &buffer) < 0) { \
goto failure; \ goto cleanup; \
} }
#define ESX_VI__METHOD__PARAMETER__SERIALIZE_LIST(_type, _name) \ #define ESX_VI__METHOD__PARAMETER__SERIALIZE_LIST(_type, _name) \
if (esxVI_##_type##_SerializeList(_name, #_name, &buffer) < 0) { \ if (esxVI_##_type##_SerializeList(_name, #_name, &buffer) < 0) { \
goto failure; \ goto cleanup; \
} }
#define ESX_VI__METHOD__PARAMETER__SERIALIZE_VALUE(_type, _name) \ #define ESX_VI__METHOD__PARAMETER__SERIALIZE_VALUE(_type, _name) \
if (esxVI_##_type##_SerializeValue(_name, #_name, &buffer) < 0) { \ if (esxVI_##_type##_SerializeValue(_name, #_name, &buffer) < 0) { \
goto failure; \ goto cleanup; \
} }
...@@ -243,7 +242,7 @@ int ...@@ -243,7 +242,7 @@ int
esxVI_RetrieveServiceContent(esxVI_Context *ctx, esxVI_RetrieveServiceContent(esxVI_Context *ctx,
esxVI_ServiceContent **serviceContent) esxVI_ServiceContent **serviceContent)
{ {
int result = 0; int result = -1;
const char *request = ESX_VI__SOAP__REQUEST_HEADER const char *request = ESX_VI__SOAP__REQUEST_HEADER
"<RetrieveServiceContent xmlns=\"urn:vim25\">" "<RetrieveServiceContent xmlns=\"urn:vim25\">"
"<_this xmlns=\"urn:vim25\" " "<_this xmlns=\"urn:vim25\" "
...@@ -263,18 +262,15 @@ esxVI_RetrieveServiceContent(esxVI_Context *ctx, ...@@ -263,18 +262,15 @@ esxVI_RetrieveServiceContent(esxVI_Context *ctx,
if (esxVI_Context_Execute(ctx, "RetrieveServiceContent", request, if (esxVI_Context_Execute(ctx, "RetrieveServiceContent", request,
&response, esxVI_Occurrence_RequiredItem) < 0 || &response, esxVI_Occurrence_RequiredItem) < 0 ||
esxVI_ServiceContent_Deserialize(response->node, serviceContent) < 0) { esxVI_ServiceContent_Deserialize(response->node, serviceContent) < 0) {
goto failure; goto cleanup;
} }
result = 0;
cleanup: cleanup:
esxVI_Response_Free(&response); esxVI_Response_Free(&response);
return result; return result;
failure:
result = -1;
goto cleanup;
} }
......
...@@ -297,7 +297,7 @@ ...@@ -297,7 +297,7 @@
int \ int \
esxVI_##_type##_Deserialize(xmlNodePtr node, esxVI_##_type **number) \ esxVI_##_type##_Deserialize(xmlNodePtr node, esxVI_##_type **number) \
{ \ { \
int result = 0; \ int result = -1; \
char *string; \ char *string; \
long long value; \ long long value; \
\ \
...@@ -317,35 +317,34 @@ ...@@ -317,35 +317,34 @@
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, \ ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, \
"XML node doesn't contain text, expecting an " \ "XML node doesn't contain text, expecting an " \
_xsdType" value"); \ _xsdType" value"); \
goto failure; \ goto cleanup; \
} \ } \
\ \
if (virStrToLong_ll(string, NULL, 10, &value) < 0) { \ if (virStrToLong_ll(string, NULL, 10, &value) < 0) { \
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, \ ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, \
"Unknown value '%s' for "_xsdType, string); \ "Unknown value '%s' for "_xsdType, string); \
goto failure; \ goto cleanup; \
} \ } \
\ \
if (value < (_min) || value > (_max)) { \ if (value < (_min) || value > (_max)) { \
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, \ ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, \
"Value '%s' is not representable as "_xsdType, \ "Value '%s' is not representable as "_xsdType, \
(const char *)string); \ (const char *)string); \
goto failure; \ goto cleanup; \
} \ } \
\ \
(*number)->value = value; \ (*number)->value = value; \
\ \
result = 0; \
\
cleanup: \ cleanup: \
if (result < 0) { \
esxVI_##_type##_Free(number); \
} \
\
VIR_FREE(string); \ VIR_FREE(string); \
\ \
return result; \ return result; \
\
failure: \
esxVI_##_type##_Free(number); \
\
result = -1; \
\
goto cleanup; \
} }
...@@ -930,7 +929,7 @@ esxVI_String_AppendValueToList(esxVI_String **stringList, const char *value) ...@@ -930,7 +929,7 @@ esxVI_String_AppendValueToList(esxVI_String **stringList, const char *value)
esxVI_String *string = NULL; esxVI_String *string = NULL;
if (esxVI_String_Alloc(&string) < 0) { if (esxVI_String_Alloc(&string) < 0) {
goto failure; return -1;
} }
string->value = strdup(value); string->value = strdup(value);
......
...@@ -590,6 +590,7 @@ char * ...@@ -590,6 +590,7 @@ char *
esxVMX_AbsolutePathToDatastoreRelatedPath(esxVI_Context *ctx, esxVMX_AbsolutePathToDatastoreRelatedPath(esxVI_Context *ctx,
const char *absolutePath) const char *absolutePath)
{ {
bool success = false;
char *copyOfAbsolutePath = NULL; char *copyOfAbsolutePath = NULL;
char *tmp = NULL; char *tmp = NULL;
char *saveptr = NULL; char *saveptr = NULL;
...@@ -601,7 +602,7 @@ esxVMX_AbsolutePathToDatastoreRelatedPath(esxVI_Context *ctx, ...@@ -601,7 +602,7 @@ esxVMX_AbsolutePathToDatastoreRelatedPath(esxVI_Context *ctx,
const char *datastoreName = NULL; const char *datastoreName = NULL;
if (esxVI_String_DeepCopyValue(&copyOfAbsolutePath, absolutePath) < 0) { if (esxVI_String_DeepCopyValue(&copyOfAbsolutePath, absolutePath) < 0) {
goto failure; return NULL;
} }
/* Expected format: '/vmfs/volumes/<datastore>/<path>' */ /* Expected format: '/vmfs/volumes/<datastore>/<path>' */
...@@ -611,14 +612,14 @@ esxVMX_AbsolutePathToDatastoreRelatedPath(esxVI_Context *ctx, ...@@ -611,14 +612,14 @@ esxVMX_AbsolutePathToDatastoreRelatedPath(esxVI_Context *ctx,
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Absolute path '%s' doesn't have expected format " _("Absolute path '%s' doesn't have expected format "
"'/vmfs/volumes/<datastore>/<path>'"), absolutePath); "'/vmfs/volumes/<datastore>/<path>'"), absolutePath);
goto failure; goto cleanup;
} }
if (ctx != NULL) { if (ctx != NULL) {
if (esxVI_LookupDatastoreByName(ctx, preliminaryDatastoreName, if (esxVI_LookupDatastoreByName(ctx, preliminaryDatastoreName,
NULL, &datastore, NULL, &datastore,
esxVI_Occurrence_OptionalItem) < 0) { esxVI_Occurrence_OptionalItem) < 0) {
goto failure; goto cleanup;
} }
if (datastore != NULL) { if (datastore != NULL) {
...@@ -629,7 +630,7 @@ esxVMX_AbsolutePathToDatastoreRelatedPath(esxVI_Context *ctx, ...@@ -629,7 +630,7 @@ esxVMX_AbsolutePathToDatastoreRelatedPath(esxVI_Context *ctx,
} else if (STREQ(dynamicProperty->name, "summary.name")) { } else if (STREQ(dynamicProperty->name, "summary.name")) {
if (esxVI_AnyType_ExpectType(dynamicProperty->val, if (esxVI_AnyType_ExpectType(dynamicProperty->val,
esxVI_Type_String) < 0) { esxVI_Type_String) < 0) {
goto failure; goto cleanup;
} }
datastoreName = dynamicProperty->val->string; datastoreName = dynamicProperty->val->string;
...@@ -656,21 +657,22 @@ esxVMX_AbsolutePathToDatastoreRelatedPath(esxVI_Context *ctx, ...@@ -656,21 +657,22 @@ esxVMX_AbsolutePathToDatastoreRelatedPath(esxVI_Context *ctx,
if (virAsprintf(&datastoreRelatedPath, "[%s] %s", datastoreName, if (virAsprintf(&datastoreRelatedPath, "[%s] %s", datastoreName,
directoryAndFileName) < 0) { directoryAndFileName) < 0) {
virReportOOMError(); virReportOOMError();
goto failure; goto cleanup;
} }
/* FIXME: Check if referenced path/file really exists */ /* FIXME: Check if referenced path/file really exists */
success = true;
cleanup: cleanup:
if (! success) {
VIR_FREE(datastoreRelatedPath);
}
VIR_FREE(copyOfAbsolutePath); VIR_FREE(copyOfAbsolutePath);
esxVI_ObjectContent_Free(&datastore); esxVI_ObjectContent_Free(&datastore);
return datastoreRelatedPath; return datastoreRelatedPath;
failure:
VIR_FREE(datastoreRelatedPath);
goto cleanup;
} }
...@@ -727,6 +729,7 @@ esxVMX_ParseConfig(esxVI_Context *ctx, const char *vmx, ...@@ -727,6 +729,7 @@ esxVMX_ParseConfig(esxVI_Context *ctx, const char *vmx,
const char *datastoreName, const char *directoryName, const char *datastoreName, const char *directoryName,
esxVI_ProductVersion productVersion) esxVI_ProductVersion productVersion)
{ {
bool success = false;
virConfPtr conf = NULL; virConfPtr conf = NULL;
virDomainDefPtr def = NULL; virDomainDefPtr def = NULL;
long long config_version = 0; long long config_version = 0;
...@@ -750,7 +753,7 @@ esxVMX_ParseConfig(esxVI_Context *ctx, const char *vmx, ...@@ -750,7 +753,7 @@ esxVMX_ParseConfig(esxVI_Context *ctx, const char *vmx,
if (VIR_ALLOC(def) < 0) { if (VIR_ALLOC(def) < 0) {
virReportOOMError(); virReportOOMError();
goto failure; return NULL;
} }
def->virtType = VIR_DOMAIN_VIRT_VMWARE; /* FIXME: maybe add VIR_DOMAIN_VIRT_ESX ? */ def->virtType = VIR_DOMAIN_VIRT_VMWARE; /* FIXME: maybe add VIR_DOMAIN_VIRT_ESX ? */
...@@ -759,20 +762,20 @@ esxVMX_ParseConfig(esxVI_Context *ctx, const char *vmx, ...@@ -759,20 +762,20 @@ esxVMX_ParseConfig(esxVI_Context *ctx, const char *vmx,
/* vmx:config.version */ /* vmx:config.version */
if (esxUtil_GetConfigLong(conf, "config.version", &config_version, 0, if (esxUtil_GetConfigLong(conf, "config.version", &config_version, 0,
0) < 0) { 0) < 0) {
goto failure; goto cleanup;
} }
if (config_version != 8) { if (config_version != 8) {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Expecting VMX entry 'config.version' to be 8 but found " _("Expecting VMX entry 'config.version' to be 8 but found "
"%lld"), config_version); "%lld"), config_version);
goto failure; goto cleanup;
} }
/* vmx:virtualHW.version */ /* vmx:virtualHW.version */
if (esxUtil_GetConfigLong(conf, "virtualHW.version", &virtualHW_version, 0, if (esxUtil_GetConfigLong(conf, "virtualHW.version", &virtualHW_version, 0,
0) < 0) { 0) < 0) {
goto failure; goto cleanup;
} }
/* /*
...@@ -790,7 +793,7 @@ esxVMX_ParseConfig(esxVI_Context *ctx, const char *vmx, ...@@ -790,7 +793,7 @@ esxVMX_ParseConfig(esxVI_Context *ctx, const char *vmx,
_("Expecting VMX entry 'virtualHW.version' to be 4 " _("Expecting VMX entry 'virtualHW.version' to be 4 "
"but found %lld"), "but found %lld"),
virtualHW_version); virtualHW_version);
goto failure; goto cleanup;
} }
break; break;
...@@ -802,7 +805,7 @@ esxVMX_ParseConfig(esxVI_Context *ctx, const char *vmx, ...@@ -802,7 +805,7 @@ esxVMX_ParseConfig(esxVI_Context *ctx, const char *vmx,
_("Expecting VMX entry 'virtualHW.version' to be 4 or 7 " _("Expecting VMX entry 'virtualHW.version' to be 4 or 7 "
"but found %lld"), "but found %lld"),
virtualHW_version); virtualHW_version);
goto failure; goto cleanup;
} }
break; break;
...@@ -810,37 +813,37 @@ esxVMX_ParseConfig(esxVI_Context *ctx, const char *vmx, ...@@ -810,37 +813,37 @@ esxVMX_ParseConfig(esxVI_Context *ctx, const char *vmx,
default: default:
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
_("Unexpected product version")); _("Unexpected product version"));
goto failure; goto cleanup;
} }
/* vmx:uuid.bios -> def:uuid */ /* vmx:uuid.bios -> def:uuid */
/* FIXME: Need to handle 'uuid.action = "create"' */ /* FIXME: Need to handle 'uuid.action = "create"' */
if (esxUtil_GetConfigUUID(conf, "uuid.bios", def->uuid, 1) < 0) { if (esxUtil_GetConfigUUID(conf, "uuid.bios", def->uuid, 1) < 0) {
goto failure; goto cleanup;
} }
/* vmx:displayName -> def:name */ /* vmx:displayName -> def:name */
if (esxUtil_GetConfigString(conf, "displayName", &def->name, 1) < 0) { if (esxUtil_GetConfigString(conf, "displayName", &def->name, 1) < 0) {
goto failure; goto cleanup;
} }
/* vmx:memsize -> def:maxmem */ /* vmx:memsize -> def:maxmem */
if (esxUtil_GetConfigLong(conf, "memsize", &memsize, 32, 1) < 0) { if (esxUtil_GetConfigLong(conf, "memsize", &memsize, 32, 1) < 0) {
goto failure; goto cleanup;
} }
if (memsize <= 0 || memsize % 4 != 0) { if (memsize <= 0 || memsize % 4 != 0) {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Expecting VMX entry 'memsize' to be an unsigned " _("Expecting VMX entry 'memsize' to be an unsigned "
"integer (multiple of 4) but found %lld"), memsize); "integer (multiple of 4) but found %lld"), memsize);
goto failure; goto cleanup;
} }
def->maxmem = memsize * 1024; /* Scale from megabytes to kilobytes */ def->maxmem = memsize * 1024; /* Scale from megabytes to kilobytes */
/* vmx:sched.mem.max -> def:memory */ /* vmx:sched.mem.max -> def:memory */
if (esxUtil_GetConfigLong(conf, "sched.mem.max", &memory, memsize, 1) < 0) { if (esxUtil_GetConfigLong(conf, "sched.mem.max", &memory, memsize, 1) < 0) {
goto failure; goto cleanup;
} }
if (memory < 0) { if (memory < 0) {
...@@ -855,14 +858,14 @@ esxVMX_ParseConfig(esxVI_Context *ctx, const char *vmx, ...@@ -855,14 +858,14 @@ esxVMX_ParseConfig(esxVI_Context *ctx, const char *vmx,
/* vmx:numvcpus -> def:vcpus */ /* vmx:numvcpus -> def:vcpus */
if (esxUtil_GetConfigLong(conf, "numvcpus", &numvcpus, 1, 1) < 0) { if (esxUtil_GetConfigLong(conf, "numvcpus", &numvcpus, 1, 1) < 0) {
goto failure; goto cleanup;
} }
if (numvcpus <= 0 || (numvcpus % 2 != 0 && numvcpus != 1)) { if (numvcpus <= 0 || (numvcpus % 2 != 0 && numvcpus != 1)) {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Expecting VMX entry 'numvcpus' to be an unsigned " _("Expecting VMX entry 'numvcpus' to be an unsigned "
"integer (1 or a multiple of 2) but found %lld"), numvcpus); "integer (1 or a multiple of 2) but found %lld"), numvcpus);
goto failure; goto cleanup;
} }
def->vcpus = numvcpus; def->vcpus = numvcpus;
...@@ -871,7 +874,7 @@ esxVMX_ParseConfig(esxVI_Context *ctx, const char *vmx, ...@@ -871,7 +874,7 @@ esxVMX_ParseConfig(esxVI_Context *ctx, const char *vmx,
// VirtualMachine:config.cpuAffinity.affinitySet // VirtualMachine:config.cpuAffinity.affinitySet
if (esxUtil_GetConfigString(conf, "sched.cpu.affinity", &sched_cpu_affinity, if (esxUtil_GetConfigString(conf, "sched.cpu.affinity", &sched_cpu_affinity,
1) < 0) { 1) < 0) {
goto failure; goto cleanup;
} }
if (sched_cpu_affinity != NULL && STRNEQ(sched_cpu_affinity, "all")) { if (sched_cpu_affinity != NULL && STRNEQ(sched_cpu_affinity, "all")) {
...@@ -882,7 +885,7 @@ esxVMX_ParseConfig(esxVI_Context *ctx, const char *vmx, ...@@ -882,7 +885,7 @@ esxVMX_ParseConfig(esxVI_Context *ctx, const char *vmx,
if (VIR_ALLOC_N(def->cpumask, VIR_DOMAIN_CPUMASK_LEN) < 0) { if (VIR_ALLOC_N(def->cpumask, VIR_DOMAIN_CPUMASK_LEN) < 0) {
virReportOOMError(); virReportOOMError();
goto failure; goto cleanup;
} }
while (*current != '\0') { while (*current != '\0') {
...@@ -895,14 +898,14 @@ esxVMX_ParseConfig(esxVI_Context *ctx, const char *vmx, ...@@ -895,14 +898,14 @@ esxVMX_ParseConfig(esxVI_Context *ctx, const char *vmx,
_("Expecting VMX entry 'sched.cpu.affinity' to be " _("Expecting VMX entry 'sched.cpu.affinity' to be "
"a comma separated list of unsigned integers but " "a comma separated list of unsigned integers but "
"found '%s'"), sched_cpu_affinity); "found '%s'"), sched_cpu_affinity);
goto failure; goto cleanup;
} }
if (number >= VIR_DOMAIN_CPUMASK_LEN) { if (number >= VIR_DOMAIN_CPUMASK_LEN) {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("VMX entry 'sched.cpu.affinity' contains a %d, " _("VMX entry 'sched.cpu.affinity' contains a %d, "
"this value is too large"), number); "this value is too large"), number);
goto failure; goto cleanup;
} }
if (number + 1 > def->cpumasklen) { if (number + 1 > def->cpumasklen) {
...@@ -923,7 +926,7 @@ esxVMX_ParseConfig(esxVI_Context *ctx, const char *vmx, ...@@ -923,7 +926,7 @@ esxVMX_ParseConfig(esxVI_Context *ctx, const char *vmx,
_("Expecting VMX entry 'sched.cpu.affinity' to be " _("Expecting VMX entry 'sched.cpu.affinity' to be "
"a comma separated list of unsigned integers but " "a comma separated list of unsigned integers but "
"found '%s'"), sched_cpu_affinity); "found '%s'"), sched_cpu_affinity);
goto failure; goto cleanup;
} }
virSkipSpaces(&current); virSkipSpaces(&current);
...@@ -934,7 +937,7 @@ esxVMX_ParseConfig(esxVI_Context *ctx, const char *vmx, ...@@ -934,7 +937,7 @@ esxVMX_ParseConfig(esxVI_Context *ctx, const char *vmx,
_("Expecting VMX entry 'sched.cpu.affinity' to contain " _("Expecting VMX entry 'sched.cpu.affinity' to contain "
"at least as many values as 'numvcpus' (%lld) but " "at least as many values as 'numvcpus' (%lld) but "
"found only %d value(s)"), numvcpus, count); "found only %d value(s)"), numvcpus, count);
goto failure; goto cleanup;
} }
} }
...@@ -948,12 +951,12 @@ esxVMX_ParseConfig(esxVI_Context *ctx, const char *vmx, ...@@ -948,12 +951,12 @@ esxVMX_ParseConfig(esxVI_Context *ctx, const char *vmx,
if (def->os.type == NULL) { if (def->os.type == NULL) {
virReportOOMError(); virReportOOMError();
goto failure; goto cleanup;
} }
/* vmx:guestOS -> def:os.arch */ /* vmx:guestOS -> def:os.arch */
if (esxUtil_GetConfigString(conf, "guestOS", &guestOS, 1) < 0) { if (esxUtil_GetConfigString(conf, "guestOS", &guestOS, 1) < 0) {
goto failure; goto cleanup;
} }
if (guestOS != NULL && virFileHasSuffix(guestOS, "-64")) { if (guestOS != NULL && virFileHasSuffix(guestOS, "-64")) {
...@@ -964,7 +967,7 @@ esxVMX_ParseConfig(esxVI_Context *ctx, const char *vmx, ...@@ -964,7 +967,7 @@ esxVMX_ParseConfig(esxVI_Context *ctx, const char *vmx,
if (def->os.arch == NULL) { if (def->os.arch == NULL) {
virReportOOMError(); virReportOOMError();
goto failure; goto cleanup;
} }
/* /*
...@@ -977,13 +980,13 @@ esxVMX_ParseConfig(esxVI_Context *ctx, const char *vmx, ...@@ -977,13 +980,13 @@ esxVMX_ParseConfig(esxVI_Context *ctx, const char *vmx,
/* def:graphics */ /* def:graphics */
if (VIR_ALLOC_N(def->graphics, 1) < 0) { if (VIR_ALLOC_N(def->graphics, 1) < 0) {
virReportOOMError(); virReportOOMError();
goto failure; goto cleanup;
} }
def->ngraphics = 0; def->ngraphics = 0;
if (esxVMX_ParseVNC(conf, &def->graphics[def->ngraphics]) < 0) { if (esxVMX_ParseVNC(conf, &def->graphics[def->ngraphics]) < 0) {
goto failure; goto cleanup;
} }
if (def->graphics[def->ngraphics] != NULL) { if (def->graphics[def->ngraphics] != NULL) {
...@@ -993,7 +996,7 @@ esxVMX_ParseConfig(esxVI_Context *ctx, const char *vmx, ...@@ -993,7 +996,7 @@ esxVMX_ParseConfig(esxVI_Context *ctx, const char *vmx,
/* def:disks: 4 * 15 scsi + 2 * 2 ide + 2 floppy = 66 */ /* def:disks: 4 * 15 scsi + 2 * 2 ide + 2 floppy = 66 */
if (VIR_ALLOC_N(def->disks, 66) < 0) { if (VIR_ALLOC_N(def->disks, 66) < 0) {
virReportOOMError(); virReportOOMError();
goto failure; goto cleanup;
} }
def->ndisks = 0; def->ndisks = 0;
...@@ -1004,7 +1007,7 @@ esxVMX_ParseConfig(esxVI_Context *ctx, const char *vmx, ...@@ -1004,7 +1007,7 @@ esxVMX_ParseConfig(esxVI_Context *ctx, const char *vmx,
if (esxVMX_ParseSCSIController(conf, controller, &present, if (esxVMX_ParseSCSIController(conf, controller, &present,
&scsi_virtualDev) < 0) { &scsi_virtualDev) < 0) {
goto failure; goto cleanup;
} }
if (! present) { if (! present) {
...@@ -1024,7 +1027,7 @@ esxVMX_ParseConfig(esxVI_Context *ctx, const char *vmx, ...@@ -1024,7 +1027,7 @@ esxVMX_ParseConfig(esxVI_Context *ctx, const char *vmx,
VIR_DOMAIN_DISK_BUS_SCSI, controller, id, VIR_DOMAIN_DISK_BUS_SCSI, controller, id,
scsi_virtualDev, datastoreName, directoryName, scsi_virtualDev, datastoreName, directoryName,
&def->disks[def->ndisks]) < 0) { &def->disks[def->ndisks]) < 0) {
goto failure; goto cleanup;
} }
if (def->disks[def->ndisks] != NULL) { if (def->disks[def->ndisks] != NULL) {
...@@ -1036,7 +1039,7 @@ esxVMX_ParseConfig(esxVI_Context *ctx, const char *vmx, ...@@ -1036,7 +1039,7 @@ esxVMX_ParseConfig(esxVI_Context *ctx, const char *vmx,
VIR_DOMAIN_DISK_BUS_SCSI, controller, id, VIR_DOMAIN_DISK_BUS_SCSI, controller, id,
scsi_virtualDev, datastoreName, directoryName, scsi_virtualDev, datastoreName, directoryName,
&def->disks[def->ndisks]) < 0) { &def->disks[def->ndisks]) < 0) {
goto failure; goto cleanup;
} }
if (def->disks[def->ndisks] != NULL) { if (def->disks[def->ndisks] != NULL) {
...@@ -1052,7 +1055,7 @@ esxVMX_ParseConfig(esxVI_Context *ctx, const char *vmx, ...@@ -1052,7 +1055,7 @@ esxVMX_ParseConfig(esxVI_Context *ctx, const char *vmx,
VIR_DOMAIN_DISK_BUS_IDE, controller, id, VIR_DOMAIN_DISK_BUS_IDE, controller, id,
NULL, datastoreName, directoryName, NULL, datastoreName, directoryName,
&def->disks[def->ndisks]) < 0) { &def->disks[def->ndisks]) < 0) {
goto failure; goto cleanup;
} }
if (def->disks[def->ndisks] != NULL) { if (def->disks[def->ndisks] != NULL) {
...@@ -1064,7 +1067,7 @@ esxVMX_ParseConfig(esxVI_Context *ctx, const char *vmx, ...@@ -1064,7 +1067,7 @@ esxVMX_ParseConfig(esxVI_Context *ctx, const char *vmx,
VIR_DOMAIN_DISK_BUS_IDE, controller, id, VIR_DOMAIN_DISK_BUS_IDE, controller, id,
NULL, datastoreName, directoryName, NULL, datastoreName, directoryName,
&def->disks[def->ndisks]) < 0) { &def->disks[def->ndisks]) < 0) {
goto failure; goto cleanup;
} }
if (def->disks[def->ndisks] != NULL) { if (def->disks[def->ndisks] != NULL) {
...@@ -1079,7 +1082,7 @@ esxVMX_ParseConfig(esxVI_Context *ctx, const char *vmx, ...@@ -1079,7 +1082,7 @@ esxVMX_ParseConfig(esxVI_Context *ctx, const char *vmx,
VIR_DOMAIN_DISK_BUS_FDC, controller, -1, NULL, VIR_DOMAIN_DISK_BUS_FDC, controller, -1, NULL,
datastoreName, directoryName, datastoreName, directoryName,
&def->disks[def->ndisks]) < 0) { &def->disks[def->ndisks]) < 0) {
goto failure; goto cleanup;
} }
if (def->disks[def->ndisks] != NULL) { if (def->disks[def->ndisks] != NULL) {
...@@ -1093,7 +1096,7 @@ esxVMX_ParseConfig(esxVI_Context *ctx, const char *vmx, ...@@ -1093,7 +1096,7 @@ esxVMX_ParseConfig(esxVI_Context *ctx, const char *vmx,
/* def:nets */ /* def:nets */
if (VIR_ALLOC_N(def->nets, 4) < 0) { if (VIR_ALLOC_N(def->nets, 4) < 0) {
virReportOOMError(); virReportOOMError();
goto failure; goto cleanup;
} }
def->nnets = 0; def->nnets = 0;
...@@ -1101,7 +1104,7 @@ esxVMX_ParseConfig(esxVI_Context *ctx, const char *vmx, ...@@ -1101,7 +1104,7 @@ esxVMX_ParseConfig(esxVI_Context *ctx, const char *vmx,
for (controller = 0; controller < 4; ++controller) { for (controller = 0; controller < 4; ++controller) {
if (esxVMX_ParseEthernet(conf, controller, if (esxVMX_ParseEthernet(conf, controller,
&def->nets[def->nnets]) < 0) { &def->nets[def->nnets]) < 0) {
goto failure; goto cleanup;
} }
if (def->nets[def->nnets] != NULL) { if (def->nets[def->nnets] != NULL) {
...@@ -1121,7 +1124,7 @@ esxVMX_ParseConfig(esxVI_Context *ctx, const char *vmx, ...@@ -1121,7 +1124,7 @@ esxVMX_ParseConfig(esxVI_Context *ctx, const char *vmx,
/* def:serials */ /* def:serials */
if (VIR_ALLOC_N(def->serials, 4) < 0) { if (VIR_ALLOC_N(def->serials, 4) < 0) {
virReportOOMError(); virReportOOMError();
goto failure; goto cleanup;
} }
def->nserials = 0; def->nserials = 0;
...@@ -1130,7 +1133,7 @@ esxVMX_ParseConfig(esxVI_Context *ctx, const char *vmx, ...@@ -1130,7 +1133,7 @@ esxVMX_ParseConfig(esxVI_Context *ctx, const char *vmx,
if (esxVMX_ParseSerial(ctx, conf, port, datastoreName, if (esxVMX_ParseSerial(ctx, conf, port, datastoreName,
directoryName, directoryName,
&def->serials[def->nserials]) < 0) { &def->serials[def->nserials]) < 0) {
goto failure; goto cleanup;
} }
if (def->serials[def->nserials] != NULL) { if (def->serials[def->nserials] != NULL) {
...@@ -1141,7 +1144,7 @@ esxVMX_ParseConfig(esxVI_Context *ctx, const char *vmx, ...@@ -1141,7 +1144,7 @@ esxVMX_ParseConfig(esxVI_Context *ctx, const char *vmx,
/* def:parallels */ /* def:parallels */
if (VIR_ALLOC_N(def->parallels, 3) < 0) { if (VIR_ALLOC_N(def->parallels, 3) < 0) {
virReportOOMError(); virReportOOMError();
goto failure; goto cleanup;
} }
def->nparallels = 0; def->nparallels = 0;
...@@ -1150,7 +1153,7 @@ esxVMX_ParseConfig(esxVI_Context *ctx, const char *vmx, ...@@ -1150,7 +1153,7 @@ esxVMX_ParseConfig(esxVI_Context *ctx, const char *vmx,
if (esxVMX_ParseParallel(ctx, conf, port, datastoreName, if (esxVMX_ParseParallel(ctx, conf, port, datastoreName,
directoryName, directoryName,
&def->parallels[def->nparallels]) < 0) { &def->parallels[def->nparallels]) < 0) {
goto failure; goto cleanup;
} }
if (def->parallels[def->nparallels] != NULL) { if (def->parallels[def->nparallels] != NULL) {
...@@ -1158,19 +1161,20 @@ esxVMX_ParseConfig(esxVI_Context *ctx, const char *vmx, ...@@ -1158,19 +1161,20 @@ esxVMX_ParseConfig(esxVI_Context *ctx, const char *vmx,
} }
} }
success = true;
cleanup: cleanup:
if (! success) {
virDomainDefFree(def);
def = NULL;
}
virConfFree(conf); virConfFree(conf);
VIR_FREE(sched_cpu_affinity); VIR_FREE(sched_cpu_affinity);
VIR_FREE(guestOS); VIR_FREE(guestOS);
VIR_FREE(scsi_virtualDev); VIR_FREE(scsi_virtualDev);
return def; return def;
failure:
virDomainDefFree(def);
def = NULL;
goto cleanup;
} }
...@@ -1335,7 +1339,7 @@ esxVMX_ParseDisk(esxVI_Context *ctx, virConfPtr conf, int device, int bus, ...@@ -1335,7 +1339,7 @@ esxVMX_ParseDisk(esxVI_Context *ctx, virConfPtr conf, int device, int bus,
* virtualDev = NULL * virtualDev = NULL
*/ */
int result = 0; int result = -1;
char *prefix = NULL; char *prefix = NULL;
char present_name[32] = ""; char present_name[32] = "";
...@@ -1366,7 +1370,7 @@ esxVMX_ParseDisk(esxVI_Context *ctx, virConfPtr conf, int device, int bus, ...@@ -1366,7 +1370,7 @@ esxVMX_ParseDisk(esxVI_Context *ctx, virConfPtr conf, int device, int bus,
if (VIR_ALLOC(*def) < 0) { if (VIR_ALLOC(*def) < 0) {
virReportOOMError(); virReportOOMError();
goto failure; return -1;
} }
(*def)->device = device; (*def)->device = device;
...@@ -1380,18 +1384,18 @@ esxVMX_ParseDisk(esxVI_Context *ctx, virConfPtr conf, int device, int bus, ...@@ -1380,18 +1384,18 @@ esxVMX_ParseDisk(esxVI_Context *ctx, virConfPtr conf, int device, int bus,
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("SCSI controller index %d out of [0..3] range"), _("SCSI controller index %d out of [0..3] range"),
controller); controller);
goto failure; goto cleanup;
} }
if (id < 0 || id > 15 || id == 7) { if (id < 0 || id > 15 || id == 7) {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("SCSI ID %d out of [0..6,8..15] range"), id); _("SCSI ID %d out of [0..6,8..15] range"), id);
goto failure; goto cleanup;
} }
if (virAsprintf(&prefix, "scsi%d:%d", controller, id) < 0) { if (virAsprintf(&prefix, "scsi%d:%d", controller, id) < 0) {
virReportOOMError(); virReportOOMError();
goto failure; goto cleanup;
} }
(*def)->dst = (*def)->dst =
...@@ -1399,7 +1403,7 @@ esxVMX_ParseDisk(esxVI_Context *ctx, virConfPtr conf, int device, int bus, ...@@ -1399,7 +1403,7 @@ esxVMX_ParseDisk(esxVI_Context *ctx, virConfPtr conf, int device, int bus,
(controller * 15 + (id < 7 ? id : id - 1), "sd"); (controller * 15 + (id < 7 ? id : id - 1), "sd");
if ((*def)->dst == NULL) { if ((*def)->dst == NULL) {
goto failure; goto cleanup;
} }
if (virtualDev != NULL) { if (virtualDev != NULL) {
...@@ -1407,7 +1411,7 @@ esxVMX_ParseDisk(esxVI_Context *ctx, virConfPtr conf, int device, int bus, ...@@ -1407,7 +1411,7 @@ esxVMX_ParseDisk(esxVI_Context *ctx, virConfPtr conf, int device, int bus,
if ((*def)->driverName == NULL) { if ((*def)->driverName == NULL) {
virReportOOMError(); virReportOOMError();
goto failure; goto cleanup;
} }
} }
} else if (bus == VIR_DOMAIN_DISK_BUS_IDE) { } else if (bus == VIR_DOMAIN_DISK_BUS_IDE) {
...@@ -1415,31 +1419,31 @@ esxVMX_ParseDisk(esxVI_Context *ctx, virConfPtr conf, int device, int bus, ...@@ -1415,31 +1419,31 @@ esxVMX_ParseDisk(esxVI_Context *ctx, virConfPtr conf, int device, int bus,
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("IDE controller index %d out of [0..1] range"), _("IDE controller index %d out of [0..1] range"),
controller); controller);
goto failure; goto cleanup;
} }
if (id < 0 || id > 1) { if (id < 0 || id > 1) {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("IDE ID %d out of [0..1] range"), id); _("IDE ID %d out of [0..1] range"), id);
goto failure; goto cleanup;
} }
if (virAsprintf(&prefix, "ide%d:%d", controller, id) < 0) { if (virAsprintf(&prefix, "ide%d:%d", controller, id) < 0) {
virReportOOMError(); virReportOOMError();
goto failure; goto cleanup;
} }
(*def)->dst = virIndexToDiskName(controller * 2 + id, "hd"); (*def)->dst = virIndexToDiskName(controller * 2 + id, "hd");
if ((*def)->dst == NULL) { if ((*def)->dst == NULL) {
goto failure; goto cleanup;
} }
} else { } else {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Unsupported bus type '%s' for device type '%s'"), _("Unsupported bus type '%s' for device type '%s'"),
virDomainDiskBusTypeToString(bus), virDomainDiskBusTypeToString(bus),
virDomainDiskDeviceTypeToString(device)); virDomainDiskDeviceTypeToString(device));
goto failure; goto cleanup;
} }
} else if (device == VIR_DOMAIN_DISK_DEVICE_FLOPPY) { } else if (device == VIR_DOMAIN_DISK_DEVICE_FLOPPY) {
if (bus == VIR_DOMAIN_DISK_BUS_FDC) { if (bus == VIR_DOMAIN_DISK_BUS_FDC) {
...@@ -1447,31 +1451,31 @@ esxVMX_ParseDisk(esxVI_Context *ctx, virConfPtr conf, int device, int bus, ...@@ -1447,31 +1451,31 @@ esxVMX_ParseDisk(esxVI_Context *ctx, virConfPtr conf, int device, int bus,
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Floppy controller index %d out of [0..1] range"), _("Floppy controller index %d out of [0..1] range"),
controller); controller);
goto failure; goto cleanup;
} }
if (virAsprintf(&prefix, "floppy%d", controller) < 0) { if (virAsprintf(&prefix, "floppy%d", controller) < 0) {
virReportOOMError(); virReportOOMError();
goto failure; goto cleanup;
} }
(*def)->dst = virIndexToDiskName(controller, "fd"); (*def)->dst = virIndexToDiskName(controller, "fd");
if ((*def)->dst == NULL) { if ((*def)->dst == NULL) {
goto failure; goto cleanup;
} }
} else { } else {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Unsupported bus type '%s' for device type '%s'"), _("Unsupported bus type '%s' for device type '%s'"),
virDomainDiskBusTypeToString(bus), virDomainDiskBusTypeToString(bus),
virDomainDiskDeviceTypeToString(device)); virDomainDiskDeviceTypeToString(device));
goto failure; goto cleanup;
} }
} else { } else {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Unsupported device type '%s'"), _("Unsupported device type '%s'"),
virDomainDiskDeviceTypeToString(device)); virDomainDiskDeviceTypeToString(device));
goto failure; goto cleanup;
} }
ESX_BUILD_VMX_NAME(present); ESX_BUILD_VMX_NAME(present);
...@@ -1484,13 +1488,13 @@ esxVMX_ParseDisk(esxVI_Context *ctx, virConfPtr conf, int device, int bus, ...@@ -1484,13 +1488,13 @@ esxVMX_ParseDisk(esxVI_Context *ctx, virConfPtr conf, int device, int bus,
/* vmx:present */ /* vmx:present */
if (esxUtil_GetConfigBoolean(conf, present_name, &present, 0, 1) < 0) { if (esxUtil_GetConfigBoolean(conf, present_name, &present, 0, 1) < 0) {
goto failure; goto cleanup;
} }
/* vmx:startConnected */ /* vmx:startConnected */
if (esxUtil_GetConfigBoolean(conf, startConnected_name, &startConnected, if (esxUtil_GetConfigBoolean(conf, startConnected_name, &startConnected,
1, 1) < 0) { 1, 1) < 0) {
goto failure; goto cleanup;
} }
/* FIXME: Need to distiguish between active and inactive domains here */ /* FIXME: Need to distiguish between active and inactive domains here */
...@@ -1500,13 +1504,13 @@ esxVMX_ParseDisk(esxVI_Context *ctx, virConfPtr conf, int device, int bus, ...@@ -1500,13 +1504,13 @@ esxVMX_ParseDisk(esxVI_Context *ctx, virConfPtr conf, int device, int bus,
/* vmx:deviceType -> def:type */ /* vmx:deviceType -> def:type */
if (esxUtil_GetConfigString(conf, deviceType_name, &deviceType, 1) < 0) { if (esxUtil_GetConfigString(conf, deviceType_name, &deviceType, 1) < 0) {
goto failure; goto cleanup;
} }
/* vmx:clientDevice */ /* vmx:clientDevice */
if (esxUtil_GetConfigBoolean(conf, clientDevice_name, &clientDevice, 0, if (esxUtil_GetConfigBoolean(conf, clientDevice_name, &clientDevice, 0,
1) < 0) { 1) < 0) {
goto failure; goto cleanup;
} }
if (clientDevice) { if (clientDevice) {
...@@ -1519,18 +1523,18 @@ esxVMX_ParseDisk(esxVI_Context *ctx, virConfPtr conf, int device, int bus, ...@@ -1519,18 +1523,18 @@ esxVMX_ParseDisk(esxVI_Context *ctx, virConfPtr conf, int device, int bus,
/* vmx:fileType -> def:type */ /* vmx:fileType -> def:type */
if (esxUtil_GetConfigString(conf, fileType_name, &fileType, 1) < 0) { if (esxUtil_GetConfigString(conf, fileType_name, &fileType, 1) < 0) {
goto failure; goto cleanup;
} }
/* vmx:fileName -> def:src, def:type */ /* vmx:fileName -> def:src, def:type */
if (esxUtil_GetConfigString(conf, fileName_name, &fileName, 0) < 0) { if (esxUtil_GetConfigString(conf, fileName_name, &fileName, 0) < 0) {
goto failure; goto cleanup;
} }
/* vmx:writeThrough -> def:cachemode */ /* vmx:writeThrough -> def:cachemode */
if (esxUtil_GetConfigBoolean(conf, writeThrough_name, &writeThrough, 0, if (esxUtil_GetConfigBoolean(conf, writeThrough_name, &writeThrough, 0,
1) < 0) { 1) < 0) {
goto failure; goto cleanup;
} }
/* Setup virDomainDiskDef */ /* Setup virDomainDiskDef */
...@@ -1542,13 +1546,13 @@ esxVMX_ParseDisk(esxVI_Context *ctx, virConfPtr conf, int device, int bus, ...@@ -1542,13 +1546,13 @@ esxVMX_ParseDisk(esxVI_Context *ctx, virConfPtr conf, int device, int bus,
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Expecting VMX entry '%s' to be 'scsi-hardDisk' " _("Expecting VMX entry '%s' to be 'scsi-hardDisk' "
"but found '%s'"), deviceType_name, deviceType); "but found '%s'"), deviceType_name, deviceType);
goto failure; goto cleanup;
} else if (bus == VIR_DOMAIN_DISK_BUS_IDE && } else if (bus == VIR_DOMAIN_DISK_BUS_IDE &&
STRCASENEQ(deviceType, "ata-hardDisk")) { STRCASENEQ(deviceType, "ata-hardDisk")) {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Expecting VMX entry '%s' to be 'ata-hardDisk' " _("Expecting VMX entry '%s' to be 'ata-hardDisk' "
"but found '%s'"), deviceType_name, deviceType); "but found '%s'"), deviceType_name, deviceType);
goto failure; goto cleanup;
} }
} }
...@@ -1569,7 +1573,7 @@ esxVMX_ParseDisk(esxVI_Context *ctx, virConfPtr conf, int device, int bus, ...@@ -1569,7 +1573,7 @@ esxVMX_ParseDisk(esxVI_Context *ctx, virConfPtr conf, int device, int bus,
: VIR_DOMAIN_DISK_CACHE_DEFAULT; : VIR_DOMAIN_DISK_CACHE_DEFAULT;
if ((*def)->src == NULL) { if ((*def)->src == NULL) {
goto failure; goto cleanup;
} }
} else if (virFileHasSuffix(fileName, ".iso") || } else if (virFileHasSuffix(fileName, ".iso") ||
STREQ(deviceType, "atapi-cdrom")) { STREQ(deviceType, "atapi-cdrom")) {
...@@ -1584,7 +1588,7 @@ esxVMX_ParseDisk(esxVI_Context *ctx, virConfPtr conf, int device, int bus, ...@@ -1584,7 +1588,7 @@ esxVMX_ParseDisk(esxVI_Context *ctx, virConfPtr conf, int device, int bus,
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Invalid or not yet handled value '%s' for VMX entry " _("Invalid or not yet handled value '%s' for VMX entry "
"'%s'"), fileName, fileName_name); "'%s'"), fileName, fileName_name);
goto failure; goto cleanup;
} }
} else if (device == VIR_DOMAIN_DISK_DEVICE_CDROM) { } else if (device == VIR_DOMAIN_DISK_DEVICE_CDROM) {
if (virFileHasSuffix(fileName, ".iso")) { if (virFileHasSuffix(fileName, ".iso")) {
...@@ -1593,7 +1597,7 @@ esxVMX_ParseDisk(esxVI_Context *ctx, virConfPtr conf, int device, int bus, ...@@ -1593,7 +1597,7 @@ esxVMX_ParseDisk(esxVI_Context *ctx, virConfPtr conf, int device, int bus,
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Expecting VMX entry '%s' to be 'cdrom-image' " _("Expecting VMX entry '%s' to be 'cdrom-image' "
"but found '%s'"), deviceType_name, deviceType); "but found '%s'"), deviceType_name, deviceType);
goto failure; goto cleanup;
} }
} }
...@@ -1602,7 +1606,7 @@ esxVMX_ParseDisk(esxVI_Context *ctx, virConfPtr conf, int device, int bus, ...@@ -1602,7 +1606,7 @@ esxVMX_ParseDisk(esxVI_Context *ctx, virConfPtr conf, int device, int bus,
directoryName); directoryName);
if ((*def)->src == NULL) { if ((*def)->src == NULL) {
goto failure; goto cleanup;
} }
} else if (virFileHasSuffix(fileName, ".vmdk")) { } else if (virFileHasSuffix(fileName, ".vmdk")) {
/* /*
...@@ -1621,7 +1625,7 @@ esxVMX_ParseDisk(esxVI_Context *ctx, virConfPtr conf, int device, int bus, ...@@ -1621,7 +1625,7 @@ esxVMX_ParseDisk(esxVI_Context *ctx, virConfPtr conf, int device, int bus,
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Invalid or not yet handled value '%s' for VMX entry " _("Invalid or not yet handled value '%s' for VMX entry "
"'%s'"), fileName, fileName_name); "'%s'"), fileName, fileName_name);
goto failure; goto cleanup;
} }
} else if (device == VIR_DOMAIN_DISK_DEVICE_FLOPPY) { } else if (device == VIR_DOMAIN_DISK_DEVICE_FLOPPY) {
if (virFileHasSuffix(fileName, ".flp")) { if (virFileHasSuffix(fileName, ".flp")) {
...@@ -1630,7 +1634,7 @@ esxVMX_ParseDisk(esxVI_Context *ctx, virConfPtr conf, int device, int bus, ...@@ -1630,7 +1634,7 @@ esxVMX_ParseDisk(esxVI_Context *ctx, virConfPtr conf, int device, int bus,
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Expecting VMX entry '%s' to be 'file' but " _("Expecting VMX entry '%s' to be 'file' but "
"found '%s'"), fileType_name, fileType); "found '%s'"), fileType_name, fileType);
goto failure; goto cleanup;
} }
} }
...@@ -1639,7 +1643,7 @@ esxVMX_ParseDisk(esxVI_Context *ctx, virConfPtr conf, int device, int bus, ...@@ -1639,7 +1643,7 @@ esxVMX_ParseDisk(esxVI_Context *ctx, virConfPtr conf, int device, int bus,
directoryName); directoryName);
if ((*def)->src == NULL) { if ((*def)->src == NULL) {
goto failure; goto cleanup;
} }
} else if (fileType != NULL && STREQ(fileType, "device")) { } else if (fileType != NULL && STREQ(fileType, "device")) {
(*def)->type = VIR_DOMAIN_DISK_TYPE_BLOCK; (*def)->type = VIR_DOMAIN_DISK_TYPE_BLOCK;
...@@ -1650,15 +1654,22 @@ esxVMX_ParseDisk(esxVI_Context *ctx, virConfPtr conf, int device, int bus, ...@@ -1650,15 +1654,22 @@ esxVMX_ParseDisk(esxVI_Context *ctx, virConfPtr conf, int device, int bus,
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Invalid or not yet handled value '%s' for VMX entry " _("Invalid or not yet handled value '%s' for VMX entry "
"'%s'"), fileName, fileName_name); "'%s'"), fileName, fileName_name);
goto failure; goto cleanup;
} }
} else { } else {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, _("Unsupported device type '%s'"), ESX_ERROR(VIR_ERR_INTERNAL_ERROR, _("Unsupported device type '%s'"),
virDomainDiskDeviceTypeToString(device)); virDomainDiskDeviceTypeToString(device));
goto failure; goto cleanup;
} }
result = 0;
cleanup: cleanup:
if (result < 0) {
virDomainDiskDefFree(*def);
*def = NULL;
}
VIR_FREE(prefix); VIR_FREE(prefix);
VIR_FREE(deviceType); VIR_FREE(deviceType);
VIR_FREE(fileType); VIR_FREE(fileType);
...@@ -1666,13 +1677,12 @@ esxVMX_ParseDisk(esxVI_Context *ctx, virConfPtr conf, int device, int bus, ...@@ -1666,13 +1677,12 @@ esxVMX_ParseDisk(esxVI_Context *ctx, virConfPtr conf, int device, int bus,
return result; return result;
failure:
result = -1;
ignore: ignore:
virDomainDiskDefFree(*def); virDomainDiskDefFree(*def);
*def = NULL; *def = NULL;
result = 0;
goto cleanup; goto cleanup;
} }
...@@ -1681,7 +1691,7 @@ esxVMX_ParseDisk(esxVI_Context *ctx, virConfPtr conf, int device, int bus, ...@@ -1681,7 +1691,7 @@ esxVMX_ParseDisk(esxVI_Context *ctx, virConfPtr conf, int device, int bus,
int int
esxVMX_ParseEthernet(virConfPtr conf, int controller, virDomainNetDefPtr *def) esxVMX_ParseEthernet(virConfPtr conf, int controller, virDomainNetDefPtr *def)
{ {
int result = 0; int result = -1;
char prefix[48] = ""; char prefix[48] = "";
char present_name[48] = ""; char present_name[48] = "";
...@@ -1728,7 +1738,7 @@ esxVMX_ParseEthernet(virConfPtr conf, int controller, virDomainNetDefPtr *def) ...@@ -1728,7 +1738,7 @@ esxVMX_ParseEthernet(virConfPtr conf, int controller, virDomainNetDefPtr *def)
if (VIR_ALLOC(*def) < 0) { if (VIR_ALLOC(*def) < 0) {
virReportOOMError(); virReportOOMError();
goto failure; return -1;
} }
snprintf(prefix, sizeof(prefix), "ethernet%d", controller); snprintf(prefix, sizeof(prefix), "ethernet%d", controller);
...@@ -1746,13 +1756,13 @@ esxVMX_ParseEthernet(virConfPtr conf, int controller, virDomainNetDefPtr *def) ...@@ -1746,13 +1756,13 @@ esxVMX_ParseEthernet(virConfPtr conf, int controller, virDomainNetDefPtr *def)
/* vmx:present */ /* vmx:present */
if (esxUtil_GetConfigBoolean(conf, present_name, &present, 0, 1) < 0) { if (esxUtil_GetConfigBoolean(conf, present_name, &present, 0, 1) < 0) {
goto failure; goto cleanup;
} }
/* vmx:startConnected */ /* vmx:startConnected */
if (esxUtil_GetConfigBoolean(conf, startConnected_name, &startConnected, 1, if (esxUtil_GetConfigBoolean(conf, startConnected_name, &startConnected, 1,
1) < 0) { 1) < 0) {
goto failure; goto cleanup;
} }
/* FIXME: Need to distiguish between active and inactive domains here */ /* FIXME: Need to distiguish between active and inactive domains here */
...@@ -1763,7 +1773,7 @@ esxVMX_ParseEthernet(virConfPtr conf, int controller, virDomainNetDefPtr *def) ...@@ -1763,7 +1773,7 @@ esxVMX_ParseEthernet(virConfPtr conf, int controller, virDomainNetDefPtr *def)
/* vmx:connectionType -> def:type */ /* vmx:connectionType -> def:type */
if (esxUtil_GetConfigString(conf, connectionType_name, &connectionType, if (esxUtil_GetConfigString(conf, connectionType_name, &connectionType,
1) < 0) { 1) < 0) {
goto failure; goto cleanup;
} }
/* vmx:addressType, vmx:generatedAddress, vmx:address -> def:mac */ /* vmx:addressType, vmx:generatedAddress, vmx:address -> def:mac */
...@@ -1771,7 +1781,7 @@ esxVMX_ParseEthernet(virConfPtr conf, int controller, virDomainNetDefPtr *def) ...@@ -1771,7 +1781,7 @@ esxVMX_ParseEthernet(virConfPtr conf, int controller, virDomainNetDefPtr *def)
esxUtil_GetConfigString(conf, generatedAddress_name, &generatedAddress, esxUtil_GetConfigString(conf, generatedAddress_name, &generatedAddress,
1) < 0 || 1) < 0 ||
esxUtil_GetConfigString(conf, address_name, &address, 1) < 0) { esxUtil_GetConfigString(conf, address_name, &address, 1) < 0) {
goto failure; goto cleanup;
} }
if (addressType == NULL || STRCASEEQ(addressType, "generated") || if (addressType == NULL || STRCASEEQ(addressType, "generated") ||
...@@ -1782,7 +1792,7 @@ esxVMX_ParseEthernet(virConfPtr conf, int controller, virDomainNetDefPtr *def) ...@@ -1782,7 +1792,7 @@ esxVMX_ParseEthernet(virConfPtr conf, int controller, virDomainNetDefPtr *def)
_("Expecting VMX entry '%s' to be MAC address but " _("Expecting VMX entry '%s' to be MAC address but "
"found '%s'"), generatedAddress_name, "found '%s'"), generatedAddress_name,
generatedAddress); generatedAddress);
goto failure; goto cleanup;
} }
} }
} else if (STRCASEEQ(addressType, "static")) { } else if (STRCASEEQ(addressType, "static")) {
...@@ -1791,20 +1801,20 @@ esxVMX_ParseEthernet(virConfPtr conf, int controller, virDomainNetDefPtr *def) ...@@ -1791,20 +1801,20 @@ esxVMX_ParseEthernet(virConfPtr conf, int controller, virDomainNetDefPtr *def)
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Expecting VMX entry '%s' to be MAC address but " _("Expecting VMX entry '%s' to be MAC address but "
"found '%s'"), address_name, address); "found '%s'"), address_name, address);
goto failure; goto cleanup;
} }
} }
} else { } else {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Expecting VMX entry '%s' to be 'generated' or 'static' or " _("Expecting VMX entry '%s' to be 'generated' or 'static' or "
"'vpx' but found '%s'"), addressType_name, addressType); "'vpx' but found '%s'"), addressType_name, addressType);
goto failure; goto cleanup;
} }
/* vmx:virtualDev, vmx:features -> def:model */ /* vmx:virtualDev, vmx:features -> def:model */
if (esxUtil_GetConfigString(conf, virtualDev_name, &virtualDev, 1) < 0 || if (esxUtil_GetConfigString(conf, virtualDev_name, &virtualDev, 1) < 0 ||
esxUtil_GetConfigLong(conf, features_name, &features, 0, 1) < 0) { esxUtil_GetConfigLong(conf, features_name, &features, 0, 1) < 0) {
goto failure; goto cleanup;
} }
if (virtualDev != NULL) { if (virtualDev != NULL) {
...@@ -1816,7 +1826,7 @@ esxVMX_ParseEthernet(virConfPtr conf, int controller, virDomainNetDefPtr *def) ...@@ -1816,7 +1826,7 @@ esxVMX_ParseEthernet(virConfPtr conf, int controller, virDomainNetDefPtr *def)
_("Expecting VMX entry '%s' to be 'vlance' or 'vmxnet' or " _("Expecting VMX entry '%s' to be 'vlance' or 'vmxnet' or "
"'vmxnet3' or 'e1000' but found '%s'"), virtualDev_name, "'vmxnet3' or 'e1000' but found '%s'"), virtualDev_name,
virtualDev); virtualDev);
goto failure; goto cleanup;
} }
if (STRCASEEQ(virtualDev, "vmxnet") && features == 15) { if (STRCASEEQ(virtualDev, "vmxnet") && features == 15) {
...@@ -1826,7 +1836,7 @@ esxVMX_ParseEthernet(virConfPtr conf, int controller, virDomainNetDefPtr *def) ...@@ -1826,7 +1836,7 @@ esxVMX_ParseEthernet(virConfPtr conf, int controller, virDomainNetDefPtr *def)
if (virtualDev == NULL) { if (virtualDev == NULL) {
virReportOOMError(); virReportOOMError();
goto failure; goto cleanup;
} }
} }
} }
...@@ -1836,13 +1846,13 @@ esxVMX_ParseEthernet(virConfPtr conf, int controller, virDomainNetDefPtr *def) ...@@ -1836,13 +1846,13 @@ esxVMX_ParseEthernet(virConfPtr conf, int controller, virDomainNetDefPtr *def)
STRCASEEQ(connectionType, "bridged") || STRCASEEQ(connectionType, "bridged") ||
STRCASEEQ(connectionType, "custom")) && STRCASEEQ(connectionType, "custom")) &&
esxUtil_GetConfigString(conf, networkName_name, &networkName, 0) < 0) { esxUtil_GetConfigString(conf, networkName_name, &networkName, 0) < 0) {
goto failure; goto cleanup;
} }
/* vmx:vnet -> def:data.ifname */ /* vmx:vnet -> def:data.ifname */
if (connectionType != NULL && STRCASEEQ(connectionType, "custom") && if (connectionType != NULL && STRCASEEQ(connectionType, "custom") &&
esxUtil_GetConfigString(conf, vnet_name, &vnet, 0) < 0) { esxUtil_GetConfigString(conf, vnet_name, &vnet, 0) < 0) {
goto failure; goto cleanup;
} }
/* Setup virDomainNetDef */ /* Setup virDomainNetDef */
...@@ -1858,13 +1868,13 @@ esxVMX_ParseEthernet(virConfPtr conf, int controller, virDomainNetDefPtr *def) ...@@ -1858,13 +1868,13 @@ esxVMX_ParseEthernet(virConfPtr conf, int controller, virDomainNetDefPtr *def)
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("No yet handled value '%s' for VMX entry '%s'"), _("No yet handled value '%s' for VMX entry '%s'"),
connectionType, connectionType_name); connectionType, connectionType_name);
goto failure; goto cleanup;
} else if (STRCASEEQ(connectionType, "nat")) { } else if (STRCASEEQ(connectionType, "nat")) {
/* FIXME */ /* FIXME */
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("No yet handled value '%s' for VMX entry '%s'"), _("No yet handled value '%s' for VMX entry '%s'"),
connectionType, connectionType_name); connectionType, connectionType_name);
goto failure; goto cleanup;
} else if (STRCASEEQ(connectionType, "custom")) { } else if (STRCASEEQ(connectionType, "custom")) {
(*def)->type = VIR_DOMAIN_NET_TYPE_BRIDGE; (*def)->type = VIR_DOMAIN_NET_TYPE_BRIDGE;
(*def)->model = virtualDev; (*def)->model = virtualDev;
...@@ -1878,10 +1888,17 @@ esxVMX_ParseEthernet(virConfPtr conf, int controller, virDomainNetDefPtr *def) ...@@ -1878,10 +1888,17 @@ esxVMX_ParseEthernet(virConfPtr conf, int controller, virDomainNetDefPtr *def)
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Invalid value '%s' for VMX entry '%s'"), connectionType, _("Invalid value '%s' for VMX entry '%s'"), connectionType,
connectionType_name); connectionType_name);
goto failure; goto cleanup;
} }
result = 0;
cleanup: cleanup:
if (result < 0) {
virDomainNetDefFree(*def);
*def = NULL;
}
VIR_FREE(connectionType); VIR_FREE(connectionType);
VIR_FREE(addressType); VIR_FREE(addressType);
VIR_FREE(generatedAddress); VIR_FREE(generatedAddress);
...@@ -1891,13 +1908,12 @@ esxVMX_ParseEthernet(virConfPtr conf, int controller, virDomainNetDefPtr *def) ...@@ -1891,13 +1908,12 @@ esxVMX_ParseEthernet(virConfPtr conf, int controller, virDomainNetDefPtr *def)
return result; return result;
failure:
result = -1;
ignore: ignore:
virDomainNetDefFree(*def); virDomainNetDefFree(*def);
*def = NULL; *def = NULL;
result = 0;
goto cleanup; goto cleanup;
} }
...@@ -1908,7 +1924,7 @@ esxVMX_ParseSerial(esxVI_Context *ctx, virConfPtr conf, int port, ...@@ -1908,7 +1924,7 @@ esxVMX_ParseSerial(esxVI_Context *ctx, virConfPtr conf, int port,
const char *datastoreName, const char *directoryName, const char *datastoreName, const char *directoryName,
virDomainChrDefPtr *def) virDomainChrDefPtr *def)
{ {
int result = 0; int result = -1;
char prefix[48] = ""; char prefix[48] = "";
char present_name[48] = ""; char present_name[48] = "";
...@@ -1936,7 +1952,7 @@ esxVMX_ParseSerial(esxVI_Context *ctx, virConfPtr conf, int port, ...@@ -1936,7 +1952,7 @@ esxVMX_ParseSerial(esxVI_Context *ctx, virConfPtr conf, int port,
if (VIR_ALLOC(*def) < 0) { if (VIR_ALLOC(*def) < 0) {
virReportOOMError(); virReportOOMError();
goto failure; return -1;
} }
(*def)->targetType = VIR_DOMAIN_CHR_TARGET_TYPE_SERIAL; (*def)->targetType = VIR_DOMAIN_CHR_TARGET_TYPE_SERIAL;
...@@ -1950,13 +1966,13 @@ esxVMX_ParseSerial(esxVI_Context *ctx, virConfPtr conf, int port, ...@@ -1950,13 +1966,13 @@ esxVMX_ParseSerial(esxVI_Context *ctx, virConfPtr conf, int port,
/* vmx:present */ /* vmx:present */
if (esxUtil_GetConfigBoolean(conf, present_name, &present, 0, 1) < 0) { if (esxUtil_GetConfigBoolean(conf, present_name, &present, 0, 1) < 0) {
goto failure; goto cleanup;
} }
/* vmx:startConnected */ /* vmx:startConnected */
if (esxUtil_GetConfigBoolean(conf, startConnected_name, &startConnected, 1, if (esxUtil_GetConfigBoolean(conf, startConnected_name, &startConnected, 1,
1) < 0) { 1) < 0) {
goto failure; goto cleanup;
} }
/* FIXME: Need to distiguish between active and inactive domains here */ /* FIXME: Need to distiguish between active and inactive domains here */
...@@ -1966,12 +1982,12 @@ esxVMX_ParseSerial(esxVI_Context *ctx, virConfPtr conf, int port, ...@@ -1966,12 +1982,12 @@ esxVMX_ParseSerial(esxVI_Context *ctx, virConfPtr conf, int port,
/* vmx:fileType -> def:type */ /* vmx:fileType -> def:type */
if (esxUtil_GetConfigString(conf, fileType_name, &fileType, 0) < 0) { if (esxUtil_GetConfigString(conf, fileType_name, &fileType, 0) < 0) {
goto failure; goto cleanup;
} }
/* vmx:fileName -> def:data.file.path */ /* vmx:fileName -> def:data.file.path */
if (esxUtil_GetConfigString(conf, fileName_name, &fileName, 0) < 0) { if (esxUtil_GetConfigString(conf, fileName_name, &fileName, 0) < 0) {
goto failure; goto cleanup;
} }
/* Setup virDomainChrDef */ /* Setup virDomainChrDef */
...@@ -1989,7 +2005,7 @@ esxVMX_ParseSerial(esxVI_Context *ctx, virConfPtr conf, int port, ...@@ -1989,7 +2005,7 @@ esxVMX_ParseSerial(esxVI_Context *ctx, virConfPtr conf, int port,
directoryName); directoryName);
if ((*def)->data.file.path == NULL) { if ((*def)->data.file.path == NULL) {
goto failure; goto cleanup;
} }
} else if (STRCASEEQ(fileType, "pipe")) { } else if (STRCASEEQ(fileType, "pipe")) {
/* /*
...@@ -2005,22 +2021,28 @@ esxVMX_ParseSerial(esxVI_Context *ctx, virConfPtr conf, int port, ...@@ -2005,22 +2021,28 @@ esxVMX_ParseSerial(esxVI_Context *ctx, virConfPtr conf, int port,
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Expecting VMX entry '%s' to be 'device', 'file' or 'pipe' " _("Expecting VMX entry '%s' to be 'device', 'file' or 'pipe' "
"but found '%s'"), fileType_name, fileType); "but found '%s'"), fileType_name, fileType);
goto failure; goto cleanup;
} }
result = 0;
cleanup: cleanup:
if (result < 0) {
virDomainChrDefFree(*def);
*def = NULL;
}
VIR_FREE(fileType); VIR_FREE(fileType);
VIR_FREE(fileName); VIR_FREE(fileName);
return result; return result;
failure:
result = -1;
ignore: ignore:
virDomainChrDefFree(*def); virDomainChrDefFree(*def);
*def = NULL; *def = NULL;
result = 0;
goto cleanup; goto cleanup;
} }
...@@ -2031,7 +2053,7 @@ esxVMX_ParseParallel(esxVI_Context *ctx, virConfPtr conf, int port, ...@@ -2031,7 +2053,7 @@ esxVMX_ParseParallel(esxVI_Context *ctx, virConfPtr conf, int port,
const char *datastoreName, const char *directoryName, const char *datastoreName, const char *directoryName,
virDomainChrDefPtr *def) virDomainChrDefPtr *def)
{ {
int result = 0; int result = -1;
char prefix[48] = ""; char prefix[48] = "";
char present_name[48] = ""; char present_name[48] = "";
...@@ -2059,7 +2081,7 @@ esxVMX_ParseParallel(esxVI_Context *ctx, virConfPtr conf, int port, ...@@ -2059,7 +2081,7 @@ esxVMX_ParseParallel(esxVI_Context *ctx, virConfPtr conf, int port,
if (VIR_ALLOC(*def) < 0) { if (VIR_ALLOC(*def) < 0) {
virReportOOMError(); virReportOOMError();
goto failure; return -1;
} }
(*def)->targetType = VIR_DOMAIN_CHR_TARGET_TYPE_PARALLEL; (*def)->targetType = VIR_DOMAIN_CHR_TARGET_TYPE_PARALLEL;
...@@ -2073,13 +2095,13 @@ esxVMX_ParseParallel(esxVI_Context *ctx, virConfPtr conf, int port, ...@@ -2073,13 +2095,13 @@ esxVMX_ParseParallel(esxVI_Context *ctx, virConfPtr conf, int port,
/* vmx:present */ /* vmx:present */
if (esxUtil_GetConfigBoolean(conf, present_name, &present, 0, 1) < 0) { if (esxUtil_GetConfigBoolean(conf, present_name, &present, 0, 1) < 0) {
goto failure; goto cleanup;
} }
/* vmx:startConnected */ /* vmx:startConnected */
if (esxUtil_GetConfigBoolean(conf, startConnected_name, &startConnected, 1, if (esxUtil_GetConfigBoolean(conf, startConnected_name, &startConnected, 1,
1) < 0) { 1) < 0) {
goto failure; goto cleanup;
} }
/* FIXME: Need to distiguish between active and inactive domains here */ /* FIXME: Need to distiguish between active and inactive domains here */
...@@ -2089,12 +2111,12 @@ esxVMX_ParseParallel(esxVI_Context *ctx, virConfPtr conf, int port, ...@@ -2089,12 +2111,12 @@ esxVMX_ParseParallel(esxVI_Context *ctx, virConfPtr conf, int port,
/* vmx:fileType -> def:type */ /* vmx:fileType -> def:type */
if (esxUtil_GetConfigString(conf, fileType_name, &fileType, 0) < 0) { if (esxUtil_GetConfigString(conf, fileType_name, &fileType, 0) < 0) {
goto failure; goto cleanup;
} }
/* vmx:fileName -> def:data.file.path */ /* vmx:fileName -> def:data.file.path */
if (esxUtil_GetConfigString(conf, fileName_name, &fileName, 0) < 0) { if (esxUtil_GetConfigString(conf, fileName_name, &fileName, 0) < 0) {
goto failure; goto cleanup;
} }
/* Setup virDomainChrDef */ /* Setup virDomainChrDef */
...@@ -2112,28 +2134,34 @@ esxVMX_ParseParallel(esxVI_Context *ctx, virConfPtr conf, int port, ...@@ -2112,28 +2134,34 @@ esxVMX_ParseParallel(esxVI_Context *ctx, virConfPtr conf, int port,
directoryName); directoryName);
if ((*def)->data.file.path == NULL) { if ((*def)->data.file.path == NULL) {
goto failure; goto cleanup;
} }
} else { } else {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Expecting VMX entry '%s' to be 'device' or 'file' but " _("Expecting VMX entry '%s' to be 'device' or 'file' but "
"found '%s'"), fileType_name, fileType); "found '%s'"), fileType_name, fileType);
goto failure; goto cleanup;
} }
result = 0;
cleanup: cleanup:
if (result < 0) {
virDomainChrDefFree(*def);
*def = NULL;
}
VIR_FREE(fileType); VIR_FREE(fileType);
VIR_FREE(fileName); VIR_FREE(fileName);
return result; return result;
failure:
result = -1;
ignore: ignore:
virDomainChrDefFree(*def); virDomainChrDefFree(*def);
*def = NULL; *def = NULL;
result = 0;
goto cleanup; goto cleanup;
} }
...@@ -2146,6 +2174,7 @@ esxVMX_ParseParallel(esxVI_Context *ctx, virConfPtr conf, int port, ...@@ -2146,6 +2174,7 @@ esxVMX_ParseParallel(esxVI_Context *ctx, virConfPtr conf, int port,
char * char *
esxVMX_FormatFileName(esxVI_Context *ctx ATTRIBUTE_UNUSED, const char *src) esxVMX_FormatFileName(esxVI_Context *ctx ATTRIBUTE_UNUSED, const char *src)
{ {
bool success = false;
char *datastoreName = NULL; char *datastoreName = NULL;
char *directoryName = NULL; char *directoryName = NULL;
char *fileName = NULL; char *fileName = NULL;
...@@ -2155,20 +2184,20 @@ esxVMX_FormatFileName(esxVI_Context *ctx ATTRIBUTE_UNUSED, const char *src) ...@@ -2155,20 +2184,20 @@ esxVMX_FormatFileName(esxVI_Context *ctx ATTRIBUTE_UNUSED, const char *src)
/* Found potential datastore related path */ /* Found potential datastore related path */
if (esxUtil_ParseDatastoreRelatedPath(src, &datastoreName, if (esxUtil_ParseDatastoreRelatedPath(src, &datastoreName,
&directoryName, &fileName) < 0) { &directoryName, &fileName) < 0) {
goto failure; goto cleanup;
} }
if (directoryName == NULL) { if (directoryName == NULL) {
if (virAsprintf(&absolutePath, "/vmfs/volumes/%s/%s", if (virAsprintf(&absolutePath, "/vmfs/volumes/%s/%s",
datastoreName, fileName) < 0) { datastoreName, fileName) < 0) {
virReportOOMError(); virReportOOMError();
goto failure; goto cleanup;
} }
} else { } else {
if (virAsprintf(&absolutePath, "/vmfs/volumes/%s/%s/%s", if (virAsprintf(&absolutePath, "/vmfs/volumes/%s/%s/%s",
datastoreName, directoryName, fileName) < 0) { datastoreName, directoryName, fileName) < 0) {
virReportOOMError(); virReportOOMError();
goto failure; goto cleanup;
} }
} }
} else if (STRPREFIX(src, "/")) { } else if (STRPREFIX(src, "/")) {
...@@ -2177,29 +2206,30 @@ esxVMX_FormatFileName(esxVI_Context *ctx ATTRIBUTE_UNUSED, const char *src) ...@@ -2177,29 +2206,30 @@ esxVMX_FormatFileName(esxVI_Context *ctx ATTRIBUTE_UNUSED, const char *src)
if (absolutePath == NULL) { if (absolutePath == NULL) {
virReportOOMError(); virReportOOMError();
goto failure; goto cleanup;
} }
} else { } else {
/* Found relative path, this is not supported */ /* Found relative path, this is not supported */
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Found relative path '%s' in domain XML, this is not " _("Found relative path '%s' in domain XML, this is not "
"supported"), src); "supported"), src);
goto failure; goto cleanup;
} }
/* FIXME: Check if referenced path/file really exists */ /* FIXME: Check if referenced path/file really exists */
success = true;
cleanup: cleanup:
if (! success) {
VIR_FREE(absolutePath);
}
VIR_FREE(datastoreName); VIR_FREE(datastoreName);
VIR_FREE(directoryName); VIR_FREE(directoryName);
VIR_FREE(fileName); VIR_FREE(fileName);
return absolutePath; return absolutePath;
failure:
VIR_FREE(absolutePath);
goto cleanup;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册