From nobody Fri Nov 14 21:05:49 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=1761693665; cv=none; d=zohomail.com; s=zohoarc; b=F1vlPwgzlS/bzZpeDCi5eyn9GEYr4txFK194bubznjmk1THFBRf6y55qLwSUL5gJnud9SIEOo8BCKIkdFE1iSLJV09fjKP9YXyCv5YG+fRQ0mZjfT5/OrDi1NFBE12DmPBhmNRqeZ8KEX4IK9qV4/iAHTDpg/ja8WgxPUFe/K0M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1761693665; 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=+knwUWedSlJ+bK+l2EihRlaK7GqDMvgSpwZc7/hhY3I=; b=ZsrTNuBgK22+5HI6uIRd7htg1edItXRIEDPWg11+3CXS5GxaeUy0wG7GVhwSckQ7PLqvoLpsG8n/mHy6YVx7yau280CovxqiKxVNS08PmAzOoUlr5w+8E3ww2941+oxXSlBhUUsCUp+zz5F9CLkp16US3VbXJbezGiXsPkP9cSY= 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 1761693665717941.8750198089214; Tue, 28 Oct 2025 16:21:05 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vDsu5-00038Q-9w; Tue, 28 Oct 2025 19:15:02 -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 1vDstu-00037T-4Y for qemu-devel@nongnu.org; Tue, 28 Oct 2025 19:14:50 -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 1vDstZ-00018J-M2 for qemu-devel@nongnu.org; Tue, 28 Oct 2025 19:14:49 -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 ACEF08177A; Wed, 29 Oct 2025 02:14:04 +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-VelCEPAQ; Wed, 29 Oct 2025 02:14:04 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1761693244; bh=+knwUWedSlJ+bK+l2EihRlaK7GqDMvgSpwZc7/hhY3I=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=KikwEammD27/em0yhEXxLPq6hnnG8tqY0kkdA38skcA1/D77hrmMyIJWEMMVzKepH hC2vkVcEQBIOss2+pP1/MwKOttM5ikvqcp3h/PImk8bqIfBtaRx4i4JS6GXe8DUgvp 7klJ8qsCvWVMKG/CLBGz0ohkxKqLxXXVycp7QkJw= 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 18/22] migration/savevm: move to new migration APIs Date: Wed, 29 Oct 2025 02:13:42 +0300 Message-ID: <20251028231347.194844-19-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: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, 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 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: 1761693670310158500 Content-Type: text/plain; charset="utf-8" Signed-off-by: Vladimir Sementsov-Ogievskiy --- migration/savevm.c | 108 +++++++++++++++++++++++---------------------- 1 file changed, 55 insertions(+), 53 deletions(-) diff --git a/migration/savevm.c b/migration/savevm.c index 7b35ec4dd0..e2681880f0 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 @@ -298,7 +299,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; @@ -319,7 +320,7 @@ static int configuration_pre_save(void *opaque) } state->uuid =3D qemu_uuid; =20 - return 0; + return true; } =20 static int configuration_post_save(void *opaque) @@ -332,7 +333,7 @@ static int configuration_post_save(void *opaque) return 0; } =20 -static int configuration_pre_load(void *opaque) +static bool configuration_pre_load(void *opaque, Error **errp) { SaveState *state =3D opaque; =20 @@ -341,7 +342,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) @@ -378,28 +379,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 @@ -411,11 +415,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]; @@ -428,15 +433,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); @@ -445,13 +451,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 @@ -541,9 +547,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), @@ -975,8 +981,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, @@ -1034,8 +1045,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; } @@ -1055,12 +1064,8 @@ static int vmstate_save(QEMUFile *f, SaveStateEntry = *se, JSONWriter *vmdesc, trace_vmstate_save(se->idstr, se->vmsd ? se->vmsd->name : "(old)"); 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; - } + } else if (!vmstate_save_vmsd(f, se->vmsd, se->opaque, vmdesc, errp)) { + return -EINVAL; } =20 trace_savevm_section_end(se->idstr, se->section_id, 0); @@ -1304,9 +1309,8 @@ void qemu_savevm_state_header(QEMUFile *f) json_writer_start_object(vmdesc, "configuration"); } =20 - vmstate_save_state(f, &vmstate_configuration, &savevm_state, - vmdesc, &local_err); - if (local_err) { + if (!vmstate_save_vmsd(f, &vmstate_configuration, &savevm_state, + vmdesc, &local_err)) { error_report_err(local_err); } =20 @@ -2850,7 +2854,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) { @@ -2881,10 +2884,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.48.1