From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53387) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aIbsu-0004JB-2u for qemu-devel@nongnu.org; Mon, 11 Jan 2016 07:47:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aIbss-0008CZ-S0 for qemu-devel@nongnu.org; Mon, 11 Jan 2016 07:47:44 -0500 Received: from mnementh.archaic.org.uk ([2001:8b0:1d0::1]:59281) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aIbss-0008BK-KM for qemu-devel@nongnu.org; Mon, 11 Jan 2016 07:47:42 -0500 From: Peter Maydell Date: Mon, 11 Jan 2016 12:40:22 +0000 Message-Id: <1452516028-25218-3-git-send-email-peter.maydell@linaro.org> In-Reply-To: <1452516028-25218-1-git-send-email-peter.maydell@linaro.org> References: <1452516028-25218-1-git-send-email-peter.maydell@linaro.org> Subject: [Qemu-devel] [PATCH v2 2/8] vmstate: Introduce VMSTATE_VARRAY_MULTPLY List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Juan Quintela , patches@linaro.org, Mark Cave-Ayland , Blue Swirl , Amit Shah , Paolo Bonzini From: Juan Quintela This allows to send a partial array where the size is another structure field multiplied by a constant. Signed-off-by: Juan Quintela [PMM: updated to current master] Signed-off-by: Peter Maydell --- include/migration/vmstate.h | 11 +++++++++++ migration/vmstate.c | 4 ++++ 2 files changed, 15 insertions(+) diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h index a389bdc..4e8495d 100644 --- a/include/migration/vmstate.h +++ b/include/migration/vmstate.h @@ -102,6 +102,7 @@ enum VMStateFlags { VMS_VARRAY_UINT32 = 0x800, /* Array with size in uint32_t field*/ VMS_MUST_EXIST = 0x1000, /* Field must exist in input */ VMS_ALLOC = 0x2000, /* Alloc a buffer on the destination */ + VMS_MULTIPLY_ELEMENTS = 0x4000, /* multiply varray size by field->num */ }; typedef struct { @@ -246,6 +247,16 @@ extern const VMStateInfo vmstate_info_bitmap; .offset = vmstate_offset_2darray(_state, _field, _type, _n1, _n2), \ } +#define VMSTATE_VARRAY_MULTIPLY(_field, _state, _field_num, _multiply, _info, _type) { \ + .name = (stringify(_field)), \ + .num_offset = vmstate_offset_value(_state, _field_num, uint32_t),\ + .num = (_multiply), \ + .info = &(_info), \ + .size = sizeof(_type), \ + .flags = VMS_VARRAY_UINT32|VMS_MULTIPLY_ELEMENTS, \ + .offset = offsetof(_state, _field), \ +} + #define VMSTATE_ARRAY_TEST(_field, _state, _num, _test, _info, _type) {\ .name = (stringify(_field)), \ .field_exists = (_test), \ diff --git a/migration/vmstate.c b/migration/vmstate.c index f70fe59..a7ad7f2 100644 --- a/migration/vmstate.c +++ b/migration/vmstate.c @@ -28,6 +28,10 @@ static int vmstate_n_elems(void *opaque, VMStateField *field) n_elems = *(uint8_t *)(opaque+field->num_offset); } + if (field->flags & VMS_MULTIPLY_ELEMENTS) { + n_elems *= field->num; + } + return n_elems; } -- 1.9.1