From 94ed706d53a9018f24c67374c71f358fca2f0413 Mon Sep 17 00:00:00 2001 From: Alexey Kardashevskiy Date: Thu, 2 Oct 2014 19:56:02 +1000 Subject: vmstate: Allow dynamic allocation for VBUFFER during migration 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 Signed-off-by: Juan Quintela --- vmstate.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'vmstate.c') diff --git a/vmstate.c b/vmstate.c index ef2f87bdad..3dde574c0f 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); } } -- cgit v1.2.1