From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50203) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ekCRl-0003ta-SI for qemu-devel@nongnu.org; Fri, 09 Feb 2018 12:26:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ekCRg-0004hx-Ut for qemu-devel@nongnu.org; Fri, 09 Feb 2018 12:26:49 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:53906 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ekCRg-0004hJ-Pj for qemu-devel@nongnu.org; Fri, 09 Feb 2018 12:26:44 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 652E540FB635 for ; Fri, 9 Feb 2018 17:26:44 +0000 (UTC) References: <20180208171807.24267-1-stefanha@redhat.com> <20180208171807.24267-2-stefanha@redhat.com> <20180209172314.GA3129@localhost.localdomain> From: Paolo Bonzini Message-ID: <94eef553-a2d6-cfac-9e5a-006ceee74519@redhat.com> Date: Fri, 9 Feb 2018 18:26:41 +0100 MIME-Version: 1.0 In-Reply-To: <20180209172314.GA3129@localhost.localdomain> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 1/3] block: add BlockBackend->in_flight counter List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Kevin Wolf Cc: Stefan Hajnoczi , qemu-devel@nongnu.org, John Snow On 09/02/2018 18:23, Kevin Wolf wrote: > Am 09.02.2018 um 17:28 hat Paolo Bonzini geschrieben: >> On 08/02/2018 18:18, Stefan Hajnoczi wrote: >>> + BlockDriverState *bs = blk_bs(blk); >>> + >>> + if (bs) { >>> + bdrv_drained_begin(bs); >>> + } >>> + >>> + /* We may have aio requests like -ENOMEDIUM in flight */ >>> + while (atomic_mb_read(&blk->in_flight) > 0) { >>> + aio_poll(blk_get_aio_context(blk), true); >>> + } >>> + >>> + if (bs) { >>> + bdrv_drained_end(bs); >> >> This only works if you are in the default AioContext, otherwise you can >> run handlers for one AioContexts in two threads. > > Should aio_poll() assert that it's called in the right thread to make > sure we obey the rules? > >> bdrv_dec_in_flight uses bdrv_wakeup and BDRV_POLL_WHILE to ensure that >> this doesn't happen, so there would be more code that you have to copy >> into block-backend.c. > > Instead of copying, can't we generalise it into a POLL_WHILE(ctx, > wakeup, cond) and make BDRV_POLL_WHILE() a wrapper for that? Yes, or even move bdrv_wakeup to AioContext would do. We already have block layer-specific fields such as the linux-aio state(*). (*) though now that linux-aio has been improved to do something like epoll, there may be a better reason to place linux-aio state in AioContext. Paolo