From nobody Fri Nov 14 17:03:04 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=1760952018; cv=none; d=zohomail.com; s=zohoarc; b=KnL2va54B0uheNUnfzLyhHcMTuguIVbT1lV4oPZrlLlDhY0kANlRc+emGdCn+MCxEjcuYhVxBUFtBwVGuW9N0wc+hvmkvApj08qQaD+6u/iSFGmKb2G0fVAGVUzKOgVkG7FAxqDqikgmhDAYJaboAebC6BF/K7zA/GaHSAH/fJ0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760952018; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=7kIPUyfA296TEPUovVoKhXBwjsl3BvS8mp986COa+xo=; b=n0o7YQacm6qy2VKK1trb/dW5llyVE0/sgsSpxy+nnH1eZ7Eu4V49S3NIbk/HHdaJg/DizG5pQmvzh+O49ZYkZHhXqwAjY70/W49xNpz2YnBWxY0UWz014UdTrBAtZIw49yYiZAamnIFPliFdf00o6qI0ite7xEJfPZernUFksm0= 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 1760952018577798.7416084918974; Mon, 20 Oct 2025 02:20:18 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vAm36-0004kU-Nd; Mon, 20 Oct 2025 05:19:28 -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 1vAm32-0004kE-GZ for qemu-devel@nongnu.org; Mon, 20 Oct 2025 05:19:24 -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 1vAm2z-00065d-P0 for qemu-devel@nongnu.org; Mon, 20 Oct 2025 05:19:24 -0400 Received: from mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:9297:0:640:61e7:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTPS id B9C2280794; Mon, 20 Oct 2025 12:19:12 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a51::1:37]) by mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id AJRWei3FoKo0-lxC7R4Py; Mon, 20 Oct 2025 12:19:12 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1760951952; bh=7kIPUyfA296TEPUovVoKhXBwjsl3BvS8mp986COa+xo=; h=Message-ID:Date:Cc:Subject:To:From; b=soJ8BdBSFkqoaFM/7Wa6eqpezsDbpMf/jQ629tIkZvNXkVJToR4+33pxuMzsYF4W2 b5kxZkfao6hf1HBV/2dB3ZlooEVUo4yzqdI0Q5fmWo/OtQi2lu+J0Pvg54IH7pHl/h taJIq9mU7WwXT3b2Cz8C0tuMO0WIF9eq2KLhHld0= Authentication-Results: mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: peterx@redhat.com Cc: stefanb@linux.vnet.ibm.com, farosas@suse.de, qemu-devel@nongnu.org, vsementsov@yandex-team.ru, armbru@redhat.com Subject: [PATCH] migration: vmsd errp handlers: return bool Date: Mon, 20 Oct 2025 12:19:07 +0300 Message-ID: <20251020091907.2173711-1-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 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: 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: 1760952024158154100 Content-Type: text/plain; charset="utf-8" Recently we moved to returning errp. Why to keep int return value? Generally it doesn't help: you can't use in a logic of handling an error, as you are never sure, that in future the logic in the stack will not change: it may start to return another error code in the same case, or return same error code in another case. Actually, we can only rely on concrete errno code when get it _directly_ from documented library function or syscall. This way we handle for example EINTR. But later in a stack, we can only add this errno to the textual error by strerror(). Let this new, recently added API be simpler and clearer, let it return simple boolean value, so we shouldn't think: - should we handle different error codes differently (if yes - how exactly, if no - why do we need this information?) - should we add it to errp, or it was already added earlier in the stack Signed-off-by: Vladimir Sementsov-Ogievskiy --- backends/tpm/tpm_emulator.c | 10 ++++------ docs/devel/migration/main.rst | 6 +++--- include/migration/vmstate.h | 6 +++--- migration/vmstate.c | 31 +++++++++++++------------------ 4 files changed, 23 insertions(+), 30 deletions(-) diff --git a/backends/tpm/tpm_emulator.c b/backends/tpm/tpm_emulator.c index dacfca5ab7..3937ac5572 100644 --- a/backends/tpm/tpm_emulator.c +++ b/backends/tpm/tpm_emulator.c @@ -947,24 +947,22 @@ static void tpm_emulator_vm_state_change(void *opaque= , bool running, =20 /* * Load the TPM state blobs into the TPM. - * - * Returns negative errno codes in case of error. */ -static int tpm_emulator_post_load(void *opaque, int version_id, Error **er= rp) +static bool tpm_emulator_post_load(void *opaque, int version_id, Error **e= rrp) { TPMBackend *tb =3D opaque; int ret; =20 ret =3D tpm_emulator_set_state_blobs(tb, errp); if (ret < 0) { - return ret; + return false; } =20 if (tpm_emulator_startup_tpm_resume(tb, 0, true) < 0) { - return -EIO; + return false; } =20 - return 0; + return true; } =20 static const VMStateDescription vmstate_tpm_emulator =3D { diff --git a/docs/devel/migration/main.rst b/docs/devel/migration/main.rst index 1afe7b9689..234d280249 100644 --- a/docs/devel/migration/main.rst +++ b/docs/devel/migration/main.rst @@ -446,15 +446,15 @@ The functions to do that are inside a vmstate definit= ion, and are called: =20 Following are the errp variants of these functions. =20 -- ``int (*pre_load_errp)(void *opaque, Error **errp);`` +- ``bool (*pre_load_errp)(void *opaque, Error **errp);`` =20 This function is called before we load the state of one device. =20 -- ``int (*post_load_errp)(void *opaque, int version_id, Error **errp);`` +- ``bool (*post_load_errp)(void *opaque, int version_id, Error **errp);`` =20 This function is called after we load the state of one device. =20 -- ``int (*pre_save_errp)(void *opaque, Error **errp);`` +- ``bool (*pre_save_errp)(void *opaque, Error **errp);`` =20 This function is called before we save the state of one device. =20 diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h index 63ccaee07a..dbe330dd5f 100644 --- a/include/migration/vmstate.h +++ b/include/migration/vmstate.h @@ -218,11 +218,11 @@ struct VMStateDescription { int minimum_version_id; MigrationPriority priority; int (*pre_load)(void *opaque); - int (*pre_load_errp)(void *opaque, Error **errp); + bool (*pre_load_errp)(void *opaque, Error **errp); int (*post_load)(void *opaque, int version_id); - int (*post_load_errp)(void *opaque, int version_id, Error **errp); + bool (*post_load_errp)(void *opaque, int version_id, Error **errp); int (*pre_save)(void *opaque); - int (*pre_save_errp)(void *opaque, Error **errp); + bool (*pre_save_errp)(void *opaque, Error **errp); int (*post_save)(void *opaque); bool (*needed)(void *opaque); bool (*dev_unplug_pending)(void *opaque); diff --git a/migration/vmstate.c b/migration/vmstate.c index 81eadde553..026fd6f1a4 100644 --- a/migration/vmstate.c +++ b/migration/vmstate.c @@ -153,15 +153,12 @@ int vmstate_load_state(QEMUFile *f, const VMStateDesc= ription *vmsd, trace_vmstate_load_state_end(vmsd->name, "too old", -EINVAL); return -EINVAL; } - if (vmsd->pre_load_errp) { - ret =3D vmsd->pre_load_errp(opaque, errp); - if (ret < 0) { - error_prepend(errp, "pre load hook failed for: '%s', " - "version_id: %d, minimum version_id: %d, " - "ret: %d: ", vmsd->name, vmsd->version_id, - vmsd->minimum_version_id, ret); - return ret; - } + if (vmsd->pre_load_errp && !vmsd->pre_load_errp(opaque, errp)) { + error_prepend(errp, "pre load hook failed for: '%s', " + "version_id: %d, minimum version_id: %d, " + "ret: %d: ", vmsd->name, vmsd->version_id, + vmsd->minimum_version_id, ret); + return -EINVAL; } else if (vmsd->pre_load) { ret =3D vmsd->pre_load(opaque); if (ret) { @@ -255,13 +252,12 @@ int vmstate_load_state(QEMUFile *f, const VMStateDesc= ription *vmsd, qemu_file_set_error(f, ret); return ret; } - if (vmsd->post_load_errp) { - ret =3D vmsd->post_load_errp(opaque, version_id, errp); - if (ret < 0) { - error_prepend(errp, "post load hook failed for: %s, version_id= : " - "%d, minimum_version: %d, ret: %d: ", vmsd->name, - vmsd->version_id, vmsd->minimum_version_id, ret); - } + if (vmsd->post_load_errp && !vmsd->post_load_errp(opaque, version_id, + errp)) { + error_prepend(errp, "post load hook failed for: %s, version_id: " + "%d, minimum_version: %d, ret: %d: ", vmsd->name, + vmsd->version_id, vmsd->minimum_version_id, ret); + ret =3D -EINVAL; } else if (vmsd->post_load) { ret =3D vmsd->post_load(opaque, version_id); if (ret < 0) { @@ -438,9 +434,8 @@ int vmstate_save_state_v(QEMUFile *f, const VMStateDesc= ription *vmsd, trace_vmstate_save_state_top(vmsd->name); =20 if (vmsd->pre_save_errp) { - ret =3D vmsd->pre_save_errp(opaque, errp); trace_vmstate_save_state_pre_save_res(vmsd->name, ret); - if (ret < 0) { + if (!vmsd->pre_save_errp(opaque, errp)) { error_prepend(errp, "pre-save for %s failed, ret: %d: ", vmsd->name, ret); } --=20 2.48.1