From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DABA4CA0EEB for ; Thu, 21 Aug 2025 08:53:10 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1up0zj-0003Rv-EV; Thu, 21 Aug 2025 04:50:04 -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 1up0z8-0001Tk-TA for qemu-devel@nongnu.org; Thu, 21 Aug 2025 04:49:27 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1up0z3-0001np-IG for qemu-devel@nongnu.org; Thu, 21 Aug 2025 04:49:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1755766158; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=aYLt2RSeJxxoQwGBQ8XY2RieBB0inql96aCo0zoBdoA=; b=CTaf47pim3CERQP0zbAJl7dpm1mQsu+LRgYFUruJirsbnpirHu02paezyXc3lENBEjNGDL XRNpQJxTAhFXrEYEVudqlFmstgHnltStZgF39s/Ia2gLkmKJnt7mA+bLthqJJ6tIGrDHhJ e05wHcft/72N+Rcct7Pf4Oa6nS0v3cY= Received: from mail-pl1-f198.google.com (mail-pl1-f198.google.com [209.85.214.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-679-ovQ1zUNwNC2JfAXCEpur7w-1; Thu, 21 Aug 2025 04:49:15 -0400 X-MC-Unique: ovQ1zUNwNC2JfAXCEpur7w-1 X-Mimecast-MFC-AGG-ID: ovQ1zUNwNC2JfAXCEpur7w_1755766154 Received: by mail-pl1-f198.google.com with SMTP id d9443c01a7336-2445820337cso8896185ad.3 for ; Thu, 21 Aug 2025 01:49:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755766154; x=1756370954; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=aYLt2RSeJxxoQwGBQ8XY2RieBB0inql96aCo0zoBdoA=; b=KGyavOgyXFKjMqXyNP0nqo6x5Be/Uev26/MeYZ5PZLoMhMvuVeto2QIWL24QW2NmVg csO4xgujFLOCYOa3OuGOwsW1RsaUGGFDPQRv9U7Ud3fb8/TknTnCqVVf60O2i6s30/P/ YJIgSLxb2hKgDMEQlC4624NNUVSLbQ2lJ0QE6TJUQL4VMk11juixS1Z++BTEANENgIXO Z2uKSk7I1vQPmtGZOCQhOssnwQUf4HlGoAGVRSpwPwxbUltObSEmUd+4ScbxKGAZ53v4 Ocx52MkR40qAK0kUL6Px33/N77sJwldjmJ5duy2MOpqcLZjtHzbRl6t3cLMy4z2fiyRW 8+oA== X-Gm-Message-State: AOJu0YzuiXUWAOa/yG0xKqYRki/HptUCxri1qMVAuFTk/c5sO1B3igsq bxuLoelfcfMWZr1n6i5W8bJ0Bwq7af/cywSLFXx9JaZXDugMwRUCB783XG6yNyZnEpghcRJIAUL QZpDOjMkcPnikIZlVA4zkHL4PC3fpRPjNtR+arDM5Jg3X4AJG5b6r+Dy8 X-Gm-Gg: ASbGncvrGMg2RLdUCp0bCrkUshh5PtO142lII3vMbnqw8x1z2D42i9lU338nn151BB2 9H+B7+GzlNSnpRbImtrK5dEUlFSDeab8gdIUVi+ovyRtCTLHIEMbWbYf+gO/aydH5kW2wA6mzDs 3afXKJWaSj/P1yX5przqiAM/LiTOc+aFUKDeN8uPDveJNR4KS6upGmBzYIHIi8l46MQ9qCm6Zwz p5K5sSDxWs+7GHexlx6ug5tHnFj1fNPoK8jmZPsGkn8qBl46IqZToFYtL7BApnAxC3fftHodLiD 057Ez45ZxTT/0lvFabiZJdRgxfBsStd+cVaY/x+p6h58GEtkC4gb X-Received: by 2002:a17:903:1b47:b0:242:b315:dda7 with SMTP id d9443c01a7336-245febef6famr22067275ad.3.1755766154313; Thu, 21 Aug 2025 01:49:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEKEjR4yLtD2g3vFKzQvwvjCahP1aDWJeIdTUgc2rf2ecTI+7mZQTewNBD0zo2na2oa3Pznew== X-Received: by 2002:a17:903:1b47:b0:242:b315:dda7 with SMTP id d9443c01a7336-245febef6famr22066945ad.3.1755766153847; Thu, 21 Aug 2025 01:49:13 -0700 (PDT) Received: from armenon-kvm.bengluru.csb ([49.47.192.65]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-245ed33e05dsm48789985ad.3.2025.08.21.01.49.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Aug 2025 01:49:13 -0700 (PDT) From: Arun Menon Date: Thu, 21 Aug 2025 14:14:20 +0530 Subject: [PATCH v12 26/27] migration: Add error-parameterized function variants in VMSD struct MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20250821-propagate_tpm_error-v12-26-72b803e707dc@redhat.com> References: <20250821-propagate_tpm_error-v12-0-72b803e707dc@redhat.com> In-Reply-To: <20250821-propagate_tpm_error-v12-0-72b803e707dc@redhat.com> To: qemu-devel@nongnu.org Cc: Peter Xu , Fabiano Rosas , =?utf-8?q?Alex_Benn=C3=A9e?= , Akihiko Odaki , Dmitry Osipenko , "Michael S. Tsirkin" , Marcel Apfelbaum , Cornelia Huck , Halil Pasic , Eric Farman , Thomas Huth , Christian Borntraeger , Matthew Rosato , Richard Henderson , David Hildenbrand , Ilya Leoshkevich , Nicholas Piggin , Harsh Prateek Bora , Paolo Bonzini , Fam Zheng , Alex Williamson , =?utf-8?q?C=C3=A9dric_Le_Goater?= , Steve Sistare , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , qemu-s390x@nongnu.org, qemu-ppc@nongnu.org, Hailiang Zhang , Stefan Berger , Peter Maydell , qemu-arm@nongnu.org, Arun Menon X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=6573; i=armenon@redhat.com; h=from:subject:message-id; bh=bA8w2RL2yE8W1o0oSEdgk2K28Sd2PPEUffHlP5NWeZU=; b=owGbwMvMwCWWVaVqcZPfqI/xtFoSQ8ayO6mOJ4wrhUQXLQxfOiV7yhXmOMvTH+9mr+e1Vtt4M Vn38cOSjlIWBjEuBlkxRZaGrwGyTQGFEZG2L6/DzGFlAhnCwMUpABOpv83IcPP7ufTuoB1ya+Z+ Cq3XPbDtZexVFtbmPXzH6k226pvp6DEyXLrjwaLF0NQ8PZF1+cbTjHsmzAv7sS4mwTBtumdED68 JJwA= X-Developer-Key: i=armenon@redhat.com; a=openpgp; fpr=80F5501D82507158593DE9D76A7A2538D90F328E Received-SPF: pass client-ip=170.10.129.124; envelope-from=armenon@redhat.com; helo=us-smtp-delivery-124.mimecast.com 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, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=unavailable 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org - We need to have good error reporting in the callbacks in VMStateDescription struct. Specifically pre_save, pre_load and post_load callbacks. - It is not possible to change these functions everywhere in one patch, therefore, we introduce a duplicate set of callbacks with Error object passed to them. - So, in this commit, we implement 'errp' variants of these callbacks, introducing an explicit Error object parameter. - This is a functional step towards transitioning the entire codebase to the new error-parameterized functions. - Deliberately called in mutual exclusion from their counterparts, to prevent conflicts during the transition. - New impls should preferentally use 'errp' variants of these methods, and existing impls incrementally converted. The variants without 'errp' are intended to be removed once all usage is converted. Signed-off-by: Arun Menon --- docs/devel/migration/main.rst | 19 +++++++++++++++++++ include/migration/vmstate.h | 14 ++++++++++++++ migration/vmstate.c | 30 +++++++++++++++++++++++++++--- 3 files changed, 60 insertions(+), 3 deletions(-) diff --git a/docs/devel/migration/main.rst b/docs/devel/migration/main.rst index a39fec2e21c26c4315c0cf13b105176d70679d4d..93620102ae875e7477af2e26eeffe636ca0cdbca 100644 --- a/docs/devel/migration/main.rst +++ b/docs/devel/migration/main.rst @@ -444,6 +444,25 @@ The functions to do that are inside a vmstate definition, and are called: This function is called after we save the state of one device (even upon failure, unless the call to pre_save returned an error). +Following are the errp variants of these functions. + +- ``int (*pre_load_errp)(void *opaque, Error **errp);`` + + This function is called before we load the state of one device. + +- ``int (*post_load_errp)(void *opaque, int version_id, Error **errp);`` + + This function is called after we load the state of one device. + +- ``int (*pre_save_errp)(void *opaque, Error **errp);`` + + This function is called before we save the state of one device. + +New impls should preferentally use 'errp' variants of these +methods and existing impls incrementally converted. +The variants without 'errp' are intended to be removed +once all usage is converted. + Example: You can look at hpet.c, that uses the first three functions to massage the state that is transferred. diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h index c1d8e5b7a7d9d544fc8ce181372660f5538ef66b..647d7a35ce5f2c8b8ca5fdb15b54c10a0896cea8 100644 --- a/include/migration/vmstate.h +++ b/include/migration/vmstate.h @@ -200,14 +200,28 @@ struct VMStateDescription { * exclusive. For this reason, also early_setup VMSDs are migrated in a * QEMU_VM_SECTION_FULL section, while save_setup() data is migrated in * a QEMU_VM_SECTION_START section. + * + * There are duplicate impls of the post/pre save/load hooks. + * New impls should preferentally use 'errp' variants of these + * methods and existing impls incrementally converted. + * The variants without 'errp' are intended to be removed + * once all usage is converted. + * + * For the errp variants, + * Returns: 0 on success, + * <0 on error where -value is an error number from errno.h */ + bool early_setup; int version_id; int minimum_version_id; MigrationPriority priority; int (*pre_load)(void *opaque); + int (*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); int (*pre_save)(void *opaque); + int (*pre_save_errp)(void *opaque, Error **errp); void (*cleanup_save)(void *opaque); bool (*needed)(void *opaque); bool (*dev_unplug_pending)(void *opaque); diff --git a/migration/vmstate.c b/migration/vmstate.c index 283b5c48d39d572c1b19819ed1860c68e118d674..5fd19acc410123be2ad23aadeb28e3ad708762e5 100644 --- a/migration/vmstate.c +++ b/migration/vmstate.c @@ -153,7 +153,16 @@ int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd, trace_vmstate_load_state_end(vmsd->name, "too old", -EINVAL); return -EINVAL; } - if (vmsd->pre_load) { + if (vmsd->pre_load_errp) { + ret = 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; + } + } else if (vmsd->pre_load) { ret = vmsd->pre_load(opaque); if (ret) { error_setg(errp, "pre load hook failed for: '%s', " @@ -249,7 +258,14 @@ int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd, qemu_file_set_error(f, ret); return ret; } - if (vmsd->post_load) { + if (vmsd->post_load_errp) { + ret = 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); + } + } else if (vmsd->post_load) { ret = vmsd->post_load(opaque, version_id); if (ret < 0) { error_setg(errp, @@ -418,12 +434,20 @@ int vmstate_save_state(QEMUFile *f, const VMStateDescription *vmsd, int vmstate_save_state_v(QEMUFile *f, const VMStateDescription *vmsd, void *opaque, JSONWriter *vmdesc, int version_id, Error **errp) { + ERRP_GUARD(); int ret = 0; const VMStateField *field = vmsd->fields; trace_vmstate_save_state_top(vmsd->name); - if (vmsd->pre_save) { + if (vmsd->pre_save_errp) { + ret = vmsd->pre_save_errp(opaque, errp); + trace_vmstate_save_state_pre_save_res(vmsd->name, ret); + if (ret < 0) { + error_prepend(errp, "pre-save for %s failed, ret: %d: ", + vmsd->name, ret); + } + } else if (vmsd->pre_save) { ret = vmsd->pre_save(opaque); trace_vmstate_save_state_pre_save_res(vmsd->name, ret); if (ret) { -- 2.50.1