Received: from eggs.gnu.org ([2001:4830:134:3::10]:54655) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WAgn8-0005Q9-Pf for qemu-devel@nongnu.org; Tue, 04 Feb 2014 09:16:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WAgn2-0005G3-VI for qemu-devel@nongnu.org; Tue, 04 Feb 2014 09:15:58 -0500 Received: from mx1.redhat.com ([209.132.183.28]:16500) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WAgn2-0005Fx-Nz for qemu-devel@nongnu.org; Tue, 04 Feb 2014 09:15:52 -0500 Date: Tue, 4 Feb 2014 15:15:49 +0100 From: Kevin Wolf Message-ID: <20140204141549.GL3384@dhcp-200-207.str.redhat.com> References: <1391464280-25627-1-git-send-email-benoit.canet@irqsave.net> <1391464280-25627-6-git-send-email-benoit.canet@irqsave.net> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <1391464280-25627-6-git-send-email-benoit.canet@irqsave.net> Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH V15 05/13] quorum: Add quorum_aio_readv. List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: =?iso-8859-1?Q?Beno=EEt?= Canet Cc: =?iso-8859-1?Q?Beno=EEt?= Canet , qemu-devel@nongnu.org, stefanha@redhat.com, mreitz@redhat.com Am 03.02.2014 um 22:51 hat Beno=EEt Canet geschrieben: > From: Beno=EEt Canet >=20 > Signed-off-by: Benoit Canet > Reviewed-by: Max Reitz > --- > block/quorum.c | 38 ++++++++++++++++++++++++++++++++++++++ > 1 file changed, 38 insertions(+) >=20 > diff --git a/block/quorum.c b/block/quorum.c > index 81bffdd..699b512 100644 > --- a/block/quorum.c > +++ b/block/quorum.c > @@ -86,10 +86,19 @@ static void quorum_aio_finalize(QuorumAIOCB *acb) > BDRVQuorumState *s =3D acb->bqs; > int ret =3D 0; > =20 > + for (i =3D 0; i < s->total; i++) { > + qemu_vfree(acb->aios[i].buf); > + acb->aios[i].buf =3D NULL; > + acb->aios[i].ret =3D 0; You free acb->aios anyway, no point in clearing the fields. > + } > + > acb->common.cb(acb->common.opaque, ret); > if (acb->finished) { > *acb->finished =3D true; > } > + for (i =3D 0; acb->is_read && i < s->total; i++) { As Max noted, pulling acb->is_read into the for loop condition is clever. Code being unnecessarily clever is usually bad. > + qemu_iovec_destroy(&acb->aios[i].qiov); > + } Any reason to have two separate for loops? I can't see one why the qiov should be any longer valid than the data in it. I also can't see the reason for the different conditions, other than qemu_vfree() being a no-op for writes. Keep it simple: if (acb->is_read) { for (i =3D 0; i < s->total; i++) { qemu_vfree(acb->aios[i].buf); qemu_iovec_destroy(&acb->aios[i].qiov); } } It's shorter, less clever and more readable than your version. > g_free(acb->aios); > qemu_aio_release(acb); > } > @@ -145,6 +154,34 @@ static void quorum_aio_cb(void *opaque, int ret) > quorum_aio_finalize(acb); > } > =20 > +static BlockDriverAIOCB *quorum_aio_readv(BlockDriverState *bs, > + int64_t sector_num, > + QEMUIOVector *qiov, > + int nb_sectors, > + BlockDriverCompletionFunc *cb= , > + void *opaque) > +{ > + BDRVQuorumState *s =3D bs->opaque; > + QuorumAIOCB *acb =3D quorum_aio_get(s, bs, qiov, sector_num, > + nb_sectors, cb, opaque); > + int i; > + > + acb->is_read =3D true; > + > + for (i =3D 0; i < s->total; i++) { > + acb->aios[i].buf =3D qemu_blockalign(bs->file, qiov->size); Shouldn't this be s->bs[i] instead of bs->file? > + qemu_iovec_init(&acb->aios[i].qiov, qiov->niov); > + qemu_iovec_clone(&acb->aios[i].qiov, qiov, acb->aios[i].buf); > + } > + > + for (i =3D 0; i < s->total; i++) { > + bdrv_aio_readv(s->bs[i], sector_num, qiov, nb_sectors, > + quorum_aio_cb, &acb->aios[i]); > + } > + > + return &acb->common; > +} > + > static BlockDriverAIOCB *quorum_aio_writev(BlockDriverState *bs, > int64_t sector_num, > QEMUIOVector *qiov, > @@ -172,6 +209,7 @@ static BlockDriver bdrv_quorum =3D { > =20 > .instance_size =3D sizeof(BDRVQuorumState), > =20 > + .bdrv_aio_readv =3D quorum_aio_readv, > .bdrv_aio_writev =3D quorum_aio_writev, > }; Kevin