From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:48782) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RPmqt-0001Oz-JT for qemu-devel@nongnu.org; Sun, 13 Nov 2011 22:04:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RPmqs-0006dP-GS for qemu-devel@nongnu.org; Sun, 13 Nov 2011 22:04:55 -0500 Received: from mail-gx0-f173.google.com ([209.85.161.173]:46512) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RPmqs-0006dL-Dz for qemu-devel@nongnu.org; Sun, 13 Nov 2011 22:04:54 -0500 Received: by ggnp2 with SMTP id p2so6632348ggn.4 for ; Sun, 13 Nov 2011 19:04:53 -0800 (PST) MIME-Version: 1.0 In-Reply-To: <1321030042-20446-3-git-send-email-stefanha@linux.vnet.ibm.com> References: <1321030042-20446-1-git-send-email-stefanha@linux.vnet.ibm.com> <1321030042-20446-3-git-send-email-stefanha@linux.vnet.ibm.com> Date: Mon, 14 Nov 2011 11:04:53 +0800 Message-ID: From: Zhi Yong Wu Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH 02/10] block: add .bdrv_co_is_allocated() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Stefan Hajnoczi Cc: Kevin Wolf , Paolo Bonzini , Marcelo Tosatti , qemu-devel@nongnu.org On Sat, Nov 12, 2011 at 12:47 AM, Stefan Hajnoczi wrote: > This patch adds the .bdrv_co_is_allocated() interface which is identical > to .bdrv_is_allocated() but runs in coroutine context. =A0Running in > coroutine context implies that other coroutines might be performing I/O > at the same time. =A0 Therefore it must be safe to run while the followin= g > BlockDriver functions are in-flight: > > =A0 =A0.bdrv_co_readv() > =A0 =A0.bdrv_co_writev() > =A0 =A0.bdrv_co_flush() > =A0 =A0.bdrv_co_is_allocated() > > The new .bdrv_co_is_allocated() interface is useful because it can be > used when a VM is running, whereas .bdrv_is_allocated() is a synchronous > interface that does not cope with parallel requests. > > Signed-off-by: Stefan Hajnoczi > --- > =A0block.c =A0 =A0 | =A0 37 +++++++++++++++++++++++++++++++++++++ > =A0block_int.h | =A0 =A02 ++ > =A02 files changed, 39 insertions(+), 0 deletions(-) > > diff --git a/block.c b/block.c > index e6ac6d3..f8705b7 100644 > --- a/block.c > +++ b/block.c > @@ -1771,6 +1771,26 @@ int bdrv_has_zero_init(BlockDriverState *bs) > =A0 =A0 return 1; > =A0} > > +typedef struct BdrvCoIsAllocatedData { > + =A0 =A0BlockDriverState *bs; > + =A0 =A0int64_t sector_num; > + =A0 =A0int nb_sectors; > + =A0 =A0int *pnum; > + =A0 =A0int ret; > + =A0 =A0bool done; > +} BdrvCoIsAllocatedData; > + > +/* Coroutine wrapper for bdrv_is_allocated() */ > +static void coroutine_fn bdrv_is_allocated_co_entry(void *opaque) > +{ > + =A0 =A0BdrvCoIsAllocatedData *data =3D opaque; > + =A0 =A0BlockDriverState *bs =3D data->bs; > + > + =A0 =A0data->ret =3D bs->drv->bdrv_co_is_allocated(bs, data->sector_num= , > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 =A0 =A0 =A0 =A0data->nb_sectors, data->pnum); > + =A0 =A0data->done =3D true; > +} > + > =A0/* > =A0* Returns true iff the specified sector is present in the disk image. = Drivers > =A0* not implementing the functionality are assumed to not support backin= g files, > @@ -1786,6 +1806,23 @@ int bdrv_is_allocated(BlockDriverState *bs, int64_= t sector_num, int nb_sectors, > =A0 =A0 =A0 =A0int *pnum) > =A0{ > =A0 =A0 int64_t n; > + =A0 =A0if (bs->drv->bdrv_co_is_allocated) { > + =A0 =A0 =A0 =A0Coroutine *co; > + =A0 =A0 =A0 =A0BdrvCoIsAllocatedData data =3D { > + =A0 =A0 =A0 =A0 =A0 =A0.bs =3D bs, > + =A0 =A0 =A0 =A0 =A0 =A0.sector_num =3D sector_num, > + =A0 =A0 =A0 =A0 =A0 =A0.nb_sectors =3D nb_sectors, > + =A0 =A0 =A0 =A0 =A0 =A0.pnum =3D pnum, > + =A0 =A0 =A0 =A0 =A0 =A0.done =3D false, > + =A0 =A0 =A0 =A0}; > + > + =A0 =A0 =A0 =A0co =3D qemu_coroutine_create(bdrv_is_allocated_co_entry)= ; > + =A0 =A0 =A0 =A0qemu_coroutine_enter(co, &data); Since this main process will stop within qemu_coroutine_enter() until bdrv_is_allocated_co_entry() is completed, three lines of condition codes below are unnecessary, right? > + =A0 =A0 =A0 =A0while (!data.done) { > + =A0 =A0 =A0 =A0 =A0 =A0qemu_aio_wait(); > + =A0 =A0 =A0 =A0} > + =A0 =A0 =A0 =A0return data.ret; > + =A0 =A0} > =A0 =A0 if (!bs->drv->bdrv_is_allocated) { > =A0 =A0 =A0 =A0 if (sector_num >=3D bs->total_sectors) { > =A0 =A0 =A0 =A0 =A0 =A0 *pnum =3D 0; > diff --git a/block_int.h b/block_int.h > index f4547f6..1c1351c 100644 > --- a/block_int.h > +++ b/block_int.h > @@ -87,6 +87,8 @@ struct BlockDriver { > =A0 =A0 int coroutine_fn (*bdrv_co_flush)(BlockDriverState *bs); > =A0 =A0 int coroutine_fn (*bdrv_co_discard)(BlockDriverState *bs, > =A0 =A0 =A0 =A0 int64_t sector_num, int nb_sectors); > + =A0 =A0int coroutine_fn (*bdrv_co_is_allocated)(BlockDriverState *bs, > + =A0 =A0 =A0 =A0int64_t sector_num, int nb_sectors, int *pnum); > > =A0 =A0 int (*bdrv_aio_multiwrite)(BlockDriverState *bs, BlockRequest *re= qs, > =A0 =A0 =A0 =A0 int num_reqs); > -- > 1.7.7.1 > > > --=20 Regards, Zhi Yong Wu