Commit 5d6be16c authored by Daniel P. Berrange's avatar Daniel P. Berrange

Add compat for 2.1.0 release

Signed-off-by: default avatarDaniel P. Berrange <[email protected]>
parent a5dc1bcc
......@@ -7,7 +7,7 @@ Make sure to have `libvirt-dev` package (or the development files otherwise some
## Version Support
The libvirt go package provides API coverage for libvirt versions
from 2.2.0 onwards, through conditional compilation of newer APIs.
from 2.1.0 onwards, through conditional compilation of newer APIs.
## Documentation
......
#ifndef LIBVIRT_GO_DOMAIN_COMPAT_H__
#define LIBVIRT_GO_ERROR_COMPAT_H__
/* 2.2.0 */
#ifndef VIR_DOMAIN_SCHEDULER_IOTHREAD_PERIOD
#define VIR_DOMAIN_SCHEDULER_IOTHREAD_PERIOD "iothread_period"
#endif
#ifndef VIR_DOMAIN_SCHEDULER_IOTHREAD_QUOTA
#define VIR_DOMAIN_SCHEDULER_IOTHREAD_QUOTA "iothread_quota"
#endif
#ifndef VIR_DOMAIN_TUNABLE_CPU_IOTHREAD_PERIOD
#define VIR_DOMAIN_TUNABLE_CPU_IOTHREAD_PERIOD "cputune.iothread_period"
#endif
#ifndef VIR_DOMAIN_TUNABLE_CPU_IOTHREAD_QUOTA
# define VIR_DOMAIN_TUNABLE_CPU_IOTHREAD_QUOTA "cputune.iothread_quota"
#endif
/* 2.3.0 */
#ifndef VIR_DOMAIN_UNDEFINE_KEEP_NVRAM
......
......@@ -564,3 +564,12 @@ func GetLastError() Error {
C.virResetError(err)
return virErr
}
func GetNotImplementedError() Error {
return Error{
Code: ERR_NO_SUPPORT,
Domain: FROM_NONE,
Message: "Function not implemented in this libvirt build",
Level: ERR_ERROR,
}
}
......@@ -5,6 +5,7 @@ package libvirt
#include <libvirt/libvirt.h>
#include <libvirt/virterror.h>
#include <stdlib.h>
#include "node_device_compat.h"
*/
import "C"
......
package libvirt
/*
#cgo pkg-config: libvirt
#include <libvirt/libvirt.h>
#include <assert.h>
#include "node_device_compat.h"
int virConnectNodeDeviceEventDeregisterAnyCompat(virConnectPtr conn,
int callbackID)
{
#if LIBVIR_VERSION_NUMBER < 2002000
assert(0); // Caller should have checked version
#else
return virConnectNodeDeviceEventDeregisterAny(conn, callbackID);
#endif
}
*/
import "C"
#ifndef LIBVIRT_GO_NODE_DEVICE_COMPAT_H__
#define LIBVIRT_GO_NODE_DEVICE_COMPAT_H__
/* 2.2.0 */
#ifndef VIR_NODE_DEVICE_EVENT_ID_LIFECYCLE
#define VIR_NODE_DEVICE_EVENT_ID_LIFECYCLE 0
#endif
#ifndef VIR_NODE_DEVICE_EVENT_ID_UPDATE
#define VIR_NODE_DEVICE_EVENT_ID_UPDATE 1
#endif
#ifndef VIR_NODE_DEVICE_EVENT_CREATED
#define VIR_NODE_DEVICE_EVENT_CREATED 0
#endif
#ifndef VIR_NODE_DEVICE_EVENT_DELETED
#define VIR_NODE_DEVICE_EVENT_DELETED 1
#endif
#if LIBVIR_VERSION_NUMBER < 2002000
typedef void (*virConnectNodeDeviceEventGenericCallback)(virConnectPtr conn,
virNodeDevicePtr dev,
void *opaque);
#endif
int virConnectNodeDeviceEventDeregisterAnyCompat(virConnectPtr conn,
int callbackID);
#endif /* LIBVIRT_GO_NODE_DEVICE_COMPAT_H__ */
......@@ -8,6 +8,7 @@ import (
/*
#cgo pkg-config: libvirt
#include <libvirt/libvirt.h>
#include "node_device_compat.h"
#include "node_device_events_cfuncs.h"
*/
import "C"
......@@ -59,6 +60,9 @@ func nodeDeviceEventGenericCallback(c C.virConnectPtr, d C.virNodeDevicePtr,
}
func (c *Connect) NodeDeviceEventLifecycleRegister(device *NodeDevice, callback NodeDeviceEventLifecycleCallback) (int, error) {
if C.LIBVIR_VERSION_NUMBER < 2002000 {
return 0, GetNotImplementedError()
}
goCallBackId := registerCallbackId(callback)
callbackPtr := unsafe.Pointer(C.nodeDeviceEventLifecycleCallback_cgo)
......@@ -97,8 +101,11 @@ func (c *Connect) NodeDeviceEventUpdateRegister(device *NodeDevice, callback Nod
}
func (c *Connect) NodeDeviceEventDeregister(callbackId int) error {
if C.LIBVIR_VERSION_NUMBER < 2002000 {
return GetNotImplementedError()
}
// Deregister the callback
if i := int(C.virConnectNodeDeviceEventDeregisterAny(c.ptr, C.int(callbackId))); i != 0 {
if i := int(C.virConnectNodeDeviceEventDeregisterAnyCompat(c.ptr, C.int(callbackId))); i != 0 {
return GetLastError()
}
return nil
......
......@@ -4,6 +4,8 @@ package libvirt
#cgo pkg-config: libvirt
#include <libvirt/libvirt.h>
#include <libvirt/virterror.h>
#include <assert.h>
#include "node_device_compat.h"
#include "node_device_events_cfuncs.h"
#include "callbacks_cfuncs.h"
#include <stdint.h>
......@@ -25,7 +27,11 @@ int virConnectNodeDeviceEventRegisterAny_cgo(virConnectPtr c, virNodeDevicePtr
int eventID, virConnectNodeDeviceEventGenericCallback cb,
long goCallbackId) {
void* id = (void*)goCallbackId;
#if LIBVIR_VERSION_NUMBER < 2002000
assert(0); // Caller should have checked version
#else
return virConnectNodeDeviceEventRegisterAny(c, d, eventID, cb, id, freeGoCallback_cgo);
#endif
}
*/
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment