Commit b72bd8ef authored by Daniel P. Berrange's avatar Daniel P. Berrange

Add compat for 1.2.5 release

Signed-off-by: default avatarDaniel P. Berrange <[email protected]>
parent 659066f8
......@@ -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 1.2.6 onwards, through conditional compilation of newer APIs.
from 1.2.5 onwards, through conditional compilation of newer APIs.
## Documentation
......
......@@ -1525,6 +1525,9 @@ func (c *Connect) GetFreeMemory() (uint64, error) {
}
func (c *Connect) GetFreePages(pageSizes []uint64, startCell int, maxCells uint, flags uint32) ([]uint64, error) {
if C.LIBVIR_VERSION_NUMBER < 1002006 {
return []uint64{}, GetNotImplementedError()
}
cpageSizes := make([]C.uint, len(pageSizes))
ccounts := make([]C.ulonglong, len(pageSizes)*int(maxCells))
......@@ -1532,7 +1535,7 @@ func (c *Connect) GetFreePages(pageSizes []uint64, startCell int, maxCells uint,
cpageSizes[i] = C.uint(pageSizes[i])
}
ret := C.virNodeGetFreePages(c.ptr, C.uint(len(pageSizes)), (*C.uint)(unsafe.Pointer(&cpageSizes)), C.int(startCell),
ret := C.virNodeGetFreePagesCompat(c.ptr, C.uint(len(pageSizes)), (*C.uint)(unsafe.Pointer(&cpageSizes)), C.int(startCell),
C.uint(maxCells), (*C.ulonglong)(unsafe.Pointer(&ccounts)), C.uint(flags))
if ret == -1 {
return []uint64{}, GetLastError()
......
......@@ -6,6 +6,21 @@ package libvirt
#include <assert.h>
#include "connect_compat.h"
int virNodeGetFreePagesCompat(virConnectPtr conn,
unsigned int npages,
unsigned int *pages,
int startcell,
unsigned int cellcount,
unsigned long long *counts,
unsigned int flags)
{
#if LIBVIR_VERSION_NUMBER < 1002006
assert(0); // Caller should have checked version
#else
return virNodeGetFreePages(conn, npages, pages, startcell, cellcount, counts, flags);
#endif
}
char * virConnectGetDomainCapabilitiesCompat(virConnectPtr conn,
const char *emulatorbin,
const char *arch,
......
#ifndef LIBVIRT_GO_CONNECT_COMPAT_H_
#define LIBVIRT_GO_CONNECT_COMPAT_H_
/* 1.2.6 */
#ifndef VIR_CONNECT_COMPARE_CPU_FAIL_INCOMPATIBLE
#define VIR_CONNECT_COMPARE_CPU_FAIL_INCOMPATIBLE 1 << 0
#endif
int virNodeGetFreePagesCompat(virConnectPtr conn,
unsigned int npages,
unsigned int *pages,
int startcell,
unsigned int cellcount,
unsigned long long *counts,
unsigned int flags);
/* 1.2.7 */
char * virConnectGetDomainCapabilitiesCompat(virConnectPtr conn,
......
#ifndef LIBVIRT_GO_DOMAIN_COMPAT_H__
#define LIBVIRT_GO_ERROR_COMPAT_H__
/* 1.2.6 */
#ifndef VIR_DOMAIN_BLOCK_COMMIT_ACTIVE
#define VIR_DOMAIN_BLOCK_COMMIT_ACTIVE 1 << 2
#endif
#ifndef VIR_DOMAIN_BLOCK_JOB_TYPE_ACTIVE_COMMIT
#define VIR_DOMAIN_BLOCK_JOB_TYPE_ACTIVE_COMMIT 4
#endif
#ifndef VIR_DOMAIN_EVENT_ID_BLOCK_JOB_2
#define VIR_DOMAIN_EVENT_ID_BLOCK_JOB_2 16
#endif
/* 1.2.7 */
#ifndef VIR_DOMAIN_BLOCK_COMMIT_RELATIVE
......
#ifndef LIBVIRT_GO_ERROR_COMPAT_H__
#define LIBVIRT_GO_ERROR_COMPAT_H__
/* 1.2.6 */
#ifndef VIR_ERR_CPU_INCOMPATIBLE
#define VIR_ERR_CPU_INCOMPATIBLE 91
#endif
/* 1.2.9 */
#ifndef VIR_FROM_POLKIT
......
......@@ -5,6 +5,7 @@ package libvirt
#include <libvirt/libvirt.h>
#include <libvirt/virterror.h>
#include <stdlib.h>
#include "network_compat.h"
*/
import "C"
......@@ -236,8 +237,11 @@ func (n *Network) Update(cmd NetworkUpdateCommand, section NetworkUpdateSection,
}
func (n *Network) GetDHCPLeases() ([]NetworkDHCPLease, error) {
if C.LIBVIR_VERSION_NUMBER < 1002006 {
return []NetworkDHCPLease{}, GetNotImplementedError()
}
var cLeases *C.virNetworkDHCPLeasePtr
numLeases := C.virNetworkGetDHCPLeases(n.ptr, nil, (**C.virNetworkDHCPLeasePtr)(&cLeases), C.uint(0))
numLeases := C.virNetworkGetDHCPLeasesCompat(n.ptr, nil, (**C.virNetworkDHCPLeasePtr)(&cLeases), C.uint(0))
if numLeases == -1 {
return nil, GetLastError()
}
......@@ -260,7 +264,7 @@ func (n *Network) GetDHCPLeases() ([]NetworkDHCPLease, error) {
Hostname: C.GoString(clease.hostname),
Clientid: C.GoString(clease.clientid),
})
C.virNetworkDHCPLeaseFree(clease)
C.virNetworkDHCPLeaseFreeCompat(clease)
}
C.free(unsafe.Pointer(cLeases))
return leases, nil
......
package libvirt
/*
#cgo pkg-config: libvirt
#include <libvirt/libvirt.h>
#include <assert.h>
#include "network_compat.h"
void virNetworkDHCPLeaseFreeCompat(virNetworkDHCPLeasePtr lease)
{
}
int virNetworkGetDHCPLeasesCompat(virNetworkPtr network,
const char *mac,
virNetworkDHCPLeasePtr **leases,
unsigned int flags)
{
#if LIBVIR_VERSION_NUMBER < 1002006
assert(0); // Caller should have checked version
#else
return virNetworkGetDHCPLeases(network, mac, leases, flags);
#endif
}
*/
import "C"
#ifndef LIBVIRT_GO_NETWORK_COMPAT_H__
#define LIBVIRT_GO_NETWORK_COMPAT_H__
/* 1.2.5 */
#ifndef VIR_IP_ADDR_TYPE_IPV4
#define VIR_IP_ADDR_TYPE_IPV4 0
#endif
#ifndef VIR_IP_ADDR_TYPE_IPV6
#define VIR_IP_ADDR_TYPE_IPV6 1
#endif
#if LIBVIR_VERSION_NUMBER < 1002006
typedef struct _virNetworkDHCPLease virNetworkDHCPLease;
typedef virNetworkDHCPLease *virNetworkDHCPLeasePtr;
struct _virNetworkDHCPLease {
char *iface; /* Network interface name */
long long expirytime; /* Seconds since epoch */
int type; /* virIPAddrType */
char *mac; /* MAC address */
char *iaid; /* IAID */
char *ipaddr; /* IP address */
unsigned int prefix; /* IP address prefix */
char *hostname; /* Hostname */
char *clientid; /* Client ID or DUID */
};
#endif
void virNetworkDHCPLeaseFreeCompat(virNetworkDHCPLeasePtr lease);
int virNetworkGetDHCPLeasesCompat(virNetworkPtr network,
const char *mac,
virNetworkDHCPLeasePtr **leases,
unsigned int flags);
#endif /* LIBVIRT_GO_NETWORK_COMPAT_H__ */
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