# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1274179092 -3600
# Node ID 8abb8cd861fca907ce77345341a9632e3a5cbf17
# Parent 2c0c08b4770fe35375c72201b619a33b6867cf3c
xl: allow scaling suffix on memory sizes in mem-set and mem-max
Allow mem-set and mem-max to take 'b', 'k', 'm', 'g' and 't' as
scaling suffixes for bytes, kilobytes, mega, etc. An unadorned number
is still treated as kilobytes so no existing users should be affected.
Signed-off-by: Jeremy Fitzhardinge <jeremy.fitzhardinge@xxxxxxxxxx>
Signed-off-by: Keir Fraser <keir.fraser@xxxxxxxxxx>
---
tools/libxl/xl_cmdimpl.c | 47 +++++++++++++++++++++++++++++++++++++---------
tools/libxl/xl_cmdtable.c | 8 +++++--
2 files changed, 44 insertions(+), 11 deletions(-)
diff -r 2c0c08b4770f -r 8abb8cd861fc tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c Tue May 18 11:24:04 2010 +0100
+++ b/tools/libxl/xl_cmdimpl.c Tue May 18 11:38:12 2010 +0100
@@ -1200,16 +1200,45 @@ void help(char *command)
}
}
+static int64_t parse_mem_size_kb(char *mem)
+{
+ char *endptr;
+ int64_t kbytes;
+
+ kbytes = strtoll(mem, &endptr, 10);
+
+ if (strlen(endptr) > 1)
+ return -1;
+
+ switch (tolower(*endptr)) {
+ case 't':
+ kbytes <<= 10;
+ case 'g':
+ kbytes <<= 10;
+ case 'm':
+ kbytes <<= 10;
+ case '\0':
+ case 'k':
+ break;
+ case 'b':
+ kbytes >>= 10;
+ break;
+ default:
+ return -1;
+ }
+
+ return kbytes;
+}
+
int set_memory_max(char *p, char *mem)
{
- char *endptr;
- uint32_t memorykb;
+ int64_t memorykb;
int rc;
find_domain(p);
- memorykb = strtoul(mem, &endptr, 10);
- if (*endptr != '\0') {
+ memorykb = parse_mem_size_kb(mem);
+ if (memorykb == -1) {
fprintf(stderr, "invalid memory size: %s\n", mem);
exit(3);
}
@@ -1255,17 +1284,17 @@ int main_memmax(int argc, char **argv)
void set_memory_target(char *p, char *mem)
{
- char *endptr;
- uint32_t memorykb;
+ long long int memorykb;
find_domain(p);
- memorykb = strtoul(mem, &endptr, 10);
- if (*endptr != '\0') {
+ memorykb = parse_mem_size_kb(mem);
+ if (memorykb == -1) {
fprintf(stderr, "invalid memory size: %s\n", mem);
exit(3);
}
- printf("setting domid %d memory to : %d\n", domid, memorykb);
+
+ printf("setting domid %d memory to : %lld\n", domid, memorykb);
libxl_set_memory_target(&ctx, domid, memorykb, /* enforce */ 1);
}
diff -r 2c0c08b4770f -r 8abb8cd861fc tools/libxl/xl_cmdtable.c
--- a/tools/libxl/xl_cmdtable.c Tue May 18 11:24:04 2010 +0100
+++ b/tools/libxl/xl_cmdtable.c Tue May 18 11:38:12 2010 +0100
@@ -110,12 +110,16 @@ struct cmd_spec cmd_table[] = {
},
{ "mem-max",
&main_memmax,
- "Set the maximum amount reservation for a domain",
+ "Set the maximum amount reservation for a domain.\n"
+ "Units default to kilobytes, but can be suffixed with\n"
+ "'b' (bytes), 'k' (KB), 'm' (MB), 'g' (GB) or 't' (TB)",
"<Domain> <MemKB>",
},
{ "mem-set",
&main_memset,
- "Set the current memory usage for a domain",
+ "Set the current memory usage for a domain.\n"
+ "Units default to kilobytes, but can be suffixed with\n"
+ "'b' (bytes), 'k' (KB), 'm' (MB), 'g' (GB) or 't' (TB)",
"<Domain> <MemKB>",
},
{ "button-press",
_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog
|