]> xenbits.xensource.com Git - xen.git/commitdiff
libxl: libxl_domain_need_memory shouldn't modify b_info
authorWei Liu <wei.liu2@citrix.com>
Mon, 11 Jul 2016 11:03:51 +0000 (12:03 +0100)
committerWei Liu <wei.liu2@citrix.com>
Tue, 12 Jul 2016 11:49:41 +0000 (12:49 +0100)
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 <wei.liu2@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
tools/libxl/libxl.c
tools/libxl/libxl.h

index 0c34d6bdc56fe34d1f0ad03a35a534cf88242f5e..51d202f3d05e1c8919393d2bf1b96c5b3001f024 100644 (file)
@@ -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;
 
 }
index f2843fdc3583d5f71d020f87518c987121801e8d..48a43ce2c0d442a15a568f0cc4dfec6eb25903f7 100644 (file)
  */
 #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);