From patchwork Fri Jan 29 05:27:34 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wen Congyang X-Patchwork-Id: 8159281 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 62480BEEED for ; Fri, 29 Jan 2016 05:30:17 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9BBD02012E for ; Fri, 29 Jan 2016 05:30:15 +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 842C2200E9 for ; Fri, 29 Jan 2016 05:30:14 +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 1aP1ay-0007pq-Fg; Fri, 29 Jan 2016 05:27:44 +0000 Received: from mail6.bemta4.messagelabs.com ([85.158.143.247]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aP1au-0007eM-8W for xen-devel@lists.xen.org; Fri, 29 Jan 2016 05:27:40 +0000 Received: from [85.158.143.35] by server-2.bemta-4.messagelabs.com id 3B/09-08977-C48FAA65; Fri, 29 Jan 2016 05:27:40 +0000 X-Env-Sender: wency@cn.fujitsu.com X-Msg-Ref: server-5.tower-21.messagelabs.com!1454045251!12793739!5 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 27888 invoked from network); 29 Jan 2016 05:27:39 -0000 Received: from cn.fujitsu.com (HELO heian.cn.fujitsu.com) (59.151.112.132) by server-5.tower-21.messagelabs.com with SMTP; 29 Jan 2016 05:27:39 -0000 X-IronPort-AV: E=Sophos;i="5.20,346,1444665600"; d="scan'208";a="3106355" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 29 Jan 2016 13:27:33 +0800 Received: from G08CNEXCHPEKD01.g08.fujitsu.local (unknown [10.167.33.80]) by cn.fujitsu.com (Postfix) with ESMTP id 4103C418AD59; Fri, 29 Jan 2016 13:26:40 +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; Fri, 29 Jan 2016 13:27:15 +0800 From: Wen Congyang To: xen devel , Konrad Rzeszutek Wilk , Andrew Cooper , Ian Campbell , Ian Jackson , Wei Liu Date: Fri, 29 Jan 2016 13:27:34 +0800 Message-ID: <1454045254-3711-19-git-send-email-wency@cn.fujitsu.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1454045254-3711-1-git-send-email-wency@cn.fujitsu.com> References: <1454045254-3711-1-git-send-email-wency@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.52] X-yoursite-MailScanner-ID: 4103C418AD59.A4EB0 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 v7 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 Acked-by: Wei Liu --- 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); }