From: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Marcelo Tosatti <mtosatti@redhat.com>,
Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Subject: [Qemu-devel] [PATCH 03/10] qed: convert to .bdrv_co_is_allocated()
Date: Fri, 11 Nov 2011 16:47:15 +0000 [thread overview]
Message-ID: <1321030042-20446-4-git-send-email-stefanha@linux.vnet.ibm.com> (raw)
In-Reply-To: <1321030042-20446-1-git-send-email-stefanha@linux.vnet.ibm.com>
The bdrv_qed_is_allocated() function is a synchronous wrapper around
qed_find_cluster(), which performs the cluster lookup. In order to
convert the synchronous function to a coroutine function we yield
instead of using qemu_aio_wait(). Note that QED's cache is already safe
for parallel requests so no locking is needed.
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
---
block/qed.c | 15 +++++++++++----
1 files changed, 11 insertions(+), 4 deletions(-)
diff --git a/block/qed.c b/block/qed.c
index d032a45..8a05445 100644
--- a/block/qed.c
+++ b/block/qed.c
@@ -651,6 +651,7 @@ static int bdrv_qed_create(const char *filename, QEMUOptionParameter *options)
}
typedef struct {
+ Coroutine *co;
int is_allocated;
int *pnum;
} QEDIsAllocatedCB;
@@ -660,10 +661,14 @@ static void qed_is_allocated_cb(void *opaque, int ret, uint64_t offset, size_t l
QEDIsAllocatedCB *cb = opaque;
*cb->pnum = len / BDRV_SECTOR_SIZE;
cb->is_allocated = (ret == QED_CLUSTER_FOUND || ret == QED_CLUSTER_ZERO);
+ if (cb->co) {
+ qemu_coroutine_enter(cb->co, NULL);
+ }
}
-static int bdrv_qed_is_allocated(BlockDriverState *bs, int64_t sector_num,
- int nb_sectors, int *pnum)
+static int coroutine_fn bdrv_qed_co_is_allocated(BlockDriverState *bs,
+ int64_t sector_num,
+ int nb_sectors, int *pnum)
{
BDRVQEDState *s = bs->opaque;
uint64_t pos = (uint64_t)sector_num * BDRV_SECTOR_SIZE;
@@ -676,8 +681,10 @@ static int bdrv_qed_is_allocated(BlockDriverState *bs, int64_t sector_num,
qed_find_cluster(s, &request, pos, len, qed_is_allocated_cb, &cb);
+ /* Now sleep if the callback wasn't invoked immediately */
while (cb.is_allocated == -1) {
- qemu_aio_wait();
+ cb.co = qemu_coroutine_self();
+ qemu_coroutine_yield();
}
qed_unref_l2_cache_entry(request.l2_table);
@@ -1475,7 +1482,7 @@ static BlockDriver bdrv_qed = {
.bdrv_open = bdrv_qed_open,
.bdrv_close = bdrv_qed_close,
.bdrv_create = bdrv_qed_create,
- .bdrv_is_allocated = bdrv_qed_is_allocated,
+ .bdrv_co_is_allocated = bdrv_qed_co_is_allocated,
.bdrv_make_empty = bdrv_qed_make_empty,
.bdrv_aio_readv = bdrv_qed_aio_readv,
.bdrv_aio_writev = bdrv_qed_aio_writev,
--
1.7.7.1
next prev parent reply other threads:[~2011-11-11 16:47 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-11-11 16:47 [Qemu-devel] [PATCH 00/10] block: replace .bdrv_is_allocated() with .bdrv_co_is_allocated() Stefan Hajnoczi
2011-11-11 16:47 ` [Qemu-devel] [PATCH 01/10] block: use public bdrv_is_allocated() interface Stefan Hajnoczi
2011-11-11 16:47 ` [Qemu-devel] [PATCH 02/10] block: add .bdrv_co_is_allocated() Stefan Hajnoczi
2011-11-14 3:04 ` Zhi Yong Wu
2011-11-14 7:32 ` Paolo Bonzini
2011-11-14 8:10 ` Zhi Yong Wu
2011-11-14 8:37 ` Paolo Bonzini
2011-11-14 8:53 ` Zhi Yong Wu
2011-11-14 8:50 ` Kevin Wolf
2011-11-14 8:50 ` Zhi Yong Wu
2011-11-11 16:47 ` Stefan Hajnoczi [this message]
2011-11-11 16:47 ` [Qemu-devel] [PATCH 04/10] block: convert qcow2, qcow2, and vmdk to .bdrv_co_is_allocated() Stefan Hajnoczi
2011-11-11 16:47 ` [Qemu-devel] [PATCH 05/10] vvfat: use public block layer interface Stefan Hajnoczi
2011-11-11 16:59 ` Kevin Wolf
2011-11-14 11:47 ` Stefan Hajnoczi
2011-11-11 16:47 ` [Qemu-devel] [PATCH 06/10] vvfat: convert to .bdrv_co_is_allocated() Stefan Hajnoczi
2011-11-11 16:47 ` [Qemu-devel] [PATCH 07/10] vdi: " Stefan Hajnoczi
2011-11-11 16:47 ` [Qemu-devel] [PATCH 08/10] cow: " Stefan Hajnoczi
2011-11-11 16:47 ` [Qemu-devel] [PATCH 09/10] block: drop .bdrv_is_allocated() interface Stefan Hajnoczi
2011-11-11 16:47 ` [Qemu-devel] [PATCH 10/10] block: add bdrv_co_is_allocated() interface 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=1321030042-20446-4-git-send-email-stefanha@linux.vnet.ibm.com \
--to=stefanha@linux.vnet.ibm.com \
--cc=kwolf@redhat.com \
--cc=mtosatti@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).