All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 0/2] quorum: cleanup and optimization for FIFO case
@ 2016-10-05 16:35 Paolo Bonzini
  2016-10-05 16:35 ` [Qemu-devel] [PATCH 1/2] quorum: change child_iter to children_read Paolo Bonzini
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Paolo Bonzini @ 2016-10-05 16:35 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-block, berto

A couple patches I had lying in the huge multiqueue series but are
not really related.  So let's flush 'em...

Paolo Bonzini (2):
  quorum: change child_iter to children_read
  quorum: do not allocate multiple iovecs for FIFO strategy

 block/quorum.c | 93 ++++++++++++++++++++++++++++------------------------------
 1 file changed, 45 insertions(+), 48 deletions(-)

-- 
2.7.4

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Qemu-devel] [PATCH 1/2] quorum: change child_iter to children_read
  2016-10-05 16:35 [Qemu-devel] [PATCH 0/2] quorum: cleanup and optimization for FIFO case Paolo Bonzini
@ 2016-10-05 16:35 ` Paolo Bonzini
  2016-10-05 17:03   ` [Qemu-devel] [Qemu-block] " Max Reitz
  2016-10-07 12:53   ` [Qemu-devel] " Alberto Garcia
  2016-10-05 16:35 ` [Qemu-devel] [PATCH 2/2] quorum: do not allocate multiple iovecs for FIFO strategy Paolo Bonzini
                   ` (2 subsequent siblings)
  3 siblings, 2 replies; 9+ messages in thread
From: Paolo Bonzini @ 2016-10-05 16:35 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-block, berto

This simplifies a bit the code by using the usual C "inclusive start,
exclusive end" pattern for ranges.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 block/quorum.c | 30 +++++++++++++-----------------
 1 file changed, 13 insertions(+), 17 deletions(-)

diff --git a/block/quorum.c b/block/quorum.c
index 9cf876f..435296e 100644
--- a/block/quorum.c
+++ b/block/quorum.c
@@ -130,7 +130,7 @@ struct QuorumAIOCB {
 
     bool is_read;
     int vote_ret;
-    int child_iter;             /* which child to read in fifo pattern */
+    int children_read;          /* how many children have been read from */
 };
 
 static bool quorum_vote(QuorumAIOCB *acb);
