Mailing List Archive

[PATCH 13 of 15 v2] libxlu: add xlu_cfg_get_list_as_string_list
# HG changeset patch
# User Ian Campbell <ian.campbell@citrix.com>
# Date 1322231691 0
# Node ID 5ce5f2cdb7be8faed396b62ce26b4ad8669db0bf
# Parent 9e98f587da45fced29dc9c317f403f53e3fec904
libxlu: add xlu_cfg_get_list_as_string_list

Returns a cfg list as a libxl_string_list.

Use this to simplify the parsing of device model extra args.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>

diff -r 9e98f587da45 -r 5ce5f2cdb7be tools/libxl/libxlu_cfg.c
--- a/tools/libxl/libxlu_cfg.c Fri Nov 25 14:34:22 2011 +0000
+++ b/tools/libxl/libxlu_cfg.c Fri Nov 25 14:34:51 2011 +0000
@@ -254,6 +254,29 @@ int xlu_cfg_get_list(const XLU_Config *c
return 0;
}

+int xlu_cfg_get_list_as_string_list(const XLU_Config *cfg, const char *n,
+ libxl_string_list *psl, int dont_warn) {
+ int i, rc, nr;
+ XLU_ConfigList *list;
+ libxl_string_list sl;
+
+ rc = xlu_cfg_get_list(cfg, n, &list, &nr, dont_warn);
+ if (rc) return rc;
+
+ sl = malloc(sizeof(char*)*(nr + 1));
+ if (sl == NULL) return ENOMEM;
+
+ for (i=0; i<nr; i++) {
+ const char *a = xlu_cfg_get_listitem(list, i);
+ sl[i] = a ? strdup(a) : NULL;
+ }
+
+ sl[nr] = NULL;
+
+ *psl = sl;
+ return 0;
+}
+
const char *xlu_cfg_get_listitem(const XLU_ConfigList *set, int entry) {
if (entry < 0 || entry >= set->nvalues) return 0;
return set->values[entry];
diff -r 9e98f587da45 -r 5ce5f2cdb7be tools/libxl/libxlutil.h
--- a/tools/libxl/libxlutil.h Fri Nov 25 14:34:22 2011 +0000
+++ b/tools/libxl/libxlutil.h Fri Nov 25 14:34:51 2011 +0000
@@ -58,6 +58,8 @@ int xlu_cfg_get_list(const XLU_Config*,
int *entries_r /* may be 0 */,
int dont_warn);
/* there is no need to free *list_r; lifetime is that of the XLU_Config */
+int xlu_cfg_get_list_as_string_list(const XLU_Config *cfg, const char *n,
+ libxl_string_list *sl, int dont_warn);
const char *xlu_cfg_get_listitem(const XLU_ConfigList*, int entry);
/* xlu_cfg_get_listitem cannot fail, except that if entry is
* out of range it returns 0 (not setting errno) */
diff -r 9e98f587da45 -r 5ce5f2cdb7be tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c Fri Nov 25 14:34:22 2011 +0000
+++ b/tools/libxl/xl_cmdimpl.c Fri Nov 25 14:34:51 2011 +0000
@@ -529,13 +529,6 @@ static void parse_config_data(const char
int pci_msitranslate = 1;
int e;

- XLU_ConfigList *dmargs;
- int nr_dmargs = 0;
- XLU_ConfigList *dmargs_hvm;
- int nr_dmargs_hvm = 0;
- XLU_ConfigList *dmargs_pv;
- int nr_dmargs_pv = 0;
-
libxl_domain_create_info *c_info = &d_config->c_info;
libxl_domain_build_info *b_info = &d_config->b_info;

@@ -1093,19 +1086,14 @@ skip_vfb:
if (!xlu_cfg_get_long (config, "device_model_stubdomain_override", &l, 0))
dm_info->device_model_stubdomain = l;

-#define parse_extra_args(type) \
- if (!xlu_cfg_get_list(config, "device_model_args"#type, \
- &dmargs##type, &nr_dmargs##type, 0)) \
- { \
- int i; \
- dm_info->extra##type = \
- xmalloc(sizeof(char*)*(nr_dmargs##type + 1)); \
- dm_info->extra##type[nr_dmargs##type] = NULL; \
- for (i=0; i<nr_dmargs##type; i++) { \
- const char *a = xlu_cfg_get_listitem(dmargs##type, i); \
- dm_info->extra##type[i] = a ? strdup(a) : NULL; \
- } \
- } \
+#define parse_extra_args(type) \
+ e = xlu_cfg_get_list_as_string_list(config, "device_model_args"#type, \
+ &dm_info->extra##type, 0); \
+ if (e && e != ESRCH) { \
+ fprintf(stderr,"xl: Unable to parse device_model_args"#type".\n");\
+ exit(-ERROR_FAIL); \
+ }
+
/* parse extra args for qemu, common to both pv, hvm */
parse_extra_args();


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel