Skip to contentSkip to conversation

Remus/Libxl: Network buffering support

PATCH In review Lai Jiangshan 5 participants 89 messages Feb 10, 2014 – May 14, 2014

lore
Share & tools
lore
#0 lore raw

v7 cover Remus/Libxl: Network buffering support

This patch series adds support for network buffering in the Remus codebase in libxl.

Changes in V7:
Applied missing comments(by IanJ).
Applied Shriram comments.

merge netbufering tangled setup/teardown code into one patch. (2/6/8 in V6 => 5 in V7. 9/10 in V6 => 7 in V7)

Changes in V6:
Applied Ian Jackson's comments of V5 series. the [PATCH 2/4 V5] is split by small functionalities.

[PATCH 4/4 V5] --> [PATCH 13/13] netbuffer is default enabled.

Changes in V5:

Merge hotplug script patch (2/5) and hotplug script setup/teardown patch (3/5) into a single patch.

Changes in V4:

[1/5] Remove check for libnl command line utils in autoconf checks

[2/5] minor nits

[3/5] define LIBXL_HAVE_REMUS_NETBUF in libxl.h

[4/5] clean ups. Make the usleep in checkpoint callback asynchronous

[5/5] minor nits

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(by shriram):

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
Lai

Shriram Rajagopalan (8):
remus: add libnl3 dependency to autoconf scripts tools/libxl: update libxl_domain_remus_info
tools/libxl: introduce a new structure libxl__remus_state
remus: introduce a function to check whether network buffering is
enabled
remus: Remus network buffering core and APIs to setup/teardown
remus: implement the APIs to buffer/release packages
libxl: use the APIs to setup/teardown network buffering
libxl: rename remus_failover_cb() to remus_replication_failure_cb()
libxl: control network buffering in remus callbacks
libxl: network buffering cmdline switch

 README                                 |    4 +
 config/Tools.mk.in                     |    3 +
 docs/man/xl.conf.pod.5                 |    6 +
 docs/man/xl.pod.1                      |   11 +-
 docs/misc/xenstore-paths.markdown      |    4 +
 tools/configure.ac                     |   15 +
 tools/hotplug/Linux/Makefile           |    1 +
 tools/hotplug/Linux/remus-netbuf-setup |  183 +++++++++++
 tools/libxl/Makefile                   |   11 +
 tools/libxl/libxl.c                    |   48 ++-
 tools/libxl/libxl.h                    |   13 +
 tools/libxl/libxl_dom.c                |  118 ++++++--
 tools/libxl/libxl_internal.h           |   54 +++-
 tools/libxl/libxl_netbuffer.c          |  561 ++++++++++++++++++++++++++++++++
 tools/libxl/libxl_nonetbuffer.c        |   56 ++++
 tools/libxl/libxl_remus.c              |   64 ++++
 tools/libxl/libxl_types.idl            |    2 +
 tools/libxl/xl.c                       |    4 +
 tools/libxl/xl.h                       |    1 +
 tools/libxl/xl_cmdimpl.c               |   28 ++-
 tools/libxl/xl_cmdtable.c              |    3 +
 tools/remus/README                     |    6 +
 22 files changed, 1155 insertions(+), 41 deletions(-)
 create mode 100644 tools/hotplug/Linux/remus-netbuf-setup
 create mode 100644 tools/libxl/libxl_netbuffer.c
 create mode 100644 tools/libxl/libxl_nonetbuffer.c
 create mode 100644 tools/libxl/libxl_remus.c
#1 lore raw

PATCH v7 1/10 remus: add libnl3 dependency to autoconf scripts

From: Shriram Rajagopalan <[email protected]>

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 ++++
 config/Tools.mk.in   |    3 +++
 tools/configure.ac   |   15 +++++++++++++++
 tools/libxl/Makefile |    2 ++
 tools/remus/README   |    6 ++++++
 5 files changed, 30 insertions(+), 0 deletions(-)
README +4 -0
index 4148a26..7bb25fb 100644
@@ -72,6 +72,10 @@ disabled at compile time:
     * cmake (if building vtpm stub domains)
     * markdown
     * figlet (for generating the traditional Xen start of day banner)
+    * 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
index d9d3239..81802b3 100644
@@ -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
index 0754f0e..f95956d 100644
@@ -236,6 +236,21 @@ esac
 # 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
index d8495bb..da27c84 100644
@@ -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
 
 LIBXL_LIBS-$(CONFIG_ARM) += -lfdt
tools/remus/README +6 -0
index 9e8140b..4736252 100644
@@ -2,3 +2,9 @@ Remus provides fault tolerance for virtual machines by sending continuous
 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/
Signature · 1 line
1.7.1
#2 lore raw

PATCH v7 2/10 tools/libxl: update libxl_domain_remus_info

In reply to Lai Jiangshan

From: Shriram Rajagopalan <[email protected]>

Add two members:
1. netbuf: whether netbuf is enabled
2. netbufscript: the path of the script which will be run to setup and tear down the guest's interface.

---
 tools/libxl/libxl.h         |   13 +++++++++++++
 tools/libxl/libxl_types.idl |    2 ++
 2 files changed, 15 insertions(+), 0 deletions(-)
tools/libxl/libxl.h +13 -0
index 12d6c31..d89ad0a 100644
@@ -409,6 +409,19 @@
  */
 #define LIBXL_HAVE_DRIVER_DOMAIN_CREATION 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_types.idl +2 -0
