Gianni Tedesco
2010-Dec-21 15:17 UTC
[Xen-devel] [PATCH,RFC,v2]: Introduce libxl_domain_create()
This patch incorporates previous suggestions: - use LIBXL namespace for ACTION_* enum - use callbacks for console attach - split to two functions / remove ''flags'' parameter - don''t call exit() from libxl - catch strdup() error in console struct init - put dm_info inside domain_info struct Not done: - internalise old domain create functions - idl bindings So not sure where to take this from here, could do a series with: 1. IDL changes 2. updated version of this patch 3. re-base of my python patch-queue More comments? diff -r 1f0f3b6d6ced tools/libxl/Makefile --- a/tools/libxl/Makefile Tue Dec 21 08:58:19 2010 +0000 +++ b/tools/libxl/Makefile Tue Dec 21 15:08:50 2010 +0000 @@ -20,7 +20,7 @@ ifeq ($(CONFIG_Linux),y) LIBS += -luuid endif -LIBXL_OBJS-y = osdeps.o libxl_paths.o libxl_bootloader.o +LIBXL_OBJS-y = osdeps.o libxl_paths.o libxl_bootloader.o flexarray.o ifeq ($(LIBXL_BLKTAP),y) LIBXL_OBJS-y += libxl_blktap2.o else @@ -29,7 +29,7 @@ endif LIBXL_OBJS-$(CONFIG_X86) += libxl_cpuid.o LIBXL_OBJS-$(CONFIG_IA64) += libxl_nocpuid.o -LIBXL_OBJS = flexarray.o libxl.o libxl_pci.o libxl_dom.o libxl_exec.o libxl_xshelp.o libxl_device.o libxl_internal.o libxl_utils.o $(LIBXL_OBJS-y) +LIBXL_OBJS = libxl.o libxl_create.o libxl_pci.o libxl_dom.o libxl_exec.o libxl_xshelp.o libxl_device.o libxl_internal.o libxl_utils.o $(LIBXL_OBJS-y) LIBXL_OBJS += _libxl_types.o AUTOINCS= libxlu_cfg_y.h libxlu_cfg_l.h diff -r 1f0f3b6d6ced tools/libxl/libxl.h --- a/tools/libxl/libxl.h Tue Dec 21 08:58:19 2010 +0000 +++ b/tools/libxl/libxl.h Tue Dec 21 15:08:50 2010 +0000 @@ -246,6 +246,38 @@ enum { #define LIBXL_VERSION 0 +enum action_on_shutdown { + LIBXL_ACTION_DESTROY, + + LIBXL_ACTION_RESTART, + LIBXL_ACTION_RESTART_RENAME, + + LIBXL_ACTION_PRESERVE, + + LIBXL_ACTION_COREDUMP_DESTROY, + LIBXL_ACTION_COREDUMP_RESTART, +}; + +typedef struct { + libxl_domain_create_info c_info; + libxl_domain_build_info b_info; + libxl_device_model_info dm_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; + enum action_on_shutdown on_crash; +} libxl_domain_config; + /* context functions */ int libxl_ctx_init(libxl_ctx *ctx, int version, xentoollog_logger*); int libxl_ctx_free(libxl_ctx *ctx); @@ -253,6 +285,10 @@ int libxl_ctx_set_log(libxl_ctx *ctx, xe int libxl_ctx_postfork(libxl_ctx *ctx); /* domain related functions */ +typedef int (*libxl_console_ready)(libxl_ctx *ctx, uint32_t domid, void *priv); +int libxl_domain_create_new(libxl_ctx *ctx, libxl_domain_config *d_config, libxl_console_ready cb, void *priv, uint32_t *domid); +int libxl_domain_create_restore(libxl_ctx *ctx, libxl_domain_config *d_config, libxl_console_ready cb, void *priv, uint32_t *domid, int restore_fd); +void libxl_domain_config_destroy(libxl_domain_config *d_config); int libxl_domain_make(libxl_ctx *ctx, libxl_domain_create_info *info, uint32_t *domid); int libxl_domain_build(libxl_ctx *ctx, libxl_domain_build_info *info, uint32_t domid, /* out */ libxl_domain_build_state *state); int libxl_domain_restore(libxl_ctx *ctx, libxl_domain_build_info *info, diff -r 1f0f3b6d6ced tools/libxl/libxl_create.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/libxl/libxl_create.c Tue Dec 21 15:08:50 2010 +0000 @@ -0,0 +1,229 @@ +/* + * Copyright (C) 2010 Citrix Ltd. + * Author Vincent Hanquez <vincent.hanquez@eu.citrix.com> + * Author Stefano Stabellini <stefano.stabellini@eu.citrix.com> + * Author Gianni Tedesco <gianni.tedesco@citrix.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; version 2.1 only. with the special + * exception on linking described in file LICENSE. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +#include "libxl_osdeps.h" + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <unistd.h> +#include "libxl.h" +#include "libxl_utils.h" +#include "libxl_internal.h" +#include "flexarray.h" + +#define MUST( call ) ({ \ + int must_rc = (call); \ + if (must_rc < 0) { \ + fprintf(stderr,"xl: fatal error: %s:%d, rc=%d: %s\n", \ + __FILE__,__LINE__, must_rc, #call); \ + goto error_out; \ + } \ + }) + +void libxl_domain_config_destroy(libxl_domain_config *d_config) +{ + int i; + + for (i=0; i<d_config->num_disks; i++) + libxl_device_disk_destroy(&d_config->disks[i]); + free(d_config->disks); + + for (i=0; i<d_config->num_vifs; i++) + libxl_device_nic_destroy(&d_config->vifs[i]); + free(d_config->vifs); + + for (i=0; i<d_config->num_vif2s; i++) + libxl_device_net2_destroy(&d_config->vif2s[i]); + free(d_config->vif2s); + + for (i=0; i<d_config->num_pcidevs; i++) + libxl_device_pci_destroy(&d_config->pcidevs[i]); + free(d_config->pcidevs); + + for (i=0; i<d_config->num_vfbs; i++) + libxl_device_vfb_destroy(&d_config->vfbs[i]); + free(d_config->vfbs); + + for (i=0; i<d_config->num_vkbs; i++) + libxl_device_vkb_destroy(&d_config->vkbs[i]); + free(d_config->vkbs); + + libxl_domain_create_info_destroy(&d_config->c_info); + libxl_domain_build_info_destroy(&d_config->b_info); + libxl_device_model_info_destroy(&d_config->dm_info); +} + +static int init_console_info(libxl_device_console *console, int dev_num, libxl_domain_build_state *state) +{ + memset(console, 0x00, sizeof(libxl_device_console)); + console->devid = dev_num; + console->consback = LIBXL_CONSBACK_XENCONSOLED; + console->output = strdup("pty"); + if ( NULL == console->output ) + return ERROR_NOMEM; + if (state) + console->build_state = state; + return 0; +} + +static int do_domain_create(libxl_ctx *ctx, libxl_domain_config *d_config, + libxl_console_ready cb, void *priv, + uint32_t *domid_out, int restore_fd) +{ + libxl_device_model_starting *dm_starting = 0; + libxl_device_model_info *dm_info = &d_config->dm_info; + libxl_domain_build_state state; + uint32_t domid; + int i, ret; + + domid = 0; + + ret = libxl_domain_make(ctx, &d_config->c_info, &domid); + if (ret) { + fprintf(stderr, "cannot make domain: %d\n", ret); + ret = ERROR_FAIL; + goto error_out; + } + + if ( !d_config->c_info.hvm && cb ) { + if ( (*cb)(ctx, domid, priv) ) + goto error_out; + } + + if ( restore_fd < 0 ) { + 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; + } + } + + if ( restore_fd >= 0 ) { + ret = libxl_domain_restore(ctx, &d_config->b_info, domid, restore_fd, &state, dm_info); + } else { + if (dm_info->saved_state) { + free(dm_info->saved_state); + dm_info->saved_state = NULL; + } + ret = libxl_domain_build(ctx, &d_config->b_info, domid, &state); + } + + if (ret) { + fprintf(stderr, "cannot (re-)build domain: %d\n", ret); + ret = ERROR_FAIL; + goto error_out; + } + + 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 < 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; + goto error_out; + } + } + if (!d_config->c_info.hvm) { + 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; + goto error_out; + } + } + } + if (d_config->c_info.hvm) { + libxl_device_console console; + + ret = init_console_info(&console, 0, &state); + if ( ret ) + goto error_out; + console.domid = domid; + libxl_device_console_add(ctx, domid, &console); + libxl_device_console_destroy(&console); + + dm_info->domid = domid; + 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 { + libxl_device_console console; + + 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]); + } + + ret = init_console_info(&console, 0, &state); + if ( ret ) + goto error_out; + console.domid = domid; + if (d_config->num_vfbs) + console.consback = LIBXL_CONSBACK_IOEMU; + libxl_device_console_add(ctx, domid, &console); + libxl_device_console_destroy(&console); + + if (d_config->num_vfbs) + libxl_create_xenpv_qemu(ctx, domid, d_config->vfbs, &dm_starting); + } + + if (dm_starting) + MUST( libxl_confirm_device_model_startup(ctx, dm_starting) ); + + for (i = 0; i < d_config->num_pcidevs; i++) + libxl_device_pci_add(ctx, domid, &d_config->pcidevs[i]); + + if ( d_config->c_info.hvm && cb ) { + if ( (*cb)(ctx, domid, priv) ) + goto error_out; + } + + *domid_out = domid; + return ret; + +error_out: + if (domid) + libxl_domain_destroy(ctx, domid, 0); + + return ret; +} +int libxl_domain_create_new(libxl_ctx *ctx, libxl_domain_config *d_config, + libxl_console_ready cb, void *priv, uint32_t *domid) +{ + return do_domain_create(ctx, d_config, cb, priv, domid, -1); +} + +int libxl_domain_create_restore(libxl_ctx *ctx, libxl_domain_config *d_config, + libxl_console_ready cb, void *priv, uint32_t *domid, int restore_fd) +{ + return do_domain_create(ctx, d_config, cb, priv, domid, restore_fd); +} diff -r 1f0f3b6d6ced tools/libxl/xl_cmdimpl.c --- a/tools/libxl/xl_cmdimpl.c Tue Dec 21 08:58:19 2010 +0000 +++ b/tools/libxl/xl_cmdimpl.c Tue Dec 21 15:08:50 2010 +0000 @@ -100,81 +100,18 @@ struct save_file_header { }; -enum action_on_shutdown { - ACTION_DESTROY, - - ACTION_RESTART, - ACTION_RESTART_RENAME, - - ACTION_PRESERVE, - - ACTION_COREDUMP_DESTROY, - ACTION_COREDUMP_RESTART, +static const char *action_on_shutdown_names[] = { + [LIBXL_ACTION_DESTROY] = "destroy", + + [LIBXL_ACTION_RESTART] = "restart", + [LIBXL_ACTION_RESTART_RENAME] = "rename-restart", + + [LIBXL_ACTION_PRESERVE] = "preserve", + + [LIBXL_ACTION_COREDUMP_DESTROY] = "coredump-destroy", + [LIBXL_ACTION_COREDUMP_RESTART] = "coredump-restart", }; -static const char *action_on_shutdown_names[] = { - [ACTION_DESTROY] = "destroy", - - [ACTION_RESTART] = "restart", - [ACTION_RESTART_RENAME] = "rename-restart", - - [ACTION_PRESERVE] = "preserve", - - [ACTION_COREDUMP_DESTROY] = "coredump-destroy", - [ACTION_COREDUMP_RESTART] = "coredump-restart", -}; - -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; - enum action_on_shutdown on_crash; -}; - -static void free_domain_config(struct domain_config *d_config) -{ - int i; - - for (i=0; i<d_config->num_disks; i++) - libxl_device_disk_destroy(&d_config->disks[i]); - free(d_config->disks); - - for (i=0; i<d_config->num_vifs; i++) - libxl_device_nic_destroy(&d_config->vifs[i]); - free(d_config->vifs); - - for (i=0; i<d_config->num_vif2s; i++) - libxl_device_net2_destroy(&d_config->vif2s[i]); - free(d_config->vif2s); - - for (i=0; i<d_config->num_pcidevs; i++) - libxl_device_pci_destroy(&d_config->pcidevs[i]); - free(d_config->pcidevs); - - for (i=0; i<d_config->num_vfbs; i++) - libxl_device_vfb_destroy(&d_config->vfbs[i]); - free(d_config->vfbs); - - for (i=0; i<d_config->num_vkbs; i++) - libxl_device_vkb_destroy(&d_config->vkbs[i]); - free(d_config->vkbs); - - libxl_domain_create_info_destroy(&d_config->c_info); - libxl_domain_build_info_destroy(&d_config->b_info); -} - /* Optional data, in order: * 4 bytes uint32_t config file size * n bytes config file in Unix text file format @@ -457,18 +394,8 @@ static void init_vkb_info(libxl_device_v vkb->devid = dev_num; } -static void init_console_info(libxl_device_console *console, int dev_num, libxl_domain_build_state *state) -{ - memset(console, 0x00, sizeof(libxl_device_console)); - console->devid = dev_num; - console->consback = LIBXL_CONSBACK_XENCONSOLED; - console->output = strdup("pty"); - if (state) - console->build_state = state; -} - static void printf_info(int domid, - struct domain_config *d_config, + libxl_domain_config *d_config, libxl_device_model_info *dm_info) { int i; @@ -644,7 +571,7 @@ static int parse_action_on_shutdown(cons static void parse_config_data(const char *configfile_filename_report, const char *configfile_data, int configfile_len, - struct domain_config *d_config, + libxl_domain_config *d_config, libxl_device_model_info *dm_info) { const char *buf; @@ -1233,29 +1160,9 @@ static void *xrealloc(void *ptr, size_t return r; } -static pid_t autoconnect_console(void) -{ - pid_t pid; - - pid = fork(); - if (pid < 0) { - perror("unable to fork xenconsole"); - return ERROR_FAIL; - } else if (pid > 0) - return pid; - - libxl_ctx_postfork(&ctx); - - sleep(1); - libxl_primary_console_exec(&ctx, domid); - /* Do not return. xl continued in child process */ - fprintf(stderr, "Unable to attach console\n"); - _exit(1); -} - /* Returns 1 if domain should be restarted, 2 if domain should be renamed then restarted */ static int handle_domain_death(libxl_ctx *ctx, uint32_t domid, libxl_event *event, - struct domain_config *d_config, libxl_dominfo *info) + libxl_domain_config *d_config, libxl_dominfo *info) { int restart = 0; enum action_on_shutdown action; @@ -1277,12 +1184,12 @@ static int handle_domain_death(libxl_ctx break; default: LOG("Unknown shutdown reason code %d. Destroying domain.", info->shutdown_reason); - action = ACTION_DESTROY; + action = LIBXL_ACTION_DESTROY; } LOG("Action for shutdown reason code %d is %s", info->shutdown_reason, action_on_shutdown_names[action]); - if (action == ACTION_COREDUMP_DESTROY || action == ACTION_COREDUMP_RESTART) { + if (action == LIBXL_ACTION_COREDUMP_DESTROY || action == LIBXL_ACTION_COREDUMP_RESTART) { char *corefile; int rc; @@ -1295,30 +1202,30 @@ static int handle_domain_death(libxl_ctx } /* No point crying over spilled milk, continue on failure. */ - if (action == ACTION_COREDUMP_DESTROY) - action = ACTION_DESTROY; + if (action == LIBXL_ACTION_COREDUMP_DESTROY) + action = LIBXL_ACTION_DESTROY; else - action = ACTION_RESTART; + action = LIBXL_ACTION_RESTART; } switch (action) { - case ACTION_PRESERVE: + case LIBXL_ACTION_PRESERVE: break; - case ACTION_RESTART_RENAME: + case LIBXL_ACTION_RESTART_RENAME: restart = 2; break; - case ACTION_RESTART: + case LIBXL_ACTION_RESTART: restart = 1; /* fall-through */ - case ACTION_DESTROY: + case LIBXL_ACTION_DESTROY: LOG("Domain %d needs to be cleaned up: destroying the domain", domid); libxl_domain_destroy(ctx, domid, 0); break; - case ACTION_COREDUMP_DESTROY: - case ACTION_COREDUMP_RESTART: + case LIBXL_ACTION_COREDUMP_DESTROY: + case LIBXL_ACTION_COREDUMP_RESTART: /* Already handled these above. */ abort(); } @@ -1327,7 +1234,7 @@ static int handle_domain_death(libxl_ctx } static int preserve_domain(libxl_ctx *ctx, uint32_t domid, libxl_event *event, - struct domain_config *d_config, libxl_dominfo *info) + libxl_domain_config *d_config, libxl_dominfo *info) { time_t now; struct tm tm; @@ -1418,12 +1325,29 @@ static int freemem(libxl_domain_build_in return ERROR_NOMEM; } +static int autoconnect_console(libxl_ctx *ctx, uint32_t domid, void *priv) +{ + pid_t *pid = priv; + + *pid = fork(); + if (*pid < 0) { + perror("unable to fork xenconsole"); + return ERROR_FAIL; + } else if (*pid > 0) + return 0; + + libxl_ctx_postfork(ctx); + + sleep(1); + libxl_primary_console_exec(ctx, domid); + /* Do not return. xl continued in child process */ + fprintf(stderr, "Unable to attach console\n"); + _exit(1); +} + static int create_domain(struct domain_create *dom_info) { - struct domain_config d_config; - - libxl_domain_build_state state; - libxl_device_model_info dm_info; + libxl_domain_config d_config; int debug = dom_info->debug; int daemonize = dom_info->daemonize; @@ -1433,20 +1357,19 @@ static int create_domain(struct domain_c const char *restore_file = dom_info->restore_file; int migrate_fd = dom_info->migrate_fd; - int i, fd; + int fd; int need_daemon = 1; int ret, rc; - libxl_device_model_starting *dm_starting = 0; libxl_waiter *w1 = NULL, *w2 = NULL; void *config_data = 0; int config_len = 0; int restore_fd = -1; + int status = 0; + libxl_console_ready cb; + pid_t child_console_pid = -1; struct save_file_header hdr; - pid_t child_console_pid = -1; - int status = 0; memset(&d_config, 0x00, sizeof(d_config)); - memset(&dm_info, 0x00, sizeof(dm_info)); if (restore_file) { uint8_t *optdata_begin = 0; @@ -1546,7 +1469,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, &dm_info); + parse_config_data(config_file, config_data, config_len, &d_config, &d_config.dm_info); ret = 0; if (dom_info->dryrun) @@ -1571,7 +1494,7 @@ static int create_domain(struct domain_c } if (debug) - printf_info(-1, &d_config, &dm_info); + printf_info(-1, &d_config, &d_config.dm_info); start: domid = 0; @@ -1580,20 +1503,13 @@ start: if (rc < 0) goto error_out; - ret = freemem(&d_config.b_info, &dm_info); + ret = freemem(&d_config.b_info, &d_config.dm_info); if (ret < 0) { fprintf(stderr, "failed to free memory for the domain\n"); ret = ERROR_FAIL; goto error_out; } - ret = libxl_domain_make(&ctx, &d_config.c_info, &domid); - if (ret) { - fprintf(stderr, "cannot make domain: %d\n", ret); - ret = ERROR_FAIL; - goto error_out; - } - ret = libxl_userdata_store(&ctx, domid, "xl", config_data, config_len); if (ret) { @@ -1602,116 +1518,22 @@ start: goto error_out; } - if (dom_info->console_autoconnect && !d_config.c_info.hvm) { - child_console_pid = autoconnect_console(); - if (child_console_pid < 0) - goto error_out; - } - - if (!restore_file) { - 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; - } - } - - if (!restore_file || !need_daemon) { - if (dm_info.saved_state) { - free(dm_info.saved_state); - dm_info.saved_state = NULL; - } - 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) { - fprintf(stderr, "cannot (re-)build domain: %d\n", ret); - ret = ERROR_FAIL; + if ( dom_info->console_autoconnect ) { + cb = autoconnect_console; + }else{ + cb = NULL; + } + + if ( restore_file ) { + ret = libxl_domain_create_restore(&ctx, &d_config, + cb, &child_console_pid, + &domid, restore_fd); + }else{ + ret = libxl_domain_create_new(&ctx, &d_config, + cb, &child_console_pid, &domid); + } + if ( ret ) goto error_out; - } - - 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 < 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; - goto error_out; - } - } - if (!d_config.c_info.hvm) { - 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; - goto error_out; - } - } - } - if (d_config.c_info.hvm) { - libxl_device_console console; - - init_console_info(&console, 0, &state); - console.domid = domid; - libxl_device_console_add(&ctx, domid, &console); - libxl_device_console_destroy(&console); - - dm_info.domid = domid; - 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 { - int need_qemu = 0; - libxl_device_console console; - - 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; - - need_qemu = libxl_need_xenpv_qemu(&ctx, 1, &console, - d_config.num_vfbs, d_config.vfbs, - d_config.num_disks, &d_config.disks[0]); - - if (need_qemu) - console.consback = LIBXL_CONSBACK_IOEMU; - - libxl_device_console_add(&ctx, domid, &console); - libxl_device_console_destroy(&console); - - if (need_qemu) - libxl_create_xenpv_qemu(&ctx, domid, d_config.vfbs, &dm_starting); - } - - if (dm_starting) - MUST( libxl_confirm_device_model_startup(&ctx, dm_starting) ); - for (i = 0; i < d_config.num_pcidevs; i++) - libxl_device_pci_add(&ctx, domid, &d_config.pcidevs[i]); - - if (dom_info->console_autoconnect && d_config.c_info.hvm) { - child_console_pid = autoconnect_console(); - if (child_console_pid < 0) - goto error_out; - } release_lock(); @@ -1729,6 +1551,8 @@ start: child1 = libxl_fork(&ctx); if (child1) { + printf("Daemon running with PID %d\n", child1); + for (;;) { got_child = waitpid(child1, &status, 0); if (got_child == child1) break; @@ -1870,9 +1694,7 @@ out: if (logfile != 2) close(logfile); - libxl_device_model_info_destroy(&dm_info); - - free_domain_config(&d_config); + libxl_domain_config_destroy(&d_config); free(config_data); @@ -2467,7 +2289,7 @@ static void reboot_domain(const char *p) static void list_domains_details(const libxl_dominfo *info, int nb_domain) { - struct domain_config d_config; + libxl_domain_config d_config; char *config_file; uint8_t *data; @@ -2485,7 +2307,7 @@ static void list_domains_details(const l 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_domain_config(&d_config); + libxl_domain_config_destroy(&d_config); free(data); free(config_file); } _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ian Campbell
2010-Dec-21 15:30 UTC
[Xen-devel] Re: [PATCH,RFC,v2]: Introduce libxl_domain_create()
Only minor comments. On Tue, 2010-12-21 at 15:17 +0000, Gianni Tedesco wrote:> @@ -246,6 +246,38 @@ enum { > > #define LIBXL_VERSION 0 > > +enum action_on_shutdown {Namespace.> + LIBXL_ACTION_DESTROY, > + > + LIBXL_ACTION_RESTART, > + LIBXL_ACTION_RESTART_RENAME, > + > + LIBXL_ACTION_PRESERVE, > + > + LIBXL_ACTION_COREDUMP_DESTROY, > + LIBXL_ACTION_COREDUMP_RESTART, > +};[...]> +#define MUST( call ) ({ \ > + int must_rc = (call); \ > + if (must_rc < 0) { \ > + fprintf(stderr,"xl: fatal error: %s:%d, rc=%d: %s\n", \ > + __FILE__,__LINE__, must_rc, #call); \ > + goto error_out; \ > + } \ > + })I don''t think the two callsites of this macro justify the obfuscation of having a goto in a macro, just open code it.> + > + if ( dom_info->console_autoconnect ) { > + cb = autoconnect_console; > + }else{} else {> + }else{Some of the indentation looks weird. Could be my mail client or perhaps you are mixing spaces and tabs or something? Ian. _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Gianni Tedesco
2010-Dec-21 16:15 UTC
[Xen-devel] Re: [PATCH,RFC,v2]: Introduce libxl_domain_create()
On Tue, 2010-12-21 at 15:30 +0000, Ian Campbell wrote:> Only minor comments. > > On Tue, 2010-12-21 at 15:17 +0000, Gianni Tedesco wrote: > > @@ -246,6 +246,38 @@ enum { > > > > #define LIBXL_VERSION 0 > > > > +enum action_on_shutdown { > > Namespace.Ah, thanks, missed that.> > + LIBXL_ACTION_DESTROY, > > + > > + LIBXL_ACTION_RESTART, > > + LIBXL_ACTION_RESTART_RENAME, > > + > > + LIBXL_ACTION_PRESERVE, > > + > > + LIBXL_ACTION_COREDUMP_DESTROY, > > + LIBXL_ACTION_COREDUMP_RESTART, > > +}; > [...] > > +#define MUST( call ) ({ \ > > + int must_rc = (call); \ > > + if (must_rc < 0) { \ > > + fprintf(stderr,"xl: fatal error: %s:%d, rc=%d: %s\n", \ > > + __FILE__,__LINE__, must_rc, #call); \ > > + goto error_out; \ > > + } \ > > + }) > > I don''t think the two callsites of this macro justify the obfuscation of > having a goto in a macro, just open code it.Yes, you''re right.> > + > > + if ( dom_info->console_autoconnect ) { > > + cb = autoconnect_console; > > + }else{ > > } else { > > > + }else{ > > Some of the indentation looks weird. Could be my mail client or perhaps > you are mixing spaces and tabs or something?Don''t think so, seems fine to me. There was something else I was working on that was all already tabs but I don''t think it''s anything I touched here.> Ian.Thanks Gianni _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel