Ian Campbell
2010-Jul-26 12:20 UTC
[Xen-devel] [PATCH 0 of 3] xl: carry domain config around in struct domain_config
Move more domain configuration items into struct domain_config. Reduces the number of functions which take large numbers of parameters and generally just keeps configuration stuff in one place. _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ian Campbell
2010-Jul-26 12:20 UTC
[Xen-devel] [PATCH 1 of 3] xl: move create and build info to struct domain_config
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # Date 1280146761 -3600 # Node ID cc6592055443e9beaa0b39b28db0648146e15149 # Parent 113b04a7e60718c8730368a045a49ddd56e64fac xl: move create and build info to struct domain_config All three are passed around together and this begins to reduce some of the exceptionally long parameter lists. Signed-off-by: Ian Campbell <ian.campbell@citrix.com> diff -r 113b04a7e607 -r cc6592055443 tools/libxl/xl_cmdimpl.c --- a/tools/libxl/xl_cmdimpl.c Mon Jul 26 11:36:03 2010 +0100 +++ b/tools/libxl/xl_cmdimpl.c Mon Jul 26 13:19:21 2010 +0100 @@ -125,6 +125,9 @@ static char *action_on_shutdown_names[] }; struct domain_config { + libxl_domain_create_info c_info; + libxl_domain_build_info b_info; + enum action_on_shutdown on_poweroff; enum action_on_shutdown on_reboot; enum action_on_shutdown on_watchdog; @@ -354,8 +357,7 @@ static void init_console_info(libxl_devi } static void printf_info(int domid, - libxl_domain_create_info *c_info, - libxl_domain_build_info *b_info, + struct domain_config *d_config, libxl_device_disk *disks, int num_disks, libxl_device_nic *vifs, @@ -369,6 +371,10 @@ static void printf_info(int domid, libxl_device_model_info *dm_info) { int i; + + libxl_domain_create_info *c_info = &d_config->c_info; + libxl_domain_build_info *b_info = &d_config->b_info; + printf("(domain\n\t(domid %d)\n", domid); printf("\t(domain_create_info)\n"); printf("\t(hvm %d)\n", c_info->hvm); @@ -523,8 +529,6 @@ static void parse_config_data(const char static void parse_config_data(const char *configfile_filename_report, const char *configfile_data, int configfile_len, - libxl_domain_create_info *c_info, - libxl_domain_build_info *b_info, struct domain_config *d_config, libxl_device_disk **disks, int *num_disks, @@ -547,6 +551,9 @@ static void parse_config_data(const char int pci_power_mgmt = 0; int pci_msitranslate = 1; int e; + + libxl_domain_create_info *c_info = &d_config->c_info; + libxl_domain_build_info *b_info = &d_config->b_info; config= xlu_cfg_init(stderr, configfile_filename_report); if (!config) { @@ -1068,7 +1075,6 @@ int autoconnect_console(int hvm) /* Returns 1 if domain should be restarted, 2 if domain should be renamed then restarted */ static int handle_domain_death(struct libxl_ctx *ctx, uint32_t domid, libxl_event *event, - libxl_domain_create_info *c_info, struct domain_config *d_config, struct libxl_dominfo *info) { int restart = 0; @@ -1097,7 +1103,7 @@ static int handle_domain_death(struct li char *corefile; int rc; - if (asprintf(&corefile, "/var/xen/dump/%s", c_info->name) < 0) { + if (asprintf(&corefile, "/var/xen/dump/%s", d_config->c_info.name) < 0) { LOG("failed to construct core dump path"); } else { LOG("dumping core to %s", corefile); @@ -1138,7 +1144,6 @@ static int handle_domain_death(struct li } static int preserve_domain(struct libxl_ctx *ctx, uint32_t domid, libxl_event *event, - libxl_domain_create_info *c_info, struct domain_config *d_config, struct libxl_dominfo *info) { time_t now; @@ -1168,8 +1173,8 @@ static int preserve_domain(struct libxl_ random_uuid(&new_uuid[0]); - LOG("Preserving domain %d %s with suffix%s", domid, c_info->name, stime); - rc = libxl_domain_preserve(ctx, domid, c_info, stime, new_uuid); + LOG("Preserving domain %d %s with suffix%s", domid, d_config->c_info.name, stime); + rc = libxl_domain_preserve(ctx, domid, &d_config->c_info, stime, new_uuid); return rc == 0 ? 1 : 0; } @@ -1192,8 +1197,6 @@ static int create_domain(struct domain_c { struct domain_config d_config; - libxl_domain_create_info c_info; - libxl_domain_build_info b_info; libxl_domain_build_state state; libxl_device_model_info dm_info; libxl_device_disk *disks = NULL; @@ -1224,6 +1227,7 @@ static int create_domain(struct domain_c int restore_fd = -1; struct save_file_header hdr; + memset(&d_config, 0x00, sizeof(d_config); memset(&dm_info, 0x00, sizeof(dm_info)); if (restore_file) { @@ -1326,32 +1330,32 @@ static int create_domain(struct domain_c if (!dom_info->quiet) printf("Parsing config file %s\n", config_file); - parse_config_data(config_file, config_data, config_len, &c_info, &b_info, &d_config, &disks, &num_disks, &vifs, &num_vifs, &vif2s, &num_vif2s, &pcidevs, &num_pcidevs, &vfbs, &num_vfbs, &vkbs, &num_vkbs, &dm_info); + parse_config_data(config_file, config_data, config_len, &d_config, &disks, &num_disks, &vifs, &num_vifs, &vif2s, &num_vif2s, &pcidevs, &num_pcidevs, &vfbs, &num_vfbs, &vkbs, &num_vkbs, &dm_info); if (dom_info->dryrun) return 0; if (migrate_fd >= 0) { - if (c_info.name) { + if (d_config.c_info.name) { /* when we receive a domain we get its name from the config * file; and we receive it to a temporary name */ assert(!common_domname); - common_domname = c_info.name; - if (asprintf(migration_domname_r, "%s--incoming", c_info.name) < 0) { + common_domname = d_config.c_info.name; + if (asprintf(migration_domname_r, "%s--incoming", d_config.c_info.name) < 0) { fprintf(stderr, "Failed to allocate memory in asprintf\n"); exit(1); } - c_info.name = *migration_domname_r; + d_config.c_info.name = *migration_domname_r; } } if (debug) - printf_info(-1, &c_info, &b_info, disks, num_disks, vifs, num_vifs, pcidevs, num_pcidevs, vfbs, num_vfbs, vkbs, num_vkbs, &dm_info); + printf_info(-1, &d_config, disks, num_disks, vifs, num_vifs, pcidevs, num_pcidevs, vfbs, num_vfbs, vkbs, num_vkbs, &dm_info); start: domid = 0; - ret = libxl_domain_make(&ctx, &c_info, &domid); + ret = libxl_domain_make(&ctx, &d_config.c_info, &domid); if (ret) { fprintf(stderr, "cannot make domain: %d\n", ret); ret = ERROR_FAIL; @@ -1367,7 +1371,7 @@ start: } if (dom_info->console_autoconnect) { - ret = autoconnect_console(c_info.hvm); + ret = autoconnect_console(d_config.c_info.hvm); if (ret) goto error_out; } @@ -1384,7 +1388,7 @@ start: */ dom_info->console_autoconnect = 0; - ret = libxl_run_bootloader(&ctx, &b_info, num_disks > 0 ? &disks[0] : NULL, domid); + ret = libxl_run_bootloader(&ctx, &d_config.b_info, num_disks > 0 ? &disks[0] : NULL, domid); if (ret) { fprintf(stderr, "failed to run bootloader: %d\n", ret); goto error_out; @@ -1395,9 +1399,9 @@ start: free(dm_info.saved_state); dm_info.saved_state = NULL; } - ret = libxl_domain_build(&ctx, &b_info, domid, &state); - } else { - ret = libxl_domain_restore(&ctx, &b_info, domid, restore_fd, &state, &dm_info); + ret = libxl_domain_build(&ctx, &d_config.b_info, domid, &state); + } else { + ret = libxl_domain_restore(&ctx, &d_config.b_info, domid, restore_fd, &state, &dm_info); } if (ret) { @@ -1424,7 +1428,7 @@ start: goto error_out; } } - if (!c_info.hvm) { + if (!d_config.c_info.hvm) { for (i = 0; i < num_vif2s; i++) { vif2s[i].domid = domid; ret = libxl_device_net2_add(&ctx, domid, &(vif2s[i])); @@ -1435,7 +1439,7 @@ start: } } } - if (c_info.hvm) { + if (d_config.c_info.hvm) { dm_info.domid = domid; MUST( libxl_create_device_model(&ctx, &dm_info, disks, num_disks, vifs, num_vifs, &dm_starting) ); @@ -1499,7 +1503,7 @@ start: exit(-1); } - if (asprintf(&name, "xl-%s", c_info.name) < 0) { + if (asprintf(&name, "xl-%s", d_config.c_info.name) < 0) { LOG("Failed to allocate memory in asprintf"); exit(1); } @@ -1522,7 +1526,7 @@ start: need_daemon = 0; } LOG("Waiting for domain %s (domid %d) to die [pid %ld]", - c_info.name, domid, (long)getpid()); + d_config.c_info.name, domid, (long)getpid()); w1 = (libxl_waiter*) xmalloc(sizeof(libxl_waiter) * num_disks); w2 = (libxl_waiter*) xmalloc(sizeof(libxl_waiter)); libxl_wait_for_disk_ejects(&ctx, domid, disks, num_disks, w1); @@ -1550,9 +1554,9 @@ start: LOG("Domain %d is dead", domid); if (ret) { - switch (handle_domain_death(&ctx, domid, &event, &c_info, &d_config, &info)) { + switch (handle_domain_death(&ctx, domid, &event, &d_config, &info)) { case 2: - if (!preserve_domain(&ctx, domid, &event, &c_info, &d_config, &info)) + if (!preserve_domain(&ctx, domid, &event, &d_config, &info)) /* If we fail then exit leaving the old domain in place. */ exit(-1); @@ -2088,8 +2092,6 @@ void list_domains_details(void) uint8_t *data; int nb_domain, i, len, rc; int num_disks = 0, num_vifs = 0, num_vif2s = 0, num_pcidevs = 0, num_vfbs = 0, num_vkbs = 0; - libxl_domain_create_info c_info; - libxl_domain_build_info b_info; libxl_device_model_info dm_info; libxl_device_disk *disks = NULL; libxl_device_nic *vifs = NULL; @@ -2109,8 +2111,9 @@ void list_domains_details(void) if (rc) continue; CHK_ERRNO(asprintf(&config_file, "<domid %d data>", info[i].domid)); - parse_config_data(config_file, (char *)data, len, &c_info, &b_info, &d_config, &disks, &num_disks, &vifs, &num_vifs, &vif2s, &num_vif2s, &pcidevs, &num_pcidevs, &vfbs, &num_vfbs, &vkbs, &num_vkbs, &dm_info); - printf_info(info[i].domid, &c_info, &b_info, disks, num_disks, vifs, num_vifs, pcidevs, num_pcidevs, vfbs, num_vfbs, vkbs, num_vkbs, &dm_info); + memset(&d_config, 0x00, sizeof(d_config); + parse_config_data(config_file, (char *)data, len, &d_config, &disks, &num_disks, &vifs, &num_vifs, &vif2s, &num_vif2s, &pcidevs, &num_pcidevs, &vfbs, &num_vfbs, &vkbs, &num_vkbs, &dm_info); + printf_info(info[i].domid, &d_config, disks, num_disks, vifs, num_vifs, pcidevs, num_pcidevs, vfbs, num_vfbs, vkbs, num_vkbs, &dm_info); free(data); free(config_file); } _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ian Campbell
2010-Jul-26 12:20 UTC
[Xen-devel] [PATCH 2 of 3] xl: move device structs into struct domain_config
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # Date 1280146761 -3600 # Node ID 5b2a54afceb6215221c2e80329e2e14d2e7923c1 # Parent cc6592055443e9beaa0b39b28db0648146e15149 xl: move device structs into struct domain_config Signed-off-by: Ian Campbell <ian.campbell@citrix.com> diff -r cc6592055443 -r 5b2a54afceb6 tools/libxl/xl_cmdimpl.c --- a/tools/libxl/xl_cmdimpl.c Mon Jul 26 13:19:21 2010 +0100 +++ b/tools/libxl/xl_cmdimpl.c Mon Jul 26 13:19:21 2010 +0100 @@ -128,6 +128,15 @@ struct domain_config { libxl_domain_create_info c_info; libxl_domain_build_info b_info; + int num_disks, num_vifs, num_vif2s, num_pcidevs, num_vfbs, num_vkbs; + + libxl_device_disk *disks; + libxl_device_nic *vifs; + libxl_device_net2 *vif2s; + libxl_device_pci *pcidevs; + libxl_device_vfb *vfbs; + libxl_device_vkb *vkbs; + enum action_on_shutdown on_poweroff; enum action_on_shutdown on_reboot; enum action_on_shutdown on_watchdog; @@ -358,16 +367,6 @@ static void init_console_info(libxl_devi static void printf_info(int domid, struct domain_config *d_config, - libxl_device_disk *disks, - int num_disks, - libxl_device_nic *vifs, - int num_vifs, - libxl_device_pci *pcidevs, - int num_pcidevs, - libxl_device_vfb *vfbs, - int num_vfbs, - libxl_device_vkb *vkb, - int num_vkbs, libxl_device_model_info *dm_info) { int i; @@ -452,58 +451,66 @@ static void printf_info(int domid, } printf("\t)\n"); - for (i = 0; i < num_disks; i++) { + for (i = 0; i < d_config->num_disks; i++) { printf("\t(device\n"); printf("\t\t(tap\n"); - printf("\t\t\t(backend_domid %d)\n", disks[i].backend_domid); - printf("\t\t\t(domid %d)\n", disks[i].domid); - printf("\t\t\t(physpath %s)\n", disks[i].physpath); - printf("\t\t\t(phystype %d)\n", disks[i].phystype); - printf("\t\t\t(virtpath %s)\n", disks[i].virtpath); - printf("\t\t\t(unpluggable %d)\n", disks[i].unpluggable); - printf("\t\t\t(readwrite %d)\n", disks[i].readwrite); - printf("\t\t\t(is_cdrom %d)\n", disks[i].is_cdrom); + printf("\t\t\t(backend_domid %d)\n", d_config->disks[i].backend_domid); + printf("\t\t\t(domid %d)\n", d_config->disks[i].domid); + printf("\t\t\t(physpath %s)\n", d_config->disks[i].physpath); + printf("\t\t\t(phystype %d)\n", d_config->disks[i].phystype); + printf("\t\t\t(virtpath %s)\n", d_config->disks[i].virtpath); + printf("\t\t\t(unpluggable %d)\n", d_config->disks[i].unpluggable); + printf("\t\t\t(readwrite %d)\n", d_config->disks[i].readwrite); + printf("\t\t\t(is_cdrom %d)\n", d_config->disks[i].is_cdrom); printf("\t\t)\n"); printf("\t)\n"); } - for (i = 0; i < num_vifs; i++) { + for (i = 0; i < d_config->num_vifs; i++) { printf("\t(device\n"); printf("\t\t(vif\n"); - printf("\t\t\t(backend_domid %d)\n", vifs[i].backend_domid); - printf("\t\t\t(domid %d)\n", vifs[i].domid); - printf("\t\t\t(devid %d)\n", vifs[i].devid); - printf("\t\t\t(mtu %d)\n", vifs[i].mtu); - printf("\t\t\t(model %s)\n", vifs[i].model); - printf("\t\t\t(mac %02x%02x%02x%02x%02x%02x)\n", vifs[i].mac[0], vifs[i].mac[1], vifs[i].mac[2], vifs[i].mac[3], vifs[i].mac[4], vifs[i].mac[5]); + printf("\t\t\t(backend_domid %d)\n", d_config->vifs[i].backend_domid); + printf("\t\t\t(domid %d)\n", d_config->vifs[i].domid); + printf("\t\t\t(devid %d)\n", d_config->vifs[i].devid); + printf("\t\t\t(mtu %d)\n", d_config->vifs[i].mtu); + printf("\t\t\t(model %s)\n", d_config->vifs[i].model); + printf("\t\t\t(mac %02x%02x%02x%02x%02x%02x)\n", + d_config->vifs[i].mac[0], d_config->vifs[i].mac[1], + d_config->vifs[i].mac[2], d_config->vifs[i].mac[3], + d_config->vifs[i].mac[4], d_config->vifs[i].mac[5]); printf("\t\t)\n"); printf("\t)\n"); } - for (i = 0; i < num_pcidevs; i++) { + for (i = 0; i < d_config->num_pcidevs; i++) { printf("\t(device\n"); printf("\t\t(pci\n"); - printf("\t\t\t(pci dev "PCI_BDF_VDEVFN")\n", pcidevs[i].domain, pcidevs[i].bus, pcidevs[i].dev, pcidevs[i].func, pcidevs[i].vdevfn); - printf("\t\t\t(opts msitranslate %d power_mgmt %d)\n", pcidevs[i].msitranslate, pcidevs[i].power_mgmt); + printf("\t\t\t(pci dev "PCI_BDF_VDEVFN")\n", + d_config->pcidevs[i].domain, d_config->pcidevs[i].bus, + d_config->pcidevs[i].dev, d_config->pcidevs[i].func, + d_config->pcidevs[i].vdevfn); + printf("\t\t\t(opts msitranslate %d power_mgmt %d)\n", + d_config->pcidevs[i].msitranslate, + d_config->pcidevs[i].power_mgmt); printf("\t\t)\n"); printf("\t)\n"); } - for (i = 0; i < num_vfbs; i++) { + for (i = 0; i < d_config->num_vfbs; i++) { printf("\t(device\n"); printf("\t\t(vfb\n"); - printf("\t\t\t(backend_domid %d)\n", vfbs[i].backend_domid); - printf("\t\t\t(domid %d)\n", vfbs[i].domid); - printf("\t\t\t(devid %d)\n", vfbs[i].devid); - printf("\t\t\t(vnc %d)\n", vfbs[i].vnc); - printf("\t\t\t(vnclisten %s)\n", vfbs[i].vnclisten); - printf("\t\t\t(vncdisplay %d)\n", vfbs[i].vncdisplay); - printf("\t\t\t(vncunused %d)\n", vfbs[i].vncunused); - printf("\t\t\t(keymap %s)\n", vfbs[i].keymap); - printf("\t\t\t(sdl %d)\n", vfbs[i].sdl); - printf("\t\t\t(opengl %d)\n", vfbs[i].opengl); - printf("\t\t\t(display %s)\n", vfbs[i].display); - printf("\t\t\t(xauthority %s)\n", vfbs[i].xauthority); + printf("\t\t\t(backend_domid %d)\n", d_config->vfbs[i].backend_domid); + printf("\t\t\t(domid %d)\n", d_config->vfbs[i].domid); + printf("\t\t\t(devid %d)\n", d_config->vfbs[i].devid); + printf("\t\t\t(vnc %d)\n", d_config->vfbs[i].vnc); + printf("\t\t\t(vnclisten %s)\n", d_config->vfbs[i].vnclisten); + printf("\t\t\t(vncdisplay %d)\n", d_config->vfbs[i].vncdisplay); + printf("\t\t\t(vncunused %d)\n", d_config->vfbs[i].vncunused); + printf("\t\t\t(keymap %s)\n", d_config->vfbs[i].keymap); + printf("\t\t\t(sdl %d)\n", d_config->vfbs[i].sdl); + printf("\t\t\t(opengl %d)\n", d_config->vfbs[i].opengl); + printf("\t\t\t(display %s)\n", d_config->vfbs[i].display); + printf("\t\t\t(xauthority %s)\n", d_config->vfbs[i].xauthority); printf("\t\t)\n"); printf("\t)\n"); } @@ -530,18 +537,6 @@ static void parse_config_data(const char const char *configfile_data, int configfile_len, struct domain_config *d_config, - libxl_device_disk **disks, - int *num_disks, - libxl_device_nic **vifs, - int *num_vifs, - libxl_device_net2 **vif2s, - int *num_vif2s, - libxl_device_pci **pcidevs, - int *num_pcidevs, - libxl_device_vfb **vfbs, - int *num_vfbs, - libxl_device_vkb **vkbs, - int *num_vkbs, libxl_device_model_info *dm_info) { const char *buf; @@ -710,72 +705,72 @@ static void parse_config_data(const char } if (!xlu_cfg_get_list (config, "disk", &vbds, 0)) { - *num_disks = 0; - *disks = NULL; - while ((buf = xlu_cfg_get_listitem (vbds, *num_disks)) != NULL) { + d_config->num_disks = 0; + d_config->disks = NULL; + while ((buf = xlu_cfg_get_listitem (vbds, d_config->num_disks)) != NULL) { char *buf2 = strdup(buf); char *p, *p2; - *disks = (libxl_device_disk *) realloc(*disks, sizeof (libxl_device_disk) * ((*num_disks) + 1)); - (*disks)[*num_disks].backend_domid = 0; - (*disks)[*num_disks].domid = 0; - (*disks)[*num_disks].unpluggable = 0; + d_config->disks = (libxl_device_disk *) realloc(d_config->disks, sizeof (libxl_device_disk) * (d_config->num_disks + 1)); + d_config->disks[d_config->num_disks].backend_domid = 0; + d_config->disks[d_config->num_disks].domid = 0; + d_config->disks[d_config->num_disks].unpluggable = 0; p = strtok(buf2, ",:"); while (*p == '' '') p++; if (!strcmp(p, "phy")) { - (*disks)[*num_disks].phystype = PHYSTYPE_PHY; + d_config->disks[d_config->num_disks].phystype = PHYSTYPE_PHY; } else if (!strcmp(p, "file")) { - (*disks)[*num_disks].phystype = PHYSTYPE_FILE; + d_config->disks[d_config->num_disks].phystype = PHYSTYPE_FILE; } else if (!strcmp(p, "tap")) { p = strtok(NULL, ":"); if (!strcmp(p, "aio")) { - (*disks)[*num_disks].phystype = PHYSTYPE_AIO; + d_config->disks[d_config->num_disks].phystype = PHYSTYPE_AIO; } else if (!strcmp(p, "vhd")) { - (*disks)[*num_disks].phystype = PHYSTYPE_VHD; + d_config->disks[d_config->num_disks].phystype = PHYSTYPE_VHD; } else if (!strcmp(p, "qcow")) { - (*disks)[*num_disks].phystype = PHYSTYPE_QCOW; + d_config->disks[d_config->num_disks].phystype = PHYSTYPE_QCOW; } else if (!strcmp(p, "qcow2")) { - (*disks)[*num_disks].phystype = PHYSTYPE_QCOW2; + d_config->disks[d_config->num_disks].phystype = PHYSTYPE_QCOW2; } } p = strtok(NULL, ","); while (*p == '' '') p++; - (*disks)[*num_disks].physpath= strdup(p); + d_config->disks[d_config->num_disks].physpath= strdup(p); p = strtok(NULL, ","); while (*p == '' '') p++; p2 = strchr(p, '':''); if (p2 == NULL) { - (*disks)[*num_disks].virtpath = strdup(p); - (*disks)[*num_disks].is_cdrom = 0; - (*disks)[*num_disks].unpluggable = 1; + d_config->disks[d_config->num_disks].virtpath = strdup(p); + d_config->disks[d_config->num_disks].is_cdrom = 0; + d_config->disks[d_config->num_disks].unpluggable = 1; } else { *p2 = ''\0''; - (*disks)[*num_disks].virtpath = strdup(p); + d_config->disks[d_config->num_disks].virtpath = strdup(p); if (!strcmp(p2 + 1, "cdrom")) { - (*disks)[*num_disks].is_cdrom = 1; - (*disks)[*num_disks].unpluggable = 1; + d_config->disks[d_config->num_disks].is_cdrom = 1; + d_config->disks[d_config->num_disks].unpluggable = 1; } else - (*disks)[*num_disks].is_cdrom = 0; + d_config->disks[d_config->num_disks].is_cdrom = 0; } p = strtok(NULL, ","); while (*p == '' '') p++; - (*disks)[*num_disks].readwrite = (p[0] == ''w'') ? 1 : 0; - free(buf2); - *num_disks = (*num_disks) + 1; + d_config->disks[d_config->num_disks].readwrite = (p[0] == ''w'') ? 1 : 0; + free(buf2); + d_config->num_disks = d_config->num_disks + 1; } } if (!xlu_cfg_get_list (config, "vif", &nics, 0)) { - *num_vifs = 0; - *vifs = NULL; - while ((buf = xlu_cfg_get_listitem (nics, *num_vifs)) != NULL) { + d_config->num_vifs = 0; + d_config->vifs = NULL; + while ((buf = xlu_cfg_get_listitem (nics, d_config->num_vifs)) != NULL) { char *buf2 = strdup(buf); char *p, *p2; - *vifs = (libxl_device_nic *) realloc(*vifs, sizeof (libxl_device_nic) * ((*num_vifs) + 1)); - init_nic_info((*vifs) + (*num_vifs), (*num_vifs)); + d_config->vifs = (libxl_device_nic *) realloc(d_config->vifs, sizeof (libxl_device_nic) * (d_config->num_vifs+1)); + init_nic_info(d_config->vifs + d_config->num_vifs, d_config->num_vifs); p = strtok(buf2, ","); if (!p) goto skip; @@ -786,39 +781,39 @@ static void parse_config_data(const char break; *p2 = ''\0''; if (!strcmp(p, "model")) { - (*vifs)[*num_vifs].model = strdup(p2 + 1); + d_config->vifs[d_config->num_vifs].model = strdup(p2 + 1); } else if (!strcmp(p, "mac")) { char *p3 = p2 + 1; *(p3 + 2) = ''\0''; - (*vifs)[*num_vifs].mac[0] = strtol(p3, NULL, 16); - p3 = p3 + 3; - *(p3 + 2) = ''\0''; - (*vifs)[*num_vifs].mac[1] = strtol(p3, NULL, 16); - p3 = p3 + 3; - *(p3 + 2) = ''\0''; - (*vifs)[*num_vifs].mac[2] = strtol(p3, NULL, 16); - p3 = p3 + 3; - *(p3 + 2) = ''\0''; - (*vifs)[*num_vifs].mac[3] = strtol(p3, NULL, 16); - p3 = p3 + 3; - *(p3 + 2) = ''\0''; - (*vifs)[*num_vifs].mac[4] = strtol(p3, NULL, 16); - p3 = p3 + 3; - *(p3 + 2) = ''\0''; - (*vifs)[*num_vifs].mac[5] = strtol(p3, NULL, 16); + d_config->vifs[d_config->num_vifs].mac[0] = strtol(p3, NULL, 16); + p3 = p3 + 3; + *(p3 + 2) = ''\0''; + d_config->vifs[d_config->num_vifs].mac[1] = strtol(p3, NULL, 16); + p3 = p3 + 3; + *(p3 + 2) = ''\0''; + d_config->vifs[d_config->num_vifs].mac[2] = strtol(p3, NULL, 16); + p3 = p3 + 3; + *(p3 + 2) = ''\0''; + d_config->vifs[d_config->num_vifs].mac[3] = strtol(p3, NULL, 16); + p3 = p3 + 3; + *(p3 + 2) = ''\0''; + d_config->vifs[d_config->num_vifs].mac[4] = strtol(p3, NULL, 16); + p3 = p3 + 3; + *(p3 + 2) = ''\0''; + d_config->vifs[d_config->num_vifs].mac[5] = strtol(p3, NULL, 16); } else if (!strcmp(p, "bridge")) { - (*vifs)[*num_vifs].bridge = strdup(p2 + 1); + d_config->vifs[d_config->num_vifs].bridge = strdup(p2 + 1); } else if (!strcmp(p, "type")) { if (!strcmp(p2 + 1, "ioemu")) - (*vifs)[*num_vifs].nictype = NICTYPE_IOEMU; + d_config->vifs[d_config->num_vifs].nictype = NICTYPE_IOEMU; else - (*vifs)[*num_vifs].nictype = NICTYPE_VIF; + d_config->vifs[d_config->num_vifs].nictype = NICTYPE_VIF; } else if (!strcmp(p, "ip")) { - inet_pton(AF_INET, p2 + 1, &((*vifs)[*num_vifs].ip)); + inet_pton(AF_INET, p2 + 1, &d_config->vifs[d_config->num_vifs].ip); } else if (!strcmp(p, "script")) { - (*vifs)[*num_vifs].script = strdup(p2 + 1); + d_config->vifs[d_config->num_vifs].script = strdup(p2 + 1); } else if (!strcmp(p, "vifname")) { - (*vifs)[*num_vifs].ifname = strdup(p2 + 1); + d_config->vifs[d_config->num_vifs].ifname = strdup(p2 + 1); } else if (!strcmp(p, "rate")) { fprintf(stderr, "the rate parameter for vifs is currently not supported\n"); } else if (!strcmp(p, "accel")) { @@ -827,63 +822,63 @@ static void parse_config_data(const char } while ((p = strtok(NULL, ",")) != NULL); skip: free(buf2); - *num_vifs = (*num_vifs) + 1; + d_config->num_vifs = d_config->num_vifs + 1; } } if (!xlu_cfg_get_list(config, "vif2", &net2s, 0)) { - *num_vif2s = 0; - *vif2s = NULL; - while ((buf = xlu_cfg_get_listitem(net2s, *num_vif2s))) { + d_config->num_vif2s = 0; + d_config->vif2s = NULL; + while ((buf = xlu_cfg_get_listitem(net2s, d_config->num_vif2s))) { char *buf2 = strdup(buf); char *p; - *vif2s = realloc(*vif2s, sizeof (libxl_device_net2) * (*num_vif2s + 1)); - init_net2_info(*vif2s + *num_vif2s, *num_vif2s); + d_config->vif2s = realloc(d_config->vif2s, sizeof (libxl_device_net2) * (d_config->num_vif2s + 1)); + init_net2_info(d_config->vif2s + d_config->num_vif2s, d_config->num_vif2s); for (p = strtok(buf2, ","); p; p = strtok(buf2, ",")) { while (isblank(*p)) p++; if (!strncmp("front_mac=", p, 10)) { - libxl_strtomac(p + 10, (*vif2s)[*num_vif2s].front_mac); + libxl_strtomac(p + 10, d_config->vif2s[d_config->num_vif2s].front_mac); } else if (!strncmp("back_mac=", p, 9)) { - libxl_strtomac(p + 9, (*vif2s)[*num_vif2s].back_mac); + libxl_strtomac(p + 9, d_config->vif2s[d_config->num_vif2s].back_mac); } else if (!strncmp("backend=", p, 8)) { - domain_qualifier_to_domid(p + 8, &((*vif2s)[*num_vif2s].backend_domid), 0); + domain_qualifier_to_domid(p + 8, &d_config->vif2s[d_config->num_vif2s].backend_domid, 0); } else if (!strncmp("trusted=", p, 8)) { - (*vif2s)[*num_vif2s].trusted = (*(p + 8) == ''1''); + d_config->vif2s[d_config->num_vif2s].trusted = (*(p + 8) == ''1''); } else if (!strncmp("back_trusted=", p, 13)) { - (*vif2s)[*num_vif2s].back_trusted = (*(p + 13) == ''1''); + d_config->vif2s[d_config->num_vif2s].back_trusted = (*(p + 13) == ''1''); } else if (!strncmp("bridge=", p, 7)) { - (*vif2s)[*num_vif2s].bridge = strdup(p + 13); + d_config->vif2s[d_config->num_vif2s].bridge = strdup(p + 13); } else if (!strncmp("filter_mac=", p, 11)) { - (*vif2s)[*num_vif2s].filter_mac = (*(p + 11) == ''1''); + d_config->vif2s[d_config->num_vif2s].filter_mac = (*(p + 11) == ''1''); } else if (!strncmp("front_filter_mac=", p, 17)) { - (*vif2s)[*num_vif2s].front_filter_mac = (*(p + 17) == ''1''); + d_config->vif2s[d_config->num_vif2s].front_filter_mac = (*(p + 17) == ''1''); } else if (!strncmp("pdev=", p, 5)) { - (*vif2s)[*num_vif2s].pdev = strtoul(p + 5, NULL, 10); + d_config->vif2s[d_config->num_vif2s].pdev = strtoul(p + 5, NULL, 10); } else if (!strncmp("max_bypasses=", p, 13)) { - (*vif2s)[*num_vif2s].max_bypasses = strtoul(p + 13, NULL, 10); - } - } - free(buf2); - ++(*num_vif2s); + d_config->vif2s[d_config->num_vif2s].max_bypasses = strtoul(p + 13, NULL, 10); + } + } + free(buf2); + ++d_config->num_vif2s; } } if (!xlu_cfg_get_list (config, "vfb", &cvfbs, 0)) { - *num_vfbs = 0; - *num_vkbs = 0; - *vfbs = NULL; - *vkbs = NULL; - while ((buf = xlu_cfg_get_listitem (cvfbs, *num_vfbs)) != NULL) { + d_config->num_vfbs = 0; + d_config->num_vkbs = 0; + d_config->vfbs = NULL; + d_config->vkbs = NULL; + while ((buf = xlu_cfg_get_listitem (cvfbs, d_config->num_vfbs)) != NULL) { char *buf2 = strdup(buf); char *p, *p2; - *vfbs = (libxl_device_vfb *) realloc(*vfbs, sizeof(libxl_device_vfb) * ((*num_vfbs) + 1)); - init_vfb_info((*vfbs) + (*num_vfbs), (*num_vfbs)); - - *vkbs = (libxl_device_vkb *) realloc(*vkbs, sizeof(libxl_device_vkb) * ((*num_vkbs) + 1)); - init_vkb_info((*vkbs) + (*num_vkbs), (*num_vkbs)); + d_config->vfbs = (libxl_device_vfb *) realloc(d_config->vfbs, sizeof(libxl_device_vfb) * (d_config->num_vfbs + 1)); + init_vfb_info(d_config->vfbs + d_config->num_vfbs, d_config->num_vfbs); + + d_config->vkbs = (libxl_device_vkb *) realloc(d_config->vkbs, sizeof(libxl_device_vkb) * (d_config->num_vkbs + 1)); + init_vkb_info(d_config->vkbs + d_config->num_vkbs, d_config->num_vkbs); p = strtok(buf2, ","); if (!p) @@ -895,31 +890,31 @@ skip: break; *p2 = ''\0''; if (!strcmp(p, "vnc")) { - (*vfbs)[*num_vfbs].vnc = atoi(p2 + 1); + d_config->vfbs[d_config->num_vfbs].vnc = atoi(p2 + 1); } else if (!strcmp(p, "vnclisten")) { - (*vfbs)[*num_vfbs].vnclisten = strdup(p2 + 1); + d_config->vfbs[d_config->num_vfbs].vnclisten = strdup(p2 + 1); } else if (!strcmp(p, "vncpasswd")) { - (*vfbs)[*num_vfbs].vncpasswd = strdup(p2 + 1); + d_config->vfbs[d_config->num_vfbs].vncpasswd = strdup(p2 + 1); } else if (!strcmp(p, "vncdisplay")) { - (*vfbs)[*num_vfbs].vncdisplay = atoi(p2 + 1); + d_config->vfbs[d_config->num_vfbs].vncdisplay = atoi(p2 + 1); } else if (!strcmp(p, "vncunused")) { - (*vfbs)[*num_vfbs].vncunused = atoi(p2 + 1); + d_config->vfbs[d_config->num_vfbs].vncunused = atoi(p2 + 1); } else if (!strcmp(p, "keymap")) { - (*vfbs)[*num_vfbs].keymap = strdup(p2 + 1); + d_config->vfbs[d_config->num_vfbs].keymap = strdup(p2 + 1); } else if (!strcmp(p, "sdl")) { - (*vfbs)[*num_vfbs].sdl = atoi(p2 + 1); + d_config->vfbs[d_config->num_vfbs].sdl = atoi(p2 + 1); } else if (!strcmp(p, "opengl")) { - (*vfbs)[*num_vfbs].opengl = atoi(p2 + 1); + d_config->vfbs[d_config->num_vfbs].opengl = atoi(p2 + 1); } else if (!strcmp(p, "display")) { - (*vfbs)[*num_vfbs].display = strdup(p2 + 1); + d_config->vfbs[d_config->num_vfbs].display = strdup(p2 + 1); } else if (!strcmp(p, "xauthority")) { - (*vfbs)[*num_vfbs].xauthority = strdup(p2 + 1); + d_config->vfbs[d_config->num_vfbs].xauthority = strdup(p2 + 1); } } while ((p = strtok(NULL, ",")) != NULL); skip_vfb: free(buf2); - *num_vfbs = (*num_vfbs) + 1; - *num_vkbs = (*num_vkbs) + 1; + d_config->num_vfbs = d_config->num_vfbs + 1; + d_config->num_vkbs = d_config->num_vkbs + 1; } } @@ -930,14 +925,14 @@ skip_vfb: pci_power_mgmt = l; if (!xlu_cfg_get_list (config, "pci", &pcis, 0)) { - *num_pcidevs = 0; - *pcidevs = NULL; - while ((buf = xlu_cfg_get_listitem (pcis, *num_pcidevs)) != NULL) { + d_config->num_pcidevs = 0; + d_config->pcidevs = NULL; + while ((buf = xlu_cfg_get_listitem (pcis, d_config->num_pcidevs)) != NULL) { unsigned int domain = 0, bus = 0, dev = 0, func = 0, vdevfn = 0; char *buf2 = strdup(buf); char *p; - *pcidevs = (libxl_device_pci *) realloc(*pcidevs, sizeof (libxl_device_pci) * ((*num_pcidevs) + 1)); - memset(*pcidevs + *num_pcidevs, 0x00, sizeof(libxl_device_pci)); + d_config->pcidevs = (libxl_device_pci *) realloc(d_config->pcidevs, sizeof (libxl_device_pci) * (d_config->num_pcidevs + 1)); + memset(d_config->pcidevs + d_config->num_pcidevs, 0x00, sizeof(libxl_device_pci)); p = strtok(buf2, ","); if (!p) goto skip_pci; @@ -948,21 +943,21 @@ skip_vfb: goto skip_pci; } } - libxl_device_pci_init(*pcidevs + *num_pcidevs, domain, bus, dev, func, vdevfn); - (*pcidevs)[*num_pcidevs].msitranslate = pci_msitranslate; - (*pcidevs)[*num_pcidevs].power_mgmt = pci_power_mgmt; + libxl_device_pci_init(d_config->pcidevs + d_config->num_pcidevs, domain, bus, dev, func, vdevfn); + d_config->pcidevs[d_config->num_pcidevs].msitranslate = pci_msitranslate; + d_config->pcidevs[d_config->num_pcidevs].power_mgmt = pci_power_mgmt; while ((p = strtok(NULL, ",=")) != NULL) { while (*p == '' '') p++; if (!strcmp(p, "msitranslate")) { p = strtok(NULL, ",="); - (*pcidevs)[*num_pcidevs].msitranslate = atoi(p); + d_config->pcidevs[d_config->num_pcidevs].msitranslate = atoi(p); } else if (!strcmp(p, "power_mgmt")) { p = strtok(NULL, ",="); - (*pcidevs)[*num_pcidevs].power_mgmt = atoi(p); - } - } - *num_pcidevs = (*num_pcidevs) + 1; + d_config->pcidevs[d_config->num_pcidevs].power_mgmt = atoi(p); + } + } + d_config->num_pcidevs = d_config->num_pcidevs + 1; skip_pci: free(buf2); } @@ -1199,12 +1194,6 @@ static int create_domain(struct domain_c libxl_domain_build_state state; libxl_device_model_info dm_info; - libxl_device_disk *disks = NULL; - libxl_device_nic *vifs = NULL; - libxl_device_net2 *vif2s = NULL; - libxl_device_pci *pcidevs = NULL; - libxl_device_vfb *vfbs = NULL; - libxl_device_vkb *vkbs = NULL; libxl_device_console console; int debug = dom_info->debug; @@ -1216,7 +1205,6 @@ static int create_domain(struct domain_c int migrate_fd = dom_info->migrate_fd; char **migration_domname_r = dom_info->migration_domname_r; - int num_disks = 0, num_vifs = 0, num_vif2s = 0, num_pcidevs = 0, num_vfbs = 0, num_vkbs = 0; int i, fd; int need_daemon = 1; int ret, rc; @@ -1227,7 +1215,7 @@ static int create_domain(struct domain_c int restore_fd = -1; struct save_file_header hdr; - memset(&d_config, 0x00, sizeof(d_config); + memset(&d_config, 0x00, sizeof(d_config)); memset(&dm_info, 0x00, sizeof(dm_info)); if (restore_file) { @@ -1330,7 +1318,7 @@ static int create_domain(struct domain_c if (!dom_info->quiet) printf("Parsing config file %s\n", config_file); - parse_config_data(config_file, config_data, config_len, &d_config, &disks, &num_disks, &vifs, &num_vifs, &vif2s, &num_vif2s, &pcidevs, &num_pcidevs, &vfbs, &num_vfbs, &vkbs, &num_vkbs, &dm_info); + parse_config_data(config_file, config_data, config_len, &d_config, &dm_info); if (dom_info->dryrun) return 0; @@ -1350,7 +1338,7 @@ static int create_domain(struct domain_c } if (debug) - printf_info(-1, &d_config, disks, num_disks, vifs, num_vifs, pcidevs, num_pcidevs, vfbs, num_vfbs, vkbs, num_vkbs, &dm_info); + printf_info(-1, &d_config, &dm_info); start: domid = 0; @@ -1388,7 +1376,7 @@ start: */ dom_info->console_autoconnect = 0; - ret = libxl_run_bootloader(&ctx, &d_config.b_info, num_disks > 0 ? &disks[0] : NULL, domid); + ret = libxl_run_bootloader(&ctx, &d_config.b_info, d_config.num_disks > 0 ? &d_config.disks[0] : NULL, domid); if (ret) { fprintf(stderr, "failed to run bootloader: %d\n", ret); goto error_out; @@ -1410,18 +1398,18 @@ start: goto error_out; } - for (i = 0; i < num_disks; i++) { - disks[i].domid = domid; - ret = libxl_device_disk_add(&ctx, domid, &disks[i]); + for (i = 0; i < d_config.num_disks; i++) { + d_config.disks[i].domid = domid; + ret = libxl_device_disk_add(&ctx, domid, &d_config.disks[i]); if (ret) { fprintf(stderr, "cannot add disk %d to domain: %d\n", i, ret); ret = ERROR_FAIL; goto error_out; } } - for (i = 0; i < num_vifs; i++) { - vifs[i].domid = domid; - ret = libxl_device_nic_add(&ctx, domid, &vifs[i]); + for (i = 0; i < d_config.num_vifs; i++) { + d_config.vifs[i].domid = domid; + ret = libxl_device_nic_add(&ctx, domid, &d_config.vifs[i]); if (ret) { fprintf(stderr, "cannot add nic %d to domain: %d\n", i, ret); ret = ERROR_FAIL; @@ -1429,9 +1417,9 @@ start: } } if (!d_config.c_info.hvm) { - for (i = 0; i < num_vif2s; i++) { - vif2s[i].domid = domid; - ret = libxl_device_net2_add(&ctx, domid, &(vif2s[i])); + for (i = 0; i < d_config.num_vif2s; i++) { + d_config.vif2s[i].domid = domid; + ret = libxl_device_net2_add(&ctx, domid, &d_config.vif2s[i]); if (ret) { fprintf(stderr, "cannot add net2 %d to domain: %d\n", i, ret); ret = ERROR_FAIL; @@ -1441,28 +1429,30 @@ start: } if (d_config.c_info.hvm) { dm_info.domid = domid; - MUST( libxl_create_device_model(&ctx, &dm_info, disks, num_disks, - vifs, num_vifs, &dm_starting) ); - } else { - for (i = 0; i < num_vfbs; i++) { - vfbs[i].domid = domid; - libxl_device_vfb_add(&ctx, domid, &vfbs[i]); - vkbs[i].domid = domid; - libxl_device_vkb_add(&ctx, domid, &vkbs[i]); + MUST( libxl_create_device_model(&ctx, &dm_info, + d_config.disks, d_config.num_disks, + d_config.vifs, d_config.num_vifs, + &dm_starting) ); + } else { + for (i = 0; i < d_config.num_vfbs; i++) { + d_config.vfbs[i].domid = domid; + libxl_device_vfb_add(&ctx, domid, &d_config.vfbs[i]); + d_config.vkbs[i].domid = domid; + libxl_device_vkb_add(&ctx, domid, &d_config.vkbs[i]); } init_console_info(&console, 0, &state); console.domid = domid; - if (num_vfbs) + if (d_config.num_vfbs) console.constype = CONSTYPE_IOEMU; libxl_device_console_add(&ctx, domid, &console); - if (num_vfbs) - libxl_create_xenpv_qemu(&ctx, vfbs, 1, &console, &dm_starting); + if (d_config.num_vfbs) + libxl_create_xenpv_qemu(&ctx, d_config.vfbs, 1, &console, &dm_starting); } if (dm_starting) MUST( libxl_confirm_device_model_startup(&ctx, dm_starting) ); - for (i = 0; i < num_pcidevs; i++) - libxl_device_pci_add(&ctx, domid, &pcidevs[i]); + for (i = 0; i < d_config.num_pcidevs; i++) + libxl_device_pci_add(&ctx, domid, &d_config.pcidevs[i]); if (!paused) libxl_domain_unpause(&ctx, domid); @@ -1527,9 +1517,9 @@ start: } LOG("Waiting for domain %s (domid %d) to die [pid %ld]", d_config.c_info.name, domid, (long)getpid()); - w1 = (libxl_waiter*) xmalloc(sizeof(libxl_waiter) * num_disks); + w1 = (libxl_waiter*) xmalloc(sizeof(libxl_waiter) * d_config.num_disks); w2 = (libxl_waiter*) xmalloc(sizeof(libxl_waiter)); - libxl_wait_for_disk_ejects(&ctx, domid, disks, num_disks, w1); + libxl_wait_for_disk_ejects(&ctx, domid, d_config.disks, d_config.num_disks, w1); libxl_wait_for_domain_death(&ctx, domid, w2); libxl_get_wait_fd(&ctx, &fd); while (1) { @@ -2091,14 +2081,7 @@ void list_domains_details(void) char *config_file; uint8_t *data; int nb_domain, i, len, rc; - int num_disks = 0, num_vifs = 0, num_vif2s = 0, num_pcidevs = 0, num_vfbs = 0, num_vkbs = 0; libxl_device_model_info dm_info; - libxl_device_disk *disks = NULL; - libxl_device_nic *vifs = NULL; - libxl_device_net2 *vif2s = NULL; - libxl_device_pci *pcidevs = NULL; - libxl_device_vfb *vfbs = NULL; - libxl_device_vkb *vkbs = NULL; info = libxl_list_domain(&ctx, &nb_domain); @@ -2111,9 +2094,9 @@ void list_domains_details(void) if (rc) continue; CHK_ERRNO(asprintf(&config_file, "<domid %d data>", info[i].domid)); - memset(&d_config, 0x00, sizeof(d_config); - parse_config_data(config_file, (char *)data, len, &d_config, &disks, &num_disks, &vifs, &num_vifs, &vif2s, &num_vif2s, &pcidevs, &num_pcidevs, &vfbs, &num_vfbs, &vkbs, &num_vkbs, &dm_info); - printf_info(info[i].domid, &d_config, disks, num_disks, vifs, num_vifs, pcidevs, num_pcidevs, vfbs, num_vfbs, vkbs, num_vkbs, &dm_info); + memset(&d_config, 0x00, sizeof(d_config)); + parse_config_data(config_file, (char *)data, len, &d_config, &dm_info); + printf_info(info[i].domid, &d_config, &dm_info); free(data); free(config_file); } _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ian Campbell
2010-Jul-26 12:20 UTC
[Xen-devel] [PATCH 3 of 3] xl: simplify configuration parsing with local variables
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # Date 1280146761 -3600 # Node ID 5e3a372815d1a44f6c2e1238bb5f4bcc5290a3fb # Parent 5b2a54afceb6215221c2e80329e2e14d2e7923c1 xl: simplify configuration parsing with local variables Replace repeated patterns of "d_config->THING[d_config->num_THING]" with a single local variable. Signed-off-by: Ian Campbell <ian.campbell@citrix.com> diff -r 5b2a54afceb6 -r 5e3a372815d1 tools/libxl/xl_cmdimpl.c --- a/tools/libxl/xl_cmdimpl.c Mon Jul 26 13:19:21 2010 +0100 +++ b/tools/libxl/xl_cmdimpl.c Mon Jul 26 13:19:21 2010 +0100 @@ -708,58 +708,63 @@ static void parse_config_data(const char d_config->num_disks = 0; d_config->disks = NULL; while ((buf = xlu_cfg_get_listitem (vbds, d_config->num_disks)) != NULL) { + libxl_device_disk *disk; char *buf2 = strdup(buf); char *p, *p2; + d_config->disks = (libxl_device_disk *) realloc(d_config->disks, sizeof (libxl_device_disk) * (d_config->num_disks + 1)); - d_config->disks[d_config->num_disks].backend_domid = 0; - d_config->disks[d_config->num_disks].domid = 0; - d_config->disks[d_config->num_disks].unpluggable = 0; + disk = d_config->disks + d_config->num_disks; + + disk->backend_domid = 0; + disk->domid = 0; + disk->unpluggable = 0; + p = strtok(buf2, ",:"); while (*p == '' '') p++; if (!strcmp(p, "phy")) { - d_config->disks[d_config->num_disks].phystype = PHYSTYPE_PHY; + disk->phystype = PHYSTYPE_PHY; } else if (!strcmp(p, "file")) { - d_config->disks[d_config->num_disks].phystype = PHYSTYPE_FILE; + disk->phystype = PHYSTYPE_FILE; } else if (!strcmp(p, "tap")) { p = strtok(NULL, ":"); if (!strcmp(p, "aio")) { - d_config->disks[d_config->num_disks].phystype = PHYSTYPE_AIO; + disk->phystype = PHYSTYPE_AIO; } else if (!strcmp(p, "vhd")) { - d_config->disks[d_config->num_disks].phystype = PHYSTYPE_VHD; + disk->phystype = PHYSTYPE_VHD; } else if (!strcmp(p, "qcow")) { - d_config->disks[d_config->num_disks].phystype = PHYSTYPE_QCOW; + disk->phystype = PHYSTYPE_QCOW; } else if (!strcmp(p, "qcow2")) { - d_config->disks[d_config->num_disks].phystype = PHYSTYPE_QCOW2; + disk->phystype = PHYSTYPE_QCOW2; } } p = strtok(NULL, ","); while (*p == '' '') p++; - d_config->disks[d_config->num_disks].physpath= strdup(p); + disk->physpath= strdup(p); p = strtok(NULL, ","); while (*p == '' '') p++; p2 = strchr(p, '':''); if (p2 == NULL) { - d_config->disks[d_config->num_disks].virtpath = strdup(p); - d_config->disks[d_config->num_disks].is_cdrom = 0; - d_config->disks[d_config->num_disks].unpluggable = 1; + disk->virtpath = strdup(p); + disk->is_cdrom = 0; + disk->unpluggable = 1; } else { *p2 = ''\0''; - d_config->disks[d_config->num_disks].virtpath = strdup(p); + disk->virtpath = strdup(p); if (!strcmp(p2 + 1, "cdrom")) { - d_config->disks[d_config->num_disks].is_cdrom = 1; - d_config->disks[d_config->num_disks].unpluggable = 1; + disk->is_cdrom = 1; + disk->unpluggable = 1; } else - d_config->disks[d_config->num_disks].is_cdrom = 0; + disk->is_cdrom = 0; } p = strtok(NULL, ","); while (*p == '' '') p++; - d_config->disks[d_config->num_disks].readwrite = (p[0] == ''w'') ? 1 : 0; - free(buf2); - d_config->num_disks = d_config->num_disks + 1; + disk->readwrite = (p[0] == ''w'') ? 1 : 0; + free(buf2); + d_config->num_disks++; } } @@ -767,10 +772,14 @@ static void parse_config_data(const char d_config->num_vifs = 0; d_config->vifs = NULL; while ((buf = xlu_cfg_get_listitem (nics, d_config->num_vifs)) != NULL) { + libxl_device_nic *nic; char *buf2 = strdup(buf); char *p, *p2; + d_config->vifs = (libxl_device_nic *) realloc(d_config->vifs, sizeof (libxl_device_nic) * (d_config->num_vifs+1)); - init_nic_info(d_config->vifs + d_config->num_vifs, d_config->num_vifs); + nic = d_config->vifs + d_config->num_vifs; + init_nic_info(nic, d_config->num_vifs); + p = strtok(buf2, ","); if (!p) goto skip; @@ -781,39 +790,39 @@ static void parse_config_data(const char break; *p2 = ''\0''; if (!strcmp(p, "model")) { - d_config->vifs[d_config->num_vifs].model = strdup(p2 + 1); + nic->model = strdup(p2 + 1); } else if (!strcmp(p, "mac")) { char *p3 = p2 + 1; *(p3 + 2) = ''\0''; - d_config->vifs[d_config->num_vifs].mac[0] = strtol(p3, NULL, 16); - p3 = p3 + 3; - *(p3 + 2) = ''\0''; - d_config->vifs[d_config->num_vifs].mac[1] = strtol(p3, NULL, 16); - p3 = p3 + 3; - *(p3 + 2) = ''\0''; - d_config->vifs[d_config->num_vifs].mac[2] = strtol(p3, NULL, 16); - p3 = p3 + 3; - *(p3 + 2) = ''\0''; - d_config->vifs[d_config->num_vifs].mac[3] = strtol(p3, NULL, 16); - p3 = p3 + 3; - *(p3 + 2) = ''\0''; - d_config->vifs[d_config->num_vifs].mac[4] = strtol(p3, NULL, 16); - p3 = p3 + 3; - *(p3 + 2) = ''\0''; - d_config->vifs[d_config->num_vifs].mac[5] = strtol(p3, NULL, 16); + nic->mac[0] = strtol(p3, NULL, 16); + p3 = p3 + 3; + *(p3 + 2) = ''\0''; + nic->mac[1] = strtol(p3, NULL, 16); + p3 = p3 + 3; + *(p3 + 2) = ''\0''; + nic->mac[2] = strtol(p3, NULL, 16); + p3 = p3 + 3; + *(p3 + 2) = ''\0''; + nic->mac[3] = strtol(p3, NULL, 16); + p3 = p3 + 3; + *(p3 + 2) = ''\0''; + nic->mac[4] = strtol(p3, NULL, 16); + p3 = p3 + 3; + *(p3 + 2) = ''\0''; + nic->mac[5] = strtol(p3, NULL, 16); } else if (!strcmp(p, "bridge")) { - d_config->vifs[d_config->num_vifs].bridge = strdup(p2 + 1); + nic->bridge = strdup(p2 + 1); } else if (!strcmp(p, "type")) { if (!strcmp(p2 + 1, "ioemu")) - d_config->vifs[d_config->num_vifs].nictype = NICTYPE_IOEMU; + nic->nictype = NICTYPE_IOEMU; else - d_config->vifs[d_config->num_vifs].nictype = NICTYPE_VIF; + nic->nictype = NICTYPE_VIF; } else if (!strcmp(p, "ip")) { - inet_pton(AF_INET, p2 + 1, &d_config->vifs[d_config->num_vifs].ip); + inet_pton(AF_INET, p2 + 1, &nic->ip); } else if (!strcmp(p, "script")) { - d_config->vifs[d_config->num_vifs].script = strdup(p2 + 1); + nic->script = strdup(p2 + 1); } else if (!strcmp(p, "vifname")) { - d_config->vifs[d_config->num_vifs].ifname = strdup(p2 + 1); + nic->ifname = strdup(p2 + 1); } else if (!strcmp(p, "rate")) { fprintf(stderr, "the rate parameter for vifs is currently not supported\n"); } else if (!strcmp(p, "accel")) { @@ -822,7 +831,7 @@ static void parse_config_data(const char } while ((p = strtok(NULL, ",")) != NULL); skip: free(buf2); - d_config->num_vifs = d_config->num_vifs + 1; + d_config->num_vifs++; } } @@ -830,39 +839,42 @@ skip: d_config->num_vif2s = 0; d_config->vif2s = NULL; while ((buf = xlu_cfg_get_listitem(net2s, d_config->num_vif2s))) { + libxl_device_net2 *net2; char *buf2 = strdup(buf); char *p; d_config->vif2s = realloc(d_config->vif2s, sizeof (libxl_device_net2) * (d_config->num_vif2s + 1)); - init_net2_info(d_config->vif2s + d_config->num_vif2s, d_config->num_vif2s); + net2 = d_config->vif2s + d_config->num_vif2s; + + init_net2_info(net2, d_config->num_vif2s); for (p = strtok(buf2, ","); p; p = strtok(buf2, ",")) { while (isblank(*p)) p++; if (!strncmp("front_mac=", p, 10)) { - libxl_strtomac(p + 10, d_config->vif2s[d_config->num_vif2s].front_mac); + libxl_strtomac(p + 10, net2->front_mac); } else if (!strncmp("back_mac=", p, 9)) { - libxl_strtomac(p + 9, d_config->vif2s[d_config->num_vif2s].back_mac); + libxl_strtomac(p + 9, net2->back_mac); } else if (!strncmp("backend=", p, 8)) { - domain_qualifier_to_domid(p + 8, &d_config->vif2s[d_config->num_vif2s].backend_domid, 0); + domain_qualifier_to_domid(p + 8, &net2->backend_domid, 0); } else if (!strncmp("trusted=", p, 8)) { - d_config->vif2s[d_config->num_vif2s].trusted = (*(p + 8) == ''1''); + net2->trusted = (*(p + 8) == ''1''); } else if (!strncmp("back_trusted=", p, 13)) { - d_config->vif2s[d_config->num_vif2s].back_trusted = (*(p + 13) == ''1''); + net2->back_trusted = (*(p + 13) == ''1''); } else if (!strncmp("bridge=", p, 7)) { - d_config->vif2s[d_config->num_vif2s].bridge = strdup(p + 13); + net2->bridge = strdup(p + 13); } else if (!strncmp("filter_mac=", p, 11)) { - d_config->vif2s[d_config->num_vif2s].filter_mac = (*(p + 11) == ''1''); + net2->filter_mac = (*(p + 11) == ''1''); } else if (!strncmp("front_filter_mac=", p, 17)) { - d_config->vif2s[d_config->num_vif2s].front_filter_mac = (*(p + 17) == ''1''); + net2->front_filter_mac = (*(p + 17) == ''1''); } else if (!strncmp("pdev=", p, 5)) { - d_config->vif2s[d_config->num_vif2s].pdev = strtoul(p + 5, NULL, 10); + net2->pdev = strtoul(p + 5, NULL, 10); } else if (!strncmp("max_bypasses=", p, 13)) { - d_config->vif2s[d_config->num_vif2s].max_bypasses = strtoul(p + 13, NULL, 10); - } - } - free(buf2); - ++d_config->num_vif2s; + net2->max_bypasses = strtoul(p + 13, NULL, 10); + } + } + free(buf2); + d_config->num_vif2s++; } } @@ -872,13 +884,19 @@ skip: d_config->vfbs = NULL; d_config->vkbs = NULL; while ((buf = xlu_cfg_get_listitem (cvfbs, d_config->num_vfbs)) != NULL) { + libxl_device_vfb *vfb; + libxl_device_vkb *vkb; + char *buf2 = strdup(buf); char *p, *p2; + d_config->vfbs = (libxl_device_vfb *) realloc(d_config->vfbs, sizeof(libxl_device_vfb) * (d_config->num_vfbs + 1)); - init_vfb_info(d_config->vfbs + d_config->num_vfbs, d_config->num_vfbs); + vfb = d_config->vfbs + d_config->num_vfbs; + init_vfb_info(vfb, d_config->num_vfbs); d_config->vkbs = (libxl_device_vkb *) realloc(d_config->vkbs, sizeof(libxl_device_vkb) * (d_config->num_vkbs + 1)); - init_vkb_info(d_config->vkbs + d_config->num_vkbs, d_config->num_vkbs); + vkb = d_config->vkbs + d_config->num_vkbs; + init_vkb_info(vkb, d_config->num_vkbs); p = strtok(buf2, ","); if (!p) @@ -890,31 +908,31 @@ skip: break; *p2 = ''\0''; if (!strcmp(p, "vnc")) { - d_config->vfbs[d_config->num_vfbs].vnc = atoi(p2 + 1); + vfb->vnc = atoi(p2 + 1); } else if (!strcmp(p, "vnclisten")) { - d_config->vfbs[d_config->num_vfbs].vnclisten = strdup(p2 + 1); + vfb->vnclisten = strdup(p2 + 1); } else if (!strcmp(p, "vncpasswd")) { - d_config->vfbs[d_config->num_vfbs].vncpasswd = strdup(p2 + 1); + vfb->vncpasswd = strdup(p2 + 1); } else if (!strcmp(p, "vncdisplay")) { - d_config->vfbs[d_config->num_vfbs].vncdisplay = atoi(p2 + 1); + vfb->vncdisplay = atoi(p2 + 1); } else if (!strcmp(p, "vncunused")) { - d_config->vfbs[d_config->num_vfbs].vncunused = atoi(p2 + 1); + vfb->vncunused = atoi(p2 + 1); } else if (!strcmp(p, "keymap")) { - d_config->vfbs[d_config->num_vfbs].keymap = strdup(p2 + 1); + vfb->keymap = strdup(p2 + 1); } else if (!strcmp(p, "sdl")) { - d_config->vfbs[d_config->num_vfbs].sdl = atoi(p2 + 1); + vfb->sdl = atoi(p2 + 1); } else if (!strcmp(p, "opengl")) { - d_config->vfbs[d_config->num_vfbs].opengl = atoi(p2 + 1); + vfb->opengl = atoi(p2 + 1); } else if (!strcmp(p, "display")) { - d_config->vfbs[d_config->num_vfbs].display = strdup(p2 + 1); + vfb->display = strdup(p2 + 1); } else if (!strcmp(p, "xauthority")) { - d_config->vfbs[d_config->num_vfbs].xauthority = strdup(p2 + 1); + vfb->xauthority = strdup(p2 + 1); } } while ((p = strtok(NULL, ",")) != NULL); skip_vfb: free(buf2); - d_config->num_vfbs = d_config->num_vfbs + 1; - d_config->num_vkbs = d_config->num_vkbs + 1; + d_config->num_vfbs++; + d_config->num_vkbs++; } } @@ -928,11 +946,15 @@ skip_vfb: d_config->num_pcidevs = 0; d_config->pcidevs = NULL; while ((buf = xlu_cfg_get_listitem (pcis, d_config->num_pcidevs)) != NULL) { + libxl_device_pci *pcidev; unsigned int domain = 0, bus = 0, dev = 0, func = 0, vdevfn = 0; char *buf2 = strdup(buf); char *p; + d_config->pcidevs = (libxl_device_pci *) realloc(d_config->pcidevs, sizeof (libxl_device_pci) * (d_config->num_pcidevs + 1)); - memset(d_config->pcidevs + d_config->num_pcidevs, 0x00, sizeof(libxl_device_pci)); + pcidev = d_config->pcidevs + d_config->num_pcidevs; + memset(pcidev, 0x00, sizeof(libxl_device_pci)); + p = strtok(buf2, ","); if (!p) goto skip_pci; @@ -943,21 +965,22 @@ skip_vfb: goto skip_pci; } } - libxl_device_pci_init(d_config->pcidevs + d_config->num_pcidevs, domain, bus, dev, func, vdevfn); - d_config->pcidevs[d_config->num_pcidevs].msitranslate = pci_msitranslate; - d_config->pcidevs[d_config->num_pcidevs].power_mgmt = pci_power_mgmt; + + libxl_device_pci_init(pcidev, domain, bus, dev, func, vdevfn); + pcidev->msitranslate = pci_msitranslate; + pcidev->power_mgmt = pci_power_mgmt; while ((p = strtok(NULL, ",=")) != NULL) { while (*p == '' '') p++; if (!strcmp(p, "msitranslate")) { p = strtok(NULL, ",="); - d_config->pcidevs[d_config->num_pcidevs].msitranslate = atoi(p); + pcidev->msitranslate = atoi(p); } else if (!strcmp(p, "power_mgmt")) { p = strtok(NULL, ",="); - d_config->pcidevs[d_config->num_pcidevs].power_mgmt = atoi(p); - } - } - d_config->num_pcidevs = d_config->num_pcidevs + 1; + pcidev->power_mgmt = atoi(p); + } + } + d_config->num_pcidevs++; skip_pci: free(buf2); } _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Stefano Stabellini
2010-Jul-26 14:40 UTC
Re: [Xen-devel] [PATCH 0 of 3] xl: carry domain config around in struct domain_config
On Mon, 26 Jul 2010, Ian Campbell wrote:> Move more domain configuration items into struct domain_config. > > Reduces the number of functions which take large numbers of parameters > and generally just keeps configuration stuff in one place.Ack the whole series. Kudos to emacs search and replace :) _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ian Campbell
2010-Jul-26 14:44 UTC
Re: [Xen-devel] [PATCH 0 of 3] xl: carry domain config around in struct domain_config
On Mon, 2010-07-26 at 15:40 +0100, Stefano Stabellini wrote:> On Mon, 26 Jul 2010, Ian Campbell wrote: > > Move more domain configuration items into struct domain_config. > > > > Reduces the number of functions which take large numbers of parameters > > and generally just keeps configuration stuff in one place. > > Ack the whole series. Kudos to emacs search and replace :)I for one welcome our Ctrl-Alt-Shift-5 pressing overlords. On a related note... I was wondering if perhaps it might make sense to try and refactor some of the xl functionality, e.g. create (and associated stuff like resume) into separate files, just to try and make it a little more tractable. Ian. _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Stefano Stabellini
2010-Jul-26 15:03 UTC
Re: [Xen-devel] [PATCH 0 of 3] xl: carry domain config around in struct domain_config
On Mon, 26 Jul 2010, Ian Campbell wrote:> On Mon, 2010-07-26 at 15:40 +0100, Stefano Stabellini wrote: > > On Mon, 26 Jul 2010, Ian Campbell wrote: > > > Move more domain configuration items into struct domain_config. > > > > > > Reduces the number of functions which take large numbers of parameters > > > and generally just keeps configuration stuff in one place. > > > > Ack the whole series. Kudos to emacs search and replace :) > > I for one welcome our Ctrl-Alt-Shift-5 pressing overlords. > > On a related note... I was wondering if perhaps it might make sense to > try and refactor some of the xl functionality, e.g. create (and > associated stuff like resume) into separate files, just to try and make > it a little more tractable.I would like an higher level libxl function to create a domain that includes some of the functionalities present in create_domain. The current lower level libxl calls would still be maintained for users that need a more flexible API. _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ian Campbell
2010-Jul-27 10:28 UTC
[Xen-devel] [PATCH 0 of 3] xl: carry domain config around in struct domain_config
Move more domain configuration items into struct domain_config. Reduces the number of functions which take large numbers of parameters and generally just keeps configuration stuff in one place. (depends on preceeding series "Add support for on_poweroff, on_reboot and on_crash configuration" due to code level dependency, resendiong due to reworking of that series) _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ian Campbell
2010-Jul-27 10:28 UTC
[Xen-devel] [PATCH 1 of 3] xl: move create and build info to struct domain_config
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # Date 1280225499 -3600 # Node ID 0d225bbe6ffa904d081ca34cd736cb121d7c67b2 # Parent 519187e3e2b1bbeb244d64d79153e350ca3ba0bf xl: move create and build info to struct domain_config All three are passed around together and this begins to reduce some of the exceptionally long parameter lists. Signed-off-by: Ian Campbell <ian.campbell@citrix.com> diff -r 519187e3e2b1 -r 0d225bbe6ffa tools/libxl/xl_cmdimpl.c --- a/tools/libxl/xl_cmdimpl.c Tue Jul 27 11:11:38 2010 +0100 +++ b/tools/libxl/xl_cmdimpl.c Tue Jul 27 11:11:39 2010 +0100 @@ -125,6 +125,9 @@ static char *action_on_shutdown_names[] }; struct domain_config { + libxl_domain_create_info c_info; + libxl_domain_build_info b_info; + enum action_on_shutdown on_poweroff; enum action_on_shutdown on_reboot; enum action_on_shutdown on_watchdog; @@ -354,8 +357,7 @@ static void init_console_info(libxl_devi } static void printf_info(int domid, - libxl_domain_create_info *c_info, - libxl_domain_build_info *b_info, + struct domain_config *d_config, libxl_device_disk *disks, int num_disks, libxl_device_nic *vifs, @@ -369,6 +371,10 @@ static void printf_info(int domid, libxl_device_model_info *dm_info) { int i; + + libxl_domain_create_info *c_info = &d_config->c_info; + libxl_domain_build_info *b_info = &d_config->b_info; + printf("(domain\n\t(domid %d)\n", domid); printf("\t(domain_create_info)\n"); printf("\t(hvm %d)\n", c_info->hvm); @@ -523,8 +529,6 @@ static void parse_config_data(const char static void parse_config_data(const char *configfile_filename_report, const char *configfile_data, int configfile_len, - libxl_domain_create_info *c_info, - libxl_domain_build_info *b_info, struct domain_config *d_config, libxl_device_disk **disks, int *num_disks, @@ -547,6 +551,9 @@ static void parse_config_data(const char int pci_power_mgmt = 0; int pci_msitranslate = 1; int e; + + libxl_domain_create_info *c_info = &d_config->c_info; + libxl_domain_build_info *b_info = &d_config->b_info; config= xlu_cfg_init(stderr, configfile_filename_report); if (!config) { @@ -1068,7 +1075,6 @@ int autoconnect_console(int hvm) /* Returns 1 if domain should be restarted, 2 if domain should be renamed then restarted */ static int handle_domain_death(struct libxl_ctx *ctx, uint32_t domid, libxl_event *event, - libxl_domain_create_info *c_info, struct domain_config *d_config, struct libxl_dominfo *info) { int restart = 0; @@ -1097,7 +1103,7 @@ static int handle_domain_death(struct li char *corefile; int rc; - if (asprintf(&corefile, "/var/xen/dump/%s", c_info->name) < 0) { + if (asprintf(&corefile, "/var/xen/dump/%s", d_config->c_info.name) < 0) { LOG("failed to construct core dump path"); } else { LOG("dumping core to %s", corefile); @@ -1138,7 +1144,6 @@ static int handle_domain_death(struct li } static int preserve_domain(struct libxl_ctx *ctx, uint32_t domid, libxl_event *event, - libxl_domain_create_info *c_info, struct domain_config *d_config, struct libxl_dominfo *info) { time_t now; @@ -1168,8 +1173,8 @@ static int preserve_domain(struct libxl_ random_uuid(&new_uuid[0]); - LOG("Preserving domain %d %s with suffix%s", domid, c_info->name, stime); - rc = libxl_domain_preserve(ctx, domid, c_info, stime, new_uuid); + LOG("Preserving domain %d %s with suffix%s", domid, d_config->c_info.name, stime); + rc = libxl_domain_preserve(ctx, domid, &d_config->c_info, stime, new_uuid); return rc == 0 ? 1 : 0; } @@ -1192,8 +1197,6 @@ static int create_domain(struct domain_c { struct domain_config d_config; - libxl_domain_create_info c_info; - libxl_domain_build_info b_info; libxl_domain_build_state state; libxl_device_model_info dm_info; libxl_device_disk *disks = NULL; @@ -1224,6 +1227,7 @@ static int create_domain(struct domain_c int restore_fd = -1; struct save_file_header hdr; + memset(&d_config, 0x00, sizeof(d_config); memset(&dm_info, 0x00, sizeof(dm_info)); if (restore_file) { @@ -1326,32 +1330,32 @@ static int create_domain(struct domain_c if (!dom_info->quiet) printf("Parsing config file %s\n", config_file); - parse_config_data(config_file, config_data, config_len, &c_info, &b_info, &d_config, &disks, &num_disks, &vifs, &num_vifs, &vif2s, &num_vif2s, &pcidevs, &num_pcidevs, &vfbs, &num_vfbs, &vkbs, &num_vkbs, &dm_info); + parse_config_data(config_file, config_data, config_len, &d_config, &disks, &num_disks, &vifs, &num_vifs, &vif2s, &num_vif2s, &pcidevs, &num_pcidevs, &vfbs, &num_vfbs, &vkbs, &num_vkbs, &dm_info); if (dom_info->dryrun) return 0; if (migrate_fd >= 0) { - if (c_info.name) { + if (d_config.c_info.name) { /* when we receive a domain we get its name from the config * file; and we receive it to a temporary name */ assert(!common_domname); - common_domname = c_info.name; - if (asprintf(migration_domname_r, "%s--incoming", c_info.name) < 0) { + common_domname = d_config.c_info.name; + if (asprintf(migration_domname_r, "%s--incoming", d_config.c_info.name) < 0) { fprintf(stderr, "Failed to allocate memory in asprintf\n"); exit(1); } - c_info.name = *migration_domname_r; + d_config.c_info.name = *migration_domname_r; } } if (debug) - printf_info(-1, &c_info, &b_info, disks, num_disks, vifs, num_vifs, pcidevs, num_pcidevs, vfbs, num_vfbs, vkbs, num_vkbs, &dm_info); + printf_info(-1, &d_config, disks, num_disks, vifs, num_vifs, pcidevs, num_pcidevs, vfbs, num_vfbs, vkbs, num_vkbs, &dm_info); start: domid = 0; - ret = libxl_domain_make(&ctx, &c_info, &domid); + ret = libxl_domain_make(&ctx, &d_config.c_info, &domid); if (ret) { fprintf(stderr, "cannot make domain: %d\n", ret); ret = ERROR_FAIL; @@ -1367,7 +1371,7 @@ start: } if (dom_info->console_autoconnect) { - ret = autoconnect_console(c_info.hvm); + ret = autoconnect_console(d_config.c_info.hvm); if (ret) goto error_out; } @@ -1378,7 +1382,7 @@ start: */ dom_info->console_autoconnect = 0; - ret = libxl_run_bootloader(&ctx, &b_info, num_disks > 0 ? &disks[0] : NULL, domid); + ret = libxl_run_bootloader(&ctx, &d_config.b_info, num_disks > 0 ? &disks[0] : NULL, domid); if (ret) { fprintf(stderr, "failed to run bootloader: %d\n", ret); goto error_out; @@ -1389,9 +1393,9 @@ start: free(dm_info.saved_state); dm_info.saved_state = NULL; } - ret = libxl_domain_build(&ctx, &b_info, domid, &state); - } else { - ret = libxl_domain_restore(&ctx, &b_info, domid, restore_fd, &state, &dm_info); + ret = libxl_domain_build(&ctx, &d_config.b_info, domid, &state); + } else { + ret = libxl_domain_restore(&ctx, &d_config.b_info, domid, restore_fd, &state, &dm_info); } if (ret) { @@ -1418,7 +1422,7 @@ start: goto error_out; } } - if (!c_info.hvm) { + if (!d_config.c_info.hvm) { for (i = 0; i < num_vif2s; i++) { vif2s[i].domid = domid; ret = libxl_device_net2_add(&ctx, domid, &(vif2s[i])); @@ -1429,7 +1433,7 @@ start: } } } - if (c_info.hvm) { + if (d_config.c_info.hvm) { dm_info.domid = domid; MUST( libxl_create_device_model(&ctx, &dm_info, disks, num_disks, vifs, num_vifs, &dm_starting) ); @@ -1493,7 +1497,7 @@ start: exit(-1); } - if (asprintf(&name, "xl-%s", c_info.name) < 0) { + if (asprintf(&name, "xl-%s", d_config.c_info.name) < 0) { LOG("Failed to allocate memory in asprintf"); exit(1); } @@ -1516,7 +1520,7 @@ start: need_daemon = 0; } LOG("Waiting for domain %s (domid %d) to die [pid %ld]", - c_info.name, domid, (long)getpid()); + d_config.c_info.name, domid, (long)getpid()); w1 = (libxl_waiter*) xmalloc(sizeof(libxl_waiter) * num_disks); w2 = (libxl_waiter*) xmalloc(sizeof(libxl_waiter)); libxl_wait_for_disk_ejects(&ctx, domid, disks, num_disks, w1); @@ -1545,9 +1549,9 @@ start: LOG("Domain %d is dead", domid); if (ret) { - switch (handle_domain_death(&ctx, domid, &event, &c_info, &d_config, &info)) { + switch (handle_domain_death(&ctx, domid, &event, &d_config, &info)) { case 2: - if (!preserve_domain(&ctx, domid, &event, &c_info, &d_config, &info)) + if (!preserve_domain(&ctx, domid, &event, &d_config, &info)) /* If we fail then exit leaving the old domain in place. */ exit(-1); @@ -2083,8 +2087,6 @@ void list_domains_details(void) uint8_t *data; int nb_domain, i, len, rc; int num_disks = 0, num_vifs = 0, num_vif2s = 0, num_pcidevs = 0, num_vfbs = 0, num_vkbs = 0; - libxl_domain_create_info c_info; - libxl_domain_build_info b_info; libxl_device_model_info dm_info; libxl_device_disk *disks = NULL; libxl_device_nic *vifs = NULL; @@ -2104,8 +2106,9 @@ void list_domains_details(void) if (rc) continue; CHK_ERRNO(asprintf(&config_file, "<domid %d data>", info[i].domid)); - parse_config_data(config_file, (char *)data, len, &c_info, &b_info, &d_config, &disks, &num_disks, &vifs, &num_vifs, &vif2s, &num_vif2s, &pcidevs, &num_pcidevs, &vfbs, &num_vfbs, &vkbs, &num_vkbs, &dm_info); - printf_info(info[i].domid, &c_info, &b_info, disks, num_disks, vifs, num_vifs, pcidevs, num_pcidevs, vfbs, num_vfbs, vkbs, num_vkbs, &dm_info); + memset(&d_config, 0x00, sizeof(d_config); + parse_config_data(config_file, (char *)data, len, &d_config, &disks, &num_disks, &vifs, &num_vifs, &vif2s, &num_vif2s, &pcidevs, &num_pcidevs, &vfbs, &num_vfbs, &vkbs, &num_vkbs, &dm_info); + printf_info(info[i].domid, &d_config, disks, num_disks, vifs, num_vifs, pcidevs, num_pcidevs, vfbs, num_vfbs, vkbs, num_vkbs, &dm_info); free(data); free(config_file); } _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ian Campbell
2010-Jul-27 10:28 UTC
[Xen-devel] [PATCH 2 of 3] xl: move device structs into struct domain_config
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # Date 1280225499 -3600 # Node ID d06f5e9633d3390cf5ea451fe39e48ca0b7bdbd4 # Parent 0d225bbe6ffa904d081ca34cd736cb121d7c67b2 xl: move device structs into struct domain_config Signed-off-by: Ian Campbell <ian.campbell@citrix.com> diff -r 0d225bbe6ffa -r d06f5e9633d3 tools/libxl/xl_cmdimpl.c --- a/tools/libxl/xl_cmdimpl.c Tue Jul 27 11:11:39 2010 +0100 +++ b/tools/libxl/xl_cmdimpl.c Tue Jul 27 11:11:39 2010 +0100 @@ -128,6 +128,15 @@ struct domain_config { libxl_domain_create_info c_info; libxl_domain_build_info b_info; + int num_disks, num_vifs, num_vif2s, num_pcidevs, num_vfbs, num_vkbs; + + libxl_device_disk *disks; + libxl_device_nic *vifs; + libxl_device_net2 *vif2s; + libxl_device_pci *pcidevs; + libxl_device_vfb *vfbs; + libxl_device_vkb *vkbs; + enum action_on_shutdown on_poweroff; enum action_on_shutdown on_reboot; enum action_on_shutdown on_watchdog; @@ -358,16 +367,6 @@ static void init_console_info(libxl_devi static void printf_info(int domid, struct domain_config *d_config, - libxl_device_disk *disks, - int num_disks, - libxl_device_nic *vifs, - int num_vifs, - libxl_device_pci *pcidevs, - int num_pcidevs, - libxl_device_vfb *vfbs, - int num_vfbs, - libxl_device_vkb *vkb, - int num_vkbs, libxl_device_model_info *dm_info) { int i; @@ -452,58 +451,66 @@ static void printf_info(int domid, } printf("\t)\n"); - for (i = 0; i < num_disks; i++) { + for (i = 0; i < d_config->num_disks; i++) { printf("\t(device\n"); printf("\t\t(tap\n"); - printf("\t\t\t(backend_domid %d)\n", disks[i].backend_domid); - printf("\t\t\t(domid %d)\n", disks[i].domid); - printf("\t\t\t(physpath %s)\n", disks[i].physpath); - printf("\t\t\t(phystype %d)\n", disks[i].phystype); - printf("\t\t\t(virtpath %s)\n", disks[i].virtpath); - printf("\t\t\t(unpluggable %d)\n", disks[i].unpluggable); - printf("\t\t\t(readwrite %d)\n", disks[i].readwrite); - printf("\t\t\t(is_cdrom %d)\n", disks[i].is_cdrom); + printf("\t\t\t(backend_domid %d)\n", d_config->disks[i].backend_domid); + printf("\t\t\t(domid %d)\n", d_config->disks[i].domid); + printf("\t\t\t(physpath %s)\n", d_config->disks[i].physpath); + printf("\t\t\t(phystype %d)\n", d_config->disks[i].phystype); + printf("\t\t\t(virtpath %s)\n", d_config->disks[i].virtpath); + printf("\t\t\t(unpluggable %d)\n", d_config->disks[i].unpluggable); + printf("\t\t\t(readwrite %d)\n", d_config->disks[i].readwrite); + printf("\t\t\t(is_cdrom %d)\n", d_config->disks[i].is_cdrom); printf("\t\t)\n"); printf("\t)\n"); } - for (i = 0; i < num_vifs; i++) { + for (i = 0; i < d_config->num_vifs; i++) { printf("\t(device\n"); printf("\t\t(vif\n"); - printf("\t\t\t(backend_domid %d)\n", vifs[i].backend_domid); - printf("\t\t\t(domid %d)\n", vifs[i].domid); - printf("\t\t\t(devid %d)\n", vifs[i].devid); - printf("\t\t\t(mtu %d)\n", vifs[i].mtu); - printf("\t\t\t(model %s)\n", vifs[i].model); - printf("\t\t\t(mac %02x%02x%02x%02x%02x%02x)\n", vifs[i].mac[0], vifs[i].mac[1], vifs[i].mac[2], vifs[i].mac[3], vifs[i].mac[4], vifs[i].mac[5]); + printf("\t\t\t(backend_domid %d)\n", d_config->vifs[i].backend_domid); + printf("\t\t\t(domid %d)\n", d_config->vifs[i].domid); + printf("\t\t\t(devid %d)\n", d_config->vifs[i].devid); + printf("\t\t\t(mtu %d)\n", d_config->vifs[i].mtu); + printf("\t\t\t(model %s)\n", d_config->vifs[i].model); + printf("\t\t\t(mac %02x%02x%02x%02x%02x%02x)\n", + d_config->vifs[i].mac[0], d_config->vifs[i].mac[1], + d_config->vifs[i].mac[2], d_config->vifs[i].mac[3], + d_config->vifs[i].mac[4], d_config->vifs[i].mac[5]); printf("\t\t)\n"); printf("\t)\n"); } - for (i = 0; i < num_pcidevs; i++) { + for (i = 0; i < d_config->num_pcidevs; i++) { printf("\t(device\n"); printf("\t\t(pci\n"); - printf("\t\t\t(pci dev "PCI_BDF_VDEVFN")\n", pcidevs[i].domain, pcidevs[i].bus, pcidevs[i].dev, pcidevs[i].func, pcidevs[i].vdevfn); - printf("\t\t\t(opts msitranslate %d power_mgmt %d)\n", pcidevs[i].msitranslate, pcidevs[i].power_mgmt); + printf("\t\t\t(pci dev "PCI_BDF_VDEVFN")\n", + d_config->pcidevs[i].domain, d_config->pcidevs[i].bus, + d_config->pcidevs[i].dev, d_config->pcidevs[i].func, + d_config->pcidevs[i].vdevfn); + printf("\t\t\t(opts msitranslate %d power_mgmt %d)\n", + d_config->pcidevs[i].msitranslate, + d_config->pcidevs[i].power_mgmt); printf("\t\t)\n"); printf("\t)\n"); } - for (i = 0; i < num_vfbs; i++) { + for (i = 0; i < d_config->num_vfbs; i++) { printf("\t(device\n"); printf("\t\t(vfb\n"); - printf("\t\t\t(backend_domid %d)\n", vfbs[i].backend_domid); - printf("\t\t\t(domid %d)\n", vfbs[i].domid); - printf("\t\t\t(devid %d)\n", vfbs[i].devid); - printf("\t\t\t(vnc %d)\n", vfbs[i].vnc); - printf("\t\t\t(vnclisten %s)\n", vfbs[i].vnclisten); - printf("\t\t\t(vncdisplay %d)\n", vfbs[i].vncdisplay); - printf("\t\t\t(vncunused %d)\n", vfbs[i].vncunused); - printf("\t\t\t(keymap %s)\n", vfbs[i].keymap); - printf("\t\t\t(sdl %d)\n", vfbs[i].sdl); - printf("\t\t\t(opengl %d)\n", vfbs[i].opengl); - printf("\t\t\t(display %s)\n", vfbs[i].display); - printf("\t\t\t(xauthority %s)\n", vfbs[i].xauthority); + printf("\t\t\t(backend_domid %d)\n", d_config->vfbs[i].backend_domid); + printf("\t\t\t(domid %d)\n", d_config->vfbs[i].domid); + printf("\t\t\t(devid %d)\n", d_config->vfbs[i].devid); + printf("\t\t\t(vnc %d)\n", d_config->vfbs[i].vnc); + printf("\t\t\t(vnclisten %s)\n", d_config->vfbs[i].vnclisten); + printf("\t\t\t(vncdisplay %d)\n", d_config->vfbs[i].vncdisplay); + printf("\t\t\t(vncunused %d)\n", d_config->vfbs[i].vncunused); + printf("\t\t\t(keymap %s)\n", d_config->vfbs[i].keymap); + printf("\t\t\t(sdl %d)\n", d_config->vfbs[i].sdl); + printf("\t\t\t(opengl %d)\n", d_config->vfbs[i].opengl); + printf("\t\t\t(display %s)\n", d_config->vfbs[i].display); + printf("\t\t\t(xauthority %s)\n", d_config->vfbs[i].xauthority); printf("\t\t)\n"); printf("\t)\n"); } @@ -530,18 +537,6 @@ static void parse_config_data(const char const char *configfile_data, int configfile_len, struct domain_config *d_config, - libxl_device_disk **disks, - int *num_disks, - libxl_device_nic **vifs, - int *num_vifs, - libxl_device_net2 **vif2s, - int *num_vif2s, - libxl_device_pci **pcidevs, - int *num_pcidevs, - libxl_device_vfb **vfbs, - int *num_vfbs, - libxl_device_vkb **vkbs, - int *num_vkbs, libxl_device_model_info *dm_info) { const char *buf; @@ -710,72 +705,72 @@ static void parse_config_data(const char } if (!xlu_cfg_get_list (config, "disk", &vbds, 0)) { - *num_disks = 0; - *disks = NULL; - while ((buf = xlu_cfg_get_listitem (vbds, *num_disks)) != NULL) { + d_config->num_disks = 0; + d_config->disks = NULL; + while ((buf = xlu_cfg_get_listitem (vbds, d_config->num_disks)) != NULL) { char *buf2 = strdup(buf); char *p, *p2; - *disks = (libxl_device_disk *) realloc(*disks, sizeof (libxl_device_disk) * ((*num_disks) + 1)); - (*disks)[*num_disks].backend_domid = 0; - (*disks)[*num_disks].domid = 0; - (*disks)[*num_disks].unpluggable = 0; + d_config->disks = (libxl_device_disk *) realloc(d_config->disks, sizeof (libxl_device_disk) * (d_config->num_disks + 1)); + d_config->disks[d_config->num_disks].backend_domid = 0; + d_config->disks[d_config->num_disks].domid = 0; + d_config->disks[d_config->num_disks].unpluggable = 0; p = strtok(buf2, ",:"); while (*p == '' '') p++; if (!strcmp(p, "phy")) { - (*disks)[*num_disks].phystype = PHYSTYPE_PHY; + d_config->disks[d_config->num_disks].phystype = PHYSTYPE_PHY; } else if (!strcmp(p, "file")) { - (*disks)[*num_disks].phystype = PHYSTYPE_FILE; + d_config->disks[d_config->num_disks].phystype = PHYSTYPE_FILE; } else if (!strcmp(p, "tap")) { p = strtok(NULL, ":"); if (!strcmp(p, "aio")) { - (*disks)[*num_disks].phystype = PHYSTYPE_AIO; + d_config->disks[d_config->num_disks].phystype = PHYSTYPE_AIO; } else if (!strcmp(p, "vhd")) { - (*disks)[*num_disks].phystype = PHYSTYPE_VHD; + d_config->disks[d_config->num_disks].phystype = PHYSTYPE_VHD; } else if (!strcmp(p, "qcow")) { - (*disks)[*num_disks].phystype = PHYSTYPE_QCOW; + d_config->disks[d_config->num_disks].phystype = PHYSTYPE_QCOW; } else if (!strcmp(p, "qcow2")) { - (*disks)[*num_disks].phystype = PHYSTYPE_QCOW2; + d_config->disks[d_config->num_disks].phystype = PHYSTYPE_QCOW2; } } p = strtok(NULL, ","); while (*p == '' '') p++; - (*disks)[*num_disks].physpath= strdup(p); + d_config->disks[d_config->num_disks].physpath= strdup(p); p = strtok(NULL, ","); while (*p == '' '') p++; p2 = strchr(p, '':''); if (p2 == NULL) { - (*disks)[*num_disks].virtpath = strdup(p); - (*disks)[*num_disks].is_cdrom = 0; - (*disks)[*num_disks].unpluggable = 1; + d_config->disks[d_config->num_disks].virtpath = strdup(p); + d_config->disks[d_config->num_disks].is_cdrom = 0; + d_config->disks[d_config->num_disks].unpluggable = 1; } else { *p2 = ''\0''; - (*disks)[*num_disks].virtpath = strdup(p); + d_config->disks[d_config->num_disks].virtpath = strdup(p); if (!strcmp(p2 + 1, "cdrom")) { - (*disks)[*num_disks].is_cdrom = 1; - (*disks)[*num_disks].unpluggable = 1; + d_config->disks[d_config->num_disks].is_cdrom = 1; + d_config->disks[d_config->num_disks].unpluggable = 1; } else - (*disks)[*num_disks].is_cdrom = 0; + d_config->disks[d_config->num_disks].is_cdrom = 0; } p = strtok(NULL, ","); while (*p == '' '') p++; - (*disks)[*num_disks].readwrite = (p[0] == ''w'') ? 1 : 0; - free(buf2); - *num_disks = (*num_disks) + 1; + d_config->disks[d_config->num_disks].readwrite = (p[0] == ''w'') ? 1 : 0; + free(buf2); + d_config->num_disks = d_config->num_disks + 1; } } if (!xlu_cfg_get_list (config, "vif", &nics, 0)) { - *num_vifs = 0; - *vifs = NULL; - while ((buf = xlu_cfg_get_listitem (nics, *num_vifs)) != NULL) { + d_config->num_vifs = 0; + d_config->vifs = NULL; + while ((buf = xlu_cfg_get_listitem (nics, d_config->num_vifs)) != NULL) { char *buf2 = strdup(buf); char *p, *p2; - *vifs = (libxl_device_nic *) realloc(*vifs, sizeof (libxl_device_nic) * ((*num_vifs) + 1)); - init_nic_info((*vifs) + (*num_vifs), (*num_vifs)); + d_config->vifs = (libxl_device_nic *) realloc(d_config->vifs, sizeof (libxl_device_nic) * (d_config->num_vifs+1)); + init_nic_info(d_config->vifs + d_config->num_vifs, d_config->num_vifs); p = strtok(buf2, ","); if (!p) goto skip; @@ -786,39 +781,39 @@ static void parse_config_data(const char break; *p2 = ''\0''; if (!strcmp(p, "model")) { - (*vifs)[*num_vifs].model = strdup(p2 + 1); + d_config->vifs[d_config->num_vifs].model = strdup(p2 + 1); } else if (!strcmp(p, "mac")) { char *p3 = p2 + 1; *(p3 + 2) = ''\0''; - (*vifs)[*num_vifs].mac[0] = strtol(p3, NULL, 16); - p3 = p3 + 3; - *(p3 + 2) = ''\0''; - (*vifs)[*num_vifs].mac[1] = strtol(p3, NULL, 16); - p3 = p3 + 3; - *(p3 + 2) = ''\0''; - (*vifs)[*num_vifs].mac[2] = strtol(p3, NULL, 16); - p3 = p3 + 3; - *(p3 + 2) = ''\0''; - (*vifs)[*num_vifs].mac[3] = strtol(p3, NULL, 16); - p3 = p3 + 3; - *(p3 + 2) = ''\0''; - (*vifs)[*num_vifs].mac[4] = strtol(p3, NULL, 16); - p3 = p3 + 3; - *(p3 + 2) = ''\0''; - (*vifs)[*num_vifs].mac[5] = strtol(p3, NULL, 16); + d_config->vifs[d_config->num_vifs].mac[0] = strtol(p3, NULL, 16); + p3 = p3 + 3; + *(p3 + 2) = ''\0''; + d_config->vifs[d_config->num_vifs].mac[1] = strtol(p3, NULL, 16); + p3 = p3 + 3; + *(p3 + 2) = ''\0''; + d_config->vifs[d_config->num_vifs].mac[2] = strtol(p3, NULL, 16); + p3 = p3 + 3; + *(p3 + 2) = ''\0''; + d_config->vifs[d_config->num_vifs].mac[3] = strtol(p3, NULL, 16); + p3 = p3 + 3; + *(p3 + 2) = ''\0''; + d_config->vifs[d_config->num_vifs].mac[4] = strtol(p3, NULL, 16); + p3 = p3 + 3; + *(p3 + 2) = ''\0''; + d_config->vifs[d_config->num_vifs].mac[5] = strtol(p3, NULL, 16); } else if (!strcmp(p, "bridge")) { - (*vifs)[*num_vifs].bridge = strdup(p2 + 1); + d_config->vifs[d_config->num_vifs].bridge = strdup(p2 + 1); } else if (!strcmp(p, "type")) { if (!strcmp(p2 + 1, "ioemu")) - (*vifs)[*num_vifs].nictype = NICTYPE_IOEMU; + d_config->vifs[d_config->num_vifs].nictype = NICTYPE_IOEMU; else - (*vifs)[*num_vifs].nictype = NICTYPE_VIF; + d_config->vifs[d_config->num_vifs].nictype = NICTYPE_VIF; } else if (!strcmp(p, "ip")) { - inet_pton(AF_INET, p2 + 1, &((*vifs)[*num_vifs].ip)); + inet_pton(AF_INET, p2 + 1, &d_config->vifs[d_config->num_vifs].ip); } else if (!strcmp(p, "script")) { - (*vifs)[*num_vifs].script = strdup(p2 + 1); + d_config->vifs[d_config->num_vifs].script = strdup(p2 + 1); } else if (!strcmp(p, "vifname")) { - (*vifs)[*num_vifs].ifname = strdup(p2 + 1); + d_config->vifs[d_config->num_vifs].ifname = strdup(p2 + 1); } else if (!strcmp(p, "rate")) { fprintf(stderr, "the rate parameter for vifs is currently not supported\n"); } else if (!strcmp(p, "accel")) { @@ -827,63 +822,63 @@ static void parse_config_data(const char } while ((p = strtok(NULL, ",")) != NULL); skip: free(buf2); - *num_vifs = (*num_vifs) + 1; + d_config->num_vifs = d_config->num_vifs + 1; } } if (!xlu_cfg_get_list(config, "vif2", &net2s, 0)) { - *num_vif2s = 0; - *vif2s = NULL; - while ((buf = xlu_cfg_get_listitem(net2s, *num_vif2s))) { + d_config->num_vif2s = 0; + d_config->vif2s = NULL; + while ((buf = xlu_cfg_get_listitem(net2s, d_config->num_vif2s))) { char *buf2 = strdup(buf); char *p; - *vif2s = realloc(*vif2s, sizeof (libxl_device_net2) * (*num_vif2s + 1)); - init_net2_info(*vif2s + *num_vif2s, *num_vif2s); + d_config->vif2s = realloc(d_config->vif2s, sizeof (libxl_device_net2) * (d_config->num_vif2s + 1)); + init_net2_info(d_config->vif2s + d_config->num_vif2s, d_config->num_vif2s); for (p = strtok(buf2, ","); p; p = strtok(buf2, ",")) { while (isblank(*p)) p++; if (!strncmp("front_mac=", p, 10)) { - libxl_strtomac(p + 10, (*vif2s)[*num_vif2s].front_mac); + libxl_strtomac(p + 10, d_config->vif2s[d_config->num_vif2s].front_mac); } else if (!strncmp("back_mac=", p, 9)) { - libxl_strtomac(p + 9, (*vif2s)[*num_vif2s].back_mac); + libxl_strtomac(p + 9, d_config->vif2s[d_config->num_vif2s].back_mac); } else if (!strncmp("backend=", p, 8)) { - domain_qualifier_to_domid(p + 8, &((*vif2s)[*num_vif2s].backend_domid), 0); + domain_qualifier_to_domid(p + 8, &d_config->vif2s[d_config->num_vif2s].backend_domid, 0); } else if (!strncmp("trusted=", p, 8)) { - (*vif2s)[*num_vif2s].trusted = (*(p + 8) == ''1''); + d_config->vif2s[d_config->num_vif2s].trusted = (*(p + 8) == ''1''); } else if (!strncmp("back_trusted=", p, 13)) { - (*vif2s)[*num_vif2s].back_trusted = (*(p + 13) == ''1''); + d_config->vif2s[d_config->num_vif2s].back_trusted = (*(p + 13) == ''1''); } else if (!strncmp("bridge=", p, 7)) { - (*vif2s)[*num_vif2s].bridge = strdup(p + 13); + d_config->vif2s[d_config->num_vif2s].bridge = strdup(p + 13); } else if (!strncmp("filter_mac=", p, 11)) { - (*vif2s)[*num_vif2s].filter_mac = (*(p + 11) == ''1''); + d_config->vif2s[d_config->num_vif2s].filter_mac = (*(p + 11) == ''1''); } else if (!strncmp("front_filter_mac=", p, 17)) { - (*vif2s)[*num_vif2s].front_filter_mac = (*(p + 17) == ''1''); + d_config->vif2s[d_config->num_vif2s].front_filter_mac = (*(p + 17) == ''1''); } else if (!strncmp("pdev=", p, 5)) { - (*vif2s)[*num_vif2s].pdev = strtoul(p + 5, NULL, 10); + d_config->vif2s[d_config->num_vif2s].pdev = strtoul(p + 5, NULL, 10); } else if (!strncmp("max_bypasses=", p, 13)) { - (*vif2s)[*num_vif2s].max_bypasses = strtoul(p + 13, NULL, 10); - } - } - free(buf2); - ++(*num_vif2s); + d_config->vif2s[d_config->num_vif2s].max_bypasses = strtoul(p + 13, NULL, 10); + } + } + free(buf2); + ++d_config->num_vif2s; } } if (!xlu_cfg_get_list (config, "vfb", &cvfbs, 0)) { - *num_vfbs = 0; - *num_vkbs = 0; - *vfbs = NULL; - *vkbs = NULL; - while ((buf = xlu_cfg_get_listitem (cvfbs, *num_vfbs)) != NULL) { + d_config->num_vfbs = 0; + d_config->num_vkbs = 0; + d_config->vfbs = NULL; + d_config->vkbs = NULL; + while ((buf = xlu_cfg_get_listitem (cvfbs, d_config->num_vfbs)) != NULL) { char *buf2 = strdup(buf); char *p, *p2; - *vfbs = (libxl_device_vfb *) realloc(*vfbs, sizeof(libxl_device_vfb) * ((*num_vfbs) + 1)); - init_vfb_info((*vfbs) + (*num_vfbs), (*num_vfbs)); - - *vkbs = (libxl_device_vkb *) realloc(*vkbs, sizeof(libxl_device_vkb) * ((*num_vkbs) + 1)); - init_vkb_info((*vkbs) + (*num_vkbs), (*num_vkbs)); + d_config->vfbs = (libxl_device_vfb *) realloc(d_config->vfbs, sizeof(libxl_device_vfb) * (d_config->num_vfbs + 1)); + init_vfb_info(d_config->vfbs + d_config->num_vfbs, d_config->num_vfbs); + + d_config->vkbs = (libxl_device_vkb *) realloc(d_config->vkbs, sizeof(libxl_device_vkb) * (d_config->num_vkbs + 1)); + init_vkb_info(d_config->vkbs + d_config->num_vkbs, d_config->num_vkbs); p = strtok(buf2, ","); if (!p) @@ -895,31 +890,31 @@ skip: break; *p2 = ''\0''; if (!strcmp(p, "vnc")) { - (*vfbs)[*num_vfbs].vnc = atoi(p2 + 1); + d_config->vfbs[d_config->num_vfbs].vnc = atoi(p2 + 1); } else if (!strcmp(p, "vnclisten")) { - (*vfbs)[*num_vfbs].vnclisten = strdup(p2 + 1); + d_config->vfbs[d_config->num_vfbs].vnclisten = strdup(p2 + 1); } else if (!strcmp(p, "vncpasswd")) { - (*vfbs)[*num_vfbs].vncpasswd = strdup(p2 + 1); + d_config->vfbs[d_config->num_vfbs].vncpasswd = strdup(p2 + 1); } else if (!strcmp(p, "vncdisplay")) { - (*vfbs)[*num_vfbs].vncdisplay = atoi(p2 + 1); + d_config->vfbs[d_config->num_vfbs].vncdisplay = atoi(p2 + 1); } else if (!strcmp(p, "vncunused")) { - (*vfbs)[*num_vfbs].vncunused = atoi(p2 + 1); + d_config->vfbs[d_config->num_vfbs].vncunused = atoi(p2 + 1); } else if (!strcmp(p, "keymap")) { - (*vfbs)[*num_vfbs].keymap = strdup(p2 + 1); + d_config->vfbs[d_config->num_vfbs].keymap = strdup(p2 + 1); } else if (!strcmp(p, "sdl")) { - (*vfbs)[*num_vfbs].sdl = atoi(p2 + 1); + d_config->vfbs[d_config->num_vfbs].sdl = atoi(p2 + 1); } else if (!strcmp(p, "opengl")) { - (*vfbs)[*num_vfbs].opengl = atoi(p2 + 1); + d_config->vfbs[d_config->num_vfbs].opengl = atoi(p2 + 1); } else if (!strcmp(p, "display")) { - (*vfbs)[*num_vfbs].display = strdup(p2 + 1); + d_config->vfbs[d_config->num_vfbs].display = strdup(p2 + 1); } else if (!strcmp(p, "xauthority")) { - (*vfbs)[*num_vfbs].xauthority = strdup(p2 + 1); + d_config->vfbs[d_config->num_vfbs].xauthority = strdup(p2 + 1); } } while ((p = strtok(NULL, ",")) != NULL); skip_vfb: free(buf2); - *num_vfbs = (*num_vfbs) + 1; - *num_vkbs = (*num_vkbs) + 1; + d_config->num_vfbs = d_config->num_vfbs + 1; + d_config->num_vkbs = d_config->num_vkbs + 1; } } @@ -930,14 +925,14 @@ skip_vfb: pci_power_mgmt = l; if (!xlu_cfg_get_list (config, "pci", &pcis, 0)) { - *num_pcidevs = 0; - *pcidevs = NULL; - while ((buf = xlu_cfg_get_listitem (pcis, *num_pcidevs)) != NULL) { + d_config->num_pcidevs = 0; + d_config->pcidevs = NULL; + while ((buf = xlu_cfg_get_listitem (pcis, d_config->num_pcidevs)) != NULL) { unsigned int domain = 0, bus = 0, dev = 0, func = 0, vdevfn = 0; char *buf2 = strdup(buf); char *p; - *pcidevs = (libxl_device_pci *) realloc(*pcidevs, sizeof (libxl_device_pci) * ((*num_pcidevs) + 1)); - memset(*pcidevs + *num_pcidevs, 0x00, sizeof(libxl_device_pci)); + d_config->pcidevs = (libxl_device_pci *) realloc(d_config->pcidevs, sizeof (libxl_device_pci) * (d_config->num_pcidevs + 1)); + memset(d_config->pcidevs + d_config->num_pcidevs, 0x00, sizeof(libxl_device_pci)); p = strtok(buf2, ","); if (!p) goto skip_pci; @@ -948,21 +943,21 @@ skip_vfb: goto skip_pci; } } - libxl_device_pci_init(*pcidevs + *num_pcidevs, domain, bus, dev, func, vdevfn); - (*pcidevs)[*num_pcidevs].msitranslate = pci_msitranslate; - (*pcidevs)[*num_pcidevs].power_mgmt = pci_power_mgmt; + libxl_device_pci_init(d_config->pcidevs + d_config->num_pcidevs, domain, bus, dev, func, vdevfn); + d_config->pcidevs[d_config->num_pcidevs].msitranslate = pci_msitranslate; + d_config->pcidevs[d_config->num_pcidevs].power_mgmt = pci_power_mgmt; while ((p = strtok(NULL, ",=")) != NULL) { while (*p == '' '') p++; if (!strcmp(p, "msitranslate")) { p = strtok(NULL, ",="); - (*pcidevs)[*num_pcidevs].msitranslate = atoi(p); + d_config->pcidevs[d_config->num_pcidevs].msitranslate = atoi(p); } else if (!strcmp(p, "power_mgmt")) { p = strtok(NULL, ",="); - (*pcidevs)[*num_pcidevs].power_mgmt = atoi(p); - } - } - *num_pcidevs = (*num_pcidevs) + 1; + d_config->pcidevs[d_config->num_pcidevs].power_mgmt = atoi(p); + } + } + d_config->num_pcidevs = d_config->num_pcidevs + 1; skip_pci: free(buf2); } @@ -1199,12 +1194,6 @@ static int create_domain(struct domain_c libxl_domain_build_state state; libxl_device_model_info dm_info; - libxl_device_disk *disks = NULL; - libxl_device_nic *vifs = NULL; - libxl_device_net2 *vif2s = NULL; - libxl_device_pci *pcidevs = NULL; - libxl_device_vfb *vfbs = NULL; - libxl_device_vkb *vkbs = NULL; libxl_device_console console; int debug = dom_info->debug; @@ -1216,7 +1205,6 @@ static int create_domain(struct domain_c int migrate_fd = dom_info->migrate_fd; char **migration_domname_r = dom_info->migration_domname_r; - int num_disks = 0, num_vifs = 0, num_vif2s = 0, num_pcidevs = 0, num_vfbs = 0, num_vkbs = 0; int i, fd; int need_daemon = 1; int ret, rc; @@ -1227,7 +1215,7 @@ static int create_domain(struct domain_c int restore_fd = -1; struct save_file_header hdr; - memset(&d_config, 0x00, sizeof(d_config); + memset(&d_config, 0x00, sizeof(d_config)); memset(&dm_info, 0x00, sizeof(dm_info)); if (restore_file) { @@ -1330,7 +1318,7 @@ static int create_domain(struct domain_c if (!dom_info->quiet) printf("Parsing config file %s\n", config_file); - parse_config_data(config_file, config_data, config_len, &d_config, &disks, &num_disks, &vifs, &num_vifs, &vif2s, &num_vif2s, &pcidevs, &num_pcidevs, &vfbs, &num_vfbs, &vkbs, &num_vkbs, &dm_info); + parse_config_data(config_file, config_data, config_len, &d_config, &dm_info); if (dom_info->dryrun) return 0; @@ -1350,7 +1338,7 @@ static int create_domain(struct domain_c } if (debug) - printf_info(-1, &d_config, disks, num_disks, vifs, num_vifs, pcidevs, num_pcidevs, vfbs, num_vfbs, vkbs, num_vkbs, &dm_info); + printf_info(-1, &d_config, &dm_info); start: domid = 0; @@ -1382,7 +1370,7 @@ start: */ dom_info->console_autoconnect = 0; - ret = libxl_run_bootloader(&ctx, &d_config.b_info, num_disks > 0 ? &disks[0] : NULL, domid); + ret = libxl_run_bootloader(&ctx, &d_config.b_info, d_config.num_disks > 0 ? &d_config.disks[0] : NULL, domid); if (ret) { fprintf(stderr, "failed to run bootloader: %d\n", ret); goto error_out; @@ -1404,18 +1392,18 @@ start: goto error_out; } - for (i = 0; i < num_disks; i++) { - disks[i].domid = domid; - ret = libxl_device_disk_add(&ctx, domid, &disks[i]); + for (i = 0; i < d_config.num_disks; i++) { + d_config.disks[i].domid = domid; + ret = libxl_device_disk_add(&ctx, domid, &d_config.disks[i]); if (ret) { fprintf(stderr, "cannot add disk %d to domain: %d\n", i, ret); ret = ERROR_FAIL; goto error_out; } } - for (i = 0; i < num_vifs; i++) { - vifs[i].domid = domid; - ret = libxl_device_nic_add(&ctx, domid, &vifs[i]); + for (i = 0; i < d_config.num_vifs; i++) { + d_config.vifs[i].domid = domid; + ret = libxl_device_nic_add(&ctx, domid, &d_config.vifs[i]); if (ret) { fprintf(stderr, "cannot add nic %d to domain: %d\n", i, ret); ret = ERROR_FAIL; @@ -1423,9 +1411,9 @@ start: } } if (!d_config.c_info.hvm) { - for (i = 0; i < num_vif2s; i++) { - vif2s[i].domid = domid; - ret = libxl_device_net2_add(&ctx, domid, &(vif2s[i])); + for (i = 0; i < d_config.num_vif2s; i++) { + d_config.vif2s[i].domid = domid; + ret = libxl_device_net2_add(&ctx, domid, &d_config.vif2s[i]); if (ret) { fprintf(stderr, "cannot add net2 %d to domain: %d\n", i, ret); ret = ERROR_FAIL; @@ -1435,28 +1423,30 @@ start: } if (d_config.c_info.hvm) { dm_info.domid = domid; - MUST( libxl_create_device_model(&ctx, &dm_info, disks, num_disks, - vifs, num_vifs, &dm_starting) ); - } else { - for (i = 0; i < num_vfbs; i++) { - vfbs[i].domid = domid; - libxl_device_vfb_add(&ctx, domid, &vfbs[i]); - vkbs[i].domid = domid; - libxl_device_vkb_add(&ctx, domid, &vkbs[i]); + MUST( libxl_create_device_model(&ctx, &dm_info, + d_config.disks, d_config.num_disks, + d_config.vifs, d_config.num_vifs, + &dm_starting) ); + } else { + for (i = 0; i < d_config.num_vfbs; i++) { + d_config.vfbs[i].domid = domid; + libxl_device_vfb_add(&ctx, domid, &d_config.vfbs[i]); + d_config.vkbs[i].domid = domid; + libxl_device_vkb_add(&ctx, domid, &d_config.vkbs[i]); } init_console_info(&console, 0, &state); console.domid = domid; - if (num_vfbs) + if (d_config.num_vfbs) console.constype = CONSTYPE_IOEMU; libxl_device_console_add(&ctx, domid, &console); - if (num_vfbs) - libxl_create_xenpv_qemu(&ctx, vfbs, 1, &console, &dm_starting); + if (d_config.num_vfbs) + libxl_create_xenpv_qemu(&ctx, d_config.vfbs, 1, &console, &dm_starting); } if (dm_starting) MUST( libxl_confirm_device_model_startup(&ctx, dm_starting) ); - for (i = 0; i < num_pcidevs; i++) - libxl_device_pci_add(&ctx, domid, &pcidevs[i]); + for (i = 0; i < d_config.num_pcidevs; i++) + libxl_device_pci_add(&ctx, domid, &d_config.pcidevs[i]); if (!paused) libxl_domain_unpause(&ctx, domid); @@ -1521,9 +1511,9 @@ start: } LOG("Waiting for domain %s (domid %d) to die [pid %ld]", d_config.c_info.name, domid, (long)getpid()); - w1 = (libxl_waiter*) xmalloc(sizeof(libxl_waiter) * num_disks); + w1 = (libxl_waiter*) xmalloc(sizeof(libxl_waiter) * d_config.num_disks); w2 = (libxl_waiter*) xmalloc(sizeof(libxl_waiter)); - libxl_wait_for_disk_ejects(&ctx, domid, disks, num_disks, w1); + libxl_wait_for_disk_ejects(&ctx, domid, d_config.disks, d_config.num_disks, w1); libxl_wait_for_domain_death(&ctx, domid, w2); libxl_get_wait_fd(&ctx, &fd); while (1) { @@ -2086,14 +2076,7 @@ void list_domains_details(void) char *config_file; uint8_t *data; int nb_domain, i, len, rc; - int num_disks = 0, num_vifs = 0, num_vif2s = 0, num_pcidevs = 0, num_vfbs = 0, num_vkbs = 0; libxl_device_model_info dm_info; - libxl_device_disk *disks = NULL; - libxl_device_nic *vifs = NULL; - libxl_device_net2 *vif2s = NULL; - libxl_device_pci *pcidevs = NULL; - libxl_device_vfb *vfbs = NULL; - libxl_device_vkb *vkbs = NULL; info = libxl_list_domain(&ctx, &nb_domain); @@ -2106,9 +2089,9 @@ void list_domains_details(void) if (rc) continue; CHK_ERRNO(asprintf(&config_file, "<domid %d data>", info[i].domid)); - memset(&d_config, 0x00, sizeof(d_config); - parse_config_data(config_file, (char *)data, len, &d_config, &disks, &num_disks, &vifs, &num_vifs, &vif2s, &num_vif2s, &pcidevs, &num_pcidevs, &vfbs, &num_vfbs, &vkbs, &num_vkbs, &dm_info); - printf_info(info[i].domid, &d_config, disks, num_disks, vifs, num_vifs, pcidevs, num_pcidevs, vfbs, num_vfbs, vkbs, num_vkbs, &dm_info); + memset(&d_config, 0x00, sizeof(d_config)); + parse_config_data(config_file, (char *)data, len, &d_config, &dm_info); + printf_info(info[i].domid, &d_config, &dm_info); free(data); free(config_file); } _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ian Campbell
2010-Jul-27 10:28 UTC
[Xen-devel] [PATCH 3 of 3] xl: simplify configuration parsing with local variables
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # Date 1280225499 -3600 # Node ID 06c6310a3c7b70196bd532dc3eec2300b5abdd5d # Parent d06f5e9633d3390cf5ea451fe39e48ca0b7bdbd4 xl: simplify configuration parsing with local variables Replace repeated patterns of "d_config->THING[d_config->num_THING]" with a single local variable. Signed-off-by: Ian Campbell <ian.campbell@citrix.com> diff -r d06f5e9633d3 -r 06c6310a3c7b tools/libxl/xl_cmdimpl.c --- a/tools/libxl/xl_cmdimpl.c Tue Jul 27 11:11:39 2010 +0100 +++ b/tools/libxl/xl_cmdimpl.c Tue Jul 27 11:11:39 2010 +0100 @@ -708,58 +708,63 @@ static void parse_config_data(const char d_config->num_disks = 0; d_config->disks = NULL; while ((buf = xlu_cfg_get_listitem (vbds, d_config->num_disks)) != NULL) { + libxl_device_disk *disk; char *buf2 = strdup(buf); char *p, *p2; + d_config->disks = (libxl_device_disk *) realloc(d_config->disks, sizeof (libxl_device_disk) * (d_config->num_disks + 1)); - d_config->disks[d_config->num_disks].backend_domid = 0; - d_config->disks[d_config->num_disks].domid = 0; - d_config->disks[d_config->num_disks].unpluggable = 0; + disk = d_config->disks + d_config->num_disks; + + disk->backend_domid = 0; + disk->domid = 0; + disk->unpluggable = 0; + p = strtok(buf2, ",:"); while (*p == '' '') p++; if (!strcmp(p, "phy")) { - d_config->disks[d_config->num_disks].phystype = PHYSTYPE_PHY; + disk->phystype = PHYSTYPE_PHY; } else if (!strcmp(p, "file")) { - d_config->disks[d_config->num_disks].phystype = PHYSTYPE_FILE; + disk->phystype = PHYSTYPE_FILE; } else if (!strcmp(p, "tap")) { p = strtok(NULL, ":"); if (!strcmp(p, "aio")) { - d_config->disks[d_config->num_disks].phystype = PHYSTYPE_AIO; + disk->phystype = PHYSTYPE_AIO; } else if (!strcmp(p, "vhd")) { - d_config->disks[d_config->num_disks].phystype = PHYSTYPE_VHD; + disk->phystype = PHYSTYPE_VHD; } else if (!strcmp(p, "qcow")) { - d_config->disks[d_config->num_disks].phystype = PHYSTYPE_QCOW; + disk->phystype = PHYSTYPE_QCOW; } else if (!strcmp(p, "qcow2")) { - d_config->disks[d_config->num_disks].phystype = PHYSTYPE_QCOW2; + disk->phystype = PHYSTYPE_QCOW2; } } p = strtok(NULL, ","); while (*p == '' '') p++; - d_config->disks[d_config->num_disks].physpath= strdup(p); + disk->physpath= strdup(p); p = strtok(NULL, ","); while (*p == '' '') p++; p2 = strchr(p, '':''); if (p2 == NULL) { - d_config->disks[d_config->num_disks].virtpath = strdup(p); - d_config->disks[d_config->num_disks].is_cdrom = 0; - d_config->disks[d_config->num_disks].unpluggable = 1; + disk->virtpath = strdup(p); + disk->is_cdrom = 0; + disk->unpluggable = 1; } else { *p2 = ''\0''; - d_config->disks[d_config->num_disks].virtpath = strdup(p); + disk->virtpath = strdup(p); if (!strcmp(p2 + 1, "cdrom")) { - d_config->disks[d_config->num_disks].is_cdrom = 1; - d_config->disks[d_config->num_disks].unpluggable = 1; + disk->is_cdrom = 1; + disk->unpluggable = 1; } else - d_config->disks[d_config->num_disks].is_cdrom = 0; + disk->is_cdrom = 0; } p = strtok(NULL, ","); while (*p == '' '') p++; - d_config->disks[d_config->num_disks].readwrite = (p[0] == ''w'') ? 1 : 0; - free(buf2); - d_config->num_disks = d_config->num_disks + 1; + disk->readwrite = (p[0] == ''w'') ? 1 : 0; + free(buf2); + d_config->num_disks++; } } @@ -767,10 +772,14 @@ static void parse_config_data(const char d_config->num_vifs = 0; d_config->vifs = NULL; while ((buf = xlu_cfg_get_listitem (nics, d_config->num_vifs)) != NULL) { + libxl_device_nic *nic; char *buf2 = strdup(buf); char *p, *p2; + d_config->vifs = (libxl_device_nic *) realloc(d_config->vifs, sizeof (libxl_device_nic) * (d_config->num_vifs+1)); - init_nic_info(d_config->vifs + d_config->num_vifs, d_config->num_vifs); + nic = d_config->vifs + d_config->num_vifs; + init_nic_info(nic, d_config->num_vifs); + p = strtok(buf2, ","); if (!p) goto skip; @@ -781,39 +790,39 @@ static void parse_config_data(const char break; *p2 = ''\0''; if (!strcmp(p, "model")) { - d_config->vifs[d_config->num_vifs].model = strdup(p2 + 1); + nic->model = strdup(p2 + 1); } else if (!strcmp(p, "mac")) { char *p3 = p2 + 1; *(p3 + 2) = ''\0''; - d_config->vifs[d_config->num_vifs].mac[0] = strtol(p3, NULL, 16); - p3 = p3 + 3; - *(p3 + 2) = ''\0''; - d_config->vifs[d_config->num_vifs].mac[1] = strtol(p3, NULL, 16); - p3 = p3 + 3; - *(p3 + 2) = ''\0''; - d_config->vifs[d_config->num_vifs].mac[2] = strtol(p3, NULL, 16); - p3 = p3 + 3; - *(p3 + 2) = ''\0''; - d_config->vifs[d_config->num_vifs].mac[3] = strtol(p3, NULL, 16); - p3 = p3 + 3; - *(p3 + 2) = ''\0''; - d_config->vifs[d_config->num_vifs].mac[4] = strtol(p3, NULL, 16); - p3 = p3 + 3; - *(p3 + 2) = ''\0''; - d_config->vifs[d_config->num_vifs].mac[5] = strtol(p3, NULL, 16); + nic->mac[0] = strtol(p3, NULL, 16); + p3 = p3 + 3; + *(p3 + 2) = ''\0''; + nic->mac[1] = strtol(p3, NULL, 16); + p3 = p3 + 3; + *(p3 + 2) = ''\0''; + nic->mac[2] = strtol(p3, NULL, 16); + p3 = p3 + 3; + *(p3 + 2) = ''\0''; + nic->mac[3] = strtol(p3, NULL, 16); + p3 = p3 + 3; + *(p3 + 2) = ''\0''; + nic->mac[4] = strtol(p3, NULL, 16); + p3 = p3 + 3; + *(p3 + 2) = ''\0''; + nic->mac[5] = strtol(p3, NULL, 16); } else if (!strcmp(p, "bridge")) { - d_config->vifs[d_config->num_vifs].bridge = strdup(p2 + 1); + nic->bridge = strdup(p2 + 1); } else if (!strcmp(p, "type")) { if (!strcmp(p2 + 1, "ioemu")) - d_config->vifs[d_config->num_vifs].nictype = NICTYPE_IOEMU; + nic->nictype = NICTYPE_IOEMU; else - d_config->vifs[d_config->num_vifs].nictype = NICTYPE_VIF; + nic->nictype = NICTYPE_VIF; } else if (!strcmp(p, "ip")) { - inet_pton(AF_INET, p2 + 1, &d_config->vifs[d_config->num_vifs].ip); + inet_pton(AF_INET, p2 + 1, &nic->ip); } else if (!strcmp(p, "script")) { - d_config->vifs[d_config->num_vifs].script = strdup(p2 + 1); + nic->script = strdup(p2 + 1); } else if (!strcmp(p, "vifname")) { - d_config->vifs[d_config->num_vifs].ifname = strdup(p2 + 1); + nic->ifname = strdup(p2 + 1); } else if (!strcmp(p, "rate")) { fprintf(stderr, "the rate parameter for vifs is currently not supported\n"); } else if (!strcmp(p, "accel")) { @@ -822,7 +831,7 @@ static void parse_config_data(const char } while ((p = strtok(NULL, ",")) != NULL); skip: free(buf2); - d_config->num_vifs = d_config->num_vifs + 1; + d_config->num_vifs++; } } @@ -830,39 +839,42 @@ skip: d_config->num_vif2s = 0; d_config->vif2s = NULL; while ((buf = xlu_cfg_get_listitem(net2s, d_config->num_vif2s))) { + libxl_device_net2 *net2; char *buf2 = strdup(buf); char *p; d_config->vif2s = realloc(d_config->vif2s, sizeof (libxl_device_net2) * (d_config->num_vif2s + 1)); - init_net2_info(d_config->vif2s + d_config->num_vif2s, d_config->num_vif2s); + net2 = d_config->vif2s + d_config->num_vif2s; + + init_net2_info(net2, d_config->num_vif2s); for (p = strtok(buf2, ","); p; p = strtok(buf2, ",")) { while (isblank(*p)) p++; if (!strncmp("front_mac=", p, 10)) { - libxl_strtomac(p + 10, d_config->vif2s[d_config->num_vif2s].front_mac); + libxl_strtomac(p + 10, net2->front_mac); } else if (!strncmp("back_mac=", p, 9)) { - libxl_strtomac(p + 9, d_config->vif2s[d_config->num_vif2s].back_mac); + libxl_strtomac(p + 9, net2->back_mac); } else if (!strncmp("backend=", p, 8)) { - domain_qualifier_to_domid(p + 8, &d_config->vif2s[d_config->num_vif2s].backend_domid, 0); + domain_qualifier_to_domid(p + 8, &net2->backend_domid, 0); } else if (!strncmp("trusted=", p, 8)) { - d_config->vif2s[d_config->num_vif2s].trusted = (*(p + 8) == ''1''); + net2->trusted = (*(p + 8) == ''1''); } else if (!strncmp("back_trusted=", p, 13)) { - d_config->vif2s[d_config->num_vif2s].back_trusted = (*(p + 13) == ''1''); + net2->back_trusted = (*(p + 13) == ''1''); } else if (!strncmp("bridge=", p, 7)) { - d_config->vif2s[d_config->num_vif2s].bridge = strdup(p + 13); + net2->bridge = strdup(p + 13); } else if (!strncmp("filter_mac=", p, 11)) { - d_config->vif2s[d_config->num_vif2s].filter_mac = (*(p + 11) == ''1''); + net2->filter_mac = (*(p + 11) == ''1''); } else if (!strncmp("front_filter_mac=", p, 17)) { - d_config->vif2s[d_config->num_vif2s].front_filter_mac = (*(p + 17) == ''1''); + net2->front_filter_mac = (*(p + 17) == ''1''); } else if (!strncmp("pdev=", p, 5)) { - d_config->vif2s[d_config->num_vif2s].pdev = strtoul(p + 5, NULL, 10); + net2->pdev = strtoul(p + 5, NULL, 10); } else if (!strncmp("max_bypasses=", p, 13)) { - d_config->vif2s[d_config->num_vif2s].max_bypasses = strtoul(p + 13, NULL, 10); - } - } - free(buf2); - ++d_config->num_vif2s; + net2->max_bypasses = strtoul(p + 13, NULL, 10); + } + } + free(buf2); + d_config->num_vif2s++; } } @@ -872,13 +884,19 @@ skip: d_config->vfbs = NULL; d_config->vkbs = NULL; while ((buf = xlu_cfg_get_listitem (cvfbs, d_config->num_vfbs)) != NULL) { + libxl_device_vfb *vfb; + libxl_device_vkb *vkb; + char *buf2 = strdup(buf); char *p, *p2; + d_config->vfbs = (libxl_device_vfb *) realloc(d_config->vfbs, sizeof(libxl_device_vfb) * (d_config->num_vfbs + 1)); - init_vfb_info(d_config->vfbs + d_config->num_vfbs, d_config->num_vfbs); + vfb = d_config->vfbs + d_config->num_vfbs; + init_vfb_info(vfb, d_config->num_vfbs); d_config->vkbs = (libxl_device_vkb *) realloc(d_config->vkbs, sizeof(libxl_device_vkb) * (d_config->num_vkbs + 1)); - init_vkb_info(d_config->vkbs + d_config->num_vkbs, d_config->num_vkbs); + vkb = d_config->vkbs + d_config->num_vkbs; + init_vkb_info(vkb, d_config->num_vkbs); p = strtok(buf2, ","); if (!p) @@ -890,31 +908,31 @@ skip: break; *p2 = ''\0''; if (!strcmp(p, "vnc")) { - d_config->vfbs[d_config->num_vfbs].vnc = atoi(p2 + 1); + vfb->vnc = atoi(p2 + 1); } else if (!strcmp(p, "vnclisten")) { - d_config->vfbs[d_config->num_vfbs].vnclisten = strdup(p2 + 1); + vfb->vnclisten = strdup(p2 + 1); } else if (!strcmp(p, "vncpasswd")) { - d_config->vfbs[d_config->num_vfbs].vncpasswd = strdup(p2 + 1); + vfb->vncpasswd = strdup(p2 + 1); } else if (!strcmp(p, "vncdisplay")) { - d_config->vfbs[d_config->num_vfbs].vncdisplay = atoi(p2 + 1); + vfb->vncdisplay = atoi(p2 + 1); } else if (!strcmp(p, "vncunused")) { - d_config->vfbs[d_config->num_vfbs].vncunused = atoi(p2 + 1); + vfb->vncunused = atoi(p2 + 1); } else if (!strcmp(p, "keymap")) { - d_config->vfbs[d_config->num_vfbs].keymap = strdup(p2 + 1); + vfb->keymap = strdup(p2 + 1); } else if (!strcmp(p, "sdl")) { - d_config->vfbs[d_config->num_vfbs].sdl = atoi(p2 + 1); + vfb->sdl = atoi(p2 + 1); } else if (!strcmp(p, "opengl")) { - d_config->vfbs[d_config->num_vfbs].opengl = atoi(p2 + 1); + vfb->opengl = atoi(p2 + 1); } else if (!strcmp(p, "display")) { - d_config->vfbs[d_config->num_vfbs].display = strdup(p2 + 1); + vfb->display = strdup(p2 + 1); } else if (!strcmp(p, "xauthority")) { - d_config->vfbs[d_config->num_vfbs].xauthority = strdup(p2 + 1); + vfb->xauthority = strdup(p2 + 1); } } while ((p = strtok(NULL, ",")) != NULL); skip_vfb: free(buf2); - d_config->num_vfbs = d_config->num_vfbs + 1; - d_config->num_vkbs = d_config->num_vkbs + 1; + d_config->num_vfbs++; + d_config->num_vkbs++; } } @@ -928,11 +946,15 @@ skip_vfb: d_config->num_pcidevs = 0; d_config->pcidevs = NULL; while ((buf = xlu_cfg_get_listitem (pcis, d_config->num_pcidevs)) != NULL) { + libxl_device_pci *pcidev; unsigned int domain = 0, bus = 0, dev = 0, func = 0, vdevfn = 0; char *buf2 = strdup(buf); char *p; + d_config->pcidevs = (libxl_device_pci *) realloc(d_config->pcidevs, sizeof (libxl_device_pci) * (d_config->num_pcidevs + 1)); - memset(d_config->pcidevs + d_config->num_pcidevs, 0x00, sizeof(libxl_device_pci)); + pcidev = d_config->pcidevs + d_config->num_pcidevs; + memset(pcidev, 0x00, sizeof(libxl_device_pci)); + p = strtok(buf2, ","); if (!p) goto skip_pci; @@ -943,21 +965,22 @@ skip_vfb: goto skip_pci; } } - libxl_device_pci_init(d_config->pcidevs + d_config->num_pcidevs, domain, bus, dev, func, vdevfn); - d_config->pcidevs[d_config->num_pcidevs].msitranslate = pci_msitranslate; - d_config->pcidevs[d_config->num_pcidevs].power_mgmt = pci_power_mgmt; + + libxl_device_pci_init(pcidev, domain, bus, dev, func, vdevfn); + pcidev->msitranslate = pci_msitranslate; + pcidev->power_mgmt = pci_power_mgmt; while ((p = strtok(NULL, ",=")) != NULL) { while (*p == '' '') p++; if (!strcmp(p, "msitranslate")) { p = strtok(NULL, ",="); - d_config->pcidevs[d_config->num_pcidevs].msitranslate = atoi(p); + pcidev->msitranslate = atoi(p); } else if (!strcmp(p, "power_mgmt")) { p = strtok(NULL, ",="); - d_config->pcidevs[d_config->num_pcidevs].power_mgmt = atoi(p); - } - } - d_config->num_pcidevs = d_config->num_pcidevs + 1; + pcidev->power_mgmt = atoi(p); + } + } + d_config->num_pcidevs++; skip_pci: free(buf2); } _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel