From nobody Fri Mar 27 04:54:25 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=1772659624; cv=none; d=zohomail.com; s=zohoarc; b=NgIrfCGkNCa6OJLekpfRLF1lBn/Vk4UqENe3nin8BOYjyDUQqT+iIbJ7RLsLV6l/J0ejFniK9c+i+CPjpNVKhftuo8JDGevPn6vyHINBx0w/6gfc6tQ2TNvMkwvB99L0J8boT3XOXvN++rml9Fuz+LTDW7lMMu5wEkrRyj5e4hs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1772659624; 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=rZq+2jxkcntS00G/DpIMhzwAYy5l95RJHArfeh2HkZM=; b=JUxY6TP5X0hkOcGtY6IHQKdvggbumk/yLIrUYFKSVIsKqxWj2XcKWsVvWfO5pebIXh9wXu3wcbao0fRl6qF9gJg35HgIh0vVPLGmt3JFOANnbu1DRLw13LUyHaIgwHJT94By5nYu6/F+HC5PHI2TzPNy7In6ggRHJohbxDBh80k= 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 1772659624980624.3197840700614; Wed, 4 Mar 2026 13:27:04 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vxth7-0004pR-Kz; Wed, 04 Mar 2026 16:23:49 -0500 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 1vxtgf-0004m1-3P for qemu-devel@nongnu.org; Wed, 04 Mar 2026 16:23:25 -0500 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 1vxtgc-0003T8-4V for qemu-devel@nongnu.org; Wed, 04 Mar 2026 16:23:20 -0500 Received: from mail-nwsmtp-smtp-corp-main-66.iva.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-66.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:bf1f:0:640:c739:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTPS id 948A980887; Thu, 05 Mar 2026 00:23:16 +0300 (MSK) Received: from vsementsov-lin (unknown [2a02:6bf:8080:921::1:1b]) by mail-nwsmtp-smtp-corp-main-66.iva.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id 5NwBA90AmW20-48L5Tkyt; Thu, 05 Mar 2026 00:23:16 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1772659396; bh=rZq+2jxkcntS00G/DpIMhzwAYy5l95RJHArfeh2HkZM=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=mlTvMs6UGIeHntGYgJUrM6lgckRvUb9oDMbeniQ4IxLqfA9R6u0hMnsLaNUOdlChY AXQeWMAt+SbFrCW0SdYcFrqacTpJdOqGZ0TiSDlXEoXFoFSP6Sv6G3dHwH1PrZXkQI 6yZNoUBeRFKY4M++5IQ4NVzHRO/o0ermnjYpg3KI= Authentication-Results: mail-nwsmtp-smtp-corp-main-66.iva.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: peterx@redhat.com Cc: farosas@suse.de, vsementsov@yandex-team.ru, qemu-devel@nongnu.org Subject: [PATCH v3 15/18] migration/savevm: move to new migration APIs Date: Thu, 5 Mar 2026 00:22:59 +0300 Message-ID: <20260304212303.667141-16-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260304212303.667141-1-vsementsov@yandex-team.ru> References: <20260304212303.667141-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, 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 Precedence: list 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: 1772659625690158500 Content-Type: text/plain; charset="utf-8" Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Peter Xu --- migration/savevm.c | 105 ++++++++++++++++++++++++--------------------- 1 file changed, 55 insertions(+), 50 deletions(-) diff --git a/migration/savevm.c b/migration/savevm.c index c5236e71ba1..a4c64dda0a2 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -205,27 +205,28 @@ void timer_get(QEMUFile *f, QEMUTimer *ts) * Not in vmstate.c to not add qemu-timer.c as dependency to vmstate.c */ =20 -static int get_timer(QEMUFile *f, void *pv, size_t size, - const VMStateField *field) +static bool load_timer(QEMUFile *f, void *pv, size_t size, + const VMStateField *field, Error **errp) { QEMUTimer *v =3D pv; timer_get(f, v); - return 0; + return true; } =20 -static int put_timer(QEMUFile *f, void *pv, size_t size, - const VMStateField *field, JSONWriter *vmdesc) +static bool save_timer(QEMUFile *f, void *pv, size_t size, + const VMStateField *field, JSONWriter *vmdesc, + Error **errp) { QEMUTimer *v =3D pv; timer_put(f, v); =20 - return 0; + return true; } =20 const VMStateInfo vmstate_info_timer =3D { .name =3D "timer", - .get =3D get_timer, - .put =3D put_timer, + .load =3D load_timer, + .save =3D save_timer, }; =20 =20 @@ -297,7 +298,7 @@ static uint32_t get_validatable_capabilities_count(void) return result; } =20 -static int configuration_pre_save(void *opaque) +static bool configuration_pre_save(void *opaque, Error **errp) { SaveState *state =3D opaque; const char *current_name =3D MACHINE_GET_CLASS(current_machine)->name; @@ -318,7 +319,7 @@ static int configuration_pre_save(void *opaque) } state->uuid =3D qemu_uuid; =20 - return 0; + return true; } =20 static void configuration_post_save(void *opaque) @@ -330,7 +331,7 @@ static void configuration_post_save(void *opaque) state->caps_count =3D 0; } =20 -static int configuration_pre_load(void *opaque) +static bool configuration_pre_load(void *opaque, Error **errp) { SaveState *state =3D opaque; =20 @@ -339,7 +340,7 @@ static int configuration_pre_load(void *opaque) * minimum possible value for this CPU. */ state->target_page_bits =3D migration_legacy_page_bits(); - return 0; + return true; } =20 static bool configuration_validate_capabilities(SaveState *state) @@ -376,28 +377,31 @@ static bool configuration_validate_capabilities(SaveS= tate *state) return ret; } =20 -static int configuration_post_load(void *opaque, int version_id) +static bool configuration_post_load(void *opaque, int version_id, Error **= errp) { SaveState *state =3D opaque; const char *current_name =3D MACHINE_GET_CLASS(current_machine)->name; - int ret =3D 0; + bool ok =3D true; =20 if (strncmp(state->name, current_name, state->len) !=3D 0) { - error_report("Machine type received is '%.*s' and local is '%s'", - (int) state->len, state->name, current_name); - ret =3D -EINVAL; + error_setg(errp, + "Machine type received is '%.*s' and local is '%s'", + (int) state->len, state->name, current_name); + ok =3D false; goto out; } =20 if (state->target_page_bits !=3D qemu_target_page_bits()) { - error_report("Received TARGET_PAGE_BITS is %d but local is %d", - state->target_page_bits, qemu_target_page_bits()); - ret =3D -EINVAL; + error_setg(errp, + "Received TARGET_PAGE_BITS is %d but local is %d", + state->target_page_bits, qemu_target_page_bits()); + ok =3D false; goto out; } =20 if (!configuration_validate_capabilities(state)) { - ret =3D -EINVAL; + error_setg(errp, "Failed to validate capabilities"); + ok =3D false; goto out; } =20 @@ -409,11 +413,12 @@ out: state->capabilities =3D NULL; state->caps_count =3D 0; =20 - return ret; + return ok; } =20 -static int get_capability(QEMUFile *f, void *pv, size_t size, - const VMStateField *field) +static bool load_capability(QEMUFile *f, void *pv, size_t size, + const VMStateField *field, + Error **errp) { MigrationCapability *capability =3D pv; char capability_str[UINT8_MAX + 1]; @@ -426,15 +431,16 @@ static int get_capability(QEMUFile *f, void *pv, size= _t size, for (i =3D 0; i < MIGRATION_CAPABILITY__MAX; i++) { if (!strcmp(MigrationCapability_str(i), capability_str)) { *capability =3D i; - return 0; + return true; } } - error_report("Received unknown capability %s", capability_str); - return -EINVAL; + error_setg(errp, "Received unknown capability %s", capability_str); + return false; } =20 -static int put_capability(QEMUFile *f, void *pv, size_t size, - const VMStateField *field, JSONWriter *vmdesc) +static bool save_capability(QEMUFile *f, void *pv, size_t size, + const VMStateField *field, JSONWriter *vmdesc, + Error **errp) { MigrationCapability *capability =3D pv; const char *capability_str =3D MigrationCapability_str(*capability); @@ -443,13 +449,13 @@ static int put_capability(QEMUFile *f, void *pv, size= _t size, =20 qemu_put_byte(f, len); qemu_put_buffer(f, (uint8_t *)capability_str, len); - return 0; + return true; } =20 static const VMStateInfo vmstate_info_capability =3D { .name =3D "capability", - .get =3D get_capability, - .put =3D put_capability, + .load =3D load_capability, + .save =3D save_capability, }; =20 /* The target-page-bits subsection is present only if the @@ -539,9 +545,9 @@ static const VMStateDescription vmstate_uuid =3D { static const VMStateDescription vmstate_configuration =3D { .name =3D "configuration", .version_id =3D 1, - .pre_load =3D configuration_pre_load, - .post_load =3D configuration_post_load, - .pre_save =3D configuration_pre_save, + .pre_load_errp =3D configuration_pre_load, + .post_load_errp =3D configuration_post_load, + .pre_save_errp =3D configuration_pre_save, .post_save =3D configuration_post_save, .fields =3D (const VMStateField[]) { VMSTATE_UINT32(len, SaveState), @@ -969,8 +975,13 @@ static int vmstate_load(QEMUFile *f, SaveStateEntry *s= e, Error **errp) } return ret; } - return vmstate_load_state(f, se->vmsd, se->opaque, se->load_version_id, - errp); + + if (!vmstate_load_vmsd(f, se->vmsd, se->opaque, se->load_version_id, + errp)) { + return -EINVAL; + } + + return 0; } =20 static void vmstate_save_old_style(QEMUFile *f, SaveStateEntry *se, @@ -1028,8 +1039,6 @@ static void save_section_footer(QEMUFile *f, SaveStat= eEntry *se) static int vmstate_save(QEMUFile *f, SaveStateEntry *se, JSONWriter *vmdes= c, Error **errp) { - int ret; - if ((!se->ops || !se->ops->save_state) && !se->vmsd) { return 0; } @@ -1050,10 +1059,8 @@ static int vmstate_save(QEMUFile *f, SaveStateEntry = *se, JSONWriter *vmdesc, if (!se->vmsd) { vmstate_save_old_style(f, se, vmdesc); } else { - ret =3D vmstate_save_state(f, se->vmsd, se->opaque, vmdesc, - errp); - if (ret) { - return ret; + if (!vmstate_save_vmsd(f, se->vmsd, se->opaque, vmdesc, errp)) { + return -EINVAL; } } =20 @@ -1317,8 +1324,8 @@ static void qemu_savevm_send_configuration(MigrationS= tate *s, QEMUFile *f) json_writer_start_object(vmdesc, "configuration"); } =20 - vmstate_save_state(f, &vmstate_configuration, &savevm_state, - vmdesc, &local_err); + vmstate_save_vmsd(f, &vmstate_configuration, &savevm_state, + vmdesc, &local_err); if (local_err) { error_report_err(local_err); } @@ -2748,7 +2755,6 @@ qemu_loadvm_section_part_end(QEMUFile *f, uint8_t typ= e, Error **errp) static int qemu_loadvm_state_header(QEMUFile *f, Error **errp) { unsigned int v; - int ret; =20 v =3D qemu_get_be32(f); if (v !=3D QEMU_VM_FILE_MAGIC) { @@ -2779,10 +2785,9 @@ static int qemu_loadvm_state_header(QEMUFile *f, Err= or **errp) return -EINVAL; } =20 - ret =3D vmstate_load_state(f, &vmstate_configuration, &savevm_stat= e, 0, - errp); - if (ret) { - return ret; + if (!vmstate_load_vmsd(f, &vmstate_configuration, &savevm_state, 0, + errp)) { + return -EINVAL; } } return 0; --=20 2.52.0