Skip to contentSkip to conversation

libxl_set_memory_target: retain the same maxmem offset on top of the current target

PATCH Superseded Stefano Stabellini 1 participant 1 message Feb 26, 2015

v5 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

PATCH v5 1/1 libxl_set_memory_target: retain the same maxmem offset on top of the current target

In libxl_set_memory_target when setting the new maxmem, retain the same offset on top of the current target. In the future the offset will include memory allocated by QEMU for rom files.

---

Changes in v5:
- call libxl_dominfo_init;
- move libxl_dominfo_dispose call before returning to the caller;

Changes in v4:
- remove new_target_memkb <= 0 check.

Changes in v3:
- move call to libxl__uuid2string and libxl_dominfo_dispose earlier;
- error out if new_target_memkb <= 0.

Changes in v2:
- remove LIBXL_MAXMEM_CONSTANT from LIBXL__LOG_ERRNO.

---
 tools/libxl/libxl.c |   18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)
tools/libxl/libxl.c +10 -8
index b9a1941..7d42dc6 100644
@@ -4720,6 +4720,12 @@ int libxl_set_memory_target(libxl_ctx *ctx, uint32_t domid,
     char *uuid;
     xs_transaction_t t;
 
+    libxl_dominfo_init(&info);
+    if (libxl_domain_info(ctx, &ptr, domid) < 0)
+        goto out_no_transaction;
+
+    uuid = libxl__uuid2string(gc, ptr.uuid);
+
 retry_transaction:
     t = xs_transaction_start(ctx->xsh);
 
@@ -4795,13 +4801,12 @@ retry_transaction:
     }
 
     if (enforce) {
-        memorykb = new_target_memkb + videoram;
-        rc = xc_domain_setmaxmem(ctx->xch, domid, memorykb +
-                LIBXL_MAXMEM_CONSTANT);
+        memorykb = ptr.max_memkb - current_target_memkb + new_target_memkb;
+        rc = xc_domain_setmaxmem(ctx->xch, domid, memorykb);
         if (rc != 0) {
             LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR,
                     "xc_domain_setmaxmem domid=%d memkb=%d failed "
-                    "rc=%d\n", domid, memorykb + LIBXL_MAXMEM_CONSTANT, rc);
+                    "rc=%d\n", domid, memorykb, rc);
             abort_transaction = 1;
             goto out;
         }
@@ -4826,12 +4831,8 @@ retry_transaction:
         goto out;
     }
 
-    libxl_dominfo_init(&ptr);
-    xcinfo2xlinfo(ctx, &info, &ptr);
-    uuid = libxl__uuid2string(gc, ptr.uuid);
     libxl__xs_write(gc, t, libxl__sprintf(gc, "/vm/%s/memory", uuid),
             "%"PRIu32, new_target_memkb / 1024);
-    libxl_dominfo_dispose(&ptr);
 
 out:
     if (!xs_transaction_end(ctx->xsh, t, abort_transaction)
@@ -4840,6 +4841,7 @@ out:
             goto retry_transaction;
 
 out_no_transaction:
+    libxl_dominfo_dispose(&ptr);
     GC_FREE;
     return rc;
 }
Signature · 1 line
1.7.10.4