From nobody Sat Nov 15 05:36:57 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=1755526189; cv=none; d=zohomail.com; s=zohoarc; b=OEcLbbHjsymFSuATDKK4a7uCs6NyQwc/HHaQikhPVQxPjh6oAfzo/ZXnmL95ysBeaS2675asWY1+5hU5lF/LGoSnwq7zoruTiCDx902fgj3B3oYNlQMAaF4kZj0D9XrBh0SvLqRSuKFkT25YNOZSY/wdWtEK3+zSWtivUYrfnpw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1755526189; 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=BU/7VLO6Y70tM+utVxCmAAVDYUvmt005RnlKNFWkZP8=; b=UrsBBxXVXTwwZjv3MvzNYA3qjpGVLx1kSpO1VWVnyJWpN5VvWDIKWoMx5FGuGPXoahYii+q5791U0FWOq2t7ny9YUNttgTP5e01fXHBfxu+8bMArHkIDyUunIVo5zaZSy/SXM82or3CZgSboLhtrDUTHrHvPTW6J1et9MwUz2lQ= 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 1755526189680888.0670377115619; Mon, 18 Aug 2025 07:09:49 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uo0Vn-0001La-Jd; Mon, 18 Aug 2025 10:06: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 1uo0Vl-0001Jy-51 for qemu-devel@nongnu.org; Mon, 18 Aug 2025 10:06:57 -0400 Received: from forwardcorp1b.mail.yandex.net ([178.154.239.136]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uo0Vh-0002B4-EZ for qemu-devel@nongnu.org; Mon, 18 Aug 2025 10:06:56 -0400 Received: from mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net [IPv6:2a02:6b8:c21:2d8b:0:640:7d49:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTPS id D74BB807B3; Mon, 18 Aug 2025 17:06:47 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:b25::1:17]) by mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id k6RC4003YeA0-U1eGjacl; Mon, 18 Aug 2025 17:06:47 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1755526007; bh=BU/7VLO6Y70tM+utVxCmAAVDYUvmt005RnlKNFWkZP8=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=exlAvelVPk/iyajEVqPav7czDqDSq9EkKAEOdPSuuuG12C5daRENCjgB9n5Qclvq8 h2h7DbM/KnNg4/Th1Q0/4rWNI3Esy3lUdoEF8Jun+KxMRYimTMpIUpOX6NOPCjZ+zT UD9oBADqcSMKlITopyJzvLBymEb3z7yMDJ5teN/E= Authentication-Results: mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: jasowang@redhat.com Cc: qemu-devel@nongnu.org, vsementsov@yandex-team.ru Subject: [PATCH 01/19] net/tap: net_init_tap_one(): add return value Date: Mon, 18 Aug 2025 17:06:27 +0300 Message-ID: <20250818140645.27904-2-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250818140645.27904-1-vsementsov@yandex-team.ru> References: <20250818140645.27904-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=178.154.239.136; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1b.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_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 Precedence: list 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: 1755526191509124100 Content-Type: text/plain; charset="utf-8" To avoid error propagation, let's follow common recommendation to use return value together with errp. Signed-off-by: Vladimir Sementsov-Ogievskiy --- net/tap.c | 55 +++++++++++++++++++++++++------------------------------ 1 file changed, 25 insertions(+), 30 deletions(-) diff --git a/net/tap.c b/net/tap.c index f7df702f97..531ef75e91 100644 --- a/net/tap.c +++ b/net/tap.c @@ -680,11 +680,11 @@ static int net_tap_init(const NetdevTapOptions *tap, = int *vnet_hdr, =20 #define MAX_TAP_QUEUES 1024 =20 -static void net_init_tap_one(const NetdevTapOptions *tap, NetClientState *= peer, - const char *model, const char *name, - const char *ifname, const char *script, - const char *downscript, const char *vhostfdna= me, - int vnet_hdr, int fd, Error **errp) +static int net_init_tap_one(const NetdevTapOptions *tap, NetClientState *p= eer, + const char *model, const char *name, + const char *ifname, const char *script, + const char *downscript, const char *vhostfdnam= e, + int vnet_hdr, int fd, Error **errp) { Error *err =3D NULL; TAPState *s =3D net_tap_fd_init(peer, model, name, fd, vnet_hdr); @@ -765,10 +765,11 @@ static void net_init_tap_one(const NetdevTapOptions *= tap, NetClientState *peer, goto failed; } =20 - return; + return 0; =20 failed: qemu_del_net_client(&s->nc); + return -1; } =20 static int get_fds(char *str, char *fds[], int max) @@ -805,7 +806,6 @@ int net_init_tap(const Netdev *netdev, const char *name, /* for the no-fd, no-helper case */ const char *script; const char *downscript; - Error *err =3D NULL; const char *vhostfdname; char ifname[128]; int ret =3D 0; @@ -852,12 +852,10 @@ int net_init_tap(const Netdev *netdev, const char *na= me, return -1; } =20 - net_init_tap_one(tap, peer, "tap", name, NULL, - script, downscript, - vhostfdname, vnet_hdr, fd, &err); - if (err) { - error_propagate(errp, err); - close(fd); + ret =3D net_init_tap_one(tap, peer, "tap", name, NULL, + script, downscript, + vhostfdname, vnet_hdr, fd, errp); + if (ret < 0) { return -1; } } else if (tap->fds) { @@ -915,12 +913,11 @@ int net_init_tap(const Netdev *netdev, const char *na= me, goto free_fail; } =20 - net_init_tap_one(tap, peer, "tap", name, ifname, - script, downscript, - tap->vhostfds ? vhost_fds[i] : NULL, - vnet_hdr, fd, &err); - if (err) { - error_propagate(errp, err); + ret =3D net_init_tap_one(tap, peer, "tap", name, ifname, + script, downscript, + tap->vhostfds ? vhost_fds[i] : NULL, + vnet_hdr, fd, errp); + if (ret < 0) { ret =3D -1; goto free_fail; } @@ -961,11 +958,10 @@ free_fail: return -1; } =20 - net_init_tap_one(tap, peer, "bridge", name, ifname, - script, downscript, vhostfdname, - vnet_hdr, fd, &err); - if (err) { - error_propagate(errp, err); + ret =3D net_init_tap_one(tap, peer, "bridge", name, ifname, + script, downscript, vhostfdname, + vnet_hdr, fd, errp); + if (ret < 0) { close(fd); return -1; } @@ -1006,12 +1002,11 @@ free_fail: } } =20 - net_init_tap_one(tap, peer, "tap", name, ifname, - i >=3D 1 ? "no" : script, - i >=3D 1 ? "no" : downscript, - vhostfdname, vnet_hdr, fd, &err); - if (err) { - error_propagate(errp, err); + ret =3D net_init_tap_one(tap, peer, "tap", name, ifname, + i >=3D 1 ? "no" : script, + i >=3D 1 ? "no" : downscript, + vhostfdname, vnet_hdr, fd, errp); + if (ret < 0) { close(fd); return -1; } --=20 2.48.1 From nobody Sat Nov 15 05:36:57 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=1755526130; cv=none; d=zohomail.com; s=zohoarc; b=lcmhaAu4B5s8WksR4TguWg2PfYMBXoEGkUZBTwMUuWy9H9jJ1AZzxsGm3UGMZpliePY7fv0Npk5wtPVUK7ST9FIe6EQV/vvyar2+sj38qY/3FNXiSXi15xXOjmkUv/Jgg1GE3ZZ2wNFl7V8WjOzhTIRJAQs/mUVfa5+A+6TGRJ0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1755526130; 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=XZ907GoTMSukCC5aa7hwWOOYOieaiLj2RzPVyep6PXA=; b=HYit9YHEgv/Lyg+P8UYQNfpB0Al9ir3SOupIsDdRhBPonL3dpmaXPLkaQcVS9H8o/+ugL+EX6rNaRdySLGzCuRUJPpkNMw3m7Jbh90bfinW1oRRHAJgkSGCbtZt7XW5s9EubBSiorSYWRV3UnPo6iiGyfY4e+3MEPDyTR7mEdHU= 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 1755526130850683.2602391891426; Mon, 18 Aug 2025 07:08:50 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uo0Vn-0001Lt-SY; Mon, 18 Aug 2025 10:06: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 1uo0Vl-0001Jv-3x for qemu-devel@nongnu.org; Mon, 18 Aug 2025 10:06:57 -0400 Received: from forwardcorp1b.mail.yandex.net ([178.154.239.136]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uo0Vh-0002B6-Fu for qemu-devel@nongnu.org; Mon, 18 Aug 2025 10:06:56 -0400 Received: from mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net [IPv6:2a02:6b8:c21:2d8b:0:640:7d49:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTPS id 31DD2807B5; Mon, 18 Aug 2025 17:06:48 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:b25::1:17]) by mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id k6RC4003YeA0-1X2frNWW; Mon, 18 Aug 2025 17:06:47 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1755526007; bh=XZ907GoTMSukCC5aa7hwWOOYOieaiLj2RzPVyep6PXA=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=Pe7PIoEh3unIECyzf7qdc3vzDM1IrZegliZ471idyqg+AFh6dRd0I8g35UeIFfcK8 d5MEpf1cKQCfxRxi/vzU197ohAO+s3OM86le/07W2CHPXlOCGqO0D0Q4vdHjbMdLWg +CETGl1+rv0U5cOCTkKddVnpeLAw4K5tsDQNbhiQ= Authentication-Results: mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: jasowang@redhat.com Cc: qemu-devel@nongnu.org, vsementsov@yandex-team.ru Subject: [PATCH 02/19] net/tap: add set_fd_nonblocking() helper Date: Mon, 18 Aug 2025 17:06:28 +0300 Message-ID: <20250818140645.27904-3-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250818140645.27904-1-vsementsov@yandex-team.ru> References: <20250818140645.27904-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=178.154.239.136; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1b.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_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 Precedence: list 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: 1755526131661116600 Content-Type: text/plain; charset="utf-8" Signed-off-by: Vladimir Sementsov-Ogievskiy --- net/tap.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/net/tap.c b/net/tap.c index 531ef75e91..ba2731ee8a 100644 --- a/net/tap.c +++ b/net/tap.c @@ -609,6 +609,18 @@ static int net_bridge_run_helper(const char *helper, c= onst char *bridge, } } =20 +static bool set_fd_nonblocking(int fd, const char *note, Error **errp) +{ + bool ok =3D g_unix_set_fd_nonblocking(fd, true, NULL); + + if (!ok) { + error_setg_errno(errp, errno, "Failed to set fd %d (%s) nonblockin= g", + fd, note); + } + + return ok; +} + int net_init_bridge(const Netdev *netdev, const char *name, NetClientState *peer, Error **errp) { @@ -627,10 +639,10 @@ int net_init_bridge(const Netdev *netdev, const char = *name, return -1; } =20 - if (!g_unix_set_fd_nonblocking(fd, true, NULL)) { - error_setg_errno(errp, errno, "Failed to set FD nonblocking"); + if (!set_fd_nonblocking(fd, name, errp)) { return -1; } + vnet_hdr =3D tap_probe_vnet_hdr(fd, errp); if (vnet_hdr < 0) { close(fd); @@ -729,9 +741,7 @@ static int net_init_tap_one(const NetdevTapOptions *tap= , NetClientState *peer, error_propagate(errp, err); goto failed; } - if (!g_unix_set_fd_nonblocking(vhostfd, true, NULL)) { - error_setg_errno(errp, errno, "%s: Can't use file descript= or %d", - name, fd); + if (!set_fd_nonblocking(vhostfd, vhostfdname, errp)) { goto failed; } } else { @@ -741,8 +751,7 @@ static int net_init_tap_one(const NetdevTapOptions *tap= , NetClientState *peer, "tap: open vhost char device failed"); goto failed; } - if (!g_unix_set_fd_nonblocking(vhostfd, true, NULL)) { - error_setg_errno(errp, errno, "Failed to set FD nonblockin= g"); + if (!set_fd_nonblocking(vhostfd, "opened /dev/vhost-net", errp= )) { goto failed; } } @@ -839,9 +848,7 @@ int net_init_tap(const Netdev *netdev, const char *name, return -1; } =20 - if (!g_unix_set_fd_nonblocking(fd, true, NULL)) { - error_setg_errno(errp, errno, "%s: Can't use file descriptor %= d", - name, fd); + if (!set_fd_nonblocking(fd, tap->fd, errp)) { close(fd); return -1; } @@ -893,10 +900,8 @@ int net_init_tap(const Netdev *netdev, const char *nam= e, goto free_fail; } =20 - if (!g_unix_set_fd_nonblocking(fd, true, NULL)) { + if (!set_fd_nonblocking(fd, fds[i], errp)) { ret =3D -1; - error_setg_errno(errp, errno, "%s: Can't use file descript= or %d", - name, fd); goto free_fail; } =20 @@ -948,8 +953,7 @@ free_fail: return -1; } =20 - if (!g_unix_set_fd_nonblocking(fd, true, NULL)) { - error_setg_errno(errp, errno, "Failed to set FD nonblocking"); + if (!set_fd_nonblocking(fd, name, errp)) { return -1; } vnet_hdr =3D tap_probe_vnet_hdr(fd, errp); --=20 2.48.1 From nobody Sat Nov 15 05:36:57 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=1755526073; cv=none; d=zohomail.com; s=zohoarc; b=f4s1sNTc68Obyy5eRmfcmEceemS9j8hOCOHuLvL3WT36UVMyUUXfrY3AZttLnBCUVT0/GSH0Ia6U48DaiiAgob+CWT4vogs6NZyhBOqEok5e6huGRGZI4Clb2vVFIm3ojc6X46lMf49eAsIg785ZG0nJQ/LKqGppcLP1GIxYhf4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1755526073; 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=tqSxf8tU4NUdXhUe8SOdly4Zaf5Ojq1JY3s5SFqYwUU=; b=Jk9rZykiQOwBe9Mi4wZzoq91F21dwylH8BDOWJ1gGq7KFj6Y+NAJ9Bzhak/CiARj8w/UdzIek4q3G8PIHBMgwTn7j1p2vxHSqbrPrbkrD6LG/pTh/7Y3N4c4VGirNoP/+YB2VDc0U4RRRKx5DpndXBbdL7VqhFBCk2F9LqynAYs= 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 175552607326929.424535092275164; Mon, 18 Aug 2025 07:07:53 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uo0Vp-0001Mi-VM; Mon, 18 Aug 2025 10:07:01 -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 1uo0Vm-0001Kw-As for qemu-devel@nongnu.org; Mon, 18 Aug 2025 10:06:58 -0400 Received: from forwardcorp1b.mail.yandex.net ([178.154.239.136]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uo0Vh-0002B7-Gj for qemu-devel@nongnu.org; Mon, 18 Aug 2025 10:06:57 -0400 Received: from mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net [IPv6:2a02:6b8:c21:2d8b:0:640:7d49:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTPS id 819C6807A7; Mon, 18 Aug 2025 17:06:48 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:b25::1:17]) by mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id k6RC4003YeA0-HqCL0C3S; Mon, 18 Aug 2025 17:06:48 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1755526008; bh=tqSxf8tU4NUdXhUe8SOdly4Zaf5Ojq1JY3s5SFqYwUU=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=apuJ8u/U0+4+H09iGqm4QYG3vRVCj6lsmR93SRY8dg1j/1u7pjokuGrFtUsX11Oyf tAyBTxumICSMMDCS4xBFpU4x1sNcAQYQuBx559xuHl+wgr8uIZLxU1uoZabBWOx0rE kp7Qlwlsl3tRCX3AbRcsqVZjukVLKIfFaSHE3Nfw= Authentication-Results: mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: jasowang@redhat.com Cc: qemu-devel@nongnu.org, vsementsov@yandex-team.ru Subject: [PATCH 03/19] net/tap: tap_set_sndbuf(): add return value Date: Mon, 18 Aug 2025 17:06:29 +0300 Message-ID: <20250818140645.27904-4-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250818140645.27904-1-vsementsov@yandex-team.ru> References: <20250818140645.27904-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=178.154.239.136; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1b.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_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 Precedence: list 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: 1755526074226124100 Content-Type: text/plain; charset="utf-8" Follow common recommendations to avoid error propagation. Signed-off-by: Vladimir Sementsov-Ogievskiy --- net/tap-linux.c | 5 ++++- net/tap.c | 4 +--- net/tap_int.h | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/net/tap-linux.c b/net/tap-linux.c index 22ec2f45d2..3625379c58 100644 --- a/net/tap-linux.c +++ b/net/tap-linux.c @@ -140,7 +140,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) +int tap_set_sndbuf(int fd, const NetdevTapOptions *tap, Error **errp) { int sndbuf; =20 @@ -154,7 +154,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 -1; } + + return 0; } =20 int tap_probe_vnet_hdr(int fd, Error **errp) diff --git a/net/tap.c b/net/tap.c index ba2731ee8a..0258ac8574 100644 --- a/net/tap.c +++ b/net/tap.c @@ -702,9 +702,7 @@ static int net_init_tap_one(const NetdevTapOptions *tap= , NetClientState *peer, TAPState *s =3D net_tap_fd_init(peer, model, name, fd, vnet_hdr); int vhostfd; =20 - tap_set_sndbuf(s->fd, tap, &err); - if (err) { - error_propagate(errp, err); + if (tap_set_sndbuf(s->fd, tap, errp) < 0) { goto failed; } =20 diff --git a/net/tap_int.h b/net/tap_int.h index 8857ff299d..d21acf8486 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); +int 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 Sat Nov 15 05:36:57 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=1755526071; cv=none; d=zohomail.com; s=zohoarc; b=mvbGe4lUbPZCpXFAogjTgeDD2tMFmHdvH5W1cer8HEe9ZqNBWjzsy0v8qEhtUdzlMQ7SjHPatu61pjeD8vKsfKe9Bmu+M9BYiA/AahGBJLIuhybKnzYrXohT8sVTiYy6zLRUV0nq7HAEX8hSWJqI1Uqo9JSJ72wN1nojySALTOQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1755526071; 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=mGSpVxvJRA2C4GRlukYvMe4WDcL+rqbKh6znjwet/FA=; b=doIdkURn29zXTHjKaxjAXxwUQCe62vTPWSWp5DNxuz9rOWQ4OAhu7pHoq9EE5Wpkn8/kPMHAK48ZhqdjERT+ajTnqL4wt3017UqIpVg93WQodQup20wl7IQDW73j0+ddguWbrVvWUb6VxmEpmo/p0q9BOUACu3I54DefM5O7Ykg= 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 1755526070862198.76737203606433; Mon, 18 Aug 2025 07:07:50 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uo0Vq-0001Oe-6Z; Mon, 18 Aug 2025 10:07:02 -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 1uo0Vm-0001Kk-5Q for qemu-devel@nongnu.org; Mon, 18 Aug 2025 10:06:58 -0400 Received: from forwardcorp1b.mail.yandex.net ([178.154.239.136]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uo0Vh-0002B8-DQ for qemu-devel@nongnu.org; Mon, 18 Aug 2025 10:06:57 -0400 Received: from mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net [IPv6:2a02:6b8:c21:2d8b:0:640:7d49:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTPS id DA0C0807AB; Mon, 18 Aug 2025 17:06:48 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:b25::1:17]) by mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id k6RC4003YeA0-cztzgLN8; Mon, 18 Aug 2025 17:06:48 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1755526008; bh=mGSpVxvJRA2C4GRlukYvMe4WDcL+rqbKh6znjwet/FA=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=g/g2x38m8Ig09WxYwnOgqzbW1CtLcHu/JGOYIoza6//dpJtJXzp/PhwAMHTIr9esj 4oX2CSG2K/vEtThilnKwzIqLoAQqfnfFIvm4FThIs8O6lxsSXNweQa1vNmlJ9kJTsn Tjc0KwpF4cHsoW6WPC6ip6qy5F6hR+nOfMEYStr8= Authentication-Results: mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: jasowang@redhat.com Cc: qemu-devel@nongnu.org, vsementsov@yandex-team.ru Subject: [PATCH 04/19] net/tap: net_init_tap_one(): drop extra error propagation Date: Mon, 18 Aug 2025 17:06:30 +0300 Message-ID: <20250818140645.27904-5-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250818140645.27904-1-vsementsov@yandex-team.ru> References: <20250818140645.27904-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=178.154.239.136; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1b.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_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 Precedence: list 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: 1755526072999116600 Content-Type: text/plain; charset="utf-8" Signed-off-by: Vladimir Sementsov-Ogievskiy --- net/tap.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/net/tap.c b/net/tap.c index 0258ac8574..58c3318b1c 100644 --- a/net/tap.c +++ b/net/tap.c @@ -698,7 +698,6 @@ static int net_init_tap_one(const NetdevTapOptions *tap= , NetClientState *peer, const char *downscript, const char *vhostfdnam= e, int vnet_hdr, int fd, Error **errp) { - Error *err =3D NULL; TAPState *s =3D net_tap_fd_init(peer, model, name, fd, vnet_hdr); int vhostfd; =20 @@ -734,9 +733,8 @@ static int net_init_tap_one(const NetdevTapOptions *tap= , 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 (!set_fd_nonblocking(vhostfd, vhostfdname, errp)) { --=20 2.48.1 From nobody Sat Nov 15 05:36:57 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=1755526075; cv=none; d=zohomail.com; s=zohoarc; b=h5CWjntKwFzE6lv8R9TeYMSYyECNOwh6N+4PFl1PmY3SZ5Ay5svDW2aL+v7fZ2jz8VB2bkcEYdhEZ2mS/7HGIfGIWiun7oJC79vLuozKYiHMPbubCHxWXez1nC/hRNzOV6vAZjWGAyputh2aST4cZr/YuM0yJg8NRvYmA/I8YBY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1755526075; 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=cRcMgIZiYjlHYEaFWbqF61HRn8FG2JLDckGn87d2yNY=; b=hRDwNKjDotKIzySXRXbzbSXgtEMKE6LvLv9R+W5NvLVGCbK8HwBe5diNs8H9xu47SPDLSXU8b7FP7f5OyAKy7Di1KnBzGuY5TVCCFTzsbpHar2teWlZoyT4ZZ9O07IP26tSNTofa0Myc4NJ0grcWmbcS1wOavfijTZ3ha9LSiho= 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 17555260756931000.7409460692073; Mon, 18 Aug 2025 07:07:55 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uo0Vp-0001MS-4e; Mon, 18 Aug 2025 10:07:01 -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 1uo0Vm-0001Kj-25 for qemu-devel@nongnu.org; Mon, 18 Aug 2025 10:06:58 -0400 Received: from forwardcorp1b.mail.yandex.net ([178.154.239.136]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uo0Vh-0002B9-RT for qemu-devel@nongnu.org; Mon, 18 Aug 2025 10:06:57 -0400 Received: from mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net [IPv6:2a02:6b8:c21:2d8b:0:640:7d49:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTPS id 32E05807BD; Mon, 18 Aug 2025 17:06:49 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:b25::1:17]) by mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id k6RC4003YeA0-GUdSWjEJ; Mon, 18 Aug 2025 17:06:48 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1755526008; bh=cRcMgIZiYjlHYEaFWbqF61HRn8FG2JLDckGn87d2yNY=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=V7huw/W0N37AK1oJpvAh2hSdlwvP58LoJZqBGLbhHJt+eGDUJMQSoFgPGxo68tiza 043/oDmRxKPxNoGKm/dwMqKpsF94pCqemEaX7cZcobn969/pJy3q4kOYKF7P7hq1zw AuyWcf7ww99TY10l3P1tDd/vtPYLcrOctziqHpIg= Authentication-Results: mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: jasowang@redhat.com Cc: qemu-devel@nongnu.org, vsementsov@yandex-team.ru Subject: [PATCH 05/19] net/tap: net_init_tap_one(): move parameter checking earlier Date: Mon, 18 Aug 2025 17:06:31 +0300 Message-ID: <20250818140645.27904-6-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250818140645.27904-1-vsementsov@yandex-team.ru> References: <20250818140645.27904-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=178.154.239.136; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1b.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_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 Precedence: list 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: 1755526077019116600 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 --- net/tap.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/net/tap.c b/net/tap.c index 58c3318b1c..3fe99ef63f 100644 --- a/net/tap.c +++ b/net/tap.c @@ -765,9 +765,6 @@ static int net_init_tap_one(const NetdevTapOptions *tap= , 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 0; @@ -829,6 +826,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 Sat Nov 15 05:36:57 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=1755526107; cv=none; d=zohomail.com; s=zohoarc; b=jfZIjP6rFbcoQm0THthATE8sEhCIPXvsAACtXqSXkU4R3Rxge/fpVzAsRBk/vbFjIsiGgQxWPBqMbJbCuDIjGyyNNgsIodz9mJ6HYtUfJvUoycPOeui9RWVQ1Yoh4thxX8G8Zb+Lg+NaBUyzazX/AvbGQXFOs7qbE4IL+Z+/NM4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1755526107; 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=1Swq7dYJJnBLISq3vORSp+LW7aF5QGfIP3wBCjdR6cY=; b=NdOwHPc0wN4abLk4UxrW4I8dCpb0Zf6D55icQGCBkp1YegLD9NdpgYUhaKQ7z0h/cBA5XPp3OXvJpx4uAOd4WN4a6QWPqbzHmwMkSiRXpZx8Gfj9S4T+/wBYaylnUHjNj7Lq/fwU+ex6ZTFX+BSO+SwC1r/C5iSvMcs0b+L2czw= 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 175552610636828.24196606114026; Mon, 18 Aug 2025 07:08:26 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uo0Vn-0001Ls-RO; Mon, 18 Aug 2025 10:06: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 1uo0Vl-0001Jw-4y for qemu-devel@nongnu.org; Mon, 18 Aug 2025 10:06:57 -0400 Received: from forwardcorp1b.mail.yandex.net ([178.154.239.136]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uo0Vh-0002BA-Jv for qemu-devel@nongnu.org; Mon, 18 Aug 2025 10:06:56 -0400 Received: from mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net [IPv6:2a02:6b8:c21:2d8b:0:640:7d49:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTPS id 80110807C0; Mon, 18 Aug 2025 17:06:49 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:b25::1:17]) by mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id k6RC4003YeA0-8JerLNma; Mon, 18 Aug 2025 17:06:49 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1755526009; bh=1Swq7dYJJnBLISq3vORSp+LW7aF5QGfIP3wBCjdR6cY=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=FImiNkpP00jxAQX3Ho6qSq84MXpfSn4fqeOjd5kS+O/nlOaRDKoD4X7d1ERQXD9bS y9ChI7WsHCufiFPuniRjHzy+DT2ntTGvvAM46+HbeHor2n8LAkdiBdl4RVnWdgQ7ne 4JHuWHPjNT3upjxgC1s071INV+hGfzIihslk9LDc= Authentication-Results: mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: jasowang@redhat.com Cc: qemu-devel@nongnu.org, vsementsov@yandex-team.ru Subject: [PATCH 06/19] net/tap: net_init_tap(): refactor parameter checking Date: Mon, 18 Aug 2025 17:06:32 +0300 Message-ID: <20250818140645.27904-7-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250818140645.27904-1-vsementsov@yandex-team.ru> References: <20250818140645.27904-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=178.154.239.136; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1b.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_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 Precedence: list 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: 1755526109456116600 Content-Type: text/plain; charset="utf-8" Unite duplicated checks of different code paths. Signed-off-by: Vladimir Sementsov-Ogievskiy --- net/tap.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/net/tap.c b/net/tap.c index 3fe99ef63f..042f9fd01a 100644 --- a/net/tap.c +++ b/net/tap.c @@ -831,12 +831,17 @@ int net_init_tap(const Netdev *netdev, const char *na= me, return -1; } =20 + if ((tap->fd || tap->fds || tap->helper) && + (tap->ifname || tap->script || tap->downscript || + tap->has_vnet_hdr || tap->has_queues)) { + error_setg(errp, "ifname=3D, script=3D, downscript=3D, vnet_hdr=3D= , " + "queues=3D, are invalid with fd=3D/fds=3D/helper=3D"); + return -1; + } + if (tap->fd) { - if (tap->ifname || tap->script || tap->downscript || - tap->has_vnet_hdr || tap->helper || tap->has_queues || - tap->fds || tap->vhostfds) { - error_setg(errp, "ifname=3D, script=3D, downscript=3D, vnet_hd= r=3D, " - "helper=3D, queues=3D, fds=3D, and vhostfds=3D " + if (tap->helper || tap->fds || tap->vhostfds) { + error_setg(errp, "helper=3D, fds=3D, and vhostfds=3D " "are invalid with fd=3D"); return -1; } @@ -868,12 +873,8 @@ int net_init_tap(const Netdev *netdev, const char *nam= e, char **vhost_fds; int nfds =3D 0, nvhosts =3D 0; =20 - if (tap->ifname || tap->script || tap->downscript || - tap->has_vnet_hdr || tap->helper || tap->has_queues || - tap->vhostfd) { - error_setg(errp, "ifname=3D, script=3D, downscript=3D, vnet_hd= r=3D, " - "helper=3D, queues=3D, and vhostfd=3D " - "are invalid with fds=3D"); + if (tap->helper || tap->vhostfd) { + error_setg(errp, "helper=3D and vhostfd=3D are invalid with fd= s=3D"); return -1; } =20 @@ -937,10 +938,8 @@ free_fail: g_free(vhost_fds); return ret; } else if (tap->helper) { - if (tap->ifname || tap->script || tap->downscript || - tap->has_vnet_hdr || tap->has_queues || tap->vhostfds) { - error_setg(errp, "ifname=3D, script=3D, downscript=3D, vnet_hd= r=3D, " - "queues=3D, and vhostfds=3D are invalid with helper= =3D"); + if (tap->vhostfds) { + error_setg(errp, "vhostfds=3D is invalid with helper=3D"); return -1; } =20 --=20 2.48.1 From nobody Sat Nov 15 05:36:57 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=1755526096; cv=none; d=zohomail.com; s=zohoarc; b=PA5gHweAcUxtOi+jkClOHRFeEpLo2M0YxpXLy6xJYWS3Y/UR4peX204I4lLglF4RL3x/UxwjSmga3CvmFFHiX9lLqlYJyCM6XJvXC4jA8Le+/TQcZikKzQ4F/O2CnkI0LDUFZ0kGmO/hI1vyzqd/CukxD2qoxkqOhlhJ7UyqygU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1755526096; 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=dzrHb42O8oLXErFY753Ty76lZhfPJm8FI957hSrKvWE=; b=UzZwOmulWVnyPxwA88Q4XN9FQ018sZNEnRigOw1saIZAIAVICRXRT3NwTd6bdKVtH/IvHXLr5gZNVKXf42gw/eY4ZvxAQB4PFv/voZdN2ReIE92ZB4ZxGZKDEe54rCf5zRmgKrJiq4tI1y4lBqfKKvM/a1TCIKgkMmFhiHv5038= 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 175552609596237.29361928111359; Mon, 18 Aug 2025 07:08:15 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uo0Vp-0001Mg-Jp; Mon, 18 Aug 2025 10:07:01 -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 1uo0Vm-0001Ki-0v for qemu-devel@nongnu.org; Mon, 18 Aug 2025 10:06:58 -0400 Received: from forwardcorp1b.mail.yandex.net ([178.154.239.136]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uo0Vh-0002BG-Gf for qemu-devel@nongnu.org; Mon, 18 Aug 2025 10:06:57 -0400 Received: from mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net [IPv6:2a02:6b8:c21:2d8b:0:640:7d49:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTPS id D0D9E807C1; Mon, 18 Aug 2025 17:06:49 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:b25::1:17]) by mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id k6RC4003YeA0-6aiJhMKd; Mon, 18 Aug 2025 17:06:49 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1755526009; bh=dzrHb42O8oLXErFY753Ty76lZhfPJm8FI957hSrKvWE=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=T+BR+guCTKjushJwdeArJUY7q5ljg0kBCYAGu3Nqp/Iz+LgiFMtFSkrvR+JCBVLho 3aEMTpUvu4xj/c0IrPUTSbfRADA1I1h1vjPT6bwpUAxcnmTjibLNNwj/wk5GC9ztoI 2WDGAG5kcu7cYu7u801pckTyQRvZl/Fe/qCVlam8= Authentication-Results: mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: jasowang@redhat.com Cc: qemu-devel@nongnu.org, vsementsov@yandex-team.ru Subject: [PATCH 07/19] net/tap: net_init_tap(): drop extra variable vhostfdname Date: Mon, 18 Aug 2025 17:06:33 +0300 Message-ID: <20250818140645.27904-8-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250818140645.27904-1-vsementsov@yandex-team.ru> References: <20250818140645.27904-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=178.154.239.136; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1b.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_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 Precedence: list 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: 1755526097329116600 Content-Type: text/plain; charset="utf-8" Signed-off-by: Vladimir Sementsov-Ogievskiy --- net/tap.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/net/tap.c b/net/tap.c index 042f9fd01a..ade58826c8 100644 --- a/net/tap.c +++ b/net/tap.c @@ -808,14 +808,12 @@ int net_init_tap(const Netdev *netdev, const char *na= me, /* for the no-fd, no-helper case */ const char *script; const char *downscript; - const char *vhostfdname; char ifname[128]; int ret =3D 0; =20 assert(netdev->type =3D=3D NET_CLIENT_DRIVER_TAP); 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 @@ -864,7 +862,7 @@ int net_init_tap(const Netdev *netdev, const char *name, =20 ret =3D net_init_tap_one(tap, peer, "tap", name, NULL, script, downscript, - vhostfdname, vnet_hdr, fd, errp); + tap->vhostfd, vnet_hdr, fd, errp); if (ret < 0) { return -1; } @@ -960,7 +958,7 @@ free_fail: } =20 ret =3D net_init_tap_one(tap, peer, "bridge", name, ifname, - script, downscript, vhostfdname, + script, downscript, tap->vhostfd, vnet_hdr, fd, errp); if (ret < 0) { close(fd); @@ -1006,7 +1004,7 @@ free_fail: ret =3D net_init_tap_one(tap, peer, "tap", name, ifname, i >=3D 1 ? "no" : script, i >=3D 1 ? "no" : downscript, - vhostfdname, vnet_hdr, fd, errp); + tap->vhostfd, vnet_hdr, fd, errp); if (ret < 0) { close(fd); return -1; --=20 2.48.1 From nobody Sat Nov 15 05:36:57 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=1755526047; cv=none; d=zohomail.com; s=zohoarc; b=Q3sxAOBLGX7MzC8A9QZU85FHN6FPYqbGm45g5eRVUN7Xh+Jqb5q3EPVnLOk8ngY/521VuFS+se6pG9ws2xBJISvDoEyiBb1DT95mo4CuoKYu/QIw54fa7L/jhKXqFj6zkAJSyxGjPRGje4N2n+5XY/DyEgOLeV2fjMfMMIdfCeg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1755526047; 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=/jmgRZlvnyx5qMTtkk0yR8vFuAW4SpHDfPYvvSqnSc0=; b=O3d51B/IXeWmQnskVY9qTkwy8YqgS5f9y1hPMxMdfV3SRQ/KpHY8RM6viJqPU0N73WH3payM3XGCa7Qf6y61aH8xkZesL8B58uNWgKWXBLydKMjhQCKgOWYKakQjDTQ50cLwn/O4bF+v6baLaKLYJXsOWbMIrH/E1+UYn7CLTmE= 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 1755526047235488.70104215375477; Mon, 18 Aug 2025 07:07:27 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uo0Vm-0001LH-Vs; Mon, 18 Aug 2025 10:06: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 1uo0Vk-0001Ji-MO for qemu-devel@nongnu.org; Mon, 18 Aug 2025 10:06:56 -0400 Received: from forwardcorp1b.mail.yandex.net ([178.154.239.136]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uo0Vh-0002BJ-6w for qemu-devel@nongnu.org; Mon, 18 Aug 2025 10:06:56 -0400 Received: from mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net [IPv6:2a02:6b8:c21:2d8b:0:640:7d49:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTPS id 2A802807C6; Mon, 18 Aug 2025 17:06:50 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:b25::1:17]) by mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id k6RC4003YeA0-2Vnf3E4J; Mon, 18 Aug 2025 17:06:49 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1755526009; bh=/jmgRZlvnyx5qMTtkk0yR8vFuAW4SpHDfPYvvSqnSc0=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=I/DDe7Z/skZOSTFBnsbgg2WT8FF9G/2wJdhz5k1SNMJkVnnVtHbEHEZbg2WCUnWhy vI02q9RtHQlfOmsDxTrugjXXCu97vSMyrBjKgVtnnYeGQ1TkwGDax1lQPVkfYsmhHk dPamml5w0Xgk1NtL11SjgdyQelCyhlM3cDinEz/g= Authentication-Results: mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: jasowang@redhat.com Cc: qemu-devel@nongnu.org, vsementsov@yandex-team.ru Subject: [PATCH 08/19] net/tap: move local variables related to the latter case to else branch Date: Mon, 18 Aug 2025 17:06:34 +0300 Message-ID: <20250818140645.27904-9-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250818140645.27904-1-vsementsov@yandex-team.ru> References: <20250818140645.27904-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=178.154.239.136; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1b.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_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 Precedence: list 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: 1755526057142116600 Content-Type: text/plain; charset="utf-8" This makes more obvious, where the variables make sense. Note that ifname, script and downscript variables are not used in net_init_tap_one() for fd/fds/helper cases. Signed-off-by: Vladimir Sementsov-Ogievskiy --- net/tap.c | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/net/tap.c b/net/tap.c index ade58826c8..80ec54f914 100644 --- a/net/tap.c +++ b/net/tap.c @@ -803,19 +803,11 @@ static int get_fds(char *str, char *fds[], int max) int net_init_tap(const Netdev *netdev, const char *name, NetClientState *peer, Error **errp) { - 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; - char ifname[128]; + const NetdevTapOptions *tap =3D &netdev->u.tap; + int fd, vnet_hdr =3D 0, i =3D 0; int ret =3D 0; =20 assert(netdev->type =3D=3D NET_CLIENT_DRIVER_TAP); - tap =3D &netdev->u.tap; - queues =3D tap->has_queues ? tap->queues : 1; - 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. */ @@ -861,7 +853,7 @@ int net_init_tap(const Netdev *netdev, const char *name, } =20 ret =3D net_init_tap_one(tap, peer, "tap", name, NULL, - script, downscript, + NULL, NULL, tap->vhostfd, vnet_hdr, fd, errp); if (ret < 0) { return -1; @@ -915,8 +907,8 @@ int net_init_tap(const Netdev *netdev, const char *name, goto free_fail; } =20 - ret =3D net_init_tap_one(tap, peer, "tap", name, ifname, - script, downscript, + ret =3D net_init_tap_one(tap, peer, "tap", name, NULL, + NULL, NULL, tap->vhostfds ? vhost_fds[i] : NULL, vnet_hdr, fd, errp); if (ret < 0) { @@ -957,16 +949,21 @@ free_fail: return -1; } =20 - ret =3D net_init_tap_one(tap, peer, "bridge", name, ifname, - script, downscript, tap->vhostfd, + ret =3D net_init_tap_one(tap, peer, "bridge", name, NULL, + NULL, NULL, tap->vhostfd, vnet_hdr, fd, errp); if (ret < 0) { close(fd); return -1; } } else { + const char *script =3D tap->script; + const char *downscript =3D tap->downscript; + int queues =3D tap->has_queues ? tap->queues : 1; g_autofree char *default_script =3D NULL; g_autofree char *default_downscript =3D NULL; + char ifname[128]; + if (tap->vhostfds) { error_setg(errp, "vhostfds=3D is invalid if fds=3D wasn't spec= ified"); return -1; --=20 2.48.1 From nobody Sat Nov 15 05:36:57 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=1755526122; cv=none; d=zohomail.com; s=zohoarc; b=HqARIH+cSxwLd06iBhVX/+WK6Idg7qd8CJab5d5M4wXcjlLdHxb76so9U05Ziqjgpl9GL5Ay1km2s1wqhEDgyJtBwXywzwUwsxIVomVhEHb6Z/MF+QP9LouzJpsSaFeUQRbDtR0NxNruVUNv18KlzGcDDiL4zPOlXOPylHy1bPc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1755526122; 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=cVIuFmKaRA15APjAb94zI55tuavk/4RbFP5EQfNMKho=; b=mEZQvkx7TJBItF6eZMNBxo28KFoyeqhHbFmyvsvJJoXbPJu1g0B9FZdWMwxBMWkJvEdKmqTG74tWJyTVtEPhzE5/R0S3O9R2HGXo6ByMLcVnrPKePMxLr8DDok6tOoUZIog99pFd1EQQhkgBP0eMn3ZKcsDMPIVKR9+nA9Q7YNM= 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 1755526122005541.2906505960847; Mon, 18 Aug 2025 07:08:42 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uo0Vo-0001M1-Os; Mon, 18 Aug 2025 10:07:00 -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 1uo0Vl-0001Jx-4y for qemu-devel@nongnu.org; Mon, 18 Aug 2025 10:06:57 -0400 Received: from forwardcorp1b.mail.yandex.net ([2a02:6b8:c02:900:1:45:d181:df01]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uo0Vh-0002BR-DM for qemu-devel@nongnu.org; Mon, 18 Aug 2025 10:06:56 -0400 Received: from mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net [IPv6:2a02:6b8:c21:2d8b:0:640:7d49:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTPS id 7D4D4807B6; Mon, 18 Aug 2025 17:06:50 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:b25::1:17]) by mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id k6RC4003YeA0-iyRSPykr; Mon, 18 Aug 2025 17:06:50 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1755526010; bh=cVIuFmKaRA15APjAb94zI55tuavk/4RbFP5EQfNMKho=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=WR/KC6Hi5UQcdDhiEfIY2jv79cJG/s6q8v3t/yeVI6J4b30+7O+mL10xERTRzBmKz vnV+J/XOIzFl5YWTH7HmH6a/OHG4xRayzKP1/w7p9gaDWOE4yf6qedaA+HICJ/75MH F8ianmolFZNNnsNxK0/sV/d79slkuQzSk6BieMV4= Authentication-Results: mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: jasowang@redhat.com Cc: qemu-devel@nongnu.org, vsementsov@yandex-team.ru Subject: [PATCH 09/19] net/tap: use glib strings vector and g_strsplit for fds case Date: Mon, 18 Aug 2025 17:06:35 +0300 Message-ID: <20250818140645.27904-10-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250818140645.27904-1-vsementsov@yandex-team.ru> References: <20250818140645.27904-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a02:6b8:c02:900:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1b.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list 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: 1755526124681124100 Content-Type: text/plain; charset="utf-8" Signed-off-by: Vladimir Sementsov-Ogievskiy --- net/tap.c | 72 +++++++++++-------------------------------------------- 1 file changed, 14 insertions(+), 58 deletions(-) diff --git a/net/tap.c b/net/tap.c index 80ec54f914..ac8d955050 100644 --- a/net/tap.c +++ b/net/tap.c @@ -774,32 +774,6 @@ failed: return -1; } =20 -static int get_fds(char *str, char *fds[], int max) -{ - char *ptr =3D str, *this; - size_t len =3D strlen(str); - int i =3D 0; - - while (i < max && ptr < str + len) { - this =3D strchr(ptr, ':'); - - if (this =3D=3D NULL) { - fds[i] =3D g_strdup(ptr); - } else { - fds[i] =3D g_strndup(ptr, this - ptr); - } - - i++; - if (this =3D=3D NULL) { - break; - } else { - ptr =3D this + 1; - } - } - - return i; -} - int net_init_tap(const Netdev *netdev, const char *name, NetClientState *peer, Error **errp) { @@ -859,74 +833,56 @@ int net_init_tap(const Netdev *netdev, const char *na= me, return -1; } } else if (tap->fds) { - char **fds; - char **vhost_fds; - int nfds =3D 0, nvhosts =3D 0; + g_auto(GStrv) fds =3D NULL; + g_auto(GStrv) vhost_fds =3D NULL; + int nfds; =20 if (tap->helper || tap->vhostfd) { error_setg(errp, "helper=3D and vhostfd=3D are invalid with fd= s=3D"); return -1; } =20 - fds =3D g_new0(char *, MAX_TAP_QUEUES); - vhost_fds =3D g_new0(char *, MAX_TAP_QUEUES); + fds =3D g_strsplit(tap->fds, ":", MAX_TAP_QUEUES); + nfds =3D g_strv_length(fds); =20 - nfds =3D get_fds(tap->fds, fds, MAX_TAP_QUEUES); if (tap->vhostfds) { - nvhosts =3D get_fds(tap->vhostfds, vhost_fds, MAX_TAP_QUEUES); - if (nfds !=3D nvhosts) { + vhost_fds =3D g_strsplit(tap->vhostfds, ":", MAX_TAP_QUEUES); + if (nfds !=3D g_strv_length(vhost_fds)) { error_setg(errp, "The number of fds passed does not match " "the number of vhostfds passed"); - ret =3D -1; - goto free_fail; + return -1; } } =20 for (i =3D 0; i < nfds; i++) { fd =3D monitor_fd_param(monitor_cur(), fds[i], errp); if (fd =3D=3D -1) { - ret =3D -1; - goto free_fail; + return -1; } =20 if (!set_fd_nonblocking(fd, fds[i], errp)) { - ret =3D -1; - goto free_fail; + return -1; } =20 if (i =3D=3D 0) { vnet_hdr =3D tap_probe_vnet_hdr(fd, errp); if (vnet_hdr < 0) { - ret =3D -1; - goto free_fail; + return -1; } } else if (vnet_hdr !=3D tap_probe_vnet_hdr(fd, NULL)) { error_setg(errp, "vnet_hdr not consistent across given tap fds"); - ret =3D -1; - goto free_fail; + return -1; } =20 ret =3D net_init_tap_one(tap, peer, "tap", name, NULL, NULL, NULL, - tap->vhostfds ? vhost_fds[i] : NULL, + vhost_fds ? vhost_fds[i] : NULL, vnet_hdr, fd, errp); if (ret < 0) { - ret =3D -1; - goto free_fail; + return -1; } } - -free_fail: - for (i =3D 0; i < nvhosts; i++) { - g_free(vhost_fds[i]); - } - for (i =3D 0; i < nfds; i++) { - g_free(fds[i]); - } - g_free(fds); - g_free(vhost_fds); - return ret; } else if (tap->helper) { if (tap->vhostfds) { error_setg(errp, "vhostfds=3D is invalid with helper=3D"); --=20 2.48.1 From nobody Sat Nov 15 05:36:57 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=1755526126; cv=none; d=zohomail.com; s=zohoarc; b=j5sVOeyHbk+lH/QT8x1QjMQGE2Z8T9uwxkjAoPcGOyVcXGhAFnsmzsIFBrJ9+aEVWZe0OjRqxFdKoUDh0HrN984rn/WeBnFjVFNyYM7/h8A/Wfx19z97h4/u+1U7qHKZJeeHuyGP9SJW1PSA3CR5c/xD9JBcUi5qNFJoaMzqngM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1755526126; 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=Nvib2fMtqDGabRyCVUGnIIQ+vzpiececeackpu4+gjk=; b=aot4TsKvIoI5xs5pusV/ZVCMP2TsJKpJnFzddpOAy9LLpHuYmWWYnJy0CvtbLbJHQx0NfYhiO6z+FyrulRU9dP1K429FJHOOhPPnwT6CGvNezsXY2c4ifDxTkkBW3Ac6PvNOhYZSfZuF+jVO9pzm9sXQBhhGZzD2kJPgGu6vpYY= 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 1755526126594675.969567942342; Mon, 18 Aug 2025 07:08:46 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uo0Vr-0001Rj-0P; Mon, 18 Aug 2025 10:07:03 -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 1uo0Vn-0001LN-6D for qemu-devel@nongnu.org; Mon, 18 Aug 2025 10:06:59 -0400 Received: from forwardcorp1b.mail.yandex.net ([178.154.239.136]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uo0Vl-0002CC-6L for qemu-devel@nongnu.org; Mon, 18 Aug 2025 10:06:58 -0400 Received: from mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net [IPv6:2a02:6b8:c21:2d8b:0:640:7d49:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTPS id D5A18807BA; Mon, 18 Aug 2025 17:06:50 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:b25::1:17]) by mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id k6RC4003YeA0-IWK0NFie; Mon, 18 Aug 2025 17:06:50 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1755526010; bh=Nvib2fMtqDGabRyCVUGnIIQ+vzpiececeackpu4+gjk=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=YSFzzmcpt3K2I/oMtqcW5e6iBObgg1AhoBg4g1djXuAXAt8Z9m4V1Ldlz5Soz2VnS FvwF8XyZxINMn0zlXCWT2EP/9pjBVF67aj1zr64FKE849BBE+Gub9bsKbBZZOM6r/4 AxNUQqjpYhvCLETr2QNx4QFspd1+sK1jDwroOpaU= Authentication-Results: mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: jasowang@redhat.com Cc: qemu-devel@nongnu.org, vsementsov@yandex-team.ru Subject: [PATCH 10/19] net/tap: drop extra tap_fd_get_ifname() call Date: Mon, 18 Aug 2025 17:06:36 +0300 Message-ID: <20250818140645.27904-11-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250818140645.27904-1-vsementsov@yandex-team.ru> References: <20250818140645.27904-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=178.154.239.136; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1b.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_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 Precedence: list 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: 1755526131663116600 Content-Type: text/plain; charset="utf-8" tap_open() cares to update ifname, no reason to call extra ioctl. Signed-off-by: Vladimir Sementsov-Ogievskiy --- net/tap.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/net/tap.c b/net/tap.c index ac8d955050..eab0a86173 100644 --- a/net/tap.c +++ b/net/tap.c @@ -946,14 +946,6 @@ int net_init_tap(const Netdev *netdev, const char *nam= e, return -1; } =20 - if (queues > 1 && i =3D=3D 0 && !tap->ifname) { - if (tap_fd_get_ifname(fd, ifname)) { - error_setg(errp, "Fail to get ifname"); - close(fd); - return -1; - } - } - ret =3D net_init_tap_one(tap, peer, "tap", name, ifname, i >=3D 1 ? "no" : script, i >=3D 1 ? "no" : downscript, --=20 2.48.1 From nobody Sat Nov 15 05:36:57 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=1755526114; cv=none; d=zohomail.com; s=zohoarc; b=WLJaAUmQYQtbWFES842s8PSvQzpmRXR8TuBDa1Qsfh69AuFlcoNNpXB4cxGwJ4U08EVRXZuNiiJtiKq2JVb0Ia8znHURTM/7syrFpSD8LfJ9JHTwHEcqAV405OfohgdjGKNQ4Pj9TybSSOwQVo9ySUowhvqds0WLCBwd+15rrpU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1755526114; 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=FV7G9bFav6fly4zXKY/M2EAtJlpqhKHxyw6pyeEvM4o=; b=Zieq7jihqjCDdSl5sndXCK0c3ESIGx4Yh+ySlqAZI8P5kb8kNoYuAe7RtNeSYldVNYDV4AneDhZ1WIQVqA/j5LAAYVmYtTtJnKa3qkr5TIq8K2FWwJD1dyy3KLZMTptgwDdoAeF6eKNWC+6sH9H/9AgUDQzf6ZgfbgZDUtpxs3A= 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 1755526114629938.8215203254179; Mon, 18 Aug 2025 07:08:34 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uo0Vv-0001ib-SO; Mon, 18 Aug 2025 10:07:07 -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 1uo0Vm-0001L6-QY for qemu-devel@nongnu.org; Mon, 18 Aug 2025 10:06:58 -0400 Received: from forwardcorp1b.mail.yandex.net ([2a02:6b8:c02:900:1:45:d181:df01]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uo0Vk-0002CD-Tw for qemu-devel@nongnu.org; Mon, 18 Aug 2025 10:06:58 -0400 Received: from mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net [IPv6:2a02:6b8:c21:2d8b:0:640:7d49:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTPS id 32710807CD; Mon, 18 Aug 2025 17:06:51 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:b25::1:17]) by mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id k6RC4003YeA0-yZYIlRC5; Mon, 18 Aug 2025 17:06:50 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1755526010; bh=FV7G9bFav6fly4zXKY/M2EAtJlpqhKHxyw6pyeEvM4o=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=uo5PwBjZmvmFFpOXmkDe0ov0QEbLcSZ8Y+0ZvbtIWO8gTa4gD/P/MmE6OtKpJMBRK MTjAJh8LpIqVRjIYd1CXdHdwdSKt9q0rul5gr4CpSkjSwP3+XHbqzhfiDMGCjrUaAI Q3p5AksTdWeZq/RBdwfBPlYP+eVLuUwT9yg7XST0= Authentication-Results: mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: jasowang@redhat.com Cc: qemu-devel@nongnu.org, vsementsov@yandex-team.ru Subject: [PATCH 11/19] net/tap: net_init_tap_one(): refactor to use netdev as first arg Date: Mon, 18 Aug 2025 17:06:37 +0300 Message-ID: <20250818140645.27904-12-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250818140645.27904-1-vsementsov@yandex-team.ru> References: <20250818140645.27904-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a02:6b8:c02:900:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1b.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list 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: 1755526115556116600 Content-Type: text/plain; charset="utf-8" This is needed for further unification of bridge initialization in net_init_tap() and net_init_bridge(). Signed-off-by: Vladimir Sementsov-Ogievskiy --- net/tap.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/net/tap.c b/net/tap.c index eab0a86173..468dae7004 100644 --- a/net/tap.c +++ b/net/tap.c @@ -692,15 +692,18 @@ static int net_tap_init(const NetdevTapOptions *tap, = int *vnet_hdr, =20 #define MAX_TAP_QUEUES 1024 =20 -static int net_init_tap_one(const NetdevTapOptions *tap, NetClientState *p= eer, +static int net_init_tap_one(const Netdev *netdev, NetClientState *peer, const char *model, const char *name, const char *ifname, const char *script, const char *downscript, const char *vhostfdnam= e, int vnet_hdr, int fd, Error **errp) { + const NetdevTapOptions *tap =3D &netdev->u.tap; TAPState *s =3D net_tap_fd_init(peer, model, name, fd, vnet_hdr); int vhostfd; =20 + assert(netdev->type =3D=3D NET_CLIENT_DRIVER_TAP); + if (tap_set_sndbuf(s->fd, tap, errp) < 0) { goto failed; } @@ -826,7 +829,7 @@ int net_init_tap(const Netdev *netdev, const char *name, return -1; } =20 - ret =3D net_init_tap_one(tap, peer, "tap", name, NULL, + ret =3D net_init_tap_one(netdev, peer, "tap", name, NULL, NULL, NULL, tap->vhostfd, vnet_hdr, fd, errp); if (ret < 0) { @@ -875,7 +878,7 @@ int net_init_tap(const Netdev *netdev, const char *name, return -1; } =20 - ret =3D net_init_tap_one(tap, peer, "tap", name, NULL, + ret =3D net_init_tap_one(netdev, peer, "tap", name, NULL, NULL, NULL, vhost_fds ? vhost_fds[i] : NULL, vnet_hdr, fd, errp); @@ -905,7 +908,7 @@ int net_init_tap(const Netdev *netdev, const char *name, return -1; } =20 - ret =3D net_init_tap_one(tap, peer, "bridge", name, NULL, + ret =3D net_init_tap_one(netdev, peer, "bridge", name, NULL, NULL, NULL, tap->vhostfd, vnet_hdr, fd, errp); if (ret < 0) { @@ -946,7 +949,7 @@ int net_init_tap(const Netdev *netdev, const char *name, return -1; } =20 - ret =3D net_init_tap_one(tap, peer, "tap", name, ifname, + ret =3D net_init_tap_one(netdev, peer, "tap", name, ifname, i >=3D 1 ? "no" : script, i >=3D 1 ? "no" : downscript, tap->vhostfd, vnet_hdr, fd, errp); --=20 2.48.1 From nobody Sat Nov 15 05:36:57 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=1755526170; cv=none; d=zohomail.com; s=zohoarc; b=ZEEUD8vu9hoNvIdaeer+QqlJYk3NgsWDlrY4jqgmQMM4OH9I0ONa4sim3Iy/BB3pLXqwBUV0tk4iKfQH8JLrxiSE04aULi1xgPBYeZjit0JWdQB/Ps1HW7o+/9K+L71mOI9D40buXqnvdP2NSOyIv47MV+OxGpkrztMQJo314zA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1755526170; 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=zxe/Qn8qaUIKSb9GVBdarhgmP62+YL/GaisgtgQiiKc=; b=KduhOuvn5/t6wpPjGIz5GDi9w0bFOPWZgNaZodHyUJ+S6TcDuQnnnot8vXRumZp5MEIP1WzL0IAS9IuFaulOxNq0k1cJbe4kcTyUYpGUQsJjdd0uQCdVUjLUOQ2b2lxta2ZVjFT80OHixF9OGeZW+HznWz/yKv9rWbwXYB1HEAw= 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 1755526170662859.5634825788007; Mon, 18 Aug 2025 07:09:30 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uo0Vq-0001OF-6U; Mon, 18 Aug 2025 10:07:02 -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 1uo0Vn-0001Lp-Pg for qemu-devel@nongnu.org; Mon, 18 Aug 2025 10:06:59 -0400 Received: from forwardcorp1b.mail.yandex.net ([2a02:6b8:c02:900:1:45:d181:df01]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uo0Vl-0002CZ-SN for qemu-devel@nongnu.org; Mon, 18 Aug 2025 10:06:59 -0400 Received: from mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net [IPv6:2a02:6b8:c21:2d8b:0:640:7d49:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTPS id 86D8A807CE; Mon, 18 Aug 2025 17:06:51 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:b25::1:17]) by mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id k6RC4003YeA0-QlqtVJKk; Mon, 18 Aug 2025 17:06:51 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1755526011; bh=zxe/Qn8qaUIKSb9GVBdarhgmP62+YL/GaisgtgQiiKc=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=wEBWPy/OsvKi1AjPLCwJ/9et6xBBjtjv3gB6ghUfXYRSpCPM1N6VAmrM0/TVtN0yq Z3KpgWiWkDKIshqLz5QHOyXUlCDXwMTq6Be6QqOsp/3PC4tTVdQAYrnL7UkgghKFv6 VTATcsTH1xQRU2T+MUhBSi60d/CEvtj0vKTGlo+M= Authentication-Results: mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: jasowang@redhat.com Cc: qemu-devel@nongnu.org, vsementsov@yandex-team.ru Subject: [PATCH 12/19] net/tap: net_init_tap_one(): support bridge Date: Mon, 18 Aug 2025 17:06:38 +0300 Message-ID: <20250818140645.27904-13-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250818140645.27904-1-vsementsov@yandex-team.ru> References: <20250818140645.27904-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a02:6b8:c02:900:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1b.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list 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: 1755526172240116600 Content-Type: text/plain; charset="utf-8" Use net_init_tap_one() in net_init_bridge(). Signed-off-by: Vladimir Sementsov-Ogievskiy --- net/tap.c | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/net/tap.c b/net/tap.c index 468dae7004..5acfb128a1 100644 --- a/net/tap.c +++ b/net/tap.c @@ -88,6 +88,12 @@ 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 int net_init_tap_one(const Netdev *netdev, NetClientState *peer, + const char *model, const char *name, + const char *ifname, const char *script, + const char *downscript, const char *vhostfdnam= e, + int vnet_hdr, int fd, Error **errp); + static void tap_update_fd_handler(TAPState *s) { qemu_set_fd_handler(s->fd, @@ -626,8 +632,7 @@ int net_init_bridge(const Netdev *netdev, const char *n= ame, { const NetdevBridgeOptions *bridge; const char *helper, *br; - TAPState *s; - int fd, vnet_hdr; + int fd, vnet_hdr, ret; =20 assert(netdev->type =3D=3D NET_CLIENT_DRIVER_BRIDGE); bridge =3D &netdev->u.bridge; @@ -648,9 +653,14 @@ int net_init_bridge(const Netdev *netdev, const char *= name, close(fd); return -1; } - s =3D net_tap_fd_init(peer, "bridge", name, fd, vnet_hdr); =20 - qemu_set_info_str(&s->nc, "helper=3D%s,br=3D%s", helper, br); + ret =3D net_init_tap_one(netdev, peer, "bridge", name, + NULL, NULL, NULL, + NULL, vnet_hdr, fd, errp); + if (ret < 0) { + close(fd); + return -1; + } =20 return 0; } @@ -698,11 +708,19 @@ static int net_init_tap_one(const Netdev *netdev, Net= ClientState *peer, const char *downscript, const char *vhostfdnam= e, int vnet_hdr, int fd, Error **errp) { - const NetdevTapOptions *tap =3D &netdev->u.tap; + const NetdevTapOptions *tap; TAPState *s =3D net_tap_fd_init(peer, model, name, fd, vnet_hdr); int vhostfd; =20 + if (netdev->type =3D=3D NET_CLIENT_DRIVER_BRIDGE) { + const NetdevBridgeOptions *bridge =3D &netdev->u.bridge; + qemu_set_info_str(&s->nc, "helper=3D%s,br=3D%s", + bridge->helper, bridge->br); + return 0; + } + assert(netdev->type =3D=3D NET_CLIENT_DRIVER_TAP); + tap =3D &netdev->u.tap; =20 if (tap_set_sndbuf(s->fd, tap, errp) < 0) { goto failed; --=20 2.48.1 From nobody Sat Nov 15 05:36:57 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=1755526061; cv=none; d=zohomail.com; s=zohoarc; b=FFWfsJUnVoMyzWBl0P+lBr8o1XpjxDBqO3J3Fyd3GrGbG5h6kuXnvioVsf75xT68tMDaKGXOrKqMDbG+5E3b8x7fcp4lxFoExsQoJfyiXQF7NhU2otamJwREVH6LtLCtj3uV7lEhbciy3n9kf7G6dvPKzB1JL3I5enImWYaXCsQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1755526061; 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=9w3QClpqsLPtFcNR/rxasMLiSjbct8d5Q3AT/oDKknU=; b=EvgxA9fpJhnWMPsMsdhxyL5X7erA+zXnqwrW0xJpmaEqTNk25XjytoiQb4uwYMmn3BGiKcTIY7tMZxMdW6X6k+LLif1KnPpjLXQidg1gygLwshIsomLzauL0+R8tj9baKdFugZNekFN3I15CKxI8z5HDusuN5iPcQBfOCnUd7Lc= 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 175552606185350.83742064652188; Mon, 18 Aug 2025 07:07:41 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uo0Vw-0001kf-Jl; Mon, 18 Aug 2025 10:07: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 1uo0Vn-0001Lj-Ib for qemu-devel@nongnu.org; Mon, 18 Aug 2025 10:06:59 -0400 Received: from forwardcorp1b.mail.yandex.net ([2a02:6b8:c02:900:1:45:d181:df01]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uo0Vl-0002CY-RF for qemu-devel@nongnu.org; Mon, 18 Aug 2025 10:06:59 -0400 Received: from mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net [IPv6:2a02:6b8:c21:2d8b:0:640:7d49:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTPS id D6BAA807AF; Mon, 18 Aug 2025 17:06:51 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:b25::1:17]) by mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id k6RC4003YeA0-QfT8heXF; Mon, 18 Aug 2025 17:06:51 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1755526011; bh=9w3QClpqsLPtFcNR/rxasMLiSjbct8d5Q3AT/oDKknU=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=EPzNpHf2ePzXe+7w3d7czpKMZHblM8YHliiOecXu3sJfK6fE+EfH3vy9QK9zM+KEx IGGCZwmtK3kgq+Z+uV8HpWz54Uc97u8GdsWfX4NYZ7jK3lZ1DMRyBhTKpO8dxob6du fnwzRm/QXBPrYeqiTDDFfKPTyhCe/FqRRO8KL27o= Authentication-Results: mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: jasowang@redhat.com Cc: qemu-devel@nongnu.org, vsementsov@yandex-team.ru Subject: [PATCH 13/19] net/tap: net_init_bridge(): support tap Date: Mon, 18 Aug 2025 17:06:39 +0300 Message-ID: <20250818140645.27904-14-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250818140645.27904-1-vsementsov@yandex-team.ru> References: <20250818140645.27904-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a02:6b8:c02:900:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1b.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list 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: 1755526065182116600 Content-Type: text/plain; charset="utf-8" Support tap in net_init_bridge() and reuse it for corresponding case in net_init_tap(). Signed-off-by: Vladimir Sementsov-Ogievskiy --- net/tap.c | 47 +++++++++++++++++------------------------------ 1 file changed, 17 insertions(+), 30 deletions(-) diff --git a/net/tap.c b/net/tap.c index 5acfb128a1..83a1c9250a 100644 --- a/net/tap.c +++ b/net/tap.c @@ -630,16 +630,24 @@ static bool set_fd_nonblocking(int fd, const char *no= te, Error **errp) int net_init_bridge(const Netdev *netdev, const char *name, NetClientState *peer, Error **errp) { - const NetdevBridgeOptions *bridge; + const NetdevTapOptions *tap =3D NULL; + const NetdevBridgeOptions *bridge =3D NULL; const char *helper, *br; int fd, vnet_hdr, ret; =20 - assert(netdev->type =3D=3D NET_CLIENT_DRIVER_BRIDGE); - bridge =3D &netdev->u.bridge; - helper =3D bridge->helper; - br =3D bridge->br ?: DEFAULT_BRIDGE_INTERFACE; + if (netdev->type =3D=3D NET_CLIENT_DRIVER_BRIDGE) { + bridge =3D &netdev->u.bridge; + helper =3D bridge->helper; + br =3D bridge->br; + } else { + assert(netdev->type =3D=3D NET_CLIENT_DRIVER_TAP); =20 - fd =3D net_bridge_run_helper(helper, br, errp); + tap =3D &netdev->u.tap; + helper =3D tap->helper; + br =3D tap->br; + } + + fd =3D net_bridge_run_helper(helper, br ?: DEFAULT_BRIDGE_INTERFACE, e= rrp); if (fd =3D=3D -1) { return -1; } @@ -656,7 +664,8 @@ int net_init_bridge(const Netdev *netdev, const char *n= ame, =20 ret =3D net_init_tap_one(netdev, peer, "bridge", name, NULL, NULL, NULL, - NULL, vnet_hdr, fd, errp); + tap ? tap->vhostfd : NULL, + vnet_hdr, fd, errp); if (ret < 0) { close(fd); return -1; @@ -910,29 +919,7 @@ int net_init_tap(const Netdev *netdev, const char *nam= e, return -1; } =20 - fd =3D net_bridge_run_helper(tap->helper, - tap->br ?: DEFAULT_BRIDGE_INTERFACE, - errp); - if (fd =3D=3D -1) { - return -1; - } - - if (!set_fd_nonblocking(fd, name, errp)) { - return -1; - } - vnet_hdr =3D tap_probe_vnet_hdr(fd, errp); - if (vnet_hdr < 0) { - close(fd); - return -1; - } - - ret =3D net_init_tap_one(netdev, peer, "bridge", name, NULL, - NULL, NULL, tap->vhostfd, - vnet_hdr, fd, errp); - if (ret < 0) { - close(fd); - return -1; - } + return net_init_bridge(netdev, name, peer, errp); } else { const char *script =3D tap->script; const char *downscript =3D tap->downscript; --=20 2.48.1 From nobody Sat Nov 15 05:36:57 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=1755526100; cv=none; d=zohomail.com; s=zohoarc; b=GDYR+OGR+30xrBCQnoUvAqSUxeYisW/TucHlo9wV8bp3GXIamkWaJWtszSEmaRpbsnAOzdQz4osh253RJsbTKPZKUHBIYBmX7V69gEG+ZVGPPYw7QTEgDNFty6QSBaTXObk5gL31axFIbd73Ne073pwsUW0pSBQ7TPd/0u3E2XQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1755526100; 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=CRFGK6nZULMxIVw/18pY4S5gebSM3w3PMN2fT81y9NE=; b=H2Gwy3EazJJtVbZ3QRHPZzv+XjJ95nNBjezMmDcwjPN5ZFosc/8F6d9UHBzJJM29VvMR4zgGGXvBkBrq4ZglqVxfdaHQmWNhkvKV/ST84fVVkUCjwmq4iLR/o+N0zoz4XLqBGgie5hC23gbZ1Yei6lo4ZTmjDxoa2IhP6pNckzw= 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 1755526100452309.7946957562583; Mon, 18 Aug 2025 07:08:20 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uo0Vs-0001Z8-R8; Mon, 18 Aug 2025 10:07:04 -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 1uo0Vp-0001MY-7m for qemu-devel@nongnu.org; Mon, 18 Aug 2025 10:07:01 -0400 Received: from forwardcorp1b.mail.yandex.net ([2a02:6b8:c02:900:1:45:d181:df01]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uo0Vm-0002Ct-JN for qemu-devel@nongnu.org; Mon, 18 Aug 2025 10:07:00 -0400 Received: from mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net [IPv6:2a02:6b8:c21:2d8b:0:640:7d49:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTPS id 32FB6807D1; Mon, 18 Aug 2025 17:06:52 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:b25::1:17]) by mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id k6RC4003YeA0-Mp3KS07W; Mon, 18 Aug 2025 17:06:51 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1755526011; bh=CRFGK6nZULMxIVw/18pY4S5gebSM3w3PMN2fT81y9NE=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=n3Bmz+R7rhNgPj10a7pJ61XrJusDJEAKwGVlOr7feaq+2yYvSrMBwdoDpKlwh0rsv +qbS5cJypXrF1FZXfJB00a++VXXIVLw3CGfP53epEkaru16QhgShGFeIYXbsabdMAD GXFYywEfQ2oKQpxwhs7NmAij+mXmP1ejpf7cD5Fk= Authentication-Results: mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: jasowang@redhat.com Cc: qemu-devel@nongnu.org, vsementsov@yandex-team.ru Subject: [PATCH 14/19] net/tap: refactor net_tap_init() into net_tap_open_one() Date: Mon, 18 Aug 2025 17:06:40 +0300 Message-ID: <20250818140645.27904-15-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250818140645.27904-1-vsementsov@yandex-team.ru> References: <20250818140645.27904-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a02:6b8:c02:900:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1b.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list 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: 1755526102536124100 Content-Type: text/plain; charset="utf-8" net_tap_init() is used in one place. Let's move net_init_tap_one() call to it and simplify outer loop code. Signed-off-by: Vladimir Sementsov-Ogievskiy --- net/tap.c | 52 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/net/tap.c b/net/tap.c index 83a1c9250a..2cffa880a4 100644 --- a/net/tap.c +++ b/net/tap.c @@ -674,31 +674,37 @@ int net_init_bridge(const Netdev *netdev, const char = *name, return 0; } =20 -static int net_tap_init(const NetdevTapOptions *tap, int *vnet_hdr, - const char *setup_script, char *ifname, - size_t ifname_sz, int mq_required, Error **errp) +static int net_tap_open_one(const Netdev *netdev, + const char *name, NetClientState *peer, + const char *script, const char *downscript, + char *ifname, size_t ifname_sz, + int mq_required, Error **errp) { + const NetdevTapOptions *tap =3D &netdev->u.tap; Error *err =3D NULL; - int fd, vnet_hdr_required; + int fd, vnet_hdr_required, vnet_hdr; + int ret; + + assert(netdev->type =3D=3D NET_CLIENT_DRIVER_TAP); =20 if (tap->has_vnet_hdr) { - *vnet_hdr =3D tap->vnet_hdr; - vnet_hdr_required =3D *vnet_hdr; + vnet_hdr =3D tap->vnet_hdr; + vnet_hdr_required =3D vnet_hdr; } else { - *vnet_hdr =3D 1; + vnet_hdr =3D 1; vnet_hdr_required =3D 0; } =20 - fd =3D RETRY_ON_EINTR(tap_open(ifname, ifname_sz, vnet_hdr, vnet_hdr_r= equired, - mq_required, errp)); + fd =3D RETRY_ON_EINTR(tap_open(ifname, ifname_sz, &vnet_hdr, + vnet_hdr_required, mq_required, errp)); if (fd < 0) { return -1; } =20 - if (setup_script && - setup_script[0] !=3D '\0' && - strcmp(setup_script, "no") !=3D 0) { - launch_script(setup_script, ifname, fd, &err); + if (script && + script[0] !=3D '\0' && + strcmp(script, "no") !=3D 0) { + launch_script(script, ifname, fd, &err); if (err) { error_propagate(errp, err); close(fd); @@ -706,6 +712,14 @@ static int net_tap_init(const NetdevTapOptions *tap, i= nt *vnet_hdr, } } =20 + ret =3D net_init_tap_one(netdev, peer, "tap", name, ifname, + script, downscript, + tap->vhostfd, vnet_hdr, fd, errp); + if (ret < 0) { + close(fd); + return -1; + } + return fd; } =20 @@ -948,20 +962,14 @@ int net_init_tap(const Netdev *netdev, const char *na= me, } =20 for (i =3D 0; i < queues; i++) { - fd =3D net_tap_init(tap, &vnet_hdr, i >=3D 1 ? "no" : script, - ifname, sizeof ifname, queues > 1, errp); - if (fd =3D=3D -1) { - return -1; - } - - ret =3D net_init_tap_one(netdev, peer, "tap", name, ifname, + ret =3D net_tap_open_one(netdev, name, peer, i >=3D 1 ? "no" : script, i >=3D 1 ? "no" : downscript, - tap->vhostfd, vnet_hdr, fd, errp); + ifname, sizeof ifname, queues > 1, errp= ); if (ret < 0) { - close(fd); return -1; } + } } =20 --=20 2.48.1 From nobody Sat Nov 15 05:36:57 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=1755526067; cv=none; d=zohomail.com; s=zohoarc; b=c6fyAX68bOyhUp2Axp6+s5G++UPraOoL01OScQoKQhPcTCOCgA820DdhzSuYXDDvBZ+20Te07E+1GnnjPhB6zY4vGF9U0hP5R78oFUgkjqCwl844ICyKidXltq4lS0Znjn5Y0wXJT5bYwaX8/Ko56PPI8895VWkuvg+6SFLlZVs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1755526067; 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=HpUvdWzVv8ea0OUfIhmNiXUGLnANMbNVPqLLdDIcsyU=; b=Gm6Ac95DwybKwto0KUN+qpYnBlOBk6wioUe2MRPWuMnjx1cDN6rxLltIPcLYseAKvi4dt61SU/uJVuH/auAv1zdtiarHpLs/YIks/hToh/5LchfRLer8r0bSXTSUve7keGfIhClBxkWQCUX/qVW90aVDCsf4VT1fKByMH62BQ6Q= 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 1755526067375156.00486239243173; Mon, 18 Aug 2025 07:07:47 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uo0Vt-0001ai-78; Mon, 18 Aug 2025 10:07:05 -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 1uo0Vo-0001M2-6T for qemu-devel@nongnu.org; Mon, 18 Aug 2025 10:07:00 -0400 Received: from forwardcorp1b.mail.yandex.net ([178.154.239.136]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uo0Vm-0002Cu-Cr for qemu-devel@nongnu.org; Mon, 18 Aug 2025 10:06:59 -0400 Received: from mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net [IPv6:2a02:6b8:c21:2d8b:0:640:7d49:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTPS id A0CD7807D2; Mon, 18 Aug 2025 17:06:52 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:b25::1:17]) by mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id k6RC4003YeA0-kDUiWHJ1; Mon, 18 Aug 2025 17:06:52 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1755526012; bh=HpUvdWzVv8ea0OUfIhmNiXUGLnANMbNVPqLLdDIcsyU=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=Sn78bW0ykphT4k2yA67GqV81slN3Vvrb0UU6vvB9jyanWAYO7vXom4eES1rlt6ASS vFpkzsctl+3Cx/hy3TpYm6w3zlw511gDrp7oPU2Ucurcarz+0tj/plrA0leeEQIQwZ H7cdSq68LwlkfH9gzC+hXoB4L2adyJX+SEAAIRAg= Authentication-Results: mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: jasowang@redhat.com Cc: qemu-devel@nongnu.org, vsementsov@yandex-team.ru Subject: [PATCH 15/19] net/tap: introduce net_tap_open() Date: Mon, 18 Aug 2025 17:06:41 +0300 Message-ID: <20250818140645.27904-16-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250818140645.27904-1-vsementsov@yandex-team.ru> References: <20250818140645.27904-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=178.154.239.136; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1b.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_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 Precedence: list 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: 1755526069172116600 Content-Type: text/plain; charset="utf-8" Move the latter case of net_init_tap() to a separate function. Signed-off-by: Vladimir Sementsov-Ogievskiy --- net/tap.c | 85 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 48 insertions(+), 37 deletions(-) diff --git a/net/tap.c b/net/tap.c index 2cffa880a4..ddee655f60 100644 --- a/net/tap.c +++ b/net/tap.c @@ -818,6 +818,49 @@ failed: return -1; } =20 +static int net_tap_open(const Netdev *netdev, + const char *name, + NetClientState *peer, + Error **errp) +{ + const NetdevTapOptions *tap =3D &netdev->u.tap; + const char *script =3D tap->script; + const char *downscript =3D tap->downscript; + int queues =3D tap->has_queues ? tap->queues : 1; + g_autofree char *default_script =3D NULL; + g_autofree char *default_downscript =3D NULL; + char ifname[128]; + int i, ret; + + assert(netdev->type =3D=3D NET_CLIENT_DRIVER_TAP); + + if (!script) { + script =3D default_script =3D get_relocated_path(DEFAULT_NETWORK_S= CRIPT); + } + if (!downscript) { + downscript =3D default_downscript =3D + get_relocated_path(DEFAULT_NETWORK_DOWN_SCRIP= T); + } + + if (tap->ifname) { + pstrcpy(ifname, sizeof ifname, tap->ifname); + } else { + ifname[0] =3D '\0'; + } + + for (i =3D 0; i < queues; i++) { + ret =3D net_tap_open_one(netdev, name, peer, + i >=3D 1 ? "no" : script, + i >=3D 1 ? "no" : downscript, + ifname, sizeof ifname, queues > 1, errp); + if (ret < 0) { + return -1; + } + } + + return 0; +} + int net_init_tap(const Netdev *netdev, const char *name, NetClientState *peer, Error **errp) { @@ -934,46 +977,14 @@ int net_init_tap(const Netdev *netdev, const char *na= me, } =20 return net_init_bridge(netdev, name, peer, errp); - } else { - const char *script =3D tap->script; - const char *downscript =3D tap->downscript; - int queues =3D tap->has_queues ? tap->queues : 1; - g_autofree char *default_script =3D NULL; - g_autofree char *default_downscript =3D NULL; - char ifname[128]; - - if (tap->vhostfds) { - error_setg(errp, "vhostfds=3D is invalid if fds=3D wasn't spec= ified"); - return -1; - } - - 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 { - ifname[0] =3D '\0'; - } - - for (i =3D 0; i < queues; i++) { - ret =3D net_tap_open_one(netdev, name, peer, - i >=3D 1 ? "no" : script, - i >=3D 1 ? "no" : downscript, - ifname, sizeof ifname, queues > 1, errp= ); - if (ret < 0) { - return -1; - } + } =20 - } + if (tap->vhostfds) { + error_setg(errp, "vhostfds=3D is invalid if fds=3D wasn't specifie= d"); + return -1; } =20 - return 0; + return net_tap_open(netdev, name, peer, errp); } =20 int tap_enable(NetClientState *nc) --=20 2.48.1 From nobody Sat Nov 15 05:36:57 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=1755526135; cv=none; d=zohomail.com; s=zohoarc; b=bDYUAZ46T3uRNuK7tcCRxPHmfbgVAmTwA1n+118nSCS3ergWph6RYW8EMjM28fjQZQseIYd7sO/WUnS+Ei+pq+5y6mvT/YRGz5MBuydxajpbxxoBC4ELAdi+d2egY+Tb5opytIuP6O3Dd24YsT1hOnUzHlrS10/CoUIu6AEnQO8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1755526135; 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=9wuLPwnwcSfjr1aFoafDNTap3QiKA6TtzHXQ+dAcJoo=; b=fKEFHl6ahFKDeSVJ7O96BQxrFhd0oA+R4YbhisBvLFzIZLgliYG7YJMz6v/wies/lZs4u9R7vcoUNmX7Km4zrTjY7eTygJc5EEPS2adReIzAsmZDY4PMlPXEw3x4zyaY8Yz8cfTl531vS2/o3kC1J87eLNE47ao2ZPNcXxcCLEw= 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 1755526135720663.0607469256577; Mon, 18 Aug 2025 07:08:55 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uo0Vs-0001Vi-Cg; Mon, 18 Aug 2025 10:07:04 -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 1uo0Vo-0001M3-7U for qemu-devel@nongnu.org; Mon, 18 Aug 2025 10:07:00 -0400 Received: from forwardcorp1b.mail.yandex.net ([2a02:6b8:c02:900:1:45:d181:df01]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uo0Vm-0002D0-Ca for qemu-devel@nongnu.org; Mon, 18 Aug 2025 10:06:59 -0400 Received: from mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net [IPv6:2a02:6b8:c21:2d8b:0:640:7d49:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTPS id 0F404807D4; Mon, 18 Aug 2025 17:06:53 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:b25::1:17]) by mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id k6RC4003YeA0-5EGxGFFS; Mon, 18 Aug 2025 17:06:52 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1755526012; bh=9wuLPwnwcSfjr1aFoafDNTap3QiKA6TtzHXQ+dAcJoo=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=klaD5lk5UfDDy9SRPAR/RMSTzkkosuNmwhtRbI2eIpQ0rQQd3s7BWpZsCir0IU0m9 lsBgCbadCzHZOQFiIF+yDW9sBpya1CWaCfQQXT/xupni8JI39BkCVxokTSsWjuSThP m5q25lWzj+mE1UF5MUJLfG5tu/rOkliMsapEbJa8= Authentication-Results: mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: jasowang@redhat.com Cc: qemu-devel@nongnu.org, vsementsov@yandex-team.ru Subject: [PATCH 16/19] net/tap: introduce net_tap_fd_init_external() Date: Mon, 18 Aug 2025 17:06:42 +0300 Message-ID: <20250818140645.27904-17-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250818140645.27904-1-vsementsov@yandex-team.ru> References: <20250818140645.27904-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a02:6b8:c02:900:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1b.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list 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: 1755526137716116600 Content-Type: text/plain; charset="utf-8" Add helper that covers logic for initializing fds, given from monitor or helper. Signed-off-by: Vladimir Sementsov-Ogievskiy --- net/tap.c | 90 ++++++++++++++++++++++--------------------------------- 1 file changed, 36 insertions(+), 54 deletions(-) diff --git a/net/tap.c b/net/tap.c index ddee655f60..09c1343ccc 100644 --- a/net/tap.c +++ b/net/tap.c @@ -627,13 +627,40 @@ static bool set_fd_nonblocking(int fd, const char *no= te, Error **errp) return ok; } =20 +static int net_tap_fd_init_external(const Netdev *netdev, NetClientState *= peer, + const char *model, const char *name, + const char *vhostfdname, + int *pvnet_hdr, int fd, Error **errp) +{ + int vnet_hdr; + + if (!set_fd_nonblocking(fd, name, errp)) { + return -1; + } + + vnet_hdr =3D tap_probe_vnet_hdr(fd, errp); + if (pvnet_hdr) { + if (*pvnet_hdr < 0) { + *pvnet_hdr =3D vnet_hdr; + } else if (vnet_hdr !=3D *pvnet_hdr) { + error_setg(errp, + "vnet_hdr not consistent across given tap fds"); + return -1; + } + } + + return net_init_tap_one(netdev, peer, model, name, + NULL, NULL, NULL, + vhostfdname, vnet_hdr, fd, errp); +} + int net_init_bridge(const Netdev *netdev, const char *name, NetClientState *peer, Error **errp) { const NetdevTapOptions *tap =3D NULL; const NetdevBridgeOptions *bridge =3D NULL; const char *helper, *br; - int fd, vnet_hdr, ret; + int fd; =20 if (netdev->type =3D=3D NET_CLIENT_DRIVER_BRIDGE) { bridge =3D &netdev->u.bridge; @@ -652,26 +679,8 @@ int net_init_bridge(const Netdev *netdev, const char *= name, return -1; } =20 - if (!set_fd_nonblocking(fd, name, errp)) { - return -1; - } - - vnet_hdr =3D tap_probe_vnet_hdr(fd, errp); - if (vnet_hdr < 0) { - close(fd); - return -1; - } - - ret =3D net_init_tap_one(netdev, peer, "bridge", name, - NULL, NULL, NULL, - tap ? tap->vhostfd : NULL, - vnet_hdr, fd, errp); - if (ret < 0) { - close(fd); - return -1; - } - - return 0; + return net_tap_fd_init_external(netdev, peer, "bridge", name, + tap ? tap->vhostfd : NULL, NULL, fd, e= rrp); } =20 static int net_tap_open_one(const Netdev *netdev, @@ -902,20 +911,8 @@ int net_init_tap(const Netdev *netdev, const char *nam= e, return -1; } =20 - if (!set_fd_nonblocking(fd, tap->fd, errp)) { - close(fd); - return -1; - } - - vnet_hdr =3D tap_probe_vnet_hdr(fd, errp); - if (vnet_hdr < 0) { - close(fd); - return -1; - } - - ret =3D net_init_tap_one(netdev, peer, "tap", name, NULL, - NULL, NULL, - tap->vhostfd, vnet_hdr, fd, errp); + ret =3D net_tap_fd_init_external(netdev, peer, "tap", name, + tap->vhostfd, NULL, fd, errp); if (ret < 0) { return -1; } @@ -941,31 +938,16 @@ int net_init_tap(const Netdev *netdev, const char *na= me, } } =20 + vnet_hdr =3D -1; for (i =3D 0; i < nfds; i++) { fd =3D monitor_fd_param(monitor_cur(), fds[i], errp); if (fd =3D=3D -1) { return -1; } =20 - if (!set_fd_nonblocking(fd, fds[i], errp)) { - return -1; - } - - if (i =3D=3D 0) { - vnet_hdr =3D tap_probe_vnet_hdr(fd, errp); - if (vnet_hdr < 0) { - return -1; - } - } else if (vnet_hdr !=3D tap_probe_vnet_hdr(fd, NULL)) { - error_setg(errp, - "vnet_hdr not consistent across given tap fds"); - return -1; - } - - ret =3D net_init_tap_one(netdev, peer, "tap", name, NULL, - NULL, NULL, - vhost_fds ? vhost_fds[i] : NULL, - vnet_hdr, fd, errp); + ret =3D net_tap_fd_init_external(netdev, peer, "tap", name, + vhost_fds ? vhost_fds[i] : NULL, + &vnet_hdr, fd, errp); if (ret < 0) { return -1; } --=20 2.48.1 From nobody Sat Nov 15 05:36:57 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=1755526047; cv=none; d=zohomail.com; s=zohoarc; b=gcHRzVui/yyuCJRbXMHa1QLSKllSl70tdnfXlQXpbH2JAv9ugTBIj5lBMzyNO4LYc2BuF9dBXtEhDYSb2L4upsO7xvZOWC195QuBlH+AnlXxvpVIjeljEgRS2rV0+ideCCBC+lSXID3/H72/2Byp0grsr2YTQlPJRNIyJmn/+jM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1755526047; 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=mFfBV1uR7UUVO/tCfL9KGV9z2B+nrC4acvDAvbLz5QE=; b=eOVIUcQuRdfD7teJgtPl37gLfm7/IfOpmvSDXDy/ctxs5qzvLxTTEJrHnwg7c4dgjDkP1ci9qjGooJJijpTvOaTbkcvaZ3nJUnmPxy7/L1lnaH8/UEbaFG8/G5Frw2mnisq+xbv0i8cBzc+0Gix9nSOl/6WJjUN1Hpv/hK3aZig= 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 1755526046947454.541884309847; Mon, 18 Aug 2025 07:07:26 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uo0Vz-0001nA-Te; Mon, 18 Aug 2025 10:07:11 -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 1uo0Vy-0001mV-5B for qemu-devel@nongnu.org; Mon, 18 Aug 2025 10:07:10 -0400 Received: from forwardcorp1b.mail.yandex.net ([178.154.239.136]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uo0Vw-0002Cx-F6 for qemu-devel@nongnu.org; Mon, 18 Aug 2025 10:07:09 -0400 Received: from mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net [IPv6:2a02:6b8:c21:2d8b:0:640:7d49:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTPS id 5E2AD807D5; Mon, 18 Aug 2025 17:06:53 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:b25::1:17]) by mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id k6RC4003YeA0-IDsDiw6q; Mon, 18 Aug 2025 17:06:53 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1755526013; bh=mFfBV1uR7UUVO/tCfL9KGV9z2B+nrC4acvDAvbLz5QE=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=V4eR+crRTMxjC/Xpdjz0gZdg0NxzUEKTRF1nRDKxhkCmLWskelvHrcB4FO5f6Z1HN aRnX6geRxXULcuukZeFNfOkL2aeIIwmMybWUKWeeuHHQavk+sx/bjXgsP6xjutpZl2 EsjqnOlX3LGHWCPqU8uQUYzlQ3hchsUoXJ+sOEW0= Authentication-Results: mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: jasowang@redhat.com Cc: qemu-devel@nongnu.org, vsementsov@yandex-team.ru Subject: [PATCH 17/19] net/tap: introduce net_tap_from_monitor_fd() helper Date: Mon, 18 Aug 2025 17:06:43 +0300 Message-ID: <20250818140645.27904-18-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250818140645.27904-1-vsementsov@yandex-team.ru> References: <20250818140645.27904-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=178.154.239.136; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1b.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_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 Precedence: list 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: 1755526052600124100 Content-Type: text/plain; charset="utf-8" Signed-off-by: Vladimir Sementsov-Ogievskiy --- net/tap.c | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/net/tap.c b/net/tap.c index 09c1343ccc..93db3c47f8 100644 --- a/net/tap.c +++ b/net/tap.c @@ -827,6 +827,20 @@ failed: return -1; } =20 +static int net_tap_from_monitor_fd(const Netdev *netdev, NetClientState *p= eer, + const char *name, const char *vhostfdna= me, + int *pvnet_hdr, const char *fdname, + Error **errp) +{ + int fd =3D monitor_fd_param(monitor_cur(), fdname, errp); + if (fd =3D=3D -1) { + return -1; + } + + return net_tap_fd_init_external(netdev, peer, "tap", name, + vhostfdname, pvnet_hdr, fd, errp); +} + static int net_tap_open(const Netdev *netdev, const char *name, NetClientState *peer, @@ -874,7 +888,7 @@ int net_init_tap(const Netdev *netdev, const char *name, NetClientState *peer, Error **errp) { const NetdevTapOptions *tap =3D &netdev->u.tap; - int fd, vnet_hdr =3D 0, i =3D 0; + int vnet_hdr =3D 0, i =3D 0; int ret =3D 0; =20 assert(netdev->type =3D=3D NET_CLIENT_DRIVER_TAP); @@ -906,16 +920,8 @@ int net_init_tap(const Netdev *netdev, const char *nam= e, return -1; } =20 - fd =3D monitor_fd_param(monitor_cur(), tap->fd, errp); - if (fd =3D=3D -1) { - return -1; - } - - ret =3D net_tap_fd_init_external(netdev, peer, "tap", name, - tap->vhostfd, NULL, fd, errp); - if (ret < 0) { - return -1; - } + return net_tap_from_monitor_fd(netdev, peer, name, tap->vhostfd, + NULL, tap->fd, errp); } else if (tap->fds) { g_auto(GStrv) fds =3D NULL; g_auto(GStrv) vhost_fds =3D NULL; @@ -940,14 +946,9 @@ int net_init_tap(const Netdev *netdev, const char *nam= e, =20 vnet_hdr =3D -1; for (i =3D 0; i < nfds; i++) { - fd =3D monitor_fd_param(monitor_cur(), fds[i], errp); - if (fd =3D=3D -1) { - return -1; - } - - ret =3D net_tap_fd_init_external(netdev, peer, "tap", name, + ret =3D net_tap_from_monitor_fd(netdev, peer, name, vhost_fds ? vhost_fds[i] : NULL, - &vnet_hdr, fd, errp); + &vnet_hdr, fds[i], errp); if (ret < 0) { return -1; } --=20 2.48.1 From nobody Sat Nov 15 05:36:57 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=1755526096; cv=none; d=zohomail.com; s=zohoarc; b=kfxrLYSRBZZBTKHCixoth8QXpyMVMpgWUw43wqI2xuH5R1OK79vbhJZdkebgL3tRICI2OFiR1ouLHRlb7wkGVAbTfO0Ez1Q1BSiSbMfBc/SnTop+AlHCOdJvdiJPIgR0q0qbTdwsslb5mjysPprDuEOwC53rk5pN8wIrogWUPuI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1755526096; 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=qurO9nCLOGwJkhLe8okvAExVdaifk8VQ87gE0if9bt8=; b=CZ4+uJE+ofODaQzyqsvS1zn8zk+pKPgpfsnzMsrI18DZAEfXJA4Bs+aDh4Pjcw8lQegPBMmGJC1AN85igJQzcY95ZhJELvjk3QbRtnY6xFo5dXhKZSvwIVDF2auuZCvN8oBoTAYQf4thJ4Kmh/1Qq8GwOkUyMkj+lURtmvKkXUw= 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 1755526096003155.6443040867282; Mon, 18 Aug 2025 07:08:16 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uo0W0-0001nI-B4; Mon, 18 Aug 2025 10:07:12 -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 1uo0Vy-0001mZ-7o for qemu-devel@nongnu.org; Mon, 18 Aug 2025 10:07:10 -0400 Received: from forwardcorp1b.mail.yandex.net ([178.154.239.136]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uo0Vw-0002D2-JM for qemu-devel@nongnu.org; Mon, 18 Aug 2025 10:07:09 -0400 Received: from mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net [IPv6:2a02:6b8:c21:2d8b:0:640:7d49:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTPS id ACDE7807D8; Mon, 18 Aug 2025 17:06:53 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:b25::1:17]) by mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id k6RC4003YeA0-Y3p4N9j0; Mon, 18 Aug 2025 17:06:53 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1755526013; bh=qurO9nCLOGwJkhLe8okvAExVdaifk8VQ87gE0if9bt8=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=eHGnJSwKQk4l5+0QuyRGBvHTyofIejOFRrX4z6QsFUDaHzjz9tJza7Pdm7lar/MEk zSrI/h+LSGmB+t+P6KnNdqq3CNpHYi0YdgMGaHDMIkWBDJNyjBksFKvszkqtZYM5Oc f6F/QkmHM05xE7DYNQBAVTGq61ZF0PYS/vWKobhk= Authentication-Results: mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: jasowang@redhat.com Cc: qemu-devel@nongnu.org, vsementsov@yandex-team.ru Subject: [PATCH 18/19] net/tap: split net_tap_setup_vhost() separate function Date: Mon, 18 Aug 2025 17:06:44 +0300 Message-ID: <20250818140645.27904-19-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250818140645.27904-1-vsementsov@yandex-team.ru> References: <20250818140645.27904-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=178.154.239.136; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1b.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_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 Precedence: list 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: 1755526097417116600 Content-Type: text/plain; charset="utf-8" Signed-off-by: Vladimir Sementsov-Ogievskiy --- net/tap.c | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/net/tap.c b/net/tap.c index 93db3c47f8..fd977b748c 100644 --- a/net/tap.c +++ b/net/tap.c @@ -93,6 +93,8 @@ static int net_init_tap_one(const Netdev *netdev, NetClie= ntState *peer, const char *ifname, const char *script, const char *downscript, const char *vhostfdnam= e, int vnet_hdr, int fd, Error **errp); +static int net_tap_setup_vhost(TAPState *s, const NetdevTapOptions *tap, + const char *vhostfdname, Error **errp); =20 static void tap_update_fd_handler(TAPState *s) { @@ -742,7 +744,7 @@ static int net_init_tap_one(const Netdev *netdev, NetCl= ientState *peer, { const NetdevTapOptions *tap; TAPState *s =3D net_tap_fd_init(peer, model, name, fd, vnet_hdr); - int vhostfd; + int ret; =20 if (netdev->type =3D=3D NET_CLIENT_DRIVER_BRIDGE) { const NetdevBridgeOptions *bridge =3D &netdev->u.bridge; @@ -773,9 +775,25 @@ static int net_init_tap_one(const Netdev *netdev, NetC= lientState *peer, } } =20 + ret =3D net_tap_setup_vhost(s, tap, vhostfdname, errp); + if (ret < 0) { + goto failed; + } + + return 0; + +failed: + qemu_del_net_client(&s->nc); + return -1; +} + +static int net_tap_setup_vhost(TAPState *s, const NetdevTapOptions *tap, + const char *vhostfdname, Error **errp) +{ if (tap->has_vhost ? tap->vhost : vhostfdname || (tap->has_vhostforce && tap->vhostforce)) { VhostNetOptions options; + int vhostfd; =20 options.backend_type =3D VHOST_BACKEND_TYPE_KERNEL; options.net_backend =3D &s->nc; @@ -788,20 +806,20 @@ static int net_init_tap_one(const Netdev *netdev, Net= ClientState *peer, if (vhostfdname) { vhostfd =3D monitor_fd_param(monitor_cur(), vhostfdname, errp); if (vhostfd =3D=3D -1) { - goto failed; + return -1; } if (!set_fd_nonblocking(vhostfd, vhostfdname, errp)) { - goto failed; + return -1; } } 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 -1; } if (!set_fd_nonblocking(vhostfd, "opened /dev/vhost-net", errp= )) { - goto failed; + return -1; } } options.opaque =3D (void *)(uintptr_t)vhostfd; @@ -816,15 +834,11 @@ static int net_init_tap_one(const Netdev *netdev, Net= ClientState *peer, if (!s->vhost_net) { error_setg(errp, "vhost-net requested but could not be initialized"); - goto failed; + return -1; } } =20 return 0; - -failed: - qemu_del_net_client(&s->nc); - return -1; } =20 static int net_tap_from_monitor_fd(const Netdev *netdev, NetClientState *p= eer, --=20 2.48.1 From nobody Sat Nov 15 05:36:57 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=1755526125; cv=none; d=zohomail.com; s=zohoarc; b=c9zFERzTjz9pP/t1EOz4kiX+PEdwJJVMdsvJgbTjzsjUuDO2y/ZY2Hx1pxYYpWo3VdOiQqxCFD3pbJabgOoZ4dXKfqwmqWZR5vf+spXRJ+UuIJiDTsX7gJ646eZrRDKtTxxcapocCOHkN0jL62fvOirM5BMfocHh3FOO5gc6Tq8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1755526125; 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=3d3UPuB7M4BByxpoQwPGncY1dWDIJSAfRsgScbQZ1no=; b=IQu5kS2yr3aJNfS571UzXVoGUEJ0M+KhMkQOEU/nKQDJGS0gSYSlBg2gS/fUNCs/KU5tt8Z7GapHEwLakN+slNvDFogSqSi+UY5FQsImguvV3J6ZvoGLsdSQCT3uvqvbLol50m4Xu9uD6MdK0ZQ0L3POXLQ9VzFDmeO1FzJrRpo= 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 1755526125981284.6960471257653; Mon, 18 Aug 2025 07:08:45 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uo0Vu-0001fJ-HW; Mon, 18 Aug 2025 10:07:06 -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 1uo0Vo-0001MN-UV for qemu-devel@nongnu.org; Mon, 18 Aug 2025 10:07:00 -0400 Received: from forwardcorp1b.mail.yandex.net ([2a02:6b8:c02:900:1:45:d181:df01]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uo0Vm-0002Cz-Ih for qemu-devel@nongnu.org; Mon, 18 Aug 2025 10:07:00 -0400 Received: from mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net [IPv6:2a02:6b8:c21:2d8b:0:640:7d49:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTPS id 13B13807D9; Mon, 18 Aug 2025 17:06:54 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:b25::1:17]) by mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id k6RC4003YeA0-MtpTwyYJ; Mon, 18 Aug 2025 17:06:53 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1755526013; bh=3d3UPuB7M4BByxpoQwPGncY1dWDIJSAfRsgScbQZ1no=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=HlDGjH61G1hlApg+1Cxi3rjRTxlleTQzvlvTpZKK5Pn6u5j1lF2gwrbaFzVCVBQj7 RvOMLZqlBVdSMzp6kTq0dVBjeCIDrmd9+lC49RiUeT8VO1eYGtEfEP5kvDJOwWIIU2 Pl5pMK/nkGDvmvSM/Cw3DQ1TdDQ7YEN9l/1bJXxg= Authentication-Results: mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: jasowang@redhat.com Cc: qemu-devel@nongnu.org, vsementsov@yandex-team.ru Subject: [PATCH 19/19] net/tap: drop net_tap_fd_init() Date: Mon, 18 Aug 2025 17:06:45 +0300 Message-ID: <20250818140645.27904-20-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250818140645.27904-1-vsementsov@yandex-team.ru> References: <20250818140645.27904-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a02:6b8:c02:900:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1b.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list 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: 1755526128682124100 Content-Type: text/plain; charset="utf-8" It's called only from net_init_tap_one(), and there is no semantic reason, why we do part of initialization in one function and continue in another. Let's combine them into one net_tap_fd_init_common(). Signed-off-by: Vladimir Sementsov-Ogievskiy --- net/tap.c | 97 +++++++++++++++++++++++++------------------------------ 1 file changed, 44 insertions(+), 53 deletions(-) diff --git a/net/tap.c b/net/tap.c index fd977b748c..3b7d75e5a5 100644 --- a/net/tap.c +++ b/net/tap.c @@ -88,11 +88,12 @@ static void launch_script(const char *setup_script, con= st char *ifname, static void tap_send(void *opaque); static void tap_writable(void *opaque); =20 -static int net_init_tap_one(const Netdev *netdev, NetClientState *peer, - const char *model, const char *name, - const char *ifname, const char *script, - const char *downscript, const char *vhostfdnam= e, - int vnet_hdr, int fd, Error **errp); +static int net_tap_fd_init_common(const Netdev *netdev, NetClientState *pe= er, + const char *model, const char *name, + const char *ifname, const char *script, + const char *downscript, + const char *vhostfdname, + int vnet_hdr, int fd, Error **errp); static int net_tap_setup_vhost(TAPState *s, const NetdevTapOptions *tap, const char *vhostfdname, Error **errp); =20 @@ -393,42 +394,6 @@ 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) -{ - NetClientState *nc; - TAPState *s; - - nc =3D qemu_new_net_client(&net_tap_info, peer, model, name); - - s =3D DO_UPCAST(TAPState, nc, nc); - - 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; - tap_set_offload(&s->nc, 0, 0, 0, 0, 0, 0, 0); - /* - * Make sure host header length is set correctly in tap: - * it might have been modified by another instance of qemu. - */ - 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; - - s->exit.notify =3D tap_exit_notify; - qemu_add_exit_notifier(&s->exit); - - return s; -} - static void close_all_fds_after_fork(int excluded_fd) { const int skip_fd[] =3D {STDIN_FILENO, STDOUT_FILENO, STDERR_FILENO, @@ -651,9 +616,9 @@ static int net_tap_fd_init_external(const Netdev *netde= v, NetClientState *peer, } } =20 - return net_init_tap_one(netdev, peer, model, name, - NULL, NULL, NULL, - vhostfdname, vnet_hdr, fd, errp); + return net_tap_fd_init_common(netdev, peer, model, name, + NULL, NULL, NULL, + vhostfdname, vnet_hdr, fd, errp); } =20 int net_init_bridge(const Netdev *netdev, const char *name, @@ -723,9 +688,9 @@ static int net_tap_open_one(const Netdev *netdev, } } =20 - ret =3D net_init_tap_one(netdev, peer, "tap", name, ifname, - script, downscript, - tap->vhostfd, vnet_hdr, fd, errp); + ret =3D net_tap_fd_init_common(netdev, peer, "tap", name, ifname, + script, downscript, + tap->vhostfd, vnet_hdr, fd, errp); if (ret < 0) { close(fd); return -1; @@ -736,15 +701,41 @@ static int net_tap_open_one(const Netdev *netdev, =20 #define MAX_TAP_QUEUES 1024 =20 -static int net_init_tap_one(const Netdev *netdev, NetClientState *peer, - const char *model, const char *name, - const char *ifname, const char *script, - const char *downscript, const char *vhostfdnam= e, - int vnet_hdr, int fd, Error **errp) +static int net_tap_fd_init_common(const Netdev *netdev, NetClientState *pe= er, + const char *model, const char *name, + const char *ifname, const char *script, + const char *downscript, + const char *vhostfdname, + int vnet_hdr, int fd, Error **errp) { const NetdevTapOptions *tap; - TAPState *s =3D net_tap_fd_init(peer, model, name, fd, vnet_hdr); int ret; + NetClientState *nc; + TAPState *s; + + nc =3D qemu_new_net_client(&net_tap_info, peer, model, name); + + s =3D DO_UPCAST(TAPState, nc, nc); + + 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; + tap_set_offload(&s->nc, 0, 0, 0, 0, 0, 0, 0); + /* + * Make sure host header length is set correctly in tap: + * it might have been modified by another instance of qemu. + */ + 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; + + s->exit.notify =3D tap_exit_notify; + qemu_add_exit_notifier(&s->exit); =20 if (netdev->type =3D=3D NET_CLIENT_DRIVER_BRIDGE) { const NetdevBridgeOptions *bridge =3D &netdev->u.bridge; --=20 2.48.1