Upcoming changes will use different LIBXL_API_VERSION variants.
Prepare libxl_set_memory_target, which changed the storage size of
parameter "target_memkb" in Xen 4.8.
No functional change intended.
Signed-off-by: Olaf Hering <olaf(a)aepfle.de>
---
src/libxl/libxl_api_wrapper.h | 27 +++++++++++++++++++++++++++
src/libxl/libxl_domain.c | 6 +++---
src/libxl/libxl_driver.c | 4 ++--
3 files changed, 32 insertions(+), 5 deletions(-)
diff --git a/src/libxl/libxl_api_wrapper.h b/src/libxl/libxl_api_wrapper.h
index 26c2215cb7..a9627f7983 100644
--- a/src/libxl/libxl_api_wrapper.h
+++ b/src/libxl/libxl_api_wrapper.h
@@ -20,6 +20,7 @@
#pragma once
+#include <limits.h>
#include <libxl.h>
static inline int
@@ -188,3 +189,29 @@ libxlSendTriggerWrapper(libxl_ctx *ctx,
return ret;
}
+
+static inline int
+libxlSetMemoryTargetWrapper(libxl_ctx *ctx,
+ uint32_t domid,
+ uint64_t target_memkb,
+ int relative,
+ int enforce)
+{
+ int ret = -1;
+
+ /* Technically this guard could be LIBXL_HAVE_MEMKB_64BITS */
+#if LIBXL_API_VERSION < 0x040800
+ if (target_memkb < UINT_MAX) {
+ uint32_t val32 = target_memkb;
+
+ ret = libxl_set_memory_target(ctx, domid, val32, relative, enforce);
+ }
+#else
+ if (target_memkb < LLONG_MAX) {
+ int64_t val64 = target_memkb;
+ ret = libxl_set_memory_target(ctx, domid, val64, relative, enforce);
+ }
+#endif
+
+ return ret;
+}
diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c
index ac613b96b9..7ffafb9023 100644
--- a/src/libxl/libxl_domain.c
+++ b/src/libxl/libxl_domain.c
@@ -1010,7 +1010,7 @@ libxlDomainFreeMem(libxl_ctx *ctx, libxl_domain_config *d_config)
{
uint64_t needed_mem;
uint64_t free_mem;
- int32_t target_mem;
+ uint64_t target_mem;
int tries = 3;
int wait_secs = 10;
@@ -1025,8 +1025,8 @@ libxlDomainFreeMem(libxl_ctx *ctx, libxl_domain_config *d_config)
return 0;
target_mem = free_mem - needed_mem;
- if (libxl_set_memory_target(ctx, 0, target_mem,
- /* relative */ 1, 0) < 0)
+ if (libxlSetMemoryTargetWrapper(ctx, 0, target_mem,
+ /* relative */ 1, 0) < 0)
goto error;
if (libxl_wait_for_memory_target(ctx, 0, wait_secs) < 0)
diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index 18098734fc..f130790484 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -1695,8 +1695,8 @@ libxlDomainSetMemoryFlags(virDomainPtr dom, unsigned long newmem,
/* Unlock virDomainObj while ballooning memory */
virObjectUnlock(vm);
- res = libxl_set_memory_target(cfg->ctx, vm->def->id, newmem, 0,
- /* force */ 1);
+ res = libxlSetMemoryTargetWrapper(cfg->ctx, vm->def->id, newmem, 0,
+ /* force */ 1);
virObjectLock(vm);
if (res < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,