Remus/Libxl: Network buffering support
PATCH v4 1/1 Remus/Libxl: Network buffering support
This patch series adds support for network buffering in the Remus codebase in libxl and makes the suspend callback asynchronous.
I have tested the series with PV guests (with and without suspend event channel). Would appreciate if anyone could test the series with PV-HVM guests and pure HVM guests.
Changes in V4:
[1/7] *new*. This Ian Jackson's patch -- making
libxl__domain_suspend_callback asynchronous
[2/7] [was 1/5 in previous versions] Remove check for libnl
command line utils
[3/7] [was 2/5 previously] minor nits
[4/7] [was 3/5 previously] define LIBXL_HAVE_REMUS_NETBUF
in libxl.h
[5/7] [was 4/5 previously] clean ups. Make the usleep in checkpoint
callback asynchronous
[6/7] [was 5/5 previously] minor nits
[7/7] *new*. Refactor libxl__domain_suspend_common_callback to
substitute usleep based wait loops with libxl's timer events.
Changes in V3:
[1/5] Fix redundant checks in configure scripts
(based on Ian Campbell's suggestions)
[2/5] Introduce locking in the script, during IFB setup.
Add xenstore paths used by netbuf scripts to xenstore-paths.markdown
[3/5] Hotplug scripts setup/teardown invocations are now asynchronous
following IanJ's feedback. However, the invocations are still sequential.
[5/5] Allow per-domain specification of netbuffer scripts in xl remus
commmand.
And minor nits throughout the series based on feedback from the last version
Changes in V2:
[1/5] Configure script will automatically enable/disable network
buffer support depending on the availability of the appropriate libnl3 version. [If libnl3 is unavailable, a warning message will be printed to let the user know that the feature has been disabled.]
use macros from pkg.m4 instead of pkg-config commands removed redundant checks for libnl3 libraries.
[3,4/5] - Minor nits.
Version 1:
[1/5] Changes to autoconf scripts to check for libnl3. Add linker flags
to libxl Makefile.
[2/5] External script to setup/teardown network buffering using libnl3's
CLI. This script will be invoked by libxl before starting Remus. The script's main job is to bring up an IFB device with plug qdisc attached to it. It then re-routes egress traffic from the guest's vif to the IFB device.
[3/5] Libxl code to invoke the external setup script, followed by netlink
related setup to obtain a handle on the output buffers attached to each vif.
[4/5] Libxl interaction with network buffer module in the kernel via
libnl3 API.
[5/5] xl cmdline switch to explicitly enable network buffering when
starting remus.
Few things to note:
a) Based on previous email discussions, the setup/teardown task has been moved to a hotplug style shell script which can be customized as desired, instead of implementing it as C code inside libxl.
b) Libnl3 is not available on NetBSD. Nor is it available on CentOS
(Linux). So I have made network buffering support an optional feature so that it can be disabled if desired.
c) NetBSD does not have libnl3. So I have put the setup script under tools/hotplug/Linux folder.
thanks
shriram
PATCH v4 1/1 libxl: make libxl__domain_suspend_callback be asynchronous
# HG changeset patch
# User Ian Jackson <[email protected]>
# Date 1384374958 28800
# Node ID 3143bed377a08bb9e87c7636e004dc371bb20338
# Parent b90864157a670771462fb05918b0829889dde86c [PATCH] libxl: make libxl__domain_suspend_callback be asynchronous
Date: Mon, 4 Nov 2013 16:27:53 +0000
Mark the suspend callback as asynchronous in the helper stub generator (libxl_save_msgs_gen.pl). Remus is going to want to provide an asynchronous version of this function.
libxl__domain_suspend_common_callback, the common synchronous core, which used to be provided directly as the callback function for the helper machinery, becomes libxl__domain_suspend_callback_common. It can now take a typesafe parameter.
For now, provide two very similar asynchronous wrappers for it. Each is a simple function which contains only boilerplate, calls the common synchronous core, and returns the asynchronous response.
Essentially, we have just moved (in the case of suspend callbacks) the call site of libxl__srm_callout_callback_complete. It was in the switch statement in the autogenerated _libxl_save_msgs_callout.c, and is now in the handwritten libxl_dom.c.
No functional change.
--- tools/libxl/libxl_dom.c | 25 +++++++++++++++++++------ tools/libxl/libxl_internal.h | 2 +- tools/libxl/libxl_save_msgs_gen.pl | 2 +- 3 files changed, 21 insertions(+), 8 deletions(-)
tools/libxl/libxl_dom.c +19 -6
@@ -1003,10 +1003,8 @@ int libxl__domain_resume_device_model(lireturn 0 ; } -int libxl__domain_suspend_common_callback (void *user) +int libxl__domain_suspend_callback_common (libxl__domain_suspend_state *dss) { -libxl__save_helper_state *shs = user; -libxl__domain_suspend_state *dss =CONTAINER_OF (shs, *dss, shs);STATE_AO_GC (dss->ao);unsigned long hvm_s_state =0 , hvm_pvdrv =0 ;int ret;
@@ -1225,12 +1223,27 @@ int libxl__toolstack_save(uint32_t domidreturn 0 ; } +static void libxl__domain_suspend_callback (void *data) +{ +libxl__save_helper_state *shs = data; +libxl__egc *egc = shs->egc; +libxl__domain_suspend_state *dss =CONTAINER_OF (shs, *dss, shs); + +int ok =libxl__domain_suspend_callback_common (dss); +libxl__xc_domain_saverestore_async_callback_done (egc, shs, ok); +} +/*----- remus callbacks -----*/ -static int libxl__remus_domain_suspend_callback (void *data) +static void libxl__remus_domain_suspend_callback (void *data) { +libxl__save_helper_state *shs = data; +libxl__egc *egc = shs->egc; +libxl__domain_suspend_state *dss =CONTAINER_OF (shs, *dss, shs); +/* REMUS TODO: Issue disk and network checkpoint reqs. */ -return libxl__domain_suspend_common_callback (data); +int ok =libxl__domain_suspend_callback_common (dss); +libxl__xc_domain_saverestore_async_callback_done (egc, shs, ok); }static int libxl__remus_domain_resume_callback (void *data)
@@ -1354,7 +1367,7 @@ void libxl__domain_suspend(libxl__egc *e callbacks->postcopy = libxl__remus_domain_resume_callback; callbacks->checkpoint = libxl__remus_domain_checkpoint_callback; }else - callbacks->suspend = libxl__domain_suspend_common_callback; + callbacks->suspend = libxl__domain_suspend_callback; callbacks->switch_qemu_logdirty = libxl__domain_suspend_common_switch_qemu_logdirty; dss->shs.callbacks.save.toolstack_save = libxl__toolstack_save;
tools/libxl/libxl_internal.h +1 -1
@@ -2597,7 +2597,7 @@ _hidden void libxl__xc_domain_save_done(void libxl__xc_domain_saverestore_async_callback_done (libxl__egc *egc,libxl__save_helper_state *shs,int return_value); -_hidden int libxl__domain_suspend_common_callback(void *data); +_hidden int libxl__domain_suspend_callback_common(libxl__domain_suspend_state*); _hidden void libxl__domain_suspend_common_switch_qemu_logdirty (int domid,unsigned int enable,void *data); _hidden int libxl__toolstack_save(uint32_t domid, uint8_t **buf,
tools/libxl/libxl_save_msgs_gen.pl +1 -1
@@ -23,7 +23,7 @@ our @msgs = ( STRING doing_what), 'unsigned long', 'done', 'unsigned long', 'total'] ], - [ 3, 'scxW', "suspend", [] ], + [ 3, 'scxA', "suspend", [] ], [ 4, 'scxW', "postcopy", [] ], [ 5, 'scxA', "checkpoint", [] ], [ 6, 'scxA', "switch_qemu_logdirty", [qw(int domid
PATCH v4 1/1 remus: add libnl3 dependency to autoconf scripts
In reply to Shriram Rajagopalan# HG changeset patch
# User Shriram Rajagopalan <[email protected]> # Date 1384492673 28800
# Node ID f14fb4982ec89b30c04c6f4684de5056450c27a0 # Parent 3143bed377a08bb9e87c7636e004dc371bb20338
remus: add libnl3 dependency to autoconf scripts
Libnl3 is required for controlling Remus network buffering. This patch adds dependency on libnl3 (>= 3.2.8) to autoconf scripts. Also provide ability to configure tools without libnl3 support, that is without network buffering support.
README +4 -0
@@ -71,6 +71,10 @@ disabled at compile time: includes the alternative ocaml xenstored. * cmake (if building vtpm stub domains) * markdown + * Development install of libnl3 (e.g., libnl-3-200, + libnl-3-dev, etc). Required if network buffering is desired + when using Remus with libxl. See tools/remus/README for detailed + information. Second, you need to acquire a suitable kernel for use in domain 0. If possible you should use a kernel provided by your OS distributor. If
config/Tools.mk.in +3 -0
@@ -38,6 +38,8 @@ PTHREAD_LIBS := @PTHREAD_LIBS@ PTYFUNCS_LIBS := @PTYFUNCS_LIBS@ +LIBNL3_LIBS := @LIBNL3_LIBS@ +LIBNL3_CFLAGS := @LIBNL3_CFLAGS@ # Download GIT repositories via HTTP or GIT's own protocol? # GIT's protocol is faster and more robust, when it works at all (firewalls # may block it). We make it the default, but if your GIT repository downloads
@@ -56,6 +58,7 @@ CONFIG_QEMU_TRAD := @qemu_traditional CONFIG_QEMU_XEN := @qemu_xen@ CONFIG_XEND := @xend@ CONFIG_BLKTAP1 := @blktap1@ +CONFIG_REMUS_NETBUF := @remus_netbuf@ #System options ZLIB := @zlib@
tools/configure.ac +15 -0
@@ -230,6 +230,21 @@ AC_SUBST(libiconv) # Checks for header files. AC_CHECK_HEADERS([yajl/yajl_version.h sys/eventfd.h]) +# Check for libnl3 >=3.2.8. If present enable remus network buffering. +PKG_CHECK_MODULES(LIBNL3, [libnl-3.0 >= 3.2.8 libnl-route-3.0 >= 3.2.8], + [libnl3_lib="y"], [libnl3_lib="n"]) + +AS_IF([test "x$libnl3_lib" = "xn" ], [ + AC_MSG_WARN([Disabling support for Remus network buffering. + Please install libnl3 libraries, command line tools and devel + headers - version 3.2.8 or higher]) + AC_SUBST(remus_netbuf, [n]) + ],[ + AC_SUBST(LIBNL3_LIBS) + AC_SUBST(LIBNL3_CFLAGS) + AC_SUBST(remus_netbuf, [y]) +]) + AC_OUTPUT() AS_IF([test "x$xend" = "xy" ], [
tools/libxl/Makefile +2 -0
@@ -21,11 +21,13 @@ endif LIBXL_LIBS = LIBXL_LIBS = $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest) $(LDLIBS_libxenstore) $(LDLIBS_libblktapctl) $(PTYFUNCS_LIBS) $(LIBUUID_LIBS) +LIBXL_LIBS += $(LIBNL3_LIBS) CFLAGS_LIBXL += $(CFLAGS_libxenctrl) CFLAGS_LIBXL += $(CFLAGS_libxenguest) CFLAGS_LIBXL += $(CFLAGS_libxenstore) CFLAGS_LIBXL += $(CFLAGS_libblktapctl) +CFLAGS_LIBXL += $(LIBNL3_CFLAGS) CFLAGS_LIBXL += -Wshadow CFLAGS += $(PTHREAD_CFLAGS)
tools/remus/README +6 -0
@@ -2,3 +2,9 @@ Remus provides fault tolerance for virtu checkpoints to a backup, which will activate if the target VM fails. See the website at http://nss.cs.ubc.ca/remus/ for details. + +Using Remus with libxl on Xen 4.4 and higher: + To enable network buffering, you need libnl 3.2.8 + or higher along with the development headers and command line utilities. + If your distro does not have the appropriate libnl3 version, you can find + the latest source tarball of libnl3 at http://www.carisma.slowglass.com/~tgr/libnl/
Re: [PATCH 2 of 7 V4] remus: add libnl3 dependency to autoconf scripts
Shriram Rajagopalan writes ("[PATCH 2 of 7 V4] remus: add libnl3 dependency to autoconf scripts"):
Quoted 7 lines
# HG changeset patch
# User Shriram Rajagopalan <[email protected]> # Date 1384492673 28800
# Node IDf14fb4982ec89b30c04c6f4684de5056450c27a0# Parent3143bed377a08bb9e87c7636e004dc371bb20338
remus: add libnl3 dependency to autoconf scripts
Quoted 6 lines
Libnl3 is required for controlling Remus network buffering. This patch adds dependency on libnl3 (>= 3.2.8) to autoconf scripts. Also provide ability to configure tools without libnl3 support, that is without network buffering support.
Signed-off-by Shriram Rajagopalan <[email protected]>
I think this looks OK.
The committer should rerun autoconf.
PATCH v4 1/1 tools/hotplug: Remus network buffering setup scripts
In reply to Shriram Rajagopalan# HG changeset patch
# User Shriram Rajagopalan <[email protected]> # Date 1384492674 28800
# Node ID 85a6d32b9e261f051bcc1776481ff5f4b7af1286 # Parent f14fb4982ec89b30c04c6f4684de5056450c27a0 tools/hotplug: Remus network buffering setup scripts
This patch introduces remus-netbuf-setup hotplug script responsible for setting up and tearing down the necessary infrastructure required for network output buffering in Remus. This script is intended to be invoked by libxl for each guest interface, when starting or stopping Remus.
Apart from returning success/failure indication via the usual hotplug entries in xenstore, this script also writes to xenstore, the name of the IFB device to be used to control the vif's network output.
The script relies on libnl3 command line utilities to perform various setup/teardown functions. The script is confined to Linux platforms only since NetBSD does not seem to have libnl3.
docs/misc/xenstore-paths.markdown +4 -0
@@ -356,6 +356,10 @@ The guest's virtual time offset from UTC The device model version for a domain. +#### /libxl/$DOMID/remus/netbuf/$DEVID/ifb = STRING [n,INTERNAL] + +IFB device used by Remus to buffer network output from the associated vif. + [BLKIF]: http://xenbits.xen.org/docs/unstable/hypercall/include,public,io,blkif.h.html [FBIF]: http://xenbits.xen.org/docs/unstable/hypercall/include,public,io,fbif.h.html [HVMPARAMS]: http://xenbits.xen.org/docs/unstable/hypercall/include,public,hvm,params.h.html
tools/hotplug/Linux/Makefile +1 -0
@@ -16,6 +16,7 @@ XEN_SCRIPTS += network-nat vif-nat XEN_SCRIPTS += vif-openvswitch XEN_SCRIPTS += vif2 XEN_SCRIPTS += vif-setup +XEN_SCRIPTS-$(CONFIG_REMUS_NETBUF) += remus-netbuf-setup XEN_SCRIPTS += block XEN_SCRIPTS += block-enbd block-nbd XEN_SCRIPTS-$(CONFIG_BLKTAP1) += blktap
tools/hotplug/Linux/remus-netbuf-setup new file +183 -0
183 lines not on this page · raw message
Re: [PATCH 3 of 7 V4] tools/hotplug: Remus network buffering setup scripts
Shriram Rajagopalan writes ("[PATCH 3 of 7 V4] tools/hotplug: Remus network buffering setup scripts"):
Quoted 7 lines
tools/hotplug: Remus network buffering setup scriptsThis patch introduces remus-netbuf-setup hotplug script responsible for setting up and tearing down the necessary infrastructure required for network output buffering in Remus. This script is intended to be invoked by libxl for each guest interface, when starting or stopping Remus.
Quoted 7 lines
Apart from returning success/failure indication via the usual hotplug entries in xenstore, this script also writes to xenstore, the name of the IFB device to be used to control the vif's network output.
The script relies on libnl3 command line utilities to perform various setup/teardown functions. The script is confined to Linux platforms only since NetBSD does not seem to have libnl3.
Thanks for this. I think this script should be introduced in the same patch as the arrangements which call it.
Also both this, and the calling arrangements, should be CC'd to Roger Pau Monne who has been doing some work on hotplug script arrangements, so I have CC'd him on this message.
Thanks,
Ian.
PATCH v4 1/1 tools/libxl: setup/teardown Remus network buffering
In reply to Shriram Rajagopalan# HG changeset patch
# User Shriram Rajagopalan <[email protected]> # Date 1384492676 28800
# Node ID d3d7da1c2289749b2a1c5b8baaf9d9c18a914e9b # Parent 85a6d32b9e261f051bcc1776481ff5f4b7af1286 tools/libxl: setup/teardown Remus network buffering
Setup/teardown remus network buffering for a given guest, when libxl_domain_remus_start API is invoked.
This patch does the following during setup:
a) call the hotplug script for each vif to setup its network buffer
b) establish a dedicated remus context containing libnl related state (netlink sockets, qdisc caches, etc.,)
c) Obtain handles to plug qdiscs installed on the IFB devices chosen by the hotplug scripts.
During teardown, the netlink resources are released, followed by invocation of hotplug scripts to remove the IFB devices.
tools/libxl/Makefile +7 -0
@@ -42,6 +42,13 @@ LIBXL_OBJS-y += libxl_blktap2.o else LIBXL_OBJS-y += libxl_noblktap2.o endif + +ifeq ($(CONFIG_REMUS_NETBUF),y) +LIBXL_OBJS-y += libxl_netbuffer.o +else +LIBXL_OBJS-y += libxl_nonetbuffer.o +endif + LIBXL_OBJS-$(CONFIG_X86) += libxl_cpuid.o libxl_x86.o LIBXL_OBJS-$(CONFIG_IA64) += libxl_nocpuid.o libxl_noarch.o LIBXL_OBJS-$(CONFIG_ARM) += libxl_nocpuid.o libxl_noarch.o
tools/libxl/libxl.c +35 -17
83 lines not on this page · raw message
tools/libxl/libxl.h +13 -0
@@ -369,6 +369,19 @@*/ #define LIBXL_HAVE_DOMAIN_CREATE_RESTORE_PARAMS 1 +/* +* LIBXL_HAVE_REMUS_NETBUF 1 +* +* If this is defined, then the libxl_domain_remus_info structure will +* have a boolean field (netbuf) and a string field (netbufscript). +* +* netbuf, if true, indicates that network buffering should be enabled. +* +* netbufscript, if set, indicates the path to the hotplug script to +* setup or teardown network buffers. +*/ +#define LIBXL_HAVE_REMUS_NETBUF 1 +/* Functions annotated with LIBXL_EXTERNAL_CALLERS_ONLY may not be * called from within libxl itself. Callers outside libxl, who * do not #include libxl_internal.h, are fine. */
tools/libxl/libxl_dom.c +60 -8
104 lines not on this page · raw message
tools/libxl/libxl_internal.h +45 -2
65 lines not on this page · raw message
tools/libxl/libxl_netbuffer.c new file +516 -0
516 lines not on this page · raw message
tools/libxl/libxl_nonetbuffer.c new file +56 -0
56 lines not on this page · raw message
tools/libxl/libxl_types.idl +2 -0
@@ -557,6 +557,8 @@ libxl_domain_remus_info = Struct("domain ("interval", integer), ("blackhole", bool), ("compression", bool), + ("netbuf", bool), + ("netbufscript", string), ]) libxl_event_type = Enumeration("event_type", [
PATCH v4 1/1 tools/libxl: Control network buffering in remus callbacks
In reply to Shriram Rajagopalan# HG changeset patch
# User Shriram Rajagopalan <[email protected]> # Date 1384492677 28800
# Node ID 8e5366a6cd958c00a9b7a726c149a552a02a7af6 # Parent d3d7da1c2289749b2a1c5b8baaf9d9c18a914e9b tools/libxl: Control network buffering in remus callbacks
This patch constitutes the core network buffering logic. and does the following:
a) create a new network buffer when the domain is suspended (remus_domain_suspend_callback)
b) release the previous network buffer pertaining to the committed checkpoint (remus_domain_checkpoint_dm_saved)
tools/libxl/libxl_dom.c +64 -6
@@ -1285,9 +1285,23 @@ static void libxl__remus_domain_suspend_libxl__save_helper_state *shs = data;libxl__egc *egc = shs->egc;libxl__domain_suspend_state *dss =CONTAINER_OF (shs, *dss, shs); +libxl__remus_ctx *remus_ctx = dss->remus_ctx; +STATE_AO_GC (dss->ao); -/* REMUS TODO: Issue disk and network checkpoint reqs. */ +/* REMUS TODO: Issue disk checkpoint reqs. */ int ok =libxl__domain_suspend_callback_common (dss); + +if (!remus_ctx->netbuf_ctx || !ok) goto out; + +/* The domain was suspended successfully. Start a new network +* buffer for the next epoch. If this operation fails, then act +* as though domain suspend failed -- libxc exits its infinite +* loop and ultimately, the replication stops. +*/ +if (libxl__remus_netbuf_start_new_epoch (gc, dss->domid, + remus_ctx)) + ok =0 ; + out:libxl__xc_domain_saverestore_async_callback_done (egc, shs, ok); }
@@ -1301,7 +1315,7 @@ static int libxl__remus_domain_resume_caif (libxl__domain_resume (gc, dss->domid,/* Fast Suspend */ 1 ))return 0 ; -/* REMUS TODO: Deal with disk. Start a new network output buffer */ +/* REMUS TODO: Deal with disk. */ return 1 ; }
@@ -1310,6 +1324,9 @@ static int libxl__remus_domain_resume_castatic void remus_checkpoint_dm_saved (libxl__egc *egc,libxl__domain_suspend_state *dss,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;
@@ -1328,10 +1345,51 @@ static void libxl__remus_domain_checkpoistatic void remus_checkpoint_dm_saved (libxl__egc *egc,libxl__domain_suspend_state *dss,int rc) { -/* REMUS TODO: Wait for disk and memory ack, release network buffer */ -/* REMUS TODO: make this asynchronous */ -assert (!rc);/* REMUS TODO handle this error properly */ -usleep (dss->remus_ctx->interval *1000 ); +/* +* REMUS TODO: Wait for disk and explicit memory ack (through restore +* callback from remote) before releasing network buffer. +*/ +libxl__remus_ctx *remus_ctx = dss->remus_ctx; +STATE_AO_GC (dss->ao); + +if (rc) { +LOG (ERROR ,"Failed to save device model. Terminating Remus.." ); + goto out; + } + +if (remus_ctx->netbuf_ctx) { + rc =libxl__remus_netbuf_release_prev_epoch (gc, dss->domid, + remus_ctx); +if (rc) { +LOG (ERROR ,"Failed to release network buffer." +" Terminating Remus.." ); + goto out; + } + } + +/* Set checkpoint interval timeout */ + rc =libxl__ev_time_register_rel (gc, &remus_ctx->timeout, + remus_next_checkpoint, + dss->remus_ctx->interval); +if (rc) { +LOG (ERROR ,"unable to register timeout for next epoch." +" Terminating Remus.." ); + 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__remus_ctx *remus_ctx =CONTAINER_OF (ev, *remus_ctx, timeout); +libxl__domain_suspend_state *dss = remus_ctx->dss; +STATE_AO_GC (dss->ao); + +libxl__ev_time_deregister (gc, &remus_ctx->timeout);libxl__xc_domain_saverestore_async_callback_done (egc, &dss->shs,1 ); }
PATCH v4 1/1 tools/xl: Remus - Network buffering cmdline switch
In reply to Shriram Rajagopalan# HG changeset patch
# User Shriram Rajagopalan <[email protected]> # Date 1384492678 28800
# Node ID 6a2a1bfffc666d5c7aaaa3532c709f2e38a86d05 # Parent 8e5366a6cd958c00a9b7a726c149a552a02a7af6 tools/xl: Remus - Network buffering cmdline switch
Command line switch to 'xl remus' command, to enable network buffering. Pass on this flag to libxl so that it can act accordingly. Also update man pages to reflect the addition of a new option to 'xl remus' command.
docs/man/xl.conf.pod.5 +6 -0
@@ -105,6 +105,12 @@ Configures the default gateway device to Default: C<None> +=item B<remus.default.netbufscript="PATH"> + +Configures the default script used by Remus to setup network buffering. + +Default: C</etc/xen/scripts/remus-netbuf-setup> + =item B<output_format="json|sxp"> Configures the default output format used by xl when printing "machine
docs/man/xl.pod.1 +13 -2
@@ -398,8 +398,7 @@ Print huge (!) amount of debug during th Enable Remus HA for domain. By default B<xl> relies on ssh as a transport mechanism between the two hosts. -N.B: Remus support in xl is still in experimental (proof-of-concept) phase. - There is no support for network or disk buffering at the moment. +N.B: There is no support for disk buffering at the moment. B<OPTIONS>
@@ -418,6 +417,18 @@ Generally useful for debugging. Disable memory checkpoint compression. +=item B<-n> + +Enable network output buffering. The default script used to configure +network buffering is /etc/xen/scripts/remus-netbuf-setup. If you wish to +use a custom script, use the I<-N> option or set the global variable +I<remus.default.netbufscript> in /etc/xen/xl.conf to point to your script. + +=item B<-N> I<netbufscript> + +Use <netbufscript> to setup network buffering instead of the instead of +the default (/etc/xen/scripts/remus-netbuf-setup). + =item B<-s> I<sshcommand> Use <sshcommand> instead of ssh. String will be passed to sh.
tools/libxl/xl.c +4 -0
@@ -46,6 +46,7 @@ char *default_vifscript = NULL;char *default_bridge =NULL ;char *default_gatewaydev =NULL ;char *default_vifbackend =NULL ; +char *default_remus_netbufscript =NULL ;enum output_format default_output_format =OUTPUT_FORMAT_JSON ;int claim_mode =1 ;
@@ -177,6 +178,9 @@ static void parse_global_config(const chif (!xlu_cfg_get_long (config,"claim_mode" , &l,0 )) claim_mode = l; +xlu_cfg_replace_string (config,"remus.default.netbufscript" , + &default_remus_netbufscript,0 ); +xlu_cfg_destroy (config); }
tools/libxl/xl.h +1 -0
@@ -152,6 +152,7 @@ extern char *default_vifscript;extern char *default_bridge;extern char *default_gatewaydev;extern char *default_vifbackend; +extern char *default_remus_netbufscript;extern char *blkdev_start;enum output_format {
tools/libxl/xl_cmdimpl.c +14 -7
@@ -7115,8 +7115,9 @@ int main_remus(int argc, char **argv) r_info.interval =200 ; r_info.blackhole =0 ; r_info.compression =1 ; - - SWITCH_FOREACH_OPT(opt, "bui:s:e", NULL, "remus", 2) { + r_info.netbuf =0 ; + + SWITCH_FOREACH_OPT(opt, "buni:s:N:e", NULL, "remus", 2) {case 'i' : r_info.interval =atoi (optarg);break ;
@@ -7126,6 +7127,12 @@ int main_remus(int argc, char **argv)case 'u' : r_info.compression =0 ;break ; +case 'n' : + r_info.netbuf =1 ; +break ; +case 'N' : + r_info.netbufscript = optarg; +break ;case 's' : ssh_command = optarg;break ;
@@ -7137,6 +7144,9 @@ int main_remus(int argc, char **argv) domid =find_domain (argv[optind]); host = argv[optind +1 ]; +if (!r_info.netbufscript) + r_info.netbufscript = default_remus_netbufscript; +if (r_info.blackhole) { send_fd =open ("/dev/null" ,O_RDWR ,0644 );if (send_fd <0 ) {
@@ -7174,13 +7184,10 @@ int main_remus(int argc, char **argv)/* Point of no return */ rc =libxl_domain_remus_start (ctx, &r_info, domid, send_fd, recv_fd,0 ); -/* If we are here, it means backup has failed/domain suspend failed. -* Try to resume the domain and exit gracefully. +/* If we are here, it means remus setup/domain suspend/backup has +* failed. Try to resume the domain and exit gracefully. * TODO: Split-Brain check. */ -fprintf (stderr,"remus sender: libxl_domain_suspend failed" -" (rc=%d)\n" , rc); -if (rc ==ERROR_GUEST_TIMEDOUT )fprintf (stderr,"Failed to suspend domain at primary.\n" );else {
tools/libxl/xl_cmdtable.c +3 -0
@@ -481,6 +481,9 @@ struct cmd_spec cmd_table[] = {"-i MS Checkpoint domain memory every MS milliseconds (def. 200ms).\n" "-b Replicate memory checkpoints to /dev/null (blackhole)\n" "-u Disable memory checkpoint compression.\n" +"-n Enable network output buffering.\n" +"-N <netbufscript> Use netbufscript to setup network buffering instead of the\n" +" instead of the default (/etc/xen/scripts/remus-netbuf-setup).\n" "-s <sshcommand> Use <sshcommand> instead of ssh. String will be passed\n" " to sh. If empty, run <host> instead of \n" " ssh <host> xl migrate-receive -r [-e]\n"
PATCH v4 1/1 tools/libxl: refactor domain_suspend_callback code to be fully asynchronous
In reply to Shriram Rajagopalan# HG changeset patch
# User Shriram Rajagopalan <[email protected]>
# Date 1384492684 28800
# Node ID c9b550e435d8dce5302e77609849bf007b4f3c2e
# Parent 6a2a1bfffc666d5c7aaaa3532c709f2e38a86d05tools/libxl: refactor domain_suspend_callback code to be fully asynchronous
libxl__domain_suspend_callback_common uses usleep calls, while the caller libxl_domain_suspend_callback is asynchronous. This patch refactors the libxl__domain_suspend__common code to use AO facilities like libxl event loop timers instead of usleep calls.
tools/libxl/libxl_dom.c +224 -122
@@ -1003,49 +1003,237 @@ int libxl__domain_resume_device_model(lireturn 0 ; } -int libxl__domain_suspend_callback_common (libxl__domain_suspend_state *dss) +static int cancel_xenbus_suspend_request (libxl__gc *gc,uint32_t domid); +static void wait_for_ack_timeout (libxl__egc *egc,libxl__ev_time *ev, +const struct timeval *requested_abs); +static void wait_for_suspend_timeout (libxl__egc *egc,libxl__ev_time *ev, +const struct timeval *requested_abs); +static void wait_for_suspend_req_ack (libxl__domain_suspend_state *dss); +static void wait_for_guest_suspend (libxl__domain_suspend_state *dss); +static void guest_suspended (libxl__domain_suspend_state *dss); + +/* Returns 0 if suspend request was cancelled and the guest did not +* respond during the cancellation process (see comments in function for +* explanation of race conditions). +* Returns 1 if guest had finally acked suspend request, during the +* cancellation process. +*/ +static int cancel_xenbus_suspend_request (libxl__gc *gc,uint32_t domid) { +char *state =NULL ; +xs_transaction_t t; + +/* +* Guest appears to not be responding. Cancel the suspend +* request. +* +* We re-read the suspend node and clear it within a +* transaction in order to handle the case where we race +* against the guest catching up and acknowledging the request +* at the last minute. +*/ +LOG (ERROR ,"guest didn't acknowledge suspend, cancelling request" ); + retry_transaction: + t =xs_transaction_start (CTX ->xsh); + + state =libxl__domain_pvcontrol_read (gc, t, domid); +if (!state) state ="" ; + +if (!strcmp (state,"suspend" )) +libxl__domain_pvcontrol_write (gc, t, domid,"" ); + +if (!xs_transaction_end (CTX ->xsh, t,0 )) +if (errno ==EAGAIN ) + goto retry_transaction; + +/* +* Final check for guest acknowledgement. The guest may have +* acknowledged while we were cancelling the request in which +* case we lost the race while cancelling and should continue. +*/ +if (!strcmp (state,"suspend" )) { +LOG (ERROR ,"guest didn't acknowledge suspend, request cancelled" ); +return 0 ; + } + +return 1 ; +} + +static void wait_for_ack_timeout (libxl__egc *egc,libxl__ev_time *ev, +const struct timeval *requested_abs) +{ +libxl__domain_suspend_state *dss =CONTAINER_OF (ev, *dss, timeout);STATE_AO_GC (dss->ao); -unsigned long hvm_s_state =0 , hvm_pvdrv =0 ; + +libxl__ev_time_deregister (gc, &dss->timeout); + dss->watchdog--; +wait_for_suspend_req_ack (dss); +} + +static void wait_for_suspend_req_ack (libxl__domain_suspend_state *dss) +{ +char *state =NULL ;int ret; -char *state ="suspend" ; -int watchdog; -xs_transaction_t t; +int wait_time; +STATE_AO_GC (dss->ao); + + state =libxl__domain_pvcontrol_read (gc,XBT_NULL , dss->domid); + +if (!state) state ="" ; + +if (!strcmp (state,"suspend" ) && dss->watchdog >0 ) { +/* The first timeout is a short one (10ms), hoping that the +* guest would respond immediately. The subsequent timeouts +* are longer (40ms). +*/ + wait_time = dss->watchdog_starting ?10 :40 ; + dss->watchdog_starting =0 ; + ret =libxl__ev_time_register_rel (gc, &dss->timeout, + wait_for_ack_timeout, wait_time); +if (ret) { +LOG (ERROR ,"unable to register timeout event to wait for" +" guest to suspend ack. Cancelling suspend request" ); + goto cancel_req; + } +return ; + } + +if (strcmp (state,"suspend" )) { + ack: +LOG (DEBUG ,"guest acknowledged suspend request" ); + dss->guest_responded =1 ; + dss->watchdog =60 ; + dss->watchdog_starting =1 ; +wait_for_guest_suspend (dss); +return ; + } + + cancel_req://either timer reg. failed or watchdog loop ended +if (cancel_xenbus_suspend_request (gc, dss->domid)) + goto ack; + +libxl__xc_domain_saverestore_async_callback_done (dss->shs.egc, &dss->shs,0 ); +} + +static void wait_for_suspend_timeout (libxl__egc *egc,libxl__ev_time *ev, +const struct timeval *requested_abs) +{ +libxl__domain_suspend_state *dss =CONTAINER_OF (ev, *dss, timeout); +STATE_AO_GC (dss->ao); + +libxl__ev_time_deregister (gc, &dss->timeout); + dss->watchdog--; +wait_for_guest_suspend (dss); +} + +static void wait_for_guest_suspend (libxl__domain_suspend_state *dss) +{ +int ret; +int wait_time; +xc_domaininfo_t info; +STATE_AO_GC (dss->ao); + + ret =xc_domain_getinfolist (CTX ->xch, dss->domid,1 , &info); +if (ret ==1 && info.domain == dss->domid && + (info.flags & XEN_DOMINF_shutdown)) { +int shutdown_reason; + + shutdown_reason = (info.flags >> XEN_DOMINF_shutdownshift) + & XEN_DOMINF_shutdownmask; +if (shutdown_reason == SHUTDOWN_suspend) { +LOG (DEBUG ,"guest has suspended" ); +guest_suspended (dss); +return ; + } + } + +if (dss->watchdog >0 ) { +/* The first timeout is a short one (10ms), hoping that the +* guest would respond immediately. The subsequent timeouts +* are longer (40ms). +*/ + wait_time = dss->watchdog_starting ?10 :40 ; + dss->watchdog_starting =0 ; + ret =libxl__ev_time_register_rel (gc, &dss->timeout, + wait_for_suspend_timeout, wait_time); +if (ret) { +LOG (ERROR ,"unable to register timeout event to wait for" +" guest to suspend." ); + goto err; + } +return ; + } + +LOG (ERROR ,"guest did not suspend" ); + err: +libxl__xc_domain_saverestore_async_callback_done (dss->shs.egc, + &dss->shs,0 ); +} + +static int libxl__remus_domain_suspend_callback (libxl__domain_suspend_state *dss); +static void guest_suspended (libxl__domain_suspend_state *dss) +{ +int ret, ok =1 ; +STATE_AO_GC (dss->ao); +if (dss->hvm) { + ret =libxl__domain_suspend_device_model (gc, dss); +if (ret) { +LOG (ERROR ,"libxl__domain_suspend_device_model failed " +"ret=%d" , ret); + ok =0 ; + goto end; + } + } + +if (dss->remus_ctx) + ok =libxl__remus_domain_suspend_callback (dss); + + end: +libxl__xc_domain_saverestore_async_callback_done (dss->shs.egc, + &dss->shs, ok); +} + +static void libxl__domain_suspend_callback (void *data) +{ +libxl__save_helper_state *shs = data; +libxl__egc *egc = shs->egc; +libxl__domain_suspend_state *dss =CONTAINER_OF (shs, *dss, shs); +int ret; +STATE_AO_GC (dss->ao);/* Convenience aliases */ const uint32_t domid = dss->domid; -if (dss->hvm) { -xc_get_hvm_param (CTX ->xch, domid,HVM_PARAM_CALLBACK_IRQ , &hvm_pvdrv); -xc_get_hvm_param (CTX ->xch, domid,HVM_PARAM_ACPI_S_STATE , &hvm_s_state); - } - -if ((hvm_s_state ==0 ) && (dss->suspend_eventchn >=0 )) { +if ((dss->hvm_s_state ==0 ) && (dss->suspend_eventchn >=0 )) {LOG (DEBUG ,"issuing %s suspend request via event channel" , dss->hvm ?"PVHVM" :"PV" ); ret =xc_evtchn_notify (dss->xce, dss->suspend_eventchn);if (ret <0 ) {LOG (ERROR ,"xc_evtchn_notify failed ret=%d" , ret); -return 0 ; + goto err; } ret =xc_await_suspend (CTX ->xch, dss->xce, dss->suspend_eventchn);if (ret <0 ) {LOG (ERROR ,"xc_await_suspend failed ret=%d" , ret); -return 0 ; + goto err; } dss->guest_responded =1 ; - goto guest_suspended; +guest_suspended (dss); +return ; } -if (dss->hvm && (!hvm_pvdrv || hvm_s_state)) { + dss->watchdog =60 ; + dss->watchdog_starting =1 ; +if (dss->hvm && (!dss->hvm_pvdrv || dss->hvm_s_state)) {LOG (DEBUG ,"Calling xc_domain_shutdown on HVM domain" ); ret =xc_domain_shutdown (CTX ->xch, domid, SHUTDOWN_suspend);if (ret <0 ) {LOGE (ERROR ,"xc_domain_shutdown failed" ); -return 0 ; + goto err; }/* The guest does not (need to) respond to this sort of request. */ dss->guest_responded =1 ; +wait_for_guest_suspend (dss); }else {LOG (DEBUG ,"issuing %s suspend request via XenBus control node" , dss->hvm ?"PVHVM" :"PV" );
@@ -1053,90 +1241,12 @@ int libxl__domain_suspend_callback_commolibxl__domain_pvcontrol_write (gc,XBT_NULL , domid,"suspend" );LOG (DEBUG ,"wait for the guest to acknowledge suspend request" ); - watchdog =60 ; -while (!strcmp (state,"suspend" ) && watchdog >0 ) { -usleep (100000 ); +wait_for_suspend_req_ack (dss); + } +return ; - state =libxl__domain_pvcontrol_read (gc,XBT_NULL , domid); -if (!state) state ="" ; - - watchdog--; - } - -/* -* Guest appears to not be responding. Cancel the suspend -* request. -* -* We re-read the suspend node and clear it within a -* transaction in order to handle the case where we race -* against the guest catching up and acknowledging the request -* at the last minute. -*/ -if (!strcmp (state,"suspend" )) { -LOG (ERROR ,"guest didn't acknowledge suspend, cancelling request" ); - retry_transaction: - t =xs_transaction_start (CTX ->xsh); - - state =libxl__domain_pvcontrol_read (gc, t, domid); -if (!state) state ="" ; - -if (!strcmp (state,"suspend" )) -libxl__domain_pvcontrol_write (gc, t, domid,"" ); - -if (!xs_transaction_end (CTX ->xsh, t,0 )) -if (errno ==EAGAIN ) - goto retry_transaction; - - } - -/* -* Final check for guest acknowledgement. The guest may have -* acknowledged while we were cancelling the request in which -* case we lost the race while cancelling and should continue. -*/ -if (!strcmp (state,"suspend" )) { -LOG (ERROR ,"guest didn't acknowledge suspend, request cancelled" ); -return 0 ; - } - -LOG (DEBUG ,"guest acknowledged suspend request" ); - dss->guest_responded =1 ; - } - -LOG (DEBUG ,"wait for the guest to suspend" ); - watchdog =60 ; -while (watchdog >0 ) { -xc_domaininfo_t info; - -usleep (100000 ); - ret =xc_domain_getinfolist (CTX ->xch, domid,1 , &info); -if (ret ==1 && info.domain == domid && - (info.flags & XEN_DOMINF_shutdown)) { -int shutdown_reason; - - shutdown_reason = (info.flags >> XEN_DOMINF_shutdownshift) - & XEN_DOMINF_shutdownmask; -if (shutdown_reason == SHUTDOWN_suspend) { -LOG (DEBUG ,"guest has suspended" ); - goto guest_suspended; - } - } - - watchdog--; - } - -LOG (ERROR ,"guest did not suspend" ); -return 0 ; - - guest_suspended: -if (dss->hvm) { - ret =libxl__domain_suspend_device_model (gc, dss); -if (ret) { -LOG (ERROR ,"libxl__domain_suspend_device_model failed ret=%d" , ret); -return 0 ; - } - } -return 1 ; + err: +libxl__xc_domain_saverestore_async_callback_done (egc, shs,0 ); } static inline char *physmap_path(libxl__gc *gc, uint32_t domid,
@@ -1223,16 +1333,6 @@ int libxl__toolstack_save(uint32_t domidreturn 0 ; } -static void libxl__domain_suspend_callback (void *data) -{ -libxl__save_helper_state *shs = data; -libxl__egc *egc = shs->egc; -libxl__domain_suspend_state *dss =CONTAINER_OF (shs, *dss, shs); - -int ok =libxl__domain_suspend_callback_common (dss); -libxl__xc_domain_saverestore_async_callback_done (egc, shs, ok); -} -/*----- remus setup/teardown code -----*/ void libxl__remus_setup_initiate (libxl__egc *egc,libxl__domain_suspend_state *dss)
@@ -1280,18 +1380,14 @@ void libxl__remus_teardown_done(libxl__e/*----- remus callbacks -----*/ -static void libxl__remus_domain_suspend_callback (void *data) +static int libxl__remus_domain_suspend_callback (libxl__domain_suspend_state *dss) { -libxl__save_helper_state *shs = data; -libxl__egc *egc = shs->egc; -libxl__domain_suspend_state *dss =CONTAINER_OF (shs, *dss, shs);libxl__remus_ctx *remus_ctx = dss->remus_ctx;STATE_AO_GC (dss->ao);/* REMUS TODO: Issue disk checkpoint reqs. */ -int ok =libxl__domain_suspend_callback_common (dss); - -if (!remus_ctx->netbuf_ctx || !ok) goto out; +if (!remus_ctx->netbuf_ctx) +return 1 ;/* The domain was suspended successfully. Start a new network * buffer for the next epoch. If this operation fails, then act
@@ -1300,9 +1396,9 @@ static void libxl__remus_domain_suspend_*/ if (libxl__remus_netbuf_start_new_epoch (gc, dss->domid, remus_ctx)) - ok =0 ; - out: -libxl__xc_domain_saverestore_async_callback_done (egc, shs, ok); +return 0 ; + +return 1 ; }static int libxl__remus_domain_resume_callback (void *data)
@@ -1411,6 +1507,7 @@ void libxl__domain_suspend(libxl__egc *e &dss->shs.callbacks.save.a;logdirty_init (&dss->logdirty); +libxl__ev_time_init (&dss->timeout);switch (type) {case LIBXL_DOMAIN_TYPE_HVM : {
@@ -1423,6 +1520,10 @@ void libxl__domain_suspend(libxl__egc *e vm_generationid_addr = (addr) ?strtoul (addr,NULL ,0 ) :0 ; dss->hvm =1 ; +xc_get_hvm_param (CTX ->xch, domid,HVM_PARAM_CALLBACK_IRQ , + &dss->hvm_pvdrv); +xc_get_hvm_param (CTX ->xch, domid,HVM_PARAM_ACPI_S_STATE , + &dss->hvm_s_state);break ; }case LIBXL_DOMAIN_TYPE_PV :
@@ -1439,6 +1540,7 @@ void libxl__domain_suspend(libxl__egc *e dss->suspend_eventchn =-1 ; dss->guest_responded =0 ; + dss->watchdog =0 ; dss->dm_savefile =libxl__device_model_savefile (gc, domid);if (dss->remus_ctx && dss->remus_ctx->compression)
@@ -1461,12 +1563,12 @@ void libxl__domain_suspend(libxl__egc *e }memset (callbacks,0 ,sizeof (*callbacks)); + + callbacks->suspend = libxl__domain_suspend_callback;if (dss->remus_ctx !=NULL ) { - callbacks->suspend = libxl__remus_domain_suspend_callback; callbacks->postcopy = libxl__remus_domain_resume_callback; callbacks->checkpoint = libxl__remus_domain_checkpoint_callback; - }else - callbacks->suspend = libxl__domain_suspend_callback; + } callbacks->switch_qemu_logdirty = libxl__domain_suspend_common_switch_qemu_logdirty; dss->shs.callbacks.save.toolstack_save = libxl__toolstack_save;
tools/libxl/libxl_internal.h +5 -1
@@ -2351,6 +2351,11 @@ struct libxl__domain_suspend_state {int hvm;int xcflags;int guest_responded; +int watchdog; +int watchdog_starting; +unsigned long hvm_s_state; +unsigned long hvm_pvdrv; +libxl__ev_time timeout;const char *dm_savefile;libxl__save_helper_state shs;libxl__logdirty_switch logdirty;
@@ -2640,7 +2645,6 @@ _hidden void libxl__xc_domain_save_done(void libxl__xc_domain_saverestore_async_callback_done (libxl__egc *egc,libxl__save_helper_state *shs,int return_value); -_hidden int libxl__domain_suspend_callback_common(libxl__domain_suspend_state*); _hidden void libxl__domain_suspend_common_switch_qemu_logdirty (int domid,unsigned int enable,void *data); _hidden int libxl__toolstack_save(uint32_t domid, uint8_t **buf,
Re: [PATCH 7 of 7 V4] tools/libxl: refactor domain_suspend_callback code to be fully asynchronous
Quoted 502 lines · Shriram Rajagopalan
# HG changeset patch
# User Shriram Rajagopalan <[email protected]>
# Date 1384492684 28800
# Node IDc9b550e435d8dce5302e77609849bf007b4f3c2e
# Parent6a2a1bfffc666d5c7aaaa3532c709f2e38a86d05tools/libxl: refactordomain_suspend_callbackcode to be fully asynchronous
libxl__domain_suspend_callback_commonuses usleep calls, while the callerlibxl_domain_suspend_callbackis asynchronous. This patch refactors thelibxl__domain_suspend__commoncode to use AO facilities like libxl event loop timers instead of usleep calls.Signed-off-by Shriram Rajagopalan <[email protected]>diff -r
6a2a1bfffc66-rc9b550e435d8tools/libxl/libxl_dom.ctools/libxl/libxl_dom.c Thu Nov 14 21:18:04 2013 -0800 renamed from tools/libxl/libxl_dom.c Thu Nov 14 21:17:58 2013 -0800 +203
-16@@ -1003,49 +1003,237 @@ int libxl__domain_resume_device_model(li return 0; } -int libxl__domain_suspend_callback_common(libxl__domain_suspend_state *dss) +static int cancel_xenbus_suspend_request(libxl__gc *gc, uint32_t domid); +static void wait_for_ack_timeout(libxl__egc *egc, libxl__ev_time *ev, + const struct timeval *requested_abs); +static void wait_for_suspend_timeout(libxl__egc *egc, libxl__ev_time *ev, + const struct timeval *requested_abs); +static void wait_for_suspend_req_ack(libxl__domain_suspend_state *dss); +static void wait_for_guest_suspend(libxl__domain_suspend_state *dss); +static void guest_suspended(libxl__domain_suspend_state *dss); + +/* Returns 0 if suspend request was cancelled and the guest did not + * respond during the cancellation process (see comments in function for + * explanation of race conditions). + * Returns 1 if guest had finally acked suspend request, during the + * cancellation process. + */ +static int cancel_xenbus_suspend_request(libxl__gc *gc, uint32_t domid) { + char *state = NULL; + xs_transaction_t t; + + /* + * Guest appears to not be responding. Cancel the suspend + * request. + * + * We re-read the suspend node and clear it within a + * transaction in order to handle the case where we race + * against the guest catching up and acknowledging the request + * at the last minute. + */ + LOG(ERROR, "guest didn't acknowledge suspend, cancelling request"); + retry_transaction: + t = xs_transaction_start(CTX->xsh); + + state = libxl__domain_pvcontrol_read(gc, t, domid); + if (!state) state = ""; + + if (!strcmp(state, "suspend")) + libxl__domain_pvcontrol_write(gc, t, domid, ""); + + if (!xs_transaction_end(CTX->xsh, t, 0)) + if (errno == EAGAIN) + goto retry_transaction; + + /* + * Final check for guest acknowledgement. The guest may have + * acknowledged while we were cancelling the request in which + * case we lost the race while cancelling and should continue. + */ + if (!strcmp(state, "suspend")) { + LOG(ERROR, "guest didn't acknowledge suspend, request cancelled"); + return 0; + } + + return 1; +} + +static void wait_for_ack_timeout(libxl__egc *egc, libxl__ev_time *ev, + const struct timeval *requested_abs) +{ + libxl__domain_suspend_state *dss = CONTAINER_OF(ev, *dss, timeout); STATE_AO_GC(dss->ao); - unsigned long hvm_s_state = 0, hvm_pvdrv = 0; + + libxl__ev_time_deregister(gc, &dss->timeout); + dss->watchdog--; + wait_for_suspend_req_ack(dss); +} + +static void wait_for_suspend_req_ack(libxl__domain_suspend_state *dss) +{ + char *state = NULL; int ret; - char *state = "suspend"; - int watchdog; - xs_transaction_t t; + int wait_time; + STATE_AO_GC(dss->ao); + + state = libxl__domain_pvcontrol_read(gc, XBT_NULL, dss->domid); + + if (!state) state = ""; + + if (!strcmp(state, "suspend") && dss->watchdog > 0) { + /* The first timeout is a short one (10ms), hoping that the + * guest would respond immediately. The subsequent timeouts + * are longer (40ms). + */ + wait_time = dss->watchdog_starting ? 10 : 40; + dss->watchdog_starting = 0; + ret = libxl__ev_time_register_rel(gc, &dss->timeout, + wait_for_ack_timeout, wait_time); + if (ret) { + LOG(ERROR, "unable to register timeout event to wait for" + " guest to suspend ack. Cancelling suspend request"); + goto cancel_req; + } + return; + } + + if (strcmp(state, "suspend")) { + ack: + LOG(DEBUG, "guest acknowledged suspend request"); + dss->guest_responded = 1; + dss->watchdog = 60; + dss->watchdog_starting = 1; + wait_for_guest_suspend(dss); + return; + } + + cancel_req: //either timer reg. failed or watchdog loop ended + if (cancel_xenbus_suspend_request(gc, dss->domid)) + goto ack; + + libxl__xc_domain_saverestore_async_callback_done(dss->shs.egc, &dss->shs, 0); +} + +static void wait_for_suspend_timeout(libxl__egc *egc, libxl__ev_time *ev, + const struct timeval *requested_abs) +{ + libxl__domain_suspend_state *dss = CONTAINER_OF(ev, *dss, timeout); + STATE_AO_GC(dss->ao); + + libxl__ev_time_deregister(gc, &dss->timeout); + dss->watchdog--; + wait_for_guest_suspend(dss); +} + +static void wait_for_guest_suspend(libxl__domain_suspend_state *dss) +{ + int ret; + int wait_time; + xc_domaininfo_t info; + STATE_AO_GC(dss->ao); + + ret = xc_domain_getinfolist(CTX->xch, dss->domid, 1, &info); + if (ret == 1 && info.domain == dss->domid && + (info.flags & XEN_DOMINF_shutdown)) { + int shutdown_reason; + + shutdown_reason = (info.flags >> XEN_DOMINF_shutdownshift) + & XEN_DOMINF_shutdownmask; + if (shutdown_reason == SHUTDOWN_suspend) { + LOG(DEBUG, "guest has suspended"); + guest_suspended(dss); + return; + } + } + + if (dss->watchdog > 0) { + /* The first timeout is a short one (10ms), hoping that the + * guest would respond immediately. The subsequent timeouts + * are longer (40ms). + */ + wait_time = dss->watchdog_starting ? 10 : 40; + dss->watchdog_starting = 0; + ret = libxl__ev_time_register_rel(gc, &dss->timeout, + wait_for_suspend_timeout, wait_time); + if (ret) { + LOG(ERROR, "unable to register timeout event to wait for" + " guest to suspend."); + goto err; + } + return; + } + + LOG(ERROR, "guest did not suspend"); + err: + libxl__xc_domain_saverestore_async_callback_done(dss->shs.egc, + &dss->shs, 0); +} + +static int libxl__remus_domain_suspend_callback(libxl__domain_suspend_state *dss); +static void guest_suspended(libxl__domain_suspend_state *dss) +{ + int ret, ok = 1; + STATE_AO_GC(dss->ao); + if (dss->hvm) { + ret = libxl__domain_suspend_device_model(gc, dss); + if (ret) { + LOG(ERROR, "libxl__domain_suspend_device_model failed " + "ret=%d", ret); + ok = 0; + goto end; + } + } + + if (dss->remus_ctx) + ok = libxl__remus_domain_suspend_callback(dss); + + end: + libxl__xc_domain_saverestore_async_callback_done(dss->shs.egc, + &dss->shs, ok); +} + +static void libxl__domain_suspend_callback(void *data) +{ + libxl__save_helper_state *shs = data; + libxl__egc *egc = shs->egc; + libxl__domain_suspend_state *dss = CONTAINER_OF(shs, *dss, shs); + int ret; + STATE_AO_GC(dss->ao); /* Convenience aliases */ const uint32_t domid = dss->domid; - if (dss->hvm) { - xc_get_hvm_param(CTX->xch, domid, HVM_PARAM_CALLBACK_IRQ, &hvm_pvdrv); - xc_get_hvm_param(CTX->xch, domid, HVM_PARAM_ACPI_S_STATE, &hvm_s_state); - } - - if ((hvm_s_state == 0) && (dss->suspend_eventchn >= 0)) { + if ((dss->hvm_s_state == 0) && (dss->suspend_eventchn >= 0)) { LOG(DEBUG, "issuing %s suspend request via event channel", dss->hvm ? "PVHVM" : "PV"); ret = xc_evtchn_notify(dss->xce, dss->suspend_eventchn); if (ret < 0) { LOG(ERROR, "xc_evtchn_notify failed ret=%d", ret); - return 0; + goto err; } ret = xc_await_suspend(CTX->xch, dss->xce, dss->suspend_eventchn); if (ret < 0) { LOG(ERROR, "xc_await_suspend failed ret=%d", ret); - return 0; + goto err; } dss->guest_responded = 1; - goto guest_suspended; + guest_suspended(dss); + return; } - if (dss->hvm && (!hvm_pvdrv || hvm_s_state)) { + dss->watchdog = 60; + dss->watchdog_starting = 1; + if (dss->hvm && (!dss->hvm_pvdrv || dss->hvm_s_state)) { LOG(DEBUG, "Calling xc_domain_shutdown on HVM domain"); ret = xc_domain_shutdown(CTX->xch, domid, SHUTDOWN_suspend); if (ret < 0) { LOGE(ERROR, "xc_domain_shutdown failed"); - return 0; + goto err; } /* The guest does not (need to) respond to this sort of request.*/
dss->guest_responded = 1;tools/libxl/libxl_dom.c Thu Nov 14 21:18:04 2013 -0800 renamed from tools/libxl/libxl_dom.c Thu Nov 14 21:17:58 2013 -0800 +6
-83+ wait_for_guest_suspend(dss); } else { LOG(DEBUG, "issuing %s suspend request via XenBus control node", dss->hvm ? "PVHVM" : "PV");@@ -1053,90 +1241,12 @@ int libxl__domain_suspend_callback_commo libxl__domain_pvcontrol_write(gc, XBT_NULL, domid, "suspend"); LOG(DEBUG, "wait for the guest to acknowledge suspend request"); - watchdog = 60; - while (!strcmp(state, "suspend") && watchdog > 0) { - usleep(100000); + wait_for_suspend_req_ack(dss); + } + return; - state = libxl__domain_pvcontrol_read(gc, XBT_NULL, domid); - if (!state) state = ""; - - watchdog--; - } - - /* - * Guest appears to not be responding. Cancel the suspend - * request. - * - * We re-read the suspend node and clear it within a - * transaction in order to handle the case where we race - * against the guest catching up and acknowledging the request - * at the last minute. - */ - if (!strcmp(state, "suspend")) { - LOG(ERROR, "guest didn't acknowledge suspend, cancelling request"); - retry_transaction: - t = xs_transaction_start(CTX->xsh); - - state = libxl__domain_pvcontrol_read(gc, t, domid); - if (!state) state = ""; - - if (!strcmp(state, "suspend")) - libxl__domain_pvcontrol_write(gc, t, domid, ""); - - if (!xs_transaction_end(CTX->xsh, t, 0)) - if (errno == EAGAIN) - goto retry_transaction; - - } - - /* - * Final check for guest acknowledgement. The guest may have - * acknowledged while we were cancelling the request in which - * case we lost the race while cancelling and should continue. - */ - if (!strcmp(state, "suspend")) { - LOG(ERROR, "guest didn't acknowledge suspend, request cancelled"); - return 0; - } - - LOG(DEBUG, "guest acknowledged suspend request"); - dss->guest_responded = 1; - } - - LOG(DEBUG, "wait for the guest to suspend"); - watchdog = 60; - while (watchdog > 0) { - xc_domaininfo_t info; - - usleep(100000); - ret = xc_domain_getinfolist(CTX->xch, domid, 1, &info); - if (ret == 1 && info.domain == domid && - (info.flags & XEN_DOMINF_shutdown)) { - int shutdown_reason; - - shutdown_reason = (info.flags >> XEN_DOMINF_shutdownshift) - & XEN_DOMINF_shutdownmask; - if (shutdown_reason == SHUTDOWN_suspend) { - LOG(DEBUG, "guest has suspended"); - goto guest_suspended; - } - } - - watchdog--; - } - - LOG(ERROR, "guest did not suspend"); - return 0; - - guest_suspended: - if (dss->hvm) { - ret = libxl__domain_suspend_device_model(gc, dss); - if (ret) { - LOG(ERROR, "libxl__domain_suspend_device_model failed ret=%d", ret); - return 0; - } - } - return 1; + err: + libxl__xc_domain_saverestore_async_callback_done(egc, shs, 0);}
static inline char *physmap_path(libxl__gc *gc,
uint32_tdomid,tools/libxl/libxl_dom.c Thu Nov 14 21:18:04 2013 -0800 renamed from tools/libxl/libxl_dom.c Thu Nov 14 21:17:58 2013 -0800 +3
-17@@ -1223,16 +1333,6 @@ int libxl__toolstack_save(uint32_t domid return 0; } -static void libxl__domain_suspend_callback(void *data) -{ - libxl__save_helper_state *shs = data; - libxl__egc *egc = shs->egc; - libxl__domain_suspend_state *dss = CONTAINER_OF(shs, *dss, shs); - - int ok = libxl__domain_suspend_callback_common(dss); - libxl__xc_domain_saverestore_async_callback_done(egc, shs, ok); -} - /*----- remus setup/teardown code -----*/ void libxl__remus_setup_initiate(libxl__egc *egc, libxl__domain_suspend_state *dss)@@ -1280,18 +1380,14 @@ void libxl__remus_teardown_done(libxl__e /*----- remus callbacks -----*/ -static void libxl__remus_domain_suspend_callback(void *data) +static int libxl__remus_domain_suspend_callback(libxl__domain_suspend_state *dss) { - libxl__save_helper_state *shs = data; - libxl__egc *egc = shs->egc; - libxl__domain_suspend_state *dss = CONTAINER_OF(shs, *dss, shs); libxl__remus_ctx *remus_ctx = dss->remus_ctx; STATE_AO_GC(dss->ao); /* REMUS TODO: Issue disk checkpoint reqs. */ - int ok = libxl__domain_suspend_callback_common(dss); - - if (!remus_ctx->netbuf_ctx || !ok) goto out; + if (!remus_ctx->netbuf_ctx) + return 1; /* The domain was suspended successfully. Start a new network* buffer for the next epoch. If this operation fails, then act
tools/libxl/libxl_dom.c Thu Nov 14 21:18:04 2013 -0800 renamed from tools/libxl/libxl_dom.c Thu Nov 14 21:17:58 2013 -0800 +12
-6@@ -1300,9 +1396,9 @@ static void libxl__remus_domain_suspend_ */ if (libxl__remus_netbuf_start_new_epoch(gc, dss->domid, remus_ctx)) - ok = 0; - out: - libxl__xc_domain_saverestore_async_callback_done(egc, shs, ok); + return 0; + + return 1; } static int libxl__remus_domain_resume_callback(void *data)@@ -1411,6 +1507,7 @@ void libxl__domain_suspend(libxl__egc *e &dss->shs.callbacks.save.a; logdirty_init(&dss->logdirty); + libxl__ev_time_init(&dss->timeout); switch (type) { case LIBXL_DOMAIN_TYPE_HVM: {@@ -1423,6 +1520,10 @@ void libxl__domain_suspend(libxl__egc *e vm_generationid_addr = (addr) ? strtoul(addr, NULL, 0) : 0; dss->hvm = 1; + xc_get_hvm_param(CTX->xch, domid, HVM_PARAM_CALLBACK_IRQ, + &dss->hvm_pvdrv); + xc_get_hvm_param(CTX->xch, domid, HVM_PARAM_ACPI_S_STATE, + &dss->hvm_s_state); break; } case LIBXL_DOMAIN_TYPE_PV:@@ -1439,6 +1540,7 @@ void libxl__domain_suspend(libxl__egc *e dss->suspend_eventchn = -1; dss->guest_responded = 0; + dss->watchdog = 0; dss->dm_savefile = libxl__device_model_savefile(gc, domid); if (dss->remus_ctx && dss->remus_ctx->compression)@@ -1461,12 +1563,12 @@ void libxl__domain_suspend(libxl__egc *e } memset(callbacks, 0, sizeof(*callbacks)); + + callbacks->suspend = libxl__domain_suspend_callback; if (dss->remus_ctx != NULL) { - callbacks->suspend = libxl__remus_domain_suspend_callback; callbacks->postcopy = libxl__remus_domain_resume_callback; callbacks->checkpoint = libxl__remus_domain_checkpoint_callback; - } else - callbacks->suspend = libxl__domain_suspend_callback; + } callbacks->switch_qemu_logdirty = libxl__domain_suspend_common_switch_qemu_logdirty;dss->shs.callbacks.save.toolstack_save = libxl__toolstack_save;diff -r
6a2a1bfffc66-rc9b550e435d8tools/libxl/libxl_internal.htools/libxl/libxl_internal.h Thu Nov 14 21:18:04 2013 -0800 renamed from tools/libxl/libxl_internal.h Thu Nov 14 21:17:58 2013 -0800 +5
-1@@ -2351,6 +2351,11 @@ struct libxl__domain_suspend_state { int hvm; int xcflags; int guest_responded; + int watchdog; + int watchdog_starting; + unsigned long hvm_s_state; + unsigned long hvm_pvdrv; + libxl__ev_time timeout; const char *dm_savefile; libxl__save_helper_state shs; libxl__logdirty_switch logdirty;@@ -2640,7 +2645,6 @@ _hidden void libxl__xc_domain_save_done( void libxl__xc_domain_saverestore_async_callback_done(libxl__egc *egc, libxl__save_helper_state *shs, int return_value); -_hidden int libxl__domain_suspend_callback_common(libxl__domain_suspend_state*); _hidden void libxl__domain_suspend_common_switch_qemu_logdirty(int domid, unsigned int enable, void
*data);
_hiddenint libxl__toolstack_save(uint32_t domid,uint8_t**buf,
Quoted 5 lines
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
ping! If there is feedback, I can get going right away. Meanwhile, I am trying to make the code use the nested-ao stuff, but I can send it as a separate patch on top of this.
shriram
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH 7 of 7 V4] tools/libxl: refactor domain_suspend_callback code to be fully asynchronous
In reply to Shriram RajagopalanQuoted 8 lines · Shriram Rajagopalan
# HG changeset patch
# User Shriram Rajagopalan <[email protected]>
# Date 1384492684 28800
# Node IDc9b550e435d8dce5302e77609849bf007b4f3c2e
# Parent6a2a1bfffc666d5c7aaaa3532c709f2e38a86d05tools/libxl: refactordomain_suspend_callbackcode to be fully asynchronous
Quoted 7 lines
libxl__domain_suspend_callback_commonuses usleep calls, while the callerlibxl_domain_suspend_callbackis asynchronous. This patch refactors thelibxl__domain_suspend__commoncode to use AO facilities like libxl event loop timers instead of usleep calls.Signed-off-by Shriram Rajagopalan <[email protected]>
Ian, would you like this to be lumped together with your patch on asynchronous domain suspend, and sent out as a separate patch series?
Re: [PATCH 7 of 7 V4] tools/libxl: refactor domain_suspend_callback code to be fully asynchronous
Shriram Rajagopalan writes ("Re: [Xen-devel] [PATCH 7 of 7 V4] tools/libxl: refactor domain_suspend_callback code to be fully asynchronous"):
Quoted 13 lines
Quoted 11 lines · Shriram Rajagopalan
# HG changeset patch
# User Shriram Rajagopalan <[email protected]>
# Date 1384492684 28800
# Node IDc9b550e435d8dce5302e77609849bf007b4f3c2e
# Parent6a2a1bfffc666d5c7aaaa3532c709f2e38a86d05tools/libxl: refactordomain_suspend_callbackcode to be fully asynchronous
libxl__domain_suspend_callback_commonuses usleep calls, while the callerlibxl_domain_suspend_callbackis asynchronous. This patch refactors thelibxl__domain_suspend__commoncode to use AO facilities like libxl event loop timers instead of usleep calls.
...
Quoted 3 lines
Ian, would you like this to be lumped together with your patch on asynchronous domain suspend, and sent out as a separate patch series?
If you'd like to see it in 4.4, yes, please. I suspect that your full Remus series isn't going to make it, I'm afraid. But these two together are a bugfix so are less in trouble due to the codefreeze.
Thanks,
Ian.
Re: [PATCH 7 of 7 V4] tools/libxl: refactor domain_suspend_callback code to be fully asynchronous
Quoted 14 lines · Ian Jackson
Shriram Rajagopalan writes ("Re: [Xen-devel] [PATCH 7 of 7 V4]
tools/libxl: refactordomain_suspend_callbackcode to be fully asynchronous"):Quoted 9 lines
Quoted 7 lines · Shriram Rajagopalan
# HG changeset patch
# User Shriram Rajagopalan <[email protected]>
# Date 1384492684 28800
# Node IDc9b550e435d8dce5302e77609849bf007b4f3c2e
# Parent6a2a1bfffc666d5c7aaaa3532c709f2e38a86d05tools/libxl: refactordomain_suspend_callbackcode to be fully asynchronousQuoted 4 lines
Quoted 4 lines
libxl__domain_suspend_callback_commonuses usleep calls, while the callerlibxl_domain_suspend_callbackis asynchronous. This patch refactors thelibxl__domain_suspend__commoncode to use AO facilities like libxl event loop timers instead of usleep calls.
Quoted 7 lines
...
Quoted 3 lines
Ian, would you like this to be lumped together with your patch on asynchronous domain suspend, and sent out as a separate patch series?
If you'd like to see it in 4.4, yes, please. I suspect that your full Remus series isn't going to make it, I'm afraid.
Why? I had posted three versions these way before the freeze date (oct 18). And the final feedback I had on the Remus series was to make the checkpoint sleep function use event timers, which has been addressed in V4.
Re: [PATCH 7 of 7 V4] tools/libxl: refactor domain_suspend_callback code to be fully asynchronous
In reply to Shriram RajagopalanShriram Rajagopalan writes ("[PATCH 7 of 7 V4] tools/libxl: refactor domain_suspend_callback code to be fully asynchronous"):
Quoted 6 lines
tools/libxl: refactordomain_suspend_callbackcode to be fully asynchronous
libxl__domain_suspend_callback_commonuses usleep calls, while the callerlibxl_domain_suspend_callbackis asynchronous. This patch refactors thelibxl__domain_suspend__commoncode to use AO facilities like libxl event loop timers instead of usleep calls.
Thanks. This mixture of code motion, semantic changes, and changes to function boundaries, is very difficult to review.
Do you think you can split this patch up into a small subseries somehow ? For example by adding pre-patches or post-patches (or both) containing the code motion, and separate patches with functional change but no bulk motion ?
Ian.
Re: [PATCH 7 of 7 V4] tools/libxl: refactor domain_suspend_callback code to be fully asynchronous
Quoted 8 lines · Ian Jackson
Shriram Rajagopalan writes ("[PATCH 7 of 7 V4]
tools/libxl: refactordomain_suspend_callbackcode to be fully asynchronous"):Quoted 6 lines
tools/libxl: refactordomain_suspend_callbackcode to be fully asynchronous
libxl__domain_suspend_callback_commonuses usleep calls, while the callerlibxl_domain_suspend_callbackis asynchronous. This patch refactors thelibxl__domain_suspend__commoncode to use AO facilities like libxl event loop timers instead of usleep calls.
Quoted 8 lines
Thanks. This mixture of code motion, semantic changes, and changes to function boundaries, is very difficult to review.
Do you think you can split this patch up into a small subseries somehow ? For example by adding pre-patches or post-patches (or both) containing the code motion, and separate patches with functional change but no bulk motion ?
Yep sure.
Quoted 2 lines
Ian.
Quoted 90 lines · Shriram Rajagopalan
This patch series adds support for network buffering in the Remus codebase in libxl and makes the suspend callback asynchronous.
I have tested the series with PV guests (with and without suspend event channel). Would appreciate if anyone could test the series with PV-HVM guests and pure HVM guests.
Changes in V4:
[1/7] *new*. This Ian Jackson's patch -- making
libxl__domain_suspend_callbackasynchronous[2/7] [was 1/5 in previous versions] Remove check for libnl
command line utils[3/7] [was 2/5 previously] minor nits
[4/7] [was 3/5 previously] define
LIBXL_HAVE_REMUS_NETBUF
inlibxl.h[5/7] [was 4/5 previously] clean ups. Make the usleep in checkpoint
callback asynchronous[6/7] [was 5/5 previously] minor nits
[7/7] *new*. Refactor
libxl__domain_suspend_common_callbackto
substitute usleep based wait loops with libxl's timer events.Changes in V3:
[1/5] Fix redundant checks in configure scripts
(based on Ian Campbell's suggestions)[2/5] Introduce locking in the script, during IFB setup.
Add xenstore paths used by netbuf scripts to xenstore-paths.markdown[3/5] Hotplug scripts setup/teardown invocations are now asynchronous
following IanJ's feedback. However, the invocations are still sequential.[5/5] Allow per-domain specification of netbuffer scripts in xl remus
commmand.And minor nits throughout the series based on feedback from the last version
Changes in V2:
[1/5] Configure script will automatically enable/disable network
buffer support depending on the availability of the appropriate libnl3 version. [If libnl3 is unavailable, a warning message will be printed to let the user know that the feature has been disabled.]use macros from pkg.m4 instead of pkg-config commands removed redundant checks for libnl3 libraries.
[3,4/5] - Minor nits.
Version 1:
[1/5] Changes to autoconf scripts to check for libnl3. Add linker flags
to libxlMakefile.[2/5] External script to setup/teardown network buffering using libnl3's
CLI. This script will be invoked by libxl before starting Remus. The script's main job is to bring up an IFB device with plug qdisc attached to it. It then re-routes egress traffic from the guest's vif to the IFB device.[3/5] Libxl code to invoke the external setup script, followed by netlink
related setup to obtain a handle on the output buffers attached to each vif.[4/5] Libxl interaction with network buffer module in the kernel via
libnl3 API.[5/5] xl cmdline switch to explicitly enable network buffering when
starting remus.Few things to note:
a) Based on previous email discussions, the setup/teardown task has been moved to a hotplug style shell script which can be customized as desired, instead of implementing it as C code inside libxl.
b) Libnl3 is not available on NetBSD. Nor is it available on CentOS
(Linux). So I have made network buffering support an optional feature so that it can be disabled if desired.
Quoted 6 lines
c) NetBSD does not have libnl3. So I have put the setup script under
tools/hotplug/Linuxfolder.thanks
shriram
Ping!
Quoted 4 lines
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel