From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48024) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1alw1n-0006iQ-6V for qemu-devel@nongnu.org; Fri, 01 Apr 2016 06:10:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1alw1m-0003Lk-Cl for qemu-devel@nongnu.org; Fri, 01 Apr 2016 06:10:07 -0400 Date: Fri, 1 Apr 2016 18:09:58 +0800 From: Fam Zheng Message-ID: <20160401100958.GA871@ad.usersys.redhat.com> References: <1459503998-31592-1-git-send-email-famz@redhat.com> <56FE4436.4040109@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <56FE4436.4040109@redhat.com> Subject: Re: [Qemu-devel] [PATCH] block: Fix bdrv_drain in coroutine List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini Cc: Kevin Wolf , lvivier@redhat.com, Stefan Hajnoczi , qemu-devel@nongnu.org, qemu-block@nongnu.org On Fri, 04/01 11:49, Paolo Bonzini wrote: > > > 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, I was trying to protect against the bugs similar to the one fixed in e424aff5f30, but you're right we can make this an assertion and the loop is not needed. If a calling coroutine is resumed unexpectedly, we will catch it and fix it. > > > + 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. Good point! Will fix. Thanks, Fam