From nobody Fri May 3 06:44:47 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 1487224969355911.0647311978418; Wed, 15 Feb 2017 22:02:49 -0800 (PST) Received: from localhost ([::1]:44715 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ceF9T-0004A2-S9 for importer@patchew.org; Thu, 16 Feb 2017 01:02:47 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46239) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ceF7r-0003Bp-1Q for qemu-devel@nongnu.org; Thu, 16 Feb 2017 01:01:08 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ceF7o-0003BE-1B for qemu-devel@nongnu.org; Thu, 16 Feb 2017 01:01:07 -0500 Received: from szxga03-in.huawei.com ([119.145.14.66]:59311) by eggs.gnu.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.71) (envelope-from ) id 1ceF7n-0003Am-7z for qemu-devel@nongnu.org; Thu, 16 Feb 2017 01:01:03 -0500 Received: from 172.24.1.36 (EHLO SZXEML429-HUB.china.huawei.com) ([172.24.1.36]) by szxrg03-dlp.huawei.com (MOS 4.4.3-GA FastPath queued) with ESMTP id CPG27960; Thu, 16 Feb 2017 14:00:57 +0800 (CST) Received: from localhost (10.177.24.212) by SZXEML429-HUB.china.huawei.com (10.82.67.184) with Microsoft SMTP Server id 14.3.235.1; Thu, 16 Feb 2017 14:00:48 +0800 From: zhanghailiang To: , , Date: Thu, 16 Feb 2017 14:00:18 +0800 Message-ID: <1487224821-120916-2-git-send-email-zhang.zhanghailiang@huawei.com> X-Mailer: git-send-email 2.7.2.windows.1 In-Reply-To: <1487224821-120916-1-git-send-email-zhang.zhanghailiang@huawei.com> References: <1487224821-120916-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 v2 1/4] 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 Fri May 3 06:44:47 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 148722520232627.31306768735999; Wed, 15 Feb 2017 22:06:42 -0800 (PST) Received: from localhost ([::1]:44742 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ceFDE-00086r-MR for importer@patchew.org; Thu, 16 Feb 2017 01:06:40 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46252) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ceF7s-0003CP-4r for qemu-devel@nongnu.org; Thu, 16 Feb 2017 01:01:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ceF7p-0003BX-FF for qemu-devel@nongnu.org; Thu, 16 Feb 2017 01:01:08 -0500 Received: from szxga01-in.huawei.com ([58.251.152.64]:14595) by eggs.gnu.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.71) (envelope-from ) id 1ceF7o-0003Ax-No for qemu-devel@nongnu.org; Thu, 16 Feb 2017 01:01:05 -0500 Received: from 172.24.1.47 (EHLO szxeml425-hub.china.huawei.com) ([172.24.1.47]) by szxrg01-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id DZA88895; Thu, 16 Feb 2017 14:00:58 +0800 (CST) Received: from localhost (10.177.24.212) by szxeml425-hub.china.huawei.com (10.82.67.180) with Microsoft SMTP Server id 14.3.235.1; Thu, 16 Feb 2017 14:00:49 +0800 From: zhanghailiang To: , , Date: Thu, 16 Feb 2017 14:00:19 +0800 Message-ID: <1487224821-120916-3-git-send-email-zhang.zhanghailiang@huawei.com> X-Mailer: git-send-email 2.7.2.windows.1 In-Reply-To: <1487224821-120916-1-git-send-email-zhang.zhanghailiang@huawei.com> References: <1487224821-120916-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.0A020201.58A5401B.02E6, 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: b969544231a3620a90e43d2f8c6c0b29 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 v2 2/4] colo-compare: kick compare thread to exit after some cleanup 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 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. Before compare thead exits, some cleanup works need to be done, All unhandled packets need to be released and connection_track_table needs to be freed, or there will be memory leak. Signed-off-by: zhanghailiang --- net/colo-compare.c | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/net/colo-compare.c b/net/colo-compare.c index fdde788..37ce75c 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; } @@ -675,6 +676,23 @@ static void colo_compare_complete(UserCreatable *uc, E= rror **errp) return; } =20 +static void colo_flush_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); @@ -703,14 +721,15 @@ 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); - } + /* Release all unhandled packets after compare thead exited */ + g_queue_foreach(&s->conn_list, colo_flush_packets, s); + + 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 Fri May 3 06:44:47 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 1487225285189812.3805726369252; Wed, 15 Feb 2017 22:08:05 -0800 (PST) Received: from localhost ([::1]:44749 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ceFEZ-0001Zk-If for importer@patchew.org; Thu, 16 Feb 2017 01:08:03 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46331) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ceF85-0003Oq-Oy for qemu-devel@nongnu.org; Thu, 16 Feb 2017 01:01:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ceF82-0003HU-OR for qemu-devel@nongnu.org; Thu, 16 Feb 2017 01:01:21 -0500 Received: from szxga01-in.huawei.com ([58.251.152.64]:14916) by eggs.gnu.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.71) (envelope-from ) id 1ceF82-0003ER-1X for qemu-devel@nongnu.org; Thu, 16 Feb 2017 01:01:18 -0500 Received: from 172.24.1.60 (EHLO szxeml427-hub.china.huawei.com) ([172.24.1.60]) by szxrg01-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id DZA88894; Thu, 16 Feb 2017 14:00:58 +0800 (CST) Received: from localhost (10.177.24.212) by szxeml427-hub.china.huawei.com (10.82.67.182) with Microsoft SMTP Server id 14.3.235.1; Thu, 16 Feb 2017 14:00:50 +0800 From: zhanghailiang To: , , Date: Thu, 16 Feb 2017 14:00:20 +0800 Message-ID: <1487224821-120916-4-git-send-email-zhang.zhanghailiang@huawei.com> X-Mailer: git-send-email 2.7.2.windows.1 In-Reply-To: <1487224821-120916-1-git-send-email-zhang.zhanghailiang@huawei.com> References: <1487224821-120916-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-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020201.58A5401A.022F, 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: 25bd512f82c655bce90837bebc0e3ab4 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 v2 3/4] 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 Fri May 3 06:44:47 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 1487225103979176.1726322357456; Wed, 15 Feb 2017 22:05:03 -0800 (PST) Received: from localhost ([::1]:44723 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ceFBe-0006eW-P1 for importer@patchew.org; Thu, 16 Feb 2017 01:05:02 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46270) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ceF7u-0003Dg-2p for qemu-devel@nongnu.org; Thu, 16 Feb 2017 01:01:11 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ceF7t-0003Cd-Ba for qemu-devel@nongnu.org; Thu, 16 Feb 2017 01:01:10 -0500 Received: from szxga01-in.huawei.com ([58.251.152.64]:14615) by eggs.gnu.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.71) (envelope-from ) id 1ceF7s-0003BN-JM for qemu-devel@nongnu.org; Thu, 16 Feb 2017 01:01:09 -0500 Received: from 172.24.1.136 (EHLO szxeml428-hub.china.huawei.com) ([172.24.1.136]) by szxrg01-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id DZA88896; Thu, 16 Feb 2017 14:00:59 +0800 (CST) Received: from localhost (10.177.24.212) by szxeml428-hub.china.huawei.com (10.82.67.183) with Microsoft SMTP Server id 14.3.235.1; Thu, 16 Feb 2017 14:00:51 +0800 From: zhanghailiang To: , , Date: Thu, 16 Feb 2017 14:00:21 +0800 Message-ID: <1487224821-120916-5-git-send-email-zhang.zhanghailiang@huawei.com> X-Mailer: git-send-email 2.7.2.windows.1 In-Reply-To: <1487224821-120916-1-git-send-email-zhang.zhanghailiang@huawei.com> References: <1487224821-120916-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.0A020204.58A54020.0160, 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: e9d2756a1b6e82bdcead10da042578ba 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 v2 4/4] 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 37ce75c..a6fc2ff 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