From patchwork Tue Nov 13 14:14:54 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 198695 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 87CE12C0094 for ; Wed, 14 Nov 2012 01:15:22 +1100 (EST) Received: from localhost ([::1]:47210 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TYHGq-0001dZ-Bb for incoming@patchwork.ozlabs.org; Tue, 13 Nov 2012 09:15:20 -0500 Received: from eggs.gnu.org ([208.118.235.92]:54712) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TYHGY-0001Xw-8P for qemu-devel@nongnu.org; Tue, 13 Nov 2012 09:15:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TYHGU-00027l-U0 for qemu-devel@nongnu.org; Tue, 13 Nov 2012 09:15:01 -0500 Received: from mx1.redhat.com ([209.132.183.28]:33183) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TYHGU-00027f-MA for qemu-devel@nongnu.org; Tue, 13 Nov 2012 09:14:58 -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 qADEEwAP011290 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 13 Nov 2012 09:14:58 -0500 Received: from dhcp-5-188.str.redhat.com (dhcp-200-232.str.redhat.com [10.33.200.232]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id qADEEtK9013340; Tue, 13 Nov 2012 09:14:57 -0500 From: Kevin Wolf To: qemu-devel@nongnu.org Date: Tue, 13 Nov 2012 15:14:54 +0100 Message-Id: <1352816095-14051-2-git-send-email-kwolf@redhat.com> In-Reply-To: <1352816095-14051-1-git-send-email-kwolf@redhat.com> References: <1352816095-14051-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com Subject: [Qemu-devel] [PATCH 1/2] block: Factor out bdrv_open_flags 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 Signed-off-by: Kevin Wolf --- block.c | 35 +++++++++++++++++++++-------------- 1 files changed, 21 insertions(+), 14 deletions(-) diff --git a/block.c b/block.c index 854ebd6..a55b06c 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);