From patchwork Fri Mar 4 08:41:29 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Changlong Xie X-Patchwork-Id: 8500281 Return-Path: X-Original-To: patchwork-xen-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 711059F659 for ; Fri, 4 Mar 2016 08:42:54 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6F7EF20373 for ; Fri, 4 Mar 2016 08:42:52 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E824A2035D for ; Fri, 4 Mar 2016 08:42:49 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xen.org with esmtp (Exim 4.84) (envelope-from ) id 1ablHQ-00079t-N6; Fri, 04 Mar 2016 08:40:12 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.84) (envelope-from ) id 1ablHP-0006wz-5t for xen-devel@lists.xen.org; Fri, 04 Mar 2016 08:40:11 +0000 Received: from [85.158.137.68] by server-3.bemta-3.messagelabs.com id C8/BB-03294-AE949D65; Fri, 04 Mar 2016 08:40:10 +0000 X-Env-Sender: xiecl.fnst@cn.fujitsu.com X-Msg-Ref: server-9.tower-31.messagelabs.com!1457080803!4530056!3 X-Originating-IP: [59.151.112.132] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 8.11; banners=-,-,- X-VirusChecked: Checked Received: (qmail 54022 invoked from network); 4 Mar 2016 08:40:09 -0000 Received: from cn.fujitsu.com (HELO heian.cn.fujitsu.com) (59.151.112.132) by server-9.tower-31.messagelabs.com with SMTP; 4 Mar 2016 08:40:09 -0000 X-IronPort-AV: E=Sophos;i="5.22,518,1449504000"; d="scan'208";a="4230668" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 04 Mar 2016 16:40:09 +0800 Received: from G08CNEXCHPEKD01.g08.fujitsu.local (unknown [10.167.33.80]) by cn.fujitsu.com (Postfix) with ESMTP id 5F9C842B4B07; Fri, 4 Mar 2016 16:40:08 +0800 (CST) Received: from changlox.g08.fujitsu.local (10.167.225.55) by G08CNEXCHPEKD01.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.181.6; Fri, 4 Mar 2016 16:40:08 +0800 From: Changlong Xie To: xen devel , Konrad Rzeszutek Wilk , Andrew Cooper , Ian Campbell , Ian Jackson , Wei Liu Date: Fri, 4 Mar 2016 16:41:29 +0800 Message-ID: <1457080891-26054-26-git-send-email-xiecl.fnst@cn.fujitsu.com> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1457080891-26054-1-git-send-email-xiecl.fnst@cn.fujitsu.com> References: <1457080891-26054-1-git-send-email-xiecl.fnst@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.225.55] X-yoursite-MailScanner-ID: 5F9C842B4B07.A194B X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: xiecl.fnst@cn.fujitsu.com X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Cc: Lars Kurth , Changlong Xie , Wen Congyang , Gui Jianfeng , Jiang Yunhong , Dong Eddie , Anthony Perard , Shriram Rajagopalan , Yang Hongyang Subject: [Xen-devel] [PATCH v11 25/27] setup and control colo proxy on primary side X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Wen Congyang Signed-off-by: Yang Hongyang Signed-off-by: Wen Congyang Signed-off-by: Changlong Xie --- tools/libxl/libxl_colo_save.c | 124 +++++++++++++++++++++++++++++++++++++++--- tools/libxl/libxl_internal.h | 1 + 2 files changed, 117 insertions(+), 8 deletions(-) diff --git a/tools/libxl/libxl_colo_save.c b/tools/libxl/libxl_colo_save.c index 97efc8d..bb44e66 100644 --- a/tools/libxl/libxl_colo_save.c +++ b/tools/libxl/libxl_colo_save.c @@ -18,9 +18,11 @@ #include "libxl_internal.h" +extern const libxl__checkpoint_device_instance_ops colo_save_device_nic; extern const libxl__checkpoint_device_instance_ops colo_save_device_qdisk; static const libxl__checkpoint_device_instance_ops *colo_ops[] = { + &colo_save_device_nic, &colo_save_device_qdisk, NULL, }; @@ -32,9 +34,15 @@ static int init_device_subkind(libxl__checkpoint_devices_state *cds) int rc; STATE_AO_GC(cds->ao); - rc = init_subkind_qdisk(cds); + rc = init_subkind_colo_nic(cds); if (rc) goto out; + rc = init_subkind_qdisk(cds); + if (rc) { + cleanup_subkind_colo_nic(cds); + goto out; + } + rc = 0; out: return rc; @@ -45,6 +53,7 @@ static void cleanup_device_subkind(libxl__checkpoint_devices_state *cds) /* cleanup device subkind-specific state in the libxl ctx */ STATE_AO_GC(cds->ao); + cleanup_subkind_colo_nic(cds); cleanup_subkind_qdisk(cds); } @@ -89,9 +98,16 @@ void libxl__colo_save_setup(libxl__egc *egc, libxl__colo_save_state *css) css->paused = true; css->qdisk_setuped = false; css->qdisk_used = false; + libxl__ev_child_init(&css->child); + + if (dss->remus->netbufscript) + css->colo_proxy_script = libxl__strdup(gc, dss->remus->netbufscript); + else + css->colo_proxy_script = GCSPRINTF("%s/colo-proxy-setup", + libxl__xen_script_dir_path()); - /* TODO: nic support */ - cds->device_kind_flags = (1 << LIBXL__DEVICE_KIND_VBD); + cds->device_kind_flags = (1 << LIBXL__DEVICE_KIND_VIF) | + (1 << LIBXL__DEVICE_KIND_VBD); cds->ops = colo_ops; cds->callback = colo_save_setup_done; cds->ao = ao; @@ -102,6 +118,12 @@ void libxl__colo_save_setup(libxl__egc *egc, libxl__colo_save_state *css) css->srs.fd = css->recv_fd; css->srs.back_channel = true; libxl__stream_read_start(egc, &css->srs); + css->cps.ao = ao; + if (colo_proxy_setup(&css->cps)) { + LOG(ERROR, "COLO: failed to setup colo proxy for guest with domid %u", + cds->domid); + goto out; + } if (init_device_subkind(cds)) goto out; @@ -189,6 +211,7 @@ static void colo_teardown_done(libxl__egc *egc, libxl__domain_save_state *dss = CONTAINER_OF(css, *dss, css); cleanup_device_subkind(cds); + colo_proxy_teardown(&css->cps); dss->callback(egc, dss, rc); } @@ -381,6 +404,8 @@ static void colo_read_svm_ready_done(libxl__egc *egc, goto out; } + colo_proxy_preresume(&css->cps); + css->svm_running = true; dss->cds.callback = colo_preresume_cb; libxl__checkpoint_devices_preresume(egc, &dss->cds); @@ -465,6 +490,8 @@ static void colo_read_svm_resumed_done(libxl__egc *egc, goto out; } + colo_proxy_postresume(&css->cps); + ok = 1; out: @@ -473,6 +500,91 @@ out: /* ===================== colo: wait new checkpoint ===================== */ + +static void colo_start_new_checkpoint(libxl__egc *egc, + libxl__checkpoint_devices_state *cds, + int rc); +static void colo_proxy_async_wait_for_checkpoint(libxl__colo_save_state *css); +static void colo_proxy_async_call_done(libxl__egc *egc, + libxl__ev_child *child, + int pid, + int status); + +static void colo_proxy_async_call(libxl__egc *egc, + libxl__colo_save_state *css, + void func(libxl__colo_save_state *), + libxl__ev_child_callback callback) +{ + libxl__domain_save_state *dss = CONTAINER_OF(css, *dss, css); + int pid = -1, rc; + + STATE_AO_GC(dss->cds.ao); + + /* Fork and call */ + pid = libxl__ev_child_fork(gc, &css->child, callback); + if (pid == -1) { + LOG(ERROR, "unable to fork"); + rc = ERROR_FAIL; + goto out; + } + + if (!pid) { + /* child */ + func(css); + /* notreached */ + abort(); + } + + return; + +out: + callback(egc, &css->child, -1, 1); +} + +static void colo_proxy_wait_for_checkpoint(libxl__egc *egc, + libxl__colo_save_state *css) +{ + colo_proxy_async_call(egc, css, + colo_proxy_async_wait_for_checkpoint, + colo_proxy_async_call_done); +} + +static void colo_proxy_async_wait_for_checkpoint(libxl__colo_save_state *css) +{ + int req; + + req = colo_proxy_checkpoint(&css->cps, 5000000); + if (req < 0) { + /* some error happens */ + _exit(1); + } else if (!req) { + /* no checkpoint is needed, do a checkpint every 5s */ + _exit(0); + } else { + /* net packets is not consistent, we need to start a checkpoint */ + _exit(0); + } +} + +static void colo_proxy_async_call_done(libxl__egc *egc, + libxl__ev_child *child, + int pid, + int status) +{ + libxl__colo_save_state *css = CONTAINER_OF(child, *css, child); + libxl__domain_save_state *dss = CONTAINER_OF(css, *dss, css); + + EGC_GC; + + if (status) { + LOG(ERROR, "failed to wait for new checkpoint"); + colo_start_new_checkpoint(egc, &dss->cds, ERROR_FAIL); + return; + } + + colo_start_new_checkpoint(egc, &dss->cds, 0); +} + /* * Do the following things: * 1. do commit @@ -482,9 +594,6 @@ out: static void colo_device_commit_cb(libxl__egc *egc, libxl__checkpoint_devices_state *cds, int rc); -static void colo_start_new_checkpoint(libxl__egc *egc, - libxl__checkpoint_devices_state *cds, - int rc); static void libxl__colo_save_domain_wait_checkpoint_callback(void *data) { @@ -514,8 +623,7 @@ static void colo_device_commit_cb(libxl__egc *egc, goto out; } - /* TODO: wait a new checkpoint */ - colo_start_new_checkpoint(egc, cds, 0); + colo_proxy_wait_for_checkpoint(egc, css); return; out: diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index ddaafc6..dd9d00f 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -3198,6 +3198,7 @@ struct libxl__colo_save_state { /* private, used by colo-proxy */ libxl__colo_proxy_state cps; + libxl__ev_child child; }; typedef struct libxl__logdirty_switch {