From nobody Sun Sep 20 16:47:48 2026 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=1784043862; cv=none; d=zohomail.com; s=zohoarc; b=jmbcOn1NXN9idAcXtG+TCb8R3LLTGji7KeZoXFjJ29appDia9qoD3PJ1KYp8rQ9b+EQ5GSfwwDMZe6g/mYb2rm7fxN3CncXwfc/IpkISJm7uUGrSlBpa0YOtEc8D+t36lXZQxxGVgj87dpZstk/2gK9divdj92+IH3W6a4pwXCQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1784043862; 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=lIljOZvuA50r9dZyj4QLNI0vLEVmNI+u5P1/S9ZuIIU=; b=LZlUNk2guU+5M5+2n7axnSkvt84xb3Q1wrD/43HGNlrokgainoaiZLBzk3ulcXSzKx/IjY8OeDPINSTP0fVvp5fLeKv0SgyB7AF2PjMYzlYVtX4LmiuXQOKvc+ibHAX4MO6x6EpjCx+Xwhe7S+nsT9OWVlt6bVdB0uAyqDpSb9w= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1784043862090714.9836566817488; Tue, 14 Jul 2026 08:44:22 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wjfHl-0001O6-0V; Tue, 14 Jul 2026 11:43:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wjfHf-0001L3-Ie for qemu-devel@nongnu.org; Tue, 14 Jul 2026 11:43:00 -0400 Received: from forwardcorp1b.mail.yandex.net ([178.154.239.136]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wjfHd-000830-2f for qemu-devel@nongnu.org; Tue, 14 Jul 2026 11:42:59 -0400 Received: from mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net (mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net [IPv6:2a02:6b8:c1b:16:0:640:bc52:0]) by forwardcorp1b.mail.yandex.net (postfix) with ESMTPS id B8C99809ED; Tue, 14 Jul 2026 18:42:54 +0300 (MSK) Received: from i115954770.yandex-team.ru (unknown [2a02:6bf:8080:c5a::1:8]) by mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net (smtpcorp) with ESMTPSA id lgRdV71YDKo0-76IXlkgd; Tue, 14 Jul 2026 18:42:54 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1784043774; bh=lIljOZvuA50r9dZyj4QLNI0vLEVmNI+u5P1/S9ZuIIU=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=IYIBlkYz3d+7PsNkTo2kFelWHqBskJDBbE1bCf56tYa3DnSMANK2p/cSYC/tzqW1d doL8kXa4dP7o3BysYWFSRgkFKa2S7322nHucZbim+H7dgP/J7G0w8+gCFakbyVKESU xrm8KO4Euu1jN1WG6HMrmXuy+HxQfK+7aZMVyLkY= Authentication-Results: mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: jasowang@redhat.com, mst@redhat.com Cc: armbru@redhat.com, peterx@redhat.com, farosas@suse.de, raphael.s.norwitz@gmail.com, bchaney@akamai.com, vsementsov@yandex-team.ru, qemu-devel@nongnu.org, berrange@redhat.com, pbonzini@redhat.com, yc-core@yandex-team.ru, mark.caveayland@nutanix.com, Jason Wang Subject: [PATCH v19 06/15] net/tap: use container_of instead of DO_UPCAST Date: Tue, 14 Jul 2026 18:42:34 +0300 Message-ID: <20260714154246.1242856-7-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260714154246.1242856-1-vsementsov@yandex-team.ru> References: <20260714154246.1242856-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=lists1p.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, 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: qemu development 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: 1784043862665158500 Content-Type: text/plain; charset="utf-8" We are going to QOMify tap backend, which includes deriving TAPState from Object. So "NetClientState nc" will not be a first member. Let's parepare for this change, and use container_of(), which will work regardless position of "nc" field. Signed-off-by: Vladimir Sementsov-Ogievskiy --- net/tap.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/net/tap.c b/net/tap.c index 3a0a7a9f2ab..0679580fcaf 100644 --- a/net/tap.c +++ b/net/tap.c @@ -176,7 +176,7 @@ static ssize_t tap_write_packet(TAPState *s, const stru= ct iovec *iov, int iovcnt static ssize_t tap_receive_iov(NetClientState *nc, const struct iovec *iov, int iovcnt) { - TAPState *s =3D DO_UPCAST(TAPState, nc, nc); + TAPState *s =3D container_of(nc, TAPState, nc); const struct iovec *iovp =3D iov; g_autofree struct iovec *iov_copy =3D NULL; struct virtio_net_hdr hdr =3D { }; @@ -212,7 +212,7 @@ ssize_t tap_read_packet(int tapfd, uint8_t *buf, int ma= xlen) =20 static void tap_send_completed(NetClientState *nc, ssize_t len) { - TAPState *s =3D DO_UPCAST(TAPState, nc, nc); + TAPState *s =3D container_of(nc, TAPState, nc); tap_read_poll(s, true); } =20 @@ -272,7 +272,7 @@ static void tap_send(void *opaque) =20 static bool tap_has_ufo(NetClientState *nc) { - TAPState *s =3D DO_UPCAST(TAPState, nc, nc); + TAPState *s =3D container_of(nc, TAPState, nc); =20 assert(nc->info->type =3D=3D NET_CLIENT_DRIVER_TAP); =20 @@ -281,7 +281,7 @@ static bool tap_has_ufo(NetClientState *nc) =20 static bool tap_has_uso(NetClientState *nc) { - TAPState *s =3D DO_UPCAST(TAPState, nc, nc); + TAPState *s =3D container_of(nc, TAPState, nc); =20 assert(nc->info->type =3D=3D NET_CLIENT_DRIVER_TAP); =20 @@ -290,7 +290,7 @@ static bool tap_has_uso(NetClientState *nc) =20 static bool tap_has_tunnel(NetClientState *nc) { - TAPState *s =3D DO_UPCAST(TAPState, nc, nc); + TAPState *s =3D container_of(nc, TAPState, nc); =20 assert(nc->info->type =3D=3D NET_CLIENT_DRIVER_TAP); return s->has_tunnel; @@ -298,7 +298,7 @@ static bool tap_has_tunnel(NetClientState *nc) =20 static bool tap_has_vnet_hdr(NetClientState *nc) { - TAPState *s =3D DO_UPCAST(TAPState, nc, nc); + TAPState *s =3D container_of(nc, TAPState, nc); =20 assert(nc->info->type =3D=3D NET_CLIENT_DRIVER_TAP); =20 @@ -312,7 +312,7 @@ static bool tap_has_vnet_hdr_len(NetClientState *nc, in= t len) =20 static void tap_set_vnet_hdr_len(NetClientState *nc, int len) { - TAPState *s =3D DO_UPCAST(TAPState, nc, nc); + TAPState *s =3D container_of(nc, TAPState, nc); =20 assert(nc->info->type =3D=3D NET_CLIENT_DRIVER_TAP); =20 @@ -323,21 +323,21 @@ static void tap_set_vnet_hdr_len(NetClientState *nc, = int len) =20 static int tap_set_vnet_le(NetClientState *nc, bool is_le) { - TAPState *s =3D DO_UPCAST(TAPState, nc, nc); + TAPState *s =3D container_of(nc, TAPState, nc); =20 return tap_fd_set_vnet_le(s->fd, is_le); } =20 static int tap_set_vnet_be(NetClientState *nc, bool is_be) { - TAPState *s =3D DO_UPCAST(TAPState, nc, nc); + TAPState *s =3D container_of(nc, TAPState, nc); =20 return tap_fd_set_vnet_be(s->fd, is_be); } =20 static void tap_set_offload(NetClientState *nc, const NetOffloads *ol) { - TAPState *s =3D DO_UPCAST(TAPState, nc, nc); + TAPState *s =3D container_of(nc, TAPState, nc); if (s->fd < 0) { return; } @@ -358,7 +358,7 @@ static void tap_exit_notify(Notifier *notifier, void *d= ata) =20 static void tap_cleanup(NetClientState *nc) { - TAPState *s =3D DO_UPCAST(TAPState, nc, nc); + TAPState *s =3D container_of(nc, TAPState, nc); =20 if (s->vhost_net) { vhost_net_cleanup(s->vhost_net); @@ -382,14 +382,14 @@ static void tap_cleanup(NetClientState *nc) =20 static void tap_poll(NetClientState *nc, bool enable) { - TAPState *s =3D DO_UPCAST(TAPState, nc, nc); + TAPState *s =3D container_of(nc, TAPState, nc); tap_read_poll(s, enable); tap_write_poll(s, enable); } =20 static bool tap_set_steering_ebpf(NetClientState *nc, int prog_fd) { - TAPState *s =3D DO_UPCAST(TAPState, nc, nc); + TAPState *s =3D container_of(nc, TAPState, nc); assert(nc->info->type =3D=3D NET_CLIENT_DRIVER_TAP); =20 return tap_fd_set_steering_ebpf(s->fd, prog_fd) =3D=3D 0; @@ -397,7 +397,7 @@ static bool tap_set_steering_ebpf(NetClientState *nc, i= nt prog_fd) =20 int tap_get_fd(NetClientState *nc) { - TAPState *s =3D DO_UPCAST(TAPState, nc, nc); + TAPState *s =3D container_of(nc, TAPState, nc); assert(nc->info->type =3D=3D NET_CLIENT_DRIVER_TAP); return s->fd; } @@ -409,7 +409,7 @@ int tap_get_fd(NetClientState *nc) */ static VHostNetState *tap_get_vhost_net(NetClientState *nc) { - TAPState *s =3D DO_UPCAST(TAPState, nc, nc); + TAPState *s =3D container_of(nc, TAPState, nc); assert(nc->info->type =3D=3D NET_CLIENT_DRIVER_TAP); return s->vhost_net; } @@ -448,7 +448,7 @@ static TAPState *net_tap_fd_init(NetClientState *peer, =20 nc =3D qemu_new_net_client(&net_tap_info, peer, model, name); =20 - s =3D DO_UPCAST(TAPState, nc, nc); + s =3D container_of(nc, TAPState, nc); =20 s->fd =3D fd; s->host_vnet_hdr_len =3D vnet_hdr ? sizeof(struct virtio_net_hdr) : 0; @@ -1017,7 +1017,7 @@ fail: =20 int tap_enable(NetClientState *nc) { - TAPState *s =3D DO_UPCAST(TAPState, nc, nc); + TAPState *s =3D container_of(nc, TAPState, nc); int ret; =20 if (s->enabled) { @@ -1034,7 +1034,7 @@ int tap_enable(NetClientState *nc) =20 int tap_disable(NetClientState *nc) { - TAPState *s =3D DO_UPCAST(TAPState, nc, nc); + TAPState *s =3D container_of(nc, TAPState, nc); int ret; =20 if (s->enabled =3D=3D 0) { --=20 2.43.0