xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Yang Hongyang <yanghy@cn.fujitsu.com>, xen-devel@lists.xen.org
Cc: wei.liu2@citrix.com, ian.campbell@citrix.com,
	wency@cn.fujitsu.com, guijianfeng@cn.fujitsu.com,
	yunhong.jiang@intel.com, eddie.dong@intel.com,
	rshriram@cs.ubc.ca, ian.jackson@eu.citrix.com
Subject: Re: [PATCH v6 COLO 04/15] libxc/restore: support COLO restore
Date: Mon, 8 Jun 2015 11:39:59 +0100	[thread overview]
Message-ID: <557570FF.10901@citrix.com> (raw)
In-Reply-To: <1433735159-26739-5-git-send-email-yanghy@cn.fujitsu.com>

On 08/06/15 04:45, Yang Hongyang wrote:
> call the callbacks resume/checkpoint/suspend while secondary vm
> status is consistent with primary.
>
> Signed-off-by: Yang Hongyang <yanghy@cn.fujitsu.com>
> Signed-off-by: Wen Congyang <wency@cn.fujitsu.com>
> CC: Andrew Cooper <andrew.cooper3@citrix.com>
> ---
>  tools/libxc/xc_sr_common.h          | 11 +++++--
>  tools/libxc/xc_sr_restore.c         | 63 ++++++++++++++++++++++++++++++++++++-
>  tools/libxc/xc_sr_restore_x86_hvm.c |  1 +
>  3 files changed, 72 insertions(+), 3 deletions(-)
>
> diff --git a/tools/libxc/xc_sr_common.h b/tools/libxc/xc_sr_common.h
> index 565c5da..382bf76 100644
> --- a/tools/libxc/xc_sr_common.h
> +++ b/tools/libxc/xc_sr_common.h
> @@ -132,8 +132,11 @@ struct xc_sr_restore_ops
>       *
>       * @return 0 for success, -1 for failure, or the sentinel value
>       * RECORD_NOT_PROCESSED.
> +     * BROKEN_CHANNEL: if we are under Remus/COLO, this means master may dead,
> +     *                 we will failover.

"this means that the master"

>       */
>  #define RECORD_NOT_PROCESSED 1
> +#define BROKEN_CHANNEL 2
>      int (*process_record)(struct xc_sr_context *ctx, struct xc_sr_record *rec);
>  
>      /**
> @@ -205,8 +208,12 @@ struct xc_sr_context
>              uint32_t guest_type;
>              uint32_t guest_page_size;
>  
> -            /* Plain VM, or checkpoints over time. */
> -            bool checkpointed;
> +            /*
> +             * 0: Plain VM
> +             * 1: Remus
> +             * 2: COLO
> +             */
> +            int checkpointed;

I think this would be nicer as

enum {
STREAM_PLAIN,
STREAM_REMUS,
STREAM_COLO,
} stream;

perhaps?  It would reduce the use of a magic 2 in the code.

