From patchwork Thu Aug 20 17:42:29 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juan Quintela X-Patchwork-Id: 31759 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 20916B7B63 for ; Fri, 21 Aug 2009 04:02:31 +1000 (EST) Received: from localhost ([127.0.0.1]:54574 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MeBxz-0005qz-MQ for incoming@patchwork.ozlabs.org; Thu, 20 Aug 2009 14:02:27 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MeBhN-0006JR-8T for qemu-devel@nongnu.org; Thu, 20 Aug 2009 13:45:17 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MeBhI-0006FS-R9 for qemu-devel@nongnu.org; Thu, 20 Aug 2009 13:45:16 -0400 Received: from [199.232.76.173] (port=39150 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MeBhH-0006FA-UN for qemu-devel@nongnu.org; Thu, 20 Aug 2009 13:45:12 -0400 Received: from mx1.redhat.com ([209.132.183.28]:64176) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1MeBhH-0006xy-Ef for qemu-devel@nongnu.org; Thu, 20 Aug 2009 13:45:11 -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 n7KHjA5L006249 for ; Thu, 20 Aug 2009 13:45:10 -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 n7KHis4W012471; Thu, 20 Aug 2009 13:45:08 -0400 From: Juan Quintela To: qemu-devel@nongnu.org Date: Thu, 20 Aug 2009 19:42:29 +0200 Message-Id: <4174a120f0e6d65670dd78cbb25b6bae67d18743.1250788880.git.quintela@redhat.com> 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 11/23] Add VMState support for structs 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 adds support for saving one VMStateDescription from other VMStateDescription. Signed-off-by: Juan Quintela --- hw/hw.h | 12 ++++++++++++ savevm.c | 15 +++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/hw/hw.h b/hw/hw.h index ebb9c22..4f63f73 100644 --- a/hw/hw.h +++ b/hw/hw.h @@ -282,6 +282,7 @@ enum VMStateFlags { VMS_SINGLE = 0x001, VMS_POINTER = 0x002, VMS_ARRAY = 0x004, + VMS_STRUCT = 0x008, }; typedef struct { @@ -291,6 +292,7 @@ typedef struct { int num; const VMStateInfo *info; enum VMStateFlags flags; + const VMStateDescription *vmsd; int version_id; } VMStateField; @@ -348,6 +350,16 @@ extern const VMStateInfo vmstate_info_timer; + type_check_array(_type,typeof_field(_state, _field),_num) \ } +#define VMSTATE_STRUCT(_field, _state, _version, _vmsd, _type) { \ + .name = (stringify(_field)), \ + .version_id = (_version), \ + .vmsd = &(_vmsd), \ + .size = sizeof(_type), \ + .flags = VMS_STRUCT, \ + .offset = offsetof(_state, _field) \ + + type_check(_type,typeof_field(_state, _field)) \ +} + /* _f : field name _n : num of elements _s : struct state name diff --git a/savevm.c b/savevm.c index 040748e..8320d37 100644 --- a/savevm.c +++ b/savevm.c @@ -954,7 +954,13 @@ int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd, } for (i = 0; i < n_elems; i++) { void *addr = base_addr + field->size * i; - ret = field->info->get(f, addr, field->size); + + if (field->flags & VMS_STRUCT) { + ret = vmstate_load_state(f, field->vmsd, addr, version_id); + } else { + ret = field->info->get(f, addr, field->size); + + } if (ret < 0) { return ret; } @@ -982,7 +988,12 @@ void vmstate_save_state(QEMUFile *f, const VMStateDescription *vmsd, } for (i = 0; i < n_elems; i++) { const void *addr = base_addr + field->size * i; - 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++; }