From nobody Sun Sep 28 15:28:19 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=1758621751; cv=none; d=zohomail.com; s=zohoarc; b=B/403dboFEtyYFgCizIkaQCr349ATFVPEC2ustOiWxkuseUVPD53DjuvT49RxGsWaWTnyomhALO2q0BnZHRC9/lVceR/nnqSH43gXEO4+IwVFFjSBlHN1ZulbVLsGQmNJV4kRchBhyQ0Qw//ABm7q7itY6qy7s/8H1s3LCUcNzU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758621751; 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=pjhq8KPtOGGqEkvrAWzGY7iHd/8HnxAvui6FG4dF3zw=; b=mX+jvDxh5qCi6dktgyfieNmYPvBnzIDl9rPXbuQFLx7DZBu7ZJUWH6m3EYtFe9qN3m/d403BBXHQb6pzh69nSbmpOyxozO3lvN2j2/UnTHmyBqKEG+y4mFJFIjze+EumG2fAVHNJyo2JBJ6EWLHy+ayQRQzUPxd1BCZnVpy5yLg= 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 1758621751151183.99875010126914; Tue, 23 Sep 2025 03:02:31 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v0zpw-0002hf-KQ; Tue, 23 Sep 2025 06:01: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 1v0zpr-0002ei-9M for qemu-devel@nongnu.org; Tue, 23 Sep 2025 06:01: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 1v0zpm-0000sv-Bu for qemu-devel@nongnu.org; Tue, 23 Sep 2025 06:01:22 -0400 Received: from mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:cf2d:0:640:140f:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id E31E180660; Tue, 23 Sep 2025 13:01:13 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:b38::1:12]) by mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id C1Ug0C0Fha60-93ModPmG; Tue, 23 Sep 2025 13:01: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=1758621673; bh=pjhq8KPtOGGqEkvrAWzGY7iHd/8HnxAvui6FG4dF3zw=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=iPP7M0XmOL8Rze+U9aoF8hnlJMvD60egw/xPS69MG6VUBD//pkQ59sgOLgUqH1FdP TrqxKq00RIjT5kw/+jKRHhqNm38LKfmVw4Wp4+hlKfDtn8UCKbz7csxPL5vntzWLRe 4eaQORZFX2xW0Pe912IKVhwaAfvzMqnC01SQN2iY= Authentication-Results: mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com Cc: qemu-devel@nongnu.org, philmd@linaro.org, thuth@redhat.com, eblake@redhat.com, michael.roth@amd.com, armbru@redhat.com, farosas@suse.de, peterx@redhat.com, berrange@redhat.com, jasowang@redhat.com, steven.sistare@oracle.com, leiyang@redhat.com, davydov-max@yandex-team.ru, yc-core@yandex-team.ru, vsementsov@yandex-team.ru Subject: [PATCH v6 01/19] net/tap: net_init_tap_one(): drop extra error propagation Date: Tue, 23 Sep 2025 13:00:52 +0300 Message-ID: <20250923100110.70862-2-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250923100110.70862-1-vsementsov@yandex-team.ru> References: <20250923100110.70862-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: 1758621753406116600 Content-Type: text/plain; charset="utf-8" Signed-off-by: Vladimir Sementsov-Ogievskiy Tested-by: Lei Yang --- net/tap.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/net/tap.c b/net/tap.c index f37133e301..5d91658660 100644 --- a/net/tap.c +++ b/net/tap.c @@ -723,9 +723,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 Sun Sep 28 15:28:19 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=1758621748; cv=none; d=zohomail.com; s=zohoarc; b=hJ2FM/7mm/pWlk3qDXyHkHmGS+Z8NTthfsUU7SD9/IOA7bXrje2U0YCLOzqBayWTU5prwJYNbRK/qb5dVyZZOI5SiE5G23fKZaGjm9qTKw1cLSd2ksl+yN6Hy/L0eGas+grHS8aIsVjsHiTz+dg3LuuCVmfh3UsgYV0BStvmRhQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758621748; 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=D9KUQlEm83ILSSQcgAwNZwMaNqzcNARWM6z4fHVrtmo=; b=aQDduMuEUOAFFaIc3aEoNlXVXMu2H4l1JSWHgLrn/kdVrMNOtWyHyU0E+QD995VdafbqguuJHBeN5Jdf7TxSajJewPJejYUBmT53hWGQ4ceY6DWG1OzS7i7YNutwl4cfzMHYh9lyyPT8+wS+oG/ZB7rnsjd1Rbj+F5/C5n7Yep8= 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 1758621748001782.2070463621878; Tue, 23 Sep 2025 03:02:28 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v0zqR-0002vm-Kv; Tue, 23 Sep 2025 06:01:59 -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 1v0zq2-0002ko-Ul for qemu-devel@nongnu.org; Tue, 23 Sep 2025 06:01:35 -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 1v0zpo-0000sz-Fd for qemu-devel@nongnu.org; Tue, 23 Sep 2025 06:01:33 -0400 Received: from mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:cf2d:0:640:140f:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id 72A6480798; Tue, 23 Sep 2025 13:01:14 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:b38::1:12]) by mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id C1Ug0C0Fha60-trIRYCAT; Tue, 23 Sep 2025 13:01: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=1758621674; bh=D9KUQlEm83ILSSQcgAwNZwMaNqzcNARWM6z4fHVrtmo=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=RyVsLUPZs0D6Yr0S3yu/HSh9O6+OUTwfncLfM+ZLP4wX8bfz+vwN08k+mcUKsVLmH axS7KWkoT/EVg5LUsgrEGIBkDRGADL9XMwfk8+3NjWa3KCFfVSgt+qfLsSO09gaMpi rF+05OSjTuFnTGgu7dF4d0yiqP3lZLHEGs0LulV8= Authentication-Results: mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com Cc: qemu-devel@nongnu.org, philmd@linaro.org, thuth@redhat.com, eblake@redhat.com, michael.roth@amd.com, armbru@redhat.com, farosas@suse.de, peterx@redhat.com, berrange@redhat.com, jasowang@redhat.com, steven.sistare@oracle.com, leiyang@redhat.com, davydov-max@yandex-team.ru, yc-core@yandex-team.ru, vsementsov@yandex-team.ru Subject: [PATCH v6 02/19] net/tap: net_init_tap_one(): move parameter checking earlier Date: Tue, 23 Sep 2025 13:00:53 +0300 Message-ID: <20250923100110.70862-3-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250923100110.70862-1-vsementsov@yandex-team.ru> References: <20250923100110.70862-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: 1758621749442116600 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 --- net/tap.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/net/tap.c b/net/tap.c index 5d91658660..8cccf71002 100644 --- a/net/tap.c +++ b/net/tap.c @@ -755,9 +755,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; @@ -819,6 +816,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 Sun Sep 28 15:28:19 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=1758621740; cv=none; d=zohomail.com; s=zohoarc; b=R5LtKasdAXkJuMhN5UbOgp/qjMgRlFUi+Pj/4Iqn2rAkeVlvYKls8MSw7JY0J4q8w2ysOu2YOtVsoSTezZFYQ3HZTuyKtlSJ73EwdZqoe8N32uXEO0UPWV7xIC9vOkXAjaO8E9GDs5ksd9Cnijal48xeyLJRR528G6Dp/QyAVhI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758621740; 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=CnCoHJI0uSDrGW/+kFfB3e6+Pm6z3E+MyzUB2efNPGo=; b=MBI54IWJVRH9t63wyJ9KDUei9G0ZPYiIkXJ4b1D34tlekqvBU1tCoLskvaC+ZBEzZ5uFwpd3pmFeIoBQQaPKAPBUhYNegm3Wcgeiu1okKzyDIPWX7RsNuY0ExpNozBa/IiFSgajEYtU8Ewaqc5qmew/rkQa/5qK855d9RYwGJes= 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 1758621740145721.0925396400179; Tue, 23 Sep 2025 03:02:20 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v0zqE-0002r5-IM; Tue, 23 Sep 2025 06:01:48 -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 1v0zq1-0002iw-72 for qemu-devel@nongnu.org; Tue, 23 Sep 2025 06:01:33 -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 1v0zpm-0000t9-QV for qemu-devel@nongnu.org; Tue, 23 Sep 2025 06:01:31 -0400 Received: from mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:cf2d:0:640:140f:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id 022AB80780; Tue, 23 Sep 2025 13:01:15 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:b38::1:12]) by mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id C1Ug0C0Fha60-yMtpbpwj; Tue, 23 Sep 2025 13:01: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=1758621674; bh=CnCoHJI0uSDrGW/+kFfB3e6+Pm6z3E+MyzUB2efNPGo=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=u8JopEdLc8fSzpuXAJDsZm++UkMYhx/IicTLL3r8/PXQRHTKe+58iVAaez0ZuzSZQ mEMylAOpk4HKwMTTCQMx8oAA4NhDWr981ynXVkWDCz2jRvWSUvMsUiJq4Kpb/H71LM 0HfHSHCBlcaOIZZFIGq3QL5SbTtHQLe3b9gdNCzc= Authentication-Results: mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com Cc: qemu-devel@nongnu.org, philmd@linaro.org, thuth@redhat.com, eblake@redhat.com, michael.roth@amd.com, armbru@redhat.com, farosas@suse.de, peterx@redhat.com, berrange@redhat.com, jasowang@redhat.com, steven.sistare@oracle.com, leiyang@redhat.com, davydov-max@yandex-team.ru, yc-core@yandex-team.ru, vsementsov@yandex-team.ru Subject: [PATCH v6 03/19] net/tap: rework net_tap_init() Date: Tue, 23 Sep 2025 13:00:54 +0300 Message-ID: <20250923100110.70862-4-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250923100110.70862-1-vsementsov@yandex-team.ru> References: <20250923100110.70862-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, 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: 1758621743117116600 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 --- net/tap.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/net/tap.c b/net/tap.c index 8cccf71002..506dc9d226 100644 --- a/net/tap.c +++ b/net/tap.c @@ -642,20 +642,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)); @@ -964,6 +956,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; @@ -984,7 +978,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 Sun Sep 28 15:28:19 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=1758621826; cv=none; d=zohomail.com; s=zohoarc; b=aq8uBx/R4nUOgz0CwdA1H9mzH7MFhfVnnmcSkXXtDw2i52hNdGw8oMIPXO/DIQPJeEtXRSK3kQWG6osE4lnlYsxSgng6gMh7OUdx/E1zw2hw3ApSEK+f+/ac/vIR4KjmSbbMJDvdy8fPm5pbpk8AvZGlVjEalTyefENU7A3xO9A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758621826; 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=FeDOTAGsW1Pcdbg0ZZNDxeOSWxQ+N3Fw7mdS9vL/kGY=; b=kMuqve/j42eTfgfll9fnRR4BE9idbz34jBMmSEdY4toViiktWiKaRLQ4Q/p9ZFBq9OzYLVBCZYHC4XfzWvWMw5nNaqwgCGNguWWkzjNG8OzzfipivtSwgW3vug3tJ2XOdI3Jb+I1DRQLQtphnJ/ca+rXCEpSp5SdTFG6aqjWDsA= 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 1758621826292284.5925280071084; Tue, 23 Sep 2025 03:03:46 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v0zq3-0002jd-7S; Tue, 23 Sep 2025 06:01: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 1v0zpt-0002fc-4m for qemu-devel@nongnu.org; Tue, 23 Sep 2025 06:01:25 -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 1v0zpm-0000t3-Qv for qemu-devel@nongnu.org; Tue, 23 Sep 2025 06:01:24 -0400 Received: from mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:cf2d:0:640:140f:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id 7ECD5807C9; Tue, 23 Sep 2025 13:01:15 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:b38::1:12]) by mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id C1Ug0C0Fha60-W2RIwL7U; Tue, 23 Sep 2025 13:01: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=1758621675; bh=FeDOTAGsW1Pcdbg0ZZNDxeOSWxQ+N3Fw7mdS9vL/kGY=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=n6SEW6xwVgpop0j6Oqndhu1ZvkPR3OCldJ7z+GyEpKhB1OJxZ9UiVAJKBosB05uvX iNQ2APQzFWLi67kHW0FDNUTbL1pxRzMqiD9LAyakgVjd1NT47oARzWtZn1BXqgi1kp nKLA0TeWBWxLOrUgi90JGO95Yftt0V8XsvkRdkcU= Authentication-Results: mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com Cc: qemu-devel@nongnu.org, philmd@linaro.org, thuth@redhat.com, eblake@redhat.com, michael.roth@amd.com, armbru@redhat.com, farosas@suse.de, peterx@redhat.com, berrange@redhat.com, jasowang@redhat.com, steven.sistare@oracle.com, leiyang@redhat.com, davydov-max@yandex-team.ru, yc-core@yandex-team.ru, vsementsov@yandex-team.ru Subject: [PATCH v6 04/19] net/tap: pass NULL to net_init_tap_one() in cases when scripts are NULL Date: Tue, 23 Sep 2025 13:00:55 +0300 Message-ID: <20250923100110.70862-5-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250923100110.70862-1-vsementsov@yandex-team.ru> References: <20250923100110.70862-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: 1758621828132116600 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 --- net/tap.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/net/tap.c b/net/tap.c index 506dc9d226..e42c7ca044 100644 --- a/net/tap.c +++ b/net/tap.c @@ -787,8 +787,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]; @@ -798,8 +796,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. */ @@ -840,7 +836,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); @@ -901,7 +897,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) { @@ -946,7 +942,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); @@ -954,6 +950,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 Sun Sep 28 15:28:19 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=1758621961; cv=none; d=zohomail.com; s=zohoarc; b=bZ5n3uedal34rZiMOZV3EpcZsal0wdU+QOPScg98ep47uWlwipJqgoiw1pniF85aQTcpPEui/lSQ/tf5Bk8kdvuNHOYx3NjlNIflRqIJlSiXKLJM/+gy8iFF0h7bs18IuhYi4AGTNdz3XyP0RR97nsjJ7cyc3pmeO+vN1RWsFhE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758621961; 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=J+j4+PwNItZRsNYaJicaECJgV/GseY0I8xoBomuNEiM=; b=hT81gvn9XLHd4iMwBpE0KWR6ZVLfVB2WAeql9oON2dHgHAqXp7dlO63wZME1cmavDVioCZJwLaPsvXvFq+35/wo0o+BuKMRmBFGTv3h8XDVzGA1ejzi5uogWE9q/Wnu54IF/uUWC5RuOidjdCWlW0HRp/OTjwGgZ5Ms4CrdtvDY= 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 1758621961571487.5293595288996; Tue, 23 Sep 2025 03:06:01 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v0zq3-0002ll-Oo; Tue, 23 Sep 2025 06:01:36 -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 1v0zpx-0002hc-15 for qemu-devel@nongnu.org; Tue, 23 Sep 2025 06:01:29 -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 1v0zpo-0000tA-3m for qemu-devel@nongnu.org; Tue, 23 Sep 2025 06:01:27 -0400 Received: from mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:cf2d:0:640:140f:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id 0BD71804E6; Tue, 23 Sep 2025 13:01:16 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:b38::1:12]) by mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id C1Ug0C0Fha60-BoofPur5; Tue, 23 Sep 2025 13:01: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=1758621675; bh=J+j4+PwNItZRsNYaJicaECJgV/GseY0I8xoBomuNEiM=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=K36wfHG0809HVU1qMdDxfNFTMjt+pPwMtpelArzq2hmsaT+xxwXczHlyhVd7qwhgY RSqCtpFcwJqllCDvaDwb0hPOvlvZLPfgKre/bz6bbr0qgfUbgh7j91rW2uCcp17FO8 PT4V2HEIEM2hcloDIIkFaMmVb9X7LEsx/WENJHIM= Authentication-Results: mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com Cc: qemu-devel@nongnu.org, philmd@linaro.org, thuth@redhat.com, eblake@redhat.com, michael.roth@amd.com, armbru@redhat.com, farosas@suse.de, peterx@redhat.com, berrange@redhat.com, jasowang@redhat.com, steven.sistare@oracle.com, leiyang@redhat.com, davydov-max@yandex-team.ru, yc-core@yandex-team.ru, vsementsov@yandex-team.ru Subject: [PATCH v6 05/19] net/tap: rework scripts handling Date: Tue, 23 Sep 2025 13:00:56 +0300 Message-ID: <20250923100110.70862-6-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250923100110.70862-1-vsementsov@yandex-team.ru> References: <20250923100110.70862-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: 1758621963258116600 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 --- net/tap.c | 45 +++++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/net/tap.c b/net/tap.c index e42c7ca044..084ee4f649 100644 --- a/net/tap.c +++ b/net/tap.c @@ -88,6 +88,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, @@ -655,9 +670,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); @@ -693,9 +706,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); @@ -950,10 +963,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->script, DEFAULT_NETWORK_DOWN_SCRIPT); bool vnet_hdr_required =3D tap->has_vnet_hdr && tap->vnet_hdr; =20 if (tap->vhostfds) { @@ -961,14 +974,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 { @@ -978,7 +983,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; @@ -993,8 +998,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 Sun Sep 28 15:28:19 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=1758621810; cv=none; d=zohomail.com; s=zohoarc; b=Vuv3egsuP61OTYBL+HqEOkhALZ5gb/XXxi9UY8VCBHII3bIAMLbdo0+h8gY0OYDq6jqo1t0iZRfyspxf6A3HaccHWVuQrQa1HgABKu6Yfv5eA7bSu0znbRopSsT3hZ1g9N1bVuoyanqLgIEzUd9dFtXd3dalQSbioj3cvu9PEuw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758621810; 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=PdbklUwN979KsN+YcWTis3pNjUVgPWr3+SFbkDah9oU=; b=JZxqZJCT5ZYybkAGtvHWmEBStySo40PejECz1mC5XQPiy1E9oEF9DvXisUE7H2bwP9RNuoGtiBasmD9no2Zk4UxKgBrkkIrsH/Sk215UP0h9zkFJMl0NDBlZ8AdU7EFl9FFJl6R34VTAn8ceY6yT6FdhBx+Lg9Cy5lF6TkM3pgY= 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 1758621810391878.745720365289; Tue, 23 Sep 2025 03:03:30 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v0zq1-0002kO-KE; Tue, 23 Sep 2025 06:01:33 -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 1v0zpw-0002hb-W6 for qemu-devel@nongnu.org; Tue, 23 Sep 2025 06:01:29 -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 1v0zpm-0000tL-G6 for qemu-devel@nongnu.org; Tue, 23 Sep 2025 06:01:27 -0400 Received: from mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:cf2d:0:640:140f:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id 896FF807C8; Tue, 23 Sep 2025 13:01:16 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:b38::1:12]) by mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id C1Ug0C0Fha60-Eazd6Bk7; Tue, 23 Sep 2025 13:01: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=1758621676; bh=PdbklUwN979KsN+YcWTis3pNjUVgPWr3+SFbkDah9oU=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=DdSQNlbj4kXLfmA0ZGurehRZ7IIwTMqREc6JLgO47/FvzK/gKJFiPz1uIglJN4MYo ScrT9IX3UjBzZY78UBBtypifaHSrwU6P1NMnwPIamtP04prhzZqLSKMCMli4pViuN3 u/V42Vvvesff4GV61GW7Ldr6///A2ahjOTYyl2w0= Authentication-Results: mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com Cc: qemu-devel@nongnu.org, philmd@linaro.org, thuth@redhat.com, eblake@redhat.com, michael.roth@amd.com, armbru@redhat.com, farosas@suse.de, peterx@redhat.com, berrange@redhat.com, jasowang@redhat.com, steven.sistare@oracle.com, leiyang@redhat.com, davydov-max@yandex-team.ru, yc-core@yandex-team.ru, vsementsov@yandex-team.ru Subject: [PATCH v6 06/19] net/tap: setup exit notifier only when needed Date: Tue, 23 Sep 2025 13:00:57 +0300 Message-ID: <20250923100110.70862-7-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250923100110.70862-1-vsementsov@yandex-team.ru> References: <20250923100110.70862-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: 1758621811970116600 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 --- net/tap.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/net/tap.c b/net/tap.c index 084ee4f649..a7ae7ab04a 100644 --- a/net/tap.c +++ b/net/tap.c @@ -316,11 +316,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 @@ -336,8 +334,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); @@ -430,9 +431,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 @@ -712,6 +710,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 Sun Sep 28 15:28:19 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=1758621777; cv=none; d=zohomail.com; s=zohoarc; b=Ndi5FP09/Jz9/N7vQH4CLtBgEmH6ZucCOMk5uMNBWMS1Y/aidg64R9ytpvrb/8Vxgh+DD/8mKKsZoRdpQg7IeaBnsnvfpt08nNja+1RQ7QqKTFu9A4X2u7dni6OLAdl/F6GRxQd4/CeJ/JwkbIg9iZzJRrxbAC8Pv5DllT/nprU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758621777; 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=rwWQWDuCrtCAcBZ8GOgOqYHWMhtyjQ7SF8SVhKkg8x8=; b=Dwo3gtmZdvN0ZVf2oCzCvQ0/lb8IVDr7DbiRq9HrShoNSahX7tbzD7MVtIPTlr0WXp0l5GuDO86+Vw9drQ3u0Q5U61vyAD3Ea8MoLTyyx9neNIBSNSesCmw+2OK9mxA18tRp4Y8r6agnTNcZTfFi2ocd5h6elXyIz7v+ooZ2h/g= 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 1758621777403774.8236342716858; Tue, 23 Sep 2025 03:02:57 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v0zq1-0002jv-BX; Tue, 23 Sep 2025 06:01:33 -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 1v0zpt-0002fd-4m for qemu-devel@nongnu.org; Tue, 23 Sep 2025 06:01:25 -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 1v0zpm-0000tU-Ne for qemu-devel@nongnu.org; Tue, 23 Sep 2025 06:01:24 -0400 Received: from mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:cf2d:0:640:140f:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id 1738980923; Tue, 23 Sep 2025 13:01:17 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:b38::1:12]) by mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id C1Ug0C0Fha60-DIKd8hcP; Tue, 23 Sep 2025 13:01: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=1758621676; bh=rwWQWDuCrtCAcBZ8GOgOqYHWMhtyjQ7SF8SVhKkg8x8=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=T6Y2UVGBjO8EuNTmajVAxze8TK94KNmoJ2utwdXl7t0MeGse3GUJJqn+nRURsulpI 3d+21RuOhhm0MbBpYeXAxyTuyuMrXu5fSm08hK+4rx5qmLBe8ega+TFlq4pmGAS20z R5R+mOKXWWPOpDd1fuAT2m9chw4O5wRrytIvpxmw= Authentication-Results: mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com Cc: qemu-devel@nongnu.org, philmd@linaro.org, thuth@redhat.com, eblake@redhat.com, michael.roth@amd.com, armbru@redhat.com, farosas@suse.de, peterx@redhat.com, berrange@redhat.com, jasowang@redhat.com, steven.sistare@oracle.com, leiyang@redhat.com, davydov-max@yandex-team.ru, yc-core@yandex-team.ru, vsementsov@yandex-team.ru Subject: [PATCH v6 07/19] net/tap: split net_tap_fd_init() Date: Tue, 23 Sep 2025 13:00:58 +0300 Message-ID: <20250923100110.70862-8-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250923100110.70862-1-vsementsov@yandex-team.ru> References: <20250923100110.70862-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: 1758621779645116600 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 --- net/tap.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/net/tap.c b/net/tap.c index a7ae7ab04a..048d130247 100644 --- a/net/tap.c +++ b/net/tap.c @@ -401,19 +401,19 @@ 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) { - 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; +} =20 +static void net_tap_set_fd(TAPState *s, int fd, int vnet_hdr) +{ s->fd =3D fd; s->host_vnet_hdr_len =3D vnet_hdr ? sizeof(struct virtio_net_hdr) : 0; s->using_vnet_hdr =3D false; @@ -430,8 +430,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) @@ -648,7 +646,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 @@ -689,9 +689,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 Sun Sep 28 15:28:19 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=1758621757; cv=none; d=zohomail.com; s=zohoarc; b=ZLh7432o7hNWnupqmIXWbTsh3hNQe14G0N+DtVRBCdjsmwJ8gHoDlWnKt8D79cg1NUS4bvuubymVWPpnaofOntWi4tU7q/MFRLL4+hI8rdzfvynWjMgQ604r5HYgpRHhnUqnfRhRqbtt3+0A1KROUQG8bSM85GbEr0ngrzesBBQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758621757; 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=jwgfCyxnkeS08WSpdIGIVrRghpy+hEGHPwdSeT5sp+k=; b=bKlusrkcLsoStKj4QfW4wjQF+tt3v1DDw+arLwBPOMIDqVo3TUizCcn6T3x0R+6QE1eBCpzoggU86MHTLFxo4d/YYvNYuLBUmuVKsspVzRtj2O8KjARgHWoarDoqF6PbNX18WBWX1/+8hNxohmo97gZJjKpth88ijxKBmQ56DT0= 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 175862175758838.40778374534352; Tue, 23 Sep 2025 03:02:37 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v0zqb-00036g-L1; Tue, 23 Sep 2025 06:02:09 -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 1v0zq3-0002ln-Lc for qemu-devel@nongnu.org; Tue, 23 Sep 2025 06:01:35 -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 1v0zpo-0000ta-FM for qemu-devel@nongnu.org; Tue, 23 Sep 2025 06:01:35 -0400 Received: from mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:cf2d:0:640:140f:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id 982448092A; Tue, 23 Sep 2025 13:01:17 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:b38::1:12]) by mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id C1Ug0C0Fha60-zOD1wE8b; Tue, 23 Sep 2025 13:01: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=1758621677; bh=jwgfCyxnkeS08WSpdIGIVrRghpy+hEGHPwdSeT5sp+k=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=uk0Clw0FF3xirjmVsJlwHgaJ7q6wSDJDMTDs3ZqzlwT5wzfxqgZcc4sV82lKvMcRB FgIFUto1kxFnzJBQ3248OMYZ87x49ubqgCCmTu+qHAQret5evxGO3Jj+xo4tXdxo22 KJgdg7fEoFHz0odHTjNFbKdPSCAi+/uXPPfsgQgw= Authentication-Results: mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com Cc: qemu-devel@nongnu.org, philmd@linaro.org, thuth@redhat.com, eblake@redhat.com, michael.roth@amd.com, armbru@redhat.com, farosas@suse.de, peterx@redhat.com, berrange@redhat.com, jasowang@redhat.com, steven.sistare@oracle.com, leiyang@redhat.com, davydov-max@yandex-team.ru, yc-core@yandex-team.ru, vsementsov@yandex-team.ru Subject: [PATCH v6 08/19] net/tap: tap_set_sndbuf(): add return value Date: Tue, 23 Sep 2025 13:00:59 +0300 Message-ID: <20250923100110.70862-9-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250923100110.70862-1-vsementsov@yandex-team.ru> References: <20250923100110.70862-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: 1758621759459116600 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 --- 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 3f98d0ea82..501bf9d3eb 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 e832810665..8cb9dc0787 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 af2ebb16f5..496c1323fc 100644 --- a/net/tap-solaris.c +++ b/net/tap-solaris.c @@ -207,8 +207,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 38673434cb..8e328c679f 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 048d130247..95cbd75fe4 100644 --- a/net/tap.c +++ b/net/tap.c @@ -688,15 +688,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 8857ff299d..08c40094b8 100644 --- a/net/tap_int.h +++ b/net/tap_int.h @@ -33,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 -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 Sun Sep 28 15:28:19 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=1758621965; cv=none; d=zohomail.com; s=zohoarc; b=Rsx1vPJFr9v1f5izkdYxfQfFyKcVivJPECAOdjmD6GbeMicf01au1N6ZVNvV6wrJ8ogAYm7M8NmzDVGbOfyqes7epxYxM1U/jAk5V0T5BJSLS1z8D+A1qvfHEj1qzWM7yWZ/j5H0enhUYCQWQ17K8jqgaCSAfEfk24tv1v64ZFk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758621965; 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=0rkp9X76WiOzr/q2WYArxjfrFUzR5vC9iuDCQ/fVu7w=; b=QZknngfCkk/F51n9oRAFjYL+0bfKlpvk8VJLsK8vkP5POSKszItqRXqZ/2jdqMANTvzBJNpKRQ40g6hSRHvyK8c6unDGww5xXLuJgjlQo9WC9yGtsSu4AXLHYVdrKjjnRZP00MylQWKIByqz+XaZkQqy9U6hk/AZBDU5TftU2dI= 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 1758621965467569.1530219480695; Tue, 23 Sep 2025 03:06:05 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v0zqh-0003EF-GC; Tue, 23 Sep 2025 06:02:15 -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 1v0zqC-0002qk-Ni for qemu-devel@nongnu.org; Tue, 23 Sep 2025 06:01:44 -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 1v0zpp-0000ts-Mt for qemu-devel@nongnu.org; Tue, 23 Sep 2025 06:01:43 -0400 Received: from mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:cf2d:0:640:140f:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id 75EDD809DD; Tue, 23 Sep 2025 13:01:18 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:b38::1:12]) by mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id C1Ug0C0Fha60-VMeo8eL5; Tue, 23 Sep 2025 13:01: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=1758621677; bh=0rkp9X76WiOzr/q2WYArxjfrFUzR5vC9iuDCQ/fVu7w=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=iyE4HqxKkLn2d8luJmXgX3xgFBj6cyfa2kSBHsI8J4dkYIxtx8xOAnzXddi6KxYok F8VlUxRd/ECjxnnqaF+5MTCa+1AH3/YuF1sGzbSb4hK41t7HZ0178q7fOxu6ikLRAL Tu7abXVx0qA0Ryz3Qe+hAFQm6lKw3SrWvaoUwM0E= Authentication-Results: mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com Cc: qemu-devel@nongnu.org, philmd@linaro.org, thuth@redhat.com, eblake@redhat.com, michael.roth@amd.com, armbru@redhat.com, farosas@suse.de, peterx@redhat.com, berrange@redhat.com, jasowang@redhat.com, steven.sistare@oracle.com, leiyang@redhat.com, davydov-max@yandex-team.ru, yc-core@yandex-team.ru, vsementsov@yandex-team.ru Subject: [PATCH v6 09/19] net/tap: rework tap_set_sndbuf() Date: Tue, 23 Sep 2025 13:01:00 +0300 Message-ID: <20250923100110.70862-10-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250923100110.70862-1-vsementsov@yandex-team.ru> References: <20250923100110.70862-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: 1758621966950116600 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 --- 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 | 4 +--- 6 files changed, 11 insertions(+), 21 deletions(-) diff --git a/net/tap-bsd.c b/net/tap-bsd.c index 501bf9d3eb..7dd9f0aeda 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 8cb9dc0787..e3e71b713d 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 496c1323fc..79e01a9de3 100644 --- a/net/tap-solaris.c +++ b/net/tap-solaris.c @@ -207,7 +207,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 8e328c679f..326e76843e 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 95cbd75fe4..e6431d0e08 100644 --- a/net/tap.c +++ b/net/tap.c @@ -690,10 +690,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 08c40094b8..08e4a592a0 100644 --- a/net/tap_int.h +++ b/net/tap_int.h @@ -26,14 +26,12 @@ #ifndef NET_TAP_INT_H #define NET_TAP_INT_H =20 -#include "qapi/qapi-types-net.h" - int tap_open(char *ifname, int ifname_size, int *vnet_hdr, int vnet_hdr_required, int mq_required, Error **errp); =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 Sun Sep 28 15:28:19 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=1758621792; cv=none; d=zohomail.com; s=zohoarc; b=ctSXhp2bWftf7PykmuZRPVYdVl2YVJwkrfWKpnRkElIBD2VDJH3FgzK1BlfTJP1o8HHGooVeFaXvnjbTGaLSHQdzF3hBuoUB6V8w8X9I6DJAzDyzdvKQ3EpPydBt16zclemmluuPGzciAQiAdjN26Vt8aShsdH/oi2jc82pc1Wk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758621792; 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=JcPxia8LOA7Ubdd+E2a5buipeOnDhmAVsVoDx82qifQ=; b=WKGb4NMFOETXUYgkNk4sOZg+JUeDe+hyLzNri8cbIGdS43IZ31p0chCdwg1ewa5xzyCJEIH+TsKfdMN1U6PG693Vjnp+6b8JMjGDmFGmHOUJf2ci9Xz6c/kup8N5GnR6M5fReVwD50ZRWfxt5lnm/bYO6Qs3qRVhNKJSCUa4wLA= 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 1758621792594954.5496307569863; Tue, 23 Sep 2025 03:03:12 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v0zqk-0003Kh-ND; Tue, 23 Sep 2025 06:02:18 -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 1v0zqE-0002rC-C4 for qemu-devel@nongnu.org; Tue, 23 Sep 2025 06:01:46 -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 1v0zpt-0000ui-4q for qemu-devel@nongnu.org; Tue, 23 Sep 2025 06:01:45 -0400 Received: from mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:cf2d:0:640:140f:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id 028F080A2D; Tue, 23 Sep 2025 13:01:19 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:b38::1:12]) by mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id C1Ug0C0Fha60-y5BpctxA; Tue, 23 Sep 2025 13:01: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=1758621678; bh=JcPxia8LOA7Ubdd+E2a5buipeOnDhmAVsVoDx82qifQ=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=yw/Kj+Kmi/Qi4W61W59Jra+RZOks2qjGCtC2pu2AYFvqQLFRoIZSSFbXW3GDIlNQu 6QTk3CiEML+smtG4BvhCkwZt6R1CK+yVknL3+bMDS1TDa3K/qBssQ837onJYI+U7Xv 3rJKmwKp8tQ0zft9+gpko959HAGgeA6OylI6DtY8= Authentication-Results: mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com Cc: qemu-devel@nongnu.org, philmd@linaro.org, thuth@redhat.com, eblake@redhat.com, michael.roth@amd.com, armbru@redhat.com, farosas@suse.de, peterx@redhat.com, berrange@redhat.com, jasowang@redhat.com, steven.sistare@oracle.com, leiyang@redhat.com, davydov-max@yandex-team.ru, yc-core@yandex-team.ru, vsementsov@yandex-team.ru Subject: [PATCH v6 10/19] net/tap: rework sndbuf handling Date: Tue, 23 Sep 2025 13:01:01 +0300 Message-ID: <20250923100110.70862-11-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250923100110.70862-1-vsementsov@yandex-team.ru> References: <20250923100110.70862-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: 1758621793932116600 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 --- net/tap.c | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/net/tap.c b/net/tap.c index e6431d0e08..5a74cb325f 100644 --- a/net/tap.c +++ b/net/tap.c @@ -80,6 +80,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, @@ -402,17 +405,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) { s->fd =3D fd; s->host_vnet_hdr_len =3D vnet_hdr ? sizeof(struct virtio_net_hdr) : 0; @@ -430,6 +441,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) @@ -647,8 +667,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 @@ -688,16 +708,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 Sun Sep 28 15:28:19 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=1758621965; cv=none; d=zohomail.com; s=zohoarc; b=eXXshAkPp9cHzmh+aCfyc7Le0JcOCJIiJsOAB/YlixPhqifaR06Pgcz4uA0nYlFXObFs5ZshJzaE9VRFffJ8ljEJsW595cNEuwnfTFlbUr/rEgYqCKouB2UAqxNWy0LGNPWJcu/Y/PYigrHDcEhy5xybwgqTw5LJckA+rx+pf9g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758621965; 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=qAgdAizP1r1UQXonXGtwl0OYoir/lIjiXgnoAfe6dB0=; b=kpLv1xjjifgw9qpHKuTf05TuvUFva1pPJmBNZnXTXwZQy5+H+glLp/F91ePycxWPREvSfHOioeZpxwlXKqZ3VAmEPvcrTqH5iDXvMxSeCtA6w0+LOg+iUj9UMnGmSXuZUQ60LfvHCwPQuKaI/YcLPJUkUHNSwgBDaAZgKWFYfQw= 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 1758621965253195.91630579736238; Tue, 23 Sep 2025 03:06:05 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v0zqh-0003CL-7R; Tue, 23 Sep 2025 06:02:15 -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 1v0zqM-0002vn-9X for qemu-devel@nongnu.org; Tue, 23 Sep 2025 06:01:58 -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 1v0zpv-0000uj-Ni for qemu-devel@nongnu.org; Tue, 23 Sep 2025 06:01:51 -0400 Received: from mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:cf2d:0:640:140f:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id 86DA580A33; Tue, 23 Sep 2025 13:01:19 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:b38::1:12]) by mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id C1Ug0C0Fha60-WYxKYWWY; Tue, 23 Sep 2025 13:01:19 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1758621679; bh=qAgdAizP1r1UQXonXGtwl0OYoir/lIjiXgnoAfe6dB0=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=lVpkEZBultxYYQeutkE+G3Itkc5cn1y84YQg0zP7f025wd+J59Takf4op3ZwuKoSt /v6h89lugqrCtiBkf2IdUcyRqCh6w0Z1gSnphON8H8w079K8/u7mYoFuCMjnJTdsHA bJmTLQfukjthRKxsDpIAkYF/xWsxfgExdjrGSlQI= Authentication-Results: mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com Cc: qemu-devel@nongnu.org, philmd@linaro.org, thuth@redhat.com, eblake@redhat.com, michael.roth@amd.com, armbru@redhat.com, farosas@suse.de, peterx@redhat.com, berrange@redhat.com, jasowang@redhat.com, steven.sistare@oracle.com, leiyang@redhat.com, davydov-max@yandex-team.ru, yc-core@yandex-team.ru, vsementsov@yandex-team.ru Subject: [PATCH v6 11/19] net/tap: introduce net_tap_setup() Date: Tue, 23 Sep 2025 13:01:02 +0300 Message-ID: <20250923100110.70862-12-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250923100110.70862-1-vsementsov@yandex-team.ru> References: <20250923100110.70862-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: 1758621967049116600 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 --- net/tap.c | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/net/tap.c b/net/tap.c index 5a74cb325f..877564405a 100644 --- a/net/tap.c +++ b/net/tap.c @@ -85,6 +85,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 @@ -709,11 +713,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); @@ -732,6 +731,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; @@ -747,20 +761,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; @@ -775,14 +789,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 Sun Sep 28 15:28:19 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=1758621797; cv=none; d=zohomail.com; s=zohoarc; b=eBh2BCS0MpbqpUMdSd2wr5U9bKY1BmxfavLNGU7Iv7VyX4eA7iAICdH4OnYyUuLVj4Cm/RTpxecW4wP5w9xrAexPClbDccJSSkWSgZ/zx696MhnGRM1iMHTawW010uoofJ7FtG6qaiS2eElRFMcTtA4+kIXPNMMczjm3JsOQenk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758621797; 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=0hyZv3Tmf7qh6fxmfFpnAzLfwhXELi2XZF0zR5DEdEY=; b=dulwaTyFvTbx8M291JKyd6UG+vBha8i+HQfYtKEVB7glAmmA1nEkZeYJ3VoHMLNbEYVTB59YY3O5IBz3Aoe0odtMqurS/P5cmY82zmbphTrleBymixaDiIO3r7n3d/EeucyA/tvL7fu4LCSfwsGbt0UNBclRyEQbr7ocT6TnpNs= 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 1758621796811736.8597002855754; Tue, 23 Sep 2025 03:03:16 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v0zqa-00038s-Sg; Tue, 23 Sep 2025 06:02: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 1v0zqF-0002sL-9W for qemu-devel@nongnu.org; Tue, 23 Sep 2025 06:01:48 -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 1v0zpw-0000ur-JS for qemu-devel@nongnu.org; Tue, 23 Sep 2025 06:01:46 -0400 Received: from mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:cf2d:0:640:140f:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id 1982680A41; Tue, 23 Sep 2025 13:01:20 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:b38::1:12]) by mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id C1Ug0C0Fha60-DqZvLq09; Tue, 23 Sep 2025 13:01:19 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1758621679; bh=0hyZv3Tmf7qh6fxmfFpnAzLfwhXELi2XZF0zR5DEdEY=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=x2eL+kBaTTQliz+ZoHsyTs6C26oZglC9BkKB38rxUeKJQbAZfj6lhoUHXWRFzk5uk VvmGMe6k0Jjdcg5Be0aoJ2K669zDdCtfZByF67muoItoVMFeTcCbQQLmcleZLFPCQ3 Qv23kc12rdNJ/HpwNpHNBnz3b2ZMBS/vA8ByaD2Q= Authentication-Results: mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com Cc: qemu-devel@nongnu.org, philmd@linaro.org, thuth@redhat.com, eblake@redhat.com, michael.roth@amd.com, armbru@redhat.com, farosas@suse.de, peterx@redhat.com, berrange@redhat.com, jasowang@redhat.com, steven.sistare@oracle.com, leiyang@redhat.com, davydov-max@yandex-team.ru, yc-core@yandex-team.ru, vsementsov@yandex-team.ru Subject: [PATCH v6 12/19] net/tap: move vhost fd initialization to net_tap_new() Date: Tue, 23 Sep 2025 13:01:03 +0300 Message-ID: <20250923100110.70862-13-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250923100110.70862-1-vsementsov@yandex-team.ru> References: <20250923100110.70862-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: 1758621797861116600 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 --- net/tap.c | 90 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 50 insertions(+), 40 deletions(-) diff --git a/net/tap.c b/net/tap.c index 877564405a..dbd1eb3a17 100644 --- a/net/tap.c +++ b/net/tap.c @@ -83,11 +83,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); @@ -351,6 +351,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) @@ -409,12 +414,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; @@ -424,7 +431,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) @@ -671,7 +707,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); @@ -712,7 +748,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); @@ -731,53 +770,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 Sun Sep 28 15:28:19 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=1758621865; cv=none; d=zohomail.com; s=zohoarc; b=GaCRHnVgNdsEjQnka20cFIqdGT821G+oJVn94hDgNYEUH4oGMyD4UZF26RQS6h69KgS4cYRynPaBTH7uoF2b+tRR/nXMgk0o9u9NllCplT024Gq63TGvR9+Y5lr9mb2oaPWbmVnMsCPCbQdZDXyQpi3whlYarCf/QME+zwcGpfE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758621865; 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=DfzOyCICzHBH/C+sRPO/6zCB1uwXvXGrUTU5e+HA5lw=; b=cv6qKwJ8im60TDDUPy5MfBbC8AHR66oIZWKVbXbiqbxHWlosOMaRNuCL8EWAsS1JhuTo6suo7mopOjAXRtFN46KuE3VBTCIDumt9DFi7HOgtsRVj70eZ8o3aZEwXSunx/OyNNV/3uwfUpjDsgMKV8YS+wt6Fif8gwpydcmpSa38= 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 1758621865111978.598759877961; Tue, 23 Sep 2025 03:04:25 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v0zqm-0003TT-Qs; Tue, 23 Sep 2025 06:02:20 -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 1v0zqE-0002sF-Pk for qemu-devel@nongnu.org; Tue, 23 Sep 2025 06:01:48 -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 1v0zpu-0000us-Ic for qemu-devel@nongnu.org; Tue, 23 Sep 2025 06:01:46 -0400 Received: from mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:cf2d:0:640:140f:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id A0A90807D1; Tue, 23 Sep 2025 13:01:20 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:b38::1:12]) by mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id C1Ug0C0Fha60-1JTnM1op; Tue, 23 Sep 2025 13:01:20 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1758621680; bh=DfzOyCICzHBH/C+sRPO/6zCB1uwXvXGrUTU5e+HA5lw=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=FiQOh7Nd6nrpxElWhIen2Yr/hnl3A/wLvQsMV/O2JQyrfUjD1/HjNlBuzYa26l199 km0uCnm+T050Rw8pB3wPGec3ywkjNnNNYzd/hFoy6Z9JCYinqtwMZNYhB58W5scEI7 prqxyvaDnXRASvSlB/q+dCAPR5Y3i21LMLHcAKqo= Authentication-Results: mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com Cc: qemu-devel@nongnu.org, philmd@linaro.org, thuth@redhat.com, eblake@redhat.com, michael.roth@amd.com, armbru@redhat.com, farosas@suse.de, peterx@redhat.com, berrange@redhat.com, jasowang@redhat.com, steven.sistare@oracle.com, leiyang@redhat.com, davydov-max@yandex-team.ru, yc-core@yandex-team.ru, vsementsov@yandex-team.ru Subject: [PATCH v6 13/19] net/tap: finalize net_tap_set_fd() logic Date: Tue, 23 Sep 2025 13:01:04 +0300 Message-ID: <20250923100110.70862-14-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250923100110.70862-1-vsementsov@yandex-team.ru> References: <20250923100110.70862-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: 1758621865740116600 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 --- net/tap.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/net/tap.c b/net/tap.c index dbd1eb3a17..340d8d0cda 100644 --- a/net/tap.c +++ b/net/tap.c @@ -467,7 +467,6 @@ static bool net_tap_set_fd(TAPState *s, int fd, int vne= t_hdr, Error **errp) { 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->enabled =3D true; @@ -479,8 +478,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; @@ -781,6 +778,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 Sun Sep 28 15:28:19 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=1758621851; cv=none; d=zohomail.com; s=zohoarc; b=LgWAQKUpwLJMwRV9shef5shSdga7PMPUz5r4SAVfsVKIGZVY5RT6ITvOU9wSU17Ce7lGCe834Ny4BbaPFLaAnVMax3YUcq33PaPNSP8uFam0cdeleeZm+7IYIOv8xiUR+MlVZGMxuHAUy5biLMPS22+OT92QJBdgU3e2YFOdAuo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758621851; 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=GzChdpIiKM7X9bgeu4CwKiMXmrBRh/3YN7kvx854C6k=; b=WtZj70X5nd/YiAxwbgjnc6Eai5kRsRWN1hn9QgELGV36CQhsCsZDQlbUTpQchGFLb7B3ZtQmcEb0XZeG2p8gwAQ0il2/f54nuBN97tsl6JNqdBIvXZ8q4JchX+AV83Ok+8mHGfNR7+K6w8t5GUHFbFnqI0Eoth5aj1n1XRkhtPM= 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 1758621851827895.5614416205273; Tue, 23 Sep 2025 03:04:11 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v0zqs-0003fA-ST; Tue, 23 Sep 2025 06:02: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 1v0zqK-0002vh-1W for qemu-devel@nongnu.org; Tue, 23 Sep 2025 06:01:52 -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 1v0zpy-0000vQ-Sg for qemu-devel@nongnu.org; Tue, 23 Sep 2025 06:01:51 -0400 Received: from mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:cf2d:0:640:140f:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id 2708980B6E; Tue, 23 Sep 2025 13:01:21 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:b38::1:12]) by mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id C1Ug0C0Fha60-BVlNaRNH; Tue, 23 Sep 2025 13:01:20 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1758621680; bh=GzChdpIiKM7X9bgeu4CwKiMXmrBRh/3YN7kvx854C6k=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=OF3WdaO4FbwXyhl/0dqAiFImJ9RDWHHMfeiU6sWStq/BdVbCRbOoh9PR0HwrlwYhK s2iT+mL8XOFwOFuoPM5ka4Iwob6HNTIgH/hMgSLp0MqAtj9jlQhPr4oV1vrdif1LSS HfZBfOPRpVf1wzm4Glopyo7o3U/c9goaoZEzozbA= Authentication-Results: mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com Cc: qemu-devel@nongnu.org, philmd@linaro.org, thuth@redhat.com, eblake@redhat.com, michael.roth@amd.com, armbru@redhat.com, farosas@suse.de, peterx@redhat.com, berrange@redhat.com, jasowang@redhat.com, steven.sistare@oracle.com, leiyang@redhat.com, davydov-max@yandex-team.ru, yc-core@yandex-team.ru, vsementsov@yandex-team.ru Subject: [PATCH v6 14/19] migration: add MIG_EVENT_PRE_INCOMING Date: Tue, 23 Sep 2025 13:01:05 +0300 Message-ID: <20250923100110.70862-15-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250923100110.70862-1-vsementsov@yandex-team.ru> References: <20250923100110.70862-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: 1758621853757116600 Content-Type: text/plain; charset="utf-8" We are going to implement backend-transfer migration feature for virtio-net/tap. When it's enabled (by setting migration parameter), TAP device is passed through migration channel (which should be a unix socket to pass fds) to a new QEMU. So we need to know during TAP initialization, should we open TAP device, or wait for incoming fds. But we can't check for migration parameter at TAP creation time, as use may set migration parameter later (especially when TAP is added by command line parameter). To solve this, we have prepared TAP initialization code so that opening the device may be postponed to later point. And this later point is obviously the early beginning of qmp_migrate_incoming(): here we already know all migration parameters and capabilities, but we are not in downtime, so we can continue initialization of TAP device. This commit introduces MIG_EVENT_PRE_INCOMING, to be used by TAP code in following commit. Signed-off-by: Vladimir Sementsov-Ogievskiy Tested-by: Lei Yang --- include/migration/misc.h | 1 + migration/migration.c | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/include/migration/misc.h b/include/migration/misc.h index a261f99d89..5765fcc204 100644 --- a/include/migration/misc.h +++ b/include/migration/misc.h @@ -63,6 +63,7 @@ typedef enum MigrationEventType { MIG_EVENT_PRECOPY_SETUP, MIG_EVENT_PRECOPY_DONE, MIG_EVENT_PRECOPY_FAILED, + MIG_EVENT_PRE_INCOMING, MIG_EVENT_MAX } MigrationEventType; =20 diff --git a/migration/migration.c b/migration/migration.c index e1ac4d73c2..4c356e0b92 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1696,7 +1696,8 @@ int migration_call_notifiers(MigrationState *s, Migra= tionEventType type, e.type =3D type; ret =3D notifier_with_return_list_notify(&migration_state_notifiers[mo= de], &e, errp); - assert(!ret || type =3D=3D MIG_EVENT_PRECOPY_SETUP); + assert(!ret || type =3D=3D MIG_EVENT_PRECOPY_SETUP || + type =3D=3D MIG_EVENT_PRE_INCOMING); return ret; } =20 @@ -1936,6 +1937,11 @@ void qmp_migrate_incoming(const char *uri, bool has_= channels, return; } =20 + if (migration_call_notifiers(migrate_get_current(), MIG_EVENT_PRE_INCO= MING, + errp)) { + return; + } + if (!yank_register_instance(MIGRATION_YANK_INSTANCE, errp)) { return; } --=20 2.48.1 From nobody Sun Sep 28 15:28:19 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=1758621805; cv=none; d=zohomail.com; s=zohoarc; b=fDBDZbVlw2dT42wECY6AFSrW7Sps8Rp9pbqQ+zSTBRlz0uF5WGkmPc84urKNXdf8iDntd3X5qdJsXglFN0H1PPv1XvD/O1Dg8XYDwE9ffaFcTjIAm8yT9zkeS9Kc3yokEcAo5WmIXa/cYz8UMHY9tFfhnNWRPjkvih8qTfyjEs4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758621805; 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=iX6zXi/sEZUUGILdy0a/kLuIbyZSAaxyaU7qYN1vwBg=; b=IdlkUWwkEEcWgP8l92oaGChoYWMUMGOW1zt5nfRAl9earQoNXXJHKtpZYFcrl1yA1/yv82q5XjtVWDEgIJ6eIANO4qMG8uLIr3nipIxCy0Y4Rv6fUBT6B0ICwxYwS0eHWeVg3zVpvvycAqyv3HPu1RZ5ZPv3iI3+y1dL3B1N6Bw= 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 1758621805199694.3479721493776; Tue, 23 Sep 2025 03:03:25 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v0zqR-0002ws-M6; Tue, 23 Sep 2025 06:01:59 -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 1v0zqF-0002sK-8A for qemu-devel@nongnu.org; Tue, 23 Sep 2025 06:01:48 -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 1v0zpu-0000vB-J2 for qemu-devel@nongnu.org; Tue, 23 Sep 2025 06:01:46 -0400 Received: from mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:cf2d:0:640:140f:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id CFB1080A49; Tue, 23 Sep 2025 13:01:21 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:b38::1:12]) by mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id C1Ug0C0Fha60-JWZ1vgup; Tue, 23 Sep 2025 13:01:21 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1758621681; bh=iX6zXi/sEZUUGILdy0a/kLuIbyZSAaxyaU7qYN1vwBg=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=z7XH5BdvfKKmrbXaaY78Twku5Pmvo1jhEruzjpAymfCXEJfb/Fihu8FNXjMTbw5S5 BmflNGw1SD6yscJJy4DDToiarzECspDxV9TOXaHy6y5ZwE2YwJFgBImQG3A57wD2/N u3x2AY6hqhPfnLkMDJUVGMbQTJ4WWciStaL1UzKU= Authentication-Results: mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com Cc: qemu-devel@nongnu.org, philmd@linaro.org, thuth@redhat.com, eblake@redhat.com, michael.roth@amd.com, armbru@redhat.com, farosas@suse.de, peterx@redhat.com, berrange@redhat.com, jasowang@redhat.com, steven.sistare@oracle.com, leiyang@redhat.com, davydov-max@yandex-team.ru, yc-core@yandex-team.ru, vsementsov@yandex-team.ru Subject: [PATCH v6 15/19] net/tap: postpone tap setup to pre-incoming Date: Tue, 23 Sep 2025 13:01:06 +0300 Message-ID: <20250923100110.70862-16-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250923100110.70862-1-vsementsov@yandex-team.ru> References: <20250923100110.70862-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_PASS=-0.001, T_SPF_HELO_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: 1758621806062116600 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 | 65 ++++++++++++++++- include/net/tap.h | 2 + net/tap-win32.c | 5 ++ net/tap.c | 172 +++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 242 insertions(+), 2 deletions(-) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 6b5b5dace3..70f688fc3a 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -688,6 +688,21 @@ 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 int peer_attach(VirtIONet *n, int index) { NetClientState *nc =3D qemu_get_subqueue(n->nic, index); @@ -2999,7 +3014,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) @@ -3028,6 +3053,17 @@ static uint64_t virtio_net_get_features(VirtIODevice= *vdev, uint64_t features, =20 virtio_add_feature(&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 features; + } + if (!peer_has_vnet_hdr(n)) { virtio_clear_feature(&features, VIRTIO_NET_F_CSUM); virtio_clear_feature(&features, VIRTIO_NET_F_HOST_TSO4); @@ -3106,6 +3142,32 @@ static uint64_t virtio_net_get_features(VirtIODevice= *vdev, uint64_t features, return features; } =20 +static int virtio_net_update_host_features(VirtIONet *n) +{ + Error *local_err =3D NULL; + VirtIODevice *vdev =3D VIRTIO_DEVICE(n); + + peer_test_vnet_hdr(n); + + vdev->host_features =3D virtio_net_get_features(vdev, vdev->host_featu= res, + &local_err); + if (local_err) { + error_report_err(local_err); + return -EINVAL; + } + + return 0; +} + +static int virtio_net_pre_load_device(void *opaque) +{ + /* + * Probably backend initialization was postponed to + * pre-incoming point. So, update information now. + */ + return virtio_net_update_host_features(opaque); +} + static int virtio_net_post_load_device(void *opaque, int version_id) { VirtIONet *n =3D opaque; @@ -3498,6 +3560,7 @@ static const VMStateDescription vmstate_virtio_net_de= vice =3D { .name =3D "virtio-net-device", .version_id =3D VIRTIO_NET_VM_VERSION, .minimum_version_id =3D VIRTIO_NET_VM_VERSION, + .pre_load =3D virtio_net_pre_load_device, .post_load =3D virtio_net_post_load_device, .fields =3D (const VMStateField[]) { VMSTATE_UINT8_ARRAY(mac, VirtIONet, ETH_ALEN), diff --git a/include/net/tap.h b/include/net/tap.h index 6f34f13eae..c6f9c1aeb1 100644 --- a/include/net/tap.h +++ b/include/net/tap.h @@ -33,4 +33,6 @@ int tap_disable(NetClientState *nc); =20 int tap_get_fd(NetClientState *nc); =20 +bool tap_wait_incoming(NetClientState *nc); + #endif /* QEMU_NET_TAP_H */ diff --git a/net/tap-win32.c b/net/tap-win32.c index 38baf90e0b..d526c42b7b 100644 --- a/net/tap-win32.c +++ b/net/tap-win32.c @@ -766,3 +766,8 @@ int tap_disable(NetClientState *nc) { abort(); } + +bool tap_wait_incoming(NetClientState *nc) +{ + return false; +} diff --git a/net/tap.c b/net/tap.c index 340d8d0cda..b959547492 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" @@ -85,8 +87,20 @@ 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 QTAILQ_HEAD(, TAPState) postponed_taps =3D + QTAILQ_HEAD_INITIALIZER(postponed_taps); +static NotifierWithReturn pre_incoming_notifier; + +static bool tap_postponed_init(TAPState *s, 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, @@ -356,6 +370,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) @@ -373,6 +389,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, errp); + } + } + + return true; +} + int tap_get_fd(NetClientState *nc) { TAPState *s =3D DO_UPCAST(TAPState, nc, nc); @@ -411,6 +446,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, @@ -831,6 +867,124 @@ static int get_fds(char *str, char *fds[], int max) return i; } =20 +#define TAP_OPEN_IFNAME_SZ 128 + +static bool tap_postponed_init(TAPState *s, Error **errp) +{ + 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; + } + + QTAILQ_REMOVE(&postponed_taps, s, next); + return true; + +fail: + QTAILQ_REMOVE(&postponed_taps, s, next); + qemu_del_net_client(&s->nc); + return false; +} + +static int tap_pre_incoming(NotifierWithReturn *notifier, + MigrationEvent *e, + Error **errp) +{ + TAPState *s; + bool ok =3D true; + + if (e->type !=3D MIG_EVENT_PRE_INCOMING) { + return 0; + } + + while (!QTAILQ_EMPTY(&postponed_taps)) { + s =3D QTAILQ_FIRST(&postponed_taps); + if (ok) { + ok =3D tap_postponed_init(s, errp); + } else { + QTAILQ_REMOVE(&postponed_taps, s, next); + qemu_del_net_client(&s->nc); + } + } + + return ok ? 0 : -1; +} + +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); + + QTAILQ_INSERT_TAIL(&postponed_taps, s, next); + } + + if (!pre_incoming_notifier.notify) { + migration_add_notifier(&pre_incoming_notifier, tap_pre_incoming); + } + + *postponed =3D true; + return true; +} + int net_init_tap(const Netdev *netdev, const char *name, NetClientState *peer, Error **errp) { @@ -839,8 +993,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; @@ -859,6 +1014,14 @@ int net_init_tap(const Netdev *netdev, const char *na= me, 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 || @@ -1083,3 +1246,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 Sun Sep 28 15:28:19 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=1758621820; cv=none; d=zohomail.com; s=zohoarc; b=XA1ZalE2Z/pXDU1LEbT6QL0/IsIWqbEL/UuXSvhQ5hJoYkGRFteJ/6Y6KLbOlyI61ZNbJg/4eH9ZTnlhzGiq8C8bSBjZzxnyYGAX8PiZmJOvZtopUbxFch4aFpD1JhrxLZokrwXJgfBELefzA2+i7dFSoPbw8XRd5IpFyyTOeTs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758621820; 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=pBzg571zcaff+LTMRWyupFJ/ags+sUhQliNbfrNb9iQ=; b=FCBuaP2RVXdwnqbzpiKbS4oWv7ec+oKCSYDPk+WaY0LlNmfDn0VXurt6+Ornhh7vlQrNZzBrjm1HNeXMQEs/bfMN3PtXBGJqeK5E5jKcsZQGurL8n4ANehsQGKLnNVfdRof4f/0CQZrmgVyv/5M2LfEaTJXr0LOrJY9BXfpA27Q= 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 1758621820224582.7267481032349; Tue, 23 Sep 2025 03:03:40 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v0zqg-0003BI-Uw; Tue, 23 Sep 2025 06:02:15 -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 1v0zqK-0002vp-F9 for qemu-devel@nongnu.org; Tue, 23 Sep 2025 06:01:53 -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 1v0zpu-0000vF-JG for qemu-devel@nongnu.org; Tue, 23 Sep 2025 06:01:52 -0400 Received: from mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:cf2d:0:640:140f:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id 78F0B80B8F; Tue, 23 Sep 2025 13:01:22 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:b38::1:12]) by mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id C1Ug0C0Fha60-cgescJDW; Tue, 23 Sep 2025 13:01:22 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1758621682; bh=pBzg571zcaff+LTMRWyupFJ/ags+sUhQliNbfrNb9iQ=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=fgtkJ3jAaMjcf9kM+J3AYdXy3YbwKnSVS7WnxGrq/M8DE9o0QXEoJbjA6SBjj0GhA /Ak4epsjBYcG2t98q/8kk82gXjZLYG0FaLjEJhOZCvhSH4o+PlFH9aFGJXazucjksU m4iLMVNeulTqjqyRAcEU2NM+PRuT+QxNLYxuFBT0= Authentication-Results: mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com Cc: qemu-devel@nongnu.org, philmd@linaro.org, thuth@redhat.com, eblake@redhat.com, michael.roth@amd.com, armbru@redhat.com, farosas@suse.de, peterx@redhat.com, berrange@redhat.com, jasowang@redhat.com, steven.sistare@oracle.com, leiyang@redhat.com, davydov-max@yandex-team.ru, yc-core@yandex-team.ru, vsementsov@yandex-team.ru Subject: [PATCH v6 16/19] qapi: add interface for backend-transfer virtio-net/tap migration Date: Tue, 23 Sep 2025 13:01:07 +0300 Message-ID: <20250923100110.70862-17-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250923100110.70862-1-vsementsov@yandex-team.ru> References: <20250923100110.70862-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, T_SPF_HELO_TEMPERROR=0.01, 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: 1758621822317116600 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. Signed-off-by: Vladimir Sementsov-Ogievskiy Tested-by: Lei Yang --- include/qapi/util.h | 17 ++++++++++++++++ migration/options.c | 32 ++++++++++++++++++++++++++++++ migration/options.h | 2 ++ qapi/migration.json | 47 ++++++++++++++++++++++++++++++++++++--------- 4 files changed, 89 insertions(+), 9 deletions(-) diff --git a/include/qapi/util.h b/include/qapi/util.h index 29bc4eb865..b953402416 100644 --- a/include/qapi/util.h +++ b/include/qapi/util.h @@ -69,4 +69,21 @@ int parse_qapi_name(const char *name, bool complete); _len; \ }) =20 +/* + * For any GenericList @list, return true if it contains specified + * element. + */ +#define QAPI_LIST_CONTAINS(list, el) \ + ({ \ + bool _found =3D false; \ + typeof_strip_qual(list) _tail; \ + for (_tail =3D list; _tail !=3D NULL; _tail =3D _tail->next) { \ + if (_tail->value =3D=3D el) { \ + _found =3D true; \ + break; \ + } \ + } \ + _found; \ + }) + #endif diff --git a/migration/options.c b/migration/options.c index 4e923a2e07..137ca2147e 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,14 @@ 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(); + + return QAPI_LIST_CONTAINS(s->parameters.backend_transfer, + BACKEND_TRANSFER_VIRTIO_NET_TAP); +} + bool migrate_ignore_shared(void) { MigrationState *s =3D migrate_get_current(); @@ -960,6 +969,12 @@ MigrationParameters *qmp_query_migrate_parameters(Erro= r **errp) params->has_direct_io =3D true; params->direct_io =3D s->parameters.direct_io; =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 @@ -993,6 +1008,7 @@ void migrate_params_init(MigrationParameters *params) params->has_mode =3D true; params->has_zero_page_detection =3D true; params->has_direct_io =3D true; + params->has_backend_transfer =3D true; } =20 /* @@ -1179,6 +1195,11 @@ bool migrate_params_check(MigrationParameters *param= s, Error **errp) return false; } =20 + if (params->has_backend_transfer) { + error_setg(errp, "Not implemented"); + return false; + } + return true; } =20 @@ -1297,6 +1318,10 @@ static void migrate_params_test_apply(MigrateSetPara= meters *params, if (params->has_direct_io) { dest->direct_io =3D params->direct_io; } + + if (params->has_backend_transfer) { + dest->backend_transfer =3D params->backend_transfer; + } } =20 static void migrate_params_apply(MigrateSetParameters *params, Error **err= p) @@ -1429,6 +1454,13 @@ static void migrate_params_apply(MigrateSetParameter= s *params, Error **errp) if (params->has_direct_io) { s->parameters.direct_io =3D params->direct_io; } + + 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 2387c21e9c..e39785dc07 100644 --- a/qapi/migration.json +++ b/qapi/migration.json @@ -747,6 +747,18 @@ '*transform': 'BitmapMigrationBitmapAliasTransform' } } =20 +## +# @BackendTransfer: +# +# @virtio-net-tap: Enable backend-transfer migration for virtio-net/tap. W= hen +# enabled, TAP fds and all related state is passed to target QEMU thro= ugh +# migration channel (which should be unix socket). +# +# Since: 10.2 +## +{ 'enum': 'BackendTransfer', + 'data': [ 'virtio-net-tap' ] } + ## # @BitmapMigrationNodeAlias: # @@ -924,10 +936,14 @@ # only has effect if the @mapped-ram capability is enabled. # (Since 9.1) # +# @backend-transfer: List of targets to enable backend-transfer +# migration for. This requires migration channel to be a unix +# socket (to pass fds through). (Since 10.2) +# # Features: # -# @unstable: Members @x-checkpoint-delay and -# @x-vcpu-dirty-limit-period are experimental. +# @unstable: Members @x-checkpoint-delay, +# @x-vcpu-dirty-limit-period and @backend-transfer are experimental. # # Since: 2.4 ## @@ -950,7 +966,8 @@ 'vcpu-dirty-limit', 'mode', 'zero-page-detection', - 'direct-io'] } + 'direct-io', + 'backend-transfer' ] } =20 ## # @MigrateSetParameters: @@ -1105,10 +1122,14 @@ # only has effect if the @mapped-ram capability is enabled. # (Since 9.1) # +# @backend-transfer: List of targets to enable backend-transfer +# migration for. This requires migration channel to be a unix +# socket (to pass fds through). (Since 10.2) +# # Features: # -# @unstable: Members @x-checkpoint-delay and -# @x-vcpu-dirty-limit-period are experimental. +# @unstable: Members @x-checkpoint-delay, +# @x-vcpu-dirty-limit-period and @backend-transfer are experimental. # # TODO: either fuse back into `MigrationParameters`, or make # `MigrationParameters` members mandatory @@ -1146,7 +1167,9 @@ '*vcpu-dirty-limit': 'uint64', '*mode': 'MigMode', '*zero-page-detection': 'ZeroPageDetection', - '*direct-io': 'bool' } } + '*direct-io': 'bool', + '*backend-transfer': { 'type': [ 'BackendTransfer' ], + 'features': [ 'unstable' ] } } } =20 ## # @migrate-set-parameters: @@ -1315,10 +1338,14 @@ # only has effect if the @mapped-ram capability is enabled. # (Since 9.1) # +# @backend-transfer: List of targets to enable backend-transfer +# migration for. This requires migration channel to be a unix +# socket (to pass fds through). (Since 10.2) +# # Features: # -# @unstable: Members @x-checkpoint-delay and -# @x-vcpu-dirty-limit-period are experimental. +# @unstable: Members @x-checkpoint-delay, +# @x-vcpu-dirty-limit-period and @backend-transfer are experimental. # # Since: 2.4 ## @@ -1353,7 +1380,9 @@ '*vcpu-dirty-limit': 'uint64', '*mode': 'MigMode', '*zero-page-detection': 'ZeroPageDetection', - '*direct-io': 'bool' } } + '*direct-io': 'bool', + '*backend-transfer': { 'type': [ 'BackendTransfer' ], + 'features': [ 'unstable' ] } } } =20 ## # @query-migrate-parameters: --=20 2.48.1 From nobody Sun Sep 28 15:28:19 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=1758621843; cv=none; d=zohomail.com; s=zohoarc; b=k2Adot0yIHjlCq9OX0SI4Ri9MkKFMEjz3Kr0CJiOmd/mbSChhGRKVK6RlZfHg/kErm6sS0+qLWdX1nMPKASL1qrQQtMyr2OF/aAEFq8iRefOswwKbuWXiUghAh0oOSfAdv3pBSvGrSyLxqkq4dvjf4UDISbkIBO407V6VWc5pTI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758621843; 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=rioAl/ubyEER0xno3M72Ijf4+vaU5tOXleX9shfbfio=; b=ICoeySMYI08DijIuW9U2t2SOlmh0MhybDwrZ9w9qjI4OIYiiaBP/VjQqh7B6zXKrYsazRA8Q0h4PnqkfUEssREBkQOTszwXsQZHexkIawQVVcBCLBg5WJYY99XZKmKaL5LfCpV9s+k64U5BuTDj+YCwGqjYKPDvtoTUaFSHtiEI= 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 1758621843802925.0314667907736; Tue, 23 Sep 2025 03:04:03 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v0zqb-00039D-6N; Tue, 23 Sep 2025 06:02:09 -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 1v0zqF-0002sN-Bi for qemu-devel@nongnu.org; Tue, 23 Sep 2025 06:01:48 -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 1v0zpv-0000vE-Ok for qemu-devel@nongnu.org; Tue, 23 Sep 2025 06:01:47 -0400 Received: from mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:cf2d:0:640:140f:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id 2B8AD8081E; Tue, 23 Sep 2025 13:01:23 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:b38::1:12]) by mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id C1Ug0C0Fha60-xoLeCjei; Tue, 23 Sep 2025 13:01:22 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1758621682; bh=rioAl/ubyEER0xno3M72Ijf4+vaU5tOXleX9shfbfio=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=VnW8PFjoIcUruCGw7v+x4uWzq9LXs8yfyomqSgHrjZPxfU6FCzkCYhri71OVTPqgN M2UVR+K5f8ykENDxvB+q1so9VtDOynB3rJnPTlcMeb8Y6VcLGMsU1iF9yyQImQImsI 7SNVPyTrefCIBx7j+Zdv/lAloHV9auDS1fDsM21c= Authentication-Results: mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com Cc: qemu-devel@nongnu.org, philmd@linaro.org, thuth@redhat.com, eblake@redhat.com, michael.roth@amd.com, armbru@redhat.com, farosas@suse.de, peterx@redhat.com, berrange@redhat.com, jasowang@redhat.com, steven.sistare@oracle.com, leiyang@redhat.com, davydov-max@yandex-team.ru, yc-core@yandex-team.ru, vsementsov@yandex-team.ru Subject: [PATCH v6 17/19] virtio-net: support backend-transfer migration for virtio-net/tap Date: Tue, 23 Sep 2025 13:01:08 +0300 Message-ID: <20250923100110.70862-18-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250923100110.70862-1-vsementsov@yandex-team.ru> References: <20250923100110.70862-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: 1758621845813116600 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 --- hw/net/virtio-net.c | 73 +++++++++++++++++++++++++++++++++++++++++++++ include/net/tap.h | 3 ++ migration/options.c | 5 ---- net/tap.c | 54 ++++++++++++++++++++++++++++++++- 4 files changed, 129 insertions(+), 6 deletions(-) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 70f688fc3a..73e4053c41 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -26,6 +26,7 @@ #include "qemu/option.h" #include "qemu/option_int.h" #include "qemu/config-file.h" +#include "qemu/typedefs.h" #include "qobject/qdict.h" #include "hw/virtio/virtio-net.h" #include "net/vhost_net.h" @@ -38,6 +39,8 @@ #include "qapi/qapi-events-migration.h" #include "hw/virtio/virtio-access.h" #include "migration/misc.h" +#include "migration/migration.h" +#include "migration/options.h" #include "standard-headers/linux/ethtool.h" #include "system/system.h" #include "system/replay.h" @@ -3147,6 +3150,11 @@ static int virtio_net_update_host_features(VirtIONet= *n) Error *local_err =3D NULL; VirtIODevice *vdev =3D VIRTIO_DEVICE(n); =20 + if (peer_wait_incoming(n)) { + /* It's too early for updating options. */ + return 0; + } + peer_test_vnet_hdr(n); =20 vdev->host_features =3D virtio_net_get_features(vdev, vdev->host_featu= res, @@ -3287,6 +3295,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 @@ -3556,6 +3567,65 @@ 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; + + return virtio_net_update_host_features(tmp->parent); +} + +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, @@ -3588,6 +3658,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), diff --git a/include/net/tap.h b/include/net/tap.h index c6f9c1aeb1..0be083f8da 100644 --- a/include/net/tap.h +++ b/include/net/tap.h @@ -26,6 +26,7 @@ #ifndef QEMU_NET_TAP_H #define QEMU_NET_TAP_H =20 +#include "qemu/typedefs.h" #include "standard-headers/linux/virtio_net.h" =20 int tap_enable(NetClientState *nc); @@ -35,4 +36,6 @@ int tap_get_fd(NetClientState *nc); =20 bool tap_wait_incoming(NetClientState *nc); =20 +extern const VMStateDescription vmstate_tap; + #endif /* QEMU_NET_TAP_H */ diff --git a/migration/options.c b/migration/options.c index 137ca2147e..38460e9b1b 100644 --- a/migration/options.c +++ b/migration/options.c @@ -1195,11 +1195,6 @@ bool migrate_params_check(MigrationParameters *param= s, Error **errp) return false; } =20 - 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 b959547492..10180daf03 100644 --- a/net/tap.c +++ b/net/tap.c @@ -36,6 +36,7 @@ #include "net/net.h" #include "clients.h" #include "migration/misc.h" +#include "migration/options.h" #include "monitor/monitor.h" #include "system/runstate.h" #include "system/system.h" @@ -94,6 +95,7 @@ typedef struct TAPState { int vnet_hdr; bool mq_required; char *ifname; + bool attached_to_virtio_net; } TAPState; =20 static QTAILQ_HEAD(, TAPState) postponed_taps =3D @@ -405,6 +407,8 @@ static bool tap_check_peer_type(NetClientState *nc, Obj= ectClass *oc, } } =20 + s->attached_to_virtio_net =3D true; + return true; } =20 @@ -810,7 +814,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 @@ -902,6 +906,7 @@ static int tap_pre_incoming(NotifierWithReturn *notifie= r, { TAPState *s; bool ok =3D true; + bool mig_fds =3D migrate_virtio_net_tap(); =20 if (e->type !=3D MIG_EVENT_PRE_INCOMING) { return 0; @@ -910,6 +915,11 @@ static int tap_pre_incoming(NotifierWithReturn *notifi= er, while (!QTAILQ_EMPTY(&postponed_taps)) { s =3D QTAILQ_FIRST(&postponed_taps); if (ok) { + if (mig_fds && s->attached_to_virtio_net) { + /* We'll get fds from incoming migration */ + QTAILQ_REMOVE(&postponed_taps, s, next); + continue; + } ok =3D tap_postponed_init(s, errp); } else { QTAILQ_REMOVE(&postponed_taps, s, next); @@ -1247,6 +1257,48 @@ 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(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 Sun Sep 28 15:28:19 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=1758621837; cv=none; d=zohomail.com; s=zohoarc; b=KvZK+k0TIZiLiBRvEF5Rja75AeHnhQaeAgC9OweewoS4kYK7mKZwq3ZYrcp6tEEuCynFb+UESiyLS1l9jCJ/5hAYlQAQAw2eHPzuLRRKxs5LOPvyJjcyPOY+HjkHFMecOSZEhuSPNeYUKhiXpgz70dGdH2rXlo1HQLssy3k17os= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758621837; 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=tVt9MTceZxb+Z2P97d76cU/wUeCLYbrndwjIMj44b50=; b=J4zQQa7DKhNxMUNn94ZTZtJShaR1K05H+u6WtmSubymtmW+Iu4B50pj9vXfmnU6kqjQ/HTuC855LoRxwb4tnX6EDSvRL62YlsJx9Y+o2+TkjYiP8nadd1k1G2CytYyNEAFqQLaaMkNR5TbDffHq75a1s5mfavz+ApVghI0mdNoY= 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 1758621836964491.1239695424098; Tue, 23 Sep 2025 03:03:56 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v0zrP-00046l-Ah; Tue, 23 Sep 2025 06:02:59 -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 1v0zqL-0002w1-Fa for qemu-devel@nongnu.org; Tue, 23 Sep 2025 06:01:53 -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 1v0zpz-0000vr-Hv for qemu-devel@nongnu.org; Tue, 23 Sep 2025 06:01:53 -0400 Received: from mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:cf2d:0:640:140f:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id AE1A78081F; Tue, 23 Sep 2025 13:01:23 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:b38::1:12]) by mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id C1Ug0C0Fha60-NdAweWPs; Tue, 23 Sep 2025 13:01:23 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1758621683; bh=tVt9MTceZxb+Z2P97d76cU/wUeCLYbrndwjIMj44b50=; h=Cc:Message-ID:References:Date:In-Reply-To:Subject:To:From; b=ekxjVH0oHFqQUIEKs4pli785hx6TivY2rvcyMWiIstOjZ4nXcnOB08MRnhPg8p+K6 7Fu18Eb9DgXT3WEGIIjgnvElwWwMg3z5IKObiXdlvdRceeaHfg6n2MEjiA5LzDxGLn 1BL1oOEKRLtdTPnqw3RuRkWlg1ONsbCd/H0jVmWQ= Authentication-Results: mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com Cc: qemu-devel@nongnu.org, philmd@linaro.org, thuth@redhat.com, eblake@redhat.com, michael.roth@amd.com, armbru@redhat.com, farosas@suse.de, peterx@redhat.com, berrange@redhat.com, jasowang@redhat.com, steven.sistare@oracle.com, leiyang@redhat.com, davydov-max@yandex-team.ru, yc-core@yandex-team.ru, vsementsov@yandex-team.ru Subject: [PATCH v6 18/19] tests/functional: add skipWithoutSudo() decorator Date: Tue, 23 Sep 2025 13:01:09 +0300 Message-ID: <20250923100110.70862-19-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250923100110.70862-1-vsementsov@yandex-team.ru> References: <20250923100110.70862-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=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: 1758621839447116600 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 --- 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 c0d1567b14..d1e97f7995 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 @@ -149,3 +150,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 Sun Sep 28 15:28:19 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=1758621803; cv=none; d=zohomail.com; s=zohoarc; b=GMb1EOPasKjeqp+6Ns5+Qqh0Hte5aHt8NWKL87qzmGi51jdWGPpwPUovbsgr/N7iY49p74TvrLi6mumk8MPgoPcZPOGqpxMn2bfwqAlQk91nIMpdpHIejvNEMlvQ9vTVDK26IwR1ObXVCAqizo2hfnKEtl4w1iOpGKg0BADnQVs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758621803; 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=93Nacz31F3vYWBwTltKjooVc2hmLufJ+L0mCrokfsvE=; b=cwHwMJS8D6QYLtyg0PqkXU9WDHGNyscZKp30ydOpM1+OgZI2id05zKZsvDXlcNoDGxpXCn/tp0n/G6Ty2ex8gxZMdnfPNaaSHAnLthN7854B9PNB4Btc00t2oNz21s+dpTEZZCPdmqpQHJhc+37CGbvSazs6Q4v+VA9MOp4YRwQ= 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 1758621803267811.3706218237724; Tue, 23 Sep 2025 03:03:23 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v0zqq-0003ZO-M7; Tue, 23 Sep 2025 06:02:24 -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 1v0zqH-0002tf-Q6 for qemu-devel@nongnu.org; Tue, 23 Sep 2025 06:01:51 -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 1v0zpx-0000vq-EK for qemu-devel@nongnu.org; Tue, 23 Sep 2025 06:01:49 -0400 Received: from mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:cf2d:0:640:140f:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id 85895804AB; Tue, 23 Sep 2025 13:01:24 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:b38::1:12]) by mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id C1Ug0C0Fha60-NS8w6Lav; Tue, 23 Sep 2025 13:01:23 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1758621683; bh=93Nacz31F3vYWBwTltKjooVc2hmLufJ+L0mCrokfsvE=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=L9wwfGdQwpwPRwMY+doCDjbxhuOcZ9d2P3XIU1WdwOC0Kqe4P+39DgI7gIdDXLuMd D/6D03McB86Q7rm2UADmDLKBVkcZalMThK9sN7FQHxpq0c2OKTDFRQzWdxE7zLrvde WKFKGWQsU0FPH7N7guHqbRfR6A5WewSxssv3HenQ= Authentication-Results: mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com Cc: qemu-devel@nongnu.org, philmd@linaro.org, thuth@redhat.com, eblake@redhat.com, michael.roth@amd.com, armbru@redhat.com, farosas@suse.de, peterx@redhat.com, berrange@redhat.com, jasowang@redhat.com, steven.sistare@oracle.com, leiyang@redhat.com, davydov-max@yandex-team.ru, yc-core@yandex-team.ru, vsementsov@yandex-team.ru Subject: [PATCH v6 19/19] tests/functional: add test_x86_64_tap_migration Date: Tue, 23 Sep 2025 13:01:10 +0300 Message-ID: <20250923100110.70862-20-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250923100110.70862-1-vsementsov@yandex-team.ru> References: <20250923100110.70862-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: 1758621804110116600 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 --- tests/functional/test_x86_64_tap_migration.py | 344 ++++++++++++++++++ 1 file changed, 344 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..5337df8aff --- /dev/null +++ b/tests/functional/test_x86_64_tap_migration.py @@ -0,0 +1,344 @@ +#!/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_MAC =3D "e6:1d:44:b5:03:5d" + + +def del_tap() -> None: + run( + ["sudo", "ip", "tuntap", "del", TAP_ID, "mode", "tap", "multi_queu= e"], + check=3DTrue, + ) + + +def init_tap() -> None: + run( + ["sudo", "ip", "tuntap", "add", "dev", TAP_ID, "mode", "tap", "mul= ti_queue"], + check=3DTrue, + ) + run(["sudo", "ip", "link", "set", "dev", TAP_ID, "address", TAP_MAC], = check=3DTrue) + run(["sudo", "ip", "addr", "add", HOST_IP_MASK, "dev", TAP_ID], check= =3DTrue) + run(["sudo", "ip", "link", "set", TAP_ID, "up"], check=3DTrue) + + +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() + + 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: disconnec= t: {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): + 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=3Dcdr= om,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) + self.add_virtio_net(vm, vhost) + + def add_virtio_net(self, vm, vhost: bool): + netdev_params =3D { + "id": "netdev.1", + "vhost": vhost, + "type": "tap", + "ifname": "tap0", + "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): + capabilities =3D [ + {"capability": "events", "state": True}, + {"capability": "x-ignore-shared", "state": True}, + ] + vm.cmd("migrate-set-capabilities", {"capabilities": capabilities}) + 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): + 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() + + self.prepare_and_launch_vm(shm_path, vhost) + 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=3D= target_vm) + + 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) + + 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) + + +if __name__ =3D=3D "__main__": + LinuxKernelTest.main() --=20 2.48.1