[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 02/46] Move QEMUFile structure to qemu-file.h
From: |
Dr. David Alan Gilbert (git) |
Subject: |
[Qemu-devel] [PATCH 02/46] Move QEMUFile structure to qemu-file.h |
Date: |
Fri, 4 Jul 2014 18:41:13 +0100 |
From: "Dr. David Alan Gilbert" <address@hidden>
This is mostly as an easy way to get to the MigrationIncomingState
that I'm hanging off the file.
Signed-off-by: Dr. David Alan Gilbert <address@hidden
---
include/migration/qemu-file.h | 22 ++++++++++++++++++++++
qemu-file.c | 40 +++++++++-------------------------------
2 files changed, 31 insertions(+), 31 deletions(-)
diff --git a/include/migration/qemu-file.h b/include/migration/qemu-file.h
index c90f529..6e797bf 100644
--- a/include/migration/qemu-file.h
+++ b/include/migration/qemu-file.h
@@ -82,6 +82,9 @@ typedef size_t (QEMURamSaveFunc)(QEMUFile *f, void *opaque,
size_t size,
int *bytes_sent);
+#define QEMUFILE_IO_BUF_SIZE 32768
+#define QEMUFILE_MAX_IOV_SIZE MIN(IOV_MAX, 64)
+
typedef struct QEMUFileOps {
QEMUFilePutBufferFunc *put_buffer;
QEMUFileGetBufferFunc *get_buffer;
@@ -94,6 +97,25 @@ typedef struct QEMUFileOps {
QEMURamSaveFunc *save_page;
} QEMUFileOps;
+struct QEMUFile {
+ const QEMUFileOps *ops;
+ void *opaque;
+
+ int64_t bytes_xfer;
+ int64_t xfer_limit;
+
+ int64_t pos; /* start of buffer when writing, end of buffer
+ when reading */
+ int buf_index;
+ int buf_size; /* 0 when writing */
+ uint8_t buf[QEMUFILE_IO_BUF_SIZE];
+
+ struct iovec iov[QEMUFILE_MAX_IOV_SIZE];
+ unsigned int iovcnt;
+
+ int last_error;
+};
+
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);
diff --git a/qemu-file.c b/qemu-file.c
index a8e3912..b4f0c73 100644
--- a/qemu-file.c
+++ b/qemu-file.c
@@ -6,28 +6,6 @@
#include "migration/qemu-file.h"
#include "trace.h"
-#define IO_BUF_SIZE 32768
-#define MAX_IOV_SIZE MIN(IOV_MAX, 64)
-
-struct QEMUFile {
- const QEMUFileOps *ops;
- void *opaque;
-
- int64_t bytes_xfer;
- int64_t xfer_limit;
-
- int64_t pos; /* start of buffer when writing, end of buffer
- when reading */
- int buf_index;
- int buf_size; /* 0 when writing */
- uint8_t buf[IO_BUF_SIZE];
-
- struct iovec iov[MAX_IOV_SIZE];
- unsigned int iovcnt;
-
- int last_error;
-};
-
typedef struct QEMUFileStdio {
FILE *stdio_file;
QEMUFile *file;
@@ -553,7 +531,7 @@ static ssize_t qemu_fill_buffer(QEMUFile *f)
f->buf_size = pending;
len = f->ops->get_buffer(f->opaque, f->buf + pending, f->pos,
- IO_BUF_SIZE - pending);
+ QEMUFILE_IO_BUF_SIZE - pending);
if (len > 0) {
f->buf_size += len;
f->pos += len;
@@ -621,7 +599,7 @@ static void add_to_iovec(QEMUFile *f, const uint8_t *buf,
int size)
f->iov[f->iovcnt++].iov_len = size;
}
- if (f->iovcnt >= MAX_IOV_SIZE) {
+ if (f->iovcnt >= QEMUFILE_MAX_IOV_SIZE) {
qemu_fflush(f);
}
}
@@ -650,7 +628,7 @@ void qemu_put_buffer(QEMUFile *f, const uint8_t *buf, int
size)
}
while (size > 0) {
- l = IO_BUF_SIZE - f->buf_index;
+ l = QEMUFILE_IO_BUF_SIZE - f->buf_index;
if (l > size) {
l = size;
}
@@ -660,7 +638,7 @@ void qemu_put_buffer(QEMUFile *f, const uint8_t *buf, int
size)
add_to_iovec(f, f->buf + f->buf_index, l);
}
f->buf_index += l;
- if (f->buf_index == IO_BUF_SIZE) {
+ if (f->buf_index == QEMUFILE_IO_BUF_SIZE) {
qemu_fflush(f);
}
if (qemu_file_get_error(f)) {
@@ -683,7 +661,7 @@ void qemu_put_byte(QEMUFile *f, int v)
add_to_iovec(f, f->buf + f->buf_index, 1);
}
f->buf_index++;
- if (f->buf_index == IO_BUF_SIZE) {
+ if (f->buf_index == QEMUFILE_IO_BUF_SIZE) {
qemu_fflush(f);
}
}
@@ -709,8 +687,8 @@ int qemu_peek_buffer(QEMUFile *f, uint8_t *buf, int size,
size_t offset)
int index;
assert(!qemu_file_is_writable(f));
- assert(offset < IO_BUF_SIZE);
- assert(size <= IO_BUF_SIZE - offset);
+ assert(offset < QEMUFILE_IO_BUF_SIZE);
+ assert(size <= QEMUFILE_IO_BUF_SIZE - offset);
/* The 1st byte to read from */
index = f->buf_index + offset;
@@ -759,7 +737,7 @@ int qemu_get_buffer(QEMUFile *f, uint8_t *buf, int size)
while (pending > 0) {
int res;
- res = qemu_peek_buffer(f, buf, MIN(pending, IO_BUF_SIZE), 0);
+ res = qemu_peek_buffer(f, buf, MIN(pending, QEMUFILE_IO_BUF_SIZE), 0);
if (res == 0) {
return done;
}
@@ -780,7 +758,7 @@ int qemu_peek_byte(QEMUFile *f, int offset)
int index = f->buf_index + offset;
assert(!qemu_file_is_writable(f));
- assert(offset < IO_BUF_SIZE);
+ assert(offset < QEMUFILE_IO_BUF_SIZE);
if (index >= f->buf_size) {
qemu_fill_buffer(f);
--
1.9.3
- [Qemu-devel] [PATCH 00/46] Postcopy implementation, Dr. David Alan Gilbert (git), 2014/07/04
- [Qemu-devel] [PATCH 02/46] Move QEMUFile structure to qemu-file.h,
Dr. David Alan Gilbert (git) <=
- [Qemu-devel] [PATCH 01/46] qemu_ram_foreach_block: pass up error value, and down the ramblock name, Dr. David Alan Gilbert (git), 2014/07/04
- [Qemu-devel] [PATCH 03/46] QEMUSizedBuffer/QEMUFile, Dr. David Alan Gilbert (git), 2014/07/04
- [Qemu-devel] [PATCH 04/46] improve DPRINTF macros, add to savevm, Dr. David Alan Gilbert (git), 2014/07/04
- [Qemu-devel] [PATCH 06/46] Create MigrationIncomingState, Dr. David Alan Gilbert (git), 2014/07/04
- [Qemu-devel] [PATCH 05/46] Add qemu_get_counted_string to read a string prefixed by a count byte, Dr. David Alan Gilbert (git), 2014/07/04
- [Qemu-devel] [PATCH 07/46] Return path: Open a return path on QEMUFile for sockets, Dr. David Alan Gilbert (git), 2014/07/04