On 3/17/21 4:57 AM, Olaf Hering wrote:
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@xxxxxxxxx>
---
src/libxl/libxl_api.h | 29 +++++++++++++++++++++++++++++
src/libxl/libxl_domain.c | 4 ++--
src/libxl/libxl_driver.c | 2 +-
3 files changed, 32 insertions(+), 3 deletions(-)
diff --git a/src/libxl/libxl_api.h b/src/libxl/libxl_api.h
index c7174f5133..1507dbd38e 100644
--- a/src/libxl/libxl_api.h
+++ b/src/libxl/libxl_api.h
@@ -20,6 +20,7 @@
#pragma once
+#include <limits.h>
#include <libxl.h>
static inline int
@@ -188,3 +189,31 @@ Libxl_Send_Trigger(libxl_ctx *ctx,
return ret;
}
+
+static inline int
+Libxl_Set_Memory_Target(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)
+ {
Here
+ uint32_t val32 = target_memkb;
+
+ ret = libxl_set_memory_target(ctx, domid, val32, relative, enforce);
+ }
+#else
+ if (target_memkb < LLONG_MAX)
+ {
and here fail syntax-check
make: Entering directory '/home/jfehlig/virt/gitlab/libvirt/build/build-aux'
curly_braces_style
/home/jfehlig/virt/gitlab/libvirt/src/libxl/libxl_api.h-205- {
/home/jfehlig/virt/gitlab/libvirt/src/libxl/libxl_api.h-212- {
Regards,
Jim
+ 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 264a730c6c..0b0c3865fa 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,7 +1025,7 @@ 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,
+ if (Libxl_Set_Memory_Target(ctx, 0, target_mem,
/* relative */ 1, 0) < 0)
goto error;
diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index cf3a2d9775..97aed9949d 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -1695,7 +1695,7 @@ 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,
+ res = Libxl_Set_Memory_Target(cfg->ctx, vm->def->id, newmem, 0,
/* force */ 1);
virObjectLock(vm);
if (res < 0) {