* [Qemu-devel] [PATCH v2 1/2] block: make bdrv_create adopt coroutine
@ 2012-05-07 8:50 zwu.kernel
0 siblings, 0 replies; only message in thread
From: zwu.kernel @ 2012-05-07 8:50 UTC (permalink / raw)
To: qemu-devel; +Cc: kwolf, Zhi Yong Wu, stefanha
From: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>
The current qemu.git introduces failure with preallocation and some sizes:
qemu-img create -f qcow2 new.img 976563K -o preallocation=metadata
qemu-img: qemu-coroutine-lock.c:111: qemu_co_mutex_unlock: Assertion
`mutex->locked == 1' failed.
And lock needs to work in coroutine context. So to fix this issue, we need to make bdrv_create adopt coroutine at first.
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..5de55fe 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;
+ 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
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2012-05-07 8:50 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-05-07 8:50 [Qemu-devel] [PATCH v2 1/2] block: make bdrv_create adopt coroutine zwu.kernel
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).