qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Hajnoczi <stefanha@redhat.com>
To: qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Stefan Hajnoczi <stefanha@redhat.com>
Subject: [Qemu-devel] [PATCH v2 12/25] qed: use BlockDriverState's AioContext
Date: Wed,  7 May 2014 12:27:28 +0200	[thread overview]
Message-ID: <1399458461-3997-13-git-send-email-stefanha@redhat.com> (raw)
In-Reply-To: <1399458461-3997-1-git-send-email-stefanha@redhat.com>

Drop the assumption that we're using the main AioContext.  Convert
qemu_bh_new() to aio_bh_new() and qemu_aio_wait() to aio_poll() so we're
using the BlockDriverState's AioContext.

Implement .bdrv_detach/attach_aio_context() interfaces to move the
QED_F_NEED_CHECK timer from the old AioContext to the new one.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 block/qed-table.c |  8 ++++----
 block/qed.c       | 35 +++++++++++++++++++++++++++++------
 2 files changed, 33 insertions(+), 10 deletions(-)

diff --git a/block/qed-table.c b/block/qed-table.c
index 76d2dcc..f61107a 100644
--- a/block/qed-table.c
+++ b/block/qed-table.c
@@ -173,7 +173,7 @@ int qed_read_l1_table_sync(BDRVQEDState *s)
     qed_read_table(s, s->header.l1_table_offset,
                    s->l1_table, qed_sync_cb, &ret);
     while (ret == -EINPROGRESS) {
-        qemu_aio_wait();
+        aio_poll(bdrv_get_aio_context(s->bs), true);
     }
 
     return ret;
