From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:38996) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TYz0r-000860-KM for qemu-devel@nongnu.org; Thu, 15 Nov 2012 07:57:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TYz0o-0004qt-IH for qemu-devel@nongnu.org; Thu, 15 Nov 2012 07:57:45 -0500 Received: from mx1.redhat.com ([209.132.183.28]:12276) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TYz0o-0004qh-AS for qemu-devel@nongnu.org; Thu, 15 Nov 2012 07:57:42 -0500 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id qAFCvfk9030601 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 15 Nov 2012 07:57:41 -0500 From: Kevin Wolf Date: Thu, 15 Nov 2012 13:57:36 +0100 Message-Id: <1352984257-29712-2-git-send-email-kwolf@redhat.com> In-Reply-To: <1352984257-29712-1-git-send-email-kwolf@redhat.com> References: <1352984257-29712-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PATCH v2 1/2] block: Factor out bdrv_open_flags List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com Signed-off-by: Kevin Wolf --- block.c | 35 +++++++++++++++++++++-------------- 1 files changed, 21 insertions(+), 14 deletions(-) diff --git a/block.c b/block.c index bf0747f..95fd00e 100644 --- a/block.c +++ b/block.c @@ -634,6 +634,26 @@ void bdrv_disable_copy_on_read(BlockDriverState *bs) bs->copy_on_read--; } +static int bdrv_open_flags(BlockDriverState *bs, int flags) +{ + int open_flags = flags | BDRV_O_CACHE_WB; + + /* + * Clear flags that are internal to the block layer before opening the + * image. + */ + open_flags &= ~(BDRV_O_SNAPSHOT | BDRV_O_NO_BACKING); + + /* + * Snapshots should be writable. + */ + if (bs->is_temporary) { + open_flags |= BDRV_O_RDWR; + } + + return open_flags; +} + /* * Common part for opening disk images and files */ @@ -665,20 +685,7 @@ static int bdrv_open_common(BlockDriverState *bs, const char *filename, bs->opaque = g_malloc0(drv->instance_size); bs->enable_write_cache = !!(flags & BDRV_O_CACHE_WB); - open_flags = flags | BDRV_O_CACHE_WB; - - /* - * Clear flags that are internal to the block layer before opening the - * image. - */ - open_flags &= ~(BDRV_O_SNAPSHOT | BDRV_O_NO_BACKING); - - /* - * Snapshots should be writable. - */ - if (bs->is_temporary) { - open_flags |= BDRV_O_RDWR; - } + open_flags = bdrv_open_flags(bs, flags); bs->read_only = !(open_flags & BDRV_O_RDWR); -- 1.7.6.5