/* * Copyright (C) 2009 Citrix Ltd. * Author Stefano Stabellini * Author Vincent Hanquez * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; version 2.1 only. with the special * exception on linking described in file LICENSE. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ #include "libxl_osdeps.h" #include #include #include #include #include #include #include #include #include #include #include #include "libxl.h" #include "libxl_utils.h" #include "libxlutil.h" #include "xl.h" #define XEND_LOCK { "/var/lock/subsys/xend", "/var/lock/xend" } xentoollog_logger_stdiostream *logger; int dryrun_only; int force_execution; int autoballoon = -1; char *blkdev_start; int run_hotplug_scripts = 1; char *lockfile; char *default_vifscript = NULL; char *default_bridge = NULL; char *default_gatewaydev = NULL; char *default_vifbackend = NULL; enum output_format default_output_format = OUTPUT_FORMAT_JSON; int claim_mode = 1; 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(®ex, "(^| )dom0_mem=((|min:|max:)[0-9]+[bBkKmMgG]?,?)+($| )", REG_NOSUB | REG_EXTENDED); if (ret) return 1; ret = regexec(®ex, info->commandline, 0, NULL, 0); regfree(®ex); return ret == REG_NOMATCH; } static void parse_global_config(const char *configfile, const char *configfile_data, int configfile_len) { long l; XLU_Config *config; int e; const char *buf; 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_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 = -1; else fprintf(stderr, "invalid autoballoon option"); } if (autoballoon == -1) autoballoon = auto_autoballoon(); if (!xlu_cfg_get_long (config, "run_hotplug_scripts", &l, 0)) run_hotplug_scripts = l; if (!xlu_cfg_get_string (config, "lockfile", &buf, 0)) lockfile = strdup(buf); else { lockfile = strdup(XL_LOCK_FILE); } if (!lockfile) { fprintf(stderr, "failed to allocate lockdir\n"); exit(1); } /* * For global options that are related to a specific type of device * we use the following nomenclature: * * .default.