index 649ce50..e49945a 100644
@@ -561,6 +561,8 @@ libxl_domain_remus_info = Struct("domain_remus_info",[
     ("interval",     integer),
     ("blackhole",    bool),
     ("compression",  bool),
+    ("netbuf",       bool),
+    ("netbufscript", string),
     ])
 
 libxl_event_type = Enumeration("event_type", [
Signature · 1 line
1.7.1
#3 lore raw

Re: [PATCH 02/10 V7] tools/libxl: update libxl_domain_remus_info

Lai Jiangshan writes ("[PATCH 02/10 V7] tools/libxl: update libxl_domain_remus_info"):

Quoted 10 lines

From: Shriram Rajagopalan <[email protected]>

Add two members:
1. netbuf: whether netbuf is enabled
2. netbufscript: the path of the script which will be run to setup and tear down the guest's interface.

Thanks. But I think these parameters should be introduced at the same time (ie in the same patch) as their implementation.

Regards,
Ian.

#4 lore raw

PATCH v7 3/10 tools/libxl: introduce a new structure libxl__remus_state

In reply to Lai Jiangshan

From: Shriram Rajagopalan <[email protected]>

libxl_domain_remus_info only contains the argument of the command 'xl remus'. So introduce a new structure libxl__remus_state to save the remus state.

---
 tools/libxl/libxl.c          |   25 +++++++++++++++++++++++--
 tools/libxl/libxl_dom.c      |   12 ++++--------
 tools/libxl/libxl_internal.h |   22 ++++++++++++++++++++--
 3 files changed, 47 insertions(+), 12 deletions(-)
tools/libxl/libxl.c +23 -2
index 2845ca4..25af816 100644
@@ -729,11 +729,32 @@ int libxl_domain_remus_start(libxl_ctx *ctx, libxl_domain_remus_info *info,
     dss->type = type;
     dss->live = 1;
     dss->debug = 0;
-    dss->remus = info;
 
     assert(info);
 
-    /* TBD: Remus setup - i.e. attach qdisc, enable disk buffering, etc */
+    GCNEW(dss->remus_state);
+
+    /* convenience shorthand */
+    libxl__remus_state *remus_state = dss->remus_state;
+    remus_state->blackhole = info->blackhole;
+    remus_state->interval = info->interval;
+    remus_state->compression = info->compression;
+    remus_state->dss = dss;
+    libxl__ev_child_init(&remus_state->child);
+
+    /* TODO: enable disk buffering */
+
+    /* Setup network buffering */
+    if (info->netbuf) {
+        if (info->netbufscript) {
+            remus_state->netbufscript =
+                libxl__strdup(gc, info->netbufscript);
+        } else {
+            remus_state->netbufscript =
+                GCSPRINTF("%s/remus-netbuf-setup",
+                          libxl__xen_script_dir_path());
+        }
+    }
 
     /* Point of no return */
     libxl__domain_suspend(egc, dss);
tools/libxl/libxl_dom.c +4 -8
index 55f74b2..8d63f90 100644
@@ -1290,7 +1290,7 @@ static void remus_checkpoint_dm_saved(libxl__egc *egc,
     /* 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->interval * 1000);
+    usleep(dss->remus_state->interval * 1000);
     libxl__xc_domain_saverestore_async_callback_done(egc, &dss->shs, 1);
 }
 
@@ -1308,7 +1308,6 @@ void libxl__domain_suspend(libxl__egc *egc, libxl__domain_suspend_state *dss)
     const libxl_domain_type type = dss->type;
     const int live = dss->live;
     const int debug = dss->debug;
-    const libxl_domain_remus_info *const r_info = dss->remus;
     libxl__srm_save_autogen_callbacks *const callbacks =
         &dss->shs.callbacks.save.a;
 
@@ -1343,11 +1342,8 @@ void libxl__domain_suspend(libxl__egc *egc, libxl__domain_suspend_state *dss)
     dss->guest_responded = 0;
     dss->dm_savefile = libxl__device_model_savefile(gc, domid);
 
-    if (r_info != NULL) {
-        dss->interval = r_info->interval;
-        if (r_info->compression)
-            dss->xcflags |= XCFLAGS_CHECKPOINT_COMPRESS;
-    }
+    if (dss->remus_state && dss->remus_state->compression)
+        dss->xcflags |= XCFLAGS_CHECKPOINT_COMPRESS;
 
     dss->xce = xc_evtchn_open(NULL, 0);
     if (dss->xce == NULL)
@@ -1366,7 +1362,7 @@ void libxl__domain_suspend(libxl__egc *egc, libxl__domain_suspend_state *dss)
     }
 
     memset(callbacks, 0, sizeof(*callbacks));
-    if (r_info != NULL) {
+    if (dss->remus_state != NULL) {
         callbacks->suspend = libxl__remus_domain_suspend_callback;
         callbacks->postcopy = libxl__remus_domain_resume_callback;
         callbacks->checkpoint = libxl__remus_domain_checkpoint_callback;
tools/libxl/libxl_internal.h +20 -2
index 1bd23ff..9970780 100644
@@ -2292,6 +2292,25 @@ typedef struct libxl__logdirty_switch {
     libxl__ev_time timeout;
 } libxl__logdirty_switch;
 
+typedef struct libxl__remus_state {
+    /* filled by the user */
+    /* checkpoint interval */
+    int interval;
+    int blackhole;
+    int compression;
+    /* Script to setup/teardown network buffers */
+    const char *netbufscript;
+    libxl__domain_suspend_state *dss;
+
+    /* private */
+    int saved_rc;
+    int dev_id;
+    /* Opaque context containing network buffer related stuff */
+    void *netbuf_state;
+    libxl__ev_time timeout;
+    libxl__ev_child child;
+} libxl__remus_state;
+
 struct libxl__domain_suspend_state {
     /* set by caller of libxl__domain_suspend */
     libxl__ao *ao;
@@ -2302,7 +2321,7 @@ struct libxl__domain_suspend_state {
     libxl_domain_type type;
     int live;
     int debug;
-    const libxl_domain_remus_info *remus;
+    libxl__remus_state *remus_state;
     /* private */
     xc_evtchn *xce; /* event channel handle */
     int suspend_eventchn;
@@ -2310,7 +2329,6 @@ struct libxl__domain_suspend_state {
     int xcflags;
     int guest_responded;
     const char *dm_savefile;
-    int interval; /* checkpoint interval (for Remus) */
     libxl__save_helper_state shs;
     libxl__logdirty_switch logdirty;
     /* private for libxl__domain_save_device_model */
Signature · 1 line
1.7.1
#5 lore raw

Re: [PATCH 03/10 V7] tools/libxl: introduce a new structure libxl__remus_state

Lai Jiangshan writes ("[PATCH 03/10 V7] tools/libxl: introduce a new structure libxl__remus_state"):

Quoted 3 lines

libxl_domain_remus_info only contains the argument of the command 'xl remus'. So introduce a new structure libxl__remus_state to save the remus state.

I appreciate that you've probably split this up to try to make the review easier, but I think there would probably be a way to do this that made the patches make more sense when reviewed in isolation.

For this one:

tools/libxl/libxl.c int libxl_domain_remus_start(libxl_ctx *ctx, libxl_domain_remus_info *info, · line 743

Quoted 7 lines
tools/libxl/libxl.c +7 -0
+    /* convenience shorthand */
+    libxl__remus_state *remus_state = dss->remus_state;
+    remus_state->blackhole = info->blackhole;
+    remus_state->interval = info->interval;
+    remus_state->compression = info->compression;
+    remus_state->dss = dss;
+    libxl__ev_child_init(&remus_state->child);

AFAICT the main point of this patch seems to be to copy a bunch of configuration options from libxl_domain_remus_start's info argument into dss->remus_state.

I don't understand why this is desirable. Does the info argument not have a sufficient lifetime ?

Thanks,
Ian.

#6 lore raw

PATCH v7 4/10 remus: introduce a function to check whether network buffering is enabled

In reply to Lai Jiangshan

From: Shriram Rajagopalan <[email protected]>

libxl__netbuffer_enabled() returns 1 when network buffering is compiled, or returns 0 when network buffering is not compiled.

If network buffering is not compiled, and the user wants to use it, report a error and exit.

---
 tools/libxl/Makefile            |    7 +++++++
 tools/libxl/libxl.c             |    5 +++++
 tools/libxl/libxl_internal.h    |    2 ++
 tools/libxl/libxl_netbuffer.c   |   31 +++++++++++++++++++++++++++++++
 tools/libxl/libxl_nonetbuffer.c |   31 +++++++++++++++++++++++++++++++
 5 files changed, 76 insertions(+), 0 deletions(-)
 create mode 100644 tools/libxl/libxl_netbuffer.c
 create mode 100644 tools/libxl/libxl_nonetbuffer.c
tools/libxl/Makefile +7 -0
index da27c84..84a467c 100644
@@ -45,6 +45,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_ARM) += libxl_nocpuid.o libxl_arm.o
 
tools/libxl/libxl.c +5 -0
index 25af816..026206a 100644
@@ -746,6 +746,11 @@ int libxl_domain_remus_start(libxl_ctx *ctx, libxl_domain_remus_info *info,
 
     /* Setup network buffering */
     if (info->netbuf) {
+        if (!libxl__netbuffer_enabled(gc)) {
+            LOG(ERROR, "Remus: No support for network buffering");
+            goto out;
+        }
+
         if (info->netbufscript) {
             remus_state->netbufscript =
                 libxl__strdup(gc, info->netbufscript);
tools/libxl/libxl_internal.h +2 -0
index 9970780..2f64382 100644
@@ -2311,6 +2311,8 @@ typedef struct libxl__remus_state {
     libxl__ev_child child;
 } libxl__remus_state;
 
+_hidden int libxl__netbuffer_enabled(libxl__gc *gc);
+
 struct libxl__domain_suspend_state {
     /* set by caller of libxl__domain_suspend */
     libxl__ao *ao;
tools/libxl/libxl_netbuffer.c new file +31 -0
new file mode 100644
index 0000000..8e23d75
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2013
+ * Author Shriram Rajagopalan <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; version 2.1 only. with the special
+ * exception on linking described in file LICENSE.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ */
+
+#include "libxl_osdeps.h" /* must come before any other headers */
+
+#include "libxl_internal.h"
+
+int libxl__netbuffer_enabled(libxl__gc *gc)
+{
+    return 1;
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
tools/libxl/libxl_nonetbuffer.c new file +31 -0
new file mode 100644
index 0000000..6aa4bf1
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2013
+ * Author Shriram Rajagopalan <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; version 2.1 only. with the special
+ * exception on linking described in file LICENSE.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ */
+
+#include "libxl_osdeps.h" /* must come before any other headers */
+
+#include "libxl_internal.h"
+
+int libxl__netbuffer_enabled(libxl__gc *gc)
+{
+    return 0;
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
Signature · 1 line
1.7.1
#7 lore raw

Re: [PATCH 04/10 V7] remus: introduce a function to check whether network buffering is enabled

Lai Jiangshan writes ("[PATCH 04/10 V7] remus: introduce a function to check whether network buffering is enabled"):

Quoted 7 lines

From: Shriram Rajagopalan <[email protected]>

libxl__netbuffer_enabled() returns 1 when network buffering is compiled, or returns 0 when network buffering is not compiled.

If network buffering is not compiled, and the user wants to use it, report a error and exit.

The code here seems plausible but again it looks like it would be more sensibly part of some larger patch.

Thanks,
Ian.

#8 lore raw

PATCH v7 5/10 remus: Remus network buffering core and APIs to setup/teardown

In reply to Lai Jiangshan

From: Shriram Rajagopalan <[email protected]>

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.

The following steps are taken 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.

And during teardown, the netlink resources are released, followed by invocation of hotplug scripts to remove the IFB devices.

---
 docs/misc/xenstore-paths.markdown      |    4 +
 tools/hotplug/Linux/Makefile           |    1 +
 tools/hotplug/Linux/remus-netbuf-setup |  183 ++++++++++++
 tools/libxl/Makefile                   |    2 +
 tools/libxl/libxl_dom.c                |    7 +-
 tools/libxl/libxl_internal.h           |   17 ++
 tools/libxl/libxl_netbuffer.c          |  481 ++++++++++++++++++++++++++++++++
 tools/libxl/libxl_nonetbuffer.c        |   11 +
 tools/libxl/libxl_remus.c              |   41 +++
 9 files changed, 742 insertions(+), 5 deletions(-)
 create mode 100644 tools/hotplug/Linux/remus-netbuf-setup
 create mode 100644 tools/libxl/libxl_remus.c
docs/misc/xenstore-paths.markdown +4 -0
index 70ab7f4..7a0d2c9 100644
@@ -385,6 +385,10 @@ The guest's virtual time offset from UTC in seconds.
 
 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
index 47655f6..6139c1f 100644
@@ -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

tools/libxl/Makefile +2 -0
index 84a467c..218f55e 100644
@@ -52,6 +52,8 @@ else
 LIBXL_OBJS-y += libxl_nonetbuffer.o
 endif
 
+LIBXL_OBJS-y += libxl_remus.o
+
 LIBXL_OBJS-$(CONFIG_X86) += libxl_cpuid.o libxl_x86.o
 LIBXL_OBJS-$(CONFIG_ARM) += libxl_nocpuid.o libxl_arm.o
 
tools/libxl/libxl_dom.c +2 -5
index 8d63f90..e3e9f6f 100644
@@ -753,9 +753,6 @@ int libxl__toolstack_restore(uint32_t domid, const uint8_t *buf,
 
 /*==================== Domain suspend (save) ====================*/
 
-static void domain_suspend_done(libxl__egc *egc,
-                        libxl__domain_suspend_state *dss, int rc);
-
 /*----- complicated callback, called by xc_domain_save -----*/
 
 /*
@@ -1508,8 +1505,8 @@ static void save_device_model_datacopier_done(libxl__egc *egc,
     dss->save_dm_callback(egc, dss, our_rc);
 }
 
-static void domain_suspend_done(libxl__egc *egc,
-                        libxl__domain_suspend_state *dss, int rc)
+void domain_suspend_done(libxl__egc *egc,
+                         libxl__domain_suspend_state *dss, int rc)
 {
     STATE_AO_GC(dss->ao);
 
tools/libxl/libxl_internal.h +17 -0
index 2f64382..4006174 100644
@@ -2313,6 +2313,23 @@ typedef struct libxl__remus_state {
 
 _hidden int libxl__netbuffer_enabled(libxl__gc *gc);
 
+_hidden void domain_suspend_done(libxl__egc *egc,
+                                 libxl__domain_suspend_state *dss,
+                                 int rc);
+
+_hidden void libxl__remus_setup_done(libxl__egc *egc,
+                                     libxl__domain_suspend_state *dss,
+                                     int rc);
+
+_hidden void libxl__remus_netbuf_setup(libxl__egc *egc,
+                                       libxl__domain_suspend_state *dss);
+
+_hidden void libxl__remus_teardown_done(libxl__egc *egc,
+                                        libxl__domain_suspend_state *dss);
+
+_hidden void libxl__remus_netbuf_teardown(libxl__egc *egc,
+                                          libxl__domain_suspend_state *dss);
+
 struct libxl__domain_suspend_state {
     /* set by caller of libxl__domain_suspend */
     libxl__ao *ao;
tools/libxl/libxl_netbuffer.c +481 -0

492 lines not on this page · raw message

tools/libxl/libxl_nonetbuffer.c +11 -0
index 6aa4bf1..559d0a6 100644
@@ -22,6 +22,17 @@ int libxl__netbuffer_enabled(libxl__gc *gc)
     return 0;
 }
 
+/* Remus network buffer related stubs */
+void libxl__remus_netbuf_setup(libxl__egc *egc,
+                               libxl__domain_suspend_state *dss)
+{
+}
+
+void libxl__remus_netbuf_teardown(libxl__egc *egc,
+                                  libxl__domain_suspend_state *dss)
+{
+}
+
 /*
  * Local variables:
  * mode: C
tools/libxl/libxl_remus.c new file +41 -0

41 lines not on this page · raw message

Signature · 1 line
1.7.1
#9 lore raw

Re: [PATCH 05/10 V7] remus: Remus network buffering core and APIs to setup/teardown

Lai Jiangshan writes ("[PATCH 05/10 V7] remus: Remus network buffering core and APIs to setup/teardown"):

Thanks. I have reviewed much of this in some detail and have some comments.

docs/misc/xenstore-paths.markdown The guest's virtual time offset from UTC in seconds. · line 390

Quoted 9 lines
docs/misc/xenstore-paths.markdown +3 -0
@@ -385,6 +385,10 @@ The guest's virtual time offset from UTC in seconds.
 
 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.

I think this should expand "IFB". Also, are these interface buffer devices really called "IFB" and not "ifb" ?

Quoted 109 lines
tools/libxl/Makefile +2 -0
index 84a467c..218f55e 100644
@@ -52,6 +52,8 @@ else
 LIBXL_OBJS-y += libxl_nonetbuffer.o
 endif
 
+LIBXL_OBJS-y += libxl_remus.o
+
 LIBXL_OBJS-$(CONFIG_X86) += libxl_cpuid.o libxl_x86.o
 LIBXL_OBJS-$(CONFIG_ARM) += libxl_nocpuid.o libxl_arm.o
 
tools/libxl/libxl_dom.c +2 -5
index 8d63f90..e3e9f6f 100644
@@ -753,9 +753,6 @@ int libxl__toolstack_restore(uint32_t domid, const uint8_t *buf,
 
 /*==================== Domain suspend (save) ====================*/
 
-static void domain_suspend_done(libxl__egc *egc,
-                        libxl__domain_suspend_state *dss, int rc);
-
 /*----- complicated callback, called by xc_domain_save -----*/
 
 /*
@@ -1508,8 +1505,8 @@ static void save_device_model_datacopier_done(libxl__egc *egc,
     dss->save_dm_callback(egc, dss, our_rc);
 }
 
-static void domain_suspend_done(libxl__egc *egc,
-                        libxl__domain_suspend_state *dss, int rc)
+void domain_suspend_done(libxl__egc *egc,
+                         libxl__domain_suspend_state *dss, int rc)
 {
     STATE_AO_GC(dss->ao);
 
tools/libxl/libxl_internal.h +17 -0
index 2f64382..4006174 100644
@@ -2313,6 +2313,23 @@ typedef struct libxl__remus_state {
 
 _hidden int libxl__netbuffer_enabled(libxl__gc *gc);
 
+_hidden void domain_suspend_done(libxl__egc *egc,
+                                 libxl__domain_suspend_state *dss,
+                                 int rc);
+
+_hidden void libxl__remus_setup_done(libxl__egc *egc,
+                                     libxl__domain_suspend_state *dss,
+                                     int rc);
+
+_hidden void libxl__remus_netbuf_setup(libxl__egc *egc,
+                                       libxl__domain_suspend_state *dss);
+
+_hidden void libxl__remus_teardown_done(libxl__egc *egc,
+                                        libxl__domain_suspend_state *dss);
+
+_hidden void libxl__remus_netbuf_teardown(libxl__egc *egc,
+                                          libxl__domain_suspend_state *dss);
+
 struct libxl__domain_suspend_state {
     /* set by caller of libxl__domain_suspend */
     libxl__ao *ao;
tools/libxl/libxl_netbuffer.c +30 -0
index 8e23d75..2c77076 100644
@@ -17,11 +17,492 @@
 
 #include "libxl_internal.h"
 
+#include <netlink/cache.h>
+#include <netlink/socket.h>
+#include <netlink/attr.h>
+#include <netlink/route/link.h>
+#include <netlink/route/route.h>
+#include <netlink/route/qdisc.h>
+#include <netlink/route/qdisc/plug.h>
+
+typedef struct libxl__remus_netbuf_state {
+    struct rtnl_qdisc **netbuf_qdisc_list;
+    struct nl_sock *nlsock;
+    struct nl_cache *qdisc_cache;
+    const char **vif_list;
+    const char **ifb_list;
+    uint32_t num_netbufs;
+    uint32_t unused;
+} libxl__remus_netbuf_state;
+
 int libxl__netbuffer_enabled(libxl__gc *gc)
 {
     return 1;
 }
 
+/* If the device has a vifname, then use that instead of
+ * the vifX.Y format.
+ */
+static const char *get_vifname(libxl__gc *gc, uint32_t domid,
+                               libxl_device_nic *nic)
+{
+    const char *vifname = NULL;
+    const char *path;
+    int rc;
+
+    path = libxl__sprintf(gc, "%s/backend/vif/%d/%d/vifname",
+                          libxl__xs_get_dompath(gc, 0), domid, nic->devid);

tools/libxl/libxl_netbuffer.c line 64

Quoted 10 lines
tools/libxl/libxl_netbuffer.c +10 -0
+    rc = libxl__xs_read_checked(gc, XBT_NULL, path, &vifname);
+    if (!rc && !vifname) {
+        /* use the default name */
+        vifname = libxl__device_nic_devname(gc, domid,
+                                            nic->devid,
+                                            nic->nictype);
+    }
+
+    return vifname;
+}

I think the error handling here is rather odd. It would be better to use the "goto out" style. And the callers should treat NULL from this function as a fatal error.

tools/libxl/libxl_netbuffer.c line 76

Quoted 11 lines
tools/libxl/libxl_netbuffer.c +11 -0
+static const char **get_guest_vif_list(libxl__gc *gc, uint32_t domid,
+                                       int *num_vifs)
+{
+    libxl_device_nic *nics = NULL;
+    int nb, i = 0;
+    const char **vif_list = NULL;
+
+    *num_vifs = 0;
+    nics = libxl_device_nic_list(CTX, domid, &nb);
+    if (!nics)
+        return NULL;

It would be clearer IMO if this sayd "goto out";

tools/libxl/libxl_netbuffer.c line 89

Quoted 13 lines
tools/libxl/libxl_netbuffer.c +13 -0
+
+    /* Ensure that none of the vifs are backed by driver domains */
+    for (i = 0; i < nb; i++) {
+        if (nics[i].backend_domid != LIBXL_TOOLSTACK_DOMID) {
+            const char *vifname = get_vifname(gc, domid, &nics[i]);
+
+            if (!vifname)
+              vifname = "(unknown)";
+            LOG(ERROR, "vif %s has driver domain (%u) as its backend. "
+                "Network buffering is not supported with driver domains",
+                vifname, nics[i].backend_domid);
+            *num_vifs = -1;
+            goto out;

The error handling return style of this function is very odd and not documented.

tools/libxl/libxl_netbuffer.c line 117

Quoted 8 lines
tools/libxl/libxl_netbuffer.c +8 -0
+static void free_qdiscs(libxl__remus_netbuf_state *netbuf_state)
+{
+    int i;
+    struct rtnl_qdisc *qdisc = NULL;
+
+    /* free qdiscs */
+    for (i = 0; i < netbuf_state->num_netbufs; i++) {
+        qdisc = netbuf_state->netbuf_qdisc_list[i];

If you made this

           qdisc = &netbuf_state->netbuf_qdisc_list[i];
then you could say
           *qdisc = NULL;

and not have to write out the long expression again.

tools/libxl/libxl_netbuffer.c line 128

Quoted 4 lines
tools/libxl/libxl_netbuffer.c +4 -0
+    /* free qdisc cache */
+    if (netbuf_state->qdisc_cache) {
+      nl_cache_clear(netbuf_state->qdisc_cache);
+      nl_cache_free(netbuf_state->qdisc_cache);

Wrong indent level.

Quoted 3 lines
tools/libxl/libxl_netbuffer.c +3 -0
+static int init_qdiscs(libxl__gc *gc,
+                       libxl__remus_state *remus_state)
+{

...

Quoted 1 line

+ libxl__remus_netbuf_state * const netbuf_state = remus_state->netbuf_state;

                                  ^

Coding style (extra space).

Quoted 17 lines
tools/libxl/libxl_netbuffer.c +17 -0
+static void netbuf_setup_timeout_cb(libxl__egc *egc,
+                                    libxl__ev_time *ev,
+                                    const struct timeval *requested_abs)
+{
+    libxl__remus_state *remus_state = CONTAINER_OF(ev, *remus_state, timeout);
+
+    /* Convenience aliases */
+    const int devid = remus_state->dev_id;
+    libxl__remus_netbuf_state *const netbuf_state = remus_state->netbuf_state;
+    const char *const vif = netbuf_state->vif_list[devid];
+
+    STATE_AO_GC(remus_state->dss->ao);
+
+    libxl__ev_time_deregister(gc, &remus_state->timeout);
+    assert(libxl__ev_child_inuse(&remus_state->child));
+
+    LOG(DEBUG, "killing hotplug script %s (on vif %s) because of timeout",

tools/libxl/libxl_netbuffer.c line 261

Quoted 10 lines
tools/libxl/libxl_netbuffer.c +10 -0
+        remus_state->netbufscript, vif);
+
+    if (kill(remus_state->child.pid, SIGKILL)) {
+        LOGEV(ERROR, errno, "unable to kill hotplug script %s [%ld]",
+              remus_state->netbufscript,
+              (unsigned long)remus_state->child.pid);
+    }
+
+    return;
+}

This function bears a striking resemblance to device_hotplug_timeout_cb. Likewise parts of exec_netbuf_script look very much like parts of device_hotplug, etc.

You should arrange to reuse code rather than clone-and-hacking it, refactoring if necessary. If refactoring is necessary, that should be brought out into a pre-patch with no functional change.

Thanks,
Ian.

#10 lore raw

Re: [PATCH 05/10 V7] remus: Remus network buffering core and APIs to setup/teardown [and 1 more messages]

Yang Hongyang writes ("[PATCH V8 3/8] remus: Remus network buffering core and APIs to setup/teardown"):

Quoted 9 lines

1.Add two members in libxl_domain_remus_info:
netbuf: whether netbuf is enabled
netbufscript: the path of the script which will be run to setup
and tear down the guest's interface.
2.introduce a new structure libxl__remus_state to save the remus state 3.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.

Thanks for your submission.

However, the last time this was posted, I commented as follows:

Quoted 8 lines

This function [netbuf_setup_timeout_cb] bears a striking resemblance to device_hotplug_timeout_cb. Likewise parts of exec_netbuf_script look very much like parts of device_hotplug, etc.

You should arrange to reuse code rather than clone-and-hacking it, refactoring if necessary. If refactoring is necessary, that should be brought out into a pre-patch with no functional change.

It looks like several of my other comments haven't been taken into account, either.

Thanks,
Ian.

#11 lore raw

PATCH v7 6/10 remus: implement the API to buffer/release packages

In reply to Lai Jiangshan

From: Shriram Rajagopalan <[email protected]>

This patch implements two APIs:
1. libxl__remus_netbuf_start_new_epoch()
It marks a new epoch. The packages before this epoch will be flushed, and the packages after this epoch will be buffered. It will be called after the guest is suspended.
2. libxl__remus_netbuf_release_prev_epoch()
It flushes the buffered packages to client, and it will be called when a checkpoint finishes.

---
 tools/libxl/libxl_internal.h    |    6 ++++
 tools/libxl/libxl_netbuffer.c   |   49 +++++++++++++++++++++++++++++++++++++++
 tools/libxl/libxl_nonetbuffer.c |   14 +++++++++++
 3 files changed, 69 insertions(+), 0 deletions(-)
tools/libxl/libxl_internal.h +6 -0
index 4006174..c13296b 100644
@@ -2330,6 +2330,12 @@ _hidden void libxl__remus_teardown_done(libxl__egc *egc,
 _hidden void libxl__remus_netbuf_teardown(libxl__egc *egc,
                                           libxl__domain_suspend_state *dss);
 
+_hidden int libxl__remus_netbuf_start_new_epoch(libxl__gc *gc, uint32_t domid,
+                                               libxl__remus_state *remus_state);
+
+_hidden int libxl__remus_netbuf_release_prev_epoch(libxl__gc *gc, uint32_t domid,
+                                                  libxl__remus_state *remus_state);
+
 struct libxl__domain_suspend_state {
     /* set by caller of libxl__domain_suspend */
     libxl__ao *ao;
tools/libxl/libxl_netbuffer.c +49 -0

55 lines not on this page · raw message

tools/libxl/libxl_nonetbuffer.c +14 -0
index 559d0a6..92f35bc 100644
@@ -33,6 +33,20 @@ void libxl__remus_netbuf_teardown(libxl__egc *egc,
 {
 }
 
+int libxl__remus_netbuf_start_new_epoch(libxl__gc *gc, uint32_t domid,
+                                        libxl__remus_state *remus_state)
+{
+    LOG(ERROR, "Remus: No support for network buffering");
+    return ERROR_FAIL;
+}
+
+int libxl__remus_netbuf_release_prev_epoch(libxl__gc *gc, uint32_t domid,
+                                           libxl__remus_state *remus_state)
+{
+    LOG(ERROR, "Remus: No support for network buffering");
+    return ERROR_FAIL;
+}
+
 /*
  * Local variables:
  * mode: C
Signature · 1 line
1.7.1
#12 lore raw

Re: [PATCH 06/10 V7] remus: implement the API to buffer/release packages

Lai Jiangshan writes ("[PATCH 06/10 V7] remus: implement the API to buffer/release packages"):

Quoted 8 lines

This patch implements two APIs:
1. libxl__remus_netbuf_start_new_epoch()
It marks a new epoch. The packages before this epoch will be flushed, and the packages after this epoch will be buffered. It will be called after the guest is suspended.
2. libxl__remus_netbuf_release_prev_epoch()
It flushes the buffered packages to client, and it will be called when a checkpoint finishes.

Thanks.

Quoted 1 line

+_hidden int libxl__remus_netbuf_start_new_epoch(libxl__gc *gc, uint32_t dom\

id,

Quoted 1 line

+ libxl__remus_state *remus_st\

ate);

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+_hidden int libxl__remus_netbuf_release_prev_epoch(libxl__gc *gc, uint32_t \

domid,

Quoted 1 line

+ libxl__remus_state *remus\

_state);

I'd really appreciate it if you could wrap or otherwise reformat the long lines in these patches. As you can see, they appear on my screen with pretty bad wrap damage otherwise.

tools/libxl/libxl_netbuffer.c void libxl__remus_netbuf_teardown(libxl__egc *egc, · line 530

Quoted 9 lines
tools/libxl/libxl_netbuffer.c +9 -0
+        if (buffer_op == tc_buffer_start)
+            ret = rtnl_qdisc_plug_buffer(netbuf_state->netbuf_qdisc_list[i]);
+        else
+            ret = rtnl_qdisc_plug_release_one(netbuf_state->netbuf_qdisc_list[i]);
+
+        if (!ret)
+            ret = rtnl_qdisc_add(netbuf_state->nlsock,
+                                 netbuf_state->netbuf_qdisc_list[i],
+                                 NLM_F_REQUEST);

This error handling approach is unconventional for libxl. The correct approach would be to explicitly check after the first call. If you really want to have only one logging point, you can do that in your "out:" section (reached via "goto out").

I confess I don't understand why this patch is broken out at this point. It provides these two functions but not yet any callers. Is that right ?

Thanks,
Ian.

#13 lore raw

PATCH v7 7/10 libxl: use the API to setup/teardown network buffering

In reply to Lai Jiangshan

From: Shriram Rajagopalan <[email protected]>

If there is network buffering hotplug scripts, call libxl__remus_netbuf_setup() to setup the network buffering and libxl__remus_netbuf_teardown() to teardown network buffering.

---
 tools/libxl/libxl.c          |    6 +-----
 tools/libxl/libxl_dom.c      |   11 +++++++++++
 tools/libxl/libxl_internal.h |    7 +++++++
 tools/libxl/libxl_remus.c    |   23 +++++++++++++++++++++++
 4 files changed, 42 insertions(+), 5 deletions(-)
tools/libxl/libxl.c +1 -5
index 026206a..83d3772 100644
@@ -762,7 +762,7 @@ int libxl_domain_remus_start(libxl_ctx *ctx, libxl_domain_remus_info *info,
     }
 
     /* Point of no return */
-    libxl__domain_suspend(egc, dss);
+    libxl__remus_setup_initiate(egc, dss);
     return AO_INPROGRESS;
 
  out:
@@ -778,10 +778,6 @@ static void remus_failover_cb(libxl__egc *egc,
      * backup died or some network error occurred preventing us
      * from sending checkpoints.
      */
-
-    /* TBD: Remus cleanup - i.e. detach qdisc, release other
-     * resources.
-     */
     libxl__ao_complete(egc, ao, rc);
 }
 
tools/libxl/libxl_dom.c +11 -0
index e3e9f6f..912a6e4 100644
@@ -1519,6 +1519,17 @@ void domain_suspend_done(libxl__egc *egc,
     if (dss->xce != NULL)
         xc_evtchn_close(dss->xce);
 
+    if (dss->remus_state) {
+        /*
+         * 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_initiate(egc, dss, rc);
+        return;
+    }
+
     dss->callback(egc, dss, rc);
 }
 
tools/libxl/libxl_internal.h +7 -0
index c13296b..1bd2bba 100644
@@ -2336,6 +2336,13 @@ _hidden int libxl__remus_netbuf_start_new_epoch(libxl__gc *gc, uint32_t domid,
 _hidden int libxl__remus_netbuf_release_prev_epoch(libxl__gc *gc, uint32_t domid,
                                                   libxl__remus_state *remus_state);
 
+_hidden void libxl__remus_setup_initiate(libxl__egc *egc,
+                                         libxl__domain_suspend_state *dss);
+
+_hidden void libxl__remus_teardown_initiate(libxl__egc *egc,
+                                            libxl__domain_suspend_state *dss,
+                                            int rc);
+
 struct libxl__domain_suspend_state {
     /* set by caller of libxl__domain_suspend */
     libxl__ao *ao;
tools/libxl/libxl_remus.c +23 -0
index 4e40412..cdc1c16 100644
@@ -19,6 +19,16 @@
 
 /*----- remus setup/teardown code -----*/
 
+void libxl__remus_setup_initiate(libxl__egc *egc,
+                                 libxl__domain_suspend_state *dss)
+{
+    libxl__ev_time_init(&dss->remus_state->timeout);
+    if (!dss->remus_state->netbufscript)
+        libxl__remus_setup_done(egc, dss, 0);
+    else
+        libxl__remus_netbuf_setup(egc, dss);
+}
+
 void libxl__remus_setup_done(libxl__egc *egc,
                              libxl__domain_suspend_state *dss,
                              int rc)
@@ -34,6 +44,19 @@ void libxl__remus_setup_done(libxl__egc *egc,
     domain_suspend_done(egc, dss, rc);
 }
 
+void libxl__remus_teardown_initiate(libxl__egc *egc,
+                                    libxl__domain_suspend_state *dss,
+                                    int rc)
+{
+    /* stash rc somewhere before invoking teardown ops. */
+    dss->remus_state->saved_rc = rc;
+
+    if (!dss->remus_state->netbuf_state)
+        libxl__remus_teardown_done(egc, dss);
+    else
+        libxl__remus_netbuf_teardown(egc, dss);
+}
+
 void libxl__remus_teardown_done(libxl__egc *egc,
                                 libxl__domain_suspend_state *dss)
 {
Signature · 1 line
1.7.1
#14 lore raw

Re: [PATCH 07/10 V7] libxl: use the API to setup/teardown network buffering

Lai Jiangshan writes ("[PATCH 07/10 V7] libxl: use the API to setup/teardown network buffering"):

Quoted 7 lines

From: Shriram Rajagopalan <[email protected]>

If there is network buffering hotplug scripts, call libxl__remus_netbuf_setup() to setup the network buffering and libxl__remus_netbuf_teardown() to teardown network buffering.

tools/libxl/libxl_dom.c void domain_suspend_done(libxl__egc *egc, · line 1531

Quoted 10 lines
tools/libxl/libxl_dom.c +10 -0
+    if (dss->remus_state) {
+        /*
+         * 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_initiate(egc, dss, rc);
+        return;
+    }

This patch seems plausible. But I wonder if it might not be better to provide a firmer interface between the remus code and the rest of the save/restore machinery. That is, have an explicit callback function recorded by the save/restore code which is called back by the remus machinery when it has done its work. What do you think ?

I think having the flow of control spring off into libxl_remus.c and magically come back by libxl_remus.c knowing to call domain_suspend_done is rather opaque.

Thanks,
Ian.

#15 lore raw

Re: [PATCH 07/10 V7] libxl: use the API to setup/teardown network buffering [and 1 more messages]

Yang Hongyang writes ("[PATCH V9 05/12] remus: remus device core and APIs to setup/teardown"):

Quoted 7 lines
tools/libxl/libxl_internal.h +0 -0
index 33b62a2..421ae24 100644
@@ -2457,8 +2457,35 @@ typedef struct libxl__logdirty_switch {
     libxl__ev_time timeout;
 } libxl__logdirty_switch;

tools/libxl/libxl_internal.h typedef struct libxl__logdirty_switch { · line 2468

Quoted 10 lines
tools/libxl/libxl_internal.h +9 -0
 
+typedef struct libxl__remus_state {
+    libxl__domain_suspend_state *dss;
+    libxl__egc *egc;
+
+    /* private */
+    int saved_rc;
+    /* Opaque context containing device related stuff */
+    void *device_state;
+} libxl__remus_state;

I'm afraid that the interface between the remus code and the rest of the code is still not very clear.

Quoted 9 lines · Earlier, I wrote:

[...] I wonder if it might not be better to provide a firmer interface between the remus code and the rest of the save/restore machinery. That is, have an explicit callback function recorded by the save/restore code which is called back by the remus machinery when it has done its work. What do you think ?

I think having the flow of control spring off into libxl_remus.c and magically come back by libxl_remus.c knowing to call domain_suspend_done is rather opaque.

I think you have basically two options:

1. Make the remus part of this be a fully self-contained standard asynchronous callback-based suboperation, like libxl__xswait, libxl__bootloader, et al.

In this case you should rigorously follow the existing patterns, defining a clear interface between the two parts, providing a callback function set by the caller, etc.

2. Integrate the remus part into the suspend/resume code in an ad hoc fashion, with extremely clear comments everywhere about the expected interface, and no extraneous moving parts.

At the moment you seem to have mixed these two approaches.

tools/libxl/libxl_internal.h struct libxl__domain_suspend_state { · line 2500

Quoted 5 lines
tools/libxl/libxl_internal.h +1 -0
@@ -2470,6 +2497,7 @@ struct libxl__domain_suspend_state {
     int live;
     int debug;
     const libxl_domain_remus_info *remus;
+    libxl__remus_state *remus_state;

I'm not sure why this variable is called "remus_state" rather than just "remus".

tools/libxl/libxl_internal.h struct libxl__domain_suspend_state {

Quoted 8 lines
tools/libxl/libxl_internal.h +8 -0
+typedef struct libxl__remus_device_state {
+    /* nic */
+    libxl_device_nic *nics;
+    int num_nics;
+
+    /* disk */
+    libxl_device_disk *disks;
+    int num_disks;

Much of this doesn't seem be used in this patch. I think you may need to restructure your patch series.

In general, when patching existing code, you should introduce an internal structure or variable in the same patch as you introduce the code which uses it.

This is in contrast to new functions (or other facilities) with a well-defined API, where it is usually best to introduce the function fully-formed and then the callers.

Since I normally look at the header file first, to try to see what all the pieces are and what's going on, it's difficult for me to review this patch in more detail as it stands.

Thanks,
Ian.

#16 lore raw

Re: [PATCH 07/10 V7] libxl: use the API to setup/teardown network buffering [and 1 more messages]

Quoted 45 lines · Ian Jackson

Yang Hongyang writes ("[PATCH V9 05/12] remus: remus device core and APIs to setup/teardown"):

Quoted 7 lines
tools/libxl/libxl_internal.h +0 -0
index 33b62a2..421ae24 100644
@@ -2457,8 +2457,35 @@ typedef struct libxl__logdirty_switch {
     libxl__ev_time timeout;
 } libxl__logdirty_switch;

tools/libxl/libxl_internal.h typedef struct libxl__logdirty_switch { · line 2468

Quoted 10 lines
tools/libxl/libxl_internal.h +9 -0
 
+typedef struct libxl__remus_state {
+    libxl__domain_suspend_state *dss;
+    libxl__egc *egc;
+
+    /* private */
+    int saved_rc;
+    /* Opaque context containing device related stuff */
+    void *device_state;
+} libxl__remus_state;

I'm afraid that the interface between the remus code and the rest of the code is still not very clear.

Quoted 9 lines · Earlier, I wrote:

[...] I wonder if it might not be better to provide a firmer interface between the remus code and the rest of the save/restore machinery. That is, have an explicit callback function recorded by the save/restore code which is called back by the remus machinery when it has done its work. What do you think ?

I think having the flow of control spring off into libxl_remus.c and magically come back by libxl_remus.c knowing to call domain_suspend_done is rather opaque.

I think you have basically two options:

1. Make the remus part of this be a fully self-contained standard asynchronous callback-based suboperation, like libxl__xswait, libxl__bootloader, et al.

In this case you should rigorously follow the existing patterns, defining a clear interface between the two parts, providing a callback function set by the caller, etc.

Quoted 6 lines

2. Integrate the remus part into the suspend/resume code in an ad hoc fashion, with extremely clear comments everywhere about the expected interface, and no extraneous moving parts.

At the moment you seem to have mixed these two approaches.

Sorry, I missed the previous comment of yours. The two options you note are bit more clearer than the previous comment. And I also agree that the current approach is mixing options 1 & 2.

The entire Remus code (executed from start to end) is one giant async op. Internally, per checkpoint, the code executes for no more than tens of milliseconds at max, with the exception of sleeping until the next checkpoint
needs to be taken.

Doing checkpoint related work (i.e., syscalls to control disk/network buffers)
in an async op is an overkill. So, they are integrated into the suspend/resume
infrastructure (option 2)

The async op is useful (please correct me if I am wrong) if the op runs for a long time, such that you don't want users of libxl to block. Which is exactly
why the setup/teardown and the sleep_until_next_checkpoint operations are ao suboperations. (option 1).

All said, perhaps, it may be more clear to add a level of indirection:
make domain_suspend_done a callback field in libxl__domain_state.

Change all direct callers of domain_suspend_done to invoke this callback.

In this way,
* domain_suspend -> domain_suspend_done (for normal suspend/save operations)
* domain_remus_start->domain_remus_terminated

What do you think?

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#17 lore raw

Re: [PATCH 07/10 V7] libxl: use the API to setup/teardown network buffering [and 1 more messages]

Shriram Rajagopalan writes ("Re: [PATCH 07/10 V7] libxl: use the API to setup/teardown network buffering [and 1 more messages]"):

Quoted 16 lines

On Wed, Apr 23, 2014 at 11:02 AM, Ian Jackson <[email protected]> wrote:
I think you have basically two options:

1. Make the remus part of this be a fully self-contained standard asynchronous callback-based suboperation, like libxl__xswait, libxl__bootloader, et al.

In this case you should rigorously follow the existing patterns, defining a clear interface between the two parts, providing a callback function set by the caller, etc.

2. Integrate the remus part into the suspend/resume code in an ad hoc fashion, with extremely clear comments everywhere about the expected interface, and no extraneous moving parts.

Quoted 5 lines

At the moment you seem to have mixed these two approaches.

Sorry, I missed the previous comment of yours. The two options you note are bit more clearer than the previous comment. And I also agree that the current approach is mixing options 1 & 2.

Right.

Quoted 4 lines

The entire Remus code (executed from start to end) is one giant async op. Internally, per checkpoint, the code executes for no more than tens of milliseconds at max, with the exception of sleeping until the next checkpoint needs to be taken.

Yes.

Quoted 9 lines

Doing checkpoint related work (i.e., syscalls to control disk/network buffers) in an async op is an overkill. So, they are integrated into the suspend/resume infrastructure (option 2)

The async op is useful (please correct me if I am wrong) if the op runs for a long time, such that you don't want users of libxl to block. Which is exactly why the setup/teardown and the sleep_until_next_checkpoint operations are ao suboperations. (option 1).

This isn't quite the right distinction. You should use an asynchronous style for anything which might block. So it is OK to synchronously make fast syscalls. (I assume that the disk/network control syscalls are fast.)

And in this context, blocking includes child processes, and calls to (u)sleep.

Quoted 10 lines

All said, perhaps, it may be more clear to add a level of indirection:
make domain_suspend_done a callback field in libxl__domain_state.

Change all direct callers of domain_suspend_done to invoke this callback.

In this way,
* domain_suspend -> domain_suspend_done (for normal suspend/save operations)
* domain_remus_start->domain_remus_terminated

What do you think?

I'm not sure I quite follow but I think you are still mixing the two approaches I discuss above. I would like you to pick one.

If you're not sure, you should probably pick option 1.

Thanks,
Ian.

#18 lore raw

Re: [PATCH 07/10 V7] libxl: use the API to setup/teardown network buffering [and 1 more messages]

Quoted 2 lines · Ian Jackson

Shriram Rajagopalan writes ("Re: [PATCH 07/10 V7] libxl: use the API to

setup/teardown network buffering [and 1 more messages]"):

Quoted 9 lines
Quoted 9 lines

On Wed, Apr 23, 2014 at 11:02 AM, Ian Jackson <[email protected]

wrote:
I think you have basically two options:

1. Make the remus part of this be a fully self-contained standard asynchronous callback-based suboperation, like libxl__xswait, libxl__bootloader, et al.

Quoted 6 lines
Quoted 6 lines

In this case you should rigorously follow the existing patterns, defining a clear interface between the two parts, providing a callback function set by the caller, etc.

2. Integrate the remus part into the suspend/resume code in an ad hoc fashion, with extremely clear comments everywhere about

the

Quoted 27 lines
Quoted 7 lines

expected interface, and no extraneous moving parts.

At the moment you seem to have mixed these two approaches.

Sorry, I missed the previous comment of yours. The two options you note are bit more clearer than the previous comment. And I also agree that the current approach is mixing options 1 & 2.

Right.

Quoted 4 lines

The entire Remus code (executed from start to end) is one giant async op. Internally, per checkpoint, the code executes for no more than tens of milliseconds at max, with the exception of sleeping until the next checkpoint needs to be taken.

Yes.

Quoted 9 lines

Doing checkpoint related work (i.e., syscalls to control disk/network buffers) in an async op is an overkill. So, they are integrated into the suspend/resume infrastructure (option 2)

The async op is useful (please correct me if I am wrong) if the op runs for a long time, such that you don't want users of libxl to block. Which is exactly why the setup/teardown and the sleep_until_next_checkpoint operations are ao suboperations. (option 1).

Quoted 8 lines

This isn't quite the right distinction. You should use an asynchronous style for anything which might block. So it is OK to synchronously make fast syscalls. (I assume that the disk/network control syscalls are fast.)

And in this context, blocking includes child processes, and calls to (u)sleep.

Isn't that what the patches are doing currently?
Setup, teardown and (u)sleep are AO subops (following the option 1 style you suggested), while the rest of Remus code runs every checkpoint in non AO fashion (syscalls to disk, libnl calls (which in turn issue syscalls) for network)

Quoted 4 lines
Quoted 4 lines

All said, perhaps, it may be more clear to add a level of indirection:
make domain_suspend_done a callback field in libxl__domain_state.

Change all direct callers of domain_suspend_done to invoke this

callback.

Quoted 3 lines
Quoted 3 lines

In this way,
* domain_suspend -> domain_suspend_done (for normal suspend/save

operations)

Quoted 5 lines
Quoted 3 lines

* domain_remus_start->domain_remus_terminated

What do you think?

I'm not sure I quite follow

The indirection helps separate the control flow between Remus and non Remus executions. Currently both end up in domain_suspend_done which as you stated, seems ad-hoc, bolting the Remus error path into a function that is used for indicating completion of AO libxl calls like domain suspend, save, etc.
This suggestion was more inline with the option (1) you suggested.

Quoted 2 lines

but I think you are still mixing the two
approaches I discuss above.

But which parts of the code? As I said earlier, one part of the code (setup, teardown, etc) follows option 1, while the other path (per checkpoint execution) follows option 2, because they are not blocking in anyway.

Quoted 7 lines

I would like you to pick one.

If you're not sure, you should probably pick option 1.

Thanks,
Ian.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#19 lore raw

Re: [PATCH 07/10 V7] libxl: use the API to setup/teardown network buffering [and 1 more messages]

In reply to Ian Jackson

Hi Ian:

Quoted 56 lines · Ian Jackson

Shriram Rajagopalan writes ("Re: [PATCH 07/10 V7] libxl: use the API to setup/teardown network buffering [and 1 more messages]"):

Quoted 16 lines

On Wed, Apr 23, 2014 at 11:02 AM, Ian Jackson <[email protected]> wrote:
I think you have basically two options:

1. Make the remus part of this be a fully self-contained standard asynchronous callback-based suboperation, like libxl__xswait, libxl__bootloader, et al.

In this case you should rigorously follow the existing patterns, defining a clear interface between the two parts, providing a callback function set by the caller, etc.

2. Integrate the remus part into the suspend/resume code in an ad hoc fashion, with extremely clear comments everywhere about the expected interface, and no extraneous moving parts.

Quoted 5 lines

At the moment you seem to have mixed these two approaches.

Sorry, I missed the previous comment of yours. The two options you note are bit more clearer than the previous comment. And I also agree that the current approach is mixing options 1 & 2.

Right.

Quoted 4 lines

The entire Remus code (executed from start to end) is one giant async op. Internally, per checkpoint, the code executes for no more than tens of milliseconds at max, with the exception of sleeping until the next checkpoint needs to be taken.

Yes.

Quoted 9 lines

Doing checkpoint related work (i.e., syscalls to control disk/network buffers) in an async op is an overkill. So, they are integrated into the suspend/resume infrastructure (option 2)

The async op is useful (please correct me if I am wrong) if the op runs for a long time, such that you don't want users of libxl to block. Which is exactly why the setup/teardown and the sleep_until_next_checkpoint operations are ao suboperations. (option 1).

This isn't quite the right distinction. You should use an asynchronous style for anything which might block. So it is OK to synchronously make fast syscalls. (I assume that the disk/network control syscalls are fast.)

And in this context, blocking includes child processes, and calls to (u)sleep.

Quoted 9 lines

All said, perhaps, it may be more clear to add a level of indirection:
make domain_suspend_done a callback field in libxl__domain_state.

Change all direct callers of domain_suspend_done to invoke this callback.

In this way,
* domain_suspend -> domain_suspend_done (for normal suspend/save operations)
* domain_remus_start->domain_remus_terminated

Quoted 5 lines
Quoted 1 line

What do you think?

I'm not sure I quite follow but I think you are still mixing the two approaches I discuss above. I would like you to pick one.

If you're not sure, you should probably pick option 1.

This patchset is based on the current remus implementation (without netbuffer) witch is integrated into suspend/resume code, if as you suggested we pick option 1, the whole remus structure needs refactoring.
we're working on it, may take quiet a while.

Quoted 10 lines

Thanks,
Ian.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#20 lore raw

Re: [PATCH 07/10 V7] libxl: use the API to setup/teardown network buffering [and 1 more messages]

Quoted 76 lines · Hongyang Yang

Hi Ian:

On 05/03/2014 12:08 AM, Ian Jackson wrote:

Shriram Rajagopalan writes ("Re: [PATCH 07/10 V7] libxl: use the API to setup/teardown network buffering [and 1 more messages]"):

On Wed, Apr 23, 2014 at 11:02 AM, Ian Jackson <[email protected]> <[email protected]>
wrote:
I think you have basically two options:

1. Make the remus part of this be a fully self-contained standard asynchronous callback-based suboperation, like libxl__xswait, libxl__bootloader, et al.

In this case you should rigorously follow the existing patterns, defining a clear interface between the two parts, providing a callback function set by the caller, etc.

2. Integrate the remus part into the suspend/resume code in an ad hoc fashion, with extremely clear comments everywhere about the expected interface, and no extraneous moving parts.

At the moment you seem to have mixed these two approaches.

Sorry, I missed the previous comment of yours. The two options you note are bit more clearer than the previous comment. And I also agree that the current approach is mixing options 1 & 2.

Right.

The entire Remus code (executed from start to end) is one giant
async op. Internally, per checkpoint, the code executes for no more than tens of milliseconds at max, with the exception of sleeping until the next checkpoint needs to be taken.

Yes.

Doing checkpoint related work (i.e., syscalls to control
disk/network buffers) in an async op is an overkill. So, they are integrated into the suspend/resume infrastructure (option 2)

The async op is useful (please correct me if I am wrong) if the op runs for a long time, such that you don't want users of libxl to block. Which is exactly why the setup/teardown and the sleep_until_next_checkpoint operations are ao suboperations. (option 1).

This isn't quite the right distinction. You should use an
asynchronous style for anything which might block. So it is OK to synchronously make fast syscalls. (I assume that the disk/network control syscalls are fast.)

And in this context, blocking includes child processes, and calls to (u)sleep.

All said, perhaps, it may be more clear to add a level of indirection:
make domain_suspend_done a callback field in libxl__domain_state.

Change all direct callers of domain_suspend_done to invoke this callback.

In this way,
* domain_suspend -> domain_suspend_done (for normal suspend/save operations)
* domain_remus_start->domain_remus_terminated

What do you think?

I'm not sure I quite follow but I think you are still mixing the two
approaches I discuss above. I would like you to pick one.

If you're not sure, you should probably pick option 1.

Quoted 8 lines

This patchset is based on the current remus implementation (without netbuffer)
witch is integrated into suspend/resume code, if as you suggested we pick option 1,
the whole remus structure needs refactoring.
we're working on it, may take quiet a while.

Just to make sure I am on the same page with you folks,
Ian, when you talked about the two options (1) & (2), did you mean the entire remus implementation inside libxl or just "this" setup/teardown code base?

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#21 lore raw

Re: [PATCH 07/10 V7] libxl: use the API to setup/teardown network buffering [and 1 more messages]

Shriram Rajagopalan writes ("Re: [Xen-devel] [PATCH 07/10 V7] libxl: use the API to setup/teardown network buffering [and 1 more messages]"):

Quoted 1 line · Hongyang Yang

...

Quoted 5 lines

This patchset is based on the current remus implementation (without netbuffer) witch is integrated into suspend/resume code, if as you suggested we pick option 1, the whole remus structure needs refactoring. we're working on it, may take quiet a while.

...

Quoted 4 lines

Just to make sure I am on the same page with you folks,
Ian, when you talked about the two options (1) & (2), did you mean the entire remus implementation inside libxl or just "this" setup/teardown code base?

I think it is OK for some of the Remus code to fit into the rest of libxl code via method (1) and some via method (2).

But any particular subfunction should do strictly one or the other. I think, overall, (1) is better. It would be nice to do (1) everywhere. But a series can be acceptable even if it contains some (2).

Thanks,
Ian.

For reference, the (1) and (2) we are referring to are these:

1. Make the remus part of this be a fully self-contained standard asynchronous callback-based suboperation, like libxl__xswait, libxl__bootloader, et al.

In this case you should rigorously follow the existing patterns, defining a clear interface between the two parts, providing a callback function set by the caller, etc.

2. Integrate the remus part into the suspend/resume code in an ad hoc fashion, with extremely clear comments everywhere about the expected interface, and no extraneous moving parts.

I'm sure you know that but I wanted to save future readers, and anyone not following this in detail, the effort of chasing it down.

#22 lore raw

Re: [PATCH 07/10 V7] libxl: use the API to setup/teardown network buffering [and 1 more messages]

Quoted 14 lines · Ian Jackson

Shriram Rajagopalan writes ("Re: [Xen-devel] [PATCH 07/10 V7] libxl: use the API to setup/teardown network buffering [and 1 more messages]"):

Quoted 1 line · Hongyang Yang

...

Quoted 5 lines

This patchset is based on the current remus implementation (without netbuffer) witch is integrated into suspend/resume code, if as you suggested we pick option 1, the whole remus structure needs refactoring. we're working on it, may take quiet a while.

...

Quoted 4 lines

Just to make sure I am on the same page with you folks,
Ian, when you talked about the two options (1) & (2), did you mean the entire remus implementation inside libxl or just "this" setup/teardown code base?

Quoted 7 lines

I think it is OK for some of the Remus code to fit into the rest of libxl code via method (1) and some via method (2).

But any particular subfunction should do strictly one or the other. I think, overall, (1) is better. It would be nice to do (1) everywhere. But a series can be acceptable even if it contains some (2).

Thanks for the reply, that's more clear and solved my doubts too.

Thanks,
Yang.

Quoted 21 lines

Thanks,
Ian.

For reference, the (1) and (2) we are referring to are these:

1. Make the remus part of this be a fully self-contained standard asynchronous callback-based suboperation, like libxl__xswait, libxl__bootloader, et al.

In this case you should rigorously follow the existing patterns, defining a clear interface between the two parts, providing a callback function set by the caller, etc.

2. Integrate the remus part into the suspend/resume code in an ad hoc fashion, with extremely clear comments everywhere about the expected interface, and no extraneous moving parts.

I'm sure you know that but I wanted to save future readers, and anyone not following this in detail, the effort of chasing it down. .

#23 lore raw

PATCH v7 8/10 libxl: rename remus_failover_cb() to remus_replication_failure_cb()

In reply to Lai Jiangshan

From: Shriram Rajagopalan <[email protected]>

Failover means that: the machine on which primary vm is running is down, and we need to start the secondary vm to take over the primary vm. remus_failover_cb() is called when remus fails, not when we need to do failover. So rename it to remus_replication_failure_cb()

---
 tools/libxl/libxl.c |   12 +++++++-----
 1 files changed, 7 insertions(+), 5 deletions(-)
tools/libxl/libxl.c +7 -5
index 83d3772..70e34c0 100644
@@ -702,8 +702,9 @@ out:
     return ptr;
 }
 
-static void remus_failover_cb(libxl__egc *egc,
-                              libxl__domain_suspend_state *dss, int rc);
+static void remus_replication_failure_cb(libxl__egc *egc,
+                                         libxl__domain_suspend_state *dss,
+                                         int rc);
 
 /* TODO: Explicit Checkpoint acknowledgements via recv_fd. */
 int libxl_domain_remus_start(libxl_ctx *ctx, libxl_domain_remus_info *info,
@@ -722,7 +723,7 @@ int libxl_domain_remus_start(libxl_ctx *ctx, libxl_domain_remus_info *info,
 
     GCNEW(dss);
     dss->ao = ao;
-    dss->callback = remus_failover_cb;
+    dss->callback = remus_replication_failure_cb;
     dss->domid = domid;
     dss->fd = send_fd;
     /* TODO do something with recv_fd */
@@ -769,8 +770,9 @@ int libxl_domain_remus_start(libxl_ctx *ctx, libxl_domain_remus_info *info,
     return AO_ABORT(rc);
 }
 
-static void remus_failover_cb(libxl__egc *egc,
-                              libxl__domain_suspend_state *dss, int rc)
+static void remus_replication_failure_cb(libxl__egc *egc,
+                                         libxl__domain_suspend_state *dss,
+                                         int rc)
 {
     STATE_AO_GC(dss->ao);
     /*
Signature · 1 line
1.7.1
Acked-by on v7 8/10
#24 lore raw

Re: [PATCH 08/10 V7] libxl: rename remus_failover_cb() to remus_replication_failure_cb()

Lai Jiangshan writes ("[PATCH 08/10 V7] libxl: rename remus_failover_cb() to remus_replication_failure_cb()"):

Quoted 10 lines

From: Shriram Rajagopalan <[email protected]>

Failover means that: the machine on which primary vm is running is down, and we need to start the secondary vm to take over the primary vm. remus_failover_cb() is called when remus fails, not when we need to do failover. So rename it to remus_replication_failure_cb()

Thanks.

#25 lore raw

PATCH v7 9/10 libxl: control network buffering in remus callbacks

In reply to Lai Jiangshan

From: Shriram Rajagopalan <[email protected]>

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 |   90 ++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 82 insertions(+), 8 deletions(-)
tools/libxl/libxl_dom.c +82 -8
index 912a6e4..a4ffdfd 100644
@@ -1243,8 +1243,30 @@ int libxl__toolstack_save(uint32_t domid, uint8_t **buf,
 
 static int libxl__remus_domain_suspend_callback(void *data)
 {
-    /* REMUS TODO: Issue disk and network checkpoint reqs. */
-    return libxl__domain_suspend_common_callback(data);
+    libxl__save_helper_state *shs = data;
+    libxl__domain_suspend_state *dss = CONTAINER_OF(shs, *dss, shs);
+
+    /* Convenience aliases */
+    libxl__remus_state *const remus_state = dss->remus_state;
+
+    STATE_AO_GC(dss->ao);
+
+    /* REMUS TODO: Issue disk checkpoint reqs. */
+    int ok = libxl__domain_suspend_common_callback(data);
+
+    if (!remus_state->netbuf_state || !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_state))
+        ok = 0;
+
+ out:
+    return ok;
 }
 
 static int libxl__remus_domain_resume_callback(void *data)
@@ -1257,7 +1279,7 @@ static int libxl__remus_domain_resume_callback(void *data)
     if (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;
 }
 
@@ -1266,11 +1288,17 @@ static int libxl__remus_domain_resume_callback(void *data)
 static 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;
     libxl__domain_suspend_state *dss = CONTAINER_OF(shs, *dss, shs);
-    libxl__egc *egc = dss->shs.egc;
+
+    /* Convenience aliases */
+    libxl__egc *const egc = dss->shs.egc;
+
     STATE_AO_GC(dss->ao);
 
     /* This would go into tailbuf. */
@@ -1284,10 +1312,56 @@ static void libxl__remus_domain_checkpoint_callback(void *data)
 static 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_state->interval * 1000);
+    /* Convenience aliases */
+    /*
+     * REMUS TODO: Wait for disk and explicit memory ack (through restore
+     * callback from remote) before releasing network buffer.
+     */
+    libxl__remus_state *const remus_state = dss->remus_state;
+
+    STATE_AO_GC(dss->ao);
+
+    if (rc) {
+        LOG(ERROR, "Failed to save device model. Terminating Remus..");
+        goto out;
+    }
+
+    if (remus_state->netbuf_state) {
+        rc = libxl__remus_netbuf_release_prev_epoch(gc, dss->domid,
+                                                    remus_state);
+        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_state->timeout,
+                                     remus_next_checkpoint,
+                                     dss->remus_state->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_state *remus_state = CONTAINER_OF(ev, *remus_state, timeout);
+
+    /* Convenience aliases */
+    libxl__domain_suspend_state *const dss = remus_state->dss;
+
+    STATE_AO_GC(dss->ao);
+
+    libxl__ev_time_deregister(gc, &remus_state->timeout);
     libxl__xc_domain_saverestore_async_callback_done(egc, &dss->shs, 1);
 }
 
Signature · 1 line
1.7.1
#26 lore raw

Re: [PATCH 09/10 V7] libxl: control network buffering in remus callbacks

Lai Jiangshan writes ("[PATCH 09/10 V7] libxl: control network buffering in remus callbacks"):

Quoted 9 lines

From: Shriram Rajagopalan <[email protected]>

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)

Quoted 3 lines

Thanks. This looks plausible but I would like to review it in the context of the whole series. This would be a lot easier if I had the whole series available to be as a git repo.

So when you repost this, can you also please provide me with a public git url to fetch the branch from ?

Thanks,
Ian.

#27 lore raw

PATCH v7 10/10 libxl: network buffering cmdline switch

In reply to Lai Jiangshan

From: Shriram Rajagopalan <[email protected]>

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.

Note: the network buffering is enabled as default. If you want to disable it, please use -n option.

---
 docs/man/xl.conf.pod.5    |    6 ++++++
 docs/man/xl.pod.1         |   11 ++++++++++-
 tools/libxl/xl.c          |    4 ++++
 tools/libxl/xl.h          |    1 +
 tools/libxl/xl_cmdimpl.c  |   28 ++++++++++++++++++++++------
 tools/libxl/xl_cmdtable.c |    3 +++
 6 files changed, 46 insertions(+), 7 deletions(-)
docs/man/xl.conf.pod.5 +6 -0
index 7c43bde..8ae19bb 100644
@@ -105,6 +105,12 @@ Configures the default gateway device to set for virtual network devices.
 
 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 +10 -1
index e7b9de2..3c5f246 100644
@@ -399,7 +399,7 @@ 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.
+     There is no support for disk buffering at the moment.
 
 B<OPTIONS>
 
@@ -418,6 +418,15 @@ Generally useful for debugging.
 
 Disable memory checkpoint compression.
 
+=item B<-n>
+
+Disable network output buffering.
+
+=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
index 657610b..e02a618 100644
@@ -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 char *configfile,
     if (!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
index c876a33..d991fd3 100644
@@ -153,6 +153,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 +22 -6
index aff6f90..6d41775 100644
@@ -7265,8 +7265,9 @@ int main_remus(int argc, char **argv)
     r_info.interval = 200;
     r_info.blackhole = 0;
     r_info.compression = 1;
+    r_info.netbuf = 1;
 
-    SWITCH_FOREACH_OPT(opt, "bui:s:e", NULL, "remus", 2) {
+    SWITCH_FOREACH_OPT(opt, "buni:s:N:e", NULL, "remus", 2) {
     case 'i':
         r_info.interval = atoi(optarg);
         break;
@@ -7276,6 +7277,12 @@ int main_remus(int argc, char **argv)
     case 'u':
         r_info.compression = 0;
         break;
+    case 'n':
+        r_info.netbuf = 0;
+        break;
+    case 'N':
+        r_info.netbufscript = optarg;
+        break;
     case 's':
         ssh_command = optarg;
         break;
@@ -7287,6 +7294,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) {
@@ -7324,13 +7334,19 @@ 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.
-     * TODO: Split-Brain check.
+    /* check if the domain exists. User may have xl destroyed the
+     * domain to force failover
      */
-    fprintf(stderr, "remus sender: libxl_domain_suspend failed"
-            " (rc=%d)\n", rc);
+    if (libxl_domain_info(ctx, 0, domid)) {
+        fprintf(stderr, "Remus: Primary domain has been destroyed.\n");
+        close(send_fd);
+        return 0;
+    }
 
+    /* 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.
+     */
     if (rc == ERROR_GUEST_TIMEDOUT)
         fprintf(stderr, "Failed to suspend domain at primary.\n");
     else {
tools/libxl/xl_cmdtable.c +3 -0
index ebe0220..9b7104c 100644
@@ -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                      Disable 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"
Signature · 1 line
1.7.1
#28 lore raw

Re: [PATCH 10/10 V7] libxl: network buffering cmdline switch

Lai Jiangshan writes ("[PATCH 10/10 V7] libxl: network buffering cmdline switch"):

Quoted 9 lines

From: Shriram Rajagopalan <[email protected]>

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.

Note: the network buffering is enabled as default. If you want to disable it, please use -n option.

...

docs/man/xl.conf.pod.5 Configures the default gateway device to set for virtual network devices. · line 110

Quoted 11 lines
docs/man/xl.conf.pod.5 +3 -0
index 7c43bde..8ae19bb 100644
@@ -105,6 +105,12 @@ Configures the default gateway device to set for virtual network devices.
 
 Default: C<None>
 
+=item B<remus.default.netbufscript="PATH">
+
+Configures the default script used by Remus to setup network buffering.

You provide a global option to control the script, but no per-domain config option. Why ?

docs/man/xl.conf.pod.5 int main_remus(int argc, char **argv) · line 7297

Quoted 5 lines
docs/man/xl.conf.pod.5 +1 -0
@@ -7287,6 +7294,9 @@ int main_remus(int argc, char **argv)
     domid = find_domain(argv[optind]);
     host = argv[optind + 1];
 
+    if(!r_info.netbufscript)
         ^

Coding style (missing space).

...

docs/man/xl.conf.pod.5 int main_remus(int argc, char **argv) · line 7301

Quoted 4 lines
docs/man/xl.conf.pod.5 +4 -0
+    if (libxl_domain_info(ctx, 0, domid)) {
+        fprintf(stderr, "Remus: Primary domain has been destroyed.\n");
+        close(send_fd);
+        return 0;

You should not assume that any error means that the domain has been destroyed. Rather you should check the error code.

docs/man/xl.conf.pod.5 int main_remus(int argc, char **argv)

Quoted 3 lines
docs/man/xl.conf.pod.5 +2 -0
 > +    /* 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.

What are your plans for the split brain check ?

Thanks,
Ian.

#29 lore raw
In reply to Lai Jiangshan

Hi, Ian Campbell, Ian Jackson

Ping.
This patchset is ready for 4.5-unstable.
It went through several rounds and got decent reviews&comments.

Could you merge it for 4.5-unstable. Or any comments?

Thanks,
Lai

Quoted 144 lines · Lai Jiangshan

This patch series adds support for network buffering in the Remus codebase in libxl.

Changes in V7:
Applied missing comments(by IanJ).
Applied Shriram comments.

merge netbufering tangled setup/teardown code into one patch. (2/6/8 in V6 => 5 in V7. 9/10 in V6 => 7 in V7)

Changes in V6:
Applied Ian Jackson's comments of V5 series. the [PATCH 2/4 V5] is split by small functionalities.

[PATCH 4/4 V5] --> [PATCH 13/13] netbuffer is default enabled.

Changes in V5:

Merge hotplug script patch (2/5) and hotplug script setup/teardown patch (3/5) into a single patch.

Changes in V4:

[1/5] Remove check for libnl command line utils in autoconf checks

[2/5] minor nits

[3/5] define LIBXL_HAVE_REMUS_NETBUF in libxl.h

[4/5] clean ups. Make the usleep in checkpoint callback asynchronous

[5/5] minor nits

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(by shriram):

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
Lai

Shriram Rajagopalan (8):
remus: add libnl3 dependency to autoconf scripts tools/libxl: update libxl_domain_remus_info
tools/libxl: introduce a new structure libxl__remus_state
remus: introduce a function to check whether network buffering is
enabled
remus: Remus network buffering core and APIs to setup/teardown
remus: implement the APIs to buffer/release packages
libxl: use the APIs to setup/teardown network buffering
libxl: rename remus_failover_cb() to remus_replication_failure_cb()
libxl: control network buffering in remus callbacks
libxl: network buffering cmdline switch

 README                                 |    4 +
 config/Tools.mk.in                     |    3 +
 docs/man/xl.conf.pod.5                 |    6 +
 docs/man/xl.pod.1                      |   11 +-
 docs/misc/xenstore-paths.markdown      |    4 +
 tools/configure.ac                     |   15 +
 tools/hotplug/Linux/Makefile           |    1 +
 tools/hotplug/Linux/remus-netbuf-setup |  183 +++++++++++
 tools/libxl/Makefile                   |   11 +
 tools/libxl/libxl.c                    |   48 ++-
 tools/libxl/libxl.h                    |   13 +
 tools/libxl/libxl_dom.c                |  118 ++++++--
 tools/libxl/libxl_internal.h           |   54 +++-
 tools/libxl/libxl_netbuffer.c          |  561 ++++++++++++++++++++++++++++++++
 tools/libxl/libxl_nonetbuffer.c        |   56 ++++
 tools/libxl/libxl_remus.c              |   64 ++++
 tools/libxl/libxl_types.idl            |    2 +
 tools/libxl/xl.c                       |    4 +
 tools/libxl/xl.h                       |    1 +
 tools/libxl/xl_cmdimpl.c               |   28 ++-
 tools/libxl/xl_cmdtable.c              |    3 +
 tools/remus/README                     |    6 +
 22 files changed, 1155 insertions(+), 41 deletions(-)
 create mode 100644 tools/hotplug/Linux/remus-netbuf-setup
 create mode 100644 tools/libxl/libxl_netbuffer.c
 create mode 100644 tools/libxl/libxl_nonetbuffer.c
 create mode 100644 tools/libxl/libxl_remus.c
#30 lore raw

RFC PATCH 1/1 remus: implement remus replicated checkpointing disk

In reply to Lai Jiangshan

This patch implements remus replicated checkpointing disk. It includes two parts:
generic remus replicated checkpointing disks framework drbd replicated checkpointing disks
They will be split into different files in next round.

The patch is still simple due to disk-setup-teardown-script is still under implementing. I need to use libxl_ao to implement it, but libxl_ao is hard to use. The work sequence is needed to ugly split to serveral callbacks like device_hotplug().

And becuase the remus disk script is unimplemented, the drbd_setup() code can't check the disk now. So it just assumes the user config the disk correctly.

This patch is *UNTESTED*.
(there is a problem with xl&drbd(without remus) in my BOXes).

I request *comments* as many as possible.

Thanks,
Lai

---
 tools/libxl/Makefile                      |    1 +
 tools/libxl/libxl_dom.c                   |   19 +++-
 tools/libxl/libxl_internal.h              |   10 ++
 tools/libxl/libxl_remus.c                 |    2 +
 tools/libxl/libxl_remus_replicated_disk.c |  219 +++++++++++++++++++++++++++++
 5 files changed, 249 insertions(+), 2 deletions(-)
 create mode 100644 tools/libxl/libxl_remus_replicated_disk.c
tools/libxl/Makefile +1 -0
index 218f55e..dbf5dd9 100644
@@ -53,6 +53,7 @@ LIBXL_OBJS-y += libxl_nonetbuffer.o
 endif
 
 LIBXL_OBJS-y += libxl_remus.o
+LIBXL_OBJS-y += libxl_remus_replicated_disk.o
 
 LIBXL_OBJS-$(CONFIG_X86) += libxl_cpuid.o libxl_x86.o
 LIBXL_OBJS-$(CONFIG_ARM) += libxl_nocpuid.o libxl_arm.o
tools/libxl/libxl_dom.c +17 -2
index a4ffdfd..858f5be 100644
@@ -1251,9 +1251,14 @@ static int libxl__remus_domain_suspend_callback(void *data)
 
     STATE_AO_GC(dss->ao);
 
-    /* REMUS TODO: Issue disk checkpoint reqs. */
     int ok = libxl__domain_suspend_common_callback(data);
 
+    /* Issue disk checkpoint reqs. */
+    if (libxl__remus_disks_postsuspend(remus_state)) {
+        ok = 0;
+        goto out;
+    }
+
     if (!remus_state->netbuf_state || !ok) goto out;
 
     /* The domain was suspended successfully. Start a new network
@@ -1279,7 +1284,10 @@ static int libxl__remus_domain_resume_callback(void *data)
     if (libxl__domain_resume(gc, dss->domid, /* Fast Suspend */1))
         return 0;
 
-    /* REMUS TODO: Deal with disk. */
+    /* Deal with disk. */
+    if (libxl__remus_disks_preresume(dss->remus_state))
+        return 0;
+
     return 1;
 }
 
@@ -1326,6 +1334,13 @@ static void remus_checkpoint_dm_saved(libxl__egc *egc,
         goto out;
     }
 
+    rc = libxl__remus_disks_commit(remus_state);
+    if (rc) {
+        LOG(ERROR, "Failed to commit disks state"
+            " Terminating Remus..");
+        goto out;
+    }
+
     if (remus_state->netbuf_state) {
         rc = libxl__remus_netbuf_release_prev_epoch(gc, dss->domid,
                                                     remus_state);
tools/libxl/libxl_internal.h +10 -0
index 1bd2bba..8933e5f 100644
@@ -2309,6 +2309,10 @@ typedef struct libxl__remus_state {
     void *netbuf_state;
     libxl__ev_time timeout;
     libxl__ev_child child;
+
+    /* remus disks state */
+    uint32_t nr_disks;
+    struct libxl__remus_disk **disks;
 } libxl__remus_state;
 
 _hidden int libxl__netbuffer_enabled(libxl__gc *gc);
@@ -2336,6 +2340,12 @@ _hidden int libxl__remus_netbuf_start_new_epoch(libxl__gc *gc, uint32_t domid,
 _hidden int libxl__remus_netbuf_release_prev_epoch(libxl__gc *gc, uint32_t domid,
                                                   libxl__remus_state *remus_state);
 
+_hidden int libxl__remus_disks_postsuspend(libxl__remus_state *state);
+_hidden int libxl__remus_disks_preresume(libxl__remus_state *state);
+_hidden int libxl__remus_disks_commit(libxl__remus_state *state);
+_hidden int libxl__remus_disks_setup(libxl__egc *egc, libxl__domain_suspend_state *dss);
+_hidden void libxl__remus_disks_teardown(libxl__remus_state *state);
+
 _hidden void libxl__remus_setup_initiate(libxl__egc *egc,
                                          libxl__domain_suspend_state *dss);
 
tools/libxl/libxl_remus.c +2 -0
index cdc1c16..92eb36a 100644
@@ -23,6 +23,7 @@ void libxl__remus_setup_initiate(libxl__egc *egc,
                                  libxl__domain_suspend_state *dss)
 {
     libxl__ev_time_init(&dss->remus_state->timeout);
+    libxl__remus_disks_setup(egc, dss);
     if (!dss->remus_state->netbufscript)
         libxl__remus_setup_done(egc, dss, 0);
     else
@@ -51,6 +52,7 @@ void libxl__remus_teardown_initiate(libxl__egc *egc,
     /* stash rc somewhere before invoking teardown ops. */
     dss->remus_state->saved_rc = rc;
 
+    libxl__remus_disks_teardown(dss->remus_state);
     if (!dss->remus_state->netbuf_state)
         libxl__remus_teardown_done(egc, dss);
     else
tools/libxl/libxl_remus_replicated_disk.c new file +219 -0

219 lines not on this page · raw message

Signature · 1 line
1.7.1
#31 lore raw

Re: [PATCH RFC] remus: implement remus replicated checkpointing disk

Lai Jiangshan writes ("[PATCH RFC] remus: implement remus replicated checkpointing disk"):

Quoted 2 lines

This patch implements remus replicated checkpointing disk. It includes two parts:

...

Quoted 1 line

I request *comments* as many as possible.

Thanks for posting this so early. It's very helpful to be able to review it before it's been polished. Sorry it's taken a while to reply:

tools/libxl/libxl_dom.c static int libxl__remus_domain_suspend_callback(void *data)

Quoted 5 lines
tools/libxl/libxl_dom.c +0 -0
index a4ffdfd..858f5be 100644
@@ -1251,9 +1251,14 @@ static int libxl__remus_domain_suspend_callback(void *data)

These parts seem reasonable.

tools/libxl/libxl_dom.c static void remus_checkpoint_dm_saved(libxl__egc *egc, · line 1340

Quoted 4 lines
tools/libxl/libxl_dom.c +4 -0
+    rc = libxl__remus_disks_commit(remus_state);
+    if (rc) {
+        LOG(ERROR, "Failed to commit disks state"
+            " Terminating Remus..");

Why do we log a message hear but not in the other
libxl__remus_disks_foo failure cases ?

tools/libxl/libxl_remus.c void libxl__remus_setup_initiate(libxl__egc *egc, · line 26

Quoted 9 lines
tools/libxl/libxl_remus.c +1 -0
index cdc1c16..92eb36a 100644
@@ -23,6 +23,7 @@ void libxl__remus_setup_initiate(libxl__egc *egc,
                                  libxl__domain_suspend_state *dss)
 {
     libxl__ev_time_init(&dss->remus_state->timeout);
+    libxl__remus_disks_setup(egc, dss);

I think this is going to have to be an asynchronous function (ie, use a callback style), as it's going to want to run scripts. Likewise the teardown.

tools/libxl/libxl_remus.c void libxl__remus_setup_initiate(libxl__egc *egc, · line 29

Quoted 3 lines
tools/libxl/libxl_remus.c +3 -0
+/*** drbd implementation ***/
+const int DRBD_SEND_CHECKPOINT = 20;
+const int DRBD_WAIT_CHECKPOINT_ACK = 30;

These should be "static" as well as "const".

tools/libxl/libxl_remus.c void libxl__remus_setup_initiate(libxl__egc *egc,

Quoted 2 lines
tools/libxl/libxl_remus.c +2 -0
+typedef struct libxl__remus_drbd_disk
+{

Our coding style reserves "{" in the LH column for functions, so your struct definitions should have the "{" on the end of the previous line. See libxl__device and libxl__ev_watch_slot for examples.

tools/libxl/libxl_remus.c

Quoted 7 lines
tools/libxl/libxl_remus.c +7 -0
+static int drbd_postsuspend(libxl__remus_disk *d)
+{
+    struct libxl__remus_drbd_disk *drbd = CONTAINER_OF(d, *drbd, remus_disk);
+
+    if (!drbd->ackwait) {
+        if (ioctl(drbd->ctl_fd, DRBD_SEND_CHECKPOINT, 0) <= 0)
+            drbd->ackwait = 1;

This seems to make some assumption about return values, or lack of errors, or something. I would expect to see some error handling here.

tools/libxl/libxl_remus.c

Quoted 5 lines
tools/libxl/libxl_remus.c +5 -0
+static int drbd_commit(libxl__remus_disk *d)
+{
+    /* nothing to do, all work are done by DRBD's protocal-D. */
+    return 0;
+}

I'm not sure I understand how this can be true. Can you point me at an explanation of the supposed semantics of the remus disk commit ? (Eg in a remus design document or even a paper.) I suspect something ought to be done here.

Quoted 1 line

+static libxl__remus_disk *drbd_setup(libxl__gc *gc, libxl_device_disk *disk)

...

Quoted 1 line

+ drbd->ctl_fd = open(GCSPRINTF("/dev/drbd/by-res/%s", disk->pdev_path), O_RDONLY);

This line could do with wrapping. And your error handling is a bit nugatory, I think - surely something should be logged here ?

tools/libxl/libxl_remus.c

Quoted 7 lines
tools/libxl/libxl_remus.c +7 -0
+static const libxl__remus_disk_type drbd_disk_type = {
+  .postsuspend = drbd_postsuspend,
+  .preresume = drbd_preresume,
+  .commit = drbd_commit,
+  .setup = drbd_setup,
+  .teardown = drbd_teardown,
+};

I like this vtable approach.

tools/libxl/libxl_remus.c

Quoted 10 lines
tools/libxl/libxl_remus.c +10 -0
+int libxl__remus_disks_postsuspend(libxl__remus_state *state)
+{
+    int i;
+    int rc = 0;
+
+    for (i = 0; rc == 0 && i < state->nr_disks; i++)
+        rc = state->disks[i]->type->postsuspend(state->disks[i]);
+
+    return rc;
+}

I think the error handling in these functions isn't correct.

Also, there are several almost-identical functions. Can you consider whether you can write a macro to define them, or perhaps use offsetof to write a generic version of the function, or something ?

tools/libxl/libxl_remus.c

Quoted 4 lines
tools/libxl/libxl_remus.c +4 -0
+#if 0
+/* TODO: implement disk setup/teardown script */
+static void disk_exec_timeout_cb(libxl__egc *egc, libxl__ev_time *ev,
+                                      const struct timeval *requested_abs)

This will probably be easier after the refactoring needed to tease out the common script invocation code for the network buffering.

tools/libxl/libxl_remus.c

Quoted 10 lines
tools/libxl/libxl_remus.c +10 -0
+int libxl__remus_disks_setup(libxl__egc *egc, libxl__domain_suspend_state *dss)
+{
+    libxl__remus_state *remus_state = dss->remus_state;
+    int i, j, nr_disks;
+    libxl_device_disk *disks;
+    libxl__remus_disk *remus_disk;
+    const libxl__remus_disk_type *type;
+
+    STATE_AO_GC(dss->ao);
+    disks = libxl_device_disk_list(CTX, dss->domid, &nr_disks);

disks doesn't come from the gc, so you need to free it. You should initialise it to 0 (NULL), and use the "goto out" error handling style.

Quoted 5 lines
tools/libxl/libxl_remus.c +5 -0
+    remus_state->nr_disks = nr_disks;
+    GCNEW_ARRAY(remus_state->disks, nr_disks);
+
+    for (i = 0; i < nr_disks; i++) {
+        remus_disk = NULL;

tools/libxl/libxl_remus.c

Quoted 10 lines
tools/libxl/libxl_remus.c +10 -0
+        for (j = 0; j < ARRAY_SIZE(remus_disk_types); j++) {
+            type = remus_disk_types[j];
+            remus_disk = type->setup(gc, &disks[i]);
+            if (!remus_disk)
+                break;
+
+            remus_state->disks[i] = remus_disk;
+            remus_disk->disk = &disks[i];
+            remus_disk->type = type;
+        }

I think this code is wrong. It appears to call all of the setup functions, not just one, and overwrite remus_disk with their successive results.

tools/libxl/libxl_remus.c

Quoted 2 lines
tools/libxl/libxl_remus.c +2 -0
+        if (!remus_disk) {
+            remus_state->nr_disks = i;

You may find this easier to write with the "goto found" / "found:" search loop idiom. See "childproc_checkall" in libxl_fork.c for an example.

Thanks,
Ian.

#32 lore raw

Re: [PATCH RFC] remus: implement remus replicated checkpointing disk

Quoted 65 lines · Ian Jackson

Lai Jiangshan writes ("[PATCH RFC] remus: implement remus replicated checkpointing disk"):

Quoted 2 lines

This patch implements remus replicated checkpointing disk. It includes two parts:

...

Quoted 1 line

I request *comments* as many as possible.

Thanks for posting this so early. It's very helpful to be able to review it before it's been polished. Sorry it's taken a while to reply:

tools/libxl/libxl_dom.c static int libxl__remus_domain_suspend_callback(void *data)

Quoted 5 lines
tools/libxl/libxl_dom.c +0 -0
index a4ffdfd..858f5be 100644
@@ -1251,9 +1251,14 @@ static int libxl__remus_domain_suspend_callback(void *data)

These parts seem reasonable.

tools/libxl/libxl_dom.c static void remus_checkpoint_dm_saved(libxl__egc *egc, · line 1340

Quoted 4 lines
tools/libxl/libxl_dom.c +4 -0
+    rc = libxl__remus_disks_commit(remus_state);
+    if (rc) {
+        LOG(ERROR, "Failed to commit disks state"
+            " Terminating Remus..");

Why do we log a message hear but not in the other
libxl__remus_disks_foo failure cases ?

tools/libxl/libxl_remus.c void libxl__remus_setup_initiate(libxl__egc *egc, · line 26

Quoted 9 lines
tools/libxl/libxl_remus.c +1 -0
index cdc1c16..92eb36a 100644
@@ -23,6 +23,7 @@ void libxl__remus_setup_initiate(libxl__egc *egc,
                                  libxl__domain_suspend_state *dss)
 {
     libxl__ev_time_init(&dss->remus_state->timeout);
+    libxl__remus_disks_setup(egc, dss);

I think this is going to have to be an asynchronous function (ie, use a callback style), as it's going to want to run scripts. Likewise the teardown.

tools/libxl/libxl_remus.c void libxl__remus_setup_initiate(libxl__egc *egc, · line 29

Quoted 3 lines
tools/libxl/libxl_remus.c +3 -0
+/*** drbd implementation ***/
+const int DRBD_SEND_CHECKPOINT = 20;
+const int DRBD_WAIT_CHECKPOINT_ACK = 30;

These should be "static" as well as "const".

tools/libxl/libxl_remus.c void libxl__remus_setup_initiate(libxl__egc *egc,

Quoted 2 lines
tools/libxl/libxl_remus.c +2 -0
+typedef struct libxl__remus_drbd_disk
+{

Our coding style reserves "{" in the LH column for functions, so your struct definitions should have the "{" on the end of the previous line. See libxl__device and libxl__ev_watch_slot for examples.

tools/libxl/libxl_remus.c

Quoted 7 lines
tools/libxl/libxl_remus.c +7 -0
+static int drbd_postsuspend(libxl__remus_disk *d)
+{
+    struct libxl__remus_drbd_disk *drbd = CONTAINER_OF(d, *drbd, remus_disk);
+
+    if (!drbd->ackwait) {
+        if (ioctl(drbd->ctl_fd, DRBD_SEND_CHECKPOINT, 0) <= 0)
+            drbd->ackwait = 1;

This seems to make some assumption about return values, or lack of errors, or something. I would expect to see some error handling here.

Quoted 10 lines

tools/libxl/libxl_remus.c

Quoted 5 lines
tools/libxl/libxl_remus.c +5 -0
+static int drbd_commit(libxl__remus_disk *d)
+{
+    /* nothing to do, all work are done by DRBD's protocal-D. */
+    return 0;
+}

I'm not sure I understand how this can be true. Can you point me at an explanation of the supposed semantics of the remus disk commit ? (Eg in a remus design document or even a paper.) I suspect something ought to be done here.

in drbd-remus case, DRBD_SEND_CHECKPOINT(drbd_postsuspend()) will do the committing works asynchronously.

tools/python/xen/remus/device.py:
def commit(self):
if not self.is_drbd:
msg = os.read(self.msgfd.fileno(), 4)
if msg != 'done':
print 'Unknown message: %s' % msg

Quoted 69 lines
Quoted 2 lines

+static libxl__remus_disk *drbd_setup(libxl__gc *gc, libxl_device_disk *disk)

...

Quoted 1 line

+ drbd->ctl_fd = open(GCSPRINTF("/dev/drbd/by-res/%s", disk->pdev_path), O_RDONLY);

This line could do with wrapping. And your error handling is a bit nugatory, I think - surely something should be logged here ?

tools/libxl/libxl_remus.c

Quoted 7 lines
tools/libxl/libxl_remus.c +7 -0
+static const libxl__remus_disk_type drbd_disk_type = {
+  .postsuspend = drbd_postsuspend,
+  .preresume = drbd_preresume,
+  .commit = drbd_commit,
+  .setup = drbd_setup,
+  .teardown = drbd_teardown,
+};

I like this vtable approach.

tools/libxl/libxl_remus.c

Quoted 10 lines
tools/libxl/libxl_remus.c +10 -0
+int libxl__remus_disks_postsuspend(libxl__remus_state *state)
+{
+    int i;
+    int rc = 0;
+
+    for (i = 0; rc == 0 && i < state->nr_disks; i++)
+        rc = state->disks[i]->type->postsuspend(state->disks[i]);
+
+    return rc;
+}

I think the error handling in these functions isn't correct.

Also, there are several almost-identical functions. Can you consider whether you can write a macro to define them, or perhaps use offsetof to write a generic version of the function, or something ?

tools/libxl/libxl_remus.c

Quoted 4 lines
tools/libxl/libxl_remus.c +4 -0
+#if 0
+/* TODO: implement disk setup/teardown script */
+static void disk_exec_timeout_cb(libxl__egc *egc, libxl__ev_time *ev,
+                                      const struct timeval *requested_abs)

This will probably be easier after the refactoring needed to tease out the common script invocation code for the network buffering.

tools/libxl/libxl_remus.c

Quoted 10 lines
tools/libxl/libxl_remus.c +10 -0
+int libxl__remus_disks_setup(libxl__egc *egc, libxl__domain_suspend_state *dss)
+{
+    libxl__remus_state *remus_state = dss->remus_state;
+    int i, j, nr_disks;
+    libxl_device_disk *disks;
+    libxl__remus_disk *remus_disk;
+    const libxl__remus_disk_type *type;
+
+    STATE_AO_GC(dss->ao);
+    disks = libxl_device_disk_list(CTX, dss->domid, &nr_disks);

disks doesn't come from the gc, so you need to free it. You should initialise it to 0 (NULL), and use the "goto out" error handling style.

Quoted 11 lines
tools/libxl/libxl_remus.c +11 -0
+    remus_state->nr_disks = nr_disks;
+    GCNEW_ARRAY(remus_state->disks, nr_disks);
+
+    for (i = 0; i < nr_disks; i++) {
+        remus_disk = NULL;
+        for (j = 0; j < ARRAY_SIZE(remus_disk_types); j++) {
+            type = remus_disk_types[j];
+            remus_disk = type->setup(gc, &disks[i]);
+            if (!remus_disk)
+                break;
+
Quoted 8 lines

tools/libxl/libxl_remus.c

Quoted 4 lines
tools/libxl/libxl_remus.c +4 -0
+            remus_state->disks[i] = remus_disk;
+            remus_disk->disk = &disks[i];
+            remus_disk->type = type;
+        }

I think this code is wrong. It appears to call all of the setup functions, not just one, and overwrite remus_disk with their successive results.

If the user use remus disk replication, it is required that all the disks should support remus disk replication.

So we call setup to all disk. If any disk doesn't support remus or any disk fail to setup, this libxl__remus_disks_setup() should failed too.

tools/python/xen/remus/device.py:

    def __init__(self, disk):
        if disk.uname.startswith('tap:remus:') or disk.uname.startswith('tap:tapdisk:remus:'):
            ...
        elif disk.uname.startswith('drbd:'):
        else:
            raise ReplicatedDiskException('Disk is not replicated: %s' %
                                        str(disk))
Quoted 11 lines

tools/libxl/libxl_remus.c

Quoted 3 lines
tools/libxl/libxl_remus.c +2 -0
+        if (!remus_disk) {
+            remus_state->nr_disks = i;

You may find this easier to write with the "goto found" / "found:" search loop idiom. See "childproc_checkall" in libxl_fork.c for an example.

Thanks,
Ian.

#33 lore raw

Re: [PATCH RFC] remus: implement remus replicated checkpointing disk

Lai Jiangshan writes ("Re: [PATCH RFC] remus: implement remus replicated checkpointing disk"):

Quoted 8 lines · Ian Jackson
Quoted 4 lines

I'm not sure I understand how this can be true. Can you point me at an explanation of the supposed semantics of the remus disk commit ? (Eg in a remus design document or even a paper.) I suspect something ought to be done here.

in drbd-remus case, DRBD_SEND_CHECKPOINT(drbd_postsuspend()) will do the committing works asynchronously.

Um, I'm still not convinced that this is right. Can you point me to the relevant design documentation for remus (as I say above) and the relevant documentation for the drbd checkpoint facility ? That will allow me to understand this and check that it's correct.

Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
tools/libxl/libxl_remus_replicated_disk.c new file +12 -0
+    for (i = 0; i < nr_disks; i++) {
+        remus_disk = NULL;
+        for (j = 0; j < ARRAY_SIZE(remus_disk_types); j++) {
+            type = remus_disk_types[j];
+            remus_disk = type->setup(gc, &disks[i]);
+            if (!remus_disk)
+                break;
+
+            remus_state->disks[i] = remus_disk;
+            remus_disk->disk = &disks[i];
+            remus_disk->type = type;
+        }
Quoted 6 lines
Quoted 3 lines

I think this code is wrong. It appears to call all of the setup functions, not just one, and overwrite remus_disk with their successive results.

If the user use remus disk replication, it is required that all the disks should support remus disk replication.

Oh, I see.

Quoted 2 lines

So we call setup to all disk. If any disk doesn't support remus or any disk fail to setup, this libxl__remus_disks_setup() should failed too.

Right. I think this deserves a long message. And in that case, I think:

+ if (!remus_disk) {

+            remus_state->nr_disks = i;
+            libxl__remus_disks_teardown(remus_state);
+            return -1;

+ }

Instead of rewinding nr_disks, it would be better to make

+void libxl__remus_disks_teardown(libxl__remus_state *state) +{
+ int i;
+
+ for (i = 0; i < state->nr_disks; i++)
+ state->disks[i]->type->teardown(state->disks[i]);

this code not mind if disks[i] == NULL;

Thanks,
Ian.

#34 lore raw

Re: [PATCH RFC] remus: implement remus replicated checkpointing disk

In reply to Lai Jiangshan
Quoted 18 lines · Lai Jiangshan

This patch implements remus replicated checkpointing disk. It includes two parts:
generic remus replicated checkpointing disks framework drbd replicated checkpointing disks
They will be split into different files in next round.

The patch is still simple due to disk-setup-teardown-script is still under implementing. I need to use libxl_ao to implement it, but libxl_ao is hard to use. The work sequence is needed to ugly split to serveral callbacks like device_hotplug().

And becuase the remus disk script is unimplemented, the drbd_setup() code can't check the disk now. So it just assumes the user config the disk correctly.

This patch is *UNTESTED*.
(there is a problem with xl&drbd(without remus) in my BOXes).

Quoted 7 lines

I request *comments* as many as possible.

Thanks,
Lai

Hi
sorry for the delayed response. And thanks a lot for this initiative.
Apart from the inline feedback,
there are a few things to consider first before going down this route.

1. The drbd kernel module required for Remus is still out of tree, currently hosted on a wiki page.
The drbd folks didnt want to include the changes into their code unfortunately, as they were offering the
same functionality to one of their paid customers. This is what they told me back in 2011 or so.

To streamline the storage replication module installation, is there a chance of hosting the code in
xen.org's repos? That way, we could script the download and installation process. Like the qemu
stuff.

2. The tapdisk based replication unfortunately is outdated. Please correct me if I have got this wrong.
Haven't we decided to get rid of blktap2 and go with the qemu disk models? In which case, the tapdisk
remus code has to be ported into some qemu disk variant.

Without getting a resolution to the above two, my stance is that we shouldn't pollute xl with functionality
that requires out-of-band modules that may prove pretty painful to install for the majority of folks out there.

Based on the experience from the last 3 years, most average users of Remus tend to skip disk replication
altogether. They install the distro's default drbd, use the disk replication provided with it and then complain
that Remus crashes or fails. Some have ventured into tapdisk replication but it unfortunately seemed to
get difficult as xend/blktap2 started getting deprecated.

Quoted 15 lines
---
 tools/libxl/Makefile                      |    1 +
 tools/libxl/libxl_dom.c                   |   19 +++-
 tools/libxl/libxl_internal.h              |   10 ++
 tools/libxl/libxl_remus.c                 |    2 +
 tools/libxl/libxl_remus_replicated_disk.c |  219
+++++++++++++++++++++++++++++
 5 files changed, 249 insertions(+), 2 deletions(-)
 create mode 100644 tools/libxl/libxl_remus_replicated_disk.c
tools/libxl/Makefile +0 -0
index 218f55e..dbf5dd9 100644

tools/libxl/Makefile LIBXL_OBJS-y += libxl_nonetbuffer.o · line 58

Quoted 6 lines
tools/libxl/Makefile +1 -0
@@ -53,6 +53,7 @@ LIBXL_OBJS-y += libxl_nonetbuffer.o
 endif
 
 LIBXL_OBJS-y += libxl_remus.o
+LIBXL_OBJS-y += libxl_remus_replicated_disk.o
 
 

So I think this part will also require some autoconf based stuff. Especially, if DRBD & tapdisk are not present, then this whole thing gets disabled. Just like the libxl_netbuffer and libxl_nonetbuffer

Given that both of these (netbuffer and disk) are associated with Remus and both are required for Remus to work "correctly", we might as well have noremus.c and remus.c . Ofcourse it can be modularized a bit to have netbuffer but no disk replication or vice versa. As long as the person installing
or compiling this stuff is made to state explicitly that he/she does not want
Remus, but only a subset of its functionality for some other purpose.

tools/libxl/libxl_dom.c +0 -0
Quoted 9 lines

index a4ffdfd..858f5be 100644

tools/libxl/libxl_dom.c +0 -0
 
 
 
 
     /* The domain was suspended successfully. Start a new network

tools/libxl/libxl_dom.c static int libxl__remus_domain_resume_callback(void · line 1292

Quoted 10 lines
tools/libxl/libxl_dom.c +4 -1
@@ -1279,7 +1284,10 @@ static int libxl__remus_domain_resume_callback(void
 *data)
     if (libxl__domain_resume(gc, dss->domid, /* Fast Suspend */1))
         return 0;
 
-    /* REMUS TODO: Deal with disk. */
+    /* Deal with disk. */
+    if (libxl__remus_disks_preresume(dss->remus_state))
+        return 0;
+
 

Bug. This should go before the resume call. Also, I would suggest changing the comment
to something more meaningful, e.g., "commit disk changes.."

     return 1;
Quoted 5 lines
tools/libxl/libxl_dom.c +0 -0
 }
@@ -1326,6 +1334,13 @@ static void remus_checkpoint_dm_saved(libxl__egc
 *egc,
         goto out;

tools/libxl/libxl_dom.c static void remus_checkpoint_dm_saved(libxl__egc · line 1345

Quoted 10 lines
tools/libxl/libxl_dom.c +7 -0
     }
 
+    rc = libxl__remus_disks_commit(remus_state);
+    if (rc) {
+        LOG(ERROR, "Failed to commit disks state"
+            " Terminating Remus..");
+        goto out;
+    }
+
 

Now might be a good time to use the restore callbacks offered by the toolstack to
get an explicit ack from the backup that it has received the memory checkpoint too
before the network buffer is released. I think I put in a comment related to that somewhere.

Quoted 91 lines
tools/libxl/libxl_dom.c +0 -0
     if (remus_state->netbuf_state) {
         rc = libxl__remus_netbuf_release_prev_epoch(gc, dss->domid,
                                                     remus_state);
tools/libxl/libxl_internal.h +8 -0
index 1bd2bba..8933e5f 100644
@@ -2309,6 +2309,10 @@ typedef struct libxl__remus_state {
     void *netbuf_state;
     libxl__ev_time timeout;
     libxl__ev_child child;
+
+    /* remus disks state */
+    uint32_t nr_disks;
+    struct libxl__remus_disk **disks;
 } libxl__remus_state;
 
 _hidden int libxl__netbuffer_enabled(libxl__gc *gc);
@@ -2336,6 +2340,12 @@ _hidden int
 libxl__remus_netbuf_start_new_epoch(libxl__gc *gc, uint32_t domid,
 _hidden int libxl__remus_netbuf_release_prev_epoch(libxl__gc *gc,
 uint32_t domid,
                                                   libxl__remus_state
 *remus_state);
 
+_hidden int libxl__remus_disks_postsuspend(libxl__remus_state *state);
+_hidden int libxl__remus_disks_preresume(libxl__remus_state *state);
+_hidden int libxl__remus_disks_commit(libxl__remus_state *state);
+_hidden int libxl__remus_disks_setup(libxl__egc *egc,

libxl__domain_suspend_state *dss);

tools/libxl/libxl_internal.h +2 -0
+_hidden void libxl__remus_disks_teardown(libxl__remus_state *state);
+
 _hidden void libxl__remus_setup_initiate(libxl__egc *egc,
                                          libxl__domain_suspend_state

*dss);

tools/libxl/libxl_remus.c +2 -0
index cdc1c16..92eb36a 100644
@@ -23,6 +23,7 @@ void libxl__remus_setup_initiate(libxl__egc *egc,
                                  libxl__domain_suspend_state *dss)
 {
     libxl__ev_time_init(&dss->remus_state->timeout);
+    libxl__remus_disks_setup(egc, dss);
     if (!dss->remus_state->netbufscript)
         libxl__remus_setup_done(egc, dss, 0);
     else
@@ -51,6 +52,7 @@ void libxl__remus_teardown_initiate(libxl__egc *egc,
     /* stash rc somewhere before invoking teardown ops. */
     dss->remus_state->saved_rc = rc;
 
+    libxl__remus_disks_teardown(dss->remus_state);
     if (!dss->remus_state->netbuf_state)
         libxl__remus_teardown_done(egc, dss);
     else
tools/libxl/libxl_remus_replicated_disk.c new file +6 -0
new file mode 100644
index 0000000..4b16403
@@ -0,0 +1,219 @@
+/*
+ * Copyright (C) 2013
+ * Author Lai Jiangshan <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as

published
+ * by the Free Software Foundation; version 2.1 only. with the special
+ * exception on linking described in file LICENSE.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */

tools/libxl/libxl_remus_replicated_disk.c new file +12 -0
+
+#include "libxl_osdeps.h" /* must come before any other headers */
+
+#include "libxl_internal.h"
+
+typedef struct libxl__remus_disk
+{
+    const struct libxl_device_disk *disk;
+    const struct libxl__remus_disk_type *type;
+
+    /* ao callbacks for setup & teardown script */
+    int (*setup_cb)(struct libxl__remus_disk *d);

tools/libxl/libxl_remus_replicated_disk.c

Quoted 10 lines
tools/libxl/libxl_remus_replicated_disk.c new file +10 -0
+    int (*teardown_cb)(struct libxl__remus_disk *d);
+} libxl__remus_disk;
+
+typedef struct libxl__remus_disk_type
+{
+    /* checkpointing */
+    int (*postsuspend)(libxl__remus_disk *d);
+    int (*preresume)(libxl__remus_disk *d);
+    int (*commit)(libxl__remus_disk *d);
+

I would also suggest renaming these to something else, not associated with suspend but associated with checkpoints. start_disk_sync, finish_disk_sync, start_new_epoch or something along those lines.

tools/libxl/libxl_remus_replicated_disk.c

Quoted 3 lines
tools/libxl/libxl_remus_replicated_disk.c new file +3 -0
+    /* setup & teardown */
+    libxl__remus_disk *(*setup)(libxl__gc *gc, libxl_device_disk *disk);
+    void (*teardown)(libxl__remus_disk *d);

+} libxl__remus_disk_type;

Quoted 51 lines
tools/libxl/libxl_remus_replicated_disk.c new file +15 -0
+
+
+/*** drbd implementation ***/
+const int DRBD_SEND_CHECKPOINT = 20;
+const int DRBD_WAIT_CHECKPOINT_ACK = 30;
+typedef struct libxl__remus_drbd_disk
+{
+    libxl__remus_disk remus_disk;
+    int ctl_fd;
+    int ackwait;
+} libxl__remus_drbd_disk;
+
+static int drbd_postsuspend(libxl__remus_disk *d)
+{
+    struct libxl__remus_drbd_disk *drbd = CONTAINER_OF(d, *drbd,

remus_disk);

tools/libxl/libxl_remus_replicated_disk.c new file +12 -0
+
+    if (!drbd->ackwait) {
+        if (ioctl(drbd->ctl_fd, DRBD_SEND_CHECKPOINT, 0) <= 0)
+            drbd->ackwait = 1;
+    }
+
+    return 0;
+}
+
+static int drbd_preresume(libxl__remus_disk *d)
+{
+    struct libxl__remus_drbd_disk *drbd = CONTAINER_OF(d, *drbd,

remus_disk);

tools/libxl/libxl_remus_replicated_disk.c new file +16 -0
+
+    if (drbd->ackwait) {
+        ioctl(drbd->ctl_fd, DRBD_WAIT_CHECKPOINT_ACK, 0);
+        drbd->ackwait = 0;
+    }
+
+    return 0;
+}
+
+static int drbd_commit(libxl__remus_disk *d)
+{
+    /* nothing to do, all work are done by DRBD's protocal-D. */
+    return 0;
+}
+
+static libxl__remus_disk *drbd_setup(libxl__gc *gc, libxl_device_disk

*disk)

tools/libxl/libxl_remus_replicated_disk.c new file +3 -0
+{
+    libxl__remus_drbd_disk *drbd;
+    //if (!(drbd && protocal-D)) // TODO: need to run script async to

check

tools/libxl/libxl_remus_replicated_disk.c

Quoted 2 lines
tools/libxl/libxl_remus_replicated_disk.c new file +2 -0
+    //  return NULL
+

We don't need to run any scripts for DRBD (or tapdisk for that matter).

DRBD scripts will get activated when the domain boots and thats the end of it.
On the backup side, it gets activated during the initial phase of Remus, which
is same as live migration. Since xl already supports live migration with drbd
based disks, we don't need any script related code at all.

With regard to tapdisk-remus (atleast with blktap2), you cant boot the domain
fully unless you start Remus too. This in turn forces the backup to start the
tapdisk-remus receiving end. Once again in this case, in Xend, the live migration
infrastructure did all the script setup work.

Quoted 80 lines
tools/libxl/libxl_remus_replicated_disk.c new file +3 -0
+    GCNEW(drbd);
+
+    drbd->ctl_fd = open(GCSPRINTF("/dev/drbd/by-res/%s",

disk->pdev_path), O_RDONLY);

tools/libxl/libxl_remus_replicated_disk.c new file +11 -0
+    drbd->ackwait = 0;
+
+    if (drbd->ctl_fd < 0)
+        return NULL;
+
+    return &drbd->remus_disk;
+}
+
+static void drbd_teardown(libxl__remus_disk *d)
+{
+    struct libxl__remus_drbd_disk *drbd = CONTAINER_OF(d, *drbd,

remus_disk);

tools/libxl/libxl_remus_replicated_disk.c new file +64 -0
+
+    close(drbd->ctl_fd);
+}
+
+static const libxl__remus_disk_type drbd_disk_type = {
+  .postsuspend = drbd_postsuspend,
+  .preresume = drbd_preresume,
+  .commit = drbd_commit,
+  .setup = drbd_setup,
+  .teardown = drbd_teardown,
+};
+
+/*** checkpoint disks states and callbacks ***/
+static const libxl__remus_disk_type *remus_disk_types[] =
+{
+    &drbd_disk_type,
+};
+
+int libxl__remus_disks_postsuspend(libxl__remus_state *state)
+{
+    int i;
+    int rc = 0;
+
+    for (i = 0; rc == 0 && i < state->nr_disks; i++)
+        rc = state->disks[i]->type->postsuspend(state->disks[i]);
+
+    return rc;
+}
+
+int libxl__remus_disks_preresume(libxl__remus_state *state)
+{
+    int i;
+    int rc = 0;
+
+    for (i = 0; rc == 0 && i < state->nr_disks; i++)
+        rc = state->disks[i]->type->preresume(state->disks[i]);
+
+    return rc;
+}
+
+int libxl__remus_disks_commit(libxl__remus_state *state)
+{
+    int i;
+    int rc = 0;
+
+    for (i = 0; rc == 0 && i < state->nr_disks; i++)
+        rc = state->disks[i]->type->commit(state->disks[i]);
+
+    return rc;
+}
+
+#if 0
+/* TODO: implement disk setup/teardown script */
+static void disk_exec_timeout_cb(libxl__egc *egc, libxl__ev_time *ev,
+                                      const struct timeval *requested_abs)
+{
+    libxl__remus_disks_state *state = CONTAINER_OF(ev, *aodev, timeout);
+    STATE_AO_GC(state->ao);
+
+    libxl__ev_time_deregister(gc, &state->timeout);
+
+    assert(libxl__ev_child_inuse(&state->child));
+    if (kill(state->child.pid, SIGKILL)) {
+    }

tools/libxl/libxl_remus_replicated_disk.c

Quoted 10 lines
tools/libxl/libxl_remus_replicated_disk.c new file +10 -0
+
+    return;
+}
+
+int libxl__remus_disks_exec_script(libxl__gc *gc,
+    libxl__remus_disks_state *state)
+{
+}
+#endif
+

I don't know if this is needed at all, given that we don't have disk script setup issues.

Quoted 1 line

+int libxl__remus_disks_setup(libxl__egc *egc, libxl__domain_suspend_state

Quoted 44 lines

*dss)

tools/libxl/libxl_remus_replicated_disk.c new file +42 -1
+{
+    libxl__remus_state *remus_state = dss->remus_state;
+    int i, j, nr_disks;
+    libxl_device_disk *disks;
+    libxl__remus_disk *remus_disk;
+    const libxl__remus_disk_type *type;
+
+    STATE_AO_GC(dss->ao);
+    disks = libxl_device_disk_list(CTX, dss->domid, &nr_disks);
+    remus_state->nr_disks = nr_disks;
+    GCNEW_ARRAY(remus_state->disks, nr_disks);
+
+    for (i = 0; i < nr_disks; i++) {
+        remus_disk = NULL;
+        for (j = 0; j < ARRAY_SIZE(remus_disk_types); j++) {
+            type = remus_disk_types[j];
+            remus_disk = type->setup(gc, &disks[i]);
+            if (!remus_disk)
+                break;
+
+            remus_state->disks[i] = remus_disk;
+            remus_disk->disk = &disks[i];
+            remus_disk->type = type;
+        }
+        if (!remus_disk) {
+            remus_state->nr_disks = i;
+            libxl__remus_disks_teardown(remus_state);
+            return -1;
+        }
+    }
+    return 0;
+}
+
+void libxl__remus_disks_teardown(libxl__remus_state *state)
+{
+    int i;
+
+    for (i = 0; i < state->nr_disks; i++)
+        state->disks[i]->type->teardown(state->disks[i]);
+    state->nr_disks = 0;
+}
+
--
Quoted 3 lines

1.7.1

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#35 lore raw

Re: [PATCH RFC] remus: implement remus replicated checkpointing disk

Quoted 36 lines · Shriram Rajagopalan

On Tue, Feb 25, 2014 at 6:53 PM, Lai Jiangshan <[email protected] <mailto:[email protected]>> wrote:

This patch implements remus replicated checkpointing disk. It includes two parts:
generic remus replicated checkpointing disks framework drbd replicated checkpointing disks
They will be split into different files in next round.

The patch is still simple due to disk-setup-teardown-script is still under implementing. I need to use libxl_ao to implement it, but libxl_ao is hard to use. The work sequence is needed to ugly split to serveral callbacks like device_hotplug().

And becuase the remus disk script is unimplemented, the drbd_setup() code can't check the disk now. So it just assumes the user config the disk correctly.

This patch is *UNTESTED*.
(there is a problem with xl&drbd(without remus) in my BOXes).

I request *comments* as many as possible.

Thanks,
Lai

Signed-off-by Lai Jiangshan <[email protected] <mailto:[email protected]>>

Hi
sorry for the delayed response. And thanks a lot for this initiative. Apart from the inline feedback,
there are a few things to consider first before going down this route.

1. The drbd kernel module required for Remus is still out of tree, currently hosted on a wiki page. The drbd folks didnt want to include the changes into their code unfortunately, as they were offering the same functionality to one of their paid customers. This is what they told me back in 2011 or so.

Quoted 7 lines

To streamline the storage replication module installation, is there a chance of hosting the code in xen.org <http://xen.org>'s repos? That way, we could script the download and installation process. Like the qemu stuff.

2. The tapdisk based replication unfortunately is outdated. Please correct me if I have got this wrong. Haven't we decided to get rid of blktap2 and go with the qemu disk models? In which case, the tapdisk remus code has to be ported into some qemu disk variant.

We are implementing *qemu* replicated checkpointing disk, but we can't make it public even we have done, we need to delay the publication due to we are paid to implement it by a paid customer.

Quoted 3 lines

Without getting a resolution to the above two, my stance is that we shouldn't pollute xl with functionality that requires out-of-band modules that may prove pretty painful to install for the majority of folks out there.

I'm also concern with out-of-band modules, since remus-drbd can't be merged upstream, It will be valueless to apply remus-drbd replicated checkpointing disk to xl.

What's the status of blktap3 now? (I am asking to xen community)

Quoted 242 lines

Based on the experience from the last 3 years, most average users of Remus tend to skip disk replication altogether. They install the distro's default drbd, use the disk replication provided with it and then complain that Remus crashes or fails. Some have ventured into tapdisk replication but it unfortunately seemed to get difficult as xend/blktap2 started getting deprecated.

    ---
     tools/libxl/Makefile                      |    1 +
     tools/libxl/libxl_dom.c                   |   19 +++-
     tools/libxl/libxl_internal.h              |   10 ++
     tools/libxl/libxl_remus.c                 |    2 +
     tools/libxl/libxl_remus_replicated_disk.c |  219 +++++++++++++++++++++++++++++
     5 files changed, 249 insertions(+), 2 deletions(-)
     create mode 100644 tools/libxl/libxl_remus_replicated_disk.c

    diff --git a/tools/libxl/Makefile b/tools/libxl/Makefile
    index 218f55e..dbf5dd9 100644
    --- a/tools/libxl/Makefile
    +++ b/tools/libxl/Makefile
    @@ -53,6 +53,7 @@ LIBXL_OBJS-y += libxl_nonetbuffer.o
     endif

     LIBXL_OBJS-y += libxl_remus.o
    +LIBXL_OBJS-y += libxl_remus_replicated_disk.o

So I think this part will also require some autoconf based stuff. Especially, if DRBD & tapdisk are not present, then this whole thing gets disabled. Just like the libxl_netbuffer and libxl_nonetbuffer

Given that both of these (netbuffer and disk) are associated with Remus and both are required for Remus to work "correctly", we might as well have noremus.c and remus.c . Ofcourse it can be modularized a bit to have netbuffer but no disk replication or vice versa. As long as the person installing or compiling this stuff is made to state explicitly that he/she does not want Remus, but only a subset of its functionality for some other purpose.

    diff --git a/tools/libxl/libxl_dom.c b/tools/libxl/libxl_dom.c
    index a4ffdfd..858f5be 100644
    --- a/tools/libxl/libxl_dom.c
    +++ b/tools/libxl/libxl_dom.c


 

         /* The domain was suspended successfully. Start a new network
    @@ -1279,7 +1284,10 @@ static int libxl__remus_domain_resume_callback(void *data)
         if (libxl__domain_resume(gc, dss->domid, /* Fast Suspend */1))
             return 0;

    -    /* REMUS TODO: Deal with disk. */
    +    /* Deal with disk. */
    +    if (libxl__remus_disks_preresume(dss->remus_state))
    +        return 0;
    +

Bug. This should go before the resume call. Also, I would suggest changing the comment to something more meaningful, e.g., "commit disk changes.."

return 1;
}

@@ -1326,6 +1334,13 @@ static void remus_checkpoint_dm_saved(libxl__egc *egc,
goto out;
}

+ rc = libxl__remus_disks_commit(remus_state);
+ if (rc) {
+ LOG(ERROR, "Failed to commit disks state"
+ " Terminating Remus..");
+ goto out;
+ }
+

Now might be a good time to use the restore callbacks offered by the toolstack to get an explicit ack from the backup that it has received the memory checkpoint too before the network buffer is released. I think I put in a comment related to that somewhere.

         if (remus_state->netbuf_state) {
             rc = libxl__remus_netbuf_release_prev_epoch(gc, dss->domid,
                                                         remus_state);
    diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
    index 1bd2bba..8933e5f 100644
    --- a/tools/libxl/libxl_internal.h
    +++ b/tools/libxl/libxl_internal.h
    @@ -2309,6 +2309,10 @@ typedef struct libxl__remus_state {
         void *netbuf_state;
         libxl__ev_time timeout;
         libxl__ev_child child;
    +
    +    /* remus disks state */
    +    uint32_t nr_disks;
    +    struct libxl__remus_disk **disks;
     } libxl__remus_state;

     _hidden int libxl__netbuffer_enabled(libxl__gc *gc);
    @@ -2336,6 +2340,12 @@ _hidden int libxl__remus_netbuf_start_new_epoch(libxl__gc *gc, uint32_t domid,
     _hidden int libxl__remus_netbuf_release_prev_epoch(libxl__gc *gc, uint32_t domid,
                                                       libxl__remus_state *remus_state);

    +_hidden int libxl__remus_disks_postsuspend(libxl__remus_state *state);
    +_hidden int libxl__remus_disks_preresume(libxl__remus_state *state);
    +_hidden int libxl__remus_disks_commit(libxl__remus_state *state);
    +_hidden int libxl__remus_disks_setup(libxl__egc *egc, libxl__domain_suspend_state *dss);
    +_hidden void libxl__remus_disks_teardown(libxl__remus_state *state);
    +
     _hidden void libxl__remus_setup_initiate(libxl__egc *egc,
                                              libxl__domain_suspend_state *dss);

    diff --git a/tools/libxl/libxl_remus.c b/tools/libxl/libxl_remus.c
    index cdc1c16..92eb36a 100644
    --- a/tools/libxl/libxl_remus.c
    +++ b/tools/libxl/libxl_remus.c
    @@ -23,6 +23,7 @@ void libxl__remus_setup_initiate(libxl__egc *egc,
                                      libxl__domain_suspend_state *dss)
     {
         libxl__ev_time_init(&dss->remus_state->timeout);
    +    libxl__remus_disks_setup(egc, dss);
         if (!dss->remus_state->netbufscript)
             libxl__remus_setup_done(egc, dss, 0);
         else
    @@ -51,6 +52,7 @@ void libxl__remus_teardown_initiate(libxl__egc *egc,
         /* stash rc somewhere before invoking teardown ops. */
         dss->remus_state->saved_rc = rc;

    +    libxl__remus_disks_teardown(dss->remus_state);
         if (!dss->remus_state->netbuf_state)
             libxl__remus_teardown_done(egc, dss);
         else
    diff --git a/tools/libxl/libxl_remus_replicated_disk.c b/tools/libxl/libxl_remus_replicated_disk.c
    new file mode 100644
    index 0000000..4b16403
    --- /dev/null
    +++ b/tools/libxl/libxl_remus_replicated_disk.c
    @@ -0,0 +1,219 @@
    +/*
    + * Copyright (C) 2013
    + * Author Lai Jiangshan <[email protected] <mailto:[email protected]>>
    + *
    + * This program is free software; you can redistribute it and/or modify
    + * it under the terms of the GNU Lesser General Public License as published
    + * by the Free Software Foundation; version 2.1 only. with the special
    + * exception on linking described in file LICENSE.
    + *
    + * This program is distributed in the hope that it will be useful,
    + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    + * GNU Lesser General Public License for more details.
    + */
    +
    +#include "libxl_osdeps.h" /* must come before any other headers */
    +
    +#include "libxl_internal.h"
    +
    +typedef struct libxl__remus_disk
    +{
    +    const struct libxl_device_disk *disk;
    +    const struct libxl__remus_disk_type *type;
    +
    +    /* ao callbacks for setup & teardown script */
    +    int (*setup_cb)(struct libxl__remus_disk *d);
    +    int (*teardown_cb)(struct libxl__remus_disk *d);
    +} libxl__remus_disk;
    +
    +typedef struct libxl__remus_disk_type
    +{
    +    /* checkpointing */
    +    int (*postsuspend)(libxl__remus_disk *d);
    +    int (*preresume)(libxl__remus_disk *d);
    +    int (*commit)(libxl__remus_disk *d);
    +

I would also suggest renaming these to something else, not associated with suspend but associated with checkpoints. start_disk_sync, finish_disk_sync, start_new_epoch or something along those lines.

    +    /* setup & teardown */
    +    libxl__remus_disk *(*setup)(libxl__gc *gc, libxl_device_disk *disk);
    +    void (*teardown)(libxl__remus_disk *d); 

+} libxl__remus_disk_type;
+
+
+/*** drbd implementation ***/
+const int DRBD_SEND_CHECKPOINT = 20;
+const int DRBD_WAIT_CHECKPOINT_ACK = 30;
+typedef struct libxl__remus_drbd_disk
+{
+ libxl__remus_disk remus_disk;
+ int ctl_fd;
+ int ackwait;
+} libxl__remus_drbd_disk;
+
+static int drbd_postsuspend(libxl__remus_disk *d)
+{
+ struct libxl__remus_drbd_disk *drbd = CONTAINER_OF(d, *drbd, remus_disk);
+
+ if (!drbd->ackwait) {
+ if (ioctl(drbd->ctl_fd, DRBD_SEND_CHECKPOINT, 0) <= 0)
+ drbd->ackwait = 1;
+ }
+
+ return 0;
+}
+
+static int drbd_preresume(libxl__remus_disk *d)
+{
+ struct libxl__remus_drbd_disk *drbd = CONTAINER_OF(d, *drbd, remus_disk);
+
+ if (drbd->ackwait) {
+ ioctl(drbd->ctl_fd, DRBD_WAIT_CHECKPOINT_ACK, 0);
+ drbd->ackwait = 0;
+ }
+
+ return 0;
+}
+
+static int drbd_commit(libxl__remus_disk *d)
+{
+ /* nothing to do, all work are done by DRBD's protocal-D. */
+ return 0;
+}
+
+static libxl__remus_disk *drbd_setup(libxl__gc *gc, libxl_device_disk *disk) +{
+ libxl__remus_drbd_disk *drbd;
+ //if (!(drbd && protocal-D)) // TODO: need to run script async to check
+ // return NULL
+

Quoted 1 line

We don't need to run any scripts for DRBD (or tapdisk for that matter).

It is hard to check the status/configuration of DRBD-disk in C code, it requires drbd C-header files(with remus supported).

I find no way to do it. So we try to use scripts.

Thank you and thanks to your elaborate reply.
Lai

Quoted 156 lines

DRBD scripts will get activated when the domain boots and thats the end of it. On the backup side, it gets activated during the initial phase of Remus, which is same as live migration. Since xl already supports live migration with drbd based disks, we don't need any script related code at all.

With regard to tapdisk-remus (atleast with blktap2), you cant boot the domain fully unless you start Remus too. This in turn forces the backup to start the tapdisk-remus receiving end. Once again in this case, in Xend, the live migration infrastructure did all the script setup work.

+ GCNEW(drbd);
+
+ drbd->ctl_fd = open(GCSPRINTF("/dev/drbd/by-res/%s", disk->pdev_path), O_RDONLY);
+ drbd->ackwait = 0;
+
+ if (drbd->ctl_fd < 0)
+ return NULL;
+
+ return &drbd->remus_disk;
+}
+
+static void drbd_teardown(libxl__remus_disk *d)
+{
+ struct libxl__remus_drbd_disk *drbd = CONTAINER_OF(d, *drbd, remus_disk);
+
+ close(drbd->ctl_fd);
+}
+
+static const libxl__remus_disk_type drbd_disk_type = {
+ .postsuspend = drbd_postsuspend,
+ .preresume = drbd_preresume,
+ .commit = drbd_commit,
+ .setup = drbd_setup,
+ .teardown = drbd_teardown,
+};
+
+/*** checkpoint disks states and callbacks ***/
+static const libxl__remus_disk_type *remus_disk_types[] = +{
+ &drbd_disk_type,
+};
+
+int libxl__remus_disks_postsuspend(libxl__remus_state *state) +{
+ int i;
+ int rc = 0;
+
+ for (i = 0; rc == 0 && i < state->nr_disks; i++)
+ rc = state->disks[i]->type->postsuspend(state->disks[i]);
+
+ return rc;
+}
+
+int libxl__remus_disks_preresume(libxl__remus_state *state) +{
+ int i;
+ int rc = 0;
+
+ for (i = 0; rc == 0 && i < state->nr_disks; i++)
+ rc = state->disks[i]->type->preresume(state->disks[i]);
+
+ return rc;
+}
+
+int libxl__remus_disks_commit(libxl__remus_state *state) +{
+ int i;
+ int rc = 0;
+
+ for (i = 0; rc == 0 && i < state->nr_disks; i++)
+ rc = state->disks[i]->type->commit(state->disks[i]);
+
+ return rc;
+}
+
+#if 0
+/* TODO: implement disk setup/teardown script */
+static void disk_exec_timeout_cb(libxl__egc *egc, libxl__ev_time *ev,
+ const struct timeval *requested_abs)
+{
+ libxl__remus_disks_state *state = CONTAINER_OF(ev, *aodev, timeout);
+ STATE_AO_GC(state->ao);
+
+ libxl__ev_time_deregister(gc, &state->timeout);
+
+ assert(libxl__ev_child_inuse(&state->child));
+ if (kill(state->child.pid, SIGKILL)) {
+ }
+
+ return;
+}
+
+int libxl__remus_disks_exec_script(libxl__gc *gc,
+ libxl__remus_disks_state *state)
+{
+}
+#endif
+

I don't know if this is needed at all, given that we don't have disk script setup issues.

+int libxl__remus_disks_setup(libxl__egc *egc, libxl__domain_suspend_state *dss) +{
+ libxl__remus_state *remus_state = dss->remus_state;
+ int i, j, nr_disks;
+ libxl_device_disk *disks;
+ libxl__remus_disk *remus_disk;
+ const libxl__remus_disk_type *type;
+
+ STATE_AO_GC(dss->ao);
+ disks = libxl_device_disk_list(CTX, dss->domid, &nr_disks);
+ remus_state->nr_disks = nr_disks;
+ GCNEW_ARRAY(remus_state->disks, nr_disks);
+
+ for (i = 0; i < nr_disks; i++) {
+ remus_disk = NULL;
+ for (j = 0; j < ARRAY_SIZE(remus_disk_types); j++) {
+ type = remus_disk_types[j];
+ remus_disk = type->setup(gc, &disks[i]);
+ if (!remus_disk)
+ break;
+
+ remus_state->disks[i] = remus_disk;
+ remus_disk->disk = &disks[i];
+ remus_disk->type = type;
+ }
+ if (!remus_disk) {
+ remus_state->nr_disks = i;
+ libxl__remus_disks_teardown(remus_state);
+ return -1;
+ }
+ }
+ return 0;
+}
+
+void libxl__remus_disks_teardown(libxl__remus_state *state)
+{
+ int i;
+
+ for (i = 0; i < state->nr_disks; i++)
+ state->disks[i]->type->teardown(state->disks[i]);
+ state->nr_disks = 0;
+}
+
--
1.7.1

#36 lore raw

Re: [PATCH RFC] remus: implement remus replicated checkpointing disk

Quoted 12 lines
Quoted 3 lines

+
+static libxl__remus_disk *drbd_setup(libxl__gc *gc,

libxl_device_disk *disk)

Quoted 3 lines

+{
+ libxl__remus_drbd_disk *drbd;
+ //if (!(drbd && protocal-D)) // TODO: need to run script async

to check

Quoted 4 lines

+ // return NULL
+

Quoted 8 lines
Quoted 1 line

We don't need to run any scripts for DRBD (or tapdisk for that matter).

It is hard to check the status/configuration of DRBD-disk in C code, it requires drbd C-header files(with remus supported).

I find no way to do it. So we try to use scripts.

Okay. So these are not setup scripts. But merely sanity check scripts to ensure
the proper version of kernel module and userspace tools for DRBD are installed.
In which case, yes, a script makes more sense and its much easier.

shriram

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#37 lore raw

Re: [PATCH RFC] remus: implement remus replicated checkpointing disk

In reply to Lai Jiangshan
Quoted 6 lines · Lai Jiangshan
Quoted 3 lines

2. The tapdisk based replication unfortunately is outdated. Please correct me if I have got this wrong. Haven't we decided to get rid of blktap2 and go with the qemu disk models? In which case, the tapdisk remus code has to be ported into some qemu disk variant.

We are implementing *qemu* replicated checkpointing disk, but we can't make it public even we have done, we need to delay the publication due to we are paid to implement it by a paid customer.

Are you saying you are never going to be able to make this code public? Or just that it will be delayed by some months?

Quoted 9 lines
Quoted 4 lines

Without getting a resolution to the above two, my stance is that we shouldn't pollute xl with functionality that requires out-of-band modules that may prove pretty painful to install for the majority of folks out there.

I'm also concern with out-of-band modules, since remus-drbd can't be merged upstream, It will be valueless to apply remus-drbd replicated checkpointing disk to xl.

What's the status of blktap3 now? (I am asking to xen community)

AFAIK the XenServer are not continuing down the blktap3 path and are instead planning to switch to qemu qdisk as a backend.

#38 lore raw

Re: [PATCH RFC] remus: implement remus replicated checkpointing disk

Quoted 10 lines · Ian Campbell
Quoted 6 lines · Lai Jiangshan
Quoted 3 lines

2. The tapdisk based replication unfortunately is outdated. Please correct me if I have got this wrong. Haven't we decided to get rid of blktap2 and go with the qemu disk models? In which case, the tapdisk remus code has to be ported into some qemu disk variant.

We are implementing *qemu* replicated checkpointing disk, but we can't make it public even we have done, we need to delay the publication due to we are paid to implement it by a paid customer.

Are you saying you are never going to be able to make this code public? Or just that it will be delayed by some months?

It will be just delayed, but it will be public finally.

This private code is just under implementing, it is far from mature. I hope the community also makes efforts to it.

see also to: http://wiki.qemu.org/Features/MicroCheckpointing

Quoted 16 lines
Quoted 10 lines
Quoted 5 lines

Without getting a resolution to the above two, my stance is that we shouldn't pollute xl with functionality that requires out-of-band modules that may prove pretty painful to install for the majority of folks out there.

I'm also concern with out-of-band modules, since remus-drbd can't be merged upstream, It will be valueless to apply remus-drbd replicated checkpointing disk to xl.

What's the status of blktap3 now? (I am asking to xen community)

AFAIK the XenServer are not continuing down the blktap3 path and are instead planning to switch to qemu qdisk as a backend.

#39 lore raw

Re: [PATCH RFC] remus: implement remus replicated checkpointing disk

Quoted 9 lines · Lai Jiangshan
Quoted 8 lines · Ian Campbell
Quoted 6 lines · Lai Jiangshan
Quoted 3 lines

2. The tapdisk based replication unfortunately is outdated. Please correct me if I have got this wrong. Haven't we decided to get rid of blktap2 and go with the qemu disk models? In which case, the tapdisk remus code has to be ported into some qemu disk variant.

We are implementing *qemu* replicated checkpointing disk, but we can't make it public even we have done, we need to delay the publication due to we are paid to implement it by a paid customer.

Quoted 7 lines
Quoted 2 lines

Are you saying you are never going to be able to make this code public? Or just that it will be delayed by some months?

It will be just delayed, but it will be public finally.

This private code is just under implementing, it is far from mature. I hope the community also makes efforts to it.

Are you asking that people work on this feature in parallel with you building the same thing privately? That doesn't seem likely.

Ian.

#40 lore raw

Re: [PATCH RFC] remus: implement remus replicated checkpointing disk

Quoted 13 lines · Ian Campbell
Quoted 12 lines · Lai Jiangshan
Quoted 10 lines · Ian Campbell
Quoted 6 lines · Lai Jiangshan
Quoted 3 lines

2. The tapdisk based replication unfortunately is outdated. Please correct me if I have got this wrong. Haven't we decided to get rid of blktap2 and go with the qemu disk models? In which case, the tapdisk remus code has to be ported into some qemu disk variant.

We are implementing *qemu* replicated checkpointing disk, but we can't make it public even we have done, we need to delay the publication due to we are paid to implement it by a paid customer.

Are you saying you are never going to be able to make this code public? Or just that it will be delayed by some months?

Quoted 8 lines
Quoted 4 lines

It will be just delayed, but it will be public finally.

This private code is just under implementing, it is far from mature. I hope the community also makes efforts to it.

Are you asking that people work on this feature in parallel with you building the same thing privately? That doesn't seem likely.

It may or may not be the same. our private implementing is too slow, If the community do it so, we will definitely join in.

#41 lore raw

Re: [PATCH RFC] remus: implement remus replicated checkpointing disk

In reply to Shriram Rajagopalan
Quoted 41 lines · Shriram Rajagopalan

On Tue, Feb 25, 2014 at 6:53 PM, Lai Jiangshan <[email protected]> wrote:

This patch implements remus replicated checkpointing disk. It includes two parts:
generic remus replicated checkpointing disks framework drbd replicated checkpointing disks
They will be split into different files in next round.

The patch is still simple due to disk-setup-teardown-script is still under implementing. I need to use libxl_ao to implement it,
but libxl_ao is hard to use. The work sequence is needed to ugly split
to serveral callbacks like device_hotplug().

And becuase the remus disk script is unimplemented, the drbd_setup() code
can't check the disk now. So it just assumes the user config the disk correctly.

This patch is *UNTESTED*.
(there is a problem with xl&drbd(without remus) in my BOXes).

I request *comments* as many as possible.

Thanks,
Lai

Hi
sorry for the delayed response. And thanks a lot for this initiative.
Apart from the inline feedback,
there are a few things to consider first before going down this route.

Quoted 6 lines

1. The drbd kernel module required for Remus is still out of tree, currently hosted on a wiki page.
The drbd folks didnt want to include the changes into their code unfortunately, as they were offering the
same functionality to one of their paid customers. This is what they told me back in 2011 or so.

That's rather sad.

Is there a more community contribution friendly project which provides similar functionality? A community drdb fork perhaps?

I don't know how invasive the changes are, but one approach might be to ask various distro package maintainers if they would be willing to carry a patch which you maintain out of the main drdb tree. You'd only need a few of the big ones to say yes for this to be worthwhile.

Quoted 5 lines

To streamline the storage replication module installation, is there a chance of hosting the code in
xen.org's repos? That way, we could script the download and installation process. Like the qemu
stuff.

I'm very reluctant to add more downloading to the Xen build system, but that doesn't rule out hosting something on xenbits. There are also things like gitorious and other hosting services.

Quoted 4 lines

2. The tapdisk based replication unfortunately is outdated. Please correct me if I have got this wrong.
Haven't we decided to get rid of blktap2 and go with the qemu disk models?

"decided" in so much as noone is interesting in maintaining blktap2. qemu is where people are willing to invest the effort so that is where things are heading.

Quoted 2 lines

In which case, the tapdisk
remus code has to be ported into some qemu disk variant.

Right. I think qemu has some amount of snapshot stuff, but how close it is to what remus wants I don't know.

Quoted 4 lines

Without getting a resolution to the above two, my stance is that we shouldn't pollute xl with functionality
that requires out-of-band modules that may prove pretty painful to install for the majority of folks out there.

This sounds reasonable.

Quoted 5 lines

Based on the experience from the last 3 years, most average users of Remus tend to skip disk replication
altogether. They install the distro's default drbd, use the disk replication provided with it and then complain
that Remus crashes or fails.

Remus should probably complain more stridently about the lack of disk replication and require a --i-know-my-data-is-at-risk type flag.

Ian.

#42 lore raw

Re: [PATCH RFC] remus: implement remus replicated checkpointing disk

Quoted 84 lines · Ian Campbell
Quoted 41 lines · Shriram Rajagopalan

On Tue, Feb 25, 2014 at 6:53 PM, Lai Jiangshan <[email protected]> wrote:

This patch implements remus replicated checkpointing disk. It includes two parts:
generic remus replicated checkpointing disks framework drbd replicated checkpointing disks
They will be split into different files in next round.

The patch is still simple due to disk-setup-teardown-script is still under implementing. I need to use libxl_ao to implement it,
but libxl_ao is hard to use. The work sequence is needed to ugly split
to serveral callbacks like device_hotplug().

And becuase the remus disk script is unimplemented, the drbd_setup() code
can't check the disk now. So it just assumes the user config the disk correctly.

This patch is *UNTESTED*.
(there is a problem with xl&drbd(without remus) in my BOXes).

I request *comments* as many as possible.

Thanks,
Lai

Hi
sorry for the delayed response. And thanks a lot for this initiative.
Apart from the inline feedback,
there are a few things to consider first before going down this route.

Quoted 6 lines

1. The drbd kernel module required for Remus is still out of tree, currently hosted on a wiki page.
The drbd folks didnt want to include the changes into their code unfortunately, as they were offering the
same functionality to one of their paid customers. This is what they told me back in 2011 or so.

That's rather sad.

Is there a more community contribution friendly project which provides similar functionality? A community drdb fork perhaps?

I don't know how invasive the changes are, but one approach might be to ask various distro package maintainers if they would be willing to carry a patch which you maintain out of the main drdb tree. You'd only need a few of the big ones to say yes for this to be worthwhile.

Quoted 5 lines

To streamline the storage replication module installation, is there a chance of hosting the code in
xen.org's repos? That way, we could script the download and installation process. Like the qemu
stuff.

I'm very reluctant to add more downloading to the Xen build system, but that doesn't rule out hosting something on xenbits. There are also things like gitorious and other hosting services.

Quoted 4 lines

2. The tapdisk based replication unfortunately is outdated. Please correct me if I have got this wrong.
Haven't we decided to get rid of blktap2 and go with the qemu disk models?

"decided" in so much as noone is interesting in maintaining blktap2. qemu is where people are willing to invest the effort so that is where things are heading.

Quoted 2 lines

In which case, the tapdisk
remus code has to be ported into some qemu disk variant.

Right. I think qemu has some amount of snapshot stuff, but how close it is to what remus wants I don't know.

Quoted 6 lines
Quoted 4 lines

Without getting a resolution to the above two, my stance is that we shouldn't pollute xl with functionality
that requires out-of-band modules that may prove pretty painful to install for the majority of folks out there.

This sounds reasonable.

But we shouldn't stop porting remus from xm to xl. we can mark xl-remus as experimental before a good remus-replicated-checkpointing-disk is ready(qemu qdisk).

I will keep doing it(with drbd for disks).

Thanks,
Lai

#43 lore raw

v8 cover Remus/Libxl: Network buffering support

This patch series adds support for network buffering in the Remus codebase in libxl.

Changes in V8:
Applied some comments(by IanJ).
Merge some struct definitions to it's implementation. (2/3/5 in V7 => 3 in V8)

Changes in V7:
Applied missing comments(by IanJ).
Applied Shriram comments.

merge netbufering tangled setup/teardown code into one patch. (2/6/8 in V6 => 5 in V7. 9/10 in V6 => 7 in V7)

Changes in V6:
Applied Ian Jackson's comments of V5 series. the [PATCH 2/4 V5] is split by small functionalities.

[PATCH 4/4 V5] --> [PATCH 13/13] netbuffer is default enabled.

Changes in V5:

Merge hotplug script patch (2/5) and hotplug script setup/teardown patch (3/5) into a single patch.

Changes in V4:

[1/5] Remove check for libnl command line utils in autoconf checks

[2/5] minor nits

[3/5] define LIBXL_HAVE_REMUS_NETBUF in libxl.h

[4/5] clean ups. Make the usleep in checkpoint callback asynchronous

[5/5] minor nits

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(by shriram):

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 Rajagopalan (8):
remus: add libnl3 dependency to autoconf scripts
libxl: rename remus_failover_cb() to remus_replication_failure_cb()
libxl: network buffering cmdline switch
remus: introduce a function to check whether network buffering is
enabled
remus: Remus network buffering core and APIs to setup/teardown
remus: implement the API to buffer/release packages
libxl: use the API to setup/teardown network buffering
libxl: control network buffering in remus callbacks

 README                                 |   4 +
 config/Tools.mk.in                     |   3 +
 docs/man/xl.conf.pod.5                 |   6 +
 docs/man/xl.pod.1                      |  11 +-
 docs/misc/xenstore-paths.markdown      |   4 +
 tools/configure.ac                     |  15 +
 tools/hotplug/Linux/Makefile           |   1 +
 tools/hotplug/Linux/remus-netbuf-setup | 184 +++++++++++
 tools/libxl/Makefile                   |  11 +
 tools/libxl/libxl.c                    |  44 ++-
 tools/libxl/libxl.h                    |  13 +
 tools/libxl/libxl_dom.c                |  92 +++++-
 tools/libxl/libxl_internal.h           |  48 +++
 tools/libxl/libxl_netbuffer.c          | 570 +++++++++++++++++++++++++++++++++
 tools/libxl/libxl_nonetbuffer.c        |  56 ++++
 tools/libxl/libxl_remus.c              |  63 ++++
 tools/libxl/libxl_types.idl            |   2 +
 tools/libxl/xl.c                       |   4 +
 tools/libxl/xl.h                       |   1 +
 tools/libxl/xl_cmdimpl.c               |  28 +-
 tools/libxl/xl_cmdtable.c              |   3 +
 tools/remus/README                     |   6 +
 22 files changed, 1142 insertions(+), 27 deletions(-)
 create mode 100644 tools/hotplug/Linux/remus-netbuf-setup
 create mode 100644 tools/libxl/libxl_netbuffer.c
 create mode 100644 tools/libxl/libxl_nonetbuffer.c
 create mode 100644 tools/libxl/libxl_remus.c
Signature · 1 line
1.8.3.2
#44 lore raw

PATCH v8 1/8 remus: add libnl3 dependency to autoconf scripts

From: Shriram Rajagopalan <[email protected]>

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 ++++
 config/Tools.mk.in   |  3 +++
 tools/configure.ac   | 15 +++++++++++++++
 tools/libxl/Makefile |  2 ++
 tools/remus/README   |  6 ++++++
 5 files changed, 30 insertions(+)
README +4 -0
index 9bbe734..e770932 100644
@@ -72,6 +72,10 @@ disabled at compile time:
     * cmake (if building vtpm stub domains)
     * markdown
     * figlet (for generating the traditional Xen start of day banner)
+    * 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
index d9d3239..81802b3 100644
@@ -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
index a62faf8..c03c2d2 100644
@@ -243,6 +243,21 @@ esac
 # 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
index 755b666..3647a2a 100644
@@ -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
 
 LIBXL_LIBS-$(CONFIG_ARM) += -lfdt
tools/remus/README +6 -0
index 9e8140b..4736252 100644
@@ -2,3 +2,9 @@ Remus provides fault tolerance for virtual machines by sending continuous
 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/
Signature · 1 line
1.8.3.2
#45 lore raw

PATCH v8 2/8 remus: introduce a function to check whether network buffering is enabled

In reply to Yang Hongyang

From: Shriram Rajagopalan <[email protected]>

libxl__netbuffer_enabled() returns 1 when network buffering is compiled, or returns 0 when network buffering is not compiled.

If network buffering is not compiled, and the user wants to use it, report a error and exit.

---
 tools/libxl/Makefile            |  7 +++++++
 tools/libxl/libxl_internal.h    |  2 ++
 tools/libxl/libxl_netbuffer.c   | 31 +++++++++++++++++++++++++++++++
 tools/libxl/libxl_nonetbuffer.c | 31 +++++++++++++++++++++++++++++++
 4 files changed, 71 insertions(+)
 create mode 100644 tools/libxl/libxl_netbuffer.c
 create mode 100644 tools/libxl/libxl_nonetbuffer.c
tools/libxl/Makefile +7 -0
index 3647a2a..a29c505 100644
@@ -45,6 +45,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_ARM) += libxl_nocpuid.o libxl_arm.o
 
tools/libxl/libxl_internal.h +2 -0
index b3a200d..79c536d 100644
@@ -2432,6 +2432,8 @@ typedef struct libxl__logdirty_switch {
     libxl__ev_time timeout;
 } libxl__logdirty_switch;
 
+_hidden int libxl__netbuffer_enabled(libxl__gc *gc);
+
 struct libxl__domain_suspend_state {
     /* set by caller of libxl__domain_suspend */
     libxl__ao *ao;
tools/libxl/libxl_netbuffer.c new file +31 -0
new file mode 100644
index 0000000..8e23d75
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2013
+ * Author Shriram Rajagopalan <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; version 2.1 only. with the special
+ * exception on linking described in file LICENSE.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ */
+
+#include "libxl_osdeps.h" /* must come before any other headers */
+
+#include "libxl_internal.h"
+
+int libxl__netbuffer_enabled(libxl__gc *gc)
+{
+    return 1;
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
tools/libxl/libxl_nonetbuffer.c new file +31 -0
new file mode 100644
index 0000000..6aa4bf1
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2013
+ * Author Shriram Rajagopalan <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; version 2.1 only. with the special
+ * exception on linking described in file LICENSE.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ */
+
+#include "libxl_osdeps.h" /* must come before any other headers */
+
+#include "libxl_internal.h"
+
+int libxl__netbuffer_enabled(libxl__gc *gc)
+{
+    return 0;
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
Signature · 1 line
1.8.3.2
#46 lore raw

PATCH v8 3/8 remus: Remus network buffering core and APIs to setup/teardown

In reply to Yang Hongyang

1.Add two members in libxl_domain_remus_info:
netbuf: whether netbuf is enabled
netbufscript: the path of the script which will be run to setup
and tear down the guest's interface.
2.introduce a new structure libxl__remus_state to save the remus state 3.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.

The following steps are taken 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.

And during teardown, the netlink resources are released, followed by invocation of hotplug scripts to remove the ifb devices.

---
 docs/misc/xenstore-paths.markdown      |   4 +
 tools/hotplug/Linux/Makefile           |   1 +
 tools/hotplug/Linux/remus-netbuf-setup | 184 +++++++++++++
 tools/libxl/Makefile                   |   2 +
 tools/libxl/libxl.c                    |  26 +-
 tools/libxl/libxl.h                    |  13 +
 tools/libxl/libxl_dom.c                |   4 +-
 tools/libxl/libxl_internal.h           |  32 +++
 tools/libxl/libxl_netbuffer.c          | 487 +++++++++++++++++++++++++++++++++
 tools/libxl/libxl_nonetbuffer.c        |  11 +
 tools/libxl/libxl_remus.c              |  41 +++
 tools/libxl/libxl_types.idl            |   2 +
 12 files changed, 803 insertions(+), 4 deletions(-)
 create mode 100644 tools/hotplug/Linux/remus-netbuf-setup
 create mode 100644 tools/libxl/libxl_remus.c
docs/misc/xenstore-paths.markdown +4 -0
index 70ab7f4..039eaea 100644
@@ -385,6 +385,10 @@ The guest's virtual time offset from UTC in seconds.
 
 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
index 47655f6..6139c1f 100644
@@ -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 +184 -0

184 lines not on this page · raw message

tools/libxl/Makefile +2 -0
index a29c505..670a2bc 100644
@@ -52,6 +52,8 @@ else
 LIBXL_OBJS-y += libxl_nonetbuffer.o
 endif
 
+LIBXL_OBJS-y += libxl_remus.o
+
 LIBXL_OBJS-$(CONFIG_X86) += libxl_cpuid.o libxl_x86.o
 LIBXL_OBJS-$(CONFIG_ARM) += libxl_nocpuid.o libxl_arm.o
 
tools/libxl/libxl.c +25 -1
index 30b0b06..f7696a3 100644
@@ -741,7 +741,31 @@ int libxl_domain_remus_start(libxl_ctx *ctx, libxl_domain_remus_info *info,
 
     assert(info);
 
-    /* TBD: Remus setup - i.e. attach qdisc, enable disk buffering, etc */
+    GCNEW(dss->remus_state);
+
+    /* convenience shorthand */
+    libxl__remus_state *remus_state = dss->remus_state;
+    remus_state->dss = dss;
+    libxl__ev_child_init(&remus_state->child);
+
+    /* TBD: enable disk buffering */
+
+    /* Setup network buffering */
+    if (info->netbuf) {
+        if (!libxl__netbuffer_enabled(gc)) {
+            LOG(ERROR, "Remus: No support for network buffering");
+            goto out;
+        }
+
+        if (info->netbufscript) {
+            remus_state->netbufscript =
+                libxl__strdup(gc, info->netbufscript);
+        } else {
+            remus_state->netbufscript =
+                GCSPRINTF("%s/remus-netbuf-setup",
+                libxl__xen_script_dir_path());
+        }
+    }
 
     /* Point of no return */
     libxl__domain_suspend(egc, dss);
tools/libxl/libxl.h +13 -0
index b2c3015..62f7dd4 100644
@@ -410,6 +410,19 @@
 #define LIBXL_HAVE_DRIVER_DOMAIN_CREATION 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
+
+/*
  * LIBXL_HAVE_SIGCHLD_SELECTIVE_REAP
  *
  * If this is defined:
tools/libxl/libxl_dom.c +1 -3
index 36e70b5..20aaec8 100644
@@ -753,8 +753,6 @@ int libxl__toolstack_restore(uint32_t domid, const uint8_t *buf,
 
 /*==================== Domain suspend (save) ====================*/
 
-static void domain_suspend_done(libxl__egc *egc,
-                        libxl__domain_suspend_state *dss, int rc);
 static void domain_suspend_callback_common_done(libxl__egc *egc,
                                 libxl__domain_suspend_state *dss, int ok);
 static void remus_domain_suspend_callback_common_done(libxl__egc *egc,
@@ -1703,7 +1701,7 @@ static void save_device_model_datacopier_done(libxl__egc *egc,
     dss->save_dm_callback(egc, dss, our_rc);
 }
 
-static void domain_suspend_done(libxl__egc *egc,
+void domain_suspend_done(libxl__egc *egc,
                         libxl__domain_suspend_state *dss, int rc)
 {
     STATE_AO_GC(dss->ao);
tools/libxl/libxl_internal.h +32 -0
index 79c536d..a6e5cff 100644
@@ -2432,8 +2432,39 @@ typedef struct libxl__logdirty_switch {
     libxl__ev_time timeout;
 } libxl__logdirty_switch;
 
+typedef struct libxl__remus_state {
+    /* Script to setup/teardown network buffers */
+    const char *netbufscript;
+    libxl__domain_suspend_state *dss;
+
+    /* private */
+    int saved_rc;
+    int dev_id;
+    /* Opaque context containing network buffer related stuff */
+    void *netbuf_state;
+    libxl__ev_time timeout;
+    libxl__ev_child child;
+} libxl__remus_state;
+
 _hidden int libxl__netbuffer_enabled(libxl__gc *gc);
 
+_hidden void domain_suspend_done(libxl__egc *egc,
+                                 libxl__domain_suspend_state *dss,
+                                 int rc);
+
+_hidden void libxl__remus_setup_done(libxl__egc *egc,
+                                     libxl__domain_suspend_state *dss,
+                                     int rc);
+
+_hidden void libxl__remus_netbuf_setup(libxl__egc *egc,
+                                       libxl__domain_suspend_state *dss);
+
+_hidden void libxl__remus_teardown_done(libxl__egc *egc,
+                                        libxl__domain_suspend_state *dss);
+
+_hidden void libxl__remus_netbuf_teardown(libxl__egc *egc,
+                                          libxl__domain_suspend_state *dss);
+
 struct libxl__domain_suspend_state {
     /* set by caller of libxl__domain_suspend */
     libxl__ao *ao;
@@ -2445,6 +2476,7 @@ struct libxl__domain_suspend_state {
     int live;
     int debug;
     const libxl_domain_remus_info *remus;
+    libxl__remus_state *remus_state;
     /* private */
     libxl__ev_evtchn guest_evtchn;
     int guest_evtchn_lockfd;
tools/libxl/libxl_netbuffer.c +487 -0

498 lines not on this page · raw message

tools/libxl/libxl_nonetbuffer.c +11 -0
index 6aa4bf1..559d0a6 100644
@@ -22,6 +22,17 @@ int libxl__netbuffer_enabled(libxl__gc *gc)
     return 0;
 }
 
+/* Remus network buffer related stubs */
+void libxl__remus_netbuf_setup(libxl__egc *egc,
+                               libxl__domain_suspend_state *dss)
+{
+}
+
+void libxl__remus_netbuf_teardown(libxl__egc *egc,
+                                  libxl__domain_suspend_state *dss)
+{
+}
+
 /*
  * Local variables:
  * mode: C
tools/libxl/libxl_remus.c new file +41 -0

41 lines not on this page · raw message

tools/libxl/libxl_types.idl +2 -0
index 612645c..cb3d926 100644
@@ -563,6 +563,8 @@ libxl_domain_remus_info = Struct("domain_remus_info",[
     ("interval",     integer),
     ("blackhole",    bool),
     ("compression",  bool),
+    ("netbuf",       bool),
+    ("netbufscript", string),
     ])
 
 libxl_event_type = Enumeration("event_type", [
Signature · 1 line
1.8.3.2
#47 lore raw

PATCH v8 4/8 remus: implement the API to buffer/release packages

In reply to Yang Hongyang

This patch implements two APIs:
1. libxl__remus_netbuf_start_new_epoch()
It marks a new epoch. The packages before this epoch will be flushed, and the packages after this epoch will be buffered. It will be called after the guest is suspended.
2. libxl__remus_netbuf_release_prev_epoch()
It flushes the buffered packages to client, and it will be called when a checkpoint finishes.

---
 tools/libxl/libxl_internal.h    |  7 ++++++
 tools/libxl/libxl_netbuffer.c   | 52 +++++++++++++++++++++++++++++++++++++++++
 tools/libxl/libxl_nonetbuffer.c | 14 +++++++++++
 3 files changed, 73 insertions(+)
tools/libxl/libxl_internal.h +7 -0
index a6e5cff..1357f2d 100644
@@ -2465,6 +2465,13 @@ _hidden void libxl__remus_teardown_done(libxl__egc *egc,
 _hidden void libxl__remus_netbuf_teardown(libxl__egc *egc,
                                           libxl__domain_suspend_state *dss);
 
+_hidden int
+libxl__remus_netbuf_start_new_epoch(libxl__gc *gc, uint32_t domid,
+                                    libxl__remus_state *remus_state);
+_hidden int
+libxl__remus_netbuf_release_prev_epoch(libxl__gc *gc, uint32_t domid,
+                                       libxl__remus_state *remus_state);
+
 struct libxl__domain_suspend_state {
     /* set by caller of libxl__domain_suspend */
     libxl__ao *ao;
tools/libxl/libxl_netbuffer.c +52 -0

58 lines not on this page · raw message

tools/libxl/libxl_nonetbuffer.c +14 -0
index 559d0a6..92f35bc 100644
@@ -33,6 +33,20 @@ void libxl__remus_netbuf_teardown(libxl__egc *egc,
 {
 }
 
+int libxl__remus_netbuf_start_new_epoch(libxl__gc *gc, uint32_t domid,
+                                        libxl__remus_state *remus_state)
+{
+    LOG(ERROR, "Remus: No support for network buffering");
+    return ERROR_FAIL;
+}
+
+int libxl__remus_netbuf_release_prev_epoch(libxl__gc *gc, uint32_t domid,
+                                           libxl__remus_state *remus_state)
+{
+    LOG(ERROR, "Remus: No support for network buffering");
+    return ERROR_FAIL;
+}
+
 /*
  * Local variables:
  * mode: C
Signature · 1 line
1.8.3.2
#48 lore raw

PATCH v8 5/8 libxl: use the API to setup/teardown network buffering

In reply to Yang Hongyang

If there is network buffering hotplug scripts, call libxl__remus_netbuf_setup() to setup the network buffering and libxl__remus_netbuf_teardown() to teardown network buffering.

---
 tools/libxl/libxl.c          |  6 +-----
 tools/libxl/libxl_dom.c      | 11 +++++++++++
 tools/libxl/libxl_internal.h |  7 +++++++
 tools/libxl/libxl_remus.c    | 22 ++++++++++++++++++++++
 4 files changed, 41 insertions(+), 5 deletions(-)
tools/libxl/libxl.c +1 -5
index f7696a3..88b34a4 100644
@@ -768,7 +768,7 @@ int libxl_domain_remus_start(libxl_ctx *ctx, libxl_domain_remus_info *info,
     }
 
     /* Point of no return */
-    libxl__domain_suspend(egc, dss);
+    libxl__remus_setup_initiate(egc, dss);
     return AO_INPROGRESS;
 
  out:
@@ -784,10 +784,6 @@ static void remus_failover_cb(libxl__egc *egc,
      * backup died or some network error occurred preventing us
      * from sending checkpoints.
      */
-
-    /* TBD: Remus cleanup - i.e. detach qdisc, release other
-     * resources.
-     */
     libxl__ao_complete(egc, ao, rc);
 }
 
tools/libxl/libxl_dom.c +11 -0
index 20aaec8..0695f3e 100644
@@ -1715,6 +1715,17 @@ void domain_suspend_done(libxl__egc *egc,
         xc_suspend_evtchn_release(CTX->xch, CTX->xce, domid,
                            dss->guest_evtchn.port, &dss->guest_evtchn_lockfd);
 
+    if (dss->remus_state) {
+        /*
+        * 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_initiate(egc, dss, rc);
+        return;
+    }
+
     dss->callback(egc, dss, rc);
 }
 
tools/libxl/libxl_internal.h +7 -0
index 1357f2d..34953ae 100644
@@ -2472,6 +2472,13 @@ _hidden int
 libxl__remus_netbuf_release_prev_epoch(libxl__gc *gc, uint32_t domid,
                                        libxl__remus_state *remus_state);
 
+_hidden void libxl__remus_setup_initiate(libxl__egc *egc,
+                                         libxl__domain_suspend_state *dss);
+
+_hidden void libxl__remus_teardown_initiate(libxl__egc *egc,
+                                            libxl__domain_suspend_state *dss,
+                                            int rc);
+
 struct libxl__domain_suspend_state {
     /* set by caller of libxl__domain_suspend */
     libxl__ao *ao;
tools/libxl/libxl_remus.c +22 -0
index 4e40412..da303e7 100644
@@ -18,6 +18,15 @@
 #include "libxl_internal.h"
 
 /*----- remus setup/teardown code -----*/
+void libxl__remus_setup_initiate(libxl__egc *egc,
+                                 libxl__domain_suspend_state *dss)
+{
+    libxl__ev_time_init(&dss->remus_state->timeout);
+    if (!dss->remus_state->netbufscript)
+        libxl__remus_setup_done(egc, dss, 0);
+    else
+        libxl__remus_netbuf_setup(egc, dss);
+}
 
 void libxl__remus_setup_done(libxl__egc *egc,
                              libxl__domain_suspend_state *dss,
@@ -34,6 +43,19 @@ void libxl__remus_setup_done(libxl__egc *egc,
     domain_suspend_done(egc, dss, rc);
 }
 
+void libxl__remus_teardown_initiate(libxl__egc *egc,
+                                    libxl__domain_suspend_state *dss,
+                                    int rc)
+{
+    /* stash rc somewhere before invoking teardown ops. */
+    dss->remus_state->saved_rc = rc;
+
+    if (!dss->remus_state->netbuf_state)
+        libxl__remus_teardown_done(egc, dss);
+    else
+        libxl__remus_netbuf_teardown(egc, dss);
+}
+
 void libxl__remus_teardown_done(libxl__egc *egc,
                                 libxl__domain_suspend_state *dss)
 {
Signature · 1 line
1.8.3.2
#49 lore raw

PATCH v8 6/8 libxl: rename remus_failover_cb() to remus_replication_failure_cb()

In reply to Yang Hongyang

From: Shriram Rajagopalan <[email protected]>

Failover means that: the machine on which primary vm is running is down, and we need to start the secondary vm to take over the primary vm. remus_failover_cb() is called when remus fails, not when we need to do failover. So rename it to remus_replication_failure_cb()

---
 tools/libxl/libxl.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
tools/libxl/libxl.c +7 -5
index 88b34a4..c4a4751 100644
@@ -710,8 +710,9 @@ out:
     return ptr;
 }
 
-static void remus_failover_cb(libxl__egc *egc,
-                              libxl__domain_suspend_state *dss, int rc);
+static void remus_replication_failure_cb(libxl__egc *egc,
+                                         libxl__domain_suspend_state *dss,
+                                         int rc);
 
 /* TODO: Explicit Checkpoint acknowledgements via recv_fd. */
 int libxl_domain_remus_start(libxl_ctx *ctx, libxl_domain_remus_info *info,
@@ -730,7 +731,7 @@ int libxl_domain_remus_start(libxl_ctx *ctx, libxl_domain_remus_info *info,
 
     GCNEW(dss);
     dss->ao = ao;
-    dss->callback = remus_failover_cb;
+    dss->callback = remus_replication_failure_cb;
     dss->domid = domid;
     dss->fd = send_fd;
     /* TODO do something with recv_fd */
@@ -775,8 +776,9 @@ int libxl_domain_remus_start(libxl_ctx *ctx, libxl_domain_remus_info *info,
     return AO_ABORT(rc);
 }
 
-static void remus_failover_cb(libxl__egc *egc,
-                              libxl__domain_suspend_state *dss, int rc)
+static void remus_replication_failure_cb(libxl__egc *egc,
+                                         libxl__domain_suspend_state *dss,
+                                         int rc)
 {
     STATE_AO_GC(dss->ao);
     /*
Signature · 1 line
1.8.3.2
#50 lore raw

PATCH v8 7/8 libxl: control network buffering in remus callbacks

In reply to Yang Hongyang

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 | 77 +++++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 71 insertions(+), 6 deletions(-)
tools/libxl/libxl_dom.c +71 -6
index 0695f3e..1272bf6 100644
@@ -1432,7 +1432,24 @@ static void libxl__remus_domain_suspend_callback(void *data)
 static void remus_domain_suspend_callback_common_done(libxl__egc *egc,
                                 libxl__domain_suspend_state *dss, int ok)
 {
-    /* REMUS TODO: Issue disk and network checkpoint reqs. */
+    /* Convenience aliases */
+    libxl__remus_state *const remus_state = dss->remus_state;
+
+    STATE_AO_GC(dss->ao);
+
+    /* REMUS TODO: Issue disk checkpoint reqs. */
+    if (!remus_state->netbuf_state || !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_state))
+        ok = 0;
+
+out:
     libxl__xc_domain_saverestore_async_callback_done(egc, &dss->shs, ok);
 }
 
@@ -1446,7 +1463,7 @@ static int libxl__remus_domain_resume_callback(void *data)
     if (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;
 }
 
@@ -1454,6 +1471,8 @@ static int libxl__remus_domain_resume_callback(void *data)
 
 static 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)
 {
@@ -1473,10 +1492,56 @@ static void libxl__remus_domain_checkpoint_callback(void *data)
 static 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->interval * 1000);
+    /* Convenience aliases */
+    /*
+     * REMUS TODO: Wait for disk and explicit memory ack (through restore
+     * callback from remote) before releasing network buffer.
+     */
+    libxl__remus_state *const remus_state = dss->remus_state;
+
+    STATE_AO_GC(dss->ao);
+
+    if (rc) {
+        LOG(ERROR, "Failed to save device model. Terminating Remus..");
+        goto out;
+    }
+
+    if (remus_state->netbuf_state) {
+        rc = libxl__remus_netbuf_release_prev_epoch(gc, dss->domid,
+                                                    remus_state);
+        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_state->timeout,
+                                     remus_next_checkpoint,
+                                     dss->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_state *remus_state = CONTAINER_OF(ev, *remus_state, timeout);
+
+    /* Convenience aliases */
+    libxl__domain_suspend_state *const dss = remus_state->dss;
+
+    STATE_AO_GC(dss->ao);
+
+    libxl__ev_time_deregister(gc, &remus_state->timeout);
     libxl__xc_domain_saverestore_async_callback_done(egc, &dss->shs, 1);
 }
 
Signature · 1 line
1.8.3.2
#51 lore raw

PATCH v8 8/8 libxl: network buffering cmdline switch

In reply to Yang Hongyang

From: Shriram Rajagopalan <[email protected]>

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.

Note: the network buffering is enabled as default. If you want to disable it, please use -n option.

---
 docs/man/xl.conf.pod.5    |  6 ++++++
 docs/man/xl.pod.1         | 11 ++++++++++-
 tools/libxl/xl.c          |  4 ++++
 tools/libxl/xl.h          |  1 +
 tools/libxl/xl_cmdimpl.c  | 28 ++++++++++++++++++++++------
 tools/libxl/xl_cmdtable.c |  3 +++
 6 files changed, 46 insertions(+), 7 deletions(-)
docs/man/xl.conf.pod.5 +6 -0
index 7c43bde..8ae19bb 100644
@@ -105,6 +105,12 @@ Configures the default gateway device to set for virtual network devices.
 
 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 +10 -1
index f7ceaa8..6319f36 100644
@@ -405,7 +405,7 @@ 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.
+     There is no support for disk buffering at the moment.
 
 B<OPTIONS>
 
@@ -424,6 +424,15 @@ Generally useful for debugging.
 
 Disable memory checkpoint compression.
 
+=item B<-n>
+
+Disable network output buffering.
+
+=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
index 527b4c5..43ef42a 100644
@@ -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;
 bool progress_use_cr = 0;
@@ -178,6 +179,9 @@ static void parse_global_config(const char *configfile,
     if (!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
index 10a2e66..087eb8c 100644
@@ -170,6 +170,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 +22 -6
index 8389468..0632e8f 100644
@@ -7279,8 +7279,9 @@ int main_remus(int argc, char **argv)
     r_info.interval = 200;
     r_info.blackhole = 0;
     r_info.compression = 1;
+    r_info.netbuf = 1;
 
-    SWITCH_FOREACH_OPT(opt, "bui:s:e", NULL, "remus", 2) {
+    SWITCH_FOREACH_OPT(opt, "buni:s:N:e", NULL, "remus", 2) {
     case 'i':
         r_info.interval = atoi(optarg);
         break;
@@ -7290,6 +7291,12 @@ int main_remus(int argc, char **argv)
     case 'u':
         r_info.compression = 0;
         break;
+    case 'n':
+        r_info.netbuf = 0;
+        break;
+    case 'N':
+        r_info.netbufscript = optarg;
+        break;
     case 's':
         ssh_command = optarg;
         break;
@@ -7301,6 +7308,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) {
@@ -7338,13 +7348,19 @@ 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.
-     * TODO: Split-Brain check.
+    /* check if the domain exists. User may have xl destroyed the
+     * domain to force failover
      */
-    fprintf(stderr, "remus sender: libxl_domain_suspend failed"
-            " (rc=%d)\n", rc);
+    if (libxl_domain_info(ctx, 0, domid)) {
+        fprintf(stderr, "Remus: Primary domain has been destroyed.\n");
+        close(send_fd);
+        return 0;
+    }
 
+    /* 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.
+     */
     if (rc == ERROR_GUEST_TIMEDOUT)
         fprintf(stderr, "Failed to suspend domain at primary.\n");
     else {
tools/libxl/xl_cmdtable.c +3 -0
index e8ab93a..cfb5999 100644
@@ -484,6 +484,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                      Disable 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"
Signature · 1 line
1.8.3.2
#52 lore raw

PATCH 1/7 introduce a new function libxl__remus_netbuf_setup_done()

We will exec some scripts to setup netbuf and disk, so we need two asynchronous functions that are called when the setup is done.

This patch introduces the asynchronous function for netbuf.

---
 tools/libxl/libxl_internal.h  |    6 +++---
 tools/libxl/libxl_netbuffer.c |    4 ++--
 tools/libxl/libxl_remus.c     |   15 +++++++++++----
 3 files changed, 16 insertions(+), 9 deletions(-)
tools/libxl/libxl_internal.h +3 -3
index 9ad0e27..3719bf4 100644
@@ -2454,9 +2454,9 @@ _hidden void domain_suspend_done(libxl__egc *egc,
                                  libxl__domain_suspend_state *dss,
                                  int rc);
 
-_hidden void libxl__remus_setup_done(libxl__egc *egc,
-                                     libxl__domain_suspend_state *dss,
-                                     int rc);
+_hidden void libxl__remus_netbuf_setup_done(libxl__egc *egc,
+                                            libxl__domain_suspend_state *dss,
+                                            int rc);
 
 _hidden void libxl__remus_netbuf_setup(libxl__egc *egc,
                                        libxl__domain_suspend_state *dss);
tools/libxl/libxl_netbuffer.c +2 -2
index 22fffec..a596d31 100644
@@ -413,7 +413,7 @@ static void netbuf_setup_script_cb(libxl__egc *egc,
 
     rc = init_qdiscs(gc, remus_state);
  out:
-    libxl__remus_setup_done(egc, remus_state->dss, rc);
+    libxl__remus_netbuf_setup_done(egc, remus_state->dss, rc);
 }
 
 /* Scan through the list of vifs belonging to domid and
@@ -454,7 +454,7 @@ void libxl__remus_netbuf_setup(libxl__egc *egc,
     return;
 
  out:
-    libxl__remus_setup_done(egc, dss, rc);
+    libxl__remus_netbuf_setup_done(egc, dss, rc);
 }
 
 static void netbuf_teardown_script_cb(libxl__egc *egc,
tools/libxl/libxl_remus.c +11 -4
index da303e7..ef90e6b 100644
@@ -23,14 +23,14 @@ void libxl__remus_setup_initiate(libxl__egc *egc,
 {
     libxl__ev_time_init(&dss->remus_state->timeout);
     if (!dss->remus_state->netbufscript)
-        libxl__remus_setup_done(egc, dss, 0);
+        libxl__remus_netbuf_setup_done(egc, dss, 0);
     else
         libxl__remus_netbuf_setup(egc, dss);
 }
 
-void libxl__remus_setup_done(libxl__egc *egc,
-                             libxl__domain_suspend_state *dss,
-                             int rc)
+static void libxl__remus_setup_done(libxl__egc *egc,
+                                    libxl__domain_suspend_state *dss,
+                                    int rc)
 {
     STATE_AO_GC(dss->ao);
     if (!rc) {
@@ -43,6 +43,13 @@ void libxl__remus_setup_done(libxl__egc *egc,
     domain_suspend_done(egc, dss, rc);
 }
 
+void libxl__remus_netbuf_setup_done(libxl__egc *egc,
+                                    libxl__domain_suspend_state *dss,
+                                    int rc)
+{
+    libxl__remus_setup_done(egc, dss, rc);
+}
+
 void libxl__remus_teardown_initiate(libxl__egc *egc,
                                     libxl__domain_suspend_state *dss,
                                     int rc)
Signature · 1 line
1.7.4.4
#53 lore raw

PATCH 2/7 introduce a new function libxl__remus_netbuf_teardown_done()

We will exec some scripts to teardown netbuf and disk, so we need two asynchronous functions that are called when the teardown is done.

This patch introduces the asynchronous function for netbuf.

---
 tools/libxl/libxl_internal.h  |    4 ++--
 tools/libxl/libxl_netbuffer.c |    4 ++--
 tools/libxl/libxl_remus.c     |   12 +++++++++---
 3 files changed, 13 insertions(+), 7 deletions(-)
tools/libxl/libxl_internal.h +2 -2
index 3719bf4..dc49f16 100644
@@ -2461,8 +2461,8 @@ _hidden void libxl__remus_netbuf_setup_done(libxl__egc *egc,
 _hidden void libxl__remus_netbuf_setup(libxl__egc *egc,
                                        libxl__domain_suspend_state *dss);
 
-_hidden void libxl__remus_teardown_done(libxl__egc *egc,
-                                        libxl__domain_suspend_state *dss);
+_hidden void libxl__remus_netbuf_teardown_done(libxl__egc *egc,
+                                               libxl__domain_suspend_state *dss);
 
 _hidden void libxl__remus_netbuf_teardown(libxl__egc *egc,
                                           libxl__domain_suspend_state *dss);
tools/libxl/libxl_netbuffer.c +2 -2
index a596d31..c9c1ba7 100644
@@ -485,7 +485,7 @@ static void netbuf_teardown_script_cb(libxl__egc *egc,
     }
 
  out:
-    libxl__remus_teardown_done(egc, remus_state->dss);
+    libxl__remus_netbuf_teardown_done(egc, remus_state->dss);
 }
 
 /* Note: This function will be called in the same gc context as
@@ -506,7 +506,7 @@ void libxl__remus_netbuf_teardown(libxl__egc *egc,
     remus_state->dev_id = 0;
     if (exec_netbuf_script(gc, remus_state, "teardown",
                            netbuf_teardown_script_cb))
-        libxl__remus_teardown_done(egc, dss);
+        libxl__remus_netbuf_teardown_done(egc, dss);
 }
 
 /* The buffer_op's value, not the value passed to kernel */
tools/libxl/libxl_remus.c +9 -3
index ef90e6b..78652d2 100644
@@ -58,13 +58,19 @@ void libxl__remus_teardown_initiate(libxl__egc *egc,
     dss->remus_state->saved_rc = rc;
 
     if (!dss->remus_state->netbuf_state)
-        libxl__remus_teardown_done(egc, dss);
+        libxl__remus_netbuf_teardown_done(egc, dss);
     else
         libxl__remus_netbuf_teardown(egc, dss);
 }
 
-void libxl__remus_teardown_done(libxl__egc *egc,
-                                libxl__domain_suspend_state *dss)
+static void libxl__remus_teardown_done(libxl__egc *egc,
+                                       libxl__domain_suspend_state *dss)
 {
     dss->callback(egc, dss, dss->remus_state->saved_rc);
 }
+
+void libxl__remus_netbuf_teardown_done(libxl__egc *egc,
+                                       libxl__domain_suspend_state *dss)
+{
+    libxl__remus_teardown_done(egc, dss);
+}
Signature · 1 line
1.7.4.4
#54 lore raw

PATCH 3/7 introduce an API to async exec scripts

In reply to Lai Jiangshan
---
 tools/libxl/libxl_internal.c |   79 ++++++++++++++++++++++++++++++++++++++++++
 tools/libxl/libxl_internal.h |   17 +++++++++
 2 files changed, 96 insertions(+), 0 deletions(-)
tools/libxl/libxl_internal.c +79 -0
index 6c94d3e..4c9c23b 100644
@@ -375,6 +375,85 @@ out:
     return rc;
 }
 
+static void libxl_async_exec_timeout(libxl__egc *egc,
+                                     libxl__ev_time *ev,
+                                     const struct timeval *requested_abs)
+{
+    libxl_async_exec *async_exec = CONTAINER_OF(ev, *async_exec, time);
+
+    STATE_AO_GC(async_exec->ao);
+
+    libxl__ev_time_deregister(gc, &async_exec->time);
+    assert(libxl__ev_child_inuse(&async_exec->child));
+
+    LOG(DEBUG, "killing hotplug script %s because of timeout",
+        async_exec->args[0]);
+
+    if (kill(async_exec->child.pid, SIGKILL)) {
+        LOGEV(ERROR, errno, "unable to kill hotplug script %s [%ld]",
+              async_exec->args[0],
+              (unsigned long)async_exec->child.pid);
+    }
+
+    return;
+}
+
+static void libxl_async_exec_done(libxl__egc *egc,
+                                  libxl__ev_child *child,
+                                  pid_t pid, int status)
+{
+    libxl_async_exec *async_exec = CONTAINER_OF(child, *async_exec, child);
+
+    STATE_AO_GC(async_exec->ao);
+
+    libxl__ev_time_deregister(gc, &async_exec->time);
+
+    if (status && !async_exec->allow_fail) {
+        libxl_report_child_exitstatus(CTX, LIBXL__LOG_ERROR,
+                                      async_exec->args[0],
+                                      pid, status);
+    }
+
+    async_exec->finish_cb(async_exec->opaque, status);
+}
+
+int libxl_async_exec_script(libxl__gc *gc, libxl_async_exec *async_exec)
+{
+    pid_t pid;
+
+    /* Convenience aliases */
+    libxl__ev_child *const child = &async_exec->child;
+    char * const *args = async_exec->args;
+    char * const *env = async_exec->env;
+
+    /* Set hotplug timeout */
+    if (libxl__ev_time_register_rel(gc, &async_exec->time,
+                                    libxl_async_exec_timeout,
+                                    async_exec->timeout * 1000)) {
+        LOG(ERROR, "unable to register timeout for "
+            "script %s", args[0]);
+        return ERROR_FAIL;
+    }
+
+    LOG(DEBUG, "Calling script: %s ", args[0]);
+
+    /* Fork and exec netbuf script */
+    pid = libxl__ev_child_fork(gc, child, libxl_async_exec_done);
+    if (pid == -1) {
+        LOG(ERROR, "unable to fork for script %s", args[0]);
+        return ERROR_FAIL;
+    }
+
+    if (!pid) {
+        /* child: Launch netbuf script */
+        libxl__exec(gc, -1, -1, -1, args[0], args, env);
+        /* notreached */
+        abort();
+    }
+
+    return 0;
+}
+
 /*
  * Local variables:
  * mode: C
tools/libxl/libxl_internal.h +17 -0
index dc49f16..ab82334 100644
@@ -3133,6 +3133,23 @@ void libxl__numa_candidate_put_nodemap(libxl__gc *gc,
  */
 #define CTYPE(isfoo,c) (isfoo((unsigned char)(c)))
 
+typedef struct libxl_async_exec {
+    char * *env;
+    char * *args;
+    void *opaque;
+    void (*finish_cb)(void *opaque, int status);
+    /* unit: second */
+    int timeout;
+    bool allow_fail;
+
+    libxl__ev_time time;
+    libxl__ev_child child;
+    libxl__ao *ao;
+} libxl_async_exec;
+
+_hidden extern int libxl_async_exec_script(libxl__gc *gc,
+                                           libxl_async_exec *async_exec);
+
 
 #endif
 
Signature · 1 line
1.7.4.4
#55 lore raw

PATCH 4/7 netbuffer: use async exec API to exec the netbuffer script

In reply to Lai Jiangshan
---
 tools/libxl/libxl.c           |    2 +-
 tools/libxl/libxl_internal.h  |    3 +-
 tools/libxl/libxl_netbuffer.c |  139 ++++++++++++-----------------------------
 3 files changed, 43 insertions(+), 101 deletions(-)
tools/libxl/libxl.c +1 -1
index c4a4751..1596146 100644
@@ -747,7 +747,7 @@ int libxl_domain_remus_start(libxl_ctx *ctx, libxl_domain_remus_info *info,
     /* convenience shorthand */
     libxl__remus_state *remus_state = dss->remus_state;
     remus_state->dss = dss;
-    libxl__ev_child_init(&remus_state->child);
+    remus_state->egc = egc;
 
     /* TBD: enable disk buffering */
 
tools/libxl/libxl_internal.h +2 -1
index ab82334..bf92975 100644
@@ -2438,14 +2438,15 @@ typedef struct libxl__remus_state {
     /* Script to setup/teardown network buffers */
     const char *netbufscript;
     libxl__domain_suspend_state *dss;
+    libxl__egc *egc;
 
     /* private */
     int saved_rc;
     int dev_id;
     /* Opaque context containing network buffer related stuff */
     void *netbuf_state;
+    /* used for checkpoint */
     libxl__ev_time timeout;
-    libxl__ev_child child;
 } libxl__remus_state;
 
 _hidden int libxl__netbuffer_enabled(libxl__gc *gc);
tools/libxl/libxl_netbuffer.c +40 -99

234 lines not on this page · raw message

Signature · 1 line
1.7.4.4
#56 lore raw

PATCH 5/7 netbuf: move dev_id from remus_state to netbuf_state

In reply to Lai Jiangshan
---
 tools/libxl/libxl_internal.h  |    1 -
 tools/libxl/libxl_netbuffer.c |   17 +++++++++--------
 2 files changed, 9 insertions(+), 9 deletions(-)
tools/libxl/libxl_internal.h +0 -1
index bf92975..4e07969 100644
@@ -2442,7 +2442,6 @@ typedef struct libxl__remus_state {
 
     /* private */
     int saved_rc;
-    int dev_id;
     /* Opaque context containing network buffer related stuff */
     void *netbuf_state;
     /* used for checkpoint */
tools/libxl/libxl_netbuffer.c +9 -8
index d996832..cd822f8 100644
@@ -32,6 +32,7 @@ typedef struct libxl__remus_netbuf_state {
     const char **vif_list;
     const char **ifb_list;
     uint32_t num_netbufs;
+    int dev_id;
     libxl_async_exec async_exec;
 } libxl__remus_netbuf_state;
 
@@ -254,8 +255,8 @@ static void setup_env(libxl_async_exec *async_exec, char *op,
     /* Convenience aliases */
     char *const script = libxl__strdup(gc, remus_state->netbufscript);
     const uint32_t domid = remus_state->dss->domid;
-    const int devid = remus_state->dev_id;
     libxl__remus_netbuf_state *const netbuf_state = remus_state->netbuf_state;
+    const int devid = netbuf_state->dev_id;
     const char *const vif = netbuf_state->vif_list[devid];
     const char *const ifb = netbuf_state->ifb_list[devid];
 
@@ -296,8 +297,8 @@ static void netbuf_setup_script_cb(void *opaque, int status)
 
     /* Convenience aliases */
     const uint32_t domid = remus_state->dss->domid;
-    const int devid = remus_state->dev_id;
     libxl__remus_netbuf_state *const netbuf_state = remus_state->netbuf_state;
+    const int devid = netbuf_state->dev_id;
     const char *const vif = netbuf_state->vif_list[devid];
     const char **const ifb = &netbuf_state->ifb_list[devid];
 
@@ -339,8 +340,8 @@ static void netbuf_setup_script_cb(void *opaque, int status)
     }
 
     LOG(DEBUG, "%s will buffer packets from vif %s", *ifb, vif);
-    remus_state->dev_id++;
-    if (remus_state->dev_id < netbuf_state->num_netbufs) {
+    netbuf_state->dev_id++;
+    if (netbuf_state->dev_id < netbuf_state->num_netbufs) {
         setup_env(&netbuf_state->async_exec, "setup", remus_state);
         if (libxl_async_exec_script(gc, &netbuf_state->async_exec))
             goto out;
@@ -386,7 +387,7 @@ void libxl__remus_netbuf_setup(libxl__egc *egc,
     GCNEW_ARRAY(netbuf_state->ifb_list, num_netbufs);
     netbuf_state->num_netbufs = num_netbufs;
     remus_state->netbuf_state = netbuf_state;
-    remus_state->dev_id = 0;
+    netbuf_state->dev_id = 0;
 
     netbuf_state->async_exec.timeout = LIBXL_HOTPLUG_TIMEOUT;
     netbuf_state->async_exec.opaque = remus_state;
@@ -410,8 +411,8 @@ static void netbuf_teardown_script_cb(void *opaque, int status)
 
     STATE_AO_GC(remus_state->dss->ao);
 
-    remus_state->dev_id++;
-    if (remus_state->dev_id < netbuf_state->num_netbufs) {
+    netbuf_state->dev_id++;
+    if (netbuf_state->dev_id < netbuf_state->num_netbufs) {
         setup_env(&netbuf_state->async_exec, "teardown", remus_state);
         if (libxl_async_exec_script(gc, &netbuf_state->async_exec))
             goto out;
@@ -443,7 +444,7 @@ void libxl__remus_netbuf_teardown(libxl__egc *egc,
     netbuf_state->async_exec.opaque = remus_state;
     netbuf_state->async_exec.finish_cb = netbuf_teardown_script_cb;
     netbuf_state->async_exec.ao = ao;
-    remus_state->dev_id = 0;
+    netbuf_state->dev_id = 0;
     setup_env(&netbuf_state->async_exec, "teardown", remus_state);
 
     if (libxl_async_exec_script(gc, &netbuf_state->async_exec))
Signature · 1 line
1.7.4.4
#57 lore raw

PATCH 6/7 remus: implement remus replicated checkpointing disk

In reply to Lai Jiangshan
---
 tools/libxl/Makefile           |    1 +
 tools/libxl/libxl_dom.c        |   19 +++-
 tools/libxl/libxl_internal.h   |   16 +++
 tools/libxl/libxl_remus.c      |   18 +++
 tools/libxl/libxl_remus_disk.c |  285 ++++++++++++++++++++++++++++++++++++++++
 tools/libxl/libxl_remus_disk.h |   74 +++++++++++
 6 files changed, 411 insertions(+), 2 deletions(-)
 create mode 100644 tools/libxl/libxl_remus_disk.c
 create mode 100644 tools/libxl/libxl_remus_disk.h
tools/libxl/Makefile +1 -0
index 670a2bc..b040a79 100644
@@ -53,6 +53,7 @@ LIBXL_OBJS-y += libxl_nonetbuffer.o
 endif
 
 LIBXL_OBJS-y += libxl_remus.o
+LIBXL_OBJS-y += libxl_remus_disk.o
 
 LIBXL_OBJS-$(CONFIG_X86) += libxl_cpuid.o libxl_x86.o
 LIBXL_OBJS-$(CONFIG_ARM) += libxl_nocpuid.o libxl_arm.o
tools/libxl/libxl_dom.c +17 -2
index 1272bf6..ebaece2 100644
@@ -1437,9 +1437,14 @@ static void remus_domain_suspend_callback_common_done(libxl__egc *egc,
 
     STATE_AO_GC(dss->ao);
 
-    /* REMUS TODO: Issue disk checkpoint reqs. */
     if (!remus_state->netbuf_state || !ok) goto out;
 
+    /* Issue disk checkpoint reqs. */
+    if (libxl__remus_disk_postsuspend(remus_state)) {
+        ok = 0;
+        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
@@ -1463,7 +1468,10 @@ static int libxl__remus_domain_resume_callback(void *data)
     if (libxl__domain_resume(gc, dss->domid, /* Fast Suspend */1))
         return 0;
 
-    /* REMUS TODO: Deal with disk. */
+    /* Deal with disk. */
+    if (libxl__remus_disk_preresume(dss->remus_state))
+        return 0;
+
     return 1;
 }
 
@@ -1506,6 +1514,13 @@ static void remus_checkpoint_dm_saved(libxl__egc *egc,
         goto out;
     }
 
+    rc = libxl__remus_disk_commit(remus_state);
+    if (rc) {
+        LOG(ERROR, "Failed to commit disk state"
+            " Terminating Remus..");
+        goto out;
+    }
+
     if (remus_state->netbuf_state) {
         rc = libxl__remus_netbuf_release_prev_epoch(gc, dss->domid,
                                                     remus_state);
tools/libxl/libxl_internal.h +16 -0
index 4e07969..7c30d9a 100644
@@ -2446,6 +2446,9 @@ typedef struct libxl__remus_state {
     void *netbuf_state;
     /* used for checkpoint */
     libxl__ev_time timeout;
+
+    /* Opaque context containing disk related stuff */
+    void *disk_state;
 } libxl__remus_state;
 
 _hidden int libxl__netbuffer_enabled(libxl__gc *gc);
@@ -2474,6 +2477,19 @@ _hidden int
 libxl__remus_netbuf_release_prev_epoch(libxl__gc *gc, uint32_t domid,
                                        libxl__remus_state *remus_state);
 
+_hidden int libxl__remus_disk_postsuspend(libxl__remus_state *state);
+_hidden int libxl__remus_disk_preresume(libxl__remus_state *state);
+_hidden int libxl__remus_disk_commit(libxl__remus_state *state);
+_hidden void libxl__remus_disk_setup(libxl__egc *egc,
+                                     libxl__domain_suspend_state *dss);
+_hidden void libxl__remus_disk_setup_done(libxl__egc *egc,
+                                          libxl__domain_suspend_state *dss,
+                                          int rc);
+_hidden void libxl__remus_disk_teardown(libxl__egc *egc,
+                                        libxl__domain_suspend_state *dss);
+_hidden void libxl__remus_disk_teardown_done(libxl__egc *egc,
+                                             libxl__domain_suspend_state *dss);
+
 _hidden void libxl__remus_setup_initiate(libxl__egc *egc,
                                          libxl__domain_suspend_state *dss);
 
tools/libxl/libxl_remus.c +18 -0
index 78652d2..9eab98d 100644
@@ -47,6 +47,18 @@ void libxl__remus_netbuf_setup_done(libxl__egc *egc,
                                     libxl__domain_suspend_state *dss,
                                     int rc)
 {
+    if (rc) {
+        libxl__remus_setup_done(egc, dss, rc);
+        return;
+    }
+
+    libxl__remus_disk_setup(egc, dss);
+}
+
+void libxl__remus_disk_setup_done(libxl__egc *egc,
+                                   libxl__domain_suspend_state *dss,
+                                   int rc)
+{
     libxl__remus_setup_done(egc, dss, rc);
 }
 
@@ -72,5 +84,11 @@ static void libxl__remus_teardown_done(libxl__egc *egc,
 void libxl__remus_netbuf_teardown_done(libxl__egc *egc,
                                        libxl__domain_suspend_state *dss)
 {
+    libxl__remus_disk_teardown(egc, dss);
+}
+
+void libxl__remus_disk_teardown_done(libxl__egc *egc,
+                                     libxl__domain_suspend_state *dss)
+{
     libxl__remus_teardown_done(egc, dss);
 }
tools/libxl/libxl_remus_disk.c new file +285 -0

285 lines not on this page · raw message

tools/libxl/libxl_remus_disk.h new file +74 -0

74 lines not on this page · raw message

Signature · 1 line
1.7.4.4
#58 lore raw

Re: [PATCH 6/7] remus: implement remus replicated checkpointing disk

tools/libxl/libxl_dom.c static int libxl__remus_domain_resume_callback(void *data) · line 1477

Quoted 12 lines
tools/libxl/libxl_dom.c +4 -1
@@ -1463,7 +1468,10 @@ static int libxl__remus_domain_resume_callback(void *data)
    if (libxl__domain_resume(gc, dss->domid, /* Fast Suspend */1))
        return 0;
 
-    /* REMUS TODO: Deal with disk. */
+    /* Deal with disk. */
+    if (libxl__remus_disk_preresume(dss->remus_state))
+        return 0;
+
    return 1;
 }
 

Bug. I think I mentioned this last time. Disk needs to be resumed before the domain is resumed. Just move the domain resume call below the above code snippet.

Quoted 28 lines
tools/libxl/libxl_remus_disk.h new file +28 -0
+typedef struct libxl__remus_disk_type {
+    /* checkpointing */
+    int (*postsuspend)(libxl__remus_disk *remus_disk);
+    int (*preresume)(libxl__remus_disk *remus_disk);
+    int (*commit)(libxl__remus_disk *remus_disk);
+
+    /*
+     * Return value:
+     *   1: the disk is not this type or the script is still running
+     *   0: the disk is this type
+     *  -1: error
+     */
+    int (*match)(libxl__domain_suspend_state *dss,
+                 const libxl_device_disk *disk,
+                 libxl_async_exec *async_exec,
+                 void *disk_state);
+
+    /*
+     * This is synchronous callback. Return value:
+     *  0: setup is done
+     * -1: error
+     *
+     */
+    int (*setup)(libxl__remus_disk *remus_disk);
+
+    /*
+     * Return value:
+     *   1: the script is still running

tools/libxl/libxl_remus_disk.h line 69

Quoted 10 lines
tools/libxl/libxl_remus_disk.h new file +10 -0
+     *   0: the script is done
+     *  -1: error
+     */
+    int (*teardown)(libxl__remus_disk *remus_disk,
+                    libxl_async_exec *async_exec);
+
+    /* the size of the private data */
+    int size;
+} libxl__remus_disk_type;
+

This vtable approach is neat. I am fine with the current disk checkpoint approach you have taken.

Something that might be worth thinking about:
The old remus code used this approach for both the disk and network buffering. Given that this code is going in a similar direction, I suggest hoisting this structure
up to an abstract buffer type, with setup, teardown, postsuspend, preresume and commit callbacks.

For disks, semantically,
setup [..]
teardown [..]
postsuspend [start flushing buffered writes to backup host] preresume [wait until all writes have been flushed to backup host] commit [no-op]

For network devices, semantically,
setup [..]
teardown [..]
postsuspend [no-op]
preresume [start_new_epoch - libnl call]
commit [release_prev_epoch - libnl call]

This way, in domain_suspend_done, the only thing we need to do is foreach remus buffer
buffer.postsuspend()

Similarly, in resume_callback()

foreach remus buffer
buffer.preresume()
domain_resume()

in remus_checkpoint_dm_saved()
foreach remus buffer
buffer.commit()

Lai, I can take an crack at it if you would like.

shriram

#59 lore raw

Re: [PATCH 6/7] remus: implement remus replicated checkpointing disk

Quoted 93 lines · Shriram Rajagopalan

tools/libxl/libxl_dom.c static int libxl__remus_domain_resume_callback(void *data) · line 1477

Quoted 12 lines
tools/libxl/libxl_dom.c +4 -1
@@ -1463,7 +1468,10 @@ static int libxl__remus_domain_resume_callback(void *data)
    if (libxl__domain_resume(gc, dss->domid, /* Fast Suspend */1))
        return 0;
 
-    /* REMUS TODO: Deal with disk. */
+    /* Deal with disk. */
+    if (libxl__remus_disk_preresume(dss->remus_state))
+        return 0;
+
    return 1;
 }
 

Bug. I think I mentioned this last time. Disk needs to be resumed before the domain is resumed. Just move the domain resume call below the above code snippet.

Quoted 28 lines
tools/libxl/libxl_remus_disk.h new file +28 -0
+typedef struct libxl__remus_disk_type {
+    /* checkpointing */
+    int (*postsuspend)(libxl__remus_disk *remus_disk);
+    int (*preresume)(libxl__remus_disk *remus_disk);
+    int (*commit)(libxl__remus_disk *remus_disk);
+
+    /*
+     * Return value:
+     *   1: the disk is not this type or the script is still running
+     *   0: the disk is this type
+     *  -1: error
+     */
+    int (*match)(libxl__domain_suspend_state *dss,
+                 const libxl_device_disk *disk,
+                 libxl_async_exec *async_exec,
+                 void *disk_state);
+
+    /*
+     * This is synchronous callback. Return value:
+     *  0: setup is done
+     * -1: error
+     *
+     */
+    int (*setup)(libxl__remus_disk *remus_disk);
+
+    /*
+     * Return value:
+     *   1: the script is still running

tools/libxl/libxl_remus_disk.h line 69

Quoted 10 lines
tools/libxl/libxl_remus_disk.h new file +10 -0
+     *   0: the script is done
+     *  -1: error
+     */
+    int (*teardown)(libxl__remus_disk *remus_disk,
+                    libxl_async_exec *async_exec);
+
+    /* the size of the private data */
+    int size;
+} libxl__remus_disk_type;
+

This vtable approach is neat. I am fine with the current disk checkpoint approach you have taken.

Something that might be worth thinking about:
The old remus code used this approach for both the disk and network buffering. Given that this code is going in a similar direction, I suggest hoisting this structure
up to an abstract buffer type, with setup, teardown, postsuspend, preresume and commit callbacks.

For disks, semantically,
setup [..]
teardown [..]
postsuspend [start flushing buffered writes to backup host] preresume [wait until all writes have been flushed to backup host] commit [no-op]

For network devices, semantically,
setup [..]
teardown [..]
postsuspend [no-op]
preresume [start_new_epoch - libnl call]
commit [release_prev_epoch - libnl call]

This way, in domain_suspend_done, the only thing we need to do is foreach remus buffer
buffer.postsuspend()

Similarly, in resume_callback()

foreach remus buffer
buffer.preresume()
domain_resume()

Quoted 6 lines

in remus_checkpoint_dm_saved()
foreach remus buffer
buffer.commit()

Lai, I can take an crack at it if you would like.

Your idea is great, I look forward to your work on it.

Quoted 6 lines

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
.

#60 lore raw

PATCH 7/7 drbd: implement replicated checkpointing disk

In reply to Lai Jiangshan
---
 tools/hotplug/Linux/Makefile         |    1 +
 tools/hotplug/Linux/block-drbd-probe |   56 ++++++++++++++
 tools/libxl/Makefile                 |    2 +-
 tools/libxl/libxl_remus_disk.c       |    1 +
 tools/libxl/libxl_remus_disk.h       |    2 +
 tools/libxl/libxl_remus_disk_drbd.c  |  132 ++++++++++++++++++++++++++++++++++
 6 files changed, 193 insertions(+), 1 deletions(-)
 create mode 100755 tools/hotplug/Linux/block-drbd-probe
 create mode 100644 tools/libxl/libxl_remus_disk_drbd.c
tools/hotplug/Linux/Makefile +1 -0
index 6139c1f..b830a8e 100644
@@ -24,6 +24,7 @@ XEN_SCRIPTS += xen-hotplug-cleanup
 XEN_SCRIPTS += external-device-migrate
 XEN_SCRIPTS += vscsi
 XEN_SCRIPTS += block-iscsi
+XEN_SCRIPTS += block-drbd-probe
 XEN_SCRIPTS += $(XEN_SCRIPTS-y)
 
 XEN_SCRIPT_DATA = xen-script-common.sh locking.sh logging.sh
tools/hotplug/Linux/block-drbd-probe new file +56 -0

56 lines not on this page · raw message

tools/libxl/Makefile +1 -1
index b040a79..658e1b1 100644
@@ -53,7 +53,7 @@ LIBXL_OBJS-y += libxl_nonetbuffer.o
 endif
 
 LIBXL_OBJS-y += libxl_remus.o
-LIBXL_OBJS-y += libxl_remus_disk.o
+LIBXL_OBJS-y += libxl_remus_disk.o libxl_remus_disk_drbd.o
 
 LIBXL_OBJS-$(CONFIG_X86) += libxl_cpuid.o libxl_x86.o
 LIBXL_OBJS-$(CONFIG_ARM) += libxl_nocpuid.o libxl_arm.o
tools/libxl/libxl_remus_disk.c +1 -0
index ca3e879..3af43e6 100644
@@ -33,6 +33,7 @@ typedef struct libxl__remus_disk_state {
 /*** checkpoint disks states and callbacks ***/
 static const libxl__remus_disk_type *remus_disk_types[] =
 {
+    &drbd_disk_type,
 };
 
 int libxl__remus_disk_postsuspend(libxl__remus_state *remus_state)
tools/libxl/libxl_remus_disk.h +2 -0
index 33b0e59..dfd2432 100644
@@ -71,4 +71,6 @@ typedef struct libxl__remus_disk_type {
 extern void disk_match_script_cb(void *disk_state, int status);
 extern void disk_teardown_script_cb(void *disk_state);
 
+extern const libxl__remus_disk_type drbd_disk_type;
+
 #endif
tools/libxl/libxl_remus_disk_drbd.c new file +132 -0

132 lines not on this page · raw message

Signature · 1 line
1.7.4.4
#61 lore raw

Re: [PATCH 7/7] drbd: implement replicated checkpointing disk

Quoted 48 lines · Lai Jiangshan

---

tools/hotplug/Linux/Makefile         |    1 +
tools/hotplug/Linux/block-drbd-probe |   56 ++++++++++++++
tools/libxl/Makefile                 |    2 +-
tools/libxl/libxl_remus_disk.c       |    1 +
tools/libxl/libxl_remus_disk.h       |    2 +
tools/libxl/libxl_remus_disk_drbd.c  |  132 ++++++++++++++++++++++++++++++++++
6 files changed, 193 insertions(+), 1 deletions(-)

create mode 100755 tools/hotplug/Linux/block-drbd-probe create mode 100644 tools/libxl/libxl_remus_disk_drbd.c

tools/hotplug/Linux/Makefile +0 -0
index 6139c1f..b830a8e 100644
@@ -24,6 +24,7 @@ XEN_SCRIPTS += xen-hotplug-cleanup

XEN_SCRIPTS += external-device-migrate
XEN_SCRIPTS += vscsi
XEN_SCRIPTS += block-iscsi
+XEN_SCRIPTS += block-drbd-probe
XEN_SCRIPTS += $(XEN_SCRIPTS-y)

XEN_SCRIPT_DATA = xen-script-common.sh locking.sh logging.sh

tools/hotplug/Linux/block-drbd-probe new file +14 -0
new file mode 100755
index 0000000..432f051
@@ -0,0 +1,56 @@
+#! /bin/bash
+#
+# Copyright (C) 2014 FUJITSU LIMITED
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of version 2.1 of the GNU Lesser General Public
+# License as published by the Free Software Foundation.
+#
+# This library 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.
+#
+# You should have received a copy of the GNU Lesser General Public

tools/hotplug/Linux/block-drbd-probe line 24

Quoted 10 lines
tools/hotplug/Linux/block-drbd-probe new file +10 -0
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+#
+# Usage:
+#     block-drbd-probe devicename
+#
+# Return value:
+#     0: the device is drbd device
+#     1: the device is not drbd device
+

I was under the impression xl had a separate type for drbd disks.
Anyway, since the disk type checking is done in an external script,
I suggest you also check for the protocol type (proto D) and drbd version (8.3.9 or 8.3.11 iirc). Otherwise, there is no point initiating drbd replication with Remus.
The old python code has this check, in case you need a reference implementation.

Quoted 209 lines
tools/hotplug/Linux/block-drbd-probe new file +32 -0
+function get_res_name()
+{
+    local drbd_dev=$1
+    local drbd_dev_list=($(drbdadm sh-dev all))
+    local drbd_res_list=($(drbdadm sh-resource all))
+    local temp_drbd_dev temp_drbd_res
+    local found=0
+
+    for temp_drbd_dev in ${drbd_dev_list[@]}; do
+        if [[ "$temp_drbd_dev" == "$drbd_dev" ]]; then
+            found=1
+            break
+        fi
+    done
+
+    if [[ $found -eq 0 ]]; then
+        return 1
+    fi
+
+    for temp_drbd_res in ${drbd_res_list[@]}; do
+        temp_drbd_dev=$(drbdadm sh-dev $temp_drbd_res)
+        if [[ "$temp_drbd_dev" == "$drbd_dev" ]]; then
+            return 0
+        fi
+    done
+
+    # OOPS
+    return 2
+}
+
+get_res_name $1
+exit $?
tools/libxl/Makefile +0 -0
index b040a79..658e1b1 100644
@@ -53,7 +53,7 @@ LIBXL_OBJS-y += libxl_nonetbuffer.o

endif

LIBXL_OBJS-y += libxl_remus.o

tools/libxl/Makefile +1 -1
-LIBXL_OBJS-y += libxl_remus_disk.o
+LIBXL_OBJS-y += libxl_remus_disk.o libxl_remus_disk_drbd.o

LIBXL_OBJS-$(CONFIG_X86) += libxl_cpuid.o libxl_x86.o LIBXL_OBJS-$(CONFIG_ARM) += libxl_nocpuid.o libxl_arm.o

tools/libxl/libxl_remus_disk.c +0 -0
index ca3e879..3af43e6 100644
@@ -33,6 +33,7 @@ typedef struct libxl__remus_disk_state {
 /*** checkpoint disks states and callbacks ***/

static const libxl__remus_disk_type *remus_disk_types[] = {
+ &drbd_disk_type,
};

int libxl__remus_disk_postsuspend(libxl__remus_state *remus_state)

tools/libxl/libxl_remus_disk.h +2 -0
index 33b0e59..dfd2432 100644
@@ -71,4 +71,6 @@ typedef struct libxl__remus_disk_type {
 extern void disk_match_script_cb(void *disk_state, int status);
 extern void disk_teardown_script_cb(void *disk_state);
 
+extern const libxl__remus_disk_type drbd_disk_type;
+
 #endif
tools/libxl/libxl_remus_disk_drbd.c new file +132 -0
new file mode 100644
index 0000000..719e950
@@ -0,0 +1,132 @@
+/*
+ * Copyright (C) 2014 FUJITSU LIMITED
+ * Author Lai Jiangshan <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; version 2.1 only. with the special
+ * exception on linking described in file LICENSE.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ */
+
+#include "libxl_osdeps.h" /* must come before any other headers */
+
+#include "libxl_internal.h"
+
+#include "libxl_remus_disk.h"
+
+/*** drbd implementation ***/
+const int DRBD_SEND_CHECKPOINT = 20;
+const int DRBD_WAIT_CHECKPOINT_ACK = 30;
+
+char *drbd_probe_script;
+
+typedef struct libxl__remus_drbd_disk
+{
+    int ctl_fd;
+    int ackwait;
+    const char *path;
+} libxl__remus_drbd_disk;
+
+static int drbd_postsuspend(libxl__remus_disk *remus_disk)
+{
+    struct libxl__remus_drbd_disk *drbd = remus_disk->opaque;
+
+    if (!drbd->ackwait) {
+        if (ioctl(drbd->ctl_fd, DRBD_SEND_CHECKPOINT, 0) <= 0)
+            drbd->ackwait = 1;
+    }
+
+    return 0;
+}
+
+static int drbd_preresume(libxl__remus_disk *remus_disk)
+{
+    struct libxl__remus_drbd_disk *drbd = remus_disk->opaque;
+
+    if (drbd->ackwait) {
+        ioctl(drbd->ctl_fd, DRBD_WAIT_CHECKPOINT_ACK, 0);
+        drbd->ackwait = 0;
+    }
+
+    return 0;
+}
+
+static int drbd_commit(libxl__remus_disk *remus_disk)
+{
+    /* nothing to do, all work are done by DRBD's protocal-D. */
+    return 0;
+}
+
+static int drbd_match(libxl__domain_suspend_state *dss,
+                      const libxl_device_disk *disk,
+                      libxl_async_exec *async_exec,
+                      void *disk_state)
+{
+    int arraysize, nr = 0;
+    STATE_AO_GC(dss->ao);
+
+    if (!drbd_probe_script)
+        drbd_probe_script = GCSPRINTF("%s/block-drbd-probe",
+                                      libxl__xen_script_dir_path());
+
+    /* setup env & args */
+    arraysize = 1;
+    GCNEW_ARRAY(async_exec->env, arraysize);
+    async_exec->env[nr++] = NULL;
+    assert(nr <= arraysize);
+
+    arraysize = 3;
+    nr = 0;
+    GCNEW_ARRAY(async_exec->args, arraysize);
+    async_exec->args[nr++] = drbd_probe_script;
+    async_exec->args[nr++] = disk->pdev_path;
+    async_exec->args[nr++] = NULL;
+    assert(nr <= arraysize);
+
+    async_exec->finish_cb = disk_match_script_cb;
+    async_exec->opaque = disk_state;
+    async_exec->allow_fail = true;
+    async_exec->timeout = LIBXL_HOTPLUG_TIMEOUT;
+
+    if (libxl_async_exec_script(gc, async_exec))
+        return ERROR_FAIL;
+
+    return 1;
+}
+
+static int drbd_setup(libxl__remus_disk *remus_disk)
+{
+    libxl__remus_drbd_disk *drbd = remus_disk->opaque;
+
+    drbd->path = remus_disk->disk->pdev_path;
+    drbd->ctl_fd = open(drbd->path, O_RDONLY);
+    drbd->ackwait = 0;
+
+    if (drbd->ctl_fd < 0)
+        return ERROR_INVAL;
+
+    return 0;
+}
+
+static int drbd_teardown(libxl__remus_disk *remus_disk, libxl_async_exec *async_exec)
+{
+    struct libxl__remus_drbd_disk *drbd = remus_disk->opaque;
+
+    close(drbd->ctl_fd);
+    return 0;
+}
+
+const libxl__remus_disk_type drbd_disk_type = {
+    .postsuspend = drbd_postsuspend,
+    .preresume = drbd_preresume,
+    .commit = drbd_commit,
+    .match = drbd_match,
+    .setup = drbd_setup,
+    .teardown = drbd_teardown,
+    .size = sizeof(libxl__remus_drbd_disk),
+};
Signature · 1 line
1.7.4.4
#62 lore raw

Re: [PATCH 1/7] introduce a new function libxl__remus_netbuf_setup_done()

In reply to Lai Jiangshan

Lai Jiangshan writes ("[PATCH 1/7] introduce a new function libxl__remus_netbuf_setup_done()"):

Quoted 2 lines

We will exec some scripts to setup netbuf and disk, so we need two asynchronous functions that are called when the setup is done.

Is there a 0/7 for this series somewhere ? I don't seem to have a copy of it.

Is this series complementary to Yang Hongyang's or does it want to go on top of it, or what ?

Thanks,
Ian.

#63 lore raw

Re: [PATCH 1/7] introduce a new function libxl__remus_netbuf_setup_done()

Quoted 8 lines · Ian Jackson

Lai Jiangshan writes ("[PATCH 1/7] introduce a new function libxl__remus_netbuf_setup_done()"):

Quoted 2 lines

We will exec some scripts to setup netbuf and disk, so we need two asynchronous functions that are called when the setup is done.

Is there a 0/7 for this series somewhere ? I don't seem to have a copy of it.

Is this series complementary to Yang Hongyang's or does it want to go on top of it, or what ?

Hi, Ian, It's based on the remus net patchset I've send.

Thanks

Quoted 5 lines

Thanks,
Ian.
.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#64 lore raw

v9 cover Remus/Libxl: Network buffering support

This patch series adds support for network buffering in the Remus codebase in libxl.

Changes in V9:
introduce an API to async exec scripts for both device and netbuffer.
Use async exec script api to exec scripts.

Changes in V8:
Applied some comments(by IanJ).
Merge some struct definitions to it's implementation. (2/3/5 in V7 => 3 in V8)

Changes in V7:
Applied missing comments(by IanJ).
Applied Shriram comments.

merge netbufering tangled setup/teardown code into one patch. (2/6/8 in V6 => 5 in V7. 9/10 in V6 => 7 in V7)

Changes in V6:
Applied Ian Jackson's comments of V5 series. the [PATCH 2/4 V5] is split by small functionalities.

[PATCH 4/4 V5] --> [PATCH 13/13] netbuffer is default enabled.

Changes in V5:

Merge hotplug script patch (2/5) and hotplug script setup/teardown patch (3/5) into a single patch.

Changes in V4:

[1/5] Remove check for libnl command line utils in autoconf checks

[2/5] minor nits

[3/5] define LIBXL_HAVE_REMUS_NETBUF in libxl.h

[4/5] clean ups. Make the usleep in checkpoint callback asynchronous

[5/5] minor nits

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(by shriram):

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 Rajagopalan (7):
remus: add libnl3 dependency to autoconf scripts
remus: introduce a function to check whether network buffering is
enabled
remus: Remus network buffering core and APIs to setup/teardown
remus: implement the API to buffer/release packages
libxl: rename remus_failover_cb() to remus_replication_failure_cb()
libxl: control network buffering in remus callbacks
libxl: network buffering cmdline switch

Yang Hongyang (5):
introduce an API to async exec scripts
libxl_device: use async exec script api
remus: remus device core and APIs to setup/teardown
remus: implement the API for checkpoint
libxl: use the API to setup/teardown network buffering

 README                                 |   4 +
 config/Tools.mk.in                     |   3 +
 docs/man/xl.conf.pod.5                 |   6 +
 docs/man/xl.pod.1                      |  11 +-
 docs/misc/xenstore-paths.markdown      |   4 +
 tools/configure.ac                     |  15 +
 tools/hotplug/Linux/Makefile           |   1 +
 tools/hotplug/Linux/remus-netbuf-setup | 183 ++++++++++++
 tools/libxl/Makefile                   |  11 +
 tools/libxl/libxl.c                    |  42 ++-
 tools/libxl/libxl.h                    |  13 +
 tools/libxl/libxl_device.c             |  80 ++----
 tools/libxl/libxl_dom.c                |  83 +++++-
 tools/libxl/libxl_internal.c           |  82 ++++++
 tools/libxl/libxl_internal.h           |  70 ++++-
 tools/libxl/libxl_netbuffer.c          | 491 +++++++++++++++++++++++++++++++++
 tools/libxl/libxl_nonetbuffer.c        |  54 ++++
 tools/libxl/libxl_remus.c              |  57 ++++
 tools/libxl/libxl_remus_device.c       | 383 +++++++++++++++++++++++++
 tools/libxl/libxl_remus_device.h       |  99 +++++++
 tools/libxl/libxl_types.idl            |   2 +
 tools/libxl/xl.c                       |   4 +
 tools/libxl/xl.h                       |   1 +
 tools/libxl/xl_cmdimpl.c               |  28 +-
 tools/libxl/xl_cmdtable.c              |   3 +
 tools/remus/README                     |   6 +
 26 files changed, 1650 insertions(+), 86 deletions(-)
 create mode 100644 tools/hotplug/Linux/remus-netbuf-setup
 create mode 100644 tools/libxl/libxl_netbuffer.c
 create mode 100644 tools/libxl/libxl_nonetbuffer.c
 create mode 100644 tools/libxl/libxl_remus.c
 create mode 100644 tools/libxl/libxl_remus_device.c
 create mode 100644 tools/libxl/libxl_remus_device.h
Signature · 1 line
1.8.3.2
#65 lore raw

PATCH v9 1/12 introduce an API to async exec scripts

introduce an API to async exec scripts.it will be used for both device and netbuffer.

---
 tools/libxl/libxl_internal.c | 82 ++++++++++++++++++++++++++++++++++++++++++++
 tools/libxl/libxl_internal.h | 21 ++++++++++++
 2 files changed, 103 insertions(+)
tools/libxl/libxl_internal.c +82 -0
index 6c94d3e..e47eb90 100644
@@ -375,6 +375,88 @@ out:
     return rc;
 }
 
+static void libxl_async_exec_timeout(libxl__egc *egc,
+                                     libxl__ev_time *ev,
+                                     const struct timeval *requested_abs)
+{
+    libxl_async_exec *async_exec = CONTAINER_OF(ev, *async_exec, time);
+
+    STATE_AO_GC(async_exec->ao);
+
+    libxl__ev_time_deregister(gc, &async_exec->time);
+    assert(libxl__ev_child_inuse(&async_exec->child));
+
+    LOG(DEBUG, "killing hotplug script %s because of timeout",
+        async_exec->args[0]);
+
+    if (kill(async_exec->child.pid, SIGKILL)) {
+        LOGEV(ERROR, errno, "unable to kill hotplug script %s [%ld]",
+              async_exec->args[0],
+              (unsigned long)async_exec->child.pid);
+    }
+
+    return;
+}
+
+static void libxl_async_exec_done(libxl__egc *egc,
+                                  libxl__ev_child *child,
+                                  pid_t pid, int status)
+{
+    libxl_async_exec *async_exec = CONTAINER_OF(child, *async_exec, child);
+
+    STATE_AO_GC(async_exec->ao);
+
+    libxl__ev_time_deregister(gc, &async_exec->time);
+
+    if (status && !async_exec->allow_fail) {
+        libxl_report_child_exitstatus(CTX, LIBXL__LOG_ERROR,
+                                      async_exec->args[0],
+                                      pid, status);
+    }
+
+    async_exec->finish_cb(async_exec->opaque, status);
+}
+
+int libxl_async_exec_script(libxl__gc *gc, libxl_async_exec *async_exec)
+{
+    pid_t pid;
+
+    /* Convenience aliases */
+    libxl__ev_child *const child = &async_exec->child;
+    char * const *args = async_exec->args;
+    char * const *env = async_exec->env;
+    const int stdinfd = async_exec->stdinfd;
+    const int stdoutfd = async_exec->stdoutfd;
+    const int stderrfd = async_exec->stderrfd;
+
+    /* Set hotplug timeout */
+    if (libxl__ev_time_register_rel(gc, &async_exec->time,
+                                    libxl_async_exec_timeout,
+                                    async_exec->timeout * 1000)) {
+        LOG(ERROR, "unable to register timeout for "
+            "script %s", args[0]);
+        return ERROR_FAIL;
+    }
+
+    LOG(DEBUG, "Calling script: %s ", args[0]);
+
+    /* Fork and exec netbuf script */
+    pid = libxl__ev_child_fork(gc, child, libxl_async_exec_done);
+    if (pid == -1) {
+        LOG(ERROR, "unable to fork for script %s", args[0]);
+        return ERROR_FAIL;
+    }
+
+    if (!pid) {
+        /* child: Launch netbuf script */
+        libxl__exec(gc, stdinfd, stdoutfd, stderrfd, args[0], args, env);
+        /* notreached */
+        abort();
+    }
+
+    return 0;
+}
+
 /*
  * Local variables:
  * mode: C
tools/libxl/libxl_internal.h +21 -0
index c2b73c4..eddafaf 100644
@@ -2030,6 +2030,27 @@ _hidden const char *libxl__xen_script_dir_path(void);
 _hidden const char *libxl__lock_dir_path(void);
 _hidden const char *libxl__run_dir_path(void);
 
+/*----- asynchronous function -----*/
+typedef struct libxl_async_exec {
+    char **env;
+    char **args;
+    void *opaque;
+    void (*finish_cb)(void *opaque, int status);
+    /* unit: second */
+    int timeout;
+    bool allow_fail;
+    int stdinfd;
+    int stdoutfd;
+    int stderrfd;
+
+    libxl__ev_time time;
+    libxl__ev_child child;
+    libxl__ao *ao;
+} libxl_async_exec;
+
+_hidden extern int libxl_async_exec_script(libxl__gc *gc,
+                                           libxl_async_exec *async_exec);
+
 /*----- device addition/removal -----*/
 
 typedef struct libxl__ao_device libxl__ao_device;
Signature · 1 line
1.8.3.2
#66 lore raw

Re: [PATCH V9 01/12] introduce an API to async exec scripts

Yang Hongyang writes ("[PATCH V9 01/12] introduce an API to async exec scripts"):

Quoted 2 lines

introduce an API to async exec scripts.it will be used for both device and netbuffer.

Thanks. This mostly looks plausible.

I think it would be better to combine it with the next patch. That way we just move/reorganise the code, rather than making a copy and deleting the old approach.

I have some comments about details.

tools/libxl/libxl_internal.h _hidden const char *libxl__xen_script_dir_path(void); · line 2034

Quoted 10 lines
tools/libxl/libxl_internal.h +2 -0
index c2b73c4..eddafaf 100644
@@ -2030,6 +2030,27 @@ _hidden const char *libxl__xen_script_dir_path(void);
 _hidden const char *libxl__lock_dir_path(void);
 _hidden const char *libxl__run_dir_path(void);
 
+/*----- asynchronous function -----*/
+typedef struct libxl_async_exec {

We would normally call structs of this kind "libxl__something_state". So this should be called "libxl__async_exec_state".

Your struct needs to have comments explaining which parts are to be filled in by the caller, and which parts are private. See libxl__xswait_state for an example.

...

tools/libxl/libxl_internal.h _hidden const char *libxl__xen_script_dir_path(void); · line 2037

Quoted 1 line
tools/libxl/libxl_internal.h +1 -0
+    void *opaque;

You shouldn't need this field. Callers should be able to use CONTAINER_OF to find their own state structure.

tools/libxl/libxl_internal.h _hidden const char *libxl__xen_script_dir_path(void); · line 2038

Quoted 1 line
tools/libxl/libxl_internal.h +1 -0
+    void (*finish_cb)(void *opaque, int status);

Most of these kinds of setups simply name the field "callback".

tools/libxl/libxl_internal.h _hidden const char *libxl__xen_script_dir_path(void); · line 2040

Quoted 2 lines
tools/libxl/libxl_internal.h +2 -0
+    /* unit: second */
+    int timeout;

The comment would be better on the same line. However, in fact it is better to express the units in the variable name.

And the timeout should be in milliseconds - all the timeouts in our internal APIs are in ms.

So, "timeout_ms".

tools/libxl/libxl_internal.h _hidden const char *libxl__xen_script_dir_path(void); · line 2041

Quoted 1 line
tools/libxl/libxl_internal.h +1 -0
+    bool allow_fail;

None of your callers set this to "true". And in fact its function is only to inhibit a log message - it makes no difference to the control flow. Can it be abolished ?

tools/libxl/libxl_internal.h _hidden const char *libxl__xen_script_dir_path(void); · line 2044

Quoted 3 lines
tools/libxl/libxl_internal.h +3 -0
+    int stdinfd;
+    int stdoutfd;
+    int stderrfd;

It would probably be better to make this an array, rather than 3 named fields. That will make it easier in the future to deal with them all at once.

tools/libxl/libxl_internal.h _hidden const char *libxl__xen_script_dir_path(void); · line 2048

Quoted 1 line
tools/libxl/libxl_internal.h +1 -0
+    libxl__ao *ao;

This field should be at the top, the way that libxl__xswait_state has it.

tools/libxl/libxl_internal.h _hidden const char *libxl__xen_script_dir_path(void); · line 2052

Quoted 4 lines
tools/libxl/libxl_internal.h +4 -0
+} libxl_async_exec;
+
+_hidden extern int libxl_async_exec_script(libxl__gc *gc,
+                                           libxl_async_exec *async_exec);

This function needs to be called "libxl__async_exec_start" or maybe just "libxl__async_exec". It doesn't seem to be limited to scripts.

It should be in libxl_exec.c, probably, or libxl_aoutils.c.

tools/libxl/libxl_internal.h _hidden const char *libxl__xen_script_dir_path(void); · line 2052

Quoted 5 lines
tools/libxl/libxl_internal.h +5 -0
+static void libxl_async_exec_timeout(libxl__egc *egc,
+                                     libxl__ev_time *ev,
+                                     const struct timeval *requested_abs)
+{
+    libxl_async_exec *async_exec = CONTAINER_OF(ev, *async_exec, time);

We normally give these local state variables very short names, because we need to refer to them a lot. If the type is changed to libxl__async_exec_state, the local variable should be "aes".

tools/libxl/libxl_internal.h _hidden const char *libxl__xen_script_dir_path(void);

Quoted 6 lines
tools/libxl/libxl_internal.h +6 -0
+    STATE_AO_GC(async_exec->ao);
+
+    libxl__ev_time_deregister(gc, &async_exec->time);
+    assert(libxl__ev_child_inuse(&async_exec->child));
+
+    LOG(DEBUG, "killing hotplug script %s because of timeout",

You have changed the formatting here, as you move the code. I think the previous location of the blank line is better.

Quoted 1 line

+ async_exec->args[0]);

This still says "hotplug script" (in several places). You probably need to add a new field to the libxl_async_exec. We generally seem to use the name "what" for this - cf libxl__xswait_state.

tools/libxl/libxl_internal.h

Quoted 3 lines
tools/libxl/libxl_internal.h +3 -0
+static void libxl_async_exec_done(libxl__egc *egc,
+                                  libxl__ev_child *child,
+                                  pid_t pid, int status)

This function can be called "async_exec_done" (because it has only internal linkage). If you prefix it with libxl, it needs to be libxl__.

tools/libxl/libxl_internal.h

Quoted 3 lines
tools/libxl/libxl_internal.h +3 -0
+    if (status && !async_exec->allow_fail) {
+        libxl_report_child_exitstatus(CTX, LIBXL__LOG_ERROR,
+                                      async_exec->args[0],

It's probably better to use the new "what" value rather args[0].

tools/libxl/libxl_internal.h

Quoted 8 lines
tools/libxl/libxl_internal.h +8 -0
+int libxl_async_exec_script(libxl__gc *gc, libxl_async_exec *async_exec)
+{
+    pid_t pid;
+
+    /* Convenience aliases */
+    libxl__ev_child *const child = &async_exec->child;
+    char * const *args = async_exec->args;
+    char * const *env = async_exec->env;

Your constness doesn't seem correct here. In the struct these parameters are char**. And your use of whitespace is anomalouse. I think you want

       char **const args = aes->args;

tools/libxl/libxl_internal.h

Quoted 3 lines
tools/libxl/libxl_internal.h +3 -0
+    const int stdinfd = async_exec->stdinfd;
+    const int stdoutfd = async_exec->stdoutfd;
+    const int stderrfd = async_exec->stderrfd;

These don't buy you anything - you only use each of these once.

Quoted 1 line

+ /* Set hotplug timeout */

The word "hotplug" again.

tools/libxl/libxl_internal.h

Quoted 10 lines
tools/libxl/libxl_internal.h +10 -0
+    if (libxl__ev_time_register_rel(gc, &async_exec->time,
+                                    libxl_async_exec_timeout,
+                                    async_exec->timeout * 1000)) {
+        LOG(ERROR, "unable to register timeout for "
+            "script %s", args[0]);
+        return ERROR_FAIL;
+    }
+
+    LOG(DEBUG, "Calling script: %s ", args[0]);
+    /* Fork and exec netbuf script */

The assumption of "script" again. And a specialised comment. Can you make sure all of these messages use "what" as appropriate and that messages and comments are fully general ?

Thanks,
Ian.

#67 lore raw

PATCH v9 2/12 libxl_device: use async exec script api

In reply to Yang Hongyang

use async exec script api to exec device related scripts.

---
 tools/libxl/libxl_device.c   | 80 ++++++++++++--------------------------------
 tools/libxl/libxl_internal.h |  4 ++-
 2 files changed, 25 insertions(+), 59 deletions(-)
tools/libxl/libxl_device.c +22 -58
index fa99f77..2e26799 100644
@@ -440,7 +440,7 @@ void libxl__prepare_ao_device(libxl__ao *ao, libxl__ao_device *aodev)
     aodev->active = 1;
     /* We init this here because we might call device_hotplug_done
      * without actually calling any hotplug script */
-    libxl__ev_child_init(&aodev->child);
+    libxl__ev_child_init(&aodev->async_exec.child);
 }
 
 /* multidev */
@@ -707,12 +707,7 @@ static void device_backend_cleanup(libxl__gc *gc,
 
 static void device_hotplug(libxl__egc *egc, libxl__ao_device *aodev);
 
-static void device_hotplug_timeout_cb(libxl__egc *egc, libxl__ev_time *ev,
-                                      const struct timeval *requested_abs);
-
-static void device_hotplug_child_death_cb(libxl__egc *egc,
-                                          libxl__ev_child *child,
-                                          pid_t pid, int status);
+static void device_hotplug_child_death_cb(void *opaque, int status);
 
 static void device_destroy_be_timeout_cb(libxl__egc *egc, libxl__ev_time *ev,
                                          const struct timeval *requested_abs);
@@ -957,7 +952,6 @@ static void device_hotplug(libxl__egc *egc, libxl__ao_device *aodev)
     char **args = NULL, **env = NULL;
     int rc = 0;
     int hotplug, nullfd = -1;
-    pid_t pid;
     uint32_t domid;
 
     /*
@@ -1009,15 +1003,6 @@ static void device_hotplug(libxl__egc *egc, libxl__ao_device *aodev)
         goto out;
     }
 
-    /* Set hotplug timeout */
-    rc = libxl__ev_time_register_rel(gc, &aodev->timeout,
-                                     device_hotplug_timeout_cb,
-                                     LIBXL_HOTPLUG_TIMEOUT * 1000);
-    if (rc) {
-        LOG(ERROR, "unable to register timeout for hotplug device %s", be_path);
-        goto out;
-    }
-
     aodev->what = GCSPRINTF("%s %s", args[0], args[1]);
     LOG(DEBUG, "calling hotplug script: %s %s", args[0], args[1]);
 
@@ -1028,23 +1013,24 @@ static void device_hotplug(libxl__egc *egc, libxl__ao_device *aodev)
         goto out;
     }
 
-    /* fork and execute hotplug script */
-    pid = libxl__ev_child_fork(gc, &aodev->child, device_hotplug_child_death_cb);
-    if (pid == -1) {
-        LOG(ERROR, "unable to fork");
-        rc = ERROR_FAIL;
+    aodev->egc = egc;
+    aodev->async_exec.env = env;
+    aodev->async_exec.args = args;
+    aodev->async_exec.opaque = aodev;
+    aodev->async_exec.finish_cb = device_hotplug_child_death_cb;
+    aodev->async_exec.timeout = LIBXL_HOTPLUG_TIMEOUT;
+    aodev->async_exec.allow_fail = false;
+    aodev->async_exec.stdinfd = nullfd;
+    aodev->async_exec.stdoutfd = 2;
+    aodev->async_exec.stderrfd = -1;
+    aodev->async_exec.ao = ao;
+
+    rc = libxl_async_exec_script(gc, &aodev->async_exec);
+    if (rc)
         goto out;
-    }
-
-    if (!pid) {
-        /* child */
-        libxl__exec(gc, nullfd, 2, -1, args[0], args, env);
-        /* notreached */
-        abort();
-    }
 
     close(nullfd);
-    assert(libxl__ev_child_inuse(&aodev->child));
+    assert(libxl__ev_child_inuse(&aodev->async_exec.child));
 
     return;
 
@@ -1055,29 +1041,9 @@ out:
     return;
 }
 
-static void device_hotplug_timeout_cb(libxl__egc *egc, libxl__ev_time *ev,
-                                      const struct timeval *requested_abs)
-{
-    libxl__ao_device *aodev = CONTAINER_OF(ev, *aodev, timeout);
-    STATE_AO_GC(aodev->ao);
-
-    libxl__ev_time_deregister(gc, &aodev->timeout);
-
-    assert(libxl__ev_child_inuse(&aodev->child));
-    LOG(DEBUG, "killing hotplug script %s because of timeout", aodev->what);
-    if (kill(aodev->child.pid, SIGKILL)) {
-        LOGEV(ERROR, errno, "unable to kill hotplug script %s [%ld]",
-                            aodev->what, (unsigned long)aodev->child.pid);
-    }
-
-    return;
-}
-
-static void device_hotplug_child_death_cb(libxl__egc *egc,
-                                          libxl__ev_child *child,
-                                          pid_t pid, int status)
+static void device_hotplug_child_death_cb(void *opaque, int status)
 {
-    libxl__ao_device *aodev = CONTAINER_OF(child, *aodev, child);
+    libxl__ao_device *aodev = opaque;
     STATE_AO_GC(aodev->ao);
     char *be_path = libxl__device_backend_path(gc, aodev->dev);
     char *hotplug_error;
@@ -1085,8 +1051,6 @@ static void device_hotplug_child_death_cb(libxl__egc *egc,
     device_hotplug_clean(gc, aodev);
 
     if (status) {
-        libxl_report_child_exitstatus(CTX, LIBXL__LOG_ERROR,
-                                      aodev->what, pid, status);
         hotplug_error = libxl__xs_read(gc, XBT_NULL,
                                        GCSPRINTF("%s/hotplug-error", be_path));
         if (hotplug_error)
@@ -1105,13 +1069,13 @@ static void device_hotplug_child_death_cb(libxl__egc *egc,
      * device_hotplug_done breaking the loop.
      */
     aodev->num_exec++;
-    device_hotplug(egc, aodev);
+    device_hotplug(aodev->egc, aodev);
 
     return;
 
 error:
     assert(aodev->rc);
-    device_hotplug_done(egc, aodev);
+    device_hotplug_done(aodev->egc, aodev);
 }
 
 static void device_destroy_be_timeout_cb(libxl__egc *egc, libxl__ev_time *ev,
@@ -1178,7 +1142,7 @@ static void device_hotplug_clean(libxl__gc *gc, libxl__ao_device *aodev)
     /* Clean events and check reentrancy */
     libxl__ev_time_deregister(gc, &aodev->timeout);
     libxl__ev_xswatch_deregister(gc, &aodev->xs_watch);
-    assert(!libxl__ev_child_inuse(&aodev->child));
+    assert(!libxl__ev_child_inuse(&aodev->async_exec.child));
 }
 
 static void devices_remove_callback(libxl__egc *egc,
tools/libxl/libxl_internal.h +3 -1
index eddafaf..cc8d558 100644
@@ -2094,7 +2094,9 @@ struct libxl__ao_device {
     /* device hotplug execution */
     const char *what;
     int num_exec;
-    libxl__ev_child child;
+
+    libxl__egc *egc;
+    libxl_async_exec async_exec;
 };
 
 /*
Signature · 1 line
1.8.3.2
#68 lore raw

Re: [PATCH V9 02/12] libxl_device: use async exec script api

Yang Hongyang writes ("[PATCH V9 02/12] libxl_device: use async exec script api"):

Quoted 1 line

use async exec script api to exec device related scripts.

Thanks. Most of this is the other half of the code motion from the previous patch.

tools/libxl/libxl_device.c void libxl__prepare_ao_device(libxl__ao *ao, libxl__ao_device *aodev) · line 443

Quoted 2 lines
tools/libxl/libxl_device.c +1 -1
-    libxl__ev_child_init(&aodev->child);
+    libxl__ev_child_init(&aodev->async_exec.child);

You need an init function, to avoid a layering violation. The child field should be accessed only from the async exec implementation.

tools/libxl/libxl_device.c static void device_hotplug(libxl__egc *egc, libxl__ao_device *aodev) · line 1033

Quoted 2 lines
tools/libxl/libxl_device.c +1 -1
-    assert(libxl__ev_child_inuse(&aodev->child));
+    assert(libxl__ev_child_inuse(&aodev->async_exec.child));

Likewise, you need an inuse function.

tools/libxl/libxl_internal.h struct libxl__ao_device { · line 2099

Quoted 12 lines
tools/libxl/libxl_internal.h +3 -1
index eddafaf..cc8d558 100644
@@ -2094,7 +2094,9 @@ struct libxl__ao_device {
     /* device hotplug execution */
     const char *what;
     int num_exec;
-    libxl__ev_child child;
+
+    libxl__egc *egc;
+    libxl_async_exec async_exec;

I think this struct field name could profitably be shortened. Perhaps "exec" is too likely to clash but "aexec" would be OK.

Thanks,
Ian.

#69 lore raw

PATCH v9 3/12 remus: add libnl3 dependency to autoconf scripts

In reply to Yang Hongyang

From: Shriram Rajagopalan <[email protected]>

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 ++++
 config/Tools.mk.in   |  3 +++
 tools/configure.ac   | 15 +++++++++++++++
 tools/libxl/Makefile |  2 ++
 tools/remus/README   |  6 ++++++
 5 files changed, 30 insertions(+)
README +4 -0
index 9bbe734..e770932 100644
@@ -72,6 +72,10 @@ disabled at compile time:
     * cmake (if building vtpm stub domains)
     * markdown
     * figlet (for generating the traditional Xen start of day banner)
+    * 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
index 0bdf37a..e8957b6 100644
@@ -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
@@ -54,6 +56,7 @@ CONFIG_SEABIOS      := @seabios@
 CONFIG_QEMU_TRAD    := @qemu_traditional@
 CONFIG_QEMU_XEN     := @qemu_xen@
 CONFIG_BLKTAP1      := @blktap1@
+CONFIG_REMUS_NETBUF := @remus_netbuf@
 
 #System options
 ZLIB                := @zlib@
tools/configure.ac +15 -0
index 00fb47b..7f4e377 100644
@@ -237,5 +237,20 @@ esac
 # 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()
 
tools/libxl/Makefile +2 -0
index 755b666..3647a2a 100644
@@ -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
 
 LIBXL_LIBS-$(CONFIG_ARM) += -lfdt
tools/remus/README +6 -0
index 9e8140b..4736252 100644
@@ -2,3 +2,9 @@ Remus provides fault tolerance for virtual machines by sending continuous
 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/
Signature · 1 line
1.8.3.2
#70 lore raw

PATCH v9 4/12 remus: introduce a function to check whether network buffering is enabled

In reply to Yang Hongyang

From: Shriram Rajagopalan <[email protected]>

libxl__netbuffer_enabled() returns 1 when network buffering is compiled, or returns 0 when network buffering is not compiled.

If network buffering is not compiled, and the user wants to use it, report a error and exit.

---
 tools/libxl/Makefile            |  7 +++++++
 tools/libxl/libxl_internal.h    |  2 ++
 tools/libxl/libxl_netbuffer.c   | 31 +++++++++++++++++++++++++++++++
 tools/libxl/libxl_nonetbuffer.c | 31 +++++++++++++++++++++++++++++++
 4 files changed, 71 insertions(+)
 create mode 100644 tools/libxl/libxl_netbuffer.c
 create mode 100644 tools/libxl/libxl_nonetbuffer.c
tools/libxl/Makefile +7 -0
index 3647a2a..a29c505 100644
@@ -45,6 +45,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_ARM) += libxl_nocpuid.o libxl_arm.o
 
tools/libxl/libxl_internal.h +2 -0
index cc8d558..33b62a2 100644
@@ -2457,6 +2457,8 @@ typedef struct libxl__logdirty_switch {
     libxl__ev_time timeout;
 } libxl__logdirty_switch;
 
+_hidden int libxl__netbuffer_enabled(libxl__gc *gc);
+
 struct libxl__domain_suspend_state {
     /* set by caller of libxl__domain_suspend */
     libxl__ao *ao;
tools/libxl/libxl_netbuffer.c new file +31 -0
new file mode 100644
index 0000000..8e23d75
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2013
+ * Author Shriram Rajagopalan <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; version 2.1 only. with the special
+ * exception on linking described in file LICENSE.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ */
+
+#include "libxl_osdeps.h" /* must come before any other headers */
+
+#include "libxl_internal.h"
+
+int libxl__netbuffer_enabled(libxl__gc *gc)
+{
+    return 1;
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
tools/libxl/libxl_nonetbuffer.c new file +31 -0
new file mode 100644
index 0000000..6aa4bf1
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2013
+ * Author Shriram Rajagopalan <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; version 2.1 only. with the special
+ * exception on linking described in file LICENSE.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ */
+
+#include "libxl_osdeps.h" /* must come before any other headers */
+
+#include "libxl_internal.h"
+
+int libxl__netbuffer_enabled(libxl__gc *gc)
+{
+    return 0;
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
Signature · 1 line
1.8.3.2
#71 lore raw

Re: [PATCH V9 04/12] remus: introduce a function to check whether network buffering is enabled

Yang Hongyang writes ("[PATCH V9 04/12] remus: introduce a function to check whether network buffering is enabled"):

Quoted 5 lines

libxl__netbuffer_enabled() returns 1 when network buffering is compiled, or returns 0 when network buffering is not compiled.

If network buffering is not compiled, and the user wants to use it, report a error and exit.

...

tools/libxl/Makefile LIBXL_OBJS-y += libxl_blktap2.o · line 53

Quoted 5 lines
tools/libxl/Makefile +5 -0
+ifeq ($(CONFIG_REMUS_NETBUF),y)
+LIBXL_OBJS-y += libxl_netbuffer.o
+else
+LIBXL_OBJS-y += libxl_nonetbuffer.o
+endif

Thanks. But I think this needs to be set somewhere ?

Ian.

#72 lore raw

Re: [PATCH V9 04/12] remus: introduce a function to check whether network buffering is enabled

Quoted 17 lines · Ian Jackson

Yang Hongyang writes ("[PATCH V9 04/12] remus: introduce a function to check whether network buffering is enabled"):

Quoted 4 lines

libxl__netbuffer_enabled() returns 1 when network buffering is compiled, or returns 0 when network buffering is not compiled.

If network buffering is not compiled, and the user wants to use it,

report

Quoted 1 line

a error and exit.

...

tools/libxl/Makefile LIBXL_OBJS-y += libxl_blktap2.o · line 53

Quoted 5 lines
tools/libxl/Makefile +5 -0
+ifeq ($(CONFIG_REMUS_NETBUF),y)
+LIBXL_OBJS-y += libxl_netbuffer.o
+else
+LIBXL_OBJS-y += libxl_nonetbuffer.o
+endif

Thanks. But I think this needs to be set somewhere ?

Quoted 3 lines

Ian.

Its already done at the autoconf level.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#73 lore raw

Re: [PATCH V9 04/12] remus: introduce a function to check whether network buffering is enabled

Shriram Rajagopalan writes ("Re: [PATCH V9 04/12] remus: introduce a function to check whether network buffering is enabled"):

Quoted 19 lines

On Wed, Apr 23, 2014 at 10:50 AM, Ian Jackson <[email protected]> wrote:

Yang Hongyang writes ("[PATCH V9 04/12] remus: introduce a function to check whether network buffering is enabled"):
> libxl__netbuffer_enabled() returns 1 when network buffering is compiled, > or returns 0 when network buffering is not compiled.
>
> If network buffering is not compiled, and the user wants to use it, report
> a error and exit.
...
> +ifeq ($(CONFIG_REMUS_NETBUF),y)
> +LIBXL_OBJS-y += libxl_netbuffer.o
> +else
> +LIBXL_OBJS-y += libxl_nonetbuffer.o
> +endif

Thanks. But I think this needs to be set somewhere ?

...

Quoted 1 line

Its already done at the autoconf level.

In another patch ? I think this is another example of a case where the series needs restructuring. Semantically related pieces should be together so that reviewing an individual patch makes sense.

Ian.

#74 lore raw

PATCH v9 5/12 remus: remus device core and APIs to setup/teardown

In reply to Yang Hongyang
---
 tools/libxl/Makefile             |   2 +
 tools/libxl/libxl.c              |   7 +-
 tools/libxl/libxl_dom.c          |   4 +-
 tools/libxl/libxl_internal.h     |  28 ++++
 tools/libxl/libxl_remus.c        |  41 ++++++
 tools/libxl/libxl_remus_device.c | 311 +++++++++++++++++++++++++++++++++++++++
 tools/libxl/libxl_remus_device.h |  97 ++++++++++++
 7 files changed, 486 insertions(+), 4 deletions(-)
 create mode 100644 tools/libxl/libxl_remus.c
 create mode 100644 tools/libxl/libxl_remus_device.c
 create mode 100644 tools/libxl/libxl_remus_device.h
tools/libxl/Makefile +2 -0
index a29c505..8398386 100644
@@ -52,6 +52,8 @@ else
 LIBXL_OBJS-y += libxl_nonetbuffer.o
 endif
 
+LIBXL_OBJS-y += libxl_remus.o libxl_remus_device.o
+
 LIBXL_OBJS-$(CONFIG_X86) += libxl_cpuid.o libxl_x86.o
 LIBXL_OBJS-$(CONFIG_ARM) += libxl_nocpuid.o libxl_arm.o
 
tools/libxl/libxl.c +6 -1
index 30b0b06..e3eca6e 100644
@@ -741,7 +741,12 @@ int libxl_domain_remus_start(libxl_ctx *ctx, libxl_domain_remus_info *info,
 
     assert(info);
 
-    /* TBD: Remus setup - i.e. attach qdisc, enable disk buffering, etc */
+    GCNEW(dss->remus_state);
+
+    /* convenience shorthand */
+    libxl__remus_state *remus_state = dss->remus_state;
+    remus_state->dss = dss;
+    remus_state->egc = egc;
 
     /* Point of no return */
     libxl__domain_suspend(egc, dss);
tools/libxl/libxl_dom.c +1 -3
index 661999c..fc0c136 100644
@@ -766,8 +766,6 @@ int libxl__toolstack_restore(uint32_t domid, const uint8_t *buf,
 
 /*==================== Domain suspend (save) ====================*/
 
-static void domain_suspend_done(libxl__egc *egc,
-                        libxl__domain_suspend_state *dss, int rc);
 static void domain_suspend_callback_common_done(libxl__egc *egc,
                                 libxl__domain_suspend_state *dss, int ok);
 static void remus_domain_suspend_callback_common_done(libxl__egc *egc,
@@ -1716,7 +1714,7 @@ static void save_device_model_datacopier_done(libxl__egc *egc,
     dss->save_dm_callback(egc, dss, our_rc);
 }
 
-static void domain_suspend_done(libxl__egc *egc,
+void domain_suspend_done(libxl__egc *egc,
                         libxl__domain_suspend_state *dss, int rc)
 {
     STATE_AO_GC(dss->ao);
tools/libxl/libxl_internal.h +28 -0
index 33b62a2..421ae24 100644
@@ -2457,8 +2457,35 @@ typedef struct libxl__logdirty_switch {
     libxl__ev_time timeout;
 } libxl__logdirty_switch;
 
+typedef struct libxl__remus_state {
+    libxl__domain_suspend_state *dss;
+    libxl__egc *egc;
+
+    /* private */
+    int saved_rc;
+    /* Opaque context containing device related stuff */
+    void *device_state;
+} libxl__remus_state;
+
 _hidden int libxl__netbuffer_enabled(libxl__gc *gc);
 
+_hidden void domain_suspend_done(libxl__egc *egc,
+                                 libxl__domain_suspend_state *dss,
+                                 int rc);
+
+_hidden void libxl__remus_setup_done(libxl__egc *egc,
+                                     libxl__domain_suspend_state *dss,
+                                     int rc);
+
+_hidden void libxl__remus_device_setup(libxl__egc *egc,
+                                       libxl__domain_suspend_state *dss);
+
+_hidden void libxl__remus_teardown_done(libxl__egc *egc,
+                                        libxl__domain_suspend_state *dss);
+
+_hidden void libxl__remus_device_teardown(libxl__egc *egc,
+                                          libxl__domain_suspend_state *dss);
+
 struct libxl__domain_suspend_state {
     /* set by caller of libxl__domain_suspend */
     libxl__ao *ao;
@@ -2470,6 +2497,7 @@ struct libxl__domain_suspend_state {
     int live;
     int debug;
     const libxl_domain_remus_info *remus;
+    libxl__remus_state *remus_state;
     /* private */
     libxl__ev_evtchn guest_evtchn;
     int guest_evtchn_lockfd;
tools/libxl/libxl_remus.c new file +41 -0

41 lines not on this page · raw message

tools/libxl/libxl_remus_device.c new file +311 -0

311 lines not on this page · raw message

tools/libxl/libxl_remus_device.h new file +97 -0

97 lines not on this page · raw message

Signature · 1 line
1.8.3.2
#75 lore raw

PATCH v9 6/12 remus: implement the API for checkpoint

In reply to Yang Hongyang
---
 tools/libxl/libxl_internal.h     |  3 +++
 tools/libxl/libxl_remus_device.c | 54 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 57 insertions(+)
tools/libxl/libxl_internal.h +3 -0
index 421ae24..14094aa 100644
@@ -2485,6 +2485,9 @@ _hidden void libxl__remus_teardown_done(libxl__egc *egc,
 
 _hidden void libxl__remus_device_teardown(libxl__egc *egc,
                                           libxl__domain_suspend_state *dss);
+_hidden int libxl__remus_device_postsuspend(libxl__remus_state *remus_state);
+_hidden int libxl__remus_device_preresume(libxl__remus_state *remus_state);
+_hidden int libxl__remus_device_commit(libxl__remus_state *remus_state);
 
 struct libxl__domain_suspend_state {
     /* set by caller of libxl__domain_suspend */
tools/libxl/libxl_remus_device.c +54 -0

60 lines not on this page · raw message

Signature · 1 line
1.8.3.2
#76 lore raw

Re: [PATCH V9 06/12] remus: implement the API for checkpoint

Yang Hongyang writes ("[PATCH V9 06/12] remus: implement the API for checkpoint"):

tools/libxl/libxl_internal.h _hidden void libxl__remus_teardown_done(libxl__egc *egc, · line 2490

Quoted 3 lines
tools/libxl/libxl_internal.h +3 -0
+_hidden int libxl__remus_device_postsuspend(libxl__remus_state *remus_state);
+_hidden int libxl__remus_device_preresume(libxl__remus_state *remus_state);
+_hidden int libxl__remus_device_commit(libxl__remus_state *remus_state);

This patch seems to introduce these functions with no callers. The functions are then patched in a subsequent patch, again without any callers. See my comments on the previous patch.

Thanks,
Ian.

#77 lore raw

Re: [PATCH V9 06/12] remus: implement the API for checkpoint

Quoted 8 lines · Ian Jackson

Yang Hongyang writes ("[PATCH V9 06/12] remus: implement the API for checkpoint"):

tools/libxl/libxl_internal.h _hidden void libxl__remus_teardown_done(libxl__egc *egc, · line 2490

Quoted 3 lines
tools/libxl/libxl_internal.h +3 -0
+_hidden int libxl__remus_device_postsuspend(libxl__remus_state *remus_state);
+_hidden int libxl__remus_device_preresume(libxl__remus_state *remus_state);
+_hidden int libxl__remus_device_commit(libxl__remus_state *remus_state);

This patch seems to introduce these functions with no callers. The functions are then patched in a subsequent patch, again without any callers. See my comments on the previous patch.

Hi Ian, these functions are called in patch 11. I will restructure the patch to make it easy to review.(merge this func define and the caller)

Quoted 5 lines

Thanks,
Ian.
.

Signature · 2 lines
Thanks,
Yang.
#78 lore raw

PATCH v9 7/12 remus: Remus network buffering core and APIs to setup/teardown

In reply to Yang Hongyang

From: Shriram Rajagopalan <[email protected]>

1.Add two members in libxl_domain_remus_info:
netbuf: whether netbuf is enabled
netbufscript: the path of the script which will be run to setup
and tear down the guest's interface.
2.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.

The following steps are taken during init:
a) establish a dedicated remus context containing libnl related state (netlink sockets, qdisc caches, etc.,)

The following steps are taken for each vif during setup:
a) call the hotplug script to setup its network buffer

b) Obtain handles to plug qdiscs installed on the IFB devices chosen by the hotplug scripts.

And during teardown, the netlink resources are released, followed by invocation of hotplug scripts to remove the ifb devices.

---
 docs/misc/xenstore-paths.markdown      |   4 +
 tools/hotplug/Linux/Makefile           |   1 +
 tools/hotplug/Linux/remus-netbuf-setup | 183 +++++++++++++++
 tools/libxl/libxl.c                    |  17 ++
 tools/libxl/libxl.h                    |  13 ++
 tools/libxl/libxl_internal.h           |   2 +
 tools/libxl/libxl_netbuffer.c          | 403 +++++++++++++++++++++++++++++++++
 tools/libxl/libxl_nonetbuffer.c        |  23 ++
 tools/libxl/libxl_remus_device.c       |  22 +-
 tools/libxl/libxl_remus_device.h       |   2 +
 tools/libxl/libxl_types.idl            |   2 +
 11 files changed, 670 insertions(+), 2 deletions(-)
 create mode 100644 tools/hotplug/Linux/remus-netbuf-setup
docs/misc/xenstore-paths.markdown +4 -0
index 70ab7f4..039eaea 100644
@@ -385,6 +385,10 @@ The guest's virtual time offset from UTC in seconds.
 
 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
index a14cb42..baaaa41 100644
@@ -15,6 +15,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

tools/libxl/libxl.c +17 -0
index e3eca6e..687a2a9 100644
@@ -748,6 +748,23 @@ int libxl_domain_remus_start(libxl_ctx *ctx, libxl_domain_remus_info *info,
     remus_state->dss = dss;
     remus_state->egc = egc;
 
+    /* Setup network buffering */
+    if (info->netbuf) {
+        if (!libxl__netbuffer_enabled(gc)) {
+            LOG(ERROR, "Remus: No support for network buffering");
+            goto out;
+        }
+
+        if (info->netbufscript) {
+            remus_state->netbufscript =
+                libxl__strdup(gc, info->netbufscript);
+        } else {
+            remus_state->netbufscript =
+                GCSPRINTF("%s/remus-netbuf-setup",
+                libxl__xen_script_dir_path());
+        }
+    }
+
     /* Point of no return */
     libxl__domain_suspend(egc, dss);
     return AO_INPROGRESS;
tools/libxl/libxl.h +13 -0
index b2c3015..62f7dd4 100644
@@ -410,6 +410,19 @@
 #define LIBXL_HAVE_DRIVER_DOMAIN_CREATION 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
+
+/*
  * LIBXL_HAVE_SIGCHLD_SELECTIVE_REAP
  *
  * If this is defined:
tools/libxl/libxl_internal.h +2 -0
index 14094aa..b72643b 100644
@@ -2458,6 +2458,8 @@ typedef struct libxl__logdirty_switch {
 } libxl__logdirty_switch;
 
 typedef struct libxl__remus_state {
+    /* Script to setup/teardown network buffers */
+    const char *netbufscript;
     libxl__domain_suspend_state *dss;
     libxl__egc *egc;
 
tools/libxl/libxl_netbuffer.c +403 -0

415 lines not on this page · raw message

tools/libxl/libxl_nonetbuffer.c +23 -0
index 6aa4bf1..4ee24e1 100644
@@ -22,6 +22,29 @@ int libxl__netbuffer_enabled(libxl__gc *gc)
     return 0;
 }
 
+static int nic_match(const void *libxl_device, int devcie_type,
+                     libxl_async_exec *async_exec)
+{
+    return REMUS_NOT_SUPPORT;
+}
+
+static int nic_init(libxl__remus_device_type *self,
+                    libxl__remus_state *remus_state)
+{
+    return REMUS_OK;
+}
+
+static void nic_destroy(libxl__remus_device_type *self)
+{
+    return;
+}
+
+libxl__remus_device_type remus_nic = {
+    .init = nic_init,
+    .destroy = nic_destroy,
+    .match = nic_match,
+};
+
 /*
  * Local variables:
  * mode: C
tools/libxl/libxl_remus_device.c +20 -2
index bfe6080..1564bd1 100644
@@ -37,6 +37,7 @@ typedef struct libxl__remus_device_state {
 } libxl__remus_device_state;
 
 static libxl__remus_device_type *device_types[] = {
+    &remus_device_nic,
 };
 
 int libxl__remus_device_postsuspend(libxl__remus_state *remus_state)
@@ -111,6 +112,16 @@ static void libxl__remus_teardown_cleanup(libxl__egc *egc,
     int i;
     libxl__remus_device_type *dev_type;
 
+    /* Convenience aliases */
+    libxl__remus_device_state *dev_state = dss->remus_state->device_state;
+
+    /* clean nic */
+    for (i = 0; i < dev_state->num_nics; i++)
+        libxl_device_nic_dispose(&dev_state->nics[i]);
+    free(dev_state->nics);
+    dev_state->nics = NULL;
+    dev_state->num_nics = 0;
+
     /* clean device_types */
     for (i = 0; i < ARRAY_SIZE(device_types); i++) {
         dev_type = device_types[i];
@@ -313,7 +324,7 @@ static void dev_match_script_cb(void *opaque, int status)
 void libxl__remus_device_setup(libxl__egc *egc,
                                libxl__domain_suspend_state *dss)
 {
-    int i, rc;
+    int i, rc, num_devices;
     libxl__remus_device_state *dev_state = NULL;
     libxl__remus_device_type *dev_type;
 
@@ -333,7 +344,14 @@ void libxl__remus_device_setup(libxl__egc *egc,
         }
     }
 
-    /* TBD: Remus setup - i.e. attach qdisc, enable disk buffering, etc */
+    /* nic */
+    if (dss->remus_state->netbufscript) {
+        dev_state->nics = libxl_device_nic_list(CTX, dss->domid, &num_devices);
+        dev_state->num_nics = num_devices;
+        dev_state->num_devices += num_devices;
+    }
+
+    /* TBD: enable disk buffering */
 
     GCNEW_ARRAY(dev_state->dev, dev_state->num_devices);
 
tools/libxl/libxl_remus_device.h +2 -0
index d8d16ff..30b368d 100644
@@ -94,4 +94,6 @@ struct libxl__remus_device {
     const libxl__remus_device_type *dev_type;
 };
 
+extern libxl__remus_device_type remus_device_nic;
+
 #endif
tools/libxl/libxl_types.idl +2 -0
index 612645c..cb3d926 100644
@@ -563,6 +563,8 @@ libxl_domain_remus_info = Struct("domain_remus_info",[
     ("interval",     integer),
     ("blackhole",    bool),
     ("compression",  bool),
+    ("netbuf",       bool),
+    ("netbufscript", string),
     ])
 
 libxl_event_type = Enumeration("event_type", [
Signature · 1 line
1.8.3.2
#79 lore raw

PATCH v9 8/12 remus: implement the API to buffer/release packages

In reply to Yang Hongyang

From: Shriram Rajagopalan <[email protected]>

This patch implements two APIs:
1. netbuf_start_new_epoch()
It marks a new epoch. The packages before this epoch will be flushed, and the packages after this epoch will be buffered. It will be called after the guest is suspended.
2. netbuf_release_prev_epoch()
It flushes the buffered packages to client, and it will be called when a checkpoint finishes.

---
 tools/libxl/libxl_netbuffer.c | 57 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 57 insertions(+)
tools/libxl/libxl_netbuffer.c +57 -0
index a5f2b9a..4b4bc9d 100644
@@ -416,9 +416,66 @@ static int nic_teardown(libxl__remus_device *remus_dev,
     return REMUS_INPROGRESS;
 }
 
+/* The buffer_op's value, not the value passed to kernel */
+enum {
+    tc_buffer_start,
+    tc_buffer_release
+};
+
+static int remus_netbuf_op(libxl__remus_device_nic *remus_nic,
+                           libxl__remus_netbuf_state *netbuf_state,
+                           int buffer_op)
+{
+    int ret;
+
+    STATE_AO_GC(netbuf_state->ao);
+
+    if (buffer_op == tc_buffer_start)
+        ret = rtnl_qdisc_plug_buffer(remus_nic->qdisc);
+    else
+        ret = rtnl_qdisc_plug_release_one(remus_nic->qdisc);
+
+    if (!ret) {
+        ret = rtnl_qdisc_add(netbuf_state->nlsock,
+                             remus_nic->qdisc,
+                             NLM_F_REQUEST);
+        if (ret)
+            goto out;
+    }
+
+    return REMUS_OK;
+
+out:
+    LOG(ERROR, "Remus: cannot do netbuf op %s on %s:%s",
+        ((buffer_op == tc_buffer_start) ?
+        "start_new_epoch" : "release_prev_epoch"),
+        remus_nic->ifb, nl_geterror(ret));
+    return REMUS_FAIL;
+}
+
+static int netbuf_start_new_epoch(libxl__remus_device *remus_dev)
+{
+    libxl__remus_device_nic *remus_nic =
+        CONTAINER_OF(remus_dev, *remus_nic, remus_dev);
+    libxl__remus_netbuf_state *netbuf_state = remus_dev->dev_type->data;
+
+    return remus_netbuf_op(remus_nic, netbuf_state, tc_buffer_start);
+}
+
+static int netbuf_release_prev_epoch(libxl__remus_device *remus_dev)
+{
+    libxl__remus_device_nic *remus_nic =
+        CONTAINER_OF(remus_dev, *remus_nic, remus_dev);
+    libxl__remus_netbuf_state *netbuf_state = remus_dev->dev_type->data;
+
+    return remus_netbuf_op(remus_nic, netbuf_state, tc_buffer_release);
+}
+
 libxl__remus_device_type remus_device_nic = {
     .init = nic_init,
     .destroy = nic_destroy,
+    .postsuspend = netbuf_start_new_epoch,
+    .commit = netbuf_release_prev_epoch,
     .match = nic_match,
     .setup = nic_setup,
     .teardown = nic_teardown,
Signature · 1 line
1.8.3.2
#80 lore raw

Re: [PATCH V9 08/12] remus: implement the API to buffer/release packages

Yang Hongyang writes ("[PATCH V9 08/12] remus: implement the API to buffer/release packages"):

Quoted 8 lines

This patch implements two APIs:
1. netbuf_start_new_epoch()
It marks a new epoch. The packages before this epoch will be flushed, and the packages after this epoch will be buffered. It will be called after the guest is suspended.
2. netbuf_release_prev_epoch()
It flushes the buffered packages to client, and it will be called when a checkpoint finishes.

Thanks.

(BTW "packages" should be "packets" throughout.)

tools/libxl/libxl_netbuffer.c static int nic_teardown(libxl__remus_device *remus_dev, · line 423

Quoted 13 lines
tools/libxl/libxl_netbuffer.c +5 -0
index a5f2b9a..4b4bc9d 100644
@@ -416,9 +416,66 @@ static int nic_teardown(libxl__remus_device *remus_dev,
     return REMUS_INPROGRESS;
 }
 
+/* The buffer_op's value, not the value passed to kernel */
+enum {
+    tc_buffer_start,
+    tc_buffer_release
+};

The comment refers to a "buffer_op" variable which is not nearby. I suggest replacing the comment with

    /* Internal value for libxl, not the value passed to kernel */

Are these names "tc_" not possibly clashing with some future kernel things ?

tools/libxl/libxl_netbuffer.c static int nic_teardown(libxl__remus_device *remus_dev, · line 436

Quoted 12 lines
tools/libxl/libxl_netbuffer.c +12 -0
+static int remus_netbuf_op(libxl__remus_device_nic *remus_nic,
+                           libxl__remus_netbuf_state *netbuf_state,
+                           int buffer_op)
+{
+    int ret;
+
+    STATE_AO_GC(netbuf_state->ao);
+
+    if (buffer_op == tc_buffer_start)
+        ret = rtnl_qdisc_plug_buffer(remus_nic->qdisc);
+    else
+        ret = rtnl_qdisc_plug_release_one(remus_nic->qdisc);

If you're going to have an enum here, I think you should use "switch", and explicitly abort() on unknown values. Otherwise when a new op is invented this code will silently do the wrong thing.

tools/libxl/libxl_netbuffer.c static int nic_teardown(libxl__remus_device *remus_dev, · line 438

Quoted 1 line
tools/libxl/libxl_netbuffer.c +1 -0
+    if (!ret) {

This is an opaque error handling style. Please use libxl's standard "goto out" style.

tools/libxl/libxl_netbuffer.c static int nic_teardown(libxl__remus_device *remus_dev, · line 446

Quoted 8 lines
tools/libxl/libxl_netbuffer.c +8 -0
+        ret = rtnl_qdisc_add(netbuf_state->nlsock,
+                             remus_nic->qdisc,
+                             NLM_F_REQUEST);
+        if (ret)
+            goto out;
+    }
+
+    return REMUS_OK;

Please don't invent your own error numbers. Please use the existing libxl error code type. Feel free to add new values if you need them.

tools/libxl/libxl_netbuffer.c static int nic_teardown(libxl__remus_device *remus_dev, · line 451

Quoted 4 lines
tools/libxl/libxl_netbuffer.c +4 -0
+out:
+    LOG(ERROR, "Remus: cannot do netbuf op %s on %s:%s",
+        ((buffer_op == tc_buffer_start) ?
+        "start_new_epoch" : "release_prev_epoch"),

Perhaps there should be a static const array of these strings. At the very least you should make sure this code handles the _release op explicitly and crashes if the value is not recognised.

tools/libxl/libxl_netbuffer.c static int nic_teardown(libxl__remus_device *remus_dev, · line 478

Quoted 5 lines
tools/libxl/libxl_netbuffer.c +2 -0
 libxl__remus_device_type remus_device_nic = {
     .init = nic_init,
     .destroy = nic_destroy,
+    .postsuspend = netbuf_start_new_epoch,
+    .commit = netbuf_release_prev_epoch,

Presumably, this is the patch where network buffering actually starts to happen. So should this come with a documentation change removing any warnings about remus and networking ?

Thanks,
Ian.

#81 lore raw

Re: [PATCH V9 08/12] remus: implement the API to buffer/release packages

Quoted 33 lines · Ian Jackson

Yang Hongyang writes ("[PATCH V9 08/12] remus: implement the API to buffer/release packages"):

Quoted 8 lines

This patch implements two APIs:
1. netbuf_start_new_epoch()
It marks a new epoch. The packages before this epoch will be flushed, and the packages after this epoch will be buffered. It will be called after the guest is suspended.
2. netbuf_release_prev_epoch()
It flushes the buffered packages to client, and it will be called when a checkpoint finishes.

Thanks.

(BTW "packages" should be "packets" throughout.)

Review

Quoted 1 line
(quoted diff) +0 -0

b/tools/libxl/libxl_netbuffer.c

tools/libxl/libxl_netbuffer.c static int nic_teardown(libxl__remus_device

Quoted 4 lines

index a5f2b9a..4b4bc9d 100644

tools/libxl/libxl_netbuffer.c +0 -0
@@ -416,9 +416,66 @@ static int nic_teardown(libxl__remus_device

*remus_dev,

tools/libxl/libxl_netbuffer.c static int nic_teardown(libxl__remus_device *remus_dev, · line 423

Quoted 8 lines
tools/libxl/libxl_netbuffer.c +5 -0
     return REMUS_INPROGRESS;
 }
 
+/* The buffer_op's value, not the value passed to kernel */
+enum {
+    tc_buffer_start,
+    tc_buffer_release
+};

The comment refers to a "buffer_op" variable which is not nearby. I suggest replacing the comment with

Quoted 6 lines
    /* Internal value for libxl, not the value passed to kernel */

Are these names "tc_" not possibly clashing with some future kernel things ?

These are local enums. They have nothing to do with the sch_plug qdisc in the kernel. That said, I agree that they could be renamed to something more local:
netbuf_begin_next_epoch /* start buffering pkts for next epoch */ netbuf_commit_prev_epoch /* release buffered pkts from prev epoch, after
* receiving commit ack
from backup

                                                     */

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#82 lore raw

Re: [PATCH V9 08/12] remus: implement the API to buffer/release packages

Shriram Rajagopalan writes ("Re: [PATCH V9 08/12] remus: implement the API to buffer/release packages"):

Quoted 8 lines

On Wed, Apr 23, 2014 at 11:10 AM, Ian Jackson <[email protected]> wrote:

Are these names "tc_" not possibly clashing with some future kernel things ?

These are local enums. They have nothing to do with the sch_plug qdisc in the kernel.

Right. All I want to know is whether the kernel is likely to introduce its own meanings for these names. (I haven't looked at the kernel headers in any detail.) The kernel has historically been a bit cavalier about namespacing.

If the kernel might think it owns the tc_* bit of the namespace then we should avoid it. If the kernel isn't likely to think that then it's good as it is.

Quoted 4 lines

That said, I agree that they could be renamed to
something more local:
netbuf_begin_next_epoch /* start buffering pkts for next epoch */ netbuf_commit_prev_epoch /* release buffered pkts from prev epoch, after

But probably we don't need to go so far ! Short names are generally a good thing too.

Ian.

#83 lore raw

PATCH v9 9/12 libxl: use the API to setup/teardown network buffering

In reply to Yang Hongyang
---
 tools/libxl/libxl.c          |  6 +-----
 tools/libxl/libxl_dom.c      | 11 +++++++++++
 tools/libxl/libxl_internal.h | 10 ++++++++++
 tools/libxl/libxl_remus.c    | 16 ++++++++++++++++
 4 files changed, 38 insertions(+), 5 deletions(-)
tools/libxl/libxl.c +1 -5
index 687a2a9..32b836f 100644
@@ -766,7 +766,7 @@ int libxl_domain_remus_start(libxl_ctx *ctx, libxl_domain_remus_info *info,
     }
 
     /* Point of no return */
-    libxl__domain_suspend(egc, dss);
+    libxl__remus_setup_initiate(egc, dss);
     return AO_INPROGRESS;
 
  out:
@@ -782,10 +782,6 @@ static void remus_failover_cb(libxl__egc *egc,
      * backup died or some network error occurred preventing us
      * from sending checkpoints.
      */
-
-    /* TBD: Remus cleanup - i.e. detach qdisc, release other
-     * resources.
-     */
     libxl__ao_complete(egc, ao, rc);
 }
 
tools/libxl/libxl_dom.c +11 -0
index fc0c136..16ea7d8 100644
@@ -1728,6 +1728,17 @@ void domain_suspend_done(libxl__egc *egc,
         xc_suspend_evtchn_release(CTX->xch, CTX->xce, domid,
                            dss->guest_evtchn.port, &dss->guest_evtchn_lockfd);
 
+    if (dss->remus_state) {
+        /*
+        * 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_initiate(egc, dss, rc);
+        return;
+    }
+
     dss->callback(egc, dss, rc);
 }
 
tools/libxl/libxl_internal.h +10 -0
index b72643b..3c0f94d 100644
@@ -2467,6 +2467,9 @@ typedef struct libxl__remus_state {
     int saved_rc;
     /* Opaque context containing device related stuff */
     void *device_state;
+
+    /* used for checkpoint */
+    libxl__ev_time timeout;
 } libxl__remus_state;
 
 _hidden int libxl__netbuffer_enabled(libxl__gc *gc);
@@ -2491,6 +2494,13 @@ _hidden int libxl__remus_device_postsuspend(libxl__remus_state *remus_state);
 _hidden int libxl__remus_device_preresume(libxl__remus_state *remus_state);
 _hidden int libxl__remus_device_commit(libxl__remus_state *remus_state);
 
+_hidden void libxl__remus_setup_initiate(libxl__egc *egc,
+                                         libxl__domain_suspend_state *dss);
+
+_hidden void libxl__remus_teardown_initiate(libxl__egc *egc,
+                                            libxl__domain_suspend_state *dss,
+                                            int rc);
+
 struct libxl__domain_suspend_state {
     /* set by caller of libxl__domain_suspend */
     libxl__ao *ao;
tools/libxl/libxl_remus.c +16 -0
index 05af451..1e17259 100644
@@ -18,6 +18,12 @@
 #include "libxl_internal.h"
 
 /*----- remus setup/teardown code -----*/
+void libxl__remus_setup_initiate(libxl__egc *egc,
+                                 libxl__domain_suspend_state *dss)
+{
+    libxl__ev_time_init(&dss->remus_state->timeout);
+    libxl__remus_device_setup(egc, dss);
+}
 
 void libxl__remus_setup_done(libxl__egc *egc,
                              libxl__domain_suspend_state *dss,
@@ -34,6 +40,16 @@ void libxl__remus_setup_done(libxl__egc *egc,
     domain_suspend_done(egc, dss, rc);
 }
 
+void libxl__remus_teardown_initiate(libxl__egc *egc,
+                                    libxl__domain_suspend_state *dss,
+                                    int rc)
+{
+    /* stash rc somewhere before invoking teardown ops. */
+    dss->remus_state->saved_rc = rc;
+
+    libxl__remus_device_teardown(egc, dss);
+}
+
 void libxl__remus_teardown_done(libxl__egc *egc,
                                 libxl__domain_suspend_state *dss)
 {
Signature · 1 line
1.8.3.2
#84 lore raw

Re: [PATCH V9 09/12] libxl: use the API to setup/teardown network buffering

Yang Hongyang writes ("[PATCH V9 09/12] libxl: use the API to setup/teardown network buffering"):

Quoted 1 line

---

...

tools/libxl/libxl.c int libxl_domain_remus_start(libxl_ctx *ctx, libxl_domain_remus_info *info, · line 769

Quoted 3 lines
     /* Point of no return */
tools/libxl/libxl.c +1 -1
-    libxl__domain_suspend(egc, dss);
+    libxl__remus_setup_initiate(egc, dss);

I think this patch may need to become part of some other patch; see my other comments.

tools/libxl/libxl_internal.h typedef struct libxl__remus_state { · line 2472

Quoted 11 lines
tools/libxl/libxl_internal.h +3 -0
index b72643b..3c0f94d 100644
@@ -2467,6 +2467,9 @@ typedef struct libxl__remus_state {
     int saved_rc;
     /* Opaque context containing device related stuff */
     void *device_state;
+
+    /* used for checkpoint */
+    libxl__ev_time timeout;

There are no calls which actually set this timeout. Nor any which clean it up. Obviously some important moving parts are missing here.

Thanks,
Ian.

#85 lore raw

PATCH 1/2 drbd: implement replicated checkpointing disk

In reply to Yang Hongyang

Implement remus-drbd-replicated-checkpointing-disk based on generic remus devices framework.

---
 tools/hotplug/Linux/Makefile         |    1 +
 tools/hotplug/Linux/block-drbd-probe |   84 +++++++++++++++++
 tools/libxl/Makefile                 |    2 +-
 tools/libxl/libxl_remus_device.c     |    1 +
 tools/libxl/libxl_remus_device.h     |    1 +
 tools/libxl/libxl_remus_disk_drbd.c  |  164 ++++++++++++++++++++++++++++++++++
 6 files changed, 252 insertions(+), 1 deletions(-)
 create mode 100755 tools/hotplug/Linux/block-drbd-probe
 create mode 100644 tools/libxl/libxl_remus_disk_drbd.c
tools/hotplug/Linux/Makefile +1 -0
index baaaa41..31d9e00 100644
@@ -23,6 +23,7 @@ XEN_SCRIPTS += xen-hotplug-cleanup
 XEN_SCRIPTS += external-device-migrate
 XEN_SCRIPTS += vscsi
 XEN_SCRIPTS += block-iscsi
+XEN_SCRIPTS += block-drbd-probe
 XEN_SCRIPTS += $(XEN_SCRIPTS-y)
 
 XEN_SCRIPT_DATA = xen-script-common.sh locking.sh logging.sh
tools/hotplug/Linux/block-drbd-probe new file +84 -0

84 lines not on this page · raw message

tools/libxl/Makefile +1 -1
index 8398386..53461ab 100644
@@ -52,7 +52,7 @@ else
 LIBXL_OBJS-y += libxl_nonetbuffer.o
 endif
 
-LIBXL_OBJS-y += libxl_remus.o libxl_remus_device.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_OBJS-$(CONFIG_ARM) += libxl_nocpuid.o libxl_arm.o
tools/libxl/libxl_remus_device.c +1 -0
index 1564bd1..c323773 100644
@@ -38,6 +38,7 @@ typedef struct libxl__remus_device_state {
 
 static libxl__remus_device_type *device_types[] = {
     &remus_device_nic,
+    &remus_device_drbd_disk,
 };
 
 int libxl__remus_device_postsuspend(libxl__remus_state *remus_state)
tools/libxl/libxl_remus_device.h +1 -0
index 30b368d..4b41021 100644
@@ -95,5 +95,6 @@ struct libxl__remus_device {
 };
 
 extern libxl__remus_device_type remus_device_nic;
+extern libxl__remus_device_type remus_device_drbd_disk;
 
 #endif
tools/libxl/libxl_remus_disk_drbd.c new file +164 -0

164 lines not on this page · raw message

Signature · 1 line
1.7.4.4
#86 lore raw

PATCH 2/2 remus: support disk replicated checkpointing

---
 tools/libxl/libxl_remus_device.c |   11 ++++++++++-
 1 files changed, 10 insertions(+), 1 deletions(-)
tools/libxl/libxl_remus_device.c +10 -1
index c323773..316f832 100644
@@ -123,6 +123,13 @@ static void libxl__remus_teardown_cleanup(libxl__egc *egc,
     dev_state->nics = NULL;
     dev_state->num_nics = 0;
 
+    /* clean disk */
+    for (i = 0; i < dev_state->num_disks; i++)
+        libxl_device_disk_dispose(&dev_state->disks[i]);
+    free(dev_state->disks);
+    dev_state->disks = NULL;
+    dev_state->num_disks = 0;
+
     /* clean device_types */
     for (i = 0; i < ARRAY_SIZE(device_types); i++) {
         dev_type = device_types[i];
@@ -352,7 +359,9 @@ void libxl__remus_device_setup(libxl__egc *egc,
         dev_state->num_devices += num_devices;
     }
 
-    /* TBD: enable disk buffering */
+    dev_state->disks = libxl_device_disk_list(CTX, dss->domid, &num_devices);
+    dev_state->num_disks = num_devices;
+    dev_state->num_devices += num_devices;
 
     GCNEW_ARRAY(dev_state->dev, dev_state->num_devices);
 
Signature · 1 line
1.7.4.4
#87 lore raw
In reply to Yang Hongyang

Ping

Quoted 153 lines · Yang Hongyang

This patch series adds support for network buffering in the Remus codebase in libxl.

Changes in V9:
introduce an API to async exec scripts for both device and netbuffer.
Use async exec script api to exec scripts.

Changes in V8:
Applied some comments(by IanJ).
Merge some struct definitions to it's implementation. (2/3/5 in V7 => 3 in V8)

Changes in V7:
Applied missing comments(by IanJ).
Applied Shriram comments.

merge netbufering tangled setup/teardown code into one patch. (2/6/8 in V6 => 5 in V7. 9/10 in V6 => 7 in V7)

Changes in V6:
Applied Ian Jackson's comments of V5 series. the [PATCH 2/4 V5] is split by small functionalities.

   [PATCH 4/4 V5] --> [PATCH 13/13] netbuffer is default enabled.

Changes in V5:

Merge hotplug script patch (2/5) and hotplug script setup/teardown patch (3/5) into a single patch.

Changes in V4:

[1/5] Remove check for libnl command line utils in autoconf checks

[2/5] minor nits

[3/5] define LIBXL_HAVE_REMUS_NETBUF in libxl.h

[4/5] clean ups. Make the usleep in checkpoint callback asynchronous

[5/5] minor nits

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(by shriram):

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 Rajagopalan (7):
remus: add libnl3 dependency to autoconf scripts
remus: introduce a function to check whether network buffering is
enabled
remus: Remus network buffering core and APIs to setup/teardown
remus: implement the API to buffer/release packages
libxl: rename remus_failover_cb() to remus_replication_failure_cb()
libxl: control network buffering in remus callbacks
libxl: network buffering cmdline switch

Yang Hongyang (5):
introduce an API to async exec scripts
libxl_device: use async exec script api
remus: remus device core and APIs to setup/teardown
remus: implement the API for checkpoint
libxl: use the API to setup/teardown network buffering

  README                                 |   4 +
  config/Tools.mk.in                     |   3 +
  docs/man/xl.conf.pod.5                 |   6 +
  docs/man/xl.pod.1                      |  11 +-
  docs/misc/xenstore-paths.markdown      |   4 +
  tools/configure.ac                     |  15 +
  tools/hotplug/Linux/Makefile           |   1 +
  tools/hotplug/Linux/remus-netbuf-setup | 183 ++++++++++++
  tools/libxl/Makefile                   |  11 +
  tools/libxl/libxl.c                    |  42 ++-
  tools/libxl/libxl.h                    |  13 +
  tools/libxl/libxl_device.c             |  80 ++----
  tools/libxl/libxl_dom.c                |  83 +++++-
  tools/libxl/libxl_internal.c           |  82 ++++++
  tools/libxl/libxl_internal.h           |  70 ++++-
  tools/libxl/libxl_netbuffer.c          | 491 +++++++++++++++++++++++++++++++++
  tools/libxl/libxl_nonetbuffer.c        |  54 ++++
  tools/libxl/libxl_remus.c              |  57 ++++
  tools/libxl/libxl_remus_device.c       | 383 +++++++++++++++++++++++++
  tools/libxl/libxl_remus_device.h       |  99 +++++++
  tools/libxl/libxl_types.idl            |   2 +
  tools/libxl/xl.c                       |   4 +
  tools/libxl/xl.h                       |   1 +
  tools/libxl/xl_cmdimpl.c               |  28 +-
  tools/libxl/xl_cmdtable.c              |   3 +
  tools/remus/README                     |   6 +
  26 files changed, 1650 insertions(+), 86 deletions(-)
Quoted 7 lines

create mode 100644 tools/hotplug/Linux/remus-netbuf-setup create mode 100644 tools/libxl/libxl_netbuffer.c create mode 100644 tools/libxl/libxl_nonetbuffer.c create mode 100644 tools/libxl/libxl_remus.c create mode 100644 tools/libxl/libxl_remus_device.c create mode 100644 tools/libxl/libxl_remus_device.h

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#88 lore raw
In reply to Yang Hongyang

Yang Hongyang writes ("[PATCH V9 00/12] Remus/Libxl: Network buffering support"):

Quoted 2 lines

This patch series adds support for network buffering in the Remus codebase in libxl.

Thanks. I'm reviewing this, but I am lacking patch 10. So my review will only include up to patch 9.

If you were to provide a public git branch I could fetch, that would be slightly more convenient and also help work around any lost messages.

Thanks,
Ian.