Remove unnecessary curly brackets in rest of src/esx/

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
This commit is contained in:
Martin Kletzander 2014-11-13 15:22:20 +01:00
parent 090cb1e63c
commit 247ad91541
11 changed files with 198 additions and 396 deletions

View File

@ -43,9 +43,8 @@ esxNodeDeviceOpen(virConnectPtr conn,
{
virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
if (conn->driver->no != VIR_DRV_ESX) {
if (conn->driver->no != VIR_DRV_ESX)
return VIR_DRV_OPEN_DECLINED;
}
return VIR_DRV_OPEN_SUCCESS;
}

View File

@ -46,9 +46,8 @@ esxInterfaceOpen(virConnectPtr conn,
{
virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
if (conn->driver->no != VIR_DRV_ESX) {
if (conn->driver->no != VIR_DRV_ESX)
return VIR_DRV_OPEN_DECLINED;
}
return VIR_DRV_OPEN_SUCCESS;
}
@ -98,9 +97,8 @@ esxConnectListInterfaces(virConnectPtr conn, char **const names, int maxnames)
int count = 0;
size_t i;
if (maxnames == 0) {
if (maxnames == 0)
return 0;
}
if (esxVI_EnsureSession(priv->primary) < 0 ||
esxVI_LookupPhysicalNicList(priv->primary, &physicalNicList) < 0) {
@ -119,9 +117,8 @@ esxConnectListInterfaces(virConnectPtr conn, char **const names, int maxnames)
cleanup:
if (! success) {
for (i = 0; i < count; ++i) {
for (i = 0; i < count; ++i)
VIR_FREE(names[i]);
}
count = -1;
}
@ -234,9 +231,8 @@ esxInterfaceGetXMLDesc(virInterfacePtr iface, unsigned int flags)
if (physicalNic->spec->ip) {
protocol.family = (char *)"ipv4";
if (physicalNic->spec->ip->dhcp == esxVI_Boolean_True) {
if (physicalNic->spec->ip->dhcp == esxVI_Boolean_True)
protocol.dhcp = 1;
}
if (physicalNic->spec->ip->ipAddress &&
physicalNic->spec->ip->subnetMask &&

View File

@ -52,9 +52,8 @@ esxNetworkOpen(virConnectPtr conn,
{
virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
if (conn->driver->no != VIR_DRV_ESX) {
if (conn->driver->no != VIR_DRV_ESX)
return VIR_DRV_OPEN_DECLINED;
}
return VIR_DRV_OPEN_SUCCESS;
}
@ -105,9 +104,8 @@ esxConnectListNetworks(virConnectPtr conn, char **const names, int maxnames)
int count = 0;
size_t i;
if (maxnames == 0) {
if (maxnames == 0)
return 0;
}
if (esxVI_EnsureSession(priv->primary) < 0 ||
esxVI_LookupHostVirtualSwitchList(priv->primary,
@ -127,9 +125,8 @@ esxConnectListNetworks(virConnectPtr conn, char **const names, int maxnames)
cleanup:
if (! success) {
for (i = 0; i < count; ++i) {
for (i = 0; i < count; ++i)
VIR_FREE(names[i]);
}
count = -1;
}
@ -181,10 +178,9 @@ esxNetworkLookupByUUID(virConnectPtr conn, const unsigned char *uuid)
hostVirtualSwitch = hostVirtualSwitch->_next) {
md5_buffer(hostVirtualSwitch->key, strlen(hostVirtualSwitch->key), md5);
if (memcmp(uuid, md5, VIR_UUID_BUFLEN) == 0) {
if (memcmp(uuid, md5, VIR_UUID_BUFLEN) == 0)
break;
}
}
if (!hostVirtualSwitch) {
virUUIDFormat(uuid, uuid_string);
@ -265,34 +261,30 @@ esxBandwidthToShapingPolicy(virNetDevBandwidthPtr bandwidth,
return 0;
}
if (esxVI_HostNetworkTrafficShapingPolicy_Alloc(shapingPolicy) < 0) {
if (esxVI_HostNetworkTrafficShapingPolicy_Alloc(shapingPolicy) < 0)
goto cleanup;
}
(*shapingPolicy)->enabled = esxVI_Boolean_True;
if (bandwidth->in->average > 0) {
if (esxVI_Long_Alloc(&(*shapingPolicy)->averageBandwidth) < 0) {
if (esxVI_Long_Alloc(&(*shapingPolicy)->averageBandwidth) < 0)
goto cleanup;
}
/* Scale kilobytes per second to bits per second */
(*shapingPolicy)->averageBandwidth->value = bandwidth->in->average * 8 * 1000;
}
if (bandwidth->in->peak > 0) {
if (esxVI_Long_Alloc(&(*shapingPolicy)->peakBandwidth) < 0) {
if (esxVI_Long_Alloc(&(*shapingPolicy)->peakBandwidth) < 0)
goto cleanup;
}
/* Scale kilobytes per second to bits per second */
(*shapingPolicy)->peakBandwidth->value = bandwidth->in->peak * 8 * 1000;
}
if (bandwidth->in->burst > 0) {
if (esxVI_Long_Alloc(&(*shapingPolicy)->burstSize) < 0) {
if (esxVI_Long_Alloc(&(*shapingPolicy)->burstSize) < 0)
goto cleanup;
}
/* Scale kilobytes to bytes */
(*shapingPolicy)->burstSize->value = bandwidth->in->burst * 1024;
@ -301,9 +293,8 @@ esxBandwidthToShapingPolicy(virNetDevBandwidthPtr bandwidth,
result = 0;
cleanup:
if (result < 0) {
if (result < 0)
esxVI_HostNetworkTrafficShapingPolicy_Free(shapingPolicy);
}
return result;
}
@ -328,16 +319,14 @@ esxNetworkDefineXML(virConnectPtr conn, const char *xml)
unsigned char md5[MD5_DIGEST_SIZE]; /* MD5_DIGEST_SIZE = VIR_UUID_BUFLEN = 16 */
if (esxVI_EnsureSession(priv->primary) < 0) {
if (esxVI_EnsureSession(priv->primary) < 0)
return NULL;
}
/* Parse network XML */
def = virNetworkDefParseString(xml);
if (!def) {
if (!def)
return NULL;
}
/* Check if an existing HostVirtualSwitch should be edited */
if (esxVI_LookupHostVirtualSwitchByName(priv->primary, def->name,
@ -372,9 +361,8 @@ esxNetworkDefineXML(virConnectPtr conn, const char *xml)
/* Verify that specified HostPortGroups don't exist already */
if (def->nPortGroups > 0) {
if (esxVI_LookupHostPortGroupList(priv->primary, &hostPortGroupList) < 0) {
if (esxVI_LookupHostPortGroupList(priv->primary, &hostPortGroupList) < 0)
goto cleanup;
}
for (i = 0; i < def->nPortGroups; ++i) {
for (hostPortGroup = hostPortGroupList; hostPortGroup;
@ -405,9 +393,8 @@ esxNetworkDefineXML(virConnectPtr conn, const char *xml)
(esxVI_HostVirtualSwitchBridge *)hostVirtualSwitchBondBridge;
/* Lookup PhysicalNic list and match by name to get key */
if (esxVI_LookupPhysicalNicList(priv->primary, &physicalNicList) < 0) {
if (esxVI_LookupPhysicalNicList(priv->primary, &physicalNicList) < 0)
goto cleanup;
}
for (i = 0; i < def->forward.nifs; ++i) {
bool found = false;
@ -447,9 +434,8 @@ esxNetworkDefineXML(virConnectPtr conn, const char *xml)
hostVirtualSwitchSpec->numPorts->value = 128;
if (def->bandwidth) {
if (esxVI_HostNetworkPolicy_Alloc(&hostVirtualSwitchSpec->policy) < 0) {
if (esxVI_HostNetworkPolicy_Alloc(&hostVirtualSwitchSpec->policy) < 0)
goto cleanup;
}
if (esxBandwidthToShapingPolicy
(def->bandwidth,
@ -530,9 +516,8 @@ esxNetworkUndefine(virNetworkPtr network)
esxVI_HostPortGroup *hostPortGroup = NULL;
esxVI_HostPortGroupPort *hostPortGroupPort = NULL;
if (esxVI_EnsureSession(priv->primary) < 0) {
if (esxVI_EnsureSession(priv->primary) < 0)
return -1;
}
/* Lookup HostVirtualSwitch and HostPortGroup list*/
if (esxVI_LookupHostVirtualSwitchByName(priv->primary, network->name,
@ -630,9 +615,8 @@ esxShapingPolicyToBandwidth(esxVI_HostNetworkTrafficShapingPolicy *shapingPolicy
return -1;
}
if (!shapingPolicy || shapingPolicy->enabled != esxVI_Boolean_True) {
if (!shapingPolicy || shapingPolicy->enabled != esxVI_Boolean_True)
return 0;
}
if (VIR_ALLOC(*bandwidth) < 0 ||
VIR_ALLOC((*bandwidth)->in) < 0 ||
@ -682,9 +666,8 @@ esxNetworkGetXMLDesc(virNetworkPtr network_, unsigned int flags)
esxVI_String *networkName = NULL;
virNetworkDefPtr def;
if (esxVI_EnsureSession(priv->primary) < 0) {
if (esxVI_EnsureSession(priv->primary) < 0)
return NULL;
}
if (VIR_ALLOC(def) < 0)
goto cleanup;
@ -718,9 +701,8 @@ esxNetworkGetXMLDesc(virNetworkPtr network_, unsigned int flags)
goto cleanup;
/* Find PhysicalNic by key */
if (esxVI_LookupPhysicalNicList(priv->primary, &physicalNicList) < 0) {
if (esxVI_LookupPhysicalNicList(priv->primary, &physicalNicList) < 0)
goto cleanup;
}
for (physicalNicKey = hostVirtualSwitch->pnic;
physicalNicKey; physicalNicKey = physicalNicKey->_next) {
@ -781,9 +763,8 @@ esxNetworkGetXMLDesc(virNetworkPtr network_, unsigned int flags)
}
/* Find HostPortGroup by key */
if (esxVI_LookupHostPortGroupList(priv->primary, &hostPortGroupList) < 0) {
if (esxVI_LookupHostPortGroupList(priv->primary, &hostPortGroupList) < 0)
goto cleanup;
}
for (hostPortGroupKey = hostVirtualSwitch->portgroup;
hostPortGroupKey; hostPortGroupKey = hostPortGroupKey->_next) {

View File

@ -43,9 +43,8 @@ esxNWFilterOpen(virConnectPtr conn,
{
virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
if (conn->driver->no != VIR_DRV_ESX) {
if (conn->driver->no != VIR_DRV_ESX)
return VIR_DRV_OPEN_DECLINED;
}
return VIR_DRV_OPEN_SUCCESS;
}

View File

@ -41,9 +41,8 @@ esxSecretOpen(virConnectPtr conn, virConnectAuthPtr auth ATTRIBUTE_UNUSED,
{
virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
if (conn->driver->no != VIR_DRV_ESX) {
if (conn->driver->no != VIR_DRV_ESX)
return VIR_DRV_OPEN_DECLINED;
}
return VIR_DRV_OPEN_SUCCESS;
}

View File

@ -104,9 +104,8 @@ esxConnectListStoragePools(virConnectPtr conn, char **const names,
esxVI_HostInternetScsiHbaStaticTarget *target;
size_t i;
if (maxnames == 0) {
if (maxnames == 0)
return 0;
}
if (esxVI_LookupHostInternetScsiHba(priv->primary,
&hostInternetScsiHba) < 0) {
@ -140,10 +139,9 @@ esxConnectListStoragePools(virConnectPtr conn, char **const names,
cleanup:
if (! success) {
for (i = 0; i < count; ++i) {
for (i = 0; i < count; ++i)
VIR_FREE(names[i]);
}
}
esxVI_HostInternetScsiHba_Free(&hostInternetScsiHba);
@ -222,10 +220,9 @@ esxStoragePoolLookupByUUID(virConnectPtr conn,
target; target = target->_next) {
md5_buffer(target->iScsiName, strlen(target->iScsiName), md5);
if (memcmp(uuid, md5, VIR_UUID_STRING_BUFLEN) == 0) {
if (memcmp(uuid, md5, VIR_UUID_STRING_BUFLEN) == 0)
break;
}
}
if (!target) {
/* pool not found, error handling done by the base driver */
@ -304,16 +301,14 @@ esxStoragePoolGetXMLDesc(virStoragePoolPtr pool, unsigned int flags)
memset(&def, 0, sizeof(def));
if (esxVI_LookupHostInternetScsiHba(priv->primary, &hostInternetScsiHba)) {
if (esxVI_LookupHostInternetScsiHba(priv->primary, &hostInternetScsiHba))
goto cleanup;
}
for (target = hostInternetScsiHba->configuredStaticTarget;
target; target = target->_next) {
if (STREQ(target->iScsiName, pool->name)) {
if (STREQ(target->iScsiName, pool->name))
break;
}
}
if (!target) {
/* pool not found */
@ -338,9 +333,8 @@ esxStoragePoolGetXMLDesc(virStoragePoolPtr pool, unsigned int flags)
def.source.hosts[0].name = target->address;
if (target->port) {
if (target->port)
def.source.hosts[0].port = target->port->value;
}
/* TODO: add CHAP authentication params */
xml = virStoragePoolDefFormat(&def);
@ -403,9 +397,8 @@ esxStoragePoolListVolumes(virStoragePoolPtr pool, char **const names,
return 0;
}
if (esxVI_LookupScsiLunList(priv->primary, &scsiLunList) < 0) {
if (esxVI_LookupScsiLunList(priv->primary, &scsiLunList) < 0)
goto cleanup;
}
for (scsiLun = scsiLunList; scsiLun && count < maxnames;
scsiLun = scsiLun->_next) {
@ -425,9 +418,8 @@ esxStoragePoolListVolumes(virStoragePoolPtr pool, char **const names,
cleanup:
if (! success) {
for (i = 0; i < count; ++i) {
for (i = 0; i < count; ++i)
VIR_FREE(names[i]);
}
count = -1;
}
@ -452,9 +444,8 @@ esxStorageVolLookupByName(virStoragePoolPtr pool,
unsigned char md5[MD5_DIGEST_SIZE];
char uuid_string[VIR_UUID_STRING_BUFLEN] = "";
if (esxVI_LookupScsiLunList(priv->primary, &scsiLunList) < 0) {
if (esxVI_LookupScsiLunList(priv->primary, &scsiLunList) < 0)
goto cleanup;
}
for (scsiLun = scsiLunList; scsiLun;
scsiLun = scsiLun->_next) {
@ -500,9 +491,8 @@ esxStorageVolLookupByPath(virConnectPtr conn, const char *path)
unsigned char md5[MD5_DIGEST_SIZE];
char uuid_string[VIR_UUID_STRING_BUFLEN] = "";
if (esxVI_LookupScsiLunList(priv->primary, &scsiLunList) < 0) {
if (esxVI_LookupScsiLunList(priv->primary, &scsiLunList) < 0)
goto cleanup;
}
for (scsiLun = scsiLunList; scsiLun; scsiLun = scsiLun->_next) {
hostScsiDisk = esxVI_HostScsiDisk_DynamicCast(scsiLun);
@ -548,13 +538,11 @@ esxStorageVolLookupByKey(virConnectPtr conn, const char *key)
char uuid_string[VIR_UUID_STRING_BUFLEN] = "";
/* key may be LUN device path */
if (STRPREFIX(key, "/")) {
if (STRPREFIX(key, "/"))
return esxStorageVolLookupByPath(conn, key);
}
if (esxVI_LookupScsiLunList(priv->primary, &scsiLunList) < 0) {
if (esxVI_LookupScsiLunList(priv->primary, &scsiLunList) < 0)
goto cleanup;
}
for (scsiLun = scsiLunList; scsiLun;
scsiLun = scsiLun->_next) {
@ -631,9 +619,8 @@ esxStorageVolGetInfo(virStorageVolPtr volume,
esxVI_ScsiLun *scsiLun;
esxVI_HostScsiDisk *hostScsiDisk = NULL;
if (esxVI_LookupScsiLunList(priv->primary, &scsiLunList) < 0) {
if (esxVI_LookupScsiLunList(priv->primary, &scsiLunList) < 0)
goto cleanup;
}
for (scsiLun = scsiLunList; scsiLun;
scsiLun = scsiLun->_next) {
@ -687,9 +674,8 @@ esxStorageVolGetXMLDesc(virStorageVolPtr volume,
memset(&pool, 0, sizeof(pool));
memset(&def, 0, sizeof(def));
if (esxVI_LookupScsiLunList(priv->primary, &scsiLunList) < 0) {
if (esxVI_LookupScsiLunList(priv->primary, &scsiLunList) < 0)
goto cleanup;
}
for (scsiLun = scsiLunList; scsiLun;
scsiLun = scsiLun->_next) {
@ -715,9 +701,8 @@ esxStorageVolGetXMLDesc(virStorageVolPtr volume,
virUUIDFormat(md5, uuid_string);
if (VIR_STRDUP(def.key, uuid_string) < 0) {
if (VIR_STRDUP(def.key, uuid_string) < 0)
goto cleanup;
}
/* iSCSI LUN exposes a block device */
def.type = VIR_STORAGE_VOL_BLOCK;

View File

@ -120,9 +120,8 @@ esxConnectNumOfStoragePools(virConnectPtr conn)
esxVI_ObjectContent *datastoreList = NULL;
esxVI_ObjectContent *datastore = NULL;
if (esxVI_LookupDatastoreList(priv->primary, NULL, &datastoreList) < 0) {
if (esxVI_LookupDatastoreList(priv->primary, NULL, &datastoreList) < 0)
return -1;
}
for (datastore = datastoreList; datastore;
datastore = datastore->_next) {
@ -149,9 +148,8 @@ esxConnectListStoragePools(virConnectPtr conn, char **const names,
int count = 0;
size_t i;
if (maxnames == 0) {
if (maxnames == 0)
return 0;
}
if (esxVI_String_AppendValueToList(&propertyNameList,
"summary.name") < 0 ||
@ -185,9 +183,8 @@ esxConnectListStoragePools(virConnectPtr conn, char **const names,
cleanup:
if (! success) {
for (i = 0; i < count; ++i) {
for (i = 0; i < count; ++i)
VIR_FREE(names[i]);
}
count = -1;
}
@ -295,10 +292,9 @@ esxStoragePoolLookupByUUID(virConnectPtr conn,
md5_buffer(hostMount->mountInfo->path,
strlen(hostMount->mountInfo->path), md5);
if (memcmp(uuid, md5, VIR_UUID_BUFLEN) == 0) {
if (memcmp(uuid, md5, VIR_UUID_BUFLEN) == 0)
break;
}
}
if (!datastore) {
/* Not found, let the base storage driver handle error reporting */
@ -580,9 +576,8 @@ esxStoragePoolListVolumes(virStoragePoolPtr pool, char **const names,
return -1;
}
if (maxnames == 0) {
if (maxnames == 0)
return 0;
}
if (esxVI_LookupDatastoreContentByDatastoreName(priv->primary, pool->name,
&searchResultsList) < 0) {
@ -626,9 +621,8 @@ esxStoragePoolListVolumes(virStoragePoolPtr pool, char **const names,
cleanup:
if (! success) {
for (i = 0; i < count; ++i) {
for (i = 0; i < count; ++i)
VIR_FREE(names[i]);
}
count = -1;
}
@ -807,9 +801,8 @@ esxStorageVolLookupByKey(virConnectPtr conn, const char *key)
goto cleanup;
}
if (esxUtil_ReformatUuid(uuid_string, key_candidate) < 0) {
if (esxUtil_ReformatUuid(uuid_string, key_candidate) < 0)
goto cleanup;
}
if (STREQ(key, key_candidate)) {
/* Found matching UUID */
@ -873,9 +866,8 @@ esxStorageVolCreateXML(virStoragePoolPtr pool,
/* Parse config */
def = virStorageVolDefParseString(&poolDef, xmldesc);
if (!def) {
if (!def)
goto cleanup;
}
if (def->type != VIR_STORAGE_VOL_FILE) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
@ -914,16 +906,14 @@ esxStorageVolCreateXML(virStoragePoolPtr pool,
directoryName = esxUtil_EscapeDatastoreItem(unescapedDirectoryName);
if (!directoryName) {
if (!directoryName)
goto cleanup;
}
fileName = esxUtil_EscapeDatastoreItem(unescapedDirectoryAndFileName +
strlen(unescapedDirectoryName) + 1);
if (!fileName) {
if (!fileName)
goto cleanup;
}
if (virAsprintf(&datastorePathWithoutFileName, "[%s] %s", pool->name,
directoryName) < 0)
@ -1012,15 +1002,13 @@ esxStorageVolCreateXML(virStoragePoolPtr pool,
goto cleanup;
}
if (esxUtil_ReformatUuid(uuid_string, key) < 0) {
if (esxUtil_ReformatUuid(uuid_string, key) < 0)
goto cleanup;
}
} else {
/* Fall back to the path as key */
if (VIR_STRDUP(key, datastorePath) < 0) {
if (VIR_STRDUP(key, datastorePath) < 0)
goto cleanup;
}
}
} else {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Creation of %s volumes is not supported"),
@ -1099,9 +1087,8 @@ esxStorageVolCreateXMLFrom(virStoragePoolPtr pool,
/* Parse config */
def = virStorageVolDefParseString(&poolDef, xmldesc);
if (!def) {
if (!def)
goto cleanup;
}
if (def->type != VIR_STORAGE_VOL_FILE) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
@ -1140,16 +1127,14 @@ esxStorageVolCreateXMLFrom(virStoragePoolPtr pool,
directoryName = esxUtil_EscapeDatastoreItem(unescapedDirectoryName);
if (!directoryName) {
if (!directoryName)
goto cleanup;
}
fileName = esxUtil_EscapeDatastoreItem(unescapedDirectoryAndFileName +
strlen(unescapedDirectoryName) + 1);
if (!fileName) {
if (!fileName)
goto cleanup;
}
if (virAsprintf(&datastorePathWithoutFileName, "[%s] %s", pool->name,
directoryName) < 0)
@ -1204,15 +1189,13 @@ esxStorageVolCreateXMLFrom(virStoragePoolPtr pool,
goto cleanup;
}
if (esxUtil_ReformatUuid(uuid_string, key) < 0) {
if (esxUtil_ReformatUuid(uuid_string, key) < 0)
goto cleanup;
}
} else {
/* Fall back to the path as key */
if (VIR_STRDUP(key, datastorePath) < 0) {
if (VIR_STRDUP(key, datastorePath) < 0)
goto cleanup;
}
}
} else {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Creation of %s volumes is not supported"),

View File

@ -60,9 +60,8 @@ esxStorageOpen(virConnectPtr conn,
{
virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
if (conn->driver->no != VIR_DRV_ESX) {
if (conn->driver->no != VIR_DRV_ESX)
return VIR_DRV_OPEN_DECLINED;
}
return VIR_DRV_OPEN_SUCCESS;
}
@ -85,16 +84,14 @@ esxConnectNumOfStoragePools(virConnectPtr conn)
size_t i;
int tmp;
if (esxVI_EnsureSession(priv->primary) < 0) {
if (esxVI_EnsureSession(priv->primary) < 0)
return -1;
}
for (i = 0; i < LAST_BACKEND; ++i) {
tmp = backends[i]->connectNumOfStoragePools(conn);
if (tmp < 0) {
if (tmp < 0)
return -1;
}
count += tmp;
}
@ -113,20 +110,17 @@ esxConnectListStoragePools(virConnectPtr conn, char **const names, int maxnames)
size_t i;
int tmp;
if (maxnames == 0) {
if (maxnames == 0)
return 0;
}
if (esxVI_EnsureSession(priv->primary) < 0) {
if (esxVI_EnsureSession(priv->primary) < 0)
return -1;
}
for (i = 0; i < LAST_BACKEND; ++i) {
tmp = backends[i]->connectListStoragePools(conn, &names[count], maxnames - count);
if (tmp < 0) {
if (tmp < 0)
goto cleanup;
}
count += tmp;
}
@ -135,9 +129,8 @@ esxConnectListStoragePools(virConnectPtr conn, char **const names, int maxnames)
cleanup:
if (! success) {
for (i = 0; i < count; ++i) {
for (i = 0; i < count; ++i)
VIR_FREE(names[i]);
}
count = -1;
}
@ -176,17 +169,15 @@ esxStoragePoolLookupByName(virConnectPtr conn, const char *name)
virCheckNonNullArgReturn(name, NULL);
if (esxVI_EnsureSession(priv->primary) < 0) {
if (esxVI_EnsureSession(priv->primary) < 0)
return NULL;
}
for (i = 0; i < LAST_BACKEND; ++i) {
pool = backends[i]->storagePoolLookupByName(conn, name);
if (pool) {
if (pool)
return pool;
}
}
virReportError(VIR_ERR_NO_STORAGE_POOL,
_("Could not find storage pool with name '%s'"), name);
@ -204,18 +195,16 @@ esxStoragePoolLookupByUUID(virConnectPtr conn, const unsigned char *uuid)
virStoragePoolPtr pool;
char uuid_string[VIR_UUID_STRING_BUFLEN] = "";
if (esxVI_EnsureSession(priv->primary) < 0) {
if (esxVI_EnsureSession(priv->primary) < 0)
return NULL;
}
/* invoke backend drive method to search all known pools */
for (i = 0; i < LAST_BACKEND; ++i) {
pool = backends[i]->storagePoolLookupByUUID(conn, uuid);
if (pool) {
if (pool)
return pool;
}
}
virUUIDFormat(uuid, uuid_string);
virReportError(VIR_ERR_NO_STORAGE_POOL,
@ -243,9 +232,8 @@ esxStoragePoolRefresh(virStoragePoolPtr pool, unsigned int flags)
virCheckNonNullArgReturn(pool->privateData, -1);
if (esxVI_EnsureSession(priv->primary) < 0) {
if (esxVI_EnsureSession(priv->primary) < 0)
return -1;
}
return backend->storagePoolRefresh(pool, flags);
}
@ -262,9 +250,8 @@ esxStoragePoolGetInfo(virStoragePoolPtr pool, virStoragePoolInfoPtr info)
memset(info, 0, sizeof(*info));
if (esxVI_EnsureSession(priv->primary) < 0) {
if (esxVI_EnsureSession(priv->primary) < 0)
return -1;
}
return backend->storagePoolGetInfo(pool, info);
}
@ -279,9 +266,8 @@ esxStoragePoolGetXMLDesc(virStoragePoolPtr pool, unsigned int flags)
virCheckNonNullArgReturn(pool->privateData, NULL);
if (esxVI_EnsureSession(priv->primary) < 0) {
if (esxVI_EnsureSession(priv->primary) < 0)
return NULL;
}
return backend->storagePoolGetXMLDesc(pool, flags);
}
@ -326,9 +312,8 @@ esxStoragePoolNumOfVolumes(virStoragePoolPtr pool)
virCheckNonNullArgReturn(pool->privateData, -1);
if (esxVI_EnsureSession(priv->primary) < 0) {
if (esxVI_EnsureSession(priv->primary) < 0)
return -1;
}
return backend->storagePoolNumOfVolumes(pool);
}
@ -344,9 +329,8 @@ esxStoragePoolListVolumes(virStoragePoolPtr pool, char **const names,
virCheckNonNullArgReturn(pool->privateData, -1);
if (esxVI_EnsureSession(priv->primary) < 0) {
if (esxVI_EnsureSession(priv->primary) < 0)
return -1;
}
return backend->storagePoolListVolumes(pool, names, maxnames);
}
@ -361,9 +345,8 @@ esxStorageVolLookupByName(virStoragePoolPtr pool, const char *name)
virCheckNonNullArgReturn(pool->privateData, NULL);
if (esxVI_EnsureSession(priv->primary) < 0) {
if (esxVI_EnsureSession(priv->primary) < 0)
return NULL;
}
return backend->storageVolLookupByName(pool, name);
}
@ -375,9 +358,8 @@ esxStorageVolLookupByPath(virConnectPtr conn, const char *path)
{
esxPrivate *priv = conn->privateData;
if (esxVI_EnsureSession(priv->primary) < 0) {
if (esxVI_EnsureSession(priv->primary) < 0)
return NULL;
}
/*
* FIXME: calling backends blindly may set unwanted error codes
@ -408,17 +390,15 @@ esxStorageVolLookupByKey(virConnectPtr conn, const char *key)
esxPrivate *priv = conn->privateData;
size_t i;
if (esxVI_EnsureSession(priv->primary) < 0) {
if (esxVI_EnsureSession(priv->primary) < 0)
return NULL;
}
for (i = 0; i < LAST_BACKEND; ++i) {
volume = backends[i]->storageVolLookupByKey(conn, key);
if (volume) {
if (volume)
return volume;
}
}
virReportError(VIR_ERR_NO_STORAGE_VOL,
_("Could not find storage volume with key '%s'"),
@ -438,9 +418,8 @@ esxStorageVolCreateXML(virStoragePoolPtr pool, const char *xmldesc,
virCheckNonNullArgReturn(pool->privateData, NULL);
if (esxVI_EnsureSession(priv->primary) < 0) {
if (esxVI_EnsureSession(priv->primary) < 0)
return NULL;
}
return backend->storageVolCreateXML(pool, xmldesc, flags);
}
@ -456,9 +435,8 @@ esxStorageVolCreateXMLFrom(virStoragePoolPtr pool, const char *xmldesc,
virCheckNonNullArgReturn(pool->privateData, NULL);
if (esxVI_EnsureSession(priv->primary) < 0) {
if (esxVI_EnsureSession(priv->primary) < 0)
return NULL;
}
return backend->storageVolCreateXMLFrom(pool, xmldesc, sourceVolume, flags);
}
@ -473,9 +451,8 @@ esxStorageVolDelete(virStorageVolPtr volume, unsigned int flags)
virCheckNonNullArgReturn(volume->privateData, -1);
if (esxVI_EnsureSession(priv->primary) < 0) {
if (esxVI_EnsureSession(priv->primary) < 0)
return -1;
}
return backend->storageVolDelete(volume, flags);
}
@ -490,9 +467,8 @@ esxStorageVolWipe(virStorageVolPtr volume, unsigned int flags)
virCheckNonNullArgReturn(volume->privateData, -1);
if (esxVI_EnsureSession(priv->primary) < 0) {
if (esxVI_EnsureSession(priv->primary) < 0)
return -1;
}
return backend->storageVolWipe(volume, flags);
}
@ -507,9 +483,8 @@ esxStorageVolGetInfo(virStorageVolPtr volume, virStorageVolInfoPtr info)
virCheckNonNullArgReturn(volume->privateData, -1);
if (esxVI_EnsureSession(priv->primary) < 0) {
if (esxVI_EnsureSession(priv->primary) < 0)
return -1;
}
return backend->storageVolGetInfo(volume, info);
}
@ -524,9 +499,8 @@ esxStorageVolGetXMLDesc(virStorageVolPtr volume, unsigned int flags)
virCheckNonNullArgReturn(volume->privateData, NULL);
if (esxVI_EnsureSession(priv->primary) < 0) {
if (esxVI_EnsureSession(priv->primary) < 0)
return NULL;
}
return backend->storageVolGetXMLDesc(volume, flags);
}
@ -541,9 +515,8 @@ esxStorageVolGetPath(virStorageVolPtr volume)
virCheckNonNullArgReturn(volume->privateData, NULL);
if (esxVI_EnsureSession(priv->primary) < 0) {
if (esxVI_EnsureSession(priv->primary) < 0)
return NULL;
}
return backend->storageVolGetPath(volume);
}

View File

@ -166,9 +166,8 @@ esxUtil_ParseUri(esxUtil_ParsedUri **parsedUri, virURIPtr uri)
result = 0;
cleanup:
if (result < 0) {
if (result < 0)
esxUtil_FreeParsedUri(parsedUri);
}
return result;
}
@ -179,9 +178,8 @@ esxUtil_ParseUri(esxUtil_ParsedUri **parsedUri, virURIPtr uri)
void
esxUtil_FreeParsedUri(esxUtil_ParsedUri **parsedUri)
{
if (!parsedUri || !(*parsedUri)) {
if (!parsedUri || !(*parsedUri))
return;
}
VIR_FREE((*parsedUri)->transport);
VIR_FREE((*parsedUri)->vCenter);
@ -197,19 +195,17 @@ int
esxUtil_ParseVirtualMachineIDString(const char *id_string, int *id)
{
/* Try to parse an integer from the complete string. */
if (virStrToLong_i(id_string, NULL, 10, id) == 0) {
if (virStrToLong_i(id_string, NULL, 10, id) == 0)
return 0;
}
/*
* If that fails try to parse an integer from the string tail
* assuming the naming scheme Virtual Center seems to use.
*/
if (STRPREFIX(id_string, "vm-")) {
if (virStrToLong_i(id_string + 3, NULL, 10, id) == 0) {
if (virStrToLong_i(id_string + 3, NULL, 10, id) == 0)
return 0;
}
}
return -1;
}
@ -234,9 +230,8 @@ esxUtil_ParseDatastorePath(const char *datastorePath, char **datastoreName,
return -1;
}
if (VIR_STRDUP(copyOfDatastorePath, datastorePath) < 0) {
if (VIR_STRDUP(copyOfDatastorePath, datastorePath) < 0)
goto cleanup;
}
/* Expected format: '[<datastore>] <path>' where <path> is optional */
if (!(tmp = STRSKIP(copyOfDatastorePath, "[")) || *tmp == ']' ||
@ -270,31 +265,26 @@ esxUtil_ParseDatastorePath(const char *datastorePath, char **datastoreName,
/* Split <path> into <directory>/<file> and remove /<file> */
tmp = strrchr(preliminaryDirectoryAndFileName, '/');
if (tmp) {
if (tmp)
*tmp = '\0';
}
if (VIR_STRDUP(*directoryName, preliminaryDirectoryAndFileName) < 0) {
if (VIR_STRDUP(*directoryName, preliminaryDirectoryAndFileName) < 0)
goto cleanup;
}
}
result = 0;
cleanup:
if (result < 0) {
if (datastoreName) {
if (datastoreName)
VIR_FREE(*datastoreName);
}
if (directoryName) {
if (directoryName)
VIR_FREE(*directoryName);
}
if (directoryAndFileName) {
if (directoryAndFileName)
VIR_FREE(*directoryAndFileName);
}
}
VIR_FREE(copyOfDatastorePath);
@ -408,22 +398,19 @@ esxUtil_EscapeBase64(const char *string)
virBufferAddChar(&buffer, base64[(c1 >> 2) & 0x3f]);
virBufferAddChar(&buffer, base64[((c1 << 4) + (c2 >> 4)) & 0x3f]);
if (length > 1) {
if (length > 1)
virBufferAddChar(&buffer, base64[((c2 << 2) + (c3 >> 6)) & 0x3f]);
}
if (length > 2) {
if (length > 2)
virBufferAddChar(&buffer, base64[c3 & 0x3f]);
}
length -= length > 3 ? 3 : length;
}
if (*tmp1 != '\0') {
if (*tmp1 != '\0')
virBufferAddChar(&buffer, '-');
}
}
}
if (virBufferCheckError(&buffer) < 0)
return NULL;
@ -450,10 +437,9 @@ esxUtil_ReplaceSpecialWindowsPathChars(char *string)
--length;
}
if (*tmp != '\0') {
if (*tmp != '\0')
++tmp;
}
}
}
@ -472,9 +458,8 @@ esxUtil_EscapeDatastoreItem(const char *string)
escaped1 = virVMXEscapeHexPercent(replaced);
if (!escaped1) {
if (!escaped1)
goto cleanup;
}
escaped2 = esxUtil_EscapeBase64(escaped1);

View File

@ -98,26 +98,22 @@ ESX_VI__TEMPLATE__FREE(CURL,
if (shared) {
esxVI_SharedCURL_Remove(shared, item);
if (shared->count == 0) {
if (shared->count == 0)
esxVI_SharedCURL_Free(&shared);
}
}
if (multi) {
esxVI_MultiCURL_Remove(multi, item);
if (multi->count == 0) {
if (multi->count == 0)
esxVI_MultiCURL_Free(&multi);
}
}
if (item->handle) {
if (item->handle)
curl_easy_cleanup(item->handle);
}
if (item->headers) {
if (item->headers)
curl_slist_free_all(item->headers);
}
virMutexDestroy(&item->lock);
})
@ -129,19 +125,16 @@ esxVI_CURL_ReadString(char *data, size_t size, size_t nmemb, void *userdata)
size_t available = 0;
size_t requested = size * nmemb;
if (!content) {
if (!content)
return 0;
}
available = strlen(content);
if (available == 0) {
if (available == 0)
return 0;
}
if (requested > available) {
if (requested > available)
requested = available;
}
memcpy(data, content, requested);
@ -162,9 +155,8 @@ esxVI_CURL_WriteBuffer(char *data, size_t size, size_t nmemb, void *userdata)
* are meant to download small things such as VMX files, VMDK metadata
* files and SOAP responses.
*/
if (size * nmemb > INT32_MAX / 2 - virBufferUse(buffer)) {
if (size * nmemb > INT32_MAX / 2 - virBufferUse(buffer))
return 0;
}
virBufferAdd(buffer, data, size * nmemb);
@ -193,9 +185,8 @@ esxVI_CURL_Debug(CURL *curl ATTRIBUTE_UNUSED, curl_infotype type,
* To handle this properly in order to pass the info string to VIR_DEBUG
* a zero terminated copy of the info string has to be allocated.
*/
if (VIR_ALLOC_N(buffer, size + 1) < 0) {
if (VIR_ALLOC_N(buffer, size + 1) < 0)
return 0;
}
if (!virStrncpy(buffer, info, size, size + 1)) {
VIR_FREE(buffer);
@ -204,9 +195,8 @@ esxVI_CURL_Debug(CURL *curl ATTRIBUTE_UNUSED, curl_infotype type,
switch (type) {
case CURLINFO_TEXT:
if (size > 0 && buffer[size - 1] == '\n') {
if (size > 0 && buffer[size - 1] == '\n')
buffer[size - 1] = '\0';
}
VIR_DEBUG("CURLINFO_TEXT [[[[%s]]]]", buffer);
break;
@ -430,9 +420,8 @@ esxVI_CURL_Download(esxVI_CURL *curl, const char *url, char **content,
if (virBufferCheckError(&buffer) < 0)
goto cleanup;
if (length) {
if (length)
*length = virBufferUse(&buffer);
}
*content = virBufferContentAndReset(&buffer);
@ -557,13 +546,11 @@ ESX_VI__TEMPLATE__FREE(SharedCURL,
return;
}
if (item->handle) {
if (item->handle)
curl_share_cleanup(item->handle);
}
for (i = 0; i < ARRAY_CARDINALITY(item->locks); ++i) {
for (i = 0; i < ARRAY_CARDINALITY(item->locks); ++i)
virMutexDestroy(&item->locks[i]);
}
})
int
@ -735,9 +722,8 @@ ESX_VI__TEMPLATE__FREE(MultiCURL,
return;
}
if (item->handle) {
if (item->handle)
curl_multi_cleanup(item->handle);
}
#if ESX_EMULATE_CURL_MULTI_WAIT
VIR_FREE(item->pollfds);
@ -856,9 +842,8 @@ esxVI_MultiCURL_Wait(esxVI_MultiCURL *multi, int *runningHandles)
curl_multi_timeout(multi->handle, &timeout);
if (timeout < 0) {
if (timeout < 0)
timeout = 1000; /* default to 1 sec timeout */
}
do {
rc = poll(multi->pollfds, multi->npollfds, timeout);
@ -980,9 +965,8 @@ ESX_VI__TEMPLATE__ALLOC(Context)
/* esxVI_Context_Free */
ESX_VI__TEMPLATE__FREE(Context,
{
if (item->sessionLock) {
if (item->sessionLock)
virMutexDestroy(item->sessionLock);
}
esxVI_CURL_Free(&item->curl);
VIR_FREE(item->url);
@ -1036,9 +1020,8 @@ esxVI_Context_Connect(esxVI_Context *ctx, const char *url,
return -1;
}
if (esxVI_RetrieveServiceContent(ctx, &ctx->service) < 0) {
if (esxVI_RetrieveServiceContent(ctx, &ctx->service) < 0)
return -1;
}
if (STRNEQ(ctx->service->about->apiType, "HostAgent") &&
STRNEQ(ctx->service->about->apiType, "VirtualCenter")) {
@ -1121,9 +1104,8 @@ esxVI_Context_Connect(esxVI_Context *ctx, const char *url,
ctx->hasQueryVirtualDiskUuid = true;
}
if (ctx->productLine == esxVI_ProductLine_VPX) {
if (ctx->productLine == esxVI_ProductLine_VPX)
ctx->hasSessionIsActive = true;
}
if (esxVI_Login(ctx, username, password, NULL, &ctx->session) < 0 ||
esxVI_BuildSelectSetCollection(ctx) < 0) {
@ -1212,9 +1194,8 @@ esxVI_Context_LookupManagedObjectsByPath(esxVI_Context *ctx, const char *path)
if (folder) {
/* It's a folder, use it as new lookup root */
if (root != ctx->service->rootFolder) {
if (root != ctx->service->rootFolder)
esxVI_ManagedObjectReference_Free(&root);
}
root = folder->_reference;
folder->_reference = NULL;
@ -1227,9 +1208,8 @@ esxVI_Context_LookupManagedObjectsByPath(esxVI_Context *ctx, const char *path)
}
/* Build datacenter path */
if (virBufferUse(&buffer) > 0) {
if (virBufferUse(&buffer) > 0)
virBufferAddChar(&buffer, '/');
}
virBufferAdd(&buffer, item, -1);
@ -1255,9 +1235,8 @@ esxVI_Context_LookupManagedObjectsByPath(esxVI_Context *ctx, const char *path)
goto cleanup;
}
if (root != ctx->service->rootFolder) {
if (root != ctx->service->rootFolder)
esxVI_ManagedObjectReference_Free(&root);
}
root = ctx->datacenter->hostFolder;
@ -1272,9 +1251,8 @@ esxVI_Context_LookupManagedObjectsByPath(esxVI_Context *ctx, const char *path)
if (folder) {
/* It's a folder, use it as new lookup root */
if (root != ctx->datacenter->hostFolder) {
if (root != ctx->datacenter->hostFolder)
esxVI_ManagedObjectReference_Free(&root);
}
root = folder->_reference;
folder->_reference = NULL;
@ -1288,9 +1266,8 @@ esxVI_Context_LookupManagedObjectsByPath(esxVI_Context *ctx, const char *path)
}
/* Build compute resource path */
if (virBufferUse(&buffer) > 0) {
if (virBufferUse(&buffer) > 0)
virBufferAddChar(&buffer, '/');
}
virBufferAdd(&buffer, item, -1);
@ -1355,9 +1332,8 @@ esxVI_Context_LookupManagedObjectsByPath(esxVI_Context *ctx, const char *path)
result = 0;
cleanup:
if (result < 0) {
if (result < 0)
virBufferFreeAndReset(&buffer);
}
if (root != ctx->service->rootFolder &&
(!ctx->datacenter || root != ctx->datacenter->hostFolder)) {
@ -1431,9 +1407,8 @@ esxVI_Context_Execute(esxVI_Context *ctx, const char *methodName,
return -1;
}
if (esxVI_Response_Alloc(response) < 0) {
if (esxVI_Response_Alloc(response) < 0)
return -1;
}
virMutexLock(&ctx->curl->lock);
@ -1448,9 +1423,8 @@ esxVI_Context_Execute(esxVI_Context *ctx, const char *methodName,
virMutexUnlock(&ctx->curl->lock);
if ((*response)->responseCode < 0) {
if ((*response)->responseCode < 0)
goto cleanup;
}
if (virBufferCheckError(&buffer) < 0)
goto cleanup;
@ -1462,9 +1436,8 @@ esxVI_Context_Execute(esxVI_Context *ctx, const char *methodName,
_("(esx execute response)"),
&xpathContext);
if (!(*response)->document) {
if (!(*response)->document)
goto cleanup;
}
xmlXPathRegisterNs(xpathContext, BAD_CAST "soapenv",
BAD_CAST "http://schemas.xmlsoap.org/soap/envelope/");
@ -1710,9 +1683,8 @@ esxVI_Enumeration_Deserialize(const esxVI_Enumeration *enumeration,
*value = 0; /* undefined */
if (esxVI_String_DeserializeValue(node, &name) < 0) {
if (esxVI_String_DeserializeValue(node, &name) < 0)
return -1;
}
for (i = 0; enumeration->values[i].name; ++i) {
if (STREQ(name, enumeration->values[i].name)) {
@ -1755,9 +1727,8 @@ esxVI_List_Append(esxVI_List **list, esxVI_List *item)
next = *list;
while (next->_next) {
while (next->_next)
next = next->_next;
}
next->_next = item;
@ -1810,9 +1781,8 @@ esxVI_List_CastFromAnyType(esxVI_AnyType *anyType, esxVI_List **list,
return -1;
}
if (!anyType) {
if (!anyType)
return 0;
}
if (! STRPREFIX(anyType->other, "ArrayOf")) {
virReportError(VIR_ERR_INTERNAL_ERROR,
@ -1865,15 +1835,13 @@ esxVI_List_Serialize(esxVI_List *list, const char *element,
return -1;
}
if (!list) {
if (!list)
return 0;
}
for (item = list; item; item = item->_next) {
if (serializeFunc(item, element, output) < 0) {
if (serializeFunc(item, element, output) < 0)
return -1;
}
}
return 0;
}
@ -1890,9 +1858,8 @@ esxVI_List_Deserialize(xmlNodePtr node, esxVI_List **list,
return -1;
}
if (!node) {
if (!node)
return 0;
}
for (; node; node = node->next) {
if (node->type != XML_ELEMENT_NODE) {
@ -2193,9 +2160,8 @@ esxVI_LookupObjectContentByType(esxVI_Context *ctx,
return -1;
}
if (esxVI_ObjectSpec_Alloc(&objectSpec) < 0) {
if (esxVI_ObjectSpec_Alloc(&objectSpec) < 0)
return -1;
}
objectSpec->obj = root;
objectSpec->skip = esxVI_Boolean_False;
@ -2254,9 +2220,8 @@ esxVI_LookupObjectContentByType(esxVI_Context *ctx,
}
}
if (esxVI_PropertySpec_Alloc(&propertySpec) < 0) {
if (esxVI_PropertySpec_Alloc(&propertySpec) < 0)
goto cleanup;
}
propertySpec->type = (char *)type;
propertySpec->pathSet = propertyNameList;
@ -2325,13 +2290,11 @@ esxVI_LookupObjectContentByType(esxVI_Context *ctx,
propertySpec->pathSet = NULL;
}
if (!objectSpec_isAppended) {
if (!objectSpec_isAppended)
esxVI_ObjectSpec_Free(&objectSpec);
}
if (!propertySpec_isAppended) {
if (!propertySpec_isAppended)
esxVI_PropertySpec_Free(&propertySpec);
}
esxVI_PropertyFilterSpec_Free(&propertyFilterSpec);
@ -2463,9 +2426,8 @@ esxVI_GetLong(esxVI_ObjectContent *objectContent, const char *propertyName,
for (dynamicProperty = objectContent->propSet; dynamicProperty;
dynamicProperty = dynamicProperty->_next) {
if (STREQ(dynamicProperty->name, propertyName)) {
if (esxVI_Long_CastFromAnyType(dynamicProperty->val, value) < 0) {
if (esxVI_Long_CastFromAnyType(dynamicProperty->val, value) < 0)
return -1;
}
break;
}
@ -2709,9 +2671,8 @@ esxVI_GetVirtualMachineIdentity(esxVI_ObjectContent *virtualMachine,
return 0;
failure:
if (name) {
if (name)
VIR_FREE(*name);
}
return -1;
}
@ -2760,9 +2721,8 @@ esxVI_GetSnapshotTreeNames(esxVI_VirtualMachineSnapshotTree *snapshotTreeList,
count++;
}
if (count >= nameslen) {
if (count >= nameslen)
break;
}
if (recurse) {
result = esxVI_GetSnapshotTreeNames(snapshotTree->childSnapshotList,
@ -2770,9 +2730,8 @@ esxVI_GetSnapshotTreeNames(esxVI_VirtualMachineSnapshotTree *snapshotTreeList,
nameslen - count,
true, leaves);
if (result < 0) {
if (result < 0)
goto failure;
}
count += result;
}
@ -2781,9 +2740,8 @@ esxVI_GetSnapshotTreeNames(esxVI_VirtualMachineSnapshotTree *snapshotTreeList,
return count;
failure:
for (i = 0; i < count; ++i) {
for (i = 0; i < count; ++i)
VIR_FREE(names[i]);
}
return -1;
}
@ -2817,9 +2775,8 @@ esxVI_GetSnapshotTreeByName
if (esxVI_GetSnapshotTreeByName(candidate->childSnapshotList, name,
snapshotTree, snapshotTreeParent,
occurrence) > 0) {
if (snapshotTreeParent && !(*snapshotTreeParent)) {
if (snapshotTreeParent && !(*snapshotTreeParent))
*snapshotTreeParent = candidate;
}
return 1;
}
@ -2987,13 +2944,11 @@ esxVI_LookupVirtualMachineByName(esxVI_Context *ctx, const char *name,
goto cleanup;
}
if (STRNEQ(name, name_candidate)) {
if (STRNEQ(name, name_candidate))
continue;
}
if (esxVI_ObjectContent_DeepCopy(virtualMachine, candidate) < 0) {
if (esxVI_ObjectContent_DeepCopy(virtualMachine, candidate) < 0)
goto cleanup;
}
break;
}
@ -3126,9 +3081,8 @@ esxVI_LookupDatastoreByName(esxVI_Context *ctx, const char *name,
}
if (STREQ(name_candidate, name)) {
if (esxVI_ObjectContent_DeepCopy(datastore, candidate) < 0) {
if (esxVI_ObjectContent_DeepCopy(datastore, candidate) < 0)
goto cleanup;
}
/* Found datastore with matching name */
result = 0;
@ -3199,9 +3153,8 @@ esxVI_LookupDatastoreByAbsolutePath(esxVI_Context *ctx,
}
}
if (!datastoreHostMountList) {
if (!datastoreHostMountList)
continue;
}
for (datastoreHostMount = datastoreHostMountList;
datastoreHostMount;
@ -3212,9 +3165,8 @@ esxVI_LookupDatastoreByAbsolutePath(esxVI_Context *ctx,
}
if (STRPREFIX(absolutePath, datastoreHostMount->mountInfo->path)) {
if (esxVI_ObjectContent_DeepCopy(datastore, candidate) < 0) {
if (esxVI_ObjectContent_DeepCopy(datastore, candidate) < 0)
goto cleanup;
}
/* Found datastore with matching mount path */
result = 0;
@ -3284,13 +3236,11 @@ esxVI_LookupDatastoreHostMount(esxVI_Context *ctx,
for (candidate = hostMountList; candidate;
candidate = candidate->_next) {
if (STRNEQ(ctx->hostSystem->_reference->value, candidate->key->value)) {
if (STRNEQ(ctx->hostSystem->_reference->value, candidate->key->value))
continue;
}
if (esxVI_DatastoreHostMount_DeepCopy(hostMount, candidate) < 0) {
if (esxVI_DatastoreHostMount_DeepCopy(hostMount, candidate) < 0)
goto cleanup;
}
break;
}
@ -3392,9 +3342,8 @@ esxVI_LookupPendingTaskInfoListByVirtualMachine
/* Lookup task info for each task */
for (recentTask = recentTaskList; recentTask;
recentTask = recentTask->_next) {
if (esxVI_LookupTaskInfoByTask(ctx, recentTask, &taskInfo) < 0) {
if (esxVI_LookupTaskInfoByTask(ctx, recentTask, &taskInfo) < 0)
goto cleanup;
}
if (taskInfo->state == esxVI_TaskInfoState_Queued ||
taskInfo->state == esxVI_TaskInfoState_Running) {
@ -3412,9 +3361,8 @@ esxVI_LookupPendingTaskInfoListByVirtualMachine
result = 0;
cleanup:
if (result < 0) {
if (result < 0)
esxVI_TaskInfo_Free(pendingTaskInfoList);
}
esxVI_String_Free(&propertyNameList);
esxVI_ManagedObjectReference_Free(&recentTaskList);
@ -3509,9 +3457,8 @@ esxVI_LookupRootSnapshotTreeList
result = 0;
cleanup:
if (result < 0) {
if (result < 0)
esxVI_VirtualMachineSnapshotTree_Free(rootSnapshotTreeList);
}
esxVI_String_Free(&propertyNameList);
esxVI_ObjectContent_Free(&virtualMachine);
@ -3651,9 +3598,8 @@ esxVI_LookupFileInfoByDatastorePath(esxVI_Context *ctx,
datastoreName) < 0)
goto cleanup;
if (VIR_STRDUP(fileName, directoryAndFileName) < 0) {
if (VIR_STRDUP(fileName, directoryAndFileName) < 0)
goto cleanup;
}
} else {
if (virAsprintf(&datastorePathWithoutFileName, "[%s] %s",
datastoreName, directoryName) < 0)
@ -3669,10 +3615,9 @@ esxVI_LookupFileInfoByDatastorePath(esxVI_Context *ctx,
goto cleanup;
}
if (VIR_STRDUP(fileName, directoryAndFileName + length + 1) < 0) {
if (VIR_STRDUP(fileName, directoryAndFileName + length + 1) < 0)
goto cleanup;
}
}
/* Lookup HostDatastoreBrowser */
if (esxVI_String_AppendValueToList(&propertyNameList, "browser") < 0 ||
@ -3736,9 +3681,8 @@ esxVI_LookupFileInfoByDatastorePath(esxVI_Context *ctx,
floppyImageFileQuery = NULL;
}
if (esxVI_String_Alloc(&searchSpec->matchPattern) < 0) {
if (esxVI_String_Alloc(&searchSpec->matchPattern) < 0)
goto cleanup;
}
searchSpec->matchPattern->value = fileName;
@ -3786,9 +3730,8 @@ esxVI_LookupFileInfoByDatastorePath(esxVI_Context *ctx,
cleanup:
/* Don't double free fileName */
if (searchSpec && searchSpec->matchPattern) {
if (searchSpec && searchSpec->matchPattern)
searchSpec->matchPattern->value = NULL;
}
VIR_FREE(datastoreName);
VIR_FREE(directoryName);
@ -3967,18 +3910,16 @@ esxVI_LookupStorageVolumeKeyByDatastorePath(esxVI_Context *ctx,
if (VIR_ALLOC_N(*key, VIR_UUID_STRING_BUFLEN) < 0)
goto cleanup;
if (esxUtil_ReformatUuid(uuid_string, *key) < 0) {
if (esxUtil_ReformatUuid(uuid_string, *key) < 0)
goto cleanup;
}
}
}
if (!(*key)) {
/* Other files don't have a UUID, fall back to the path as key */
if (VIR_STRDUP(*key, datastorePath) < 0) {
if (VIR_STRDUP(*key, datastorePath) < 0)
goto cleanup;
}
}
result = 0;
@ -4157,17 +4098,15 @@ esxVI_LookupPhysicalNicByName(esxVI_Context *ctx, const char *name,
return -1;
}
if (esxVI_LookupPhysicalNicList(ctx, &physicalNicList) < 0) {
if (esxVI_LookupPhysicalNicList(ctx, &physicalNicList) < 0)
goto cleanup;
}
/* Search for a matching physical NIC */
for (candidate = physicalNicList; candidate;
candidate = candidate->_next) {
if (STRCASEEQ(candidate->device, name)) {
if (esxVI_PhysicalNic_DeepCopy(physicalNic, candidate) < 0) {
if (esxVI_PhysicalNic_DeepCopy(physicalNic, candidate) < 0)
goto cleanup;
}
/* Found physical NIC with matching name */
result = 0;
@ -4206,17 +4145,15 @@ esxVI_LookupPhysicalNicByMACAddress(esxVI_Context *ctx, const char *mac,
return -1;
}
if (esxVI_LookupPhysicalNicList(ctx, &physicalNicList) < 0) {
if (esxVI_LookupPhysicalNicList(ctx, &physicalNicList) < 0)
goto cleanup;
}
/* Search for a matching physical NIC */
for (candidate = physicalNicList; candidate;
candidate = candidate->_next) {
if (STRCASEEQ(candidate->mac, mac)) {
if (esxVI_PhysicalNic_DeepCopy(physicalNic, candidate) < 0) {
if (esxVI_PhysicalNic_DeepCopy(physicalNic, candidate) < 0)
goto cleanup;
}
/* Found physical NIC with matching MAC address */
result = 0;
@ -4299,9 +4236,8 @@ esxVI_LookupHostVirtualSwitchByName(esxVI_Context *ctx, const char *name,
return -1;
}
if (esxVI_LookupHostVirtualSwitchList(ctx, &hostVirtualSwitchList) < 0) {
if (esxVI_LookupHostVirtualSwitchList(ctx, &hostVirtualSwitchList) < 0)
goto cleanup;
}
/* Search for a matching HostVirtualSwitch */
for (candidate = hostVirtualSwitchList; candidate;
@ -4421,9 +4357,8 @@ esxVI_HandleVirtualMachineQuestion
elementDescription = elementDescription->_next) {
virBufferAsprintf(&buffer, "'%s'", elementDescription->label);
if (elementDescription->_next) {
if (elementDescription->_next)
virBufferAddLit(&buffer, ", ");
}
if (!answerChoice &&
questionInfo->choice->defaultIndex &&
@ -4489,9 +4424,8 @@ esxVI_HandleVirtualMachineQuestion
result = 0;
cleanup:
if (result < 0) {
if (result < 0)
virBufferFreeAndReset(&buffer);
}
VIR_FREE(possibleAnswers);
@ -4533,16 +4467,14 @@ esxVI_WaitForTaskCompletion(esxVI_Context *ctx,
if (VIR_STRDUP(version, "") < 0)
return -1;
if (esxVI_ObjectSpec_Alloc(&objectSpec) < 0) {
if (esxVI_ObjectSpec_Alloc(&objectSpec) < 0)
goto cleanup;
}
objectSpec->obj = task;
objectSpec->skip = esxVI_Boolean_False;
if (esxVI_PropertySpec_Alloc(&propertySpec) < 0) {
if (esxVI_PropertySpec_Alloc(&propertySpec) < 0)
goto cleanup;
}
propertySpec->type = task->type;
@ -4581,9 +4513,8 @@ esxVI_WaitForTaskCompletion(esxVI_Context *ctx,
* esxVI_LookupTaskInfoByTask() and esxVI_CancelTask()
* don't overwrite the actual error
*/
if (esxVI_LookupTaskInfoByTask(ctx, task, &taskInfo)) {
if (esxVI_LookupTaskInfoByTask(ctx, task, &taskInfo))
goto cleanup;
}
if (taskInfo->cancelable == esxVI_Boolean_True) {
if (esxVI_CancelTask(ctx, task) < 0 && blocked) {
@ -4602,17 +4533,15 @@ esxVI_WaitForTaskCompletion(esxVI_Context *ctx,
}
}
if (esxVI_WaitForUpdates(ctx, version, &updateSet) < 0) {
if (esxVI_WaitForUpdates(ctx, version, &updateSet) < 0)
goto cleanup;
}
VIR_FREE(version);
if (VIR_STRDUP(version, updateSet->version) < 0)
goto cleanup;
if (!updateSet->filterSet) {
if (!updateSet->filterSet)
continue;
}
for (propertyFilterUpdate = updateSet->filterSet;
propertyFilterUpdate;
@ -4634,27 +4563,22 @@ esxVI_WaitForTaskCompletion(esxVI_Context *ctx,
}
}
if (!propertyValue) {
if (!propertyValue)
continue;
}
if (esxVI_TaskInfoState_CastFromAnyType(propertyValue, &state) < 0) {
if (esxVI_TaskInfoState_CastFromAnyType(propertyValue, &state) < 0)
goto cleanup;
}
}
if (esxVI_DestroyPropertyFilter(ctx, propertyFilter) < 0) {
if (esxVI_DestroyPropertyFilter(ctx, propertyFilter) < 0)
VIR_DEBUG("DestroyPropertyFilter failed");
}
if (esxVI_TaskInfoState_CastFromAnyType(propertyValue, finalState) < 0) {
if (esxVI_TaskInfoState_CastFromAnyType(propertyValue, finalState) < 0)
goto cleanup;
}
if (*finalState != esxVI_TaskInfoState_Success) {
if (esxVI_LookupTaskInfoByTask(ctx, task, &taskInfo)) {
if (esxVI_LookupTaskInfoByTask(ctx, task, &taskInfo))
goto cleanup;
}
if (!taskInfo->error) {
if (VIR_STRDUP(*errorMessage, _("Unknown error")) < 0)
@ -4677,21 +4601,17 @@ esxVI_WaitForTaskCompletion(esxVI_Context *ctx,
* Remove values given by the caller from the data structures to prevent
* them from being freed by the call to esxVI_PropertyFilterSpec_Free().
*/
if (objectSpec) {
if (objectSpec)
objectSpec->obj = NULL;
}
if (propertySpec) {
if (propertySpec)
propertySpec->type = NULL;
}
if (!objectSpec_isAppended) {
if (!objectSpec_isAppended)
esxVI_ObjectSpec_Free(&objectSpec);
}
if (!propertySpec_isAppended) {
if (!propertySpec_isAppended)
esxVI_PropertySpec_Free(&propertySpec);
}
esxVI_PropertyFilterSpec_Free(&propertyFilterSpec);
esxVI_ManagedObjectReference_Free(&propertyFilter);
@ -4849,10 +4769,9 @@ esxVI_LookupHostInternetScsiHbaStaticTargetByName
for (candidate = hostInternetScsiHba->configuredStaticTarget;
candidate; candidate = candidate->_next) {
if (STREQ(candidate->iScsiName, name)) {
if (STREQ(candidate->iScsiName, name))
break;
}
}
if (!candidate) {
if (occurrence == esxVI_Occurrence_RequiredItem) {
@ -4863,9 +4782,8 @@ esxVI_LookupHostInternetScsiHbaStaticTargetByName
goto cleanup;
}
if (esxVI_HostInternetScsiHbaStaticTarget_DeepCopy(target, candidate) < 0) {
if (esxVI_HostInternetScsiHbaStaticTarget_DeepCopy(target, candidate) < 0)
goto cleanup;
}
result = 0;
@ -5044,9 +4962,8 @@ esxVI_LookupHostScsiTopologyLunListByTargetName
}
}
if (!found || !hostScsiTopologyTarget) {
if (!found || !hostScsiTopologyTarget)
goto cleanup;
}
if (!hostScsiTopologyTarget->lun) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",

View File

@ -944,13 +944,11 @@ esxVI_AnyType_DeepCopy(esxVI_AnyType **dest, esxVI_AnyType *src)
return -1;
}
if (!src) {
if (!src)
return 0;
}
if (esxVI_AnyType_Alloc(dest) < 0) {
if (esxVI_AnyType_Alloc(dest) < 0)
goto failure;
}
(*dest)->_type = src->_type;
(*dest)->node = xmlCopyNode(src->node, 1);
@ -1015,9 +1013,8 @@ esxVI_AnyType_Deserialize(xmlNodePtr node, esxVI_AnyType **anyType)
return -1;
}
if (esxVI_AnyType_Alloc(anyType) < 0) {
if (esxVI_AnyType_Alloc(anyType) < 0)
return -1;
}
(*anyType)->node = xmlCopyNode(node, 1);
@ -1151,10 +1148,9 @@ esxVI_String_ListContainsValue(esxVI_String *stringList, const char *value)
esxVI_String *string;
for (string = stringList; string; string = string->_next) {
if (STREQ(string->value, value)) {
if (STREQ(string->value, value))
return true;
}
}
return false;
}
@ -1167,16 +1163,14 @@ esxVI_String_AppendValueToList(esxVI_String **stringList, const char *value)
{
esxVI_String *string = NULL;
if (esxVI_String_Alloc(&string) < 0) {
if (esxVI_String_Alloc(&string) < 0)
return -1;
}
if (VIR_STRDUP(string->value, value) < 0)
goto failure;
if (esxVI_String_AppendToList(stringList, string) < 0) {
if (esxVI_String_AppendToList(stringList, string) < 0)
goto failure;
}
return 0;
@ -1194,16 +1188,14 @@ esxVI_String_AppendValueListToList(esxVI_String **stringList,
const char *value = valueList;
while (value && *value != '\0') {
if (esxVI_String_AppendValueToList(&stringListToAppend, value) < 0) {
if (esxVI_String_AppendValueToList(&stringListToAppend, value) < 0)
goto failure;
}
value += strlen(value) + 1;
}
if (esxVI_String_AppendToList(stringList, stringListToAppend) < 0) {
if (esxVI_String_AppendToList(stringList, stringListToAppend) < 0)
goto failure;
}
return 0;
@ -1230,9 +1222,8 @@ esxVI_String_DeepCopyValue(char **dest, const char *src)
return -1;
}
if (!src) {
if (!src)
return 0;
}
return VIR_STRDUP(*dest, src);
}
@ -1263,9 +1254,8 @@ esxVI_String_SerializeValue(const char *value, const char *element,
return -1;
}
if (!value) {
if (!value)
return 0;
}
ESV_VI__XML_TAG__OPEN(output, element, "xsd:string");
@ -1483,9 +1473,8 @@ esxVI_DateTime_Deserialize(xmlNodePtr node, esxVI_DateTime **dateTime)
return -1;
}
if (esxVI_DateTime_Alloc(dateTime) < 0) {
if (esxVI_DateTime_Alloc(dateTime) < 0)
return -1;
}
(*dateTime)->value =
(char *)xmlNodeListGetString(node->doc, node->children, 1);
@ -1577,9 +1566,8 @@ esxVI_DateTime_ConvertToCalendarTime(esxVI_DateTime *dateTime,
tz_offset = tz_hours * 60 * 60 + tz_minutes * 60;
if (sign == '-') {
if (sign == '-')
tz_offset = -tz_offset;
}
} else if (STREQ(tmp, "Z")) {
/* Z refers to UTC. tz_offset is already initialized to zero */
} else {
@ -1657,9 +1645,8 @@ esxVI_MethodFault_Deserialize(xmlNodePtr node, esxVI_MethodFault **methodFault)
return -1;
}
if (esxVI_MethodFault_Alloc(methodFault) < 0) {
if (esxVI_MethodFault_Alloc(methodFault) < 0)
return -1;
}
(*methodFault)->_actualType =
(char *)xmlGetNsProp(node, BAD_CAST "type",
@ -1723,9 +1710,8 @@ esxVI_ManagedObjectReference_Serialize
return -1;
}
if (!managedObjectReference) {
if (!managedObjectReference)
return 0;
}
virBufferAddLit(output, "<");
virBufferAdd(output, element, -1);
@ -1753,9 +1739,8 @@ esxVI_ManagedObjectReference_Deserialize
return -1;
}
if (esxVI_ManagedObjectReference_Alloc(managedObjectReference) < 0) {
if (esxVI_ManagedObjectReference_Alloc(managedObjectReference) < 0)
return -1;
}
(*managedObjectReference)->type =
(char *)xmlGetNoNsProp(node, BAD_CAST "type");