From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54066) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YktyE-0000Xk-J5 for qemu-devel@nongnu.org; Wed, 22 Apr 2015 08:41:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ykty9-0005rd-QS for qemu-devel@nongnu.org; Wed, 22 Apr 2015 08:41:38 -0400 Received: from mail-wg0-x232.google.com ([2a00:1450:400c:c00::232]:35391) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ykty9-0005rZ-Eq for qemu-devel@nongnu.org; Wed, 22 Apr 2015 08:41:33 -0400 Received: by wgyo15 with SMTP id o15so245465065wgy.2 for ; Wed, 22 Apr 2015 05:41:32 -0700 (PDT) Date: Wed, 22 Apr 2015 13:41:30 +0100 From: Stefan Hajnoczi Message-ID: <20150422124130.GF27617@stefanha-thinkpad.redhat.com> References: <1426069701-1405-1-git-send-email-den@openvz.org> <1426069701-1405-7-git-send-email-den@openvz.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="bGR76rFJjkSxVeRa" Content-Disposition: inline In-Reply-To: <1426069701-1405-7-git-send-email-den@openvz.org> Subject: Re: [Qemu-devel] [PATCH 06/27] block/parallels: provide _co_readv routine for parallels format driver List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Denis V. Lunev" Cc: Kevin Wolf , qemu-devel@nongnu.org, Stefan Hajnoczi --bGR76rFJjkSxVeRa Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Mar 11, 2015 at 01:28:00PM +0300, Denis V. Lunev wrote: > Main approach is taken from qcow2_co_readv. >=20 > The patch drops coroutine lock for the duration of IO operation and > peforms normal scatter-gather IO using standard QEMU backend. >=20 > Signed-off-by: Denis V. Lunev > Reviewed-by: Roman Kagan > CC: Kevin Wolf > CC: Stefan Hajnoczi > --- > block/parallels.c | 46 +++++++++++++++++++++++++++------------------- > 1 file changed, 27 insertions(+), 19 deletions(-) >=20 > diff --git a/block/parallels.c b/block/parallels.c > index b469984..64b169b 100644 > --- a/block/parallels.c > +++ b/block/parallels.c > @@ -186,37 +186,45 @@ static int64_t coroutine_fn parallels_co_get_block_= status(BlockDriverState *bs, > BDRV_BLOCK_DATA | BDRV_BLOCK_OFFSET_VALID; > } > =20 > -static int parallels_read(BlockDriverState *bs, int64_t sector_num, > - uint8_t *buf, int nb_sectors) > +static coroutine_fn int parallels_co_readv(BlockDriverState *bs, > + int64_t sector_num, int nb_sectors, QEMUIOVector *qiov) > { > BDRVParallelsState *s =3D bs->opaque; > + uint64_t bytes_done =3D 0; > + QEMUIOVector hd_qiov; > + int ret =3D 0; > =20 > + qemu_iovec_init(&hd_qiov, qiov->niov); > + > + qemu_co_mutex_lock(&s->lock); > while (nb_sectors > 0) { > int64_t position =3D seek_to_sector(s, sector_num); > int n =3D cluster_remainder(s, sector_num, nb_sectors); > - if (position >=3D 0) { > - int ret =3D bdrv_read(bs->file, position, buf, n); > + int nbytes =3D n << BDRV_SECTOR_BITS; > + > + if (position < 0) { > + qemu_iovec_memset(qiov, bytes_done, 0, nbytes); > + } else { > + qemu_iovec_reset(&hd_qiov); > + qemu_iovec_concat(&hd_qiov, qiov, bytes_done, nbytes); > + > + qemu_co_mutex_unlock(&s->lock); > + ret =3D bdrv_co_readv(bs->file, position, n, &hd_qiov); > + qemu_co_mutex_lock(&s->lock); > + > if (ret < 0) { > - return ret; > + goto fail; The lock is never unlocked if the goto is taken. > } > - } else { > - memset(buf, 0, n << BDRV_SECTOR_BITS); > } > + > nb_sectors -=3D n; > sector_num +=3D n; > - buf +=3D n << BDRV_SECTOR_BITS; > + bytes_done +=3D nbytes; > } > - return 0; > -} > - > -static coroutine_fn int parallels_co_read(BlockDriverState *bs, int64_t = sector_num, > - uint8_t *buf, int nb_sectors) > -{ > - int ret; > - BDRVParallelsState *s =3D bs->opaque; > - qemu_co_mutex_lock(&s->lock); > - ret =3D parallels_read(bs, sector_num, buf, nb_sectors); > qemu_co_mutex_unlock(&s->lock); > + > +fail: > + qemu_iovec_destroy(&hd_qiov); > return ret; > } --bGR76rFJjkSxVeRa Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQEcBAEBAgAGBQJVN5b6AAoJEJykq7OBq3PIxHEIAINDmT9Jg6z6kPqQz2Jc4qrs Q412mFxoOAaefwmMIGry6rIqkql2LYB7EdF/d7Fs9SyICg3iscakBOgLzB0KLX3B khjuoM6HpL7Z3Lx3LFwlPz6VQ3kDzSE251UYBQHhaX10ICDSIbJDjaR34VKE3HJu bBFFkdOn+zHDyCLp8a1DZPQ8vvYe77np510KaLp8CJh1LLpRB1XWNMPXwm+cOORP tanRwpoRBSYecg3tL+xvt715ra6QdR2cS7OE7Z//2f4y9iUqQn/JydICL0WIF+Vk iwxGZGRFrfniNBLB/EkN668XKfVaHpl8NzxRwdgqH3XJV/87D3I1GK5znODVsCI= =dgRZ -----END PGP SIGNATURE----- --bGR76rFJjkSxVeRa--