Skip to contentSkip to conversation

Remus/Libxl: Remus network buffering and drbd disk

PATCH Superseded Yang Hongyang 3 participants 19 messages Jul 7, 2014 – Jul 11, 2014

v15 of 21 Superseded Latest is v21 →

lore
Share & tools
lore
#0 lore raw

v15 cover Remus/Libxl: Remus network buffering and drbd disk

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

the code is also hosted on github:

url: https://github.com/laijs/xen
branch: remus-v15

Changes in v15:
The first patch in v14 has been taken, so remove it from the patchset. Add a patch to Update maintained files of REMUS.
Rebased.

Changes in v14:
Addressed IanJ's comments.
Rebased.

Changes in v13:
Addressed Konrad's comments.
Rebased.

Changes in v12:
Add disk buffering cmdline switch.

Changes in v11:
Addressed comments from Ian J and Shriram.
Add drbd disk implement into this patch series.

Changes in V10:
Restructured the whole patch series.
Introduce the remus device abstract layer.
Make remus checkpoint asynchronous.

Changes in V9:
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

Legend:
A - acked
D - previous acked, but new change introduced so acked-by dropped M - Modified
S - the same version as last round
No marker - new patch

Yang Hongyang (7):
A remus: add libnl3 dependency for network buffering support S remus: introduce remus device
S remus netbuffer: implement remus network buffering for nic devices S remus drbd: Implement remus drbd replicated disk
S libxl: network buffering cmdline switch
S libxl: disk buffering cmdline switch
MAINTAINERS: Update maintained files of REMUS

 MAINTAINERS                            |   5 +
 README                                 |   4 +
 config/Tools.mk.in                     |   4 +
 docs/README.remus                      |   6 +
 docs/man/xl.conf.pod.5                 |   6 +
 docs/man/xl.pod.1                      |  15 +-
 docs/misc/xenstore-paths.markdown      |   4 +
 tools/configure.ac                     |  16 ++
 tools/hotplug/Linux/Makefile           |   2 +
 tools/hotplug/Linux/block-drbd-probe   |  85 ++++++
 tools/hotplug/Linux/remus-netbuf-setup | 203 +++++++++++++
 tools/libxl/Makefile                   |  15 +
 tools/libxl/libxl.c                    |  58 +++-
 tools/libxl/libxl.h                    |   6 +
 tools/libxl/libxl_dom.c                | 132 ++++++++-
 tools/libxl/libxl_internal.h           | 199 +++++++++++++
 tools/libxl/libxl_netbuffer.c          | 506 +++++++++++++++++++++++++++++++++
 tools/libxl/libxl_nonetbuffer.c        |  58 ++++
 tools/libxl/libxl_remus_device.c       | 411 ++++++++++++++++++++++++++
 tools/libxl/libxl_remus_disk_drbd.c    | 239 ++++++++++++++++
 tools/libxl/libxl_types.idl            |   4 +
 tools/libxl/xl.c                       |   4 +
 tools/libxl/xl.h                       |   1 +
 tools/libxl/xl_cmdimpl.c               |  32 ++-
 tools/libxl/xl_cmdtable.c              |   4 +
 25 files changed, 1993 insertions(+), 26 deletions(-)
 create mode 100755 tools/hotplug/Linux/block-drbd-probe
 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_device.c
 create mode 100644 tools/libxl/libxl_remus_disk_drbd.c
Signature · 1 line
1.9.1
#1 lore raw

PATCH v15 1/7 remus: add libnl3 dependency for network buffering support

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.

when there's no network buffering support,libxl__netbuffer_enabled() returns 0, otherwise returns 1. The callers of this api will be introduced in the rest of the series.

NOTE: This patch changes tools/configure.ac, please rerun
autogen.sh while apply the patch.

---
 README                          |  4 ++++
 config/Tools.mk.in              |  4 ++++
 docs/README.remus               |  6 ++++++
 tools/configure.ac              | 16 ++++++++++++++++
 tools/libxl/Makefile            | 13 +++++++++++++
 tools/libxl/libxl_internal.h    |  1 +
 tools/libxl/libxl_netbuffer.c   | 31 +++++++++++++++++++++++++++++++
 tools/libxl/libxl_nonetbuffer.c | 31 +++++++++++++++++++++++++++++++
 8 files changed, 106 insertions(+)
 create mode 100644 tools/libxl/libxl_netbuffer.c
 create mode 100644 tools/libxl/libxl_nonetbuffer.c
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 +4 -0
index 852c941..003ba95 100644
@@ -38,6 +38,9 @@ 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
@@ -57,6 +60,7 @@ CONFIG_BLKTAP1      := @blktap1@
 CONFIG_BLKTAP2      := @blktap2@
 CONFIG_VTPM         := @vtpm@
 CONFIG_QEMUU_EXTRA_ARGS:= @EXTRA_QEMUU_CONFIGURE_ARGS@
+CONFIG_REMUS_NETBUF := @remus_netbuf@
 
 #System options
 ZLIB                := @zlib@
docs/README.remus +6 -0
index 9fa00fe..ddf5b55 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://wiki.xen.org/wiki/Remus for details.
+
+Using Remus with libxl on Xen 4.5 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/
tools/configure.ac +16 -0
index 6d70f04..a1f47e2 100644
@@ -287,5 +287,21 @@ esac
 # Checks for header files.
 AC_CHECK_HEADERS([yajl/yajl_version.h sys/eventfd.h valgrind/memcheck.h utmp.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(remus_netbuf, [y])
+])
+
+AC_SUBST(LIBNL3_LIBS)
+AC_SUBST(LIBNL3_CFLAGS)
+
 AC_OUTPUT()
 
tools/libxl/Makefile +13 -0
index 78c1996..086fbe0 100644
@@ -21,11 +21,17 @@ endif
 
 LIBXL_LIBS =
 LIBXL_LIBS = $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest) $(LDLIBS_libxenstore) $(LDLIBS_libblktapctl) $(PTYFUNCS_LIBS) $(LIBUUID_LIBS)
+ifeq ($(CONFIG_REMUS_NETBUF),y)
+LIBXL_LIBS += $(LIBNL3_LIBS)
+endif
 
 CFLAGS_LIBXL += $(CFLAGS_libxenctrl)
 CFLAGS_LIBXL += $(CFLAGS_libxenguest)
 CFLAGS_LIBXL += $(CFLAGS_libxenstore)
 CFLAGS_LIBXL += $(CFLAGS_libblktapctl) 
+ifeq ($(CONFIG_REMUS_NETBUF),y)
+CFLAGS_LIBXL += $(LIBNL3_CFLAGS)
+endif
 CFLAGS_LIBXL += -Wshadow
 
 LIBXL_LIBS-$(CONFIG_ARM) += -lfdt
@@ -43,6 +49,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 +1 -0
index e8f2abb..f8441f6 100644
@@ -2468,6 +2468,7 @@ typedef struct libxl__save_helper_state {
                       * marshalling and xc callback functions */
 } libxl__save_helper_state;
 
+_hidden int libxl__netbuffer_enabled(libxl__gc *gc);
 
 /*----- Domain suspend (save) state structure -----*/
 
tools/libxl/libxl_netbuffer.c new file +31 -0
new file mode 100644
index 0000000..52d593c
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2014
+ * 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..1c72a7f
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2014
+ * 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.9.1
#2 lore raw

PATCH v15 2/7 remus: introduce remus device

In reply to Yang Hongyang

introduce remus device, an abstract layer of remus devices(nic, disk, etc).It provides the following APIs for libxl:

Quoted 1 line

libxl__remus_device_setup

setup remus devices, like attach qdisc, enable disk buffering, etc

Quoted 1 line

libxl__remus_device_teardown

teardown devices

Quoted 3 lines

libxl__remus_device_postsuspend
libxl__remus_device_preresume
libxl__remus_device_commit

above three are for checkpoint.
through remus device layer, the remus execution flow will be like this:
xl remus -> remus device setup

                |-> remus checkpoint(postsuspend, preresume, commit)
                      ...
                       |-> remus device teardown, failover or abort
the remus device layer provides an interface
  libxl__remus_device_ops
which a remus device must implement. the whole remus structure:
                            |remus|
                               |
                        |remus device|
                               |
                |nic| |drbd disks| |qemu disks| ...

a device(nic, drbd disks, qemu disks, etc) must implement libxl__remus_device_ops to support remus.

---
 tools/libxl/Makefile             |   2 +
 tools/libxl/libxl.c              |  34 +++-
 tools/libxl/libxl.h              |   6 +
 tools/libxl/libxl_dom.c          | 132 ++++++++++++--
 tools/libxl/libxl_internal.h     | 184 +++++++++++++++++++
 tools/libxl/libxl_remus_device.c | 379 +++++++++++++++++++++++++++++++++++++++
 tools/libxl/libxl_types.idl      |   1 +
 7 files changed, 722 insertions(+), 16 deletions(-)
 create mode 100644 tools/libxl/libxl_remus_device.c
tools/libxl/Makefile +2 -0
index 086fbe0..9c81a59 100644
@@ -56,6 +56,8 @@ else
 LIBXL_OBJS-y += libxl_nonetbuffer.o
 endif
 
+LIBXL_OBJS-y += 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 +32 -2
index 39f1c28..bcbd02b 100644
@@ -733,6 +733,31 @@ out:
 static void remus_failover_cb(libxl__egc *egc,
                               libxl__domain_suspend_state *dss, int rc);
 
