libxl: add API wrapper for libxl_set_memory_target

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@aepfle.de>
Reviewed-by: Jim Fehlig <jfehlig@suse.com>
This commit is contained in:
Olaf Hering 2021-03-25 17:26:11 +01:00 committed by Jim Fehlig
parent 4d6e2c0f89
commit 8bc6a55f1b
3 changed files with 32 additions and 5 deletions

View File

@ -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;
}

View File

@ -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)

View File

@ -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,