From nobody Tue Nov 11 22:52:44 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1566894837; cv=none; d=zoho.com; s=zohoarc; b=JCUOdgTaiW2ni2ZPBAq5H3nvx2jxbNsk0oXVCeFKVir06rMrzY1U3TTZEcAlnk174/psbU672Bv7eC87i6FjdlfuhK4xRgE30jFxoAmioDDUsD2FXZt9mfff7mzo4w4lcSA3IcLwO8l8sOBlwFeBYJanmGqnzMScwBhd2mgO724= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1566894837; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To:ARC-Authentication-Results; bh=sEUpG06nV7FI/6sgSsvMzMWO4RNYTPYqov7+ZylFC2U=; b=LLoT8VEWlW5CbVK+fsAakitQTQ+Fx4SFBfyonlrFxOrHaQRsiZIVEuc3JY04WwVcOmlxB2cVI1Y8pv01hjsATLpSmvoC+Aw8sfJKUIFT59u79s41/nq81XwS0vTGCEeaQcY1/kacugXJGZeIM8nU5I3T57LU4u4bQzo1GXf+s24= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1566894837090445.61058832365075; Tue, 27 Aug 2019 01:33:57 -0700 (PDT) Received: from localhost ([::1]:48150 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i2WvL-0005Ol-UO for importer@patchew.org; Tue, 27 Aug 2019 04:33:55 -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: quoted-printable 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" 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 =3D g_hash_table_new_full(NULL, NULL, NULL, (GDestroyNotify) g_source_destroy); =20 - dev->src =3D vug_source_new(dev, socket, G_IO_IN, vug_watch, NULL); + set_watch(&dev->parent, socket, VU_WATCH_IN, vug_watch, NULL); =20 return true; } @@ -157,5 +157,4 @@ vug_deinit(VugDev *dev) g_assert(dev); =20 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; =20 GHashTable *fdmap; /* fd -> gsource */ - GSource *src; } VugDev; =20 bool vug_init(VugDev *dev, uint16_t max_queues, int socket, --=20 2.23.0