From nobody Fri Nov 14 21:05:51 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=1761693367; cv=none; d=zohomail.com; s=zohoarc; b=Y9AqxB4vpZBPTtXxF0iEmfUHdxy/KA1HQ917x+k9/2G6jhvUVu/TafwHvayQoovdY8zM4OhTqoz/Ks4g32zDB51+mlgLTdJDhvh+mdWMPNisaD+vpnWW1+poxgiYCnaYgwSpzkkv5rM614K0b1pPJSz4Ro7DFceRwgZg96Tp0+I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1761693367; 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=W4FzO8lSWOUPXV+V8oEsi7uae9/GNQt9LV+s1RTTQo8=; b=VOfYF1uUVtS6eTKHcq3SLbM1fZlZnwYDSg0kopTO4B3eQi1yj1gQVWhkh0AAHnszF2Ohr3gdGYKrYmpcaz5IKQLrtaUy0df6fprE6TxhoKn0kN4DYtUsd+jhr4mTUxJ4SMQAT3WZscm+xc8GK3J0WLZxfzYF12Oelb/Jbn7megU= 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 1761693367405889.7038771507546; Tue, 28 Oct 2025 16:16:07 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vDstX-0002z9-F3; Tue, 28 Oct 2025 19:14:27 -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 1vDstW-0002yj-JJ for qemu-devel@nongnu.org; Tue, 28 Oct 2025 19:14:26 -0400 Received: from forwardcorp1b.mail.yandex.net ([2a02:6b8:c02:900:1:45:d181:df01]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vDstK-00017d-Pe for qemu-devel@nongnu.org; Tue, 28 Oct 2025 19:14:25 -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:c10:49f:0:640:b99a:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTPS id 04E4E8176E; Wed, 29 Oct 2025 02:14:02 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:582::1:19]) by mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id oDnXpg2bCW20-HHYfGBkN; Wed, 29 Oct 2025 02:14:01 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1761693241; bh=W4FzO8lSWOUPXV+V8oEsi7uae9/GNQt9LV+s1RTTQo8=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=ugf1XKvz7j/KB31uVvLcl+9OerbmToJtgi1rx1FAVYhXFdhItHtHdrZ3tKdbtge8t woaW11Vx913JKmoem3TSLqkfFPp28ZH7Pi7zAv4B8MoLV+vn9wcbZ6yjPRvR1ZgU9v AVaEMx1Tk9CkqWlB+IJTduA+ItFB6KzHp6qSJNC8= 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: peterx@redhat.com Cc: armbru@redhat.com, vsementsov@yandex-team.ru, qemu-devel@nongnu.org Subject: [RFC 14/22] hw/net/virtio-net.c: use new migration APIs Date: Wed, 29 Oct 2025 02:13:38 +0300 Message-ID: <20251028231347.194844-15-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251028231347.194844-1-vsementsov@yandex-team.ru> References: <20251028231347.194844-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=2a02:6b8:c02:900:1:45:d181:df01; 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, 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 Precedence: list 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: 1761693371046158500 Content-Type: text/plain; charset="utf-8" Signed-off-by: Vladimir Sementsov-Ogievskiy --- hw/net/virtio-net.c | 118 +++++++++++++++++++++----------------------- 1 file changed, 55 insertions(+), 63 deletions(-) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 33116712eb..23be0e3047 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -3180,7 +3180,8 @@ static void virtio_net_get_features(VirtIODevice *vde= v, uint64_t *features, } } =20 -static int virtio_net_post_load_device(void *opaque, int version_id) +static bool virtio_net_post_load_device(void *opaque, int version_id, + Error **errp) { VirtIONet *n =3D opaque; VirtIODevice *vdev =3D VIRTIO_DEVICE(n); @@ -3243,7 +3244,7 @@ static int virtio_net_post_load_device(void *opaque, = int version_id) } =20 virtio_net_commit_rss_config(n); - return 0; + return true; } =20 static int virtio_net_post_load_virtio(VirtIODevice *vdev) @@ -3309,7 +3310,7 @@ struct VirtIONetMigTmp { * pointer and count and also validate the count. */ =20 -static int virtio_net_tx_waiting_pre_save(void *opaque) +static bool virtio_net_tx_waiting_pre_save(void *opaque, Error **errp) { struct VirtIONetMigTmp *tmp =3D opaque; =20 @@ -3319,30 +3320,30 @@ static int virtio_net_tx_waiting_pre_save(void *opa= que) tmp->curr_queue_pairs_1 =3D 0; } =20 - return 0; + return true; } =20 -static int virtio_net_tx_waiting_pre_load(void *opaque) +static bool virtio_net_tx_waiting_pre_load(void *opaque, Error **errp) { struct VirtIONetMigTmp *tmp =3D opaque; =20 /* Reuse the pointer setup from save */ - virtio_net_tx_waiting_pre_save(opaque); + virtio_net_tx_waiting_pre_save(opaque, &error_abort); =20 if (tmp->parent->curr_queue_pairs > tmp->parent->max_queue_pairs) { - error_report("virtio-net: curr_queue_pairs %x > max_queue_pairs %x= ", + error_setg(errp, "virtio-net: curr_queue_pairs %x > max_queue_pair= s %x", tmp->parent->curr_queue_pairs, tmp->parent->max_queue_pairs); =20 - return -EINVAL; + return false; } =20 - return 0; /* all good */ + return true; } =20 static const VMStateDescription vmstate_virtio_net_tx_waiting =3D { .name =3D "virtio-net-tx_waiting", - .pre_load =3D virtio_net_tx_waiting_pre_load, - .pre_save =3D virtio_net_tx_waiting_pre_save, + .pre_load_errp =3D virtio_net_tx_waiting_pre_load, + .pre_save_errp =3D virtio_net_tx_waiting_pre_save, .fields =3D (const VMStateField[]) { VMSTATE_STRUCT_VARRAY_POINTER_UINT16(vqs_1, struct VirtIONetMigTmp, curr_queue_pairs_1, @@ -3355,31 +3356,31 @@ static const VMStateDescription vmstate_virtio_net_= tx_waiting =3D { /* the 'has_ufo' flag is just tested; if the incoming stream has the * flag set we need to check that we have it */ -static int virtio_net_ufo_post_load(void *opaque, int version_id) +static bool virtio_net_ufo_post_load(void *opaque, int version_id, Error *= *errp) { struct VirtIONetMigTmp *tmp =3D opaque; =20 if (tmp->has_ufo && !peer_has_ufo(tmp->parent)) { - error_report("virtio-net: saved image requires TUN_F_UFO support"); - return -EINVAL; + error_setg(errp, "virtio-net: saved image requires TUN_F_UFO suppo= rt"); + return false; } =20 - return 0; + return true; } =20 -static int virtio_net_ufo_pre_save(void *opaque) +static bool virtio_net_ufo_pre_save(void *opaque, Error **errp) { struct VirtIONetMigTmp *tmp =3D opaque; =20 tmp->has_ufo =3D tmp->parent->has_ufo; =20 - return 0; + return true; } =20 static const VMStateDescription vmstate_virtio_net_has_ufo =3D { .name =3D "virtio-net-ufo", - .post_load =3D virtio_net_ufo_post_load, - .pre_save =3D virtio_net_ufo_pre_save, + .post_load_errp =3D virtio_net_ufo_post_load, + .pre_save_errp =3D virtio_net_ufo_pre_save, .fields =3D (const VMStateField[]) { VMSTATE_UINT8(has_ufo, struct VirtIONetMigTmp), VMSTATE_END_OF_LIST() @@ -3389,38 +3390,39 @@ static const VMStateDescription vmstate_virtio_net_= has_ufo =3D { /* the 'has_vnet_hdr' flag is just tested; if the incoming stream has the * flag set we need to check that we have it */ -static int virtio_net_vnet_post_load(void *opaque, int version_id) +static bool virtio_net_vnet_post_load(void *opaque, int version_id, + Error **errp) { struct VirtIONetMigTmp *tmp =3D opaque; =20 if (tmp->has_vnet_hdr && !peer_has_vnet_hdr(tmp->parent)) { - error_report("virtio-net: saved image requires vnet_hdr=3Don"); - return -EINVAL; + error_setg(errp, "virtio-net: saved image requires vnet_hdr=3Don"); + return false; } =20 - return 0; + return true; } =20 -static int virtio_net_vnet_pre_save(void *opaque) +static bool virtio_net_vnet_pre_save(void *opaque, Error **errp) { struct VirtIONetMigTmp *tmp =3D opaque; =20 tmp->has_vnet_hdr =3D tmp->parent->has_vnet_hdr; =20 - return 0; + return true; } =20 static const VMStateDescription vmstate_virtio_net_has_vnet =3D { .name =3D "virtio-net-vnet", - .post_load =3D virtio_net_vnet_post_load, - .pre_save =3D virtio_net_vnet_pre_save, + .post_load_errp =3D virtio_net_vnet_post_load, + .pre_save_errp =3D virtio_net_vnet_pre_save, .fields =3D (const VMStateField[]) { VMSTATE_UINT32(has_vnet_hdr, struct VirtIONetMigTmp), VMSTATE_END_OF_LIST() }, }; =20 -static int virtio_net_rss_post_load(void *opaque, int version_id) +static bool virtio_net_rss_post_load(void *opaque, int version_id, Error *= *errp) { VirtIONet *n =3D VIRTIO_NET(opaque); =20 @@ -3428,7 +3430,7 @@ static int virtio_net_rss_post_load(void *opaque, int= version_id) n->rss_data.supported_hash_types =3D VIRTIO_NET_RSS_SUPPORTED_HASH= ES; } =20 - return 0; + return true; } =20 static bool virtio_net_rss_needed(void *opaque) @@ -3440,7 +3442,7 @@ static const VMStateDescription vmstate_virtio_net_rs= s =3D { .name =3D "virtio-net-device/rss", .version_id =3D 2, .minimum_version_id =3D 1, - .post_load =3D virtio_net_rss_post_load, + .post_load_errp =3D virtio_net_rss_post_load, .needed =3D virtio_net_rss_needed, .fields =3D (const VMStateField[]) { VMSTATE_BOOL(rss_data.enabled, VirtIONet), @@ -3482,61 +3484,51 @@ static struct vhost_dev *virtio_net_get_vhost(VirtI= ODevice *vdev) return &net->dev; } =20 -static int vhost_user_net_save_state(QEMUFile *f, void *pv, size_t size, - const VMStateField *field, - JSONWriter *vmdesc) +static bool vhost_user_net_save_state(QEMUFile *f, void *pv, size_t size, + const VMStateField *field, + JSONWriter *vmdesc, Error **errp) { VirtIONet *n =3D pv; VirtIODevice *vdev =3D VIRTIO_DEVICE(n); struct vhost_dev *vhdev; - Error *local_error =3D NULL; int ret; =20 vhdev =3D virtio_net_get_vhost(vdev); if (vhdev =3D=3D NULL) { - error_reportf_err(local_error, - "Error getting vhost back-end of %s device %s: ", - vdev->name, vdev->parent_obj.canonical_path); - return -1; + error_setg(errp, "Error getting vhost back-end of %s device %s", + vdev->name, vdev->parent_obj.canonical_path); + return false; } =20 - ret =3D vhost_save_backend_state(vhdev, f, &local_error); + ret =3D vhost_save_backend_state(vhdev, f, errp); if (ret < 0) { - error_reportf_err(local_error, - "Error saving back-end state of %s device %s: ", - vdev->name, vdev->parent_obj.canonical_path); - return ret; + return false; } =20 - return 0; + return true; } =20 -static int vhost_user_net_load_state(QEMUFile *f, void *pv, size_t size, - const VMStateField *field) +static bool vhost_user_net_load_state(QEMUFile *f, void *pv, size_t size, + const VMStateField *field, Error **e= rrp) { VirtIONet *n =3D pv; VirtIODevice *vdev =3D VIRTIO_DEVICE(n); struct vhost_dev *vhdev; - Error *local_error =3D NULL; int ret; =20 vhdev =3D virtio_net_get_vhost(vdev); if (vhdev =3D=3D NULL) { - error_reportf_err(local_error, - "Error getting vhost back-end of %s device %s: ", - vdev->name, vdev->parent_obj.canonical_path); - return -1; + error_setg(errp, "Error getting vhost back-end of %s device %s", + vdev->name, vdev->parent_obj.canonical_path); + return false; } =20 - ret =3D vhost_load_backend_state(vhdev, f, &local_error); + ret =3D vhost_load_backend_state(vhdev, f, errp); if (ret < 0) { - error_reportf_err(local_error, - "Error loading back-end state of %s device %s: = ", - vdev->name, vdev->parent_obj.canonical_path); - return ret; + return false; } =20 - return 0; + return true; } =20 static bool vhost_user_net_is_internal_migration(void *opaque) @@ -3562,8 +3554,8 @@ static const VMStateDescription vhost_user_net_backen= d_state =3D { .name =3D "backend", .info =3D &(const VMStateInfo) { .name =3D "virtio-net vhost-user backend state", - .get =3D vhost_user_net_load_state, - .put =3D vhost_user_net_save_state, + .load =3D vhost_user_net_load_state, + .save =3D vhost_user_net_save_state, }, }, VMSTATE_END_OF_LIST() @@ -3574,7 +3566,7 @@ static const VMStateDescription vmstate_virtio_net_de= vice =3D { .name =3D "virtio-net-device", .version_id =3D VIRTIO_NET_VM_VERSION, .minimum_version_id =3D VIRTIO_NET_VM_VERSION, - .post_load =3D virtio_net_post_load_device, + .post_load_errp =3D virtio_net_post_load_device, .fields =3D (const VMStateField[]) { VMSTATE_UINT8_ARRAY(mac, VirtIONet, ETH_ALEN), VMSTATE_STRUCT_POINTER(vqs, VirtIONet, @@ -4144,7 +4136,7 @@ static void virtio_net_instance_init(Object *obj) ebpf_rss_init(&n->ebpf_rss); } =20 -static int virtio_net_pre_save(void *opaque) +static bool virtio_net_pre_save(void *opaque, Error **errp) { VirtIONet *n =3D opaque; =20 @@ -4152,7 +4144,7 @@ static int virtio_net_pre_save(void *opaque) * it might keep writing to memory. */ assert(!n->vhost_started); =20 - return 0; + return true; } =20 static bool primary_unplug_pending(void *opaque) @@ -4185,7 +4177,7 @@ static const VMStateDescription vmstate_virtio_net = =3D { VMSTATE_VIRTIO_DEVICE, VMSTATE_END_OF_LIST() }, - .pre_save =3D virtio_net_pre_save, + .pre_save_errp =3D virtio_net_pre_save, .dev_unplug_pending =3D dev_unplug_pending, }; =20 --=20 2.48.1