This enables this function to handle "v1" and "v2" WMI requests.
Since this commit is where complilation breakage starts:
* commits that follow should be squashed into this one
* rename hypervObjectUnified -> hypervObject as we've already broken
compilation here so there's no point in keeping those in parallel
anymore.
---
src/hyperv/hyperv_wmi.c | 38 +++++++++++++++++---------------------
src/hyperv/hyperv_wmi.h | 17 ++++-------------
2 files changed, 21 insertions(+), 34 deletions(-)
diff --git a/src/hyperv/hyperv_wmi.c b/src/hyperv/hyperv_wmi.c
index 42ce507..dcd4d7a 100644
--- a/src/hyperv/hyperv_wmi.c
+++ b/src/hyperv/hyperv_wmi.c
@@ -141,14 +141,13 @@ 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;
@@ -158,18 +157,14 @@ hypervEnumAndPull(hypervPrivate *priv, virBufferPtr query, const
char *root,
XML_TYPE_PTR data = NULL;
hypervObject *object;
- if (virBufferCheckError(query) < 0) {
- virBufferFreeAndReset(query);
- return -1;
- }
- query_string = virBufferContentAndReset(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)
+ return -1;
+
serializerContext = wsmc_get_serialization_context(priv->client);
options = wsmc_options_init();
@@ -180,7 +175,7 @@ hypervEnumAndPull(hypervPrivate *priv, virBufferPtr query, const char
*root,
goto cleanup;
}
- filter = filter_create_simple(WSM_WQL_FILTER_DIALECT, query_string);
+ filter = filter_create_simple(WSM_WQL_FILTER_DIALECT, wqlQuery->query);
if (filter == NULL) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
@@ -188,7 +183,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;
@@ -199,7 +195,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)
@@ -229,11 +225,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",
@@ -244,8 +241,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;
@@ -281,13 +278,12 @@ 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);
hypervFreeObject(priv, head);
diff --git a/src/hyperv/hyperv_wmi.h b/src/hyperv/hyperv_wmi.h
index 12b94af..8ce32a9 100644
--- a/src/hyperv/hyperv_wmi.h
+++ b/src/hyperv/hyperv_wmi.h
@@ -32,7 +32,6 @@
# define HYPERV_WQL_QUERY_INITIALIZER {NULL, 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