From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:52658) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SRJej-0003xR-MI for qemu-devel@nongnu.org; Mon, 07 May 2012 04:50:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SRJeh-0003nE-L2 for qemu-devel@nongnu.org; Mon, 07 May 2012 04:50:57 -0400 Received: from e33.co.us.ibm.com ([32.97.110.151]:33544) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SRJeh-0003mv-E5 for qemu-devel@nongnu.org; Mon, 07 May 2012 04:50:55 -0400 Received: from /spool/local by e33.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 7 May 2012 02:50:53 -0600 Received: from d01relay07.pok.ibm.com (d01relay07.pok.ibm.com [9.56.227.147]) by d01dlp03.pok.ibm.com (Postfix) with ESMTP id B11A9C90050 for ; Mon, 7 May 2012 04:50:48 -0400 (EDT) Received: from d01av03.pok.ibm.com (d01av03.pok.ibm.com [9.56.224.217]) by d01relay07.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q478oo5d21037286 for ; Mon, 7 May 2012 04:50:50 -0400 Received: from d01av03.pok.ibm.com (loopback [127.0.0.1]) by d01av03.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q478ooHd017752 for ; Mon, 7 May 2012 05:50:50 -0300 From: zwu.kernel@gmail.com Date: Mon, 7 May 2012 16:50:42 +0800 Message-Id: <1336380642-29705-1-git-send-email-zwu.kernel@gmail.com> Subject: [Qemu-devel] [PATCH v2 1/2] block: make bdrv_create adopt coroutine List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, Zhi Yong Wu , stefanha@linux.vnet.ibm.com From: Zhi Yong Wu 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 --- 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