From patchwork Wed Feb 15 08:34:14 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhanghailiang X-Patchwork-Id: 9573489 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 833A860209 for ; Wed, 15 Feb 2017 08:35:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 78A0D27FB0 for ; Wed, 15 Feb 2017 08:35:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6CA462843B; Wed, 15 Feb 2017 08:35:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 61FA927FB0 for ; Wed, 15 Feb 2017 08:35:30 +0000 (UTC) Received: from localhost ([::1]:39043 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cdv3h-0008FQ-8Z for patchwork-qemu-devel@patchwork.kernel.org; Wed, 15 Feb 2017 03:35:29 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38059) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cdv3B-0008Ey-RS for qemu-devel@nongnu.org; Wed, 15 Feb 2017 03:34:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cdv38-0007aO-Ab for qemu-devel@nongnu.org; Wed, 15 Feb 2017 03:34:57 -0500 Received: from szxga03-in.huawei.com ([119.145.14.66]:44876) by eggs.gnu.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.71) (envelope-from ) id 1cdv37-0007Tt-Ny for qemu-devel@nongnu.org; Wed, 15 Feb 2017 03:34:54 -0500 Received: from 172.24.1.136 (EHLO szxeml426-hub.china.huawei.com) ([172.24.1.136]) by szxrg03-dlp.huawei.com (MOS 4.4.3-GA FastPath queued) with ESMTP id CPF49044; Wed, 15 Feb 2017 16:34:44 +0800 (CST) Received: from localhost (10.177.24.212) by szxeml426-hub.china.huawei.com (10.82.67.181) with Microsoft SMTP Server id 14.3.235.1; Wed, 15 Feb 2017 16:34:34 +0800 From: zhanghailiang To: , , Date: Wed, 15 Feb 2017 16:34:14 +0800 Message-ID: <1487147657-166092-3-git-send-email-zhang.zhanghailiang@huawei.com> X-Mailer: git-send-email 2.7.2.windows.1 In-Reply-To: <1487147657-166092-1-git-send-email-zhang.zhanghailiang@huawei.com> References: <1487147657-166092-1-git-send-email-zhang.zhanghailiang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.177.24.212] X-CFilter-Loop: Reflected X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] [fuzzy] X-Received-From: 119.145.14.66 Subject: [Qemu-devel] [PATCH 2/5] colo-compare: kick compare thread to exit while finalize X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: zhanghailiang , xuquan8@huawei.com, qemu-devel@nongnu.org, pss.wulizhen@huawei.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP We should call g_main_loop_quit() to notify colo compare thread to exit, Or it will run in g_main_loop_run() forever. Besides, the finalizing process can't happen in context of colo thread, it is reasonable to remove the 'if (qemu_thread_is_self(&s->thread))' branch. Signed-off-by: zhanghailiang --- net/colo-compare.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/net/colo-compare.c b/net/colo-compare.c index fdde788..a16e2d5 100644 --- a/net/colo-compare.c +++ b/net/colo-compare.c @@ -83,6 +83,8 @@ typedef struct CompareState { GHashTable *connection_track_table; /* compare thread, a thread for each NIC */ QemuThread thread; + + GMainLoop *compare_loop; } CompareState; typedef struct CompareClass { @@ -496,7 +498,6 @@ static gboolean check_old_packet_regular(void *opaque) static void *colo_compare_thread(void *opaque) { GMainContext *worker_context; - GMainLoop *compare_loop; CompareState *s = opaque; GSource *timeout_source; @@ -507,7 +508,7 @@ static void *colo_compare_thread(void *opaque) qemu_chr_fe_set_handlers(&s->chr_sec_in, compare_chr_can_read, compare_sec_chr_in, NULL, s, worker_context, true); - compare_loop = g_main_loop_new(worker_context, FALSE); + s->compare_loop = g_main_loop_new(worker_context, FALSE); /* To kick any packets that the secondary doesn't match */ timeout_source = g_timeout_source_new(REGULAR_PACKET_CHECK_MS); @@ -515,10 +516,10 @@ static void *colo_compare_thread(void *opaque) (GSourceFunc)check_old_packet_regular, s, NULL); g_source_attach(timeout_source, worker_context); - g_main_loop_run(compare_loop); + g_main_loop_run(s->compare_loop); g_source_unref(timeout_source); - g_main_loop_unref(compare_loop); + g_main_loop_unref(s->compare_loop); g_main_context_unref(worker_context); return NULL; } @@ -703,13 +704,11 @@ static void colo_compare_finalize(Object *obj) qemu_chr_fe_deinit(&s->chr_sec_in); qemu_chr_fe_deinit(&s->chr_out); - g_queue_free(&s->conn_list); + g_main_loop_quit(s->compare_loop); + qemu_thread_join(&s->thread); - if (qemu_thread_is_self(&s->thread)) { - /* compare connection */ - g_queue_foreach(&s->conn_list, colo_compare_connection, s); - qemu_thread_join(&s->thread); - } + + g_queue_free(&s->conn_list); g_free(s->pri_indev); g_free(s->sec_indev);