+static void libxl__remus_setup_failed(libxl__egc *egc,
+                                      libxl__remus_state *rs, int rc)
+{
+    STATE_AO_GC(rs->ao);
+    libxl__ao_complete(egc, ao, rc);
+}
+
+static void libxl__remus_setup_done(libxl__egc *egc,
+                                    libxl__remus_state *rs, int rc)
+{
+    libxl__domain_suspend_state *dss = CONTAINER_OF(rs, *dss, rs);
+    STATE_AO_GC(rs->ao);
+
+    if (!rc) {
+        libxl__domain_suspend(egc, dss);
+        return;
+    }
+
+    LOG(ERROR, "Remus: failed to setup device for guest with domid %u",
+        dss->domid);
+    rs->saved_rc = rc;
+    rs->callback = libxl__remus_setup_failed;
+    libxl__remus_device_teardown(egc, rs);
+}
+
 /* TODO: Explicit Checkpoint acknowledgements via recv_fd. */
 int libxl_domain_remus_start(libxl_ctx *ctx, libxl_domain_remus_info *info,
                              uint32_t domid, int send_fd, int recv_fd,
@@ -761,10 +786,15 @@ 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 */
+    /* Convenience aliases */
+    libxl__remus_state *const rs = &dss->rs;
+    rs->ao = ao;
+    rs->domid = domid;
+    rs->saved_rc = 0;
+    rs->callback = libxl__remus_setup_done;
 
     /* Point of no return */
-    libxl__domain_suspend(egc, dss);
+    libxl__remus_device_setup(egc, rs);
     return AO_INPROGRESS;
 
  out:
tools/libxl/libxl.h +6 -0
index 459557d..0fb1aad 100644
@@ -565,6 +565,12 @@ typedef struct libxl__ctx libxl_ctx;
  */
 #define LIBXL_HAVE_CPUPOOL_NAME 1
 
+/*
+ * LIBXL_HAVE_REMUS
+ * If this is defined, then libxl supports remus.
+ */
+#define LIBXL_HAVE_REMUS 1
+
 typedef uint8_t libxl_mac[6];
 #define LIBXL_MAC_FMT "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx"
 #define LIBXL_MAC_FMTLEN ((2*6)+5) /* 6 hex bytes plus 5 colons */
tools/libxl/libxl_dom.c +118 -14

181 lines not on this page · raw message

tools/libxl/libxl_internal.h +184 -0

196 lines not on this page · raw message

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

379 lines not on this page · raw message

tools/libxl/libxl_types.idl +1 -0
index de25f42..e56567f 100644
@@ -44,6 +44,7 @@ libxl_error = Enumeration("error", [
     (-12, "OSEVENT_REG_FAIL"),
     (-13, "BUFFERFULL"),
     (-14, "UNKNOWN_CHILD"),
+    (-15, "REMUS_DEVOPS_NOT_MATCH"),
     ], value_namespace = "")
 
 libxl_domain_type = Enumeration("domain_type", [
Signature · 1 line
1.9.1
#3 lore raw

Re: [PATCH v15 2/7] remus: introduce remus device

Yang Hongyang writes ("[PATCH v15 2/7] remus: introduce remus device"):

Quoted 10 lines

introduce remus device, an abstract layer of remus devices(nic, disk, etc).It provides the following APIs for libxl:

Quoted 1 line

libxl__remus_device_setup

setup remus devices, like attach qdisc, enable disk buffering, etc

Quoted 1 line

libxl__remus_device_teardown

teardown devices

Quoted 3 lines

libxl__remus_device_postsuspend
libxl__remus_device_preresume
libxl__remus_device_commit

above three are for checkpoint.

Sorry to mention this now, but I think it would be clearer if all these libxl__remus_device_* functions which manipulate _all_ the devices for a domain used the plural of "device", ie libxl__remus_devices_setup, etc.

Quoted 7 lines
tools/libxl/libxl.c +0 -0
index 39f1c28..bcbd02b 100644
@@ -733,6 +733,31 @@ out:
 static void remus_failover_cb(libxl__egc *egc,
                               libxl__domain_suspend_state *dss, int rc);

tools/libxl/libxl.c out: · line 744

Quoted 10 lines
tools/libxl/libxl.c +9 -0
 
+static void libxl__remus_setup_failed(libxl__egc *egc,
+                                      libxl__remus_state *rs, int rc)
+{
+    STATE_AO_GC(rs->ao);
+    libxl__ao_complete(egc, ao, rc);
+}
+
+static void libxl__remus_setup_done(libxl__egc *egc,
+                                    libxl__remus_state *rs, int rc)

This callback appears after the code which sets it up, which naturally executes first. Things should be in chronological order, as I said.

tools/libxl/libxl.c out: · line 755

Quoted 11 lines
tools/libxl/libxl.c +11 -0
+{
+    libxl__domain_suspend_state *dss = CONTAINER_OF(rs, *dss, rs);
+    STATE_AO_GC(rs->ao);
+
+    if (!rc) {
+        libxl__domain_suspend(egc, dss);
+        return;
+    }
+
+    LOG(ERROR, "Remus: failed to setup device for guest with domid %u",
+        dss->domid);

This log message should report the rc.

tools/libxl/libxl_dom.c static void libxl__domain_suspend_callback(void *data) · line 1459

Quoted 11 lines
tools/libxl/libxl_dom.c +3 -0
index 83eb29a..8cc90dc 100644
@@ -1454,6 +1454,17 @@ static void libxl__domain_suspend_callback(void *data)
     domain_suspend_callback_common(egc, dss);
 }
 
+static void remus_device_postsuspend_cb(libxl__egc *egc,
+                                        libxl__remus_state *rs, int rc)
+{

I can't quite tell, but isn't this code not in chronological order ?

Quoted 4 lines
tools/libxl/libxl_internal.h +0 -0
index f8441f6..8ef20a0 100644

...

Quoted 4 lines

+/*
+ * This structure is for remus device layer, it records remus devices
+ * that have been setuped.
+ */

Still lots of uses of "setuped". Correct would be "devices that have been set up".

tools/libxl/libxl_internal.h

Quoted 8 lines
tools/libxl/libxl_internal.h +8 -0
+/*----- checkpointing APIs -----*/
+
+/* callbacks */
+
+static void device_common_cb(libxl__egc *egc,
+                             libxl__remus_device *dev,
+                             int rc)
+{

I asked for things to be in chronological order in the file. I think this function therefore ought to be below these checkpoint functions.

Also its name isn't very suggestive. Perhaps it should have "checkpoint" in the name ?

Quoted 3 lines
tools/libxl/libxl_internal.h +3 -0
+/* API implementations */
+
+void libxl__remus_device_postsuspend(libxl__egc *egc, libxl__remus_state *rs)

...

Quoted 1 line

+void libxl__remus_device_preresume(libxl__egc *egc, libxl__remus_state *rs)

...

Quoted 1 line

+void libxl__remus_device_commit(libxl__egc *egc, libxl__remus_state *rs)

These three functions are nearly identical. They should be combined somehow. Perhaps there should be a single function which takes the offset of the per-device operation vtable member as a parameter. Or perhaps the three functions should be generated by a macro. Currently I'm leaning towards the former.

Quoted 1 line

+ if(rds->num_set_up == 0)

         ^

Coding style.

tools/libxl/libxl_internal.h

Quoted 9 lines
tools/libxl/libxl_internal.h +9 -0
+    for (i = 0; i < rds->num_set_up; i++) {
+        dev = rds->dev[i];
+        dev->callback = device_common_cb;
+        if (dev->ops->commit) {
+            dev->ops->commit(dev);
+        } else {
+            rds->num_devices++;
+            if (rds->num_devices == rds->num_set_up)
+                rs->callback(egc, rs, rs->saved_rc);

Why not have this call device_common_cb rather than open-coding it ?

Quoted 1 line

+/*----- main flow of control -----*/

This is for setup, right ? Or teardown ? Or both ?

tools/libxl/libxl_internal.h

Quoted 9 lines
tools/libxl/libxl_internal.h +9 -0
+/* callbacks */
+
+static void device_setup_cb(libxl__egc *egc,
+                            libxl__remus_device *dev,
+                            int rc);
+static void device_match_cb(libxl__egc *egc,
+                            libxl__remus_device *dev,
+                            int rc)
+{

This is still not in chronological order. You must put callbacks after the things that set them up, since obviously the callback happens after it is set up.

Seeing things in the wrong order makes it hard to see what's going on. In the interests of trying to reduce the number of iterations of this series I'm going to do a kind of peephole review of what I see here; you should bear in mind that I'm not always trying to understand what the purpose of these functions is so I may have structural comments on your next version.

tools/libxl/libxl_internal.h

Quoted 7 lines
tools/libxl/libxl_internal.h +7 -0
+    libxl__remus_device_state *const rds = dev->rds;
+    libxl__remus_state *rs = CONTAINER_OF(rds, *rs, dev_state);
+
+    STATE_AO_GC(rs->ao);
+
+    if (rc) {
+        if (++dev->ops_index >= ARRAY_SIZE(dev_ops) ||

This use of ++ looks confusing to me.

tools/libxl/libxl_internal.h

Quoted 4 lines
tools/libxl/libxl_internal.h +4 -0
+            rc != ERROR_REMUS_DEVOPS_NOT_MATCH) {
+            /* the device can not be matched */
+            rds->num_devices++;
+            rs->saved_rc = ERROR_FAIL;

Please can we not return more ERROR_FAIL. Instead, why not return ERROR_REMUS_DEVICE_NOT_SUPPORTED as I suggested before ?

tools/libxl/libxl_internal.h

Quoted 13 lines
tools/libxl/libxl_internal.h +13 -0
+    rds->num_devices++;
+    /*
+     * we add devices that have been setuped to the array no matter
+     * the setup process succeed or failed because we need to ensure
+     * the device been teardown while setup failed. If any of the
+     * device setup failed, we will quit remus, but before we exit,
+     * we will teardown the devices that have been added to **dev
+     */
+    rds->dev[rds->num_set_up++] = dev;
+    if (rc) {
+        /* setup failed */
+        rs->saved_rc = ERROR_FAIL;
+    }

This doesn't look right. If the setup fails, presumably we shouldn't put the device in the array ? If we do it will presumably be torn down later.

tools/libxl/libxl_internal.h

Quoted 12 lines
tools/libxl/libxl_internal.h +12 -0
+static void destroy_device_ops(libxl__remus_state *rs);
+static void device_teardown_cb(libxl__egc *egc,
+                               libxl__remus_device *dev,
+                               int rc)
+{
+    libxl__remus_device_state *const rds = dev->rds;
+    libxl__remus_state *rs = CONTAINER_OF(rds, *rs, dev_state);
+
+    STATE_AO_GC(rs->ao);
+
+    /* ignore teardown errors to teardown as many devs as possible*/
+    rds->num_set_up--;

We should at least preserve the rc so that we don't pretend that everything worked if it didn't.

You may need to invent a new teardown rc variable, and/or add logging, so that you get the right error code out, and the right log messages, if a setup fails and causes a teardown which also fails.

tools/libxl/libxl_internal.h

Quoted 9 lines
tools/libxl/libxl_internal.h +9 -0
+static int init_device_ops(libxl__remus_state *rs)
+{
+    int i, rc;
+    const libxl__remus_device_ops *ops;
+
+    for (i = 0; i < ARRAY_SIZE(dev_ops); i++) {
+        ops = dev_ops[i];
+        if (ops->init(ops, rs)) {
+            rc = ERROR_FAIL;

In general, you should preserve the rc, not turn everything into ERROR_FAIL.

I still don't understand why libxl__remus_device_state is not part of libxl__remus_state.

I wonder if you need a different name for "the abstract thing which is represented by a libxl__remus_device_ops". Since each ops only deals with one kind (but perhaps a kind may have several ops), I suggest calling them "subkind"s or "devsubkinds" or something. At the moment you seem to be calling them "ops".

As a result I think this function is poorly named. It doesn't initialise any ops. It initialises each subkind. Perhaps it should be called init_device_subkind.

You might consider whether libxl__remus_device_ops should be libxl__remus_subkind_ops perhaps or libxl__remus_devsubkind_ops or libxl__remus_device_subkind_ops.

tools/libxl/libxl_internal.h

Quoted 9 lines
tools/libxl/libxl_internal.h +9 -0
+void libxl__remus_device_setup(libxl__egc *egc, libxl__remus_state *rs)
+{
+    STATE_AO_GC(rs->ao);
+
+    /* Convenience aliases */
+    libxl__remus_device_state *const rds = &rs->dev_state;
+
+    if (ARRAY_SIZE(dev_ops) == 0)
+        goto out;

Why is this special case necessary ?

tools/libxl/libxl_types.idl libxl_error = Enumeration("error", [ · line 47

Quoted 9 lines
tools/libxl/libxl_types.idl +1 -0
index de25f42..e56567f 100644
@@ -44,6 +44,7 @@ libxl_error = Enumeration("error", [
     (-12, "OSEVENT_REG_FAIL"),
     (-13, "BUFFERFULL"),
     (-14, "UNKNOWN_CHILD"),
+    (-15, "REMUS_DEVOPS_NOT_MATCH"),

I don't object to this name for this exact case and it's fine to have a specific error code.

But if you are going to make the whole machinery return ERROR_REMUS_DEVICE_NOT_SUPPORTED if no subkind matches, then you can reuse that error code for the subkind methods.

Thanks,
Ian.

#4 lore raw

Re: [PATCH v15 2/7] remus: introduce remus device

Quoted 12 lines · Ian Jackson

Yang Hongyang writes ("[PATCH v15 2/7] remus: introduce remus device"):

Quoted 10 lines

introduce remus device, an abstract layer of remus devices(nic, disk, etc).It provides the following APIs for libxl:

Quoted 1 line

libxl__remus_device_setup

setup remus devices, like attach qdisc, enable disk buffering, etc

Quoted 1 line

libxl__remus_device_teardown

teardown devices

Quoted 3 lines

libxl__remus_device_postsuspend
libxl__remus_device_preresume
libxl__remus_device_commit

above three are for checkpoint.

Quoted 4 lines

Sorry to mention this now, but I think it would be clearer if all these libxl__remus_device_* functions which manipulate _all_ the devices for a domain used the plural of "device", ie libxl__remus_devices_setup, etc.

Ok

Quoted 63 lines
Quoted 8 lines
tools/libxl/libxl.c +0 -0
index 39f1c28..bcbd02b 100644
@@ -733,6 +733,31 @@ out:
  static void remus_failover_cb(libxl__egc *egc,
                                libxl__domain_suspend_state *dss, int rc);

tools/libxl/libxl.c out: · line 744

Quoted 10 lines
tools/libxl/libxl.c +9 -0
 
+static void libxl__remus_setup_failed(libxl__egc *egc,
+                                      libxl__remus_state *rs, int rc)
+{
+    STATE_AO_GC(rs->ao);
+    libxl__ao_complete(egc, ao, rc);
+}
+
+static void libxl__remus_setup_done(libxl__egc *egc,
+                                    libxl__remus_state *rs, int rc)

This callback appears after the code which sets it up, which naturally executes first. Things should be in chronological order, as I said.

tools/libxl/libxl.c out: · line 755

Quoted 11 lines
tools/libxl/libxl.c +11 -0
+{
+    libxl__domain_suspend_state *dss = CONTAINER_OF(rs, *dss, rs);
+    STATE_AO_GC(rs->ao);
+
+    if (!rc) {
+        libxl__domain_suspend(egc, dss);
+        return;
+    }
+
+    LOG(ERROR, "Remus: failed to setup device for guest with domid %u",
+        dss->domid);

This log message should report the rc.

tools/libxl/libxl_dom.c static void libxl__domain_suspend_callback(void *data) · line 1459

Quoted 11 lines
tools/libxl/libxl_dom.c +3 -0
index 83eb29a..8cc90dc 100644
@@ -1454,6 +1454,17 @@ static void libxl__domain_suspend_callback(void *data)
      domain_suspend_callback_common(egc, dss);
  }
 
+static void remus_device_postsuspend_cb(libxl__egc *egc,
+                                        libxl__remus_state *rs, int rc)
+{

I can't quite tell, but isn't this code not in chronological order ?

Quoted 4 lines
tools/libxl/libxl_internal.h +0 -0
index f8441f6..8ef20a0 100644

...

Quoted 4 lines

+/*
+ * This structure is for remus device layer, it records remus devices
+ * that have been setuped.
+ */

Still lots of uses of "setuped". Correct would be "devices that have been set up".

Quoted 11 lines

tools/libxl/libxl_internal.h

Quoted 8 lines
tools/libxl/libxl_internal.h +8 -0
+/*----- checkpointing APIs -----*/
+
+/* callbacks */
+
+static void device_common_cb(libxl__egc *egc,
+                             libxl__remus_device *dev,
+                             int rc)
+{

I asked for things to be in chronological order in the file. I think this function therefore ought to be below these checkpoint functions.

I used to thought that the definitions of callbacks should be before the functions that set them, sorry for the misunderstanding, I will correct them.

Quoted 9 lines

Also its name isn't very suggestive. Perhaps it should have "checkpoint" in the name ?

Quoted 3 lines
tools/libxl/libxl_internal.h +3 -0
+/* API implementations */
+
+void libxl__remus_device_postsuspend(libxl__egc *egc, libxl__remus_state *rs)

...

Quoted 1 line

+void libxl__remus_device_preresume(libxl__egc *egc, libxl__remus_state *rs)

Quoted 8 lines

...

Quoted 1 line

+void libxl__remus_device_commit(libxl__egc *egc, libxl__remus_state *rs)

These three functions are nearly identical. They should be combined somehow. Perhaps there should be a single function which takes the offset of the per-device operation vtable member as a parameter. Or perhaps the three functions should be generated by a macro. Currently I'm leaning towards the former.

Good suggestions

Quoted 15 lines
Quoted 2 lines

+ if(rds->num_set_up == 0)

          ^

Coding style.

tools/libxl/libxl_internal.h

Quoted 9 lines
tools/libxl/libxl_internal.h +9 -0
+    for (i = 0; i < rds->num_set_up; i++) {
+        dev = rds->dev[i];
+        dev->callback = device_common_cb;
+        if (dev->ops->commit) {
+            dev->ops->commit(dev);
+        } else {
+            rds->num_devices++;
+            if (rds->num_devices == rds->num_set_up)
+                rs->callback(egc, rs, rs->saved_rc);
Quoted 1 line

Why not have this call device_common_cb rather than open-coding it ?

Sorry for the poor named function, device_common_cb should be used at checkpoint. will add checkpoint to the function name.

Quoted 19 lines
Quoted 2 lines

+/*----- main flow of control -----*/

This is for setup, right ? Or teardown ? Or both ?

tools/libxl/libxl_internal.h

Quoted 9 lines
tools/libxl/libxl_internal.h +9 -0
+/* callbacks */
+
+static void device_setup_cb(libxl__egc *egc,
+                            libxl__remus_device *dev,
+                            int rc);
+static void device_match_cb(libxl__egc *egc,
+                            libxl__remus_device *dev,
+                            int rc)
+{

This is still not in chronological order. You must put callbacks after the things that set them up, since obviously the callback happens after it is set up.

Quoted 6 lines

Seeing things in the wrong order makes it hard to see what's going on. In the interests of trying to reduce the number of iterations of this series I'm going to do a kind of peephole review of what I see here; you should bear in mind that I'm not always trying to understand what the purpose of these functions is so I may have structural comments on your next version.

Ok, just don't quite follow the meaning of chronological order, but it's more clearer for me now.

Quoted 11 lines

tools/libxl/libxl_internal.h

Quoted 8 lines
tools/libxl/libxl_internal.h +7 -0
+    libxl__remus_device_state *const rds = dev->rds;
+    libxl__remus_state *rs = CONTAINER_OF(rds, *rs, dev_state);
+
+    STATE_AO_GC(rs->ao);
+
+    if (rc) {
+        if (++dev->ops_index >= ARRAY_SIZE(dev_ops) ||

This use of ++ looks confusing to me.

Quoted 7 lines

tools/libxl/libxl_internal.h

Quoted 4 lines
tools/libxl/libxl_internal.h +4 -0
+            rc != ERROR_REMUS_DEVOPS_NOT_MATCH) {
+            /* the device can not be matched */
+            rds->num_devices++;
+            rs->saved_rc = ERROR_FAIL;

Please can we not return more ERROR_FAIL. Instead, why not return ERROR_REMUS_DEVICE_NOT_SUPPORTED as I suggested before ?

I will add this error code.

Quoted 15 lines
Quoted 4 lines
tools/libxl/libxl_internal.h +3 -0
+    rds->num_devices++;
+    /*
+     * we add devices that have been setuped to the array no matter

tools/libxl/libxl_internal.h

Quoted 10 lines
tools/libxl/libxl_internal.h +10 -0
+     * the setup process succeed or failed because we need to ensure
+     * the device been teardown while setup failed. If any of the
+     * device setup failed, we will quit remus, but before we exit,
+     * we will teardown the devices that have been added to **dev
+     */
+    rds->dev[rds->num_set_up++] = dev;
+    if (rc) {
+        /* setup failed */
+        rs->saved_rc = ERROR_FAIL;
+    }
Quoted 3 lines

This doesn't look right. If the setup fails, presumably we shouldn't put the device in the array ? If we do it will presumably be torn down later.

the netbuf script was designed as below:
1. when setup failed, the script won't teardown the device itself.
2. the teardown op is ok to be excute many times.

In the remus device layer, if one device setup failed(whether script exit or the script get killed or something), we will quit remus, but before that, we will teardown all device that has been set up, whether it's correctly set up or not. So if we don't put the device in the array, we will get a leaked device, that has not been teardown.

Quoted 17 lines

tools/libxl/libxl_internal.h

Quoted 13 lines
tools/libxl/libxl_internal.h +12 -0
+static void destroy_device_ops(libxl__remus_state *rs);
+static void device_teardown_cb(libxl__egc *egc,
+                               libxl__remus_device *dev,
+                               int rc)
+{
+    libxl__remus_device_state *const rds = dev->rds;
+    libxl__remus_state *rs = CONTAINER_OF(rds, *rs, dev_state);
+
+    STATE_AO_GC(rs->ao);
+
+    /* ignore teardown errors to teardown as many devs as possible*/
+    rds->num_set_up--;

We should at least preserve the rc so that we don't pretend that everything worked if it didn't.

Quoted 3 lines

You may need to invent a new teardown rc variable, and/or add logging, so that you get the right error code out, and the right log messages, if a setup fails and causes a teardown which also fails.

Ok, thanks.

Quoted 13 lines

tools/libxl/libxl_internal.h

Quoted 10 lines
tools/libxl/libxl_internal.h +9 -0
+static int init_device_ops(libxl__remus_state *rs)
+{
+    int i, rc;
+    const libxl__remus_device_ops *ops;
+
+    for (i = 0; i < ARRAY_SIZE(dev_ops); i++) {
+        ops = dev_ops[i];
+        if (ops->init(ops, rs)) {
+            rc = ERROR_FAIL;

In general, you should preserve the rc, not turn everything into ERROR_FAIL.

Ok, thanks.

Quoted 3 lines

I still don't understand why libxl__remus_device_state is not part of libxl__remus_state.

libxl__remus_device_state is part of libxl__remus_state:
+struct libxl__remus_state {

+    /* must set by caller of libxl__remus_device_(setup|teardown) */
+    libxl__ao *ao;
+    uint32_t domid;
+    libxl__remus_callback *callback;
+
+    /* private */
+    int saved_rc;
+    /* context containing device related stuff */
+    libxl__remus_device_state dev_state;
     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

+
+ libxl__ev_time timeout; /* used for checkpoint */
+};

Quoted 7 lines

I wonder if you need a different name for "the abstract thing which is represented by a libxl__remus_device_ops". Since each ops only deals with one kind (but perhaps a kind may have several ops), I suggest calling them "subkind"s or "devsubkinds" or something. At the moment you seem to be calling them "ops".

Quoted 7 lines

As a result I think this function is poorly named. It doesn't initialise any ops. It initialises each subkind. Perhaps it should be called init_device_subkind.

You might consider whether libxl__remus_device_ops should be libxl__remus_subkind_ops perhaps or libxl__remus_devsubkind_ops or libxl__remus_device_subkind_ops.

Ok, thanks.

Quoted 26 lines

tools/libxl/libxl_internal.h

Quoted 10 lines
tools/libxl/libxl_internal.h +9 -0
+void libxl__remus_device_setup(libxl__egc *egc, libxl__remus_state *rs)
+{
+    STATE_AO_GC(rs->ao);
+
+    /* Convenience aliases */
+    libxl__remus_device_state *const rds = &rs->dev_state;
+
+    if (ARRAY_SIZE(dev_ops) == 0)
+        goto out;

Why is this special case necessary ?

tools/libxl/libxl_types.idl libxl_error = Enumeration("error", [ · line 47

Quoted 9 lines
tools/libxl/libxl_types.idl +1 -0
index de25f42..e56567f 100644
@@ -44,6 +44,7 @@ libxl_error = Enumeration("error", [
      (-12, "OSEVENT_REG_FAIL"),
      (-13, "BUFFERFULL"),
      (-14, "UNKNOWN_CHILD"),
+    (-15, "REMUS_DEVOPS_NOT_MATCH"),

I don't object to this name for this exact case and it's fine to have a specific error code.

Quoted 3 lines

But if you are going to make the whole machinery return ERROR_REMUS_DEVICE_NOT_SUPPORTED if no subkind matches, then you can reuse that error code for the subkind methods.

Will add ERROR_REMUS_DEVICE_NOT_SUPPORTED error code.

Quoted 5 lines

Thanks,
Ian.
.

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

Re: [PATCH v15 2/7] remus: introduce remus device

Hongyang Yang writes ("Re: [PATCH v15 2/7] remus: introduce remus device"):

Quoted 7 lines · Ian Jackson
Quoted 4 lines

Sorry to mention this now, but I think it would be clearer if all these libxl__remus_device_* functions which manipulate _all_ the devices for a domain used the plural of "device", ie libxl__remus_devices_setup, etc.

Ok

Thanks. You may find git-filter-branch helpful to do this easily. (Be careful not to blow your leg off.)

Quoted 14 lines
Quoted 14 lines
Quoted 13 lines
tools/libxl/libxl_remus_device.c new file +13 -0
+    rds->num_devices++;
+    /*
+     * we add devices that have been setuped to the array no matter
+     * the setup process succeed or failed because we need to ensure
+     * the device been teardown while setup failed. If any of the
+     * device setup failed, we will quit remus, but before we exit,
+     * we will teardown the devices that have been added to **dev
+     */
+    rds->dev[rds->num_set_up++] = dev;
+    if (rc) {
+        /* setup failed */
+        rs->saved_rc = ERROR_FAIL;
+    }
Quoted 7 lines
Quoted 3 lines

This doesn't look right. If the setup fails, presumably we shouldn't put the device in the array ? If we do it will presumably be torn down later.

the netbuf script was designed as below:
1. when setup failed, the script won't teardown the device itself.
2. the teardown op is ok to be excute many times.

Aha. Right.

I think you should state exactly that, probably in a comment here and also in the script itself. This can replace the comment you have above, which is rather vague.

Quoted 6 lines

In the remus device layer, if one device setup failed(whether script exit or the script get killed or something), we will quit remus, but before that, we will teardown all device that has been set up, whether it's correctly set up or not. So if we don't put the device in the array, we will get a leaked device, that has not been teardown.

That makes sense.

Quoted 5 lines
Quoted 2 lines

I still don't understand why libxl__remus_device_state is not part of libxl__remus_state.

libxl__remus_device_state is part of libxl__remus_state:
+struct libxl__remus_state {

...

Quoted 2 lines
+    libxl__remus_device_state dev_state;
      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

I meant: why is it a separate structure, rather than the contents simply being included there ?

Thanks for your other replies. You don't seem to have replied to everything I said, including some questions I asked. Do you intend to, later, perhaps ?

Thanks,
Ian.

#6 lore raw

Re: [PATCH v15 2/7] remus: introduce remus device

Quoted 11 lines · Ian Jackson

Hongyang Yang writes ("Re: [PATCH v15 2/7] remus: introduce remus device"):

Quoted 7 lines · Ian Jackson
Quoted 4 lines

Sorry to mention this now, but I think it would be clearer if all these libxl__remus_device_* functions which manipulate _all_ the devices for a domain used the plural of "device", ie libxl__remus_devices_setup, etc.

Ok

Thanks. You may find git-filter-branch helpful to do this easily. (Be careful not to blow your leg off.)

Thanks for the tip.

Quoted 41 lines
Quoted 15 lines
Quoted 15 lines
Quoted 14 lines
tools/libxl/libxl_remus_device.c new file +13 -0
+    rds->num_devices++;
+    /*
+     * we add devices that have been setuped to the array no matter
+     * the setup process succeed or failed because we need to ensure
+     * the device been teardown while setup failed. If any of the
+     * device setup failed, we will quit remus, but before we exit,
+     * we will teardown the devices that have been added to **dev
+     */
+    rds->dev[rds->num_set_up++] = dev;
+    if (rc) {
+        /* setup failed */
+        rs->saved_rc = ERROR_FAIL;
+    }
Quoted 7 lines
Quoted 3 lines

This doesn't look right. If the setup fails, presumably we shouldn't put the device in the array ? If we do it will presumably be torn down later.

the netbuf script was designed as below:
1. when setup failed, the script won't teardown the device itself.
2. the teardown op is ok to be excute many times.

Aha. Right.

I think you should state exactly that, probably in a comment here and also in the script itself. This can replace the comment you have above, which is rather vague.

Quoted 6 lines

In the remus device layer, if one device setup failed(whether script exit or the script get killed or something), we will quit remus, but before that, we will teardown all device that has been set up, whether it's correctly set up or not. So if we don't put the device in the array, we will get a leaked device, that has not been teardown.

That makes sense.

Quoted 3 lines
Quoted 2 lines

I still don't understand why libxl__remus_device_state is not part of libxl__remus_state.

Quoted 9 lines
Quoted 2 lines

libxl__remus_device_state is part of libxl__remus_state:
+struct libxl__remus_state {

...

Quoted 2 lines
+    libxl__remus_device_state dev_state;
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

I meant: why is it a separate structure, rather than the contents simply being included there ?

Err, I thought I've replied on the last thread about this, but I will reply here.
I intend to use libxl__remus_state on upper layer, that is, in the main flow of libxl layer, and use libxl__remus_device_state in both remus abstract layer and concrete layer. I thought that will make things more clear. But yes, there still some libxl__remus_state use in remus abstract layer and concrete layer, I will fix it up in the next version.

Quoted 4 lines

Thanks for your other replies. You don't seem to have replied to everything I said, including some questions I asked. Do you intend to, later, perhaps ?

Sorry, I might have missed some of your comments or questions, but that's not what I was intend to...I was trying to reply every question you've pointed out. I will go back and go through your comments carefully.

Quoted 5 lines

Thanks,
Ian.
.

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

Re: [PATCH v15 2/7] remus: introduce remus device

Quoted 68 lines · Hongyang Yang
Quoted 11 lines · Ian Jackson

Hongyang Yang writes ("Re: [PATCH v15 2/7] remus: introduce remus device"):

Quoted 7 lines · Ian Jackson
Quoted 4 lines

Sorry to mention this now, but I think it would be clearer if all these libxl__remus_device_* functions which manipulate _all_ the devices for a domain used the plural of "device", ie libxl__remus_devices_setup, etc.

Ok

Thanks. You may find git-filter-branch helpful to do this easily. (Be careful not to blow your leg off.)

Thanks for the tip.

Quoted 41 lines
Quoted 15 lines
Quoted 15 lines
Quoted 14 lines
tools/libxl/libxl_remus_device.c new file +13 -0
+    rds->num_devices++;
+    /*
+     * we add devices that have been setuped to the array no matter
+     * the setup process succeed or failed because we need to ensure
+     * the device been teardown while setup failed. If any of the
+     * device setup failed, we will quit remus, but before we exit,
+     * we will teardown the devices that have been added to **dev
+     */
+    rds->dev[rds->num_set_up++] = dev;
+    if (rc) {
+        /* setup failed */
+        rs->saved_rc = ERROR_FAIL;
+    }
Quoted 7 lines
Quoted 3 lines

This doesn't look right. If the setup fails, presumably we shouldn't put the device in the array ? If we do it will presumably be torn down later.

the netbuf script was designed as below:
1. when setup failed, the script won't teardown the device itself.
2. the teardown op is ok to be excute many times.

Aha. Right.

I think you should state exactly that, probably in a comment here and also in the script itself. This can replace the comment you have above, which is rather vague.

Quoted 6 lines

In the remus device layer, if one device setup failed(whether script exit or the script get killed or something), we will quit remus, but before that, we will teardown all device that has been set up, whether it's correctly set up or not. So if we don't put the device in the array, we will get a leaked device, that has not been teardown.

That makes sense.

Quoted 3 lines
Quoted 2 lines

I still don't understand why libxl__remus_device_state is not part of libxl__remus_state.

Quoted 9 lines
Quoted 2 lines

libxl__remus_device_state is part of libxl__remus_state:
+struct libxl__remus_state {

...

Quoted 2 lines
+    libxl__remus_device_state dev_state;
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

I meant: why is it a separate structure, rather than the contents simply being included there ?

Quoted 8 lines

Err, I thought I've replied on the last thread about this, but I will reply here.
I intend to use libxl__remus_state on upper layer, that is, in the main flow of libxl layer, and use libxl__remus_device_state in both remus abstract layer and concrete layer. I thought that will make things more clear. But yes, there still some libxl__remus_state use in remus abstract layer and concrete layer, I will fix it up in the next version.

I reconsidered about this case, most part of libxl__remus_state can be merged into libxl__remus_device_state, there's only one left:
libxl__ev_time timeout; /* used for checkpoint */
but I think this can be moved to libxl__domain_suspend_state just like interval for remus:
struct libxl__domain_suspend_state {
...snip...
const char *dm_savefile;
int interval; /* checkpoint interval (for Remus) */
+ libxl__ev_time checkpoint_timeout; /* used for remus checkpoint */
...snip...
};

So, I'll merge libxl__remus_state into libxl__remus_device_state.

Quoted 16 lines
Quoted 5 lines

Thanks for your other replies. You don't seem to have replied to everything I said, including some questions I asked. Do you intend to, later, perhaps ?

Sorry, I might have missed some of your comments or questions, but that's not what I was intend to...I was trying to reply every question you've pointed out. I will go back and go through your comments carefully.

Quoted 5 lines

Thanks,
Ian.
.

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

Re: [PATCH v15 2/7] remus: introduce remus device

In reply to Ian Jackson
Quoted 38 lines · Ian Jackson

Yang Hongyang writes ("[PATCH v15 2/7] remus: introduce remus device"):

Quoted 10 lines

introduce remus device, an abstract layer of remus devices(nic, disk, etc).It provides the following APIs for libxl:

Quoted 1 line

libxl__remus_device_setup

setup remus devices, like attach qdisc, enable disk buffering, etc

Quoted 1 line

libxl__remus_device_teardown

teardown devices

Quoted 3 lines

libxl__remus_device_postsuspend
libxl__remus_device_preresume
libxl__remus_device_commit

above three are for checkpoint.

Sorry to mention this now, but I think it would be clearer if all these libxl__remus_device_* functions which manipulate _all_ the devices for a domain used the plural of "device", ie libxl__remus_devices_setup, etc.

Quoted 7 lines
tools/libxl/libxl.c +0 -0
index 39f1c28..bcbd02b 100644
@@ -733,6 +733,31 @@ out:
  static void remus_failover_cb(libxl__egc *egc,
                                libxl__domain_suspend_state *dss, int rc);

tools/libxl/libxl.c out: · line 744

Quoted 10 lines
tools/libxl/libxl.c +9 -0
 
+static void libxl__remus_setup_failed(libxl__egc *egc,
+                                      libxl__remus_state *rs, int rc)
+{
+    STATE_AO_GC(rs->ao);
+    libxl__ao_complete(egc, ao, rc);
+}
+
+static void libxl__remus_setup_done(libxl__egc *egc,
+                                    libxl__remus_state *rs, int rc)

This callback appears after the code which sets it up, which naturally executes first. Things should be in chronological order, as I said.

Quoted 13 lines

tools/libxl/libxl.c out: · line 755

Quoted 11 lines
tools/libxl/libxl.c +11 -0
+{
+    libxl__domain_suspend_state *dss = CONTAINER_OF(rs, *dss, rs);
+    STATE_AO_GC(rs->ao);
+
+    if (!rc) {
+        libxl__domain_suspend(egc, dss);
+        return;
+    }
+
+    LOG(ERROR, "Remus: failed to setup device for guest with domid %u",
+        dss->domid);

This log message should report the rc.

Ok, thanks.

Quoted 40 lines

tools/libxl/libxl_dom.c static void libxl__domain_suspend_callback(void *data) · line 1459

Quoted 12 lines
tools/libxl/libxl_dom.c +3 -0
index 83eb29a..8cc90dc 100644
@@ -1454,6 +1454,17 @@ static void libxl__domain_suspend_callback(void *data)
      domain_suspend_callback_common(egc, dss);
  }
 
+static void remus_device_postsuspend_cb(libxl__egc *egc,
+                                        libxl__remus_state *rs, int rc)
+{

I can't quite tell, but isn't this code not in chronological order ?

Quoted 4 lines
tools/libxl/libxl_internal.h +0 -0
index f8441f6..8ef20a0 100644

...

Quoted 4 lines

+/*
+ * This structure is for remus device layer, it records remus devices
+ * that have been setuped.
+ */

Still lots of uses of "setuped". Correct would be "devices that have been set up".

tools/libxl/libxl_internal.h

Quoted 8 lines
tools/libxl/libxl_internal.h +8 -0
+/*----- checkpointing APIs -----*/
+
+/* callbacks */
+
+static void device_common_cb(libxl__egc *egc,
+                             libxl__remus_device *dev,
+                             int rc)
+{

I asked for things to be in chronological order in the file. I think this function therefore ought to be below these checkpoint functions.

Quoted 2 lines

Also its name isn't very suggestive. Perhaps it should have "checkpoint" in the name ?

Yes, I shall put "checkpoint" in the name.

Quoted 29 lines
Quoted 4 lines
tools/libxl/libxl_internal.h +3 -0
+/* API implementations */
+
+void libxl__remus_device_postsuspend(libxl__egc *egc, libxl__remus_state *rs)

...

Quoted 1 line

+void libxl__remus_device_preresume(libxl__egc *egc, libxl__remus_state *rs)

...

Quoted 1 line

+void libxl__remus_device_commit(libxl__egc *egc, libxl__remus_state *rs)

These three functions are nearly identical. They should be combined somehow. Perhaps there should be a single function which takes the offset of the per-device operation vtable member as a parameter. Or perhaps the three functions should be generated by a macro. Currently I'm leaning towards the former.

Quoted 1 line

+ if(rds->num_set_up == 0)

          ^

Coding style.

tools/libxl/libxl_internal.h

Quoted 9 lines
tools/libxl/libxl_internal.h +9 -0
+    for (i = 0; i < rds->num_set_up; i++) {
+        dev = rds->dev[i];
+        dev->callback = device_common_cb;
+        if (dev->ops->commit) {
+            dev->ops->commit(dev);
+        } else {
+            rds->num_devices++;
+            if (rds->num_devices == rds->num_set_up)
+                rs->callback(egc, rs, rs->saved_rc);
Quoted 5 lines

Why not have this call device_common_cb rather than open-coding it ?

Quoted 1 line

+/*----- main flow of control -----*/

This is for setup, right ? Or teardown ? Or both ?

setup and teardown, will change this comment.

Quoted 108 lines

tools/libxl/libxl_internal.h

Quoted 10 lines
tools/libxl/libxl_internal.h +9 -0
+/* callbacks */
+
+static void device_setup_cb(libxl__egc *egc,
+                            libxl__remus_device *dev,
+                            int rc);
+static void device_match_cb(libxl__egc *egc,
+                            libxl__remus_device *dev,
+                            int rc)
+{

This is still not in chronological order. You must put callbacks after the things that set them up, since obviously the callback happens after it is set up.

Seeing things in the wrong order makes it hard to see what's going on. In the interests of trying to reduce the number of iterations of this series I'm going to do a kind of peephole review of what I see here; you should bear in mind that I'm not always trying to understand what the purpose of these functions is so I may have structural comments on your next version.

tools/libxl/libxl_internal.h

Quoted 7 lines
tools/libxl/libxl_internal.h +7 -0
+    libxl__remus_device_state *const rds = dev->rds;
+    libxl__remus_state *rs = CONTAINER_OF(rds, *rs, dev_state);
+
+    STATE_AO_GC(rs->ao);
+
+    if (rc) {
+        if (++dev->ops_index >= ARRAY_SIZE(dev_ops) ||

This use of ++ looks confusing to me.

tools/libxl/libxl_internal.h

Quoted 4 lines
tools/libxl/libxl_internal.h +4 -0
+            rc != ERROR_REMUS_DEVOPS_NOT_MATCH) {
+            /* the device can not be matched */
+            rds->num_devices++;
+            rs->saved_rc = ERROR_FAIL;

Please can we not return more ERROR_FAIL. Instead, why not return ERROR_REMUS_DEVICE_NOT_SUPPORTED as I suggested before ?

tools/libxl/libxl_internal.h

Quoted 13 lines
tools/libxl/libxl_internal.h +13 -0
+    rds->num_devices++;
+    /*
+     * we add devices that have been setuped to the array no matter
+     * the setup process succeed or failed because we need to ensure
+     * the device been teardown while setup failed. If any of the
+     * device setup failed, we will quit remus, but before we exit,
+     * we will teardown the devices that have been added to **dev
+     */
+    rds->dev[rds->num_set_up++] = dev;
+    if (rc) {
+        /* setup failed */
+        rs->saved_rc = ERROR_FAIL;
+    }

This doesn't look right. If the setup fails, presumably we shouldn't put the device in the array ? If we do it will presumably be torn down later.

tools/libxl/libxl_internal.h

Quoted 12 lines
tools/libxl/libxl_internal.h +12 -0
+static void destroy_device_ops(libxl__remus_state *rs);
+static void device_teardown_cb(libxl__egc *egc,
+                               libxl__remus_device *dev,
+                               int rc)
+{
+    libxl__remus_device_state *const rds = dev->rds;
+    libxl__remus_state *rs = CONTAINER_OF(rds, *rs, dev_state);
+
+    STATE_AO_GC(rs->ao);
+
+    /* ignore teardown errors to teardown as many devs as possible*/
+    rds->num_set_up--;

We should at least preserve the rc so that we don't pretend that everything worked if it didn't.

You may need to invent a new teardown rc variable, and/or add logging, so that you get the right error code out, and the right log messages, if a setup fails and causes a teardown which also fails.

tools/libxl/libxl_internal.h

Quoted 9 lines
tools/libxl/libxl_internal.h +9 -0
+static int init_device_ops(libxl__remus_state *rs)
+{
+    int i, rc;
+    const libxl__remus_device_ops *ops;
+
+    for (i = 0; i < ARRAY_SIZE(dev_ops); i++) {
+        ops = dev_ops[i];
+        if (ops->init(ops, rs)) {
+            rc = ERROR_FAIL;

In general, you should preserve the rc, not turn everything into ERROR_FAIL.

I still don't understand why libxl__remus_device_state is not part of libxl__remus_state.

I wonder if you need a different name for "the abstract thing which is represented by a libxl__remus_device_ops". Since each ops only deals with one kind (but perhaps a kind may have several ops), I suggest calling them "subkind"s or "devsubkinds" or something. At the moment you seem to be calling them "ops".

As a result I think this function is poorly named. It doesn't initialise any ops. It initialises each subkind. Perhaps it should be called init_device_subkind.

You might consider whether libxl__remus_device_ops should be libxl__remus_subkind_ops perhaps or libxl__remus_devsubkind_ops or libxl__remus_device_subkind_ops.

Quoted 11 lines

tools/libxl/libxl_internal.h

Quoted 9 lines
tools/libxl/libxl_internal.h +9 -0
+void libxl__remus_device_setup(libxl__egc *egc, libxl__remus_state *rs)
+{
+    STATE_AO_GC(rs->ao);
+
+    /* Convenience aliases */
+    libxl__remus_device_state *const rds = &rs->dev_state;
+
+    if (ARRAY_SIZE(dev_ops) == 0)
+        goto out;

Why is this special case necessary ?

This means there're no ops present, the following process of setup are unnecessary, so we just goto out and return.

Quoted 22 lines

tools/libxl/libxl_types.idl libxl_error = Enumeration("error", [ · line 47

Quoted 10 lines
tools/libxl/libxl_types.idl +1 -0
index de25f42..e56567f 100644
@@ -44,6 +44,7 @@ libxl_error = Enumeration("error", [
      (-12, "OSEVENT_REG_FAIL"),
      (-13, "BUFFERFULL"),
      (-14, "UNKNOWN_CHILD"),
+    (-15, "REMUS_DEVOPS_NOT_MATCH"),

I don't object to this name for this exact case and it's fine to have a specific error code.

But if you are going to make the whole machinery return ERROR_REMUS_DEVICE_NOT_SUPPORTED if no subkind matches, then you can reuse that error code for the subkind methods.

Thanks,
Ian.
.

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

PATCH v15 3/7 remus netbuffer: implement remus network buffering for nic devices

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 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)

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

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.
3.Implement the remus device interface. setup, teardown, etc. The
checkpoint callbacks for netbuffer are implemented as sync op because net ops are quick enough and will not block.

---
 docs/misc/xenstore-paths.markdown      |   4 +
 tools/hotplug/Linux/Makefile           |   1 +
 tools/hotplug/Linux/remus-netbuf-setup | 203 ++++++++++++++
 tools/libxl/libxl.c                    |  21 +-
 tools/libxl/libxl_internal.h           |  10 +
 tools/libxl/libxl_netbuffer.c          | 475 +++++++++++++++++++++++++++++++++
 tools/libxl/libxl_nonetbuffer.c        |  27 ++
 tools/libxl/libxl_remus_device.c       |  21 +-
 tools/libxl/libxl_types.idl            |   2 +
 9 files changed, 759 insertions(+), 5 deletions(-)
 create mode 100644 tools/hotplug/Linux/remus-netbuf-setup
docs/misc/xenstore-paths.markdown +4 -0
index ea67536..d94ea9d 100644
@@ -393,6 +393,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 d5de9e6..721f8c0 100644
@@ -16,6 +16,7 @@ XEN_SCRIPTS += 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 +203 -0

203 lines not on this page · raw message

tools/libxl/libxl.c +18 -3
index bcbd02b..b7d62c1 100644
@@ -788,6 +788,24 @@ int libxl_domain_remus_start(libxl_ctx *ctx, libxl_domain_remus_info *info,
 
     /* Convenience aliases */
     libxl__remus_state *const rs = &dss->rs;
+
+    /* Setup network buffering */
+    if (info->netbuf) {
+        if (!libxl__netbuffer_enabled(gc)) {
+            LOG(ERROR, "Remus: No support for network buffering");
+            goto out;
+        }
+
+        if (info->netbufscript) {
+            rs->netbufscript =
+                libxl__strdup(gc, info->netbufscript);
+        } else {
+            rs->netbufscript =
+                GCSPRINTF("%s/remus-netbuf-setup",
+                libxl__xen_script_dir_path());
+        }
+    }
+
     rs->ao = ao;
     rs->domid = domid;
     rs->saved_rc = 0;
@@ -811,9 +829,6 @@ static void remus_failover_cb(libxl__egc *egc,
      * from sending checkpoints.
      */
 
-    /* TBD: Remus cleanup - i.e. detach qdisc, release other
-     * resources.
-     */
     libxl__ao_complete(egc, ao, rc);
 }
 
tools/libxl/libxl_internal.h +10 -0
index 8ef20a0..2fe36a6 100644
@@ -310,6 +310,10 @@ struct libxl__gc {
     libxl_ctx *owner;
 };
 
+/* remus device ops specific structures start */
+typedef struct libxl__remus_netbuf_state libxl__remus_netbuf_state;
+/* remus device ops specific structures end */
+
 struct libxl__ctx {
     xentoollog_logger *lg;
     xc_interface *xch;
@@ -374,6 +378,9 @@ struct libxl__ctx {
     LIBXL_LIST_ENTRY(libxl_ctx) sigchld_users_entry;
 
     libxl_version_info version_info;
+
+    /* remus device ops specific structures */
+    libxl__remus_netbuf_state *rns;
 };
 
 typedef struct {
@@ -2576,6 +2583,7 @@ struct libxl__remus_device_state {
     /* devices that have been setuped */
     libxl__remus_device **dev;
 
+    libxl_device_nic *nics;
     int num_nics;
     int num_disks;
 
@@ -2631,6 +2639,8 @@ struct libxl__remus_state {
     libxl__ao *ao;
     uint32_t domid;
     libxl__remus_callback *callback;
+    /* Script to setup/teardown network buffers */
+    const char *netbufscript;
 
     /* private */
     int saved_rc;
tools/libxl/libxl_netbuffer.c +475 -0

486 lines not on this page · raw message

tools/libxl/libxl_nonetbuffer.c +27 -0
index 1c72a7f..5390274 100644
@@ -22,6 +22,33 @@ int libxl__netbuffer_enabled(libxl__gc *gc)
     return 0;
 }
 
+static void nic_match(const libxl__remus_device_ops *self,
+                      libxl__remus_device *dev)
+{
+    STATE_AO_GC(dev->rds->ao);
+
+    dev->callback(dev->rds->egc, dev, ERROR_FAIL);
+}
+
+static int nic_init(const libxl__remus_device_ops *self,
+                    libxl__remus_state *rs)
+{
+    return 0;
+}
+
+static void nic_destroy(const libxl__remus_device_ops *self,
+                        libxl__remus_state *rs)
+{
+    return;
+}
+
+const libxl__remus_device_ops remus_device_nic = {
+    .kind = LIBXL__REMUS_DEVICE_NIC,
+    .init = nic_init,
+    .destroy = nic_destroy,
+    .match = nic_match,
+};
+
 /*
  * Local variables:
  * mode: C
tools/libxl/libxl_remus_device.c +19 -2
index cd71242..5ef11b9 100644
@@ -17,7 +17,9 @@
 
 #include "libxl_internal.h"
 
+extern const libxl__remus_device_ops remus_device_nic;
 static const libxl__remus_device_ops *dev_ops[] = {
+    &remus_device_nic,
 };
 
 /*----- checkpointing APIs -----*/
@@ -227,6 +229,7 @@ static void device_teardown_cb(libxl__egc *egc,
                                libxl__remus_device *dev,
                                int rc)
 {
+    int i;
     libxl__remus_device_state *const rds = dev->rds;
     libxl__remus_state *rs = CONTAINER_OF(rds, *rs, dev_state);
 
@@ -236,6 +239,13 @@ static void device_teardown_cb(libxl__egc *egc,
     rds->num_set_up--;
 
     if (rds->num_set_up == 0) {
+        /* clean nic */
+        for (i = 0; i < rds->num_nics; i++)
+            libxl_device_nic_dispose(&rds->nics[i]);
+        free(rds->nics);
+        rds->nics = NULL;
+        rds->num_nics = 0;
+
         destroy_device_ops(rs);
         rs->callback(egc, rs, rs->saved_rc);
     }
@@ -243,7 +253,7 @@ static void device_teardown_cb(libxl__egc *egc,
 
 /* remus device setup and teardown */
 
-static __attribute__((unused)) void libxl__remus_device_init(libxl__egc *egc,
+static void libxl__remus_device_init(libxl__egc *egc,
                                      libxl__remus_device_state *rds,
                                      libxl__remus_device_kind kind,
                                      void *libxl_dev)
@@ -314,6 +324,7 @@ static void destroy_device_ops(libxl__remus_state *rs)
 
 void libxl__remus_device_setup(libxl__egc *egc, libxl__remus_state *rs)
 {
+    int i;
     STATE_AO_GC(rs->ao);
 
     /* Convenience aliases */
@@ -332,7 +343,9 @@ void libxl__remus_device_setup(libxl__egc *egc, libxl__remus_state *rs)
     rds->num_nics = 0;
     rds->num_disks = 0;
 
-    /* TBD: Remus setup - i.e. attach qdisc, enable disk buffering, etc */
+    /* TBD: Remus setup - i.e. enable disk buffering, etc */
+    if (rs->netbufscript)
+        rds->nics = libxl_device_nic_list(CTX, rs->domid, &rds->num_nics);
 
     if (rds->num_nics == 0 && rds->num_disks == 0)
         goto out;
@@ -340,6 +353,10 @@ void libxl__remus_device_setup(libxl__egc *egc, libxl__remus_state *rs)
     GCNEW_ARRAY(rds->dev, rds->num_nics + rds->num_disks);
 
     /* TBD: CALL libxl__remus_device_init to init remus devices */
+    for (i = 0; i < rds->num_nics; i++) {
+        libxl__remus_device_init(egc, rds,
+                                 LIBXL__REMUS_DEVICE_NIC, &rds->nics[i]);
+    }
 
     return;
 
tools/libxl/libxl_types.idl +2 -0
index e56567f..e85a636 100644
@@ -575,6 +575,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.9.1
#10 lore raw

Re: [PATCH v15 3/7] remus netbuffer: implement remus network buffering for nic devices

Yang Hongyang writes ("[PATCH v15 3/7] remus netbuffer: implement remus network buffering for nic devices"):

Quoted 9 lines
tools/hotplug/Linux/remus-netbuf-setup new file +3 -0
new file mode 100644
index 0000000..58c46f3
@@ -0,0 +1,203 @@
+#!/bin/bash
+#============================================================================
+# ${XEN_SCRIPT_DIR}/remus-netbuf-setup

...

Quoted 1 line

+# IFB ifb interface to be cleaned up (required). [for teardown op only]

It occurs to me to ask: Is it wise to use such a bare name for the variable IFB ? I would suggest that it might be better to use a variable with XEN or REMUS or something in it. Otherwise perhaps someone somewhere might think IFB stood for something else and would set it to something irrelevant (or your setting of it might break their usage...)

I had some other comments about this script in v10, which we were having a conversation about. I'm afraid I seem to have dropped the thread of that. I will reply separately in that thread.

Quoted 5 lines
tools/libxl/libxl.c +0 -0
index bcbd02b..b7d62c1 100644
@@ -788,6 +788,24 @@ int libxl_domain_remus_start(libxl_ctx *ctx, libxl_domain_remus_info *info,

...

Quoted 1 line

+ /* Setup network buffering */

This comment is misleading. This code doesn't actually set up any network buffering. It doesn't call the setup script. All it does is some checks and computing the script path.

It would probably be better to simply remove the comment. Or you could replace it with something more accurate.

tools/libxl/libxl_internal.h struct libxl__gc { · line 315

Quoted 11 lines
tools/libxl/libxl_internal.h +3 -0
index 8ef20a0..2fe36a6 100644
@@ -310,6 +310,10 @@ struct libxl__gc {
     libxl_ctx *owner;
 };
 
+/* remus device ops specific structures start */
+typedef struct libxl__remus_netbuf_state libxl__remus_netbuf_state;
+/* remus device ops specific structures end */

I don't think these comments add anything. You should move these struct typedefs alongside the other struct typedefs (libxl__ao et al). There is then no need to comment what they are.

tools/libxl/libxl_internal.h struct libxl__ctx { · line 383

Quoted 10 lines
tools/libxl/libxl_internal.h +3 -0
 struct libxl__ctx {
     xentoollog_logger *lg;
     xc_interface *xch;
@@ -374,6 +378,9 @@ struct libxl__ctx {
     LIBXL_LIST_ENTRY(libxl_ctx) sigchld_users_entry;
 
     libxl_version_info version_info;
+
+    /* remus device ops specific structures */
+    libxl__remus_netbuf_state *rns;

Again, I think this comment adds nothing that isn't in the type name. There is no need to say in a comment anything that is plain from the code.

But before you delete it (and other comments that I'm going to quibble about), please wait for a comment from the other tools maintainer, Ian Campbell, who may disagree.

tools/libxl/libxl_internal.h struct libxl__remus_state { · line 2643

Quoted 6 lines
tools/libxl/libxl_internal.h +2 -0
@@ -2631,6 +2639,8 @@ struct libxl__remus_state {
     libxl__ao *ao;
     uint32_t domid;
     libxl__remus_callback *callback;
+    /* Script to setup/teardown network buffers */
+    const char *netbufscript;

And again.

Quoted 10 lines
tools/libxl/libxl_netbuffer.c +2 -0
index 52d593c..025ee89 100644
@@ -17,11 +17,486 @@
 
 #include "libxl_internal.h"
 
+#include <netlink/cache.h>
+#include <netlink/socket.h>

tools/libxl/libxl_netbuffer.c line 31

Quoted 10 lines
tools/libxl/libxl_netbuffer.c +10 -0
+#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>
+
+struct libxl__remus_netbuf_state {
+    libxl__ao *ao;
+    uint32_t domid;
+    const char *netbufscript;

Why is there a copy of netbufscript here ?

tools/libxl/libxl_netbuffer.c line 53

Quoted 5 lines
tools/libxl/libxl_netbuffer.c +5 -0
+/*----- init() and destroy() -----*/
+
+static int nic_init(const libxl__remus_device_ops *self,
+                    libxl__remus_state *rs)
+{

This function seems to leak the things it allocates, on error. The `out' section should probably call destroy.

tools/libxl/libxl_netbuffer.c line 66

Quoted 5 lines
tools/libxl/libxl_netbuffer.c +5 -0
+    ns->nlsock = nl_socket_alloc();
+    if (!ns->nlsock) {
+        LOG(ERROR, "cannot allocate nl socket");
+        goto out;
+    }

Last time I commented on the error handling in this patch. I see that you have added an nl_geterror in some places.

When I make a comment like that, you need to apply it whereever relevant in the code, and to the whole patch series.

Quoted 2 lines
tools/libxl/libxl_netbuffer.c +2 -0
+static void nic_destroy(const libxl__remus_device_ops *self,
+                        libxl__remus_state *rs)

...

tools/libxl/libxl_netbuffer.c line 105

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

Can these functions fail ? If so, what does it mean and what should the program do ?

tools/libxl/libxl_netbuffer.c line 119

Quoted 3 lines
tools/libxl/libxl_netbuffer.c +3 -0
+/*----- checkpointing APIs -----*/
+
+/* The buffer_op's value, not the value passed to kernel */

I would say "The value of buffer_op, not the value passed to kernel".

tools/libxl/libxl_netbuffer.c line 138

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 rc;
+
+    STATE_AO_GC(netbuf_state->ao);
+
+    if (buffer_op == tc_buffer_start)
+        rc = rtnl_qdisc_plug_buffer(remus_nic->qdisc);
+    else
+        rc = rtnl_qdisc_plug_release_one(remus_nic->qdisc);

Error handling again.

Also do not put anything other than a libxl error code in a variable called "rc".

Quoted 13 lines
tools/libxl/libxl_netbuffer.c +13 -0
+/*----- main flow of control -----*/
+
+/* helper functions */
+
+/*
+ * If the device has a vifname, then use that instead of
+ * the vifX.Y format.
+ * it must ONLY be used for remus because if driver domains
+ * were in use it would constitute a security vulnerability.
+ */
+static const char *get_vifname(libxl__remus_device *dev,
+                               const libxl_device_nic *nic)
+{

...

tools/libxl/libxl_netbuffer.c line 205

Quoted 2 lines
tools/libxl/libxl_netbuffer.c +2 -0
+    path = libxl__sprintf(gc, "%s/backend/vif/%d/%d/vifname",
+                          libxl__xs_get_dompath(gc, 0), domid, nic->devid);

Please use GCSPRINTF where applicable.

tools/libxl/libxl_netbuffer.c line 208

Quoted 3 lines
tools/libxl/libxl_netbuffer.c +3 -0
+    rc = libxl__xs_read_checked(gc, XBT_NULL, path, &vifname);
+    if (!rc && !vifname) {
+        /* use the default name */

This comment adds nothing to the comment above.

tools/libxl/libxl_netbuffer.c line 261

Quoted 9 lines
tools/libxl/libxl_netbuffer.c +8 -0
+        vifname = libxl__device_nic_devname(gc, domid,
+                                            nic->devid,
+                                            nic->nictype);
 
+    rc = ERROR_FAIL;
+    ifindex = rtnl_link_get_ifindex(ifb);
+    if (!ifindex) {
+        LOG(ERROR, "interface %s has no index", remus_nic->ifb);
+        goto out;

How does rtnl_link_get_ifindex report its error code ? Or can it fail only one way ?

tools/libxl/libxl_netbuffer.c line 279

Quoted 8 lines
tools/libxl/libxl_netbuffer.c +8 -0
+    qdisc = rtnl_qdisc_get_by_parent(netbuf_state->qdisc_cache, ifindex,
+                                     TC_H_ROOT);
+
+    if (qdisc) {
+        const char *tc_kind = rtnl_tc_get_kind(TC_CAST(qdisc));
+        /* Sanity check: Ensure that the root qdisc is a plug qdisc. */
+        if (!tc_kind || strcmp(tc_kind, "plug")) {
+            nl_object_put((struct nl_object *)qdisc);

This freeing of qdisc should be in the `out' section.

You can do this either by arranging that the `out' section is not used at all on successful completion, or by saying something like

    if (rc) {
        if (qdisc) nl_object_put((struct nl_object *)qdisc);
    }

tools/libxl/libxl_netbuffer.c line 286

Quoted 7 lines
tools/libxl/libxl_netbuffer.c +7 -0
+            LOG(ERROR, "plug qdisc is not installed on %s", remus_nic->ifb);
+            goto out;
+        }
+        remus_nic->qdisc = qdisc;
+        rc = 0;
+    } else {
+        LOG(ERROR, "Cannot get qdisc handle from ifb %s", remus_nic->ifb);

This path out of the function seems not to set rc.

... In fact, I see that you initialise rc to ERROR_FAIL above. IMO this is not a good programming paradigm. rc should be set, obviously, on every exit path, at the point the error is generated.

tools/libxl/libxl_netbuffer.c line 304

Quoted 7 lines
tools/libxl/libxl_netbuffer.c +7 -0
+/*
+ * In return, the script writes the name of IFB device (during setup) to be
+ * used for output buffering into XENBUS_PATH/ifb
+ */
+static void netbuf_setup_script_cb(libxl__egc *egc,
+                                   libxl__async_exec_state *aes,
+                                   int status)

This callback is not in chronological order.

I'm afraid I've run out of time now so I'm going to stop here. I hope these comments have been helpful.

Thanks,
Ian.

#11 lore raw

Re: [PATCH v15 3/7] remus netbuffer: implement remus network buffering for nic devices

Quoted 11 lines · Ian Jackson

Yang Hongyang writes ("[PATCH v15 3/7] remus netbuffer: implement remus network buffering for nic devices"):

Quoted 9 lines
tools/hotplug/Linux/remus-netbuf-setup new file +3 -0
new file mode 100644
index 0000000..58c46f3
@@ -0,0 +1,203 @@
+#!/bin/bash
+#============================================================================
+# ${XEN_SCRIPT_DIR}/remus-netbuf-setup

...

Quoted 8 lines
Quoted 1 line

+# IFB ifb interface to be cleaned up (required). [for teardown op only]

It occurs to me to ask: Is it wise to use such a bare name for the variable IFB ? I would suggest that it might be better to use a variable with XEN or REMUS or something in it. Otherwise perhaps someone somewhere might think IFB stood for something else and would set it to something irrelevant (or your setting of it might break their usage...)

Maybe REMUS_IFB?

Quoted 4 lines

I had some other comments about this script in v10, which we were having a conversation about. I'm afraid I seem to have dropped the thread of that. I will reply separately in that thread.

I have replied in that thread.

Quoted 7 lines
Quoted 6 lines
tools/libxl/libxl.c +0 -0
index bcbd02b..b7d62c1 100644
@@ -788,6 +788,24 @@ int libxl_domain_remus_start(libxl_ctx *ctx, libxl_domain_remus_info *info,

...

Quoted 8 lines
Quoted 1 line

+ /* Setup network buffering */

This comment is misleading. This code doesn't actually set up any network buffering. It doesn't call the setup script. All it does is some checks and computing the script path.

It would probably be better to simply remove the comment. Or you could replace it with something more accurate.

Will remove the comment, thanks.

Quoted 53 lines

tools/libxl/libxl_internal.h struct libxl__gc { · line 315

Quoted 12 lines
tools/libxl/libxl_internal.h +3 -0
index 8ef20a0..2fe36a6 100644
@@ -310,6 +310,10 @@ struct libxl__gc {
      libxl_ctx *owner;
  };
 
+/* remus device ops specific structures start */
+typedef struct libxl__remus_netbuf_state libxl__remus_netbuf_state;
+/* remus device ops specific structures end */

I don't think these comments add anything. You should move these struct typedefs alongside the other struct typedefs (libxl__ao et al). There is then no need to comment what they are.

tools/libxl/libxl_internal.h struct libxl__ctx { · line 383

Quoted 10 lines
tools/libxl/libxl_internal.h +3 -0
  struct libxl__ctx {
      xentoollog_logger *lg;
      xc_interface *xch;
@@ -374,6 +378,9 @@ struct libxl__ctx {
      LIBXL_LIST_ENTRY(libxl_ctx) sigchld_users_entry;
 
      libxl_version_info version_info;
+
+    /* remus device ops specific structures */
+    libxl__remus_netbuf_state *rns;

Again, I think this comment adds nothing that isn't in the type name. There is no need to say in a comment anything that is plain from the code.

But before you delete it (and other comments that I'm going to quibble about), please wait for a comment from the other tools maintainer, Ian Campbell, who may disagree.

tools/libxl/libxl_internal.h struct libxl__remus_state { · line 2643

Quoted 6 lines
tools/libxl/libxl_internal.h +2 -0
@@ -2631,6 +2639,8 @@ struct libxl__remus_state {
      libxl__ao *ao;
      uint32_t domid;
      libxl__remus_callback *callback;
+    /* Script to setup/teardown network buffers */
+    const char *netbufscript;

And again.

Quoted 8 lines
tools/libxl/libxl_netbuffer.c +0 -0
index 52d593c..025ee89 100644
@@ -17,11 +17,486 @@
 
  #include "libxl_internal.h"
 
Quoted 14 lines

tools/libxl/libxl_netbuffer.c line 31

Quoted 12 lines
tools/libxl/libxl_netbuffer.c +12 -0
+#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>
+
+struct libxl__remus_netbuf_state {
+    libxl__ao *ao;
+    uint32_t domid;
+    const char *netbufscript;

Why is there a copy of netbufscript here ?

We use netbuf state in device concrete layer, so we made a copy of this.

Quoted 9 lines

tools/libxl/libxl_netbuffer.c line 53

Quoted 6 lines
tools/libxl/libxl_netbuffer.c +5 -0
+/*----- init() and destroy() -----*/
+
+static int nic_init(const libxl__remus_device_ops *self,
+                    libxl__remus_state *rs)
+{

This function seems to leak the things it allocates, on error. The `out' section should probably call destroy.

If this failed, we will call teardown, and in teardown, the nic_destroy will be called.

Quoted 7 lines

tools/libxl/libxl_netbuffer.c line 66

Quoted 6 lines
tools/libxl/libxl_netbuffer.c +5 -0
+    ns->nlsock = nl_socket_alloc();
+    if (!ns->nlsock) {
+        LOG(ERROR, "cannot allocate nl socket");
+        goto out;
+    }
Quoted 5 lines

Last time I commented on the error handling in this patch. I see that you have added an nl_geterror in some places.

When I make a comment like that, you need to apply it whereever relevant in the code, and to the whole patch series.

Yes, actually I've checked the whole patch about this and corrected them. for this special case, nl_socket_alloc() doesn't return an error number, so we can't use nl_geterror, it returns NULL if alloc failed, so I think this error message should be ok.

Quoted 11 lines
Quoted 3 lines
tools/libxl/libxl_netbuffer.c +2 -0
+static void nic_destroy(const libxl__remus_device_ops *self,
+                        libxl__remus_state *rs)

...

tools/libxl/libxl_netbuffer.c line 105

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

Can these functions fail ? If so, what does it mean and what should the program do ?

No, they both return void.

Quoted 6 lines

tools/libxl/libxl_netbuffer.c line 119

Quoted 4 lines
tools/libxl/libxl_netbuffer.c +3 -0
+/*----- checkpointing APIs -----*/
+
+/* The buffer_op's value, not the value passed to kernel */

I would say "The value of buffer_op, not the value passed to kernel".

Ok, thanks.

Quoted 15 lines

tools/libxl/libxl_netbuffer.c line 138

Quoted 13 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 rc;
+
+    STATE_AO_GC(netbuf_state->ao);
+
+    if (buffer_op == tc_buffer_start)
+        rc = rtnl_qdisc_plug_buffer(remus_nic->qdisc);
+    else
+        rc = rtnl_qdisc_plug_release_one(remus_nic->qdisc);

Error handling again.

I can't quite follow you, what's wrong with the error handling in this function except the name of the "rc"?

Quoted 3 lines

Also do not put anything other than a libxl error code in a variable called "rc".

Ok.

Quoted 15 lines
Quoted 14 lines
tools/libxl/libxl_netbuffer.c +13 -0
+/*----- main flow of control -----*/
+
+/* helper functions */
+
+/*
+ * If the device has a vifname, then use that instead of
+ * the vifX.Y format.
+ * it must ONLY be used for remus because if driver domains
+ * were in use it would constitute a security vulnerability.
+ */
+static const char *get_vifname(libxl__remus_device *dev,
+                               const libxl_device_nic *nic)
+{

...

Quoted 4 lines

tools/libxl/libxl_netbuffer.c line 205

Quoted 2 lines
tools/libxl/libxl_netbuffer.c +2 -0
+    path = libxl__sprintf(gc, "%s/backend/vif/%d/%d/vifname",
+                          libxl__xs_get_dompath(gc, 0), domid, nic->devid);

Please use GCSPRINTF where applicable.

Ok, thanks.

Quoted 11 lines

tools/libxl/libxl_netbuffer.c line 208

Quoted 4 lines
tools/libxl/libxl_netbuffer.c +3 -0
+    rc = libxl__xs_read_checked(gc, XBT_NULL, path, &vifname);
+    if (!rc && !vifname) {
+        /* use the default name */

This comment adds nothing to the comment above.

Quoted 3 lines
tools/libxl/libxl_netbuffer.c +3 -0
+        vifname = libxl__device_nic_devname(gc, domid,
+                                            nic->devid,
+                                            nic->nictype);
Quoted 8 lines

tools/libxl/libxl_netbuffer.c line 261

Quoted 5 lines
tools/libxl/libxl_netbuffer.c +5 -0
+    rc = ERROR_FAIL;
+    ifindex = rtnl_link_get_ifindex(ifb);
+    if (!ifindex) {
+        LOG(ERROR, "interface %s has no index", remus_nic->ifb);
+        goto out;

How does rtnl_link_get_ifindex report its error code ? Or can it fail only one way ?

It Returns Interface index or 0 if not set. No error code will be returned.

Quoted 10 lines

tools/libxl/libxl_netbuffer.c line 279

Quoted 9 lines
tools/libxl/libxl_netbuffer.c +8 -0
+    qdisc = rtnl_qdisc_get_by_parent(netbuf_state->qdisc_cache, ifindex,
+                                     TC_H_ROOT);
+
+    if (qdisc) {
+        const char *tc_kind = rtnl_tc_get_kind(TC_CAST(qdisc));
+        /* Sanity check: Ensure that the root qdisc is a plug qdisc. */
+        if (!tc_kind || strcmp(tc_kind, "plug")) {
+            nl_object_put((struct nl_object *)qdisc);
Quoted 7 lines

This freeing of qdisc should be in the `out' section.

You can do this either by arranging that the `out' section is not used at all on successful completion, or by saying something like

     if (rc) {
         if (qdisc) nl_object_put((struct nl_object *)qdisc);
     }

Ok thanks.

Quoted 9 lines

tools/libxl/libxl_netbuffer.c line 286

Quoted 8 lines
tools/libxl/libxl_netbuffer.c +7 -0
+            LOG(ERROR, "plug qdisc is not installed on %s", remus_nic->ifb);
+            goto out;
+        }
+        remus_nic->qdisc = qdisc;
+        rc = 0;
+    } else {
+        LOG(ERROR, "Cannot get qdisc handle from ifb %s", remus_nic->ifb);
Quoted 5 lines

This path out of the function seems not to set rc.

... In fact, I see that you initialise rc to ERROR_FAIL above. IMO this is not a good programming paradigm. rc should be set, obviously, on every exit path, at the point the error is generated.

Ok thanks.

Quoted 11 lines

tools/libxl/libxl_netbuffer.c line 304

Quoted 8 lines
tools/libxl/libxl_netbuffer.c +7 -0
+/*
+ * In return, the script writes the name of IFB device (during setup) to be
+ * used for output buffering into XENBUS_PATH/ifb
+ */
+static void netbuf_setup_script_cb(libxl__egc *egc,
+                                   libxl__async_exec_state *aes,
+                                   int status)

This callback is not in chronological order.

Quoted 2 lines

I'm afraid I've run out of time now so I'm going to stop here. I hope these comments have been helpful.

Thank you for patiently reviewing this.

Quoted 5 lines

Thanks,
Ian.
.

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

Re: [PATCH v15 3/7] remus netbuffer: implement remus network buffering for nic devices

Hongyang Yang writes ("Re: [PATCH v15 3/7] remus netbuffer: implement remus network buffering for nic devices"):

Quoted 9 lines · Ian Jackson
Quoted 6 lines

It occurs to me to ask: Is it wise to use such a bare name for the variable IFB ? I would suggest that it might be better to use a variable with XEN or REMUS or something in it. Otherwise perhaps someone somewhere might think IFB stood for something else and would set it to something irrelevant (or your setting of it might break their usage...)

Maybe REMUS_IFB?

Sounds good to me.

Quoted 9 lines
Quoted 6 lines

tools/libxl/libxl_netbuffer.c line 31

Quoted 4 lines
tools/libxl/libxl_netbuffer.c +4 -0
+struct libxl__remus_netbuf_state {
+    libxl__ao *ao;
+    uint32_t domid;
+    const char *netbufscript;

Why is there a copy of netbufscript here ?

We use netbuf state in device concrete layer, so we made a copy of this.

What I mean is, why does the concrete layer not have access to the remus_state ? Is there something wrong with passing it the remus_state ?

Quoted 11 lines
Quoted 8 lines

tools/libxl/libxl_netbuffer.c line 53

Quoted 5 lines
tools/libxl/libxl_netbuffer.c +5 -0
+/*----- init() and destroy() -----*/
+
+static int nic_init(const libxl__remus_device_ops *self,
+                    libxl__remus_state *rs)
+{

This function seems to leak the things it allocates, on error. The `out' section should probably call destroy.

If this failed, we will call teardown, and in teardown, the nic_destroy will be called.

OIC. I think this needs to be documented in a comment in libxl__remus_device_ops. Normally one wouldn't expect to have to call destroy() if init() fails.

Quoted 10 lines
Quoted 5 lines

Last time I commented on the error handling in this patch. I see that you have added an nl_geterror in some places.

When I make a comment like that, you need to apply it whereever relevant in the code, and to the whole patch series.

Yes, actually I've checked the whole patch about this and corrected them. for this special case, nl_socket_alloc() doesn't return an error number, so we can't use nl_geterror, it returns NULL if alloc failed, so I think this error message should be ok.

Err, OK.

Quoted 8 lines
Quoted 8 lines
Quoted 2 lines
(quoted diff) +2 -0
+static void nic_destroy(const libxl__remus_device_ops *self,
+                        libxl__remus_state *rs)

...

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

Can these functions fail ? If so, what does it mean and what should the program do ?

No, they both return void.

Oh, good.

Quoted 15 lines
Quoted 6 lines
Quoted 6 lines
tools/libxl/libxl_netbuffer.c +6 -0
+static int remus_netbuf_op(libxl__remus_device_nic *remus_nic,
+                           libxl__remus_netbuf_state *netbuf_state,
+                           int buffer_op)
+{
+    int rc;
+
Quoted 8 lines

tools/libxl/libxl_netbuffer.c line 138

Quoted 6 lines
tools/libxl/libxl_netbuffer.c +6 -0
+    STATE_AO_GC(netbuf_state->ao);
+
+    if (buffer_op == tc_buffer_start)
+        rc = rtnl_qdisc_plug_buffer(remus_nic->qdisc);
+    else
+        rc = rtnl_qdisc_plug_release_one(remus_nic->qdisc);

Error handling again.

Quoted 2 lines

I can't quite follow you, what's wrong with the error handling in this function except the name of the "rc"?

In fact reading it again I was confused by the fact that this function doesn't actually return rc. Sorry about that - but I guess this shows why using the conventional names etc. is important.

Quoted 4 lines
Quoted 2 lines

How does rtnl_link_get_ifindex report its error code ? Or can it fail only one way ?

It Returns Interface index or 0 if not set. No error code will be returned.

Oh. The error handling in this rtnl facility you're using does seem rather poor - but of course this isn't your fault. Thanks for clarifying.

Thanks for your comprehensive reply.

Ian.

#13 lore raw

Re: [PATCH v15 3/7] remus netbuffer: implement remus network buffering for nic devices

Quoted 18 lines · Ian Jackson

Hongyang Yang writes ("Re: [PATCH v15 3/7] remus netbuffer: implement remus network buffering for nic devices"):

Quoted 9 lines · Ian Jackson
Quoted 6 lines

It occurs to me to ask: Is it wise to use such a bare name for the variable IFB ? I would suggest that it might be better to use a variable with XEN or REMUS or something in it. Otherwise perhaps someone somewhere might think IFB stood for something else and would set it to something irrelevant (or your setting of it might break their usage...)

Maybe REMUS_IFB?

Sounds good to me.

Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
tools/libxl/libxl_netbuffer.c +4 -0
+struct libxl__remus_netbuf_state {
+    libxl__ao *ao;
+    uint32_t domid;
+    const char *netbufscript;
Quoted 8 lines
Quoted 4 lines
Quoted 1 line

Why is there a copy of netbufscript here ?

We use netbuf state in device concrete layer, so we made a copy of this.

What I mean is, why does the concrete layer not have access to the remus_state ? Is there something wrong with passing it the remus_state ?

I intend to make less connections between layers, but I will rethink about this.

Quoted 81 lines
Quoted 10 lines
Quoted 9 lines

tools/libxl/libxl_netbuffer.c line 53

Quoted 6 lines
tools/libxl/libxl_netbuffer.c +5 -0
+/*----- init() and destroy() -----*/
+
+static int nic_init(const libxl__remus_device_ops *self,
+                    libxl__remus_state *rs)
+{

This function seems to leak the things it allocates, on error. The `out' section should probably call destroy.

Quoted 2 lines

If this failed, we will call teardown, and in teardown, the nic_destroy will be called.

OIC. I think this needs to be documented in a comment in libxl__remus_device_ops. Normally one wouldn't expect to have to call destroy() if init() fails.

Quoted 10 lines
Quoted 5 lines

Last time I commented on the error handling in this patch. I see that you have added an nl_geterror in some places.

When I make a comment like that, you need to apply it whereever relevant in the code, and to the whole patch series.

Yes, actually I've checked the whole patch about this and corrected them. for this special case, nl_socket_alloc() doesn't return an error number, so we can't use nl_geterror, it returns NULL if alloc failed, so I think this error message should be ok.

Err, OK.

Quoted 8 lines
Quoted 8 lines
Quoted 2 lines
(quoted diff) +2 -0
+static void nic_destroy(const libxl__remus_device_ops *self,
+                        libxl__remus_state *rs)

...

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

Can these functions fail ? If so, what does it mean and what should the program do ?

No, they both return void.

Oh, good.

Quoted 15 lines
Quoted 6 lines
Quoted 6 lines
tools/libxl/libxl_netbuffer.c +6 -0
+static int remus_netbuf_op(libxl__remus_device_nic *remus_nic,
+                           libxl__remus_netbuf_state *netbuf_state,
+                           int buffer_op)
+{
+    int rc;
+
Quoted 8 lines

tools/libxl/libxl_netbuffer.c line 138

Quoted 6 lines
tools/libxl/libxl_netbuffer.c +6 -0
+    STATE_AO_GC(netbuf_state->ao);
+
+    if (buffer_op == tc_buffer_start)
+        rc = rtnl_qdisc_plug_buffer(remus_nic->qdisc);
+    else
+        rc = rtnl_qdisc_plug_release_one(remus_nic->qdisc);

Error handling again.

Quoted 2 lines

I can't quite follow you, what's wrong with the error handling in this function except the name of the "rc"?

In fact reading it again I was confused by the fact that this function doesn't actually return rc. Sorry about that - but I guess this shows why using the conventional names etc. is important.

Quoted 4 lines
Quoted 2 lines

How does rtnl_link_get_ifindex report its error code ? Or can it fail only one way ?

It Returns Interface index or 0 if not set. No error code will be returned.

Oh. The error handling in this rtnl facility you're using does seem rather poor - but of course this isn't your fault. Thanks for clarifying.

Thanks for your comprehensive reply.

Ian.
.

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

Re: [PATCH v15 3/7] remus netbuffer: implement remus network buffering for nic devices

In reply to Ian Jackson
Quoted 7 lines · Ian Jackson

Again, I think this comment adds nothing that isn't in the type name. There is no need to say in a comment anything that is plain from the code.

But before you delete it (and other comments that I'm going to quibble about), please wait for a comment from the other tools maintainer, Ian Campbell, who may disagree.

I've not looked at all of them but the random sampling I glanced at did seem unnecessary.

Ian.

#15 lore raw

PATCH v15 4/7 remus drbd: Implement remus drbd replicated 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 |  85 +++++++++++++
 tools/libxl/Makefile                 |   2 +-
 tools/libxl/libxl_internal.h         |   3 +
 tools/libxl/libxl_remus_device.c     |  18 ++-
 tools/libxl/libxl_remus_disk_drbd.c  | 239 +++++++++++++++++++++++++++++++++++
 6 files changed, 345 insertions(+), 3 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 721f8c0..15d1b37 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 +85 -0

85 lines not on this page · raw message

tools/libxl/Makefile +1 -1
index 9c81a59..7a246af 100644
@@ -56,7 +56,7 @@ else
 LIBXL_OBJS-y += libxl_nonetbuffer.o
 endif
 
-LIBXL_OBJS-y += libxl_remus_device.o
+LIBXL_OBJS-y += 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_internal.h +3 -0
index 2fe36a6..2941329 100644
@@ -312,6 +312,7 @@ struct libxl__gc {
 
 /* remus device ops specific structures start */
 typedef struct libxl__remus_netbuf_state libxl__remus_netbuf_state;
+typedef struct libxl__remus_drbd_state libxl__remus_drbd_state;
 /* remus device ops specific structures end */
 
 struct libxl__ctx {
@@ -381,6 +382,7 @@ struct libxl__ctx {
 
     /* remus device ops specific structures */
     libxl__remus_netbuf_state *rns;
+    libxl__remus_drbd_state *drbd_state;
 };
 
 typedef struct {
@@ -2585,6 +2587,7 @@ struct libxl__remus_device_state {
 
     libxl_device_nic *nics;
     int num_nics;
+    libxl_device_disk *disks;
     int num_disks;
 
     /* for counting devices that have been handled */
tools/libxl/libxl_remus_device.c +16 -2
index 5ef11b9..d940de1 100644
@@ -18,8 +18,10 @@
 #include "libxl_internal.h"
 
 extern const libxl__remus_device_ops remus_device_nic;
+extern const libxl__remus_device_ops remus_device_drbd_disk;
 static const libxl__remus_device_ops *dev_ops[] = {
     &remus_device_nic,
+    &remus_device_drbd_disk,
 };
 
 /*----- checkpointing APIs -----*/
@@ -246,6 +248,13 @@ static void device_teardown_cb(libxl__egc *egc,
         rds->nics = NULL;
         rds->num_nics = 0;
 
+        /* clean disk */
+        for (i = 0; i < rds->num_disks; i++)
+            libxl_device_disk_dispose(&rds->disks[i]);
+        free(rds->disks);
+        rds->disks = NULL;
+        rds->num_disks = 0;
+
         destroy_device_ops(rs);
         rs->callback(egc, rs, rs->saved_rc);
     }
@@ -343,21 +352,26 @@ void libxl__remus_device_setup(libxl__egc *egc, libxl__remus_state *rs)
     rds->num_nics = 0;
     rds->num_disks = 0;
 
-    /* TBD: Remus setup - i.e. enable disk buffering, etc */
     if (rs->netbufscript)
         rds->nics = libxl_device_nic_list(CTX, rs->domid, &rds->num_nics);
 
+    rds->disks = libxl_device_disk_list(CTX, rs->domid, &rds->num_disks);
+
     if (rds->num_nics == 0 && rds->num_disks == 0)
         goto out;
 
     GCNEW_ARRAY(rds->dev, rds->num_nics + rds->num_disks);
 
-    /* TBD: CALL libxl__remus_device_init to init remus devices */
     for (i = 0; i < rds->num_nics; i++) {
         libxl__remus_device_init(egc, rds,
                                  LIBXL__REMUS_DEVICE_NIC, &rds->nics[i]);
     }
 
+    for (i = 0; i < rds->num_disks; i++) {
+        libxl__remus_device_init(egc, rds,
+                                 LIBXL__REMUS_DEVICE_DISK, &rds->disks[i]);
+    }
+
     return;
 
 out:
tools/libxl/libxl_remus_disk_drbd.c new file +239 -0

239 lines not on this page · raw message

Signature · 1 line
1.9.1
#16 lore raw

PATCH v15 5/7 libxl: network buffering cmdline switch

In reply to Yang Hongyang

Command line switch to 'xl remus' command.
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 30bd4bf..e9e4a83 100644
@@ -431,7 +431,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.
+     Disk buffering support is limited to drbd disks.
 
 B<OPTIONS>
 
@@ -450,6 +450,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 4c5a5ee..f014306 100644
@@ -44,6 +44,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;
@@ -176,6 +177,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 68df548..b324f34 100644
@@ -7175,8 +7175,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;
@@ -7186,6 +7187,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;
@@ -7197,6 +7204,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) {
@@ -7234,13 +7244,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 4279b9f..3f7520d 100644
@@ -487,6 +487,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.9.1
#17 lore raw

PATCH v15 6/7 libxl: disk buffering cmdline switch

In reply to Yang Hongyang

disk buffering is enabled as default.
add an option "-d" to disable it.

---
 docs/man/xl.pod.1                | 4 ++++
 tools/libxl/libxl.c              | 3 +++
 tools/libxl/libxl_internal.h     | 1 +
 tools/libxl/libxl_remus_device.c | 3 ++-
 tools/libxl/libxl_types.idl      | 1 +
 tools/libxl/xl_cmdimpl.c         | 6 +++++-
 tools/libxl/xl_cmdtable.c        | 1 +
 7 files changed, 17 insertions(+), 2 deletions(-)
docs/man/xl.pod.1 +4 -0
index e9e4a83..547e8a2 100644
@@ -459,6 +459,10 @@ Disable network output buffering.
 Use <netbufscript> to setup network buffering instead of the instead of
 the default (/etc/xen/scripts/remus-netbuf-setup).
 
+=item B<-d>
+
+Disable disk buffering.
+
 =item B<-s> I<sshcommand>
 
 Use <sshcommand> instead of ssh.  String will be passed to sh.
tools/libxl/libxl.c +3 -0
index b7d62c1..331689f 100644
@@ -806,6 +806,9 @@ int libxl_domain_remus_start(libxl_ctx *ctx, libxl_domain_remus_info *info,
         }
     }
 
+    /* Setup disk buffering */
+    rs->diskbuf = info->diskbuf;
+
     rs->ao = ao;
     rs->domid = domid;
     rs->saved_rc = 0;
tools/libxl/libxl_internal.h +1 -0
index 2941329..ebe486b 100644
@@ -2644,6 +2644,7 @@ struct libxl__remus_state {
     libxl__remus_callback *callback;
     /* Script to setup/teardown network buffers */
     const char *netbufscript;
+    bool diskbuf;
 
     /* private */
     int saved_rc;
tools/libxl/libxl_remus_device.c +2 -1
index d940de1..c542833 100644
@@ -355,7 +355,8 @@ void libxl__remus_device_setup(libxl__egc *egc, libxl__remus_state *rs)
     if (rs->netbufscript)
         rds->nics = libxl_device_nic_list(CTX, rs->domid, &rds->num_nics);
 
-    rds->disks = libxl_device_disk_list(CTX, rs->domid, &rds->num_disks);
+    if (rs->diskbuf)
+        rds->disks = libxl_device_disk_list(CTX, rs->domid, &rds->num_disks);
 
     if (rds->num_nics == 0 && rds->num_disks == 0)
         goto out;
tools/libxl/libxl_types.idl +1 -0
index e85a636..1056702 100644
@@ -577,6 +577,7 @@ libxl_domain_remus_info = Struct("domain_remus_info",[
     ("compression",  bool),
     ("netbuf",       bool),
     ("netbufscript", string),
+    ("diskbuf",      bool),
     ])
 
 libxl_event_type = Enumeration("event_type", [
tools/libxl/xl_cmdimpl.c +5 -1
index b324f34..167b65b 100644
@@ -7176,8 +7176,9 @@ int main_remus(int argc, char **argv)
     r_info.blackhole = 0;
     r_info.compression = 1;
     r_info.netbuf = 1;
+    r_info.diskbuf = 1;
 
-    SWITCH_FOREACH_OPT(opt, "buni:s:N:e", NULL, "remus", 2) {
+    SWITCH_FOREACH_OPT(opt, "bundi:s:N:e", NULL, "remus", 2) {
     case 'i':
         r_info.interval = atoi(optarg);
         break;
@@ -7193,6 +7194,9 @@ int main_remus(int argc, char **argv)
     case 'N':
         r_info.netbufscript = optarg;
         break;
+    case 'd':
+        r_info.diskbuf = 0;
+        break;
     case 's':
         ssh_command = optarg;
         break;
tools/libxl/xl_cmdtable.c +1 -0
index 3f7520d..246aa11 100644
@@ -490,6 +490,7 @@ struct cmd_spec cmd_table[] = {
       "-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"
+      "-d                      Disable disk buffering.\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.9.1
#18 lore raw

PATCH v15 7/7 MAINTAINERS: Update maintained files of REMUS

In reply to Yang Hongyang

Update maintained files of REMUS.

---
 MAINTAINERS | 5 +++++
 1 file changed, 5 insertions(+)
MAINTAINERS +5 -0
index 266e47b..9c407dc 100644
@@ -262,6 +262,11 @@ S:	Maintained
 F:	docs/README.remus
 F:	tools/blktap2/drivers/block-remus.c
 F:	tools/blktap2/drivers/hashtable*
+F:	tools/libxl/libxl_remus_*
+F:	tools/libxl/libxl_netbuffer.c
+F:	tools/libxl/libxl_nonetbuffer.c
+F:	tools/hotplug/Linux/remus-netbuf-setup
+F:	tools/hotplug/Linux/block-drbd-probe
 
 SCHEDULING
 M:	George Dunlap <[email protected]>
Signature · 1 line
1.9.1