mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-03 11:35:19 +00:00
esx: eliminate unnecessary cleanup: labels and result variables
switching to g_autofree left many cleanup: sections empty. Signed-off-by: Laine Stump <laine@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
d6e357c47c
commit
b10402ece1
@ -690,7 +690,6 @@ esxConnectToVCenter(esxPrivate *priv,
|
|||||||
const char *hostname,
|
const char *hostname,
|
||||||
const char *hostSystemIPAddress)
|
const char *hostSystemIPAddress)
|
||||||
{
|
{
|
||||||
int result = -1;
|
|
||||||
g_autofree char *ipAddress = NULL;
|
g_autofree char *ipAddress = NULL;
|
||||||
g_autofree char *username = NULL;
|
g_autofree char *username = NULL;
|
||||||
g_autofree char *password = NULL;
|
g_autofree char *password = NULL;
|
||||||
@ -711,11 +710,11 @@ esxConnectToVCenter(esxPrivate *priv,
|
|||||||
} else {
|
} else {
|
||||||
if (!(username = virAuthGetUsername(conn, auth, "esx", "administrator",
|
if (!(username = virAuthGetUsername(conn, auth, "esx", "administrator",
|
||||||
hostname)))
|
hostname)))
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(password = virAuthGetPassword(conn, auth, "esx", username, hostname)))
|
if (!(password = virAuthGetPassword(conn, auth, "esx", username, hostname)))
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
url = g_strdup_printf("%s://%s:%d/sdk", priv->parsedUri->transport, hostname,
|
url = g_strdup_printf("%s://%s:%d/sdk", priv->parsedUri->transport, hostname,
|
||||||
conn->uri->port);
|
conn->uri->port);
|
||||||
@ -723,7 +722,7 @@ esxConnectToVCenter(esxPrivate *priv,
|
|||||||
if (esxVI_Context_Alloc(&priv->vCenter) < 0 ||
|
if (esxVI_Context_Alloc(&priv->vCenter) < 0 ||
|
||||||
esxVI_Context_Connect(priv->vCenter, url, ipAddress, username,
|
esxVI_Context_Connect(priv->vCenter, url, ipAddress, username,
|
||||||
password, priv->parsedUri) < 0) {
|
password, priv->parsedUri) < 0) {
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (priv->vCenter->productLine != esxVI_ProductLine_VPX) {
|
if (priv->vCenter->productLine != esxVI_ProductLine_VPX) {
|
||||||
@ -732,25 +731,20 @@ esxConnectToVCenter(esxPrivate *priv,
|
|||||||
hostname,
|
hostname,
|
||||||
esxVI_ProductLineToDisplayName(esxVI_ProductLine_VPX),
|
esxVI_ProductLineToDisplayName(esxVI_ProductLine_VPX),
|
||||||
esxVI_ProductLineToDisplayName(priv->vCenter->productLine));
|
esxVI_ProductLineToDisplayName(priv->vCenter->productLine));
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hostSystemIPAddress) {
|
if (hostSystemIPAddress) {
|
||||||
if (esxVI_Context_LookupManagedObjectsByHostSystemIp
|
if (esxVI_Context_LookupManagedObjectsByHostSystemIp(priv->vCenter, hostSystemIPAddress) < 0)
|
||||||
(priv->vCenter, hostSystemIPAddress) < 0) {
|
return -1;
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (esxVI_Context_LookupManagedObjectsByPath(priv->vCenter,
|
if (esxVI_Context_LookupManagedObjectsByPath(priv->vCenter,
|
||||||
priv->parsedUri->path) < 0) {
|
priv->parsedUri->path) < 0) {
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
result = 0;
|
return 0;
|
||||||
|
|
||||||
cleanup:
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -667,7 +667,6 @@ static virStorageVolPtr
|
|||||||
esxStorageVolLookupByName(virStoragePoolPtr pool,
|
esxStorageVolLookupByName(virStoragePoolPtr pool,
|
||||||
const char *name)
|
const char *name)
|
||||||
{
|
{
|
||||||
virStorageVolPtr volume = NULL;
|
|
||||||
esxPrivate *priv = pool->conn->privateData;
|
esxPrivate *priv = pool->conn->privateData;
|
||||||
g_autofree char *datastorePath = NULL;
|
g_autofree char *datastorePath = NULL;
|
||||||
g_autofree char *key = NULL;
|
g_autofree char *key = NULL;
|
||||||
@ -676,14 +675,11 @@ esxStorageVolLookupByName(virStoragePoolPtr pool,
|
|||||||
|
|
||||||
if (esxVI_LookupStorageVolumeKeyByDatastorePath(priv->primary,
|
if (esxVI_LookupStorageVolumeKeyByDatastorePath(priv->primary,
|
||||||
datastorePath, &key) < 0) {
|
datastorePath, &key) < 0) {
|
||||||
goto cleanup;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
volume = virGetStorageVol(pool->conn, pool->name, name, key,
|
return virGetStorageVol(pool->conn, pool->name, name, key,
|
||||||
&esxStorageBackendVMFS, NULL);
|
&esxStorageBackendVMFS, NULL);
|
||||||
|
|
||||||
cleanup:
|
|
||||||
return volume;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -691,7 +687,6 @@ esxStorageVolLookupByName(virStoragePoolPtr pool,
|
|||||||
static virStorageVolPtr
|
static virStorageVolPtr
|
||||||
esxStorageVolLookupByPath(virConnectPtr conn, const char *path)
|
esxStorageVolLookupByPath(virConnectPtr conn, const char *path)
|
||||||
{
|
{
|
||||||
virStorageVolPtr volume = NULL;
|
|
||||||
esxPrivate *priv = conn->privateData;
|
esxPrivate *priv = conn->privateData;
|
||||||
g_autofree char *datastoreName = NULL;
|
g_autofree char *datastoreName = NULL;
|
||||||
g_autofree char *directoryAndFileName = NULL;
|
g_autofree char *directoryAndFileName = NULL;
|
||||||
@ -699,19 +694,16 @@ esxStorageVolLookupByPath(virConnectPtr conn, const char *path)
|
|||||||
|
|
||||||
if (esxUtil_ParseDatastorePath(path, &datastoreName, NULL,
|
if (esxUtil_ParseDatastorePath(path, &datastoreName, NULL,
|
||||||
&directoryAndFileName) < 0) {
|
&directoryAndFileName) < 0) {
|
||||||
goto cleanup;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (esxVI_LookupStorageVolumeKeyByDatastorePath(priv->primary, path,
|
if (esxVI_LookupStorageVolumeKeyByDatastorePath(priv->primary, path,
|
||||||
&key) < 0) {
|
&key) < 0) {
|
||||||
goto cleanup;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
volume = virGetStorageVol(conn, datastoreName, directoryAndFileName, key,
|
return virGetStorageVol(conn, datastoreName, directoryAndFileName, key,
|
||||||
&esxStorageBackendVMFS, NULL);
|
&esxStorageBackendVMFS, NULL);
|
||||||
|
|
||||||
cleanup:
|
|
||||||
return volume;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -429,7 +429,6 @@ esxUtil_EscapeDatastoreItem(const char *string)
|
|||||||
{
|
{
|
||||||
g_autofree char *replaced = NULL;
|
g_autofree char *replaced = NULL;
|
||||||
g_autofree char *escaped1 = NULL;
|
g_autofree char *escaped1 = NULL;
|
||||||
char *escaped2 = NULL;
|
|
||||||
|
|
||||||
replaced = g_strdup(string);
|
replaced = g_strdup(string);
|
||||||
|
|
||||||
@ -438,12 +437,9 @@ esxUtil_EscapeDatastoreItem(const char *string)
|
|||||||
escaped1 = virVMXEscapeHexPercent(replaced);
|
escaped1 = virVMXEscapeHexPercent(replaced);
|
||||||
|
|
||||||
if (!escaped1)
|
if (!escaped1)
|
||||||
goto cleanup;
|
return NULL;
|
||||||
|
|
||||||
escaped2 = esxUtil_EscapeBase64(escaped1);
|
return esxUtil_EscapeBase64(escaped1);
|
||||||
|
|
||||||
cleanup:
|
|
||||||
return escaped2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -830,7 +830,6 @@ esxVI_Context_Connect(esxVI_Context *ctx, const char *url,
|
|||||||
const char *ipAddress, const char *username,
|
const char *ipAddress, const char *username,
|
||||||
const char *password, esxUtil_ParsedUri *parsedUri)
|
const char *password, esxUtil_ParsedUri *parsedUri)
|
||||||
{
|
{
|
||||||
int result = -1;
|
|
||||||
g_autofree char *escapedPassword = NULL;
|
g_autofree char *escapedPassword = NULL;
|
||||||
|
|
||||||
if (!ctx || !url || !ipAddress || !username ||
|
if (!ctx || !url || !ipAddress || !username ||
|
||||||
@ -844,12 +843,12 @@ esxVI_Context_Connect(esxVI_Context *ctx, const char *url,
|
|||||||
if (!escapedPassword) {
|
if (!escapedPassword) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
_("Failed to escape password for XML"));
|
_("Failed to escape password for XML"));
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (esxVI_CURL_Alloc(&ctx->curl) < 0 ||
|
if (esxVI_CURL_Alloc(&ctx->curl) < 0 ||
|
||||||
esxVI_CURL_Connect(ctx->curl, parsedUri) < 0) {
|
esxVI_CURL_Connect(ctx->curl, parsedUri) < 0) {
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx->url = g_strdup(url);
|
ctx->url = g_strdup(url);
|
||||||
@ -863,18 +862,18 @@ esxVI_Context_Connect(esxVI_Context *ctx, const char *url,
|
|||||||
if (virMutexInit(ctx->sessionLock) < 0) {
|
if (virMutexInit(ctx->sessionLock) < 0) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
_("Could not initialize session mutex"));
|
_("Could not initialize session mutex"));
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (esxVI_RetrieveServiceContent(ctx, &ctx->service) < 0)
|
if (esxVI_RetrieveServiceContent(ctx, &ctx->service) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
if (STRNEQ(ctx->service->about->apiType, "HostAgent") &&
|
if (STRNEQ(ctx->service->about->apiType, "HostAgent") &&
|
||||||
STRNEQ(ctx->service->about->apiType, "VirtualCenter")) {
|
STRNEQ(ctx->service->about->apiType, "VirtualCenter")) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(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 cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virParseVersionString(ctx->service->about->apiVersion,
|
if (virParseVersionString(ctx->service->about->apiVersion,
|
||||||
@ -882,14 +881,14 @@ esxVI_Context_Connect(esxVI_Context *ctx, const char *url,
|
|||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("Could not parse VI API version '%s'"),
|
_("Could not parse VI API version '%s'"),
|
||||||
ctx->service->about->apiVersion);
|
ctx->service->about->apiVersion);
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ctx->apiVersion < 1000000 * 2 + 1000 * 5 /* 2.5 */) {
|
if (ctx->apiVersion < 1000000 * 2 + 1000 * 5 /* 2.5 */) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("Minimum supported %s version is %s but found version '%s'"),
|
_("Minimum supported %s version is %s but found version '%s'"),
|
||||||
"VI API", "2.5", ctx->service->about->apiVersion);
|
"VI API", "2.5", ctx->service->about->apiVersion);
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virParseVersionString(ctx->service->about->version,
|
if (virParseVersionString(ctx->service->about->version,
|
||||||
@ -897,7 +896,7 @@ esxVI_Context_Connect(esxVI_Context *ctx, const char *url,
|
|||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("Could not parse product version '%s'"),
|
_("Could not parse product version '%s'"),
|
||||||
ctx->service->about->version);
|
ctx->service->about->version);
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (STREQ(ctx->service->about->productLineId, "gsx")) {
|
if (STREQ(ctx->service->about->productLineId, "gsx")) {
|
||||||
@ -906,7 +905,7 @@ esxVI_Context_Connect(esxVI_Context *ctx, const char *url,
|
|||||||
_("Minimum supported %s version is %s but found version '%s'"),
|
_("Minimum supported %s version is %s but found version '%s'"),
|
||||||
esxVI_ProductLineToDisplayName(esxVI_ProductLine_GSX),
|
esxVI_ProductLineToDisplayName(esxVI_ProductLine_GSX),
|
||||||
"2.0", ctx->service->about->version);
|
"2.0", ctx->service->about->version);
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx->productLine = esxVI_ProductLine_GSX;
|
ctx->productLine = esxVI_ProductLine_GSX;
|
||||||
@ -917,7 +916,7 @@ esxVI_Context_Connect(esxVI_Context *ctx, const char *url,
|
|||||||
_("Minimum supported %s version is %s but found version '%s'"),
|
_("Minimum supported %s version is %s but found version '%s'"),
|
||||||
esxVI_ProductLineToDisplayName(esxVI_ProductLine_ESX),
|
esxVI_ProductLineToDisplayName(esxVI_ProductLine_ESX),
|
||||||
"3.5", ctx->service->about->version);
|
"3.5", ctx->service->about->version);
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx->productLine = esxVI_ProductLine_ESX;
|
ctx->productLine = esxVI_ProductLine_ESX;
|
||||||
@ -927,7 +926,7 @@ esxVI_Context_Connect(esxVI_Context *ctx, const char *url,
|
|||||||
_("Minimum supported %s version is %s but found version '%s'"),
|
_("Minimum supported %s version is %s but found version '%s'"),
|
||||||
esxVI_ProductLineToDisplayName(esxVI_ProductLine_VPX),
|
esxVI_ProductLineToDisplayName(esxVI_ProductLine_VPX),
|
||||||
"2.5", ctx->service->about->version);
|
"2.5", ctx->service->about->version);
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx->productLine = esxVI_ProductLine_VPX;
|
ctx->productLine = esxVI_ProductLine_VPX;
|
||||||
@ -936,7 +935,7 @@ esxVI_Context_Connect(esxVI_Context *ctx, const char *url,
|
|||||||
_("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 cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ctx->productLine == esxVI_ProductLine_ESX) {
|
if (ctx->productLine == esxVI_ProductLine_ESX) {
|
||||||
@ -957,13 +956,10 @@ esxVI_Context_Connect(esxVI_Context *ctx, const char *url,
|
|||||||
|
|
||||||
if (esxVI_Login(ctx, username, escapedPassword, NULL, &ctx->session) < 0 ||
|
if (esxVI_Login(ctx, username, escapedPassword, NULL, &ctx->session) < 0 ||
|
||||||
esxVI_BuildSelectSetCollection(ctx) < 0) {
|
esxVI_BuildSelectSetCollection(ctx) < 0) {
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
result = 0;
|
return 0;
|
||||||
|
|
||||||
cleanup:
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
@ -4093,7 +4089,6 @@ esxVI_HandleVirtualMachineQuestion
|
|||||||
esxVI_VirtualMachineQuestionInfo *questionInfo, bool autoAnswer,
|
esxVI_VirtualMachineQuestionInfo *questionInfo, bool autoAnswer,
|
||||||
bool *blocked)
|
bool *blocked)
|
||||||
{
|
{
|
||||||
int result = -1;
|
|
||||||
esxVI_ElementDescription *elementDescription = NULL;
|
esxVI_ElementDescription *elementDescription = NULL;
|
||||||
g_auto(virBuffer) buffer = VIR_BUFFER_INITIALIZER;
|
g_auto(virBuffer) buffer = VIR_BUFFER_INITIALIZER;
|
||||||
esxVI_ElementDescription *answerChoice = NULL;
|
esxVI_ElementDescription *answerChoice = NULL;
|
||||||
@ -4136,7 +4131,7 @@ esxVI_HandleVirtualMachineQuestion
|
|||||||
questionInfo->text);
|
questionInfo->text);
|
||||||
|
|
||||||
*blocked = true;
|
*blocked = true;
|
||||||
goto cleanup;
|
return -1;
|
||||||
} else if (!answerChoice) {
|
} else if (!answerChoice) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("Pending question blocks virtual machine execution, "
|
_("Pending question blocks virtual machine execution, "
|
||||||
@ -4145,7 +4140,7 @@ esxVI_HandleVirtualMachineQuestion
|
|||||||
possibleAnswers);
|
possibleAnswers);
|
||||||
|
|
||||||
*blocked = true;
|
*blocked = true;
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
VIR_INFO("Pending question blocks virtual machine execution, "
|
VIR_INFO("Pending question blocks virtual machine execution, "
|
||||||
@ -4155,7 +4150,7 @@ esxVI_HandleVirtualMachineQuestion
|
|||||||
|
|
||||||
if (esxVI_AnswerVM(ctx, virtualMachine, questionInfo->id,
|
if (esxVI_AnswerVM(ctx, virtualMachine, questionInfo->id,
|
||||||
answerChoice->key) < 0) {
|
answerChoice->key) < 0) {
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (possibleAnswers) {
|
if (possibleAnswers) {
|
||||||
@ -4171,13 +4166,11 @@ esxVI_HandleVirtualMachineQuestion
|
|||||||
}
|
}
|
||||||
|
|
||||||
*blocked = true;
|
*blocked = true;
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
result = 0;
|
return 0;
|
||||||
|
|
||||||
cleanup:
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -700,7 +700,6 @@ static int
|
|||||||
esxVI_GetActualObjectType(xmlNodePtr node, esxVI_Type baseType,
|
esxVI_GetActualObjectType(xmlNodePtr node, esxVI_Type baseType,
|
||||||
esxVI_Type *actualType)
|
esxVI_Type *actualType)
|
||||||
{
|
{
|
||||||
int result = -1;
|
|
||||||
g_autofree char *type = NULL;
|
g_autofree char *type = NULL;
|
||||||
|
|
||||||
if (!actualType || *actualType != esxVI_Type_Undefined) {
|
if (!actualType || *actualType != esxVI_Type_Undefined) {
|
||||||
@ -724,13 +723,10 @@ esxVI_GetActualObjectType(xmlNodePtr node, esxVI_Type baseType,
|
|||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("Unknown value '%s' for %s 'type' property"),
|
_("Unknown value '%s' for %s 'type' property"),
|
||||||
type, esxVI_Type_ToString(baseType));
|
type, esxVI_Type_ToString(baseType));
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
result = 0;
|
return 0;
|
||||||
|
|
||||||
cleanup:
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user