diff mbox

[5/8] migration: add draft of new transport

Message ID 1444198846-5383-6-git-send-email-den@openvz.org
State New
Headers show

Commit Message

Denis V. Lunev Oct. 7, 2015, 6:20 a.m. UTC
From: Igor Redko <redkoi@virtuozzo.com>

In this patch transport test is added. It can be used to estimate
the possibility of live migration given downtime and bandwidth.
In this patch basic functionality is implemented to meet the
QEMUFile interface requirements.

This transport is write-only. Moreover, it saves only the size of
the transferred data and drops the data itself.

Also, the Makefile modification to link this file included.

Signed-off-by: Igor Redko <redkoi@virtuozzo.com>
Reviewed-by: Anna Melekhova <annam@virtuozzo.com>
Signed-off-by: Denis V. Lunev <den@openvz.org>
---
 include/migration/migration.h |  2 ++
 migration/Makefile.objs       |  2 +-
 migration/test.c              | 66 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 69 insertions(+), 1 deletion(-)
 create mode 100644 migration/test.c
diff mbox

Patch

diff --git a/include/migration/migration.h b/include/migration/migration.h
index 8611750..555267b 100644
--- a/include/migration/migration.h
+++ b/include/migration/migration.h
@@ -108,6 +108,8 @@  void rdma_start_outgoing_migration(void *opaque, const char *host_port, Error **
 
 void rdma_start_incoming_migration(const char *host_port, Error **errp);
 
+void test_start_migration(void *opaque, const char *host_port, Error **errp);
+
 void migrate_fd_error(MigrationState *s);
 
 void migrate_fd_connect(MigrationState *s);
diff --git a/migration/Makefile.objs b/migration/Makefile.objs
index d929e96..2da590b 100644
--- a/migration/Makefile.objs
+++ b/migration/Makefile.objs
@@ -1,4 +1,4 @@ 
-common-obj-y += migration.o tcp.o
+common-obj-y += migration.o tcp.o test.o
 common-obj-y += vmstate.o
 common-obj-y += qemu-file.o qemu-file-buf.o qemu-file-unix.o qemu-file-stdio.o
 common-obj-y += xbzrle.o
diff --git a/migration/test.c b/migration/test.c
new file mode 100644
index 0000000..8d06988
--- /dev/null
+++ b/migration/test.c
@@ -0,0 +1,66 @@ 
+#include "qemu-common.h"
+#include "migration/migration.h"
+#include "migration/qemu-file.h"
+#include "exec/cpu-common.h"
+#include "qemu/error-report.h"
+#include "qemu/main-loop.h"
+#include "qemu/sockets.h"
+#include "qemu/bitmap.h"
+#include <stdio.h>
+#include <string.h>
+#include "qmp-commands.h"
+
+typedef struct QEMUFileTest {
+    MigrationState *s;
+    size_t len;
+    QEMUFile *file;
+} QEMUFileTest;
+
+static uint64_t transfered_bytes;
+static uint64_t initial_bytes;
+
+static ssize_t qemu_test_put_buffer(void *opaque, const uint8_t *buf,
+                                    int64_t pos, size_t size)
+{
+    transfered_bytes += size;
+    return size;
+}
+
+static int qemu_test_close(void *opaque)
+{
+    return 0;
+}
+
+static const QEMUFileOps test_write_ops = {
+    .put_buffer         = qemu_test_put_buffer,
+    .close              = qemu_test_close,
+};
+
+static void *qemu_fopen_test(MigrationState *s, const char *mode)
+{
+    QEMUFileTest *t;
+    transfered_bytes = 0;
+    initial_bytes = 0;
+    if (qemu_file_mode_is_not_valid(mode)) {
+        return NULL;
+    }
+
+    t = g_malloc0(sizeof(QEMUFileTest));
+    t->s = s;
+
+    if (mode[0] == 'w') {
+        t->file = qemu_fopen_ops(s, &test_write_ops);
+    } else {
+        return NULL;
+    }
+    qemu_file_set_rate_limit(t->file, -1);
+    return t->file;
+}
+
+void test_start_migration(void *opaque, const char *host_port, Error **errp)
+{
+    MigrationState *s = opaque;
+    s->file = qemu_fopen_test(s, "wb");
+    migrate_fd_connect(s);
+    return;
+}