From patchwork Tue Sep 29 20:49:07 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juan Quintela X-Patchwork-Id: 34499 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 72463B7BB8 for ; Wed, 30 Sep 2009 08:20:24 +1000 (EST) Received: from localhost ([127.0.0.1]:39311 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Msl3V-0002Og-Fg for incoming@patchwork.ozlabs.org; Tue, 29 Sep 2009 18:20:21 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MsjeR-0005o5-Gc for qemu-devel@nongnu.org; Tue, 29 Sep 2009 16:50:23 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MsjeQ-0005nE-MJ for qemu-devel@nongnu.org; Tue, 29 Sep 2009 16:50:23 -0400 Received: from [199.232.76.173] (port=55269 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MsjeQ-0005n5-Dh for qemu-devel@nongnu.org; Tue, 29 Sep 2009 16:50:22 -0400 Received: from mx1.redhat.com ([209.132.183.28]:31586) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MsjeP-0002g5-Lr for qemu-devel@nongnu.org; Tue, 29 Sep 2009 16:50:22 -0400 Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n8TKoKCC026776 for ; Tue, 29 Sep 2009 16:50:20 -0400 Received: from localhost.localdomain (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n8TKnHYN006885; Tue, 29 Sep 2009 16:50:19 -0400 From: Juan Quintela To: qemu-devel@nongnu.org Date: Tue, 29 Sep 2009 22:49:07 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.67 on 10.5.11.16 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Subject: [Qemu-devel] [PATCH 48/49] vmstate: Add suppot for field_exist() test X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Juan Quintela --- hw/hw.h | 26 ++++++++++++++++++++++++++ savevm.c | 40 +++++++++++++++++++++++----------------- 2 files changed, 49 insertions(+), 17 deletions(-) diff --git a/hw/hw.h b/hw/hw.h index cabf633..8c223f8 100644 --- a/hw/hw.h +++ b/hw/hw.h @@ -10,6 +10,7 @@ #include "cpu-common.h" #endif +#include #include "ioport.h" #include "irq.h" @@ -299,6 +300,7 @@ typedef struct { enum VMStateFlags flags; const VMStateDescription *vmsd; int version_id; + bool (*field_exists)(void *opaque, int version_id); } VMStateField; struct VMStateDescription { @@ -345,6 +347,16 @@ extern const VMStateInfo vmstate_info_buffer; + type_check(_type,typeof_field(_state, _field)) \ } +#define VMSTATE_SINGLE_TEST(_field, _state, _test, _info, _type) { \ + .name = (stringify(_field)), \ + .field_exists = (_test), \ + .size = sizeof(_type), \ + .info = &(_info), \ + .flags = VMS_SINGLE, \ + .offset = offsetof(_state, _field) \ + + type_check(_type,typeof_field(_state, _field)) \ +} + #define VMSTATE_POINTER(_field, _state, _version, _info, _type) { \ .name = (stringify(_field)), \ .version_id = (_version), \ @@ -366,6 +378,17 @@ extern const VMStateInfo vmstate_info_buffer; + type_check_array(_type,typeof_field(_state, _field),_num) \ } +#define VMSTATE_ARRAY_TEST(_field, _state, _num, _test, _info, _type) {\ + .name = (stringify(_field)), \ + .field_exists = (_test), \ + .num = (_num), \ + .info = &(_info), \ + .size = sizeof(_type), \ + .flags = VMS_ARRAY, \ + .offset = offsetof(_state, _field) \ + + type_check_array(_type,typeof_field(_state, _field),_num) \ +} + #define VMSTATE_VARRAY(_field, _state, _field_num, _version, _info, _type) {\ .name = (stringify(_field)), \ .version_id = (_version), \ @@ -524,6 +547,9 @@ extern const VMStateDescription vmstate_i2c_slave; #define VMSTATE_INT32_LE(_f, _s) \ VMSTATE_SINGLE(_f, _s, 0, vmstate_info_int32_le, int32_t) +#define VMSTATE_UINT32_TEST(_f, _s, _t) \ + VMSTATE_SINGLE_TEST(_f, _s, _t, vmstate_info_uint32, uint32_t) + #define VMSTATE_TIMER_V(_f, _s, _v) \ VMSTATE_POINTER(_f, _s, _v, vmstate_info_timer, QEMUTimer *) diff --git a/savevm.c b/savevm.c index 11b331b..7a363b6 100644 --- a/savevm.c +++ b/savevm.c @@ -1055,7 +1055,10 @@ int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd, return ret; } while(field->name) { - if (field->version_id <= version_id) { + if ((field->field_exists && + field->field_exists(opaque, version_id)) || + (!field->field_exists && + field->version_id <= version_id)) { void *base_addr = opaque + field->offset; int ret, i, n_elems = 1; @@ -1101,24 +1104,27 @@ void vmstate_save_state(QEMUFile *f, const VMStateDescription *vmsd, vmsd->pre_save(opaque); } while(field->name) { - void *base_addr = opaque + field->offset; - int i, n_elems = 1; + if (!field->field_exists || + field->field_exists(opaque, vmsd->version_id)) { + void *base_addr = opaque + field->offset; + int i, n_elems = 1; - if (field->flags & VMS_ARRAY) { - n_elems = field->num; - } else if (field->flags & VMS_VARRAY) { - n_elems = *(size_t *)(opaque+field->num_offset); - } - if (field->flags & VMS_POINTER) { - base_addr = *(void **)base_addr; - } - for (i = 0; i < n_elems; i++) { - void *addr = base_addr + field->size * i; + if (field->flags & VMS_ARRAY) { + n_elems = field->num; + } else if (field->flags & VMS_VARRAY) { + n_elems = *(size_t *)(opaque+field->num_offset); + } + if (field->flags & VMS_POINTER) { + base_addr = *(void **)base_addr; + } + for (i = 0; i < n_elems; i++) { + void *addr = base_addr + field->size * i; - if (field->flags & VMS_STRUCT) { - vmstate_save_state(f, field->vmsd, addr); - } else { - field->info->put(f, addr, field->size); + if (field->flags & VMS_STRUCT) { + vmstate_save_state(f, field->vmsd, addr); + } else { + field->info->put(f, addr, field->size); + } } } field++;