mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
esx: Remove redundant checks for esxVI_LookupHostSystemProperties result
esxVI_LookupHostSystemProperties guarantees that hostSystem is non-NULL. Remove redundant NULL checks from callers. Also prefer esxVI_GetStringValue over open-coding the logic.
This commit is contained in:
parent
c10cc25470
commit
ba86e5cd3f
@ -3,7 +3,7 @@
|
|||||||
* esx_driver.c: core driver functions for managing VMware ESX hosts
|
* esx_driver.c: core driver functions for managing VMware ESX hosts
|
||||||
*
|
*
|
||||||
* Copyright (C) 2010-2012 Red Hat, Inc.
|
* Copyright (C) 2010-2012 Red Hat, Inc.
|
||||||
* Copyright (C) 2009-2011 Matthias Bolte <matthias.bolte@googlemail.com>
|
* Copyright (C) 2009-2012 Matthias Bolte <matthias.bolte@googlemail.com>
|
||||||
* Copyright (C) 2009 Maximilian Wilhelm <max@rfc2324.org>
|
* Copyright (C) 2009 Maximilian Wilhelm <max@rfc2324.org>
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
@ -467,12 +467,6 @@ esxSupportsLongMode(esxPrivate *priv)
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hostSystem == NULL) {
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
||||||
_("Could not retrieve the HostSystem object"));
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (dynamicProperty = hostSystem->propSet; dynamicProperty != NULL;
|
for (dynamicProperty = hostSystem->propSet; dynamicProperty != NULL;
|
||||||
dynamicProperty = dynamicProperty->_next) {
|
dynamicProperty = dynamicProperty->_next) {
|
||||||
if (STREQ(dynamicProperty->name, "hardware.cpuFeature")) {
|
if (STREQ(dynamicProperty->name, "hardware.cpuFeature")) {
|
||||||
@ -534,7 +528,7 @@ esxLookupHostSystemBiosUuid(esxPrivate *priv, unsigned char *uuid)
|
|||||||
int result = -1;
|
int result = -1;
|
||||||
esxVI_String *propertyNameList = NULL;
|
esxVI_String *propertyNameList = NULL;
|
||||||
esxVI_ObjectContent *hostSystem = NULL;
|
esxVI_ObjectContent *hostSystem = NULL;
|
||||||
esxVI_DynamicProperty *dynamicProperty = NULL;
|
char *uuid_string = NULL;
|
||||||
|
|
||||||
if (esxVI_EnsureSession(priv->primary) < 0) {
|
if (esxVI_EnsureSession(priv->primary) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
@ -543,41 +537,22 @@ esxLookupHostSystemBiosUuid(esxPrivate *priv, unsigned char *uuid)
|
|||||||
if (esxVI_String_AppendValueToList(&propertyNameList,
|
if (esxVI_String_AppendValueToList(&propertyNameList,
|
||||||
"hardware.systemInfo.uuid") < 0 ||
|
"hardware.systemInfo.uuid") < 0 ||
|
||||||
esxVI_LookupHostSystemProperties(priv->primary, propertyNameList,
|
esxVI_LookupHostSystemProperties(priv->primary, propertyNameList,
|
||||||
&hostSystem) < 0) {
|
&hostSystem) < 0 ||
|
||||||
|
esxVI_GetStringValue(hostSystem, "hardware.systemInfo.uuid",
|
||||||
|
&uuid_string, esxVI_Occurrence_RequiredItem) < 0) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hostSystem == NULL) {
|
if (strlen(uuid_string) > 0) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
if (virUUIDParse(uuid_string, uuid) < 0) {
|
||||||
_("Could not retrieve the HostSystem object"));
|
VIR_WARN("Could not parse host UUID from string '%s'", uuid_string);
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (dynamicProperty = hostSystem->propSet; dynamicProperty != NULL;
|
/* HostSystem has an invalid UUID, ignore it */
|
||||||
dynamicProperty = dynamicProperty->_next) {
|
memset(uuid, 0, VIR_UUID_BUFLEN);
|
||||||
if (STREQ(dynamicProperty->name, "hardware.systemInfo.uuid")) {
|
|
||||||
if (esxVI_AnyType_ExpectType(dynamicProperty->val,
|
|
||||||
esxVI_Type_String) < 0) {
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (strlen(dynamicProperty->val->string) > 0) {
|
|
||||||
if (virUUIDParse(dynamicProperty->val->string, uuid) < 0) {
|
|
||||||
VIR_WARN("Could not parse host UUID from string '%s'",
|
|
||||||
dynamicProperty->val->string);
|
|
||||||
|
|
||||||
/* HostSystem has an invalid UUID, ignore it */
|
|
||||||
memset(uuid, 0, VIR_UUID_BUFLEN);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
/* HostSystem has an empty UUID */
|
|
||||||
memset(uuid, 0, VIR_UUID_BUFLEN);
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
VIR_WARN("Unexpected '%s' property", dynamicProperty->name);
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
/* HostSystem has an empty UUID */
|
||||||
|
memset(uuid, 0, VIR_UUID_BUFLEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
result = 0;
|
result = 0;
|
||||||
@ -1176,17 +1151,8 @@ esxSupportsVMotion(esxPrivate *priv)
|
|||||||
if (esxVI_String_AppendValueToList(&propertyNameList,
|
if (esxVI_String_AppendValueToList(&propertyNameList,
|
||||||
"capability.vmotionSupported") < 0 ||
|
"capability.vmotionSupported") < 0 ||
|
||||||
esxVI_LookupHostSystemProperties(priv->primary, propertyNameList,
|
esxVI_LookupHostSystemProperties(priv->primary, propertyNameList,
|
||||||
&hostSystem) < 0) {
|
&hostSystem) < 0 ||
|
||||||
goto cleanup;
|
esxVI_GetBoolean(hostSystem, "capability.vmotionSupported",
|
||||||
}
|
|
||||||
|
|
||||||
if (hostSystem == NULL) {
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
||||||
_("Could not retrieve the HostSystem object"));
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (esxVI_GetBoolean(hostSystem, "capability.vmotionSupported",
|
|
||||||
&priv->supportsVMotion,
|
&priv->supportsVMotion,
|
||||||
esxVI_Occurrence_RequiredItem) < 0) {
|
esxVI_Occurrence_RequiredItem) < 0) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -1281,12 +1247,6 @@ esxGetHostname(virConnectPtr conn)
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hostSystem == NULL) {
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
||||||
_("Could not retrieve the HostSystem object"));
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (dynamicProperty = hostSystem->propSet; dynamicProperty != NULL;
|
for (dynamicProperty = hostSystem->propSet; dynamicProperty != NULL;
|
||||||
dynamicProperty = dynamicProperty->_next) {
|
dynamicProperty = dynamicProperty->_next) {
|
||||||
if (STREQ(dynamicProperty->name,
|
if (STREQ(dynamicProperty->name,
|
||||||
@ -1379,12 +1339,6 @@ esxNodeGetInfo(virConnectPtr conn, virNodeInfoPtr nodeinfo)
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hostSystem == NULL) {
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
||||||
_("Could not retrieve the HostSystem object"));
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (dynamicProperty = hostSystem->propSet; dynamicProperty != NULL;
|
for (dynamicProperty = hostSystem->propSet; dynamicProperty != NULL;
|
||||||
dynamicProperty = dynamicProperty->_next) {
|
dynamicProperty = dynamicProperty->_next) {
|
||||||
if (STREQ(dynamicProperty->name, "hardware.cpuInfo.hz")) {
|
if (STREQ(dynamicProperty->name, "hardware.cpuInfo.hz")) {
|
||||||
@ -2702,12 +2656,6 @@ esxDomainGetVcpusFlags(virDomainPtr domain, unsigned int flags)
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hostSystem == NULL) {
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
||||||
_("Could not retrieve the HostSystem object"));
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (dynamicProperty = hostSystem->propSet; dynamicProperty != NULL;
|
for (dynamicProperty = hostSystem->propSet; dynamicProperty != NULL;
|
||||||
dynamicProperty = dynamicProperty->_next) {
|
dynamicProperty = dynamicProperty->_next) {
|
||||||
if (STREQ(dynamicProperty->name, "capability.maxSupportedVcpus")) {
|
if (STREQ(dynamicProperty->name, "capability.maxSupportedVcpus")) {
|
||||||
|
@ -4570,8 +4570,8 @@ esxVI_ProductVersionToDefaultVirtualHWVersion(esxVI_ProductVersion productVersio
|
|||||||
esxVI_DynamicProperty *dynamicProperty = NULL; \
|
esxVI_DynamicProperty *dynamicProperty = NULL; \
|
||||||
\
|
\
|
||||||
if (ptrptr == NULL || *ptrptr != NULL) { \
|
if (ptrptr == NULL || *ptrptr != NULL) { \
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", \
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", \
|
||||||
_("Invalid argument")); \
|
_("Invalid argument")); \
|
||||||
return -1; \
|
return -1; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
|
@ -296,7 +296,8 @@
|
|||||||
childNode = childNode->next) { \
|
childNode = childNode->next) { \
|
||||||
if (childNode->type != XML_ELEMENT_NODE) { \
|
if (childNode->type != XML_ELEMENT_NODE) { \
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, \
|
virReportError(VIR_ERR_INTERNAL_ERROR, \
|
||||||
_("Wrong XML element type %d"), childNode->type); \
|
_("Wrong XML element type %d"), \
|
||||||
|
childNode->type); \
|
||||||
goto failure; \
|
goto failure; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
|
Loading…
Reference in New Issue
Block a user