[libvirt] [PATCH] esx: Make the parsed URI part of the private connection data
by Matthias Bolte
This will be used to make esxVI_Context clonable.
Also move cleanup code for esxPrivate to esxFreePrivate().
---
src/esx/esx_driver.c | 103 ++++++++++++++++++++++++-------------------------
src/esx/esx_private.h | 4 +-
2 files changed, 52 insertions(+), 55 deletions(-)
diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c
index ef76350..bfb3c16 100644
--- a/src/esx/esx_driver.c
+++ b/src/esx/esx_driver.c
@@ -3,7 +3,7 @@
* esx_driver.c: core driver functions for managing VMware ESX hosts
*
* Copyright (C) 2010-2011 Red Hat, Inc.
- * Copyright (C) 2009-2010 Matthias Bolte <matthias.bolte(a)googlemail.com>
+ * Copyright (C) 2009-2011 Matthias Bolte <matthias.bolte(a)googlemail.com>
* Copyright (C) 2009 Maximilian Wilhelm <max(a)rfc2324.org>
*
* This library is free software; you can redistribute it and/or
@@ -57,6 +57,22 @@ struct _esxVMX_Data {
+static void
+esxFreePrivate(esxPrivate **priv)
+{
+ if (priv == NULL || *priv == NULL) {
+ return;
+ }
+
+ esxVI_Context_Free(&(*priv)->host);
+ esxVI_Context_Free(&(*priv)->vCenter);
+ esxUtil_FreeParsedUri(&(*priv)->parsedUri);
+ virCapabilitiesFree((*priv)->caps);
+ VIR_FREE(*priv);
+}
+
+
+
/*
* Parse a file name from a .vmx file and convert it to datastore path format.
* A .vmx file can contain file names in various formats:
@@ -619,7 +635,6 @@ static int
esxConnectToHost(esxPrivate *priv, virConnectAuthPtr auth,
const char *hostname, int port,
const char *predefinedUsername,
- esxUtil_ParsedUri *parsedUri,
esxVI_ProductVersion expectedProductVersion,
char **vCenterIpAddress)
{
@@ -671,16 +686,16 @@ esxConnectToHost(esxPrivate *priv, virConnectAuthPtr auth,
goto cleanup;
}
- if (virAsprintf(&url, "%s://%s:%d/sdk", priv->transport, hostname,
- port) < 0) {
+ if (virAsprintf(&url, "%s://%s:%d/sdk", priv->parsedUri->transport,
+ hostname, port) < 0) {
virReportOOMError();
goto cleanup;
}
if (esxVI_Context_Alloc(&priv->host) < 0 ||
esxVI_Context_Connect(priv->host, url, ipAddress, username, password,
- parsedUri) < 0 ||
- esxVI_Context_LookupObjectsByPath(priv->host, parsedUri) < 0) {
+ priv->parsedUri) < 0 ||
+ esxVI_Context_LookupObjectsByPath(priv->host, priv->parsedUri) < 0) {
goto cleanup;
}
@@ -750,8 +765,7 @@ static int
esxConnectToVCenter(esxPrivate *priv, virConnectAuthPtr auth,
const char *hostname, int port,
const char *predefinedUsername,
- const char *hostSystemIpAddress,
- esxUtil_ParsedUri *parsedUri)
+ const char *hostSystemIpAddress)
{
int result = -1;
char ipAddress[NI_MAXHOST] = "";
@@ -761,8 +775,8 @@ esxConnectToVCenter(esxPrivate *priv, virConnectAuthPtr auth,
char *url = NULL;
if (hostSystemIpAddress == NULL &&
- (parsedUri->path_datacenter == NULL ||
- parsedUri->path_computeResource == NULL)) {
+ (priv->parsedUri->path_datacenter == NULL ||
+ priv->parsedUri->path_computeResource == NULL)) {
ESX_ERROR(VIR_ERR_INVALID_ARG, "%s",
_("Path has to specify the datacenter and compute resource"));
return -1;
@@ -801,15 +815,15 @@ esxConnectToVCenter(esxPrivate *priv, virConnectAuthPtr auth,
goto cleanup;
}
- if (virAsprintf(&url, "%s://%s:%d/sdk", priv->transport, hostname,
- port) < 0) {
+ if (virAsprintf(&url, "%s://%s:%d/sdk", priv->parsedUri->transport,
+ hostname, port) < 0) {
virReportOOMError();
goto cleanup;
}
if (esxVI_Context_Alloc(&priv->vCenter) < 0 ||
esxVI_Context_Connect(priv->vCenter, url, ipAddress, username,
- password, parsedUri) < 0) {
+ password, priv->parsedUri) < 0) {
goto cleanup;
}
@@ -829,7 +843,8 @@ esxConnectToVCenter(esxPrivate *priv, virConnectAuthPtr auth,
goto cleanup;
}
} else {
- if (esxVI_Context_LookupObjectsByPath(priv->vCenter, parsedUri) < 0) {
+ if (esxVI_Context_LookupObjectsByPath(priv->vCenter,
+ priv->parsedUri) < 0) {
goto cleanup;
}
}
@@ -896,7 +911,6 @@ esxOpen(virConnectPtr conn, virConnectAuthPtr auth, int flags ATTRIBUTE_UNUSED)
{
virDrvOpenStatus result = VIR_DRV_OPEN_ERROR;
esxPrivate *priv = NULL;
- esxUtil_ParsedUri *parsedUri = NULL;
char *potentialVCenterIpAddress = NULL;
char vCenterIpAddress[NI_MAXHOST] = "";
@@ -919,18 +933,15 @@ esxOpen(virConnectPtr conn, virConnectAuthPtr auth, int flags ATTRIBUTE_UNUSED)
goto cleanup;
}
- if (esxUtil_ParseUri(&parsedUri, conn->uri) < 0) {
+ if (esxUtil_ParseUri(&priv->parsedUri, conn->uri) < 0) {
goto cleanup;
}
- priv->transport = parsedUri->transport;
- parsedUri->transport = NULL;
-
priv->maxVcpus = -1;
priv->supportsVMotion = esxVI_Boolean_Undefined;
priv->supportsLongMode = esxVI_Boolean_Undefined;
- priv->autoAnswer = parsedUri->autoAnswer ? esxVI_Boolean_True
- : esxVI_Boolean_False;
+ priv->autoAnswer = priv->parsedUri->autoAnswer ? esxVI_Boolean_True
+ : esxVI_Boolean_False;
priv->usedCpuTimeCounterId = -1;
/*
@@ -942,13 +953,13 @@ esxOpen(virConnectPtr conn, virConnectAuthPtr auth, int flags ATTRIBUTE_UNUSED)
if (conn->uri->port == 0) {
if (STRCASEEQ(conn->uri->scheme, "vpx") ||
STRCASEEQ(conn->uri->scheme, "esx")) {
- if (STRCASEEQ(priv->transport, "https")) {
+ if (STRCASEEQ(priv->parsedUri->transport, "https")) {
conn->uri->port = 443;
} else {
conn->uri->port = 80;
}
} else { /* GSX */
- if (STRCASEEQ(priv->transport, "https")) {
+ if (STRCASEEQ(priv->parsedUri->transport, "https")) {
conn->uri->port = 8333;
} else {
conn->uri->port = 8222;
@@ -960,7 +971,7 @@ esxOpen(virConnectPtr conn, virConnectAuthPtr auth, int flags ATTRIBUTE_UNUSED)
STRCASEEQ(conn->uri->scheme, "gsx")) {
/* Connect to host */
if (esxConnectToHost(priv, auth, conn->uri->server, conn->uri->port,
- conn->uri->user, parsedUri,
+ conn->uri->user,
STRCASEEQ(conn->uri->scheme, "esx")
? esxVI_ProductVersion_ESX
: esxVI_ProductVersion_GSX,
@@ -969,8 +980,8 @@ esxOpen(virConnectPtr conn, virConnectAuthPtr auth, int flags ATTRIBUTE_UNUSED)
}
/* Connect to vCenter */
- if (parsedUri->vCenter != NULL) {
- if (STREQ(parsedUri->vCenter, "*")) {
+ if (priv->parsedUri->vCenter != NULL) {
+ if (STREQ(priv->parsedUri->vCenter, "*")) {
if (potentialVCenterIpAddress == NULL) {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
_("This host is not managed by a vCenter"));
@@ -985,7 +996,7 @@ esxOpen(virConnectPtr conn, virConnectAuthPtr auth, int flags ATTRIBUTE_UNUSED)
goto cleanup;
}
} else {
- if (esxUtil_ResolveHostname(parsedUri->vCenter,
+ if (esxUtil_ResolveHostname(priv->parsedUri->vCenter,
vCenterIpAddress, NI_MAXHOST) < 0) {
goto cleanup;
}
@@ -996,7 +1007,7 @@ esxOpen(virConnectPtr conn, virConnectAuthPtr auth, int flags ATTRIBUTE_UNUSED)
_("This host is managed by a vCenter with IP "
"address %s, but a mismachting vCenter '%s' "
"(%s) has been specified"),
- potentialVCenterIpAddress, parsedUri->vCenter,
+ potentialVCenterIpAddress, priv->parsedUri->vCenter,
vCenterIpAddress);
goto cleanup;
}
@@ -1004,7 +1015,7 @@ esxOpen(virConnectPtr conn, virConnectAuthPtr auth, int flags ATTRIBUTE_UNUSED)
if (esxConnectToVCenter(priv, auth, vCenterIpAddress,
conn->uri->port, NULL,
- priv->host->ipAddress, parsedUri) < 0) {
+ priv->host->ipAddress) < 0) {
goto cleanup;
}
}
@@ -1013,15 +1024,13 @@ esxOpen(virConnectPtr conn, virConnectAuthPtr auth, int flags ATTRIBUTE_UNUSED)
} else { /* VPX */
/* Connect to vCenter */
if (esxConnectToVCenter(priv, auth, conn->uri->server, conn->uri->port,
- conn->uri->user, NULL, parsedUri) < 0) {
+ conn->uri->user, NULL) < 0) {
goto cleanup;
}
priv->primary = priv->vCenter;
}
- conn->privateData = priv;
-
/* Setup capabilities */
priv->caps = esxCapsInit(priv);
@@ -1029,20 +1038,15 @@ esxOpen(virConnectPtr conn, virConnectAuthPtr auth, int flags ATTRIBUTE_UNUSED)
goto cleanup;
}
+ conn->privateData = priv;
+
result = VIR_DRV_OPEN_SUCCESS;
cleanup:
- if (result == VIR_DRV_OPEN_ERROR && priv != NULL) {
- esxVI_Context_Free(&priv->host);
- esxVI_Context_Free(&priv->vCenter);
-
- virCapabilitiesFree(priv->caps);
-
- VIR_FREE(priv->transport);
- VIR_FREE(priv);
+ if (result == VIR_DRV_OPEN_ERROR) {
+ esxFreePrivate(&priv);
}
- esxUtil_FreeParsedUri(&parsedUri);
VIR_FREE(potentialVCenterIpAddress);
return result;
@@ -1061,8 +1065,6 @@ esxClose(virConnectPtr conn)
esxVI_Logout(priv->host) < 0) {
result = -1;
}
-
- esxVI_Context_Free(&priv->host);
}
if (priv->vCenter != NULL) {
@@ -1070,14 +1072,9 @@ esxClose(virConnectPtr conn)
esxVI_Logout(priv->vCenter) < 0) {
result = -1;
}
-
- esxVI_Context_Free(&priv->vCenter);
}
- virCapabilitiesFree(priv->caps);
-
- VIR_FREE(priv->transport);
- VIR_FREE(priv);
+ esxFreePrivate(&priv);
conn->privateData = NULL;
@@ -2627,7 +2624,7 @@ esxDomainDumpXML(virDomainPtr domain, int flags)
goto cleanup;
}
- virBufferVSprintf(&buffer, "%s://%s:%d/folder/", priv->transport,
+ virBufferVSprintf(&buffer, "%s://%s:%d/folder/", priv->parsedUri->transport,
domain->conn->uri->server, domain->conn->uri->port);
virBufferURIEncodeString(&buffer, directoryAndFileName);
virBufferAddLit(&buffer, "?dcPath=");
@@ -3078,7 +3075,7 @@ esxDomainDefineXML(virConnectPtr conn, const char *xml)
goto cleanup;
}
- virBufferVSprintf(&buffer, "%s://%s:%d/folder/", priv->transport,
+ virBufferVSprintf(&buffer, "%s://%s:%d/folder/", priv->parsedUri->transport,
conn->uri->server, conn->uri->port);
if (directoryName != NULL) {
@@ -3960,7 +3957,7 @@ esxIsEncrypted(virConnectPtr conn)
{
esxPrivate *priv = conn->privateData;
- if (STRCASEEQ(priv->transport, "https")) {
+ if (STRCASEEQ(priv->parsedUri->transport, "https")) {
return 1;
} else {
return 0;
@@ -3974,7 +3971,7 @@ esxIsSecure(virConnectPtr conn)
{
esxPrivate *priv = conn->privateData;
- if (STRCASEEQ(priv->transport, "https")) {
+ if (STRCASEEQ(priv->parsedUri->transport, "https")) {
return 1;
} else {
return 0;
diff --git a/src/esx/esx_private.h b/src/esx/esx_private.h
index 6c7edb1..1da2552 100644
--- a/src/esx/esx_private.h
+++ b/src/esx/esx_private.h
@@ -2,7 +2,7 @@
/*
* esx_private.h: private driver struct for the VMware ESX driver
*
- * Copyright (C) 2009-2010 Matthias Bolte <matthias.bolte(a)googlemail.com>
+ * Copyright (C) 2009-2011 Matthias Bolte <matthias.bolte(a)googlemail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -36,8 +36,8 @@ typedef struct _esxPrivate {
esxVI_Context *primary; /* points to host or vCenter */
esxVI_Context *host;
esxVI_Context *vCenter;
+ esxUtil_ParsedUri *parsedUri;
virCapsPtr caps;
- char *transport;
int32_t maxVcpus;
esxVI_Boolean supportsVMotion;
esxVI_Boolean supportsLongMode; /* aka x86_64 */
--
1.7.0.4
13 years, 7 months
[libvirt] [PATCH] esx: Mark error message in macros for translation
by Matthias Bolte
---
src/esx/esx_vi_types.c | 20 ++++++++++----------
1 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/src/esx/esx_vi_types.c b/src/esx/esx_vi_types.c
index 9e23030..29a3c39 100644
--- a/src/esx/esx_vi_types.c
+++ b/src/esx/esx_vi_types.c
@@ -77,12 +77,12 @@
int \
esxVI_##__type##_Validate(esxVI_##__type *item) \
{ \
- const char *type_name = esxVI_Type_ToString(esxVI_Type_##__type); \
+ const char *typeName = esxVI_Type_ToString(esxVI_Type_##__type); \
\
if (item->_type <= esxVI_Type_Undefined || \
item->_type >= esxVI_Type_Other) { \
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, \
- "%s object has invalid dynamic type", type_name); \
+ _("%s object has invalid dynamic type"), typeName); \
return -1; \
} \
\
@@ -293,7 +293,7 @@
childNode = childNode->next) { \
if (childNode->type != XML_ELEMENT_NODE) { \
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, \
- "Wrong XML element type %d", childNode->type); \
+ _("Wrong XML element type %d"), childNode->type);\
goto failure; \
} \
\
@@ -343,22 +343,22 @@
\
if (string == NULL) { \
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, \
- "XML node doesn't contain text, expecting an " \
- _xsdType" value"); \
+ _("XML node doesn't contain text, expecting an %s " \
+ "value"), _xsdType); \
goto cleanup; \
} \
\
if (virStrToLong_ll(string, NULL, 10, &value) < 0) { \
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, \
- "Unknown value '%s' for "_xsdType, string); \
+ _("Unknown value '%s' for %s"), string, _xsdType); \
goto cleanup; \
} \
\
if (((_min) != INT64_MIN && value < (_min)) \
|| ((_max) != INT64_MAX && value > (_max))) { \
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, \
- "Value '%s' is not representable as "_xsdType, \
- (const char *)string); \
+ _("Value '%s' is not representable as %s"), \
+ string, _xsdType); \
goto cleanup; \
} \
\
@@ -482,8 +482,8 @@
#define ESX_VI__TEMPLATE__PROPERTY__REQUIRE(_name) \
if (item->_name == 0) { \
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, \
- "%s object is missing the required '%s' property", \
- type_name, #_name); \
+ _("%s object is missing the required '%s' property"), \
+ typeName, #_name); \
return -1; \
}
--
1.7.0.4
13 years, 7 months
[libvirt] [PATCH] esx: Extend VI generator to cover managed object types
by Matthias Bolte
Generate lookup functions for managed object types.
---
src/esx/esx_vi.c | 414 +++++++++++++++++++++++-----------------
src/esx/esx_vi.h | 2 +
src/esx/esx_vi_generator.input | 28 +++-
src/esx/esx_vi_generator.py | 411 ++++++++++++++++++++++++++++++++++++++--
src/esx/esx_vi_types.c | 349 ++++++----------------------------
src/esx/esx_vi_types.h | 102 ++---------
6 files changed, 728 insertions(+), 578 deletions(-)
diff --git a/src/esx/esx_vi.c b/src/esx/esx_vi.c
index 7446ec5..fbab347 100644
--- a/src/esx/esx_vi.c
+++ b/src/esx/esx_vi.c
@@ -3,7 +3,7 @@
* esx_vi.c: client for the VMware VI API 2.5 to manage ESX hosts
*
* Copyright (C) 2010 Red Hat, Inc.
- * Copyright (C) 2009-2010 Matthias Bolte <matthias.bolte(a)googlemail.com>
+ * Copyright (C) 2009-2011 Matthias Bolte <matthias.bolte(a)googlemail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -481,107 +481,26 @@ int
esxVI_Context_LookupObjectsByPath(esxVI_Context *ctx,
esxUtil_ParsedUri *parsedUri)
{
- int result = -1;
- esxVI_String *propertyNameList = NULL;
- char *name = NULL;
- esxVI_ObjectContent *datacenterList = NULL;
- esxVI_ObjectContent *datacenter = NULL;
- esxVI_ObjectContent *computeResourceList = NULL;
- esxVI_ObjectContent *computeResource = NULL;
char *hostSystemName = NULL;
- esxVI_ObjectContent *hostSystemList = NULL;
- esxVI_ObjectContent *hostSystem = NULL;
-
/* Lookup Datacenter */
- if (esxVI_String_AppendValueListToList(&propertyNameList,
- "name\0"
- "vmFolder\0"
- "hostFolder\0") < 0 ||
- esxVI_LookupObjectContentByType(ctx, ctx->service->rootFolder,
- "Datacenter", propertyNameList,
- &datacenterList,
- esxVI_Occurrence_RequiredList) < 0) {
- goto cleanup;
- }
-
- if (parsedUri->path_datacenter != NULL) {
- for (datacenter = datacenterList; datacenter != NULL;
- datacenter = datacenter->_next) {
- name = NULL;
-
- if (esxVI_GetStringValue(datacenter, "name", &name,
- esxVI_Occurrence_RequiredItem) < 0) {
- goto cleanup;
- }
-
- if (STREQ(name, parsedUri->path_datacenter)) {
- break;
- }
- }
-
- if (datacenter == NULL) {
- ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
- _("Could not find datacenter '%s'"),
- parsedUri->path_datacenter);
- goto cleanup;
- }
- } else {
- datacenter = datacenterList;
- }
-
- if (esxVI_Datacenter_CastFromObjectContent(datacenter,
- &ctx->datacenter) < 0) {
- goto cleanup;
+ if (esxVI_LookupDatacenter(ctx, parsedUri->path_datacenter,
+ ctx->service->rootFolder, NULL, &ctx->datacenter,
+ esxVI_Occurrence_RequiredItem) < 0) {
+ return -1;
}
/* Lookup (Cluster)ComputeResource */
- esxVI_String_Free(&propertyNameList);
-
- if (esxVI_String_AppendValueListToList(&propertyNameList,
- "name\0"
- "host\0"
- "resourcePool\0") < 0 ||
- esxVI_LookupObjectContentByType(ctx, ctx->datacenter->hostFolder,
- "ComputeResource", propertyNameList,
- &computeResourceList,
- esxVI_Occurrence_RequiredList) < 0) {
- goto cleanup;
- }
-
- if (parsedUri->path_computeResource != NULL) {
- for (computeResource = computeResourceList; computeResource != NULL;
- computeResource = computeResource->_next) {
- name = NULL;
-
- if (esxVI_GetStringValue(computeResource, "name", &name,
- esxVI_Occurrence_RequiredItem) < 0) {
- goto cleanup;
- }
-
- if (STREQ(name, parsedUri->path_computeResource)) {
- break;
- }
- }
-
- if (computeResource == NULL) {
- ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
- _("Could not find compute resource '%s'"),
- parsedUri->path_computeResource);
- goto cleanup;
- }
- } else {
- computeResource = computeResourceList;
- }
-
- if (esxVI_ComputeResource_CastFromObjectContent(computeResource,
- &ctx->computeResource) < 0) {
- goto cleanup;
+ if (esxVI_LookupComputeResource(ctx, parsedUri->path_computeResource,
+ ctx->datacenter->hostFolder, NULL,
+ &ctx->computeResource,
+ esxVI_Occurrence_RequiredItem) < 0) {
+ return -1;
}
if (ctx->computeResource->resourcePool == NULL) {
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
_("Could not retrieve resource pool"));
- goto cleanup;
+ return -1;
}
/* Lookup HostSystem */
@@ -590,19 +509,7 @@ esxVI_Context_LookupObjectsByPath(esxVI_Context *ctx,
"ClusterComputeResource")) {
ESX_VI_ERROR(VIR_ERR_INVALID_ARG, "%s",
_("Path has to specify the host system"));
- goto cleanup;
- }
-
- esxVI_String_Free(&propertyNameList);
-
- if (esxVI_String_AppendValueListToList(&propertyNameList,
- "name\0"
- "configManager\0") < 0 ||
- esxVI_LookupObjectContentByType(ctx, ctx->computeResource->_reference,
- "HostSystem", propertyNameList,
- &hostSystemList,
- esxVI_Occurrence_RequiredList) < 0) {
- goto cleanup;
+ return -1;
}
if (parsedUri->path_hostSystem != NULL ||
@@ -613,44 +520,16 @@ esxVI_Context_LookupObjectsByPath(esxVI_Context *ctx,
} else {
hostSystemName = parsedUri->path_computeResource;
}
-
- for (hostSystem = hostSystemList; hostSystem != NULL;
- hostSystem = hostSystem->_next) {
- name = NULL;
-
- if (esxVI_GetStringValue(hostSystem, "name", &name,
- esxVI_Occurrence_RequiredItem) < 0) {
- goto cleanup;
- }
-
- if (STREQ(name, hostSystemName)) {
- break;
- }
- }
-
- if (hostSystem == NULL) {
- ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
- _("Could not find host system '%s'"), hostSystemName);
- goto cleanup;
- }
- } else {
- hostSystem = hostSystemList;
}
- if (esxVI_HostSystem_CastFromObjectContent(hostSystem,
- &ctx->hostSystem) < 0) {
- goto cleanup;
+ if (esxVI_LookupHostSystem(ctx, hostSystemName,
+ ctx->computeResource->_reference, NULL,
+ &ctx->hostSystem,
+ esxVI_Occurrence_RequiredItem) < 0) {
+ return -1;
}
- result = 0;
-
- cleanup:
- esxVI_String_Free(&propertyNameList);
- esxVI_ObjectContent_Free(&datacenterList);
- esxVI_ObjectContent_Free(&computeResourceList);
- esxVI_ObjectContent_Free(&hostSystemList);
-
- return result;
+ return 0;
}
int
@@ -658,67 +537,41 @@ esxVI_Context_LookupObjectsByHostSystemIp(esxVI_Context *ctx,
const char *hostSystemIpAddress)
{
int result = -1;
- esxVI_String *propertyNameList = NULL;
esxVI_ManagedObjectReference *managedObjectReference = NULL;
- esxVI_ObjectContent *hostSystem = NULL;
- esxVI_ObjectContent *computeResource = NULL;
- esxVI_ObjectContent *datacenter = NULL;
/* Lookup HostSystem */
- if (esxVI_String_AppendValueListToList(&propertyNameList,
- "name\0"
- "configManager\0") < 0 ||
- esxVI_FindByIp(ctx, NULL, hostSystemIpAddress, esxVI_Boolean_False,
+ if (esxVI_FindByIp(ctx, NULL, hostSystemIpAddress, esxVI_Boolean_False,
&managedObjectReference) < 0 ||
- esxVI_LookupObjectContentByType(ctx, managedObjectReference,
- "HostSystem", propertyNameList,
- &hostSystem,
- esxVI_Occurrence_RequiredItem) < 0 ||
- esxVI_HostSystem_CastFromObjectContent(hostSystem,
- &ctx->hostSystem) < 0) {
+ esxVI_LookupHostSystem(ctx, NULL, managedObjectReference, NULL,
+ &ctx->hostSystem,
+ esxVI_Occurrence_RequiredItem) < 0) {
goto cleanup;
}
/* Lookup (Cluster)ComputeResource */
- esxVI_String_Free(&propertyNameList);
+ if (esxVI_LookupComputeResource(ctx, NULL, ctx->hostSystem->_reference,
+ NULL, &ctx->computeResource,
+ esxVI_Occurrence_RequiredItem) < 0) {
+ goto cleanup;
+ }
- if (esxVI_String_AppendValueListToList(&propertyNameList,
- "name\0"
- "host\0"
- "resourcePool\0") < 0 ||
- esxVI_LookupObjectContentByType(ctx, hostSystem->obj,
- "ComputeResource", propertyNameList,
- &computeResource,
- esxVI_Occurrence_RequiredItem) < 0 ||
- esxVI_ComputeResource_CastFromObjectContent(computeResource,
- &ctx->computeResource) < 0) {
+ if (ctx->computeResource->resourcePool == NULL) {
+ ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("Could not retrieve resource pool"));
goto cleanup;
}
/* Lookup Datacenter */
- esxVI_String_Free(&propertyNameList);
-
- if (esxVI_String_AppendValueListToList(&propertyNameList,
- "name\0"
- "vmFolder\0"
- "hostFolder\0") < 0 ||
- esxVI_LookupObjectContentByType(ctx, computeResource->obj,
- "Datacenter", propertyNameList,
- &datacenter,
- esxVI_Occurrence_RequiredItem) < 0 ||
- esxVI_Datacenter_CastFromObjectContent(datacenter,
- &ctx->datacenter) < 0) {
+ if (esxVI_LookupDatacenter(ctx, NULL, ctx->computeResource->_reference,
+ NULL, &ctx->datacenter,
+ esxVI_Occurrence_RequiredItem) < 0) {
goto cleanup;
}
result = 0;
cleanup:
- esxVI_String_Free(&propertyNameList);
esxVI_ManagedObjectReference_Free(&managedObjectReference);
- esxVI_ObjectContent_Free(&hostSystem);
- esxVI_ObjectContent_Free(&computeResource);
- esxVI_ObjectContent_Free(&datacenter);
return result;
}
@@ -3872,3 +3725,204 @@ esxVI_ProductVersionToDefaultVirtualHWVersion(esxVI_ProductVersion productVersio
return -1;
}
}
+
+
+
+
+#define ESX_VI__TEMPLATE__PROPERTY__CAST_FROM_ANY_TYPE_IGNORE(_name) \
+ if (STREQ(dynamicProperty->name, #_name)) { \
+ continue; \
+ }
+
+
+
+#define ESX_VI__TEMPLATE__PROPERTY__CAST_FROM_ANY_TYPE(_type, _name) \
+ if (STREQ(dynamicProperty->name, #_name)) { \
+ if (esxVI_##_type##_CastFromAnyType(dynamicProperty->val, \
+ &(*ptrptr)->_name) < 0) { \
+ goto cleanup; \
+ } \
+ \
+ continue; \
+ }
+
+
+
+#define ESX_VI__TEMPLATE__PROPERTY__CAST_LIST_FROM_ANY_TYPE(_type, _name) \
+ if (STREQ(dynamicProperty->name, #_name)) { \
+ if (esxVI_##_type##_CastListFromAnyType(dynamicProperty->val, \
+ &(*ptrptr)->_name) < 0) { \
+ goto cleanup; \
+ } \
+ \
+ continue; \
+ }
+
+
+
+#define ESX_VI__TEMPLATE__PROPERTY__CAST_VALUE_FROM_ANY_TYPE(_type, _name) \
+ if (STREQ(dynamicProperty->name, #_name)) { \
+ if (esxVI_##_type##_CastValueFromAnyType(dynamicProperty->val, \
+ &(*ptrptr)->_name) < 0) { \
+ goto cleanup; \
+ } \
+ \
+ continue; \
+ }
+
+
+
+#define ESX_VI__TEMPLATE__LOOKUP(_type, _complete_properties, \
+ _cast_from_anytype) \
+ int \
+ esxVI_Lookup##_type(esxVI_Context *ctx, const char* name /* optional */, \
+ esxVI_ManagedObjectReference *root, \
+ esxVI_String *selectedPropertyNameList /* optional */,\
+ esxVI_##_type **ptrptr, esxVI_Occurrence occurrence) \
+ { \
+ int result = -1; \
+ const char *completePropertyNameValueList = _complete_properties; \
+ esxVI_String *propertyNameList = NULL; \
+ esxVI_ObjectContent *objectContent = NULL; \
+ esxVI_ObjectContent *objectContentList = NULL; \
+ esxVI_DynamicProperty *dynamicProperty = NULL; \
+ \
+ if (ptrptr == NULL || *ptrptr != NULL) { \
+ ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", \
+ _("Invalid argument")); \
+ return -1; \
+ } \
+ \
+ propertyNameList = selectedPropertyNameList; \
+ \
+ if (propertyNameList == NULL && \
+ esxVI_String_AppendValueListToList \
+ (&propertyNameList, completePropertyNameValueList) < 0) { \
+ goto cleanup; \
+ } \
+ \
+ if (esxVI_LookupManagedObjectHelper(ctx, name, root, #_type, \
+ propertyNameList, &objectContent, \
+ &objectContentList, \
+ occurrence) < 0) { \
+ goto cleanup; \
+ } \
+ \
+ if (esxVI_##_type##_Alloc(ptrptr) < 0) { \
+ goto cleanup; \
+ } \
+ \
+ if (esxVI_ManagedObjectReference_DeepCopy(&(*ptrptr)->_reference, \
+ objectContent->obj) < 0) { \
+ goto cleanup; \
+ } \
+ \
+ for (dynamicProperty = objectContent->propSet; \
+ dynamicProperty != NULL; \
+ dynamicProperty = dynamicProperty->_next) { \
+ _cast_from_anytype \
+ \
+ VIR_WARN("Unexpected '%s' property", dynamicProperty->name); \
+ } \
+ \
+ if (esxVI_##_type##_Validate(*ptrptr, selectedPropertyNameList) < 0) {\
+ goto cleanup; \
+ } \
+ \
+ result = 0; \
+ \
+ cleanup: \
+ if (result < 0) { \
+ esxVI_##_type##_Free(ptrptr); \
+ } \
+ \
+ if (propertyNameList != selectedPropertyNameList) { \
+ esxVI_String_Free(&propertyNameList); \
+ } \
+ \
+ esxVI_ObjectContent_Free(&objectContentList); \
+ \
+ return result; \
+ }
+
+
+
+static int
+esxVI_LookupManagedObjectHelper(esxVI_Context *ctx,
+ const char *name /* optional */,
+ esxVI_ManagedObjectReference *root,
+ const char *type,
+ esxVI_String *propertyNameList,
+ esxVI_ObjectContent **objectContent,
+ esxVI_ObjectContent **objectContentList,
+ esxVI_Occurrence occurrence)
+{
+ int result = -1;
+ esxVI_ObjectContent *candidate = NULL;
+ char *name_candidate;
+
+ if (objectContent == NULL || *objectContent != NULL ||
+ objectContentList == NULL || *objectContentList != NULL) {
+ ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
+ return -1;
+ }
+
+ if (!esxVI_String_ListContainsValue(propertyNameList, "name")) {
+ ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
+ _("Missing 'name' property in %s lookup"), type);
+ goto cleanup;
+ }
+
+ if (esxVI_LookupObjectContentByType(ctx, root, type, propertyNameList,
+ objectContentList,
+ esxVI_Occurrence_OptionalList) < 0) {
+ goto cleanup;
+ }
+
+ /* Search for a matching item */
+ if (name != NULL) {
+ for (candidate = *objectContentList; candidate != NULL;
+ candidate = candidate->_next) {
+ name_candidate = NULL;
+
+ if (esxVI_GetStringValue(candidate, "name", &name_candidate,
+ esxVI_Occurrence_RequiredItem) < 0) {
+ goto cleanup;
+ }
+
+ if (STREQ(name_candidate, name)) {
+ /* Found item with matching name */
+ break;
+ }
+ }
+ } else {
+ candidate = *objectContentList;
+ }
+
+ if (candidate == NULL) {
+ if (occurrence != esxVI_Occurrence_OptionalItem) {
+ ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
+ _("Could not find %s with name '%s'"), type, name);
+ goto cleanup;
+ }
+
+ result = 0;
+
+ goto cleanup;
+ }
+
+ result = 0;
+
+ cleanup:
+ if (result < 0) {
+ esxVI_ObjectContent_Free(objectContentList);
+ } else {
+ *objectContent = candidate;
+ }
+
+ return result;
+}
+
+
+
+#include "esx_vi.generated.c"
diff --git a/src/esx/esx_vi.h b/src/esx/esx_vi.h
index e150dbf..d046bf9 100644
--- a/src/esx/esx_vi.h
+++ b/src/esx/esx_vi.h
@@ -444,4 +444,6 @@ int esxVI_ParseHostCpuIdInfo(esxVI_ParsedHostCpuIdInfo *parsedHostCpuIdInfo,
int esxVI_ProductVersionToDefaultVirtualHWVersion(esxVI_ProductVersion productVersion);
+# include "esx_vi.generated.h"
+
#endif /* __ESX_VI_H__ */
diff --git a/src/esx/esx_vi_generator.input b/src/esx/esx_vi_generator.input
index 44d1d9b..98b5206 100644
--- a/src/esx/esx_vi_generator.input
+++ b/src/esx/esx_vi_generator.input
@@ -15,7 +15,7 @@
#
# Object definition:
#
-# object <name> [extends <name>]
+# [managed] object <name> [extends <name>]
# <type> <name> <occurrence>
# ...
# end
@@ -739,6 +739,32 @@ end
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+# Managed Objects
+#
+
+managed object ComputeResource extends ManagedEntity
+ ManagedObjectReference host ol
+ ManagedObjectReference resourcePool o
+end
+
+
+managed object Datacenter extends ManagedEntity
+ ManagedObjectReference hostFolder r
+ ManagedObjectReference vmFolder r
+end
+
+
+managed object HostSystem extends ManagedEntity
+ HostConfigManager configManager r
+end
+
+
+managed object ManagedEntity
+ String name r
+end
+
+
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Methods
#
diff --git a/src/esx/esx_vi_generator.py b/src/esx/esx_vi_generator.py
index 0fd84dd..ab127a3 100755
--- a/src/esx/esx_vi_generator.py
+++ b/src/esx/esx_vi_generator.py
@@ -3,7 +3,7 @@
#
# esx_vi_generator.py: generates most of the SOAP type mapping code
#
-# Copyright (C) 2010 Matthias Bolte <matthias.bolte(a)googlemail.com>
+# Copyright (C) 2010-2011 Matthias Bolte <matthias.bolte(a)googlemail.com>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
@@ -297,10 +297,15 @@ class Property:
return " esxVI_%s_Free(&item->%s);\n" % (self.type, self.name)
- def generate_validate_code(self):
+ def generate_validate_code(self, managed=False):
+ if managed:
+ macro = "ESX_VI__TEMPLATE__PROPERTY__MANAGED_REQUIRE"
+ else:
+ macro = "ESX_VI__TEMPLATE__PROPERTY__REQUIRE"
+
if self.occurrence in [OCCURRENCE__REQUIRED_ITEM,
OCCURRENCE__REQUIRED_LIST]:
- return " ESX_VI__TEMPLATE__PROPERTY__REQUIRE(%s)\n" % self.name
+ return " %s(%s)\n" % (macro, self.name)
elif self.occurrence == OCCURRENCE__IGNORED:
return " /* FIXME: %s is currently ignored */\n" % self.name
else:
@@ -345,6 +350,18 @@ class Property:
return " ESX_VI__TEMPLATE__PROPERTY__DESERIALIZE(%s, %s)\n" % (self.type, self.name)
+ def generate_lookup_code(self):
+ if self.occurrence == OCCURRENCE__IGNORED:
+ return " ESX_VI__TEMPLATE__PROPERTY__CAST_FROM_ANY_TYPE_IGNORE(%s) /* FIXME */\n" % self.name
+ elif self.occurrence in [OCCURRENCE__REQUIRED_LIST,
+ OCCURRENCE__OPTIONAL_LIST]:
+ return " ESX_VI__TEMPLATE__PROPERTY__CAST_LIST_FROM_ANY_TYPE(%s, %s)\n" % (self.type, self.name)
+ elif self.type == "String":
+ return " ESX_VI__TEMPLATE__PROPERTY__CAST_VALUE_FROM_ANY_TYPE(String, %s)\n" % self.name
+ else:
+ return " ESX_VI__TEMPLATE__PROPERTY__CAST_FROM_ANY_TYPE(%s, %s)\n" % (self.type, self.name)
+
+
def get_type_string(self):
if self.type == "String" and \
self.occurrence not in [OCCURRENCE__REQUIRED_LIST,
@@ -572,20 +589,20 @@ class Object(Base):
def generate_header(self):
header = "/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n"
- header += " * VI Type: %s\n" % self.name
+ header += " * VI Object: %s\n" % self.name
if self.extends is not None:
- header += " * extends %s\n" % self.extends
+ header += " * extends %s\n" % self.extends
first = True
if self.extended_by is not None:
for extended_by in self.extended_by:
if first:
- header += " * extended by %s\n" % extended_by
+ header += " * extended by %s\n" % extended_by
first = False
else:
- header += " * %s\n" % extended_by
+ header += " * %s\n" % extended_by
header += " */\n\n"
@@ -646,20 +663,20 @@ class Object(Base):
def generate_source(self):
source = "/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n"
- source += " * VI Type: %s\n" % self.name
+ source += " * VI Object: %s\n" % self.name
if self.extends is not None:
- source += " * extends %s\n" % self.extends
+ source += " * extends %s\n" % self.extends
first = True
if self.extended_by is not None:
for extended_by in self.extended_by:
if first:
- source += " * extended by %s\n" % extended_by
+ source += " * extended by %s\n" % extended_by
first = False
else:
- source += " * %s\n" % extended_by
+ source += " * %s\n" % extended_by
source += " */\n\n"
@@ -863,15 +880,303 @@ class Object(Base):
+class ManagedObject(Base):
+ FEATURE__LIST = (1 << 2)
+
+
+ def __init__(self, name, extends, properties, features=0, extended_by=None):
+ Base.__init__(self, "struct", name)
+ self.extends = extends
+ self.features = features
+ self.properties = properties
+ self.extended_by = extended_by
+
+ if self.extended_by is not None:
+ self.extended_by.sort()
+
+
+ def generate_struct_members(self, add_banner=False, struct_gap=False):
+ members = ""
+
+ if struct_gap:
+ members += "\n"
+
+ if self.extends is not None:
+ members += managed_objects_by_name[self.extends].generate_struct_members(add_banner=True) + "\n"
+
+ if self.extends is not None or add_banner:
+ members += " /* %s */\n" % self.name
+
+ for property in self.properties:
+ members += property.generate_struct_member()
+
+ if len(self.properties) < 1:
+ members += " /* no properties */\n"
+
+ return members
+
+
+ def generate_free_code(self, add_banner=False):
+ source = ""
+ if self.extends is not None:
+ source += managed_objects_by_name[self.extends].generate_free_code(add_banner=True) + "\n"
+ if self.extends is not None or add_banner:
+ source += " /* %s */\n" % self.name
+ if len(self.properties) < 1:
+ source += " /* no properties */\n"
+ else:
+ string = ""
+ for property in self.properties:
+ string += property.generate_free_code()
+ if len(string) < 1:
+ source += " /* no properties to be freed */\n"
+ else:
+ source += string
+ return source
+ def generate_validate_code(self, add_banner=False):
+ source = ""
+
+ if self.extends is not None:
+ source += managed_objects_by_name[self.extends].generate_validate_code(add_banner=True) + "\n"
+
+ if self.extends is not None or add_banner:
+ source += " /* %s */\n" % self.name
+
+ if len(self.properties) < 1:
+ source += " /* no properties */\n"
+ else:
+ string = ""
+ for property in self.properties:
+ string += property.generate_validate_code(managed=True)
+
+ if len(string) < 1:
+ source += " /* no required properties */\n"
+ else:
+ source += string
+
+ return source
+
+
+ def generate_lookup_code1(self, add_banner=False):
+ source = ""
+
+ if self.extends is not None:
+ source += managed_objects_by_name[self.extends].generate_lookup_code1(add_banner=True) + "\n"
+
+ if self.extends is not None or add_banner:
+ source += " /* %s */\n" % self.name
+
+ if len(self.properties) < 1:
+ source += " /* no properties */\n"
+ else:
+ string = ""
+
+ for property in self.properties:
+ string += " \"%s\\0\"\n" % property.name
+
+ if len(string) < 1:
+ source += " /* no properties */\n"
+ else:
+ source += string
+
+ return source
+
+
+ def generate_lookup_code2(self, add_banner=False):
+ source = ""
+
+ if self.extends is not None:
+ source += managed_objects_by_name[self.extends].generate_lookup_code2(add_banner=True) + "\n"
+
+ if self.extends is not None or add_banner:
+ source += " /* %s */\n" % self.name
+
+ if len(self.properties) < 1:
+ source += " /* no properties */\n"
+ else:
+ string = ""
+
+ for property in self.properties:
+ string += property.generate_lookup_code()
+
+ if len(string) < 1:
+ source += " /* no properties */\n"
+ else:
+ source += string
+
+ return source
+
+
+ def generate_comment(self):
+ comment = "/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n"
+ comment += " * VI Managed Object: %s\n" % self.name
+
+ if self.extends is not None:
+ comment += " * extends %s\n" % self.extends
+
+ first = True
+
+ if self.extended_by is not None:
+ for extended_by in self.extended_by:
+ if first:
+ comment += " * extended by %s\n" % extended_by
+ first = False
+ else:
+ comment += " * %s\n" % extended_by
+
+ comment += " */\n\n"
+
+ return comment
+
+
+ def generate_header(self):
+ header = self.generate_comment()
+
+ # struct
+ header += "struct _esxVI_%s {\n" % self.name
+
+ if self.features & Object.FEATURE__LIST:
+ header += aligned(" esxVI_%s *_next; " % self.name, "/* optional */\n")
+ else:
+ header += aligned(" esxVI_%s *_unused; " % self.name, "/* optional */\n")
+
+ header += aligned(" esxVI_Type _type; ", "/* required */\n")
+ header += aligned(" esxVI_ManagedObjectReference *_reference; ", "/* required */\n")
+ header += "\n"
+ header += self.generate_struct_members()
+
+ header += "};\n\n"
+
+ # functions
+ header += "int esxVI_%s_Alloc(esxVI_%s **item);\n" % (self.name, self.name)
+ header += "void esxVI_%s_Free(esxVI_%s **item);\n" % (self.name, self.name)
+ header += "int esxVI_%s_Validate(esxVI_%s *item, esxVI_String *selectedPropertyNameList);\n" % (self.name, self.name)
+
+ if self.features & Object.FEATURE__LIST:
+ header += "int esxVI_%s_AppendToList(esxVI_%s **list, esxVI_%s *item);\n" % (self.name, self.name, self.name)
+
+ header += "\n\n\n"
+
+ return header
+
+
+ def generate_helper_header(self):
+ header = ""
+
+ # functions
+ header += ("int esxVI_Lookup%s(esxVI_Context *ctx, " +
+ "const char *name, " +
+ "esxVI_ManagedObjectReference *root, " +
+ "esxVI_String *selectedPropertyNameList, " +
+ "esxVI_%s **item, " +
+ "esxVI_Occurrence occurrence);\n") % (self.name, self.name)
+
+ header += "\n"
+
+ return header
+
+
+ def generate_source(self):
+ source = self.generate_comment()
+
+ # functions
+ source += "/* esxVI_%s_Alloc */\n" % self.name
+ source += "ESX_VI__TEMPLATE__ALLOC(%s)\n\n" % self.name
+
+ # free
+ if self.extended_by is None:
+ source += "/* esxVI_%s_Free */\n" % self.name
+ source += "ESX_VI__TEMPLATE__FREE(%s,\n" % self.name
+ source += "{\n"
+
+ if self.features & ManagedObject.FEATURE__LIST:
+ if self.extends is not None:
+ # avoid "dereferencing type-punned pointer will break strict-aliasing rules" warnings
+ source += " esxVI_%s *next = (esxVI_%s *)item->_next;\n\n" % (self.extends, self.extends)
+ source += " esxVI_%s_Free(&next);\n" % self.extends
+ source += " item->_next = (esxVI_%s *)next;\n\n" % self.name
+ else:
+ source += " esxVI_%s_Free(&item->_next);\n" % self.name
+
+ source += " esxVI_ManagedObjectReference_Free(&item->_reference);\n\n"
+
+ source += self.generate_free_code()
+
+ source += "})\n\n"
+ else:
+ source += "/* esxVI_%s_Free */\n" % self.name
+ source += "ESX_VI__TEMPLATE__DYNAMIC_FREE(%s,\n" % self.name
+ source += "{\n"
+
+ for extended_by in self.extended_by:
+ source += " ESX_VI__TEMPLATE__DISPATCH__FREE(%s)\n" % extended_by
+
+ source += "},\n"
+ source += "{\n"
+
+ if self.features & Object.FEATURE__LIST:
+ if self.extends is not None:
+ # avoid "dereferencing type-punned pointer will break strict-aliasing rules" warnings
+ source += " esxVI_%s *next = (esxVI_%s *)item->_next;\n\n" % (self.extends, self.extends)
+ source += " esxVI_%s_Free(&next);\n" % self.extends
+ source += " item->_next = (esxVI_%s *)next;\n\n" % self.name
+ else:
+ source += " esxVI_%s_Free(&item->_next);\n" % self.name
+
+ source += " esxVI_ManagedObjectReference_Free(&item->_reference);\n\n"
+
+ source += self.generate_free_code()
+
+ source += "})\n\n"
+
+ # validate
+ source += "/* esxVI_%s_Validate */\n" % self.name
+ source += "ESX_VI__TEMPLATE__MANAGED_VALIDATE(%s,\n" % self.name
+ source += "{\n"
+
+ source += self.generate_validate_code()
+
+ source += "})\n\n"
+
+ # append to list
+ if self.features & ManagedObject.FEATURE__LIST:
+ source += "/* esxVI_%s_AppendToList */\n" % self.name
+ source += "ESX_VI__TEMPLATE__LIST__APPEND(%s)\n\n" % self.name
+
+ source += "\n\n"
+
+ return source
+
+
+ def generate_helper_source(self):
+ source = ""
+
+ # lookup
+ source += "/* esxVI_Lookup%s */\n" % self.name
+ source += "ESX_VI__TEMPLATE__LOOKUP(%s,\n" % self.name
+ source += "{\n"
+
+ source += self.generate_lookup_code1()
+
+ source += "},\n"
+ source += "{\n"
+
+ source += self.generate_lookup_code2()
+
+ source += "})\n\n"
+
+ source += "\n\n"
+
+ return source
@@ -962,8 +1267,13 @@ def capitalize_first(string):
def parse_object(block):
- # expected format: object <name> [extends <name>]
+ # expected format: [managed] object <name> [extends <name>]
header_items = block[0][1].split()
+ managed = False
+
+ if header_items[0] == "managed":
+ managed = True
+ del header_items[0]
if len(header_items) < 2:
report_error("line %d: invalid block header" % (number))
@@ -994,7 +1304,10 @@ def parse_object(block):
properties.append(Property(type=items[0], name=items[1],
occurrence=items[2]))
- return Object(name = name, extends = extends, properties = properties)
+ if managed:
+ return ManagedObject(name=name, extends=extends, properties=properties)
+ else:
+ return Object(name=name, extends=extends, properties=properties)
@@ -1075,6 +1388,7 @@ def is_known_type(type):
return type in predefined_objects or \
type in predefined_enums or \
type in objects_by_name or \
+ type in managed_objects_by_name or \
type in enums_by_name
@@ -1169,11 +1483,14 @@ types_header = open_and_print(os.path.join(output_dirname, "esx_vi_types.generat
types_source = open_and_print(os.path.join(output_dirname, "esx_vi_types.generated.c"))
methods_header = open_and_print(os.path.join(output_dirname, "esx_vi_methods.generated.h"))
methods_source = open_and_print(os.path.join(output_dirname, "esx_vi_methods.generated.c"))
+helpers_header = open_and_print(os.path.join(output_dirname, "esx_vi.generated.h"))
+helpers_source = open_and_print(os.path.join(output_dirname, "esx_vi.generated.c"))
number = 0
objects_by_name = {}
+managed_objects_by_name = {}
enums_by_name = {}
methods_by_name = {}
block = None
@@ -1191,7 +1508,8 @@ for line in file(input_filename, "rb").readlines():
if len(line) < 1:
continue
- if line.startswith("object") or line.startswith("enum") or line.startswith("method"):
+ if line.startswith("object") or line.startswith("managed object") or \
+ line.startswith("enum") or line.startswith("method"):
if block is not None:
report_error("line %d: nested block found" % (number))
else:
@@ -1202,6 +1520,9 @@ for line in file(input_filename, "rb").readlines():
if block[0][1].startswith("object"):
obj = parse_object(block)
objects_by_name[obj.name] = obj
+ elif block[0][1].startswith("managed object"):
+ obj = parse_object(block)
+ managed_objects_by_name[obj.name] = obj
elif block[0][1].startswith("enum"):
enum = parse_enum(block)
enums_by_name[enum.name] = enum
@@ -1268,6 +1589,30 @@ for obj in objects_by_name.values():
+for obj in managed_objects_by_name.values():
+ for property in obj.properties:
+ if property.occurrence != OCCURRENCE__IGNORED and \
+ not is_known_type(property.type):
+ report_error("object '%s' contains unknown property type '%s'" % (obj.name, property.type))
+
+ if obj.extends is not None:
+ if not is_known_type(obj.extends):
+ report_error("object '%s' extends unknown object '%s'" % (obj.name, obj.extends))
+
+ # detect extended_by relation
+ if obj.extends is not None:
+ extended_obj = managed_objects_by_name[obj.extends]
+
+ if extended_obj.extended_by is None:
+ extended_obj.extended_by = [obj.name]
+ else:
+ extended_obj.extended_by.append(obj.name)
+ extended_obj.extended_by.sort()
+
+
+
+
+
for obj in objects_by_name.values():
inherit_features(obj)
@@ -1283,6 +1628,8 @@ types_header.write("/* Generated by esx_vi_generator.py */\n\n\n\n")
types_source.write("/* Generated by esx_vi_generator.py */\n\n\n\n")
methods_header.write("/* Generated by esx_vi_generator.py */\n\n\n\n")
methods_source.write("/* Generated by esx_vi_generator.py */\n\n\n\n")
+helpers_header.write("/* Generated by esx_vi_generator.py */\n\n\n\n")
+helpers_source.write("/* Generated by esx_vi_generator.py */\n\n\n\n")
# output enums
@@ -1306,7 +1653,7 @@ for name in names:
# output objects
types_typedef.write("\n\n\n" +
"/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n" +
- " * VI Types\n" +
+ " * VI Objects\n" +
" */\n\n")
types_typeenum.write("\n")
types_typetostring.write("\n")
@@ -1327,6 +1674,30 @@ for name in names:
+# output managed objects
+types_typedef.write("\n\n\n" +
+ "/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n" +
+ " * VI Managed Objects\n" +
+ " */\n\n")
+types_typeenum.write("\n")
+types_typetostring.write("\n")
+types_typefromstring.write("\n")
+
+
+
+names = managed_objects_by_name.keys()
+names.sort()
+
+for name in names:
+ types_typedef.write(managed_objects_by_name[name].generate_typedef())
+ types_typeenum.write(managed_objects_by_name[name].generate_typeenum())
+ types_typetostring.write(managed_objects_by_name[name].generate_typetostring())
+ types_typefromstring.write(managed_objects_by_name[name].generate_typefromstring())
+ types_header.write(managed_objects_by_name[name].generate_header())
+ types_source.write(managed_objects_by_name[name].generate_source())
+
+
+
# output methods
names = methods_by_name.keys()
names.sort()
@@ -1334,3 +1705,13 @@ names.sort()
for name in names:
methods_header.write(methods_by_name[name].generate_header())
methods_source.write(methods_by_name[name].generate_source())
+
+
+
+# output helpers
+names = managed_objects_by_name.keys()
+names.sort()
+
+for name in names:
+ helpers_header.write(managed_objects_by_name[name].generate_helper_header())
+ helpers_source.write(managed_objects_by_name[name].generate_helper_source())
diff --git a/src/esx/esx_vi_types.c b/src/esx/esx_vi_types.c
index f3cdf2a..9e23030 100644
--- a/src/esx/esx_vi_types.c
+++ b/src/esx/esx_vi_types.c
@@ -3,7 +3,7 @@
* esx_vi_types.c: client for the VMware VI API 2.5 to manage ESX hosts
*
* Copyright (C) 2010 Red Hat, Inc.
- * Copyright (C) 2009-2010 Matthias Bolte <matthias.bolte(a)googlemail.com>
+ * Copyright (C) 2009-2011 Matthias Bolte <matthias.bolte(a)googlemail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -693,6 +693,44 @@ esxVI_GetActualObjectType(xmlNodePtr node, esxVI_Type baseType,
+/*
+ * Macros to implement managed objects
+ */
+
+#define ESX_VI__TEMPLATE__PROPERTY__MANAGED_REQUIRE(_name) \
+ /* FIXME: This results in O(n^2) runtime in case of missing required, but \
+ * unselected properties. */ \
+ if (item->_name == 0 && \
+ esxVI_String_ListContainsValue(selectedPropertyNameList, #_name)) { \
+ ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, \
+ _("%s object is missing the required '%s' property"), \
+ typeName, #_name); \
+ return -1; \
+ }
+
+
+
+#define ESX_VI__TEMPLATE__MANAGED_VALIDATE(__type, _require) \
+ int \
+ esxVI_##__type##_Validate(esxVI_##__type *item, \
+ esxVI_String *selectedPropertyNameList) \
+ { \
+ const char *typeName = esxVI_Type_ToString(esxVI_Type_##__type); \
+ \
+ if (item->_type <= esxVI_Type_Undefined || \
+ item->_type >= esxVI_Type_Other) { \
+ ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, \
+ _("%s object has invalid dynamic type"), typeName); \
+ return -1; \
+ } \
+ \
+ _require \
+ \
+ return 0; \
+ }
+
+
+
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* XSI: Type
*/
@@ -735,15 +773,6 @@ esxVI_Type_ToString(esxVI_Type type)
case esxVI_Type_ManagedObjectReference:
return "ManagedObjectReference";
- case esxVI_Type_Datacenter:
- return "Datacenter";
-
- case esxVI_Type_ComputeResource:
- return "ComputeResource";
-
- case esxVI_Type_HostSystem:
- return "HostSystem";
-
#include "esx_vi_types.generated.typetostring"
case esxVI_Type_Other:
@@ -776,12 +805,6 @@ esxVI_Type_FromString(const char *type)
return esxVI_Type_MethodFault;
} else if (STREQ(type, "ManagedObjectReference")) {
return esxVI_Type_ManagedObjectReference;
- } else if (STREQ(type, "Datacenter")) {
- return esxVI_Type_Datacenter;
- } else if (STREQ(type, "ComputeResource")) {
- return esxVI_Type_ComputeResource;
- } else if (STREQ(type, "HostSystem")) {
- return esxVI_Type_HostSystem;
}
#include "esx_vi_types.generated.typefromstring"
@@ -1050,6 +1073,20 @@ ESX_VI__TEMPLATE__VALIDATE(String,
ESX_VI__TEMPLATE__PROPERTY__REQUIRE(value)
})
+bool
+esxVI_String_ListContainsValue(esxVI_String *stringList, const char *value)
+{
+ esxVI_String *string;
+
+ for (string = stringList; string != NULL; string = string->_next) {
+ if (STREQ(string->value, value)) {
+ return true;
+ }
+ }
+
+ return false;
+}
+
/* esxVI_String_AppendToList */
ESX_VI__TEMPLATE__LIST__APPEND(String)
@@ -1452,7 +1489,7 @@ esxVI_DateTime_ConvertToCalendarTime(esxVI_DateTime *dateTime,
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- * VI Type: Fault
+ * SOAP: Fault
*/
/* esxVI_Fault_Alloc */
@@ -1483,7 +1520,7 @@ ESX_VI__TEMPLATE__DESERIALIZE(Fault,
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- * VI Type: MethodFault
+ * VI Object: MethodFault
*/
/* esxVI_MethodFault_Alloc */
@@ -1528,7 +1565,7 @@ esxVI_MethodFault_Deserialize(xmlNodePtr node, esxVI_MethodFault **methodFault)
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- * VI Type: ManagedObjectReference
+ * VI Object: ManagedObjectReference
*/
/* esxVI_ManagedObjectReference_Alloc */
@@ -1632,280 +1669,6 @@ esxVI_ManagedObjectReference_Deserialize
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- * VI Managed Object: Datacenter
- * extends ManagedEntity
- */
-
-/* esxVI_Datacenter_Alloc */
-ESX_VI__TEMPLATE__ALLOC(Datacenter)
-
-/* esxVI_Datacenter_Free */
-ESX_VI__TEMPLATE__FREE(Datacenter,
-{
- esxVI_Datacenter_Free(&item->_next);
- esxVI_ManagedObjectReference_Free(&item->_reference);
-
- /* ManagedEntity */
- VIR_FREE(item->name);
-
- /* Datacenter */
- esxVI_ManagedObjectReference_Free(&item->hostFolder);
- esxVI_ManagedObjectReference_Free(&item->vmFolder);
-})
-
-/* esxVI_Datacenter_Validate */
-ESX_VI__TEMPLATE__VALIDATE(Datacenter,
-{
- /* ManagedEntity */
- ESX_VI__TEMPLATE__PROPERTY__REQUIRE(name);
-
- /* Datacenter */
- ESX_VI__TEMPLATE__PROPERTY__REQUIRE(hostFolder);
- ESX_VI__TEMPLATE__PROPERTY__REQUIRE(vmFolder);
-})
-
-int
-esxVI_Datacenter_CastFromObjectContent(esxVI_ObjectContent *objectContent,
- esxVI_Datacenter **datacenter)
-{
- esxVI_DynamicProperty *dynamicProperty = NULL;
-
- if (objectContent == NULL || datacenter == NULL || *datacenter != NULL) {
- ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
- return -1;
- }
-
- if (esxVI_Datacenter_Alloc(datacenter) < 0) {
- return -1;
- }
-
- if (esxVI_ManagedObjectReference_DeepCopy(&(*datacenter)->_reference,
- objectContent->obj) < 0) {
- goto failure;
- }
-
- for (dynamicProperty = objectContent->propSet; dynamicProperty != NULL;
- dynamicProperty = dynamicProperty->_next) {
- if (STREQ(dynamicProperty->name, "name")) {
- if (esxVI_AnyType_ExpectType(dynamicProperty->val,
- esxVI_Type_String) < 0) {
- goto failure;
- }
-
- (*datacenter)->name = strdup(dynamicProperty->val->string);
-
- if ((*datacenter)->name == NULL) {
- virReportOOMError();
- goto failure;
- }
- } else if (STREQ(dynamicProperty->name, "hostFolder")) {
- if (esxVI_ManagedObjectReference_CastFromAnyType
- (dynamicProperty->val, &(*datacenter)->hostFolder) < 0) {
- goto failure;
- }
- } else if (STREQ(dynamicProperty->name, "vmFolder")) {
- if (esxVI_ManagedObjectReference_CastFromAnyType
- (dynamicProperty->val, &(*datacenter)->vmFolder) < 0) {
- goto failure;
- }
- }
- }
-
- if (esxVI_Datacenter_Validate(*datacenter) < 0) {
- goto failure;
- }
-
- return 0;
-
- failure:
- esxVI_Datacenter_Free(datacenter);
-
- return -1;
-}
-
-
-
-/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- * VI Managed Object: ComputeResource
- * extends ManagedEntity
- */
-
-/* esxVI_ComputeResource_Alloc */
-ESX_VI__TEMPLATE__ALLOC(ComputeResource)
-
-/* esxVI_ComputeResource_Free */
-ESX_VI__TEMPLATE__FREE(ComputeResource,
-{
- esxVI_ComputeResource_Free(&item->_next);
- esxVI_ManagedObjectReference_Free(&item->_reference);
-
- /* ManagedEntity */
- VIR_FREE(item->name);
-
- /* ComputeResource */
- esxVI_ManagedObjectReference_Free(&item->host);
- esxVI_ManagedObjectReference_Free(&item->resourcePool);
-})
-
-/* esxVI_ComputeResource_Validate */
-ESX_VI__TEMPLATE__VALIDATE(ComputeResource,
-{
- /* ManagedEntity */
- ESX_VI__TEMPLATE__PROPERTY__REQUIRE(name);
-
- /* ComputeResource */
-})
-
-int
-esxVI_ComputeResource_CastFromObjectContent
- (esxVI_ObjectContent *objectContent, esxVI_ComputeResource **computeResource)
-{
- esxVI_DynamicProperty *dynamicProperty = NULL;
-
- if (objectContent == NULL || computeResource == NULL ||
- *computeResource != NULL) {
- ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
- return -1;
- }
-
- if (esxVI_ComputeResource_Alloc(computeResource) < 0) {
- return -1;
- }
-
- if (esxVI_ManagedObjectReference_DeepCopy(&(*computeResource)->_reference,
- objectContent->obj) < 0) {
- goto failure;
- }
-
- for (dynamicProperty = objectContent->propSet; dynamicProperty != NULL;
- dynamicProperty = dynamicProperty->_next) {
- if (STREQ(dynamicProperty->name, "name")) {
- if (esxVI_AnyType_ExpectType(dynamicProperty->val,
- esxVI_Type_String) < 0) {
- goto failure;
- }
-
- (*computeResource)->name = strdup(dynamicProperty->val->string);
-
- if ((*computeResource)->name == NULL) {
- virReportOOMError();
- goto failure;
- }
- } else if (STREQ(dynamicProperty->name, "host")) {
- if (esxVI_ManagedObjectReference_CastListFromAnyType
- (dynamicProperty->val, &(*computeResource)->host) < 0) {
- goto failure;
- }
- } else if (STREQ(dynamicProperty->name, "resourcePool")) {
- if (esxVI_ManagedObjectReference_CastFromAnyType
- (dynamicProperty->val, &(*computeResource)->resourcePool) < 0) {
- goto failure;
- }
- }
- }
-
- if (esxVI_ComputeResource_Validate(*computeResource) < 0) {
- goto failure;
- }
-
- return 0;
-
- failure:
- esxVI_ComputeResource_Free(computeResource);
-
- return -1;
-}
-
-
-
-/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- * VI Managed Object: HostSystem
- * extends ManagedEntity
- */
-
-/* esxVI_HostSystem_Alloc */
-ESX_VI__TEMPLATE__ALLOC(HostSystem)
-
-/* esxVI_HostSystem_Free */
-ESX_VI__TEMPLATE__FREE(HostSystem,
-{
- esxVI_HostSystem_Free(&item->_next);
- esxVI_ManagedObjectReference_Free(&item->_reference);
-
- /* ManagedEntity */
- VIR_FREE(item->name);
-
- /* HostSystem */
- esxVI_HostConfigManager_Free(&item->configManager);
-})
-
-/* esxVI_HostSystem_Validate */
-ESX_VI__TEMPLATE__VALIDATE(HostSystem,
-{
- /* ManagedEntity */
- ESX_VI__TEMPLATE__PROPERTY__REQUIRE(name);
-
- /* HostSystem */
- ESX_VI__TEMPLATE__PROPERTY__REQUIRE(configManager);
-})
-
-int
-esxVI_HostSystem_CastFromObjectContent(esxVI_ObjectContent *objectContent,
- esxVI_HostSystem **hostSystem)
-{
- esxVI_DynamicProperty *dynamicProperty = NULL;
-
- if (objectContent == NULL || hostSystem == NULL || *hostSystem != NULL) {
- ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
- return -1;
- }
-
- if (esxVI_HostSystem_Alloc(hostSystem) < 0) {
- return -1;
- }
-
- if (esxVI_ManagedObjectReference_DeepCopy(&(*hostSystem)->_reference,
- objectContent->obj) < 0) {
- goto failure;
- }
-
- for (dynamicProperty = objectContent->propSet; dynamicProperty != NULL;
- dynamicProperty = dynamicProperty->_next) {
- if (STREQ(dynamicProperty->name, "name")) {
- if (esxVI_AnyType_ExpectType(dynamicProperty->val,
- esxVI_Type_String) < 0) {
- goto failure;
- }
-
- (*hostSystem)->name = strdup(dynamicProperty->val->string);
-
- if ((*hostSystem)->name == NULL) {
- virReportOOMError();
- goto failure;
- }
- } else if (STREQ(dynamicProperty->name, "configManager")) {
- if (esxVI_HostConfigManager_CastFromAnyType
- (dynamicProperty->val, &(*hostSystem)->configManager) < 0) {
- goto failure;
- }
- }
- }
-
- if (esxVI_HostSystem_Validate(*hostSystem) < 0) {
- goto failure;
- }
-
- return 0;
-
- failure:
- esxVI_HostSystem_Free(hostSystem);
-
- return -1;
-}
-
-
-
-/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* VI Enum: VirtualMachinePowerState (Additions)
*/
diff --git a/src/esx/esx_vi_types.h b/src/esx/esx_vi_types.h
index e53ccda..ac3741f 100644
--- a/src/esx/esx_vi_types.h
+++ b/src/esx/esx_vi_types.h
@@ -1,7 +1,8 @@
+
/*
* esx_vi_types.h: client for the VMware VI API 2.5 to manage ESX hosts
*
- * Copyright (C) 2009-2010 Matthias Bolte <matthias.bolte(a)googlemail.com>
+ * Copyright (C) 2009-2011 Matthias Bolte <matthias.bolte(a)googlemail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -44,15 +45,18 @@ typedef struct _esxVI_DateTime esxVI_DateTime;
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- * VI Types
+ * SOAP
*/
typedef struct _esxVI_Fault esxVI_Fault;
+
+
+
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * VI Objects
+ */
typedef struct _esxVI_MethodFault esxVI_MethodFault;
typedef struct _esxVI_ManagedObjectReference esxVI_ManagedObjectReference;
-typedef struct _esxVI_Datacenter esxVI_Datacenter;
-typedef struct _esxVI_ComputeResource esxVI_ComputeResource;
-typedef struct _esxVI_HostSystem esxVI_HostSystem;
# include "esx_vi_types.generated.typedef"
@@ -74,9 +78,6 @@ enum _esxVI_Type {
esxVI_Type_Fault,
esxVI_Type_MethodFault,
esxVI_Type_ManagedObjectReference,
- esxVI_Type_Datacenter,
- esxVI_Type_ComputeResource,
- esxVI_Type_HostSystem,
# include "esx_vi_types.generated.typeenum"
@@ -170,6 +171,7 @@ struct _esxVI_String {
int esxVI_String_Alloc(esxVI_String **string);
void esxVI_String_Free(esxVI_String **stringList);
int esxVI_String_Validate(esxVI_String *string);
+bool esxVI_String_ListContainsValue(esxVI_String *stringList, const char *value);
int esxVI_String_AppendToList(esxVI_String **stringList, esxVI_String *string);
int esxVI_String_AppendValueToList(esxVI_String **stringList,
const char *value);
@@ -264,7 +266,7 @@ int esxVI_DateTime_ConvertToCalendarTime(esxVI_DateTime *dateTime,
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- * VI Type: Fault
+ * SOAP: Fault
*/
struct _esxVI_Fault {
@@ -283,7 +285,7 @@ int esxVI_Fault_Deserialize(xmlNodePtr node, esxVI_Fault **fault);
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- * VI Type: MethodFault
+ * VI Object: MethodFault
*/
/*
@@ -306,7 +308,7 @@ int esxVI_MethodFault_Deserialize(xmlNodePtr node,
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- * VI Type: ManagedObjectReference
+ * VI Object: ManagedObjectReference
*/
struct _esxVI_ManagedObjectReference {
@@ -348,84 +350,6 @@ int esxVI_ManagedObjectReference_Deserialize
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- * VI Managed Object: Datacenter
- * extends ManagedEntity
- */
-
-struct _esxVI_Datacenter {
- esxVI_Datacenter *_next; /* optional */
- esxVI_Type _type; /* required */
- esxVI_ManagedObjectReference *_reference; /* required */
-
- /* ManagedEntity */
- char *name; /* required */
-
- /* Datacenter */
- esxVI_ManagedObjectReference *hostFolder; /* required */
- esxVI_ManagedObjectReference *vmFolder; /* required */
-};
-
-int esxVI_Datacenter_Alloc(esxVI_Datacenter **datacenter);
-void esxVI_Datacenter_Free(esxVI_Datacenter **datacenter);
-int esxVI_Datacenter_Validate(esxVI_Datacenter *datacenter);
-int esxVI_Datacenter_CastFromObjectContent(esxVI_ObjectContent *objectContent,
- esxVI_Datacenter **datacenter);
-
-
-
-/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- * VI Managed Object: ComputeResource
- * extends ManagedEntity
- */
-
-struct _esxVI_ComputeResource {
- esxVI_ComputeResource *_next; /* optional */
- esxVI_Type _type; /* required */
- esxVI_ManagedObjectReference *_reference; /* required */
-
- /* ManagedEntity */
- char *name; /* required */
-
- /* ComputeResource */
- esxVI_ManagedObjectReference *host; /* optional, list */
- esxVI_ManagedObjectReference *resourcePool; /* optional */
-};
-
-int esxVI_ComputeResource_Alloc(esxVI_ComputeResource **computeResource);
-void esxVI_ComputeResource_Free(esxVI_ComputeResource **computeResource);
-int esxVI_ComputeResource_Validate(esxVI_ComputeResource *computeResource);
-int esxVI_ComputeResource_CastFromObjectContent
- (esxVI_ObjectContent *objectContent,
- esxVI_ComputeResource **computeResource);
-
-
-
-/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- * VI Managed Object: HostSystem
- * extends ManagedEntity
- */
-
-struct _esxVI_HostSystem {
- esxVI_HostSystem *_next; /* optional */
- esxVI_Type _type; /* required */
- esxVI_ManagedObjectReference *_reference; /* required */
-
- /* ManagedEntity */
- char *name; /* required */
-
- /* HostSystem */
- esxVI_HostConfigManager *configManager; /* required */
-};
-
-int esxVI_HostSystem_Alloc(esxVI_HostSystem **hostSystem);
-void esxVI_HostSystem_Free(esxVI_HostSystem **hostSystem);
-int esxVI_HostSystem_Validate(esxVI_HostSystem *hostSystem);
-int esxVI_HostSystem_CastFromObjectContent(esxVI_ObjectContent *objectContent,
- esxVI_HostSystem **hostSystem);
-
-
-
-/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* VI Enum: VirtualMachinePowerState (Additions)
*/
--
1.7.0.4
13 years, 7 months
[libvirt] [PATCH] esx: Cleanup and refactor CastFromAnyType macros
by Matthias Bolte
Add CastFromAnyType functions for the String type.
---
src/esx/esx_vi_generator.py | 5 +--
src/esx/esx_vi_types.c | 64 +++++++++++++++++++++++++++++++-----------
src/esx/esx_vi_types.h | 2 +
3 files changed, 51 insertions(+), 20 deletions(-)
diff --git a/src/esx/esx_vi_generator.py b/src/esx/esx_vi_generator.py
index 622a34a..0fd84dd 100755
--- a/src/esx/esx_vi_generator.py
+++ b/src/esx/esx_vi_generator.py
@@ -773,12 +773,11 @@ class Object(Base):
# cast from any type
if self.features & Object.FEATURE__ANY_TYPE:
source += "/* esxVI_%s_CastFromAnyType */\n" % self.name
- source += "ESX_VI__TEMPLATE__CAST_FROM_ANY_TYPE(%s,\n" % self.name
if self.extended_by is None:
- source += "{\n"
- source += "})\n\n"
+ source += "ESX_VI__TEMPLATE__CAST_FROM_ANY_TYPE(%s)\n\n" % self.name
else:
+ source += "ESX_VI__TEMPLATE__DYNAMIC_CAST_FROM_ANY_TYPE(%s,\n" % self.name
source += "{\n"
for extended_by in self.extended_by:
diff --git a/src/esx/esx_vi_types.c b/src/esx/esx_vi_types.c
index f3df2b5..f3cdf2a 100644
--- a/src/esx/esx_vi_types.c
+++ b/src/esx/esx_vi_types.c
@@ -183,32 +183,53 @@
-#define ESX_VI__TEMPLATE__CAST_FROM_ANY_TYPE(_type, _dispatch) \
+#define ESX_VI__TEMPLATE__CAST_FROM_ANY_TYPE_EXTRA(_type, _dest_type, _extra, \
+ _dest_extra) \
int \
- esxVI_##_type##_CastFromAnyType(esxVI_AnyType *anyType, \
- esxVI_##_type **ptrptr) \
+ esxVI_##_type##_Cast##_dest_extra##FromAnyType(esxVI_AnyType *anyType, \
+ _dest_type **ptrptr) \
{ \
+ _dest_type *item; \
+ \
if (anyType == NULL || ptrptr == NULL || *ptrptr != NULL) { \
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", \
_("Invalid argument")); \
return -1; \
} \
\
- switch (anyType->type) { \
- _dispatch \
+ item = *ptrptr; \
\
- case esxVI_Type_##_type: \
- break; \
+ _extra \
\
- default: \
+ return esxVI_##_type##_Deserialize##_dest_extra(anyType->node, \
+ ptrptr); \
+ }
+
+
+
+#define ESX_VI__TEMPLATE__CAST_FROM_ANY_TYPE(_type) \
+ ESX_VI__TEMPLATE__CAST_FROM_ANY_TYPE_EXTRA(_type, esxVI_##_type, \
+ { \
+ if (anyType->type != esxVI_Type_##_type) { \
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, \
_("Call to %s for unexpected type '%s'"), \
__FUNCTION__, anyType->other); \
return -1; \
} \
- \
- return esxVI_##_type##_Deserialize(anyType->node, ptrptr); \
- }
+ }, /* nothing */)
+
+
+
+#define ESX_VI__TEMPLATE__CAST_VALUE_FROM_ANY_TYPE(_type, _value_type) \
+ ESX_VI__TEMPLATE__CAST_FROM_ANY_TYPE_EXTRA(_type, _value_type, \
+ { \
+ if (anyType->type != esxVI_Type_##_type) { \
+ ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, \
+ _("Call to %s for unexpected type '%s'"), \
+ __FUNCTION__, anyType->other); \
+ return -1; \
+ } \
+ }, Value)
@@ -591,6 +612,13 @@
+#define ESX_VI__TEMPLATE__DYNAMIC_CAST_FROM_ANY_TYPE(__type, _dispatch) \
+ ESX_VI__TEMPLATE__CAST_FROM_ANY_TYPE_EXTRA(__type, esxVI_##__type, \
+ ESX_VI__TEMPLATE__DISPATCH(__type, _dispatch, -1), \
+ /* nothing */)
+
+
+
#define ESX_VI__TEMPLATE__DYNAMIC_SERIALIZE(__type, _dispatch, _serialize) \
ESX_VI__TEMPLATE__SERIALIZE_EXTRA(__type, \
ESX_VI__TEMPLATE__DISPATCH(__type, _dispatch, -1), \
@@ -1111,6 +1139,12 @@ esxVI_String_DeepCopyValue(char **dest, const char *src)
return 0;
}
+/* esxVI_String_CastFromAnyType */
+ESX_VI__TEMPLATE__CAST_FROM_ANY_TYPE(String)
+
+/* esxVI_String_CastValueFromAnyType */
+ESX_VI__TEMPLATE__CAST_VALUE_FROM_ANY_TYPE(String, char)
+
int
esxVI_String_Serialize(esxVI_String *string, const char *element,
virBufferPtr output)
@@ -1240,9 +1274,7 @@ ESX_VI__TEMPLATE__VALIDATE(Long,
ESX_VI__TEMPLATE__LIST__APPEND(Long)
/* esxVI_Long_CastFromAnyType */
-ESX_VI__TEMPLATE__CAST_FROM_ANY_TYPE(Long,
-{
-})
+ESX_VI__TEMPLATE__CAST_FROM_ANY_TYPE(Long)
/* esxVI_Long_Serialize */
ESX_VI__TEMPLATE__SERIALIZE(Long,
@@ -1522,9 +1554,7 @@ ESX_VI__TEMPLATE__DEEP_COPY(ManagedObjectReference,
ESX_VI__TEMPLATE__LIST__APPEND(ManagedObjectReference)
/* esxVI_ManagedObjectReference_CastFromAnyType */
-ESX_VI__TEMPLATE__CAST_FROM_ANY_TYPE(ManagedObjectReference,
-{
-})
+ESX_VI__TEMPLATE__CAST_FROM_ANY_TYPE(ManagedObjectReference)
/* esxVI_ManagedObjectReference_CastListFromAnyType */
ESX_VI__TEMPLATE__LIST__CAST_FROM_ANY_TYPE(ManagedObjectReference)
diff --git a/src/esx/esx_vi_types.h b/src/esx/esx_vi_types.h
index 1ab39da..e53ccda 100644
--- a/src/esx/esx_vi_types.h
+++ b/src/esx/esx_vi_types.h
@@ -178,6 +178,8 @@ int esxVI_String_AppendValueListToList(esxVI_String **stringList,
int esxVI_String_DeepCopy(esxVI_String **dest, esxVI_String *src);
int esxVI_String_DeepCopyList(esxVI_String **destList, esxVI_String *srcList);
int esxVI_String_DeepCopyValue(char **dest, const char *src);
+int esxVI_String_CastFromAnyType(esxVI_AnyType *anyType, esxVI_String **string);
+int esxVI_String_CastValueFromAnyType(esxVI_AnyType *anyType, char **string);
int esxVI_String_Serialize(esxVI_String *string, const char *element,
virBufferPtr output);
int esxVI_String_SerializeList(esxVI_String *stringList, const char *element,
--
1.7.0.4
13 years, 7 months
[libvirt] [PATCH] esx: Cleanup VI generator code
by Matthias Bolte
---
src/esx/esx_vi_generator.py | 177 +++++++++++++++++--------------------------
1 files changed, 71 insertions(+), 106 deletions(-)
diff --git a/src/esx/esx_vi_generator.py b/src/esx/esx_vi_generator.py
index 3d068f3..622a34a 100755
--- a/src/esx/esx_vi_generator.py
+++ b/src/esx/esx_vi_generator.py
@@ -41,6 +41,11 @@ valid_occurrences = [OCCURRENCE__REQUIRED_ITEM,
+def aligned(left, right):
+ while len(left) < 59:
+ left += " "
+
+ return left + right
@@ -64,9 +69,6 @@ class Parameter:
def is_enum(self):
- global predefined_enums
- global enums_by_name
-
return self.type in predefined_enums or self.type in enums_by_name
@@ -88,10 +90,7 @@ class Parameter:
else:
string += ", "
- while len(string) < 59:
- string += " "
-
- return string + self.get_occurrence_comment() + "\n"
+ return aligned(string, self.get_occurrence_comment() + "\n")
def generate_return(self, offset = 0, end_of_line = ";"):
@@ -102,10 +101,7 @@ class Parameter:
string += " " * offset
string += "%s%s)%s" % (self.get_type_string(True), self.name, end_of_line)
- while len(string) < 59:
- string += " "
-
- return string + self.get_occurrence_comment() + "\n"
+ return aligned(string, self.get_occurrence_comment() + "\n")
def generate_require_code(self):
@@ -274,9 +270,6 @@ class Property:
def is_enum(self):
- global predefined_enums
- global enums_by_name
-
return self.type in predefined_enums or self.type in enums_by_name
@@ -286,10 +279,7 @@ class Property:
else:
string = " %s%s; " % (self.get_type_string(), self.name)
- while len(string) < 59:
- string += " "
-
- return string + self.get_occurrence_comment() + "\n"
+ return aligned(string, self.get_occurrence_comment() + "\n")
def generate_free_code(self):
@@ -380,7 +370,37 @@ class Property:
-class Object:
+class Base:
+ def __init__(self, kind, name):
+ self.kind = kind
+ self.name = name
+
+
+ def generate_typedef(self):
+ return "typedef %s _esxVI_%s esxVI_%s;\n" % (self.kind, self.name, self.name)
+
+
+ def generate_typeenum(self):
+ return " esxVI_Type_%s,\n" % self.name
+
+
+ def generate_typetostring(self):
+ string = " case esxVI_Type_%s:\n" % self.name
+ string += " return \"%s\";\n\n" % self.name
+
+ return string
+
+
+ def generate_typefromstring(self):
+ string = " else if (STREQ(type, \"%s\")) {\n" % self.name
+ string += " return esxVI_Type_%s;\n" % self.name
+ string += " }\n"
+
+ return string
+
+
+
+class Object(Base):
FEATURE__DYNAMIC_CAST = (1 << 1)
FEATURE__LIST = (1 << 2)
FEATURE__DEEP_COPY = (1 << 3)
@@ -390,34 +410,24 @@ class Object:
def __init__(self, name, extends, properties, features = 0, extended_by = None):
- self.name = name
+ Base.__init__(self, "struct", name)
self.extends = extends
self.features = features | Object.FEATURE__SERIALIZE | Object.FEATURE__DESERIALIZE
self.properties = properties
self.extended_by = extended_by
if self.extended_by is not None:
- self.extended_by.sort();
+ self.extended_by.sort()
- def generate_struct_members(self, add_banner = False, struct_gap = False):
- global objects_by_name
+ def generate_struct_members(self, add_banner=False, struct_gap=False):
members = ""
- if self.extends is None:
- struct_gap = True
- string = " esxVI_Type _type; "
-
- while len(string) < 59:
- string += " "
-
- members += string + "/* required */\n"
-
- if struct_gap and self.extends is None:
+ if struct_gap:
members += "\n"
if self.extends is not None:
- members += objects_by_name[self.extends].generate_struct_members(add_banner = True, struct_gap = False) + "\n"
+ members += objects_by_name[self.extends].generate_struct_members(add_banner=True, struct_gap=False) + "\n"
if self.extends is not None or add_banner:
members += " /* %s */\n" % self.name
@@ -431,12 +441,11 @@ class Object:
return members
- def generate_free_code(self, add_banner = False):
- global objects_by_name
+ def generate_free_code(self, add_banner=False):
source = ""
if self.extends is not None:
- source += objects_by_name[self.extends].generate_free_code(add_banner = True) + "\n"
+ source += objects_by_name[self.extends].generate_free_code(add_banner=True) + "\n"
if self.extends is not None or add_banner:
source += " /* %s */\n" % self.name
@@ -457,12 +466,11 @@ class Object:
return source
- def generate_validate_code(self, add_banner = False):
- global objects_by_name
+ def generate_validate_code(self, add_banner=False):
source = ""
if self.extends is not None:
- source += objects_by_name[self.extends].generate_validate_code(add_banner = True) + "\n"
+ source += objects_by_name[self.extends].generate_validate_code(add_banner=True) + "\n"
if self.extends is not None or add_banner:
source += " /* %s */\n" % self.name
@@ -484,7 +492,6 @@ class Object:
def generate_dynamic_cast_code(self, is_first = True):
- global objects_by_name
source = ""
if self.extended_by is not None:
@@ -503,7 +510,6 @@ class Object:
def generate_deep_copy_code(self, add_banner = False):
- global objects_by_name
source = ""
if self.extends is not None:
@@ -529,7 +535,6 @@ class Object:
def generate_serialize_code(self, add_banner = False):
- global objects_by_name
source = ""
if self.extends is not None:
@@ -548,11 +553,10 @@ class Object:
def generate_deserialize_code(self, add_banner = False):
- global objects_by_name
source = ""
if self.extends is not None:
- source += objects_by_name[self.extends].generate_deserialize_code(add_banner = True) + "\n"
+ source += objects_by_name[self.extends].generate_deserialize_code(add_banner=True) + "\n"
if self.extends is not None or add_banner:
source += " /* %s */\n" % self.name
@@ -566,29 +570,6 @@ class Object:
return source
- def generate_typedef(self):
- return "typedef struct _esxVI_%s esxVI_%s;\n" % (self.name, self.name)
-
-
- def generate_typeenum(self):
- return " esxVI_Type_%s,\n" % self.name
-
-
- def generate_typetostring(self):
- string = " case esxVI_Type_%s:\n" % self.name
- string += " return \"%s\";\n\n" % self.name
-
- return string
-
-
- def generate_typefromstring(self):
- string = " else if (STREQ(type, \"%s\")) {\n" % self.name
- string += " return esxVI_Type_%s;\n" % self.name
- string += " }\n"
-
- return string
-
-
def generate_header(self):
header = "/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n"
header += " * VI Type: %s\n" % self.name
@@ -612,17 +593,12 @@ class Object:
header += "struct _esxVI_%s {\n" % self.name
if self.features & Object.FEATURE__LIST:
- string = " esxVI_%s *_next; " % self.name
+ header += aligned(" esxVI_%s *_next; " % self.name, "/* optional */\n")
else:
- string = " esxVI_%s *_unused; " % self.name
-
- while len(string) < 59:
- string += " "
-
- header += string + "/* optional */\n"
-
- header += self.generate_struct_members(struct_gap = True)
+ header += aligned(" esxVI_%s *_unused; " % self.name, "/* optional */\n")
+ header += aligned(" esxVI_Type _type; ", "/* required */\n")
+ header += self.generate_struct_members(struct_gap=True)
header += "};\n\n"
# functions
@@ -888,39 +864,28 @@ class Object:
-class Enum:
- FEATURE__ANY_TYPE = (1 << 1)
- FEATURE__SERIALIZE = (1 << 2)
- FEATURE__DESERIALIZE = (1 << 3)
- def __init__(self, name, values, features = 0):
- self.name = name
- self.values = values
- self.features = features | Enum.FEATURE__SERIALIZE | Enum.FEATURE__DESERIALIZE
- def generate_typedef(self):
- return "typedef enum _esxVI_%s esxVI_%s;\n" % (self.name, self.name)
- def generate_typeenum(self):
- return " esxVI_Type_%s,\n" % self.name
- def generate_typetostring(self):
- string = " case esxVI_Type_%s:\n" % self.name
- string += " return \"%s\";\n\n" % self.name
- return string
- def generate_typefromstring(self):
- string = " else if (STREQ(type, \"%s\")) {\n" % self.name
- string += " return esxVI_Type_%s;\n" % self.name
- string += " }\n"
- return string
+class Enum(Base):
+ FEATURE__ANY_TYPE = (1 << 1)
+ FEATURE__SERIALIZE = (1 << 2)
+ FEATURE__DESERIALIZE = (1 << 3)
+
+
+ def __init__(self, name, values, features=0):
+ Base.__init__(self, "enum", name)
+ self.values = values
+ self.features = features | Enum.FEATURE__SERIALIZE | Enum.FEATURE__DESERIALIZE
def generate_header(self):
@@ -1027,8 +992,8 @@ def parse_object(block):
if items[2] not in valid_occurrences:
report_error("line %d: invalid occurrence" % line[0])
- properties.append(Property(type = items[0], name = items[1],
- occurrence = items[2]))
+ properties.append(Property(type=items[0], name=items[1],
+ occurrence=items[2]))
return Object(name = name, extends = extends, properties = properties)
@@ -1051,7 +1016,7 @@ def parse_enum(block):
# expected format: <value>
values.append(line[1])
- return Enum(name = name, values = values)
+ return Enum(name=name, values=values)
@@ -1071,8 +1036,8 @@ def parse_method(block):
if header_items[2] != "returns":
report_error("line %d: invalid block header" % (number))
else:
- returns = Parameter(type = header_items[3], name = "output",
- occurrence = header_items[4])
+ returns = Parameter(type=header_items[3], name="output",
+ occurrence=header_items[4])
parameters = []
@@ -1086,10 +1051,10 @@ def parse_method(block):
if items[2] not in valid_occurrences:
report_error("line %d: invalid occurrence" % line[0])
- parameters.append(Parameter(type = items[0], name = items[1],
- occurrence = items[2]))
+ parameters.append(Parameter(type=items[0], name=items[1],
+ occurrence=items[2]))
- return Method(name = name, parameters = parameters, returns = returns)
+ return Method(name=name, parameters=parameters, returns=returns)
--
1.7.0.4
13 years, 7 months
[libvirt] [PATCH] Fix possible NULL dereference in driver
by Michal Privoznik
If brSetForwardDelay() fails, we go to err1 where we want to access
macTapIfName variable which was just VIR_FREE'd a few lines above.
---
src/network/bridge_driver.c | 5 +++--
1 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index ea2bfd4..97d8ce0 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -1616,7 +1616,7 @@ networkStartNetworkDaemon(struct network_driver *driver,
bool v4present = false, v6present = false;
virErrorPtr save_err = NULL;
virNetworkIpDefPtr ipdef;
- char *macTapIfName;
+ char *macTapIfName = NULL;
if (virNetworkObjIsActive(network)) {
networkReportError(VIR_ERR_OPERATION_INVALID,
@@ -1657,7 +1657,6 @@ networkStartNetworkDaemon(struct network_driver *driver,
VIR_FREE(macTapIfName);
goto err0;
}
- VIR_FREE(macTapIfName);
}
/* Set bridge options */
@@ -1731,6 +1730,7 @@ networkStartNetworkDaemon(struct network_driver *driver,
goto err5;
}
+ VIR_FREE(macTapIfName);
VIR_INFO(_("Starting up network '%s'"), network->def->name);
network->active = 1;
@@ -1778,6 +1778,7 @@ networkStartNetworkDaemon(struct network_driver *driver,
macTapIfName, network->def->bridge,
virStrerror(err, ebuf, sizeof ebuf));
}
+ VIR_FREE(macTapIfName);
err0:
if (!save_err)
--
1.7.4.2
13 years, 7 months
[libvirt] [PATCH] docs: Serial and parallel device target ports actually start from 0
by Matthias Bolte
Reported by Igor Galić
---
docs/formatdomain.html.in | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index 574fee5..ea021e8 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -1807,7 +1807,7 @@ qemu-kvm -net nic,model=? /dev/null
<p>
<code>target</code> can have a <code>port</code> attribute, which
- specifies the port number. Ports are numbered starting from 1. There are
+ specifies the port number. Ports are numbered starting from 0. There are
usually 0, 1 or 2 parallel ports.
</p>
@@ -1825,7 +1825,7 @@ qemu-kvm -net nic,model=? /dev/null
<p>
<code>target</code> can have a <code>port</code> attribute, which
- specifies the port number. Ports are numbered starting from 1. There are
+ specifies the port number. Ports are numbered starting from 0. There are
usually 0, 1 or 2 serial ports.
</p>
--
1.7.0.4
13 years, 7 months
[libvirt] virsh shutdown
by Zvi Dubitzky
Hi
For some reason recent libvirt code (0.8.3 and even before) the 'virsh
shutdown <domain> ' is not effective .
It issues an ok message by the domians remains in a runnning state . Only
th e destroy works fine.
Any idea ?
Zvi Dubitzky
Email:dubi@il.ibm.com
13 years, 7 months
[libvirt] [PATCH] Fix possible NULL dereference in driver
by Michal Privoznik
If brSetForwardDelay() fails, we go to err1 where we want to access
macTapIfName variable which was just VIR_FREE'd a few lines above.
---
src/network/bridge_driver.c | 5 +++--
1 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index ea2bfd4..abde150 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -1616,7 +1616,7 @@ networkStartNetworkDaemon(struct network_driver *driver,
bool v4present = false, v6present = false;
virErrorPtr save_err = NULL;
virNetworkIpDefPtr ipdef;
- char *macTapIfName;
+ char *macTapIfName = NULL;
if (virNetworkObjIsActive(network)) {
networkReportError(VIR_ERR_OPERATION_INVALID,
@@ -1657,7 +1657,6 @@ networkStartNetworkDaemon(struct network_driver *driver,
VIR_FREE(macTapIfName);
goto err0;
}
- VIR_FREE(macTapIfName);
}
/* Set bridge options */
@@ -1687,6 +1686,8 @@ networkStartNetworkDaemon(struct network_driver *driver,
if (networkAddIptablesRules(driver, network) < 0)
goto err1;
+ VIR_FREE(macTapIfName);
+
for (ii = 0;
(ipdef = virNetworkDefGetIpByIndex(network->def, AF_UNSPEC, ii));
ii++) {
--
1.7.4.2
13 years, 7 months
[libvirt] [PATCH] Fix checking of return codes in dispatcher
by Daniel P. Berrange
The libvirt APIs reserve any negative value for indicating an
error. Thus checks
if (virXXXX() == -1)
Should instead be
if (virXXXX() < 0)
* daemon/remote.c: s/ == -1/ < 0/
---
daemon/remote.c | 339 +++++++++++++++++++++++++++++--------------------------
1 files changed, 180 insertions(+), 159 deletions(-)
diff --git a/daemon/remote.c b/daemon/remote.c
index 8f4d6a6..325ba90 100644
--- a/daemon/remote.c
+++ b/daemon/remote.c
@@ -476,7 +476,7 @@ remoteDispatchSupportsFeature(struct qemud_server *server ATTRIBUTE_UNUSED,
ret->supported = virDrvSupportsFeature(conn, args->feature);
- if (ret->supported == -1) {
+ if (ret->supported < 0) {
goto cleanup;
}
@@ -543,7 +543,7 @@ remoteDispatchGetVersion(struct qemud_server *server ATTRIBUTE_UNUSED,
goto cleanup;
}
- if (virConnectGetVersion(conn, &hvVer) == -1) {
+ if (virConnectGetVersion(conn, &hvVer) < 0) {
goto cleanup;
}
@@ -573,7 +573,7 @@ remoteDispatchGetLibVersion(struct qemud_server *server ATTRIBUTE_UNUSED,
goto cleanup;
}
- if (virConnectGetLibVersion(conn, &libVer) == -1) {
+ if (virConnectGetLibVersion(conn, &libVer) < 0) {
goto cleanup;
}
@@ -700,7 +700,7 @@ remoteDispatchGetMaxVcpus(struct qemud_server *server ATTRIBUTE_UNUSED,
type = args->type ? *args->type : NULL;
ret->max_vcpus = virConnectGetMaxVcpus(conn, type);
- if (ret->max_vcpus == -1) {
+ if (ret->max_vcpus < 0) {
goto cleanup;
}
@@ -729,7 +729,7 @@ remoteDispatchNodeGetInfo(struct qemud_server *server ATTRIBUTE_UNUSED,
goto cleanup;
}
- if (virNodeGetInfo(conn, &info) == -1) {
+ if (virNodeGetInfo(conn, &info) < 0) {
goto cleanup;
}
@@ -938,7 +938,7 @@ remoteDispatchDomainGetSchedulerParameters(struct qemud_server *server ATTRIBUTE
}
r = virDomainGetSchedulerParameters(dom, params, &nparams);
- if (r == -1) {
+ if (r < 0) {
goto cleanup;
}
@@ -1051,7 +1051,7 @@ remoteDispatchDomainSetSchedulerParameters(struct qemud_server *server ATTRIBUTE
}
r = virDomainSetSchedulerParameters(dom, params, nparams);
- if (r == -1) {
+ if (r < 0) {
goto cleanup;
}
@@ -1091,7 +1091,7 @@ remoteDispatchDomainBlockStats(struct qemud_server *server ATTRIBUTE_UNUSED,
}
path = args->path;
- if (virDomainBlockStats(dom, path, &stats, sizeof stats) == -1) {
+ if (virDomainBlockStats(dom, path, &stats, sizeof stats) < 0) {
goto cleanup;
}
@@ -1136,7 +1136,7 @@ remoteDispatchDomainInterfaceStats(struct qemud_server *server ATTRIBUTE_UNUSED,
}
path = args->path;
- if (virDomainInterfaceStats(dom, path, &stats, sizeof stats) == -1) {
+ if (virDomainInterfaceStats(dom, path, &stats, sizeof stats) < 0) {
goto cleanup;
}
@@ -1170,7 +1170,7 @@ remoteDispatchDomainMemoryStats(struct qemud_server *server ATTRIBUTE_UNUSED,
{
virDomainPtr dom = NULL;
struct _virDomainMemoryStat *stats;
- unsigned int nr_stats, i;
+ int nr_stats, i;
int rv = -1;
if (!conn) {
@@ -1196,7 +1196,7 @@ remoteDispatchDomainMemoryStats(struct qemud_server *server ATTRIBUTE_UNUSED,
}
nr_stats = virDomainMemoryStats(dom, stats, args->maxStats, 0);
- if (nr_stats == -1) {
+ if (nr_stats < 0) {
goto cleanup;
}
@@ -1266,7 +1266,7 @@ remoteDispatchDomainBlockPeek(struct qemud_server *server ATTRIBUTE_UNUSED,
}
if (virDomainBlockPeek(dom, path, offset, size,
- ret->buffer.buffer_val, flags) == -1) {
+ ret->buffer.buffer_val, flags) < 0) {
goto cleanup;
}
@@ -1323,7 +1323,7 @@ remoteDispatchDomainMemoryPeek(struct qemud_server *server ATTRIBUTE_UNUSED,
}
if (virDomainMemoryPeek(dom, offset, size,
- ret->buffer.buffer_val, flags) == -1) {
+ ret->buffer.buffer_val, flags) < 0) {
goto cleanup;
}
if (dom)
@@ -1363,7 +1363,7 @@ remoteDispatchDomainAttachDevice(struct qemud_server *server ATTRIBUTE_UNUSED,
goto cleanup;
}
- if (virDomainAttachDevice(dom, args->xml) == -1) {
+ if (virDomainAttachDevice(dom, args->xml) < 0) {
goto cleanup;
}
@@ -1399,7 +1399,7 @@ remoteDispatchDomainAttachDeviceFlags(struct qemud_server *server ATTRIBUTE_UNUS
goto cleanup;
}
- if (virDomainAttachDeviceFlags(dom, args->xml, args->flags) == -1) {
+ if (virDomainAttachDeviceFlags(dom, args->xml, args->flags) < 0) {
goto cleanup;
}
@@ -1435,7 +1435,7 @@ remoteDispatchDomainUpdateDeviceFlags(struct qemud_server *server ATTRIBUTE_UNUS
goto cleanup;
}
- if (virDomainUpdateDeviceFlags(dom, args->xml, args->flags) == -1) {
+ if (virDomainUpdateDeviceFlags(dom, args->xml, args->flags) < 0) {
goto cleanup;
}
@@ -1471,7 +1471,7 @@ remoteDispatchDomainCreate(struct qemud_server *server ATTRIBUTE_UNUSED,
goto cleanup;
}
- if (virDomainCreate(dom) == -1) {
+ if (virDomainCreate(dom) < 0) {
goto cleanup;
}
@@ -1502,7 +1502,7 @@ remoteDispatchDomainCreateWithFlags(struct qemud_server *server ATTRIBUTE_UNUSED
goto cleanup;
}
- if (virDomainCreateWithFlags(dom, args->flags) == -1) {
+ if (virDomainCreateWithFlags(dom, args->flags) < 0) {
goto cleanup;
}
@@ -1608,7 +1608,7 @@ remoteDispatchDomainDestroy(struct qemud_server *server ATTRIBUTE_UNUSED,
goto cleanup;
}
- if (virDomainDestroy(dom) == -1) {
+ if (virDomainDestroy(dom) < 0) {
goto cleanup;
}
@@ -1644,7 +1644,7 @@ remoteDispatchDomainDetachDevice(struct qemud_server *server ATTRIBUTE_UNUSED,
goto cleanup;
}
- if (virDomainDetachDevice(dom, args->xml) == -1) {
+ if (virDomainDetachDevice(dom, args->xml) < 0) {
goto cleanup;
}
@@ -1680,7 +1680,7 @@ remoteDispatchDomainDetachDeviceFlags(struct qemud_server *server ATTRIBUTE_UNUS
goto cleanup;
}
- if (virDomainDetachDeviceFlags(dom, args->xml, args->flags) == -1) {
+ if (virDomainDetachDeviceFlags(dom, args->xml, args->flags) < 0) {
goto cleanup;
}
@@ -1819,7 +1819,7 @@ remoteDispatchDomainGetAutostart(struct qemud_server *server ATTRIBUTE_UNUSED,
goto cleanup;
}
- if (virDomainGetAutostart(dom, &ret->autostart) == -1) {
+ if (virDomainGetAutostart(dom, &ret->autostart) < 0) {
goto cleanup;
}
@@ -1856,7 +1856,7 @@ remoteDispatchDomainGetInfo(struct qemud_server *server ATTRIBUTE_UNUSED,
goto cleanup;
}
- if (virDomainGetInfo(dom, &info) == -1) {
+ if (virDomainGetInfo(dom, &info) < 0) {
goto cleanup;
}
@@ -1936,7 +1936,7 @@ remoteDispatchDomainGetMaxVcpus(struct qemud_server *server ATTRIBUTE_UNUSED,
}
ret->num = virDomainGetMaxVcpus(dom);
- if (ret->num == -1) {
+ if (ret->num < 0) {
goto cleanup;
}
@@ -1978,7 +1978,7 @@ remoteDispatchDomainGetSecurityLabel(struct qemud_server *server ATTRIBUTE_UNUSE
goto cleanup;
}
- if (virDomainGetSecurityLabel(dom, seclabel) == -1) {
+ if (virDomainGetSecurityLabel(dom, seclabel) < 0) {
goto cleanup;
}
@@ -2019,7 +2019,7 @@ remoteDispatchNodeGetSecurityModel(struct qemud_server *server ATTRIBUTE_UNUSED,
}
memset(&secmodel, 0, sizeof secmodel);
- if (virNodeGetSecurityModel(conn, &secmodel) == -1) {
+ if (virNodeGetSecurityModel(conn, &secmodel) < 0) {
goto cleanup;
}
@@ -2127,7 +2127,7 @@ remoteDispatchDomainGetVcpus(struct qemud_server *server ATTRIBUTE_UNUSED,
info_len = virDomainGetVcpus(dom,
info, args->maxinfo,
cpumaps, args->maplen);
- if (info_len == -1) {
+ if (info_len < 0) {
goto cleanup;
}
@@ -2192,7 +2192,7 @@ remoteDispatchDomainGetVcpusFlags(struct qemud_server *server ATTRIBUTE_UNUSED,
}
ret->num = virDomainGetVcpusFlags(dom, args->flags);
- if (ret->num == -1) {
+ if (ret->num < 0) {
goto cleanup;
}
@@ -2240,7 +2240,7 @@ remoteDispatchDomainMigratePrepare(struct qemud_server *server ATTRIBUTE_UNUSED,
r = virDomainMigratePrepare(conn, &cookie, &cookielen,
uri_in, uri_out,
args->flags, dname, args->resource);
- if (r == -1) {
+ if (r < 0) {
goto cleanup;
}
@@ -2296,7 +2296,7 @@ remoteDispatchDomainMigratePerform(struct qemud_server *server ATTRIBUTE_UNUSED,
args->cookie.cookie_len,
args->uri,
args->flags, dname, args->resource);
- if (r == -1) {
+ if (r < 0) {
goto cleanup;
}
@@ -2382,7 +2382,7 @@ remoteDispatchDomainMigratePrepare2(struct qemud_server *server ATTRIBUTE_UNUSED
uri_in, uri_out,
args->flags, dname, args->resource,
args->dom_xml);
- if (r == -1) {
+ if (r < 0) {
goto cleanup;
}
@@ -2470,7 +2470,7 @@ remoteDispatchDomainMigratePrepareTunnel(struct qemud_server *server ATTRIBUTE_U
r = virDomainMigratePrepareTunnel(conn, stream->st,
args->flags, dname, args->resource,
args->dom_xml);
- if (r == -1) {
+ if (r < 0) {
goto cleanup;
}
@@ -2501,6 +2501,7 @@ remoteDispatchListDefinedDomains(struct qemud_server *server ATTRIBUTE_UNUSED,
remote_list_defined_domains_ret *ret)
{
int rv = -1;
+ int len;
if (!conn) {
virNetError(VIR_ERR_INTERNAL_ERROR, "%s", _("connection not open"));
@@ -2519,12 +2520,12 @@ remoteDispatchListDefinedDomains(struct qemud_server *server ATTRIBUTE_UNUSED,
goto cleanup;
}
- ret->names.names_len =
- virConnectListDefinedDomains(conn,
- ret->names.names_val, args->maxnames);
- if (ret->names.names_len == -1) {
+ len = virConnectListDefinedDomains(conn,
+ ret->names.names_val, args->maxnames);
+ if (len < 0) {
goto cleanup;
}
+ ret->names.names_len = len;
rv = 0;
@@ -2655,7 +2656,7 @@ remoteDispatchNumOfDefinedDomains(struct qemud_server *server ATTRIBUTE_UNUSED,
}
ret->num = virConnectNumOfDefinedDomains(conn);
- if (ret->num == -1) {
+ if (ret->num < 0) {
goto cleanup;
}
@@ -2697,7 +2698,7 @@ remoteDispatchDomainPinVcpu(struct qemud_server *server ATTRIBUTE_UNUSED,
rv = virDomainPinVcpu(dom, args->vcpu,
(unsigned char *) args->cpumap.cpumap_val,
args->cpumap.cpumap_len);
- if (rv == -1) {
+ if (rv < 0) {
goto cleanup;
}
@@ -2733,7 +2734,7 @@ remoteDispatchDomainReboot(struct qemud_server *server ATTRIBUTE_UNUSED,
goto cleanup;
}
- if (virDomainReboot(dom, args->flags) == -1) {
+ if (virDomainReboot(dom, args->flags) < 0) {
goto cleanup;
}
@@ -2763,7 +2764,7 @@ remoteDispatchDomainRestore(struct qemud_server *server ATTRIBUTE_UNUSED,
goto cleanup;
}
- if (virDomainRestore(conn, args->from) == -1) {
+ if (virDomainRestore(conn, args->from) < 0) {
goto cleanup;
}
@@ -2797,7 +2798,7 @@ remoteDispatchDomainResume(struct qemud_server *server ATTRIBUTE_UNUSED,
goto cleanup;
}
- if (virDomainResume(dom) == -1) {
+ if (virDomainResume(dom) < 0) {
goto cleanup;
}
@@ -2833,7 +2834,7 @@ remoteDispatchDomainSave(struct qemud_server *server ATTRIBUTE_UNUSED,
goto cleanup;
}
- if (virDomainSave(dom, args->to) == -1) {
+ if (virDomainSave(dom, args->to) < 0) {
goto cleanup;
}
@@ -2869,7 +2870,7 @@ remoteDispatchDomainCoreDump(struct qemud_server *server ATTRIBUTE_UNUSED,
goto cleanup;
}
- if (virDomainCoreDump(dom, args->to, args->flags) == -1) {
+ if (virDomainCoreDump(dom, args->to, args->flags) < 0) {
goto cleanup;
}
@@ -2905,7 +2906,7 @@ remoteDispatchDomainSetAutostart(struct qemud_server *server ATTRIBUTE_UNUSED,
goto cleanup;
}
- if (virDomainSetAutostart(dom, args->autostart) == -1) {
+ if (virDomainSetAutostart(dom, args->autostart) < 0) {
goto cleanup;
}
@@ -2941,7 +2942,7 @@ remoteDispatchDomainSetMaxMemory(struct qemud_server *server ATTRIBUTE_UNUSED,
goto cleanup;
}
- if (virDomainSetMaxMemory(dom, args->memory) == -1) {
+ if (virDomainSetMaxMemory(dom, args->memory) < 0) {
goto cleanup;
}
@@ -2977,7 +2978,7 @@ remoteDispatchDomainSetMemory(struct qemud_server *server ATTRIBUTE_UNUSED,
goto cleanup;
}
- if (virDomainSetMemory(dom, args->memory) == -1) {
+ if (virDomainSetMemory(dom, args->memory) < 0) {
goto cleanup;
}
@@ -3013,7 +3014,7 @@ remoteDispatchDomainSetMemoryFlags(struct qemud_server *server ATTRIBUTE_UNUSED,
goto cleanup;
}
- if (virDomainSetMemoryFlags(dom, args->memory, args->flags) == -1) {
+ if (virDomainSetMemoryFlags(dom, args->memory, args->flags) < 0) {
goto cleanup;
}
@@ -3112,7 +3113,7 @@ remoteDispatchDomainSetMemoryParameters(struct qemud_server *server
}
r = virDomainSetMemoryParameters(dom, params, nparams, flags);
- if (r == -1) {
+ if (r < 0) {
goto cleanup;
}
@@ -3170,7 +3171,7 @@ remoteDispatchDomainGetMemoryParameters(struct qemud_server *server
}
r = virDomainGetMemoryParameters(dom, params, &nparams, flags);
- if (r == -1) {
+ if (r < 0) {
goto cleanup;
}
/* In this case, we need to send back the number of parameters
@@ -3333,7 +3334,7 @@ remoteDispatchDomainSetBlkioParameters(struct qemud_server *server
}
r = virDomainSetBlkioParameters(dom, params, nparams, flags);
- if (r == -1) {
+ if (r < 0) {
goto cleanup;
}
@@ -3391,7 +3392,7 @@ remoteDispatchDomainGetBlkioParameters(struct qemud_server *server
}
r = virDomainGetBlkioParameters(dom, params, &nparams, flags);
- if (r == -1) {
+ if (r < 0) {
goto cleanup;
}
/* In this case, we need to send back the number of parameters
@@ -3493,7 +3494,7 @@ remoteDispatchDomainSetVcpus(struct qemud_server *server ATTRIBUTE_UNUSED,
goto cleanup;
}
- if (virDomainSetVcpus(dom, args->nvcpus) == -1) {
+ if (virDomainSetVcpus(dom, args->nvcpus) < 0) {
goto cleanup;
}
@@ -3529,7 +3530,7 @@ remoteDispatchDomainSetVcpusFlags(struct qemud_server *server ATTRIBUTE_UNUSED,
goto cleanup;
}
- if (virDomainSetVcpusFlags(dom, args->nvcpus, args->flags) == -1) {
+ if (virDomainSetVcpusFlags(dom, args->nvcpus, args->flags) < 0) {
goto cleanup;
}
@@ -3565,7 +3566,7 @@ remoteDispatchDomainShutdown(struct qemud_server *server ATTRIBUTE_UNUSED,
goto cleanup;
}
- if (virDomainShutdown(dom) == -1) {
+ if (virDomainShutdown(dom) < 0) {
goto cleanup;
}
@@ -3601,7 +3602,7 @@ remoteDispatchDomainSuspend(struct qemud_server *server ATTRIBUTE_UNUSED,
goto cleanup;
}
- if (virDomainSuspend(dom) == -1) {
+ if (virDomainSuspend(dom) < 0) {
goto cleanup;
}
@@ -3637,7 +3638,7 @@ remoteDispatchDomainUndefine(struct qemud_server *server ATTRIBUTE_UNUSED,
goto cleanup;
}
- if (virDomainUndefine(dom) == -1) {
+ if (virDomainUndefine(dom) < 0) {
goto cleanup;
}
@@ -3661,6 +3662,7 @@ remoteDispatchListDefinedNetworks(struct qemud_server *server ATTRIBUTE_UNUSED,
remote_list_defined_networks_ret *ret)
{
int rv = -1;
+ int len;
if (!conn) {
virNetError(VIR_ERR_INTERNAL_ERROR, "%s", _("connection not open"));
@@ -3679,12 +3681,12 @@ remoteDispatchListDefinedNetworks(struct qemud_server *server ATTRIBUTE_UNUSED,
goto cleanup;
}
- ret->names.names_len =
- virConnectListDefinedNetworks(conn,
+ len = virConnectListDefinedNetworks(conn,
ret->names.names_val, args->maxnames);
- if (ret->names.names_len == -1) {
+ if (len < 0) {
goto cleanup;
}
+ ret->names.names_len = len;
rv = 0;
@@ -3706,6 +3708,7 @@ remoteDispatchListDomains(struct qemud_server *server ATTRIBUTE_UNUSED,
remote_list_domains_ret *ret)
{
int rv = -1;
+ int len;
if (!conn) {
virNetError(VIR_ERR_INTERNAL_ERROR, "%s", _("connection not open"));
@@ -3724,11 +3727,12 @@ remoteDispatchListDomains(struct qemud_server *server ATTRIBUTE_UNUSED,
goto cleanup;
}
- ret->ids.ids_len = virConnectListDomains(conn,
- ret->ids.ids_val, args->maxids);
- if (ret->ids.ids_len == -1) {
+ len = virConnectListDomains(conn,
+ ret->ids.ids_val, args->maxids);
+ if (len < 0) {
goto cleanup;
}
+ ret->ids.ids_len = len;
rv = 0;
@@ -3762,7 +3766,7 @@ remoteDispatchDomainManagedSave(struct qemud_server *server ATTRIBUTE_UNUSED,
goto cleanup;
}
- if (virDomainManagedSave(dom, args->flags) == -1) {
+ if (virDomainManagedSave(dom, args->flags) < 0) {
goto cleanup;
}
@@ -3799,7 +3803,7 @@ remoteDispatchDomainHasManagedSaveImage(struct qemud_server *server ATTRIBUTE_UN
}
ret->ret = virDomainHasManagedSaveImage(dom, args->flags);
- if (ret->ret == -1) {
+ if (ret->ret < 0) {
goto cleanup;
}
@@ -3835,7 +3839,7 @@ remoteDispatchDomainManagedSaveRemove(struct qemud_server *server ATTRIBUTE_UNUS
goto cleanup;
}
- if (virDomainManagedSaveRemove(dom, args->flags) == -1) {
+ if (virDomainManagedSaveRemove(dom, args->flags) < 0) {
goto cleanup;
}
@@ -3859,6 +3863,7 @@ remoteDispatchListNetworks(struct qemud_server *server ATTRIBUTE_UNUSED,
remote_list_networks_ret *ret)
{
int rv = -1;
+ int len;
if (!conn) {
virNetError(VIR_ERR_INTERNAL_ERROR, "%s", _("connection not open"));
@@ -3877,12 +3882,12 @@ remoteDispatchListNetworks(struct qemud_server *server ATTRIBUTE_UNUSED,
goto cleanup;
}
- ret->names.names_len =
- virConnectListNetworks(conn,
- ret->names.names_val, args->maxnames);
- if (ret->names.names_len == -1) {
+ len = virConnectListNetworks(conn,
+ ret->names.names_val, args->maxnames);
+ if (len < 0) {
goto cleanup;
}
+ ret->names.names_len = len;
rv = 0;
@@ -3916,7 +3921,7 @@ remoteDispatchNetworkCreate(struct qemud_server *server ATTRIBUTE_UNUSED,
goto cleanup;
}
- if (virNetworkCreate(net) == -1) {
+ if (virNetworkCreate(net) < 0) {
goto cleanup;
}
@@ -4020,7 +4025,7 @@ remoteDispatchNetworkDestroy(struct qemud_server *server ATTRIBUTE_UNUSED,
goto cleanup;
}
- if (virNetworkDestroy(net) == -1) {
+ if (virNetworkDestroy(net) < 0) {
goto cleanup;
}
@@ -4094,7 +4099,7 @@ remoteDispatchNetworkGetAutostart(struct qemud_server *server ATTRIBUTE_UNUSED,
goto cleanup;
}
- if (virNetworkGetAutostart(net, &ret->autostart) == -1) {
+ if (virNetworkGetAutostart(net, &ret->autostart) < 0) {
goto cleanup;
}
@@ -4236,7 +4241,7 @@ remoteDispatchNetworkSetAutostart(struct qemud_server *server ATTRIBUTE_UNUSED,
goto cleanup;
}
- if (virNetworkSetAutostart(net, args->autostart) == -1) {
+ if (virNetworkSetAutostart(net, args->autostart) < 0) {
goto cleanup;
}
@@ -4272,7 +4277,7 @@ remoteDispatchNetworkUndefine(struct qemud_server *server ATTRIBUTE_UNUSED,
goto cleanup;
}
- if (virNetworkUndefine(net) == -1) {
+ if (virNetworkUndefine(net) < 0) {
goto cleanup;
}
@@ -4296,16 +4301,18 @@ remoteDispatchNumOfDefinedNetworks(struct qemud_server *server ATTRIBUTE_UNUSED,
remote_num_of_defined_networks_ret *ret)
{
int rv = -1;
+ int len;
if (!conn) {
virNetError(VIR_ERR_INTERNAL_ERROR, "%s", _("connection not open"));
goto cleanup;
}
- ret->num = virConnectNumOfDefinedNetworks(conn);
- if (ret->num == -1) {
+ len = virConnectNumOfDefinedNetworks(conn);
+ if (len < 0) {
goto cleanup;
}
+ ret->num = len;
rv = 0;
@@ -4332,7 +4339,7 @@ remoteDispatchNumOfDomains(struct qemud_server *server ATTRIBUTE_UNUSED,
}
ret->num = virConnectNumOfDomains(conn);
- if (ret->num == -1) {
+ if (ret->num < 0) {
goto cleanup;
}
@@ -4361,7 +4368,7 @@ remoteDispatchNumOfNetworks(struct qemud_server *server ATTRIBUTE_UNUSED,
}
ret->num = virConnectNumOfNetworks(conn);
- if (ret->num == -1) {
+ if (ret->num < 0) {
goto cleanup;
}
@@ -4392,7 +4399,7 @@ remoteDispatchNumOfInterfaces(struct qemud_server *server ATTRIBUTE_UNUSED,
}
ret->num = virConnectNumOfInterfaces(conn);
- if (ret->num == -1) {
+ if (ret->num < 0) {
goto cleanup;
}
@@ -4414,6 +4421,7 @@ remoteDispatchListInterfaces(struct qemud_server *server ATTRIBUTE_UNUSED,
remote_list_interfaces_ret *ret)
{
int rv = -1;
+ int len;
if (!conn) {
virNetError(VIR_ERR_INTERNAL_ERROR, "%s", _("connection not open"));
@@ -4432,12 +4440,12 @@ remoteDispatchListInterfaces(struct qemud_server *server ATTRIBUTE_UNUSED,
goto cleanup;
}
- ret->names.names_len =
- virConnectListInterfaces(conn,
- ret->names.names_val, args->maxnames);
- if (ret->names.names_len == -1) {
+ len = virConnectListInterfaces(conn,
+ ret->names.names_val, args->maxnames);
+ if (len < 0) {
goto cleanup;
}
+ ret->names.names_len = len;
rv = 0;
@@ -4459,16 +4467,18 @@ remoteDispatchNumOfDefinedInterfaces(struct qemud_server *server ATTRIBUTE_UNUSE
remote_num_of_defined_interfaces_ret *ret)
{
int rv = -1;
+ int len;
if (!conn) {
virNetError(VIR_ERR_INTERNAL_ERROR, "%s", _("connection not open"));
goto cleanup;
}
- ret->num = virConnectNumOfDefinedInterfaces(conn);
- if (ret->num == -1) {
+ len = virConnectNumOfDefinedInterfaces(conn);
+ if (len < 0) {
goto cleanup;
}
+ ret->num = len;
rv = 0;
@@ -4488,6 +4498,7 @@ remoteDispatchListDefinedInterfaces(struct qemud_server *server ATTRIBUTE_UNUSED
remote_list_defined_interfaces_ret *ret)
{
int rv = -1;
+ int len;
if (!conn) {
virNetError(VIR_ERR_INTERNAL_ERROR, "%s", _("connection not open"));
@@ -4506,12 +4517,12 @@ remoteDispatchListDefinedInterfaces(struct qemud_server *server ATTRIBUTE_UNUSED
goto cleanup;
}
- ret->names.names_len =
- virConnectListDefinedInterfaces(conn,
- ret->names.names_val, args->maxnames);
- if (ret->names.names_len == -1) {
+ len = virConnectListDefinedInterfaces(conn,
+ ret->names.names_val, args->maxnames);
+ if (len < 0) {
goto cleanup;
}
+ ret->names.names_len = len;
rv = 0;
@@ -4685,7 +4696,7 @@ remoteDispatchInterfaceUndefine(struct qemud_server *server ATTRIBUTE_UNUSED,
goto cleanup;
}
- if (virInterfaceUndefine(iface) == -1) {
+ if (virInterfaceUndefine(iface) < 0) {
goto cleanup;
}
@@ -4721,7 +4732,7 @@ remoteDispatchInterfaceCreate(struct qemud_server *server ATTRIBUTE_UNUSED,
goto cleanup;
}
- if (virInterfaceCreate(iface, args->flags) == -1) {
+ if (virInterfaceCreate(iface, args->flags) < 0) {
goto cleanup;
}
@@ -4757,7 +4768,7 @@ remoteDispatchInterfaceDestroy(struct qemud_server *server ATTRIBUTE_UNUSED,
goto cleanup;
}
- if (virInterfaceDestroy(iface, args->flags) == -1) {
+ if (virInterfaceDestroy(iface, args->flags) < 0) {
goto cleanup;
}
@@ -5585,6 +5596,7 @@ remoteDispatchListDefinedStoragePools(struct qemud_server *server ATTRIBUTE_UNUS
remote_list_defined_storage_pools_ret *ret)
{
int rv = -1;
+ int len;
if (!conn) {
virNetError(VIR_ERR_INTERNAL_ERROR, "%s", _("connection not open"));
@@ -5603,12 +5615,12 @@ remoteDispatchListDefinedStoragePools(struct qemud_server *server ATTRIBUTE_UNUS
goto cleanup;
}
- ret->names.names_len =
- virConnectListDefinedStoragePools(conn,
- ret->names.names_val, args->maxnames);
- if (ret->names.names_len == -1) {
+ len = virConnectListDefinedStoragePools(conn,
+ ret->names.names_val, args->maxnames);
+ if (len < 0) {
goto cleanup;
}
+ ret->names.names_len = len;
rv = 0;
@@ -5630,6 +5642,7 @@ remoteDispatchListStoragePools(struct qemud_server *server ATTRIBUTE_UNUSED,
remote_list_storage_pools_ret *ret)
{
int rv = -1;
+ int len;
if (!conn) {
virNetError(VIR_ERR_INTERNAL_ERROR, "%s", _("connection not open"));
@@ -5648,12 +5661,12 @@ remoteDispatchListStoragePools(struct qemud_server *server ATTRIBUTE_UNUSED,
goto cleanup;
}
- ret->names.names_len =
- virConnectListStoragePools(conn,
- ret->names.names_val, args->maxnames);
- if (ret->names.names_len == -1) {
+ len = virConnectListStoragePools(conn,
+ ret->names.names_val, args->maxnames);
+ if (len < 0) {
goto cleanup;
}
+ ret->names.names_len = len;
rv = 0;
@@ -5721,7 +5734,7 @@ remoteDispatchStoragePoolCreate(struct qemud_server *server ATTRIBUTE_UNUSED,
goto cleanup;
}
- if (virStoragePoolCreate(pool, args->flags) == -1) {
+ if (virStoragePoolCreate(pool, args->flags) < 0) {
goto cleanup;
}
@@ -5825,7 +5838,7 @@ remoteDispatchStoragePoolBuild(struct qemud_server *server ATTRIBUTE_UNUSED,
goto cleanup;
}
- if (virStoragePoolBuild(pool, args->flags) == -1) {
+ if (virStoragePoolBuild(pool, args->flags) < 0) {
goto cleanup;
}
@@ -5862,7 +5875,7 @@ remoteDispatchStoragePoolDestroy(struct qemud_server *server ATTRIBUTE_UNUSED,
goto cleanup;
}
- if (virStoragePoolDestroy(pool) == -1) {
+ if (virStoragePoolDestroy(pool) < 0) {
goto cleanup;
}
@@ -5898,7 +5911,7 @@ remoteDispatchStoragePoolDelete(struct qemud_server *server ATTRIBUTE_UNUSED,
goto cleanup;
}
- if (virStoragePoolDelete(pool, args->flags) == -1) {
+ if (virStoragePoolDelete(pool, args->flags) < 0) {
goto cleanup;
}
@@ -5934,7 +5947,7 @@ remoteDispatchStoragePoolRefresh(struct qemud_server *server ATTRIBUTE_UNUSED,
goto cleanup;
}
- if (virStoragePoolRefresh(pool, args->flags) == -1) {
+ if (virStoragePoolRefresh(pool, args->flags) < 0) {
goto cleanup;
}
@@ -5971,7 +5984,7 @@ remoteDispatchStoragePoolGetInfo(struct qemud_server *server ATTRIBUTE_UNUSED,
goto cleanup;
}
- if (virStoragePoolGetInfo(pool, &info) == -1) {
+ if (virStoragePoolGetInfo(pool, &info) < 0) {
goto cleanup;
}
@@ -6050,7 +6063,7 @@ remoteDispatchStoragePoolGetAutostart(struct qemud_server *server ATTRIBUTE_UNUS
goto cleanup;
}
- if (virStoragePoolGetAutostart(pool, &ret->autostart) == -1) {
+ if (virStoragePoolGetAutostart(pool, &ret->autostart) < 0) {
goto cleanup;
}
@@ -6197,7 +6210,7 @@ remoteDispatchStoragePoolSetAutostart(struct qemud_server *server ATTRIBUTE_UNUS
goto cleanup;
}
- if (virStoragePoolSetAutostart(pool, args->autostart) == -1) {
+ if (virStoragePoolSetAutostart(pool, args->autostart) < 0) {
goto cleanup;
}
@@ -6233,7 +6246,7 @@ remoteDispatchStoragePoolUndefine(struct qemud_server *server ATTRIBUTE_UNUSED,
goto cleanup;
}
- if (virStoragePoolUndefine(pool) == -1) {
+ if (virStoragePoolUndefine(pool) < 0) {
goto cleanup;
}
@@ -6264,7 +6277,7 @@ remoteDispatchNumOfStoragePools(struct qemud_server *server ATTRIBUTE_UNUSED,
}
ret->num = virConnectNumOfStoragePools(conn);
- if (ret->num == -1) {
+ if (ret->num < 0) {
goto cleanup;
}
@@ -6293,7 +6306,7 @@ remoteDispatchNumOfDefinedStoragePools(struct qemud_server *server ATTRIBUTE_UNU
}
ret->num = virConnectNumOfDefinedStoragePools(conn);
- if (ret->num == -1) {
+ if (ret->num < 0) {
goto cleanup;
}
@@ -6316,6 +6329,7 @@ remoteDispatchStoragePoolListVolumes(struct qemud_server *server ATTRIBUTE_UNUSE
{
virStoragePoolPtr pool = NULL;
int rv = -1;
+ int len;
if (!conn) {
virNetError(VIR_ERR_INTERNAL_ERROR, "%s", _("connection not open"));
@@ -6339,12 +6353,12 @@ remoteDispatchStoragePoolListVolumes(struct qemud_server *server ATTRIBUTE_UNUSE
goto cleanup;
}
- ret->names.names_len =
- virStoragePoolListVolumes(pool,
- ret->names.names_val, args->maxnames);
- if (ret->names.names_len == -1) {
+ len = virStoragePoolListVolumes(pool,
+ ret->names.names_val, args->maxnames);
+ if (len < 0) {
goto cleanup;
}
+ ret->names.names_len = len;
rv = 0;
@@ -6382,7 +6396,7 @@ remoteDispatchStoragePoolNumOfVolumes(struct qemud_server *server ATTRIBUTE_UNUS
}
ret->num = virStoragePoolNumOfVolumes(pool);
- if (ret->num == -1) {
+ if (ret->num < 0) {
goto cleanup;
}
@@ -6516,7 +6530,7 @@ remoteDispatchStorageVolDelete(struct qemud_server *server ATTRIBUTE_UNUSED,
goto cleanup;
}
- if (virStorageVolDelete(vol, args->flags) == -1) {
+ if (virStorageVolDelete(vol, args->flags) < 0) {
goto cleanup;
}
@@ -6552,7 +6566,7 @@ remoteDispatchStorageVolWipe(struct qemud_server *server ATTRIBUTE_UNUSED,
goto cleanup;
}
- if (virStorageVolWipe(vol, args->flags) == -1) {
+ if (virStorageVolWipe(vol, args->flags) < 0) {
goto cleanup;
}
@@ -6589,7 +6603,7 @@ remoteDispatchStorageVolGetInfo(struct qemud_server *server ATTRIBUTE_UNUSED,
goto cleanup;
}
- if (virStorageVolGetInfo(vol, &info) == -1) {
+ if (virStorageVolGetInfo(vol, &info) < 0) {
goto cleanup;
}
@@ -6820,7 +6834,7 @@ remoteDispatchNodeNumOfDevices(struct qemud_server *server ATTRIBUTE_UNUSED,
ret->num = virNodeNumOfDevices(conn,
args->cap ? *args->cap : NULL,
args->flags);
- if (ret->num == -1) {
+ if (ret->num < 0) {
goto cleanup;
}
@@ -6843,6 +6857,7 @@ remoteDispatchNodeListDevices(struct qemud_server *server ATTRIBUTE_UNUSED,
remote_node_list_devices_ret *ret)
{
int rv = -1;
+ int len;
if (!conn) {
virNetError(VIR_ERR_INTERNAL_ERROR, "%s", _("connection not open"));
@@ -6861,13 +6876,13 @@ remoteDispatchNodeListDevices(struct qemud_server *server ATTRIBUTE_UNUSED,
goto cleanup;
}
- ret->names.names_len =
- virNodeListDevices(conn,
- args->cap ? *args->cap : NULL,
- ret->names.names_val, args->maxnames, args->flags);
- if (ret->names.names_len == -1) {
+ len = virNodeListDevices(conn,
+ args->cap ? *args->cap : NULL,
+ ret->names.names_val, args->maxnames, args->flags);
+ if (len < 0) {
goto cleanup;
}
+ ret->names.names_len = len;
rv = 0;
@@ -7056,6 +7071,7 @@ remoteDispatchNodeDeviceListCaps(struct qemud_server *server ATTRIBUTE_UNUSED,
{
virNodeDevicePtr dev = NULL;
int rv = -1;
+ int len;
if (!conn) {
virNetError(VIR_ERR_INTERNAL_ERROR, "%s", _("connection not open"));
@@ -7079,12 +7095,12 @@ remoteDispatchNodeDeviceListCaps(struct qemud_server *server ATTRIBUTE_UNUSED,
goto cleanup;
}
- ret->names.names_len =
- virNodeDeviceListCaps(dev, ret->names.names_val,
- args->maxnames);
- if (ret->names.names_len == -1) {
+ len = virNodeDeviceListCaps(dev, ret->names.names_val,
+ args->maxnames);
+ if (len < 0) {
goto cleanup;
}
+ ret->names.names_len = len;
rv = 0;
@@ -7121,7 +7137,7 @@ remoteDispatchNodeDeviceDettach(struct qemud_server *server ATTRIBUTE_UNUSED,
goto cleanup;
}
- if (virNodeDeviceDettach(dev) == -1) {
+ if (virNodeDeviceDettach(dev) < 0) {
goto cleanup;
}
@@ -7158,7 +7174,7 @@ remoteDispatchNodeDeviceReAttach(struct qemud_server *server ATTRIBUTE_UNUSED,
goto cleanup;
}
- if (virNodeDeviceReAttach(dev) == -1) {
+ if (virNodeDeviceReAttach(dev) < 0) {
goto cleanup;
}
@@ -7195,7 +7211,7 @@ remoteDispatchNodeDeviceReset(struct qemud_server *server ATTRIBUTE_UNUSED,
goto cleanup;
}
- if (virNodeDeviceReset(dev) == -1) {
+ if (virNodeDeviceReset(dev) < 0) {
goto cleanup;
}
@@ -7267,7 +7283,7 @@ remoteDispatchNodeDeviceDestroy(struct qemud_server *server ATTRIBUTE_UNUSED,
goto cleanup;
}
- if (virNodeDeviceDestroy(dev) == -1) {
+ if (virNodeDeviceDestroy(dev) < 0) {
goto cleanup;
}
@@ -7443,7 +7459,7 @@ remoteDispatchDomainEventsDeregister(struct qemud_server *server ATTRIBUTE_UNUSE
goto cleanup;
}
- if (client->domainEventCallbackID[VIR_DOMAIN_EVENT_ID_LIFECYCLE] == -1) {
+ if (client->domainEventCallbackID[VIR_DOMAIN_EVENT_ID_LIFECYCLE] < 0) {
virNetError(VIR_ERR_INTERNAL_ERROR, _("domain event %d not registered"), VIR_DOMAIN_EVENT_ID_LIFECYCLE);
goto cleanup;
}
@@ -7543,7 +7559,7 @@ remoteDispatchNumOfSecrets(struct qemud_server *server ATTRIBUTE_UNUSED,
}
ret->num = virConnectNumOfSecrets(conn);
- if (ret->num == -1) {
+ if (ret->num < 0) {
goto cleanup;
}
@@ -7565,6 +7581,7 @@ remoteDispatchListSecrets(struct qemud_server *server ATTRIBUTE_UNUSED,
remote_list_secrets_ret *ret)
{
int rv = -1;
+ int len;
if (!conn) {
virNetError(VIR_ERR_INTERNAL_ERROR, "%s", _("connection not open"));
@@ -7582,11 +7599,12 @@ remoteDispatchListSecrets(struct qemud_server *server ATTRIBUTE_UNUSED,
goto cleanup;
}
- ret->uuids.uuids_len = virConnectListSecrets(conn, ret->uuids.uuids_val,
- args->maxuuids);
- if (ret->uuids.uuids_len == -1) {
+ len = virConnectListSecrets(conn, ret->uuids.uuids_val,
+ args->maxuuids);
+ if (len < 0) {
goto cleanup;
}
+ ret->uuids.uuids_len = len;
rv = 0;
@@ -8267,7 +8285,7 @@ remoteDispatchDomainGetJobInfo(struct qemud_server *server ATTRIBUTE_UNUSED,
goto cleanup;
}
- if (virDomainGetJobInfo(dom, &info) == -1) {
+ if (virDomainGetJobInfo(dom, &info) < 0) {
goto cleanup;
}
@@ -8317,7 +8335,7 @@ remoteDispatchDomainAbortJob(struct qemud_server *server ATTRIBUTE_UNUSED,
goto cleanup;
}
- if (virDomainAbortJob(dom) == -1) {
+ if (virDomainAbortJob(dom) < 0) {
goto cleanup;
}
@@ -8354,7 +8372,7 @@ remoteDispatchDomainMigrateSetMaxDowntime(struct qemud_server *server ATTRIBUTE_
goto cleanup;
}
- if (virDomainMigrateSetMaxDowntime(dom, args->downtime, args->flags) == -1) {
+ if (virDomainMigrateSetMaxDowntime(dom, args->downtime, args->flags) < 0) {
goto cleanup;
}
@@ -8390,7 +8408,7 @@ remoteDispatchDomainMigrateSetMaxSpeed(struct qemud_server *server ATTRIBUTE_UNU
goto cleanup;
}
- if (virDomainMigrateSetMaxSpeed(dom, args->bandwidth, args->flags) == -1) {
+ if (virDomainMigrateSetMaxSpeed(dom, args->bandwidth, args->flags) < 0) {
goto cleanup;
}
@@ -8512,7 +8530,7 @@ remoteDispatchDomainSnapshotNum(struct qemud_server *server ATTRIBUTE_UNUSED,
}
ret->num = virDomainSnapshotNum(domain, args->flags);
- if (ret->num == -1) {
+ if (ret->num < 0) {
goto cleanup;
}
@@ -8537,6 +8555,7 @@ remoteDispatchDomainSnapshotListNames(struct qemud_server *server ATTRIBUTE_UNUS
{
virDomainPtr domain = NULL;
int rv = -1;
+ int len;
if (!conn) {
virNetError(VIR_ERR_INTERNAL_ERROR, "%s", _("connection not open"));
@@ -8560,13 +8579,14 @@ remoteDispatchDomainSnapshotListNames(struct qemud_server *server ATTRIBUTE_UNUS
goto cleanup;
}
- ret->names.names_len = virDomainSnapshotListNames(domain,
- ret->names.names_val,
- args->nameslen,
- args->flags);
- if (ret->names.names_len == -1) {
+ len = virDomainSnapshotListNames(domain,
+ ret->names.names_val,
+ args->nameslen,
+ args->flags);
+ if (len < 0) {
goto cleanup;
}
+ ret->names.names_len = len;
rv = 0;
@@ -8730,7 +8750,7 @@ remoteDispatchDomainRevertToSnapshot(struct qemud_server *server ATTRIBUTE_UNUSE
if (snapshot == NULL)
goto cleanup;
- if (virDomainRevertToSnapshot(snapshot, args->flags) == -1)
+ if (virDomainRevertToSnapshot(snapshot, args->flags) < 0)
goto cleanup;
rv = 0;
@@ -8771,7 +8791,7 @@ remoteDispatchDomainSnapshotDelete(struct qemud_server *server ATTRIBUTE_UNUSED,
if (snapshot == NULL)
goto cleanup;
- if (virDomainSnapshotDelete(snapshot, args->flags) == -1)
+ if (virDomainSnapshotDelete(snapshot, args->flags) < 0)
goto cleanup;
rv = 0;
@@ -9004,7 +9024,7 @@ remoteDispatchNwfilterUndefine(struct qemud_server *server ATTRIBUTE_UNUSED,
goto cleanup;
}
- if (virNWFilterUndefine(nwfilter) == -1) {
+ if (virNWFilterUndefine(nwfilter) < 0) {
goto cleanup;
}
@@ -9028,6 +9048,7 @@ remoteDispatchListNwfilters(struct qemud_server *server ATTRIBUTE_UNUSED,
remote_list_nwfilters_ret *ret)
{
int rv = -1;
+ int len;
if (!conn) {
virNetError(VIR_ERR_INTERNAL_ERROR, "%s", _("connection not open"));
@@ -9046,12 +9067,12 @@ remoteDispatchListNwfilters(struct qemud_server *server ATTRIBUTE_UNUSED,
goto cleanup;
}
- ret->names.names_len =
- virConnectListNWFilters(conn,
- ret->names.names_val, args->maxnames);
- if (ret->names.names_len == -1) {
+ len = virConnectListNWFilters(conn,
+ ret->names.names_val, args->maxnames);
+ if (len < 0) {
goto cleanup;
}
+ ret->names.names_len = len;
rv = 0;
@@ -9120,7 +9141,7 @@ remoteDispatchNumOfNwfilters(struct qemud_server *server ATTRIBUTE_UNUSED,
}
ret->num = virConnectNumOfNWFilters(conn);
- if (ret->num == -1) {
+ if (ret->num < 0) {
goto cleanup;
}
@@ -9156,7 +9177,7 @@ remoteDispatchDomainGetBlockInfo(struct qemud_server *server ATTRIBUTE_UNUSED,
goto cleanup;
}
- if (virDomainGetBlockInfo(dom, args->path, &info, args->flags) == -1) {
+ if (virDomainGetBlockInfo(dom, args->path, &info, args->flags) < 0) {
goto cleanup;
}
@@ -9197,7 +9218,7 @@ qemuDispatchMonitorCommand(struct qemud_server *server ATTRIBUTE_UNUSED,
}
if (virDomainQemuMonitorCommand(domain, args->cmd, &ret->result,
- args->flags) == -1) {
+ args->flags) < 0) {
goto cleanup;
}
@@ -9246,7 +9267,7 @@ remoteDispatchDomainOpenConsole(struct qemud_server *server ATTRIBUTE_UNUSED,
args->devname ? *args->devname : NULL,
stream->st,
args->flags);
- if (r == -1) {
+ if (r < 0) {
goto cleanup;
}
--
1.7.4.2
13 years, 7 months