From patchwork Wed Dec 2 11:36:43 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juan Quintela X-Patchwork-Id: 40003 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 AEE21B7BDF for ; Wed, 2 Dec 2009 23:30:42 +1100 (EST) Received: from localhost ([127.0.0.1]:41880 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NFoLu-0004ca-PZ for incoming@patchwork.ozlabs.org; Wed, 02 Dec 2009 07:30:38 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NFnWl-0005x2-J9 for qemu-devel@nongnu.org; Wed, 02 Dec 2009 06:37:47 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NFnWg-0005sq-4A for qemu-devel@nongnu.org; Wed, 02 Dec 2009 06:37:45 -0500 Received: from [199.232.76.173] (port=50864 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NFnWe-0005sZ-Pe for qemu-devel@nongnu.org; Wed, 02 Dec 2009 06:37:40 -0500 Received: from mx1.redhat.com ([209.132.183.28]:42076) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NFnWd-0002CI-2z for qemu-devel@nongnu.org; Wed, 02 Dec 2009 06:37:40 -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 nB2Bbb9d017247 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 2 Dec 2009 06:37:37 -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 nB2BbPre004274; Wed, 2 Dec 2009 06:37:36 -0500 From: Juan Quintela To: qemu-devel@nongnu.org Date: Wed, 2 Dec 2009 12:36:43 +0100 Message-Id: <78813d45a9e1216677b80937bef50ef109c0512a.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 09/12] vmstate: Add support for multiplying size for a constant 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 When the size that we want to transmit is in another field, but in an unit different that bytes Signed-off-by: Juan Quintela --- hw/hw.h | 13 +++++++++++++ savevm.c | 6 ++++++ 2 files changed, 19 insertions(+), 0 deletions(-) diff --git a/hw/hw.h b/hw/hw.h index 41e13cc..5f34991 100644 --- a/hw/hw.h +++ b/hw/hw.h @@ -295,6 +295,7 @@ enum VMStateFlags { 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 */ + VMS_MULTIPLY = 0x200, /* multiply "size" field by field_size */ }; typedef struct { @@ -485,6 +486,18 @@ extern const VMStateInfo vmstate_info_unused_buffer; .offset = vmstate_offset_buffer(_state, _field) + _start, \ } +#define VMSTATE_BUFFER_MULTIPLY(_field, _state, _version, _test, _start, _field_size, _multiply) { \ + .name = (stringify(_field)), \ + .version_id = (_version), \ + .field_exists = (_test), \ + .size_offset = vmstate_offset_value(_state, _field_size, uint32_t),\ + .size = (_multiply), \ + .info = &vmstate_info_buffer, \ + .flags = VMS_VBUFFER|VMS_MULTIPLY, \ + .offset = offsetof(_state, _field), \ + .start = (_start), \ +} + #define VMSTATE_VBUFFER(_field, _state, _version, _test, _start, _field_size) { \ .name = (stringify(_field)), \ .version_id = (_version), \ diff --git a/savevm.c b/savevm.c index 2715f8f..c7da4a6 100644 --- a/savevm.c +++ b/savevm.c @@ -1147,6 +1147,9 @@ int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd, if (field->flags & VMS_VBUFFER) { size = *(int32_t *)(opaque+field->size_offset); + if (field->flags & VMS_MULTIPLY) { + size *= field->size; + } } if (field->flags & VMS_ARRAY) { n_elems = field->num; @@ -1200,6 +1203,9 @@ void vmstate_save_state(QEMUFile *f, const VMStateDescription *vmsd, if (field->flags & VMS_VBUFFER) { size = *(int32_t *)(opaque+field->size_offset); + if (field->flags & VMS_MULTIPLY) { + size *= field->size; + } } if (field->flags & VMS_ARRAY) { n_elems = field->num;