From patchwork Thu Aug 20 17:42:33 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juan Quintela X-Patchwork-Id: 31763 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 bilbo.ozlabs.org (Postfix) with ESMTPS id E36FEB70C4 for ; Fri, 21 Aug 2009 04:09:18 +1000 (EST) Received: from localhost ([127.0.0.1]:45841 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MeC4Y-00017D-Az for incoming@patchwork.ozlabs.org; Thu, 20 Aug 2009 14:09:14 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MeBhU-0006Oy-12 for qemu-devel@nongnu.org; Thu, 20 Aug 2009 13:45:24 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MeBhO-0006Jn-8I for qemu-devel@nongnu.org; Thu, 20 Aug 2009 13:45:22 -0400 Received: from [199.232.76.173] (port=39154 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MeBhN-0006JZ-CJ for qemu-devel@nongnu.org; Thu, 20 Aug 2009 13:45:17 -0400 Received: from mx1.redhat.com ([209.132.183.28]:32823) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1MeBhM-0006yw-Ns for qemu-devel@nongnu.org; Thu, 20 Aug 2009 13:45:17 -0400 Received: from int-mx04.intmail.prod.int.phx2.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.17]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n7KHjF7u021571 for ; Thu, 20 Aug 2009 13:45:15 -0400 Received: from localhost.localdomain (vpn2-8-130.ams2.redhat.com [10.36.8.130]) by int-mx04.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n7KHis4a012471; Thu, 20 Aug 2009 13:45:13 -0400 From: Juan Quintela To: qemu-devel@nongnu.org Date: Thu, 20 Aug 2009 19:42:33 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.67 on 10.5.11.17 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Subject: [Qemu-devel] [PATCH 15/23] Add VMState support for variable sized arrays 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 This patch add supports for variable sized arrays whose size is another field of the state. Signed-off-by: Juan Quintela --- hw/hw.h | 22 ++++++++++++++++++++++ savevm.c | 4 ++++ 2 files changed, 26 insertions(+), 0 deletions(-) diff --git a/hw/hw.h b/hw/hw.h index e3e9d5b..911ab6f 100644 --- a/hw/hw.h +++ b/hw/hw.h @@ -283,6 +283,7 @@ enum VMStateFlags { VMS_POINTER = 0x002, VMS_ARRAY = 0x004, VMS_STRUCT = 0x008, + VMS_VARRAY = 0x010, /* Array with size in another field */ }; typedef struct { @@ -290,6 +291,7 @@ typedef struct { size_t offset; size_t size; int num; + size_t num_offset; const VMStateInfo *info; enum VMStateFlags flags; const VMStateDescription *vmsd; @@ -320,6 +322,7 @@ extern const VMStateInfo vmstate_info_uint64; extern const VMStateInfo vmstate_info_timer; #define type_check_array(t1,t2,n) ((t1(*)[n])0 - (t2*)0) +#define type_check_pointer(t1,t2) ((t1**)0 - (t2*)0) #define VMSTATE_SINGLE(_field, _state, _version, _info, _type) { \ .name = (stringify(_field)), \ @@ -352,6 +355,18 @@ extern const VMStateInfo vmstate_info_timer; + 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), \ + .num_offset = offsetof(_state, _field_num) \ + + type_check(int32_t,typeof_field(_state, _field_num)), \ + .info = &(_info), \ + .size = sizeof(_type), \ + .flags = VMS_VARRAY|VMS_POINTER, \ + .offset = offsetof(_state, _field) \ + + type_check_pointer(_type,typeof_field(_state, _field)) \ +} + #define VMSTATE_STRUCT(_field, _state, _version, _vmsd, _type) { \ .name = (stringify(_field)), \ .version_id = (_version), \ @@ -374,6 +389,7 @@ extern const VMStateInfo vmstate_info_timer; } /* _f : field name + _f_n : num of elements field_name _n : num of elements _s : struct state name _v : version @@ -436,6 +452,12 @@ extern const VMStateInfo vmstate_info_timer; #define VMSTATE_INT32_ARRAY(_f, _s, _n) \ VMSTATE_INT32_ARRAY_V(_f, _s, _n, 0) +#define VMSTATE_INT32_VARRAY_V(_f, _s, _f_n, _v) \ + VMSTATE_VARRAY(_f, _s, _f_n, _v, vmstate_info_int32, int32_t) + +#define VMSTATE_INT32_VARRAY(_f, _s, _f_n) \ + VMSTATE_INT32_VARRAY_V(_f, _s, _f_n, 0) + #define VMSTATE_END_OF_LIST() \ {} diff --git a/savevm.c b/savevm.c index e443f00..721bbf4 100644 --- a/savevm.c +++ b/savevm.c @@ -968,6 +968,8 @@ int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd, 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; @@ -1002,6 +1004,8 @@ void vmstate_save_state(QEMUFile *f, const VMStateDescription *vmsd, 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;