From patchwork Wed Apr 14 15:50:12 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 50169 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 6C69DB7D2A for ; Thu, 15 Apr 2010 01:58:53 +1000 (EST) Received: from localhost ([127.0.0.1]:49182 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O24xn-0007tp-6e for incoming@patchwork.ozlabs.org; Wed, 14 Apr 2010 11:57:15 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1O24rw-0006Ha-V0 for qemu-devel@nongnu.org; Wed, 14 Apr 2010 11:51:13 -0400 Received: from [140.186.70.92] (port=53926 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O24rq-0006GQ-KZ for qemu-devel@nongnu.org; Wed, 14 Apr 2010 11:51:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1O24ri-0004OO-UA for qemu-devel@nongnu.org; Wed, 14 Apr 2010 11:51:06 -0400 Received: from mx1.redhat.com ([209.132.183.28]:21348) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1O24rh-0004Ny-CL for qemu-devel@nongnu.org; Wed, 14 Apr 2010 11:50:58 -0400 Received: from int-mx05.intmail.prod.int.phx2.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.18]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o3EFonwv000645 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 14 Apr 2010 11:50:50 -0400 Received: from localhost.localdomain (dhcp-5-175.str.redhat.com [10.32.5.175]) by int-mx05.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o3EFohRq020074; Wed, 14 Apr 2010 11:50:48 -0400 From: Kevin Wolf To: qemu-devel@nongnu.org Date: Wed, 14 Apr 2010 17:50:12 +0200 Message-Id: <1271260214-27443-4-git-send-email-kwolf@redhat.com> In-Reply-To: <1271260214-27443-1-git-send-email-kwolf@redhat.com> References: <1271260214-27443-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.18 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: kwolf@redhat.com, hch@lst.de Subject: [Qemu-devel] [RFC PATCH 3/5] block: Avoid forward declaration of bdrv_open_common X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Move bdrv_open_common so it's defined before its callers and remove the forward declaration. Signed-off-by: Kevin Wolf --- block.c | 145 +++++++++++++++++++++++++++++++-------------------------------- 1 files changed, 71 insertions(+), 74 deletions(-) diff --git a/block.c b/block.c index e04f80d..fd70d64 100644 --- a/block.c +++ b/block.c @@ -42,9 +42,6 @@ #include #endif -static int bdrv_open_common(BlockDriverState *bs, const char *filename, - int flags, BlockDriver *drv); - static BlockDriverAIOCB *bdrv_aio_readv_em(BlockDriverState *bs, int64_t sector_num, QEMUIOVector *qiov, int nb_sectors, BlockDriverCompletionFunc *cb, void *opaque); @@ -354,6 +351,77 @@ static BlockDriver *find_image_format(const char *filename) } /* + * Common part for opening disk images and files + */ +static int bdrv_open_common(BlockDriverState *bs, const char *filename, + int flags, BlockDriver *drv) +{ + int ret, open_flags; + + assert(drv != NULL); + + bs->is_temporary = 0; + bs->encrypted = 0; + bs->valid_key = 0; + bs->open_flags = flags; + /* buffer_alignment defaulted to 512, drivers can change this value */ + bs->buffer_alignment = 512; + + pstrcpy(bs->filename, sizeof(bs->filename), filename); + + if (use_bdrv_whitelist && !bdrv_is_whitelisted(drv)) { + return -ENOTSUP; + } + + bs->drv = drv; + bs->opaque = qemu_mallocz(drv->instance_size); + + /* + * Yes, BDRV_O_NOCACHE aka O_DIRECT means we have to present a + * write cache to the guest. We do need the fdatasync to flush + * out transactions for block allocations, and we maybe have a + * volatile write cache in our backing device to deal with. + */ + if (flags & (BDRV_O_CACHE_WB|BDRV_O_NOCACHE)) + bs->enable_write_cache = 1; + + /* + * Clear flags that are internal to the block layer before opening the + * image. + */ + open_flags = flags & ~(BDRV_O_SNAPSHOT | BDRV_O_NO_BACKING); + + /* + * Snapshots should be writeable. + */ + if (bs->is_temporary) { + open_flags |= BDRV_O_RDWR; + } + + ret = drv->bdrv_open(bs, filename, open_flags); + if (ret < 0) { + goto free_and_fail; + } + + bs->keep_read_only = bs->read_only = !(open_flags & BDRV_O_RDWR); + if (drv->bdrv_getlength) { + bs->total_sectors = bdrv_getlength(bs) >> BDRV_SECTOR_BITS; + } +#ifndef _WIN32 + if (bs->is_temporary) { + unlink(filename); + } +#endif + return 0; + +free_and_fail: + qemu_free(bs->opaque); + bs->opaque = NULL; + bs->drv = NULL; + return ret; +} + +/* * Opens a file using a protocol (file, host_device, nbd, ...) */ int bdrv_file_open(BlockDriverState **pbs, const char *filename, int flags) @@ -502,77 +570,6 @@ unlink_and_fail: return ret; } -/* - * Common part for opening disk images and files - */ -static int bdrv_open_common(BlockDriverState *bs, const char *filename, - int flags, BlockDriver *drv) -{ - int ret, open_flags; - - assert(drv != NULL); - - bs->is_temporary = 0; - bs->encrypted = 0; - bs->valid_key = 0; - bs->open_flags = flags; - /* buffer_alignment defaulted to 512, drivers can change this value */ - bs->buffer_alignment = 512; - - pstrcpy(bs->filename, sizeof(bs->filename), filename); - - if (use_bdrv_whitelist && !bdrv_is_whitelisted(drv)) { - return -ENOTSUP; - } - - bs->drv = drv; - bs->opaque = qemu_mallocz(drv->instance_size); - - /* - * Yes, BDRV_O_NOCACHE aka O_DIRECT means we have to present a - * write cache to the guest. We do need the fdatasync to flush - * out transactions for block allocations, and we maybe have a - * volatile write cache in our backing device to deal with. - */ - if (flags & (BDRV_O_CACHE_WB|BDRV_O_NOCACHE)) - bs->enable_write_cache = 1; - - /* - * Clear flags that are internal to the block layer before opening the - * image. - */ - open_flags = flags & ~(BDRV_O_SNAPSHOT | BDRV_O_NO_BACKING); - - /* - * Snapshots should be writeable. - */ - if (bs->is_temporary) { - open_flags |= BDRV_O_RDWR; - } - - ret = drv->bdrv_open(bs, filename, open_flags); - if (ret < 0) { - goto free_and_fail; - } - - bs->keep_read_only = bs->read_only = !(open_flags & BDRV_O_RDWR); - if (drv->bdrv_getlength) { - bs->total_sectors = bdrv_getlength(bs) >> BDRV_SECTOR_BITS; - } -#ifndef _WIN32 - if (bs->is_temporary) { - unlink(filename); - } -#endif - return 0; - -free_and_fail: - qemu_free(bs->opaque); - bs->opaque = NULL; - bs->drv = NULL; - return ret; -} - void bdrv_close(BlockDriverState *bs) { if (bs->drv) {