@@ -194,7 +194,7 @@ int qed_write_l1_table_sync(BDRVQEDState *s, unsigned int index,
 
     qed_write_l1_table(s, index, n, qed_sync_cb, &ret);
     while (ret == -EINPROGRESS) {
-        qemu_aio_wait();
+        aio_poll(bdrv_get_aio_context(s->bs), true);
     }
 
     return ret;
@@ -267,7 +267,7 @@ int qed_read_l2_table_sync(BDRVQEDState *s, QEDRequest *request, uint64_t offset
 
     qed_read_l2_table(s, request, offset, qed_sync_cb, &ret);
     while (ret == -EINPROGRESS) {
-        qemu_aio_wait();
+        aio_poll(bdrv_get_aio_context(s->bs), true);
     }
 
     return ret;
@@ -289,7 +289,7 @@ int qed_write_l2_table_sync(BDRVQEDState *s, QEDRequest *request,
 
     qed_write_l2_table(s, request, index, n, flush, qed_sync_cb, &ret);
     while (ret == -EINPROGRESS) {
-        qemu_aio_wait();
+        aio_poll(bdrv_get_aio_context(s->bs), true);
     }
 
     return ret;
diff --git a/block/qed.c b/block/qed.c
index c130e42..79f5bd3 100644
--- a/block/qed.c
+++ b/block/qed.c
@@ -21,12 +21,13 @@
 static void qed_aio_cancel(BlockDriverAIOCB *blockacb)
 {
     QEDAIOCB *acb = (QEDAIOCB *)blockacb;
+    AioContext *aio_context = bdrv_get_aio_context(blockacb->bs);
     bool finished = false;
 
     /* Wait for the request to finish */
     acb->finished = &finished;
     while (!finished) {
-        qemu_aio_wait();
+        aio_poll(aio_context, true);
     }
 }
 
@@ -373,6 +374,27 @@ static void bdrv_qed_rebind(BlockDriverState *bs)
     s->bs = bs;
 }
 
+static void bdrv_qed_detach_aio_context(BlockDriverState *bs)
+{
+    BDRVQEDState *s = bs->opaque;
+
+    qed_cancel_need_check_timer(s);
+    timer_free(s->need_check_timer);
+}
+
+static void bdrv_qed_attach_aio_context(BlockDriverState *bs,
+                                        AioContext *new_context)
+{
+    BDRVQEDState *s = bs->opaque;
+
+    s->need_check_timer = aio_timer_new(new_context,
+                                        QEMU_CLOCK_VIRTUAL, SCALE_NS,
+                                        qed_need_check_timer_cb, s);
+    if (s->header.features & QED_F_NEED_CHECK) {
+        qed_start_need_check_timer(s);
+    }
+}
+
 static int bdrv_qed_open(BlockDriverState *bs, QDict *options, int flags,
                          Error **errp)
 {
@@ -496,8 +518,7 @@ static int bdrv_qed_open(BlockDriverState *bs, QDict *options, int flags,
         }
     }
 
-    s->need_check_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL,
-                                            qed_need_check_timer_cb, s);
+    bdrv_qed_attach_aio_context(bs, bdrv_get_aio_context(bs));
 
 out:
     if (ret) {
@@ -528,8 +549,7 @@ static void bdrv_qed_close(BlockDriverState *bs)
 {
     BDRVQEDState *s = bs->opaque;
 
-    qed_cancel_need_check_timer(s);
-    timer_free(s->need_check_timer);
+    bdrv_qed_detach_aio_context(bs);
 
     /* Ensure writes reach stable storage */
     bdrv_flush(bs->file);
@@ -919,7 +939,8 @@ static void qed_aio_complete(QEDAIOCB *acb, int ret)
 
     /* Arrange for a bh to invoke the completion function */
     acb->bh_ret = ret;
-    acb->bh = qemu_bh_new(qed_aio_complete_bh, acb);
+    acb->bh = aio_bh_new(bdrv_get_aio_context(acb->common.bs),
+                         qed_aio_complete_bh, acb);
     qemu_bh_schedule(acb->bh);
 
     /* Start next allocating write request waiting behind this one.  Note that
@@ -1644,6 +1665,8 @@ static BlockDriver bdrv_qed = {
     .bdrv_change_backing_file = bdrv_qed_change_backing_file,
     .bdrv_invalidate_cache    = bdrv_qed_invalidate_cache,
     .bdrv_check               = bdrv_qed_check,
+    .bdrv_detach_aio_context  = bdrv_qed_detach_aio_context,
+    .bdrv_attach_aio_context  = bdrv_qed_attach_aio_context,
 };
 
 static void bdrv_qed_init(void)
-- 
1.9.0

  parent reply	other threads:[~2014-05-07 10:28 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-07 10:27 [Qemu-devel] [PATCH v2 00/25] dataplane: use QEMU block layer Stefan Hajnoczi
2014-05-07 10:27 ` [Qemu-devel] [PATCH v2 01/25] block: use BlockDriverState AioContext Stefan Hajnoczi
2014-05-07 10:27 ` [Qemu-devel] [PATCH v2 02/25] block: acquire AioContext in bdrv_*_all() Stefan Hajnoczi
2014-05-07 10:27 ` [Qemu-devel] [PATCH v2 03/25] block: acquire AioContext in bdrv_drain_all() Stefan Hajnoczi
2014-05-07 10:27 ` [Qemu-devel] [PATCH v2 04/25] block: add bdrv_set_aio_context() Stefan Hajnoczi
2014-05-07 10:27 ` [Qemu-devel] [PATCH v2 05/25] blkdebug: use BlockDriverState's AioContext Stefan Hajnoczi
2014-05-07 10:27 ` [Qemu-devel] [PATCH v2 06/25] blkverify: implement .bdrv_detach/attach_aio_context() Stefan Hajnoczi
2014-05-07 10:27 ` [Qemu-devel] [PATCH v2 07/25] curl: " Stefan Hajnoczi
2014-05-07 10:27 ` [Qemu-devel] [PATCH v2 08/25] gluster: use BlockDriverState's AioContext Stefan Hajnoczi
2014-05-07 10:27 ` [Qemu-devel] [PATCH v2 09/25] iscsi: implement .bdrv_detach/attach_aio_context() Stefan Hajnoczi
2014-05-07 14:14   ` Peter Lieven
2014-05-08 13:40     ` Stefan Hajnoczi
2014-05-07 10:27 ` [Qemu-devel] [PATCH v2 10/25] nbd: " Stefan Hajnoczi
2014-05-07 10:27 ` [Qemu-devel] [PATCH v2 11/25] nfs: " Stefan Hajnoczi
2014-05-07 14:12   ` Peter Lieven
2014-05-08 13:46     ` Stefan Hajnoczi
2014-05-07 10:27 ` Stefan Hajnoczi [this message]
2014-05-07 10:27 ` [Qemu-devel] [PATCH v2 13/25] quorum: " Stefan Hajnoczi
2014-05-07 11:24   ` Benoît Canet
2014-05-08 11:24     ` Stefan Hajnoczi
2014-05-07 10:27 ` [Qemu-devel] [PATCH v2 14/25] block/raw-posix: " Stefan Hajnoczi
2014-05-07 10:27 ` [Qemu-devel] [PATCH v2 15/25] block/linux-aio: fix memory and fd leak Stefan Hajnoczi
2014-05-07 10:27 ` [Qemu-devel] [PATCH v2 16/25] block/raw-win32: create one QEMUWin32AIOState per BDRVRawState Stefan Hajnoczi
2014-05-07 10:34   ` Paolo Bonzini
2014-05-07 10:27 ` [Qemu-devel] [PATCH v2 17/25] block/raw-win32: implement .bdrv_detach/attach_aio_context() Stefan Hajnoczi
2014-05-07 10:35   ` Paolo Bonzini
2014-05-08 11:25     ` Stefan Hajnoczi
2014-05-07 10:27 ` [Qemu-devel] [PATCH v2 18/25] rbd: use BlockDriverState's AioContext Stefan Hajnoczi
2014-05-07 10:27 ` [Qemu-devel] [PATCH v2 19/25] sheepdog: implement .bdrv_detach/attach_aio_context() Stefan Hajnoczi
2014-05-07 10:27 ` [Qemu-devel] [PATCH v2 20/25] ssh: use BlockDriverState's AioContext Stefan Hajnoczi
2014-05-07 10:27 ` [Qemu-devel] [PATCH v2 21/25] vmdk: implement .bdrv_detach/attach_aio_context() Stefan Hajnoczi
2014-05-07 10:27 ` [Qemu-devel] [PATCH v2 22/25] dataplane: use the QEMU block layer for I/O Stefan Hajnoczi
2014-05-07 10:27 ` [Qemu-devel] [PATCH v2 23/25] dataplane: delete IOQueue since it is no longer used Stefan Hajnoczi
2014-05-07 10:27 ` [Qemu-devel] [PATCH v2 24/25] dataplane: implement async flush Stefan Hajnoczi
2014-05-07 10:27 ` [Qemu-devel] [PATCH v2 25/25] raw-posix: drop raw_get_aio_fd() since it is no longer used Stefan Hajnoczi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1399458461-3997-13-git-send-email-stefanha@redhat.com \
    --to=stefanha@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).