From baae0f2bceb661804de10ec428d2d175fa2ec632 Mon Sep 17 00:00:00 2001 From: Ian Campbell Date: Thu, 3 Mar 2011 17:07:40 +0000 Subject: [PATCH] xl: add "device_model_args" to pass arbitrary extra arguments to device model The libxl support was already in place so simply plumb it through. This allows for passing debug options to the device model and provides a method to work around missing toolstack functionality. e.g. xl does not current support floppy disks but adding: device_model_args = [ "-fda", "/scratch/fdboot.img" ] allowed me to boot FreeDOS from a floppy image. I was unable to find any equivalent functionality in xend so this is a new xl feature. Moved xmalloc/xrealloc earlier to allow use from parse_config_data. Signed-off-by: Ian Campbell Acked-by: Ian Jackson Committed-by: Ian Jackson --- tools/libxl/xl_cmdimpl.c | 54 +++++++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 20 deletions(-) diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c index 2dd0f29e71..de7230dd53 100644 --- a/tools/libxl/xl_cmdimpl.c +++ b/tools/libxl/xl_cmdimpl.c @@ -244,6 +244,26 @@ release_lock: return rc; } +static void *xmalloc(size_t sz) { + void *r; + r = malloc(sz); + if (!r) { fprintf(stderr,"xl: Unable to malloc %lu bytes.\n", + (unsigned long)sz); exit(-ERROR_FAIL); } + return r; +} + +static void *xrealloc(void *ptr, size_t sz) { + void *r; + if (!sz) { free(ptr); return 0; } + /* realloc(non-0, 0) has a useless return value; + * but xrealloc(anything, 0) is like free + */ + r = realloc(ptr, sz); + if (!r) { fprintf(stderr,"xl: Unable to realloc to %lu bytes.\n", + (unsigned long)sz); exit(-ERROR_FAIL); } + return r; +} + #define LOG(_f, _a...) dolog(__FILE__, __LINE__, __func__, _f "\n", ##_a) static void dolog(const char *file, int line, const char *func, char *fmt, ...) @@ -1087,6 +1107,9 @@ skip_vfb: } if (c_info->hvm == 1) { + XLU_ConfigList *dmargs; + int nr_dmargs = 0; + /* init dm from c and b */ libxl_init_dm_info(dm_info, c_info, b_info); @@ -1119,6 +1142,17 @@ skip_vfb: xlu_cfg_replace_string (config, "soundhw", &dm_info->soundhw); if (!xlu_cfg_get_long (config, "xen_platform_pci", &l)) dm_info->xen_platform_pci = l; + + if (!xlu_cfg_get_list(config, "device_model_args", &dmargs, &nr_dmargs, 0)) + { + int i; + dm_info->extra = xmalloc(sizeof(char *) * (nr_dmargs + 1)); + dm_info->extra[nr_dmargs] = NULL; + for (i=0; iextra[i] = a ? strdup(a) : NULL; + } + } } dm_info->type = c_info->hvm ? XENFV : XENPV; @@ -1126,26 +1160,6 @@ skip_vfb: xlu_cfg_destroy(config); } -static void *xmalloc(size_t sz) { - void *r; - r = malloc(sz); - if (!r) { fprintf(stderr,"xl: Unable to malloc %lu bytes.\n", - (unsigned long)sz); exit(-ERROR_FAIL); } - return r; -} - -static void *xrealloc(void *ptr, size_t sz) { - void *r; - if (!sz) { free(ptr); return 0; } - /* realloc(non-0, 0) has a useless return value; - * but xrealloc(anything, 0) is like free - */ - r = realloc(ptr, sz); - if (!r) { fprintf(stderr,"xl: Unable to realloc to %lu bytes.\n", - (unsigned long)sz); exit(-ERROR_FAIL); } - return r; -} - /* Returns 1 if domain should be restarted, 2 if domain should be renamed then restarted */ static int handle_domain_death(libxl_ctx *ctx, uint32_t domid, libxl_event *event, libxl_domain_config *d_config, libxl_dominfo *info) -- 2.39.5