| 1 |
/* |
| 2 |
* Copyright 2009-2017 Citrix Ltd and other contributors |
| 3 |
* |
| 4 |
* This program is free software; you can redistribute it and/or modify |
| 5 |
* it under the terms of the GNU Lesser General Public License as published |
| 6 |
* by the Free Software Foundation; version 2.1 only. with the special |
| 7 |
* exception on linking described in file LICENSE. |
| 8 |
* |
| 9 |
* This program is distributed in the hope that it will be useful, |
| 10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
* GNU Lesser General Public License for more details. |
| 13 |
*/ |
| 14 |
|
| 15 |
#include <ctype.h> |
| 16 |
#include <inttypes.h> |
| 17 |
#include <limits.h> |
| 18 |
#include <stdio.h> |
| 19 |
#include <stdlib.h> |
| 20 |
#include <xen/hvm/e820.h> |
| 21 |
#include <xen/hvm/params.h> |
| 22 |
#include <xen/io/sndif.h> |
| 23 |
#include <xen/io/kbdif.h> |
| 24 |
|
| 25 |
#include <libxl.h> |
| 26 |
#include <libxl_utils.h> |
| 27 |
#include <libxlutil.h> |
| 28 |
|
| 29 |
#include "xl.h" |
| 30 |
#include "xl_utils.h" |
| 31 |
#include "xl_parse.h" |
| 32 |
|
| 33 |
extern void set_default_nic_values(libxl_device_nic *nic); |
| 34 |
|
| 35 |
#define ARRAY_EXTEND_INIT__CORE(array,count,initfn,more) \ |
| 36 |
({ \ |
| 37 |
typeof((count)) array_extend_old_count = (count); \ |
| 38 |
(count)++; \ |
| 39 |
(array) = xrealloc((array), sizeof(*array) * (count)); \ |
| 40 |
(initfn)(&(array)[array_extend_old_count]); \ |
| 41 |
more; \ |
| 42 |
&(array)[array_extend_old_count]; \ |
| 43 |
}) |
| 44 |
|
| 45 |
#define ARRAY_EXTEND_INIT(array,count,initfn) \ |
| 46 |
ARRAY_EXTEND_INIT__CORE((array),(count),(initfn), ({ \ |
| 47 |
(array)[array_extend_old_count].devid = array_extend_old_count; \ |
| 48 |
})) |
| 49 |
|
| 50 |
#define ARRAY_EXTEND_INIT_NODEVID(array,count,initfn) \ |
| 51 |
ARRAY_EXTEND_INIT__CORE((array),(count),(initfn), /* nothing */ ) |
| 52 |
|
| 53 |
static const char *action_on_shutdown_names[] = { |
| 54 |
[LIBXL_ACTION_ON_SHUTDOWN_DESTROY] = "destroy", |
| 55 |
|
| 56 |
[LIBXL_ACTION_ON_SHUTDOWN_RESTART] = "restart", |
| 57 |
[LIBXL_ACTION_ON_SHUTDOWN_RESTART_RENAME] = "rename-restart", |
| 58 |
|
| 59 |
[LIBXL_ACTION_ON_SHUTDOWN_PRESERVE] = "preserve", |
| 60 |
|
| 61 |
[LIBXL_ACTION_ON_SHUTDOWN_COREDUMP_DESTROY] = "coredump-destroy", |
| 62 |
[LIBXL_ACTION_ON_SHUTDOWN_COREDUMP_RESTART] = "coredump-restart", |
| 63 |
|
| 64 |
[LIBXL_ACTION_ON_SHUTDOWN_SOFT_RESET] = "soft-reset", |
| 65 |
}; |
| 66 |
|
| 67 |
const char *get_action_on_shutdown_name(libxl_action_on_shutdown a) |
| 68 |
{ |
| 69 |
return action_on_shutdown_names[a]; |
| 70 |
} |
| 71 |
|
| 72 |
static int parse_action_on_shutdown(const char *buf, libxl_action_on_shutdown *a) |
| 73 |
{ |
| 74 |
int i; |
| 75 |
const char *n; |
| 76 |
|
| 77 |
for (i = 0; i < sizeof(action_on_shutdown_names) / sizeof(action_on_shutdown_names[0]); i++) { |
| 78 |
n = action_on_shutdown_names[i]; |
| 79 |
|
| 80 |
if (!n) continue; |
| 81 |
|
| 82 |
if (strcmp(buf, n) == 0) { |
| 83 |
*a = i; |
| 84 |
return 1; |
| 85 |
} |
| 86 |
} |
| 87 |
return 0; |
| 88 |
} |
| 89 |
|
| 90 |
#define DSTATE_INITIAL 0 |
| 91 |
#define DSTATE_TAP 1 |
| 92 |
#define DSTATE_PHYSPATH 2 |
| 93 |
#define DSTATE_VIRTPATH 3 |
| 94 |
#define DSTATE_VIRTTYPE 4 |
| 95 |
#define DSTATE_RW 5 |
| 96 |
#define DSTATE_TERMINAL 6 |
| 97 |
|
| 98 |
void parse_disk_config_multistring(XLU_Config **config, |
| 99 |
int nspecs, const char *const *specs, |
| 100 |
libxl_device_disk *disk) |
| 101 |
{ |
| 102 |
int e; |
| 103 |
|
| 104 |
libxl_device_disk_init(disk); |
| 105 |
|
| 106 |
if (!*config) { |
| 107 |
*config = xlu_cfg_init(stderr, "command line"); |
| 108 |
if (!*config) { perror("xlu_cfg_init"); exit(-1); } |
| 109 |
} |
| 110 |
|
| 111 |
e = xlu_disk_parse(*config, nspecs, specs, disk); |
| 112 |
if (e == EINVAL) exit(EXIT_FAILURE); |
| 113 |
if (e) { |
| 114 |
fprintf(stderr,"xlu_disk_parse failed: %s\n",strerror(errno)); |
| 115 |
exit(EXIT_FAILURE); |
| 116 |
} |
| 117 |
} |
| 118 |
|
| 119 |
void parse_disk_config(XLU_Config **config, const char *spec, |
| 120 |
libxl_device_disk *disk) |
| 121 |
{ |
| 122 |
parse_disk_config_multistring(config, 1, &spec, disk); |
| 123 |
} |
| 124 |
|
| 125 |
static void parse_vif_rate(XLU_Config **config, const char *rate, |
| 126 |
libxl_device_nic *nic) |
| 127 |
{ |
| 128 |
int e; |
| 129 |
|
| 130 |
e = xlu_vif_parse_rate(*config, rate, nic); |
| 131 |
if (e == EINVAL || e == EOVERFLOW) exit(EXIT_FAILURE); |
| 132 |
if (e) { |
| 133 |
fprintf(stderr,"xlu_vif_parse_rate failed: %s\n",strerror(errno)); |
| 134 |
exit(EXIT_FAILURE); |
| 135 |
} |
| 136 |
} |
| 137 |
|
| 138 |
int parse_range(const char *str, unsigned long *a, unsigned long *b) |
| 139 |
{ |
| 140 |
const char *nstr; |
| 141 |
char *endptr; |
| 142 |
|
| 143 |
*a = *b = strtoul(str, &endptr, 10); |
| 144 |
if (endptr == str || *a == ULONG_MAX) |
| 145 |
return 1; |
| 146 |
|
| 147 |
if (*endptr == '-') { |
| 148 |
nstr = endptr + 1; |
| 149 |
|
| 150 |
*b = strtoul(nstr, &endptr, 10); |
| 151 |
if (endptr == nstr || *b == ULONG_MAX || *b < *a) |
| 152 |
return 1; |
| 153 |
} |
| 154 |
|
| 155 |
/* Valid value or range so far, but we also don't want junk after that */ |
| 156 |
if (*endptr != '\0') |
| 157 |
return 1; |
| 158 |
|
| 159 |
return 0; |
| 160 |
} |
| 161 |
|
| 162 |
/* |
| 163 |
* Add or removes a specific set of cpus (specified in str, either as |
| 164 |
* single cpus or as entire NUMA nodes) to/from cpumap. |
| 165 |
*/ |
| 166 |
static int update_cpumap_range(const char *str, libxl_bitmap *cpumap) |
| 167 |
{ |
| 168 |
unsigned long ida, idb; |
| 169 |
libxl_bitmap node_cpumap; |
| 170 |
bool is_not = false, is_nodes = false; |
| 171 |
int rc = 0; |
| 172 |
|
| 173 |
libxl_bitmap_init(&node_cpumap); |
| 174 |
|
| 175 |
rc = libxl_node_bitmap_alloc(ctx, &node_cpumap, 0); |
| 176 |
if (rc) { |
| 177 |
fprintf(stderr, "libxl_node_bitmap_alloc failed.\n"); |
| 178 |
goto out; |
| 179 |
} |
| 180 |
|
| 181 |
/* Are we adding or removing cpus/nodes? */ |
| 182 |
if (STR_SKIP_PREFIX(str, "^")) { |
| 183 |
is_not = true; |
| 184 |
} |
| 185 |
|
| 186 |
/* Are we dealing with cpus or full nodes? */ |
| 187 |
if (STR_SKIP_PREFIX(str, "node:") || STR_SKIP_PREFIX(str, "nodes:")) { |
| 188 |
is_nodes = true; |
| 189 |
} |
| 190 |
|
| 191 |
if (strcmp(str, "all") == 0) { |
| 192 |
/* We do not accept "^all" or "^nodes:all" */ |
| 193 |
if (is_not) { |
| 194 |
fprintf(stderr, "Can't combine \"^\" and \"all\".\n"); |
| 195 |
rc = ERROR_INVAL; |
| 196 |
} else |
| 197 |
libxl_bitmap_set_any(cpumap); |
| 198 |
goto out; |
| 199 |
} |
| 200 |
|
| 201 |
rc = parse_range(str, &ida, &idb); |
| 202 |
if (rc) { |
| 203 |
fprintf(stderr, "Invalid pcpu range: %s.\n", str); |
| 204 |
goto out; |
| 205 |
} |
| 206 |
|
| 207 |
/* Add or remove the specified cpus in the range */ |
| 208 |
while (ida <= idb) { |
| 209 |
if (is_nodes) { |
| 210 |
/* Add/Remove all the cpus of a NUMA node */ |
| 211 |
int i; |
| 212 |
|
| 213 |
rc = libxl_node_to_cpumap(ctx, ida, &node_cpumap); |
| 214 |
if (rc) { |
| 215 |
fprintf(stderr, "libxl_node_to_cpumap failed.\n"); |
| 216 |
goto out; |
| 217 |
} |
| 218 |
|
| 219 |
/* Add/Remove all the cpus in the node cpumap */ |
| 220 |
libxl_for_each_set_bit(i, node_cpumap) { |
| 221 |
is_not ? libxl_bitmap_reset(cpumap, i) : |
| 222 |
libxl_bitmap_set(cpumap, i); |
| 223 |
} |
| 224 |
} else { |
| 225 |
/* Add/Remove this cpu */ |
| 226 |
is_not ? libxl_bitmap_reset(cpumap, ida) : |
| 227 |
libxl_bitmap_set(cpumap, ida); |
| 228 |
} |
| 229 |
ida++; |
| 230 |
} |
| 231 |
|
| 232 |
out: |
| 233 |
libxl_bitmap_dispose(&node_cpumap); |
| 234 |
return rc; |
| 235 |
} |
| 236 |
|
| 237 |
/* |
| 238 |
* Takes a string representing a set of cpus (specified either as |
| 239 |
* single cpus or as eintire NUMA nodes) and turns it into the |
| 240 |
* corresponding libxl_bitmap (in cpumap). |
| 241 |
*/ |
| 242 |
int parse_cpurange(const char *cpu, libxl_bitmap *cpumap) |
| 243 |
{ |
| 244 |
char *ptr, *saveptr = NULL, *buf = xstrdup(cpu); |
| 245 |
int rc = 0; |
| 246 |
|
| 247 |
for (ptr = strtok_r(buf, ",", &saveptr); ptr; |
| 248 |
ptr = strtok_r(NULL, ",", &saveptr)) { |
| 249 |
rc = update_cpumap_range(ptr, cpumap); |
| 250 |
if (rc) |
| 251 |
break; |
| 252 |
} |
| 253 |
free(buf); |
| 254 |
|
| 255 |
return rc; |
| 256 |
} |
| 257 |
|
| 258 |
static void parse_top_level_vnc_options(XLU_Config *config, |
| 259 |
libxl_vnc_info *vnc) |
| 260 |
{ |
| 261 |
long l; |
| 262 |
|
| 263 |
xlu_cfg_get_defbool(config, "vnc", &vnc->enable, 0); |
| 264 |
xlu_cfg_replace_string (config, "vnclisten", &vnc->listen, 0); |
| 265 |
xlu_cfg_replace_string (config, "vncpasswd", &vnc->passwd, 0); |
| 266 |
if (!xlu_cfg_get_long (config, "vncdisplay", &l, 0)) |
| 267 |
vnc->display = l; |
| 268 |
xlu_cfg_get_defbool(config, "vncunused", &vnc->findunused, 0); |
| 269 |
} |
| 270 |
|
| 271 |
static void parse_top_level_sdl_options(XLU_Config *config, |
| 272 |
libxl_sdl_info *sdl) |
| 273 |
{ |
| 274 |
xlu_cfg_get_defbool(config, "sdl", &sdl->enable, 0); |
| 275 |
xlu_cfg_get_defbool(config, "opengl", &sdl->opengl, 0); |
| 276 |
xlu_cfg_replace_string (config, "display", &sdl->display, 0); |
| 277 |
xlu_cfg_replace_string (config, "xauthority", &sdl->xauthority, 0); |
| 278 |
} |
| 279 |
|
| 280 |
static char *parse_cmdline(XLU_Config *config) |
| 281 |
{ |
| 282 |
char *cmdline = NULL; |
| 283 |
const char *root = NULL, *extra = NULL, *buf = NULL; |
| 284 |
|
| 285 |
xlu_cfg_get_string (config, "cmdline", &buf, 0); |
| 286 |
xlu_cfg_get_string (config, "root", &root, 0); |
| 287 |
xlu_cfg_get_string (config, "extra", &extra, 0); |
| 288 |
|
| 289 |
if (buf) { |
| 290 |
cmdline = strdup(buf); |
| 291 |
if (root || extra) |
| 292 |
fprintf(stderr, "Warning: ignoring root= and extra= " |
| 293 |
"in favour of cmdline=\n"); |
| 294 |
} else { |
| 295 |
if (root && extra) { |
| 296 |
xasprintf(&cmdline, "root=%s %s", root, extra); |
| 297 |
} else if (root) { |
| 298 |
xasprintf(&cmdline, "root=%s", root); |
| 299 |
} else if (extra) { |
| 300 |
cmdline = strdup(extra); |
| 301 |
} |
| 302 |
} |
| 303 |
|
| 304 |
if ((buf || root || extra) && !cmdline) { |
| 305 |
fprintf(stderr, "Failed to allocate memory for cmdline\n"); |
| 306 |
exit(EXIT_FAILURE); |
| 307 |
} |
| 308 |
|
| 309 |
return cmdline; |
| 310 |
} |
| 311 |
|
| 312 |
static void parse_vcpu_affinity(libxl_domain_build_info *b_info, |
| 313 |
XLU_ConfigList *cpus, const char *buf, |
| 314 |
int num_cpus, bool is_hard) |
| 315 |
{ |
| 316 |
libxl_bitmap *vcpu_affinity_array; |
| 317 |
|
| 318 |
/* |
| 319 |
* If we are here, and buf is !NULL, we're dealing with a string. What |
| 320 |
* we do in this case is parse it, and copy the result in _all_ (up to |
| 321 |
* b_info->max_vcpus) the elements of the vcpu affinity array. |
| 322 |
* |
| 323 |
* If buf is NULL, we have a list, and what we do is putting in the |
| 324 |
* i-eth element of the vcpu affinity array the result of the parsing |
| 325 |
* of the i-eth entry of the list. If there are more vcpus than |
| 326 |
* entries, it is fine to just not touch the last array elements. |
| 327 |
*/ |
| 328 |
|
| 329 |
/* Silently ignore values corresponding to non existing vcpus */ |
| 330 |
if (buf || num_cpus > b_info->max_vcpus) |
| 331 |
num_cpus = b_info->max_vcpus; |
| 332 |
|
| 333 |
if (is_hard) { |
| 334 |
b_info->num_vcpu_hard_affinity = num_cpus; |
| 335 |
b_info->vcpu_hard_affinity = xmalloc(num_cpus * sizeof(libxl_bitmap)); |
| 336 |
vcpu_affinity_array = b_info->vcpu_hard_affinity; |
| 337 |
} else { |
| 338 |
b_info->num_vcpu_soft_affinity = num_cpus; |
| 339 |
b_info->vcpu_soft_affinity = xmalloc(num_cpus * sizeof(libxl_bitmap)); |
| 340 |
vcpu_affinity_array = b_info->vcpu_soft_affinity; |
| 341 |
} |
| 342 |
|
| 343 |
if (!buf) { |
| 344 |
int j = 0; |
| 345 |
|
| 346 |
while ((buf = xlu_cfg_get_listitem(cpus, j)) != NULL && j < num_cpus) { |
| 347 |
libxl_bitmap_init(&vcpu_affinity_array[j]); |
| 348 |
if (libxl_cpu_bitmap_alloc(ctx, &vcpu_affinity_array[j], 0)) { |
| 349 |
fprintf(stderr, "Unable to allocate cpumap for vcpu %d\n", j); |
| 350 |
exit(EXIT_FAILURE); |
| 351 |
} |
| 352 |
|
| 353 |
if (parse_cpurange(buf, &vcpu_affinity_array[j])) |
| 354 |
exit(EXIT_FAILURE); |
| 355 |
|
| 356 |
j++; |
| 357 |
} |
| 358 |
|
| 359 |
/* When we have a list of cpumaps, always disable automatic placement */ |
| 360 |
libxl_defbool_set(&b_info->numa_placement, false); |
| 361 |
} else { |
| 362 |
int i; |
| 363 |
|
| 364 |
libxl_bitmap_init(&vcpu_affinity_array[0]); |
| 365 |
if (libxl_cpu_bitmap_alloc(ctx, &vcpu_affinity_array[0], 0)) { |
| 366 |
fprintf(stderr, "Unable to allocate cpumap for vcpu 0\n"); |
| 367 |
exit(EXIT_FAILURE); |
| 368 |
} |
| 369 |
|
| 370 |
if (parse_cpurange(buf, &vcpu_affinity_array[0])) |
| 371 |
exit(EXIT_FAILURE); |
| 372 |
|
| 373 |
for (i = 1; i < b_info->max_vcpus; i++) { |
| 374 |
libxl_bitmap_init(&vcpu_affinity_array[i]); |
| 375 |
if (libxl_cpu_bitmap_alloc(ctx, &vcpu_affinity_array[i], 0)) { |
| 376 |
fprintf(stderr, "Unable to allocate cpumap for vcpu %d\n", i); |
| 377 |
exit(EXIT_FAILURE); |
| 378 |
} |
| 379 |
libxl_bitmap_copy(ctx, &vcpu_affinity_array[i], |
| 380 |
&vcpu_affinity_array[0]); |
| 381 |
} |
| 382 |
|
| 383 |
/* We have soft affinity already, disable automatic placement */ |
| 384 |
if (!is_hard) |
| 385 |
libxl_defbool_set(&b_info->numa_placement, false); |
| 386 |
} |
| 387 |
} |
| 388 |
|
| 389 |
static unsigned long parse_ulong(const char *str) |
| 390 |
{ |
| 391 |
char *endptr; |
| 392 |
unsigned long val; |
| 393 |
|
| 394 |
val = strtoul(str, &endptr, 10); |
| 395 |
if (endptr == str || val == ULONG_MAX) { |
| 396 |
fprintf(stderr, "xl: failed to convert \"%s\" to number\n", str); |
| 397 |
exit(EXIT_FAILURE); |
| 398 |
} |
| 399 |
return val; |
| 400 |
} |
| 401 |
|
| 402 |
void replace_string(char **str, const char *val) |
| 403 |
{ |
| 404 |
free(*str); |
| 405 |
*str = xstrdup(val); |
| 406 |
} |
| 407 |
|
| 408 |
int match_option_size(const char *prefix, size_t len, |
| 409 |
char *arg, char **argopt) |
| 410 |
{ |
| 411 |
int rc = strncmp(prefix, arg, len); |
| 412 |
if (!rc) *argopt = arg+len; |
| 413 |
return !rc; |
| 414 |
} |
| 415 |
|
| 416 |
/* Parses network data and adds info into nic |
| 417 |
* Returns 1 if the input token does not match one of the keys |
| 418 |
* or parsed values are not correct. Successful parse returns 0 */ |
| 419 |
int parse_nic_config(libxl_device_nic *nic, XLU_Config **config, char *token) |
| 420 |
{ |
| 421 |
char *endptr, *oparg; |
| 422 |
int i; |
| 423 |
unsigned int val; |
| 424 |
|
| 425 |
if (MATCH_OPTION("type", token, oparg)) { |
| 426 |
if (!strcmp("vif", oparg)) { |
| 427 |
nic->nictype = LIBXL_NIC_TYPE_VIF; |
| 428 |
} else if (!strcmp("ioemu", oparg)) { |
| 429 |
nic->nictype = LIBXL_NIC_TYPE_VIF_IOEMU; |
| 430 |
} else { |
| 431 |
fprintf(stderr, "Invalid parameter `type'.\n"); |
| 432 |
return 1; |
| 433 |
} |
| 434 |
} else if (MATCH_OPTION("mac", token, oparg)) { |
| 435 |
for (i = 0; i < 6; i++) { |
| 436 |
val = strtoul(oparg, &endptr, 16); |
| 437 |
if ((oparg == endptr) || (val > 255)) { |
| 438 |
fprintf(stderr, "Invalid parameter `mac'.\n"); |
| 439 |
return 1; |
| 440 |
} |
| 441 |
nic->mac[i] = val; |
| 442 |
oparg = endptr + 1; |
| 443 |
} |
| 444 |
} else if (MATCH_OPTION("bridge", token, oparg)) { |
| 445 |
replace_string(&nic->bridge, oparg); |
| 446 |
} else if (MATCH_OPTION("netdev", token, oparg)) { |
| 447 |
fprintf(stderr, "the netdev parameter is deprecated, " |
| 448 |
"please use gatewaydev instead\n"); |
| 449 |
replace_string(&nic->gatewaydev, oparg); |
| 450 |
} else if (MATCH_OPTION("gatewaydev", token, oparg)) { |
| 451 |
replace_string(&nic->gatewaydev, oparg); |
| 452 |
} else if (MATCH_OPTION("ip", token, oparg)) { |
| 453 |
replace_string(&nic->ip, oparg); |
| 454 |
} else if (MATCH_OPTION("script", token, oparg)) { |
| 455 |
replace_string(&nic->script, oparg); |
| 456 |
} else if (MATCH_OPTION("backend", token, oparg)) { |
| 457 |
replace_string(&nic->backend_domname, oparg); |
| 458 |
} else if (MATCH_OPTION("vifname", token, oparg)) { |
| 459 |
replace_string(&nic->ifname, oparg); |
| 460 |
} else if (MATCH_OPTION("model", token, oparg)) { |
| 461 |
replace_string(&nic->model, oparg); |
| 462 |
} else if (MATCH_OPTION("rate", token, oparg)) { |
| 463 |
parse_vif_rate(config, oparg, nic); |
| 464 |
} else if (MATCH_OPTION("forwarddev", token, oparg)) { |
| 465 |
replace_string(&nic->coloft_forwarddev, oparg); |
| 466 |
} else if (MATCH_OPTION("colo_sock_mirror_id", token, oparg)) { |
| 467 |
replace_string(&nic->colo_sock_mirror_id, oparg); |
| 468 |
} else if (MATCH_OPTION("colo_sock_mirror_ip", token, oparg)) { |
| 469 |
replace_string(&nic->colo_sock_mirror_ip, oparg); |
| 470 |
} else if (MATCH_OPTION("colo_sock_mirror_port", token, oparg)) { |
| 471 |
replace_string(&nic->colo_sock_mirror_port, oparg); |
| 472 |
} else if (MATCH_OPTION("colo_sock_compare_sec_in_id", token, oparg)) { |
| 473 |
replace_string(&nic->colo_sock_compare_sec_in_id, oparg); |
| 474 |
} else if (MATCH_OPTION("colo_sock_compare_sec_in_ip", token, oparg)) { |
| 475 |
replace_string(&nic->colo_sock_compare_sec_in_ip, oparg); |
| 476 |
} else if (MATCH_OPTION("colo_sock_compare_sec_in_port", token, oparg)) { |
| 477 |
replace_string(&nic->colo_sock_compare_sec_in_port, oparg); |
| 478 |
} else if (MATCH_OPTION("colo_sock_redirector0_id", token, oparg)) { |
| 479 |
replace_string(&nic->colo_sock_redirector0_id, oparg); |
| 480 |
} else if (MATCH_OPTION("colo_sock_redirector0_ip", token, oparg)) { |
| 481 |
replace_string(&nic->colo_sock_redirector0_ip, oparg); |
| 482 |
} else if (MATCH_OPTION("colo_sock_redirector0_port", token, oparg)) { |
| 483 |
replace_string(&nic->colo_sock_redirector0_port, oparg); |
| 484 |
} else if (MATCH_OPTION("colo_sock_redirector1_id", token, oparg)) { |
| 485 |
replace_string(&nic->colo_sock_redirector1_id, oparg); |
| 486 |
} else if (MATCH_OPTION("colo_sock_redirector1_ip", token, oparg)) { |
| 487 |
replace_string(&nic->colo_sock_redirector1_ip, oparg); |
| 488 |
} else if (MATCH_OPTION("colo_sock_redirector1_port", token, oparg)) { |
| 489 |
replace_string(&nic->colo_sock_redirector1_port, oparg); |
| 490 |
} else if (MATCH_OPTION("colo_sock_redirector2_id", token, oparg)) { |
| 491 |
replace_string(&nic->colo_sock_redirector2_id, oparg); |
| 492 |
} else if (MATCH_OPTION("colo_sock_redirector2_ip", token, oparg)) { |
| 493 |
replace_string(&nic->colo_sock_redirector2_ip, oparg); |
| 494 |
} else if (MATCH_OPTION("colo_sock_redirector2_port", token, oparg)) { |
| 495 |
replace_string(&nic->colo_sock_redirector2_port, oparg); |
| 496 |
} else if (MATCH_OPTION("colo_sock_compare_pri_in_id", token, oparg)) { |
| 497 |
replace_string(&nic->colo_sock_compare_pri_in_id, oparg); |
| 498 |
} else if (MATCH_OPTION("colo_sock_compare_pri_in_ip", token, oparg)) { |
| 499 |
replace_string(&nic->colo_sock_compare_pri_in_ip, oparg); |
| 500 |
} else if (MATCH_OPTION("colo_sock_compare_pri_in_port", token, oparg)) { |
| 501 |
replace_string(&nic->colo_sock_compare_pri_in_port, oparg); |
| 502 |
} else if (MATCH_OPTION("colo_sock_compare_notify_id", token, oparg)) { |
| 503 |
replace_string(&nic->colo_sock_compare_notify_id, oparg); |
| 504 |
} else if (MATCH_OPTION("colo_sock_compare_notify_ip", token, oparg)) { |
| 505 |
replace_string(&nic->colo_sock_compare_notify_ip, oparg); |
| 506 |
} else if (MATCH_OPTION("colo_sock_compare_notify_port", token, oparg)) { |
| 507 |
replace_string(&nic->colo_sock_compare_notify_port, oparg); |
| 508 |
} else if (MATCH_OPTION("colo_filter_mirror_queue", token, oparg)) { |
| 509 |
replace_string(&nic->colo_filter_mirror_queue, oparg); |
| 510 |
} else if (MATCH_OPTION("colo_filter_mirror_outdev", token, oparg)) { |
| 511 |
replace_string(&nic->colo_filter_mirror_outdev, oparg); |
| 512 |
} else if (MATCH_OPTION("colo_filter_redirector0_queue", token, oparg)) { |
| 513 |
replace_string(&nic->colo_filter_redirector0_queue, oparg); |
| 514 |
} else if (MATCH_OPTION("colo_filter_redirector0_indev", token, oparg)) { |
| 515 |
replace_string(&nic->colo_filter_redirector0_indev, oparg); |
| 516 |
} else if (MATCH_OPTION("colo_filter_redirector0_outdev", token, oparg)) { |
| 517 |
replace_string(&nic->colo_filter_redirector0_outdev, oparg); |
| 518 |
} else if (MATCH_OPTION("colo_filter_redirector1_queue", token, oparg)) { |
| 519 |
replace_string(&nic->colo_filter_redirector1_queue, oparg); |
| 520 |
} else if (MATCH_OPTION("colo_filter_redirector1_indev", token, oparg)) { |
| 521 |
replace_string(&nic->colo_filter_redirector1_indev, oparg); |
| 522 |
} else if (MATCH_OPTION("colo_filter_redirector1_outdev", token, oparg)) { |
| 523 |
replace_string(&nic->colo_filter_redirector1_outdev, oparg); |
| 524 |
} else if (MATCH_OPTION("colo_compare_pri_in", token, oparg)) { |
| 525 |
replace_string(&nic->colo_compare_pri_in, oparg); |
| 526 |
} else if (MATCH_OPTION("colo_compare_sec_in", token, oparg)) { |
| 527 |
replace_string(&nic->colo_compare_sec_in, oparg); |
| 528 |
} else if (MATCH_OPTION("colo_compare_out", token, oparg)) { |
| 529 |
replace_string(&nic->colo_compare_out, oparg); |
| 530 |
} else if (MATCH_OPTION("colo_compare_notify_dev", token, oparg)) { |
| 531 |
replace_string(&nic->colo_compare_notify_dev, oparg); |
| 532 |
} else if (MATCH_OPTION("colo_sock_sec_redirector0_id", token, oparg)) { |
| 533 |
replace_string(&nic->colo_sock_sec_redirector0_id, oparg); |
| 534 |
} else if (MATCH_OPTION("colo_sock_sec_redirector0_ip", token, oparg)) { |
| 535 |
replace_string(&nic->colo_sock_sec_redirector0_ip, oparg); |
| 536 |
} else if (MATCH_OPTION("colo_sock_sec_redirector0_port", token, oparg)) { |
| 537 |
replace_string(&nic->colo_sock_sec_redirector0_port, oparg); |
| 538 |
} else if (MATCH_OPTION("colo_sock_sec_redirector1_id", token, oparg)) { |
| 539 |
replace_string(&nic->colo_sock_sec_redirector1_id, oparg); |
| 540 |
} else if (MATCH_OPTION("colo_sock_sec_redirector1_ip", token, oparg)) { |
| 541 |
replace_string(&nic->colo_sock_sec_redirector1_ip, oparg); |
| 542 |
} else if (MATCH_OPTION("colo_sock_sec_redirector1_port", token, oparg)) { |
| 543 |
replace_string(&nic->colo_sock_sec_redirector1_port, oparg); |
| 544 |
} else if (MATCH_OPTION("colo_filter_sec_redirector0_queue", token, oparg)) { |
| 545 |
replace_string(&nic->colo_filter_sec_redirector0_queue, oparg); |
| 546 |
} else if (MATCH_OPTION("colo_filter_sec_redirector0_indev", token, oparg)) { |
| 547 |
replace_string(&nic->colo_filter_sec_redirector0_indev, oparg); |
| 548 |
} else if (MATCH_OPTION("colo_filter_sec_redirector0_outdev", token, oparg)) { |
| 549 |
replace_string(&nic->colo_filter_sec_redirector0_outdev, oparg); |
| 550 |
} else if (MATCH_OPTION("colo_filter_sec_redirector1_queue", token, oparg)) { |
| 551 |
replace_string(&nic->colo_filter_sec_redirector1_queue, oparg); |
| 552 |
} else if (MATCH_OPTION("colo_filter_sec_redirector1_indev", token, oparg)) { |
| 553 |
replace_string(&nic->colo_filter_sec_redirector1_indev, oparg); |
| 554 |
} else if (MATCH_OPTION("colo_filter_sec_redirector1_outdev", token, oparg)) { |
| 555 |
replace_string(&nic->colo_filter_sec_redirector1_outdev, oparg); |
| 556 |
} else if (MATCH_OPTION("colo_filter_sec_rewriter0_queue", token, oparg)) { |
| 557 |
replace_string(&nic->colo_filter_sec_rewriter0_queue, oparg); |
| 558 |
} else if (MATCH_OPTION("colo_checkpoint_host", token, oparg)) { |
| 559 |
replace_string(&nic->colo_checkpoint_host, oparg); |
| 560 |
} else if (MATCH_OPTION("colo_checkpoint_port", token, oparg)) { |
| 561 |
replace_string(&nic->colo_checkpoint_port, oparg); |
| 562 |
} else if (MATCH_OPTION("accel", token, oparg)) { |
| 563 |
fprintf(stderr, "the accel parameter for vifs is currently not supported\n"); |
| 564 |
} else if (MATCH_OPTION("devid", token, oparg)) { |
| 565 |
nic->devid = parse_ulong(oparg); |
| 566 |
} else if (MATCH_OPTION("mtu", token, oparg)) { |
| 567 |
nic->mtu = parse_ulong(oparg); |
| 568 |
} else if (MATCH_OPTION("vlan", token, oparg)) { |
| 569 |
replace_string(&nic->vlan, oparg); |
| 570 |
} else if (!strcmp("trusted", token)) { |
| 571 |
libxl_defbool_set(&nic->trusted, true); |
| 572 |
} else if (!strcmp("untrusted", token)) { |
| 573 |
libxl_defbool_set(&nic->trusted, false); |
| 574 |
} else { |
| 575 |
fprintf(stderr, "unrecognized argument `%s'\n", token); |
| 576 |
return 1; |
| 577 |
} |
| 578 |
return 0; |
| 579 |
} |
| 580 |
|
| 581 |
static void parse_vnuma_config(const XLU_Config *config, |
| 582 |
libxl_domain_build_info *b_info) |
| 583 |
{ |
| 584 |
libxl_physinfo physinfo; |
| 585 |
uint32_t nr_nodes; |
| 586 |
XLU_ConfigList *vnuma; |
| 587 |
int i, j, len, num_vnuma; |
| 588 |
unsigned long max_vcpus = 0, max_memkb = 0; |
| 589 |
/* Temporary storage for parsed vcpus information to avoid |
| 590 |
* parsing config twice. This array has num_vnuma elements. |
| 591 |
*/ |
| 592 |
libxl_bitmap *vcpu_parsed; |
| 593 |
|
| 594 |
libxl_physinfo_init(&physinfo); |
| 595 |
if (libxl_get_physinfo(ctx, &physinfo) != 0) { |
| 596 |
libxl_physinfo_dispose(&physinfo); |
| 597 |
fprintf(stderr, "libxl_get_physinfo failed\n"); |
| 598 |
exit(EXIT_FAILURE); |
| 599 |
} |
| 600 |
|
| 601 |
nr_nodes = physinfo.nr_nodes; |
| 602 |
libxl_physinfo_dispose(&physinfo); |
| 603 |
|
| 604 |
if (xlu_cfg_get_list(config, "vnuma", &vnuma, &num_vnuma, 1)) |
| 605 |
return; |
| 606 |
|
| 607 |
if (!num_vnuma) |
| 608 |
return; |
| 609 |
|
| 610 |
b_info->num_vnuma_nodes = num_vnuma; |
| 611 |
b_info->vnuma_nodes = xcalloc(num_vnuma, sizeof(libxl_vnode_info)); |
| 612 |
vcpu_parsed = xcalloc(num_vnuma, sizeof(libxl_bitmap)); |
| 613 |
for (i = 0; i < num_vnuma; i++) { |
| 614 |
libxl_bitmap_init(&vcpu_parsed[i]); |
| 615 |
if (libxl_cpu_bitmap_alloc(ctx, &vcpu_parsed[i], b_info->max_vcpus)) { |
| 616 |
fprintf(stderr, "libxl_node_bitmap_alloc failed.\n"); |
| 617 |
exit(EXIT_FAILURE); |
| 618 |
} |
| 619 |
} |
| 620 |
|
| 621 |
for (i = 0; i < b_info->num_vnuma_nodes; i++) { |
| 622 |
libxl_vnode_info *p = &b_info->vnuma_nodes[i]; |
| 623 |
|
| 624 |
libxl_vnode_info_init(p); |
| 625 |
p->distances = xcalloc(b_info->num_vnuma_nodes, |
| 626 |
sizeof(*p->distances)); |
| 627 |
p->num_distances = b_info->num_vnuma_nodes; |
| 628 |
} |
| 629 |
|
| 630 |
for (i = 0; i < num_vnuma; i++) { |
| 631 |
XLU_ConfigValue *vnode_spec, *conf_option; |
| 632 |
XLU_ConfigList *vnode_config_list; |
| 633 |
int conf_count; |
| 634 |
libxl_vnode_info *p = &b_info->vnuma_nodes[i]; |
| 635 |
|
| 636 |
vnode_spec = xlu_cfg_get_listitem2(vnuma, i); |
| 637 |
assert(vnode_spec); |
| 638 |
|
| 639 |
xlu_cfg_value_get_list(config, vnode_spec, &vnode_config_list, 0); |
| 640 |
if (!vnode_config_list) { |
| 641 |
fprintf(stderr, "xl: cannot get vnode config option list\n"); |
| 642 |
exit(EXIT_FAILURE); |
| 643 |
} |
| 644 |
|
| 645 |
for (conf_count = 0; |
| 646 |
(conf_option = |
| 647 |
xlu_cfg_get_listitem2(vnode_config_list, conf_count)); |
| 648 |
conf_count++) { |
| 649 |
|
| 650 |
if (xlu_cfg_value_type(conf_option) == XLU_STRING) { |
| 651 |
char *buf; |
| 652 |
char *option, *value; |
| 653 |
unsigned long val; |
| 654 |
|
| 655 |
xlu_cfg_value_get_string(config, conf_option, &buf, 0); |
| 656 |
|
| 657 |
if (!buf) continue; |
| 658 |
|
| 659 |
if (split_string_into_pair(buf, '=', &option, &value, |
| 660 |
isspace)) { |
| 661 |
fprintf(stderr, "xl: failed to split \"%s\" into pair\n", |
| 662 |
buf); |
| 663 |
exit(EXIT_FAILURE); |
| 664 |
} |
| 665 |
|
| 666 |
if (!strcmp("pnode", option)) { |
| 667 |
val = parse_ulong(value); |
| 668 |
if (val >= nr_nodes) { |
| 669 |
fprintf(stderr, |
| 670 |
"xl: invalid pnode number: %lu\n", val); |
| 671 |
exit(EXIT_FAILURE); |
| 672 |
} |
| 673 |
p->pnode = val; |
| 674 |
libxl_defbool_set(&b_info->numa_placement, false); |
| 675 |
} else if (!strcmp("size", option)) { |
| 676 |
val = parse_ulong(value); |
| 677 |
p->memkb = val << 10; |
| 678 |
max_memkb += p->memkb; |
| 679 |
} else if (!strcmp("vcpus", option)) { |
| 680 |
libxl_string_list cpu_spec_list; |
| 681 |
unsigned long s, e; |
| 682 |
|
| 683 |
split_string_into_string_list(value, ",", &cpu_spec_list); |
| 684 |
len = libxl_string_list_length(&cpu_spec_list); |
| 685 |
|
| 686 |
for (j = 0; j < len; j++) { |
| 687 |
parse_range(cpu_spec_list[j], &s, &e); |
| 688 |
for (; s <= e; s++) { |
| 689 |
/* |
| 690 |
* Note that if we try to set a bit beyond |
| 691 |
* the size of bitmap, libxl_bitmap_set |
| 692 |
* has no effect. The resulted bitmap |
| 693 |
* doesn't reflect what user wants. The |
| 694 |
* fallout is dealt with later after |
| 695 |
* parsing. |
| 696 |
*/ |
| 697 |
libxl_bitmap_set(&vcpu_parsed[i], s); |
| 698 |
max_vcpus++; |
| 699 |
} |
| 700 |
} |
| 701 |
|
| 702 |
libxl_string_list_dispose(&cpu_spec_list); |
| 703 |
} else if (!strcmp("vdistances", option)) { |
| 704 |
libxl_string_list vdist; |
| 705 |
|
| 706 |
split_string_into_string_list(value, ",", &vdist); |
| 707 |
len = libxl_string_list_length(&vdist); |
| 708 |
|
| 709 |
for (j = 0; j < len; j++) { |
| 710 |
val = parse_ulong(vdist[j]); |
| 711 |
p->distances[j] = val; |
| 712 |
} |
| 713 |
libxl_string_list_dispose(&vdist); |
| 714 |
} |
| 715 |
free(option); |
| 716 |
free(value); |
| 717 |
} |
| 718 |
} |
| 719 |
} |
| 720 |
|
| 721 |
/* User has specified maxvcpus= */ |
| 722 |
if (b_info->max_vcpus != 0) { |
| 723 |
if (b_info->max_vcpus != max_vcpus) { |
| 724 |
fprintf(stderr, "xl: vnuma vcpus and maxvcpus= mismatch\n"); |
| 725 |
exit(EXIT_FAILURE); |
| 726 |
} |
| 727 |
} else { |
| 728 |
int host_cpus = libxl_get_online_cpus(ctx); |
| 729 |
|
| 730 |
if (host_cpus < 0) { |
| 731 |
fprintf(stderr, "Failed to get online cpus\n"); |
| 732 |
exit(EXIT_FAILURE); |
| 733 |
} |
| 734 |
|
| 735 |
if (host_cpus < max_vcpus) { |
| 736 |
fprintf(stderr, "xl: vnuma specifies more vcpus than pcpus, "\ |
| 737 |
"use maxvcpus= to override this check.\n"); |
| 738 |
exit(EXIT_FAILURE); |
| 739 |
} |
| 740 |
|
| 741 |
b_info->max_vcpus = max_vcpus; |
| 742 |
} |
| 743 |
|
| 744 |
/* User has specified maxmem= */ |
| 745 |
if (b_info->max_memkb != LIBXL_MEMKB_DEFAULT && |
| 746 |
b_info->max_memkb != max_memkb) { |
| 747 |
fprintf(stderr, "xl: maxmem and vnuma memory size mismatch\n"); |
| 748 |
exit(EXIT_FAILURE); |
| 749 |
} else |
| 750 |
b_info->max_memkb = max_memkb; |
| 751 |
|
| 752 |
for (i = 0; i < b_info->num_vnuma_nodes; i++) { |
| 753 |
libxl_vnode_info *p = &b_info->vnuma_nodes[i]; |
| 754 |
|
| 755 |
libxl_bitmap_copy_alloc(ctx, &p->vcpus, &vcpu_parsed[i]); |
| 756 |
libxl_bitmap_dispose(&vcpu_parsed[i]); |
| 757 |
} |
| 758 |
|
| 759 |
free(vcpu_parsed); |
| 760 |
} |
| 761 |
|
| 762 |
/* Parses usbctrl data and adds info into usbctrl |
| 763 |
* Returns 1 if the input token does not match one of the keys |
| 764 |
* or parsed values are not correct. Successful parse returns 0 */ |
| 765 |
int parse_usbctrl_config(libxl_device_usbctrl *usbctrl, char *token) |
| 766 |
{ |
| 767 |
char *oparg; |
| 768 |
|
| 769 |
if (MATCH_OPTION("type", token, oparg)) { |
| 770 |
if (libxl_usbctrl_type_from_string(oparg, &usbctrl->type)) { |
| 771 |
fprintf(stderr, "Invalid usb controller type '%s'\n", oparg); |
| 772 |
return 1; |
| 773 |
} |
| 774 |
} else if (MATCH_OPTION("version", token, oparg)) { |
| 775 |
usbctrl->version = atoi(oparg); |
| 776 |
} else if (MATCH_OPTION("ports", token, oparg)) { |
| 777 |
usbctrl->ports = atoi(oparg); |
| 778 |
} else { |
| 779 |
fprintf(stderr, "Unknown string `%s' in usbctrl spec\n", token); |
| 780 |
return 1; |
| 781 |
} |
| 782 |
|
| 783 |
return 0; |
| 784 |
} |
| 785 |
|
| 786 |
/* Parses usbdev data and adds info into usbdev |
| 787 |
* Returns 1 if the input token does not match one of the keys |
| 788 |
* or parsed values are not correct. Successful parse returns 0 */ |
| 789 |
int parse_usbdev_config(libxl_device_usbdev *usbdev, char *token) |
| 790 |
{ |
| 791 |
char *oparg; |
| 792 |
|
| 793 |
if (MATCH_OPTION("type", token, oparg)) { |
| 794 |
if (libxl_usbdev_type_from_string(oparg, &usbdev->type)) { |
| 795 |
fprintf(stderr, "Invalid usb device type: %s\n", optarg); |
| 796 |
return 1; |
| 797 |
} |
| 798 |
} else if (MATCH_OPTION("hostbus", token, oparg)) { |
| 799 |
usbdev->u.hostdev.hostbus = strtoul(oparg, NULL, 0); |
| 800 |
} else if (MATCH_OPTION("hostaddr", token, oparg)) { |
| 801 |
usbdev->u.hostdev.hostaddr = strtoul(oparg, NULL, 0); |
| 802 |
} else if (MATCH_OPTION("controller", token, oparg)) { |
| 803 |
usbdev->ctrl = atoi(oparg); |
| 804 |
} else if (MATCH_OPTION("port", token, oparg)) { |
| 805 |
usbdev->port = atoi(oparg); |
| 806 |
} else { |
| 807 |
fprintf(stderr, "Unknown string `%s' in usbdev spec\n", token); |
| 808 |
return 1; |
| 809 |
} |
| 810 |
|
| 811 |
return 0; |
| 812 |
} |
| 813 |
|
| 814 |
int parse_vdispl_config(libxl_device_vdispl *vdispl, char *token) |
| 815 |
{ |
| 816 |
char *oparg; |
| 817 |
libxl_string_list connectors = NULL; |
| 818 |
int i; |
| 819 |
int rc; |
| 820 |
|
| 821 |
if (MATCH_OPTION("backend", token, oparg)) { |
| 822 |
vdispl->backend_domname = strdup(oparg); |
| 823 |
} else if (MATCH_OPTION("be-alloc", token, oparg)) { |
| 824 |
vdispl->be_alloc = strtoul(oparg, NULL, 0); |
| 825 |
} else if (MATCH_OPTION("connectors", token, oparg)) { |
| 826 |
split_string_into_string_list(oparg, ";", &connectors); |
| 827 |
|
| 828 |
vdispl->num_connectors = libxl_string_list_length(&connectors); |
| 829 |
vdispl->connectors = xcalloc(vdispl->num_connectors, |
| 830 |
sizeof(*vdispl->connectors)); |
| 831 |
|
| 832 |
for(i = 0; i < vdispl->num_connectors; i++) |
| 833 |
{ |
| 834 |
char *resolution; |
| 835 |
|
| 836 |
rc = split_string_into_pair(connectors[i], ':', |
| 837 |
&vdispl->connectors[i].unique_id, |
| 838 |
&resolution, NULL); |
| 839 |
|
| 840 |
rc= sscanf(resolution, "%ux%u", &vdispl->connectors[i].width, |
| 841 |
&vdispl->connectors[i].height); |
| 842 |
free(resolution); |
| 843 |
|
| 844 |
if (rc != 2) { |
| 845 |
fprintf(stderr, "Can't parse connector resolution\n"); |
| 846 |
goto out; |
| 847 |
} |
| 848 |
} |
| 849 |
} else { |
| 850 |
fprintf(stderr, "Unknown string \"%s\" in vdispl spec\n", token); |
| 851 |
rc = 1; goto out; |
| 852 |
} |
| 853 |
|
| 854 |
rc = 0; |
| 855 |
|
| 856 |
out: |
| 857 |
libxl_string_list_dispose(&connectors); |
| 858 |
return rc; |
| 859 |
} |
| 860 |
|
| 861 |
static int parse_vsnd_params(libxl_vsnd_params *params, char *token) |
| 862 |
{ |
| 863 |
char *oparg; |
| 864 |
int i; |
| 865 |
|
| 866 |
if (MATCH_OPTION(XENSND_FIELD_SAMPLE_RATES, token, oparg)) { |
| 867 |
libxl_string_list rates = NULL; |
| 868 |
|
| 869 |
split_string_into_string_list(oparg, ";", &rates); |
| 870 |
|
| 871 |
params->num_sample_rates = libxl_string_list_length(&rates); |
| 872 |
params->sample_rates = xcalloc(params->num_sample_rates, |
| 873 |
sizeof(*params->sample_rates)); |
| 874 |
|
| 875 |
for (i = 0; i < params->num_sample_rates; i++) { |
| 876 |
params->sample_rates[i] = strtoul(rates[i], NULL, 0); |
| 877 |
} |
| 878 |
|
| 879 |
libxl_string_list_dispose(&rates); |
| 880 |
} else if (MATCH_OPTION(XENSND_FIELD_SAMPLE_FORMATS, token, oparg)) { |
| 881 |
libxl_string_list formats = NULL; |
| 882 |
|
| 883 |
split_string_into_string_list(oparg, ";", &formats); |
| 884 |
|
| 885 |
params->num_sample_formats = libxl_string_list_length(&formats); |
| 886 |
params->sample_formats = xcalloc(params->num_sample_formats, |
| 887 |
sizeof(*params->sample_formats)); |
| 888 |
|
| 889 |
for (i = 0; i < params->num_sample_formats; i++) { |
| 890 |
libxl_vsnd_pcm_format format; |
| 891 |
|
| 892 |
if (libxl_vsnd_pcm_format_from_string(formats[i], &format)) { |
| 893 |
fprintf(stderr, "Invalid pcm format: %s\n", formats[i]); |
| 894 |
exit(EXIT_FAILURE); |
| 895 |
} |
| 896 |
|
| 897 |
params->sample_formats[i] = format; |
| 898 |
} |
| 899 |
|
| 900 |
libxl_string_list_dispose(&formats); |
| 901 |
} else if (MATCH_OPTION(XENSND_FIELD_CHANNELS_MIN, token, oparg)) { |
| 902 |
params->channels_min = strtoul(oparg, NULL, 0); |
| 903 |
} else if (MATCH_OPTION(XENSND_FIELD_CHANNELS_MAX, token, oparg)) { |
| 904 |
params->channels_max = strtoul(oparg, NULL, 0); |
| 905 |
} else if (MATCH_OPTION(XENSND_FIELD_BUFFER_SIZE, token, oparg)) { |
| 906 |
params->buffer_size = strtoul(oparg, NULL, 0); |
| 907 |
} else { |
| 908 |
return 1; |
| 909 |
} |
| 910 |
|
| 911 |
return 0; |
| 912 |
} |
| 913 |
|
| 914 |
static int parse_vsnd_pcm_stream(libxl_device_vsnd *vsnd, char *param) |
| 915 |
{ |
| 916 |
if (vsnd->num_vsnd_pcms == 0) { |
| 917 |
fprintf(stderr, "No vsnd pcm device\n"); |
| 918 |
return -1; |
| 919 |
} |
| 920 |
|
| 921 |
libxl_vsnd_pcm *pcm = &vsnd->pcms[vsnd->num_vsnd_pcms - 1]; |
| 922 |
|
| 923 |
if (pcm->num_vsnd_streams == 0) { |
| 924 |
fprintf(stderr, "No vsnd stream\n"); |
| 925 |
return -1; |
| 926 |
} |
| 927 |
|
| 928 |
libxl_vsnd_stream *stream = &pcm->streams[pcm->num_vsnd_streams - 1]; |
| 929 |
|
| 930 |
if (parse_vsnd_params(&stream->params, param)) { |
| 931 |
char *oparg; |
| 932 |
|
| 933 |
if (MATCH_OPTION(XENSND_FIELD_STREAM_UNIQUE_ID, param, oparg)) { |
| 934 |
stream->unique_id = strdup(oparg); |
| 935 |
} else if (MATCH_OPTION(XENSND_FIELD_TYPE, param, oparg)) { |
| 936 |
if (libxl_vsnd_stream_type_from_string(oparg, &stream->type)) { |
| 937 |
fprintf(stderr, "Invalid stream type: %s\n", oparg); |
| 938 |
return -1; |
| 939 |
} |
| 940 |
} else { |
| 941 |
fprintf(stderr, "Invalid parameter: %s\n", param); |
| 942 |
return -1; |
| 943 |
} |
| 944 |
} |
| 945 |
|
| 946 |
return 0; |
| 947 |
} |
| 948 |
|
| 949 |
static int parse_vsnd_pcm_param(libxl_device_vsnd *vsnd, char *param) |
| 950 |
{ |
| 951 |
if (vsnd->num_vsnd_pcms == 0) { |
| 952 |
fprintf(stderr, "No pcm device\n"); |
| 953 |
return -1; |
| 954 |
} |
| 955 |
|
| 956 |
libxl_vsnd_pcm *pcm = &vsnd->pcms[vsnd->num_vsnd_pcms - 1]; |
| 957 |
|
| 958 |
if (parse_vsnd_params(&pcm->params, param)) { |
| 959 |
char *oparg; |
| 960 |
|
| 961 |
if (MATCH_OPTION(XENSND_FIELD_DEVICE_NAME, param, oparg)) { |
| 962 |
pcm->name = strdup(oparg); |
| 963 |
} else { |
| 964 |
fprintf(stderr, "Invalid parameter: %s\n", param); |
| 965 |
return -1; |
| 966 |
} |
| 967 |
} |
| 968 |
|
| 969 |
return 0; |
| 970 |
} |
| 971 |
|
| 972 |
static int parse_vsnd_card_param(libxl_device_vsnd *vsnd, char *param) |
| 973 |
{ |
| 974 |
if (parse_vsnd_params(&vsnd->params, param)) { |
| 975 |
char *oparg; |
| 976 |
|
| 977 |
if (MATCH_OPTION("backend", param, oparg)) { |
| 978 |
vsnd->backend_domname = strdup(oparg); |
| 979 |
} else if (MATCH_OPTION(XENSND_FIELD_VCARD_SHORT_NAME, param, oparg)) { |
| 980 |
vsnd->short_name = strdup(oparg); |
| 981 |
} else if (MATCH_OPTION(XENSND_FIELD_VCARD_LONG_NAME, param, oparg)) { |
| 982 |
vsnd->long_name = strdup(oparg); |
| 983 |
} else { |
| 984 |
fprintf(stderr, "Invalid parameter: %s\n", param); |
| 985 |
return -1; |
| 986 |
} |
| 987 |
} |
| 988 |
|
| 989 |
return 0; |
| 990 |
} |
| 991 |
|
| 992 |
static int parse_vsnd_create_item(libxl_device_vsnd *vsnd, const char *key) |
| 993 |
{ |
| 994 |
if (strcasecmp(key, "card") == 0) { |
| 995 |
|
| 996 |
} else if (strcasecmp(key, "pcm") == 0) { |
| 997 |
ARRAY_EXTEND_INIT_NODEVID(vsnd->pcms, vsnd->num_vsnd_pcms, |
| 998 |
libxl_vsnd_pcm_init); |
| 999 |
} else if (strcasecmp(key, "stream") == 0) { |
| 1000 |
if (vsnd->num_vsnd_pcms == 0) { |
| 1001 |
ARRAY_EXTEND_INIT_NODEVID(vsnd->pcms, vsnd->num_vsnd_pcms, |
| 1002 |
libxl_vsnd_pcm_init); |
| 1003 |
} |
| 1004 |
|
| 1005 |
libxl_vsnd_pcm *pcm = &vsnd->pcms[vsnd->num_vsnd_pcms - 1]; |
| 1006 |
|
| 1007 |
ARRAY_EXTEND_INIT_NODEVID(pcm->streams, pcm->num_vsnd_streams, |
| 1008 |
libxl_vsnd_stream_init); |
| 1009 |
} else { |
| 1010 |
fprintf(stderr, "Invalid key: %s\n", key); |
| 1011 |
return -1; |
| 1012 |
} |
| 1013 |
|
| 1014 |
return 0; |
| 1015 |
} |
| 1016 |
|
| 1017 |
int parse_vsnd_item(libxl_device_vsnd *vsnd, const char *spec) |
| 1018 |
{ |
| 1019 |
char *buf = strdup(spec); |
| 1020 |
char *token = strtok(buf, ","); |
| 1021 |
char *key = NULL; |
| 1022 |
int ret; |
| 1023 |
|
| 1024 |
while (token) { |
| 1025 |
while (*token == ' ') token++; |
| 1026 |
|
| 1027 |
if (!key) { |
| 1028 |
key = token; |
| 1029 |
ret = parse_vsnd_create_item(vsnd, key); |
| 1030 |
if (ret) goto out; |
| 1031 |
} else { |
| 1032 |
if (strcasecmp(key, "card") == 0) { |
| 1033 |
ret = parse_vsnd_card_param(vsnd, token); |
| 1034 |
if (ret) goto out; |
| 1035 |
} else if (strcasecmp(key, "pcm") == 0) { |
| 1036 |
ret = parse_vsnd_pcm_param(vsnd, token); |
| 1037 |
if (ret) goto out; |
| 1038 |
} else if (strcasecmp(key, "stream") == 0) { |
| 1039 |
ret = parse_vsnd_pcm_stream(vsnd, token); |
| 1040 |
if (ret) goto out; |
| 1041 |
} |
| 1042 |
} |
| 1043 |
token = strtok (NULL, ","); |
| 1044 |
} |
| 1045 |
|
| 1046 |
ret = 0; |
| 1047 |
|
| 1048 |
out: |
| 1049 |
free(buf); |
| 1050 |
return ret; |
| 1051 |
} |
| 1052 |
|
| 1053 |
static void parse_vsnd_card_config(const XLU_Config *config, |
| 1054 |
XLU_ConfigValue *card_value, |
| 1055 |
libxl_domain_config *d_config) |
| 1056 |
{ |
| 1057 |
int ret; |
| 1058 |
XLU_ConfigList *card_list; |
| 1059 |
libxl_device_vsnd *vsnd; |
| 1060 |
const char *card_item; |
| 1061 |
int item = 0; |
| 1062 |
|
| 1063 |
ret = xlu_cfg_value_get_list(config, card_value, &card_list, 0); |
| 1064 |
|
| 1065 |
if (ret) { |
| 1066 |
fprintf(stderr, "Failed to get vsnd card list: %s\n", strerror(ret)); |
| 1067 |
goto out; |
| 1068 |
} |
| 1069 |
|
| 1070 |
vsnd = ARRAY_EXTEND_INIT(d_config->vsnds, |
| 1071 |
d_config->num_vsnds, |
| 1072 |
libxl_device_vsnd_init); |
| 1073 |
|
| 1074 |
while ((card_item = xlu_cfg_get_listitem(card_list, item++)) != NULL) { |
| 1075 |
ret = parse_vsnd_item(vsnd, card_item); |
| 1076 |
if (ret) goto out; |
| 1077 |
} |
| 1078 |
|
| 1079 |
ret = 0; |
| 1080 |
|
| 1081 |
out: |
| 1082 |
|
| 1083 |
if (ret) exit(EXIT_FAILURE); |
| 1084 |
} |
| 1085 |
|
| 1086 |
static void parse_vsnd_config(const XLU_Config *config, |
| 1087 |
libxl_domain_config *d_config) |
| 1088 |
{ |
| 1089 |
XLU_ConfigList *vsnds; |
| 1090 |
|
| 1091 |
if (!xlu_cfg_get_list(config, "vsnd", &vsnds, 0, 0)) { |
| 1092 |
XLU_ConfigValue *card_value; |
| 1093 |
|
| 1094 |
d_config->num_vsnds = 0; |
| 1095 |
d_config->vsnds = NULL; |
| 1096 |
|
| 1097 |
while ((card_value = xlu_cfg_get_listitem2(vsnds, d_config->num_vsnds)) |
| 1098 |
!= NULL) { |
| 1099 |
parse_vsnd_card_config(config, card_value, d_config); |
| 1100 |
} |
| 1101 |
} |
| 1102 |
} |
| 1103 |
|
| 1104 |
int parse_vkb_config(libxl_device_vkb *vkb, char *token) |
| 1105 |
{ |
| 1106 |
char *oparg; |
| 1107 |
|
| 1108 |
if (MATCH_OPTION("backend", token, oparg)) { |
| 1109 |
vkb->backend_domname = strdup(oparg); |
| 1110 |
} else if (MATCH_OPTION("backend-type", token, oparg)) { |
| 1111 |
libxl_vkb_backend backend_type; |
| 1112 |
if (libxl_vkb_backend_from_string(oparg, &backend_type)) { |
| 1113 |
fprintf(stderr, "Unknown backend_type \"%s\" in vkb spec\n", |
| 1114 |
oparg); |
| 1115 |
return -1; |
| 1116 |
} |
| 1117 |
vkb->backend_type = backend_type; |
| 1118 |
} else if (MATCH_OPTION(XENKBD_FIELD_UNIQUE_ID, token, oparg)) { |
| 1119 |
vkb->unique_id = strdup(oparg); |
| 1120 |
} else if (MATCH_OPTION(XENKBD_FIELD_FEAT_DSBL_KEYBRD, token, oparg)) { |
| 1121 |
vkb->feature_disable_keyboard = strtoul(oparg, NULL, 0); |
| 1122 |
} else if (MATCH_OPTION(XENKBD_FIELD_FEAT_DSBL_POINTER, token, oparg)) { |
| 1123 |
vkb->feature_disable_pointer = strtoul(oparg, NULL, 0); |
| 1124 |
} else if (MATCH_OPTION(XENKBD_FIELD_FEAT_ABS_POINTER, token, oparg)) { |
| 1125 |
vkb->feature_abs_pointer = strtoul(oparg, NULL, 0); |
| 1126 |
} else if (MATCH_OPTION(XENKBD_FIELD_FEAT_RAW_POINTER, token, oparg)) { |
| 1127 |
vkb->feature_raw_pointer = strtoul(oparg, NULL, 0); |
| 1128 |
} else if (MATCH_OPTION(XENKBD_FIELD_FEAT_MTOUCH, token, oparg)) { |
| 1129 |
vkb->feature_multi_touch = strtoul(oparg, NULL, 0); |
| 1130 |
} else if (MATCH_OPTION(XENKBD_FIELD_MT_WIDTH, token, oparg)) { |
| 1131 |
vkb->multi_touch_width = strtoul(oparg, NULL, 0); |
| 1132 |
} else if (MATCH_OPTION(XENKBD_FIELD_MT_HEIGHT, token, oparg)) { |
| 1133 |
vkb->multi_touch_height = strtoul(oparg, NULL, 0); |
| 1134 |
} else if (MATCH_OPTION(XENKBD_FIELD_MT_NUM_CONTACTS, token, oparg)) { |
| 1135 |
vkb->multi_touch_num_contacts = strtoul(oparg, NULL, 0); |
| 1136 |
} else if (MATCH_OPTION(XENKBD_FIELD_WIDTH, token, oparg)) { |
| 1137 |
vkb->width = strtoul(oparg, NULL, 0); |
| 1138 |
} else if (MATCH_OPTION(XENKBD_FIELD_HEIGHT, token, oparg)) { |
| 1139 |
vkb->height = strtoul(oparg, NULL, 0); |
| 1140 |
} else { |
| 1141 |
fprintf(stderr, "Unknown string \"%s\" in vkb spec\n", token); |
| 1142 |
return -1; |
| 1143 |
} |
| 1144 |
|
| 1145 |
return 0; |
| 1146 |
} |
| 1147 |
|
| 1148 |
static void parse_vkb_list(const XLU_Config *config, |
| 1149 |
libxl_domain_config *d_config) |
| 1150 |
{ |
| 1151 |
XLU_ConfigList *vkbs; |
| 1152 |
const char *item; |
| 1153 |
char *buf = NULL; |
| 1154 |
int rc; |
| 1155 |
|
| 1156 |
if (!xlu_cfg_get_list (config, "vkb", &vkbs, 0, 0)) { |
| 1157 |
int entry = 0; |
| 1158 |
while ((item = xlu_cfg_get_listitem(vkbs, entry)) != NULL) { |
| 1159 |
libxl_device_vkb *vkb; |
| 1160 |
char *p; |
| 1161 |
|
| 1162 |
vkb = ARRAY_EXTEND_INIT(d_config->vkbs, |
| 1163 |
d_config->num_vkbs, |
| 1164 |
libxl_device_vkb_init); |
| 1165 |
|
| 1166 |
buf = strdup(item); |
| 1167 |
|
| 1168 |
p = strtok (buf, ","); |
| 1169 |
while (p != NULL) |
| 1170 |
{ |
| 1171 |
while (*p == ' ') p++; |
| 1172 |
|
| 1173 |
rc = parse_vkb_config(vkb, p); |
| 1174 |
if (rc) goto out; |
| 1175 |
|
| 1176 |
p = strtok (NULL, ","); |
| 1177 |
} |
| 1178 |
|
| 1179 |
if (vkb->backend_type == LIBXL_VKB_BACKEND_UNKNOWN) { |
| 1180 |
fprintf(stderr, "backend-type should be set in vkb spec\n"); |
| 1181 |
rc = ERROR_FAIL; goto out; |
| 1182 |
} |
| 1183 |
|
| 1184 |
if (vkb->multi_touch_height || vkb->multi_touch_width || |
| 1185 |
vkb->multi_touch_num_contacts) { |
| 1186 |
vkb->feature_multi_touch = true; |
| 1187 |
} |
| 1188 |
|
| 1189 |
if (vkb->feature_multi_touch && !(vkb->multi_touch_height || |
| 1190 |
vkb->multi_touch_width || vkb->multi_touch_num_contacts)) { |
| 1191 |
fprintf(stderr, XENKBD_FIELD_MT_WIDTH", "XENKBD_FIELD_MT_HEIGHT", " |
| 1192 |
XENKBD_FIELD_MT_NUM_CONTACTS" should be set for " |
| 1193 |
"multi touch in vkb spec\n"); |
| 1194 |
rc = ERROR_FAIL; goto out; |
| 1195 |
} |
| 1196 |
|
| 1197 |
entry++; |
| 1198 |
} |
| 1199 |
} |
| 1200 |
|
| 1201 |
rc = 0; |
| 1202 |
|
| 1203 |
out: |
| 1204 |
free(buf); |
| 1205 |
if (rc) exit(EXIT_FAILURE); |
| 1206 |
} |
| 1207 |
|
| 1208 |
static int parse_virtio_config(libxl_device_virtio *virtio, char *token) |
| 1209 |
{ |
| 1210 |
char *oparg; |
| 1211 |
int rc; |
| 1212 |
|
| 1213 |
if (MATCH_OPTION("backend", token, oparg)) { |
| 1214 |
virtio->backend_domname = strdup(oparg); |
| 1215 |
} else if (MATCH_OPTION("type", token, oparg)) { |
| 1216 |
virtio->type = strdup(oparg); |
| 1217 |
} else if (MATCH_OPTION("transport", token, oparg)) { |
| 1218 |
rc = libxl_virtio_transport_from_string(oparg, &virtio->transport); |
| 1219 |
if (rc) return rc; |
| 1220 |
} else if (MATCH_OPTION("grant_usage", token, oparg)) { |
| 1221 |
libxl_defbool_set(&virtio->grant_usage, strtoul(oparg, NULL, 0)); |
| 1222 |
} else { |
| 1223 |
fprintf(stderr, "Unknown string \"%s\" in virtio spec\n", token); |
| 1224 |
return -1; |
| 1225 |
} |
| 1226 |
|
| 1227 |
return 0; |
| 1228 |
} |
| 1229 |
|
| 1230 |
static void parse_virtio_list(const XLU_Config *config, |
| 1231 |
libxl_domain_config *d_config) |
| 1232 |
{ |
| 1233 |
XLU_ConfigList *virtios; |
| 1234 |
const char *item; |
| 1235 |
char *buf = NULL, *oparg, *str = NULL; |
| 1236 |
int rc; |
| 1237 |
|
| 1238 |
if (!xlu_cfg_get_list (config, "virtio", &virtios, 0, 0)) { |
| 1239 |
int entry = 0; |
| 1240 |
while ((item = xlu_cfg_get_listitem(virtios, entry)) != NULL) { |
| 1241 |
libxl_device_virtio *virtio; |
| 1242 |
char *p; |
| 1243 |
|
| 1244 |
virtio = ARRAY_EXTEND_INIT(d_config->virtios, d_config->num_virtios, |
| 1245 |
libxl_device_virtio_init); |
| 1246 |
|
| 1247 |
buf = strdup(item); |
| 1248 |
|
| 1249 |
p = strtok(buf, ","); |
| 1250 |
while (p != NULL) |
| 1251 |
{ |
| 1252 |
while (*p == ' ') p++; |
| 1253 |
|
| 1254 |
// Type may contain a comma, do special handling. |
| 1255 |
if (MATCH_OPTION("type", p, oparg)) { |
| 1256 |
if (!strncmp(oparg, "virtio", strlen("virtio"))) { |
| 1257 |
char *p2 = strtok(NULL, ","); |
| 1258 |
str = malloc(strlen(p) + strlen(p2) + 2); |
| 1259 |
|
| 1260 |
strcpy(str, p); |
| 1261 |
strcat(str, ","); |
| 1262 |
strcat(str, p2); |
| 1263 |
p = str; |
| 1264 |
} |
| 1265 |
} |
| 1266 |
|
| 1267 |
rc = parse_virtio_config(virtio, p); |
| 1268 |
if (rc) goto out; |
| 1269 |
|
| 1270 |
free(str); |
| 1271 |
str = NULL; |
| 1272 |
p = strtok(NULL, ","); |
| 1273 |
} |
| 1274 |
|
| 1275 |
entry++; |
| 1276 |
free(buf); |
| 1277 |
} |
| 1278 |
} |
| 1279 |
|
| 1280 |
return; |
| 1281 |
|
| 1282 |
out: |
| 1283 |
free(buf); |
| 1284 |
if (rc) exit(EXIT_FAILURE); |
| 1285 |
} |
| 1286 |
|
| 1287 |
void parse_config_data(const char *config_source, |
| 1288 |
const char *config_data, |
| 1289 |
int config_len, |
| 1290 |
libxl_domain_config *d_config) |
| 1291 |
{ |
| 1292 |
libxl_physinfo physinfo; |
| 1293 |
const char *buf; |
| 1294 |
long l, vcpus = 0; |
| 1295 |
XLU_Config *config; |
| 1296 |
XLU_ConfigList *cpus, *vbds, *nics, *pcis, *cvfbs, *cpuids, *vtpms, |
| 1297 |
*usbctrls, *usbdevs, *p9devs, *vdispls, *pvcallsifs_devs; |
| 1298 |
XLU_ConfigList *channels, *ioports, *irqs, *iomem, *viridian, *dtdevs, |
| 1299 |
*mca_caps, *smbios, *llc_colors; |
| 1300 |
int num_ioports, num_irqs, num_iomem, num_cpus, num_viridian, num_mca_caps; |
| 1301 |
int num_smbios; |
| 1302 |
int pci_power_mgmt = 0; |
| 1303 |
int pci_msitranslate = 0; |
| 1304 |
int pci_permissive = 0; |
| 1305 |
int pci_seize = 0; |
| 1306 |
int i, e; |
| 1307 |
int num_llc_colors; |
| 1308 |
char *kernel_basename; |
| 1309 |
|
| 1310 |
libxl_domain_create_info *c_info = &d_config->c_info; |
| 1311 |
libxl_domain_build_info *b_info = &d_config->b_info; |
| 1312 |
|
| 1313 |
libxl_physinfo_init(&physinfo); |
| 1314 |
if (libxl_get_physinfo(ctx, &physinfo) != 0) { |
| 1315 |
libxl_physinfo_dispose(&physinfo); |
| 1316 |
fprintf(stderr, "libxl_get_physinfo failed\n"); |
| 1317 |
exit(EXIT_FAILURE); |
| 1318 |
} |
| 1319 |
|
| 1320 |
libxl_physinfo_dispose(&physinfo); |
| 1321 |
|
| 1322 |
config= xlu_cfg_init(stderr, config_source); |
| 1323 |
if (!config) { |
| 1324 |
fprintf(stderr, "Failed to allocate for configuration\n"); |
| 1325 |
exit(1); |
| 1326 |
} |
| 1327 |
|
| 1328 |
e= xlu_cfg_readdata(config, config_data, config_len); |
| 1329 |
if (e) { |
| 1330 |
fprintf(stderr, "Failed to parse config: %s\n", strerror(e)); |
| 1331 |
exit(1); |
| 1332 |
} |
| 1333 |
|
| 1334 |
if (!xlu_cfg_get_string (config, "init_seclabel", &buf, 0)) |
| 1335 |
xlu_cfg_replace_string(config, "init_seclabel", |
| 1336 |
&c_info->ssid_label, 0); |
| 1337 |
|
| 1338 |
if (!xlu_cfg_get_string (config, "seclabel", &buf, 0)) { |
| 1339 |
if (c_info->ssid_label) |
| 1340 |
xlu_cfg_replace_string(config, "seclabel", |
| 1341 |
&b_info->exec_ssid_label, 0); |
| 1342 |
else |
| 1343 |
xlu_cfg_replace_string(config, "seclabel", |
| 1344 |
&c_info->ssid_label, 0); |
| 1345 |
} |
| 1346 |
|
| 1347 |
libxl_defbool_set(&c_info->run_hotplug_scripts, run_hotplug_scripts); |
| 1348 |
|
| 1349 |
if (!xlu_cfg_get_string(config, "type", &buf, 0)) { |
| 1350 |
if (!strncmp(buf, "hvm", strlen(buf))) |
| 1351 |
c_info->type = LIBXL_DOMAIN_TYPE_HVM; |
| 1352 |
else if (!strncmp(buf, "pv", strlen(buf))) |
| 1353 |
c_info->type = LIBXL_DOMAIN_TYPE_PV; |
| 1354 |
else if (!strncmp(buf, "pvh", strlen(buf))) |
| 1355 |
c_info->type = LIBXL_DOMAIN_TYPE_PVH; |
| 1356 |
else { |
| 1357 |
fprintf(stderr, "Invalid domain type %s.\n", buf); |
| 1358 |
exit(1); |
| 1359 |
} |
| 1360 |
} |
| 1361 |
|
| 1362 |
/* Deprecated since Xen 4.10. */ |
| 1363 |
if (!xlu_cfg_get_string(config, "builder", &buf, 0)) { |
| 1364 |
libxl_domain_type builder_type; |
| 1365 |
|
| 1366 |
if (!strncmp(buf, "hvm", strlen(buf))) |
| 1367 |
builder_type = LIBXL_DOMAIN_TYPE_HVM; |
| 1368 |
else if (!strncmp(buf, "generic", strlen(buf))) |
| 1369 |
builder_type = LIBXL_DOMAIN_TYPE_PV; |
| 1370 |
else { |
| 1371 |
fprintf(stderr, "Invalid domain type %s.\n", buf); |
| 1372 |
exit(1); |
| 1373 |
} |
| 1374 |
|
| 1375 |
if (c_info->type != LIBXL_DOMAIN_TYPE_INVALID && |
| 1376 |
c_info->type != builder_type) { |
| 1377 |
fprintf(stderr, |
| 1378 |
"Contradicting \"builder\" and \"type\" options specified.\n"); |
| 1379 |
exit(1); |
| 1380 |
} |
| 1381 |
c_info->type = builder_type; |
| 1382 |
} |
| 1383 |
|
| 1384 |
if (c_info->type == LIBXL_DOMAIN_TYPE_INVALID) |
| 1385 |
#if defined(__arm__) || defined(__aarch64__) |
| 1386 |
c_info->type = LIBXL_DOMAIN_TYPE_PVH; |
| 1387 |
#else |
| 1388 |
c_info->type = LIBXL_DOMAIN_TYPE_PV; |
| 1389 |
#endif |
| 1390 |
|
| 1391 |
xlu_cfg_get_defbool(config, "hap", &c_info->hap, 0); |
| 1392 |
|
| 1393 |
if (xlu_cfg_replace_string (config, "name", &c_info->name, 0)) { |
| 1394 |
fprintf(stderr, "Domain name must be specified.\n"); |
| 1395 |
exit(1); |
| 1396 |
} |
| 1397 |
|
| 1398 |
if (!xlu_cfg_get_string (config, "uuid", &buf, 0) ) { |
| 1399 |
if ( libxl_uuid_from_string(&c_info->uuid, buf) ) { |
| 1400 |
fprintf(stderr, "Failed to parse UUID: %s\n", buf); |
| 1401 |
exit(1); |
| 1402 |
} |
| 1403 |
}else{ |
| 1404 |
libxl_uuid_generate(&c_info->uuid); |
| 1405 |
} |
| 1406 |
|
| 1407 |
xlu_cfg_get_defbool(config, "oos", &c_info->oos, 0); |
| 1408 |
|
| 1409 |
if (!xlu_cfg_get_string (config, "pool", &buf, 0)) |
| 1410 |
xlu_cfg_replace_string(config, "pool", &c_info->pool_name, 0); |
| 1411 |
|
| 1412 |
libxl_domain_build_info_init_type(b_info, c_info->type); |
| 1413 |
|
| 1414 |
if (b_info->type == LIBXL_DOMAIN_TYPE_PVH) { |
| 1415 |
xlu_cfg_get_defbool(config, "pvshim", &b_info->u.pvh.pvshim, 0); |
| 1416 |
if (!xlu_cfg_get_string(config, "pvshim_path", &buf, 0)) |
| 1417 |
xlu_cfg_replace_string(config, "pvshim_path", |
| 1418 |
&b_info->u.pvh.pvshim_path, 0); |
| 1419 |
if (!xlu_cfg_get_string(config, "pvshim_cmdline", &buf, 0)) |
| 1420 |
xlu_cfg_replace_string(config, "pvshim_cmdline", |
| 1421 |
&b_info->u.pvh.pvshim_cmdline, 0); |
| 1422 |
if (!xlu_cfg_get_string(config, "pvshim_extra", &buf, 0)) |
| 1423 |
xlu_cfg_replace_string(config, "pvshim_extra", |
| 1424 |
&b_info->u.pvh.pvshim_extra, 0); |
| 1425 |
} |
| 1426 |
|
| 1427 |
if (blkdev_start) |
| 1428 |
b_info->blkdev_start = strdup(blkdev_start); |
| 1429 |
|
| 1430 |
/* the following is the actual config parsing with overriding |
| 1431 |
* values in the structures */ |
| 1432 |
if (!xlu_cfg_get_long (config, "cpu_weight", &l, 0)) |
| 1433 |
b_info->sched_params.weight = l; |
| 1434 |
if (!xlu_cfg_get_long (config, "cap", &l, 0)) |
| 1435 |
b_info->sched_params.cap = l; |
| 1436 |
if (!xlu_cfg_get_long (config, "period", &l, 0)) |
| 1437 |
b_info->sched_params.period = l; |
| 1438 |
if (!xlu_cfg_get_long (config, "slice", &l, 0)) |
| 1439 |
b_info->sched_params.slice = l; |
| 1440 |
if (!xlu_cfg_get_long (config, "latency", &l, 0)) |
| 1441 |
b_info->sched_params.latency = l; |
| 1442 |
if (!xlu_cfg_get_long (config, "extratime", &l, 0)) |
| 1443 |
b_info->sched_params.extratime = l; |
| 1444 |
|
| 1445 |
if (!xlu_cfg_get_long (config, "memory", &l, 0)) |
| 1446 |
b_info->target_memkb = l * 1024; |
| 1447 |
|
| 1448 |
if (!xlu_cfg_get_long (config, "maxmem", &l, 0)) |
| 1449 |
b_info->max_memkb = l * 1024; |
| 1450 |
|
| 1451 |
if (!xlu_cfg_get_list(config, "llc_colors", &llc_colors, &num_llc_colors, 0)) { |
| 1452 |
int cur_index = 0; |
| 1453 |
|
| 1454 |
b_info->num_llc_colors = 0; |
| 1455 |
for (i = 0; i < num_llc_colors; i++) { |
| 1456 |
uint32_t start = 0, end = 0, k; |
| 1457 |
|
| 1458 |
buf = xlu_cfg_get_listitem(llc_colors, i); |
| 1459 |
if (!buf) { |
| 1460 |
fprintf(stderr, |
| 1461 |
"xl: Can't get element %d in LLC color list\n", i); |
| 1462 |
exit(1); |
| 1463 |
} |
| 1464 |
|
| 1465 |
if (sscanf(buf, "%" SCNu32 "-%" SCNu32, &start, &end) != 2) { |
| 1466 |
if (sscanf(buf, "%" SCNu32, &start) != 1) { |
| 1467 |
fprintf(stderr, "xl: Invalid LLC color range: %s\n", buf); |
| 1468 |
exit(1); |
| 1469 |
} |
| 1470 |
end = start; |
| 1471 |
} else if (start > end) { |
| 1472 |
fprintf(stderr, |
| 1473 |
"xl: Start LLC color is greater than end: %s\n", buf); |
| 1474 |
exit(1); |
| 1475 |
} |
| 1476 |
|
| 1477 |
b_info->num_llc_colors += (end - start) + 1; |
| 1478 |
b_info->llc_colors = (uint32_t *)realloc(b_info->llc_colors, |
| 1479 |
sizeof(*b_info->llc_colors) * b_info->num_llc_colors); |
| 1480 |
|
| 1481 |
for (k = start; k <= end; k++) |
| 1482 |
b_info->llc_colors[cur_index++] = k; |
| 1483 |
} |
| 1484 |
} |
| 1485 |
|
| 1486 |
if (!xlu_cfg_get_long (config, "vcpus", &l, 0)) { |
| 1487 |
vcpus = l; |
| 1488 |
if (libxl_cpu_bitmap_alloc(ctx, &b_info->avail_vcpus, l)) { |
| 1489 |
fprintf(stderr, "Unable to allocate cpumap\n"); |
| 1490 |
exit(1); |
| 1491 |
} |
| 1492 |
libxl_bitmap_set_none(&b_info->avail_vcpus); |
| 1493 |
while (l-- > 0) |
| 1494 |
libxl_bitmap_set((&b_info->avail_vcpus), l); |
| 1495 |
} |
| 1496 |
|
| 1497 |
if (!xlu_cfg_get_long (config, "maxvcpus", &l, 0)) |
| 1498 |
b_info->max_vcpus = l; |
| 1499 |
|
| 1500 |
if (!xlu_cfg_get_string(config, "vuart", &buf, 0)) { |
| 1501 |
if (libxl_vuart_type_from_string(buf, &b_info->arch_arm.vuart)) { |
| 1502 |
fprintf(stderr, "ERROR: invalid value \"%s\" for \"vuart\"\n", |
| 1503 |
buf); |
| 1504 |
exit(1); |
| 1505 |
} |
| 1506 |
} |
| 1507 |
|
| 1508 |
parse_vnuma_config(config, b_info); |
| 1509 |
|
| 1510 |
/* Set max_memkb to target_memkb and max_vcpus to avail_vcpus if |
| 1511 |
* they are not set by user specified config option or vnuma. |
| 1512 |
*/ |
| 1513 |
if (b_info->max_memkb == LIBXL_MEMKB_DEFAULT) |
| 1514 |
b_info->max_memkb = b_info->target_memkb; |
| 1515 |
if (b_info->max_vcpus == 0) |
| 1516 |
b_info->max_vcpus = vcpus; |
| 1517 |
|
| 1518 |
if (b_info->max_vcpus < vcpus) { |
| 1519 |
fprintf(stderr, "xl: maxvcpus < vcpus\n"); |
| 1520 |
exit(1); |
| 1521 |
} |
| 1522 |
|
| 1523 |
buf = NULL; |
| 1524 |
if (!xlu_cfg_get_list (config, "cpus", &cpus, &num_cpus, 1) || |
| 1525 |
!xlu_cfg_get_string (config, "cpus", &buf, 0)) |
| 1526 |
parse_vcpu_affinity(b_info, cpus, buf, num_cpus, /* is_hard */ true); |
| 1527 |
|
| 1528 |
buf = NULL; |
| 1529 |
if (!xlu_cfg_get_list (config, "cpus_soft", &cpus, &num_cpus, 1) || |
| 1530 |
!xlu_cfg_get_string (config, "cpus_soft", &buf, 0)) |
| 1531 |
parse_vcpu_affinity(b_info, cpus, buf, num_cpus, false); |
| 1532 |
|
| 1533 |
e = xlu_cfg_get_bounded_long (config, "max_grant_frames", 0, INT_MAX, |
| 1534 |
&l, 1); |
| 1535 |
if (e == ESRCH) /* not specified */ |
| 1536 |
b_info->max_grant_frames = max_grant_frames; |
| 1537 |
else if (!e) |
| 1538 |
b_info->max_grant_frames = l; |
| 1539 |
else |
| 1540 |
exit(1); |
| 1541 |
|
| 1542 |
e = xlu_cfg_get_bounded_long (config, "max_maptrack_frames", 0, |
| 1543 |
INT_MAX, &l, 1); |
| 1544 |
if (e == ESRCH) /* not specified */ |
| 1545 |
b_info->max_maptrack_frames = max_maptrack_frames; |
| 1546 |
else if (!e) |
| 1547 |
b_info->max_maptrack_frames = l; |
| 1548 |
else |
| 1549 |
exit(1); |
| 1550 |
|
| 1551 |
e = xlu_cfg_get_bounded_long (config, "max_grant_version", 0, |
| 1552 |
INT_MAX, &l, 1); |
| 1553 |
if (e == ESRCH) /* not specified */ |
| 1554 |
b_info->max_grant_version = max_grant_version; |
| 1555 |
else if (!e) |
| 1556 |
b_info->max_grant_version = l; |
| 1557 |
else |
| 1558 |
exit(1); |
| 1559 |
|
| 1560 |
libxl_defbool_set(&b_info->claim_mode, claim_mode); |
| 1561 |
|
| 1562 |
if (xlu_cfg_get_string (config, "on_poweroff", &buf, 0)) |
| 1563 |
buf = "destroy"; |
| 1564 |
if (!parse_action_on_shutdown(buf, &d_config->on_poweroff)) { |
| 1565 |
fprintf(stderr, "Unknown on_poweroff action \"%s\" specified\n", buf); |
| 1566 |
exit(1); |
| 1567 |
} |
| 1568 |
|
| 1569 |
if (xlu_cfg_get_string (config, "on_reboot", &buf, 0)) |
| 1570 |
buf = "restart"; |
| 1571 |
if (!parse_action_on_shutdown(buf, &d_config->on_reboot)) { |
| 1572 |
fprintf(stderr, "Unknown on_reboot action \"%s\" specified\n", buf); |
| 1573 |
exit(1); |
| 1574 |
} |
| 1575 |
|
| 1576 |
if (xlu_cfg_get_string (config, "on_watchdog", &buf, 0)) |
| 1577 |
buf = "destroy"; |
| 1578 |
if (!parse_action_on_shutdown(buf, &d_config->on_watchdog)) { |
| 1579 |
fprintf(stderr, "Unknown on_watchdog action \"%s\" specified\n", buf); |
| 1580 |
exit(1); |
| 1581 |
} |
| 1582 |
|
| 1583 |
|
| 1584 |
if (xlu_cfg_get_string (config, "on_crash", &buf, 0)) |
| 1585 |
buf = "destroy"; |
| 1586 |
if (!parse_action_on_shutdown(buf, &d_config->on_crash)) { |
| 1587 |
fprintf(stderr, "Unknown on_crash action \"%s\" specified\n", buf); |
| 1588 |
exit(1); |
| 1589 |
} |
| 1590 |
|
| 1591 |
if (xlu_cfg_get_string (config, "on_soft_reset", &buf, 0)) |
| 1592 |
buf = "soft-reset"; |
| 1593 |
if (!parse_action_on_shutdown(buf, &d_config->on_soft_reset)) { |
| 1594 |
fprintf(stderr, "Unknown on_soft_reset action \"%s\" specified\n", buf); |
| 1595 |
exit(1); |
| 1596 |
} |
| 1597 |
|
| 1598 |
/* To be reworked (automatically enabled) once the auto ballooning |
| 1599 |
* after guest starts is done (with PCI devices passed in). */ |
| 1600 |
if (c_info->type == LIBXL_DOMAIN_TYPE_PV) { |
| 1601 |
xlu_cfg_get_defbool(config, "e820_host", &b_info->u.pv.e820_host, 0); |
| 1602 |
} |
| 1603 |
|
| 1604 |
if (!xlu_cfg_get_long (config, "pci_msitranslate", &l, 0)) |
| 1605 |
pci_msitranslate = l; |
| 1606 |
|
| 1607 |
if (!xlu_cfg_get_long (config, "pci_power_mgmt", &l, 0)) |
| 1608 |
pci_power_mgmt = l; |
| 1609 |
|
| 1610 |
if (!xlu_cfg_get_long (config, "pci_permissive", &l, 0)) |
| 1611 |
pci_permissive = l; |
| 1612 |
|
| 1613 |
if (!xlu_cfg_get_long (config, "pci_seize", &l, 0)) |
| 1614 |
pci_seize = l; |
| 1615 |
|
| 1616 |
if (!xlu_cfg_get_string(config, "rdm", &buf, 0)) { |
| 1617 |
libxl_rdm_reserve rdm; |
| 1618 |
if (!xlu_rdm_parse(config, &rdm, buf)) { |
| 1619 |
b_info->u.hvm.rdm.strategy = rdm.strategy; |
| 1620 |
b_info->u.hvm.rdm.policy = rdm.policy; |
| 1621 |
} |
| 1622 |
} |
| 1623 |
|
| 1624 |
if (!xlu_cfg_get_list (config, "pci", &pcis, 0, 0)) { |
| 1625 |
d_config->num_pcidevs = 0; |
| 1626 |
d_config->pcidevs = NULL; |
| 1627 |
for(i = 0; (buf = xlu_cfg_get_listitem (pcis, i)) != NULL; i++) { |
| 1628 |
libxl_device_pci *pci; |
| 1629 |
|
| 1630 |
pci = ARRAY_EXTEND_INIT_NODEVID(d_config->pcidevs, |
| 1631 |
d_config->num_pcidevs, |
| 1632 |
libxl_device_pci_init); |
| 1633 |
pci->msitranslate = pci_msitranslate; |
| 1634 |
pci->power_mgmt = pci_power_mgmt; |
| 1635 |
pci->permissive = pci_permissive; |
| 1636 |
pci->seize = pci_seize; |
| 1637 |
/* |
| 1638 |
* Like other pci option, the per-device policy always follows |
| 1639 |
* the global policy by default. |
| 1640 |
*/ |
| 1641 |
pci->rdm_policy = b_info->u.hvm.rdm.policy; |
| 1642 |
e = xlu_pci_parse_spec_string(config, pci, buf); |
| 1643 |
if (e) { |
| 1644 |
fprintf(stderr, |
| 1645 |
"unable to parse PCI_SPEC_STRING `%s' for passthrough\n", |
| 1646 |
buf); |
| 1647 |
exit(-e); |
| 1648 |
} |
| 1649 |
} |
| 1650 |
if (d_config->num_pcidevs && c_info->type == LIBXL_DOMAIN_TYPE_PV) |
| 1651 |
libxl_defbool_set(&b_info->u.pv.e820_host, true); |
| 1652 |
} |
| 1653 |
|
| 1654 |
if (!xlu_cfg_get_list (config, "dtdev", &dtdevs, 0, 0)) { |
| 1655 |
d_config->num_dtdevs = 0; |
| 1656 |
d_config->dtdevs = NULL; |
| 1657 |
for (i = 0; (buf = xlu_cfg_get_listitem(dtdevs, i)) != NULL; i++) { |
| 1658 |
libxl_device_dtdev *dtdev; |
| 1659 |
|
| 1660 |
dtdev = ARRAY_EXTEND_INIT_NODEVID(d_config->dtdevs, |
| 1661 |
d_config->num_dtdevs, |
| 1662 |
libxl_device_dtdev_init); |
| 1663 |
|
| 1664 |
dtdev->path = strdup(buf); |
| 1665 |
if (dtdev->path == NULL) { |
| 1666 |
fprintf(stderr, "unable to duplicate string for dtdevs\n"); |
| 1667 |
exit(-1); |
| 1668 |
} |
| 1669 |
} |
| 1670 |
} |
| 1671 |
|
| 1672 |
if (!xlu_cfg_get_string(config, "passthrough", &buf, 0)) { |
| 1673 |
if (libxl_passthrough_from_string(buf, &c_info->passthrough)) { |
| 1674 |
fprintf(stderr, |
| 1675 |
"ERROR: unknown passthrough option '%s'\n", |
| 1676 |
buf); |
| 1677 |
exit(1); |
| 1678 |
} |
| 1679 |
} |
| 1680 |
|
| 1681 |
if (!xlu_cfg_get_long(config, "shadow_memory", &l, 0)) |
| 1682 |
b_info->shadow_memkb = l * 1024; |
| 1683 |
|
| 1684 |
xlu_cfg_get_defbool(config, "nomigrate", &b_info->disable_migrate, 0); |
| 1685 |
|
| 1686 |
if (!xlu_cfg_get_long(config, "tsc_mode", &l, 1)) { |
| 1687 |
const char *s = libxl_tsc_mode_to_string(l); |
| 1688 |
fprintf(stderr, "WARNING: specifying \"tsc_mode\" as an integer is deprecated. " |
| 1689 |
"Please use the named parameter variant. %s%s%s\n", |
| 1690 |
s ? "e.g. tsc_mode=\"" : "", |
| 1691 |
s ? s : "", |
| 1692 |
s ? "\"" : ""); |
| 1693 |
|
| 1694 |
if (l < LIBXL_TSC_MODE_DEFAULT || |
| 1695 |
l > LIBXL_TSC_MODE_NATIVE_PARAVIRT) { |
| 1696 |
fprintf(stderr, "ERROR: invalid value %ld for \"tsc_mode\"\n", l); |
| 1697 |
exit (1); |
| 1698 |
} |
| 1699 |
b_info->tsc_mode = l; |
| 1700 |
} else if (!xlu_cfg_get_string(config, "tsc_mode", &buf, 0)) { |
| 1701 |
if (libxl_tsc_mode_from_string(buf, &b_info->tsc_mode)) { |
| 1702 |
fprintf(stderr, "ERROR: invalid value \"%s\" for \"tsc_mode\"\n", |
| 1703 |
buf); |
| 1704 |
exit (1); |
| 1705 |
} |
| 1706 |
} |
| 1707 |
|
| 1708 |
if (!xlu_cfg_get_long(config, "rtc_timeoffset", &l, 0)) |
| 1709 |
b_info->rtc_timeoffset = l; |
| 1710 |
|
| 1711 |
if (!xlu_cfg_get_long(config, "vncviewer", &l, 0)) |
| 1712 |
fprintf(stderr, "WARNING: ignoring \"vncviewer\" option. " |
| 1713 |
"Use \"-V\" option of \"xl create\" to automatically spawn vncviewer.\n"); |
| 1714 |
|
| 1715 |
xlu_cfg_get_defbool(config, "localtime", &b_info->localtime, 0); |
| 1716 |
|
| 1717 |
if (!xlu_cfg_get_long (config, "videoram", &l, 0)) |
| 1718 |
b_info->video_memkb = l * 1024; |
| 1719 |
|
| 1720 |
if (!xlu_cfg_get_long(config, "max_event_channels", &l, 0)) |
| 1721 |
b_info->event_channels = l; |
| 1722 |
|
| 1723 |
xlu_cfg_replace_string (config, "kernel", &b_info->kernel, 0); |
| 1724 |
xlu_cfg_replace_string (config, "ramdisk", &b_info->ramdisk, 0); |
| 1725 |
xlu_cfg_replace_string (config, "device_tree", &b_info->device_tree, 0); |
| 1726 |
b_info->cmdline = parse_cmdline(config); |
| 1727 |
|
| 1728 |
xlu_cfg_get_defbool(config, "driver_domain", &c_info->driver_domain, 0); |
| 1729 |
xlu_cfg_get_defbool(config, "acpi", &b_info->acpi, 0); |
| 1730 |
|
| 1731 |
xlu_cfg_replace_string (config, "bootloader", &b_info->bootloader, 0); |
| 1732 |
#ifndef HAVE_PYGRUB |
| 1733 |
if (b_info->bootloader && |
| 1734 |
(!strcmp(b_info->bootloader, "pygrub") || |
| 1735 |
!strcmp(b_info->bootloader, "/usr/bin/pygrub"))) { |
| 1736 |
fprintf(stderr, "ERROR: this instance of Xen has been built without support of \"pygrub\".\n"); |
| 1737 |
exit(-ERROR_FAIL); |
| 1738 |
} |
| 1739 |
#endif |
| 1740 |
xlu_cfg_get_defbool(config, "bootloader_restrict", |
| 1741 |
&b_info->bootloader_restrict, 0); |
| 1742 |
if (!libxl_defbool_is_default(bootloader_restrict)) |
| 1743 |
libxl_defbool_setdefault(&b_info->bootloader_restrict, |
| 1744 |
libxl_defbool_val(bootloader_restrict)); |
| 1745 |
xlu_cfg_replace_string(config, "bootloader_user", |
| 1746 |
&b_info->bootloader_user, 0); |
| 1747 |
|
| 1748 |
switch (xlu_cfg_get_list_as_string_list(config, "bootloader_args", |
| 1749 |
&b_info->bootloader_args, 1)) { |
| 1750 |
case 0: |
| 1751 |
break; /* Success */ |
| 1752 |
case ESRCH: break; /* Option not present */ |
| 1753 |
case EINVAL: |
| 1754 |
if (!xlu_cfg_get_string(config, "bootloader_args", &buf, 0)) { |
| 1755 |
|
| 1756 |
fprintf(stderr, "WARNING: Specifying \"bootloader_args\"" |
| 1757 |
" as a string is deprecated. " |
| 1758 |
"Please use a list of arguments.\n"); |
| 1759 |
split_string_into_string_list(buf, " \t\n", |
| 1760 |
&b_info->bootloader_args); |
| 1761 |
} |
| 1762 |
break; |
| 1763 |
default: |
| 1764 |
fprintf(stderr,"xl: Unable to parse bootloader_args.\n"); |
| 1765 |
exit(-ERROR_FAIL); |
| 1766 |
} |
| 1767 |
|
| 1768 |
if (!xlu_cfg_get_long(config, "timer_mode", &l, 1)) { |
| 1769 |
const char *s = libxl_timer_mode_to_string(l); |
| 1770 |
|
| 1771 |
if (b_info->type == LIBXL_DOMAIN_TYPE_PV) { |
| 1772 |
fprintf(stderr, |
| 1773 |
"ERROR: \"timer_mode\" option is not supported for PV guests.\n"); |
| 1774 |
exit(-ERROR_FAIL); |
| 1775 |
} |
| 1776 |
|
| 1777 |
fprintf(stderr, |
| 1778 |
"WARNING: specifying \"timer_mode\" as an integer is deprecated. " |
| 1779 |
"Please use the named parameter variant. %s%s%s\n", |
| 1780 |
s ? "e.g. timer_mode=\"" : "", |
| 1781 |
s ? s : "", |
| 1782 |
s ? "\"" : ""); |
| 1783 |
|
| 1784 |
if (l < LIBXL_TIMER_MODE_DELAY_FOR_MISSED_TICKS || |
| 1785 |
l > LIBXL_TIMER_MODE_ONE_MISSED_TICK_PENDING) { |
| 1786 |
fprintf(stderr, "ERROR: invalid value %ld for \"timer_mode\"\n", |
| 1787 |
l); |
| 1788 |
exit (1); |
| 1789 |
} |
| 1790 |
b_info->timer_mode = l; |
| 1791 |
} else if (!xlu_cfg_get_string(config, "timer_mode", &buf, 0)) { |
| 1792 |
if (b_info->type == LIBXL_DOMAIN_TYPE_PV) { |
| 1793 |
fprintf(stderr, |
| 1794 |
"ERROR: \"timer_mode\" option is not supported for PV guests.\n"); |
| 1795 |
exit(-ERROR_FAIL); |
| 1796 |
} |
| 1797 |
|
| 1798 |
if (libxl_timer_mode_from_string(buf, &b_info->timer_mode)) { |
| 1799 |
fprintf(stderr, |
| 1800 |
"ERROR: invalid value \"%s\" for \"timer_mode\"\n", buf); |
| 1801 |
exit (1); |
| 1802 |
} |
| 1803 |
} |
| 1804 |
|
| 1805 |
xlu_cfg_get_defbool(config, "nestedhvm", &b_info->nested_hvm, 0); |
| 1806 |
|
| 1807 |
switch(b_info->type) { |
| 1808 |
case LIBXL_DOMAIN_TYPE_HVM: |
| 1809 |
kernel_basename = libxl_basename(b_info->kernel); |
| 1810 |
if (!strcmp(kernel_basename, "hvmloader")) { |
| 1811 |
fprintf(stderr, "WARNING: you seem to be using \"kernel\" " |
| 1812 |
"directive to override HVM guest firmware. Ignore " |
| 1813 |
"that. Use \"firmware_override\" instead if you " |
| 1814 |
"really want a non-default firmware\n"); |
| 1815 |
b_info->kernel = NULL; |
| 1816 |
} |
| 1817 |
free(kernel_basename); |
| 1818 |
|
| 1819 |
xlu_cfg_replace_string (config, "firmware_override", |
| 1820 |
&b_info->u.hvm.firmware, 0); |
| 1821 |
xlu_cfg_replace_string (config, "bios_path_override", |
| 1822 |
&b_info->u.hvm.system_firmware, 0); |
| 1823 |
if (!xlu_cfg_get_string(config, "bios", &buf, 0)) { |
| 1824 |
if (libxl_bios_type_from_string(buf, &b_info->u.hvm.bios)) { |
| 1825 |
fprintf(stderr, "ERROR: invalid value \"%s\" for \"bios\"\n", |
| 1826 |
buf); |
| 1827 |
exit (1); |
| 1828 |
} |
| 1829 |
} else if (b_info->u.hvm.system_firmware) |
| 1830 |
fprintf(stderr, "WARNING: " |
| 1831 |
"bios_path_override given without specific bios name\n"); |
| 1832 |
|
| 1833 |
xlu_cfg_get_defbool(config, "pae", &b_info->u.hvm.pae, 0); |
| 1834 |
xlu_cfg_get_defbool(config, "acpi_s3", &b_info->u.hvm.acpi_s3, 0); |
| 1835 |
xlu_cfg_get_defbool(config, "acpi_s4", &b_info->u.hvm.acpi_s4, 0); |
| 1836 |
xlu_cfg_get_defbool(config, "acpi_laptop_slate", &b_info->u.hvm.acpi_laptop_slate, 0); |
| 1837 |
xlu_cfg_get_defbool(config, "nx", &b_info->u.hvm.nx, 0); |
| 1838 |
xlu_cfg_get_defbool(config, "hpet", &b_info->u.hvm.hpet, 0); |
| 1839 |
xlu_cfg_get_defbool(config, "vpt_align", &b_info->u.hvm.vpt_align, 0); |
| 1840 |
xlu_cfg_get_defbool(config, "apic", &b_info->apic, 0); |
| 1841 |
xlu_cfg_get_defbool(config, "hvm_pirq", &b_info->u.hvm.pirq, 0); |
| 1842 |
|
| 1843 |
switch (xlu_cfg_get_list(config, "viridian", |
| 1844 |
&viridian, &num_viridian, 1)) |
| 1845 |
{ |
| 1846 |
case 0: /* Success */ |
| 1847 |
if (num_viridian) { |
| 1848 |
libxl_bitmap_alloc(ctx, &b_info->u.hvm.viridian_enable, |
| 1849 |
LIBXL_BUILDINFO_HVM_VIRIDIAN_ENABLE_DISABLE_WIDTH); |
| 1850 |
libxl_bitmap_alloc(ctx, &b_info->u.hvm.viridian_disable, |
| 1851 |
LIBXL_BUILDINFO_HVM_VIRIDIAN_ENABLE_DISABLE_WIDTH); |
| 1852 |
} |
| 1853 |
for (i = 0; i < num_viridian; i++) { |
| 1854 |
libxl_viridian_enlightenment v; |
| 1855 |
|
| 1856 |
buf = xlu_cfg_get_listitem(viridian, i); |
| 1857 |
if (strcmp(buf, "all") == 0) |
| 1858 |
libxl_bitmap_set_any(&b_info->u.hvm.viridian_enable); |
| 1859 |
else if (strcmp(buf, "defaults") == 0) |
| 1860 |
libxl_defbool_set(&b_info->u.hvm.viridian, true); |
| 1861 |
else { |
| 1862 |
libxl_bitmap *s = &b_info->u.hvm.viridian_enable; |
| 1863 |
libxl_bitmap *r = &b_info->u.hvm.viridian_disable; |
| 1864 |
|
| 1865 |
if (*buf == '!') { |
| 1866 |
s = &b_info->u.hvm.viridian_disable; |
| 1867 |
r = &b_info->u.hvm.viridian_enable; |
| 1868 |
buf++; |
| 1869 |
} |
| 1870 |
|
| 1871 |
e = libxl_viridian_enlightenment_from_string(buf, &v); |
| 1872 |
if (e) { |
| 1873 |
fprintf(stderr, |
| 1874 |
"xl: unknown viridian enlightenment '%s'\n", |
| 1875 |
buf); |
| 1876 |
exit(-ERROR_FAIL); |
| 1877 |
} |
| 1878 |
|
| 1879 |
libxl_bitmap_set(s, v); |
| 1880 |
libxl_bitmap_reset(r, v); |
| 1881 |
} |
| 1882 |
} |
| 1883 |
break; |
| 1884 |
case ESRCH: break; /* Option not present */ |
| 1885 |
case EINVAL: |
| 1886 |
xlu_cfg_get_defbool(config, "viridian", &b_info->u.hvm.viridian, 1); |
| 1887 |
break; |
| 1888 |
default: |
| 1889 |
fprintf(stderr,"xl: Unable to parse viridian enlightenments.\n"); |
| 1890 |
exit(-ERROR_FAIL); |
| 1891 |
} |
| 1892 |
|
| 1893 |
if (!xlu_cfg_get_long(config, "mmio_hole", &l, 0)) { |
| 1894 |
uint64_t mmio_hole_size; |
| 1895 |
|
| 1896 |
b_info->u.hvm.mmio_hole_memkb = l * 1024; |
| 1897 |
mmio_hole_size = b_info->u.hvm.mmio_hole_memkb * 1024; |
| 1898 |
if (mmio_hole_size < HVM_BELOW_4G_MMIO_LENGTH || |
| 1899 |
mmio_hole_size > HVM_BELOW_4G_MMIO_START) { |
| 1900 |
fprintf(stderr, |
| 1901 |
"ERROR: invalid value %ld for \"mmio_hole\"\n", l); |
| 1902 |
exit (1); |
| 1903 |
} |
| 1904 |
} |
| 1905 |
|
| 1906 |
if (!xlu_cfg_get_defbool(config, "altp2mhvm", &b_info->u.hvm.altp2m, 0)) |
| 1907 |
fprintf(stderr, "WARNING: Specifying \"altp2mhvm\" is deprecated. " |
| 1908 |
"Please use \"altp2m\" instead.\n"); |
| 1909 |
|
| 1910 |
xlu_cfg_replace_string(config, "smbios_firmware", |
| 1911 |
&b_info->u.hvm.smbios_firmware, 0); |
| 1912 |
xlu_cfg_replace_string(config, "acpi_firmware", |
| 1913 |
&b_info->u.hvm.acpi_firmware, 0); |
| 1914 |
|
| 1915 |
switch (xlu_cfg_get_list(config, "smbios", &smbios, &num_smbios, 0)) |
| 1916 |
{ |
| 1917 |
case 0: /* Success */ |
| 1918 |
{ |
| 1919 |
unsigned int num_oem = 1; |
| 1920 |
|
| 1921 |
b_info->u.hvm.num_smbios = num_smbios; |
| 1922 |
b_info->u.hvm.smbios = xcalloc(num_smbios, sizeof(libxl_smbios)); |
| 1923 |
for (i = 0; i < num_smbios; i++) { |
| 1924 |
libxl_smbios_type type; |
| 1925 |
char *option; |
| 1926 |
char *value; |
| 1927 |
|
| 1928 |
buf = xlu_cfg_get_listitem(smbios, i); |
| 1929 |
if (!buf) { |
| 1930 |
fprintf(stderr, |
| 1931 |
"xl: Unable to get element #%d in smbios list\n", |
| 1932 |
i); |
| 1933 |
exit(EXIT_FAILURE); |
| 1934 |
} |
| 1935 |
|
| 1936 |
option = xstrdup(buf); |
| 1937 |
value = strchr(option, '='); |
| 1938 |
if (value == NULL) { |
| 1939 |
fprintf(stderr, "xl: failed to split \"%s\" at '='\n", |
| 1940 |
option); |
| 1941 |
exit(EXIT_FAILURE); |
| 1942 |
} |
| 1943 |
|
| 1944 |
*value = '\0'; |
| 1945 |
value++; |
| 1946 |
|
| 1947 |
if (*value == '\0') { |
| 1948 |
fprintf(stderr, |
| 1949 |
"xl: empty value not allowed for smbios \"%s=\"\n", |
| 1950 |
option); |
| 1951 |
exit(EXIT_FAILURE); |
| 1952 |
} |
| 1953 |
|
| 1954 |
e = libxl_smbios_type_from_string(option, &type); |
| 1955 |
if (e) { |
| 1956 |
fprintf(stderr, "xl: unknown smbios type '%s'\n", option); |
| 1957 |
exit(EXIT_FAILURE); |
| 1958 |
} |
| 1959 |
|
| 1960 |
if (type == LIBXL_SMBIOS_TYPE_OEM) { |
| 1961 |
if (num_oem > 99) { |
| 1962 |
fprintf(stderr, |
| 1963 |
"xl: smbios limited to 99 oem strings\n"); |
| 1964 |
exit(EXIT_FAILURE); |
| 1965 |
} |
| 1966 |
num_oem++; |
| 1967 |
} |
| 1968 |
|
| 1969 |
b_info->u.hvm.smbios[i].key = type; |
| 1970 |
b_info->u.hvm.smbios[i].value = xstrdup(value); |
| 1971 |
|
| 1972 |
free(option); |
| 1973 |
} |
| 1974 |
break; |
| 1975 |
} |
| 1976 |
case ESRCH: /* Option not present */ |
| 1977 |
break; |
| 1978 |
default: |
| 1979 |
fprintf(stderr,"xl: Unable to parse smbios options.\n"); |
| 1980 |
exit(EXIT_FAILURE); |
| 1981 |
} |
| 1982 |
|
| 1983 |
if (!xlu_cfg_get_string(config, "ms_vm_genid", &buf, 0)) { |
| 1984 |
if (!strcmp(buf, "generate")) { |
| 1985 |
e = libxl_ms_vm_genid_generate(ctx, &b_info->u.hvm.ms_vm_genid); |
| 1986 |
if (e) { |
| 1987 |
fprintf(stderr, "ERROR: failed to generate a VM Generation ID\n"); |
| 1988 |
exit(1); |
| 1989 |
} |
| 1990 |
} else if (!strcmp(buf, "none")) { |
| 1991 |
; |
| 1992 |
} else { |
| 1993 |
fprintf(stderr, "ERROR: \"ms_vm_genid\" option must be \"generate\" or \"none\"\n"); |
| 1994 |
exit(1); |
| 1995 |
} |
| 1996 |
} |
| 1997 |
|
| 1998 |
if (!xlu_cfg_get_long (config, "rdm_mem_boundary", &l, 0)) |
| 1999 |
b_info->u.hvm.rdm_mem_boundary_memkb = l * 1024; |
| 2000 |
|
| 2001 |
switch (xlu_cfg_get_list(config, "mca_caps", |
| 2002 |
&mca_caps, &num_mca_caps, 1)) |
| 2003 |
{ |
| 2004 |
case 0: /* Success */ |
| 2005 |
for (i = 0; i < num_mca_caps; i++) { |
| 2006 |
buf = xlu_cfg_get_listitem(mca_caps, i); |
| 2007 |
if (!strcmp(buf, "lmce")) |
| 2008 |
b_info->u.hvm.mca_caps |= XEN_HVM_MCA_CAP_LMCE; |
| 2009 |
else { |
| 2010 |
fprintf(stderr, "ERROR: unrecognized MCA capability '%s'.\n", |
| 2011 |
buf); |
| 2012 |
exit(-ERROR_FAIL); |
| 2013 |
} |
| 2014 |
} |
| 2015 |
break; |
| 2016 |
|
| 2017 |
case ESRCH: /* Option not present */ |
| 2018 |
break; |
| 2019 |
|
| 2020 |
default: |
| 2021 |
fprintf(stderr, "ERROR: unable to parse mca_caps.\n"); |
| 2022 |
exit(-ERROR_FAIL); |
| 2023 |
} |
| 2024 |
|
| 2025 |
/* |
| 2026 |
* The firmware config option can be used as a simplification |
| 2027 |
* instead of setting bios or firmware_override. It has the |
| 2028 |
* following meanings for HVM guests: |
| 2029 |
* |
| 2030 |
* - ovmf | seabios | rombios: maps directly into the "bios" |
| 2031 |
* option. |
| 2032 |
* - uefi | bios: maps into one of the above options and is set |
| 2033 |
* in the bios field. |
| 2034 |
* - Anything else is treated as a path that is copied into |
| 2035 |
* firmware. |
| 2036 |
*/ |
| 2037 |
if (!xlu_cfg_get_string (config, "firmware", &buf, 0) && |
| 2038 |
libxl_bios_type_from_string(buf, &b_info->u.hvm.bios)) { |
| 2039 |
if (!strncmp(buf, "uefi", strlen(buf))) |
| 2040 |
b_info->u.hvm.bios = LIBXL_BIOS_TYPE_OVMF; |
| 2041 |
else if (strncmp(buf, "bios", strlen(buf))) |
| 2042 |
/* Assume it's a path to a custom firmware. */ |
| 2043 |
xlu_cfg_replace_string(config, "firmware", |
| 2044 |
&b_info->u.hvm.firmware, 0); |
| 2045 |
/* |
| 2046 |
* BIOS is the default, and will be chosen by libxl based on |
| 2047 |
* the device model specified. |
| 2048 |
*/ |
| 2049 |
} |
| 2050 |
|
| 2051 |
break; |
| 2052 |
case LIBXL_DOMAIN_TYPE_PVH: |
| 2053 |
case LIBXL_DOMAIN_TYPE_PV: |
| 2054 |
{ |
| 2055 |
/* |
| 2056 |
* The firmware config option can be used as a simplification |
| 2057 |
* instead of directly setting kernel. It will be translated to |
| 2058 |
* XENFIRMWAREDIR/<string>.bin |
| 2059 |
*/ |
| 2060 |
if (!xlu_cfg_get_string (config, "firmware", &buf, 0)) { |
| 2061 |
if (b_info->kernel) { |
| 2062 |
fprintf(stderr, |
| 2063 |
"ERROR: both kernel and firmware specified\n"); |
| 2064 |
exit(1); |
| 2065 |
} |
| 2066 |
if (strncmp(buf, "pvgrub32", strlen(buf)) && |
| 2067 |
strncmp(buf, "pvgrub64", strlen(buf))) { |
| 2068 |
fprintf(stderr, |
| 2069 |
"ERROR: only pvgrub{32|64} supported as firmware options\n"); |
| 2070 |
exit(1); |
| 2071 |
} |
| 2072 |
|
| 2073 |
xasprintf(&b_info->kernel, XENFIRMWAREDIR "/%s.bin", buf); |
| 2074 |
} |
| 2075 |
if (!b_info->bootloader && !b_info->kernel) { |
| 2076 |
fprintf(stderr, "Neither kernel nor bootloader specified\n"); |
| 2077 |
exit(1); |
| 2078 |
} |
| 2079 |
|
| 2080 |
break; |
| 2081 |
} |
| 2082 |
default: |
| 2083 |
abort(); |
| 2084 |
} |
| 2085 |
|
| 2086 |
if (!xlu_cfg_get_long(config, "altp2m", &l, 1)) { |
| 2087 |
if (l < LIBXL_ALTP2M_MODE_DISABLED || |
| 2088 |
l > LIBXL_ALTP2M_MODE_LIMITED) { |
| 2089 |
fprintf(stderr, "ERROR: invalid value %ld for \"altp2m\"\n", l); |
| 2090 |
exit (1); |
| 2091 |
} |
| 2092 |
|
| 2093 |
b_info->altp2m = l; |
| 2094 |
} else if (!xlu_cfg_get_string(config, "altp2m", &buf, 0)) { |
| 2095 |
if (libxl_altp2m_mode_from_string(buf, &b_info->altp2m)) { |
| 2096 |
fprintf(stderr, "ERROR: invalid value \"%s\" for \"altp2m\"\n", |
| 2097 |
buf); |
| 2098 |
exit (1); |
| 2099 |
} |
| 2100 |
} |
| 2101 |
|
| 2102 |
if (!xlu_cfg_get_long(config, "vmtrace_buf_kb", &l, 1) && l) { |
| 2103 |
b_info->vmtrace_buf_kb = l; |
| 2104 |
} |
| 2105 |
|
| 2106 |
if (!xlu_cfg_get_list(config, "ioports", &ioports, &num_ioports, 0)) { |
| 2107 |
b_info->num_ioports = num_ioports; |
| 2108 |
b_info->ioports = calloc(num_ioports, sizeof(*b_info->ioports)); |
| 2109 |
if (b_info->ioports == NULL) { |
| 2110 |
fprintf(stderr, "unable to allocate memory for ioports\n"); |
| 2111 |
exit(-1); |
| 2112 |
} |
| 2113 |
|
| 2114 |
for (i = 0; i < num_ioports; i++) { |
| 2115 |
const char *buf2; |
| 2116 |
char *ep; |
| 2117 |
uint32_t start, end; |
| 2118 |
unsigned long ul; |
| 2119 |
|
| 2120 |
buf = xlu_cfg_get_listitem (ioports, i); |
| 2121 |
if (!buf) { |
| 2122 |
fprintf(stderr, |
| 2123 |
"xl: Unable to get element #%d in ioport list\n", i); |
| 2124 |
exit(1); |
| 2125 |
} |
| 2126 |
ul = strtoul(buf, &ep, 16); |
| 2127 |
if (ep == buf) { |
| 2128 |
fprintf(stderr, "xl: Invalid argument parsing ioport: %s\n", |
| 2129 |
buf); |
| 2130 |
exit(1); |
| 2131 |
} |
| 2132 |
if (ul >= UINT32_MAX) { |
| 2133 |
fprintf(stderr, "xl: ioport %lx too big\n", ul); |
| 2134 |
exit(1); |
| 2135 |
} |
| 2136 |
start = end = ul; |
| 2137 |
|
| 2138 |
if (*ep == '-') { |
| 2139 |
buf2 = ep + 1; |
| 2140 |
ul = strtoul(buf2, &ep, 16); |
| 2141 |
if (ep == buf2 || *ep != '\0' || start > end) { |
| 2142 |
fprintf(stderr, |
| 2143 |
"xl: Invalid argument parsing ioport: %s\n", buf); |
| 2144 |
exit(1); |
| 2145 |
} |
| 2146 |
if (ul >= UINT32_MAX) { |
| 2147 |
fprintf(stderr, "xl: ioport %lx too big\n", ul); |
| 2148 |
exit(1); |
| 2149 |
} |
| 2150 |
end = ul; |
| 2151 |
} else if ( *ep != '\0' ) |
| 2152 |
fprintf(stderr, |
| 2153 |
"xl: Invalid argument parsing ioport: %s\n", buf); |
| 2154 |
b_info->ioports[i].first = start; |
| 2155 |
b_info->ioports[i].number = end - start + 1; |
| 2156 |
} |
| 2157 |
} |
| 2158 |
|
| 2159 |
if (!xlu_cfg_get_list(config, "irqs", &irqs, &num_irqs, 0)) { |
| 2160 |
b_info->num_irqs = num_irqs; |
| 2161 |
b_info->irqs = calloc(num_irqs, sizeof(*b_info->irqs)); |
| 2162 |
if (b_info->irqs == NULL) { |
| 2163 |
fprintf(stderr, "unable to allocate memory for ioports\n"); |
| 2164 |
exit(-1); |
| 2165 |
} |
| 2166 |
for (i = 0; i < num_irqs; i++) { |
| 2167 |
char *ep; |
| 2168 |
unsigned long ul; |
| 2169 |
buf = xlu_cfg_get_listitem (irqs, i); |
| 2170 |
if (!buf) { |
| 2171 |
fprintf(stderr, |
| 2172 |
"xl: Unable to get element %d in irq list\n", i); |
| 2173 |
exit(1); |
| 2174 |
} |
| 2175 |
ul = strtoul(buf, &ep, 10); |
| 2176 |
if (ep == buf || *ep != '\0') { |
| 2177 |
fprintf(stderr, |
| 2178 |
"xl: Invalid argument parsing irq: %s\n", buf); |
| 2179 |
exit(1); |
| 2180 |
} |
| 2181 |
if (ul >= UINT32_MAX) { |
| 2182 |
fprintf(stderr, "xl: irq %lx too big\n", ul); |
| 2183 |
exit(1); |
| 2184 |
} |
| 2185 |
b_info->irqs[i] = ul; |
| 2186 |
} |
| 2187 |
} |
| 2188 |
|
| 2189 |
if (!xlu_cfg_get_list(config, "iomem", &iomem, &num_iomem, 0)) { |
| 2190 |
int ret; |
| 2191 |
b_info->num_iomem = num_iomem; |
| 2192 |
b_info->iomem = calloc(num_iomem, sizeof(*b_info->iomem)); |
| 2193 |
if (b_info->iomem == NULL) { |
| 2194 |
fprintf(stderr, "unable to allocate memory for iomem\n"); |
| 2195 |
exit(-1); |
| 2196 |
} |
| 2197 |
for (i = 0; i < num_iomem; i++) { |
| 2198 |
int used; |
| 2199 |
|
| 2200 |
buf = xlu_cfg_get_listitem (iomem, i); |
| 2201 |
if (!buf) { |
| 2202 |
fprintf(stderr, |
| 2203 |
"xl: Unable to get element %d in iomem list\n", i); |
| 2204 |
exit(1); |
| 2205 |
} |
| 2206 |
libxl_iomem_range_init(&b_info->iomem[i]); |
| 2207 |
ret = sscanf(buf, "%" SCNx64",%" SCNx64"%n@%" SCNx64"%n", |
| 2208 |
&b_info->iomem[i].start, |
| 2209 |
&b_info->iomem[i].number, &used, |
| 2210 |
&b_info->iomem[i].gfn, &used); |
| 2211 |
if (ret < 2 || buf[used] != '\0') { |
| 2212 |
fprintf(stderr, |
| 2213 |
"xl: Invalid argument parsing iomem: %s\n", buf); |
| 2214 |
exit(1); |
| 2215 |
} |
| 2216 |
} |
| 2217 |
} |
| 2218 |
|
| 2219 |
|
| 2220 |
|
| 2221 |
if (!xlu_cfg_get_list (config, "disk", &vbds, 0, 0)) { |
| 2222 |
d_config->num_disks = 0; |
| 2223 |
d_config->disks = NULL; |
| 2224 |
while ((buf = xlu_cfg_get_listitem (vbds, d_config->num_disks)) != NULL) { |
| 2225 |
libxl_device_disk *disk; |
| 2226 |
char *buf2 = strdup(buf); |
| 2227 |
|
| 2228 |
disk = ARRAY_EXTEND_INIT_NODEVID(d_config->disks, |
| 2229 |
d_config->num_disks, |
| 2230 |
libxl_device_disk_init); |
| 2231 |
parse_disk_config(&config, buf2, disk); |
| 2232 |
|
| 2233 |
free(buf2); |
| 2234 |
} |
| 2235 |
} |
| 2236 |
|
| 2237 |
if (!xlu_cfg_get_list(config, "p9", &p9devs, 0, 0)) { |
| 2238 |
libxl_device_p9 *p9; |
| 2239 |
|
| 2240 |
d_config->num_p9s = 0; |
| 2241 |
d_config->p9s = NULL; |
| 2242 |
while ((buf = xlu_cfg_get_listitem (p9devs, d_config->num_p9s)) != NULL) { |
| 2243 |
libxl_string_list pairs; |
| 2244 |
int len; |
| 2245 |
|
| 2246 |
p9 = ARRAY_EXTEND_INIT(d_config->p9s, |
| 2247 |
d_config->num_p9s, |
| 2248 |
libxl_device_p9_init); |
| 2249 |
libxl_device_p9_init(p9); |
| 2250 |
|
| 2251 |
split_string_into_string_list(buf, ",", &pairs); |
| 2252 |
len = libxl_string_list_length(&pairs); |
| 2253 |
for (i = 0; i < len; i++) { |
| 2254 |
char *key, *value; |
| 2255 |
int rc; |
| 2256 |
|
| 2257 |
rc = split_string_into_pair(pairs[i], '=', &key, &value, |
| 2258 |
isspace); |
| 2259 |
if (rc != 0) { |
| 2260 |
fprintf(stderr, "failed to parse 9pfs configuration: %s", |
| 2261 |
pairs[i]); |
| 2262 |
exit(1); |
| 2263 |
} |
| 2264 |
|
| 2265 |
if (!strcmp(key, "security_model")) { |
| 2266 |
replace_string(&p9->security_model, value); |
| 2267 |
} else if (!strcmp(key, "path")) { |
| 2268 |
replace_string(&p9->path, value); |
| 2269 |
} else if (!strcmp(key, "tag")) { |
| 2270 |
replace_string(&p9->tag, value); |
| 2271 |
} else if (!strcmp(key, "backend")) { |
| 2272 |
replace_string(&p9->backend_domname, value); |
| 2273 |
} else if (!strcmp(key, "type")) { |
| 2274 |
if (libxl_p9_type_from_string(value, &p9->type)) { |
| 2275 |
fprintf(stderr, "failed to parse 9pfs type: %s\n", |
| 2276 |
value); |
| 2277 |
exit(1); |
| 2278 |
} |
| 2279 |
} else if (!strcmp(key, "max-files")) { |
| 2280 |
p9->max_files = parse_ulong(value); |
| 2281 |
} else if (!strcmp(key, "max-open-files")) { |
| 2282 |
p9->max_open_files = parse_ulong(value); |
| 2283 |
} else if (!strcmp(key, "max-space")) { |
| 2284 |
p9->max_space = parse_ulong(value); |
| 2285 |
} else if (!strcmp(key, "auto-delete")) { |
| 2286 |
p9->auto_delete = strtoul(value, NULL, 0); |
| 2287 |
} else { |
| 2288 |
fprintf(stderr, "Unknown 9pfs parameter '%s'\n", key); |
| 2289 |
exit(1); |
| 2290 |
} |
| 2291 |
free(key); |
| 2292 |
free(value); |
| 2293 |
} |
| 2294 |
|
| 2295 |
libxl_string_list_dispose(&pairs); |
| 2296 |
|
| 2297 |
if (p9->type == LIBXL_P9_TYPE_XEN_9PFSD && !p9->path) { |
| 2298 |
char *path; |
| 2299 |
|
| 2300 |
xasprintf(&path, XEN_LOG_DIR "/guests/%s", c_info->name); |
| 2301 |
replace_string(&p9->path, path); |
| 2302 |
free(path); |
| 2303 |
} |
| 2304 |
} |
| 2305 |
} |
| 2306 |
|
| 2307 |
if (!xlu_cfg_get_list(config, "vtpm", &vtpms, 0, 0)) { |
| 2308 |
d_config->num_vtpms = 0; |
| 2309 |
d_config->vtpms = NULL; |
| 2310 |
while ((buf = xlu_cfg_get_listitem (vtpms, d_config->num_vtpms)) != NULL) { |
| 2311 |
libxl_device_vtpm *vtpm; |
| 2312 |
char * buf2 = strdup(buf); |
| 2313 |
char *p, *p2; |
| 2314 |
bool got_backend = false; |
| 2315 |
|
| 2316 |
vtpm = ARRAY_EXTEND_INIT(d_config->vtpms, |
| 2317 |
d_config->num_vtpms, |
| 2318 |
libxl_device_vtpm_init); |
| 2319 |
|
| 2320 |
p = strtok(buf2, ","); |
| 2321 |
if(p) { |
| 2322 |
do { |
| 2323 |
while(*p == ' ') |
| 2324 |
++p; |
| 2325 |
if ((p2 = strchr(p, '=')) == NULL) |
| 2326 |
break; |
| 2327 |
*p2 = '\0'; |
| 2328 |
if (!strcmp(p, "backend")) { |
| 2329 |
vtpm->backend_domname = strdup(p2 + 1); |
| 2330 |
got_backend = true; |
| 2331 |
} else if(!strcmp(p, "uuid")) { |
| 2332 |
if( libxl_uuid_from_string(&vtpm->uuid, p2 + 1) ) { |
| 2333 |
fprintf(stderr, |
| 2334 |
"Failed to parse vtpm UUID: %s\n", p2 + 1); |
| 2335 |
exit(1); |
| 2336 |
} |
| 2337 |
} else { |
| 2338 |
fprintf(stderr, "Unknown string `%s' in vtpm spec\n", p); |
| 2339 |
exit(1); |
| 2340 |
} |
| 2341 |
} while ((p = strtok(NULL, ",")) != NULL); |
| 2342 |
} |
| 2343 |
if(!got_backend) { |
| 2344 |
fprintf(stderr, "vtpm spec missing required backend field!\n"); |
| 2345 |
exit(1); |
| 2346 |
} |
| 2347 |
free(buf2); |
| 2348 |
} |
| 2349 |
} |
| 2350 |
|
| 2351 |
if (!xlu_cfg_get_list(config, "vdispl", &vdispls, 0, 0)) { |
| 2352 |
d_config->num_vdispls = 0; |
| 2353 |
d_config->vdispls = NULL; |
| 2354 |
while ((buf = xlu_cfg_get_listitem(vdispls, d_config->num_vdispls)) != NULL) { |
| 2355 |
libxl_device_vdispl *vdispl; |
| 2356 |
char * buf2 = strdup(buf); |
| 2357 |
char *p; |
| 2358 |
vdispl = ARRAY_EXTEND_INIT(d_config->vdispls, |
| 2359 |
d_config->num_vdispls, |
| 2360 |
libxl_device_vdispl_init); |
| 2361 |
p = strtok (buf2, ","); |
| 2362 |
while (p != NULL) |
| 2363 |
{ |
| 2364 |
while (*p == ' ') p++; |
| 2365 |
if (parse_vdispl_config(vdispl, p)) { |
| 2366 |
free(buf2); |
| 2367 |
exit(1); |
| 2368 |
} |
| 2369 |
p = strtok (NULL, ","); |
| 2370 |
} |
| 2371 |
free(buf2); |
| 2372 |
if (vdispl->num_connectors == 0) { |
| 2373 |
fprintf(stderr, "At least one connector should be specified.\n"); |
| 2374 |
exit(1); |
| 2375 |
} |
| 2376 |
} |
| 2377 |
} |
| 2378 |
|
| 2379 |
if (!xlu_cfg_get_list(config, "pvcalls", &pvcallsifs_devs, 0, 0)) { |
| 2380 |
d_config->num_pvcallsifs = 0; |
| 2381 |
d_config->pvcallsifs = NULL; |
| 2382 |
while ((buf = xlu_cfg_get_listitem (pvcallsifs_devs, d_config->num_pvcallsifs)) != NULL) { |
| 2383 |
libxl_device_pvcallsif *pvcallsif; |
| 2384 |
char *backend = NULL; |
| 2385 |
char *p, *p2, *buf2; |
| 2386 |
pvcallsif = ARRAY_EXTEND_INIT(d_config->pvcallsifs, |
| 2387 |
d_config->num_pvcallsifs, |
| 2388 |
libxl_device_pvcallsif_init); |
| 2389 |
|
| 2390 |
buf2 = strdup(buf); |
| 2391 |
p = strtok(buf2, ","); |
| 2392 |
if (p) { |
| 2393 |
do { |
| 2394 |
while (*p == ' ') |
| 2395 |
++p; |
| 2396 |
if ((p2 = strchr(p, '=')) == NULL) |
| 2397 |
break; |
| 2398 |
*p2 = '\0'; |
| 2399 |
if(!strcmp(p, "backend")) { |
| 2400 |
backend = strdup(p2 + 1); |
| 2401 |
} else { |
| 2402 |
fprintf(stderr, "Unknown string `%s' in pvcalls spec\n", p); |
| 2403 |
exit(1); |
| 2404 |
} |
| 2405 |
} while ((p = strtok(NULL, ",")) != NULL); |
| 2406 |
} |
| 2407 |
free(buf2); |
| 2408 |
|
| 2409 |
if (backend) |
| 2410 |
replace_string(&pvcallsif->backend_domname, backend); |
| 2411 |
} |
| 2412 |
} |
| 2413 |
|
| 2414 |
parse_vsnd_config(config, d_config); |
| 2415 |
|
| 2416 |
if (!xlu_cfg_get_list (config, "channel", &channels, 0, 0)) { |
| 2417 |
d_config->num_channels = 0; |
| 2418 |
d_config->channels = NULL; |
| 2419 |
while ((buf = xlu_cfg_get_listitem (channels, |
| 2420 |
d_config->num_channels)) != NULL) { |
| 2421 |
libxl_device_channel *chn; |
| 2422 |
libxl_string_list pairs; |
| 2423 |
char *path = NULL; |
| 2424 |
int len; |
| 2425 |
|
| 2426 |
chn = ARRAY_EXTEND_INIT_NODEVID(d_config->channels, |
| 2427 |
d_config->num_channels, |
| 2428 |
libxl_device_channel_init); |
| 2429 |
|
| 2430 |
split_string_into_string_list(buf, ",", &pairs); |
| 2431 |
len = libxl_string_list_length(&pairs); |
| 2432 |
for (i = 0; i < len; i++) { |
| 2433 |
char *key, *value; |
| 2434 |
int rc; |
| 2435 |
rc = split_string_into_pair(pairs[i], '=', &key, &value, |
| 2436 |
isspace); |
| 2437 |
if (rc != 0) { |
| 2438 |
fprintf(stderr, "failed to parse channel configuration: %s", |
| 2439 |
pairs[i]); |
| 2440 |
exit(1); |
| 2441 |
} |
| 2442 |
|
| 2443 |
if (!strcmp(key, "backend")) { |
| 2444 |
replace_string(&chn->backend_domname, value); |
| 2445 |
} else if (!strcmp(key, "name")) { |
| 2446 |
replace_string(&chn->name, value); |
| 2447 |
} else if (!strcmp(key, "path")) { |
| 2448 |
replace_string(&path, value); |
| 2449 |
} else if (!strcmp(key, "connection")) { |
| 2450 |
if (!strcmp(value, "pty")) { |
| 2451 |
chn->connection = LIBXL_CHANNEL_CONNECTION_PTY; |
| 2452 |
} else if (!strcmp(value, "socket")) { |
| 2453 |
chn->connection = LIBXL_CHANNEL_CONNECTION_SOCKET; |
| 2454 |
} else { |
| 2455 |
fprintf(stderr, "unknown channel connection '%s'\n", |
| 2456 |
value); |
| 2457 |
exit(1); |
| 2458 |
} |
| 2459 |
} else { |
| 2460 |
fprintf(stderr, "unknown channel parameter '%s'," |
| 2461 |
" ignoring\n", key); |
| 2462 |
} |
| 2463 |
free(key); |
| 2464 |
free(value); |
| 2465 |
} |
| 2466 |
switch (chn->connection) { |
| 2467 |
case LIBXL_CHANNEL_CONNECTION_UNKNOWN: |
| 2468 |
fprintf(stderr, "channel has unknown 'connection'\n"); |
| 2469 |
exit(1); |
| 2470 |
case LIBXL_CHANNEL_CONNECTION_SOCKET: |
| 2471 |
if (!path) { |
| 2472 |
fprintf(stderr, "channel connection 'socket' requires path=..\n"); |
| 2473 |
exit(1); |
| 2474 |
} |
| 2475 |
chn->u.socket.path = xstrdup(path); |
| 2476 |
break; |
| 2477 |
case LIBXL_CHANNEL_CONNECTION_PTY: |
| 2478 |
/* Nothing to do since PTY has no arguments */ |
| 2479 |
break; |
| 2480 |
default: |
| 2481 |
fprintf(stderr, "unknown channel connection: %d", |
| 2482 |
chn->connection); |
| 2483 |
exit(1); |
| 2484 |
} |
| 2485 |
libxl_string_list_dispose(&pairs); |
| 2486 |
free(path); |
| 2487 |
} |
| 2488 |
} |
| 2489 |
|
| 2490 |
if (!xlu_cfg_get_list (config, "vif", &nics, 0, 0)) { |
| 2491 |
d_config->num_nics = 0; |
| 2492 |
d_config->nics = NULL; |
| 2493 |
while ((buf = xlu_cfg_get_listitem (nics, d_config->num_nics)) != NULL) { |
| 2494 |
libxl_device_nic *nic; |
| 2495 |
char *buf2 = strdup(buf); |
| 2496 |
char *p; |
| 2497 |
|
| 2498 |
nic = ARRAY_EXTEND_INIT(d_config->nics, |
| 2499 |
d_config->num_nics, |
| 2500 |
libxl_device_nic_init); |
| 2501 |
set_default_nic_values(nic); |
| 2502 |
|
| 2503 |
p = strtok(buf2, ","); |
| 2504 |
if (!p) |
| 2505 |
goto skip_nic; |
| 2506 |
do { |
| 2507 |
while (*p == ' ') |
| 2508 |
p++; |
| 2509 |
parse_nic_config(nic, &config, p); |
| 2510 |
} while ((p = strtok(NULL, ",")) != NULL); |
| 2511 |
skip_nic: |
| 2512 |
free(buf2); |
| 2513 |
} |
| 2514 |
} |
| 2515 |
|
| 2516 |
if (!xlu_cfg_get_list(config, "vif2", NULL, 0, 0)) { |
| 2517 |
fprintf(stderr, "WARNING: vif2: netchannel2 is deprecated and not supported by xl\n"); |
| 2518 |
} |
| 2519 |
|
| 2520 |
d_config->num_vfbs = 0; |
| 2521 |
d_config->num_vkbs = 0; |
| 2522 |
d_config->vfbs = NULL; |
| 2523 |
d_config->vkbs = NULL; |
| 2524 |
|
| 2525 |
if (!xlu_cfg_get_list (config, "vfb", &cvfbs, 0, 0)) { |
| 2526 |
while ((buf = xlu_cfg_get_listitem (cvfbs, d_config->num_vfbs)) != NULL) { |
| 2527 |
libxl_device_vfb *vfb; |
| 2528 |
libxl_device_vkb *vkb; |
| 2529 |
|
| 2530 |
char *buf2 = strdup(buf); |
| 2531 |
char *p, *p2; |
| 2532 |
|
| 2533 |
vfb = ARRAY_EXTEND_INIT(d_config->vfbs, d_config->num_vfbs, |
| 2534 |
libxl_device_vfb_init); |
| 2535 |
|
| 2536 |
vkb = ARRAY_EXTEND_INIT(d_config->vkbs, d_config->num_vkbs, |
| 2537 |
libxl_device_vkb_init); |
| 2538 |
|
| 2539 |
p = strtok(buf2, ","); |
| 2540 |
if (!p) |
| 2541 |
goto skip_vfb; |
| 2542 |
do { |
| 2543 |
while (*p == ' ') |
| 2544 |
p++; |
| 2545 |
if ((p2 = strchr(p, '=')) == NULL) |
| 2546 |
break; |
| 2547 |
*p2 = '\0'; |
| 2548 |
if (!strcmp(p, "vnc")) { |
| 2549 |
libxl_defbool_set(&vfb->vnc.enable, atoi(p2 + 1)); |
| 2550 |
} else if (!strcmp(p, "vnclisten")) { |
| 2551 |
free(vfb->vnc.listen); |
| 2552 |
vfb->vnc.listen = strdup(p2 + 1); |
| 2553 |
} else if (!strcmp(p, "vncpasswd")) { |
| 2554 |
free(vfb->vnc.passwd); |
| 2555 |
vfb->vnc.passwd = strdup(p2 + 1); |
| 2556 |
} else if (!strcmp(p, "vncdisplay")) { |
| 2557 |
vfb->vnc.display = atoi(p2 + 1); |
| 2558 |
} else if (!strcmp(p, "vncunused")) { |
| 2559 |
libxl_defbool_set(&vfb->vnc.findunused, atoi(p2 + 1)); |
| 2560 |
} else if (!strcmp(p, "keymap")) { |
| 2561 |
free(vfb->keymap); |
| 2562 |
vfb->keymap = strdup(p2 + 1); |
| 2563 |
} else if (!strcmp(p, "sdl")) { |
| 2564 |
libxl_defbool_set(&vfb->sdl.enable, atoi(p2 + 1)); |
| 2565 |
} else if (!strcmp(p, "opengl")) { |
| 2566 |
libxl_defbool_set(&vfb->sdl.opengl, atoi(p2 + 1)); |
| 2567 |
} else if (!strcmp(p, "display")) { |
| 2568 |
free(vfb->sdl.display); |
| 2569 |
vfb->sdl.display = strdup(p2 + 1); |
| 2570 |
} else if (!strcmp(p, "xauthority")) { |
| 2571 |
free(vfb->sdl.xauthority); |
| 2572 |
vfb->sdl.xauthority = strdup(p2 + 1); |
| 2573 |
} |
| 2574 |
} while ((p = strtok(NULL, ",")) != NULL); |
| 2575 |
|
| 2576 |
skip_vfb: |
| 2577 |
free(buf2); |
| 2578 |
} |
| 2579 |
} |
| 2580 |
|
| 2581 |
if (!xlu_cfg_get_list(config, "usbctrl", &usbctrls, 0, 0)) { |
| 2582 |
d_config->num_usbctrls = 0; |
| 2583 |
d_config->usbctrls = NULL; |
| 2584 |
while ((buf = xlu_cfg_get_listitem(usbctrls, d_config->num_usbctrls)) |
| 2585 |
!= NULL) { |
| 2586 |
libxl_device_usbctrl *usbctrl; |
| 2587 |
char *buf2 = strdup(buf); |
| 2588 |
char *p; |
| 2589 |
|
| 2590 |
usbctrl = ARRAY_EXTEND_INIT(d_config->usbctrls, |
| 2591 |
d_config->num_usbctrls, |
| 2592 |
libxl_device_usbctrl_init); |
| 2593 |
p = strtok(buf2, ","); |
| 2594 |
if (!p) |
| 2595 |
goto skip_usbctrl; |
| 2596 |
do { |
| 2597 |
while (*p == ' ') |
| 2598 |
p++; |
| 2599 |
if (parse_usbctrl_config(usbctrl, p)) |
| 2600 |
exit(1); |
| 2601 |
} while ((p = strtok(NULL, ",")) != NULL); |
| 2602 |
skip_usbctrl: |
| 2603 |
free(buf2); |
| 2604 |
} |
| 2605 |
} |
| 2606 |
|
| 2607 |
if (!xlu_cfg_get_list(config, "usbdev", &usbdevs, 0, 0)) { |
| 2608 |
d_config->num_usbdevs = 0; |
| 2609 |
d_config->usbdevs = NULL; |
| 2610 |
while ((buf = xlu_cfg_get_listitem(usbdevs, d_config->num_usbdevs)) |
| 2611 |
!= NULL) { |
| 2612 |
libxl_device_usbdev *usbdev; |
| 2613 |
char *buf2 = strdup(buf); |
| 2614 |
char *p; |
| 2615 |
|
| 2616 |
usbdev = ARRAY_EXTEND_INIT_NODEVID(d_config->usbdevs, |
| 2617 |
d_config->num_usbdevs, |
| 2618 |
libxl_device_usbdev_init); |
| 2619 |
p = strtok(buf2, ","); |
| 2620 |
if (!p) |
| 2621 |
goto skip_usbdev; |
| 2622 |
do { |
| 2623 |
while (*p == ' ') |
| 2624 |
p++; |
| 2625 |
if (parse_usbdev_config(usbdev, p)) |
| 2626 |
exit(1); |
| 2627 |
} while ((p = strtok(NULL, ",")) != NULL); |
| 2628 |
skip_usbdev: |
| 2629 |
free(buf2); |
| 2630 |
} |
| 2631 |
} |
| 2632 |
|
| 2633 |
switch (xlu_cfg_get_list(config, "cpuid", &cpuids, 0, 1)) { |
| 2634 |
case 0: |
| 2635 |
{ |
| 2636 |
const char *errstr; |
| 2637 |
|
| 2638 |
for (i = 0; (buf = xlu_cfg_get_listitem(cpuids, i)) != NULL; i++) { |
| 2639 |
e = libxl_cpuid_parse_config_xend(&b_info->cpuid, buf); |
| 2640 |
switch (e) { |
| 2641 |
case 0: continue; |
| 2642 |
case 1: |
| 2643 |
errstr = "illegal leaf number"; |
| 2644 |
break; |
| 2645 |
case 2: |
| 2646 |
errstr = "illegal subleaf number"; |
| 2647 |
break; |
| 2648 |
case 3: |
| 2649 |
errstr = "missing colon"; |
| 2650 |
break; |
| 2651 |
case 4: |
| 2652 |
errstr = "invalid register name (must be e[abcd]x)"; |
| 2653 |
break; |
| 2654 |
case 5: |
| 2655 |
errstr = "policy string must be exactly 32 characters long"; |
| 2656 |
break; |
| 2657 |
default: |
| 2658 |
errstr = "unknown error"; |
| 2659 |
break; |
| 2660 |
} |
| 2661 |
fprintf(stderr, "while parsing CPUID line: \"%s\":\n", buf); |
| 2662 |
fprintf(stderr, " error #%i: %s\n", e, errstr); |
| 2663 |
} |
| 2664 |
} |
| 2665 |
break; |
| 2666 |
case EINVAL: /* config option is not a list, parse as a string */ |
| 2667 |
if (!xlu_cfg_get_string(config, "cpuid", &buf, 0)) { |
| 2668 |
char *buf2, *p, *strtok_ptr = NULL; |
| 2669 |
const char *errstr; |
| 2670 |
|
| 2671 |
buf2 = strdup(buf); |
| 2672 |
p = strtok_r(buf2, ",", &strtok_ptr); |
| 2673 |
if (p == NULL) { |
| 2674 |
free(buf2); |
| 2675 |
break; |
| 2676 |
} |
| 2677 |
if (strcmp(p, "host")) { |
| 2678 |
fprintf(stderr, "while parsing CPUID string: \"%s\":\n", buf); |
| 2679 |
fprintf(stderr, " error: first word must be \"host\"\n"); |
| 2680 |
free(buf2); |
| 2681 |
break; |
| 2682 |
} |
| 2683 |
for (p = strtok_r(NULL, ",", &strtok_ptr); p != NULL; |
| 2684 |
p = strtok_r(NULL, ",", &strtok_ptr)) { |
| 2685 |
e = libxl_cpuid_parse_config(&b_info->cpuid, p); |
| 2686 |
switch (e) { |
| 2687 |
case 0: continue; |
| 2688 |
case 1: |
| 2689 |
errstr = "missing \"=\" in key=value"; |
| 2690 |
break; |
| 2691 |
case 2: |
| 2692 |
errstr = "unknown CPUID flag name"; |
| 2693 |
break; |
| 2694 |
case 3: |
| 2695 |
errstr = "illegal CPUID value (must be: [0|1|x|k|s])"; |
| 2696 |
break; |
| 2697 |
case ERROR_NOMEM: |
| 2698 |
errstr = "out of memory"; |
| 2699 |
break; |
| 2700 |
default: |
| 2701 |
errstr = "unknown error"; |
| 2702 |
break; |
| 2703 |
} |
| 2704 |
fprintf(stderr, "while parsing CPUID flag: \"%s\":\n", p); |
| 2705 |
fprintf(stderr, " error #%i: %s\n", e, errstr); |
| 2706 |
} |
| 2707 |
free(buf2); |
| 2708 |
} |
| 2709 |
break; |
| 2710 |
default: |
| 2711 |
break; |
| 2712 |
} |
| 2713 |
|
| 2714 |
/* parse device model arguments, this works for pv, hvm and stubdom */ |
| 2715 |
if (!xlu_cfg_get_string (config, "device_model", &buf, 0)) { |
| 2716 |
fprintf(stderr, |
| 2717 |
"WARNING: ignoring device_model directive.\n" |
| 2718 |
"WARNING: Use \"device_model_override\" instead if you" |
| 2719 |
" really want a non-default device_model\n"); |
| 2720 |
if (strstr(buf, "stubdom-dm")) { |
| 2721 |
if (c_info->type == LIBXL_DOMAIN_TYPE_HVM) |
| 2722 |
fprintf(stderr, "WARNING: Or use" |
| 2723 |
" \"device_model_stubdomain_override\" if you " |
| 2724 |
" want to enable stubdomains\n"); |
| 2725 |
else |
| 2726 |
fprintf(stderr, "WARNING: ignoring" |
| 2727 |
" \"device_model_stubdomain_override\" directive" |
| 2728 |
" for pv guest\n"); |
| 2729 |
} |
| 2730 |
} |
| 2731 |
|
| 2732 |
|
| 2733 |
xlu_cfg_replace_string (config, "device_model_override", |
| 2734 |
&b_info->device_model, 0); |
| 2735 |
if (!xlu_cfg_get_string (config, "device_model_version", &buf, 0)) { |
| 2736 |
if (!strcmp(buf, "qemu-xen-traditional")) { |
| 2737 |
b_info->device_model_version |
| 2738 |
= LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL; |
| 2739 |
} else if (!strcmp(buf, "qemu-xen")) { |
| 2740 |
b_info->device_model_version |
| 2741 |
= LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN; |
| 2742 |
} else { |
| 2743 |
fprintf(stderr, |
| 2744 |
"Unknown device_model_version \"%s\" specified\n", buf); |
| 2745 |
exit(1); |
| 2746 |
} |
| 2747 |
} else if (b_info->device_model) |
| 2748 |
fprintf(stderr, "WARNING: device model override given without specific DM version\n"); |
| 2749 |
xlu_cfg_get_defbool (config, "device_model_stubdomain_override", |
| 2750 |
&b_info->device_model_stubdomain, 0); |
| 2751 |
|
| 2752 |
if (!xlu_cfg_get_string (config, "device_model_stubdomain_seclabel", |
| 2753 |
&buf, 0)) |
| 2754 |
xlu_cfg_replace_string(config, "device_model_stubdomain_seclabel", |
| 2755 |
&b_info->device_model_ssid_label, 0); |
| 2756 |
|
| 2757 |
xlu_cfg_replace_string(config, "device_model_user", |
| 2758 |
&b_info->device_model_user, 0); |
| 2759 |
|
| 2760 |
xlu_cfg_replace_string (config, "stubdomain_kernel", |
| 2761 |
&b_info->stubdomain_kernel, 0); |
| 2762 |
xlu_cfg_replace_string (config, "stubdomain_cmdline", |
| 2763 |
&b_info->stubdomain_cmdline, 0); |
| 2764 |
xlu_cfg_replace_string (config, "stubdomain_ramdisk", |
| 2765 |
&b_info->stubdomain_ramdisk, 0); |
| 2766 |
if (!xlu_cfg_get_long (config, "stubdomain_memory", &l, 0)) |
| 2767 |
b_info->stubdomain_memkb = l * 1024; |
| 2768 |
|
| 2769 |
#define parse_extra_args(type) \ |
| 2770 |
e = xlu_cfg_get_list_as_string_list(config, "device_model_args"#type, \ |
| 2771 |
&b_info->extra##type, 0); \ |
| 2772 |
if (e && e != ESRCH) { \ |
| 2773 |
fprintf(stderr,"xl: Unable to parse device_model_args"#type".\n");\ |
| 2774 |
exit(-ERROR_FAIL); \ |
| 2775 |
} |
| 2776 |
|
| 2777 |
/* parse extra args for qemu, common to both pv, hvm */ |
| 2778 |
parse_extra_args(); |
| 2779 |
|
| 2780 |
/* parse extra args dedicated to pv */ |
| 2781 |
parse_extra_args(_pv); |
| 2782 |
|
| 2783 |
/* parse extra args dedicated to hvm */ |
| 2784 |
parse_extra_args(_hvm); |
| 2785 |
|
| 2786 |
#undef parse_extra_args |
| 2787 |
|
| 2788 |
/* If we've already got vfb=[] for PV guest then ignore top level |
| 2789 |
* VNC config. */ |
| 2790 |
if (c_info->type == LIBXL_DOMAIN_TYPE_PV && !d_config->num_vfbs) { |
| 2791 |
long vnc_enabled = 0; |
| 2792 |
|
| 2793 |
if (!xlu_cfg_get_long (config, "vnc", &l, 0)) |
| 2794 |
vnc_enabled = l; |
| 2795 |
|
| 2796 |
if (vnc_enabled) { |
| 2797 |
libxl_device_vfb *vfb; |
| 2798 |
libxl_device_vkb *vkb; |
| 2799 |
|
| 2800 |
vfb = ARRAY_EXTEND_INIT(d_config->vfbs, d_config->num_vfbs, |
| 2801 |
libxl_device_vfb_init); |
| 2802 |
|
| 2803 |
vkb = ARRAY_EXTEND_INIT(d_config->vkbs, d_config->num_vkbs, |
| 2804 |
libxl_device_vkb_init); |
| 2805 |
|
| 2806 |
parse_top_level_vnc_options(config, &vfb->vnc); |
| 2807 |
parse_top_level_sdl_options(config, &vfb->sdl); |
| 2808 |
xlu_cfg_replace_string (config, "keymap", &vfb->keymap, 0); |
| 2809 |
} |
| 2810 |
} else { |
| 2811 |
parse_top_level_vnc_options(config, &b_info->u.hvm.vnc); |
| 2812 |
parse_top_level_sdl_options(config, &b_info->u.hvm.sdl); |
| 2813 |
} |
| 2814 |
|
| 2815 |
xlu_cfg_get_defbool(config, "dm_restrict", &b_info->dm_restrict, 0); |
| 2816 |
|
| 2817 |
if (c_info->type == LIBXL_DOMAIN_TYPE_HVM) { |
| 2818 |
if (!xlu_cfg_get_string (config, "vga", &buf, 0)) { |
| 2819 |
if (!strcmp(buf, "stdvga")) { |
| 2820 |
b_info->u.hvm.vga.kind = LIBXL_VGA_INTERFACE_TYPE_STD; |
| 2821 |
} else if (!strcmp(buf, "cirrus")) { |
| 2822 |
b_info->u.hvm.vga.kind = LIBXL_VGA_INTERFACE_TYPE_CIRRUS; |
| 2823 |
} else if (!strcmp(buf, "none")) { |
| 2824 |
b_info->u.hvm.vga.kind = LIBXL_VGA_INTERFACE_TYPE_NONE; |
| 2825 |
} else if (!strcmp(buf, "qxl")) { |
| 2826 |
b_info->u.hvm.vga.kind = LIBXL_VGA_INTERFACE_TYPE_QXL; |
| 2827 |
} else { |
| 2828 |
fprintf(stderr, "Unknown vga \"%s\" specified\n", buf); |
| 2829 |
exit(1); |
| 2830 |
} |
| 2831 |
} else if (!xlu_cfg_get_long(config, "stdvga", &l, 0)) |
| 2832 |
b_info->u.hvm.vga.kind = l ? LIBXL_VGA_INTERFACE_TYPE_STD : |
| 2833 |
LIBXL_VGA_INTERFACE_TYPE_CIRRUS; |
| 2834 |
|
| 2835 |
if (!xlu_cfg_get_string(config, "hdtype", &buf, 0) && |
| 2836 |
libxl_hdtype_from_string(buf, &b_info->u.hvm.hdtype)) { |
| 2837 |
fprintf(stderr, "ERROR: invalid value \"%s\" for \"hdtype\"\n", |
| 2838 |
buf); |
| 2839 |
exit (1); |
| 2840 |
} |
| 2841 |
|
| 2842 |
xlu_cfg_replace_string (config, "keymap", &b_info->u.hvm.keymap, 0); |
| 2843 |
xlu_cfg_get_defbool (config, "spice", &b_info->u.hvm.spice.enable, 0); |
| 2844 |
if (!xlu_cfg_get_long (config, "spiceport", &l, 0)) |
| 2845 |
b_info->u.hvm.spice.port = l; |
| 2846 |
if (!xlu_cfg_get_long (config, "spicetls_port", &l, 0)) |
| 2847 |
b_info->u.hvm.spice.tls_port = l; |
| 2848 |
xlu_cfg_replace_string (config, "spicehost", |
| 2849 |
&b_info->u.hvm.spice.host, 0); |
| 2850 |
xlu_cfg_get_defbool(config, "spicedisable_ticketing", |
| 2851 |
&b_info->u.hvm.spice.disable_ticketing, 0); |
| 2852 |
xlu_cfg_replace_string (config, "spicepasswd", |
| 2853 |
&b_info->u.hvm.spice.passwd, 0); |
| 2854 |
xlu_cfg_get_defbool(config, "spiceagent_mouse", |
| 2855 |
&b_info->u.hvm.spice.agent_mouse, 0); |
| 2856 |
xlu_cfg_get_defbool(config, "spicevdagent", |
| 2857 |
&b_info->u.hvm.spice.vdagent, 0); |
| 2858 |
xlu_cfg_get_defbool(config, "spice_clipboard_sharing", |
| 2859 |
&b_info->u.hvm.spice.clipboard_sharing, 0); |
| 2860 |
if (!xlu_cfg_get_long (config, "spiceusbredirection", &l, 0)) |
| 2861 |
b_info->u.hvm.spice.usbredirection = l; |
| 2862 |
xlu_cfg_replace_string (config, "spice_image_compression", |
| 2863 |
&b_info->u.hvm.spice.image_compression, 0); |
| 2864 |
xlu_cfg_replace_string (config, "spice_streaming_video", |
| 2865 |
&b_info->u.hvm.spice.streaming_video, 0); |
| 2866 |
xlu_cfg_get_defbool(config, "nographic", &b_info->u.hvm.nographic, 0); |
| 2867 |
if (!xlu_cfg_get_long(config, "gfx_passthru", &l, 1)) { |
| 2868 |
libxl_defbool_set(&b_info->u.hvm.gfx_passthru, l); |
| 2869 |
} else if (!xlu_cfg_get_string(config, "gfx_passthru", &buf, 0)) { |
| 2870 |
if (libxl_gfx_passthru_kind_from_string(buf, |
| 2871 |
&b_info->u.hvm.gfx_passthru_kind)) { |
| 2872 |
fprintf(stderr, |
| 2873 |
"ERROR: invalid value \"%s\" for \"gfx_passthru\"\n", |
| 2874 |
buf); |
| 2875 |
exit (1); |
| 2876 |
} |
| 2877 |
libxl_defbool_set(&b_info->u.hvm.gfx_passthru, true); |
| 2878 |
} |
| 2879 |
switch (xlu_cfg_get_list_as_string_list(config, "serial", |
| 2880 |
&b_info->u.hvm.serial_list, |
| 2881 |
1)) |
| 2882 |
{ |
| 2883 |
|
| 2884 |
case 0: break; /* Success */ |
| 2885 |
case ESRCH: break; /* Option not present */ |
| 2886 |
case EINVAL: |
| 2887 |
/* If it's not a valid list, try reading it as an atom, |
| 2888 |
* falling through to an error if it fails */ |
| 2889 |
if (!xlu_cfg_replace_string(config, "serial", |
| 2890 |
&b_info->u.hvm.serial, 0)) |
| 2891 |
break; |
| 2892 |
/* FALLTHRU */ |
| 2893 |
default: |
| 2894 |
fprintf(stderr,"xl: Unable to parse serial.\n"); |
| 2895 |
exit(-ERROR_FAIL); |
| 2896 |
} |
| 2897 |
xlu_cfg_replace_string (config, "boot", &b_info->u.hvm.boot, 0); |
| 2898 |
xlu_cfg_get_defbool(config, "usb", &b_info->u.hvm.usb, 0); |
| 2899 |
if (!xlu_cfg_get_long (config, "usbversion", &l, 0)) |
| 2900 |
b_info->u.hvm.usbversion = l; |
| 2901 |
switch (xlu_cfg_get_list_as_string_list(config, "usbdevice", |
| 2902 |
&b_info->u.hvm.usbdevice_list, |
| 2903 |
1)) |
| 2904 |
{ |
| 2905 |
|
| 2906 |
case 0: break; /* Success */ |
| 2907 |
case ESRCH: break; /* Option not present */ |
| 2908 |
case EINVAL: |
| 2909 |
/* If it's not a valid list, try reading it as an atom, |
| 2910 |
* falling through to an error if it fails */ |
| 2911 |
if (!xlu_cfg_replace_string(config, "usbdevice", |
| 2912 |
&b_info->u.hvm.usbdevice, 0)) |
| 2913 |
break; |
| 2914 |
/* FALLTHRU */ |
| 2915 |
default: |
| 2916 |
fprintf(stderr,"xl: Unable to parse usbdevice.\n"); |
| 2917 |
exit(-ERROR_FAIL); |
| 2918 |
} |
| 2919 |
xlu_cfg_get_defbool(config, "vkb_device", &b_info->u.hvm.vkb_device, 0); |
| 2920 |
xlu_cfg_replace_string (config, "soundhw", &b_info->u.hvm.soundhw, 0); |
| 2921 |
xlu_cfg_get_defbool(config, "xen_platform_pci", |
| 2922 |
&b_info->u.hvm.xen_platform_pci, 0); |
| 2923 |
|
| 2924 |
if(b_info->u.hvm.vnc.listen |
| 2925 |
&& b_info->u.hvm.vnc.display |
| 2926 |
&& strchr(b_info->u.hvm.vnc.listen, ':') != NULL) { |
| 2927 |
fprintf(stderr, |
| 2928 |
"ERROR: Display specified both in vnclisten" |
| 2929 |
" and vncdisplay!\n"); |
| 2930 |
exit (1); |
| 2931 |
|
| 2932 |
} |
| 2933 |
|
| 2934 |
if (!xlu_cfg_get_string (config, "vendor_device", &buf, 0)) { |
| 2935 |
libxl_vendor_device d; |
| 2936 |
|
| 2937 |
e = libxl_vendor_device_from_string(buf, &d); |
| 2938 |
if (e) { |
| 2939 |
fprintf(stderr, |
| 2940 |
"xl: unknown vendor_device '%s'\n", |
| 2941 |
buf); |
| 2942 |
exit(-ERROR_FAIL); |
| 2943 |
} |
| 2944 |
|
| 2945 |
b_info->u.hvm.vendor_device = d; |
| 2946 |
} |
| 2947 |
} |
| 2948 |
|
| 2949 |
if (!xlu_cfg_get_string (config, "gic_version", &buf, 1)) { |
| 2950 |
e = libxl_gic_version_from_string(buf, &b_info->arch_arm.gic_version); |
| 2951 |
if (e) { |
| 2952 |
fprintf(stderr, |
| 2953 |
"Unknown gic_version \"%s\" specified\n", buf); |
| 2954 |
exit(-ERROR_FAIL); |
| 2955 |
} |
| 2956 |
} |
| 2957 |
|
| 2958 |
if (!xlu_cfg_get_string (config, "tee", &buf, 1)) { |
| 2959 |
e = libxl_tee_type_from_string(buf, &b_info->tee); |
| 2960 |
if (e) { |
| 2961 |
fprintf(stderr, |
| 2962 |
"Unknown tee \"%s\" specified\n", buf); |
| 2963 |
exit(-ERROR_FAIL); |
| 2964 |
} |
| 2965 |
} |
| 2966 |
|
| 2967 |
if (!xlu_cfg_get_string (config, "sve", &buf, 1)) { |
| 2968 |
e = libxl_sve_type_from_string(buf, &b_info->arch_arm.sve_vl); |
| 2969 |
if (e) { |
| 2970 |
fprintf(stderr, "Unknown sve \"%s\" specified\n", buf); |
| 2971 |
exit(EXIT_FAILURE); |
| 2972 |
} |
| 2973 |
} |
| 2974 |
|
| 2975 |
if (!xlu_cfg_get_long (config, "nr_spis", &l, 0)) |
| 2976 |
b_info->arch_arm.nr_spis = l; |
| 2977 |
|
| 2978 |
parse_vkb_list(config, d_config); |
| 2979 |
|
| 2980 |
d_config->virtios = NULL; |
| 2981 |
d_config->num_virtios = 0; |
| 2982 |
parse_virtio_list(config, d_config); |
| 2983 |
|
| 2984 |
xlu_cfg_get_defbool(config, "xend_suspend_evtchn_compat", |
| 2985 |
&c_info->xend_suspend_evtchn_compat, 0); |
| 2986 |
|
| 2987 |
if (!xlu_cfg_get_defbool(config, "msr_relaxed", |
| 2988 |
&b_info->arch_x86.msr_relaxed, 0)) |
| 2989 |
fprintf(stderr, |
| 2990 |
"WARNING: msr_relaxed will be removed in future versions.\n" |
| 2991 |
"If it fixes an issue you are having please report to " |
| 2992 |
"[email protected].\n"); |
| 2993 |
|
| 2994 |
xlu_cfg_get_defbool(config, "vpmu", &b_info->vpmu, 0); |
| 2995 |
|
| 2996 |
xlu_cfg_destroy(config); |
| 2997 |
} |
| 2998 |
|
| 2999 |
/* Returns -1 on failure; the amount of memory on success. */ |
| 3000 |
int64_t parse_mem_size_kb(const char *mem) |
| 3001 |
{ |
| 3002 |
char *endptr; |
| 3003 |
int64_t kbytes; |
| 3004 |
|
| 3005 |
kbytes = strtoll(mem, &endptr, 10); |
| 3006 |
|
| 3007 |
if (strlen(endptr) > 1) |
| 3008 |
return -1; |
| 3009 |
|
| 3010 |
switch (tolower((uint8_t)*endptr)) { |
| 3011 |
case 't': |
| 3012 |
kbytes <<= 10; |
| 3013 |
/* fallthrough */ |
| 3014 |
case 'g': |
| 3015 |
kbytes <<= 10; |
| 3016 |
/* fallthrough */ |
| 3017 |
case '\0': |
| 3018 |
case 'm': |
| 3019 |
kbytes <<= 10; |
| 3020 |
/* fallthrough */ |
| 3021 |
case 'k': |
| 3022 |
break; |
| 3023 |
case 'b': |
| 3024 |
kbytes >>= 10; |
| 3025 |
break; |
| 3026 |
default: |
| 3027 |
return -1; |
| 3028 |
} |
| 3029 |
|
| 3030 |
return kbytes; |
| 3031 |
} |
| 3032 |
|
| 3033 |
|
| 3034 |
void split_string_into_string_list(const char *str, |
| 3035 |
const char *delim, |
| 3036 |
libxl_string_list *psl) |
| 3037 |
{ |
| 3038 |
char *s, *saveptr; |
| 3039 |
const char *p; |
| 3040 |
libxl_string_list sl; |
| 3041 |
|
| 3042 |
int i = 0, nr = 0; |
| 3043 |
|
| 3044 |
s = strdup(str); |
| 3045 |
if (s == NULL) { |
| 3046 |
fprintf(stderr, "unable to allocate memory to split string\n"); |
| 3047 |
exit(-1); |
| 3048 |
} |
| 3049 |
|
| 3050 |
/* Count number of entries */ |
| 3051 |
p = strtok_r(s, delim, &saveptr); |
| 3052 |
do { |
| 3053 |
nr++; |
| 3054 |
} while ((p = strtok_r(NULL, delim, &saveptr))); |
| 3055 |
|
| 3056 |
free(s); |
| 3057 |
|
| 3058 |
s = strdup(str); |
| 3059 |
|
| 3060 |
sl = malloc((nr+1) * sizeof (char *)); |
| 3061 |
if (sl == NULL) { |
| 3062 |
fprintf(stderr, "unable to allocate memory to split string\n"); |
| 3063 |
exit(-1); |
| 3064 |
} |
| 3065 |
|
| 3066 |
p = strtok_r(s, delim, &saveptr); |
| 3067 |
do { |
| 3068 |
assert(i < nr); |
| 3069 |
sl[i] = strdup(p); |
| 3070 |
i++; |
| 3071 |
} while ((p = strtok_r(NULL, delim, &saveptr))); |
| 3072 |
sl[i] = NULL; |
| 3073 |
|
| 3074 |
*psl = sl; |
| 3075 |
|
| 3076 |
free(s); |
| 3077 |
} |
| 3078 |
|
| 3079 |
void trim(char_predicate_t predicate, const char *input, char **output) |
| 3080 |
{ |
| 3081 |
const char *first, *after; |
| 3082 |
|
| 3083 |
for (first = input; |
| 3084 |
*first && predicate((unsigned char)first[0]); |
| 3085 |
first++) |
| 3086 |
; |
| 3087 |
|
| 3088 |
for (after = first + strlen(first); |
| 3089 |
after > first && predicate((unsigned char)after[-1]); |
| 3090 |
after--) |
| 3091 |
; |
| 3092 |
|
| 3093 |
size_t len_nonnull = after - first; |
| 3094 |
char *result = xmalloc(len_nonnull + 1); |
| 3095 |
|
| 3096 |
memcpy(result, first, len_nonnull); |
| 3097 |
result[len_nonnull] = 0; |
| 3098 |
|
| 3099 |
*output = result; |
| 3100 |
} |
| 3101 |
|
| 3102 |
int split_string_into_pair(const char *str, char delim, char **a, char **b, |
| 3103 |
char_predicate_t predicate) |
| 3104 |
{ |
| 3105 |
char *s, *p, *aa = NULL, *bb = NULL; |
| 3106 |
int rc = 0; |
| 3107 |
|
| 3108 |
s = xstrdup(str); |
| 3109 |
|
| 3110 |
p = strchr(s, delim); |
| 3111 |
if (p == NULL) { |
| 3112 |
rc = ERROR_INVAL; |
| 3113 |
goto out; |
| 3114 |
} |
| 3115 |
*p = 0; |
| 3116 |
if (predicate) { |
| 3117 |
trim(predicate, s, &aa); |
| 3118 |
} else { |
| 3119 |
aa = xstrdup(s); |
| 3120 |
} |
| 3121 |
p++; |
| 3122 |
if (!*p) { |
| 3123 |
rc = ERROR_INVAL; |
| 3124 |
goto out; |
| 3125 |
} |
| 3126 |
if (predicate) { |
| 3127 |
trim(predicate, p, &bb); |
| 3128 |
} else { |
| 3129 |
bb = xstrdup(p); |
| 3130 |
} |
| 3131 |
|
| 3132 |
*a = aa; |
| 3133 |
aa = NULL; |
| 3134 |
*b = bb; |
| 3135 |
bb = NULL; |
| 3136 |
out: |
| 3137 |
free(s); |
| 3138 |
free(aa); |
| 3139 |
free(bb); |
| 3140 |
return rc; |
| 3141 |
} |
| 3142 |
|
| 3143 |
|
| 3144 |
/* |
| 3145 |
* Local variables: |
| 3146 |
* mode: C |
| 3147 |
* c-basic-offset: 4 |
| 3148 |
* indent-tabs-mode: nil |
| 3149 |
* End: |
| 3150 |
*/ |