From: Wei Liu Date: Mon, 11 Jul 2016 11:03:51 +0000 (+0100) Subject: libxl: libxl_domain_need_memory shouldn't modify b_info X-Git-Tag: archive/raspbian/4.8.0-1+rpi1~1^2~807 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=b173750d2bc2c9b57fda9750309824296bdea932;p=xen.git libxl: libxl_domain_need_memory shouldn't modify b_info This function is used to return the memory needed for a guest. It's not in a position to modify the b_info passed in (note the _setdefault function). Constify the passed in b_info, use a copy to do the calculation. Mark the change in API in libxl.h. Signed-off-by: Wei Liu Acked-by: Ian Jackson --- diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c index 0c34d6bdc5..51d202f3d0 100644 --- a/tools/libxl/libxl.c +++ b/tools/libxl/libxl.c @@ -5121,12 +5121,17 @@ int libxl_get_memory_target(libxl_ctx *ctx, uint32_t domid, return rc; } -int libxl_domain_need_memory(libxl_ctx *ctx, libxl_domain_build_info *b_info, +int libxl_domain_need_memory(libxl_ctx *ctx, + const libxl_domain_build_info *b_info_in, uint32_t *need_memkb) { GC_INIT(ctx); + libxl_domain_build_info b_info[1]; int rc; + libxl_domain_build_info_init(b_info); + libxl_domain_build_info_copy(ctx, b_info, b_info_in); + rc = libxl__domain_build_info_setdefault(gc, b_info); if (rc) goto out; @@ -5149,6 +5154,7 @@ int libxl_domain_need_memory(libxl_ctx *ctx, libxl_domain_build_info *b_info, rc = 0; out: GC_FREE; + libxl_domain_build_info_dispose(b_info); return rc; } diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h index f2843fdc35..48a43ce2c0 100644 --- a/tools/libxl/libxl.h +++ b/tools/libxl/libxl.h @@ -74,6 +74,13 @@ */ #define LIBXL_HAVE_CONST_COPY_AND_LENGTH_FUNCTIONS 1 +/* LIBXL_HAVE_DOMAIN_NEED_MEMORY_CONST_B_INFO + * + * If this is defined, libxl_domain_need_memory no longer modifies + * the b_info paseed in. + */ +#define LIBXL_HAVE_DOMAIN_NEED_MEMORY_CONST_B_INFO 1 + /* LIBXL_HAVE_VNUMA * * If this is defined the type libxl_vnode_info exists, and a @@ -1383,7 +1390,8 @@ int libxl_get_memory_target(libxl_ctx *ctx, uint32_t domid, uint32_t *out_target * existing programs which use them in roughly the same way as libxl. */ /* how much free memory in the system a domain needs to be built */ -int libxl_domain_need_memory(libxl_ctx *ctx, libxl_domain_build_info *b_info, +int libxl_domain_need_memory(libxl_ctx *ctx, + const libxl_domain_build_info *b_info_in, uint32_t *need_memkb); /* how much free memory is available in the system */ int libxl_get_free_memory(libxl_ctx *ctx, uint32_t *memkb);