From patchwork Wed Oct 10 20:37:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aaron Lindsay X-Patchwork-Id: 982102 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="A2zugbyK"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42VmNX4sddz9s9J for ; Thu, 11 Oct 2018 07:46:36 +1100 (AEDT) Received: from localhost ([::1]:59076 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gALNK-0000TM-8y for incoming@patchwork.ozlabs.org; Wed, 10 Oct 2018 16:46:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39618) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gALFb-0002rn-Sz for qemu-devel@nongnu.org; Wed, 10 Oct 2018 16:38:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gALFa-0002V0-P3 for qemu-devel@nongnu.org; Wed, 10 Oct 2018 16:38:35 -0400 Received: from mail-yb1-xb42.google.com ([2607:f8b0:4864:20::b42]:41873) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gALFV-0002Np-M1; Wed, 10 Oct 2018 16:38:29 -0400 Received: by mail-yb1-xb42.google.com with SMTP id e16-v6so2754152ybk.8; Wed, 10 Oct 2018 13:38:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=lcqRW3+QlXEvaODHcyzMa2/tXsQVITsUxvIKVHTwHag=; b=A2zugbyKfkLhrC/EK5ZhMoWjJnaJrlgHaeZd6PlTL/4Wfpqlk35eVT0Ri0+NabE12a 3ScegIXeHBb2pCiV+WRni46R1Qg0uNFCv8oGkgc0bEZgXX5Sk7pdL6gDlJ8wCLcvG8r2 iEpRk4cY5qvg2yWyuLkCnPquraDTaLeeI7EWx27QCg6/jFlM+jdCRPDBUjKofbOzHHWv 6gn0EQa1JAl5Az9/jlODtZNGJwxK0sS7OzqnVU/umBfqxujqV5AQR+gDNw7Q8rLWqs/9 ZZeArpyc8nlKSXpD2bj2F0rLwuZZIkiw7iWuuxZfPmODFUAfx6iSsMpdTpvfG1H+kvB+ ktzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=lcqRW3+QlXEvaODHcyzMa2/tXsQVITsUxvIKVHTwHag=; b=WzINA1mYZ1+bK6bAOcI4MvOoMAkpfgwfnBT8vAAmlGLi1R7Jkqx6t3v5nGOO+1PKDN oeWKuVN/LALkBrfZOxD7zRRrSCpyLsf8PAiX7ctcm4qXcfASMP0GJJsJWgZW+OEbMtFF YEEDdsjZJidtuE1asbZTIjuHOhcyCll6dK+ATVWBRN8Kf9xAFLi62GW4gS6n2ELRWiXv L+TUL9yULGPP5mATMTxoCoeYYmpfBGQtXxtYLfc0lMAHECoGAWB2EqFmHyszeCDXpOt2 IAHr8Jj1XHZ7nqqLwsuR8r2O9oj5znRTa+jewqO7SGluu94BDSGXfyd6aQnlWJkLtsX9 RHZQ== X-Gm-Message-State: ABuFfoiJP5MT1VEWni0kiSeY2o3NBYGEXi584qMf7McOxfCsDBFmWTDY HFYhh6OtaKH1yLr/co7v1KqwNt8j X-Google-Smtp-Source: ACcGV62G8A8xLq164W9roei0Yrn8VOJzAqkRuQcDjcRKYZhJKhLKsmvevsqAjtZ8a9ZOcZGn4X314g== X-Received: by 2002:a25:ace2:: with SMTP id x34-v6mr19272250ybd.161.1539203905994; Wed, 10 Oct 2018 13:38:25 -0700 (PDT) Received: from quinoa.localdomain ([216.85.170.153]) by smtp.gmail.com with ESMTPSA id u131-v6sm15170728ywf.13.2018.10.10.13.38.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 10 Oct 2018 13:38:25 -0700 (PDT) From: Aaron Lindsay To: qemu-arm@nongnu.org, Peter Maydell , Alistair Francis , Wei Huang , Peter Crosthwaite Date: Wed, 10 Oct 2018 16:37:24 -0400 Message-Id: <20181010203735.27918-4-aclindsa@gmail.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181010203735.27918-1-aclindsa@gmail.com> References: <20181010203735.27918-1-aclindsa@gmail.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::b42 Subject: [Qemu-devel] [PATCH v6 03/14] migration: Add post_save function to VMStateDescription X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Aaron Lindsay , Michael Spradling , qemu-devel@nongnu.org, Digant Desai Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" In some cases it may be helpful to modify state before saving it for migration, and then modify the state back after it has been saved. The existing pre_save function provides half of this functionality. This patch adds a post_save function to provide the second half. Signed-off-by: Aaron Lindsay --- docs/devel/migration.rst | 9 +++++++-- include/migration/vmstate.h | 1 + migration/vmstate.c | 10 +++++++++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/docs/devel/migration.rst b/docs/devel/migration.rst index 687570754d..2a2533c9b3 100644 --- a/docs/devel/migration.rst +++ b/docs/devel/migration.rst @@ -419,8 +419,13 @@ The functions to do that are inside a vmstate definition, and are called: This function is called before we save the state of one device. -Example: You can look at hpet.c, that uses the three function to -massage the state that is transferred. +- ``void (*post_save)(void *opaque);`` + + This function is called after we save the state of one device + (even upon failure, unless the call to pre_save returned and error). + +Example: You can look at hpet.c, that uses the first three functions +to massage the state that is transferred. The ``VMSTATE_WITH_TMP`` macro may be useful when the migration data doesn't match the stored device data well; it allows an diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h index 2b501d0466..f6053b94e4 100644 --- a/include/migration/vmstate.h +++ b/include/migration/vmstate.h @@ -185,6 +185,7 @@ struct VMStateDescription { int (*pre_load)(void *opaque); int (*post_load)(void *opaque, int version_id); int (*pre_save)(void *opaque); + void (*post_save)(void *opaque); bool (*needed)(void *opaque); VMStateField *fields; const VMStateDescription **subsections; diff --git a/migration/vmstate.c b/migration/vmstate.c index 0bc240a317..9afc9298f3 100644 --- a/migration/vmstate.c +++ b/migration/vmstate.c @@ -387,6 +387,9 @@ int vmstate_save_state_v(QEMUFile *f, const VMStateDescription *vmsd, if (ret) { error_report("Save of field %s/%s failed", vmsd->name, field->name); + if (vmsd->post_save) { + vmsd->post_save(opaque); + } return ret; } @@ -412,7 +415,12 @@ int vmstate_save_state_v(QEMUFile *f, const VMStateDescription *vmsd, json_end_array(vmdesc); } - return vmstate_subsection_save(f, vmsd, opaque, vmdesc); + ret = vmstate_subsection_save(f, vmsd, opaque, vmdesc); + + if (vmsd->post_save) { + vmsd->post_save(opaque); + } + return ret; } static const VMStateDescription *