[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH v3 1/5] 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).

Use a copy of b_info to do the calculation. Define a macro to mark the
change in API.

Signed-off-by: Wei Liu <wei.liu2@xxxxxxxxxx>
---
Cc: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>

v3: new
Any suggestion on the macro name?

This patch should not be backported because it changes API behaviour.
---
 tools/libxl/libxl.c | 17 +++++++++++------
 tools/libxl/libxl.h |  7 +++++++
 2 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c
index 5ec4c80..65af9ee 100644
--- a/tools/libxl/libxl.c
+++ b/tools/libxl/libxl.c
@@ -5123,20 +5123,24 @@ int libxl_domain_need_memory(libxl_ctx *ctx, 
libxl_domain_build_info *b_info,
                              uint32_t *need_memkb)
 {
     GC_INIT(ctx);
+    libxl_domain_build_info tmp;
     int rc;
 
-    rc = libxl__domain_build_info_setdefault(gc, b_info);
+    libxl_domain_build_info_init(&tmp);
+    libxl_domain_build_info_copy(ctx, &tmp, b_info);
+
+    rc = libxl__domain_build_info_setdefault(gc, &tmp);
     if (rc) goto out;
 
-    *need_memkb = b_info->target_memkb;
-    switch (b_info->type) {
+    *need_memkb = tmp.target_memkb;
+    switch (tmp.type) {
     case LIBXL_DOMAIN_TYPE_HVM:
-        *need_memkb += b_info->shadow_memkb + LIBXL_HVM_EXTRA_MEMORY;
-        if (libxl_defbool_val(b_info->device_model_stubdomain))
+        *need_memkb += tmp.shadow_memkb + LIBXL_HVM_EXTRA_MEMORY;
+        if (libxl_defbool_val(tmp.device_model_stubdomain))
             *need_memkb += 32 * 1024;
         break;
     case LIBXL_DOMAIN_TYPE_PV:
-        *need_memkb += b_info->shadow_memkb + LIBXL_PV_EXTRA_MEMORY;
+        *need_memkb += tmp.shadow_memkb + LIBXL_PV_EXTRA_MEMORY;
         break;
     default:
         rc = ERROR_INVAL;
@@ -5146,6 +5150,7 @@ int libxl_domain_need_memory(libxl_ctx *ctx, 
libxl_domain_build_info *b_info,
         *need_memkb += (2 * 1024) - (*need_memkb % (2 * 1024));
     rc = 0;
 out:
+    libxl_domain_build_info_dispose(&tmp);
     GC_FREE;
     return rc;
 
diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h
index 2c0f868..905852d 100644
--- a/tools/libxl/libxl.h
+++ b/tools/libxl/libxl.h
@@ -67,6 +67,13 @@
  * the same $(XEN_VERSION) (e.g. throughout a major release).
  */
 
+/* LIBXL_HAVE_DOMAIN_NEED_MEMORY_V2
+ *
+ * If this is defined, libxl_domain_need_memory no longer modifies
+ * passed in b_info.
+ */
+#define LIBXL_HAVE_DOMAIN_NEED_MEMORY_V2
+
 /* LIBXL_HAVE_VNUMA
  *
  * If this is defined the type libxl_vnode_info exists, and a
-- 
2.1.4


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.