aboutsummaryrefslogtreecommitdiffstats
path: root/tools/libxl
diff options
context:
space:
mode:
authorDavid Vrabel <david.vrabel@citrix.com>2013-04-04 17:21:12 +0000
committerIan Jackson <Ian.Jackson@eu.citrix.com>2013-04-08 17:04:52 +0100
commit48f4af18b3e1e36bf0eda793455ecaea9a316c65 (patch)
tree556900b9852da7b71432178ef968b81b65c0d660 /tools/libxl
parentb4932b39319229291ff019ba23cab465988e02d8 (diff)
downloadxen-48f4af18b3e1e36bf0eda793455ecaea9a316c65.tar.gz
xen-48f4af18b3e1e36bf0eda793455ecaea9a316c65.tar.bz2
xen-48f4af18b3e1e36bf0eda793455ecaea9a316c65.zip
xl: extend autoballoon xl.conf option with an "auto" option
autoballoon=1 is not recommened if dom0_mem was used to reduce the amount of dom0 memory. Instead of requiring users to change xl.conf if they do this, extend the autoballoon option with a new choice: "auto". With autoballoon="auto", autoballooning will be disabled if dom0_mem was used on the Xen command line. For consistency, accept "on" and "off" as valid autoballoon options (1 and 0 are still accepted). The default remains "on" for now. Signed-off-by: David Vrabel <david.vrabel@citrix.com> Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
Diffstat (limited to 'tools/libxl')
-rw-r--r--tools/libxl/xl.c36
1 files changed, 34 insertions, 2 deletions
diff --git a/tools/libxl/xl.c b/tools/libxl/xl.c
index 4c598dbbad..ac41fcd294 100644
--- a/tools/libxl/xl.c
+++ b/tools/libxl/xl.c
@@ -26,6 +26,7 @@
#include <fcntl.h>
#include <ctype.h>
#include <inttypes.h>
+#include <regex.h>
#include "libxl.h"
#include "libxl_utils.h"
@@ -48,6 +49,29 @@ enum output_format default_output_format = OUTPUT_FORMAT_JSON;
static xentoollog_level minmsglevel = XTL_PROGRESS;
+/* Get autoballoon option based on presence of dom0_mem Xen command
+ line option. */
+static int auto_autoballoon(void)
+{
+ const libxl_version_info *info;
+ regex_t regex;
+ int ret;
+
+ info = libxl_get_version_info(ctx);
+ if (!info)
+ return 1; /* default to on */
+
+ ret = regcomp(&regex,
+ "(^| )dom0_mem=((|min:|max:)[0-9]+[bBkKmMgG]?,?)+($| )",
+ REG_NOSUB | REG_EXTENDED);
+ if (ret)
+ return 1;
+
+ ret = regexec(&regex, info->commandline, 0, NULL, 0);
+ regfree(&regex);
+ return ret == REG_NOMATCH;
+}
+
static void parse_global_config(const char *configfile,
const char *configfile_data,
int configfile_len)
@@ -69,8 +93,16 @@ static void parse_global_config(const char *configfile,
exit(1);
}
- if (!xlu_cfg_get_long (config, "autoballoon", &l, 0))
- autoballoon = l;
+ if (!xlu_cfg_get_string(config, "autoballoon", &buf, 0)) {
+ if (!strcmp(buf, "on") || !strcmp(buf, "1"))
+ autoballoon = 1;
+ else if (!strcmp(buf, "off") || !strcmp(buf, "0"))
+ autoballoon = 0;
+ else if (!strcmp(buf, "auto"))
+ autoballoon = auto_autoballoon();
+ else
+ fprintf(stderr, "invalid autoballoon option");
+ }
if (!xlu_cfg_get_long (config, "run_hotplug_scripts", &l, 0))
run_hotplug_scripts = l;