From: zwu.kernel@gmail.com
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>,
marcandre.lureau@gmail.com, stefanha@linux.vnet.ibm.com
Subject: [Qemu-devel] [PATCH 1/2] block: make bdrv_create adopt coroutine
Date: Sat, 5 May 2012 11:13:03 +0800 [thread overview]
Message-ID: <1336187583-27323-1-git-send-email-zwu.kernel@gmail.com> (raw)
From: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>
Signed-off-by: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>
---
block.c | 48 +++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 47 insertions(+), 1 deletions(-)
diff --git a/block.c b/block.c
index 43c794c..3ff78c5 100644
--- a/block.c
+++ b/block.c
@@ -341,13 +341,59 @@ BlockDriver *bdrv_find_whitelisted_format(const char *format_name)
return drv && bdrv_is_whitelisted(drv) ? drv : NULL;
}
+typedef struct CreateCo {
+ BlockDriver *drv;
+ const char *filename;
+ QEMUOptionParameter *options;
+ int ret;
+} CreateCo;
+
+static void coroutine_fn bdrv_create_co_entry(void *opaque)
+{
+ CreateCo *cco = opaque;
+ assert(cco->drv);
+
+ cco->ret = cco->drv->bdrv_create(cco->filename, cco->options);
+}
+
+static int bdrv_create_co(BlockDriver *drv,
+ const char *filename,
+ QEMUOptionParameter *options)
+{
+ int ret;
+
+ Coroutine *co;
+ CreateCo cco = {
+ .drv = drv,
+ .filename = g_strdup(filename),
+ .options = options,
+ .ret = NOT_DONE,
+ };
+
+ if (qemu_in_coroutine()) {
+ /* Fast-path if already in coroutine context */
+ bdrv_create_co_entry(&cco);
+ } else {
+ co = qemu_coroutine_create(bdrv_create_co_entry);
+ qemu_coroutine_enter(co, &cco);
+ while (cco.ret == NOT_DONE) {
+ qemu_aio_wait();
+ }
+ }
+
+ ret = cco.ret;
+ g_free(cco.filename);
+
+ return ret;
+}
+
int bdrv_create(BlockDriver *drv, const char* filename,
QEMUOptionParameter *options)
{
if (!drv->bdrv_create)
return -ENOTSUP;
- return drv->bdrv_create(filename, options);
+ return bdrv_create_co(drv, filename, options);
}
int bdrv_create_file(const char* filename, QEMUOptionParameter *options)
--
1.7.6
next reply other threads:[~2012-05-05 3:13 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-05 3:13 zwu.kernel [this message]
-- strict thread matches above, loose matches on Subject: below --
2012-05-05 3:28 [Qemu-devel] [PATCH 1/2] block: make bdrv_create adopt coroutine zwu.kernel
2012-05-07 8:32 ` Kevin Wolf
2012-05-07 8:39 ` Zhi Yong Wu
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=1336187583-27323-1-git-send-email-zwu.kernel@gmail.com \
--to=zwu.kernel@gmail.com \
--cc=kwolf@redhat.com \
--cc=marcandre.lureau@gmail.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@linux.vnet.ibm.com \
--cc=wuzhy@linux.vnet.ibm.com \
/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 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.