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

[Xen-devel] [PATCH v4 2/4] libxl: Allow a guest to inform a host about its maximum supported memory size



Allow a guest to inform a host about its maximum
supported memory size. This gives a chance to ignore
limit established at boot by maxmem and usage of memory
hotplug infrustacture if the guest OS supports it.

Signed-off-by: Daniel Kiper <daniel.kiper@xxxxxxxxxx>
---
 tools/libxl/libxl.c        |   58 +++++++++++++++++++++++++++++++-------------
 tools/libxl/libxl_create.c |    3 +++
 2 files changed, 44 insertions(+), 17 deletions(-)

diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c
index 9906224..3427c13 100644
--- a/tools/libxl/libxl.c
+++ b/tools/libxl/libxl.c
@@ -3640,7 +3640,7 @@ int libxl_set_memory_target(libxl_ctx *ctx, uint32_t 
domid,
 {
     GC_INIT(ctx);
     int rc = 1, abort_transaction = 0;
-    uint32_t memorykb = 0, videoram = 0;
+    uint32_t guestkb, memorykb = 0, videoram = 0;
     uint32_t current_target_memkb = 0, new_target_memkb = 0;
     char *memmax, *endptr, *videoram_s = NULL, *target = NULL;
     char *dompath = libxl__xs_get_dompath(gc, domid);
@@ -3689,21 +3689,36 @@ retry_transaction:
     xcinfo2xlinfo(&info, &ptr);
 
     memmax = libxl__xs_read(gc, t, libxl__sprintf(gc,
-                "%s/memory/static-max", dompath));
-    if (!memmax) {
-        LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR,
-                "cannot get memory info from %s/memory/static-max\n",
-                dompath);
-        abort_transaction = 1;
-        goto out;
-    }
-    memorykb = strtoul(memmax, &endptr, 10);
-    if (*endptr != '\0') {
-        LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR,
-                "invalid max memory %s from %s/memory/static-max\n",
-                memmax, dompath);
-        abort_transaction = 1;
-        goto out;
+                "%s/memory/guest-max", dompath));
+
+    if (memmax) {
+        guestkb = strtoul(memmax, &endptr, 10);
+        if (*endptr != '\0')
+            guestkb = 0;
+    } else
+        guestkb = 0;
+
+    if (!guestkb) {
+        memmax = libxl__xs_read(gc, t, libxl__sprintf(gc,
+                    "%s/memory/static-max", dompath));
+
+        if (!memmax) {
+            LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR,
+                    "cannot get memory info from %s/memory/static-max\n",
+                    dompath);
+            abort_transaction = 1;
+            goto out;
+        }
+
+        memorykb = strtoul(memmax, &endptr, 10);
+
+        if (*endptr != '\0') {
+            LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR,
+                    "invalid max memory %s from %s/memory/static-max\n",
+                    memmax, dompath);
+            abort_transaction = 1;
+            goto out;
+        }
     }
 
     if (relative) {
@@ -3713,7 +3728,16 @@ retry_transaction:
             new_target_memkb = current_target_memkb + target_memkb;
     } else
         new_target_memkb = target_memkb;
-    if (new_target_memkb > memorykb) {
+
+    if (guestkb) {
+        if (new_target_memkb > guestkb) {
+            LIBXL__LOG(ctx, LIBXL__LOG_ERROR,
+                    "memory_dynamic_max must be less than or equal to"
+                    " memory_guest_max\n");
+            abort_transaction = 1;
+            goto out;
+        }
+    } else if (new_target_memkb > memorykb) {
         LIBXL__LOG(ctx, LIBXL__LOG_ERROR,
                 "memory_dynamic_max must be less than or equal to"
                 " memory_static_max\n");
diff --git a/tools/libxl/libxl_create.c b/tools/libxl/libxl_create.c
index cb9c822..f57cbe9 100644
--- a/tools/libxl/libxl_create.c
+++ b/tools/libxl/libxl_create.c
@@ -512,6 +512,9 @@ retry_transaction:
                     libxl__sprintf(gc, "%s/device/suspend/event-channel", 
dom_path),
                     rwperm, ARRAY_SIZE(rwperm));
     libxl__xs_mkdir(gc, t,
+                    libxl__sprintf(gc, "%s/memory/guest-max", dom_path),
+                    rwperm, ARRAY_SIZE(rwperm));
+    libxl__xs_mkdir(gc, t,
                     libxl__sprintf(gc, "%s/data", dom_path),
                     rwperm, ARRAY_SIZE(rwperm));
     if (info->type == LIBXL_DOMAIN_TYPE_HVM)
-- 
1.7.10.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®.