From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56066) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b2ccY-0002rk-Ss for qemu-devel@nongnu.org; Tue, 17 May 2016 06:53:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b2ccT-00083K-QX for qemu-devel@nongnu.org; Tue, 17 May 2016 06:53:02 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58541) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b2ccT-000836-IQ for qemu-devel@nongnu.org; Tue, 17 May 2016 06:52:57 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (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 E1F1563318 for ; Tue, 17 May 2016 10:52:56 +0000 (UTC) References: <1460384056-29494-1-git-send-email-stefanha@redhat.com> From: Max Reitz Message-ID: Date: Tue, 17 May 2016 12:52:54 +0200 MIME-Version: 1.0 In-Reply-To: <1460384056-29494-1-git-send-email-stefanha@redhat.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="c35xtCkSDUgho8rfDESFxXjvDpvw2DUap" Subject: Re: [Qemu-devel] [RFC for-2.7] block: keep AioContext pointer in BlockBackend List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Stefan Hajnoczi , qemu-devel@nongnu.org Cc: Kevin Wolf , Paolo Bonzini This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --c35xtCkSDUgho8rfDESFxXjvDpvw2DUap From: Max Reitz To: Stefan Hajnoczi , qemu-devel@nongnu.org Cc: Kevin Wolf , Paolo Bonzini Message-ID: Subject: Re: [RFC for-2.7] block: keep AioContext pointer in BlockBackend References: <1460384056-29494-1-git-send-email-stefanha@redhat.com> In-Reply-To: <1460384056-29494-1-git-send-email-stefanha@redhat.com> Content-Type: text/plain; charset=iso-8859-15 Content-Transfer-Encoding: quoted-printable On 11.04.2016 16:14, Stefan Hajnoczi wrote: > blk_get/set_aio_context() delegate to BlockDriverState without storing > the AioContext pointer in BlockBackend. >=20 > There are two flaws: >=20 > 1. BlockBackend falls back to the QEMU main loop AioContext when there > is no root BlockDriverState. This means the drive loses its > AioContext during media change and would break dataplane. >=20 > 2. BlockBackend state used from multiple threads has no lock. Race > conditions will creep in as functionality is moved from > BlockDriverState to BlockBackend due to the absense of a lock. The > monitor cannot access BlockBackend state safely while an IOThread is= > also accessing the state. >=20 > Both issue #1 and #2 are mostly theoretical at the moment. I haven't > figured out a way to trigger #1 with virtio-blk (does not support media= > change) or virtio-scsi (blocks the eject operation). #2 may be possibl= e > with block accounting statistics in BlockBackend but I'm not aware of a= > crash that can be triggered. >=20 > This patch stores the AioContext pointer in BlockBackend and puts newly= > inserted BlockDriverStates into the AioContext. >=20 > Signed-off-by: Stefan Hajnoczi > --- > block/block-backend.c | 13 ++++++------- > 1 file changed, 6 insertions(+), 7 deletions(-) We can have multiple BBs per BDS tree, and in the future (after Kevin's "block: Remove BlockDriverState.blk" series) we may even have multiple BBs per BDS. Therefore, we have to make sure to propagate the AIO context to all BBs attached to the BDS tree, just as the AIO context is propagated to all BDSs in the BDS tree. A trivial way to do this would be to query the BDS's AIO context in blk_get_aio_context() and update the BB's context if they don't match. The more correct way would probably be to make bdrv_attach_aio_context() update its BB's (or BBs', in the future) AIO context. Max --c35xtCkSDUgho8rfDESFxXjvDpvw2DUap Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQEcBAEBCAAGBQJXOvgGAAoJEDuxQgLoOKytHN8H/jaWKRdnvFqTZlyAATzeAPTN uODps7e44TaxHET8nip7KM6i1QlGq16l2uq+0LkonV7jKT8xB0AoYr4rFBqMuyQv u+m5wVQ6EdIzIviCBukCjYC5XgZsWn5yo2T2I7pX8KB3pciJMJ2ZgoOJYKuZVGs2 Cr4tesp2i0xw/2lR8D1MvW4CXCdQMDADkguu7kM+z03ZpQrVgOcz6pcEgTq5ISG/ I3O65iyTJAuI5RTVuOQHGcf+hHf2fSvOuB3Fsoqp+NKytODpshZdOi/9eYGIK/vb OcNGs9XDScl/krxEp/j0FZUwzSRNSZYY9zoH61vRecBudKjAI4cSfh0kvjNAijA= =dDsm -----END PGP SIGNATURE----- --c35xtCkSDUgho8rfDESFxXjvDpvw2DUap--