From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52449) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XReUf-0004Wx-UO for qemu-devel@nongnu.org; Wed, 10 Sep 2014 05:47:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XReUZ-0002Qn-P8 for qemu-devel@nongnu.org; Wed, 10 Sep 2014 05:47:17 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51590) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XReUZ-0002Qf-I6 for qemu-devel@nongnu.org; Wed, 10 Sep 2014 05:47:11 -0400 Message-ID: <54101E0F.3040900@redhat.com> Date: Wed, 10 Sep 2014 11:46:55 +0200 From: Paolo Bonzini MIME-Version: 1.0 References: <1410328814-12560-1-git-send-email-famz@redhat.com> <1410328814-12560-6-git-send-email-famz@redhat.com> <541009D3.3070301@redhat.com> <20140910093604.GB5620@fam-t430.nay.redhat.com> In-Reply-To: <20140910093604.GB5620@fam-t430.nay.redhat.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v5 05/22] block: Convert bdrv_em_aiocb_info.cancel to .cancel_async List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Fam Zheng Cc: Kevin Wolf , Benoit Canet , Peter Lieven , qemu-devel@nongnu.org, Stefan Hajnoczi , Liu Yuan Il 10/09/2014 11:36, Fam Zheng ha scritto: >> > >> > This could call the callback before I/O is finished. I/O can then >> > complete and write to disk stuff that was not meant to be written. > I think the request is already completed when bdrv_aio_rw_vector returns this > blockacb. I shouldn't override the return code anyway, but perhaps a nop > bdrv_aio_cancel_em is better. Note that the legacy bdrv_read/bdrv_write function calls actually are AIO-friendly (they run in a coroutine, and can yield). > > I think there is a pre-existing bug, which should be fixed with a "bool > > *done" member similar to BlockDriverAIOCBCoroutine's. But for the sake > > of conversion to async cancellation, you can just empty bdrv_aio_cancel_em. > > BTW, why is it "bool *done" instead of just "bool done"? Because, until your patches to add reference counting, this would have caused a dangling pointer in bdrv_aio_co_cancel_em: acb->done = true; qemu_bh_delete(acb->bh); qemu_aio_release(acb); instead, using "bool *done" works because bdrv_co_em_bh writes into the variable of bdrv_aio_co_cancel_em. This assumes that bdrv_aio_cancel is only called once (no reentrancy). Paolo