[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH v1 3/5] tools/libxl: move remus codes into libxl_remus.c
move remus codes into libxl_remus.c Signed-off-by: Yang Hongyang <yanghy@xxxxxxxxxxxxxx> CC: Ian Campbell <Ian.Campbell@xxxxxxxxxx> CC: Ian Jackson <Ian.Jackson@xxxxxxxxxxxxx> CC: Wei Liu <wei.liu2@xxxxxxxxxx> CC: Andrew Cooper <andrew.cooper3@xxxxxxxxxx> --- tools/libxl/Makefile | 2 +- tools/libxl/libxl.c | 55 +------- tools/libxl/libxl_dom.c | 223 ++----------------------------- tools/libxl/libxl_internal.h | 11 ++ tools/libxl/libxl_remus.c | 306 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 327 insertions(+), 270 deletions(-) create mode 100644 tools/libxl/libxl_remus.c diff --git a/tools/libxl/Makefile b/tools/libxl/Makefile index 21558b0..a9abdbc 100644 --- a/tools/libxl/Makefile +++ b/tools/libxl/Makefile @@ -56,7 +56,7 @@ else LIBXL_OBJS-y += libxl_nonetbuffer.o endif -LIBXL_OBJS-y += libxl_remus_device.o libxl_remus_disk_drbd.o +LIBXL_OBJS-y += libxl_remus.o libxl_remus_device.o libxl_remus_disk_drbd.o LIBXL_OBJS-$(CONFIG_X86) += libxl_cpuid.o libxl_x86.o libxl_psr.o LIBXL_OBJS-$(CONFIG_ARM) += libxl_nocpuid.o libxl_arm.o diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c index 7259061..43a4b88 100644 --- a/tools/libxl/libxl.c +++ b/tools/libxl/libxl.c @@ -825,10 +825,6 @@ out: return ptr; } -static void libxl__remus_setup_done(libxl__egc *egc, - libxl__remus_devices_state *rds, int rc); -static void libxl__remus_setup_failed(libxl__egc *egc, - libxl__remus_devices_state *rds, int rc); static void remus_failover_cb(libxl__egc *egc, libxl__domain_save_state *dss, int rc); @@ -877,63 +873,14 @@ int libxl_domain_remus_start(libxl_ctx *ctx, libxl_domain_remus_info *info, assert(info); - /* Convenience aliases */ - libxl__remus_devices_state *const rds = &dss->rds; - - if (libxl_defbool_val(info->netbuf)) { - if (!libxl__netbuffer_enabled(gc)) { - LOG(ERROR, "Remus: No support for network buffering"); - rc = ERROR_FAIL; - goto out; - } - rds->device_kind_flags |= (1 << LIBXL__DEVICE_KIND_VIF); - } - - if (libxl_defbool_val(info->diskbuf)) - rds->device_kind_flags |= (1 << LIBXL__DEVICE_KIND_VBD); - - rds->ao = ao; - rds->domid = domid; - rds->callback = libxl__remus_setup_done; - /* Point of no return */ - libxl__remus_devices_setup(egc, rds); + libxl__remus_setup(egc, dss); return AO_INPROGRESS; out: return AO_ABORT(rc); } -static void libxl__remus_setup_done(libxl__egc *egc, - libxl__remus_devices_state *rds, int rc) -{ - libxl__domain_save_state *dss = CONTAINER_OF(rds, *dss, rds); - STATE_AO_GC(dss->ao); - - if (!rc) { - libxl__domain_save(egc, dss); - return; - } - - LOG(ERROR, "Remus: failed to setup device for guest with domid %u, rc %d", - dss->domid, rc); - rds->callback = libxl__remus_setup_failed; - libxl__remus_devices_teardown(egc, rds); -} - -static void libxl__remus_setup_failed(libxl__egc *egc, - libxl__remus_devices_state *rds, int rc) -{ - libxl__domain_save_state *dss = CONTAINER_OF(rds, *dss, rds); - STATE_AO_GC(dss->ao); - - if (rc) - LOG(ERROR, "Remus: failed to teardown device after setup failed" - " for guest with domid %u, rc %d", dss->domid, rc); - - dss->callback(egc, dss, rc); -} - static void remus_failover_cb(libxl__egc *egc, libxl__domain_save_state *dss, int rc) { diff --git a/tools/libxl/libxl_dom.c b/tools/libxl/libxl_dom.c index 1681a12..b937d99 100644 --- a/tools/libxl/libxl_dom.c +++ b/tools/libxl/libxl_dom.c @@ -1405,192 +1405,6 @@ int libxl__toolstack_save(uint32_t domid, uint8_t **buf, return 0; } -/*----- remus callbacks -----*/ -static void remus_domain_suspend_callback_common_done(libxl__egc *egc, - libxl__domain_suspend_state *dss, int ok); -static void remus_devices_postsuspend_cb(libxl__egc *egc, - libxl__remus_devices_state *rds, - int rc); -static void remus_devices_preresume_cb(libxl__egc *egc, - libxl__remus_devices_state *rds, - int rc); - -static void libxl__remus_domain_suspend_callback(void *data) -{ - libxl__save_helper_state *shs = data; - libxl__egc *egc = shs->egc; - libxl__domain_save_state *dss = CONTAINER_OF(shs, *dss, shs); - libxl__domain_suspend_state *dss2 = &dss->dss; - - dss2->callback_common_done = remus_domain_suspend_callback_common_done; - libxl__domain_suspend(egc, dss2); -} - -static void remus_domain_suspend_callback_common_done(libxl__egc *egc, - libxl__domain_suspend_state *dss, int ok) -{ - libxl__domain_save_state *dsvs = CONTAINER_OF(dss, *dsvs, dss); - - if (!ok) - goto out; - - libxl__remus_devices_state *const rds = &dsvs->rds; - rds->callback = remus_devices_postsuspend_cb; - libxl__remus_devices_postsuspend(egc, rds); - return; - -out: - libxl__xc_domain_saverestore_async_callback_done(egc, &dsvs->shs, ok); -} - -static void remus_devices_postsuspend_cb(libxl__egc *egc, - libxl__remus_devices_state *rds, - int rc) -{ - int ok = 0; - libxl__domain_save_state *dss = CONTAINER_OF(rds, *dss, rds); - - if (rc) - goto out; - - ok = 1; - -out: - libxl__xc_domain_saverestore_async_callback_done(egc, &dss->shs, ok); -} - -static void libxl__remus_domain_resume_callback(void *data) -{ - libxl__save_helper_state *shs = data; - libxl__egc *egc = shs->egc; - libxl__domain_save_state *dss = CONTAINER_OF(shs, *dss, shs); - STATE_AO_GC(dss->ao); - - libxl__remus_devices_state *const rds = &dss->rds; - rds->callback = remus_devices_preresume_cb; - libxl__remus_devices_preresume(egc, rds); -} - -static void remus_devices_preresume_cb(libxl__egc *egc, - libxl__remus_devices_state *rds, - int rc) -{ - int ok = 0; - libxl__domain_save_state *dss = CONTAINER_OF(rds, *dss, rds); - STATE_AO_GC(dss->ao); - - if (rc) - goto out; - - /* Resumes the domain and the device model */ - rc = libxl__domain_resume(gc, dss->domid, /* Fast Suspend */1); - if (rc) - goto out; - - ok = 1; - -out: - libxl__xc_domain_saverestore_async_callback_done(egc, &dss->shs, ok); -} - -/*----- remus asynchronous checkpoint callback -----*/ - -static void remus_checkpoint_dm_saved(libxl__egc *egc, - libxl__domain_save_state *dss, int rc); -static void remus_devices_commit_cb(libxl__egc *egc, - libxl__remus_devices_state *rds, - int rc); -static void remus_next_checkpoint(libxl__egc *egc, libxl__ev_time *ev, - const struct timeval *requested_abs); - -static void libxl__remus_domain_checkpoint_callback(void *data) -{ - libxl__save_helper_state *shs = data; - libxl__domain_save_state *dss = CONTAINER_OF(shs, *dss, shs); - libxl__egc *egc = dss->shs.egc; - STATE_AO_GC(dss->ao); - - /* This would go into tailbuf. */ - if (dss->hvm) { - libxl__domain_save_device_model(egc, dss, remus_checkpoint_dm_saved); - } else { - remus_checkpoint_dm_saved(egc, dss, 0); - } -} - -static void remus_checkpoint_dm_saved(libxl__egc *egc, - libxl__domain_save_state *dss, int rc) -{ - /* Convenience aliases */ - libxl__remus_devices_state *const rds = &dss->rds; - - STATE_AO_GC(dss->ao); - - if (rc) { - LOG(ERROR, "Failed to save device model. Terminating Remus.."); - goto out; - } - - rds->callback = remus_devices_commit_cb; - libxl__remus_devices_commit(egc, rds); - - return; - -out: - libxl__xc_domain_saverestore_async_callback_done(egc, &dss->shs, 0); -} - -static void remus_devices_commit_cb(libxl__egc *egc, - libxl__remus_devices_state *rds, - int rc) -{ - libxl__domain_save_state *dss = CONTAINER_OF(rds, *dss, rds); - - STATE_AO_GC(dss->ao); - - if (rc) { - LOG(ERROR, "Failed to do device commit op." - " Terminating Remus.."); - goto out; - } - - /* - * At this point, we have successfully checkpointed the guest and - * committed it at the backup. We'll come back after the checkpoint - * interval to checkpoint the guest again. Until then, let the guest - * continue execution. - */ - - /* Set checkpoint interval timeout */ - rc = libxl__ev_time_register_rel(gc, &dss->checkpoint_timeout, - remus_next_checkpoint, - dss->interval); - - if (rc) - goto out; - - return; - -out: - libxl__xc_domain_saverestore_async_callback_done(egc, &dss->shs, 0); -} - -static void remus_next_checkpoint(libxl__egc *egc, libxl__ev_time *ev, - const struct timeval *requested_abs) -{ - libxl__domain_save_state *dss = - CONTAINER_OF(ev, *dss, checkpoint_timeout); - - STATE_AO_GC(dss->ao); - - /* - * Time to checkpoint the guest again. We return 1 to libxc - * (xc_domain_save.c). in order to continue executing the infinite loop - * (suspend, checkpoint, resume) in xc_domain_save(). - */ - libxl__xc_domain_saverestore_async_callback_done(egc, &dss->shs, 1); -} - /*----- main code for saving, in order of execution -----*/ static void domain_save_done(libxl__egc *egc, @@ -1816,10 +1630,6 @@ static void save_device_model_datacopier_done(libxl__egc *egc, dss->save_dm_callback(egc, dss, our_rc); } -static void remus_teardown_done(libxl__egc *egc, - libxl__remus_devices_state *rds, - int rc); - static void domain_save_done(libxl__egc *egc, libxl__domain_save_state *dss, int rc) { @@ -1835,34 +1645,17 @@ static void domain_save_done(libxl__egc *egc, xc_suspend_evtchn_release(CTX->xch, CTX->xce, domid, dss2->guest_evtchn.port, &dss2->guest_evtchn_lockfd); - if (!dss->remus) { - dss->callback(egc, dss, rc); + if (dss->remus) { + /* + * With Remus, if we reach this point, it means either + * backup died or some network error occurred preventing us + * from sending checkpoints. Teardown the network buffers and + * release netlink resources. This is an async op. + */ + libxl__remus_teardown(egc, dss, rc); return; } - /* - * With Remus, if we reach this point, it means either - * backup died or some network error occurred preventing us - * from sending checkpoints. Teardown the network buffers and - * release netlink resources. This is an async op. - */ - LOG(WARN, "Remus: Domain suspend terminated with rc %d," - " teardown Remus devices...", rc); - dss->rds.callback = remus_teardown_done; - libxl__remus_devices_teardown(egc, &dss->rds); -} - -static void remus_teardown_done(libxl__egc *egc, - libxl__remus_devices_state *rds, - int rc) -{ - libxl__domain_save_state *dss = CONTAINER_OF(rds, *dss, rds); - STATE_AO_GC(dss->ao); - - if (rc) - LOG(ERROR, "Remus: failed to teardown device for guest with domid %u," - " rc %d", dss->domid, rc); - dss->callback(egc, dss, rc); } diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index b2eeb89..c3d70eb 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -2815,6 +2815,7 @@ _hidden void libxl__remus_devices_commit(libxl__egc *egc, libxl__remus_devices_state *rds); _hidden int libxl__netbuffer_enabled(libxl__gc *gc); + /*----- Domain suspend (save) state structure -----*/ typedef struct libxl__domain_suspend_state libxl__domain_suspend_state; @@ -3197,6 +3198,16 @@ void libxl__domain_suspend_callback(void *data); void libxl__domain_suspend(libxl__egc *egc, libxl__domain_suspend_state *dss); +/* Remus callbacks for save */ +void libxl__remus_domain_suspend_callback(void *data); +void libxl__remus_domain_resume_callback(void *data); +void libxl__remus_domain_checkpoint_callback(void *data); +/* Remus setup and teardown*/ +void libxl__remus_setup(libxl__egc *egc, libxl__domain_save_state *dss); +void libxl__remus_teardown(libxl__egc *egc, + libxl__domain_save_state *dss, + int rc); + /* * Convenience macros. diff --git a/tools/libxl/libxl_remus.c b/tools/libxl/libxl_remus.c new file mode 100644 index 0000000..7eb21e7 --- /dev/null +++ b/tools/libxl/libxl_remus.c @@ -0,0 +1,306 @@ +/* + * Copyright (C) 2015 FUJITSU LIMITED + * Author: Yang Hongyang <yanghy@xxxxxxxxxxxxxx> + * + * 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 and later. 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" /* must come before any other headers */ + +#include "libxl_internal.h" + +/*----- Remus setup and teardown -----*/ + +static void libxl_remus_setup_done(libxl__egc *egc, + libxl__remus_devices_state *rds, int rc); +static void libxl_remus_setup_failed(libxl__egc *egc, + libxl__remus_devices_state *rds, int rc); +void libxl__remus_setup(libxl__egc *egc, libxl__domain_save_state *dss) +{ + /* Convenience aliases */ + libxl__remus_devices_state *const rds = &dss->rds; + const libxl_domain_remus_info *const info = dss->remus; + + STATE_AO_GC(dss->ao); + + if (libxl_defbool_val(info->netbuf)) { + if (!libxl__netbuffer_enabled(gc)) { + LOG(ERROR, "Remus: No support for network buffering"); + goto out; + } + rds->device_kind_flags |= (1 << LIBXL__DEVICE_KIND_VIF); + } + + if (libxl_defbool_val(info->diskbuf)) + rds->device_kind_flags |= (1 << LIBXL__DEVICE_KIND_VBD); + + rds->ao = ao; + rds->domid = dss->domid; + rds->callback = libxl_remus_setup_done; + + libxl__remus_devices_setup(egc, rds); + return; + +out: + libxl_remus_setup_failed(egc, rds, ERROR_FAIL); +} + +static void libxl_remus_setup_done(libxl__egc *egc, + libxl__remus_devices_state *rds, int rc) +{ + libxl__domain_save_state *dss = CONTAINER_OF(rds, *dss, rds); + STATE_AO_GC(dss->ao); + + if (!rc) { + libxl__domain_save(egc, dss); + return; + } + + LOG(ERROR, "Remus: failed to setup device for guest with domid %u, rc %d", + dss->domid, rc); + rds->callback = libxl_remus_setup_failed; + libxl__remus_devices_teardown(egc, rds); +} + +static void libxl_remus_setup_failed(libxl__egc *egc, + libxl__remus_devices_state *rds, int rc) +{ + libxl__domain_save_state *dss = CONTAINER_OF(rds, *dss, rds); + STATE_AO_GC(dss->ao); + + if (rc) + LOG(ERROR, "Remus: failed to teardown device after setup failed" + " for guest with domid %u, rc %d", dss->domid, rc); + + dss->callback(egc, dss, rc); +} + +static void remus_teardown_done(libxl__egc *egc, + libxl__remus_devices_state *rds, + int rc); +void libxl__remus_teardown(libxl__egc *egc, + libxl__domain_save_state *dss, + int rc) +{ + EGC_GC; + + LOG(WARN, "Remus: Domain suspend terminated with rc %d," + " teardown Remus devices...", rc); + dss->rds.callback = remus_teardown_done; + libxl__remus_devices_teardown(egc, &dss->rds); +} + +static void remus_teardown_done(libxl__egc *egc, + libxl__remus_devices_state *rds, + int rc) +{ + libxl__domain_save_state *dss = CONTAINER_OF(rds, *dss, rds); + STATE_AO_GC(dss->ao); + + if (rc) + LOG(ERROR, "Remus: failed to teardown device for guest with domid %u," + " rc %d", dss->domid, rc); + + dss->callback(egc, dss, rc); +} + +/*----- remus callbacks -----*/ +static void remus_domain_suspend_callback_common_done(libxl__egc *egc, + libxl__domain_suspend_state *dss, int ok); +static void remus_devices_postsuspend_cb(libxl__egc *egc, + libxl__remus_devices_state *rds, + int rc); +static void remus_devices_preresume_cb(libxl__egc *egc, + libxl__remus_devices_state *rds, + int rc); + +void libxl__remus_domain_suspend_callback(void *data) +{ + libxl__save_helper_state *shs = data; + libxl__egc *egc = shs->egc; + libxl__domain_save_state *dss = CONTAINER_OF(shs, *dss, shs); + libxl__domain_suspend_state *dss2 = &dss->dss; + + dss2->callback_common_done = remus_domain_suspend_callback_common_done; + libxl__domain_suspend(egc, dss2); +} + +static void remus_domain_suspend_callback_common_done(libxl__egc *egc, + libxl__domain_suspend_state *dss, int ok) +{ + libxl__domain_save_state *dsvs = CONTAINER_OF(dss, *dsvs, dss); + + if (!ok) + goto out; + + libxl__remus_devices_state *const rds = &dsvs->rds; + rds->callback = remus_devices_postsuspend_cb; + libxl__remus_devices_postsuspend(egc, rds); + return; + +out: + libxl__xc_domain_saverestore_async_callback_done(egc, &dsvs->shs, ok); +} + +static void remus_devices_postsuspend_cb(libxl__egc *egc, + libxl__remus_devices_state *rds, + int rc) +{ + int ok = 0; + libxl__domain_save_state *dss = CONTAINER_OF(rds, *dss, rds); + + if (rc) + goto out; + + ok = 1; + +out: + libxl__xc_domain_saverestore_async_callback_done(egc, &dss->shs, ok); +} + +void libxl__remus_domain_resume_callback(void *data) +{ + libxl__save_helper_state *shs = data; + libxl__egc *egc = shs->egc; + libxl__domain_save_state *dss = CONTAINER_OF(shs, *dss, shs); + STATE_AO_GC(dss->ao); + + libxl__remus_devices_state *const rds = &dss->rds; + rds->callback = remus_devices_preresume_cb; + libxl__remus_devices_preresume(egc, rds); +} + +static void remus_devices_preresume_cb(libxl__egc *egc, + libxl__remus_devices_state *rds, + int rc) +{ + int ok = 0; + libxl__domain_save_state *dss = CONTAINER_OF(rds, *dss, rds); + STATE_AO_GC(dss->ao); + + if (rc) + goto out; + + /* Resumes the domain and the device model */ + rc = libxl__domain_resume(gc, dss->domid, /* Fast Suspend */1); + if (rc) + goto out; + + ok = 1; + +out: + libxl__xc_domain_saverestore_async_callback_done(egc, &dss->shs, ok); +} + +/*----- remus asynchronous checkpoint callback -----*/ + +static void remus_checkpoint_dm_saved(libxl__egc *egc, + libxl__domain_save_state *dss, int rc); +static void remus_devices_commit_cb(libxl__egc *egc, + libxl__remus_devices_state *rds, + int rc); +static void remus_next_checkpoint(libxl__egc *egc, libxl__ev_time *ev, + const struct timeval *requested_abs); + +void libxl__remus_domain_checkpoint_callback(void *data) +{ + libxl__save_helper_state *shs = data; + libxl__domain_save_state *dss = CONTAINER_OF(shs, *dss, shs); + libxl__egc *egc = dss->shs.egc; + STATE_AO_GC(dss->ao); + + /* This would go into tailbuf. */ + if (dss->hvm) { + libxl__domain_save_device_model(egc, dss, remus_checkpoint_dm_saved); + } else { + remus_checkpoint_dm_saved(egc, dss, 0); + } +} + +static void remus_checkpoint_dm_saved(libxl__egc *egc, + libxl__domain_save_state *dss, int rc) +{ + /* Convenience aliases */ + libxl__remus_devices_state *const rds = &dss->rds; + + STATE_AO_GC(dss->ao); + + if (rc) { + LOG(ERROR, "Failed to save device model. Terminating Remus.."); + goto out; + } + + rds->callback = remus_devices_commit_cb; + libxl__remus_devices_commit(egc, rds); + + return; + +out: + libxl__xc_domain_saverestore_async_callback_done(egc, &dss->shs, 0); +} + +static void remus_devices_commit_cb(libxl__egc *egc, + libxl__remus_devices_state *rds, + int rc) +{ + libxl__domain_save_state *dss = CONTAINER_OF(rds, *dss, rds); + + STATE_AO_GC(dss->ao); + + if (rc) { + LOG(ERROR, "Failed to do device commit op." + " Terminating Remus.."); + goto out; + } + + /* + * At this point, we have successfully checkpointed the guest and + * committed it at the backup. We'll come back after the checkpoint + * interval to checkpoint the guest again. Until then, let the guest + * continue execution. + */ + + /* Set checkpoint interval timeout */ + rc = libxl__ev_time_register_rel(gc, &dss->checkpoint_timeout, + remus_next_checkpoint, + dss->interval); + + if (rc) + goto out; + + return; + +out: + libxl__xc_domain_saverestore_async_callback_done(egc, &dss->shs, 0); +} + +static void remus_next_checkpoint(libxl__egc *egc, libxl__ev_time *ev, + const struct timeval *requested_abs) +{ + libxl__domain_save_state *dss = + CONTAINER_OF(ev, *dss, checkpoint_timeout); + + STATE_AO_GC(dss->ao); + + /* + * Time to checkpoint the guest again. We return 1 to libxc + * (xc_domain_save.c). in order to continue executing the infinite loop + * (suspend, checkpoint, resume) in xc_domain_save(). + */ + libxl__xc_domain_saverestore_async_callback_done(egc, &dss->shs, 1); +} +/* + * Local variables: + * mode: C + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ -- 1.9.1 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx http://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |