From patchwork Thu Feb 16 06:00:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Zhanghailiang X-Patchwork-Id: 9576545 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 C98DC60244 for ; Thu, 16 Feb 2017 06:07:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B9FB8284F0 for ; Thu, 16 Feb 2017 06:07:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ACA8E2851A; Thu, 16 Feb 2017 06:07:11 +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 10ABD284F0 for ; Thu, 16 Feb 2017 06:07:11 +0000 (UTC) Received: from localhost ([::1]:44744 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ceFDi-0000JV-5j for patchwork-qemu-devel@patchwork.kernel.org; Thu, 16 Feb 2017 01:07:10 -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 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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é 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; } -static void io_remove_watch_poll(guint tag) +static void io_remove_watch_poll(guint tag, GMainContext *context) { GSource *source; IOWatchPoll *iwp; g_return_if_fail(tag > 0); - source = g_main_context_find_source_by_id(NULL, tag); + source = g_main_context_find_source_by_id(context, tag); g_return_if_fail(source != NULL); iwp = io_watch_poll_from_source(source); @@ -146,14 +146,19 @@ static void io_remove_watch_poll(guint tag) g_source_destroy(&iwp->parent); } -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 = 0; } } +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, void remove_fd_in_watch(Chardev *chr); +void qemu_remove_fd_in_watch(Chardev *chr, GMainContext *context); + int io_channel_send(QIOChannel *ioc, const void *buf, size_t len); 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 = CHARDEV_GET_CLASS(s); if (!opaque && !fd_can_read && !fd_read && !fd_event) { fe_open = 0; - remove_fd_in_watch(s); + qemu_remove_fd_in_watch(s, context); } else { fe_open = 1; }