All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>,
	Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>,
	Ben Chaney <bchaney@akamai.com>,
	Jason Wang <jasowangio@gmail.com>
Subject: [PULL 25/90] net/tap: QOMify tap backend
Date: Thu, 10 Sep 2026 16:12:23 -0400	[thread overview]
Message-ID: <3559b6073c917e55bbd8fffe8df42ead10c19cf9.1789071042.git.mst@redhat.com> (raw)
In-Reply-To: <cover.1789071042.git.mst@redhat.com>

From: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>

We prepare for being able to migrate TAP backend. We'll need a
user change-able property for it, which can be set from machine
type. So, let's QOMify it first.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Reviewed-by: Ben Chaney <bchaney@akamai.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Message-ID: <20260819180201.1970193-8-vsementsov@yandex-team.ru>
---
 include/net/net.h |  7 +++++++
 include/net/tap.h |  2 ++
 net/net.c         | 14 +++++++-------
 net/tap.c         | 48 +++++++++++++++++++++++++++++++++++++++--------
 4 files changed, 56 insertions(+), 15 deletions(-)

diff --git a/include/net/net.h b/include/net/net.h
index 626b997948..ea07760b56 100644
--- a/include/net/net.h
+++ b/include/net/net.h
@@ -161,6 +161,13 @@ char *qemu_mac_strdup_printf(const uint8_t *macaddr);
 NetClientState *qemu_find_netdev(const char *id);
 int qemu_find_net_clients_except(const char *id, NetClientState **ncs,
                                  NetClientDriver type, int max);