@@ -165,8 +165,7 @@ static void quorum_aio_finalize(QuorumAIOCB *acb)
     acb->common.cb(acb->common.opaque, ret);
 
     if (acb->is_read) {
-        /* on the quorum case acb->child_iter == s->num_children - 1 */
-        for (i = 0; i <= acb->child_iter; i++) {
+        for (i = 0; i < acb->children_read; i++) {
             qemu_vfree(acb->qcrs[i].buf);
             qemu_iovec_destroy(&acb->qcrs[i].qiov);
         }
@@ -301,14 +300,13 @@ static void quorum_aio_cb(void *opaque, int ret)
 
     if (acb->is_read && s->read_pattern == QUORUM_READ_PATTERN_FIFO) {
         /* We try to read next child in FIFO order if we fail to read */
-        if (ret < 0 && (acb->child_iter + 1) < s->num_children) {
-            acb->child_iter++;
+        if (ret < 0 && acb->children_read < s->num_children) {
             read_fifo_child(acb);
             return;
         }
 
         if (ret == 0) {
-            quorum_copy_qiov(acb->qiov, &acb->qcrs[acb->child_iter].qiov);
+            quorum_copy_qiov(acb->qiov, &acb->qcrs[acb->children_read - 1].qiov);
         }
         acb->vote_ret = ret;
         quorum_aio_finalize(acb);
@@ -653,6 +651,7 @@ static BlockAIOCB *read_quorum_children(QuorumAIOCB *acb)
     BDRVQuorumState *s = acb->common.bs->opaque;
     int i;
 
+    acb->children_read = s->num_children;
     for (i = 0; i < s->num_children; i++) {
         acb->qcrs[i].buf = qemu_blockalign(s->children[i]->bs, acb->qiov->size);
         qemu_iovec_init(&acb->qcrs[i].qiov, acb->qiov->niov);
@@ -671,16 +670,14 @@ static BlockAIOCB *read_quorum_children(QuorumAIOCB *acb)
 static BlockAIOCB *read_fifo_child(QuorumAIOCB *acb)
 {
     BDRVQuorumState *s = acb->common.bs->opaque;
+    int n = acb->children_read++;
 
-    acb->qcrs[acb->child_iter].buf =
-        qemu_blockalign(s->children[acb->child_iter]->bs, acb->qiov->size);
-    qemu_iovec_init(&acb->qcrs[acb->child_iter].qiov, acb->qiov->niov);
-    qemu_iovec_clone(&acb->qcrs[acb->child_iter].qiov, acb->qiov,
-                     acb->qcrs[acb->child_iter].buf);
-    acb->qcrs[acb->child_iter].aiocb =
-        bdrv_aio_readv(s->children[acb->child_iter], acb->sector_num,
-                       &acb->qcrs[acb->child_iter].qiov, acb->nb_sectors,
-                       quorum_aio_cb, &acb->qcrs[acb->child_iter]);
+    acb->qcrs[n].buf = qemu_blockalign(s->children[n]->bs, acb->qiov->size);
+    qemu_iovec_init(&acb->qcrs[n].qiov, acb->qiov->niov);
+    qemu_iovec_clone(&acb->qcrs[n].qiov, acb->qiov, acb->qcrs[n].buf);
+    acb->qcrs[n].aiocb = bdrv_aio_readv(s->children[n], acb->sector_num,
+                                        &acb->qcrs[n].qiov, acb->nb_sectors,
+                                        quorum_aio_cb, &acb->qcrs[n]);
 
     return &acb->common;
 }
@@ -696,13 +693,12 @@ static BlockAIOCB *quorum_aio_readv(BlockDriverState *bs,
     QuorumAIOCB *acb = quorum_aio_get(s, bs, qiov, sector_num,
                                       nb_sectors, cb, opaque);
     acb->is_read = true;
+    acb->children_read = 0;
 
     if (s->read_pattern == QUORUM_READ_PATTERN_QUORUM) {
-        acb->child_iter = s->num_children - 1;
         return read_quorum_children(acb);
     }
 
-    acb->child_iter = 0;
     return read_fifo_child(acb);
 }
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [Qemu-devel] [PATCH 2/2] quorum: do not allocate multiple iovecs for FIFO strategy
  2016-10-05 16:35 [Qemu-devel] [PATCH 0/2] quorum: cleanup and optimization for FIFO case Paolo Bonzini
  2016-10-05 16:35 ` [Qemu-devel] [PATCH 1/2] quorum: change child_iter to children_read Paolo Bonzini
@ 2016-10-05 16:35 ` Paolo Bonzini
  2016-10-05 17:20   ` [Qemu-devel] [Qemu-block] " Max Reitz
  2016-10-07 13:01   ` [Qemu-devel] " Alberto Garcia
  2016-10-14 13:51 ` [Qemu-devel] [Qemu-block] [PATCH 0/2] quorum: cleanup and optimization for FIFO case Stefan Hajnoczi
  2016-10-17 17:03 ` Max Reitz
  3 siblings, 2 replies; 9+ messages in thread
From: Paolo Bonzini @ 2016-10-05 16:35 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-block, berto

In FIFO mode there are no parallel reads, hence there is no need to
allocate separate buffers and clone the iovecs.

The two cases of quorum_aio_cb are now even more different, and
most of quorum_aio_finalize is only needed in one of them, so split
them in separate functions.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 block/quorum.c | 79 +++++++++++++++++++++++++++++-----------------------------
 1 file changed, 40 insertions(+), 39 deletions(-)

diff --git a/block/quorum.c b/block/quorum.c
index 435296e..d122299 100644
--- a/block/quorum.c
+++ b/block/quorum.c
@@ -156,21 +156,7 @@ static AIOCBInfo quorum_aiocb_info = {
 
 static void quorum_aio_finalize(QuorumAIOCB *acb)
 {
-    int i, ret = 0;
-
-    if (acb->vote_ret) {
-        ret = acb->vote_ret;
-    }
-
-    acb->common.cb(acb->common.opaque, ret);
-
-    if (acb->is_read) {
-        for (i = 0; i < acb->children_read; i++) {
-            qemu_vfree(acb->qcrs[i].buf);
-            qemu_iovec_destroy(&acb->qcrs[i].qiov);
-        }
-    }
-
+    acb->common.cb(acb->common.opaque, acb->vote_ret);
     g_free(acb->qcrs);
     qemu_aio_unref(acb);
 }
@@ -282,38 +268,52 @@ static void quorum_copy_qiov(QEMUIOVector *dest, QEMUIOVector *source)
     }
 }
 
-static void quorum_aio_cb(void *opaque, int ret)
+static void quorum_report_bad_acb(QuorumChildRequest *sacb, int ret)
+{
+    QuorumAIOCB *acb = sacb->parent;
+    QuorumOpType type = acb->is_read ? QUORUM_OP_TYPE_READ : QUORUM_OP_TYPE_WRITE;
+    quorum_report_bad(type, acb->sector_num, acb->nb_sectors,
+                      sacb->aiocb->bs->node_name, ret);
+}
+
+static void quorum_fifo_aio_cb(void *opaque, int ret)
 {
     QuorumChildRequest *sacb = opaque;
     QuorumAIOCB *acb = sacb->parent;
     BDRVQuorumState *s = acb->common.bs->opaque;
-    bool rewrite = false;
 
-    if (ret == 0) {
-        acb->success_count++;
-    } else {
-        QuorumOpType type;
-        type = acb->is_read ? QUORUM_OP_TYPE_READ : QUORUM_OP_TYPE_WRITE;
-        quorum_report_bad(type, acb->sector_num, acb->nb_sectors,
-                          sacb->aiocb->bs->node_name, ret);
-    }
+    assert(acb->is_read && s->read_pattern == QUORUM_READ_PATTERN_FIFO);
+
+    if (ret < 0) {
+        quorum_report_bad_acb(sacb, ret);
 
-    if (acb->is_read && s->read_pattern == QUORUM_READ_PATTERN_FIFO) {
         /* We try to read next child in FIFO order if we fail to read */
-        if (ret < 0 && acb->children_read < s->num_children) {
+        if (acb->children_read < s->num_children) {
             read_fifo_child(acb);
             return;
         }
-
-        if (ret == 0) {
-            quorum_copy_qiov(acb->qiov, &acb->qcrs[acb->children_read - 1].qiov);
-        }
-        acb->vote_ret = ret;
-        quorum_aio_finalize(acb);
-        return;
     }
 
+    acb->vote_ret = ret;
+
+    /* FIXME: rewrite failed children if acb->children_read > 1? */
+    quorum_aio_finalize(acb);
+}
+
+static void quorum_aio_cb(void *opaque, int ret)
+{
+    QuorumChildRequest *sacb = opaque;
+    QuorumAIOCB *acb = sacb->parent;
+    BDRVQuorumState *s = acb->common.bs->opaque;
+    bool rewrite = false;
+    int i;
+
     sacb->ret = ret;
+    if (ret == 0) {
+        acb->success_count++;
+    } else {
+        quorum_report_bad_acb(sacb, ret);
+    }
     acb->count++;
     assert(acb->count <= s->num_children);
     assert(acb->success_count <= s->num_children);
@@ -324,6 +324,10 @@ static void quorum_aio_cb(void *opaque, int ret)
     /* Do the vote on read */
     if (acb->is_read) {
         rewrite = quorum_vote(acb);
+        for (i = 0; i < s->num_children; i++) {
+            qemu_vfree(acb->qcrs[i].buf);
+            qemu_iovec_destroy(&acb->qcrs[i].qiov);
+        }
     } else {
         quorum_has_too_much_io_failed(acb);
     }
@@ -672,12 +676,9 @@ static BlockAIOCB *read_fifo_child(QuorumAIOCB *acb)
     BDRVQuorumState *s = acb->common.bs->opaque;
     int n = acb->children_read++;
 
-    acb->qcrs[n].buf = qemu_blockalign(s->children[n]->bs, acb->qiov->size);
-    qemu_iovec_init(&acb->qcrs[n].qiov, acb->qiov->niov);
-    qemu_iovec_clone(&acb->qcrs[n].qiov, acb->qiov, acb->qcrs[n].buf);
     acb->qcrs[n].aiocb = bdrv_aio_readv(s->children[n], acb->sector_num,
-                                        &acb->qcrs[n].qiov, acb->nb_sectors,
-                                        quorum_aio_cb, &acb->qcrs[n]);
+                                        acb->qiov, acb->nb_sectors,
+                                        quorum_fifo_aio_cb, &acb->qcrs[n]);
 
     return &acb->common;
 }
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [Qemu-devel] [Qemu-block] [PATCH 1/2] quorum: change child_iter to children_read
  2016-10-05 16:35 ` [Qemu-devel] [PATCH 1/2] quorum: change child_iter to children_read Paolo Bonzini
@ 2016-10-05 17:03   ` Max Reitz
  2016-10-07 12:53   ` [Qemu-devel] " Alberto Garcia
  1 sibling, 0 replies; 9+ messages in thread
From: Max Reitz @ 2016-10-05 17:03 UTC (permalink / raw)
  To: Paolo Bonzini, qemu-devel; +Cc: qemu-block

[-- Attachment #1: Type: text/plain, Size: 376 bytes --]

On 05.10.2016 18:35, Paolo Bonzini wrote:
> This simplifies a bit the code by using the usual C "inclusive start,
> exclusive end" pattern for ranges.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  block/quorum.c | 30 +++++++++++++-----------------
>  1 file changed, 13 insertions(+), 17 deletions(-)

Reviewed-by: Max Reitz <mreitz@redhat.com>


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 480 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Qemu-devel] [Qemu-block] [PATCH 2/2] quorum: do not allocate multiple iovecs for FIFO strategy
  2016-10-05 16:35 ` [Qemu-devel] [PATCH 2/2] quorum: do not allocate multiple iovecs for FIFO strategy Paolo Bonzini
@ 2016-10-05 17:20   ` Max Reitz
  2016-10-07 13:01   ` [Qemu-devel] " Alberto Garcia
  1 sibling, 0 replies; 9+ messages in thread
From: Max Reitz @ 2016-10-05 17:20 UTC (permalink / raw)
  To: Paolo Bonzini, qemu-devel; +Cc: qemu-block

[-- Attachment #1: Type: text/plain, Size: 588 bytes --]

On 05.10.2016 18:35, Paolo Bonzini wrote:
> In FIFO mode there are no parallel reads, hence there is no need to
> allocate separate buffers and clone the iovecs.
> 
> The two cases of quorum_aio_cb are now even more different, and
> most of quorum_aio_finalize is only needed in one of them, so split
> them in separate functions.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  block/quorum.c | 79 +++++++++++++++++++++++++++++-----------------------------
>  1 file changed, 40 insertions(+), 39 deletions(-)

Reviewed-by: Max Reitz <mreitz@redhat.com>


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 480 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Qemu-devel] [PATCH 1/2] quorum: change child_iter to children_read
  2016-10-05 16:35 ` [Qemu-devel] [PATCH 1/2] quorum: change child_iter to children_read Paolo Bonzini
  2016-10-05 17:03   ` [Qemu-devel] [Qemu-block] " Max Reitz
@ 2016-10-07 12:53   ` Alberto Garcia
  1 sibling, 0 replies; 9+ messages in thread
From: Alberto Garcia @ 2016-10-07 12:53 UTC (permalink / raw)
  To: Paolo Bonzini, qemu-devel; +Cc: qemu-block

On Wed 05 Oct 2016 06:35:26 PM CEST, Paolo Bonzini wrote:
> This simplifies a bit the code by using the usual C "inclusive start,
> exclusive end" pattern for ranges.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

Reviewed-by: Alberto Garcia <berto@igalia.com>

Berto

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Qemu-devel] [PATCH 2/2] quorum: do not allocate multiple iovecs for FIFO strategy
  2016-10-05 16:35 ` [Qemu-devel] [PATCH 2/2] quorum: do not allocate multiple iovecs for FIFO strategy Paolo Bonzini
  2016-10-05 17:20   ` [Qemu-devel] [Qemu-block] " Max Reitz
@ 2016-10-07 13:01   ` Alberto Garcia
  1 sibling, 0 replies; 9+ messages in thread
From: Alberto Garcia @ 2016-10-07 13:01 UTC (permalink / raw)
  To: Paolo Bonzini, qemu-devel; +Cc: qemu-block

On Wed 05 Oct 2016 06:35:27 PM CEST, Paolo Bonzini wrote:
> In FIFO mode there are no parallel reads, hence there is no need to
> allocate separate buffers and clone the iovecs.
>
> The two cases of quorum_aio_cb are now even more different, and
> most of quorum_aio_finalize is only needed in one of them, so split
> them in separate functions.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

Reviewed-by: Alberto Garcia <berto@igalia.com>

Berto

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Qemu-devel] [Qemu-block] [PATCH 0/2] quorum: cleanup and optimization for FIFO case
  2016-10-05 16:35 [Qemu-devel] [PATCH 0/2] quorum: cleanup and optimization for FIFO case Paolo Bonzini
  2016-10-05 16:35 ` [Qemu-devel] [PATCH 1/2] quorum: change child_iter to children_read Paolo Bonzini
  2016-10-05 16:35 ` [Qemu-devel] [PATCH 2/2] quorum: do not allocate multiple iovecs for FIFO strategy Paolo Bonzini
@ 2016-10-14 13:51 ` Stefan Hajnoczi
  2016-10-17 17:03 ` Max Reitz
  3 siblings, 0 replies; 9+ messages in thread
From: Stefan Hajnoczi @ 2016-10-14 13:51 UTC (permalink / raw)
  To: Kevin Wolf; +Cc: qemu-devel, qemu-block, Paolo Bonzini

[-- Attachment #1: Type: text/plain, Size: 501 bytes --]

On Wed, Oct 05, 2016 at 06:35:25PM +0200, Paolo Bonzini wrote:
> A couple patches I had lying in the huge multiqueue series but are
> not really related.  So let's flush 'em...
> 
> Paolo Bonzini (2):
>   quorum: change child_iter to children_read
>   quorum: do not allocate multiple iovecs for FIFO strategy
> 
>  block/quorum.c | 93 ++++++++++++++++++++++++++++------------------------------
>  1 file changed, 45 insertions(+), 48 deletions(-)

Kevin: Is this going through your tree?

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 455 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Qemu-devel] [Qemu-block] [PATCH 0/2] quorum: cleanup and optimization for FIFO case
  2016-10-05 16:35 [Qemu-devel] [PATCH 0/2] quorum: cleanup and optimization for FIFO case Paolo Bonzini
                   ` (2 preceding siblings ...)
  2016-10-14 13:51 ` [Qemu-devel] [Qemu-block] [PATCH 0/2] quorum: cleanup and optimization for FIFO case Stefan Hajnoczi
@ 2016-10-17 17:03 ` Max Reitz
  3 siblings, 0 replies; 9+ messages in thread
From: Max Reitz @ 2016-10-17 17:03 UTC (permalink / raw)
  To: Paolo Bonzini, qemu-devel; +Cc: qemu-block

[-- Attachment #1: Type: text/plain, Size: 550 bytes --]

On 05.10.2016 18:35, Paolo Bonzini wrote:
> A couple patches I had lying in the huge multiqueue series but are
> not really related.  So let's flush 'em...
> 
> Paolo Bonzini (2):
>   quorum: change child_iter to children_read
>   quorum: do not allocate multiple iovecs for FIFO strategy
> 
>  block/quorum.c | 93 ++++++++++++++++++++++++++++------------------------------
>  1 file changed, 45 insertions(+), 48 deletions(-)

Thanks, I've applied the series to my block branch:

https://github.com/XanClic/qemu/commits/block

Max


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 480 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2016-10-17 17:03 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-10-05 16:35 [Qemu-devel] [PATCH 0/2] quorum: cleanup and optimization for FIFO case Paolo Bonzini
2016-10-05 16:35 ` [Qemu-devel] [PATCH 1/2] quorum: change child_iter to children_read Paolo Bonzini
2016-10-05 17:03   ` [Qemu-devel] [Qemu-block] " Max Reitz
2016-10-07 12:53   ` [Qemu-devel] " Alberto Garcia
2016-10-05 16:35 ` [Qemu-devel] [PATCH 2/2] quorum: do not allocate multiple iovecs for FIFO strategy Paolo Bonzini
2016-10-05 17:20   ` [Qemu-devel] [Qemu-block] " Max Reitz
2016-10-07 13:01   ` [Qemu-devel] " Alberto Garcia
2016-10-14 13:51 ` [Qemu-devel] [Qemu-block] [PATCH 0/2] quorum: cleanup and optimization for FIFO case Stefan Hajnoczi
2016-10-17 17:03 ` Max Reitz

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.