@@ -168,6 +168,15 @@ static int buffered_put_buffer(void *opaque, const uint8_t *buf, int64_t pos, in
return offset;
}
+static void buffered_drain(QEMUFileBuffered *s)
+{
+ while (!qemu_file_get_error(s->file) && s->buffer_size) {
+ buffered_flush(s);
+ if (s->freeze_output)
+ s->wait_for_unfreeze(s->opaque);
+ }
+}
+
static int buffered_close(void *opaque)
{
QEMUFileBuffered *s = opaque;
@@ -175,11 +184,7 @@ static int buffered_close(void *opaque)
DPRINTF("closing\n");
- while (!qemu_file_get_error(s->file) && s->buffer_size) {
- buffered_flush(s);
- if (s->freeze_output)
- s->wait_for_unfreeze(s->opaque);
- }
+ buffered_drain(s);
ret = s->close(s->opaque);
@@ -289,3 +294,8 @@ QEMUFile *qemu_fopen_ops_buffered(void *opaque,
return s->file;
}
+
+void qemu_buffered_file_drain_buffer(void *buffered_file)
+{
+ buffered_drain(buffered_file);
+}
@@ -26,5 +26,6 @@ QEMUFile *qemu_fopen_ops_buffered(void *opaque, size_t xfer_limit,
BufferedPutReadyFunc *put_ready,
BufferedWaitForUnfreezeFunc *wait_for_unfreeze,
BufferedCloseFunc *close);
+void qemu_buffered_file_drain_buffer(void *buffered_file);
#endif
@@ -61,6 +61,7 @@ QEMUFile *qemu_popen(FILE *popen_file, const char *mode);
QEMUFile *qemu_popen_cmd(const char *command, const char *mode);
int qemu_stdio_fd(QEMUFile *f);
void qemu_fflush(QEMUFile *f);
+void qemu_buffered_file_drain(QEMUFile *f);
int qemu_fclose(QEMUFile *f);
void qemu_put_buffer(QEMUFile *f, const uint8_t *buf, int size);
void qemu_put_byte(QEMUFile *f, int v);
@@ -83,6 +83,7 @@
#include "qemu-queue.h"
#include "qemu-timer.h"
#include "cpus.h"
+#include "buffered_file.h"
#define SELF_ANNOUNCE_ROUNDS 5
@@ -475,6 +476,11 @@ void qemu_fflush(QEMUFile *f)
}
}
+void qemu_buffered_file_drain(QEMUFile *f)
+{
+ qemu_buffered_file_drain_buffer(f->opaque);
+}
+
static void qemu_fill_buffer(QEMUFile *f)
{
int len;
Introduce a new method to drain the buffer of QEMUBufferedFile. When postcopy migration, buffer size can increase unboundedly. To keep the buffer size reasonably small, introduce the method to wait for buffer to drain. Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp> --- buffered_file.c | 20 +++++++++++++++----- buffered_file.h | 1 + hw/hw.h | 1 + savevm.c | 6 ++++++ 4 files changed, 23 insertions(+), 5 deletions(-)