>  
>              /* Currently buffering records between a checkpoint */
>              bool buffer_all_records;
> diff --git a/tools/libxc/xc_sr_restore.c b/tools/libxc/xc_sr_restore.c
> index 2d2edd3..982a70e 100644
> --- a/tools/libxc/xc_sr_restore.c
> +++ b/tools/libxc/xc_sr_restore.c
> @@ -1,4 +1,5 @@
>  #include <arpa/inet.h>
> +#include <assert.h>
>  
>  #include "xc_sr_common.h"
>  
> @@ -472,7 +473,7 @@ static int process_record(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 )
> @@ -498,6 +499,46 @@ static int handle_checkpoint(struct xc_sr_context *ctx)
>      else
>          ctx->restore.buffer_all_records = true;
>  
> +    if ( ctx->restore.checkpointed == 2 )
> +    {
> +#define HANDLE_CALLBACK_RETURN_VALUE(ret)                   \

I would ideally like to avoid macros like this in an effort to avoid the
code slipping back into the state that the legacy code was in, but at
least it is local to the area used.

> +    do {                                                    \
> +        if ( ret == 0 )                                     \
> +        {                                                   \
> +            /* Some internal error happens */               \
> +            rc = -1;                                        \
> +            goto err;                                       \
> +        }                                                   \
> +        else if ( ret == 2 )                                \
> +        {                                                   \
> +            /* Reading/writing error, do failover */        \
> +            rc = BROKEN_CHANNEL;                            \
> +            goto err;                                       \
> +        }                                                   \
> +    } while (0)

This should have the logic inverted somewhat, to cover all possible
values of ret, including the negative half.

e.g.

if ( ret == 1 )
    rc = 0; /* Success */
else
{
    if ( ret == 2 )
        rc = BROKEN_CHANNEL;
    else
        rc = -1; /* Some unspecified error */
    goto err;
}

> +
> +        /* COLO */
> +
> +        /* We need to resume guest */
> +        rc = ctx->restore.ops.stream_complete(ctx);
> +        if ( rc )
> +            goto err;
> +
> +        /* TODO: call restore_results */
> +
> +        /* Resume secondary vm */
> +        ret = ctx->restore.callbacks->postcopy(ctx->restore.callbacks->data);
> +        HANDLE_CALLBACK_RETURN_VALUE(ret);
> +
> +        /* wait for new checkpoint */
> +        ret = ctx->restore.callbacks->checkpoint(ctx->restore.callbacks->data);
> +        HANDLE_CALLBACK_RETURN_VALUE(ret);
> +
> +        /* suspend secondary vm */
> +        ret = ctx->restore.callbacks->suspend(ctx->restore.callbacks->data);
> +        HANDLE_CALLBACK_RETURN_VALUE(ret);

Please #undef HANDLE_CALLBACK_RETURN_VALUE here.

> +    }
> +
>   err:
>      return rc;
>  }
> @@ -678,6 +719,8 @@ static int restore(struct xc_sr_context *ctx)
>                      goto err;
>                  }
>              }
> +            else if ( rc == BROKEN_CHANNEL )
> +                goto remus_failover;
>              else if ( rc )
>                  goto err;
>          }
> @@ -685,6 +728,15 @@ static int restore(struct xc_sr_context *ctx)
>      } while ( rec.type != REC_TYPE_END );
>  
>   remus_failover:
> +
> +    if ( ctx->restore.checkpointed == 2 )
> +    {
> +        /* With COLO, we have already called stream_complete */
> +        rc = 0;
> +        IPRINTF("COLO Failover");
> +        goto done;
> +    }
> +
>      /*
>       * With Remus, if we reach here, there must be some error on primary,
>       * failover from the last checkpoint state.
> @@ -735,6 +787,15 @@ 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 ( ctx.restore.checkpointed == 2 )
> +    {
> +        /* this is COLO restore */
> +        assert(callbacks->suspend &&
> +               callbacks->checkpoint &&
> +               callbacks->postcopy);

FWIW, I need to make the ->checkpoint() callback used even in the remus
case for qemu handling in libxl migration v2.

> +    }
> +
>      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/libxc/xc_sr_restore_x86_hvm.c b/tools/libxc/xc_sr_restore_x86_hvm.c
> index 06177e0..8e54c68 100644
> --- a/tools/libxc/xc_sr_restore_x86_hvm.c
> +++ b/tools/libxc/xc_sr_restore_x86_hvm.c
> @@ -181,6 +181,7 @@ static int handle_qemu(struct xc_sr_context *ctx)
>      if ( fp )
>          fclose(fp);
>      free(qbuf);
> +    ctx->x86_hvm.restore.qbuf = NULL;

This looks like an unrelated bugfix.

~Andrew

