In memory QEMUFile
v6 cover In memory QEMUFile
From: "Dr. David Alan Gilbert" <[email protected]>
This patch-pair adds the QEMUSizedBuffer based in-memory QEMUFile
written by Stefan Berger and Joel Schopp. I've made some
fixes 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.
(Eric I've kept your reviewed-by from v5 - please confirm you're OK)
Dave
v6:
Build fixes for older compiler/glib reported by [email protected]
removed: typedef QEMUSizedBuffer from qemu-file.h
used g_try_new rather than g_try_malloc_n
v5:
Fixes from Eric's comments; including a memory leak in an error path
v4:
Fix very silly mistake in qsb_grow ENOMEM check
v3:
Mostly addressing comments from Eric and Gonglei
rewrote qsb_grow to always use _try_ for memory allocation
also made it use MAX_CHUNK_SIZE as needed
made QSB_MAX_CHUNK_SIZE 16x rather than 10x CHUNK_SIZE
reworked qsb_get_buffer to always take an allocated buffer
qsb_create:
Cope with 0 length but passed buffer Rework so it can fail on memory allocation failures
qsb_write_at
return -EINVAL for invalid position
qsb_clone
Cope with qsb_write_at failing
Typo: 'of of' in comment
'withing'
Reword qsb_clone 'exact copy'->'deep copy'
Dr. David Alan Gilbert (2):
QEMUSizedBuffer based QEMUFile
Tests: QEMUSizedBuffer/QEMUBuffer
include/migration/qemu-file.h | 26 +++ include/qemu/typedefs.h | 1 + qemu-file.c | 455 ++++++++++++++++++++++++++++++++++++++++++ tests/Makefile | 2 +- tests/test-vmstate.c | 74 +++---- 5 files changed, 521 insertions(+), 37 deletions(-)
Signature · 1 line
1.9.3
PATCH v6 1/2 QEMUSizedBuffer based QEMUFile
From: "Dr. David Alan Gilbert" <[email protected]>
This is based on Stefan and Joel's patch that creates a QEMUFile that goes to a memory buffer; from:
http://lists.gnu.org/archive/html/qemu-devel/2013-03/msg05036.html
Using the QEMUFile interface, this patch adds support functions for operating on in-memory sized buffers that can be written to or read from.
For fixes/tweeks I've done:
--- include/migration/qemu-file.h | 26 +++ include/qemu/typedefs.h | 1 + qemu-file.c | 455 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 482 insertions(+)
include/migration/qemu-file.h +26 -0
@@ -25,6 +25,8 @@#define QEMU_FILE_H 1#include "exec/cpu-common.h" +#include <stdint.h> +/* This function writes a chunk of data to a file at the given position. * The pos argument can be ignored if the file is only being used for * streaming. The handler should try to write all of the data it can.
@@ -94,11 +96,19 @@ typedef struct QEMUFileOps {QEMURamSaveFunc *save_page; } QEMUFileOps; +struct QEMUSizedBuffer { +struct iovec *iov; +size_t n_iov; +size_t size;/* total allocated size in all iov's */ +size_t used;/* number of used bytes */ +}; +QEMUFile *qemu_fopen_ops (void *opaque,const QEMUFileOps *ops);QEMUFile *qemu_fopen (const char *filename,const char *mode);QEMUFile *qemu_fdopen (int fd,const char *mode);QEMUFile *qemu_fopen_socket (int fd,const char *mode);QEMUFile *qemu_popen_cmd (const char *command,const char *mode); +QEMUFile *qemu_bufopen (const char *mode,QEMUSizedBuffer *input);int qemu_get_fd (QEMUFile *f);int qemu_fclose (QEMUFile *f);int64_t qemu_ftell (QEMUFile *f);
@@ -111,6 +121,22 @@ void qemu_put_byte(QEMUFile *f, int v);void qemu_put_buffer_async (QEMUFile *f,const uint8_t *buf,int size);bool qemu_file_mode_is_not_valid (const char *mode); +QEMUSizedBuffer *qsb_create (const uint8_t *buffer,size_t len); +QEMUSizedBuffer *qsb_clone (const QEMUSizedBuffer *); +void qsb_free (QEMUSizedBuffer *); +size_t qsb_set_length (QEMUSizedBuffer *qsb,size_t length); +size_t qsb_get_length (const QEMUSizedBuffer *qsb); +ssize_t qsb_get_buffer (const QEMUSizedBuffer *,off_t start,size_t count, +uint8_t *buf); +ssize_t qsb_write_at (QEMUSizedBuffer *qsb,const uint8_t *buf, +off_t pos,size_t count); + + +/* +* For use on files opened with qemu_bufopen +*/ +const QEMUSizedBuffer *qemu_buf_get (QEMUFile *f); +static inline void qemu_put_ubyte (QEMUFile *f,unsigned int v) {qemu_put_byte (f, (int )v);
include/qemu/typedefs.h +1 -0
@@ -71,6 +71,7 @@ typedef struct SSIBus SSIBus;typedef struct EventNotifier EventNotifier ;typedef struct VirtIODevice VirtIODevice ;typedef struct QEMUSGList QEMUSGList ; +typedef struct QEMUSizedBuffer QEMUSizedBuffer ;typedef struct SHPCDevice SHPCDevice ;typedef struct FWCfgState FWCfgState ;typedef struct PcGuestInfo PcGuestInfo ;
qemu-file.c +455 -0
458 lines not on this page · raw message
Signature · 1 line
1.9.3
PATCH v6 2/2 Tests: QEMUSizedBuffer/QEMUBuffer
In reply to Dr. David Alan Gilbert (git)From: "Dr. David Alan Gilbert" <[email protected]>
Modify some of tests/test-vmstate.c to use the in memory file based on QEMUSizedBuffer to provide basic testing of QEMUSizedBuffer and the associated memory backed QEMUFile type.
Only some of the tests are changed so that the fd backed QEMUFile is still tested.
--- tests/Makefile | 2 +- tests/test-vmstate.c | 74 +++++++++++++++++++++++++++------------------------- 2 files changed, 39 insertions(+), 37 deletions(-)
tests/Makefile +1 -1
@@ -259,7 +259,7 @@ tests/test-qdev-global-props$(EXESUF): tests/test-qdev-global-props.o \ libqemuutil.a libqemustub.a tests/test-vmstate$(EXESUF): tests/test-vmstate.o \ vmstate.o qemu-file.o \ - libqemuutil.a + libqemuutil.a libqemustub.a tests/test-qapi-types.c tests/test-qapi-types.h :\ $(SRC_PATH)/tests/qapi-schema/qapi-schema-test.json $(SRC_PATH)/scripts/qapi-types.py
tests/test-vmstate.c +38 -36
143 lines not on this page · raw message
Signature · 1 line
1.9.3
Quoted 16 lines · Dr. David Alan Gilbert (git)
From: "Dr. David Alan Gilbert" <[email protected]>
This patch-pair adds the QEMUSizedBuffer based in-memory QEMUFile
written by Stefan Berger and Joel Schopp. I've made some
fixes 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.
Quoted 8 lines
(Eric I've kept your reviewed-by from v5 - please confirm you're OK)
Dave
v6:
Build fixes for older compiler/glib reported by [email protected]
removed: typedef QEMUSizedBuffer fromqemu-file.h
usedg_try_newrather thang_try_malloc_n
Yes, my R-b is still okay, after checking that these are indeed the only changes.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Juan Quintela
AppliedQuoted 16 lines · Dr. David Alan Gilbert (git)
From: "Dr. David Alan Gilbert" <[email protected]>
This patch-pair adds the QEMUSizedBuffer based in-memory QEMUFile
written by Stefan Berger and Joel Schopp. I've made some
fixes 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.
Quoted 3 lines
(Eric I've kept your reviewed-by from v5 - please confirm you're OK)
Dave
Applied, thanks.