From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.7 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8AB35C3A5A4 for ; Tue, 27 Aug 2019 08:33:52 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 603E22173E for ; Tue, 27 Aug 2019 08:33:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 603E22173E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=sipsolutions.net Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:48150 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i2WvH-0005Ol-AE for qemu-devel@archiver.kernel.org; Tue, 27 Aug 2019 04:33:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37830) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i2Wt5-00047d-7U for qemu-devel@nongnu.org; Tue, 27 Aug 2019 04:31:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i2Wt3-0002Qv-3f for qemu-devel@nongnu.org; Tue, 27 Aug 2019 04:31:34 -0400 Received: from s3.sipsolutions.net ([2a01:4f8:191:4433::2]:40188 helo=sipsolutions.net) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i2Wt2-0002Ow-SD for qemu-devel@nongnu.org; Tue, 27 Aug 2019 04:31:33 -0400 Received: by sipsolutions.net with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1i2Wsw-0002r1-Ai; Tue, 27 Aug 2019 10:31:26 +0200 From: Johannes Berg To: qemu-devel@nongnu.org Date: Tue, 27 Aug 2019 11:31:24 +0300 Message-Id: <20190827083124.30791-1-johannes@sipsolutions.net> X-Mailer: git-send-email 2.23.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a01:4f8:191:4433::2 Subject: [Qemu-devel] [PATCH] libvhost-user-glib: fix VugDev main fd cleanup X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Johannes Berg Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Johannes Berg If you try to make a device implementation that can handle multiple connections and allow disconnections (which requires overriding the VHOST_USER_NONE handling), then glib will warn that we remove a src while it's still on the mainloop, and will poll() an FD that doesn't exist anymore. Fix this by just using the internal add_watch() function that has all necessary cleanups built in via the hashtable, rather than treating the "main" fd of a device specially. Fixes: 8bb7ddb78a1c ("libvhost-user: add glib source helper") Signed-off-by: Johannes Berg --- contrib/libvhost-user/libvhost-user-glib.c | 3 +-- contrib/libvhost-user/libvhost-user-glib.h | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/contrib/libvhost-user/libvhost-user-glib.c b/contrib/libvhost-user/libvhost-user-glib.c index 99edd2f3de45..a092a55c1d57 100644 --- a/contrib/libvhost-user/libvhost-user-glib.c +++ b/contrib/libvhost-user/libvhost-user-glib.c @@ -146,7 +146,7 @@ vug_init(VugDev *dev, uint16_t max_queues, int socket, dev->fdmap = g_hash_table_new_full(NULL, NULL, NULL, (GDestroyNotify) g_source_destroy); - dev->src = vug_source_new(dev, socket, G_IO_IN, vug_watch, NULL); + set_watch(&dev->parent, socket, VU_WATCH_IN, vug_watch, NULL); return true; } @@ -157,5 +157,4 @@ vug_deinit(VugDev *dev) g_assert(dev); g_hash_table_unref(dev->fdmap); - g_source_unref(dev->src); } diff --git a/contrib/libvhost-user/libvhost-user-glib.h b/contrib/libvhost-user/libvhost-user-glib.h index 64d539d93aba..32a6ec6df063 100644 --- a/contrib/libvhost-user/libvhost-user-glib.h +++ b/contrib/libvhost-user/libvhost-user-glib.h @@ -22,7 +22,6 @@ typedef struct VugDev { VuDev parent; GHashTable *fdmap; /* fd -> gsource */ - GSource *src; } VugDev; bool vug_init(VugDev *dev, uint16_t max_queues, int socket, -- 2.23.0