+void qemu_net_client_setup(NetClientState *nc,
+                           NetClientInfo *info,
+                           NetClientState *peer,
+                           const char *model,
+                           const char *name,
+                           NetClientDestructor *destructor,
+                           bool is_datapath);
 NetClientState *qemu_new_net_client(NetClientInfo *info,
                                     NetClientState *peer,
                                     const char *model,
diff --git a/include/net/tap.h b/include/net/tap.h
index 6f34f13eae..268570571f 100644
--- a/include/net/tap.h
+++ b/include/net/tap.h
@@ -28,6 +28,8 @@
 
 #include "standard-headers/linux/virtio_net.h"
 
+#define TYPE_TAP_NETDEV "tap-netdev"
+
 int tap_enable(NetClientState *nc);
 int tap_disable(NetClientState *nc);
 
diff --git a/net/net.c b/net/net.c
index 1161183e18..d7fa637ce5 100644
--- a/net/net.c
+++ b/net/net.c
@@ -261,13 +261,13 @@ static ssize_t qemu_deliver_packet_iov(NetClientState *sender,
                                        int iovcnt,
                                        void *opaque);
 
-static void qemu_net_client_setup(NetClientState *nc,
-                                  NetClientInfo *info,
-                                  NetClientState *peer,
-                                  const char *model,
-                                  const char *name,
-                                  NetClientDestructor *destructor,
-                                  bool is_datapath)
+void qemu_net_client_setup(NetClientState *nc,
+                           NetClientInfo *info,
+                           NetClientState *peer,
+                           const char *model,
+                           const char *name,
+                           NetClientDestructor *destructor,
+                           bool is_datapath)
 {
     nc->info = info;
     nc->model = g_strdup(model);
diff --git a/net/tap.c b/net/tap.c
index bfed74717e..7392344200 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -43,6 +43,7 @@
 #include "qemu/main-loop.h"
 #include "qemu/sockets.h"
 #include "hw/virtio/vhost.h"
+#include "qom/object.h"
 
 #include "net/tap.h"
 #include "net/util.h"
@@ -68,7 +69,11 @@ static const int kernel_feature_bits[] = {
     VHOST_INVALID_FEATURE_BIT
 };
 
-typedef struct TAPState {
+OBJECT_DECLARE_SIMPLE_TYPE(TAPState, TAP_NETDEV)
+
+struct TAPState {
+    Object parent_obj;
+
     NetClientState nc;
     int fd;
     int vhostfd;
@@ -86,7 +91,7 @@ typedef struct TAPState {
     VHostNetState *vhost_net;
     unsigned host_vnet_hdr_len;
     Notifier exit;
-} TAPState;
+};
 
 static void launch_script(const char *setup_script, const char *ifname,
                           int fd, Error **errp);
@@ -413,6 +418,19 @@ static VHostNetState *tap_get_vhost_net(NetClientState *nc)
     return s->vhost_net;
 }
 
+
+static const TypeInfo tap_netdev_info = {
+    .name = TYPE_TAP_NETDEV,
+    .parent = TYPE_OBJECT,
+    .instance_size = sizeof(TAPState),
+};
+
+static void tap_net_client_destructor(NetClientState *nc)
+{
+    TAPState *s = container_of(nc, TAPState, nc);
+    object_unref(OBJECT(s));
+}
+
 /* fd support */
 
 static NetClientInfo net_tap_info = {
@@ -435,6 +453,18 @@ static NetClientInfo net_tap_info = {
     .get_vhost_net = tap_get_vhost_net,
 };
 
+static TAPState *new_tap(NetClientState *peer,
+                         const char *model,
+                         const char *name)
+{
+    TAPState *s = TAP_NETDEV(object_new(TYPE_TAP_NETDEV));
+
+    qemu_net_client_setup(&s->nc, &net_tap_info, peer, model, name,
+                          tap_net_client_destructor, true);
+
+    return s;
+}
+
 static TAPState *net_tap_fd_init(NetClientState *peer,
                                  const char *model,
                                  const char *name,
@@ -442,12 +472,7 @@ static TAPState *net_tap_fd_init(NetClientState *peer,
                                  int vnet_hdr)
 {
     NetOffloads ol = {};
-    NetClientState *nc;
-    TAPState *s;
-
-    nc = qemu_new_net_client(&net_tap_info, peer, model, name);
-
-    s = container_of(nc, TAPState, nc);
+    TAPState *s = new_tap(peer, model, name);
 
     s->fd = fd;
     s->host_vnet_hdr_len = vnet_hdr ? sizeof(struct virtio_net_hdr) : 0;
@@ -1048,3 +1073,10 @@ int tap_disable(NetClientState *nc)
         return ret;
     }
 }
+
+static void tap_register_types(void)
+{
+    type_register_static(&tap_netdev_info);
+}
+
+type_init(tap_register_types)
-- 
MST



  parent reply	other threads:[~2026-09-10 23:04 UTC|newest]

Thread overview: 95+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-10 20:11 [PULL 00/90] pci, vhost, virtio, iommu, apci: features, fixes Michael S. Tsirkin
2026-09-10 20:11 ` [PULL 01/90] virtio: fix exit(1) on DMA mapping failure during migration restore Michael S. Tsirkin
2026-09-10 20:11 ` [PULL 02/90] virtio: fix config_len DoS in migration restore path Michael S. Tsirkin
2026-09-10 20:11 ` [PULL 03/90] virtio-pci: reject Q_ENABLE write on already-enabled queue Michael S. Tsirkin
2026-09-10 20:11 ` [PULL 04/90] hw/cxl: Fix guest-triggerable QEMU exit on reserved interleave ways Michael S. Tsirkin
2026-09-10 20:11 ` [PULL 05/90] vhost-vsock: block CPR migration modes Michael S. Tsirkin
2026-09-10 20:11 ` [PULL 06/90] vhost: add vhost_reset_owner op Michael S. Tsirkin
2026-09-10 20:11 ` [PULL 07/90] vhost-vsock: don't reset connections during CPR Michael S. Tsirkin
2026-09-10 20:11 ` [PULL 08/90] vhost-vsock: fix FD leak in realize() Michael S. Tsirkin
2026-09-10 20:11 ` [PULL 09/90] vhost-vsock: preserve vhost FD during CPR Michael S. Tsirkin
2026-09-10 20:11 ` [PULL 10/90] vhost: factor out vhost_dev_init_backend() Michael S. Tsirkin
2026-09-10 20:11 ` [PULL 11/90] vhost: make vhost_dev_cleanup() safe on a partially initialized device Michael S. Tsirkin
2026-09-10 20:11 ` [PULL 12/90] vhost: add vhost_dev_set_owner() / vhost_dev_reset_owner() helpers Michael S. Tsirkin
2026-09-10 20:11 ` [PULL 13/90] vhost: add vhost_dev_is_initialized() helper Michael S. Tsirkin
2026-09-10 20:11 ` [PULL 14/90] vhost-vsock: hand off device ownership across CPR Michael S. Tsirkin
2026-09-10 20:11 ` [PULL 15/90] linux-headers: add VIRTIO_ID_MEDIA Michael S. Tsirkin
2026-09-10 20:11 ` [PULL 16/90] hw/display: add vhost-user-media device Michael S. Tsirkin
2026-09-10 20:12 ` [PULL 17/90] hw/display/vhost-user-media: add shared memory region BAR Michael S. Tsirkin
2026-09-10 20:12 ` [PULL 18/90] virtio: reduce code duplication for split ring Michael S. Tsirkin
2026-09-10 20:12 ` [PULL 19/90] net/tap: rework tap_parse_script Michael S. Tsirkin
2026-09-10 20:12 ` [PULL 20/90] net/tap: improve script/downscript options documentation Michael S. Tsirkin
2026-09-10 20:12 ` [PULL 21/90] net/tap: deprecate "no" as special value for script/downscript Michael S. Tsirkin
2026-09-10 20:12 ` [PULL 22/90] net/tap: move vhost-net open() calls to tap_parse_vhost_fds() Michael S. Tsirkin
2026-09-10 20:12 ` [PULL 23/90] net/tap: move vhost initialization to tap_setup_vhost() Michael S. Tsirkin
2026-09-10 20:12 ` [PULL 24/90] net/tap: use container_of instead of DO_UPCAST Michael S. Tsirkin
2026-09-10 20:12 ` Michael S. Tsirkin [this message]
2026-09-10 20:12 ` [PULL 26/90] net/tap: add TYPE_VMSTATE_IF interface Michael S. Tsirkin
2026-09-10 20:12 ` [PULL 27/90] qapi: add local migration parameter Michael S. Tsirkin
2026-09-10 20:12 ` [PULL 28/90] migration/fd: fix fd leak when fd is not valid for migration Michael S. Tsirkin
2026-09-10 20:12 ` [PULL 29/90] migration/fd: add errp parameter to migration_fd_valid() Michael S. Tsirkin
2026-09-10 20:12 ` [PULL 30/90] migration: check that transfer is UNIX socket when "local" set Michael S. Tsirkin
2026-09-10 20:12 ` [PULL 31/90] virtio-net: support local migration of backend Michael S. Tsirkin
2026-09-10 20:12 ` [PULL 32/90] net/tap: disable read polling for stopped VM Michael S. Tsirkin
2026-09-10 20:12 ` [PULL 33/90] net/tap: support local migration with virtio-net Michael S. Tsirkin
2026-09-10 20:12 ` [PULL 34/90] tests/functional: add test_tap_migration Michael S. Tsirkin
2026-09-10 20:12 ` [PULL 35/90] vhost-user-gpu: validate command buffer size in submit_3d Michael S. Tsirkin
2026-09-11 14:50   ` admin
2026-09-11 20:03     ` Michael S. Tsirkin
2026-09-10 20:12 ` [PULL 36/90] vhost: Fix SHMEM_MAP transaction ordering and resulting deadlock Michael S. Tsirkin
2026-09-10 20:12 ` [PULL 37/90] vhost-user-gpu: Add shared memory region support Michael S. Tsirkin
2026-09-10 20:13 ` [PULL 38/90] vhost-user-gpu: Forward RESOURCE_BLOB and CONTEXT_INIT flags Michael S. Tsirkin
2026-09-10 20:13 ` [PULL 39/90] tests/bios-tables-test: Exclude CEDT.cxl for the CFMW restriction change Michael S. Tsirkin
2026-09-10 20:13 ` [PULL 40/90] hw/cxl: Drop Back-Invalidate from default CFMW window restrictions Michael S. Tsirkin
2026-09-10 20:13 ` [PULL 41/90] tests/acpi/cxl: Update CEDT.cxl for the default CFMW restrictions Michael S. Tsirkin
2026-09-10 20:13 ` [PULL 42/90] hw/cxl: Add configurable CXL Fixed Memory Window restriction flags Michael S. Tsirkin
2026-09-10 20:13 ` [PULL 43/90] tests/qtest/cxl: Add CXL Fixed Memory Window restriction flag tests Michael S. Tsirkin
2026-09-10 20:13 ` [PULL 44/90] hw/net/virtio-net: check packet size before VLAN tag access in receive_filter() Michael S. Tsirkin
2026-09-10 20:13 ` [PULL 45/90] hw/virtio-blk: Account discard operations Michael S. Tsirkin
2026-09-10 20:13 ` [PULL 46/90] hw/virtio-blk: Complete zone-append cookies Michael S. Tsirkin
2026-09-10 20:13 ` [PULL 47/90] hw/nvme: Fix block accounting in nvme_copy() Michael S. Tsirkin
2026-09-10 20:13 ` [PULL 48/90] hw/nvme: Fix block accounting for compare Michael S. Tsirkin
2026-09-10 20:13 ` [PULL 49/90] hw/ide: Have ide_dma_cb() complete accounting Michael S. Tsirkin
2026-09-10 20:13 ` [PULL 50/90] hw/scsi-disk: Fix accounting for IGNORE, ret > 0 Michael S. Tsirkin
2026-09-10 20:13 ` [PULL 51/90] meson: disable "maybe uninitilized" errors with -Og Michael S. Tsirkin
2026-09-10 20:13 ` [PULL 52/90] hw/net/virtio-net: strip trailing padding when caching RSC segment Michael S. Tsirkin
2026-09-10 20:13 ` [PULL 53/90] virtio-crypto: clean up every data queue Michael S. Tsirkin
2026-09-10 20:13 ` [PULL 54/90] hw/virtio: reject inverted virtio-iommu IOVA ranges Michael S. Tsirkin
2026-09-10 20:13 ` [PULL 55/90] virtio-balloon: fix free-page BH teardown on unrealize Michael S. Tsirkin
2026-09-10 20:13 ` [PULL 56/90] vhost-user.rst: fix typo Michael S. Tsirkin
2026-09-10 20:13 ` [PULL 57/90] vhost-user: Reject SHMEM_MAP when no KVM memory slot is left Michael S. Tsirkin
2026-09-10 20:13 ` [PULL 58/90] hw/virtio: Propagate vhost_virtqueue_mask errors Michael S. Tsirkin
2026-09-10 20:13 ` [PULL 59/90] amd_iommu: Return empty efr for stub call Michael S. Tsirkin
2026-09-10 20:13 ` [PULL 60/90] tests/acpi: x86: Allow IVRS acpi table changes Michael S. Tsirkin
2026-09-10 20:14 ` [PULL 61/90] amd_iommu: acpi-build: update PA, GVA and VA size macros Michael S. Tsirkin
2026-09-10 20:14 ` [PULL 62/90] acpi_build: Use IOMMU pci device to build IOMMU DeviceID Michael S. Tsirkin
2026-09-10 20:14 ` [PULL 63/90] acpi_build: Build IVRS feature report using extended feature register Michael S. Tsirkin
2026-09-10 20:14 ` [PULL 64/90] amd_iommu: acpi-build: Remove unsupported PPR and HE feature Michael S. Tsirkin
2026-09-10 20:14 ` [PULL 65/90] tests/acpi: x86: update golden masters for IVRS Michael S. Tsirkin
2026-09-10 20:14 ` [PULL 66/90] libvhost-user: accept the postcopy client base ack in vu_add_mem_reg() Michael S. Tsirkin
2026-09-10 20:14 ` [PULL 67/90] libvhost-user: return the backend mapping address for added regions Michael S. Tsirkin
2026-09-10 20:14 ` [PULL 68/90] linux-headers: Update to Linux v7.3-rc1 Michael S. Tsirkin
2026-09-10 20:14 ` [PULL 69/90] virtio-scsi: set dataplane_started to false upon failure Michael S. Tsirkin
2026-09-10 20:14 ` [PULL 70/90] hw/cxl: fix the CDAT DOE overlapping the Flex Bus DVSEC when sn= is set Michael S. Tsirkin
2026-09-10 20:14 ` [PULL 71/90] virtio-rtc: Report smeared UTC clock type Michael S. Tsirkin
2026-09-10 20:14 ` [PULL 72/90] intel_iommu: Support concurrent page fault handling with PRI Michael S. Tsirkin
2026-09-10 20:14 ` [PULL 73/90] intel_iommu: Only set dirty bit when PTE exposes write permission Michael S. Tsirkin
2026-09-10 20:14 ` [PULL 74/90] intel_iommu: Always write all the flags passed to vtd_set_flag_in_pte Michael S. Tsirkin
2026-09-10 20:14 ` [PULL 75/90] pci: batch BAR remapping into one memory transaction Michael S. Tsirkin
2026-09-10 20:14 ` [PULL 76/90] pci: load a device's config inside " Michael S. Tsirkin
2026-09-10 20:15 ` [PULL 77/90] hw/acpi: Make AcpiGedState const in build_ged_aml() Michael S. Tsirkin
2026-09-10 20:15 ` [PULL 78/90] hw/hotplug: Mark various HotplugHandlerClass variables as const Michael S. Tsirkin
2026-09-10 20:15 ` [PULL 79/90] hw/hotplug: Reduce some HotplugHandler variables scope Michael S. Tsirkin
2026-09-10 20:15 ` [PULL 80/90] hw/hotplug: Constify HotplugHandler Michael S. Tsirkin
2026-09-10 20:15 ` [PULL 81/90] net/tap-solaris: Fix resource leaks on error paths Michael S. Tsirkin
2026-09-10 20:15 ` [PULL 82/90] virtio-net: validate IHL in virtio_net_rsc_extract_unit4 before use Michael S. Tsirkin
2026-09-10 20:15 ` [PULL 83/90] intel_iommu: Expose SMPWC when SVM is enabled Michael S. Tsirkin
2026-09-10 20:15 ` [PULL 84/90] vhost-user: add skip_drain param to do_vhost_virtqueue_stop Michael S. Tsirkin
2026-09-10 20:15 ` [PULL 85/90] vhost-user: add GET_VRING_BASE_SKIP_DRAIN message Michael S. Tsirkin
2026-09-10 20:15 ` [PULL 86/90] vhost-user: use skip_drain with " Michael S. Tsirkin
2026-09-10 20:15 ` [PULL 87/90] vhost-user-blk: make inflight-migration prop mutable on running vm Michael S. Tsirkin
2026-09-10 20:15 ` [PULL 88/90] vhost-user-blk: move inflight_needed higher Michael S. Tsirkin
2026-09-10 20:15 ` [PULL 89/90] vhost-user-blk: use GET_VRING_BASE_SKIP_DRAIN when inflight-migration is on Michael S. Tsirkin
2026-09-10 20:15 ` [PULL 90/90] MAINTAINERS: add Junjie Cao as CXL reviewer Michael S. Tsirkin
2026-09-11  7:30 ` [PULL 00/90] pci, vhost, virtio, iommu, apci: features, fixes Stefano Garzarella
2026-09-11  8:05   ` Michael S. Tsirkin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3559b6073c917e55bbd8fffe8df42ead10c19cf9.1789071042.git.mst@redhat.com \
    --to=mst@redhat.com \
    --cc=bchaney@akamai.com \
    --cc=jasowangio@gmail.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=vsementsov@yandex-team.ru \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.