From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42377) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dkZyR-0000pe-Ns for qemu-devel@nongnu.org; Wed, 23 Aug 2017 14:01:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dkZyM-00043U-Tv for qemu-devel@nongnu.org; Wed, 23 Aug 2017 14:01:51 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47746) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dkZyM-000436-LM for qemu-devel@nongnu.org; Wed, 23 Aug 2017 14:01:46 -0400 Date: Wed, 23 Aug 2017 19:01:35 +0100 From: "Dr. David Alan Gilbert" Message-ID: <20170823180135.GI2648@work-vm> References: <1503471071-2233-1-git-send-email-peterx@redhat.com> <1503471071-2233-9-git-send-email-peterx@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1503471071-2233-9-git-send-email-peterx@redhat.com> Subject: Re: [Qemu-devel] [RFC v2 8/8] migration: add incoming mgmt lock List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Xu Cc: qemu-devel@nongnu.org, Paolo Bonzini , "Daniel P . Berrange" , Fam Zheng , Juan Quintela , mdroth@linux.vnet.ibm.com, Eric Blake , Laurent Vivier , Markus Armbruster * Peter Xu (peterx@redhat.com) wrote: > Now at least migrate_incoming can be run in parallel. Let's provide a > migration lock to protect it. > > Signed-off-by: Peter Xu > --- > migration/migration.c | 6 ++++++ > migration/migration.h | 3 +++ > 2 files changed, 9 insertions(+) > > diff --git a/migration/migration.c b/migration/migration.c > index c3fe0ed..32058f7 100644 > --- a/migration/migration.c > +++ b/migration/migration.c > @@ -145,6 +145,7 @@ MigrationIncomingState *migration_incoming_get_current(void) > mis_current.state = MIGRATION_STATUS_NONE; > memset(&mis_current, 0, sizeof(MigrationIncomingState)); > qemu_mutex_init(&mis_current.rp_mutex); > + qemu_mutex_init(&mis_current.mgmt_mutex); > qemu_event_init(&mis_current.main_thread_load_event, false); > once = true; > } > @@ -1171,6 +1172,7 @@ void qmp_migrate_incoming(const char *uri, Error **errp) > { > Error *local_err = NULL; > static bool once = true; > + MigrationIncomingState *mis = migration_incoming_get_current(); migration_incoming_get_current isn't actually thread-safe itself unless you can guarantee the initial allocation has happened - otherwise both threads can race and do the 'once' code at the same time. Similarly, these locks - they don't protect our 'once' - so a second thread could come in here and both get past the !once check. Dave > > if (!deferred_incoming) { > error_setg(errp, "For use with '-incoming defer'"); > @@ -1180,8 +1182,12 @@ void qmp_migrate_incoming(const char *uri, Error **errp) > error_setg(errp, "The incoming migration has already been started"); > } > > + qemu_mutex_lock(&mis->mgmt_mutex); > + > qemu_start_incoming_migration(uri, &local_err); > > + qemu_mutex_unlock(&mis->mgmt_mutex); > + > if (local_err) { > error_propagate(errp, local_err); > return; > diff --git a/migration/migration.h b/migration/migration.h > index 148c9fa..95f077b 100644 > --- a/migration/migration.h > +++ b/migration/migration.h > @@ -58,6 +58,9 @@ struct MigrationIncomingState { > /* The coroutine we should enter (back) after failover */ > Coroutine *migration_incoming_co; > QemuSemaphore colo_incoming_sem; > + > + /* Migration incoming management lock */ > + QemuMutex mgmt_mutex; > }; > > MigrationIncomingState *migration_incoming_get_current(void); > -- > 2.7.4 > -- Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK