All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 1/2] QEMUSizedBuffer: only free qsb that qemu_bufopen allocated
@ 2014-12-12  9:53 Yang Hongyang
  2014-12-12  9:53 ` [Qemu-devel] [PATCH 2/2] Tests: QEMUSizedBuffer/QEMUBuffer Yang Hongyang
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Yang Hongyang @ 2014-12-12  9:53 UTC (permalink / raw)
  To: qemu-devel; +Cc: Yang Hongyang, Dr. David Alan Gilbert, Juan Quintela

Only free qsb that qemu_bufopen allocated, and also allow
qemu_bufopen accept qsb as input for write operation. It
will make the API more logical:
1.If you create the QEMUSizedBuffer yourself, you need to
  free it by using qsb_free() but not depends on other API
  like qemu_fclose.
2.allow qemu_bufopen() accept QEMUSizedBuffer as input for
  write operation, otherwise, it will be a little strange
  for this API won't accept the second parameter.

This brings API change, since there are only 3
users of this API currently, this change only impact the
first one which will be fixed in patch 2 of this patchset,
so I think it is safe to do this change.

1     70  tests/test-vmstate.c <<open_mem_file_read>>
            return qemu_bufopen("r", qsb);
2    404  tests/test-vmstate.c <<test_save_noskip>>
            QEMUFile *fsave = qemu_bufopen("w", NULL);
3    424  tests/test-vmstate.c <<test_save_skip>>
            QEMUFile *fsave = qemu_bufopen("w", NULL);

Signed-off-by: Yang Hongyang <yanghy@cn.fujitsu.com>
Cc: Dr. David Alan Gilbert <dgilbert@redhat.com>
Cc: Juan Quintela <quintela@redhat.com>
---
 qemu-file.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/qemu-file.c b/qemu-file.c
index f938e36..52f8d69 100644
--- a/qemu-file.c
+++ b/qemu-file.c
@@ -904,6 +904,7 @@ QEMUSizedBuffer *qsb_clone(const QEMUSizedBuffer *qsb)
 typedef struct QEMUBuffer {
     QEMUSizedBuffer *qsb;
     QEMUFile *file;
+    bool qsb_allocated;
 } QEMUBuffer;
 
 static int buf_get_buffer(void *opaque, uint8_t *buf, int64_t pos, int size)
@@ -933,7 +934,9 @@ static int buf_close(void *opaque)
 {
     QEMUBuffer *s = opaque;
 
-    qsb_free(s->qsb);
+    if (s->qsb_allocated) {
+        qsb_free(s->qsb);
+    }
 
     g_free(s);
 
@@ -972,12 +975,11 @@ QEMUFile *qemu_bufopen(const char *mode, QEMUSizedBuffer *input)
     }
 
     s = g_malloc0(sizeof(QEMUBuffer));
-    if (mode[0] == 'r') {
-        s->qsb = input;
-    }
+    s->qsb = input;
 
     if (s->qsb == NULL) {
         s->qsb = qsb_create(NULL, 0);
+        s->qsb_allocated = true;
     }
     if (!s->qsb) {
         g_free(s);
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 6+ messages in thread
* [Qemu-devel] [PATCH 0/2] In memory QEMUFile
@ 2014-08-06 17:30 Dr. David Alan Gilbert (git)
  2014-08-06 17:30 ` [Qemu-devel] [PATCH 2/2] Tests: QEMUSizedBuffer/QEMUBuffer Dr. David Alan Gilbert (git)
  0 siblings, 1 reply; 6+ messages in thread
From: Dr. David Alan Gilbert (git) @ 2014-08-06 17:30 UTC (permalink / raw)
  To: qemu-devel; +Cc: joel.schopp, stefanb, quintela

From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>

Hi,
  This patch-pair adds the QEMUSizedBuffer based in-memory QEMUFile
written by Stefan Berger and Joel Schopp.  I've made some minor
fixes (and typo cleanups) and modified the existing test-vmstate
to use it for some test cases.

  While there's nothing other than test cases using it yet, I think
it's worth going in by itself, since I'm using it in two separate
patchsets (postcopy and visitor/BER) and Sanidhya uses it in
the periodic vmstate test world.  In addition both microcheckpointing and
COLO have similar but independent implementations (although they both
have some extra-gotcha's so it might not be possible to reuse it), and
there was another implementation of the same thing in the Yabusame Postcopy
world.  Thus it seems best to put in, if only to stop people writing yet
another implementation.

Dr. David Alan Gilbert (2):
  QEMUSizedBuffer based QEMUFile
  Tests: QEMUSizedBuffer/QEMUBuffer

 include/migration/qemu-file.h |  28 +++
 include/qemu/typedefs.h       |   1 +
 qemu-file.c                   | 410 ++++++++++++++++++++++++++++++++++++++++++
 tests/Makefile                |   2 +-
 tests/test-vmstate.c          |  73 ++++----
 5 files changed, 477 insertions(+), 37 deletions(-)

-- 
1.9.3

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2014-12-16 13:37 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-12-12  9:53 [Qemu-devel] [PATCH 1/2] QEMUSizedBuffer: only free qsb that qemu_bufopen allocated Yang Hongyang
2014-12-12  9:53 ` [Qemu-devel] [PATCH 2/2] Tests: QEMUSizedBuffer/QEMUBuffer Yang Hongyang
2014-12-16 13:37   ` Dr. David Alan Gilbert
2014-12-16  2:20 ` [Qemu-devel] [PATCH 1/2] QEMUSizedBuffer: only free qsb that qemu_bufopen allocated Hongyang Yang
2014-12-16 13:34 ` Dr. David Alan Gilbert
  -- strict thread matches above, loose matches on Subject: below --
2014-08-06 17:30 [Qemu-devel] [PATCH 0/2] In memory QEMUFile Dr. David Alan Gilbert (git)
2014-08-06 17:30 ` [Qemu-devel] [PATCH 2/2] Tests: QEMUSizedBuffer/QEMUBuffer Dr. David Alan Gilbert (git)

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.