From nobody Sun Sep 28 17:07:10 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=1757609491; cv=none; d=zohomail.com; s=zohoarc; b=GulwVVj2nRbfAp06kJzIku9oFqA+ffDwr8N3ItbUGxqhCO0xE2ynjKcoMc9uA2SwC+phtLwwiqlW+wQCT1K99TpfYC92AuXIfTxzv21azftsDL9R6fPvMUUTF2n6jSKJ2PyXEuSh4cTks/rBIdisE0Tg6Gi9PlX6avYbeRqJmyM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1757609491; 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=OyOqvzoRuRR+qR59yZ7B1V6AlEuto7qGRLZU91LQMBk=; b=U2IAh7FsVa+vRBltpsGMP4YxYBG7Tn0+EZJfMIVxqeAnjXV+/kDuvGaY1bZOtaV6VAJ2bJl8cslP3JhJTOnxwpMqB21ZviloJrkUKQ/bgRB4d/7kM0fqvrG2U6jWsnWyLFBP3oo5J8ZtrFZkHAFXw0qmcK/KJnXT3lLuvLftqpQ= 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 1757609490667324.704000289684; Thu, 11 Sep 2025 09:51:30 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uwkVw-0002wE-I5; Thu, 11 Sep 2025 12:51:16 -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 1uwkVt-0002lQ-LE for qemu-devel@nongnu.org; Thu, 11 Sep 2025 12:51:13 -0400 Received: from forwardcorp1d.mail.yandex.net ([178.154.239.200]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uwkVq-0004AM-1O for qemu-devel@nongnu.org; Thu, 11 Sep 2025 12:51:13 -0400 Received: from mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:94a9:0:640:a3fa:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id 2F022804CA; Thu, 11 Sep 2025 19:51:05 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:b3c::1:2f]) by mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id 2pOVKM0Fka60-rWf8MZRp; Thu, 11 Sep 2025 19:51:04 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1757609464; bh=OyOqvzoRuRR+qR59yZ7B1V6AlEuto7qGRLZU91LQMBk=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=qj+YHDN2zprPRWZdS4mPE7Pp7mNFHmlGKsSB0V+R/GkXuTpON3NiCGJIF6E6NULOU i2POXMeqjFehIqJxScqYRfDsV9vYnPKnM1Cs5OS030fZyQAZ9DsIsWNIOteU36Zel0 x7zuy3Bq++mu3YMTD8gjlTkPQmVNIFWDoWvhL2zA= Authentication-Results: mail-nwsmtp-smtp-corp-main-68.klg.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, leiyang@redhat.com, steven.sistare@oracle.com, yc-core@yandex-team.ru, davydov-max@yandex-team.ru Subject: [PATCH v4 1/8] net/tap: net_init_tap_one(): add return value Date: Thu, 11 Sep 2025 19:50:54 +0300 Message-ID: <20250911165101.1637608-2-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250911165101.1637608-1-vsementsov@yandex-team.ru> References: <20250911165101.1637608-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=178.154.239.200; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1d.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_VALIDITY_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 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: 1757609494304116600 Content-Type: text/plain; charset="utf-8" To avoid error propagation, let's follow common recommendations in include/qapi/error.h and use return boolean value together with errp. Why do we prefer errp-based functions with return value? In short with additional return value we get: - less code to handle error - don't create and set Error object when it's not required (when passed errp=3DNULL) More details in commit message of e3fe3988d7851cac3 "error: Document Error API usage rules" Signed-off-by: Vladimir Sementsov-Ogievskiy Tested-by: Lei Yang --- net/tap.c | 43 +++++++++++++++++-------------------------- 1 file changed, 17 insertions(+), 26 deletions(-) diff --git a/net/tap.c b/net/tap.c index f7df702f97..e023c5f67f 100644 --- a/net/tap.c +++ b/net/tap.c @@ -680,7 +680,7 @@ static int net_tap_init(const NetdevTapOptions *tap, in= t *vnet_hdr, =20 #define MAX_TAP_QUEUES 1024 =20 -static void net_init_tap_one(const NetdevTapOptions *tap, NetClientState *= peer, +static bool 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, @@ -765,10 +765,11 @@ static void net_init_tap_one(const NetdevTapOptions *= tap, NetClientState *peer, goto failed; } =20 - return; + return true; =20 failed: qemu_del_net_client(&s->nc); + return false; } =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,9 @@ int net_init_tap(const Netdev *netdev, const char *nam= e, 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); + if (!net_init_tap_one(tap, peer, "tap", name, NULL, + script, downscript, + vhostfdname, vnet_hdr, fd, errp)) { return -1; } } else if (tap->fds) { @@ -915,12 +912,10 @@ 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); + if (!net_init_tap_one(tap, peer, "tap", name, ifname, + script, downscript, + tap->vhostfds ? vhost_fds[i] : NULL, + vnet_hdr, fd, errp)) { ret =3D -1; goto free_fail; } @@ -961,11 +956,9 @@ 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); + if (!net_init_tap_one(tap, peer, "bridge", name, ifname, + script, downscript, vhostfdname, + vnet_hdr, fd, errp)) { close(fd); return -1; } @@ -1006,12 +999,10 @@ 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); + if (!net_init_tap_one(tap, peer, "tap", name, ifname, + i >=3D 1 ? "no" : script, + i >=3D 1 ? "no" : downscript, + vhostfdname, vnet_hdr, fd, errp)) { close(fd); return -1; } --=20 2.48.1 From nobody Sun Sep 28 17:07:10 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=1757609614; cv=none; d=zohomail.com; s=zohoarc; b=NooMACy9PXS++RdtFl5VBVf+gfvp59/YEDLo4Q36ZJYnYn+dstKaybvwSCZzdNqEAb6V+cnDWuBAm+nhGWWkR2jLrgTpr6TqCjAv7scoLAGtJxSHQZ+rGfcS3BztBKJ7FrqPkVMryT+mdhN0JpBWQTwUURDWlUfVI+sSM7Mjk8U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1757609614; 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=0ooFnJ5mdkGdKd3/GRUX63tfFBQ1KtWG9Z6i7YLvLkY=; b=ae1FyxGEAhM2b59dlp3g9GjWPBuVswmKVxVkhyfjcLpRimES5W3AY9H7gtXp4qzRvz/8ZmIl/Er1luwosCR5YrScXjW1y8j7IzTw8RnQe7ckJjwwa2I1/MU7QuOgfoxRCRyHipYh+IaAjq+Qa0Kgpu1WmWJDwTQcBgXyHPzIG+E= 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 1757609614144827.5700639939228; Thu, 11 Sep 2025 09:53:34 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uwkVx-00030r-J8; Thu, 11 Sep 2025 12:51:17 -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 1uwkVu-0002lm-Fw for qemu-devel@nongnu.org; Thu, 11 Sep 2025 12:51:14 -0400 Received: from forwardcorp1d.mail.yandex.net ([178.154.239.200]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uwkVq-0004AP-1K for qemu-devel@nongnu.org; Thu, 11 Sep 2025 12:51:13 -0400 Received: from mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:94a9:0:640:a3fa:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id D067B8071F; Thu, 11 Sep 2025 19:51:05 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:b3c::1:2f]) by mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id 2pOVKM0Fka60-Byp6w9Sg; Thu, 11 Sep 2025 19:51:05 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1757609465; bh=0ooFnJ5mdkGdKd3/GRUX63tfFBQ1KtWG9Z6i7YLvLkY=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=YEdZtwt6tow/fGXn8U6O/iHwapH9MA5uTsOFR/BAF32TrX+3HmsA9Thb5ZsoXfEet T1aKEI5r6AsthSKwqwZXsS455XiVNtG24JohO+28hAXJylAzVzeXVCsN57trHqfBfG 4zLN6nG8Mdcxd4HI8Mg0nkxREwT6S08mWUdnpPkY= Authentication-Results: mail-nwsmtp-smtp-corp-main-68.klg.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, leiyang@redhat.com, steven.sistare@oracle.com, yc-core@yandex-team.ru, davydov-max@yandex-team.ru Subject: [PATCH v4 2/8] net/tap: rework tap_set_sndbuf() Date: Thu, 11 Sep 2025 19:50:55 +0300 Message-ID: <20250911165101.1637608-3-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250911165101.1637608-1-vsementsov@yandex-team.ru> References: <20250911165101.1637608-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=178.154.239.200; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1d.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_VALIDITY_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 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: 1757609614947116600 Content-Type: text/plain; charset="utf-8" First, follow common recommendations to avoid error propagation: add return value. Second, keep NetdevTapOptions related logic in tap.c, and make tap_set_sndbuf a simple system call wrapper, more like other functions in tap-linux.c Signed-off-by: Vladimir Sementsov-Ogievskiy Tested-by: Lei Yang --- net/tap-bsd.c | 3 ++- net/tap-linux.c | 19 +++++-------------- net/tap-solaris.c | 3 ++- net/tap-stub.c | 3 ++- net/tap.c | 10 +++++++--- net/tap_int.h | 4 +--- 6 files changed, 19 insertions(+), 23 deletions(-) diff --git a/net/tap-bsd.c b/net/tap-bsd.c index b4c84441ba..3bfc1cc577 100644 --- a/net/tap-bsd.c +++ b/net/tap-bsd.c @@ -198,8 +198,9 @@ error: } #endif /* __FreeBSD__ */ =20 -void tap_set_sndbuf(int fd, const NetdevTapOptions *tap, Error **errp) +bool tap_set_sndbuf(int fd, int sndbuf, Error **errp) { + return true; } =20 int tap_probe_vnet_hdr(int fd, Error **errp) diff --git a/net/tap-linux.c b/net/tap-linux.c index 22ec2f45d2..c46f488c08 100644 --- a/net/tap-linux.c +++ b/net/tap-linux.c @@ -138,23 +138,14 @@ int tap_open(char *ifname, int ifname_size, int *vnet= _hdr, * Ethernet NICs generally have txqueuelen=3D1000, so 1Mb is * a good value, given a 1500 byte MTU. */ -#define TAP_DEFAULT_SNDBUF 0 - -void tap_set_sndbuf(int fd, const NetdevTapOptions *tap, Error **errp) +bool tap_set_sndbuf(int fd, int sndbuf, Error **errp) { - int sndbuf; - - sndbuf =3D !tap->has_sndbuf ? TAP_DEFAULT_SNDBUF : - tap->sndbuf > INT_MAX ? INT_MAX : - tap->sndbuf; - - if (!sndbuf) { - sndbuf =3D INT_MAX; - } - - if (ioctl(fd, TUNSETSNDBUF, &sndbuf) =3D=3D -1 && tap->has_sndbuf) { + if (ioctl(fd, TUNSETSNDBUF, &sndbuf) =3D=3D -1) { error_setg_errno(errp, errno, "TUNSETSNDBUF ioctl failed"); + return false; } + + return true; } =20 int tap_probe_vnet_hdr(int fd, Error **errp) diff --git a/net/tap-solaris.c b/net/tap-solaris.c index 51b7830bef..2932c2de39 100644 --- a/net/tap-solaris.c +++ b/net/tap-solaris.c @@ -202,8 +202,9 @@ int tap_open(char *ifname, int ifname_size, int *vnet_h= dr, return fd; } =20 -void tap_set_sndbuf(int fd, const NetdevTapOptions *tap, Error **errp) +bool tap_set_sndbuf(int fd, int sndbuf, Error **errp) { + return true; } =20 int tap_probe_vnet_hdr(int fd, Error **errp) diff --git a/net/tap-stub.c b/net/tap-stub.c index 38673434cb..326e76843e 100644 --- a/net/tap-stub.c +++ b/net/tap-stub.c @@ -33,8 +33,9 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr, return -1; } =20 -void tap_set_sndbuf(int fd, const NetdevTapOptions *tap, Error **errp) +bool tap_set_sndbuf(int fd, int sndbuf, Error **errp) { + return true; } =20 int tap_probe_vnet_hdr(int fd, Error **errp) diff --git a/net/tap.c b/net/tap.c index e023c5f67f..2ffd8c9907 100644 --- a/net/tap.c +++ b/net/tap.c @@ -690,9 +690,13 @@ static bool net_init_tap_one(const NetdevTapOptions *t= ap, NetClientState *peer, TAPState *s =3D net_tap_fd_init(peer, model, name, fd, vnet_hdr); int vhostfd; =20 - tap_set_sndbuf(s->fd, tap, &err); - if (err) { - error_propagate(errp, err); + /* 0 means no limit, so set INT_MAX. Same is the default */ + int sndbuf =3D + (tap->has_sndbuf && tap->sndbuf) ? MIN(tap->sndbuf, INT_MAX) : INT= _MAX; + + /* Ignore error when sndbuf was not requested */ + if (!tap_set_sndbuf(s->fd, sndbuf, tap->has_sndbuf ? errp : NULL) + && tap->has_sndbuf) { goto failed; } =20 diff --git a/net/tap_int.h b/net/tap_int.h index 8857ff299d..08e4a592a0 100644 --- a/net/tap_int.h +++ b/net/tap_int.h @@ -26,14 +26,12 @@ #ifndef NET_TAP_INT_H #define NET_TAP_INT_H =20 -#include "qapi/qapi-types-net.h" - int tap_open(char *ifname, int ifname_size, int *vnet_hdr, int vnet_hdr_required, int mq_required, Error **errp); =20 ssize_t tap_read_packet(int tapfd, uint8_t *buf, int maxlen); =20 -void tap_set_sndbuf(int fd, const NetdevTapOptions *tap, Error **errp); +bool tap_set_sndbuf(int fd, int sndbuf, Error **errp); int tap_probe_vnet_hdr(int fd, Error **errp); int tap_probe_has_ufo(int fd); int tap_probe_has_uso(int fd); --=20 2.48.1 From nobody Sun Sep 28 17:07:10 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=1757609573; cv=none; d=zohomail.com; s=zohoarc; b=dnvgG/a2JTziYrIOAyu6TQmnzIyBUE7jjlQJ6XnXZioINah7j6EC/ACRnzYLFmIgpCPKGlWfYfVF8Fs8H7Aemw9FO08XVeNqS1UoRIvuwuQzXK0/w+zLzn53ChpVGX2PqwMJVGIZqJtoHBNsgVBj6e1r76ecaoTRPda4gob9I9U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1757609573; 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=D73cNTnWcybuDLyY0oDLUZRiSjUAGGTfs8skyWxc7BU=; b=WbqF0GYeYBAibYxK8lKlJow99h1XZh2eQ9UcmmJxvHF4aK8F4MOZc2cW0gHLWphW0zmmZbF0vM1F9NEDXGt6jM4eF+fgZTXTsNLkFfLFaGrPy+UlKsF5fINzRCTwwDV/U1/LC7E1N/8M4cEC7t0jKJY7qpvWtQt0mWfKR7vIfkE= 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 17576095730451012.8910251993451; Thu, 11 Sep 2025 09:52:53 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uwkVu-0002la-CZ; Thu, 11 Sep 2025 12:51:14 -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 1uwkVs-0002jM-4U for qemu-devel@nongnu.org; Thu, 11 Sep 2025 12:51:12 -0400 Received: from forwardcorp1d.mail.yandex.net ([2a02:6b8:c41:1300:1:45:d181:df01]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uwkVq-0004AR-49 for qemu-devel@nongnu.org; Thu, 11 Sep 2025 12:51:11 -0400 Received: from mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:94a9:0:640:a3fa:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id 50C418071E; Thu, 11 Sep 2025 19:51:06 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:b3c::1:2f]) by mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id 2pOVKM0Fka60-Ufp6dNmx; Thu, 11 Sep 2025 19:51:05 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1757609465; bh=D73cNTnWcybuDLyY0oDLUZRiSjUAGGTfs8skyWxc7BU=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=Zjf2a+MZGInMLUkd6zMbzS0Z1JVjln75+baBOK5SiwAnxlbDgcGGlbicQJWeHJmJE f1B/6akch44jtZ3YryEy9ZV2r81dSnABsfvDG3nfPO8mZKi/R4ejVvwxE+OzG3XyRt EygMWlZ6xcedpDZvfjgOaNzc9mpsmUP9svrpBDuU= Authentication-Results: mail-nwsmtp-smtp-corp-main-68.klg.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, leiyang@redhat.com, steven.sistare@oracle.com, yc-core@yandex-team.ru, davydov-max@yandex-team.ru Subject: [PATCH v4 3/8] net/tap: net_init_tap_one(): drop extra error propagation Date: Thu, 11 Sep 2025 19:50:56 +0300 Message-ID: <20250911165101.1637608-4-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250911165101.1637608-1-vsementsov@yandex-team.ru> References: <20250911165101.1637608-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a02:6b8:c41:1300:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1d.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1757609574381116600 Content-Type: text/plain; charset="utf-8" Signed-off-by: Vladimir Sementsov-Ogievskiy Tested-by: Lei Yang --- net/tap.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/net/tap.c b/net/tap.c index 2ffd8c9907..49d4a29beb 100644 --- a/net/tap.c +++ b/net/tap.c @@ -686,7 +686,6 @@ static bool net_init_tap_one(const NetdevTapOptions *ta= p, NetClientState *peer, const char *downscript, const char *vhostfdna= me, int vnet_hdr, int fd, Error **errp) { - Error *err =3D NULL; TAPState *s =3D net_tap_fd_init(peer, model, name, fd, vnet_hdr); int vhostfd; =20 @@ -728,9 +727,8 @@ static bool net_init_tap_one(const NetdevTapOptions *ta= p, NetClientState *peer, } =20 if (vhostfdname) { - vhostfd =3D monitor_fd_param(monitor_cur(), vhostfdname, &err); + vhostfd =3D monitor_fd_param(monitor_cur(), vhostfdname, errp); if (vhostfd =3D=3D -1) { - error_propagate(errp, err); goto failed; } if (!g_unix_set_fd_nonblocking(vhostfd, true, NULL)) { --=20 2.48.1 From nobody Sun Sep 28 17:07:10 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=1757609561; cv=none; d=zohomail.com; s=zohoarc; b=V+BeUxaiG0cSU2eC6dSk6dQjLcF8KCrABhBDCvVgAW6r+xv67r160VxQe02l+T876qWTVolq4TF0LTZxHxcBjZBO/ZZURG8di0gSCElPtH+7UPqjRM+h639Cum7nulSKi+5QpKuUqgqFkN3svvM8QbNhcknEUjCsj+9dS0Ib5kE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1757609561; 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=lDIFm/NciBS2F0gopRTcAo1Mra2x5xPBU6oXwYj0/tM=; b=a40k4GTHpIoWBNNVzBge/3XGuQGvAJwK7uCb9AzZb2JIb84mUXDaYTysM51dxlPvYkg4y7PZ1QgmG17pKtYfGzoVGimFLAE7NFeI26mpEDk1SWJp0Z4G12a2ROMCF2U4pLet3BIhMG/c+FvJ063RSDsZ/H8z0H2XFtWL+o5IUXc= 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 1757609561635430.3189528410903; Thu, 11 Sep 2025 09:52:41 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uwkW5-00038R-6q; Thu, 11 Sep 2025 12:51:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uwkVx-0002wv-0X for qemu-devel@nongnu.org; Thu, 11 Sep 2025 12:51:17 -0400 Received: from forwardcorp1d.mail.yandex.net ([178.154.239.200]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uwkVq-0004AU-9L for qemu-devel@nongnu.org; Thu, 11 Sep 2025 12:51:16 -0400 Received: from mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:94a9:0:640:a3fa:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id C47B980730; Thu, 11 Sep 2025 19:51:06 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:b3c::1:2f]) by mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id 2pOVKM0Fka60-F8iLlU56; Thu, 11 Sep 2025 19:51:06 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1757609466; bh=lDIFm/NciBS2F0gopRTcAo1Mra2x5xPBU6oXwYj0/tM=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=nqcqCzIbG47ovPYUfVqm/WI9mPE+YnLvITMVd3CkZgCwVqEamu8H27fuDWTiCP1NB 5VxReN2VeS3roMzDrK3g1B7wpT0k2Bo3Ig3BuVbCUYEqi/k8ltLC0C61Fsl1JbyiUK pbWvZ7P2yo5zvpX/bM34CAr+zaQpA4o7E8fA9oJs= Authentication-Results: mail-nwsmtp-smtp-corp-main-68.klg.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, leiyang@redhat.com, steven.sistare@oracle.com, yc-core@yandex-team.ru, davydov-max@yandex-team.ru Subject: [PATCH v4 4/8] net/tap: launch_script(): add return value Date: Thu, 11 Sep 2025 19:50:57 +0300 Message-ID: <20250911165101.1637608-5-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250911165101.1637608-1-vsementsov@yandex-team.ru> References: <20250911165101.1637608-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=178.154.239.200; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1d.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_VALIDITY_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 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: 1757609562506116600 Content-Type: text/plain; charset="utf-8" Follow common recommendations to avoid error propagation. Signed-off-by: Vladimir Sementsov-Ogievskiy Tested-by: Lei Yang --- net/tap.c | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/net/tap.c b/net/tap.c index 49d4a29beb..13118515b9 100644 --- a/net/tap.c +++ b/net/tap.c @@ -82,7 +82,7 @@ typedef struct TAPState { Notifier exit; } TAPState; =20 -static void launch_script(const char *setup_script, const char *ifname, +static bool launch_script(const char *setup_script, const char *ifname, int fd, Error **errp); =20 static void tap_send(void *opaque); @@ -439,7 +439,7 @@ static void close_all_fds_after_fork(int excluded_fd) qemu_close_all_open_fd(skip_fd, nskip); } =20 -static void launch_script(const char *setup_script, const char *ifname, +static bool launch_script(const char *setup_script, const char *ifname, int fd, Error **errp) { int pid, status; @@ -451,8 +451,9 @@ static void launch_script(const char *setup_script, con= st char *ifname, if (pid < 0) { error_setg_errno(errp, errno, "could not launch network script %s", setup_script); - return; + return false; } + if (pid =3D=3D 0) { close_all_fds_after_fork(fd); parg =3D args; @@ -461,17 +462,20 @@ static void launch_script(const char *setup_script, c= onst char *ifname, *parg =3D NULL; execv(setup_script, args); _exit(1); - } else { - while (waitpid(pid, &status, 0) !=3D pid) { - /* loop */ - } + } =20 - if (WIFEXITED(status) && WEXITSTATUS(status) =3D=3D 0) { - return; - } - error_setg(errp, "network script %s failed with status %d", - setup_script, status); + while (waitpid(pid, &status, 0) !=3D pid) { + /* loop */ } + + if (WIFEXITED(status) && WEXITSTATUS(status) =3D=3D 0) { + return true; + } + + error_setg(errp, "network script %s failed with status %d", + setup_script, status); + + return false; } =20 static int recv_fd(int c) @@ -647,7 +651,6 @@ static int net_tap_init(const NetdevTapOptions *tap, in= t *vnet_hdr, const char *setup_script, char *ifname, size_t ifname_sz, int mq_required, Error **errp) { - Error *err =3D NULL; int fd, vnet_hdr_required; =20 if (tap->has_vnet_hdr) { @@ -667,9 +670,7 @@ static int net_tap_init(const NetdevTapOptions *tap, in= t *vnet_hdr, if (setup_script && setup_script[0] !=3D '\0' && strcmp(setup_script, "no") !=3D 0) { - launch_script(setup_script, ifname, fd, &err); - if (err) { - error_propagate(errp, err); + if (!launch_script(setup_script, ifname, fd, errp)) { close(fd); return -1; } --=20 2.48.1 From nobody Sun Sep 28 17:07:10 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=1757609574; cv=none; d=zohomail.com; s=zohoarc; b=CG90bt2Kb16LplSbCJAFFNgkzDkaoG22f7LLYKf6hKWMYPtHEJeLYXu7bc11jhGZL6RIeV0xzGJIcCbIw9KZcyNDeK3kq56w0YanUWdvG96dEHSZeHxPnmz76YnMMqjd6n0a0GeoO0/BN/wNWIbkJgvpcN/RwO/YPjwzve6k0g0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1757609574; 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=l9OMayB/diwN3o/DExcDYrWOhjRVDUz+kxS1Yv7vtJY=; b=SYoYbtn/WrLSsLCEJN5bw/rfPQvqV3LF0zarHrOpm8l57YJYdXbmjafw39qo/811/PJ1+An9tMSkQ+gNZkDUIj1lJ+O+2/rMB2RPDYOVybQW8gf8PmmyYXSp7hQfMXpznIHKrxvzLgpk//kCK1LNO3bZCrIfvT7Z4RVo5P+w5jw= 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 1757609574087153.21803633333934; Thu, 11 Sep 2025 09:52:54 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uwkVz-00037H-7L; Thu, 11 Sep 2025 12:51:19 -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 1uwkVw-0002wG-3M for qemu-devel@nongnu.org; Thu, 11 Sep 2025 12:51:16 -0400 Received: from forwardcorp1d.mail.yandex.net ([178.154.239.200]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uwkVq-0004Ab-97 for qemu-devel@nongnu.org; Thu, 11 Sep 2025 12:51:15 -0400 Received: from mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:94a9:0:640:a3fa:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id 365F88076D; Thu, 11 Sep 2025 19:51:07 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:b3c::1:2f]) by mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id 2pOVKM0Fka60-95w6YC4d; Thu, 11 Sep 2025 19:51:06 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1757609466; bh=l9OMayB/diwN3o/DExcDYrWOhjRVDUz+kxS1Yv7vtJY=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=CvnBUGxwR8TwyjB2Ec/WDflq0DBFjejZGcTgSNM/EPbbHGA8bMbSnmPi1bvKeUoV0 4bXCCQgP0S6wAAB/tVgXd20TkVbENKOxzstiE/zCOEUKUxVoUbxCMt4Ga4fIMi649s Ap5ZUwqrHh9HNBl93ILE+aLxBFz/I8rTnnzvRQ6c= Authentication-Results: mail-nwsmtp-smtp-corp-main-68.klg.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, leiyang@redhat.com, steven.sistare@oracle.com, yc-core@yandex-team.ru, davydov-max@yandex-team.ru Subject: [PATCH v4 5/8] net/tap: net_init_tap_one(): move parameter checking earlier Date: Thu, 11 Sep 2025 19:50:58 +0300 Message-ID: <20250911165101.1637608-6-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250911165101.1637608-1-vsementsov@yandex-team.ru> References: <20250911165101.1637608-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=178.154.239.200; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1d.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_VALIDITY_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 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: 1757609574396116600 Content-Type: text/plain; charset="utf-8" Let's keep all similar argument checking in net_init_tap() function. Signed-off-by: Vladimir Sementsov-Ogievskiy Tested-by: Lei Yang --- net/tap.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/net/tap.c b/net/tap.c index 13118515b9..257290f06b 100644 --- a/net/tap.c +++ b/net/tap.c @@ -763,9 +763,6 @@ static bool net_init_tap_one(const NetdevTapOptions *ta= p, NetClientState *peer, "vhost-net requested but could not be initialized"); goto failed; } - } else if (vhostfdname) { - error_setg(errp, "vhostfd(s)=3D is not valid without vhost"); - goto failed; } =20 return true; @@ -827,6 +824,11 @@ int net_init_tap(const Netdev *netdev, const char *nam= e, return -1; } =20 + if (tap->has_vhost && !tap->vhost && (tap->vhostfds || tap->vhostfd)) { + error_setg(errp, "vhostfd(s)=3D is not valid without vhost"); + return -1; + } + if (tap->fd) { if (tap->ifname || tap->script || tap->downscript || tap->has_vnet_hdr || tap->helper || tap->has_queues || --=20 2.48.1 From nobody Sun Sep 28 17:07:10 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=1757609615; cv=none; d=zohomail.com; s=zohoarc; b=gbz2/ot2hTYUy44OpMv8p7jaru0tN/pQ7sxQhps50DWJuFueiqDPrF6ZPjRaFvhvD3fAOUUSvr7b0TgbHef1WxbQwjPTltuuVNo5wAjtm9v5s1oVIbhgUyFLzDEyNJSj09zmIGhmaQQPL8o+58aREflYZGR6HksRtdIpPvypzlI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1757609615; 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=meCRCih9ZiD5d2tMU7VeKv9KexoM7K/oh14kEeMF7fc=; b=Op5AabSIHYAPznN5Mmp6IJ1w5+RF62F57itiwUvDeZGwxd7hXDsGmLqgEUhmCRCHl33rLAvavfvwC2EnwamlDK3FORqwDeW7ZaUCx98RjVJQMESFDNdBaSXgrlZMzM2DkbwDKvKx7iogcpmFPBaW+77WpBd0RJoqV2oPfFv+G7g= 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 175760961531392.45071056608731; Thu, 11 Sep 2025 09:53:35 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uwkVv-0002vy-QZ; Thu, 11 Sep 2025 12:51:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uwkVt-0002lP-KV for qemu-devel@nongnu.org; Thu, 11 Sep 2025 12:51:13 -0400 Received: from forwardcorp1d.mail.yandex.net ([2a02:6b8:c41:1300:1:45:d181:df01]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uwkVq-0004Ag-97 for qemu-devel@nongnu.org; Thu, 11 Sep 2025 12:51:13 -0400 Received: from mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:94a9:0:640:a3fa:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id A949280795; Thu, 11 Sep 2025 19:51:07 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:b3c::1:2f]) by mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id 2pOVKM0Fka60-2ccDHXt0; Thu, 11 Sep 2025 19:51:07 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1757609467; bh=meCRCih9ZiD5d2tMU7VeKv9KexoM7K/oh14kEeMF7fc=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=kUDKmnnLa0nE9af4cmIkdc+eqajtaw9zhca4Uo/6g5L40gwj9FlTCPTRcCPQw9II5 PdV9rvLG9llPQjALRAREMww7mVZnbo8wbWPWjM4Rkngrjut/I7eF3ensC+qdPqJjJH Fphd0fN9DidOIzXr03z2adimiH1c9yCTUnv65pm4= Authentication-Results: mail-nwsmtp-smtp-corp-main-68.klg.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, leiyang@redhat.com, steven.sistare@oracle.com, yc-core@yandex-team.ru, davydov-max@yandex-team.ru Subject: [PATCH v4 6/8] net/tap: net_init_tap(): refactor parameter checking Date: Thu, 11 Sep 2025 19:50:59 +0300 Message-ID: <20250911165101.1637608-7-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250911165101.1637608-1-vsementsov@yandex-team.ru> References: <20250911165101.1637608-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a02:6b8:c41:1300:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1d.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1757609616826116600 Content-Type: text/plain; charset="utf-8" Unite duplicated checks of different code paths. Signed-off-by: Vladimir Sementsov-Ogievskiy Tested-by: Lei Yang --- net/tap.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/net/tap.c b/net/tap.c index 257290f06b..9b0ff70cf2 100644 --- a/net/tap.c +++ b/net/tap.c @@ -829,12 +829,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; } @@ -867,12 +872,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 Sun Sep 28 17:07:10 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=1757609589; cv=none; d=zohomail.com; s=zohoarc; b=QYYMyWy9NF9qZYz8GO6nEysGG/N0Gs24q/a2tdNQOSTi4IOcJr2l8fxUNZpAt7cLDEww74vZ0O+qG31IBU7eYqUInkM0g3S1G7VwKYwRaZ3FBq/l3RZHK4XuQfeEsEY9BeXmqP0Hq2ls3Hc5YHynEC7fqoZ2sw5gxmBkkwAtujE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1757609589; 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=mL60+yvxLhyujWvQbaf2IDcS9XPHKjBpReGt18aEJ7g=; b=Yu4QjWMNdblM1YgeVSER7rp8eE1qe13KyDRby8JXDdJewcA3APdFWYBB9auBHs12/Q5FXKBo/8YJfh9981ZKpIxfbolQICOTocaCugJBw+gOBP5W1tHfVGgZrxSw6tHag8fptuDMkz+WAX55YQymm8WMq7w414K7sTxqvQ04mHA= 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 1757609589447864.9588749023828; Thu, 11 Sep 2025 09:53:09 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uwkVy-00036x-NW; Thu, 11 Sep 2025 12:51:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uwkVu-0002r6-SH for qemu-devel@nongnu.org; Thu, 11 Sep 2025 12:51:14 -0400 Received: from forwardcorp1d.mail.yandex.net ([2a02:6b8:c41:1300:1:45:d181:df01]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uwkVr-0004Ao-0H for qemu-devel@nongnu.org; Thu, 11 Sep 2025 12:51:14 -0400 Received: from mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:94a9:0:640:a3fa:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id 2174E80792; Thu, 11 Sep 2025 19:51:08 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:b3c::1:2f]) by mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id 2pOVKM0Fka60-pJTsubfx; Thu, 11 Sep 2025 19:51:07 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1757609467; bh=mL60+yvxLhyujWvQbaf2IDcS9XPHKjBpReGt18aEJ7g=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=N7nyHVTdGB4HXzLXqs1Rki+/QEGEMInsoOeqsf6XAbFO216kqfHuTXEorSAYImJAV AbD0Gmi0yOZQuYZsCbDPvHDdvHCToAWXyUlPvr69CaAxJWoRbCROYT/VRm0JlflW7Q oSWBqpMpSYs6pZdAHYbonzNHT1yqPdqFCJ08mhEk= Authentication-Results: mail-nwsmtp-smtp-corp-main-68.klg.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, leiyang@redhat.com, steven.sistare@oracle.com, yc-core@yandex-team.ru, davydov-max@yandex-team.ru Subject: [PATCH v4 7/8] net/tap: net_init_tap(): drop extra variable vhostfdname Date: Thu, 11 Sep 2025 19:51:00 +0300 Message-ID: <20250911165101.1637608-8-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250911165101.1637608-1-vsementsov@yandex-team.ru> References: <20250911165101.1637608-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a02:6b8:c41:1300:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1d.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1757609590717116600 Content-Type: text/plain; charset="utf-8" Signed-off-by: Vladimir Sementsov-Ogievskiy Tested-by: Lei Yang --- net/tap.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/net/tap.c b/net/tap.c index 9b0ff70cf2..70ebe0c752 100644 --- a/net/tap.c +++ b/net/tap.c @@ -806,14 +806,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 if (!net_init_tap_one(tap, peer, "tap", name, NULL, script, downscript, - vhostfdname, vnet_hdr, fd, errp)) { + tap->vhostfd, vnet_hdr, fd, errp)) { return -1; } } else if (tap->fds) { @@ -961,7 +959,7 @@ free_fail: } =20 if (!net_init_tap_one(tap, peer, "bridge", name, ifname, - script, downscript, vhostfdname, + script, downscript, tap->vhostfd, vnet_hdr, fd, errp)) { close(fd); return -1; @@ -1006,7 +1004,7 @@ free_fail: if (!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)) { close(fd); return -1; } --=20 2.48.1 From nobody Sun Sep 28 17:07:10 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=1757609515; cv=none; d=zohomail.com; s=zohoarc; b=WsQGGi8/IopQFeZkjf3HRnPNCOnGYukShVnSbjjBwnGqmAbLFn0mr1XpClSg89SvKUO8rNhAiQDdK7ZviVbymNC30TtbZNh3ZkOYueVdzGJd29jTvHVOBVbl5Qsk9A5qokoOCV2CJp5j+S6zwX986uEBM4m8DoP0HKPLtE1JSZY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1757609515; 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=eJ3HD6jryrgptt1wCimqF9otPGpP21C0gDC98NJaLv0=; b=eVE2aYoarox9SY70IJIS2k8hzUbTyaRnOnUhsIuesHwy1+4qnWbGBMXO7h3XeXveeqKJnm3heIrgWg9QmQhRF/q0DybXK+CWgHEzyVt48royIm0lyFJ4atjKqSj2XrKnBg7rtqBEtr/6APpEZN77GzchnPp0mWFYYfmVwjCpG3M= 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 1757609515636587.4354193384568; Thu, 11 Sep 2025 09:51:55 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uwkW1-00037z-Le; Thu, 11 Sep 2025 12:51:21 -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 1uwkVv-0002t3-5n for qemu-devel@nongnu.org; Thu, 11 Sep 2025 12:51:15 -0400 Received: from forwardcorp1d.mail.yandex.net ([2a02:6b8:c41:1300:1:45:d181:df01]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uwkVr-0004As-DO for qemu-devel@nongnu.org; Thu, 11 Sep 2025 12:51:14 -0400 Received: from mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:94a9:0:640:a3fa:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id 925BA807B0; Thu, 11 Sep 2025 19:51:08 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:b3c::1:2f]) by mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id 2pOVKM0Fka60-aFGvYJGI; Thu, 11 Sep 2025 19:51:08 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1757609468; bh=eJ3HD6jryrgptt1wCimqF9otPGpP21C0gDC98NJaLv0=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=lmcr2AUyOSDfB4HYuk/PbC6Jwa1GQ7v+TDLxmgLA5zAytbKd+yNr22BsGvifIUfcK xbvPzJZMPImZVBmMmbEkVhtJ3sj3VpzySU1nV20xfmHOX0xUtRWimf9/08zx7QB347 uybLFaKDoLDOTBhOGmRkq6iLwOfNxud9kQ7wPl6U= Authentication-Results: mail-nwsmtp-smtp-corp-main-68.klg.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, leiyang@redhat.com, steven.sistare@oracle.com, yc-core@yandex-team.ru, davydov-max@yandex-team.ru Subject: [PATCH v4 8/8] net/tap: move local variables related to the latter case to else branch Date: Thu, 11 Sep 2025 19:51:01 +0300 Message-ID: <20250911165101.1637608-9-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250911165101.1637608-1-vsementsov@yandex-team.ru> References: <20250911165101.1637608-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a02:6b8:c41:1300:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1d.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1757609517970116600 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 Tested-by: Lei Yang --- net/tap.c | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/net/tap.c b/net/tap.c index 70ebe0c752..ce090582e0 100644 --- a/net/tap.c +++ b/net/tap.c @@ -801,19 +801,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 if (!net_init_tap_one(tap, peer, "tap", name, NULL, - script, downscript, + NULL, NULL, tap->vhostfd, vnet_hdr, fd, errp)) { return -1; } @@ -916,8 +908,8 @@ int net_init_tap(const Netdev *netdev, const char *name, goto free_fail; } =20 - if (!net_init_tap_one(tap, peer, "tap", name, ifname, - script, downscript, + if (!net_init_tap_one(tap, peer, "tap", name, NULL, + NULL, NULL, tap->vhostfds ? vhost_fds[i] : NULL, vnet_hdr, fd, errp)) { ret =3D -1; @@ -958,15 +950,20 @@ free_fail: return -1; } =20 - if (!net_init_tap_one(tap, peer, "bridge", name, ifname, - script, downscript, tap->vhostfd, + if (!net_init_tap_one(tap, peer, "bridge", name, NULL, + NULL, NULL, tap->vhostfd, vnet_hdr, fd, errp)) { 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