@@ -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
@@ -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 *);
@@ -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
@@ -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);
new file mode 100644
@@ -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);
+}
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 <b.reynal@virtualopensystems.com> --- 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