All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Xen-devel <xen-devel@lists.xen.org>
Cc: Wei Liu <wei.liu2@citrix.com>,
	Ian Campbell <Ian.Campbell@citrix.com>,
	Wen Congyang <wency@cn.fujitsu.com>,
	Andrew Cooper <andrew.cooper3@citrix.com>,
	Ian Jackson <Ian.Jackson@eu.citrix.com>,
	Yang Hongyang <yanghy@cn.fujitsu.com>
Subject: [PATCH v2 24/27] tools/libx{c, l}: Introduce restore_callbacks.checkpoint()
Date: Thu, 9 Jul 2015 19:26:50 +0100	[thread overview]
Message-ID: <1436466413-25867-25-git-send-email-andrew.cooper3@citrix.com> (raw)
In-Reply-To: <1436466413-25867-1-git-send-email-andrew.cooper3@citrix.com>

And call it when a checkpoint record is found in the libxc stream.

Some parts of this patch have been based on patches from the COLO series.

Signed-off-by: Wen Congyang <wency@cn.fujitsu.com>
Signed-off-by: Yang Hongyang <yanghy@cn.fujitsu.com>
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
CC: Ian Campbell <Ian.Campbell@citrix.com>
CC: Ian Jackson <Ian.Jackson@eu.citrix.com>
CC: Wei Liu <wei.liu2@citrix.com>

---
v2: Borrow sufficient fragments from several COLO patches to get
    BROKEN_CHANNEL and checkpoint failover to function.
---
 tools/libxc/include/xenguest.h     |    9 ++++++
 tools/libxc/xc_sr_common.h         |    7 +++--
 tools/libxc/xc_sr_restore.c        |   53 ++++++++++++++++++++++++++----------
 tools/libxl/libxl_save_msgs_gen.pl |    2 +-
 4 files changed, 53 insertions(+), 18 deletions(-)

diff --git a/tools/libxc/include/xenguest.h b/tools/libxc/include/xenguest.h
index 7581263..8799c9f 100644
--- a/tools/libxc/include/xenguest.h
+++ b/tools/libxc/include/xenguest.h
@@ -102,6 +102,15 @@ struct restore_callbacks {
     int (*toolstack_restore)(uint32_t domid, const uint8_t *buf,
             uint32_t size, void* data);
 
+    /* A checkpoint record has been found in the stream.
+     *
+     * returns:
+     * 0: (error)    terminate processing
+     * 1: (success)  continue normally
+     * 2: (failover) failover and resume VM
+     */
+    int (*checkpoint)(void* data);
+
     /* to be provided as the last argument to each callback function */
     void* data;
 };
diff --git a/tools/libxc/xc_sr_common.h b/tools/libxc/xc_sr_common.h
index 08c66db..1f4d4e4 100644
--- a/tools/libxc/xc_sr_common.h
+++ b/tools/libxc/xc_sr_common.h
@@ -130,10 +130,13 @@ struct xc_sr_restore_ops
      * Process an individual record from the stream.  The caller shall take
      * care of processing common records (e.g. END, PAGE_DATA).
      *
-     * @return 0 for success, -1 for failure, or the sentinel value
-     * RECORD_NOT_PROCESSED.
+     * @return 0 for success, -1 for failure, or the following sentinels:
+     *  - RECORD_NOT_PROCESSED
+     *  - BROKEN_CHANNEL: under Remus/COLO, this means master may be dead, and
+     *    a failover is needed.
      */
 #define RECORD_NOT_PROCESSED 1
+#define BROKEN_CHANNEL 2
     int (*process_record)(struct xc_sr_context *ctx, struct xc_sr_record *rec);
 
     /**
diff --git a/tools/libxc/xc_sr_restore.c b/tools/libxc/xc_sr_restore.c
index 9e27dba..c9b5213 100644
--- a/tools/libxc/xc_sr_restore.c
+++ b/tools/libxc/xc_sr_restore.c
@@ -1,5 +1,7 @@
 #include <arpa/inet.h>
 
+#include <assert.h>
+
 #include "xc_sr_common.h"
 
 /*
@@ -472,7 +474,7 @@ static int handle_page_data(struct xc_sr_context *ctx, struct xc_sr_record *rec)
 static int handle_checkpoint(struct xc_sr_context *ctx)
 {
     xc_interface *xch = ctx->xch;
-    int rc = 0;
+    int rc = 0, ret;
     unsigned i;
 
     if ( !ctx->restore.checkpointed )
@@ -482,6 +484,21 @@ static int handle_checkpoint(struct xc_sr_context *ctx)
         goto err;
     }
 
+    ret = ctx->restore.callbacks->checkpoint(ctx->restore.callbacks->data);
+    switch ( ret )
+    {
+    case 1: /* Success */
+        break;
+
+    case 2: /* Failover */
+        rc = BROKEN_CHANNEL;
+        goto err;
+
+    default: /* Other fatal error */
+        rc = -1;
+        goto err;
+    }
+
     if ( ctx->restore.buffer_all_records )
     {
         IPRINTF("All records buffered");
@@ -560,19 +577,6 @@ static int process_record(struct xc_sr_context *ctx, struct xc_sr_record *rec)
     free(rec->data);
     rec->data = NULL;
 
-    if ( rc == RECORD_NOT_PROCESSED )
-    {
-        if ( rec->type & REC_TYPE_OPTIONAL )
-            DPRINTF("Ignoring optional record %#x (%s)",
-                    rec->type, rec_type_to_str(rec->type));
-        else
-        {
-            ERROR("Mandatory record %#x (%s) not handled",
-                  rec->type, rec_type_to_str(rec->type));
-            rc = -1;
-        }
-    }
-
     return rc;
 }
 
