mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
Avoid virGetVersion failure on specific driver support configurations
virGetVersion itself doesn't take a virConnectPtr, but in order to obtain the hypervisor version against which libvirt was compiled it is used in combination with virConnectGetType like this: hvType = virConnectGetType(conn) virGetVersion(&libVer, hvType, &typeVer) When virConnectGetType is called on a remote connection then the remote driver returns the type of the underlying driver on the server side, for example QEMU. Then virGetVersion compares hvType to a set of strings that depend on configure options and returns LIBVIR_VERSION_NUMBER in most cases. Now this fails in case libvirt on the client side is just compiled with the remote driver enabled only and the server side has the actual driver such as the QEMU driver. It just happens to work when the actual driver is enabled on client and server side. But that's not always true. I noticed this on FreeBSD: freebsd# virsh -c qemu+tcp://192.168.178.22/system version Compiled against library: libvir 0.9.2 error: failed to get the library version error: this function is not supported by the connection driver: virGetVersion This is not FreeBSD specific, happens on Windows as well due to the similar driver support configuration. The problem is that virConnectGetType returns QEMU, but virGetVersion on the client side only accepts Remote as hvType due to all other drivers being disabled on the client side. Daniel P. Berrange suggested to get rid of all the conditional code in virGetVersion, ignoring the hvType and always setting typeVer to LIBVIR_VERSION_NUMBER. virConnectGetVersion is supposed to be used to obtain the hypervisor version.
This commit is contained in:
parent
4bf1f33b7e
commit
b10bca09f9
@ -894,21 +894,25 @@ int virStateActive(void) {
|
|||||||
/**
|
/**
|
||||||
* virGetVersion:
|
* virGetVersion:
|
||||||
* @libVer: return value for the library version (OUT)
|
* @libVer: return value for the library version (OUT)
|
||||||
* @type: the type of connection/driver looked at, if @typeVer is not NULL
|
* @type: ignored; pass NULL
|
||||||
* @typeVer: optional return value for the version of the hypervisor (OUT)
|
* @typeVer: pass NULL; for historical purposes duplicates @libVer if
|
||||||
|
* non-NULL
|
||||||
*
|
*
|
||||||
* Provides information on up to two versions: @libVer is the version of the
|
* Provides version information. @libVer is the version of the
|
||||||
* library and will always be set unless an error occurs, in which case an
|
* library and will always be set unless an error occurs, in which case
|
||||||
* error code will be returned. If @typeVer is not NULL it will be set to the
|
* an error code will be returned. @typeVer exists for historical
|
||||||
* version of the hypervisor @type against which the library was compiled.
|
* compatibility; if it is not NULL it will duplicate @libVer (it was
|
||||||
* If @type is NULL, "Xen" is assumed, if @type is unknown or not
|
* originally intended to return hypervisor information based on @type,
|
||||||
* available, an error code will be returned and @typeVer will be 0.
|
* but due to the design of remote clients this is not reliable). To
|
||||||
|
* get the version of the running hypervisor use the virConnectGetVersion
|
||||||
|
* function instead. To get the libvirt library version used by a
|
||||||
|
* connection use the virConnectGetLibVersion instead.
|
||||||
*
|
*
|
||||||
* Returns -1 in case of failure, 0 otherwise, and values for @libVer and
|
* Returns -1 in case of failure, 0 otherwise, and values for @libVer and
|
||||||
* @typeVer have the format major * 1,000,000 + minor * 1,000 + release.
|
* @typeVer have the format major * 1,000,000 + minor * 1,000 + release.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
virGetVersion(unsigned long *libVer, const char *type,
|
virGetVersion(unsigned long *libVer, const char *type ATTRIBUTE_UNUSED,
|
||||||
unsigned long *typeVer)
|
unsigned long *typeVer)
|
||||||
{
|
{
|
||||||
VIR_DEBUG("libVir=%p, type=%s, typeVer=%p", libVer, type, typeVer);
|
VIR_DEBUG("libVir=%p, type=%s, typeVer=%p", libVer, type, typeVer);
|
||||||
@ -921,78 +925,9 @@ virGetVersion(unsigned long *libVer, const char *type,
|
|||||||
goto error;
|
goto error;
|
||||||
*libVer = LIBVIR_VERSION_NUMBER;
|
*libVer = LIBVIR_VERSION_NUMBER;
|
||||||
|
|
||||||
if (typeVer != NULL) {
|
if (typeVer != NULL)
|
||||||
if (type == NULL)
|
*typeVer = LIBVIR_VERSION_NUMBER;
|
||||||
type = "Xen";
|
|
||||||
|
|
||||||
/* FIXME: Add _proper_ type version handling for loadable driver modules... */
|
|
||||||
#ifdef WITH_DRIVER_MODULES
|
|
||||||
*typeVer = LIBVIR_VERSION_NUMBER;
|
|
||||||
#else
|
|
||||||
*typeVer = 0;
|
|
||||||
|
|
||||||
# if WITH_XEN
|
|
||||||
if (STRCASEEQ(type, "Xen"))
|
|
||||||
*typeVer = xenUnifiedVersion();
|
|
||||||
# endif
|
|
||||||
# if WITH_TEST
|
|
||||||
if (STRCASEEQ(type, "Test"))
|
|
||||||
*typeVer = LIBVIR_VERSION_NUMBER;
|
|
||||||
# endif
|
|
||||||
# if WITH_QEMU
|
|
||||||
if (STRCASEEQ(type, "QEMU"))
|
|
||||||
*typeVer = LIBVIR_VERSION_NUMBER;
|
|
||||||
# endif
|
|
||||||
# if WITH_LXC
|
|
||||||
if (STRCASEEQ(type, "LXC"))
|
|
||||||
*typeVer = LIBVIR_VERSION_NUMBER;
|
|
||||||
# endif
|
|
||||||
# if WITH_LIBXL
|
|
||||||
if (STRCASEEQ(type, "xenlight"))
|
|
||||||
*typeVer = LIBVIR_VERSION_NUMBER;
|
|
||||||
# endif
|
|
||||||
# if WITH_PHYP
|
|
||||||
if (STRCASEEQ(type, "phyp"))
|
|
||||||
*typeVer = LIBVIR_VERSION_NUMBER;
|
|
||||||
# endif
|
|
||||||
# if WITH_OPENVZ
|
|
||||||
if (STRCASEEQ(type, "OpenVZ"))
|
|
||||||
*typeVer = LIBVIR_VERSION_NUMBER;
|
|
||||||
# endif
|
|
||||||
# if WITH_VMWARE
|
|
||||||
if (STRCASEEQ(type, "VMware"))
|
|
||||||
*typeVer = LIBVIR_VERSION_NUMBER;
|
|
||||||
# endif
|
|
||||||
# if WITH_VBOX
|
|
||||||
if (STRCASEEQ(type, "VBox"))
|
|
||||||
*typeVer = LIBVIR_VERSION_NUMBER;
|
|
||||||
# endif
|
|
||||||
# if WITH_UML
|
|
||||||
if (STRCASEEQ(type, "UML"))
|
|
||||||
*typeVer = LIBVIR_VERSION_NUMBER;
|
|
||||||
# endif
|
|
||||||
# if WITH_ONE
|
|
||||||
if (STRCASEEQ(type, "ONE"))
|
|
||||||
*typeVer = LIBVIR_VERSION_NUMBER;
|
|
||||||
# endif
|
|
||||||
# if WITH_ESX
|
|
||||||
if (STRCASEEQ(type, "ESX"))
|
|
||||||
*typeVer = LIBVIR_VERSION_NUMBER;
|
|
||||||
# endif
|
|
||||||
# if WITH_XENAPI
|
|
||||||
if (STRCASEEQ(type, "XenAPI"))
|
|
||||||
*typeVer = LIBVIR_VERSION_NUMBER;
|
|
||||||
# endif
|
|
||||||
# if WITH_REMOTE
|
|
||||||
if (STRCASEEQ(type, "Remote"))
|
|
||||||
*typeVer = remoteVersion();
|
|
||||||
# endif
|
|
||||||
if (*typeVer == 0) {
|
|
||||||
virLibConnError(VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
#endif /* WITH_DRIVER_MODULES */
|
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user