qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Juan Quintela <quintela@redhat.com>
To: qemu-devel@nongnu.org
Cc: Alexey Kardashevskiy <aik@ozlabs.ru>
Subject: [Qemu-devel] [PULL 04/10] vmstate: Allow dynamic allocation for VBUFFER during migration
Date: Wed, 15 Oct 2014 10:24:58 +0200	[thread overview]
Message-ID: <1413361504-26396-5-git-send-email-quintela@redhat.com> (raw)
In-Reply-To: <1413361504-26396-1-git-send-email-quintela@redhat.com>

From: Alexey Kardashevskiy <aik@ozlabs.ru>

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 <aik@ozlabs.ru>
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 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.1.0

  parent reply	other threads:[~2014-10-15  8:25 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-15  8:24 [Qemu-devel] [PULL 00/10] Migration pull request Juan Quintela
2014-10-15  8:24 ` [Qemu-devel] [PULL 01/10] QEMUSizedBuffer based QEMUFile Juan Quintela
2014-10-15  8:24 ` [Qemu-devel] [PULL 02/10] Tests: QEMUSizedBuffer/QEMUBuffer Juan Quintela
2014-10-15  8:24 ` [Qemu-devel] [PULL 03/10] block/migration: Disable cache invalidate for incoming migration Juan Quintela
2014-10-15  8:24 ` Juan Quintela [this message]
2014-10-15  8:24 ` [Qemu-devel] [PULL 05/10] qemu-file: Add copyright header to qemu-file.c Juan Quintela
2014-10-15  8:25 ` [Qemu-devel] [PULL 06/10] qemu-file: Make qemu_file_is_writable() non-static Juan Quintela
2014-10-15  8:25 ` [Qemu-devel] [PULL 07/10] qemu-file: Use qemu_file_is_writable() on stdio_fclose() Juan Quintela
2014-10-15  8:25 ` [Qemu-devel] [PULL 08/10] qemu-file: Move unix and socket implementations to qemu-file-unix.c Juan Quintela
2014-10-15  8:25 ` [Qemu-devel] [PULL 09/10] qemu-file: Move stdio implementation to qemu-file-stdio.c Juan Quintela
2014-10-15  8:25 ` [Qemu-devel] [PULL 10/10] migration: catch unknown flag combinations in ram_load Juan Quintela
2014-10-15 12:37 ` [Qemu-devel] [PULL 00/10] Migration pull request Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1413361504-26396-5-git-send-email-quintela@redhat.com \
    --to=quintela@redhat.com \
    --cc=aik@ozlabs.ru \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).