Received: from eggs.gnu.org ([2001:4830:134:3::10]:53634) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XUBC4-00019R-DJ for qemu-devel@nongnu.org; Wed, 17 Sep 2014 05:06:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XUBBu-0006Zd-JG for qemu-devel@nongnu.org; Wed, 17 Sep 2014 05:06:32 -0400 Received: from mail-wi0-x22f.google.com ([2a00:1450:400c:c05::22f]:53213) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XUBBu-0006YS-C8 for qemu-devel@nongnu.org; Wed, 17 Sep 2014 05:06:22 -0400 Received: by mail-wi0-f175.google.com with SMTP id cc10so791837wib.2 for ; Wed, 17 Sep 2014 02:06:18 -0700 (PDT) Date: Wed, 17 Sep 2014 10:06:15 +0100 From: Stefan Hajnoczi Message-ID: <20140917090615.GB10699@stefanha-thinkpad.redhat.com> References: <5416C46D.7040105@ozlabs.ru> <541826CA.7050607@ozlabs.ru> <541828BF.8090301@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="pvezYHf7grwyp3Bc" Content-Disposition: inline In-Reply-To: <541828BF.8090301@redhat.com> Subject: Re: [Qemu-devel] migration: qemu-coroutine-lock.c:141: qemu_co_mutex_unlock: Assertion `mutex->locked == 1' failed List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini Cc: Kevin Wolf , Alexey Kardashevskiy , "qemu-devel@nongnu.org" , "Dr. David Alan Gilbert" , Stefan Hajnoczi , Max Reitz --pvezYHf7grwyp3Bc Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Sep 16, 2014 at 02:10:39PM +0200, Paolo Bonzini wrote: > Il 16/09/2014 14:02, Alexey Kardashevskiy ha scritto: > > I am having problems when migrate a guest via libvirt like this: > >=20 > > virsh migrate --live --persistent --undefinesource --copy-storage-all > > --verbose --desturi qemu+ssh://legkvm/system --domain chig1 > >=20 > > The XML used to create the guest is at the end of this mail. > >=20 > > I see NBD FLUSH command after the destination QEMU received EOF for > > migration stream and this produces a crash in qcow2_co_flush_to_os() as > > s->lock is false or s->l2_table_cache is NULL. > >=20 >=20 > Max, Kevin, could the fix be something like this? >=20 > diff --git a/block/qcow2.c b/block/qcow2.c > index 0daf25c..e7459ea 100644 > --- a/block/qcow2.c > +++ b/block/qcow2.c > @@ -1442,6 +1442,7 @@ static void qcow2_invalidate_cache(BlockDriverState= *bs, Error **errp) > memcpy(&aes_decrypt_key, &s->aes_decrypt_key, sizeof(aes_decrypt= _key)); > } > =20 > + qemu_co_mutex_lock(&s->lock); > qcow2_close(bs); > =20 > bdrv_invalidate_cache(bs->file, &local_err); > @@ -1455,6 +1456,7 @@ static void qcow2_invalidate_cache(BlockDriverState= *bs, Error **errp) > =20 > ret =3D qcow2_open(bs, options, flags, &local_err); > QDECREF(options); > + qemu_co_mutex_unlock(&s->lock); > if (local_err) { > error_setg(errp, "Could not reopen qcow2 layer: %s", > error_get_pretty(local_err)); >=20 > On top of this, *_invalidate_cache needs to be marked as coroutine_fn. I think the fundamental problem here is that the mirror block job on the source host does not synchronize with live migration. Remember the mirror block job iterates on the dirty bitmap whenever it feels like. There is no guarantee that the mirror block job has quiesced before migration handover takes place, right? IMO that's the fundamental problem and trying to protect qcow2_invalidate_cache() seems wrong. We must make sure that the mirror block job on the source has quiesced before we hand over, otherwise the destination could see an outdated copy of the disk! Please let me know if I missed something which makes the operation safe on the source, but I didn't spot any guards. Stefan --pvezYHf7grwyp3Bc Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQEcBAEBAgAGBQJUGU8HAAoJEJykq7OBq3PIPSMH/1Htx70T8vIO0VFsMQtU+Y14 NRUP+m1r5Y7BC52YwyrZnqjiwlaOVIL8DGhf/FgA32M8y+tjkjC/UbeKAv+5IJhq t4OsXyNVoBl7i3Mp8/r7OJlNe/fBq1ULegQ5PwvgZaRXOJcDE5n13MKWVAhVV/jk iP7/KR0J80zg+4k83U+IOZsXj4q7LzaPsGDM7rfhOt4e1UZIT+fU4UQoYcS8eODQ dxJVsICL7PqVPhUc8vOmTzA8PGcSYpSm5r2Rpi3Xa0z1YvhqerdYowloT/CqADjP rPvq9EFq5hJjXSl7pTVv4aA6EfJmN76wQj01anjhr6H+3PWcBYp7qzU4FMPYN/g= =V2/u -----END PGP SIGNATURE----- --pvezYHf7grwyp3Bc--