From nobody Fri Nov 14 17:01:14 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=1761844903; cv=none; d=zohomail.com; s=zohoarc; b=f9O25a9YnBKYK9PtWEKIRtJ2tKu3CR8hQ0s3KdF18tHlZ1onF2KkeXducIrZQTV7sjnsSAE8/3wybnRoHe/5ffriWTkuz5ZmGSzjj5TOsw7wer+6XYAA2oFqIAdYov+NuD2uDaQ67d3QWsweWMuMW1yqig0dGTMglAGXTpMpPlA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1761844903; 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=ZzTQMVYEjB0S4uk/EFQKwFsi3FnRTfXbCtOvRoIniJc=; b=I7iSzDn8usNNv2EWXJN9EluarOA56MZBhp5J5AxwJUwUSkkqYPaaetenwEU0gazF2bXkSpagk2nIMRQmBX5yCkFVhv53NgvC1C3KIuWWjxrGHCjD8pk6an4JtZR1cZo2zvzrKtI6LDZqc3jBqz3DGFtSZhgzcVQAtPmuBfSPU+g= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1761844903696552.5053393722264; Thu, 30 Oct 2025 10:21:43 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vEWK1-0001Pe-2m; Thu, 30 Oct 2025 13:20:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vEWJY-0001BF-My for qemu-devel@nongnu.org; Thu, 30 Oct 2025 13:19: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 1vEWJJ-0008Lt-CO for qemu-devel@nongnu.org; Thu, 30 Oct 2025 13:19:55 -0400 Received: from mail-nwsmtp-smtp-corp-main-66.iva.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-66.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:1a8f:0:640:2fa2:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTPS id AC77F80807; Thu, 30 Oct 2025 20:19:18 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:861::1:2b]) by mail-nwsmtp-smtp-corp-main-66.iva.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id GJjc0O0FA0U0-7OvusgEp; Thu, 30 Oct 2025 20:19:18 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1761844758; bh=ZzTQMVYEjB0S4uk/EFQKwFsi3FnRTfXbCtOvRoIniJc=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=yLKJ5G+842nbH8wADiz0erpFutkgBV+B4UGkB4WhNNPrnFzV+k008hZJvDgs9ZoQc Zr+SG+BWuuDYBNXVYe7tCnQUk6Jt5XhdI7e5sRz7HrZWsYuYE36wDM52eSJGocYqDs oZAlZtYnN1Rlq3+RnG92Wa0iDyVhb0wgCGcTJFOQ= Authentication-Results: mail-nwsmtp-smtp-corp-main-66.iva.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, davydov-max@yandex-team.ru, yc-core@yandex-team.ru, pbonzini@redhat.com, berrange@redhat.com, eduardo@habkost.net, peterx@redhat.com Subject: [PATCH v9 1/9] net: introduce backend-connect concept Date: Thu, 30 Oct 2025 20:19:06 +0300 Message-ID: <20251030171915.726441-2-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251030171915.726441-1-vsementsov@yandex-team.ru> References: <20251030171915.726441-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 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: 1761844904620154100 Content-Type: text/plain; charset="utf-8" To implement in future backend-transfer migration for virtio-net, i.e. we are going to migrate TAP fd and some other TAP properties, we'll need a possibility to postpone opening TAP device until the point where we are know what user wants: open TAP device, or wait from fd coming in migration stream. So, new interface is here: since this commit, net backends may postpone some initialization actions (like opening or connecting) up to call of .backend_connect() handler. Currently, for all net drivers, .backend_connect() is called during set of netdev property, so drivers continue to work with already "connected" backends. Still, we add a possibility for drivers to use new DEFINE_NIC_PROPERTIES_NO_CONNECT() instead of DEFINE_NIC_PROPERTIES(). This way, driver take responsibility to call net_backend_connect() in its own. So, in future we'll use it in vritio-net, to finally implement backand-transfer migration fot TAP backend. Signed-off-by: Vladimir Sementsov-Ogievskiy --- hw/core/qdev-properties-system.c | 29 +++++++++++++++++++++++++++-- include/hw/qdev-properties-system.h | 2 ++ include/net/net.h | 6 ++++++ net/net.c | 15 +++++++++++++++ 4 files changed, 50 insertions(+), 2 deletions(-) diff --git a/hw/core/qdev-properties-system.c b/hw/core/qdev-properties-sys= tem.c index 13cc91680b..0b2668a45f 100644 --- a/hw/core/qdev-properties-system.c +++ b/hw/core/qdev-properties-system.c @@ -415,8 +415,8 @@ static void get_netdev(Object *obj, Visitor *v, const c= har *name, g_free(p); } =20 -static void set_netdev(Object *obj, Visitor *v, const char *name, - void *opaque, Error **errp) +static void do_set_netdev(Object *obj, Visitor *v, const char *name, + void *opaque, bool connect, Error **errp) { const Property *prop =3D opaque; NICPeers *peers_ptr =3D object_field_prop_ptr(obj, prop); @@ -463,6 +463,12 @@ static void set_netdev(Object *obj, Visitor *v, const = char *name, } } =20 + if (connect) { + if (!net_backend_connect(peers[i], errp)) { + goto out; + } + } + ncs[i] =3D peers[i]; ncs[i]->queue_index =3D i; } @@ -474,6 +480,18 @@ out: g_free(str); } =20 +static void set_netdev(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + return do_set_netdev(obj, v, name, opaque, true, errp); +} + +static void set_netdev_no_connect(Object *obj, Visitor *v, const char *nam= e, + void *opaque, Error **errp) +{ + return do_set_netdev(obj, v, name, opaque, false, errp); +} + const PropertyInfo qdev_prop_netdev =3D { .type =3D "str", .description =3D "ID of a netdev to use as a backend", @@ -481,6 +499,13 @@ const PropertyInfo qdev_prop_netdev =3D { .set =3D set_netdev, }; =20 +const PropertyInfo qdev_prop_netdev_no_connect =3D { + .type =3D "str", + .description =3D "ID of a netdev to use as a backend", + .get =3D get_netdev, + .set =3D set_netdev_no_connect, +}; + =20 /* --- audiodev --- */ static void get_audiodev(Object *obj, Visitor *v, const char* name, diff --git a/include/hw/qdev-properties-system.h b/include/hw/qdev-properti= es-system.h index 5c6cc5eae8..f41b5edadc 100644 --- a/include/hw/qdev-properties-system.h +++ b/include/hw/qdev-properties-system.h @@ -41,6 +41,8 @@ extern const PropertyInfo qdev_prop_virtio_gpu_output_lis= t; DEFINE_PROP(_n, _s, _f, qdev_prop_chr, CharFrontend) #define DEFINE_PROP_NETDEV(_n, _s, _f) \ DEFINE_PROP(_n, _s, _f, qdev_prop_netdev, NICPeers) +#define DEFINE_PROP_NETDEV_NO_CONNECT(_n, _s, _f) \ + DEFINE_PROP(_n, _s, _f, qdev_prop_netdev_no_connect, NICPeers) #define DEFINE_PROP_DRIVE(_n, _s, _f) \ DEFINE_PROP(_n, _s, _f, qdev_prop_drive, BlockBackend *) #define DEFINE_PROP_DRIVE_IOTHREAD(_n, _s, _f) \ diff --git a/include/net/net.h b/include/net/net.h index 72b476ee1d..3aa67db57c 100644 --- a/include/net/net.h +++ b/include/net/net.h @@ -51,6 +51,9 @@ typedef struct NetOffloads { DEFINE_PROP_MACADDR("mac", _state, _conf.macaddr), \ DEFINE_PROP_NETDEV("netdev", _state, _conf.peers) =20 +#define DEFINE_NIC_PROPERTIES_NO_CONNECT(_state, _conf) \ + DEFINE_PROP_MACADDR("mac", _state, _conf.macaddr), \ + DEFINE_PROP_NETDEV_NO_CONNECT("netdev", _state, _conf.peers) =20 /* Net clients */ =20 @@ -82,6 +85,7 @@ typedef void (NetAnnounce)(NetClientState *); typedef bool (SetSteeringEBPF)(NetClientState *, int); typedef bool (NetCheckPeerType)(NetClientState *, ObjectClass *, Error **); typedef struct vhost_net *(GetVHostNet)(NetClientState *nc); +typedef bool (NetBackendConnect)(NetClientState *, Error **); =20 typedef struct NetClientInfo { NetClientDriver type; @@ -110,6 +114,7 @@ typedef struct NetClientInfo { SetSteeringEBPF *set_steering_ebpf; NetCheckPeerType *check_peer_type; GetVHostNet *get_vhost_net; + NetBackendConnect *backend_connect; } NetClientInfo; =20 struct NetClientState { @@ -322,6 +327,7 @@ void net_cleanup(void); void hmp_host_net_add(Monitor *mon, const QDict *qdict); void hmp_host_net_remove(Monitor *mon, const QDict *qdict); void netdev_add(QemuOpts *opts, Error **errp); +bool net_backend_connect(NetClientState *nc, Error **errp); =20 int net_hub_id_for_client(NetClientState *nc, int *id); =20 diff --git a/net/net.c b/net/net.c index 27e0d27807..4fc6b1d0a6 100644 --- a/net/net.c +++ b/net/net.c @@ -2162,3 +2162,18 @@ int net_fill_rstate(SocketReadState *rs, const uint8= _t *buf, int size) assert(size =3D=3D 0); return 0; } + +bool net_backend_connect(NetClientState *nc, Error **errp) +{ + if (!nc->info->backend_connect) { + /* + * For most net backends from net/, the connection with + * some external entity is don in init function, defined + * in net_client_init_fun[] list. They don't have separate + * .backend_connect. + */ + return true; + } + + return nc->info->backend_connect(nc, errp); +} --=20 2.48.1 From nobody Fri Nov 14 17:01:14 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=1761844905; cv=none; d=zohomail.com; s=zohoarc; b=OV7uJMCc6ccI1aVnvfp6NncZ00HNfWDPcrWM0ItOPZhZYm8kCgyiuKAZ7w5JVG2jkQWrFmzD0Hs5vhCX+1dHzWgyibNGOXzrxsL8Y58sLMEWbGlzyhIA6lYwL4kyqb5t6sM7VIaZF3ZvL9JG+iTJKnDZXM/ezkkHRwKu7uA8RmE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1761844905; 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=fUHKAefukzFPik1zAPDmFaZI1FqMXXq3sbBaJu+yMjM=; b=kRK4xN1bl6ATm8AlAKPwR8z4zh2W/nAFLz+AORpWUoj+BxhCiy0fmcEwdU9+Me99P9lNbRfqmA12sbQE3X7uxBOOKnGoOCrL+s2OagyCfIZUoO8zoEJSoNmbw8iuu2ctBzQ/amc47t8NVwVqgEFEYWAUxlNdzfqfGyDnMpWNBXE= 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 1761844905604431.75981817740194; Thu, 30 Oct 2025 10:21:45 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vEWK8-0001TZ-FC; Thu, 30 Oct 2025 13:20:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vEWJS-00017o-1r for qemu-devel@nongnu.org; Thu, 30 Oct 2025 13:19:51 -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 1vEWJ5-0008M6-Cc for qemu-devel@nongnu.org; Thu, 30 Oct 2025 13:19:42 -0400 Received: from mail-nwsmtp-smtp-corp-main-66.iva.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-66.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:1a8f:0:640:2fa2:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTPS id CE26480808; Thu, 30 Oct 2025 20:19:19 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:861::1:2b]) by mail-nwsmtp-smtp-corp-main-66.iva.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id GJjc0O0FA0U0-9JV8PcFe; Thu, 30 Oct 2025 20:19:19 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1761844759; bh=fUHKAefukzFPik1zAPDmFaZI1FqMXXq3sbBaJu+yMjM=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=vx2woOqnpPVlNQfz2eKWtc5MFvGfunPMULPVOoD6GW0/Xdv8AAv8SYsEnrRWtxqP2 IVqNe331OYfb42fm4FUjF5Uy9X5v3i9X9fjZZeSdnvs6Tv7mfhJejfk2I4h/EmcWhh jv2vDYeH+si2XQELrSU4C0koHN5c2RIczI+8MPHE= Authentication-Results: mail-nwsmtp-smtp-corp-main-66.iva.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, davydov-max@yandex-team.ru, yc-core@yandex-team.ru, pbonzini@redhat.com, berrange@redhat.com, eduardo@habkost.net, peterx@redhat.com Subject: [PATCH v9 2/9] net/tap: rework net_tap_init() Date: Thu, 30 Oct 2025 20:19:07 +0300 Message-ID: <20251030171915.726441-3-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251030171915.726441-1-vsementsov@yandex-team.ru> References: <20251030171915.726441-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 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: 1761844906454154100 Content-Type: text/plain; charset="utf-8" In future (to support backend-transfer migration for virtio-net/tap, which includes fds passing through unix socket) we'll want to postpone fd-initialization to the later point, when QAPI structured parameters are not available. So, let's now rework the function to interface without "tap" parameter. Also, rename to net_tap_open(), as it's just a wrapper on tap_open(), and having net_tap_init() and net_init_tap() functions in one file is confusing. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Maksim Davydov --- net/tap.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/net/tap.c b/net/tap.c index 3bd81883fd..05f7480334 100644 --- a/net/tap.c +++ b/net/tap.c @@ -668,20 +668,12 @@ int net_init_bridge(const Netdev *netdev, const char = *name, return 0; } =20 -static int net_tap_init(const NetdevTapOptions *tap, int *vnet_hdr, +static int net_tap_open(int *vnet_hdr, bool vnet_hdr_required, const char *setup_script, char *ifname, size_t ifname_sz, int mq_required, Error **errp) { Error *err =3D NULL; - int fd, vnet_hdr_required; - - if (tap->has_vnet_hdr) { - *vnet_hdr =3D tap->vnet_hdr; - vnet_hdr_required =3D *vnet_hdr; - } else { - *vnet_hdr =3D 1; - vnet_hdr_required =3D 0; - } + int fd; =20 fd =3D RETRY_ON_EINTR(tap_open(ifname, ifname_sz, vnet_hdr, vnet_hdr_r= equired, mq_required, errp)); @@ -989,6 +981,7 @@ free_fail: tap_parse_script(tap->script, DEFAULT_NETWORK_SCRIPT); g_autofree char *downscript =3D tap_parse_script(tap->downscript, DEFAULT_NETWORK_DOWN_SCRIPT); + bool vnet_hdr_required =3D tap->has_vnet_hdr && tap->vnet_hdr; =20 if (tap->vhostfds) { error_setg(errp, "vhostfds=3D is invalid if fds=3D wasn't spec= ified"); @@ -1002,7 +995,9 @@ free_fail: } =20 for (i =3D 0; i < queues; i++) { - fd =3D net_tap_init(tap, &vnet_hdr, i >=3D 1 ? NULL : script, + vnet_hdr =3D tap->has_vnet_hdr ? tap->vnet_hdr : 1; + fd =3D net_tap_open(&vnet_hdr, vnet_hdr_required, + i >=3D 1 ? NULL : script, ifname, sizeof ifname, queues > 1, errp); if (fd =3D=3D -1) { return -1; --=20 2.48.1 From nobody Fri Nov 14 17:01:14 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=1761844887; cv=none; d=zohomail.com; s=zohoarc; b=X86kmC2tTLQPFe/QDAIyie5rckWwnsqhdSyVMP/xcdV98vEBkhYR67AllL00DGlmPfscHFkxF20I5AxTGK4j4TsL9gRFhtG7nUVGZuK656iCNuf2umgkuHParc6968s3IyQUCkEIOG27L2RQ1LCP9ddqSiTwCvt9PYVPX2zaZ50= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1761844887; 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=yeWOZPxoQ+RhgwSWm4C33+dN10v4duJePM9Nwnd0SsA=; b=AJD022fW/HPbOPMnWVaqQ35tCJstO5tj+DQlGHVKes1n7F892Yu9pp8gWxjdSvyJxsX3KKzHjzekx6E9WWwrccoVTKlmS4sYjvMEb/7IKn9aHUzeFWCRAxBRBiFTy/4wAylFfspW2Mdv6Cvras4W04EXcmU5Rh3kp8xZL5G2v8Y= 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 1761844887534394.19254275112564; Thu, 30 Oct 2025 10:21:27 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vEWJp-0001Nk-U5; Thu, 30 Oct 2025 13:20: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 1vEWJS-000182-Um for qemu-devel@nongnu.org; Thu, 30 Oct 2025 13:19:51 -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 1vEWJ4-0008MB-Jp for qemu-devel@nongnu.org; Thu, 30 Oct 2025 13:19:46 -0400 Received: from mail-nwsmtp-smtp-corp-main-66.iva.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-66.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:1a8f:0:640:2fa2:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id A1332807E8; Thu, 30 Oct 2025 20:19:20 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:861::1:2b]) by mail-nwsmtp-smtp-corp-main-66.iva.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id GJjc0O0FA0U0-JA72TGSj; Thu, 30 Oct 2025 20:19:20 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1761844760; bh=yeWOZPxoQ+RhgwSWm4C33+dN10v4duJePM9Nwnd0SsA=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=UUHvPIWjX1//IuHbtQ1LEloYBcJPBAeQnjUxCyBfa81OIMWQa3CZBKG7ZWOd8dVf5 BZlCIc1r6VWb1TAfQekLm1QLLopzPQDkdwG3coZVT5NMGJC48cinp264DHNYZrhW5l 33JPIKbGOv594n1A1cUrQVrrj1vMZmHjdCCDJY28= Authentication-Results: mail-nwsmtp-smtp-corp-main-66.iva.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, davydov-max@yandex-team.ru, yc-core@yandex-team.ru, pbonzini@redhat.com, berrange@redhat.com, eduardo@habkost.net, peterx@redhat.com Subject: [PATCH v9 3/9] net/tap: split net_tap_fd_init() Date: Thu, 30 Oct 2025 20:19:08 +0300 Message-ID: <20251030171915.726441-4-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251030171915.726441-1-vsementsov@yandex-team.ru> References: <20251030171915.726441-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: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_PASS=-0.001, T_SPF_HELO_TEMPERROR=0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1761844890250154100 Content-Type: text/plain; charset="utf-8" Split the function into separate net_tap_new() and net_tap_set_fd(). We start move to the following picture: net_tap_new() - take QAPI @tap parameter, but don't have @fd, initialize the net client, called during initialization. net_tap_setup() - don't have @tap (QAPI), but have @fd parameter, may be called at later point. In this commit we introduce the first function. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Maksim Davydov --- net/tap.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/net/tap.c b/net/tap.c index 05f7480334..f5830f4b00 100644 --- a/net/tap.c +++ b/net/tap.c @@ -412,19 +412,20 @@ static NetClientInfo net_tap_info =3D { .get_vhost_net =3D tap_get_vhost_net, }; =20 -static TAPState *net_tap_fd_init(NetClientState *peer, - const char *model, - const char *name, - int fd, - int vnet_hdr) +static TAPState *net_tap_new(NetClientState *peer, const char *model, + const char *name) { - NetOffloads ol =3D {}; - NetClientState *nc; - TAPState *s; + NetClientState *nc =3D qemu_new_net_client(&net_tap_info, peer, model,= name); + TAPState *s =3D DO_UPCAST(TAPState, nc, nc); =20 - nc =3D qemu_new_net_client(&net_tap_info, peer, model, name); + s->fd =3D -1; =20 - s =3D DO_UPCAST(TAPState, nc, nc); + return s; +} + +static void net_tap_set_fd(TAPState *s, int fd, int vnet_hdr) +{ + NetOffloads ol =3D {}; =20 s->fd =3D fd; s->host_vnet_hdr_len =3D vnet_hdr ? sizeof(struct virtio_net_hdr) : 0; @@ -443,8 +444,6 @@ static TAPState *net_tap_fd_init(NetClientState *peer, } tap_read_poll(s, true); s->vhost_net =3D NULL; - - return s; } =20 static void close_all_fds_after_fork(int excluded_fd) @@ -661,7 +660,9 @@ int net_init_bridge(const Netdev *netdev, const char *n= ame, close(fd); return -1; } - s =3D net_tap_fd_init(peer, "bridge", name, fd, vnet_hdr); + + s =3D net_tap_new(peer, "bridge", name); + net_tap_set_fd(s, fd, vnet_hdr); =20 qemu_set_info_str(&s->nc, "helper=3D%s,br=3D%s", helper, br); =20 @@ -701,12 +702,14 @@ static void net_init_tap_one(const NetdevTapOptions *= tap, NetClientState *peer, const char *downscript, const char *vhostfdna= me, int vnet_hdr, int fd, Error **errp) { - TAPState *s =3D net_tap_fd_init(peer, model, name, fd, vnet_hdr); + TAPState *s =3D net_tap_new(peer, model, name); int vhostfd; bool sndbuf_required =3D tap->has_sndbuf; int sndbuf =3D (tap->has_sndbuf && tap->sndbuf) ? MIN(tap->sndbuf, INT_MAX) : INT= _MAX; =20 + net_tap_set_fd(s, fd, vnet_hdr); + if (!tap_set_sndbuf(fd, sndbuf, sndbuf_required ? errp : NULL) && sndbuf_required) { goto failed; --=20 2.48.1 From nobody Fri Nov 14 17:01:14 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=1761844892; cv=none; d=zohomail.com; s=zohoarc; b=HXAYeQZ7Dp4g+Qe6U5DIdc2zeEZYyK9N+nJ+dujUZVcTR7f4WnDRZkdOPq1ER1hEjfm+27P6+cIrRXbGGRiVT3SXxlaqiEQAAgJ3u/C85uMG+d3AchEg813B2tFt/oIObTD725fS3iFSfnrX8g0K8vndprqjTI4StusBCDSGjS8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1761844892; 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=TB7tSfpGHKqIJdTjWaRpG2DXyUXEaASRQs5mgaYjW4U=; b=nVnGBg4ZCkegeZSI42JA2zR+bpeT4iC6hDo2SiCMFx5jAkuLAOA87Bp9idfMlM1ZPIJj0qX2pn6K7mnjgdt8dZlyU+oPZaqJZOTmxtIr4jI6gPrMvwtFJOZo6+JNMuNwcLxOCg+S4Y8ZPokNmsDcg6Jxk6EEvFGfusjXOCjtAko= 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 1761844892136645.0250971983443; Thu, 30 Oct 2025 10:21:32 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vEWJn-0001Da-Rw; Thu, 30 Oct 2025 13:20: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 1vEWJR-00017n-Sa for qemu-devel@nongnu.org; Thu, 30 Oct 2025 13:19:51 -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 1vEWJ5-0008MD-8L for qemu-devel@nongnu.org; Thu, 30 Oct 2025 13:19:42 -0400 Received: from mail-nwsmtp-smtp-corp-main-66.iva.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-66.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:1a8f:0:640:2fa2:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTPS id 667F18078C; Thu, 30 Oct 2025 20:19:21 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:861::1:2b]) by mail-nwsmtp-smtp-corp-main-66.iva.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id GJjc0O0FA0U0-UlAC0Lgi; Thu, 30 Oct 2025 20:19:20 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1761844760; bh=TB7tSfpGHKqIJdTjWaRpG2DXyUXEaASRQs5mgaYjW4U=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=1KOKCbsgTfoD4G1b9eGlniIwHc2uG1P3VN/7MQeYwZ4FWVgSad5lrVEgMH7dQfMUZ bjQH5lEqsv4jYcLaem9nq2Fge/RSLNEABzM1PpajYYhMfAkn23ALyr9Kvkw63rb1ka /6AO+Vy4TmEaLCUoV1Bih4U1gjGv9yhFtzjUuDEs= Authentication-Results: mail-nwsmtp-smtp-corp-main-66.iva.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, davydov-max@yandex-team.ru, yc-core@yandex-team.ru, pbonzini@redhat.com, berrange@redhat.com, eduardo@habkost.net, peterx@redhat.com Subject: [PATCH v9 4/9] net/tap: rework sndbuf handling Date: Thu, 30 Oct 2025 20:19:09 +0300 Message-ID: <20251030171915.726441-5-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251030171915.726441-1-vsementsov@yandex-team.ru> References: <20251030171915.726441-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 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: 1761844894678154100 Content-Type: text/plain; charset="utf-8" Continue the main idea: avoid dependency on @tap in net_tap_setup(). So, move QAPI parsing to net_tap_new(). Move setting sndbuf to net_tap_set_fd(), as it's more appropriate place (other initial fd settings are here). Note that net_tap_new() and net_tap_set_fd() are shared with net_init_bridge(), which didn't set sndbuf. Handle this case by sndbuf=3D0 (we never pass zero to tap_set_sndbuf(), so let this specific value mean that we don't want touch sndbuf). Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Maksim Davydov --- net/tap.c | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/net/tap.c b/net/tap.c index f5830f4b00..b5ac856a3d 100644 --- a/net/tap.c +++ b/net/tap.c @@ -83,6 +83,9 @@ typedef struct TAPState { VHostNetState *vhost_net; unsigned host_vnet_hdr_len; Notifier exit; + + bool sndbuf_required; + int sndbuf; } TAPState; =20 static void launch_script(const char *setup_script, const char *ifname, @@ -413,17 +416,25 @@ static NetClientInfo net_tap_info =3D { }; =20 static TAPState *net_tap_new(NetClientState *peer, const char *model, - const char *name) + const char *name, const NetdevTapOptions *tap) { NetClientState *nc =3D qemu_new_net_client(&net_tap_info, peer, model,= name); TAPState *s =3D DO_UPCAST(TAPState, nc, nc); =20 s->fd =3D -1; =20 + if (!tap) { + return s; + } + + s->sndbuf_required =3D tap->has_sndbuf; + s->sndbuf =3D + (tap->has_sndbuf && tap->sndbuf) ? MIN(tap->sndbuf, INT_MAX) : INT= _MAX; + return s; } =20 -static void net_tap_set_fd(TAPState *s, int fd, int vnet_hdr) +static bool net_tap_set_fd(TAPState *s, int fd, int vnet_hdr, Error **errp) { NetOffloads ol =3D {}; =20 @@ -444,6 +455,15 @@ static void net_tap_set_fd(TAPState *s, int fd, int vn= et_hdr) } tap_read_poll(s, true); s->vhost_net =3D NULL; + + if (s->sndbuf) { + Error **e =3D s->sndbuf_required ? errp : NULL; + if (!tap_set_sndbuf(s->fd, s->sndbuf, e) && s->sndbuf_required) { + return false; + } + } + + return true; } =20 static void close_all_fds_after_fork(int excluded_fd) @@ -661,8 +681,8 @@ int net_init_bridge(const Netdev *netdev, const char *n= ame, return -1; } =20 - s =3D net_tap_new(peer, "bridge", name); - net_tap_set_fd(s, fd, vnet_hdr); + s =3D net_tap_new(peer, "bridge", name, NULL); + net_tap_set_fd(s, fd, vnet_hdr, &error_abort); =20 qemu_set_info_str(&s->nc, "helper=3D%s,br=3D%s", helper, br); =20 @@ -702,16 +722,10 @@ static void net_init_tap_one(const NetdevTapOptions *= tap, NetClientState *peer, const char *downscript, const char *vhostfdna= me, int vnet_hdr, int fd, Error **errp) { - TAPState *s =3D net_tap_new(peer, model, name); + TAPState *s =3D net_tap_new(peer, model, name, tap); int vhostfd; - bool sndbuf_required =3D tap->has_sndbuf; - int sndbuf =3D - (tap->has_sndbuf && tap->sndbuf) ? MIN(tap->sndbuf, INT_MAX) : INT= _MAX; - - net_tap_set_fd(s, fd, vnet_hdr); =20 - if (!tap_set_sndbuf(fd, sndbuf, sndbuf_required ? errp : NULL) && - sndbuf_required) { + if (!net_tap_set_fd(s, fd, vnet_hdr, errp)) { goto failed; } =20 --=20 2.48.1 From nobody Fri Nov 14 17:01:14 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=1761845000; cv=none; d=zohomail.com; s=zohoarc; b=D3k/cbmW5hBpBKF8sDbc4P7RNwM2IxDr2GzHpBvRT60YWN+/2YXMDWo21kKHvhKzAWNJvxKOCq8bt7eof8OxoKudlEXjSYcm1s/uCD4W1cggm3Evrq6ub/Zm42gRPrPIbZnNsRALzT8oNsRmV9w60ObCIIu1bSjN64QZFV7ZW0Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1761845000; 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=xRxB8m3ApY6lvXruCoP/DqQRTZctBhFMTVb0CdV1Knw=; b=NYG2FasP3g2cPyq5uyy91J5n3OGWW4xwiy0rvypgWSYkdLc62YizuBX6t25oXVw2Llf6xP0CPRS+ee6jMUhTc0huaB9+KmVAgdbTvwRGVQJJRXI+4y4kTsR4GZVZ+VBZn28dbyVTKUNfKTfwwePLGFfWVKHCeDbV2TMzmvJsj8s= 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 1761845000668107.88646017566987; Thu, 30 Oct 2025 10:23:20 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vEWJo-0001LN-0k; Thu, 30 Oct 2025 13:20: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 1vEWJT-00018C-D2 for qemu-devel@nongnu.org; Thu, 30 Oct 2025 13:19:51 -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 1vEWJ7-0008MM-B1 for qemu-devel@nongnu.org; Thu, 30 Oct 2025 13:19:49 -0400 Received: from mail-nwsmtp-smtp-corp-main-66.iva.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-66.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:1a8f:0:640:2fa2:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id 1CB99807FA; Thu, 30 Oct 2025 20:19:22 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:861::1:2b]) by mail-nwsmtp-smtp-corp-main-66.iva.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id GJjc0O0FA0U0-309qyuIh; Thu, 30 Oct 2025 20:19:21 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1761844761; bh=xRxB8m3ApY6lvXruCoP/DqQRTZctBhFMTVb0CdV1Knw=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=IsdzJF12zxMzLpgQop/L3r6fF5XMRD1i1fFhFtv3CeK2vR7gbC5NjJy8Ijkx8EApa gMmQuQ/J3qHdksvAuvFtKKuN3whyoR5wNldVtzeCK7r7unsUMf9kjXUbYBF/3Bx0qc URG8mKiDjf2ipGJOHYxUrDBvzXppyDLhoIoWpm9Y= Authentication-Results: mail-nwsmtp-smtp-corp-main-66.iva.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, davydov-max@yandex-team.ru, yc-core@yandex-team.ru, pbonzini@redhat.com, berrange@redhat.com, eduardo@habkost.net, peterx@redhat.com Subject: [PATCH v9 5/9] net/tap: introduce net_tap_setup() Date: Thu, 30 Oct 2025 20:19:10 +0300 Message-ID: <20251030171915.726441-6-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251030171915.726441-1-vsementsov@yandex-team.ru> References: <20251030171915.726441-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: 1761845003789154100 Content-Type: text/plain; charset="utf-8" Move most of net_init_tap_one() to net_tap_setup() - future pair for net_tap_new(), for postponed setup. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Maksim Davydov --- net/tap.c | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/net/tap.c b/net/tap.c index b5ac856a3d..b01cd4d6c2 100644 --- a/net/tap.c +++ b/net/tap.c @@ -88,6 +88,10 @@ typedef struct TAPState { int sndbuf; } TAPState; =20 +static bool net_tap_setup(TAPState *s, const NetdevTapOptions *tap, + const char *vhostfdname, + int fd, int vnet_hdr, Error **errp); + static void launch_script(const char *setup_script, const char *ifname, int fd, Error **errp); =20 @@ -723,11 +727,6 @@ static void net_init_tap_one(const NetdevTapOptions *t= ap, NetClientState *peer, int vnet_hdr, int fd, Error **errp) { TAPState *s =3D net_tap_new(peer, model, name, tap); - int vhostfd; - - if (!net_tap_set_fd(s, fd, vnet_hdr, errp)) { - goto failed; - } =20 if (tap->fd || tap->fds) { qemu_set_info_str(&s->nc, "fd=3D%d", fd); @@ -746,6 +745,21 @@ static void net_init_tap_one(const NetdevTapOptions *t= ap, NetClientState *peer, } } =20 + if (!net_tap_setup(s, tap, vhostfdname, fd, vnet_hdr, errp)) { + qemu_del_net_client(&s->nc); + } +} + +static bool net_tap_setup(TAPState *s, const NetdevTapOptions *tap, + const char *vhostfdname, + int fd, int vnet_hdr, Error **errp) +{ + int vhostfd; + + if (!net_tap_set_fd(s, fd, vnet_hdr, errp)) { + return false; + } + if (tap->has_vhost ? tap->vhost : vhostfdname || (tap->has_vhostforce && tap->vhostforce)) { VhostNetOptions options; @@ -761,20 +775,20 @@ static void net_init_tap_one(const NetdevTapOptions *= tap, NetClientState *peer, if (vhostfdname) { vhostfd =3D monitor_fd_param(monitor_cur(), vhostfdname, errp); if (vhostfd =3D=3D -1) { - goto failed; + return false; } if (!qemu_set_blocking(vhostfd, false, errp)) { - goto failed; + return false; } } else { vhostfd =3D open("/dev/vhost-net", O_RDWR); if (vhostfd < 0) { error_setg_errno(errp, errno, "tap: open vhost char device failed"); - goto failed; + return false; } if (!qemu_set_blocking(vhostfd, false, errp)) { - goto failed; + return false; } } options.opaque =3D (void *)(uintptr_t)vhostfd; @@ -789,14 +803,11 @@ static void net_init_tap_one(const NetdevTapOptions *= tap, NetClientState *peer, if (!s->vhost_net) { error_setg(errp, "vhost-net requested but could not be initialized"); - goto failed; + return false; } } =20 - return; - -failed: - qemu_del_net_client(&s->nc); + return true; } =20 static int get_fds(char *str, char *fds[], int max) --=20 2.48.1 From nobody Fri Nov 14 17:01:14 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=1761844876; cv=none; d=zohomail.com; s=zohoarc; b=Y5sjNfdBirRUkXDts6XZ1CiZ6V2Bs/HAc/irb7OeJ3O1RpF5/tqVVhFUziOs6+foqk9X7GoynvHe/T7g4O7Zmldvx5SsxChTvmemRTj7zpbNKIAr4gRaptoCNqRZpCfmJPFI1986BCkLSHkfaCjGommH2Ugj/kBBYZbWFN8QFRE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1761844876; 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=DGvyS8TbIfokvlCPXEcapy+W+NYlKlRVQwp3Ep9VRaE=; b=k8L2Jc+mcf4WY70ZxTAeh1JX56NBLe7n4Y6EPELKBpXyEO8r4Kxaby7ZqhR+NK3GZQP7+W4LQW3nmpZjZT70+o2Meb6JnvK68L9G5RCV+cAIkam8SB1VhmiUhxFqzNBz3tOJs23vppRp7jX8CV/Xgy8obdrmitzoMPbVB6FvFSQ= 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 1761844875725121.44128005909397; Thu, 30 Oct 2025 10:21:15 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vEWJb-0001CP-6f; Thu, 30 Oct 2025 13:20: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 1vEWJT-000183-1o for qemu-devel@nongnu.org; Thu, 30 Oct 2025 13:19:51 -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 1vEWJ4-0008Ma-GC for qemu-devel@nongnu.org; Thu, 30 Oct 2025 13:19:42 -0400 Received: from mail-nwsmtp-smtp-corp-main-66.iva.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-66.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:1a8f:0:640:2fa2:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id E8A0A808C4; Thu, 30 Oct 2025 20:19:22 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:861::1:2b]) by mail-nwsmtp-smtp-corp-main-66.iva.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id GJjc0O0FA0U0-v9TXQwG2; Thu, 30 Oct 2025 20:19:22 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1761844762; bh=DGvyS8TbIfokvlCPXEcapy+W+NYlKlRVQwp3Ep9VRaE=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=wxW9heAf6WZ1dg88HH7rHRh0MeQVrbPf1CL5YYDTKXMQdSn5NqakpVuzXpSj3Rznh Gfwz0OYRr67Q7rgu+q3qq8pk1r7WWxj0BMvXBVAsXZsYibpQvUeqEmQoUbQNa1q3aH cI+Zsba5Yvmefc/Qud3fKJyWYruLD1GJTs97GTXM= Authentication-Results: mail-nwsmtp-smtp-corp-main-66.iva.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, davydov-max@yandex-team.ru, yc-core@yandex-team.ru, pbonzini@redhat.com, berrange@redhat.com, eduardo@habkost.net, peterx@redhat.com Subject: [PATCH v9 6/9] net/tap: move vhost fd initialization to net_tap_new() Date: Thu, 30 Oct 2025 20:19:11 +0300 Message-ID: <20251030171915.726441-7-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251030171915.726441-1-vsementsov@yandex-team.ru> References: <20251030171915.726441-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: 1761844879769154100 Content-Type: text/plain; charset="utf-8" Continue the track to avoid dependency on @tap in net_tap_setup(), no move the vhost fd initialization to net_tap_new(). So in net_tap_setup() we simply check, do we have and vhostfd at this point or not. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Maksim Davydov --- net/tap.c | 90 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 50 insertions(+), 40 deletions(-) diff --git a/net/tap.c b/net/tap.c index b01cd4d6c2..d08ef070e9 100644 --- a/net/tap.c +++ b/net/tap.c @@ -86,11 +86,11 @@ typedef struct TAPState { =20 bool sndbuf_required; int sndbuf; + int vhostfd; + uint32_t vhost_busyloop_timeout; } TAPState; =20 -static bool net_tap_setup(TAPState *s, const NetdevTapOptions *tap, - const char *vhostfdname, - int fd, int vnet_hdr, Error **errp); +static bool net_tap_setup(TAPState *s, int fd, int vnet_hdr, Error **errp); =20 static void launch_script(const char *setup_script, const char *ifname, int fd, Error **errp); @@ -361,6 +361,11 @@ static void tap_cleanup(NetClientState *nc) tap_write_poll(s, false); close(s->fd); s->fd =3D -1; + + if (s->vhostfd !=3D -1) { + close(s->vhostfd); + s->vhostfd =3D -1; + } } =20 static void tap_poll(NetClientState *nc, bool enable) @@ -420,12 +425,14 @@ static NetClientInfo net_tap_info =3D { }; =20 static TAPState *net_tap_new(NetClientState *peer, const char *model, - const char *name, const NetdevTapOptions *tap) + const char *name, const NetdevTapOptions *tap, + const char *vhostfdname, Error **errp) { NetClientState *nc =3D qemu_new_net_client(&net_tap_info, peer, model,= name); TAPState *s =3D DO_UPCAST(TAPState, nc, nc); =20 s->fd =3D -1; + s->vhostfd =3D -1; =20 if (!tap) { return s; @@ -435,7 +442,36 @@ static TAPState *net_tap_new(NetClientState *peer, con= st char *model, s->sndbuf =3D (tap->has_sndbuf && tap->sndbuf) ? MIN(tap->sndbuf, INT_MAX) : INT= _MAX; =20 + if (tap->has_vhost ? tap->vhost : + vhostfdname || (tap->has_vhostforce && tap->vhostforce)) { + if (vhostfdname) { + s->vhostfd =3D monitor_fd_param(monitor_cur(), vhostfdname, er= rp); + if (s->vhostfd =3D=3D -1) { + goto failed; + } + if (!qemu_set_blocking(s->vhostfd, false, errp)) { + goto failed; + } + } else { + s->vhostfd =3D open("/dev/vhost-net", O_RDWR); + if (s->vhostfd < 0) { + error_setg_errno(errp, errno, + "tap: open vhost char device failed"); + goto failed; + } + if (!qemu_set_blocking(s->vhostfd, false, errp)) { + goto failed; + } + } + + s->vhost_busyloop_timeout =3D tap->has_poll_us ? tap->poll_us : 0; + } + return s; + +failed: + qemu_del_net_client(&s->nc); + return NULL; } =20 static bool net_tap_set_fd(TAPState *s, int fd, int vnet_hdr, Error **errp) @@ -685,7 +721,7 @@ int net_init_bridge(const Netdev *netdev, const char *n= ame, return -1; } =20 - s =3D net_tap_new(peer, "bridge", name, NULL); + s =3D net_tap_new(peer, "bridge", name, NULL, NULL, &error_abort); net_tap_set_fd(s, fd, vnet_hdr, &error_abort); =20 qemu_set_info_str(&s->nc, "helper=3D%s,br=3D%s", helper, br); @@ -726,7 +762,10 @@ static void net_init_tap_one(const NetdevTapOptions *t= ap, NetClientState *peer, const char *downscript, const char *vhostfdna= me, int vnet_hdr, int fd, Error **errp) { - TAPState *s =3D net_tap_new(peer, model, name, tap); + TAPState *s =3D net_tap_new(peer, model, name, tap, vhostfdname, errp); + if (!s) { + return; + } =20 if (tap->fd || tap->fds) { qemu_set_info_str(&s->nc, "fd=3D%d", fd); @@ -745,53 +784,24 @@ static void net_init_tap_one(const NetdevTapOptions *= tap, NetClientState *peer, } } =20 - if (!net_tap_setup(s, tap, vhostfdname, fd, vnet_hdr, errp)) { + if (!net_tap_setup(s, fd, vnet_hdr, errp)) { qemu_del_net_client(&s->nc); } } =20 -static bool net_tap_setup(TAPState *s, const NetdevTapOptions *tap, - const char *vhostfdname, - int fd, int vnet_hdr, Error **errp) +static bool net_tap_setup(TAPState *s, int fd, int vnet_hdr, Error **errp) { - int vhostfd; - if (!net_tap_set_fd(s, fd, vnet_hdr, errp)) { return false; } =20 - if (tap->has_vhost ? tap->vhost : - vhostfdname || (tap->has_vhostforce && tap->vhostforce)) { + if (s->vhostfd !=3D -1) { VhostNetOptions options; =20 options.backend_type =3D VHOST_BACKEND_TYPE_KERNEL; options.net_backend =3D &s->nc; - if (tap->has_poll_us) { - options.busyloop_timeout =3D tap->poll_us; - } else { - options.busyloop_timeout =3D 0; - } - - if (vhostfdname) { - vhostfd =3D monitor_fd_param(monitor_cur(), vhostfdname, errp); - if (vhostfd =3D=3D -1) { - return false; - } - if (!qemu_set_blocking(vhostfd, false, errp)) { - return false; - } - } else { - vhostfd =3D open("/dev/vhost-net", O_RDWR); - if (vhostfd < 0) { - error_setg_errno(errp, errno, - "tap: open vhost char device failed"); - return false; - } - if (!qemu_set_blocking(vhostfd, false, errp)) { - return false; - } - } - options.opaque =3D (void *)(uintptr_t)vhostfd; + options.busyloop_timeout =3D s->vhost_busyloop_timeout; + options.opaque =3D (void *)(uintptr_t)s->vhostfd; options.nvqs =3D 2; options.feature_bits =3D kernel_feature_bits; options.get_acked_features =3D NULL; --=20 2.48.1 From nobody Fri Nov 14 17:01:14 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=1761844927; cv=none; d=zohomail.com; s=zohoarc; b=dXwwBm8vcpi5jnaoTLNP8eJkjb/QOtLmt+GGVrHHkMNWMwi0suMlAl5c6rNvFhgG3Mrx8IWQTA403w8qjD5i2uGmfIy0t/t82Yu6qt3L6fOHG8/yoroGOtxbR3yMkBT8CfewtC70CnNHYJ4lal7P4bl9Cov292VUJ6yzbbhf2ms= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1761844927; 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=5TyEDZ5Mjwqq60C4nA/4AdTGhH71Q5NYhSQBBF9mZHM=; b=b9IADg29dI8Vh+ARBbZNJIt4Be2HkpwfZ9lolYHmHA6VESR12TsLTlUJGeu/SOntHHBY1TLEatHFApvcQ7tVUqslHSg6CbNSu9fN72T7HpdVktyI0KjZrDQnKBvH/25Bbz2BlWVflKOPj0qoUUAv2BoBR99lXmcIxpfve1xu3Bc= 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 17618449272591002.9307951032183; Thu, 30 Oct 2025 10:22:07 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vEWKC-0001UN-Ap; Thu, 30 Oct 2025 13:20: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 1vEWJZ-0001BU-4y for qemu-devel@nongnu.org; Thu, 30 Oct 2025 13:19:57 -0400 Received: from forwardcorp1a.mail.yandex.net ([178.154.239.72]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vEWJR-0008Mv-WB for qemu-devel@nongnu.org; Thu, 30 Oct 2025 13:19:56 -0400 Received: from mail-nwsmtp-smtp-corp-main-66.iva.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-66.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:1a8f:0:640:2fa2:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id 9FCC8C00CB; Thu, 30 Oct 2025 20:19:23 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:861::1:2b]) by mail-nwsmtp-smtp-corp-main-66.iva.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id GJjc0O0FA0U0-iGfWLy01; Thu, 30 Oct 2025 20:19:23 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1761844763; bh=5TyEDZ5Mjwqq60C4nA/4AdTGhH71Q5NYhSQBBF9mZHM=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=ilOkB9+Lv3XvmJH/8USVmjfVMCC03hJK1dijfOW6g0QkLeWpzmKRWDdgS2ypm93cX clOtBn6GEs/kV4UD/jmkeh5/zvFMt28tly+2OpBlpHbrjbGHIyqA5voJcfJd/UjjU+ e/TCxMxlUPej/Rwt7wIjpGmkRYy6eVqK9nRhKdWY= Authentication-Results: mail-nwsmtp-smtp-corp-main-66.iva.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, davydov-max@yandex-team.ru, yc-core@yandex-team.ru, pbonzini@redhat.com, berrange@redhat.com, eduardo@habkost.net, peterx@redhat.com Subject: [PATCH v9 7/9] net/tap: finalize net_tap_set_fd() logic Date: Thu, 30 Oct 2025 20:19:12 +0300 Message-ID: <20251030171915.726441-8-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251030171915.726441-1-vsementsov@yandex-team.ru> References: <20251030171915.726441-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=178.154.239.72; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1a.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, T_SPF_TEMPERROR=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1761844928882154100 Content-Type: text/plain; charset="utf-8" Let net_tap_set_fd() do only fd-related setup. Actually, for further backend-transfer migration for virtio-net/tap we'll want to skip net_tap_set_fd() (as incoming fds are already prepared by source QEMU). So move tap_read_poll() to net_tap_setup(). Don't care about using_vnet_hdr and vhost_net, the state is zero-initialized. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Maksim Davydov --- net/tap.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/net/tap.c b/net/tap.c index d08ef070e9..7e85444ace 100644 --- a/net/tap.c +++ b/net/tap.c @@ -480,7 +480,6 @@ static bool net_tap_set_fd(TAPState *s, int fd, int vne= t_hdr, Error **errp) =20 s->fd =3D fd; s->host_vnet_hdr_len =3D vnet_hdr ? sizeof(struct virtio_net_hdr) : 0; - s->using_vnet_hdr =3D false; s->has_ufo =3D tap_probe_has_ufo(s->fd); s->has_uso =3D tap_probe_has_uso(s->fd); s->has_tunnel =3D tap_probe_has_tunnel(s->fd); @@ -493,8 +492,6 @@ static bool net_tap_set_fd(TAPState *s, int fd, int vne= t_hdr, Error **errp) if (vnet_hdr) { tap_fd_set_vnet_hdr_len(s->fd, s->host_vnet_hdr_len); } - tap_read_poll(s, true); - s->vhost_net =3D NULL; =20 if (s->sndbuf) { Error **e =3D s->sndbuf_required ? errp : NULL; @@ -795,6 +792,8 @@ static bool net_tap_setup(TAPState *s, int fd, int vnet= _hdr, Error **errp) return false; } =20 + tap_read_poll(s, true); + if (s->vhostfd !=3D -1) { VhostNetOptions options; =20 --=20 2.48.1 From nobody Fri Nov 14 17:01:14 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=1761844883; cv=none; d=zohomail.com; s=zohoarc; b=gGX2Zs3AYlsEYumqVyX5UyLbPNOY/nduooGJX6bCIq9Ro28ReK3su7sdsbri0o7R18kS78SyaKjZLrEngGreKSx52uUSk7ffT9oJIb/L+ElDIldbGLFbHymclWMK2Dl5DHi1gF/6Nu1NWXgwqEGLiaG8uEWf9gdtSUVRT9HNXIk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1761844883; 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=Pyx9akFGNoeu+Fy6mc4TIv8Sp1l5A46fhojHiVayjV4=; b=Z+XlOMRDtZ1faAE6Sn+M1AEjg2zfNRcwAMYevWV2FDTbfS7OMqcJTGIfTj/h2xMj7UqunUQxJcxUt3vAhIne6hHlQChBgl2FfLDvwNuDo1hl4GiZrZWTcI/IQEhYWdOacndQfTeaXiEtWMw6Ba5/pkU7Va2FnB7P/P/PB2ipFCA= 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 1761844883512761.6804116059944; Thu, 30 Oct 2025 10:21:23 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vEWK6-0001TY-D5; Thu, 30 Oct 2025 13:20:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vEWJb-0001CY-6x for qemu-devel@nongnu.org; Thu, 30 Oct 2025 13:19:59 -0400 Received: from forwardcorp1a.mail.yandex.net ([178.154.239.72]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vEWJU-0008Mp-FC for qemu-devel@nongnu.org; Thu, 30 Oct 2025 13:19:58 -0400 Received: from mail-nwsmtp-smtp-corp-main-66.iva.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-66.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:1a8f:0:640:2fa2:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id 5B0F6C0165; Thu, 30 Oct 2025 20:19:24 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:861::1:2b]) by mail-nwsmtp-smtp-corp-main-66.iva.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id GJjc0O0FA0U0-3uPA7wJD; Thu, 30 Oct 2025 20:19:23 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1761844763; bh=Pyx9akFGNoeu+Fy6mc4TIv8Sp1l5A46fhojHiVayjV4=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=NnRdZFSg+W1nhO3vMTIxDW6A8FsDfsmy+FMgC4feOLunyoLOzpiWToGg2eH20ga80 Lld4LH9TZpTXQKt1htFkSQHTFZBeLAYH/TiISjOhaRuKAVuzsrv+a6X3XwHz1mzHdz 8ip1L7iDJPeED3w3uMybLsZKXaKP73h2+hwYlWC8= Authentication-Results: mail-nwsmtp-smtp-corp-main-66.iva.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, davydov-max@yandex-team.ru, yc-core@yandex-team.ru, pbonzini@redhat.com, berrange@redhat.com, eduardo@habkost.net, peterx@redhat.com Subject: [PATCH v9 8/9] net/tap: introduce TAP_IFNAME_SZ Date: Thu, 30 Oct 2025 20:19:13 +0300 Message-ID: <20251030171915.726441-9-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251030171915.726441-1-vsementsov@yandex-team.ru> References: <20251030171915.726441-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=178.154.239.72; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1a.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_VALIDITY_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: 1761844887158158500 Content-Type: text/plain; charset="utf-8" To be reused in the next commit. Signed-off-by: Vladimir Sementsov-Ogievskiy --- net/tap.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/net/tap.c b/net/tap.c index 7e85444ace..c50430ba49 100644 --- a/net/tap.c +++ b/net/tap.c @@ -48,6 +48,8 @@ =20 #include "net/vhost_net.h" =20 +#define TAP_IFNAME_SZ 128 + static const int kernel_feature_bits[] =3D { VIRTIO_F_NOTIFY_ON_EMPTY, VIRTIO_RING_F_INDIRECT_DESC, @@ -853,7 +855,7 @@ int net_init_tap(const Netdev *netdev, const char *name, /* for the no-fd, no-helper case */ Error *err =3D NULL; const char *vhostfdname; - char ifname[128]; + char ifname[TAP_IFNAME_SZ]; int ret =3D 0; =20 assert(netdev->type =3D=3D NET_CLIENT_DRIVER_TAP); --=20 2.48.1 From nobody Fri Nov 14 17:01:14 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=1761844995; cv=none; d=zohomail.com; s=zohoarc; b=g9+AYYtq97SvbXptbAVQRw0Mh29sg1HqgK5iOeMVzY6olhxsWr905aMvIRZjns4Sx44MFkNI8dgTi+0xPPItDDZOciQX8T/M+LFexJYJ+5s3fxf43O+jiHoSE0OI/ipv/Ono5ladIjy07ygETZyvtKPlwH0imU1eLy93/sozjEM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1761844995; 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=4mc/qBRLhfYXRJW391uyW9nJdD23QGaduedXq3nj154=; b=Bg0+q+F7AYnX/cRjq6BzbDRlq8uPGkhYh2BiIRwFsXQLOEtoPr3ToHj3S7E7fxf4jd8JUmQIchwP5/Y5BPab/94uml9RI5OlvlkW4voFrPpnkaj9esoxnf0fivvT2DtDH3OFaiIpO+dElKqrHZ3OJ3SUO1O75uRc0YA1btTTGsU= 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 1761844995941606.4792311364544; Thu, 30 Oct 2025 10:23:15 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vEWJc-0001Ce-Oo; Thu, 30 Oct 2025 13:20: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 1vEWJS-000180-UU for qemu-devel@nongnu.org; Thu, 30 Oct 2025 13:19:51 -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 1vEWJ9-0008Mx-9N for qemu-devel@nongnu.org; Thu, 30 Oct 2025 13:19:48 -0400 Received: from mail-nwsmtp-smtp-corp-main-66.iva.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-66.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:1a8f:0:640:2fa2:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id 2FEED8094A; Thu, 30 Oct 2025 20:19:25 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:861::1:2b]) by mail-nwsmtp-smtp-corp-main-66.iva.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id GJjc0O0FA0U0-fLAA5S6I; Thu, 30 Oct 2025 20:19:24 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1761844764; bh=4mc/qBRLhfYXRJW391uyW9nJdD23QGaduedXq3nj154=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=gifW8X1uO3BMUUllENMu6cpL+PuoQ2iLARh5T0L6cild5mcv0BLxlFH5wg/YF6B+c 8/r3HTM4EkWHsPn8I4qyTi6Y73JNTITLXlBI9sSrzTJtAZkQaIMEdfoEdjxvKOBZ4o Rar+rFBSHK938UtIBWCIQDbmlPIgeVdAuK+DYKxw= Authentication-Results: mail-nwsmtp-smtp-corp-main-66.iva.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, davydov-max@yandex-team.ru, yc-core@yandex-team.ru, pbonzini@redhat.com, berrange@redhat.com, eduardo@habkost.net, peterx@redhat.com Subject: [PATCH v9 9/9] net/tap: postpone tap setup to net_backend_connect() call Date: Thu, 30 Oct 2025 20:19:14 +0300 Message-ID: <20251030171915.726441-10-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251030171915.726441-1-vsementsov@yandex-team.ru> References: <20251030171915.726441-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: 1761844997986158500 Content-Type: text/plain; charset="utf-8" As described in previous commit, to support backend-transfer migration for virtio-net/tap, we need to postpone the decision to open the device or to wait for incoming fds up to pre-incoming point (when we actually can decide). This commit only postpones TAP-open case of initialization. We don't try to postpone the all cases of initialization, as it will require a lot more work of refactoring the code. So we postpone only the simple case, for which we are going to support fd-incoming migration: 1. No fds / fd parameters: obviously, if user give fd/fds the should be used, no incoming backend-transfer migration is possible. 2. No helper: just for simplicity. It probably possible to allow it (and just ignore in case of backend-transfer migration), to allow user use same cmdline on target QEMU.. But that questionable, and postponable. 3. No sciprt/downscript. It's not simple to support downscript: we should pass the responsiblity to call it on target QEMU with migration.. And back to source QEMU on migration failure. It feasible, but may be implemented later on demand. 3. Concrete ifname: to not try to share it between queues, when we only can setup queues as separate entities. Supporting undecided ifname will require to create some extra netdev state, connecting all the taps, to be able to iterate through them. No part of backend-transfer migration is here, we only prepare the code for future implementation of it. Signed-off-by: Vladimir Sementsov-Ogievskiy --- net/tap.c | 111 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) diff --git a/net/tap.c b/net/tap.c index c50430ba49..ad1d458521 100644 --- a/net/tap.c +++ b/net/tap.c @@ -90,6 +90,12 @@ typedef struct TAPState { int sndbuf; int vhostfd; uint32_t vhost_busyloop_timeout; + + /* for postponed setup */ + bool vnet_hdr_required; + int vnet_hdr; + bool mq_required; + char *ifname; } TAPState; =20 static bool net_tap_setup(TAPState *s, int fd, int vnet_hdr, Error **errp); @@ -99,6 +105,7 @@ static void launch_script(const char *setup_script, cons= t char *ifname, =20 static void tap_send(void *opaque); static void tap_writable(void *opaque); +static bool tap_backend_connect(NetClientState *nc, Error **errp); =20 static char *tap_parse_script(const char *script_arg, const char *default_= path) { @@ -368,6 +375,8 @@ static void tap_cleanup(NetClientState *nc) close(s->vhostfd); s->vhostfd =3D -1; } + + g_free(s->ifname); } =20 static void tap_poll(NetClientState *nc, bool enable) @@ -424,6 +433,7 @@ static NetClientInfo net_tap_info =3D { .set_vnet_be =3D tap_set_vnet_be, .set_steering_ebpf =3D tap_set_steering_ebpf, .get_vhost_net =3D tap_get_vhost_net, + .backend_connect =3D tap_backend_connect, }; =20 static TAPState *net_tap_new(NetClientState *peer, const char *model, @@ -847,6 +857,102 @@ static int get_fds(char *str, char *fds[], int max) return i; } =20 +static bool tap_wait_incoming(NetClientState *nc) +{ + TAPState *s =3D DO_UPCAST(TAPState, nc, nc); + + return s->fd =3D=3D -1; +} + +static bool tap_backend_connect(NetClientState *nc, Error **errp) +{ + TAPState *s =3D DO_UPCAST(TAPState, nc, nc); + char ifname[TAP_IFNAME_SZ]; + int vnet_hdr =3D s->vnet_hdr; + int fd; + + if (!tap_wait_incoming(nc)) { + /* Already connected */ + return true; + } + + pstrcpy(ifname, sizeof(ifname), s->ifname); + fd =3D net_tap_open(&vnet_hdr, s->vnet_hdr_required, NULL, + ifname, sizeof(ifname), + s->mq_required, errp); + if (fd < 0) { + goto fail; + } + + if (!net_tap_setup(s, fd, vnet_hdr, errp)) { + goto fail; + } + + return true; + +fail: + qemu_del_net_client(&s->nc); + return false; +} + +static bool check_no_script(const char *script_arg) +{ + return script_arg && + (script_arg[0] =3D=3D '\0' || strcmp(script_arg, "no") =3D=3D 0); +} + +/* + * Returns: + * -1 - failed, errp set. The whole tap creation process is faild. + * 0 - success, tap initialized, connect is postponed + * 1 - no critical error, but postponed connect is not supported, + * caller should continue usual initialization + */ +static int tap_postpone_init(const NetdevTapOptions *tap, + const char *name, NetClientState *peer, + Error **errp) +{ + int queues =3D tap->has_queues ? tap->queues : 1; + + if (tap->fd || tap->fds || tap->helper || tap->vhostfds) { + return 1; + } + + if (!tap->ifname || tap->ifname[0] =3D=3D '\0' || + strstr(tap->ifname, "%d") !=3D NULL) { + /* + * It's hard to postpone logic of parsing template or + * absent ifname + */ + return 1; + } + + /* + * It's not simple to support downscript for backend transfer migratio= n, + * so for simplicity, let's not support postponed connect in case of + * any scripts given. + */ + if (!check_no_script(tap->script) || !check_no_script(tap->downscript)= ) { + return 1; + } + + for (int i =3D 0; i < queues; i++) { + TAPState *s =3D net_tap_new(peer, "tap", name, tap, NULL, errp); + if (!s) { + return -1; + } + + s->vnet_hdr_required =3D tap->has_vnet_hdr && tap->vnet_hdr; + s->vnet_hdr =3D tap->has_vnet_hdr ? tap->vnet_hdr : 1; + s->mq_required =3D queues > 1; + s->ifname =3D g_strdup(tap->ifname); + qemu_set_info_str(&s->nc, "ifname=3D%s,script=3Dno,downscript=3Dno= ", + tap->ifname); + } + + return 0; +} + int net_init_tap(const Netdev *netdev, const char *name, NetClientState *peer, Error **errp) { @@ -875,6 +981,11 @@ int net_init_tap(const Netdev *netdev, const char *nam= e, return -1; } =20 + ret =3D tap_postpone_init(tap, name, peer, errp); + if (ret <=3D 0) { + return ret; + } + if (tap->fd) { if (tap->ifname || tap->script || tap->downscript || tap->has_vnet_hdr || tap->helper || tap->has_queues || --=20 2.48.1