Patchwork [RFC,V2,09/10] quorum: Add quorum_aio_readv.

login
register
mail settings
Submitter Benoit Canet
Date Aug. 7, 2012, 1:44 p.m.
Message ID <1344347073-7773-10-git-send-email-benoit@irqsave.net>
Download mbox | patch
Permalink /patch/175644/
State New
Headers show

Comments

Benoit Canet - Aug. 7, 2012, 1:44 p.m.
Signed-off-by: Benoit Canet <benoit@irqsave.net>
---
 block/quorum.c |   35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)
Stefan Hajnoczi - Aug. 8, 2012, 3:44 p.m.
On Tue, Aug 7, 2012 at 2:44 PM, Benoît Canet <benoit.canet@gmail.com> wrote:
> Signed-off-by: Benoit Canet <benoit@irqsave.net>
> ---
>  block/quorum.c |   35 +++++++++++++++++++++++++++++++++++
>  1 file changed, 35 insertions(+)
>
> diff --git a/block/quorum.c b/block/quorum.c
> index 2df3ae6..13804c1 100644
> --- a/block/quorum.c
> +++ b/block/quorum.c
> @@ -174,6 +174,14 @@ static int quorum_check_ret(QuorumAIOCB *acb)
>  static void quorum_aio_bh(void *opaque)
>  {
>      QuorumAIOCB *acb = opaque;
> +    int i;
> +
> +    for (i = 0; i <= 2; i++) {
> +        if (acb->aios[i].buf) {
> +            g_free(acb->aios[i].buf);
> +            acb->aios[i].buf = NULL;
> +        }

qemu_blockalign() buffers must be freed using qemu_vfree().  Also
qemu_vfree(NULL) is a nop so there no need for if (acb->aios[i].buf),
it can be done unconditionally.

> +    }
>
>      qemu_bh_delete(acb->bh);
>      acb->common.cb(acb->common.opaque, quorum_check_ret(acb));
> @@ -224,6 +232,32 @@ static void quorum_aio_cb(void *opaque, int ret)
>      }
>  }
>
> +static BlockDriverAIOCB *quorum_aio_readv(BlockDriverState *bs,
> +                                         int64_t sector_num,
> +                                         QEMUIOVector *qiov,
> +                                         int nb_sectors,
> +                                         BlockDriverCompletionFunc *cb,
> +                                         void *opaque)
> +{
> +    BDRVQuorumState *s = bs->opaque;
> +    QuorumAIOCB *acb = quorum_aio_get(bs, qiov, sector_num,
> +                                      nb_sectors, cb, opaque);
> +    int i;
> +
> +    for (i = 0; i <= 2; i++) {
> +        acb->aios[i].buf = qemu_blockalign(bs->file, qiov->size);
> +        qemu_iovec_init(&acb->qiovs[i], qiov->niov);
> +        blkverify_iovec_clone(&acb->qiovs[i], qiov, acb->aios[i].buf);
> +    }
> +
> +    for (i = 0; i <= 2; i++) {
> +        bdrv_aio_readv(s->bs[i], sector_num, qiov, nb_sectors,
> +                       quorum_aio_cb, &acb->aios[i]);

acb->qiovs[i] instead of qiov.
Stefan Hajnoczi - Aug. 8, 2012, 3:46 p.m.
On Wed, Aug 8, 2012 at 4:44 PM, Stefan Hajnoczi <stefanha@gmail.com> wrote:
> On Tue, Aug 7, 2012 at 2:44 PM, Benoît Canet <benoit.canet@gmail.com> wrote:
>> @@ -224,6 +232,32 @@ static void quorum_aio_cb(void *opaque, int ret)
>>      }
>>  }
>>
>> +static BlockDriverAIOCB *quorum_aio_readv(BlockDriverState *bs,
>> +                                         int64_t sector_num,
>> +                                         QEMUIOVector *qiov,
>> +                                         int nb_sectors,
>> +                                         BlockDriverCompletionFunc *cb,
>> +                                         void *opaque)
>> +{
>> +    BDRVQuorumState *s = bs->opaque;
>> +    QuorumAIOCB *acb = quorum_aio_get(bs, qiov, sector_num,
>> +                                      nb_sectors, cb, opaque);
>> +    int i;
>> +
>> +    for (i = 0; i <= 2; i++) {
>> +        acb->aios[i].buf = qemu_blockalign(bs->file, qiov->size);
>> +        qemu_iovec_init(&acb->qiovs[i], qiov->niov);
>> +        blkverify_iovec_clone(&acb->qiovs[i], qiov, acb->aios[i].buf);
>> +    }
>> +
>> +    for (i = 0; i <= 2; i++) {
>> +        bdrv_aio_readv(s->bs[i], sector_num, qiov, nb_sectors,
>> +                       quorum_aio_cb, &acb->aios[i]);
>
> acb->qiovs[i] instead of qiov.

Ah, I now see this was intentional because voting hasn't been added yet.

Patch

diff --git a/block/quorum.c b/block/quorum.c
index 2df3ae6..13804c1 100644
--- a/block/quorum.c
+++ b/block/quorum.c
@@ -174,6 +174,14 @@  static int quorum_check_ret(QuorumAIOCB *acb)
 static void quorum_aio_bh(void *opaque)
 {
     QuorumAIOCB *acb = opaque;
+    int i;
+
+    for (i = 0; i <= 2; i++) {
+        if (acb->aios[i].buf) {
+            g_free(acb->aios[i].buf);
+            acb->aios[i].buf = NULL;
+        }
+    }
 
     qemu_bh_delete(acb->bh);
     acb->common.cb(acb->common.opaque, quorum_check_ret(acb));
@@ -224,6 +232,32 @@  static void quorum_aio_cb(void *opaque, int ret)
     }
 }
 
+static BlockDriverAIOCB *quorum_aio_readv(BlockDriverState *bs,
+                                         int64_t sector_num,
+                                         QEMUIOVector *qiov,
+                                         int nb_sectors,
+                                         BlockDriverCompletionFunc *cb,
+                                         void *opaque)
+{
+    BDRVQuorumState *s = bs->opaque;
+    QuorumAIOCB *acb = quorum_aio_get(bs, qiov, sector_num,
+                                      nb_sectors, cb, opaque);
+    int i;
+
+    for (i = 0; i <= 2; i++) {
+        acb->aios[i].buf = qemu_blockalign(bs->file, qiov->size);
+        qemu_iovec_init(&acb->qiovs[i], qiov->niov);
+        blkverify_iovec_clone(&acb->qiovs[i], qiov, acb->aios[i].buf);
+    }
+
+    for (i = 0; i <= 2; 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,
@@ -272,6 +306,7 @@  static BlockDriver bdrv_quorum = {
     .bdrv_close         = quorum_close,
     .bdrv_co_flush_to_disk = quorum_co_flush,
 
+    .bdrv_aio_readv     = quorum_aio_readv,
     .bdrv_aio_writev    = quorum_aio_writev,
 };