From nobody Sun Mar 22 15:41:49 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=1773935662; cv=none; d=zohomail.com; s=zohoarc; b=i01FUXvKzdkniQA63vP+48v0uldV7us555PdqALq1AFSh0amuEgcqLuUcqYGv9XE9J2DaxgWcNHTszht/96dyXvfRLipBVq3nEhcoMy+c6wCiSFVl8B+f1cbzjGmj4XsF5tgQQctsqMWwPmAqLbU2ZZkI1uQ5M77Abj4QU4Yrjg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1773935662; 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=iiWNx+dF+mt5iK8SCPOqGVSv2ZNa0uhrveivEOlVYWk=; b=aCrduxiS7sctDp5iMmZWzK5uzwwk4XDVJOWMlIAxArugNT9MzlJVP/RLXzxhr7GVNVMjqFQoDYQd1y0DfOeXmu8zm/hvzk76MBFusMUy+3xVzhC2wOd5Ybx4gxvwPdOrMCwZivltOc0glA2JPw3uv2SW5hWoJ+WkJG3B827iRwc= 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 1773935661375749.4598893021246; Thu, 19 Mar 2026 08:54:21 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w3Fh2-0003ZE-K5; Thu, 19 Mar 2026 11:53:52 -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 1w3Fgz-0003Xx-Nf for qemu-devel@nongnu.org; Thu, 19 Mar 2026 11:53:49 -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 1w3Fgw-0007gZ-V4 for qemu-devel@nongnu.org; Thu, 19 Mar 2026 11:53:49 -0400 Received: from mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net [IPv6:2a02:6b8:c24:fa2:0:640:41ee:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTPS id F0B798081B; Thu, 19 Mar 2026 18:53:43 +0300 (MSK) Received: from vsementsov-lin (unknown [2a02:6bf:8080:d57::1:20]) by mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id arQgWZ2AA0U0-5pkpixqs; Thu, 19 Mar 2026 18:53:43 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1773935623; bh=iiWNx+dF+mt5iK8SCPOqGVSv2ZNa0uhrveivEOlVYWk=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=ww8PbTUdsdqpq+Uvxkh2uuGnI16XtS9mXfrz2ESyKY2OnwxPYax0G6rxTuMPuHtw6 BM08JGRF13hezOEa4fjCUyUSKdRdSvZNlgXm8JradqX9TKh9bCBJX+WN2/deW8P4tj IYv5lPHp+/OmBBf+gLVSlcgeeowsTD3idq/Qtuf8= Authentication-Results: mail-nwsmtp-smtp-corp-main-34.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, 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 Message-ID: <20260319155333.260341-5-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260319155333.260341-1-vsementsov@yandex-team.ru> References: <20260319155333.260341-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: -3 X-Spam_score: -0.4 X-Spam_bar: / X-Spam_report: (-0.4 / 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.819, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.903, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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: 1773935666535158500 Content-Type: text/plain; charset="utf-8" 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 --- 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" =20 #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; =20 struct NetClientState { @@ -354,4 +356,6 @@ static inline bool net_peer_needs_padding(NetClientStat= e *nc) return nc->peer && !nc->peer->do_not_pad; } =20 +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" =20 /* 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 =3D=3D 0); return 0; } + +static int get_peer_backend(QEMUFile *f, void *pv, size_t size, + const VMStateField *field) +{ + NetClientState *nc =3D pv; + Error *local_err =3D NULL; + int ret; + + if (!nc->peer) { + return -EINVAL; + } + nc =3D nc->peer; + + ret =3D vmstate_load_state(f, nc->info->backend_vmsd, nc, 0, &local_er= r); + 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 =3D pv; + Error *local_err =3D NULL; + int ret; + + if (!nc->peer) { + return -EINVAL; + } + nc =3D nc->peer; + + ret =3D vmstate_save_state(f, nc->info->backend_vmsd, nc, 0, &local_er= r); + if (ret < 0) { + error_report_err(local_err); + } + + return ret; +} + +const VMStateInfo vmstate_net_peer_backend =3D { + .name =3D "virtio-net-nic-nc-backend", + .get =3D get_peer_backend, + .put =3D put_peer_backend, +}; --=20 2.52.0