From nobody Sun Sep 28 16:35:29 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1758621961; cv=none; d=zohomail.com; s=zohoarc; b=bZ5n3uedal34rZiMOZV3EpcZsal0wdU+QOPScg98ep47uWlwipJqgoiw1pniF85aQTcpPEui/lSQ/tf5Bk8kdvuNHOYx3NjlNIflRqIJlSiXKLJM/+gy8iFF0h7bs18IuhYi4AGTNdz3XyP0RR97nsjJ7cyc3pmeO+vN1RWsFhE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758621961; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=J+j4+PwNItZRsNYaJicaECJgV/GseY0I8xoBomuNEiM=; b=hT81gvn9XLHd4iMwBpE0KWR6ZVLfVB2WAeql9oON2dHgHAqXp7dlO63wZME1cmavDVioCZJwLaPsvXvFq+35/wo0o+BuKMRmBFGTv3h8XDVzGA1ejzi5uogWE9q/Wnu54IF/uUWC5RuOidjdCWlW0HRp/OTjwGgZ5Ms4CrdtvDY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1758621961571487.5293595288996; Tue, 23 Sep 2025 03:06:01 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v0zq3-0002ll-Oo; Tue, 23 Sep 2025 06:01:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v0zpx-0002hc-15 for qemu-devel@nongnu.org; Tue, 23 Sep 2025 06:01:29 -0400 Received: from forwardcorp1d.mail.yandex.net ([178.154.239.200]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v0zpo-0000tA-3m for qemu-devel@nongnu.org; Tue, 23 Sep 2025 06:01:27 -0400 Received: from mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:cf2d:0:640:140f:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id 0BD71804E6; Tue, 23 Sep 2025 13:01:16 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:b38::1:12]) by mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id C1Ug0C0Fha60-BoofPur5; Tue, 23 Sep 2025 13:01:15 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1758621675; bh=J+j4+PwNItZRsNYaJicaECJgV/GseY0I8xoBomuNEiM=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=K36wfHG0809HVU1qMdDxfNFTMjt+pPwMtpelArzq2hmsaT+xxwXczHlyhVd7qwhgY RSqCtpFcwJqllCDvaDwb0hPOvlvZLPfgKre/bz6bbr0qgfUbgh7j91rW2uCcp17FO8 PT4V2HEIEM2hcloDIIkFaMmVb9X7LEsx/WENJHIM= Authentication-Results: mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com Cc: qemu-devel@nongnu.org, philmd@linaro.org, thuth@redhat.com, eblake@redhat.com, michael.roth@amd.com, armbru@redhat.com, farosas@suse.de, peterx@redhat.com, berrange@redhat.com, jasowang@redhat.com, steven.sistare@oracle.com, leiyang@redhat.com, davydov-max@yandex-team.ru, yc-core@yandex-team.ru, vsementsov@yandex-team.ru Subject: [PATCH v6 05/19] net/tap: rework scripts handling Date: Tue, 23 Sep 2025 13:00:56 +0300 Message-ID: <20250923100110.70862-6-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250923100110.70862-1-vsementsov@yandex-team.ru> References: <20250923100110.70862-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=178.154.239.200; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1d.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1758621963258116600 Content-Type: text/plain; charset="utf-8" Simplify handling scripts: parse all these "no" and '\0' once, and then keep simpler logic for net_tap_open() and net_init_tap_one(): NULL means no script to run, otherwise run script. Signed-off-by: Vladimir Sementsov-Ogievskiy --- net/tap.c | 45 +++++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/net/tap.c b/net/tap.c index e42c7ca044..084ee4f649 100644 --- a/net/tap.c +++ b/net/tap.c @@ -88,6 +88,21 @@ static void launch_script(const char *setup_script, cons= t char *ifname, static void tap_send(void *opaque); static void tap_writable(void *opaque); =20 +static char *tap_parse_script(const char *script_arg, const char *default_= path) +{ + g_autofree char *res =3D g_strdup(script_arg); + + if (!res) { + res =3D get_relocated_path(default_path); + } + + if (res[0] =3D=3D '\0' || strcmp(res, "no") =3D=3D 0) { + return NULL; + } + + return g_steal_pointer(&res); +} + static void tap_update_fd_handler(TAPState *s) { qemu_set_fd_handler(s->fd, @@ -655,9 +670,7 @@ static int net_tap_open(int *vnet_hdr, bool vnet_hdr_re= quired, return -1; } =20 - if (setup_script && - setup_script[0] !=3D '\0' && - strcmp(setup_script, "no") !=3D 0) { + if (setup_script) { launch_script(setup_script, ifname, fd, &err); if (err) { error_propagate(errp, err); @@ -693,9 +706,9 @@ static void net_init_tap_one(const NetdevTapOptions *ta= p, NetClientState *peer, qemu_set_info_str(&s->nc, "helper=3D%s", tap->helper); } else { qemu_set_info_str(&s->nc, "ifname=3D%s,script=3D%s,downscript=3D%s= ", ifname, - script, downscript); + script ?: "no", downscript ?: "no"); =20 - if (strcmp(downscript, "no") !=3D 0) { + if (downscript) { snprintf(s->down_script, sizeof(s->down_script), "%s", downscr= ipt); snprintf(s->down_script_arg, sizeof(s->down_script_arg), "%s", ifname); @@ -950,10 +963,10 @@ free_fail: return -1; } } else { - const char *script =3D tap->script; - const char *downscript =3D tap->downscript; - g_autofree char *default_script =3D NULL; - g_autofree char *default_downscript =3D NULL; + g_autofree char *script =3D + tap_parse_script(tap->script, DEFAULT_NETWORK_SCRIPT); + g_autofree char *downscript =3D + tap_parse_script(tap->script, DEFAULT_NETWORK_DOWN_SCRIPT); bool vnet_hdr_required =3D tap->has_vnet_hdr && tap->vnet_hdr; =20 if (tap->vhostfds) { @@ -961,14 +974,6 @@ free_fail: return -1; } =20 - if (!script) { - script =3D default_script =3D get_relocated_path(DEFAULT_NETWO= RK_SCRIPT); - } - if (!downscript) { - downscript =3D default_downscript =3D - get_relocated_path(DEFAULT_NETWORK_DOWN_S= CRIPT); - } - if (tap->ifname) { pstrcpy(ifname, sizeof ifname, tap->ifname); } else { @@ -978,7 +983,7 @@ free_fail: for (i =3D 0; i < queues; i++) { vnet_hdr =3D tap->has_vnet_hdr ? tap->vnet_hdr : 1; fd =3D net_tap_open(&vnet_hdr, vnet_hdr_required, - i >=3D 1 ? "no" : script, + i >=3D 1 ? NULL : script, ifname, sizeof ifname, queues > 1, errp); if (fd =3D=3D -1) { return -1; @@ -993,8 +998,8 @@ free_fail: } =20 net_init_tap_one(tap, peer, "tap", name, ifname, - i >=3D 1 ? "no" : script, - i >=3D 1 ? "no" : downscript, + i >=3D 1 ? NULL : script, + i >=3D 1 ? NULL : downscript, vhostfdname, vnet_hdr, fd, &err); if (err) { error_propagate(errp, err); --=20 2.48.1