From patchwork Mon Aug 11 14:29:25 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Dr. David Alan Gilbert" X-Patchwork-Id: 379005 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id BF00714013A for ; Tue, 12 Aug 2014 00:31:26 +1000 (EST) Received: from localhost ([::1]:36233 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XGqdA-0000Po-Io for incoming@patchwork.ozlabs.org; Mon, 11 Aug 2014 10:31:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40647) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XGqcF-0007YI-JW for qemu-devel@nongnu.org; Mon, 11 Aug 2014 10:30:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XGqc9-0000qb-EQ for qemu-devel@nongnu.org; Mon, 11 Aug 2014 10:30:27 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47406) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XGqc9-0000pu-7U for qemu-devel@nongnu.org; Mon, 11 Aug 2014 10:30:21 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s7BEUIqk011791 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 11 Aug 2014 10:30:18 -0400 Received: from dgilbert-t530.home.treblig.org (vpn1-5-102.ams2.redhat.com [10.36.5.102]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s7BEU08V003792; Mon, 11 Aug 2014 10:30:16 -0400 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org Date: Mon, 11 Aug 2014 15:29:25 +0100 Message-Id: <1407767399-3030-10-git-send-email-dgilbert@redhat.com> In-Reply-To: <1407767399-3030-1-git-send-email-dgilbert@redhat.com> References: <1407767399-3030-1-git-send-email-dgilbert@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: aarcange@redhat.com, yamahata@private.email.ne.jp, lilei@linux.vnet.ibm.com, quintela@redhat.com Subject: [Qemu-devel] [PATCH v2 09/43] Return path: Send responses from destination to source 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: "Dr. David Alan Gilbert" Add migrate_send_rp_message to send a message from destination to source along the return path. (It uses a mutex to let it be called from multiple threads) Add migrate_send_rp_shut to send a 'shut' message to indicate the destination is finished with the RP. Add migrate_send_rp_ack to send an 'ack' message Use it in the CMD_REQACK handler Signed-off-by: Dr. David Alan Gilbert --- include/migration/migration.h | 18 ++++++++++++++++++ migration.c | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/include/migration/migration.h b/include/migration/migration.h index 173775b..12e640d 100644 --- a/include/migration/migration.h +++ b/include/migration/migration.h @@ -40,6 +40,13 @@ struct MigrationParams { bool shared; }; +/* Commands sent on the return path from destination to source*/ +enum mig_rpcomm_cmd { + MIG_RPCOMM_INVALID = 0, /* Must be 0 */ + MIG_RPCOMM_SHUT, /* sibling will not send any more RP messages */ + MIG_RPCOMM_ACK, /* data (seq: be32 ) */ + MIG_RPCOMM_AFTERLASTVALID +}; typedef struct MigrationState MigrationState; /* State for the incoming migration */ @@ -47,6 +54,7 @@ struct MigrationIncomingState { QEMUFile *file; QEMUFile *return_path; + QemuMutex rp_mutex; /* We send replies from multiple threads */ }; MigrationIncomingState *migration_incoming_get_current(void); @@ -168,6 +176,16 @@ int64_t migrate_xbzrle_cache_size(void); int64_t xbzrle_cache_resize(int64_t new_size); +/* Sending on the return path - generic and then for each message type */ +void migrate_send_rp_message(MigrationIncomingState *mis, + enum mig_rpcomm_cmd cmd, + uint16_t len, uint8_t *data); +void migrate_send_rp_shut(MigrationIncomingState *mis, + uint32_t value); +void migrate_send_rp_ack(MigrationIncomingState *mis, + uint32_t value); + + void ram_control_before_iterate(QEMUFile *f, uint64_t flags); void ram_control_after_iterate(QEMUFile *f, uint64_t flags); void ram_control_load_hook(QEMUFile *f, uint64_t flags); diff --git a/migration.c b/migration.c index c203958..3e4e120 100644 --- a/migration.c +++ b/migration.c @@ -90,6 +90,7 @@ MigrationIncomingState *migration_incoming_state_init(QEMUFile* f) { mis_current = g_malloc0(sizeof(MigrationIncomingState)); mis_current->file = f; + qemu_mutex_init(&mis_current->rp_mutex); return mis_current; } @@ -100,6 +101,46 @@ void migration_incoming_state_destroy(void) mis_current = NULL; } +/* Send a message on the return channel back to the source + * of the migration. + */ +void migrate_send_rp_message(MigrationIncomingState *mis, + enum mig_rpcomm_cmd cmd, + uint16_t len, uint8_t *data) +{ + DPRINTF("migrate_send_rp_message: cmd=%d, len=%d\n", (int)cmd, len); + qemu_mutex_lock(&mis->rp_mutex); + qemu_put_be16(mis->return_path, (unsigned int)cmd); + qemu_put_be16(mis->return_path, len); + qemu_put_buffer(mis->return_path, data, len); + qemu_fflush(mis->return_path); + qemu_mutex_unlock(&mis->rp_mutex); +} + +/* + * Send a 'SHUT' message on the return channel with the given value + * to indicate that we've finished with the RP. None-0 value indicates + * error. + */ +void migrate_send_rp_shut(MigrationIncomingState *mis, + uint32_t value) +{ + uint32_t buf; + + buf = cpu_to_be32(value); + migrate_send_rp_message(mis, MIG_RPCOMM_SHUT, 4, (uint8_t *)&buf); +} + +/* Send an 'ACK' message on the return channel with the given value */ +void migrate_send_rp_ack(MigrationIncomingState *mis, + uint32_t value) +{ + uint32_t buf; + + buf = cpu_to_be32(value); + migrate_send_rp_message(mis, MIG_RPCOMM_ACK, 4, (uint8_t *)&buf); +} + void qemu_start_incoming_migration(const char *uri, Error **errp) { const char *p;