From patchwork Wed Dec 30 02:37:51 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wen Congyang X-Patchwork-Id: 7931651 Return-Path: X-Original-To: patchwork-xen-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id E84BEBF0A9 for ; Wed, 30 Dec 2015 02:40:38 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E85B220219 for ; Wed, 30 Dec 2015 02:40:36 +0000 (UTC) Received: from lists.xen.org (lists.xenproject.org [50.57.142.19]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7543A201FA for ; Wed, 30 Dec 2015 02:40:35 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aE6fF-0003E9-R4; Wed, 30 Dec 2015 02:39:01 +0000 Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aE6fC-00035l-8G for xen-devel@lists.xen.org; Wed, 30 Dec 2015 02:38:58 +0000 Received: from [193.109.254.147] by server-12.bemta-14.messagelabs.com id 3F/F9-09834-1C343865; Wed, 30 Dec 2015 02:38:57 +0000 X-Env-Sender: wency@cn.fujitsu.com X-Msg-Ref: server-9.tower-27.messagelabs.com!1451443108!13748866!7 X-Originating-IP: [59.151.112.132] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 7.35.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 30817 invoked from network); 30 Dec 2015 02:38:55 -0000 Received: from cn.fujitsu.com (HELO heian.cn.fujitsu.com) (59.151.112.132) by server-9.tower-27.messagelabs.com with SMTP; 30 Dec 2015 02:38:55 -0000 X-IronPort-AV: E=Sophos;i="5.20,346,1444665600"; d="scan'208";a="2080194" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 30 Dec 2015 10:38:36 +0800 Received: from G08CNEXCHPEKD01.g08.fujitsu.local (unknown [10.167.33.80]) by cn.fujitsu.com (Postfix) with ESMTP id 591B74189109; Wed, 30 Dec 2015 10:38:21 +0800 (CST) Received: from G08FNSTD140052.g08.fujitsu.local (10.167.226.52) by G08CNEXCHPEKD01.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.181.6; Wed, 30 Dec 2015 10:38:21 +0800 From: Wen Congyang To: xen devel , Andrew Cooper , Ian Campbell , Ian Jackson , Wei Liu Date: Wed, 30 Dec 2015 10:37:51 +0800 Message-ID: <1451443075-27428-22-git-send-email-wency@cn.fujitsu.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1451443075-27428-1-git-send-email-wency@cn.fujitsu.com> References: <1451443075-27428-1-git-send-email-wency@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.52] X-yoursite-MailScanner-ID: 591B74189109.A37C8 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: wency@cn.fujitsu.com X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Cc: Lars Kurth , Changlong Xie , Wen Congyang , Gui Jianfeng , Jiang Yunhong , Dong Eddie , Shriram Rajagopalan , Yang Hongyang Subject: [Xen-devel] [PATCH v9 21/25] COLO proxy: preresume, postresume and checkpoint X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP preresume, postresume and checkpoint Signed-off-by: Yang Hongyang Signed-off-by: Wen Congyang --- tools/libxl/libxl_colo.h | 4 +++ tools/libxl/libxl_colo_proxy.c | 62 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/tools/libxl/libxl_colo.h b/tools/libxl/libxl_colo.h index 2604b0f..ea17faa 100644 --- a/tools/libxl/libxl_colo.h +++ b/tools/libxl/libxl_colo.h @@ -33,4 +33,8 @@ extern void libxl__colo_save_teardown(libxl__egc *egc, extern int colo_proxy_setup(libxl__colo_proxy_state *cps); extern void colo_proxy_teardown(libxl__colo_proxy_state *cps); +extern void colo_proxy_preresume(libxl__colo_proxy_state *cps); +extern void colo_proxy_postresume(libxl__colo_proxy_state *cps); +extern int colo_proxy_checkpoint(libxl__colo_proxy_state *cps, + unsigned int timeout_us); #endif diff --git a/tools/libxl/libxl_colo_proxy.c b/tools/libxl/libxl_colo_proxy.c index e07e640..c714b52 100644 --- a/tools/libxl/libxl_colo_proxy.c +++ b/tools/libxl/libxl_colo_proxy.c @@ -228,3 +228,65 @@ void colo_proxy_teardown(libxl__colo_proxy_state *cps) cps->sock_fd = -1; } } + +/* ========= colo-proxy: preresume, postresume and checkpoint ========== */ + +void colo_proxy_preresume(libxl__colo_proxy_state *cps) +{ + colo_proxy_send(cps, NULL, 0, COLO_CHECKPOINT); + /* TODO: need to handle if the call fails... */ +} + +void colo_proxy_postresume(libxl__colo_proxy_state *cps) +{ + /* nothing to do... */ +} + +typedef struct colo_msg { + bool is_checkpoint; +} colo_msg; + +/* + * Return value: + * -1: error + * 0: no checkpoint event is received before timeout + * 1: do checkpoint + */ +int colo_proxy_checkpoint(libxl__colo_proxy_state *cps, + unsigned int timeout_us) +{ + uint8_t *buff; + int64_t size; + struct nlmsghdr *h; + struct colo_msg *m; + int ret = -1; + + STATE_AO_GC(cps->ao); + + size = colo_proxy_recv(cps, &buff, timeout_us); + + /* timeout, return no checkpoint message. */ + if (size <= 0) { + return 0; + } + + h = (struct nlmsghdr *) buff; + + if (h->nlmsg_type == NLMSG_ERROR) { + LOG(ERROR, "receive NLMSG_ERROR"); + goto out; + } + + if (h->nlmsg_len < NLMSG_LENGTH(sizeof(*m))) { + LOG(ERROR, "NLMSG_LENGTH is too short"); + goto out; + } + + m = NLMSG_DATA(h); + + ret = m->is_checkpoint ? 1 : 0; + +out: + free(buff); + return ret; +}