From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54796) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WsAbd-0001jN-Qi for qemu-devel@nongnu.org; Wed, 04 Jun 2014 08:47:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WsAbS-0001Oq-4b for qemu-devel@nongnu.org; Wed, 04 Jun 2014 08:47:49 -0400 Received: from mail-wi0-x235.google.com ([2a00:1450:400c:c05::235]:62000) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WsAbR-0001OX-Tj for qemu-devel@nongnu.org; Wed, 04 Jun 2014 08:47:38 -0400 Received: by mail-wi0-f181.google.com with SMTP id n15so1362010wiw.8 for ; Wed, 04 Jun 2014 05:47:35 -0700 (PDT) Date: Wed, 4 Jun 2014 14:47:31 +0200 From: Stefan Hajnoczi Message-ID: <20140604124731.GF11073@stefanha-thinkpad.redhat.com> References: <1401561792-13410-1-git-send-email-mreitz@redhat.com> <538A3A8F.3060508@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <538A3A8F.3060508@redhat.com> Subject: Re: [Qemu-devel] [RFC 0/5] nbd: Adapt for dataplane List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Max Reitz Cc: Kevin Wolf , Paolo Bonzini , Fam Zheng , qemu-devel@nongnu.org, Stefan Hajnoczi On Sat, May 31, 2014 at 10:24:47PM +0200, Max Reitz wrote: > On 31.05.2014 20:43, Max Reitz wrote: > >[snip] > > > >However, if bs_aio_detach() is called from a different thread than the > >old AioContext is running in, we may still have coroutines running for > >which we should wait before returning from bs_aio_detach(). > > After re-reading Stefan's RFC and the AIO locking code, would it suffice to > call aio_context_acquire() and aio_context_release() on the old AioContext > at the end of bs_aio_detach() to ensure all coroutines are settled? If not, > I guess I have to wait until the coroutine variables are set to NULL (which > indicates they have completely finished execution; however, this is not > actually necessary and might lead to an infinite loop if the block driver > keeps yielding due to some condition related to the AioContext switch), or I > really have to switch the existing coroutines to the new AioContext while > they are running. Doing this from the outside will probably be even messier > than it would already be from the inside, so I sure hope to be able to avoid > this… I think you don't need to worry about this at all. bdrv_set_aio_context() is always invoked with the QEMU global mutex held. Regarding switching a coroutine from one AioContext to another (possibly in another thread), I've implemented it but it's a little involved (complex and slow). Let's avoid it, if possible. I also lost the patch during the great "make distclean twice deletes .git/" fiasco of 2014 so would need to reimplement it :). Stefan