From patchwork Fri Oct 21 19:42:08 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juan Quintela X-Patchwork-Id: 9390035 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 89E1860762 for ; Fri, 21 Oct 2016 19:56:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 771262A28C for ; Fri, 21 Oct 2016 19:56:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6BD932A290; Fri, 21 Oct 2016 19:56:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id CBB2E2A28C for ; Fri, 21 Oct 2016 19:56:48 +0000 (UTC) Received: from localhost ([::1]:34149 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bxfvs-0008Pa-3O for patchwork-qemu-devel@patchwork.kernel.org; Fri, 21 Oct 2016 15:56:48 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55408) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bxfi6-0005Bl-HS for qemu-devel@nongnu.org; Fri, 21 Oct 2016 15:42:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bxfi5-0007Vq-1o for qemu-devel@nongnu.org; Fri, 21 Oct 2016 15:42:34 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40082) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1bxfi4-0007Vc-QP for qemu-devel@nongnu.org; Fri, 21 Oct 2016 15:42:32 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 158D090E6B for ; Fri, 21 Oct 2016 19:42:32 +0000 (UTC) Received: from emacs.mitica (ovpn-116-122.ams2.redhat.com [10.36.116.122]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u9LJgLrd018033; Fri, 21 Oct 2016 15:42:30 -0400 From: Juan Quintela To: qemu-devel@nongnu.org Date: Fri, 21 Oct 2016 21:42:08 +0200 Message-Id: <1477078935-7182-7-git-send-email-quintela@redhat.com> In-Reply-To: <1477078935-7182-1-git-send-email-quintela@redhat.com> References: <1477078935-7182-1-git-send-email-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 21 Oct 2016 19:42:32 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 06/13] migration: Start of multiple fd work X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: amit.shah@redhat.com, dgilbert@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP We create new channels for each new thread created. We only send through them a character to be sure that we are creating the channels in the right order. Note: Reference count/freeing of channels is not done Signed-off-by: Juan Quintela --- include/migration/migration.h | 6 +++++ migration/ram.c | 45 +++++++++++++++++++++++++++++++++++- migration/socket.c | 53 ++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 102 insertions(+), 2 deletions(-) diff --git a/include/migration/migration.h b/include/migration/migration.h index 80ab8c0..0b455d6 100644 --- a/include/migration/migration.h +++ b/include/migration/migration.h @@ -21,6 +21,7 @@ #include "migration/vmstate.h" #include "qapi-types.h" #include "exec/cpu-common.h" +#include "io/channel.h" #define QEMU_VM_FILE_MAGIC 0x5145564d #define QEMU_VM_FILE_VERSION_COMPAT 0x00000002 @@ -211,6 +212,11 @@ void tcp_start_incoming_migration(const char *host_port, Error **errp); void tcp_start_outgoing_migration(MigrationState *s, const char *host_port, Error **errp); +QIOChannel *socket_recv_channel_create(void); +int socket_recv_channel_destroy(QIOChannel *recv); +QIOChannel *socket_send_channel_create(void); +int socket_send_channel_destroy(QIOChannel *send); + void unix_start_incoming_migration(const char *path, Error **errp); void unix_start_outgoing_migration(MigrationState *s, const char *path, Error **errp); diff --git a/migration/ram.c b/migration/ram.c index 78d400e..0ea40eb 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -396,6 +396,8 @@ struct MultiFDSendParams { QemuCond cond; QemuMutex mutex; bool quit; + bool started; + QIOChannel *c; }; typedef struct MultiFDSendParams MultiFDSendParams; @@ -404,6 +406,13 @@ static MultiFDSendParams *multifd_send; static void *multifd_send_thread(void *opaque) { MultiFDSendParams *params = opaque; + char start = 's'; + + qio_channel_write(params->c, &start, 1, &error_abort); + qemu_mutex_lock(¶ms->mutex); + params->started = true; + qemu_cond_signal(¶ms->cond); + qemu_mutex_unlock(¶ms->mutex); qemu_mutex_lock(¶ms->mutex); while (!params->quit){ @@ -440,6 +449,7 @@ void migrate_multifd_send_threads_join(void) qemu_thread_join(&multifd_send[i].thread); qemu_mutex_destroy(&multifd_send[i].mutex); qemu_cond_destroy(&multifd_send[i].cond); + socket_send_channel_destroy(multifd_send[i].c); } g_free(multifd_send); multifd_send = NULL; @@ -458,9 +468,20 @@ void migrate_multifd_send_threads_create(void) qemu_mutex_init(&multifd_send[i].mutex); qemu_cond_init(&multifd_send[i].cond); multifd_send[i].quit = false; + multifd_send[i].started = false; + multifd_send[i].c = socket_send_channel_create(); + if(!multifd_send[i].c) { + printf("Error creating a send channel"); + exit(0); + } qemu_thread_create(&multifd_send[i].thread, "multifd_send", multifd_send_thread, &multifd_send[i], QEMU_THREAD_JOINABLE); + qemu_mutex_lock(&multifd_send[i].mutex); + while (!multifd_send[i].started) { + qemu_cond_wait(&multifd_send[i].cond, &multifd_send[i].mutex); + } + qemu_mutex_unlock(&multifd_send[i].mutex); } } @@ -469,6 +490,8 @@ struct MultiFDRecvParams { QemuCond cond; QemuMutex mutex; bool quit; + bool started; + QIOChannel *c; }; typedef struct MultiFDRecvParams MultiFDRecvParams; @@ -477,7 +500,14 @@ static MultiFDRecvParams *multifd_recv; static void *multifd_recv_thread(void *opaque) { MultiFDRecvParams *params = opaque; - + char start; + + qio_channel_read(params->c, &start, 1, &error_abort); + qemu_mutex_lock(¶ms->mutex); + params->started = true; + qemu_cond_signal(¶ms->cond); + qemu_mutex_unlock(¶ms->mutex); + qemu_mutex_lock(¶ms->mutex); while (!params->quit){ qemu_cond_wait(¶ms->cond, ¶ms->mutex); @@ -513,6 +543,7 @@ void migrate_multifd_recv_threads_join(void) qemu_thread_join(&multifd_recv[i].thread); qemu_mutex_destroy(&multifd_recv[i].mutex); qemu_cond_destroy(&multifd_recv[i].cond); + socket_send_channel_destroy(multifd_recv[i].c); } g_free(multifd_recv); multifd_recv = NULL; @@ -531,9 +562,21 @@ void migrate_multifd_recv_threads_create(void) qemu_mutex_init(&multifd_recv[i].mutex); qemu_cond_init(&multifd_recv[i].cond); multifd_recv[i].quit = false; + multifd_recv[i].started = false; + multifd_recv[i].c = socket_recv_channel_create(); + + if(!multifd_recv[i].c) { + printf("Error creating a recv channel"); + exit(0); + } qemu_thread_create(&multifd_recv[i].thread, "multifd_recv", multifd_recv_thread, &multifd_recv[i], QEMU_THREAD_JOINABLE); + qemu_mutex_lock(&multifd_recv[i].mutex); + while (!multifd_recv[i].started) { + qemu_cond_wait(&multifd_recv[i].cond, &multifd_recv[i].mutex); + } + qemu_mutex_unlock(&multifd_recv[i].mutex); } } diff --git a/migration/socket.c b/migration/socket.c index a21c0c5..f001396 100644 --- a/migration/socket.c +++ b/migration/socket.c @@ -24,6 +24,48 @@ #include "io/channel-socket.h" #include "trace.h" +struct SocketArgs { + QIOChannelSocket *ioc; + SocketAddress *saddr; + Error **errp; +} socket_args; + +QIOChannel *socket_recv_channel_create(void) +{ + QIOChannelSocket *sioc; + Error *err = NULL; + + sioc = qio_channel_socket_accept(QIO_CHANNEL_SOCKET(socket_args.ioc), + &err); + if (!sioc) { + error_report("could not accept migration connection (%s)", + error_get_pretty(err)); + return NULL; + } + return QIO_CHANNEL(sioc); +} + +int socket_recv_channel_destroy(QIOChannel *recv) +{ + // Remove channel here + return 0; +} + +QIOChannel *socket_send_channel_create(void) +{ + QIOChannelSocket *sioc = qio_channel_socket_new(); + + qio_channel_socket_connect_sync(sioc, socket_args.saddr, + socket_args.errp); + qio_channel_set_delay(QIO_CHANNEL(sioc), false); + return QIO_CHANNEL(sioc); +} + +int socket_send_channel_destroy(QIOChannel *send) +{ + // Remove channel here + return 0; +} static SocketAddress *tcp_build_address(const char *host_port, Error **errp) { @@ -96,6 +138,10 @@ static void socket_start_outgoing_migration(MigrationState *s, struct SocketConnectData *data = g_new0(struct SocketConnectData, 1); data->s = s; + + socket_args.saddr = saddr; + socket_args.errp = errp; + if (saddr->type == SOCKET_ADDRESS_KIND_INET) { data->hostname = g_strdup(saddr->u.inet.data->host); } @@ -105,7 +151,11 @@ static void socket_start_outgoing_migration(MigrationState *s, socket_outgoing_migration, data, socket_connect_data_free); + /* + We are not freeing saddr yet, we need some kind of reference + counting qapi_free_SocketAddress(saddr); + */ } void tcp_start_outgoing_migration(MigrationState *s, @@ -152,7 +202,7 @@ static gboolean socket_accept_incoming_migration(QIOChannel *ioc, out: /* Close listening socket as its no longer needed */ - qio_channel_close(ioc, NULL); +// qio_channel_close(ioc, NULL); return FALSE; /* unregister */ } @@ -161,6 +211,7 @@ static void socket_start_incoming_migration(SocketAddress *saddr, Error **errp) { QIOChannelSocket *listen_ioc = qio_channel_socket_new(); + socket_args.ioc = listen_ioc; if (qio_channel_socket_listen_sync(listen_ioc, saddr, errp) < 0) { object_unref(OBJECT(listen_ioc));