public inbox for qemu-devel@nongnu.org
 help / color / mirror / Atom feed
From: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
To: jasowang@redhat.com, mst@redhat.com
Cc: armbru@redhat.com, eblake@redhat.com, farosas@suse.de,
	peterx@redhat.com, zhao1.liu@intel.com, wangyanan55@huawei.com,
	philmd@linaro.org, marcel.apfelbaum@gmail.com,
	eduardo@habkost.net, davydov-max@yandex-team.ru,
	qemu-devel@nongnu.org, vsementsov@yandex-team.ru,
	yc-core@yandex-team.ru, leiyang@redhat.com,
	raphael.s.norwitz@gmail.com, bchaney@akamai.com,
	th.huth+qemu@posteo.eu, berrange@redhat.com, pbonzini@redhat.com
Subject: [PATCH v13 4/8] net: introduce vmstate_net_peer_backend
Date: Thu, 19 Mar 2026 18:53:28 +0300	[thread overview]
Message-ID: <20260319155333.260341-5-vsementsov@yandex-team.ru> (raw)
In-Reply-To: <20260319155333.260341-1-vsementsov@yandex-team.ru>

To implement backend migration in virtio-net in the next commit, we need
a generic API to migrate net backend. Here is it.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
---
 include/net/net.h |  4 ++++
 net/net.c         | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 51 insertions(+)

diff --git a/include/net/net.h b/include/net/net.h
index 45bc86fc86b..aa34043b1ac 100644
--- a/include/net/net.h
+++ b/include/net/net.h
@@ -5,6 +5,7 @@
 #include "qapi/qapi-types-net.h"
 #include "net/queue.h"
 #include "hw/core/qdev-properties-system.h"
+#include "migration/vmstate.h"
 
 #define MAC_FMT "%02X:%02X:%02X:%02X:%02X:%02X"
 #define MAC_ARG(x) ((uint8_t *)(x))[0], ((uint8_t *)(x))[1], \
@@ -110,6 +111,7 @@ typedef struct NetClientInfo {
     SetSteeringEBPF *set_steering_ebpf;
     NetCheckPeerType *check_peer_type;
     GetVHostNet *get_vhost_net;
+    const VMStateDescription *backend_vmsd;
 } NetClientInfo;
 
 struct NetClientState {
@@ -354,4 +356,6 @@ static inline bool net_peer_needs_padding(NetClientState *nc)
   return nc->peer && !nc->peer->do_not_pad;
 }
 
+extern const VMStateInfo vmstate_net_peer_backend;
+
 #endif
diff --git a/net/net.c b/net/net.c
index a176936f9bc..8d09754fa0d 100644
--- a/net/net.c
+++ b/net/net.c
@@ -58,6 +58,7 @@
 #include "qapi/string-output-visitor.h"
 #include "qapi/qobject-input-visitor.h"
 #include "standard-headers/linux/virtio_net.h"
+#include "migration/vmstate.h"
 
 /* Net bridge is currently not supported for W32. */
 #if !defined(_WIN32)
@@ -2173,3 +2174,49 @@ int net_fill_rstate(SocketReadState *rs, const uint8_t *buf, int size)
     assert(size == 0);
     return 0;
 }
+
+static int get_peer_backend(QEMUFile *f, void *pv, size_t size,
+                            const VMStateField *field)
+{
+    NetClientState *nc = pv;
+    Error *local_err = NULL;
+    int ret;
+
+    if (!nc->peer) {
+        return -EINVAL;
+    }
+    nc = nc->peer;
+
+    ret = vmstate_load_state(f, nc->info->backend_vmsd, nc, 0, &local_err);
+    if (ret < 0) {
+        error_report_err(local_err);
+    }
+
+    return ret;
+}
+
+static int put_peer_backend(QEMUFile *f, void *pv, size_t size,
+                            const VMStateField *field, JSONWriter *vmdesc)
+{
+    NetClientState *nc = pv;
+    Error *local_err = NULL;
+    int ret;
+
+    if (!nc->peer) {
+        return -EINVAL;
+    }
+    nc = nc->peer;
+
+    ret = vmstate_save_state(f, nc->info->backend_vmsd, nc, 0, &local_err);
+    if (ret < 0) {
+        error_report_err(local_err);
+    }
+
+    return ret;
+}
+
+const VMStateInfo vmstate_net_peer_backend = {
+    .name = "virtio-net-nic-nc-backend",
+    .get = get_peer_backend,
+    .put = put_peer_backend,
+};
-- 
2.52.0



  parent reply	other threads:[~2026-03-19 15:54 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-19 15:53 [PATCH v13 0/8] virtio-net: live-TAP local migration Vladimir Sementsov-Ogievskiy
2026-03-19 15:53 ` [PATCH v13 1/8] net/tap: move vhost-net open() calls to tap_parse_vhost_fds() Vladimir Sementsov-Ogievskiy
2026-03-19 15:53 ` [PATCH v13 2/8] net/tap: move vhost initialization to tap_setup_vhost() Vladimir Sementsov-Ogievskiy
2026-03-19 15:53 ` [PATCH v13 3/8] qapi: add local migration parameter Vladimir Sementsov-Ogievskiy
2026-03-24 12:24   ` Markus Armbruster
2026-03-24 13:32     ` Vladimir Sementsov-Ogievskiy
2026-03-19 15:53 ` Vladimir Sementsov-Ogievskiy [this message]
2026-03-19 15:53 ` [PATCH v13 5/8] virtio-net: support local migration of backend Vladimir Sementsov-Ogievskiy
2026-03-19 15:53 ` [PATCH v13 6/8] net/tap: support local migration with virtio-net Vladimir Sementsov-Ogievskiy
2026-03-24 12:33   ` Markus Armbruster
2026-03-24 13:51     ` Vladimir Sementsov-Ogievskiy
2026-03-19 15:53 ` [PATCH v13 7/8] tests/functional: add skipWithoutSudo() decorator Vladimir Sementsov-Ogievskiy
2026-03-19 15:53 ` [PATCH v13 8/8] tests/functional: add test_tap_migration Vladimir Sementsov-Ogievskiy
2026-03-19 16:01 ` [PATCH v13 0/8] virtio-net: live-TAP local migration Vladimir Sementsov-Ogievskiy
2026-03-20  9:39 ` Markus Armbruster
2026-03-20 13:15   ` Vladimir Sementsov-Ogievskiy

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=20260319155333.260341-5-vsementsov@yandex-team.ru \
    --to=vsementsov@yandex-team.ru \
    --cc=armbru@redhat.com \
    --cc=bchaney@akamai.com \
    --cc=berrange@redhat.com \
    --cc=davydov-max@yandex-team.ru \
    --cc=eblake@redhat.com \
    --cc=eduardo@habkost.net \
    --cc=farosas@suse.de \
    --cc=jasowang@redhat.com \
    --cc=leiyang@redhat.com \
    --cc=marcel.apfelbaum@gmail.com \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peterx@redhat.com \
    --cc=philmd@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=raphael.s.norwitz@gmail.com \
    --cc=th.huth+qemu@posteo.eu \
    --cc=wangyanan55@huawei.com \
    --cc=yc-core@yandex-team.ru \
    --cc=zhao1.liu@intel.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox