2011-07-13 15:05:19 +00:00
|
|
|
/*
|
|
|
|
* hyperv_wmi.h: general WMI over WSMAN related functions and structures for
|
|
|
|
* managing Microsoft Hyper-V hosts
|
|
|
|
*
|
|
|
|
* Copyright (C) 2011 Matthias Bolte <matthias.bolte@googlemail.com>
|
|
|
|
* Copyright (C) 2009 Michael Sievers <msievers83@googlemail.com>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2012-09-20 22:30:55 +00:00
|
|
|
* License along with this library. If not, see
|
2012-07-21 10:06:23 +00:00
|
|
|
* <http://www.gnu.org/licenses/>.
|
2011-07-13 15:05:19 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2019-06-07 20:20:25 +00:00
|
|
|
#pragma once
|
2011-07-13 15:05:19 +00:00
|
|
|
|
2019-06-07 20:20:25 +00:00
|
|
|
#include "virbuffer.h"
|
|
|
|
#include "hyperv_private.h"
|
|
|
|
#include "hyperv_wmi_classes.h"
|
|
|
|
#include "virhash.h"
|
2011-07-13 15:05:19 +00:00
|
|
|
|
|
|
|
|
2019-06-07 20:20:25 +00:00
|
|
|
#define HYPERV_WQL_QUERY_INITIALIZER { NULL, NULL }
|
2011-07-13 15:05:19 +00:00
|
|
|
|
2019-06-07 20:20:25 +00:00
|
|
|
#define HYPERV_DEFAULT_PARAM_COUNT 5
|
2017-06-27 19:13:23 +00:00
|
|
|
|
2019-06-07 20:20:25 +00:00
|
|
|
#define MSVM_VIRTUALSYSTEMMANAGEMENTSERVICE_SELECTOR \
|
2017-06-27 19:13:27 +00:00
|
|
|
"CreationClassName=Msvm_VirtualSystemManagementService"
|
|
|
|
|
2017-03-30 16:47:18 +00:00
|
|
|
int hypervVerifyResponse(WsManClient *client, WsXmlDocH response,
|
2011-07-13 15:05:19 +00:00
|
|
|
const char *detail);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
|
|
* Object
|
|
|
|
*/
|
hyperv: add support for Hyper-V 2012 and newer
This patch reworks the Hyper-V driver structs and the code generator
to provide seamless support for both Hyper-V 2008 and 2012 or newer.
This does not implement any new libvirt APIs, it just adapts existing
2008-only driver to also handle 2012 and newer by sharing as much
driver code as possible (currently it's all of it :-)). This is needed
to set the foundation before we can move forward with implementing the
rest of the driver APIs.
With the 2012 release, Microsoft introduced "v2" version of Msvm_* WMI
classes. Those are largely the same as "v1" (used in 2008) but have some
new properties as well as need different wsman request URIs. To
accomodate those differences, most of work went into the code generator
so that it's "aware" of possibility of multiple versions of the same WMI
class and produce C code accordingly.
To accomplish this the following changes were made:
* the abstract hypervObject struct's data member was changed to a union
that has "common", "v1" and "v2" members. Those are structs that
represent WMI classes that we get back from wsman response. The
"common" struct has members that are present in both "v1" and "v2"
which the driver API callbacks can use to read the data from in
version-independent manner (if version-specific member needs to be
accessed the driver can check priv->wmiVersion and read from "v1" or
"v2" as needed). Those structs are guaranteed to be memory aligned
by the code generator (see the align_property_members implementation
that takes care of that)
* the generator produces *_WmiInfo for each WMI class "family" that
holds an array of hypervWmiClassInfoPtr each providing information
as to which request URI to use for each "version" of given WMI class
as well as XmlSerializerInfo struct needed to unserilize WS-MAN
responsed into the data structs. The driver uses those to make proper
WS-MAN request depending on which version it's connected to.
* the generator no longer produces "helper" functions such as
hypervGetMsvmComputerSystemList as those were originally just simple
wrappers around hypervEnumAndPull, instead those were hand-written
now (to keep driver changes minimal). The reason is that we'll have
more code coming implementing missing libvirt APIs and surely code
patterns will emerge that would warrant more useful "utility" functions
like that.
* a hypervInitConnection was added to the driver which "detects"
Hyper-V version by testing simple wsman request using v2 then falling
back to v1, obviously if both fail, the we're erroring out.
To express how the above translates in code:
void
hypervImplementSomeLibvirtApi(virConnectPtr conn, ...)
{
hypervPrivate *priv = conn->privateData;
virBuffer query = VIR_BUFFER_INITIALIZER;
hypervWqlQuery wqlQuery = HYPERV_WQL_QUERY_INITIALIZER;
Msvm_ComputerSystem *list = NULL; /* typed hypervObject instance */
/* the WmiInfo struct has the data needed for wsman request and
* response handling for both v1 and v2 */
wqlQuery.info = Msvm_ComputerSystem_WmiInfo;
wqlQuery.query = &query;
virBufferAddLit(&query, "select * from Msvm_ComputerSystem");
if (hypervEnumAndPull(priv, &wqlQuery, (hypervObject **) &list) < 0) {
goto cleanup;
}
if (list == NULL) {
/* none found */
goto cleanup;
}
/* works with v1 and v2 */
char *vmName = list->data.common->Name;
/* access property that is in v2 only */
if (priv->wmiVersion == HYPERV_WMI_VERSION_V2)
char *foo = list->data.v2->V2Property;
else
char *foo = list->data.v1->V1Property;
cleanup:
hypervFreeObject(priv, (hypervObject *)list);
}
2017-04-04 22:26:08 +00:00
|
|
|
|
|
|
|
typedef struct _hypervObject hypervObject;
|
|
|
|
struct _hypervObject {
|
2020-11-09 08:43:09 +00:00
|
|
|
XML_TYPE_PTR data; /* Unserialized data from wsman response */
|
|
|
|
hypervWmiClassInfoPtr info; /* The info used to make wsman request */
|
hyperv: add support for Hyper-V 2012 and newer
This patch reworks the Hyper-V driver structs and the code generator
to provide seamless support for both Hyper-V 2008 and 2012 or newer.
This does not implement any new libvirt APIs, it just adapts existing
2008-only driver to also handle 2012 and newer by sharing as much
driver code as possible (currently it's all of it :-)). This is needed
to set the foundation before we can move forward with implementing the
rest of the driver APIs.
With the 2012 release, Microsoft introduced "v2" version of Msvm_* WMI
classes. Those are largely the same as "v1" (used in 2008) but have some
new properties as well as need different wsman request URIs. To
accomodate those differences, most of work went into the code generator
so that it's "aware" of possibility of multiple versions of the same WMI
class and produce C code accordingly.
To accomplish this the following changes were made:
* the abstract hypervObject struct's data member was changed to a union
that has "common", "v1" and "v2" members. Those are structs that
represent WMI classes that we get back from wsman response. The
"common" struct has members that are present in both "v1" and "v2"
which the driver API callbacks can use to read the data from in
version-independent manner (if version-specific member needs to be
accessed the driver can check priv->wmiVersion and read from "v1" or
"v2" as needed). Those structs are guaranteed to be memory aligned
by the code generator (see the align_property_members implementation
that takes care of that)
* the generator produces *_WmiInfo for each WMI class "family" that
holds an array of hypervWmiClassInfoPtr each providing information
as to which request URI to use for each "version" of given WMI class
as well as XmlSerializerInfo struct needed to unserilize WS-MAN
responsed into the data structs. The driver uses those to make proper
WS-MAN request depending on which version it's connected to.
* the generator no longer produces "helper" functions such as
hypervGetMsvmComputerSystemList as those were originally just simple
wrappers around hypervEnumAndPull, instead those were hand-written
now (to keep driver changes minimal). The reason is that we'll have
more code coming implementing missing libvirt APIs and surely code
patterns will emerge that would warrant more useful "utility" functions
like that.
* a hypervInitConnection was added to the driver which "detects"
Hyper-V version by testing simple wsman request using v2 then falling
back to v1, obviously if both fail, the we're erroring out.
To express how the above translates in code:
void
hypervImplementSomeLibvirtApi(virConnectPtr conn, ...)
{
hypervPrivate *priv = conn->privateData;
virBuffer query = VIR_BUFFER_INITIALIZER;
hypervWqlQuery wqlQuery = HYPERV_WQL_QUERY_INITIALIZER;
Msvm_ComputerSystem *list = NULL; /* typed hypervObject instance */
/* the WmiInfo struct has the data needed for wsman request and
* response handling for both v1 and v2 */
wqlQuery.info = Msvm_ComputerSystem_WmiInfo;
wqlQuery.query = &query;
virBufferAddLit(&query, "select * from Msvm_ComputerSystem");
if (hypervEnumAndPull(priv, &wqlQuery, (hypervObject **) &list) < 0) {
goto cleanup;
}
if (list == NULL) {
/* none found */
goto cleanup;
}
/* works with v1 and v2 */
char *vmName = list->data.common->Name;
/* access property that is in v2 only */
if (priv->wmiVersion == HYPERV_WMI_VERSION_V2)
char *foo = list->data.v2->V2Property;
else
char *foo = list->data.v1->V1Property;
cleanup:
hypervFreeObject(priv, (hypervObject *)list);
}
2017-04-04 22:26:08 +00:00
|
|
|
hypervObject *next;
|
2017-04-04 22:26:07 +00:00
|
|
|
};
|
2011-07-13 15:05:19 +00:00
|
|
|
|
hyperv: add support for Hyper-V 2012 and newer
This patch reworks the Hyper-V driver structs and the code generator
to provide seamless support for both Hyper-V 2008 and 2012 or newer.
This does not implement any new libvirt APIs, it just adapts existing
2008-only driver to also handle 2012 and newer by sharing as much
driver code as possible (currently it's all of it :-)). This is needed
to set the foundation before we can move forward with implementing the
rest of the driver APIs.
With the 2012 release, Microsoft introduced "v2" version of Msvm_* WMI
classes. Those are largely the same as "v1" (used in 2008) but have some
new properties as well as need different wsman request URIs. To
accomodate those differences, most of work went into the code generator
so that it's "aware" of possibility of multiple versions of the same WMI
class and produce C code accordingly.
To accomplish this the following changes were made:
* the abstract hypervObject struct's data member was changed to a union
that has "common", "v1" and "v2" members. Those are structs that
represent WMI classes that we get back from wsman response. The
"common" struct has members that are present in both "v1" and "v2"
which the driver API callbacks can use to read the data from in
version-independent manner (if version-specific member needs to be
accessed the driver can check priv->wmiVersion and read from "v1" or
"v2" as needed). Those structs are guaranteed to be memory aligned
by the code generator (see the align_property_members implementation
that takes care of that)
* the generator produces *_WmiInfo for each WMI class "family" that
holds an array of hypervWmiClassInfoPtr each providing information
as to which request URI to use for each "version" of given WMI class
as well as XmlSerializerInfo struct needed to unserilize WS-MAN
responsed into the data structs. The driver uses those to make proper
WS-MAN request depending on which version it's connected to.
* the generator no longer produces "helper" functions such as
hypervGetMsvmComputerSystemList as those were originally just simple
wrappers around hypervEnumAndPull, instead those were hand-written
now (to keep driver changes minimal). The reason is that we'll have
more code coming implementing missing libvirt APIs and surely code
patterns will emerge that would warrant more useful "utility" functions
like that.
* a hypervInitConnection was added to the driver which "detects"
Hyper-V version by testing simple wsman request using v2 then falling
back to v1, obviously if both fail, the we're erroring out.
To express how the above translates in code:
void
hypervImplementSomeLibvirtApi(virConnectPtr conn, ...)
{
hypervPrivate *priv = conn->privateData;
virBuffer query = VIR_BUFFER_INITIALIZER;
hypervWqlQuery wqlQuery = HYPERV_WQL_QUERY_INITIALIZER;
Msvm_ComputerSystem *list = NULL; /* typed hypervObject instance */
/* the WmiInfo struct has the data needed for wsman request and
* response handling for both v1 and v2 */
wqlQuery.info = Msvm_ComputerSystem_WmiInfo;
wqlQuery.query = &query;
virBufferAddLit(&query, "select * from Msvm_ComputerSystem");
if (hypervEnumAndPull(priv, &wqlQuery, (hypervObject **) &list) < 0) {
goto cleanup;
}
if (list == NULL) {
/* none found */
goto cleanup;
}
/* works with v1 and v2 */
char *vmName = list->data.common->Name;
/* access property that is in v2 only */
if (priv->wmiVersion == HYPERV_WMI_VERSION_V2)
char *foo = list->data.v2->V2Property;
else
char *foo = list->data.v1->V1Property;
cleanup:
hypervFreeObject(priv, (hypervObject *)list);
}
2017-04-04 22:26:08 +00:00
|
|
|
typedef struct _hypervWqlQuery hypervWqlQuery;
|
|
|
|
typedef hypervWqlQuery *hypervWqlQueryPtr;
|
|
|
|
struct _hypervWqlQuery {
|
|
|
|
virBufferPtr query;
|
2020-11-09 08:43:10 +00:00
|
|
|
hypervWmiClassInfoPtr info;
|
2011-07-13 15:05:19 +00:00
|
|
|
};
|
|
|
|
|
hyperv: add support for Hyper-V 2012 and newer
This patch reworks the Hyper-V driver structs and the code generator
to provide seamless support for both Hyper-V 2008 and 2012 or newer.
This does not implement any new libvirt APIs, it just adapts existing
2008-only driver to also handle 2012 and newer by sharing as much
driver code as possible (currently it's all of it :-)). This is needed
to set the foundation before we can move forward with implementing the
rest of the driver APIs.
With the 2012 release, Microsoft introduced "v2" version of Msvm_* WMI
classes. Those are largely the same as "v1" (used in 2008) but have some
new properties as well as need different wsman request URIs. To
accomodate those differences, most of work went into the code generator
so that it's "aware" of possibility of multiple versions of the same WMI
class and produce C code accordingly.
To accomplish this the following changes were made:
* the abstract hypervObject struct's data member was changed to a union
that has "common", "v1" and "v2" members. Those are structs that
represent WMI classes that we get back from wsman response. The
"common" struct has members that are present in both "v1" and "v2"
which the driver API callbacks can use to read the data from in
version-independent manner (if version-specific member needs to be
accessed the driver can check priv->wmiVersion and read from "v1" or
"v2" as needed). Those structs are guaranteed to be memory aligned
by the code generator (see the align_property_members implementation
that takes care of that)
* the generator produces *_WmiInfo for each WMI class "family" that
holds an array of hypervWmiClassInfoPtr each providing information
as to which request URI to use for each "version" of given WMI class
as well as XmlSerializerInfo struct needed to unserilize WS-MAN
responsed into the data structs. The driver uses those to make proper
WS-MAN request depending on which version it's connected to.
* the generator no longer produces "helper" functions such as
hypervGetMsvmComputerSystemList as those were originally just simple
wrappers around hypervEnumAndPull, instead those were hand-written
now (to keep driver changes minimal). The reason is that we'll have
more code coming implementing missing libvirt APIs and surely code
patterns will emerge that would warrant more useful "utility" functions
like that.
* a hypervInitConnection was added to the driver which "detects"
Hyper-V version by testing simple wsman request using v2 then falling
back to v1, obviously if both fail, the we're erroring out.
To express how the above translates in code:
void
hypervImplementSomeLibvirtApi(virConnectPtr conn, ...)
{
hypervPrivate *priv = conn->privateData;
virBuffer query = VIR_BUFFER_INITIALIZER;
hypervWqlQuery wqlQuery = HYPERV_WQL_QUERY_INITIALIZER;
Msvm_ComputerSystem *list = NULL; /* typed hypervObject instance */
/* the WmiInfo struct has the data needed for wsman request and
* response handling for both v1 and v2 */
wqlQuery.info = Msvm_ComputerSystem_WmiInfo;
wqlQuery.query = &query;
virBufferAddLit(&query, "select * from Msvm_ComputerSystem");
if (hypervEnumAndPull(priv, &wqlQuery, (hypervObject **) &list) < 0) {
goto cleanup;
}
if (list == NULL) {
/* none found */
goto cleanup;
}
/* works with v1 and v2 */
char *vmName = list->data.common->Name;
/* access property that is in v2 only */
if (priv->wmiVersion == HYPERV_WMI_VERSION_V2)
char *foo = list->data.v2->V2Property;
else
char *foo = list->data.v1->V1Property;
cleanup:
hypervFreeObject(priv, (hypervObject *)list);
}
2017-04-04 22:26:08 +00:00
|
|
|
int hypervEnumAndPull(hypervPrivate *priv, hypervWqlQueryPtr wqlQuery,
|
2011-07-13 15:05:19 +00:00
|
|
|
hypervObject **list);
|
|
|
|
|
|
|
|
void hypervFreeObject(hypervPrivate *priv, hypervObject *object);
|
|
|
|
|
|
|
|
|
2017-06-27 19:13:23 +00:00
|
|
|
/*
|
|
|
|
* Invoke
|
|
|
|
*/
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
HYPERV_SIMPLE_PARAM,
|
|
|
|
HYPERV_EPR_PARAM,
|
|
|
|
HYPERV_EMBEDDED_PARAM
|
|
|
|
} hypervStorageType;
|
|
|
|
|
|
|
|
struct _hypervSimpleParam {
|
|
|
|
const char *name;
|
|
|
|
const char *value;
|
|
|
|
};
|
|
|
|
typedef struct _hypervSimpleParam hypervSimpleParam;
|
|
|
|
|
|
|
|
struct _hypervEprParam {
|
|
|
|
const char *name;
|
|
|
|
virBufferPtr query;
|
2017-06-27 19:13:25 +00:00
|
|
|
hypervWmiClassInfoPtr info; /* info of the object this param represents */
|
2017-06-27 19:13:23 +00:00
|
|
|
};
|
|
|
|
typedef struct _hypervEprParam hypervEprParam;
|
|
|
|
|
|
|
|
struct _hypervEmbeddedParam {
|
|
|
|
const char *name;
|
2020-10-22 17:04:18 +00:00
|
|
|
GHashTable *table;
|
2017-06-27 19:13:25 +00:00
|
|
|
hypervWmiClassInfoPtr info; /* info of the object this param represents */
|
2017-06-27 19:13:23 +00:00
|
|
|
};
|
|
|
|
typedef struct _hypervEmbeddedParam hypervEmbeddedParam;
|
|
|
|
|
|
|
|
struct _hypervParam {
|
|
|
|
hypervStorageType type;
|
|
|
|
union {
|
|
|
|
hypervSimpleParam simple;
|
|
|
|
hypervEprParam epr;
|
|
|
|
hypervEmbeddedParam embedded;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
typedef struct _hypervParam hypervParam;
|
|
|
|
typedef hypervParam *hypervParamPtr;
|
|
|
|
|
|
|
|
struct _hypervInvokeParamsList {
|
|
|
|
const char *method;
|
|
|
|
const char *ns;
|
|
|
|
const char *resourceUri;
|
|
|
|
const char *selector;
|
|
|
|
hypervParamPtr params;
|
|
|
|
size_t nbParams;
|
|
|
|
size_t nbAvailParams;
|
|
|
|
};
|
|
|
|
typedef struct _hypervInvokeParamsList hypervInvokeParamsList;
|
|
|
|
typedef hypervInvokeParamsList *hypervInvokeParamsListPtr;
|
|
|
|
|
|
|
|
|
2020-11-09 08:43:08 +00:00
|
|
|
hypervInvokeParamsListPtr hypervCreateInvokeParamsList(const char *method,
|
2020-10-21 12:53:12 +00:00
|
|
|
const char *selector,
|
2020-11-09 08:43:10 +00:00
|
|
|
hypervWmiClassInfoPtr obj);
|
2017-06-27 19:13:23 +00:00
|
|
|
|
|
|
|
void hypervFreeInvokeParams(hypervInvokeParamsListPtr params);
|
2020-10-21 08:46:05 +00:00
|
|
|
G_DEFINE_AUTOPTR_CLEANUP_FUNC(hypervInvokeParamsList, hypervFreeInvokeParams);
|
2017-06-27 19:13:23 +00:00
|
|
|
|
|
|
|
int hypervAddSimpleParam(hypervInvokeParamsListPtr params, const char *name,
|
2020-10-21 12:53:12 +00:00
|
|
|
const char *value);
|
2017-06-27 19:13:23 +00:00
|
|
|
|
2020-11-09 08:43:08 +00:00
|
|
|
int hypervAddEprParam(hypervInvokeParamsListPtr params,
|
|
|
|
const char *name,
|
|
|
|
virBufferPtr query,
|
2020-11-09 08:43:10 +00:00
|
|
|
hypervWmiClassInfoPtr eprInfo);
|
2017-06-27 19:13:23 +00:00
|
|
|
|
2020-11-09 08:43:10 +00:00
|
|
|
GHashTable *hypervCreateEmbeddedParam(hypervWmiClassInfoPtr info);
|
2017-06-27 19:13:23 +00:00
|
|
|
|
2020-10-22 17:04:18 +00:00
|
|
|
int hypervSetEmbeddedProperty(GHashTable *table,
|
2020-10-19 09:55:10 +00:00
|
|
|
const char *name,
|
|
|
|
const char *value);
|
2017-06-27 19:13:23 +00:00
|
|
|
|
2020-10-15 13:31:51 +00:00
|
|
|
int hypervAddEmbeddedParam(hypervInvokeParamsListPtr params,
|
|
|
|
const char *name,
|
2020-10-22 17:04:18 +00:00
|
|
|
GHashTable **table,
|
2020-11-09 08:43:10 +00:00
|
|
|
hypervWmiClassInfoPtr info);
|
2011-07-13 15:05:19 +00:00
|
|
|
|
2020-10-22 17:04:18 +00:00
|
|
|
void hypervFreeEmbeddedParam(GHashTable *p);
|
2017-06-27 19:13:25 +00:00
|
|
|
|
2020-10-15 13:53:27 +00:00
|
|
|
int hypervInvokeMethod(hypervPrivate *priv,
|
|
|
|
hypervInvokeParamsListPtr *paramsPtr,
|
|
|
|
WsXmlDocH *res);
|
2017-06-27 19:13:25 +00:00
|
|
|
|
2011-07-13 15:05:19 +00:00
|
|
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
|
|
* CIM/Msvm_ReturnCode
|
|
|
|
*/
|
|
|
|
|
|
|
|
enum _CIM_ReturnCode {
|
|
|
|
CIM_RETURNCODE_COMPLETED_WITH_NO_ERROR = 0,
|
|
|
|
CIM_RETURNCODE_NOT_SUPPORTED = 1,
|
|
|
|
CIM_RETURNCODE_UNKNOWN_ERROR = 2,
|
|
|
|
CIM_RETURNCODE_CANNOT_COMPLETE_WITHIN_TIMEOUT_PERIOD = 3,
|
|
|
|
CIM_RETURNCODE_FAILED = 4,
|
|
|
|
CIM_RETURNCODE_INVALID_PARAMETER = 5,
|
|
|
|
CIM_RETURNCODE_IN_USE = 6,
|
|
|
|
CIM_RETURNCODE_TRANSITION_STARTED = 4096,
|
|
|
|
CIM_RETURNCODE_INVALID_STATE_TRANSITION = 4097,
|
|
|
|
CIM_RETURNCODE_TIMEOUT_PARAMETER_NOT_SUPPORTED = 4098,
|
|
|
|
CIM_RETURNCODE_BUSY = 4099,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum _Msvm_ReturnCode {
|
|
|
|
MSVM_RETURNCODE_FAILED = 32768,
|
|
|
|
MSVM_RETURNCODE_ACCESS_DENIED = 32769,
|
|
|
|
MSVM_RETURNCODE_NOT_SUPPORTED = 32770,
|
|
|
|
MSVM_RETURNCODE_STATUS_IS_UNKNOWN = 32771,
|
|
|
|
MSVM_RETURNCODE_TIMEOUT = 32772,
|
|
|
|
MSVM_RETURNCODE_INVALID_PARAMETER = 32773,
|
|
|
|
MSVM_RETURNCODE_SYSTEM_IS_IN_USE = 32774,
|
|
|
|
MSVM_RETURNCODE_INVALID_STATE_FOR_THIS_OPERATION = 32775,
|
|
|
|
MSVM_RETURNCODE_INCORRECT_DATA_TYPE = 32776,
|
|
|
|
MSVM_RETURNCODE_SYSTEM_IS_NOT_AVAILABLE = 32777,
|
|
|
|
MSVM_RETURNCODE_OUT_OF_MEMORY = 32778,
|
|
|
|
};
|
|
|
|
|
|
|
|
const char *hypervReturnCodeToString(int returnCode);
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-10-05 16:20:09 +00:00
|
|
|
int hypervGetWmiClassList(hypervPrivate *priv,
|
2020-11-09 08:43:10 +00:00
|
|
|
hypervWmiClassInfoPtr wmiInfo,
|
|
|
|
virBufferPtr query,
|
2020-10-05 16:20:09 +00:00
|
|
|
hypervObject **wmiClass);
|
hyperv: add support for Hyper-V 2012 and newer
This patch reworks the Hyper-V driver structs and the code generator
to provide seamless support for both Hyper-V 2008 and 2012 or newer.
This does not implement any new libvirt APIs, it just adapts existing
2008-only driver to also handle 2012 and newer by sharing as much
driver code as possible (currently it's all of it :-)). This is needed
to set the foundation before we can move forward with implementing the
rest of the driver APIs.
With the 2012 release, Microsoft introduced "v2" version of Msvm_* WMI
classes. Those are largely the same as "v1" (used in 2008) but have some
new properties as well as need different wsman request URIs. To
accomodate those differences, most of work went into the code generator
so that it's "aware" of possibility of multiple versions of the same WMI
class and produce C code accordingly.
To accomplish this the following changes were made:
* the abstract hypervObject struct's data member was changed to a union
that has "common", "v1" and "v2" members. Those are structs that
represent WMI classes that we get back from wsman response. The
"common" struct has members that are present in both "v1" and "v2"
which the driver API callbacks can use to read the data from in
version-independent manner (if version-specific member needs to be
accessed the driver can check priv->wmiVersion and read from "v1" or
"v2" as needed). Those structs are guaranteed to be memory aligned
by the code generator (see the align_property_members implementation
that takes care of that)
* the generator produces *_WmiInfo for each WMI class "family" that
holds an array of hypervWmiClassInfoPtr each providing information
as to which request URI to use for each "version" of given WMI class
as well as XmlSerializerInfo struct needed to unserilize WS-MAN
responsed into the data structs. The driver uses those to make proper
WS-MAN request depending on which version it's connected to.
* the generator no longer produces "helper" functions such as
hypervGetMsvmComputerSystemList as those were originally just simple
wrappers around hypervEnumAndPull, instead those were hand-written
now (to keep driver changes minimal). The reason is that we'll have
more code coming implementing missing libvirt APIs and surely code
patterns will emerge that would warrant more useful "utility" functions
like that.
* a hypervInitConnection was added to the driver which "detects"
Hyper-V version by testing simple wsman request using v2 then falling
back to v1, obviously if both fail, the we're erroring out.
To express how the above translates in code:
void
hypervImplementSomeLibvirtApi(virConnectPtr conn, ...)
{
hypervPrivate *priv = conn->privateData;
virBuffer query = VIR_BUFFER_INITIALIZER;
hypervWqlQuery wqlQuery = HYPERV_WQL_QUERY_INITIALIZER;
Msvm_ComputerSystem *list = NULL; /* typed hypervObject instance */
/* the WmiInfo struct has the data needed for wsman request and
* response handling for both v1 and v2 */
wqlQuery.info = Msvm_ComputerSystem_WmiInfo;
wqlQuery.query = &query;
virBufferAddLit(&query, "select * from Msvm_ComputerSystem");
if (hypervEnumAndPull(priv, &wqlQuery, (hypervObject **) &list) < 0) {
goto cleanup;
}
if (list == NULL) {
/* none found */
goto cleanup;
}
/* works with v1 and v2 */
char *vmName = list->data.common->Name;
/* access property that is in v2 only */
if (priv->wmiVersion == HYPERV_WMI_VERSION_V2)
char *foo = list->data.v2->V2Property;
else
char *foo = list->data.v1->V1Property;
cleanup:
hypervFreeObject(priv, (hypervObject *)list);
}
2017-04-04 22:26:08 +00:00
|
|
|
|
2020-11-03 00:22:04 +00:00
|
|
|
/**
|
|
|
|
* hypervGetWmiClass:
|
|
|
|
* @type: the type of the class being retrieved from WMI
|
|
|
|
* @class: double pointer where the class data will be stored
|
|
|
|
*
|
|
|
|
* Retrieve one or more classes from WMI.
|
|
|
|
*
|
|
|
|
* The following variables must exist in the caller:
|
|
|
|
* 1. hypervPrivate *priv
|
|
|
|
* 2. virBuffer query
|
|
|
|
*/
|
|
|
|
#define hypervGetWmiClass(type, class) \
|
|
|
|
hypervGetWmiClassList(priv, type ## _WmiInfo, &query, (hypervObject **)class)
|
|
|
|
|
2011-07-13 15:05:19 +00:00
|
|
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
|
|
* Msvm_ComputerSystem
|
|
|
|
*/
|
|
|
|
|
|
|
|
int hypervInvokeMsvmComputerSystemRequestStateChange(virDomainPtr domain,
|
|
|
|
int requestedState);
|
|
|
|
|
2020-10-21 12:53:12 +00:00
|
|
|
int hypervMsvmComputerSystemEnabledStateToDomainState(Msvm_ComputerSystem *computerSystem);
|
2011-07-13 15:05:19 +00:00
|
|
|
|
|
|
|
bool hypervIsMsvmComputerSystemActive(Msvm_ComputerSystem *computerSystem,
|
|
|
|
bool *in_transition);
|
|
|
|
|
|
|
|
int hypervMsvmComputerSystemToDomain(virConnectPtr conn,
|
|
|
|
Msvm_ComputerSystem *computerSystem,
|
|
|
|
virDomainPtr *domain);
|
|
|
|
|
2020-11-03 00:22:07 +00:00
|
|
|
int hypervMsvmComputerSystemFromUUID(hypervPrivate *priv, const char *uuid,
|
|
|
|
Msvm_ComputerSystem **computerSystem);
|
2020-10-22 16:38:23 +00:00
|
|
|
|
2011-07-13 15:05:19 +00:00
|
|
|
int hypervMsvmComputerSystemFromDomain(virDomainPtr domain,
|
|
|
|
Msvm_ComputerSystem **computerSystem);
|
2020-11-03 00:22:03 +00:00
|
|
|
|
|
|
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
|
|
* Generic "Get WMI class list" helpers
|
|
|
|
*/
|
|
|
|
|
|
|
|
int hypervGetMsvmVirtualSystemSettingDataFromUUID(hypervPrivate *priv,
|
|
|
|
const char *uuid_string,
|
|
|
|
Msvm_VirtualSystemSettingData **list);
|
|
|
|
|
2020-11-03 00:22:06 +00:00
|
|
|
int hypervGetProcessorSD(hypervPrivate *priv,
|
|
|
|
const char *id,
|
|
|
|
Msvm_ProcessorSettingData **data);
|
2020-11-03 00:22:05 +00:00
|
|
|
|
2020-11-03 00:22:06 +00:00
|
|
|
int hypervGetMemorySD(hypervPrivate *priv,
|
|
|
|
const char *vssd_instanceid,
|
|
|
|
Msvm_MemorySettingData **list);
|