From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54758) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V96IC-0006ib-G3 for qemu-devel@nongnu.org; Tue, 13 Aug 2013 00:33:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V96I3-0000IG-VY for qemu-devel@nongnu.org; Tue, 13 Aug 2013 00:33:12 -0400 Received: from mail-pd0-x230.google.com ([2607:f8b0:400e:c02::230]:38421) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V96I3-0000Hz-OV for qemu-devel@nongnu.org; Tue, 13 Aug 2013 00:33:03 -0400 Received: by mail-pd0-f176.google.com with SMTP id q10so4305862pdj.7 for ; Mon, 12 Aug 2013 21:33:03 -0700 (PDT) Sender: Dong Xu Wang From: Dong Xu Wang Date: Tue, 13 Aug 2013 12:31:47 +0800 Message-Id: <1376368326-7433-7-git-send-email-wdongxu@linux.vnet.ibm.com> In-Reply-To: <1376368326-7433-1-git-send-email-wdongxu@linux.vnet.ibm.com> References: <1376368326-7433-1-git-send-email-wdongxu@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH V18 06/25] add interface to block List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, wdongxu@cn.ibm.com, stefanha@redhat.com, Dong Xu Wang To make patches easy for reviewing, each block format is a single patch. Add a new interface to block layer to make sure origin code can compile and do not change any code logic. Signed-off-by: Dong Xu Wang --- block.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++ include/block/block.h | 2 ++ include/block/block_int.h | 2 ++ 3 files changed, 55 insertions(+) diff --git a/block.c b/block.c index 01b66d8..25090dc 100644 --- a/block.c +++ b/block.c @@ -366,6 +366,7 @@ typedef struct CreateCo { BlockDriver *drv; char *filename; QEMUOptionParameter *options; + QemuOpts *opts; int ret; } CreateCo; @@ -425,6 +426,56 @@ int bdrv_create_file(const char* filename, QEMUOptionParameter *options) return bdrv_create(drv, filename, options); } +int bdrv_create_new(BlockDriver *drv, const char* filename, QemuOpts *opts) +{ + int ret; + + Coroutine *co; + CreateCo cco = { + .drv = drv, + .filename = g_strdup(filename), + .opts = opts ?: qemu_opts_create_nofail(drv->bdrv_create_opts), + .ret = NOT_DONE, + }; + + if (!drv->bdrv_create) { + ret = -ENOTSUP; + goto out; + } + + 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; + +out: + if (!opts) { + qemu_opts_del(cco.opts); + } + g_free(cco.filename); + return ret; +} + +int bdrv_create_file_new(const char *filename, QemuOpts *opts) +{ + BlockDriver *drv; + + drv = bdrv_find_protocol(filename, true); + if (drv == NULL) { + return -ENOENT; + } + + return bdrv_create_new(drv, filename, opts); +} + /* * Create a uniquely-named empty temporary file. * Return 0 upon success, otherwise a negative errno value. diff --git a/include/block/block.h b/include/block/block.h index 742fce5..efcaaa4 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -119,6 +119,8 @@ BlockDriver *bdrv_find_whitelisted_format(const char *format_name, int bdrv_create(BlockDriver *drv, const char* filename, QEMUOptionParameter *options); int bdrv_create_file(const char* filename, QEMUOptionParameter *options); +int bdrv_create_new(BlockDriver *drv, const char* filename, QemuOpts *opts); +int bdrv_create_file_new(const char *filename, QemuOpts *opts); BlockDriverState *bdrv_new(const char *device_name); void bdrv_make_anon(BlockDriverState *bs); void bdrv_swap(BlockDriverState *bs_new, BlockDriverState *bs_old); diff --git a/include/block/block_int.h b/include/block/block_int.h index e45f2a0..fb12bba 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -105,6 +105,7 @@ struct BlockDriver { void (*bdrv_close)(BlockDriverState *bs); void (*bdrv_rebind)(BlockDriverState *bs); int (*bdrv_create)(const char *filename, QEMUOptionParameter *options); + int (*bdrv_create_new)(const char *filename, QemuOpts *opts); int (*bdrv_set_key)(BlockDriverState *bs, const char *key); int (*bdrv_make_empty)(BlockDriverState *bs); /* aio */ @@ -195,6 +196,7 @@ struct BlockDriver { /* List of options for creating images, terminated by name == NULL */ QEMUOptionParameter *create_options; + QemuOptsList *bdrv_create_opts; /* -- 1.7.11.7