From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43068) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1alviC-0004VX-HK for qemu-devel@nongnu.org; Fri, 01 Apr 2016 05:49:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1alviB-00070u-LF for qemu-devel@nongnu.org; Fri, 01 Apr 2016 05:49:52 -0400 Sender: Paolo Bonzini References: <1459503998-31592-1-git-send-email-famz@redhat.com> From: Paolo Bonzini Message-ID: <56FE4436.4040109@redhat.com> Date: Fri, 1 Apr 2016 11:49:42 +0200 MIME-Version: 1.0 In-Reply-To: <1459503998-31592-1-git-send-email-famz@redhat.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH] block: Fix bdrv_drain in coroutine List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Fam Zheng , qemu-devel@nongnu.org Cc: Kevin Wolf , lvivier@redhat.com, Stefan Hajnoczi , qemu-block@nongnu.org On 01/04/2016 11:46, Fam Zheng wrote: > + > +static void bdrv_co_drain_bh_cb(void *opaque) > +{ > + BdrvCoDrainData *data = opaque; > + Coroutine *co = data->co; > + > + bdrv_drain(data->bs); > + data->done = true; > + qemu_coroutine_enter(co, NULL); > +} > + > +static void coroutine_fn bdrv_co_drain(BlockDriverState *bs) > +{ > + QEMUBH *bh; > + BdrvCoDrainData data; > + > + assert(qemu_in_coroutine()); > + data = (BdrvCoDrainData) { > + .co = qemu_coroutine_self(), > + .bs = bs, > + .done = false, > + }; > + bh = aio_bh_new(bdrv_get_aio_context(bs), bdrv_co_drain_bh_cb, &data), > + qemu_bh_schedule(bh); > + > + do { > + qemu_coroutine_yield(); > + } while (!data.done); The loop and "done" is not necessary. Also, > + qemu_bh_delete(bh); this can be moved to bdrv_co_drain_bh_cb before bdrv_drain, so that the bottom half doesn't slow down the event loop until bdrv_drain completes. Paolo > +}