From nobody Fri Nov 14 18:23:12 2025 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=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1760118227; cv=none; d=zohomail.com; s=zohoarc; b=M6L/SLSeDzuR51azwA0eteQ5dmGBynJiaHvRriufSsfF3Ytwodvsdx7zUlx/euCfcGKNGu7nWKSpSPlS+ypWjx12lRSbWgRAodhxMF5fYo6iT0suID6Q2SIxPHzaxnM6fIcYTjVz3jkbw3I/bd4OJLszhmxKk3dKLfNQb46fYlA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760118227; h=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=hNNyaUEJ3Cj5e7CyfXk59JiOH0k3NnD3beCoPCNADKM=; b=Hzi9G3/XKdcRnL8cM2tomcGwoTm7sVtsfDKAPuENl8S4cwdC1Rivm01D5EMwN3/08T3AlqC6F6eeJL3qSTWRKwKtuq2RxA9dZhs64ZBFFEzK1hooEzeN3a/hcglo7wenMQS8yn2m6WedPfldJVwJLPZJl2374+ARHzZTIvbuyrk= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 176011822719346.24160042453525; Fri, 10 Oct 2025 10:43:47 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v7H6U-0008Dz-0J; Fri, 10 Oct 2025 13:40:30 -0400 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 1v7H6P-00089n-UC for qemu-devel@nongnu.org; Fri, 10 Oct 2025 13:40:25 -0400 Received: from forwardcorp1b.mail.yandex.net ([178.154.239.136]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v7H6B-0007JD-L3 for qemu-devel@nongnu.org; Fri, 10 Oct 2025 13:40:25 -0400 Received: from mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:9297:0:640:61e7:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTPS id 526628074F; Fri, 10 Oct 2025 20:40:03 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a89::1:23]) by mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id xdPFQ30FtmI0-Wk0rXZxf; Fri, 10 Oct 2025 20:40:01 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1760118001; bh=hNNyaUEJ3Cj5e7CyfXk59JiOH0k3NnD3beCoPCNADKM=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=FG93afAA/I2j4BipCyhsZ4nTHk8UdHJYEgHs6FNxj7xFJUgH9mxoZvFH9P/HzGDnX VDwuT2A/pbvBiQhS/TLHxDn+IjpUwAys64f2cKfwU5/L+l71u/2f4+bkH9dzrX2lvA T2daKdVutWE5t96Yfe8LZ/yV5oY8fK1i4D5lebl0= Authentication-Results: mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com, jasowang@redhat.com Cc: peterx@redhat.com, farosas@suse.de, sw@weilnetz.de, eblake@redhat.com, armbru@redhat.com, thuth@redhat.com, philmd@linaro.org, berrange@redhat.com, qemu-devel@nongnu.org, michael.roth@amd.com, steven.sistare@oracle.com, leiyang@redhat.com, davydov-max@yandex-team.ru, yc-core@yandex-team.ru, vsementsov@yandex-team.ru, raphael.s.norwitz@gmail.com Subject: [PATCH v7 01/19] net/tap: net_init_tap_one(): drop extra error propagation Date: Fri, 10 Oct 2025 20:39:39 +0300 Message-ID: <20251010173957.166759-2-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251010173957.166759-1-vsementsov@yandex-team.ru> References: <20251010173957.166759-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=178.154.239.136; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1b.mail.yandex.net X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=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 List-Id: 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 @yandex-team.ru) X-ZM-MESSAGEID: 1760118228664158502 Content-Type: text/plain; charset="utf-8" Signed-off-by: Vladimir Sementsov-Ogievskiy Tested-by: Lei Yang Reviewed-by: Maksim Davydov --- net/tap.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/net/tap.c b/net/tap.c index abe3b2d036..70de798fe8 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.48.1 From nobody Fri Nov 14 18:23:12 2025 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=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1760118227; cv=none; d=zohomail.com; s=zohoarc; b=mtN7assPBb+nkRR9W8i2LGZQhNendsa80pARyPcCVCCeC7JXLLHS7dtDqbpNbmQjeeQmGELmCQp7QkMRGhFMJogRMAjWLMWykSCMgZa1vUmr3Sj63daQdwsXNqpc0xYMVM0Fw2pQN/VBivhQU/sA4gwqkjbmKFG9vtScf1zKR3c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760118227; h=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=bbvjn2b2AN6mVV4jMAmeSq+jgoBhCopUSDtTBCApKuY=; b=SrpNNIP4I6ex99Cpa/D0JyUMYFJEL2H1U9jjP4edUNc1kBgf0xrDPxGDl5krfXljS4Ska/CcmjNn+Y1Vf9Sg78L2CLYYxyqP6JkFtV9JD9XdrrV2nif0zQ/EFD2TdNu/w3M5RfHtNujwV10cht7FKvDKPRxW4w6T3o7fzrGT9mU= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1760118226651603.1248852146709; Fri, 10 Oct 2025 10:43:46 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v7H6b-0008G2-W4; Fri, 10 Oct 2025 13:40:38 -0400 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 1v7H6X-0008FM-Pp for qemu-devel@nongnu.org; Fri, 10 Oct 2025 13:40:33 -0400 Received: from forwardcorp1a.mail.yandex.net ([2a02:6b8:c0e:500:1:45:d181:df01]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v7H6H-0007Rh-Nd for qemu-devel@nongnu.org; Fri, 10 Oct 2025 13:40:33 -0400 Received: from mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:9297:0:640:61e7:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id 67A28C00B7; Fri, 10 Oct 2025 20:40:04 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a89::1:23]) by mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id xdPFQ30FtmI0-lwkDM22p; Fri, 10 Oct 2025 20:40:03 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1760118003; bh=bbvjn2b2AN6mVV4jMAmeSq+jgoBhCopUSDtTBCApKuY=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=v2NS/UZzwR+wBq49jMm0NAY0blGLUSeHb7OqA1tGHttEpkFb4PmhYAq0HCSKtzAey bygP92ydvesCin8ZXTxRd0ksKF80AcSdcHyBzSxoRvfE1tQzZBr9Io/h9x7zbMyShN +lFfkNeTS+oomqiQxTI9rjbXra055rFv4eRlCOi0= Authentication-Results: mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com, jasowang@redhat.com Cc: peterx@redhat.com, farosas@suse.de, sw@weilnetz.de, eblake@redhat.com, armbru@redhat.com, thuth@redhat.com, philmd@linaro.org, berrange@redhat.com, qemu-devel@nongnu.org, michael.roth@amd.com, steven.sistare@oracle.com, leiyang@redhat.com, davydov-max@yandex-team.ru, yc-core@yandex-team.ru, vsementsov@yandex-team.ru, raphael.s.norwitz@gmail.com Subject: [PATCH v7 02/19] net/tap: net_init_tap_one(): move parameter checking earlier Date: Fri, 10 Oct 2025 20:39:40 +0300 Message-ID: <20251010173957.166759-3-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251010173957.166759-1-vsementsov@yandex-team.ru> References: <20251010173957.166759-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=2a02:6b8:c0e:500:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1a.mail.yandex.net X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=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 List-Id: 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 @yandex-team.ru) X-ZM-MESSAGEID: 1760118230562158500 Content-Type: text/plain; charset="utf-8" Let's keep all similar argument checking in net_init_tap() function. Signed-off-by: Vladimir Sementsov-Ogievskiy Tested-by: Lei Yang Reviewed-by: Maksim Davydov --- net/tap.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/net/tap.c b/net/tap.c index 70de798fe8..f90050c3a0 100644 --- a/net/tap.c +++ b/net/tap.c @@ -768,9 +768,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; @@ -832,6 +829,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.48.1 From nobody Fri Nov 14 18:23:12 2025 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=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1760118084; cv=none; d=zohomail.com; s=zohoarc; b=h99B7CwQ1o1Ka8qVWMzyp9Mwq8CLZlmlLiaEX2D7rGdRYAfNbov55nwac3PDPe5AhP0pUise9K9DuWbN9ITO/On9sEM1JFMuE0UjRkMZOK7p7DHdlTrAeEPKCUqoI3GD5Db89PAElDFeVdHC8GPNfsjHoYLGMtWu6rV/ChxFA0Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760118084; h=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=sWnY8ZzMlkKOLKPtaKjH3fVS/aysz4QqO5yCpSiiFBE=; b=U8EG59+qFK5eme2x7euwnW8pRb3mnYu7qGi9nCquTepzglDgvXnQx45p7i3TCn+Xk3aBmxR+wzq/Ver+SHQb1RZNAxwtSbmVC+6t8jfd/wdSMRY2muMcYwzKFxBcV2/Y2cVlxca/ThBHcud8mT0WdNfWRliuw05wOoSOUGACssM= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1760118084283844.5343103392789; Fri, 10 Oct 2025 10:41:24 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v7H6M-00084B-O8; Fri, 10 Oct 2025 13:40:22 -0400 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 1v7H6H-0007zF-VA for qemu-devel@nongnu.org; Fri, 10 Oct 2025 13:40:19 -0400 Received: from forwardcorp1d.mail.yandex.net ([2a02:6b8:c41:1300:1:45:d181:df01]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v7H6A-0007RY-OL for qemu-devel@nongnu.org; Fri, 10 Oct 2025 13:40:16 -0400 Received: from mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:9297:0:640:61e7:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id 2E5F9806FA; Fri, 10 Oct 2025 20:40:05 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a89::1:23]) by mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id xdPFQ30FtmI0-DvJXLtwd; Fri, 10 Oct 2025 20:40:04 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1760118004; bh=sWnY8ZzMlkKOLKPtaKjH3fVS/aysz4QqO5yCpSiiFBE=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=BEcx68vKSJlYfP3Ryq1HWQbwx/58Mcu1O9ZC+bajTVDzGuy7ev3KTuV/hksftCqND lsWxz9brUwXnZCgSOKAUS9c1p8bxLYeb2vH6FQdkstuP55vKim9iz7b0MPBDG36h9Z lX5NexUIE7R0SygyFXDnFFla8APyM3YuJp3mXQYE= Authentication-Results: mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com, jasowang@redhat.com Cc: peterx@redhat.com, farosas@suse.de, sw@weilnetz.de, eblake@redhat.com, armbru@redhat.com, thuth@redhat.com, philmd@linaro.org, berrange@redhat.com, qemu-devel@nongnu.org, michael.roth@amd.com, steven.sistare@oracle.com, leiyang@redhat.com, davydov-max@yandex-team.ru, yc-core@yandex-team.ru, vsementsov@yandex-team.ru, raphael.s.norwitz@gmail.com Subject: [PATCH v7 03/19] net/tap: rework net_tap_init() Date: Fri, 10 Oct 2025 20:39:41 +0300 Message-ID: <20251010173957.166759-4-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251010173957.166759-1-vsementsov@yandex-team.ru> References: <20251010173957.166759-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=2a02:6b8:c41:1300:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1d.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=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 List-Id: 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 @yandex-team.ru) X-ZM-MESSAGEID: 1760118090019158500 Content-Type: text/plain; charset="utf-8" In future (to support backend-transfer migration for virtio-net/tap, which includes fds passing through unix socket) we'll want to postpone fd-initialization to the later point, when QAPI structured parameters are not available. So, let's now rework the function to interface without "tap" parameter. Also, rename to net_tap_open(), as it's just a wrapper on tap_open(), and having net_tap_init() and net_init_tap() functions in one file is confusing. Signed-off-by: Vladimir Sementsov-Ogievskiy Tested-by: Lei Yang Reviewed-by: Maksim Davydov --- net/tap.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/net/tap.c b/net/tap.c index f90050c3a0..b1b64c508d 100644 --- a/net/tap.c +++ b/net/tap.c @@ -655,20 +655,12 @@ int net_init_bridge(const Netdev *netdev, const char = *name, return 0; } =20 -static int net_tap_init(const NetdevTapOptions *tap, int *vnet_hdr, +static int net_tap_open(int *vnet_hdr, bool vnet_hdr_required, const char *setup_script, char *ifname, size_t ifname_sz, int mq_required, Error **errp) { Error *err =3D NULL; - int fd, vnet_hdr_required; - - if (tap->has_vnet_hdr) { - *vnet_hdr =3D tap->vnet_hdr; - vnet_hdr_required =3D *vnet_hdr; - } else { - *vnet_hdr =3D 1; - vnet_hdr_required =3D 0; - } + int fd; =20 fd =3D RETRY_ON_EINTR(tap_open(ifname, ifname_sz, vnet_hdr, vnet_hdr_r= equired, mq_required, errp)); @@ -977,6 +969,8 @@ free_fail: } else { g_autofree char *default_script =3D NULL; g_autofree char *default_downscript =3D NULL; + bool vnet_hdr_required =3D tap->has_vnet_hdr && tap->vnet_hdr; + if (tap->vhostfds) { error_setg(errp, "vhostfds=3D is invalid if fds=3D wasn't spec= ified"); return -1; @@ -997,7 +991,9 @@ free_fail: } =20 for (i =3D 0; i < queues; i++) { - fd =3D net_tap_init(tap, &vnet_hdr, i >=3D 1 ? "no" : script, + vnet_hdr =3D tap->has_vnet_hdr ? tap->vnet_hdr : 1; + fd =3D net_tap_open(&vnet_hdr, vnet_hdr_required, + i >=3D 1 ? "no" : script, ifname, sizeof ifname, queues > 1, errp); if (fd =3D=3D -1) { return -1; --=20 2.48.1 From nobody Fri Nov 14 18:23:12 2025 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=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1760118145; cv=none; d=zohomail.com; s=zohoarc; b=BRqbNiqHYF0dGzdBcacPwZS3RoiTHHnKts6Xs50ycowz7qR8MaPSjS5E5uXkKrEUEevACtUFN116v2RQW9qyr/u2uN9nShXMXqj0sW98v85tlNWvHwp4woC7mhkgivPTQvC9VtdgLN8Ok5OgJrfqi5NQFWyzyl2QhBjBdV9ME9M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760118145; h=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=qRZTogNTqI/NlvPAmDaFtUT9hXrMy3NPHnhfaXmrOwM=; b=nje59QQ082CORdtyWL0vY69rlnzNP/YKdbiVeEkdc8PHqBadCEcmV7FrPrIXYJ6vJBkgmbKcZq44NCSQIDq3N1Nm38P6djIIvkg623r1WU2RLGBhWmihoujIUeiPBBqXPPvd3XPfoRaIfOqOpB++twxjMEezNfftHnDqLJ4y0Y0= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1760118145863597.3248504869226; Fri, 10 Oct 2025 10:42:25 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v7H6c-0008Gy-7T; Fri, 10 Oct 2025 13:40:38 -0400 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 1v7H6V-0008Ed-Sa for qemu-devel@nongnu.org; Fri, 10 Oct 2025 13:40:32 -0400 Received: from forwardcorp1a.mail.yandex.net ([2a02:6b8:c0e:500:1:45:d181:df01]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v7H6C-0007Rg-SX for qemu-devel@nongnu.org; Fri, 10 Oct 2025 13:40:30 -0400 Received: from mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:9297:0:640:61e7:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id 0863FC00B8; Fri, 10 Oct 2025 20:40:06 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a89::1:23]) by mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id xdPFQ30FtmI0-UgN6n4KO; Fri, 10 Oct 2025 20:40:05 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1760118005; bh=qRZTogNTqI/NlvPAmDaFtUT9hXrMy3NPHnhfaXmrOwM=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=j36Gjb7VRPnabJvU5G0KIvFqE1B+ngb91YP7ZGmYawyJtJNkZbFTJMDU0X87dlyr8 HuvQBA145xG8IC8MSmLSIKp0b1E6T+DKsLiQzzlm5NKcUaJhRBo9fyE9jdsIbfPRJ4 rhv9xABzNwtgngzt+ad6QE3a7ot+b/jicb/4SwVU= Authentication-Results: mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com, jasowang@redhat.com Cc: peterx@redhat.com, farosas@suse.de, sw@weilnetz.de, eblake@redhat.com, armbru@redhat.com, thuth@redhat.com, philmd@linaro.org, berrange@redhat.com, qemu-devel@nongnu.org, michael.roth@amd.com, steven.sistare@oracle.com, leiyang@redhat.com, davydov-max@yandex-team.ru, yc-core@yandex-team.ru, vsementsov@yandex-team.ru, raphael.s.norwitz@gmail.com Subject: [PATCH v7 04/19] net/tap: pass NULL to net_init_tap_one() in cases when scripts are NULL Date: Fri, 10 Oct 2025 20:39:42 +0300 Message-ID: <20251010173957.166759-5-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251010173957.166759-1-vsementsov@yandex-team.ru> References: <20251010173957.166759-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=2a02:6b8:c0e:500:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1a.mail.yandex.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, T_SPF_TEMPERROR=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: 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 @yandex-team.ru) X-ZM-MESSAGEID: 1760118150505154100 Content-Type: text/plain; charset="utf-8" Directly pass NULL in cases where we report an error if script or downscript are set. Signed-off-by: Vladimir Sementsov-Ogievskiy Tested-by: Lei Yang Reviewed-by: Maksim Davydov --- net/tap.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/net/tap.c b/net/tap.c index b1b64c508d..a05cc7ef64 100644 --- a/net/tap.c +++ b/net/tap.c @@ -800,8 +800,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]; @@ -811,8 +809,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. */ @@ -853,7 +849,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); @@ -914,7 +910,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) { @@ -959,7 +955,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); @@ -967,6 +963,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; bool vnet_hdr_required =3D tap->has_vnet_hdr && tap->vnet_hdr; --=20 2.48.1 From nobody Fri Nov 14 18:23:12 2025 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=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1760118300; cv=none; d=zohomail.com; s=zohoarc; b=cVXEpMO14RK+OWCTfeVs7jzib0gCcMUSb+LGIoS6QJN83xDlqdC99Swyo9Dt9xjILxkG6+1leBX8FR9bB8VgtuNOuzE5wBZun3Yk+vtB8Y1gydhh0DHkNREViynB7zVq8bbNHi6kC3fMMyBZ21G9TGge8zv1WukwvElpxmxlQHs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760118300; h=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=CH1U52vxvOc9yKk9t/kUb3x+nUIUMQAF51KvUr2wRZY=; b=Js2D2QsEIhtYDaKBJ3qlnrRG/Ee0cQWLr9Lb044WhpC6XeWTHLm3J5bs8Lu+0XgjTcUSlZVgSKWt+zZEDvKJWkVriLKbs5fC7V4cexDyKmjIHaYY2Yb667kjZe1Fi3lEbDlWR/jlOEJgsIPTISI++PKa3NW9FrHVOA31J1LVPlA= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1760118300243971.8420573608636; Fri, 10 Oct 2025 10:45:00 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v7H6Q-0008Aj-OJ; Fri, 10 Oct 2025 13:40:26 -0400 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 1v7H6P-000888-7E for qemu-devel@nongnu.org; Fri, 10 Oct 2025 13:40:25 -0400 Received: from forwardcorp1a.mail.yandex.net ([178.154.239.72]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v7H6D-0007Rl-7y for qemu-devel@nongnu.org; Fri, 10 Oct 2025 13:40:24 -0400 Received: from mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:9297:0:640:61e7:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id D015EC0148; Fri, 10 Oct 2025 20:40:06 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a89::1:23]) by mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id xdPFQ30FtmI0-i8JKKzjw; Fri, 10 Oct 2025 20:40:06 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1760118006; bh=CH1U52vxvOc9yKk9t/kUb3x+nUIUMQAF51KvUr2wRZY=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=SoAz3VvOtLz1b1SWMJEdKPWk8vKlpaRtDQiXM7SA0rXM2BRtIGJPMLiQnUeyVdEfO EHg+dCziwgA43rrag3Iw5Y+xItCK+C6zgxXdLdta+PlGZXlJDqZ+O/j72Xrz+Ew4xX x2xGHBB3cae5bBA+ThNXZcFZy5I3iMwRYA0O77gE= Authentication-Results: mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com, jasowang@redhat.com Cc: peterx@redhat.com, farosas@suse.de, sw@weilnetz.de, eblake@redhat.com, armbru@redhat.com, thuth@redhat.com, philmd@linaro.org, berrange@redhat.com, qemu-devel@nongnu.org, michael.roth@amd.com, steven.sistare@oracle.com, leiyang@redhat.com, davydov-max@yandex-team.ru, yc-core@yandex-team.ru, vsementsov@yandex-team.ru, raphael.s.norwitz@gmail.com Subject: [PATCH v7 05/19] net/tap: rework scripts handling Date: Fri, 10 Oct 2025 20:39:43 +0300 Message-ID: <20251010173957.166759-6-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251010173957.166759-1-vsementsov@yandex-team.ru> References: <20251010173957.166759-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=178.154.239.72; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1a.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=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 List-Id: 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 @yandex-team.ru) X-ZM-MESSAGEID: 1760118302320154100 Content-Type: text/plain; charset="utf-8" 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 Tested-by: Lei Yang Reviewed-by: Maksim Davydov --- net/tap.c | 45 +++++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/net/tap.c b/net/tap.c index a05cc7ef64..994e885c5f 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, @@ -668,9 +683,7 @@ static int net_tap_open(int *vnet_hdr, bool vnet_hdr_re= quired, 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); @@ -706,9 +719,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); @@ -963,10 +976,10 @@ 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); bool vnet_hdr_required =3D tap->has_vnet_hdr && tap->vnet_hdr; =20 if (tap->vhostfds) { @@ -974,14 +987,6 @@ free_fail: 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 { @@ -991,7 +996,7 @@ free_fail: for (i =3D 0; i < queues; i++) { vnet_hdr =3D tap->has_vnet_hdr ? tap->vnet_hdr : 1; fd =3D net_tap_open(&vnet_hdr, vnet_hdr_required, - i >=3D 1 ? "no" : script, + i >=3D 1 ? NULL : script, ifname, sizeof ifname, queues > 1, errp); if (fd =3D=3D -1) { return -1; @@ -1006,8 +1011,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.48.1 From nobody Fri Nov 14 18:23:12 2025 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=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1760118351; cv=none; d=zohomail.com; s=zohoarc; b=YFtMLtIShv6Gz9T1Fse4IRzbykrAatNLWoeLNfzBdNsfzkJ5684VTlnu+gvUg0qrI7k7dXstHYVRRJyEjXU/VHYvJ1Zr1BIudjlxYkSq1TcHRd+AGux3JpwvDEyLa/qxhUFxivBBpqYd+h+CnRv3UUak5x0iIHVmXzMptCp2vb0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760118351; h=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=AqHqBScLVphRHYcYitihKjsg9x0DNw0fNX+yiK30WWI=; b=I6RVx9dnl9odx/vWZKY7KHi/Rc97z1Y5XXf2vc8tEWAO3IchSrvIaTYIfsN5OZViJNaD2IvpxxR6fSCvRB432tD4dRB3KlkfbgsI2Ivspjy24JVu9eYG0YlR6B/NtjbNOVdGhIFqQ0faqQfFLbm8u3ttoC32CeNVLhHV39he6ng= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 176011835163529.26743466870323; Fri, 10 Oct 2025 10:45:51 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v7H6P-00087C-Kl; Fri, 10 Oct 2025 13:40:25 -0400 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 1v7H6M-00083y-7g for qemu-devel@nongnu.org; Fri, 10 Oct 2025 13:40:22 -0400 Received: from forwardcorp1d.mail.yandex.net ([178.154.239.200]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v7H6B-0007Rr-C9 for qemu-devel@nongnu.org; Fri, 10 Oct 2025 13:40:20 -0400 Received: from mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:9297:0:640:61e7:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id 8C5BE80787; Fri, 10 Oct 2025 20:40:07 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a89::1:23]) by mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id xdPFQ30FtmI0-NRxkOOZG; Fri, 10 Oct 2025 20:40:07 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1760118007; bh=AqHqBScLVphRHYcYitihKjsg9x0DNw0fNX+yiK30WWI=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=BEF3J81FIMPxj4UPUw3Kcd2aIZfgSPYOmBIBk8/OMkiicS3OM/H2+pAM70zfag0YU H4YOfCV0UxJSP9zz9wAjSkUzE1kDvLtB5TdVgxxZG02+XtoeN9pFV3b0U6LwODe81H KVYuk75YuKEbIOSRR1nomMT1oruhqAq4nsrds/To= Authentication-Results: mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com, jasowang@redhat.com Cc: peterx@redhat.com, farosas@suse.de, sw@weilnetz.de, eblake@redhat.com, armbru@redhat.com, thuth@redhat.com, philmd@linaro.org, berrange@redhat.com, qemu-devel@nongnu.org, michael.roth@amd.com, steven.sistare@oracle.com, leiyang@redhat.com, davydov-max@yandex-team.ru, yc-core@yandex-team.ru, vsementsov@yandex-team.ru, raphael.s.norwitz@gmail.com Subject: [PATCH v7 06/19] net/tap: setup exit notifier only when needed Date: Fri, 10 Oct 2025 20:39:44 +0300 Message-ID: <20251010173957.166759-7-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251010173957.166759-1-vsementsov@yandex-team.ru> References: <20251010173957.166759-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=178.154.239.200; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1d.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=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 List-Id: 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 @yandex-team.ru) X-ZM-MESSAGEID: 1760118354788154101 Content-Type: text/plain; charset="utf-8" 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 Tested-by: Lei Yang Reviewed-by: Maksim Davydov --- net/tap.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/net/tap.c b/net/tap.c index 994e885c5f..17ad561f9c 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 @@ -725,6 +723,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.48.1 From nobody Fri Nov 14 18:23:12 2025 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=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1760118135; cv=none; d=zohomail.com; s=zohoarc; b=F0fqy3doMIfrOuDNb/54VgKEzdzFjcTO0P4e2brJM8KD523HQn3tHxdgNkynhY9lR2IJwbv6rAtZBzYAQ+KJauipBMkO3hPDhwEFUNZfdO6QcbwRM5/SK0G0VhER/bPr7eyOAcCVSO5Sr7Og1eoVaeIOWaWUjnXEEQwHYCTkr+c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760118135; h=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=hBBLVUnal74IiYpctK3zPNaVGPEhk/xudXLj3q7/EVs=; b=I+a65ySlIz4Ula9sYj/QxcZVPxe3uIkQ4/L9EbrFC51eqCGJwph26zDEYHW78LgndjSiG2iI5YDSQsHw2kGngMVtha3RaQ6nhYZTCuc3/jQYOL2kXC0mIZm3KfQYiR0GGc1KIid53XHBJeW1+J3XsANPdnWZa095lY3XTDVZiyg= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1760118135255154.3090575010632; Fri, 10 Oct 2025 10:42:15 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v7H6Z-0008FN-Ua; Fri, 10 Oct 2025 13:40:35 -0400 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 1v7H6V-0008Ec-Pv for qemu-devel@nongnu.org; Fri, 10 Oct 2025 13:40:31 -0400 Received: from forwardcorp1b.mail.yandex.net ([178.154.239.136]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v7H6I-0007S6-4p for qemu-devel@nongnu.org; Fri, 10 Oct 2025 13:40:29 -0400 Received: from mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:9297:0:640:61e7:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTPS id 4EC8880779; Fri, 10 Oct 2025 20:40:08 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a89::1:23]) by mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id xdPFQ30FtmI0-VUhflSaL; Fri, 10 Oct 2025 20:40:07 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1760118007; bh=hBBLVUnal74IiYpctK3zPNaVGPEhk/xudXLj3q7/EVs=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=lOsT0asiaq4LvDxJoeJ2FbujrUqswhvJad8m/iB4AXV5iVoLCAlWBH/myOWeKUqIa 20RO9O8xRT64WvTRWTHpYl/5zyUHDRsfb7BV73LILPU87fMcZttx2bDnp1JlCX2fLk e0smBUbqciIvZJv9VqxgXSp3T75NGyv7f8EF7V0E= Authentication-Results: mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com, jasowang@redhat.com Cc: peterx@redhat.com, farosas@suse.de, sw@weilnetz.de, eblake@redhat.com, armbru@redhat.com, thuth@redhat.com, philmd@linaro.org, berrange@redhat.com, qemu-devel@nongnu.org, michael.roth@amd.com, steven.sistare@oracle.com, leiyang@redhat.com, davydov-max@yandex-team.ru, yc-core@yandex-team.ru, vsementsov@yandex-team.ru, raphael.s.norwitz@gmail.com Subject: [PATCH v7 07/19] net/tap: split net_tap_fd_init() Date: Fri, 10 Oct 2025 20:39:45 +0300 Message-ID: <20251010173957.166759-8-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251010173957.166759-1-vsementsov@yandex-team.ru> References: <20251010173957.166759-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=178.154.239.136; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1b.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=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 List-Id: 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 @yandex-team.ru) X-ZM-MESSAGEID: 1760118140554154100 Content-Type: text/plain; charset="utf-8" Split the function into separate net_tap_new() and net_tap_set_fd(). We start move to the following picture: net_tap_new() - take QAPI @tap parameter, but don't have @fd, initialize the net client, called during initialization. net_tap_setup() - don't have @tap (QAPI), but have @fd parameter, may be called at later point. In this commit we introduce the first function. Signed-off-by: Vladimir Sementsov-Ogievskiy Tested-by: Lei Yang Reviewed-by: Maksim Davydov --- net/tap.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/net/tap.c b/net/tap.c index 17ad561f9c..7cb694e683 100644 --- a/net/tap.c +++ b/net/tap.c @@ -412,19 +412,20 @@ static NetClientInfo net_tap_info =3D { .get_vhost_net =3D tap_get_vhost_net, }; =20 -static TAPState *net_tap_fd_init(NetClientState *peer, - const char *model, - const char *name, - int fd, - int vnet_hdr) +static TAPState *net_tap_new(NetClientState *peer, const char *model, + const char *name) { - NetOffloads ol =3D {}; - NetClientState *nc; - TAPState *s; + NetClientState *nc =3D qemu_new_net_client(&net_tap_info, peer, model,= name); + TAPState *s =3D DO_UPCAST(TAPState, nc, nc); =20 - nc =3D qemu_new_net_client(&net_tap_info, peer, model, name); + s->fd =3D -1; =20 - s =3D DO_UPCAST(TAPState, nc, nc); + return s; +} + +static void net_tap_set_fd(TAPState *s, int fd, int vnet_hdr) +{ + NetOffloads ol =3D {}; =20 s->fd =3D fd; s->host_vnet_hdr_len =3D vnet_hdr ? sizeof(struct virtio_net_hdr) : 0; @@ -443,8 +444,6 @@ static TAPState *net_tap_fd_init(NetClientState *peer, } tap_read_poll(s, true); s->vhost_net =3D NULL; - - return s; } =20 static void close_all_fds_after_fork(int excluded_fd) @@ -661,7 +660,9 @@ int net_init_bridge(const Netdev *netdev, const char *n= ame, close(fd); return -1; } - s =3D net_tap_fd_init(peer, "bridge", name, fd, vnet_hdr); + + s =3D net_tap_new(peer, "bridge", name); + net_tap_set_fd(s, fd, vnet_hdr); =20 qemu_set_info_str(&s->nc, "helper=3D%s,br=3D%s", helper, br); =20 @@ -702,9 +703,11 @@ static void net_init_tap_one(const NetdevTapOptions *t= ap, NetClientState *peer, int vnet_hdr, int fd, Error **errp) { Error *err =3D NULL; - TAPState *s =3D net_tap_fd_init(peer, model, name, fd, vnet_hdr); + TAPState *s =3D net_tap_new(peer, model, name); int vhostfd; =20 + net_tap_set_fd(s, fd, vnet_hdr); + tap_set_sndbuf(s->fd, tap, &err); if (err) { error_propagate(errp, err); --=20 2.48.1 From nobody Fri Nov 14 18:23:12 2025 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=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1760118218; cv=none; d=zohomail.com; s=zohoarc; b=F89hW64RhOUu3eG5g2IdBnwtn7FRSX9aUGcej1nAYg/hCwr7gLWuZlU6fV7tmI1HSN+fz5ORf0GI1kigeM13wOPWLYu8+h4pf3GNOCAR0gN9+wRiNFg3YGv85g7QbDE+t3d6Mz05UsAhHJm+EOc6QISVK3sMOQ/3iTegcub+kEU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760118218; h=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=nnKwp9UVQ4ods/yG1iyoepfjor+lRBQrWYh08dJIpQ8=; b=nj32tWPrQZ92+8ciUAPSW2BdpUFIUYJpiwGeeg7aw4NYD5bRle2+sxxNJqiNlD8/M9BNcZSzCgG6MR+T89dSWBXgdEduMBAYeoQE08AbZgr/WksSMPBDJOVxMjLwKegZxvDRDJ3iCOrpgp4ssCEFdVhHJK9IZWQBLJ4Ww6oE6qk= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1760118218069715.3813202806143; Fri, 10 Oct 2025 10:43:38 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v7H6f-0008Hu-8U; Fri, 10 Oct 2025 13:40:41 -0400 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 1v7H6Z-0008GD-T6 for qemu-devel@nongnu.org; Fri, 10 Oct 2025 13:40:35 -0400 Received: from forwardcorp1b.mail.yandex.net ([178.154.239.136]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v7H6H-0007SI-Lz for qemu-devel@nongnu.org; Fri, 10 Oct 2025 13:40:35 -0400 Received: from mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:9297:0:640:61e7:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTPS id 5DEBE807DC; Fri, 10 Oct 2025 20:40:09 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a89::1:23]) by mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id xdPFQ30FtmI0-jXC9gl68; Fri, 10 Oct 2025 20:40:08 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1760118008; bh=nnKwp9UVQ4ods/yG1iyoepfjor+lRBQrWYh08dJIpQ8=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=e7uP+jHW6EqRddxTE0n8B9i1218oYYb27bGdfwh5K++yeG67OiLERVrzc7zMTY6IQ 4koimPa8liE3bKIANDSqEKpVqEMgeEDFKkhKzSBycee4W0ikz1/QbOfw43R5oycEyV Z0dkujkCH6pT2r8I4LAPAZzxo7wb+qBhawwDWmog= Authentication-Results: mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com, jasowang@redhat.com Cc: peterx@redhat.com, farosas@suse.de, sw@weilnetz.de, eblake@redhat.com, armbru@redhat.com, thuth@redhat.com, philmd@linaro.org, berrange@redhat.com, qemu-devel@nongnu.org, michael.roth@amd.com, steven.sistare@oracle.com, leiyang@redhat.com, davydov-max@yandex-team.ru, yc-core@yandex-team.ru, vsementsov@yandex-team.ru, raphael.s.norwitz@gmail.com Subject: [PATCH v7 08/19] net/tap: tap_set_sndbuf(): add return value Date: Fri, 10 Oct 2025 20:39:46 +0300 Message-ID: <20251010173957.166759-9-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251010173957.166759-1-vsementsov@yandex-team.ru> References: <20251010173957.166759-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=178.154.239.136; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1b.mail.yandex.net X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=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 List-Id: 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 @yandex-team.ru) X-ZM-MESSAGEID: 1760118223172158500 Content-Type: text/plain; charset="utf-8" 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 Tested-by: Lei Yang Reviewed-by: Maksim Davydov --- 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 bbf84d1828..9bd282b69c 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 2a90b58467..db68693bbf 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 75397e6c54..e5ba89d926 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 7cb694e683..25dedd8492 100644 --- a/net/tap.c +++ b/net/tap.c @@ -702,15 +702,12 @@ 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_new(peer, model, name); int vhostfd; =20 net_tap_set_fd(s, fd, vnet_hdr); =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.48.1 From nobody Fri Nov 14 18:23:12 2025 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=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1760118321; cv=none; d=zohomail.com; s=zohoarc; b=Fpf1k3oUNZXz9x4zrvYC4d4TgEZ9muWnGzxyB1khoXe8D0Ip7B1+29GGYmKsdGoFhj+t2m0S3VIAQ/uOOjaeLw66mL7qAahgxM098QnRMEmNye7/W7DmjZtmuP+5lRnJz+8S/Amo79oF/g/AEYogalgg0k5y9rnj7plKtBWqr20= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760118321; h=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=i1cFQjSXciecDMWlo5WBjvLdJBze5d5h6eICW7ris+Q=; b=RT77Sjm97oG3eywQH0gEglI52sTOzhR1kJckNAWKVyc5O068+zd91RKBRnhRL6Uct82NOWreE2u9uSzL0R2+rg7M4Yke6cJu/lCORKDQix/Zvk3wU4mGD6bZaSZ5RVGIt51TZH9dllbw18pgPEqmqYp1smi7m7lHyw7bYYHLaX0= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1760118321171758.75922995648; Fri, 10 Oct 2025 10:45:21 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v7H6Q-00089e-Un; Fri, 10 Oct 2025 13:40:27 -0400 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 1v7H6O-00086o-F9 for qemu-devel@nongnu.org; Fri, 10 Oct 2025 13:40:24 -0400 Received: from forwardcorp1d.mail.yandex.net ([2a02:6b8:c41:1300:1:45:d181:df01]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v7H6H-0007SX-0K for qemu-devel@nongnu.org; Fri, 10 Oct 2025 13:40:24 -0400 Received: from mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:9297:0:640:61e7:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id 582DA80474; Fri, 10 Oct 2025 20:40:10 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a89::1:23]) by mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id xdPFQ30FtmI0-bo14vNwd; Fri, 10 Oct 2025 20:40:09 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1760118009; bh=i1cFQjSXciecDMWlo5WBjvLdJBze5d5h6eICW7ris+Q=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=ulVgOVznImhyyNRRuccTEIVNjgIvotLTXHOvZfYD07uLql2Bz2Kgv9LHlWbXm5RzF x5PQFfFOnJ8iWUol5f7kv2QlMphfUYqCDl4BRZLzcX9XABYQ6FJhv/xG6ArlcFT/+l cAcLDJli+E3hTruB+wmnMDtG/AmljX6rxuFJbdd8= Authentication-Results: mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com, jasowang@redhat.com Cc: peterx@redhat.com, farosas@suse.de, sw@weilnetz.de, eblake@redhat.com, armbru@redhat.com, thuth@redhat.com, philmd@linaro.org, berrange@redhat.com, qemu-devel@nongnu.org, michael.roth@amd.com, steven.sistare@oracle.com, leiyang@redhat.com, davydov-max@yandex-team.ru, yc-core@yandex-team.ru, vsementsov@yandex-team.ru, raphael.s.norwitz@gmail.com Subject: [PATCH v7 09/19] net/tap: rework tap_set_sndbuf() Date: Fri, 10 Oct 2025 20:39:47 +0300 Message-ID: <20251010173957.166759-10-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251010173957.166759-1-vsementsov@yandex-team.ru> References: <20251010173957.166759-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=2a02:6b8:c41:1300:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1d.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=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 List-Id: 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 @yandex-team.ru) X-ZM-MESSAGEID: 1760118324734154100 Content-Type: text/plain; charset="utf-8" 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 Tested-by: Lei Yang Reviewed-by: Maksim Davydov --- 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 9bd282b69c..4cea60664e 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 db68693bbf..bb73fa4b13 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 e5ba89d926..e925ca8ae9 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 25dedd8492..f5830f4b00 100644 --- a/net/tap.c +++ b/net/tap.c @@ -704,10 +704,14 @@ static void net_init_tap_one(const NetdevTapOptions *= tap, NetClientState *peer, { TAPState *s =3D net_tap_new(peer, model, name); 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 net_tap_set_fd(s, fd, vnet_hdr); =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.48.1 From nobody Fri Nov 14 18:23:12 2025 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=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1760118220; cv=none; d=zohomail.com; s=zohoarc; b=Efc/u/6AYGAviz5FGNQL7cbjJcIiCXQPxFseLcH8J9wBBYRZaQIYUj2lhmAcp1FQq5XpaXSAKIuDqVXCWx9Z51BGZVaugkR50G9D6ArJIDkOPDU3A9HLm1XGJ8Bj/O6TIWoYgnkqtxwqG6vyoUqwZgKSxtHWNbCQeP5ludB8uPI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760118220; h=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=Rn2HksTFyzmo06oKJaSInOpdhEVFJkUFFxj6tzH9yK8=; b=RC8WFoWSq7Mtl3yrBIGoLRxO1aazliZFvF5J5dNeuKsV0DHTNcYvF89pXPWTsNyY2il7KSZ2tb388bmhXQYVM4fpAqaPF/dmCl9MYCS4rgFzM2dAl5Bc+jq7qABU2BMga4ZJIlkXxHCQbY5le/cVybI1Deq3Bh8WOczNIiB08ZA= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1760118220859788.8526010495585; Fri, 10 Oct 2025 10:43:40 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v7H6S-0008DA-4q; Fri, 10 Oct 2025 13:40:28 -0400 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 1v7H6R-0008Bg-Dz for qemu-devel@nongnu.org; Fri, 10 Oct 2025 13:40:27 -0400 Received: from forwardcorp1a.mail.yandex.net ([2a02:6b8:c0e:500:1:45:d181:df01]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v7H6H-0007Sg-Nc for qemu-devel@nongnu.org; Fri, 10 Oct 2025 13:40:27 -0400 Received: from mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:9297:0:640:61e7:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id 3C4CEC0173; Fri, 10 Oct 2025 20:40:11 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a89::1:23]) by mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id xdPFQ30FtmI0-ktFbvmr4; Fri, 10 Oct 2025 20:40:10 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1760118010; bh=Rn2HksTFyzmo06oKJaSInOpdhEVFJkUFFxj6tzH9yK8=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=oIltdWR/YxsBGUSBzdOvYMJsxMIdn6MtY0N38kTZoegge93Ude9+O4ob+kpgnf+dp H97cosfjl3BZtKSPu/PKX7IxV7i65KgxBSRk2VvkSTGcC+HlZXlN4kijB06wEhfLe8 A+78C4KVEyD54app/iuEe6F+PTszGThpd/05TNkg= Authentication-Results: mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com, jasowang@redhat.com Cc: peterx@redhat.com, farosas@suse.de, sw@weilnetz.de, eblake@redhat.com, armbru@redhat.com, thuth@redhat.com, philmd@linaro.org, berrange@redhat.com, qemu-devel@nongnu.org, michael.roth@amd.com, steven.sistare@oracle.com, leiyang@redhat.com, davydov-max@yandex-team.ru, yc-core@yandex-team.ru, vsementsov@yandex-team.ru, raphael.s.norwitz@gmail.com Subject: [PATCH v7 10/19] net/tap: rework sndbuf handling Date: Fri, 10 Oct 2025 20:39:48 +0300 Message-ID: <20251010173957.166759-11-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251010173957.166759-1-vsementsov@yandex-team.ru> References: <20251010173957.166759-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=2a02:6b8:c0e:500:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1a.mail.yandex.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=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 List-Id: 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 @yandex-team.ru) X-ZM-MESSAGEID: 1760118224486158500 Content-Type: text/plain; charset="utf-8" Continue the main idea: avoid dependency on @tap in net_tap_setup(). So, move QAPI parsing to net_tap_new(). Move setting sndbuf to net_tap_set_fd(), as it's more appropriate place (other initial fd settings are here). Note that net_tap_new() and net_tap_set_fd() are shared with net_init_bridge(), which didn't set sndbuf. Handle this case by sndbuf=3D0 (we never pass zero to tap_set_sndbuf(), so let this specific value mean that we don't want touch sndbuf). Signed-off-by: Vladimir Sementsov-Ogievskiy Tested-by: Lei Yang Reviewed-by: Maksim Davydov --- net/tap.c | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/net/tap.c b/net/tap.c index f5830f4b00..b5ac856a3d 100644 --- a/net/tap.c +++ b/net/tap.c @@ -83,6 +83,9 @@ typedef struct TAPState { VHostNetState *vhost_net; unsigned host_vnet_hdr_len; Notifier exit; + + bool sndbuf_required; + int sndbuf; } TAPState; =20 static void launch_script(const char *setup_script, const char *ifname, @@ -413,17 +416,25 @@ static NetClientInfo net_tap_info =3D { }; =20 static TAPState *net_tap_new(NetClientState *peer, const char *model, - const char *name) + const char *name, const NetdevTapOptions *tap) { NetClientState *nc =3D qemu_new_net_client(&net_tap_info, peer, model,= name); TAPState *s =3D DO_UPCAST(TAPState, nc, nc); =20 s->fd =3D -1; =20 + if (!tap) { + return s; + } + + s->sndbuf_required =3D tap->has_sndbuf; + s->sndbuf =3D + (tap->has_sndbuf && tap->sndbuf) ? MIN(tap->sndbuf, INT_MAX) : INT= _MAX; + return s; } =20 -static void net_tap_set_fd(TAPState *s, int fd, int vnet_hdr) +static bool net_tap_set_fd(TAPState *s, int fd, int vnet_hdr, Error **errp) { NetOffloads ol =3D {}; =20 @@ -444,6 +455,15 @@ static void net_tap_set_fd(TAPState *s, int fd, int vn= et_hdr) } tap_read_poll(s, true); s->vhost_net =3D NULL; + + if (s->sndbuf) { + Error **e =3D s->sndbuf_required ? errp : NULL; + if (!tap_set_sndbuf(s->fd, s->sndbuf, e) && s->sndbuf_required) { + return false; + } + } + + return true; } =20 static void close_all_fds_after_fork(int excluded_fd) @@ -661,8 +681,8 @@ int net_init_bridge(const Netdev *netdev, const char *n= ame, return -1; } =20 - s =3D net_tap_new(peer, "bridge", name); - net_tap_set_fd(s, fd, vnet_hdr); + s =3D net_tap_new(peer, "bridge", name, NULL); + net_tap_set_fd(s, fd, vnet_hdr, &error_abort); =20 qemu_set_info_str(&s->nc, "helper=3D%s,br=3D%s", helper, br); =20 @@ -702,16 +722,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) { - TAPState *s =3D net_tap_new(peer, model, name); + TAPState *s =3D net_tap_new(peer, model, name, tap); int vhostfd; - bool sndbuf_required =3D tap->has_sndbuf; - int sndbuf =3D - (tap->has_sndbuf && tap->sndbuf) ? MIN(tap->sndbuf, INT_MAX) : INT= _MAX; - - net_tap_set_fd(s, fd, vnet_hdr); =20 - if (!tap_set_sndbuf(fd, sndbuf, sndbuf_required ? errp : NULL) && - sndbuf_required) { + if (!net_tap_set_fd(s, fd, vnet_hdr, errp)) { goto failed; } =20 --=20 2.48.1 From nobody Fri Nov 14 18:23:12 2025 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=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1760118305; cv=none; d=zohomail.com; s=zohoarc; b=fU9/pJ6O3km+33K9+c38kys+b7/wki4o0kc/vt5533FIW8Z3lH63SeFjsfuRGQ5cN1UqAOoxcWPgi7kXpIvRwe4XZOm2l4e40hiUfsP8y3iq0nplHQiStytXHOF33d4amK4BVFFXQa92GKcG5HiU/qb0PmB22radIDSFv97V2Mc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760118305; h=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=bQt+gPOuzNBNYHmDfV4+WMNfu6qlQ2YEWlgC+gNksfY=; b=CJFx6Yib+HSW70nbWYEOyiMjsrMn3M98g/Wom2aLH/6bRoPIEfMsDWMmJ7FwtmJoFvQc/ErRqonNhWOR8VV9ydJ3blFirFm+Az/YGEUlZP190WaX3uAof7OB4mWf2ELbvXMhJmwDfABvCZ0sPsqdYjF9E5liMdDuLa4HPTfa/mY= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1760118305844648.9919789323487; Fri, 10 Oct 2025 10:45:05 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v7H6q-0008Jt-9Z; Fri, 10 Oct 2025 13:40:52 -0400 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 1v7H6b-0008Gp-Sz for qemu-devel@nongnu.org; Fri, 10 Oct 2025 13:40:37 -0400 Received: from forwardcorp1b.mail.yandex.net ([2a02:6b8:c02:900:1:45:d181:df01]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v7H6J-0007Sq-LW for qemu-devel@nongnu.org; Fri, 10 Oct 2025 13:40:36 -0400 Received: from mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:9297:0:640:61e7:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTPS id 254BC807A9; Fri, 10 Oct 2025 20:40:12 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a89::1:23]) by mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id xdPFQ30FtmI0-SHDFVDmL; Fri, 10 Oct 2025 20:40:11 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1760118011; bh=bQt+gPOuzNBNYHmDfV4+WMNfu6qlQ2YEWlgC+gNksfY=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=Q2bflAHJ39jjC+2SsDtFeNDQycL723FbCIA6pIpy4bOZKW0l7JVVBIRWcCrOAPASJ V/XfKbCHqaQfo8oLRZDCO/sBDv+2+aE5kUrevXuGQDaXhb9ZsYzWud1JkUaS4mJdJv gyGMuw6B9Y1rlZa1b4QlhTpcyIgBN1AjN3nm8fSI= Authentication-Results: mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com, jasowang@redhat.com Cc: peterx@redhat.com, farosas@suse.de, sw@weilnetz.de, eblake@redhat.com, armbru@redhat.com, thuth@redhat.com, philmd@linaro.org, berrange@redhat.com, qemu-devel@nongnu.org, michael.roth@amd.com, steven.sistare@oracle.com, leiyang@redhat.com, davydov-max@yandex-team.ru, yc-core@yandex-team.ru, vsementsov@yandex-team.ru, raphael.s.norwitz@gmail.com Subject: [PATCH v7 11/19] net/tap: introduce net_tap_setup() Date: Fri, 10 Oct 2025 20:39:49 +0300 Message-ID: <20251010173957.166759-12-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251010173957.166759-1-vsementsov@yandex-team.ru> References: <20251010173957.166759-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=2a02:6b8:c02:900:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1b.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=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 List-Id: 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 @yandex-team.ru) X-ZM-MESSAGEID: 1760118309642158500 Content-Type: text/plain; charset="utf-8" Move most of net_init_tap_one() to net_tap_setup() - future pair for net_tap_new(), for postponed setup. Signed-off-by: Vladimir Sementsov-Ogievskiy Tested-by: Lei Yang Reviewed-by: Maksim Davydov --- net/tap.c | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/net/tap.c b/net/tap.c index b5ac856a3d..b01cd4d6c2 100644 --- a/net/tap.c +++ b/net/tap.c @@ -88,6 +88,10 @@ typedef struct TAPState { int sndbuf; } TAPState; =20 +static bool net_tap_setup(TAPState *s, const NetdevTapOptions *tap, + const char *vhostfdname, + int fd, int vnet_hdr, Error **errp); + static void launch_script(const char *setup_script, const char *ifname, int fd, Error **errp); =20 @@ -723,11 +727,6 @@ static void net_init_tap_one(const NetdevTapOptions *t= ap, NetClientState *peer, int vnet_hdr, int fd, Error **errp) { TAPState *s =3D net_tap_new(peer, model, name, tap); - int vhostfd; - - if (!net_tap_set_fd(s, fd, vnet_hdr, errp)) { - goto failed; - } =20 if (tap->fd || tap->fds) { qemu_set_info_str(&s->nc, "fd=3D%d", fd); @@ -746,6 +745,21 @@ static void net_init_tap_one(const NetdevTapOptions *t= ap, NetClientState *peer, } } =20 + if (!net_tap_setup(s, tap, vhostfdname, fd, vnet_hdr, errp)) { + qemu_del_net_client(&s->nc); + } +} + +static bool net_tap_setup(TAPState *s, const NetdevTapOptions *tap, + const char *vhostfdname, + int fd, int vnet_hdr, Error **errp) +{ + int vhostfd; + + if (!net_tap_set_fd(s, fd, vnet_hdr, errp)) { + return false; + } + if (tap->has_vhost ? tap->vhost : vhostfdname || (tap->has_vhostforce && tap->vhostforce)) { VhostNetOptions options; @@ -761,20 +775,20 @@ static void net_init_tap_one(const NetdevTapOptions *= tap, NetClientState *peer, if (vhostfdname) { vhostfd =3D monitor_fd_param(monitor_cur(), vhostfdname, errp); if (vhostfd =3D=3D -1) { - goto failed; + return false; } if (!qemu_set_blocking(vhostfd, false, errp)) { - goto failed; + return false; } } else { vhostfd =3D open("/dev/vhost-net", O_RDWR); if (vhostfd < 0) { error_setg_errno(errp, errno, "tap: open vhost char device failed"); - goto failed; + return false; } if (!qemu_set_blocking(vhostfd, false, errp)) { - goto failed; + return false; } } options.opaque =3D (void *)(uintptr_t)vhostfd; @@ -789,14 +803,11 @@ static void net_init_tap_one(const NetdevTapOptions *= tap, NetClientState *peer, if (!s->vhost_net) { error_setg(errp, "vhost-net requested but could not be initialized"); - goto failed; + return false; } } =20 - return; - -failed: - qemu_del_net_client(&s->nc); + return true; } =20 static int get_fds(char *str, char *fds[], int max) --=20 2.48.1 From nobody Fri Nov 14 18:23:12 2025 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=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1760118162; cv=none; d=zohomail.com; s=zohoarc; b=Egzf7sKNmrvx5SgfDw4GpEA9eLHoUoK20dRmh+u5A+GBOLy94F5QxzynEaBVAPrmN37q0nHOkMTj7MyL/YTNvMU34CjuYBnwAr/QEWssFr51fYqrkj7x+ptrsOI+bi+e1VIOETHEJ/toTqpbN+9gMPoQwi/HMZSwlvxFmyIHYJM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760118162; h=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=nl2+2Bb8Tc8O3k95uaNJdjhEm6v2qoQg7sRCDCKeFb4=; b=cEgy2zi3qem7txcusOppWkv2hY7dKIjArG/zeeFbNCRUBGSju8lSHHCPL6f2j0W2HSFQHfeQTJzU7yEopZxQhKhHMvR4SduvHxCwjIif8PmP+VkQC9fAbFUAT7ONde/B3BMZoCdOTD5vGvr2xb+W8smGqRM41bS3CyZzWk7uaqU= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1760118162868804.7089629554048; Fri, 10 Oct 2025 10:42:42 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v7H6s-0008Ky-Cg; Fri, 10 Oct 2025 13:40:54 -0400 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 1v7H6j-0008Iq-8z for qemu-devel@nongnu.org; Fri, 10 Oct 2025 13:40:46 -0400 Received: from forwardcorp1a.mail.yandex.net ([178.154.239.72]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v7H6J-0007TQ-UL for qemu-devel@nongnu.org; Fri, 10 Oct 2025 13:40:43 -0400 Received: from mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:9297:0:640:61e7:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id F2E1CC0177; Fri, 10 Oct 2025 20:40:12 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a89::1:23]) by mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id xdPFQ30FtmI0-GFfeL6ht; Fri, 10 Oct 2025 20:40:12 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1760118012; bh=nl2+2Bb8Tc8O3k95uaNJdjhEm6v2qoQg7sRCDCKeFb4=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=i6GJBRgKSzliPngBM589FXBgO+c07aCssUGedb87vJsZhy9Z1ZOOePEOAF1CyV8Lk n5eYuJw9sq3sr+tZZ9zOiYNxZTXUbaBX8qL5q+VSgLeB78MDN4eqWItPGgvhg1zFFX WRJGit/LG5QSF8AwRqd73+7xYxjttCfvafPjImhM= Authentication-Results: mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com, jasowang@redhat.com Cc: peterx@redhat.com, farosas@suse.de, sw@weilnetz.de, eblake@redhat.com, armbru@redhat.com, thuth@redhat.com, philmd@linaro.org, berrange@redhat.com, qemu-devel@nongnu.org, michael.roth@amd.com, steven.sistare@oracle.com, leiyang@redhat.com, davydov-max@yandex-team.ru, yc-core@yandex-team.ru, vsementsov@yandex-team.ru, raphael.s.norwitz@gmail.com Subject: [PATCH v7 12/19] net/tap: move vhost fd initialization to net_tap_new() Date: Fri, 10 Oct 2025 20:39:50 +0300 Message-ID: <20251010173957.166759-13-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251010173957.166759-1-vsementsov@yandex-team.ru> References: <20251010173957.166759-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=178.154.239.72; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1a.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=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 List-Id: 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 @yandex-team.ru) X-ZM-MESSAGEID: 1760118164110158500 Content-Type: text/plain; charset="utf-8" Continue the track to avoid dependency on @tap in net_tap_setup(), no move the vhost fd initialization to net_tap_new(). So in net_tap_setup() we simply check, do we have and vhostfd at this point or not. Signed-off-by: Vladimir Sementsov-Ogievskiy Tested-by: Lei Yang Reviewed-by: Maksim Davydov --- net/tap.c | 90 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 50 insertions(+), 40 deletions(-) diff --git a/net/tap.c b/net/tap.c index b01cd4d6c2..d08ef070e9 100644 --- a/net/tap.c +++ b/net/tap.c @@ -86,11 +86,11 @@ typedef struct TAPState { =20 bool sndbuf_required; int sndbuf; + int vhostfd; + uint32_t vhost_busyloop_timeout; } TAPState; =20 -static bool net_tap_setup(TAPState *s, const NetdevTapOptions *tap, - const char *vhostfdname, - int fd, int vnet_hdr, Error **errp); +static bool net_tap_setup(TAPState *s, int fd, int vnet_hdr, Error **errp); =20 static void launch_script(const char *setup_script, const char *ifname, int fd, Error **errp); @@ -361,6 +361,11 @@ static void tap_cleanup(NetClientState *nc) tap_write_poll(s, false); close(s->fd); s->fd =3D -1; + + if (s->vhostfd !=3D -1) { + close(s->vhostfd); + s->vhostfd =3D -1; + } } =20 static void tap_poll(NetClientState *nc, bool enable) @@ -420,12 +425,14 @@ static NetClientInfo net_tap_info =3D { }; =20 static TAPState *net_tap_new(NetClientState *peer, const char *model, - const char *name, const NetdevTapOptions *tap) + const char *name, const NetdevTapOptions *tap, + const char *vhostfdname, Error **errp) { NetClientState *nc =3D qemu_new_net_client(&net_tap_info, peer, model,= name); TAPState *s =3D DO_UPCAST(TAPState, nc, nc); =20 s->fd =3D -1; + s->vhostfd =3D -1; =20 if (!tap) { return s; @@ -435,7 +442,36 @@ static TAPState *net_tap_new(NetClientState *peer, con= st char *model, s->sndbuf =3D (tap->has_sndbuf && tap->sndbuf) ? MIN(tap->sndbuf, INT_MAX) : INT= _MAX; =20 + if (tap->has_vhost ? tap->vhost : + vhostfdname || (tap->has_vhostforce && tap->vhostforce)) { + if (vhostfdname) { + s->vhostfd =3D monitor_fd_param(monitor_cur(), vhostfdname, er= rp); + if (s->vhostfd =3D=3D -1) { + goto failed; + } + if (!qemu_set_blocking(s->vhostfd, false, errp)) { + goto failed; + } + } else { + s->vhostfd =3D open("/dev/vhost-net", O_RDWR); + if (s->vhostfd < 0) { + error_setg_errno(errp, errno, + "tap: open vhost char device failed"); + goto failed; + } + if (!qemu_set_blocking(s->vhostfd, false, errp)) { + goto failed; + } + } + + s->vhost_busyloop_timeout =3D tap->has_poll_us ? tap->poll_us : 0; + } + return s; + +failed: + qemu_del_net_client(&s->nc); + return NULL; } =20 static bool net_tap_set_fd(TAPState *s, int fd, int vnet_hdr, Error **errp) @@ -685,7 +721,7 @@ int net_init_bridge(const Netdev *netdev, const char *n= ame, return -1; } =20 - s =3D net_tap_new(peer, "bridge", name, NULL); + s =3D net_tap_new(peer, "bridge", name, NULL, NULL, &error_abort); net_tap_set_fd(s, fd, vnet_hdr, &error_abort); =20 qemu_set_info_str(&s->nc, "helper=3D%s,br=3D%s", helper, br); @@ -726,7 +762,10 @@ static void net_init_tap_one(const NetdevTapOptions *t= ap, NetClientState *peer, const char *downscript, const char *vhostfdna= me, int vnet_hdr, int fd, Error **errp) { - TAPState *s =3D net_tap_new(peer, model, name, tap); + TAPState *s =3D net_tap_new(peer, model, name, tap, vhostfdname, errp); + if (!s) { + return; + } =20 if (tap->fd || tap->fds) { qemu_set_info_str(&s->nc, "fd=3D%d", fd); @@ -745,53 +784,24 @@ static void net_init_tap_one(const NetdevTapOptions *= tap, NetClientState *peer, } } =20 - if (!net_tap_setup(s, tap, vhostfdname, fd, vnet_hdr, errp)) { + if (!net_tap_setup(s, fd, vnet_hdr, errp)) { qemu_del_net_client(&s->nc); } } =20 -static bool net_tap_setup(TAPState *s, const NetdevTapOptions *tap, - const char *vhostfdname, - int fd, int vnet_hdr, Error **errp) +static bool net_tap_setup(TAPState *s, int fd, int vnet_hdr, Error **errp) { - int vhostfd; - if (!net_tap_set_fd(s, fd, vnet_hdr, errp)) { return false; } =20 - if (tap->has_vhost ? tap->vhost : - vhostfdname || (tap->has_vhostforce && tap->vhostforce)) { + if (s->vhostfd !=3D -1) { VhostNetOptions options; =20 options.backend_type =3D VHOST_BACKEND_TYPE_KERNEL; options.net_backend =3D &s->nc; - if (tap->has_poll_us) { - options.busyloop_timeout =3D tap->poll_us; - } else { - options.busyloop_timeout =3D 0; - } - - if (vhostfdname) { - vhostfd =3D monitor_fd_param(monitor_cur(), vhostfdname, errp); - if (vhostfd =3D=3D -1) { - return false; - } - if (!qemu_set_blocking(vhostfd, false, errp)) { - return false; - } - } else { - vhostfd =3D open("/dev/vhost-net", O_RDWR); - if (vhostfd < 0) { - error_setg_errno(errp, errno, - "tap: open vhost char device failed"); - return false; - } - if (!qemu_set_blocking(vhostfd, false, errp)) { - return false; - } - } - options.opaque =3D (void *)(uintptr_t)vhostfd; + options.busyloop_timeout =3D s->vhost_busyloop_timeout; + options.opaque =3D (void *)(uintptr_t)s->vhostfd; options.nvqs =3D 2; options.feature_bits =3D kernel_feature_bits; options.get_acked_features =3D NULL; --=20 2.48.1 From nobody Fri Nov 14 18:23:12 2025 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=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1760118169; cv=none; d=zohomail.com; s=zohoarc; b=ZqnhWoNsCFuHlJMSH8V8JZNS5VjrxYBaoZUpEufbJllo+nQhaI+tLnSD55i3S8N/Ut6Wseixv5QRjRW2h1FKwuTG4thaqGx/TDRl+yJt1stZpyqRBM+80bztzmhY4C/m42maF2/wKB4ziDtCda1OZDKCDkIj4F1OGZ5j4e/89rU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760118169; h=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=UicDA5etzsJjSp7/6GitAPJDaIZ/euilBHmOaCwUrWA=; b=j8+Bk10SHzzvQFzCb4IDJq/OdSojrEsFW1pvObYXtxug6tRpea8LzFHMlnvy0ugAYe/HV6LZFi3iIPPcFmQ8JKeTfJx1PnDfj8N3jETaAm7O8ne56LRM4aClaEza1c2WOsRmAD9uAR9cKppoS4MP370XQXEp3g4wPZ79K+qJeaQ= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1760118169235902.6585768458672; Fri, 10 Oct 2025 10:42:49 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v7H6q-0008KD-82; Fri, 10 Oct 2025 13:40:52 -0400 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 1v7H6l-0008J6-7e for qemu-devel@nongnu.org; Fri, 10 Oct 2025 13:40:49 -0400 Received: from forwardcorp1b.mail.yandex.net ([178.154.239.136]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v7H6J-0007Tb-OS for qemu-devel@nongnu.org; Fri, 10 Oct 2025 13:40:46 -0400 Received: from mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:9297:0:640:61e7:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTPS id B289D807EE; Fri, 10 Oct 2025 20:40:13 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a89::1:23]) by mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id xdPFQ30FtmI0-yWC79TkM; Fri, 10 Oct 2025 20:40:13 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1760118013; bh=UicDA5etzsJjSp7/6GitAPJDaIZ/euilBHmOaCwUrWA=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=k4ATWK+vvtP8PSWaPD2fXhKR5+vxba6uu0mdtOG/sU45g9OZj0NUMDv1lvmhkwB2E 4N6OJ9pATAVYtKxnGGxxoGW7Z/gPl6UHUbfWAFb609AWG+WVB7yoHpN4M1FNQVt1hi 8tEIWa33aXJpiFi2TwYVauPfVoqAVIo3iXNe1was= Authentication-Results: mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com, jasowang@redhat.com Cc: peterx@redhat.com, farosas@suse.de, sw@weilnetz.de, eblake@redhat.com, armbru@redhat.com, thuth@redhat.com, philmd@linaro.org, berrange@redhat.com, qemu-devel@nongnu.org, michael.roth@amd.com, steven.sistare@oracle.com, leiyang@redhat.com, davydov-max@yandex-team.ru, yc-core@yandex-team.ru, vsementsov@yandex-team.ru, raphael.s.norwitz@gmail.com Subject: [PATCH v7 13/19] net/tap: finalize net_tap_set_fd() logic Date: Fri, 10 Oct 2025 20:39:51 +0300 Message-ID: <20251010173957.166759-14-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251010173957.166759-1-vsementsov@yandex-team.ru> References: <20251010173957.166759-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=178.154.239.136; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1b.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=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 List-Id: 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 @yandex-team.ru) X-ZM-MESSAGEID: 1760118172357154100 Content-Type: text/plain; charset="utf-8" Let net_tap_set_fd() do only fd-related setup. Actually, for further backend-transfer migration for virtio-net/tap we'll want to skip net_tap_set_fd() (as incoming fds are already prepared by source QEMU). So move tap_read_poll() to net_tap_setup(). Don't care about using_vnet_hdr and vhost_net, the state is zero-initialized. Signed-off-by: Vladimir Sementsov-Ogievskiy Tested-by: Lei Yang Reviewed-by: Maksim Davydov --- net/tap.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/net/tap.c b/net/tap.c index d08ef070e9..7e85444ace 100644 --- a/net/tap.c +++ b/net/tap.c @@ -480,7 +480,6 @@ static bool net_tap_set_fd(TAPState *s, int fd, int vne= t_hdr, Error **errp) =20 s->fd =3D fd; s->host_vnet_hdr_len =3D vnet_hdr ? sizeof(struct virtio_net_hdr) : 0; - s->using_vnet_hdr =3D false; s->has_ufo =3D tap_probe_has_ufo(s->fd); s->has_uso =3D tap_probe_has_uso(s->fd); s->has_tunnel =3D tap_probe_has_tunnel(s->fd); @@ -493,8 +492,6 @@ static bool net_tap_set_fd(TAPState *s, int fd, int vne= t_hdr, Error **errp) if (vnet_hdr) { tap_fd_set_vnet_hdr_len(s->fd, s->host_vnet_hdr_len); } - tap_read_poll(s, true); - s->vhost_net =3D NULL; =20 if (s->sndbuf) { Error **e =3D s->sndbuf_required ? errp : NULL; @@ -795,6 +792,8 @@ static bool net_tap_setup(TAPState *s, int fd, int vnet= _hdr, Error **errp) return false; } =20 + tap_read_poll(s, true); + if (s->vhostfd !=3D -1) { VhostNetOptions options; =20 --=20 2.48.1 From nobody Fri Nov 14 18:23:12 2025 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=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1760118259; cv=none; d=zohomail.com; s=zohoarc; b=n5uotydz+7BzfpoiV0hNh3KchTXb+wFtz5ncMhwSZQaRT2laRPU9yOmQNePCstc/zQxrpZz31AYjUEKCtL038FcBHOjw86M3mbeRkJCSCGV5D2sItuO8kdbZSD+wb6AIuB3bYwrXYURFSLypmwwCKpSvsOM0epntaqZoqrtRANY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760118259; h=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=1aqdMYqp8Yx3D93m6Dm+Tvka8wXxuYClFadXubXeNIY=; b=SNhOQH3kI87rAtIWvB21ePrYwhu1GAZY9I607rLQOx1v6wSAmm6T4rnqrbaTdyzm7BsoJ1ybLfys8nIiMrHwcQZkVmJk+6txVvhBzRqKJWXzqLxHa3SkvpJGmLj7Yi9e83eGjKgIH9BEPk4++qXeCa0mu4W8d5FoRvMSzUXXaY0= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1760118259102898.856841195559; Fri, 10 Oct 2025 10:44:19 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v7H6s-0008Ki-6g; Fri, 10 Oct 2025 13:40:54 -0400 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 1v7H6j-0008Is-Tt for qemu-devel@nongnu.org; Fri, 10 Oct 2025 13:40:47 -0400 Received: from forwardcorp1d.mail.yandex.net ([178.154.239.200]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v7H6K-0007U4-N1 for qemu-devel@nongnu.org; Fri, 10 Oct 2025 13:40:45 -0400 Received: from mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:9297:0:640:61e7:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id 86D9A80788; Fri, 10 Oct 2025 20:40:14 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a89::1:23]) by mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id xdPFQ30FtmI0-1TSMwjXk; Fri, 10 Oct 2025 20:40:14 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1760118014; bh=1aqdMYqp8Yx3D93m6Dm+Tvka8wXxuYClFadXubXeNIY=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=uvyvv/Elp4Xgz+ahERpkn+mL6JkVOqwdH8TMCD3d2GpE92mwJ5xv3+j+0cewVzzKx gFxagQao6/vyPtt59xoIMxM64sYewN92qhN2BzH9otXSmlI7/goL4hbWaQCcZfVEnN IokKEkYlRrHzn8Kfa/gMrFomGlqKwusQi7a3J9TU= Authentication-Results: mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com, jasowang@redhat.com Cc: peterx@redhat.com, farosas@suse.de, sw@weilnetz.de, eblake@redhat.com, armbru@redhat.com, thuth@redhat.com, philmd@linaro.org, berrange@redhat.com, qemu-devel@nongnu.org, michael.roth@amd.com, steven.sistare@oracle.com, leiyang@redhat.com, davydov-max@yandex-team.ru, yc-core@yandex-team.ru, vsementsov@yandex-team.ru, raphael.s.norwitz@gmail.com Subject: [PATCH v7 14/19] migration: introduce .pre_incoming() vmsd handler Date: Fri, 10 Oct 2025 20:39:52 +0300 Message-ID: <20251010173957.166759-15-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251010173957.166759-1-vsementsov@yandex-team.ru> References: <20251010173957.166759-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=178.154.239.200; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1d.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=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 List-Id: 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 @yandex-team.ru) X-ZM-MESSAGEID: 1760118265032158500 Content-Type: text/plain; charset="utf-8" Add possibility for devices to hook into top of migrate-incoming QMP command. It's a place, where migration capabilities and parameters are already set, but migration downtime is not yet started (source is still running). So here devices may do some remaining initializations dependent on migration capabilities. This will be used in further commit to support backend-transfer migration feature for vhost-user-blk. Signed-off-by: Vladimir Sementsov-Ogievskiy Acked-by: Peter Xu Tested-by: Lei Yang --- include/migration/vmstate.h | 1 + migration/migration.c | 4 ++++ migration/savevm.c | 15 +++++++++++++++ migration/savevm.h | 1 + 4 files changed, 21 insertions(+) diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h index 63ccaee07a..f243518fb5 100644 --- a/include/migration/vmstate.h +++ b/include/migration/vmstate.h @@ -217,6 +217,7 @@ struct VMStateDescription { int version_id; int minimum_version_id; MigrationPriority priority; + bool (*pre_incoming)(void *opaque, Error **errp); int (*pre_load)(void *opaque); int (*pre_load_errp)(void *opaque, Error **errp); int (*post_load)(void *opaque, int version_id); diff --git a/migration/migration.c b/migration/migration.c index a63b46bbef..6ed6a10f57 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1983,6 +1983,10 @@ void qmp_migrate_incoming(const char *uri, bool has_= channels, return; } =20 + if (!qemu_pre_incoming(errp)) { + return; + } + if (!yank_register_instance(MIGRATION_YANK_INSTANCE, errp)) { return; } diff --git a/migration/savevm.c b/migration/savevm.c index 7b35ec4dd0..6e240ea100 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -1268,6 +1268,21 @@ bool qemu_savevm_state_blocked(Error **errp) return false; } =20 +bool qemu_pre_incoming(Error **errp) +{ + SaveStateEntry *se; + + QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { + if (se->vmsd && se->vmsd->pre_incoming) { + if (!se->vmsd->pre_incoming(se->opaque, errp)) { + return false; + } + } + } + + return true; +} + void qemu_savevm_non_migratable_list(strList **reasons) { SaveStateEntry *se; diff --git a/migration/savevm.h b/migration/savevm.h index c337e3e3d1..4ad8997f94 100644 --- a/migration/savevm.h +++ b/migration/savevm.h @@ -29,6 +29,7 @@ #define QEMU_VM_COMMAND 0x08 #define QEMU_VM_SECTION_FOOTER 0x7e =20 +bool qemu_pre_incoming(Error **errp); bool qemu_savevm_state_blocked(Error **errp); void qemu_savevm_non_migratable_list(strList **reasons); int qemu_savevm_state_prepare(Error **errp); --=20 2.48.1 From nobody Fri Nov 14 18:23:12 2025 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=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1760118337; cv=none; d=zohomail.com; s=zohoarc; b=NThbvYz2rzl7QMSNkK9gLKCbRlVWLTiPj2BmPf06XbKj3ruAhRbHEHI2DrlI4uhy1gt2CnaQWJH+CzFXpWRPiCEj7fa+17MHNRsIecwX8A4QX4yCYHaSC+QjZMyaaNJP9Ml/w8vA3opF9Iu6jIRo8Q7JuozitEyM/yt4cdNZj40= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760118337; h=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=XTOoRgjZxbvOOe/95H3efUvxXfxwDYqJdenVX8jbsHM=; b=Upl5m5zAc4egitSjvMWBrosYG/2zZgWQ/jv4WaC3pzSg3jcVo4N635IYVVXI9V8GnC+CeADTaYn3e8nOfIm6Eik05vTHMuzwUwOo09vzob3ng0sFElrFgtunXW2eQcwSJDdeJQwaTLohbBHhW8sDLNLgXhnQQ0aUuwgpNJS76gA= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 176011833781079.72573526565498; Fri, 10 Oct 2025 10:45:37 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v7H6t-0008Kx-GK; Fri, 10 Oct 2025 13:40:55 -0400 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 1v7H6o-0008JT-BD for qemu-devel@nongnu.org; Fri, 10 Oct 2025 13:40:52 -0400 Received: from forwardcorp1d.mail.yandex.net ([2a02:6b8:c41:1300:1:45:d181:df01]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v7H6J-0007UW-Nu for qemu-devel@nongnu.org; Fri, 10 Oct 2025 13:40:48 -0400 Received: from mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:9297:0:640:61e7:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id 7EA2E80798; Fri, 10 Oct 2025 20:40:15 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a89::1:23]) by mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id xdPFQ30FtmI0-VFzx9Cwd; Fri, 10 Oct 2025 20:40:14 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1760118014; bh=XTOoRgjZxbvOOe/95H3efUvxXfxwDYqJdenVX8jbsHM=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=NudDSTPZLK/k5ZnZEQOxnU5qOWLo8yHtCmrBaBf1biN1gdRjhd2SQJfm36ObzEUIK x+5nZDRDoUDDUZKfp9CFi1dH9cnyCZa2ECJnBQXwmJovpXbhg+jiecKz3in4S/COim e1IphKKPp74ue3ZsVeI0PXv0JzlR/jveJ0o0W+2A= Authentication-Results: mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com, jasowang@redhat.com Cc: peterx@redhat.com, farosas@suse.de, sw@weilnetz.de, eblake@redhat.com, armbru@redhat.com, thuth@redhat.com, philmd@linaro.org, berrange@redhat.com, qemu-devel@nongnu.org, michael.roth@amd.com, steven.sistare@oracle.com, leiyang@redhat.com, davydov-max@yandex-team.ru, yc-core@yandex-team.ru, vsementsov@yandex-team.ru, raphael.s.norwitz@gmail.com Subject: [PATCH v7 15/19] net/tap: postpone tap setup to pre-incoming Date: Fri, 10 Oct 2025 20:39:53 +0300 Message-ID: <20251010173957.166759-16-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251010173957.166759-1-vsementsov@yandex-team.ru> References: <20251010173957.166759-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=2a02:6b8:c41:1300:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1d.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=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 List-Id: 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 @yandex-team.ru) X-ZM-MESSAGEID: 1760118342191158500 Content-Type: text/plain; charset="utf-8" As described in previous commit, to support backend-transfer migration for virtio-net/tap, we need to postpone the decision to open the device or to wait for incoming fds up to pre-incoming point (when we actually can decide). This commit only postpones TAP-open case of initialization. We don't try to postpone the all cases of initialization, as it will require a lot more work of refactoring the code. So we postpone only the simple case, for which we are going to support fd-incoming migration: 1. No fds / fd parameters: obviously, if user give fd/fds the should be used, no incoming backend-transfer migration is possible. 2. No helper: just for simplicity. It probably possible to allow it (and just ignore in case of backend-transfer migration), to allow user use same cmdline on target QEMU.. But that questionable, and postponable. 3. No sciprt/downscript. It's not simple to support downscript: we should pass the responsiblity to call it on target QEMU with migration.. And back to source QEMU on migration failure. It feasible, but may be implemented later on demand. 3. Concrete ifname: to not try to share it between queues, when we only can setup queues as separate entities. Supporting undecided ifname will require to create some extra netdev state, connecting all the taps, to be able to iterate through them. No part of backend-transfer migration is here, we only prepare the code for future implementation of it. Are net-drivers prepared to postponed initialization of NICs? For future feature of backend-transfer migration, we are mainly interested in virtio-net. So, let's prepare virtio-net to work with postponed initialization of TAP (two places about early set/get features) and for other drivers let's simply finalize initialization on setting netdev property. Support for other drivers may be added later if needed. Signed-off-by: Vladimir Sementsov-Ogievskiy Tested-by: Lei Yang --- hw/net/virtio-net.c | 78 ++++++++++++++++++++++++- include/net/tap.h | 3 + net/tap-win32.c | 11 ++++ net/tap.c | 136 +++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 226 insertions(+), 2 deletions(-) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 33116712eb..661413c72f 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -719,6 +719,30 @@ default_value: return VIRTIO_NET_TX_QUEUE_DEFAULT_SIZE; } =20 +static bool peer_wait_incoming(VirtIONet *n) +{ + NetClientState *nc =3D qemu_get_queue(n->nic); + + if (!nc->peer) { + return false; + } + + if (nc->peer->info->type !=3D NET_CLIENT_DRIVER_TAP) { + return false; + } + + return tap_wait_incoming(nc->peer); +} + +static bool peer_postponed_init(VirtIONet *n, int index, Error **errp) +{ + NetClientState *nc =3D qemu_get_subqueue(n->nic, index); + + assert(nc->peer->info->type =3D=3D NET_CLIENT_DRIVER_TAP); + + return tap_postponed_init(nc->peer, errp); +} + static int peer_attach(VirtIONet *n, int index) { NetClientState *nc =3D qemu_get_subqueue(n->nic, index); @@ -3060,7 +3084,17 @@ static void virtio_net_set_multiqueue(VirtIONet *n, = int multiqueue) n->multiqueue =3D multiqueue; virtio_net_change_num_queues(n, max * 2 + 1); =20 - virtio_net_set_queue_pairs(n); + /* + * virtio_net_set_multiqueue() called from set_features(0) on early + * reset, when peer may wait for incoming (and is not initialized + * yet). + * Don't worry about it: virtio_net_set_queue_pairs() will be called + * later form virtio_net_post_load_device(), and anyway will be + * noop for local incoming migration with live backend passing. + */ + if (!peer_wait_incoming(n)) { + virtio_net_set_queue_pairs(n); + } } =20 static int virtio_net_pre_load_queues(VirtIODevice *vdev, uint32_t n) @@ -3089,6 +3123,17 @@ static void virtio_net_get_features(VirtIODevice *vd= ev, uint64_t *features, =20 virtio_add_feature_ex(features, VIRTIO_NET_F_MAC); =20 + if (peer_wait_incoming(n)) { + /* + * Excessive feature set is OK for early initialization when + * we wait for local incoming migration: actual guest-negotiated + * features will come with migration stream anyway. And we are sure + * that we support same host-features as source, because the backe= nd + * is the same (the same TAP device, for example). + */ + return; + } + if (!peer_has_vnet_hdr(n)) { virtio_clear_feature_ex(features, VIRTIO_NET_F_CSUM); virtio_clear_feature_ex(features, VIRTIO_NET_F_HOST_TSO4); @@ -3180,6 +3225,18 @@ static void virtio_net_get_features(VirtIODevice *vd= ev, uint64_t *features, } } =20 +static bool virtio_net_update_host_features(VirtIONet *n, Error **errp) +{ + ERRP_GUARD(); + VirtIODevice *vdev =3D VIRTIO_DEVICE(n); + + peer_test_vnet_hdr(n); + + virtio_net_get_features(vdev, &vdev->host_features, errp); + + return !*errp; +} + static int virtio_net_post_load_device(void *opaque, int version_id) { VirtIONet *n =3D opaque; @@ -4177,6 +4234,24 @@ static bool dev_unplug_pending(void *opaque) return vdc->primary_unplug_pending(dev); } =20 +static bool vhost_user_blk_pre_incoming(void *opaque, Error **errp) +{ + VirtIONet *n =3D opaque; + int i; + + if (peer_wait_incoming(n)) { + for (i =3D 0; i < n->max_queue_pairs; i++) { + if (!peer_postponed_init(n, i, errp)) { + return false; + } + } + + return virtio_net_update_host_features(n, errp); + } + + return true; +} + static const VMStateDescription vmstate_virtio_net =3D { .name =3D "virtio-net", .minimum_version_id =3D VIRTIO_NET_VM_VERSION, @@ -4185,6 +4260,7 @@ static const VMStateDescription vmstate_virtio_net = =3D { VMSTATE_VIRTIO_DEVICE, VMSTATE_END_OF_LIST() }, + .pre_incoming =3D vhost_user_blk_pre_incoming, .pre_save =3D virtio_net_pre_save, .dev_unplug_pending =3D dev_unplug_pending, }; diff --git a/include/net/tap.h b/include/net/tap.h index 6f34f13eae..5a926ba513 100644 --- a/include/net/tap.h +++ b/include/net/tap.h @@ -33,4 +33,7 @@ int tap_disable(NetClientState *nc); =20 int tap_get_fd(NetClientState *nc); =20 +bool tap_wait_incoming(NetClientState *nc); +bool tap_postponed_init(NetClientState *nc, Error **errp); + #endif /* QEMU_NET_TAP_H */ diff --git a/net/tap-win32.c b/net/tap-win32.c index 38baf90e0b..7430cdf6fa 100644 --- a/net/tap-win32.c +++ b/net/tap-win32.c @@ -766,3 +766,14 @@ int tap_disable(NetClientState *nc) { abort(); } + +bool tap_wait_incoming(NetClientState *nc) +{ + return false; +} + +bool tap_postponed_init(NetClientState *nc, Error **errp) +{ + error_setg(errp, "win32 tap postponed init is not supported"); + return false; +} diff --git a/net/tap.c b/net/tap.c index 7e85444ace..8afbf3b407 100644 --- a/net/tap.c +++ b/net/tap.c @@ -35,7 +35,9 @@ #include "net/eth.h" #include "net/net.h" #include "clients.h" +#include "migration/misc.h" #include "monitor/monitor.h" +#include "system/runstate.h" #include "system/system.h" #include "qapi/error.h" #include "qemu/cutils.h" @@ -88,6 +90,13 @@ typedef struct TAPState { int sndbuf; int vhostfd; uint32_t vhost_busyloop_timeout; + + /* for postponed setup */ + QTAILQ_ENTRY(TAPState) next; + bool vnet_hdr_required; + int vnet_hdr; + bool mq_required; + char *ifname; } TAPState; =20 static bool net_tap_setup(TAPState *s, int fd, int vnet_hdr, Error **errp); @@ -366,6 +375,8 @@ static void tap_cleanup(NetClientState *nc) close(s->vhostfd); s->vhostfd =3D -1; } + + g_free(s->ifname); } =20 static void tap_poll(NetClientState *nc, bool enable) @@ -383,6 +394,25 @@ static bool tap_set_steering_ebpf(NetClientState *nc, = int prog_fd) return tap_fd_set_steering_ebpf(s->fd, prog_fd) =3D=3D 0; } =20 +static bool tap_check_peer_type(NetClientState *nc, ObjectClass *oc, + Error **errp) +{ + TAPState *s =3D DO_UPCAST(TAPState, nc, nc); + const char *driver =3D object_class_get_name(oc); + + if (!g_str_has_prefix(driver, "virtio-net-")) { + /* + * Only virtio-net support postponed TAP initialization, so + * for other drivers let's finalize initialization now. + */ + if (tap_wait_incoming(nc)) { + return tap_postponed_init(&s->nc, errp); + } + } + + return true; +} + int tap_get_fd(NetClientState *nc) { TAPState *s =3D DO_UPCAST(TAPState, nc, nc); @@ -422,6 +452,7 @@ static NetClientInfo net_tap_info =3D { .set_vnet_be =3D tap_set_vnet_be, .set_steering_ebpf =3D tap_set_steering_ebpf, .get_vhost_net =3D tap_get_vhost_net, + .check_peer_type =3D tap_check_peer_type, }; =20 static TAPState *net_tap_new(NetClientState *peer, const char *model, @@ -845,6 +876,93 @@ static int get_fds(char *str, char *fds[], int max) return i; } =20 +#define TAP_OPEN_IFNAME_SZ 128 + +bool tap_postponed_init(NetClientState *nc, Error **errp) +{ + TAPState *s =3D DO_UPCAST(TAPState, nc, nc); + char ifname[TAP_OPEN_IFNAME_SZ]; + int vnet_hdr =3D s->vnet_hdr; + int fd; + + pstrcpy(ifname, sizeof(ifname), s->ifname); + fd =3D net_tap_open(&vnet_hdr, s->vnet_hdr_required, NULL, + ifname, sizeof(ifname), + s->mq_required, errp); + if (fd < 0) { + goto fail; + } + + if (!net_tap_setup(s, fd, vnet_hdr, errp)) { + goto fail; + } + + return true; + +fail: + qemu_del_net_client(&s->nc); + return false; +} + +static bool check_no_script(const char *script_arg) +{ + return script_arg && + (script_arg[0] =3D=3D '\0' || strcmp(script_arg, "no") =3D=3D 0); +} + +static bool tap_postpone_init(const NetdevTapOptions *tap, + const char *name, NetClientState *peer, + bool *postponed, Error **errp) +{ + int queues =3D tap->has_queues ? tap->queues : 1; + + *postponed =3D false; + + if (!runstate_check(RUN_STATE_INMIGRATE)) { + return true; + } + + if (tap->fd || tap->fds || tap->helper || tap->vhostfds) { + return true; + } + + if (!tap->ifname || tap->ifname[0] =3D=3D '\0' || + strstr(tap->ifname, "%d") !=3D NULL) { + /* + * It's hard to postpone logic of parsing template or + * absent ifname + */ + return true; + } + + /* + * Supporting downscipt means understanding and realizing the logic of + * transfer of responsibility to call it in target QEMU process. Or in + * source QEMU process in case of migration failure. So for simplicity= we + * don't support scripts together with fds migration. + */ + if (!check_no_script(tap->script) || !check_no_script(tap->downscript)= ) { + return true; + } + + for (int i =3D 0; i < queues; i++) { + TAPState *s =3D net_tap_new(peer, "tap", name, tap, NULL, errp); + if (!s) { + return false; + } + + s->vnet_hdr_required =3D tap->has_vnet_hdr && tap->vnet_hdr; + s->vnet_hdr =3D tap->has_vnet_hdr ? tap->vnet_hdr : 1; + s->mq_required =3D queues > 1; + s->ifname =3D g_strdup(tap->ifname); + qemu_set_info_str(&s->nc, "ifname=3D%s,script=3Dno,downscript=3Dno= ", + tap->ifname); + } + + *postponed =3D true; + return true; +} + int net_init_tap(const Netdev *netdev, const char *name, NetClientState *peer, Error **errp) { @@ -853,8 +971,9 @@ int net_init_tap(const Netdev *netdev, const char *name, /* for the no-fd, no-helper case */ Error *err =3D NULL; const char *vhostfdname; - char ifname[128]; + char ifname[TAP_OPEN_IFNAME_SZ]; int ret =3D 0; + bool postponed =3D false; =20 assert(netdev->type =3D=3D NET_CLIENT_DRIVER_TAP); tap =3D &netdev->u.tap; @@ -873,6 +992,14 @@ int net_init_tap(const Netdev *netdev, const char *nam= e, return -1; } =20 + if (!tap_postpone_init(tap, name, peer, &postponed, errp)) { + return -1; + } + + if (postponed) { + return 0; + } + if (tap->fd) { if (tap->ifname || tap->script || tap->downscript || tap->has_vnet_hdr || tap->helper || tap->has_queues || @@ -1097,3 +1224,10 @@ int tap_disable(NetClientState *nc) return ret; } } + +bool tap_wait_incoming(NetClientState *nc) +{ + TAPState *s =3D DO_UPCAST(TAPState, nc, nc); + + return s->fd =3D=3D -1; +} --=20 2.48.1 From nobody Fri Nov 14 18:23:12 2025 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=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1760118324; cv=none; d=zohomail.com; s=zohoarc; b=ic+pCSFfWJ0lX6WnvGzzUfb3/OG9Pe0iOpchOT53tkQFb+4nnBw7lMCiiU51ODnHcsvxSwSbSpvmNlN2mHT6gqOCzZEmMdo2bUQKkgJWCO8urgbuDzaAyGoBVD+WpC7v1rLc5o9KxFkrBEsEQCd6TJck2jmNoMfOG3BD7JyaPA4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760118324; h=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=4QZahEI9jXh4SY0arLFmkWwqBvNmEl03FiavUfOzMw4=; b=FZdbVilwD4h8/afcVLo2CMFbcqToAWNDXn/A13HEY4qw6iZ0xx3Uh3aucyhy9TRx0ZNbK4ywihvi7uzdxduq/llCHLIxQUnQs2XRUJ18QAzs6BKAYKji0mATsQ2R88w/U7x/DsRTWXqxIVnPF73Z+zYBFsKKvyWoJoSQtupqf5A= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17601183247491001.3771508623946; Fri, 10 Oct 2025 10:45:24 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v7H6p-0008K7-VU; Fri, 10 Oct 2025 13:40:52 -0400 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 1v7H6k-0008It-8j for qemu-devel@nongnu.org; Fri, 10 Oct 2025 13:40:48 -0400 Received: from forwardcorp1a.mail.yandex.net ([178.154.239.72]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v7H6J-0007Ut-QP for qemu-devel@nongnu.org; Fri, 10 Oct 2025 13:40:43 -0400 Received: from mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:9297:0:640:61e7:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id 6A8F0C0179; Fri, 10 Oct 2025 20:40:16 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a89::1:23]) by mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id xdPFQ30FtmI0-7AA8UpLt; Fri, 10 Oct 2025 20:40:15 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1760118015; bh=4QZahEI9jXh4SY0arLFmkWwqBvNmEl03FiavUfOzMw4=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=P79CGupdtdmTnEvoM7CQzh6iNbipS2j1A1KGRVPfX97PQf/OvuR+Llf7wFLDfaw1L LZkXx171rLL36NuijXBEN7z16HBQaRkkgqNUcixXJLfVzuP5fgLmtlJkRIV5QrhLWb wW5+bNFaxsFwxbwcqmdtViTVMpCVhqashE6p+mJQ= Authentication-Results: mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com, jasowang@redhat.com Cc: peterx@redhat.com, farosas@suse.de, sw@weilnetz.de, eblake@redhat.com, armbru@redhat.com, thuth@redhat.com, philmd@linaro.org, berrange@redhat.com, qemu-devel@nongnu.org, michael.roth@amd.com, steven.sistare@oracle.com, leiyang@redhat.com, davydov-max@yandex-team.ru, yc-core@yandex-team.ru, vsementsov@yandex-team.ru, raphael.s.norwitz@gmail.com Subject: [PATCH v7 16/19] qapi: add interface for backend-transfer virtio-net/tap migration Date: Fri, 10 Oct 2025 20:39:54 +0300 Message-ID: <20251010173957.166759-17-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251010173957.166759-1-vsementsov@yandex-team.ru> References: <20251010173957.166759-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=178.154.239.72; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1a.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=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 List-Id: 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 @yandex-team.ru) X-ZM-MESSAGEID: 1760118326228158500 Content-Type: text/plain; charset="utf-8" To migrate virtio-net TAP device backend (including open fds) locally, user should simply set migration parameter backend-transfer =3D ["virtio-net-tap"] Why not simple boolean? To simplify migration to further versions, when more devices will support backend-transfer migration. Alternatively, we may add per-device option to disable backend-transfer migration, but still: 1. It's more comfortable to set same capabilities/parameters on both source and target QEMU, than care about each device. 2. To not break the design, that machine-type + device options + migration capabilities and parameters are fully define the resulting migration stream. We'll break this if add in future more backend-transfer support in devices under same backend-transfer=3Dtrue parameter. The commit only brings the interface, the realization will come in later commit. That's why we add a temporary not-implemented error in migrate_params_check(). Signed-off-by: Vladimir Sementsov-Ogievskiy Tested-by: Lei Yang --- migration/options.c | 39 +++++++++++++++++++++++++++++++++++++++ migration/options.h | 2 ++ qapi/migration.json | 42 ++++++++++++++++++++++++++++++++++++------ 3 files changed, 77 insertions(+), 6 deletions(-) diff --git a/migration/options.c b/migration/options.c index 5183112775..76709af3ab 100644 --- a/migration/options.c +++ b/migration/options.c @@ -13,6 +13,7 @@ =20 #include "qemu/osdep.h" #include "qemu/error-report.h" +#include "qapi/util.h" #include "exec/target_page.h" #include "qapi/clone-visitor.h" #include "qapi/error.h" @@ -262,6 +263,20 @@ bool migrate_mapped_ram(void) return s->capabilities[MIGRATION_CAPABILITY_MAPPED_RAM]; } =20 +bool migrate_virtio_net_tap(void) +{ + MigrationState *s =3D migrate_get_current(); + BackendTransferList *el =3D s->parameters.backend_transfer; + + for ( ; el; el =3D el->next) { + if (el->value =3D=3D BACKEND_TRANSFER_VIRTIO_NET_TAP) { + return true; + } + } + + return false; +} + bool migrate_ignore_shared(void) { MigrationState *s =3D migrate_get_current(); @@ -963,6 +978,12 @@ MigrationParameters *qmp_query_migrate_parameters(Erro= r **errp) params->cpr_exec_command =3D QAPI_CLONE(strList, s->parameters.cpr_exec_command); =20 + if (s->parameters.backend_transfer) { + params->has_backend_transfer =3D true; + params->backend_transfer =3D QAPI_CLONE(BackendTransferList, + s->parameters.backend_transf= er); + } + return params; } =20 @@ -997,6 +1018,7 @@ void migrate_params_init(MigrationParameters *params) params->has_zero_page_detection =3D true; params->has_direct_io =3D true; params->has_cpr_exec_command =3D true; + params->has_backend_transfer =3D true; } =20 /* @@ -1183,6 +1205,12 @@ bool migrate_params_check(MigrationParameters *param= s, Error **errp) return false; } =20 + /* TODO: implement backend-transfer and remove this check */ + if (params->has_backend_transfer) { + error_setg(errp, "Not implemented"); + return false; + } + return true; } =20 @@ -1305,6 +1333,10 @@ static void migrate_params_test_apply(MigrateSetPara= meters *params, if (params->has_cpr_exec_command) { dest->cpr_exec_command =3D params->cpr_exec_command; } + + if (params->has_backend_transfer) { + dest->backend_transfer =3D params->backend_transfer; + } } =20 static void migrate_params_apply(MigrateSetParameters *params, Error **err= p) @@ -1443,6 +1475,13 @@ static void migrate_params_apply(MigrateSetParameter= s *params, Error **errp) s->parameters.cpr_exec_command =3D QAPI_CLONE(strList, params->cpr_exec_command); } + + if (params->has_backend_transfer) { + qapi_free_BackendTransferList(s->parameters.backend_transfer); + + s->parameters.backend_transfer =3D QAPI_CLONE(BackendTransferList, + params->backend_transf= er); + } } =20 void qmp_migrate_set_parameters(MigrateSetParameters *params, Error **errp) diff --git a/migration/options.h b/migration/options.h index 82d839709e..55c0345433 100644 --- a/migration/options.h +++ b/migration/options.h @@ -87,6 +87,8 @@ const char *migrate_tls_hostname(void); uint64_t migrate_xbzrle_cache_size(void); ZeroPageDetection migrate_zero_page_detection(void); =20 +bool migrate_virtio_net_tap(void); + /* parameters helpers */ =20 bool migrate_params_check(MigrationParameters *params, Error **errp); diff --git a/qapi/migration.json b/qapi/migration.json index be0f3fcc12..1bfe7df191 100644 --- a/qapi/migration.json +++ b/qapi/migration.json @@ -770,6 +770,19 @@ '*transform': 'BitmapMigrationBitmapAliasTransform' } } =20 +## +# @BackendTransfer: +# +# @virtio-net-tap: Enable backend-transfer migration for +# virtio-net/tap. When enabled, TAP fds and all related state are +# passed to the destination in the migration channel (which must +# be a UNIX domain socket). +# +# Since: 10.2 +## +{ 'enum': 'BackendTransfer', + 'data': [ 'virtio-net-tap' ] } + ## # @BitmapMigrationNodeAlias: # @@ -951,9 +964,13 @@ # is @cpr-exec. The first list element is the program's filename, # the remainder its arguments. (Since 10.2) # +# @backend-transfer: List of targets for backend-transfer migration. +# See description in `BackendTransfer`. Default is no +# backend-transfer migration (Since 10.2) +# # Features: # -# @unstable: Members @x-checkpoint-delay and +# @unstable: Members @backend-transfer, @x-checkpoint-delay and # @x-vcpu-dirty-limit-period are experimental. # # Since: 2.4 @@ -978,7 +995,8 @@ 'mode', 'zero-page-detection', 'direct-io', - 'cpr-exec-command'] } + 'cpr-exec-command', + { 'name': 'backend-transfer', 'features': ['unstable'] } ] } =20 ## # @MigrateSetParameters: @@ -1137,9 +1155,13 @@ # is @cpr-exec. The first list element is the program's filename, # the remainder its arguments. (Since 10.2) # +# @backend-transfer: List of targets for backend-transfer migration. +# See description in `BackendTransfer`. Default is no +# backend-transfer migration (Since 10.2) +# # Features: # -# @unstable: Members @x-checkpoint-delay and +# @unstable: Members @backend-transfer, @x-checkpoint-delay and # @x-vcpu-dirty-limit-period are experimental. # # TODO: either fuse back into `MigrationParameters`, or make @@ -1179,7 +1201,9 @@ '*mode': 'MigMode', '*zero-page-detection': 'ZeroPageDetection', '*direct-io': 'bool', - '*cpr-exec-command': [ 'str' ]} } + '*cpr-exec-command': [ 'str' ], + '*backend-transfer': { 'type': [ 'BackendTransfer' ], + 'features': [ 'unstable' ] } } } =20 ## # @migrate-set-parameters: @@ -1352,9 +1376,13 @@ # is @cpr-exec. The first list element is the program's filename, # the remainder its arguments. (Since 10.2) # +# @backend-transfer: List of targets for backend-transfer migration. +# See description in `BackendTransfer`. Default is no +# backend-transfer migration (Since 10.2) +# # Features: # -# @unstable: Members @x-checkpoint-delay and +# @unstable: Members @backend-transfer, @x-checkpoint-delay and # @x-vcpu-dirty-limit-period are experimental. # # Since: 2.4 @@ -1391,7 +1419,9 @@ '*mode': 'MigMode', '*zero-page-detection': 'ZeroPageDetection', '*direct-io': 'bool', - '*cpr-exec-command': [ 'str' ]} } + '*cpr-exec-command': [ 'str' ], + '*backend-transfer': { 'type': [ 'BackendTransfer' ], + 'features': [ 'unstable' ] } } } =20 ## # @query-migrate-parameters: --=20 2.48.1 From nobody Fri Nov 14 18:23:12 2025 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=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1760118346; cv=none; d=zohomail.com; s=zohoarc; b=XyS7aOccSZz3CqhJV9rWcMKuOkDNvidjijJcG3X8uVMOB4lQJRcRE0rjWgAOtjzBdZA+9MAVUUea2C0t1kSflvW8JL3vlqIfoKpf6LaSe7a0hFptZrDYDQXG1p7QcDLpaEq4w80OwTm2r9jnqwZP0MxqAEIBEIBV+IniOiSyM9E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760118346; h=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=61jCkT5i+9uBQRoCzNnQJOXoZpL2mbbhlFGP6ZbMFB8=; b=c2tuCc6y4zdEqGQYnOipzJ67VY6RXVO5PDl0nvaEsif9o3m49rw53A2WdHMHc19yZn8sMLH/1s46rPw9i010q82vICzObk6N65EO2wQ0xjPmXxVZtOzYhN+R+YVxKEAGRuBH8r03cZ6tHzu1i1nynXriE3k+u/Qn09Il1Uxh0FU= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1760118346911500.71793706965616; Fri, 10 Oct 2025 10:45:46 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v7H6v-0008ML-H3; Fri, 10 Oct 2025 13:40:57 -0400 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 1v7H6t-0008LC-8r for qemu-devel@nongnu.org; Fri, 10 Oct 2025 13:40:55 -0400 Received: from forwardcorp1b.mail.yandex.net ([178.154.239.136]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v7H6M-0007VE-1c for qemu-devel@nongnu.org; Fri, 10 Oct 2025 13:40:54 -0400 Received: from mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:9297:0:640:61e7:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTPS id 79C75807F4; Fri, 10 Oct 2025 20:40:17 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a89::1:23]) by mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id xdPFQ30FtmI0-JsuqmfgU; Fri, 10 Oct 2025 20:40:16 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1760118016; bh=61jCkT5i+9uBQRoCzNnQJOXoZpL2mbbhlFGP6ZbMFB8=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=KA/cG8cON0canPRGrwQqqMWMTXBVXe4WwZohOagDFe0Au92/TwpGoWSW37mMb89Nb wKYNL3/A5fun1dtC97QFua/9C7ZOVOwmdbAf9m09vPo2zDum6YH01k86+omdgyIAix qURpXyRO54xz4PpZCmHRNf5vGZMnN+sDmOJ0/mtI= Authentication-Results: mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com, jasowang@redhat.com Cc: peterx@redhat.com, farosas@suse.de, sw@weilnetz.de, eblake@redhat.com, armbru@redhat.com, thuth@redhat.com, philmd@linaro.org, berrange@redhat.com, qemu-devel@nongnu.org, michael.roth@amd.com, steven.sistare@oracle.com, leiyang@redhat.com, davydov-max@yandex-team.ru, yc-core@yandex-team.ru, vsementsov@yandex-team.ru, raphael.s.norwitz@gmail.com Subject: [PATCH v7 17/19] virtio-net: support backend-transfer migration for virtio-net/tap Date: Fri, 10 Oct 2025 20:39:55 +0300 Message-ID: <20251010173957.166759-18-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251010173957.166759-1-vsementsov@yandex-team.ru> References: <20251010173957.166759-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=178.154.239.136; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1b.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, T_SPF_TEMPERROR=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: 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 @yandex-team.ru) X-ZM-MESSAGEID: 1760118350277158500 Content-Type: text/plain; charset="utf-8" Finally implement the new migration option backend-transfer =3D ["virtio-net-tap"]. With this enabled (both on source and target) of-course, and with unix-socket used as migration-channel, we do "migrate" the virtio-net backend - TAP device, with all its fds. This way management tool should not care about creating new TAP, and should not handle switching to it. Migration downtime become shorter. How it works: 1. For incoming migration, we postpone TAP initialization up to pre-incoming point. 2. At pre-incoming point we see that "virtio-net-tap" is set for backend-transfer, so we postpone TAP initialization up to post-load 3. During virtio-load, we get TAP state (and fds) as part of virtio-net state 4. In post-load we finalize TAP initialization Signed-off-by: Vladimir Sementsov-Ogievskiy Tested-by: Lei Yang Reviewed-by: Maksim Davydov --- hw/net/virtio-net.c | 74 ++++++++++++++++++++++++++++++++++++++++++++- include/net/tap.h | 2 ++ migration/options.c | 6 ---- net/tap.c | 45 ++++++++++++++++++++++++++- 4 files changed, 119 insertions(+), 8 deletions(-) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 661413c72f..41c45a4bc7 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -38,6 +38,7 @@ #include "qapi/qapi-events-migration.h" #include "hw/virtio/virtio-access.h" #include "migration/misc.h" +#include "migration/options.h" #include "standard-headers/linux/ethtool.h" #include "system/system.h" #include "system/replay.h" @@ -3358,6 +3359,9 @@ struct VirtIONetMigTmp { uint16_t curr_queue_pairs_1; uint8_t has_ufo; uint32_t has_vnet_hdr; + + NetClientState *ncs; + uint32_t max_queue_pairs; }; =20 /* The 2nd and subsequent tx_waiting flags are loaded later than @@ -3627,6 +3631,71 @@ static const VMStateDescription vhost_user_net_backe= nd_state =3D { } }; =20 +static bool virtio_net_is_tap_mig(void *opaque, int version_id) +{ + VirtIONet *n =3D opaque; + NetClientState *nc; + + nc =3D qemu_get_queue(n->nic); + + return migrate_virtio_net_tap() && nc->peer && + nc->peer->info->type =3D=3D NET_CLIENT_DRIVER_TAP; +} + +static int virtio_net_nic_pre_save(void *opaque) +{ + struct VirtIONetMigTmp *tmp =3D opaque; + + tmp->ncs =3D tmp->parent->nic->ncs; + tmp->max_queue_pairs =3D tmp->parent->max_queue_pairs; + + return 0; +} + +static int virtio_net_nic_pre_load(void *opaque) +{ + /* Reuse the pointer setup from save */ + virtio_net_nic_pre_save(opaque); + + return 0; +} + +static int virtio_net_nic_post_load(void *opaque, int version_id) +{ + struct VirtIONetMigTmp *tmp =3D opaque; + Error *local_err =3D NULL; + + if (!virtio_net_update_host_features(tmp->parent, &local_err)) { + error_report_err(local_err); + return -EINVAL; + } + + return 0; +} + +static const VMStateDescription vmstate_virtio_net_nic_nc =3D { + .name =3D "virtio-net-nic-nc", + .fields =3D (const VMStateField[]) { + VMSTATE_STRUCT_POINTER(peer, NetClientState, vmstate_tap, + NetClientState), + VMSTATE_END_OF_LIST() + }, +}; + +static const VMStateDescription vmstate_virtio_net_nic =3D { + .name =3D "virtio-net-nic", + .pre_load =3D virtio_net_nic_pre_load, + .pre_save =3D virtio_net_nic_pre_save, + .post_load =3D virtio_net_nic_post_load, + .fields =3D (const VMStateField[]) { + VMSTATE_STRUCT_VARRAY_POINTER_UINT32(ncs, struct VirtIONetMigTmp, + max_queue_pairs, + vmstate_virtio_net_nic_nc, + struct NetClientState), + VMSTATE_END_OF_LIST() + }, +}; + static const VMStateDescription vmstate_virtio_net_device =3D { .name =3D "virtio-net-device", .version_id =3D VIRTIO_NET_VM_VERSION, @@ -3658,6 +3727,9 @@ static const VMStateDescription vmstate_virtio_net_de= vice =3D { * but based on the uint. */ VMSTATE_BUFFER_POINTER_UNSAFE(vlans, VirtIONet, 0, MAX_VLAN >> 3), + VMSTATE_WITH_TMP_TEST(VirtIONet, virtio_net_is_tap_mig, + struct VirtIONetMigTmp, + vmstate_virtio_net_nic), VMSTATE_WITH_TMP(VirtIONet, struct VirtIONetMigTmp, vmstate_virtio_net_has_vnet), VMSTATE_UINT8(mac_table.multi_overflow, VirtIONet), @@ -4239,7 +4311,7 @@ static bool vhost_user_blk_pre_incoming(void *opaque,= Error **errp) VirtIONet *n =3D opaque; int i; =20 - if (peer_wait_incoming(n)) { + if (!virtio_net_is_tap_mig(opaque, 0) && peer_wait_incoming(n)) { for (i =3D 0; i < n->max_queue_pairs; i++) { if (!peer_postponed_init(n, i, errp)) { return false; diff --git a/include/net/tap.h b/include/net/tap.h index 5a926ba513..506f7ab719 100644 --- a/include/net/tap.h +++ b/include/net/tap.h @@ -36,4 +36,6 @@ int tap_get_fd(NetClientState *nc); bool tap_wait_incoming(NetClientState *nc); bool tap_postponed_init(NetClientState *nc, Error **errp); =20 +extern const VMStateDescription vmstate_tap; + #endif /* QEMU_NET_TAP_H */ diff --git a/migration/options.c b/migration/options.c index 76709af3ab..7c7df6c484 100644 --- a/migration/options.c +++ b/migration/options.c @@ -1205,12 +1205,6 @@ bool migrate_params_check(MigrationParameters *param= s, Error **errp) return false; } =20 - /* TODO: implement backend-transfer and remove this check */ - if (params->has_backend_transfer) { - error_setg(errp, "Not implemented"); - return false; - } - return true; } =20 diff --git a/net/tap.c b/net/tap.c index 8afbf3b407..b9c12dd64c 100644 --- a/net/tap.c +++ b/net/tap.c @@ -819,7 +819,7 @@ static void net_init_tap_one(const NetdevTapOptions *ta= p, NetClientState *peer, =20 static bool net_tap_setup(TAPState *s, int fd, int vnet_hdr, Error **errp) { - if (!net_tap_set_fd(s, fd, vnet_hdr, errp)) { + if (fd !=3D -1 && !net_tap_set_fd(s, fd, vnet_hdr, errp)) { return false; } =20 @@ -1225,6 +1225,49 @@ int tap_disable(NetClientState *nc) } } =20 +static int tap_pre_load(void *opaque) +{ + TAPState *s =3D opaque; + + if (s->fd !=3D -1) { + error_report( + "TAP is already initialized and cannot receive incoming fd"); + return -EINVAL; + } + + return 0; +} + +static int tap_post_load(void *opaque, int version_id) +{ + TAPState *s =3D opaque; + Error *local_err =3D NULL; + + if (!net_tap_setup(s, -1, -1, &local_err)) { + error_report_err(local_err); + qemu_del_net_client(&s->nc); + return -EINVAL; + } + + return 0; +} + +const VMStateDescription vmstate_tap =3D { + .name =3D "net-tap", + .pre_load =3D tap_pre_load, + .post_load =3D tap_post_load, + .fields =3D (const VMStateField[]) { + VMSTATE_FD(fd, TAPState), + VMSTATE_BOOL(using_vnet_hdr, TAPState), + VMSTATE_BOOL(has_ufo, TAPState), + VMSTATE_BOOL(has_uso, TAPState), + VMSTATE_BOOL(has_tunnel, TAPState), + VMSTATE_BOOL(enabled, TAPState), + VMSTATE_UINT32(host_vnet_hdr_len, TAPState), + VMSTATE_END_OF_LIST() + } +}; + bool tap_wait_incoming(NetClientState *nc) { TAPState *s =3D DO_UPCAST(TAPState, nc, nc); --=20 2.48.1 From nobody Fri Nov 14 18:23:12 2025 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=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1760118121; cv=none; d=zohomail.com; s=zohoarc; b=PZnUAe80ncRaW5VsSb9MppIK5tmAS1dXrKu+BKexK2Irq8OL9pkuHCZit7zmfwNzMYRh1cdHvBg0OoDDBEoHw8cyU0I9eSZbseY1KdyD7IiUxdHW5d23YM/65Vr3sskoHwBIqdt8HJmKtilx5o1ZnZAxrBYu4ASDJWbvOkm3GDk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760118121; 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=vOw5oa65DZ0Z+eI0DURWrqAVxZOetTHC4LKJBWHMDPQ=; b=KBhsRuYHn7+WEQAK3UAKJlN2CX7iWvXe6uIIhDdVaFO5iDxRGl83dNEkJsZGzQv82772p2H4e8oYQpMwSBi/g9tevUUTHQc+lQ2aOgYliKjzATBStWSegKgwNZunhIo/ZTmO5b8EWqF7jXU215ooOFi8ctmLHausJfeOyJAIpIM= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1760118121419374.3379171600975; Fri, 10 Oct 2025 10:42:01 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v7H6u-0008Lv-K1; Fri, 10 Oct 2025 13:40:56 -0400 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 1v7H6t-0008LB-9B for qemu-devel@nongnu.org; Fri, 10 Oct 2025 13:40:55 -0400 Received: from forwardcorp1a.mail.yandex.net ([2a02:6b8:c0e:500:1:45:d181:df01]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v7H6N-0007VY-1h for qemu-devel@nongnu.org; Fri, 10 Oct 2025 13:40:54 -0400 Received: from mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:9297:0:640:61e7:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id 6CB99C0178; Fri, 10 Oct 2025 20:40:18 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a89::1:23]) by mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id xdPFQ30FtmI0-8PJuNnk9; Fri, 10 Oct 2025 20:40:17 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1760118017; bh=vOw5oa65DZ0Z+eI0DURWrqAVxZOetTHC4LKJBWHMDPQ=; h=Cc:Message-ID:References:Date:In-Reply-To:Subject:To:From; b=knHnxEQrqsMUQm7aHguaf7LOG2UHOElG4f9h3GtyTdWDlX0oojFk+5CgG8vXiHZ2e p5I3lw12s60G6I8fUNbMwH36mFWSyuiGkf34HJmYSomZM2Oy8X9F2F8R59fJ2Sda+m ItT0c5eiBou6EZkQDMBgXDNFI3EDXRYqmc48sXZw= Authentication-Results: mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com, jasowang@redhat.com Cc: peterx@redhat.com, farosas@suse.de, sw@weilnetz.de, eblake@redhat.com, armbru@redhat.com, thuth@redhat.com, philmd@linaro.org, berrange@redhat.com, qemu-devel@nongnu.org, michael.roth@amd.com, steven.sistare@oracle.com, leiyang@redhat.com, davydov-max@yandex-team.ru, yc-core@yandex-team.ru, vsementsov@yandex-team.ru, raphael.s.norwitz@gmail.com Subject: [PATCH v7 18/19] tests/functional: add skipWithoutSudo() decorator Date: Fri, 10 Oct 2025 20:39:56 +0300 Message-ID: <20251010173957.166759-19-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251010173957.166759-1-vsementsov@yandex-team.ru> References: <20251010173957.166759-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=2a02:6b8:c0e:500:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1a.mail.yandex.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=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 List-Id: 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 @yandex-team.ru) X-ZM-MESSAGEID: 1760118124831154100 To be used in the next commit: that would be a test for TAP networking, and it will need to setup TAP device. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-by: Thomas Huth Tested-by: Lei Yang Reviewed-by: Maksim Davydov --- tests/functional/qemu_test/decorators.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/functional/qemu_test/decorators.py b/tests/functional/qe= mu_test/decorators.py index b239295804..125d31dda6 100644 --- a/tests/functional/qemu_test/decorators.py +++ b/tests/functional/qemu_test/decorators.py @@ -6,6 +6,7 @@ import os import platform import resource +import subprocess from unittest import skipIf, skipUnless =20 from .cmd import which @@ -167,3 +168,18 @@ def skipLockedMemoryTest(locked_memory): ulimit_memory =3D=3D resource.RLIM_INFINITY or ulimit_memory >=3D = locked_memory * 1024, f'Test required {locked_memory} kB of available locked memory', ) + +''' +Decorator to skip execution of a test if passwordless +sudo command is not available. +''' +def skipWithoutSudo(): + proc =3D subprocess.run(["sudo", "-n", "/bin/true"], + stdin=3Dsubprocess.PIPE, + stdout=3Dsubprocess.PIPE, + stderr=3Dsubprocess.STDOUT, + universal_newlines=3DTrue, + check=3DFalse) + + return skipUnless(proc.returncode =3D=3D 0, + f'requires password-less sudo access: {proc.stdout}') --=20 2.48.1 From nobody Fri Nov 14 18:23:12 2025 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=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1760118141; cv=none; d=zohomail.com; s=zohoarc; b=TxYGdBkM8seAf5V1q3zpn0AInbSVZGmFijvAgFeze+THDYaoyvKZUAhkl99UG2tOjoVKY9fb21Q9Pf9dKQ04UOzbi+4qchb7cYSUVGpajAeaP0dLUgRPyQ+1t18RWMQfyJnExrQ4Wj4hTemjpBSAuplAcsjtE8WcGkkzF/f68ps= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760118141; h=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=rjLn72HLlk8MFzUON5t/+xeThUiGXnGupFyWwRrx7nY=; b=PcL20hwd0t6H2+a1OoKOqIsaM7OHOrQKmpGIBwANf701kgTyVhMvxIGqaKhLPQWnILQ/EIflA4yLm2Q3I8Mq6JY4enzvMJxEQ0+6LMHt6N5Kw37Z2mquGF9yngouPzelXBJ+0Z/p3nq2797EACZkyEfPKkyOGtZjd+x4OFNjh5w= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1760118141255879.6268219850809; Fri, 10 Oct 2025 10:42:21 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v7H75-0008Qi-U7; Fri, 10 Oct 2025 13:41:08 -0400 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 1v7H6x-0008Md-Ss for qemu-devel@nongnu.org; Fri, 10 Oct 2025 13:41:00 -0400 Received: from forwardcorp1a.mail.yandex.net ([2a02:6b8:c0e:500:1:45:d181:df01]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v7H6R-0007W5-Uj for qemu-devel@nongnu.org; Fri, 10 Oct 2025 13:40:59 -0400 Received: from mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:9297:0:640:61e7:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id 8BF6BC017A; Fri, 10 Oct 2025 20:40:19 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a89::1:23]) by mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id xdPFQ30FtmI0-PeMIxPnG; Fri, 10 Oct 2025 20:40:18 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1760118018; bh=rjLn72HLlk8MFzUON5t/+xeThUiGXnGupFyWwRrx7nY=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=Ksp6nnD0u8R6e8l3mfXBqyIwtr8Og+WLdvldqN83PAoWqNKiteJVzZRo4MV1IGPtg vibbviH4g2BfvamqikJNYniaWDAd8rEueCXG9/FXanZglaESQVN4zG6pjlO5/2LvUJ 7bpNgOwUvFugHV5RHDPO4PaHXmZY31HYOQLpfIuY= Authentication-Results: mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com, jasowang@redhat.com Cc: peterx@redhat.com, farosas@suse.de, sw@weilnetz.de, eblake@redhat.com, armbru@redhat.com, thuth@redhat.com, philmd@linaro.org, berrange@redhat.com, qemu-devel@nongnu.org, michael.roth@amd.com, steven.sistare@oracle.com, leiyang@redhat.com, davydov-max@yandex-team.ru, yc-core@yandex-team.ru, vsementsov@yandex-team.ru, raphael.s.norwitz@gmail.com Subject: [PATCH v7 19/19] tests/functional: add test_x86_64_tap_migration Date: Fri, 10 Oct 2025 20:39:57 +0300 Message-ID: <20251010173957.166759-20-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251010173957.166759-1-vsementsov@yandex-team.ru> References: <20251010173957.166759-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=2a02:6b8:c0e:500:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1a.mail.yandex.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=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 List-Id: 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 @yandex-team.ru) X-ZM-MESSAGEID: 1760118144211158500 Content-Type: text/plain; charset="utf-8" Add test for a new backend-transfer migration of virtio-net/tap, with fd passing through unix socket. Signed-off-by: Vladimir Sementsov-Ogievskiy Tested-by: Lei Yang Reviewed-by: Maksim Davydov --- tests/functional/test_x86_64_tap_migration.py | 396 ++++++++++++++++++ 1 file changed, 396 insertions(+) create mode 100644 tests/functional/test_x86_64_tap_migration.py diff --git a/tests/functional/test_x86_64_tap_migration.py b/tests/function= al/test_x86_64_tap_migration.py new file mode 100644 index 0000000000..d7d1ed72bf --- /dev/null +++ b/tests/functional/test_x86_64_tap_migration.py @@ -0,0 +1,396 @@ +#!/usr/bin/env python3 +# +# Functional test that tests TAP local migration +# with fd passing +# +# Copyright (c) Yandex Technologies LLC, 2025 +# +# SPDX-License-Identifier: GPL-2.0-or-later + +import os +import time +import subprocess +from subprocess import run +import signal +from typing import Tuple + +from qemu_test import ( + LinuxKernelTest, + Asset, + exec_command_and_wait_for_pattern, +) +from qemu_test.decorators import skipWithoutSudo + +GUEST_IP =3D "10.0.1.2" +GUEST_IP_MASK =3D f"{GUEST_IP}/24" +GUEST_MAC =3D "d6:0d:75:f8:0f:b7" +HOST_IP =3D "10.0.1.1" +HOST_IP_MASK =3D f"{HOST_IP}/24" +TAP_ID =3D "tap0" +TAP_ID2 =3D "tap1" +TAP_MAC =3D "e6:1d:44:b5:03:5d" + + +def ip(args, check=3DTrue) -> None: + """Run ip command with sudo""" + run(["sudo", "ip"] + args, check=3Dcheck) + + +def del_tap(tap_name: str =3D TAP_ID) -> None: + ip(["tuntap", "del", tap_name, "mode", "tap", "multi_queue"], check=3D= False) + + +def init_tap(tap_name: str =3D TAP_ID, with_ip: bool =3D True) -> None: + ip(["tuntap", "add", "dev", tap_name, "mode", "tap", "multi_queue"]) + if with_ip: + ip(["link", "set", "dev", tap_name, "address", TAP_MAC]) + ip(["addr", "add", HOST_IP_MASK, "dev", tap_name]) + ip(["link", "set", tap_name, "up"]) + + +def switch_network_to_tap2() -> None: + ip(["link", "set", TAP_ID2, "down"]) + ip(["link", "set", TAP_ID, "down"]) + ip(["addr", "delete", HOST_IP_MASK, "dev", TAP_ID]) + ip(["link", "set", "dev", TAP_ID2, "address", TAP_MAC]) + ip(["addr", "add", HOST_IP_MASK, "dev", TAP_ID2]) + ip(["link", "set", TAP_ID2, "up"]) + + +def parse_ping_line(line: str) -> float: + # suspect lines like + # [1748524876.590509] 64 bytes from 94.245.155.3 \ + # (94.245.155.3): icmp_seq=3D1 ttl=3D250 time=3D101 ms + spl =3D line.split() + return float(spl[0][1:-1]) + + +def parse_ping_output(out) -> Tuple[bool, float, float]: + lines =3D [x for x in out.split("\n") if x.startswith("[")] + + try: + first_no_ans =3D next( + (ind for ind in range(len(lines)) if lines[ind][20:26] =3D=3D = "no ans") + ) + except StopIteration: + return False, parse_ping_line(lines[0]), parse_ping_line(lines[-1]) + + last_no_ans =3D next( + ind + for ind in range(len(lines) - 1, -1, -1) + if lines[ind][20:26] =3D=3D "no ans" + ) + + return ( + True, + parse_ping_line(lines[first_no_ans]), + parse_ping_line(lines[last_no_ans]), + ) + + +def wait_migration_finish(source_vm, target_vm): + migr_events =3D ( + ("MIGRATION", {"data": {"status": "completed"}}), + ("MIGRATION", {"data": {"status": "failed"}}), + ) + + source_e =3D source_vm.events_wait(migr_events)["data"] + target_e =3D target_vm.events_wait(migr_events)["data"] + + source_s =3D source_vm.cmd("query-status")["status"] + target_s =3D target_vm.cmd("query-status")["status"] + + assert ( + source_e["status"] =3D=3D "completed" + and target_e["status"] =3D=3D "completed" + and source_s =3D=3D "postmigrate" + and target_s =3D=3D "paused" + ), f"""Migration failed: + SRC status: {source_s} + SRC event: {source_e} + TGT status: {target_s} + TGT event:{target_e}""" + + +@skipWithoutSudo() +class VhostUserBlkFdMigration(LinuxKernelTest): + + ASSET_KERNEL =3D Asset( + ( + "https://archives.fedoraproject.org/pub/archive/fedora/linux/r= eleases" + "/31/Server/x86_64/os/images/pxeboot/vmlinuz" + ), + "d4738d03dbbe083ca610d0821d0a8f1488bebbdccef54ce33e3adb35fda00129", + ) + + ASSET_INITRD =3D Asset( + ( + "https://archives.fedoraproject.org/pub/archive/fedora/linux/r= eleases" + "/31/Server/x86_64/os/images/pxeboot/initrd.img" + ), + "277cd6c7adf77c7e63d73bbb2cded8ef9e2d3a2f100000e92ff1f8396513cd8b", + ) + + ASSET_ALPINE_ISO =3D Asset( + ( + "https://dl-cdn.alpinelinux.org/" + "alpine/v3.22/releases/x86_64/alpine-standard-3.22.1-x86_64.is= o" + ), + "96d1b44ea1b8a5a884f193526d92edb4676054e9fa903ad2f016441a0fe13089", + ) + + def setUp(self): + super().setUp() + + init_tap() + + self.outer_ping_proc =3D None + + def tearDown(self): + try: + del_tap(TAP_ID) + del_tap(TAP_ID2) + + if self.outer_ping_proc: + self.stop_outer_ping() + finally: + super().tearDown() + + def start_outer_ping(self) -> None: + assert self.outer_ping_proc is None + self.outer_ping_log =3D self.scratch_file("ping.log") + with open(self.outer_ping_log, "w") as f: + self.outer_ping_proc =3D subprocess.Popen( + ["ping", "-i", "0", "-O", "-D", GUEST_IP], + text=3DTrue, + stdout=3Df, + ) + + def stop_outer_ping(self) -> str: + assert self.outer_ping_proc + self.outer_ping_proc.send_signal(signal.SIGINT) + + self.outer_ping_proc.communicate(timeout=3D5) + self.outer_ping_proc =3D None + + with open(self.outer_ping_log) as f: + return f.read() + + def stop_ping_and_check(self, stop_time, resume_time): + ping_res =3D self.stop_outer_ping() + + discon, a, b =3D parse_ping_output(ping_res) + + if not discon: + text =3D ( + f"STOP: {stop_time}, RESUME: {resume_time}," f"PING: {a} -= {b}" + ) + if a > stop_time or b < resume_time: + self.fail(f"PING failed: {text}") + self.log.info(f"PING: no packets lost: {text}") + return + + text =3D ( + f"STOP: {stop_time}, RESUME: {resume_time}," + f"PING: disconnect: {a} - {b}" + ) + self.log.info(text) + eps =3D 0.01 + if a < stop_time - eps or b > resume_time + eps: + self.fail(text) + + def one_ping_from_guest(self, vm) -> None: + exec_command_and_wait_for_pattern( + self, + f"ping -c 1 -W 1 {HOST_IP}", + "1 packets transmitted, 1 packets received", + "1 packets transmitted, 0 packets received", + vm=3Dvm, + ) + self.wait_for_console_pattern("# ", vm=3Dvm) + + def one_ping_from_host(self) -> None: + run(["ping", "-c", "1", "-W", "1", GUEST_IP]) + + def setup_shared_memory(self): + shm_path =3D f"/dev/shm/qemu_test_{os.getpid()}" + + try: + with open(shm_path, "wb") as f: + f.write(b"\0" * (1024 * 1024 * 1024)) # 1GB + except Exception as e: + self.fail(f"Failed to create shared memory file: {e}") + + return shm_path + + def prepare_and_launch_vm( + self, shm_path, vhost, incoming=3DFalse, vm=3DNone, backend_transf= er=3DTrue + ): + if not vm: + vm =3D self.vm + + vm.set_console() + vm.add_args("-accel", "kvm") + vm.add_args("-device", "pcie-pci-bridge,id=3Dpci.1,bus=3Dpcie.0") + vm.add_args("-m", "1G") + + vm.add_args( + "-object", + f"memory-backend-file,id=3Dram0,size=3D1G,mem-path=3D{shm_path= },share=3Don", + ) + vm.add_args("-machine", "memory-backend=3Dram0") + + vm.add_args( + "-drive", + f"file=3D{self.ASSET_ALPINE_ISO.fetch()},media=3Dcdrom,format= =3Draw", + ) + + vm.add_args("-S") + + if incoming: + vm.add_args("-incoming", "defer") + + vm_s =3D "target" if incoming else "source" + self.log.info(f"Launching {vm_s} VM") + vm.launch() + + self.set_migration_capabilities(vm, backend_transfer) + + if not backend_transfer: + tap_name =3D TAP_ID2 if incoming else TAP_ID + else: + tap_name =3D TAP_ID + + self.add_virtio_net(vm, vhost, tap_name) + + def add_virtio_net(self, vm, vhost: bool, tap_name: str =3D "tap0"): + netdev_params =3D { + "id": "netdev.1", + "vhost": vhost, + "type": "tap", + "ifname": tap_name, + "script": "no", + "downscript": "no", + "queues": 4, + "vnet_hdr": True, + } + + vm.cmd("netdev_add", netdev_params) + + vm.cmd( + "device_add", + driver=3D"virtio-net-pci", + romfile=3D"", + id=3D"vnet.1", + netdev=3D"netdev.1", + mq=3DTrue, + vectors=3D18, + bus=3D"pci.1", + mac=3DGUEST_MAC, + disable_legacy=3D"off", + ) + + def set_migration_capabilities(self, vm, backend_transfer=3DTrue): + capabilities =3D [ + {"capability": "events", "state": True}, + {"capability": "x-ignore-shared", "state": True}, + ] + vm.cmd("migrate-set-capabilities", {"capabilities": capabilities}) + if backend_transfer: + vm.cmd( + "migrate-set-parameters", + {"backend-transfer": ["virtio-net-tap"]}, + ) + + def setup_guest_network(self) -> None: + exec_command_and_wait_for_pattern(self, "ip addr", "# ") + exec_command_and_wait_for_pattern( + self, + f"ip addr add {GUEST_IP_MASK} dev eth0 && " + "ip link set eth0 up && echo OK", + "OK", + ) + self.wait_for_console_pattern("# ") + + def do_test_tap_fd_migration(self, vhost, backend_transfer=3DTrue): + self.require_accelerator("kvm") + self.set_machine("q35") + + socket_dir =3D self.socket_dir() + migration_socket =3D os.path.join(socket_dir.name, "migration.sock= ") + + shm_path =3D self.setup_shared_memory() + + # Setup second TAP if needed + if not backend_transfer: + del_tap(TAP_ID2) + init_tap(TAP_ID2, with_ip=3DFalse) + + self.prepare_and_launch_vm( + shm_path, vhost, backend_transfer=3Dbackend_transfer + ) + self.vm.cmd("cont") + self.wait_for_console_pattern("login:") + exec_command_and_wait_for_pattern(self, "root", "# ") + + self.setup_guest_network() + + self.one_ping_from_guest(self.vm) + self.one_ping_from_host() + self.start_outer_ping() + + # Get some successful pings before migration + time.sleep(0.5) + + target_vm =3D self.get_vm(name=3D"target") + self.prepare_and_launch_vm( + shm_path, + vhost, + incoming=3DTrue, + vm=3Dtarget_vm, + backend_transfer=3Dbackend_transfer, + ) + + target_vm.cmd("migrate-incoming", {"uri": f"unix:{migration_socket= }"}) + + self.log.info("Starting migration") + freeze_start =3D time.time() + self.vm.cmd("migrate", {"uri": f"unix:{migration_socket}"}) + + self.log.info("Waiting for migration completion") + wait_migration_finish(self.vm, target_vm) + + # Switch network to tap1 if not using backend transfer + if not backend_transfer: + switch_network_to_tap2() + + target_vm.cmd("cont") + freeze_end =3D time.time() + + self.vm.shutdown() + + self.log.info("Verifying PING on target VM after migration") + self.one_ping_from_guest(target_vm) + self.one_ping_from_host() + + # And a bit more pings after source shutdown + time.sleep(0.3) + self.stop_ping_and_check(freeze_start, freeze_end) + + target_vm.shutdown() + + def test_tap_fd_migration(self): + self.do_test_tap_fd_migration(False) + + def test_tap_fd_migration_vhost(self): + self.do_test_tap_fd_migration(True) + + def test_tap_new_tap_migration(self): + self.do_test_tap_fd_migration(False, backend_transfer=3DFalse) + + def test_tap_new_tap_migration_vhost(self): + self.do_test_tap_fd_migration(True, backend_transfer=3DFalse) + + +if __name__ =3D=3D "__main__": + LinuxKernelTest.main() --=20 2.48.1