All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yu Zhiguo <yuzg@cn.fujitsu.com>
To: Ian Jackson <Ian.Jackson@eu.citrix.com>,
	Stefano Stabellini <stefano.stabellini@eu.citrix.com>,
	"xen-devel@lists.xensource.com" <xen-devel@lists.xensource.com>
Subject: [PATCH 1/2] xl: Add command 'xl mem-max'
Date: Wed, 12 May 2010 14:26:59 +0800	[thread overview]
Message-ID: <4BEA4A33.5010107@cn.fujitsu.com> (raw)

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

Signed-off-by: Yu Zhiguo <yuzg@cn.fujitsu.com>

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",

                 reply	other threads:[~2010-05-12  6:26 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=4BEA4A33.5010107@cn.fujitsu.com \
    --to=yuzg@cn.fujitsu.com \
    --cc=Ian.Jackson@eu.citrix.com \
    --cc=stefano.stabellini@eu.citrix.com \
    --cc=xen-devel@lists.xensource.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.