/* * Copyright 2009-2017 Citrix Ltd and other contributors * * 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 #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "xl.h" #include "xl_parse.h" #include "xl_utils.h" 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; char *default_remus_netbufscript = NULL; char *default_colo_proxy_script = NULL; libxl_bitmap global_vm_affinity_mask; libxl_bitmap global_hvm_affinity_mask; libxl_bitmap global_pv_affinity_mask; enum output_format default_output_format = OUTPUT_FORMAT_JSON; int claim_mode = 1; bool progress_use_cr = 0; bool timestamps = 0; int max_grant_frames = -1; int max_maptrack_frames = -1; int max_grant_version = LIBXL_MAX_GRANT_DEFAULT; libxl_domid domid_policy = INVALID_DOMID; xentoollog_level minmsglevel = minmsglevel_default; int logfile = 2; /* every libxl action in xl uses this same libxl context */ libxl_ctx *ctx; xlchild children[child_max]; const char *common_domname; /* 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 */ #define SIZE_PATTERN "-?[0-9]+[bBkKmMgGtT]?" ret = regcomp(®ex, "(^| )dom0_mem=((|min:|max:)(" SIZE_PATTERN "|(" SIZE_PATTERN "\\+)?[0-9]{1,2}%),?)+($| )", REG_NOSUB | REG_EXTENDED); #undef SIZE_PATTERN 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 lockfile\n"); exit(1); } /* * For global options that are related to a specific type of device * we use the following nomenclature: * * .default.