From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41808) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YfKG5-00050v-Ap for qemu-devel@nongnu.org; Mon, 06 Apr 2015 23:33:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YfKG3-0002xG-Ou for qemu-devel@nongnu.org; Mon, 06 Apr 2015 23:33:01 -0400 Received: from ozlabs.org ([2401:3900:2:1::2]:50559) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YfKG3-0002x6-5j for qemu-devel@nongnu.org; Mon, 06 Apr 2015 23:32:59 -0400 Date: Tue, 7 Apr 2015 13:07:07 +1000 From: David Gibson Message-ID: <20150407030707.GB3476@voom.fritz.box> References: <1424883128-9841-1-git-send-email-dgilbert@redhat.com> <1424883128-9841-13-git-send-email-dgilbert@redhat.com> <20150310060824.GD11973@voom.redhat.com> <20150320181730.GI2468@work-vm> <20150323023739.GH25043@voom.fritz.box> <20150401151404.GA2310@work-vm> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="IrhDeMKUP4DT/M7F" Content-Disposition: inline In-Reply-To: <20150401151404.GA2310@work-vm> Subject: Re: [Qemu-devel] [PATCH v5 12/45] Return path: Source handling of return path List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Dr. David Alan Gilbert" Cc: aarcange@redhat.com, yamahata@private.email.ne.jp, quintela@redhat.com, qemu-devel@nongnu.org, amit.shah@redhat.com, pbonzini@redhat.com, yanghy@cn.fujitsu.com --IrhDeMKUP4DT/M7F Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Apr 01, 2015 at 04:14:05PM +0100, Dr. David Alan Gilbert wrote: > * David Gibson (david@gibson.dropbear.id.au) wrote: > > On Fri, Mar 20, 2015 at 06:17:31PM +0000, Dr. David Alan Gilbert wrote: > > > * David Gibson (david@gibson.dropbear.id.au) wrote: > > > > On Wed, Feb 25, 2015 at 04:51:35PM +0000, Dr. David Alan Gilbert (g= it) wrote: > > > > > From: "Dr. David Alan Gilbert" > > > > >=20 > > > > > Open a return path, and handle messages that are received upon it. > > > > >=20 > > > > > Signed-off-by: Dr. David Alan Gilbert > > > > > --- > > > > > include/migration/migration.h | 8 ++ > > > > > migration/migration.c | 178 ++++++++++++++++++++++++++++= +++++++++++++- > > > > > trace-events | 13 +++ > > > > > 3 files changed, 198 insertions(+), 1 deletion(-) > > > > >=20 > > > > > diff --git a/include/migration/migration.h b/include/migration/mi= gration.h > > > > > index 6775747..5242ead 100644 > > > > > --- a/include/migration/migration.h > > > > > +++ b/include/migration/migration.h > > > > > @@ -73,6 +73,14 @@ struct MigrationState > > > > > =20 > > > > > int state; > > > > > MigrationParams params; > > > > > + > > > > > + /* State related to return path */ > > > > > + struct { > > > > > + QEMUFile *file; > > > > > + QemuThread rp_thread; > > > > > + bool error; > > > > > + } rp_state; > > > > > + > > > > > double mbps; > > > > > int64_t total_time; > > > > > int64_t downtime; > > > > > diff --git a/migration/migration.c b/migration/migration.c > > > > > index 80d234c..34cd4fe 100644 > > > > > --- a/migration/migration.c > > > > > +++ b/migration/migration.c > > > > > @@ -237,6 +237,23 @@ MigrationCapabilityStatusList *qmp_query_mig= rate_capabilities(Error **errp) > > > > > return head; > > > > > } > > > > > =20 > > > > > +/* > > > > > + * Return true if we're already in the middle of a migration > > > > > + * (i.e. any of the active or setup states) > > > > > + */ > > > > > +static bool migration_already_active(MigrationState *ms) > > > > > +{ > > > > > + switch (ms->state) { > > > > > + case MIG_STATE_ACTIVE: > > > > > + case MIG_STATE_SETUP: > > > > > + return true; > > > > > + > > > > > + default: > > > > > + return false; > > > > > + > > > > > + } > > > > > +} > > > > > + > > > > > static void get_xbzrle_cache_stats(MigrationInfo *info) > > > > > { > > > > > if (migrate_use_xbzrle()) { > > > > > @@ -362,6 +379,21 @@ static void migrate_set_state(MigrationState= *s, int old_state, int new_state) > > > > > } > > > > > } > > > > > =20 > > > > > +static void migrate_fd_cleanup_src_rp(MigrationState *ms) > > > > > +{ > > > > > + QEMUFile *rp =3D ms->rp_state.file; > > > > > + > > > > > + /* > > > > > + * When stuff goes wrong (e.g. failing destination) on the r= p, it can get > > > > > + * cleaned up from a few threads; make sure not to do it twi= ce in parallel > > > > > + */ > > > > > + rp =3D atomic_cmpxchg(&ms->rp_state.file, rp, NULL); > > > >=20 > > > > A cmpxchg seems dangerously subtle for such a basic and infrequent > > > > operation, but ok. > > >=20 > > > I'll take other suggestions; but I'm trying to just do > > > 'if the qemu_file still exists close it', and it didn't seem > > > worth introducing another state variable to atomically update > > > when we've already got the file pointer itself. > >=20 > > Yes, I see the rationale. My concern is just that the more atomicity > > mechanisms are scattered through the code, the harder it is to analyze > > and be sure you haven't missed race cases (or introduced then with a > > future change). > >=20 > > In short, I prefer to see a simple-as-possible, and preferably > > documented, consistent overall concurrency scheme for a data > > structure, rather than scattered atomic ops for various variable where > > it's difficult to see how all the pieces might relate together. > >=20 > > > > > + if (rp) { > > > > > + trace_migrate_fd_cleanup_src_rp(); > > > > > + qemu_fclose(rp); > > > > > + } > > > > > +} > > > > > + > > > > > static void migrate_fd_cleanup(void *opaque) > > > > > { > > > > > MigrationState *s =3D opaque; > > > > > @@ -369,6 +401,8 @@ static void migrate_fd_cleanup(void *opaque) > > > > > qemu_bh_delete(s->cleanup_bh); > > > > > s->cleanup_bh =3D NULL; > > > > > =20 > > > > > + migrate_fd_cleanup_src_rp(s); > > > > > + > > > > > if (s->file) { > > > > > trace_migrate_fd_cleanup(); > > > > > qemu_mutex_unlock_iothread(); > > > > > @@ -406,6 +440,11 @@ static void migrate_fd_cancel(MigrationState= *s) > > > > > QEMUFile *f =3D migrate_get_current()->file; > > > > > trace_migrate_fd_cancel(); > > > > > =20 > > > > > + if (s->rp_state.file) { > > > > > + /* shutdown the rp socket, so causing the rp thread to s= hutdown */ > > > > > + qemu_file_shutdown(s->rp_state.file); > > > >=20 > > > > I missed where qemu_file_shutdown() was implemented. Does this > > > > introduce a leftover socket dependency? > > >=20 > > > No, it shouldn't. The shutdown() causes a shutdown(2) syscall to > > > be issued on the socket stopping anything blocking on it; it then > > > gets closed at the end after the rp thread has exited. > >=20 > >=20 > > Sorry, that's not what I meant. I mean is this a hole in the > > abstraction of the QemuFile, because it assumes that what you're > > dealing with here is indeed a socket, rather than something else? >=20 > It's just a dependency that we have a shutdown method on the qemu_file > we're using; if it's not a socket then whatever it is, if we're going > to use it for a rp then it needs to implement something equivalent. Um, yeah, except I don't think most file types really have an operation that's semantically similar to socket shutdown. --=20 David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson --IrhDeMKUP4DT/M7F Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBAgAGBQJVI0nbAAoJEGw4ysog2bOS8McQANM9rcUv5vK3EL0f8nzBUsjf Ho2PcBBKtCfXPj6yHp+wCLjulJ0ue7cnn0Xbuk1/P+WS9zXNg9Yod5pLOfxkzOO9 ekvTAMn/WERINRI41OFJxSsLkDGDOtpO1SnEBnAkPd5uIJYbPiLj8KI311CpmiSg KamXKKqV0tPKrCcwbdBUT11732SvsJJqFE9XlvTi/SLNdmVlFnFEh0vjKs0zw265 UiUkHov7asIU7cHQ9yFKbEW/W0T0O6TiXgzI6OHUS5+ntYNZ6jOurvXZ7YZaitGl GKiUUrePT8wemcVg/67/gMKyrGQ3QDGXnffSrSxch/NpJpJ4XUbpV0anVQOzyPOF XnRy1hXT2GfKs8RjKPEgBzNzRvwnG5C3i2um54uWhNLpdRAjAGUcdBwO8p9ihmgq FnXxGZPXWfzYAOr7i39ds0cB2FhNt2zgIyW4G+QBMRyctqvKWmhmB8+YWQqy75GR YzkAZDccZgdUc4e8qD0pH9gcY6CR06VoyWowkNNSVmat1/Zr5kMFT3/HcvRNwznB uJ79RS0VLtSqZNOLY5LFwO4rX1k3VNnBdz/ZDp1wUIyukwhYPEGAXA/pgd0va5Mj kBSMPZMiquQ/Sz/2o2cEH0fT212T5ANWx0Qc5lufJgs6L7BzDplseQ4nck0eiOx3 Kbp4lHOaj1QQfp/XvKdx =pXeX -----END PGP SIGNATURE----- --IrhDeMKUP4DT/M7F--