[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH v5 8/9] libxl: soft reset support
Perform soft reset when a domain did SHUTDOWN_soft_reset. Migrate the content with xc_domain_soft_reset(), reload dm and toolstack. Signed-off-by: Vitaly Kuznetsov <vkuznets@xxxxxxxxxx> --- docs/man/xl.cfg.pod.5 | 12 +++++ tools/libxl/libxl.h | 6 +++ tools/libxl/libxl_create.c | 103 +++++++++++++++++++++++++++++++++++++++---- tools/libxl/libxl_internal.h | 26 +++++++++++ tools/libxl/libxl_types.idl | 3 ++ tools/libxl/xl_cmdimpl.c | 35 ++++++++++++++- 6 files changed, 174 insertions(+), 11 deletions(-) diff --git a/docs/man/xl.cfg.pod.5 b/docs/man/xl.cfg.pod.5 index 622ea53..8b57643 100644 --- a/docs/man/xl.cfg.pod.5 +++ b/docs/man/xl.cfg.pod.5 @@ -306,6 +306,13 @@ destroy the domain. write a "coredump" of the domain to F</var/xen/dump/NAME> and then restart the domain. +=item B<soft-reset> + +create a new domain with the same configuration, reassign all the domain's +memory to this new domain, kill the original domain, and continue execution +of the new domain from where the action was triggered. Supported for HVM +guests only. + =back The default for C<on_poweroff> is C<destroy>. @@ -324,6 +331,11 @@ Default is C<destroy>. Action to take if the domain crashes. Default is C<destroy>. +=item B<on_soft_reset="ACTION"> + +Action to take if the domain performs 'soft reset' (e.g. does kexec). +Default is C<soft-reset>. + =back =head3 Direct Kernel Boot diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h index 0a123f1..710dc0e 100644 --- a/tools/libxl/libxl.h +++ b/tools/libxl/libxl.h @@ -929,6 +929,12 @@ int static inline libxl_domain_create_restore_0x040200( #endif +int libxl_domain_soft_reset(libxl_ctx *ctx, libxl_domain_config *d_config, + uint32_t *domid, uint32_t domid_old, + const libxl_asyncop_how *ao_how, + const libxl_asyncprogress_how *aop_console_how) + LIBXL_EXTERNAL_CALLERS_ONLY; + /* A progress report will be made via ao_console_how, of type * domain_create_console_available, when the domain's primary * console is available and can be connected to. diff --git a/tools/libxl/libxl_create.c b/tools/libxl/libxl_create.c index 1198225..0a840c9 100644 --- a/tools/libxl/libxl_create.c +++ b/tools/libxl/libxl_create.c @@ -25,6 +25,8 @@ #include <xen/hvm/hvm_info_table.h> #include <xen/hvm/e820.h> +#define INVALID_DOMID ~0 + int libxl__domain_create_info_setdefault(libxl__gc *gc, libxl_domain_create_info *c_info) { @@ -903,6 +905,9 @@ static void initiate_domain_create(libxl__egc *egc, if (restore_fd >= 0) { LOG(DEBUG, "restoring, not running bootloader"); domcreate_bootloader_done(egc, &dcs->bl, 0); + } else if (dcs->domid_soft_reset != INVALID_DOMID) { + LOG(DEBUG, "soft reset, not running bootloader\n"); + domcreate_bootloader_done(egc, &dcs->bl, 0); } else { LOG(DEBUG, "running bootloader"); dcs->bl.callback = domcreate_bootloader_done; @@ -951,6 +956,7 @@ static void domcreate_bootloader_done(libxl__egc *egc, libxl_domain_config *const d_config = dcs->guest_config; libxl_domain_build_info *const info = &d_config->b_info; const int restore_fd = dcs->restore_fd; + const uint32_t domid_soft_reset = dcs->domid_soft_reset; libxl__domain_build_state *const state = &dcs->build_state; libxl__srm_restore_autogen_callbacks *const callbacks = &dcs->shs.callbacks.restore.a; @@ -974,7 +980,7 @@ static void domcreate_bootloader_done(libxl__egc *egc, dcs->dmss.dm.callback = domcreate_devmodel_started; dcs->dmss.callback = domcreate_devmodel_started; - if ( restore_fd < 0 ) { + if ( (restore_fd < 0) && (domid_soft_reset == INVALID_DOMID) ) { rc = libxl__domain_build(gc, d_config, domid, state); domcreate_rebuild_done(egc, dcs, rc); return; @@ -1004,14 +1010,74 @@ static void domcreate_bootloader_done(libxl__egc *egc, rc = ERROR_INVAL; goto out; } - libxl__xc_domain_restore(egc, dcs, - hvm, pae, superpages); + if ( restore_fd >= 0 ) { + libxl__xc_domain_restore(egc, dcs, + hvm, pae, superpages); + } else { + libxl__xc_domain_soft_reset(egc, dcs); + } + return; out: libxl__xc_domain_restore_done(egc, dcs, rc, 0, 0); } +void libxl__xc_domain_soft_reset(libxl__egc *egc, + libxl__domain_create_state *dcs) +{ + STATE_AO_GC(dcs->ao); + libxl_ctx *ctx = libxl__gc_owner(gc); + const uint32_t domid_soft_reset = dcs->domid_soft_reset; + const uint32_t domid = dcs->guest_domid; + libxl_domain_config *const d_config = dcs->guest_config; + libxl_domain_build_info *const info = &d_config->b_info; + uint8_t *buf; + uint32_t len; + uint32_t console_domid, store_domid; + unsigned long store_mfn, console_mfn; + int rc; + struct libxl__domain_suspend_state *dss; + + GCNEW(dss); + + dss->ao = ao; + dss->domid = domid_soft_reset; + dss->dm_savefile = GCSPRINTF("/var/lib/xen/qemu-save.%d", + domid_soft_reset); + + if (info->type == LIBXL_DOMAIN_TYPE_HVM) { + rc = libxl__domain_suspend_device_model(gc, dss); + if (rc) goto out; + } + + console_domid = dcs->build_state.console_domid; + store_domid = dcs->build_state.store_domid; + + libxl__domain_soft_reset_destroy(gc, domid_soft_reset, 0); + + rc = xc_domain_soft_reset(ctx->xch, domid_soft_reset, domid, console_domid, + &console_mfn, store_domid, &store_mfn); + if (rc) goto out; + + libxl__qmp_cleanup(gc, domid_soft_reset); + + dcs->build_state.store_mfn = store_mfn; + dcs->build_state.console_mfn = console_mfn; + + rc = libxl__toolstack_save(domid_soft_reset, &buf, &len, dss); + if (rc) goto out; + + rc = libxl__toolstack_restore(domid, buf, len, &dcs->shs); + if (rc) goto out; +out: + /* + * Now pretend we did normal restore and simply call + * libxl__xc_domain_restore_done(). + */ + libxl__xc_domain_restore_done(egc, dcs, rc, 0, 0); +} + void libxl__srm_callout_callback_restore_results(unsigned long store_mfn, unsigned long console_mfn, void *user) { @@ -1037,6 +1103,7 @@ void libxl__xc_domain_restore_done(libxl__egc *egc, void *dcs_void, /* convenience aliases */ const uint32_t domid = dcs->guest_domid; + const uint32_t domid_soft_reset = dcs->domid_soft_reset; libxl_domain_config *const d_config = dcs->guest_config; libxl_domain_build_info *const info = &d_config->b_info; libxl__domain_build_state *const state = &dcs->build_state; @@ -1089,9 +1156,12 @@ void libxl__xc_domain_restore_done(libxl__egc *egc, void *dcs_void, if (ret) goto out; - if (info->type == LIBXL_DOMAIN_TYPE_HVM) { + if (info->type == LIBXL_DOMAIN_TYPE_HVM && fd != -1) { state->saved_state = GCSPRINTF( XC_DEVICE_MODEL_RESTORE_FILE".%d", domid); + } else if (domid_soft_reset != INVALID_DOMID) { + state->saved_state = GCSPRINTF( + "/var/lib/xen/qemu-save.%d", domid_soft_reset); } out: @@ -1100,9 +1170,12 @@ out: libxl__file_reference_unmap(&state->pv_ramdisk); } - esave = errno; - libxl_fd_set_nonblock(ctx, fd, 0); - errno = esave; + if ( fd != -1 ) { + esave = errno; + libxl_fd_set_nonblock(ctx, fd, 0); + errno = esave; + } + domcreate_rebuild_done(egc, dcs, ret); } @@ -1495,6 +1568,7 @@ static void domain_create_cb(libxl__egc *egc, static int do_domain_create(libxl_ctx *ctx, libxl_domain_config *d_config, uint32_t *domid, int restore_fd, int checkpointed_stream, + uint32_t domid_old, const libxl_asyncop_how *ao_how, const libxl_asyncprogress_how *aop_console_how) { @@ -1507,6 +1581,7 @@ static int do_domain_create(libxl_ctx *ctx, libxl_domain_config *d_config, libxl_domain_config_init(&cdcs->dcs.guest_config_saved); libxl_domain_config_copy(ctx, &cdcs->dcs.guest_config_saved, d_config); cdcs->dcs.restore_fd = restore_fd; + cdcs->dcs.domid_soft_reset = domid_old; cdcs->dcs.callback = domain_create_cb; cdcs->dcs.checkpointed_stream = checkpointed_stream; libxl__ao_progress_gethow(&cdcs->dcs.aop_console_how, aop_console_how); @@ -1535,7 +1610,7 @@ int libxl_domain_create_new(libxl_ctx *ctx, libxl_domain_config *d_config, const libxl_asyncop_how *ao_how, const libxl_asyncprogress_how *aop_console_how) { - return do_domain_create(ctx, d_config, domid, -1, 0, + return do_domain_create(ctx, d_config, domid, -1, 0, INVALID_DOMID, ao_how, aop_console_how); } @@ -1546,7 +1621,17 @@ int libxl_domain_create_restore(libxl_ctx *ctx, libxl_domain_config *d_config, const libxl_asyncprogress_how *aop_console_how) { return do_domain_create(ctx, d_config, domid, restore_fd, - params->checkpointed_stream, ao_how, aop_console_how); + params->checkpointed_stream, INVALID_DOMID, + ao_how, aop_console_how); +} + +int libxl_domain_soft_reset(libxl_ctx *ctx, libxl_domain_config *d_config, + uint32_t *domid, uint32_t domid_old, + const libxl_asyncop_how *ao_how, + const libxl_asyncprogress_how *aop_console_how) +{ + return do_domain_create(ctx, d_config, domid, -1, 0, domid_old, + ao_how, aop_console_how); } /* diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index d58f08a..b149c51 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -3069,6 +3069,7 @@ struct libxl__domain_create_state { libxl_domain_config *guest_config; libxl_domain_config guest_config_saved; /* vanilla config */ int restore_fd; + uint32_t domid_soft_reset; libxl__domain_create_cb *callback; libxl_asyncprogress_how aop_console_how; /* private to domain_create */ @@ -3133,6 +3134,31 @@ _hidden void libxl__domain_save_device_model(libxl__egc *egc, _hidden const char *libxl__device_model_savefile(libxl__gc *gc, uint32_t domid); +/* + * Soft reset is a special type of reset when the new domain is being built with + * the memory contents and vCPU contexts of the original domain thus allowing + * to continue execution from where the hypercall was done. This is supported + * for HVM domains only and is done as a modification for the domain create / + * restore path within xl: + * domcreate_bootloader_done() + * libxl__xc_domain_soft_reset() + * for the original domain: + * libxl__domain_suspend_device_model() + * libxl__domain_soft_reset_destroy() + * xc_domain_soft_reset() which saves HVM context and HVM params, calls + * XEN_DOMCTL_devour destroying the original domain and waiting till + * all memory migrates to the new domain, restoring HVM context and + * HVM params for the new domain + * for the new domain: + * libxl__toolstack_save() + * libxl__toolstack_restore() + * libxl__xc_domain_restore_done() and following the standard 'restore' + * path. + */ + +_hidden void libxl__xc_domain_soft_reset(libxl__egc *egc, + libxl__domain_create_state *dcs); + _hidden int libxl__domain_soft_reset_destroy(libxl__gc *gc, uint32_t domid, const libxl_asyncop_how *ao_how); diff --git a/tools/libxl/libxl_types.idl b/tools/libxl/libxl_types.idl index 4a0e2be..10ef652 100644 --- a/tools/libxl/libxl_types.idl +++ b/tools/libxl/libxl_types.idl @@ -121,6 +121,8 @@ libxl_action_on_shutdown = Enumeration("action_on_shutdown", [ (5, "COREDUMP_DESTROY"), (6, "COREDUMP_RESTART"), + + (7, "SOFT_RESET"), ], init_val = "LIBXL_ACTION_ON_SHUTDOWN_DESTROY") libxl_trigger = Enumeration("trigger", [ @@ -558,6 +560,7 @@ libxl_domain_config = Struct("domain_config", [ ("on_reboot", libxl_action_on_shutdown), ("on_watchdog", libxl_action_on_shutdown), ("on_crash", libxl_action_on_shutdown), + ("on_soft_reset", libxl_action_on_shutdown), ], dir=DIR_IN) libxl_diskinfo = Struct("diskinfo", [ diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c index b193c3c..d3ce409 100644 --- a/tools/libxl/xl_cmdimpl.c +++ b/tools/libxl/xl_cmdimpl.c @@ -130,6 +130,8 @@ static const char *action_on_shutdown_names[] = { [LIBXL_ACTION_ON_SHUTDOWN_COREDUMP_DESTROY] = "coredump-destroy", [LIBXL_ACTION_ON_SHUTDOWN_COREDUMP_RESTART] = "coredump-restart", + + [LIBXL_ACTION_ON_SHUTDOWN_SOFT_RESET] = "soft-reset", }; /* Optional data, in order: @@ -1067,6 +1069,13 @@ static void parse_config_data(const char *config_source, exit(1); } + if (xlu_cfg_get_string (config, "on_soft_reset", &buf, 0)) + buf = "soft-reset"; + if (!parse_action_on_shutdown(buf, &d_config->on_soft_reset)) { + fprintf(stderr, "Unknown on_soft_reset action \"%s\" specified\n", buf); + exit(1); + } + /* libxl_get_required_shadow_memory() must be called after final values * (default or specified) for vcpus and memory are set, because the * calculation depends on those values. */ @@ -2052,7 +2061,8 @@ static void reload_domain_config(uint32_t domid, } /* Returns 1 if domain should be restarted, - * 2 if domain should be renamed then restarted, or 0 + * 2 if domain should be renamed then restarted, + * 3 if domain performed soft reset, or 0 * Can update r_domid if domain is destroyed etc */ static int handle_domain_death(uint32_t *r_domid, libxl_event *event, @@ -2078,6 +2088,9 @@ static int handle_domain_death(uint32_t *r_domid, case LIBXL_SHUTDOWN_REASON_WATCHDOG: action = d_config->on_watchdog; break; + case LIBXL_SHUTDOWN_REASON_SOFT_RESET: + action = d_config->on_soft_reset; + break; default: LOG("Unknown shutdown reason code %d. Destroying domain.", event->u.domain_shutdown.shutdown_reason); @@ -2128,6 +2141,11 @@ static int handle_domain_death(uint32_t *r_domid, *r_domid = INVALID_DOMID; break; + case LIBXL_ACTION_ON_SHUTDOWN_SOFT_RESET: + reload_domain_config(*r_domid, d_config); + restart = 3; + break; + case LIBXL_ACTION_ON_SHUTDOWN_COREDUMP_DESTROY: case LIBXL_ACTION_ON_SHUTDOWN_COREDUMP_RESTART: /* Already handled these above. */ @@ -2294,6 +2312,7 @@ static void evdisable_disk_ejects(libxl_evgen_disk_eject **diskws, static uint32_t create_domain(struct domain_create *dom_info) { uint32_t domid = INVALID_DOMID; + uint32_t domid_old = INVALID_DOMID; libxl_domain_config d_config; @@ -2519,7 +2538,17 @@ start: * restore/migrate-receive it again. */ restoring = 0; - }else{ + } else if (domid_old != INVALID_DOMID) { + /* Do soft reset */ + ret = libxl_domain_soft_reset(ctx, &d_config, + &domid, domid_old, + 0, 0); + + if ( ret ) { + goto error_out; + } + domid_old = INVALID_DOMID; + } else { ret = libxl_domain_create_new(ctx, &d_config, &domid, 0, autoconnect_console_how); } @@ -2583,6 +2612,8 @@ start: event->u.domain_shutdown.shutdown_reason, event->u.domain_shutdown.shutdown_reason); switch (handle_domain_death(&domid, event, &d_config)) { + case 3: + domid_old = domid; case 2: if (!preserve_domain(&domid, event, &d_config)) { /* If we fail then exit leaving the old domain in place. */ -- 1.9.3 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx http://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |