From patchwork Wed Dec 2 11:36:38 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juan Quintela X-Patchwork-Id: 39997 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 C1D15B7BE3 for ; Wed, 2 Dec 2009 23:13:56 +1100 (EST) Received: from localhost ([127.0.0.1]:36056 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NFo5h-0000XV-2y for incoming@patchwork.ozlabs.org; Wed, 02 Dec 2009 07:13:53 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NFnWd-0005s8-2B for qemu-devel@nongnu.org; Wed, 02 Dec 2009 06:37:39 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NFnWX-0005pM-AK for qemu-devel@nongnu.org; Wed, 02 Dec 2009 06:37:37 -0500 Received: from [199.232.76.173] (port=50857 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NFnWX-0005pH-1R for qemu-devel@nongnu.org; Wed, 02 Dec 2009 06:37:33 -0500 Received: from mx1.redhat.com ([209.132.183.28]:59199) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NFnWW-0002BW-FK for qemu-devel@nongnu.org; Wed, 02 Dec 2009 06:37:32 -0500 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id nB2BbVfF013233 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 2 Dec 2009 06:37:31 -0500 Received: from localhost.localdomain (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id nB2BbPrZ004274; Wed, 2 Dec 2009 06:37:31 -0500 From: Juan Quintela To: qemu-devel@nongnu.org Date: Wed, 2 Dec 2009 12:36:38 +0100 Message-Id: <8df3de4a1a31962b2f87694a29a60139d5d1c130.1259753146.git.quintela@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Subject: [Qemu-devel] [PATCH 04/12] vmstate: Add support for VBUFFERS 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 Support for buffer that are pointed by a pointer (i.e. not embedded) where the size that we want to use is a field in the state. We also need a new place to store where to start in the middle of the buffer, as now it is a pointer, not the offset of the 1st field. Signed-off-by: Juan Quintela --- hw/hw.h | 20 ++++++++++++++++++++ savevm.c | 20 ++++++++++++++------ 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/hw/hw.h b/hw/hw.h index c3c0c9f..47fb12b 100644 --- a/hw/hw.h +++ b/hw/hw.h @@ -294,14 +294,17 @@ enum VMStateFlags { VMS_BUFFER = 0x020, /* static sized buffer */ VMS_ARRAY_OF_POINTER = 0x040, VMS_VARRAY_UINT16 = 0x080, /* Array with size in uint16_t field */ + VMS_VBUFFER = 0x100, /* Buffer with size in int32_t field */ }; typedef struct { const char *name; size_t offset; size_t size; + size_t start; int num; size_t num_offset; + size_t size_offset; const VMStateInfo *info; enum VMStateFlags flags; const VMStateDescription *vmsd; @@ -490,6 +493,17 @@ extern const VMStateInfo vmstate_info_unused_buffer; .offset = vmstate_offset_buffer(_state, _field) + _start, \ } +#define VMSTATE_VBUFFER(_field, _state, _version, _test, _start, _field_size) { \ + .name = (stringify(_field)), \ + .version_id = (_version), \ + .field_exists = (_test), \ + .size_offset = vmstate_offset_value(_state, _field_size, int32_t),\ + .info = &vmstate_info_buffer, \ + .flags = VMS_VBUFFER|VMS_POINTER, \ + .offset = offsetof(_state, _field), \ + .start = (_start), \ +} + #define VMSTATE_BUFFER_UNSAFE_INFO(_field, _state, _version, _info, _size) { \ .name = (stringify(_field)), \ .version_id = (_version), \ @@ -683,6 +697,12 @@ extern const VMStateDescription vmstate_i2c_slave; #define VMSTATE_BUFFER_START_MIDDLE(_f, _s, _start) \ VMSTATE_STATIC_BUFFER(_f, _s, 0, NULL, _start, sizeof(typeof_field(_s, _f))) +#define VMSTATE_PARTIAL_VBUFFER(_f, _s, _size) \ + VMSTATE_VBUFFER(_f, _s, 0, NULL, 0, _size) + +#define VMSTATE_SUB_VBUFFER(_f, _s, _start, _size) \ + VMSTATE_VBUFFER(_f, _s, 0, NULL, _start, _size) + #define VMSTATE_BUFFER_TEST(_f, _s, _test) \ VMSTATE_STATIC_BUFFER(_f, _s, 0, _test, 0, sizeof(typeof_field(_s, _f))) diff --git a/savevm.c b/savevm.c index 8fac502..2715f8f 100644 --- a/savevm.c +++ b/savevm.c @@ -1143,7 +1143,11 @@ int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd, field->version_id <= version_id)) { void *base_addr = opaque + field->offset; int ret, i, n_elems = 1; + int size = field->size; + if (field->flags & VMS_VBUFFER) { + size = *(int32_t *)(opaque+field->size_offset); + } if (field->flags & VMS_ARRAY) { n_elems = field->num; } else if (field->flags & VMS_VARRAY_INT32) { @@ -1152,10 +1156,10 @@ int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd, n_elems = *(uint16_t *)(opaque+field->num_offset); } if (field->flags & VMS_POINTER) { - base_addr = *(void **)base_addr; + base_addr = *(void **)base_addr + field->start; } for (i = 0; i < n_elems; i++) { - void *addr = base_addr + field->size * i; + void *addr = base_addr + size * i; if (field->flags & VMS_ARRAY_OF_POINTER) { addr = *(void **)addr; @@ -1163,7 +1167,7 @@ int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd, if (field->flags & VMS_STRUCT) { ret = vmstate_load_state(f, field->vmsd, addr, field->vmsd->version_id); } else { - ret = field->info->get(f, addr, field->size); + ret = field->info->get(f, addr, size); } if (ret < 0) { @@ -1192,7 +1196,11 @@ void vmstate_save_state(QEMUFile *f, const VMStateDescription *vmsd, field->field_exists(opaque, vmsd->version_id)) { void *base_addr = opaque + field->offset; int i, n_elems = 1; + int size = field->size; + if (field->flags & VMS_VBUFFER) { + size = *(int32_t *)(opaque+field->size_offset); + } if (field->flags & VMS_ARRAY) { n_elems = field->num; } else if (field->flags & VMS_VARRAY_INT32) { @@ -1201,10 +1209,10 @@ void vmstate_save_state(QEMUFile *f, const VMStateDescription *vmsd, n_elems = *(uint16_t *)(opaque+field->num_offset); } if (field->flags & VMS_POINTER) { - base_addr = *(void **)base_addr; + base_addr = *(void **)base_addr + field->start; } for (i = 0; i < n_elems; i++) { - void *addr = base_addr + field->size * i; + void *addr = base_addr + size * i; if (field->flags & VMS_ARRAY_OF_POINTER) { addr = *(void **)addr; @@ -1212,7 +1220,7 @@ void vmstate_save_state(QEMUFile *f, const VMStateDescription *vmsd, if (field->flags & VMS_STRUCT) { vmstate_save_state(f, field->vmsd, addr); } else { - field->info->put(f, addr, field->size); + field->info->put(f, addr, size); } } }