From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:52346) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RqT2W-0003OX-Pw for qemu-devel@nongnu.org; Thu, 26 Jan 2012 12:23:18 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RqT2Q-0003G2-SJ for qemu-devel@nongnu.org; Thu, 26 Jan 2012 12:23:12 -0500 Received: from mail-iy0-f173.google.com ([209.85.210.173]:60416) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RqT2Q-0003D7-NQ for qemu-devel@nongnu.org; Thu, 26 Jan 2012 12:23:06 -0500 Received: by mail-iy0-f173.google.com with SMTP id k25so1227300iah.4 for ; Thu, 26 Jan 2012 09:23:06 -0800 (PST) Sender: Paolo Bonzini From: Paolo Bonzini Date: Thu, 26 Jan 2012 18:22:33 +0100 Message-Id: <1327598569-5199-3-git-send-email-pbonzini@redhat.com> In-Reply-To: <1327598569-5199-1-git-send-email-pbonzini@redhat.com> References: <1327598569-5199-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PATCH v2 02/18] block: store actual flags in bs->open_flags List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com The passed flags are changed slightly before passing them to bdrv_open. Store the same flags in bs->open_flags, so that they are used correctly in bdrv. In addition, this way we will be able to query them and get back consistent values. Signed-off-by: Paolo Bonzini --- block.c | 38 ++++++++++++++++++-------------------- 1 files changed, 18 insertions(+), 20 deletions(-) diff --git a/block.c b/block.c index c5a85a2..a1d2433 100644 --- a/block.c +++ b/block.c @@ -565,18 +565,30 @@ void bdrv_disable_copy_on_read(BlockDriverState *bs) static int bdrv_open_common(BlockDriverState *bs, const char *filename, int flags, BlockDriver *drv) { - int ret, open_flags; + int ret; assert(drv != NULL); trace_bdrv_open_common(bs, filename, flags, drv->format_name); + /* + * Clear flags that are internal to the block layer before opening the + * image. + */ + bs->open_flags = flags & ~(BDRV_O_SNAPSHOT | BDRV_O_NO_BACKING); + + /* + * Snapshots should be writable. + */ + if (bs->is_temporary) { + bs->open_flags |= BDRV_O_RDWR; + } + bs->file = NULL; bs->total_sectors = 0; bs->encrypted = 0; bs->valid_key = 0; bs->sg = 0; - bs->open_flags = flags; bs->growable = 0; bs->buffer_alignment = 512; @@ -596,29 +608,15 @@ 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); - - /* - * 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 writable. - */ - if (bs->is_temporary) { - open_flags |= BDRV_O_RDWR; - } - - bs->keep_read_only = bs->read_only = !(open_flags & BDRV_O_RDWR); + bs->keep_read_only = bs->read_only = !(bs->open_flags & BDRV_O_RDWR); /* Open the image, either directly or using a protocol */ if (drv->bdrv_file_open) { - ret = drv->bdrv_file_open(bs, filename, open_flags); + ret = drv->bdrv_file_open(bs, filename, bs->open_flags); } else { - ret = bdrv_file_open(&bs->file, filename, open_flags); + ret = bdrv_file_open(&bs->file, filename, bs->open_flags); if (ret >= 0) { - ret = drv->bdrv_open(bs, open_flags); + ret = drv->bdrv_open(bs, bs->open_flags); } } -- 1.7.7.6