[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v2 28/41] buffered_file: add qemu_file to read/write
From: |
Isaku Yamahata |
Subject: |
[Qemu-devel] [PATCH v2 28/41] buffered_file: add qemu_file to read/write to buffer in memory |
Date: |
Mon, 4 Jun 2012 18:57:30 +0900 |
This is used by postcopy live migration.
Signed-off-by: Isaku Yamahata <address@hidden>
---
buffered_file.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
buffered_file.h | 10 ++++++++++
2 files changed, 60 insertions(+), 0 deletions(-)
diff --git a/buffered_file.c b/buffered_file.c
index 5198923..4f0c98e 100644
--- a/buffered_file.c
+++ b/buffered_file.c
@@ -106,6 +106,56 @@ static void buffer_flush(QEMUBuffer *buf, QEMUFile *file,
/***************************************************************************
+ * read/write to buffer on memory
+ */
+
+static int buf_close(void *opaque)
+{
+ QEMUFileBuf *s = opaque;
+ buffer_destroy(&s->buf);
+ g_free(s);
+ return 0;
+}
+
+static int buf_put_buffer(void *opaque,
+ const uint8_t *buf, int64_t pos, int size)
+{
+ QEMUFileBuf *s = opaque;
+ buffer_append(&s->buf, buf, size);
+ return size;
+}
+
+QEMUFileBuf *qemu_fopen_buf_write(void)
+{
+ QEMUFileBuf *s = g_malloc0(sizeof(*s));
+
+ s->file = qemu_fopen_ops(s, buf_put_buffer, NULL, buf_close,
+ NULL, NULL, NULL);
+ return s;
+}
+
+static int buf_get_buffer(void *opaque, uint8_t *buf, int64_t pos, int size)
+{
+ QEMUFileBuf *s = opaque;
+ ssize_t len = MIN(size, s->buf.buffer_capacity - s->buf.buffer_size);
+ memcpy(buf, s->buf.buffer + s->buf.buffer_size, len);
+ s->buf.buffer_size += len;
+ return len;
+}
+
+/* This get the ownership of buf. */
+QEMUFile *qemu_fopen_buf_read(uint8_t *buf, size_t size)
+{
+ QEMUFileBuf *s = g_malloc0(sizeof(*s));
+ s->buf.buffer = buf;
+ s->buf.buffer_size = 0; /* this is used as index to read */
+ s->buf.buffer_capacity = size;
+ s->file = qemu_fopen_ops(s, NULL, buf_get_buffer, buf_close,
+ NULL, NULL, NULL);
+ return s->file;
+}
+
+/***************************************************************************
* Nonblocking write only file
*/
static ssize_t nonblock_flush_buffer_putbuf(void *opaque,
diff --git a/buffered_file.h b/buffered_file.h
index 2712e01..9e28bef 100644
--- a/buffered_file.h
+++ b/buffered_file.h
@@ -24,6 +24,16 @@ struct QEMUBuffer {
};
typedef struct QEMUBuffer QEMUBuffer;
+struct QEMUFileBuf {
+ QEMUFile *file;
+ QEMUBuffer buf;
+};
+typedef struct QEMUFileBuf QEMUFileBuf;
+
+QEMUFileBuf *qemu_fopen_buf_write(void);
+/* This get the ownership of buf. */
+QEMUFile *qemu_fopen_buf_read(uint8_t *buf, size_t size);
+
struct QEMUFileNonblock {
int fd;
QEMUFile *file;
--
1.7.1.1
- [Qemu-devel] [PATCH v2 15/41] savevm: export qemu_peek_buffer, qemu_peek_byte, qemu_file_skip, (continued)
- [Qemu-devel] [PATCH v2 15/41] savevm: export qemu_peek_buffer, qemu_peek_byte, qemu_file_skip, Isaku Yamahata, 2012/06/04
- [Qemu-devel] [PATCH v2 25/41] migration: factor out parameters into MigrationParams, Isaku Yamahata, 2012/06/04
- [Qemu-devel] [PATCH v2 30/41] update-linux-headers.sh: teach umem.h to update-linux-headers.sh, Isaku Yamahata, 2012/06/04
- [Qemu-devel] [PATCH v2 38/41] postcopy/outgoing: add forward, backward option to specify the size of prefault, Isaku Yamahata, 2012/06/04
- [Qemu-devel] [PATCH v2 10/41] arch_init: simplify a bit by ram_find_block(), Isaku Yamahata, 2012/06/04
- [Qemu-devel] [PATCH v2 34/41] postcopy outgoing: add -p and -n option to migrate command, Isaku Yamahata, 2012/06/04
- [Qemu-devel] [PATCH v2 39/41] postcopy/outgoing: implement prefault, Isaku Yamahata, 2012/06/04
- [Qemu-devel] [PATCH v2 26/41] buffered_file: factor out buffer management logic, Isaku Yamahata, 2012/06/04
- [Qemu-devel] [PATCH v2 14/41] exec.c: export last_ram_offset(), Isaku Yamahata, 2012/06/04
- [Qemu-devel] [PATCH v2 08/41] arch_init/ram_load: refactor ram_load, Isaku Yamahata, 2012/06/04
- [Qemu-devel] [PATCH v2 28/41] buffered_file: add qemu_file to read/write to buffer in memory,
Isaku Yamahata <=
- [Qemu-devel] [PATCH v2 33/41] postcopy: introduce -postcopy and -postcopy-flags option, Isaku Yamahata, 2012/06/04
- [Qemu-devel] [PATCH v2 12/41] arch_init: factor out setting last_block, last_offset, Isaku Yamahata, 2012/06/04
- [Qemu-devel] [PATCH v2 36/41] postcopy: implement incoming part of postcopy live migration, Isaku Yamahata, 2012/06/04
- [Qemu-devel] [PATCH v2 41/41] migration/postcopy: add movebg mode, Isaku Yamahata, 2012/06/04
- [Qemu-devel] [PATCH v2 40/41] migrate: add -m (movebg) option to migrate command, Isaku Yamahata, 2012/06/04
- [Qemu-devel] [PATCH v2 37/41] postcopy: implement outgoing part of postcopy live migration, Isaku Yamahata, 2012/06/04