From mboxrd@z Thu Jan 1 00:00:00 1970 From: Yang Hongyang Subject: [PATCH v7 COLO 03/18] tools/libxl: write colo_context records into the stream Date: Thu, 25 Jun 2015 14:30:57 +0800 Message-ID: <1435213872-10698-4-git-send-email-yanghy@cn.fujitsu.com> References: <1435213872-10698-1-git-send-email-yanghy@cn.fujitsu.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1435213872-10698-1-git-send-email-yanghy@cn.fujitsu.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xen.org Cc: wei.liu2@citrix.com, ian.campbell@citrix.com, wency@cn.fujitsu.com, andrew.cooper3@citrix.com, yunhong.jiang@intel.com, eddie.dong@intel.com, guijianfeng@cn.fujitsu.com, rshriram@cs.ubc.ca, ian.jackson@eu.citrix.com List-Id: xen-devel@lists.xenproject.org From: Wen Congyang Signed-off-by: Wen Congyang --- tools/libxl/libxl_internal.h | 4 ++ tools/libxl/libxl_stream_write.c | 92 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+) diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index 7f591ee..1ef6fc8 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -2905,6 +2905,7 @@ struct libxl__stream_write_state { size_t padding; bool running; bool in_checkpoint; + bool in_colo_context; libxl__datacopier_state dc; }; @@ -2913,6 +2914,9 @@ _hidden void libxl__stream_write_start(libxl__egc *egc, _hidden void libxl__stream_write_start_checkpoint( libxl__egc *egc, libxl__stream_write_state *stream); +_hidden void libxl__stream_write_colo_context( + libxl__egc *egc, libxl__stream_write_state *stream, + libxl_sr_colo_context *colo_context); _hidden void libxl__stream_write_abort(libxl__egc *egc, libxl__stream_write_state *stream, diff --git a/tools/libxl/libxl_stream_write.c b/tools/libxl/libxl_stream_write.c index 3f981f0..a445189 100644 --- a/tools/libxl/libxl_stream_write.c +++ b/tools/libxl/libxl_stream_write.c @@ -107,6 +107,15 @@ static void checkpoint_end_record_done(libxl__egc *egc, libxl__datacopier_state *dc, int onwrite, int errnoval); +static void write_colo_context(libxl__egc *egc, + libxl__stream_write_state *stream, + libxl_sr_colo_context *colo_context); +static void write_colo_context_done(libxl__egc *egc, + libxl__datacopier_state *dc, + int onwrite, int errnoval); +static void colo_context_done(libxl__egc *egc, + libxl__stream_write_state *stream, int rc); + void libxl__stream_write_start(libxl__egc *egc, libxl__stream_write_state *stream) { @@ -154,11 +163,24 @@ void libxl__stream_write_start_checkpoint(libxl__egc *egc, assert(stream->running); assert(!stream->in_checkpoint); assert(!stream->back_channel); + assert(!stream->in_colo_context); stream->in_checkpoint = true; write_toolstack_record(egc, stream); } +void libxl__stream_write_colo_context(libxl__egc *egc, + libxl__stream_write_state *stream, + libxl_sr_colo_context *colo_context) +{ + assert(stream->running); + assert(!stream->in_checkpoint); + assert(!stream->in_colo_context); + stream->in_colo_context = true; + + write_colo_context(egc, stream, colo_context); +} + void libxl__stream_write_abort(libxl__egc *egc, libxl__stream_write_state *stream, int rc) { @@ -171,6 +193,7 @@ static void stream_success(libxl__egc *egc, libxl__stream_write_state *stream) stream->running = false; assert(!stream->in_checkpoint); + assert(!stream->in_colo_context); stream_done(egc, stream); } @@ -189,6 +212,11 @@ static void stream_failed(libxl__egc *egc, return; } + if (stream->in_colo_context) { + colo_context_done(egc, stream, rc); + return; + } + if (stream->back_channel) { stream->completion_callback(egc, stream, rc); return; @@ -207,6 +235,7 @@ static void stream_done(libxl__egc *egc, assert(!stream->running); assert(!stream->in_checkpoint); + assert(!stream->in_colo_context); check_stream_finished(egc, dss, stream->rc, "stream"); } @@ -544,6 +573,61 @@ static void emulator_padding_done(libxl__egc *egc, stream_failed(egc, stream, ret); } +static void write_colo_context(libxl__egc *egc, + libxl__stream_write_state *stream, + libxl_sr_colo_context *colo_context) +{ + libxl__datacopier_state *dc = &stream->dc; + STATE_AO_GC(stream->ao); + struct libxl_sr_rec_hdr rec = { REC_TYPE_COLO_CONTEXT, 0 }; + int ret = 0; + uint32_t padding_len; + + dc->copywhat = "colo context record"; + dc->writewhat = "save/migration stream"; + dc->callback = write_colo_context_done; + + ret = libxl__datacopier_start(dc); + if (ret) + goto err; + + rec.length = sizeof(*colo_context); + + libxl__datacopier_prefixdata(egc, dc, &rec, sizeof(rec)); + libxl__datacopier_prefixdata(egc, dc, colo_context, rec.length); + + padding_len = ROUNDUP(rec.length, REC_ALIGN_ORDER) - rec.length; + if (padding_len) + libxl__datacopier_prefixdata(egc, dc, zero_padding, padding_len); + + return; + + err: + assert(ret); + stream_failed(egc, stream, ret); +} + +static void write_colo_context_done(libxl__egc *egc, + libxl__datacopier_state *dc, + int onwrite, int errnoval) +{ + libxl__stream_write_state *stream = CONTAINER_OF(dc, *stream, dc); + STATE_AO_GC(stream->ao); + int ret = 0; + + if (onwrite || errnoval) { + ret = ERROR_FAIL; + goto err; + } + + colo_context_done(egc, stream, 0); + return; + + err: + assert(ret); + stream_failed(egc, stream, ret); +} + static void write_end_record(libxl__egc *egc, libxl__stream_write_state *stream) { @@ -645,6 +729,14 @@ static void checkpoint_end_record_done(libxl__egc *egc, stream_failed(egc, stream, ret); } +static void colo_context_done(libxl__egc *egc, + libxl__stream_write_state *stream, int rc) +{ + assert(stream->in_colo_context); + stream->in_colo_context = false; + stream->write_records_callback(egc, stream, rc); +} + /* * Local variables: * mode: C -- 1.9.1