From patchwork Fri Mar 18 09:13:54 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baptiste Reynal X-Patchwork-Id: 8617441 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id A118F9F44D for ; Fri, 18 Mar 2016 09:18:20 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D843120374 for ; Fri, 18 Mar 2016 09:18:19 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 196A02035D for ; Fri, 18 Mar 2016 09:18:18 +0000 (UTC) Received: from localhost ([::1]:42399 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1agqXx-0001Ys-2P for patchwork-qemu-devel@patchwork.kernel.org; Fri, 18 Mar 2016 05:18:17 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42358) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1agqU2-0003iK-Kt for qemu-devel@nongnu.org; Fri, 18 Mar 2016 05:14:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1agqU1-0003vq-F7 for qemu-devel@nongnu.org; Fri, 18 Mar 2016 05:14:14 -0400 Received: from mail-wm0-x233.google.com ([2a00:1450:400c:c09::233]:35986) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1agqU1-0003vl-1x for qemu-devel@nongnu.org; Fri, 18 Mar 2016 05:14:13 -0400 Received: by mail-wm0-x233.google.com with SMTP id l124so22969308wmf.1 for ; Fri, 18 Mar 2016 02:14:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtualopensystems-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ILt2pxHCUkZ+UY3SbehC1FGjmg5JmCojw5NoDpYt0G0=; b=cbMDuDQU5mlnqafuqwvNg9uMULQ+gmKoX/ovh/1JUXNRKbxNc88NDJ2OdvlL5aNUee wko28LpLgynqA+z/WQhjd3xwgw0Ek0Rds3eSreB5UoZh2KjJEBdIyfnC/EzzrtcBI4Gq oliI4uD8+V/ECe60fk5J9t4Kkgc3LjqvaD/Z8lwd9r4Lxp2EdEQe64pnDfkJBCQqBqW8 6fNUwa0CF0Ba+EGKJGnPbVeek41tJkfXtmO2CUc+9xssD0B7O/YBn833xV4gHtq1vRGx Sfb7fvRquQrNd83dc3bhO+LDL4hpuB+zQxzFYKloLK9OUpo0RyFzYi16m97e35Op5u6j XYYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ILt2pxHCUkZ+UY3SbehC1FGjmg5JmCojw5NoDpYt0G0=; b=KXQp0vA0zG870avjx5FDzKJjLB57L012LpvqorBFOAIX22g/tWyoEAaPgrF7vZZslG zzv9oHJXH2/57c11qIEPzM6hUte8TNZWQ0tVuoV9Jx4/+pq/Mpv82iVAuzFP2kUVV/nB fcLw7mygh3olxerPMaZ1Td6gT9ofcCdi6tEJsNxxAD4bmZWiEA1dfCbXa7I7zCeNgnfX Po5+uu5B2F3WB9/G+9YjhS3vUBI32MKk3DvqmjIhQkJSmtlYkTJzRZ7H6Ooxr8VQgNZh thysuCU9MNmjbF+MIqYEm4J32rsVZylkV/WhtCX81zr6m7di6UwWLtTugqrYwS8VzPZ6 dxCQ== X-Gm-Message-State: AD7BkJII5b2ncfgwLdzCbq1KEpgNeQhx3DPyqyZW6m2GxlfJSKdzVBegIVoBXJMzmq0WMQ== X-Received: by 10.28.186.214 with SMTP id k205mr41981613wmf.23.1458292452589; Fri, 18 Mar 2016 02:14:12 -0700 (PDT) Received: from localhost (LMontsouris-657-1-4-224.w90-63.abo.wanadoo.fr. [90.63.239.224]) by smtp.gmail.com with ESMTPSA id gt7sm11348108wjc.1.2016.03.18.02.14.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 18 Mar 2016 02:14:12 -0700 (PDT) From: Baptiste Reynal To: qemu-devel@nongnu.org Date: Fri, 18 Mar 2016 10:13:54 +0100 Message-Id: <1458292438-13909-3-git-send-email-b.reynal@virtualopensystems.com> X-Mailer: git-send-email 2.7.3 In-Reply-To: <1458292438-13909-1-git-send-email-b.reynal@virtualopensystems.com> References: <1458292438-13909-1-git-send-email-b.reynal@virtualopensystems.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::233 Cc: b.reynal@virtualopensystems.com, Jani.Kokkonen@huawei.com, tech@virtualopensystems.com, Claudio.Fontana@huawei.com Subject: [Qemu-devel] [RFC v2 2/6] migration: add shared migration type X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP A QEMU instance can now wait for the instantiation of the memory by the master while shared-memory backend is used. Use: -incoming "shared:" Signed-off-by: Baptiste Reynal --- 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); +}