From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53179) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XX34T-0006uI-IH for qemu-devel@nongnu.org; Thu, 25 Sep 2014 03:02:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XX34E-0004MK-J9 for qemu-devel@nongnu.org; Thu, 25 Sep 2014 03:02:33 -0400 Received: from e23smtp03.au.ibm.com ([202.81.31.145]:39934) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XX34E-0004Jv-0P for qemu-devel@nongnu.org; Thu, 25 Sep 2014 03:02:18 -0400 Received: from /spool/local by e23smtp03.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 25 Sep 2014 17:02:09 +1000 From: Alexey Kardashevskiy Date: Thu, 25 Sep 2014 17:02:02 +1000 Message-Id: <1411628523-3498-2-git-send-email-aik@ozlabs.ru> In-Reply-To: <1411628523-3498-1-git-send-email-aik@ozlabs.ru> References: <1411628523-3498-1-git-send-email-aik@ozlabs.ru> Subject: [Qemu-devel] [PATCH 1/2] vmstate: Allow dynamic allocation for VBUFFER during migration List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Alexey Kardashevskiy , Paolo Bonzini , qemu-ppc@nongnu.org, Alexander Graf This extends use of VMS_ALLOC flag from arrays to VBUFFER as well. This defines VMSTATE_VBUFFER_ALLOC_UINT32 which makes use of VMS_ALLOC and uses uint32_t type for a size. Signed-off-by: Alexey Kardashevskiy --- include/migration/vmstate.h | 11 +++++++++++ vmstate.c | 13 ++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h index 9a001bd..e45fc49 100644 --- a/include/migration/vmstate.h +++ b/include/migration/vmstate.h @@ -484,6 +484,17 @@ extern const VMStateInfo vmstate_info_bitmap; .start = (_start), \ } +#define VMSTATE_VBUFFER_ALLOC_UINT32(_field, _state, _version, _test, _start, _field_size) { \ + .name = (stringify(_field)), \ + .version_id = (_version), \ + .field_exists = (_test), \ + .size_offset = vmstate_offset_value(_state, _field_size, uint32_t),\ + .info = &vmstate_info_buffer, \ + .flags = VMS_VBUFFER|VMS_POINTER|VMS_ALLOC, \ + .offset = offsetof(_state, _field), \ + .start = (_start), \ +} + #define VMSTATE_BUFFER_UNSAFE_INFO(_field, _state, _version, _info, _size) { \ .name = (stringify(_field)), \ .version_id = (_version), \ diff --git a/vmstate.c b/vmstate.c index ef2f87b..3dde574 100644 --- a/vmstate.c +++ b/vmstate.c @@ -49,9 +49,16 @@ static void *vmstate_base_addr(void *opaque, VMStateField *field, bool alloc) if (field->flags & VMS_POINTER) { if (alloc && (field->flags & VMS_ALLOC)) { - int n_elems = vmstate_n_elems(opaque, field); - if (n_elems) { - gsize size = n_elems * field->size; + gsize size = 0; + if (field->flags & VMS_VBUFFER) { + size = vmstate_size(opaque, field); + } else { + int n_elems = vmstate_n_elems(opaque, field); + if (n_elems) { + size = n_elems * field->size; + } + } + if (size) { *((void **)base_addr + field->start) = g_malloc(size); } } -- 2.0.0