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

[Xen-devel] [PATCH 1/2] xl: Add command 'xl mem-max'



Add subcommand 'xl mem-max', can be used to set static max memory

Signed-off-by: Yu Zhiguo <yuzg@xxxxxxxxxxxxxx>

diff -r d77a88f938c6 -r ee4820366b13 tools/libxl/libxl.c
--- a/tools/libxl/libxl.c       Tue May 11 14:05:28 2010 +0100
+++ b/tools/libxl/libxl.c       Wed May 12 22:11:43 2010 +0800
@@ -2346,6 +2346,39 @@
     return 0;
 }
 
+int libxl_domain_setmaxmem(struct libxl_ctx *ctx, uint32_t domid, uint32_t 
max_memkb)
+{
+    char *mem, *endptr;
+    uint32_t memorykb;
+    char *dompath = libxl_xs_get_dompath(ctx, domid);
+    int rc;
+
+    mem = libxl_xs_read(ctx, XBT_NULL, libxl_sprintf(ctx, "%s/memory/target", 
dompath));
+    if (!mem) {
+        XL_LOG_ERRNO(ctx, XL_LOG_ERROR, "cannot get memory info from 
%s/memory/target\n", dompath);
+        return 1;
+    }
+    memorykb = strtoul(mem, &endptr, 10);
+    if (*endptr != '\0') {
+        XL_LOG_ERRNO(ctx, XL_LOG_ERROR, "invalid memory %s from 
%s/memory/target\n", mem, dompath);
+        return 1;
+    }
+
+    if (max_memkb < memorykb) {
+        XL_LOG_ERRNO(ctx, XL_LOG_ERROR, "memory_static_max must be greater 
than or or equal to memory_dynamic_max\n");
+        return 1;
+    }
+
+    rc = xc_domain_setmaxmem(ctx->xch, domid, max_memkb);
+    if (rc != 0)
+        return rc;
+
+    if (domid != 0)
+        libxl_xs_write(ctx, XBT_NULL, libxl_sprintf(ctx, 
"%s/memory/static-max", dompath), "%lu", max_memkb);
+
+    return rc;
+}
+
 int libxl_set_memory_target(struct libxl_ctx *ctx, uint32_t domid, uint32_t 
target_memkb)
 {
     int rc = 0;
diff -r d77a88f938c6 -r ee4820366b13 tools/libxl/libxl.h
--- a/tools/libxl/libxl.h       Tue May 11 14:05:28 2010 +0100
+++ b/tools/libxl/libxl.h       Wed May 12 22:11:43 2010 +0800
@@ -339,6 +339,7 @@
 int libxl_domain_pause(struct libxl_ctx *ctx, uint32_t domid);
 int libxl_domain_unpause(struct libxl_ctx *ctx, uint32_t domid);
 
+int libxl_domain_setmaxmem(struct libxl_ctx *ctx, uint32_t domid, uint32_t 
target_memkb);
 int libxl_set_memory_target(struct libxl_ctx *ctx, uint32_t domid, uint32_t 
target_memkb);
 
 int libxl_console_attach(struct libxl_ctx *ctx, uint32_t domid, int cons_num);
diff -r d77a88f938c6 -r ee4820366b13 tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c  Tue May 11 14:05:28 2010 +0100
+++ b/tools/libxl/xl_cmdimpl.c  Wed May 12 22:11:43 2010 +0800
@@ -1187,6 +1187,59 @@
     }
 }
 
+int set_memory_max(char *p, char *mem)
+{
+    char *endptr;
+    uint32_t memorykb;
+    int rc;
+
+    find_domain(p);
+
+    memorykb = strtoul(mem, &endptr, 10);
+    if (*endptr != '\0') {
+        fprintf(stderr, "invalid memory size: %s\n", mem);
+        exit(3);
+    }
+
+    rc = libxl_domain_setmaxmem(&ctx, domid, memorykb);
+
+    return rc;
+}
+
+int main_memmax(int argc, char **argv)
+{
+    int opt = 0;
+    char *p = NULL, *mem;
+    int rc;
+
+    while ((opt = getopt(argc, argv, "h")) != -1) {
+        switch (opt) {
+        case 'h':
+            help("mem-max");
+            exit(0);
+        default:
+            fprintf(stderr, "option not supported\n");
+            break;
+        }
+    }
+    if (optind >= argc - 1) {
+        help("mem-max");
+        exit(2);
+    }
+
+    p = argv[optind];
+    mem = argv[optind + 1];
+
+    rc = set_memory_max(p, mem);
+    if (rc) {
+        fprintf(stderr, "cannot set domid %d static max memory to : %s\n", 
domid, mem);
+        exit(1);
+    }
+
+    printf("setting domid %d static max memory to : %s\n", domid, mem);
+    exit(0);
+}
+
 void set_memory_target(char *p, char *mem)
 {
     char *endptr;
diff -r d77a88f938c6 -r ee4820366b13 tools/libxl/xl_cmdimpl.h
--- a/tools/libxl/xl_cmdimpl.h  Tue May 11 14:05:28 2010 +0100
+++ b/tools/libxl/xl_cmdimpl.h  Wed May 12 22:11:43 2010 +0800
@@ -33,6 +33,7 @@
 int main_button_press(int argc, char **argv);
 int main_vcpupin(int argc, char **argv);
 int main_vcpuset(int argc, char **argv);
+int main_memmax(int argc, char **argv);
 int main_memset(int argc, char **argv);
 int main_sched_credit(int argc, char **argv);
 int main_domid(int argc, char **argv);
diff -r d77a88f938c6 -r ee4820366b13 tools/libxl/xl_cmdtable.c
--- a/tools/libxl/xl_cmdtable.c Tue May 11 14:05:28 2010 +0100
+++ b/tools/libxl/xl_cmdtable.c Wed May 12 22:11:43 2010 +0800
@@ -108,6 +108,11 @@
       "Eject a cdrom from a guest's cd drive",
       "<Domain> <VirtualDevice>",
     },
+    { "mem-max",
+      &main_memmax,
+      "Set the maximum amount reservation for a domain",
+      "<Domain> <MemKB>",
+    },
     { "mem-set",
       &main_memset,
       "Set the current memory usage for a domain",



_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel


 


Rackspace

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