This enables this function to handle "v1" and "v2" WMI requests.
Since this commit and the ones that follow should be squashed on
previous one:
* rename hypervObjectUnified -> hypervObject as we've already broken
compilation here so there's no point in keeping those in parallel
anymore.
* do not mark hypervGetWmiClassInfo as unused
---
src/hyperv/hyperv_wmi.c | 41 ++++++++++++++++++++++-------------------
src/hyperv/hyperv_wmi.h | 17 ++++-------------
2 files changed, 26 insertions(+), 32 deletions(-)
diff --git a/src/hyperv/hyperv_wmi.c b/src/hyperv/hyperv_wmi.c
index 069bcc9..eab6192 100644
--- a/src/hyperv/hyperv_wmi.c
+++ b/src/hyperv/hyperv_wmi.c
@@ -45,7 +45,7 @@
#define VIR_FROM_THIS VIR_FROM_HYPERV
-static int ATTRIBUTE_UNUSED
+static int
hypervGetWmiClassInfo(hypervPrivate *priv, hypervWmiClassInfoListPtr list,
hypervWmiClassInfoPtr *info)
{
@@ -143,14 +143,14 @@ hypervVerifyResponse(WsManClient *client, WsXmlDocH response,
/* This function guarantees that query is freed, even on failure */
int
-hypervEnumAndPull(hypervPrivate *priv, virBufferPtr query, const char *root,
- XmlSerializerInfo *serializerInfo, const char *resourceUri,
- const char *className, hypervObject **list)
+hypervEnumAndPull(hypervPrivate *priv, hypervWqlQueryPtr wqlQuery,
+ hypervObject **list)
{
int result = -1;
WsSerializerContextH serializerContext;
client_opt_t *options = NULL;
char *query_string = NULL;
+ hypervWmiClassInfoPtr wmiInfo = NULL;
filter_t *filter = NULL;
WsXmlDocH response = NULL;
char *enumContext = NULL;
@@ -160,18 +160,20 @@ hypervEnumAndPull(hypervPrivate *priv, virBufferPtr query, const
char *root,
XML_TYPE_PTR data = NULL;
hypervObject *object;
- if (virBufferCheckError(query) < 0) {
- virBufferFreeAndReset(query);
+ if (virBufferCheckError(&wqlQuery->query) < 0) {
+ virBufferFreeAndReset(&wqlQuery->query);
return -1;
}
- query_string = virBufferContentAndReset(query);
+ query_string = virBufferContentAndReset(&wqlQuery->query);
if (list == NULL || *list != NULL) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid
argument"));
- VIR_FREE(query_string);
return -1;
}
+ if (hypervGetWmiClassInfo(priv, wqlQuery->info, &wmiInfo) < 0)
+ goto cleanup;
+
serializerContext = wsmc_get_serialization_context(priv->client);
options = wsmc_options_init();
@@ -190,7 +192,8 @@ hypervEnumAndPull(hypervPrivate *priv, virBufferPtr query, const char
*root,
goto cleanup;
}
- response = wsmc_action_enumerate(priv->client, root, options, filter);
+ response = wsmc_action_enumerate(priv->client, wmiInfo->rootUri, options,
+ filter);
if (hypervVerifyResponse(priv->client, response, "enumeration") < 0)
goto cleanup;
@@ -201,7 +204,7 @@ hypervEnumAndPull(hypervPrivate *priv, virBufferPtr query, const char
*root,
response = NULL;
while (enumContext != NULL && *enumContext != '\0') {
- response = wsmc_action_pull(priv->client, resourceUri, options,
+ response = wsmc_action_pull(priv->client, wmiInfo->resourceUri, options,
filter, enumContext);
if (hypervVerifyResponse(priv->client, response, "pull") < 0)
@@ -231,11 +234,12 @@ hypervEnumAndPull(hypervPrivate *priv, virBufferPtr query, const
char *root,
goto cleanup;
}
- if (ws_xml_get_child(node, 0, resourceUri, className) == NULL)
+ if (ws_xml_get_child(node, 0, wmiInfo->resourceUri,
+ wmiInfo->name) == NULL)
break;
- data = ws_deserialize(serializerContext, node, serializerInfo,
- className, resourceUri, NULL, 0, 0);
+ data = ws_deserialize(serializerContext, node, wmiInfo->serializerInfo,
+ wmiInfo->name, wmiInfo->resourceUri, NULL, 0, 0);
if (data == NULL) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
@@ -246,8 +250,8 @@ hypervEnumAndPull(hypervPrivate *priv, virBufferPtr query, const char
*root,
if (VIR_ALLOC(object) < 0)
goto cleanup;
- object->serializerInfo = serializerInfo;
- object->data = data;
+ object->info = wmiInfo;
+ object->data.common = data;
data = NULL;
@@ -283,12 +287,11 @@ hypervEnumAndPull(hypervPrivate *priv, virBufferPtr query, const
char *root,
/* FIXME: ws_serializer_free_mem is broken in openwsman <= 2.2.6,
* see hypervFreeObject for a detailed explanation. */
if (ws_serializer_free_mem(serializerContext, data,
- serializerInfo) < 0) {
+ wmiInfo->serializerInfo) < 0) {
VIR_ERROR(_("Could not free deserialized data"));
}
#endif
}
-
VIR_FREE(query_string);
ws_xml_destroy_doc(response);
VIR_FREE(enumContext);
@@ -322,8 +325,8 @@ hypervFreeObject(hypervPrivate *priv ATTRIBUTE_UNUSED, hypervObject
*object)
* them in wsmc_release. So this doesn't result in a real
* memory leak, but just in piling up unused memory until
* the connection is closed. */
- if (ws_serializer_free_mem(serializerContext, object->data,
- object->serializerInfo) < 0) {
+ if (ws_serializer_free_mem(serializerContext, object->data.common,
+ object->info->serializerInfo) < 0) {
VIR_ERROR(_("Could not free deserialized data"));
}
#endif
diff --git a/src/hyperv/hyperv_wmi.h b/src/hyperv/hyperv_wmi.h
index c7d82bc..b8b9c3d 100644
--- a/src/hyperv/hyperv_wmi.h
+++ b/src/hyperv/hyperv_wmi.h
@@ -32,7 +32,6 @@
# define HYPERV_WQL_QUERY_INITIALIZER { VIR_BUFFER_INITIALIZER, NULL }
-typedef struct _hypervObject hypervObject;
int hypervVerifyResponse(WsManClient *client, WsXmlDocH response,
const char *detail);
@@ -42,8 +41,8 @@ int hypervVerifyResponse(WsManClient *client, WsXmlDocH response,
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Object
*/
-typedef struct _hypervObjectUnified hypervObjectUnified;
-struct _hypervObjectUnified {
+typedef struct _hypervObject hypervObject;
+struct _hypervObject {
/* Unserialized data from wsman response. The member called "common" has
* properties that are the same type and name for all "versions" of given
* WMI class. This means that calling code does not have to make any
@@ -59,7 +58,7 @@ struct _hypervObjectUnified {
/* The info used to make wsman request */
hypervWmiClassInfoPtr info;
- hypervObjectUnified *next;
+ hypervObject *next;
};
typedef struct _hypervWqlQuery hypervWqlQuery;
@@ -69,15 +68,7 @@ struct _hypervWqlQuery {
hypervWmiClassInfoListPtr info;
};
-struct _hypervObject {
- XmlSerializerInfo *serializerInfo;
- XML_TYPE_PTR data;
- hypervObject *next;
-};
-
-int hypervEnumAndPull(hypervPrivate *priv, virBufferPtr query,
- const char *root, XmlSerializerInfo *serializerInfo,
- const char *resourceUri, const char *className,
+int hypervEnumAndPull(hypervPrivate *priv, hypervWqlQueryPtr wqlQuery,
hypervObject **list);
void hypervFreeObject(hypervPrivate *priv, hypervObject *object);
--
2.9.3