From patchwork Tue Aug 13 04:31:47 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Wang X-Patchwork-Id: 266716 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (unknown [IPv6:2001:4830:134:3::12]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 308C72C00E1 for ; Tue, 13 Aug 2013 15:36:51 +1000 (EST) Received: from localhost ([::1]:51675 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V96K6-00008K-Va for incoming@patchwork.ozlabs.org; Tue, 13 Aug 2013 00:35:10 -0400 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) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=ZVPToeC0uS4HA4N507k6J6kYPBHhd6D5j7YBaVYvz7A=; b=VBWFTlYdr7gDvPstQ+TNHNw8x5Z8AwG8GDVCbl/TtEiKH0sx070jGa8VfidFoqX/lC o/2r6wFBGMEsMCskTSUGPpijdGXHDL6i9Unwu5hcLlW1eYDn95GKCoPCQ87ckDRDEL3b YUbD5krzVayqa11ZsSaSzWtCU4sdkwTZaqShkuiiEjtkH0Lm3xOLTWpPCOBaSEG74U8w DClfPBmX701oIOG1WVf5kjVL5sSGCRenPg87qfsxXrl0hmdfdOBl+4ce/P8h7gVoZutp BWhUgXyy1G9XLrDQAzgr0FJdfHdOWn7YniGZl9MD0hm5CYvG0D+OKMZfzd6f0VAs+akQ ZJPw== X-Received: by 10.68.106.99 with SMTP id gt3mr2488346pbb.116.1376368382998; Mon, 12 Aug 2013 21:33:02 -0700 (PDT) Received: from 11.wdongxu.kvm58 ([202.108.130.153]) by mx.google.com with ESMTPSA id mz5sm10285023pbc.18.2013.08.12.21.32.59 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 12 Aug 2013 21:33:02 -0700 (PDT) From: Dong Xu Wang To: qemu-devel@nongnu.org Date: Tue, 13 Aug 2013 12:31:47 +0800 Message-Id: <1376368326-7433-7-git-send-email-wdongxu@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.11.7 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> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:400e:c02::230 Cc: kwolf@redhat.com, wdongxu@cn.ibm.com, stefanha@redhat.com, Dong Xu Wang Subject: [Qemu-devel] [PATCH V18 06/25] add interface to block X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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; /*