From nobody Mon Apr 29 20:34:51 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1487147816148858.1385721406192; Wed, 15 Feb 2017 00:36:56 -0800 (PST) Received: from localhost ([::1]:39056 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cdv54-0000zq-Rh for importer@patchew.org; Wed, 15 Feb 2017 03:36:54 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38058) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cdv3B-0008Ex-RO 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 1cdv37-0007Zs-HY for qemu-devel@nongnu.org; Wed, 15 Feb 2017 03:34:57 -0500 Received: from szxga03-in.huawei.com ([119.145.14.66]:44866) by eggs.gnu.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.71) (envelope-from ) id 1cdv36-0007Ti-KE for qemu-devel@nongnu.org; Wed, 15 Feb 2017 03:34:53 -0500 Received: from 172.24.1.137 (EHLO szxeml431-hub.china.huawei.com) ([172.24.1.137]) by szxrg03-dlp.huawei.com (MOS 4.4.3-GA FastPath queued) with ESMTP id CPF49039; Wed, 15 Feb 2017 16:34:41 +0800 (CST) Received: from localhost (10.177.24.212) by szxeml431-hub.china.huawei.com (10.82.67.208) 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:13 +0800 Message-ID: <1487147657-166092-2-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 1/5] colo-compare: use g_timeout_source_new() to process the stale packets 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Instead of using qemu timer to process the stale packets, We re-use the colo compare thread to process these packets by creating a new timeout coroutine. Besides, since we process all the same vNIC's net connection/packets in one thread, it is safe to remove the timer_check_lock. Signed-off-by: zhanghailiang --- net/colo-compare.c | 62 +++++++++++++++++++-------------------------------= ---- 1 file changed, 22 insertions(+), 40 deletions(-) diff --git a/net/colo-compare.c b/net/colo-compare.c index 162fd6a..fdde788 100644 --- a/net/colo-compare.c +++ b/net/colo-compare.c @@ -83,9 +83,6 @@ typedef struct CompareState { GHashTable *connection_track_table; /* compare thread, a thread for each NIC */ QemuThread thread; - /* Timer used on the primary to find packets that are never matched */ - QEMUTimer *timer; - QemuMutex timer_check_lock; } CompareState; =20 typedef struct CompareClass { @@ -374,9 +371,7 @@ static void colo_compare_connection(void *opaque, void = *user_data) =20 while (!g_queue_is_empty(&conn->primary_list) && !g_queue_is_empty(&conn->secondary_list)) { - qemu_mutex_lock(&s->timer_check_lock); pkt =3D g_queue_pop_tail(&conn->primary_list); - qemu_mutex_unlock(&s->timer_check_lock); switch (conn->ip_proto) { case IPPROTO_TCP: result =3D g_queue_find_custom(&conn->secondary_list, @@ -411,9 +406,7 @@ static void colo_compare_connection(void *opaque, void = *user_data) * until next comparison. */ trace_colo_compare_main("packet different"); - qemu_mutex_lock(&s->timer_check_lock); g_queue_push_tail(&conn->primary_list, pkt); - qemu_mutex_unlock(&s->timer_check_lock); /* TODO: colo_notify_checkpoint();*/ break; } @@ -486,11 +479,26 @@ static void compare_sec_chr_in(void *opaque, const ui= nt8_t *buf, int size) } } =20 +/* + * Check old packet regularly so it can watch for any packets + * that the secondary hasn't produced equivalents of. + */ +static gboolean check_old_packet_regular(void *opaque) +{ + CompareState *s =3D opaque; + + /* if have old packet we will notify checkpoint */ + colo_old_packet_check(s); + + return TRUE; +} + static void *colo_compare_thread(void *opaque) { GMainContext *worker_context; GMainLoop *compare_loop; CompareState *s =3D opaque; + GSource *timeout_source; =20 worker_context =3D g_main_context_new(); =20 @@ -501,8 +509,15 @@ static void *colo_compare_thread(void *opaque) =20 compare_loop =3D g_main_loop_new(worker_context, FALSE); =20 + /* To kick any packets that the secondary doesn't match */ + timeout_source =3D g_timeout_source_new(REGULAR_PACKET_CHECK_MS); + g_source_set_callback(timeout_source, + (GSourceFunc)check_old_packet_regular, s, NULL); + g_source_attach(timeout_source, worker_context); + g_main_loop_run(compare_loop); =20 + g_source_unref(timeout_source); g_main_loop_unref(compare_loop); g_main_context_unref(worker_context); return NULL; @@ -604,26 +619,6 @@ static int find_and_check_chardev(Chardev **chr, } =20 /* - * Check old packet regularly so it can watch for any packets - * that the secondary hasn't produced equivalents of. - */ -static void check_old_packet_regular(void *opaque) -{ - CompareState *s =3D opaque; - - timer_mod(s->timer, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) + - REGULAR_PACKET_CHECK_MS); - /* if have old packet we will notify checkpoint */ - /* - * TODO: Make timer handler run in compare thread - * like qemu_chr_add_handlers_full. - */ - qemu_mutex_lock(&s->timer_check_lock); - colo_old_packet_check(s); - qemu_mutex_unlock(&s->timer_check_lock); -} - -/* * Called from the main thread on the primary * to setup colo-compare. */ @@ -665,7 +660,6 @@ static void colo_compare_complete(UserCreatable *uc, Er= ror **errp) net_socket_rs_init(&s->sec_rs, compare_sec_rs_finalize); =20 g_queue_init(&s->conn_list); - qemu_mutex_init(&s->timer_check_lock); =20 s->connection_track_table =3D g_hash_table_new_full(connection_key_has= h, connection_key_equal, @@ -678,12 +672,6 @@ static void colo_compare_complete(UserCreatable *uc, E= rror **errp) QEMU_THREAD_JOINABLE); compare_id++; =20 - /* A regular timer to kick any packets that the secondary doesn't matc= h */ - s->timer =3D timer_new_ms(QEMU_CLOCK_VIRTUAL, /* Only when guest runs = */ - check_old_packet_regular, s); - timer_mod(s->timer, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) + - REGULAR_PACKET_CHECK_MS); - return; } =20 @@ -723,12 +711,6 @@ static void colo_compare_finalize(Object *obj) qemu_thread_join(&s->thread); } =20 - if (s->timer) { - timer_del(s->timer); - } - - qemu_mutex_destroy(&s->timer_check_lock); - g_free(s->pri_indev); g_free(s->sec_indev); g_free(s->outdev); --=20 1.8.3.1 From nobody Mon Apr 29 20:34:51 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1487147812421506.58484548298816; Wed, 15 Feb 2017 00:36:52 -0800 (PST) Received: from localhost ([::1]:39054 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cdv50-0000wo-RU for importer@patchew.org; Wed, 15 Feb 2017 03:36:50 -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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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; =20 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 =3D opaque; GSource *timeout_source; =20 @@ -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); =20 - compare_loop =3D g_main_loop_new(worker_context, FALSE); + s->compare_loop =3D g_main_loop_new(worker_context, FALSE); =20 /* To kick any packets that the secondary doesn't match */ timeout_source =3D 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); =20 - g_main_loop_run(compare_loop); + g_main_loop_run(s->compare_loop); =20 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); =20 - g_queue_free(&s->conn_list); + g_main_loop_quit(s->compare_loop); + qemu_thread_join(&s->thread); =20 - 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); =20 g_free(s->pri_indev); g_free(s->sec_indev); --=20 1.8.3.1 From nobody Mon Apr 29 20:34:51 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1487147814432845.5291656231552; Wed, 15 Feb 2017 00:36:54 -0800 (PST) Received: from localhost ([::1]:39055 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cdv53-0000yR-5J for importer@patchew.org; Wed, 15 Feb 2017 03:36:53 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38057) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cdv3B-0008Ew-R9 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 1cdv37-0007Zg-5m for qemu-devel@nongnu.org; Wed, 15 Feb 2017 03:34:57 -0500 Received: from szxga03-in.huawei.com ([119.145.14.66]:44864) by eggs.gnu.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.71) (envelope-from ) id 1cdv36-0007Th-Im for qemu-devel@nongnu.org; Wed, 15 Feb 2017 03:34:53 -0500 Received: from 172.24.1.137 (EHLO szxeml430-hub.china.huawei.com) ([172.24.1.137]) by szxrg03-dlp.huawei.com (MOS 4.4.3-GA FastPath queued) with ESMTP id CPF49041; Wed, 15 Feb 2017 16:34:42 +0800 (CST) Received: from localhost (10.177.24.212) by szxeml430-hub.china.huawei.com (10.82.67.185) with Microsoft SMTP Server id 14.3.235.1; Wed, 15 Feb 2017 16:34:35 +0800 From: zhanghailiang To: , , Date: Wed, 15 Feb 2017 16:34:15 +0800 Message-ID: <1487147657-166092-4-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 3/5] colo-compare: release all unhandled packets in finalize function 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" We should release all unhandled packets before finalize colo compare. Besides, we need to free connection_track_table, or there will be a memory leak bug. Signed-off-by: zhanghailiang --- net/colo-compare.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/net/colo-compare.c b/net/colo-compare.c index a16e2d5..809bad3 100644 --- a/net/colo-compare.c +++ b/net/colo-compare.c @@ -676,6 +676,23 @@ static void colo_compare_complete(UserCreatable *uc, E= rror **errp) return; } =20 +static void colo_release_packets(void *opaque, void *user_data) +{ + CompareState *s =3D user_data; + Connection *conn =3D opaque; + Packet *pkt =3D NULL; + + while (!g_queue_is_empty(&conn->primary_list)) { + pkt =3D g_queue_pop_head(&conn->primary_list); + compare_chr_send(&s->chr_out, pkt->data, pkt->size); + packet_destroy(pkt, NULL); + } + while (!g_queue_is_empty(&conn->secondary_list)) { + pkt =3D g_queue_pop_head(&conn->secondary_list); + packet_destroy(pkt, NULL); + } +} + static void colo_compare_class_init(ObjectClass *oc, void *data) { UserCreatableClass *ucc =3D USER_CREATABLE_CLASS(oc); @@ -707,9 +724,12 @@ static void colo_compare_finalize(Object *obj) g_main_loop_quit(s->compare_loop); qemu_thread_join(&s->thread); =20 + /* Release all unhandled packets after compare thead exited */ + g_queue_foreach(&s->conn_list, colo_release_packets, s); =20 g_queue_free(&s->conn_list); =20 + g_hash_table_destroy(s->connection_track_table); g_free(s->pri_indev); g_free(s->sec_indev); g_free(s->outdev); --=20 1.8.3.1 From nobody Mon Apr 29 20:34:51 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1487147815799376.72917088329757; Wed, 15 Feb 2017 00:36:55 -0800 (PST) Received: from localhost ([::1]:39057 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cdv54-0000zt-Gx for importer@patchew.org; Wed, 15 Feb 2017 03:36:54 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38099) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cdv3D-0008FD-AL for qemu-devel@nongnu.org; Wed, 15 Feb 2017 03:35:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cdv3C-0007cp-4n for qemu-devel@nongnu.org; Wed, 15 Feb 2017 03:34:59 -0500 Received: from szxga03-in.huawei.com ([119.145.14.66]:44929) by eggs.gnu.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.71) (envelope-from ) id 1cdv3B-0007aB-Iz for qemu-devel@nongnu.org; Wed, 15 Feb 2017 03:34:58 -0500 Received: from 172.24.1.137 (EHLO szxeml430-hub.china.huawei.com) ([172.24.1.137]) by szxrg03-dlp.huawei.com (MOS 4.4.3-GA FastPath queued) with ESMTP id CPF49042; Wed, 15 Feb 2017 16:34:42 +0800 (CST) Received: from localhost (10.177.24.212) by szxeml430-hub.china.huawei.com (10.82.67.185) with Microsoft SMTP Server id 14.3.235.1; Wed, 15 Feb 2017 16:34:36 +0800 From: zhanghailiang To: , , Date: Wed, 15 Feb 2017 16:34:16 +0800 Message-ID: <1487147657-166092-5-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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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 4/5] char: remove the right fd been watched in qemu_chr_fe_set_handlers() 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: xuquan8@huawei.com, zhanghailiang , qemu-devel@nongnu.org, pss.wulizhen@huawei.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 We can call qemu_chr_fe_set_handlers() to add/remove fd been watched in 'context' which can be either default main context or other explicit context. But the original logic is not correct, we didn't remove the right fd because we call g_main_context_find_source_by_id(NULL, tag) which always try to find the Gsource from default context. Fix it by passing the right context to g_main_context_find_source_by_id(). Cc: Paolo Bonzini Cc: Marc-Andr=C3=A9 Lureau Signed-off-by: zhanghailiang --- chardev/char-io.c | 13 +++++++++---- chardev/char-io.h | 2 ++ chardev/char.c | 2 +- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/chardev/char-io.c b/chardev/char-io.c index 7dfc3f2..a69cc61 100644 --- a/chardev/char-io.c +++ b/chardev/char-io.c @@ -127,14 +127,14 @@ guint io_add_watch_poll(Chardev *chr, return tag; } =20 -static void io_remove_watch_poll(guint tag) +static void io_remove_watch_poll(guint tag, GMainContext *context) { GSource *source; IOWatchPoll *iwp; =20 g_return_if_fail(tag > 0); =20 - source =3D g_main_context_find_source_by_id(NULL, tag); + source =3D g_main_context_find_source_by_id(context, tag); g_return_if_fail(source !=3D NULL); =20 iwp =3D io_watch_poll_from_source(source); @@ -146,14 +146,19 @@ static void io_remove_watch_poll(guint tag) g_source_destroy(&iwp->parent); } =20 -void remove_fd_in_watch(Chardev *chr) +void qemu_remove_fd_in_watch(Chardev *chr, GMainContext *context) { if (chr->fd_in_tag) { - io_remove_watch_poll(chr->fd_in_tag); + io_remove_watch_poll(chr->fd_in_tag, context); chr->fd_in_tag =3D 0; } } =20 +void remove_fd_in_watch(Chardev *chr) +{ + qemu_remove_fd_in_watch(chr, NULL); +} + int io_channel_send_full(QIOChannel *ioc, const void *buf, size_t len, int *fds, size_t nfds) diff --git a/chardev/char-io.h b/chardev/char-io.h index d7ae5f1..117c888 100644 --- a/chardev/char-io.h +++ b/chardev/char-io.h @@ -38,6 +38,8 @@ guint io_add_watch_poll(Chardev *chr, =20 void remove_fd_in_watch(Chardev *chr); =20 +void qemu_remove_fd_in_watch(Chardev *chr, GMainContext *context); + int io_channel_send(QIOChannel *ioc, const void *buf, size_t len); =20 int io_channel_send_full(QIOChannel *ioc, const void *buf, size_t len, diff --git a/chardev/char.c b/chardev/char.c index abd525f..5563375 100644 --- a/chardev/char.c +++ b/chardev/char.c @@ -560,7 +560,7 @@ void qemu_chr_fe_set_handlers(CharBackend *b, cc =3D CHARDEV_GET_CLASS(s); if (!opaque && !fd_can_read && !fd_read && !fd_event) { fe_open =3D 0; - remove_fd_in_watch(s); + qemu_remove_fd_in_watch(s, context); } else { fe_open =3D 1; } --=20 1.8.3.1 From nobody Mon Apr 29 20:34:51 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1487148026703645.0800907437966; Wed, 15 Feb 2017 00:40:26 -0800 (PST) Received: from localhost ([::1]:39071 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cdv8T-0004rm-FQ for importer@patchew.org; Wed, 15 Feb 2017 03:40:25 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38092) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cdv3C-0008F4-Ve for qemu-devel@nongnu.org; Wed, 15 Feb 2017 03:35:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cdv38-0007a8-7u for qemu-devel@nongnu.org; Wed, 15 Feb 2017 03:34:59 -0500 Received: from szxga01-in.huawei.com ([58.251.152.64]:38294) by eggs.gnu.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.71) (envelope-from ) id 1cdv37-0007Wz-Fn for qemu-devel@nongnu.org; Wed, 15 Feb 2017 03:34:54 -0500 Received: from 172.24.1.136 (EHLO szxeml434-hub.china.huawei.com) ([172.24.1.136]) by szxrg01-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id DZA13704; Wed, 15 Feb 2017 16:34:45 +0800 (CST) Received: from localhost (10.177.24.212) by szxeml434-hub.china.huawei.com (10.82.67.225) with Microsoft SMTP Server id 14.3.235.1; Wed, 15 Feb 2017 16:34:36 +0800 From: zhanghailiang To: , , Date: Wed, 15 Feb 2017 16:34:17 +0800 Message-ID: <1487147657-166092-6-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-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A090201.58A412A7.00E4, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2013-06-18 04:22:30, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 667a89c05389ec5bb0e2fe13edd1dc99 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] [fuzzy] X-Received-From: 58.251.152.64 Subject: [Qemu-devel] [PATCH 5/5] colo-compare: Fix removing fds been watched incorrectly in finalization 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" We will catch the bellow error report while try to delete compare object by qmp command: chardev/char-io.c:91: io_watch_poll_finalize: Assertion `iwp->src =3D=3D ((= void *)0)' failed. This is caused by failing to remove the right fd been watched while call qemu_chr_fe_set_handlers(); Fix it by pass the worker_context parameter to qemu_chr_fe_set_handlers(). Signed-off-by: zhanghailiang --- net/colo-compare.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/net/colo-compare.c b/net/colo-compare.c index 809bad3..4c74b02 100644 --- a/net/colo-compare.c +++ b/net/colo-compare.c @@ -84,6 +84,7 @@ typedef struct CompareState { /* compare thread, a thread for each NIC */ QemuThread thread; =20 + GMainContext *worker_context; GMainLoop *compare_loop; } CompareState; =20 @@ -497,30 +498,29 @@ static gboolean check_old_packet_regular(void *opaque) =20 static void *colo_compare_thread(void *opaque) { - GMainContext *worker_context; CompareState *s =3D opaque; GSource *timeout_source; =20 - worker_context =3D g_main_context_new(); + s->worker_context =3D g_main_context_new(); =20 qemu_chr_fe_set_handlers(&s->chr_pri_in, compare_chr_can_read, - compare_pri_chr_in, NULL, s, worker_context, = true); + compare_pri_chr_in, NULL, s, s->worker_context, = true); qemu_chr_fe_set_handlers(&s->chr_sec_in, compare_chr_can_read, - compare_sec_chr_in, NULL, s, worker_context, = true); + compare_sec_chr_in, NULL, s, s->worker_context, = true); =20 - s->compare_loop =3D g_main_loop_new(worker_context, FALSE); + s->compare_loop =3D g_main_loop_new(s->worker_context, FALSE); =20 /* To kick any packets that the secondary doesn't match */ timeout_source =3D g_timeout_source_new(REGULAR_PACKET_CHECK_MS); g_source_set_callback(timeout_source, (GSourceFunc)check_old_packet_regular, s, NULL); - g_source_attach(timeout_source, worker_context); + g_source_attach(timeout_source, s->worker_context); =20 g_main_loop_run(s->compare_loop); =20 g_source_unref(timeout_source); g_main_loop_unref(s->compare_loop); - g_main_context_unref(worker_context); + g_main_context_unref(s->worker_context); return NULL; } =20 @@ -717,8 +717,10 @@ static void colo_compare_finalize(Object *obj) { CompareState *s =3D COLO_COMPARE(obj); =20 - qemu_chr_fe_deinit(&s->chr_pri_in); - qemu_chr_fe_deinit(&s->chr_sec_in); + qemu_chr_fe_set_handlers(&s->chr_pri_in, NULL, NULL, NULL, NULL, + s->worker_context, true); + qemu_chr_fe_set_handlers(&s->chr_sec_in, NULL, NULL, NULL, NULL, + s->worker_context, true); qemu_chr_fe_deinit(&s->chr_out); =20 g_main_loop_quit(s->compare_loop); --=20 1.8.3.1