[libvirt] [PATCH v4 04/12] hyperv: add hypervWqlQuery struct.

Dawid Zamirski posted 12 patches 8 years, 10 months ago
[libvirt] [PATCH v4 04/12] hyperv: add hypervWqlQuery struct.
Posted by Dawid Zamirski 8 years, 10 months ago
Since this is the last commit that will compile in the series, the
remaining patches should be squashed into this one - they are kept
separate only for code review purposes.

This struct is to be passed to enumerate-and-pull wsman request (to run
"Select" queries) and provides the hypervWmiClassInfoListPtr instance
from which we can extract the version specific info using the new
hypervGetWmiClassInfo function (currently unused)
---
 src/hyperv/hyperv_wmi.c | 35 +++++++++++++++++++++++++++++++++++
 src/hyperv/hyperv_wmi.h |  8 ++++++++
 2 files changed, 43 insertions(+)

diff --git a/src/hyperv/hyperv_wmi.c b/src/hyperv/hyperv_wmi.c
index b2b5243..069bcc9 100644
--- a/src/hyperv/hyperv_wmi.c
+++ b/src/hyperv/hyperv_wmi.c
@@ -45,6 +45,41 @@
 #define VIR_FROM_THIS VIR_FROM_HYPERV
 
 
+static int ATTRIBUTE_UNUSED
+hypervGetWmiClassInfo(hypervPrivate *priv, hypervWmiClassInfoListPtr list,
+                      hypervWmiClassInfoPtr *info)
+{
+    const char *version = "v2";
+    size_t i;
+
+    if (list->count == 0) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("The WMI class info list is empty"));
+        return -1;
+    }
+
+    /* if there's just one WMI class and isn't versioned, assume "shared" */
+    if (list->count == 1 && list->objs[0]->version == NULL) {
+        *info = list->objs[0];
+        return 0;
+    }
+
+    if (priv->wmiVersion == HYPERV_WMI_VERSION_V1)
+        version = "v1";
+
+    for (i = 0; i < list->count; i++) {
+       if (STRCASEEQ(list->objs[i]->version, version)) {
+           *info = list->objs[i];
+           return 0;
+       }
+    }
+
+    virReportError(VIR_ERR_INTERNAL_ERROR,
+                   _("Could not match WMI class info for version %s"),
+                   version);
+
+    return -1;
+}
 
 int
 hypervVerifyResponse(WsManClient *client, WsXmlDocH response,
diff --git a/src/hyperv/hyperv_wmi.h b/src/hyperv/hyperv_wmi.h
index 5fc36e8..c7d82bc 100644
--- a/src/hyperv/hyperv_wmi.h
+++ b/src/hyperv/hyperv_wmi.h
@@ -30,6 +30,7 @@
 # include "openwsman.h"
 
 
+# define HYPERV_WQL_QUERY_INITIALIZER { VIR_BUFFER_INITIALIZER, NULL }
 
 typedef struct _hypervObject hypervObject;
 
@@ -61,6 +62,13 @@ struct _hypervObjectUnified {
     hypervObjectUnified *next;
 };
 
+typedef struct _hypervWqlQuery hypervWqlQuery;
+typedef hypervWqlQuery *hypervWqlQueryPtr;
+struct _hypervWqlQuery {
+    virBuffer query;
+    hypervWmiClassInfoListPtr info;
+};
+
 struct _hypervObject {
     XmlSerializerInfo *serializerInfo;
     XML_TYPE_PTR data;
-- 
2.9.3

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH v4 04/12] hyperv: add hypervWqlQuery struct.
Posted by Matthias Bolte 8 years, 10 months ago
2017-04-05 0:26 GMT+02:00 Dawid Zamirski <dzamirski@datto.com>:
> Since this is the last commit that will compile in the series, the
> remaining patches should be squashed into this one - they are kept
> separate only for code review purposes.
>
> This struct is to be passed to enumerate-and-pull wsman request (to run
> "Select" queries) and provides the hypervWmiClassInfoListPtr instance
> from which we can extract the version specific info using the new
> hypervGetWmiClassInfo function (currently unused)
> ---
>  src/hyperv/hyperv_wmi.c | 35 +++++++++++++++++++++++++++++++++++
>  src/hyperv/hyperv_wmi.h |  8 ++++++++
>  2 files changed, 43 insertions(+)

> diff --git a/src/hyperv/hyperv_wmi.h b/src/hyperv/hyperv_wmi.h
> index 5fc36e8..c7d82bc 100644
> --- a/src/hyperv/hyperv_wmi.h
> +++ b/src/hyperv/hyperv_wmi.h
> @@ -30,6 +30,7 @@
>  # include "openwsman.h"
>
>
> +# define HYPERV_WQL_QUERY_INITIALIZER { VIR_BUFFER_INITIALIZER, NULL }
>
>  typedef struct _hypervObject hypervObject;
>
> @@ -61,6 +62,13 @@ struct _hypervObjectUnified {
>      hypervObjectUnified *next;
>  };
>
> +typedef struct _hypervWqlQuery hypervWqlQuery;
> +typedef hypervWqlQuery *hypervWqlQueryPtr;
> +struct _hypervWqlQuery {
> +    virBuffer query;
> +    hypervWmiClassInfoListPtr info;
> +};

My suggestion to use a virBuffer instead of a virBufferPtr here wasn't
well though out. I switched this to virBufferPtr before pushing this
patch.

-- 
Matthias Bolte
http://photron.blogspot.com

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list