xl: add a global configuration file
authorStefano Stabellini <stefano.stabellini@eu.citrix.com>
Wed, 22 Sep 2010 16:42:01 +0000 (17:42 +0100)
committerStefano Stabellini <stefano.stabellini@eu.citrix.com>
Wed, 22 Sep 2010 16:42:01 +0000 (17:42 +0100)
Add a global configuration file: /etc/xen/xl.conf; the only option
currently parsed is autoballoon that is 1 by default.

[fixed up for conflicts with libxl__ naming policy changes -iwj]

Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
tools/examples/Makefile
tools/examples/xl.conf [new file with mode: 0644]
tools/libxl/xl.c
tools/libxl/xl.h

index a911fff057e415fcceb0f3889c46bbb43a2dcad2..ba54a1b8c796ec7d5b39146016cdb9e52ba94338 100644 (file)
@@ -21,6 +21,7 @@ XEN_CONFIGS += xmexample.nbd
 XEN_CONFIGS += xmexample.vti
 XEN_CONFIGS += xend-pci-quirks.sxp
 XEN_CONFIGS += xend-pci-permissive.sxp
+XEN_CONFIGS += xl.conf
 
 .PHONY: all
 all:
diff --git a/tools/examples/xl.conf b/tools/examples/xl.conf
new file mode 100644 (file)
index 0000000..946c1a1
--- /dev/null
@@ -0,0 +1,5 @@
+## Global XL config file ##
+
+# automatically balloon down dom0 when xen doesn't have enough free
+# memory to create a domain
+autoballon=1
index c96c2c79c0c41c2fcd10e6abae6fd87805ca9c07..345f4a5f35ca7f01e72cea2407cf394acdb0bc17 100644 (file)
 
 #include "libxl.h"
 #include "libxl_utils.h"
+#include "libxlutil.h"
 #include "xl.h"
 
 xentoollog_logger_stdiostream *logger;
+int autoballoon = 1;
 
 static xentoollog_level minmsglevel = XTL_PROGRESS;
 
+static void parse_global_config(const char *configfile,
+                              const char *configfile_data,
+                              int configfile_len)
+{
+    long l;
+    XLU_Config *config;
+    int e;
+
+    config = xlu_cfg_init(stderr, configfile);
+    if (!config) {
+        fprintf(stderr, "Failed to allocate for configuration\n");
+        exit(1);
+    }
+
+    e = xlu_cfg_readdata(config, configfile_data, configfile_len);
+    if (e) {
+        fprintf(stderr, "Failed to parse config file: %s\n", strerror(e));
+        exit(1);
+    }
+
+    if (!xlu_cfg_get_long (config, "autoballoon", &l))
+        autoballoon = l;
+
+    xlu_cfg_destroy(config);
+}
 int main(int argc, char **argv)
 {
     int opt = 0;
     char *cmd = 0;
     struct cmd_spec *cspec;
     int ret;
+    char *config_file;
+    void *config_data = 0;
+    int config_len = 0;
 
     while ((opt = getopt(argc, argv, "+v")) >= 0) {
         switch (opt) {
@@ -69,6 +100,21 @@ int main(int argc, char **argv)
         exit(1);
     }
 
+    /* Read global config file options */
+    ret = asprintf(&config_file, "%s/xl.conf", libxl_xen_config_dir_path());
+    if (ret < 0) {
+        fprintf(stderr, "memory allocation failed ret=%d, errno=%d\n", ret, errno);
+        exit(1);
+    }
+
+    ret = libxl_read_file_contents(&ctx, config_file,
+            &config_data, &config_len);
+    if (ret)
+        fprintf(stderr, "Failed to read config file: %s: %s\n",
+                config_file, strerror(errno));
+    parse_global_config(config_file, config_data, config_len);
+    free(config_file);
+
     /* Reset options for per-command use of getopt. */
     argv += optind;
     argc -= optind;
index 468b18bec2bd555c3031d3154cc83256ebaedcbf..55f83599f96875eb600ad4b7b163312aa986fd64 100644 (file)
@@ -90,4 +90,7 @@ struct cmd_spec *cmdtable_lookup(const char *s);
 extern libxl_ctx ctx;
 extern xentoollog_logger_stdiostream *logger;
 
+/* global options */
+extern int autoballoon;
+
 #endif /* XL_H */