>  
>      return rc;
>  }

  reply	other threads:[~2015-06-08 10:39 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-08  3:45 [PATCH v6 COLO 00/15] COarse-grain LOck-stepping Virtual Machines for Non-stop Service Yang Hongyang
2015-06-08  3:45 ` [PATCH v6 COLO 01/15] docs: add colo readme Yang Hongyang
2015-06-16 10:56   ` Ian Campbell
2015-06-24  9:13     ` Yang Hongyang
2015-06-08  3:45 ` [PATCH v6 COLO 02/15] secondary vm suspend/resume/checkpoint code Yang Hongyang
2015-06-12 14:23   ` Wei Liu
2015-06-12 14:51     ` Ian Jackson
2015-06-15  2:10       ` Yang Hongyang
2015-06-15  1:55     ` Yang Hongyang
2015-06-16 11:42       ` Ian Jackson
2015-06-08  3:45 ` [PATCH v6 COLO 03/15] primary vm suspend/get_dirty_pfn/resume/checkpoint code Yang Hongyang
2015-06-16 11:05   ` Ian Campbell
2015-06-08  3:45 ` [PATCH v6 COLO 04/15] libxc/restore: support COLO restore Yang Hongyang
2015-06-08 10:39   ` Andrew Cooper [this message]
2015-06-08 14:06     ` Yang Hongyang
2015-06-08  3:45 ` [PATCH v6 COLO 05/15] send store mfn and console mfn to xl before resuming secondary vm Yang Hongyang
2015-06-08 12:16   ` Andrew Cooper
2015-06-08 14:08     ` Yang Hongyang
2015-06-16 11:13   ` Ian Campbell
2015-06-08  3:45 ` [PATCH v6 COLO 06/15] libxc/save: support COLO save Yang Hongyang
2015-06-08 13:04   ` Andrew Cooper
2015-06-09  3:15     ` Yang Hongyang
2015-06-09  7:20       ` Andrew Cooper
2015-06-09  8:45         ` Yang Hongyang
2015-06-09  8:51           ` Andrew Cooper
2015-06-09  9:09             ` Yang Hongyang
2015-06-09  9:10               ` Andrew Cooper
2015-06-09  9:16                 ` Yang Hongyang
2015-06-09  3:18     ` Yang Hongyang
2015-06-08  3:45 ` [PATCH v6 COLO 07/15] implement the cmdline for COLO Yang Hongyang
2015-06-16 11:19   ` Ian Campbell
2015-06-25  4:06     ` Yang Hongyang
2015-07-14 15:14       ` Ian Campbell
2015-06-08  3:45 ` [PATCH v6 COLO 08/15] Support colo mode for qemu disk Yang Hongyang
2015-06-16 11:21   ` Ian Campbell
2015-06-08  3:45 ` [PATCH v6 COLO 09/15] COLO: use qemu block replication Yang Hongyang
2015-06-16 11:22   ` Ian Campbell
2015-06-08  3:45 ` [PATCH v6 COLO 10/15] COLO proxy: implement setup/teardown of COLO proxy module Yang Hongyang
2015-06-16 11:24   ` Ian Campbell
2015-06-16 11:26     ` Ian Campbell
2015-06-25  5:22       ` Yang Hongyang
2015-06-25  8:39         ` Ian Campbell
2015-06-25  8:48           ` Yang Hongyang
2015-06-08  3:45 ` [PATCH v6 COLO 11/15] COLO proxy: preresume, postresume and checkpoint Yang Hongyang
2015-06-08  3:45 ` [PATCH v6 COLO 12/15] COLO nic: implement COLO nic subkind Yang Hongyang
2015-06-12 14:35   ` Wei Liu
2015-06-15  2:13     ` Yang Hongyang
2015-06-08  3:45 ` [PATCH v6 COLO 13/15] setup and control colo proxy on primary side Yang Hongyang
2015-06-08  3:45 ` [PATCH v6 COLO 14/15] setup and control colo proxy on secondary side Yang Hongyang
2015-06-08  3:45 ` [PATCH v6 COLO 15/15] cmdline switches and config vars to control colo-proxy 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=557570FF.10901@citrix.com \
    --to=andrew.cooper3@citrix.com \
    --cc=eddie.dong@intel.com \
    --cc=guijianfeng@cn.fujitsu.com \
    --cc=ian.campbell@citrix.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=rshriram@cs.ubc.ca \
    --cc=wei.liu2@citrix.com \
    --cc=wency@cn.fujitsu.com \
    --cc=xen-devel@lists.xen.org \
    --cc=yanghy@cn.fujitsu.com \
    --cc=yunhong.jiang@intel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).