xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Wei Liu <wei.liu2@citrix.com>
To: Xen-devel <xen-devel@lists.xenproject.org>
Cc: Ian Jackson <ian.jackson@eu.citrix.com>, Wei Liu <wei.liu2@citrix.com>
Subject: [PATCH v3 1/5] libxl: libxl_domain_need_memory shouldn't modify b_info
Date: Wed, 15 Jun 2016 10:31:38 +0100	[thread overview]
Message-ID: <1465983102-19308-2-git-send-email-wei.liu2@citrix.com> (raw)
In-Reply-To: <1465983102-19308-1-git-send-email-wei.liu2@citrix.com>

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@citrix.com>
---
Cc: Ian Jackson <ian.jackson@eu.citrix.com>

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@lists.xen.org
http://lists.xen.org/xen-devel

  reply	other threads:[~2016-06-15  9:31 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-15  9:31 [PATCH v3 0/5] libxl: libxl: update available vcpus map in retrieve configuration function Wei Liu
2016-06-15  9:31 ` Wei Liu [this message]
2016-06-15 13:31   ` [PATCH v3 1/5] libxl: libxl_domain_need_memory shouldn't modify b_info Dario Faggioli
2016-06-15 13:38     ` Wei Liu
2016-07-08 17:35   ` Ian Jackson
2016-07-11 11:03     ` Wei Liu
2016-06-15  9:31 ` [PATCH v3 2/5] libxl: factor out libxl__get_device_modlel_version Wei Liu
2016-06-15 13:27   ` Dario Faggioli
2016-06-15 17:04   ` Anthony PERARD
2016-07-08 17:37   ` Ian Jackson
2016-06-15  9:31 ` [PATCH v3 3/5] libxl: introduce libxl__qmp_query_cpus Wei Liu
2016-06-15 13:26   ` Dario Faggioli
2016-06-15 16:48   ` Anthony PERARD
2016-07-08 17:45   ` Ian Jackson
2016-06-15  9:31 ` [PATCH v3 4/5] libxl: update vcpus bitmap in retrieved guest config Wei Liu
2016-06-15 17:20   ` Anthony PERARD
2016-07-08 17:44   ` Ian Jackson
2016-07-11 11:31     ` Wei Liu
2016-07-11 14:59       ` Wei Liu
2016-06-15  9:31 ` [PATCH v3 5/5] libxl: only issue cpu-add call to QEMU for not present CPU Wei Liu
2016-07-08 17:48   ` Ian Jackson
2016-07-11 11:32     ` Wei Liu
2016-07-02 10:22 ` [PATCH v3 0/5] libxl: libxl: update available vcpus map in retrieve configuration function Wei Liu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1465983102-19308-2-git-send-email-wei.liu2@citrix.com \
    --to=wei.liu2@citrix.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).