[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 3/5] block: make bdrv_create adopt coroutine
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PATCH 3/5] block: make bdrv_create adopt coroutine |
Date: |
Mon, 7 May 2012 19:55:52 +0200 |
From: Zhi Yong Wu <address@hidden>
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 <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
block.c | 44 ++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 42 insertions(+), 2 deletions(-)
diff --git a/block.c b/block.c
index 43c794c..ee7d8f2 100644
--- a/block.c
+++ b/block.c
@@ -341,13 +341,53 @@ 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);
+}
+
int bdrv_create(BlockDriver *drv, const char* filename,
QEMUOptionParameter *options)
{
- if (!drv->bdrv_create)
+ int ret;
+
+ Coroutine *co;
+ CreateCo cco = {
+ .drv = drv,
+ .filename = g_strdup(filename),
+ .options = options,
+ .ret = NOT_DONE,
+ };
+
+ if (!drv->bdrv_create) {
return -ENOTSUP;
+ }
- return drv->bdrv_create(filename, options);
+ 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_file(const char* filename, QEMUOptionParameter *options)
--
1.7.6.5
- [Qemu-devel] [PULL 0/5] Block patches for 1.1, Kevin Wolf, 2012/05/07
- [Qemu-devel] [PATCH 1/5] sheepdog: switch to writethrough mode if cluster doesn't support flush, Kevin Wolf, 2012/05/07
- [Qemu-devel] [PATCH 2/5] qcow2: Limit COW to where it's needed, Kevin Wolf, 2012/05/07
- [Qemu-devel] [PATCH 3/5] block: make bdrv_create adopt coroutine,
Kevin Wolf <=
- [Qemu-devel] [PATCH 4/5] qcow2: lock on prealloc, Kevin Wolf, 2012/05/07
- [Qemu-devel] [PATCH 5/5] fdc: simplify media change handling, Kevin Wolf, 2012/05/07
- Re: [Qemu-devel] [PULL 0/5] Block patches for 1.1, Anthony Liguori, 2012/05/08
- [Qemu-devel] [PULL 0/5] Block patches for 1.1, Kevin Wolf, 2012/05/30
- [Qemu-devel] [PATCH 2/5] sheepdog: fix return value of do_load_save_vm_state, Kevin Wolf, 2012/05/30
- [Qemu-devel] [PATCH 3/5] block: prevent snapshot mode $TMPDIR symlink attack, Kevin Wolf, 2012/05/30
- [Qemu-devel] [PATCH 5/5] ahci: SATA FIS is 20 bytes, not 0x20, Kevin Wolf, 2012/05/30
- [Qemu-devel] [PATCH 1/5] virtio: Fix compiler warning for non Linux hosts, Kevin Wolf, 2012/05/30
- [Qemu-devel] [PATCH 4/5] virtio-blk: Fix geometry sector calculation, Kevin Wolf, 2012/05/30
- Re: [Qemu-devel] [PULL 0/5] Block patches for 1.1, Anthony Liguori, 2012/05/30