From patchwork Wed Dec 30 02:29:08 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wen Congyang X-Patchwork-Id: 7931301 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 A805ABEEE5 for ; Wed, 30 Dec 2015 02:32:26 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7A463201DD for ; Wed, 30 Dec 2015 02:32:25 +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 35CDA201F2 for ; Wed, 30 Dec 2015 02:32:24 +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 1aE6Wq-0000JP-TX; Wed, 30 Dec 2015 02:30:20 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aE6Wp-0000GM-QV for xen-devel@lists.xen.org; Wed, 30 Dec 2015 02:30:19 +0000 Received: from [85.158.139.211] by server-4.bemta-5.messagelabs.com id 06/74-24856-BB143865; Wed, 30 Dec 2015 02:30:19 +0000 X-Env-Sender: wency@cn.fujitsu.com X-Msg-Ref: server-2.tower-206.messagelabs.com!1451442585!13222421!6 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 21031 invoked from network); 30 Dec 2015 02:30:15 -0000 Received: from cn.fujitsu.com (HELO heian.cn.fujitsu.com) (59.151.112.132) by server-2.tower-206.messagelabs.com with SMTP; 30 Dec 2015 02:30:15 -0000 X-IronPort-AV: E=Sophos;i="5.20,346,1444665600"; d="scan'208";a="2079702" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 30 Dec 2015 10:29:47 +0800 Received: from G08CNEXCHPEKD01.g08.fujitsu.local (unknown [10.167.33.80]) by cn.fujitsu.com (Postfix) with ESMTP id CAA2541890F6; Wed, 30 Dec 2015 10:29:33 +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:29:33 +0800 From: Wen Congyang To: xen devel , Andrew Cooper , Ian Campbell , Ian Jackson , Wei Liu Date: Wed, 30 Dec 2015 10:29:08 +0800 Message-ID: <1451442548-26974-19-git-send-email-wency@cn.fujitsu.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1451442548-26974-1-git-send-email-wency@cn.fujitsu.com> References: <1451442548-26974-1-git-send-email-wency@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.52] X-yoursite-MailScanner-ID: CAA2541890F6.A85F0 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 v6 18/18] tools/libxl: seperate device init/cleanup from checkpoint device layer 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 we call (init|cleanup)_subkind_nic and (init|cleanup)_subkind_drbd_disk directly in checkpoint device. Move them to libxl_remus.c, Call them before calling libxl__checkpoint_devices_setup() or after calling libxl__checkpoint_devices_teardown(). it is pure refactoring and no functional changes. Signed-off-by: Wen Congyang Signed-off-by: Yang Hongyang Acked-by: Ian Campbell Reviewed-by: Konrad Rzeszutek Wilk --- tools/libxl/libxl_checkpoint_device.c | 42 ++--------------------------------- tools/libxl/libxl_remus.c | 42 +++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 40 deletions(-) diff --git a/tools/libxl/libxl_checkpoint_device.c b/tools/libxl/libxl_checkpoint_device.c index bbc6dc4..0a16dbb 100644 --- a/tools/libxl/libxl_checkpoint_device.c +++ b/tools/libxl/libxl_checkpoint_device.c @@ -17,38 +17,6 @@ #include "libxl_internal.h" -/*----- helper functions -----*/ - -static int init_device_subkind(libxl__checkpoint_devices_state *cds) -{ - /* init device subkind-specific state in the libxl ctx */ - int rc; - STATE_AO_GC(cds->ao); - - if (libxl__netbuffer_enabled(gc)) { - rc = init_subkind_nic(cds); - if (rc) goto out; - } - - rc = init_subkind_drbd_disk(cds); - if (rc) goto out; - - rc = 0; -out: - return rc; -} - -static void cleanup_device_subkind(libxl__checkpoint_devices_state *cds) -{ - /* cleanup device subkind-specific state in the libxl ctx */ - STATE_AO_GC(cds->ao); - - if (libxl__netbuffer_enabled(gc)) - cleanup_subkind_nic(cds); - - cleanup_subkind_drbd_disk(cds); -} - /*----- setup() and teardown() -----*/ /* callbacks */ @@ -86,14 +54,10 @@ static void checkpoint_devices_setup(libxl__egc *egc, void libxl__checkpoint_devices_setup(libxl__egc *egc, libxl__checkpoint_devices_state *cds) { - int i, rc; + int i; STATE_AO_GC(cds->ao); - rc = init_device_subkind(cds); - if (rc) - goto out; - cds->num_devices = 0; cds->num_nics = 0; cds->num_disks = 0; @@ -126,7 +90,7 @@ void libxl__checkpoint_devices_setup(libxl__egc *egc, return; out: - cds->callback(egc, cds, rc); + cds->callback(egc, cds, 0); } static void checkpoint_devices_setup(libxl__egc *egc, @@ -263,8 +227,6 @@ static void devices_teardown_cb(libxl__egc *egc, cds->disks = NULL; cds->num_disks = 0; - cleanup_device_subkind(cds); - cds->callback(egc, cds, rc); } diff --git a/tools/libxl/libxl_remus.c b/tools/libxl/libxl_remus.c index 00e3c80..07a1699 100644 --- a/tools/libxl/libxl_remus.c +++ b/tools/libxl/libxl_remus.c @@ -26,6 +26,38 @@ static const libxl__checkpoint_device_instance_ops *remus_ops[] = { NULL, }; +/*----- helper functions -----*/ + +static int init_device_subkind(libxl__checkpoint_devices_state *cds) +{ + /* init device subkind-specific state in the libxl ctx */ + int rc; + STATE_AO_GC(cds->ao); + + if (libxl__netbuffer_enabled(gc)) { + rc = init_subkind_nic(cds); + if (rc) goto out; + } + + rc = init_subkind_drbd_disk(cds); + if (rc) goto out; + + rc = 0; +out: + return rc; +} + +static void cleanup_device_subkind(libxl__checkpoint_devices_state *cds) +{ + /* cleanup device subkind-specific state in the libxl ctx */ + STATE_AO_GC(cds->ao); + + if (libxl__netbuffer_enabled(gc)) + cleanup_subkind_nic(cds); + + cleanup_subkind_drbd_disk(cds); +} + /*-------------------- Remus setup and teardown ---------------------*/ static void remus_setup_done(libxl__egc *egc, @@ -63,6 +95,12 @@ void libxl__remus_setup(libxl__egc *egc, libxl__remus_state *rs) cds->concrete_data = rs; rs->interval = info->interval; + if (init_device_subkind(cds)) { + LOG(ERROR, "Remus: failed to init device subkind for guest %u", + dss->domid); + goto out; + } + dss->sws.checkpoint_callback = remus_checkpoint_stream_written; libxl__checkpoint_devices_setup(egc, cds); @@ -99,6 +137,8 @@ static void remus_setup_failed(libxl__egc *egc, LOG(ERROR, "Remus: failed to teardown device after setup failed" " for guest with domid %u, rc %d", dss->domid, rc); + cleanup_device_subkind(cds); + dss->callback(egc, dss, rc); } @@ -133,6 +173,8 @@ static void remus_teardown_done(libxl__egc *egc, LOG(ERROR, "Remus: failed to teardown device for guest with domid %u," " rc %d", dss->domid, rc); + cleanup_device_subkind(cds); + dss->callback(egc, dss, rc); }