From nobody Sun Jan 25 10:13:57 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1769170999; cv=none; d=zohomail.com; s=zohoarc; b=kvat9KD996sfe1mt1WW+ggodcBmSAs9VdJkpD/30DyeyiRdeXaq9hk63vUXcGTBCnm9hupyXXoHkycQHjQfr760Vv9eTwoqHzTQB29vYcWkFgCxcN8KH+xuDD/mAlhl3C88EgJMM5ff9W6vlpMVpNC5hD8nUfyRUJerMmvxFtQY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1769170999; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=zmQ4kVlin0c8KBX0FvJaXZrddy4do6mTePX6ZqOzRJw=; b=MxLZXL0gaVc5X54WUvEnMkfbDmCBpMHH2dCGVPSZF82J3HeqCA4NKZWsqtDWiAGO2HadWqg2j3kWxaEm2XqIHi5PQ1yAx17CntQ1FUA0tZWwC0biNgQCw4q9w1I8zyr9dxygVSVQx+d1Q+Hfwzwg84y1dXAIMN54WLgeLaK6Qj8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1769170999627130.77350439542988; Fri, 23 Jan 2026 04:23:19 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vjGAC-0004wi-C6; Fri, 23 Jan 2026 07:21:20 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vjGA7-0004rf-B6 for qemu-devel@nongnu.org; Fri, 23 Jan 2026 07:21:15 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vjGA5-0004zx-TI for qemu-devel@nongnu.org; Fri, 23 Jan 2026 07:21:15 -0500 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-279-SVcLalIYOtuC5Vq_RBN9ZQ-1; Fri, 23 Jan 2026 07:21:11 -0500 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 812B719775AB for ; Fri, 23 Jan 2026 12:21:10 +0000 (UTC) Received: from localhost.localdomain (unknown [10.72.112.7]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 6276230002D1; Fri, 23 Jan 2026 12:21:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1769170873; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zmQ4kVlin0c8KBX0FvJaXZrddy4do6mTePX6ZqOzRJw=; b=f0uwKJ/07uu3F0HHdiGzsheV5Wpv+5/BSCJRIyT/ROpzMpw9VzKN3Lq4J2s+8IZFvBm/r+ jwcc06L9wzokrGwo5Ter/+Xmx3MBdR/i4ePEFoNKG2MkIk8vbDGm5ts+Lo/kvhVUBl61WP RH4Qz+I61oPsi6zKuBGDdX+ISkSP+xI= X-MC-Unique: SVcLalIYOtuC5Vq_RBN9ZQ-1 X-Mimecast-MFC-AGG-ID: SVcLalIYOtuC5Vq_RBN9ZQ_1769170870 From: Jason Wang To: qemu-devel@nongnu.org Cc: "Houqi (Nick) Zuo" , Jason Wang Subject: [PULL 01/13] net/tap-linux.c: avoid abort when setting invalid fd Date: Fri, 23 Jan 2026 20:20:50 +0800 Message-ID: <20260123122102.51422-2-jasowang@redhat.com> In-Reply-To: <20260123122102.51422-1-jasowang@redhat.com> References: <20260123122102.51422-1-jasowang@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=170.10.129.124; envelope-from=jasowang@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 12 X-Spam_score: 1.2 X-Spam_bar: + X-Spam_report: (1.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.079, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_SBL_CSS=3.335, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1769171003388154100 Content-Type: text/plain; charset="utf-8" From: "Houqi (Nick) Zuo" This patch removes abort() call in the tap_fd_set_vnet_hdr_len() function. If the fd is found to be in a bad state (e.g., EBADFD or ENODEV), the function will print an error message. When QEMU creates a tap device automatically and the tap device is manually removed from the host while the guest is running, the tap device file descriptor becomes invalid. Later, when the guest executes shutdown, the tap_fd_set_vnet_hdr_len() function may be called and abort QEMU with a core dump when attempting to use the invalid fd. The expected behavior for this negative test case is that QEMU should report an error but continue running rather than aborting. Testing: - Start QEMU with automatically created tap device - Manually remove the tap device on the host - Execute shutdown in the guest - Verify QEMU reports an error but does not abort Fixes: 0caed25cd171 ("virtio: Call set_features during reset") Signed-off-by: Houqi (Nick) Zuo Signed-off-by: Jason Wang --- net/tap-linux.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/net/tap-linux.c b/net/tap-linux.c index 909c4f1fcf..54de3cd06b 100644 --- a/net/tap-linux.c +++ b/net/tap-linux.c @@ -214,10 +214,11 @@ bool tap_probe_has_tunnel(int fd) =20 void tap_fd_set_vnet_hdr_len(int fd, int len) { - if (ioctl(fd, TUNSETVNETHDRSZ, &len) =3D=3D -1) { - fprintf(stderr, "TUNSETVNETHDRSZ ioctl() failed: %s. Exiting.\n", - strerror(errno)); - abort(); + int ret; + + ret =3D ioctl(fd, TUNSETVNETHDRSZ, &len); + if (ret !=3D 0) { + error_report("TUNSETVNETHDRSZ ioctl() failed: %s.", strerror(errno= )); } } =20 --=20 2.42.0 From nobody Sun Jan 25 10:13:57 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1769171106; cv=none; d=zohomail.com; s=zohoarc; b=i+HHKzdSrqxsyxRKn+PbeIyoKTJBg+ufHMDu4bGuwZFj+CyYNj16l03fK1g6lVy2IsBXelvAH2P6y1NpRTGc5n5XmWORD4D26pMC05zD4D+emnya6gcxBvmjzKHDf0aPdwvzKtb9JXo4dI9On6ACdprq/UkJ4tVCXzlQXqg+R5g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1769171106; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=cKqukgA4xLz4LCaAwon0HAS7jLqYicKn6A+YO2XVudU=; b=BRMc16tKNETAtz0y98/wzLkFXY+OjVOKgISx3lXPW0dS3hQPXf6VN5q+bFRGQN1VZOZ8PwktQKQPlWt6i0gAqTWmHkUaVlcSytB/9ah5xvLDNetIEUS3TehZXZizE4LVRM/yyfwwPAFEAWxn7YIOVTfibXmSpU2aViOjn9CcAm0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1769171106591933.4112823417956; Fri, 23 Jan 2026 04:25:06 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vjGAd-0005BM-Fp; Fri, 23 Jan 2026 07:21:47 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vjGAD-0004z0-5K for qemu-devel@nongnu.org; Fri, 23 Jan 2026 07:21:23 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vjGAB-00051G-Ov for qemu-devel@nongnu.org; Fri, 23 Jan 2026 07:21:20 -0500 Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-515-dAaIsS79OR6vXjqRVDmaDw-1; Fri, 23 Jan 2026 07:21:15 -0500 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 607271944B0C; Fri, 23 Jan 2026 12:21:14 +0000 (UTC) Received: from localhost.localdomain (unknown [10.72.112.7]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 5613230002DC; Fri, 23 Jan 2026 12:21:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1769170879; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cKqukgA4xLz4LCaAwon0HAS7jLqYicKn6A+YO2XVudU=; b=ZgJxueMwpkosxmcJVciRUdOKu1Rp1dZ0dQI/ziMYQyw05kXKxW+l0WCy1uYt51d3Fw28/I OLvxXvf9y3t1pdAwuhaBnK7i4ZhnNfFLXAaWm1vZgvFmQkgs1Iae03fYieiW0mjwQ7TYG2 jng9rqsFL8pCNMq7EBOLxKX0cJiXn5U= X-MC-Unique: dAaIsS79OR6vXjqRVDmaDw-1 X-Mimecast-MFC-AGG-ID: dAaIsS79OR6vXjqRVDmaDw_1769170875 From: Jason Wang To: qemu-devel@nongnu.org Cc: Vladimir Sementsov-Ogievskiy , Maksim Davydov , Jason Wang Subject: [PULL 02/13] net/tap: net_init_tap_one(): drop extra error propagation Date: Fri, 23 Jan 2026 20:20:51 +0800 Message-ID: <20260123122102.51422-3-jasowang@redhat.com> In-Reply-To: <20260123122102.51422-1-jasowang@redhat.com> References: <20260123122102.51422-1-jasowang@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=170.10.129.124; envelope-from=jasowang@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 12 X-Spam_score: 1.2 X-Spam_bar: + X-Spam_report: (1.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.079, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_SBL_CSS=3.335, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1769171108343158500 Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Maksim Davydov Signed-off-by: Jason Wang --- net/tap.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/net/tap.c b/net/tap.c index bfba3fd7a7..c162523a03 100644 --- a/net/tap.c +++ b/net/tap.c @@ -736,9 +736,8 @@ static void net_init_tap_one(const NetdevTapOptions *ta= p, NetClientState *peer, } =20 if (vhostfdname) { - vhostfd =3D monitor_fd_param(monitor_cur(), vhostfdname, &err); + vhostfd =3D monitor_fd_param(monitor_cur(), vhostfdname, errp); if (vhostfd =3D=3D -1) { - error_propagate(errp, err); goto failed; } if (!qemu_set_blocking(vhostfd, false, errp)) { --=20 2.42.0 From nobody Sun Jan 25 10:13:57 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1769171032; cv=none; d=zohomail.com; s=zohoarc; b=gFiODrdeTurAGv3Tru4BdacGG3EICxvixOG9hSJLGFzEQBBzEcTMi7xDLZGG8uQAZ4cLsy73Ini9DHCry7+NmRwl65ekK857S+tuzb+lVnQCdy8ISgwMt6fLv5BSoJoHJNPJ6DhZor1wYoNt/QlxxBK7hSMP5UKRC4GR505gx2w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1769171032; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=tHr9OZZi/YA1GRFV9Q1h9pRGKpldGn1ZYzdmXBoPg7w=; b=UAgkfww5Kb0QAPceGH9NrjDPJ3uomSzKsLi101snPEuW1V3ufu1jXF1lwK/EQvLhQAQ8p10+rxaRL4oo+VoJw7JFn2cK0h94TxbirXxXnvIwUguVIZb88fGgeihryjKfx+7pRYsHr/fs9vK4GCWq5aHdYA/Y0JfkFehc/BMdIok= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1769171032067130.15129245357468; Fri, 23 Jan 2026 04:23:52 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vjGAc-00058h-Fu; Fri, 23 Jan 2026 07:21:47 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vjGAI-00050S-6o for qemu-devel@nongnu.org; Fri, 23 Jan 2026 07:21:30 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vjGAF-00051v-CC for qemu-devel@nongnu.org; Fri, 23 Jan 2026 07:21:24 -0500 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-244-phwW_jqYN2-Gdo8a14AHWA-1; Fri, 23 Jan 2026 07:21:19 -0500 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 1E96318005AE; Fri, 23 Jan 2026 12:21:18 +0000 (UTC) Received: from localhost.localdomain (unknown [10.72.112.7]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 531C630002D1; Fri, 23 Jan 2026 12:21:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1769170882; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tHr9OZZi/YA1GRFV9Q1h9pRGKpldGn1ZYzdmXBoPg7w=; b=b9/EWLwEr5rgDZh0O75Oe/dM6ZNXb1XYJSafhf5rnmpqtg4J4KfODPjmscbrgCMUJr6hY4 XVp7t8I1wxVKU2kR2GMuG9uKPKslzvLBawu/SecA7goflzQngUklQQkN905c8kJ6uQWplh GJCjhDa+JhU4o8jhdfTtRO1EVXYDRwo= X-MC-Unique: phwW_jqYN2-Gdo8a14AHWA-1 X-Mimecast-MFC-AGG-ID: phwW_jqYN2-Gdo8a14AHWA_1769170878 From: Jason Wang To: qemu-devel@nongnu.org Cc: Vladimir Sementsov-Ogievskiy , Maksim Davydov , Jason Wang Subject: [PULL 03/13] net/tap: net_init_tap_one(): move parameter checking earlier Date: Fri, 23 Jan 2026 20:20:52 +0800 Message-ID: <20260123122102.51422-4-jasowang@redhat.com> In-Reply-To: <20260123122102.51422-1-jasowang@redhat.com> References: <20260123122102.51422-1-jasowang@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=170.10.133.124; envelope-from=jasowang@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.079, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1769171034499158500 Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy Let's keep all similar argument checking in net_init_tap() function. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Maksim Davydov Signed-off-by: Jason Wang --- net/tap.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/net/tap.c b/net/tap.c index c162523a03..abeee6be11 100644 --- a/net/tap.c +++ b/net/tap.c @@ -767,9 +767,6 @@ static void net_init_tap_one(const NetdevTapOptions *ta= p, NetClientState *peer, "vhost-net requested but could not be initialized"); goto failed; } - } else if (vhostfdname) { - error_setg(errp, "vhostfd(s)=3D is not valid without vhost"); - goto failed; } =20 return; @@ -831,6 +828,11 @@ int net_init_tap(const Netdev *netdev, const char *nam= e, return -1; } =20 + if (tap->has_vhost && !tap->vhost && (tap->vhostfds || tap->vhostfd)) { + error_setg(errp, "vhostfd(s)=3D is not valid without vhost"); + return -1; + } + if (tap->fd) { if (tap->ifname || tap->script || tap->downscript || tap->has_vnet_hdr || tap->helper || tap->has_queues || --=20 2.42.0 From nobody Sun Jan 25 10:13:57 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1769171251; cv=none; d=zohomail.com; s=zohoarc; b=mB7dV81QetJhQhv25F4sYb8dUNEhznxrTJjZWcbdCJGVg+hD6UmGmm9+q9a5D+gCaqhm0JT61Nrmvhlq+cQyYp/l4+f4aSYe5/PzIunZKTwn3f5Yoto1yxsW0TGXwaH74/Rpwekd1iBPl3dKbkV5d0U5HQBb99p3Mvlfuh7W4Yk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1769171251; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=O0Tiy4KOQPJNfeInfzeqJzVHUyBwoqqHu8MQ5hZPthA=; b=m8O+GIN34s3umzxrgHqiP87gmRDRJfr8F1s8pAaezetQRNtL5y4mg4I62ZbhP+FaTwaY+V+51T6gxi+xlNesSssRpN93MNJOUAnMRpmkfbzAV93kPgItqfU4QTECi1dOq2Sqp88GHbPieDeiKzhFcfWMgagZwOKE9YM5kwr9FIM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1769171251446813.0564017093673; Fri, 23 Jan 2026 04:27:31 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vjGAn-0005KQ-Oy; Fri, 23 Jan 2026 07:21:57 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vjGAL-00051j-TQ for qemu-devel@nongnu.org; Fri, 23 Jan 2026 07:21:32 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vjGAI-00052J-Nk for qemu-devel@nongnu.org; Fri, 23 Jan 2026 07:21:27 -0500 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-119-0-IPeOV1PrWcKfA8UtEisw-1; Fri, 23 Jan 2026 07:21:22 -0500 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id ADDDB1955F2C; Fri, 23 Jan 2026 12:21:21 +0000 (UTC) Received: from localhost.localdomain (unknown [10.72.112.7]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id E804D30002D1; Fri, 23 Jan 2026 12:21:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1769170886; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=O0Tiy4KOQPJNfeInfzeqJzVHUyBwoqqHu8MQ5hZPthA=; b=MhiFQ126XUjr56Rj9gYO9Vz1iFcmK2MBSZ1Em4PF0Gp+cVheCp+uelo/Y1thybNtJYYJ28 ZH5BqhmI96XhLhPiJAx7Cfu43Cc40S7H2spEN4FHzbOddHRJqmN6mryBybdNRwV0APPo0q F1K/JVABbx0ZVdIbvQgA/zFLIwMEcSI= X-MC-Unique: 0-IPeOV1PrWcKfA8UtEisw-1 X-Mimecast-MFC-AGG-ID: 0-IPeOV1PrWcKfA8UtEisw_1769170881 From: Jason Wang To: qemu-devel@nongnu.org Cc: Vladimir Sementsov-Ogievskiy , Maksim Davydov , Jason Wang Subject: [PULL 04/13] net/tap: pass NULL to net_init_tap_one() in cases when scripts are NULL Date: Fri, 23 Jan 2026 20:20:53 +0800 Message-ID: <20260123122102.51422-5-jasowang@redhat.com> In-Reply-To: <20260123122102.51422-1-jasowang@redhat.com> References: <20260123122102.51422-1-jasowang@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=170.10.129.124; envelope-from=jasowang@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 12 X-Spam_score: 1.2 X-Spam_bar: + X-Spam_report: (1.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.079, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_SBL_CSS=3.335, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1769171253220158500 Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy Directly pass NULL in cases where we report an error if script or downscript are set. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Maksim Davydov Signed-off-by: Jason Wang --- net/tap.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/net/tap.c b/net/tap.c index abeee6be11..8182f39851 100644 --- a/net/tap.c +++ b/net/tap.c @@ -807,8 +807,6 @@ int net_init_tap(const Netdev *netdev, const char *name, const NetdevTapOptions *tap; int fd, vnet_hdr =3D 0, i =3D 0, queues; /* for the no-fd, no-helper case */ - const char *script; - const char *downscript; Error *err =3D NULL; const char *vhostfdname; char ifname[128]; @@ -818,8 +816,6 @@ int net_init_tap(const Netdev *netdev, const char *name, tap =3D &netdev->u.tap; queues =3D tap->has_queues ? tap->queues : 1; vhostfdname =3D tap->vhostfd; - script =3D tap->script; - downscript =3D tap->downscript; =20 /* QEMU hubs do not support multiqueue tap, in this case peer is set. * For -netdev, peer is always NULL. */ @@ -860,7 +856,7 @@ int net_init_tap(const Netdev *netdev, const char *name, } =20 net_init_tap_one(tap, peer, "tap", name, NULL, - script, downscript, + NULL, NULL, vhostfdname, vnet_hdr, fd, &err); if (err) { error_propagate(errp, err); @@ -921,7 +917,7 @@ int net_init_tap(const Netdev *netdev, const char *name, } =20 net_init_tap_one(tap, peer, "tap", name, ifname, - script, downscript, + NULL, NULL, tap->vhostfds ? vhost_fds[i] : NULL, vnet_hdr, fd, &err); if (err) { @@ -966,7 +962,7 @@ free_fail: } =20 net_init_tap_one(tap, peer, "bridge", name, ifname, - script, downscript, vhostfdname, + NULL, NULL, vhostfdname, vnet_hdr, fd, &err); if (err) { error_propagate(errp, err); @@ -974,6 +970,8 @@ free_fail: return -1; } } else { + const char *script =3D tap->script; + const char *downscript =3D tap->downscript; g_autofree char *default_script =3D NULL; g_autofree char *default_downscript =3D NULL; if (tap->vhostfds) { --=20 2.42.0 From nobody Sun Jan 25 10:13:57 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1769171000; cv=none; d=zohomail.com; s=zohoarc; b=Nb5Z6KGJMcqn0yTHfl/J5ussP+Z8lLARDwUlkNp7tOjBtX8blnRgsrUxg4GaMxhTC6TSAdx7QOMrH2pFmog8pgmVMWhcLa78OVA57C0aT+qPfIWyBsFuC6jNsF2/5dxowwDDlVPRkGHwwDSJmM9xYd3SMefo0HvaSm45JqPODas= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1769171000; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=X4Dq+fUO8dxbp9hG+7gZc96RrwC1q1Qc8B/brKxVYUs=; b=lQAextEpqhUCuNv8PI9QbBYQ9S0/9fbeNBRXEkqZbOL7xPiJhnSMuLc+g8qGZliaqPCj/63fmN3LdoL3PjibLYBSOZCopM0SOm9XAgS8JlXO1Id/zPgB0DIia396J2D2UNgbM2Zl+dJ0MzVxTLedUJtszBbfLQ7QpKItTvKyYJI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1769171000451887.3310986239936; Fri, 23 Jan 2026 04:23:20 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vjGAf-0005Fe-0s; Fri, 23 Jan 2026 07:21:49 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vjGAO-00053Z-Es for qemu-devel@nongnu.org; Fri, 23 Jan 2026 07:21:34 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vjGAL-00052V-Ly for qemu-devel@nongnu.org; Fri, 23 Jan 2026 07:21:31 -0500 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-491-9gdjj7vOMX-GHC9piksX5Q-1; Fri, 23 Jan 2026 07:21:26 -0500 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 44CF8195608D; Fri, 23 Jan 2026 12:21:25 +0000 (UTC) Received: from localhost.localdomain (unknown [10.72.112.7]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 8025D30002D1; Fri, 23 Jan 2026 12:21:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1769170888; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=X4Dq+fUO8dxbp9hG+7gZc96RrwC1q1Qc8B/brKxVYUs=; b=YFrrRRB4o+24apeEw7ntl6l8IIpyUNvhYp3S3+M+OkXq8CU1E5TYa2CVDNsyyahweUOHQw 4xR3nC6tN3oZenll+2sPa4cITn5pXyMEDJMlKY0pQvYsmU701hp8BU40BDA/qc+BVINdw6 UF3fMBhxklOnUBxIQBgfxM8fx8W9/ZI= X-MC-Unique: 9gdjj7vOMX-GHC9piksX5Q-1 X-Mimecast-MFC-AGG-ID: 9gdjj7vOMX-GHC9piksX5Q_1769170885 From: Jason Wang To: qemu-devel@nongnu.org Cc: Vladimir Sementsov-Ogievskiy , Maksim Davydov , Jason Wang Subject: [PULL 05/13] net/tap: rework scripts handling Date: Fri, 23 Jan 2026 20:20:54 +0800 Message-ID: <20260123122102.51422-6-jasowang@redhat.com> In-Reply-To: <20260123122102.51422-1-jasowang@redhat.com> References: <20260123122102.51422-1-jasowang@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=170.10.129.124; envelope-from=jasowang@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 12 X-Spam_score: 1.2 X-Spam_bar: + X-Spam_report: (1.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.079, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_SBL_CSS=3.335, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1769171004366158500 Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy Simplify handling scripts: parse all these "no" and '\0' once, and then keep simpler logic for net_tap_open() and net_init_tap_one(): NULL means no script to run, otherwise run script. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Maksim Davydov Signed-off-by: Jason Wang --- net/tap.c | 46 ++++++++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/net/tap.c b/net/tap.c index 8182f39851..c7d8e1a3be 100644 --- a/net/tap.c +++ b/net/tap.c @@ -91,6 +91,21 @@ static void launch_script(const char *setup_script, cons= t char *ifname, static void tap_send(void *opaque); static void tap_writable(void *opaque); =20 +static char *tap_parse_script(const char *script_arg, const char *default_= path) +{ + g_autofree char *res =3D g_strdup(script_arg); + + if (!res) { + res =3D get_relocated_path(default_path); + } + + if (res[0] =3D=3D '\0' || strcmp(res, "no") =3D=3D 0) { + return NULL; + } + + return g_steal_pointer(&res); +} + static void tap_update_fd_handler(TAPState *s) { qemu_set_fd_handler(s->fd, @@ -676,9 +691,7 @@ static int net_tap_init(const NetdevTapOptions *tap, in= t *vnet_hdr, return -1; } =20 - if (setup_script && - setup_script[0] !=3D '\0' && - strcmp(setup_script, "no") !=3D 0) { + if (setup_script) { launch_script(setup_script, ifname, fd, &err); if (err) { error_propagate(errp, err); @@ -714,9 +727,9 @@ static void net_init_tap_one(const NetdevTapOptions *ta= p, NetClientState *peer, qemu_set_info_str(&s->nc, "helper=3D%s", tap->helper); } else { qemu_set_info_str(&s->nc, "ifname=3D%s,script=3D%s,downscript=3D%s= ", ifname, - script, downscript); + script ?: "no", downscript ?: "no"); =20 - if (strcmp(downscript, "no") !=3D 0) { + if (downscript) { snprintf(s->down_script, sizeof(s->down_script), "%s", downscr= ipt); snprintf(s->down_script_arg, sizeof(s->down_script_arg), "%s", ifname); @@ -970,23 +983,16 @@ free_fail: return -1; } } else { - const char *script =3D tap->script; - const char *downscript =3D tap->downscript; - g_autofree char *default_script =3D NULL; - g_autofree char *default_downscript =3D NULL; + g_autofree char *script =3D + tap_parse_script(tap->script, DEFAULT_NETWORK_SCRIPT); + g_autofree char *downscript =3D + tap_parse_script(tap->downscript, DEFAULT_NETWORK_DOWN_SCRIPT); + if (tap->vhostfds) { error_setg(errp, "vhostfds=3D is invalid if fds=3D wasn't spec= ified"); return -1; } =20 - if (!script) { - script =3D default_script =3D get_relocated_path(DEFAULT_NETWO= RK_SCRIPT); - } - if (!downscript) { - downscript =3D default_downscript =3D - get_relocated_path(DEFAULT_NETWORK_DOWN_S= CRIPT); - } - if (tap->ifname) { pstrcpy(ifname, sizeof ifname, tap->ifname); } else { @@ -994,7 +1000,7 @@ free_fail: } =20 for (i =3D 0; i < queues; i++) { - fd =3D net_tap_init(tap, &vnet_hdr, i >=3D 1 ? "no" : script, + fd =3D net_tap_init(tap, &vnet_hdr, i >=3D 1 ? NULL : script, ifname, sizeof ifname, queues > 1, errp); if (fd =3D=3D -1) { return -1; @@ -1009,8 +1015,8 @@ free_fail: } =20 net_init_tap_one(tap, peer, "tap", name, ifname, - i >=3D 1 ? "no" : script, - i >=3D 1 ? "no" : downscript, + i >=3D 1 ? NULL : script, + i >=3D 1 ? NULL : downscript, vhostfdname, vnet_hdr, fd, &err); if (err) { error_propagate(errp, err); --=20 2.42.0 From nobody Sun Jan 25 10:13:57 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1769171068; cv=none; d=zohomail.com; s=zohoarc; b=f+HMep3MHy/Qlz/zun67rqKr3RTAjrNi3OG3LxWzvLN0kKq5LQUR+kaX0mcd3TEAxno66Rbw/CCwHSNEOLWFwpMEaPBAP9oe/HbqOPHdjl/py2ghcuLCxxDWWU1csuwDq0Ns3SqkxEVMPenFo5T8cA/5fOt8O08EDUU9iUwnLq0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1769171068; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=hRG2QgvHCpXDQBjeUQQjipXHIFMKfDOPRE3sdL4JVxk=; b=X7yVutNA/3WOIUpjNk15yPWP5DlT69F7x6VNRvI9duJr8GSKBWFFPZu5+Mj7LrcQ2J0AEn94hQUfTA1awww896bYe1pPwYv3lIZUljYS6arEYxts2l7ztSHUouHN0oRNHf4C2YBF4n/UkKPeuJ5zqk6xjh2SS24zIbwxOF3LmsY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1769171068185771.8594197739424; Fri, 23 Jan 2026 04:24:28 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vjGAq-0005Pg-G8; Fri, 23 Jan 2026 07:22:01 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vjGAT-000569-JQ for qemu-devel@nongnu.org; Fri, 23 Jan 2026 07:21:41 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vjGAR-00053z-90 for qemu-devel@nongnu.org; Fri, 23 Jan 2026 07:21:36 -0500 Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-629-JWYKmzRlMV-a5pvkngsanA-1; Fri, 23 Jan 2026 07:21:31 -0500 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 734DF1944EA8; Fri, 23 Jan 2026 12:21:30 +0000 (UTC) Received: from localhost.localdomain (unknown [10.72.112.7]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 17A9930002D1; Fri, 23 Jan 2026 12:21:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1769170894; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hRG2QgvHCpXDQBjeUQQjipXHIFMKfDOPRE3sdL4JVxk=; b=fupIrAbBVLCMX6Ni4/aC069yqRwynDpPBoCdl0QL27BP44nCJdKr2uJL3aQ42Pa1qNULtU 0IeLVCsVdKW0SRimrUpvP6adt5eHK4HLqTqOPiBDP7oHgUo/d+wCFlY2QZAnn7ki6svtJA GdgSH/Nq47bDflXFvuVibCAfP4XLETU= X-MC-Unique: JWYKmzRlMV-a5pvkngsanA-1 X-Mimecast-MFC-AGG-ID: JWYKmzRlMV-a5pvkngsanA_1769170890 From: Jason Wang To: qemu-devel@nongnu.org Cc: Vladimir Sementsov-Ogievskiy , Maksim Davydov , Jason Wang Subject: [PULL 06/13] net/tap: setup exit notifier only when needed Date: Fri, 23 Jan 2026 20:20:55 +0800 Message-ID: <20260123122102.51422-7-jasowang@redhat.com> In-Reply-To: <20260123122102.51422-1-jasowang@redhat.com> References: <20260123122102.51422-1-jasowang@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=170.10.129.124; envelope-from=jasowang@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 12 X-Spam_score: 1.2 X-Spam_bar: + X-Spam_report: (1.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.079, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_SBL_CSS=3.335, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1769171070421154100 Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy No reason to setup notifier on each queue of multique tap, when we actually want to run downscript only once. As well, let's not setup notifier, when downscript is not enabled (downsciprt=3D"no"). Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Maksim Davydov Signed-off-by: Jason Wang --- net/tap.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/net/tap.c b/net/tap.c index c7d8e1a3be..5af157164e 100644 --- a/net/tap.c +++ b/net/tap.c @@ -326,11 +326,9 @@ static void tap_exit_notify(Notifier *notifier, void *= data) TAPState *s =3D container_of(notifier, TAPState, exit); Error *err =3D NULL; =20 - if (s->down_script[0]) { - launch_script(s->down_script, s->down_script_arg, s->fd, &err); - if (err) { - error_report_err(err); - } + launch_script(s->down_script, s->down_script_arg, s->fd, &err); + if (err) { + error_report_err(err); } } =20 @@ -346,8 +344,11 @@ static void tap_cleanup(NetClientState *nc) =20 qemu_purge_queued_packets(nc); =20 - tap_exit_notify(&s->exit, NULL); - qemu_remove_exit_notifier(&s->exit); + if (s->exit.notify) { + tap_exit_notify(&s->exit, NULL); + qemu_remove_exit_notifier(&s->exit); + s->exit.notify =3D NULL; + } =20 tap_read_poll(s, false); tap_write_poll(s, false); @@ -443,9 +444,6 @@ static TAPState *net_tap_fd_init(NetClientState *peer, tap_read_poll(s, true); s->vhost_net =3D NULL; =20 - s->exit.notify =3D tap_exit_notify; - qemu_add_exit_notifier(&s->exit); - return s; } =20 @@ -733,6 +731,8 @@ static void net_init_tap_one(const NetdevTapOptions *ta= p, NetClientState *peer, snprintf(s->down_script, sizeof(s->down_script), "%s", downscr= ipt); snprintf(s->down_script_arg, sizeof(s->down_script_arg), "%s", ifname); + s->exit.notify =3D tap_exit_notify; + qemu_add_exit_notifier(&s->exit); } } =20 --=20 2.42.0 From nobody Sun Jan 25 10:13:57 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1769171040; cv=none; d=zohomail.com; s=zohoarc; b=PnOx4mOhjIbw+1y2exaQHZgP/XAcHdUV/NpSS19Hu6U0ISKdGPFetadp4EJGnD+iCD2hrfJHcNWmLhkYBaQAg2m/uCxwrh9YBbmVW3XHxR00AykttOe/1UGhAd5CMdzbDlHNjETnqAlJk0B4dYq5+fHr4fZCxs5uE8va5fCCSN0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1769171040; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=wdoZHqK9EzUwe62USeHMhpcpxmGDMPzgP9NSzBkvJ7o=; b=l08vbaaNumF6WQa3UT6xogNyBYxvmdBLPwZYkBhDyN4jiq2D2h+1PcoYBxxoU6MKGix78DAIuX14bNE9xDzBN4BAAyNu8Ga2W/o6mCXV30zr2Fg0olTqWHWVA1zIEKnuHUCEJgvzN0VLCVthQxMM2EygCqHA/01yzwoORMi2GTM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17691710408852.2205996129218875; Fri, 23 Jan 2026 04:24:00 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vjGAf-0005IS-SQ; Fri, 23 Jan 2026 07:21:50 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vjGAU-00056H-SH for qemu-devel@nongnu.org; Fri, 23 Jan 2026 07:21:41 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vjGAT-00054K-92 for qemu-devel@nongnu.org; Fri, 23 Jan 2026 07:21:38 -0500 Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-118-bMa0Awr6PNyStzAsU60wAg-1; Fri, 23 Jan 2026 07:21:34 -0500 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id DB5671944B15; Fri, 23 Jan 2026 12:21:33 +0000 (UTC) Received: from localhost.localdomain (unknown [10.72.112.7]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 4335030002D1; Fri, 23 Jan 2026 12:21:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1769170896; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wdoZHqK9EzUwe62USeHMhpcpxmGDMPzgP9NSzBkvJ7o=; b=Ukgi8skXdWwFlQ2lHrMRi6E4Nbm/HZAmcWN7xklRhdpzhiQH52W5uTgJJFQyJHfw0KHqEb 2fZPori8ZjKZKh2rC8ftDd4jyChb9oVkrk2uPAJsqoQFuec77RwNNtPqCcoT4qnOarJYHO dpBvYxyaj2t/7PUtYoEyAuu0AVHbFTo= X-MC-Unique: bMa0Awr6PNyStzAsU60wAg-1 X-Mimecast-MFC-AGG-ID: bMa0Awr6PNyStzAsU60wAg_1769170894 From: Jason Wang To: qemu-devel@nongnu.org Cc: Vladimir Sementsov-Ogievskiy , Maksim Davydov , Jason Wang Subject: [PULL 07/13] net/tap: tap_set_sndbuf(): add return value Date: Fri, 23 Jan 2026 20:20:56 +0800 Message-ID: <20260123122102.51422-8-jasowang@redhat.com> In-Reply-To: <20260123122102.51422-1-jasowang@redhat.com> References: <20260123122102.51422-1-jasowang@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=170.10.133.124; envelope-from=jasowang@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 12 X-Spam_score: 1.2 X-Spam_bar: + X-Spam_report: (1.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.079, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1769171041899154100 Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy Follow common recommendations in include/qapi/error.h of having a return value together with errp. This allows to avoid error propagation. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Maksim Davydov Signed-off-by: Jason Wang --- net/tap-bsd.c | 3 ++- net/tap-linux.c | 5 ++++- net/tap-solaris.c | 3 ++- net/tap-stub.c | 3 ++- net/tap.c | 5 +---- net/tap_int.h | 2 +- 6 files changed, 12 insertions(+), 9 deletions(-) diff --git a/net/tap-bsd.c b/net/tap-bsd.c index 3fd300d46f..0e62530aaa 100644 --- a/net/tap-bsd.c +++ b/net/tap-bsd.c @@ -206,8 +206,9 @@ error: } #endif /* __FreeBSD__ */ =20 -void tap_set_sndbuf(int fd, const NetdevTapOptions *tap, Error **errp) +bool tap_set_sndbuf(int fd, const NetdevTapOptions *tap, Error **errp) { + return true; } =20 int tap_probe_vnet_hdr(int fd, Error **errp) diff --git a/net/tap-linux.c b/net/tap-linux.c index 54de3cd06b..2b2d75a823 100644 --- a/net/tap-linux.c +++ b/net/tap-linux.c @@ -145,7 +145,7 @@ int tap_open(char *ifname, int ifname_size, int *vnet_h= dr, */ #define TAP_DEFAULT_SNDBUF 0 =20 -void tap_set_sndbuf(int fd, const NetdevTapOptions *tap, Error **errp) +bool tap_set_sndbuf(int fd, const NetdevTapOptions *tap, Error **errp) { int sndbuf; =20 @@ -159,7 +159,10 @@ void tap_set_sndbuf(int fd, const NetdevTapOptions *ta= p, Error **errp) =20 if (ioctl(fd, TUNSETSNDBUF, &sndbuf) =3D=3D -1 && tap->has_sndbuf) { error_setg_errno(errp, errno, "TUNSETSNDBUF ioctl failed"); + return false; } + + return true; } =20 int tap_probe_vnet_hdr(int fd, Error **errp) diff --git a/net/tap-solaris.c b/net/tap-solaris.c index faf7922ea8..049b551ae1 100644 --- a/net/tap-solaris.c +++ b/net/tap-solaris.c @@ -208,8 +208,9 @@ int tap_open(char *ifname, int ifname_size, int *vnet_h= dr, return fd; } =20 -void tap_set_sndbuf(int fd, const NetdevTapOptions *tap, Error **errp) +bool tap_set_sndbuf(int fd, const NetdevTapOptions *tap, Error **errp) { + return true; } =20 int tap_probe_vnet_hdr(int fd, Error **errp) diff --git a/net/tap-stub.c b/net/tap-stub.c index f7a5e0c163..86d7d38e0f 100644 --- a/net/tap-stub.c +++ b/net/tap-stub.c @@ -33,8 +33,9 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr, return -1; } =20 -void tap_set_sndbuf(int fd, const NetdevTapOptions *tap, Error **errp) +bool tap_set_sndbuf(int fd, const NetdevTapOptions *tap, Error **errp) { + return true; } =20 int tap_probe_vnet_hdr(int fd, Error **errp) diff --git a/net/tap.c b/net/tap.c index 5af157164e..07a450e68d 100644 --- a/net/tap.c +++ b/net/tap.c @@ -709,13 +709,10 @@ static void net_init_tap_one(const NetdevTapOptions *= tap, NetClientState *peer, const char *downscript, const char *vhostfdna= me, int vnet_hdr, int fd, Error **errp) { - Error *err =3D NULL; TAPState *s =3D net_tap_fd_init(peer, model, name, fd, vnet_hdr); int vhostfd; =20 - tap_set_sndbuf(s->fd, tap, &err); - if (err) { - error_propagate(errp, err); + if (!tap_set_sndbuf(s->fd, tap, errp)) { goto failed; } =20 diff --git a/net/tap_int.h b/net/tap_int.h index b76a05044b..7963dd6aae 100644 --- a/net/tap_int.h +++ b/net/tap_int.h @@ -34,7 +34,7 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr, =20 ssize_t tap_read_packet(int tapfd, uint8_t *buf, int maxlen); =20 -void tap_set_sndbuf(int fd, const NetdevTapOptions *tap, Error **errp); +bool tap_set_sndbuf(int fd, const NetdevTapOptions *tap, Error **errp); int tap_probe_vnet_hdr(int fd, Error **errp); int tap_probe_has_ufo(int fd); int tap_probe_has_uso(int fd); --=20 2.42.0 From nobody Sun Jan 25 10:13:57 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1769171022; cv=none; d=zohomail.com; s=zohoarc; b=QeG5QUIs8NjZMVMbVB9u8lTAhT2moHwwpW9e799cuEi4UO5ZFLU/WCz59sZa1eTDWPGkaKnmG/3E6dt74Fm97G6qAQv/c/NMzUUxRHLPKD+fNSaWXKtE03SdU5BkNrs7JlenkJ8/eG3JRpMWVDq7piDhSFEKYCJXXoFpCoLYwHk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1769171022; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=I5kj45gtgryG+2GLx8F0xuwiGmEtj2lgp1HS7acdcHk=; b=VGBnILKYWP1H3MGFS7YMIidDOOgcAwKWEFP5n46vp6GZXSvlD5tLqwsZgqFkVjG5n7AmIog55JMo5PyrsAoPpiEQIhVRKNJlmwS0kDAOlhvDAAYc/jCf7XU2ISUWZbD/4tcN28rwmD2g2Lbt091hiODSidpRs35VKDY8E/USOWg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1769171022486319.1978568865002; Fri, 23 Jan 2026 04:23:42 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vjGAz-0005gM-7X; Fri, 23 Jan 2026 07:22:09 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vjGAY-00057r-KY for qemu-devel@nongnu.org; Fri, 23 Jan 2026 07:21:44 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vjGAW-000559-4B for qemu-devel@nongnu.org; Fri, 23 Jan 2026 07:21:41 -0500 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-529-9EVb3PxiOb-Vsh9r49Jpww-1; Fri, 23 Jan 2026 07:21:38 -0500 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 2A3541955DA2; Fri, 23 Jan 2026 12:21:37 +0000 (UTC) Received: from localhost.localdomain (unknown [10.72.112.7]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 9773B30002D1; Fri, 23 Jan 2026 12:21:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1769170899; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=I5kj45gtgryG+2GLx8F0xuwiGmEtj2lgp1HS7acdcHk=; b=egAMXI2AUDmAO6Zj9+VuHRunaGIYmVlHHiocSznQp5JlA7kSk2m6gICX9R6S1Hs9D6rOnk 9N3N839/qarHZTc2BFeF63gpbD+DW61NY2wq5rGAD+AS8YZw780zuion7FUXhlXKnXfbHj yIWT0q5yX4yp4JTK7BB3IjIEZk5KGpQ= X-MC-Unique: 9EVb3PxiOb-Vsh9r49Jpww-1 X-Mimecast-MFC-AGG-ID: 9EVb3PxiOb-Vsh9r49Jpww_1769170897 From: Jason Wang To: qemu-devel@nongnu.org Cc: Vladimir Sementsov-Ogievskiy , Maksim Davydov , Jason Wang Subject: [PULL 08/13] net/tap: rework tap_set_sndbuf() Date: Fri, 23 Jan 2026 20:20:57 +0800 Message-ID: <20260123122102.51422-9-jasowang@redhat.com> In-Reply-To: <20260123122102.51422-1-jasowang@redhat.com> References: <20260123122102.51422-1-jasowang@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=170.10.129.124; envelope-from=jasowang@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 12 X-Spam_score: 1.2 X-Spam_bar: + X-Spam_report: (1.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.079, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_SBL_CSS=3.335, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1769171025418154100 Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy Keep NetdevTapOptions related logic in tap.c, and make tap_set_sndbuf a simple system call wrapper, more like other functions in tap-linux.c Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Maksim Davydov Signed-off-by: Jason Wang --- net/tap-bsd.c | 2 +- net/tap-linux.c | 16 ++-------------- net/tap-solaris.c | 2 +- net/tap-stub.c | 2 +- net/tap.c | 6 +++++- net/tap_int.h | 3 +-- 6 files changed, 11 insertions(+), 20 deletions(-) diff --git a/net/tap-bsd.c b/net/tap-bsd.c index 0e62530aaa..c39daf9385 100644 --- a/net/tap-bsd.c +++ b/net/tap-bsd.c @@ -206,7 +206,7 @@ error: } #endif /* __FreeBSD__ */ =20 -bool tap_set_sndbuf(int fd, const NetdevTapOptions *tap, Error **errp) +bool tap_set_sndbuf(int fd, int sndbuf, Error **errp) { return true; } diff --git a/net/tap-linux.c b/net/tap-linux.c index 2b2d75a823..3cd7d26710 100644 --- a/net/tap-linux.c +++ b/net/tap-linux.c @@ -143,21 +143,9 @@ int tap_open(char *ifname, int ifname_size, int *vnet_= hdr, * Ethernet NICs generally have txqueuelen=3D1000, so 1Mb is * a good value, given a 1500 byte MTU. */ -#define TAP_DEFAULT_SNDBUF 0 - -bool tap_set_sndbuf(int fd, const NetdevTapOptions *tap, Error **errp) +bool tap_set_sndbuf(int fd, int sndbuf, Error **errp) { - int sndbuf; - - sndbuf =3D !tap->has_sndbuf ? TAP_DEFAULT_SNDBUF : - tap->sndbuf > INT_MAX ? INT_MAX : - tap->sndbuf; - - if (!sndbuf) { - sndbuf =3D INT_MAX; - } - - if (ioctl(fd, TUNSETSNDBUF, &sndbuf) =3D=3D -1 && tap->has_sndbuf) { + if (ioctl(fd, TUNSETSNDBUF, &sndbuf) =3D=3D -1) { error_setg_errno(errp, errno, "TUNSETSNDBUF ioctl failed"); return false; } diff --git a/net/tap-solaris.c b/net/tap-solaris.c index 049b551ae1..8704b1084b 100644 --- a/net/tap-solaris.c +++ b/net/tap-solaris.c @@ -208,7 +208,7 @@ int tap_open(char *ifname, int ifname_size, int *vnet_h= dr, return fd; } =20 -bool tap_set_sndbuf(int fd, const NetdevTapOptions *tap, Error **errp) +bool tap_set_sndbuf(int fd, int sndbuf, Error **errp) { return true; } diff --git a/net/tap-stub.c b/net/tap-stub.c index 86d7d38e0f..6aa60d96ad 100644 --- a/net/tap-stub.c +++ b/net/tap-stub.c @@ -33,7 +33,7 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr, return -1; } =20 -bool tap_set_sndbuf(int fd, const NetdevTapOptions *tap, Error **errp) +bool tap_set_sndbuf(int fd, int sndbuf, Error **errp) { return true; } diff --git a/net/tap.c b/net/tap.c index 07a450e68d..8d7ab6ba6f 100644 --- a/net/tap.c +++ b/net/tap.c @@ -711,8 +711,12 @@ static void net_init_tap_one(const NetdevTapOptions *t= ap, NetClientState *peer, { TAPState *s =3D net_tap_fd_init(peer, model, name, fd, vnet_hdr); int vhostfd; + bool sndbuf_required =3D tap->has_sndbuf; + int sndbuf =3D + (tap->has_sndbuf && tap->sndbuf) ? MIN(tap->sndbuf, INT_MAX) : INT= _MAX; =20 - if (!tap_set_sndbuf(s->fd, tap, errp)) { + if (!tap_set_sndbuf(fd, sndbuf, sndbuf_required ? errp : NULL) && + sndbuf_required) { goto failed; } =20 diff --git a/net/tap_int.h b/net/tap_int.h index 7963dd6aae..dc4f484006 100644 --- a/net/tap_int.h +++ b/net/tap_int.h @@ -26,7 +26,6 @@ #ifndef NET_TAP_INT_H #define NET_TAP_INT_H =20 -#include "qapi/qapi-types-net.h" #include "net/net.h" =20 int tap_open(char *ifname, int ifname_size, int *vnet_hdr, @@ -34,7 +33,7 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr, =20 ssize_t tap_read_packet(int tapfd, uint8_t *buf, int maxlen); =20 -bool tap_set_sndbuf(int fd, const NetdevTapOptions *tap, Error **errp); +bool tap_set_sndbuf(int fd, int sndbuf, Error **errp); int tap_probe_vnet_hdr(int fd, Error **errp); int tap_probe_has_ufo(int fd); int tap_probe_has_uso(int fd); --=20 2.42.0 From nobody Sun Jan 25 10:13:57 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1769171096; cv=none; d=zohomail.com; s=zohoarc; b=ki27ti9z3eLFO2m7CeCWyehrPgcUlLxcOydLN+F82BDHl/N4c0T6s7hB3vaV1LP2WgYz9i/Uy6GbXXHSW41d15+HB6pnC/XvMrBOQqF14a2YgMY4midmGLDrgJ+6hH6LSJfqzGw15/XC9O+rcshfiIvEKXK+zbs4LVV+ILaOSw8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1769171096; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=qeMx6AsK3anORPzR6IouDopmDhX/6ygcD5xk4N1Z3hI=; b=ZQA+WK6oaf/KjJpPUTfX7V0HGXp6tHinavCj2fd2f+YmsrT+fZmxL1y17uWzee9nylbaF7ym8y5S4/ETVxGVdff/nGh9IZ6KfcC0ItkBNZ+Gv/deoPsMMl/q+fm89BkLOUoH9vjwECu1EFV88qzPbv8NKzyGzx3kDIYZiM7j1eY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1769171096288437.4347307956165; Fri, 23 Jan 2026 04:24:56 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vjGAx-0005a7-8r; Fri, 23 Jan 2026 07:22:07 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vjGAa-00058Y-Md for qemu-devel@nongnu.org; Fri, 23 Jan 2026 07:21:46 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vjGAZ-00055Z-AA for qemu-devel@nongnu.org; Fri, 23 Jan 2026 07:21:44 -0500 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-161-Do6yTjWVMG6DS6-Yb8gThQ-1; Fri, 23 Jan 2026 07:21:41 -0500 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 36FED1956096; Fri, 23 Jan 2026 12:21:40 +0000 (UTC) Received: from localhost.localdomain (unknown [10.72.112.7]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id EEB9030002D1; Fri, 23 Jan 2026 12:21:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1769170902; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qeMx6AsK3anORPzR6IouDopmDhX/6ygcD5xk4N1Z3hI=; b=FlCHlsRKFtr/syBmmxgNYJi9QKZ+zYAy2qBLFN3oknDAYTB8nEEKISmO17wifUDCq7lMZV FCPSdDnuUaLk2hevPJD0tn55RcW2A4ekivvV3yARgblxzcmVwG7SisX0GEeFejRA9dXUA9 06uP60MzDnfezY6poWjOVKOzx3o0DnQ= X-MC-Unique: Do6yTjWVMG6DS6-Yb8gThQ-1 X-Mimecast-MFC-AGG-ID: Do6yTjWVMG6DS6-Yb8gThQ_1769170900 From: Jason Wang To: qemu-devel@nongnu.org Cc: Jason Wang , Zhang Chen Subject: [PULL 09/13] net/filter-buffer: make interval change take effect immediately Date: Fri, 23 Jan 2026 20:20:58 +0800 Message-ID: <20260123122102.51422-10-jasowang@redhat.com> In-Reply-To: <20260123122102.51422-1-jasowang@redhat.com> References: <20260123122102.51422-1-jasowang@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=170.10.129.124; envelope-from=jasowang@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 12 X-Spam_score: 1.2 X-Spam_bar: + X-Spam_report: (1.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.079, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_SBL_CSS=3.335, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1769171098384158500 Content-Type: text/plain; charset="utf-8" Previously, when the 'interval' property was modified at runtime via QMP, the new value would only take effect after the current timer period elapsed. This could lead to unexpected behavior when users expect immediate changes. Fix this by checking if the timer is already running when setting the interval property. If so, reschedule the timer with the new interval value immediately. Reviewed-by: Zhang Chen Signed-off-by: Jason Wang --- net/filter-buffer.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/net/filter-buffer.c b/net/filter-buffer.c index a36be31dc8..427da24097 100644 --- a/net/filter-buffer.c +++ b/net/filter-buffer.c @@ -159,6 +159,7 @@ static void filter_buffer_set_interval(Object *obj, Vis= itor *v, Error **errp) { FilterBufferState *s =3D FILTER_BUFFER(obj); + NetFilterState *nf =3D NETFILTER(obj); uint32_t value; =20 if (!visit_type_uint32(v, name, &value, errp)) { @@ -170,6 +171,11 @@ static void filter_buffer_set_interval(Object *obj, Vi= sitor *v, return; } s->interval =3D value; + + if (nf->netdev && nf->on) { + timer_mod(&s->release_timer, + qemu_clock_get_us(QEMU_CLOCK_VIRTUAL) + s->interval); + } } =20 static void filter_buffer_class_init(ObjectClass *oc, const void *data) --=20 2.42.0 From nobody Sun Jan 25 10:13:57 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1769171065; cv=none; d=zohomail.com; s=zohoarc; b=TlpmGKN7pxomaqtuvAxH9x1eOy0bBqAXBXZxDKIUxCfmsF9TAXbmENXSs3w7a0RJCzjX27dC+WwfZmgMiDVQm0t7Ry318WaS2LAJdFs/7Rb4rmU/uraBNcZnlSyL/17gP9JYz72Ox3OJtQWZ2UjIGO2MRls9KFefiT3CnHzGC4o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1769171065; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=feH2FujmpRO46VbJB4z/pcE4jUNKzw/fe/zu4QkB8Qw=; b=BxiNzWRnFUU3yJtyipchvkCtDc84wAA+wTy1tGltrRpHYfA4ee2D0OphHhNjqyu4FX3OHiJjGPXEyNr2tk4X9p3cavf9Cjr6OJN5aeiXt2/P1jZ+2OvZzeaYE9WWPljC9lCUK251ha7Y3K3rvPPPvjVV0FRV9WgZEbGlCQpNKak= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1769171065622705.451105276987; Fri, 23 Jan 2026 04:24:25 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vjGB1-0005nn-J6; Fri, 23 Jan 2026 07:22:11 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vjGAj-0005LD-5s for qemu-devel@nongnu.org; Fri, 23 Jan 2026 07:21:56 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vjGAg-00056T-4P for qemu-devel@nongnu.org; Fri, 23 Jan 2026 07:21:52 -0500 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-80-4mTFS3kHNBuDXSF8LBAnRA-1; Fri, 23 Jan 2026 07:21:46 -0500 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 3E625180047F; Fri, 23 Jan 2026 12:21:45 +0000 (UTC) Received: from localhost.localdomain (unknown [10.72.112.7]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id E389230002D1; Fri, 23 Jan 2026 12:21:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1769170909; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=feH2FujmpRO46VbJB4z/pcE4jUNKzw/fe/zu4QkB8Qw=; b=Z8eBe9bVV9AhSHQnEugjAOWgq3HoTLF7epdPOXUbcEQQZrcJ1xXkH74rlpmlB54pKLsnhP 4VO6YdJ5T502SqdhYWemJBo+RIGCL7iWPwJRou1V9Fc7/URs/R3+lIxXORQuuhSvdN9bRo dzskXVT3LC+FQUgmravZSK2OYZA4YxA= X-MC-Unique: 4mTFS3kHNBuDXSF8LBAnRA-1 X-Mimecast-MFC-AGG-ID: 4mTFS3kHNBuDXSF8LBAnRA_1769170905 From: Jason Wang To: qemu-devel@nongnu.org Cc: Jason Wang , Zhang Chen , Fabiano Rosas Subject: [PULL 10/13] tests/qtest: add test for filter-buffer interval change Date: Fri, 23 Jan 2026 20:20:59 +0800 Message-ID: <20260123122102.51422-11-jasowang@redhat.com> In-Reply-To: <20260123122102.51422-1-jasowang@redhat.com> References: <20260123122102.51422-1-jasowang@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=170.10.133.124; envelope-from=jasowang@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.079, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1769171068040154100 Content-Type: text/plain; charset="utf-8" Add test_change_interval_timer to verify that modifying the 'interval' property of filter-buffer at runtime takes effect immediately. The test uses socket backend and filter-redirector to verify timer behavior: - Creates filter-buffer with a very long interval (1000 seconds) - Sends a packet which gets buffered - Advances virtual clock by 1 second, verifies packet is still buffered - Changes interval to 1ms via qom-set (timer should be rescheduled) - Advances virtual clock by 2ms, verifies packet is now released - This proves the timer was rescheduled immediately when interval changed The test uses filter-redirector to observe when packets are released by filter-buffer, providing end-to-end verification of the timer rescheduling behavior. Reviewed-by: Zhang Chen Reviewed-by: Fabiano Rosas Signed-off-by: Jason Wang --- tests/qtest/meson.build | 1 + tests/qtest/test-filter-buffer.c | 169 +++++++++++++++++++++++++++++++ 2 files changed, 170 insertions(+) create mode 100644 tests/qtest/test-filter-buffer.c diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build index a8b09d065f..dfb83650c6 100644 --- a/tests/qtest/meson.build +++ b/tests/qtest/meson.build @@ -46,6 +46,7 @@ qtests_cxl =3D \ # for the availability of the default NICs in the tests qtests_filter =3D \ (get_option('default_devices') and slirp.found() ? ['test-netfilter'] : = []) + \ + (get_option('default_devices') and host_os !=3D 'windows' ? ['test-filte= r-buffer'] : []) + \ (get_option('default_devices') and host_os !=3D 'windows' ? ['test-filte= r-mirror'] : []) + \ (get_option('default_devices') and host_os !=3D 'windows' ? ['test-filte= r-redirector'] : []) =20 diff --git a/tests/qtest/test-filter-buffer.c b/tests/qtest/test-filter-buf= fer.c new file mode 100644 index 0000000000..441cbb975c --- /dev/null +++ b/tests/qtest/test-filter-buffer.c @@ -0,0 +1,169 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * QTest testcase for filter-buffer + * + * Copyright (c) 2025 Red Hat, Inc. + * Author: Jason Wang + */ + +#include "qemu/osdep.h" +#include "libqtest.h" +#include "qobject/qdict.h" +#include "qemu/iov.h" +#include "qemu/sockets.h" + +/* + * Test that changing interval at runtime affects packet release timing. + * + * Traffic flow with filter-buffer and filter-redirector: + * + * test side | qemu side + * | + * +--------+ | +---------+ + * | send +------------------------>| backend | + * | sock[0]| | +----+----+ + * +--------+ | | + * | +----v----+ + * | | fbuf0 | filter-buffer (queue=3Dt= x) + * | +----+----+ + * | | + * | +----v----+ +----------+ + * | | rd0 +->| chardev0 | + * | +---------+ +----+-----+ + * | | + * +--------+ | | + * | recv |<--------------------------------------+ + * | sock | | + * +--------+ | + * + * The test verifies that when interval is changed via qom-set, the timer + * is rescheduled immediately, causing buffered packets to be released + * at the new interval rather than waiting for the old interval to elapse. + */ +static void test_change_interval_timer(void) +{ + QTestState *qts; + QDict *response; + int backend_sock[2], recv_sock; + int ret; + char send_buf[] =3D "Hello filter-buffer!"; + char recv_buf[128]; + char sock_path[] =3D "filter-buffer-test.XXXXXX"; + uint32_t size =3D sizeof(send_buf); + uint32_t len; + + size =3D htonl(size); + + ret =3D socketpair(PF_UNIX, SOCK_STREAM, 0, backend_sock); + g_assert_cmpint(ret, !=3D, -1); + + ret =3D mkstemp(sock_path); + g_assert_cmpint(ret, !=3D, -1); + + /* + * Start QEMU with: + * - socket backend connected to our socketpair + * - filter-buffer with a very long interval (1000 seconds) + * - filter-redirector to send released packets to a chardev socket + * + * queue=3Dtx intercepts packets going from backend to the guest, + * i.e., data we send from the test side. + */ + qts =3D qtest_initf( + "-nic socket,id=3Dqtest-bn0,fd=3D%d " + "-chardev socket,id=3Dchardev0,path=3D%s,server=3Don,wait=3Doff " + "-object filter-buffer,id=3Dfbuf0,netdev=3Dqtest-bn0," + "queue=3Dtx,interval=3D1000000000 " + "-object filter-redirector,id=3Drd0,netdev=3Dqtest-bn0," + "queue=3Dtx,outdev=3Dchardev0", + backend_sock[1], sock_path); + + /* Connect to the chardev socket to receive redirected packets */ + recv_sock =3D unix_connect(sock_path, NULL); + g_assert_cmpint(recv_sock, !=3D, -1); + + /* Send a QMP command to ensure chardev connection is established */ + qtest_qmp_assert_success(qts, "{ 'execute' : 'query-status'}"); + + /* + * Send a packet from the test side. + * It should be buffered by filter-buffer. + */ + struct iovec iov[] =3D { + { + .iov_base =3D &size, + .iov_len =3D sizeof(size), + }, { + .iov_base =3D send_buf, + .iov_len =3D sizeof(send_buf), + }, + }; + + ret =3D iov_send(backend_sock[0], iov, 2, 0, sizeof(size) + sizeof(sen= d_buf)); + g_assert_cmpint(ret, =3D=3D, sizeof(send_buf) + sizeof(size)); + + /* + * Advance virtual clock by 1 second (1,000,000,000 ns). + * This is much less than the 1000 second interval, so the packet + * should still be buffered. + */ + qtest_clock_step(qts, 1000000000LL); + + /* Try to receive with non-blocking - should fail (packet still buffer= ed) */ + ret =3D recv(recv_sock, recv_buf, sizeof(recv_buf), MSG_DONTWAIT); + g_assert_cmpint(ret, =3D=3D, -1); + g_assert(errno =3D=3D EAGAIN || errno =3D=3D EWOULDBLOCK); + + /* + * Now change the interval to 1000 us (1ms) via qom-set. + * This should reschedule the timer to fire in 1ms from now. + */ + response =3D qtest_qmp(qts, + "{'execute': 'qom-set'," + " 'arguments': {" + " 'path': 'fbuf0'," + " 'property': 'interval'," + " 'value': 1000" + "}}"); + g_assert(response); + g_assert(!qdict_haskey(response, "error")); + qobject_unref(response); + + /* + * Advance virtual clock by 2ms (2,000,000 ns). + * This exceeds the new 1ms interval, so the timer should fire + * and release the buffered packet. + * + * If the interval change didn't take effect immediately, we would + * still be waiting for the original 1000 second interval to elapse, + * and the packet would not be released. + */ + qtest_clock_step(qts, 2000000LL); + + /* + * Now we should be able to receive the packet through the redirector. + * The packet was released by filter-buffer and sent to filter-redirec= tor, + * which forwarded it to the chardev socket. + */ + ret =3D recv(recv_sock, &len, sizeof(len), 0); + g_assert_cmpint(ret, =3D=3D, sizeof(len)); + len =3D ntohl(len); + g_assert_cmpint(len, =3D=3D, sizeof(send_buf)); + + ret =3D recv(recv_sock, recv_buf, len, 0); + g_assert_cmpint(ret, =3D=3D, len); + g_assert_cmpstr(recv_buf, =3D=3D, send_buf); + + close(recv_sock); + close(backend_sock[0]); + unlink(sock_path); + qtest_quit(qts); +} + +int main(int argc, char **argv) +{ + g_test_init(&argc, &argv, NULL); + qtest_add_func("/netfilter/change_interval_timer", + test_change_interval_timer); + return g_test_run(); +} --=20 2.42.0 From nobody Sun Jan 25 10:13:57 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1769171259; cv=none; d=zohomail.com; s=zohoarc; b=HdGhqpLAghhjFu5YyYeaX+gnvwTtNTInzI6aqxQRSlcGNO3Sr80DHrbVkOAO2F3tzx3d/wJKwjaJLEkrVip+ltcfXcRs23Ayyxyz6NBAq+OhUEEohCIslhrEsKt/LBL+2FsIrudTpCAW7uiV6w1hR9XZWq6Ct+OmW5V2LmJbvFM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1769171259; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=vaPMnSfoRztdHHij+NJ9O+nGEqaIxYFd+PHUxdtCIXI=; b=FXAwZ04d/1bBrYsTHu2AgImwSAbxVGaaDOFiYC0sZ7eYoR3Uj4gFn0AmgMcUpE7ouWhRuBlnK6mXNhyC4WfMD3DaAsFaSFX49Zi2Zh2YSJKN5POuZnroc75hLGY9dwRYecykzIPIUa1HRPHYwJbPHgg9e70y0IpqAqBh2I1cIt8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1769171259021753.2516483925409; Fri, 23 Jan 2026 04:27:39 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vjGB3-0005vA-V1; Fri, 23 Jan 2026 07:22:14 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vjGAj-0005LE-67 for qemu-devel@nongnu.org; Fri, 23 Jan 2026 07:21:56 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vjGAh-00056X-Ar for qemu-devel@nongnu.org; Fri, 23 Jan 2026 07:21:52 -0500 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-138-tNTOyCYFPIC-0Gz-wqlhAw-1; Fri, 23 Jan 2026 07:21:48 -0500 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C7C8419775A8 for ; Fri, 23 Jan 2026 12:21:47 +0000 (UTC) Received: from localhost.localdomain (unknown [10.72.112.7]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 0F4FF30002DC; Fri, 23 Jan 2026 12:21:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1769170910; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vaPMnSfoRztdHHij+NJ9O+nGEqaIxYFd+PHUxdtCIXI=; b=ZTTckaCMZBx5vvcrLPFwZB8SPjLz3aH+/8LYQiF44XmXFxcU1bzuJwy7GwMg+oQGFtQqd9 Ro6HpCGIyuz6JShcO+r6fjJo1k8N1leLV/3zDm5a+FoamW2i10oC95OPFrcnvuViGwnqEp 37V5xPjztLtRuaSqIR7y83+9ANM40dg= X-MC-Unique: tNTOyCYFPIC-0Gz-wqlhAw-1 X-Mimecast-MFC-AGG-ID: tNTOyCYFPIC-0Gz-wqlhAw_1769170907 From: Jason Wang To: qemu-devel@nongnu.org Cc: Jason Wang Subject: [PULL 11/13] net/filter-redirector: add support for dynamic status on/off switching Date: Fri, 23 Jan 2026 20:21:00 +0800 Message-ID: <20260123122102.51422-12-jasowang@redhat.com> In-Reply-To: <20260123122102.51422-1-jasowang@redhat.com> References: <20260123122102.51422-1-jasowang@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=170.10.133.124; envelope-from=jasowang@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 12 X-Spam_score: 1.2 X-Spam_bar: + X-Spam_report: (1.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.079, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1769171261199158500 Content-Type: text/plain; charset="utf-8" Currently, filter-redirector does not implement the status_changed callback, which means the 'status' property cannot be used to dynamically enable/disable the filter at runtime. When status is set to 'off' via QMP/HMP, the filter still receives data from the indev chardev because the chardev handlers remain registered. This patch adds proper support for the 'status' property: 1. Implement filter_redirector_status_changed() callback: - When status changes to 'off': remove chardev read handlers - When status changes to 'on': re-register chardev handlers (only if chardev is already open) 2. Update filter_redirector_setup() to respect initial status: - If filter is created with status=3Doff, do not register handlers - This allows creating disabled filters via command line or QMP 3. Handle chardev OPENED/CLOSED events to re-arm handlers on reconnect: - Keep the chr_event callback installed on CLOSE so a later OPENED can re-register the read handlers when nf->on - Use qemu_chr_fe_set_handlers_full(..., set_open=3Dfalse, sync_state=3D= false) instead of qemu_chr_fe_set_handlers() because the latter forces sync_state=3Dtrue and may emit CHR_EVENT_OPENED for an already-open backend. Doing that from inside the chr_event callback would cause recursive/re-entrant OPENED handling. Signed-off-by: Jason Wang --- net/filter-mirror.c | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/net/filter-mirror.c b/net/filter-mirror.c index d2bfde42e8..6ac28067a2 100644 --- a/net/filter-mirror.c +++ b/net/filter-mirror.c @@ -179,9 +179,16 @@ static void redirector_chr_event(void *opaque, QEMUChr= Event event) MirrorState *s =3D FILTER_REDIRECTOR(nf); =20 switch (event) { + case CHR_EVENT_OPENED: + if (nf->on) { + qemu_chr_fe_set_handlers_full(&s->chr_in, redirector_chr_can_r= ead, + redirector_chr_read, redirector_= chr_event, + NULL, nf, NULL, false, false); + } + break; case CHR_EVENT_CLOSED: - qemu_chr_fe_set_handlers(&s->chr_in, NULL, NULL, NULL, - NULL, NULL, NULL, true); + qemu_chr_fe_set_handlers_full(&s->chr_in, NULL, NULL, redirector_c= hr_event, + NULL, nf, NULL, false, false); break; default: break; @@ -306,9 +313,11 @@ static void filter_redirector_setup(NetFilterState *nf= , Error **errp) return; } =20 - qemu_chr_fe_set_handlers(&s->chr_in, redirector_chr_can_read, - redirector_chr_read, redirector_chr_event, - NULL, nf, NULL, true); + if (nf->on) { + qemu_chr_fe_set_handlers(&s->chr_in, redirector_chr_can_read, + redirector_chr_read, redirector_chr_e= vent, + NULL, nf, NULL, true); + } } =20 if (s->outdev) { @@ -324,6 +333,24 @@ static void filter_redirector_setup(NetFilterState *nf= , Error **errp) } } =20 +static void filter_redirector_status_changed(NetFilterState *nf, Error **e= rrp) +{ + MirrorState *s =3D FILTER_REDIRECTOR(nf); + + if (!s->indev) { + return; + } + + if (nf->on) { + qemu_chr_fe_set_handlers(&s->chr_in, redirector_chr_can_read, + redirector_chr_read, redirector_chr_event, + NULL, nf, NULL, true); + } else { + qemu_chr_fe_set_handlers(&s->chr_in, NULL, NULL, NULL, + NULL, NULL, NULL, true); + } +} + static char *filter_redirector_get_indev(Object *obj, Error **errp) { MirrorState *s =3D FILTER_REDIRECTOR(obj); @@ -440,6 +467,7 @@ static void filter_redirector_class_init(ObjectClass *o= c, const void *data) nfc->setup =3D filter_redirector_setup; nfc->cleanup =3D filter_redirector_cleanup; nfc->receive_iov =3D filter_redirector_receive_iov; + nfc->status_changed =3D filter_redirector_status_changed; } =20 static void filter_mirror_init(Object *obj) --=20 2.42.0 From nobody Sun Jan 25 10:13:57 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1769171000; cv=none; d=zohomail.com; s=zohoarc; b=l28hfBmtXhdU/+SpUrOyl8RkfZBGbQNONBMEQ60Ao7AvRqSWDHb48dR9SwrCmjzh+cJFwLUWVfwDX3Jh3+TX22OFbZ9fuNfwQs/0kdy74nWztMqaYYsviFeDuCQmOXraVEgR4h+IId4OuSg9u0Ki+X0m8qSDVjFAq+N5w4GjW3U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1769171000; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=i3EVwsiSDB231vkk0/kcTiBiQPVx7EwGjAXn9tukIlg=; b=AvRxUfEmUDvJ0NQqnZQB5TPOHzW75D1CClD0aRHME7yKLWxwSVFCLuoFditETNKqVEsqcBxNztWWzMudrZUW4QHLloTxCsoNravlnToqFDxXWi3XiUNmahDHkmjg5WM4ZjdeM4gm4yMAy7F2dLURJUXAROoaofqBQO/kKq3MKDA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1769171000777356.97297868416; Fri, 23 Jan 2026 04:23:20 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vjGAz-0005iD-G5; Fri, 23 Jan 2026 07:22:09 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vjGAl-0005M6-Rp for qemu-devel@nongnu.org; Fri, 23 Jan 2026 07:21:57 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vjGAk-00057C-7F for qemu-devel@nongnu.org; Fri, 23 Jan 2026 07:21:55 -0500 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-689-Gg2iWrPRMRemoYIIBa5GNw-1; Fri, 23 Jan 2026 07:21:51 -0500 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B4A3E1955F2C; Fri, 23 Jan 2026 12:21:50 +0000 (UTC) Received: from localhost.localdomain (unknown [10.72.112.7]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 985CA30002DC; Fri, 23 Jan 2026 12:21:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1769170913; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=i3EVwsiSDB231vkk0/kcTiBiQPVx7EwGjAXn9tukIlg=; b=AJYbWXULvf4XBZlY7fqNIaPWPGGQFMMVyIKc20RaRcE9zGjTowKYpxB5Tlogg6mzWFAdpO 1XoWJOTXKzK8pRz2z3+/bTm1QXoCco28Dq8qy4IjQBzLYZ3uVaijD/TIx7oML0GM0CbaAz Tj77dcJF0Csezh6Ej5XlsXYWNtY3pBI= X-MC-Unique: Gg2iWrPRMRemoYIIBa5GNw-1 X-Mimecast-MFC-AGG-ID: Gg2iWrPRMRemoYIIBa5GNw_1769170910 From: Jason Wang To: qemu-devel@nongnu.org Cc: Jason Wang , Zhang Chen Subject: [PULL 12/13] qtest: add a test to test redirector status change Date: Fri, 23 Jan 2026 20:21:01 +0800 Message-ID: <20260123122102.51422-13-jasowang@redhat.com> In-Reply-To: <20260123122102.51422-1-jasowang@redhat.com> References: <20260123122102.51422-1-jasowang@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=170.10.129.124; envelope-from=jasowang@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 12 X-Spam_score: 1.2 X-Spam_bar: + X-Spam_report: (1.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.079, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_SBL_CSS=3.335, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1769171003468154100 Content-Type: text/plain; charset="utf-8" This patch adds a qtest to test the status change of filter-redirector. Two subtests were added: - test_redirector_status: tests dynamic on/off switching at runtime using qom-set QMP command - test_redirector_init_status_off: tests creating filter-redirector with status=3Doff from the start via command line Both tests verify that: 1. When status is off, data from indev chardev is not received 2. When status is switched to on, data is received correctly Reviewed-by: Zhang Chen Signed-off-by: Jason Wang --- tests/qtest/test-filter-redirector.c | 192 +++++++++++++++++++++++++++ 1 file changed, 192 insertions(+) diff --git a/tests/qtest/test-filter-redirector.c b/tests/qtest/test-filter= -redirector.c index a996a80c1c..da0c126314 100644 --- a/tests/qtest/test-filter-redirector.c +++ b/tests/qtest/test-filter-redirector.c @@ -196,10 +196,202 @@ static void test_redirector_rx(void) qtest_quit(qts); } =20 +/* + * Test filter-redirector status on/off switching. + * + * This test verifies that: + * 1. When status is set to "off", the filter stops receiving data from in= dev + * 2. When status is set back to "on", the filter resumes receiving data + */ +static void test_redirector_status(void) +{ + int backend_sock[2], send_sock; + uint32_t ret =3D 0, len =3D 0; + char send_buf[] =3D "Hello!!"; + char sock_path0[] =3D "filter-redirector0.XXXXXX"; + char *recv_buf; + uint32_t size =3D sizeof(send_buf); + size =3D htonl(size); + QTestState *qts; + struct timeval tv; + fd_set rfds; + + ret =3D socketpair(PF_UNIX, SOCK_STREAM, 0, backend_sock); + g_assert_cmpint(ret, !=3D, -1); + + ret =3D mkstemp(sock_path0); + g_assert_cmpint(ret, !=3D, -1); + + /* + * Setup a simple rx path: + * chardev (sock_path0) -> filter-redirector -> socket backend + */ + qts =3D qtest_initf( + "-nic socket,id=3Dqtest-bn0,fd=3D%d " + "-chardev socket,id=3Dredirector0,path=3D%s,server=3Don,wait=3Doff= " + "-object filter-redirector,id=3Dqtest-f0,netdev=3Dqtest-bn0," + "queue=3Drx,indev=3Dredirector0 ", + backend_sock[1], sock_path0); + + send_sock =3D unix_connect(sock_path0, NULL); + g_assert_cmpint(send_sock, !=3D, -1); + + /* send a qmp command to guarantee that 'connected' is setting to true= . */ + qtest_qmp_assert_success(qts, "{ 'execute' : 'query-status'}"); + + struct iovec iov[] =3D { + { + .iov_base =3D &size, + .iov_len =3D sizeof(size), + }, { + .iov_base =3D send_buf, + .iov_len =3D sizeof(send_buf), + }, + }; + + /* + * Test 1: Set status to "off" and verify data is not received + */ + qtest_qmp_assert_success(qts, + "{ 'execute': 'qom-set', 'arguments': " + "{ 'path': '/objects/qtest-f0', 'property': 'status', 'value': 'of= f' }}"); + + ret =3D iov_send(send_sock, iov, 2, 0, sizeof(size) + sizeof(send_buf)= ); + g_assert_cmpint(ret, =3D=3D, sizeof(send_buf) + sizeof(size)); + + /* + * Use select with timeout to check if data arrives. + * When status is off, no data should arrive. + */ + FD_ZERO(&rfds); + FD_SET(backend_sock[0], &rfds); + tv.tv_sec =3D 0; + tv.tv_usec =3D 500000; /* 500ms timeout */ + ret =3D select(backend_sock[0] + 1, &rfds, NULL, NULL, &tv); + g_assert_cmpint(ret, =3D=3D, 0); /* Should timeout, no data */ + + /* + * Test 2: Set status back to "on" and verify data is received + */ + qtest_qmp_assert_success(qts, + "{ 'execute': 'qom-set', 'arguments': " + "{ 'path': '/objects/qtest-f0', 'property': 'status', 'value': 'on= ' }}"); + + ret =3D iov_send(send_sock, iov, 2, 0, sizeof(size) + sizeof(send_buf)= ); + g_assert_cmpint(ret, =3D=3D, sizeof(send_buf) + sizeof(size)); + + ret =3D recv(backend_sock[0], &len, sizeof(len), 0); + g_assert_cmpint(ret, =3D=3D, sizeof(len)); + len =3D ntohl(len); + + g_assert_cmpint(len, =3D=3D, sizeof(send_buf)); + recv_buf =3D g_malloc(len); + ret =3D recv(backend_sock[0], recv_buf, len, 0); + g_assert_cmpint(ret, =3D=3D, len); + g_assert_cmpstr(recv_buf, =3D=3D, send_buf); + + g_free(recv_buf); + close(send_sock); + unlink(sock_path0); + qtest_quit(qts); +} + +/* + * Test filter-redirector created with status=3Doff. + * + * This test verifies that when a filter-redirector is created with + * status=3Doff, it does not receive data until status is set to on. + */ +static void test_redirector_init_status_off(void) +{ + int backend_sock[2], send_sock; + uint32_t ret =3D 0, len =3D 0; + char send_buf[] =3D "Hello!!"; + char sock_path0[] =3D "filter-redirector0.XXXXXX"; + char *recv_buf; + uint32_t size =3D sizeof(send_buf); + size =3D htonl(size); + QTestState *qts; + struct timeval tv; + fd_set rfds; + + ret =3D socketpair(PF_UNIX, SOCK_STREAM, 0, backend_sock); + g_assert_cmpint(ret, !=3D, -1); + + ret =3D mkstemp(sock_path0); + g_assert_cmpint(ret, !=3D, -1); + + /* + * Create filter-redirector with status=3Doff from the start + */ + qts =3D qtest_initf( + "-nic socket,id=3Dqtest-bn0,fd=3D%d " + "-chardev socket,id=3Dredirector0,path=3D%s,server=3Don,wait=3Doff= " + "-object filter-redirector,id=3Dqtest-f0,netdev=3Dqtest-bn0," + "queue=3Drx,indev=3Dredirector0,status=3Doff ", + backend_sock[1], sock_path0); + + send_sock =3D unix_connect(sock_path0, NULL); + g_assert_cmpint(send_sock, !=3D, -1); + + qtest_qmp_assert_success(qts, "{ 'execute' : 'query-status'}"); + + struct iovec iov[] =3D { + { + .iov_base =3D &size, + .iov_len =3D sizeof(size), + }, { + .iov_base =3D send_buf, + .iov_len =3D sizeof(send_buf), + }, + }; + + /* + * Test 1: Filter was created with status=3Doff, data should not be re= ceived + */ + ret =3D iov_send(send_sock, iov, 2, 0, sizeof(size) + sizeof(send_buf)= ); + g_assert_cmpint(ret, =3D=3D, sizeof(send_buf) + sizeof(size)); + + FD_ZERO(&rfds); + FD_SET(backend_sock[0], &rfds); + tv.tv_sec =3D 0; + tv.tv_usec =3D 500000; + ret =3D select(backend_sock[0] + 1, &rfds, NULL, NULL, &tv); + g_assert_cmpint(ret, =3D=3D, 0); /* Should timeout, no data */ + + /* + * Test 2: Set status to "on" and verify data is received + */ + qtest_qmp_assert_success(qts, + "{ 'execute': 'qom-set', 'arguments': " + "{ 'path': '/objects/qtest-f0', 'property': 'status', 'value': 'on= ' }}"); + + ret =3D iov_send(send_sock, iov, 2, 0, sizeof(size) + sizeof(send_buf)= ); + g_assert_cmpint(ret, =3D=3D, sizeof(send_buf) + sizeof(size)); + + ret =3D recv(backend_sock[0], &len, sizeof(len), 0); + g_assert_cmpint(ret, =3D=3D, sizeof(len)); + len =3D ntohl(len); + + g_assert_cmpint(len, =3D=3D, sizeof(send_buf)); + recv_buf =3D g_malloc(len); + ret =3D recv(backend_sock[0], recv_buf, len, 0); + g_assert_cmpint(ret, =3D=3D, len); + g_assert_cmpstr(recv_buf, =3D=3D, send_buf); + + g_free(recv_buf); + close(send_sock); + unlink(sock_path0); + qtest_quit(qts); +} + int main(int argc, char **argv) { g_test_init(&argc, &argv, NULL); qtest_add_func("/netfilter/redirector_tx", test_redirector_tx); qtest_add_func("/netfilter/redirector_rx", test_redirector_rx); + qtest_add_func("/netfilter/redirector_status", test_redirector_status); + qtest_add_func("/netfilter/redirector_init_status_off", + test_redirector_init_status_off); return g_test_run(); } --=20 2.42.0 From nobody Sun Jan 25 10:13:57 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1769171367; cv=none; d=zohomail.com; s=zohoarc; b=i1A6tbaHypA9OktN4A0sAwmztureqiQecr0DHpWiGxIzFaQX4jcQL/QSMH7isIK+ti17sUV5ImkY81pxaHrmUwbOmLve5NT13BImuOrfIYySYDNBpWhXKPy+CSz/H8FO8bYEn8UW97b/TtaoNbiaspdQKM+aN6aVxddOq/ZnHzw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1769171367; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=zQJADknNipkIeaFvMv03KcywULGzZAIzWuzM93yH8oM=; b=I4MJa2I21gOFT20eg+x0zRUbQP0zvXIb0vTaUtYR7l/+2cqhGWjjd6DuEBd4pWcXlKYINf1jnefBFgWkh76kKm3DYeiENOSphQGfae+YBSgEeV5J2e/fOGtKVr8ofJGp3Tu7bm7mo4o2YlR+7gkvsfm2udGzKztZuGp52pdPyVc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1769171367179161.8822900912819; Fri, 23 Jan 2026 04:29:27 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vjGB9-00061s-1h; Fri, 23 Jan 2026 07:22:19 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vjGAq-0005Qz-5L for qemu-devel@nongnu.org; Fri, 23 Jan 2026 07:22:00 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vjGAo-00057l-Jw for qemu-devel@nongnu.org; Fri, 23 Jan 2026 07:21:59 -0500 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-7-kei69_OHNByMxsY1dybl8A-1; Fri, 23 Jan 2026 07:21:54 -0500 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C067E1955D84; Fri, 23 Jan 2026 12:21:53 +0000 (UTC) Received: from localhost.localdomain (unknown [10.72.112.7]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 8BB6B30002D1; Fri, 23 Jan 2026 12:21:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1769170917; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zQJADknNipkIeaFvMv03KcywULGzZAIzWuzM93yH8oM=; b=WNI5NaBN56nipKuaMwVPPvvghernsM/NBmIBXxllp6WL8m9G/rvxZVFZzmLXaGCV2xKoHc E9WiU4NQGgNPPN0I6BZ5/6Egmxjg/uVVfJywrQhIiF+9N4atRyjDtwR2IGm7RRH9uA0T+w ndTLsiPvarMrbo4W2PhSsAWgNAGWFSs= X-MC-Unique: kei69_OHNByMxsY1dybl8A-1 X-Mimecast-MFC-AGG-ID: kei69_OHNByMxsY1dybl8A_1769170913 From: Jason Wang To: qemu-devel@nongnu.org Cc: Jason Wang , Zhang Chen Subject: [PULL 13/13] tests/qtest: Add test for filter-redirector rx event opened Date: Fri, 23 Jan 2026 20:21:02 +0800 Message-ID: <20260123122102.51422-14-jasowang@redhat.com> In-Reply-To: <20260123122102.51422-1-jasowang@redhat.com> References: <20260123122102.51422-1-jasowang@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=170.10.129.124; envelope-from=jasowang@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 12 X-Spam_score: 1.2 X-Spam_bar: + X-Spam_report: (1.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.079, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_SBL_CSS=3.335, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1769171367762158500 Content-Type: text/plain; charset="utf-8" Add a new test case 'test_redirector_rx_event_opened' to verify the handling of the CHR_EVENT_OPENED event in filter-redirector. The test simulates a scenario where the backend character device (socket) is disconnected and then reconnected. It works by: 1. Connecting to the redirector's socket (triggers CHR_EVENT_OPENED). 2. Sending a packet to verify initial connectivity. 3. Disconnecting (triggers CHR_EVENT_CLOSED). 4. Reconnecting (triggers CHR_EVENT_OPENED again). 5. Sending another packet to verify that the redirector correctly re-registers its handlers and resumes passing traffic. This ensures that the filter-redirector can recover and function correctly after a backend reconnection. Reviewed-by: Zhang Chen Signed-off-by: Jason Wang --- tests/qtest/test-filter-redirector.c | 96 ++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) diff --git a/tests/qtest/test-filter-redirector.c b/tests/qtest/test-filter= -redirector.c index da0c126314..5540c232c0 100644 --- a/tests/qtest/test-filter-redirector.c +++ b/tests/qtest/test-filter-redirector.c @@ -385,6 +385,100 @@ static void test_redirector_init_status_off(void) qtest_quit(qts); } =20 +static void test_redirector_rx_event_opened(void) +{ + int backend_sock[2], send_sock; + uint32_t ret =3D 0, len =3D 0; + char send_buf[] =3D "Hello!!"; + char send_buf2[] =3D "Hello2!!"; + char sock_path0[] =3D "filter-redirector0.XXXXXX"; + char *recv_buf; + uint32_t size =3D sizeof(send_buf); + uint32_t size2 =3D sizeof(send_buf2); + size =3D htonl(size); + size2 =3D htonl(size2); + QTestState *qts; + + ret =3D socketpair(PF_UNIX, SOCK_STREAM, 0, backend_sock); + g_assert_cmpint(ret, !=3D, -1); + + ret =3D mkstemp(sock_path0); + g_assert_cmpint(ret, !=3D, -1); + + qts =3D qtest_initf( + "-nic socket,id=3Dqtest-bn0,fd=3D%d " + "-chardev socket,id=3Dredirector0,path=3D%s,server=3Don,wait=3Doff= " + "-object filter-redirector,id=3Dqtest-f0,netdev=3Dqtest-bn0," + "queue=3Drx,indev=3Dredirector0 ", + backend_sock[1], sock_path0); + + struct iovec iov[] =3D { + { + .iov_base =3D &size, + .iov_len =3D sizeof(size), + }, { + .iov_base =3D send_buf, + .iov_len =3D sizeof(send_buf), + }, + }; + + struct iovec iov2[] =3D { + { + .iov_base =3D &size2, + .iov_len =3D sizeof(size2), + }, { + .iov_base =3D send_buf2, + .iov_len =3D sizeof(send_buf2), + }, + }; + + /* First connection */ + send_sock =3D unix_connect(sock_path0, NULL); + g_assert_cmpint(send_sock, !=3D, -1); + qtest_qmp_assert_success(qts, "{ 'execute' : 'query-status'}"); + + ret =3D iov_send(send_sock, iov, 2, 0, sizeof(size) + sizeof(send_buf)= ); + g_assert_cmpint(ret, =3D=3D, sizeof(send_buf) + sizeof(size)); + + ret =3D recv(backend_sock[0], &len, sizeof(len), 0); + g_assert_cmpint(ret, =3D=3D, sizeof(len)); + len =3D ntohl(len); + g_assert_cmpint(len, =3D=3D, sizeof(send_buf)); + recv_buf =3D g_malloc(len); + ret =3D recv(backend_sock[0], recv_buf, len, 0); + g_assert_cmpint(ret, =3D=3D, len); + g_assert_cmpstr(recv_buf, =3D=3D, send_buf); + g_free(recv_buf); + + close(send_sock); + + /* Verify disconnection handling if needed, but mainly we want to test= Reconnection */ + qtest_qmp_assert_success(qts, "{ 'execute' : 'query-status'}"); + + /* Second connection */ + send_sock =3D unix_connect(sock_path0, NULL); + g_assert_cmpint(send_sock, !=3D, -1); + qtest_qmp_assert_success(qts, "{ 'execute' : 'query-status'}"); + + ret =3D iov_send(send_sock, iov2, 2, 0, sizeof(size2) + sizeof(send_bu= f2)); + g_assert_cmpint(ret, =3D=3D, sizeof(send_buf2) + sizeof(size2)); + + ret =3D recv(backend_sock[0], &len, sizeof(len), 0); + g_assert_cmpint(ret, =3D=3D, sizeof(len)); + len =3D ntohl(len); + g_assert_cmpint(len, =3D=3D, sizeof(send_buf2)); + recv_buf =3D g_malloc(len); + ret =3D recv(backend_sock[0], recv_buf, len, 0); + g_assert_cmpint(ret, =3D=3D, len); + g_assert_cmpstr(recv_buf, =3D=3D, send_buf2); + g_free(recv_buf); + + close(send_sock); + unlink(sock_path0); + qtest_quit(qts); + close(backend_sock[0]); +} + int main(int argc, char **argv) { g_test_init(&argc, &argv, NULL); @@ -393,5 +487,7 @@ int main(int argc, char **argv) qtest_add_func("/netfilter/redirector_status", test_redirector_status); qtest_add_func("/netfilter/redirector_init_status_off", test_redirector_init_status_off); + qtest_add_func("/netfilter/redirector_rx_event_opened", + test_redirector_rx_event_opened); return g_test_run(); } --=20 2.42.0