@@ -678,7 +682,22 @@ static int restore(struct xc_sr_context *ctx)
         else
         {
             rc = process_record(ctx, &rec);
-            if ( rc )
+            if ( rc == RECORD_NOT_PROCESSED )
+            {
+                if ( rec.type & REC_TYPE_OPTIONAL )
+                    DPRINTF("Ignoring optional record %#x (%s)",
+                            rec.type, rec_type_to_str(rec.type));
+                else
+                {
+                    ERROR("Mandatory record %#x (%s) not handled",
+                          rec.type, rec_type_to_str(rec.type));
+                    rc = -1;
+                    goto err;
+                }
+            }
+            else if ( rc == BROKEN_CHANNEL )
+                goto remus_failover;
+            else if ( rc )
                 goto err;
         }
 
@@ -735,6 +754,10 @@ int xc_domain_restore2(xc_interface *xch, int io_fd, uint32_t dom,
     ctx.restore.checkpointed = checkpointed_stream;
     ctx.restore.callbacks = callbacks;
 
+    /* Sanity checks for callbacks. */
+    if ( checkpointed_stream )
+        assert(callbacks->checkpoint);
+
     IPRINTF("In experimental %s", __func__);
     DPRINTF("fd %d, dom %u, hvm %u, pae %u, superpages %d"
             ", checkpointed_stream %d", io_fd, dom, hvm, pae,
diff --git a/tools/libxl/libxl_save_msgs_gen.pl b/tools/libxl/libxl_save_msgs_gen.pl
index 6b4b65e..825d5cc 100755
--- a/tools/libxl/libxl_save_msgs_gen.pl
+++ b/tools/libxl/libxl_save_msgs_gen.pl
@@ -25,7 +25,7 @@ our @msgs = (
                                                 'unsigned long', 'total'] ],
     [  3, 'scxA',   "suspend", [] ],
     [  4, 'scxA',   "postcopy", [] ],
-    [  5, 'scxA',   "checkpoint", [] ],
+    [  5, 'srcxA',  "checkpoint", [] ],
     [  6, 'scxA',   "switch_qemu_logdirty",  [qw(int domid
                                               unsigned enable)] ],
     #                toolstack_save          done entirely `by hand'
-- 
1.7.10.4

  parent reply	other threads:[~2015-07-09 18:26 UTC|newest]

Thread overview: 65+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-09 18:26 [PATCH v2 00/27] Libxl migration v2 Andrew Cooper
2015-07-09 18:26 ` [PATCH v2 01/27] bsd-sys-queue-h-seddery: Massage `offsetof' Andrew Cooper
2015-07-10  9:32   ` Ian Campbell
2015-07-09 18:26 ` [PATCH v2 02/27] tools/libxc: Always compile the compat qemu variables into xc_sr_context Andrew Cooper
2015-07-09 18:26 ` [PATCH v2 03/27] tools/libxl: Introduce ROUNDUP() Andrew Cooper
2015-07-09 18:26 ` [PATCH v2 04/27] tools/libxl: Introduce libxl__kill() Andrew Cooper
2015-07-10  1:34   ` Yang Hongyang
2015-07-10  8:56     ` Andrew Cooper
2015-07-10  9:08   ` Wei Liu
2015-07-10  9:25     ` Andrew Cooper
2015-07-10  9:34     ` Ian Campbell
2015-07-09 18:26 ` [PATCH v2 05/27] tools/libxl: Stash all restore parameters in domain_create_state Andrew Cooper
2015-07-09 18:26 ` [PATCH v2 06/27] tools/libxl: Split libxl__domain_create_state.restore_fd in two Andrew Cooper
2015-07-10  9:37   ` Ian Campbell
2015-07-09 18:26 ` [PATCH v2 07/27] tools/libxl: Extra management APIs for the save helper Andrew Cooper
2015-07-10  9:41   ` Ian Campbell
2015-07-10  9:52     ` Andrew Cooper
2015-07-09 18:26 ` [PATCH v2 08/27] tools/xl: Mandatory flag indicating the format of the migration stream Andrew Cooper
2015-07-09 18:26 ` [PATCH v2 09/27] docs: Libxl migration v2 stream specification Andrew Cooper
2015-07-10  9:46   ` Ian Campbell
2015-07-09 18:26 ` [PATCH v2 10/27] tools/python: Libxc migration v2 infrastructure Andrew Cooper
2015-07-09 18:26 ` [PATCH v2 11/27] tools/python: Libxl " Andrew Cooper
2015-07-09 18:26 ` [PATCH v2 12/27] tools/python: Other migration infrastructure Andrew Cooper
2015-07-10  9:48   ` Ian Campbell
2015-07-09 18:26 ` [PATCH v2 13/27] tools/python: Verification utility for v2 stream spec compliance Andrew Cooper
2015-07-09 18:26 ` [PATCH v2 14/27] tools/python: Conversion utility for legacy migration streams Andrew Cooper
2015-07-09 18:26 ` [PATCH v2 15/27] tools/libxl: Migration v2 stream format Andrew Cooper
2015-07-10  9:49   ` Ian Campbell
2015-07-09 18:26 ` [PATCH v2 16/27] tools/libxl: Infrastructure for reading a libxl migration v2 stream Andrew Cooper
2015-07-10 10:23   ` Ian Campbell
2015-07-10 10:47     ` Andrew Cooper
2015-07-10 11:16       ` Ian Jackson
2015-07-10 11:25       ` Ian Campbell
2015-07-10 12:28         ` Andrew Cooper
2015-07-10 12:46           ` Ian Jackson
2015-07-10 12:50             ` Andrew Cooper
2015-07-10 12:17   ` Ian Jackson
2015-07-10 12:56     ` Andrew Cooper
2015-07-10 13:09       ` Ian Jackson
2015-07-09 18:26 ` [PATCH v2 17/27] tools/libxl: Support converting a legacy stream to a " Andrew Cooper
2015-07-10 10:28   ` Ian Campbell
2015-07-10 10:39     ` Andrew Cooper
2015-07-10 12:28   ` Ian Jackson
2015-07-09 18:26 ` [PATCH v2 18/27] tools/libxl: Convert a legacy stream if needed Andrew Cooper
2015-07-10 10:31   ` Ian Campbell
2015-07-10 12:41   ` Ian Jackson
2015-07-09 18:26 ` [PATCH v2 19/27] tools/libxc+libxl+xl: Restore v2 streams Andrew Cooper
2015-07-10 10:45   ` Ian Campbell
2015-07-09 18:26 ` [PATCH v2 20/27] tools/libxl: Infrastructure for writing a v2 stream Andrew Cooper
2015-07-10 11:10   ` Ian Campbell
2015-07-09 18:26 ` [PATCH v2 21/27] tools/libxc+libxl+xl: Save v2 streams Andrew Cooper
2015-07-10 10:57   ` Ian Campbell
2015-07-09 18:26 ` [PATCH v2 22/27] docs/libxl: Introduce CHECKPOINT_END to support migration v2 remus streams Andrew Cooper
2015-07-10 10:59   ` Ian Campbell
2015-07-09 18:26 ` [PATCH v2 23/27] tools/libxl: Write checkpoint records into the stream Andrew Cooper
2015-07-10 11:02   ` Ian Campbell
2015-07-10 11:47   ` Wei Liu
2015-07-09 18:26 ` Andrew Cooper [this message]
2015-07-10 11:13   ` [PATCH v2 24/27] tools/libx{c, l}: Introduce restore_callbacks.checkpoint() Ian Campbell
2015-07-09 18:26 ` [PATCH v2 25/27] tools/libxl: Handle checkpoint records in a libxl migration v2 stream Andrew Cooper
2015-07-10 11:18   ` Ian Campbell
2015-07-10 14:34     ` Andrew Cooper
2015-07-09 18:26 ` [PATCH v2 26/27] tools/libxc: Drop all XG_LIBXL_HVM_COMPAT code from libxc Andrew Cooper
2015-07-09 18:26 ` [PATCH v2 27/27] tools/libxl: Drop all knowledge of toolstack callbacks Andrew Cooper
2015-07-10  3:01 ` [PATCH v2 00/27] Libxl migration v2 Yang Hongyang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1436466413-25867-25-git-send-email-andrew.cooper3@citrix.com \
    --to=andrew.cooper3@citrix.com \
    --cc=Ian.Campbell@citrix.com \
    --cc=Ian.Jackson@eu.citrix.com \
    --cc=wei.liu2@citrix.com \
    --cc=wency@cn.fujitsu.com \
    --cc=xen-devel@lists.xen.org \
    --cc=yanghy@cn.fujitsu.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.