From nobody Thu Dec 18 19:37:03 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1547826147826509.6276526145749; Fri, 18 Jan 2019 07:42:27 -0800 (PST) Received: from localhost ([127.0.0.1]:41683 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gkWHq-0006Sn-Pb for importer@patchew.org; Fri, 18 Jan 2019 10:42:26 -0500 Received: from eggs.gnu.org ([209.51.188.92]:43274) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gkVbe-0002xQ-L5 for qemu-devel@nongnu.org; Fri, 18 Jan 2019 09:58:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gkVbd-0007Yo-KO for qemu-devel@nongnu.org; Fri, 18 Jan 2019 09:58:50 -0500 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]:40302) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gkVbd-0007Y9-DQ for qemu-devel@nongnu.org; Fri, 18 Jan 2019 09:58:49 -0500 Received: by mail-wr1-x443.google.com with SMTP id p4so15418836wrt.7 for ; Fri, 18 Jan 2019 06:58:49 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id e27sm92094561wra.67.2019.01.18.06.58.47 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 18 Jan 2019 06:58:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=37vpT9ZhqUc4By2gBmZ5lzO24eMh2TWirKsg8cK6+GQ=; b=L+qfDD7lS2+7LY+unqPzjdv5pFqEVSbCpbxCptGujGKQNErwhYqLkOoYxSRGQ6y8XQ o2voXRqJiWh0C8ZdHUVvLFmpLhsPG0qJPnJG/yhPidWUe4XZ1pNaMo6wpoEnr2QbYfDR 9f+KytW4DwhtBGS1nYwMtNMz/5KyJznEuulrI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=37vpT9ZhqUc4By2gBmZ5lzO24eMh2TWirKsg8cK6+GQ=; b=BAzRtYm7dlES5Wedalj07E9hJZQsHHmRSXNqV4U9dz+yPu3U3lqn4YuGibtnSDCs2z SKXkPAPf/e1s0CkAdB7fiZHqudv6INTV/yhAhqmxd1zZXGc8J+Ld+NjudtmnAESNcxwZ zaJzzp1W9OIkI4AISJwGEXSZrqh+ijsf1T+rOORR4eI02Xji9KNgmVehpWvh0DsV9xhz eQ8yTzgfKbMw+dc5eINGE/rGLqaP9HaerkkJKz/2+Lhbf+xg3LbH4KjDRD2zmz4x+N9w WDrIvHq8g+E4ex8KXl6nTW7rKkMbl/924CEAYwyNYANrjuZNkkqwwA84HiaqzgUnwodt BxmA== X-Gm-Message-State: AJcUukfWP1lyoQzuhzQoAsdh8Gn3psNb+06n4/3bCNk+FgLT8NkSR0OJ yrdjaxINXeqWLPa2F1oEM//yU2/G4WxBVA== X-Google-Smtp-Source: ALg8bN4WqvlOgC79/3efKo5rEy4VyML59A1wxvSkxLZdCllCguMHRZslCtMHEuHpkY4nSiHDoOBpBg== X-Received: by 2002:a5d:4d11:: with SMTP id z17mr16038764wrt.209.1547823528210; Fri, 18 Jan 2019 06:58:48 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Date: Fri, 18 Jan 2019 14:57:52 +0000 Message-Id: <20190118145805.6852-37-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190118145805.6852-1-peter.maydell@linaro.org> References: <20190118145805.6852-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::443 Subject: [Qemu-devel] [PULL 36/49] 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Aaron Lindsay 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 Reviewed-by: Peter Maydell Reviewed-by: Dr. David Alan Gilbert Message-id: 20181211151945.29137-2-aaron@os.amperecomputing.com Signed-off-by: Peter Maydell --- include/migration/vmstate.h | 1 + migration/vmstate.c | 13 ++++++++++++- docs/devel/migration.rst | 9 +++++++-- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h index 61bef3ef5c0..067b126cf16 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); + int (*post_save)(void *opaque); bool (*needed)(void *opaque); const VMStateField *fields; const VMStateDescription **subsections; diff --git a/migration/vmstate.c b/migration/vmstate.c index 80b59009aab..e2bbb7b5f7f 100644 --- a/migration/vmstate.c +++ b/migration/vmstate.c @@ -390,6 +390,9 @@ int vmstate_save_state_v(QEMUFile *f, const VMStateDesc= ription *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; } =20 @@ -415,7 +418,15 @@ int vmstate_save_state_v(QEMUFile *f, const VMStateDes= cription *vmsd, json_end_array(vmdesc); } =20 - return vmstate_subsection_save(f, vmsd, opaque, vmdesc); + ret =3D vmstate_subsection_save(f, vmsd, opaque, vmdesc); + + if (vmsd->post_save) { + int ps_ret =3D vmsd->post_save(opaque); + if (!ret) { + ret =3D ps_ret; + } + } + return ret; } =20 static const VMStateDescription * diff --git a/docs/devel/migration.rst b/docs/devel/migration.rst index e7658ab0506..220059679ac 100644 --- a/docs/devel/migration.rst +++ b/docs/devel/migration.rst @@ -419,8 +419,13 @@ The functions to do that are inside a vmstate definiti= on, and are called: =20 This function is called before we save the state of one device. =20 -Example: You can look at hpet.c, that uses the three function to -massage the state that is transferred. +- ``int (*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 an error). + +Example: You can look at hpet.c, that uses the first three functions +to massage the state that is transferred. =20 The ``VMSTATE_WITH_TMP`` macro may be useful when the migration data doesn't match the stored device data well; it allows an --=20 2.20.1