From patchwork Wed Apr 25 15:27:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 10363515 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 23A4E60225 for ; Wed, 25 Apr 2018 15:29:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0BDE623B24 for ; Wed, 25 Apr 2018 15:29:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0040728ACE; Wed, 25 Apr 2018 15:29:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 35AA923B24 for ; Wed, 25 Apr 2018 15:29:08 +0000 (UTC) Received: from localhost ([::1]:37653 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fBMLz-00038a-GP for patchwork-qemu-devel@patchwork.kernel.org; Wed, 25 Apr 2018 11:29:07 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50728) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fBMKf-0001rx-HN for qemu-devel@nongnu.org; Wed, 25 Apr 2018 11:27:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fBMKe-0007iG-4s for qemu-devel@nongnu.org; Wed, 25 Apr 2018 11:27:45 -0400 Received: from mail-pf0-x244.google.com ([2607:f8b0:400e:c00::244]:39902) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fBMKd-0007hI-SP for qemu-devel@nongnu.org; Wed, 25 Apr 2018 11:27:44 -0400 Received: by mail-pf0-x244.google.com with SMTP id z9so15528165pfe.6 for ; Wed, 25 Apr 2018 08:27:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=gf/5CowLf0kUhWuFGPaZfNLSbme1genL5quk7A29FGs=; b=ehCM4bj4nmbMjW63oY05IhJpMDSItszAPtTQWv+WxSTuEyY3SV6PSgNVsNYERaCqrJ 0XYPsU1tSvJP2mBHXfrYTzYbiLFiDakznzbCEVI2msnSq+SgqjN6DdojQniwebT5cV2X dXwe68r2w3u1dgosOWfIXQoWcVL1lO8Guew5kh7NsQZxvFt5Y8acxwsN2eeVOMMri6Jm tWkCF1l4MQNkFwi43PwS6svi5w8WxGoMtUYFi4l1uB1D9JTHNWzRhFCqMG+FDqTf4kvx KsZRnlOhcPyAoa9QL4l03hUZZHn22R6/dTI4wRR1GC/wmUO2kcm+RDG+Sdhz/2x1wqVv Ek7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=gf/5CowLf0kUhWuFGPaZfNLSbme1genL5quk7A29FGs=; b=XTjcyFSAGu84wcgvvKDjWlv4YDxsff0hHx/YE8JjnFfAZw3y/+A5l4iffz0M0xsLUc DxC67QPRbQ0Vsb9iPUPQapZZFoyEdKYnf9vA7iJKLIaSaKpCVIDI+dRQ8NJWa+U/uDtd wcQyrnyr7z7Rhz1v3a9N4vKS2cEF7LMqQP+e6EkwN+27JPFluIAovhRusuQfC2ak6IUb JFTi/lpw++QP0jK9PF3jwBgwPcYUzkPK2k1osA4F0ieW0GmxLlTPyIPBB7h/DIPgFx7O x4lMki+sdxF0gTj8oi/9gY4gNHf4fXJwsayCMBrqMPueC0/VbYGl1nQFE72XY4wYPi6p TeBg== X-Gm-Message-State: ALQs6tCb7Ah6kt4dvBFH7b9+q0MtFMlFFV0SYkhGg3IHo+sJBwL7ZVT0 Do8EhuM0U6k50QmCTjaEQoB57SY= X-Google-Smtp-Source: AB8JxZofmkH7uV6AJwQ2YZwzUJDr+0F6C27O27akgaj/66hxepNan4iCtYGjiIgTcnfsnsFLhTdbKg== X-Received: by 2002:a17:902:b7c8:: with SMTP id v8-v6mr4360335plz.45.1524670062887; Wed, 25 Apr 2018 08:27:42 -0700 (PDT) Received: from serve.minyard.net (serve.minyard.net. [2001:470:b8f6:1b::1]) by smtp.gmail.com with ESMTPSA id z62sm12017642pff.57.2018.04.25.08.27.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 25 Apr 2018 08:27:40 -0700 (PDT) Received: from t430.minyard.net (t430m.minyard.net [192.168.27.3]) by serve.minyard.net (Postfix) with ESMTPA id C7340BE7; Wed, 25 Apr 2018 10:27:38 -0500 (CDT) Received: by t430.minyard.net (Postfix, from userid 1000) id 6C182301059; Wed, 25 Apr 2018 10:27:36 -0500 (CDT) From: minyard@acm.org To: "Dr . David Alan Gilbert" , qemu-devel@nongnu.org Date: Wed, 25 Apr 2018 10:27:30 -0500 Message-Id: <1524670052-28373-2-git-send-email-minyard@acm.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1524670052-28373-1-git-send-email-minyard@acm.org> References: <1524670052-28373-1-git-send-email-minyard@acm.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c00::244 Subject: [Qemu-devel] [PATCH v3 1/3] vmstate: Add a VSTRUCT type 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: Corey Minyard Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Corey Minyard The VMS_STRUCT has no way to specify which version of a structure to use. Add a type and a new field to allow the specific version of a structure to be used. Signed-off-by: Corey Minyard --- include/migration/vmstate.h | 45 +++++++++++++++++++++++++++++++++++++++++++++ migration/vmstate.c | 25 +++++++++++++++++++++---- 2 files changed, 66 insertions(+), 4 deletions(-) diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h index df463fd..efa0a11 100644 --- a/include/migration/vmstate.h +++ b/include/migration/vmstate.h @@ -143,6 +143,11 @@ enum VMStateFlags { * to determine the number of entries in the array. Only valid in * combination with one of VMS_VARRAY*. */ VMS_MULTIPLY_ELEMENTS = 0x4000, + + /* A structure field that is like VMS_STRUCT, but uses + * VMStateField.struct_version_id to tell which version of the + * structure we are referencing to use. */ + VMS_VSTRUCT = 0x8000, }; typedef enum { @@ -167,6 +172,7 @@ struct VMStateField { enum VMStateFlags flags; const VMStateDescription *vmsd; int version_id; + int struct_version_id; bool (*field_exists)(void *opaque, int version_id); }; @@ -248,6 +254,25 @@ extern const VMStateInfo vmstate_info_qtailq; vmstate_offset_array(_state, _field, uint8_t, \ sizeof(typeof_field(_state, _field))) +/* In the macros below, if there is a _version, that means the macro's + * field will be processed only if the version being received is >= + * the _version specified. In general, if you add a new field, you + * would increment the structure's version and put that version + * number into the new field so it would only be processed with the + * new version. + * + * In particular, for VMSTATE_STRUCT() and friends the _version does + * *NOT* pick the version of the sub-structure. It works just as + * specified above. The version of the top-level structure received + * is passed down to all sub-structures. This means that the + * sub-structures must have version that are compatible with all the + * structures that use them. + * + * If you want to specify the version of the sub-structure, use + * VMSTATE_VSTRUCT(), which allows the specific sub-structure version + * to be directly specified. + */ + #define VMSTATE_SINGLE_TEST(_field, _state, _test, _version, _info, _type) { \ .name = (stringify(_field)), \ .version_id = (_version), \ @@ -395,6 +420,17 @@ extern const VMStateInfo vmstate_info_qtailq; .offset = offsetof(_state, _field), \ } +#define VMSTATE_VSTRUCT_TEST(_field, _state, _test, _version, _vmsd, _type, _struct_version) { \ + .name = (stringify(_field)), \ + .version_id = (_version), \ + .struct_version_id = (_struct_version), \ + .field_exists = (_test), \ + .vmsd = &(_vmsd), \ + .size = sizeof(_type), \ + .flags = VMS_VSTRUCT, \ + .offset = vmstate_offset_value(_state, _field, _type), \ +} + #define VMSTATE_STRUCT_TEST(_field, _state, _test, _version, _vmsd, _type) { \ .name = (stringify(_field)), \ .version_id = (_version), \ @@ -712,6 +748,13 @@ extern const VMStateInfo vmstate_info_qtailq; #define VMSTATE_SINGLE(_field, _state, _version, _info, _type) \ VMSTATE_SINGLE_TEST(_field, _state, NULL, _version, _info, _type) +#define VMSTATE_VSTRUCT(_field, _state, _vmsd, _type, _struct_version)\ + VMSTATE_VSTRUCT_TEST(_field, _state, NULL, 0, _vmsd, _type, _struct_version) + +#define VMSTATE_VSTRUCT_V(_field, _state, _version, _vmsd, _type, _struct_version) \ + VMSTATE_VSTRUCT_TEST(_field, _state, NULL, _version, _vmsd, _type, \ + _struct_version) + #define VMSTATE_STRUCT(_field, _state, _version, _vmsd, _type) \ VMSTATE_STRUCT_TEST(_field, _state, NULL, _version, _vmsd, _type) @@ -1000,6 +1043,8 @@ int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd, void *opaque, int version_id); int vmstate_save_state(QEMUFile *f, const VMStateDescription *vmsd, void *opaque, QJSON *vmdesc); +int vmstate_save_state_v(QEMUFile *f, const VMStateDescription *vmsd, + void *opaque, QJSON *vmdesc, int version_id); bool vmstate_save_needed(const VMStateDescription *vmsd, void *opaque); diff --git a/migration/vmstate.c b/migration/vmstate.c index 0b3282c..f0b07f4 100644 --- a/migration/vmstate.c +++ b/migration/vmstate.c @@ -136,6 +136,9 @@ int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd, } else if (field->flags & VMS_STRUCT) { ret = vmstate_load_state(f, field->vmsd, curr_elem, field->vmsd->version_id); + } else if (field->flags & VMS_VSTRUCT) { + ret = vmstate_load_state(f, field->vmsd, curr_elem, + field->struct_version_id); } else { ret = field->info->get(f, curr_elem, size, field); } @@ -209,6 +212,8 @@ static const char *vmfield_get_type_name(VMStateField *field) if (field->flags & VMS_STRUCT) { type = "struct"; + } else if (field->flags & VMS_VSTRUCT) { + type = "vstruct"; } else if (field->info->name) { type = field->info->name; } @@ -309,7 +314,13 @@ bool vmstate_save_needed(const VMStateDescription *vmsd, void *opaque) int vmstate_save_state(QEMUFile *f, const VMStateDescription *vmsd, - void *opaque, QJSON *vmdesc) + void *opaque, QJSON *vmdesc_id) +{ + return vmstate_save_state_v(f, vmsd, opaque, vmdesc_id, vmsd->version_id); +} + +int vmstate_save_state_v(QEMUFile *f, const VMStateDescription *vmsd, + void *opaque, QJSON *vmdesc, int version_id) { int ret = 0; VMStateField *field = vmsd->fields; @@ -327,13 +338,15 @@ int vmstate_save_state(QEMUFile *f, const VMStateDescription *vmsd, if (vmdesc) { json_prop_str(vmdesc, "vmsd_name", vmsd->name); - json_prop_int(vmdesc, "version", vmsd->version_id); + json_prop_int(vmdesc, "version", version_id); json_start_array(vmdesc, "fields"); } while (field->name) { - if (!field->field_exists || - field->field_exists(opaque, vmsd->version_id)) { + if ((field->field_exists && + field->field_exists(opaque, version_id)) || + (!field->field_exists && + field->version_id <= version_id)) { void *first_elem = opaque + field->offset; int i, n_elems = vmstate_n_elems(opaque, field); int size = vmstate_size(opaque, field); @@ -363,6 +376,10 @@ int vmstate_save_state(QEMUFile *f, const VMStateDescription *vmsd, } else if (field->flags & VMS_STRUCT) { ret = vmstate_save_state(f, field->vmsd, curr_elem, vmdesc_loop); + } else if (field->flags & VMS_VSTRUCT) { + ret = vmstate_save_state_v(f, field->vmsd, curr_elem, + vmdesc_loop, + field->struct_version_id); } else { ret = field->info->put(f, curr_elem, size, field, vmdesc_loop);