qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [RFC v2 2/6] migration: add shared migration type


From: Baptiste Reynal
Subject: [Qemu-devel] [RFC v2 2/6] migration: add shared migration type
Date: Fri, 18 Mar 2016 10:13:54 +0100

A QEMU instance can now wait for the instantiation of the memory by the
master while shared-memory backend is used.

Use:
-incoming "shared:<shared-memory_id>"

Signed-off-by: Baptiste Reynal <address@hidden>
---
 backends/hostmem-shared.c     |  6 ++++++
 include/migration/migration.h |  2 ++
 migration/Makefile.objs       |  2 +-
 migration/migration.c         |  2 ++
 migration/shared.c            | 33 +++++++++++++++++++++++++++++++++
 5 files changed, 44 insertions(+), 1 deletion(-)
 create mode 100644 migration/shared.c

diff --git a/backends/hostmem-shared.c b/backends/hostmem-shared.c
index b45a87b..e703c30 100644
--- a/backends/hostmem-shared.c
+++ b/backends/hostmem-shared.c
@@ -11,6 +11,7 @@
  */
 
 #include "sysemu/hostmem-shared.h"
+#include "migration/vmstate.h"
 
 static void shm_map(HostMemoryBackendShared *shm, size_t size, off_t offset)
 {
@@ -96,6 +97,11 @@ shared_backend_memory_alloc(HostMemoryBackend *backend, 
Error **errp)
                     set_shared_memory, shm);
         }
     }
+
+    shm->levent = g_new(EventNotifier, 1);
+    event_notifier_init(shm->levent, 0);
+
+    shm->event = event_notifier_get_fd(shm->levent);
 }
 
 static void
diff --git a/include/migration/migration.h b/include/migration/migration.h
index 8334621..0d4efa5 100644
--- a/include/migration/migration.h
+++ b/include/migration/migration.h
@@ -114,6 +114,8 @@ void migrate_fd_connect(MigrationState *s);
 
 int migrate_fd_close(MigrationState *s);
 
+void shared_start_incoming_migration(const char *name, Error **errp);
+
 void add_migration_state_change_notifier(Notifier *notify);
 void remove_migration_state_change_notifier(Notifier *notify);
 bool migration_in_setup(MigrationState *);
diff --git a/migration/Makefile.objs b/migration/Makefile.objs
index d929e96..08c96f7 100644
--- a/migration/Makefile.objs
+++ b/migration/Makefile.objs
@@ -7,4 +7,4 @@ common-obj-$(CONFIG_RDMA) += rdma.o
 common-obj-$(CONFIG_POSIX) += exec.o unix.o fd.o
 
 common-obj-y += block.o
-
+common-obj-y += shared.o
diff --git a/migration/migration.c b/migration/migration.c
index 662e77e..798801c 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -249,6 +249,8 @@ void qemu_start_incoming_migration(const char *uri, Error 
**errp)
         deferred_incoming_migration(errp);
     } else if (strstart(uri, "tcp:", &p)) {
         tcp_start_incoming_migration(p, errp);
+    } else if (strstart(uri, "shared:", &p)) {
+        shared_start_incoming_migration(p, errp);
 #ifdef CONFIG_RDMA
     } else if (strstart(uri, "rdma:", &p)) {
         rdma_start_incoming_migration(p, errp);
diff --git a/migration/shared.c b/migration/shared.c
new file mode 100644
index 0000000..1371a71
--- /dev/null
+++ b/migration/shared.c
@@ -0,0 +1,33 @@
+#include "qemu-common.h"
+#include "qemu/main-loop.h"
+#include "qemu/sockets.h"
+#include "migration/migration.h"
+#include "monitor/monitor.h"
+#include "migration/qemu-file.h"
+#include "block/block.h"
+#include "sysemu/hostmem-shared.h"
+
+static void shared_accept_incoming_migration(void *opaque)
+{
+    QEMUFile *f = opaque;
+    printf("Start !\n");
+
+    qemu_set_fd_handler(qemu_get_fd(f), NULL, NULL, NULL);
+    vm_start();
+}
+
+void shared_start_incoming_migration(const char *id, Error **errp)
+{
+    HostMemoryBackendShared *shm = (HostMemoryBackendShared *)
+        object_resolve_path_type(id, TYPE_MEMORY_BACKEND_SHARED, NULL);
+    QEMUFile *f;
+
+    if (shm == NULL) {
+        printf("Error: Cannot find shared memory %s\n", id);
+        exit(-1);
+    }
+
+    f = qemu_fdopen(shm->event, "rb");
+
+    qemu_set_fd_handler(shm->event, shared_accept_incoming_migration, NULL, f);
+}
-- 
2.7.3




reply via email to

[Prev in Thread] Current Thread [Next in Thread]